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