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