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