1 | /*␊ |
2 | * Copyright (c) 2009 Evan Lojewski. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | ␊ |
6 | /*␊ |
7 | * cparm : cleaned␊ |
8 | */␊ |
9 | ␊ |
10 | ␊ |
11 | #include "libsaio.h"␊ |
12 | #include "platform.h"␊ |
13 | #include "graphic_utils.h"␊ |
14 | #include "embedded.h"␊ |
15 | ␊ |
16 | #include "picopng.h"␊ |
17 | #include "gui.h"␊ |
18 | ␊ |
19 | #include "modules.h"␊ |
20 | ␊ |
21 | enum {␊ |
22 | kMenuTopRow = 5,␊ |
23 | kMenuMaxItems = 10,␊ |
24 | kScreenLastRow = 24␊ |
25 | };␊ |
26 | ␊ |
27 | enum {␊ |
28 | ␉kBackspaceKey␉= 0x08,␊ |
29 | ␉kTabKey␉␉␉= 0x09,␊ |
30 | ␉kReturnKey␉␉= 0x0d,␊ |
31 | ␉kEscapeKey␉␉= 0x1b,␊ |
32 | ␉kUpArrowkey␉␉= 0x4800, ␊ |
33 | ␉kDownArrowkey␉= 0x5000,␊ |
34 | ␉kASCIIKeyMask␉= 0x7f,␊ |
35 | ␉kF5Key␉␉␉= 0x3f00,␊ |
36 | ␉kF10Key␉␉␉= 0x4400␊ |
37 | };␊ |
38 | /*␊ |
39 | * Flags to the booter or kernel␊ |
40 | */␊ |
41 | #define kVerboseModeFlag␉"-v"␊ |
42 | #define kSafeModeFlag␉␉"-x"␊ |
43 | #define kIgnoreCachesFlag␉"-f"␊ |
44 | #define kSingleUserModeFlag␉"-s"␊ |
45 | #define kIgnorePrelinkKern "-F"␊ |
46 | #define kIgnoreBootFileFlag␉"-B"␊ |
47 | ␊ |
48 | /*␊ |
49 | * Booter behavior control␊ |
50 | */␊ |
51 | #define kBootTimeout -1␊ |
52 | #define kCDBootTimeout 8␊ |
53 | ␊ |
54 | /*␊ |
55 | * A global set by boot() to record the device that the booter␊ |
56 | * was loaded from.␊ |
57 | */␊ |
58 | #define Cache_len_name 512␊ |
59 | ␊ |
60 | /*␊ |
61 | * Boot Modes␊ |
62 | */␊ |
63 | enum {␊ |
64 | kBootModeNormal = 0,␊ |
65 | kBootModeSafe = 1,␊ |
66 | kBootModeSecure = 2,␊ |
67 | kBootModeQuiet = 4␊ |
68 | };␊ |
69 | typedef struct {␊ |
70 | int x;␊ |
71 | int y;␊ |
72 | int type;␊ |
73 | } CursorState;␊ |
74 | ␊ |
75 | /* Kabyl: BooterLog */␊ |
76 | #define BOOTER_LOG_SIZE (128 * 1024)␊ |
77 | #define SAFE_LOG_SIZE 134␊ |
78 | ␊ |
79 | static bool useGUI = true;␊ |
80 | static int␉␉␉selectIndex = 0;␊ |
81 | ␊ |
82 | void GUI_Kernel_Start_hook(void* kernelEntry, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
83 | void GUI_PreBoot_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
84 | ␊ |
85 | int GUI_getBootOptions(bool firstRun);␊ |
86 | ␊ |
87 | static void GUI_updateBootArgs( int key );␊ |
88 | void GUI_clearBootArgs(void);␊ |
89 | void GUI_addBootArg(const char * argStr);␊ |
90 | ␊ |
91 | static void GUI_showBootPrompt(int row, bool visible);␊ |
92 | static void GUI_showMenu( const MenuItem * items, int count, int selection, int row, int height );␊ |
93 | static int GUI_updateMenu( int key, void ** paramPtr );␊ |
94 | static void GUI_showHelp(void);␊ |
95 | static void GUI_showMessage(char *message);␊ |
96 | ␊ |
97 | int GUI_printf(const char * fmt, ...);␊ |
98 | int GUI_verbose(const char * fmt, ...);␊ |
99 | int GUI_error(const char * fmt, ...);␊ |
100 | void GUI_stop(const char * fmt, ...);␊ |
101 | ␊ |
102 | ␊ |
103 | /* console.c */␊ |
104 | struct putc_info {␊ |
105 | char * str;␊ |
106 | char * last_str;␊ |
107 | };␊ |
108 | void sputc(int c, struct putc_info * pi);␊ |
109 | extern char *msgbuf;␊ |
110 | extern char *cursor;␊ |
111 | ␊ |
112 | static void (*showTextBuffer)(char *, int ) = NULL;␊ |
113 | static char *(*getMemoryInfoString)(void) = NULL;␊ |
114 | static BVRef (*getBvChain)(void) = NULL;␊ |
115 | static void (*lspci)(void) = NULL;␊ |
116 | static void (*printMemoryInfo)(void) = NULL;␊ |
117 | static void (*showHelp)(void) = NULL;␊ |
118 | static void (*showTextFile)(const char * ) = NULL;␊ |
119 | static void (*showMessage)(char * ) = NULL;␊ |
120 | ␊ |
121 | static const MenuItem * gMenuItems = NULL;␊ |
122 | static MenuItem * menuItems = NULL;␊ |
123 | ␊ |
124 | static char gBootArgs[BOOT_STRING_LEN];␊ |
125 | static char * gBootArgsPtr = gBootArgs;␊ |
126 | static char * gBootArgsEnd = gBootArgs + BOOT_STRING_LEN - 1;␊ |
127 | static char booterCommand[BOOT_STRING_LEN];␊ |
128 | static char booterParam[BOOT_STRING_LEN];␊ |
129 | ␊ |
130 | static void printMenuItem( const MenuItem * item, int highlight )␊ |
131 | {␊ |
132 | printf(" ");␊ |
133 | ␉␊ |
134 | if ( highlight )␊ |
135 | putca(' ', 0x70, strlen(item->name) + 4);␊ |
136 | else␊ |
137 | putca(' ', 0x07, 40);␊ |
138 | ␉␊ |
139 | printf(" %40s\n", item->name);␊ |
140 | }␊ |
141 | //==========================================================================␊ |
142 | ␊ |
143 | static void changeCursor( int col, int row, int type, CursorState * cs )␊ |
144 | {␊ |
145 | if (cs) getCursorPositionAndType( &cs->x, &cs->y, &cs->type );␊ |
146 | setCursorType( type );␊ |
147 | setCursorPosition( col, row, 0 );␊ |
148 | }␊ |
149 | ␊ |
150 | static void moveCursor( int col, int row )␊ |
151 | {␊ |
152 | setCursorPosition( col, row, 0 );␊ |
153 | }␊ |
154 | ␊ |
155 | static int restoreCursor( const CursorState * cs )␊ |
156 | {␊ |
157 | if (!cs) {␊ |
158 | return 0;␊ |
159 | }␊ |
160 | ␊ |
161 | setCursorPosition( cs->x, cs->y, 0 );␊ |
162 | setCursorType( cs->type );␊ |
163 | ␊ |
164 | return 1;␊ |
165 | }␊ |
166 | ␊ |
167 | char GUI_bootRescanPrompt[] =␊ |
168 | "Press Enter to start up Darwin/x86 with no options, or you can:\n"␊ |
169 | " Press F5 after you swapped the media. The drive will be rescanned.\n"␊ |
170 | " Type -v and press Enter to start up with diagnostic messages\n"␊ |
171 | " Type ? and press Enter to learn about advanced startup options\n\n"␊ |
172 | "boot: ";␊ |
173 | ␊ |
174 | ␊ |
175 | static bool KernelStart = false;␊ |
176 | /**␊ |
177 | ** The kernel is about to start, draw the boot graphics if we are not in␊ |
178 | ** verbose mode.␊ |
179 | **/␊ |
180 | void GUI_ExecKernel_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
181 | {␊ |
182 | ␉if(!gVerboseMode)␊ |
183 | ␉{␊ |
184 | ␉␉// Note: shouldn't be needed, but just in case␊ |
185 | ␉␉drawBootGraphics();␊ |
186 | ␉}␊ |
187 | ␉else␊ |
188 | ␉{␊ |
189 | #if UNUSED␊ |
190 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
191 | #else␊ |
192 | ␉␉setVideoMode(GRAPHICS_MODE);␊ |
193 | #endif␊ |
194 | ␉␉␊ |
195 | ␉}␊ |
196 | ␉KernelStart = true;␊ |
197 | }␊ |
198 | ␊ |
199 | /**␊ |
200 | ** A boot option has been selected, disable the graphical elements on screen.␊ |
201 | **/␊ |
202 | void GUI_PreBoot_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
203 | {␉␉␊ |
204 | ␉// Turn off any GUI elements␊ |
205 | ␉if( getVideoMode() == GRAPHICS_MODE )␊ |
206 | ␉{␊ |
207 | ␉␉gui.devicelist.draw = false;␊ |
208 | ␉␉gui.bootprompt.draw = false;␊ |
209 | ␉␉gui.menu.draw = false;␊ |
210 | ␉␉gui.infobox.draw = false;␊ |
211 | ␉␉gui.logo.draw = false;␊ |
212 | ␉␉drawBackground();␉␉␊ |
213 | ␉␉updateVRAM();␊ |
214 | ␊ |
215 | ␉␉if(!gVerboseMode)␊ |
216 | ␉␉{␊ |
217 | ␉␉␉// Disable outputs, they will still show in the boot log.␊ |
218 | ␉␉␉replace_system_function("_printf", &GUI_verbose);␊ |
219 | ␉␉␉//drawBootGraphics();␊ |
220 | ␉␉}␊ |
221 | ␉␉␊ |
222 | ␉}␉␊ |
223 | ␊ |
224 | }␊ |
225 | ␊ |
226 | void GUI_diplay_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
227 | {␊ |
228 | ␉// Start and display the gui␊ |
229 | ␉msglog("* Attempting to Display GUI\n");␊ |
230 | ␊ |
231 | ␉if (initGUI())␊ |
232 | ␉{␊ |
233 | ␉␉␊ |
234 | ␉␉useGUI = false; // initGUI() returned with an error, disabling GUI.␉␉␊ |
235 | ␉␉msglog("* GUI failed to Display, or disabled by user (a.k.a you)\n");␊ |
236 | ␊ |
237 | ␉␉␊ |
238 | ␉}␊ |
239 | ␉else␊ |
240 | ␉{␊ |
241 | ␉␉//replace_system_function("_initGraphicsMode", &GUI_initGraphicsMode);␊ |
242 | ␉␉replace_system_function("_getBootOptions", &GUI_getBootOptions);␊ |
243 | ␉␉replace_system_function("_clearBootArgs", &GUI_clearBootArgs);␊ |
244 | replace_system_function("_addBootArg", &GUI_addBootArg); ␊ |
245 | ␊ |
246 | replace_system_function("_showHelp", &GUI_showHelp);␊ |
247 | ␉␉␊ |
248 | ␉␉replace_system_function("_printf", &GUI_printf);␊ |
249 | ␉␉replace_system_function("_verbose", &GUI_verbose);␊ |
250 | ␉␉replace_system_function("_error", &GUI_error);␊ |
251 | ␉␉replace_system_function("_stop", &GUI_stop);␊ |
252 | ␉␉replace_system_function("_showMessage", &GUI_showMessage);␊ |
253 | ␊ |
254 | ␉␉␊ |
255 | ␉␉// Hook for the boot screen ␉␊ |
256 | ␉␉register_hook_callback("GUI_ExecKernel", &GUI_ExecKernel_hook);␊ |
257 | ␉␉register_hook_callback("GUI_PreBoot", &GUI_PreBoot_hook);␊ |
258 | ␉␉␊ |
259 | ␊ |
260 | getBvChain = (void*)lookup_all_symbols(SYMBOLS_MODULE,"_getBvChain");␊ |
261 | getMemoryInfoString = (void*)lookup_all_symbols(SYMBOLS_MODULE,"_getMemoryInfoString");␊ |
262 | ␊ |
263 | printMemoryInfo = (void*)lookup_all_symbols(SYMBOLS_MODULE,"_printMemoryInfo");␊ |
264 | lspci = (void*)lookup_all_symbols(SYMBOLS_MODULE,"_lspci"); ␊ |
265 | showHelp = (void*)lookup_all_symbols(SYMBOLS_MODULE,"_showHelp");␊ |
266 | showTextFile = (void*)lookup_all_symbols(SYMBOLS_MODULE,"_showTextFile");␊ |
267 | showMessage = (void*)lookup_all_symbols(SYMBOLS_MODULE,"_showMessage"); ␊ |
268 | showTextBuffer = (void*)lookup_all_symbols(SYMBOLS_MODULE,"_showTextBuffer");␊ |
269 | ␉␉safe_set_env(envgBootArgs,(uint32_t)gBootArgs);␊ |
270 | ␊ |
271 | ␉␉msglog("* GUI successfully Displayed\n");␊ |
272 | ␉␉␊ |
273 | ␉}␊ |
274 | }␊ |
275 | ␊ |
276 | /**␊ |
277 | ** Module startup code. Replace console only print functions as well as␊ |
278 | ** replace various menu functions. Finaly, initialize the gui and hook␊ |
279 | ** into important events.␊ |
280 | **/␊ |
281 | void GUI_start(moduleList_t* module)␊ |
282 | {␊ |
283 | ␉register_hook_callback("GUI_Display", &GUI_diplay_hook);␉␉␉␉␊ |
284 | ␉␊ |
285 | }␊ |
286 | ␊ |
287 | /**␊ |
288 | ** Overriden chameleon function. Draws the updated menu.␊ |
289 | **/␊ |
290 | static int GUI_updateMenu( int key, void ** paramPtr )␊ |
291 | {␊ |
292 | int moved = 0;␊ |
293 | ␊ |
294 | int MenuTop = (int)get_env(envgMenuTop);␊ |
295 | int MenuSelection = (int)get_env(envgMenuSelection);␊ |
296 | int MenuRow = (int)get_env(envgMenuRow);␊ |
297 | int MenuHeight = (int)get_env(envgMenuHeight);␊ |
298 | int MenuBottom = (int)get_env(envgMenuBottom);␊ |
299 | int MenuStart = (int)get_env(envgMenuStart);␊ |
300 | int MenuEnd = (int)get_env(envgMenuEnd);␊ |
301 | ␉␊ |
302 | union {␊ |
303 | struct {␊ |
304 | unsigned int␊ |
305 | ␉␉␉selectionUp : 1,␊ |
306 | ␉␉␉selectionDown : 1,␊ |
307 | ␉␉␉scrollUp : 1,␊ |
308 | ␉␉␉scrollDown : 1;␊ |
309 | } f;␊ |
310 | unsigned int w;␊ |
311 | } draw = {{0}};␊ |
312 | ␉␊ |
313 | if ( gMenuItems == NULL )␊ |
314 | ␉␉return 0;␊ |
315 | ␉␊ |
316 | ␉if( getVideoMode() == GRAPHICS_MODE )␊ |
317 | ␉{␊ |
318 | ␉␉int res;␊ |
319 | ␉␉␊ |
320 | ␉␉// set navigation keys for horizontal layout as defaults␊ |
321 | ␉␉int previous␉= 0x4B00;␉␉// left arrow␊ |
322 | ␉␉int subsequent␉= 0x4D00;␉␉// right arrow␊ |
323 | ␉␉int menu␉␉= 0x5000;␉␉// down arrow␊ |
324 | ␉␉␊ |
325 | ␉␉if ( gui.layout == VerticalLayout )␊ |
326 | ␉␉{␊ |
327 | ␉␉␉// set navigation keys for vertical layout␊ |
328 | ␉␉␉previous␉= 0x4800;␉␉// up arrow␊ |
329 | ␉␉␉subsequent␉= 0x5000;␉␉// down arrow␊ |
330 | ␉␉␉menu␉␉= 0x4B00;␉␉// right arrow␊ |
331 | ␉␉} ␊ |
332 | ␉␉␊ |
333 | ␉␉if ( key == previous )␊ |
334 | ␉␉{␊ |
335 | ␉␉␉if ( MenuSelection > MenuTop )␊ |
336 | ␉␉␉␉draw.f.selectionUp = 1;␊ |
337 | ␉␉␉else if ( MenuTop > 0 )␊ |
338 | ␉␉␉␉draw.f.scrollDown = 1;␊ |
339 | ␉␉␉␊ |
340 | ␉␉}␊ |
341 | ␉␉␊ |
342 | ␉␉else if ( key == subsequent )␊ |
343 | ␉␉{␊ |
344 | ␉␉␉if ( MenuSelection != MenuBottom)␊ |
345 | ␉␉␉␉draw.f.selectionDown = 1;␊ |
346 | ␉␉␉else if ( MenuBottom < ( get_env(envgMenuItemCount) - 1 ) )␊ |
347 | ␉␉␉␉draw.f.scrollUp = 1;␊ |
348 | ␉␉}␊ |
349 | ␉␉␊ |
350 | ␉␉else if ( key == menu )␊ |
351 | ␉␉{␊ |
352 | ␉␉␉if ( gui.menu.draw )␊ |
353 | ␉␉␉␉updateInfoMenu(key);␊ |
354 | ␉␉␉else␊ |
355 | ␉␉␉␉drawInfoMenu();␊ |
356 | ␉␉}␊ |
357 | ␉␉␊ |
358 | ␉␉else if ( gui.menu.draw )␊ |
359 | ␉␉{␊ |
360 | ␉␉␉res = updateInfoMenu(key);␊ |
361 | ␉␉␉␊ |
362 | ␉␉␉if ( res == CLOSE_INFO_MENU )␊ |
363 | ␉␉␉␉gui.menu.draw = false;␊ |
364 | ␉␉␉else␊ |
365 | ␉␉␉{␊ |
366 | ␉␉␉␉bool shouldboot = ( res != DO_NOT_BOOT );␊ |
367 | safe_set_env(envShouldboot, shouldboot);␊ |
368 | ␊ |
369 | ␉␉␉␉if ( shouldboot )␊ |
370 | ␉␉␉␉␉gui.menu.draw = false;␊ |
371 | ␉␉␉␉␊ |
372 | ␉␉␉␉switch (res)␊ |
373 | ␉␉␉␉{␊ |
374 | ␉␉␉␉␉case BOOT_NORMAL:␊ |
375 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
376 | safe_set_env(envgBootMode, kBootModeNormal);␊ |
377 | ␊ |
378 | ␉␉␉␉␉␉break;␊ |
379 | ␉␉␉␉␉␉␊ |
380 | ␉␉␉␉␉case BOOT_VERBOSE:␊ |
381 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
382 | safe_set_env(envgBootMode, kBootModeNormal);␊ |
383 | ␉␉␉␉␉␉GUI_addBootArg(kVerboseModeFlag);␊ |
384 | ␉␉␉␉␉␉break;␊ |
385 | ␉␉␉␉␉␉␊ |
386 | ␉␉␉␉␉case BOOT_IGNORECACHE:␊ |
387 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
388 | safe_set_env(envgBootMode, kBootModeNormal);␊ |
389 | ␉␉␉␉␉␉GUI_addBootArg(kIgnoreCachesFlag);␊ |
390 | ␉␉␉␉␉␉break;␊ |
391 | ␉␉␉␉␉␉␊ |
392 | ␉␉␉␉␉case BOOT_SINGLEUSER:␊ |
393 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
394 | safe_set_env(envgBootMode, kBootModeNormal);␊ |
395 | ␉␉␉␉␉␉GUI_addBootArg(kSingleUserModeFlag);␊ |
396 | ␉␉␉␉␉␉break;␊ |
397 | ␉␉␉␉␉default:␊ |
398 | ␉␉␉␉␉␉break;␊ |
399 | ␉␉␉␉}␊ |
400 | ␉␉␉␉␊ |
401 | ␉␉␉}␊ |
402 | ␉␉␉␊ |
403 | ␉␉}␉␊ |
404 | ␉␉␊ |
405 | ␉} else {␊ |
406 | ␉␉switch ( key )␊ |
407 | ␉␉{␊ |
408 | ␉case 0x4800: // Up Arrow␊ |
409 | ␉␉␉␉if ( MenuSelection != MenuTop )␊ |
410 | ␉␉␉␉{␊ |
411 | ␉␉␉␉␉draw.f.selectionUp = 1;␊ |
412 | ␉␉␉␉}␊ |
413 | ␉␉␉␉else if ( MenuTop > 0 )␊ |
414 | ␉␉␉␉{␊ |
415 | ␉␉␉␉␉draw.f.scrollDown = 1;␊ |
416 | ␉␉␉␉}␊ |
417 | ␉␉␉␉break;␊ |
418 | ␉␉␉␉␊ |
419 | ␉␉␉case 0x5000: // Down Arrow␊ |
420 | ␉␉␉␉if ( MenuSelection != MenuBottom )␊ |
421 | ␉␉␉␉{␊ |
422 | ␉␉␉␉␉draw.f.selectionDown = 1;␊ |
423 | ␉␉␉␉}␊ |
424 | ␉␉␉␉else if ( MenuBottom < (get_env(envgMenuItemCount) - 1) ) ␊ |
425 | ␉␉␉␉{␊ |
426 | ␉␉␉␉␉draw.f.scrollUp = 1;␊ |
427 | ␉␉␉␉}␊ |
428 | ␉␉␉␉break;␊ |
429 | ␉␉␉default:␊ |
430 | ␉␉␉␉break;␊ |
431 | ␉␉}␊ |
432 | ␉}␊ |
433 | ␉␊ |
434 | if ( draw.w )␊ |
435 | {␊ |
436 | if ( draw.f.scrollUp )␊ |
437 | {␊ |
438 | scollPage(0, MenuRow, 40, MenuRow + MenuHeight - 1, 0x07, 1, 1);␊ |
439 | MenuTop++; MenuBottom++;␊ |
440 | ␉␉␉MenuStart++; MenuEnd++;␊ |
441 | draw.f.selectionDown = 1;␊ |
442 | }␊ |
443 | ␉␉␊ |
444 | if ( draw.f.scrollDown )␊ |
445 | {␊ |
446 | scollPage(0, MenuRow, 40, MenuRow + MenuHeight - 1, 0x07, 1, -1);␊ |
447 | MenuTop--; MenuBottom--;␊ |
448 | MenuStart--; MenuEnd--;␊ |
449 | draw.f.selectionUp = 1;␊ |
450 | }␊ |
451 | ␉␉␊ |
452 | if ( draw.f.selectionUp || draw.f.selectionDown )␊ |
453 | {␊ |
454 | ␉␉␉␊ |
455 | ␉␉␉CursorState cursorState;␊ |
456 | ␉␉␉␊ |
457 | ␉␉␉// Set cursor at current position, and clear inverse video.␊ |
458 | ␉␉␉␊ |
459 | ␉␉␉if( getVideoMode() == VGA_TEXT_MODE )␊ |
460 | ␉␉␉{␊ |
461 | ␉␉␉␉changeCursor( 0, (MenuRow + MenuSelection - MenuTop), kCursorTypeHidden, &cursorState );␊ |
462 | ␉␉␉␉printMenuItem( &gMenuItems[MenuSelection], 0 );␊ |
463 | ␉␉␉}␊ |
464 | ␉␉␉␊ |
465 | ␉␉␉if ( draw.f.selectionUp )␊ |
466 | ␉␉␉{␊ |
467 | ␉␉␉␉MenuSelection--;␊ |
468 | ␉␉␉␉if(( MenuSelection - MenuStart) == -1 )␊ |
469 | ␉␉␉␉{␊ |
470 | ␉␉␉␉␉MenuStart--;␊ |
471 | ␉␉␉␉␉MenuEnd--;␊ |
472 | ␉␉␉␉}␊ |
473 | ␉␉␉␉␊ |
474 | ␉␉␉} else {␊ |
475 | ␉␉␉␉MenuSelection++;␊ |
476 | ␉␉␉␉if(( MenuSelection - ( gui.maxdevices - 1) - MenuStart) > 0 )␊ |
477 | ␉␉␉␉{␊ |
478 | ␉␉␉␉␉MenuStart++;␊ |
479 | ␉␉␉␉␉MenuEnd++;␊ |
480 | ␉␉␉␉}␊ |
481 | ␉␉␉}␊ |
482 | ␉␉␉␊ |
483 | ␉␉␉if( getVideoMode() == VGA_TEXT_MODE )␊ |
484 | ␉␉␉{␊ |
485 | ␉␉␉␉moveCursor( 0, MenuRow + MenuSelection - MenuTop );␊ |
486 | ␉␉␉␉printMenuItem( &gMenuItems[MenuSelection], 1 );␊ |
487 | ␉␉␉␉moved = restoreCursor( &cursorState );␊ |
488 | ␉␉␉␉␊ |
489 | ␉␉␉}␊ |
490 | ␉␉␉else␊ |
491 | ␉␉␉{␊ |
492 | ␉␉␉␉drawDeviceList (MenuStart, MenuEnd, MenuSelection, menuItems);␊ |
493 | ␉␉␉}␊ |
494 | ␉␉␉␊ |
495 | ␉␉}␊ |
496 | ␉␉␊ |
497 | *paramPtr = gMenuItems[MenuSelection].param; ␊ |
498 | moved = 1;␊ |
499 | }␊ |
500 | ␊ |
501 | ␉safe_set_env(envgMenuSelection,MenuSelection);␊ |
502 | safe_set_env(envgMenuTop,MenuTop );␊ |
503 | safe_set_env(envgMenuRow,MenuRow);␊ |
504 | safe_set_env(envgMenuHeight,MenuHeight);␊ |
505 | safe_set_env(envgMenuBottom,MenuBottom);␊ |
506 | safe_set_env(envgMenuStart,MenuStart);␊ |
507 | safe_set_env(envgMenuEnd,MenuEnd);␊ |
508 | ␊ |
509 | ␉return moved;␊ |
510 | }␊ |
511 | ␊ |
512 | ␊ |
513 | static void GUI_showMenu( const MenuItem * items, int count,␊ |
514 | ␉␉␉␉␉␉ int selection, int row, int height )␊ |
515 | {␊ |
516 | int i;␊ |
517 | CursorState cursorState;␊ |
518 | ␉␊ |
519 | if ( items == NULL || count == 0 ) ␊ |
520 | ␉␉return;␊ |
521 | ␉␊ |
522 | // head and tail points to the start and the end of the list.␊ |
523 | // top and bottom points to the first and last visible items␊ |
524 | // in the menu window.␊ |
525 | ␉␊ |
526 | gMenuItems␉␉= items;␊ |
527 | int MenuTop␉␉= 0;␊ |
528 | int MenuBottom␉␉= min( count, height ) - 1;␊ |
529 | int MenuSelection␉= selection;␉␊ |
530 | int MenuStart␉␉= 0;␊ |
531 | int MenuEnd␉ = count; //min( count, gui.maxdevices ) - 1;␊ |
532 | ␉␊ |
533 | ␉// If the selected item is not visible, shift the list down.␊ |
534 | ␉␊ |
535 | if ( MenuSelection > MenuBottom )␊ |
536 | {␊ |
537 | MenuTop += ( MenuSelection - MenuBottom );␊ |
538 | MenuBottom = MenuSelection;␊ |
539 | }␊ |
540 | ␉␊ |
541 | ␉if ( MenuSelection > MenuEnd )␊ |
542 | {␊ |
543 | ␉␉MenuStart += ( MenuSelection - MenuEnd );␊ |
544 | MenuEnd = MenuSelection;␊ |
545 | }␊ |
546 | ␉␊ |
547 | ␉// Draw the visible items.␊ |
548 | ␉␊ |
549 | ␉if( getVideoMode() == GRAPHICS_MODE )␊ |
550 | ␉{␊ |
551 | ␉␉drawDeviceList(MenuStart, MenuEnd, MenuSelection, menuItems);␊ |
552 | ␉}␊ |
553 | ␉else ␊ |
554 | ␉{␊ |
555 | ␉␉␊ |
556 | ␉␉changeCursor( 0, row, kCursorTypeHidden, &cursorState );␊ |
557 | ␉␉␊ |
558 | ␉␉for ( i = MenuTop; i <= MenuBottom; i++ )␊ |
559 | ␉␉{␊ |
560 | ␉␉␉printMenuItem( &items[i], (i == MenuSelection) );␊ |
561 | ␉␉}␊ |
562 | ␉␉␊ |
563 | ␉␉restoreCursor( &cursorState ); // FIXME : handle the return error␊ |
564 | }␊ |
565 | ␊ |
566 | safe_set_env(envgMenuRow,row);␊ |
567 | safe_set_env(envgMenuHeight,height);␊ |
568 | safe_set_env(envgMenuItemCount,count);␊ |
569 | safe_set_env(envgMenuTop,MenuTop);␊ |
570 | safe_set_env(envgMenuBottom,MenuBottom);␊ |
571 | safe_set_env(envgMenuSelection,MenuSelection);␊ |
572 | safe_set_env(envgMenuStart,MenuStart);␊ |
573 | safe_set_env(envgMenuEnd,MenuEnd);␊ |
574 | }␊ |
575 | ␊ |
576 | ␊ |
577 | static void GUI_updateBootArgs( int key )␊ |
578 | {␊ |
579 | key &= kASCIIKeyMask;␊ |
580 | ␉␊ |
581 | switch ( key )␊ |
582 | {␊ |
583 | case kBackspaceKey:␊ |
584 | if ( gBootArgsPtr > gBootArgs )␊ |
585 | {␊ |
586 | int x, y, t;␊ |
587 | getCursorPositionAndType( &x, &y, &t );␊ |
588 | if ( x == 0 && y )␊ |
589 | {␊ |
590 | x = 80; y--;␊ |
591 | }␊ |
592 | if (x)␊ |
593 | ␉␉␉␉␉x--;␊ |
594 | ␉␉␉␉if( getVideoMode() == VGA_TEXT_MODE )␊ |
595 | ␉␉␉␉{␊ |
596 | ␉␉␉␉␉setCursorPosition( x, y, 0 );␊ |
597 | ␉␉␉␉␉putca(' ', 0x07, 1);␊ |
598 | ␉␉␉␉} else␊ |
599 | ␉␉␉␉{␊ |
600 | ␉␉␉␉␉updateGraphicBootPrompt(kBackspaceKey);␊ |
601 | ␉␉␉␉}␊ |
602 | ␉␉␉␉␊ |
603 | ␉␉␉␉*gBootArgsPtr-- = '\0';␊ |
604 | ␉␉␉}␊ |
605 | ␊ |
606 | ␉␉␉break;␊ |
607 | ␉␉␉␊ |
608 | default:␊ |
609 | if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
610 | {␊ |
611 | ␉␉␉␉if( getVideoMode() == VGA_TEXT_MODE )␊ |
612 | ␉␉␉␉{␊ |
613 | ␉␉␉␉␉putchar(key); // echo to screen␊ |
614 | ␉␉␉␉}␊ |
615 | ␉␉␉␉else␊ |
616 | ␉␉␉␉{␊ |
617 | ␉␉␉␉␉updateGraphicBootPrompt(key);␊ |
618 | ␉␉␉␉}␊ |
619 | ␉␉␉␉*gBootArgsPtr++ = key;␊ |
620 | ␉␉␉}␊ |
621 | ␊ |
622 | ␉␉␉break;␊ |
623 | }␊ |
624 | }␊ |
625 | ␊ |
626 | ␊ |
627 | static void GUI_showBootPrompt(int row, bool visible)␊ |
628 | {␊ |
629 | ␉char * bootPrompt = (char*)(uint32_t)get_env(envBootPrompt);␊ |
630 | ␉␊ |
631 | ␉if( getVideoMode() == VGA_TEXT_MODE )␊ |
632 | ␉{␊ |
633 | ␉␉changeCursor( 0, row, kCursorTypeUnderline, 0 ); ␊ |
634 | ␉␉clearScreenRows( row, kScreenLastRow );␊ |
635 | ␉}␊ |
636 | ␉␊ |
637 | ␉GUI_clearBootArgs();␊ |
638 | ␉␊ |
639 | ␉if (visible)␊ |
640 | ␉{␊ |
641 | ␉␉if (getVideoMode() == VGA_TEXT_MODE) ␊ |
642 | ␉␉{␊ |
643 | ␉␉␉if (get_env(envgEnableCDROMRescan))␊ |
644 | ␉␉␉{␊ |
645 | ␉␉␉␉printf( GUI_bootRescanPrompt );␊ |
646 | ␉␉␉} ␊ |
647 | ␉␉␉else␊ |
648 | ␉␉␉{␊ |
649 | ␉␉␉␉printf( bootPrompt );␊ |
650 | ␉␉␉}␊ |
651 | ␉␉}␊ |
652 | ␉} ␊ |
653 | ␉else␊ |
654 | ␉{␊ |
655 | ␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
656 | ␉␉{␊ |
657 | ␉␉␉clearGraphicBootPrompt();␊ |
658 | ␉␉} ␊ |
659 | ␉␉else␊ |
660 | ␉␉{␊ |
661 | ␉␉␉printf("Press Enter to start up the foreign OS. ");␊ |
662 | ␉␉}␊ |
663 | ␉}␊ |
664 | }␊ |
665 | ␊ |
666 | void GUI_clearBootArgs(void)␊ |
667 | {␊ |
668 | ␉gBootArgsPtr = gBootArgs;␊ |
669 | ␉memset(gBootArgs, '\0', BOOT_STRING_LEN);␊ |
670 | ␉␊ |
671 | ␉if (getVideoMode() == GRAPHICS_MODE) ␊ |
672 | ␉{␊ |
673 | ␉␉clearGraphicBootPrompt();␊ |
674 | ␉}␊ |
675 | }␊ |
676 | ␊ |
677 | void GUI_addBootArg(const char * argStr)␊ |
678 | {␊ |
679 | ␉if ( (gBootArgsPtr + strlen(argStr) + 1) < gBootArgsEnd)␊ |
680 | ␉{␊ |
681 | ␉␉*gBootArgsPtr++ = ' ';␊ |
682 | ␉␉strcat(gBootArgs, argStr);␊ |
683 | ␉␉gBootArgsPtr += strlen(argStr);␊ |
684 | ␉}␊ |
685 | }␊ |
686 | ␊ |
687 | int GUI_getBootOptions(bool firstRun)␊ |
688 | {␊ |
689 | ␉int i;␊ |
690 | ␉int key;␊ |
691 | ␉int nextRow;␊ |
692 | ␉int timeout;␊ |
693 | #if UNUSED␊ |
694 | ␉int bvCount;␊ |
695 | #endif␊ |
696 | ␉BVRef bvr;␊ |
697 | ␉BVRef menuBVR;␊ |
698 | ␉bool showPrompt, newShowPrompt, isCDROM;␊ |
699 | int optionKey;␊ |
700 | int devcnt = (int)get_env(envgDeviceCount);␊ |
701 | ␊ |
702 | ␉// Initialize default menu selection entry.␊ |
703 | ␉gBootVolume = menuBVR = selectBootVolume(getBvChain());␊ |
704 | ␉␊ |
705 | ␉if (biosDevIsCDROM((int)get_env(envgBIOSDev)))␊ |
706 | ␉{␊ |
707 | ␉␉isCDROM = true;␊ |
708 | ␉} ␊ |
709 | ␉else␊ |
710 | ␉{␊ |
711 | ␉␉isCDROM = false;␊ |
712 | ␉}␊ |
713 | ␊ |
714 | ␉// ensure we're in graphics mode if gui is setup␊ |
715 | ␉if (gui.initialised && (getVideoMode() == VGA_TEXT_MODE))␊ |
716 | ␉{␊ |
717 | #if UNUSED␊ |
718 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
719 | #else␊ |
720 | ␉␉setVideoMode(GRAPHICS_MODE);␊ |
721 | #endif␊ |
722 | ␉}␊ |
723 | ␉␊ |
724 | ␉// Clear command line boot arguments␊ |
725 | ␉GUI_clearBootArgs();␊ |
726 | ␉␊ |
727 | ␉// Allow user to override default timeout.␊ |
728 | ␉if (!getIntForKey(kTimeoutKey, &timeout, DEFAULT_BOOT_CONFIG))␊ |
729 | ␉{␊ |
730 | ␉␉/* If there is no timeout key in the file use the default timeout␊ |
731 | ␉␉ which is different for CDs vs. hard disks. However, if not booting␊ |
732 | ␉␉ a CD and no config file could be loaded set the timeout␊ |
733 | ␉␉ to zero which causes the menu to display immediately.␊ |
734 | ␉␉ This way, if no partitions can be found, that is the disk is unpartitioned␊ |
735 | ␉␉ or simply cannot be read) then an empty menu is displayed.␊ |
736 | ␉␉ If some partitions are found, for example a Windows partition, then␊ |
737 | ␉␉ these will be displayed in the menu as foreign partitions.␊ |
738 | ␉␉ */␊ |
739 | ␉␉if (isCDROM)␊ |
740 | ␉␉{␊ |
741 | ␉␉␉timeout = kCDBootTimeout;␊ |
742 | ␉␉}␊ |
743 | ␉␉else ␊ |
744 | ␉␉{␊ |
745 | ␉␉␉timeout = get_env(envSysConfigValid) ? kBootTimeout : 0;␊ |
746 | ␉␉}␊ |
747 | ␉}␊ |
748 | ␊ |
749 | ␉long gBootMode = get_env(envgBootMode);␊ |
750 | ␊ |
751 | ␉if (timeout < 0) ␊ |
752 | ␉{␊ |
753 | ␉␉gBootMode |= kBootModeQuiet;␊ |
754 | safe_set_env(envgBootMode,gBootMode);␊ |
755 | ␊ |
756 | ␉}␊ |
757 | ␉␊ |
758 | ␉// If the user is holding down a modifier key, enter safe mode.␊ |
759 | ␉if ((readKeyboardShiftFlags() & 0x0F) != 0) ␊ |
760 | ␉{␊ |
761 | ␉␉␊ |
762 | ␉␉gBootMode |= kBootModeSafe;␊ |
763 | safe_set_env(envgBootMode,gBootMode);␊ |
764 | ␊ |
765 | ␉}␊ |
766 | ␉␊ |
767 | ␉// Checking user pressed keys␊ |
768 | ␉bool f8press = false, spress = false, vpress = false;␊ |
769 | ␉while (readKeyboardStatus())␊ |
770 | ␉{␊ |
771 | ␉␉key = bgetc ();␊ |
772 | ␉␉if (key == 0x4200) f8press = true;␊ |
773 | ␉␉if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true;␊ |
774 | ␉␉if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true;␊ |
775 | ␉}␊ |
776 | ␉// If user typed F8, abort quiet mode, and display the menu.␊ |
777 | ␉if (f8press)␊ |
778 | ␉{␊ |
779 | ␉␉gBootMode &= ~kBootModeQuiet;␊ |
780 | safe_set_env(envgBootMode,gBootMode);␊ |
781 | ␊ |
782 | ␉␉timeout = 0;␊ |
783 | ␉}␊ |
784 | ␉// If user typed 'v' or 'V', boot in verbose mode.␊ |
785 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && vpress)␊ |
786 | ␉{␊ |
787 | ␉␉GUI_addBootArg(kVerboseModeFlag);␊ |
788 | ␉}␊ |
789 | ␉// If user typed 's' or 'S', boot in single user mode.␊ |
790 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && spress)␊ |
791 | ␉{␊ |
792 | ␉␉GUI_addBootArg(kSingleUserModeFlag);␊ |
793 | ␉}␊ |
794 | ␉␊ |
795 | ␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
796 | ␉{␊ |
797 | ␉␉setCursorPosition(0, 0, 0);␊ |
798 | ␉␉clearScreenRows(0, kScreenLastRow);␊ |
799 | ␉␉if (!(gBootMode & kBootModeQuiet)) ␊ |
800 | ␉␉{␊ |
801 | char * bootBanner = (char*)(uint32_t)get_env(envBootBanner);␊ |
802 | ␉␉␉// Display banner and show hardware info.␊ |
803 | ␉␉␉printf(bootBanner, (int)(get_env(envConvMem) + get_env(envExtMem)) / 1024);␊ |
804 | ␉␉␉printf(getVBEInfoString());␊ |
805 | ␉␉}␊ |
806 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
807 | ␉␉msglog("Scanning device %x...", (uint32_t)get_env(envgBIOSDev));␊ |
808 | ␉}␊ |
809 | ␉␊ |
810 | ␉// When booting from CD, default to hard drive boot when possible. ␊ |
811 | ␉if (isCDROM && firstRun)␊ |
812 | ␉{␊ |
813 | ␉␉const char *val;␊ |
814 | ␉␉char *prompt = NULL;␊ |
815 | ␉␉char *name = NULL;␊ |
816 | ␉␉int cnt;␊ |
817 | ␉␉␊ |
818 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, DEFAULT_BOOT_CONFIG)) {␊ |
819 | ␉␉␉prompt = malloc(cnt + 1);␊ |
820 | if (!prompt) {␊ |
821 | stop("Couldn't allocate memory for the prompt\n"); //TODO: Find a better stategie␊ |
822 | return -1;␊ |
823 | }␊ |
824 | ␉␉␉strncat(prompt, val, cnt);␊ |
825 | ␉␉} else {␊ |
826 | ␉␉␉name = malloc(80);␊ |
827 | if (!name) {␊ |
828 | stop("Couldn't allocate memory for the device name\n"); //TODO: Find a better stategie␊ |
829 | return -1;␊ |
830 | }␊ |
831 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 79, false);␊ |
832 | ␉␉␉prompt = malloc(256); ␊ |
833 | if (!prompt) {␊ |
834 | free(name);␊ |
835 | stop("Couldn't allocate memory for the prompt\n"); //TODO: Find a better stategie␊ |
836 | return -1;␊ |
837 | }␊ |
838 | ␉␉␉sprintf(prompt, "Press ENTER to start up from %s, or press any key to enter startup options.", name);␊ |
839 | ␉␉␉free(name);␊ |
840 | ␉␉}␊ |
841 | ␉␉␊ |
842 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, DEFAULT_BOOT_CONFIG ))␊ |
843 | ␉␉{␊ |
844 | ␉␉␉// The key specified is a special key.␊ |
845 | ␉␉}␊ |
846 | ␉␉else␊ |
847 | ␉␉{␊ |
848 | ␉␉␉// Default to F8.␊ |
849 | ␉␉␉optionKey = 0x4200;␊ |
850 | ␉␉}␊ |
851 | ␉␉␊ |
852 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
853 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
854 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
855 | ␉␉if (timeout != 0) {␊ |
856 | ␉␉␉key = GUI_countdown(prompt, kMenuTopRow, timeout, &optionKey);␊ |
857 | ␉␉} ␊ |
858 | ␉␉else ␊ |
859 | ␉␉{␊ |
860 | ␉␉␉key = optionKey;␊ |
861 | ␉␉}␊ |
862 | ␉␉␊ |
863 | ␉␉if (prompt != NULL)␊ |
864 | ␉␉{␊ |
865 | ␉␉␉free(prompt);␊ |
866 | ␉␉}␊ |
867 | ␉␉␊ |
868 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
869 | ␉␉␊ |
870 | ␉␉do {␊ |
871 | // Hit the option key ?␊ |
872 | if (key == optionKey) {␊ |
873 | ␊ |
874 | if (key != 0x1C0D) {␊ |
875 | gBootMode &= ~kBootModeQuiet;␊ |
876 | safe_set_env(envgBootMode,gBootMode);␊ |
877 | timeout = 0;␊ |
878 | break;␊ |
879 | }␊ |
880 | ␊ |
881 | } ␊ |
882 | ␊ |
883 | key = key & 0xFF;␊ |
884 | ␊ |
885 | // Try booting hard disk if user pressed 'h'␊ |
886 | if (biosDevIsCDROM((int)get_env(envgBIOSDev)) && key == 'h') {␊ |
887 | BVRef bvr;␊ |
888 | ␊ |
889 | // Look at partitions hosting OS X other than the CD-ROM␊ |
890 | for (bvr = getBvChain(); bvr; bvr=bvr->next) {␊ |
891 | if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != (int)get_env(envgBIOSDev)) {␊ |
892 | gBootVolume = bvr;␊ |
893 | }␊ |
894 | }␊ |
895 | }␊ |
896 | goto done;␊ |
897 | ␊ |
898 | } while (0);␊ |
899 | ␉}␊ |
900 | ␉␊ |
901 | ␉if (gBootMode & kBootModeQuiet)␊ |
902 | ␉{␊ |
903 | ␉␉// No input allowed from user.␊ |
904 | ␉␉goto done;␊ |
905 | ␉}␊ |
906 | ␉␊ |
907 | ␉if (firstRun && timeout > 0 ) {␊ |
908 | ␊ |
909 | key = GUI_countdown("Press ENTER to start up, or press any key to enter startup options.", kMenuTopRow, timeout, &optionKey);␊ |
910 | ␊ |
911 | if (key == 0x1C0D) {␊ |
912 | goto done;␊ |
913 | ␊ |
914 | } ␊ |
915 | else if (key == 0)␊ |
916 | {␊ |
917 | // If the user is holding down a modifier key,␊ |
918 | // enter safe mode. ␊ |
919 | ␊ |
920 | if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
921 | gBootMode |= kBootModeSafe;␊ |
922 | safe_set_env(envgBootMode,gBootMode);␊ |
923 | }␊ |
924 | goto done;␊ |
925 | }␊ |
926 | ␉}␊ |
927 | ␊ |
928 | ␉if (devcnt)␊ |
929 | ␉{␊ |
930 | ␉␉// Allocate memory for an array of menu items.␊ |
931 | ␉␉menuItems = malloc(sizeof(MenuItem) * devcnt);␊ |
932 | ␉␉if (menuItems == NULL) ␊ |
933 | ␉␉{␊ |
934 | ␉␉␉goto done;␊ |
935 | ␉␉}␊ |
936 | ␉␉␊ |
937 | ␉␉// Associate a menu item for each BVRef.␊ |
938 | ␉␉for (bvr=getBvChain(), i=devcnt-1, selectIndex=0; bvr; bvr=bvr->next)␊ |
939 | ␉␉{␊ |
940 | ␉␉␉if (bvr->visible)␊ |
941 | ␉␉␉{␊ |
942 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true);␊ |
943 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
944 | ␉␉␉␉if (bvr == menuBVR)␊ |
945 | ␉␉␉␉{␊ |
946 | ␉␉␉␉␉selectIndex = i;␊ |
947 | safe_set_env(envSelectIndex, selectIndex);␊ |
948 | ␉␉␉␉}␊ |
949 | ␉␉␉␉i--;␊ |
950 | ␉␉␉}␊ |
951 | ␉␉}␊ |
952 | ␉}␊ |
953 | ␉␊ |
954 | ␉if (getVideoMode() == GRAPHICS_MODE)␊ |
955 | ␉{␊ |
956 | ␉␉// redraw the background buffer␊ |
957 | ␉␉gui.logo.draw = true;␊ |
958 | ␉␉drawBackground();␊ |
959 | ␉␉gui.devicelist.draw = true;␊ |
960 | ␉␉gui.redraw = true;␊ |
961 | ␉␉if (!(gBootMode & kBootModeQuiet))␊ |
962 | ␉␉{␊ |
963 | ␉␉␉bool showBootBanner = true;␊ |
964 | ␉␉␉␊ |
965 | ␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
966 | ␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, DEFAULT_BOOT_CONFIG); ␊ |
967 | ␉␉␉if (showBootBanner)␊ |
968 | ␉␉␉{␊ |
969 | char * bootBanner = (char*)(uint32_t)get_env(envBootBanner);␊ |
970 | ␊ |
971 | ␉␉␉␉// Display banner and show hardware info.␊ |
972 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (int)(get_env(envConvMem) + get_env(envExtMem)) / 1024);␊ |
973 | ␊ |
974 | ␉␉␉}␊ |
975 | ␉␉␉␊ |
976 | ␉␉␉// redraw background␊ |
977 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
978 | ␉␉}␊ |
979 | ␉}␊ |
980 | ␉else ␊ |
981 | ␉{␊ |
982 | ␉␉// Clear screen and hide the blinking cursor.␊ |
983 | ␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
984 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
985 | ␉}␊ |
986 | ␉␊ |
987 | ␉nextRow = kMenuTopRow;␊ |
988 | ␉␊ |
989 | ␉if (devcnt)␊ |
990 | ␉{␊ |
991 | ␉␉if( getVideoMode() == VGA_TEXT_MODE )␊ |
992 | ␉␉{␊ |
993 | ␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
994 | ␉␉}␊ |
995 | ␉␉GUI_showMenu( menuItems, devcnt, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
996 | ␉␉nextRow += min( devcnt, kMenuMaxItems ) + 3;␊ |
997 | ␉}␊ |
998 | ␉␊ |
999 | ␉// Show the boot prompt.␊ |
1000 | ␉showPrompt = (devcnt == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1001 | ␉GUI_showBootPrompt( nextRow, showPrompt );␊ |
1002 | ␉␊ |
1003 | ␉do {␊ |
1004 | ␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
1005 | ␉␉{␊ |
1006 | ␉␉␉// redraw background␊ |
1007 | ␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1008 | ␉␉␉// reset cursor co-ords␊ |
1009 | ␉␉␉gui.debug.cursor = pos( gui.screen.width - 160 , 10 );␊ |
1010 | ␉␉}␊ |
1011 | ␉␉key = getc();␊ |
1012 | ␉␉GUI_updateMenu( key, (void **) &menuBVR );␊ |
1013 | ␉␉newShowPrompt = (devcnt == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1014 | ␉␉␊ |
1015 | ␉␉if (newShowPrompt != showPrompt)␊ |
1016 | ␉␉{␊ |
1017 | ␉␉␉showPrompt = newShowPrompt;␊ |
1018 | ␉␉␉GUI_showBootPrompt( nextRow, showPrompt );␊ |
1019 | ␉␉}␊ |
1020 | ␉␉␊ |
1021 | ␉␉if (showPrompt)␊ |
1022 | ␉␉{␊ |
1023 | ␉␉␉GUI_updateBootArgs(key);␊ |
1024 | ␉␉}␊ |
1025 | ␉␉␊ |
1026 | ␉␉switch (key)␊ |
1027 | ␉␉{␊ |
1028 | ␉␉␉case kReturnKey:␊ |
1029 | ␉␉␉␉if (gui.menu.draw)␊ |
1030 | ␉␉␉␉{ ␊ |
1031 | ␉␉␉␉␉key=0;␊ |
1032 | ␉␉␉␉␉break;␊ |
1033 | ␉␉␉␉}␊ |
1034 | ␉␉␉␉if (*gBootArgs == '?')␊ |
1035 | ␉␉␉␉{␊ |
1036 | ␉␉␉␉␉char * argPtr = gBootArgs;␊ |
1037 | ␉␉␉␉␉␊ |
1038 | ␉␉␉␉␉// Skip the leading "?" character.␊ |
1039 | ␉␉␉␉␉argPtr++;␊ |
1040 | ␉␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
1041 | ␉␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
1042 | ␉␉␉␉␉␊ |
1043 | ␉␉␉␉␉/*␊ |
1044 | ␉␉␉␉␉ * TODO: this needs to be refactored.␊ |
1045 | ␉␉␉␉␉ */␊ |
1046 | ␉␉␉␉␉if (strcmp( booterCommand, "video" ) == 0)␊ |
1047 | ␉␉␉␉␉{␊ |
1048 | ␉␉␉␉␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
1049 | ␉␉␉␉␉␉{␊ |
1050 | ␉␉␉␉␉␉␉showInfoBox(getVBEInfoString(), getVBEModeInfoString());␊ |
1051 | ␉␉␉␉␉␉}␊ |
1052 | ␉␉␉␉␉␉else␊ |
1053 | ␉␉␉␉␉␉{␊ |
1054 | ␉␉␉␉␉␉␉printVBEModeInfo();␊ |
1055 | ␉␉␉␉␉␉}␊ |
1056 | ␉␉␉␉␉}␊ |
1057 | ␉␉␉␉␉else if ( strcmp( booterCommand, "memory" ) == 0)␊ |
1058 | ␉␉␉␉␉{␊ |
1059 | ␉␉␉␉␉␉if (getVideoMode() == GRAPHICS_MODE ) ␊ |
1060 | ␉␉␉␉␉␉{␊ |
1061 | ␉␉␉␉␉␉␉showInfoBox("Memory Map", getMemoryInfoString());␊ |
1062 | ␉␉␉␉␉␉}␊ |
1063 | ␉␉␉␉␉␉else␊ |
1064 | ␉␉␉␉␉␉{␊ |
1065 | ␉␉␉␉␉␉␉printMemoryInfo();␊ |
1066 | ␉␉␉␉␉␉}␊ |
1067 | ␉␉␉␉␉}␊ |
1068 | ␉␉␉␉␉else if (strcmp(booterCommand, "lspci") == 0)␊ |
1069 | ␉␉␉␉␉{␊ |
1070 | ␉␉␉␉␉␉lspci();␊ |
1071 | ␉␉␉␉␉}␊ |
1072 | ␉␉␉␉␉else if (strcmp(booterCommand, "more") == 0)␊ |
1073 | ␉␉␉␉␉{␊ |
1074 | ␉␉␉␉␉␉showTextFile(booterParam);␊ |
1075 | ␉␉␉␉␉}␊ |
1076 | ␉␉␉␉␉else if (strcmp(booterCommand, "rd") == 0)␊ |
1077 | ␉␉␉␉␉{␊ |
1078 | ␉␉␉␉␉␉if (execute_hook("processRAMDiskCommand", (void*)argPtr, &booterParam, NULL, NULL, NULL, NULL) != EFI_SUCCESS)␊ |
1079 | ␉␉␉␉␉␉␉showMessage("ramdisk module not found, please install RamdiskLoader.dylib in /Extra/modules/");␊ |
1080 | ␉␉␉␉␉} ␊ |
1081 | ␉␉␉␉␉else if (strcmp(booterCommand, "norescan") == 0)␊ |
1082 | ␉␉␉␉␉{␊ |
1083 | ␉␉␉␉␉␉if (get_env(envgEnableCDROMRescan))␊ |
1084 | {␊ |
1085 | safe_set_env(envgEnableCDROMRescan,false);␊ |
1086 | break;␊ |
1087 | }␊ |
1088 | ␉␉␉␉␉} ␊ |
1089 | ␉␉␉␉␉else␊ |
1090 | ␉␉␉␉␉{␊ |
1091 | ␉␉␉␉␉␉showHelp();␊ |
1092 | ␉␉␉␉␉}␊ |
1093 | ␉␉␉␉␉key = 0;␊ |
1094 | ␉␉␉␉␉GUI_showBootPrompt(nextRow, showPrompt);␊ |
1095 | ␉␉␉␉␉break;␊ |
1096 | ␉␉␉␉}␊ |
1097 | ␉␉␉␉gBootVolume = menuBVR;␊ |
1098 | ␉␉␉␉setRootVolume(menuBVR);␊ |
1099 | safe_set_env(envgBIOSDev,menuBVR->biosdev);␊ |
1100 | ␉␉␉␉break;␊ |
1101 | ␉␉␉␉␊ |
1102 | ␉␉␉case kEscapeKey:␊ |
1103 | ␉␉␉␉GUI_clearBootArgs();␊ |
1104 | ␉␉␉␉break;␊ |
1105 | ␉␉␉␉␊ |
1106 | ␉␉␉case kF5Key:␊ |
1107 | ␉␉␉␉// New behavior:␊ |
1108 | ␉␉␉␉// Clear gBootVolume to restart the loop␊ |
1109 | ␉␉␉␉// if the user enabled rescanning the optical drive.␊ |
1110 | ␉␉␉␉// Otherwise boot the default boot volume.␊ |
1111 | ␉␉␉␉if (get_env(envgEnableCDROMRescan)) {␊ |
1112 | ␉␉␉␉␉gBootVolume = NULL;␊ |
1113 | ␉␉␉␉␉GUI_clearBootArgs();␊ |
1114 | ␉␉␉␉}␊ |
1115 | ␉␉␉␉break;␊ |
1116 | ␉␉␉␉␊ |
1117 | ␉␉␉case kF10Key:␊ |
1118 | safe_set_env(envgScanSingleDrive, false);␊ |
1119 | #if UNUSED␊ |
1120 | scanDisks((int)get_env(envgBIOSDev), &bvCount);␊ |
1121 | #else␊ |
1122 | scanDisks();␊ |
1123 | #endif␊ |
1124 | ␉␉␉␉gBootVolume = NULL;␊ |
1125 | ␉␉␉␉GUI_clearBootArgs();␊ |
1126 | ␉␉␉␉break;␊ |
1127 | ␉␉␉␉␊ |
1128 | ␉␉␉case kTabKey:␊ |
1129 | ␉␉␉␉// New behavior:␊ |
1130 | ␉␉␉␉// Switch between text & graphic interfaces␊ |
1131 | ␉␉␉␉// Only Permitted if started in graphics interface␊ |
1132 | ␉␉␉␉if (useGUI)␊ |
1133 | ␉␉␉␉{␊ |
1134 | ␉␉␉␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
1135 | ␉␉␉␉␉{␊ |
1136 | #if UNUSED␊ |
1137 | ␉␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1138 | #else␊ |
1139 | ␉␉␉␉␉␉setVideoMode(VGA_TEXT_MODE);␊ |
1140 | #endif␉␉␉␉␉␊ |
1141 | ␉␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1142 | ␉␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1143 | ␊ |
1144 | ␉␉␉␉␉␉char * bootBanner = (char*)(uint32_t)get_env(envBootBanner);␊ |
1145 | ␊ |
1146 | ␉␉␉␉␉␉// Display banner and show hardware info.␊ |
1147 | ␉␉␉␉␉␉printf(bootBanner, (int)(get_env(envConvMem) + get_env(envExtMem)) / 1024);␊ |
1148 | ␉␉␉␉␉␉printf(getVBEInfoString());␊ |
1149 | ␉␉␉␉␉␉␊ |
1150 | ␉␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
1151 | ␉␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
1152 | ␉␉␉␉␉␉␊ |
1153 | ␉␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1154 | ␉␉␉␉␉␉␊ |
1155 | ␉␉␉␉␉␉if (devcnt)␊ |
1156 | ␉␉␉␉␉␉{␊ |
1157 | ␉␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1158 | ␉␉␉␉␉␉␉GUI_showMenu(menuItems, devcnt, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
1159 | ␉␉␉␉␉␉␉nextRow += min(devcnt, kMenuMaxItems) + 3;␊ |
1160 | ␉␉␉␉␉␉}␊ |
1161 | ␉␉␉␉␉␉␊ |
1162 | ␉␉␉␉␉␉showPrompt = (devcnt == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1163 | ␉␉␉␉␉␉GUI_showBootPrompt(nextRow, showPrompt);␊ |
1164 | ␉␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
1165 | ␉␉␉␉␉} ␊ |
1166 | ␉␉␉␉␉else ␊ |
1167 | ␉␉␉␉␉{␊ |
1168 | ␉␉␉␉␉␉gui.redraw = true;␊ |
1169 | #if UNUSED␊ |
1170 | ␉␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1171 | #else␊ |
1172 | ␉␉␉␉␉␉setVideoMode(GRAPHICS_MODE);␊ |
1173 | #endif␊ |
1174 | ␉␉␉␉␉␉updateVRAM();␊ |
1175 | ␉␉␉␉␉}␊ |
1176 | ␉␉␉␉}␊ |
1177 | ␉␉␉␉key = 0;␊ |
1178 | ␉␉␉␉break;␊ |
1179 | ␉␉␉␉␊ |
1180 | ␉␉␉default:␊ |
1181 | ␉␉␉␉key = 0;␊ |
1182 | ␉␉␉␉break;␊ |
1183 | ␉␉}␊ |
1184 | ␉} while (0 == key);␊ |
1185 | ␉␊ |
1186 | done:␊ |
1187 | ␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
1188 | ␉{␊ |
1189 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
1190 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
1191 | ␉}␊ |
1192 | safe_set_env(envShouldboot, false);␊ |
1193 | ␉gui.menu.draw = false;␊ |
1194 | ␉if (menuItems)␊ |
1195 | ␉{␊ |
1196 | ␉␉free(menuItems);␊ |
1197 | ␉␉menuItems = NULL;␊ |
1198 | ␉}␊ |
1199 | ␉return 0;␊ |
1200 | }␊ |
1201 | ␊ |
1202 | ␊ |
1203 | ␊ |
1204 | int GUI_error(const char * fmt, ...)␊ |
1205 | {␊ |
1206 | va_list ap;␊ |
1207 | gErrors = true;␊ |
1208 | va_start(ap, fmt);␊ |
1209 | ␉␊ |
1210 | ␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
1211 | ␉{␊ |
1212 | ␉␉prf(fmt, ap, putchar, 0);␊ |
1213 | }␊ |
1214 | ␉else␊ |
1215 | ␉{␊ |
1216 | ␉␉vprf(fmt, ap);␊ |
1217 | ␉}␊ |
1218 | ␉␊ |
1219 | ␉va_end(ap);␊ |
1220 | return(0);␊ |
1221 | }␊ |
1222 | ␊ |
1223 | int GUI_verbose(const char * fmt, ...)␊ |
1224 | {␊ |
1225 | va_list ap;␊ |
1226 | ␊ |
1227 | ␉va_start(ap, fmt);␊ |
1228 | ␉␊ |
1229 | if (gVerboseMode && (KernelStart == false))␊ |
1230 | {␊ |
1231 | ␉␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
1232 | ␉␉{␊ |
1233 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
1234 | ␉␉}␊ |
1235 | ␉␉else␊ |
1236 | ␉␉{␊ |
1237 | ␉␉␉vprf(fmt, ap);␊ |
1238 | ␉␉}␊ |
1239 | }␊ |
1240 | ␉␊ |
1241 | ␉/* Kabyl: BooterLog */␊ |
1242 | ␉struct putc_info pi;␊ |
1243 | ␉␊ |
1244 | ␉if (!msgbuf)␊ |
1245 | ␉␉return 0;␊ |
1246 | ␉␊ |
1247 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
1248 | ␉␉return 0;␊ |
1249 | ␉pi.str = cursor;␊ |
1250 | ␉pi.last_str = 0;␊ |
1251 | ␉prf(fmt, ap, sputc, &pi);␊ |
1252 | ␉cursor += strlen((char *)cursor);␊ |
1253 | ␉␊ |
1254 | ␉␊ |
1255 | va_end(ap);␊ |
1256 | return(0);␊ |
1257 | }␊ |
1258 | ␊ |
1259 | int GUI_printf(const char * fmt, ...)␊ |
1260 | {␊ |
1261 | va_list ap;␊ |
1262 | ␉va_start(ap, fmt);␊ |
1263 | ␉␊ |
1264 | ␉if (KernelStart == false) {␊ |
1265 | ␉␉␊ |
1266 | ␉␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
1267 | ␉␉{␊ |
1268 | ␉␉␉prf(fmt, ap, putchar, 0);␊ |
1269 | ␉␉}␊ |
1270 | ␉␉else␊ |
1271 | ␉␉{␊ |
1272 | ␉␉␉vprf(fmt, ap);␊ |
1273 | ␉␉}␊ |
1274 | ␉}␊ |
1275 | ␉/* Kabyl: BooterLog */␊ |
1276 | ␉struct putc_info pi;␊ |
1277 | ␉␊ |
1278 | ␉if (!msgbuf)␊ |
1279 | ␉␉return 0;␊ |
1280 | ␉␊ |
1281 | ␉if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))␊ |
1282 | ␉␉return 0;␊ |
1283 | ␉pi.str = cursor;␊ |
1284 | ␉pi.last_str = 0;␊ |
1285 | ␉prf(fmt, ap, sputc, &pi);␊ |
1286 | ␉cursor += strlen((char *)cursor);␊ |
1287 | ␉␊ |
1288 | ␉va_end(ap);␊ |
1289 | return 0;␊ |
1290 | }␊ |
1291 | ␊ |
1292 | void GUI_stop(const char * fmt, ...)␊ |
1293 | {␊ |
1294 | ␉va_list ap;␊ |
1295 | ␉␊ |
1296 | ␉printf("\n");␊ |
1297 | ␉va_start(ap, fmt);␊ |
1298 | ␉␊ |
1299 | ␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
1300 | ␉{␊ |
1301 | ␉␉prf(fmt, ap, putchar, 0);␊ |
1302 | ␉} ␊ |
1303 | ␉else ␊ |
1304 | ␉{␊ |
1305 | ␉␉vprf(fmt, ap);␊ |
1306 | ␉}␊ |
1307 | ␉va_end(ap);␊ |
1308 | ␉␊ |
1309 | ␉printf("\nThis is a non recoverable error! System HALTED!!!");␊ |
1310 | ␉halt();␊ |
1311 | ␉while (1);␊ |
1312 | }␊ |
1313 | ␊ |
1314 | void GUI_showHelp(void)␊ |
1315 | {␊ |
1316 | ␉if (getVideoMode() == GRAPHICS_MODE) {␊ |
1317 | ␉␉showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);␊ |
1318 | ␉} else {␊ |
1319 | ␉␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1320 | ␉}␊ |
1321 | }␊ |
1322 | ␊ |
1323 | void GUI_showMessage(char *message)␊ |
1324 | {␊ |
1325 | ␉if (getVideoMode() == GRAPHICS_MODE) {␊ |
1326 | ␉␉showInfoBox("Help. Press q to quit.\n", message);␊ |
1327 | ␉} else {␊ |
1328 | ␉␉showTextBuffer(message, strlen(message));␊ |
1329 | ␉}␊ |
1330 | } |