blob: 019b3d9debafc4c3a7f019e27507ab1c3c5d82ac [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include "coreinfo.h"
21
22#ifdef CONFIG_MODULE_RAMDUMP
23
24static s64 cursor = 0;
25static s64 cursor_max = (1 * 1024 * 1024 * 1024); /* Max. 1 GB RAM for now. */
26
27static int ramdump_module_init(void)
28{
29 return 0;
30}
31
32static void dump_ram(WINDOW *win, uint32_t addr, int row, int col)
33{
34 int i, x = 0, y = 0, count = 0;
35 volatile uint8_t *ptr = (void *)(addr);
36
37 mvwprintw(win, 0, col + 54, "RAM address: %10d", addr);
38
39 /* Dump 256 bytes of RAM. */
40 for (i = 1; i < 257; i++) {
41 if (x == 0) {
42 mvwprintw(win, row + y, col - 1, "%08x", addr + 16 * y);
Ulf Jordanc5c14422008-08-09 20:15:00 +000043 mvwaddch(win, row + y, col + 59, '|');
44 mvwaddch(win, row + y, col + 76, '|');
Uwe Hermann2fbbb292008-07-08 16:18:38 +000045 }
46 mvwprintw(win, row + y, col + x + 9, "%02x", ptr[i - 1]);
47 mvwprintw(win, row + y, 62 + count++, "%c", ptr[i - 1]);
48 x += 3;
49 if (x == 24) /* One more space after column/byte 8. */
50 x++;
51 if (i % 16 == 0) {
52 y++; /* Start a newline after 16 bytes. */
53 x = count = 0;
54 }
55 }
56}
57
58static int ramdump_module_redraw(WINDOW *win)
59{
60 print_module_title(win, "RAM Dump");
61 dump_ram(win, cursor * 256, 2, 2);
62
63 return 0;
64}
65
66static int ramdump_module_handle(int key)
67{
68 switch (key) {
69 case KEY_DOWN:
70 if (cursor == cursor_max)
71 return 0;
72 cursor++;
73 break;
74 case KEY_UP:
75 if (cursor == 0)
76 return 0;
77 cursor--;
78 break;
79 case KEY_NPAGE:
80 if (cursor == cursor_max)
81 return 0;
82 cursor += 4096; /* Jump in 1MB steps. */
83 break;
84 case KEY_PPAGE:
85 if (cursor == 0)
86 return 0;
87 cursor -= 4096; /* Jump in 1MB steps. */
88 break;
89 }
90
91 if (cursor > cursor_max)
92 cursor = cursor_max;
93
94 if (cursor < 0)
95 cursor = 0;
96
97 return 1;
98}
99
100struct coreinfo_module ramdump_module = {
101 .name = "RAM Dump",
102 .init = ramdump_module_init,
103 .redraw = ramdump_module_redraw,
104 .handle = ramdump_module_handle,
105};
106
107#else
108
109struct coreinfo_module ramdump_module = {
110};
111
112#endif