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