| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <ctype.h> |
| 5 |
#include <lib.h> |
| 6 |
|
| 7 |
void hexdump(const void *memory, size_t length) |
| 8 |
{ |
| 9 |
size_t i, j; |
| 10 |
uint8_t *line; |
| 11 |
int all_zero = 0; |
| 12 |
int all_one = 0; |
| 13 |
size_t num_bytes; |
| 14 |
|
| 15 |
for (i = 0; i < length; i += 16) { |
| 16 |
num_bytes = MIN(length - i, 16); |
| 17 |
line = ((uint8_t *)memory) + i; |
| 18 |
|
| 19 |
all_zero++; |
| 20 |
all_one++; |
| 21 |
for (j = 0; j < num_bytes; j++) { |
| 22 |
if (line[j] != 0) { |
| 23 |
all_zero = 0; |
| 24 |
break; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
for (j = 0; j < num_bytes; j++) { |
| 29 |
if (line[j] != 0xff) { |
| 30 |
all_one = 0; |
| 31 |
break; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
if ((all_zero < 2) && (all_one < 2)) { |
| 36 |
printk(BIOS_DEBUG, "%p:", memory + i); |
| 37 |
for (j = 0; j < num_bytes; j++) |
| 38 |
printk(BIOS_DEBUG, " %02x", line[j]); |
| 39 |
for (; j < 16; j++) |
| 40 |
printk(BIOS_DEBUG, " "); |
| 41 |
printk(BIOS_DEBUG, " "); |
| 42 |
for (j = 0; j < num_bytes; j++) |
| 43 |
printk(BIOS_DEBUG, "%c", |
| 44 |
isprint(line[j]) ? line[j] : '.'); |
| 45 |
printk(BIOS_DEBUG, "\n"); |
| 46 |
} else if ((all_zero == 2) || (all_one == 2)) { |
| 47 |
printk(BIOS_DEBUG, "...\n"); |
| 48 |
} |
| 49 |
} |
| 50 |
} |