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