1 | /*␊ |
2 | * Copyright (c) 1999-2004 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2004 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License"). You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | * ␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | ␊ |
25 | //Azi:include␊ |
26 | //#include "boot.h" - included on graphics.h, which is included on gui.h␊ |
27 | //#include "bootstruct.h" - same as above␊ |
28 | #include "embedded.h"␊ |
29 | #include "fdisk.h"␊ |
30 | #include "gui.h"␊ |
31 | #include "pci.h"␊ |
32 | #include "ramdisk.h"␊ |
33 | #include "sl.h" //Azi:sysversion␊ |
34 | ␊ |
35 | #include "autoresolution.h" //Azi:autoresolution - "was" included on boot.h, which is everywere!! -> gui.h -> graphics.h␊ |
36 | ␊ |
37 | static bool shouldboot = false;␊ |
38 | ␊ |
39 | char gMacOSVersion[8]; //Azi:sysversion␊ |
40 | ␊ |
41 | extern int multiboot_timeout;␊ |
42 | extern int multiboot_timeout_set;␊ |
43 | ␊ |
44 | extern BVRef bvChain;␊ |
45 | //extern int␉␉menucount;␊ |
46 | ␊ |
47 | extern int␉␉gDeviceCount;␊ |
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 ) +␊ |
118 | ␉␉␉␉␉␉␉( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );␊ |
119 | ␉␊ |
120 | ␉␉char dummy[80];␊ |
121 | ␉␉getBootVolumeDescription( gBootVolume, dummy, 80, true );␊ |
122 | ␉␉drawDeviceIcon( gBootVolume, gui.screen.pixmap, p, false );␊ |
123 | ␉␉drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );␊ |
124 | ␉␉␊ |
125 | ␉␉// make this screen the new background␊ |
126 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
127 | ␉␉␊ |
128 | ␉}␊ |
129 | ␊ |
130 | ␉int multi_buff = 18 * (timeout);␊ |
131 | int multi = ++multi_buff;␊ |
132 | ␊ |
133 | int lasttime=0;␊ |
134 | ␊ |
135 | for ( time = time18(), timeout++; timeout > 0; )␊ |
136 | {␊ |
137 | ␉␉if( time18() > lasttime)␊ |
138 | ␉␉{␊ |
139 | ␉␉␉multi--; ␊ |
140 | ␉␉␉lasttime=time18();␊ |
141 | ␉␉}␉␉␊ |
142 | ␊ |
143 | if (ch = readKeyboardStatus())␊ |
144 | break;␊ |
145 | ␊ |
146 | // Count can be interrupted by holding down shift,␊ |
147 | // control or alt key␊ |
148 | if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 )␊ |
149 | ␉␉{␊ |
150 | ch = 1;␊ |
151 | break;␊ |
152 | }␊ |
153 | ␊ |
154 | if ( time18() >= time )␊ |
155 | {␊ |
156 | time += 18;␊ |
157 | timeout--;␊ |
158 | ␊ |
159 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
160 | ␉␉␉{␊ |
161 | ␉␉␉␉moveCursor( col, row );␊ |
162 | ␉␉␉␉printf("(%d) ", timeout);␊ |
163 | ␉␉␉}␊ |
164 | }␊ |
165 | ␉␊ |
166 | ␉␉if( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
167 | ␉␉{␊ |
168 | ␉␉␉drawProgressBar( gui.screen.pixmap, 100, gui.progressbar.pos , ( multi * 100 / multi_buff ) );␊ |
169 | ␉␉␉gui.redraw = true;␊ |
170 | ␉␉␉updateVRAM();␊ |
171 | ␉␉}␊ |
172 | ␊ |
173 | }␊ |
174 | ␊ |
175 | flushKeyboardBuffer();␊ |
176 | ␊ |
177 | return ch;␊ |
178 | }␊ |
179 | ␊ |
180 | //==========================================================================␊ |
181 | ␊ |
182 | static char gBootArgs[BOOT_STRING_LEN];␊ |
183 | static char * gBootArgsPtr = gBootArgs;␊ |
184 | static char * gBootArgsEnd = gBootArgs + BOOT_STRING_LEN - 1;␊ |
185 | static char booterCommand[BOOT_STRING_LEN];␊ |
186 | static char booterParam[BOOT_STRING_LEN];␊ |
187 | ␊ |
188 | static void clearBootArgs(void)␊ |
189 | {␊ |
190 | ␉gBootArgsPtr = gBootArgs;␊ |
191 | ␉memset(gBootArgs, '\0', BOOT_STRING_LEN);␊ |
192 | ␉␊ |
193 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
194 | ␉␉clearGraphicBootPrompt();␊ |
195 | ␉}␊ |
196 | }␊ |
197 | ␊ |
198 | //==========================================================================␊ |
199 | ␊ |
200 | static void showBootPrompt(int row, bool visible)␊ |
201 | {␊ |
202 | ␉extern char bootPrompt[];␊ |
203 | ␉extern char bootRescanPrompt[];␊ |
204 | ␊ |
205 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
206 | ␉␉changeCursor( 0, row, kCursorTypeUnderline, 0 ); ␊ |
207 | ␉␉clearScreenRows( row, kScreenLastRow );␊ |
208 | ␉}␊ |
209 | ␊ |
210 | ␉clearBootArgs();␊ |
211 | ␊ |
212 | ␉if (visible) {␊ |
213 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
214 | ␉␉␉if (gEnableCDROMRescan) {␊ |
215 | ␉␉␉␉printf( bootRescanPrompt );␊ |
216 | ␉␉␉} else {␊ |
217 | ␉␉␉␉printf( bootPrompt );␊ |
218 | ␉␉␉}␊ |
219 | ␉␉}␊ |
220 | ␉} else {␊ |
221 | ␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
222 | ␉␉␉clearGraphicBootPrompt();␊ |
223 | ␉␉} else {␊ |
224 | ␉␉␉printf("Press Enter to start up the foreign OS. ");␊ |
225 | ␉␉}␊ |
226 | ␉}␊ |
227 | }␊ |
228 | ␊ |
229 | //==========================================================================␊ |
230 | ␊ |
231 | static void updateBootArgs( int key )␊ |
232 | {␊ |
233 | key &= kASCIIKeyMask;␊ |
234 | ␊ |
235 | switch ( key )␊ |
236 | {␊ |
237 | case kBackspaceKey:␊ |
238 | if ( gBootArgsPtr > gBootArgs )␊ |
239 | {␊ |
240 | int x, y, t;␊ |
241 | getCursorPositionAndType( &x, &y, &t );␊ |
242 | if ( x == 0 && y )␊ |
243 | {␊ |
244 | x = 80; y--;␊ |
245 | }␊ |
246 | if (x)␊ |
247 | ␉␉␉␉␉x--;␊ |
248 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
249 | ␉␉␉␉{␊ |
250 | ␉␉␉␉␉setCursorPosition( x, y, 0 );␊ |
251 | ␉␉␉␉␉putca(' ', 0x07, 1);␊ |
252 | ␉␉␉␉} else␊ |
253 | ␉␉␉␉␉updateGraphicBootPrompt(kBackspaceKey);␊ |
254 | ␉␉␉␊ |
255 | ␉␉␉␉*gBootArgsPtr-- = '\0';␊ |
256 | ␉␉␉}␊ |
257 | ␊ |
258 | ␉␉␉break;␊ |
259 | ␊ |
260 | default:␊ |
261 | if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
262 | {␊ |
263 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
264 | ␉␉␉␉␉putchar(key); // echo to screen␊ |
265 | ␉␉␉␉else␊ |
266 | ␉␉␉␉␉updateGraphicBootPrompt(key);␊ |
267 | ␉␉␉*gBootArgsPtr++ = key;␊ |
268 | ␉␉␉}␊ |
269 | ␊ |
270 | ␉␉␉break;␊ |
271 | }␊ |
272 | }␊ |
273 | ␊ |
274 | //==========================================================================␊ |
275 | ␊ |
276 | static const MenuItem * gMenuItems = NULL;␊ |
277 | ␊ |
278 | static int gMenuItemCount;␊ |
279 | static int gMenuRow;␊ |
280 | static int gMenuHeight;␊ |
281 | static int gMenuTop;␊ |
282 | static int gMenuBottom;␊ |
283 | static int gMenuSelection;␊ |
284 | ␊ |
285 | static int␉ gMenuStart;␊ |
286 | static int␉ gMenuEnd;␊ |
287 | ␊ |
288 | static void printMenuItem( const MenuItem * item, int highlight )␊ |
289 | {␊ |
290 | printf(" ");␊ |
291 | ␊ |
292 | if ( highlight )␊ |
293 | putca(' ', 0x70, strlen(item->name) + 4);␊ |
294 | else␊ |
295 | putca(' ', 0x07, 40);␊ |
296 | ␊ |
297 | printf(" %40s\n", item->name);␊ |
298 | }␊ |
299 | ␊ |
300 | //==========================================================================␊ |
301 | ␊ |
302 | static 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 | ␉␉␉␉␉␉*gBootArgsPtr++ = '-';␊ |
445 | ␉␉␉␉␉␉*gBootArgsPtr++ = 'v';␊ |
446 | ␉␉␉␉␉␉break;␊ |
447 | ␉␉␉␉␉␉␊ |
448 | ␉␉␉␉␉case BOOT_IGNORECACHE:␊ |
449 | ␉␉␉␉␉␉gVerboseMode = false;␊ |
450 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
451 | ␉␉␉␉␉␉*gBootArgsPtr++ = '-';␊ |
452 | ␉␉␉␉␉␉*gBootArgsPtr++ = 'f';␊ |
453 | ␉␉␉␉␉␉break;␊ |
454 | ␉␉␉␉␉␉␊ |
455 | ␉␉␉␉␉case BOOT_SINGLEUSER:␊ |
456 | ␉␉␉␉␉␉gVerboseMode = true;␊ |
457 | ␉␉␉␉␉␉gBootMode = kBootModeNormal;␊ |
458 | ␉␉␉␉␉␉*gBootArgsPtr++ = '-';␊ |
459 | ␉␉␉␉␉␉*gBootArgsPtr++ = 's';␊ |
460 | ␉␉␉␉␉␉break;␊ |
461 | ␉␉␉␉}␊ |
462 | ␉␉␉␉␊ |
463 | ␉␉␉}␊ |
464 | ␉␉␉␊ |
465 | ␉␉}␉␊ |
466 | ␉␉␉␊ |
467 | ␉} else {␊ |
468 | ␉␉switch ( key )␊ |
469 | ␉␉{␊ |
470 | ␉case 0x4800: // Up Arrow␊ |
471 | ␉␉␉␉if ( gMenuSelection != gMenuTop )␊ |
472 | ␉␉␉␉␉draw.f.selectionUp = 1;␊ |
473 | ␉␉␉␉else if ( gMenuTop > 0 )␊ |
474 | ␉␉␉␉␉draw.f.scrollDown = 1;␊ |
475 | ␉␉␉␉break;␊ |
476 | ␊ |
477 | ␉␉␉case 0x5000: // Down Arrow␊ |
478 | ␉␉␉␉if ( gMenuSelection != gMenuBottom )␊ |
479 | ␉␉␉␉␉draw.f.selectionDown = 1;␊ |
480 | ␉␉␉␉else if ( gMenuBottom < (gMenuItemCount - 1) ) ␊ |
481 | ␉␉␉␉␉draw.f.scrollUp = 1;␊ |
482 | ␉␉␉␉break;␊ |
483 | ␉␉}␊ |
484 | ␉}␊ |
485 | ␊ |
486 | if ( draw.w )␊ |
487 | {␊ |
488 | if ( draw.f.scrollUp )␊ |
489 | {␊ |
490 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, 1);␊ |
491 | gMenuTop++; gMenuBottom++;␊ |
492 | ␉␉␉gMenuStart++; gMenuEnd++;␊ |
493 | draw.f.selectionDown = 1;␊ |
494 | }␊ |
495 | ␊ |
496 | if ( draw.f.scrollDown )␊ |
497 | {␊ |
498 | scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, -1);␊ |
499 | gMenuTop--; gMenuBottom--;␊ |
500 | gMenuStart--; gMenuEnd--;␊ |
501 | draw.f.selectionUp = 1;␊ |
502 | }␊ |
503 | ␊ |
504 | if ( draw.f.selectionUp || draw.f.selectionDown )␊ |
505 | {␊ |
506 | ␊ |
507 | ␉␉␉CursorState cursorState;␊ |
508 | ␊ |
509 | ␉␉␉// Set cursor at current position, and clear inverse video.␊ |
510 | ␉␊ |
511 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
512 | ␉␉␉{␊ |
513 | ␉␉␉␉changeCursor( 0, gMenuRow + gMenuSelection - gMenuTop, kCursorTypeHidden, &cursorState );␊ |
514 | ␉␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 0 );␊ |
515 | ␉␉␉}␊ |
516 | ␊ |
517 | ␉␉␉if ( draw.f.selectionUp )␊ |
518 | ␉␉␉{␊ |
519 | ␉␉␉␉gMenuSelection--;␊ |
520 | ␉␉␉␉if(( gMenuSelection - gMenuStart) == -1 )␊ |
521 | ␉␉␉␉{␊ |
522 | ␉␉␉␉␉gMenuStart--;␊ |
523 | ␉␉␉␉␉gMenuEnd--;␊ |
524 | ␉␉␉␉}␊ |
525 | ␉␉␉␉␊ |
526 | ␉␉␉} else {␊ |
527 | ␉␉␉gMenuSelection++;␊ |
528 | ␉␉␉if(( gMenuSelection - ( gui.maxdevices - 1) - gMenuStart) > 0 )␊ |
529 | ␉␉␉{␊ |
530 | ␉␉␉␉gMenuStart++;␊ |
531 | ␉␉␉␉gMenuEnd++;␊ |
532 | ␉␉␉}␊ |
533 | ␉ }␊ |
534 | ␊ |
535 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
536 | ␉ {␊ |
537 | ␉␉␉moveCursor( 0, gMenuRow + gMenuSelection - gMenuTop );␊ |
538 | ␉␉␉printMenuItem( &gMenuItems[gMenuSelection], 1 );␊ |
539 | ␉␉␉restoreCursor( &cursorState );␊ |
540 | ␊ |
541 | ␉ } else␊ |
542 | ␊ |
543 | ␉␉␉drawDeviceList (gMenuStart, gMenuEnd, gMenuSelection);␊ |
544 | ␊ |
545 | ␉}␊ |
546 | ␊ |
547 | *paramPtr = gMenuItems[gMenuSelection].param; ␊ |
548 | moved = 1;␊ |
549 | }␊ |
550 | ␊ |
551 | ␉return moved;␊ |
552 | }␊ |
553 | ␊ |
554 | //==========================================================================␊ |
555 | ␊ |
556 | static void skipblanks( const char ** cpp ) ␊ |
557 | {␊ |
558 | while ( **(cpp) == ' ' || **(cpp) == '\t' ) ++(*cpp);␊ |
559 | }␊ |
560 | ␊ |
561 | //==========================================================================␊ |
562 | ␊ |
563 | static const char * extractKernelName( char ** cpp )␊ |
564 | {␊ |
565 | char * kn = *cpp;␊ |
566 | char * cp = *cpp;␊ |
567 | char c;␊ |
568 | ␊ |
569 | // Convert char to lower case.␊ |
570 | ␊ |
571 | c = *cp | 0x20;␊ |
572 | ␊ |
573 | // Must start with a letter or a '/'.␊ |
574 | ␊ |
575 | if ( (c < 'a' || c > 'z') && ( c != '/' ) )␊ |
576 | return 0;␊ |
577 | ␊ |
578 | // Keep consuming characters until we hit a separator.␊ |
579 | ␊ |
580 | while ( *cp && (*cp != '=') && (*cp != ' ') && (*cp != '\t') )␊ |
581 | cp++;␊ |
582 | ␊ |
583 | // Only SPACE or TAB separator is accepted.␊ |
584 | // Reject everything else.␊ |
585 | ␊ |
586 | if (*cp == '=')␊ |
587 | return 0;␊ |
588 | ␊ |
589 | // Overwrite the separator, and move the pointer past␊ |
590 | // the kernel name.␊ |
591 | ␊ |
592 | if (*cp != '\0') *cp++ = '\0';␊ |
593 | *cpp = cp;␊ |
594 | ␊ |
595 | return kn;␊ |
596 | }␊ |
597 | ␊ |
598 | //==========================================================================␊ |
599 | ␊ |
600 | static void␊ |
601 | printMemoryInfo(void)␊ |
602 | {␊ |
603 | int line;␊ |
604 | int i;␊ |
605 | MemoryRange *mp = bootInfo->memoryMap;␊ |
606 | ␊ |
607 | // Activate and clear page 1␊ |
608 | setActiveDisplayPage(1);␊ |
609 | clearScreenRows(0, 24);␊ |
610 | setCursorPosition( 0, 0, 1 );␊ |
611 | ␊ |
612 | printf("BIOS reported memory ranges:\n");␊ |
613 | line = 1;␊ |
614 | for (i=0; i<bootInfo->memoryMapCount; i++) {␊ |
615 | printf("Base 0x%08x%08x, ",␊ |
616 | (unsigned long)(mp->base >> 32),␊ |
617 | (unsigned long)(mp->base));␊ |
618 | printf("length 0x%08x%08x, type %d\n",␊ |
619 | (unsigned long)(mp->length >> 32),␊ |
620 | (unsigned long)(mp->length),␊ |
621 | mp->type);␊ |
622 | if (line++ > 20) {␊ |
623 | pause();␊ |
624 | line = 0;␊ |
625 | }␊ |
626 | mp++;␊ |
627 | }␊ |
628 | if (line > 0) {␊ |
629 | pause();␊ |
630 | }␊ |
631 | ␊ |
632 | setActiveDisplayPage(0);␊ |
633 | }␊ |
634 | ␊ |
635 | char *getMemoryInfoString()␊ |
636 | {␊ |
637 | int i;␊ |
638 | MemoryRange *mp = bootInfo->memoryMap;␊ |
639 | ␉char *buff = malloc(sizeof(char)*1024);␊ |
640 | ␉if(!buff) return 0;␊ |
641 | ␉␊ |
642 | ␉char info[] = "BIOS reported memory ranges:\n";␊ |
643 | ␉sprintf(buff, "%s", info);␊ |
644 | for (i=0; i<bootInfo->memoryMapCount; i++) {␊ |
645 | sprintf( buff+strlen(buff), "Base 0x%08x%08x, ",␊ |
646 | (unsigned long)(mp->base >> 32),␊ |
647 | (unsigned long)(mp->base));␊ |
648 | sprintf( buff+strlen(buff), "length 0x%08x%08x, type %d\n",␊ |
649 | (unsigned long)(mp->length >> 32),␊ |
650 | (unsigned long)(mp->length),␊ |
651 | mp->type);␊ |
652 | mp++;␊ |
653 | }␊ |
654 | ␉return buff;␊ |
655 | }␊ |
656 | ␊ |
657 | //==========================================================================␊ |
658 | ␊ |
659 | void lspci(void)␊ |
660 | {␊ |
661 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) { ␊ |
662 | ␉␉setActiveDisplayPage(1);␊ |
663 | ␉␉clearScreenRows(0, 24);␊ |
664 | ␉␉setCursorPosition(0, 0, 1);␊ |
665 | ␉}␊ |
666 | ␊ |
667 | ␉dump_pci_dt(root_pci_dev->children);␊ |
668 | ␊ |
669 | ␉pause();␊ |
670 | ␊ |
671 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
672 | ␉␉setActiveDisplayPage(0);␊ |
673 | ␉}␊ |
674 | }␊ |
675 | ␊ |
676 | //==========================================================================␊ |
677 | ␊ |
678 | int getBootOptions(bool firstRun)␊ |
679 | {␊ |
680 | ␉int i;␊ |
681 | ␉int key;␊ |
682 | ␉int nextRow;␊ |
683 | ␉int timeout;␊ |
684 | ␉int bvCount;␊ |
685 | ␉BVRef bvr;␊ |
686 | ␉BVRef menuBVR;␊ |
687 | ␉bool showPrompt, newShowPrompt, isCDROM;␊ |
688 | ␊ |
689 | ␉// Initialize default menu selection entry.␊ |
690 | ␉gBootVolume = menuBVR = selectBootVolume(bvChain);␊ |
691 | ␊ |
692 | ␉if (biosDevIsCDROM(gBIOSDev)) {␊ |
693 | ␉␉isCDROM = true;␊ |
694 | ␉} else {␊ |
695 | ␉␉isCDROM = false;␊ |
696 | ␉}␊ |
697 | ␊ |
698 | ␉// ensure we're in graphics mode if gui is setup␊ |
699 | ␉if (gui.initialised) {␊ |
700 | ␉␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
701 | ␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
702 | ␉␉}␊ |
703 | ␉}␊ |
704 | ␊ |
705 | ␉// Allow user to override default timeout.␊ |
706 | ␉if (multiboot_timeout_set) {␊ |
707 | ␉␉timeout = multiboot_timeout;␊ |
708 | ␉} else if (!getIntForKey(kTimeoutKey, &timeout, &bootInfo->bootConfig)) {␊ |
709 | ␉␉/* If there is no timeout key in the file use the default timeout␊ |
710 | ␉␉ which is different for CDs vs. hard disks. However, if not booting␊ |
711 | ␉␉ a CD and no config file could be loaded set the timeout␊ |
712 | ␉␉ to zero which causes the menu to display immediately.␊ |
713 | ␉␉ This way, if no partitions can be found, that is the disk is unpartitioned␊ |
714 | ␉␉ or simply cannot be read) then an empty menu is displayed.␊ |
715 | ␉␉ If some partitions are found, for example a Windows partition, then␊ |
716 | ␉␉ these will be displayed in the menu as foreign partitions.␊ |
717 | ␉␉ */␊ |
718 | ␉␉if (isCDROM) {␊ |
719 | ␉␉␉timeout = kCDBootTimeout;␊ |
720 | ␉␉} else {␊ |
721 | ␉␉␉timeout = sysConfigValid ? kBootTimeout : 0;␊ |
722 | ␉␉}␊ |
723 | ␉}␊ |
724 | ␊ |
725 | ␉if (timeout < 0) {␊ |
726 | ␉␉gBootMode |= kBootModeQuiet;␊ |
727 | ␉}␊ |
728 | ␊ |
729 | ␉// If the user is holding down a modifier key, enter safe mode.␊ |
730 | ␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
731 | ␉␉gBootMode |= kBootModeSafe; //Azi: Mek has this commented out.␊ |
732 | ␉}␊ |
733 | ␊ |
734 | ␉// If user typed F8, abort quiet mode, and display the menu.␊ |
735 | ␉{␊ |
736 | ␉␉bool f8press = false, spress = false, vpress = false;␊ |
737 | ␉␉int key;␊ |
738 | ␉␉while (readKeyboardStatus()) {␊ |
739 | ␉␉␉key = bgetc ();␊ |
740 | ␉␉␉if (key == 0x4200) f8press = true;␊ |
741 | ␉␉␉if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true;␊ |
742 | ␉␉␉if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true;␊ |
743 | ␉␉}␊ |
744 | ␉␉if (f8press) {␊ |
745 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
746 | ␉␉␉timeout = 0;␊ |
747 | ␉␉}␊ |
748 | ␉␉if ((gBootMode & kBootModeQuiet) && firstRun && vpress && (gBootArgsPtr + 3 < gBootArgsEnd)) {␊ |
749 | ␉␉␉*(gBootArgsPtr++) = ' ';␊ |
750 | ␉␉␉*(gBootArgsPtr++) = '-';␊ |
751 | ␉␉␉*(gBootArgsPtr++) = 'v';␊ |
752 | ␉␉}␊ |
753 | ␉␉if ((gBootMode & kBootModeQuiet) && firstRun && spress && (gBootArgsPtr + 3 < gBootArgsEnd)) {␊ |
754 | ␉␉␉*(gBootArgsPtr++) = ' ';␊ |
755 | ␉␉␉*(gBootArgsPtr++) = '-';␊ |
756 | ␉␉␉*(gBootArgsPtr++) = 's';␊ |
757 | ␉␉}␉␊ |
758 | ␉}␊ |
759 | ␉clearBootArgs();␊ |
760 | ␊ |
761 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
762 | ␉␉setCursorPosition(0, 0, 0);␊ |
763 | ␉␉clearScreenRows(0, kScreenLastRow);␊ |
764 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
765 | ␉␉␉// Display banner and show hardware info.␊ |
766 | ␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
767 | ␉␉␉printf(getVBEInfoString());␊ |
768 | ␉␉}␊ |
769 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
770 | ␉␉verbose("Scanning device %x...", gBIOSDev);␊ |
771 | ␉}␊ |
772 | ␊ |
773 | ␉// When booting from CD, default to hard drive boot when possible. ␊ |
774 | ␉if (isCDROM && firstRun) {␊ |
775 | ␉␉const char *val;␊ |
776 | ␉␉char *prompt;␊ |
777 | ␉␉char *name;␊ |
778 | ␉␉int cnt;␊ |
779 | ␉␉int optionKey;␊ |
780 | ␊ |
781 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig)) {␊ |
782 | ␉␉␉cnt += 1;␊ |
783 | ␉␉␉prompt = malloc(cnt);␊ |
784 | ␉␉␉strlcpy(prompt, val, cnt);␊ |
785 | ␉␉} else {␊ |
786 | ␉␉␉name = malloc(80);␊ |
787 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 80, false);␊ |
788 | ␉␉␉prompt = malloc(256);␊ |
789 | ␉␉␉sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);␊ |
790 | ␉␉␉free(name);␊ |
791 | ␉␉␉cnt = 0;␊ |
792 | ␉␉}␊ |
793 | ␊ |
794 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig )) {␊ |
795 | ␉␉␉// The key specified is a special key.␊ |
796 | ␉␉} else if (getValueForKey( kCDROMOptionKey, &val, &cnt, &bootInfo->bootConfig ) && cnt >= 1) {␊ |
797 | ␉␉␉optionKey = val[0];␊ |
798 | ␉␉} else {␊ |
799 | ␉␉␉// Default to F8.␊ |
800 | ␉␉␉optionKey = 0x4200;␊ |
801 | ␉␉}␊ |
802 | ␊ |
803 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
804 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
805 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
806 | ␉␉if (timeout != 0) {␊ |
807 | ␉␉␉key = countdown(prompt, kMenuTopRow, timeout);␊ |
808 | ␉␉} else {␊ |
809 | ␉␉␉key = optionKey;␊ |
810 | ␉␉}␊ |
811 | ␊ |
812 | ␉␉if (cnt) {␊ |
813 | ␉␉␉free(prompt);␊ |
814 | ␉␉}␊ |
815 | ␊ |
816 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
817 | ␊ |
818 | ␉␉// Hit the option key ?␊ |
819 | ␉␉if (key == optionKey) {␊ |
820 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
821 | ␉␉␉timeout = 0;␊ |
822 | ␉␉} else {␊ |
823 | ␉␉␉key = key & 0xFF;␊ |
824 | ␊ |
825 | ␉␉␉// Try booting hard disk if user pressed 'h'␊ |
826 | ␉␉␉if (biosDevIsCDROM(gBIOSDev) && key == 'h') {␊ |
827 | ␉␉␉␉BVRef bvr;␊ |
828 | ␊ |
829 | ␉␉␉␉// Look at partitions hosting OS X other than the CD-ROM␊ |
830 | ␉␉␉␉for (bvr = bvChain; bvr; bvr=bvr->next) {␊ |
831 | ␉␉␉␉␉if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) {␊ |
832 | ␉␉␉␉␉␉gBootVolume = bvr;␊ |
833 | ␉␉␉␉␉}␊ |
834 | ␉␉␉␉}␊ |
835 | ␉␉␉}␊ |
836 | ␉␉␉goto done;␊ |
837 | ␉␉}␊ |
838 | ␉}␊ |
839 | ␊ |
840 | ␉if (gBootMode & kBootModeQuiet) {␊ |
841 | ␉␉// No input allowed from user.␊ |
842 | ␉␉goto done;␊ |
843 | ␉}␊ |
844 | ␊ |
845 | ␉if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) {␊ |
846 | ␉␉// If the user is holding down a modifier key,␊ |
847 | ␉␉// enter safe mode.␊ |
848 | ␉␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
849 | ␉␉␉gBootMode |= kBootModeSafe;␊ |
850 | ␉␉}␊ |
851 | ␉␉goto done;␊ |
852 | ␉}␊ |
853 | ␊ |
854 | ␉if (gDeviceCount) {␊ |
855 | ␉␉// Allocate memory for an array of menu items.␊ |
856 | ␉␉menuItems = malloc(sizeof(MenuItem) * gDeviceCount);␊ |
857 | ␉␉if (menuItems == NULL) {␊ |
858 | ␉␉␉goto done;␊ |
859 | ␉␉}␊ |
860 | ␊ |
861 | ␉␉// Associate a menu item for each BVRef.␊ |
862 | ␉␉for (bvr=bvChain, i=gDeviceCount-1, selectIndex=0; bvr; bvr=bvr->next) {␊ |
863 | ␉␉␉if (bvr->visible) {␊ |
864 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, 80, true);␊ |
865 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
866 | ␉␉␉␉if (bvr == menuBVR) {␊ |
867 | ␉␉␉␉␉selectIndex = i;␊ |
868 | ␉␉␉␉}␊ |
869 | ␉␉␉␉i--;␊ |
870 | ␉␉␉}␊ |
871 | ␉␉}␊ |
872 | ␉}␊ |
873 | ␊ |
874 | ␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
875 | ␉␉// redraw the background buffer␊ |
876 | ␉␉drawBackground();␊ |
877 | ␉␉gui.devicelist.draw = true;␊ |
878 | ␉␉gui.redraw = true;␊ |
879 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
880 | ␉␉␉bool showBootBanner = true;␊ |
881 | ␊ |
882 | ␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
883 | ␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->bootConfig); ␊ |
884 | ␉␉␉if (showBootBanner) {␊ |
885 | ␉␉␉␉// Display banner and show hardware info.␊ |
886 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
887 | ␉␉␉}␊ |
888 | ␊ |
889 | ␉␉␉// redraw background␊ |
890 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
891 | ␉␉}␊ |
892 | ␉} else {␊ |
893 | ␉␉// Clear screen and hide the blinking cursor.␊ |
894 | ␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
895 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
896 | ␉}␊ |
897 | ␊ |
898 | ␉nextRow = kMenuTopRow;␊ |
899 | ␉showPrompt = true;␊ |
900 | ␊ |
901 | ␉if (gDeviceCount) {␊ |
902 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
903 | ␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
904 | ␉␉}␊ |
905 | ␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
906 | ␉␉nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;␊ |
907 | ␉}␊ |
908 | ␊ |
909 | ␉// Show the boot prompt.␊ |
910 | ␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
911 | ␉showBootPrompt( nextRow, showPrompt );␊ |
912 | ␉␊ |
913 | ␉do //Azi:style␊ |
914 | ␉{␊ |
915 | ␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE) {␊ |
916 | ␉␉␉// redraw background␊ |
917 | ␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
918 | ␉␉␉// reset cursor co-ords␊ |
919 | ␉␉␉gui.debug.cursor = pos( gui.screen.width - 160 , 10 );␊ |
920 | ␉␉}␊ |
921 | ␉␉key = getc();␊ |
922 | ␉␉updateMenu( key, (void **) &menuBVR );␊ |
923 | ␉␉newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
924 | ␊ |
925 | ␉␉if (newShowPrompt != showPrompt) {␊ |
926 | ␉␉␉showPrompt = newShowPrompt;␊ |
927 | ␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
928 | ␉␉}␊ |
929 | ␊ |
930 | ␉␉if (showPrompt) {␊ |
931 | ␉␉␉updateBootArgs(key);␊ |
932 | ␉␉}␊ |
933 | ␊ |
934 | ␉␉switch (key)␊ |
935 | ␉␉{␊ |
936 | ␉␉␉case kReturnKey:␊ |
937 | ␉␉␉␉if (gui.menu.draw)␊ |
938 | ␉␉␉␉{␊ |
939 | ␉␉␉␉␉key=0;␊ |
940 | ␉␉␉␉␉break;␊ |
941 | ␉␉␉␉}␊ |
942 | ␉␉␉␉if (*gBootArgs == '?')␊ |
943 | ␉␉␉␉{␊ |
944 | ␉␉␉␉␉char * argPtr = gBootArgs;␊ |
945 | ␊ |
946 | ␉␉␉␉␉// Skip the leading "?" character.␊ |
947 | ␉␉␉␉␉argPtr++;␊ |
948 | ␉␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
949 | ␉␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
950 | ␊ |
951 | ␉␉␉␉␉/*␊ |
952 | ␉␉␉␉␉* TODO: this needs to be refactored.␊ |
953 | ␉␉␉␉␉*/␊ |
954 | ␉␉␉␉␉if (strcmp( booterCommand, "video" ) == 0)␊ |
955 | ␉␉␉␉␉{␊ |
956 | ␉␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
957 | ␉␉␉␉␉␉{␊ |
958 | ␉␉␉␉␉␉␉showInfoBox(getVBEInfoString(), getVBEModeInfoString());␊ |
959 | ␉␉␉␉␉␉}␊ |
960 | ␉␉␉␉␉␉else␊ |
961 | ␉␉␉␉␉␉{␊ |
962 | ␉␉␉␉␉␉␉printVBEModeInfo();␊ |
963 | ␉␉␉␉␉␉}␊ |
964 | ␉␉␉␉␉}␊ |
965 | ␉␉␉␉␉else if ( strcmp( booterCommand, "memory" ) == 0)␊ |
966 | ␉␉␉␉␉{␊ |
967 | ␉␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
968 | ␉␉␉␉␉␉{␊ |
969 | ␉␉␉␉␉␉␉showInfoBox("Memory Map", getMemoryInfoString());␊ |
970 | ␉␉␉␉␉␉}␊ |
971 | ␉␉␉␉␉␉else␊ |
972 | ␉␉␉␉␉␉{␊ |
973 | ␉␉␉␉␉␉␉printMemoryInfo();␊ |
974 | ␉␉␉␉␉␉}␊ |
975 | ␉␉␉␉␉}␊ |
976 | ␉␉␉␉␉else if (strcmp(booterCommand, "lspci") == 0)␊ |
977 | ␉␉␉␉␉{␊ |
978 | ␉␉␉␉␉␉lspci();␊ |
979 | ␉␉␉␉␉} //Azi: ?more ??␊ |
980 | ␉␉␉␉␉else if (strcmp(booterCommand, "more") == 0)␊ |
981 | ␉␉␉␉␉{␊ |
982 | ␉␉␉␉␉␉showTextFile(booterParam);␊ |
983 | ␉␉␉␉␉}␊ |
984 | ␉␉␉␉␉else if (strcmp(booterCommand, "rd") == 0)␊ |
985 | ␉␉␉␉␉{␊ |
986 | ␉␉␉␉␉␉processRAMDiskCommand(&argPtr, booterParam);␊ |
987 | ␉␉␉␉␉}␊ |
988 | ␉␉␉␉␉else if (strcmp(booterCommand, "norescan") == 0)␊ |
989 | ␉␉␉␉␉{␊ |
990 | ␉␉␉␉␉␉if (gEnableCDROMRescan)␊ |
991 | ␉␉␉␉␉␉{␊ |
992 | ␉␉␉␉␉␉␉gEnableCDROMRescan = false;␊ |
993 | ␉␉␉␉␉␉␉break;␊ |
994 | ␉␉␉␉␉␉}␊ |
995 | ␉␉␉␉␉}␊ |
996 | ␉␉␉␉␉else␊ |
997 | ␉␉␉␉␉{␊ |
998 | ␉␉␉␉␉␉showHelp();␊ |
999 | ␉␉␉␉␉}␊ |
1000 | ␉␉␉␉␉key = 0;␊ |
1001 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1002 | ␉␉␉␉␉break;␊ |
1003 | ␉␉␉␉}␊ |
1004 | ␉␉␉␉gBootVolume = menuBVR;␊ |
1005 | ␉␉␉␉setRootVolume(menuBVR);␊ |
1006 | ␉␉␉␉gBIOSDev = menuBVR->biosdev;␊ |
1007 | ␉␉␉␉break;␊ |
1008 | ␉␉␉␊ |
1009 | ␉␉␉case kEscapeKey:␊ |
1010 | ␉␉␉␉clearBootArgs();␊ |
1011 | ␉␉␉␉break;␊ |
1012 | ␉␉␉␊ |
1013 | ␉␉␉case kF2Key:␊ |
1014 | ␉␉␉␉␉␉␉␊ |
1015 | ␉␉␉␉/*␊ |
1016 | ␉␉␉␉ * AutoResolution - Reapply the patch if Graphics Mode was incorrect␊ |
1017 | ␉␉␉␉ * or EDID Info was insane␊ |
1018 | ␉␉␉␉ */␊ |
1019 | ␉␉␉␉␊ |
1020 | ␉␉␉␉//get the new Graphics Mode key␊ |
1021 | ␉␉␉␉processBootOptions();␊ |
1022 | ␉␉␉␉if ((gAutoResolution == TRUE) && map)␊ |
1023 | ␉␉␉␉{␊ |
1024 | ␉␉␉␉␉UInt32 params[4];␊ |
1025 | ␉␉␉␉␉params[3] = 0;␊ |
1026 | ␉␉␉␉␉//Has the target Resolution Changed ?␊ |
1027 | ␉␉␉␉␉int count = getNumberArrayFromProperty(kGraphicsModeKey, params, 4);␊ |
1028 | ␉␉␉␉␉if ( count < 3 )␊ |
1029 | ␉␉␉␉␉␉getResolution(params);␊ |
1030 | ␊ |
1031 | ␉␉␉␉␉if (␉(params[0] != 0) && (params[1] != 0)␊ |
1032 | ␉␉␉␉␉␉&&␉(params[0] != map->currentX) && (params[1] != map->currentY))␊ |
1033 | ␉␉␉␉␉{␊ |
1034 | ␊ |
1035 | ␉␉␉␉␉␉//Go back to TEXT mode while we change the mode␊ |
1036 | ␉␉␉␉␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
1037 | ␉␉␉␉␉␉{␊ |
1038 | ␉␉␉␉␉␉␉CursorState cursorState;␊ |
1039 | ␊ |
1040 | ␉␉␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1041 | ␊ |
1042 | ␉␉␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1043 | ␉␉␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1044 | ␉␉␉␉␉␉␉changeCursor( 0, 0, kCursorTypeHidden, &cursorState );␊ |
1045 | ␊ |
1046 | ␉␉␉␉␉␉␉//Reapply patch in case resolution have changed␊ |
1047 | ␊ |
1048 | ␉␉␉␉␉␉␉patchVbios(map, params[0], params[1], params[2], 0, 0);␊ |
1049 | ␊ |
1050 | ␉␉␉␉␉␉␉if (useGUI && (gui.initialised == true))␊ |
1051 | ␉␉␉␉␉␉␉␉initGUI();␊ |
1052 | ␉␉␉␉␉␉␉// Make sure all values are set␊ |
1053 | ␉␉␉␉␉␉␉if (bootArgs->Video.v_display != GRAPHICS_MODE)␊ |
1054 | ␉␉␉␉␉␉␉␉bootArgs->Video.v_display = GRAPHICS_MODE;␊ |
1055 | ␊ |
1056 | ␉␉␉␉␉␉␉if (!useGUI)␊ |
1057 | ␉␉␉␉␉␉␉␉useGUI = true;␊ |
1058 | ␊ |
1059 | ␉␉␉␉␉␉␉// redraw the background buffer␊ |
1060 | ␉␉␉␉␉␉␉drawBackground();␊ |
1061 | ␉␉␉␉␉␉␉gui.devicelist.draw = true;␊ |
1062 | ␉␉␉␉␉␉␉gui.redraw = true;␊ |
1063 | ␉␉␉␉␉␉␉if (!(gBootMode & kBootModeQuiet))␊ |
1064 | ␉␉␉␉␉␉␉{␊ |
1065 | ␉␉␉␉␉␉␉␉bool showBootBanner = true;␊ |
1066 | ␊ |
1067 | ␉␉␉␉␉␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
1068 | ␉␉␉␉␉␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->bootConfig); ␊ |
1069 | ␉␉␉␉␉␉␉␉if (showBootBanner)␊ |
1070 | ␉␉␉␉␉␉␉␉␉// Display banner and show hardware info.␊ |
1071 | ␉␉␉␉␉␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1072 | ␊ |
1073 | ␉␉␉␉␉␉␉␉// redraw background␊ |
1074 | ␉␉␉␉␉␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
1075 | ␉␉␉␉␉␉␉}␊ |
1076 | ␊ |
1077 | ␉␉␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1078 | ␉␉␉␉␉␉␉showPrompt = true;␊ |
1079 | ␊ |
1080 | ␉␉␉␉␉␉␉if (gDeviceCount)␊ |
1081 | ␉␉␉␉␉␉␉{␊ |
1082 | ␉␉␉␉␉␉␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
1083 | ␉␉␉␉␉␉␉␉nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;␊ |
1084 | ␉␉␉␉␉␉␉}␊ |
1085 | ␊ |
1086 | ␉␉␉␉␉␉␉// Show the boot prompt.␊ |
1087 | ␉␉␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1088 | ␉␉␉␉␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
1089 | ␊ |
1090 | ␉␉␉␉␉␉␉//this is used to avoid resetting the incorrect mode while quiting the boot menu␊ |
1091 | ␉␉␉␉␉␉␉map->hasSwitched = true;␊ |
1092 | ␉␉␉␉␉␉}␊ |
1093 | ␉␉␉␉␉}␊ |
1094 | ␉␉␉␉␉clearBootArgs();␊ |
1095 | ␉␉␉␉␉key = 0;␊ |
1096 | ␉␉␉␉}␊ |
1097 | ␉␉␉␉break;␊ |
1098 | ␉␉␉␊ |
1099 | ␉␉␉case kF5Key:␊ |
1100 | ␉␉␉␉// New behavior:␊ |
1101 | ␉␉␉␉// Clear gBootVolume to restart the loop␊ |
1102 | ␉␉␉␉// if the user enabled rescanning the optical drive.␊ |
1103 | ␉␉␉␉// Otherwise boot the default boot volume.␊ |
1104 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
1105 | ␉␉␉␉{␊ |
1106 | ␉␉␉␉␉gBootVolume = NULL;␊ |
1107 | ␉␉␉␉␉clearBootArgs();␊ |
1108 | ␉␉␉␉}␊ |
1109 | ␉␉␉␉break;␊ |
1110 | ␉␉␉␊ |
1111 | ␉␉␉case kF10Key:␊ |
1112 | ␉␉␉␉gScanSingleDrive = false;␊ |
1113 | ␉␉␉␉scanDisks(gBIOSDev, &bvCount);␊ |
1114 | ␉␉␉␉gBootVolume = NULL;␊ |
1115 | ␉␉␉␉clearBootArgs();␊ |
1116 | ␉␉␉␉break;␊ |
1117 | ␉␉␉␊ |
1118 | ␉␉␉case kTabKey:␊ |
1119 | ␉␉␉␉// New behavior:␊ |
1120 | ␉␉␉␉// Switch between text & graphic interfaces␊ |
1121 | ␉␉␉␉// Only Permitted if started in graphics interface␊ |
1122 | ␉␉␉␉if (useGUI)␊ |
1123 | ␉␉␉␉{␊ |
1124 | ␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1125 | ␊ |
1126 | ␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1127 | ␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1128 | ␊ |
1129 | ␉␉␉␉␉// Display banner and show hardware info.␊ |
1130 | ␉␉␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1131 | ␉␉␉␉␉printf(getVBEInfoString());␊ |
1132 | ␊ |
1133 | ␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
1134 | ␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
1135 | ␊ |
1136 | ␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1137 | ␉␉␉␉␉showPrompt = true;␊ |
1138 | ␊ |
1139 | ␉␉␉␉␉if (gDeviceCount)␊ |
1140 | ␉␉␉␉␉{␊ |
1141 | ␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1142 | ␉␉␉␉␉␉showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
1143 | ␉␉␉␉␉␉nextRow += min(gDeviceCount, kMenuMaxItems) + 3;␊ |
1144 | ␉␉␉␉␉}␊ |
1145 | ␊ |
1146 | ␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1147 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1148 | ␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
1149 | ␊ |
1150 | ␉␉␉␉␉/*␊ |
1151 | ␉␉␉␉␉ * AutoResolution - make sure all values are set␊ |
1152 | ␉␉␉␉␉ */␊ |
1153 | ␊ |
1154 | ␉␉␉␉␉bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
1155 | ␉␉␉␉␉useGUI = false;␊ |
1156 | ␉␉␉␉}␊ |
1157 | ␉␉␉␉else␊ |
1158 | ␉␉␉␉{␊ |
1159 | ␉␉␉␉␉gui.redraw = true;␊ |
1160 | ␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1161 | ␊ |
1162 | ␉␉␉␉␉/*␊ |
1163 | ␉␉␉␉␉ * AutoResolution - make sure all values are set␊ |
1164 | ␉␉␉␉␉ */␊ |
1165 | ␉␉␉␉␉bootArgs->Video.v_display = GRAPHICS_MODE;␊ |
1166 | ␉␉␉␉␉useGUI = true;␊ |
1167 | ␊ |
1168 | ␉␉␉␉␉updateVRAM();␊ |
1169 | ␉␉␉␉}␊ |
1170 | ␉␉␉␉key = 0;␊ |
1171 | ␉␉␉␉break;␊ |
1172 | ␊ |
1173 | ␉␉␉default:␊ |
1174 | ␉␉␉␉key = 0;␊ |
1175 | ␉␉␉␉break;␊ |
1176 | ␉␉}␊ |
1177 | ␉} while (0 == key);␊ |
1178 | ␊ |
1179 | done:␊ |
1180 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
1181 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
1182 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
1183 | ␉}␊ |
1184 | ␉shouldboot = false;␊ |
1185 | ␉gui.menu.draw = false;␊ |
1186 | ␉if (menuItems) {␊ |
1187 | ␉␉free(menuItems);␊ |
1188 | ␉␉menuItems = NULL;␊ |
1189 | ␉}␊ |
1190 | ␉return 0;␊ |
1191 | }␊ |
1192 | ␊ |
1193 | //==========================================================================␊ |
1194 | ␊ |
1195 | extern unsigned char chainbootdev;␊ |
1196 | extern unsigned char chainbootflag;␊ |
1197 | ␊ |
1198 | bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)␊ |
1199 | {␊ |
1200 | int argLen = argName ? strlen(argName) : 0;␊ |
1201 | int len = argLen + cnt + 1; // +1 to account for space␊ |
1202 | ␊ |
1203 | if (len > *cntRemainingP) {␊ |
1204 | error("Warning: boot arguments too long, truncating\n");␊ |
1205 | return false;␊ |
1206 | }␊ |
1207 | ␊ |
1208 | if (argName) {␊ |
1209 | strncpy( *argP, argName, argLen );␊ |
1210 | *argP += argLen;␊ |
1211 | *argP[0] = '=';␊ |
1212 | (*argP)++;␊ |
1213 | len++; // +1 to account for '='␊ |
1214 | }␊ |
1215 | strncpy( *argP, val, cnt );␊ |
1216 | *argP += cnt;␊ |
1217 | *argP[0] = ' ';␊ |
1218 | (*argP)++;␊ |
1219 | ␊ |
1220 | *cntRemainingP -= len;␊ |
1221 | return true;␊ |
1222 | }␊ |
1223 | ␊ |
1224 | // ␊ |
1225 | // Returns TRUE if an argument was copied, FALSE otherwise␊ |
1226 | bool␊ |
1227 | processBootArgument(␊ |
1228 | const char *argName, // The argument to search for␊ |
1229 | const char *userString, // Typed-in boot arguments␊ |
1230 | const char *kernelFlags, // Kernel flags from config table␊ |
1231 | const char *configTable,␊ |
1232 | char **argP, // Output value␊ |
1233 | int *cntRemainingP, // Output count␊ |
1234 | char *foundVal // found value␊ |
1235 | )␊ |
1236 | {␊ |
1237 | const char *val;␊ |
1238 | int cnt;␊ |
1239 | bool found = false;␊ |
1240 | ␊ |
1241 | if (getValueForBootKey(userString, argName, &val, &cnt)) {␊ |
1242 | // Don't copy; these values will be copied at the end of argument processing.␊ |
1243 | found = true;␊ |
1244 | } else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {␊ |
1245 | // Don't copy; these values will be copied at the end of argument processing.␊ |
1246 | found = true;␊ |
1247 | } else if (getValueForKey(argName, &val, &cnt, &bootInfo->bootConfig)) {␊ |
1248 | copyArgument(argName, val, cnt, argP, cntRemainingP);␊ |
1249 | found = true;␊ |
1250 | }␊ |
1251 | if (found && foundVal) {␊ |
1252 | strlcpy(foundVal, val, cnt+1);␊ |
1253 | }␊ |
1254 | return found;␊ |
1255 | }␊ |
1256 | ␊ |
1257 | // Maximum config table value size␊ |
1258 | #define VALUE_SIZE 2048␊ |
1259 | ␊ |
1260 | int␊ |
1261 | processBootOptions()␊ |
1262 | {␊ |
1263 | const char * cp = gBootArgs;␊ |
1264 | const char * val = 0;␊ |
1265 | const char * kernel;␊ |
1266 | ␉const char␉␉*value; //Azi:sysversion␊ |
1267 | ␉int␉␉␉␉ len; //Azi:sysversion␊ |
1268 | int cnt;␊ |
1269 | ␉int␉␉ userCnt;␊ |
1270 | int cntRemaining;␊ |
1271 | char * argP;␊ |
1272 | char uuidStr[64];␊ |
1273 | bool uuidSet = false;␊ |
1274 | char * configKernelFlags;␊ |
1275 | char * valueBuffer;␊ |
1276 | ␉config_file_t␉ systemVersion;␉␉//Azi:sysversion - system.plist of booting partition␊ |
1277 | ␊ |
1278 | valueBuffer = malloc(VALUE_SIZE);␊ |
1279 | ␊ |
1280 | skipblanks( &cp );␊ |
1281 | ␊ |
1282 | // Update the unit and partition number.␊ |
1283 | ␊ |
1284 | if ( gBootVolume )␊ |
1285 | {␊ |
1286 | if (!( gBootVolume->flags & kBVFlagNativeBoot ))␊ |
1287 | {␊ |
1288 | readBootSector( gBootVolume->biosdev, gBootVolume->part_boff,␊ |
1289 | (void *) 0x7c00 );␊ |
1290 | ␊ |
1291 | //␊ |
1292 | // Setup edx, and signal intention to chain load the␊ |
1293 | // foreign booter.␊ |
1294 | //␊ |
1295 | ␊ |
1296 | chainbootdev = gBootVolume->biosdev;␊ |
1297 | chainbootflag = 1;␊ |
1298 | ␊ |
1299 | return 1;␊ |
1300 | }␊ |
1301 | setRootVolume( gBootVolume );␊ |
1302 | }␊ |
1303 | // If no boot volume fail immediately because we're just going to fail␊ |
1304 | // trying to load the config file anyway.␊ |
1305 | else␊ |
1306 | return -1;␊ |
1307 | ␊ |
1308 | ␉// Find out which version mac os we're booting. Azi:sysversion - Ok, if i move this here,␊ |
1309 | ␉// which seems ideal to me, it gets hidden from verbose and this info been pretty helpful to me;␊ |
1310 | ␉// plus, for some reason gMacOSVersion doesn't get initialized on boot.c?! i have to call this anyway␊ |
1311 | ␉// with another variable name so, back to were i was. Need advice! Check below on loadOverrideConfig.␊ |
1312 | ␉if (!loadConfigFile("/System/Library/CoreServices/SystemVersion.plist", &systemVersion))␊ |
1313 | ␉{ //Azi: shouldn't this path start with / ?␊ |
1314 | ␉␉if (getValueForKey(kProductVersion, &value, &len, &systemVersion))␊ |
1315 | ␉␉{␊ |
1316 | ␉␉␉// getValueForKey uses const char for val␊ |
1317 | ␉␉␉// so copy it and trim␊ |
1318 | ␉␉␉strncpy(gMacOSVersion, value, MIN(len, 4));␊ |
1319 | ␉␉␉gMacOSVersion[MIN(len, 4)] = '\0';␊ |
1320 | ␉␉}␊ |
1321 | ␉} // doesn't print to screen here!␊ |
1322 | ␉␊ |
1323 | ␉//Azi: check loadOverrideConfig().␊ |
1324 | ␉// Load config table specified by the user, or use the default.␊ |
1325 | /* if (!getValueForBootKey(cp, "config", &val, &cnt)) {␊ |
1326 | ␉␉val = 0;␊ |
1327 | ␉␉cnt = 0;␊ |
1328 | }*/␊ |
1329 | ␊ |
1330 | // Load com.apple.Boot.plist from the selected volume␊ |
1331 | // and use its contents to override default bootConfig.␊ |
1332 | // This is not a mandatory operation anymore. Azi: meaning, it desn't return -1 anymore.␊ |
1333 | ␊ |
1334 | ␉// About overriding from OS specific folders: gMacOSVersion is not stored at this point;␊ |
1335 | ␉// placed a "call 2" under common_boot, right after getting system version.␊ |
1336 | ␉loadOverrideConfig(&bootInfo->overrideConfig); // call 1 - first to print to screen␊ |
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( kOldSafeModeFlag, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1464 | ␉gBootMode = kBootModeSafe;␊ |
1465 | ␉}␊ |
1466 | ␊ |
1467 | ␉if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1468 | ␉strlcpy(gMKextName, val, cnt + 1);␊ |
1469 | ␉}␊ |
1470 | ␊ |
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 | |