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