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