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