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