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