1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include "coreinfo.h"
4
5 #if CONFIG(MODULE_RAMDUMP)
6
7 static s64 cursor = 0;
8 static s64 cursor_max = (1 * 1024 * 1024 * 1024); /* Max. 1 GB RAM for now. */
9
ramdump_module_init(void)10 static int ramdump_module_init(void)
11 {
12 return 0;
13 }
14
dump_ram(WINDOW * win,uint32_t addr,int row,int col)15 static 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
20 mvwprintw(win, 0, col + 54, "RAM address: 0x%08x", addr);
21
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);
26 mvwaddch(win, row + y, col + 59, '|');
27 mvwaddch(win, row + y, col + 76, '|');
28 }
29 mvwprintw(win, row + y, col + x + 9, "%02x", ptr[i - 1]);
30 mvwprintw(win, row + y, 62 + count++, "%c",
31 isprint(ptr[i - 1]) ? ptr[i - 1] : ' ');
32 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
ramdump_module_redraw(WINDOW * win)42 static 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
ramdump_module_handle(int key)50 static int ramdump_module_handle(int key)
51 {
52 switch (key) {
53 case KEY_DOWN:
54 cursor++;
55 break;
56 case KEY_UP:
57 cursor--;
58 break;
59 case KEY_RIGHT:
60 cursor += 256;
61 break;
62 case KEY_LEFT:
63 cursor -= 256;
64 break;
65 case KEY_PPAGE:
66 cursor += 4096; /* Jump in 1MB steps. */
67 break;
68 case KEY_NPAGE:
69 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
82 struct 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
91 struct coreinfo_module ramdump_module = {
92 };
93
94 #endif
95