port_enable and port_reset must change atomically.
[coreboot.git] / payloads / coreinfo / ramdump_module.c
1 /*
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
24 static s64 cursor = 0;
25 static s64 cursor_max = (1 * 1024 * 1024 * 1024); /* Max. 1 GB RAM for now. */
26
27 static int ramdump_module_init(void)
28 {
29         return 0;
30 }
31
32 static 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: %10x", 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);
43                         mvwaddch(win, row + y, col + 59, '|');
44                         mvwaddch(win, row + y, col + 76, '|');
45                 }
46                 mvwprintw(win, row + y, col + x + 9, "%02x", ptr[i - 1]);
47                 mvwprintw(win, row + y, 62 + count++, "%c",
48                           isprint(ptr[i - 1]) ? ptr[i - 1] : ' ');
49                 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
59 static 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
67 static int ramdump_module_handle(int key)
68 {
69         switch (key) {
70         case KEY_DOWN:
71                 cursor++;
72                 break;
73         case KEY_UP:
74                 cursor--;
75                 break;
76         case KEY_RIGHT:
77                 cursor += 256;
78                 break;
79         case KEY_LEFT:
80                 cursor -= 256;
81                 break;
82         case KEY_PPAGE:
83                 cursor += 4096; /* Jump in 1MB steps. */
84                 break;
85         case KEY_NPAGE:
86                 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
99 struct 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
108 struct coreinfo_module ramdump_module = {
109 };
110
111 #endif