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