blob: 8401a61ab1c00e09bd27f6193d04f8e43484d88f [file] [log] [blame]
Uwe Hermann2fbbb292008-07-08 16:18:38 +00001/*
2 * This file is part of the coreinfo project.
3 *
4 * Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Uwe Hermann2fbbb292008-07-08 16:18:38 +000014 */
15
16#include "coreinfo.h"
17
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070018#if IS_ENABLED(CONFIG_MODULE_RAMDUMP)
Uwe Hermann2fbbb292008-07-08 16:18:38 +000019
20static s64 cursor = 0;
21static s64 cursor_max = (1 * 1024 * 1024 * 1024); /* Max. 1 GB RAM for now. */
22
23static int ramdump_module_init(void)
24{
25 return 0;
26}
27
28static void dump_ram(WINDOW *win, uint32_t addr, int row, int col)
29{
30 int i, x = 0, y = 0, count = 0;
31 volatile uint8_t *ptr = (void *)(addr);
32
Stefan Reinauer31575f62016-03-12 12:17:48 -080033 mvwprintw(win, 0, col + 54, "RAM address: 0x%08x", addr);
Uwe Hermann2fbbb292008-07-08 16:18:38 +000034
35 /* Dump 256 bytes of RAM. */
36 for (i = 1; i < 257; i++) {
37 if (x == 0) {
38 mvwprintw(win, row + y, col - 1, "%08x", addr + 16 * y);
Ulf Jordanc5c14422008-08-09 20:15:00 +000039 mvwaddch(win, row + y, col + 59, '|');
40 mvwaddch(win, row + y, col + 76, '|');
Uwe Hermann2fbbb292008-07-08 16:18:38 +000041 }
42 mvwprintw(win, row + y, col + x + 9, "%02x", ptr[i - 1]);
Ulf Jordan94c1bd82008-09-30 06:13:54 +000043 mvwprintw(win, row + y, 62 + count++, "%c",
44 isprint(ptr[i - 1]) ? ptr[i - 1] : ' ');
Uwe Hermann2fbbb292008-07-08 16:18:38 +000045 x += 3;
46 if (x == 24) /* One more space after column/byte 8. */
47 x++;
48 if (i % 16 == 0) {
49 y++; /* Start a newline after 16 bytes. */
50 x = count = 0;
51 }
52 }
53}
54
55static int ramdump_module_redraw(WINDOW *win)
56{
57 print_module_title(win, "RAM Dump");
58 dump_ram(win, cursor * 256, 2, 2);
59
60 return 0;
61}
62
63static int ramdump_module_handle(int key)
64{
65 switch (key) {
66 case KEY_DOWN:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000067 cursor++;
68 break;
69 case KEY_UP:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000070 cursor--;
71 break;
Myles Watson44163f72009-08-24 15:25:11 +000072 case KEY_RIGHT:
73 cursor += 256;
74 break;
75 case KEY_LEFT:
76 cursor -= 256;
Uwe Hermann2fbbb292008-07-08 16:18:38 +000077 break;
78 case KEY_PPAGE:
Myles Watson44163f72009-08-24 15:25:11 +000079 cursor += 4096; /* Jump in 1MB steps. */
80 break;
81 case KEY_NPAGE:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000082 cursor -= 4096; /* Jump in 1MB steps. */
83 break;
84 }
85
86 if (cursor > cursor_max)
87 cursor = cursor_max;
88
89 if (cursor < 0)
90 cursor = 0;
91
92 return 1;
93}
94
95struct coreinfo_module ramdump_module = {
96 .name = "RAM Dump",
97 .init = ramdump_module_init,
98 .redraw = ramdump_module_redraw,
99 .handle = ramdump_module_handle,
100};
101
102#else
103
104struct coreinfo_module ramdump_module = {
105};
106
107#endif