7 printf ( "\nPress a key" );
13 printf ( "---more---" );
19 * Print row of a hex dump with specified display address
21 * @v dispaddr Display address
22 * @v data Data to print
23 * @v len Length of data
24 * @v offset Starting offset within data
26 static void dbg_hex_dump_da_row ( unsigned long dispaddr
, const void *data
,
27 unsigned long len
, unsigned int offset
) {
28 const uint8_t *bytes
= data
;
32 printf ( "%08lx :", ( dispaddr
+ offset
) );
33 for ( i
= offset
; i
< ( offset
+ 16 ) ; i
++ ) {
38 printf ( " %02x", bytes
[i
] );
41 for ( i
= offset
; i
< ( offset
+ 16 ) ; i
++ ) {
47 if ( ( byte
< 0x20 ) || ( byte
>= 0x7f ) )
49 printf ( "%c", byte
);
55 * Print hex dump with specified display address
57 * @v dispaddr Display address
58 * @v data Data to print
59 * @v len Length of data
61 void dbg_hex_dump_da ( unsigned long dispaddr
, const void *data
,
65 for ( offset
= 0 ; offset
< len
; offset
+= 16 ) {
66 dbg_hex_dump_da_row ( dispaddr
, data
, len
, offset
);
70 #define GUARD_SYMBOL ( ( 'M' << 24 ) | ( 'I' << 16 ) | ( 'N' << 8 ) | 'E' )
71 /* Fill a region with guard markers. We use a 4-byte pattern to make
72 * it less likely that check_region will find spurious 1-byte regions
75 void guard_region ( void *region
, size_t len
) {
79 for ( offset
= 0; offset
< len
; offset
+= 4 ) {
80 *((uint32_t *)(region
+ offset
)) = GUARD_SYMBOL
;
84 /* Check a region that has been guarded with guard_region() for
87 int check_region ( void *region
, size_t len
) {
88 uint8_t corrupted
= 0;
89 uint8_t in_corruption
= 0;
94 for ( offset
= 0; offset
< len
; offset
+= 4 ) {
95 test
= *((uint32_t *)(region
+ offset
)) = GUARD_SYMBOL
;
96 if ( ( in_corruption
== 0 ) &&
97 ( test
!= GUARD_SYMBOL
) ) {
98 /* Start of corruption */
99 if ( corrupted
== 0 ) {
101 printf ( "Region %p-%p (physical %#lx-%#lx) "
103 region
, region
+ len
,
104 virt_to_phys ( region
),
105 virt_to_phys ( region
+ len
) );
108 printf ( "--- offset %#lx ", offset
);
109 } else if ( ( in_corruption
!= 0 ) &&
110 ( test
== GUARD_SYMBOL
) ) {
111 /* End of corruption */
113 printf ( "to offset %#lx", offset
);
117 if ( in_corruption
!= 0 ) {
118 printf ( "to offset %#x (end of region)\n", len
-1 );
124 * Maximum number of separately coloured message streams
126 * Six is the realistic maximum; there are 8 basic ANSI colours, one
127 * of which will be the terminal default and one of which will be
128 * invisible on the terminal because it matches the background colour.
130 #define NUM_AUTO_COLOURS 6
132 /** A colour assigned to an autocolourised debug message stream */
134 /** Message stream ID */
135 unsigned long stream
;
136 /** Last recorded usage */
137 unsigned long last_used
;
141 * Choose colour index for debug autocolourisation
143 * @v stream Message stream ID
144 * @ret colour Colour ID
146 static int dbg_autocolour ( unsigned long stream
) {
147 static struct autocolour acs
[NUM_AUTO_COLOURS
];
148 static unsigned long use
;
151 unsigned int oldest_last_used
;
153 /* Increment usage iteration counter */
156 /* Scan through list for a currently assigned colour */
157 for ( i
= 0 ; i
< ( sizeof ( acs
) / sizeof ( acs
[0] ) ) ; i
++ ) {
158 if ( acs
[i
].stream
== stream
) {
159 acs
[i
].last_used
= use
;
164 /* No colour found; evict the oldest from the list */
166 oldest_last_used
= use
;
167 for ( i
= 0 ; i
< ( sizeof ( acs
) / sizeof ( acs
[0] ) ) ; i
++ ) {
168 if ( acs
[i
].last_used
< oldest_last_used
) {
169 oldest_last_used
= acs
[i
].last_used
;
173 acs
[oldest
].stream
= stream
;
174 acs
[oldest
].last_used
= use
;
179 * Select automatic colour for debug messages
181 * @v stream Message stream ID
183 void dbg_autocolourise ( unsigned long stream
) {
185 ( stream
? ( 31 + dbg_autocolour ( stream
) ) : 0 ) );
189 * Revert to normal colour
192 void dbg_decolourise ( void ) {
193 printf ( "\033[0m" );