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