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