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