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