2 * Copyright 2013 Google Inc.
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
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but without any warranty; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <console/console.h>
18 static int isprint(int c
)
20 return (c
>= 32 && c
<= 126);
23 void hexdump(const void *memory
, size_t length
)
31 for (i
= 0; i
< length
; i
+= 16) {
33 num_bytes
= MIN(length
- i
, 16);
34 line
= ((uint8_t *)memory
) + i
;
38 for (j
= 0; j
< num_bytes
; j
++) {
45 for (j
= 0; j
< num_bytes
; j
++) {
46 if (line
[j
] != 0xff) {
52 if ((all_zero
< 2) && (all_one
< 2)) {
53 printk(BIOS_DEBUG
, "%p:", memory
+ i
);
54 for (j
= 0; j
< num_bytes
; j
++)
55 printk(BIOS_DEBUG
, " %02x", line
[j
]);
57 printk(BIOS_DEBUG
, " ");
58 printk(BIOS_DEBUG
, " ");
59 for (j
= 0; j
< num_bytes
; j
++)
60 printk(BIOS_DEBUG
, "%c",
61 isprint(line
[j
]) ? line
[j
] : '.');
62 printk(BIOS_DEBUG
, "\n");
63 } else if ((all_zero
== 2) || (all_one
== 2)) {
64 printk(BIOS_DEBUG
, "...\n");
69 void hexdump32(char LEVEL
, const void *d
, size_t len
)
76 printk(LEVEL
, "%p:", d
);
78 printk(LEVEL
, " 0x%08lx", *(unsigned long *)d
);
84 printk(LEVEL
, "\n\n");