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 | ␉␉strlcat(gBootArgs, argStr, BOOT_STRING_LEN);␊ |
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 | ␉␉{␉␉␉␊ |
815 | ␉␉␉prompt = malloc(cnt + 1);␊ |
816 | if (!prompt) {␊ |
817 | stop("Couldn't allocate memory for the prompt\n"); //TODO: Find a better stategie␊ |
818 | return -1;␊ |
819 | }␊ |
820 | ␉␉␉strncat(prompt, val, cnt);␊ |
821 | ␉␉} else {␊ |
822 | ␉␉␉name = malloc(80);␊ |
823 | if (!name) {␊ |
824 | stop("Couldn't allocate memory for the device name\n"); //TODO: Find a better stategie␊ |
825 | return -1;␊ |
826 | }␊ |
827 | ␉␉␉getBootVolumeDescription(((BVRef)(uint32_t)get_env(envgBootVolume)), name, 79, false);␊ |
828 | ␉␉␉prompt = malloc(256); ␊ |
829 | if (!prompt) {␊ |
830 | free(name);␊ |
831 | stop("Couldn't allocate memory for the prompt\n"); //TODO: Find a better stategie␊ |
832 | return -1;␊ |
833 | }␊ |
834 | ␉␉␉snprintf(prompt, 256 ,"Press ENTER to start up from %s, or press any key to enter startup options.", name);␊ |
835 | ␉␉␉free(name);␊ |
836 | ␉␉}␊ |
837 | ␉␉␊ |
838 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, DEFAULT_BOOT_CONFIG ))␊ |
839 | ␉␉{␊ |
840 | ␉␉␉// The key specified is a special key.␊ |
841 | ␉␉}␊ |
842 | ␉␉else␊ |
843 | ␉␉{␊ |
844 | ␉␉␉// Default to F8.␊ |
845 | ␉␉␉optionKey = 0x4200;␊ |
846 | ␉␉}␊ |
847 | ␉␉␊ |
848 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
849 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
850 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
851 | ␉␉if (timeout != 0) {␊ |
852 | ␉␉␉key = GUI_countdown(prompt, kMenuTopRow, timeout, &optionKey);␊ |
853 | ␉␉} ␊ |
854 | ␉␉else ␊ |
855 | ␉␉{␊ |
856 | ␉␉␉key = optionKey;␊ |
857 | ␉␉}␊ |
858 | ␉␉␊ |
859 | ␉␉if (prompt != NULL)␊ |
860 | ␉␉{␊ |
861 | ␉␉␉free(prompt);␊ |
862 | ␉␉}␊ |
863 | ␉␉␊ |
864 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
865 | ␉␉␊ |
866 | ␉␉do {␊ |
867 | // Hit the option key ?␊ |
868 | if (key == optionKey) {␊ |
869 | ␊ |
870 | if (key != 0x1C0D) {␊ |
871 | gBootMode &= ~kBootModeQuiet;␊ |
872 | safe_set_env(envgBootMode,gBootMode);␊ |
873 | timeout = 0;␊ |
874 | break;␊ |
875 | }␊ |
876 | ␊ |
877 | } ␊ |
878 | ␊ |
879 | key = key & 0xFF;␊ |
880 | ␊ |
881 | // Try booting hard disk if user pressed 'h'␊ |
882 | if (biosDevIsCDROM((int)get_env(envgBIOSDev)) && key == 'h') {␊ |
883 | BVRef bvr;␊ |
884 | ␊ |
885 | // Look at partitions hosting OS X other than the CD-ROM␊ |
886 | for (bvr = getBvChain(); bvr; bvr=bvr->next) {␊ |
887 | if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != (int)get_env(envgBIOSDev)) {␊ |
888 | ␉␉␉␉␉␉safe_set_env(envgBootVolume, (uint32_t)bvr);␊ |
889 | }␊ |
890 | }␊ |
891 | }␊ |
892 | goto done;␊ |
893 | ␊ |
894 | } while (0);␊ |
895 | ␉}␊ |
896 | ␉␊ |
897 | ␉if (gBootMode & kBootModeQuiet)␊ |
898 | ␉{␊ |
899 | ␉␉// No input allowed from user.␊ |
900 | ␉␉goto done;␊ |
901 | ␉}␊ |
902 | ␉␊ |
903 | ␉if (firstRun && timeout > 0 ) {␊ |
904 | ␊ |
905 | key = GUI_countdown("Press ENTER to start up, or press any key to enter startup options.", kMenuTopRow, timeout, &optionKey);␊ |
906 | ␊ |
907 | if (key == 0x1C0D) {␊ |
908 | goto done;␊ |
909 | ␊ |
910 | } ␊ |
911 | else if (key == 0)␊ |
912 | {␊ |
913 | // If the user is holding down a modifier key,␊ |
914 | // enter safe mode. ␊ |
915 | ␊ |
916 | if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
917 | gBootMode |= kBootModeSafe;␊ |
918 | safe_set_env(envgBootMode,gBootMode);␊ |
919 | }␊ |
920 | goto done;␊ |
921 | }␊ |
922 | ␉}␊ |
923 | ␊ |
924 | ␉if (devcnt)␊ |
925 | ␉{␊ |
926 | ␉␉// Allocate memory for an array of menu items.␊ |
927 | ␉␉menuItems = malloc(sizeof(MenuItem) * devcnt);␊ |
928 | ␉␉if (menuItems == NULL) ␊ |
929 | ␉␉{␊ |
930 | ␉␉␉goto done;␊ |
931 | ␉␉}␊ |
932 | ␉␉␊ |
933 | ␉␉// Associate a menu item for each BVRef.␊ |
934 | ␉␉for (bvr=getBvChain(), i=devcnt-1, selectIndex=0; bvr; bvr=bvr->next)␊ |
935 | ␉␉{␊ |
936 | ␉␉␉if (bvr->visible)␊ |
937 | ␉␉␉{␊ |
938 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true);␊ |
939 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
940 | ␉␉␉␉if (bvr == menuBVR)␊ |
941 | ␉␉␉␉{␊ |
942 | ␉␉␉␉␉selectIndex = i;␊ |
943 | safe_set_env(envSelectIndex, selectIndex);␊ |
944 | ␉␉␉␉}␊ |
945 | ␉␉␉␉i--;␊ |
946 | ␉␉␉}␊ |
947 | ␉␉}␊ |
948 | ␉}␊ |
949 | ␉␊ |
950 | ␉if (getVideoMode() == GRAPHICS_MODE)␊ |
951 | ␉{␊ |
952 | ␉␉// redraw the background buffer␊ |
953 | ␉␉gui.logo.draw = true;␊ |
954 | ␉␉drawBackground();␊ |
955 | ␉␉gui.devicelist.draw = true;␊ |
956 | ␉␉gui.redraw = true;␊ |
957 | ␉␉if (!(gBootMode & kBootModeQuiet))␊ |
958 | ␉␉{␊ |
959 | ␉␉␉bool showBootBanner = true;␊ |
960 | ␉␉␉␊ |
961 | ␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
962 | ␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, DEFAULT_BOOT_CONFIG); ␊ |
963 | ␉␉␉if (showBootBanner)␊ |
964 | ␉␉␉{␊ |
965 | char * bootBanner = (char*)(uint32_t)get_env(envBootBanner);␊ |
966 | ␊ |
967 | ␉␉␉␉// Display banner and show hardware info.␊ |
968 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (int)(get_env(envConvMem) + get_env(envExtMem)) / 1024);␊ |
969 | ␊ |
970 | ␉␉␉}␊ |
971 | ␉␉␉␊ |
972 | ␉␉␉// redraw background␊ |
973 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
974 | ␉␉}␊ |
975 | ␉}␊ |
976 | ␉else ␊ |
977 | ␉{␊ |
978 | ␉␉// Clear screen and hide the blinking cursor.␊ |
979 | ␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
980 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
981 | ␉}␊ |
982 | ␉␊ |
983 | ␉nextRow = kMenuTopRow;␊ |
984 | ␉␊ |
985 | ␉if (devcnt)␊ |
986 | ␉{␊ |
987 | ␉␉if( getVideoMode() == VGA_TEXT_MODE )␊ |
988 | ␉␉{␊ |
989 | ␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
990 | ␉␉}␊ |
991 | ␉␉GUI_showMenu( menuItems, devcnt, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
992 | ␉␉nextRow += min( devcnt, kMenuMaxItems ) + 3;␊ |
993 | ␉}␊ |
994 | ␉␊ |
995 | ␉// Show the boot prompt.␊ |
996 | ␉showPrompt = (devcnt == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
997 | ␉GUI_showBootPrompt( nextRow, showPrompt );␊ |
998 | ␉␊ |
999 | ␉do {␊ |
1000 | ␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
1001 | ␉␉{␊ |
1002 | ␉␉␉// redraw background␊ |
1003 | ␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1004 | ␉␉␉// reset cursor co-ords␊ |
1005 | ␉␉␉gui.debug.cursor = pos( gui.screen.width - 160 , 10 );␊ |
1006 | ␉␉}␊ |
1007 | ␉␉key = getc();␊ |
1008 | ␉␉GUI_updateMenu( key, (void **) &menuBVR );␊ |
1009 | ␉␉newShowPrompt = (devcnt == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1010 | ␉␉␊ |
1011 | ␉␉if (newShowPrompt != showPrompt)␊ |
1012 | ␉␉{␊ |
1013 | ␉␉␉showPrompt = newShowPrompt;␊ |
1014 | ␉␉␉GUI_showBootPrompt( nextRow, showPrompt );␊ |
1015 | ␉␉}␊ |
1016 | ␉␉␊ |
1017 | ␉␉if (showPrompt)␊ |
1018 | ␉␉{␊ |
1019 | ␉␉␉GUI_updateBootArgs(key);␊ |
1020 | ␉␉}␊ |
1021 | ␉␉␊ |
1022 | ␉␉switch (key)␊ |
1023 | ␉␉{␊ |
1024 | ␉␉␉case kReturnKey:␊ |
1025 | ␉␉␉␉if (gui.menu.draw)␊ |
1026 | ␉␉␉␉{ ␊ |
1027 | ␉␉␉␉␉key=0;␊ |
1028 | ␉␉␉␉␉break;␊ |
1029 | ␉␉␉␉}␊ |
1030 | ␉␉␉␉if (*gBootArgs == '?')␊ |
1031 | ␉␉␉␉{␊ |
1032 | ␉␉␉␉␉char * argPtr = gBootArgs;␊ |
1033 | ␉␉␉␉␉␊ |
1034 | ␉␉␉␉␉// Skip the leading "?" character.␊ |
1035 | ␉␉␉␉␉argPtr++;␊ |
1036 | ␉␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
1037 | ␉␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
1038 | ␉␉␉␉␉␊ |
1039 | ␉␉␉␉␉/*␊ |
1040 | ␉␉␉␉␉ * TODO: this needs to be refactored.␊ |
1041 | ␉␉␉␉␉ */␊ |
1042 | ␉␉␉␉␉if (strncmp( booterCommand, "video", sizeof("video") ) == 0)␊ |
1043 | ␉␉␉␉␉{␊ |
1044 | ␉␉␉␉␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
1045 | ␉␉␉␉␉␉{␊ |
1046 | ␉␉␉␉␉␉␉showInfoBox(getVBEInfoString(), getVBEModeInfoString());␊ |
1047 | ␉␉␉␉␉␉}␊ |
1048 | ␉␉␉␉␉␉else␊ |
1049 | ␉␉␉␉␉␉{␊ |
1050 | ␉␉␉␉␉␉␉printVBEModeInfo();␊ |
1051 | ␉␉␉␉␉␉}␊ |
1052 | ␉␉␉␉␉}␊ |
1053 | ␉␉␉␉␉else if ( strncmp( booterCommand, "memory", sizeof("memory") ) == 0)␊ |
1054 | ␉␉␉␉␉{␊ |
1055 | ␉␉␉␉␉␉if (getVideoMode() == GRAPHICS_MODE ) ␊ |
1056 | ␉␉␉␉␉␉{␊ |
1057 | ␉␉␉␉␉␉␉showInfoBox("Memory Map", getMemoryInfoString());␊ |
1058 | ␉␉␉␉␉␉}␊ |
1059 | ␉␉␉␉␉␉else␊ |
1060 | ␉␉␉␉␉␉{␊ |
1061 | ␉␉␉␉␉␉␉printMemoryInfo();␊ |
1062 | ␉␉␉␉␉␉}␊ |
1063 | ␉␉␉␉␉}␊ |
1064 | ␉␉␉␉␉else if (strncmp(booterCommand, "lspci", sizeof( "lspci")) == 0)␊ |
1065 | ␉␉␉␉␉{␊ |
1066 | ␉␉␉␉␉␉lspci();␊ |
1067 | ␉␉␉␉␉}␊ |
1068 | ␉␉␉␉␉else if (strncmp(booterCommand, "more", sizeof("more")) == 0)␊ |
1069 | ␉␉␉␉␉{␊ |
1070 | ␉␉␉␉␉␉showTextFile(booterParam);␊ |
1071 | ␉␉␉␉␉}␊ |
1072 | ␉␉␉␉␉else if (strncmp(booterCommand, "rd", sizeof("rd")) == 0)␊ |
1073 | ␉␉␉␉␉{␊ |
1074 | ␉␉␉␉␉␉if (execute_hook("processRAMDiskCommand", (void*)argPtr, &booterParam, NULL, NULL, NULL, NULL) != EFI_SUCCESS)␊ |
1075 | ␉␉␉␉␉␉␉showMessage("ramdisk module not found, please install RamdiskLoader.dylib in /Extra/modules/");␊ |
1076 | ␉␉␉␉␉} ␊ |
1077 | ␉␉␉␉␉else if (strncmp(booterCommand, "norescan", sizeof("norescan")) == 0)␊ |
1078 | ␉␉␉␉␉{␊ |
1079 | ␉␉␉␉␉␉if (get_env(envgEnableCDROMRescan))␊ |
1080 | {␊ |
1081 | safe_set_env(envgEnableCDROMRescan,false);␊ |
1082 | break;␊ |
1083 | }␊ |
1084 | ␉␉␉␉␉} ␊ |
1085 | ␉␉␉␉␉else␊ |
1086 | ␉␉␉␉␉{␊ |
1087 | ␉␉␉␉␉␉showHelp();␊ |
1088 | ␉␉␉␉␉}␊ |
1089 | ␉␉␉␉␉key = 0;␊ |
1090 | ␉␉␉␉␉GUI_showBootPrompt(nextRow, showPrompt);␊ |
1091 | ␉␉␉␉␉break;␊ |
1092 | ␉␉␉␉}␊ |
1093 | ␉␉␉␉safe_set_env(envgBootVolume, (uint32_t)menuBVR);␊ |
1094 | ␉␉␉␉setRootVolume(menuBVR);␊ |
1095 | safe_set_env(envgBIOSDev,menuBVR->biosdev);␊ |
1096 | ␉␉␉␉break;␊ |
1097 | ␉␉␉␉␊ |
1098 | ␉␉␉case kEscapeKey:␊ |
1099 | ␉␉␉␉GUI_clearBootArgs();␊ |
1100 | ␉␉␉␉break;␊ |
1101 | ␉␉␉␉␊ |
1102 | ␉␉␉case kF5Key:␊ |
1103 | ␉␉␉␉// New behavior:␊ |
1104 | ␉␉␉␉// Clear gBootVolume to restart the loop␊ |
1105 | ␉␉␉␉// if the user enabled rescanning the optical drive.␊ |
1106 | ␉␉␉␉// Otherwise boot the default boot volume.␊ |
1107 | ␉␉␉␉if (get_env(envgEnableCDROMRescan)) {␊ |
1108 | ␉␉␉␉␉safe_set_env(envgBootVolume, (uint32_t)NULL);␊ |
1109 | ␉␉␉␉␉GUI_clearBootArgs();␊ |
1110 | ␉␉␉␉}␊ |
1111 | ␉␉␉␉break;␊ |
1112 | ␉␉␉␉␊ |
1113 | ␉␉␉case kF10Key:␊ |
1114 | safe_set_env(envgScanSingleDrive, false);␊ |
1115 | #if UNUSED␊ |
1116 | scanDisks((int)get_env(envgBIOSDev), &bvCount);␊ |
1117 | #else␊ |
1118 | scanDisks();␊ |
1119 | #endif␊ |
1120 | ␉␉␉␉safe_set_env(envgBootVolume, (uint32_t)NULL);␊ |
1121 | ␉␉␉␉␊ |
1122 | ␉␉␉␉GUI_clearBootArgs();␊ |
1123 | ␉␉␉␉break;␊ |
1124 | ␉␉␉␉␊ |
1125 | ␉␉␉case kTabKey:␊ |
1126 | ␉␉␉␉// New behavior:␊ |
1127 | ␉␉␉␉// Switch between text & graphic interfaces␊ |
1128 | ␉␉␉␉// Only Permitted if started in graphics interface␊ |
1129 | ␉␉␉␉if (useGUI)␊ |
1130 | ␉␉␉␉{␊ |
1131 | ␉␉␉␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
1132 | ␉␉␉␉␉{␊ |
1133 | #if UNUSED␊ |
1134 | ␉␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1135 | #else␊ |
1136 | ␉␉␉␉␉␉setVideoMode(VGA_TEXT_MODE);␊ |
1137 | #endif␉␉␉␉␉␊ |
1138 | ␉␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1139 | ␉␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1140 | ␊ |
1141 | ␉␉␉␉␉␉char * bootBanner = (char*)(uint32_t)get_env(envBootBanner);␊ |
1142 | ␊ |
1143 | ␉␉␉␉␉␉// Display banner and show hardware info.␊ |
1144 | ␉␉␉␉␉␉printf(bootBanner, (int)(get_env(envConvMem) + get_env(envExtMem)) / 1024);␊ |
1145 | ␉␉␉␉␉␉printf(getVBEInfoString());␊ |
1146 | ␉␉␉␉␉␉␊ |
1147 | ␉␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
1148 | ␉␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
1149 | ␉␉␉␉␉␉␊ |
1150 | ␉␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1151 | ␉␉␉␉␉␉␊ |
1152 | ␉␉␉␉␉␉if (devcnt)␊ |
1153 | ␉␉␉␉␉␉{␊ |
1154 | ␉␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1155 | ␉␉␉␉␉␉␉GUI_showMenu(menuItems, devcnt, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
1156 | ␉␉␉␉␉␉␉nextRow += min(devcnt, kMenuMaxItems) + 3;␊ |
1157 | ␉␉␉␉␉␉}␊ |
1158 | ␉␉␉␉␉␉␊ |
1159 | ␉␉␉␉␉␉showPrompt = (devcnt == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1160 | ␉␉␉␉␉␉GUI_showBootPrompt(nextRow, showPrompt);␊ |
1161 | ␉␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
1162 | ␉␉␉␉␉} ␊ |
1163 | ␉␉␉␉␉else ␊ |
1164 | ␉␉␉␉␉{␊ |
1165 | ␉␉␉␉␉␉gui.redraw = true;␊ |
1166 | #if UNUSED␊ |
1167 | ␉␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1168 | #else␊ |
1169 | ␉␉␉␉␉␉setVideoMode(GRAPHICS_MODE);␊ |
1170 | #endif␊ |
1171 | ␉␉␉␉␉␉updateVRAM();␊ |
1172 | ␉␉␉␉␉}␊ |
1173 | ␉␉␉␉}␊ |
1174 | ␉␉␉␉key = 0;␊ |
1175 | ␉␉␉␉break;␊ |
1176 | ␉␉␉␉␊ |
1177 | ␉␉␉default:␊ |
1178 | ␉␉␉␉key = 0;␊ |
1179 | ␉␉␉␉break;␊ |
1180 | ␉␉}␊ |
1181 | ␉} while (0 == key);␊ |
1182 | ␉␊ |
1183 | done:␊ |
1184 | ␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
1185 | ␉{␊ |
1186 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
1187 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
1188 | ␉}␊ |
1189 | safe_set_env(envShouldboot, false);␊ |
1190 | ␉gui.menu.draw = false;␊ |
1191 | ␉if (menuItems)␊ |
1192 | ␉{␊ |
1193 | ␉␉free(menuItems);␊ |
1194 | ␉␉menuItems = NULL;␊ |
1195 | ␉}␊ |
1196 | ␉return 0;␊ |
1197 | }␊ |
1198 | ␊ |
1199 | int␊ |
1200 | GUI_reallyVPrint(const char *format, va_list ap, int flag)␊ |
1201 | {␊ |
1202 | #define LOG 1␊ |
1203 | #define PRINT 2␊ |
1204 | ␊ |
1205 | if (KernelStart == false)␊ |
1206 | {␊ |
1207 | if (flag & PRINT) {␊ |
1208 | ␊ |
1209 | if (getVideoMode() == VGA_TEXT_MODE)␊ |
1210 | {␊ |
1211 | prf(format, ap, putchar);␊ |
1212 | }␊ |
1213 | else␊ |
1214 | {␊ |
1215 | vprf(format, ap);␊ |
1216 | }␊ |
1217 | }␊ |
1218 | } ␊ |
1219 | ␊ |
1220 | if (flag & LOG)␊ |
1221 | {␊ |
1222 | /* Kabyl: BooterLog */␉␉␊ |
1223 | prf(format, ap, debug_putc);␊ |
1224 | } ␊ |
1225 | ␊ |
1226 | return 0;␊ |
1227 | }␊ |
1228 | #if 0␊ |
1229 | int GUI_verbose(const char * fmt, ...)␊ |
1230 | {␊ |
1231 | va_list ap;␊ |
1232 | ␊ |
1233 | ␉va_start(ap, fmt);␊ |
1234 | ␉␊ |
1235 | if (get_env(envgVerboseMode) && (KernelStart == false))␊ |
1236 | {␊ |
1237 | ␉␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
1238 | ␉␉{␊ |
1239 | ␉␉␉prf(fmt, ap, putchar);␊ |
1240 | ␉␉}␊ |
1241 | ␉␉else␊ |
1242 | ␉␉{␊ |
1243 | ␉␉␉vprf(fmt, ap);␊ |
1244 | ␉␉}␊ |
1245 | }␊ |
1246 | ␉␊ |
1247 | ␉{␊ |
1248 | ␉␉/* Kabyl: BooterLog */␉␉␊ |
1249 | ␉␉prf(fmt, ap, debug_putc);␊ |
1250 | ␉}␊ |
1251 | ␉␊ |
1252 | va_end(ap);␊ |
1253 | return(0);␊ |
1254 | }␊ |
1255 | ␊ |
1256 | int GUI_printf(const char * fmt, ...)␊ |
1257 | {␊ |
1258 | va_list ap;␊ |
1259 | ␉va_start(ap, fmt);␊ |
1260 | ␉␊ |
1261 | ␉if (KernelStart == false) {␊ |
1262 | ␉␉␊ |
1263 | ␉␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
1264 | ␉␉{␊ |
1265 | ␉␉␉prf(fmt, ap, putchar);␊ |
1266 | ␉␉}␊ |
1267 | ␉␉else␊ |
1268 | ␉␉{␊ |
1269 | ␉␉␉vprf(fmt, ap);␊ |
1270 | ␉␉}␊ |
1271 | ␉}␊ |
1272 | ␊ |
1273 | ␉{␊ |
1274 | ␉␉/* Kabyl: BooterLog */␉␉␊ |
1275 | ␉␉prf(fmt, ap, debug_putc);␊ |
1276 | ␉}␊ |
1277 | ␉va_end(ap);␊ |
1278 | return 0;␊ |
1279 | }␊ |
1280 | ␊ |
1281 | void GUI_stop(const char * fmt, ...)␊ |
1282 | {␊ |
1283 | ␉va_list ap;␊ |
1284 | ␉␊ |
1285 | ␉printf("\n");␊ |
1286 | ␉va_start(ap, fmt);␊ |
1287 | ␉␊ |
1288 | ␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
1289 | ␉{␊ |
1290 | ␉␉prf(fmt, ap, putchar);␊ |
1291 | ␉} ␊ |
1292 | ␉else ␊ |
1293 | ␉{␊ |
1294 | ␉␉vprf(fmt, ap);␊ |
1295 | ␉}␊ |
1296 | ␉va_end(ap);␊ |
1297 | ␉␊ |
1298 | ␉printf("\nThis is a non recoverable error! System HALTED!!!");␊ |
1299 | ␉halt();␊ |
1300 | ␉while (1);␊ |
1301 | }␊ |
1302 | #endif␊ |
1303 | void GUI_showHelp(void)␊ |
1304 | {␊ |
1305 | ␉if (getVideoMode() == GRAPHICS_MODE) {␊ |
1306 | ␉␉showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);␊ |
1307 | ␉} else {␊ |
1308 | ␉␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1309 | ␉}␊ |
1310 | }␊ |
1311 | ␊ |
1312 | void GUI_showMessage(char *message)␊ |
1313 | {␊ |
1314 | ␉if (getVideoMode() == GRAPHICS_MODE) {␊ |
1315 | ␉␉showInfoBox("Help. Press q to quit.\n", message);␊ |
1316 | ␉} else {␊ |
1317 | ␉␉showTextBuffer(message, strlen(message));␊ |
1318 | ␉}␊ |
1319 | } |