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