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 "term.h"␊ |
31 | #include "embedded.h"␊ |
32 | #include "pci.h"␊ |
33 | #include "modules.h"␊ |
34 | ␊ |
35 | bool showBootBanner = true; //Azi:showinfo␊ |
36 | static bool shouldboot = false;␊ |
37 | ␊ |
38 | extern int multiboot_timeout;␊ |
39 | extern int multiboot_timeout_set;␊ |
40 | ␊ |
41 | extern BVRef bvChain;␊ |
42 | //extern int␉␉menucount;␊ |
43 | ␊ |
44 | extern int␉␉gDeviceCount;␊ |
45 | ␊ |
46 | int␉␉␉selectIndex = 0;␊ |
47 | MenuItem * menuItems = NULL;␊ |
48 | ␊ |
49 | enum {␊ |
50 | kMenuTopRow = 5,␊ |
51 | kMenuMaxItems = 10,␊ |
52 | kScreenLastRow = 24␊ |
53 | };␊ |
54 | ␊ |
55 | //==========================================================================␊ |
56 | ␊ |
57 | typedef struct {␊ |
58 | int x;␊ |
59 | int y;␊ |
60 | int type;␊ |
61 | } CursorState;␊ |
62 | ␊ |
63 | static void changeCursor( int col, int row, int type, CursorState * cs )␊ |
64 | {␊ |
65 | if (cs) getCursorPositionAndType( &cs->x, &cs->y, &cs->type );␊ |
66 | setCursorType( type );␊ |
67 | setCursorPosition( col, row, 0 );␊ |
68 | }␊ |
69 | ␊ |
70 | static void moveCursor( int col, int row )␊ |
71 | {␊ |
72 | setCursorPosition( col, row, 0 );␊ |
73 | }␊ |
74 | ␊ |
75 | static void restoreCursor( const CursorState * cs )␊ |
76 | {␊ |
77 | setCursorPosition( cs->x, cs->y, 0 );␊ |
78 | setCursorType( cs->type );␊ |
79 | }␊ |
80 | ␊ |
81 | //==========================================================================␊ |
82 | ␊ |
83 | /* Flush keyboard buffer; returns TRUE if any of the flushed␊ |
84 | * characters was F8.␊ |
85 | */␊ |
86 | ␊ |
87 | static bool flushKeyboardBuffer(void)␊ |
88 | {␊ |
89 | bool status = false;␊ |
90 | ␊ |
91 | while ( readKeyboardStatus() ) {␊ |
92 | if (bgetc() == 0x4200) status = true;␊ |
93 | }␊ |
94 | return status;␊ |
95 | }␊ |
96 | ␊ |
97 | //==========================================================================␊ |
98 | ␊ |
99 | static int countdown( const char * msg, int row, int timeout )␊ |
100 | {␊ |
101 | unsigned long time;␊ |
102 | int ch = 0;␊ |
103 | int col = strlen(msg) + 1;␊ |
104 | ␉␊ |
105 | flushKeyboardBuffer();␊ |
106 | ␊ |
107 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
108 | ␉{␊ |
109 | ␉␉moveCursor( 0, row );␊ |
110 | ␉␉printf(msg);␊ |
111 | ␊ |
112 | ␉} else {␊ |
113 | ␊ |
114 | ␉␉position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );␊ |
115 | ␉␊ |
116 | ␉␉char dummy[80];␊ |
117 | ␉␉getBootVolumeDescription( gBootVolume, dummy, sizeof(dummy) - 1, true );␊ |
118 | ␉␉drawDeviceIcon( gBootVolume, gui.screen.pixmap, p, true );␊ |
119 | ␉␉drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );␊ |
120 | ␉␉␊ |
121 | ␉␉// make this screen the new background␊ |
122 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
123 | ␉␉␊ |
124 | ␉}␊ |
125 | ␊ |
126 | ␉int multi_buff = 18 * (timeout);␊ |
127 | int multi = ++multi_buff;␊ |
128 | ␊ |
129 | int lasttime=0;␊ |
130 | ␊ |
131 | for ( time = time18(), timeout++; timeout > 0; )␊ |
132 | {␊ |
133 | ␉␉if( time18() > lasttime)␊ |
134 | ␉␉{␊ |
135 | ␉␉␉multi--; ␊ |
136 | ␉␉␉lasttime=time18();␊ |
137 | ␉␉}␉␉␊ |
138 | ␊ |
139 | if ( (ch = readKeyboardStatus()) )␊ |
140 | break;␊ |
141 | ␊ |
142 | // Count can be interrupted by holding down shift,␊ |
143 | // control or alt key␊ |
144 | if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 )␊ |
145 | ␉␉{␊ |
146 | ch = 1;␊ |
147 | break;␊ |
148 | }␊ |
149 | ␊ |
150 | if ( time18() >= time )␊ |
151 | {␊ |
152 | time += 18;␊ |
153 | timeout--;␊ |
154 | ␊ |
155 | ␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
156 | ␉␉␉{␊ |
157 | ␉␉␉␉moveCursor( col, row );␊ |
158 | ␉␉␉␉printf("(%d) ", timeout);␊ |
159 | ␉␉␉}␊ |
160 | }␊ |
161 | ␉␊ |
162 | ␉␉if( bootArgs->Video.v_display != VGA_TEXT_MODE )␊ |
163 | ␉␉{␊ |
164 | ␉␉␉drawProgressBar( gui.screen.pixmap, 100, gui.progressbar.pos , ( multi * 100 / multi_buff ) );␊ |
165 | ␉␉␉gui.redraw = true;␊ |
166 | ␉␉␉updateVRAM();␊ |
167 | ␉␉}␊ |
168 | ␊ |
169 | }␊ |
170 | ␊ |
171 | flushKeyboardBuffer();␊ |
172 | ␊ |
173 | return ch;␊ |
174 | }␊ |
175 | ␊ |
176 | //==========================================================================␊ |
177 | ␊ |
178 | 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 != VGA_TEXT_MODE) {␊ |
190 | ␉␉clearGraphicBootPrompt();␊ |
191 | ␉}␊ |
192 | ␉execute_hook("ClearArgs", NULL, NULL, NULL, NULL);␊ |
193 | }␊ |
194 | ␊ |
195 | void addBootArg(const char * argStr)␊ |
196 | {␊ |
197 | ␉if ( (gBootArgsPtr + strlen(argStr) + 1) < gBootArgsEnd)␊ |
198 | ␉{␊ |
199 | ␉␉if(gBootArgsPtr != gBootArgs) *gBootArgsPtr++ = ' ';␊ |
200 | ␉␉strcat(gBootArgs, argStr);␊ |
201 | ␉␉gBootArgsPtr += strlen(argStr);␊ |
202 | ␉}␊ |
203 | }␊ |
204 | ␊ |
205 | //==========================================================================␊ |
206 | ␊ |
207 | static void showBootPrompt(int row, bool visible)␊ |
208 | {␊ |
209 | ␉extern char bootPrompt[];␊ |
210 | ␉extern char bootRescanPrompt[];␊ |
211 | ␊ |
212 | ␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
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 != VGA_TEXT_MODE) {␊ |
230 | ␉␉␉clearGraphicBootPrompt();␊ |
231 | ␉␉} else {␊ |
232 | ␉␉␉printf("Press Enter to start up the foreign OS. ");␊ |
233 | ␉␉}␊ |
234 | ␉}␊ |
235 | }␊ |
236 | ␊ |
237 | //==========================================================================␊ |
238 | ␊ |
239 | static void updateBootArgs( int key )␊ |
240 | {␊ |
241 | key = ASCII_KEY(key);␊ |
242 | ␊ |
243 | switch ( key )␊ |
244 | {␊ |
245 | case KEY_BKSP:␊ |
246 | if ( gBootArgsPtr > gBootArgs )␊ |
247 | {␊ |
248 | *--gBootArgsPtr = '\0';␊ |
249 | ␊ |
250 | int x, y, t;␊ |
251 | getCursorPositionAndType( &x, &y, &t );␊ |
252 | if ( x == 0 && y )␊ |
253 | {␊ |
254 | x = 80; y--;␊ |
255 | }␊ |
256 | if (x) {␊ |
257 | ␉␉␉x--;␊ |
258 | ␉␉}␊ |
259 | ␊ |
260 | ␉␉␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE )␊ |
261 | ␉␉␉␉{␊ |
262 | ␉␉␉␉␉setCursorPosition( x, y, 0 );␊ |
263 | ␉␉␉␉␉putca(' ', 0x07, 1);␊ |
264 | ␉␉␉␉}␊ |
265 | else␊ |
266 | {␊ |
267 | updateGraphicBootPrompt();␊ |
268 | }␊ |
269 | }␊ |
270 | ␉␉␉break;␊ |
271 | ␊ |
272 | default:␊ |
273 | if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)␊ |
274 | {␊ |
275 | *gBootArgsPtr++ = key;␊ |
276 | ␊ |
277 | if( bootArgs->Video.v_display != VGA_TEXT_MODE ) updateGraphicBootPrompt();␊ |
278 | else if ( key >= ' ' && key < 0x7f) putchar(key);␊ |
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 != VGA_TEXT_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 != VGA_TEXT_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, bufflen;␊ |
646 | ␉MemoryRange *mp = bootInfo->memoryMap;␊ |
647 | ␉char *buff = malloc(sizeof(char)*1024);␊ |
648 | ␉if(!buff) {␊ |
649 | ␉␉return 0;␊ |
650 | ␉}␊ |
651 | ␊ |
652 | ␉static const char info[] = "BIOS reported memory ranges:\n";␊ |
653 | ␉bufflen = sprintf(buff, "%s", info);␊ |
654 | ␊ |
655 | ␉for (i = 0;␊ |
656 | ␉␉(i < bootInfo->memoryMapCount) && (bufflen < 1024); /* prevent buffer overflow */␊ |
657 | ␉␉i++) {␊ |
658 | ␉␉bufflen += snprintf(buff+bufflen, 1024-bufflen, "Base 0x%08x%08x, ",␊ |
659 | (unsigned long)(mp->base >> 32),␊ |
660 | (unsigned long)(mp->base));␊ |
661 | ␉␉bufflen += snprintf(buff+bufflen, 1024-bufflen, "length 0x%08x%08x, type %d\n",␊ |
662 | (unsigned long)(mp->length >> 32),␊ |
663 | (unsigned long)(mp->length),␊ |
664 | mp->type);␊ |
665 | ␉␉mp++;␊ |
666 | ␉}␊ |
667 | ␉return buff;␊ |
668 | }␊ |
669 | ␊ |
670 | //==========================================================================␊ |
671 | ␊ |
672 | void lspci(void)␊ |
673 | {␊ |
674 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) { ␊ |
675 | ␉␉setActiveDisplayPage(1);␊ |
676 | ␉␉clearScreenRows(0, 24);␊ |
677 | ␉␉setCursorPosition(0, 0, 1);␊ |
678 | ␉}␊ |
679 | ␊ |
680 | ␉dump_pci_dt(root_pci_dev->children);␊ |
681 | ␊ |
682 | ␉pause();␊ |
683 | ␊ |
684 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
685 | ␉␉setActiveDisplayPage(0);␊ |
686 | ␉}␊ |
687 | }␊ |
688 | ␊ |
689 | //==========================================================================␊ |
690 | ␊ |
691 | int getBootOptions(bool firstRun)␊ |
692 | {␊ |
693 | ␉int i;␊ |
694 | ␉int key;␊ |
695 | ␉int nextRow;␊ |
696 | ␉int timeout;␊ |
697 | ␉int bvCount;␊ |
698 | ␉BVRef bvr;␊ |
699 | ␉BVRef menuBVR;␊ |
700 | ␉bool showPrompt, newShowPrompt, isCDROM;␊ |
701 | ␊ |
702 | ␉// Initialize default menu selection entry.␊ |
703 | ␉gBootVolume = menuBVR = selectBootVolume(bvChain);␊ |
704 | ␊ |
705 | ␉if (biosDevIsCDROM(gBIOSDev)) {␊ |
706 | ␉␉isCDROM = true;␊ |
707 | ␉} else {␊ |
708 | ␉␉isCDROM = false;␊ |
709 | ␉}␊ |
710 | ␊ |
711 | ␉// ensure we're in graphics mode if gui is setup␊ |
712 | ␉if (firstRun && gui.initialised && bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
713 | ␉{␊ |
714 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
715 | ␉}␊ |
716 | ␊ |
717 | ␉// Clear command line boot arguments␊ |
718 | ␉clearBootArgs();␊ |
719 | ␊ |
720 | ␉// Allow user to override default timeout.␊ |
721 | ␉if (multiboot_timeout_set) {␊ |
722 | ␉␉timeout = multiboot_timeout;␊ |
723 | ␉} else if (!getIntForKey(kTimeoutKey, &timeout, &bootInfo->chameleonConfig)) {␊ |
724 | ␉␉/* If there is no timeout key in the file use the default timeout␊ |
725 | ␉␉ which is different for CDs vs. hard disks. However, if not booting␊ |
726 | ␉␉ a CD and no config file could be loaded set the timeout␊ |
727 | ␉␉ to zero which causes the menu to display immediately.␊ |
728 | ␉␉ This way, if no partitions can be found, that is the disk is unpartitioned␊ |
729 | ␉␉ or simply cannot be read) then an empty menu is displayed.␊ |
730 | ␉␉ If some partitions are found, for example a Windows partition, then␊ |
731 | ␉␉ these will be displayed in the menu as foreign partitions.␊ |
732 | ␉␉ */␊ |
733 | ␉␉if (isCDROM) {␊ |
734 | ␉␉␉timeout = kCDBootTimeout;␊ |
735 | ␉␉} else {␊ |
736 | ␉␉␉timeout = sysConfigValid ? kBootTimeout : 0;␊ |
737 | ␉␉}␊ |
738 | ␉}␊ |
739 | ␊ |
740 | ␉if (timeout < 0) {␊ |
741 | ␉␉gBootMode |= kBootModeQuiet;␊ |
742 | ␉}␊ |
743 | ␊ |
744 | ␉// If the user is holding down a modifier key, enter safe mode.␊ |
745 | ␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
746 | ␉␉gBootMode |= kBootModeSafe;␊ |
747 | ␉}␊ |
748 | ␊ |
749 | ␉// Checking user pressed keys␊ |
750 | ␉bool f8press = false, spress = false, vpress = false;␊ |
751 | ␉while (readKeyboardStatus()) {␊ |
752 | ␉␉key = bgetc ();␊ |
753 | ␉␉if (key == 0x4200) f8press = true;␊ |
754 | ␉␉if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true;␊ |
755 | ␉␉if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true;␊ |
756 | ␉}␊ |
757 | ␉// If user typed F8, abort quiet mode, and display the menu.␊ |
758 | ␉if (f8press) {␊ |
759 | ␉␉gBootMode &= ~kBootModeQuiet;␊ |
760 | ␉␉timeout = 0;␊ |
761 | ␉}␊ |
762 | ␉// If user typed 'v' or 'V', boot in verbose mode.␊ |
763 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && vpress) {␊ |
764 | ␉␉addBootArg(kVerboseModeFlag);␊ |
765 | ␉}␊ |
766 | ␉// If user typed 's' or 'S', boot in single user mode.␊ |
767 | ␉if ((gBootMode & kBootModeQuiet) && firstRun && spress) {␊ |
768 | ␉␉addBootArg(kSingleUserModeFlag);␊ |
769 | ␉}␊ |
770 | ␊ |
771 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
772 | ␉␉setCursorPosition(0, 0, 0);␊ |
773 | ␉␉clearScreenRows(0, kScreenLastRow);␊ |
774 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
775 | ␉␉␉// Display banner and show hardware info.␊ |
776 | ␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
777 | ␉␉␉printf(getVBEInfoString());␊ |
778 | ␉␉}␊ |
779 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
780 | ␉␉verbose("Scanning device %x...", gBIOSDev);␊ |
781 | ␉}␊ |
782 | ␊ |
783 | ␉// When booting from CD, default to hard drive boot when possible. ␊ |
784 | ␉if (isCDROM && firstRun) {␊ |
785 | ␉␉const char *val;␊ |
786 | ␉␉char *prompt = NULL;␊ |
787 | ␉␉char *name = NULL;␊ |
788 | ␉␉int cnt;␊ |
789 | ␉␉int optionKey;␊ |
790 | ␊ |
791 | ␉␉if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->chameleonConfig)) {␊ |
792 | ␉␉␉prompt = malloc(cnt + 1);␊ |
793 | ␉␉␉strncat(prompt, val, cnt);␊ |
794 | ␉␉} else {␊ |
795 | ␉␉␉name = malloc(80);␊ |
796 | ␉␉␉getBootVolumeDescription(gBootVolume, name, 79, false);␊ |
797 | ␉␉␉prompt = malloc(256);␊ |
798 | ␉␉␉sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name);␊ |
799 | ␉␉␉free(name);␊ |
800 | ␉␉}␊ |
801 | ␊ |
802 | ␉␉if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->chameleonConfig )) {␊ |
803 | ␉␉␉// The key specified is a special key.␊ |
804 | ␉␉} else {␊ |
805 | ␉␉␉// Default to F8.␊ |
806 | ␉␉␉optionKey = 0x4200;␊ |
807 | ␉␉}␊ |
808 | ␊ |
809 | ␉␉// If the timeout is zero then it must have been set above due to the␊ |
810 | ␉␉// early catch of F8 which means the user wants to set boot options␊ |
811 | ␉␉// which we ought to interpret as meaning he wants to boot the CD.␊ |
812 | ␉␉if (timeout != 0) {␊ |
813 | ␉␉␉key = countdown(prompt, kMenuTopRow, timeout);␊ |
814 | ␉␉} else {␊ |
815 | ␉␉␉key = optionKey;␊ |
816 | ␉␉}␊ |
817 | ␊ |
818 | ␉␉if (prompt != NULL) {␊ |
819 | ␉␉␉free(prompt);␊ |
820 | ␉␉}␊ |
821 | ␊ |
822 | ␉␉clearScreenRows( kMenuTopRow, kMenuTopRow + 2 );␊ |
823 | ␊ |
824 | ␉␉// Hit the option key ?␊ |
825 | ␉␉if (key == optionKey) {␊ |
826 | ␉␉␉gBootMode &= ~kBootModeQuiet;␊ |
827 | ␉␉␉timeout = 0;␊ |
828 | ␉␉} else {␊ |
829 | ␉␉␉key = key & 0xFF;␊ |
830 | ␊ |
831 | ␉␉␉// Try booting hard disk if user pressed 'h'␊ |
832 | ␉␉␉if (biosDevIsCDROM(gBIOSDev) && key == 'h') {␊ |
833 | ␉␉␉␉BVRef bvr;␊ |
834 | ␊ |
835 | ␉␉␉␉// Look at partitions hosting OS X other than the CD-ROM␊ |
836 | ␉␉␉␉for (bvr = bvChain; bvr; bvr=bvr->next) {␊ |
837 | ␉␉␉␉␉if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) {␊ |
838 | ␉␉␉␉␉␉gBootVolume = bvr;␊ |
839 | ␉␉␉␉␉}␊ |
840 | ␉␉␉␉}␊ |
841 | ␉␉␉}␊ |
842 | ␉␉␉goto done;␊ |
843 | ␉␉}␊ |
844 | ␉}␊ |
845 | ␊ |
846 | ␉if (gBootMode & kBootModeQuiet) {␊ |
847 | ␉␉// No input allowed from user.␊ |
848 | ␉␉goto done;␊ |
849 | ␉}␊ |
850 | ␊ |
851 | ␉if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) {␊ |
852 | ␉␉// If the user is holding down a modifier key,␊ |
853 | ␉␉// enter safe mode.␊ |
854 | ␉␉if ((readKeyboardShiftFlags() & 0x0F) != 0) {␊ |
855 | ␉␉␉gBootMode |= kBootModeSafe;␊ |
856 | ␉␉}␊ |
857 | ␉␉goto done;␊ |
858 | ␉}␊ |
859 | ␊ |
860 | ␉if (gDeviceCount > 0) {␊ |
861 | ␉␉// Allocate memory for an array of menu items.␊ |
862 | ␉␉menuItems = malloc(sizeof(MenuItem) * gDeviceCount);␊ |
863 | ␉␉if (menuItems == NULL) {␊ |
864 | ␉␉␉goto done;␊ |
865 | ␉␉}␊ |
866 | ␊ |
867 | ␉␉// Associate a menu item for each BVRef.␊ |
868 | ␉␉for (bvr=bvChain, i=gDeviceCount-1, selectIndex=-1; bvr; bvr=bvr->next) {␊ |
869 | ␉␉␉if (bvr->visible) {␊ |
870 | ␉␉␉␉getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true);␊ |
871 | ␉␉␉␉menuItems[i].param = (void *) bvr;␊ |
872 | ␉␉␉␉if (bvr == menuBVR) {␊ |
873 | ␉␉␉␉␉selectIndex = i;␊ |
874 | ␉␉␉␉}␊ |
875 | ␉␉␉␉i--;␊ |
876 | ␉␉␉}␊ |
877 | ␉␉}␊ |
878 | ␉␉// Jief : In case the default partition (returned by selectBootVolume) is not in the menu␊ |
879 | ␉␉if ( selectIndex == -1 )␊ |
880 | ␉␉{␊ |
881 | ␉␉␉selectIndex = 0;␊ |
882 | ␊ |
883 | ␉␉␉// gDeviceCount is actually > 0, so menuItems[selectIndex] exists␊ |
884 | ␉␉␉menuBVR = (BVRef)(menuItems[selectIndex].param);␊ |
885 | ␉␉␉// what happen is bvChain is empty ?␊ |
886 | ␉␉}␊ |
887 | ␉}␊ |
888 | ␊ |
889 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
890 | ␉␉// redraw the background buffer␊ |
891 | ␉␉gui.logo.draw = true;␊ |
892 | ␉␉drawBackground();␊ |
893 | ␉␉gui.devicelist.draw = true;␊ |
894 | ␉␉gui.redraw = true;␊ |
895 | ␉␉if (!(gBootMode & kBootModeQuiet)) {␊ |
896 | ␊ |
897 | ␉␉␉// Check if "Boot Banner"=N switch is present in config file.␊ |
898 | ␉␉␉getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->chameleonConfig); ␊ |
899 | ␉␉␉if (showBootBanner) {␊ |
900 | ␉␉␉␉// Display banner and show hardware info.␊ |
901 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
902 | ␉␉␉}␊ |
903 | ␊ |
904 | ␉␉␉// redraw background␊ |
905 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
906 | ␉␉}␊ |
907 | ␉} else {␊ |
908 | ␉␉// Clear screen and hide the blinking cursor.␊ |
909 | ␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
910 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
911 | ␉}␊ |
912 | ␊ |
913 | ␉nextRow = kMenuTopRow;␊ |
914 | ␉showPrompt = true;␊ |
915 | ␊ |
916 | ␉if (gDeviceCount) {␊ |
917 | ␉␉if( bootArgs->Video.v_display == VGA_TEXT_MODE ) {␊ |
918 | ␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
919 | ␉␉}␊ |
920 | ␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
921 | ␉␉nextRow += MIN( gDeviceCount, kMenuMaxItems ) + 3;␊ |
922 | ␉}␊ |
923 | ␊ |
924 | ␉// Show the boot prompt.␊ |
925 | ␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
926 | ␉showBootPrompt( nextRow, showPrompt );␊ |
927 | ␉␊ |
928 | ␉do {␊ |
929 | ␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
930 | ␉␉␉// redraw background␊ |
931 | ␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
932 | ␉␉␉// reset cursor co-ords␊ |
933 | ␉␉␉gui.debug.cursor = pos( gui.screen.width - 160 , 10 );␊ |
934 | ␉␉}␊ |
935 | ␉␉key = getchar();␊ |
936 | ␉␉updateMenu( key, (void **) &menuBVR );␊ |
937 | ␉␉newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
938 | ␊ |
939 | ␉␉if (newShowPrompt != showPrompt) {␊ |
940 | ␉␉␉showPrompt = newShowPrompt;␊ |
941 | ␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
942 | ␉␉}␊ |
943 | ␊ |
944 | ␉␉if (showPrompt) {␊ |
945 | ␉␉␉updateBootArgs(key);␊ |
946 | ␉␉}␊ |
947 | ␊ |
948 | ␉␉switch (key) {␊ |
949 | ␉␉case KEY_ENTER:␊ |
950 | ␉␉␉if (gui.menu.draw) { ␊ |
951 | ␉␉␉␉key=0;␊ |
952 | ␉␉␉␉break;␊ |
953 | ␉␉␉}␊ |
954 | ␉␉␉if (*gBootArgs == '?') {␊ |
955 | ␉␉␉␉char * argPtr = gBootArgs;␊ |
956 | ␊ |
957 | ␉␉␉␉// Skip the leading "?" character.␊ |
958 | ␉␉␉␉argPtr++;␊ |
959 | ␉␉␉␉getNextArg(&argPtr, booterCommand);␊ |
960 | ␉␉␉␉getNextArg(&argPtr, booterParam);␊ |
961 | ␊ |
962 | ␉␉␉␉/*␊ |
963 | ␉␉␉␉* TODO: this needs to be refactored.␊ |
964 | ␉␉␉␉*/␊ |
965 | ␉␉␉␉if (strcmp( booterCommand, "video" ) == 0) {␊ |
966 | ␉␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
967 | ␉␉␉␉␉␉showInfoBox(getVBEInfoString(), getVBEModeInfoString());␊ |
968 | ␉␉␉␉␉} else {␊ |
969 | ␉␉␉␉␉␉printVBEModeInfo();␊ |
970 | ␉␉␉␉␉}␊ |
971 | ␉␉␉␉} else if ( strcmp( booterCommand, "memory" ) == 0) {␊ |
972 | ␉␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE ) {␊ |
973 | ␉␉␉␉␉␉showInfoBox("Memory Map", getMemoryInfoString());␊ |
974 | ␉␉␉␉␉} else {␊ |
975 | ␉␉␉␉␉␉printMemoryInfo();␊ |
976 | ␉␉␉␉␉}␊ |
977 | ␉␉␉␉} else if (strcmp(booterCommand, "lspci") == 0) {␊ |
978 | ␉␉␉␉␉lspci();␊ |
979 | ␉␉␉␉} else if (strcmp(booterCommand, "more") == 0) {␊ |
980 | ␉␉␉␉␉showTextFile(booterParam);␊ |
981 | ␉␉␉␉} else if (strcmp(booterCommand, "rd") == 0) {␊ |
982 | ␉␉␉␉␉processRAMDiskCommand(&argPtr, booterParam);␊ |
983 | ␉␉␉␉} else if (strcmp(booterCommand, "norescan") == 0) {␊ |
984 | ␉␉␉␉␉if (gEnableCDROMRescan) {␊ |
985 | ␉␉␉␉␉␉gEnableCDROMRescan = false;␊ |
986 | ␉␉␉␉␉␉break;␊ |
987 | ␉␉␉␉␉}␊ |
988 | ␉␉␉␉} else {␊ |
989 | ␉␉␉␉␉showHelp();␊ |
990 | ␉␉␉␉}␊ |
991 | ␉␉␉␉key = 0;␊ |
992 | ␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
993 | ␉␉␉␉break;␊ |
994 | ␉␉␉}␊ |
995 | ␉␉␉gBootVolume = menuBVR;␊ |
996 | ␉␉␉setRootVolume(menuBVR);␊ |
997 | ␉␉␉gBIOSDev = menuBVR->biosdev;␊ |
998 | ␉␉␉break;␊ |
999 | ␊ |
1000 | ␉␉case KEY_ESC:␊ |
1001 | ␉␉␉clearBootArgs();␊ |
1002 | ␉␉␉break;␊ |
1003 | ␊ |
1004 | ␉␉case KEY_F5:␊ |
1005 | ␉␉␉// New behavior:␊ |
1006 | ␉␉␉// Clear gBootVolume to restart the loop␊ |
1007 | ␉␉␉// if the user enabled rescanning the optical drive.␊ |
1008 | ␉␉␉// Otherwise boot the default boot volume.␊ |
1009 | ␉␉␉if (gEnableCDROMRescan) {␊ |
1010 | ␉␉␉␉gBootVolume = NULL;␊ |
1011 | ␉␉␉␉clearBootArgs();␊ |
1012 | ␉␉␉}␊ |
1013 | ␉␉␉break;␊ |
1014 | ␊ |
1015 | ␉␉case KEY_F10:␊ |
1016 | ␉␉␉gScanSingleDrive = false;␊ |
1017 | ␉␉␉scanDisks(gBIOSDev, &bvCount);␊ |
1018 | ␉␉␉gBootVolume = NULL;␊ |
1019 | ␉␉␉clearBootArgs();␊ |
1020 | ␉␉␉break;␊ |
1021 | ␊ |
1022 | ␉␉case KEY_TAB:␊ |
1023 | ␉␉␉// New behavior:␊ |
1024 | ␉␉␉// Switch between text & graphic interfaces␊ |
1025 | ␉␉␉// Only Permitted if started in graphics interface␊ |
1026 | ␉␉␉if (useGUI) {␊ |
1027 | ␉␉␉␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1028 | ␉␉␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
1029 | ␊ |
1030 | ␉␉␉␉␉setCursorPosition(0, 0, 0);␊ |
1031 | ␉␉␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
1032 | ␊ |
1033 | ␉␉␉␉␉// Display banner and show hardware info.␊ |
1034 | ␉␉␉␉␉printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
1035 | ␉␉␉␉␉printf(getVBEInfoString());␊ |
1036 | ␊ |
1037 | ␉␉␉␉␉clearScreenRows(kMenuTopRow, kMenuTopRow + 2);␊ |
1038 | ␉␉␉␉␉changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0);␊ |
1039 | ␊ |
1040 | ␉␉␉␉␉nextRow = kMenuTopRow;␊ |
1041 | ␉␉␉␉␉showPrompt = true;␊ |
1042 | ␊ |
1043 | ␉␉␉␉␉if (gDeviceCount) {␊ |
1044 | ␉␉␉␉␉␉printf("Use \30\31 keys to select the startup volume.");␊ |
1045 | ␉␉␉␉␉␉showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems);␊ |
1046 | ␉␉␉␉␉␉nextRow += MIN(gDeviceCount, kMenuMaxItems) + 3;␊ |
1047 | ␉␉␉␉␉}␊ |
1048 | ␊ |
1049 | ␉␉␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
1050 | ␉␉␉␉␉showBootPrompt(nextRow, showPrompt);␊ |
1051 | ␉␉␉␉␉//changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 );␊ |
1052 | ␉␉␉␉} else {␊ |
1053 | ␉␉␉␉␉gui.redraw = true;␊ |
1054 | ␉␉␉␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
1055 | ␉␉␉␉␉updateVRAM();␊ |
1056 | ␉␉␉updateGraphicBootPrompt();␊ |
1057 | ␉␉␉␉}␊ |
1058 | ␉␉␉}␊ |
1059 | ␉␉␉key = 0;␊ |
1060 | ␉␉␉break;␊ |
1061 | ␊ |
1062 | ␉␉default:␊ |
1063 | ␉␉␉key = 0;␊ |
1064 | ␉␉␉break;␊ |
1065 | ␉␉}␊ |
1066 | ␉} while (0 == key);␊ |
1067 | ␊ |
1068 | done:␊ |
1069 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE) {␊ |
1070 | ␉␉clearScreenRows(kMenuTopRow, kScreenLastRow);␊ |
1071 | ␉␉changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);␊ |
1072 | ␉}␊ |
1073 | ␉shouldboot = false;␊ |
1074 | ␉gui.menu.draw = false;␊ |
1075 | ␉if (menuItems) {␊ |
1076 | ␉␉free(menuItems);␊ |
1077 | ␉␉menuItems = NULL;␊ |
1078 | ␉}␊ |
1079 | ␉execute_hook("BootOptions", gBootArgs, gBootArgsPtr, NULL, NULL);␊ |
1080 | ␉return 0;␊ |
1081 | }␊ |
1082 | ␊ |
1083 | //==========================================================================␊ |
1084 | ␊ |
1085 | char gBootUUIDString[32+4+1] = ""; // UUID of the boot volume e.g. 5EB1869F-C4FA-3502-BDEB-3B8ED5D87292␊ |
1086 | extern unsigned char chainbootdev;␊ |
1087 | extern unsigned char chainbootflag;␊ |
1088 | ␊ |
1089 | bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)␊ |
1090 | {␊ |
1091 | ␉int argLen = argName ? strlen(argName) : 0;␊ |
1092 | ␉int len = argLen + cnt + 1; // + 1 to account for space.␊ |
1093 | ␊ |
1094 | ␉if (len > *cntRemainingP) {␊ |
1095 | ␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1096 | ␉␉return false;␊ |
1097 | ␉}␊ |
1098 | ␊ |
1099 | ␉if (argName) {␊ |
1100 | ␉␉strncpy( *argP, argName, argLen );␊ |
1101 | ␉␉*argP += argLen;␊ |
1102 | ␉␉*argP[0] = '=';␊ |
1103 | ␉␉(*argP)++;␊ |
1104 | ␉␉len++; // +1 to account for '='␊ |
1105 | ␉}␊ |
1106 | ␊ |
1107 | ␉strncpy(*argP, val, cnt);␊ |
1108 | ␉*argP += cnt;␊ |
1109 | ␉*argP[0] = ' ';␊ |
1110 | ␉(*argP)++;␊ |
1111 | ␉*cntRemainingP -= len;␊ |
1112 | ␊ |
1113 | ␉return true;␊ |
1114 | }␊ |
1115 | ␊ |
1116 | // ␊ |
1117 | // Returns TRUE if an argument was copied, FALSE otherwise␊ |
1118 | bool␊ |
1119 | processBootArgument(␊ |
1120 | const char *argName, // The argument to search for␊ |
1121 | const char *userString, // Typed-in boot arguments␊ |
1122 | const char *kernelFlags, // Kernel flags from config table␊ |
1123 | const char *configTable,␊ |
1124 | char **argP, // Output value␊ |
1125 | int *cntRemainingP, // Output count␊ |
1126 | char *foundVal, // found value␊ |
1127 | int foundValSize // max found value size␊ |
1128 | ) {␊ |
1129 | ␉const char *val;␊ |
1130 | ␉int cnt;␊ |
1131 | ␉bool found = false;␊ |
1132 | ␊ |
1133 | ␉if (getValueForBootKey(userString, argName, &val, &cnt)) {␊ |
1134 | ␉␉// Don't copy; these values will be copied at the end of argument processing.␊ |
1135 | ␉␉found = true;␊ |
1136 | ␉} else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {␊ |
1137 | ␉␉// Don't copy; these values will be copied at the end of argument processing.␊ |
1138 | ␉␉found = true;␊ |
1139 | ␉} else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig)) {␊ |
1140 | ␉␉copyArgument(argName, val, cnt, argP, cntRemainingP);␊ |
1141 | ␉␉found = true;␊ |
1142 | ␉}␊ |
1143 | ␉if (found && foundVal) {␊ |
1144 | ␉␉strlcpy(foundVal, val, foundValSize);␊ |
1145 | ␉}␊ |
1146 | ␉return found;␊ |
1147 | }␊ |
1148 | ␊ |
1149 | // Maximum config table value size␊ |
1150 | #define VALUE_SIZE 2048␊ |
1151 | ␊ |
1152 | int␊ |
1153 | processBootOptions()␊ |
1154 | {␊ |
1155 | ␉const char *cp = gBootArgs;␊ |
1156 | ␉const char *val = 0;␊ |
1157 | ␉const char *kernel;␊ |
1158 | ␉int cnt;␊ |
1159 | ␉int userCnt;␊ |
1160 | ␉int cntRemaining;␊ |
1161 | ␉char *argP;␊ |
1162 | ␉char *configKernelFlags;␊ |
1163 | ␉char *valueBuffer;␊ |
1164 | ␊ |
1165 | ␉valueBuffer = malloc(VALUE_SIZE);␊ |
1166 | ␊ |
1167 | ␉skipblanks( &cp );␊ |
1168 | ␊ |
1169 | ␉// Update the unit and partition number.␊ |
1170 | ␊ |
1171 | ␉if ( gBootVolume ) {␊ |
1172 | ␉␉if (!( gBootVolume->flags & kBVFlagNativeBoot )) {␊ |
1173 | ␉␉␉readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 );␊ |
1174 | ␉␉␉//␊ |
1175 | ␉␉␉// Setup edx, and signal intention to chain load the␊ |
1176 | ␉␉␉// foreign booter.␊ |
1177 | ␉␉␉//␊ |
1178 | ␊ |
1179 | ␉␉␉chainbootdev = gBootVolume->biosdev;␊ |
1180 | ␉␉␉chainbootflag = 1;␊ |
1181 | ␊ |
1182 | ␉␉␉return 1;␊ |
1183 | ␉␉}␊ |
1184 | ␊ |
1185 | ␉␉setRootVolume(gBootVolume);␊ |
1186 | ␊ |
1187 | ␉}␊ |
1188 | ␉// If no boot volume fail immediately because we're just going to fail␊ |
1189 | ␉// trying to load the config file anyway.␊ |
1190 | ␉else {␊ |
1191 | ␉␉return -1;␊ |
1192 | ␉}␊ |
1193 | ␊ |
1194 | ␉// Load config table specified by the user, or use the default.␊ |
1195 | ␊ |
1196 | ␉if (!getValueForBootKey(cp, "config", &val, &cnt)) {␊ |
1197 | ␉␉val = 0;␊ |
1198 | ␉␉cnt = 0;␊ |
1199 | ␉}␊ |
1200 | ␊ |
1201 | ␉// Load com.apple.Boot.plist from the selected volume␊ |
1202 | ␉// and use its contents to override default bootConfig.␊ |
1203 | ␊ |
1204 | ␉loadSystemConfig(&bootInfo->bootConfig); ␊ |
1205 | ␉loadChameleonConfig(&bootInfo->chameleonConfig);␊ |
1206 | ␊ |
1207 | ␉// Use the kernel name specified by the user, or fetch the name␊ |
1208 | ␉// in the config table, or use the default if not specified.␊ |
1209 | ␉// Specifying a kernel name on the command line, or specifying␊ |
1210 | ␉// a non-default kernel name in the config file counts as␊ |
1211 | ␉// overriding the kernel, which causes the kernelcache not␊ |
1212 | ␉// to be used.␊ |
1213 | ␊ |
1214 | ␉gOverrideKernel = false;␊ |
1215 | ␉if (( kernel = extractKernelName((char **)&cp) )) {␊ |
1216 | ␉␉strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );␊ |
1217 | ␉} else {␊ |
1218 | ␉␉if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1219 | ␉␉␉strlcpy( bootInfo->bootFile, val, cnt+1 );␊ |
1220 | ␉␉} else {␊ |
1221 | ␉␉␉strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );␊ |
1222 | ␉␉}␊ |
1223 | ␉}␊ |
1224 | ␉if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {␊ |
1225 | ␉␉gOverrideKernel = true;␊ |
1226 | ␉}␊ |
1227 | ␊ |
1228 | ␉cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space␊ |
1229 | ␉argP = bootArgs->CommandLine;␊ |
1230 | ␊ |
1231 | ␉// Get config kernel flags, if not ignored.␊ |
1232 | ␉if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||␊ |
1233 | !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) {␊ |
1234 | ␉␉val = "";␊ |
1235 | ␉␉cnt = 0;␊ |
1236 | ␉}␊ |
1237 | ␉configKernelFlags = malloc(cnt + 1);␊ |
1238 | ␉strlcpy(configKernelFlags, val, cnt + 1);␊ |
1239 | ␊ |
1240 | ␉// boot-uuid can be set either on the command-line or in the config file␊ |
1241 | ␉if (!processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config,␊ |
1242 | &argP, &cntRemaining, gBootUUIDString, sizeof(gBootUUIDString))) {␊ |
1243 | ␉␉//␊ |
1244 | ␉␉// Try an alternate method for getting the root UUID on boot helper partitions.␊ |
1245 | ␉␉//␊ |
1246 | ␉␉if (gBootVolume->flags & kBVFlagBooter) {␊ |
1247 | ␉␉␉// Load the configuration store in the boot helper partition␊ |
1248 | ␉␉␉if (loadHelperConfig(&bootInfo->helperConfig) == 0) {␊ |
1249 | ␉␉␉␉val = getStringForKey(kHelperRootUUIDKey, &bootInfo->helperConfig);␊ |
1250 | ␉␉␉␉if (val != NULL) {␊ |
1251 | ␉␉␉␉␉strlcpy(gBootUUIDString, val, sizeof(gBootUUIDString));␊ |
1252 | ␉␉␉␉}␊ |
1253 | ␉␉␉}␊ |
1254 | ␉␉}␊ |
1255 | ␊ |
1256 | ␉␉// Try to get the volume uuid string␊ |
1257 | ␉␉if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) {␊ |
1258 | ␉␉␉gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString);␊ |
1259 | ␉␉}␊ |
1260 | ␊ |
1261 | ␉␉// If we have the volume uuid add it to the commandline arguments␊ |
1262 | ␉␉if (strlen(gBootUUIDString)) {␊ |
1263 | ␉␉␉copyArgument(kBootUUIDKey, gBootUUIDString, strlen(gBootUUIDString), &argP, &cntRemaining);␊ |
1264 | ␉␉}␊ |
1265 | ␉}␊ |
1266 | ␊ |
1267 | ␉if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config,␊ |
1268 | &argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE)) {␊ |
1269 | ␉␉cnt = 0;␊ |
1270 | ␉␉if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig)) {␊ |
1271 | ␉␉␉valueBuffer[0] = '*';␊ |
1272 | ␉␉␉cnt++;␊ |
1273 | ␉␉␉strlcpy(valueBuffer + 1, val, cnt);␊ |
1274 | ␉␉␉val = valueBuffer;␊ |
1275 | ␉␉} else {␊ |
1276 | ␉␉␉if (strlen(gBootUUIDString)) {␊ |
1277 | ␉␉␉␉val = "*uuid";␊ |
1278 | ␉␉␉␉cnt = 5;␊ |
1279 | ␉␉␉} else {␊ |
1280 | ␉␉␉␉// Don't set "rd=.." if there is no boot device key␊ |
1281 | ␉␉␉␉// and no UUID.␊ |
1282 | ␉␉␉␉val = "";␊ |
1283 | ␉␉␉␉cnt = 0;␊ |
1284 | ␉␉␉}␊ |
1285 | ␉␉} ␊ |
1286 | ␉␉if (cnt > 0) {␊ |
1287 | ␉␉␉copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);␊ |
1288 | ␉␉}␊ |
1289 | ␉␉strlcpy( gRootDevice, val, (cnt + 1));␊ |
1290 | ␉}␊ |
1291 | ␊ |
1292 | ␉/*␊ |
1293 | ␉ * Removed. We don't need this anymore.␊ |
1294 | ␉ *␊ |
1295 | ␉if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config,␊ |
1296 | ␉␉␉␉␉␉␉ &argP, &cntRemaining, gPlatformName, sizeof(gCacheNameAdler))) {␊ |
1297 | ␉␉getPlatformName(gPlatformName);␊ |
1298 | ␉␉copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);␊ |
1299 | ␉}␊ |
1300 | ␉*/␊ |
1301 | ␊ |
1302 | ␉if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&␊ |
1303 | !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) {␊ |
1304 | ␉␉if (gBootMode & kBootModeSafe) {␊ |
1305 | ␉␉␉copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);␊ |
1306 | ␉␉}␊ |
1307 | ␉}␊ |
1308 | ␊ |
1309 | ␉// Store the merged kernel flags and boot args.␊ |
1310 | ␊ |
1311 | ␉cnt = strlen(configKernelFlags);␊ |
1312 | ␉if (cnt) {␊ |
1313 | ␉␉if (cnt > cntRemaining) {␊ |
1314 | ␉␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1315 | ␉␉␉cnt = cntRemaining;␊ |
1316 | ␉␉}␊ |
1317 | ␉␉strncpy(argP, configKernelFlags, cnt);␊ |
1318 | ␉␉argP[cnt++] = ' ';␊ |
1319 | ␉␉cntRemaining -= cnt;␊ |
1320 | ␉}␊ |
1321 | ␉userCnt = strlen(cp);␊ |
1322 | ␉if (userCnt > cntRemaining) {␊ |
1323 | ␉␉error("Warning: boot arguments too long, truncating\n");␊ |
1324 | ␉␉userCnt = cntRemaining;␊ |
1325 | ␉}␊ |
1326 | ␉strncpy(&argP[cnt], cp, userCnt);␊ |
1327 | ␉argP[cnt+userCnt] = '\0';␊ |
1328 | ␊ |
1329 | ␉if(!shouldboot) {␊ |
1330 | ␉␉gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ||␊ |
1331 | ␉␉␉getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->chameleonConfig );␊ |
1332 | ␉␉␊ |
1333 | ␉␉gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) ?␊ |
1334 | ␉␉␉kBootModeSafe : kBootModeNormal;␊ |
1335 | ␊ |
1336 | ␉␉if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) {␊ |
1337 | ␉␉␉gBootMode = kBootModeSafe;␊ |
1338 | ␉␉}␊ |
1339 | ␉}␊ |
1340 | ␊ |
1341 | ␉if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) ) {␊ |
1342 | ␉␉strlcpy(gMKextName, val, cnt + 1);␊ |
1343 | ␉} else {␊ |
1344 | ␉␉gMKextName[0]=0;␊ |
1345 | ␉}␊ |
1346 | ␊ |
1347 | ␉free(configKernelFlags);␊ |
1348 | ␉free(valueBuffer);␊ |
1349 | ␊ |
1350 | ␉return 0;␊ |
1351 | }␊ |
1352 | ␊ |
1353 | ␊ |
1354 | //==========================================================================␊ |
1355 | // Load the help file and display the file contents on the screen.␊ |
1356 | ␊ |
1357 | void showTextBuffer(char *buf_orig, int size)␊ |
1358 | {␊ |
1359 | ␉char␉*bp;␊ |
1360 | ␉char* buf;␊ |
1361 | ␉int␉line;␊ |
1362 | ␉int␉line_offset;␊ |
1363 | ␉int␉c;␊ |
1364 | ␊ |
1365 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1366 | ␉␉showInfoBox( "Press q to continue, space for next page.\n",buf_orig );␊ |
1367 | ␉␉return;␊ |
1368 | ␉}␊ |
1369 | ␊ |
1370 | ␉// Create a copy so that we don't mangle the original␊ |
1371 | ␉buf = malloc(size + 1);␊ |
1372 | ␉memcpy(buf, buf_orig, size);␊ |
1373 | ␉␊ |
1374 | ␊ |
1375 | bp = buf;␊ |
1376 | while (size-- > 0) {␊ |
1377 | ␉␉if (*bp == '\n') {␊ |
1378 | ␉␉␉*bp = '\0';␊ |
1379 | ␉␉}␊ |
1380 | ␉␉bp++;␊ |
1381 | }␊ |
1382 | *bp = '\1';␊ |
1383 | line_offset = 0;␊ |
1384 | ␊ |
1385 | setActiveDisplayPage(1);␊ |
1386 | ␊ |
1387 | while (1) {␊ |
1388 | ␉␉clearScreenRows(0, 24);␊ |
1389 | ␉␉setCursorPosition(0, 0, 1);␊ |
1390 | ␉␉bp = buf;␊ |
1391 | ␉␉for (line = 0; *bp != '\1' && line < line_offset; line++) {␊ |
1392 | ␉␉␉while (*bp != '\0') {␊ |
1393 | ␉␉␉␉bp++;␊ |
1394 | ␉␉␉}␊ |
1395 | ␉␉␉bp++;␊ |
1396 | ␉␉}␊ |
1397 | ␉␉for (line = 0; *bp != '\1' && line < 23; line++) {␊ |
1398 | ␉␉␉setCursorPosition(0, line, 1);␊ |
1399 | ␉␉␉printf("%s\n", bp);␊ |
1400 | ␉␉␉while (*bp != '\0') {␊ |
1401 | ␉␉␉␉bp++;␊ |
1402 | ␉␉␉}␊ |
1403 | ␉␉␉bp++;␊ |
1404 | ␉␉}␊ |
1405 | ␊ |
1406 | ␉␉setCursorPosition(0, 23, 1);␊ |
1407 | ␉␉if (*bp == '\1') {␊ |
1408 | ␉␉␉printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : "");␊ |
1409 | ␉␉} else {␊ |
1410 | ␉␉␉printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : "");␊ |
1411 | ␉␉}␊ |
1412 | ␊ |
1413 | ␉␉c = getchar();␊ |
1414 | ␉␉if (c == 'q' || c == 'Q') {␊ |
1415 | ␉␉␉break;␊ |
1416 | ␉␉}␊ |
1417 | ␉␉if ((c == 'p' || c == 'P') && line_offset > 0) {␊ |
1418 | ␉␉␉line_offset -= 23;␊ |
1419 | ␉␉}␊ |
1420 | ␉␉if (c == ' ') {␊ |
1421 | ␉␉␉if (*bp == '\1') {␊ |
1422 | ␉␉␉␉break;␊ |
1423 | ␉␉␉} else {␊ |
1424 | ␉␉␉␉line_offset += 23;␊ |
1425 | ␉␉␉}␊ |
1426 | ␉␉}␊ |
1427 | }␊ |
1428 | setActiveDisplayPage(0);␊ |
1429 | }␊ |
1430 | ␊ |
1431 | void showHelp(void)␊ |
1432 | {␊ |
1433 | ␉if (bootArgs->Video.v_display != VGA_TEXT_MODE) {␊ |
1434 | ␉␉showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt);␊ |
1435 | ␉} else {␊ |
1436 | ␉␉showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len);␊ |
1437 | ␉}␊ |
1438 | }␊ |
1439 | ␊ |
1440 | void showTextFile(const char * filename)␊ |
1441 | {␊ |
1442 | #define MAX_TEXT_FILE_SIZE 65536␊ |
1443 | ␉char␉*buf;␊ |
1444 | ␉int␉fd;␊ |
1445 | ␉int␉size;␊ |
1446 | ␊ |
1447 | ␉if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {␊ |
1448 | ␉␉printf("\nFile not found: %s\n", filename);␊ |
1449 | ␉␉sleep(2);␊ |
1450 | ␉␉return;␊ |
1451 | ␉}␊ |
1452 | ␊ |
1453 | size = file_size(fd);␊ |
1454 | if (size > MAX_TEXT_FILE_SIZE) {␊ |
1455 | ␉␉size = MAX_TEXT_FILE_SIZE;␊ |
1456 | ␉}␊ |
1457 | buf = malloc(size);␊ |
1458 | read(fd, buf, size);␊ |
1459 | close(fd);␊ |
1460 | ␉showTextBuffer(buf, size);␊ |
1461 | ␉free(buf);␊ |
1462 | }␊ |
1463 | ␊ |
1464 | // This is a very simplistic prompting scheme that just grabs two hex characters␊ |
1465 | // Eventually we need to do something more user-friendly like display a menu␊ |
1466 | // based off of the Multiboot device list␊ |
1467 | ␊ |
1468 | int selectAlternateBootDevice(int bootdevice)␊ |
1469 | {␊ |
1470 | ␉int key;␊ |
1471 | ␉int newbootdevice;␊ |
1472 | ␉int digitsI = 0;␊ |
1473 | ␉char *end;␊ |
1474 | ␉char digits[3] = {0,0,0};␊ |
1475 | ␊ |
1476 | ␉// We've already printed the current boot device so user knows what it is␊ |
1477 | ␉printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n");␊ |
1478 | ␉printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice);␊ |
1479 | ␉do {␊ |
1480 | ␉␉key = getchar();␊ |
1481 | ␉␉switch (ASCII_KEY(key)) {␊ |
1482 | ␉␉case KEY_BKSP:␊ |
1483 | ␉␉␉if (digitsI > 0) {␊ |
1484 | ␉␉␉␉int x, y, t;␊ |
1485 | ␉␉␉␉getCursorPositionAndType(&x, &y, &t);␊ |
1486 | ␉␉␉␉// Assume x is not 0;␊ |
1487 | ␉␉␉␉x--;␊ |
1488 | ␉␉␉␉setCursorPosition(x,y,0); // back up one char␊ |
1489 | ␉␉␉␉// Overwrite with space without moving cursor position␊ |
1490 | ␉␉␉␉putca(' ', 0x07, 1);␊ |
1491 | ␉␉␉␉digitsI--;␊ |
1492 | ␉␉␉} else {␊ |
1493 | ␉␉␉␉// TODO: Beep or something␊ |
1494 | ␉␉␉}␊ |
1495 | ␉␉␉break;␊ |
1496 | ␊ |
1497 | ␉␉case KEY_ENTER:␊ |
1498 | ␉␉␉digits[digitsI] = '\0';␊ |
1499 | ␉␉␉newbootdevice = strtol(digits, &end, 16);␊ |
1500 | ␉␉␉if (end == digits && *end == '\0') {␊ |
1501 | ␉␉␉␉// User entered empty string␊ |
1502 | ␉␉␉␉printf("\nUsing default boot device %x\n", bootdevice);␊ |
1503 | ␉␉␉␉key = 0;␊ |
1504 | ␉␉␉} else if(end != digits && *end == '\0') {␊ |
1505 | ␉␉␉␉bootdevice = newbootdevice;␊ |
1506 | ␉␉␉␉printf("\n");␊ |
1507 | ␉␉␉␉key = 0; // We gots da boot device␊ |
1508 | ␉␉␉} else {␊ |
1509 | ␉␉␉␉printf("\nCouldn't parse. try again: ");␊ |
1510 | ␉␉␉␉digitsI = 0;␊ |
1511 | ␉␉␉}␊ |
1512 | ␉␉␉break;␊ |
1513 | ␊ |
1514 | ␉␉default:␊ |
1515 | ␉␉␉if (isxdigit(ASCII_KEY(key)) && digitsI < 2) {␊ |
1516 | ␉␉␉␉putchar(ASCII_KEY(key));␊ |
1517 | ␉␉␉␉digits[digitsI++] = ASCII_KEY(key);␊ |
1518 | ␉␉␉} else {␊ |
1519 | ␉␉␉␉// TODO: Beep or something␊ |
1520 | ␉␉␉}␊ |
1521 | ␉␉␉break;␊ |
1522 | ␉␉};␊ |
1523 | ␉} while (key != 0);␊ |
1524 | ␊ |
1525 | ␉return bootdevice;␊ |
1526 | }␊ |
1527 | ␊ |
1528 | bool promptForRescanOption(void)␊ |
1529 | {␊ |
1530 | ␉printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n");␊ |
1531 | ␉if (getchar() == KEY_ENTER) {␊ |
1532 | ␉␉return true;␊ |
1533 | ␉} else {␊ |
1534 | ␉␉return false;␊ |
1535 | ␉}␊ |
1536 | }␊ |
1537 | |