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 | static void addBootArg(const char * argStr)␊ |
194 | {␊ |
195 | ␉if ( (gBootArgsPtr + strlen(argStr) + 1) < gBootArgsEnd)␊ |
196 | ␉{␊ |
197 | ␉␉*gBootArgsPtr++ = ' ';␊ |
198 | ␉␉strcat(gBootArgs, argStr);␊ |
199 | ␉␉gBootArgsPtr += strlen(argStr);␊ |
200 | ␉}␊ |
201 | }␊ |
202 | ␊ |
203 | //==========================================================================␊ |
204 | ␊ |
205 | static void showBootPrompt(int row, bool visible)␊ |
206 | {␊ |
207 | ␉extern char bootPrompt[];␊ |
208 | ␉extern char bootRescanPrompt[];␊ |
209 | ␊ |
210 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
211 | ␉␉changeCursor( 0, row, kCursorTypeUnderline, 0 ); ␊ |
212 | ␉␉clearScreenRows( row, kScreenLastRow );␊ |
213 | ␉}␊ |
214 | ␊ |
215 | ␉clearBootArgs();␊ |
216 | ␊ |
217 | ␉if (visible) {␊ |
218 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
219 | ␉␉␉if (gEnableCDROMRescan) {␊ |
220 | ␉␉␉␉printf( bootRescanPrompt );␊ |
221 | ␉␉␉} else {␊ |
222 | ␉␉␉␉printf( bootPrompt );␊ |
223 | ␉␉␉}␊ |
224 | ␉␉}␊ |
225 | ␉} else {␊ |
226 | ␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
227 | ␉␉␉clearGraphicBootPrompt();␊ |
228 | ␉␉} else {␊ |
229 | ␉␉␉printf("Press Enter to start up the foreign OS. ");␊ |
230 | ␉␉}␊ |
231 | ␉}␊ |
232 | }␊ |
233 | ␊ |
234 | //==========================================================================␊ |
235 | ␊ |
236 | static void updateBootArgs( int key )␊ |
237 | {␊ |
238 | key &= kASCIIKeyMask;␊ |
239 | ␊ |
240 | switch ( key )␊ |
241 | {␊ |
242 | case kBackspaceKey:␊ |
243 | if ( gBootArgsPtr > gBootArgs )␊ |
244 | {␊ |
245 | int x, y, t;␊ |
246 | getCursorPositionAndType( &x, &y, &t );␊ |
247 | if ( x == 0 && y )␊ |
248 | {␊ |
249 | x = 80; y--;␊ |
250 | }␊ |
251 | if (x)␊ |
252 | ␉␉␉␉␉x--;␊ |
253 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
254 | ␉␉␉␉{␊ |
255 | ␉␉␉␉␉setCursorPosition( x, y, 0 );␊ |
256 | ␉␉␉␉␉putca(' ', 0x07, 1);␊ |
257 | ␉␉␉␉} else␊ |
258 | ␉␉␉␉␉updateGraphicBootPrompt(kBackspaceKey);␊ |
259 | ␉␉␉␊ |
260 | ␉␉␉␉*gBootArgsPtr-- = '\0';␊ |
261 | ␉␉␉}␊ |
262 | ␊ |
263 | ␉␉␉break;␊ |
264 | ␊ |
265 | default:␊ |
266 | if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
267 | {␊ |
268 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
269 | ␉␉␉␉␉putchar(key); // echo to screen␊ |
270 | ␉␉␉␉else␊ |
271 | ␉␉␉␉␉updateGraphicBootPrompt(key);␊ |
272 | ␉␉␉*gBootArgsPtr++ = 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 == GRAPHICS_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 == GRAPHICS_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 (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;␊ |
776 | ␉␉char *name;␊ |
777 | ␉␉int cnt;␊ |
778 | ␉␉int optionKey;␊ |
779 | ␊ |
780 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig)) {␊ |
781 | ␉␉␉cnt += 1;␊ |
782 | ␉␉␉prompt = malloc(cnt);␊ |
783 | ␉␉␉strlcpy(prompt, val, cnt);␊ |
784 | ␉␉} else {␊ |
785 | ␉␉␉name = malloc(80);␊ |
786 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 80, false);␊ |
787 | ␉␉␉prompt = malloc(256);␊ |
788 | ␉␉␉sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);␊ |
789 | ␉␉␉free(name);␊ |
790 | ␉␉␉cnt = 0;␊ |
791 | ␉␉}␊ |
792 | ␊ |
793 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig )) {␊ |
794 | ␉␉␉// The key specified is a special key.␊ |
795 | ␉␉} else if (getValueForKey( kCDROMOptionKey, &val, &cnt, &bootInfo->bootConfig ) && cnt >= 1) {␊ |
796 | ␉␉␉optionKey = val[0];␊ |
797 | ␉␉} else {␊ |
798 | ␉␉␉// Default to F8.␊ |
799 | ␉␉␉optionKey = 0x4200;␊ |
800 | ␉␉}␊ |
801 | ␊ |
802 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
803 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
804 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
805 | ␉␉if (timeout != 0) {␊ |
806 | ␉␉␉key = countdown(prompt, kMenuTopRow, timeout);␊ |
807 | ␉␉} else {␊ |
808 | ␉␉␉key = optionKey;␊ |
809 | ␉␉}␊ |
810 | ␊ |
811 | ␉␉if (cnt) {␊ |
812 | ␉␉␉free(prompt);␊ |
813 | ␉␉}␊ |
814 | ␊ |
815 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
816 | ␊ |
817 | ␉␉// Hit the option key ?␊ |
818 | ␉␉if (key == optionKey) {␊ |
819 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
820 | ␉␉␉timeout = 0;␊ |
821 | ␉␉} else {␊ |
822 | ␉␉␉key = key & 0xFF;␊ |
823 | ␊ |
824 | ␉␉␉// Try booting hard disk if user pressed 'h'␊ |
825 | ␉␉␉if (biosDevIsCDROM(gBIOSDev) && key == 'h') {␊ |
826 | ␉␉␉␉BVRef bvr;␊ |
827 | ␊ |
828 | ␉␉␉␉// Look at partitions hosting OS X other than the CD-ROM␊ |
829 | ␉␉␉␉for (bvr = bvChain; bvr; bvr=bvr->next) {␊ |
830 | ␉␉␉␉␉if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) {␊ |
831 | ␉␉␉␉␉␉gBootVolume = bvr;␊ |
832 | ␉␉␉␉␉}␊ |
833 | ␉␉␉␉}␊ |
834 | ␉␉␉}␊ |
835 | ␉␉␉goto done;␊ |
836 | ␉␉}␊ |
837 | ␉}␊ |
838 | ␊ |
839 | ␉if (gBootMode & kBootModeQuiet) {␊ |
840 | ␉␉// No input allowed from user.␊ |
841 | ␉␉goto done;␊ |
842 | ␉}␊ |
843 | ␊ |
844 | ␉if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) {␊ |
845 | ␉␉// If the user is holding down a modifier key,␊ |
846 | ␉␉// enter safe mode.␊ |
847 | ␉␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
848 | ␉␉␉gBootMode |= kBootModeSafe;␊ |
849 | ␉␉}␊ |
850 | ␉␉goto done;␊ |
851 | ␉}␊ |
852 | ␊ |
853 | ␉if (gDeviceCount) {␊ |
854 | ␉␉// Allocate memory for an array of menu items.␊ |
855 | ␉␉menuItems = malloc(sizeof(MenuItem) * gDeviceCount);␊ |
856 | ␉␉if (menuItems == NULL) {␊ |
857 | ␉␉␉goto done;␊ |
858 | ␉␉}␊ |
859 | ␊ |
860 | ␉␉// Associate a menu item for each BVRef.␊ |
861 | ␉␉for (bvr=bvChain, i=gDeviceCount-1, selectIndex=0; bvr; bvr=bvr->next) {␊ |
862 | ␉␉␉if (bvr->visible) {␊ |
863 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, 80, true);␊ |
864 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
865 | ␉␉␉␉if (bvr == menuBVR) {␊ |
866 | ␉␉␉␉␉selectIndex = i;␊ |
867 | ␉␉␉␉}␊ |
868 | ␉␉␉␉i--;␊ |
869 | ␉␉␉}␊ |
870 | ␉␉}␊ |
871 | ␉}␊ |
872 | ␊ |
873 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
874 | ␉␉// redraw the background buffer␊ |
875 | ␉␉gui.logo.draw = true;␊ |
876 | ␉␉drawBackground();␊ |
877 | ␉␉gui.devicelist.draw = true;␊ |
878 | ␉␉gui.redraw = true;␊ |
879 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
880 | ␉␉␉bool showBootBanner = true;␊ |
881 | ␊ |
882 | ␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
883 | ␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->bootConfig); ␊ |
884 | ␉␉␉if (showBootBanner) {␊ |
885 | ␉␉␉␉// Display banner and show hardware info.␊ |
886 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
887 | ␉␉␉}␊ |
888 | ␊ |
889 | ␉␉␉// redraw background␊ |
890 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
891 | ␉␉}␊ |
892 | ␉} else {␊ |
893 | ␉␉// Clear screen and hide the blinking cursor.␊ |
894 | ␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
895 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
896 | ␉}␊ |
897 | ␊ |
898 | ␉nextRow = kMenuTopRow;␊ |
899 | ␉showPrompt = true;␊ |
900 | ␊ |
901 | ␉if (gDeviceCount) {␊ |
902 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
903 | ␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
904 | ␉␉}␊ |
905 | ␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
906 | ␉␉nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;␊ |
907 | ␉}␊ |
908 | ␊ |
909 | ␉// Show the boot prompt.␊ |
910 | ␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
911 | ␉showBootPrompt( nextRow, showPrompt );␊ |
912 | ␉␊ |
913 | ␉do {␊ |
914 | ␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
915 | ␉␉␉// redraw background␊ |
916 | ␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
917 | ␉␉␉// reset cursor co-ords␊ |
918 | ␉␉␉gui.debug.cursor = pos( gui.screen.width - 160 , 10 );␊ |
919 | ␉␉}␊ |
920 | ␉␉key = getc();␊ |
921 | ␉␉updateMenu( key, (void **) &menuBVR );␊ |
922 | ␉␉newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
923 | ␊ |
924 | ␉␉if (newShowPrompt != showPrompt) {␊ |
925 | ␉␉␉showPrompt = newShowPrompt;␊ |
926 | ␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
927 | ␉␉}␊ |
928 | ␊ |
929 | ␉␉if (showPrompt) {␊ |
930 | ␉␉␉updateBootArgs(key);␊ |
931 | ␉␉}␊ |
932 | ␊ |
933 | ␉␉switch (key) {␊ |
934 | ␉␉case kReturnKey:␊ |
935 | ␉␉␉if (gui.menu.draw) { ␊ |
936 | ␉␉␉␉key=0;␊ |
937 | ␉␉␉␉break;␊ |
938 | ␉␉␉}␊ |
939 | ␉␉␉if (*gBootArgs == '?') {␊ |
940 | ␉␉␉␉char * argPtr = gBootArgs;␊ |
941 | ␊ |
942 | ␉␉␉␉// Skip the leading "?" character.␊ |
943 | ␉␉␉␉argPtr++;␊ |
944 | ␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
945 | ␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
946 | ␊ |
947 | ␉␉␉␉/*␊ |
948 | ␉␉␉␉* TODO: this needs to be refactored.␊ |
949 | ␉␉␉␉*/␊ |
950 | ␉␉␉␉if (strcmp( booterCommand, "video" ) == 0) {␊ |
951 | ␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
952 | ␉␉␉␉␉␉showInfoBox(getVBEInfoString(), getVBEModeInfoString());␊ |
953 | ␉␉␉␉␉} else {␊ |
954 | ␉␉␉␉␉␉printVBEModeInfo();␊ |
955 | ␉␉␉␉␉}␊ |
956 | ␉␉␉␉} else if ( strcmp( booterCommand, "memory" ) == 0) {␊ |
957 | ␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE ) {␊ |
958 | ␉␉␉␉␉␉showInfoBox("Memory Map", getMemoryInfoString());␊ |
959 | ␉␉␉␉␉} else {␊ |
960 | ␉␉␉␉␉␉printMemoryInfo();␊ |
961 | ␉␉␉␉␉}␊ |
962 | ␉␉␉␉} else if (strcmp(booterCommand, "lspci") == 0) {␊ |
963 | ␉␉␉␉␉lspci();␊ |
964 | ␉␉␉␉} else if (strcmp(booterCommand, "more") == 0) {␊ |
965 | ␉␉␉␉␉showTextFile(booterParam);␊ |
966 | ␉␉␉␉} else if (strcmp(booterCommand, "rd") == 0) {␊ |
967 | ␉␉␉␉␉processRAMDiskCommand(&argPtr, booterParam);␊ |
968 | ␉␉␉␉} else if (strcmp(booterCommand, "norescan") == 0) {␊ |
969 | ␉␉␉␉␉if (gEnableCDROMRescan) {␊ |
970 | ␉␉␉␉␉␉gEnableCDROMRescan = false;␊ |
971 | ␉␉␉␉␉␉break;␊ |
972 | ␉␉␉␉␉}␊ |
973 | ␉␉␉␉} else {␊ |
974 | ␉␉␉␉␉showHelp();␊ |
975 | ␉␉␉␉}␊ |
976 | ␉␉␉␉key = 0;␊ |
977 | ␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
978 | ␉␉␉␉break;␊ |
979 | ␉␉␉}␊ |
980 | ␉␉␉gBootVolume = menuBVR;␊ |
981 | ␉␉␉setRootVolume(menuBVR);␊ |
982 | ␉␉␉gBIOSDev = menuBVR->biosdev;␊ |
983 | ␉␉␉break;␊ |
984 | ␊ |
985 | ␉␉case kEscapeKey:␊ |
986 | ␉␉␉clearBootArgs();␊ |
987 | ␉␉␉break;␊ |
988 | ␊ |
989 | ␉␉case kF5Key:␊ |
990 | ␉␉␉// New behavior:␊ |
991 | ␉␉␉// Clear gBootVolume to restart the loop␊ |
992 | ␉␉␉// if the user enabled rescanning the optical drive.␊ |
993 | ␉␉␉// Otherwise boot the default boot volume.␊ |
994 | ␉␉␉if (gEnableCDROMRescan) {␊ |
995 | ␉␉␉␉gBootVolume = NULL;␊ |
996 | ␉␉␉␉clearBootArgs();␊ |
997 | ␉␉␉}␊ |
998 | ␉␉␉break;␊ |
999 | ␊ |
1000 | ␉␉case kF10Key:␊ |
1001 | ␉␉␉gScanSingleDrive = false;␊ |
1002 | ␉␉␉scanDisks(gBIOSDev, &bvCount);␊ |
1003 | ␉␉␉gBootVolume = NULL;␊ |
1004 | ␉␉␉clearBootArgs();␊ |
1005 | ␉␉␉break;␊ |
1006 | ␊ |
1007 | ␉␉case kTabKey:␊ |
1008 | ␉␉␉// New behavior:␊ |
1009 | ␉␉␉// Switch between text & graphic interfaces␊ |
1010 | ␉␉␉// Only Permitted if started in graphics interface␊ |
1011 | ␉␉␉if (useGUI) {␊ |
1012 | ␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
1013 | ␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1014 | ␊ |
1015 | ␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1016 | ␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1017 | ␊ |
1018 | ␉␉␉␉␉// Display banner and show hardware info.␊ |
1019 | ␉␉␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1020 | ␉␉␉␉␉printf(getVBEInfoString());␊ |
1021 | ␊ |
1022 | ␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
1023 | ␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
1024 | ␊ |
1025 | ␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1026 | ␉␉␉␉␉showPrompt = true;␊ |
1027 | ␊ |
1028 | ␉␉␉␉␉if (gDeviceCount) {␊ |
1029 | ␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1030 | ␉␉␉␉␉␉showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
1031 | ␉␉␉␉␉␉nextRow += min(gDeviceCount, kMenuMaxItems) + 3;␊ |
1032 | ␉␉␉␉␉}␊ |
1033 | ␊ |
1034 | ␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1035 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1036 | ␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
1037 | ␉␉␉␉} else {␊ |
1038 | ␉␉␉␉␉gui.redraw = true;␊ |
1039 | ␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1040 | ␉␉␉␉␉updateVRAM();␊ |
1041 | ␉␉␉␉}␊ |
1042 | ␉␉␉}␊ |
1043 | ␉␉␉key = 0;␊ |
1044 | ␉␉␉break;␊ |
1045 | ␊ |
1046 | ␉␉default:␊ |
1047 | ␉␉␉key = 0;␊ |
1048 | ␉␉␉break;␊ |
1049 | ␉␉}␊ |
1050 | ␉} while (0 == key);␊ |
1051 | ␊ |
1052 | done:␊ |
1053 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
1054 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
1055 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
1056 | ␉}␊ |
1057 | ␉shouldboot = false;␊ |
1058 | ␉gui.menu.draw = false;␊ |
1059 | ␉if (menuItems) {␊ |
1060 | ␉␉free(menuItems);␊ |
1061 | ␉␉menuItems = NULL;␊ |
1062 | ␉}␊ |
1063 | ␉return 0;␊ |
1064 | }␊ |
1065 | ␊ |
1066 | //==========================================================================␊ |
1067 | ␊ |
1068 | extern unsigned char chainbootdev;␊ |
1069 | extern unsigned char chainbootflag;␊ |
1070 | ␊ |
1071 | bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)␊ |
1072 | {␊ |
1073 | int argLen = argName ? strlen(argName) : 0;␊ |
1074 | int len = argLen + cnt + 1; // +1 to account for space␊ |
1075 | ␊ |
1076 | if (len > *cntRemainingP) {␊ |
1077 | error("Warning: boot arguments too long, truncating\n");␊ |
1078 | return false;␊ |
1079 | }␊ |
1080 | ␊ |
1081 | if (argName) {␊ |
1082 | strncpy( *argP, argName, argLen );␊ |
1083 | *argP += argLen;␊ |
1084 | *argP[0] = '=';␊ |
1085 | (*argP)++;␊ |
1086 | len++; // +1 to account for '='␊ |
1087 | }␊ |
1088 | strncpy( *argP, val, cnt );␊ |
1089 | *argP += cnt;␊ |
1090 | *argP[0] = ' ';␊ |
1091 | (*argP)++;␊ |
1092 | ␊ |
1093 | *cntRemainingP -= len;␊ |
1094 | return true;␊ |
1095 | }␊ |
1096 | ␊ |
1097 | // ␊ |
1098 | // Returns TRUE if an argument was copied, FALSE otherwise␊ |
1099 | bool␊ |
1100 | processBootArgument(␊ |
1101 | const char *argName, // The argument to search for␊ |
1102 | const char *userString, // Typed-in boot arguments␊ |
1103 | const char *kernelFlags, // Kernel flags from config table␊ |
1104 | const char *configTable,␊ |
1105 | char **argP, // Output value␊ |
1106 | int *cntRemainingP, // Output count␊ |
1107 | char *foundVal // found value␊ |
1108 | )␊ |
1109 | {␊ |
1110 | const char *val;␊ |
1111 | int cnt;␊ |
1112 | bool found = false;␊ |
1113 | ␊ |
1114 | if (getValueForBootKey(userString, argName, &val, &cnt)) {␊ |
1115 | // Don't copy; these values will be copied at the end of argument processing.␊ |
1116 | found = true;␊ |
1117 | } else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {␊ |
1118 | // Don't copy; these values will be copied at the end of argument processing.␊ |
1119 | found = true;␊ |
1120 | } else if (getValueForKey(argName, &val, &cnt, &bootInfo->bootConfig)) {␊ |
1121 | copyArgument(argName, val, cnt, argP, cntRemainingP);␊ |
1122 | found = true;␊ |
1123 | }␊ |
1124 | if (found && foundVal) {␊ |
1125 | strlcpy(foundVal, val, cnt+1);␊ |
1126 | }␊ |
1127 | return found;␊ |
1128 | }␊ |
1129 | ␊ |
1130 | // Maximum config table value size␊ |
1131 | #define VALUE_SIZE 2048␊ |
1132 | ␊ |
1133 | int␊ |
1134 | processBootOptions()␊ |
1135 | {␊ |
1136 | const char * cp = gBootArgs;␊ |
1137 | const char * val = 0;␊ |
1138 | const char * kernel;␊ |
1139 | ␉const char␉␉*value;␊ |
1140 | ␉int␉␉␉␉ len;␊ |
1141 | int cnt;␊ |
1142 | int␉␉ userCnt;␊ |
1143 | int cntRemaining;␊ |
1144 | char * argP;␊ |
1145 | char uuidStr[64];␊ |
1146 | bool uuidSet = false;␊ |
1147 | char * configKernelFlags;␊ |
1148 | char * valueBuffer;␊ |
1149 | ␉config_file_t␉ systemVersion;␊ |
1150 | ␊ |
1151 | valueBuffer = malloc(VALUE_SIZE);␊ |
1152 | ␊ |
1153 | skipblanks( &cp );␊ |
1154 | ␊ |
1155 | // Update the unit and partition number.␊ |
1156 | ␊ |
1157 | if ( gBootVolume )␊ |
1158 | {␊ |
1159 | if (!( gBootVolume->flags & kBVFlagNativeBoot ))␊ |
1160 | {␊ |
1161 | readBootSector( gBootVolume->biosdev, gBootVolume->part_boff,␊ |
1162 | (void *) 0x7c00 );␊ |
1163 | ␊ |
1164 | //␊ |
1165 | // Setup edx, and signal intention to chain load the␊ |
1166 | // foreign booter.␊ |
1167 | //␊ |
1168 | ␊ |
1169 | chainbootdev = gBootVolume->biosdev;␊ |
1170 | chainbootflag = 1;␊ |
1171 | ␊ |
1172 | return 1;␊ |
1173 | }␊ |
1174 | ␊ |
1175 | setRootVolume(gBootVolume);␊ |
1176 | ␊ |
1177 | }␊ |
1178 | // If no boot volume fail immediately because we're just going to fail␊ |
1179 | // trying to load the config file anyway.␊ |
1180 | else␊ |
1181 | return -1;␊ |
1182 | ␉␊ |
1183 | ␉// Needed here to enable search for override Boot.plist on OS specific folders.␊ |
1184 | ␉// Find out which Mac OS version we're booting.␊ |
1185 | ␉if (!loadConfigFile("/System/Library/CoreServices/SystemVersion.plist", &systemVersion))␊ |
1186 | ␉{␊ |
1187 | ␉␉if (getValueForKey(kProductVersion, &value, &len, &systemVersion))␊ |
1188 | ␉␉{␊ |
1189 | ␉␉␉// getValueForKey uses const char for val␊ |
1190 | ␉␉␉// so copy it and trim␊ |
1191 | ␉␉␉strncpy(gMacOSVersion, value, MIN(len, 4));␊ |
1192 | ␉␉␉gMacOSVersion[MIN(len, 4)] = '\0';␊ |
1193 | ␉␉}␊ |
1194 | ␉}␊ |
1195 | ␉␊ |
1196 | ␉//Azi: implemented at loadOverrideConfig.␊ |
1197 | // Load config table specified by the user, or use the default.␊ |
1198 | //if (!getValueForBootKey(cp, "config", &val, &cnt)) {␊ |
1199 | // val = 0;␊ |
1200 | // cnt = 0;␊ |
1201 | //}␊ |
1202 | ␊ |
1203 | // Load com.apple.Boot.plist from the selected volume␊ |
1204 | // and use its contents to override default bootConfig.␊ |
1205 | // This is not a mandatory operation anymore.␊ |
1206 | ␊ |
1207 | loadOverrideConfig(&bootInfo->overrideConfig);␊ |
1208 | ␊ |
1209 | // Use the kernel name specified by the user, or fetch the name␊ |
1210 | // in the config table, or use the default if not specified.␊ |
1211 | // Specifying a kernel name on the command line, or specifying␊ |
1212 | // a non-default kernel name in the config file counts as␊ |
1213 | // overriding the kernel, which causes the kernelcache not␊ |
1214 | // to be used.␊ |
1215 | ␊ |
1216 | gOverrideKernel = false;␊ |
1217 | if (( kernel = extractKernelName((char **)&cp) )) {␊ |
1218 | strcpy( bootInfo->bootFile, kernel );␊ |
1219 | gOverrideKernel = true;␊ |
1220 | } else {␊ |
1221 | if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1222 | strlcpy( bootInfo->bootFile, val, cnt+1 );␊ |
1223 | if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {␊ |
1224 | gOverrideKernel = true;␊ |
1225 | }␊ |
1226 | } else {␊ |
1227 | strcpy( bootInfo->bootFile, kDefaultKernel );␊ |
1228 | }␊ |
1229 | }␊ |
1230 | ␊ |
1231 | cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space␊ |
1232 | argP = bootArgs->CommandLine;␊ |
1233 | ␊ |
1234 | // Get config table kernel flags, if not ignored.␊ |
1235 | if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||␊ |
1236 | !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) {␊ |
1237 | val = "";␊ |
1238 | cnt = 0;␊ |
1239 | }␊ |
1240 | configKernelFlags = malloc(cnt + 1);␊ |
1241 | strlcpy(configKernelFlags, val, cnt + 1);␊ |
1242 | ␊ |
1243 | if (processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0)) {␊ |
1244 | // boot-uuid was set either on the command-line␊ |
1245 | // or in the config file.␊ |
1246 | uuidSet = true;␊ |
1247 | } else {␊ |
1248 | ␊ |
1249 | //␊ |
1250 | // Try an alternate method for getting the root UUID on boot helper partitions.␊ |
1251 | //␊ |
1252 | if (gBootVolume->flags & kBVFlagBooter)␊ |
1253 | {␊ |
1254 | ␉if((loadHelperConfig(&bootInfo->helperConfig) == 0)␊ |
1255 | ␉ && getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig) )␊ |
1256 | ␉{␊ |
1257 | ␉getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig);␊ |
1258 | copyArgument(kBootUUIDKey, val, cnt, &argP, &cntRemaining);␊ |
1259 | uuidSet = true;␊ |
1260 | ␉}␊ |
1261 | }␊ |
1262 | ␊ |
1263 | if (!uuidSet && gBootVolume->fs_getuuid && gBootVolume->fs_getuuid (gBootVolume, uuidStr) == 0) {␊ |
1264 | verbose("Setting boot-uuid to: %s\n", uuidStr);␊ |
1265 | copyArgument(kBootUUIDKey, uuidStr, strlen(uuidStr), &argP, &cntRemaining);␊ |
1266 | uuidSet = true;␊ |
1267 | }␊ |
1268 | }␊ |
1269 | ␊ |
1270 | if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice)) {␊ |
1271 | cnt = 0;␊ |
1272 | if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig)) {␊ |
1273 | valueBuffer[0] = '*';␊ |
1274 | cnt++;␊ |
1275 | strlcpy(valueBuffer + 1, val, cnt);␊ |
1276 | val = valueBuffer;␊ |
1277 | } else {␊ |
1278 | if (uuidSet) {␊ |
1279 | val = "*uuid";␊ |
1280 | cnt = 5;␊ |
1281 | } else {␊ |
1282 | // Don't set "rd=.." if there is no boot device key␊ |
1283 | // and no UUID.␊ |
1284 | val = "";␊ |
1285 | cnt = 0;␊ |
1286 | }␊ |
1287 | } ␊ |
1288 | if (cnt > 0) {␊ |
1289 | copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);␊ |
1290 | }␊ |
1291 | strlcpy( gRootDevice, val, (cnt + 1));␊ |
1292 | }␊ |
1293 | ␊ |
1294 | /*␊ |
1295 | * Removed. We don't need this anymore.␊ |
1296 | *␊ |
1297 | if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gPlatformName)) {␊ |
1298 | getPlatformName(gPlatformName);␊ |
1299 | copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);␊ |
1300 | }␊ |
1301 | */␊ |
1302 | ␊ |
1303 | if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&␊ |
1304 | !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) {␊ |
1305 | if (gBootMode & kBootModeSafe) {␊ |
1306 | copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);␊ |
1307 | }␊ |
1308 | }␊ |
1309 | ␊ |
1310 | // Store the merged kernel flags and boot args.␊ |
1311 | ␊ |
1312 | cnt = strlen(configKernelFlags);␊ |
1313 | if (cnt) {␊ |
1314 | if (cnt > cntRemaining) {␊ |
1315 | error("Warning: boot arguments too long, truncating\n");␊ |
1316 | cnt = cntRemaining;␊ |
1317 | }␊ |
1318 | strncpy(argP, configKernelFlags, cnt);␊ |
1319 | argP[cnt++] = ' ';␊ |
1320 | cntRemaining -= cnt;␊ |
1321 | }␊ |
1322 | userCnt = strlen(cp);␊ |
1323 | if (userCnt > cntRemaining) {␊ |
1324 | error("Warning: boot arguments too long, truncating\n");␊ |
1325 | userCnt = cntRemaining;␊ |
1326 | }␊ |
1327 | strncpy(&argP[cnt], cp, userCnt);␊ |
1328 | argP[cnt+userCnt] = '\0';␊ |
1329 | ␊ |
1330 | if(!shouldboot)␊ |
1331 | ␉{␊ |
1332 | ␉␉gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->bootConfig ) ||␊ |
1333 | ␉␉␉getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->bootConfig );␊ |
1334 | ␊ |
1335 | ␉␉gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->bootConfig ) ) ?␊ |
1336 | ␉␉␉kBootModeSafe : kBootModeNormal;␊ |
1337 | ␉␉␊ |
1338 | ␉␉if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1339 | ␉␉ gBootMode = kBootModeSafe;␊ |
1340 | ␉␉}␊ |
1341 | ␉}␊ |
1342 | ␊ |
1343 | ␉if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )␊ |
1344 | ␉{␊ |
1345 | ␉␉strlcpy(gMKextName, val, cnt + 1);␊ |
1346 | ␉}␊ |
1347 | ␉ ␊ |
1348 | free(configKernelFlags);␊ |
1349 | free(valueBuffer);␊ |
1350 | ␊ |
1351 | return 0;␊ |
1352 | }␊ |
1353 | ␊ |
1354 | ␊ |
1355 | //==========================================================================␊ |
1356 | // Load the help file and display the file contents on the screen.␊ |
1357 | ␊ |
1358 | static void showTextBuffer(char *buf, int size)␊ |
1359 | {␊ |
1360 | ␉char␉*bp;␊ |
1361 | ␉int␉line;␊ |
1362 | ␉int␉line_offset;␊ |
1363 | ␉int␉c;␊ |
1364 | ␊ |
1365 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
1366 | ␉␉showInfoBox( "Press q to quit\n",buf );␊ |
1367 | ␉␉return;␊ |
1368 | ␉}␊ |
1369 | ␊ |
1370 | bp = buf;␊ |
1371 | while (size-- > 0) {␊ |
1372 | ␉␉if (*bp == '\n') {␊ |
1373 | ␉␉␉*bp = '\0';␊ |
1374 | ␉␉}␊ |
1375 | ␉␉bp++;␊ |
1376 | }␊ |
1377 | *bp = '\1';␊ |
1378 | line_offset = 0;␊ |
1379 | ␊ |
1380 | setActiveDisplayPage(1);␊ |
1381 | ␊ |
1382 | while (1) {␊ |
1383 | ␉␉clearScreenRows(0, 24);␊ |
1384 | ␉␉setCursorPosition(0, 0, 1);␊ |
1385 | ␉␉bp = buf;␊ |
1386 | ␉␉for (line = 0; *bp != '\1' && line < line_offset; line++) {␊ |
1387 | ␉␉␉while (*bp != '\0') {␊ |
1388 | ␉␉␉␉bp++;␊ |
1389 | ␉␉␉}␊ |
1390 | ␉␉␉bp++;␊ |
1391 | ␉␉}␊ |
1392 | ␉␉for (line = 0; *bp != '\1' && line < 23; line++) {␊ |
1393 | ␉␉␉setCursorPosition(0, line, 1);␊ |
1394 | ␉␉␉printf("%s\n", bp);␊ |
1395 | ␉␉␉while (*bp != '\0') {␊ |
1396 | ␉␉␉␉bp++;␊ |
1397 | ␉␉␉}␊ |
1398 | ␉␉␉bp++;␊ |
1399 | ␉␉}␊ |
1400 | ␊ |
1401 | ␉␉setCursorPosition(0, 23, 1);␊ |
1402 | ␉␉if (*bp == '\1') {␊ |
1403 | ␉␉␉printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : "");␊ |
1404 | ␉␉} else {␊ |
1405 | ␉␉␉printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : "");␊ |
1406 | ␉␉}␊ |
1407 | ␊ |
1408 | ␉␉c = getc();␊ |
1409 | ␉␉if (c == 'q' || c == 'Q') {␊ |
1410 | ␉␉␉break;␊ |
1411 | ␉␉}␊ |
1412 | ␉␉if ((c == 'p' || c == 'P') && line_offset > 0) {␊ |
1413 | ␉␉␉line_offset -= 23;␊ |
1414 | ␉␉}␊ |
1415 | ␉␉if (c == ' ') {␊ |
1416 | ␉␉␉if (*bp == '\1') {␊ |
1417 | ␉␉␉␉break;␊ |
1418 | ␉␉␉} else {␊ |
1419 | ␉␉␉␉line_offset += 23;␊ |
1420 | ␉␉␉}␊ |
1421 | ␉␉}␊ |
1422 | }␊ |
1423 | setActiveDisplayPage(0);␊ |
1424 | }␊ |
1425 | ␊ |
1426 | void showHelp(void)␊ |
1427 | {␊ |
1428 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
1429 | ␉␉showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);␊ |
1430 | ␉} else {␊ |
1431 | ␉␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1432 | ␉}␊ |
1433 | }␊ |
1434 | ␊ |
1435 | void showTextFile(const char * filename)␊ |
1436 | {␊ |
1437 | #define MAX_TEXT_FILE_SIZE 65536␊ |
1438 | ␉char␉*buf;␊ |
1439 | ␉int␉fd;␊ |
1440 | ␉int␉size;␊ |
1441 | ␊ |
1442 | ␉if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {␊ |
1443 | ␉␉printf("\nFile not found: %s\n", filename);␊ |
1444 | ␉␉sleep(2);␊ |
1445 | ␉␉return;␊ |
1446 | ␉}␊ |
1447 | ␊ |
1448 | size = file_size(fd);␊ |
1449 | if (size > MAX_TEXT_FILE_SIZE) {␊ |
1450 | ␉␉size = MAX_TEXT_FILE_SIZE;␊ |
1451 | ␉}␊ |
1452 | buf = malloc(size);␊ |
1453 | read(fd, buf, size);␊ |
1454 | close(fd);␊ |
1455 | ␉showTextBuffer(buf, size);␊ |
1456 | ␉free(buf);␊ |
1457 | }␊ |
1458 | ␊ |
1459 | // This is a very simplistic prompting scheme that just grabs two hex characters␊ |
1460 | // Eventually we need to do something more user-friendly like display a menu␊ |
1461 | // based off of the Multiboot device list␊ |
1462 | ␊ |
1463 | int selectAlternateBootDevice(int bootdevice)␊ |
1464 | {␊ |
1465 | ␉int key;␊ |
1466 | ␉int newbootdevice;␊ |
1467 | ␉int digitsI = 0;␊ |
1468 | ␉char *end;␊ |
1469 | ␉char digits[3] = {0,0,0};␊ |
1470 | ␊ |
1471 | ␉// We've already printed the current boot device so user knows what it is␊ |
1472 | ␉printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n");␊ |
1473 | ␉printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice);␊ |
1474 | ␉do {␊ |
1475 | ␉␉key = getc();␊ |
1476 | ␉␉switch (key & kASCIIKeyMask) {␊ |
1477 | ␉␉case kBackspaceKey:␊ |
1478 | ␉␉␉if (digitsI > 0) {␊ |
1479 | ␉␉␉␉int x, y, t;␊ |
1480 | ␉␉␉␉getCursorPositionAndType(&x, &y, &t);␊ |
1481 | ␉␉␉␉// Assume x is not 0;␊ |
1482 | ␉␉␉␉x--;␊ |
1483 | ␉␉␉␉setCursorPosition(x,y,0); // back up one char␊ |
1484 | ␉␉␉␉// Overwrite with space without moving cursor position␊ |
1485 | ␉␉␉␉putca(' ', 0x07, 1);␊ |
1486 | ␉␉␉␉digitsI--;␊ |
1487 | ␉␉␉} else {␊ |
1488 | ␉␉␉␉// TODO: Beep or something␊ |
1489 | ␉␉␉}␊ |
1490 | ␉␉␉break;␊ |
1491 | ␊ |
1492 | ␉␉case kReturnKey:␊ |
1493 | ␉␉␉digits[digitsI] = '\0';␊ |
1494 | ␉␉␉newbootdevice = strtol(digits, &end, 16);␊ |
1495 | ␉␉␉if (end == digits && *end == '\0') {␊ |
1496 | ␉␉␉␉// User entered empty string␊ |
1497 | ␉␉␉␉printf("\nUsing default boot device %x\n", bootdevice);␊ |
1498 | ␉␉␉␉key = 0;␊ |
1499 | ␉␉␉} else if(end != digits && *end == '\0') {␊ |
1500 | ␉␉␉␉bootdevice = newbootdevice;␊ |
1501 | ␉␉␉␉printf("\n");␊ |
1502 | ␉␉␉␉key = 0; // We gots da boot device␊ |
1503 | ␉␉␉} else {␊ |
1504 | ␉␉␉␉printf("\nCouldn't parse. try again: ");␊ |
1505 | ␉␉␉␉digitsI = 0;␊ |
1506 | ␉␉␉}␊ |
1507 | ␉␉␉break;␊ |
1508 | ␊ |
1509 | ␉␉default:␊ |
1510 | ␉␉␉if (isxdigit(key & kASCIIKeyMask) && digitsI < 2) {␊ |
1511 | ␉␉␉␉putc(key & kASCIIKeyMask);␊ |
1512 | ␉␉␉␉digits[digitsI++] = key & kASCIIKeyMask;␊ |
1513 | ␉␉␉} else {␊ |
1514 | ␉␉␉␉// TODO: Beep or something␊ |
1515 | ␉␉␉}␊ |
1516 | ␉␉␉break;␊ |
1517 | ␉␉};␊ |
1518 | ␉} while (key != 0);␊ |
1519 | ␊ |
1520 | ␉return bootdevice;␊ |
1521 | }␊ |
1522 | ␊ |
1523 | bool promptForRescanOption(void)␊ |
1524 | {␊ |
1525 | ␉printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");␊ |
1526 | ␉if (getc() == kReturnKey) {␊ |
1527 | ␉␉return true;␊ |
1528 | ␉} else {␊ |
1529 | ␉␉return false;␊ |
1530 | ␉}␊ |
1531 | }␊ |
1532 | |