Bläddra i källkod

Split debug functions out into core/debug.c, so that they can be

automatically linked in on demand.

Corrected warnings in misc.c.  strtoul() really should be
  unsigned long strtoul ( const char *p, const char **endp, int base )
but such is not the ANSI standard.
tags/v0.9.3
Michael Brown 18 år sedan
förälder
incheckning
a4143e8c87
2 ändrade filer med 89 tillägg och 91 borttagningar
  1. 87
    0
      src/core/debug.c
  2. 2
    91
      src/core/misc.c

+ 87
- 0
src/core/debug.c Visa fil

@@ -0,0 +1,87 @@
1
+#include <stdint.h>
2
+#include <io.h>
3
+#include <console.h>
4
+
5
+void pause ( void ) {
6
+	printf ( "\nPress a key" );
7
+	getchar();
8
+	printf ( "\r           \r" );
9
+}
10
+
11
+void more ( void ) {
12
+	printf ( "---more---" );
13
+	getchar();
14
+	printf ( "\r          \r" );
15
+}
16
+
17
+/* Produce a paged hex dump of the specified data and length */
18
+void hex_dump ( const char *data, const unsigned int len ) {
19
+	unsigned int index;
20
+	for ( index = 0; index < len; index++ ) {
21
+		if ( ( index % 16 ) == 0 ) {
22
+			printf ( "\n" );
23
+		}
24
+		if ( ( index % 368 ) == 352 ) {
25
+			more();
26
+		}
27
+		if ( ( index % 16 ) == 0 ) {
28
+			printf ( "%X [%X] : %hX :", data + index,
29
+				 virt_to_phys ( data + index ), index );
30
+		}
31
+		printf ( " %hhX", data[index] );
32
+	}
33
+	printf ( "\n" );
34
+}
35
+
36
+#define GUARD_SYMBOL ( ( 'M' << 24 ) | ( 'I' << 16 ) | ( 'N' << 8 ) | 'E' )
37
+/* Fill a region with guard markers.  We use a 4-byte pattern to make
38
+ * it less likely that check_region will find spurious 1-byte regions
39
+ * of non-corruption.
40
+ */
41
+void guard_region ( void *region, size_t len ) {
42
+	uint32_t offset = 0;
43
+
44
+	len &= ~0x03;
45
+	for ( offset = 0; offset < len ; offset += 4 ) {
46
+		*((uint32_t *)(region + offset)) = GUARD_SYMBOL;
47
+	}
48
+}
49
+
50
+/* Check a region that has been guarded with guard_region() for
51
+ * corruption.
52
+ */
53
+int check_region ( void *region, size_t len ) {
54
+	uint8_t corrupted = 0;
55
+	uint8_t in_corruption = 0;
56
+	uint32_t offset = 0;
57
+	uint32_t test = 0;
58
+
59
+	len &= ~0x03;
60
+	for ( offset = 0; offset < len ; offset += 4 ) {
61
+		test = *((uint32_t *)(region + offset)) = GUARD_SYMBOL;
62
+		if ( ( in_corruption == 0 ) &&
63
+		     ( test != GUARD_SYMBOL ) ) {
64
+			/* Start of corruption */
65
+			if ( corrupted == 0 ) {
66
+				corrupted = 1;
67
+				printf ( "Region %#x-%#x (physical %#x-%#x) "
68
+					 "corrupted\n",
69
+					 region, region + len,
70
+					 virt_to_phys ( region ),
71
+					 virt_to_phys ( region + len ) );
72
+			}
73
+			in_corruption = 1;
74
+			printf ( "--- offset %#x ", offset );
75
+		} else if ( ( in_corruption != 0 ) &&
76
+			    ( test == GUARD_SYMBOL ) ) {
77
+			/* End of corruption */
78
+			in_corruption = 0;
79
+			printf ( "to offset %#x", offset );
80
+		}
81
+
82
+	}
83
+	if ( in_corruption != 0 ) {
84
+		printf ( "to offset %#x (end of region)\n", len-1 );
85
+	}
86
+	return corrupted;
87
+}

+ 2
- 91
src/core/misc.c Visa fil

@@ -154,7 +154,7 @@ int inet_aton ( const char *cp, struct in_addr *inp ) {
154 154
 	int j;
155 155
 	for(j = 0; j <= 3; j++) {
156 156
 		digits_start = p;
157
-		val = strtoul(p, &p, 10);
157
+		val = strtoul(p, ( char ** ) &p, 10);
158 158
 		if ((p == digits_start) || (val > 255)) return 0;
159 159
 		if ( ( j < 3 ) && ( *(p++) != '.' ) ) return 0;
160 160
 		ip = (ip << 8) | val;
@@ -175,100 +175,11 @@ unsigned long strtoul(const char *p, char **endp, int base)
175 175
 		p++;
176 176
 	}
177 177
 	if (endp)
178
-		*endp = p;
178
+		*endp = ( char * ) p;
179 179
 	return(ret);
180 180
 	
181 181
 }
182 182
 
183
-
184
-#if DEBUG_UTILS
185
-
186
-void pause ( void ) {
187
-	printf ( "\nPress a key" );
188
-	getchar();
189
-	printf ( "\r           \r" );
190
-}
191
-
192
-void more ( void ) {
193
-	printf ( "---more---" );
194
-	getchar();
195
-	printf ( "\r          \r" );
196
-}
197
-
198
-/* Produce a paged hex dump of the specified data and length */
199
-void hex_dump ( const char *data, const unsigned int len ) {
200
-	unsigned int index;
201
-	for ( index = 0; index < len; index++ ) {
202
-		if ( ( index % 16 ) == 0 ) {
203
-			printf ( "\n" );
204
-		}
205
-		if ( ( index % 368 ) == 352 ) {
206
-			more();
207
-		}
208
-		if ( ( index % 16 ) == 0 ) {
209
-			printf ( "%X [%X] : %hX :", data + index,
210
-				 virt_to_phys ( data + index ), index );
211
-		}
212
-		printf ( " %hhX", data[index] );
213
-	}
214
-	printf ( "\n" );
215
-}
216
-
217
-#define GUARD_SYMBOL ( ( 'M' << 24 ) | ( 'I' << 16 ) | ( 'N' << 8 ) | 'E' )
218
-/* Fill a region with guard markers.  We use a 4-byte pattern to make
219
- * it less likely that check_region will find spurious 1-byte regions
220
- * of non-corruption.
221
- */
222
-void guard_region ( void *region, size_t len ) {
223
-	uint32_t offset = 0;
224
-
225
-	len &= ~0x03;
226
-	for ( offset = 0; offset < len ; offset += 4 ) {
227
-		*((uint32_t *)(region + offset)) = GUARD_SYMBOL;
228
-	}
229
-}
230
-
231
-/* Check a region that has been guarded with guard_region() for
232
- * corruption.
233
- */
234
-int check_region ( void *region, size_t len ) {
235
-	uint8_t corrupted = 0;
236
-	uint8_t in_corruption = 0;
237
-	uint32_t offset = 0;
238
-	uint32_t test = 0;
239
-
240
-	len &= ~0x03;
241
-	for ( offset = 0; offset < len ; offset += 4 ) {
242
-		test = *((uint32_t *)(region + offset)) = GUARD_SYMBOL;
243
-		if ( ( in_corruption == 0 ) &&
244
-		     ( test != GUARD_SYMBOL ) ) {
245
-			/* Start of corruption */
246
-			if ( corrupted == 0 ) {
247
-				corrupted = 1;
248
-				printf ( "Region %#x-%#x (physical %#x-%#x) "
249
-					 "corrupted\n",
250
-					 region, region + len,
251
-					 virt_to_phys ( region ),
252
-					 virt_to_phys ( region + len ) );
253
-			}
254
-			in_corruption = 1;
255
-			printf ( "--- offset %#x ", offset );
256
-		} else if ( ( in_corruption != 0 ) &&
257
-			    ( test == GUARD_SYMBOL ) ) {
258
-			/* End of corruption */
259
-			in_corruption = 0;
260
-			printf ( "to offset %#x", offset );
261
-		}
262
-
263
-	}
264
-	if ( in_corruption != 0 ) {
265
-		printf ( "to offset %#x (end of region)\n", len-1 );
266
-	}
267
-	return corrupted;
268
-}
269
-
270
-#endif /* DEBUG_UTILS */
271
-
272 183
 /*
273 184
  * Local variables:
274 185
  *  c-basic-offset: 8

Laddar…
Avbryt
Spara