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