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