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