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