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