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 | bool showBootBanner = true; //Azi:autoresolution␊ |
35 | static bool shouldboot = false;␊ |
36 | ␊ |
37 | extern int multiboot_timeout;␊ |
38 | extern int multiboot_timeout_set;␊ |
39 | ␊ |
40 | extern BVRef bvChain;␊ |
41 | //extern int␉␉menucount;␊ |
42 | ␊ |
43 | extern int␉␉gDeviceCount;␊ |
44 | ␊ |
45 | int␉␉␉selectIndex = 0;␊ |
46 | MenuItem * menuItems = NULL;␊ |
47 | ␊ |
48 | enum {␊ |
49 | kMenuTopRow = 5,␊ |
50 | kMenuMaxItems = 10,␊ |
51 | kScreenLastRow = 24␊ |
52 | };␊ |
53 | ␊ |
54 | //==========================================================================␊ |
55 | ␊ |
56 | typedef struct {␊ |
57 | int x;␊ |
58 | int y;␊ |
59 | int type;␊ |
60 | } CursorState;␊ |
61 | ␊ |
62 | static void changeCursor( int col, int row, int type, CursorState * cs )␊ |
63 | {␊ |
64 | if (cs) getCursorPositionAndType( &cs->x, &cs->y, &cs->type );␊ |
65 | setCursorType( type );␊ |
66 | setCursorPosition( col, row, 0 );␊ |
67 | }␊ |
68 | ␊ |
69 | static void moveCursor( int col, int row )␊ |
70 | {␊ |
71 | setCursorPosition( col, row, 0 );␊ |
72 | }␊ |
73 | ␊ |
74 | static void restoreCursor( const CursorState * cs )␊ |
75 | {␊ |
76 | setCursorPosition( cs->x, cs->y, 0 );␊ |
77 | setCursorType( cs->type );␊ |
78 | }␊ |
79 | ␊ |
80 | //==========================================================================␊ |
81 | ␊ |
82 | /* Flush keyboard buffer; returns TRUE if any of the flushed␊ |
83 | * characters was F8.␊ |
84 | */␊ |
85 | ␊ |
86 | static bool flushKeyboardBuffer(void)␊ |
87 | {␊ |
88 | bool status = false;␊ |
89 | ␊ |
90 | while ( readKeyboardStatus() ) {␊ |
91 | if (bgetc() == 0x4200) status = true;␊ |
92 | }␊ |
93 | return status;␊ |
94 | }␊ |
95 | ␊ |
96 | //==========================================================================␊ |
97 | ␊ |
98 | static int countdown( const char * msg, int row, int timeout )␊ |
99 | {␊ |
100 | unsigned long time;␊ |
101 | int ch = 0;␊ |
102 | int col = strlen(msg) + 1;␊ |
103 | ␉␊ |
104 | flushKeyboardBuffer();␊ |
105 | ␊ |
106 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
107 | ␉{␊ |
108 | ␉␉moveCursor( 0, row );␊ |
109 | ␉␉printf(msg);␊ |
110 | ␊ |
111 | ␉} else {␊ |
112 | ␊ |
113 | ␉␉position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );␊ |
114 | ␉␊ |
115 | ␉␉char dummy[80];␊ |
116 | ␉␉getBootVolumeDescription( gBootVolume, dummy, sizeof(dummy) - 1, true );␊ |
117 | ␉␉drawDeviceIcon( gBootVolume, gui.screen.pixmap, p, true );␊ |
118 | ␉␉drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );␊ |
119 | ␉␉␊ |
120 | ␉␉// make this screen the new background␊ |
121 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
122 | ␉␉␊ |
123 | ␉}␊ |
124 | ␊ |
125 | ␉int multi_buff = 18 * (timeout);␊ |
126 | int multi = ++multi_buff;␊ |
127 | ␊ |
128 | int lasttime=0;␊ |
129 | ␊ |
130 | for ( time = time18(), timeout++; timeout > 0; )␊ |
131 | {␊ |
132 | ␉␉if( time18() > lasttime)␊ |
133 | ␉␉{␊ |
134 | ␉␉␉multi--; ␊ |
135 | ␉␉␉lasttime=time18();␊ |
136 | ␉␉}␉␉␊ |
137 | ␊ |
138 | if (ch = readKeyboardStatus())␊ |
139 | break;␊ |
140 | ␊ |
141 | // Count can be interrupted by holding down shift,␊ |
142 | // control or alt key␊ |
143 | if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 )␊ |
144 | ␉␉{␊ |
145 | ch = 1;␊ |
146 | break;␊ |
147 | }␊ |
148 | ␊ |
149 | if ( time18() >= time )␊ |
150 | {␊ |
151 | time += 18;␊ |
152 | timeout--;␊ |
153 | ␊ |
154 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
155 | ␉␉␉{␊ |
156 | ␉␉␉␉moveCursor( col, row );␊ |
157 | ␉␉␉␉printf("(%d) ", timeout);␊ |
158 | ␉␉␉}␊ |
159 | }␊ |
160 | ␉␊ |
161 | ␉␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
162 | ␉␉{␊ |
163 | ␉␉␉drawProgressBar( gui.screen.pixmap, 100, gui.progressbar.pos , ( multi * 100 / multi_buff ) );␊ |
164 | ␉␉␉gui.redraw = true;␊ |
165 | ␉␉␉updateVRAM();␊ |
166 | ␉␉}␊ |
167 | ␊ |
168 | }␊ |
169 | ␊ |
170 | flushKeyboardBuffer();␊ |
171 | ␊ |
172 | return ch;␊ |
173 | }␊ |
174 | ␊ |
175 | //==========================================================================␊ |
176 | ␊ |
177 | char gBootArgs[BOOT_STRING_LEN];␊ |
178 | static char * gBootArgsPtr = gBootArgs;␊ |
179 | static char * gBootArgsEnd = gBootArgs + BOOT_STRING_LEN - 1;␊ |
180 | static char booterCommand[BOOT_STRING_LEN];␊ |
181 | static char booterParam[BOOT_STRING_LEN];␊ |
182 | ␊ |
183 | static void clearBootArgs(void)␊ |
184 | {␊ |
185 | ␉gBootArgsPtr = gBootArgs;␊ |
186 | ␉memset(gBootArgs, '\0', BOOT_STRING_LEN);␊ |
187 | ␊ |
188 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
189 | ␉␉clearGraphicBootPrompt();␊ |
190 | ␉}␊ |
191 | }␊ |
192 | ␊ |
193 | static void addBootArg(const char * argStr)␊ |
194 | {␊ |
195 | ␉if ( (gBootArgsPtr + strlen(argStr) + 1) < gBootArgsEnd)␊ |
196 | ␉{␊ |
197 | ␉␉*gBootArgsPtr++ = ' ';␊ |
198 | ␉␉strcat(gBootArgs, argStr);␊ |
199 | ␉␉gBootArgsPtr += strlen(argStr);␊ |
200 | ␉}␊ |
201 | }␊ |
202 | ␊ |
203 | //==========================================================================␊ |
204 | ␊ |
205 | static void showBootPrompt(int row, bool visible)␊ |
206 | {␊ |
207 | ␉extern char bootPrompt[];␊ |
208 | ␉extern char bootRescanPrompt[];␊ |
209 | ␊ |
210 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
211 | ␉␉changeCursor( 0, row, kCursorTypeUnderline, 0 ); ␊ |
212 | ␉␉clearScreenRows( row, kScreenLastRow );␊ |
213 | ␉}␊ |
214 | ␊ |
215 | ␉//clearBootArgs();␊ |
216 | ␊ |
217 | ␉if (visible) {␊ |
218 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
219 | ␉␉␉if (gEnableCDROMRescan) {␊ |
220 | ␉␉␉␉printf( bootRescanPrompt );␊ |
221 | ␉␉␉} else {␊ |
222 | ␉␉␉␉printf( bootPrompt );␊ |
223 | printf( gBootArgs );␊ |
224 | ␉␉␉}␊ |
225 | ␉␉}␊ |
226 | ␉} else {␊ |
227 | ␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
228 | //␉␉␉clearGraphicBootPrompt();␊ |
229 | ␉␉} else {␊ |
230 | ␉␉␉printf("Press Enter to start up the foreign OS. ");␊ |
231 | ␉␉}␊ |
232 | ␉}␊ |
233 | }␊ |
234 | ␊ |
235 | //==========================================================================␊ |
236 | ␊ |
237 | static void updateBootArgs( int key )␊ |
238 | {␊ |
239 | key &= kASCIIKeyMask;␊ |
240 | ␊ |
241 | switch ( key )␊ |
242 | {␊ |
243 | case kBackspaceKey:␊ |
244 | if ( gBootArgsPtr > gBootArgs )␊ |
245 | {␊ |
246 | *--gBootArgsPtr = '\0';␊ |
247 | ␊ |
248 | int x, y, t;␊ |
249 | getCursorPositionAndType( &x, &y, &t );␊ |
250 | if ( x == 0 && y )␊ |
251 | {␊ |
252 | x = 80; y--;␊ |
253 | }␊ |
254 | if (x) x--;␊ |
255 | ␊ |
256 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
257 | ␉␉␉␉{␊ |
258 | ␉␉␉␉␉setCursorPosition( x, y, 0 );␊ |
259 | ␉␉␉␉␉putca(' ', 0x07, 1);␊ |
260 | ␉␉␉␉}␊ |
261 | else␊ |
262 | {␊ |
263 | updateGraphicBootPrompt();␊ |
264 | }␊ |
265 | } ␊ |
266 | ␉␉␉break;␊ |
267 | ␊ |
268 | default:␊ |
269 | if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
270 | {␊ |
271 | *gBootArgsPtr++ = key;␊ |
272 | ␊ |
273 | if( bootArgs->Video.v_display != VGA_TEXT_MODE ) updateGraphicBootPrompt();␊ |
274 | else if ( key >= ' ' && key < 0x7f) putchar(key);␊ |
275 | ␉␉␉}␊ |
276 | ␊ |
277 | ␉␉␉break;␊ |
278 | }␊ |
279 | }␊ |
280 | ␊ |
281 | //==========================================================================␊ |
282 | ␊ |
283 | static const MenuItem * gMenuItems = NULL;␊ |
284 | ␊ |
285 | static int gMenuItemCount;␊ |
286 | static int gMenuRow;␊ |
287 | static int gMenuHeight;␊ |
288 | static int gMenuTop;␊ |
289 | static int gMenuBottom;␊ |
290 | static int gMenuSelection;␊ |
291 | ␊ |
292 | static int␉ gMenuStart;␊ |
293 | static int␉ gMenuEnd;␊ |
294 | ␊ |
295 | static void printMenuItem( const MenuItem * item, int highlight )␊ |
296 | {␊ |
297 | printf(" ");␊ |
298 | ␊ |
299 | if ( highlight )␊ |
300 | putca(' ', 0x70, strlen(item->name) + 4);␊ |
301 | else␊ |
302 | putca(' ', 0x07, 40);␊ |
303 | ␊ |
304 | printf(" %40s\n", item->name);␊ |
305 | }␊ |
306 | ␊ |
307 | //==========================================================================␊ |
308 | ␊ |
309 | static void showMenu( const MenuItem * items, int count,␊ |
310 | int selection, int row, int height )␊ |
311 | {␊ |
312 | int i;␊ |
313 | CursorState cursorState;␊ |
314 | ␊ |
315 | if ( items == NULL || count == 0 ) ␊ |
316 | ␉␉return;␊ |
317 | ␊ |
318 | // head and tail points to the start and the end of the list.␊ |
319 | // top and bottom points to the first and last visible items␊ |
320 | // in the menu window.␊ |
321 | ␊ |
322 | gMenuItems␉␉= items;␊ |
323 | gMenuRow␉␉= row;␊ |
324 | gMenuHeight␉␉= height;␊ |
325 | gMenuItemCount␉= count;␊ |
326 | gMenuTop␉␉= 0;␊ |
327 | gMenuBottom␉␉= MIN( count, height ) - 1;␊ |
328 | gMenuSelection␉= selection;␊ |
329 | ␊ |
330 | gMenuStart␉␉= 0;␊ |
331 | gMenuEnd␉ = MIN( count, gui.maxdevices ) - 1;␊ |
332 | ␉␊ |
333 | ␉// If the selected item is not visible, shift the list down.␊ |
334 | ␊ |
335 | if ( gMenuSelection > gMenuBottom )␊ |
336 | {␊ |
337 | gMenuTop += ( gMenuSelection - gMenuBottom );␊ |
338 | gMenuBottom = gMenuSelection;␊ |
339 | }␊ |
340 | ␊ |
341 | ␉if ( gMenuSelection > gMenuEnd )␊ |
342 | {␊ |
343 | ␉␉gMenuStart += ( gMenuSelection - gMenuEnd );␊ |
344 | gMenuEnd = gMenuSelection;␊ |
345 | }␊ |
346 | ␉␊ |
347 | ␉// Draw the visible items.␊ |
348 | ␊ |
349 | ␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
350 | ␉␊ |
351 | ␉␉drawDeviceList(gMenuStart, gMenuEnd, gMenuSelection);␊ |
352 | ␊ |
353 | ␉else {␊ |
354 | ␉␉␊ |
355 | ␉␉changeCursor( 0, row, kCursorTypeHidden, &cursorState );␊ |
356 | ␊ |
357 | ␉␉for ( i = gMenuTop; i <= gMenuBottom; i++ )␊ |
358 | ␉␉{␊ |
359 | ␉␉␉printMenuItem( &items[i], (i == gMenuSelection) );␊ |
360 | ␉␉}␊ |
361 | ␊ |
362 | ␉␉restoreCursor( &cursorState );␊ |
363 | }␊ |
364 | }␊ |
365 | ␊ |
366 | //==========================================================================␊ |
367 | ␊ |
368 | static int updateMenu( int key, void ** paramPtr )␊ |
369 | {␊ |
370 | int moved = 0;␊ |
371 | ␊ |
372 | union {␊ |
373 | struct {␊ |
374 | unsigned int␊ |
375 | selectionUp : 1,␊ |
376 | selectionDown : 1,␊ |
377 | scrollUp : 1,␊ |
378 | scrollDown : 1;␊ |
379 | } f;␊ |
380 | unsigned int w;␊ |
381 | } draw = {{0}};␊ |
382 | ␊ |
383 | if ( gMenuItems == NULL )␊ |
384 | ␉␉return 0;␊ |
385 | ␊ |
386 | ␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
387 | ␉{␊ |
388 | ␉␉int res;␊ |
389 | ␉␉␊ |
390 | ␉␉// set navigation keys for horizontal layout as defaults␊ |
391 | ␉␉int previous␉= 0x4B00;␉␉// left arrow␊ |
392 | ␉␉int subsequent␉= 0x4D00;␉␉// right arrow␊ |
393 | ␉␉int menu␉␉= 0x5000;␉␉// down arrow␊ |
394 | ␉␉␊ |
395 | ␉␉if ( gui.layout == VerticalLayout )␊ |
396 | ␉␉{␊ |
397 | ␉␉␉// set navigation keys for vertical layout␊ |
398 | ␉␉␉previous␉= 0x4800;␉␉// up arrow␊ |
399 | ␉␉␉subsequent␉= 0x5000;␉␉// down arrow␊ |
400 | ␉␉␉menu␉␉= 0x4B00;␉␉// right arrow␊ |
401 | ␉␉} ␊ |
402 | ␊ |
403 | ␉␉if ( key == previous )␊ |
404 | ␉␉{␊ |
405 | ␉␉␉if ( gMenuSelection > gMenuTop )␊ |
406 | ␉␉␉␉draw.f.selectionUp = 1;␊ |
407 | ␉␉␉else if ( gMenuTop > 0 )␊ |
408 | ␉␉␉␉draw.f.scrollDown = 1;␊ |
409 | ␉␉␉␊ |
410 | ␉␉}␊ |
411 | ␉␉␊ |
412 | ␉␉else if ( key == subsequent )␊ |
413 | ␉␉{␊ |
414 | ␉␉␉if ( gMenuSelection != gMenuBottom)␊ |
415 | ␉␉␉␉draw.f.selectionDown = 1;␊ |
416 | ␉␉␉else if ( gMenuBottom < ( gMenuItemCount - 1 ) )␊ |
417 | ␉␉␉␉draw.f.scrollUp = 1;␊ |
418 | ␉␉}␊ |
419 | ␉␉␊ |
420 | ␉␉else if ( key == menu )␊ |
421 | ␉␉{␊ |
422 | ␉␉␉if ( gui.menu.draw )␊ |
423 | ␉␉␉␉updateInfoMenu(key);␊ |
424 | ␉␉␉else␊ |
425 | ␉␉␉␉drawInfoMenu();␊ |
426 | ␉␉}␊ |
427 | ␊ |
428 | ␉␉else if ( gui.menu.draw )␊ |
429 | ␉␉{␊ |
430 | ␉␉␉res = updateInfoMenu(key);␊ |
431 | ␊ |
432 | ␉␉␉if ( res == CLOSE_INFO_MENU )␊ |
433 | ␉␉␉␉gui.menu.draw = false;␊ |
434 | ␉␉␉else␊ |
435 | ␉␉␉{␊ |
436 | ␉␉␉␉shouldboot = ( res != DO_NOT_BOOT );␊ |
437 | ␉␉␉␉␊ |
438 | ␉␉␉␉if ( shouldboot )␊ |
439 | ␉␉␉␉␉gui.menu.draw = false;␊ |
440 | ␊ |
441 | ␉␉␉␉switch (res)␊ |
442 | ␉␉␉␉{␊ |
443 | ␉␉␉␉␉case BOOT_NORMAL:␊ |
444 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
445 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
446 | ␉␉␉␉␉␉break;␊ |
447 | ␉␉␉␉␉␉␊ |
448 | ␉␉␉␉␉case BOOT_VERBOSE:␊ |
449 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
450 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
451 | ␉␉␉␉␉␉addBootArg(kVerboseModeFlag);␊ |
452 | ␉␉␉␉␉␉break;␊ |
453 | ␉␉␉␉␉␉␊ |
454 | ␉␉␉␉␉case BOOT_IGNORECACHE:␊ |
455 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
456 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
457 | ␉␉␉␉␉␉addBootArg(kIgnoreCachesFlag);␊ |
458 | ␉␉␉␉␉␉break;␊ |
459 | ␉␉␉␉␉␉␊ |
460 | ␉␉␉␉␉case BOOT_SINGLEUSER:␊ |
461 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
462 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
463 | ␉␉␉␉␉␉addBootArg(kSingleUserModeFlag);␊ |
464 | ␉␉␉␉␉␉break;␊ |
465 | ␉␉␉␉}␊ |
466 | ␉␉␉␉␊ |
467 | ␉␉␉}␊ |
468 | ␉␉␉␊ |
469 | ␉␉}␉␊ |
470 | ␉␉␉␊ |
471 | ␉} else {␊ |
472 | ␉␉switch ( key )␊ |
473 | ␉␉{␊ |
474 | ␉case 0x4800: // Up Arrow␊ |
475 | ␉␉␉␉if ( gMenuSelection != gMenuTop )␊ |
476 | ␉␉␉␉␉draw.f.selectionUp = 1;␊ |
477 | ␉␉␉␉else if ( gMenuTop > 0 )␊ |
478 | ␉␉␉␉␉draw.f.scrollDown = 1;␊ |
479 | ␉␉␉␉break;␊ |
480 | ␊ |
481 | ␉␉␉case 0x5000: // Down Arrow␊ |
482 | ␉␉␉␉if ( gMenuSelection != gMenuBottom )␊ |
483 | ␉␉␉␉␉draw.f.selectionDown = 1;␊ |
484 | ␉␉␉␉else if ( gMenuBottom < (gMenuItemCount - 1) ) ␊ |
485 | ␉␉␉␉␉draw.f.scrollUp = 1;␊ |
486 | ␉␉␉␉break;␊ |
487 | ␉␉}␊ |
488 | ␉}␊ |
489 | ␊ |
490 | if ( draw.w )␊ |
491 | {␊ |
492 | if ( draw.f.scrollUp )␊ |
493 | {␊ |
494 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, 1);␊ |
495 | gMenuTop++; gMenuBottom++;␊ |
496 | ␉␉␉gMenuStart++; gMenuEnd++;␊ |
497 | draw.f.selectionDown = 1;␊ |
498 | }␊ |
499 | ␊ |
500 | if ( draw.f.scrollDown )␊ |
501 | {␊ |
502 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, -1);␊ |
503 | gMenuTop--; gMenuBottom--;␊ |
504 | gMenuStart--; gMenuEnd--;␊ |
505 | draw.f.selectionUp = 1;␊ |
506 | }␊ |
507 | ␊ |
508 | if ( draw.f.selectionUp || draw.f.selectionDown )␊ |
509 | {␊ |
510 | ␊ |
511 | ␉␉␉CursorState cursorState;␊ |
512 | ␊ |
513 | ␉␉␉// Set cursor at current position, and clear inverse video.␊ |
514 | ␉␊ |
515 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
516 | ␉␉␉{␊ |
517 | ␉␉␉␉changeCursor( 0, gMenuRow + gMenuSelection - gMenuTop, kCursorTypeHidden, &cursorState );␊ |
518 | ␉␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 0 );␊ |
519 | ␉␉␉}␊ |
520 | ␊ |
521 | ␉␉␉if ( draw.f.selectionUp )␊ |
522 | ␉␉␉{␊ |
523 | ␉␉␉␉gMenuSelection--;␊ |
524 | ␉␉␉␉if(( gMenuSelection - gMenuStart) == -1 )␊ |
525 | ␉␉␉␉{␊ |
526 | ␉␉␉␉␉gMenuStart--;␊ |
527 | ␉␉␉␉␉gMenuEnd--;␊ |
528 | ␉␉␉␉}␊ |
529 | ␉␉␉␉␊ |
530 | ␉␉␉} else {␊ |
531 | ␉␉␉gMenuSelection++;␊ |
532 | ␉␉␉if(( gMenuSelection - ( gui.maxdevices - 1) - gMenuStart) > 0 )␊ |
533 | ␉␉␉{␊ |
534 | ␉␉␉␉gMenuStart++;␊ |
535 | ␉␉␉␉gMenuEnd++;␊ |
536 | ␉␉␉}␊ |
537 | ␉ }␊ |
538 | ␊ |
539 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
540 | ␉ {␊ |
541 | ␉␉␉moveCursor( 0, gMenuRow + gMenuSelection - gMenuTop );␊ |
542 | ␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 1 );␊ |
543 | ␉␉␉restoreCursor( &cursorState );␊ |
544 | ␊ |
545 | ␉ } else␊ |
546 | ␊ |
547 | ␉␉␉drawDeviceList (gMenuStart, gMenuEnd, gMenuSelection);␊ |
548 | ␊ |
549 | ␉}␊ |
550 | ␊ |
551 | *paramPtr = gMenuItems[gMenuSelection].param; ␊ |
552 | moved = 1;␊ |
553 | }␊ |
554 | ␊ |
555 | ␉return moved;␊ |
556 | }␊ |
557 | ␊ |
558 | //==========================================================================␊ |
559 | ␊ |
560 | static void skipblanks( const char ** cpp ) ␊ |
561 | {␊ |
562 | while ( **(cpp) == ' ' || **(cpp) == '\t' ) ++(*cpp);␊ |
563 | }␊ |
564 | ␊ |
565 | //==========================================================================␊ |
566 | ␊ |
567 | static const char * extractKernelName( char ** cpp )␊ |
568 | {␊ |
569 | char * kn = *cpp;␊ |
570 | char * cp = *cpp;␊ |
571 | char c;␊ |
572 | ␊ |
573 | // Convert char to lower case.␊ |
574 | ␊ |
575 | c = *cp | 0x20;␊ |
576 | ␊ |
577 | // Must start with a letter or a '/'.␊ |
578 | ␊ |
579 | if ( (c < 'a' || c > 'z') && ( c != '/' ) )␊ |
580 | return 0;␊ |
581 | ␊ |
582 | // Keep consuming characters until we hit a separator.␊ |
583 | ␊ |
584 | while ( *cp && (*cp != '=') && (*cp != ' ') && (*cp != '\t') )␊ |
585 | cp++;␊ |
586 | ␊ |
587 | // Only SPACE or TAB separator is accepted.␊ |
588 | // Reject everything else.␊ |
589 | ␊ |
590 | if (*cp == '=')␊ |
591 | return 0;␊ |
592 | ␊ |
593 | // Overwrite the separator, and move the pointer past␊ |
594 | // the kernel name.␊ |
595 | ␊ |
596 | if (*cp != '\0') *cp++ = '\0';␊ |
597 | *cpp = cp;␊ |
598 | ␊ |
599 | return kn;␊ |
600 | }␊ |
601 | ␊ |
602 | //==========================================================================␊ |
603 | ␊ |
604 | static void␊ |
605 | printMemoryInfo(void)␊ |
606 | {␊ |
607 | int line;␊ |
608 | int i;␊ |
609 | MemoryRange *mp = bootInfo->memoryMap;␊ |
610 | ␊ |
611 | // Activate and clear page 1␊ |
612 | setActiveDisplayPage(1);␊ |
613 | clearScreenRows(0, 24);␊ |
614 | setCursorPosition( 0, 0, 1 );␊ |
615 | ␊ |
616 | printf("BIOS reported memory ranges:\n");␊ |
617 | line = 1;␊ |
618 | for (i=0; i<bootInfo->memoryMapCount; i++) {␊ |
619 | printf("Base 0x%08x%08x, ",␊ |
620 | (unsigned long)(mp->base >> 32),␊ |
621 | (unsigned long)(mp->base));␊ |
622 | printf("length 0x%08x%08x, type %d\n",␊ |
623 | (unsigned long)(mp->length >> 32),␊ |
624 | (unsigned long)(mp->length),␊ |
625 | mp->type);␊ |
626 | if (line++ > 20) {␊ |
627 | pause();␊ |
628 | line = 0;␊ |
629 | }␊ |
630 | mp++;␊ |
631 | }␊ |
632 | if (line > 0) {␊ |
633 | pause();␊ |
634 | }␊ |
635 | ␊ |
636 | setActiveDisplayPage(0);␊ |
637 | }␊ |
638 | ␊ |
639 | char *getMemoryInfoString()␊ |
640 | {␊ |
641 | int i;␊ |
642 | MemoryRange *mp = bootInfo->memoryMap;␊ |
643 | ␉char *buff = malloc(sizeof(char)*1024);␊ |
644 | ␉if(!buff) return 0;␊ |
645 | ␉␊ |
646 | ␉char info[] = "BIOS reported memory ranges:\n";␊ |
647 | ␉sprintf(buff, "%s", info);␊ |
648 | for (i=0; i<bootInfo->memoryMapCount; i++) {␊ |
649 | sprintf( buff+strlen(buff), "Base 0x%08x%08x, ",␊ |
650 | (unsigned long)(mp->base >> 32),␊ |
651 | (unsigned long)(mp->base));␊ |
652 | sprintf( buff+strlen(buff), "length 0x%08x%08x, type %d\n",␊ |
653 | (unsigned long)(mp->length >> 32),␊ |
654 | (unsigned long)(mp->length),␊ |
655 | mp->type);␊ |
656 | mp++;␊ |
657 | }␊ |
658 | ␉return buff;␊ |
659 | }␊ |
660 | ␊ |
661 | //==========================================================================␊ |
662 | ␊ |
663 | void lspci(void)␊ |
664 | {␊ |
665 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) { ␊ |
666 | ␉␉setActiveDisplayPage(1);␊ |
667 | ␉␉clearScreenRows(0, 24);␊ |
668 | ␉␉setCursorPosition(0, 0, 1);␊ |
669 | ␉}␊ |
670 | ␊ |
671 | ␉dump_pci_dt(root_pci_dev->children);␊ |
672 | ␊ |
673 | ␉pause();␊ |
674 | ␊ |
675 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
676 | ␉␉setActiveDisplayPage(0);␊ |
677 | ␉}␊ |
678 | }␊ |
679 | ␊ |
680 | //==========================================================================␊ |
681 | ␊ |
682 | int getBootOptions(bool firstRun)␊ |
683 | {␊ |
684 | ␉int i;␊ |
685 | ␉int key;␊ |
686 | ␉int nextRow;␊ |
687 | ␉int timeout;␊ |
688 | ␉int bvCount;␊ |
689 | ␉BVRef bvr;␊ |
690 | ␉BVRef menuBVR;␊ |
691 | ␉bool showPrompt, newShowPrompt, isCDROM;␊ |
692 | ␊ |
693 | ␉// Initialize default menu selection entry.␊ |
694 | ␉gBootVolume = menuBVR = selectBootVolume(bvChain);␊ |
695 | ␊ |
696 | ␉if (biosDevIsCDROM(gBIOSDev)) {␊ |
697 | ␉␉isCDROM = true;␊ |
698 | ␉} else {␊ |
699 | ␉␉isCDROM = false;␊ |
700 | ␉}␊ |
701 | ␊ |
702 | ␉// ensure we're in graphics mode if gui is setup␊ |
703 | ␉if (firstRun && gui.initialised && bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
704 | ␉{␊ |
705 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
706 | ␉}␊ |
707 | ␊ |
708 | ␉// Clear command line boot arguments␊ |
709 | ␉clearBootArgs();␊ |
710 | ␊ |
711 | ␉// Allow user to override default timeout.␊ |
712 | ␉if (multiboot_timeout_set) {␊ |
713 | ␉␉timeout = multiboot_timeout;␊ |
714 | ␉} else if (!getIntForKey(kTimeoutKey, &timeout, &bootInfo->bootConfig)) {␊ |
715 | ␉␉/* If there is no timeout key in the file use the default timeout␊ |
716 | ␉␉ which is different for CDs vs. hard disks. However, if not booting␊ |
717 | ␉␉ a CD and no config file could be loaded set the timeout␊ |
718 | ␉␉ to zero which causes the menu to display immediately.␊ |
719 | ␉␉ This way, if no partitions can be found, that is the disk is unpartitioned␊ |
720 | ␉␉ or simply cannot be read) then an empty menu is displayed.␊ |
721 | ␉␉ If some partitions are found, for example a Windows partition, then␊ |
722 | ␉␉ these will be displayed in the menu as foreign partitions.␊ |
723 | ␉␉ */␊ |
724 | ␉␉if (isCDROM) {␊ |
725 | ␉␉␉timeout = kCDBootTimeout;␊ |
726 | ␉␉} else {␊ |
727 | ␉␉␉timeout = sysConfigValid ? kBootTimeout : 0;␊ |
728 | ␉␉}␊ |
729 | ␉}␊ |
730 | ␊ |
731 | ␉if (timeout < 0) {␊ |
732 | ␉␉gBootMode |= kBootModeQuiet;␊ |
733 | ␉}␊ |
734 | ␊ |
735 | ␉// If the user is holding down a modifier key, enter safe mode.␊ |
736 | ␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
737 | ␉␉gBootMode |= kBootModeSafe;␊ |
738 | ␉}␊ |
739 | ␊ |
740 | ␉// Checking user pressed keys␊ |
741 | ␉bool f8press = false, spress = false, vpress = false;␊ |
742 | ␉while (readKeyboardStatus()) {␊ |
743 | ␉␉key = bgetc ();␊ |
744 | ␉␉if (key == 0x4200) f8press = true;␊ |
745 | ␉␉if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true;␊ |
746 | ␉␉if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true;␊ |
747 | ␉}␊ |
748 | ␉// If user typed F8, abort quiet mode, and display the menu.␊ |
749 | ␉if (f8press) {␊ |
750 | ␉␉gBootMode &= ~kBootModeQuiet;␊ |
751 | ␉␉timeout = 0;␊ |
752 | ␉}␊ |
753 | ␉// If user typed 'v' or 'V', boot in verbose mode.␊ |
754 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && vpress) {␊ |
755 | ␉␉addBootArg(kVerboseModeFlag);␊ |
756 | ␉}␊ |
757 | ␉// If user typed 's' or 'S', boot in single user mode.␊ |
758 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && spress) {␊ |
759 | ␉␉addBootArg(kSingleUserModeFlag);␊ |
760 | ␉}␊ |
761 | ␊ |
762 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
763 | ␉␉setCursorPosition(0, 0, 0);␊ |
764 | ␉␉clearScreenRows(0, kScreenLastRow);␊ |
765 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
766 | ␉␉␉// Display banner and show hardware info.␊ |
767 | ␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
768 | ␉␉␉printf(getVBEInfoString());␊ |
769 | ␉␉}␊ |
770 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
771 | ␉␉verbose("Scanning device %x...", gBIOSDev);␊ |
772 | ␉}␊ |
773 | ␊ |
774 | ␉// When booting from CD, default to hard drive boot when possible. ␊ |
775 | ␉if (isCDROM && firstRun) {␊ |
776 | ␉␉const char *val;␊ |
777 | ␉␉char *prompt = NULL;␊ |
778 | ␉␉char *name = NULL;␊ |
779 | ␉␉int cnt;␊ |
780 | ␉␉int optionKey;␊ |
781 | ␊ |
782 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig)) {␊ |
783 | ␉␉␉prompt = malloc(cnt + 1);␊ |
784 | ␉␉␉strncat(prompt, val, cnt);␊ |
785 | ␉␉} else {␊ |
786 | ␉␉␉name = malloc(80);␊ |
787 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 79, false);␊ |
788 | ␉␉␉prompt = malloc(256);␊ |
789 | ␉␉␉sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);␊ |
790 | ␉␉␉free(name);␊ |
791 | ␉␉}␊ |
792 | ␊ |
793 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig )) {␊ |
794 | ␉␉␉// The key specified is a special key.␊ |
795 | ␉␉} else {␊ |
796 | ␉␉␉// Default to F8.␊ |
797 | ␉␉␉optionKey = 0x4200;␊ |
798 | ␉␉}␊ |
799 | ␊ |
800 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
801 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
802 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
803 | ␉␉if (timeout != 0) {␊ |
804 | ␉␉␉key = countdown(prompt, kMenuTopRow, timeout);␊ |
805 | ␉␉} else {␊ |
806 | ␉␉␉key = optionKey;␊ |
807 | ␉␉}␊ |
808 | ␊ |
809 | ␉␉if (prompt != NULL) {␊ |
810 | ␉␉␉free(prompt);␊ |
811 | ␉␉}␊ |
812 | ␊ |
813 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
814 | ␊ |
815 | ␉␉// Hit the option key ?␊ |
816 | ␉␉if (key == optionKey) {␊ |
817 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
818 | ␉␉␉timeout = 0;␊ |
819 | ␉␉} else {␊ |
820 | ␉␉␉key = key & 0xFF;␊ |
821 | ␊ |
822 | ␉␉␉// Try booting hard disk if user pressed 'h'␊ |
823 | ␉␉␉if (biosDevIsCDROM(gBIOSDev) && key == 'h') {␊ |
824 | ␉␉␉␉BVRef bvr;␊ |
825 | ␊ |
826 | ␉␉␉␉// Look at partitions hosting OS X other than the CD-ROM␊ |
827 | ␉␉␉␉for (bvr = bvChain; bvr; bvr=bvr->next) {␊ |
828 | ␉␉␉␉␉if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) {␊ |
829 | ␉␉␉␉␉␉gBootVolume = bvr;␊ |
830 | ␉␉␉␉␉}␊ |
831 | ␉␉␉␉}␊ |
832 | ␉␉␉}␊ |
833 | ␉␉␉goto done;␊ |
834 | ␉␉}␊ |
835 | ␉}␊ |
836 | ␊ |
837 | ␉if (gBootMode & kBootModeQuiet) {␊ |
838 | ␉␉// No input allowed from user.␊ |
839 | ␉␉goto done;␊ |
840 | ␉}␊ |
841 | ␊ |
842 | ␉if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) {␊ |
843 | ␉␉// If the user is holding down a modifier key,␊ |
844 | ␉␉// enter safe mode.␊ |
845 | ␉␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
846 | ␉␉␉gBootMode |= kBootModeSafe;␊ |
847 | ␉␉}␊ |
848 | ␉␉goto done;␊ |
849 | ␉}␊ |
850 | ␊ |
851 | ␉if (gDeviceCount) {␊ |
852 | ␉␉// Allocate memory for an array of menu items.␊ |
853 | ␉␉menuItems = malloc(sizeof(MenuItem) * gDeviceCount);␊ |
854 | ␉␉if (menuItems == NULL) {␊ |
855 | ␉␉␉goto done;␊ |
856 | ␉␉}␊ |
857 | ␊ |
858 | ␉␉// Associate a menu item for each BVRef.␊ |
859 | ␉␉for (bvr=bvChain, i=gDeviceCount-1, selectIndex=0; bvr; bvr=bvr->next) {␊ |
860 | ␉␉␉if (bvr->visible) {␊ |
861 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true);␊ |
862 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
863 | ␉␉␉␉if (bvr == menuBVR) {␊ |
864 | ␉␉␉␉␉selectIndex = i;␊ |
865 | ␉␉␉␉}␊ |
866 | ␉␉␉␉i--;␊ |
867 | ␉␉␉}␊ |
868 | ␉␉}␊ |
869 | ␉}␊ |
870 | ␊ |
871 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
872 | ␉␉// redraw the background buffer␊ |
873 | ␉␉gui.logo.draw = true;␊ |
874 | ␉␉drawBackground();␊ |
875 | ␉␉gui.devicelist.draw = true;␊ |
876 | ␉␉gui.redraw = true;␊ |
877 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
878 | //␉␉␉bool showBootBanner = true; //Azi:autoresolution␊ |
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 | |