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 | ␊ |
41 | char␉␉gMacOSVersion[OSVERSTRLEN];␊ |
42 | uint32_t␉MacOSVerCurrent = 0;␊ |
43 | bool␉␉showBootBanner = true; //Azi:showinfo␊ |
44 | static bool␉shouldboot = false;␊ |
45 | ␊ |
46 | extern int multiboot_timeout;␊ |
47 | extern int multiboot_timeout_set;␊ |
48 | ␊ |
49 | extern BVRef bvChain;␊ |
50 | //extern int␉␉menucount;␊ |
51 | ␊ |
52 | extern int␉␉gDeviceCount;␊ |
53 | ␊ |
54 | int␉␉␉selectIndex = 0;␊ |
55 | ␊ |
56 | MenuItem *menuItems = NULL;␊ |
57 | ␊ |
58 | enum {␊ |
59 | kMenuTopRow = 5,␊ |
60 | kMenuMaxItems = 10,␊ |
61 | kScreenLastRow = 24␊ |
62 | };␊ |
63 | ␊ |
64 | extern char *msgbuf;␊ |
65 | ␊ |
66 | void showTextBuffer(char *buf_orig, int size);␊ |
67 | ␊ |
68 | //==========================================================================␊ |
69 | ␊ |
70 | // 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 | ␉}␊ |
556 | ␉else␊ |
557 | ␉{␊ |
558 | ␉␉switch ( key )␊ |
559 | ␉␉{␊ |
560 | ␉case 0x4800: // Up Arrow␊ |
561 | ␉␉␉␉if ( gMenuSelection != gMenuTop )␊ |
562 | ␉␉␉␉␉draw.f.selectionUp = 1;␊ |
563 | ␉␉␉␉else if ( gMenuTop > 0 )␊ |
564 | ␉␉␉␉␉draw.f.scrollDown = 1;␊ |
565 | ␉␉␉␉break;␊ |
566 | ␊ |
567 | ␉␉␉case 0x5000: // Down Arrow␊ |
568 | ␉␉␉␉if ( gMenuSelection != gMenuBottom )␊ |
569 | ␉␉␉␉␉draw.f.selectionDown = 1;␊ |
570 | ␉␉␉␉else if ( gMenuBottom < (gMenuItemCount - 1) ) ␊ |
571 | ␉␉␉␉␉draw.f.scrollUp = 1;␊ |
572 | ␉␉␉␉break;␊ |
573 | ␉␉}␊ |
574 | ␉}␊ |
575 | ␊ |
576 | ␉if ( draw.w )␊ |
577 | ␉{␊ |
578 | ␉␉if ( draw.f.scrollUp )␊ |
579 | ␉␉{␊ |
580 | ␉␉␉scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, 1);␊ |
581 | ␉␉␉gMenuTop++; gMenuBottom++;␊ |
582 | ␉␉␉gMenuStart++; gMenuEnd++;␊ |
583 | ␉␉␉draw.f.selectionDown = 1;␊ |
584 | ␉␉}␊ |
585 | ␊ |
586 | ␉␉if ( draw.f.scrollDown )␊ |
587 | ␉␉{␊ |
588 | ␉␉␉scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, -1);␊ |
589 | ␉␉␉gMenuTop--; gMenuBottom--;␊ |
590 | ␉␉␉gMenuStart--; gMenuEnd--;␊ |
591 | ␉␉␉draw.f.selectionUp = 1;␊ |
592 | ␉␉}␊ |
593 | ␊ |
594 | ␉␉if ( draw.f.selectionUp || draw.f.selectionDown )␊ |
595 | ␉␉{␊ |
596 | ␉␉␉CursorState cursorState;␊ |
597 | ␊ |
598 | ␉␉␉// Set cursor at current position, and clear inverse video.␊ |
599 | ␊ |
600 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
601 | ␉␉␉{␊ |
602 | ␉␉␉␉changeCursor( 0, gMenuRow + gMenuSelection - gMenuTop, kCursorTypeHidden, &cursorState );␊ |
603 | ␉␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 0 );␊ |
604 | ␉␉␉}␊ |
605 | ␊ |
606 | ␉␉␉if ( draw.f.selectionUp )␊ |
607 | ␉␉␉{␊ |
608 | ␉␉␉␉gMenuSelection--;␊ |
609 | ␉␉␉␉if(( gMenuSelection - gMenuStart) == -1 )␊ |
610 | ␉␉␉␉{␊ |
611 | ␉␉␉␉␉gMenuStart--;␊ |
612 | ␉␉␉␉␉gMenuEnd--;␊ |
613 | ␉␉␉␉}␊ |
614 | ␊ |
615 | ␉␉␉}␊ |
616 | ␉␉␉else␊ |
617 | ␉␉␉{␊ |
618 | ␉␉␉␉gMenuSelection++;␊ |
619 | ␉␉␉␉if(( gMenuSelection - ( gui.maxdevices - 1) - gMenuStart) > 0 )␊ |
620 | ␉␉␉␉{␊ |
621 | ␉␉␉␉␉gMenuStart++;␊ |
622 | ␉␉␉␉␉gMenuEnd++;␊ |
623 | ␉␉␉␉}␊ |
624 | ␉␉␉}␊ |
625 | ␊ |
626 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
627 | ␉␉␉{␊ |
628 | ␉␉␉␉moveCursor( 0, gMenuRow + gMenuSelection - gMenuTop );␊ |
629 | ␉␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 1 );␊ |
630 | ␉␉␉␉restoreCursor( &cursorState );␊ |
631 | ␊ |
632 | ␉␉␉}␊ |
633 | ␉␉␉else␊ |
634 | ␉␉␉{␊ |
635 | ␉␉␉␉drawDeviceList (gMenuStart, gMenuEnd, gMenuSelection);␊ |
636 | ␉␉␉}␊ |
637 | ␉␉}␊ |
638 | ␊ |
639 | ␉␉*paramPtr = gMenuItems[gMenuSelection].param;␊ |
640 | ␉␉moved = 1;␊ |
641 | ␉}␊ |
642 | ␊ |
643 | ␉return moved;␊ |
644 | }␊ |
645 | ␊ |
646 | //==========================================================================␊ |
647 | ␊ |
648 | static void skipblanks( const char ** cpp ) ␊ |
649 | {␊ |
650 | while ( **(cpp) == ' ' || **(cpp) == '\t' ) ++(*cpp);␊ |
651 | }␊ |
652 | ␊ |
653 | //==========================================================================␊ |
654 | ␊ |
655 | static const char * extractKernelName( char ** cpp )␊ |
656 | {␊ |
657 | char * kn = *cpp;␊ |
658 | char * cp = *cpp;␊ |
659 | char c;␊ |
660 | ␊ |
661 | // Convert char to lower case.␊ |
662 | ␊ |
663 | c = *cp | 0x20;␊ |
664 | ␊ |
665 | // Must start with a letter or a '/'.␊ |
666 | ␊ |
667 | if ( (c < 'a' || c > 'z') && ( c != '/' ) )␊ |
668 | return 0;␊ |
669 | ␊ |
670 | // Keep consuming characters until we hit a separator.␊ |
671 | ␊ |
672 | while ( *cp && (*cp != '=') && (*cp != ' ') && (*cp != '\t') )␊ |
673 | cp++;␊ |
674 | ␊ |
675 | // Only SPACE or TAB separator is accepted.␊ |
676 | // Reject everything else.␊ |
677 | ␊ |
678 | if (*cp == '=')␊ |
679 | return 0;␊ |
680 | ␊ |
681 | // Overwrite the separator, and move the pointer past␊ |
682 | // the kernel name.␊ |
683 | ␊ |
684 | if (*cp != '\0') *cp++ = '\0';␊ |
685 | *cpp = cp;␊ |
686 | ␊ |
687 | return kn;␊ |
688 | }␊ |
689 | ␊ |
690 | //==========================================================================␊ |
691 | ␊ |
692 | static void printMemoryInfo(void)␊ |
693 | {␊ |
694 | int line;␊ |
695 | int i;␊ |
696 | MemoryRange *mp = bootInfo->memoryMap;␊ |
697 | ␊ |
698 | // Activate and clear page 1␊ |
699 | setActiveDisplayPage(1);␊ |
700 | clearScreenRows(0, 24);␊ |
701 | setCursorPosition( 0, 0, 1 );␊ |
702 | ␊ |
703 | printf("BIOS reported memory ranges:\n");␊ |
704 | line = 1;␊ |
705 | for (i=0; i<bootInfo->memoryMapCount; i++) {␊ |
706 | printf("Base 0x%08x%08x, ",␊ |
707 | (unsigned long)(mp->base >> 32),␊ |
708 | (unsigned long)(mp->base));␊ |
709 | printf("length 0x%08x%08x, type %d\n",␊ |
710 | (unsigned long)(mp->length >> 32),␊ |
711 | (unsigned long)(mp->length),␊ |
712 | mp->type);␊ |
713 | if (line++ > 20) {␊ |
714 | pause();␊ |
715 | line = 0;␊ |
716 | }␊ |
717 | mp++;␊ |
718 | }␊ |
719 | if (line > 0) {␊ |
720 | pause();␊ |
721 | }␊ |
722 | ␊ |
723 | setActiveDisplayPage(0);␊ |
724 | }␊ |
725 | ␊ |
726 | char *getMemoryInfoString()␊ |
727 | {␊ |
728 | ␉int i, bufflen;␊ |
729 | ␉MemoryRange *mp = bootInfo->memoryMap;␊ |
730 | ␉char *buff = malloc(sizeof(char)*1024);␊ |
731 | ␉if(!buff) {␊ |
732 | ␉␉return 0;␊ |
733 | ␉}␊ |
734 | ␊ |
735 | ␉static const char info[] = "BIOS reported memory ranges:\n";␊ |
736 | ␉bufflen = sprintf(buff, "%s", info);␊ |
737 | ␊ |
738 | ␉for (i = 0;␊ |
739 | ␉␉(i < bootInfo->memoryMapCount) && (bufflen < 1024); /* prevent buffer overflow */␊ |
740 | ␉␉i++) {␊ |
741 | ␉␉bufflen += snprintf(buff+bufflen, 1024-bufflen, "Base 0x%08x%08x, ",␊ |
742 | (unsigned long)(mp->base >> 32),␊ |
743 | (unsigned long)(mp->base));␊ |
744 | ␉␉bufflen += snprintf(buff+bufflen, 1024-bufflen, "length 0x%08x%08x, type %d\n",␊ |
745 | (unsigned long)(mp->length >> 32),␊ |
746 | (unsigned long)(mp->length),␊ |
747 | mp->type);␊ |
748 | ␉␉mp++;␊ |
749 | ␉}␊ |
750 | ␉return buff;␊ |
751 | }␊ |
752 | ␊ |
753 | //==========================================================================␊ |
754 | ␊ |
755 | void lspci(void)␊ |
756 | {␊ |
757 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
758 | ␉{␊ |
759 | ␉␉setActiveDisplayPage(1);␊ |
760 | ␉␉clearScreenRows(0, 24);␊ |
761 | ␉␉setCursorPosition(0, 0, 1);␊ |
762 | ␉}␊ |
763 | ␊ |
764 | ␉dump_pci_dt(root_pci_dev->children);␊ |
765 | ␊ |
766 | ␉pause();␊ |
767 | ␊ |
768 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
769 | ␉{␊ |
770 | ␉␉setActiveDisplayPage(0);␊ |
771 | ␉}␊ |
772 | }␊ |
773 | ␊ |
774 | //==========================================================================␊ |
775 | ␊ |
776 | int getBootOptions(bool firstRun)␊ |
777 | {␊ |
778 | ␉int i;␊ |
779 | ␉int key;␊ |
780 | ␉int nextRow;␊ |
781 | ␉int timeout;␊ |
782 | ␉int bvCount;␊ |
783 | ␉BVRef bvr;␊ |
784 | ␉BVRef menuBVR;␊ |
785 | ␉bool showPrompt, newShowPrompt, isCDROM;␊ |
786 | ␊ |
787 | ␉// Initialize default menu selection entry.␊ |
788 | ␉gBootVolume = menuBVR = selectBootVolume(bvChain);␊ |
789 | ␊ |
790 | ␉if (biosDevIsCDROM(gBIOSDev)) {␊ |
791 | ␉␉isCDROM = true;␊ |
792 | ␉} else {␊ |
793 | ␉␉isCDROM = false;␊ |
794 | ␉}␊ |
795 | ␊ |
796 | ␉// ensure we're in graphics mode if gui is setup␊ |
797 | ␉if (firstRun && gui.initialised && bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
798 | ␉{␊ |
799 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
800 | ␉}␊ |
801 | ␊ |
802 | ␉// Clear command line boot arguments␊ |
803 | ␉clearBootArgs();␊ |
804 | ␊ |
805 | ␉// Allow user to override default timeout.␊ |
806 | ␉if (multiboot_timeout_set) {␊ |
807 | ␉␉timeout = multiboot_timeout;␊ |
808 | ␉} else if (!getIntForKey(kTimeoutKey, &timeout, &bootInfo->chameleonConfig)) {␊ |
809 | ␉␉/* If there is no timeout key in the file use the default timeout␊ |
810 | ␉␉ which is different for CDs vs. hard disks. However, if not booting␊ |
811 | ␉␉ a CD and no config file could be loaded set the timeout␊ |
812 | ␉␉ to zero which causes the menu to display immediately.␊ |
813 | ␉␉ This way, if no partitions can be found, that is the disk is unpartitioned␊ |
814 | ␉␉ or simply cannot be read) then an empty menu is displayed.␊ |
815 | ␉␉ If some partitions are found, for example a Windows partition, then␊ |
816 | ␉␉ these will be displayed in the menu as foreign partitions.␊ |
817 | ␉␉ */␊ |
818 | ␉␉if (isCDROM) {␊ |
819 | ␉␉␉timeout = kCDBootTimeout;␊ |
820 | ␉␉} else {␊ |
821 | ␉␉␉timeout = sysConfigValid ? kBootTimeout : 0;␊ |
822 | ␉␉}␊ |
823 | ␉}␊ |
824 | ␊ |
825 | ␉if (timeout < 0) {␊ |
826 | ␉␉gBootMode |= kBootModeQuiet;␊ |
827 | ␉}␊ |
828 | ␊ |
829 | ␉// If the user is holding down a modifier key, enter safe mode.␊ |
830 | ␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
831 | ␉␉gBootMode |= kBootModeSafe;␊ |
832 | ␉}␊ |
833 | ␊ |
834 | ␉// Checking user pressed keys␊ |
835 | ␉bool f8press = false, spress = false, vpress = false;␊ |
836 | ␉while (readKeyboardStatus()) {␊ |
837 | ␉␉key = bgetc ();␊ |
838 | ␉␉if (key == 0x4200) f8press = true;␊ |
839 | ␉␉if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true;␊ |
840 | ␉␉if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true;␊ |
841 | ␉}␊ |
842 | ␉// If user typed F8, abort quiet mode, and display the menu.␊ |
843 | ␉if (f8press) {␊ |
844 | ␉␉gBootMode &= ~kBootModeQuiet;␊ |
845 | ␉␉timeout = 0;␊ |
846 | ␉}␊ |
847 | ␉// If user typed 'v' or 'V', boot in verbose mode.␊ |
848 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && vpress) {␊ |
849 | ␉␉addBootArg(kVerboseModeFlag);␊ |
850 | ␉}␊ |
851 | ␉// If user typed 's' or 'S', boot in single user mode.␊ |
852 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && spress) {␊ |
853 | ␉␉addBootArg(kSingleUserModeFlag);␊ |
854 | ␉}␊ |
855 | ␊ |
856 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
857 | ␉␉setCursorPosition(0, 0, 0);␊ |
858 | ␉␉clearScreenRows(0, kScreenLastRow);␊ |
859 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
860 | ␉␉␉// Display banner and show hardware info.␊ |
861 | ␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
862 | ␉␉␉printf(getVBEInfoString());␊ |
863 | ␉␉}␊ |
864 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
865 | ␉␉verbose("Scanning device %x...", gBIOSDev);␊ |
866 | ␉}␊ |
867 | ␊ |
868 | ␉// When booting from CD, default to hard drive boot when possible. ␊ |
869 | ␉if (isCDROM && firstRun) {␊ |
870 | ␉␉const char *val;␊ |
871 | ␉␉char *prompt = NULL;␊ |
872 | ␉␉char *name = NULL;␊ |
873 | ␉␉int cnt;␊ |
874 | ␉␉int optionKey;␊ |
875 | ␊ |
876 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->chameleonConfig)) {␊ |
877 | ␉␉␉prompt = malloc(cnt + 1);␊ |
878 | ␉␉␉strncat(prompt, val, cnt);␊ |
879 | ␉␉} else {␊ |
880 | ␉␉␉name = malloc(80);␊ |
881 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 79, false);␊ |
882 | ␉␉␉prompt = malloc(256);␊ |
883 | ␉␉␉sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);␊ |
884 | ␉␉␉free(name);␊ |
885 | ␉␉}␊ |
886 | ␊ |
887 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->chameleonConfig )) {␊ |
888 | ␉␉␉// The key specified is a special key.␊ |
889 | ␉␉} else {␊ |
890 | ␉␉␉// Default to F8.␊ |
891 | ␉␉␉optionKey = 0x4200;␊ |
892 | ␉␉}␊ |
893 | ␊ |
894 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
895 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
896 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
897 | ␉␉if (timeout != 0) {␊ |
898 | ␉␉␉key = countdown(prompt, kMenuTopRow, timeout);␊ |
899 | ␉␉} else {␊ |
900 | ␉␉␉key = optionKey;␊ |
901 | ␉␉}␊ |
902 | ␊ |
903 | ␉␉if (prompt != NULL) {␊ |
904 | ␉␉␉free(prompt);␊ |
905 | ␉␉}␊ |
906 | ␊ |
907 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
908 | ␊ |
909 | ␉␉// Hit the option key ?␊ |
910 | ␉␉if (key == optionKey) {␊ |
911 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
912 | ␉␉␉timeout = 0;␊ |
913 | ␉␉} else {␊ |
914 | ␉␉␉key = key & 0xFF;␊ |
915 | ␊ |
916 | ␉␉␉// Try booting hard disk if user pressed 'h'␊ |
917 | ␉␉␉if (biosDevIsCDROM(gBIOSDev) && key == 'h') {␊ |
918 | ␉␉␉␉BVRef bvr;␊ |
919 | ␊ |
920 | ␉␉␉␉// Look at partitions hosting OS X other than the CD-ROM␊ |
921 | ␉␉␉␉for (bvr = bvChain; bvr; bvr=bvr->next) {␊ |
922 | ␉␉␉␉␉if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) {␊ |
923 | ␉␉␉␉␉␉gBootVolume = bvr;␊ |
924 | ␉␉␉␉␉}␊ |
925 | ␉␉␉␉}␊ |
926 | ␉␉␉}␊ |
927 | ␉␉␉goto done;␊ |
928 | ␉␉}␊ |
929 | ␉}␊ |
930 | ␊ |
931 | ␉if (gBootMode & kBootModeQuiet) {␊ |
932 | ␉␉// No input allowed from user.␊ |
933 | ␉␉goto done;␊ |
934 | ␉}␊ |
935 | ␊ |
936 | ␉if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) {␊ |
937 | ␉␉// If the user is holding down a modifier key,␊ |
938 | ␉␉// enter safe mode.␊ |
939 | ␉␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
940 | ␉␉␉gBootMode |= kBootModeSafe;␊ |
941 | ␉␉}␊ |
942 | ␉␉goto done;␊ |
943 | ␉}␊ |
944 | ␊ |
945 | ␉if (gDeviceCount > 0) {␊ |
946 | ␉␉// Allocate memory for an array of menu items.␊ |
947 | ␉␉menuItems = malloc(sizeof(MenuItem) * gDeviceCount);␊ |
948 | ␉␉if (menuItems == NULL) {␊ |
949 | ␉␉␉goto done;␊ |
950 | ␉␉}␊ |
951 | ␊ |
952 | ␉␉// Associate a menu item for each BVRef.␊ |
953 | ␉␉for (bvr=bvChain, i=gDeviceCount-1, selectIndex=-1; bvr; bvr=bvr->next) {␊ |
954 | ␉␉␉if (bvr->visible) {␊ |
955 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true);␊ |
956 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
957 | ␉␉␉␉if (bvr == menuBVR) {␊ |
958 | ␉␉␉␉␉selectIndex = i;␊ |
959 | ␉␉␉␉}␊ |
960 | ␉␉␉␉i--;␊ |
961 | ␉␉␉}␊ |
962 | ␉␉}␊ |
963 | ␉␉// Jief : In case the default partition (returned by selectBootVolume) is not in the menu␊ |
964 | ␉␉if ( selectIndex == -1 )␊ |
965 | ␉␉{␊ |
966 | ␉␉␉selectIndex = 0;␊ |
967 | ␊ |
968 | ␉␉␉// gDeviceCount is actually > 0, so menuItems[selectIndex] exists␊ |
969 | ␉␉␉menuBVR = (BVRef)(menuItems[selectIndex].param);␊ |
970 | ␉␉␉// what happen if bvChain is empty ?␊ |
971 | ␉␉}␊ |
972 | ␉}␊ |
973 | ␊ |
974 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
975 | ␉␉// redraw the background buffer␊ |
976 | ␉␉gui.logo.draw = true;␊ |
977 | ␉␉drawBackground();␊ |
978 | ␉␉gui.devicelist.draw = true;␊ |
979 | ␉␉gui.redraw = true;␊ |
980 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
981 | ␊ |
982 | ␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
983 | ␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->chameleonConfig); ␊ |
984 | ␉␉␉if (showBootBanner) {␊ |
985 | ␉␉␉␉// Display banner and show hardware info.␊ |
986 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
987 | ␉␉␉}␊ |
988 | ␊ |
989 | ␉␉␉// redraw background␊ |
990 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
991 | ␉␉}␊ |
992 | ␉} else {␊ |
993 | ␉␉// Clear screen and hide the blinking cursor.␊ |
994 | ␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
995 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
996 | ␉}␊ |
997 | ␊ |
998 | ␉nextRow = kMenuTopRow;␊ |
999 | ␉showPrompt = true;␊ |
1000 | ␊ |
1001 | ␉if (gDeviceCount) {␊ |
1002 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
1003 | ␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1004 | ␉␉}␊ |
1005 | ␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
1006 | ␉␉nextRow += MIN( gDeviceCount, kMenuMaxItems ) + 3;␊ |
1007 | ␉}␊ |
1008 | ␊ |
1009 | ␉// Show the boot prompt.␊ |
1010 | ␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1011 | ␉showBootPrompt( nextRow, showPrompt );␊ |
1012 | ␉␊ |
1013 | ␉do {␊ |
1014 | ␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1015 | ␉␉␉// redraw background␊ |
1016 | ␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1017 | ␉␉␉// reset cursor co-ords␊ |
1018 | ␉␉␉gui.debug.cursor = pos( gui.screen.width - 160 , 10 );␊ |
1019 | ␉␉}␊ |
1020 | ␉␉key = getchar();␊ |
1021 | ␉␉updateMenu( key, (void **) &menuBVR );␊ |
1022 | ␉␉newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1023 | ␊ |
1024 | ␉␉if (newShowPrompt != showPrompt) {␊ |
1025 | ␉␉␉showPrompt = newShowPrompt;␊ |
1026 | ␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
1027 | ␉␉}␊ |
1028 | ␊ |
1029 | ␉␉if (showPrompt) {␊ |
1030 | ␉␉␉updateBootArgs(key);␊ |
1031 | ␉␉}␊ |
1032 | ␊ |
1033 | ␉␉switch (key) {␊ |
1034 | ␉␉case KEY_ENTER:␊ |
1035 | ␉␉␉if (gui.menu.draw) { ␊ |
1036 | ␉␉␉␉key=0;␊ |
1037 | ␉␉␉␉break;␊ |
1038 | ␉␉␉}␊ |
1039 | ␉␉␉if (*gBootArgs == '?') {␊ |
1040 | ␉␉␉␉char * argPtr = gBootArgs;␊ |
1041 | ␊ |
1042 | ␉␉␉␉// Skip the leading "?" character.␊ |
1043 | ␉␉␉␉argPtr++;␊ |
1044 | ␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
1045 | ␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
1046 | ␊ |
1047 | ␉␉␉␉/*␊ |
1048 | ␉␉␉␉* TODO: this needs to be refactored.␊ |
1049 | ␉␉␉␉*/␊ |
1050 | ␉␉␉␉if (strcmp( booterCommand, "video" ) == 0) {␊ |
1051 | ␉␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1052 | ␉␉␉␉␉␉showInfoBox(getVBEInfoString(), getVBEModeInfoString());␊ |
1053 | ␉␉␉␉␉} else {␊ |
1054 | ␉␉␉␉␉␉printVBEModeInfo();␊ |
1055 | ␉␉␉␉␉}␊ |
1056 | ␉␉␉␉} else if ( strcmp( booterCommand, "memory" ) == 0) {␊ |
1057 | ␉␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE ) {␊ |
1058 | ␉␉␉␉␉␉showInfoBox("Memory Map", getMemoryInfoString());␊ |
1059 | ␉␉␉␉␉} else {␊ |
1060 | ␉␉␉␉␉␉printMemoryInfo();␊ |
1061 | ␉␉␉␉␉}␊ |
1062 | ␉␉␉␉} else if (strcmp(booterCommand, "lspci") == 0) {␊ |
1063 | ␉␉␉␉␉lspci();␊ |
1064 | ␉␉␉␉} else if (strcmp(booterCommand, "log") == 0) {␊ |
1065 | ␉␉␉ showTextBuffer(msgbuf, strlen(msgbuf));␊ |
1066 | ␉␉␉␉} else if (strcmp(booterCommand, "more") == 0) {␊ |
1067 | ␉␉␉␉␉showTextFile(booterParam);␊ |
1068 | ␉␉␉␉} else if (strcmp(booterCommand, "rd") == 0) {␊ |
1069 | ␉␉␉␉␉processRAMDiskCommand(&argPtr, booterParam);␊ |
1070 | ␉␉␉␉} else if (strcmp(booterCommand, "norescan") == 0) {␊ |
1071 | ␉␉␉␉␉if (gEnableCDROMRescan) {␊ |
1072 | ␉␉␉␉␉␉gEnableCDROMRescan = false;␊ |
1073 | ␉␉␉␉␉␉break;␊ |
1074 | ␉␉␉␉␉}␊ |
1075 | ␉␉␉␉} else {␊ |
1076 | ␉␉␉␉␉showHelp();␊ |
1077 | ␉␉␉␉}␊ |
1078 | ␉␉␉␉key = 0;␊ |
1079 | ␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1080 | ␉␉␉␉break;␊ |
1081 | ␉␉␉}␊ |
1082 | ␉␉␉gBootVolume = menuBVR;␊ |
1083 | ␉␉␉setRootVolume(menuBVR);␊ |
1084 | ␉␉␉gBIOSDev = menuBVR->biosdev;␊ |
1085 | ␉␉␉break;␊ |
1086 | ␊ |
1087 | ␉␉case KEY_ESC:␊ |
1088 | ␉␉␉clearBootArgs();␊ |
1089 | ␉␉␉break;␊ |
1090 | ␊ |
1091 | ␉␉case KEY_F5:␊ |
1092 | ␉␉␉// New behavior:␊ |
1093 | ␉␉␉// Clear gBootVolume to restart the loop␊ |
1094 | ␉␉␉// if the user enabled rescanning the optical drive.␊ |
1095 | ␉␉␉// Otherwise boot the default boot volume.␊ |
1096 | ␉␉␉if (gEnableCDROMRescan) {␊ |
1097 | ␉␉␉␉gBootVolume = NULL;␊ |
1098 | ␉␉␉␉clearBootArgs();␊ |
1099 | ␉␉␉}␊ |
1100 | ␉␉␉break;␊ |
1101 | ␊ |
1102 | ␉␉case KEY_F10:␊ |
1103 | ␉␉␉gScanSingleDrive = false;␊ |
1104 | ␉␉␉scanDisks(gBIOSDev, &bvCount);␊ |
1105 | ␉␉␉gBootVolume = NULL;␊ |
1106 | ␉␉␉clearBootArgs();␊ |
1107 | ␉␉␉break;␊ |
1108 | ␊ |
1109 | ␉␉case KEY_TAB:␊ |
1110 | ␉␉␉// New behavior:␊ |
1111 | ␉␉␉// Switch between text & graphic interfaces␊ |
1112 | ␉␉␉// Only Permitted if started in graphics interface␊ |
1113 | ␉␉␉if (useGUI)␊ |
1114 | ␉␉␉{␊ |
1115 | ␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE)␊ |
1116 | ␉␉␉␉{␊ |
1117 | ␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1118 | ␊ |
1119 | ␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1120 | ␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1121 | ␊ |
1122 | ␉␉␉␉␉// Display banner and show hardware info.␊ |
1123 | ␉␉␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1124 | ␉␉␉␉␉printf(getVBEInfoString());␊ |
1125 | ␊ |
1126 | ␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
1127 | ␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
1128 | ␊ |
1129 | ␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1130 | ␉␉␉␉␉showPrompt = true;␊ |
1131 | ␊ |
1132 | ␉␉␉␉␉if (gDeviceCount)␊ |
1133 | ␉␉␉␉␉{␊ |
1134 | ␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1135 | ␉␉␉␉␉␉showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
1136 | ␉␉␉␉␉␉nextRow += MIN(gDeviceCount, kMenuMaxItems) + 3;␊ |
1137 | ␉␉␉␉␉}␊ |
1138 | ␊ |
1139 | ␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1140 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1141 | ␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
1142 | ␉␉␉␉}␊ |
1143 | ␉␉␉␉else␊ |
1144 | ␉␉␉␉{␊ |
1145 | ␉␉␉␉␉gui.redraw = true;␊ |
1146 | ␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1147 | ␉␉␉␉␉updateVRAM();␊ |
1148 | ␉␉␉updateGraphicBootPrompt();␊ |
1149 | ␉␉␉␉}␊ |
1150 | ␉␉␉}␊ |
1151 | ␉␉␉key = 0;␊ |
1152 | ␉␉␉break;␊ |
1153 | ␊ |
1154 | ␉␉default:␊ |
1155 | ␉␉␉key = 0;␊ |
1156 | ␉␉␉break;␊ |
1157 | ␉␉}␊ |
1158 | ␉} while (0 == key);␊ |
1159 | ␊ |
1160 | done:␊ |
1161 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
1162 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
1163 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
1164 | ␉}␊ |
1165 | ␊ |
1166 | ␉shouldboot = false;␊ |
1167 | ␉gui.menu.draw = false;␊ |
1168 | ␉if (menuItems) {␊ |
1169 | ␉␉free(menuItems);␊ |
1170 | ␉␉menuItems = NULL;␊ |
1171 | ␉}␊ |
1172 | ␉execute_hook("BootOptions", gBootArgs, gBootArgsPtr, NULL, NULL);␊ |
1173 | ␉return 0;␊ |
1174 | }␊ |
1175 | ␊ |
1176 | //==========================================================================␊ |
1177 | ␊ |
1178 | char gBootUUIDString[32+4+1] = ""; // UUID of the boot volume e.g. 5EB1869F-C4FA-3502-BDEB-3B8ED5D87292␊ |
1179 | extern unsigned char chainbootdev;␊ |
1180 | extern unsigned char chainbootflag;␊ |
1181 | ␊ |
1182 | bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)␊ |
1183 | {␊ |
1184 | ␉int argLen = argName ? strlen(argName) : 0;␊ |
1185 | ␉int len = argLen + cnt + 1; // +1 to account for space␊ |
1186 | ␊ |
1187 | ␉if (argName)␊ |
1188 | ␉{␊ |
1189 | ␉␉len++; // +1 to account for '='␊ |
1190 | ␉}␊ |
1191 | ␊ |
1192 | ␉if (len > *cntRemainingP)␊ |
1193 | ␉{␊ |
1194 | ␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1195 | ␉␉return false;␊ |
1196 | ␉}␊ |
1197 | ␊ |
1198 | ␉if (argName)␊ |
1199 | ␉{␊ |
1200 | ␉␉strncpy(*argP, argName, argLen);␊ |
1201 | ␉␉*argP += argLen;␊ |
1202 | ␉␉*argP[0] = '=';␊ |
1203 | ␉␉(*argP)++;␊ |
1204 | ␉}␊ |
1205 | ␊ |
1206 | ␉strncpy(*argP, val, cnt);␊ |
1207 | ␉*argP += cnt;␊ |
1208 | ␉*argP[0] = ' ';␊ |
1209 | ␉(*argP)++;␊ |
1210 | ␊ |
1211 | ␉*cntRemainingP -= len;␊ |
1212 | ␊ |
1213 | ␉return true;␊ |
1214 | }␊ |
1215 | ␊ |
1216 | // ␊ |
1217 | // Returns TRUE if an argument was copied, FALSE otherwise␊ |
1218 | bool␊ |
1219 | processBootArgument(␊ |
1220 | const char *argName, // The argument to search for␊ |
1221 | const char *userString, // Typed-in boot arguments␊ |
1222 | const char *kernelFlags, // Kernel flags from config table␊ |
1223 | const char *configTable,␊ |
1224 | char **argP, // Output value␊ |
1225 | int *cntRemainingP, // Output count␊ |
1226 | char *foundVal, // found value␊ |
1227 | int foundValSize // max found value size␊ |
1228 | ) {␊ |
1229 | ␉const char *val;␊ |
1230 | ␉int cnt;␊ |
1231 | ␉bool found = false;␊ |
1232 | ␊ |
1233 | ␉if (getValueForBootKey(userString, argName, &val, &cnt)) {␊ |
1234 | ␉␉// Don't copy; these values will be copied at the end of argument processing.␊ |
1235 | ␉␉found = true;␊ |
1236 | ␉} else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {␊ |
1237 | ␉␉// Don't copy; these values will be copied at the end of argument processing.␊ |
1238 | ␉␉found = true;␊ |
1239 | ␉} else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig)) {␊ |
1240 | ␉␉copyArgument(argName, val, cnt, argP, cntRemainingP);␊ |
1241 | ␉␉found = true;␊ |
1242 | ␉}␊ |
1243 | ␉if (found && foundVal) {␊ |
1244 | ␉␉strlcpy(foundVal, val, foundValSize);␊ |
1245 | ␉}␊ |
1246 | ␉return found;␊ |
1247 | }␊ |
1248 | ␊ |
1249 | // Maximum config table value size␊ |
1250 | #define VALUE_SIZE 2048␊ |
1251 | ␊ |
1252 | int processBootOptions()␊ |
1253 | {␊ |
1254 | ␉const char␉*cp = gBootArgs;␊ |
1255 | ␉const char␉*val = 0;␊ |
1256 | ␉const char␉*kernel;␊ |
1257 | ␉int␉␉cnt;␊ |
1258 | ␉int␉␉userCnt;␊ |
1259 | ␉int␉␉cntRemaining;␊ |
1260 | ␉char␉␉*argP;␊ |
1261 | ␉char␉␉*configKernelFlags;␊ |
1262 | ␉char␉␉*valueBuffer;␊ |
1263 | ␊ |
1264 | ␉valueBuffer = malloc(VALUE_SIZE);␊ |
1265 | ␊ |
1266 | ␉skipblanks( &cp );␊ |
1267 | ␊ |
1268 | ␉// Update the unit and partition number.␊ |
1269 | ␉if (gBootVolume)␊ |
1270 | ␉{␊ |
1271 | ␉␉if (!(gBootVolume->flags & kBVFlagNativeBoot))␊ |
1272 | ␉␉{␊ |
1273 | ␉␉␉readBootSector(gBootVolume->biosdev, gBootVolume->part_boff, (void *)0x7c00);␊ |
1274 | ␉␉␉//␊ |
1275 | ␉␉␉// Setup edx, and signal intention to chain load the␊ |
1276 | ␉␉␉// foreign booter.␊ |
1277 | ␉␉␉//␊ |
1278 | ␊ |
1279 | ␉␉␉chainbootdev = gBootVolume->biosdev;␊ |
1280 | ␉␉␉chainbootflag = 1;␊ |
1281 | ␊ |
1282 | ␉␉␉return 1;␊ |
1283 | ␉␉}␊ |
1284 | ␊ |
1285 | ␉␉setRootVolume(gBootVolume);␊ |
1286 | ␊ |
1287 | ␉}␊ |
1288 | ␉// If no boot volume fail immediately because we're just going to fail␊ |
1289 | ␉// trying to load the config file anyway.␊ |
1290 | ␉else␊ |
1291 | ␉{␊ |
1292 | ␉␉return -1;␊ |
1293 | ␉}␊ |
1294 | ␊ |
1295 | ␉// Save a version of mac os we're booting.␊ |
1296 | ␉MacOSVerCurrent = MacOSVer2Int(gBootVolume->OSVersion);␊ |
1297 | ␉// so copy it and trim␊ |
1298 | ␉gMacOSVersion[0] = 0;␊ |
1299 | ␉if (MacOSVerCurrent >= MacOSVer2Int("10.10"))␊ |
1300 | ␉{␊ |
1301 | ␉␉strncat(gMacOSVersion, gBootVolume->OSVersion, 5);␊ |
1302 | ␉}␊ |
1303 | ␉else␊ |
1304 | ␉{␊ |
1305 | ␉␉strncat(gMacOSVersion, gBootVolume->OSVersion, 4);␊ |
1306 | ␉}␊ |
1307 | ␊ |
1308 | ␉// Load config table specified by the user, or use the default.␊ |
1309 | ␊ |
1310 | ␉if (!getValueForBootKey(cp, "config", &val, &cnt))␊ |
1311 | ␉{␊ |
1312 | ␉␉val = 0;␊ |
1313 | ␉␉cnt = 0;␊ |
1314 | ␉}␊ |
1315 | ␊ |
1316 | ␉// Load com.apple.Boot.plist from the selected volume␊ |
1317 | ␉// and use its contents to override default bootConfig.␊ |
1318 | ␊ |
1319 | ␉loadSystemConfig(&bootInfo->bootConfig);␊ |
1320 | ␉loadChameleonConfig(&bootInfo->chameleonConfig, NULL);␊ |
1321 | ␊ |
1322 | ␉// Use the kernel name specified by the user, or fetch the name␊ |
1323 | ␉// in the config table, or use the default if not specified.␊ |
1324 | ␉// Specifying a kernel name on the command line, or specifying␊ |
1325 | ␉// a non-default kernel name in the config file counts as␊ |
1326 | ␉// overriding the kernel, which causes the kernelcache not␊ |
1327 | ␉// to be used.␊ |
1328 | ␊ |
1329 | ␉gOverrideKernel = false;␊ |
1330 | ␉if (( kernel = extractKernelName((char **)&cp) ))␊ |
1331 | ␉{␊ |
1332 | ␉␉strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );␊ |
1333 | ␉}␊ |
1334 | ␉else␊ |
1335 | ␉{␊ |
1336 | ␉␉if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) )␊ |
1337 | ␉␉{␊ |
1338 | ␉␉␉strlcpy( bootInfo->bootFile, val, cnt+1 );␊ |
1339 | ␉␉}␊ |
1340 | ␉␉else␊ |
1341 | ␉␉{␊ |
1342 | ␉␉␉if (MacOSVerCurrent >= MacOSVer2Int("10.10")) // OS X is 10.10 or newer␊ |
1343 | ␉␉␉{␊ |
1344 | ␉␉␉␉strlcpy( bootInfo->bootFile, kOSXKernel, sizeof(bootInfo->bootFile) );␊ |
1345 | ␉␉␉}␊ |
1346 | ␉␉␉else␊ |
1347 | ␉␉␉{␊ |
1348 | ␉␉␉␉// or 10.9 and previous␊ |
1349 | ␉␉␉␉strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );␊ |
1350 | ␉␉␉}␊ |
1351 | ␉␉}␊ |
1352 | ␉}␊ |
1353 | ␊ |
1354 | ␉if ((strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) && (strcmp( bootInfo->bootFile, kOSXKernel ) != 0))␊ |
1355 | ␉{␊ |
1356 | ␉␉gOverrideKernel = true;␊ |
1357 | ␉}␊ |
1358 | ␊ |
1359 | ␉// Ermac : Inject "kext-dev-mode=1" if OS X 10.10 is detected␊ |
1360 | ␉if (MacOSVerCurrent >= MacOSVer2Int("10.10")) // OS X is 10.10 or newer␊ |
1361 | ␉{␊ |
1362 | ␉␉addBootArg("kext-dev-mode=1");␊ |
1363 | ␉}␊ |
1364 | ␊ |
1365 | ␉cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space␊ |
1366 | ␉argP = bootArgs->CommandLine;␊ |
1367 | ␊ |
1368 | ␉// Get config kernel flags, if not ignored.␊ |
1369 | ␉if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || !getValueForKey(kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig))␊ |
1370 | ␉{␊ |
1371 | ␉␉val = "";␊ |
1372 | ␉␉cnt = 0;␊ |
1373 | ␉}␊ |
1374 | ␉configKernelFlags = malloc(cnt + 1);␊ |
1375 | ␉strlcpy(configKernelFlags, val, cnt + 1);␊ |
1376 | ␊ |
1377 | ␉// boot-uuid can be set either on the command-line or in the config file␊ |
1378 | ␉if (!processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config,␊ |
1379 | &argP, &cntRemaining, gBootUUIDString, sizeof(gBootUUIDString)))␊ |
1380 | ␉{␊ |
1381 | ␉␉//␊ |
1382 | ␉␉// Try an alternate method for getting the root UUID on boot helper partitions.␊ |
1383 | ␉␉//␊ |
1384 | ␉␉if (gBootVolume->flags & kBVFlagBooter)␊ |
1385 | ␉␉{␊ |
1386 | ␉␉␉// Load the configuration store in the boot helper partition␊ |
1387 | ␉␉␉if (loadHelperConfig(&bootInfo->helperConfig) == 0)␊ |
1388 | ␉␉␉{␊ |
1389 | ␉␉␉␉val = getStringForKey(kHelperRootUUIDKey, &bootInfo->helperConfig);␊ |
1390 | ␉␉␉␉if (val != NULL)␊ |
1391 | ␉␉␉␉{␊ |
1392 | ␉␉␉␉␉strlcpy(gBootUUIDString, val, sizeof(gBootUUIDString));␊ |
1393 | ␉␉␉␉}␊ |
1394 | ␉␉␉}␊ |
1395 | ␉␉}␊ |
1396 | /*␊ |
1397 | ␉␉// Try to get the volume uuid string␊ |
1398 | ␉␉if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid)␊ |
1399 | ␉␉{␊ |
1400 | ␉␉␉gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString);␊ |
1401 | ␉␉}␊ |
1402 | */␊ |
1403 | ␉␉// If we have the volume uuid add it to the commandline arguments␊ |
1404 | ␉␉if (strlen(gBootUUIDString))␊ |
1405 | ␉␉{␊ |
1406 | ␉␉␉copyArgument(kBootUUIDKey, gBootUUIDString, strlen(gBootUUIDString), &argP, &cntRemaining);␊ |
1407 | ␉␉}␊ |
1408 | ␉␉// Try to get the volume uuid string␊ |
1409 | ␉␉if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid)␊ |
1410 | ␉␉{␊ |
1411 | ␉␉␉gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString);␊ |
1412 | ␉␉}␊ |
1413 | ␉}␊ |
1414 | ␉DBG("Boot UUID [%s (%s), %s]: %s\n", gBootVolume->label, gBootVolume->altlabel, gBootVolume->type_name, gBootUUIDString);␊ |
1415 | ␊ |
1416 | ␉if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config,␊ |
1417 | &argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE))␊ |
1418 | ␉{␊ |
1419 | ␉␉cnt = 0;␊ |
1420 | ␉␉if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig))␊ |
1421 | ␉␉{␊ |
1422 | ␉␉␉valueBuffer[0] = '*';␊ |
1423 | ␉␉␉cnt++;␊ |
1424 | ␉␉␉strlcpy(valueBuffer + 1, val, cnt);␊ |
1425 | ␉␉␉val = valueBuffer;␊ |
1426 | ␉␉␉if (cnt > 0)␊ |
1427 | ␉␉␉{␊ |
1428 | ␉␉␉␉copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);␊ |
1429 | ␉␉␉}␊ |
1430 | ␉␉}␊ |
1431 | ␉␉else␊ |
1432 | ␉␉{␊ |
1433 | ␉␉␉if (strlen(gBootUUIDString))␊ |
1434 | ␉␉␉{␊ |
1435 | ␉␉␉␉val = "*uuid";␊ |
1436 | ␉␉␉␉cnt = 5;␊ |
1437 | ␉␉␉}␊ |
1438 | ␉␉␉else␊ |
1439 | ␉␉␉{␊ |
1440 | ␉␉␉␉// Don't set "rd=.." if there is no boot device key␊ |
1441 | ␉␉␉␉// and no UUID.␊ |
1442 | ␉␉␉␉val = "";␊ |
1443 | ␉␉␉␉cnt = 0;␊ |
1444 | ␉␉␉}␊ |
1445 | ␉␉}␊ |
1446 | /* Bungo␊ |
1447 | ␉␉if (cnt > 0)␊ |
1448 | ␉␉{␊ |
1449 | ␉␉␉copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);␊ |
1450 | ␉␉}␊ |
1451 | */␊ |
1452 | ␉␉strlcpy(gRootDevice, val, (cnt + 1));␊ |
1453 | ␉}␊ |
1454 | ␊ |
1455 | ␉/*␊ |
1456 | ␉ * Removed. We don't need this anymore.␊ |
1457 | ␉ *␊ |
1458 | ␉if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config,␊ |
1459 | ␉␉␉␉␉␉␉ &argP, &cntRemaining, gPlatformName, sizeof(gCacheNameAdler)))␊ |
1460 | ␉{␊ |
1461 | ␉␉getPlatformName(gPlatformName);␊ |
1462 | ␉␉copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);␊ |
1463 | ␉}␊ |
1464 | ␉*/␊ |
1465 | ␊ |
1466 | ␉if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&␊ |
1467 | !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt))␊ |
1468 | ␉{␊ |
1469 | ␉␉if (gBootMode & kBootModeSafe)␊ |
1470 | ␉␉{␊ |
1471 | ␉␉␉copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);␊ |
1472 | ␉␉}␊ |
1473 | ␉}␊ |
1474 | ␊ |
1475 | ␉// Store the merged kernel flags and boot args.␊ |
1476 | ␊ |
1477 | ␉cnt = strlen(configKernelFlags);␊ |
1478 | ␉if (cnt)␊ |
1479 | ␉{␊ |
1480 | ␉␉if (cnt > cntRemaining)␊ |
1481 | ␉␉{␊ |
1482 | ␉␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1483 | ␉␉␉cnt = cntRemaining;␊ |
1484 | ␉␉}␊ |
1485 | ␉␉strncpy(argP, configKernelFlags, cnt);␊ |
1486 | ␉␉argP[cnt++] = ' ';␊ |
1487 | ␉␉cntRemaining -= cnt;␊ |
1488 | ␉}␊ |
1489 | ␉userCnt = strlen(cp);␊ |
1490 | ␉if (userCnt > cntRemaining)␊ |
1491 | ␉{␊ |
1492 | ␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1493 | ␉␉userCnt = cntRemaining;␊ |
1494 | ␉}␊ |
1495 | ␉strncpy(&argP[cnt], cp, userCnt);␊ |
1496 | ␉argP[cnt+userCnt] = '\0';␊ |
1497 | ␊ |
1498 | ␉if(!shouldboot)␊ |
1499 | ␉{␊ |
1500 | ␉␉gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ||␊ |
1501 | ␉␉␉getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->chameleonConfig );␊ |
1502 | ␉␉␊ |
1503 | ␉␉gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) ?␊ |
1504 | ␉␉␉kBootModeSafe : kBootModeNormal;␊ |
1505 | ␊ |
1506 | ␉␉if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) )␊ |
1507 | ␉␉{␊ |
1508 | ␉␉␉gBootMode = kBootModeSafe;␊ |
1509 | ␉␉}␊ |
1510 | ␉}␊ |
1511 | ␊ |
1512 | ␉if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )␊ |
1513 | ␉{␊ |
1514 | ␉␉strlcpy(gMKextName, val, cnt + 1);␊ |
1515 | ␉}␊ |
1516 | ␉else␊ |
1517 | ␉{␊ |
1518 | ␉␉gMKextName[0]=0;␊ |
1519 | ␉}␊ |
1520 | ␊ |
1521 | ␉free(configKernelFlags);␊ |
1522 | ␉free(valueBuffer);␊ |
1523 | ␊ |
1524 | ␉return 0;␊ |
1525 | }␊ |
1526 | ␊ |
1527 | ␊ |
1528 | //==========================================================================␊ |
1529 | // Load the help file and display the file contents on the screen.␊ |
1530 | ␊ |
1531 | void showTextBuffer(char *buf_orig, int size)␊ |
1532 | {␊ |
1533 | ␉char␉*bp;␊ |
1534 | ␉char␉*buf;␊ |
1535 | ␉int␉line;␊ |
1536 | ␉int␉line_offset;␊ |
1537 | ␉int␉c;␊ |
1538 | ␊ |
1539 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1540 | ␉␉showInfoBox( "Press q to continue, space for next page.\n",buf_orig );␊ |
1541 | ␉␉return;␊ |
1542 | ␉}␊ |
1543 | ␊ |
1544 | ␉// Create a copy so that we don't mangle the original␊ |
1545 | ␉buf = malloc(size + 1);␊ |
1546 | ␉memcpy(buf, buf_orig, size);␊ |
1547 | ␉␊ |
1548 | ␊ |
1549 | bp = buf;␊ |
1550 | while (size-- > 0) {␊ |
1551 | ␉␉if (*bp == '\n') {␊ |
1552 | ␉␉␉*bp = '\0';␊ |
1553 | ␉␉}␊ |
1554 | ␉␉bp++;␊ |
1555 | }␊ |
1556 | *bp = '\1';␊ |
1557 | line_offset = 0;␊ |
1558 | ␊ |
1559 | setActiveDisplayPage(1);␊ |
1560 | ␊ |
1561 | while (1) {␊ |
1562 | ␉␉clearScreenRows(0, 24);␊ |
1563 | ␉␉setCursorPosition(0, 0, 1);␊ |
1564 | ␉␉bp = buf;␊ |
1565 | ␉␉for (line = 0; *bp != '\1' && line < line_offset; line++) {␊ |
1566 | ␉␉␉while (*bp != '\0') {␊ |
1567 | ␉␉␉␉bp++;␊ |
1568 | ␉␉␉}␊ |
1569 | ␉␉␉bp++;␊ |
1570 | ␉␉}␊ |
1571 | ␉␉for (line = 0; *bp != '\1' && line < 23; line++) {␊ |
1572 | ␉␉␉setCursorPosition(0, line, 1);␊ |
1573 | ␉␉␉printf("%s\n", bp);␊ |
1574 | ␉␉␉while (*bp != '\0') {␊ |
1575 | ␉␉␉␉bp++;␊ |
1576 | ␉␉␉}␊ |
1577 | ␉␉␉bp++;␊ |
1578 | ␉␉}␊ |
1579 | ␊ |
1580 | ␉␉setCursorPosition(0, 23, 1);␊ |
1581 | ␉␉if (*bp == '\1') {␊ |
1582 | ␉␉␉printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : "");␊ |
1583 | ␉␉} else {␊ |
1584 | ␉␉␉printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : "");␊ |
1585 | ␉␉}␊ |
1586 | ␊ |
1587 | ␉␉c = getchar();␊ |
1588 | ␉␉if (c == 'q' || c == 'Q') {␊ |
1589 | ␉␉␉break;␊ |
1590 | ␉␉}␊ |
1591 | ␉␉if ((c == 'p' || c == 'P') && line_offset > 0) {␊ |
1592 | ␉␉␉line_offset -= 23;␊ |
1593 | ␉␉}␊ |
1594 | ␉␉if (c == ' ') {␊ |
1595 | ␉␉␉if (*bp == '\1') {␊ |
1596 | ␉␉␉␉break;␊ |
1597 | ␉␉␉} else {␊ |
1598 | ␉␉␉␉line_offset += 23;␊ |
1599 | ␉␉␉}␊ |
1600 | ␉␉}␊ |
1601 | }␊ |
1602 | setActiveDisplayPage(0);␊ |
1603 | }␊ |
1604 | ␊ |
1605 | void showHelp(void)␊ |
1606 | {␊ |
1607 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE)␊ |
1608 | ␉{␊ |
1609 | ␉␉showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);␊ |
1610 | ␉}␊ |
1611 | ␉else␊ |
1612 | ␉{␊ |
1613 | ␉␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1614 | ␉}␊ |
1615 | }␊ |
1616 | ␊ |
1617 | void showTextFile(const char * filename)␊ |
1618 | {␊ |
1619 | #define MAX_TEXT_FILE_SIZE 65536␊ |
1620 | ␉char␉*buf;␊ |
1621 | ␉int␉fd;␊ |
1622 | ␉int␉size;␊ |
1623 | ␊ |
1624 | ␉if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0)␊ |
1625 | ␉{␊ |
1626 | ␉␉printf("\nFile not found: %s\n", filename);␊ |
1627 | ␉␉sleep(2);␊ |
1628 | ␉␉return;␊ |
1629 | ␉}␊ |
1630 | ␊ |
1631 | size = file_size(fd);␊ |
1632 | if (size > MAX_TEXT_FILE_SIZE)␊ |
1633 | ␉{␊ |
1634 | ␉␉size = MAX_TEXT_FILE_SIZE;␊ |
1635 | ␉}␊ |
1636 | buf = malloc(size);␊ |
1637 | read(fd, buf, size);␊ |
1638 | close(fd);␊ |
1639 | ␉showTextBuffer(buf, size);␊ |
1640 | ␉free(buf);␊ |
1641 | }␊ |
1642 | ␊ |
1643 | // This is a very simplistic prompting scheme that just grabs two hex characters␊ |
1644 | // Eventually we need to do something more user-friendly like display a menu␊ |
1645 | // based off of the Multiboot device list␊ |
1646 | ␊ |
1647 | int selectAlternateBootDevice(int bootdevice)␊ |
1648 | {␊ |
1649 | ␉int key;␊ |
1650 | ␉int newbootdevice;␊ |
1651 | ␉int digitsI = 0;␊ |
1652 | ␉char *end;␊ |
1653 | ␉char digits[3] = {0,0,0};␊ |
1654 | ␊ |
1655 | ␉// We've already printed the current boot device so user knows what it is␊ |
1656 | ␉printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n");␊ |
1657 | ␉printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice);␊ |
1658 | ␉do {␊ |
1659 | ␉␉key = getchar();␊ |
1660 | ␉␉switch (ASCII_KEY(key))␊ |
1661 | ␉␉{␊ |
1662 | ␉␉case KEY_BKSP:␊ |
1663 | ␉␉␉if (digitsI > 0)␊ |
1664 | ␉␉␉{␊ |
1665 | ␉␉␉␉int x, y, t;␊ |
1666 | ␉␉␉␉getCursorPositionAndType(&x, &y, &t);␊ |
1667 | ␉␉␉␉// Assume x is not 0;␊ |
1668 | ␉␉␉␉x--;␊ |
1669 | ␉␉␉␉setCursorPosition(x,y,0); // back up one char␊ |
1670 | ␉␉␉␉// Overwrite with space without moving cursor position␊ |
1671 | ␉␉␉␉putca(' ', 0x07, 1);␊ |
1672 | ␉␉␉␉digitsI--;␊ |
1673 | ␉␉␉}␊ |
1674 | ␉␉␉else␊ |
1675 | ␉␉␉{␊ |
1676 | ␉␉␉␉// TODO: Beep or something␊ |
1677 | ␉␉␉}␊ |
1678 | ␉␉␉break;␊ |
1679 | ␊ |
1680 | ␉␉case KEY_ENTER:␊ |
1681 | ␉␉␉digits[digitsI] = '\0';␊ |
1682 | ␉␉␉newbootdevice = strtol(digits, &end, 16);␊ |
1683 | ␉␉␉if (end == digits && *end == '\0')␊ |
1684 | ␉␉␉{␊ |
1685 | ␉␉␉␉// User entered empty string␊ |
1686 | ␉␉␉␉printf("\nUsing default boot device %x\n", bootdevice);␊ |
1687 | ␉␉␉␉key = 0;␊ |
1688 | ␉␉␉} else if(end != digits && *end == '\0') {␊ |
1689 | ␉␉␉␉bootdevice = newbootdevice;␊ |
1690 | ␉␉␉␉printf("\n");␊ |
1691 | ␉␉␉␉key = 0; // We gots da boot device␊ |
1692 | ␉␉␉} else {␊ |
1693 | ␉␉␉␉printf("\nCouldn't parse. try again: ");␊ |
1694 | ␉␉␉␉digitsI = 0;␊ |
1695 | ␉␉␉}␊ |
1696 | ␉␉␉break;␊ |
1697 | ␊ |
1698 | ␉␉default:␊ |
1699 | ␉␉␉if (isxdigit(ASCII_KEY(key)) && digitsI < 2)␊ |
1700 | ␉␉␉{␊ |
1701 | ␉␉␉␉putchar(ASCII_KEY(key));␊ |
1702 | ␉␉␉␉digits[digitsI++] = ASCII_KEY(key);␊ |
1703 | ␉␉␉}␊ |
1704 | ␉␉␉else␊ |
1705 | ␉␉␉{␊ |
1706 | ␉␉␉␉// TODO: Beep or something␊ |
1707 | ␉␉␉}␊ |
1708 | ␉␉␉break;␊ |
1709 | ␉␉};␊ |
1710 | ␉} while (key != 0);␊ |
1711 | ␊ |
1712 | ␉return bootdevice;␊ |
1713 | }␊ |
1714 | ␊ |
1715 | bool promptForRescanOption(void)␊ |
1716 | {␊ |
1717 | ␉printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");␊ |
1718 | ␉if (getchar() == KEY_ENTER)␊ |
1719 | ␉{␊ |
1720 | ␉␉return true;␊ |
1721 | ␉}␊ |
1722 | ␉else␊ |
1723 | ␉{␊ |
1724 | ␉␉return false;␊ |
1725 | ␉}␊ |
1726 | }␊ |
1727 | |