blob: a15c5cdb1160586f7df7fdc60749b46aea04ba73 [file] [log] [blame]
Stefan Reinauer2f38b072013-07-18 16:24:08 -07001/*
2 * Copyright 2013 Google Inc.
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
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.
11 *
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.
16 *
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., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <console/console.h>
24#include <lib.h>
25
26static int isprint(int c)
27{
28 return (c >= 32 && c <= 126);
29}
30
Paul Menzelf0a59912013-12-27 14:43:44 +010031void hexdump(const void *memory, size_t length)
Stefan Reinauer2f38b072013-07-18 16:24:08 -070032{
Paul Menzelf0a59912013-12-27 14:43:44 +010033 int i;
34 uint8_t *m;
35 int all_zero = 0;
Stefan Reinauer2f38b072013-07-18 16:24:08 -070036
Paul Menzelf0a59912013-12-27 14:43:44 +010037 m = (uint8_t *) memory;
Stefan Reinauer2f38b072013-07-18 16:24:08 -070038
Paul Menzelf0a59912013-12-27 14:43:44 +010039 for (i = 0; i < length; i += 16) {
40 int j;
Stefan Reinauer2f38b072013-07-18 16:24:08 -070041
Paul Menzelf0a59912013-12-27 14:43:44 +010042 all_zero++;
43 for (j = 0; j < 16; j++) {
44 if (m[i + j] != 0) {
45 all_zero = 0;
46 break;
47 }
48 }
Stefan Reinauer2f38b072013-07-18 16:24:08 -070049
Paul Menzelf0a59912013-12-27 14:43:44 +010050 if (all_zero < 2) {
51 printk(BIOS_DEBUG, "%p:", memory + i);
52 for (j = 0; j < 16; j++)
53 printk(BIOS_DEBUG, " %02x", m[i + j]);
54 printk(BIOS_DEBUG, " ");
55 for (j = 0; j < 16; j++)
56 printk(BIOS_DEBUG, "%c",
57 isprint(m[i + j]) ? m[i + j] : '.');
58 printk(BIOS_DEBUG, "\n");
59 } else if (all_zero == 2) {
60 printk(BIOS_DEBUG, "...\n");
61 }
62 }
Stefan Reinauer2f38b072013-07-18 16:24:08 -070063}
64
Paul Menzel60ec2ff2014-05-03 16:21:34 +020065void hexdump32(char LEVEL, const void *d, size_t len)
Kyösti Mälkki972d5cf2014-01-26 14:44:18 +020066{
Paul Menzelf0a59912013-12-27 14:43:44 +010067 int count = 0;
Stefan Reinauer2f38b072013-07-18 16:24:08 -070068
Kyösti Mälkki972d5cf2014-01-26 14:44:18 +020069 while (len > 0) {
70 if (count % 8 == 0) {
Paul Menzelf0a59912013-12-27 14:43:44 +010071 printk(LEVEL, "\n");
Kyösti Mälkki972d5cf2014-01-26 14:44:18 +020072 printk(LEVEL, "%p:", d);
73 }
Paul Menzelf0a59912013-12-27 14:43:44 +010074 printk(LEVEL, " 0x%08lx", *(unsigned long *)d);
Kyösti Mälkki972d5cf2014-01-26 14:44:18 +020075 count++;
76 len--;
77 d += 4;
78 }
79
Paul Menzelf0a59912013-12-27 14:43:44 +010080 printk(LEVEL, "\n\n");
Kyösti Mälkki972d5cf2014-01-26 14:44:18 +020081}