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