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