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