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 | #if DEBUG␊ |
36 | #define DBG(x...)␉printf(x)␊ |
37 | #else␊ |
38 | #define DBG(x...)␉msglog(x)␊ |
39 | #endif␊ |
40 | ␊ |
41 | bool showBootBanner = true; //Azi:showinfo␊ |
42 | static bool shouldboot = false;␊ |
43 | ␊ |
44 | extern int multiboot_timeout;␊ |
45 | extern int multiboot_timeout_set;␊ |
46 | ␊ |
47 | extern BVRef bvChain;␊ |
48 | //extern int␉␉menucount;␊ |
49 | ␊ |
50 | extern int␉␉gDeviceCount;␊ |
51 | ␊ |
52 | int␉␉␉selectIndex = 0;␊ |
53 | MenuItem * menuItems = NULL;␊ |
54 | ␊ |
55 | enum {␊ |
56 | kMenuTopRow = 5,␊ |
57 | kMenuMaxItems = 10,␊ |
58 | kScreenLastRow = 24␊ |
59 | };␊ |
60 | ␊ |
61 | //==========================================================================␊ |
62 | ␊ |
63 | typedef struct {␊ |
64 | int x;␊ |
65 | int y;␊ |
66 | int type;␊ |
67 | } CursorState;␊ |
68 | ␊ |
69 | static void changeCursor( int col, int row, int type, CursorState * cs )␊ |
70 | {␊ |
71 | if (cs) getCursorPositionAndType( &cs->x, &cs->y, &cs->type );␊ |
72 | setCursorType( type );␊ |
73 | setCursorPosition( col, row, 0 );␊ |
74 | }␊ |
75 | ␊ |
76 | static void moveCursor( int col, int row )␊ |
77 | {␊ |
78 | setCursorPosition( col, row, 0 );␊ |
79 | }␊ |
80 | ␊ |
81 | static void restoreCursor( const CursorState * cs )␊ |
82 | {␊ |
83 | setCursorPosition( cs->x, cs->y, 0 );␊ |
84 | setCursorType( cs->type );␊ |
85 | }␊ |
86 | ␊ |
87 | //==========================================================================␊ |
88 | ␊ |
89 | /* Flush keyboard buffer; returns TRUE if any of the flushed␊ |
90 | * characters was F8.␊ |
91 | */␊ |
92 | ␊ |
93 | static bool flushKeyboardBuffer(void)␊ |
94 | {␊ |
95 | bool status = false;␊ |
96 | ␊ |
97 | while ( readKeyboardStatus() ) {␊ |
98 | if (bgetc() == 0x4200) status = true;␊ |
99 | }␊ |
100 | return status;␊ |
101 | }␊ |
102 | ␊ |
103 | //==========================================================================␊ |
104 | ␊ |
105 | static int countdown( const char * msg, int row, int timeout )␊ |
106 | {␊ |
107 | unsigned long time;␊ |
108 | int ch = 0;␊ |
109 | int col = strlen(msg) + 1;␊ |
110 | ␉␊ |
111 | flushKeyboardBuffer();␊ |
112 | ␊ |
113 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
114 | ␉{␊ |
115 | ␉␉moveCursor( 0, row );␊ |
116 | ␉␉printf(msg);␊ |
117 | ␊ |
118 | ␉} else {␊ |
119 | ␊ |
120 | ␉␉position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );␊ |
121 | ␉␊ |
122 | ␉␉char dummy[80];␊ |
123 | ␉␉getBootVolumeDescription( gBootVolume, dummy, sizeof(dummy) - 1, true );␊ |
124 | ␉␉drawDeviceIcon( gBootVolume, gui.screen.pixmap, p, true );␊ |
125 | ␉␉drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );␊ |
126 | ␉␉␊ |
127 | ␉␉// make this screen the new background␊ |
128 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
129 | ␉␉␊ |
130 | ␉}␊ |
131 | ␊ |
132 | ␉int multi_buff = 18 * (timeout);␊ |
133 | int multi = ++multi_buff;␊ |
134 | ␊ |
135 | int lasttime=0;␊ |
136 | ␊ |
137 | for ( time = time18(), timeout++; timeout > 0; )␊ |
138 | {␊ |
139 | ␉␉if( time18() > lasttime)␊ |
140 | ␉␉{␊ |
141 | ␉␉␉multi--; ␊ |
142 | ␉␉␉lasttime=time18();␊ |
143 | ␉␉}␉␉␊ |
144 | ␊ |
145 | if ( (ch = readKeyboardStatus()) )␊ |
146 | break;␊ |
147 | ␊ |
148 | // Count can be interrupted by holding down shift,␊ |
149 | // control or alt key␊ |
150 | if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 )␊ |
151 | ␉␉{␊ |
152 | ch = 1;␊ |
153 | break;␊ |
154 | }␊ |
155 | ␊ |
156 | if ( time18() >= time )␊ |
157 | {␊ |
158 | time += 18;␊ |
159 | timeout--;␊ |
160 | ␊ |
161 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
162 | ␉␉␉{␊ |
163 | ␉␉␉␉moveCursor( col, row );␊ |
164 | ␉␉␉␉printf("(%d) ", timeout);␊ |
165 | ␉␉␉}␊ |
166 | }␊ |
167 | ␉␊ |
168 | ␉␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
169 | ␉␉{␊ |
170 | ␉␉␉drawProgressBar( gui.screen.pixmap, 100, gui.progressbar.pos , ( multi * 100 / multi_buff ) );␊ |
171 | ␉␉␉gui.redraw = true;␊ |
172 | ␉␉␉updateVRAM();␊ |
173 | ␉␉}␊ |
174 | ␊ |
175 | }␊ |
176 | ␊ |
177 | flushKeyboardBuffer();␊ |
178 | ␊ |
179 | return ch;␊ |
180 | }␊ |
181 | ␊ |
182 | //==========================================================================␊ |
183 | ␊ |
184 | char gBootArgs[BOOT_STRING_LEN];␊ |
185 | static char * gBootArgsPtr = gBootArgs;␊ |
186 | static char * gBootArgsEnd = gBootArgs + BOOT_STRING_LEN - 1;␊ |
187 | static char booterCommand[BOOT_STRING_LEN];␊ |
188 | static char booterParam[BOOT_STRING_LEN];␊ |
189 | ␊ |
190 | static void clearBootArgs(void)␊ |
191 | {␊ |
192 | ␉gBootArgsPtr = gBootArgs;␊ |
193 | ␉memset(gBootArgs, '\0', BOOT_STRING_LEN);␊ |
194 | ␊ |
195 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
196 | ␉␉clearGraphicBootPrompt();␊ |
197 | ␉}␊ |
198 | ␉execute_hook("ClearArgs", NULL, NULL, NULL, NULL);␊ |
199 | }␊ |
200 | ␊ |
201 | void addBootArg(const char * argStr)␊ |
202 | {␊ |
203 | ␉if ( (gBootArgsPtr + strlen(argStr) + 1) < gBootArgsEnd)␊ |
204 | ␉{␊ |
205 | ␉␉if(gBootArgsPtr != gBootArgs) *gBootArgsPtr++ = ' ';␊ |
206 | ␉␉strcat(gBootArgs, argStr);␊ |
207 | ␉␉gBootArgsPtr += strlen(argStr);␊ |
208 | ␉}␊ |
209 | }␊ |
210 | ␊ |
211 | //==========================================================================␊ |
212 | ␊ |
213 | static void showBootPrompt(int row, bool visible)␊ |
214 | {␊ |
215 | ␉extern char bootPrompt[];␊ |
216 | ␉extern char bootRescanPrompt[];␊ |
217 | ␊ |
218 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
219 | ␉␉changeCursor( 0, row, kCursorTypeUnderline, 0 ); ␊ |
220 | ␉␉clearScreenRows( row, kScreenLastRow );␊ |
221 | ␉}␊ |
222 | ␊ |
223 | ␉clearBootArgs();␊ |
224 | ␊ |
225 | ␉if (visible) {␊ |
226 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
227 | ␉␉␉if (gEnableCDROMRescan) {␊ |
228 | ␉␉␉␉printf( bootRescanPrompt );␊ |
229 | ␉␉␉} else {␊ |
230 | ␉␉␉␉printf( bootPrompt );␊ |
231 | ␉␉␉␉printf( gBootArgs );␊ |
232 | ␉␉␉}␊ |
233 | ␉␉}␊ |
234 | ␉} else {␊ |
235 | ␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
236 | ␉␉␉clearGraphicBootPrompt();␊ |
237 | ␉␉} else {␊ |
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) {␊ |
263 | ␉␉␉x--;␊ |
264 | ␉␉}␊ |
265 | ␊ |
266 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
267 | ␉␉␉␉{␊ |
268 | ␉␉␉␉␉setCursorPosition( x, y, 0 );␊ |
269 | ␉␉␉␉␉putca(' ', 0x07, 1);␊ |
270 | ␉␉␉␉}␊ |
271 | else␊ |
272 | {␊ |
273 | updateGraphicBootPrompt();␊ |
274 | }␊ |
275 | }␊ |
276 | ␉␉␉break;␊ |
277 | ␊ |
278 | default:␊ |
279 | if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
280 | {␊ |
281 | *gBootArgsPtr++ = key;␊ |
282 | ␊ |
283 | if( bootArgs->Video.v_display != VGA_TEXT_MODE ) updateGraphicBootPrompt();␊ |
284 | else if ( key >= ' ' && key < 0x7f) putchar(key);␊ |
285 | ␉␉␉}␊ |
286 | ␊ |
287 | ␉␉␉break;␊ |
288 | }␊ |
289 | }␊ |
290 | ␊ |
291 | //==========================================================================␊ |
292 | ␊ |
293 | static const MenuItem * gMenuItems = NULL;␊ |
294 | ␊ |
295 | static int gMenuItemCount;␊ |
296 | static int gMenuRow;␊ |
297 | static int gMenuHeight;␊ |
298 | static int gMenuTop;␊ |
299 | static int gMenuBottom;␊ |
300 | static int gMenuSelection;␊ |
301 | ␊ |
302 | static int␉ gMenuStart;␊ |
303 | static int␉ gMenuEnd;␊ |
304 | ␊ |
305 | static void printMenuItem( const MenuItem * item, int highlight )␊ |
306 | {␊ |
307 | printf(" ");␊ |
308 | ␊ |
309 | if ( highlight )␊ |
310 | putca(' ', 0x70, strlen(item->name) + 4);␊ |
311 | else␊ |
312 | putca(' ', 0x07, 40);␊ |
313 | ␊ |
314 | printf(" %40s\n", item->name);␊ |
315 | }␊ |
316 | ␊ |
317 | //==========================================================================␊ |
318 | ␊ |
319 | static void showMenu( const MenuItem * items, int count,␊ |
320 | int selection, int row, int height )␊ |
321 | {␊ |
322 | int i;␊ |
323 | CursorState cursorState;␊ |
324 | ␊ |
325 | if ( items == NULL || count == 0 ) ␊ |
326 | ␉␉return;␊ |
327 | ␊ |
328 | // head and tail points to the start and the end of the list.␊ |
329 | // top and bottom points to the first and last visible items␊ |
330 | // in the menu window.␊ |
331 | ␊ |
332 | gMenuItems␉␉= items;␊ |
333 | gMenuRow␉␉= row;␊ |
334 | gMenuHeight␉␉= height;␊ |
335 | gMenuItemCount␉= count;␊ |
336 | gMenuTop␉␉= 0;␊ |
337 | gMenuBottom␉␉= MIN( count, height ) - 1;␊ |
338 | gMenuSelection␉= selection;␊ |
339 | ␊ |
340 | gMenuStart␉␉= 0;␊ |
341 | gMenuEnd␉ = MIN( count, gui.maxdevices ) - 1;␊ |
342 | ␉␊ |
343 | ␉// If the selected item is not visible, shift the list down.␊ |
344 | ␊ |
345 | if ( gMenuSelection > gMenuBottom )␊ |
346 | {␊ |
347 | gMenuTop += ( gMenuSelection - gMenuBottom );␊ |
348 | gMenuBottom = gMenuSelection;␊ |
349 | }␊ |
350 | ␊ |
351 | ␉if ( gMenuSelection > gMenuEnd )␊ |
352 | {␊ |
353 | ␉␉gMenuStart += ( gMenuSelection - gMenuEnd );␊ |
354 | gMenuEnd = gMenuSelection;␊ |
355 | }␊ |
356 | ␉␊ |
357 | ␉// Draw the visible items.␊ |
358 | ␊ |
359 | ␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
360 | ␉␊ |
361 | ␉␉drawDeviceList(gMenuStart, gMenuEnd, gMenuSelection);␊ |
362 | ␊ |
363 | ␉else {␊ |
364 | ␉␉␊ |
365 | ␉␉changeCursor( 0, row, kCursorTypeHidden, &cursorState );␊ |
366 | ␊ |
367 | ␉␉for ( i = gMenuTop; i <= gMenuBottom; i++ )␊ |
368 | ␉␉{␊ |
369 | ␉␉␉printMenuItem( &items[i], (i == gMenuSelection) );␊ |
370 | ␉␉}␊ |
371 | ␊ |
372 | ␉␉restoreCursor( &cursorState );␊ |
373 | }␊ |
374 | }␊ |
375 | ␊ |
376 | //==========================================================================␊ |
377 | ␊ |
378 | static int updateMenu( int key, void ** paramPtr )␊ |
379 | {␊ |
380 | int moved = 0;␊ |
381 | ␊ |
382 | union {␊ |
383 | struct {␊ |
384 | unsigned int␊ |
385 | selectionUp : 1,␊ |
386 | selectionDown : 1,␊ |
387 | scrollUp : 1,␊ |
388 | scrollDown : 1;␊ |
389 | } f;␊ |
390 | unsigned int w;␊ |
391 | } draw = {{0}};␊ |
392 | ␊ |
393 | if ( gMenuItems == NULL )␊ |
394 | ␉␉return 0;␊ |
395 | ␊ |
396 | ␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
397 | ␉{␊ |
398 | ␉␉int res;␊ |
399 | ␉␉␊ |
400 | ␉␉// set navigation keys for horizontal layout as defaults␊ |
401 | ␉␉int previous␉= 0x4B00;␉␉// left arrow␊ |
402 | ␉␉int subsequent␉= 0x4D00;␉␉// right arrow␊ |
403 | ␉␉int menu␉␉= 0x5000;␉␉// down arrow␊ |
404 | ␉␉␊ |
405 | ␉␉if ( gui.layout == VerticalLayout )␊ |
406 | ␉␉{␊ |
407 | ␉␉␉// set navigation keys for vertical layout␊ |
408 | ␉␉␉previous␉= 0x4800;␉␉// up arrow␊ |
409 | ␉␉␉subsequent␉= 0x5000;␉␉// down arrow␊ |
410 | ␉␉␉menu␉␉= 0x4B00;␉␉// right arrow␊ |
411 | ␉␉} ␊ |
412 | ␊ |
413 | ␉␉if ( key == previous )␊ |
414 | ␉␉{␊ |
415 | ␉␉␉if ( gMenuSelection > gMenuTop )␊ |
416 | ␉␉␉␉draw.f.selectionUp = 1;␊ |
417 | ␉␉␉else if ( gMenuTop > 0 )␊ |
418 | ␉␉␉␉draw.f.scrollDown = 1;␊ |
419 | ␉␉␉␊ |
420 | ␉␉}␊ |
421 | ␉␉␊ |
422 | ␉␉else if ( key == subsequent )␊ |
423 | ␉␉{␊ |
424 | ␉␉␉if ( gMenuSelection != gMenuBottom)␊ |
425 | ␉␉␉␉draw.f.selectionDown = 1;␊ |
426 | ␉␉␉else if ( gMenuBottom < ( gMenuItemCount - 1 ) )␊ |
427 | ␉␉␉␉draw.f.scrollUp = 1;␊ |
428 | ␉␉}␊ |
429 | ␉␉␊ |
430 | ␉␉else if ( key == menu )␊ |
431 | ␉␉{␊ |
432 | ␉␉␉if ( gui.menu.draw )␊ |
433 | ␉␉␉␉updateInfoMenu(key);␊ |
434 | ␉␉␉else␊ |
435 | ␉␉␉␉drawInfoMenu();␊ |
436 | ␉␉}␊ |
437 | ␊ |
438 | ␉␉else if ( gui.menu.draw )␊ |
439 | ␉␉{␊ |
440 | ␉␉␉res = updateInfoMenu(key);␊ |
441 | ␊ |
442 | ␉␉␉if ( res == CLOSE_INFO_MENU )␊ |
443 | ␉␉␉␉gui.menu.draw = false;␊ |
444 | ␉␉␉else␊ |
445 | ␉␉␉{␊ |
446 | ␉␉␉␉shouldboot = ( res != DO_NOT_BOOT );␊ |
447 | ␉␉␉␉␊ |
448 | ␉␉␉␉if ( shouldboot )␊ |
449 | ␉␉␉␉␉gui.menu.draw = false;␊ |
450 | ␊ |
451 | ␉␉␉␉switch (res)␊ |
452 | ␉␉␉␉{␊ |
453 | ␉␉␉␉␉case BOOT_NORMAL:␊ |
454 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
455 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
456 | ␉␉␉␉␉␉break;␊ |
457 | ␉␉␉␉␉␉␊ |
458 | ␉␉␉␉␉case BOOT_VERBOSE:␊ |
459 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
460 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
461 | ␉␉␉␉␉␉addBootArg(kVerboseModeFlag);␊ |
462 | ␉␉␉␉␉␉break;␊ |
463 | ␉␉␉␉␉␉␊ |
464 | ␉␉␉␉␉case BOOT_IGNORECACHE:␊ |
465 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
466 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
467 | ␉␉␉␉␉␉addBootArg(kIgnoreCachesFlag);␊ |
468 | ␉␉␉␉␉␉break;␊ |
469 | ␉␉␉␉␉␉␊ |
470 | ␉␉␉␉␉case BOOT_SINGLEUSER:␊ |
471 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
472 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
473 | ␉␉␉␉␉␉addBootArg(kSingleUserModeFlag);␊ |
474 | ␉␉␉␉␉␉break;␊ |
475 | ␉␉␉␉}␊ |
476 | ␉␉␉␉␊ |
477 | ␉␉␉}␊ |
478 | ␉␉␉␊ |
479 | ␉␉}␉␊ |
480 | ␉␉␉␊ |
481 | ␉} else {␊ |
482 | ␉␉switch ( key )␊ |
483 | ␉␉{␊ |
484 | ␉case 0x4800: // Up Arrow␊ |
485 | ␉␉␉␉if ( gMenuSelection != gMenuTop )␊ |
486 | ␉␉␉␉␉draw.f.selectionUp = 1;␊ |
487 | ␉␉␉␉else if ( gMenuTop > 0 )␊ |
488 | ␉␉␉␉␉draw.f.scrollDown = 1;␊ |
489 | ␉␉␉␉break;␊ |
490 | ␊ |
491 | ␉␉␉case 0x5000: // Down Arrow␊ |
492 | ␉␉␉␉if ( gMenuSelection != gMenuBottom )␊ |
493 | ␉␉␉␉␉draw.f.selectionDown = 1;␊ |
494 | ␉␉␉␉else if ( gMenuBottom < (gMenuItemCount - 1) ) ␊ |
495 | ␉␉␉␉␉draw.f.scrollUp = 1;␊ |
496 | ␉␉␉␉break;␊ |
497 | ␉␉}␊ |
498 | ␉}␊ |
499 | ␊ |
500 | if ( draw.w )␊ |
501 | {␊ |
502 | if ( draw.f.scrollUp )␊ |
503 | {␊ |
504 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, 1);␊ |
505 | gMenuTop++; gMenuBottom++;␊ |
506 | ␉␉␉gMenuStart++; gMenuEnd++;␊ |
507 | draw.f.selectionDown = 1;␊ |
508 | }␊ |
509 | ␊ |
510 | if ( draw.f.scrollDown )␊ |
511 | {␊ |
512 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, -1);␊ |
513 | gMenuTop--; gMenuBottom--;␊ |
514 | gMenuStart--; gMenuEnd--;␊ |
515 | draw.f.selectionUp = 1;␊ |
516 | }␊ |
517 | ␊ |
518 | if ( draw.f.selectionUp || draw.f.selectionDown )␊ |
519 | {␊ |
520 | ␊ |
521 | ␉␉␉CursorState cursorState;␊ |
522 | ␊ |
523 | ␉␉␉// Set cursor at current position, and clear inverse video.␊ |
524 | ␉␊ |
525 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
526 | ␉␉␉{␊ |
527 | ␉␉␉␉changeCursor( 0, gMenuRow + gMenuSelection - gMenuTop, kCursorTypeHidden, &cursorState );␊ |
528 | ␉␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 0 );␊ |
529 | ␉␉␉}␊ |
530 | ␊ |
531 | ␉␉␉if ( draw.f.selectionUp )␊ |
532 | ␉␉␉{␊ |
533 | ␉␉␉␉gMenuSelection--;␊ |
534 | ␉␉␉␉if(( gMenuSelection - gMenuStart) == -1 )␊ |
535 | ␉␉␉␉{␊ |
536 | ␉␉␉␉␉gMenuStart--;␊ |
537 | ␉␉␉␉␉gMenuEnd--;␊ |
538 | ␉␉␉␉}␊ |
539 | ␉␉␉␉␊ |
540 | ␉␉␉} else {␊ |
541 | ␉␉␉gMenuSelection++;␊ |
542 | ␉␉␉if(( gMenuSelection - ( gui.maxdevices - 1) - gMenuStart) > 0 )␊ |
543 | ␉␉␉{␊ |
544 | ␉␉␉␉gMenuStart++;␊ |
545 | ␉␉␉␉gMenuEnd++;␊ |
546 | ␉␉␉}␊ |
547 | ␉ }␊ |
548 | ␊ |
549 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
550 | ␉ {␊ |
551 | ␉␉␉moveCursor( 0, gMenuRow + gMenuSelection - gMenuTop );␊ |
552 | ␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 1 );␊ |
553 | ␉␉␉restoreCursor( &cursorState );␊ |
554 | ␊ |
555 | ␉ } else␊ |
556 | ␊ |
557 | ␉␉␉drawDeviceList (gMenuStart, gMenuEnd, gMenuSelection);␊ |
558 | ␊ |
559 | ␉}␊ |
560 | ␊ |
561 | *paramPtr = gMenuItems[gMenuSelection].param; ␊ |
562 | moved = 1;␊ |
563 | }␊ |
564 | ␊ |
565 | ␉return moved;␊ |
566 | }␊ |
567 | ␊ |
568 | //==========================================================================␊ |
569 | ␊ |
570 | static void skipblanks( const char ** cpp ) ␊ |
571 | {␊ |
572 | while ( **(cpp) == ' ' || **(cpp) == '\t' ) ++(*cpp);␊ |
573 | }␊ |
574 | ␊ |
575 | //==========================================================================␊ |
576 | ␊ |
577 | static const char * extractKernelName( char ** cpp )␊ |
578 | {␊ |
579 | char * kn = *cpp;␊ |
580 | char * cp = *cpp;␊ |
581 | char c;␊ |
582 | ␊ |
583 | // Convert char to lower case.␊ |
584 | ␊ |
585 | c = *cp | 0x20;␊ |
586 | ␊ |
587 | // Must start with a letter or a '/'.␊ |
588 | ␊ |
589 | if ( (c < 'a' || c > 'z') && ( c != '/' ) )␊ |
590 | return 0;␊ |
591 | ␊ |
592 | // Keep consuming characters until we hit a separator.␊ |
593 | ␊ |
594 | while ( *cp && (*cp != '=') && (*cp != ' ') && (*cp != '\t') )␊ |
595 | cp++;␊ |
596 | ␊ |
597 | // Only SPACE or TAB separator is accepted.␊ |
598 | // Reject everything else.␊ |
599 | ␊ |
600 | if (*cp == '=')␊ |
601 | return 0;␊ |
602 | ␊ |
603 | // Overwrite the separator, and move the pointer past␊ |
604 | // the kernel name.␊ |
605 | ␊ |
606 | if (*cp != '\0') *cp++ = '\0';␊ |
607 | *cpp = cp;␊ |
608 | ␊ |
609 | return kn;␊ |
610 | }␊ |
611 | ␊ |
612 | //==========================================================================␊ |
613 | ␊ |
614 | static void␊ |
615 | printMemoryInfo(void)␊ |
616 | {␊ |
617 | int line;␊ |
618 | int i;␊ |
619 | MemoryRange *mp = bootInfo->memoryMap;␊ |
620 | ␊ |
621 | // Activate and clear page 1␊ |
622 | setActiveDisplayPage(1);␊ |
623 | clearScreenRows(0, 24);␊ |
624 | setCursorPosition( 0, 0, 1 );␊ |
625 | ␊ |
626 | printf("BIOS reported memory ranges:\n");␊ |
627 | line = 1;␊ |
628 | for (i=0; i<bootInfo->memoryMapCount; i++) {␊ |
629 | printf("Base 0x%08x%08x, ",␊ |
630 | (unsigned long)(mp->base >> 32),␊ |
631 | (unsigned long)(mp->base));␊ |
632 | printf("length 0x%08x%08x, type %d\n",␊ |
633 | (unsigned long)(mp->length >> 32),␊ |
634 | (unsigned long)(mp->length),␊ |
635 | mp->type);␊ |
636 | if (line++ > 20) {␊ |
637 | pause();␊ |
638 | line = 0;␊ |
639 | }␊ |
640 | mp++;␊ |
641 | }␊ |
642 | if (line > 0) {␊ |
643 | pause();␊ |
644 | }␊ |
645 | ␊ |
646 | setActiveDisplayPage(0);␊ |
647 | }␊ |
648 | ␊ |
649 | char *getMemoryInfoString()␊ |
650 | {␊ |
651 | ␉int i, bufflen;␊ |
652 | ␉MemoryRange *mp = bootInfo->memoryMap;␊ |
653 | ␉char *buff = malloc(sizeof(char)*1024);␊ |
654 | ␉if(!buff) {␊ |
655 | ␉␉return 0;␊ |
656 | ␉}␊ |
657 | ␊ |
658 | ␉static const char info[] = "BIOS reported memory ranges:\n";␊ |
659 | ␉bufflen = sprintf(buff, "%s", info);␊ |
660 | ␊ |
661 | ␉for (i = 0;␊ |
662 | ␉␉(i < bootInfo->memoryMapCount) && (bufflen < 1024); /* prevent buffer overflow */␊ |
663 | ␉␉i++) {␊ |
664 | ␉␉bufflen += snprintf(buff+bufflen, 1024-bufflen, "Base 0x%08x%08x, ",␊ |
665 | (unsigned long)(mp->base >> 32),␊ |
666 | (unsigned long)(mp->base));␊ |
667 | ␉␉bufflen += snprintf(buff+bufflen, 1024-bufflen, "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 | ␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1034 | ␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1035 | ␊ |
1036 | ␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1037 | ␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1038 | ␊ |
1039 | ␉␉␉␉␉// Display banner and show hardware info.␊ |
1040 | ␉␉␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1041 | ␉␉␉␉␉printf(getVBEInfoString());␊ |
1042 | ␊ |
1043 | ␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
1044 | ␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
1045 | ␊ |
1046 | ␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1047 | ␉␉␉␉␉showPrompt = true;␊ |
1048 | ␊ |
1049 | ␉␉␉␉␉if (gDeviceCount) {␊ |
1050 | ␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1051 | ␉␉␉␉␉␉showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
1052 | ␉␉␉␉␉␉nextRow += MIN(gDeviceCount, kMenuMaxItems) + 3;␊ |
1053 | ␉␉␉␉␉}␊ |
1054 | ␊ |
1055 | ␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1056 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1057 | ␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
1058 | ␉␉␉␉} else {␊ |
1059 | ␉␉␉␉␉gui.redraw = true;␊ |
1060 | ␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1061 | ␉␉␉␉␉updateVRAM();␊ |
1062 | ␉␉␉updateGraphicBootPrompt();␊ |
1063 | ␉␉␉␉}␊ |
1064 | ␉␉␉}␊ |
1065 | ␉␉␉key = 0;␊ |
1066 | ␉␉␉break;␊ |
1067 | ␊ |
1068 | ␉␉default:␊ |
1069 | ␉␉␉key = 0;␊ |
1070 | ␉␉␉break;␊ |
1071 | ␉␉}␊ |
1072 | ␉} while (0 == key);␊ |
1073 | ␊ |
1074 | done:␊ |
1075 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
1076 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
1077 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
1078 | ␉}␊ |
1079 | ␉shouldboot = false;␊ |
1080 | ␉gui.menu.draw = false;␊ |
1081 | ␉if (menuItems) {␊ |
1082 | ␉␉free(menuItems);␊ |
1083 | ␉␉menuItems = NULL;␊ |
1084 | ␉}␊ |
1085 | ␉execute_hook("BootOptions", gBootArgs, gBootArgsPtr, NULL, NULL);␊ |
1086 | ␉return 0;␊ |
1087 | }␊ |
1088 | ␊ |
1089 | //==========================================================================␊ |
1090 | ␊ |
1091 | char gBootUUIDString[32+4+1] = ""; // UUID of the boot volume e.g. 5EB1869F-C4FA-3502-BDEB-3B8ED5D87292␊ |
1092 | extern unsigned char chainbootdev;␊ |
1093 | extern unsigned char chainbootflag;␊ |
1094 | ␊ |
1095 | bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)␊ |
1096 | {␊ |
1097 | int argLen = argName ? strlen(argName) : 0;␊ |
1098 | int len = argLen + cnt + 1; // +1 to account for space␊ |
1099 | ␊ |
1100 | ␉if (argName)␊ |
1101 | ␉␉len++; // +1 to account for '='␊ |
1102 | ␊ |
1103 | if (len > *cntRemainingP) {␊ |
1104 | error("Warning: boot arguments too long, truncating\n");␊ |
1105 | return false;␊ |
1106 | }␊ |
1107 | ␊ |
1108 | if (argName) {␊ |
1109 | strncpy( *argP, argName, argLen );␊ |
1110 | *argP += argLen;␊ |
1111 | *argP[0] = '=';␊ |
1112 | (*argP)++;␊ |
1113 | }␊ |
1114 | ␊ |
1115 | strncpy( *argP, val, cnt );␊ |
1116 | *argP += cnt;␊ |
1117 | *argP[0] = ' ';␊ |
1118 | (*argP)++;␊ |
1119 | ␊ |
1120 | *cntRemainingP -= len;␊ |
1121 | return true;␊ |
1122 | }␊ |
1123 | ␊ |
1124 | // ␊ |
1125 | // Returns TRUE if an argument was copied, FALSE otherwise␊ |
1126 | bool␊ |
1127 | processBootArgument(␊ |
1128 | const char *argName, // The argument to search for␊ |
1129 | const char *userString, // Typed-in boot arguments␊ |
1130 | const char *kernelFlags, // Kernel flags from config table␊ |
1131 | const char *configTable,␊ |
1132 | char **argP, // Output value␊ |
1133 | int *cntRemainingP, // Output count␊ |
1134 | char *foundVal, // found value␊ |
1135 | int foundValSize // max found value size␊ |
1136 | ) {␊ |
1137 | ␉const char *val;␊ |
1138 | ␉int cnt;␊ |
1139 | ␉bool found = false;␊ |
1140 | ␊ |
1141 | ␉if (getValueForBootKey(userString, argName, &val, &cnt)) {␊ |
1142 | ␉␉// Don't copy; these values will be copied at the end of argument processing.␊ |
1143 | ␉␉found = true;␊ |
1144 | ␉} else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {␊ |
1145 | ␉␉// Don't copy; these values will be copied at the end of argument processing.␊ |
1146 | ␉␉found = true;␊ |
1147 | ␉} else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig)) {␊ |
1148 | ␉␉copyArgument(argName, val, cnt, argP, cntRemainingP);␊ |
1149 | ␉␉found = true;␊ |
1150 | ␉}␊ |
1151 | ␉if (found && foundVal) {␊ |
1152 | ␉␉strlcpy(foundVal, val, foundValSize);␊ |
1153 | ␉}␊ |
1154 | ␉return found;␊ |
1155 | }␊ |
1156 | ␊ |
1157 | // Maximum config table value size␊ |
1158 | #define VALUE_SIZE 2048␊ |
1159 | ␊ |
1160 | int␊ |
1161 | processBootOptions()␊ |
1162 | {␊ |
1163 | ␉const char *cp = gBootArgs;␊ |
1164 | ␉const char *val = 0;␊ |
1165 | ␉const char *kernel;␊ |
1166 | ␉int cnt;␊ |
1167 | ␉int userCnt;␊ |
1168 | ␉int cntRemaining;␊ |
1169 | ␉char *argP;␊ |
1170 | ␉char *configKernelFlags;␊ |
1171 | ␉char *valueBuffer;␊ |
1172 | ␊ |
1173 | ␉valueBuffer = malloc(VALUE_SIZE);␊ |
1174 | ␊ |
1175 | ␉skipblanks( &cp );␊ |
1176 | ␊ |
1177 | ␉// Update the unit and partition number.␊ |
1178 | ␊ |
1179 | ␉if ( gBootVolume ) {␊ |
1180 | ␉␉if (!( gBootVolume->flags & kBVFlagNativeBoot )) {␊ |
1181 | ␉␉␉readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 );␊ |
1182 | ␉␉␉//␊ |
1183 | ␉␉␉// Setup edx, and signal intention to chain load the␊ |
1184 | ␉␉␉// foreign booter.␊ |
1185 | ␉␉␉//␊ |
1186 | ␊ |
1187 | ␉␉␉chainbootdev = gBootVolume->biosdev;␊ |
1188 | ␉␉␉chainbootflag = 1;␊ |
1189 | ␊ |
1190 | ␉␉␉return 1;␊ |
1191 | ␉␉}␊ |
1192 | ␊ |
1193 | ␉␉setRootVolume(gBootVolume);␊ |
1194 | ␊ |
1195 | ␉}␊ |
1196 | ␉// If no boot volume fail immediately because we're just going to fail␊ |
1197 | ␉// trying to load the config file anyway.␊ |
1198 | ␉else {␊ |
1199 | ␉␉return -1;␊ |
1200 | ␉}␊ |
1201 | ␊ |
1202 | ␉// Load config table specified by the user, or use the default.␊ |
1203 | ␊ |
1204 | ␉if (!getValueForBootKey(cp, "config", &val, &cnt)) {␊ |
1205 | ␉␉val = 0;␊ |
1206 | ␉␉cnt = 0;␊ |
1207 | ␉}␊ |
1208 | ␊ |
1209 | ␉// Load com.apple.Boot.plist from the selected volume␊ |
1210 | ␉// and use its contents to override default bootConfig.␊ |
1211 | ␊ |
1212 | ␉loadSystemConfig(&bootInfo->bootConfig); ␊ |
1213 | ␉loadChameleonConfig(&bootInfo->chameleonConfig);␊ |
1214 | ␊ |
1215 | ␉// Use the kernel name specified by the user, or fetch the name␊ |
1216 | ␉// in the config table, or use the default if not specified.␊ |
1217 | ␉// Specifying a kernel name on the command line, or specifying␊ |
1218 | ␉// a non-default kernel name in the config file counts as␊ |
1219 | ␉// overriding the kernel, which causes the kernelcache not␊ |
1220 | ␉// to be used.␊ |
1221 | ␊ |
1222 | ␉gOverrideKernel = false;␊ |
1223 | ␉if (( kernel = extractKernelName((char **)&cp) )) {␊ |
1224 | ␉␉strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );␊ |
1225 | ␉} else {␊ |
1226 | ␉␉if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1227 | ␉␉␉strlcpy( bootInfo->bootFile, val, cnt+1 );␊ |
1228 | ␉␉} else {␊ |
1229 | ␉␉␉strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );␊ |
1230 | ␉␉}␊ |
1231 | ␉}␊ |
1232 | ␉if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {␊ |
1233 | ␉␉gOverrideKernel = true;␊ |
1234 | ␉}␊ |
1235 | ␊ |
1236 | ␉cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space␊ |
1237 | ␉argP = bootArgs->CommandLine;␊ |
1238 | ␊ |
1239 | ␉// Get config kernel flags, if not ignored.␊ |
1240 | ␉if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||␊ |
1241 | !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) {␊ |
1242 | ␉␉val = "";␊ |
1243 | ␉␉cnt = 0;␊ |
1244 | ␉}␊ |
1245 | ␉configKernelFlags = malloc(cnt + 1);␊ |
1246 | ␉strlcpy(configKernelFlags, val, cnt + 1);␊ |
1247 | ␊ |
1248 | ␉// boot-uuid can be set either on the command-line or in the config file␊ |
1249 | ␉if (!processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config,␊ |
1250 | &argP, &cntRemaining, gBootUUIDString, sizeof(gBootUUIDString))) {␊ |
1251 | ␉␉//␊ |
1252 | ␉␉// Try an alternate method for getting the root UUID on boot helper partitions.␊ |
1253 | ␉␉//␊ |
1254 | ␉␉if (gBootVolume->flags & kBVFlagBooter) {␊ |
1255 | ␉␉␉// Load the configuration store in the boot helper partition␊ |
1256 | ␉␉␉if (loadHelperConfig(&bootInfo->helperConfig) == 0) {␊ |
1257 | ␉␉␉␉val = getStringForKey(kHelperRootUUIDKey, &bootInfo->helperConfig);␊ |
1258 | ␉␉␉␉if (val != NULL) {␊ |
1259 | ␉␉␉␉␉strlcpy(gBootUUIDString, val, sizeof(gBootUUIDString));␊ |
1260 | ␉␉␉␉}␊ |
1261 | ␉␉␉}␊ |
1262 | ␉␉}␊ |
1263 | /*␊ |
1264 | ␉␉// Try to get the volume uuid string␊ |
1265 | ␉␉if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) {␊ |
1266 | ␉␉␉gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString);␊ |
1267 | ␉␉}␊ |
1268 | */␊ |
1269 | ␉␉// If we have the volume uuid add it to the commandline arguments␊ |
1270 | ␉␉if (strlen(gBootUUIDString)) {␊ |
1271 | ␉␉␉copyArgument(kBootUUIDKey, gBootUUIDString, strlen(gBootUUIDString), &argP, &cntRemaining);␊ |
1272 | ␉␉}␊ |
1273 | ␊ |
1274 | // Try to get the volume uuid string␊ |
1275 | if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) {␊ |
1276 | ␉␉␉gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString);␊ |
1277 | DBG("boot-uuid: %s\n", gBootUUIDString);␊ |
1278 | ␉␉}␊ |
1279 | ␉}␊ |
1280 | ␊ |
1281 | ␉if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config,␊ |
1282 | &argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE)) {␊ |
1283 | ␉␉cnt = 0;␊ |
1284 | ␉␉if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig)) {␊ |
1285 | ␉␉␉valueBuffer[0] = '*';␊ |
1286 | ␉␉␉cnt++;␊ |
1287 | ␉␉␉strlcpy(valueBuffer + 1, val, cnt);␊ |
1288 | ␉␉␉val = valueBuffer;␊ |
1289 | ␉␉} else { /*␊ |
1290 | ␉␉␉if (strlen(gBootUUIDString)) {␊ |
1291 | ␉␉␉␉val = "*uuid";␊ |
1292 | ␉␉␉␉cnt = 5;␊ |
1293 | ␉␉␉} else { */␊ |
1294 | ␉␉␉␉// Don't set "rd=.." if there is no boot device key␊ |
1295 | ␉␉␉␉// and no UUID.␊ |
1296 | ␉␉␉␉val = "";␊ |
1297 | ␉␉␉␉cnt = 0;␊ |
1298 | ␉␉␉/* } */␊ |
1299 | ␉␉}␊ |
1300 | ␊ |
1301 | ␉␉if (cnt > 0) {␊ |
1302 | ␉␉␉copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);␊ |
1303 | ␉␉}␊ |
1304 | ␉␉strlcpy( gRootDevice, val, (cnt + 1));␊ |
1305 | ␉}␊ |
1306 | ␊ |
1307 | ␉/*␊ |
1308 | ␉ * Removed. We don't need this anymore.␊ |
1309 | ␉ *␊ |
1310 | ␉if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config,␊ |
1311 | ␉␉␉␉␉␉␉ &argP, &cntRemaining, gPlatformName, sizeof(gCacheNameAdler))) {␊ |
1312 | ␉␉getPlatformName(gPlatformName);␊ |
1313 | ␉␉copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);␊ |
1314 | ␉}␊ |
1315 | ␉*/␊ |
1316 | ␊ |
1317 | ␉if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&␊ |
1318 | !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) {␊ |
1319 | ␉␉if (gBootMode & kBootModeSafe) {␊ |
1320 | ␉␉␉copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);␊ |
1321 | ␉␉}␊ |
1322 | ␉}␊ |
1323 | ␊ |
1324 | ␉// Store the merged kernel flags and boot args.␊ |
1325 | ␊ |
1326 | ␉cnt = strlen(configKernelFlags);␊ |
1327 | ␉if (cnt) {␊ |
1328 | ␉␉if (cnt > cntRemaining) {␊ |
1329 | ␉␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1330 | ␉␉␉cnt = cntRemaining;␊ |
1331 | ␉␉}␊ |
1332 | ␉␉strncpy(argP, configKernelFlags, cnt);␊ |
1333 | ␉␉argP[cnt++] = ' ';␊ |
1334 | ␉␉cntRemaining -= cnt;␊ |
1335 | ␉}␊ |
1336 | ␉userCnt = strlen(cp);␊ |
1337 | ␉if (userCnt > cntRemaining) {␊ |
1338 | ␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1339 | ␉␉userCnt = cntRemaining;␊ |
1340 | ␉}␊ |
1341 | ␉strncpy(&argP[cnt], cp, userCnt);␊ |
1342 | ␉argP[cnt+userCnt] = '\0';␊ |
1343 | ␊ |
1344 | ␉if(!shouldboot) {␊ |
1345 | ␉␉gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ||␊ |
1346 | ␉␉␉getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->chameleonConfig );␊ |
1347 | ␉␉␊ |
1348 | ␉␉gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) ?␊ |
1349 | ␉␉␉kBootModeSafe : kBootModeNormal;␊ |
1350 | ␊ |
1351 | ␉␉if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) {␊ |
1352 | ␉␉␉gBootMode = kBootModeSafe;␊ |
1353 | ␉␉}␊ |
1354 | ␉}␊ |
1355 | ␊ |
1356 | ␉if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1357 | ␉␉strlcpy(gMKextName, val, cnt + 1);␊ |
1358 | ␉} else {␊ |
1359 | ␉␉gMKextName[0]=0;␊ |
1360 | ␉}␊ |
1361 | ␊ |
1362 | ␉free(configKernelFlags);␊ |
1363 | ␉free(valueBuffer);␊ |
1364 | ␊ |
1365 | ␉return 0;␊ |
1366 | }␊ |
1367 | ␊ |
1368 | ␊ |
1369 | //==========================================================================␊ |
1370 | // Load the help file and display the file contents on the screen.␊ |
1371 | ␊ |
1372 | void showTextBuffer(char *buf_orig, int size)␊ |
1373 | {␊ |
1374 | ␉char␉*bp;␊ |
1375 | ␉char* buf;␊ |
1376 | ␉int␉line;␊ |
1377 | ␉int␉line_offset;␊ |
1378 | ␉int␉c;␊ |
1379 | ␊ |
1380 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1381 | ␉␉showInfoBox( "Press q to continue, space for next page.\n",buf_orig );␊ |
1382 | ␉␉return;␊ |
1383 | ␉}␊ |
1384 | ␊ |
1385 | ␉// Create a copy so that we don't mangle the original␊ |
1386 | ␉buf = malloc(size + 1);␊ |
1387 | ␉memcpy(buf, buf_orig, size);␊ |
1388 | ␉␊ |
1389 | ␊ |
1390 | bp = buf;␊ |
1391 | while (size-- > 0) {␊ |
1392 | ␉␉if (*bp == '\n') {␊ |
1393 | ␉␉␉*bp = '\0';␊ |
1394 | ␉␉}␊ |
1395 | ␉␉bp++;␊ |
1396 | }␊ |
1397 | *bp = '\1';␊ |
1398 | line_offset = 0;␊ |
1399 | ␊ |
1400 | setActiveDisplayPage(1);␊ |
1401 | ␊ |
1402 | while (1) {␊ |
1403 | ␉␉clearScreenRows(0, 24);␊ |
1404 | ␉␉setCursorPosition(0, 0, 1);␊ |
1405 | ␉␉bp = buf;␊ |
1406 | ␉␉for (line = 0; *bp != '\1' && line < line_offset; line++) {␊ |
1407 | ␉␉␉while (*bp != '\0') {␊ |
1408 | ␉␉␉␉bp++;␊ |
1409 | ␉␉␉}␊ |
1410 | ␉␉␉bp++;␊ |
1411 | ␉␉}␊ |
1412 | ␉␉for (line = 0; *bp != '\1' && line < 23; line++) {␊ |
1413 | ␉␉␉setCursorPosition(0, line, 1);␊ |
1414 | ␉␉␉printf("%s\n", bp);␊ |
1415 | ␉␉␉while (*bp != '\0') {␊ |
1416 | ␉␉␉␉bp++;␊ |
1417 | ␉␉␉}␊ |
1418 | ␉␉␉bp++;␊ |
1419 | ␉␉}␊ |
1420 | ␊ |
1421 | ␉␉setCursorPosition(0, 23, 1);␊ |
1422 | ␉␉if (*bp == '\1') {␊ |
1423 | ␉␉␉printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : "");␊ |
1424 | ␉␉} else {␊ |
1425 | ␉␉␉printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : "");␊ |
1426 | ␉␉}␊ |
1427 | ␊ |
1428 | ␉␉c = getchar();␊ |
1429 | ␉␉if (c == 'q' || c == 'Q') {␊ |
1430 | ␉␉␉break;␊ |
1431 | ␉␉}␊ |
1432 | ␉␉if ((c == 'p' || c == 'P') && line_offset > 0) {␊ |
1433 | ␉␉␉line_offset -= 23;␊ |
1434 | ␉␉}␊ |
1435 | ␉␉if (c == ' ') {␊ |
1436 | ␉␉␉if (*bp == '\1') {␊ |
1437 | ␉␉␉␉break;␊ |
1438 | ␉␉␉} else {␊ |
1439 | ␉␉␉␉line_offset += 23;␊ |
1440 | ␉␉␉}␊ |
1441 | ␉␉}␊ |
1442 | }␊ |
1443 | setActiveDisplayPage(0);␊ |
1444 | }␊ |
1445 | ␊ |
1446 | void showHelp(void)␊ |
1447 | {␊ |
1448 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1449 | ␉␉showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);␊ |
1450 | ␉} else {␊ |
1451 | ␉␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1452 | ␉}␊ |
1453 | }␊ |
1454 | ␊ |
1455 | void showTextFile(const char * filename)␊ |
1456 | {␊ |
1457 | #define MAX_TEXT_FILE_SIZE 65536␊ |
1458 | ␉char␉*buf;␊ |
1459 | ␉int␉fd;␊ |
1460 | ␉int␉size;␊ |
1461 | ␊ |
1462 | ␉if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {␊ |
1463 | ␉␉printf("\nFile not found: %s\n", filename);␊ |
1464 | ␉␉sleep(2);␊ |
1465 | ␉␉return;␊ |
1466 | ␉}␊ |
1467 | ␊ |
1468 | size = file_size(fd);␊ |
1469 | if (size > MAX_TEXT_FILE_SIZE) {␊ |
1470 | ␉␉size = MAX_TEXT_FILE_SIZE;␊ |
1471 | ␉}␊ |
1472 | buf = malloc(size);␊ |
1473 | read(fd, buf, size);␊ |
1474 | close(fd);␊ |
1475 | ␉showTextBuffer(buf, size);␊ |
1476 | ␉free(buf);␊ |
1477 | }␊ |
1478 | ␊ |
1479 | // This is a very simplistic prompting scheme that just grabs two hex characters␊ |
1480 | // Eventually we need to do something more user-friendly like display a menu␊ |
1481 | // based off of the Multiboot device list␊ |
1482 | ␊ |
1483 | int selectAlternateBootDevice(int bootdevice)␊ |
1484 | {␊ |
1485 | ␉int key;␊ |
1486 | ␉int newbootdevice;␊ |
1487 | ␉int digitsI = 0;␊ |
1488 | ␉char *end;␊ |
1489 | ␉char digits[3] = {0,0,0};␊ |
1490 | ␊ |
1491 | ␉// We've already printed the current boot device so user knows what it is␊ |
1492 | ␉printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n");␊ |
1493 | ␉printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice);␊ |
1494 | ␉do {␊ |
1495 | ␉␉key = getchar();␊ |
1496 | ␉␉switch (ASCII_KEY(key)) {␊ |
1497 | ␉␉case KEY_BKSP:␊ |
1498 | ␉␉␉if (digitsI > 0) {␊ |
1499 | ␉␉␉␉int x, y, t;␊ |
1500 | ␉␉␉␉getCursorPositionAndType(&x, &y, &t);␊ |
1501 | ␉␉␉␉// Assume x is not 0;␊ |
1502 | ␉␉␉␉x--;␊ |
1503 | ␉␉␉␉setCursorPosition(x,y,0); // back up one char␊ |
1504 | ␉␉␉␉// Overwrite with space without moving cursor position␊ |
1505 | ␉␉␉␉putca(' ', 0x07, 1);␊ |
1506 | ␉␉␉␉digitsI--;␊ |
1507 | ␉␉␉} else {␊ |
1508 | ␉␉␉␉// TODO: Beep or something␊ |
1509 | ␉␉␉}␊ |
1510 | ␉␉␉break;␊ |
1511 | ␊ |
1512 | ␉␉case KEY_ENTER:␊ |
1513 | ␉␉␉digits[digitsI] = '\0';␊ |
1514 | ␉␉␉newbootdevice = strtol(digits, &end, 16);␊ |
1515 | ␉␉␉if (end == digits && *end == '\0') {␊ |
1516 | ␉␉␉␉// User entered empty string␊ |
1517 | ␉␉␉␉printf("\nUsing default boot device %x\n", bootdevice);␊ |
1518 | ␉␉␉␉key = 0;␊ |
1519 | ␉␉␉} else if(end != digits && *end == '\0') {␊ |
1520 | ␉␉␉␉bootdevice = newbootdevice;␊ |
1521 | ␉␉␉␉printf("\n");␊ |
1522 | ␉␉␉␉key = 0; // We gots da boot device␊ |
1523 | ␉␉␉} else {␊ |
1524 | ␉␉␉␉printf("\nCouldn't parse. try again: ");␊ |
1525 | ␉␉␉␉digitsI = 0;␊ |
1526 | ␉␉␉}␊ |
1527 | ␉␉␉break;␊ |
1528 | ␊ |
1529 | ␉␉default:␊ |
1530 | ␉␉␉if (isxdigit(ASCII_KEY(key)) && digitsI < 2) {␊ |
1531 | ␉␉␉␉putchar(ASCII_KEY(key));␊ |
1532 | ␉␉␉␉digits[digitsI++] = ASCII_KEY(key);␊ |
1533 | ␉␉␉} else {␊ |
1534 | ␉␉␉␉// TODO: Beep or something␊ |
1535 | ␉␉␉}␊ |
1536 | ␉␉␉break;␊ |
1537 | ␉␉};␊ |
1538 | ␉} while (key != 0);␊ |
1539 | ␊ |
1540 | ␉return bootdevice;␊ |
1541 | }␊ |
1542 | ␊ |
1543 | bool promptForRescanOption(void)␊ |
1544 | {␊ |
1545 | ␉printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");␊ |
1546 | ␉if (getchar() == KEY_ENTER) {␊ |
1547 | ␉␉return true;␊ |
1548 | ␉} else {␊ |
1549 | ␉␉return false;␊ |
1550 | ␉}␊ |
1551 | }␊ |
1552 | |