|
@@ -15,25 +15,58 @@ void more ( void ) {
|
15
|
15
|
printf ( "\r \r" );
|
16
|
16
|
}
|
17
|
17
|
|
18
|
|
-/* Produce a paged hex dump of the specified data and length */
|
19
|
|
-void hex_dump ( const unsigned char *data, const unsigned int len ) {
|
20
|
|
- unsigned int index;
|
21
|
|
- for ( index = 0; index < len; index++ ) {
|
22
|
|
- if ( ( index % 16 ) == 0 ) {
|
23
|
|
- printf ( "\n" );
|
24
|
|
- }
|
25
|
|
- if ( ( index % 368 ) == 352 ) {
|
26
|
|
- more();
|
|
18
|
+/**
|
|
19
|
+ * Print row of a hex dump with specified display address
|
|
20
|
+ *
|
|
21
|
+ * @v dispaddr Display address
|
|
22
|
+ * @v data Data to print
|
|
23
|
+ * @v len Length of data
|
|
24
|
+ * @v offset Starting offset within data
|
|
25
|
+ */
|
|
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;
|
|
29
|
+ unsigned int i;
|
|
30
|
+ uint8_t byte;
|
|
31
|
+
|
|
32
|
+ printf ( "%08lx :", ( dispaddr + offset ) );
|
|
33
|
+ for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
|
|
34
|
+ if ( i >= len ) {
|
|
35
|
+ printf ( " " );
|
|
36
|
+ continue;
|
27
|
37
|
}
|
28
|
|
- if ( ( index % 16 ) == 0 ) {
|
29
|
|
- printf ( "%p [%lx] : %04x :", data + index,
|
30
|
|
- virt_to_phys ( data + index ), index );
|
|
38
|
+ printf ( " %02x", bytes[i] );
|
|
39
|
+ }
|
|
40
|
+ printf ( " : " );
|
|
41
|
+ for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
|
|
42
|
+ if ( i >= len ) {
|
|
43
|
+ printf ( " " );
|
|
44
|
+ continue;
|
31
|
45
|
}
|
32
|
|
- printf ( " %02x", data[index] );
|
|
46
|
+ byte = bytes[i];
|
|
47
|
+ if ( ( byte < 0x20 ) || ( byte >= 0x7f ) )
|
|
48
|
+ byte = '.';
|
|
49
|
+ printf ( "%c", byte );
|
33
|
50
|
}
|
34
|
51
|
printf ( "\n" );
|
35
|
52
|
}
|
36
|
53
|
|
|
54
|
+/**
|
|
55
|
+ * Print hex dump with specified display address
|
|
56
|
+ *
|
|
57
|
+ * @v dispaddr Display address
|
|
58
|
+ * @v data Data to print
|
|
59
|
+ * @v len Length of data
|
|
60
|
+ */
|
|
61
|
+void dbg_hex_dump_da ( unsigned long dispaddr, const void *data,
|
|
62
|
+ unsigned long len ) {
|
|
63
|
+ unsigned int offset;
|
|
64
|
+
|
|
65
|
+ for ( offset = 0 ; offset < len ; offset += 16 ) {
|
|
66
|
+ dbg_hex_dump_da_row ( dispaddr, data, len, offset );
|
|
67
|
+ }
|
|
68
|
+}
|
|
69
|
+
|
37
|
70
|
#define GUARD_SYMBOL ( ( 'M' << 24 ) | ( 'I' << 16 ) | ( 'N' << 8 ) | 'E' )
|
38
|
71
|
/* Fill a region with guard markers. We use a 4-byte pattern to make
|
39
|
72
|
* it less likely that check_region will find spurious 1-byte regions
|
|
@@ -87,14 +120,30 @@ int check_region ( void *region, size_t len ) {
|
87
|
120
|
return corrupted;
|
88
|
121
|
}
|
89
|
122
|
|
|
123
|
+/**
|
|
124
|
+ * Maximum number of separately coloured message streams
|
|
125
|
+ *
|
|
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.
|
|
129
|
+ */
|
90
|
130
|
#define NUM_AUTO_COLOURS 6
|
91
|
131
|
|
|
132
|
+/** A colour assigned to an autocolourised debug message stream */
|
92
|
133
|
struct autocolour {
|
93
|
|
- void * id;
|
|
134
|
+ /** Message stream ID */
|
|
135
|
+ unsigned long stream;
|
|
136
|
+ /** Last recorded usage */
|
94
|
137
|
unsigned long last_used;
|
95
|
138
|
};
|
96
|
139
|
|
97
|
|
-static int autocolourise ( void *id ) {
|
|
140
|
+/**
|
|
141
|
+ * Choose colour index for debug autocolourisation
|
|
142
|
+ *
|
|
143
|
+ * @v stream Message stream ID
|
|
144
|
+ * @ret colour Colour ID
|
|
145
|
+ */
|
|
146
|
+static int dbg_autocolour ( unsigned long stream ) {
|
98
|
147
|
static struct autocolour acs[NUM_AUTO_COLOURS];
|
99
|
148
|
static unsigned long use;
|
100
|
149
|
unsigned int i;
|
|
@@ -106,7 +155,7 @@ static int autocolourise ( void *id ) {
|
106
|
155
|
|
107
|
156
|
/* Scan through list for a currently assigned colour */
|
108
|
157
|
for ( i = 0 ; i < ( sizeof ( acs ) / sizeof ( acs[0] ) ) ; i++ ) {
|
109
|
|
- if ( acs[i].id == id ) {
|
|
158
|
+ if ( acs[i].stream == stream ) {
|
110
|
159
|
acs[i].last_used = use;
|
111
|
160
|
return i;
|
112
|
161
|
}
|
|
@@ -121,23 +170,25 @@ static int autocolourise ( void *id ) {
|
121
|
170
|
oldest = i;
|
122
|
171
|
}
|
123
|
172
|
}
|
124
|
|
- acs[oldest].id = id;
|
|
173
|
+ acs[oldest].stream = stream;
|
125
|
174
|
acs[oldest].last_used = use;
|
126
|
175
|
return oldest;
|
127
|
176
|
}
|
128
|
177
|
|
129
|
|
-/** printf() for debugging with automatic colourisation
|
|
178
|
+/**
|
|
179
|
+ * Select automatic colour for debug messages
|
130
|
180
|
*
|
131
|
|
- * @v id Message stream ID
|
132
|
|
- * @v fmt printf() format
|
133
|
|
- * @v ... printf() argument list
|
|
181
|
+ * @v stream Message stream ID
|
134
|
182
|
*/
|
135
|
|
-void dbg_printf_autocolour ( void *id, const char *fmt, ... ) {
|
136
|
|
- va_list args;
|
|
183
|
+void dbg_autocolourise ( unsigned long stream ) {
|
|
184
|
+ printf ( "\033[%dm",
|
|
185
|
+ ( stream ? ( 31 + dbg_autocolour ( stream ) ) : 0 ) );
|
|
186
|
+}
|
137
|
187
|
|
138
|
|
- printf ( "\033[%dm", ( id ? ( 31 + autocolourise ( id ) ) : 0 ) );
|
139
|
|
- va_start ( args, fmt );
|
140
|
|
- vprintf ( fmt, args );
|
141
|
|
- va_end ( args );
|
|
188
|
+/**
|
|
189
|
+ * Revert to normal colour
|
|
190
|
+ *
|
|
191
|
+ */
|
|
192
|
+void dbg_decolourise ( void ) {
|
142
|
193
|
printf ( "\033[0m" );
|
143
|
194
|
}
|