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