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