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