blob: abb8472ff543a47c08011f6bd23b37ba088a8749 [file] [log] [blame]
Uwe Hermann2fbbb292008-07-08 16:18:38 +00001/*
Uwe Hermann2fbbb292008-07-08 16:18:38 +00002 *
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 Hermann2fbbb292008-07-08 16:18:38 +000013 */
14
15#include "coreinfo.h"
16
Julius Wernereab2a292019-03-05 16:55:15 -080017#if CONFIG(MODULE_RAMDUMP)
Uwe Hermann2fbbb292008-07-08 16:18:38 +000018
19static s64 cursor = 0;
20static s64 cursor_max = (1 * 1024 * 1024 * 1024); /* Max. 1 GB RAM for now. */
21
22static int ramdump_module_init(void)
23{
24 return 0;
25}
26
27static 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 Reinauer31575f62016-03-12 12:17:48 -080032 mvwprintw(win, 0, col + 54, "RAM address: 0x%08x", addr);
Uwe Hermann2fbbb292008-07-08 16:18:38 +000033
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 Jordanc5c14422008-08-09 20:15:00 +000038 mvwaddch(win, row + y, col + 59, '|');
39 mvwaddch(win, row + y, col + 76, '|');
Uwe Hermann2fbbb292008-07-08 16:18:38 +000040 }
41 mvwprintw(win, row + y, col + x + 9, "%02x", ptr[i - 1]);
Ulf Jordan94c1bd82008-09-30 06:13:54 +000042 mvwprintw(win, row + y, 62 + count++, "%c",
43 isprint(ptr[i - 1]) ? ptr[i - 1] : ' ');
Uwe Hermann2fbbb292008-07-08 16:18:38 +000044 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
54static 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
62static int ramdump_module_handle(int key)
63{
64 switch (key) {
65 case KEY_DOWN:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000066 cursor++;
67 break;
68 case KEY_UP:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000069 cursor--;
70 break;
Myles Watson44163f72009-08-24 15:25:11 +000071 case KEY_RIGHT:
72 cursor += 256;
73 break;
74 case KEY_LEFT:
75 cursor -= 256;
Uwe Hermann2fbbb292008-07-08 16:18:38 +000076 break;
77 case KEY_PPAGE:
Myles Watson44163f72009-08-24 15:25:11 +000078 cursor += 4096; /* Jump in 1MB steps. */
79 break;
80 case KEY_NPAGE:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000081 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
94struct 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
103struct coreinfo_module ramdump_module = {
104};
105
106#endif