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