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