1 | /*␊ |
2 | * Copyright (c) 1999-2004 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2004 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License"). You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | * ␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | ␊ |
25 | #include "boot.h"␊ |
26 | #include "fdisk.h"␊ |
27 | #include "ramdisk.h"␊ |
28 | #include "gui.h"␊ |
29 | #include "embedded.h"␊ |
30 | #include "pci.h"␊ |
31 | #include "options.h"␊ |
32 | #include "efi.h"␊ |
33 | ␊ |
34 | bool showBootBanner = true; //Azi:debuginfo␊ |
35 | static bool shouldboot = false;␊ |
36 | ␊ |
37 | extern int multiboot_timeout;␊ |
38 | extern int multiboot_timeout_set;␊ |
39 | ␊ |
40 | extern BVRef bvChain;␊ |
41 | //extern int␉␉menucount;␊ |
42 | ␊ |
43 | //extern int␉␉gDeviceCount; //Azi: header␊ |
44 | char␉␉␉gMacOSVersion[8]; //Azi: moved from boot.c - extern on boot.h/bootargs.h␊ |
45 | static bool getOSVersion(char *str); //␉␉␉||␊ |
46 | ␊ |
47 | int␉␉␉selectIndex = 0;␊ |
48 | MenuItem * menuItems = NULL;␊ |
49 | ␊ |
50 | //==========================================================================␊ |
51 | ␊ |
52 | //static //Azi:autoresolution␊ |
53 | void changeCursor( int col, int row, int type, CursorState * cs )␊ |
54 | {␊ |
55 | if (cs) getCursorPositionAndType( &cs->x, &cs->y, &cs->type );␊ |
56 | setCursorType( type );␊ |
57 | setCursorPosition( col, row, 0 );␊ |
58 | }␊ |
59 | ␊ |
60 | static void moveCursor( int col, int row )␊ |
61 | {␊ |
62 | setCursorPosition( col, row, 0 );␊ |
63 | }␊ |
64 | ␊ |
65 | static void restoreCursor( const CursorState * cs )␊ |
66 | {␊ |
67 | setCursorPosition( cs->x, cs->y, 0 );␊ |
68 | setCursorType( cs->type );␊ |
69 | }␊ |
70 | ␊ |
71 | //==========================================================================␊ |
72 | ␊ |
73 | /* Flush keyboard buffer; returns TRUE if any of the flushed␊ |
74 | * characters was F8.␊ |
75 | */␊ |
76 | ␊ |
77 | static bool flushKeyboardBuffer(void)␊ |
78 | {␊ |
79 | bool status = false;␊ |
80 | ␊ |
81 | while ( readKeyboardStatus() ) {␊ |
82 | if (bgetc() == 0x4200) status = true;␊ |
83 | }␊ |
84 | return status;␊ |
85 | }␊ |
86 | ␊ |
87 | //==========================================================================␊ |
88 | ␊ |
89 | static int countdown( const char * msg, int row, int timeout )␊ |
90 | {␊ |
91 | unsigned long time;␊ |
92 | int ch = 0;␊ |
93 | int col = strlen(msg) + 1;␊ |
94 | ␉␊ |
95 | flushKeyboardBuffer();␊ |
96 | ␊ |
97 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
98 | ␉{␊ |
99 | ␉␉moveCursor( 0, row );␊ |
100 | ␉␉printf(msg);␊ |
101 | ␊ |
102 | ␉} else {␊ |
103 | ␊ |
104 | ␉␉position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );␊ |
105 | ␉␊ |
106 | ␉␉char dummy[80];␊ |
107 | ␉␉getBootVolumeDescription( gBootVolume, dummy, sizeof(dummy) - 1, true );␊ |
108 | ␉␉drawDeviceIcon( gBootVolume, gui.screen.pixmap, p, true );␊ |
109 | ␉␉drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );␊ |
110 | ␉␉␊ |
111 | ␉␉// make this screen the new background␊ |
112 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
113 | ␉␉␊ |
114 | ␉}␊ |
115 | ␊ |
116 | ␉int multi_buff = 18 * (timeout);␊ |
117 | int multi = ++multi_buff;␊ |
118 | ␊ |
119 | int lasttime=0;␊ |
120 | ␊ |
121 | for ( time = time18(), timeout++; timeout > 0; )␊ |
122 | {␊ |
123 | ␉␉if( time18() > lasttime)␊ |
124 | ␉␉{␊ |
125 | ␉␉␉multi--; ␊ |
126 | ␉␉␉lasttime=time18();␊ |
127 | ␉␉}␉␉␊ |
128 | ␊ |
129 | if (ch = readKeyboardStatus())␊ |
130 | break;␊ |
131 | ␊ |
132 | // Count can be interrupted by holding down shift,␊ |
133 | // control or alt key␊ |
134 | if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 )␊ |
135 | ␉␉{␊ |
136 | ch = 1;␊ |
137 | break;␊ |
138 | }␊ |
139 | ␊ |
140 | if ( time18() >= time )␊ |
141 | {␊ |
142 | time += 18;␊ |
143 | timeout--;␊ |
144 | ␊ |
145 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
146 | ␉␉␉{␊ |
147 | ␉␉␉␉moveCursor( col, row );␊ |
148 | ␉␉␉␉printf("(%d) ", timeout);␊ |
149 | ␉␉␉}␊ |
150 | }␊ |
151 | ␉␊ |
152 | ␉␉if( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
153 | ␉␉{␊ |
154 | ␉␉␉drawProgressBar( gui.screen.pixmap, 100, gui.progressbar.pos , ( multi * 100 / multi_buff ) );␊ |
155 | ␉␉␉gui.redraw = true;␊ |
156 | ␉␉␉updateVRAM();␊ |
157 | ␉␉}␊ |
158 | ␊ |
159 | }␊ |
160 | ␊ |
161 | flushKeyboardBuffer();␊ |
162 | ␊ |
163 | return ch;␊ |
164 | }␊ |
165 | ␊ |
166 | //==========================================================================␊ |
167 | //Azi: bootargs reminder␊ |
168 | static char gBootArgs[BOOT_STRING_LEN];␊ |
169 | static char * gBootArgsPtr = gBootArgs;␊ |
170 | static char * gBootArgsEnd = gBootArgs + BOOT_STRING_LEN - 1;␊ |
171 | static char booterCommand[BOOT_STRING_LEN];␊ |
172 | static char booterParam[BOOT_STRING_LEN];␊ |
173 | ␊ |
174 | //static //Azi:autoresolution␊ |
175 | void clearBootArgs(void)␊ |
176 | {␊ |
177 | ␉gBootArgsPtr = gBootArgs;␊ |
178 | ␉memset(gBootArgs, '\0', BOOT_STRING_LEN);␊ |
179 | ␊ |
180 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
181 | ␉␉clearGraphicBootPrompt();␊ |
182 | ␉}␊ |
183 | }␊ |
184 | ␊ |
185 | static void addBootArg(const char * argStr)␊ |
186 | {␊ |
187 | ␉if ( (gBootArgsPtr + strlen(argStr) + 1) < gBootArgsEnd)␊ |
188 | ␉{␊ |
189 | ␉␉*gBootArgsPtr++ = ' ';␊ |
190 | ␉␉strcat(gBootArgs, argStr);␊ |
191 | ␉␉gBootArgsPtr += strlen(argStr);␊ |
192 | ␉}␊ |
193 | }␊ |
194 | ␊ |
195 | //==========================================================================␊ |
196 | ␊ |
197 | //static //Azi:autoresolution␊ |
198 | void showBootPrompt(int row, bool visible)␊ |
199 | {␊ |
200 | ␉extern char bootPrompt[];␊ |
201 | ␉extern char bootRescanPrompt[];␊ |
202 | ␊ |
203 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
204 | ␉␉changeCursor( 0, row, kCursorTypeUnderline, 0 ); ␊ |
205 | ␉␉clearScreenRows( row, kScreenLastRow );␊ |
206 | ␉}␊ |
207 | ␊ |
208 | ␉clearBootArgs();␊ |
209 | ␊ |
210 | ␉if (visible) {␊ |
211 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
212 | ␉␉␉if (gEnableCDROMRescan) {␊ |
213 | ␉␉␉␉printf( bootRescanPrompt );␊ |
214 | ␉␉␉} else {␊ |
215 | ␉␉␉␉printf( bootPrompt );␊ |
216 | ␉␉␉}␊ |
217 | ␉␉}␊ |
218 | ␉} else {␊ |
219 | ␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
220 | ␉␉␉clearGraphicBootPrompt();␊ |
221 | ␉␉} else {␊ |
222 | ␉␉␉printf("Press Enter to start up the foreign OS. ");␊ |
223 | ␉␉}␊ |
224 | ␉}␊ |
225 | }␊ |
226 | ␊ |
227 | //==========================================================================␊ |
228 | ␊ |
229 | static void updateBootArgs( int key )␊ |
230 | {␊ |
231 | key &= kASCIIKeyMask;␊ |
232 | ␊ |
233 | switch ( key )␊ |
234 | {␊ |
235 | case kBackspaceKey:␊ |
236 | if ( gBootArgsPtr > gBootArgs )␊ |
237 | {␊ |
238 | int x, y, t;␊ |
239 | getCursorPositionAndType( &x, &y, &t );␊ |
240 | if ( x == 0 && y )␊ |
241 | {␊ |
242 | x = 80; y--;␊ |
243 | }␊ |
244 | if (x)␊ |
245 | ␉␉␉␉␉x--;␊ |
246 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
247 | ␉␉␉␉{␊ |
248 | ␉␉␉␉␉setCursorPosition( x, y, 0 );␊ |
249 | ␉␉␉␉␉putca(' ', 0x07, 1);␊ |
250 | ␉␉␉␉} else␊ |
251 | ␉␉␉␉␉updateGraphicBootPrompt(kBackspaceKey);␊ |
252 | ␉␉␉␊ |
253 | ␉␉␉␉*gBootArgsPtr-- = '\0';␊ |
254 | ␉␉␉}␊ |
255 | ␊ |
256 | ␉␉␉break;␊ |
257 | ␊ |
258 | default:␊ |
259 | if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
260 | {␊ |
261 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
262 | ␉␉␉␉␉putchar(key); // echo to screen␊ |
263 | ␉␉␉␉else␊ |
264 | ␉␉␉␉␉updateGraphicBootPrompt(key);␊ |
265 | ␉␉␉␉␊ |
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 //Azi:autoresolution␊ |
302 | void showMenu( const MenuItem * items, int count,␊ |
303 | int selection, int row, int height )␊ |
304 | {␊ |
305 | int i;␊ |
306 | CursorState cursorState;␊ |
307 | ␊ |
308 | if ( items == NULL || count == 0 ) ␊ |
309 | ␉␉return;␊ |
310 | ␊ |
311 | // head and tail points to the start and the end of the list.␊ |
312 | // top and bottom points to the first and last visible items␊ |
313 | // in the menu window.␊ |
314 | ␊ |
315 | gMenuItems␉␉= items;␊ |
316 | gMenuRow␉␉= row;␊ |
317 | gMenuHeight␉␉= height;␊ |
318 | gMenuItemCount␉= count;␊ |
319 | gMenuTop␉␉= 0;␊ |
320 | gMenuBottom␉␉= MIN( count, height ) - 1;␊ |
321 | gMenuSelection␉= selection;␊ |
322 | ␊ |
323 | gMenuStart␉␉= 0;␊ |
324 | gMenuEnd␉ = MIN( count, gui.maxdevices ) - 1;␊ |
325 | ␉␊ |
326 | ␉// If the selected item is not visible, shift the list down.␊ |
327 | ␊ |
328 | if ( gMenuSelection > gMenuBottom )␊ |
329 | {␊ |
330 | gMenuTop += ( gMenuSelection - gMenuBottom );␊ |
331 | gMenuBottom = gMenuSelection;␊ |
332 | }␊ |
333 | ␊ |
334 | ␉if ( gMenuSelection > gMenuEnd )␊ |
335 | {␊ |
336 | ␉␉gMenuStart += ( gMenuSelection - gMenuEnd );␊ |
337 | gMenuEnd = gMenuSelection;␊ |
338 | }␊ |
339 | ␉␊ |
340 | ␉// Draw the visible items.␊ |
341 | ␊ |
342 | ␉if( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
343 | ␉␊ |
344 | ␉␉drawDeviceList(gMenuStart, gMenuEnd, gMenuSelection);␊ |
345 | ␊ |
346 | ␉else {␊ |
347 | ␉␉␊ |
348 | ␉␉changeCursor( 0, row, kCursorTypeHidden, &cursorState );␊ |
349 | ␊ |
350 | ␉␉for ( i = gMenuTop; i <= gMenuBottom; i++ )␊ |
351 | ␉␉{␊ |
352 | ␉␉␉printMenuItem( &items[i], (i == gMenuSelection) );␊ |
353 | ␉␉}␊ |
354 | ␊ |
355 | ␉␉restoreCursor( &cursorState );␊ |
356 | }␊ |
357 | }␊ |
358 | ␊ |
359 | //==========================================================================␊ |
360 | ␊ |
361 | static int updateMenu( int key, void ** paramPtr )␊ |
362 | {␊ |
363 | int moved = 0;␊ |
364 | ␊ |
365 | union {␊ |
366 | struct {␊ |
367 | unsigned int␊ |
368 | selectionUp : 1,␊ |
369 | selectionDown : 1,␊ |
370 | scrollUp : 1,␊ |
371 | scrollDown : 1;␊ |
372 | } f;␊ |
373 | unsigned int w;␊ |
374 | } draw = {{0}};␊ |
375 | ␊ |
376 | if ( gMenuItems == NULL )␊ |
377 | ␉␉return 0;␊ |
378 | ␊ |
379 | ␉if( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
380 | ␉{␊ |
381 | ␉␉int res;␊ |
382 | ␉␉␊ |
383 | ␉␉// set navigation keys for horizontal layout as defaults␊ |
384 | ␉␉int previous␉= 0x4B00;␉␉// left arrow␊ |
385 | ␉␉int subsequent␉= 0x4D00;␉␉// right arrow␊ |
386 | ␉␉int menu␉␉= 0x5000;␉␉// down arrow␊ |
387 | ␉␉␊ |
388 | ␉␉if ( gui.layout == VerticalLayout )␊ |
389 | ␉␉{␊ |
390 | ␉␉␉// set navigation keys for vertical layout␊ |
391 | ␉␉␉previous␉= 0x4800;␉␉// up arrow␊ |
392 | ␉␉␉subsequent␉= 0x5000;␉␉// down arrow␊ |
393 | ␉␉␉menu␉␉= 0x4B00;␉␉// right arrow␊ |
394 | ␉␉} ␊ |
395 | ␊ |
396 | ␉␉if ( key == previous )␊ |
397 | ␉␉{␊ |
398 | ␉␉␉if ( gMenuSelection > gMenuTop )␊ |
399 | ␉␉␉␉draw.f.selectionUp = 1;␊ |
400 | ␉␉␉else if ( gMenuTop > 0 )␊ |
401 | ␉␉␉␉draw.f.scrollDown = 1;␊ |
402 | ␉␉␉␊ |
403 | ␉␉}␊ |
404 | ␉␉␊ |
405 | ␉␉else if ( key == subsequent )␊ |
406 | ␉␉{␊ |
407 | ␉␉␉if ( gMenuSelection != gMenuBottom)␊ |
408 | ␉␉␉␉draw.f.selectionDown = 1;␊ |
409 | ␉␉␉else if ( gMenuBottom < ( gMenuItemCount - 1 ) )␊ |
410 | ␉␉␉␉draw.f.scrollUp = 1;␊ |
411 | ␉␉}␊ |
412 | ␉␉␊ |
413 | ␉␉else if ( key == menu )␊ |
414 | ␉␉{␊ |
415 | ␉␉␉if ( gui.menu.draw )␊ |
416 | ␉␉␉␉updateInfoMenu(key);␊ |
417 | ␉␉␉else␊ |
418 | ␉␉␉␉drawInfoMenu();␊ |
419 | ␉␉}␊ |
420 | ␊ |
421 | ␉␉else if ( gui.menu.draw )␊ |
422 | ␉␉{␊ |
423 | ␉␉␉res = updateInfoMenu(key);␊ |
424 | ␊ |
425 | ␉␉␉if ( res == CLOSE_INFO_MENU )␊ |
426 | ␉␉␉␉gui.menu.draw = false;␊ |
427 | ␉␉␉else␊ |
428 | ␉␉␉{␊ |
429 | ␉␉␉␉shouldboot = ( res != DO_NOT_BOOT );␊ |
430 | ␉␉␉␉␊ |
431 | ␉␉␉␉if ( shouldboot )␊ |
432 | ␉␉␉␉␉gui.menu.draw = false;␊ |
433 | ␊ |
434 | ␉␉␉␉switch (res)␊ |
435 | ␉␉␉␉{␊ |
436 | ␉␉␉␉␉case BOOT_NORMAL:␊ |
437 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
438 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
439 | ␉␉␉␉␉␉break;␊ |
440 | ␉␉␉␉␉␉␊ |
441 | ␉␉␉␉␉case BOOT_VERBOSE:␊ |
442 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
443 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
444 | ␉␉␉␉␉␉addBootArg(kVerboseModeFlag);␊ |
445 | ␉␉␉␉␉␉break;␊ |
446 | ␊ |
447 | ␉␉␉␉␉case BOOT_IGNORECACHE:␊ |
448 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
449 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
450 | ␉␉␉␉␉␉addBootArg(kIgnoreCachesFlag);␊ |
451 | ␉␉␉␉␉␉//Azi: this one crossed my mind a lot of times.. nice going :)␊ |
452 | ␉␉␉␉␉␉addBootArg(kVerboseModeFlag); //Slice - if ignore cache then verbose␊ |
453 | ␉␉␉␉␉␉break;␊ |
454 | ␊ |
455 | ␉␉␉␉␉case BOOT_SINGLEUSER:␊ |
456 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
457 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
458 | ␉␉␉␉␉␉addBootArg(kSingleUserModeFlag);␊ |
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 | //Azi: autoresolution␊ |
677 | int key;␊ |
678 | int nextRow;␊ |
679 | BVRef menuBVR;␊ |
680 | bool showPrompt;␊ |
681 | extern void reloadAutoRes();␊ |
682 | ␊ |
683 | int getBootOptions(bool firstRun)␊ |
684 | {␊ |
685 | ␉int i;␊ |
686 | //␉int key;␊ |
687 | //␉int nextRow;␊ |
688 | ␉int timeout;␊ |
689 | ␉int bvCount;␊ |
690 | ␉BVRef bvr;␊ |
691 | //␉BVRef menuBVR;␊ |
692 | //␉bool showPrompt;␊ |
693 | ␉bool 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;␊ |
740 | ␉}␊ |
741 | ␊ |
742 | ␉// Checking user pressed keys␊ |
743 | ␉bool f8press = false, spress = false, vpress = false;␊ |
744 | ␉while (readKeyboardStatus()) {␊ |
745 | ␉␉key = bgetc ();␊ |
746 | ␉␉if (key == 0x4200) f8press = true;␊ |
747 | ␉␉if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true;␊ |
748 | ␉␉if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true;␊ |
749 | ␉}␊ |
750 | ␉// If user typed F8, abort quiet mode, and display the menu.␊ |
751 | ␉if (f8press) {␊ |
752 | ␉␉gBootMode &= ~kBootModeQuiet;␊ |
753 | ␉␉timeout = 0;␊ |
754 | ␉}␊ |
755 | ␉// If user typed 'v' or 'V', boot in verbose mode.␊ |
756 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && vpress) {␊ |
757 | ␉␉addBootArg(kVerboseModeFlag);␊ |
758 | ␉}␊ |
759 | ␉// If user typed 's' or 'S', boot in single user mode.␊ |
760 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && spress) {␊ |
761 | ␉␉addBootArg(kSingleUserModeFlag);␊ |
762 | ␉}␊ |
763 | ␊ |
764 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
765 | ␉␉setCursorPosition(0, 0, 0);␊ |
766 | ␉␉clearScreenRows(0, kScreenLastRow);␊ |
767 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
768 | ␉␉␉// Display banner and show hardware info.␊ |
769 | ␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
770 | ␉␉␉printf(getVBEInfoString());␊ |
771 | ␉␉}␊ |
772 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
773 | ␉␉verbose("Scanning device %x...", gBIOSDev);␊ |
774 | ␉}␊ |
775 | ␊ |
776 | ␉// When booting from CD, default to hard drive boot when possible. ␊ |
777 | ␉if (isCDROM && firstRun) {␊ |
778 | ␉␉const char *val;␊ |
779 | ␉␉char *prompt = NULL;␊ |
780 | ␉␉char *name = NULL;␊ |
781 | ␉␉int cnt;␊ |
782 | ␉␉int optionKey;␊ |
783 | ␊ |
784 | ␉␉//Azi:---␊ |
785 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig)) ␊ |
786 | ␉␉{␊ |
787 | ␉␉␉prompt = malloc(cnt + 1);␊ |
788 | ␉␉␉strncat(prompt, val, cnt);␊ |
789 | ␉␉}␊ |
790 | ␉␉else␊ |
791 | ␉␉{␊ |
792 | ␉␉␉name = malloc(80);␊ |
793 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 79, false);␊ |
794 | ␉␉␉prompt = malloc(256);␊ |
795 | ␉␉␉//Azi: too long for 80X25, GUI=n, vmware, depending on the device name (more than 5 char).␊ |
796 | ␉␉␉sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);␊ |
797 | ␉␉␉free(name);␊ |
798 | ␉␉}␊ |
799 | ␊ |
800 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig ))␊ |
801 | ␉␉{␊ |
802 | ␉␉␉// The key specified is a special key.␊ |
803 | ␉␉}␊ |
804 | ␉␉else␊ |
805 | ␉␉{␊ |
806 | ␉␉␉// Default to F8.␊ |
807 | ␉␉␉optionKey = 0x4200;␊ |
808 | ␉␉}␊ |
809 | ␊ |
810 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
811 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
812 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
813 | ␉␉if (timeout != 0) {␊ |
814 | ␉␉␉key = countdown(prompt, kMenuTopRow, timeout);␊ |
815 | ␉␉} else {␊ |
816 | ␉␉␉key = optionKey;␊ |
817 | ␉␉}␊ |
818 | ␊ |
819 | ␉␉if (prompt != NULL) {␊ |
820 | ␉␉␉free(prompt);␊ |
821 | ␉␉}␊ |
822 | ␊ |
823 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
824 | ␊ |
825 | ␉␉// Hit the option key ?␊ |
826 | ␉␉if (key == optionKey) {␊ |
827 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
828 | ␉␉␉timeout = 0;␊ |
829 | ␉␉} else {␊ |
830 | ␉␉␉key = key & 0xFF;␊ |
831 | ␊ |
832 | ␉␉␉// Try booting hard disk if user pressed 'h'␊ |
833 | ␉␉␉if (biosDevIsCDROM(gBIOSDev) && key == 'h') {␊ |
834 | ␉␉␉␉BVRef bvr;␊ |
835 | ␊ |
836 | ␉␉␉␉// Look at partitions hosting OS X other than the CD-ROM␊ |
837 | ␉␉␉␉for (bvr = bvChain; bvr; bvr=bvr->next) {␊ |
838 | ␉␉␉␉␉if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) {␊ |
839 | ␉␉␉␉␉␉gBootVolume = bvr;␊ |
840 | ␉␉␉␉␉}␊ |
841 | ␉␉␉␉}␊ |
842 | ␉␉␉}␊ |
843 | ␉␉␉goto done;␊ |
844 | ␉␉}␊ |
845 | ␉}␊ |
846 | ␊ |
847 | ␉if (gBootMode & kBootModeQuiet) {␊ |
848 | ␉␉// No input allowed from user.␊ |
849 | ␉␉goto done;␊ |
850 | ␉}␊ |
851 | ␊ |
852 | ␉if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) {␊ |
853 | ␉␉// If the user is holding down a modifier key,␊ |
854 | ␉␉// enter safe mode.␊ |
855 | ␉␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
856 | ␉␉␉gBootMode |= kBootModeSafe;␊ |
857 | ␉␉}␊ |
858 | ␉␉goto done;␊ |
859 | ␉}␊ |
860 | ␊ |
861 | ␉if (gDeviceCount) {␊ |
862 | ␉␉// Allocate memory for an array of menu items.␊ |
863 | ␉␉menuItems = malloc(sizeof(MenuItem) * gDeviceCount);␊ |
864 | ␉␉if (menuItems == NULL) {␊ |
865 | ␉␉␉goto done;␊ |
866 | ␉␉}␊ |
867 | ␊ |
868 | ␉␉// Associate a menu item for each BVRef.␊ |
869 | ␉␉for (bvr=bvChain, i=gDeviceCount-1, selectIndex=0; bvr; bvr=bvr->next) {␊ |
870 | ␉␉␉if (bvr->visible) {␊ |
871 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true);␊ |
872 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
873 | ␉␉␉␉if (bvr == menuBVR) {␊ |
874 | ␉␉␉␉␉selectIndex = i;␊ |
875 | ␉␉␉␉}␊ |
876 | ␉␉␉␉i--;␊ |
877 | ␉␉␉}␊ |
878 | ␉␉}␊ |
879 | ␉}␊ |
880 | ␊ |
881 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
882 | ␉␉// redraw the background buffer␊ |
883 | ␉␉gui.logo.draw = true;␊ |
884 | ␉␉drawBackground();␊ |
885 | ␉␉gui.devicelist.draw = true;␊ |
886 | ␉␉gui.redraw = true;␊ |
887 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
888 | ␊ |
889 | ␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
890 | ␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->bootConfig); ␊ |
891 | ␉␉␉if (showBootBanner) {␊ |
892 | ␉␉␉␉// Display banner and show hardware info.␊ |
893 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
894 | ␉␉␉}␊ |
895 | ␊ |
896 | ␉␉␉// redraw background␊ |
897 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
898 | ␉␉}␊ |
899 | ␉} else {␊ |
900 | ␉␉// Clear screen and hide the blinking cursor.␊ |
901 | ␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
902 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
903 | ␉}␊ |
904 | ␊ |
905 | ␉nextRow = kMenuTopRow;␊ |
906 | ␉showPrompt = true;␊ |
907 | ␊ |
908 | ␉if (gDeviceCount) {␊ |
909 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
910 | ␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
911 | ␉␉}␊ |
912 | ␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
913 | ␉␉nextRow += MIN( gDeviceCount, kMenuMaxItems ) + 3;␊ |
914 | ␉}␊ |
915 | ␊ |
916 | ␉// Show the boot prompt.␊ |
917 | ␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
918 | ␉showBootPrompt( nextRow, showPrompt );␊ |
919 | ␉␊ |
920 | ␉do {␊ |
921 | ␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
922 | ␉␉␉// redraw background␊ |
923 | ␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
924 | ␉␉␉// reset cursor co-ords␊ |
925 | ␉␉␉gui.debug.cursor = pos( gui.screen.width - 160 , 10 );␊ |
926 | ␉␉}␊ |
927 | ␉␉key = getc();␊ |
928 | ␉␉updateMenu( key, (void **) &menuBVR );␊ |
929 | ␉␉newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
930 | ␊ |
931 | ␉␉if (newShowPrompt != showPrompt) {␊ |
932 | ␉␉␉showPrompt = newShowPrompt;␊ |
933 | ␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
934 | ␉␉}␊ |
935 | ␊ |
936 | ␉␉if (showPrompt) {␊ |
937 | ␉␉␉updateBootArgs(key);␊ |
938 | ␉␉}␊ |
939 | ␊ |
940 | ␉␉switch (key) {␊ |
941 | ␉␉case kReturnKey:␊ |
942 | ␉␉␉if (gui.menu.draw) { ␊ |
943 | ␉␉␉␉key=0;␊ |
944 | ␉␉␉␉break;␊ |
945 | ␉␉␉}␊ |
946 | ␉␉␉if (*gBootArgs == '?') {␊ |
947 | ␉␉␉␉char * argPtr = gBootArgs;␊ |
948 | ␊ |
949 | ␉␉␉␉// Skip the leading "?" character.␊ |
950 | ␉␉␉␉argPtr++;␊ |
951 | ␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
952 | ␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
953 | ␊ |
954 | ␉␉␉␉/*␊ |
955 | ␉␉␉␉* TODO: this needs to be refactored.␊ |
956 | ␉␉␉␉*/␊ |
957 | ␉␉␉␉if (strcmp( booterCommand, "video" ) == 0)␊ |
958 | ␉␉␉␉{␊ |
959 | ␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
960 | ␉␉␉␉␉{␊ |
961 | ␉␉␉␉␉␉showInfoBox(getVBEInfoString(), getVBEModeInfoString());␊ |
962 | ␉␉␉␉␉}␊ |
963 | ␉␉␉␉␉else␊ |
964 | ␉␉␉␉␉{␊ |
965 | ␉␉␉␉␉␉printVBEModeInfo();␊ |
966 | ␉␉␉␉␉}␊ |
967 | ␉␉␉␉}␊ |
968 | ␉␉␉␉else if ( strcmp( booterCommand, "memory" ) == 0)␊ |
969 | ␉␉␉␉{␊ |
970 | ␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
971 | ␉␉␉␉␉{␊ |
972 | ␉␉␉␉␉␉showInfoBox("Memory Map", getMemoryInfoString());␊ |
973 | ␉␉␉␉␉}␊ |
974 | ␉␉␉␉␉else␊ |
975 | ␉␉␉␉␉{␊ |
976 | ␉␉␉␉␉␉printMemoryInfo();␊ |
977 | ␉␉␉␉␉}␊ |
978 | ␉␉␉␉}␊ |
979 | ␉␉␉␉else if (strcmp(booterCommand, "lspci") == 0)␊ |
980 | ␉␉␉␉{␊ |
981 | ␉␉␉␉␉lspci();␊ |
982 | ␉␉␉␉}␊ |
983 | ␉␉␉␉else if (strcmp(booterCommand, "more") == 0)␊ |
984 | ␉␉␉␉{␊ |
985 | ␉␉␉␉␉showTextFile(booterParam);␊ |
986 | ␉␉␉␉}␊ |
987 | ␉␉␉␉else if (strcmp(booterCommand, "rd") == 0)␊ |
988 | ␉␉␉␉{␊ |
989 | ␉␉␉␉␉processRAMDiskCommand(&argPtr, booterParam);␊ |
990 | ␉␉␉␉}␊ |
991 | ␉␉␉␉else if (strcmp(booterCommand, "norescan") == 0)␊ |
992 | ␉␉␉␉{␊ |
993 | ␉␉␉␉␉if (gEnableCDROMRescan)␊ |
994 | ␉␉␉␉␉{␊ |
995 | ␉␉␉␉␉␉gEnableCDROMRescan = false;␊ |
996 | ␉␉␉␉␉␉break;␊ |
997 | ␉␉␉␉␉}␊ |
998 | ␉␉␉␉}␊ |
999 | ␉␉␉␉else␊ |
1000 | ␉␉␉␉{␊ |
1001 | ␉␉␉␉␉showHelp();␊ |
1002 | ␉␉␉␉}␊ |
1003 | ␉␉␉␉key = 0;␊ |
1004 | ␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1005 | ␉␉␉␉break;␊ |
1006 | ␉␉␉}␊ |
1007 | ␉␉␉gBootVolume = menuBVR;␊ |
1008 | ␉␉␉setRootVolume(menuBVR);␊ |
1009 | ␉␉␉gBIOSDev = menuBVR->biosdev;␊ |
1010 | ␉␉␉break;␊ |
1011 | ␊ |
1012 | ␉␉case kEscapeKey:␊ |
1013 | ␉␉␉clearBootArgs();␊ |
1014 | ␉␉␉break;␊ |
1015 | ␊ |
1016 | ␉␉// AutoResolution - Reapply the patch if Graphics Mode was incorrect␊ |
1017 | ␉␉// or EDID Info was insane. ␊ |
1018 | ␉␉case kF2Key:␊ |
1019 | ␉␉␉reloadAutoRes();␊ |
1020 | ␉␉␉break;␊ |
1021 | ␉␉␉␊ |
1022 | ␉␉case kF5Key:␊ |
1023 | ␉␉␉// New behavior:␊ |
1024 | ␉␉␉// Clear gBootVolume to restart the loop␊ |
1025 | ␉␉␉// if the user enabled rescanning the optical drive.␊ |
1026 | ␉␉␉// Otherwise boot the default boot volume.␊ |
1027 | ␉␉␉if (gEnableCDROMRescan) {␊ |
1028 | ␉␉␉␉gBootVolume = NULL;␊ |
1029 | ␉␉␉␉clearBootArgs();␊ |
1030 | ␉␉␉}␊ |
1031 | ␉␉␉break;␊ |
1032 | ␊ |
1033 | ␉␉case kF10Key: //Azi: disable "Scan Single Drive"=y (if set) and rescan disks.␊ |
1034 | ␉␉␉gScanSingleDrive = false;␊ |
1035 | ␉␉␉scanDisks(gBIOSDev, &bvCount);␊ |
1036 | ␉␉␉gBootVolume = NULL;␊ |
1037 | ␉␉␉clearBootArgs();␊ |
1038 | ␉␉␉break;␊ |
1039 | ␊ |
1040 | ␉␉case kTabKey:␊ |
1041 | ␉␉␉// New behavior:␊ |
1042 | ␉␉␉// Switch between text & graphic interfaces␊ |
1043 | ␉␉␉// Only Permitted if started in graphics interface␊ |
1044 | ␉␉␉if (useGUI) {␊ |
1045 | ␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
1046 | ␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1047 | ␊ |
1048 | ␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1049 | ␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1050 | ␊ |
1051 | ␉␉␉␉␉// Display banner and show hardware info.␊ |
1052 | ␉␉␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1053 | ␉␉␉␉␉printf(getVBEInfoString());␊ |
1054 | ␊ |
1055 | ␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
1056 | ␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
1057 | ␊ |
1058 | ␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1059 | ␉␉␉␉␉showPrompt = true;␊ |
1060 | ␊ |
1061 | ␉␉␉␉␉if (gDeviceCount) {␊ |
1062 | ␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1063 | ␉␉␉␉␉␉showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
1064 | ␉␉␉␉␉␉nextRow += MIN(gDeviceCount, kMenuMaxItems) + 3;␊ |
1065 | ␉␉␉␉␉}␊ |
1066 | ␊ |
1067 | ␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1068 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1069 | ␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
1070 | ␉␉␉␉} else {␊ |
1071 | ␉␉␉␉␉gui.redraw = true;␊ |
1072 | ␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1073 | ␉␉␉␉␉updateVRAM();␊ |
1074 | ␉␉␉␉}␊ |
1075 | ␉␉␉}␊ |
1076 | ␉␉␉key = 0;␊ |
1077 | ␉␉␉break;␊ |
1078 | ␊ |
1079 | ␉␉default:␊ |
1080 | ␉␉␉key = 0;␊ |
1081 | ␉␉␉break;␊ |
1082 | ␉␉}␊ |
1083 | ␉} while (0 == key);␊ |
1084 | ␊ |
1085 | done:␊ |
1086 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
1087 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
1088 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
1089 | ␉}␊ |
1090 | ␉shouldboot = false;␊ |
1091 | ␉gui.menu.draw = false;␊ |
1092 | ␉if (menuItems) {␊ |
1093 | ␉␉free(menuItems);␊ |
1094 | ␉␉menuItems = NULL;␊ |
1095 | ␉}␊ |
1096 | ␉return 0;␊ |
1097 | }␊ |
1098 | ␊ |
1099 | //==========================================================================␊ |
1100 | ␊ |
1101 | extern unsigned char chainbootdev;␊ |
1102 | extern unsigned char chainbootflag;␊ |
1103 | ␊ |
1104 | bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)␊ |
1105 | {␊ |
1106 | int argLen = argName ? strlen(argName) : 0;␊ |
1107 | int len = argLen + cnt + 1; // +1 to account for space␊ |
1108 | ␊ |
1109 | if (len > *cntRemainingP) {␊ |
1110 | error("Warning: boot arguments too long, truncating\n");␊ |
1111 | return false;␊ |
1112 | }␊ |
1113 | ␊ |
1114 | if (argName) {␊ |
1115 | strncpy( *argP, argName, argLen );␊ |
1116 | *argP += argLen;␊ |
1117 | *argP[0] = '=';␊ |
1118 | (*argP)++;␊ |
1119 | len++; // +1 to account for '='␊ |
1120 | }␊ |
1121 | strncpy( *argP, val, cnt );␊ |
1122 | *argP += cnt;␊ |
1123 | *argP[0] = ' ';␊ |
1124 | (*argP)++;␊ |
1125 | ␊ |
1126 | *cntRemainingP -= len;␊ |
1127 | return true;␊ |
1128 | }␊ |
1129 | ␊ |
1130 | // ␊ |
1131 | // Returns TRUE if an argument was copied, FALSE otherwise␊ |
1132 | bool␊ |
1133 | processBootArgument(␊ |
1134 | const char *argName, // The argument to search for␊ |
1135 | const char *userString, // Typed-in boot arguments␊ |
1136 | const char *kernelFlags, // Kernel flags from config table␊ |
1137 | const char *configTable,␊ |
1138 | char **argP, // Output value␊ |
1139 | int *cntRemainingP, // Output count␊ |
1140 | char *foundVal // found value␊ |
1141 | )␊ |
1142 | {␊ |
1143 | const char *val;␊ |
1144 | int cnt;␊ |
1145 | bool found = false;␊ |
1146 | ␊ |
1147 | if (getValueForBootKey(userString, argName, &val, &cnt)) {␊ |
1148 | // Don't copy; these values will be copied at the end of argument processing.␊ |
1149 | found = true;␊ |
1150 | } else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {␊ |
1151 | // Don't copy; these values will be copied at the end of argument processing.␊ |
1152 | found = true;␊ |
1153 | } else if (getValueForKey(argName, &val, &cnt, &bootInfo->bootConfig)) {␊ |
1154 | copyArgument(argName, val, cnt, argP, cntRemainingP);␊ |
1155 | found = true;␊ |
1156 | }␊ |
1157 | if (found && foundVal) {␊ |
1158 | strlcpy(foundVal, val, cnt+1);␊ |
1159 | }␊ |
1160 | return found;␊ |
1161 | }␊ |
1162 | ␊ |
1163 | // Maximum config table value size␊ |
1164 | #define VALUE_SIZE 2048␊ |
1165 | ␊ |
1166 | int␊ |
1167 | processBootOptions()␊ |
1168 | {␊ |
1169 | const char * cp = gBootArgs;␊ |
1170 | const char * val = 0;␊ |
1171 | const char * kernel;␊ |
1172 | int cnt;␊ |
1173 | int␉␉ userCnt;␊ |
1174 | int cntRemaining;␊ |
1175 | char * argP;␊ |
1176 | char uuidStr[64];␊ |
1177 | bool uuidSet = false;␊ |
1178 | char * configKernelFlags;␊ |
1179 | char * valueBuffer;␊ |
1180 | ␉extern void␉␉ setupSmbiosConfigFile(); // test :P␊ |
1181 | ␊ |
1182 | valueBuffer = malloc(VALUE_SIZE); // 2048␊ |
1183 | ␊ |
1184 | skipblanks( &cp );␊ |
1185 | ␊ |
1186 | // Update the unit and partition number.␊ |
1187 | ␊ |
1188 | if ( gBootVolume )␊ |
1189 | {␊ |
1190 | if (!( gBootVolume->flags & kBVFlagNativeBoot ))␊ |
1191 | {␊ |
1192 | readBootSector( gBootVolume->biosdev, gBootVolume->part_boff,␊ |
1193 | (void *) 0x7c00 );␊ |
1194 | ␊ |
1195 | //␊ |
1196 | // Setup edx, and signal intention to chain load the␊ |
1197 | // foreign booter.␊ |
1198 | //␊ |
1199 | ␊ |
1200 | chainbootdev = gBootVolume->biosdev;␊ |
1201 | chainbootflag = 1;␊ |
1202 | ␊ |
1203 | return 1;␊ |
1204 | }␊ |
1205 | ␊ |
1206 | setRootVolume(gBootVolume);␊ |
1207 | ␊ |
1208 | }␊ |
1209 | // If no boot volume fail immediately because we're just going to fail␊ |
1210 | // trying to load the config file anyway.␊ |
1211 | else␊ |
1212 | return -1;␊ |
1213 | ␉␊ |
1214 | ␉// Moved here to enable search for override Boot.plist on OS specific folders.␊ |
1215 | ␉// Find out which Mac OS version we're booting.␊ |
1216 | ␉// make sure the damn thing get's zeroed, just in case... :)*␊ |
1217 | ␉bzero(gMacOSVersion, sizeof(gMacOSVersion)); // do this to argP ??... check it*****␊ |
1218 | ␉getOSVersion(gMacOSVersion);␊ |
1219 | ␉␊ |
1220 | ␉//Azi: implemented at loadOverrideConfig. ???␊ |
1221 | // Load config table specified by the user, or use the default.␊ |
1222 | //if (!getValueForBootKey(cp, "config", &val, &cnt)) {␊ |
1223 | // val = 0;␊ |
1224 | // cnt = 0;␊ |
1225 | //}␊ |
1226 | //␉loadSystemConfig(val, cnt); Azi:reminder␊ |
1227 | // if ( !sysConfigValid ) return -1;␊ |
1228 | ␊ |
1229 | // Load com.apple.Boot.plist from the selected volume␊ |
1230 | // and use its contents to override default bootConfig.␊ |
1231 | // This is not a mandatory operation anymore.␊ |
1232 | ␊ |
1233 | loadOverrideConfig(&bootInfo->overrideConfig);␊ |
1234 | ␉// testing ugly hack :P␊ |
1235 | ␉setupSmbiosConfigFile("SMBIOS.plist");␊ |
1236 | ␊ |
1237 | // Use the kernel name specified by the user, or fetch the name␊ |
1238 | // in the config table, or use the default if not specified.␊ |
1239 | // Specifying a kernel name on the command line, or specifying␊ |
1240 | // a non-default kernel name in the config file counts as␊ |
1241 | // overriding the kernel, which causes the kernelcache not␊ |
1242 | // to be used.␊ |
1243 | ␊ |
1244 | ␉gOverrideKernel = false;␊ |
1245 | ␉//Azi: setting bootFile - kernel name (path) used in common_boot()␊ |
1246 | ␉if (( kernel = extractKernelName((char **)&cp) )) // boot prompt␊ |
1247 | ␉{␊ |
1248 | ␉␉strcpy( bootInfo->bootFile, kernel );␊ |
1249 | ␉␉gOverrideKernel = true;␊ |
1250 | ␉}␊ |
1251 | ␉else␊ |
1252 | ␉{␊ |
1253 | ␉␉if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) // Boot.plist␊ |
1254 | ␉␉{␊ |
1255 | ␉␉␉strlcpy( bootInfo->bootFile, val, cnt+1 );␊ |
1256 | ␉␉␉if (strcmp( bootInfo->bootFile, kDefaultKernelName ) != 0)␊ |
1257 | ␉␉␉{␊ |
1258 | ␉␉␉␉gOverrideKernel = true;␊ |
1259 | ␉␉␉}␊ |
1260 | ␉␉}␊ |
1261 | ␉␉else␊ |
1262 | ␉␉{␊ |
1263 | ␉␉␉strcpy( bootInfo->bootFile, kDefaultKernelName ); // mach_kernel␊ |
1264 | ␉␉}␊ |
1265 | ␉}␊ |
1266 | ␊ |
1267 | cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space␊ |
1268 | argP = bootArgs->CommandLine;␊ |
1269 | ␊ |
1270 | // Get config table kernel flags, if not ignored.␊ |
1271 | if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || // if -F arg was used...␊ |
1272 | ␉␉␉// don't get the value/s passed by "Kernel Flags" key on "override" Boot.plist.␊ |
1273 | ␉␉␉//Azi: test this*****␊ |
1274 | !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig ))␊ |
1275 | ␉{␊ |
1276 | val = "";␊ |
1277 | cnt = 0;␊ |
1278 | }␊ |
1279 | configKernelFlags = malloc(cnt + 1);␊ |
1280 | strlcpy(configKernelFlags, val, cnt + 1);␊ |
1281 | ␊ |
1282 | ␉// user provided a uuid... at boot prompt or override Boot.plist ??␊ |
1283 | if (processBootArgument(kBootUUIDKey/*boot-uuid*/, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0))␊ |
1284 | ␉{␊ |
1285 | // "boot-uuid" was set either on the command-line or in the config file.␊ |
1286 | uuidSet = true;␊ |
1287 | }␊ |
1288 | ␉else␊ |
1289 | ␉{␊ |
1290 | // Try an alternate method for getting the root UUID on boot helper partitions.␊ |
1291 | if (gBootVolume->flags & kBVFlagBooter)␊ |
1292 | {␊ |
1293 | ␉if ((loadHelperConfig(&bootInfo->helperConfig) == 0) &&␊ |
1294 | ␉␉␉␉getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig) )␊ |
1295 | ␉{␊ |
1296 | ␉␉getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig);␊ |
1297 | ␉copyArgument(kBootUUIDKey/*boot-uuid*/, val, cnt, &argP, &cntRemaining);␊ |
1298 | ␉uuidSet = true;␊ |
1299 | ␉}␊ |
1300 | }␊ |
1301 | ␊ |
1302 | if (!uuidSet && gBootVolume->fs_getuuid && gBootVolume->fs_getuuid(gBootVolume, uuidStr) == 0)␊ |
1303 | ␉␉{␊ |
1304 | verbose("Setting boot-uuid to: %s\n", uuidStr);␊ |
1305 | copyArgument(kBootUUIDKey/*boot-uuid*/, uuidStr, strlen(uuidStr), &argP, &cntRemaining);␊ |
1306 | uuidSet = true;␊ |
1307 | }␊ |
1308 | }␊ |
1309 | ␊ |
1310 | ␉// if no rd=diskXsY key issued by user... at boot prompt or override Boot.plist ??␊ |
1311 | if (!processBootArgument(kRootDeviceKey,␊ |
1312 | ␉␉cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice))␊ |
1313 | ␉{␊ |
1314 | cnt = 0;␊ |
1315 | ␉␉// try "Boot Device" key ???␊ |
1316 | if (getValueForKey(kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig))␊ |
1317 | ␉␉{␊ |
1318 | valueBuffer[0] = '*'; // check for rd=*uuid ???␊ |
1319 | cnt++;␊ |
1320 | strlcpy(valueBuffer + 1, val, cnt);␊ |
1321 | val = valueBuffer;␊ |
1322 | }␊ |
1323 | ␉␉else␊ |
1324 | ␉␉{␊ |
1325 | if (uuidSet)␊ |
1326 | ␉␉␉{␊ |
1327 | val = "*uuid";␊ |
1328 | cnt = 5; // nr of characters on *uuid␊ |
1329 | }␊ |
1330 | ␉␉␉else␊ |
1331 | ␉␉␉{␊ |
1332 | // Don't set "rd=.." if there is no boot device key␊ |
1333 | // and no UUID.␊ |
1334 | val = "";␊ |
1335 | cnt = 0;␊ |
1336 | }␊ |
1337 | }␊ |
1338 | ␊ |
1339 | if (cnt > 0)␊ |
1340 | ␉␉{␊ |
1341 | copyArgument(kRootDeviceKey, val, cnt, &argP, &cntRemaining);␊ |
1342 | }␊ |
1343 | strlcpy(gRootDevice, val, (cnt + 1));␊ |
1344 | }␊ |
1345 | ␊ |
1346 | if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&␊ |
1347 | !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt))␊ |
1348 | ␉{␊ |
1349 | if (gBootMode & kBootModeSafe)␊ |
1350 | ␉␉{␊ |
1351 | copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);␊ |
1352 | }␊ |
1353 | }␊ |
1354 | ␊ |
1355 | // Store the merged kernel flags and boot args.␊ |
1356 | ␉cnt = strlen(configKernelFlags);␊ |
1357 | ␉if (cnt)␊ |
1358 | ␉{␊ |
1359 | ␉␉if (cnt > cntRemaining) {␊ |
1360 | ␉␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1361 | ␉␉␉cnt = cntRemaining;␊ |
1362 | ␉␉}␊ |
1363 | ␉␉strncpy(argP, configKernelFlags, cnt);␊ |
1364 | ␉␉argP[cnt++] = ' ';␊ |
1365 | ␉␉cntRemaining -= cnt;␊ |
1366 | ␉}␊ |
1367 | ␉␊ |
1368 | ␉userCnt = strlen(cp);␊ |
1369 | ␉if (userCnt > cntRemaining)␊ |
1370 | ␉{␊ |
1371 | ␉ error("Warning: boot arguments too long, truncating\n");␊ |
1372 | ␉ userCnt = cntRemaining;␊ |
1373 | ␉}␊ |
1374 | ␉strncpy(&argP[cnt], cp, userCnt);␊ |
1375 | ␉verbose("BootArgs = %s\n", argP); //Azi: checking...␊ |
1376 | ␉argP[cnt+userCnt] = '\0'; // shouldn't this null argP ?? see getOSVersion***␊ |
1377 | ␉verbose("BootArgs check = %s\n", argP); // ||␊ |
1378 | ␉␊ |
1379 | ␉if (!shouldboot)␊ |
1380 | ␉{␊ |
1381 | ␉␉gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->bootConfig ) ||␊ |
1382 | ␉␉␉getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->bootConfig );␊ |
1383 | ␉␉␊ |
1384 | ␉␉gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->bootConfig ) ) ?␊ |
1385 | ␉␉␉kBootModeSafe : kBootModeNormal;␊ |
1386 | ␊ |
1387 | if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1388 | gBootMode = kBootModeSafe; //Azi: ??␊ |
1389 | }␊ |
1390 | ␉}␊ |
1391 | ␊ |
1392 | ␉if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )␊ |
1393 | ␉{␊ |
1394 | ␉␉strlcpy(gMKextName, val, cnt + 1);␊ |
1395 | ␉}␊ |
1396 | ␊ |
1397 | free(configKernelFlags);␊ |
1398 | free(valueBuffer);␊ |
1399 | ␊ |
1400 | return 0;␊ |
1401 | }␊ |
1402 | ␊ |
1403 | static bool getOSVersion(char *str) //Azi: moved from boot.c␊ |
1404 | {␊ |
1405 | ␉bool valid = false;␊ |
1406 | ␉config_file_t systemVersion;␊ |
1407 | ␉const char *val;␊ |
1408 | ␉int len;␊ |
1409 | ␊ |
1410 | ␉if (!loadConfigFile("/System/Library/CoreServices/SystemVersion.plist", &systemVersion))␊ |
1411 | ␉{ //Azi: so, is this path on selected or current volume?? ... clean!␊ |
1412 | ␉␉valid = true;␊ |
1413 | ␉}␊ |
1414 | ␉else if (!loadConfigFile("/System/Library/CoreServices/ServerVersion.plist", &systemVersion))␊ |
1415 | ␉{␊ |
1416 | ␉␉valid = true;␊ |
1417 | ␉}␊ |
1418 | ␊ |
1419 | ␉if (valid)␊ |
1420 | ␉{␊ |
1421 | ␉␉if (getValueForKey("ProductVersion", &val, &len, &systemVersion))␊ |
1422 | ␉␉{␉␊ |
1423 | ␉␉␉// getValueForKey uses const char for val␊ |
1424 | ␉␉␉strncat(str, val, len); //Azi: nothing better to do :P␊ |
1425 | //␉␉␉msglog("System Version: %s\n", str);␊ |
1426 | ␉␉␉verbose("Loading Darwin %s\n", str);␊ |
1427 | ␉␉␉␊ |
1428 | ␉␉␉// so copy it and trim␊ |
1429 | ␉␉␉*str = '\0';␊ |
1430 | ␉␉␉strncat(str, val, MIN(len, 4));␊ |
1431 | ␉␉}␊ |
1432 | ␉␉else␊ |
1433 | ␉␉␉valid = false;␊ |
1434 | ␉}␊ |
1435 | ␊ |
1436 | ␉return valid;␊ |
1437 | }␊ |
1438 | ␊ |
1439 | //==========================================================================␊ |
1440 | // Load the help file and display the file contents on the screen.␊ |
1441 | ␊ |
1442 | static void showTextBuffer(char *buf, int size)␊ |
1443 | {␊ |
1444 | ␉char␉*bp;␊ |
1445 | ␉int␉line;␊ |
1446 | ␉int␉line_offset;␊ |
1447 | ␉int␉c;␊ |
1448 | ␊ |
1449 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
1450 | ␉␉showInfoBox( "Press q to quit\n",buf );␊ |
1451 | ␉␉return;␊ |
1452 | ␉}␊ |
1453 | ␊ |
1454 | bp = buf;␊ |
1455 | while (size-- > 0) {␊ |
1456 | ␉␉if (*bp == '\n') {␊ |
1457 | ␉␉␉*bp = '\0';␊ |
1458 | ␉␉}␊ |
1459 | ␉␉bp++;␊ |
1460 | }␊ |
1461 | *bp = '\1';␊ |
1462 | line_offset = 0;␊ |
1463 | ␊ |
1464 | setActiveDisplayPage(1);␊ |
1465 | ␊ |
1466 | while (1) {␊ |
1467 | ␉␉clearScreenRows(0, 24);␊ |
1468 | ␉␉setCursorPosition(0, 0, 1);␊ |
1469 | ␉␉bp = buf;␊ |
1470 | ␉␉for (line = 0; *bp != '\1' && line < line_offset; line++) {␊ |
1471 | ␉␉␉while (*bp != '\0') {␊ |
1472 | ␉␉␉␉bp++;␊ |
1473 | ␉␉␉}␊ |
1474 | ␉␉␉bp++;␊ |
1475 | ␉␉}␊ |
1476 | ␉␉for (line = 0; *bp != '\1' && line < 23; line++) {␊ |
1477 | ␉␉␉setCursorPosition(0, line, 1);␊ |
1478 | ␉␉␉printf("%s\n", bp);␊ |
1479 | ␉␉␉while (*bp != '\0') {␊ |
1480 | ␉␉␉␉bp++;␊ |
1481 | ␉␉␉}␊ |
1482 | ␉␉␉bp++;␊ |
1483 | ␉␉}␊ |
1484 | ␊ |
1485 | ␉␉setCursorPosition(0, 23, 1);␊ |
1486 | ␉␉if (*bp == '\1') {␊ |
1487 | ␉␉␉printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : "");␊ |
1488 | ␉␉} else {␊ |
1489 | ␉␉␉printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : "");␊ |
1490 | ␉␉}␊ |
1491 | ␊ |
1492 | ␉␉c = getc();␊ |
1493 | ␉␉if (c == 'q' || c == 'Q') {␊ |
1494 | ␉␉␉break;␊ |
1495 | ␉␉}␊ |
1496 | ␉␉if ((c == 'p' || c == 'P') && line_offset > 0) {␊ |
1497 | ␉␉␉line_offset -= 23;␊ |
1498 | ␉␉}␊ |
1499 | ␉␉if (c == ' ') {␊ |
1500 | ␉␉␉if (*bp == '\1') {␊ |
1501 | ␉␉␉␉break;␊ |
1502 | ␉␉␉} else {␊ |
1503 | ␉␉␉␉line_offset += 23;␊ |
1504 | ␉␉␉}␊ |
1505 | ␉␉}␊ |
1506 | }␊ |
1507 | setActiveDisplayPage(0);␊ |
1508 | }␊ |
1509 | ␊ |
1510 | void showHelp(void)␊ |
1511 | {␊ |
1512 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
1513 | ␉␉showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);␊ |
1514 | ␉} else {␊ |
1515 | ␉␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1516 | ␉}␊ |
1517 | }␊ |
1518 | ␊ |
1519 | void showTextFile(const char * filename) //Azi:?more␊ |
1520 | {␊ |
1521 | #define MAX_TEXT_FILE_SIZE 65536␊ |
1522 | ␉char *buf;␊ |
1523 | ␉int␉ fd;␊ |
1524 | ␉int␉ size;␊ |
1525 | ␊ |
1526 | ␉if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0)␊ |
1527 | ␉{␊ |
1528 | ␉␉printf("\nFile not found: %s\n", filename);␊ |
1529 | ␉␉sleep(2);␊ |
1530 | ␉␉return;␊ |
1531 | ␉}␊ |
1532 | ␊ |
1533 | size = file_size(fd);␊ |
1534 | ␊ |
1535 | if (size > MAX_TEXT_FILE_SIZE)␊ |
1536 | {␊ |
1537 | ␉␉size = MAX_TEXT_FILE_SIZE;␊ |
1538 | ␉}␊ |
1539 | ␊ |
1540 | buf = malloc(size);␊ |
1541 | read(fd, buf, size);␊ |
1542 | close(fd);␊ |
1543 | ␊ |
1544 | ␉showTextBuffer(buf, size);␊ |
1545 | ␉free(buf);␊ |
1546 | }␊ |
1547 | ␊ |
1548 | // This is a very simplistic prompting scheme that just grabs two hex characters␊ |
1549 | // Eventually we need to do something more user-friendly like display a menu␊ |
1550 | // based off of the Multiboot device list␊ |
1551 | ␊ |
1552 | //Azi: is this stuff still used for anything?? check multiboot()...␊ |
1553 | int selectAlternateBootDevice(int bootdevice)␊ |
1554 | {␊ |
1555 | ␉int key;␊ |
1556 | ␉int newbootdevice;␊ |
1557 | ␉int digitsI = 0;␊ |
1558 | ␉char *end;␊ |
1559 | ␉char digits[3] = {0,0,0};␊ |
1560 | ␊ |
1561 | ␉// We've already printed the current boot device so user knows what it is␊ |
1562 | ␉printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n");␊ |
1563 | ␉printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice);␊ |
1564 | ␉do {␊ |
1565 | ␉␉key = getc();␊ |
1566 | ␉␉switch (key & kASCIIKeyMask) {␊ |
1567 | ␉␉case kBackspaceKey:␊ |
1568 | ␉␉␉if (digitsI > 0) {␊ |
1569 | ␉␉␉␉int x, y, t;␊ |
1570 | ␉␉␉␉getCursorPositionAndType(&x, &y, &t);␊ |
1571 | ␉␉␉␉// Assume x is not 0;␊ |
1572 | ␉␉␉␉x--;␊ |
1573 | ␉␉␉␉setCursorPosition(x,y,0); // back up one char␊ |
1574 | ␉␉␉␉// Overwrite with space without moving cursor position␊ |
1575 | ␉␉␉␉putca(' ', 0x07, 1);␊ |
1576 | ␉␉␉␉digitsI--;␊ |
1577 | ␉␉␉} else {␊ |
1578 | ␉␉␉␉// TODO: Beep or something␊ |
1579 | ␉␉␉}␊ |
1580 | ␉␉␉break;␊ |
1581 | ␊ |
1582 | ␉␉case kReturnKey:␊ |
1583 | ␉␉␉digits[digitsI] = '\0';␊ |
1584 | ␉␉␉newbootdevice = strtol(digits, &end, 16);␊ |
1585 | ␉␉␉if (end == digits && *end == '\0') {␊ |
1586 | ␉␉␉␉// User entered empty string␊ |
1587 | ␉␉␉␉printf("\nUsing default boot device %x\n", bootdevice);␊ |
1588 | ␉␉␉␉key = 0;␊ |
1589 | ␉␉␉} else if(end != digits && *end == '\0') {␊ |
1590 | ␉␉␉␉bootdevice = newbootdevice;␊ |
1591 | ␉␉␉␉printf("\n");␊ |
1592 | ␉␉␉␉key = 0; // We gots da boot device␊ |
1593 | ␉␉␉} else {␊ |
1594 | ␉␉␉␉printf("\nCouldn't parse. try again: ");␊ |
1595 | ␉␉␉␉digitsI = 0;␊ |
1596 | ␉␉␉}␊ |
1597 | ␉␉␉break;␊ |
1598 | ␊ |
1599 | ␉␉default:␊ |
1600 | ␉␉␉if (isxdigit(key & kASCIIKeyMask) && digitsI < 2) {␊ |
1601 | ␉␉␉␉putc(key & kASCIIKeyMask);␊ |
1602 | ␉␉␉␉digits[digitsI++] = key & kASCIIKeyMask;␊ |
1603 | ␉␉␉} else {␊ |
1604 | ␉␉␉␉// TODO: Beep or something␊ |
1605 | ␉␉␉}␊ |
1606 | ␉␉␉break;␊ |
1607 | ␉␉};␊ |
1608 | ␉} while (key != 0);␊ |
1609 | ␊ |
1610 | ␉return bootdevice;␊ |
1611 | }␊ |
1612 | ␊ |
1613 | bool promptForRescanOption(void)␊ |
1614 | {␊ |
1615 | ␉printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");␊ |
1616 | ␉if (getc() == kReturnKey) {␊ |
1617 | ␉␉return true;␊ |
1618 | ␉} else {␊ |
1619 | ␉␉return false;␊ |
1620 | ␉}␊ |
1621 | }␊ |
1622 | |