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