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 "fdisk.h"␊ |
28 | #include "ramdisk.h"␊ |
29 | #include "gui.h"␊ |
30 | #include "embedded.h"␊ |
31 | #include "pci.h"␊ |
32 | #include "autoresolution.h" //Azi:autoresolution␊ |
33 | ␊ |
34 | ␊ |
35 | bool showBootBanner = true; //Azi:showinfo␊ |
36 | static bool shouldboot = false;␊ |
37 | ␊ |
38 | extern int multiboot_timeout;␊ |
39 | extern int multiboot_timeout_set;␊ |
40 | ␊ |
41 | extern BVRef bvChain;␊ |
42 | //extern int␉␉menucount;␊ |
43 | ␊ |
44 | extern int␉␉gDeviceCount;␊ |
45 | ␊ |
46 | int␉␉␉selectIndex = 0;␊ |
47 | MenuItem * menuItems = NULL;␊ |
48 | ␊ |
49 | enum {␊ |
50 | kMenuTopRow = 5,␊ |
51 | kMenuMaxItems = 10,␊ |
52 | kScreenLastRow = 24␊ |
53 | };␊ |
54 | ␊ |
55 | //==========================================================================␊ |
56 | ␊ |
57 | typedef struct {␊ |
58 | int x;␊ |
59 | int y;␊ |
60 | int type;␊ |
61 | } CursorState;␊ |
62 | ␊ |
63 | static void changeCursor( int col, int row, int type, CursorState * cs )␊ |
64 | {␊ |
65 | if (cs) getCursorPositionAndType( &cs->x, &cs->y, &cs->type );␊ |
66 | setCursorType( type );␊ |
67 | setCursorPosition( col, row, 0 );␊ |
68 | }␊ |
69 | ␊ |
70 | static void moveCursor( int col, int row )␊ |
71 | {␊ |
72 | setCursorPosition( col, row, 0 );␊ |
73 | }␊ |
74 | ␊ |
75 | static void restoreCursor( const CursorState * cs )␊ |
76 | {␊ |
77 | setCursorPosition( cs->x, cs->y, 0 );␊ |
78 | setCursorType( cs->type );␊ |
79 | }␊ |
80 | ␊ |
81 | //==========================================================================␊ |
82 | ␊ |
83 | /* Flush keyboard buffer; returns TRUE if any of the flushed␊ |
84 | * characters was F8.␊ |
85 | */␊ |
86 | ␊ |
87 | static bool flushKeyboardBuffer(void)␊ |
88 | {␊ |
89 | bool status = false;␊ |
90 | ␊ |
91 | while ( readKeyboardStatus() ) {␊ |
92 | if (bgetc() == 0x4200) status = true;␊ |
93 | }␊ |
94 | return status;␊ |
95 | }␊ |
96 | ␊ |
97 | //==========================================================================␊ |
98 | ␊ |
99 | static int countdown( const char * msg, int row, int timeout )␊ |
100 | {␊ |
101 | unsigned long time;␊ |
102 | int ch = 0;␊ |
103 | int col = strlen(msg) + 1;␊ |
104 | ␉␊ |
105 | flushKeyboardBuffer();␊ |
106 | ␊ |
107 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
108 | ␉{␊ |
109 | ␉␉moveCursor( 0, row );␊ |
110 | ␉␉printf(msg);␊ |
111 | ␊ |
112 | ␉} else {␊ |
113 | ␊ |
114 | ␉␉position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );␊ |
115 | ␉␊ |
116 | ␉␉char dummy[80];␊ |
117 | ␉␉getBootVolumeDescription( gBootVolume, dummy, sizeof(dummy) - 1, true );␊ |
118 | ␉␉drawDeviceIcon( gBootVolume, gui.screen.pixmap, p, true );␊ |
119 | ␉␉drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );␊ |
120 | ␉␉␊ |
121 | ␉␉// make this screen the new background␊ |
122 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
123 | ␉␉␊ |
124 | ␉}␊ |
125 | ␊ |
126 | ␉int multi_buff = 18 * (timeout);␊ |
127 | int multi = ++multi_buff;␊ |
128 | ␊ |
129 | int lasttime=0;␊ |
130 | ␊ |
131 | for ( time = time18(), timeout++; timeout > 0; )␊ |
132 | {␊ |
133 | ␉␉if( time18() > lasttime)␊ |
134 | ␉␉{␊ |
135 | ␉␉␉multi--; ␊ |
136 | ␉␉␉lasttime=time18();␊ |
137 | ␉␉}␉␉␊ |
138 | ␊ |
139 | if (ch = readKeyboardStatus())␊ |
140 | break;␊ |
141 | ␊ |
142 | // Count can be interrupted by holding down shift,␊ |
143 | // control or alt key␊ |
144 | if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 )␊ |
145 | ␉␉{␊ |
146 | ch = 1;␊ |
147 | break;␊ |
148 | }␊ |
149 | ␊ |
150 | if ( time18() >= time )␊ |
151 | {␊ |
152 | time += 18;␊ |
153 | timeout--;␊ |
154 | ␊ |
155 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
156 | ␉␉␉{␊ |
157 | ␉␉␉␉moveCursor( col, row );␊ |
158 | ␉␉␉␉printf("(%d) ", timeout);␊ |
159 | ␉␉␉}␊ |
160 | }␊ |
161 | ␉␊ |
162 | ␉␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
163 | ␉␉{␊ |
164 | ␉␉␉drawProgressBar( gui.screen.pixmap, 100, gui.progressbar.pos , ( multi * 100 / multi_buff ) );␊ |
165 | ␉␉␉gui.redraw = true;␊ |
166 | ␉␉␉updateVRAM();␊ |
167 | ␉␉}␊ |
168 | ␊ |
169 | }␊ |
170 | ␊ |
171 | flushKeyboardBuffer();␊ |
172 | ␊ |
173 | return ch;␊ |
174 | }␊ |
175 | ␊ |
176 | //==========================================================================␊ |
177 | ␊ |
178 | char gBootArgs[BOOT_STRING_LEN];␊ |
179 | static char * gBootArgsPtr = gBootArgs;␊ |
180 | static char * gBootArgsEnd = gBootArgs + BOOT_STRING_LEN - 1;␊ |
181 | static char booterCommand[BOOT_STRING_LEN];␊ |
182 | static char booterParam[BOOT_STRING_LEN];␊ |
183 | ␊ |
184 | static void clearBootArgs(void)␊ |
185 | {␊ |
186 | ␉gBootArgsPtr = gBootArgs;␊ |
187 | ␉memset(gBootArgs, '\0', BOOT_STRING_LEN);␊ |
188 | ␊ |
189 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
190 | ␉␉clearGraphicBootPrompt();␊ |
191 | ␉}␊ |
192 | }␊ |
193 | ␊ |
194 | static void addBootArg(const char * argStr)␊ |
195 | {␊ |
196 | ␉if ( (gBootArgsPtr + strlen(argStr) + 1) < gBootArgsEnd)␊ |
197 | ␉{␊ |
198 | ␉␉*gBootArgsPtr++ = ' ';␊ |
199 | ␉␉strcat(gBootArgs, argStr);␊ |
200 | ␉␉gBootArgsPtr += strlen(argStr);␊ |
201 | ␉}␊ |
202 | }␊ |
203 | ␊ |
204 | //==========================================================================␊ |
205 | ␊ |
206 | static void showBootPrompt(int row, bool visible)␊ |
207 | {␊ |
208 | ␉extern char bootPrompt[];␊ |
209 | ␉extern char bootRescanPrompt[];␊ |
210 | ␊ |
211 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
212 | ␉␉changeCursor( 0, row, kCursorTypeUnderline, 0 ); ␊ |
213 | ␉␉clearScreenRows( row, kScreenLastRow );␊ |
214 | ␉}␊ |
215 | ␊ |
216 | ␉//clearBootArgs();␊ |
217 | ␊ |
218 | ␉if (visible) {␊ |
219 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
220 | ␉␉␉if (gEnableCDROMRescan) {␊ |
221 | ␉␉␉␉printf( bootRescanPrompt );␊ |
222 | ␉␉␉} else {␊ |
223 | ␉␉␉␉printf( bootPrompt );␊ |
224 | printf( gBootArgs );␊ |
225 | ␉␉␉}␊ |
226 | ␉␉}␊ |
227 | ␉} else {␊ |
228 | ␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
229 | //␉␉␉clearGraphicBootPrompt();␊ |
230 | ␉␉} else {␊ |
231 | ␉␉␉printf("Press Enter to start up the foreign OS. ");␊ |
232 | ␉␉}␊ |
233 | ␉}␊ |
234 | }␊ |
235 | ␊ |
236 | //==========================================================================␊ |
237 | ␊ |
238 | static void updateBootArgs( int key )␊ |
239 | {␊ |
240 | key &= kASCIIKeyMask;␊ |
241 | ␊ |
242 | switch ( key )␊ |
243 | {␊ |
244 | case kBackspaceKey:␊ |
245 | if ( gBootArgsPtr > gBootArgs )␊ |
246 | {␊ |
247 | *--gBootArgsPtr = '\0';␊ |
248 | ␊ |
249 | int x, y, t;␊ |
250 | getCursorPositionAndType( &x, &y, &t );␊ |
251 | if ( x == 0 && y )␊ |
252 | {␊ |
253 | x = 80; y--;␊ |
254 | }␊ |
255 | if (x) x--;␊ |
256 | ␊ |
257 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
258 | ␉␉␉␉{␊ |
259 | ␉␉␉␉␉setCursorPosition( x, y, 0 );␊ |
260 | ␉␉␉␉␉putca(' ', 0x07, 1);␊ |
261 | ␉␉␉␉}␊ |
262 | else␊ |
263 | {␊ |
264 | updateGraphicBootPrompt();␊ |
265 | }␊ |
266 | } ␊ |
267 | ␉␉␉break;␊ |
268 | ␊ |
269 | default:␊ |
270 | if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
271 | {␊ |
272 | *gBootArgsPtr++ = key;␊ |
273 | ␊ |
274 | if( bootArgs->Video.v_display != VGA_TEXT_MODE ) updateGraphicBootPrompt();␊ |
275 | else if ( key >= ' ' && key < 0x7f) putchar(key);␊ |
276 | ␉␉␉}␊ |
277 | ␊ |
278 | ␉␉␉break;␊ |
279 | }␊ |
280 | }␊ |
281 | ␊ |
282 | //==========================================================================␊ |
283 | ␊ |
284 | static const MenuItem * gMenuItems = NULL;␊ |
285 | ␊ |
286 | static int gMenuItemCount;␊ |
287 | static int gMenuRow;␊ |
288 | static int gMenuHeight;␊ |
289 | static int gMenuTop;␊ |
290 | static int gMenuBottom;␊ |
291 | static int gMenuSelection;␊ |
292 | ␊ |
293 | static int␉ gMenuStart;␊ |
294 | static int␉ gMenuEnd;␊ |
295 | ␊ |
296 | static void printMenuItem( const MenuItem * item, int highlight )␊ |
297 | {␊ |
298 | printf(" ");␊ |
299 | ␊ |
300 | if ( highlight )␊ |
301 | putca(' ', 0x70, strlen(item->name) + 4);␊ |
302 | else␊ |
303 | putca(' ', 0x07, 40);␊ |
304 | ␊ |
305 | printf(" %40s\n", item->name);␊ |
306 | }␊ |
307 | ␊ |
308 | //==========================================================================␊ |
309 | ␊ |
310 | static void showMenu( const MenuItem * items, int count,␊ |
311 | int selection, int row, int height )␊ |
312 | {␊ |
313 | int i;␊ |
314 | CursorState cursorState;␊ |
315 | ␊ |
316 | if ( items == NULL || count == 0 ) ␊ |
317 | ␉␉return;␊ |
318 | ␊ |
319 | // head and tail points to the start and the end of the list.␊ |
320 | // top and bottom points to the first and last visible items␊ |
321 | // in the menu window.␊ |
322 | ␊ |
323 | gMenuItems␉␉= items;␊ |
324 | gMenuRow␉␉= row;␊ |
325 | gMenuHeight␉␉= height;␊ |
326 | gMenuItemCount␉= count;␊ |
327 | gMenuTop␉␉= 0;␊ |
328 | gMenuBottom␉␉= MIN( count, height ) - 1;␊ |
329 | gMenuSelection␉= selection;␊ |
330 | ␊ |
331 | gMenuStart␉␉= 0;␊ |
332 | gMenuEnd␉ = MIN( count, gui.maxdevices ) - 1;␊ |
333 | ␉␊ |
334 | ␉// If the selected item is not visible, shift the list down.␊ |
335 | ␊ |
336 | if ( gMenuSelection > gMenuBottom )␊ |
337 | {␊ |
338 | gMenuTop += ( gMenuSelection - gMenuBottom );␊ |
339 | gMenuBottom = gMenuSelection;␊ |
340 | }␊ |
341 | ␊ |
342 | ␉if ( gMenuSelection > gMenuEnd )␊ |
343 | {␊ |
344 | ␉␉gMenuStart += ( gMenuSelection - gMenuEnd );␊ |
345 | gMenuEnd = gMenuSelection;␊ |
346 | }␊ |
347 | ␉␊ |
348 | ␉// Draw the visible items.␊ |
349 | ␊ |
350 | ␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
351 | ␉␊ |
352 | ␉␉drawDeviceList(gMenuStart, gMenuEnd, gMenuSelection);␊ |
353 | ␊ |
354 | ␉else {␊ |
355 | ␉␉␊ |
356 | ␉␉changeCursor( 0, row, kCursorTypeHidden, &cursorState );␊ |
357 | ␊ |
358 | ␉␉for ( i = gMenuTop; i <= gMenuBottom; i++ )␊ |
359 | ␉␉{␊ |
360 | ␉␉␉printMenuItem( &items[i], (i == gMenuSelection) );␊ |
361 | ␉␉}␊ |
362 | ␊ |
363 | ␉␉restoreCursor( &cursorState );␊ |
364 | }␊ |
365 | }␊ |
366 | ␊ |
367 | //==========================================================================␊ |
368 | ␊ |
369 | static int updateMenu( int key, void ** paramPtr )␊ |
370 | {␊ |
371 | int moved = 0;␊ |
372 | ␊ |
373 | union {␊ |
374 | struct {␊ |
375 | unsigned int␊ |
376 | selectionUp : 1,␊ |
377 | selectionDown : 1,␊ |
378 | scrollUp : 1,␊ |
379 | scrollDown : 1;␊ |
380 | } f;␊ |
381 | unsigned int w;␊ |
382 | } draw = {{0}};␊ |
383 | ␊ |
384 | if ( gMenuItems == NULL )␊ |
385 | ␉␉return 0;␊ |
386 | ␊ |
387 | ␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
388 | ␉{␊ |
389 | ␉␉int res;␊ |
390 | ␉␉␊ |
391 | ␉␉// set navigation keys for horizontal layout as defaults␊ |
392 | ␉␉int previous␉= 0x4B00;␉␉// left arrow␊ |
393 | ␉␉int subsequent␉= 0x4D00;␉␉// right arrow␊ |
394 | ␉␉int menu␉␉= 0x5000;␉␉// down arrow␊ |
395 | ␉␉␊ |
396 | ␉␉if ( gui.layout == VerticalLayout )␊ |
397 | ␉␉{␊ |
398 | ␉␉␉// set navigation keys for vertical layout␊ |
399 | ␉␉␉previous␉= 0x4800;␉␉// up arrow␊ |
400 | ␉␉␉subsequent␉= 0x5000;␉␉// down arrow␊ |
401 | ␉␉␉menu␉␉= 0x4B00;␉␉// right arrow␊ |
402 | ␉␉} ␊ |
403 | ␊ |
404 | ␉␉if ( key == previous )␊ |
405 | ␉␉{␊ |
406 | ␉␉␉if ( gMenuSelection > gMenuTop )␊ |
407 | ␉␉␉␉draw.f.selectionUp = 1;␊ |
408 | ␉␉␉else if ( gMenuTop > 0 )␊ |
409 | ␉␉␉␉draw.f.scrollDown = 1;␊ |
410 | ␉␉␉␊ |
411 | ␉␉}␊ |
412 | ␉␉␊ |
413 | ␉␉else if ( key == subsequent )␊ |
414 | ␉␉{␊ |
415 | ␉␉␉if ( gMenuSelection != gMenuBottom)␊ |
416 | ␉␉␉␉draw.f.selectionDown = 1;␊ |
417 | ␉␉␉else if ( gMenuBottom < ( gMenuItemCount - 1 ) )␊ |
418 | ␉␉␉␉draw.f.scrollUp = 1;␊ |
419 | ␉␉}␊ |
420 | ␉␉␊ |
421 | ␉␉else if ( key == menu )␊ |
422 | ␉␉{␊ |
423 | ␉␉␉if ( gui.menu.draw )␊ |
424 | ␉␉␉␉updateInfoMenu(key);␊ |
425 | ␉␉␉else␊ |
426 | ␉␉␉␉drawInfoMenu();␊ |
427 | ␉␉}␊ |
428 | ␊ |
429 | ␉␉else if ( gui.menu.draw )␊ |
430 | ␉␉{␊ |
431 | ␉␉␉res = updateInfoMenu(key);␊ |
432 | ␊ |
433 | ␉␉␉if ( res == CLOSE_INFO_MENU )␊ |
434 | ␉␉␉␉gui.menu.draw = false;␊ |
435 | ␉␉␉else␊ |
436 | ␉␉␉{␊ |
437 | ␉␉␉␉shouldboot = ( res != DO_NOT_BOOT );␊ |
438 | ␉␉␉␉␊ |
439 | ␉␉␉␉if ( shouldboot )␊ |
440 | ␉␉␉␉␉gui.menu.draw = false;␊ |
441 | ␊ |
442 | ␉␉␉␉switch (res)␊ |
443 | ␉␉␉␉{␊ |
444 | ␉␉␉␉␉case BOOT_NORMAL:␊ |
445 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
446 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
447 | ␉␉␉␉␉␉break;␊ |
448 | ␉␉␉␉␉␉␊ |
449 | ␉␉␉␉␉case BOOT_VERBOSE:␊ |
450 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
451 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
452 | ␉␉␉␉␉␉addBootArg(kVerboseModeFlag);␊ |
453 | ␉␉␉␉␉␉break;␊ |
454 | ␉␉␉␉␉␉␊ |
455 | ␉␉␉␉␉case BOOT_IGNORECACHE:␊ |
456 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
457 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
458 | ␉␉␉␉␉␉addBootArg(kIgnoreCachesFlag);␊ |
459 | ␉␉␉␉␉␉break;␊ |
460 | ␉␉␉␉␉␉␊ |
461 | ␉␉␉␉␉case BOOT_SINGLEUSER:␊ |
462 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
463 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
464 | ␉␉␉␉␉␉addBootArg(kSingleUserModeFlag);␊ |
465 | ␉␉␉␉␉␉break;␊ |
466 | ␉␉␉␉}␊ |
467 | ␉␉␉␉␊ |
468 | ␉␉␉}␊ |
469 | ␉␉␉␊ |
470 | ␉␉}␉␊ |
471 | ␉␉␉␊ |
472 | ␉} else {␊ |
473 | ␉␉switch ( key )␊ |
474 | ␉␉{␊ |
475 | ␉case 0x4800: // Up Arrow␊ |
476 | ␉␉␉␉if ( gMenuSelection != gMenuTop )␊ |
477 | ␉␉␉␉␉draw.f.selectionUp = 1;␊ |
478 | ␉␉␉␉else if ( gMenuTop > 0 )␊ |
479 | ␉␉␉␉␉draw.f.scrollDown = 1;␊ |
480 | ␉␉␉␉break;␊ |
481 | ␊ |
482 | ␉␉␉case 0x5000: // Down Arrow␊ |
483 | ␉␉␉␉if ( gMenuSelection != gMenuBottom )␊ |
484 | ␉␉␉␉␉draw.f.selectionDown = 1;␊ |
485 | ␉␉␉␉else if ( gMenuBottom < (gMenuItemCount - 1) ) ␊ |
486 | ␉␉␉␉␉draw.f.scrollUp = 1;␊ |
487 | ␉␉␉␉break;␊ |
488 | ␉␉}␊ |
489 | ␉}␊ |
490 | ␊ |
491 | if ( draw.w )␊ |
492 | {␊ |
493 | if ( draw.f.scrollUp )␊ |
494 | {␊ |
495 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, 1);␊ |
496 | gMenuTop++; gMenuBottom++;␊ |
497 | ␉␉␉gMenuStart++; gMenuEnd++;␊ |
498 | draw.f.selectionDown = 1;␊ |
499 | }␊ |
500 | ␊ |
501 | if ( draw.f.scrollDown )␊ |
502 | {␊ |
503 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, -1);␊ |
504 | gMenuTop--; gMenuBottom--;␊ |
505 | gMenuStart--; gMenuEnd--;␊ |
506 | draw.f.selectionUp = 1;␊ |
507 | }␊ |
508 | ␊ |
509 | if ( draw.f.selectionUp || draw.f.selectionDown )␊ |
510 | {␊ |
511 | ␊ |
512 | ␉␉␉CursorState cursorState;␊ |
513 | ␊ |
514 | ␉␉␉// Set cursor at current position, and clear inverse video.␊ |
515 | ␉␊ |
516 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
517 | ␉␉␉{␊ |
518 | ␉␉␉␉changeCursor( 0, gMenuRow + gMenuSelection - gMenuTop, kCursorTypeHidden, &cursorState );␊ |
519 | ␉␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 0 );␊ |
520 | ␉␉␉}␊ |
521 | ␊ |
522 | ␉␉␉if ( draw.f.selectionUp )␊ |
523 | ␉␉␉{␊ |
524 | ␉␉␉␉gMenuSelection--;␊ |
525 | ␉␉␉␉if(( gMenuSelection - gMenuStart) == -1 )␊ |
526 | ␉␉␉␉{␊ |
527 | ␉␉␉␉␉gMenuStart--;␊ |
528 | ␉␉␉␉␉gMenuEnd--;␊ |
529 | ␉␉␉␉}␊ |
530 | ␉␉␉␉␊ |
531 | ␉␉␉} else {␊ |
532 | ␉␉␉gMenuSelection++;␊ |
533 | ␉␉␉if(( gMenuSelection - ( gui.maxdevices - 1) - gMenuStart) > 0 )␊ |
534 | ␉␉␉{␊ |
535 | ␉␉␉␉gMenuStart++;␊ |
536 | ␉␉␉␉gMenuEnd++;␊ |
537 | ␉␉␉}␊ |
538 | ␉ }␊ |
539 | ␊ |
540 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
541 | ␉ {␊ |
542 | ␉␉␉moveCursor( 0, gMenuRow + gMenuSelection - gMenuTop );␊ |
543 | ␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 1 );␊ |
544 | ␉␉␉restoreCursor( &cursorState );␊ |
545 | ␊ |
546 | ␉ } else␊ |
547 | ␊ |
548 | ␉␉␉drawDeviceList (gMenuStart, gMenuEnd, gMenuSelection);␊ |
549 | ␊ |
550 | ␉}␊ |
551 | ␊ |
552 | *paramPtr = gMenuItems[gMenuSelection].param; ␊ |
553 | moved = 1;␊ |
554 | }␊ |
555 | ␊ |
556 | ␉return moved;␊ |
557 | }␊ |
558 | ␊ |
559 | //==========================================================================␊ |
560 | ␊ |
561 | static void skipblanks( const char ** cpp ) ␊ |
562 | {␊ |
563 | while ( **(cpp) == ' ' || **(cpp) == '\t' ) ++(*cpp);␊ |
564 | }␊ |
565 | ␊ |
566 | //==========================================================================␊ |
567 | ␊ |
568 | static const char * extractKernelName( char ** cpp )␊ |
569 | {␊ |
570 | char * kn = *cpp;␊ |
571 | char * cp = *cpp;␊ |
572 | char c;␊ |
573 | ␊ |
574 | // Convert char to lower case.␊ |
575 | ␊ |
576 | c = *cp | 0x20;␊ |
577 | ␊ |
578 | // Must start with a letter or a '/'.␊ |
579 | ␊ |
580 | if ( (c < 'a' || c > 'z') && ( c != '/' ) )␊ |
581 | return 0;␊ |
582 | ␊ |
583 | // Keep consuming characters until we hit a separator.␊ |
584 | ␊ |
585 | while ( *cp && (*cp != '=') && (*cp != ' ') && (*cp != '\t') )␊ |
586 | cp++;␊ |
587 | ␊ |
588 | // Only SPACE or TAB separator is accepted.␊ |
589 | // Reject everything else.␊ |
590 | ␊ |
591 | if (*cp == '=')␊ |
592 | return 0;␊ |
593 | ␊ |
594 | // Overwrite the separator, and move the pointer past␊ |
595 | // the kernel name.␊ |
596 | ␊ |
597 | if (*cp != '\0') *cp++ = '\0';␊ |
598 | *cpp = cp;␊ |
599 | ␊ |
600 | return kn;␊ |
601 | }␊ |
602 | ␊ |
603 | //==========================================================================␊ |
604 | ␊ |
605 | static void␊ |
606 | printMemoryInfo(void)␊ |
607 | {␊ |
608 | int line;␊ |
609 | int i;␊ |
610 | MemoryRange *mp = bootInfo->memoryMap;␊ |
611 | ␊ |
612 | // Activate and clear page 1␊ |
613 | setActiveDisplayPage(1);␊ |
614 | clearScreenRows(0, 24);␊ |
615 | setCursorPosition( 0, 0, 1 );␊ |
616 | ␊ |
617 | printf("BIOS reported memory ranges:\n");␊ |
618 | line = 1;␊ |
619 | for (i=0; i<bootInfo->memoryMapCount; i++) {␊ |
620 | printf("Base 0x%08x%08x, ",␊ |
621 | (unsigned long)(mp->base >> 32),␊ |
622 | (unsigned long)(mp->base));␊ |
623 | printf("length 0x%08x%08x, type %d\n",␊ |
624 | (unsigned long)(mp->length >> 32),␊ |
625 | (unsigned long)(mp->length),␊ |
626 | mp->type);␊ |
627 | if (line++ > 20) {␊ |
628 | pause();␊ |
629 | line = 0;␊ |
630 | }␊ |
631 | mp++;␊ |
632 | }␊ |
633 | if (line > 0) {␊ |
634 | pause();␊ |
635 | }␊ |
636 | ␊ |
637 | setActiveDisplayPage(0);␊ |
638 | }␊ |
639 | ␊ |
640 | char *getMemoryInfoString()␊ |
641 | {␊ |
642 | int i;␊ |
643 | MemoryRange *mp = bootInfo->memoryMap;␊ |
644 | ␉char *buff = malloc(sizeof(char)*1024);␊ |
645 | ␉if(!buff) return 0;␊ |
646 | ␉␊ |
647 | ␉char info[] = "BIOS reported memory ranges:\n";␊ |
648 | ␉sprintf(buff, "%s", info);␊ |
649 | for (i=0; i<bootInfo->memoryMapCount; i++) {␊ |
650 | sprintf( buff+strlen(buff), "Base 0x%08x%08x, ",␊ |
651 | (unsigned long)(mp->base >> 32),␊ |
652 | (unsigned long)(mp->base));␊ |
653 | sprintf( buff+strlen(buff), "length 0x%08x%08x, type %d\n",␊ |
654 | (unsigned long)(mp->length >> 32),␊ |
655 | (unsigned long)(mp->length),␊ |
656 | mp->type);␊ |
657 | mp++;␊ |
658 | }␊ |
659 | ␉return buff;␊ |
660 | }␊ |
661 | ␊ |
662 | //==========================================================================␊ |
663 | ␊ |
664 | void lspci(void)␊ |
665 | {␊ |
666 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) { ␊ |
667 | ␉␉setActiveDisplayPage(1);␊ |
668 | ␉␉clearScreenRows(0, 24);␊ |
669 | ␉␉setCursorPosition(0, 0, 1);␊ |
670 | ␉}␊ |
671 | ␊ |
672 | ␉dump_pci_dt(root_pci_dev->children);␊ |
673 | ␊ |
674 | ␉pause();␊ |
675 | ␊ |
676 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
677 | ␉␉setActiveDisplayPage(0);␊ |
678 | ␉}␊ |
679 | }␊ |
680 | ␊ |
681 | //==========================================================================␊ |
682 | ␊ |
683 | int getBootOptions(bool firstRun)␊ |
684 | {␊ |
685 | ␉int i;␊ |
686 | ␉int key;␊ |
687 | ␉int nextRow;␊ |
688 | ␉int timeout;␊ |
689 | ␉int bvCount;␊ |
690 | ␉BVRef bvr;␊ |
691 | ␉BVRef menuBVR;␊ |
692 | ␉bool showPrompt, newShowPrompt, isCDROM;␊ |
693 | ␊ |
694 | ␉// Initialize default menu selection entry.␊ |
695 | ␉gBootVolume = menuBVR = selectBootVolume(bvChain);␊ |
696 | ␊ |
697 | ␉if (biosDevIsCDROM(gBIOSDev)) {␊ |
698 | ␉␉isCDROM = true;␊ |
699 | ␉} else {␊ |
700 | ␉␉isCDROM = false;␊ |
701 | ␉}␊ |
702 | ␊ |
703 | ␉// ensure we're in graphics mode if gui is setup␊ |
704 | ␉if (firstRun && gui.initialised && bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
705 | ␉{␊ |
706 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
707 | ␉}␊ |
708 | ␊ |
709 | ␉// Clear command line boot arguments␊ |
710 | ␉clearBootArgs();␊ |
711 | ␊ |
712 | ␉// Allow user to override default timeout.␊ |
713 | ␉if (multiboot_timeout_set) {␊ |
714 | ␉␉timeout = multiboot_timeout;␊ |
715 | ␉} else if (!getIntForKey(kTimeoutKey, &timeout, &bootInfo->bootConfig)) {␊ |
716 | ␉␉/* If there is no timeout key in the file use the default timeout␊ |
717 | ␉␉ which is different for CDs vs. hard disks. However, if not booting␊ |
718 | ␉␉ a CD and no config file could be loaded set the timeout␊ |
719 | ␉␉ to zero which causes the menu to display immediately.␊ |
720 | ␉␉ This way, if no partitions can be found, that is the disk is unpartitioned␊ |
721 | ␉␉ or simply cannot be read) then an empty menu is displayed.␊ |
722 | ␉␉ If some partitions are found, for example a Windows partition, then␊ |
723 | ␉␉ these will be displayed in the menu as foreign partitions.␊ |
724 | ␉␉ */␊ |
725 | ␉␉if (isCDROM) {␊ |
726 | ␉␉␉timeout = kCDBootTimeout;␊ |
727 | ␉␉} else {␊ |
728 | ␉␉␉timeout = sysConfigValid ? kBootTimeout : 0;␊ |
729 | ␉␉}␊ |
730 | ␉}␊ |
731 | ␊ |
732 | ␉if (timeout < 0) {␊ |
733 | ␉␉gBootMode |= kBootModeQuiet;␊ |
734 | ␉}␊ |
735 | ␊ |
736 | ␉// If the user is holding down a modifier key, enter safe mode.␊ |
737 | ␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
738 | ␉␉gBootMode |= kBootModeSafe;␊ |
739 | ␉}␊ |
740 | ␊ |
741 | ␉// Checking user pressed keys␊ |
742 | ␉bool f8press = false, spress = false, vpress = false;␊ |
743 | ␉while (readKeyboardStatus()) {␊ |
744 | ␉␉key = bgetc ();␊ |
745 | ␉␉if (key == 0x4200) f8press = true;␊ |
746 | ␉␉if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true;␊ |
747 | ␉␉if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true;␊ |
748 | ␉}␊ |
749 | ␉// If user typed F8, abort quiet mode, and display the menu.␊ |
750 | ␉if (f8press) {␊ |
751 | ␉␉gBootMode &= ~kBootModeQuiet;␊ |
752 | ␉␉timeout = 0;␊ |
753 | ␉}␊ |
754 | ␉// If user typed 'v' or 'V', boot in verbose mode.␊ |
755 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && vpress) {␊ |
756 | ␉␉addBootArg(kVerboseModeFlag);␊ |
757 | ␉}␊ |
758 | ␉// If user typed 's' or 'S', boot in single user mode.␊ |
759 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && spress) {␊ |
760 | ␉␉addBootArg(kSingleUserModeFlag);␊ |
761 | ␉}␊ |
762 | ␊ |
763 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
764 | ␉␉setCursorPosition(0, 0, 0);␊ |
765 | ␉␉clearScreenRows(0, kScreenLastRow);␊ |
766 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
767 | ␉␉␉// Display banner and show hardware info.␊ |
768 | ␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
769 | ␉␉␉printf(getVBEInfoString());␊ |
770 | ␉␉}␊ |
771 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
772 | ␉␉verbose("Scanning device %x...", gBIOSDev);␊ |
773 | ␉}␊ |
774 | ␊ |
775 | ␉// When booting from CD, default to hard drive boot when possible. ␊ |
776 | ␉if (isCDROM && firstRun) {␊ |
777 | ␉␉const char *val;␊ |
778 | ␉␉char *prompt = NULL;␊ |
779 | ␉␉char *name = NULL;␊ |
780 | ␉␉int cnt;␊ |
781 | ␉␉int optionKey;␊ |
782 | ␊ |
783 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig)) {␊ |
784 | ␉␉␉prompt = malloc(cnt + 1);␊ |
785 | ␉␉␉strncat(prompt, val, cnt);␊ |
786 | ␉␉} else {␊ |
787 | ␉␉␉name = malloc(80);␊ |
788 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 79, false);␊ |
789 | ␉␉␉prompt = malloc(256);␊ |
790 | ␉␉␉sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);␊ |
791 | ␉␉␉free(name);␊ |
792 | ␉␉}␊ |
793 | ␊ |
794 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig )) {␊ |
795 | ␉␉␉// The key specified is a special key.␊ |
796 | ␉␉} else {␊ |
797 | ␉␉␉// Default to F8.␊ |
798 | ␉␉␉optionKey = 0x4200;␊ |
799 | ␉␉}␊ |
800 | ␊ |
801 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
802 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
803 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
804 | ␉␉if (timeout != 0) {␊ |
805 | ␉␉␉key = countdown(prompt, kMenuTopRow, timeout);␊ |
806 | ␉␉} else {␊ |
807 | ␉␉␉key = optionKey;␊ |
808 | ␉␉}␊ |
809 | ␊ |
810 | ␉␉if (prompt != NULL) {␊ |
811 | ␉␉␉free(prompt);␊ |
812 | ␉␉}␊ |
813 | ␊ |
814 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
815 | ␊ |
816 | ␉␉// Hit the option key ?␊ |
817 | ␉␉if (key == optionKey) {␊ |
818 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
819 | ␉␉␉timeout = 0;␊ |
820 | ␉␉} else {␊ |
821 | ␉␉␉key = key & 0xFF;␊ |
822 | ␊ |
823 | ␉␉␉// Try booting hard disk if user pressed 'h'␊ |
824 | ␉␉␉if (biosDevIsCDROM(gBIOSDev) && key == 'h') {␊ |
825 | ␉␉␉␉BVRef bvr;␊ |
826 | ␊ |
827 | ␉␉␉␉// Look at partitions hosting OS X other than the CD-ROM␊ |
828 | ␉␉␉␉for (bvr = bvChain; bvr; bvr=bvr->next) {␊ |
829 | ␉␉␉␉␉if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) {␊ |
830 | ␉␉␉␉␉␉gBootVolume = bvr;␊ |
831 | ␉␉␉␉␉}␊ |
832 | ␉␉␉␉}␊ |
833 | ␉␉␉}␊ |
834 | ␉␉␉goto done;␊ |
835 | ␉␉}␊ |
836 | ␉}␊ |
837 | ␊ |
838 | ␉if (gBootMode & kBootModeQuiet) {␊ |
839 | ␉␉// No input allowed from user.␊ |
840 | ␉␉goto done;␊ |
841 | ␉}␊ |
842 | ␊ |
843 | ␉if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) {␊ |
844 | ␉␉// If the user is holding down a modifier key,␊ |
845 | ␉␉// enter safe mode.␊ |
846 | ␉␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
847 | ␉␉␉gBootMode |= kBootModeSafe;␊ |
848 | ␉␉}␊ |
849 | ␉␉goto done;␊ |
850 | ␉}␊ |
851 | ␊ |
852 | ␉if (gDeviceCount) {␊ |
853 | ␉␉// Allocate memory for an array of menu items.␊ |
854 | ␉␉menuItems = malloc(sizeof(MenuItem) * gDeviceCount);␊ |
855 | ␉␉if (menuItems == NULL) {␊ |
856 | ␉␉␉goto done;␊ |
857 | ␉␉}␊ |
858 | ␊ |
859 | ␉␉// Associate a menu item for each BVRef.␊ |
860 | ␉␉for (bvr=bvChain, i=gDeviceCount-1, selectIndex=0; bvr; bvr=bvr->next) {␊ |
861 | ␉␉␉if (bvr->visible) {␊ |
862 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true);␊ |
863 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
864 | ␉␉␉␉if (bvr == menuBVR) {␊ |
865 | ␉␉␉␉␉selectIndex = i;␊ |
866 | ␉␉␉␉}␊ |
867 | ␉␉␉␉i--;␊ |
868 | ␉␉␉}␊ |
869 | ␉␉}␊ |
870 | ␉}␊ |
871 | ␊ |
872 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
873 | ␉␉// redraw the background buffer␊ |
874 | ␉␉gui.logo.draw = true;␊ |
875 | ␉␉drawBackground();␊ |
876 | ␉␉gui.devicelist.draw = true;␊ |
877 | ␉␉gui.redraw = true;␊ |
878 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
879 | ␊ |
880 | ␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
881 | ␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->bootConfig); ␊ |
882 | ␉␉␉if (showBootBanner) {␊ |
883 | ␉␉␉␉// Display banner and show hardware info.␊ |
884 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
885 | ␉␉␉}␊ |
886 | ␊ |
887 | ␉␉␉// redraw background␊ |
888 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
889 | ␉␉}␊ |
890 | ␉} else {␊ |
891 | ␉␉// Clear screen and hide the blinking cursor.␊ |
892 | ␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
893 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
894 | ␉}␊ |
895 | ␊ |
896 | ␉nextRow = kMenuTopRow;␊ |
897 | ␉showPrompt = true;␊ |
898 | ␊ |
899 | ␉if (gDeviceCount) {␊ |
900 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
901 | ␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
902 | ␉␉}␊ |
903 | ␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
904 | ␉␉nextRow += MIN( gDeviceCount, kMenuMaxItems ) + 3;␊ |
905 | ␉}␊ |
906 | ␊ |
907 | ␉// Show the boot prompt.␊ |
908 | ␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
909 | ␉showBootPrompt( nextRow, showPrompt );␊ |
910 | ␉␊ |
911 | ␉do {␊ |
912 | ␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
913 | ␉␉␉// redraw background␊ |
914 | ␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
915 | ␉␉␉// reset cursor co-ords␊ |
916 | ␉␉␉gui.debug.cursor = pos( gui.screen.width - 160 , 10 );␊ |
917 | ␉␉}␊ |
918 | ␉␉key = getchar();␊ |
919 | ␉␉updateMenu( key, (void **) &menuBVR );␊ |
920 | ␉␉newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
921 | ␊ |
922 | ␉␉if (newShowPrompt != showPrompt) {␊ |
923 | ␉␉␉showPrompt = newShowPrompt;␊ |
924 | ␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
925 | ␉␉}␊ |
926 | ␊ |
927 | ␉␉if (showPrompt) {␊ |
928 | ␉␉␉updateBootArgs(key);␊ |
929 | ␉␉}␊ |
930 | ␊ |
931 | ␉␉switch (key) {␊ |
932 | ␉␉case kReturnKey:␊ |
933 | ␉␉␉if (gui.menu.draw) { ␊ |
934 | ␉␉␉␉key=0;␊ |
935 | ␉␉␉␉break;␊ |
936 | ␉␉␉}␊ |
937 | ␉␉␉if (*gBootArgs == '?') {␊ |
938 | ␉␉␉␉char * argPtr = gBootArgs;␊ |
939 | ␊ |
940 | ␉␉␉␉// Skip the leading "?" character.␊ |
941 | ␉␉␉␉argPtr++;␊ |
942 | ␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
943 | ␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
944 | ␊ |
945 | ␉␉␉␉/*␊ |
946 | ␉␉␉␉* TODO: this needs to be refactored.␊ |
947 | ␉␉␉␉*/␊ |
948 | ␉␉␉␉if (strcmp( booterCommand, "video" ) == 0) {␊ |
949 | ␉␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
950 | ␉␉␉␉␉␉showInfoBox(getVBEInfoString(), getVBEModeInfoString());␊ |
951 | ␉␉␉␉␉} else {␊ |
952 | ␉␉␉␉␉␉printVBEModeInfo();␊ |
953 | ␉␉␉␉␉}␊ |
954 | ␉␉␉␉} else if ( strcmp( booterCommand, "memory" ) == 0) {␊ |
955 | ␉␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE ) {␊ |
956 | ␉␉␉␉␉␉showInfoBox("Memory Map", getMemoryInfoString());␊ |
957 | ␉␉␉␉␉} else {␊ |
958 | ␉␉␉␉␉␉printMemoryInfo();␊ |
959 | ␉␉␉␉␉}␊ |
960 | ␉␉␉␉} else if (strcmp(booterCommand, "lspci") == 0) {␊ |
961 | ␉␉␉␉␉lspci();␊ |
962 | ␉␉␉␉} else if (strcmp(booterCommand, "more") == 0) {␊ |
963 | ␉␉␉␉␉showTextFile(booterParam);␊ |
964 | ␉␉␉␉} else if (strcmp(booterCommand, "rd") == 0) {␊ |
965 | ␉␉␉␉␉processRAMDiskCommand(&argPtr, booterParam);␊ |
966 | ␉␉␉␉} else if (strcmp(booterCommand, "norescan") == 0) {␊ |
967 | ␉␉␉␉␉if (gEnableCDROMRescan) {␊ |
968 | ␉␉␉␉␉␉gEnableCDROMRescan = false;␊ |
969 | ␉␉␉␉␉␉break;␊ |
970 | ␉␉␉␉␉}␊ |
971 | ␉␉␉␉} else {␊ |
972 | ␉␉␉␉␉showHelp();␊ |
973 | ␉␉␉␉}␊ |
974 | ␉␉␉␉key = 0;␊ |
975 | ␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
976 | ␉␉␉␉break;␊ |
977 | ␉␉␉}␊ |
978 | ␉␉␉gBootVolume = menuBVR;␊ |
979 | ␉␉␉setRootVolume(menuBVR);␊ |
980 | ␉␉␉gBIOSDev = menuBVR->biosdev;␊ |
981 | ␉␉␉break;␊ |
982 | ␊ |
983 | ␉␉case kEscapeKey:␊ |
984 | ␉␉␉clearBootArgs();␊ |
985 | ␉␉␉break;␊ |
986 | ␊ |
987 | ␉␉//Azi:autoresolution - Reapply the patch if Graphics Mode was incorrect␊ |
988 | ␉␉// or EDID Info was insane.␊ |
989 | ␉␉case kF2Key:␊ |
990 | ␉␉␊ |
991 | ␉␉␉if ((gAutoResolution == true) && useGUI && map )␊ |
992 | ␉␉␉{␊ |
993 | ␉␉␉␉// get the new Graphics Mode key␊ |
994 | ␉␉␉␉processBootOptions(); //Azi: use processBootArgument instead?␊ |
995 | ␊ |
996 | //␉␉␉␉UInt32 paramsAR[4];␊ |
997 | ␉␉␉␉paramsAR[3] = 0;␊ |
998 | ␊ |
999 | ␉␉␉␉getNumberArrayFromProperty(kGraphicsModeKey, paramsAR, 4);␊ |
1000 | ␊ |
1001 | ␉␉␉␉// user changed resolution...␊ |
1002 | ␉␉␉␉if ((paramsAR[0] != 0) && (paramsAR[1] != 0) &&␊ |
1003 | ␉␉␉␉␉(paramsAR[0] != map->currentX) && (paramsAR[1] != map->currentY))␊ |
1004 | ␉␉␉␉{␊ |
1005 | ␉␉␉␉␉//Azi: identical to "case kTabKey:"␉␉␉(check later)␊ |
1006 | ␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
1007 | ␉␉␉␉␉{␊ |
1008 | ␉␉␉␉␉␉CursorState cursorState;␊ |
1009 | ␊ |
1010 | ␉␉␉␉␉␉// Go back to TEXT MODE while we change the mode␊ |
1011 | ␉␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1012 | ␊ |
1013 | ␉␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1014 | ␉␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1015 | ␉␉␉␉␉␉changeCursor( 0, 0, kCursorTypeHidden, &cursorState );␊ |
1016 | ␊ |
1017 | ␉␉␉␉␉␉// Reapply patch␊ |
1018 | ␉␉␉␉␉␉patchVbios(map, paramsAR[0], paramsAR[1], paramsAR[2], 0, 0);␊ |
1019 | ␊ |
1020 | ␉␉␉␉␉␉if (useGUI && (gui.initialised == true))␊ |
1021 | ␉␉␉␉␉␉␉initGUI();␊ |
1022 | ␉␉␉␉␉␉// Make sure all values are set␊ |
1023 | ␉␉␉␉␉␉if (bootArgs->Video.v_display != GRAPHICS_MODE)␊ |
1024 | ␉␉␉␉␉␉␉bootArgs->Video.v_display = GRAPHICS_MODE;␊ |
1025 | ␊ |
1026 | ␉␉␉␉␉␉if (!useGUI)␊ |
1027 | ␉␉␉␉␉␉␉useGUI = true;␊ |
1028 | ␊ |
1029 | ␉␉␉␉␉␉// redraw the background buffer␊ |
1030 | ␉␉␉␉␉␉drawBackground();␊ |
1031 | ␉␉␉␉␉␉gui.devicelist.draw = true;␊ |
1032 | ␉␉␉␉␉␉gui.redraw = true;␊ |
1033 | ␊ |
1034 | ␉␉␉␉␉␉if (showBootBanner)␊ |
1035 | ␉␉␉␉␉␉{␊ |
1036 | ␉␉␉␉␉␉␉// Display banner and show hardware info.␊ |
1037 | ␉␉␉␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1038 | ␉␉␉␉␉␉}␊ |
1039 | ␊ |
1040 | ␉␉␉␉␉␉// redraw background␊ |
1041 | ␉␉␉␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels,␊ |
1042 | ␉␉␉␉␉␉␉ gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
1043 | ␊ |
1044 | ␉␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1045 | ␉␉␉␉␉␉showPrompt = true;␊ |
1046 | ␊ |
1047 | ␉␉␉␉␉␉if (gDeviceCount)␊ |
1048 | ␉␉␉␉␉␉{␊ |
1049 | ␉␉␉␉␉␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
1050 | ␉␉␉␉␉␉␉nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;␊ |
1051 | ␉␉␉␉␉␉}␊ |
1052 | ␊ |
1053 | ␉␉␉␉␉␉// Show the boot prompt.␊ |
1054 | ␉␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1055 | ␉␉␉␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
1056 | ␊ |
1057 | ␉␉␉␉␉␉// this is used to avoid resetting the incorrect mode while quiting the boot menu␊ |
1058 | //␉␉␉␉␉␉map->hasSwitched = true; (check again later!)␊ |
1059 | ␉␉␉␉␉}␊ |
1060 | ␉␉␉␉}␊ |
1061 | ␊ |
1062 | ␉␉␉␉clearBootArgs();␊ |
1063 | ␉␉␉␉key = 0;␊ |
1064 | ␉␉␉}␉␊ |
1065 | ␉␉␉else // if gAutoResolution == false...␊ |
1066 | ␉␉␉{␊ |
1067 | ␉␉␉␉// ... do "nothing".␉␉␉(Reviewing...)␊ |
1068 | ␉␉␉␉clearBootArgs();␊ |
1069 | ␉␉␉␉key = 0;␊ |
1070 | ␉␉␉}␊ |
1071 | ␉␉␉break;␊ |
1072 | ␊ |
1073 | ␉␉case kF5Key:␊ |
1074 | ␉␉␉// New behavior:␊ |
1075 | ␉␉␉// Clear gBootVolume to restart the loop␊ |
1076 | ␉␉␉// if the user enabled rescanning the optical drive.␊ |
1077 | ␉␉␉// Otherwise boot the default boot volume.␊ |
1078 | ␉␉␉if (gEnableCDROMRescan) {␊ |
1079 | ␉␉␉␉gBootVolume = NULL;␊ |
1080 | ␉␉␉␉clearBootArgs();␊ |
1081 | ␉␉␉}␊ |
1082 | ␉␉␉break;␊ |
1083 | ␊ |
1084 | ␉␉case kF10Key:␊ |
1085 | ␉␉␉gScanSingleDrive = false;␊ |
1086 | ␉␉␉scanDisks(gBIOSDev, &bvCount);␊ |
1087 | ␉␉␉gBootVolume = NULL;␊ |
1088 | ␉␉␉clearBootArgs();␊ |
1089 | ␉␉␉break;␊ |
1090 | ␊ |
1091 | ␉␉case kTabKey:␊ |
1092 | ␉␉␉// New behavior:␊ |
1093 | ␉␉␉// Switch between text & graphic interfaces␊ |
1094 | ␉␉␉// Only Permitted if started in graphics interface␊ |
1095 | ␉␉␉if (useGUI) {␊ |
1096 | ␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1097 | ␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1098 | ␊ |
1099 | ␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1100 | ␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1101 | ␊ |
1102 | ␉␉␉␉␉// Display banner and show hardware info.␊ |
1103 | ␉␉␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1104 | ␉␉␉␉␉printf(getVBEInfoString());␊ |
1105 | ␊ |
1106 | ␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
1107 | ␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
1108 | ␊ |
1109 | ␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1110 | ␉␉␉␉␉showPrompt = true;␊ |
1111 | ␊ |
1112 | ␉␉␉␉␉if (gDeviceCount) {␊ |
1113 | ␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1114 | ␉␉␉␉␉␉showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
1115 | ␉␉␉␉␉␉nextRow += MIN(gDeviceCount, kMenuMaxItems) + 3;␊ |
1116 | ␉␉␉␉␉}␊ |
1117 | ␊ |
1118 | ␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1119 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1120 | ␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
1121 | ␉␉␉␉␉␊ |
1122 | ␉␉␉␉␉/*␊ |
1123 | ␉␉␉␉␉ * AutoResolution - make sure all values are set - Azi: think! it makes some sense!!␊ |
1124 | ␉␉␉␉␉ */␊ |
1125 | //␉␉␉␉␉bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
1126 | //␉␉␉␉␉useGUI = false;␊ |
1127 | ␉␉␉␉␉␊ |
1128 | ␉␉␉␉} else {␊ |
1129 | ␉␉␉␉␉gui.redraw = true;␊ |
1130 | ␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1131 | ␉␉␉␉␉␊ |
1132 | ␉␉␉␉␉/*␊ |
1133 | ␉␉␉␉␉ * AutoResolution - make sure all values are set - Azi: same as above...!?␊ |
1134 | ␉␉␉␉␉ */␊ |
1135 | //␉␉␉␉␉bootArgs->Video.v_display = GRAPHICS_MODE;␊ |
1136 | //␉␉␉␉␉useGUI = true;␊ |
1137 | ␉␉␉␉␉␊ |
1138 | ␉␉␉␉␉updateVRAM();␊ |
1139 | updateGraphicBootPrompt();␊ |
1140 | ␉␉␉␉}␊ |
1141 | ␉␉␉}␊ |
1142 | ␉␉␉key = 0;␊ |
1143 | ␉␉␉break;␊ |
1144 | ␊ |
1145 | ␉␉default:␊ |
1146 | ␉␉␉key = 0;␊ |
1147 | ␉␉␉break;␊ |
1148 | ␉␉}␊ |
1149 | ␉} while (0 == key);␊ |
1150 | ␊ |
1151 | done:␊ |
1152 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
1153 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
1154 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
1155 | ␉}␊ |
1156 | ␉shouldboot = false;␊ |
1157 | ␉gui.menu.draw = false;␊ |
1158 | ␉if (menuItems) {␊ |
1159 | ␉␉free(menuItems);␊ |
1160 | ␉␉menuItems = NULL;␊ |
1161 | ␉}␊ |
1162 | ␉return 0;␊ |
1163 | }␊ |
1164 | ␊ |
1165 | //==========================================================================␊ |
1166 | ␊ |
1167 | extern unsigned char chainbootdev;␊ |
1168 | extern unsigned char chainbootflag;␊ |
1169 | ␊ |
1170 | bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)␊ |
1171 | {␊ |
1172 | int argLen = argName ? strlen(argName) : 0;␊ |
1173 | int len = argLen + cnt + 1; // +1 to account for space␊ |
1174 | ␊ |
1175 | if (len > *cntRemainingP) {␊ |
1176 | error("Warning: boot arguments too long, truncating\n");␊ |
1177 | return false;␊ |
1178 | }␊ |
1179 | ␊ |
1180 | if (argName) {␊ |
1181 | strncpy( *argP, argName, argLen );␊ |
1182 | *argP += argLen;␊ |
1183 | *argP[0] = '=';␊ |
1184 | (*argP)++;␊ |
1185 | len++; // +1 to account for '='␊ |
1186 | }␊ |
1187 | strncpy( *argP, val, cnt );␊ |
1188 | *argP += cnt;␊ |
1189 | *argP[0] = ' ';␊ |
1190 | (*argP)++;␊ |
1191 | ␊ |
1192 | *cntRemainingP -= len;␊ |
1193 | return true;␊ |
1194 | }␊ |
1195 | ␊ |
1196 | // ␊ |
1197 | // Returns TRUE if an argument was copied, FALSE otherwise␊ |
1198 | bool␊ |
1199 | processBootArgument(␊ |
1200 | const char *argName, // The argument to search for␊ |
1201 | const char *userString, // Typed-in boot arguments␊ |
1202 | const char *kernelFlags, // Kernel flags from config table␊ |
1203 | const char *configTable,␊ |
1204 | char **argP, // Output value␊ |
1205 | int *cntRemainingP, // Output count␊ |
1206 | char *foundVal // found value␊ |
1207 | )␊ |
1208 | {␊ |
1209 | const char *val;␊ |
1210 | int cnt;␊ |
1211 | bool found = false;␊ |
1212 | ␊ |
1213 | if (getValueForBootKey(userString, argName, &val, &cnt)) {␊ |
1214 | // Don't copy; these values will be copied at the end of argument processing.␊ |
1215 | found = true;␊ |
1216 | } else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {␊ |
1217 | // Don't copy; these values will be copied at the end of argument processing.␊ |
1218 | found = true;␊ |
1219 | } else if (getValueForKey(argName, &val, &cnt, &bootInfo->bootConfig)) {␊ |
1220 | copyArgument(argName, val, cnt, argP, cntRemainingP);␊ |
1221 | found = true;␊ |
1222 | }␊ |
1223 | if (found && foundVal) {␊ |
1224 | strlcpy(foundVal, val, cnt+1);␊ |
1225 | }␊ |
1226 | return found;␊ |
1227 | }␊ |
1228 | ␊ |
1229 | // Maximum config table value size␊ |
1230 | #define VALUE_SIZE 2048␊ |
1231 | ␊ |
1232 | int␊ |
1233 | processBootOptions()␊ |
1234 | {␊ |
1235 | const char * cp = gBootArgs;␊ |
1236 | const char * val = 0;␊ |
1237 | const char * kernel;␊ |
1238 | int cnt;␊ |
1239 | int␉␉ userCnt;␊ |
1240 | int cntRemaining;␊ |
1241 | char * argP;␊ |
1242 | char uuidStr[64];␊ |
1243 | bool uuidSet = false;␊ |
1244 | char * configKernelFlags;␊ |
1245 | char * valueBuffer;␊ |
1246 | ␊ |
1247 | valueBuffer = malloc(VALUE_SIZE);␊ |
1248 | ␊ |
1249 | skipblanks( &cp );␊ |
1250 | ␊ |
1251 | // Update the unit and partition number.␊ |
1252 | ␊ |
1253 | if ( gBootVolume )␊ |
1254 | {␊ |
1255 | if (!( gBootVolume->flags & kBVFlagNativeBoot ))␊ |
1256 | {␊ |
1257 | readBootSector( gBootVolume->biosdev, gBootVolume->part_boff,␊ |
1258 | (void *) 0x7c00 );␊ |
1259 | ␊ |
1260 | //␊ |
1261 | // Setup edx, and signal intention to chain load the␊ |
1262 | // foreign booter.␊ |
1263 | //␊ |
1264 | ␊ |
1265 | chainbootdev = gBootVolume->biosdev;␊ |
1266 | chainbootflag = 1;␊ |
1267 | ␊ |
1268 | return 1;␊ |
1269 | }␊ |
1270 | ␊ |
1271 | setRootVolume(gBootVolume);␊ |
1272 | ␊ |
1273 | }␊ |
1274 | // If no boot volume fail immediately because we're just going to fail␊ |
1275 | // trying to load the config file anyway.␊ |
1276 | else␊ |
1277 | return -1;␊ |
1278 | ␊ |
1279 | // Load config table specified by the user, or use the default.␊ |
1280 | ␊ |
1281 | if (!getValueForBootKey(cp, "config", &val, &cnt)) {␊ |
1282 | val = 0;␊ |
1283 | cnt = 0;␊ |
1284 | }␊ |
1285 | ␊ |
1286 | // Load com.apple.Boot.plist from the selected volume␊ |
1287 | // and use its contents to override default bootConfig.␊ |
1288 | // This is not a mandatory opeartion anymore.␊ |
1289 | ␊ |
1290 | loadOverrideConfig(&bootInfo->overrideConfig);␊ |
1291 | ␊ |
1292 | // Use the kernel name specified by the user, or fetch the name␊ |
1293 | // in the config table, or use the default if not specified.␊ |
1294 | // Specifying a kernel name on the command line, or specifying␊ |
1295 | // a non-default kernel name in the config file counts as␊ |
1296 | // overriding the kernel, which causes the kernelcache not␊ |
1297 | // to be used.␊ |
1298 | ␊ |
1299 | gOverrideKernel = false;␊ |
1300 | if (( kernel = extractKernelName((char **)&cp) )) {␊ |
1301 | strcpy( bootInfo->bootFile, kernel );␊ |
1302 | gOverrideKernel = true;␊ |
1303 | } else {␊ |
1304 | if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1305 | strlcpy( bootInfo->bootFile, val, cnt+1 );␊ |
1306 | if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {␊ |
1307 | gOverrideKernel = true;␊ |
1308 | }␊ |
1309 | } else {␊ |
1310 | strcpy( bootInfo->bootFile, kDefaultKernel );␊ |
1311 | }␊ |
1312 | }␊ |
1313 | ␊ |
1314 | cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space␊ |
1315 | argP = bootArgs->CommandLine;␊ |
1316 | ␊ |
1317 | // Get config table kernel flags, if not ignored.␊ |
1318 | if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||␊ |
1319 | !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) {␊ |
1320 | val = "";␊ |
1321 | cnt = 0;␊ |
1322 | }␊ |
1323 | configKernelFlags = malloc(cnt + 1);␊ |
1324 | strlcpy(configKernelFlags, val, cnt + 1);␊ |
1325 | ␊ |
1326 | if (processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0)) {␊ |
1327 | // boot-uuid was set either on the command-line␊ |
1328 | // or in the config file.␊ |
1329 | uuidSet = true;␊ |
1330 | } else {␊ |
1331 | ␊ |
1332 | //␊ |
1333 | // Try an alternate method for getting the root UUID on boot helper partitions.␊ |
1334 | //␊ |
1335 | if (gBootVolume->flags & kBVFlagBooter)␊ |
1336 | {␊ |
1337 | ␉if((loadHelperConfig(&bootInfo->helperConfig) == 0)␊ |
1338 | ␉ && getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig) )␊ |
1339 | ␉{␊ |
1340 | ␉getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig);␊ |
1341 | copyArgument(kBootUUIDKey, val, cnt, &argP, &cntRemaining);␊ |
1342 | uuidSet = true;␊ |
1343 | ␉}␊ |
1344 | }␊ |
1345 | ␊ |
1346 | if (!uuidSet && gBootVolume->fs_getuuid && gBootVolume->fs_getuuid (gBootVolume, uuidStr) == 0) {␊ |
1347 | verbose("Setting boot-uuid to: %s\n", uuidStr);␊ |
1348 | copyArgument(kBootUUIDKey, uuidStr, strlen(uuidStr), &argP, &cntRemaining);␊ |
1349 | uuidSet = true;␊ |
1350 | }␊ |
1351 | }␊ |
1352 | ␊ |
1353 | if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice)) {␊ |
1354 | cnt = 0;␊ |
1355 | if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig)) {␊ |
1356 | valueBuffer[0] = '*';␊ |
1357 | cnt++;␊ |
1358 | strlcpy(valueBuffer + 1, val, cnt);␊ |
1359 | val = valueBuffer;␊ |
1360 | } else {␊ |
1361 | if (uuidSet) {␊ |
1362 | val = "*uuid";␊ |
1363 | cnt = 5;␊ |
1364 | } else {␊ |
1365 | // Don't set "rd=.." if there is no boot device key␊ |
1366 | // and no UUID.␊ |
1367 | val = "";␊ |
1368 | cnt = 0;␊ |
1369 | }␊ |
1370 | } ␊ |
1371 | if (cnt > 0) {␊ |
1372 | copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);␊ |
1373 | }␊ |
1374 | strlcpy( gRootDevice, val, (cnt + 1));␊ |
1375 | }␊ |
1376 | ␊ |
1377 | /*␊ |
1378 | * Removed. We don't need this anymore.␊ |
1379 | *␊ |
1380 | if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gPlatformName)) {␊ |
1381 | getPlatformName(gPlatformName);␊ |
1382 | copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);␊ |
1383 | }␊ |
1384 | */␊ |
1385 | ␊ |
1386 | if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&␊ |
1387 | !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) {␊ |
1388 | if (gBootMode & kBootModeSafe) {␊ |
1389 | copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);␊ |
1390 | }␊ |
1391 | }␊ |
1392 | ␊ |
1393 | // Store the merged kernel flags and boot args.␊ |
1394 | ␊ |
1395 | cnt = strlen(configKernelFlags);␊ |
1396 | if (cnt) {␊ |
1397 | if (cnt > cntRemaining) {␊ |
1398 | error("Warning: boot arguments too long, truncating\n");␊ |
1399 | cnt = cntRemaining;␊ |
1400 | }␊ |
1401 | strncpy(argP, configKernelFlags, cnt);␊ |
1402 | argP[cnt++] = ' ';␊ |
1403 | cntRemaining -= cnt;␊ |
1404 | }␊ |
1405 | userCnt = strlen(cp);␊ |
1406 | if (userCnt > cntRemaining) {␊ |
1407 | error("Warning: boot arguments too long, truncating\n");␊ |
1408 | userCnt = cntRemaining;␊ |
1409 | }␊ |
1410 | strncpy(&argP[cnt], cp, userCnt);␊ |
1411 | argP[cnt+userCnt] = '\0';␊ |
1412 | ␊ |
1413 | ␉if(!shouldboot)␊ |
1414 | ␉{␊ |
1415 | ␉␉gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->bootConfig ) ||␊ |
1416 | ␉␉␉getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->bootConfig );␊ |
1417 | ␉␉␊ |
1418 | ␉␉gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->bootConfig ) ) ?␊ |
1419 | ␉␉␉kBootModeSafe : kBootModeNormal;␊ |
1420 | ␊ |
1421 | if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1422 | gBootMode = kBootModeSafe;␊ |
1423 | }␊ |
1424 | ␉}␊ |
1425 | ␊ |
1426 | ␉if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )␊ |
1427 | ␉{␊ |
1428 | ␉␉strlcpy(gMKextName, val, cnt + 1);␊ |
1429 | ␉}␊ |
1430 | ␊ |
1431 | free(configKernelFlags);␊ |
1432 | free(valueBuffer);␊ |
1433 | ␊ |
1434 | return 0;␊ |
1435 | }␊ |
1436 | ␊ |
1437 | ␊ |
1438 | //==========================================================================␊ |
1439 | // Load the help file and display the file contents on the screen.␊ |
1440 | ␊ |
1441 | static void showTextBuffer(char *buf, int size)␊ |
1442 | {␊ |
1443 | ␉char␉*bp;␊ |
1444 | ␉int␉line;␊ |
1445 | ␉int␉line_offset;␊ |
1446 | ␉int␉c;␊ |
1447 | ␊ |
1448 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1449 | ␉␉showInfoBox( "Press q to quit\n",buf );␊ |
1450 | ␉␉return;␊ |
1451 | ␉}␊ |
1452 | ␊ |
1453 | bp = buf;␊ |
1454 | while (size-- > 0) {␊ |
1455 | ␉␉if (*bp == '\n') {␊ |
1456 | ␉␉␉*bp = '\0';␊ |
1457 | ␉␉}␊ |
1458 | ␉␉bp++;␊ |
1459 | }␊ |
1460 | *bp = '\1';␊ |
1461 | line_offset = 0;␊ |
1462 | ␊ |
1463 | setActiveDisplayPage(1);␊ |
1464 | ␊ |
1465 | while (1) {␊ |
1466 | ␉␉clearScreenRows(0, 24);␊ |
1467 | ␉␉setCursorPosition(0, 0, 1);␊ |
1468 | ␉␉bp = buf;␊ |
1469 | ␉␉for (line = 0; *bp != '\1' && line < line_offset; line++) {␊ |
1470 | ␉␉␉while (*bp != '\0') {␊ |
1471 | ␉␉␉␉bp++;␊ |
1472 | ␉␉␉}␊ |
1473 | ␉␉␉bp++;␊ |
1474 | ␉␉}␊ |
1475 | ␉␉for (line = 0; *bp != '\1' && line < 23; line++) {␊ |
1476 | ␉␉␉setCursorPosition(0, line, 1);␊ |
1477 | ␉␉␉printf("%s\n", bp);␊ |
1478 | ␉␉␉while (*bp != '\0') {␊ |
1479 | ␉␉␉␉bp++;␊ |
1480 | ␉␉␉}␊ |
1481 | ␉␉␉bp++;␊ |
1482 | ␉␉}␊ |
1483 | ␊ |
1484 | ␉␉setCursorPosition(0, 23, 1);␊ |
1485 | ␉␉if (*bp == '\1') {␊ |
1486 | ␉␉␉printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : "");␊ |
1487 | ␉␉} else {␊ |
1488 | ␉␉␉printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : "");␊ |
1489 | ␉␉}␊ |
1490 | ␊ |
1491 | ␉␉c = getchar();␊ |
1492 | ␉␉if (c == 'q' || c == 'Q') {␊ |
1493 | ␉␉␉break;␊ |
1494 | ␉␉}␊ |
1495 | ␉␉if ((c == 'p' || c == 'P') && line_offset > 0) {␊ |
1496 | ␉␉␉line_offset -= 23;␊ |
1497 | ␉␉}␊ |
1498 | ␉␉if (c == ' ') {␊ |
1499 | ␉␉␉if (*bp == '\1') {␊ |
1500 | ␉␉␉␉break;␊ |
1501 | ␉␉␉} else {␊ |
1502 | ␉␉␉␉line_offset += 23;␊ |
1503 | ␉␉␉}␊ |
1504 | ␉␉}␊ |
1505 | }␊ |
1506 | setActiveDisplayPage(0);␊ |
1507 | }␊ |
1508 | ␊ |
1509 | void showHelp(void)␊ |
1510 | {␊ |
1511 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1512 | ␉␉showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);␊ |
1513 | ␉} else {␊ |
1514 | ␉␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1515 | ␉}␊ |
1516 | }␊ |
1517 | ␊ |
1518 | void showTextFile(const char * filename)␊ |
1519 | {␊ |
1520 | #define MAX_TEXT_FILE_SIZE 65536␊ |
1521 | ␉char␉*buf;␊ |
1522 | ␉int␉fd;␊ |
1523 | ␉int␉size;␊ |
1524 | ␊ |
1525 | ␉if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {␊ |
1526 | ␉␉printf("\nFile not found: %s\n", filename);␊ |
1527 | ␉␉sleep(2);␊ |
1528 | ␉␉return;␊ |
1529 | ␉}␊ |
1530 | ␊ |
1531 | size = file_size(fd);␊ |
1532 | if (size > MAX_TEXT_FILE_SIZE) {␊ |
1533 | ␉␉size = MAX_TEXT_FILE_SIZE;␊ |
1534 | ␉}␊ |
1535 | buf = malloc(size);␊ |
1536 | read(fd, buf, size);␊ |
1537 | close(fd);␊ |
1538 | ␉showTextBuffer(buf, size);␊ |
1539 | ␉free(buf);␊ |
1540 | }␊ |
1541 | ␊ |
1542 | // This is a very simplistic prompting scheme that just grabs two hex characters␊ |
1543 | // Eventually we need to do something more user-friendly like display a menu␊ |
1544 | // based off of the Multiboot device list␊ |
1545 | ␊ |
1546 | int selectAlternateBootDevice(int bootdevice)␊ |
1547 | {␊ |
1548 | ␉int key;␊ |
1549 | ␉int newbootdevice;␊ |
1550 | ␉int digitsI = 0;␊ |
1551 | ␉char *end;␊ |
1552 | ␉char digits[3] = {0,0,0};␊ |
1553 | ␊ |
1554 | ␉// We've already printed the current boot device so user knows what it is␊ |
1555 | ␉printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n");␊ |
1556 | ␉printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice);␊ |
1557 | ␉do {␊ |
1558 | ␉␉key = getchar();␊ |
1559 | ␉␉switch (key & kASCIIKeyMask) {␊ |
1560 | ␉␉case kBackspaceKey:␊ |
1561 | ␉␉␉if (digitsI > 0) {␊ |
1562 | ␉␉␉␉int x, y, t;␊ |
1563 | ␉␉␉␉getCursorPositionAndType(&x, &y, &t);␊ |
1564 | ␉␉␉␉// Assume x is not 0;␊ |
1565 | ␉␉␉␉x--;␊ |
1566 | ␉␉␉␉setCursorPosition(x,y,0); // back up one char␊ |
1567 | ␉␉␉␉// Overwrite with space without moving cursor position␊ |
1568 | ␉␉␉␉putca(' ', 0x07, 1);␊ |
1569 | ␉␉␉␉digitsI--;␊ |
1570 | ␉␉␉} else {␊ |
1571 | ␉␉␉␉// TODO: Beep or something␊ |
1572 | ␉␉␉}␊ |
1573 | ␉␉␉break;␊ |
1574 | ␊ |
1575 | ␉␉case kReturnKey:␊ |
1576 | ␉␉␉digits[digitsI] = '\0';␊ |
1577 | ␉␉␉newbootdevice = strtol(digits, &end, 16);␊ |
1578 | ␉␉␉if (end == digits && *end == '\0') {␊ |
1579 | ␉␉␉␉// User entered empty string␊ |
1580 | ␉␉␉␉printf("\nUsing default boot device %x\n", bootdevice);␊ |
1581 | ␉␉␉␉key = 0;␊ |
1582 | ␉␉␉} else if(end != digits && *end == '\0') {␊ |
1583 | ␉␉␉␉bootdevice = newbootdevice;␊ |
1584 | ␉␉␉␉printf("\n");␊ |
1585 | ␉␉␉␉key = 0; // We gots da boot device␊ |
1586 | ␉␉␉} else {␊ |
1587 | ␉␉␉␉printf("\nCouldn't parse. try again: ");␊ |
1588 | ␉␉␉␉digitsI = 0;␊ |
1589 | ␉␉␉}␊ |
1590 | ␉␉␉break;␊ |
1591 | ␊ |
1592 | ␉␉default:␊ |
1593 | ␉␉␉if (isxdigit(key & kASCIIKeyMask) && digitsI < 2) {␊ |
1594 | ␉␉␉␉putchar(key & kASCIIKeyMask);␊ |
1595 | ␉␉␉␉digits[digitsI++] = key & kASCIIKeyMask;␊ |
1596 | ␉␉␉} else {␊ |
1597 | ␉␉␉␉// TODO: Beep or something␊ |
1598 | ␉␉␉}␊ |
1599 | ␉␉␉break;␊ |
1600 | ␉␉};␊ |
1601 | ␉} while (key != 0);␊ |
1602 | ␊ |
1603 | ␉return bootdevice;␊ |
1604 | }␊ |
1605 | ␊ |
1606 | bool promptForRescanOption(void)␊ |
1607 | {␊ |
1608 | ␉printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");␊ |
1609 | ␉if (getchar() == kReturnKey) {␊ |
1610 | ␉␉return true;␊ |
1611 | ␉} else {␊ |
1612 | ␉␉return false;␊ |
1613 | ␉}␊ |
1614 | }␊ |
1615 | |