blob: 7907a381b57dbf877b04d8628f70fae2233fd319 [file] [log] [blame]
Stefan Reinauer2f38b072013-07-18 16:24:08 -07001/*
2 * Copyright 2013 Google Inc.
3 *
Stefan Reinauer2f38b072013-07-18 16:24:08 -07004 * 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.
8 *
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.
Stefan Reinauer2f38b072013-07-18 16:24:08 -070013 */
14
15#include <console/console.h>
16#include <lib.h>
17
18static int isprint(int c)
19{
20 return (c >= 32 && c <= 126);
21}
22
Paul Menzelf0a59912013-12-27 14:43:44 +010023void hexdump(const void *memory, size_t length)
Stefan Reinauer2f38b072013-07-18 16:24:08 -070024{
Paul Menzelf0a59912013-12-27 14:43:44 +010025 int i;
26 uint8_t *m;
27 int all_zero = 0;
Stefan Reinauer2f38b072013-07-18 16:24:08 -070028
Paul Menzelf0a59912013-12-27 14:43:44 +010029 m = (uint8_t *) memory;
Stefan Reinauer2f38b072013-07-18 16:24:08 -070030
Paul Menzelf0a59912013-12-27 14:43:44 +010031 for (i = 0; i < length; i += 16) {
32 int j;
Ben Gardnerb50d8fb2015-11-19 11:43:05 -060033 int left = MIN(length - i, 16);
Stefan Reinauer2f38b072013-07-18 16:24:08 -070034
Ben Gardnerb50d8fb2015-11-19 11:43:05 -060035 if (left < 16) {
36 all_zero = 0;
37 } else {
38 all_zero++;
39 for (j = 0; j < 16; j++) {
40 if (m[i + j] != 0) {
41 all_zero = 0;
42 break;
43 }
Paul Menzelf0a59912013-12-27 14:43:44 +010044 }
45 }
Stefan Reinauer2f38b072013-07-18 16:24:08 -070046
Paul Menzelf0a59912013-12-27 14:43:44 +010047 if (all_zero < 2) {
48 printk(BIOS_DEBUG, "%p:", memory + i);
Ben Gardnerb50d8fb2015-11-19 11:43:05 -060049 for (j = 0; j < left; j++)
Paul Menzelf0a59912013-12-27 14:43:44 +010050 printk(BIOS_DEBUG, " %02x", m[i + j]);
Ben Gardnerb50d8fb2015-11-19 11:43:05 -060051 for (j = left; j < 16; j++)
52 printk(BIOS_DEBUG, " ");
Paul Menzelf0a59912013-12-27 14:43:44 +010053 printk(BIOS_DEBUG, " ");
Ben Gardnerb50d8fb2015-11-19 11:43:05 -060054 for (j = 0; j < left; j++)
Paul Menzelf0a59912013-12-27 14:43:44 +010055 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");
60 }
61 }
Stefan Reinauer2f38b072013-07-18 16:24:08 -070062}
63
Paul Menzel60ec2ff2014-05-03 16:21:34 +020064void hexdump32(char LEVEL, const void *d, size_t len)
Kyösti Mälkki972d5cf2014-01-26 14:44:18 +020065{
Paul Menzelf0a59912013-12-27 14:43:44 +010066 int count = 0;
Stefan Reinauer2f38b072013-07-18 16:24:08 -070067
Kyösti Mälkki972d5cf2014-01-26 14:44:18 +020068 while (len > 0) {
69 if (count % 8 == 0) {
Paul Menzelf0a59912013-12-27 14:43:44 +010070 printk(LEVEL, "\n");
Kyösti Mälkki972d5cf2014-01-26 14:44:18 +020071 printk(LEVEL, "%p:", d);
72 }
Paul Menzelf0a59912013-12-27 14:43:44 +010073 printk(LEVEL, " 0x%08lx", *(unsigned long *)d);
Kyösti Mälkki972d5cf2014-01-26 14:44:18 +020074 count++;
75 len--;
76 d += 4;
77 }
78
Paul Menzelf0a59912013-12-27 14:43:44 +010079 printk(LEVEL, "\n\n");
Kyösti Mälkki972d5cf2014-01-26 14:44:18 +020080}