Stefan Reinauer | 2f38b07 | 2013-07-18 16:24:08 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 26 | static int isprint(int c) |
| 27 | { |
| 28 | return (c >= 32 && c <= 126); |
| 29 | } |
| 30 | |
Paul Menzel | f0a5991 | 2013-12-27 14:43:44 +0100 | [diff] [blame] | 31 | void hexdump(const void *memory, size_t length) |
Stefan Reinauer | 2f38b07 | 2013-07-18 16:24:08 -0700 | [diff] [blame] | 32 | { |
Paul Menzel | f0a5991 | 2013-12-27 14:43:44 +0100 | [diff] [blame] | 33 | int i; |
| 34 | uint8_t *m; |
| 35 | int all_zero = 0; |
Stefan Reinauer | 2f38b07 | 2013-07-18 16:24:08 -0700 | [diff] [blame] | 36 | |
Paul Menzel | f0a5991 | 2013-12-27 14:43:44 +0100 | [diff] [blame] | 37 | m = (uint8_t *) memory; |
Stefan Reinauer | 2f38b07 | 2013-07-18 16:24:08 -0700 | [diff] [blame] | 38 | |
Paul Menzel | f0a5991 | 2013-12-27 14:43:44 +0100 | [diff] [blame] | 39 | for (i = 0; i < length; i += 16) { |
| 40 | int j; |
Stefan Reinauer | 2f38b07 | 2013-07-18 16:24:08 -0700 | [diff] [blame] | 41 | |
Paul Menzel | f0a5991 | 2013-12-27 14:43:44 +0100 | [diff] [blame] | 42 | all_zero++; |
| 43 | for (j = 0; j < 16; j++) { |
| 44 | if (m[i + j] != 0) { |
| 45 | all_zero = 0; |
| 46 | break; |
| 47 | } |
| 48 | } |
Stefan Reinauer | 2f38b07 | 2013-07-18 16:24:08 -0700 | [diff] [blame] | 49 | |
Paul Menzel | f0a5991 | 2013-12-27 14:43:44 +0100 | [diff] [blame] | 50 | 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 Reinauer | 2f38b07 | 2013-07-18 16:24:08 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Paul Menzel | 60ec2ff | 2014-05-03 16:21:34 +0200 | [diff] [blame] | 65 | void hexdump32(char LEVEL, const void *d, size_t len) |
Kyösti Mälkki | 972d5cf | 2014-01-26 14:44:18 +0200 | [diff] [blame] | 66 | { |
Paul Menzel | f0a5991 | 2013-12-27 14:43:44 +0100 | [diff] [blame] | 67 | int count = 0; |
Stefan Reinauer | 2f38b07 | 2013-07-18 16:24:08 -0700 | [diff] [blame] | 68 | |
Kyösti Mälkki | 972d5cf | 2014-01-26 14:44:18 +0200 | [diff] [blame] | 69 | while (len > 0) { |
| 70 | if (count % 8 == 0) { |
Paul Menzel | f0a5991 | 2013-12-27 14:43:44 +0100 | [diff] [blame] | 71 | printk(LEVEL, "\n"); |
Kyösti Mälkki | 972d5cf | 2014-01-26 14:44:18 +0200 | [diff] [blame] | 72 | printk(LEVEL, "%p:", d); |
| 73 | } |
Paul Menzel | f0a5991 | 2013-12-27 14:43:44 +0100 | [diff] [blame] | 74 | printk(LEVEL, " 0x%08lx", *(unsigned long *)d); |
Kyösti Mälkki | 972d5cf | 2014-01-26 14:44:18 +0200 | [diff] [blame] | 75 | count++; |
| 76 | len--; |
| 77 | d += 4; |
| 78 | } |
| 79 | |
Paul Menzel | f0a5991 | 2013-12-27 14:43:44 +0100 | [diff] [blame] | 80 | printk(LEVEL, "\n\n"); |
Kyösti Mälkki | 972d5cf | 2014-01-26 14:44:18 +0200 | [diff] [blame] | 81 | } |