1 | /*␊ |
2 | * Copyright (c) 1999-2004 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2004 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License"). You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | * ␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | ␊ |
25 | #include "boot.h"␊ |
26 | #include "bootstruct.h"␊ |
27 | #include "fdisk.h"␊ |
28 | #include "ramdisk.h"␊ |
29 | #include "gui.h"␊ |
30 | #include "term.h"␊ |
31 | #include "embedded.h"␊ |
32 | #include "pci.h"␊ |
33 | #include "modules.h"␊ |
34 | ␊ |
35 | #if DEBUG␊ |
36 | #define DBG(x...)␉printf(x)␊ |
37 | #else␊ |
38 | #define DBG(x...)␉msglog(x)␊ |
39 | #endif␊ |
40 | // Bungo:␊ |
41 | char␉␉gMacOSVersion[OSVERSTRLEN];␊ |
42 | uint32_t␉MacOSVerCurrent = 0;␊ |
43 | //Azi: showinfo␊ |
44 | bool␉␉showBootBanner = true;␊ |
45 | static bool␉shouldboot = false;␊ |
46 | ␊ |
47 | extern int multiboot_timeout;␊ |
48 | extern int multiboot_timeout_set;␊ |
49 | ␊ |
50 | extern BVRef bvChain;␊ |
51 | //extern int␉␉menucount;␊ |
52 | ␊ |
53 | extern int␉␉gDeviceCount;␊ |
54 | ␊ |
55 | int␉␉␉selectIndex = 0;␊ |
56 | ␊ |
57 | MenuItem *menuItems = NULL;␊ |
58 | ␊ |
59 | enum {␊ |
60 | kMenuTopRow = 5,␊ |
61 | kMenuMaxItems = 10,␊ |
62 | kScreenLastRow = 24␊ |
63 | };␊ |
64 | ␊ |
65 | extern char *msgbuf;␊ |
66 | ␊ |
67 | void showTextBuffer(char *buf_orig, int size);␊ |
68 | ␊ |
69 | //==========================================================================␊ |
70 | // Bungo: MacOSVer2Int - converts OS ver. string to uint32 (e.g "10.9.5" -> 0x0A090500) for easy comparing␊ |
71 | uint32_t MacOSVer2Int(const char *osver)␊ |
72 | {␊ |
73 | ␉uint32_t result = 0;␊ |
74 | ␉uint8_t *resptr = (uint8_t *)&result;␊ |
75 | ␉uint8_t len = strlen(osver);␊ |
76 | ␉uint8_t i, j, m;␊ |
77 | #define CHR2UINT(c) ((uint8_t)(c - '0'))␊ |
78 | #define ISDIGIT(c) ((c >= '0') && (c <= '9'))␊ |
79 | #define ISDOT(c) (c == '.')␊ |
80 | ␊ |
81 | ␉if (!osver || (len < 4) || (len > OSVERSTRLEN - 1) || !ISDIGIT(osver[0]) || !ISDOT(osver[2]) || !ISDIGIT(osver[len - 1]))␊ |
82 | ␉{␊ |
83 | ␉␉verbose("ERROR: wrong Mac OS version string syntax: '%s'\n", osver);␊ |
84 | ␉␉return 0;␊ |
85 | ␉}␊ |
86 | ␊ |
87 | ␉for (i = 0, j = 3, m = 1; i < len; i++)␊ |
88 | ␉{␊ |
89 | ␉␉if (ISDIGIT(osver[i]))␊ |
90 | ␉␉{␊ |
91 | ␉␉␉resptr[j] = resptr[j] * m + CHR2UINT(osver[i]);␊ |
92 | ␉␉␉m = 10;␊ |
93 | ␉␉}␊ |
94 | ␉␉else if (ISDOT(osver[i]))␊ |
95 | ␉␉{␊ |
96 | ␉␉␉if (j > 0)␊ |
97 | ␉␉␉{␊ |
98 | ␉␉␉␉j--;␊ |
99 | ␉␉␉}␊ |
100 | ␉␉␉else␊ |
101 | ␉␉␉{␊ |
102 | ␉␉␉␉return 0;␊ |
103 | ␉␉␉}␊ |
104 | ␉␉␉m = 1;␊ |
105 | ␉␉}␊ |
106 | ␉␉else␊ |
107 | ␉␉{␊ |
108 | ␉␉␉return 0;␊ |
109 | ␉␉}␊ |
110 | ␉}␊ |
111 | ␊ |
112 | ␉return result;␊ |
113 | }␊ |
114 | ␊ |
115 | //==========================================================================␊ |
116 | ␊ |
117 | typedef struct {␊ |
118 | int x;␊ |
119 | int y;␊ |
120 | int type;␊ |
121 | } CursorState;␊ |
122 | ␊ |
123 | static void changeCursor( int col, int row, int type, CursorState * cs )␊ |
124 | {␊ |
125 | if (cs) getCursorPositionAndType( &cs->x, &cs->y, &cs->type );␊ |
126 | setCursorType( type );␊ |
127 | setCursorPosition( col, row, 0 );␊ |
128 | }␊ |
129 | ␊ |
130 | static void moveCursor( int col, int row )␊ |
131 | {␊ |
132 | setCursorPosition( col, row, 0 );␊ |
133 | }␊ |
134 | ␊ |
135 | static void restoreCursor( const CursorState * cs )␊ |
136 | {␊ |
137 | setCursorPosition( cs->x, cs->y, 0 );␊ |
138 | setCursorType( cs->type );␊ |
139 | }␊ |
140 | ␊ |
141 | //==========================================================================␊ |
142 | ␊ |
143 | /* Flush keyboard buffer; returns TRUE if any of the flushed␊ |
144 | * characters was F8.␊ |
145 | */␊ |
146 | ␊ |
147 | static bool flushKeyboardBuffer(void)␊ |
148 | {␊ |
149 | bool status = false;␊ |
150 | ␊ |
151 | while ( readKeyboardStatus() ) {␊ |
152 | if (bgetc() == 0x4200) status = true;␊ |
153 | }␊ |
154 | return status;␊ |
155 | }␊ |
156 | ␊ |
157 | //==========================================================================␊ |
158 | ␊ |
159 | static int countdown( const char * msg, int row, int timeout )␊ |
160 | {␊ |
161 | ␉unsigned long time;␊ |
162 | ␉int ch = 0;␊ |
163 | ␉int col = strlen(msg) + 1;␊ |
164 | ␊ |
165 | ␉flushKeyboardBuffer();␊ |
166 | ␊ |
167 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
168 | ␉{␊ |
169 | ␉␉moveCursor( 0, row );␊ |
170 | ␉␉printf(msg);␊ |
171 | ␊ |
172 | ␉} else {␊ |
173 | ␊ |
174 | ␉␉position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );␊ |
175 | ␊ |
176 | ␉␉char dummy[80];␊ |
177 | ␉␉getBootVolumeDescription( gBootVolume, dummy, sizeof(dummy) - 1, true );␊ |
178 | ␉␉drawDeviceIcon( gBootVolume, gui.screen.pixmap, p, true );␊ |
179 | ␉␉drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );␊ |
180 | ␊ |
181 | ␉␉// make this screen the new background␊ |
182 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
183 | ␊ |
184 | ␉}␊ |
185 | ␊ |
186 | ␉int multi_buff = 18 * (timeout);␊ |
187 | ␉int multi = ++multi_buff;␊ |
188 | ␊ |
189 | ␉int lasttime=0;␊ |
190 | ␊ |
191 | ␉for ( time = time18(), timeout++; timeout > 0; )␊ |
192 | ␉{␊ |
193 | ␉␉if( time18() > lasttime)␊ |
194 | ␉␉{␊ |
195 | ␉␉␉multi--; ␊ |
196 | ␉␉␉lasttime=time18();␊ |
197 | ␉␉}␉␉␊ |
198 | ␊ |
199 | ␉␉if ( (ch = readKeyboardStatus()) )␊ |
200 | ␉␉␉break;␊ |
201 | ␊ |
202 | ␉␉// Count can be interrupted by holding down shift,␊ |
203 | ␉␉// control or alt key␊ |
204 | ␉␉if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 )␊ |
205 | ␉␉{␊ |
206 | ␉␉␉ch = 1;␊ |
207 | ␉␉␉break;␊ |
208 | ␉␉}␊ |
209 | ␊ |
210 | ␉␉if ( time18() >= time )␊ |
211 | ␉␉{␊ |
212 | ␉␉␉time += 18;␊ |
213 | ␉␉␉timeout--;␊ |
214 | ␊ |
215 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
216 | ␉␉␉{␊ |
217 | ␉␉␉␉moveCursor( col, row );␊ |
218 | ␉␉␉␉printf("(%d) ", timeout);␊ |
219 | ␉␉␉}␊ |
220 | ␉␉}␊ |
221 | ␊ |
222 | ␉␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
223 | ␉␉{␊ |
224 | ␉␉␉drawProgressBar( gui.screen.pixmap, 100, gui.progressbar.pos , ( multi * 100 / multi_buff ) );␊ |
225 | ␉␉␉gui.redraw = true;␊ |
226 | ␉␉␉updateVRAM();␊ |
227 | ␉␉}␊ |
228 | ␊ |
229 | ␉}␊ |
230 | ␊ |
231 | ␉flushKeyboardBuffer();␊ |
232 | ␊ |
233 | ␉return ch;␊ |
234 | }␊ |
235 | ␊ |
236 | //==========================================================================␊ |
237 | ␊ |
238 | char␉␉gBootArgs[BOOT_STRING_LEN];␊ |
239 | static char␉*gBootArgsPtr = gBootArgs;␊ |
240 | static char␉*gBootArgsEnd = gBootArgs + BOOT_STRING_LEN - 1;␊ |
241 | static char␉booterCommand[BOOT_STRING_LEN];␊ |
242 | static char␉booterParam[BOOT_STRING_LEN];␊ |
243 | ␊ |
244 | static void clearBootArgs(void)␊ |
245 | {␊ |
246 | ␉gBootArgsPtr = gBootArgs;␊ |
247 | ␉memset(gBootArgs, '\0', BOOT_STRING_LEN);␊ |
248 | ␊ |
249 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE)␊ |
250 | ␉{␊ |
251 | ␉␉clearGraphicBootPrompt();␊ |
252 | ␉}␊ |
253 | ␉execute_hook("ClearArgs", NULL, NULL, NULL, NULL);␊ |
254 | }␊ |
255 | ␊ |
256 | void addBootArg(const char * argStr)␊ |
257 | {␊ |
258 | ␉if ( (gBootArgsPtr + strlen(argStr) + 1) < gBootArgsEnd)␊ |
259 | ␉{␊ |
260 | ␉␉if(gBootArgsPtr != gBootArgs) *gBootArgsPtr++ = ' ';␊ |
261 | ␉␉strcat(gBootArgs, argStr);␊ |
262 | ␉␉gBootArgsPtr += strlen(argStr);␊ |
263 | ␉}␊ |
264 | }␊ |
265 | ␊ |
266 | //==========================================================================␊ |
267 | ␊ |
268 | static void showBootPrompt(int row, bool visible)␊ |
269 | {␊ |
270 | ␉extern char bootPrompt[];␊ |
271 | ␉extern char bootRescanPrompt[];␊ |
272 | ␊ |
273 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
274 | ␉{␊ |
275 | ␉␉changeCursor( 0, row, kCursorTypeUnderline, 0 );␊ |
276 | ␉␉clearScreenRows( row, kScreenLastRow );␊ |
277 | ␉}␊ |
278 | ␊ |
279 | ␉clearBootArgs();␊ |
280 | ␊ |
281 | ␉if (visible)␊ |
282 | ␉{␊ |
283 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
284 | ␉␉{␊ |
285 | ␉␉␉if (gEnableCDROMRescan)␊ |
286 | ␉␉␉{␊ |
287 | ␉␉␉␉printf( bootRescanPrompt );␊ |
288 | ␉␉␉}␊ |
289 | ␉␉␉else␊ |
290 | ␉␉␉{␊ |
291 | ␉␉␉␉printf( bootPrompt );␊ |
292 | ␉␉␉␉printf( gBootArgs );␊ |
293 | ␉␉␉}␊ |
294 | ␉␉}␊ |
295 | ␉}␊ |
296 | ␉else␊ |
297 | ␉{␊ |
298 | ␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE)␊ |
299 | ␉␉{␊ |
300 | ␉␉␉clearGraphicBootPrompt();␊ |
301 | ␉␉}␊ |
302 | ␉␉else␊ |
303 | ␉␉{␊ |
304 | ␉␉␉printf("Press Enter to start up the foreign OS. ");␊ |
305 | ␉␉}␊ |
306 | ␉}␊ |
307 | }␊ |
308 | ␊ |
309 | //==========================================================================␊ |
310 | ␊ |
311 | static void updateBootArgs( int key )␊ |
312 | {␊ |
313 | ␉key = ASCII_KEY(key);␊ |
314 | ␊ |
315 | ␉switch ( key )␊ |
316 | ␉{␊ |
317 | ␉␉case KEY_BKSP:␊ |
318 | ␉␉␉if ( gBootArgsPtr > gBootArgs )␊ |
319 | ␉␉␉{␊ |
320 | ␉␉␉␉*--gBootArgsPtr = '\0';␊ |
321 | ␊ |
322 | ␉␉␉␉int x, y, t;␊ |
323 | ␉␉␉␉getCursorPositionAndType( &x, &y, &t );␊ |
324 | ␉␉␉␉if ( x == 0 && y )␊ |
325 | ␉␉␉␉{␊ |
326 | ␉␉␉␉␉x = 80; y--;␊ |
327 | ␉␉␉␉}␊ |
328 | ␊ |
329 | ␉␉␉␉if (x)␊ |
330 | ␉␉␉␉{␊ |
331 | ␉␉␉␉␉x--;␊ |
332 | ␉␉␉␉}␊ |
333 | ␊ |
334 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
335 | ␉␉␉␉{␊ |
336 | ␉␉␉␉␉setCursorPosition( x, y, 0 );␊ |
337 | ␉␉␉␉␉putca(' ', 0x07, 1);␊ |
338 | ␉␉␉␉}␊ |
339 | ␉␉␉␉else␊ |
340 | ␉␉␉␉{␊ |
341 | ␉␉␉␉␉updateGraphicBootPrompt();␊ |
342 | ␉␉␉␉}␊ |
343 | ␉␉␉}␊ |
344 | ␉␉␉break;␊ |
345 | ␊ |
346 | ␉default:␊ |
347 | ␉␉␉if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
348 | ␉␉␉{␊ |
349 | ␉␉␉␉*gBootArgsPtr++ = key;␊ |
350 | ␊ |
351 | ␉␉␉␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
352 | ␉␉␉␉{␊ |
353 | ␉␉␉␉␉updateGraphicBootPrompt();␊ |
354 | ␉␉␉␉}␊ |
355 | ␉␉␉␉else if ( key >= ' ' && key < 0x7f)␊ |
356 | ␉␉␉␉{␊ |
357 | ␉␉␉␉␉putchar(key);␊ |
358 | ␉␉␉␉}␊ |
359 | ␉␉␉}␊ |
360 | ␊ |
361 | ␉␉␉break;␊ |
362 | ␉}␊ |
363 | }␊ |
364 | ␊ |
365 | //==========================================================================␊ |
366 | ␊ |
367 | static const MenuItem * gMenuItems = NULL;␊ |
368 | ␊ |
369 | static int gMenuItemCount;␊ |
370 | static int gMenuRow;␊ |
371 | static int gMenuHeight;␊ |
372 | static int gMenuTop;␊ |
373 | static int gMenuBottom;␊ |
374 | static int gMenuSelection;␊ |
375 | ␊ |
376 | static int␉ gMenuStart;␊ |
377 | static int␉ gMenuEnd;␊ |
378 | ␊ |
379 | static void printMenuItem( const MenuItem * item, int highlight )␊ |
380 | {␊ |
381 | printf(" ");␊ |
382 | ␊ |
383 | if ( highlight )␊ |
384 | putca(' ', 0x70, strlen(item->name) + 4);␊ |
385 | else␊ |
386 | putca(' ', 0x07, 40);␊ |
387 | ␊ |
388 | printf(" %40s\n", item->name);␊ |
389 | }␊ |
390 | ␊ |
391 | //==========================================================================␊ |
392 | ␊ |
393 | static void showMenu( const MenuItem * items, int count,␊ |
394 | int selection, int row, int height )␊ |
395 | {␊ |
396 | int i;␊ |
397 | CursorState cursorState;␊ |
398 | ␊ |
399 | if ( items == NULL || count == 0 ) ␊ |
400 | ␉␉return;␊ |
401 | ␊ |
402 | // head and tail points to the start and the end of the list.␊ |
403 | // top and bottom points to the first and last visible items␊ |
404 | // in the menu window.␊ |
405 | ␊ |
406 | gMenuItems␉␉= items;␊ |
407 | gMenuRow␉␉= row;␊ |
408 | gMenuHeight␉␉= height;␊ |
409 | gMenuItemCount␉= count;␊ |
410 | gMenuTop␉␉= 0;␊ |
411 | gMenuBottom␉␉= MIN( count, height ) - 1;␊ |
412 | gMenuSelection␉= selection;␊ |
413 | ␊ |
414 | gMenuStart␉␉= 0;␊ |
415 | gMenuEnd␉ = MIN( count, gui.maxdevices ) - 1;␊ |
416 | ␉␊ |
417 | ␉// If the selected item is not visible, shift the list down.␊ |
418 | ␊ |
419 | if ( gMenuSelection > gMenuBottom )␊ |
420 | {␊ |
421 | gMenuTop += ( gMenuSelection - gMenuBottom );␊ |
422 | gMenuBottom = gMenuSelection;␊ |
423 | }␊ |
424 | ␊ |
425 | ␉if ( gMenuSelection > gMenuEnd )␊ |
426 | {␊ |
427 | ␉␉gMenuStart += ( gMenuSelection - gMenuEnd );␊ |
428 | gMenuEnd = gMenuSelection;␊ |
429 | }␊ |
430 | ␉␊ |
431 | ␉// Draw the visible items.␊ |
432 | ␊ |
433 | ␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
434 | ␉{␊ |
435 | ␉␉drawDeviceList(gMenuStart, gMenuEnd, gMenuSelection);␊ |
436 | ␉}␊ |
437 | ␉else␊ |
438 | ␉{␊ |
439 | ␉␉changeCursor( 0, row, kCursorTypeHidden, &cursorState );␊ |
440 | ␊ |
441 | ␉␉for ( i = gMenuTop; i <= gMenuBottom; i++ )␊ |
442 | ␉␉{␊ |
443 | ␉␉␉printMenuItem( &items[i], (i == gMenuSelection) );␊ |
444 | ␉␉}␊ |
445 | ␊ |
446 | ␉␉restoreCursor( &cursorState );␊ |
447 | ␉}␊ |
448 | }␊ |
449 | ␊ |
450 | //==========================================================================␊ |
451 | ␊ |
452 | static int updateMenu( int key, void ** paramPtr )␊ |
453 | {␊ |
454 | int moved = 0;␊ |
455 | ␊ |
456 | union {␊ |
457 | struct {␊ |
458 | unsigned int␊ |
459 | selectionUp : 1,␊ |
460 | selectionDown : 1,␊ |
461 | scrollUp : 1,␊ |
462 | scrollDown : 1;␊ |
463 | } f;␊ |
464 | unsigned int w;␊ |
465 | } draw = {{0}};␊ |
466 | ␊ |
467 | if ( gMenuItems == NULL )␊ |
468 | ␉␉return 0;␊ |
469 | ␊ |
470 | ␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
471 | ␉{␊ |
472 | ␉␉int res;␊ |
473 | ␉␉␊ |
474 | ␉␉// set navigation keys for horizontal layout as defaults␊ |
475 | ␉␉int previous␉= 0x4B00;␉␉// left arrow␊ |
476 | ␉␉int subsequent␉= 0x4D00;␉␉// right arrow␊ |
477 | ␉␉int menu␉␉= 0x5000;␉␉// down arrow␊ |
478 | ␉␉␊ |
479 | ␉␉if ( gui.layout == VerticalLayout )␊ |
480 | ␉␉{␊ |
481 | ␉␉␉// set navigation keys for vertical layout␊ |
482 | ␉␉␉previous␉= 0x4800;␉␉// up arrow␊ |
483 | ␉␉␉subsequent␉= 0x5000;␉␉// down arrow␊ |
484 | ␉␉␉menu␉␉= 0x4B00;␉␉// right arrow␊ |
485 | ␉␉} ␊ |
486 | ␊ |
487 | ␉␉if ( key == previous )␊ |
488 | ␉␉{␊ |
489 | ␉␉␉if ( gMenuSelection > gMenuTop )␊ |
490 | ␉␉␉␉draw.f.selectionUp = 1;␊ |
491 | ␉␉␉else if ( gMenuTop > 0 )␊ |
492 | ␉␉␉␉draw.f.scrollDown = 1;␊ |
493 | ␉␉␉␊ |
494 | ␉␉}␊ |
495 | ␉␉␊ |
496 | ␉␉else if ( key == subsequent )␊ |
497 | ␉␉{␊ |
498 | ␉␉␉if ( gMenuSelection != gMenuBottom)␊ |
499 | ␉␉␉␉draw.f.selectionDown = 1;␊ |
500 | ␉␉␉else if ( gMenuBottom < ( gMenuItemCount - 1 ) )␊ |
501 | ␉␉␉␉draw.f.scrollUp = 1;␊ |
502 | ␉␉}␊ |
503 | ␉␉␊ |
504 | ␉␉else if ( key == menu )␊ |
505 | ␉␉{␊ |
506 | ␉␉␉if ( gui.menu.draw )␊ |
507 | ␉␉␉␉updateInfoMenu(key);␊ |
508 | ␉␉␉else␊ |
509 | ␉␉␉␉drawInfoMenu();␊ |
510 | ␉␉}␊ |
511 | ␊ |
512 | ␉␉else if ( gui.menu.draw )␊ |
513 | ␉␉{␊ |
514 | ␉␉␉res = updateInfoMenu(key);␊ |
515 | ␊ |
516 | ␉␉␉if ( res == CLOSE_INFO_MENU )␊ |
517 | ␉␉␉␉gui.menu.draw = false;␊ |
518 | ␉␉␉else␊ |
519 | ␉␉␉{␊ |
520 | ␉␉␉␉shouldboot = ( res != DO_NOT_BOOT );␊ |
521 | ␉␉␉␉␊ |
522 | ␉␉␉␉if ( shouldboot )␊ |
523 | ␉␉␉␉␉gui.menu.draw = false;␊ |
524 | ␊ |
525 | ␉␉␉␉switch (res)␊ |
526 | ␉␉␉␉{␊ |
527 | ␉␉␉␉␉case BOOT_NORMAL:␊ |
528 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
529 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
530 | ␉␉␉␉␉␉break;␊ |
531 | ␉␉␉␉␉␉␊ |
532 | ␉␉␉␉␉case BOOT_VERBOSE:␊ |
533 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
534 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
535 | ␉␉␉␉␉␉addBootArg(kVerboseModeFlag);␊ |
536 | ␉␉␉␉␉␉break;␊ |
537 | ␉␉␉␉␉␉␊ |
538 | ␉␉␉␉␉case BOOT_IGNORECACHE:␊ |
539 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
540 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
541 | ␉␉␉␉␉␉addBootArg(kIgnoreCachesFlag);␊ |
542 | ␉␉␉␉␉␉break;␊ |
543 | ␉␉␉␉␉␉␊ |
544 | ␉␉␉␉␉case BOOT_SINGLEUSER:␊ |
545 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
546 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
547 | ␉␉␉␉␉␉addBootArg(kSingleUserModeFlag);␊ |
548 | ␉␉␉␉␉␉break;␊ |
549 | ␉␉␉␉}␊ |
550 | ␉␉␉␉␊ |
551 | ␉␉␉}␊ |
552 | ␉␉␉␊ |
553 | ␉␉}␉␊ |
554 | ␉␉␉␊ |
555 | ␉} else {␊ |
556 | ␉␉switch ( key )␊ |
557 | ␉␉{␊ |
558 | ␉case 0x4800: // Up Arrow␊ |
559 | ␉␉␉␉if ( gMenuSelection != gMenuTop )␊ |
560 | ␉␉␉␉␉draw.f.selectionUp = 1;␊ |
561 | ␉␉␉␉else if ( gMenuTop > 0 )␊ |
562 | ␉␉␉␉␉draw.f.scrollDown = 1;␊ |
563 | ␉␉␉␉break;␊ |
564 | ␊ |
565 | ␉␉␉case 0x5000: // Down Arrow␊ |
566 | ␉␉␉␉if ( gMenuSelection != gMenuBottom )␊ |
567 | ␉␉␉␉␉draw.f.selectionDown = 1;␊ |
568 | ␉␉␉␉else if ( gMenuBottom < (gMenuItemCount - 1) ) ␊ |
569 | ␉␉␉␉␉draw.f.scrollUp = 1;␊ |
570 | ␉␉␉␉break;␊ |
571 | ␉␉}␊ |
572 | ␉}␊ |
573 | ␊ |
574 | if ( draw.w )␊ |
575 | {␊ |
576 | if ( draw.f.scrollUp )␊ |
577 | {␊ |
578 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, 1);␊ |
579 | gMenuTop++; gMenuBottom++;␊ |
580 | ␉␉␉gMenuStart++; gMenuEnd++;␊ |
581 | draw.f.selectionDown = 1;␊ |
582 | }␊ |
583 | ␊ |
584 | if ( draw.f.scrollDown )␊ |
585 | {␊ |
586 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, -1);␊ |
587 | gMenuTop--; gMenuBottom--;␊ |
588 | gMenuStart--; gMenuEnd--;␊ |
589 | draw.f.selectionUp = 1;␊ |
590 | }␊ |
591 | ␊ |
592 | if ( draw.f.selectionUp || draw.f.selectionDown )␊ |
593 | {␊ |
594 | ␊ |
595 | ␉␉␉CursorState cursorState;␊ |
596 | ␊ |
597 | ␉␉␉// Set cursor at current position, and clear inverse video.␊ |
598 | ␉␊ |
599 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
600 | ␉␉␉{␊ |
601 | ␉␉␉␉changeCursor( 0, gMenuRow + gMenuSelection - gMenuTop, kCursorTypeHidden, &cursorState );␊ |
602 | ␉␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 0 );␊ |
603 | ␉␉␉}␊ |
604 | ␊ |
605 | ␉␉␉if ( draw.f.selectionUp )␊ |
606 | ␉␉␉{␊ |
607 | ␉␉␉␉gMenuSelection--;␊ |
608 | ␉␉␉␉if(( gMenuSelection - gMenuStart) == -1 )␊ |
609 | ␉␉␉␉{␊ |
610 | ␉␉␉␉␉gMenuStart--;␊ |
611 | ␉␉␉␉␉gMenuEnd--;␊ |
612 | ␉␉␉␉}␊ |
613 | ␉␉␉␉␊ |
614 | ␉␉␉} else {␊ |
615 | ␉␉␉gMenuSelection++;␊ |
616 | ␉␉␉if(( gMenuSelection - ( gui.maxdevices - 1) - gMenuStart) > 0 )␊ |
617 | ␉␉␉{␊ |
618 | ␉␉␉␉gMenuStart++;␊ |
619 | ␉␉␉␉gMenuEnd++;␊ |
620 | ␉␉␉}␊ |
621 | ␉ }␊ |
622 | ␊ |
623 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
624 | ␉ {␊ |
625 | ␉␉␉moveCursor( 0, gMenuRow + gMenuSelection - gMenuTop );␊ |
626 | ␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 1 );␊ |
627 | ␉␉␉restoreCursor( &cursorState );␊ |
628 | ␊ |
629 | ␉ } else␊ |
630 | ␊ |
631 | ␉␉␉drawDeviceList (gMenuStart, gMenuEnd, gMenuSelection);␊ |
632 | ␊ |
633 | ␉}␊ |
634 | ␊ |
635 | *paramPtr = gMenuItems[gMenuSelection].param; ␊ |
636 | moved = 1;␊ |
637 | }␊ |
638 | ␊ |
639 | ␉return moved;␊ |
640 | }␊ |
641 | ␊ |
642 | //==========================================================================␊ |
643 | ␊ |
644 | static void skipblanks( const char ** cpp ) ␊ |
645 | {␊ |
646 | while ( **(cpp) == ' ' || **(cpp) == '\t' ) ++(*cpp);␊ |
647 | }␊ |
648 | ␊ |
649 | //==========================================================================␊ |
650 | ␊ |
651 | static const char * extractKernelName( char ** cpp )␊ |
652 | {␊ |
653 | char * kn = *cpp;␊ |
654 | char * cp = *cpp;␊ |
655 | char c;␊ |
656 | ␊ |
657 | // Convert char to lower case.␊ |
658 | ␊ |
659 | c = *cp | 0x20;␊ |
660 | ␊ |
661 | // Must start with a letter or a '/'.␊ |
662 | ␊ |
663 | if ( (c < 'a' || c > 'z') && ( c != '/' ) )␊ |
664 | return 0;␊ |
665 | ␊ |
666 | // Keep consuming characters until we hit a separator.␊ |
667 | ␊ |
668 | while ( *cp && (*cp != '=') && (*cp != ' ') && (*cp != '\t') )␊ |
669 | cp++;␊ |
670 | ␊ |
671 | // Only SPACE or TAB separator is accepted.␊ |
672 | // Reject everything else.␊ |
673 | ␊ |
674 | if (*cp == '=')␊ |
675 | return 0;␊ |
676 | ␊ |
677 | // Overwrite the separator, and move the pointer past␊ |
678 | // the kernel name.␊ |
679 | ␊ |
680 | if (*cp != '\0') *cp++ = '\0';␊ |
681 | *cpp = cp;␊ |
682 | ␊ |
683 | return kn;␊ |
684 | }␊ |
685 | ␊ |
686 | //==========================================================================␊ |
687 | ␊ |
688 | static void printMemoryInfo(void)␊ |
689 | {␊ |
690 | int line;␊ |
691 | int i;␊ |
692 | MemoryRange *mp = bootInfo->memoryMap;␊ |
693 | ␊ |
694 | // Activate and clear page 1␊ |
695 | setActiveDisplayPage(1);␊ |
696 | clearScreenRows(0, 24);␊ |
697 | setCursorPosition( 0, 0, 1 );␊ |
698 | ␊ |
699 | printf("BIOS reported memory ranges:\n");␊ |
700 | line = 1;␊ |
701 | for (i=0; i<bootInfo->memoryMapCount; i++) {␊ |
702 | printf("Base 0x%08x%08x, ",␊ |
703 | (unsigned long)(mp->base >> 32),␊ |
704 | (unsigned long)(mp->base));␊ |
705 | printf("length 0x%08x%08x, type %d\n",␊ |
706 | (unsigned long)(mp->length >> 32),␊ |
707 | (unsigned long)(mp->length),␊ |
708 | mp->type);␊ |
709 | if (line++ > 20) {␊ |
710 | pause("");␊ |
711 | line = 0;␊ |
712 | }␊ |
713 | mp++;␊ |
714 | }␊ |
715 | if (line > 0) {␊ |
716 | pause("");␊ |
717 | }␊ |
718 | ␊ |
719 | setActiveDisplayPage(0);␊ |
720 | }␊ |
721 | ␊ |
722 | char *getMemoryInfoString()␊ |
723 | {␊ |
724 | ␉int i, bufflen;␊ |
725 | ␉MemoryRange *mp = bootInfo->memoryMap;␊ |
726 | ␉char *buff = malloc(sizeof(char)*1024);␊ |
727 | ␉if(!buff) {␊ |
728 | ␉␉return 0;␊ |
729 | ␉}␊ |
730 | ␊ |
731 | ␉static const char info[] = "BIOS reported memory ranges:\n";␊ |
732 | ␉bufflen = sprintf(buff, "%s", info);␊ |
733 | ␊ |
734 | ␉for (i = 0;␊ |
735 | ␉␉(i < bootInfo->memoryMapCount) && (bufflen < 1024); /* prevent buffer overflow */␊ |
736 | ␉␉i++) {␊ |
737 | ␉␉bufflen += snprintf(buff+bufflen, 1024-bufflen, "Base 0x%08x%08x, ",␊ |
738 | (unsigned long)(mp->base >> 32),␊ |
739 | (unsigned long)(mp->base));␊ |
740 | ␉␉bufflen += snprintf(buff+bufflen, 1024-bufflen, "length 0x%08x%08x, type %d\n",␊ |
741 | (unsigned long)(mp->length >> 32),␊ |
742 | (unsigned long)(mp->length),␊ |
743 | mp->type);␊ |
744 | ␉␉mp++;␊ |
745 | ␉}␊ |
746 | ␉return buff;␊ |
747 | }␊ |
748 | ␊ |
749 | //==========================================================================␊ |
750 | ␊ |
751 | void lspci(void)␊ |
752 | {␊ |
753 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) { ␊ |
754 | ␉␉setActiveDisplayPage(1);␊ |
755 | ␉␉clearScreenRows(0, 24);␊ |
756 | ␉␉setCursorPosition(0, 0, 1);␊ |
757 | ␉}␊ |
758 | ␊ |
759 | ␉dump_pci_dt(root_pci_dev->children);␊ |
760 | ␊ |
761 | ␉pause("\n[dump lspci] ");␊ |
762 | ␊ |
763 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
764 | ␉␉setActiveDisplayPage(0);␊ |
765 | ␉}␊ |
766 | }␊ |
767 | ␊ |
768 | //==========================================================================␊ |
769 | ␊ |
770 | int getBootOptions(bool firstRun)␊ |
771 | {␊ |
772 | ␉int i;␊ |
773 | ␉int key;␊ |
774 | ␉int nextRow;␊ |
775 | ␉int timeout;␊ |
776 | ␉int bvCount;␊ |
777 | ␉BVRef bvr;␊ |
778 | ␉BVRef menuBVR;␊ |
779 | ␉bool showPrompt, newShowPrompt, isCDROM;␊ |
780 | ␊ |
781 | ␉// Initialize default menu selection entry.␊ |
782 | ␉gBootVolume = menuBVR = selectBootVolume(bvChain);␊ |
783 | ␊ |
784 | ␉if (biosDevIsCDROM(gBIOSDev)) {␊ |
785 | ␉␉isCDROM = true;␊ |
786 | ␉} else {␊ |
787 | ␉␉isCDROM = false;␊ |
788 | ␉}␊ |
789 | ␊ |
790 | ␉// ensure we're in graphics mode if gui is setup␊ |
791 | ␉if (firstRun && gui.initialised && bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
792 | ␉{␊ |
793 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
794 | ␉}␊ |
795 | ␊ |
796 | ␉// Clear command line boot arguments␊ |
797 | ␉clearBootArgs();␊ |
798 | ␊ |
799 | ␉// Allow user to override default timeout.␊ |
800 | ␉if (multiboot_timeout_set) {␊ |
801 | ␉␉timeout = multiboot_timeout;␊ |
802 | ␉} else if (!getIntForKey(kTimeoutKey, &timeout, &bootInfo->chameleonConfig)) {␊ |
803 | ␉␉/* If there is no timeout key in the file use the default timeout␊ |
804 | ␉␉ which is different for CDs vs. hard disks. However, if not booting␊ |
805 | ␉␉ a CD and no config file could be loaded set the timeout␊ |
806 | ␉␉ to zero which causes the menu to display immediately.␊ |
807 | ␉␉ This way, if no partitions can be found, that is the disk is unpartitioned␊ |
808 | ␉␉ or simply cannot be read) then an empty menu is displayed.␊ |
809 | ␉␉ If some partitions are found, for example a Windows partition, then␊ |
810 | ␉␉ these will be displayed in the menu as foreign partitions.␊ |
811 | ␉␉ */␊ |
812 | ␉␉if (isCDROM) {␊ |
813 | ␉␉␉timeout = kCDBootTimeout;␊ |
814 | ␉␉} else {␊ |
815 | ␉␉␉timeout = sysConfigValid ? kBootTimeout : 0;␊ |
816 | ␉␉}␊ |
817 | ␉}␊ |
818 | ␊ |
819 | ␉if (timeout < 0) {␊ |
820 | ␉␉gBootMode |= kBootModeQuiet;␊ |
821 | ␉}␊ |
822 | ␊ |
823 | ␉// If the user is holding down a modifier key, enter safe mode.␊ |
824 | ␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
825 | ␉␉gBootMode |= kBootModeSafe;␊ |
826 | ␉}␊ |
827 | ␊ |
828 | ␉// Checking user pressed keys␊ |
829 | ␉bool f8press = false, spress = false, vpress = false;␊ |
830 | ␉while (readKeyboardStatus()) {␊ |
831 | ␉␉key = bgetc ();␊ |
832 | ␉␉if (key == 0x4200) f8press = true;␊ |
833 | ␉␉if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true;␊ |
834 | ␉␉if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true;␊ |
835 | ␉}␊ |
836 | ␉// If user typed F8, abort quiet mode, and display the menu.␊ |
837 | ␉if (f8press) {␊ |
838 | ␉␉gBootMode &= ~kBootModeQuiet;␊ |
839 | ␉␉timeout = 0;␊ |
840 | ␉}␊ |
841 | ␉// If user typed 'v' or 'V', boot in verbose mode.␊ |
842 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && vpress) {␊ |
843 | ␉␉addBootArg(kVerboseModeFlag);␊ |
844 | ␉}␊ |
845 | ␉// If user typed 's' or 'S', boot in single user mode.␊ |
846 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && spress) {␊ |
847 | ␉␉addBootArg(kSingleUserModeFlag);␊ |
848 | ␉}␊ |
849 | ␊ |
850 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
851 | ␉␉setCursorPosition(0, 0, 0);␊ |
852 | ␉␉clearScreenRows(0, kScreenLastRow);␊ |
853 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
854 | ␉␉␉// Display banner and show hardware info.␊ |
855 | ␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
856 | ␉␉␉printf(getVBEInfoString());␊ |
857 | ␉␉}␊ |
858 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
859 | ␉␉verbose("Scanning device %x...", gBIOSDev);␊ |
860 | ␉}␊ |
861 | ␊ |
862 | ␉// When booting from CD, default to hard drive boot when possible. ␊ |
863 | ␉if (isCDROM && firstRun) {␊ |
864 | ␉␉const char *val;␊ |
865 | ␉␉char *prompt = NULL;␊ |
866 | ␉␉char *name = NULL;␊ |
867 | ␉␉int cnt;␊ |
868 | ␉␉int optionKey;␊ |
869 | ␊ |
870 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->chameleonConfig)) {␊ |
871 | ␉␉␉prompt = malloc(cnt + 1);␊ |
872 | ␉␉␉strncat(prompt, val, cnt);␊ |
873 | ␉␉} else {␊ |
874 | ␉␉␉name = malloc(80);␊ |
875 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 79, false);␊ |
876 | ␉␉␉prompt = malloc(256);␊ |
877 | ␉␉␉sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);␊ |
878 | ␉␉␉free(name);␊ |
879 | ␉␉}␊ |
880 | ␊ |
881 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->chameleonConfig )) {␊ |
882 | ␉␉␉// The key specified is a special key.␊ |
883 | ␉␉} else {␊ |
884 | ␉␉␉// Default to F8.␊ |
885 | ␉␉␉optionKey = 0x4200;␊ |
886 | ␉␉}␊ |
887 | ␊ |
888 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
889 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
890 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
891 | ␉␉if (timeout != 0) {␊ |
892 | ␉␉␉key = countdown(prompt, kMenuTopRow, timeout);␊ |
893 | ␉␉} else {␊ |
894 | ␉␉␉key = optionKey;␊ |
895 | ␉␉}␊ |
896 | ␊ |
897 | ␉␉if (prompt != NULL) {␊ |
898 | ␉␉␉free(prompt);␊ |
899 | ␉␉}␊ |
900 | ␊ |
901 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
902 | ␊ |
903 | ␉␉// Hit the option key ?␊ |
904 | ␉␉if (key == optionKey) {␊ |
905 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
906 | ␉␉␉timeout = 0;␊ |
907 | ␉␉} else {␊ |
908 | ␉␉␉key = key & 0xFF;␊ |
909 | ␊ |
910 | ␉␉␉// Try booting hard disk if user pressed 'h'␊ |
911 | ␉␉␉if (biosDevIsCDROM(gBIOSDev) && key == 'h') {␊ |
912 | ␉␉␉␉BVRef bvr;␊ |
913 | ␊ |
914 | ␉␉␉␉// Look at partitions hosting OS X other than the CD-ROM␊ |
915 | ␉␉␉␉for (bvr = bvChain; bvr; bvr=bvr->next) {␊ |
916 | ␉␉␉␉␉if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) {␊ |
917 | ␉␉␉␉␉␉gBootVolume = bvr;␊ |
918 | ␉␉␉␉␉}␊ |
919 | ␉␉␉␉}␊ |
920 | ␉␉␉}␊ |
921 | ␉␉␉goto done;␊ |
922 | ␉␉}␊ |
923 | ␉}␊ |
924 | ␊ |
925 | ␉if (gBootMode & kBootModeQuiet) {␊ |
926 | ␉␉// No input allowed from user.␊ |
927 | ␉␉goto done;␊ |
928 | ␉}␊ |
929 | ␊ |
930 | ␉if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) {␊ |
931 | ␉␉// If the user is holding down a modifier key,␊ |
932 | ␉␉// enter safe mode.␊ |
933 | ␉␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
934 | ␉␉␉gBootMode |= kBootModeSafe;␊ |
935 | ␉␉}␊ |
936 | ␉␉goto done;␊ |
937 | ␉}␊ |
938 | ␊ |
939 | ␉if (gDeviceCount > 0) {␊ |
940 | ␉␉// Allocate memory for an array of menu items.␊ |
941 | ␉␉menuItems = malloc(sizeof(MenuItem) * gDeviceCount);␊ |
942 | ␉␉if (menuItems == NULL) {␊ |
943 | ␉␉␉goto done;␊ |
944 | ␉␉}␊ |
945 | ␊ |
946 | ␉␉// Associate a menu item for each BVRef.␊ |
947 | ␉␉for (bvr=bvChain, i=gDeviceCount-1, selectIndex=-1; bvr; bvr=bvr->next) {␊ |
948 | ␉␉␉if (bvr->visible) {␊ |
949 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true);␊ |
950 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
951 | ␉␉␉␉if (bvr == menuBVR) {␊ |
952 | ␉␉␉␉␉selectIndex = i;␊ |
953 | ␉␉␉␉}␊ |
954 | ␉␉␉␉i--;␊ |
955 | ␉␉␉}␊ |
956 | ␉␉}␊ |
957 | ␉␉// Jief : In case the default partition (returned by selectBootVolume) is not in the menu␊ |
958 | ␉␉if ( selectIndex == -1 )␊ |
959 | ␉␉{␊ |
960 | ␉␉␉selectIndex = 0;␊ |
961 | ␊ |
962 | ␉␉␉// gDeviceCount is actually > 0, so menuItems[selectIndex] exists␊ |
963 | ␉␉␉menuBVR = (BVRef)(menuItems[selectIndex].param);␊ |
964 | ␉␉␉// what happen if bvChain is empty ?␊ |
965 | ␉␉}␊ |
966 | ␉}␊ |
967 | ␊ |
968 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
969 | ␉␉// redraw the background buffer␊ |
970 | ␉␉gui.logo.draw = true;␊ |
971 | ␉␉drawBackground();␊ |
972 | ␉␉gui.devicelist.draw = true;␊ |
973 | ␉␉gui.redraw = true;␊ |
974 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
975 | ␊ |
976 | ␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
977 | ␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->chameleonConfig); ␊ |
978 | ␉␉␉if (showBootBanner) {␊ |
979 | ␉␉␉␉// Display banner and show hardware info.␊ |
980 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
981 | ␉␉␉}␊ |
982 | ␊ |
983 | ␉␉␉// redraw background␊ |
984 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
985 | ␉␉}␊ |
986 | ␉} else {␊ |
987 | ␉␉// Clear screen and hide the blinking cursor.␊ |
988 | ␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
989 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
990 | ␉}␊ |
991 | ␊ |
992 | ␉nextRow = kMenuTopRow;␊ |
993 | ␉showPrompt = true;␊ |
994 | ␊ |
995 | ␉if (gDeviceCount) {␊ |
996 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
997 | ␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
998 | ␉␉}␊ |
999 | ␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
1000 | ␉␉nextRow += MIN( gDeviceCount, kMenuMaxItems ) + 3;␊ |
1001 | ␉}␊ |
1002 | ␊ |
1003 | ␉// Show the boot prompt.␊ |
1004 | ␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1005 | ␉showBootPrompt( nextRow, showPrompt );␊ |
1006 | ␉␊ |
1007 | ␉do {␊ |
1008 | ␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1009 | ␉␉␉// redraw background␊ |
1010 | ␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1011 | ␉␉␉// reset cursor co-ords␊ |
1012 | ␉␉␉gui.debug.cursor = pos( gui.screen.width - 160 , 10 );␊ |
1013 | ␉␉}␊ |
1014 | ␉␉key = getchar();␊ |
1015 | ␉␉updateMenu( key, (void **) &menuBVR );␊ |
1016 | ␉␉newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1017 | ␊ |
1018 | ␉␉if (newShowPrompt != showPrompt) {␊ |
1019 | ␉␉␉showPrompt = newShowPrompt;␊ |
1020 | ␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
1021 | ␉␉}␊ |
1022 | ␊ |
1023 | ␉␉if (showPrompt) {␊ |
1024 | ␉␉␉updateBootArgs(key);␊ |
1025 | ␉␉}␊ |
1026 | ␊ |
1027 | ␉␉switch (key) {␊ |
1028 | ␉␉case KEY_ENTER:␊ |
1029 | ␉␉␉if (gui.menu.draw) { ␊ |
1030 | ␉␉␉␉key=0;␊ |
1031 | ␉␉␉␉break;␊ |
1032 | ␉␉␉}␊ |
1033 | ␉␉␉if (*gBootArgs == '?') {␊ |
1034 | ␉␉␉␉char * argPtr = gBootArgs;␊ |
1035 | ␊ |
1036 | ␉␉␉␉// Skip the leading "?" character.␊ |
1037 | ␉␉␉␉argPtr++;␊ |
1038 | ␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
1039 | ␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
1040 | ␊ |
1041 | ␉␉␉␉/*␊ |
1042 | ␉␉␉␉* TODO: this needs to be refactored.␊ |
1043 | ␉␉␉␉*/␊ |
1044 | ␉␉␉␉if (strcmp( booterCommand, "video" ) == 0) {␊ |
1045 | ␉␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1046 | ␉␉␉␉␉␉showInfoBox(getVBEInfoString(), getVBEModeInfoString());␊ |
1047 | ␉␉␉␉␉} else {␊ |
1048 | ␉␉␉␉␉␉printVBEModeInfo();␊ |
1049 | ␉␉␉␉␉}␊ |
1050 | ␉␉␉␉} else if ( strcmp( booterCommand, "memory" ) == 0) {␊ |
1051 | ␉␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE ) {␊ |
1052 | ␉␉␉␉␉␉showInfoBox("Memory Map", getMemoryInfoString());␊ |
1053 | ␉␉␉␉␉} else {␊ |
1054 | ␉␉␉␉␉␉printMemoryInfo();␊ |
1055 | ␉␉␉␉␉}␊ |
1056 | ␉␉␉␉} else if (strcmp(booterCommand, "lspci") == 0) {␊ |
1057 | ␉␉␉␉␉lspci();␊ |
1058 | ␉␉␉␉} else if (strcmp(booterCommand, "log") == 0) {␊ |
1059 | ␉␉␉ showTextBuffer(msgbuf, strlen(msgbuf));␊ |
1060 | ␉␉␉␉} else if (strcmp(booterCommand, "more") == 0) {␊ |
1061 | ␉␉␉␉␉showTextFile(booterParam);␊ |
1062 | ␉␉␉␉} else if (strcmp(booterCommand, "rd") == 0) {␊ |
1063 | ␉␉␉␉␉processRAMDiskCommand(&argPtr, booterParam);␊ |
1064 | ␉␉␉␉} else if (strcmp(booterCommand, "norescan") == 0) {␊ |
1065 | ␉␉␉␉␉if (gEnableCDROMRescan) {␊ |
1066 | ␉␉␉␉␉␉gEnableCDROMRescan = false;␊ |
1067 | ␉␉␉␉␉␉break;␊ |
1068 | ␉␉␉␉␉}␊ |
1069 | ␉␉␉␉} else {␊ |
1070 | ␉␉␉␉␉showHelp();␊ |
1071 | ␉␉␉␉}␊ |
1072 | ␉␉␉␉key = 0;␊ |
1073 | ␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1074 | ␉␉␉␉break;␊ |
1075 | ␉␉␉}␊ |
1076 | ␉␉␉gBootVolume = menuBVR;␊ |
1077 | ␉␉␉setRootVolume(menuBVR);␊ |
1078 | ␉␉␉gBIOSDev = menuBVR->biosdev;␊ |
1079 | ␉␉␉break;␊ |
1080 | ␊ |
1081 | ␉␉case KEY_ESC:␊ |
1082 | ␉␉␉clearBootArgs();␊ |
1083 | ␉␉␉break;␊ |
1084 | ␊ |
1085 | ␉␉case KEY_F5:␊ |
1086 | ␉␉␉// New behavior:␊ |
1087 | ␉␉␉// Clear gBootVolume to restart the loop␊ |
1088 | ␉␉␉// if the user enabled rescanning the optical drive.␊ |
1089 | ␉␉␉// Otherwise boot the default boot volume.␊ |
1090 | ␉␉␉if (gEnableCDROMRescan) {␊ |
1091 | ␉␉␉␉gBootVolume = NULL;␊ |
1092 | ␉␉␉␉clearBootArgs();␊ |
1093 | ␉␉␉}␊ |
1094 | ␉␉␉break;␊ |
1095 | ␊ |
1096 | ␉␉case KEY_F10:␊ |
1097 | ␉␉␉gScanSingleDrive = false;␊ |
1098 | ␉␉␉scanDisks(gBIOSDev, &bvCount);␊ |
1099 | ␉␉␉gBootVolume = NULL;␊ |
1100 | ␉␉␉clearBootArgs();␊ |
1101 | ␉␉␉break;␊ |
1102 | ␊ |
1103 | ␉␉case KEY_TAB:␊ |
1104 | ␉␉␉// New behavior:␊ |
1105 | ␉␉␉// Switch between text & graphic interfaces␊ |
1106 | ␉␉␉// Only Permitted if started in graphics interface␊ |
1107 | ␉␉␉if (useGUI) {␊ |
1108 | ␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1109 | ␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1110 | ␊ |
1111 | ␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1112 | ␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1113 | ␊ |
1114 | ␉␉␉␉␉// Display banner and show hardware info.␊ |
1115 | ␉␉␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1116 | ␉␉␉␉␉printf(getVBEInfoString());␊ |
1117 | ␊ |
1118 | ␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
1119 | ␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
1120 | ␊ |
1121 | ␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1122 | ␉␉␉␉␉showPrompt = true;␊ |
1123 | ␊ |
1124 | ␉␉␉␉␉if (gDeviceCount) {␊ |
1125 | ␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1126 | ␉␉␉␉␉␉showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
1127 | ␉␉␉␉␉␉nextRow += MIN(gDeviceCount, kMenuMaxItems) + 3;␊ |
1128 | ␉␉␉␉␉}␊ |
1129 | ␊ |
1130 | ␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1131 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1132 | ␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
1133 | ␉␉␉␉} else {␊ |
1134 | ␉␉␉␉␉gui.redraw = true;␊ |
1135 | ␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1136 | ␉␉␉␉␉updateVRAM();␊ |
1137 | ␉␉␉updateGraphicBootPrompt();␊ |
1138 | ␉␉␉␉}␊ |
1139 | ␉␉␉}␊ |
1140 | ␉␉␉key = 0;␊ |
1141 | ␉␉␉break;␊ |
1142 | ␊ |
1143 | ␉␉default:␊ |
1144 | ␉␉␉key = 0;␊ |
1145 | ␉␉␉break;␊ |
1146 | ␉␉}␊ |
1147 | ␉} while (0 == key);␊ |
1148 | ␊ |
1149 | done:␊ |
1150 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
1151 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
1152 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
1153 | ␉}␊ |
1154 | ␉shouldboot = false;␊ |
1155 | ␉gui.menu.draw = false;␊ |
1156 | ␉if (menuItems) {␊ |
1157 | ␉␉free(menuItems);␊ |
1158 | ␉␉menuItems = NULL;␊ |
1159 | ␉}␊ |
1160 | ␉execute_hook("BootOptions", gBootArgs, gBootArgsPtr, NULL, NULL);␊ |
1161 | ␉return 0;␊ |
1162 | }␊ |
1163 | ␊ |
1164 | //==========================================================================␊ |
1165 | ␊ |
1166 | char gBootUUIDString[32+4+1] = ""; // UUID of the boot volume e.g. 5EB1869F-C4FA-3502-BDEB-3B8ED5D87292␊ |
1167 | extern unsigned char chainbootdev;␊ |
1168 | extern unsigned char chainbootflag;␊ |
1169 | ␊ |
1170 | bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)␊ |
1171 | {␊ |
1172 | ␉int argLen = argName ? strlen(argName) : 0;␊ |
1173 | ␉int len = argLen + cnt + 1; // +1 to account for space␊ |
1174 | ␊ |
1175 | ␉if (argName)␊ |
1176 | ␉{␊ |
1177 | ␉␉len++; // +1 to account for '='␊ |
1178 | ␉}␊ |
1179 | ␊ |
1180 | ␉if (len > *cntRemainingP)␊ |
1181 | ␉{␊ |
1182 | ␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1183 | ␉␉return false;␊ |
1184 | ␉}␊ |
1185 | ␊ |
1186 | ␉if (argName)␊ |
1187 | ␉{␊ |
1188 | ␉␉strncpy(*argP, argName, argLen);␊ |
1189 | ␉␉*argP += argLen;␊ |
1190 | ␉␉*argP[0] = '=';␊ |
1191 | ␉␉(*argP)++;␊ |
1192 | ␉}␊ |
1193 | ␊ |
1194 | ␉strncpy(*argP, val, cnt);␊ |
1195 | ␉*argP += cnt;␊ |
1196 | ␉*argP[0] = ' ';␊ |
1197 | ␉(*argP)++;␊ |
1198 | ␉*cntRemainingP -= len;␊ |
1199 | ␊ |
1200 | ␉return true;␊ |
1201 | }␊ |
1202 | ␊ |
1203 | // ␊ |
1204 | // Returns TRUE if an argument was copied, FALSE otherwise␊ |
1205 | bool␊ |
1206 | processBootArgument(␊ |
1207 | const char *argName, // The argument to search for␊ |
1208 | const char *userString, // Typed-in boot arguments␊ |
1209 | const char *kernelFlags, // Kernel flags from config table␊ |
1210 | const char *configTable,␊ |
1211 | char **argP, // Output value␊ |
1212 | int *cntRemainingP, // Output count␊ |
1213 | char *foundVal, // found value␊ |
1214 | int foundValSize // max found value size␊ |
1215 | ) {␊ |
1216 | ␉const char *val;␊ |
1217 | ␉int cnt;␊ |
1218 | ␉bool found = false;␊ |
1219 | ␊ |
1220 | ␉if (getValueForBootKey(userString, argName, &val, &cnt)) {␊ |
1221 | ␉␉// Don't copy; these values will be copied at the end of argument processing.␊ |
1222 | ␉␉found = true;␊ |
1223 | ␉} else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {␊ |
1224 | ␉␉// Don't copy; these values will be copied at the end of argument processing.␊ |
1225 | ␉␉found = true;␊ |
1226 | ␉} else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig)) {␊ |
1227 | ␉␉copyArgument(argName, val, cnt, argP, cntRemainingP);␊ |
1228 | ␉␉found = true;␊ |
1229 | ␉}␊ |
1230 | ␉if (found && foundVal) {␊ |
1231 | ␉␉strlcpy(foundVal, val, foundValSize);␊ |
1232 | ␉}␊ |
1233 | ␉return found;␊ |
1234 | }␊ |
1235 | ␊ |
1236 | // Maximum config table value size␊ |
1237 | #define VALUE_SIZE 2048␊ |
1238 | ␊ |
1239 | int processBootOptions()␊ |
1240 | {␊ |
1241 | ␉const char *cp = gBootArgs;␊ |
1242 | ␉const char *val = 0;␊ |
1243 | ␉const char *kernel;␊ |
1244 | ␉int cnt;␊ |
1245 | ␉int userCnt;␊ |
1246 | ␉int cntRemaining;␊ |
1247 | ␉char *argP;␊ |
1248 | ␉char *configKernelFlags;␊ |
1249 | ␉char *valueBuffer;␊ |
1250 | ␊ |
1251 | ␉valueBuffer = malloc(VALUE_SIZE);␊ |
1252 | ␊ |
1253 | ␉skipblanks( &cp );␊ |
1254 | ␊ |
1255 | ␉// Update the unit and partition number.␊ |
1256 | ␉if (gBootVolume)␊ |
1257 | ␉{␊ |
1258 | ␉␉if (!(gBootVolume->flags & kBVFlagNativeBoot))␊ |
1259 | ␉␉{␊ |
1260 | ␉␉␉readBootSector(gBootVolume->biosdev, gBootVolume->part_boff, (void *)0x7c00);␊ |
1261 | ␉␉␉//␊ |
1262 | ␉␉␉// Setup edx, and signal intention to chain load the␊ |
1263 | ␉␉␉// foreign booter.␊ |
1264 | ␉␉␉//␊ |
1265 | ␊ |
1266 | ␉␉␉chainbootdev = gBootVolume->biosdev;␊ |
1267 | ␉␉␉chainbootflag = 1;␊ |
1268 | ␊ |
1269 | ␉␉␉return 1;␊ |
1270 | ␉␉}␊ |
1271 | ␊ |
1272 | ␉␉setRootVolume(gBootVolume);␊ |
1273 | ␊ |
1274 | ␉}␊ |
1275 | ␉// If no boot volume fail immediately because we're just going to fail␊ |
1276 | ␉// trying to load the config file anyway.␊ |
1277 | ␉else␊ |
1278 | ␉{␊ |
1279 | ␉␉return -1;␊ |
1280 | ␉}␊ |
1281 | ␊ |
1282 | ␉// Save a version of mac os we're booting.␊ |
1283 | ␉MacOSVerCurrent = MacOSVer2Int(gBootVolume->OSVersion);␊ |
1284 | ␉// so copy it and trim␊ |
1285 | ␉gMacOSVersion[0] = 0;␊ |
1286 | ␉if (MacOSVerCurrent >= MacOSVer2Int("10.10"))␊ |
1287 | ␉{␊ |
1288 | ␉␉strncat(gMacOSVersion, gBootVolume->OSVersion, 5);␊ |
1289 | ␉}␊ |
1290 | ␉else␊ |
1291 | ␉{␊ |
1292 | ␉␉strncat(gMacOSVersion, gBootVolume->OSVersion, 4);␊ |
1293 | ␉}␊ |
1294 | ␊ |
1295 | ␉// Load config table specified by the user, or use the default.␊ |
1296 | ␊ |
1297 | ␉if (!getValueForBootKey(cp, "config", &val, &cnt))␊ |
1298 | ␉{␊ |
1299 | ␉␉val = 0;␊ |
1300 | ␉␉cnt = 0;␊ |
1301 | ␉}␊ |
1302 | ␊ |
1303 | ␉// Load com.apple.Boot.plist from the selected volume␊ |
1304 | ␉// and use its contents to override default bootConfig.␊ |
1305 | ␊ |
1306 | ␉loadSystemConfig(&bootInfo->bootConfig);␊ |
1307 | ␉loadChameleonConfig(&bootInfo->chameleonConfig, NULL);␊ |
1308 | ␊ |
1309 | ␉// Use the kernel name specified by the user, or fetch the name␊ |
1310 | ␉// in the config table, or use the default if not specified.␊ |
1311 | ␉// Specifying a kernel name on the command line, or specifying␊ |
1312 | ␉// a non-default kernel name in the config file counts as␊ |
1313 | ␉// overriding the kernel, which causes the kernelcache not␊ |
1314 | ␉// to be used.␊ |
1315 | ␊ |
1316 | ␉gOverrideKernel = false;␊ |
1317 | ␉if (( kernel = extractKernelName((char **)&cp) ))␊ |
1318 | ␉{␊ |
1319 | ␉␉strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );␊ |
1320 | ␉}␊ |
1321 | ␉else␊ |
1322 | ␉{␊ |
1323 | ␉␉if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) )␊ |
1324 | ␉␉{␊ |
1325 | ␉␉␉strlcpy( bootInfo->bootFile, val, cnt+1 );␊ |
1326 | ␉␉}␊ |
1327 | ␉␉else␊ |
1328 | ␉␉{␊ |
1329 | ␉␉␉if (MacOSVerCurrent >= MacOSVer2Int("10.10")) { // OS X is 10.10 or newer␊ |
1330 | ␉␉␉␉strlcpy( bootInfo->bootFile, kYosemiteKernel, sizeof(bootInfo->bootFile) );␊ |
1331 | ␉␉␉}␊ |
1332 | ␉␉␉else␊ |
1333 | ␉␉␉{␊ |
1334 | ␉␉␉␉// or 10.9 and previous␊ |
1335 | ␉␉␉␉strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );␊ |
1336 | ␉␉␉}␊ |
1337 | ␉␉}␊ |
1338 | ␉}␊ |
1339 | ␊ |
1340 | ␉if ((strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) && (strcmp( bootInfo->bootFile, kYosemiteKernel ) != 0))␊ |
1341 | ␉{␊ |
1342 | ␉␉gOverrideKernel = true;␊ |
1343 | ␉}␊ |
1344 | ␊ |
1345 | ␉cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space␊ |
1346 | ␉argP = bootArgs->CommandLine;␊ |
1347 | ␊ |
1348 | ␉// Get config kernel flags, if not ignored.␊ |
1349 | ␉if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || !getValueForKey(kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig))␊ |
1350 | ␉{␊ |
1351 | ␉␉val = "";␊ |
1352 | ␉␉cnt = 0;␊ |
1353 | ␉}␊ |
1354 | ␉configKernelFlags = malloc(cnt + 1);␊ |
1355 | ␉strlcpy(configKernelFlags, val, cnt + 1);␊ |
1356 | ␊ |
1357 | ␉// boot-uuid can be set either on the command-line or in the config file␊ |
1358 | ␉if (!processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config,␊ |
1359 | &argP, &cntRemaining, gBootUUIDString, sizeof(gBootUUIDString)))␊ |
1360 | ␉{␊ |
1361 | ␉␉//␊ |
1362 | ␉␉// Try an alternate method for getting the root UUID on boot helper partitions.␊ |
1363 | ␉␉//␊ |
1364 | ␉␉if (gBootVolume->flags & kBVFlagBooter)␊ |
1365 | ␉␉{␊ |
1366 | ␉␉␉// Load the configuration store in the boot helper partition␊ |
1367 | ␉␉␉if (loadHelperConfig(&bootInfo->helperConfig) == 0)␊ |
1368 | ␉␉␉{␊ |
1369 | ␉␉␉␉val = getStringForKey(kHelperRootUUIDKey, &bootInfo->helperConfig);␊ |
1370 | ␉␉␉␉if (val != NULL)␊ |
1371 | ␉␉␉␉{␊ |
1372 | ␉␉␉␉␉strlcpy(gBootUUIDString, val, sizeof(gBootUUIDString));␊ |
1373 | ␉␉␉␉}␊ |
1374 | ␉␉␉}␊ |
1375 | ␉␉}␊ |
1376 | /* Bungo␊ |
1377 | ␉␉// Try to get the volume uuid string␊ |
1378 | ␉␉if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid)␊ |
1379 | ␉␉{␊ |
1380 | ␉␉␉gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString);␊ |
1381 | ␉␉}␊ |
1382 | */␊ |
1383 | ␉␉// If we have the volume uuid add it to the commandline arguments␊ |
1384 | ␉␉if (strlen(gBootUUIDString))␊ |
1385 | ␉␉{␊ |
1386 | ␉␉␉copyArgument(kBootUUIDKey, gBootUUIDString, strlen(gBootUUIDString), &argP, &cntRemaining);␊ |
1387 | ␉␉}␊ |
1388 | ␉␉// Try to get the volume uuid string␊ |
1389 | ␉␉if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid)␊ |
1390 | ␉␉{␊ |
1391 | ␉␉␉gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString);␊ |
1392 | ␉␉}␊ |
1393 | ␉}␊ |
1394 | ␉verbose("Boot UUID [%s (%s), %s]: %s\n", gBootVolume->label, gBootVolume->altlabel, gBootVolume->type_name, gBootUUIDString);␊ |
1395 | ␊ |
1396 | ␉if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config,␊ |
1397 | &argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE))␊ |
1398 | ␉{␊ |
1399 | ␉␉cnt = 0;␊ |
1400 | ␉␉if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig))␊ |
1401 | ␉␉{␊ |
1402 | ␉␉␉valueBuffer[0] = '*';␊ |
1403 | ␉␉␉cnt++;␊ |
1404 | ␉␉␉strlcpy(valueBuffer + 1, val, cnt);␊ |
1405 | ␉␉␉val = valueBuffer;␊ |
1406 | ␉␉␉if (cnt > 0)␊ |
1407 | ␉␉␉{␊ |
1408 | ␉␉␉␉copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);␊ |
1409 | ␉␉␉}␊ |
1410 | ␉␉}␊ |
1411 | ␉␉else␊ |
1412 | ␉␉{␊ |
1413 | ␉␉␉if (strlen(gBootUUIDString))␊ |
1414 | ␉␉␉{␊ |
1415 | ␉␉␉␉val = "*uuid";␊ |
1416 | ␉␉␉␉cnt = 5;␊ |
1417 | ␉␉␉}␊ |
1418 | ␉␉␉else␊ |
1419 | ␉␉␉{␊ |
1420 | ␉␉␉␉// Don't set "rd=.." if there is no boot device key␊ |
1421 | ␉␉␉␉// and no UUID.␊ |
1422 | ␉␉␉␉val = "";␊ |
1423 | ␉␉␉␉cnt = 0;␊ |
1424 | ␉␉␉}␊ |
1425 | ␉␉}␊ |
1426 | /* Bungo␊ |
1427 | ␉␉if (cnt > 0)␊ |
1428 | ␉␉{␊ |
1429 | ␉␉␉copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);␊ |
1430 | ␉␉}␊ |
1431 | */␊ |
1432 | ␉␉strlcpy(gRootDevice, val, (cnt + 1));␊ |
1433 | ␉}␊ |
1434 | ␊ |
1435 | ␉/*␊ |
1436 | ␉ * Removed. We don't need this anymore.␊ |
1437 | ␉ *␊ |
1438 | ␉if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config,␊ |
1439 | ␉␉␉␉␉␉␉ &argP, &cntRemaining, gPlatformName, sizeof(gCacheNameAdler)))␊ |
1440 | ␉{␊ |
1441 | ␉␉getPlatformName(gPlatformName);␊ |
1442 | ␉␉copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);␊ |
1443 | ␉}␊ |
1444 | ␉*/␊ |
1445 | ␊ |
1446 | ␉if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&␊ |
1447 | !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt))␊ |
1448 | ␉{␊ |
1449 | ␉␉if (gBootMode & kBootModeSafe)␊ |
1450 | ␉␉{␊ |
1451 | ␉␉␉copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);␊ |
1452 | ␉␉}␊ |
1453 | ␉}␊ |
1454 | ␊ |
1455 | ␉// Store the merged kernel flags and boot args.␊ |
1456 | ␊ |
1457 | ␉cnt = strlen(configKernelFlags);␊ |
1458 | ␉if (cnt)␊ |
1459 | ␉{␊ |
1460 | ␉␉if (cnt > cntRemaining)␊ |
1461 | ␉␉{␊ |
1462 | ␉␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1463 | ␉␉␉cnt = cntRemaining;␊ |
1464 | ␉␉}␊ |
1465 | ␉␉strncpy(argP, configKernelFlags, cnt);␊ |
1466 | ␉␉argP[cnt++] = ' ';␊ |
1467 | ␉␉cntRemaining -= cnt;␊ |
1468 | ␉}␊ |
1469 | ␉userCnt = strlen(cp);␊ |
1470 | ␉if (userCnt > cntRemaining)␊ |
1471 | ␉{␊ |
1472 | ␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1473 | ␉␉userCnt = cntRemaining;␊ |
1474 | ␉}␊ |
1475 | ␉strncpy(&argP[cnt], cp, userCnt);␊ |
1476 | ␉argP[cnt+userCnt] = '\0';␊ |
1477 | ␊ |
1478 | ␉if(!shouldboot)␊ |
1479 | ␉{␊ |
1480 | ␉␉gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ||␊ |
1481 | ␉␉␉getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->chameleonConfig );␊ |
1482 | ␉␉␊ |
1483 | ␉␉gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) ?␊ |
1484 | ␉␉␉kBootModeSafe : kBootModeNormal;␊ |
1485 | ␊ |
1486 | ␉␉if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) )␊ |
1487 | ␉␉{␊ |
1488 | ␉␉␉gBootMode = kBootModeSafe;␊ |
1489 | ␉␉}␊ |
1490 | ␉}␊ |
1491 | ␊ |
1492 | ␉if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )␊ |
1493 | ␉{␊ |
1494 | ␉␉strlcpy(gMKextName, val, cnt + 1);␊ |
1495 | ␉}␊ |
1496 | ␉else␊ |
1497 | ␉{␊ |
1498 | ␉␉gMKextName[0]=0;␊ |
1499 | ␉}␊ |
1500 | ␊ |
1501 | ␉free(configKernelFlags);␊ |
1502 | ␉free(valueBuffer);␊ |
1503 | ␊ |
1504 | ␉return 0;␊ |
1505 | }␊ |
1506 | ␊ |
1507 | ␊ |
1508 | //==========================================================================␊ |
1509 | // Load the help file and display the file contents on the screen.␊ |
1510 | ␊ |
1511 | void showTextBuffer(char *buf_orig, int size)␊ |
1512 | {␊ |
1513 | ␉char␉*bp;␊ |
1514 | ␉char* buf;␊ |
1515 | ␉int␉line;␊ |
1516 | ␉int␉line_offset;␊ |
1517 | ␉int␉c;␊ |
1518 | ␊ |
1519 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1520 | ␉␉showInfoBox( "Press q to continue, space for next page.\n",buf_orig );␊ |
1521 | ␉␉return;␊ |
1522 | ␉}␊ |
1523 | ␊ |
1524 | ␉// Create a copy so that we don't mangle the original␊ |
1525 | ␉buf = malloc(size + 1);␊ |
1526 | ␉memcpy(buf, buf_orig, size);␊ |
1527 | ␉␊ |
1528 | ␊ |
1529 | bp = buf;␊ |
1530 | while (size-- > 0) {␊ |
1531 | ␉␉if (*bp == '\n') {␊ |
1532 | ␉␉␉*bp = '\0';␊ |
1533 | ␉␉}␊ |
1534 | ␉␉bp++;␊ |
1535 | }␊ |
1536 | *bp = '\1';␊ |
1537 | line_offset = 0;␊ |
1538 | ␊ |
1539 | setActiveDisplayPage(1);␊ |
1540 | ␊ |
1541 | while (1) {␊ |
1542 | ␉␉clearScreenRows(0, 24);␊ |
1543 | ␉␉setCursorPosition(0, 0, 1);␊ |
1544 | ␉␉bp = buf;␊ |
1545 | ␉␉for (line = 0; *bp != '\1' && line < line_offset; line++) {␊ |
1546 | ␉␉␉while (*bp != '\0') {␊ |
1547 | ␉␉␉␉bp++;␊ |
1548 | ␉␉␉}␊ |
1549 | ␉␉␉bp++;␊ |
1550 | ␉␉}␊ |
1551 | ␉␉for (line = 0; *bp != '\1' && line < 23; line++) {␊ |
1552 | ␉␉␉setCursorPosition(0, line, 1);␊ |
1553 | ␉␉␉printf("%s\n", bp);␊ |
1554 | ␉␉␉while (*bp != '\0') {␊ |
1555 | ␉␉␉␉bp++;␊ |
1556 | ␉␉␉}␊ |
1557 | ␉␉␉bp++;␊ |
1558 | ␉␉}␊ |
1559 | ␊ |
1560 | ␉␉setCursorPosition(0, 23, 1);␊ |
1561 | ␉␉if (*bp == '\1') {␊ |
1562 | ␉␉␉printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : "");␊ |
1563 | ␉␉} else {␊ |
1564 | ␉␉␉printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : "");␊ |
1565 | ␉␉}␊ |
1566 | ␊ |
1567 | ␉␉c = getchar();␊ |
1568 | ␉␉if (c == 'q' || c == 'Q') {␊ |
1569 | ␉␉␉break;␊ |
1570 | ␉␉}␊ |
1571 | ␉␉if ((c == 'p' || c == 'P') && line_offset > 0) {␊ |
1572 | ␉␉␉line_offset -= 23;␊ |
1573 | ␉␉}␊ |
1574 | ␉␉if (c == ' ') {␊ |
1575 | ␉␉␉if (*bp == '\1') {␊ |
1576 | ␉␉␉␉break;␊ |
1577 | ␉␉␉} else {␊ |
1578 | ␉␉␉␉line_offset += 23;␊ |
1579 | ␉␉␉}␊ |
1580 | ␉␉}␊ |
1581 | }␊ |
1582 | setActiveDisplayPage(0);␊ |
1583 | }␊ |
1584 | ␊ |
1585 | void showHelp(void)␊ |
1586 | {␊ |
1587 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE)␊ |
1588 | ␉{␊ |
1589 | ␉␉showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);␊ |
1590 | ␉}␊ |
1591 | ␉else␊ |
1592 | ␉{␊ |
1593 | ␉␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1594 | ␉}␊ |
1595 | }␊ |
1596 | ␊ |
1597 | void showTextFile(const char * filename)␊ |
1598 | {␊ |
1599 | #define MAX_TEXT_FILE_SIZE 65536␊ |
1600 | ␉char␉*buf;␊ |
1601 | ␉int␉fd;␊ |
1602 | ␉int␉size;␊ |
1603 | ␊ |
1604 | ␉if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0)␊ |
1605 | ␉{␊ |
1606 | ␉␉printf("\nFile not found: %s\n", filename);␊ |
1607 | ␉␉sleep(2);␊ |
1608 | ␉␉return;␊ |
1609 | ␉}␊ |
1610 | ␊ |
1611 | size = file_size(fd);␊ |
1612 | if (size > MAX_TEXT_FILE_SIZE)␊ |
1613 | ␉{␊ |
1614 | ␉␉size = MAX_TEXT_FILE_SIZE;␊ |
1615 | ␉}␊ |
1616 | buf = malloc(size);␊ |
1617 | read(fd, buf, size);␊ |
1618 | close(fd);␊ |
1619 | ␉showTextBuffer(buf, size);␊ |
1620 | ␉free(buf);␊ |
1621 | }␊ |
1622 | ␊ |
1623 | // This is a very simplistic prompting scheme that just grabs two hex characters␊ |
1624 | // Eventually we need to do something more user-friendly like display a menu␊ |
1625 | // based off of the Multiboot device list␊ |
1626 | ␊ |
1627 | int selectAlternateBootDevice(int bootdevice)␊ |
1628 | {␊ |
1629 | ␉int key;␊ |
1630 | ␉int newbootdevice;␊ |
1631 | ␉int digitsI = 0;␊ |
1632 | ␉char *end;␊ |
1633 | ␉char digits[3] = {0,0,0};␊ |
1634 | ␊ |
1635 | ␉// We've already printed the current boot device so user knows what it is␊ |
1636 | ␉printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n");␊ |
1637 | ␉printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice);␊ |
1638 | ␉do {␊ |
1639 | ␉␉key = getchar();␊ |
1640 | ␉␉switch (ASCII_KEY(key))␊ |
1641 | ␉␉{␊ |
1642 | ␉␉case KEY_BKSP:␊ |
1643 | ␉␉␉if (digitsI > 0)␊ |
1644 | ␉␉␉{␊ |
1645 | ␉␉␉␉int x, y, t;␊ |
1646 | ␉␉␉␉getCursorPositionAndType(&x, &y, &t);␊ |
1647 | ␉␉␉␉// Assume x is not 0;␊ |
1648 | ␉␉␉␉x--;␊ |
1649 | ␉␉␉␉setCursorPosition(x,y,0); // back up one char␊ |
1650 | ␉␉␉␉// Overwrite with space without moving cursor position␊ |
1651 | ␉␉␉␉putca(' ', 0x07, 1);␊ |
1652 | ␉␉␉␉digitsI--;␊ |
1653 | ␉␉␉}␊ |
1654 | ␉␉␉else␊ |
1655 | ␉␉␉{␊ |
1656 | ␉␉␉␉// TODO: Beep or something␊ |
1657 | ␉␉␉}␊ |
1658 | ␉␉␉break;␊ |
1659 | ␊ |
1660 | ␉␉case KEY_ENTER:␊ |
1661 | ␉␉␉digits[digitsI] = '\0';␊ |
1662 | ␉␉␉newbootdevice = strtol(digits, &end, 16);␊ |
1663 | ␉␉␉if (end == digits && *end == '\0')␊ |
1664 | ␉␉␉{␊ |
1665 | ␉␉␉␉// User entered empty string␊ |
1666 | ␉␉␉␉printf("\nUsing default boot device %x\n", bootdevice);␊ |
1667 | ␉␉␉␉key = 0;␊ |
1668 | ␉␉␉} else if(end != digits && *end == '\0') {␊ |
1669 | ␉␉␉␉bootdevice = newbootdevice;␊ |
1670 | ␉␉␉␉printf("\n");␊ |
1671 | ␉␉␉␉key = 0; // We gots da boot device␊ |
1672 | ␉␉␉} else {␊ |
1673 | ␉␉␉␉printf("\nCouldn't parse. try again: ");␊ |
1674 | ␉␉␉␉digitsI = 0;␊ |
1675 | ␉␉␉}␊ |
1676 | ␉␉␉break;␊ |
1677 | ␊ |
1678 | ␉␉default:␊ |
1679 | ␉␉␉if (isxdigit(ASCII_KEY(key)) && digitsI < 2)␊ |
1680 | ␉␉␉{␊ |
1681 | ␉␉␉␉putchar(ASCII_KEY(key));␊ |
1682 | ␉␉␉␉digits[digitsI++] = ASCII_KEY(key);␊ |
1683 | ␉␉␉}␊ |
1684 | ␉␉␉else␊ |
1685 | ␉␉␉{␊ |
1686 | ␉␉␉␉// TODO: Beep or something␊ |
1687 | ␉␉␉}␊ |
1688 | ␉␉␉break;␊ |
1689 | ␉␉};␊ |
1690 | ␉} while (key != 0);␊ |
1691 | ␊ |
1692 | ␉return bootdevice;␊ |
1693 | }␊ |
1694 | ␊ |
1695 | bool promptForRescanOption(void)␊ |
1696 | {␊ |
1697 | ␉printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");␊ |
1698 | ␉if (getchar() == KEY_ENTER)␊ |
1699 | ␉{␊ |
1700 | ␉␉return true;␊ |
1701 | ␉}␊ |
1702 | ␉else␊ |
1703 | ␉{␊ |
1704 | ␉␉return false;␊ |
1705 | ␉}␊ |
1706 | }␊ |
1707 | |