soc/intel/skylake: Correct address of I2C5 Device
[coreboot.git] / src / lib / hexdump.c
blob2861d6321e97b6167588e65d86185d2a59fc8f1b
1 /*
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>
16 #include <lib.h>
18 static int isprint(int c)
20 return (c >= 32 && c <= 126);
23 void hexdump(const void *memory, size_t length)
25 int i;
26 uint8_t *line;
27 int all_zero = 0;
28 int all_one = 0;
29 size_t num_bytes;
31 for (i = 0; i < length; i += 16) {
32 int j;
33 num_bytes = MIN(length - i, 16);
34 line = ((uint8_t *)memory) + i;
36 all_zero++;
37 all_one++;
38 for (j = 0; j < num_bytes; j++) {
39 if (line[j] != 0) {
40 all_zero = 0;
41 break;
45 for (j = 0; j < num_bytes; j++) {
46 if (line[j] != 0xff) {
47 all_one = 0;
48 break;
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]);
56 for (; j < 16; 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)
71 int count = 0;
73 while (len > 0) {
74 if (count % 8 == 0) {
75 printk(LEVEL, "\n");
76 printk(LEVEL, "%p:", d);
78 printk(LEVEL, " 0x%08lx", *(unsigned long *)d);
79 count++;
80 len--;
81 d += 4;
84 printk(LEVEL, "\n\n");