Browse Source

[debug] Add DBG_MD5() and related macros

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
66531a5918
2 changed files with 108 additions and 0 deletions
  1. 47
    0
      src/core/debug_md5.c
  2. 61
    0
      src/include/compiler.h

+ 47
- 0
src/core/debug_md5.c View File

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+FILE_LICENCE ( GPL2_OR_LATER );
20
+
21
+#include <stdio.h>
22
+#include <stdint.h>
23
+#include <ipxe/crypto.h>
24
+#include <ipxe/md5.h>
25
+
26
+/**
27
+ * Print an MD5 checksum with specified display address
28
+ *
29
+ * @v dispaddr		Display address
30
+ * @v data		Data to checksum
31
+ * @v len		Length of data
32
+ */
33
+void dbg_md5_da ( unsigned long dispaddr, const void *data,
34
+		  unsigned long len ) {
35
+	struct digest_algorithm *digest = &md5_algorithm;
36
+	uint8_t digest_ctx[digest->ctxsize];
37
+	uint8_t digest_out[digest->digestsize];
38
+	unsigned int i;
39
+
40
+	printf ( "md5sum ( %#08lx, %#lx ) = ", dispaddr, len );
41
+	digest_init ( digest, digest_ctx );
42
+	digest_update ( digest, digest_ctx, data, len );
43
+	digest_final ( digest, digest_ctx, digest_out );
44
+	for ( i = 0 ; i < sizeof ( digest_out ) ; i++ )
45
+		printf ( "%02x", digest_out[i] );
46
+	printf ( "\n" );
47
+}

+ 61
- 0
src/include/compiler.h View File

@@ -272,6 +272,8 @@ extern void dbg_autocolourise ( unsigned long id );
272 272
 extern void dbg_decolourise ( void );
273 273
 extern void dbg_hex_dump_da ( unsigned long dispaddr,
274 274
 			      const void *data, unsigned long len );
275
+extern void dbg_md5_da ( unsigned long dispaddr,
276
+			 const void *data, unsigned long len );
275 277
 extern void dbg_pause ( void );
276 278
 extern void dbg_more ( void );
277 279
 
@@ -349,6 +351,37 @@ int __debug_disable;
349 351
 		DBG_HDA_IF ( level, _data, _data, len );	\
350 352
 	} while ( 0 )
351 353
 
354
+/**
355
+ * Print an MD5 checksum if we are at a certain debug level
356
+ *
357
+ * @v level		Debug level
358
+ * @v dispaddr		Display address
359
+ * @v data		Data to print
360
+ * @v len		Length of data
361
+ */
362
+#define DBG_MD5A_IF( level, dispaddr, data, len )  do {		\
363
+		if ( DBG_ ## level ) {				\
364
+			union {					\
365
+				unsigned long ul;		\
366
+				typeof ( dispaddr ) raw;	\
367
+			} da;					\
368
+			da.raw = dispaddr;			\
369
+			dbg_md5_da ( da.ul, data, len );	\
370
+		}						\
371
+	} while ( 0 )
372
+
373
+/**
374
+ * Print an MD5 checksum if we are at a certain debug level
375
+ *
376
+ * @v level		Debug level
377
+ * @v data		Data to print
378
+ * @v len		Length of data
379
+ */
380
+#define DBG_MD5_IF( level, data, len ) do {			\
381
+		const void *_data = data;			\
382
+		DBG_MD5A_IF ( level, _data, _data, len );	\
383
+	} while ( 0 )
384
+
352 385
 /**
353 386
  * Prompt for key press if we are at a certain debug level
354 387
  *
@@ -419,6 +452,18 @@ int __debug_disable;
419 452
 		DBG_DC_IF ( level );				\
420 453
 	} while ( 0 )
421 454
 
455
+#define DBGC_MD5A_IF( level, id, ... ) do {			\
456
+		DBG_AC_IF ( level, id );			\
457
+		DBG_MD5A_IF ( level, __VA_ARGS__ );		\
458
+		DBG_DC_IF ( level );				\
459
+	} while ( 0 )
460
+
461
+#define DBGC_MD5_IF( level, id, ... ) do {			\
462
+		DBG_AC_IF ( level, id );			\
463
+		DBG_MD5_IF ( level, __VA_ARGS__ );		\
464
+		DBG_DC_IF ( level );				\
465
+	} while ( 0 )
466
+
422 467
 #define DBGC_PAUSE_IF( level, id ) do {				\
423 468
 		DBG_AC_IF ( level, id );			\
424 469
 		DBG_PAUSE_IF ( level );				\
@@ -436,11 +481,15 @@ int __debug_disable;
436 481
 #define DBG( ... )		DBG_IF		( LOG, ##__VA_ARGS__ )
437 482
 #define DBG_HDA( ... )		DBG_HDA_IF	( LOG, ##__VA_ARGS__ )
438 483
 #define DBG_HD( ... )		DBG_HD_IF	( LOG, ##__VA_ARGS__ )
484
+#define DBG_MD5A( ... )		DBG_MD5A_IF	( LOG, ##__VA_ARGS__ )
485
+#define DBG_MD5( ... )		DBG_MD5_IF	( LOG, ##__VA_ARGS__ )
439 486
 #define DBG_PAUSE( ... )	DBG_PAUSE_IF	( LOG, ##__VA_ARGS__ )
440 487
 #define DBG_MORE( ... )		DBG_MORE_IF	( LOG, ##__VA_ARGS__ )
441 488
 #define DBGC( ... )		DBGC_IF		( LOG, ##__VA_ARGS__ )
442 489
 #define DBGC_HDA( ... )		DBGC_HDA_IF	( LOG, ##__VA_ARGS__ )
443 490
 #define DBGC_HD( ... )		DBGC_HD_IF	( LOG, ##__VA_ARGS__ )
491
+#define DBGC_MD5A( ... )	DBGC_MD5A_IF	( LOG, ##__VA_ARGS__ )
492
+#define DBGC_MD5( ... )		DBGC_MD5_IF	( LOG, ##__VA_ARGS__ )
444 493
 #define DBGC_PAUSE( ... )	DBGC_PAUSE_IF	( LOG, ##__VA_ARGS__ )
445 494
 #define DBGC_MORE( ... )	DBGC_MORE_IF	( LOG, ##__VA_ARGS__ )
446 495
 
@@ -449,11 +498,15 @@ int __debug_disable;
449 498
 #define DBG2( ... )		DBG_IF		( EXTRA, ##__VA_ARGS__ )
450 499
 #define DBG2_HDA( ... )		DBG_HDA_IF	( EXTRA, ##__VA_ARGS__ )
451 500
 #define DBG2_HD( ... )		DBG_HD_IF	( EXTRA, ##__VA_ARGS__ )
501
+#define DBG2_MD5A( ... )	DBG_MD5A_IF	( EXTRA, ##__VA_ARGS__ )
502
+#define DBG2_MD5( ... )		DBG_MD5_IF	( EXTRA, ##__VA_ARGS__ )
452 503
 #define DBG2_PAUSE( ... )	DBG_PAUSE_IF	( EXTRA, ##__VA_ARGS__ )
453 504
 #define DBG2_MORE( ... )	DBG_MORE_IF	( EXTRA, ##__VA_ARGS__ )
454 505
 #define DBGC2( ... )		DBGC_IF		( EXTRA, ##__VA_ARGS__ )
455 506
 #define DBGC2_HDA( ... )	DBGC_HDA_IF	( EXTRA, ##__VA_ARGS__ )
456 507
 #define DBGC2_HD( ... )		DBGC_HD_IF	( EXTRA, ##__VA_ARGS__ )
508
+#define DBGC2_MD5A( ... )	DBGC_MD5A_IF	( EXTRA, ##__VA_ARGS__ )
509
+#define DBGC2_MD5( ... )	DBGC_MD5_IF	( EXTRA, ##__VA_ARGS__ )
457 510
 #define DBGC2_PAUSE( ... )	DBGC_PAUSE_IF	( EXTRA, ##__VA_ARGS__ )
458 511
 #define DBGC2_MORE( ... )	DBGC_MORE_IF	( EXTRA, ##__VA_ARGS__ )
459 512
 
@@ -462,11 +515,15 @@ int __debug_disable;
462 515
 #define DBGP( ... )		DBG_IF		( PROFILE, ##__VA_ARGS__ )
463 516
 #define DBGP_HDA( ... )		DBG_HDA_IF	( PROFILE, ##__VA_ARGS__ )
464 517
 #define DBGP_HD( ... )		DBG_HD_IF	( PROFILE, ##__VA_ARGS__ )
518
+#define DBGP_MD5A( ... )	DBG_MD5A_IF	( PROFILE, ##__VA_ARGS__ )
519
+#define DBGP_MD5( ... )		DBG_MD5_IF	( PROFILE, ##__VA_ARGS__ )
465 520
 #define DBGP_PAUSE( ... )	DBG_PAUSE_IF	( PROFILE, ##__VA_ARGS__ )
466 521
 #define DBGP_MORE( ... )	DBG_MORE_IF	( PROFILE, ##__VA_ARGS__ )
467 522
 #define DBGCP( ... )		DBGC_IF		( PROFILE, ##__VA_ARGS__ )
468 523
 #define DBGCP_HDA( ... )	DBGC_HDA_IF	( PROFILE, ##__VA_ARGS__ )
469 524
 #define DBGCP_HD( ... )		DBGC_HD_IF	( PROFILE, ##__VA_ARGS__ )
525
+#define DBGCP_MD5A( ... )	DBGC_MD5A_IF	( PROFILE, ##__VA_ARGS__ )
526
+#define DBGCP_MD5( ... )	DBGC_MD5_IF	( PROFILE, ##__VA_ARGS__ )
470 527
 #define DBGCP_PAUSE( ... )	DBGC_PAUSE_IF	( PROFILE, ##__VA_ARGS__ )
471 528
 #define DBGCP_MORE( ... )	DBGC_MORE_IF	( PROFILE, ##__VA_ARGS__ )
472 529
 
@@ -475,11 +532,15 @@ int __debug_disable;
475 532
 #define DBGIO( ... )		DBG_IF		( IO, ##__VA_ARGS__ )
476 533
 #define DBGIO_HDA( ... )	DBG_HDA_IF	( IO, ##__VA_ARGS__ )
477 534
 #define DBGIO_HD( ... )		DBG_HD_IF	( IO, ##__VA_ARGS__ )
535
+#define DBGIO_MD5A( ... )	DBG_MD5A_IF	( IO, ##__VA_ARGS__ )
536
+#define DBGIO_MD5( ... )	DBG_MD5_IF	( IO, ##__VA_ARGS__ )
478 537
 #define DBGIO_PAUSE( ... )	DBG_PAUSE_IF	( IO, ##__VA_ARGS__ )
479 538
 #define DBGIO_MORE( ... )	DBG_MORE_IF	( IO, ##__VA_ARGS__ )
480 539
 #define DBGCIO( ... )		DBGC_IF		( IO, ##__VA_ARGS__ )
481 540
 #define DBGCIO_HDA( ... )	DBGC_HDA_IF	( IO, ##__VA_ARGS__ )
482 541
 #define DBGCIO_HD( ... )	DBGC_HD_IF	( IO, ##__VA_ARGS__ )
542
+#define DBGCIO_MD5A( ... )	DBGC_MD5A_IF	( IO, ##__VA_ARGS__ )
543
+#define DBGCIO_MD5( ... )	DBGC_MD5_IF	( IO, ##__VA_ARGS__ )
483 544
 #define DBGCIO_PAUSE( ... )	DBGC_PAUSE_IF	( IO, ##__VA_ARGS__ )
484 545
 #define DBGCIO_MORE( ... )	DBGC_MORE_IF	( IO, ##__VA_ARGS__ )
485 546
 

Loading…
Cancel
Save