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 "graphics.h"␊ |
28 | #include "fdisk.h"␊ |
29 | #include "pci.h"␊ |
30 | #include "options.h"␊ |
31 | #include "modules.h"␊ |
32 | ␊ |
33 | #ifndef EMBED_HELP␊ |
34 | #define EMBED_HELP 0␊ |
35 | #endif␊ |
36 | ␊ |
37 | #if EMBED_HELP␊ |
38 | #include "embedded.h" //+ 1376 bytes␊ |
39 | #endif␊ |
40 | ␊ |
41 | ␊ |
42 | bool shouldboot = false;␊ |
43 | ␊ |
44 | #if UNUSED␊ |
45 | extern int multiboot_timeout;␊ |
46 | extern int multiboot_timeout_set;␊ |
47 | #endif␊ |
48 | ␊ |
49 | extern BVRef bvChain;␊ |
50 | //extern int␉␉menucount;␊ |
51 | ␊ |
52 | extern int␉␉gDeviceCount;␊ |
53 | ␊ |
54 | int␉␉␉selectIndex = 0;␊ |
55 | MenuItem * menuItems = NULL;␊ |
56 | ␊ |
57 | static int countdown( const char * msg, int row, int timeout );␊ |
58 | static void showBootPrompt(int row, bool visible);␊ |
59 | static void updateBootArgs( int key );␊ |
60 | static void showMenu( const MenuItem * items, int count,␊ |
61 | ␉␉␉␉␉ int selection, int row, int height );␊ |
62 | static int updateMenu( int key, void ** paramPtr );␊ |
63 | static void skipblanks( const char ** cpp );␊ |
64 | static const char * extractKernelName( char ** cpp );␊ |
65 | ␊ |
66 | //==========================================================================␊ |
67 | ␊ |
68 | void changeCursor( int col, int row, int type, CursorState * cs )␊ |
69 | {␊ |
70 | if (cs) getCursorPositionAndType( &cs->x, &cs->y, &cs->type );␊ |
71 | setCursorType( type );␊ |
72 | setCursorPosition( col, row, 0 );␊ |
73 | }␊ |
74 | ␊ |
75 | void moveCursor( int col, int row )␊ |
76 | {␊ |
77 | setCursorPosition( col, row, 0 );␊ |
78 | }␊ |
79 | ␊ |
80 | void restoreCursor( const CursorState * cs )␊ |
81 | {␊ |
82 | setCursorPosition( cs->x, cs->y, 0 );␊ |
83 | setCursorType( cs->type );␊ |
84 | }␊ |
85 | ␊ |
86 | //==========================================================================␊ |
87 | ␊ |
88 | /* Flush keyboard buffer; returns TRUE if any of the flushed␊ |
89 | * characters was F8.␊ |
90 | */␊ |
91 | ␊ |
92 | bool flushKeyboardBuffer(void)␊ |
93 | {␊ |
94 | bool status = false;␊ |
95 | ␉␊ |
96 | while ( readKeyboardStatus() ) {␊ |
97 | if (bgetc() == 0x4200) status = true;␊ |
98 | }␊ |
99 | return status;␊ |
100 | }␊ |
101 | ␊ |
102 | //==========================================================================␊ |
103 | ␊ |
104 | static int countdown( const char * msg, int row, int timeout )␊ |
105 | {␊ |
106 | unsigned long time;␊ |
107 | int ch = 0;␊ |
108 | int col = strlen(msg) + 1;␊ |
109 | ␉␊ |
110 | flushKeyboardBuffer();␊ |
111 | ␉␊ |
112 | ␉moveCursor( 0, row );␊ |
113 | ␉printf(msg);␊ |
114 | ␉␉␊ |
115 | for ( time = time18(), timeout++; timeout > 0; )␊ |
116 | {␊ |
117 | ␉␉if ((ch = readKeyboardStatus()))␊ |
118 | break;␊ |
119 | ␉␉␊ |
120 | // Count can be interrupted by holding down shift,␊ |
121 | // control or alt key␊ |
122 | if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 )␊ |
123 | ␉␉{␊ |
124 | ch = 1;␊ |
125 | break;␊ |
126 | }␊ |
127 | ␉␉␊ |
128 | if ( time18() >= time )␊ |
129 | {␊ |
130 | time += 18;␊ |
131 | timeout--;␊ |
132 | ␉␉␉␊ |
133 | ␉␉␉moveCursor( col, row );␊ |
134 | ␉␉␉printf("(%d) ", timeout);␊ |
135 | }␊ |
136 | }␊ |
137 | ␉␊ |
138 | flushKeyboardBuffer();␊ |
139 | ␉␊ |
140 | return ch;␊ |
141 | }␊ |
142 | ␊ |
143 | //==========================================================================␊ |
144 | ␊ |
145 | char gBootArgs[BOOT_STRING_LEN];␊ |
146 | char * gBootArgsPtr = gBootArgs;␊ |
147 | char * gBootArgsEnd = gBootArgs + BOOT_STRING_LEN - 1;␊ |
148 | char booterCommand[BOOT_STRING_LEN];␊ |
149 | char booterParam[BOOT_STRING_LEN];␊ |
150 | ␊ |
151 | void clearBootArgs(void)␊ |
152 | {␊ |
153 | ␉gBootArgsPtr = gBootArgs;␊ |
154 | ␉memset(gBootArgs, '\0', BOOT_STRING_LEN);␊ |
155 | }␊ |
156 | ␊ |
157 | void addBootArg(const char * argStr)␊ |
158 | {␊ |
159 | ␉if ( (gBootArgsPtr + strlen(argStr) + 1) < gBootArgsEnd)␊ |
160 | ␉{␊ |
161 | ␉␉*gBootArgsPtr++ = ' ';␊ |
162 | ␉␉strcat(gBootArgs, argStr);␊ |
163 | ␉␉gBootArgsPtr += strlen(argStr);␊ |
164 | ␉}␊ |
165 | }␊ |
166 | ␊ |
167 | //==========================================================================␊ |
168 | ␊ |
169 | static void showBootPrompt(int row, bool visible)␊ |
170 | {␊ |
171 | ␉extern char bootPrompt[];␊ |
172 | #ifndef OPTION_ROM␊ |
173 | ␉extern char bootRescanPrompt[];␊ |
174 | #endif␊ |
175 | ␉␊ |
176 | ␉changeCursor( 0, row, kCursorTypeUnderline, 0 ); ␊ |
177 | ␉clearScreenRows( row, kScreenLastRow );␊ |
178 | ␉␊ |
179 | ␉clearBootArgs();␊ |
180 | ␉␊ |
181 | ␉if (visible) {␊ |
182 | #ifndef OPTION_ROM␊ |
183 | ␉␉if (gEnableCDROMRescan)␊ |
184 | ␉␉{␊ |
185 | ␉␉␉printf( bootRescanPrompt );␊ |
186 | ␉␉}␊ |
187 | ␉␉else␊ |
188 | #endif␊ |
189 | ␉␉{␊ |
190 | ␉␉␉printf( bootPrompt );␊ |
191 | ␉␉}␊ |
192 | ␉} else {␊ |
193 | ␉␉printf("Press Enter to start up the foreign OS. ");␊ |
194 | ␉}␊ |
195 | }␊ |
196 | ␊ |
197 | //==========================================================================␊ |
198 | ␊ |
199 | static void updateBootArgs( int key )␊ |
200 | {␊ |
201 | key &= kASCIIKeyMask;␊ |
202 | ␉␊ |
203 | switch ( key )␊ |
204 | {␊ |
205 | case kBackspaceKey:␊ |
206 | if ( gBootArgsPtr > gBootArgs )␊ |
207 | {␊ |
208 | int x, y, t;␊ |
209 | getCursorPositionAndType( &x, &y, &t );␊ |
210 | if ( x == 0 && y )␊ |
211 | {␊ |
212 | x = 80; y--;␊ |
213 | }␊ |
214 | if (x)␊ |
215 | ␉␉␉␉{␊ |
216 | ␉␉␉␉␉x--;␊ |
217 | ␉␉␉␉}␊ |
218 | ␉␉␉␉␊ |
219 | ␉␉␉␉setCursorPosition( x, y, 0 );␊ |
220 | ␉␉␉␉putca(' ', 0x07, 1);␊ |
221 | ␉␉␉␉␊ |
222 | ␉␉␉␉*gBootArgsPtr-- = '\0';␊ |
223 | ␉␉␉}␊ |
224 | ␊ |
225 | ␉␉␉break;␊ |
226 | ␉␉␉␊ |
227 | default:␊ |
228 | if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
229 | {␊ |
230 | ␉␉␉␉putchar(key); // echo to screen␊ |
231 | ␉␉␉␉*gBootArgsPtr++ = key;␊ |
232 | ␉␉␉}␊ |
233 | ␊ |
234 | ␉␉␉break;␊ |
235 | }␊ |
236 | }␊ |
237 | ␊ |
238 | //==========================================================================␊ |
239 | ␊ |
240 | const MenuItem * gMenuItems = NULL;␊ |
241 | ␊ |
242 | int gMenuItemCount;␊ |
243 | int gMenuRow;␊ |
244 | int gMenuHeight;␊ |
245 | int gMenuTop;␊ |
246 | int gMenuBottom;␊ |
247 | int gMenuSelection;␊ |
248 | ␊ |
249 | int␉ gMenuStart;␊ |
250 | int␉ gMenuEnd;␊ |
251 | ␊ |
252 | void printMenuItem( const MenuItem * item, int highlight )␊ |
253 | {␊ |
254 | printf(" ");␊ |
255 | ␉␊ |
256 | if ( highlight )␊ |
257 | putca(' ', 0x70, strlen(item->name) + 4);␊ |
258 | else␊ |
259 | putca(' ', 0x07, 40);␊ |
260 | ␉␊ |
261 | printf(" %40s\n", item->name);␊ |
262 | }␊ |
263 | ␊ |
264 | //==========================================================================␊ |
265 | ␊ |
266 | static void showMenu( const MenuItem * items, int count,␊ |
267 | ␉␉␉␉␉ int selection, int row, int height )␊ |
268 | {␊ |
269 | int i;␊ |
270 | CursorState cursorState;␊ |
271 | ␉␊ |
272 | if ( items == NULL || count == 0 ) ␊ |
273 | ␉␉return;␊ |
274 | ␉␊ |
275 | // head and tail points to the start and the end of the list.␊ |
276 | // top and bottom points to the first and last visible items␊ |
277 | // in the menu window.␊ |
278 | ␉␊ |
279 | gMenuItems␉␉= items;␊ |
280 | gMenuRow␉␉= row;␊ |
281 | gMenuHeight␉␉= height;␊ |
282 | gMenuItemCount␉= count;␊ |
283 | gMenuTop␉␉= 0;␊ |
284 | gMenuBottom␉␉= min( count, height ) - 1;␊ |
285 | gMenuSelection␉= selection;␊ |
286 | ␉␊ |
287 | gMenuStart␉␉= 0;␊ |
288 | gMenuEnd␉ = count; //min( count, gui.maxdevices ) - 1;␊ |
289 | ␉␊ |
290 | ␉// If the selected item is not visible, shift the list down.␊ |
291 | ␉␊ |
292 | if ( gMenuSelection > gMenuBottom )␊ |
293 | {␊ |
294 | gMenuTop += ( gMenuSelection - gMenuBottom );␊ |
295 | gMenuBottom = gMenuSelection;␊ |
296 | }␊ |
297 | ␉␊ |
298 | ␉if ( gMenuSelection > gMenuEnd )␊ |
299 | {␊ |
300 | ␉␉gMenuStart += ( gMenuSelection - gMenuEnd );␊ |
301 | gMenuEnd = gMenuSelection;␊ |
302 | }␊ |
303 | ␉␊ |
304 | ␉// Draw the visible items.␊ |
305 | ␉␊ |
306 | ␉changeCursor( 0, row, kCursorTypeHidden, &cursorState );␊ |
307 | ␉␊ |
308 | ␉for ( i = gMenuTop; i <= gMenuBottom; i++ )␊ |
309 | ␉{␊ |
310 | ␉␉printMenuItem( &items[i], (i == gMenuSelection) );␊ |
311 | ␉}␊ |
312 | ␉␊ |
313 | ␉restoreCursor( &cursorState );␊ |
314 | }␊ |
315 | ␊ |
316 | //==========================================================================␊ |
317 | ␊ |
318 | static int updateMenu( int key, void ** paramPtr )␊ |
319 | {␊ |
320 | int moved = 0;␊ |
321 | ␉␊ |
322 | union {␊ |
323 | struct {␊ |
324 | unsigned int␊ |
325 | ␉␉␉selectionUp : 1,␊ |
326 | ␉␉␉selectionDown : 1,␊ |
327 | ␉␉␉scrollUp : 1,␊ |
328 | ␉␉␉scrollDown : 1;␊ |
329 | } f;␊ |
330 | unsigned int w;␊ |
331 | } draw = {{0}};␊ |
332 | ␉␊ |
333 | ␉if ( gMenuItems == NULL )␊ |
334 | ␉␉return 0;␊ |
335 | ␉␊ |
336 | ␉switch ( key )␊ |
337 | ␉{␊ |
338 | ␉␉case 0x4800: // Up Arrow␊ |
339 | ␉␉␉if ( gMenuSelection != gMenuTop )␊ |
340 | ␉␉␉␉draw.f.selectionUp = 1;␊ |
341 | ␉␉␉else if ( gMenuTop > 0 )␊ |
342 | ␉␉␉␉draw.f.scrollDown = 1;␊ |
343 | ␉␉␉break;␊ |
344 | ␉␉␉␊ |
345 | ␉␉case 0x5000: // Down Arrow␊ |
346 | ␉␉␉if ( gMenuSelection != gMenuBottom )␊ |
347 | ␉␉␉␉draw.f.selectionDown = 1;␊ |
348 | ␉␉␉else if ( gMenuBottom < (gMenuItemCount - 1) ) ␊ |
349 | ␉␉␉␉draw.f.scrollUp = 1;␊ |
350 | ␉␉␉break;␊ |
351 | ␉␉default:␊ |
352 | ␉␉␉break;␊ |
353 | ␉}␊ |
354 | ␉␊ |
355 | if ( draw.w )␊ |
356 | {␊ |
357 | if ( draw.f.scrollUp )␊ |
358 | {␊ |
359 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, 1);␊ |
360 | gMenuTop++; gMenuBottom++;␊ |
361 | ␉␉␉gMenuStart++; gMenuEnd++;␊ |
362 | draw.f.selectionDown = 1;␊ |
363 | }␊ |
364 | ␉␉␊ |
365 | if ( draw.f.scrollDown )␊ |
366 | {␊ |
367 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, -1);␊ |
368 | gMenuTop--; gMenuBottom--;␊ |
369 | gMenuStart--; gMenuEnd--;␊ |
370 | draw.f.selectionUp = 1;␊ |
371 | }␊ |
372 | ␉␉␊ |
373 | if ( draw.f.selectionUp || draw.f.selectionDown )␊ |
374 | {␊ |
375 | ␉␉␉␊ |
376 | ␉␉␉CursorState cursorState;␊ |
377 | ␉␉␉␊ |
378 | ␉␉␉// Set cursor at current position, and clear inverse video.␊ |
379 | ␉␉␉changeCursor( 0, gMenuRow + gMenuSelection - gMenuTop, kCursorTypeHidden, &cursorState );␊ |
380 | ␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 0 );␊ |
381 | ␉␉␉␊ |
382 | ␉␉␉if ( draw.f.selectionUp )␊ |
383 | ␉␉␉{␊ |
384 | ␉␉␉␉gMenuSelection--;␊ |
385 | ␉␉␉␉if(( gMenuSelection - gMenuStart) == -1 )␊ |
386 | ␉␉␉␉{␊ |
387 | ␉␉␉␉␉gMenuStart--;␊ |
388 | ␉␉␉␉␉gMenuEnd--;␊ |
389 | ␉␉␉␉}␊ |
390 | ␉␉␉␉␊ |
391 | ␉␉␉} else {␊ |
392 | ␉␉␉␉gMenuSelection++;␊ |
393 | ␉␉␉␉if(( gMenuSelection - ( gMenuEnd - 1) - gMenuStart) > 0 )␊ |
394 | ␉␉␉␉{␊ |
395 | ␉␉␉␉␉gMenuStart++;␊ |
396 | ␉␉␉␉␉gMenuEnd++;␊ |
397 | ␉␉␉␉}␊ |
398 | ␉␉␉}␊ |
399 | ␉␉␉␊ |
400 | ␉␉␉moveCursor( 0, gMenuRow + gMenuSelection - gMenuTop );␊ |
401 | ␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 1 );␊ |
402 | ␉␉␉restoreCursor( &cursorState );␊ |
403 | ␉␉␉␊ |
404 | ␉␉}␊ |
405 | ␉␉␊ |
406 | *paramPtr = gMenuItems[gMenuSelection].param; ␊ |
407 | moved = 1;␊ |
408 | }␊ |
409 | ␉␊ |
410 | ␉return moved;␊ |
411 | }␊ |
412 | ␊ |
413 | //==========================================================================␊ |
414 | ␊ |
415 | static void skipblanks( const char ** cpp ) ␊ |
416 | {␊ |
417 | while ( **(cpp) == ' ' || **(cpp) == '\t' ) ++(*cpp);␊ |
418 | }␊ |
419 | ␊ |
420 | //==========================================================================␊ |
421 | ␊ |
422 | static const char * extractKernelName( char ** cpp )␊ |
423 | {␊ |
424 | char * kn = *cpp;␊ |
425 | char * cp = *cpp;␊ |
426 | char c;␊ |
427 | ␉␊ |
428 | // Convert char to lower case.␊ |
429 | ␉␊ |
430 | c = *cp | 0x20;␊ |
431 | ␉␊ |
432 | // Must start with a letter or a '/'.␊ |
433 | ␉␊ |
434 | if ( (c < 'a' || c > 'z') && ( c != '/' ) ) return 0;␊ |
435 | ␉␊ |
436 | // Keep consuming characters until we hit a separator.␊ |
437 | ␉␊ |
438 | while ( *cp && (*cp != '=') && (*cp != ' ') && (*cp != '\t') )␊ |
439 | ␉{␊ |
440 | cp++;␊ |
441 | ␉}␊ |
442 | // Only SPACE or TAB separator is accepted.␊ |
443 | // Reject everything else.␊ |
444 | ␉␊ |
445 | if (*cp == '=') return 0;␊ |
446 | ␉␊ |
447 | // Overwrite the separator, and move the pointer past␊ |
448 | // the kernel name.␊ |
449 | ␉␊ |
450 | if (*cp != '\0') *cp++ = '\0';␊ |
451 | *cpp = cp;␊ |
452 | ␉␊ |
453 | return kn;␊ |
454 | }␊ |
455 | ␊ |
456 | #ifndef OPTION_ROM␊ |
457 | //==========================================================================␊ |
458 | ␊ |
459 | void printMemoryInfo(void)␊ |
460 | {␊ |
461 | int line;␊ |
462 | unsigned long i;␊ |
463 | MemoryRange *mp = bootInfo->memoryMap;␊ |
464 | ␉␊ |
465 | // Activate and clear page 1␊ |
466 | setActiveDisplayPage(1);␊ |
467 | clearScreenRows(0, 24);␊ |
468 | setCursorPosition( 0, 0, 1 );␊ |
469 | ␉␊ |
470 | printf("BIOS reported memory ranges:\n");␊ |
471 | line = 1;␊ |
472 | for (i=0; i<bootInfo->memoryMapCount; i++) {␊ |
473 | printf("Base 0x%08x%08x, ",␊ |
474 | (unsigned long)(mp->base >> 32),␊ |
475 | (unsigned long)(mp->base));␊ |
476 | printf("length 0x%08x%08x, type %d\n",␊ |
477 | (unsigned long)(mp->length >> 32),␊ |
478 | (unsigned long)(mp->length),␊ |
479 | mp->type);␊ |
480 | if (line++ > 20) {␊ |
481 | pause();␊ |
482 | line = 0;␊ |
483 | }␊ |
484 | mp++;␊ |
485 | }␊ |
486 | if (line > 0) {␊ |
487 | pause();␊ |
488 | }␊ |
489 | ␊ |
490 | setActiveDisplayPage(0);␊ |
491 | }␊ |
492 | ␊ |
493 | char *getMemoryInfoString()␊ |
494 | {␊ |
495 | unsigned long i;␊ |
496 | MemoryRange *mp = bootInfo->memoryMap;␊ |
497 | ␉char *buff = malloc(sizeof(char)*1024);␊ |
498 | ␉if(!buff) return 0;␊ |
499 | ␉␊ |
500 | ␉char info[] = "BIOS reported memory ranges:\n";␊ |
501 | ␉sprintf(buff, "%s", info);␊ |
502 | for (i=0; i<bootInfo->memoryMapCount; i++) {␊ |
503 | sprintf( buff+strlen(buff), "Base 0x%08x%08x, ",␊ |
504 | ␉␉␉␉(unsigned long)(mp->base >> 32),␊ |
505 | ␉␉␉␉(unsigned long)(mp->base));␊ |
506 | sprintf( buff+strlen(buff), "length 0x%08x%08x, type %d\n",␊ |
507 | ␉␉␉␉(unsigned long)(mp->length >> 32),␊ |
508 | ␉␉␉␉(unsigned long)(mp->length),␊ |
509 | ␉␉␉␉mp->type);␊ |
510 | mp++;␊ |
511 | }␊ |
512 | ␉return buff;␊ |
513 | }␊ |
514 | //==========================================================================␊ |
515 | ␊ |
516 | void lspci(void)␊ |
517 | {␊ |
518 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) { ␊ |
519 | ␉␉setActiveDisplayPage(1);␊ |
520 | ␉␉clearScreenRows(0, 24);␊ |
521 | ␉␉setCursorPosition(0, 0, 1);␊ |
522 | ␉}␊ |
523 | ␉␊ |
524 | ␉dump_pci_dt(root_pci_dev->children);␊ |
525 | ␉␊ |
526 | ␉pause();␊ |
527 | ␉␊ |
528 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
529 | ␉␉setActiveDisplayPage(0);␊ |
530 | ␉}␊ |
531 | }␊ |
532 | #endif␊ |
533 | ␊ |
534 | //==========================================================================␊ |
535 | ␊ |
536 | int getBootOptions(bool firstRun)␊ |
537 | {␊ |
538 | ␉int i;␊ |
539 | ␉int key;␊ |
540 | ␉int nextRow;␊ |
541 | ␉int timeout;␊ |
542 | #if UNUSED␊ |
543 | ␉int bvCount;␊ |
544 | #endif␊ |
545 | ␉BVRef bvr;␊ |
546 | ␉BVRef menuBVR;␊ |
547 | ␉bool showPrompt, newShowPrompt, isCDROM;␊ |
548 | ␉␊ |
549 | ␉// Initialize default menu selection entry.␊ |
550 | ␉gBootVolume = menuBVR = selectBootVolume(bvChain);␊ |
551 | ␉␊ |
552 | ␉if (biosDevIsCDROM(gBIOSDev)) {␊ |
553 | ␉␉isCDROM = true;␊ |
554 | ␉} else {␊ |
555 | ␉␉isCDROM = false;␊ |
556 | ␉}␊ |
557 | ␉␊ |
558 | ␉// Clear command line boot arguments␊ |
559 | ␉clearBootArgs();␊ |
560 | ␉␊ |
561 | ␉// Allow user to override default timeout.␊ |
562 | #if UNUSED␊ |
563 | ␉if (multiboot_timeout_set) {␊ |
564 | ␉␉timeout = multiboot_timeout;␊ |
565 | ␉} else ␊ |
566 | #endif␊ |
567 | ␉if (!getIntForKey(kTimeoutKey, &timeout, &bootInfo->bootConfig)) {␊ |
568 | ␉␉/* If there is no timeout key in the file use the default timeout␊ |
569 | ␉␉ which is different for CDs vs. hard disks. However, if not booting␊ |
570 | ␉␉ a CD and no config file could be loaded set the timeout␊ |
571 | ␉␉ to zero which causes the menu to display immediately.␊ |
572 | ␉␉ This way, if no partitions can be found, that is the disk is unpartitioned␊ |
573 | ␉␉ or simply cannot be read) then an empty menu is displayed.␊ |
574 | ␉␉ If some partitions are found, for example a Windows partition, then␊ |
575 | ␉␉ these will be displayed in the menu as foreign partitions.␊ |
576 | ␉␉ */␊ |
577 | ␉␉if (isCDROM) {␊ |
578 | ␉␉␉timeout = kCDBootTimeout;␊ |
579 | ␉␉} else {␊ |
580 | ␉␉␉timeout = sysConfigValid ? kBootTimeout : 0;␊ |
581 | ␉␉}␊ |
582 | ␉}␊ |
583 | ␉␊ |
584 | ␉if (timeout < 0) {␊ |
585 | ␉␉gBootMode |= kBootModeQuiet;␊ |
586 | ␉}␊ |
587 | ␉␊ |
588 | ␉// If the user is holding down a modifier key, enter safe mode.␊ |
589 | ␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
590 | ␉␉␊ |
591 | ␉␉gBootMode |= kBootModeSafe;␊ |
592 | ␉}␊ |
593 | ␉␊ |
594 | ␉// Checking user pressed keys␊ |
595 | ␉bool f8press = false, spress = false, vpress = false;␊ |
596 | ␉while (readKeyboardStatus()) {␊ |
597 | ␉␉key = bgetc ();␊ |
598 | ␉␉if (key == 0x4200) f8press = true;␊ |
599 | ␉␉if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true;␊ |
600 | ␉␉if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true;␊ |
601 | ␉}␊ |
602 | ␉// If user typed F8, abort quiet mode, and display the menu.␊ |
603 | ␉if (f8press) {␊ |
604 | ␉␉gBootMode &= ~kBootModeQuiet;␊ |
605 | ␉␉timeout = 0;␊ |
606 | ␉}␊ |
607 | ␉// If user typed 'v' or 'V', boot in verbose mode.␊ |
608 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && vpress) {␊ |
609 | ␉␉addBootArg(kVerboseModeFlag);␊ |
610 | ␉}␊ |
611 | ␉// If user typed 's' or 'S', boot in single user mode.␊ |
612 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && spress) {␊ |
613 | ␉␉addBootArg(kSingleUserModeFlag);␊ |
614 | ␉}␊ |
615 | ␉␊ |
616 | ␉setCursorPosition(0, 0, 0);␊ |
617 | ␉clearScreenRows(0, kScreenLastRow);␊ |
618 | ␉if (!(gBootMode & kBootModeQuiet)) {␊ |
619 | ␉␉// Display banner and show hardware info.␊ |
620 | ␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
621 | ␉}␊ |
622 | ␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
623 | ␉verbose("Scanning device %x...", gBIOSDev);␊ |
624 | ␉␊ |
625 | ␉// When booting from CD, default to hard drive boot when possible. ␊ |
626 | ␉if (isCDROM && firstRun) {␊ |
627 | ␉␉const char *val;␊ |
628 | ␉␉char *prompt = NULL;␊ |
629 | ␉␉char *name = NULL;␊ |
630 | ␉␉int cnt;␊ |
631 | ␉␉int optionKey;␊ |
632 | ␉␉␊ |
633 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig)) {␊ |
634 | ␉␉␉prompt = malloc(cnt + 1);␊ |
635 | ␉␉␉strncat(prompt, val, cnt);␊ |
636 | ␉␉} else {␊ |
637 | ␉␉␉name = malloc(80);␊ |
638 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 79, false);␊ |
639 | ␉␉␉prompt = malloc(256);␊ |
640 | ␉␉␉sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);␊ |
641 | ␉␉␉free(name);␊ |
642 | ␉␉}␊ |
643 | ␉␉␊ |
644 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig )) {␊ |
645 | ␉␉␉// The key specified is a special key.␊ |
646 | ␉␉} else {␊ |
647 | ␉␉␉// Default to F8.␊ |
648 | ␉␉␉optionKey = 0x4200;␊ |
649 | ␉␉}␊ |
650 | ␉␉␊ |
651 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
652 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
653 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
654 | ␉␉if (timeout != 0) {␊ |
655 | ␉␉␉key = countdown(prompt, kMenuTopRow, timeout);␊ |
656 | ␉␉} else {␊ |
657 | ␉␉␉key = optionKey;␊ |
658 | ␉␉}␊ |
659 | ␉␉␊ |
660 | ␉␉if (prompt != NULL) {␊ |
661 | ␉␉␉free(prompt);␊ |
662 | ␉␉}␊ |
663 | ␉␉␊ |
664 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
665 | ␉␉␊ |
666 | ␉␉// Hit the option key ?␊ |
667 | ␉␉if (key == optionKey) {␊ |
668 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
669 | ␉␉␉timeout = 0;␊ |
670 | ␉␉} else {␊ |
671 | ␉␉␉key = key & 0xFF;␊ |
672 | ␉␉␉␊ |
673 | ␉␉␉// Try booting hard disk if user pressed 'h'␊ |
674 | ␉␉␉if (biosDevIsCDROM(gBIOSDev) && key == 'h') {␊ |
675 | ␉␉␉␉BVRef bvr;␊ |
676 | ␉␉␉␉␊ |
677 | ␉␉␉␉// Look at partitions hosting OS X other than the CD-ROM␊ |
678 | ␉␉␉␉for (bvr = bvChain; bvr; bvr=bvr->next) {␊ |
679 | ␉␉␉␉␉if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) {␊ |
680 | ␉␉␉␉␉␉gBootVolume = bvr;␊ |
681 | ␉␉␉␉␉}␊ |
682 | ␉␉␉␉}␊ |
683 | ␉␉␉}␊ |
684 | ␉␉␉goto done;␊ |
685 | ␉␉}␊ |
686 | ␉}␊ |
687 | ␉␊ |
688 | ␉if (gBootMode & kBootModeQuiet) {␊ |
689 | ␉␉// No input allowed from user.␊ |
690 | ␉␉goto done;␊ |
691 | ␉}␊ |
692 | ␉␊ |
693 | ␉if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) {␊ |
694 | ␉␉// If the user is holding down a modifier key,␊ |
695 | ␉␉// enter safe mode.␊ |
696 | ␉␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
697 | ␉␉␉gBootMode |= kBootModeSafe;␊ |
698 | ␉␉}␊ |
699 | ␉␉goto done;␊ |
700 | ␉}␊ |
701 | ␉␊ |
702 | ␉if (gDeviceCount) {␊ |
703 | ␉␉// Allocate memory for an array of menu items.␊ |
704 | ␉␉menuItems = malloc(sizeof(MenuItem) * gDeviceCount);␊ |
705 | ␉␉if (menuItems == NULL) {␊ |
706 | ␉␉␉goto done;␊ |
707 | ␉␉}␊ |
708 | ␉␉␊ |
709 | ␉␉// Associate a menu item for each BVRef.␊ |
710 | ␉␉for (bvr=bvChain, i=gDeviceCount-1, selectIndex=0; bvr; bvr=bvr->next) {␊ |
711 | ␉␉␉if (bvr->visible) {␊ |
712 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true);␊ |
713 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
714 | ␉␉␉␉if (bvr == menuBVR) {␊ |
715 | ␉␉␉␉␉selectIndex = i;␊ |
716 | ␉␉␉␉}␊ |
717 | ␉␉␉␉i--;␊ |
718 | ␉␉␉}␊ |
719 | ␉␉}␊ |
720 | ␉}␊ |
721 | ␉␊ |
722 | ␉// Clear screen and hide the blinking cursor.␊ |
723 | ␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
724 | ␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
725 | ␉␊ |
726 | ␉nextRow = kMenuTopRow;␊ |
727 | ␉showPrompt = true;␊ |
728 | ␉␊ |
729 | ␉if (gDeviceCount) {␊ |
730 | ␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
731 | ␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
732 | ␉␉nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;␊ |
733 | ␉}␊ |
734 | ␉␊ |
735 | ␉// Show the boot prompt.␊ |
736 | ␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
737 | ␉showBootPrompt( nextRow, showPrompt );␊ |
738 | ␉␊ |
739 | ␉do {␊ |
740 | ␉␉key = getc();␊ |
741 | ␉␉updateMenu( key, (void **) &menuBVR );␊ |
742 | ␉␉newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
743 | ␉␉␊ |
744 | ␉␉if (newShowPrompt != showPrompt)␊ |
745 | ␉␉{␊ |
746 | ␉␉␉showPrompt = newShowPrompt;␊ |
747 | ␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
748 | ␉␉}␊ |
749 | ␉␉␊ |
750 | ␉␉if (showPrompt)␊ |
751 | ␉␉{␊ |
752 | ␉␉␉updateBootArgs(key);␊ |
753 | ␉␉}␊ |
754 | ␉␉␊ |
755 | ␉␉switch (key) {␊ |
756 | ␉␉␉case kReturnKey:␊ |
757 | ␉␉␉␉if (*gBootArgs == '?') {␊ |
758 | ␉␉␉␉␉char * argPtr = gBootArgs;␊ |
759 | ␉␉␉␉␉␊ |
760 | ␉␉␉␉␉// Skip the leading "?" character.␊ |
761 | ␉␉␉␉␉argPtr++;␊ |
762 | ␉␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
763 | ␉␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
764 | ␉␉␉␉␉␊ |
765 | ␉␉␉␉␉/*␊ |
766 | ␉␉␉␉␉ * TODO: this needs to be refactored.␊ |
767 | ␉␉␉␉␉ */␊ |
768 | #ifndef OPTION_ROM␊ |
769 | #if UNUSED␊ |
770 | ␉␉␉␉␉if (strcmp( booterCommand, "video" ) == 0)␊ |
771 | ␉␉␉␉␉{␊ |
772 | ␉␉␉␉␉␉printVBEModeInfo();␊ |
773 | ␉␉␉␉␉}␊ |
774 | ␉␉␉␉␉else␊ |
775 | #endif␊ |
776 | ␉␉␉␉␉if ( strcmp( booterCommand, "memory" ) == 0) ␊ |
777 | ␉␉␉␉␉{␊ |
778 | ␉␉␉␉␉␉printMemoryInfo();␊ |
779 | ␉␉␉␉␉}␊ |
780 | ␉␉␉␉␉else if (strcmp(booterCommand, "lspci") == 0) ␊ |
781 | ␉␉␉␉␉{␊ |
782 | ␉␉␉␉␉␉lspci();␊ |
783 | ␉␉␉␉␉} ␊ |
784 | ␉␉␉␉␉else if (strcmp(booterCommand, "more") == 0) ␊ |
785 | ␉␉␉␉␉{␊ |
786 | ␉␉␉␉␉␉showTextFile(booterParam);␊ |
787 | ␉␉␉␉␉}␊ |
788 | ␉␉␉␉␉else if (strcmp(booterCommand, "rd") == 0) ␊ |
789 | ␉␉␉␉␉{␊ |
790 | ␉␉␉␉␉␉if (execute_hook("processRAMDiskCommand", (void*)argPtr, &booterParam, NULL, NULL, NULL, NULL) != EFI_SUCCESS)␊ |
791 | ␉␉␉␉␉␉showMessage("ramdisk module not found, please install RamdiskLoader.dylib in /Extra/modules/");␊ |
792 | ␉␉␉␉␉} ␊ |
793 | ␉␉␉␉␉else if (strcmp(booterCommand, "norescan") == 0)␊ |
794 | ␉␉␉␉␉{␊ |
795 | ␉␉␉␉␉␉if (gEnableCDROMRescan)␊ |
796 | ␉␉␉␉␉␉{␊ |
797 | ␉␉␉␉␉␉␉gEnableCDROMRescan = false;␊ |
798 | ␉␉␉␉␉␉␉break;␊ |
799 | ␉␉␉␉␉␉}␊ |
800 | ␉␉␉␉␉}␊ |
801 | ␉␉␉␉␉else␊ |
802 | ␉␉␉␉␉{␊ |
803 | ␉␉␉␉␉␉showHelp();␊ |
804 | ␉␉␉␉␉}␊ |
805 | #endif␊ |
806 | ␉␉␉␉␉key = 0;␊ |
807 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
808 | ␉␉␉␉␉break;␊ |
809 | ␉␉␉␉}␊ |
810 | ␉␉␉␉gBootVolume = menuBVR;␊ |
811 | ␉␉␉␉setRootVolume(menuBVR);␊ |
812 | ␉␉␉␉gBIOSDev = menuBVR->biosdev;␊ |
813 | ␉␉␉␉break;␊ |
814 | ␉␉␉␉␊ |
815 | ␉␉␉case kEscapeKey:␊ |
816 | ␉␉␉␉clearBootArgs();␊ |
817 | ␉␉␉␉break;␊ |
818 | #ifndef OPTION_ROM␊ |
819 | ␉␉␉case kF5Key:␊ |
820 | ␉␉␉␉// New behavior:␊ |
821 | ␉␉␉␉// Clear gBootVolume to restart the loop␊ |
822 | ␉␉␉␉// if the user enabled rescanning the optical drive.␊ |
823 | ␉␉␉␉// Otherwise boot the default boot volume.␊ |
824 | ␉␉␉␉if (gEnableCDROMRescan) {␊ |
825 | ␉␉␉␉␉gBootVolume = NULL;␊ |
826 | ␉␉␉␉␉clearBootArgs();␊ |
827 | ␉␉␉␉}␊ |
828 | ␉␉␉␉break;␊ |
829 | ␉␉␉␉␊ |
830 | ␉␉␉case kF10Key:␊ |
831 | ␉␉␉␉gScanSingleDrive = false;␊ |
832 | #if UNUSED␊ |
833 | scanDisks(gBIOSDev, &bvCount);␊ |
834 | #else␊ |
835 | scanDisks();␊ |
836 | #endif␊ |
837 | ␉␉␉␉gBootVolume = NULL;␊ |
838 | ␉␉␉␉clearBootArgs();␊ |
839 | ␉␉␉␉break;␊ |
840 | #endif␊ |
841 | ␉␉␉default:␊ |
842 | ␉␉␉␉key = 0;␊ |
843 | ␉␉␉␉break;␊ |
844 | ␉␉}␊ |
845 | ␉} while (0 == key);␊ |
846 | ␉␊ |
847 | done:␊ |
848 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
849 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
850 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
851 | ␉}␊ |
852 | ␉shouldboot = false;␊ |
853 | ␉if (menuItems) {␊ |
854 | ␉␉free(menuItems);␊ |
855 | ␉␉menuItems = NULL;␊ |
856 | ␉}␊ |
857 | ␉return 0;␊ |
858 | }␊ |
859 | ␊ |
860 | //==========================================================================␊ |
861 | ␊ |
862 | extern unsigned char chainbootdev;␊ |
863 | extern unsigned char chainbootflag;␊ |
864 | ␊ |
865 | bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)␊ |
866 | {␊ |
867 | int argLen = argName ? strlen(argName) : 0;␊ |
868 | int len = argLen + cnt + 1; // +1 to account for space␊ |
869 | ␉␊ |
870 | if (len > *cntRemainingP) {␊ |
871 | error("Warning: boot arguments too long, truncating\n");␊ |
872 | return false;␊ |
873 | }␊ |
874 | ␉␊ |
875 | if (argName) {␊ |
876 | strncpy( *argP, argName, argLen );␊ |
877 | *argP += argLen;␊ |
878 | *argP[0] = '=';␊ |
879 | (*argP)++;␊ |
880 | len++; // +1 to account for '='␊ |
881 | }␊ |
882 | strncpy( *argP, val, cnt );␊ |
883 | *argP += cnt;␊ |
884 | *argP[0] = ' ';␊ |
885 | (*argP)++;␊ |
886 | ␉␊ |
887 | *cntRemainingP -= len;␊ |
888 | return true;␊ |
889 | }␊ |
890 | ␊ |
891 | int ArgCntRemaining;␊ |
892 | ␊ |
893 | int␊ |
894 | processBootOptions()␊ |
895 | {␊ |
896 | const char * cp = gBootArgs;␊ |
897 | const char * val = 0;␊ |
898 | const char * kernel;␊ |
899 | int cnt;␊ |
900 | int␉␉ userCnt;␊ |
901 | char * argP;␊ |
902 | char * configKernelFlags;␊ |
903 | ␊ |
904 | skipblanks( &cp );␊ |
905 | ␉␊ |
906 | // Update the unit and partition number.␊ |
907 | ␉␊ |
908 | if ( gBootVolume )␊ |
909 | {␊ |
910 | if (!( gBootVolume->flags & kBVFlagNativeBoot ))␊ |
911 | {␊ |
912 | readBootSector( gBootVolume->biosdev, gBootVolume->part_boff,␊ |
913 | ␉␉␉␉␉␉ (void *) 0x7c00 );␊ |
914 | ␉␉␉␊ |
915 | //␊ |
916 | // Setup edx, and signal intention to chain load the␊ |
917 | // foreign booter.␊ |
918 | //␊ |
919 | ␉␉␉␊ |
920 | chainbootdev = gBootVolume->biosdev;␊ |
921 | chainbootflag = 1;␊ |
922 | ␉␉␉␊ |
923 | return 1;␊ |
924 | }␊ |
925 | ␉␉␊ |
926 | setRootVolume(gBootVolume);␊ |
927 | ␉␉␊ |
928 | }␊ |
929 | // If no boot volume fail immediately because we're just going to fail␊ |
930 | // trying to load the config file anyway.␊ |
931 | else␊ |
932 | ␉␉return -1;␊ |
933 | ␉␊ |
934 | // Load config table specified by the user, or use the default.␊ |
935 | ␉␊ |
936 | if (!getValueForBootKey(cp, "config", &val, &cnt)) {␊ |
937 | ␉␉val = 0;␊ |
938 | ␉␉cnt = 0;␊ |
939 | }␊ |
940 | ␉␊ |
941 | // Load com.apple.Boot.plist from the selected volume␊ |
942 | // and use its contents to override default bootConfig.␊ |
943 | // This is not a mandatory opeartion anymore.␊ |
944 | ␉␊ |
945 | loadOverrideConfig(&bootInfo->overrideConfig);␊ |
946 | ␊ |
947 | // Load System com.apple.boot.plist config file␊ |
948 | ␉loadSystemConfig(&bootInfo->SystemConfig);␊ |
949 | ␊ |
950 | #if virtualM || PCI_FIX // we can simply make an option for this fix␊ |
951 | addBootArg("npci=0x2000");␊ |
952 | #endif␊ |
953 | ␊ |
954 | // Use the kernel name specified by the user, or fetch the name␊ |
955 | // in the config table, or use the default if not specified.␊ |
956 | // Specifying a kernel name on the command line, or specifying␊ |
957 | // a non-default kernel name in the config file counts as␊ |
958 | // overriding the kernel, which causes the kernelcache not␊ |
959 | // to be used.␊ |
960 | ␉␊ |
961 | gOverrideKernel = false;␊ |
962 | if (( kernel = extractKernelName((char **)&cp) )) { ␊ |
963 | ␉␉strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile)+1 );␊ |
964 | gOverrideKernel = true;␊ |
965 | } else {␊ |
966 | if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
967 | strlcpy( bootInfo->bootFile, val, cnt+1 );␊ |
968 | if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {␊ |
969 | gOverrideKernel = true;␊ |
970 | }␊ |
971 | } else {␊ |
972 | ␉␉␉strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile)+1 );␊ |
973 | }␊ |
974 | }␊ |
975 | ␉␊ |
976 | ArgCntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space␊ |
977 | argP = bootArgs->CommandLine;␊ |
978 | ␉␊ |
979 | // Get config table kernel flags, if not ignored.␊ |
980 | if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||␊ |
981 | ␉␉!getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) {␊ |
982 | val = "";␊ |
983 | cnt = 0;␊ |
984 | }␊ |
985 | ␉␊ |
986 | configKernelFlags = malloc(cnt + 1);␊ |
987 | strlcpy(configKernelFlags, val, cnt + 1);␊ |
988 | ␉␊ |
989 | ␉␊ |
990 | if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&␊ |
991 | !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) {␊ |
992 | if (gBootMode & kBootModeSafe) {␊ |
993 | copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &ArgCntRemaining);␊ |
994 | }␊ |
995 | }␊ |
996 | ␉␊ |
997 | // Store the merged kernel flags and boot args.␊ |
998 | ␉␊ |
999 | cnt = strlen(configKernelFlags);␊ |
1000 | if (cnt) {␊ |
1001 | if (cnt > ArgCntRemaining) {␊ |
1002 | error("Warning: boot arguments too long, truncating\n");␊ |
1003 | cnt = ArgCntRemaining;␊ |
1004 | }␊ |
1005 | strncpy(argP, configKernelFlags, cnt);␊ |
1006 | argP[cnt++] = ' ';␊ |
1007 | ArgCntRemaining -= cnt;␊ |
1008 | }␊ |
1009 | userCnt = strlen(cp);␊ |
1010 | if (userCnt > ArgCntRemaining) {␊ |
1011 | ␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1012 | ␉␉userCnt = ArgCntRemaining;␊ |
1013 | }␊ |
1014 | strncpy(&argP[cnt], cp, userCnt);␊ |
1015 | argP[cnt+userCnt] = '\0';␊ |
1016 | ␉␊ |
1017 | ␉if(!shouldboot)␊ |
1018 | ␉{␊ |
1019 | ␉␉gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->bootConfig ) ||␊ |
1020 | ␉␉getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->bootConfig );␊ |
1021 | ␉␉␊ |
1022 | ␉␉gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->bootConfig ) ) ?␊ |
1023 | ␉␉kBootModeSafe : kBootModeNormal;␊ |
1024 | ␉␉␊ |
1025 | if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1026 | gBootMode = kBootModeSafe;␊ |
1027 | ␉␉}␊ |
1028 | ␉}␊ |
1029 | ␉␊ |
1030 | ␉if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )␊ |
1031 | ␉{␊ |
1032 | ␉␉strlcpy(gMKextName, val, cnt + 1);␊ |
1033 | ␉}␊ |
1034 | ␉␊ |
1035 | free(configKernelFlags);␊ |
1036 | ␉␊ |
1037 | return 0;␊ |
1038 | }␊ |
1039 | ␊ |
1040 | #ifndef OPTION_ROM␊ |
1041 | ␊ |
1042 | //==========================================================================␊ |
1043 | // Load the help file and display the file contents on the screen.␊ |
1044 | ␊ |
1045 | void showTextBuffer(char *buf, int size)␊ |
1046 | {␊ |
1047 | ␉char␉*bp;␊ |
1048 | ␉int␉line;␊ |
1049 | ␉int␉line_offset;␊ |
1050 | ␉int␉c;␊ |
1051 | ␉␊ |
1052 | ␉␊ |
1053 | ␉bp = buf;␊ |
1054 | ␉while (size-- > 0) {␊ |
1055 | ␉␉if (*bp == '\n') {␊ |
1056 | ␉␉␉*bp = '\0';␊ |
1057 | ␉␉}␊ |
1058 | ␉␉bp++;␊ |
1059 | ␉}␊ |
1060 | ␉*bp = '\1';␊ |
1061 | ␉line_offset = 0;␊ |
1062 | ␉␊ |
1063 | ␉setActiveDisplayPage(1);␊ |
1064 | ␉␊ |
1065 | ␉while (1) {␊ |
1066 | ␉␉clearScreenRows(0, 24);␊ |
1067 | ␉␉setCursorPosition(0, 0, 1);␊ |
1068 | ␉␉bp = buf;␊ |
1069 | ␉␉for (line = 0; *bp != '\1' && line < line_offset; line++) {␊ |
1070 | ␉␉␉while (*bp != '\0') {␊ |
1071 | ␉␉␉␉bp++;␊ |
1072 | ␉␉␉}␊ |
1073 | ␉␉␉bp++;␊ |
1074 | ␉␉}␊ |
1075 | ␉␉for (line = 0; *bp != '\1' && line < 23; line++) {␊ |
1076 | ␉␉␉setCursorPosition(0, line, 1);␊ |
1077 | ␉␉␉printf("%s\n", bp);␊ |
1078 | ␉␉␉while (*bp != '\0') {␊ |
1079 | ␉␉␉␉bp++;␊ |
1080 | ␉␉␉}␊ |
1081 | ␉␉␉bp++;␊ |
1082 | ␉␉}␊ |
1083 | ␉␉␊ |
1084 | ␉␉setCursorPosition(0, 23, 1);␊ |
1085 | ␉␉if (*bp == '\1') {␊ |
1086 | ␉␉␉printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : "");␊ |
1087 | ␉␉} else {␊ |
1088 | ␉␉␉printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : "");␊ |
1089 | ␉␉}␊ |
1090 | ␉␉␊ |
1091 | ␉␉c = getc();␊ |
1092 | ␉␉if (c == 'q' || c == 'Q') {␊ |
1093 | ␉␉␉break;␊ |
1094 | ␉␉}␊ |
1095 | ␉␉if ((c == 'p' || c == 'P') && line_offset > 0) {␊ |
1096 | ␉␉␉line_offset -= 23;␊ |
1097 | ␉␉}␊ |
1098 | ␉␉if (c == ' ') {␊ |
1099 | ␉␉␉if (*bp == '\1') {␊ |
1100 | ␉␉␉␉break;␊ |
1101 | ␉␉␉} else {␊ |
1102 | ␉␉␉␉line_offset += 23;␊ |
1103 | ␉␉␉}␊ |
1104 | ␉␉}␊ |
1105 | ␉}␊ |
1106 | ␉setActiveDisplayPage(0);␊ |
1107 | }␊ |
1108 | ␊ |
1109 | void showHelp(void)␊ |
1110 | {␊ |
1111 | #if EMBED_HELP==0␊ |
1112 | ␉int fd = -1;␊ |
1113 | ␉char dirspec[512];␊ |
1114 | ␉char filename[512];␊ |
1115 | ␉sprintf(filename, "BootHelp.txt");␊ |
1116 | ␉␊ |
1117 | ␉␉// Check Extra on booting partition␊ |
1118 | ␉␉sprintf(dirspec,"/Extra/%s",filename);␊ |
1119 | ␉␉fd=open (dirspec);␊ |
1120 | ␉␉if (fd<0)␊ |
1121 | ␉␉{␉// Fall back to booter partition␊ |
1122 | ␉␉␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
1123 | ␉␉␉fd=open (dirspec);␊ |
1124 | ␉␉␉if (fd<0)␊ |
1125 | ␉␉␉{␊ |
1126 | ␉␉␉␉printf("BootHelp not found: %s\n", filename);␊ |
1127 | ␉␉␉␉return;␊ |
1128 | ␉␉␉}␊ |
1129 | ␉␉}␊ |
1130 | ␉int BootHelp_txt_len = file_size (fd);␊ |
1131 | ␉void *BootHelp_txt=malloc(BootHelp_txt_len);␊ |
1132 | ␉if (BootHelp_txt)␊ |
1133 | ␉{␊ |
1134 | ␉␉if (read (fd, BootHelp_txt, BootHelp_txt_len)!=BootHelp_txt_len)␊ |
1135 | ␉␉{␊ |
1136 | ␉␉␉printf("Couldn't read BootHelp %s\n",dirspec);␊ |
1137 | ␉␉␉free (BootHelp_txt);␊ |
1138 | ␉␉␉close (fd);␊ |
1139 | ␉␉␉return;␊ |
1140 | ␉␉}␊ |
1141 | ␉␉␉␉␊ |
1142 | ␉␉close (fd);␉␉␊ |
1143 | ␉}␊ |
1144 | #endif␊ |
1145 | ␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1146 | }␊ |
1147 | ␊ |
1148 | void showMessage(char * message)␊ |
1149 | {␊ |
1150 | ␉showTextBuffer(message, strlen(message));␊ |
1151 | }␊ |
1152 | ␊ |
1153 | void showTextFile(const char * filename)␊ |
1154 | {␊ |
1155 | #define MAX_TEXT_FILE_SIZE 65536␊ |
1156 | ␉char␉*buf;␊ |
1157 | ␉int␉fd;␊ |
1158 | ␉int␉size;␊ |
1159 | ␉␊ |
1160 | ␉if ((fd = open_bvdev("bt(0,0)", filename)) < 0) {␊ |
1161 | ␉␉printf("\nFile not found: %s\n", filename);␊ |
1162 | ␉␉sleep(2);␊ |
1163 | ␉␉return;␊ |
1164 | ␉}␊ |
1165 | ␉␊ |
1166 | ␉size = file_size(fd);␊ |
1167 | ␉if (size > MAX_TEXT_FILE_SIZE) {␊ |
1168 | ␉␉size = MAX_TEXT_FILE_SIZE;␊ |
1169 | ␉}␊ |
1170 | ␉buf = malloc(size);␊ |
1171 | ␉read(fd, buf, size);␊ |
1172 | ␉close(fd);␊ |
1173 | ␉showTextBuffer(buf, size);␊ |
1174 | ␉free(buf);␊ |
1175 | }␊ |
1176 | #endif␊ |
1177 | ␊ |
1178 | #ifndef OPTION_ROM␊ |
1179 | bool promptForRescanOption(void)␊ |
1180 | {␊ |
1181 | ␉printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");␊ |
1182 | ␉if (getc() == kReturnKey) {␊ |
1183 | ␉␉return true;␊ |
1184 | ␉} else {␊ |
1185 | ␉␉return false;␊ |
1186 | ␉}␊ |
1187 | }␊ |
1188 | #endif␊ |
1189 | |