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