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