blob: 762707f5e585ad2c1ac258f043350482ee34e89c [file] [log] [blame]
Jacob Garber07201d72020-09-08 12:25:44 -06001/* SPDX-License-Identifier: GPL-2.0-only */
Uwe Hermann2fbbb292008-07-08 16:18:38 +00002
3#include "coreinfo.h"
4
Julius Wernereab2a292019-03-05 16:55:15 -08005#if CONFIG(MODULE_RAMDUMP)
Uwe Hermann2fbbb292008-07-08 16:18:38 +00006
7static s64 cursor = 0;
8static s64 cursor_max = (1 * 1024 * 1024 * 1024); /* Max. 1 GB RAM for now. */
9
10static int ramdump_module_init(void)
11{
12 return 0;
13}
14
15static void dump_ram(WINDOW *win, uint32_t addr, int row, int col)
16{
17 int i, x = 0, y = 0, count = 0;
18 volatile uint8_t *ptr = (void *)(addr);
19
Stefan Reinauer31575f62016-03-12 12:17:48 -080020 mvwprintw(win, 0, col + 54, "RAM address: 0x%08x", addr);
Uwe Hermann2fbbb292008-07-08 16:18:38 +000021
22 /* Dump 256 bytes of RAM. */
23 for (i = 1; i < 257; i++) {
24 if (x == 0) {
25 mvwprintw(win, row + y, col - 1, "%08x", addr + 16 * y);
Ulf Jordanc5c14422008-08-09 20:15:00 +000026 mvwaddch(win, row + y, col + 59, '|');
27 mvwaddch(win, row + y, col + 76, '|');
Uwe Hermann2fbbb292008-07-08 16:18:38 +000028 }
29 mvwprintw(win, row + y, col + x + 9, "%02x", ptr[i - 1]);
Ulf Jordan94c1bd82008-09-30 06:13:54 +000030 mvwprintw(win, row + y, 62 + count++, "%c",
31 isprint(ptr[i - 1]) ? ptr[i - 1] : ' ');
Uwe Hermann2fbbb292008-07-08 16:18:38 +000032 x += 3;
33 if (x == 24) /* One more space after column/byte 8. */
34 x++;
35 if (i % 16 == 0) {
36 y++; /* Start a newline after 16 bytes. */
37 x = count = 0;
38 }
39 }
40}
41
42static int ramdump_module_redraw(WINDOW *win)
43{
44 print_module_title(win, "RAM Dump");
45 dump_ram(win, cursor * 256, 2, 2);
46
47 return 0;
48}
49
50static int ramdump_module_handle(int key)
51{
52 switch (key) {
53 case KEY_DOWN:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000054 cursor++;
55 break;
56 case KEY_UP:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000057 cursor--;
58 break;
Myles Watson44163f72009-08-24 15:25:11 +000059 case KEY_RIGHT:
60 cursor += 256;
61 break;
62 case KEY_LEFT:
63 cursor -= 256;
Uwe Hermann2fbbb292008-07-08 16:18:38 +000064 break;
65 case KEY_PPAGE:
Myles Watson44163f72009-08-24 15:25:11 +000066 cursor += 4096; /* Jump in 1MB steps. */
67 break;
68 case KEY_NPAGE:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000069 cursor -= 4096; /* Jump in 1MB steps. */
70 break;
71 }
72
73 if (cursor > cursor_max)
74 cursor = cursor_max;
75
76 if (cursor < 0)
77 cursor = 0;
78
79 return 1;
80}
81
82struct coreinfo_module ramdump_module = {
83 .name = "RAM Dump",
84 .init = ramdump_module_init,
85 .redraw = ramdump_module_redraw,
86 .handle = ramdump_module_handle,
87};
88
89#else
90
91struct coreinfo_module ramdump_module = {
92};
93
94#endif