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 
568   MAX_ERR_NUM
569 } grub_error_t;
570 
571 extern unsigned long install_partition;
572 extern unsigned long boot_drive;
573 extern unsigned long install_second_sector;
574 extern struct apm_info apm_bios_info;
575 extern unsigned long boot_part_addr;
576 extern int saved_entryno;
577 extern unsigned char force_lba;
578 extern char version_string[];
579 extern char config_file[];
580 extern unsigned long linux_text_len;
581 extern char *linux_data_tmp_addr;
582 extern char *linux_data_real_addr;
583 
584 #ifdef GRUB_UTIL
585 /* If not using config file, this variable is set to zero,
586    otherwise non-zero.  */
587 extern int use_config_file;
588 /* If using the preset menu, this variable is set to non-zero,
589    otherwise zero.  */
590 extern int use_preset_menu;
591 /* If not using curses, this variable is set to zero, otherwise non-zero.  */
592 extern int use_curses;
593 /* The flag for verbose messages.  */
594 extern int verbose;
595 /* The flag for read-only.  */
596 extern int read_only;
597 /* The number of floppies to be probed.  */
598 extern int floppy_disks;
599 /* The map between BIOS drives and UNIX device file names.  */
600 extern char **device_map;
601 /* The filename which stores the information about a device map.  */
602 extern char *device_map_file;
603 /* The array of geometries.  */
604 extern struct geometry *disks;
605 /* Assign DRIVE to a device name DEVICE.  */
606 extern void assign_device_name (int drive, const char *device);
607 #endif
608 
609 #ifndef STAGE1_5
610 /* GUI interface variables. */
611 # define MAX_FALLBACK_ENTRIES	8
612 extern int fallback_entries[MAX_FALLBACK_ENTRIES];
613 extern int fallback_entryno;
614 extern int default_entry;
615 extern int current_entryno;
616 
617 /* The constants for password types.  */
618 typedef enum
619 {
620   PASSWORD_PLAIN,
621   PASSWORD_MD5,
622   PASSWORD_UNSUPPORTED
623 }
624 password_t;
625 
626 extern char *password;
627 extern password_t password_type;
628 extern int auth;
629 extern char commands[];
630 
631 /* For `more'-like feature.  */
632 extern int max_lines;
633 extern int count_lines;
634 extern int use_pager;
635 #endif
636 
637 #ifndef NO_DECOMPRESSION
638 extern int no_decompression;
639 extern int compressed_file;
640 #endif
641 
642 /* instrumentation variables */
643 extern void (*disk_read_hook) (int, int, int);
644 extern void (*disk_read_func) (int, int, int);
645 
646 #ifndef STAGE1_5
647 /* The flag for debug mode.  */
648 extern int debug;
649 #endif /* STAGE1_5 */
650 
651 extern unsigned long current_drive;
652 extern unsigned long current_partition;
653 extern char current_rootpool[MAXNAMELEN];
654 extern char current_bootfs[MAXNAMELEN];
655 extern unsigned long long current_bootfs_obj;
656 extern int is_zfs_mount;
657 
658 extern int fsys_type;
659 
660 /* The information for a disk geometry. The CHS information is only for
661    DOS/Partition table compatibility, and the real number of sectors is
662    stored in TOTAL_SECTORS.  */
663 struct geometry
664 {
665   /* The number of cylinders */
666   unsigned long cylinders;
667   /* The number of heads */
668   unsigned long heads;
669   /* The number of sectors */
670   unsigned long sectors;
671   /* The total number of sectors */
672   unsigned long total_sectors;
673   /* Device sector size */
674   unsigned long sector_size;
675   /* Flags */
676   unsigned long flags;
677 };
678 
679 extern unsigned long part_start;
680 extern unsigned long part_length;
681 
682 extern int current_slice;
683 
684 extern int buf_drive;
685 extern int buf_track;
686 extern struct geometry buf_geom;
687 
688 /* these are the current file position and maximum file position */
689 extern int filepos;
690 extern int filemax;
691 
692 /*
693  *  Common BIOS/boot data.
694  */
695 
696 extern struct multiboot_info mbi;
697 extern unsigned long saved_drive;
698 extern unsigned long saved_partition;
699 extern unsigned long cdrom_drive;
700 #ifndef STAGE1_5
701 #ifdef SOLARIS_NETBOOT
702 extern unsigned long dhcpack_length;
703 extern unsigned long dhcpack_buf;
704 #endif
705 extern unsigned long saved_mem_upper;
706 extern unsigned long extended_memory;
707 #endif
708 
709 /*
710  *  Error variables.
711  */
712 
713 extern grub_error_t errnum;
714 extern char *err_list[];
715 
716 /* don't print geeky noise */
717 typedef enum
718 {
719   SILENT,
720   VERBOSE,
721   DEFER_SILENT,
722   DEFER_VERBOSE
723 } silent_status;
724 
725 /* one screen worth of messages 80x24 = 1920 chars -- more with newlines */
726 #define	SCREENBUF 2000
727 
728 struct silentbuf {
729 	silent_status status;
730 	int looped;
731 	char buffer[SCREENBUF];
732 	char *buffer_start;
733 };
734 
735 extern struct silentbuf silent;
736 extern int reset_term;
737 
738 /* Simplify declaration of entry_addr. */
739 typedef void (*entry_func) (int, int, int, int, int, int)
740      __attribute__ ((noreturn));
741 
742 extern entry_func entry_addr;
743 
744 /* Enter the stage1.5/stage2 C code after the stack is set up. */
745 void cmain (void);
746 
747 /* Halt the processor (called after an unrecoverable error). */
748 void stop (void) __attribute__ ((noreturn));
749 
750 /* Reboot the system.  */
751 void grub_reboot (void) __attribute__ ((noreturn));
752 
753 /* Halt the system, using APM if possible. If NO_APM is true, don't use
754    APM even if it is available.  */
755 void grub_halt (int no_apm) __attribute__ ((noreturn));
756 
757 /* Copy MAP to the drive map and set up int13_handler.  */
758 void set_int13_handler (unsigned short *map);
759 
760 /* Set up int15_handler.  */
761 void set_int15_handler (void);
762 
763 /* Restore the original int15 handler.  */
764 void unset_int15_handler (void);
765 
766 /* Track the int13 handler to probe I/O address space.  */
767 void track_int13 (int drive);
768 
769 /* The key map.  */
770 extern unsigned short bios_key_map[];
771 extern unsigned short ascii_key_map[];
772 extern unsigned short io_map[];
773 
774 /* calls for direct boot-loader chaining */
775 void chain_stage1 (unsigned long segment, unsigned long offset,
776 		   unsigned long part_table_addr)
777      __attribute__ ((noreturn));
778 void chain_stage2 (unsigned long segment, unsigned long offset,
779 		   int second_sector)
780      __attribute__ ((noreturn));
781 
782 /* do some funky stuff, then boot linux */
783 void linux_boot (void) __attribute__ ((noreturn));
784 
785 /* do some funky stuff, then boot bzImage linux */
786 void big_linux_boot (void) __attribute__ ((noreturn));
787 
788 /* booting a multiboot executable */
789 void multi_boot (int start, int mb_info) __attribute__ ((noreturn));
790 
791 /* If LINEAR is nonzero, then set the Intel processor to linear mode.
792    Otherwise, bit 20 of all memory accesses is always forced to zero,
793    causing a wraparound effect for bugwards compatibility with the
794    8086 CPU. */
795 void gateA20 (int linear);
796 
797 /* memory probe routines */
798 int get_memsize (int type);
799 int get_eisamemsize (void);
800 
801 /* Fetch the next entry in the memory map and return the continuation
802    value.  DESC is a pointer to the descriptor buffer, and CONT is the
803    previous continuation value (0 to get the first entry in the
804    map). */
805 int get_mmap_entry (struct mmar_desc *desc, int cont);
806 
807 /* Get the linear address of a ROM configuration table. Return zero,
808    if fails.  */
809 unsigned long get_rom_config_table (void);
810 
811 /* Get APM BIOS information.  */
812 void get_apm_info (void);
813 
814 /* Get VBE controller information.  */
815 int get_vbe_controller_info (struct vbe_controller *controller);
816 
817 /* Get VBE mode information.  */
818 int get_vbe_mode_info (int mode_number, struct vbe_mode *mode);
819 
820 /* Set VBE mode.  */
821 int set_vbe_mode (int mode_number);
822 
823 /* Return the data area immediately following our code. */
824 int get_code_end (void);
825 
826 /* low-level timing info */
827 int getrtsecs (void);
828 int currticks (void);
829 
830 /* Clear the screen. */
831 void cls (void);
832 
833 /* Turn on/off cursor. */
834 int setcursor (int on);
835 
836 /* Get the current cursor position (where 0,0 is the top left hand
837    corner of the screen).  Returns packed values, (RET >> 8) is x,
838    (RET & 0xff) is y. */
839 int getxy (void);
840 
841 /* Set the cursor position. */
842 void gotoxy (int x, int y);
843 
844 /* Displays an ASCII character.  IBM displays will translate some
845    characters to special graphical ones (see the DISP_* constants). */
846 void grub_putchar (int c);
847 
848 /* Wait for a keypress, and return its packed BIOS/ASCII key code.
849    Use ASCII_CHAR(ret) to extract the ASCII code. */
850 int getkey (void);
851 
852 /* Like GETKEY, but doesn't block, and returns -1 if no keystroke is
853    available. */
854 int checkkey (void);
855 
856 /* Low-level disk I/O */
857 int get_diskinfo (int drive, struct geometry *geometry);
858 int biosdisk (int subfunc, int drive, struct geometry *geometry,
859 	      int sector, int nsec, int segment);
860 void stop_floppy (void);
861 
862 /* Command-line interface functions. */
863 #ifndef STAGE1_5
864 
865 /* The flags for the builtins.  */
866 #define BUILTIN_CMDLINE		0x1	/* Run in the command-line.  */
867 #define BUILTIN_MENU		0x2	/* Run in the menu.  */
868 #define BUILTIN_TITLE		0x4	/* Only for the command title.  */
869 #define BUILTIN_SCRIPT		0x8	/* Run in the script.  */
870 #define BUILTIN_NO_ECHO		0x10	/* Don't print command on booting. */
871 #define BUILTIN_HELP_LIST	0x20	/* Show help in listing.  */
872 
873 /* The table for a builtin.  */
874 struct builtin
875 {
876   /* The command name.  */
877   char *name;
878   /* The callback function.  */
879   int (*func) (char *, int);
880   /* The combination of the flags defined above.  */
881   int flags;
882   /* The short version of the documentation.  */
883   char *short_doc;
884   /* The long version of the documentation.  */
885   char *long_doc;
886 };
887 
888 /* All the builtins are registered in this.  */
889 extern struct builtin *builtin_table[];
890 
891 /* The constants for kernel types.  */
892 typedef enum
893 {
894   KERNEL_TYPE_NONE,		/* None is loaded.  */
895   KERNEL_TYPE_MULTIBOOT,	/* Multiboot.  */
896   KERNEL_TYPE_LINUX,		/* Linux.  */
897   KERNEL_TYPE_BIG_LINUX,	/* Big Linux.  */
898   KERNEL_TYPE_FREEBSD,		/* FreeBSD.  */
899   KERNEL_TYPE_NETBSD,		/* NetBSD.  */
900   KERNEL_TYPE_CHAINLOADER	/* Chainloader.  */
901 }
902 kernel_t;
903 
904 extern kernel_t kernel_type;
905 extern int show_menu;
906 extern int grub_timeout;
907 
908 void init_builtins (void);
909 void init_config (void);
910 char *skip_to (int after_equal, char *cmdline);
911 struct builtin *find_command (char *command);
912 void print_cmdline_message (int forever);
913 void enter_cmdline (char *heap, int forever);
914 int run_script (char *script, char *heap);
915 #endif
916 
917 /* C library replacement functions with identical semantics. */
918 void grub_printf (const char *format,...);
919 int grub_sprintf (char *buffer, const char *format, ...);
920 int grub_tolower (int c);
921 int grub_isspace (int c);
922 int grub_strncat (char *s1, const char *s2, int n);
923 void grub_memcpy(void *dest, const void *src, int len);
924 void *grub_memmove (void *to, const void *from, int len);
925 void *grub_memset (void *start, int c, int len);
926 int grub_strncat (char *s1, const char *s2, int n);
927 char *grub_strstr (const char *s1, const char *s2);
928 int grub_memcmp (const char *s1, const char *s2, int n);
929 int grub_strcmp (const char *s1, const char *s2);
930 int grub_strlen (const char *str);
931 char *grub_strcpy (char *dest, const char *src);
932 
933 void noisy_printf (const char *format,...);
934 
935 #ifndef GRUB_UTIL
936 typedef unsigned long grub_jmp_buf[6];
937 #else
938 /* In the grub shell, use the libc jmp_buf instead.  */
939 # include <setjmp.h>
940 # define grub_jmp_buf jmp_buf
941 #endif
942 
943 #ifdef GRUB_UTIL
944 # define grub_setjmp	setjmp
945 # define grub_longjmp	longjmp
946 #else /* ! GRUB_UTIL */
947 int grub_setjmp (grub_jmp_buf env);
948 void grub_longjmp (grub_jmp_buf env, int val);
949 #endif /* ! GRUB_UTIL */
950 
951 /* The environment for restarting Stage 2.  */
952 extern grub_jmp_buf restart_env;
953 /* The environment for restarting the command-line interface.  */
954 extern grub_jmp_buf restart_cmdline_env;
955 
956 /* misc */
957 void init_page (void);
958 void print_error (void);
959 char *convert_to_ascii (char *buf, int c, ...);
960 int get_cmdline (char *prompt, char *cmdline, int maxlen,
961 		 int echo_char, int history);
962 int substring (const char *s1, const char *s2);
963 int nul_terminate (char *str);
964 int get_based_digit (int c, int base);
965 int safe_parse_maxint (char **str_ptr, int *myint_ptr);
966 int memcheck (unsigned long start, unsigned long len);
967 void grub_putstr (const char *str);
968 
969 #ifndef NO_DECOMPRESSION
970 /* Compression support. */
971 int gunzip_test_header (void);
972 int gunzip_read (char *buf, int len);
973 #endif /* NO_DECOMPRESSION */
974 
975 int rawread (int drive, int sector, int byte_offset, int byte_len, char *buf);
976 int devread (int sector, int byte_offset, int byte_len, char *buf);
977 int rawwrite (int drive, int sector, char *buf);
978 int devwrite (int sector, int sector_len, char *buf);
979 
980 /* Parse a device string and initialize the global parameters. */
981 char *set_device (char *device);
982 int open_device (void);
983 int real_open_partition (int flags);
984 int open_partition (void);
985 int next_partition (unsigned long drive, unsigned long dest,
986 		    unsigned long *partition, int *type,
987 		    unsigned long *start, unsigned long *len,
988 		    unsigned long *offset, int *entry,
989 		    unsigned long *ext_offset, char *buf);
990 
991 /* Sets device to the one represented by the SAVED_* parameters. */
992 int make_saved_active (void);
993 
994 /* Set or clear the current root partition's hidden flag.  */
995 int set_partition_hidden_flag (int hidden);
996 
997 /* Open a file or directory on the active device, using GRUB's
998    internal filesystem support. */
999 int grub_open (char *filename);
1000 
1001 /* Read LEN bytes into BUF from the file that was opened with
1002    GRUB_OPEN.  If LEN is -1, read all the remaining data in the file.  */
1003 int grub_read (char *buf, int len);
1004 
1005 /* Reposition a file offset.  */
1006 int grub_seek (int offset);
1007 
1008 /* Close a file.  */
1009 void grub_close (void);
1010 
1011 /* List the contents of the directory that was opened with GRUB_OPEN,
1012    printing all completions. */
1013 int dir (char *dirname);
1014 
1015 int set_bootdev (int hdbias);
1016 
1017 /* Display statistics on the current active device. */
1018 void print_fsys_type (void);
1019 
1020 /* Display device and filename completions. */
1021 void print_a_completion (char *filename);
1022 int print_completions (int is_filename, int is_completion);
1023 
1024 /* Copies the current partition data to the desired address. */
1025 void copy_current_part_entry (char *buf);
1026 
1027 #ifndef STAGE1_5
1028 void bsd_boot (kernel_t type, int bootdev, char *arg)
1029      __attribute__ ((noreturn));
1030 
1031 /* Define flags for load_image here.  */
1032 /* Don't pass a Linux's mem option automatically.  */
1033 #define KERNEL_LOAD_NO_MEM_OPTION	(1 << 0)
1034 
1035 kernel_t load_image (char *kernel, char *arg, kernel_t suggested_type,
1036 		     unsigned long load_flags);
1037 
1038 int load_module (char *module, char *arg);
1039 int load_initrd (char *initrd);
1040 
1041 int check_password(char *entered, char* expected, password_t type);
1042 #endif
1043 
1044 void init_bios_info (void);
1045 
1046 #endif /* ASM_FILE */
1047 
1048 #endif /* ! GRUB_SHARED_HEADER */
1049