2 * Entry points for 15-410 extensions
3 * NetWatch system management mode administration console
5 * Copyright (c) 2008 Jacob Potter and Joshua Wise. All rights reserved.
6 * This program is free software; you can redistribute and/or modify it under
7 * the terms found in the file LICENSE in the root of this source tree.
14 #include <video_defines.h>
18 #define CONSCOLOR 0x1F
20 unsigned char oldcons[80 * 25 * 2];
22 static unsigned char vga_read(unsigned char idx)
24 outb(CRTC_IDX_REG, idx);
25 return inb(CRTC_DATA_REG);
28 static char * vga_base()
32 + (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
33 + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1)
37 static void grey_console()
42 for (i = 0; i < 80*25; i++, p+=2)
43 p[1] &= ~0xF8; /* Clear the background and any brightness. */
46 #define CHAR(x, y) (base[((y)*80+(x))*2])
47 #define COLOR(x, y) (base[((y)*80+(x))*2+1])
49 static void ui_frame(int xp, int yp, int xs, int ys, char *title)
52 char *base = vga_base();
54 /* Blank and fill the region. */
55 for (y = yp; y <= (yp + ys); y++)
56 for (x = xp; x <= (xp + xs); x++)
59 COLOR(x, y) = CONSCOLOR;
62 /* Draw the top and the bottom (and the bar if need be). */
63 for (x = xp; x <= (xp + xs); x++)
65 CHAR(x, yp) = 0xCD /* double line horizontal */;
66 CHAR(x, yp+ys) = 0xCD /* double line horizontal */;
68 CHAR(x, yp+2) = 0xC4 /* single line horizontal */;
71 /* Draw the left and right. */
72 for (y = yp; y <= (yp + ys); y++)
74 CHAR(xp, y) = 0xBA /* double line vertical */;
75 CHAR(xp+xs, y) = 0xBA /* double line vertical */;
78 /* Drop in the corners. */
80 CHAR(xp+xs, yp) = 0xBB;
81 CHAR(xp, yp+ys) = 0xC8;
82 CHAR(xp+xs, yp+ys) = 0xBC;
85 CHAR(xp, yp+2) = 0xC7;
86 CHAR(xp+xs, yp+2) = 0xB6;
89 /* Drop in the text. */
91 for (x = (xs - strlen(title)) / 2 + xp; *title; x++, title++)
92 CHAR(x, yp+1) = *title;
95 static void ui_label(int xp, int yp, char *s)
98 char *base = vga_base();
100 for (x = xp; *s; x++, s++)
104 typedef enum ui_element_type {
110 typedef union ui_element {
111 ui_element_type_t type;
113 ui_element_type_t type;
119 ui_element_type_t type;
125 static ui_element_t mainmenu[] = {
130 .title = "NetWatch main menu" } },
134 .text = "Options:" } },
138 .text = "q - Return to system" } },
142 static void ui_render(ui_element_t *ui)
144 for (; ui->type != UI_END; ui++)
148 ui_frame(ui->frame.xp, ui->frame.yp,
149 ui->frame.xs, ui->frame.ys,
153 ui_label(ui->label.xp, ui->label.yp,
162 void cs410_pwrbtn_handler(smi_event_t ev)
164 smram_state_t old_state;
166 outputf("410watch: Power button event");
168 /* Save off the console. */
169 old_state = smram_save_state();
170 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
171 memcpy(oldcons, vga_base(), 80*25*2);
173 /* Pull a Simics, and grey out the console -- why not? */
176 /* Show the main menu. */
179 /* Allow access to data in ASEG. */
180 smram_restore_state(old_state);
182 /* Now just sit for a while to show off our newly greyed console. */
184 char *p = vga_base() + (11*80+12)*2;
185 extern int getchar();
186 while ((c = getchar()) != 'q')
188 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
191 smram_restore_state(old_state);
194 /* Put the console back. */
195 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
196 memcpy(vga_base(), oldcons, 80*25*2);
197 smram_restore_state(old_state);