blob: 4560a60b23e3ba5a2c9e4f56a8e56577508c7f73 [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
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Uwe Hermann2fbbb292008-07-08 16:18:38 +000018 */
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
Myles Watson44163f72009-08-24 15:25:11 +000037 mvwprintw(win, 0, col + 54, "RAM address: %10x", addr);
Uwe Hermann2fbbb292008-07-08 16:18:38 +000038
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]);
Ulf Jordan94c1bd82008-09-30 06:13:54 +000047 mvwprintw(win, row + y, 62 + count++, "%c",
48 isprint(ptr[i - 1]) ? ptr[i - 1] : ' ');
Uwe Hermann2fbbb292008-07-08 16:18:38 +000049 x += 3;
50 if (x == 24) /* One more space after column/byte 8. */
51 x++;
52 if (i % 16 == 0) {
53 y++; /* Start a newline after 16 bytes. */
54 x = count = 0;
55 }
56 }
57}
58
59static int ramdump_module_redraw(WINDOW *win)
60{
61 print_module_title(win, "RAM Dump");
62 dump_ram(win, cursor * 256, 2, 2);
63
64 return 0;
65}
66
67static int ramdump_module_handle(int key)
68{
69 switch (key) {
70 case KEY_DOWN:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000071 cursor++;
72 break;
73 case KEY_UP:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000074 cursor--;
75 break;
Myles Watson44163f72009-08-24 15:25:11 +000076 case KEY_RIGHT:
77 cursor += 256;
78 break;
79 case KEY_LEFT:
80 cursor -= 256;
Uwe Hermann2fbbb292008-07-08 16:18:38 +000081 break;
82 case KEY_PPAGE:
Myles Watson44163f72009-08-24 15:25:11 +000083 cursor += 4096; /* Jump in 1MB steps. */
84 break;
85 case KEY_NPAGE:
Uwe Hermann2fbbb292008-07-08 16:18:38 +000086 cursor -= 4096; /* Jump in 1MB steps. */
87 break;
88 }
89
90 if (cursor > cursor_max)
91 cursor = cursor_max;
92
93 if (cursor < 0)
94 cursor = 0;
95
96 return 1;
97}
98
99struct coreinfo_module ramdump_module = {
100 .name = "RAM Dump",
101 .init = ramdump_module_init,
102 .redraw = ramdump_module_redraw,
103 .handle = ramdump_module_handle,
104};
105
106#else
107
108struct coreinfo_module ramdump_module = {
109};
110
111#endif