1 /* shared.h - definitions used in all GRUB-specific code */ 2 /* 3 * GRUB -- GRand Unified Bootloader 4 * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 /* 21 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 22 * Use is subject to license terms. 23 */ 24 25 /* 26 * Generic defines to use anywhere 27 */ 28 29 #ifndef GRUB_SHARED_HEADER 30 #define GRUB_SHARED_HEADER 1 31 32 #include <config.h> 33 34 /* Add an underscore to a C symbol in assembler code if needed. */ 35 #ifdef HAVE_ASM_USCORE 36 # define EXT_C(sym) _ ## sym 37 #else 38 # define EXT_C(sym) sym 39 #endif 40 41 /* Maybe redirect memory requests through grub_scratch_mem. */ 42 #ifdef GRUB_UTIL 43 extern char *grub_scratch_mem; 44 # define RAW_ADDR(x) ((x) + (int) grub_scratch_mem) 45 # define RAW_SEG(x) (RAW_ADDR ((x) << 4) >> 4) 46 #else 47 # define RAW_ADDR(x) (x) 48 # define RAW_SEG(x) (x) 49 #endif 50 51 /* ZFS will use the top 4 Meg of physical memory (below 4Gig) for sratch */ 52 #define ZFS_SCRATCH_SIZE 0x400000 53 54 #ifndef MAXPATHLEN 55 #define MAXPATHLEN 1024 56 #endif 57 58 #define MAXNAMELEN 256 59 #define MIN(x, y) ((x) < (y) ? (x) : (y)) 60 61 /* Boot signature related defines for the findroot command */ 62 #define BOOTSIGN_DIR "/boot/grub/bootsign" 63 #define BOOTSIGN_ARGLEN (MAXNAMELEN + 10) /* (<sign>,0,d) */ 64 #define BOOTSIGN_LEN (sizeof (BOOTSIGN_DIR) + 1 + BOOTSIGN_ARGLEN) 65 #define BOOTSIGN_BACKUP "/etc/bootsign" 66 67 /* 68 * Integer sizes 69 */ 70 71 #define MAXINT 0x7FFFFFFF 72 #define MAXUINT 0xFFFFFFFF 73 74 /* Maximum command line size. Before you blindly increase this value, 75 see the comment in char_io.c (get_cmdline). */ 76 #define MAX_CMDLINE 1600 77 #define NEW_HEAPSIZE 1500 78 79 /* 512-byte scratch area */ 80 #define SCRATCHADDR RAW_ADDR (0x77e00) 81 #define SCRATCHSEG RAW_SEG (0x77e0) 82 83 /* 84 * This is the location of the raw device buffer. It is 31.5K 85 * in size. 86 */ 87 88 #define BUFFERLEN 0x7e00 89 #define BUFFERADDR RAW_ADDR (0x70000) 90 #define BUFFERSEG RAW_SEG (0x7000) 91 92 #define BOOT_PART_TABLE RAW_ADDR (0x07be) 93 94 /* 95 * BIOS disk defines 96 */ 97 #define BIOSDISK_READ 0x0 98 #define BIOSDISK_WRITE 0x1 99 #define BIOSDISK_ERROR_GEOMETRY 0x100 100 #define BIOSDISK_ERROR_SHORT_IO 0x101 101 #define BIOSDISK_FLAG_LBA_EXTENSION 0x1 102 #define BIOSDISK_FLAG_CDROM 0x2 103 104 /* 105 * This is the filesystem (not raw device) buffer. 106 * It is 32K in size, do not overrun! 107 */ 108 109 #define FSYS_BUFLEN 0x8000 110 #define FSYS_BUF RAW_ADDR (0x68000) 111 112 /* Command-line buffer for Multiboot kernels and modules. This area 113 includes the area into which Stage 1.5 and Stage 1 are loaded, but 114 that's no problem. */ 115 #define MB_CMDLINE_BUF RAW_ADDR (0x2000) 116 #define MB_CMDLINE_BUFLEN 0x6000 117 118 /* The buffer for the password. */ 119 #define PASSWORD_BUF RAW_ADDR (0x78000) 120 #define PASSWORD_BUFLEN 0x200 121 122 /* THe buffer for the filename of "/boot/grub/default". */ 123 #define DEFAULT_FILE_BUF (PASSWORD_BUF + PASSWORD_BUFLEN) 124 #define DEFAULT_FILE_BUFLEN 0x60 125 126 /* The buffer for the command-line. */ 127 #define CMDLINE_BUF (DEFAULT_FILE_BUF + DEFAULT_FILE_BUFLEN) 128 #define CMDLINE_BUFLEN MAX_CMDLINE 129 130 /* The kill buffer for the command-line. */ 131 #define KILL_BUF (CMDLINE_BUF + CMDLINE_BUFLEN) 132 #define KILL_BUFLEN MAX_CMDLINE 133 134 /* The history buffer for the command-line. */ 135 #define HISTORY_BUF (KILL_BUF + KILL_BUFLEN) 136 #define HISTORY_SIZE 5 137 #define HISTORY_BUFLEN (MAX_CMDLINE * HISTORY_SIZE) 138 139 /* The buffer for the completion. */ 140 #define COMPLETION_BUF (HISTORY_BUF + HISTORY_BUFLEN) 141 #define COMPLETION_BUFLEN MAX_CMDLINE 142 143 /* The buffer for the unique string. */ 144 #define UNIQUE_BUF (COMPLETION_BUF + COMPLETION_BUFLEN) 145 #define UNIQUE_BUFLEN MAX_CMDLINE 146 147 /* The buffer for the menu entries. */ 148 #define MENU_BUF (UNIQUE_BUF + UNIQUE_BUFLEN) 149 #define MENU_BUFLEN (0x8000 + PASSWORD_BUF - MENU_BUF) 150 151 /* The size of the drive map. */ 152 #define DRIVE_MAP_SIZE 8 153 154 /* The size of the key map. */ 155 #define KEY_MAP_SIZE 128 156 157 /* The size of the io map. */ 158 #define IO_MAP_SIZE 128 159 160 /* 161 * Linux setup parameters 162 */ 163 164 #define LINUX_MAGIC_SIGNATURE 0x53726448 /* "HdrS" */ 165 #define LINUX_DEFAULT_SETUP_SECTS 4 166 #define LINUX_FLAG_CAN_USE_HEAP 0x80 167 #define LINUX_INITRD_MAX_ADDRESS 0x38000000 168 #define LINUX_MAX_SETUP_SECTS 64 169 #define LINUX_BOOT_LOADER_TYPE 0x71 170 #define LINUX_HEAP_END_OFFSET (0x9000 - 0x200) 171 172 #define LINUX_BZIMAGE_ADDR RAW_ADDR (0x100000) 173 #define LINUX_ZIMAGE_ADDR RAW_ADDR (0x10000) 174 #define LINUX_OLD_REAL_MODE_ADDR RAW_ADDR (0x90000) 175 #define LINUX_SETUP_STACK 0x9000 176 177 #define LINUX_FLAG_BIG_KERNEL 0x1 178 179 /* Linux's video mode selection support. Actually I hate it! */ 180 #define LINUX_VID_MODE_NORMAL 0xFFFF 181 #define LINUX_VID_MODE_EXTENDED 0xFFFE 182 #define LINUX_VID_MODE_ASK 0xFFFD 183 184 #define LINUX_CL_OFFSET 0x9000 185 #define LINUX_CL_END_OFFSET 0x90FF 186 #define LINUX_SETUP_MOVE_SIZE 0x9100 187 #define LINUX_CL_MAGIC 0xA33F 188 189 /* 190 * General disk stuff 191 */ 192 193 #define SECTOR_SIZE 0x200 194 #define SECTOR_BITS 9 195 #define BIOS_FLAG_FIXED_DISK 0x80 196 197 #define BOOTSEC_LOCATION RAW_ADDR (0x7C00) 198 #define BOOTSEC_SIGNATURE 0xAA55 199 #define BOOTSEC_BPB_OFFSET 0x3 200 #define BOOTSEC_BPB_LENGTH 0x3B 201 #define BOOTSEC_BPB_SYSTEM_ID 0x3 202 #define BOOTSEC_BPB_HIDDEN_SECTORS 0x1C 203 #define BOOTSEC_PART_OFFSET 0x1BE 204 #define BOOTSEC_PART_LENGTH 0x40 205 #define BOOTSEC_SIG_OFFSET 0x1FE 206 #define BOOTSEC_LISTSIZE 8 207 208 /* Not bad, perhaps. */ 209 #define NETWORK_DRIVE 0x20 210 211 /* 212 * GRUB specific information 213 * (in LSB order) 214 */ 215 216 #include <stage1.h> 217 218 #define STAGE2_VER_MAJ_OFFS 0x6 219 #define STAGE2_INSTALLPART 0x8 220 #define STAGE2_SAVED_ENTRYNO 0xc 221 #define STAGE2_STAGE2_ID 0x10 222 #define STAGE2_FORCE_LBA 0x11 223 #define STAGE2_VER_STR_OFFS 0x12 224 225 /* Stage 2 identifiers */ 226 #define STAGE2_ID_STAGE2 0 227 #define STAGE2_ID_FFS_STAGE1_5 1 228 #define STAGE2_ID_E2FS_STAGE1_5 2 229 #define STAGE2_ID_FAT_STAGE1_5 3 230 #define STAGE2_ID_MINIX_STAGE1_5 4 231 #define STAGE2_ID_REISERFS_STAGE1_5 5 232 #define STAGE2_ID_VSTAFS_STAGE1_5 6 233 #define STAGE2_ID_JFS_STAGE1_5 7 234 #define STAGE2_ID_XFS_STAGE1_5 8 235 #define STAGE2_ID_ISO9660_STAGE1_5 9 236 #define STAGE2_ID_UFS2_STAGE1_5 10 237 #define STAGE2_ID_UFS_STAGE1_5 11 238 #define STAGE2_ID_ZFS_STAGE1_5 12 239 240 #ifndef STAGE1_5 241 # define STAGE2_ID STAGE2_ID_STAGE2 242 #else 243 # if defined(FSYS_FFS) 244 # define STAGE2_ID STAGE2_ID_FFS_STAGE1_5 245 # elif defined(FSYS_EXT2FS) 246 # define STAGE2_ID STAGE2_ID_E2FS_STAGE1_5 247 # elif defined(FSYS_FAT) 248 # define STAGE2_ID STAGE2_ID_FAT_STAGE1_5 249 # elif defined(FSYS_MINIX) 250 # define STAGE2_ID STAGE2_ID_MINIX_STAGE1_5 251 # elif defined(FSYS_REISERFS) 252 # define STAGE2_ID STAGE2_ID_REISERFS_STAGE1_5 253 # elif defined(FSYS_VSTAFS) 254 # define STAGE2_ID STAGE2_ID_VSTAFS_STAGE1_5 255 # elif defined(FSYS_JFS) 256 # define STAGE2_ID STAGE2_ID_JFS_STAGE1_5 257 # elif defined(FSYS_XFS) 258 # define STAGE2_ID STAGE2_ID_XFS_STAGE1_5 259 # elif defined(FSYS_ISO9660) 260 # define STAGE2_ID STAGE2_ID_ISO9660_STAGE1_5 261 # elif defined(FSYS_UFS2) 262 # define STAGE2_ID STAGE2_ID_UFS2_STAGE1_5 263 # elif defined(FSYS_UFS) 264 # define STAGE2_ID STAGE2_ID_UFS_STAGE1_5 265 # elif defined(FSYS_ZFS) 266 # define STAGE2_ID STAGE2_ID_ZFS_STAGE1_5 267 # else 268 # error "unknown Stage 2" 269 # endif 270 #endif 271 272 /* 273 * defines for use when switching between real and protected mode 274 */ 275 276 #define CR0_PE_ON 0x1 277 #define CR0_PE_OFF 0xfffffffe 278 #define PROT_MODE_CSEG 0x8 279 #define PROT_MODE_DSEG 0x10 280 #define PSEUDO_RM_CSEG 0x18 281 #define PSEUDO_RM_DSEG 0x20 282 #define STACKOFF (0x2000 - 0x10) 283 #define PROTSTACKINIT (FSYS_BUF - 0x10) 284 285 286 /* 287 * Assembly code defines 288 * 289 * "EXT_C" is assumed to be defined in the Makefile by the configure 290 * command. 291 */ 292 293 #define ENTRY(x) .globl EXT_C(x) ; EXT_C(x): 294 #define VARIABLE(x) ENTRY(x) 295 296 297 #define K_RDWR 0x60 /* keyboard data & cmds (read/write) */ 298 #define K_STATUS 0x64 /* keyboard status */ 299 #define K_CMD 0x64 /* keybd ctlr command (write-only) */ 300 301 #define K_OBUF_FUL 0x01 /* output buffer full */ 302 #define K_IBUF_FUL 0x02 /* input buffer full */ 303 304 #define KC_CMD_WIN 0xd0 /* read output port */ 305 #define KC_CMD_WOUT 0xd1 /* write output port */ 306 #define KB_OUTPUT_MASK 0xdd /* enable output buffer full interrupt 307 enable data line 308 enable clock line */ 309 #define KB_A20_ENABLE 0x02 310 311 /* Codes for getchar. */ 312 #define ASCII_CHAR(x) ((x) & 0xFF) 313 #if !defined(GRUB_UTIL) || !defined(HAVE_LIBCURSES) 314 # define KEY_LEFT 0x4B00 315 # define KEY_RIGHT 0x4D00 316 # define KEY_UP 0x4800 317 # define KEY_DOWN 0x5000 318 # define KEY_IC 0x5200 /* insert char */ 319 # define KEY_DC 0x5300 /* delete char */ 320 # define KEY_BACKSPACE 0x0008 321 # define KEY_HOME 0x4700 322 # define KEY_END 0x4F00 323 # define KEY_NPAGE 0x5100 324 # define KEY_PPAGE 0x4900 325 # define A_NORMAL 0x7 326 # define A_REVERSE 0x70 327 #elif defined(HAVE_NCURSES_CURSES_H) 328 # include <ncurses/curses.h> 329 #elif defined(HAVE_NCURSES_H) 330 # include <ncurses.h> 331 #elif defined(HAVE_CURSES_H) 332 # include <curses.h> 333 #endif 334 335 /* In old BSD curses, A_NORMAL and A_REVERSE are not defined, so we 336 define them here if they are undefined. */ 337 #ifndef A_NORMAL 338 # define A_NORMAL 0 339 #endif /* ! A_NORMAL */ 340 #ifndef A_REVERSE 341 # ifdef A_STANDOUT 342 # define A_REVERSE A_STANDOUT 343 # else /* ! A_STANDOUT */ 344 # define A_REVERSE 0 345 # endif /* ! A_STANDOUT */ 346 #endif /* ! A_REVERSE */ 347 348 /* Define ACS_* ourselves, since the definitions are not consistent among 349 various curses implementations. */ 350 #undef ACS_ULCORNER 351 #undef ACS_URCORNER 352 #undef ACS_LLCORNER 353 #undef ACS_LRCORNER 354 #undef ACS_HLINE 355 #undef ACS_VLINE 356 #undef ACS_LARROW 357 #undef ACS_RARROW 358 #undef ACS_UARROW 359 #undef ACS_DARROW 360 361 #define ACS_ULCORNER '+' 362 #define ACS_URCORNER '+' 363 #define ACS_LLCORNER '+' 364 #define ACS_LRCORNER '+' 365 #define ACS_HLINE '-' 366 #define ACS_VLINE '|' 367 #define ACS_LARROW '<' 368 #define ACS_RARROW '>' 369 #define ACS_UARROW '^' 370 #define ACS_DARROW 'v' 371 372 /* Special graphics characters for IBM displays. */ 373 #define DISP_UL 218 374 #define DISP_UR 191 375 #define DISP_LL 192 376 #define DISP_LR 217 377 #define DISP_HORIZ 196 378 #define DISP_VERT 179 379 #define DISP_LEFT 0x1b 380 #define DISP_RIGHT 0x1a 381 #define DISP_UP 0x18 382 #define DISP_DOWN 0x19 383 384 /* Remap some libc-API-compatible function names so that we prevent 385 circularararity. */ 386 #ifndef WITHOUT_LIBC_STUBS 387 #define memmove grub_memmove 388 #define memcpy grub_memmove /* we don't need a separate memcpy */ 389 #define memset grub_memset 390 #undef isspace 391 #define isspace grub_isspace 392 #define printf grub_printf 393 #define sprintf grub_sprintf 394 #undef putchar 395 #define putchar grub_putchar 396 #define strncat grub_strncat 397 #define strstr grub_strstr 398 #define memcmp grub_memcmp 399 #define strcmp grub_strcmp 400 #define tolower grub_tolower 401 #define strlen grub_strlen 402 #define strcpy grub_strcpy 403 #endif /* WITHOUT_LIBC_STUBS */ 404 405 #define UNDI_STACK (512 + 64) << 10 406 #define UNDI_STACK_SEG (UNDI_STACK >> 4) /* PXE load GRUB here */ 407 #define UNDI_STACK_OFF (0x10000 - 0x10) 408 409 #ifndef ASM_FILE 410 /* 411 * Below this should be ONLY defines and other constructs for C code. 412 */ 413 414 /* multiboot stuff */ 415 416 #include "mb_header.h" 417 #include "mb_info.h" 418 419 /* For the Linux/i386 boot protocol version 2.03. */ 420 struct linux_kernel_header 421 { 422 char code1[0x0020]; 423 unsigned short cl_magic; /* Magic number 0xA33F */ 424 unsigned short cl_offset; /* The offset of command line */ 425 char code2[0x01F1 - 0x0020 - 2 - 2]; 426 unsigned char setup_sects; /* The size of the setup in sectors */ 427 unsigned short root_flags; /* If the root is mounted readonly */ 428 unsigned short syssize; /* obsolete */ 429 unsigned short swap_dev; /* obsolete */ 430 unsigned short ram_size; /* obsolete */ 431 unsigned short vid_mode; /* Video mode control */ 432 unsigned short root_dev; /* Default root device number */ 433 unsigned short boot_flag; /* 0xAA55 magic number */ 434 unsigned short jump; /* Jump instruction */ 435 unsigned long header; /* Magic signature "HdrS" */ 436 unsigned short version; /* Boot protocol version supported */ 437 unsigned long realmode_swtch; /* Boot loader hook */ 438 unsigned long start_sys; /* Points to kernel version string */ 439 unsigned char type_of_loader; /* Boot loader identifier */ 440 unsigned char loadflags; /* Boot protocol option flags */ 441 unsigned short setup_move_size; /* Move to high memory size */ 442 unsigned long code32_start; /* Boot loader hook */ 443 unsigned long ramdisk_image; /* initrd load address */ 444 unsigned long ramdisk_size; /* initrd size */ 445 unsigned long bootsect_kludge; /* obsolete */ 446 unsigned short heap_end_ptr; /* Free memory after setup end */ 447 unsigned short pad1; /* Unused */ 448 char *cmd_line_ptr; /* Points to the kernel command line */ 449 unsigned long initrd_addr_max; /* The highest address of initrd */ 450 } __attribute__ ((packed)); 451 452 /* Memory map address range descriptor used by GET_MMAP_ENTRY. */ 453 struct mmar_desc 454 { 455 unsigned long desc_len; /* Size of this descriptor. */ 456 unsigned long long addr; /* Base address. */ 457 unsigned long long length; /* Length in bytes. */ 458 unsigned long type; /* Type of address range. */ 459 } __attribute__ ((packed)); 460 461 /* VBE controller information. */ 462 struct vbe_controller 463 { 464 unsigned char signature[4]; 465 unsigned short version; 466 unsigned long oem_string; 467 unsigned long capabilities; 468 unsigned long video_mode; 469 unsigned short total_memory; 470 unsigned short oem_software_rev; 471 unsigned long oem_vendor_name; 472 unsigned long oem_product_name; 473 unsigned long oem_product_rev; 474 unsigned char reserved[222]; 475 unsigned char oem_data[256]; 476 } __attribute__ ((packed)); 477 478 /* VBE mode information. */ 479 struct vbe_mode 480 { 481 unsigned short mode_attributes; 482 unsigned char win_a_attributes; 483 unsigned char win_b_attributes; 484 unsigned short win_granularity; 485 unsigned short win_size; 486 unsigned short win_a_segment; 487 unsigned short win_b_segment; 488 unsigned long win_func; 489 unsigned short bytes_per_scanline; 490 491 /* >=1.2 */ 492 unsigned short x_resolution; 493 unsigned short y_resolution; 494 unsigned char x_char_size; 495 unsigned char y_char_size; 496 unsigned char number_of_planes; 497 unsigned char bits_per_pixel; 498 unsigned char number_of_banks; 499 unsigned char memory_model; 500 unsigned char bank_size; 501 unsigned char number_of_image_pages; 502 unsigned char reserved0; 503 504 /* direct color */ 505 unsigned char red_mask_size; 506 unsigned char red_field_position; 507 unsigned char green_mask_size; 508 unsigned char green_field_position; 509 unsigned char blue_mask_size; 510 unsigned char blue_field_position; 511 unsigned char reserved_mask_size; 512 unsigned char reserved_field_position; 513 unsigned char direct_color_mode_info; 514 515 /* >=2.0 */ 516 unsigned long phys_base; 517 unsigned long reserved1; 518 unsigned short reversed2; 519 520 /* >=3.0 */ 521 unsigned short linear_bytes_per_scanline; 522 unsigned char banked_number_of_image_pages; 523 unsigned char linear_number_of_image_pages; 524 unsigned char linear_red_mask_size; 525 unsigned char linear_red_field_position; 526 unsigned char linear_green_mask_size; 527 unsigned char linear_green_field_position; 528 unsigned char linear_blue_mask_size; 529 unsigned char linear_blue_field_position; 530 unsigned char linear_reserved_mask_size; 531 unsigned char linear_reserved_field_position; 532 unsigned long max_pixel_clock; 533 534 unsigned char reserved3[189]; 535 } __attribute__ ((packed)); 536 537 538 #undef NULL 539 #define NULL ((void *) 0) 540 541 /* Error codes (descriptions are in common.c) */ 542 typedef enum 543 { 544 ERR_NONE = 0, 545 ERR_BAD_FILENAME, 546 ERR_BAD_FILETYPE, 547 ERR_BAD_GZIP_DATA, 548 ERR_BAD_GZIP_HEADER, 549 ERR_BAD_PART_TABLE, 550 ERR_BAD_VERSION, 551 ERR_BELOW_1MB, 552 ERR_BOOT_COMMAND, 553 ERR_BOOT_FAILURE, 554 ERR_BOOT_FEATURES, 555 ERR_DEV_FORMAT, 556 ERR_DEV_VALUES, 557 ERR_EXEC_FORMAT, 558 ERR_FILELENGTH, 559 ERR_FILE_NOT_FOUND, 560 ERR_FSYS_CORRUPT, 561 ERR_FSYS_MOUNT, 562 ERR_GEOM, 563 ERR_NEED_LX_KERNEL, 564 ERR_NEED_MB_KERNEL, 565 ERR_NO_DISK, 566 ERR_NO_PART, 567 ERR_NUMBER_PARSING, 568 ERR_OUTSIDE_PART, 569 ERR_READ, 570 ERR_SYMLINK_LOOP, 571 ERR_UNRECOGNIZED, 572 ERR_WONT_FIT, 573 ERR_WRITE, 574 ERR_BAD_ARGUMENT, 575 ERR_UNALIGNED, 576 ERR_PRIVILEGED, 577 ERR_DEV_NEED_INIT, 578 ERR_NO_DISK_SPACE, 579 ERR_NUMBER_OVERFLOW, 580 ERR_BAD_GZIP_CRC, 581 ERR_FILESYSTEM_NOT_FOUND, 582 ERR_NO_BOOTPATH, 583 ERR_NEWER_VERSION, 584 ERR_NOTXPM, 585 ERR_TOOMANYCOLORS, 586 ERR_CORRUPTXPM, 587 588 MAX_ERR_NUM 589 } grub_error_t; 590 591 typedef enum 592 { 593 CFG_HARDCODED, 594 CFG_150, 595 CFG_MAC, 596 CFG_BOOTFILE 597 } configfile_origin_t; 598 599 extern unsigned long install_partition; 600 extern unsigned long boot_drive; 601 extern unsigned long install_second_sector; 602 extern struct apm_info apm_bios_info; 603 extern unsigned long boot_part_addr; 604 extern int saved_entryno; 605 extern unsigned char force_lba; 606 extern char version_string[]; 607 extern char config_file[]; 608 extern char *bootfile; 609 extern configfile_origin_t configfile_origin; 610 extern unsigned char md5hash[]; 611 extern char pkg_version[]; 612 extern unsigned long linux_text_len; 613 extern char *linux_data_tmp_addr; 614 extern char *linux_data_real_addr; 615 616 #ifdef GRUB_UTIL 617 /* If not using config file, this variable is set to zero, 618 otherwise non-zero. */ 619 extern int use_config_file; 620 /* If using the preset menu, this variable is set to non-zero, 621 otherwise zero. */ 622 extern int use_preset_menu; 623 /* If not using curses, this variable is set to zero, otherwise non-zero. */ 624 extern int use_curses; 625 /* The flag for verbose messages. */ 626 extern int verbose; 627 /* The flag for read-only. */ 628 extern int read_only; 629 /* The number of floppies to be probed. */ 630 extern int floppy_disks; 631 /* The map between BIOS drives and UNIX device file names. */ 632 extern char **device_map; 633 /* The filename which stores the information about a device map. */ 634 extern char *device_map_file; 635 /* The array of geometries. */ 636 extern struct geometry *disks; 637 /* Assign DRIVE to a device name DEVICE. */ 638 extern void assign_device_name (int drive, const char *device); 639 #endif 640 641 #ifndef STAGE1_5 642 /* GUI interface variables. */ 643 # define MAX_FALLBACK_ENTRIES 8 644 extern int fallback_entries[MAX_FALLBACK_ENTRIES]; 645 extern int fallback_entryno; 646 extern int default_entry; 647 extern int current_entryno; 648 649 /* The constants for password types. */ 650 typedef enum 651 { 652 PASSWORD_PLAIN, 653 PASSWORD_MD5, 654 PASSWORD_UNSUPPORTED 655 } 656 password_t; 657 658 extern char *password; 659 extern password_t password_type; 660 extern int auth; 661 extern char commands[]; 662 663 /* For `more'-like feature. */ 664 extern int max_lines; 665 extern int count_lines; 666 extern int use_pager; 667 #endif 668 669 #ifndef NO_DECOMPRESSION 670 extern int no_decompression; 671 extern int compressed_file; 672 #endif 673 674 /* instrumentation variables */ 675 extern void (*disk_read_hook) (unsigned int, int, int); 676 extern void (*disk_read_func) (unsigned int, int, int); 677 678 #ifndef STAGE1_5 679 /* The flag for debug mode. */ 680 extern int debug; 681 #endif /* STAGE1_5 */ 682 683 extern unsigned long current_drive; 684 extern unsigned long current_partition; 685 extern char current_rootpool[MAXNAMELEN]; 686 extern char current_bootfs[MAXNAMELEN]; 687 extern unsigned long long current_bootfs_obj; 688 extern char current_bootpath[MAXPATHLEN]; 689 extern char current_devid[MAXPATHLEN]; 690 extern int is_zfs_mount; 691 extern unsigned long best_drive; 692 extern unsigned long best_part; 693 extern int find_best_root; 694 695 extern int fsys_type; 696 697 /* The information for a disk geometry. The CHS information is only for 698 DOS/Partition table compatibility, and the real number of sectors is 699 stored in TOTAL_SECTORS. */ 700 struct geometry 701 { 702 /* The number of cylinders */ 703 unsigned long cylinders; 704 /* The number of heads */ 705 unsigned long heads; 706 /* The number of sectors */ 707 unsigned long sectors; 708 /* The total number of sectors */ 709 unsigned long long total_sectors; 710 /* Device sector size */ 711 unsigned long sector_size; 712 /* Flags */ 713 unsigned long flags; 714 }; 715 716 extern unsigned long part_start; 717 extern unsigned long part_length; 718 719 extern int current_slice; 720 721 extern int buf_drive; 722 #define BUF_CACHE_INVALID 0xffffffff 723 extern unsigned int buf_track; 724 extern struct geometry buf_geom; 725 726 /* these are the current file position and maximum file position */ 727 extern int filepos; 728 extern int filemax; 729 730 /* 731 * Common BIOS/boot data. 732 */ 733 734 extern struct multiboot_info mbi; 735 extern unsigned long saved_drive; 736 extern unsigned long saved_partition; 737 extern unsigned long cdrom_drive; 738 #ifndef STAGE1_5 739 #ifdef SOLARIS_NETBOOT 740 extern unsigned long dhcpack_length; 741 extern unsigned long dhcpack_buf; 742 #endif 743 extern unsigned long saved_mem_upper; 744 extern unsigned long extended_memory; 745 #endif 746 747 /* 748 * Error variables. 749 */ 750 751 extern grub_error_t errnum; 752 extern char *err_list[]; 753 754 /* don't print geeky noise */ 755 typedef enum 756 { 757 SILENT, 758 VERBOSE, 759 DEFER_SILENT, 760 DEFER_VERBOSE 761 } silent_status; 762 763 /* one screen worth of messages 80x24 = 1920 chars -- more with newlines */ 764 #define SCREENBUF 2000 765 766 struct silentbuf { 767 silent_status status; 768 int looped; 769 char buffer[SCREENBUF]; 770 char *buffer_start; 771 }; 772 773 extern struct silentbuf silent; 774 extern int reset_term; 775 776 /* Simplify declaration of entry_addr. */ 777 typedef void (*entry_func) (int, int, int, int, int, int) 778 __attribute__ ((noreturn)); 779 780 extern entry_func entry_addr; 781 782 /* Enter the stage1.5/stage2 C code after the stack is set up. */ 783 void cmain (void); 784 785 /* Halt the processor (called after an unrecoverable error). */ 786 void stop (void) __attribute__ ((noreturn)); 787 788 /* Reboot the system. */ 789 void grub_reboot (void) __attribute__ ((noreturn)); 790 791 /* Halt the system, using APM if possible. If NO_APM is true, don't use 792 APM even if it is available. */ 793 void grub_halt (int no_apm) __attribute__ ((noreturn)); 794 795 /* Copy MAP to the drive map and set up int13_handler. */ 796 void set_int13_handler (unsigned short *map); 797 798 /* Set up int15_handler. */ 799 void set_int15_handler (void); 800 801 /* Restore the original int15 handler. */ 802 void unset_int15_handler (void); 803 804 /* Track the int13 handler to probe I/O address space. */ 805 void track_int13 (int drive); 806 807 /* The key map. */ 808 extern unsigned short bios_key_map[]; 809 extern unsigned short ascii_key_map[]; 810 extern unsigned short io_map[]; 811 812 /* calls for direct boot-loader chaining */ 813 void chain_stage1 (unsigned long segment, unsigned long offset, 814 unsigned long part_table_addr) 815 __attribute__ ((noreturn)); 816 void chain_stage2 (unsigned long segment, unsigned long offset, 817 int second_sector) 818 __attribute__ ((noreturn)); 819 820 /* do some funky stuff, then boot linux */ 821 void linux_boot (void) __attribute__ ((noreturn)); 822 823 /* do some funky stuff, then boot bzImage linux */ 824 void big_linux_boot (void) __attribute__ ((noreturn)); 825 826 /* booting a multiboot executable */ 827 void multi_boot (int start, int mb_info) __attribute__ ((noreturn)); 828 829 /* If LINEAR is nonzero, then set the Intel processor to linear mode. 830 Otherwise, bit 20 of all memory accesses is always forced to zero, 831 causing a wraparound effect for bugwards compatibility with the 832 8086 CPU. */ 833 void gateA20 (int linear); 834 835 /* memory probe routines */ 836 int get_memsize (int type); 837 int get_eisamemsize (void); 838 839 /* Fetch the next entry in the memory map and return the continuation 840 value. DESC is a pointer to the descriptor buffer, and CONT is the 841 previous continuation value (0 to get the first entry in the 842 map). */ 843 int get_mmap_entry (struct mmar_desc *desc, int cont); 844 845 /* Get the linear address of a ROM configuration table. Return zero, 846 if fails. */ 847 unsigned long get_rom_config_table (void); 848 849 /* Get APM BIOS information. */ 850 void get_apm_info (void); 851 852 /* Get VBE controller information. */ 853 int get_vbe_controller_info (struct vbe_controller *controller); 854 855 /* Get VBE mode information. */ 856 int get_vbe_mode_info (int mode_number, struct vbe_mode *mode); 857 858 /* Set VBE mode. */ 859 int set_vbe_mode (int mode_number); 860 861 /* Return the data area immediately following our code. */ 862 int get_code_end (void); 863 864 /* low-level timing info */ 865 int getrtsecs (void); 866 int currticks (void); 867 868 /* Clear the screen. */ 869 void cls (void); 870 871 /* Turn on/off cursor. */ 872 int setcursor (int on); 873 874 /* Get the current cursor position (where 0,0 is the top left hand 875 corner of the screen). Returns packed values, (RET >> 8) is x, 876 (RET & 0xff) is y. */ 877 int getxy (void); 878 879 /* Set the cursor position. */ 880 void gotoxy (int x, int y); 881 882 /* Displays an ASCII character. IBM displays will translate some 883 characters to special graphical ones (see the DISP_* constants). */ 884 void grub_putchar (int c); 885 886 /* Wait for a keypress, and return its packed BIOS/ASCII key code. 887 Use ASCII_CHAR(ret) to extract the ASCII code. */ 888 int getkey (void); 889 890 /* Like GETKEY, but doesn't block, and returns -1 if no keystroke is 891 available. */ 892 int checkkey (void); 893 894 /* Low-level disk I/O */ 895 int get_diskinfo (int drive, struct geometry *geometry); 896 int biosdisk (int subfunc, int drive, struct geometry *geometry, 897 unsigned int sector, int nsec, int segment); 898 void stop_floppy (void); 899 900 /* Command-line interface functions. */ 901 #ifndef STAGE1_5 902 903 /* The flags for the builtins. */ 904 #define BUILTIN_CMDLINE 0x1 /* Run in the command-line. */ 905 #define BUILTIN_MENU 0x2 /* Run in the menu. */ 906 #define BUILTIN_TITLE 0x4 /* Only for the command title. */ 907 #define BUILTIN_SCRIPT 0x8 /* Run in the script. */ 908 #define BUILTIN_NO_ECHO 0x10 /* Don't print command on booting. */ 909 #define BUILTIN_HELP_LIST 0x20 /* Show help in listing. */ 910 911 /* The table for a builtin. */ 912 struct builtin 913 { 914 /* The command name. */ 915 char *name; 916 /* The callback function. */ 917 int (*func) (char *, int); 918 /* The combination of the flags defined above. */ 919 int flags; 920 /* The short version of the documentation. */ 921 char *short_doc; 922 /* The long version of the documentation. */ 923 char *long_doc; 924 }; 925 926 /* All the builtins are registered in this. */ 927 extern struct builtin *builtin_table[]; 928 929 /* The constants for kernel types. */ 930 typedef enum 931 { 932 KERNEL_TYPE_NONE, /* None is loaded. */ 933 KERNEL_TYPE_MULTIBOOT, /* Multiboot. */ 934 KERNEL_TYPE_LINUX, /* Linux. */ 935 KERNEL_TYPE_BIG_LINUX, /* Big Linux. */ 936 KERNEL_TYPE_FREEBSD, /* FreeBSD. */ 937 KERNEL_TYPE_NETBSD, /* NetBSD. */ 938 KERNEL_TYPE_CHAINLOADER /* Chainloader. */ 939 } 940 kernel_t; 941 942 extern kernel_t kernel_type; 943 extern int show_menu; 944 extern int grub_timeout; 945 946 void init_builtins (void); 947 void init_config (void); 948 char *skip_to (int after_equal, char *cmdline); 949 struct builtin *find_command (char *command); 950 void print_cmdline_message (int forever); 951 void enter_cmdline (char *heap, int forever); 952 int run_script (char *script, char *heap); 953 #endif 954 955 /* C library replacement functions with identical semantics. */ 956 void grub_printf (const char *format,...); 957 int grub_sprintf (char *buffer, const char *format, ...); 958 int grub_tolower (int c); 959 int grub_isspace (int c); 960 int grub_strncat (char *s1, const char *s2, int n); 961 void grub_memcpy(void *dest, const void *src, int len); 962 void *grub_memmove (void *to, const void *from, int len); 963 void *grub_memset (void *start, int c, int len); 964 int grub_strncat (char *s1, const char *s2, int n); 965 char *grub_strstr (const char *s1, const char *s2); 966 int grub_memcmp (const char *s1, const char *s2, int n); 967 int grub_strcmp (const char *s1, const char *s2); 968 int grub_strlen (const char *str); 969 char *grub_strcpy (char *dest, const char *src); 970 char *grub_strchr (char *str, char c); 971 972 void noisy_printf (const char *format,...); 973 974 #ifndef GRUB_UTIL 975 typedef unsigned long grub_jmp_buf[6]; 976 #else 977 /* In the grub shell, use the libc jmp_buf instead. */ 978 # include <setjmp.h> 979 # define grub_jmp_buf jmp_buf 980 #endif 981 982 #ifdef GRUB_UTIL 983 # define grub_setjmp setjmp 984 # define grub_longjmp longjmp 985 #else /* ! GRUB_UTIL */ 986 int grub_setjmp (grub_jmp_buf env); 987 void grub_longjmp (grub_jmp_buf env, int val); 988 #endif /* ! GRUB_UTIL */ 989 990 /* The environment for restarting Stage 2. */ 991 extern grub_jmp_buf restart_env; 992 /* The environment for restarting the command-line interface. */ 993 extern grub_jmp_buf restart_cmdline_env; 994 995 /* misc */ 996 void init_page (void); 997 void print_error (void); 998 char *convert_to_ascii (char *buf, int c, ...); 999 int get_cmdline (char *prompt, char *cmdline, int maxlen, 1000 int echo_char, int history); 1001 int substring (const char *s1, const char *s2); 1002 int nul_terminate (char *str); 1003 int get_based_digit (int c, int base); 1004 int safe_parse_maxint (char **str_ptr, int *myint_ptr); 1005 int memcheck (unsigned long start, unsigned long len); 1006 void grub_putstr (const char *str); 1007 1008 #ifndef NO_DECOMPRESSION 1009 /* Compression support. */ 1010 int gunzip_test_header (void); 1011 int gunzip_read (char *buf, int len); 1012 #endif /* NO_DECOMPRESSION */ 1013 1014 int rawread (int drive, unsigned int sector, int byte_offset, int byte_len, 1015 char *buf); 1016 int devread (unsigned int sector, int byte_offset, int byte_len, char *buf); 1017 int rawwrite (int drive, unsigned int sector, char *buf); 1018 int devwrite (unsigned int sector, int sector_len, char *buf); 1019 1020 /* Parse a device string and initialize the global parameters. */ 1021 char *set_device (char *device); 1022 int open_device (void); 1023 int real_open_partition (int flags); 1024 int open_partition (void); 1025 int next_partition (unsigned long drive, unsigned long dest, 1026 unsigned long *partition, int *type, 1027 unsigned long *start, unsigned long *len, 1028 unsigned long *offset, int *entry, 1029 unsigned long *ext_offset, char *buf); 1030 1031 /* Sets device to the one represented by the SAVED_* parameters. */ 1032 int make_saved_active (void); 1033 1034 /* Set or clear the current root partition's hidden flag. */ 1035 int set_partition_hidden_flag (int hidden); 1036 1037 /* Open a file or directory on the active device, using GRUB's 1038 internal filesystem support. */ 1039 int grub_open (char *filename); 1040 1041 /* Read LEN bytes into BUF from the file that was opened with 1042 GRUB_OPEN. If LEN is -1, read all the remaining data in the file. */ 1043 int grub_read (char *buf, int len); 1044 1045 /* Reposition a file offset. */ 1046 int grub_seek (int offset); 1047 1048 /* Close a file. */ 1049 void grub_close (void); 1050 1051 /* List the contents of the directory that was opened with GRUB_OPEN, 1052 printing all completions. */ 1053 int dir (char *dirname); 1054 1055 int set_bootdev (int hdbias); 1056 1057 /* Display statistics on the current active device. */ 1058 void print_fsys_type (void); 1059 1060 /* Display device and filename completions. */ 1061 void print_a_completion (char *filename); 1062 int print_completions (int is_filename, int is_completion); 1063 1064 /* Copies the current partition data to the desired address. */ 1065 void copy_current_part_entry (char *buf); 1066 1067 #ifndef STAGE1_5 1068 void bsd_boot (kernel_t type, int bootdev, char *arg) 1069 __attribute__ ((noreturn)); 1070 1071 /* Define flags for load_image here. */ 1072 /* Don't pass a Linux's mem option automatically. */ 1073 #define KERNEL_LOAD_NO_MEM_OPTION (1 << 0) 1074 1075 kernel_t load_image (char *kernel, char *arg, kernel_t suggested_type, 1076 unsigned long load_flags); 1077 1078 int load_module (char *module, char *arg); 1079 int load_initrd (char *initrd); 1080 1081 int check_password(char *entered, char* expected, password_t type); 1082 #endif 1083 1084 void init_bios_info (void); 1085 1086 #endif /* ASM_FILE */ 1087 1088 #endif /* ! GRUB_SHARED_HEADER */ 1089