drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / payloads / coreinfo / ramdump_module.c
blob762707f5e585ad2c1ac258f043350482ee34e89c
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include "coreinfo.h"
5 #if CONFIG(MODULE_RAMDUMP)
7 static s64 cursor = 0;
8 static s64 cursor_max = (1 * 1024 * 1024 * 1024); /* Max. 1 GB RAM for now. */
10 static int ramdump_module_init(void)
12 return 0;
15 static void dump_ram(WINDOW *win, uint32_t addr, int row, int col)
17 int i, x = 0, y = 0, count = 0;
18 volatile uint8_t *ptr = (void *)(addr);
20 mvwprintw(win, 0, col + 54, "RAM address: 0x%08x", addr);
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, '|');
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;
42 static int ramdump_module_redraw(WINDOW *win)
44 print_module_title(win, "RAM Dump");
45 dump_ram(win, cursor * 256, 2, 2);
47 return 0;
50 static int ramdump_module_handle(int key)
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;
73 if (cursor > cursor_max)
74 cursor = cursor_max;
76 if (cursor < 0)
77 cursor = 0;
79 return 1;
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,
89 #else
91 struct coreinfo_module ramdump_module = {
94 #endif