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