17c478bd9Sstevel@tonic-gate /* shared.h - definitions used in all GRUB-specific code */
27c478bd9Sstevel@tonic-gate /*
37c478bd9Sstevel@tonic-gate  *  GRUB  --  GRand Unified Bootloader
47c478bd9Sstevel@tonic-gate  *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
5*1a065e93SAndrew Stormont  *  Copyright 2021 RackTop Systems, Inc.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  *  This program is free software; you can redistribute it and/or modify
87c478bd9Sstevel@tonic-gate  *  it under the terms of the GNU General Public License as published by
97c478bd9Sstevel@tonic-gate  *  the Free Software Foundation; either version 2 of the License, or
107c478bd9Sstevel@tonic-gate  *  (at your option) any later version.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  *  This program is distributed in the hope that it will be useful,
137c478bd9Sstevel@tonic-gate  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
147c478bd9Sstevel@tonic-gate  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
157c478bd9Sstevel@tonic-gate  *  GNU General Public License for more details.
167c478bd9Sstevel@tonic-gate  *
177c478bd9Sstevel@tonic-gate  *  You should have received a copy of the GNU General Public License
187c478bd9Sstevel@tonic-gate  *  along with this program; if not, write to the Free Software
197c478bd9Sstevel@tonic-gate  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  *  Generic defines to use anywhere
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef GRUB_SHARED_HEADER
277c478bd9Sstevel@tonic-gate #define GRUB_SHARED_HEADER	1
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <config.h>
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /* Add an underscore to a C symbol in assembler code if needed. */
327c478bd9Sstevel@tonic-gate #ifdef HAVE_ASM_USCORE
337c478bd9Sstevel@tonic-gate # define EXT_C(sym) _ ## sym
347c478bd9Sstevel@tonic-gate #else
357c478bd9Sstevel@tonic-gate # define EXT_C(sym) sym
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /* Maybe redirect memory requests through grub_scratch_mem. */
397c478bd9Sstevel@tonic-gate #ifdef GRUB_UTIL
407c478bd9Sstevel@tonic-gate extern char *grub_scratch_mem;
417c478bd9Sstevel@tonic-gate # define RAW_ADDR(x) ((x) + (int) grub_scratch_mem)
427c478bd9Sstevel@tonic-gate # define RAW_SEG(x) (RAW_ADDR ((x) << 4) >> 4)
437c478bd9Sstevel@tonic-gate #else
447c478bd9Sstevel@tonic-gate # define RAW_ADDR(x) (x)
457c478bd9Sstevel@tonic-gate # define RAW_SEG(x) (x)
467c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate 
48843e1988Sjohnlev /* ZFS will use the top 4 Meg of physical memory (below 4Gig) for sratch */
49843e1988Sjohnlev #define ZFS_SCRATCH_SIZE 0x400000
50843e1988Sjohnlev 
51ffb5616eSLin Ling #ifndef MAXPATHLEN
52ffb5616eSLin Ling #define	MAXPATHLEN	1024
53ffb5616eSLin Ling #endif
54ffb5616eSLin Ling 
55b1b8ab34Slling #define	MAXNAMELEN	256
56b1b8ab34Slling #define MIN(x, y) ((x) < (y) ? (x) : (y))
57b1b8ab34Slling 
58eb2bd662Svikram /* Boot signature related defines for the findroot command */
59eb2bd662Svikram #define	BOOTSIGN_DIR	"/boot/grub/bootsign"
60eb2bd662Svikram #define	BOOTSIGN_ARGLEN	(MAXNAMELEN + 10)	/* (<sign>,0,d) */
61eb2bd662Svikram #define	BOOTSIGN_LEN	(sizeof (BOOTSIGN_DIR) + 1 + BOOTSIGN_ARGLEN)
62eb2bd662Svikram #define	BOOTSIGN_BACKUP	"/etc/bootsign"
63eb2bd662Svikram 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  *  Integer sizes
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #define MAXINT     0x7FFFFFFF
69828d47c1SShidokht Yadegari #define	MAXUINT		0xFFFFFFFF
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /* Maximum command line size. Before you blindly increase this value,
727c478bd9Sstevel@tonic-gate    see the comment in char_io.c (get_cmdline).  */
737c478bd9Sstevel@tonic-gate #define MAX_CMDLINE 1600
747c478bd9Sstevel@tonic-gate #define NEW_HEAPSIZE 1500
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /* 512-byte scratch area */
777c478bd9Sstevel@tonic-gate #define SCRATCHADDR  RAW_ADDR (0x77e00)
787c478bd9Sstevel@tonic-gate #define SCRATCHSEG   RAW_SEG (0x77e0)
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate  *  This is the location of the raw device buffer.  It is 31.5K
827c478bd9Sstevel@tonic-gate  *  in size.
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #define BUFFERLEN   0x7e00
867c478bd9Sstevel@tonic-gate #define BUFFERADDR  RAW_ADDR (0x70000)
877c478bd9Sstevel@tonic-gate #define BUFFERSEG   RAW_SEG (0x7000)
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #define BOOT_PART_TABLE	RAW_ADDR (0x07be)
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  *  BIOS disk defines
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate #define BIOSDISK_READ			0x0
957c478bd9Sstevel@tonic-gate #define BIOSDISK_WRITE			0x1
967c478bd9Sstevel@tonic-gate #define BIOSDISK_ERROR_GEOMETRY		0x100
979caa1482Sszhou #define BIOSDISK_ERROR_SHORT_IO		0x101
987c478bd9Sstevel@tonic-gate #define BIOSDISK_FLAG_LBA_EXTENSION	0x1
997c478bd9Sstevel@tonic-gate #define BIOSDISK_FLAG_CDROM		0x2
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  *  This is the filesystem (not raw device) buffer.
1037c478bd9Sstevel@tonic-gate  *  It is 32K in size, do not overrun!
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #define FSYS_BUFLEN  0x8000
1077c478bd9Sstevel@tonic-gate #define FSYS_BUF RAW_ADDR (0x68000)
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /* Command-line buffer for Multiboot kernels and modules. This area
1107c478bd9Sstevel@tonic-gate    includes the area into which Stage 1.5 and Stage 1 are loaded, but
1117c478bd9Sstevel@tonic-gate    that's no problem.  */
1127c478bd9Sstevel@tonic-gate #define MB_CMDLINE_BUF		RAW_ADDR (0x2000)
1137c478bd9Sstevel@tonic-gate #define MB_CMDLINE_BUFLEN	0x6000
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /* The buffer for the password.  */
1167c478bd9Sstevel@tonic-gate #define PASSWORD_BUF		RAW_ADDR (0x78000)
1177c478bd9Sstevel@tonic-gate #define PASSWORD_BUFLEN		0x200
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /* THe buffer for the filename of "/boot/grub/default".  */
1207c478bd9Sstevel@tonic-gate #define DEFAULT_FILE_BUF	(PASSWORD_BUF + PASSWORD_BUFLEN)
1217c478bd9Sstevel@tonic-gate #define DEFAULT_FILE_BUFLEN	0x60
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /* The buffer for the command-line.  */
1247c478bd9Sstevel@tonic-gate #define CMDLINE_BUF		(DEFAULT_FILE_BUF + DEFAULT_FILE_BUFLEN)
1257c478bd9Sstevel@tonic-gate #define CMDLINE_BUFLEN		MAX_CMDLINE
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /* The kill buffer for the command-line.  */
1287c478bd9Sstevel@tonic-gate #define KILL_BUF		(CMDLINE_BUF + CMDLINE_BUFLEN)
1297c478bd9Sstevel@tonic-gate #define KILL_BUFLEN		MAX_CMDLINE
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /* The history buffer for the command-line.  */
1327c478bd9Sstevel@tonic-gate #define HISTORY_BUF		(KILL_BUF + KILL_BUFLEN)
1337c478bd9Sstevel@tonic-gate #define HISTORY_SIZE		5
1347c478bd9Sstevel@tonic-gate #define HISTORY_BUFLEN		(MAX_CMDLINE * HISTORY_SIZE)
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /* The buffer for the completion.  */
1377c478bd9Sstevel@tonic-gate #define COMPLETION_BUF		(HISTORY_BUF + HISTORY_BUFLEN)
1387c478bd9Sstevel@tonic-gate #define COMPLETION_BUFLEN	MAX_CMDLINE
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /* The buffer for the unique string.  */
1417c478bd9Sstevel@tonic-gate #define UNIQUE_BUF		(COMPLETION_BUF + COMPLETION_BUFLEN)
1427c478bd9Sstevel@tonic-gate #define UNIQUE_BUFLEN		MAX_CMDLINE
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /* The buffer for the menu entries.  */
1457c478bd9Sstevel@tonic-gate #define MENU_BUF		(UNIQUE_BUF + UNIQUE_BUFLEN)
1467c478bd9Sstevel@tonic-gate #define MENU_BUFLEN		(0x8000 + PASSWORD_BUF - MENU_BUF)
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /* The size of the drive map.  */
1497c478bd9Sstevel@tonic-gate #define DRIVE_MAP_SIZE		8
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /* The size of the key map.  */
1527c478bd9Sstevel@tonic-gate #define KEY_MAP_SIZE		128
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /* The size of the io map.  */
1557c478bd9Sstevel@tonic-gate #define IO_MAP_SIZE		128
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate  *  Linux setup parameters
1597c478bd9Sstevel@tonic-gate  */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #define LINUX_MAGIC_SIGNATURE		0x53726448	/* "HdrS" */
1627c478bd9Sstevel@tonic-gate #define LINUX_DEFAULT_SETUP_SECTS	4
1637c478bd9Sstevel@tonic-gate #define LINUX_FLAG_CAN_USE_HEAP		0x80
1647c478bd9Sstevel@tonic-gate #define LINUX_INITRD_MAX_ADDRESS	0x38000000
1657c478bd9Sstevel@tonic-gate #define LINUX_MAX_SETUP_SECTS		64
1667c478bd9Sstevel@tonic-gate #define LINUX_BOOT_LOADER_TYPE		0x71
1677c478bd9Sstevel@tonic-gate #define LINUX_HEAP_END_OFFSET		(0x9000 - 0x200)
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #define LINUX_BZIMAGE_ADDR		RAW_ADDR (0x100000)
1707c478bd9Sstevel@tonic-gate #define LINUX_ZIMAGE_ADDR		RAW_ADDR (0x10000)
1717c478bd9Sstevel@tonic-gate #define LINUX_OLD_REAL_MODE_ADDR	RAW_ADDR (0x90000)
1727c478bd9Sstevel@tonic-gate #define LINUX_SETUP_STACK		0x9000
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate #define LINUX_FLAG_BIG_KERNEL		0x1
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /* Linux's video mode selection support. Actually I hate it!  */
1777c478bd9Sstevel@tonic-gate #define LINUX_VID_MODE_NORMAL		0xFFFF
1787c478bd9Sstevel@tonic-gate #define LINUX_VID_MODE_EXTENDED		0xFFFE
1797c478bd9Sstevel@tonic-gate #define LINUX_VID_MODE_ASK		0xFFFD
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate #define LINUX_CL_OFFSET			0x9000
1827c478bd9Sstevel@tonic-gate #define LINUX_CL_END_OFFSET		0x90FF
1837c478bd9Sstevel@tonic-gate #define LINUX_SETUP_MOVE_SIZE		0x9100
1847c478bd9Sstevel@tonic-gate #define LINUX_CL_MAGIC			0xA33F
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate /*
1877c478bd9Sstevel@tonic-gate  *  General disk stuff
1887c478bd9Sstevel@tonic-gate  */
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate #define SECTOR_SIZE		0x200
1917c478bd9Sstevel@tonic-gate #define SECTOR_BITS		9
1927c478bd9Sstevel@tonic-gate #define BIOS_FLAG_FIXED_DISK	0x80
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate #define BOOTSEC_LOCATION		RAW_ADDR (0x7C00)
1957c478bd9Sstevel@tonic-gate #define BOOTSEC_SIGNATURE		0xAA55
1967c478bd9Sstevel@tonic-gate #define BOOTSEC_BPB_OFFSET		0x3
1977c478bd9Sstevel@tonic-gate #define BOOTSEC_BPB_LENGTH		0x3B
1987c478bd9Sstevel@tonic-gate #define BOOTSEC_BPB_SYSTEM_ID		0x3
1997c478bd9Sstevel@tonic-gate #define BOOTSEC_BPB_HIDDEN_SECTORS	0x1C
2007c478bd9Sstevel@tonic-gate #define BOOTSEC_PART_OFFSET		0x1BE
2017c478bd9Sstevel@tonic-gate #define BOOTSEC_PART_LENGTH		0x40
2027c478bd9Sstevel@tonic-gate #define BOOTSEC_SIG_OFFSET		0x1FE
2037c478bd9Sstevel@tonic-gate #define BOOTSEC_LISTSIZE		8
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate /* Not bad, perhaps.  */
2067c478bd9Sstevel@tonic-gate #define NETWORK_DRIVE	0x20
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  *  GRUB specific information
2107c478bd9Sstevel@tonic-gate  *    (in LSB order)
2117c478bd9Sstevel@tonic-gate  */
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate #include <stage1.h>
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate #define STAGE2_VER_MAJ_OFFS	0x6
2167c478bd9Sstevel@tonic-gate #define STAGE2_INSTALLPART	0x8
2177c478bd9Sstevel@tonic-gate #define STAGE2_SAVED_ENTRYNO	0xc
2187c478bd9Sstevel@tonic-gate #define STAGE2_STAGE2_ID	0x10
2197c478bd9Sstevel@tonic-gate #define STAGE2_FORCE_LBA	0x11
2207c478bd9Sstevel@tonic-gate #define STAGE2_VER_STR_OFFS	0x12
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate /* Stage 2 identifiers */
2237c478bd9Sstevel@tonic-gate #define STAGE2_ID_STAGE2		0
2247c478bd9Sstevel@tonic-gate #define STAGE2_ID_FFS_STAGE1_5		1
2257c478bd9Sstevel@tonic-gate #define STAGE2_ID_E2FS_STAGE1_5		2
2267c478bd9Sstevel@tonic-gate #define STAGE2_ID_FAT_STAGE1_5		3
2277c478bd9Sstevel@tonic-gate #define STAGE2_ID_MINIX_STAGE1_5	4
2287c478bd9Sstevel@tonic-gate #define STAGE2_ID_REISERFS_STAGE1_5	5
2297c478bd9Sstevel@tonic-gate #define STAGE2_ID_VSTAFS_STAGE1_5	6
2307c478bd9Sstevel@tonic-gate #define STAGE2_ID_JFS_STAGE1_5		7
2317c478bd9Sstevel@tonic-gate #define STAGE2_ID_XFS_STAGE1_5		8
2327c478bd9Sstevel@tonic-gate #define STAGE2_ID_ISO9660_STAGE1_5	9
2337c478bd9Sstevel@tonic-gate #define STAGE2_ID_UFS2_STAGE1_5		10
2347c478bd9Sstevel@tonic-gate #define STAGE2_ID_UFS_STAGE1_5		11
235b1b8ab34Slling #define STAGE2_ID_ZFS_STAGE1_5		12
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate #ifndef STAGE1_5
2387c478bd9Sstevel@tonic-gate # define STAGE2_ID	STAGE2_ID_STAGE2
2397c478bd9Sstevel@tonic-gate #else
2407c478bd9Sstevel@tonic-gate # if defined(FSYS_FFS)
2417c478bd9Sstevel@tonic-gate #  define STAGE2_ID	STAGE2_ID_FFS_STAGE1_5
2427c478bd9Sstevel@tonic-gate # elif defined(FSYS_EXT2FS)
2437c478bd9Sstevel@tonic-gate #  define STAGE2_ID	STAGE2_ID_E2FS_STAGE1_5
2447c478bd9Sstevel@tonic-gate # elif defined(FSYS_FAT)
2457c478bd9Sstevel@tonic-gate #  define STAGE2_ID	STAGE2_ID_FAT_STAGE1_5
2467c478bd9Sstevel@tonic-gate # elif defined(FSYS_MINIX)
2477c478bd9Sstevel@tonic-gate #  define STAGE2_ID	STAGE2_ID_MINIX_STAGE1_5
2487c478bd9Sstevel@tonic-gate # elif defined(FSYS_REISERFS)
2497c478bd9Sstevel@tonic-gate #  define STAGE2_ID	STAGE2_ID_REISERFS_STAGE1_5
2507c478bd9Sstevel@tonic-gate # elif defined(FSYS_VSTAFS)
2517c478bd9Sstevel@tonic-gate #  define STAGE2_ID	STAGE2_ID_VSTAFS_STAGE1_5
2527c478bd9Sstevel@tonic-gate # elif defined(FSYS_JFS)
2537c478bd9Sstevel@tonic-gate #  define STAGE2_ID	STAGE2_ID_JFS_STAGE1_5
2547c478bd9Sstevel@tonic-gate # elif defined(FSYS_XFS)
2557c478bd9Sstevel@tonic-gate #  define STAGE2_ID	STAGE2_ID_XFS_STAGE1_5
2567c478bd9Sstevel@tonic-gate # elif defined(FSYS_ISO9660)
2577c478bd9Sstevel@tonic-gate #  define STAGE2_ID	STAGE2_ID_ISO9660_STAGE1_5
2587c478bd9Sstevel@tonic-gate # elif defined(FSYS_UFS2)
2597c478bd9Sstevel@tonic-gate #  define STAGE2_ID	STAGE2_ID_UFS2_STAGE1_5
2607c478bd9Sstevel@tonic-gate # elif defined(FSYS_UFS)
2617c478bd9Sstevel@tonic-gate #  define STAGE2_ID	STAGE2_ID_UFS_STAGE1_5
262b1b8ab34Slling # elif defined(FSYS_ZFS)
263b1b8ab34Slling #  define STAGE2_ID	STAGE2_ID_ZFS_STAGE1_5
2647c478bd9Sstevel@tonic-gate # else
2657c478bd9Sstevel@tonic-gate #  error "unknown Stage 2"
2667c478bd9Sstevel@tonic-gate # endif
2677c478bd9Sstevel@tonic-gate #endif
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate /*
2707c478bd9Sstevel@tonic-gate  *  defines for use when switching between real and protected mode
2717c478bd9Sstevel@tonic-gate  */
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate #define CR0_PE_ON	0x1
2747c478bd9Sstevel@tonic-gate #define CR0_PE_OFF	0xfffffffe
2757c478bd9Sstevel@tonic-gate #define PROT_MODE_CSEG	0x8
2767c478bd9Sstevel@tonic-gate #define PROT_MODE_DSEG  0x10
2777c478bd9Sstevel@tonic-gate #define PSEUDO_RM_CSEG	0x18
2787c478bd9Sstevel@tonic-gate #define PSEUDO_RM_DSEG	0x20
2797c478bd9Sstevel@tonic-gate #define STACKOFF	(0x2000 - 0x10)
2807c478bd9Sstevel@tonic-gate #define PROTSTACKINIT   (FSYS_BUF - 0x10)
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate /*
2847c478bd9Sstevel@tonic-gate  * Assembly code defines
2857c478bd9Sstevel@tonic-gate  *
2867c478bd9Sstevel@tonic-gate  * "EXT_C" is assumed to be defined in the Makefile by the configure
2877c478bd9Sstevel@tonic-gate  *   command.
2887c478bd9Sstevel@tonic-gate  */
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate #define ENTRY(x) .globl EXT_C(x) ; EXT_C(x):
2917c478bd9Sstevel@tonic-gate #define VARIABLE(x) ENTRY(x)
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate #define K_RDWR  	0x60	/* keyboard data & cmds (read/write) */
2957c478bd9Sstevel@tonic-gate #define K_STATUS	0x64	/* keyboard status */
2967c478bd9Sstevel@tonic-gate #define K_CMD		0x64	/* keybd ctlr command (write-only) */
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate #define K_OBUF_FUL 	0x01	/* output buffer full */
2997c478bd9Sstevel@tonic-gate #define K_IBUF_FUL 	0x02	/* input buffer full */
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate #define KC_CMD_WIN	0xd0	/* read  output port */
3027c478bd9Sstevel@tonic-gate #define KC_CMD_WOUT	0xd1	/* write output port */
3037c478bd9Sstevel@tonic-gate #define KB_OUTPUT_MASK  0xdd	/* enable output buffer full interrupt
3047c478bd9Sstevel@tonic-gate 				   enable data line
3057c478bd9Sstevel@tonic-gate 				   enable clock line */
3067c478bd9Sstevel@tonic-gate #define KB_A20_ENABLE   0x02
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate /* Codes for getchar. */
3097c478bd9Sstevel@tonic-gate #define ASCII_CHAR(x)   ((x) & 0xFF)
3107c478bd9Sstevel@tonic-gate #if !defined(GRUB_UTIL) || !defined(HAVE_LIBCURSES)
3117c478bd9Sstevel@tonic-gate # define KEY_LEFT        0x4B00
3127c478bd9Sstevel@tonic-gate # define KEY_RIGHT       0x4D00
3137c478bd9Sstevel@tonic-gate # define KEY_UP          0x4800
3147c478bd9Sstevel@tonic-gate # define KEY_DOWN        0x5000
3157c478bd9Sstevel@tonic-gate # define KEY_IC          0x5200	/* insert char */
3167c478bd9Sstevel@tonic-gate # define KEY_DC          0x5300	/* delete char */
3177c478bd9Sstevel@tonic-gate # define KEY_BACKSPACE   0x0008
3187c478bd9Sstevel@tonic-gate # define KEY_HOME        0x4700
3197c478bd9Sstevel@tonic-gate # define KEY_END         0x4F00
3207c478bd9Sstevel@tonic-gate # define KEY_NPAGE       0x5100
3217c478bd9Sstevel@tonic-gate # define KEY_PPAGE       0x4900
3227c478bd9Sstevel@tonic-gate # define A_NORMAL        0x7
3237c478bd9Sstevel@tonic-gate # define A_REVERSE       0x70
3247c478bd9Sstevel@tonic-gate #elif defined(HAVE_NCURSES_CURSES_H)
3257c478bd9Sstevel@tonic-gate # include <ncurses/curses.h>
3267c478bd9Sstevel@tonic-gate #elif defined(HAVE_NCURSES_H)
3277c478bd9Sstevel@tonic-gate # include <ncurses.h>
3287c478bd9Sstevel@tonic-gate #elif defined(HAVE_CURSES_H)
3297c478bd9Sstevel@tonic-gate # include <curses.h>
3307c478bd9Sstevel@tonic-gate #endif
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate /* In old BSD curses, A_NORMAL and A_REVERSE are not defined, so we
3337c478bd9Sstevel@tonic-gate    define them here if they are undefined.  */
3347c478bd9Sstevel@tonic-gate #ifndef A_NORMAL
3357c478bd9Sstevel@tonic-gate # define A_NORMAL	0
3367c478bd9Sstevel@tonic-gate #endif /* ! A_NORMAL */
3377c478bd9Sstevel@tonic-gate #ifndef A_REVERSE
3387c478bd9Sstevel@tonic-gate # ifdef A_STANDOUT
3397c478bd9Sstevel@tonic-gate #  define A_REVERSE	A_STANDOUT
3407c478bd9Sstevel@tonic-gate # else /* ! A_STANDOUT */
3417c478bd9Sstevel@tonic-gate #  define A_REVERSE	0
3427c478bd9Sstevel@tonic-gate # endif /* ! A_STANDOUT */
3437c478bd9Sstevel@tonic-gate #endif /* ! A_REVERSE */
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate /* Define ACS_* ourselves, since the definitions are not consistent among
3467c478bd9Sstevel@tonic-gate    various curses implementations.  */
3477c478bd9Sstevel@tonic-gate #undef ACS_ULCORNER
3487c478bd9Sstevel@tonic-gate #undef ACS_URCORNER
3497c478bd9Sstevel@tonic-gate #undef ACS_LLCORNER
3507c478bd9Sstevel@tonic-gate #undef ACS_LRCORNER
3517c478bd9Sstevel@tonic-gate #undef ACS_HLINE
3527c478bd9Sstevel@tonic-gate #undef ACS_VLINE
3537c478bd9Sstevel@tonic-gate #undef ACS_LARROW
3547c478bd9Sstevel@tonic-gate #undef ACS_RARROW
3557c478bd9Sstevel@tonic-gate #undef ACS_UARROW
3567c478bd9Sstevel@tonic-gate #undef ACS_DARROW
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate #define ACS_ULCORNER	'+'
3597c478bd9Sstevel@tonic-gate #define ACS_URCORNER	'+'
3607c478bd9Sstevel@tonic-gate #define ACS_LLCORNER	'+'
3617c478bd9Sstevel@tonic-gate #define ACS_LRCORNER	'+'
3627c478bd9Sstevel@tonic-gate #define ACS_HLINE	'-'
3637c478bd9Sstevel@tonic-gate #define ACS_VLINE	'|'
3647c478bd9Sstevel@tonic-gate #define ACS_LARROW	'<'
3657c478bd9Sstevel@tonic-gate #define ACS_RARROW	'>'
3667c478bd9Sstevel@tonic-gate #define ACS_UARROW	'^'
3677c478bd9Sstevel@tonic-gate #define ACS_DARROW	'v'
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate /* Special graphics characters for IBM displays. */
3707c478bd9Sstevel@tonic-gate #define DISP_UL		218
3717c478bd9Sstevel@tonic-gate #define DISP_UR		191
3727c478bd9Sstevel@tonic-gate #define DISP_LL		192
3737c478bd9Sstevel@tonic-gate #define DISP_LR		217
3747c478bd9Sstevel@tonic-gate #define DISP_HORIZ	196
3757c478bd9Sstevel@tonic-gate #define DISP_VERT	179
3767c478bd9Sstevel@tonic-gate #define DISP_LEFT	0x1b
3777c478bd9Sstevel@tonic-gate #define DISP_RIGHT	0x1a
3787c478bd9Sstevel@tonic-gate #define DISP_UP		0x18
3797c478bd9Sstevel@tonic-gate #define DISP_DOWN	0x19
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate /* Remap some libc-API-compatible function names so that we prevent
3827c478bd9Sstevel@tonic-gate    circularararity. */
3837c478bd9Sstevel@tonic-gate #ifndef WITHOUT_LIBC_STUBS
3847c478bd9Sstevel@tonic-gate #define memmove grub_memmove
3857c478bd9Sstevel@tonic-gate #define memcpy grub_memmove	/* we don't need a separate memcpy */
3867c478bd9Sstevel@tonic-gate #define memset grub_memset
3877c478bd9Sstevel@tonic-gate #undef isspace
3887c478bd9Sstevel@tonic-gate #define isspace grub_isspace
3897c478bd9Sstevel@tonic-gate #define printf grub_printf
3907c478bd9Sstevel@tonic-gate #define sprintf grub_sprintf
3917c478bd9Sstevel@tonic-gate #undef putchar
3927c478bd9Sstevel@tonic-gate #define putchar grub_putchar
3937c478bd9Sstevel@tonic-gate #define strncat grub_strncat
3947c478bd9Sstevel@tonic-gate #define strstr grub_strstr
3957c478bd9Sstevel@tonic-gate #define memcmp grub_memcmp
3967c478bd9Sstevel@tonic-gate #define strcmp grub_strcmp
3977c478bd9Sstevel@tonic-gate #define tolower grub_tolower
3987c478bd9Sstevel@tonic-gate #define strlen grub_strlen
3997c478bd9Sstevel@tonic-gate #define strcpy grub_strcpy
4007c478bd9Sstevel@tonic-gate #endif /* WITHOUT_LIBC_STUBS */
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate #define UNDI_STACK (512 + 64) << 10
4037c478bd9Sstevel@tonic-gate #define UNDI_STACK_SEG (UNDI_STACK >> 4) /*  PXE load GRUB here */
4047c478bd9Sstevel@tonic-gate #define UNDI_STACK_OFF (0x10000 - 0x10)
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate #ifndef ASM_FILE
4077c478bd9Sstevel@tonic-gate /*
4087c478bd9Sstevel@tonic-gate  *  Below this should be ONLY defines and other constructs for C code.
4097c478bd9Sstevel@tonic-gate  */
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate /* multiboot stuff */
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate #include "mb_header.h"
4147c478bd9Sstevel@tonic-gate #include "mb_info.h"
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate /* For the Linux/i386 boot protocol version 2.03.  */
4177c478bd9Sstevel@tonic-gate struct linux_kernel_header
4187c478bd9Sstevel@tonic-gate {
4197c478bd9Sstevel@tonic-gate   char code1[0x0020];
4207c478bd9Sstevel@tonic-gate   unsigned short cl_magic;		/* Magic number 0xA33F */
4217c478bd9Sstevel@tonic-gate   unsigned short cl_offset;		/* The offset of command line */
4227c478bd9Sstevel@tonic-gate   char code2[0x01F1 - 0x0020 - 2 - 2];
4237c478bd9Sstevel@tonic-gate   unsigned char setup_sects;		/* The size of the setup in sectors */
4247c478bd9Sstevel@tonic-gate   unsigned short root_flags;		/* If the root is mounted readonly */
4257c478bd9Sstevel@tonic-gate   unsigned short syssize;		/* obsolete */
4267c478bd9Sstevel@tonic-gate   unsigned short swap_dev;		/* obsolete */
4277c478bd9Sstevel@tonic-gate   unsigned short ram_size;		/* obsolete */
4287c478bd9Sstevel@tonic-gate   unsigned short vid_mode;		/* Video mode control */
4297c478bd9Sstevel@tonic-gate   unsigned short root_dev;		/* Default root device number */
4307c478bd9Sstevel@tonic-gate   unsigned short boot_flag;		/* 0xAA55 magic number */
4317c478bd9Sstevel@tonic-gate   unsigned short jump;			/* Jump instruction */
4327c478bd9Sstevel@tonic-gate   unsigned long header;			/* Magic signature "HdrS" */
4337c478bd9Sstevel@tonic-gate   unsigned short version;		/* Boot protocol version supported */
4347c478bd9Sstevel@tonic-gate   unsigned long realmode_swtch;		/* Boot loader hook */
4357c478bd9Sstevel@tonic-gate   unsigned long start_sys;		/* Points to kernel version string */
4367c478bd9Sstevel@tonic-gate   unsigned char type_of_loader;		/* Boot loader identifier */
4377c478bd9Sstevel@tonic-gate   unsigned char loadflags;		/* Boot protocol option flags */
4387c478bd9Sstevel@tonic-gate   unsigned short setup_move_size;	/* Move to high memory size */
4397c478bd9Sstevel@tonic-gate   unsigned long code32_start;		/* Boot loader hook */
4407c478bd9Sstevel@tonic-gate   unsigned long ramdisk_image;		/* initrd load address */
4417c478bd9Sstevel@tonic-gate   unsigned long ramdisk_size;		/* initrd size */
4427c478bd9Sstevel@tonic-gate   unsigned long bootsect_kludge;	/* obsolete */
4437c478bd9Sstevel@tonic-gate   unsigned short heap_end_ptr;		/* Free memory after setup end */
4447c478bd9Sstevel@tonic-gate   unsigned short pad1;			/* Unused */
4457c478bd9Sstevel@tonic-gate   char *cmd_line_ptr;			/* Points to the kernel command line */
4467c478bd9Sstevel@tonic-gate   unsigned long initrd_addr_max;	/* The highest address of initrd */
4477c478bd9Sstevel@tonic-gate } __attribute__ ((packed));
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate /* Memory map address range descriptor used by GET_MMAP_ENTRY. */
4507c478bd9Sstevel@tonic-gate struct mmar_desc
4517c478bd9Sstevel@tonic-gate {
4527c478bd9Sstevel@tonic-gate   unsigned long desc_len;	/* Size of this descriptor. */
4537c478bd9Sstevel@tonic-gate   unsigned long long addr;	/* Base address. */
4547c478bd9Sstevel@tonic-gate   unsigned long long length;	/* Length in bytes. */
4557c478bd9Sstevel@tonic-gate   unsigned long type;		/* Type of address range. */
4567c478bd9Sstevel@tonic-gate } __attribute__ ((packed));
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate /* VBE controller information.  */
4597c478bd9Sstevel@tonic-gate struct vbe_controller
4607c478bd9Sstevel@tonic-gate {
4617c478bd9Sstevel@tonic-gate   unsigned char signature[4];
4627c478bd9Sstevel@tonic-gate   unsigned short version;
4637c478bd9Sstevel@tonic-gate   unsigned long oem_string;
4647c478bd9Sstevel@tonic-gate   unsigned long capabilities;
4657c478bd9Sstevel@tonic-gate   unsigned long video_mode;
4667c478bd9Sstevel@tonic-gate   unsigned short total_memory;
4677c478bd9Sstevel@tonic-gate   unsigned short oem_software_rev;
4687c478bd9Sstevel@tonic-gate   unsigned long oem_vendor_name;
4697c478bd9Sstevel@tonic-gate   unsigned long oem_product_name;
4707c478bd9Sstevel@tonic-gate   unsigned long oem_product_rev;
4717c478bd9Sstevel@tonic-gate   unsigned char reserved[222];
4727c478bd9Sstevel@tonic-gate   unsigned char oem_data[256];
4737c478bd9Sstevel@tonic-gate } __attribute__ ((packed));
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate /* VBE mode information.  */
4767c478bd9Sstevel@tonic-gate struct vbe_mode
4777c478bd9Sstevel@tonic-gate {
4787c478bd9Sstevel@tonic-gate   unsigned short mode_attributes;
4797c478bd9Sstevel@tonic-gate   unsigned char win_a_attributes;
4807c478bd9Sstevel@tonic-gate   unsigned char win_b_attributes;
4817c478bd9Sstevel@tonic-gate   unsigned short win_granularity;
4827c478bd9Sstevel@tonic-gate   unsigned short win_size;
4837c478bd9Sstevel@tonic-gate   unsigned short win_a_segment;
4847c478bd9Sstevel@tonic-gate   unsigned short win_b_segment;
4857c478bd9Sstevel@tonic-gate   unsigned long win_func;
4867c478bd9Sstevel@tonic-gate   unsigned short bytes_per_scanline;
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate   /* >=1.2 */
4897c478bd9Sstevel@tonic-gate   unsigned short x_resolution;
4907c478bd9Sstevel@tonic-gate   unsigned short y_resolution;
4917c478bd9Sstevel@tonic-gate   unsigned char x_char_size;
4927c478bd9Sstevel@tonic-gate   unsigned char y_char_size;
4937c478bd9Sstevel@tonic-gate   unsigned char number_of_planes;
4947c478bd9Sstevel@tonic-gate   unsigned char bits_per_pixel;
4957c478bd9Sstevel@tonic-gate   unsigned char number_of_banks;
4967c478bd9Sstevel@tonic-gate   unsigned char memory_model;
4977c478bd9Sstevel@tonic-gate   unsigned char bank_size;
4987c478bd9Sstevel@tonic-gate   unsigned char number_of_image_pages;
4997c478bd9Sstevel@tonic-gate   unsigned char reserved0;
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate   /* direct color */
5027c478bd9Sstevel@tonic-gate   unsigned char red_mask_size;
5037c478bd9Sstevel@tonic-gate   unsigned char red_field_position;
5047c478bd9Sstevel@tonic-gate   unsigned char green_mask_size;
5057c478bd9Sstevel@tonic-gate   unsigned char green_field_position;
5067c478bd9Sstevel@tonic-gate   unsigned char blue_mask_size;
5077c478bd9Sstevel@tonic-gate   unsigned char blue_field_position;
5087c478bd9Sstevel@tonic-gate   unsigned char reserved_mask_size;
5097c478bd9Sstevel@tonic-gate   unsigned char reserved_field_position;
5107c478bd9Sstevel@tonic-gate   unsigned char direct_color_mode_info;
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate   /* >=2.0 */
5137c478bd9Sstevel@tonic-gate   unsigned long phys_base;
5147c478bd9Sstevel@tonic-gate   unsigned long reserved1;
5157c478bd9Sstevel@tonic-gate   unsigned short reversed2;
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate   /* >=3.0 */
5187c478bd9Sstevel@tonic-gate   unsigned short linear_bytes_per_scanline;
5197c478bd9Sstevel@tonic-gate   unsigned char banked_number_of_image_pages;
5207c478bd9Sstevel@tonic-gate   unsigned char linear_number_of_image_pages;
5217c478bd9Sstevel@tonic-gate   unsigned char linear_red_mask_size;
5227c478bd9Sstevel@tonic-gate   unsigned char linear_red_field_position;
5237c478bd9Sstevel@tonic-gate   unsigned char linear_green_mask_size;
5247c478bd9Sstevel@tonic-gate   unsigned char linear_green_field_position;
5257c478bd9Sstevel@tonic-gate   unsigned char linear_blue_mask_size;
5267c478bd9Sstevel@tonic-gate   unsigned char linear_blue_field_position;
5277c478bd9Sstevel@tonic-gate   unsigned char linear_reserved_mask_size;
5287c478bd9Sstevel@tonic-gate   unsigned char linear_reserved_field_position;
5297c478bd9Sstevel@tonic-gate   unsigned long max_pixel_clock;
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate   unsigned char reserved3[189];
5327c478bd9Sstevel@tonic-gate } __attribute__ ((packed));
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate #undef NULL
5357c478bd9Sstevel@tonic-gate #define NULL         ((void *) 0)
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate /* Error codes (descriptions are in common.c) */
5387c478bd9Sstevel@tonic-gate typedef enum
5397c478bd9Sstevel@tonic-gate {
5407c478bd9Sstevel@tonic-gate   ERR_NONE = 0,
5417c478bd9Sstevel@tonic-gate   ERR_BAD_FILENAME,
5427c478bd9Sstevel@tonic-gate   ERR_BAD_FILETYPE,
5437c478bd9Sstevel@tonic-gate   ERR_BAD_GZIP_DATA,
5447c478bd9Sstevel@tonic-gate   ERR_BAD_GZIP_HEADER,
5457c478bd9Sstevel@tonic-gate   ERR_BAD_PART_TABLE,
5467c478bd9Sstevel@tonic-gate   ERR_BAD_VERSION,
5477c478bd9Sstevel@tonic-gate   ERR_BELOW_1MB,
5487c478bd9Sstevel@tonic-gate   ERR_BOOT_COMMAND,
5497c478bd9Sstevel@tonic-gate   ERR_BOOT_FAILURE,
5507c478bd9Sstevel@tonic-gate   ERR_BOOT_FEATURES,
5517c478bd9Sstevel@tonic-gate   ERR_DEV_FORMAT,
5527c478bd9Sstevel@tonic-gate   ERR_DEV_VALUES,
5537c478bd9Sstevel@tonic-gate   ERR_EXEC_FORMAT,
5547c478bd9Sstevel@tonic-gate   ERR_FILELENGTH,
5557c478bd9Sstevel@tonic-gate   ERR_FILE_NOT_FOUND,
5567c478bd9Sstevel@tonic-gate   ERR_FSYS_CORRUPT,
5577c478bd9Sstevel@tonic-gate   ERR_FSYS_MOUNT,
5587c478bd9Sstevel@tonic-gate   ERR_GEOM,
5597c478bd9Sstevel@tonic-gate   ERR_NEED_LX_KERNEL,
5607c478bd9Sstevel@tonic-gate   ERR_NEED_MB_KERNEL,
5617c478bd9Sstevel@tonic-gate   ERR_NO_DISK,
5627c478bd9Sstevel@tonic-gate   ERR_NO_PART,
5637c478bd9Sstevel@tonic-gate   ERR_NUMBER_PARSING,
5647c478bd9Sstevel@tonic-gate   ERR_OUTSIDE_PART,
5657c478bd9Sstevel@tonic-gate   ERR_READ,
5667c478bd9Sstevel@tonic-gate   ERR_SYMLINK_LOOP,
5677c478bd9Sstevel@tonic-gate   ERR_UNRECOGNIZED,
5687c478bd9Sstevel@tonic-gate   ERR_WONT_FIT,
5697c478bd9Sstevel@tonic-gate   ERR_WRITE,
5707c478bd9Sstevel@tonic-gate   ERR_BAD_ARGUMENT,
5717c478bd9Sstevel@tonic-gate   ERR_UNALIGNED,
5727c478bd9Sstevel@tonic-gate   ERR_PRIVILEGED,
5737c478bd9Sstevel@tonic-gate   ERR_DEV_NEED_INIT,
5747c478bd9Sstevel@tonic-gate   ERR_NO_DISK_SPACE,
5757c478bd9Sstevel@tonic-gate   ERR_NUMBER_OVERFLOW,
5769caa1482Sszhou   ERR_BAD_GZIP_CRC,
577b1b8ab34Slling   ERR_FILESYSTEM_NOT_FOUND,
578e7cbe64fSgw   ERR_NO_BOOTPATH,
579fe3e2633SEric Taylor   ERR_NEWER_VERSION,
5809b4e3ac2SWilliam Kucharski   ERR_NOTXPM,
5819b4e3ac2SWilliam Kucharski   ERR_TOOMANYCOLORS,
5829b4e3ac2SWilliam Kucharski   ERR_CORRUPTXPM,
583a5602e1bSKeith M Wesolowski   ERR_NOVAR,
5847c478bd9Sstevel@tonic-gate   MAX_ERR_NUM
5857c478bd9Sstevel@tonic-gate } grub_error_t;
5867c478bd9Sstevel@tonic-gate 
5872506833eSJan Setje-Eilers typedef enum
5882506833eSJan Setje-Eilers {
5892506833eSJan Setje-Eilers 	CFG_HARDCODED,
5902506833eSJan Setje-Eilers 	CFG_150,
5912506833eSJan Setje-Eilers 	CFG_MAC,
5922506833eSJan Setje-Eilers 	CFG_BOOTFILE
5932506833eSJan Setje-Eilers } configfile_origin_t;
5942506833eSJan Setje-Eilers 
5957c478bd9Sstevel@tonic-gate extern unsigned long install_partition;
5967c478bd9Sstevel@tonic-gate extern unsigned long boot_drive;
5977c478bd9Sstevel@tonic-gate extern unsigned long install_second_sector;
5987c478bd9Sstevel@tonic-gate extern struct apm_info apm_bios_info;
5997c478bd9Sstevel@tonic-gate extern unsigned long boot_part_addr;
6007c478bd9Sstevel@tonic-gate extern int saved_entryno;
6017c478bd9Sstevel@tonic-gate extern unsigned char force_lba;
6027c478bd9Sstevel@tonic-gate extern char version_string[];
6037c478bd9Sstevel@tonic-gate extern char config_file[];
6042506833eSJan Setje-Eilers extern char *bootfile;
6052506833eSJan Setje-Eilers extern configfile_origin_t configfile_origin;
6067c478bd9Sstevel@tonic-gate extern unsigned long linux_text_len;
6077c478bd9Sstevel@tonic-gate extern char *linux_data_tmp_addr;
6087c478bd9Sstevel@tonic-gate extern char *linux_data_real_addr;
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate #ifdef GRUB_UTIL
6117c478bd9Sstevel@tonic-gate /* If not using config file, this variable is set to zero,
6127c478bd9Sstevel@tonic-gate    otherwise non-zero.  */
6137c478bd9Sstevel@tonic-gate extern int use_config_file;
6147c478bd9Sstevel@tonic-gate /* If using the preset menu, this variable is set to non-zero,
6157c478bd9Sstevel@tonic-gate    otherwise zero.  */
6167c478bd9Sstevel@tonic-gate extern int use_preset_menu;
6177c478bd9Sstevel@tonic-gate /* If not using curses, this variable is set to zero, otherwise non-zero.  */
6187c478bd9Sstevel@tonic-gate extern int use_curses;
6197c478bd9Sstevel@tonic-gate /* The flag for verbose messages.  */
6207c478bd9Sstevel@tonic-gate extern int verbose;
6217c478bd9Sstevel@tonic-gate /* The flag for read-only.  */
6227c478bd9Sstevel@tonic-gate extern int read_only;
6237c478bd9Sstevel@tonic-gate /* The number of floppies to be probed.  */
6247c478bd9Sstevel@tonic-gate extern int floppy_disks;
6257c478bd9Sstevel@tonic-gate /* The map between BIOS drives and UNIX device file names.  */
6267c478bd9Sstevel@tonic-gate extern char **device_map;
6277c478bd9Sstevel@tonic-gate /* The filename which stores the information about a device map.  */
6287c478bd9Sstevel@tonic-gate extern char *device_map_file;
6297c478bd9Sstevel@tonic-gate /* The array of geometries.  */
6307c478bd9Sstevel@tonic-gate extern struct geometry *disks;
6317c478bd9Sstevel@tonic-gate /* Assign DRIVE to a device name DEVICE.  */
6327c478bd9Sstevel@tonic-gate extern void assign_device_name (int drive, const char *device);
6337c478bd9Sstevel@tonic-gate #endif
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate #ifndef STAGE1_5
6367c478bd9Sstevel@tonic-gate /* GUI interface variables. */
6377c478bd9Sstevel@tonic-gate # define MAX_FALLBACK_ENTRIES	8
6387c478bd9Sstevel@tonic-gate extern int fallback_entries[MAX_FALLBACK_ENTRIES];
6397c478bd9Sstevel@tonic-gate extern int fallback_entryno;
6407c478bd9Sstevel@tonic-gate extern int default_entry;
6417c478bd9Sstevel@tonic-gate extern int current_entryno;
6427c478bd9Sstevel@tonic-gate 
643a5602e1bSKeith M Wesolowski extern unsigned int min_mem64;
644a5602e1bSKeith M Wesolowski 
6457c478bd9Sstevel@tonic-gate /* The constants for password types.  */
6467c478bd9Sstevel@tonic-gate typedef enum
6477c478bd9Sstevel@tonic-gate {
6487c478bd9Sstevel@tonic-gate   PASSWORD_PLAIN,
6497c478bd9Sstevel@tonic-gate   PASSWORD_MD5,
6507c478bd9Sstevel@tonic-gate   PASSWORD_UNSUPPORTED
6517c478bd9Sstevel@tonic-gate }
6527c478bd9Sstevel@tonic-gate password_t;
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate extern char *password;
6557c478bd9Sstevel@tonic-gate extern password_t password_type;
6567c478bd9Sstevel@tonic-gate extern int auth;
6577c478bd9Sstevel@tonic-gate extern char commands[];
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate /* For `more'-like feature.  */
6607c478bd9Sstevel@tonic-gate extern int max_lines;
6617c478bd9Sstevel@tonic-gate extern int count_lines;
6627c478bd9Sstevel@tonic-gate extern int use_pager;
6637c478bd9Sstevel@tonic-gate #endif
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate #ifndef NO_DECOMPRESSION
6667c478bd9Sstevel@tonic-gate extern int no_decompression;
6677c478bd9Sstevel@tonic-gate extern int compressed_file;
6687c478bd9Sstevel@tonic-gate #endif
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate /* instrumentation variables */
6719890706eSHans Rosenfeld extern void (*disk_read_hook) (unsigned long long, int, int);
6729890706eSHans Rosenfeld extern void (*disk_read_func) (unsigned long long, int, int);
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate #ifndef STAGE1_5
6757c478bd9Sstevel@tonic-gate /* The flag for debug mode.  */
6767c478bd9Sstevel@tonic-gate extern int debug;
6777c478bd9Sstevel@tonic-gate #endif /* STAGE1_5 */
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate extern unsigned long current_drive;
6807c478bd9Sstevel@tonic-gate extern unsigned long current_partition;
681b1b8ab34Slling extern char current_rootpool[MAXNAMELEN];
682b1b8ab34Slling extern char current_bootfs[MAXNAMELEN];
683b1b8ab34Slling extern unsigned long long current_bootfs_obj;
684ffb5616eSLin Ling extern char current_bootpath[MAXPATHLEN];
685ffb5616eSLin Ling extern char current_devid[MAXPATHLEN];
686*1a065e93SAndrew Stormont extern unsigned long long current_bootguid;
687*1a065e93SAndrew Stormont extern unsigned long long current_bootvdev;
688b1b8ab34Slling extern int is_zfs_mount;
689051aabe6Staylor extern unsigned long best_drive;
690051aabe6Staylor extern unsigned long best_part;
691051aabe6Staylor extern int find_best_root;
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate extern int fsys_type;
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate /* The information for a disk geometry. The CHS information is only for
6967c478bd9Sstevel@tonic-gate    DOS/Partition table compatibility, and the real number of sectors is
6977c478bd9Sstevel@tonic-gate    stored in TOTAL_SECTORS.  */
6987c478bd9Sstevel@tonic-gate struct geometry
6997c478bd9Sstevel@tonic-gate {
7007c478bd9Sstevel@tonic-gate   /* The number of cylinders */
7017c478bd9Sstevel@tonic-gate   unsigned long cylinders;
7027c478bd9Sstevel@tonic-gate   /* The number of heads */
7037c478bd9Sstevel@tonic-gate   unsigned long heads;
7047c478bd9Sstevel@tonic-gate   /* The number of sectors */
7057c478bd9Sstevel@tonic-gate   unsigned long sectors;
7067c478bd9Sstevel@tonic-gate   /* The total number of sectors */
707828d47c1SShidokht Yadegari   unsigned long long total_sectors;
7087c478bd9Sstevel@tonic-gate   /* Device sector size */
7097c478bd9Sstevel@tonic-gate   unsigned long sector_size;
7107c478bd9Sstevel@tonic-gate   /* Flags */
7117c478bd9Sstevel@tonic-gate   unsigned long flags;
7127c478bd9Sstevel@tonic-gate };
7137c478bd9Sstevel@tonic-gate 
7149890706eSHans Rosenfeld extern unsigned long long part_start;
7159890706eSHans Rosenfeld extern unsigned long long part_length;
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate extern int current_slice;
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate extern int buf_drive;
7209890706eSHans Rosenfeld #define BUF_CACHE_INVALID (-1ULL)
7219890706eSHans Rosenfeld extern unsigned long long buf_track;
7227c478bd9Sstevel@tonic-gate extern struct geometry buf_geom;
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate /* these are the current file position and maximum file position */
7257c478bd9Sstevel@tonic-gate extern int filepos;
7267c478bd9Sstevel@tonic-gate extern int filemax;
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate /*
7297c478bd9Sstevel@tonic-gate  *  Common BIOS/boot data.
7307c478bd9Sstevel@tonic-gate  */
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate extern struct multiboot_info mbi;
7337c478bd9Sstevel@tonic-gate extern unsigned long saved_drive;
7347c478bd9Sstevel@tonic-gate extern unsigned long saved_partition;
7357c478bd9Sstevel@tonic-gate extern unsigned long cdrom_drive;
7367c478bd9Sstevel@tonic-gate #ifndef STAGE1_5
7377c478bd9Sstevel@tonic-gate #ifdef SOLARIS_NETBOOT
7387c478bd9Sstevel@tonic-gate extern unsigned long dhcpack_length;
7397c478bd9Sstevel@tonic-gate extern unsigned long dhcpack_buf;
7407c478bd9Sstevel@tonic-gate #endif
7417c478bd9Sstevel@tonic-gate extern unsigned long saved_mem_upper;
7427c478bd9Sstevel@tonic-gate extern unsigned long extended_memory;
7437c478bd9Sstevel@tonic-gate #endif
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate /*
7467c478bd9Sstevel@tonic-gate  *  Error variables.
7477c478bd9Sstevel@tonic-gate  */
7487c478bd9Sstevel@tonic-gate 
7497c478bd9Sstevel@tonic-gate extern grub_error_t errnum;
7507c478bd9Sstevel@tonic-gate extern char *err_list[];
7517c478bd9Sstevel@tonic-gate 
7521fac5a60Ssetje /* don't print geeky noise */
7531fac5a60Ssetje typedef enum
7541fac5a60Ssetje {
7551fac5a60Ssetje   SILENT,
7561fac5a60Ssetje   VERBOSE,
7571fac5a60Ssetje   DEFER_SILENT,
7581fac5a60Ssetje   DEFER_VERBOSE
7591fac5a60Ssetje } silent_status;
7601fac5a60Ssetje 
7611fac5a60Ssetje /* one screen worth of messages 80x24 = 1920 chars -- more with newlines */
7621fac5a60Ssetje #define	SCREENBUF 2000
7631fac5a60Ssetje 
7641fac5a60Ssetje struct silentbuf {
7651fac5a60Ssetje 	silent_status status;
7661fac5a60Ssetje 	int looped;
7671fac5a60Ssetje 	char buffer[SCREENBUF];
7681fac5a60Ssetje 	char *buffer_start;
7691fac5a60Ssetje };
7701fac5a60Ssetje 
7711fac5a60Ssetje extern struct silentbuf silent;
7721fac5a60Ssetje extern int reset_term;
7731fac5a60Ssetje 
7747c478bd9Sstevel@tonic-gate /* Simplify declaration of entry_addr. */
7757c478bd9Sstevel@tonic-gate typedef void (*entry_func) (int, int, int, int, int, int)
7767c478bd9Sstevel@tonic-gate      __attribute__ ((noreturn));
7777c478bd9Sstevel@tonic-gate 
7787c478bd9Sstevel@tonic-gate extern entry_func entry_addr;
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate /* Enter the stage1.5/stage2 C code after the stack is set up. */
7817c478bd9Sstevel@tonic-gate void cmain (void);
7827c478bd9Sstevel@tonic-gate 
7837c478bd9Sstevel@tonic-gate /* Halt the processor (called after an unrecoverable error). */
7847c478bd9Sstevel@tonic-gate void stop (void) __attribute__ ((noreturn));
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate /* Reboot the system.  */
7877c478bd9Sstevel@tonic-gate void grub_reboot (void) __attribute__ ((noreturn));
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate /* Halt the system, using APM if possible. If NO_APM is true, don't use
7907c478bd9Sstevel@tonic-gate    APM even if it is available.  */
7917c478bd9Sstevel@tonic-gate void grub_halt (int no_apm) __attribute__ ((noreturn));
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate /* Copy MAP to the drive map and set up int13_handler.  */
7947c478bd9Sstevel@tonic-gate void set_int13_handler (unsigned short *map);
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate /* Set up int15_handler.  */
7977c478bd9Sstevel@tonic-gate void set_int15_handler (void);
7987c478bd9Sstevel@tonic-gate 
7997c478bd9Sstevel@tonic-gate /* Restore the original int15 handler.  */
8007c478bd9Sstevel@tonic-gate void unset_int15_handler (void);
8017c478bd9Sstevel@tonic-gate 
8027c478bd9Sstevel@tonic-gate /* Track the int13 handler to probe I/O address space.  */
8037c478bd9Sstevel@tonic-gate void track_int13 (int drive);
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate /* The key map.  */
8067c478bd9Sstevel@tonic-gate extern unsigned short bios_key_map[];
8077c478bd9Sstevel@tonic-gate extern unsigned short ascii_key_map[];
8087c478bd9Sstevel@tonic-gate extern unsigned short io_map[];
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate /* calls for direct boot-loader chaining */
8117c478bd9Sstevel@tonic-gate void chain_stage1 (unsigned long segment, unsigned long offset,
8127c478bd9Sstevel@tonic-gate 		   unsigned long part_table_addr)
8137c478bd9Sstevel@tonic-gate      __attribute__ ((noreturn));
8147c478bd9Sstevel@tonic-gate void chain_stage2 (unsigned long segment, unsigned long offset,
8157c478bd9Sstevel@tonic-gate 		   int second_sector)
8167c478bd9Sstevel@tonic-gate      __attribute__ ((noreturn));
8177c478bd9Sstevel@tonic-gate 
8187c478bd9Sstevel@tonic-gate /* do some funky stuff, then boot linux */
8197c478bd9Sstevel@tonic-gate void linux_boot (void) __attribute__ ((noreturn));
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate /* do some funky stuff, then boot bzImage linux */
8227c478bd9Sstevel@tonic-gate void big_linux_boot (void) __attribute__ ((noreturn));
8237c478bd9Sstevel@tonic-gate 
8247c478bd9Sstevel@tonic-gate /* booting a multiboot executable */
8257c478bd9Sstevel@tonic-gate void multi_boot (int start, int mb_info) __attribute__ ((noreturn));
8267c478bd9Sstevel@tonic-gate 
8277c478bd9Sstevel@tonic-gate /* If LINEAR is nonzero, then set the Intel processor to linear mode.
8287c478bd9Sstevel@tonic-gate    Otherwise, bit 20 of all memory accesses is always forced to zero,
8297c478bd9Sstevel@tonic-gate    causing a wraparound effect for bugwards compatibility with the
8307c478bd9Sstevel@tonic-gate    8086 CPU. */
8317c478bd9Sstevel@tonic-gate void gateA20 (int linear);
8327c478bd9Sstevel@tonic-gate 
8337c478bd9Sstevel@tonic-gate /* memory probe routines */
8347c478bd9Sstevel@tonic-gate int get_memsize (int type);
8357c478bd9Sstevel@tonic-gate int get_eisamemsize (void);
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate /* Fetch the next entry in the memory map and return the continuation
8387c478bd9Sstevel@tonic-gate    value.  DESC is a pointer to the descriptor buffer, and CONT is the
8397c478bd9Sstevel@tonic-gate    previous continuation value (0 to get the first entry in the
8407c478bd9Sstevel@tonic-gate    map). */
8417c478bd9Sstevel@tonic-gate int get_mmap_entry (struct mmar_desc *desc, int cont);
8427c478bd9Sstevel@tonic-gate 
8437c478bd9Sstevel@tonic-gate /* Get the linear address of a ROM configuration table. Return zero,
8447c478bd9Sstevel@tonic-gate    if fails.  */
8457c478bd9Sstevel@tonic-gate unsigned long get_rom_config_table (void);
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate /* Get APM BIOS information.  */
8487c478bd9Sstevel@tonic-gate void get_apm_info (void);
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate /* Get VBE controller information.  */
8517c478bd9Sstevel@tonic-gate int get_vbe_controller_info (struct vbe_controller *controller);
8527c478bd9Sstevel@tonic-gate 
8537c478bd9Sstevel@tonic-gate /* Get VBE mode information.  */
8547c478bd9Sstevel@tonic-gate int get_vbe_mode_info (int mode_number, struct vbe_mode *mode);
8557c478bd9Sstevel@tonic-gate 
8567c478bd9Sstevel@tonic-gate /* Set VBE mode.  */
8577c478bd9Sstevel@tonic-gate int set_vbe_mode (int mode_number);
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate /* Return the data area immediately following our code. */
8607c478bd9Sstevel@tonic-gate int get_code_end (void);
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate /* low-level timing info */
8637c478bd9Sstevel@tonic-gate int getrtsecs (void);
8647c478bd9Sstevel@tonic-gate int currticks (void);
8657c478bd9Sstevel@tonic-gate 
8667c478bd9Sstevel@tonic-gate /* Clear the screen. */
8677c478bd9Sstevel@tonic-gate void cls (void);
8687c478bd9Sstevel@tonic-gate 
8697c478bd9Sstevel@tonic-gate /* Turn on/off cursor. */
8707c478bd9Sstevel@tonic-gate int setcursor (int on);
8717c478bd9Sstevel@tonic-gate 
8727c478bd9Sstevel@tonic-gate /* Get the current cursor position (where 0,0 is the top left hand
8737c478bd9Sstevel@tonic-gate    corner of the screen).  Returns packed values, (RET >> 8) is x,
8747c478bd9Sstevel@tonic-gate    (RET & 0xff) is y. */
8757c478bd9Sstevel@tonic-gate int getxy (void);
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate /* Set the cursor position. */
8787c478bd9Sstevel@tonic-gate void gotoxy (int x, int y);
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate /* Displays an ASCII character.  IBM displays will translate some
8817c478bd9Sstevel@tonic-gate    characters to special graphical ones (see the DISP_* constants). */
8827c478bd9Sstevel@tonic-gate void grub_putchar (int c);
8837c478bd9Sstevel@tonic-gate 
8847c478bd9Sstevel@tonic-gate /* Wait for a keypress, and return its packed BIOS/ASCII key code.
8857c478bd9Sstevel@tonic-gate    Use ASCII_CHAR(ret) to extract the ASCII code. */
8867c478bd9Sstevel@tonic-gate int getkey (void);
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate /* Like GETKEY, but doesn't block, and returns -1 if no keystroke is
8897c478bd9Sstevel@tonic-gate    available. */
8907c478bd9Sstevel@tonic-gate int checkkey (void);
8917c478bd9Sstevel@tonic-gate 
8927c478bd9Sstevel@tonic-gate /* Low-level disk I/O */
8937c478bd9Sstevel@tonic-gate int get_diskinfo (int drive, struct geometry *geometry);
8947c478bd9Sstevel@tonic-gate int biosdisk (int subfunc, int drive, struct geometry *geometry,
8959890706eSHans Rosenfeld     unsigned long long sector, int nsec, int segment);
8967c478bd9Sstevel@tonic-gate void stop_floppy (void);
8977c478bd9Sstevel@tonic-gate 
8987c478bd9Sstevel@tonic-gate /* Command-line interface functions. */
8997c478bd9Sstevel@tonic-gate #ifndef STAGE1_5
9007c478bd9Sstevel@tonic-gate 
9017c478bd9Sstevel@tonic-gate /* The flags for the builtins.  */
9027c478bd9Sstevel@tonic-gate #define BUILTIN_CMDLINE		0x1	/* Run in the command-line.  */
9037c478bd9Sstevel@tonic-gate #define BUILTIN_MENU		0x2	/* Run in the menu.  */
9047c478bd9Sstevel@tonic-gate #define BUILTIN_TITLE		0x4	/* Only for the command title.  */
9057c478bd9Sstevel@tonic-gate #define BUILTIN_SCRIPT		0x8	/* Run in the script.  */
9067c478bd9Sstevel@tonic-gate #define BUILTIN_NO_ECHO		0x10	/* Don't print command on booting. */
9077c478bd9Sstevel@tonic-gate #define BUILTIN_HELP_LIST	0x20	/* Show help in listing.  */
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate /* The table for a builtin.  */
9107c478bd9Sstevel@tonic-gate struct builtin
9117c478bd9Sstevel@tonic-gate {
9127c478bd9Sstevel@tonic-gate   /* The command name.  */
9137c478bd9Sstevel@tonic-gate   char *name;
9147c478bd9Sstevel@tonic-gate   /* The callback function.  */
9157c478bd9Sstevel@tonic-gate   int (*func) (char *, int);
9167c478bd9Sstevel@tonic-gate   /* The combination of the flags defined above.  */
9177c478bd9Sstevel@tonic-gate   int flags;
9187c478bd9Sstevel@tonic-gate   /* The short version of the documentation.  */
9197c478bd9Sstevel@tonic-gate   char *short_doc;
9207c478bd9Sstevel@tonic-gate   /* The long version of the documentation.  */
9217c478bd9Sstevel@tonic-gate   char *long_doc;
9227c478bd9Sstevel@tonic-gate };
9237c478bd9Sstevel@tonic-gate 
9247c478bd9Sstevel@tonic-gate /* All the builtins are registered in this.  */
9257c478bd9Sstevel@tonic-gate extern struct builtin *builtin_table[];
9267c478bd9Sstevel@tonic-gate 
9277c478bd9Sstevel@tonic-gate /* The constants for kernel types.  */
9287c478bd9Sstevel@tonic-gate typedef enum
9297c478bd9Sstevel@tonic-gate {
9307c478bd9Sstevel@tonic-gate   KERNEL_TYPE_NONE,		/* None is loaded.  */
9317c478bd9Sstevel@tonic-gate   KERNEL_TYPE_MULTIBOOT,	/* Multiboot.  */
9327c478bd9Sstevel@tonic-gate   KERNEL_TYPE_LINUX,		/* Linux.  */
9337c478bd9Sstevel@tonic-gate   KERNEL_TYPE_BIG_LINUX,	/* Big Linux.  */
9347c478bd9Sstevel@tonic-gate   KERNEL_TYPE_FREEBSD,		/* FreeBSD.  */
9357c478bd9Sstevel@tonic-gate   KERNEL_TYPE_NETBSD,		/* NetBSD.  */
9367c478bd9Sstevel@tonic-gate   KERNEL_TYPE_CHAINLOADER	/* Chainloader.  */
9377c478bd9Sstevel@tonic-gate }
9387c478bd9Sstevel@tonic-gate kernel_t;
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate extern kernel_t kernel_type;
9417c478bd9Sstevel@tonic-gate extern int show_menu;
9427c478bd9Sstevel@tonic-gate extern int grub_timeout;
9437c478bd9Sstevel@tonic-gate 
9447c478bd9Sstevel@tonic-gate void init_builtins (void);
9457c478bd9Sstevel@tonic-gate void init_config (void);
9467c478bd9Sstevel@tonic-gate char *skip_to (int after_equal, char *cmdline);
9477c478bd9Sstevel@tonic-gate struct builtin *find_command (char *command);
9487c478bd9Sstevel@tonic-gate void print_cmdline_message (int forever);
9497c478bd9Sstevel@tonic-gate void enter_cmdline (char *heap, int forever);
9507c478bd9Sstevel@tonic-gate int run_script (char *script, char *heap);
9517c478bd9Sstevel@tonic-gate #endif
9527c478bd9Sstevel@tonic-gate 
9537c478bd9Sstevel@tonic-gate /* C library replacement functions with identical semantics. */
9547c478bd9Sstevel@tonic-gate void grub_printf (const char *format,...);
9557c478bd9Sstevel@tonic-gate int grub_sprintf (char *buffer, const char *format, ...);
9567c478bd9Sstevel@tonic-gate int grub_tolower (int c);
9577c478bd9Sstevel@tonic-gate int grub_isspace (int c);
9587c478bd9Sstevel@tonic-gate int grub_strncat (char *s1, const char *s2, int n);
9597c478bd9Sstevel@tonic-gate void grub_memcpy(void *dest, const void *src, int len);
9607c478bd9Sstevel@tonic-gate void *grub_memmove (void *to, const void *from, int len);
9617c478bd9Sstevel@tonic-gate void *grub_memset (void *start, int c, int len);
9627c478bd9Sstevel@tonic-gate int grub_strncat (char *s1, const char *s2, int n);
9637c478bd9Sstevel@tonic-gate char *grub_strstr (const char *s1, const char *s2);
9647c478bd9Sstevel@tonic-gate int grub_memcmp (const char *s1, const char *s2, int n);
9657c478bd9Sstevel@tonic-gate int grub_strcmp (const char *s1, const char *s2);
9667c478bd9Sstevel@tonic-gate int grub_strlen (const char *str);
9677c478bd9Sstevel@tonic-gate char *grub_strcpy (char *dest, const char *src);
968eb2bd662Svikram char *grub_strchr (char *str, char c);
9697c478bd9Sstevel@tonic-gate 
9701fac5a60Ssetje void noisy_printf (const char *format,...);
9711fac5a60Ssetje 
9727c478bd9Sstevel@tonic-gate #ifndef GRUB_UTIL
9737c478bd9Sstevel@tonic-gate typedef unsigned long grub_jmp_buf[6];
9747c478bd9Sstevel@tonic-gate #else
9757c478bd9Sstevel@tonic-gate /* In the grub shell, use the libc jmp_buf instead.  */
9767c478bd9Sstevel@tonic-gate # include <setjmp.h>
9777c478bd9Sstevel@tonic-gate # define grub_jmp_buf jmp_buf
9787c478bd9Sstevel@tonic-gate #endif
9797c478bd9Sstevel@tonic-gate 
9807c478bd9Sstevel@tonic-gate #ifdef GRUB_UTIL
9817c478bd9Sstevel@tonic-gate # define grub_setjmp	setjmp
9827c478bd9Sstevel@tonic-gate # define grub_longjmp	longjmp
9837c478bd9Sstevel@tonic-gate #else /* ! GRUB_UTIL */
9847c478bd9Sstevel@tonic-gate int grub_setjmp (grub_jmp_buf env);
9857c478bd9Sstevel@tonic-gate void grub_longjmp (grub_jmp_buf env, int val);
9867c478bd9Sstevel@tonic-gate #endif /* ! GRUB_UTIL */
9877c478bd9Sstevel@tonic-gate 
9887c478bd9Sstevel@tonic-gate /* The environment for restarting Stage 2.  */
9897c478bd9Sstevel@tonic-gate extern grub_jmp_buf restart_env;
9907c478bd9Sstevel@tonic-gate /* The environment for restarting the command-line interface.  */
9917c478bd9Sstevel@tonic-gate extern grub_jmp_buf restart_cmdline_env;
9927c478bd9Sstevel@tonic-gate 
9937c478bd9Sstevel@tonic-gate /* misc */
9947c478bd9Sstevel@tonic-gate void init_page (void);
9957c478bd9Sstevel@tonic-gate void print_error (void);
9969890706eSHans Rosenfeld char *convert_to_ascii (char *buf, int c, unsigned long long num);
9977c478bd9Sstevel@tonic-gate int get_cmdline (char *prompt, char *cmdline, int maxlen,
9987c478bd9Sstevel@tonic-gate 		 int echo_char, int history);
9997c478bd9Sstevel@tonic-gate int substring (const char *s1, const char *s2);
10007c478bd9Sstevel@tonic-gate int nul_terminate (char *str);
10017c478bd9Sstevel@tonic-gate int get_based_digit (int c, int base);
10027c478bd9Sstevel@tonic-gate int safe_parse_maxint (char **str_ptr, int *myint_ptr);
100335497fcdSsetje int memcheck (unsigned long start, unsigned long len);
10047c478bd9Sstevel@tonic-gate void grub_putstr (const char *str);
10057c478bd9Sstevel@tonic-gate 
10067c478bd9Sstevel@tonic-gate #ifndef NO_DECOMPRESSION
10077c478bd9Sstevel@tonic-gate /* Compression support. */
10087c478bd9Sstevel@tonic-gate int gunzip_test_header (void);
10097c478bd9Sstevel@tonic-gate int gunzip_read (char *buf, int len);
10107c478bd9Sstevel@tonic-gate #endif /* NO_DECOMPRESSION */
10117c478bd9Sstevel@tonic-gate 
10129890706eSHans Rosenfeld int rawread (int drive, unsigned long long sector, int byte_offset, int byte_len,
1013342440ecSPrasad Singamsetty 	char *buf);
10149890706eSHans Rosenfeld int devread (unsigned long long sector, int byte_offset, int byte_len, char *buf);
10159890706eSHans Rosenfeld int rawwrite (int drive, unsigned long long sector, char *buf);
10169890706eSHans Rosenfeld int devwrite (unsigned long long sector, int sector_len, char *buf);
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate /* Parse a device string and initialize the global parameters. */
10197c478bd9Sstevel@tonic-gate char *set_device (char *device);
10207c478bd9Sstevel@tonic-gate int open_device (void);
10217c478bd9Sstevel@tonic-gate int real_open_partition (int flags);
10227c478bd9Sstevel@tonic-gate int open_partition (void);
10237c478bd9Sstevel@tonic-gate int next_partition (unsigned long drive, unsigned long dest,
10247c478bd9Sstevel@tonic-gate 		    unsigned long *partition, int *type,
10259890706eSHans Rosenfeld 		    unsigned long long *start, unsigned long long *len,
10269890706eSHans Rosenfeld 		    unsigned long long *offset, int *entry,
10279890706eSHans Rosenfeld                    unsigned long long *ext_offset,
10289890706eSHans Rosenfeld                    unsigned long long *gpt_offset, int *gpt_count,
102944bc9120SRichard Yao                    int *gpt_size, char *buf);
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate /* Sets device to the one represented by the SAVED_* parameters. */
10327c478bd9Sstevel@tonic-gate int make_saved_active (void);
10337c478bd9Sstevel@tonic-gate 
10347c478bd9Sstevel@tonic-gate /* Set or clear the current root partition's hidden flag.  */
10357c478bd9Sstevel@tonic-gate int set_partition_hidden_flag (int hidden);
10367c478bd9Sstevel@tonic-gate 
10377c478bd9Sstevel@tonic-gate /* Open a file or directory on the active device, using GRUB's
10387c478bd9Sstevel@tonic-gate    internal filesystem support. */
10397c478bd9Sstevel@tonic-gate int grub_open (char *filename);
10407c478bd9Sstevel@tonic-gate 
10417c478bd9Sstevel@tonic-gate /* Read LEN bytes into BUF from the file that was opened with
10427c478bd9Sstevel@tonic-gate    GRUB_OPEN.  If LEN is -1, read all the remaining data in the file.  */
10437c478bd9Sstevel@tonic-gate int grub_read (char *buf, int len);
10447c478bd9Sstevel@tonic-gate 
10457c478bd9Sstevel@tonic-gate /* Reposition a file offset.  */
10467c478bd9Sstevel@tonic-gate int grub_seek (int offset);
10477c478bd9Sstevel@tonic-gate 
10487c478bd9Sstevel@tonic-gate /* Close a file.  */
10497c478bd9Sstevel@tonic-gate void grub_close (void);
10507c478bd9Sstevel@tonic-gate 
10517c478bd9Sstevel@tonic-gate /* List the contents of the directory that was opened with GRUB_OPEN,
10527c478bd9Sstevel@tonic-gate    printing all completions. */
10537c478bd9Sstevel@tonic-gate int dir (char *dirname);
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate int set_bootdev (int hdbias);
10567c478bd9Sstevel@tonic-gate 
10577c478bd9Sstevel@tonic-gate /* Display statistics on the current active device. */
10587c478bd9Sstevel@tonic-gate void print_fsys_type (void);
10597c478bd9Sstevel@tonic-gate 
10607c478bd9Sstevel@tonic-gate /* Display device and filename completions. */
10617c478bd9Sstevel@tonic-gate void print_a_completion (char *filename);
10627c478bd9Sstevel@tonic-gate int print_completions (int is_filename, int is_completion);
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate /* Copies the current partition data to the desired address. */
10657c478bd9Sstevel@tonic-gate void copy_current_part_entry (char *buf);
10667c478bd9Sstevel@tonic-gate 
10677c478bd9Sstevel@tonic-gate #ifndef STAGE1_5
10687c478bd9Sstevel@tonic-gate void bsd_boot (kernel_t type, int bootdev, char *arg)
10697c478bd9Sstevel@tonic-gate      __attribute__ ((noreturn));
10707c478bd9Sstevel@tonic-gate 
10717c478bd9Sstevel@tonic-gate /* Define flags for load_image here.  */
10727c478bd9Sstevel@tonic-gate /* Don't pass a Linux's mem option automatically.  */
10737c478bd9Sstevel@tonic-gate #define KERNEL_LOAD_NO_MEM_OPTION	(1 << 0)
10747c478bd9Sstevel@tonic-gate 
10757c478bd9Sstevel@tonic-gate kernel_t load_image (char *kernel, char *arg, kernel_t suggested_type,
10767c478bd9Sstevel@tonic-gate 		     unsigned long load_flags);
10777c478bd9Sstevel@tonic-gate 
10787c478bd9Sstevel@tonic-gate int load_module (char *module, char *arg);
10797c478bd9Sstevel@tonic-gate int load_initrd (char *initrd);
10807c478bd9Sstevel@tonic-gate 
10817c478bd9Sstevel@tonic-gate int check_password(char *entered, char* expected, password_t type);
10827c478bd9Sstevel@tonic-gate #endif
10837c478bd9Sstevel@tonic-gate 
10847c478bd9Sstevel@tonic-gate void init_bios_info (void);
10857c478bd9Sstevel@tonic-gate 
10867c478bd9Sstevel@tonic-gate #endif /* ASM_FILE */
10877c478bd9Sstevel@tonic-gate 
10887c478bd9Sstevel@tonic-gate #endif /* ! GRUB_SHARED_HEADER */
1089