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"␊ |
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];␊ |
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 | static void addBootArg(const char * argStr)␊ |
198 | {␊ |
199 | ␉if ( (gBootArgsPtr + strlen(argStr) + 1) < gBootArgsEnd)␊ |
200 | ␉{␊ |
201 | ␉␉*gBootArgsPtr++ = ' ';␊ |
202 | ␉␉strcat(gBootArgs, argStr);␊ |
203 | ␉␉gBootArgsPtr += strlen(argStr);␊ |
204 | ␉}␊ |
205 | }␊ |
206 | ␊ |
207 | //==========================================================================␊ |
208 | ␊ |
209 | static void showBootPrompt(int row, bool visible)␊ |
210 | {␊ |
211 | ␉extern char bootPrompt[];␊ |
212 | ␉extern char bootRescanPrompt[];␊ |
213 | ␊ |
214 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
215 | ␉␉changeCursor( 0, row, kCursorTypeUnderline, 0 ); ␊ |
216 | ␉␉clearScreenRows( row, kScreenLastRow );␊ |
217 | ␉}␊ |
218 | ␊ |
219 | ␉clearBootArgs();␊ |
220 | ␊ |
221 | ␉if (visible) {␊ |
222 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
223 | ␉␉␉if (gEnableCDROMRescan) {␊ |
224 | ␉␉␉␉printf( bootRescanPrompt );␊ |
225 | ␉␉␉} else {␊ |
226 | ␉␉␉␉printf( bootPrompt );␊ |
227 | ␉␉␉}␊ |
228 | ␉␉}␊ |
229 | ␉} else {␊ |
230 | ␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
231 | ␉␉␉clearGraphicBootPrompt();␊ |
232 | ␉␉} else {␊ |
233 | ␉␉␉printf("Press Enter to start up the foreign OS. ");␊ |
234 | ␉␉}␊ |
235 | ␉}␊ |
236 | }␊ |
237 | ␊ |
238 | //==========================================================================␊ |
239 | ␊ |
240 | static void updateBootArgs( int key )␊ |
241 | {␊ |
242 | key &= kASCIIKeyMask;␊ |
243 | ␊ |
244 | switch ( key )␊ |
245 | {␊ |
246 | case kBackspaceKey:␊ |
247 | if ( gBootArgsPtr > gBootArgs )␊ |
248 | {␊ |
249 | int x, y, t;␊ |
250 | getCursorPositionAndType( &x, &y, &t );␊ |
251 | if ( x == 0 && y )␊ |
252 | {␊ |
253 | x = 80; y--;␊ |
254 | }␊ |
255 | if (x)␊ |
256 | ␉␉␉␉␉x--;␊ |
257 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
258 | ␉␉␉␉{␊ |
259 | ␉␉␉␉␉setCursorPosition( x, y, 0 );␊ |
260 | ␉␉␉␉␉putca(' ', 0x07, 1);␊ |
261 | ␉␉␉␉} else␊ |
262 | ␉␉␉␉␉updateGraphicBootPrompt(kBackspaceKey);␊ |
263 | ␉␉␉␊ |
264 | ␉␉␉␉*gBootArgsPtr-- = '\0';␊ |
265 | ␉␉␉}␊ |
266 | ␊ |
267 | ␉␉␉break;␊ |
268 | ␊ |
269 | default:␊ |
270 | if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
271 | {␊ |
272 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
273 | ␉␉␉␉␉putchar(key); // echo to screen␊ |
274 | ␉␉␉␉else␊ |
275 | ␉␉␉␉␉updateGraphicBootPrompt(key);␊ |
276 | ␉␉␉*gBootArgsPtr++ = 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 == GRAPHICS_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 == GRAPHICS_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 (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->bootConfig)) {␊ |
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; //Azi: Mek has this commented out.␊ |
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;␊ |
780 | ␉␉char *name;␊ |
781 | ␉␉int cnt;␊ |
782 | ␉␉int optionKey;␊ |
783 | ␊ |
784 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig)) {␊ |
785 | ␉␉␉cnt += 1;␊ |
786 | ␉␉␉prompt = malloc(cnt);␊ |
787 | ␉␉␉strlcpy(prompt, val, cnt);␊ |
788 | ␉␉} else {␊ |
789 | ␉␉␉name = malloc(80);␊ |
790 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 80, false);␊ |
791 | ␉␉␉prompt = malloc(256);␊ |
792 | ␉␉␉sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);␊ |
793 | ␉␉␉free(name);␊ |
794 | ␉␉␉cnt = 0;␊ |
795 | ␉␉}␊ |
796 | ␊ |
797 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig )) {␊ |
798 | ␉␉␉// The key specified is a special key.␊ |
799 | ␉␉} else if (getValueForKey( kCDROMOptionKey, &val, &cnt, &bootInfo->bootConfig ) && cnt >= 1) {␊ |
800 | ␉␉␉optionKey = val[0];␊ |
801 | ␉␉} else {␊ |
802 | ␉␉␉// Default to F8.␊ |
803 | ␉␉␉optionKey = 0x4200;␊ |
804 | ␉␉}␊ |
805 | ␊ |
806 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
807 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
808 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
809 | ␉␉if (timeout != 0) {␊ |
810 | ␉␉␉key = countdown(prompt, kMenuTopRow, timeout);␊ |
811 | ␉␉} else {␊ |
812 | ␉␉␉key = optionKey;␊ |
813 | ␉␉}␊ |
814 | ␊ |
815 | ␉␉if (cnt) {␊ |
816 | ␉␉␉free(prompt);␊ |
817 | ␉␉}␊ |
818 | ␊ |
819 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
820 | ␊ |
821 | ␉␉// Hit the option key ?␊ |
822 | ␉␉if (key == optionKey) {␊ |
823 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
824 | ␉␉␉timeout = 0;␊ |
825 | ␉␉} else {␊ |
826 | ␉␉␉key = key & 0xFF;␊ |
827 | ␊ |
828 | ␉␉␉// Try booting hard disk if user pressed 'h'␊ |
829 | ␉␉␉if (biosDevIsCDROM(gBIOSDev) && key == 'h') {␊ |
830 | ␉␉␉␉BVRef bvr;␊ |
831 | ␊ |
832 | ␉␉␉␉// Look at partitions hosting OS X other than the CD-ROM␊ |
833 | ␉␉␉␉for (bvr = bvChain; bvr; bvr=bvr->next) {␊ |
834 | ␉␉␉␉␉if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) {␊ |
835 | ␉␉␉␉␉␉gBootVolume = bvr;␊ |
836 | ␉␉␉␉␉}␊ |
837 | ␉␉␉␉}␊ |
838 | ␉␉␉}␊ |
839 | ␉␉␉goto done;␊ |
840 | ␉␉}␊ |
841 | ␉}␊ |
842 | ␊ |
843 | ␉if (gBootMode & kBootModeQuiet) {␊ |
844 | ␉␉// No input allowed from user.␊ |
845 | ␉␉goto done;␊ |
846 | ␉}␊ |
847 | ␊ |
848 | ␉if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) {␊ |
849 | ␉␉// If the user is holding down a modifier key,␊ |
850 | ␉␉// enter safe mode.␊ |
851 | ␉␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
852 | ␉␉␉gBootMode |= kBootModeSafe;␊ |
853 | ␉␉}␊ |
854 | ␉␉goto done;␊ |
855 | ␉}␊ |
856 | ␊ |
857 | ␉if (gDeviceCount) {␊ |
858 | ␉␉// Allocate memory for an array of menu items.␊ |
859 | ␉␉menuItems = malloc(sizeof(MenuItem) * gDeviceCount);␊ |
860 | ␉␉if (menuItems == NULL) {␊ |
861 | ␉␉␉goto done;␊ |
862 | ␉␉}␊ |
863 | ␊ |
864 | ␉␉// Associate a menu item for each BVRef.␊ |
865 | ␉␉for (bvr=bvChain, i=gDeviceCount-1, selectIndex=0; bvr; bvr=bvr->next) {␊ |
866 | ␉␉␉if (bvr->visible) {␊ |
867 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, 80, true);␊ |
868 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
869 | ␉␉␉␉if (bvr == menuBVR) {␊ |
870 | ␉␉␉␉␉selectIndex = i;␊ |
871 | ␉␉␉␉}␊ |
872 | ␉␉␉␉i--;␊ |
873 | ␉␉␉}␊ |
874 | ␉␉}␊ |
875 | ␉}␊ |
876 | ␊ |
877 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
878 | ␉␉// redraw the background buffer␊ |
879 | ␉␉gui.logo.draw = true;␊ |
880 | ␉␉drawBackground();␊ |
881 | ␉␉gui.devicelist.draw = true;␊ |
882 | ␉␉gui.redraw = true;␊ |
883 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
884 | ␉␉␉//bool showBootBanner = true;␊ |
885 | ␊ |
886 | ␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
887 | ␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->bootConfig); ␊ |
888 | ␉␉␉if (showBootBanner) {␊ |
889 | ␉␉␉␉// Display banner and show hardware info.␊ |
890 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
891 | ␉␉␉}␊ |
892 | ␊ |
893 | ␉␉␉// redraw background␊ |
894 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
895 | ␉␉}␊ |
896 | ␉} else {␊ |
897 | ␉␉// Clear screen and hide the blinking cursor.␊ |
898 | ␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
899 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
900 | ␉}␊ |
901 | ␊ |
902 | ␉nextRow = kMenuTopRow;␊ |
903 | ␉showPrompt = true;␊ |
904 | ␊ |
905 | ␉if (gDeviceCount) {␊ |
906 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
907 | ␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
908 | ␉␉}␊ |
909 | ␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
910 | ␉␉nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;␊ |
911 | ␉}␊ |
912 | ␊ |
913 | ␉// Show the boot prompt.␊ |
914 | ␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
915 | ␉showBootPrompt( nextRow, showPrompt );␊ |
916 | ␉␊ |
917 | ␉do //Azi:style␊ |
918 | ␉{␊ |
919 | ␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
920 | ␉␉␉// redraw background␊ |
921 | ␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
922 | ␉␉␉// reset cursor co-ords␊ |
923 | ␉␉␉gui.debug.cursor = pos( gui.screen.width - 160 , 10 );␊ |
924 | ␉␉}␊ |
925 | ␉␉key = getc();␊ |
926 | ␉␉updateMenu( key, (void **) &menuBVR );␊ |
927 | ␉␉newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
928 | ␊ |
929 | ␉␉if (newShowPrompt != showPrompt) {␊ |
930 | ␉␉␉showPrompt = newShowPrompt;␊ |
931 | ␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
932 | ␉␉}␊ |
933 | ␊ |
934 | ␉␉if (showPrompt) {␊ |
935 | ␉␉␉updateBootArgs(key);␊ |
936 | ␉␉}␊ |
937 | ␊ |
938 | ␉␉switch (key)␊ |
939 | ␉␉{␊ |
940 | ␉␉␉case kReturnKey:␊ |
941 | ␉␉␉␉if (gui.menu.draw)␊ |
942 | ␉␉␉␉{␊ |
943 | ␉␉␉␉␉key=0;␊ |
944 | ␉␉␉␉␉break;␊ |
945 | ␉␉␉␉}␊ |
946 | ␉␉␉␉if (*gBootArgs == '?')␊ |
947 | ␉␉␉␉{␊ |
948 | ␉␉␉␉␉char * argPtr = gBootArgs;␊ |
949 | ␊ |
950 | ␉␉␉␉␉// Skip the leading "?" character.␊ |
951 | ␉␉␉␉␉argPtr++;␊ |
952 | ␉␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
953 | ␉␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
954 | ␊ |
955 | ␉␉␉␉␉/*␊ |
956 | ␉␉␉␉␉* TODO: this needs to be refactored.␊ |
957 | ␉␉␉␉␉*/␊ |
958 | ␉␉␉␉␉if (strcmp( booterCommand, "video" ) == 0)␊ |
959 | ␉␉␉␉␉{␊ |
960 | ␉␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
961 | ␉␉␉␉␉␉{␊ |
962 | ␉␉␉␉␉␉␉showInfoBox(getVBEInfoString(), getVBEModeInfoString());␊ |
963 | ␉␉␉␉␉␉}␊ |
964 | ␉␉␉␉␉␉else␊ |
965 | ␉␉␉␉␉␉{␊ |
966 | ␉␉␉␉␉␉␉printVBEModeInfo();␊ |
967 | ␉␉␉␉␉␉}␊ |
968 | ␉␉␉␉␉}␊ |
969 | ␉␉␉␉␉else if ( strcmp( booterCommand, "memory" ) == 0)␊ |
970 | ␉␉␉␉␉{␊ |
971 | ␉␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
972 | ␉␉␉␉␉␉{␊ |
973 | ␉␉␉␉␉␉␉showInfoBox("Memory Map", getMemoryInfoString());␊ |
974 | ␉␉␉␉␉␉}␊ |
975 | ␉␉␉␉␉␉else␊ |
976 | ␉␉␉␉␉␉{␊ |
977 | ␉␉␉␉␉␉␉printMemoryInfo();␊ |
978 | ␉␉␉␉␉␉}␊ |
979 | ␉␉␉␉␉}␊ |
980 | ␉␉␉␉␉else if (strcmp(booterCommand, "lspci") == 0)␊ |
981 | ␉␉␉␉␉{␊ |
982 | ␉␉␉␉␉␉lspci();␊ |
983 | ␉␉␉␉␉} //Azi: ?more ??␊ |
984 | ␉␉␉␉␉else if (strcmp(booterCommand, "more") == 0)␊ |
985 | ␉␉␉␉␉{␊ |
986 | ␉␉␉␉␉␉showTextFile(booterParam);␊ |
987 | ␉␉␉␉␉}␊ |
988 | ␉␉␉␉␉else if (strcmp(booterCommand, "rd") == 0)␊ |
989 | ␉␉␉␉␉{␊ |
990 | ␉␉␉␉␉␉processRAMDiskCommand(&argPtr, booterParam);␊ |
991 | ␉␉␉␉␉}␊ |
992 | ␉␉␉␉␉else if (strcmp(booterCommand, "norescan") == 0)␊ |
993 | ␉␉␉␉␉{␊ |
994 | ␉␉␉␉␉␉if (gEnableCDROMRescan)␊ |
995 | ␉␉␉␉␉␉{␊ |
996 | ␉␉␉␉␉␉␉gEnableCDROMRescan = false;␊ |
997 | ␉␉␉␉␉␉␉break;␊ |
998 | ␉␉␉␉␉␉}␊ |
999 | ␉␉␉␉␉}␊ |
1000 | ␉␉␉␉␉else␊ |
1001 | ␉␉␉␉␉{␊ |
1002 | ␉␉␉␉␉␉showHelp();␊ |
1003 | ␉␉␉␉␉}␊ |
1004 | ␉␉␉␉␉key = 0;␊ |
1005 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1006 | ␉␉␉␉␉break;␊ |
1007 | ␉␉␉␉}␊ |
1008 | ␉␉␉␉gBootVolume = menuBVR;␊ |
1009 | ␉␉␉␉setRootVolume(menuBVR);␊ |
1010 | ␉␉␉␉gBIOSDev = menuBVR->biosdev;␊ |
1011 | ␉␉␉␉break;␊ |
1012 | ␉␉␉␊ |
1013 | ␉␉␉case kEscapeKey:␊ |
1014 | ␉␉␉␉clearBootArgs();␊ |
1015 | ␉␉␉␉break;␊ |
1016 | ␉␉␉␊ |
1017 | ␉␉␉case kF2Key:␊ |
1018 | ␉␉␉␉␉␉␉␊ |
1019 | ␉␉␉␉/*␊ |
1020 | ␉␉␉␉ * AutoResolution - Reapply the patch if Graphics Mode was incorrect␊ |
1021 | ␉␉␉␉ * or EDID Info was insane␊ |
1022 | ␉␉␉␉ */␊ |
1023 | ␉␉␉␉␊ |
1024 | ␉␉␉␉//get the new Graphics Mode key␊ |
1025 | ␉␉␉␉processBootOptions(); //Azi: calling this just to get the resolution??␊ |
1026 | ␉␉␉␉if ((gAutoResolution == TRUE) && map)␊ |
1027 | ␉␉␉␉{␊ |
1028 | ␉␉␉␉␉UInt32 params[4];␊ |
1029 | ␉␉␉␉␉params[3] = 0;␊ |
1030 | ␉␉␉␉␉//Has the target Resolution Changed ?␊ |
1031 | ␉␉␉␉␉int count = getNumberArrayFromProperty(kGraphicsModeKey, params, 4);␊ |
1032 | ␉␉␉␉␉if ( count < 3 )␊ |
1033 | ␉␉␉␉␉␉getResolution(params);␊ |
1034 | ␊ |
1035 | ␉␉␉␉␉if (␉(params[0] != 0) && (params[1] != 0)␊ |
1036 | ␉␉␉␉␉␉&&␉(params[0] != map->currentX) && (params[1] != map->currentY))␊ |
1037 | ␉␉␉␉␉{␊ |
1038 | ␊ |
1039 | ␉␉␉␉␉␉//Go back to TEXT mode while we change the mode␊ |
1040 | ␉␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
1041 | ␉␉␉␉␉␉{␊ |
1042 | ␉␉␉␉␉␉␉CursorState cursorState;␊ |
1043 | ␊ |
1044 | ␉␉␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1045 | ␊ |
1046 | ␉␉␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1047 | ␉␉␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1048 | ␉␉␉␉␉␉␉changeCursor( 0, 0, kCursorTypeHidden, &cursorState );␊ |
1049 | ␊ |
1050 | ␉␉␉␉␉␉␉//Reapply patch in case resolution have changed␊ |
1051 | ␊ |
1052 | ␉␉␉␉␉␉␉patchVbios(map, params[0], params[1], params[2], 0, 0);␊ |
1053 | ␊ |
1054 | ␉␉␉␉␉␉␉if (useGUI && (gui.initialised == true))␊ |
1055 | ␉␉␉␉␉␉␉␉initGUI();␊ |
1056 | ␉␉␉␉␉␉␉// Make sure all values are set␊ |
1057 | ␉␉␉␉␉␉␉if (bootArgs->Video.v_display != GRAPHICS_MODE)␊ |
1058 | ␉␉␉␉␉␉␉␉bootArgs->Video.v_display = GRAPHICS_MODE;␊ |
1059 | ␊ |
1060 | ␉␉␉␉␉␉␉if (!useGUI)␊ |
1061 | ␉␉␉␉␉␉␉␉useGUI = true;␊ |
1062 | ␊ |
1063 | ␉␉␉␉␉␉␉// redraw the background buffer␊ |
1064 | ␉␉␉␉␉␉␉drawBackground();␊ |
1065 | ␉␉␉␉␉␉␉gui.devicelist.draw = true;␊ |
1066 | ␉␉␉␉␉␉␉gui.redraw = true;␊ |
1067 | ␉␉␉␉␉␉␉if (!(gBootMode & kBootModeQuiet))␊ |
1068 | ␉␉␉␉␉␉␉{␊ |
1069 | ␉␉␉␉␉␉␉␉//bool showBootBanner = true;␊ |
1070 | ␊ |
1071 | ␉␉␉␉␉␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
1072 | ␉␉␉␉␉␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->bootConfig); ␊ |
1073 | ␉␉␉␉␉␉␉␉if (showBootBanner)␊ |
1074 | ␉␉␉␉␉␉␉␉␉// Display banner and show hardware info.␊ |
1075 | ␉␉␉␉␉␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1076 | ␊ |
1077 | ␉␉␉␉␉␉␉␉// redraw background␊ |
1078 | ␉␉␉␉␉␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
1079 | ␉␉␉␉␉␉␉}␊ |
1080 | ␊ |
1081 | ␉␉␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1082 | ␉␉␉␉␉␉␉showPrompt = true;␊ |
1083 | ␊ |
1084 | ␉␉␉␉␉␉␉if (gDeviceCount)␊ |
1085 | ␉␉␉␉␉␉␉{␊ |
1086 | ␉␉␉␉␉␉␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
1087 | ␉␉␉␉␉␉␉␉nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;␊ |
1088 | ␉␉␉␉␉␉␉}␊ |
1089 | ␊ |
1090 | ␉␉␉␉␉␉␉// Show the boot prompt.␊ |
1091 | ␉␉␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1092 | ␉␉␉␉␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
1093 | ␊ |
1094 | ␉␉␉␉␉␉␉//this is used to avoid resetting the incorrect mode while quiting the boot menu␊ |
1095 | ␉␉␉␉␉␉␉map->hasSwitched = true;␊ |
1096 | ␉␉␉␉␉␉}␊ |
1097 | ␉␉␉␉␉}␊ |
1098 | ␉␉␉␉␉clearBootArgs();␊ |
1099 | ␉␉␉␉␉key = 0;␊ |
1100 | ␉␉␉␉}␊ |
1101 | ␉␉␉␉break;␊ |
1102 | ␉␉␉␊ |
1103 | ␉␉␉case kF5Key:␊ |
1104 | ␉␉␉␉// New behavior:␊ |
1105 | ␉␉␉␉// Clear gBootVolume to restart the loop␊ |
1106 | ␉␉␉␉// if the user enabled rescanning the optical drive.␊ |
1107 | ␉␉␉␉// Otherwise boot the default boot volume.␊ |
1108 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
1109 | ␉␉␉␉{␊ |
1110 | ␉␉␉␉␉gBootVolume = NULL;␊ |
1111 | ␉␉␉␉␉clearBootArgs();␊ |
1112 | ␉␉␉␉}␊ |
1113 | ␉␉␉␉break;␊ |
1114 | ␉␉␉␊ |
1115 | ␉␉␉case kF10Key:␊ |
1116 | ␉␉␉␉gScanSingleDrive = false;␊ |
1117 | ␉␉␉␉scanDisks(gBIOSDev, &bvCount);␊ |
1118 | ␉␉␉␉gBootVolume = NULL;␊ |
1119 | ␉␉␉␉clearBootArgs();␊ |
1120 | ␉␉␉␉break;␊ |
1121 | ␉␉␉␊ |
1122 | ␉␉␉case kTabKey:␊ |
1123 | ␉␉␉␉// New behavior:␊ |
1124 | ␉␉␉␉// Switch between text & graphic interfaces␊ |
1125 | ␉␉␉␉// Only Permitted if started in graphics interface␊ |
1126 | ␉␉␉␉if (useGUI)␊ |
1127 | ␉␉␉␉{␊ |
1128 | ␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1129 | ␊ |
1130 | ␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1131 | ␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1132 | ␊ |
1133 | ␉␉␉␉␉// Display banner and show hardware info.␊ |
1134 | ␉␉␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1135 | ␉␉␉␉␉printf(getVBEInfoString());␊ |
1136 | ␊ |
1137 | ␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
1138 | ␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
1139 | ␊ |
1140 | ␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1141 | ␉␉␉␉␉showPrompt = true;␊ |
1142 | ␊ |
1143 | ␉␉␉␉␉if (gDeviceCount)␊ |
1144 | ␉␉␉␉␉{␊ |
1145 | ␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1146 | ␉␉␉␉␉␉showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
1147 | ␉␉␉␉␉␉nextRow += min(gDeviceCount, kMenuMaxItems) + 3;␊ |
1148 | ␉␉␉␉␉}␊ |
1149 | ␊ |
1150 | ␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1151 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1152 | ␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
1153 | ␊ |
1154 | ␉␉␉␉␉/*␊ |
1155 | ␉␉␉␉␉ * AutoResolution - make sure all values are set␊ |
1156 | ␉␉␉␉␉ */␊ |
1157 | ␊ |
1158 | ␉␉␉␉␉bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
1159 | ␉␉␉␉␉useGUI = false;␊ |
1160 | ␉␉␉␉}␊ |
1161 | ␉␉␉␉else␊ |
1162 | ␉␉␉␉{␊ |
1163 | ␉␉␉␉␉gui.redraw = true;␊ |
1164 | ␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1165 | ␊ |
1166 | ␉␉␉␉␉/*␊ |
1167 | ␉␉␉␉␉ * AutoResolution - make sure all values are set␊ |
1168 | ␉␉␉␉␉ */␊ |
1169 | ␉␉␉␉␉bootArgs->Video.v_display = GRAPHICS_MODE;␊ |
1170 | ␉␉␉␉␉useGUI = true;␊ |
1171 | ␊ |
1172 | ␉␉␉␉␉updateVRAM();␊ |
1173 | ␉␉␉␉}␊ |
1174 | ␉␉␉␉key = 0;␊ |
1175 | ␉␉␉␉break;␊ |
1176 | ␊ |
1177 | ␉␉␉default:␊ |
1178 | ␉␉␉␉key = 0;␊ |
1179 | ␉␉␉␉break;␊ |
1180 | ␉␉}␊ |
1181 | ␉} while (0 == key);␊ |
1182 | ␊ |
1183 | done:␊ |
1184 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
1185 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
1186 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
1187 | ␉}␊ |
1188 | ␉shouldboot = false;␊ |
1189 | ␉gui.menu.draw = false;␊ |
1190 | ␉if (menuItems) {␊ |
1191 | ␉␉free(menuItems);␊ |
1192 | ␉␉menuItems = NULL;␊ |
1193 | ␉}␊ |
1194 | ␉return 0;␊ |
1195 | }␊ |
1196 | ␊ |
1197 | //==========================================================================␊ |
1198 | ␊ |
1199 | extern unsigned char chainbootdev;␊ |
1200 | extern unsigned char chainbootflag;␊ |
1201 | ␊ |
1202 | bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)␊ |
1203 | {␊ |
1204 | int argLen = argName ? strlen(argName) : 0;␊ |
1205 | int len = argLen + cnt + 1; // +1 to account for space␊ |
1206 | ␊ |
1207 | if (len > *cntRemainingP) {␊ |
1208 | error("Warning: boot arguments too long, truncating\n");␊ |
1209 | return false;␊ |
1210 | }␊ |
1211 | ␊ |
1212 | if (argName) {␊ |
1213 | strncpy( *argP, argName, argLen );␊ |
1214 | *argP += argLen;␊ |
1215 | *argP[0] = '=';␊ |
1216 | (*argP)++;␊ |
1217 | len++; // +1 to account for '='␊ |
1218 | }␊ |
1219 | strncpy( *argP, val, cnt );␊ |
1220 | *argP += cnt;␊ |
1221 | *argP[0] = ' ';␊ |
1222 | (*argP)++;␊ |
1223 | ␊ |
1224 | *cntRemainingP -= len;␊ |
1225 | return true;␊ |
1226 | }␊ |
1227 | ␊ |
1228 | // ␊ |
1229 | // Returns TRUE if an argument was copied, FALSE otherwise␊ |
1230 | bool␊ |
1231 | processBootArgument(␊ |
1232 | const char *argName, // The argument to search for␊ |
1233 | const char *userString, // Typed-in boot arguments␊ |
1234 | const char *kernelFlags, // Kernel flags from config table␊ |
1235 | const char *configTable,␊ |
1236 | char **argP, // Output value␊ |
1237 | int *cntRemainingP, // Output count␊ |
1238 | char *foundVal // found value␊ |
1239 | )␊ |
1240 | {␊ |
1241 | const char *val;␊ |
1242 | int cnt;␊ |
1243 | bool found = false;␊ |
1244 | ␊ |
1245 | if (getValueForBootKey(userString, argName, &val, &cnt)) {␊ |
1246 | // Don't copy; these values will be copied at the end of argument processing.␊ |
1247 | found = true;␊ |
1248 | } else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {␊ |
1249 | // Don't copy; these values will be copied at the end of argument processing.␊ |
1250 | found = true;␊ |
1251 | } else if (getValueForKey(argName, &val, &cnt, &bootInfo->bootConfig)) {␊ |
1252 | copyArgument(argName, val, cnt, argP, cntRemainingP);␊ |
1253 | found = true;␊ |
1254 | }␊ |
1255 | if (found && foundVal) {␊ |
1256 | strlcpy(foundVal, val, cnt+1);␊ |
1257 | }␊ |
1258 | return found;␊ |
1259 | }␊ |
1260 | ␊ |
1261 | // Maximum config table value size␊ |
1262 | #define VALUE_SIZE 2048␊ |
1263 | ␊ |
1264 | int␊ |
1265 | processBootOptions()␊ |
1266 | {␊ |
1267 | const char * cp = gBootArgs;␊ |
1268 | const char * val = 0;␊ |
1269 | const char * kernel;␊ |
1270 | ␉const char␉␉*value;␊ |
1271 | ␉int␉␉␉␉ len;␊ |
1272 | int cnt;␊ |
1273 | ␉int␉␉ userCnt;␊ |
1274 | int cntRemaining;␊ |
1275 | char * argP;␊ |
1276 | char uuidStr[64];␊ |
1277 | bool uuidSet = false;␊ |
1278 | char * configKernelFlags;␊ |
1279 | char * valueBuffer;␊ |
1280 | ␉config_file_t␉ systemVersion;␊ |
1281 | ␊ |
1282 | valueBuffer = malloc(VALUE_SIZE);␊ |
1283 | ␊ |
1284 | skipblanks( &cp );␊ |
1285 | ␊ |
1286 | // Update the unit and partition number.␊ |
1287 | ␊ |
1288 | if ( gBootVolume )␊ |
1289 | {␊ |
1290 | if (!( gBootVolume->flags & kBVFlagNativeBoot ))␊ |
1291 | {␊ |
1292 | readBootSector( gBootVolume->biosdev, gBootVolume->part_boff,␊ |
1293 | (void *) 0x7c00 );␊ |
1294 | ␊ |
1295 | //␊ |
1296 | // Setup edx, and signal intention to chain load the␊ |
1297 | // foreign booter.␊ |
1298 | //␊ |
1299 | ␊ |
1300 | chainbootdev = gBootVolume->biosdev;␊ |
1301 | chainbootflag = 1;␊ |
1302 | ␊ |
1303 | return 1;␊ |
1304 | }␊ |
1305 | setRootVolume( gBootVolume );␊ |
1306 | }␊ |
1307 | // If no boot volume fail immediately because we're just going to fail␊ |
1308 | // trying to load the config file anyway.␊ |
1309 | else␊ |
1310 | return -1;␊ |
1311 | ␊ |
1312 | ␉// Needed here to enable search for override Boot.plist on OS specific folders.␊ |
1313 | ␉// Find out which Mac OS version we're booting.␊ |
1314 | ␉if (!loadConfigFile("/System/Library/CoreServices/SystemVersion.plist", &systemVersion))␊ |
1315 | ␉{␊ |
1316 | ␉␉if (getValueForKey(kProductVersion, &value, &len, &systemVersion))␊ |
1317 | ␉␉{␊ |
1318 | ␉␉␉// getValueForKey uses const char for val␊ |
1319 | ␉␉␉// so copy it and trim␊ |
1320 | ␉␉␉strncpy(gMacOSVersion, value, MIN(len, 4));␊ |
1321 | ␉␉␉gMacOSVersion[MIN(len, 4)] = '\0';␊ |
1322 | ␉␉}␊ |
1323 | ␉}␊ |
1324 | ␊ |
1325 | ␉//Azi: implemented at loadOverrideConfig.␊ |
1326 | // Load config table specified by the user, or use the default.␊ |
1327 | //if (!getValueForBootKey(cp, "config", &val, &cnt)) {␊ |
1328 | // val = 0;␊ |
1329 | // cnt = 0;␊ |
1330 | //}␊ |
1331 | ␊ |
1332 | // Load com.apple.Boot.plist from the selected volume␊ |
1333 | // and use its contents to override default bootConfig.␊ |
1334 | // This is not a mandatory operation anymore.␊ |
1335 | ␊ |
1336 | loadOverrideConfig(&bootInfo->overrideConfig);␊ |
1337 | ␊ |
1338 | // Use the kernel name specified by the user, or fetch the name␊ |
1339 | // in the config table, or use the default if not specified.␊ |
1340 | // Specifying a kernel name on the command line, or specifying␊ |
1341 | // a non-default kernel name in the config file counts as␊ |
1342 | // overriding the kernel, which causes the kernelcache not␊ |
1343 | // to be used.␊ |
1344 | ␊ |
1345 | gOverrideKernel = false;␊ |
1346 | if (( kernel = extractKernelName((char **)&cp) )) {␊ |
1347 | strcpy( bootInfo->bootFile, kernel );␊ |
1348 | gOverrideKernel = true;␊ |
1349 | } else {␊ |
1350 | if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1351 | strlcpy( bootInfo->bootFile, val, cnt+1 );␊ |
1352 | if (strcmp( bootInfo->bootFile, kDefaultKernelName ) != 0) {␊ |
1353 | gOverrideKernel = true;␊ |
1354 | }␊ |
1355 | } else {␊ |
1356 | strcpy( bootInfo->bootFile, kDefaultKernelName );␊ |
1357 | }␊ |
1358 | }␊ |
1359 | ␊ |
1360 | cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space␊ |
1361 | argP = bootArgs->CommandLine;␊ |
1362 | ␊ |
1363 | // Get config table kernel flags, if not ignored.␊ |
1364 | if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||␊ |
1365 | ␉␉!getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) {␊ |
1366 | val = "";␊ |
1367 | cnt = 0;␊ |
1368 | }␊ |
1369 | configKernelFlags = malloc(cnt + 1);␊ |
1370 | strlcpy(configKernelFlags, val, cnt + 1);␊ |
1371 | ␊ |
1372 | if (processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0)) {␊ |
1373 | // boot-uuid was set either on the command-line or in the config file.␊ |
1374 | uuidSet = true;␊ |
1375 | } else {␊ |
1376 | // Try an alternate method for getting the root UUID on boot helper partitions.␊ |
1377 | if (gBootVolume->flags & kBVFlagBooter)␊ |
1378 | {␊ |
1379 | ␉if ((loadHelperConfig(&bootInfo->helperConfig) == 0)␊ |
1380 | ␉ && getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig) )␊ |
1381 | ␉{␊ |
1382 | ␉␉getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig);␊ |
1383 | ␉copyArgument(kBootUUIDKey, val, cnt, &argP, &cntRemaining);␊ |
1384 | ␉uuidSet = true;␊ |
1385 | ␉}␊ |
1386 | }␊ |
1387 | ␊ |
1388 | if (!uuidSet && gBootVolume->fs_getuuid && gBootVolume->fs_getuuid (gBootVolume, uuidStr) == 0) {␊ |
1389 | verbose("Setting boot-uuid to: %s\n", uuidStr);␊ |
1390 | copyArgument(kBootUUIDKey, uuidStr, strlen(uuidStr), &argP, &cntRemaining);␊ |
1391 | uuidSet = true;␊ |
1392 | }␊ |
1393 | }␊ |
1394 | ␊ |
1395 | if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice)) {␊ |
1396 | cnt = 0;␊ |
1397 | if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig)) {␊ |
1398 | valueBuffer[0] = '*';␊ |
1399 | cnt++;␊ |
1400 | strlcpy(valueBuffer + 1, val, cnt);␊ |
1401 | val = valueBuffer;␊ |
1402 | } else {␊ |
1403 | if (uuidSet) {␊ |
1404 | val = "*uuid";␊ |
1405 | cnt = 5;␊ |
1406 | } else {␊ |
1407 | // Don't set "rd=.." if there is no boot device key␊ |
1408 | // and no UUID.␊ |
1409 | val = "";␊ |
1410 | cnt = 0;␊ |
1411 | }␊ |
1412 | } ␊ |
1413 | if (cnt > 0) {␊ |
1414 | copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);␊ |
1415 | }␊ |
1416 | strlcpy( gRootDevice, val, (cnt + 1));␊ |
1417 | }␊ |
1418 | ␊ |
1419 | /*␊ |
1420 | * Removed. We don't need this anymore.␊ |
1421 | *␊ |
1422 | if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gPlatformName)) {␊ |
1423 | getPlatformName(gPlatformName);␊ |
1424 | copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);␊ |
1425 | }␊ |
1426 | */␊ |
1427 | ␊ |
1428 | if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&␊ |
1429 | !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) {␊ |
1430 | if (gBootMode & kBootModeSafe) {␊ |
1431 | copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);␊ |
1432 | }␊ |
1433 | }␊ |
1434 | ␊ |
1435 | // Store the merged kernel flags and boot args.␊ |
1436 | ␊ |
1437 | cnt = strlen(configKernelFlags);␊ |
1438 | if (cnt) {␊ |
1439 | if (cnt > cntRemaining) {␊ |
1440 | error("Warning: boot arguments too long, truncating\n");␊ |
1441 | cnt = cntRemaining;␊ |
1442 | }␊ |
1443 | strncpy(argP, configKernelFlags, cnt);␊ |
1444 | argP[cnt++] = ' ';␊ |
1445 | cntRemaining -= cnt;␊ |
1446 | }␊ |
1447 | userCnt = strlen(cp);␊ |
1448 | if (userCnt > cntRemaining) {␊ |
1449 | error("Warning: boot arguments too long, truncating\n");␊ |
1450 | userCnt = cntRemaining;␊ |
1451 | }␊ |
1452 | strncpy(&argP[cnt], cp, userCnt);␊ |
1453 | argP[cnt+userCnt] = '\0';␊ |
1454 | ␊ |
1455 | ␉if(!shouldboot)␊ |
1456 | ␉{␊ |
1457 | ␉␉gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->bootConfig ) ||␊ |
1458 | ␉␉␉getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->bootConfig );␊ |
1459 | ␉␉␊ |
1460 | ␉␉gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->bootConfig ) ) ?␊ |
1461 | ␉␉␉kBootModeSafe : kBootModeNormal;␊ |
1462 | ␊ |
1463 | if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1464 | gBootMode = kBootModeSafe;␊ |
1465 | }␊ |
1466 | ␉}␊ |
1467 | ␊ |
1468 | ␉if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )␊ |
1469 | ␉{␊ |
1470 | ␉␉strlcpy(gMKextName, val, cnt + 1);␊ |
1471 | ␉}␊ |
1472 | ␊ |
1473 | free(configKernelFlags);␊ |
1474 | free(valueBuffer);␊ |
1475 | ␊ |
1476 | return 0;␊ |
1477 | }␊ |
1478 | ␊ |
1479 | ␊ |
1480 | //==========================================================================␊ |
1481 | // Load the help file and display the file contents on the screen.␊ |
1482 | ␊ |
1483 | static void showTextBuffer(char *buf, int size)␊ |
1484 | {␊ |
1485 | ␉char␉*bp;␊ |
1486 | ␉int␉line;␊ |
1487 | ␉int␉line_offset;␊ |
1488 | ␉int␉c;␊ |
1489 | ␊ |
1490 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
1491 | ␉␉showInfoBox( "Press q to quit\n",buf );␊ |
1492 | ␉␉return;␊ |
1493 | ␉}␊ |
1494 | ␊ |
1495 | bp = buf;␊ |
1496 | while (size-- > 0) {␊ |
1497 | ␉␉if (*bp == '\n') {␊ |
1498 | ␉␉␉*bp = '\0';␊ |
1499 | ␉␉}␊ |
1500 | ␉␉bp++;␊ |
1501 | }␊ |
1502 | *bp = '\1';␊ |
1503 | line_offset = 0;␊ |
1504 | ␊ |
1505 | setActiveDisplayPage(1);␊ |
1506 | ␊ |
1507 | while (1) {␊ |
1508 | ␉␉clearScreenRows(0, 24);␊ |
1509 | ␉␉setCursorPosition(0, 0, 1);␊ |
1510 | ␉␉bp = buf;␊ |
1511 | ␉␉for (line = 0; *bp != '\1' && line < line_offset; line++) {␊ |
1512 | ␉␉␉while (*bp != '\0') {␊ |
1513 | ␉␉␉␉bp++;␊ |
1514 | ␉␉␉}␊ |
1515 | ␉␉␉bp++;␊ |
1516 | ␉␉}␊ |
1517 | ␉␉for (line = 0; *bp != '\1' && line < 23; line++) {␊ |
1518 | ␉␉␉setCursorPosition(0, line, 1);␊ |
1519 | ␉␉␉printf("%s\n", bp);␊ |
1520 | ␉␉␉while (*bp != '\0') {␊ |
1521 | ␉␉␉␉bp++;␊ |
1522 | ␉␉␉}␊ |
1523 | ␉␉␉bp++;␊ |
1524 | ␉␉}␊ |
1525 | ␊ |
1526 | ␉␉setCursorPosition(0, 23, 1);␊ |
1527 | ␉␉if (*bp == '\1') {␊ |
1528 | ␉␉␉printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : "");␊ |
1529 | ␉␉} else {␊ |
1530 | ␉␉␉printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : "");␊ |
1531 | ␉␉}␊ |
1532 | ␊ |
1533 | ␉␉c = getc();␊ |
1534 | ␉␉if (c == 'q' || c == 'Q') {␊ |
1535 | ␉␉␉break;␊ |
1536 | ␉␉}␊ |
1537 | ␉␉if ((c == 'p' || c == 'P') && line_offset > 0) {␊ |
1538 | ␉␉␉line_offset -= 23;␊ |
1539 | ␉␉}␊ |
1540 | ␉␉if (c == ' ') {␊ |
1541 | ␉␉␉if (*bp == '\1') {␊ |
1542 | ␉␉␉␉break;␊ |
1543 | ␉␉␉} else {␊ |
1544 | ␉␉␉␉line_offset += 23;␊ |
1545 | ␉␉␉}␊ |
1546 | ␉␉}␊ |
1547 | }␊ |
1548 | setActiveDisplayPage(0);␊ |
1549 | }␊ |
1550 | ␊ |
1551 | void showHelp(void)␊ |
1552 | {␊ |
1553 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
1554 | ␉␉showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);␊ |
1555 | ␉} else {␊ |
1556 | ␉␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1557 | ␉}␊ |
1558 | }␊ |
1559 | ␊ |
1560 | void showTextFile(const char * filename) //Azi: ?more - check this...␊ |
1561 | {␊ |
1562 | #define MAX_TEXT_FILE_SIZE 65536␊ |
1563 | ␉char␉*buf;␊ |
1564 | ␉int␉fd;␊ |
1565 | ␉int␉size;␊ |
1566 | ␊ |
1567 | ␉if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {␊ |
1568 | ␉␉printf("\nFile not found: %s\n", filename);␊ |
1569 | ␉␉sleep(2);␊ |
1570 | ␉␉return;␊ |
1571 | ␉}␊ |
1572 | ␊ |
1573 | size = file_size(fd);␊ |
1574 | if (size > MAX_TEXT_FILE_SIZE) {␊ |
1575 | ␉␉size = MAX_TEXT_FILE_SIZE;␊ |
1576 | ␉}␊ |
1577 | buf = malloc(size);␊ |
1578 | read(fd, buf, size);␊ |
1579 | close(fd);␊ |
1580 | ␉showTextBuffer(buf, size);␊ |
1581 | ␉free(buf);␊ |
1582 | }␊ |
1583 | ␊ |
1584 | // This is a very simplistic prompting scheme that just grabs two hex characters␊ |
1585 | // Eventually we need to do something more user-friendly like display a menu␊ |
1586 | // based off of the Multiboot device list␊ |
1587 | ␊ |
1588 | int selectAlternateBootDevice(int bootdevice)␊ |
1589 | {␊ |
1590 | ␉int key;␊ |
1591 | ␉int newbootdevice;␊ |
1592 | ␉int digitsI = 0;␊ |
1593 | ␉char *end;␊ |
1594 | ␉char digits[3] = {0,0,0};␊ |
1595 | ␊ |
1596 | ␉// We've already printed the current boot device so user knows what it is␊ |
1597 | ␉printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n");␊ |
1598 | ␉printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice);␊ |
1599 | ␉do {␊ |
1600 | ␉␉key = getc();␊ |
1601 | ␉␉switch (key & kASCIIKeyMask) {␊ |
1602 | ␉␉case kBackspaceKey:␊ |
1603 | ␉␉␉if (digitsI > 0) {␊ |
1604 | ␉␉␉␉int x, y, t;␊ |
1605 | ␉␉␉␉getCursorPositionAndType(&x, &y, &t);␊ |
1606 | ␉␉␉␉// Assume x is not 0;␊ |
1607 | ␉␉␉␉x--;␊ |
1608 | ␉␉␉␉setCursorPosition(x,y,0); // back up one char␊ |
1609 | ␉␉␉␉// Overwrite with space without moving cursor position␊ |
1610 | ␉␉␉␉putca(' ', 0x07, 1);␊ |
1611 | ␉␉␉␉digitsI--;␊ |
1612 | ␉␉␉} else {␊ |
1613 | ␉␉␉␉// TODO: Beep or something␊ |
1614 | ␉␉␉}␊ |
1615 | ␉␉␉break;␊ |
1616 | ␊ |
1617 | ␉␉case kReturnKey:␊ |
1618 | ␉␉␉digits[digitsI] = '\0';␊ |
1619 | ␉␉␉newbootdevice = strtol(digits, &end, 16);␊ |
1620 | ␉␉␉if (end == digits && *end == '\0') {␊ |
1621 | ␉␉␉␉// User entered empty string␊ |
1622 | ␉␉␉␉printf("\nUsing default boot device %x\n", bootdevice);␊ |
1623 | ␉␉␉␉key = 0;␊ |
1624 | ␉␉␉} else if(end != digits && *end == '\0') {␊ |
1625 | ␉␉␉␉bootdevice = newbootdevice;␊ |
1626 | ␉␉␉␉printf("\n");␊ |
1627 | ␉␉␉␉key = 0; // We gots da boot device␊ |
1628 | ␉␉␉} else {␊ |
1629 | ␉␉␉␉printf("\nCouldn't parse. try again: ");␊ |
1630 | ␉␉␉␉digitsI = 0;␊ |
1631 | ␉␉␉}␊ |
1632 | ␉␉␉break;␊ |
1633 | ␊ |
1634 | ␉␉default:␊ |
1635 | ␉␉␉if (isxdigit(key & kASCIIKeyMask) && digitsI < 2) {␊ |
1636 | ␉␉␉␉putc(key & kASCIIKeyMask);␊ |
1637 | ␉␉␉␉digits[digitsI++] = key & kASCIIKeyMask;␊ |
1638 | ␉␉␉} else {␊ |
1639 | ␉␉␉␉// TODO: Beep or something␊ |
1640 | ␉␉␉}␊ |
1641 | ␉␉␉break;␊ |
1642 | ␉␉};␊ |
1643 | ␉} while (key != 0);␊ |
1644 | ␊ |
1645 | ␉return bootdevice;␊ |
1646 | }␊ |
1647 | ␊ |
1648 | bool promptForRescanOption(void)␊ |
1649 | {␊ |
1650 | ␉printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");␊ |
1651 | ␉if (getc() == kReturnKey) {␊ |
1652 | ␉␉return true;␊ |
1653 | ␉} else {␊ |
1654 | ␉␉return false;␊ |
1655 | ␉}␊ |
1656 | }␊ |
1657 | |