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