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