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