Remove address from GPLv2 headers
[coreboot.git] / src / lib / hexdump.c
blob1329f222442f4b393727a8aacfce71b9d0d55a77
1 /*
2 * Copyright 2013 Google Inc.
4 * See file CREDITS for list of people who contributed to this
5 * project.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but without any warranty; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc.
22 #include <console/console.h>
23 #include <lib.h>
25 static int isprint(int c)
27 return (c >= 32 && c <= 126);
30 void hexdump(const void *memory, size_t length)
32 int i;
33 uint8_t *m;
34 int all_zero = 0;
36 m = (uint8_t *) memory;
38 for (i = 0; i < length; i += 16) {
39 int j;
41 all_zero++;
42 for (j = 0; j < 16; j++) {
43 if (m[i + j] != 0) {
44 all_zero = 0;
45 break;
49 if (all_zero < 2) {
50 printk(BIOS_DEBUG, "%p:", memory + i);
51 for (j = 0; j < 16; j++)
52 printk(BIOS_DEBUG, " %02x", m[i + j]);
53 printk(BIOS_DEBUG, " ");
54 for (j = 0; j < 16; j++)
55 printk(BIOS_DEBUG, "%c",
56 isprint(m[i + j]) ? m[i + j] : '.');
57 printk(BIOS_DEBUG, "\n");
58 } else if (all_zero == 2) {
59 printk(BIOS_DEBUG, "...\n");
64 void hexdump32(char LEVEL, const void *d, size_t len)
66 int count = 0;
68 while (len > 0) {
69 if (count % 8 == 0) {
70 printk(LEVEL, "\n");
71 printk(LEVEL, "%p:", d);
73 printk(LEVEL, " 0x%08lx", *(unsigned long *)d);
74 count++;
75 len--;
76 d += 4;
79 printk(LEVEL, "\n\n");