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