2013-07-19 01:24:08 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but without any warranty; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <lib.h>
|
|
|
|
|
|
|
|
static int isprint(int c)
|
|
|
|
{
|
|
|
|
return (c >= 32 && c <= 126);
|
|
|
|
}
|
|
|
|
|
2013-12-27 14:43:44 +01:00
|
|
|
void hexdump(const void *memory, size_t length)
|
2013-07-19 01:24:08 +02:00
|
|
|
{
|
2013-12-27 14:43:44 +01:00
|
|
|
int i;
|
|
|
|
uint8_t *m;
|
|
|
|
int all_zero = 0;
|
2013-07-19 01:24:08 +02:00
|
|
|
|
2013-12-27 14:43:44 +01:00
|
|
|
m = (uint8_t *) memory;
|
2013-07-19 01:24:08 +02:00
|
|
|
|
2013-12-27 14:43:44 +01:00
|
|
|
for (i = 0; i < length; i += 16) {
|
|
|
|
int j;
|
2013-07-19 01:24:08 +02:00
|
|
|
|
2013-12-27 14:43:44 +01:00
|
|
|
all_zero++;
|
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
if (m[i + j] != 0) {
|
|
|
|
all_zero = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-07-19 01:24:08 +02:00
|
|
|
|
2013-12-27 14:43:44 +01:00
|
|
|
if (all_zero < 2) {
|
|
|
|
printk(BIOS_DEBUG, "%p:", memory + i);
|
|
|
|
for (j = 0; j < 16; j++)
|
|
|
|
printk(BIOS_DEBUG, " %02x", m[i + j]);
|
|
|
|
printk(BIOS_DEBUG, " ");
|
|
|
|
for (j = 0; j < 16; j++)
|
|
|
|
printk(BIOS_DEBUG, "%c",
|
|
|
|
isprint(m[i + j]) ? m[i + j] : '.');
|
|
|
|
printk(BIOS_DEBUG, "\n");
|
|
|
|
} else if (all_zero == 2) {
|
|
|
|
printk(BIOS_DEBUG, "...\n");
|
|
|
|
}
|
|
|
|
}
|
2013-07-19 01:24:08 +02:00
|
|
|
}
|
|
|
|
|
2014-05-03 16:21:34 +02:00
|
|
|
void hexdump32(char LEVEL, const void *d, size_t len)
|
2014-01-26 13:44:18 +01:00
|
|
|
{
|
2013-12-27 14:43:44 +01:00
|
|
|
int count = 0;
|
2014-01-26 13:44:18 +01:00
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
if (count % 8 == 0) {
|
2013-12-27 14:43:44 +01:00
|
|
|
printk(LEVEL, "\n");
|
2014-01-26 13:44:18 +01:00
|
|
|
printk(LEVEL, "%p:", d);
|
|
|
|
}
|
2013-12-27 14:43:44 +01:00
|
|
|
printk(LEVEL, " 0x%08lx", *(unsigned long *)d);
|
2014-01-26 13:44:18 +01:00
|
|
|
count++;
|
|
|
|
len--;
|
|
|
|
d += 4;
|
|
|
|
}
|
2013-07-19 01:24:08 +02:00
|
|
|
|
2013-12-27 14:43:44 +01:00
|
|
|
printk(LEVEL, "\n\n");
|
2014-01-26 13:44:18 +01:00
|
|
|
}
|