Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreinfo project. |
| 3 | * |
| 4 | * Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include "coreinfo.h" |
| 17 | |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 18 | #if CONFIG(MODULE_RAMDUMP) |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 19 | |
| 20 | static s64 cursor = 0; |
| 21 | static s64 cursor_max = (1 * 1024 * 1024 * 1024); /* Max. 1 GB RAM for now. */ |
| 22 | |
| 23 | static int ramdump_module_init(void) |
| 24 | { |
| 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | static void dump_ram(WINDOW *win, uint32_t addr, int row, int col) |
| 29 | { |
| 30 | int i, x = 0, y = 0, count = 0; |
| 31 | volatile uint8_t *ptr = (void *)(addr); |
| 32 | |
Stefan Reinauer | 31575f6 | 2016-03-12 12:17:48 -0800 | [diff] [blame] | 33 | mvwprintw(win, 0, col + 54, "RAM address: 0x%08x", addr); |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 34 | |
| 35 | /* Dump 256 bytes of RAM. */ |
| 36 | for (i = 1; i < 257; i++) { |
| 37 | if (x == 0) { |
| 38 | mvwprintw(win, row + y, col - 1, "%08x", addr + 16 * y); |
Ulf Jordan | c5c1442 | 2008-08-09 20:15:00 +0000 | [diff] [blame] | 39 | mvwaddch(win, row + y, col + 59, '|'); |
| 40 | mvwaddch(win, row + y, col + 76, '|'); |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 41 | } |
| 42 | mvwprintw(win, row + y, col + x + 9, "%02x", ptr[i - 1]); |
Ulf Jordan | 94c1bd8 | 2008-09-30 06:13:54 +0000 | [diff] [blame] | 43 | mvwprintw(win, row + y, 62 + count++, "%c", |
| 44 | isprint(ptr[i - 1]) ? ptr[i - 1] : ' '); |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 45 | x += 3; |
| 46 | if (x == 24) /* One more space after column/byte 8. */ |
| 47 | x++; |
| 48 | if (i % 16 == 0) { |
| 49 | y++; /* Start a newline after 16 bytes. */ |
| 50 | x = count = 0; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | static int ramdump_module_redraw(WINDOW *win) |
| 56 | { |
| 57 | print_module_title(win, "RAM Dump"); |
| 58 | dump_ram(win, cursor * 256, 2, 2); |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static int ramdump_module_handle(int key) |
| 64 | { |
| 65 | switch (key) { |
| 66 | case KEY_DOWN: |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 67 | cursor++; |
| 68 | break; |
| 69 | case KEY_UP: |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 70 | cursor--; |
| 71 | break; |
Myles Watson | 44163f7 | 2009-08-24 15:25:11 +0000 | [diff] [blame] | 72 | case KEY_RIGHT: |
| 73 | cursor += 256; |
| 74 | break; |
| 75 | case KEY_LEFT: |
| 76 | cursor -= 256; |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 77 | break; |
| 78 | case KEY_PPAGE: |
Myles Watson | 44163f7 | 2009-08-24 15:25:11 +0000 | [diff] [blame] | 79 | cursor += 4096; /* Jump in 1MB steps. */ |
| 80 | break; |
| 81 | case KEY_NPAGE: |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 82 | cursor -= 4096; /* Jump in 1MB steps. */ |
| 83 | break; |
| 84 | } |
| 85 | |
| 86 | if (cursor > cursor_max) |
| 87 | cursor = cursor_max; |
| 88 | |
| 89 | if (cursor < 0) |
| 90 | cursor = 0; |
| 91 | |
| 92 | return 1; |
| 93 | } |
| 94 | |
| 95 | struct coreinfo_module ramdump_module = { |
| 96 | .name = "RAM Dump", |
| 97 | .init = ramdump_module_init, |
| 98 | .redraw = ramdump_module_redraw, |
| 99 | .handle = ramdump_module_handle, |
| 100 | }; |
| 101 | |
| 102 | #else |
| 103 | |
| 104 | struct coreinfo_module ramdump_module = { |
| 105 | }; |
| 106 | |
| 107 | #endif |