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