Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazi/i386/boot2/options.c

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

Archive Download this file

Revision: 515