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 | 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 | ␉}␊ |
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 | int 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 | int 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 | #ifndef OPTION_ROM␊ |
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) == 0)␊ |
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 | ␉␉␉␉scanDisks(gBIOSDev, &bvCount);␊ |
833 | ␉␉␉␉gBootVolume = NULL;␊ |
834 | ␉␉␉␉clearBootArgs();␊ |
835 | ␉␉␉␉break;␊ |
836 | #endif␊ |
837 | ␉␉␉default:␊ |
838 | ␉␉␉␉key = 0;␊ |
839 | ␉␉␉␉break;␊ |
840 | ␉␉}␊ |
841 | ␉} while (0 == key);␊ |
842 | ␉␊ |
843 | done:␊ |
844 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
845 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
846 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
847 | ␉}␊ |
848 | ␉shouldboot = false;␊ |
849 | ␉if (menuItems) {␊ |
850 | ␉␉free(menuItems);␊ |
851 | ␉␉menuItems = NULL;␊ |
852 | ␉}␊ |
853 | ␉return 0;␊ |
854 | }␊ |
855 | ␊ |
856 | //==========================================================================␊ |
857 | ␊ |
858 | extern unsigned char chainbootdev;␊ |
859 | extern unsigned char chainbootflag;␊ |
860 | ␊ |
861 | bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)␊ |
862 | {␊ |
863 | int argLen = argName ? strlen(argName) : 0;␊ |
864 | int len = argLen + cnt + 1; // +1 to account for space␊ |
865 | ␉␊ |
866 | if (len > *cntRemainingP) {␊ |
867 | error("Warning: boot arguments too long, truncating\n");␊ |
868 | return false;␊ |
869 | }␊ |
870 | ␉␊ |
871 | if (argName) {␊ |
872 | strncpy( *argP, argName, argLen );␊ |
873 | *argP += argLen;␊ |
874 | *argP[0] = '=';␊ |
875 | (*argP)++;␊ |
876 | len++; // +1 to account for '='␊ |
877 | }␊ |
878 | strncpy( *argP, val, cnt );␊ |
879 | *argP += cnt;␊ |
880 | *argP[0] = ' ';␊ |
881 | (*argP)++;␊ |
882 | ␉␊ |
883 | *cntRemainingP -= len;␊ |
884 | return true;␊ |
885 | }␊ |
886 | ␊ |
887 | int ArgCntRemaining;␊ |
888 | ␊ |
889 | int␊ |
890 | processBootOptions()␊ |
891 | {␊ |
892 | const char * cp = gBootArgs;␊ |
893 | const char * val = 0;␊ |
894 | const char * kernel;␊ |
895 | int cnt;␊ |
896 | int␉␉ userCnt;␊ |
897 | char * argP;␊ |
898 | char * configKernelFlags;␊ |
899 | ␊ |
900 | skipblanks( &cp );␊ |
901 | ␉␊ |
902 | // Update the unit and partition number.␊ |
903 | ␉␊ |
904 | if ( gBootVolume )␊ |
905 | {␊ |
906 | if (!( gBootVolume->flags & kBVFlagNativeBoot ))␊ |
907 | {␊ |
908 | readBootSector( gBootVolume->biosdev, gBootVolume->part_boff,␊ |
909 | ␉␉␉␉␉␉ (void *) 0x7c00 );␊ |
910 | ␉␉␉␊ |
911 | //␊ |
912 | // Setup edx, and signal intention to chain load the␊ |
913 | // foreign booter.␊ |
914 | //␊ |
915 | ␉␉␉␊ |
916 | chainbootdev = gBootVolume->biosdev;␊ |
917 | chainbootflag = 1;␊ |
918 | ␉␉␉␊ |
919 | return 1;␊ |
920 | }␊ |
921 | ␉␉␊ |
922 | setRootVolume(gBootVolume);␊ |
923 | ␉␉␊ |
924 | }␊ |
925 | // If no boot volume fail immediately because we're just going to fail␊ |
926 | // trying to load the config file anyway.␊ |
927 | else␊ |
928 | ␉␉return -1;␊ |
929 | ␉␊ |
930 | // Load config table specified by the user, or use the default.␊ |
931 | ␉␊ |
932 | if (!getValueForBootKey(cp, "config", &val, &cnt)) {␊ |
933 | ␉␉val = 0;␊ |
934 | ␉␉cnt = 0;␊ |
935 | }␊ |
936 | ␉␊ |
937 | // Load com.apple.Boot.plist from the selected volume␊ |
938 | // and use its contents to override default bootConfig.␊ |
939 | // This is not a mandatory opeartion anymore.␊ |
940 | ␉␊ |
941 | loadOverrideConfig(&bootInfo->overrideConfig);␊ |
942 | ␉␊ |
943 | // Use the kernel name specified by the user, or fetch the name␊ |
944 | // in the config table, or use the default if not specified.␊ |
945 | // Specifying a kernel name on the command line, or specifying␊ |
946 | // a non-default kernel name in the config file counts as␊ |
947 | // overriding the kernel, which causes the kernelcache not␊ |
948 | // to be used.␊ |
949 | ␉␊ |
950 | gOverrideKernel = false;␊ |
951 | if (( kernel = extractKernelName((char **)&cp) )) {␊ |
952 | strcpy( bootInfo->bootFile, kernel );␊ |
953 | gOverrideKernel = true;␊ |
954 | } else {␊ |
955 | if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
956 | strlcpy( bootInfo->bootFile, val, cnt+1 );␊ |
957 | if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {␊ |
958 | gOverrideKernel = true;␊ |
959 | }␊ |
960 | } else {␊ |
961 | strcpy( bootInfo->bootFile, kDefaultKernel );␊ |
962 | }␊ |
963 | }␊ |
964 | ␉␊ |
965 | ArgCntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space␊ |
966 | argP = bootArgs->CommandLine;␊ |
967 | ␉␊ |
968 | // Get config table kernel flags, if not ignored.␊ |
969 | if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||␊ |
970 | ␉␉!getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) {␊ |
971 | val = "";␊ |
972 | cnt = 0;␊ |
973 | }␊ |
974 | ␉␊ |
975 | configKernelFlags = malloc(cnt + 1);␊ |
976 | strlcpy(configKernelFlags, val, cnt + 1);␊ |
977 | ␉␊ |
978 | ␉␊ |
979 | if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&␊ |
980 | !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) {␊ |
981 | if (gBootMode & kBootModeSafe) {␊ |
982 | copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &ArgCntRemaining);␊ |
983 | }␊ |
984 | }␊ |
985 | ␉␊ |
986 | // Store the merged kernel flags and boot args.␊ |
987 | ␉␊ |
988 | cnt = strlen(configKernelFlags);␊ |
989 | if (cnt) {␊ |
990 | if (cnt > ArgCntRemaining) {␊ |
991 | error("Warning: boot arguments too long, truncating\n");␊ |
992 | cnt = ArgCntRemaining;␊ |
993 | }␊ |
994 | strncpy(argP, configKernelFlags, cnt);␊ |
995 | argP[cnt++] = ' ';␊ |
996 | ArgCntRemaining -= cnt;␊ |
997 | }␊ |
998 | userCnt = strlen(cp);␊ |
999 | if (userCnt > ArgCntRemaining) {␊ |
1000 | ␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1001 | ␉␉userCnt = ArgCntRemaining;␊ |
1002 | }␊ |
1003 | strncpy(&argP[cnt], cp, userCnt);␊ |
1004 | argP[cnt+userCnt] = '\0';␊ |
1005 | ␉␊ |
1006 | ␉if(!shouldboot)␊ |
1007 | ␉{␊ |
1008 | ␉␉gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->bootConfig ) ||␊ |
1009 | ␉␉getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->bootConfig );␊ |
1010 | ␉␉␊ |
1011 | ␉␉gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->bootConfig ) ) ?␊ |
1012 | ␉␉kBootModeSafe : kBootModeNormal;␊ |
1013 | ␉␉␊ |
1014 | if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1015 | gBootMode = kBootModeSafe;␊ |
1016 | ␉␉}␊ |
1017 | ␉}␊ |
1018 | ␉␊ |
1019 | ␉if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )␊ |
1020 | ␉{␊ |
1021 | ␉␉strlcpy(gMKextName, val, cnt + 1);␊ |
1022 | ␉}␊ |
1023 | ␉␊ |
1024 | free(configKernelFlags);␊ |
1025 | ␉␊ |
1026 | return 0;␊ |
1027 | }␊ |
1028 | ␊ |
1029 | #ifndef OPTION_ROM␊ |
1030 | ␊ |
1031 | //==========================================================================␊ |
1032 | // Load the help file and display the file contents on the screen.␊ |
1033 | ␊ |
1034 | void showTextBuffer(char *buf, int size)␊ |
1035 | {␊ |
1036 | ␉char␉*bp;␊ |
1037 | ␉int␉line;␊ |
1038 | ␉int␉line_offset;␊ |
1039 | ␉int␉c;␊ |
1040 | ␉␊ |
1041 | ␉␊ |
1042 | ␉bp = buf;␊ |
1043 | ␉while (size-- > 0) {␊ |
1044 | ␉␉if (*bp == '\n') {␊ |
1045 | ␉␉␉*bp = '\0';␊ |
1046 | ␉␉}␊ |
1047 | ␉␉bp++;␊ |
1048 | ␉}␊ |
1049 | ␉*bp = '\1';␊ |
1050 | ␉line_offset = 0;␊ |
1051 | ␉␊ |
1052 | ␉setActiveDisplayPage(1);␊ |
1053 | ␉␊ |
1054 | ␉while (1) {␊ |
1055 | ␉␉clearScreenRows(0, 24);␊ |
1056 | ␉␉setCursorPosition(0, 0, 1);␊ |
1057 | ␉␉bp = buf;␊ |
1058 | ␉␉for (line = 0; *bp != '\1' && line < line_offset; line++) {␊ |
1059 | ␉␉␉while (*bp != '\0') {␊ |
1060 | ␉␉␉␉bp++;␊ |
1061 | ␉␉␉}␊ |
1062 | ␉␉␉bp++;␊ |
1063 | ␉␉}␊ |
1064 | ␉␉for (line = 0; *bp != '\1' && line < 23; line++) {␊ |
1065 | ␉␉␉setCursorPosition(0, line, 1);␊ |
1066 | ␉␉␉printf("%s\n", bp);␊ |
1067 | ␉␉␉while (*bp != '\0') {␊ |
1068 | ␉␉␉␉bp++;␊ |
1069 | ␉␉␉}␊ |
1070 | ␉␉␉bp++;␊ |
1071 | ␉␉}␊ |
1072 | ␉␉␊ |
1073 | ␉␉setCursorPosition(0, 23, 1);␊ |
1074 | ␉␉if (*bp == '\1') {␊ |
1075 | ␉␉␉printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : "");␊ |
1076 | ␉␉} else {␊ |
1077 | ␉␉␉printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : "");␊ |
1078 | ␉␉}␊ |
1079 | ␉␉␊ |
1080 | ␉␉c = getc();␊ |
1081 | ␉␉if (c == 'q' || c == 'Q') {␊ |
1082 | ␉␉␉break;␊ |
1083 | ␉␉}␊ |
1084 | ␉␉if ((c == 'p' || c == 'P') && line_offset > 0) {␊ |
1085 | ␉␉␉line_offset -= 23;␊ |
1086 | ␉␉}␊ |
1087 | ␉␉if (c == ' ') {␊ |
1088 | ␉␉␉if (*bp == '\1') {␊ |
1089 | ␉␉␉␉break;␊ |
1090 | ␉␉␉} else {␊ |
1091 | ␉␉␉␉line_offset += 23;␊ |
1092 | ␉␉␉}␊ |
1093 | ␉␉}␊ |
1094 | ␉}␊ |
1095 | ␉setActiveDisplayPage(0);␊ |
1096 | }␊ |
1097 | ␊ |
1098 | void showHelp(void)␊ |
1099 | {␊ |
1100 | #if EMBED_HELP==0␊ |
1101 | ␉int fd = -1;␊ |
1102 | ␉char dirspec[512];␊ |
1103 | ␉char filename[512];␊ |
1104 | ␉sprintf(filename, "BootHelp.txt");␊ |
1105 | ␉␊ |
1106 | ␉␉// Check Extra on booting partition␊ |
1107 | ␉␉sprintf(dirspec,"/Extra/%s",filename);␊ |
1108 | ␉␉fd=open (dirspec,0);␊ |
1109 | ␉␉if (fd<0)␊ |
1110 | ␉␉{␉// Fall back to booter partition␊ |
1111 | ␉␉␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
1112 | ␉␉␉fd=open (dirspec,0);␊ |
1113 | ␉␉␉if (fd<0)␊ |
1114 | ␉␉␉{␊ |
1115 | ␉␉␉␉printf("BootHelp not found: %s\n", filename);␊ |
1116 | ␉␉␉␉return;␊ |
1117 | ␉␉␉}␊ |
1118 | ␉␉}␊ |
1119 | ␉int BootHelp_txt_len = file_size (fd);␊ |
1120 | ␉void *BootHelp_txt=malloc(BootHelp_txt_len);␊ |
1121 | ␉if (BootHelp_txt)␊ |
1122 | ␉{␊ |
1123 | ␉␉if (read (fd, BootHelp_txt, BootHelp_txt_len)!=BootHelp_txt_len)␊ |
1124 | ␉␉{␊ |
1125 | ␉␉␉printf("Couldn't read BootHelp %s\n",dirspec);␊ |
1126 | ␉␉␉free (BootHelp_txt);␊ |
1127 | ␉␉␉close (fd);␊ |
1128 | ␉␉␉return;␊ |
1129 | ␉␉}␊ |
1130 | ␉␉␉␉␊ |
1131 | ␉␉close (fd);␉␉␊ |
1132 | ␉}␊ |
1133 | #endif␊ |
1134 | ␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1135 | }␊ |
1136 | ␊ |
1137 | void showMessage(char * message)␊ |
1138 | {␊ |
1139 | ␉showTextBuffer(message, strlen(message));␊ |
1140 | }␊ |
1141 | ␊ |
1142 | void showTextFile(const char * filename)␊ |
1143 | {␊ |
1144 | #define MAX_TEXT_FILE_SIZE 65536␊ |
1145 | ␉char␉*buf;␊ |
1146 | ␉int␉fd;␊ |
1147 | ␉int␉size;␊ |
1148 | ␉␊ |
1149 | ␉if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {␊ |
1150 | ␉␉printf("\nFile not found: %s\n", filename);␊ |
1151 | ␉␉sleep(2);␊ |
1152 | ␉␉return;␊ |
1153 | ␉}␊ |
1154 | ␉␊ |
1155 | ␉size = file_size(fd);␊ |
1156 | ␉if (size > MAX_TEXT_FILE_SIZE) {␊ |
1157 | ␉␉size = MAX_TEXT_FILE_SIZE;␊ |
1158 | ␉}␊ |
1159 | ␉buf = malloc(size);␊ |
1160 | ␉read(fd, buf, size);␊ |
1161 | ␉close(fd);␊ |
1162 | ␉showTextBuffer(buf, size);␊ |
1163 | ␉free(buf);␊ |
1164 | }␊ |
1165 | #endif␊ |
1166 | ␊ |
1167 | #ifndef OPTION_ROM␊ |
1168 | bool promptForRescanOption(void)␊ |
1169 | {␊ |
1170 | ␉printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");␊ |
1171 | ␉if (getc() == kReturnKey) {␊ |
1172 | ␉␉return true;␊ |
1173 | ␉} else {␊ |
1174 | ␉␉return false;␊ |
1175 | ␉}␊ |
1176 | }␊ |
1177 | #endif␊ |
1178 | |