[coreboot] r63 - in trunk/filo: . configs drivers/newusb include/grub main main/grub util
svn at coreboot.org
svn at coreboot.org
Thu Sep 18 10:04:14 CEST 2008
Author: stepan
Date: 2008-09-18 10:04:13 +0200 (Thu, 18 Sep 2008)
New Revision: 63
Removed:
trunk/filo/include/grub/mb_header.h
trunk/filo/include/grub/mb_info.h
trunk/filo/include/grub/serial.h
trunk/filo/include/grub/term.h
trunk/filo/include/grub/terminfo.h
trunk/filo/include/grub/tparm.h
trunk/filo/main/grub/grubcons.c
trunk/filo/main/grub/serial.c
trunk/filo/main/grub/stage2.c
trunk/filo/main/grub/terminfo.c
trunk/filo/main/grub/tparm.c
Modified:
trunk/filo/Config.in
trunk/filo/configs/config.grub
trunk/filo/configs/config.nogrub
trunk/filo/configs/defconfig
trunk/filo/drivers/newusb/usb.c
trunk/filo/include/grub/shared.h
trunk/filo/main/filo.c
trunk/filo/main/grub/Makefile.inc
trunk/filo/main/grub/builtins.c
trunk/filo/main/grub/char_io.c
trunk/filo/main/grub/cmdline.c
trunk/filo/main/grub/completions.c
trunk/filo/main/grub/grub.c
trunk/filo/main/grub/md5.c
trunk/filo/util/Makefile.inc
trunk/filo/util/vmser.c
Log:
* drop lots of unused files
* use console code from tinycurses rather than duplicating it in FILO
(this also allows multiple consoles at the same time)
* fix configfile command
* cosmetic changes (indent, Makefile fixes, ...)
Modified: trunk/filo/Config.in
===================================================================
--- trunk/filo/Config.in 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/Config.in 2008-09-18 08:04:13 UTC (rev 63)
@@ -160,38 +160,6 @@
endmenu
-menu "Console"
-
-config VGA_CONSOLE
- bool "VGA Text Console"
- default y
-
-config PC_KEYBOARD
- bool "PC Keyboard Support"
- default y
-
-config SERIAL_CONSOLE
- bool "Serial Console"
- default y
-
-config SERIAL_IOBASE
- hex "Serial Console IO base"
- depends on SERIAL_CONSOLE
- default 0x3f8
-
-config SERIAL_SPEED_DEFAULT
- bool "Use default serial speed"
- depends on SERIAL_CONSOLE
- default y
-
-config SERIAL_SPEED
- int "Serial Speed"
- depends on SERIAL_CONSOLE
- depends on !SERIAL_SPEED_DEFAULT
- default 115200
-
-endmenu
-
menu "Filesystems"
config FSYS_EXT2FS
Modified: trunk/filo/configs/config.grub
===================================================================
--- trunk/filo/configs/config.grub 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/configs/config.grub 2008-09-18 08:04:13 UTC (rev 63)
@@ -30,15 +30,6 @@
# CONFIG_SUPPORT_SOUND is not set
#
-# Console
-#
-CONFIG_VGA_CONSOLE=y
-CONFIG_PC_KEYBOARD=y
-CONFIG_SERIAL_CONSOLE=y
-CONFIG_SERIAL_IOBASE=0x3f8
-CONFIG_SERIAL_SPEED_DEFAULT=y
-
-#
# Filesystems
#
CONFIG_FSYS_EXT2FS=y
Modified: trunk/filo/configs/config.nogrub
===================================================================
--- trunk/filo/configs/config.nogrub 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/configs/config.nogrub 2008-09-18 08:04:13 UTC (rev 63)
@@ -27,15 +27,6 @@
# CONFIG_SUPPORT_SOUND is not set
#
-# Console
-#
-CONFIG_VGA_CONSOLE=y
-CONFIG_PC_KEYBOARD=y
-CONFIG_SERIAL_CONSOLE=y
-CONFIG_SERIAL_IOBASE=0x3f8
-CONFIG_SERIAL_SPEED_DEFAULT=y
-
-#
# Filesystems
#
CONFIG_FSYS_EXT2FS=y
Modified: trunk/filo/configs/defconfig
===================================================================
--- trunk/filo/configs/defconfig 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/configs/defconfig 2008-09-18 08:04:13 UTC (rev 63)
@@ -30,15 +30,6 @@
# CONFIG_SUPPORT_SOUND is not set
#
-# Console
-#
-CONFIG_VGA_CONSOLE=y
-CONFIG_PC_KEYBOARD=y
-CONFIG_SERIAL_CONSOLE=y
-CONFIG_SERIAL_IOBASE=0x3f8
-CONFIG_SERIAL_SPEED_DEFAULT=y
-
-#
# Filesystems
#
CONFIG_FSYS_EXT2FS=y
Modified: trunk/filo/drivers/newusb/usb.c
===================================================================
--- trunk/filo/drivers/newusb/usb.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/drivers/newusb/usb.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,6 +1,8 @@
/*
* This file is part of FILO.
*
+ * Copyright (C) 2008 coresystems GmbH
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
Deleted: trunk/filo/include/grub/mb_header.h
===================================================================
--- trunk/filo/include/grub/mb_header.h 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/include/grub/mb_header.h 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,90 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2000 Free Software Foundation, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * MultiBoot Header description
- */
-
-struct multiboot_header
-{
- /* Must be MULTIBOOT_MAGIC - see below. */
- unsigned magic;
-
- /* Feature flags - see below. */
- unsigned flags;
-
- /*
- * Checksum
- *
- * The above fields plus this one must equal 0 mod 2^32.
- */
- unsigned checksum;
-
- /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
- unsigned header_addr;
- unsigned load_addr;
- unsigned load_end_addr;
- unsigned bss_end_addr;
- unsigned entry_addr;
-
- /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
- unsigned mode_type;
- unsigned width;
- unsigned height;
- unsigned depth;
-};
-
-/*
- * The entire multiboot_header must be contained
- * within the first MULTIBOOT_SEARCH bytes of the kernel image.
- */
-#define MULTIBOOT_SEARCH 8192
-#define MULTIBOOT_FOUND(addr, len) \
- (! ((addr) & 0x3) \
- && (len) >= 12 \
- && *((int *) (addr)) == MULTIBOOT_MAGIC \
- && ! (*((unsigned *) (addr)) + *((unsigned *) (addr + 4)) \
- + *((unsigned *) (addr + 8))) \
- && (! (MULTIBOOT_AOUT_KLUDGE & *((int *) (addr + 4))) || (len) >= 32) \
- && (! (MULTIBOOT_VIDEO_MODE & *((int *) (addr + 4))) || (len) >= 48))
-
-/* Magic value identifying the multiboot_header. */
-#define MULTIBOOT_MAGIC 0x1BADB002
-
-/*
- * Features flags for 'flags'.
- * If a boot loader sees a flag in MULTIBOOT_MUSTKNOW set
- * and it doesn't understand it, it must fail.
- */
-#define MULTIBOOT_MUSTKNOW 0x0000FFFF
-
-/* currently unsupported flags... this is a kind of version number. */
-#define MULTIBOOT_UNSUPPORTED 0x0000FFF8
-
-/* Align all boot modules on i386 page (4KB) boundaries. */
-#define MULTIBOOT_PAGE_ALIGN 0x00000001
-
-/* Must pass memory information to OS. */
-#define MULTIBOOT_MEMORY_INFO 0x00000002
-
-/* Must pass video information to OS. */
-#define MULTIBOOT_VIDEO_MODE 0x00000004
-
-/* This flag indicates the use of the address fields in the header. */
-#define MULTIBOOT_AOUT_KLUDGE 0x00010000
Deleted: trunk/filo/include/grub/mb_info.h
===================================================================
--- trunk/filo/include/grub/mb_info.h 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/include/grub/mb_info.h 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,217 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2000,2003 Free Software Foundation, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * The structure type "mod_list" is used by the "multiboot_info" structure.
- */
-
-struct mod_list
-{
- /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
- unsigned long mod_start;
- unsigned long mod_end;
-
- /* Module command line */
- unsigned long cmdline;
-
- /* padding to take it to 16 bytes (must be zero) */
- unsigned long pad;
-};
-
-
-/*
- * INT-15, AX=E820 style "AddressRangeDescriptor"
- * ...with a "size" parameter on the front which is the structure size - 4,
- * pointing to the next one, up until the full buffer length of the memory
- * map has been reached.
- */
-
-struct AddrRangeDesc
-{
- unsigned long size;
- unsigned long long BaseAddr;
- unsigned long long Length;
- unsigned long Type;
-
- /* unspecified optional padding... */
-} __attribute__ ((packed));
-
-/* usable memory "Type", all others are reserved. */
-#define MB_ARD_MEMORY 1
-
-
-/* Drive Info structure. */
-struct drive_info
-{
- /* The size of this structure. */
- unsigned long size;
-
- /* The BIOS drive number. */
- unsigned char drive_number;
-
- /* The access mode (see below). */
- unsigned char drive_mode;
-
- /* The BIOS geometry. */
- unsigned short drive_cylinders;
- unsigned char drive_heads;
- unsigned char drive_sectors;
-
- /* The array of I/O ports used for the drive. */
- unsigned short drive_ports[0];
-};
-
-/* Drive Mode. */
-#define MB_DI_CHS_MODE 0
-#define MB_DI_LBA_MODE 1
-
-
-/* APM BIOS info. */
-struct apm_info
-{
- unsigned short version;
- unsigned short cseg;
- unsigned long offset;
- unsigned short cseg_16;
- unsigned short dseg_16;
- unsigned short cseg_len;
- unsigned short cseg_16_len;
- unsigned short dseg_16_len;
-};
-
-
-/*
- * MultiBoot Info description
- *
- * This is the struct passed to the boot image. This is done by placing
- * its address in the EAX register.
- */
-
-struct multiboot_info
-{
- /* MultiBoot info version number */
- unsigned long flags;
-
- /* Available memory from BIOS */
- unsigned long mem_lower;
- unsigned long mem_upper;
-
- /* "root" partition */
- unsigned long boot_device;
-
- /* Kernel command line */
- unsigned long cmdline;
-
- /* Boot-Module list */
- unsigned long mods_count;
- unsigned long mods_addr;
-
- union
- {
- struct
- {
- /* (a.out) Kernel symbol table info */
- unsigned long tabsize;
- unsigned long strsize;
- unsigned long addr;
- unsigned long pad;
- }
- a;
-
- struct
- {
- /* (ELF) Kernel section header table */
- unsigned long num;
- unsigned long size;
- unsigned long addr;
- unsigned long shndx;
- }
- e;
- }
- syms;
-
- /* Memory Mapping buffer */
- unsigned long mmap_length;
- unsigned long mmap_addr;
-
- /* Drive Info buffer */
- unsigned long drives_length;
- unsigned long drives_addr;
-
- /* ROM configuration table */
- unsigned long config_table;
-
- /* Boot Loader Name */
- unsigned long boot_loader_name;
-
- /* APM table */
- unsigned long apm_table;
-
- /* Video */
- unsigned long vbe_control_info;
- unsigned long vbe_mode_info;
- unsigned short vbe_mode;
- unsigned short vbe_interface_seg;
- unsigned short vbe_interface_off;
- unsigned short vbe_interface_len;
-};
-
-/*
- * Flags to be set in the 'flags' parameter above
- */
-
-/* is there basic lower/upper memory information? */
-#define MB_INFO_MEMORY 0x00000001
-/* is there a boot device set? */
-#define MB_INFO_BOOTDEV 0x00000002
-/* is the command-line defined? */
-#define MB_INFO_CMDLINE 0x00000004
-/* are there modules to do something with? */
-#define MB_INFO_MODS 0x00000008
-
-/* These next two are mutually exclusive */
-
-/* is there a symbol table loaded? */
-#define MB_INFO_AOUT_SYMS 0x00000010
-/* is there an ELF section header table? */
-#define MB_INFO_ELF_SHDR 0x00000020
-
-/* is there a full memory map? */
-#define MB_INFO_MEM_MAP 0x00000040
-
-/* Is there drive info? */
-#define MB_INFO_DRIVE_INFO 0x00000080
-
-/* Is there a config table? */
-#define MB_INFO_CONFIG_TABLE 0x00000100
-
-/* Is there a boot loader name? */
-#define MB_INFO_BOOT_LOADER_NAME 0x00000200
-
-/* Is there a APM table? */
-#define MB_INFO_APM_TABLE 0x00000400
-
-/* Is there video information? */
-#define MB_INFO_VIDEO_INFO 0x00000800
-
-/*
- * The following value must be present in the EAX register.
- */
-
-#define MULTIBOOT_VALID 0x2BADB002
Deleted: trunk/filo/include/grub/serial.h
===================================================================
--- trunk/filo/include/grub/serial.h 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/include/grub/serial.h 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,87 +0,0 @@
-/* serial.h - serial device interface */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef GRUB_SERIAL_HEADER
-#define GRUB_SERIAL_HEADER 1
-
-/* Macros. */
-
-/* The offsets of UART registers. */
-#define UART_TX 0
-#define UART_RX 0
-#define UART_DLL 0
-#define UART_IER 1
-#define UART_DLH 1
-#define UART_IIR 2
-#define UART_FCR 2
-#define UART_LCR 3
-#define UART_MCR 4
-#define UART_LSR 5
-#define UART_MSR 6
-#define UART_SR 7
-
-/* For LSR bits. */
-#define UART_DATA_READY 0x01
-#define UART_EMPTY_TRANSMITTER 0x20
-
-/* The type of parity. */
-#define UART_NO_PARITY 0x00
-#define UART_ODD_PARITY 0x08
-#define UART_EVEN_PARITY 0x18
-
-/* The type of word length. */
-#define UART_5BITS_WORD 0x00
-#define UART_6BITS_WORD 0x01
-#define UART_7BITS_WORD 0x02
-#define UART_8BITS_WORD 0x03
-
-/* The type of the length of stop bit. */
-#define UART_1_STOP_BIT 0x00
-#define UART_2_STOP_BITS 0x04
-
-/* the switch of DLAB. */
-#define UART_DLAB 0x80
-
-/* Enable the FIFO. */
-#define UART_ENABLE_FIFO 0xC7
-
-/* Turn on DTR, RTS, and OUT2. */
-#define UART_ENABLE_MODEM 0x0B
-
-
-/* Function prototypes. */
-
-/* Fetch a key. */
-int serial_hw_fetch (void);
-
-/* Put a character. */
-void serial_hw_put (int c);
-
-/* Insert a delay. */
-void serial_hw_delay (void);
-
-/* Return the port number for the UNITth serial device. */
-unsigned short serial_hw_get_port (int unit);
-
-/* Initialize a serial device. */
-int serial_hw_init (unsigned short port, unsigned int speed,
- int word_len, int parity, int stop_bit_len);
-
-#endif /* ! GRUB_SERIAL_HEADER */
Modified: trunk/filo/include/grub/shared.h
===================================================================
--- trunk/filo/include/grub/shared.h 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/include/grub/shared.h 2008-09-18 08:04:13 UTC (rev 63)
@@ -2,6 +2,7 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ * Copyright (C) 2005-2008 coresystems GmbH
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,19 +19,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/*
- * Generic defines to use anywhere
- */
-
#ifndef GRUB_SHARED_HEADER
-#define GRUB_SHARED_HEADER 1
+#define GRUB_SHARED_HEADER
-void grub_main(void);
-
-/* Maybe redirect memory requests through grub_scratch_mem. */
-# define RAW_ADDR(x) (x)
-# define RAW_SEG(x) (x)
-
/*
* Integer sizes
*/
@@ -42,253 +33,50 @@
#define MAX_CMDLINE 1600
#define NEW_HEAPSIZE 1500
-/* 512-byte scratch area */
-#define SCRATCHADDR RAW_ADDR (0x77e00)
-#define SCRATCHSEG RAW_SEG (0x77e0)
-
-/*
- * This is the location of the raw device buffer. It is 31.5K
- * in size.
- */
-
-#define BUFFERLEN 0x7e00
-#define BUFFERADDR RAW_ADDR (0x70000)
-#define BUFFERSEG RAW_SEG (0x7000)
-
-#define BOOT_PART_TABLE RAW_ADDR (0x07be)
-
-/*
- * BIOS disk defines
- */
-#define BIOSDISK_READ 0x0
-#define BIOSDISK_WRITE 0x1
-#define BIOSDISK_ERROR_GEOMETRY 0x100
-#define BIOSDISK_FLAG_LBA_EXTENSION 0x1
-#define BIOSDISK_FLAG_CDROM 0x2
-
-/*
- * This is the filesystem (not raw device) buffer.
- * It is 32K in size, do not overrun!
- */
-
-#define FSYS_BUFLEN 0x8000
-#define FSYS_BUF RAW_ADDR (0x68000)
-
-/* Command-line buffer for Multiboot kernels and modules. This area
- includes the area into which Stage 1.5 and Stage 1 are loaded, but
- that's no problem. */
-#define MB_CMDLINE_BUF RAW_ADDR (0x2000)
-#define MB_CMDLINE_BUFLEN 0x6000
-
/* The buffer for the password. */
-#define PASSWORD_BUF RAW_ADDR (0x78000)
+extern char PASSWORD_BUF[];
#define PASSWORD_BUFLEN 0x200
/* THe buffer for the filename of "/boot/grub/default". */
-#define DEFAULT_FILE_BUF (PASSWORD_BUF + PASSWORD_BUFLEN)
+extern char DEFAULT_FILE_BUF[];
#define DEFAULT_FILE_BUFLEN 0x60
/* The buffer for the command-line. */
-#define CMDLINE_BUF (DEFAULT_FILE_BUF + DEFAULT_FILE_BUFLEN)
+extern char CMDLINE_BUF[];
#define CMDLINE_BUFLEN MAX_CMDLINE
-/* The kill buffer for the command-line. */
-#define KILL_BUF (CMDLINE_BUF + CMDLINE_BUFLEN)
-#define KILL_BUFLEN MAX_CMDLINE
-
/* The history buffer for the command-line. */
-#define HISTORY_BUF (KILL_BUF + KILL_BUFLEN)
+extern char HISTORY_BUF[];
#define HISTORY_SIZE 5
#define HISTORY_BUFLEN (MAX_CMDLINE * HISTORY_SIZE)
/* The buffer for the completion. */
-#define COMPLETION_BUF (HISTORY_BUF + HISTORY_BUFLEN)
+extern char COMPLETION_BUF[];
#define COMPLETION_BUFLEN MAX_CMDLINE
/* The buffer for the unique string. */
-#define UNIQUE_BUF (COMPLETION_BUF + COMPLETION_BUFLEN)
#define UNIQUE_BUFLEN MAX_CMDLINE
/* The buffer for the menu entries. */
-#define MENU_BUF (UNIQUE_BUF + UNIQUE_BUFLEN)
-#define MENU_BUFLEN (0x8000 + PASSWORD_BUF - MENU_BUF)
+extern char MENU_BUF[];
+#define MENU_BUFLEN 0x1000
-/* The size of the drive map. */
-#define DRIVE_MAP_SIZE 8
+/* The kill buffer */
+extern char KILL_BUF[];
+#define KILL_BUFLEN MAX_CMDLINE
-/* The size of the key map. */
-#define KEY_MAP_SIZE 128
-
-/* The size of the io map. */
-#define IO_MAP_SIZE 128
-
/*
- * Linux setup parameters
- */
-
-#define LINUX_MAGIC_SIGNATURE 0x53726448 /* "HdrS" */
-#define LINUX_DEFAULT_SETUP_SECTS 4
-#define LINUX_FLAG_CAN_USE_HEAP 0x80
-#define LINUX_INITRD_MAX_ADDRESS 0x38000000
-#define LINUX_MAX_SETUP_SECTS 64
-#define LINUX_BOOT_LOADER_TYPE 0x71
-#define LINUX_HEAP_END_OFFSET (0x9000 - 0x200)
-
-#define LINUX_BZIMAGE_ADDR RAW_ADDR (0x100000)
-#define LINUX_ZIMAGE_ADDR RAW_ADDR (0x10000)
-#define LINUX_OLD_REAL_MODE_ADDR RAW_ADDR (0x90000)
-#define LINUX_SETUP_STACK 0x9000
-
-#define LINUX_FLAG_BIG_KERNEL 0x1
-
-/* Linux's video mode selection support. Actually I hate it! */
-#define LINUX_VID_MODE_NORMAL 0xFFFF
-#define LINUX_VID_MODE_EXTENDED 0xFFFE
-#define LINUX_VID_MODE_ASK 0xFFFD
-
-#define LINUX_CL_OFFSET 0x9000
-#define LINUX_CL_END_OFFSET 0x90FF
-#define LINUX_SETUP_MOVE_SIZE 0x9100
-#define LINUX_CL_MAGIC 0xA33F
-
-/*
- * General disk stuff
- */
-
-#define SECTOR_SIZE 0x200
-#define SECTOR_BITS 9
-#define BIOS_FLAG_FIXED_DISK 0x80
-
-#define BOOTSEC_LOCATION RAW_ADDR (0x7C00)
-#define BOOTSEC_SIGNATURE 0xAA55
-#define BOOTSEC_BPB_OFFSET 0x3
-#define BOOTSEC_BPB_LENGTH 0x3B
-#define BOOTSEC_BPB_SYSTEM_ID 0x3
-#define BOOTSEC_BPB_HIDDEN_SECTORS 0x1C
-#define BOOTSEC_PART_OFFSET 0x1BE
-#define BOOTSEC_PART_LENGTH 0x40
-#define BOOTSEC_SIG_OFFSET 0x1FE
-#define BOOTSEC_LISTSIZE 8
-
-/* Not bad, perhaps. */
-#define NETWORK_DRIVE 0x20
-
-/*
* GRUB specific information
* (in LSB order)
*/
#define GRUB_INVALID_DRIVE 0xFF
-// #include <stage1.h>
-
-#define STAGE2_VER_MAJ_OFFS 0x6
-#define STAGE2_INSTALLPART 0x8
-#define STAGE2_SAVED_ENTRYNO 0xc
-#define STAGE2_STAGE2_ID 0x10
-#define STAGE2_FORCE_LBA 0x11
-#define STAGE2_VER_STR_OFFS 0x12
-
-/* Stage 2 identifiers */
-#define STAGE2_ID_STAGE2 0
-#define STAGE2_ID_FFS_STAGE1_5 1
-#define STAGE2_ID_E2FS_STAGE1_5 2
-#define STAGE2_ID_FAT_STAGE1_5 3
-#define STAGE2_ID_MINIX_STAGE1_5 4
-#define STAGE2_ID_REISERFS_STAGE1_5 5
-#define STAGE2_ID_VSTAFS_STAGE1_5 6
-#define STAGE2_ID_JFS_STAGE1_5 7
-#define STAGE2_ID_XFS_STAGE1_5 8
-#define STAGE2_ID_ISO9660_STAGE1_5 9
-#define STAGE2_ID_UFS2_STAGE1_5 10
-
-# define STAGE2_ID STAGE2_ID_STAGE2
-
-/*
- * defines for use when switching between real and protected mode
- */
-
-#define CR0_PE_ON 0x1
-#define CR0_PE_OFF 0xfffffffe
-#define PROT_MODE_CSEG 0x8
-#define PROT_MODE_DSEG 0x10
-#define PSEUDO_RM_CSEG 0x18
-#define PSEUDO_RM_DSEG 0x20
-#define STACKOFF (0x2000 - 0x10)
-#define PROTSTACKINIT (FSYS_BUF - 0x10)
-
-
-#define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
-#define K_STATUS 0x64 /* keyboard status */
-#define K_CMD 0x64 /* keybd ctlr command (write-only) */
-
-#define K_OBUF_FUL 0x01 /* output buffer full */
-#define K_IBUF_FUL 0x02 /* input buffer full */
-
-#define KC_CMD_WIN 0xd0 /* read output port */
-#define KC_CMD_WOUT 0xd1 /* write output port */
-#define KB_OUTPUT_MASK 0xdd /* enable output buffer full interrupt
- enable data line
- enable clock line */
-#define KB_A20_ENABLE 0x02
-
/* Codes for getchar. */
#define ASCII_CHAR(x) ((x) & 0xFF)
-#warning "CURSES keys fundamentally different from libpayload's"
-// And that's why we can't just do
-// # include <curses.h>
-# define KEY_LEFT 0x4B00
-# define KEY_RIGHT 0x4D00
-# define KEY_UP 0x4800
-# define KEY_DOWN 0x5000
-# define KEY_IC 0x5200 /* insert char */
-# define KEY_DC 0x5300 /* delete char */
-# define KEY_BACKSPACE 0x0008
-# define KEY_HOME 0x4700
-# define KEY_END 0x4F00
-# define KEY_NPAGE 0x5100
-# define KEY_PPAGE 0x4900
-# define A_NORMAL 0x7
-# define A_REVERSE 0x70
+# include <curses.h>
-/* In old BSD curses, A_NORMAL and A_REVERSE are not defined, so we
- define them here if they are undefined. */
-#ifndef A_NORMAL
-# define A_NORMAL 0
-#endif /* ! A_NORMAL */
-#ifndef A_REVERSE
-# ifdef A_STANDOUT
-# define A_REVERSE A_STANDOUT
-# else /* ! A_STANDOUT */
-# define A_REVERSE 0
-# endif /* ! A_STANDOUT */
-#endif /* ! A_REVERSE */
-
-/* Define ACS_* ourselves, since the definitions are not consistent among
- various curses implementations. */
-#undef ACS_ULCORNER
-#undef ACS_URCORNER
-#undef ACS_LLCORNER
-#undef ACS_LRCORNER
-#undef ACS_HLINE
-#undef ACS_VLINE
-#undef ACS_LARROW
-#undef ACS_RARROW
-#undef ACS_UARROW
-#undef ACS_DARROW
-
-#define ACS_ULCORNER '+'
-#define ACS_URCORNER '+'
-#define ACS_LLCORNER '+'
-#define ACS_LRCORNER '+'
-#define ACS_HLINE '-'
-#define ACS_VLINE '|'
-#define ACS_LARROW '<'
-#define ACS_RARROW '>'
-#define ACS_UARROW '^'
-#define ACS_DARROW 'v'
-
/* Special graphics characters for IBM displays. */
#define DISP_UL 218
#define DISP_UR 191
@@ -301,165 +89,6 @@
#define DISP_UP 0x18
#define DISP_DOWN 0x19
-/* Remap some libc-API-compatible function names so that we prevent
- circularararity. */
-#ifndef WITHOUT_LIBC_STUBS
-#undef putchar
-#define putchar grub_putchar
-
-/* Instead, for FILO we map the grub_ functions to
- * "normal" functions:
- */
-
-#define grub_isspace isspace
-#define grub_memcmp memcmp
-#define grub_memmove memmove
-#define grub_memset memset
-#define grub_strcpy strcpy
-#define grub_strstr strstr
-#define grub_strcmp strcmp
-#define grub_strlen strlen
-#define grub_strncat strncat
-#define grub_sprintf sprintf
-
-#define grub_open file_open
-#define grub_read file_read
-#define grub_seek file_seek
-#define grub_close file_close
-#endif /* WITHOUT_LIBC_STUBS */
-
-#ifndef ASM_FILE
-/*
- * Below this should be ONLY defines and other constructs for C code.
- */
-
-/* multiboot stuff */
-
-#include "grub/mb_header.h"
-#include "grub/mb_info.h"
-
-/* For the Linux/i386 boot protocol version 2.03. */
-struct linux_kernel_header
-{
- char code1[0x0020];
- unsigned short cl_magic; /* Magic number 0xA33F */
- unsigned short cl_offset; /* The offset of command line */
- char code2[0x01F1 - 0x0020 - 2 - 2];
- unsigned char setup_sects; /* The size of the setup in sectors */
- unsigned short root_flags; /* If the root is mounted readonly */
- unsigned short syssize; /* obsolete */
- unsigned short swap_dev; /* obsolete */
- unsigned short ram_size; /* obsolete */
- unsigned short vid_mode; /* Video mode control */
- unsigned short root_dev; /* Default root device number */
- unsigned short boot_flag; /* 0xAA55 magic number */
- unsigned short jump; /* Jump instruction */
- unsigned long header; /* Magic signature "HdrS" */
- unsigned short version; /* Boot protocol version supported */
- unsigned long realmode_swtch; /* Boot loader hook */
- unsigned long start_sys; /* Points to kernel version string */
- unsigned char type_of_loader; /* Boot loader identifier */
- unsigned char loadflags; /* Boot protocol option flags */
- unsigned short setup_move_size; /* Move to high memory size */
- unsigned long code32_start; /* Boot loader hook */
- unsigned long ramdisk_image; /* initrd load address */
- unsigned long ramdisk_size; /* initrd size */
- unsigned long bootsect_kludge; /* obsolete */
- unsigned short heap_end_ptr; /* Free memory after setup end */
- unsigned short pad1; /* Unused */
- char *cmd_line_ptr; /* Points to the kernel command line */
- unsigned long initrd_addr_max; /* The highest address of initrd */
-} __attribute__ ((packed));
-
-/* Memory map address range descriptor used by GET_MMAP_ENTRY. */
-struct mmar_desc
-{
- unsigned long desc_len; /* Size of this descriptor. */
- unsigned long long addr; /* Base address. */
- unsigned long long length; /* Length in bytes. */
- unsigned long type; /* Type of address range. */
-} __attribute__ ((packed));
-
-/* VBE controller information. */
-struct vbe_controller
-{
- unsigned char signature[4];
- unsigned short version;
- unsigned long oem_string;
- unsigned long capabilities;
- unsigned long video_mode;
- unsigned short total_memory;
- unsigned short oem_software_rev;
- unsigned long oem_vendor_name;
- unsigned long oem_product_name;
- unsigned long oem_product_rev;
- unsigned char reserved[222];
- unsigned char oem_data[256];
-} __attribute__ ((packed));
-
-/* VBE mode information. */
-struct vbe_mode
-{
- unsigned short mode_attributes;
- unsigned char win_a_attributes;
- unsigned char win_b_attributes;
- unsigned short win_granularity;
- unsigned short win_size;
- unsigned short win_a_segment;
- unsigned short win_b_segment;
- unsigned long win_func;
- unsigned short bytes_per_scanline;
-
- /* >=1.2 */
- unsigned short x_resolution;
- unsigned short y_resolution;
- unsigned char x_char_size;
- unsigned char y_char_size;
- unsigned char number_of_planes;
- unsigned char bits_per_pixel;
- unsigned char number_of_banks;
- unsigned char memory_model;
- unsigned char bank_size;
- unsigned char number_of_image_pages;
- unsigned char reserved0;
-
- /* direct color */
- unsigned char red_mask_size;
- unsigned char red_field_position;
- unsigned char green_mask_size;
- unsigned char green_field_position;
- unsigned char blue_mask_size;
- unsigned char blue_field_position;
- unsigned char reserved_mask_size;
- unsigned char reserved_field_position;
- unsigned char direct_color_mode_info;
-
- /* >=2.0 */
- unsigned long phys_base;
- unsigned long reserved1;
- unsigned short reversed2;
-
- /* >=3.0 */
- unsigned short linear_bytes_per_scanline;
- unsigned char banked_number_of_image_pages;
- unsigned char linear_number_of_image_pages;
- unsigned char linear_red_mask_size;
- unsigned char linear_red_field_position;
- unsigned char linear_green_mask_size;
- unsigned char linear_green_field_position;
- unsigned char linear_blue_mask_size;
- unsigned char linear_blue_field_position;
- unsigned char linear_reserved_mask_size;
- unsigned char linear_reserved_field_position;
- unsigned long max_pixel_clock;
-
- unsigned char reserved3[189];
-} __attribute__ ((packed));
-
-
-#undef NULL
-#define NULL ((void *) 0)
-
/* Error codes (descriptions are in common.c) */
typedef enum
{
@@ -503,18 +132,8 @@
MAX_ERR_NUM
} grub_error_t;
-extern unsigned long install_partition;
-extern unsigned long boot_drive;
-extern unsigned long install_second_sector;
-extern struct apm_info apm_bios_info;
-extern unsigned long boot_part_addr;
extern int saved_entryno;
-extern unsigned char force_lba;
-extern char version_string[];
extern char config_file[];
-extern unsigned long linux_text_len;
-extern char *linux_data_tmp_addr;
-extern char *linux_data_real_addr;
/* GUI interface variables. */
# define MAX_FALLBACK_ENTRIES 8
@@ -529,8 +148,7 @@
PASSWORD_PLAIN,
PASSWORD_MD5,
PASSWORD_UNSUPPORTED
-}
-password_t;
+} password_t;
extern char *password;
extern password_t password_type;
@@ -542,163 +160,41 @@
extern int count_lines;
extern int use_pager;
-#ifndef NO_DECOMPRESSION
-extern int no_decompression;
-extern int compressed_file;
-#endif
-
-/* instrumentation variables */
-extern void (*disk_read_hook) (int, int, int);
-extern void (*disk_read_func) (int, int, int);
-
-extern unsigned long current_drive;
-extern unsigned long current_partition;
-
-extern int fsys_type;
-
-/* The information for a disk geometry. The CHS information is only for
- DOS/Partition table compatibility, and the real number of sectors is
- stored in TOTAL_SECTORS. */
-struct geometry
-{
- /* The number of cylinders */
- unsigned long cylinders;
- /* The number of heads */
- unsigned long heads;
- /* The number of sectors */
- unsigned long sectors;
- /* The total number of sectors */
- unsigned long total_sectors;
- /* Device sector size */
- unsigned long sector_size;
- /* Flags */
- unsigned long flags;
-};
-
-extern unsigned long part_start;
-extern unsigned long part_length;
-
-extern int current_slice;
-
-extern int buf_drive;
-extern int buf_track;
-extern struct geometry buf_geom;
-
-/* these are the current file position and maximum file position */
-extern int filepos;
-extern int filemax;
-
/*
- * Common BIOS/boot data.
- */
-
-extern struct multiboot_info mbi;
-extern unsigned long saved_drive;
-extern unsigned long saved_partition;
-extern unsigned long cdrom_drive;
-extern unsigned long saved_mem_upper;
-extern unsigned long extended_memory;
-
-/*
* Error variables.
*/
extern grub_error_t errnum;
extern char *err_list[];
-/* Simplify declaration of entry_addr. */
-typedef void (*entry_func) (int, int, int, int, int, int)
- __attribute__ ((noreturn));
+/* Terminal */
+extern int terminal_flags;
-extern entry_func entry_addr;
+/* These are used to represent the various color states we use */
+typedef enum
+{
+ /* represents the color used to display all text that does not use the user
+ * defined colors below
+ */
+ COLOR_STATE_STANDARD,
+ /* represents the user defined colors for normal text */
+ COLOR_STATE_NORMAL,
+ /* represents the user defined colors for highlighted text */
+ COLOR_STATE_HIGHLIGHT
+} color_state;
-/* Enter the stage1.5/stage2 C code after the stack is set up. */
-void cmain (void);
+/* Flags for representing the capabilities of a terminal. */
-/* Halt the processor (called after an unrecoverable error). */
-void stop (void) __attribute__ ((noreturn));
+/* Set when input characters shouldn't be echoed back. */
+#define TERM_NO_ECHO (1 << 0)
+/* Set when the editing feature should be disabled. */
+#define TERM_NO_EDIT (1 << 1)
-/* Reboot the system. */
-void grub_reboot (void) __attribute__ ((noreturn));
+/* The console stuff. */
+void console_putchar (int c);
+void console_setcolorstate (color_state state);
+void console_setcolor (int normal_color, int highlight_color);
-/* Halt the system, using APM if possible. If NO_APM is true, don't use
- APM even if it is available. */
-void grub_halt (int no_apm) __attribute__ ((noreturn));
-
-/* Copy MAP to the drive map and set up int13_handler. */
-void set_int13_handler (unsigned short *map);
-
-/* Set up int15_handler. */
-void set_int15_handler (void);
-
-/* Restore the original int15 handler. */
-void unset_int15_handler (void);
-
-/* Track the int13 handler to probe I/O address space. */
-void track_int13 (int drive);
-
-/* The key map. */
-extern unsigned short bios_key_map[];
-extern unsigned short ascii_key_map[];
-extern unsigned short io_map[];
-
-/* calls for direct boot-loader chaining */
-void chain_stage1 (unsigned long segment, unsigned long offset,
- unsigned long part_table_addr)
- __attribute__ ((noreturn));
-void chain_stage2 (unsigned long segment, unsigned long offset,
- int second_sector)
- __attribute__ ((noreturn));
-
-/* do some funky stuff, then boot linux */
-void linux_boot (void) __attribute__ ((noreturn));
-
-/* do some funky stuff, then boot bzImage linux */
-void big_linux_boot (void) __attribute__ ((noreturn));
-
-/* booting a multiboot executable */
-void multi_boot (int start, int mb_info) __attribute__ ((noreturn));
-
-/* If LINEAR is nonzero, then set the Intel processor to linear mode.
- Otherwise, bit 20 of all memory accesses is always forced to zero,
- causing a wraparound effect for bugwards compatibility with the
- 8086 CPU. */
-void gateA20 (int linear);
-
-/* memory probe routines */
-int get_memsize (int type);
-int get_eisamemsize (void);
-
-/* Fetch the next entry in the memory map and return the continuation
- value. DESC is a pointer to the descriptor buffer, and CONT is the
- previous continuation value (0 to get the first entry in the
- map). */
-int get_mmap_entry (struct mmar_desc *desc, int cont);
-
-/* Get the linear address of a ROM configuration table. Return zero,
- if fails. */
-unsigned long get_rom_config_table (void);
-
-/* Get APM BIOS information. */
-void get_apm_info (void);
-
-/* Get VBE controller information. */
-int get_vbe_controller_info (struct vbe_controller *controller);
-
-/* Get VBE mode information. */
-int get_vbe_mode_info (int mode_number, struct vbe_mode *mode);
-
-/* Set VBE mode. */
-int set_vbe_mode (int mode_number);
-
-/* Return the data area immediately following our code. */
-int get_code_end (void);
-
-/* low-level timing info */
-int getrtsecs (void);
-unsigned long currticks(void);
-//int currticks (void);
-
/* Clear the screen. */
void cls (void);
@@ -725,12 +221,6 @@
available. */
int checkkey (void);
-/* Low-level disk I/O */
-int get_diskinfo (int drive, struct geometry *geometry);
-int biosdisk (int subfunc, int drive, struct geometry *geometry,
- int sector, int nsec, int segment);
-void stop_floppy (void);
-
/* Command-line interface functions. */
/* The flags for the builtins. */
@@ -801,67 +291,20 @@
int echo_char, int history);
int substring (const char *s1, const char *s2);
int nul_terminate (char *str);
-int get_based_digit (int c, int base);
int safe_parse_maxint (char **str_ptr, int *myint_ptr);
-int memcheck (int start, int len);
void grub_putstr (const char *str);
-#ifndef NO_DECOMPRESSION
-/* Compression support. */
-int gunzip_test_header (void);
-int gunzip_read (char *buf, int len);
-#endif /* NO_DECOMPRESSION */
-
-/* Parse a device string and initialize the global parameters. */
-char *set_device (char *device);
-int open_device (void);
-int real_open_partition (int flags);
-int open_partition (void);
-int next_partition (unsigned long drive, unsigned long dest,
- unsigned long *partition, int *type,
- unsigned long *start, unsigned long *len,
- unsigned long *offset, int *entry,
- unsigned long *ext_offset, char *buf);
-
-/* Sets device to the one represented by the SAVED_* parameters. */
-int make_saved_active (void);
-
-/* Set or clear the current root partition's hidden flag. */
-int set_partition_hidden_flag (int hidden);
-
/* List the contents of the directory that was opened with GRUB_OPEN,
printing all completions. */
int dir (char *dirname);
-int set_bootdev (int hdbias);
-
-/* Display statistics on the current active device. */
-void print_fsys_type (void);
-
/* Display device and filename completions. */
void print_a_completion (char *filename);
int print_completions (int is_filename, int is_completion);
-/* Copies the current partition data to the desired address. */
-void copy_current_part_entry (char *buf);
-
-void bsd_boot (kernel_t type, int bootdev, char *arg)
- __attribute__ ((noreturn));
-
-/* Define flags for load_image here. */
-/* Don't pass a Linux's mem option automatically. */
-#define KERNEL_LOAD_NO_MEM_OPTION (1 << 0)
-
-kernel_t load_image (char *kernel, char *arg, kernel_t suggested_type,
- unsigned long load_flags);
-
-int load_module (char *module, char *arg);
-int load_initrd (char *initrd);
-
int check_password(char *entered, char* expected, password_t type);
-void init_bios_info (void);
+/* FILO specific stuff */
+void copy_path_to_filo_bootline(char *arg, char *path, int use_rootdev);
-#endif /* ASM_FILE */
-
#endif /* ! GRUB_SHARED_HEADER */
Deleted: trunk/filo/include/grub/term.h
===================================================================
--- trunk/filo/include/grub/term.h 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/include/grub/term.h 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,115 +0,0 @@
-/* term.h - definitions for terminal handling */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2002 Free Software Foundation, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef GRUB_TERM_HEADER
-#define GRUB_TERM_HEADER 1
-
-/* These are used to represent the various color states we use */
-typedef enum
-{
- /* represents the color used to display all text that does not use the user
- * defined colors below
- */
- COLOR_STATE_STANDARD,
- /* represents the user defined colors for normal text */
- COLOR_STATE_NORMAL,
- /* represents the user defined colors for highlighted text */
- COLOR_STATE_HIGHLIGHT
-} color_state;
-
-#ifndef STAGE1_5
-
-/* Flags for representing the capabilities of a terminal. */
-/* Some notes about the flags:
- - These flags are used by higher-level functions but not terminals
- themselves.
- - If a terminal is dumb, you may assume that only putchar, getkey and
- checkkey are called.
- - Some fancy features (nocursor, setcolor, and highlight) can be set to
- NULL. */
-
-/* Set when input characters shouldn't be echoed back. */
-#define TERM_NO_ECHO (1 << 0)
-/* Set when the editing feature should be disabled. */
-#define TERM_NO_EDIT (1 << 1)
-/* Set when the terminal cannot do fancy things. */
-#define TERM_DUMB (1 << 2)
-/* Set when the terminal needs to be initialized. */
-#define TERM_NEED_INIT (1 << 16)
-
-struct term_entry
-{
- /* The name of a terminal. */
- const char *name;
- /* The feature flags defined above. */
- unsigned long flags;
- /* Put a character. */
- void (*putchar) (int c);
- /* Check if any input character is available. */
- int (*checkkey) (void);
- /* Get a character. */
- int (*getkey) (void);
- /* Get the cursor position. The return value is ((X << 8) | Y). */
- int (*getxy) (void);
- /* Go to the position (X, Y). */
- void (*gotoxy) (int x, int y);
- /* Clear the screen. */
- void (*cls) (void);
- /* Set the current color to be used */
- void (*setcolorstate) (color_state state);
- /* Set the normal color and the highlight color. The format of each
- color is VGA's. */
- void (*setcolor) (int normal_color, int highlight_color);
- /* Turn on/off the cursor. */
- int (*setcursor) (int on);
-};
-
-/* This lists up available terminals. */
-extern struct term_entry term_table[];
-/* This points to the current terminal. This is useful, because only
- a single terminal is enabled normally. */
-extern struct term_entry *current_term;
-
-#endif /* ! STAGE1_5 */
-
-/* The console stuff. */
-//extern int console_current_color;
-void console_putchar (int c);
-
-#ifndef STAGE1_5
-int console_checkkey (void);
-int console_getkey (void);
-int console_getxy (void);
-void console_gotoxy (int x, int y);
-void console_cls (void);
-void console_setcolorstate (color_state state);
-void console_setcolor (int normal_color, int highlight_color);
-int console_setcursor (int on);
-#endif
-
-void grub_serial_putchar (int c);
-int serial_checkkey (void);
-int serial_getkey (void);
-int serial_getxy (void);
-void serial_gotoxy (int x, int y);
-void serial_cls (void);
-void serial_setcolorstate (color_state state);
-
-#endif /* ! GRUB_TERM_HEADER */
Deleted: trunk/filo/include/grub/terminfo.h
===================================================================
--- trunk/filo/include/grub/terminfo.h 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/include/grub/terminfo.h 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,51 +0,0 @@
-/* terminfo.h - read a terminfo entry from the command line */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2002,2003,2004 Free Software Foundation, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef GRUB_TERMCAP_HEADER
-#define GRUB_TERMCAP_HEADER 1
-
-#define TERMINFO_LEN 40
-
-typedef struct terminfo
-{
- char name[TERMINFO_LEN];
- char cursor_address[TERMINFO_LEN];
- char clear_screen[TERMINFO_LEN];
- char enter_standout_mode[TERMINFO_LEN];
- char exit_standout_mode[TERMINFO_LEN];
-}
-terminfo;
-
-
-/* Function prototypes. */
-char *ti_escape_memory (const char *in, const char *end);
-char *ti_escape_string (const char *in);
-char *ti_unescape_memory (const char *in, const char *end);
-char *ti_unescape_string (const char *in);
-
-void ti_set_term (const struct terminfo *new);
-void ti_get_term (struct terminfo *copy);
-
-void ti_cursor_address (int x, int y);
-void ti_clear_screen (void);
-void ti_enter_standout_mode (void);
-void ti_exit_standout_mode (void);
-
-#endif /* ! GRUB_TERMCAP_HEADER */
Deleted: trunk/filo/include/grub/tparm.h
===================================================================
--- trunk/filo/include/grub/tparm.h 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/include/grub/tparm.h 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,28 +0,0 @@
-/* tparm.h - parameter formatting of terminfo */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2002 Free Software Foundation, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef GRUB_TPARM_HEADER
-#define GRUB_TPARM_HEADER 1
-
-
-/* Function prototypes. */
-char *grub_tparm (const char *string, ...);
-
-#endif /* ! GRUB_TERMCAP_HEADER */
Modified: trunk/filo/main/filo.c
===================================================================
--- trunk/filo/main/filo.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/filo.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -94,10 +94,12 @@
/* The main routine */
int main(void)
{
+ void grub_menulst(void);
void grub_main(void);
/* Initialize */
init();
+ grub_menulst();
grub_main();
return 0;
}
Modified: trunk/filo/main/grub/Makefile.inc
===================================================================
--- trunk/filo/main/grub/Makefile.inc 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/Makefile.inc 2008-09-18 08:04:13 UTC (rev 63)
@@ -17,11 +17,8 @@
#
-TARGETS-$(CONFIG_USE_GRUB) += main/grub/stage2.o main/grub/builtins.o
-TARGETS-$(CONFIG_USE_GRUB) += main/grub/cmdline.o main/grub/char_io.o
-TARGETS-$(CONFIG_USE_GRUB) += main/grub/grubcons.o main/grub/serial.o
-TARGETS-$(CONFIG_USE_GRUB) += main/grub/terminfo.o main/grub/tparm.o
+TARGETS-$(CONFIG_USE_GRUB) += main/grub/grub.o main/grub/builtins.o
+TARGETS-$(CONFIG_USE_GRUB) += main/grub/cmdline.o main/grub/char_io.o
TARGETS-$(CONFIG_USE_GRUB) += main/grub/completions.o
-TARGETS-$(CONFIG_USE_GRUB) += main/grub/grub.o
TARGETS-$(CONFIG_USE_MD5_PASSWORDS) += main/grub/md5.o
Modified: trunk/filo/main/grub/builtins.c
===================================================================
--- trunk/filo/main/grub/builtins.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/builtins.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -23,9 +23,7 @@
#include <config.h>
#include <fs.h>
#include <grub/shared.h>
-#include <grub/term.h>
-#include <grub/terminfo.h>
-#include <grub/serial.h>
+#include <arch/timer.h>
#ifdef CONFIG_USE_MD5_PASSWORDS
#include <grub/md5.h>
#endif
@@ -46,7 +44,7 @@
unsigned long install_partition = 0x20000;
unsigned long boot_drive = 0;
int saved_entryno = 0;
-char config_file[128] = "\0";
+char config_file[128] = "\0";
kernel_t kernel_type;
@@ -56,9 +54,8 @@
int grub_timeout = -1;
-
/* The password. */
-char *password;
+char *password = NULL;
/* The password type. */
password_t password_type;
/* The flag for indicating that the user is authoritative. */
@@ -66,70 +63,59 @@
/* -------- FILO logic -------- */
#define BOOT_LINE_LENGTH 1024
-char boot_line[BOOT_LINE_LENGTH]={0};
-char root_device[16]={0};
+char boot_line[BOOT_LINE_LENGTH] = { 0 };
+char root_device[16] = { 0 };
/* ---------------------------- */
int show_menu = 1;
/* Initialize the data for builtins. */
-void
-init_builtins (void)
+void init_builtins(void)
{
- kernel_type = KERNEL_TYPE_NONE;
- /* BSD and chainloading evil hacks! */
- //bootdev = set_bootdev (0);
- //mb_cmdline = (char *) MB_CMDLINE_BUF;
+ kernel_type = KERNEL_TYPE_NONE;
}
/* Initialize the data for the configuration file. */
-void
-init_config (void)
+void init_config(void)
{
- default_entry = 0;
- password = 0;
- fallback_entryno = -1;
- fallback_entries[0] = -1;
- grub_timeout = -1;
+ default_entry = 0;
+ password = NULL;
+ fallback_entryno = -1;
+ fallback_entries[0] = -1;
+ grub_timeout = -1;
}
-
-int
-check_password (char *entered, char* expected, password_t type)
+int check_password(char *entered, char *expected, password_t type)
{
- switch (type)
- {
- case PASSWORD_PLAIN:
- return strcmp (entered, expected);
-
+ switch (type) {
+ case PASSWORD_PLAIN:
+ return strcmp(entered, expected);
#ifdef CONFIG_USE_MD5_PASSWORDS
- case PASSWORD_MD5:
- return check_md5_password (entered, expected);
+ case PASSWORD_MD5:
+ return check_md5_password(entered, expected);
#endif
- default:
- /* unsupported password type: be secure */
- return 1;
- }
+ default:
+ /* unsupported password type: be secure */
+ return 1;
+ }
}
/* boot */
-static int
-boot_func (char *arg, int flags)
+static int boot_func(char *arg, int flags)
{
- void boot(const char *line);
- cls();
- grub_printf("\nBooting '%s'\n", boot_line);
- boot(boot_line);
- return 1;
+ void boot(const char *line);
+ cls();
+ grub_printf("\nBooting '%s'\n", boot_line);
+ boot(boot_line);
+ return 1;
}
-static struct builtin builtin_boot =
-{
- "boot",
- boot_func,
- BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
- "boot",
- "Boot the OS/chain-loader which has been loaded."
+static struct builtin builtin_boot = {
+ "boot",
+ boot_func,
+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
+ "boot",
+ "Boot the OS/chain-loader which has been loaded."
};
@@ -137,259 +123,262 @@
/* Set new colors used for the menu interface. Support two methods to
* specify a color name: a direct integer representation and a symbolic
* color name. An example of the latter is "blink-light-gray/blue". */
-static int
-color_func (char *arg, int flags)
+static int color_func(char *arg, int flags)
{
- char *normal;
- char *highlight;
- int new_normal_color;
- int new_highlight_color;
- static char *color_list[16] =
- {
- "black",
- "blue",
- "green",
- "cyan",
- "red",
- "magenta",
- "brown",
- "light-gray",
- "dark-gray",
- "light-blue",
- "light-green",
- "light-cyan",
- "light-red",
- "light-magenta",
- "yellow",
- "white"
- };
+ char *normal;
+ char *highlight;
+ int new_normal_color;
+ int new_highlight_color;
+ static char *color_list[16] = {
+ "black",
+ "blue",
+ "green",
+ "cyan",
+ "red",
+ "magenta",
+ "brown",
+ "light-gray",
+ "dark-gray",
+ "light-blue",
+ "light-green",
+ "light-cyan",
+ "light-red",
+ "light-magenta",
+ "yellow",
+ "white"
+ };
- auto int color_number (char *str);
+ auto int color_number(char *str);
- /* Convert the color name STR into the magical number. */
- auto int color_number (char *str)
- {
- char *ptr;
- int i;
- int color = 0;
+ /* Convert the color name STR into the magical number. */
+ auto int color_number(char *str) {
+ char *ptr;
+ int i;
+ int color = 0;
- /* Find the separator. */
- for (ptr = str; *ptr && *ptr != '/'; ptr++)
- ;
+ /* Find the separator. */
+ for (ptr = str; *ptr && *ptr != '/'; ptr++);
- /* If not found, return -1. */
- if (! *ptr)
- return -1;
+ /* If not found, return -1. */
+ if (!*ptr)
+ return -1;
- /* Terminate the string STR. */
- *ptr++ = 0;
+ /* Terminate the string STR. */
+ *ptr++ = 0;
- /* If STR contains the prefix "blink-", then set the `blink' bit in COLOR. */
- if (substring ("blink-", str) <= 0)
- {
- color = 0x80;
- str += 6;
- }
+ /* If STR contains the prefix "blink-", then set the `blink' bit in COLOR. */
+ if (substring("blink-", str) <= 0) {
+ color = 0x80;
+ str += 6;
+ }
- /* Search for the color name. */
- for (i = 0; i < 16; i++)
- if (grub_strcmp (color_list[i], str) == 0)
- {
- color |= i;
- break;
- }
+ /* Search for the color name. */
+ for (i = 0; i < 16; i++)
+ if (strcmp(color_list[i], str) == 0) {
+ color |= i;
+ break;
+ }
- if (i == 16)
- return -1;
+ if (i == 16)
+ return -1;
- str = ptr;
- nul_terminate (str);
+ str = ptr;
+ nul_terminate(str);
- /* Search for the color name. */
- for (i = 0; i < 8; i++)
- if (grub_strcmp (color_list[i], str) == 0)
- {
- color |= i << 4;
- break;
- }
+ /* Search for the color name. */
+ for (i = 0; i < 8; i++)
+ if (strcmp(color_list[i], str) == 0) {
+ color |= i << 4;
+ break;
+ }
- if (i == 8)
- return -1;
+ if (i == 8)
+ return -1;
- return color;
- }
+ return color;
+ }
- normal = arg;
- highlight = skip_to (0, arg);
+ normal = arg;
+ highlight = skip_to(0, arg);
- new_normal_color = color_number (normal);
- if (new_normal_color < 0 && ! safe_parse_maxint (&normal, &new_normal_color))
- return 1;
+ new_normal_color = color_number(normal);
+ if (new_normal_color < 0 && !safe_parse_maxint(&normal, &new_normal_color))
+ return 1;
- /* The second argument is optional, so set highlight_color to inverted NORMAL_COLOR. */
- if (! *highlight)
- new_highlight_color = ((new_normal_color >> 4)
- | ((new_normal_color & 0xf) << 4));
- else
- {
- new_highlight_color = color_number (highlight);
- if (new_highlight_color < 0
- && ! safe_parse_maxint (&highlight, &new_highlight_color))
- return 1;
- }
+ /* The second argument is optional, so set highlight_color to inverted NORMAL_COLOR. */
+ if (!*highlight)
+ new_highlight_color = ((new_normal_color >> 4)
+ | ((new_normal_color & 0xf) << 4));
+ else {
+ new_highlight_color = color_number(highlight);
+ if (new_highlight_color < 0 && !safe_parse_maxint(&highlight, &new_highlight_color))
+ return 1;
+ }
- if (current_term->setcolor)
- current_term->setcolor (new_normal_color, new_highlight_color);
+ console_setcolor(new_normal_color, new_highlight_color);
- return 0;
+ return 0;
}
-static struct builtin builtin_color =
-{
- "color",
- color_func,
- BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
- "color NORMAL [HIGHLIGHT]",
- "Change the menu colors. The color NORMAL is used for most"
- " lines in the menu, and the color HIGHLIGHT is used to highlight the"
- " line where the cursor points. If you omit HIGHLIGHT, then the"
- " inverted color of NORMAL is used for the highlighted line."
- " The format of a color is \"FG/BG\". FG and BG are symbolic color names."
- " A symbolic color name must be one of these: black, blue, green,"
- " cyan, red, magenta, brown, light-gray, dark-gray, light-blue,"
- " light-green, light-cyan, light-red, light-magenta, yellow and white."
- " But only the first eight names can be used for BG. You can prefix"
- " \"blink-\" to FG if you want a blinking foreground color."
+static struct builtin builtin_color = {
+ "color",
+ color_func,
+ BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
+ "color NORMAL [HIGHLIGHT]",
+ "Change the menu colors. The color NORMAL is used for most"
+ " lines in the menu, and the color HIGHLIGHT is used to highlight the"
+ " line where the cursor points. If you omit HIGHLIGHT, then the"
+ " inverted color of NORMAL is used for the highlighted line."
+ " The format of a color is \"FG/BG\". FG and BG are symbolic color names."
+ " A symbolic color name must be one of these: black, blue, green,"
+ " cyan, red, magenta, brown, light-gray, dark-gray, light-blue,"
+ " light-green, light-cyan, light-red, light-magenta, yellow and white."
+ " But only the first eight names can be used for BG. You can prefix"
+ " \"blink-\" to FG if you want a blinking foreground color."
};
+static char temp_config_file[128];
/* configfile */
-static int
-configfile_func (char *arg, int flags)
+static int configfile_func(char *arg, int flags)
{
- char *new_config = config_file;
+ extern int is_opened, keep_cmdline_running;
- /* Check if the file ARG is present. */
- if (! grub_open (arg))
- return 1;
+ /* Check if the file ARG is present. */
+ memset(temp_config_file, 0, 128);
+ copy_path_to_filo_bootline(arg, temp_config_file, 1);
+ if (!file_open(temp_config_file)) {
+ grub_printf("Could not open '%s'.\n", temp_config_file);
+ return 1;
+ }
- grub_close ();
+ file_close();
- /* Copy ARG to CONFIG_FILE. */
- while ((*new_config++ = *arg++) != 0)
- ;
+ /* Copy ARG to CONFIG_FILE. */
+ memset(config_file, 0, 128);
+ copy_path_to_filo_bootline(arg, config_file, 1);
- /* Force to load the configuration file. */
- // use_config_file = 1;
+ /* Force to load the configuration file. */
+ is_opened = 0;
+ keep_cmdline_running = 0;
- /* Make sure that the user will not be authoritative. */
- auth = 0;
+ /* Make sure that the user will not be authoritative. */
+ auth = 0;
- /* Restart cmain. */
- grub_main();
-
- /* Never reach here. */
- return 0;
+ return 0;
}
-static struct builtin builtin_configfile =
-{
- "configfile",
- configfile_func,
- BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
- "configfile FILE",
- "Load FILE as the configuration file."
+static struct builtin builtin_configfile = {
+ "configfile",
+ configfile_func,
+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
+ "configfile FILE",
+ "Load FILE as the configuration file."
};
/* default */
-static int
-default_func (char *arg, int flags)
+static int default_func(char *arg, int flags)
{
- if (! safe_parse_maxint (&arg, &default_entry))
- return 1;
+ if (!safe_parse_maxint(&arg, &default_entry))
+ return 1;
- return 0;
+ return 0;
}
-static struct builtin builtin_default =
-{
- "default",
- default_func,
- BUILTIN_MENU,
+static struct builtin builtin_default = {
+ "default",
+ default_func,
+ BUILTIN_MENU,
#if 0
- "default [NUM]",
- "Set the default entry to entry number NUM (if not specified, it is"
- " 0, the first entry) or the entry number saved by savedefault."
+ "default [NUM]",
+ "Set the default entry to entry number NUM (if not specified, it is"
+ " 0, the first entry) or the entry number saved by savedefault."
#endif
};
/* nvram-default */
-static int
-nvram_default_func (char *arg, int flags)
+static int nvram_default_func(char *arg, int flags)
{
- u8 boot_default;
+ u8 boot_default;
- if (get_option(&boot_default, "boot_default"))
- return 1;
+ if (get_option(&boot_default, "boot_default"))
+ return 1;
- default_entry = boot_default;
+ default_entry = boot_default;
- return 0;
+ return 0;
}
-static struct builtin builtin_nvram_default =
-{
- "nvram-default",
- nvram_default_func,
- BUILTIN_MENU,
+static struct builtin builtin_nvram_default = {
+ "nvram-default",
+ nvram_default_func,
+ BUILTIN_MENU,
#if 0
- "default [NUM]",
- "Set the default entry to entry number NUM (if not specified, it is"
- " 0, the first entry) or the entry number saved by savedefault."
+ "nvram-default",
+ "Set the default entry to entry number NUM read from nvram."
#endif
};
+/* nvram-root */
+static int nvram_root_func(char *arg, int flags)
+{
+ char new_root[16]; /* Assume 128 bits in cmos.layout */
+
+ if (get_option(new_root, "boot_device"))
+ return 1;
+
+ memset(root_device, 0, 16);
+ copy_path_to_filo_bootline(new_root, root_device, 0);
+
+ return 0;
+}
+
+static struct builtin builtin_nvram_root = {
+ "nvram-root",
+ nvram_root_func,
+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
+ "nvram-root",
+ "Set the root device according to the NVRAM entry boot_device"
+};
+
#if CONFIG_EXPERIMENTAL
#warning "FIND not implemented yet."
/* find */
/* Search for the filename ARG in all of partitions. */
-static int
-find_func (char *arg, int flags)
+static int find_func(char *arg, int flags)
{
- char *filename = arg;
- int got_file = 0;
+ char *filename = arg;
+ int got_file = 0;
- // the grub find works like this:
- //
- // for all disks
- // for all partitions on disk
- // open file
- // if file exists
- // print partition name
- // set got_file to 1
- //
- // dont they search all subdirectories? Thats a dumb find then.. :(
+ // the grub find works like this:
+ //
+ // for all disks
+ // for all partitions on disk
+ // open file
+ // if file exists
+ // print partition name
+ // set got_file to 1
+ //
+ // dont they search all subdirectories? Thats a dumb find then.. :(
- /* We want to ignore any error here. */
- errnum = ERR_NONE;
-
- if (got_file)
- {
- errnum = ERR_NONE;
- return 0;
- }
+ /* We want to ignore any error here. */
+ errnum = ERR_NONE;
- errnum = ERR_FILE_NOT_FOUND;
- return 1;
+ if (got_file) {
+ errnum = ERR_NONE;
+ return 0;
+ }
+
+ errnum = ERR_FILE_NOT_FOUND;
+ return 1;
}
-static struct builtin builtin_find =
-{
- "find",
- find_func,
- BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
- "find FILENAME",
- "Search for the filename FILENAME in all of partitions and print the list of"
- " the devices which contain the file."
+static struct builtin builtin_find = {
+ "find",
+ find_func,
+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
+ "find FILENAME",
+ "Search for the filename FILENAME in all of partitions and print the list of"
+ " the devices which contain the file."
};
#endif
@@ -397,146 +386,131 @@
#define MAX_SHORT_DOC_LEN 39
#define MAX_LONG_DOC_LEN 66
-static int
-help_func (char *arg, int flags)
+static int help_func(char *arg, int flags)
{
- int all = 0;
+ int all = 0;
- if (grub_memcmp (arg, "--all", sizeof ("--all") - 1) == 0)
- {
- all = 1;
- arg = skip_to (0, arg);
- }
+ if (memcmp(arg, "--all", sizeof("--all") - 1) == 0) {
+ all = 1;
+ arg = skip_to(0, arg);
+ }
- if (! *arg)
- {
- /* Invoked with no argument. Print the list of the short docs. */
- struct builtin **builtin;
- int left = 1;
+ if (!*arg) {
+ /* Invoked with no argument. Print the list of the short docs. */
+ struct builtin **builtin;
+ int left = 1;
- for (builtin = builtin_table; *builtin != 0; builtin++)
- {
- int len;
- int i;
+ for (builtin = builtin_table; *builtin != 0; builtin++) {
+ int len;
+ int i;
- /* If this cannot be used in the command-line interface,
- skip this. */
- if (! ((*builtin)->flags & BUILTIN_CMDLINE))
- continue;
+ /* If this cannot be used in the command-line interface,
+ skip this. */
+ if (!((*builtin)->flags & BUILTIN_CMDLINE))
+ continue;
- /* If this doesn't need to be listed automatically and "--all"
- is not specified, skip this. */
- if (! all && ! ((*builtin)->flags & BUILTIN_HELP_LIST))
- continue;
+ /* If this doesn't need to be listed automatically and "--all"
+ is not specified, skip this. */
+ if (!all && !((*builtin)->flags & BUILTIN_HELP_LIST))
+ continue;
- len = grub_strlen ((*builtin)->short_doc);
- /* If the length of SHORT_DOC is too long, truncate it. */
- if (len > MAX_SHORT_DOC_LEN - 1)
- len = MAX_SHORT_DOC_LEN - 1;
+ len = strlen((*builtin)->short_doc);
+ /* If the length of SHORT_DOC is too long, truncate it. */
+ if (len > MAX_SHORT_DOC_LEN - 1)
+ len = MAX_SHORT_DOC_LEN - 1;
- for (i = 0; i < len; i++)
- grub_putchar ((*builtin)->short_doc[i]);
+ for (i = 0; i < len; i++)
+ grub_putchar((*builtin)->short_doc[i]);
- for (; i < MAX_SHORT_DOC_LEN; i++)
- grub_putchar (' ');
+ for (; i < MAX_SHORT_DOC_LEN; i++)
+ grub_putchar(' ');
- if (! left)
- grub_putchar ('\n');
+ if (!left)
+ grub_putchar('\n');
- left = ! left;
- }
+ left = !left;
+ }
- /* If the last entry was at the left column, no newline was printed
- at the end. */
- if (! left)
- grub_putchar ('\n');
- }
- else
- {
- /* Invoked with one or more patterns. */
- do
- {
- struct builtin **builtin;
- char *next_arg;
+ /* If the last entry was at the left column, no newline was printed
+ at the end. */
+ if (!left)
+ grub_putchar('\n');
+ } else {
+ /* Invoked with one or more patterns. */
+ do {
+ struct builtin **builtin;
+ char *next_arg;
- /* Get the next argument. */
- next_arg = skip_to (0, arg);
+ /* Get the next argument. */
+ next_arg = skip_to(0, arg);
- /* Terminate ARG. */
- nul_terminate (arg);
+ /* Terminate ARG. */
+ nul_terminate(arg);
- for (builtin = builtin_table; *builtin; builtin++)
- {
- /* Skip this if this is only for the configuration file. */
- if (! ((*builtin)->flags & BUILTIN_CMDLINE))
- continue;
+ for (builtin = builtin_table; *builtin; builtin++) {
+ /* Skip this if this is only for the configuration file. */
+ if (!((*builtin)->flags & BUILTIN_CMDLINE))
+ continue;
- if (substring (arg, (*builtin)->name) < 1)
- {
- char *doc = (*builtin)->long_doc;
+ if (substring(arg, (*builtin)->name) < 1) {
+ char *doc = (*builtin)->long_doc;
- /* At first, print the name and the short doc. */
- grub_printf ("%s: %s\n",
- (*builtin)->name, (*builtin)->short_doc);
+ /* At first, print the name and the short doc. */
+ grub_printf("%s: %s\n", (*builtin)->name, (*builtin)->short_doc);
- /* Print the long doc. */
- while (*doc)
- {
- int len = grub_strlen (doc);
- int i;
+ /* Print the long doc. */
+ while (*doc) {
+ int len = strlen(doc);
+ int i;
- /* If LEN is too long, fold DOC. */
- if (len > MAX_LONG_DOC_LEN)
- {
- /* Fold this line at the position of a space. */
- for (len = MAX_LONG_DOC_LEN; len > 0; len--)
- if (doc[len - 1] == ' ')
- break;
- }
+ /* If LEN is too long, fold DOC. */
+ if (len > MAX_LONG_DOC_LEN) {
+ /* Fold this line at the position of a space. */
+ for (len = MAX_LONG_DOC_LEN; len > 0; len--)
+ if (doc[len - 1] == ' ')
+ break;
+ }
- grub_printf (" ");
- for (i = 0; i < len; i++)
- grub_putchar (*doc++);
- grub_putchar ('\n');
- }
- }
- }
+ grub_printf(" ");
+ for (i = 0; i < len; i++)
+ grub_putchar(*doc++);
+ grub_putchar('\n');
+ }
+ }
+ }
- arg = next_arg;
- }
- while (*arg);
- }
-
- return 0;
+ arg = next_arg;
+ }
+ while (*arg);
+ }
+ refresh();
+ return 0;
}
-static struct builtin builtin_help =
-{
- "help",
- help_func,
- BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
- "help [--all] [PATTERN ...]",
- "Display helpful information about builtin commands. Not all commands"
- " aren't shown without the option `--all'."
+static struct builtin builtin_help = {
+ "help",
+ help_func,
+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
+ "help [--all] [PATTERN ...]",
+ "Display helpful information about builtin commands. Not all commands"
+ " aren't shown without the option `--all'."
};
/* hiddenmenu */
-static int
-hiddenmenu_func (char *arg, int flags)
+static int hiddenmenu_func(char *arg, int flags)
{
- show_menu = 0;
- return 0;
+ show_menu = 0;
+ return 0;
}
-static struct builtin builtin_hiddenmenu =
-{
- "hiddenmenu",
- hiddenmenu_func,
- BUILTIN_MENU,
+static struct builtin builtin_hiddenmenu = {
+ "hiddenmenu",
+ hiddenmenu_func,
+ BUILTIN_MENU,
#if 0
- "hiddenmenu",
- "Hide the menu."
+ "hiddenmenu",
+ "Hide the menu."
#endif
};
@@ -547,7 +521,7 @@
* command is taken into regard here. This has to be zero when calling from root_func.
*/
-static void copy_path_to_filo_bootline(char *arg, char *path, int use_rootdev)
+void copy_path_to_filo_bootline(char *arg, char *path, int use_rootdev)
{
char devicename[16];
char drivername[16];
@@ -565,9 +539,9 @@
/* Read until we encounter a number, a comma or a closing
* bracket
*/
- while ((i <= 16) && (arg[i]) &&
- (!isdigit(arg[i])) && (arg[i] != ',') && (arg[i] != ')')) {
- drivername[i-1] = arg[i];
+ while ((i <= 16) && (arg[i]) && (!isdigit(arg[i])) && (arg[i] != ',')
+ && (arg[i] != ')')) {
+ drivername[i - 1] = arg[i];
i++;
}
}
@@ -576,16 +550,16 @@
part = -1;
len = strlen(drivername);
- if (len) { /* We have a driver. No idea if it exists though */
+ if (len) { /* We have a driver. No idea if it exists though */
// The driver should decide this:
- len++; // skip driver name + opening bracket
+ len++; // skip driver name + opening bracket
// XXX put @ handling in here, too for flash at addr and mem at addr
if (isdigit(arg[len])) {
disk = arg[len] - '0';
len++;
- if (isdigit(arg[len])) { /* More than 9 drives? */
+ if (isdigit(arg[len])) { /* More than 9 drives? */
/* ok, get one more number. No more than 99 drives */
disk *= 10;
disk += arg[len] - '0';
@@ -596,7 +570,7 @@
len++;
part = arg[len] - '0';
len++;
- if (isdigit(arg[len])) { /* More than 9 partitions? */
+ if (isdigit(arg[len])) { /* More than 9 partitions? */
/* ok, get one more number. No more than 99
* partitions */
part *= 10;
@@ -609,25 +583,26 @@
// set len = 0 --> just copy the drive name
len = 0;
} else {
- len++; // skip closing bracket
+ len++; // skip closing bracket
}
}
if (disk == -1) {
- grub_printf("No drive.\n");
- len = 0; // just copy the drive name
+ /* The user did specify a FILO name already */
+ // grub_printf("No drive.\n");
+ len = 0; // just copy the drive name
} else {
- if(part == -1) { // No partition
+ if (part == -1) { // No partition
sprintf(devicename, "%s%c:", drivername, disk + 'a');
- } else { // both disk and partition
+ } else { // both disk and partition
sprintf(devicename, "%s%c%d:", drivername, disk + 'a', part + 1);
}
strncat(path, devicename, BOOT_LINE_LENGTH);
- arg += len; // skip original drive name
+ arg += len; // skip original drive name
}
- if (use_rootdev && !len) { // No drive was explicitly specified
- if (strlen(root_device)) { // But someone set a root device
+ if (use_rootdev && !len) { // No drive was explicitly specified
+ if (strlen(root_device)) { // But someone set a root device
strncat(path, root_device, BOOT_LINE_LENGTH);
}
}
@@ -637,8 +612,7 @@
}
/* initrd */
-static int
-initrd_func (char *arg, int flags)
+static int initrd_func(char *arg, int flags)
{
strncat(boot_line, " initrd=", BOOT_LINE_LENGTH);
copy_path_to_filo_bootline(arg, boot_line, 1);
@@ -646,25 +620,23 @@
return 0;
}
-static struct builtin builtin_initrd =
-{
- "initrd",
- initrd_func,
- BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
- "initrd FILE [ARG ...]",
- "Load an initial ramdisk FILE for a Linux format boot image and set the"
- " appropriate parameters in the Linux setup area in memory."
+static struct builtin builtin_initrd = {
+ "initrd",
+ initrd_func,
+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
+ "initrd FILE [ARG ...]",
+ "Load an initial ramdisk FILE for a Linux format boot image and set the"
+ " appropriate parameters in the Linux setup area in memory."
};
/* kernel */
-static int
-kernel_func (char *arg, int flags)
+static int kernel_func(char *arg, int flags)
{
/* Needed to pass grub checks */
- kernel_type=KERNEL_TYPE_LINUX;
+ kernel_type = KERNEL_TYPE_LINUX;
/* clear out boot_line. Kernel is the first thing */
memset(boot_line, 0, BOOT_LINE_LENGTH);
@@ -674,694 +646,575 @@
return 0;
}
-static struct builtin builtin_kernel =
-{
- "kernel",
- kernel_func,
- BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
- "kernel [--no-mem-option] [--type=TYPE] FILE [ARG ...]",
- "Attempt to load the primary boot image from FILE. The rest of the"
- " line is passed verbatim as the \"kernel command line\". Any modules"
- " must be reloaded after using this command. The option --type is used"
- " to suggest what type of kernel to be loaded. TYPE must be either of"
- " \"netbsd\", \"freebsd\", \"openbsd\", \"linux\", \"biglinux\" and"
- " \"multiboot\". The option --no-mem-option tells GRUB not to pass a"
- " Linux's mem option automatically."
+static struct builtin builtin_kernel = {
+ "kernel",
+ kernel_func,
+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
+ "kernel [--no-mem-option] [--type=TYPE] FILE [ARG ...]",
+ "Attempt to load the primary boot image from FILE. The rest of the"
+ " line is passed verbatim as the \"kernel command line\". Any modules"
+ " must be reloaded after using this command. The option --type is used"
+ " to suggest what type of kernel to be loaded. TYPE must be either of"
+ " \"netbsd\", \"freebsd\", \"openbsd\", \"linux\", \"biglinux\" and"
+ " \"multiboot\". The option --no-mem-option tells GRUB not to pass a" " Linux's mem option automatically."
};
/* lock */
-static int
-lock_func (char *arg, int flags)
+static int lock_func(char *arg, int flags)
{
- if (! auth && password)
- {
- errnum = ERR_PRIVILEGED;
- return 1;
- }
+ if (!auth && password) {
+ errnum = ERR_PRIVILEGED;
+ return 1;
+ }
- return 0;
+ return 0;
}
-static struct builtin builtin_lock =
-{
- "lock",
- lock_func,
- BUILTIN_CMDLINE,
- "lock",
- "Break a command execution unless the user is authenticated."
+static struct builtin builtin_lock = {
+ "lock",
+ lock_func,
+ BUILTIN_CMDLINE,
+ "lock",
+ "Break a command execution unless the user is authenticated."
};
#ifdef CONFIG_USE_MD5_PASSWORDS
/* md5crypt */
-static int
-md5crypt_func (char *arg, int flags)
+static int md5crypt_func(char *arg, int flags)
{
- char crypted[36];
- char key[32];
- unsigned int seed;
- int i;
- const char *const seedchars =
- "./0123456789ABCDEFGHIJKLMNOPQRST"
- "UVWXYZabcdefghijklmnopqrstuvwxyz";
+ char crypted[36];
+ char key[32];
+ unsigned int seed;
+ int i;
+ const char *const seedchars = "./0123456789ABCDEFGHIJKLMNOPQRST" "UVWXYZabcdefghijklmnopqrstuvwxyz";
- /* First create a salt. */
+ /* First create a salt. */
- /* The magical prefix. */
- memset (crypted, 0, sizeof (crypted));
- memmove (crypted, "$1$", 3);
+ /* The magical prefix. */
+ memset(crypted, 0, sizeof(crypted));
+ memmove(crypted, "$1$", 3);
- /* Create the length of a salt. */
- seed = currticks ();
+ /* Create the length of a salt. */
+ seed = currticks();
- /* Generate a salt. */
- for (i = 0; i < 8 && seed; i++)
- {
- /* FIXME: This should be more random. */
- crypted[3 + i] = seedchars[seed & 0x3f];
- seed >>= 6;
- }
+ /* Generate a salt. */
+ for (i = 0; i < 8 && seed; i++) {
+ /* FIXME: This should be more random. */
+ crypted[3 + i] = seedchars[seed & 0x3f];
+ seed >>= 6;
+ }
- /* A salt must be terminated with `$', if it is less than 8 chars. */
- crypted[3 + i] = '$';
+ /* A salt must be terminated with `$', if it is less than 8 chars. */
+ crypted[3 + i] = '$';
#ifdef CONFIG_DEBUG_MD5CRYPT
- grub_printf ("salt = %s\n", crypted);
+ grub_printf("salt = %s\n", crypted);
#endif
- /* Get a password. */
- memset (key, 0, sizeof (key));
- get_cmdline ("Password: ", key, sizeof (key) - 1, '*', 0);
+ /* Get a password. */
+ memset(key, 0, sizeof(key));
+ get_cmdline("Password: ", key, sizeof(key) - 1, '*', 0);
- /* Crypt the key. */
- make_md5_password (key, crypted);
+ /* Crypt the key. */
+ make_md5_password(key, crypted);
- grub_printf ("Encrypted: %s\n", crypted);
- return 0;
+ grub_printf("Encrypted: %s\n", crypted);
+ return 0;
}
-static struct builtin builtin_md5crypt =
-{
- "md5crypt",
- md5crypt_func,
- BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
- "md5crypt",
- "Generate a password in MD5 format."
+static struct builtin builtin_md5crypt = {
+ "md5crypt",
+ md5crypt_func,
+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
+ "md5crypt",
+ "Generate a password in MD5 format."
};
-#endif /* CONFIG_USE_MD5_PASSWORDS */
+#endif /* CONFIG_USE_MD5_PASSWORDS */
/* password */
-static int
-password_func (char *arg, int flags)
+static int password_func(char *arg, int flags)
{
- int len;
- password_t type = PASSWORD_PLAIN;
+ int len;
+ password_t type = PASSWORD_PLAIN;
#ifdef CONFIG_USE_MD5_PASSWORDS
- if (grub_memcmp (arg, "--md5", 5) == 0)
- {
- type = PASSWORD_MD5;
- arg = skip_to (0, arg);
- }
+ if (memcmp(arg, "--md5", 5) == 0) {
+ type = PASSWORD_MD5;
+ arg = skip_to(0, arg);
+ }
#endif
- if (grub_memcmp (arg, "--", 2) == 0)
- {
- type = PASSWORD_UNSUPPORTED;
- arg = skip_to (0, arg);
- }
+ if (memcmp(arg, "--", 2) == 0) {
+ type = PASSWORD_UNSUPPORTED;
+ arg = skip_to(0, arg);
+ }
- if ((flags & (BUILTIN_CMDLINE | BUILTIN_SCRIPT)) != 0)
- {
- /* Do password check! */
- char entered[32];
+ if ((flags & (BUILTIN_CMDLINE | BUILTIN_SCRIPT)) != 0) {
+ /* Do password check! */
+ char entered[32];
- /* Wipe out any previously entered password */
- entered[0] = 0;
- get_cmdline ("Password: ", entered, 31, '*', 0);
+ /* Wipe out any previously entered password */
+ entered[0] = 0;
+ get_cmdline("Password: ", entered, 31, '*', 0);
- nul_terminate (arg);
- if (check_password (entered, arg, type) != 0)
- {
- errnum = ERR_PRIVILEGED;
- return 1;
- }
- }
- else
- {
- len = grub_strlen (arg);
+ nul_terminate(arg);
+ if (check_password(entered, arg, type) != 0) {
+ errnum = ERR_PRIVILEGED;
+ return 1;
+ }
+ } else {
+ len = strlen(arg);
- /* PASSWORD NUL NUL ... */
- if (len + 2 > PASSWORD_BUFLEN)
- {
- errnum = ERR_WONT_FIT;
- return 1;
- }
+ /* PASSWORD NUL NUL ... */
+ if (len + 2 > PASSWORD_BUFLEN) {
+ errnum = ERR_WONT_FIT;
+ return 1;
+ }
- /* Copy the password and clear the rest of the buffer. */
- password = (char *) PASSWORD_BUF;
- memmove (password, arg, len);
- memset (password + len, 0, PASSWORD_BUFLEN - len);
- password_type = type;
- }
- return 0;
+ /* Copy the password and clear the rest of the buffer. */
+ password = (char *) PASSWORD_BUF;
+ memmove(password, arg, len);
+ memset(password + len, 0, PASSWORD_BUFLEN - len);
+ password_type = type;
+ }
+ return 0;
}
-static struct builtin builtin_password =
-{
- "password",
- password_func,
- BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_NO_ECHO,
- "password [--md5] PASSWD [FILE]",
- "If used in the first section of a menu file, disable all"
- " interactive editing control (menu entry editor and"
- " command line). If the password PASSWD is entered, it loads the"
- " FILE as a new config file and restarts the GRUB Stage 2. If you"
- " omit the argument FILE, then GRUB just unlocks privileged"
- " instructions. You can also use it in the script section, in"
- " which case it will ask for the password, before continueing."
- " The option --md5 tells GRUB that PASSWD is encrypted with"
- " md5crypt."
+static struct builtin builtin_password = {
+ "password",
+ password_func,
+ BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_NO_ECHO,
+ "password [--md5] PASSWD [FILE]",
+ "If used in the first section of a menu file, disable all"
+ " interactive editing control (menu entry editor and"
+ " command line). If the password PASSWD is entered, it loads the"
+ " FILE as a new config file and restarts the GRUB Stage 2. If you"
+ " omit the argument FILE, then GRUB just unlocks privileged"
+ " instructions. You can also use it in the script section, in"
+ " which case it will ask for the password, before continueing."
+ " The option --md5 tells GRUB that PASSWD is encrypted with" " md5crypt."
};
/* pause */
-static int
-pause_func (char *arg, int flags)
+static int pause_func(char *arg, int flags)
{
- grub_printf("%s\n", arg);
+ grub_printf("%s\n", arg);
- /* If ESC is returned, then abort this entry. */
- if (ASCII_CHAR (getkey ()) == 27)
- return 1;
+ /* If ESC is returned, then abort this entry. */
+ if (ASCII_CHAR(getkey()) == 27)
+ return 1;
- return 0;
+ return 0;
}
-static struct builtin builtin_pause =
+static struct builtin builtin_pause = {
+ "pause",
+ pause_func,
+ BUILTIN_CMDLINE | BUILTIN_NO_ECHO,
+ "pause [MESSAGE ...]",
+ "Print MESSAGE, then wait until a key is pressed."
+};
+
+static int poweroff_func(char *arg, int flags)
{
- "pause",
- pause_func,
- BUILTIN_CMDLINE | BUILTIN_NO_ECHO,
- "pause [MESSAGE ...]",
- "Print MESSAGE, then wait until a key is pressed."
+ void platform_poweroff(void);
+
+#ifdef PLATFORM_SUPPORT
+ platform_poweroff();
+#else
+ grub_printf("Poweroff not supported.\n");
+#endif
+
+ // Will never return;
+ return 0;
+}
+
+static struct builtin builtin_poweroff = {
+ "poweroff",
+ poweroff_func,
+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
+ "poweroff",
+ "Power off the system."
};
+static int reboot_func(char *arg, int flags)
+{
+ void platform_reboot(void);
-static int
-root_func (char *arg, int flags)
+#ifdef PLATFORM_SUPPORT
+ platform_reboot();
+#else
+ grub_printf("Rebooting not supported.\n");
+#endif
+
+ // Will never return;
+ return 0;
+}
+
+static struct builtin builtin_reboot = {
+ "reboot",
+ reboot_func,
+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
+ "reboot",
+ "Reboot the system."
+};
+
+static int root_func(char *arg, int flags)
{
memset(root_device, 0, 16);
copy_path_to_filo_bootline(arg, root_device, 0);
- return 0;
+ return 0;
}
-static struct builtin builtin_root =
-{
- "root",
- root_func,
- BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
- "root [DEVICE [HDBIAS]]",
- "Set the current \"root device\" to the device DEVICE, then"
- " attempt to mount it to get the partition size (for passing the"
- " partition descriptor in `ES:ESI', used by some chain-loaded"
- " bootloaders), the BSD drive-type (for booting BSD kernels using"
- " their native boot format), and correctly determine "
- " the PC partition where a BSD sub-partition is located. The"
- " optional HDBIAS parameter is a number to tell a BSD kernel"
- " how many BIOS drive numbers are on controllers before the current"
- " one. For example, if there is an IDE disk and a SCSI disk, and your"
- " FreeBSD root partition is on the SCSI disk, then use a `1' for HDBIAS."
+static struct builtin builtin_root = {
+ "root",
+ root_func,
+ BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
+ "root [DEVICE]",
+ "Set the current \"root device\" to the device DEVICE."
};
/* serial */
-static int
-serial_func (char *arg, int flags)
+static int serial_func(char *arg, int flags)
{
- unsigned short port = serial_hw_get_port (0);
- unsigned int speed = 9600;
- int word_len = UART_8BITS_WORD;
- int parity = UART_NO_PARITY;
- int stop_bit_len = UART_1_STOP_BIT;
+#if 0
+ unsigned short port = serial_hw_get_port(0);
+ unsigned int speed = 9600;
+ int word_len = UART_8BITS_WORD;
+ int parity = UART_NO_PARITY;
+ int stop_bit_len = UART_1_STOP_BIT;
- /* Process GNU-style long options.
- FIXME: We should implement a getopt-like function, to avoid
- duplications. */
- while (1)
- {
- if (grub_memcmp (arg, "--unit=", sizeof ("--unit=") - 1) == 0)
- {
- char *p = arg + sizeof ("--unit=") - 1;
- int unit;
-
- if (! safe_parse_maxint (&p, &unit))
- return 1;
-
- if (unit < 0 || unit > 3)
- {
- errnum = ERR_DEV_VALUES;
- return 1;
- }
+ /* Process GNU-style long options.
+ FIXME: We should implement a getopt-like function, to avoid
+ duplications. */
+ while (1) {
+ if (memcmp(arg, "--unit=", sizeof("--unit=") - 1) == 0) {
+ char *p = arg + sizeof("--unit=") - 1;
+ int unit;
- port = serial_hw_get_port (unit);
- }
- else if (grub_memcmp (arg, "--speed=", sizeof ("--speed=") - 1) == 0)
- {
- char *p = arg + sizeof ("--speed=") - 1;
- int num;
-
- if (! safe_parse_maxint (&p, &num))
- return 1;
+ if (!safe_parse_maxint(&p, &unit))
+ return 1;
- speed = (unsigned int) num;
- }
- else if (grub_memcmp (arg, "--port=", sizeof ("--port=") - 1) == 0)
- {
- char *p = arg + sizeof ("--port=") - 1;
- int num;
-
- if (! safe_parse_maxint (&p, &num))
- return 1;
+ if (unit < 0 || unit > 3) {
+ errnum = ERR_DEV_VALUES;
+ return 1;
+ }
- port = (unsigned short) num;
- }
- else if (grub_memcmp (arg, "--word=", sizeof ("--word=") - 1) == 0)
- {
- char *p = arg + sizeof ("--word=") - 1;
- int len;
-
- if (! safe_parse_maxint (&p, &len))
- return 1;
+ port = serial_hw_get_port(unit);
+ } else if (memcmp(arg, "--speed=", sizeof("--speed=") - 1) == 0) {
+ char *p = arg + sizeof("--speed=") - 1;
+ int num;
- switch (len)
- {
- case 5: word_len = UART_5BITS_WORD; break;
- case 6: word_len = UART_6BITS_WORD; break;
- case 7: word_len = UART_7BITS_WORD; break;
- case 8: word_len = UART_8BITS_WORD; break;
- default:
- errnum = ERR_BAD_ARGUMENT;
- return 1;
- }
- }
- else if (grub_memcmp (arg, "--stop=", sizeof ("--stop=") - 1) == 0)
- {
- char *p = arg + sizeof ("--stop=") - 1;
- int len;
-
- if (! safe_parse_maxint (&p, &len))
- return 1;
+ if (!safe_parse_maxint(&p, &num))
+ return 1;
- switch (len)
- {
- case 1: stop_bit_len = UART_1_STOP_BIT; break;
- case 2: stop_bit_len = UART_2_STOP_BITS; break;
- default:
- errnum = ERR_BAD_ARGUMENT;
- return 1;
- }
- }
- else if (grub_memcmp (arg, "--parity=", sizeof ("--parity=") - 1) == 0)
- {
- char *p = arg + sizeof ("--parity=") - 1;
+ speed = (unsigned int) num;
+ } else if (memcmp(arg, "--port=", sizeof("--port=") - 1)
+ == 0) {
+ char *p = arg + sizeof("--port=") - 1;
+ int num;
- if (grub_memcmp (p, "no", sizeof ("no") - 1) == 0)
- parity = UART_NO_PARITY;
- else if (grub_memcmp (p, "odd", sizeof ("odd") - 1) == 0)
- parity = UART_ODD_PARITY;
- else if (grub_memcmp (p, "even", sizeof ("even") - 1) == 0)
- parity = UART_EVEN_PARITY;
- else
- {
- errnum = ERR_BAD_ARGUMENT;
- return 1;
- }
- }
- else
- break;
+ if (!safe_parse_maxint(&p, &num))
+ return 1;
- arg = skip_to (0, arg);
- }
+ port = (unsigned short) num;
+ } else if (memcmp(arg, "--word=", sizeof("--word=") - 1)
+ == 0) {
+ char *p = arg + sizeof("--word=") - 1;
+ int len;
- /* Initialize the serial unit. */
- if (! serial_hw_init (port, speed, word_len, parity, stop_bit_len))
- {
- errnum = ERR_BAD_ARGUMENT;
- return 1;
- }
-
- return 0;
-}
+ if (!safe_parse_maxint(&p, &len))
+ return 1;
-static struct builtin builtin_serial =
-{
- "serial",
- serial_func,
- BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST | BUILTIN_NO_ECHO,
- "serial [--unit=UNIT] [--port=PORT] [--speed=SPEED] [--word=WORD] [--parity=PARITY] [--stop=STOP] [--device=DEV]",
- "Initialize a serial device. UNIT is a digit that specifies which serial"
- " device is used (e.g. 0 == COM1). If you need to specify the port number,"
- " set it by --port. SPEED is the DTE-DTE speed. WORD is the word length,"
- " PARITY is the type of parity, which is one of `no', `odd' and `even'."
- " STOP is the length of stop bit(s). The option --device can be used only"
- " in the grub shell, which specifies the file name of a tty device. The"
- " default values are COM1, 9600, 8N1."
-};
+ switch (len) {
+ case 5:
+ word_len = UART_5BITS_WORD;
+ break;
+ case 6:
+ word_len = UART_6BITS_WORD;
+ break;
+ case 7:
+ word_len = UART_7BITS_WORD;
+ break;
+ case 8:
+ word_len = UART_8BITS_WORD;
+ break;
+ default:
+ errnum = ERR_BAD_ARGUMENT;
+ return 1;
+ }
+ } else if (memcmp(arg, "--stop=", sizeof("--stop=") - 1)
+ == 0) {
+ char *p = arg + sizeof("--stop=") - 1;
+ int len;
+ if (!safe_parse_maxint(&p, &len))
+ return 1;
+ switch (len) {
+ case 1:
+ stop_bit_len = UART_1_STOP_BIT;
+ break;
+ case 2:
+ stop_bit_len = UART_2_STOP_BITS;
+ break;
+ default:
+ errnum = ERR_BAD_ARGUMENT;
+ return 1;
+ }
+ } else if (memcmp(arg, "--parity=", sizeof("--parity=") - 1) == 0) {
+ char *p = arg + sizeof("--parity=") - 1;
-/* terminal */
-static int
-terminal_func (char *arg, int flags)
-{
- /* The index of the default terminal in TERM_TABLE. */
- int default_term = -1;
- struct term_entry *prev_term = current_term;
- int to = -1;
- int lines = 0;
- int no_message = 0;
- unsigned long term_flags = 0;
- /* XXX: Assume less than 32 terminals. */
- unsigned long term_bitmap = 0;
+ if (memcmp(p, "no", sizeof("no") - 1) == 0)
+ parity = UART_NO_PARITY;
+ else if (memcmp(p, "odd", sizeof("odd") - 1)
+ == 0)
+ parity = UART_ODD_PARITY;
+ else if (memcmp(p, "even", sizeof("even") - 1)
+ == 0)
+ parity = UART_EVEN_PARITY;
+ else {
+ errnum = ERR_BAD_ARGUMENT;
+ return 1;
+ }
+ } else
+ break;
- /* Get GNU-style long options. */
- while (1)
- {
- if (grub_memcmp (arg, "--dumb", sizeof ("--dumb") - 1) == 0)
- term_flags |= TERM_DUMB;
- else if (grub_memcmp (arg, "--no-echo", sizeof ("--no-echo") - 1) == 0)
- /* ``--no-echo'' implies ``--no-edit''. */
- term_flags |= (TERM_NO_ECHO | TERM_NO_EDIT);
- else if (grub_memcmp (arg, "--no-edit", sizeof ("--no-edit") - 1) == 0)
- term_flags |= TERM_NO_EDIT;
- else if (grub_memcmp (arg, "--timeout=", sizeof ("--timeout=") - 1) == 0)
- {
- char *val = arg + sizeof ("--timeout=") - 1;
+ arg = skip_to(0, arg);
+ }
- if (! safe_parse_maxint (&val, &to))
- return 1;
- }
- else if (grub_memcmp (arg, "--lines=", sizeof ("--lines=") - 1) == 0)
- {
- char *val = arg + sizeof ("--lines=") - 1;
+ /* Initialize the serial unit. */
+ if (!serial_hw_init(port, speed, word_len, parity, stop_bit_len)) {
+ errnum = ERR_BAD_ARGUMENT;
+ return 1;
+ }
+#endif
+ return 0;
+}
- if (! safe_parse_maxint (&val, &lines))
- return 1;
+static struct builtin builtin_serial = {
+ "serial",
+ serial_func,
+ BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST | BUILTIN_NO_ECHO,
+ "serial [--unit=UNIT] [--port=PORT] [--speed=SPEED] [--word=WORD] [--parity=PARITY] [--stop=STOP] [--device=DEV]",
+ "Initialize a serial device. UNIT is a digit that specifies which serial"
+ " device is used (e.g. 0 == COM1). If you need to specify the port number,"
+ " set it by --port. SPEED is the DTE-DTE speed. WORD is the word length,"
+ " PARITY is the type of parity, which is one of `no', `odd' and `even'."
+ " STOP is the length of stop bit(s). The option --device can be used only"
+ " in the grub shell, which specifies the file name of a tty device. The"
+ " default values are COM1, 9600, 8N1."
+};
- /* Probably less than four is meaningless.... */
- if (lines < 4)
- {
- errnum = ERR_BAD_ARGUMENT;
- return 1;
- }
- }
- else if (grub_memcmp (arg, "--silent", sizeof ("--silent") - 1) == 0)
- no_message = 1;
- else {
- while (*arg)
- {
- int i;
- char *next = skip_to (0, arg);
-
- nul_terminate (arg);
-
- for (i = 0; term_table[i].name; i++)
- {
- if (grub_strcmp (arg, term_table[i].name) == 0)
- {
- if (term_table[i].flags & TERM_NEED_INIT)
- {
- errnum = ERR_DEV_NEED_INIT;
- return 1;
- }
-
- if (default_term < 0)
- default_term = i;
-
- term_bitmap |= (1 << i);
- break;
- }
- }
-
- if (! term_table[i].name)
- {
- errnum = ERR_BAD_ARGUMENT;
- return 1;
- }
-
- arg = next;
- break;
- }
- if (!*arg) break;
- continue;
- }
- arg = skip_to (0, arg);
- }
- /* If no argument is specified, show current setting. */
- // if (! *arg)
- if (! term_bitmap)
- {
- grub_printf ("%s%s%s%s\n",
- current_term->name,
- current_term->flags & TERM_DUMB ? " (dumb)" : "",
- current_term->flags & TERM_NO_EDIT ? " (no edit)" : "",
- current_term->flags & TERM_NO_ECHO ? " (no echo)" : "");
- return 0;
- }
+/* terminal */
+static int terminal_func(char *arg, int flags)
+{
+#if 0
+ /* The index of the default terminal in TERM_TABLE. */
+ int default_term = -1;
+ struct term_entry *prev_term = current_term;
+ int to = -1;
+ int lines = 0;
+ int no_message = 0;
+ unsigned long term_flags = 0;
+ /* XXX: Assume less than 32 terminals. */
+ unsigned long term_bitmap = 0;
- /* If multiple terminals are specified, wait until the user pushes any key on one of the terminals. */
- if (term_bitmap & ~(1 << default_term))
- {
- int time1, time2 = -1;
+ /* Get GNU-style long options. */
+ while (1) {
+ if (memcmp(arg, "--no-echo", sizeof("--no-echo") - 1) == 0)
+ /* ``--no-echo'' implies ``--no-edit''. */
+ term_flags |= (TERM_NO_ECHO | TERM_NO_EDIT);
+ else if (memcmp(arg, "--no-edit", sizeof("--no-edit") - 1) == 0)
+ term_flags |= TERM_NO_EDIT;
+ else if (memcmp(arg, "--timeout=", sizeof("--timeout=") - 1) == 0) {
+ char *val = arg + sizeof("--timeout=") - 1;
- /* XXX: Disable the pager. */
- count_lines = -1;
+ if (!safe_parse_maxint(&val, &to))
+ return 1;
+ } else if (memcmp(arg, "--lines=", sizeof("--lines=") - 1) == 0) {
+ char *val = arg + sizeof("--lines=") - 1;
- /* Get current time. */
- while ((time1 = getrtsecs ()) == 0xFF)
- ;
+ if (!safe_parse_maxint(&val, &lines))
+ return 1;
- /* Wait for a key input. */
- while (to)
- {
- int i;
+ /* Probably less than four is meaningless.... */
+ if (lines < 4) {
+ errnum = ERR_BAD_ARGUMENT;
+ return 1;
+ }
+ } else if (memcmp(arg, "--silent", sizeof("--silent") - 1) == 0)
+ no_message = 1;
+ else {
+ while (*arg) {
+ int i;
+ char *next = skip_to(0, arg);
- for (i = 0; term_table[i].name; i++)
- {
- if (term_bitmap & (1 << i))
- {
- if (term_table[i].checkkey () >= 0)
- {
- (void) term_table[i].getkey ();
- default_term = i;
+ nul_terminate(arg);
- goto end;
- }
- }
- }
+ for (i = 0; term_table[i].name; i++) {
+ if (strcmp(arg, term_table[i].name) == 0) {
+ if (default_term < 0)
+ default_term = i;
- /* Prompt the user, once per sec. */
- if ((time1 = getrtsecs ()) != time2 && time1 != 0xFF)
- {
- if (! no_message)
- {
- /* Need to set CURRENT_TERM to each of selected terminals. */
- for (i = 0; term_table[i].name; i++)
- if (term_bitmap & (1 << i))
- {
- current_term = term_table + i;
- grub_printf ("\rPress any key to continue.\n");
- }
+ term_bitmap |= (1 << i);
+ break;
+ }
+ }
- /* Restore CURRENT_TERM. */
- current_term = prev_term;
- }
+ if (!term_table[i].name) {
+ errnum = ERR_BAD_ARGUMENT;
+ return 1;
+ }
- time2 = time1;
- if (to > 0)
- to--;
- }
- }
- }
+ arg = next;
+ break;
+ }
+ if (!*arg)
+ break;
+ continue;
+ }
- end:
- current_term = term_table + default_term;
- current_term->flags = term_flags;
+ arg = skip_to(0, arg);
+ }
- if (lines)
- max_lines = lines;
- else
- /* 24 would be a good default value. */
- max_lines = 24;
+ /* If no argument is specified, show current setting. */
+ // if (! *arg)
+ if (!term_bitmap) {
+ grub_printf("%s%s%s\n",
+ current_term->name,
+ current_term->
+ current_term->
+ flags & TERM_NO_EDIT ? " (no edit)" : "",
+ terminal_flags & TERM_NO_ECHO ? " (no echo)" : "");
+ return 0;
+ }
- /* If the interface is currently the command-line, restart it to repaint the screen. */
- //if (current_term != prev_term && (flags & BUILTIN_CMDLINE))
- // grub_longjmp (restart_cmdline_env, 0);
+ /* If multiple terminals are specified, wait until the user pushes any key on one of the terminals. */
+ if (term_bitmap & ~(1 << default_term)) {
+ int time1, time2 = -1;
- return 0;
-}
+ /* XXX: Disable the pager. */
+ count_lines = -1;
-static struct builtin builtin_terminal =
-{
- "terminal",
- terminal_func,
- BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST | BUILTIN_NO_ECHO,
- "terminal [--dumb] [--no-echo] [--no-edit] [--timeout=SECS] [--lines=LINES] [--silent] [console] [serial]",
- "Select a terminal. When multiple terminals are specified, wait until"
- " you push any key to continue. If both console and serial are specified,"
- " the terminal to which you input a key first will be selected. If no"
- " argument is specified, print current setting. The option --dumb"
- " specifies that your terminal is dumb, otherwise, vt100-compatibility"
- " is assumed. If you specify --no-echo, input characters won't be echoed."
- " If you specify --no-edit, the BASH-like editing feature will be disabled."
- " If --timeout is present, this command will wait at most for SECS"
- " seconds. The option --lines specifies the maximum number of lines."
- " The option --silent is used to suppress messages."
-};
+ /* Get current time. */
+ while ((time1 = getrtsecs()) == 0xFF);
-static int
-terminfo_func (char *arg, int flags)
-{
- struct terminfo term;
+ /* Wait for a key input. */
+ while (to) {
+ int i;
- if (*arg)
- {
- struct
- {
- const char *name;
- char *var;
- }
- options[] =
- {
- {"--name=", term.name},
- {"--cursor-address=", term.cursor_address},
- {"--clear-screen=", term.clear_screen},
- {"--enter-standout-mode=", term.enter_standout_mode},
- {"--exit-standout-mode=", term.exit_standout_mode}
- };
+ for (i = 0; term_table[i].name; i++) {
+ if (term_bitmap & (1 << i)) {
+ if (term_table[i].checkkey() >= 0) {
+ (void) term_table[i].getkey();
+ default_term = i;
- memset (&term, 0, sizeof (term));
+ goto end;
+ }
+ }
+ }
- while (*arg)
- {
- int i;
- char *next = skip_to (0, arg);
+ /* Prompt the user, once per sec. */
+ if ((time1 = getrtsecs()) != time2 && time1 != 0xFF) {
+ if (!no_message) {
+ /* Need to set CURRENT_TERM to each of selected terminals. */
+ for (i = 0; term_table[i].name; i++)
+ if (term_bitmap & (1 << i)) {
+ current_term = term_table + i;
+ grub_printf("\rPress any key to continue.\n");
+ }
- nul_terminate (arg);
+ /* Restore CURRENT_TERM. */
+ current_term = prev_term;
+ }
- for (i = 0; i < sizeof (options) / sizeof (options[0]); i++)
- {
- const char *name = options[i].name;
- int len = grub_strlen (name);
+ time2 = time1;
+ if (to > 0)
+ to--;
+ }
+ }
+ }
- if (! grub_memcmp (arg, name, len))
- {
- grub_strcpy (options[i].var, ti_unescape_string (arg + len));
- break;
- }
- }
- if (i == sizeof (options) / sizeof (options[0]))
- {
- errnum = ERR_BAD_ARGUMENT;
- return errnum;
- }
+ end:
+ current_term = term_table + default_term;
+ terminal_flags = term_flags;
- arg = next;
- }
+ if (lines)
+ max_lines = lines;
+ else
+ /* 24 would be a good default value. */
+ max_lines = 24;
- if (term.name[0] == 0 || term.cursor_address[0] == 0)
- {
- errnum = ERR_BAD_ARGUMENT;
- return errnum;
- }
-
- ti_set_term (&term);
- }
- else
- {
- /* No option specifies printing out current settings. */
- ti_get_term (&term);
-
- grub_printf ("name=%s\n",
- ti_escape_string (term.name));
- grub_printf ("cursor_address=%s\n",
- ti_escape_string (term.cursor_address));
- grub_printf ("clear_screen=%s\n",
- ti_escape_string (term.clear_screen));
- grub_printf ("enter_standout_mode=%s\n",
- ti_escape_string (term.enter_standout_mode));
- grub_printf ("exit_standout_mode=%s\n",
- ti_escape_string (term.exit_standout_mode));
- }
-
- return 0;
+ /* If the interface is currently the command-line, restart it to repaint the screen. */
+ //if (current_term != prev_term && (flags & BUILTIN_CMDLINE))
+ // grub_longjmp (restart_cmdline_env, 0);
+#endif
+ return 0;
}
-
-static struct builtin builtin_terminfo =
-{
- "terminfo",
- terminfo_func,
- BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
- "terminfo [--name=NAME --cursor-address=SEQ [--clear-screen=SEQ]"
- " [--enter-standout-mode=SEQ] [--exit-standout-mode=SEQ]]",
-
- "Define the capabilities of your terminal. Use this command to"
- " define escape sequences, if it is not vt100-compatible."
- " You may use \\e for ESC and ^X for a control character."
- " If no option is specified, the current settings are printed."
+static struct builtin builtin_terminal = {
+ "terminal",
+ terminal_func,
+ BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST | BUILTIN_NO_ECHO,
+ "terminal [--dumb] [--no-echo] [--no-edit] [--timeout=SECS] [--lines=LINES] [--silent] [console] [serial]",
+ "Select a terminal. When multiple terminals are specified, wait until"
+ " you push any key to continue. If both console and serial are specified,"
+ " the terminal to which you input a key first will be selected. If no"
+ " argument is specified, print current setting. The option --dumb"
+ " specifies that your terminal is dumb, otherwise, vt100-compatibility"
+ " is assumed. If you specify --no-echo, input characters won't be echoed."
+ " If you specify --no-edit, the BASH-like editing feature will be disabled."
+ " If --timeout is present, this command will wait at most for SECS"
+ " seconds. The option --lines specifies the maximum number of lines."
+ " The option --silent is used to suppress messages."
};
-
-
/* timeout */
-static int
-timeout_func (char *arg, int flags)
+static int timeout_func(char *arg, int flags)
{
- if (! safe_parse_maxint (&arg, &grub_timeout))
- return 1;
+ if (!safe_parse_maxint(&arg, &grub_timeout))
+ return 1;
- return 0;
+ return 0;
}
-static struct builtin builtin_timeout =
-{
- "timeout",
- timeout_func,
- BUILTIN_MENU,
+static struct builtin builtin_timeout = {
+ "timeout",
+ timeout_func,
+ BUILTIN_MENU,
#if 0
- "timeout SEC",
- "Set a timeout, in SEC seconds, before automatically booting the"
- " default entry (normally the first entry defined)."
+ "timeout SEC",
+ "Set a timeout, in SEC seconds, before automatically booting the"
+ " default entry (normally the first entry defined)."
#endif
};
-static int
-title_func (char *arg, int flags)
+static int title_func(char *arg, int flags)
{
- /* This function is not actually used at least currently. */
- return 0;
+ /* This function is not actually used at least currently. */
+ return 0;
}
-static struct builtin builtin_title =
-{
- "title",
- title_func,
- BUILTIN_TITLE,
+static struct builtin builtin_title = {
+ "title",
+ title_func,
+ BUILTIN_TITLE,
#if 0
- "title [NAME ...]",
- "Start a new boot entry, and set its name to the contents of the"
- " rest of the line, starting with the first non-space character."
+ "title [NAME ...]",
+ "Start a new boot entry, and set its name to the contents of the"
+ " rest of the line, starting with the first non-space character."
#endif
};
/* README !!! XXX !!! This list has to be alphabetically ordered !!! */
-struct builtin *builtin_table[] =
-{
+struct builtin *builtin_table[] = {
&builtin_boot,
&builtin_color,
&builtin_configfile,
@@ -1378,14 +1231,15 @@
&builtin_md5crypt,
#endif
&builtin_nvram_default,
+ &builtin_nvram_root,
&builtin_password,
&builtin_pause,
+ &builtin_poweroff,
+ &builtin_reboot,
&builtin_root,
&builtin_serial,
&builtin_terminal,
- &builtin_terminfo,
&builtin_timeout,
&builtin_title,
0
};
-
Modified: trunk/filo/main/grub/char_io.c
===================================================================
--- trunk/filo/main/grub/char_io.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/char_io.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -2,6 +2,7 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2004 Free Software Foundation, Inc.
+ * Copyright (C) 2005-2008 coresystems GmbH
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,192 +23,136 @@
#include <config.h>
#include <version.h>
#include <grub/shared.h>
-#include <grub/term.h>
-#include <grub/serial.h>
-char *err_list[] =
-{
- [ERR_NONE] = 0,
- [ERR_BAD_ARGUMENT] = "Invalid argument",
- [ERR_BAD_FILENAME] = "Filename must be either an absolute pathname or blocklist",
- [ERR_BAD_FILETYPE] = "Bad file or directory type",
- [ERR_BAD_GZIP_DATA] = "Bad or corrupt data while decompressing file",
- [ERR_BAD_GZIP_HEADER] = "Bad or incompatible header in compressed file",
- [ERR_BAD_PART_TABLE] = "Partition table invalid or corrupt",
- [ERR_BAD_VERSION] = "Mismatched or corrupt version of stage1/stage2",
- [ERR_BELOW_1MB] = "Loading below 1MB is not supported",
- [ERR_BOOT_COMMAND] = "Kernel must be loaded before booting",
- [ERR_BOOT_FAILURE] = "Unknown boot failure",
- [ERR_BOOT_FEATURES] = "Unsupported Multiboot features requested",
- [ERR_DEV_FORMAT] = "Unrecognized device string",
- [ERR_DEV_NEED_INIT] = "Device not initialized yet",
- [ERR_DEV_VALUES] = "Invalid device requested",
- [ERR_EXEC_FORMAT] = "Invalid or unsupported executable format",
- [ERR_FILELENGTH] = "Filesystem compatibility error, cannot read whole file",
- [ERR_FILE_NOT_FOUND] = "File not found",
- [ERR_FSYS_CORRUPT] = "Inconsistent filesystem structure",
- [ERR_FSYS_MOUNT] = "Cannot mount selected partition",
- [ERR_GEOM] = "Selected cylinder exceeds maximum supported by BIOS",
- [ERR_NEED_LX_KERNEL] = "Linux kernel must be loaded before initrd",
- [ERR_NEED_MB_KERNEL] = "Multiboot kernel must be loaded before modules",
- [ERR_NO_DISK] = "Selected disk does not exist",
- [ERR_NO_DISK_SPACE] = "No spare sectors on the disk",
- [ERR_NO_PART] = "No such partition",
- [ERR_NUMBER_OVERFLOW] = "Overflow while parsing number",
- [ERR_NUMBER_PARSING] = "Error while parsing number",
- [ERR_OUTSIDE_PART] = "Attempt to access block outside partition",
- [ERR_PRIVILEGED] = "Must be authenticated",
- [ERR_READ] = "Disk read error",
- [ERR_SYMLINK_LOOP] = "Too many symbolic links",
- [ERR_UNALIGNED] = "File is not sector aligned",
- [ERR_UNRECOGNIZED] = "Unrecognized command",
- [ERR_WONT_FIT] = "Selected item cannot fit into memory",
- [ERR_WRITE] = "Disk write error",
+char *err_list[] = {
+ [ERR_NONE] = 0,
+ [ERR_BAD_ARGUMENT] = "Invalid argument",
+ [ERR_BAD_FILENAME] = "Filename must be either an absolute pathname or blocklist",
+ [ERR_BAD_FILETYPE] = "Bad file or directory type",
+ [ERR_BAD_GZIP_DATA] = "Bad or corrupt data while decompressing file",
+ [ERR_BAD_GZIP_HEADER] = "Bad or incompatible header in compressed file",
+ [ERR_BAD_PART_TABLE] = "Partition table invalid or corrupt",
+ [ERR_BAD_VERSION] = "Mismatched or corrupt version of stage1/stage2",
+ [ERR_BELOW_1MB] = "Loading below 1MB is not supported",
+ [ERR_BOOT_COMMAND] = "Kernel must be loaded before booting",
+ [ERR_BOOT_FAILURE] = "Unknown boot failure",
+ [ERR_BOOT_FEATURES] = "Unsupported Multiboot features requested",
+ [ERR_DEV_FORMAT] = "Unrecognized device string",
+ [ERR_DEV_NEED_INIT] = "Device not initialized yet",
+ [ERR_DEV_VALUES] = "Invalid device requested",
+ [ERR_EXEC_FORMAT] = "Invalid or unsupported executable format",
+ [ERR_FILELENGTH] = "Filesystem compatibility error, cannot read whole file",
+ [ERR_FILE_NOT_FOUND] = "File not found",
+ [ERR_FSYS_CORRUPT] = "Inconsistent filesystem structure",
+ [ERR_FSYS_MOUNT] = "Cannot mount selected partition",
+ [ERR_GEOM] = "Selected cylinder exceeds maximum supported by BIOS",
+ [ERR_NEED_LX_KERNEL] = "Linux kernel must be loaded before initrd",
+ [ERR_NEED_MB_KERNEL] = "Multiboot kernel must be loaded before modules",
+ [ERR_NO_DISK] = "Selected disk does not exist",
+ [ERR_NO_DISK_SPACE] = "No spare sectors on the disk",
+ [ERR_NO_PART] = "No such partition",
+ [ERR_NUMBER_OVERFLOW] = "Overflow while parsing number",
+ [ERR_NUMBER_PARSING] = "Error while parsing number",
+ [ERR_OUTSIDE_PART] = "Attempt to access block outside partition",
+ [ERR_PRIVILEGED] = "Must be authenticated",
+ [ERR_READ] = "Disk read error",
+ [ERR_SYMLINK_LOOP] = "Too many symbolic links",
+ [ERR_UNALIGNED] = "File is not sector aligned",
+ [ERR_UNRECOGNIZED] = "Unrecognized command",
+ [ERR_WONT_FIT] = "Selected item cannot fit into memory",
+ [ERR_WRITE] = "Disk write error",
};
-
-
-struct term_entry term_table[] =
- {
-#if CONFIG_VGA_CONSOLE == 1 && CONFIG_PC_KEYBOARD ==1
- {
- "console",
- 0,
- console_putchar,
- console_checkkey,
- console_getkey,
- console_getxy,
- console_gotoxy,
- console_cls,
- console_setcolorstate,
- console_setcolor,
- console_setcursor
- },
-#endif
-#ifdef CONFIG_SERIAL_CONSOLE
- {
- "serial",
- /* A serial device must be initialized. */
-#if 0
- TERM_NEED_INIT,
-#else
- 0, // Not with FILO..
-#endif
- grub_serial_putchar,
- serial_checkkey,
- serial_getkey,
- serial_getxy,
- serial_gotoxy,
- serial_cls,
- serial_setcolorstate,
- 0,
- 0
- },
-#endif
- /* This must be the last entry. */
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
- };
-
-/* This must be console. */
-struct term_entry *current_term = term_table;
-
int max_lines = 24;
int count_lines = -1;
int use_pager = 1;
-void
-print_error (void)
+void print_error(void)
{
- if (errnum > ERR_NONE && errnum < MAX_ERR_NUM)
- grub_printf ("\nError %u: %s\n", errnum, err_list[errnum]);
+ if (errnum > ERR_NONE && errnum < MAX_ERR_NUM)
+ grub_printf("\nError %u: %s\n", errnum, err_list[errnum]);
}
-char *
-convert_to_ascii (char *buf, int c,...)
+char *convert_to_ascii(char *buf, int c, ...)
{
- unsigned long num = *((&c) + 1), mult = 10;
- char *ptr = buf;
+ unsigned long num = *((&c) + 1), mult = 10;
+ char *ptr = buf;
- if (c == 'x' || c == 'X')
- mult = 16;
+ if (c == 'x' || c == 'X')
+ mult = 16;
- if ((num & 0x80000000uL) && c == 'd')
- {
- num = (~num) + 1;
- *(ptr++) = '-';
- buf++;
- }
+ if ((num & 0x80000000uL) && c == 'd') {
+ num = (~num) + 1;
+ *(ptr++) = '-';
+ buf++;
+ }
- do
- {
- int dig = num % mult;
- *(ptr++) = ((dig > 9) ? dig + 'a' - 10 : '0' + dig);
- }
- while (num /= mult);
+ do {
+ int dig = num % mult;
+ *(ptr++) = ((dig > 9) ? dig + 'a' - 10 : '0' + dig);
+ }
+ while (num /= mult);
- /* reorder to correct direction!! */
- {
- char *ptr1 = ptr - 1;
- char *ptr2 = buf;
- while (ptr1 > ptr2)
- {
- int tmp = *ptr1;
- *ptr1 = *ptr2;
- *ptr2 = tmp;
- ptr1--;
- ptr2++;
- }
- }
+ /* reorder to correct direction!! */
+ {
+ char *ptr1 = ptr - 1;
+ char *ptr2 = buf;
+ while (ptr1 > ptr2) {
+ int tmp = *ptr1;
+ *ptr1 = *ptr2;
+ *ptr2 = tmp;
+ ptr1--;
+ ptr2++;
+ }
+ }
- return ptr;
+ return ptr;
}
-void
-grub_putstr (const char *str)
+void grub_putstr(const char *str)
{
- while (*str)
- grub_putchar (*str++);
+ while (*str)
+ grub_putchar(*str++);
}
-void
-grub_printf (const char *format,...)
+void grub_printf(const char *format, ...)
{
- int *dataptr = (int *) &format;
- char c, str[16];
-
- dataptr++;
+ int *dataptr = (int *) &format;
+ char c, str[16];
- while ((c = *(format++)) != 0)
- {
- if (c != '%')
- grub_putchar (c);
- else
- switch (c = *(format++))
- {
- case 'd':
- case 'x':
- case 'X':
- case 'u':
- *convert_to_ascii (str, c, *((unsigned long *) dataptr++)) = 0;
- grub_putstr (str);
- break;
+ dataptr++;
- case 'c':
- grub_putchar ((*(dataptr++)) & 0xff);
- break;
+ while ((c = *(format++)) != 0) {
+ if (c != '%')
+ grub_putchar(c);
+ else
+ switch (c = *(format++)) {
+ case 'd':
+ case 'x':
+ case 'X':
+ case 'u':
+ *convert_to_ascii(str, c, *((unsigned long *)
+ dataptr++)) = 0;
+ grub_putstr(str);
+ break;
- case 's':
- grub_putstr ((char *) *(dataptr++));
- break;
- }
- }
+ case 'c':
+ grub_putchar((*(dataptr++)) & 0xff);
+ break;
+
+ case 's':
+ grub_putstr((char *) *(dataptr++));
+ break;
+ }
+ }
+ refresh();
}
-void
-init_page (void)
+void init_page(void)
{
- cls ();
- grub_printf ("\n %s %s\n\n", PROGRAM_NAME, PROGRAM_VERSION);
+ cls();
+ grub_printf("\n %s %s\n\n",
+ PROGRAM_NAME, PROGRAM_VERSION);
}
/* The number of the history entries. */
@@ -215,534 +160,465 @@
/* Get the NOth history. If NO is less than zero or greater than or
equal to NUM_HISTORY, return NULL. Otherwise return a valid string. */
-static char *
-get_history (int no)
+static char *get_history(int no)
{
- if (no < 0 || no >= num_history)
- return 0;
+ if (no < 0 || no >= num_history)
+ return 0;
- return (char *) HISTORY_BUF + MAX_CMDLINE * no;
+ return (char *) HISTORY_BUF + MAX_CMDLINE * no;
}
/* Add CMDLINE to the history buffer. */
-static void
-add_history (const char *cmdline, int no)
+static void add_history(const char *cmdline, int no)
{
- grub_memmove ((char *) HISTORY_BUF + MAX_CMDLINE * (no + 1),
- (char *) HISTORY_BUF + MAX_CMDLINE * no,
- MAX_CMDLINE * (num_history - no));
- grub_strcpy ((char *) HISTORY_BUF + MAX_CMDLINE * no, cmdline);
- if (num_history < HISTORY_SIZE)
- num_history++;
+ memmove((char *) HISTORY_BUF + MAX_CMDLINE * (no + 1),
+ (char *) HISTORY_BUF + MAX_CMDLINE * no, MAX_CMDLINE * (num_history - no));
+ strcpy((char *) HISTORY_BUF + MAX_CMDLINE * no, cmdline);
+ if (num_history < HISTORY_SIZE)
+ num_history++;
}
-static int
-real_get_cmdline (char *prompt, char *cmdline, int maxlen,
- int echo_char, int readline)
+static int real_get_cmdline(char *prompt, char *cmdline, int maxlen, int echo_char, int readline)
{
- /* This is a rather complicated function. So explain the concept.
-
- A command-line consists of ``section''s. A section is a part of the
- line which may be displayed on the screen, but a section is never
- displayed with another section simultaneously.
+ /* This is a rather complicated function. So explain the concept.
- Each section is basically 77 or less characters, but the exception
- is the first section, which is 78 or less characters, because the
- starting point is special. See below.
+ A command-line consists of ``section''s. A section is a part of the
+ line which may be displayed on the screen, but a section is never
+ displayed with another section simultaneously.
- The first section contains a prompt and a command-line (or the
- first part of a command-line when it is too long to be fit in the
- screen). So, in the first section, the number of command-line
- characters displayed is 78 minus the length of the prompt (or
- less). If the command-line has more characters, `>' is put at the
- position 78 (zero-origin), to inform the user of the hidden
- characters.
+ Each section is basically 77 or less characters, but the exception
+ is the first section, which is 78 or less characters, because the
+ starting point is special. See below.
- Other sections always have `<' at the first position, since there
- is absolutely a section before each section. If there is a section
- after another section, this section consists of 77 characters and
- `>' at the last position. The last section has 77 or less
- characters and doesn't have `>'.
+ The first section contains a prompt and a command-line (or the
+ first part of a command-line when it is too long to be fit in the
+ screen). So, in the first section, the number of command-line
+ characters displayed is 78 minus the length of the prompt (or
+ less). If the command-line has more characters, `>' is put at the
+ position 78 (zero-origin), to inform the user of the hidden
+ characters.
- Each section other than the last shares some characters with the
- previous section. This region is called ``margin''. If the cursor
- is put at the magin which is shared by the first section and the
- second, the first section is displayed. Otherwise, a displayed
- section is switched to another section, only if the cursor is put
- outside that section. */
+ Other sections always have `<' at the first position, since there
+ is absolutely a section before each section. If there is a section
+ after another section, this section consists of 77 characters and
+ `>' at the last position. The last section has 77 or less
+ characters and doesn't have `>'.
- /* XXX: These should be defined in shared.h, but I leave these here,
- until this code is freezed. */
+ Each section other than the last shares some characters with the
+ previous section. This region is called ``margin''. If the cursor
+ is put at the magin which is shared by the first section and the
+ second, the first section is displayed. Otherwise, a displayed
+ section is switched to another section, only if the cursor is put
+ outside that section. */
+
+ /* XXX: These should be defined in shared.h, but I leave these here,
+ until this code is freezed. */
#define CMDLINE_WIDTH 78
#define CMDLINE_MARGIN 10
-
- int xpos, lpos, c, section;
- /* The length of PROMPT. */
- int plen;
- /* The length of the command-line. */
- int llen;
- /* The index for the history. */
- int history = -1;
- /* The working buffer for the command-line. */
- char *buf = (char *) CMDLINE_BUF;
- /* The kill buffer. */
- char *kill_buf = (char *) KILL_BUF;
-
- /* Nested function definitions for code simplicity. */
- /* The forward declarations of nested functions are prefixed
- with `auto'. */
- auto void cl_refresh (int full, int len);
- auto void cl_backward (int count);
- auto void cl_forward (int count);
- auto void cl_insert (const char *str);
- auto void cl_delete (int count);
- auto void cl_init (void);
-
- /* Move the cursor backward. */
- void cl_backward (int count)
- {
- lpos -= count;
-
- /* If the cursor is in the first section, display the first section
- instead of the second. */
- if (section == 1 && plen + lpos < CMDLINE_WIDTH)
- cl_refresh (1, 0);
- else if (xpos - count < 1)
- cl_refresh (1, 0);
- else
- {
- xpos -= count;
+ int xpos, lpos, c, section;
+ /* The length of PROMPT. */
+ int plen;
+ /* The length of the command-line. */
+ int llen;
+ /* The index for the history. */
+ int history = -1;
+ /* The working buffer for the command-line. */
+ char *buf = (char *) CMDLINE_BUF;
+ /* The kill buffer. */
+ char *kill_buf = (char *) KILL_BUF;
- if (current_term->flags & TERM_DUMB)
- {
- int i;
-
- for (i = 0; i < count; i++)
- grub_putchar ('\b');
- }
- else
- gotoxy (xpos, getxy () & 0xFF);
- }
- }
+ /* Nested function definitions for code simplicity. */
- /* Move the cursor forward. */
- void cl_forward (int count)
- {
- lpos += count;
+ /* The forward declarations of nested functions are prefixed
+ * with `auto'. */
+ auto void cl_refresh(int full, int len);
+ auto void cl_backward(int count);
+ auto void cl_forward(int count);
+ auto void cl_insert(const char *str);
+ auto void cl_delete(int count);
+ auto void cl_init(void);
- /* If the cursor goes outside, scroll the screen to the right. */
- if (xpos + count >= CMDLINE_WIDTH)
- cl_refresh (1, 0);
- else
- {
- xpos += count;
+ /* Move the cursor backward. */
+ void cl_backward(int count) {
+ lpos -= count;
- if (current_term->flags & TERM_DUMB)
- {
- int i;
-
- for (i = lpos - count; i < lpos; i++)
- {
- if (! echo_char)
- grub_putchar (buf[i]);
- else
- grub_putchar (echo_char);
+ /* If the cursor is in the first section, display the first section
+ instead of the second. */
+ if (section == 1 && plen + lpos < CMDLINE_WIDTH)
+ cl_refresh(1, 0);
+ else if (xpos - count < 1)
+ cl_refresh(1, 0);
+ else {
+ xpos -= count;
+
+ gotoxy(xpos, getxy() & 0xFF);
}
- }
- else
- gotoxy (xpos, getxy () & 0xFF);
+ refresh();
}
- }
- /* Refresh the screen. If FULL is true, redraw the full line, otherwise,
- only LEN characters from LPOS. */
- void cl_refresh (int full, int len)
- {
- int i;
- int start;
- int pos = xpos;
-
- if (full)
- {
- /* Recompute the section number. */
- if (lpos + plen < CMDLINE_WIDTH)
- section = 0;
- else
- section = ((lpos + plen - CMDLINE_WIDTH)
- / (CMDLINE_WIDTH - 1 - CMDLINE_MARGIN) + 1);
+ /* Move the cursor forward. */
+ void cl_forward(int count) {
+ lpos += count;
- /* From the start to the end. */
- len = CMDLINE_WIDTH;
- pos = 0;
- grub_putchar ('\r');
+ /* If the cursor goes outside, scroll the screen to the right. */
+ if (xpos + count >= CMDLINE_WIDTH)
+ cl_refresh(1, 0);
+ else {
+ xpos += count;
- /* If SECTION is the first section, print the prompt, otherwise,
- print `<'. */
- if (section == 0)
- {
- grub_printf ("%s", prompt);
- len -= plen;
- pos += plen;
- }
- else
- {
- grub_putchar ('<');
- len--;
- pos++;
- }
+ gotoxy(xpos, getxy() & 0xFF);
+ }
+ refresh();
}
- /* Compute the index to start writing BUF and the resulting position
- on the screen. */
- if (section == 0)
- {
- int offset = 0;
-
- if (! full)
- offset = xpos - plen;
-
- start = 0;
- xpos = lpos + plen;
- start += offset;
- }
- else
- {
- int offset = 0;
-
- if (! full)
- offset = xpos - 1;
-
- start = ((section - 1) * (CMDLINE_WIDTH - 1 - CMDLINE_MARGIN)
- + CMDLINE_WIDTH - plen - CMDLINE_MARGIN);
- xpos = lpos + 1 - start;
- start += offset;
- }
+ /* Refresh the screen. If FULL is true, redraw the full line, otherwise,
+ only LEN characters from LPOS. */
+ void cl_refresh(int full, int len) {
+ int i;
+ int start;
+ int pos = xpos;
- /* Print BUF. If ECHO_CHAR is not zero, put it instead. */
- for (i = start; i < start + len && i < llen; i++)
- {
- if (! echo_char)
- grub_putchar (buf[i]);
- else
- grub_putchar (echo_char);
+ if (full) {
+ /* Recompute the section number. */
+ if (lpos + plen < CMDLINE_WIDTH)
+ section = 0;
+ else
+ section = ((lpos + plen - CMDLINE_WIDTH)
+ / (CMDLINE_WIDTH - 1 - CMDLINE_MARGIN) + 1);
- pos++;
+ /* From the start to the end. */
+ len = CMDLINE_WIDTH;
+ pos = 0;
+ grub_putchar('\r');
+
+ /* If SECTION is the first section, print the prompt, otherwise,
+ print `<'. */
+ if (section == 0) {
+ grub_printf("%s", prompt);
+ len -= plen;
+ pos += plen;
+ } else {
+ grub_putchar('<');
+ len--;
+ pos++;
+ }
+ }
+
+ /* Compute the index to start writing BUF and the resulting position
+ on the screen. */
+ if (section == 0) {
+ int offset = 0;
+
+ if (!full)
+ offset = xpos - plen;
+
+ start = 0;
+ xpos = lpos + plen;
+ start += offset;
+ } else {
+ int offset = 0;
+
+ if (!full)
+ offset = xpos - 1;
+
+ start = ((section - 1) * (CMDLINE_WIDTH - 1 - CMDLINE_MARGIN)
+ + CMDLINE_WIDTH - plen - CMDLINE_MARGIN);
+ xpos = lpos + 1 - start;
+ start += offset;
+ }
+
+ /* Print BUF. If ECHO_CHAR is not zero, put it instead. */
+ for (i = start; i < start + len && i < llen; i++) {
+ if (!echo_char)
+ grub_putchar(buf[i]);
+ else
+ grub_putchar(echo_char);
+
+ pos++;
+ }
+
+ /* Fill up the rest of the line with spaces. */
+ for (; i < start + len; i++) {
+ grub_putchar(' ');
+ pos++;
+ }
+ /* If the cursor is at the last position, put `>' or a space,
+ depending on if there are more characters in BUF. */
+ if (pos == CMDLINE_WIDTH) {
+ if (start + len < llen)
+ grub_putchar('>');
+ else
+ grub_putchar(' ');
+
+ pos++;
+ }
+
+ /* Back to XPOS. */
+ gotoxy(xpos, getxy() & 0xFF);
+
+ refresh();
}
-
- // FIXME
-#if 1
- /* Fill up the rest of the line with spaces. */
- for (; i < start + len; i++)
- {
- grub_putchar (' ');
- pos++;
- }
- /* If the cursor is at the last position, put `>' or a space,
- depending on if there are more characters in BUF. */
- if (pos == CMDLINE_WIDTH)
- {
- if (start + len < llen)
- grub_putchar ('>');
- else
- grub_putchar (' ');
-
- pos++;
- }
-
- /* Back to XPOS. */
- if (current_term->flags & TERM_DUMB)
- {
- for (i = 0; i < pos - xpos; i++)
- grub_putchar ('\b');
- }
- else
- gotoxy (xpos, getxy () & 0xFF);
-#endif
- }
-
- /* Initialize the command-line. */
- void cl_init (void)
- {
+ /* Initialize the command-line. */
+ void cl_init(void) {
#ifdef CONFIG_NEWLINE_BEFORE_EACH_PROMPT
- /* Distinguish us from other lines and error messages! */
- grub_putchar ('\n');
+ /* Distinguish us from other lines and error messages! */
+ grub_putchar('\n');
#endif
- /* Print full line and set position here. */
- cl_refresh (1, 0);
- }
+ /* Print full line and set position here. */
+ cl_refresh(1, 0);
+ }
- /* Insert STR to BUF. */
- void cl_insert (const char *str)
- {
- int l = grub_strlen (str);
+ /* Insert STR to BUF. */
+ void cl_insert(const char *str) {
+ int l = strlen(str);
- if (llen + l < maxlen)
- {
- if (lpos == llen)
- grub_memmove (buf + lpos, str, l + 1);
- else
- {
- grub_memmove (buf + lpos + l, buf + lpos, llen - lpos + 1);
- grub_memmove (buf + lpos, str, l);
- }
-
- llen += l;
- lpos += l;
- if (xpos + l >= CMDLINE_WIDTH)
- cl_refresh (1, 0);
- else if (xpos + l + llen - lpos > CMDLINE_WIDTH)
- cl_refresh (0, CMDLINE_WIDTH - xpos);
- else
- cl_refresh (0, l + llen - lpos);
+ if (llen + l < maxlen) {
+ if (lpos == llen)
+ memmove(buf + lpos, str, l + 1);
+ else {
+ memmove(buf + lpos + l, buf + lpos, llen - lpos + 1);
+ memmove(buf + lpos, str, l);
+ }
+
+ llen += l;
+ lpos += l;
+ if (xpos + l >= CMDLINE_WIDTH)
+ cl_refresh(1, 0);
+ else if (xpos + l + llen - lpos > CMDLINE_WIDTH)
+ cl_refresh(0, CMDLINE_WIDTH - xpos);
+ else
+ cl_refresh(0, l + llen - lpos);
+ }
}
- }
- /* Delete COUNT characters in BUF. */
- void cl_delete (int count)
- {
- grub_memmove (buf + lpos, buf + lpos + count, llen - count + 1);
- llen -= count;
-
- if (xpos + llen + count - lpos > CMDLINE_WIDTH)
- cl_refresh (0, CMDLINE_WIDTH - xpos);
- else
- cl_refresh (0, llen + count - lpos);
- }
+ /* Delete COUNT characters in BUF. */
+ void cl_delete(int count) {
+ memmove(buf + lpos, buf + lpos + count, llen - count + 1);
+ llen -= count;
- plen = grub_strlen (prompt);
- llen = grub_strlen (cmdline);
+ if (xpos + llen + count - lpos > CMDLINE_WIDTH)
+ cl_refresh(0, CMDLINE_WIDTH - xpos);
+ else
+ cl_refresh(0, llen + count - lpos);
+ }
- if (maxlen > MAX_CMDLINE)
- {
- maxlen = MAX_CMDLINE;
- if (llen >= MAX_CMDLINE)
- {
- llen = MAX_CMDLINE - 1;
- cmdline[MAX_CMDLINE] = 0;
+ plen = strlen(prompt);
+ llen = strlen(cmdline);
+
+ if (maxlen > MAX_CMDLINE) {
+ maxlen = MAX_CMDLINE;
+ if (llen >= MAX_CMDLINE) {
+ llen = MAX_CMDLINE - 1;
+ cmdline[MAX_CMDLINE] = 0;
+ }
}
- }
- lpos = llen;
- grub_strcpy (buf, cmdline);
+ lpos = llen;
+ strcpy(buf, cmdline);
- cl_init ();
+ cl_init();
- while ((c = ASCII_CHAR (getkey ())) != '\n' && c != '\r')
- {
- /* If READLINE is non-zero, handle readline-like key bindings. */
- if (readline)
- {
- switch (c)
- {
- case 9: /* TAB lists completions */
- {
- int i;
- /* POS points to the first space after a command. */
- int pos = 0;
- int ret;
- char *completion_buffer = (char *) COMPLETION_BUF;
- int equal_pos = -1;
- int is_filename;
+ while ((c = ASCII_CHAR(getkey())) != '\n' && c != '\r') {
+ /* If READLINE is non-zero, handle readline-like key bindings. */
+ if (readline) {
+ switch (c) {
+ case 9: /* TAB lists completions */
+ {
+ int i;
+ /* POS points to the first space after a command. */
+ int pos = 0;
+ int ret;
+ char *completion_buffer = (char *) COMPLETION_BUF;
+ int equal_pos = -1;
+ int is_filename;
- /* Find the first word. */
- while (buf[pos] == ' ')
- pos++;
- while (buf[pos] && buf[pos] != '=' && buf[pos] != ' ')
- pos++;
+ /* Find the first word. */
+ while (buf[pos] == ' ')
+ pos++;
+ while (buf[pos] && buf[pos] != '=' && buf[pos] != ' ')
+ pos++;
- is_filename = (lpos > pos);
+ is_filename = (lpos > pos);
- /* Find the position of the equal character after a
- command, and replace it with a space. */
- for (i = pos; buf[i] && buf[i] != ' '; i++)
- if (buf[i] == '=')
- {
- equal_pos = i;
- buf[i] = ' ';
- break;
- }
+ /* Find the position of the equal character after a
+ command, and replace it with a space. */
+ for (i = pos; buf[i] && buf[i] != ' '; i++)
+ if (buf[i] == '=') {
+ equal_pos = i;
+ buf[i] = ' ';
+ break;
+ }
- /* Find the position of the first character in this
- word. */
- for (i = lpos; i > 0 && buf[i - 1] != ' '; i--)
- ;
+ /* Find the position of the first character in this
+ word. */
+ for (i = lpos; i > 0 && buf[i - 1] != ' '; i--);
- /* Invalidate the cache, because the user may exchange
- removable disks. */
- buf_drive = -1;
+ /* Copy this word to COMPLETION_BUFFER and do the
+ completion. */
+ memmove(completion_buffer, buf + i, lpos - i);
+ completion_buffer[lpos - i] = 0;
+ ret = print_completions(is_filename, 1);
+ errnum = ERR_NONE;
- /* Copy this word to COMPLETION_BUFFER and do the
- completion. */
- grub_memmove (completion_buffer, buf + i, lpos - i);
- completion_buffer[lpos - i] = 0;
- ret = print_completions (is_filename, 1);
- errnum = ERR_NONE;
+ if (ret >= 0) {
+ /* Found, so insert COMPLETION_BUFFER. */
+ cl_insert(completion_buffer + lpos - i);
- if (ret >= 0)
- {
- /* Found, so insert COMPLETION_BUFFER. */
- cl_insert (completion_buffer + lpos - i);
+ if (ret > 0) {
+ /* There are more than one candidates, so print
+ the list. */
+ grub_putchar('\n');
+ print_completions(is_filename, 0);
+ errnum = ERR_NONE;
+ }
+ }
- if (ret > 0)
- {
- /* There are more than one candidates, so print
- the list. */
- grub_putchar ('\n');
- print_completions (is_filename, 0);
- errnum = ERR_NONE;
- }
- }
+ /* Restore the command-line. */
+ if (equal_pos >= 0)
+ buf[equal_pos] = '=';
- /* Restore the command-line. */
- if (equal_pos >= 0)
- buf[equal_pos] = '=';
+ if (ret)
+ cl_init();
+ }
- if (ret)
- cl_init ();
- }
-
- break;
- case 1: /* C-a go to beginning of line */
- cl_backward (lpos);
- break;
- case 5: /* C-e go to end of line */
- cl_forward (llen - lpos);
- break;
- case 6: /* C-f forward one character */
- if (lpos < llen)
- cl_forward (1);
- break;
- case 2: /* C-b backward one character */
- if (lpos > 0)
- cl_backward (1);
- break;
- case 21: /* C-u kill to beginning of line */
- if (lpos == 0)
- break;
- /* Copy the string being deleted to KILL_BUF. */
- grub_memmove (kill_buf, buf, lpos);
- kill_buf[lpos] = 0;
- {
- /* XXX: Not very clever. */
-
- int count = lpos;
-
- cl_backward (lpos);
- cl_delete (count);
- }
- break;
- case 11: /* C-k kill to end of line */
- if (lpos == llen)
- break;
- /* Copy the string being deleted to KILL_BUF. */
- grub_memmove (kill_buf, buf + lpos, llen - lpos + 1);
- cl_delete (llen - lpos);
- break;
- case 25: /* C-y yank the kill buffer */
- cl_insert (kill_buf);
- break;
- case 16: /* C-p fetch the previous command */
- {
- char *p;
+ break;
+ case 1: /* C-a go to beginning of line */
+ cl_backward(lpos);
+ break;
+ case 5: /* C-e go to end of line */
+ cl_forward(llen - lpos);
+ break;
+ case 6: /* C-f forward one character */
+ if (lpos < llen)
+ cl_forward(1);
+ break;
+ case 2: /* C-b backward one character */
+ if (lpos > 0)
+ cl_backward(1);
+ break;
+ case 21: /* C-u kill to beginning of line */
+ if (lpos == 0)
+ break;
+ /* Copy the string being deleted to KILL_BUF. */
+ memmove(kill_buf, buf, lpos);
+ kill_buf[lpos] = 0;
+ {
+ /* XXX: Not very clever. */
- if (history < 0)
- /* Save the working buffer. */
- grub_strcpy (cmdline, buf);
- else if (grub_strcmp (get_history (history), buf) != 0)
- /* If BUF is modified, add it into the history list. */
- add_history (buf, history);
+ int count = lpos;
- history++;
- p = get_history (history);
- if (! p)
- {
- history--;
- break;
- }
+ cl_backward(lpos);
+ cl_delete(count);
+ }
+ break;
+ case 11: /* C-k kill to end of line */
+ if (lpos == llen)
+ break;
+ /* Copy the string being deleted to KILL_BUF. */
+ memmove(kill_buf, buf + lpos, llen - lpos + 1);
+ cl_delete(llen - lpos);
+ break;
+ case 25: /* C-y yank the kill buffer */
+ cl_insert(kill_buf);
+ break;
+ case 16: /* C-p fetch the previous command */
+ {
+ char *p;
- grub_strcpy (buf, p);
- llen = grub_strlen (buf);
- lpos = llen;
- cl_refresh (1, 0);
- }
- break;
- case 14: /* C-n fetch the next command */
- {
- char *p;
+ if (history < 0)
+ /* Save the working buffer. */
+ strcpy(cmdline, buf);
+ else if (strcmp(get_history(history), buf) != 0)
+ /* If BUF is modified, add it into the history list. */
+ add_history(buf, history);
- if (history < 0)
- {
- break;
- }
- else if (grub_strcmp (get_history (history), buf) != 0)
- /* If BUF is modified, add it into the history list. */
- add_history (buf, history);
+ history++;
+ p = get_history(history);
+ if (!p) {
+ history--;
+ break;
+ }
- history--;
- p = get_history (history);
- if (! p)
- p = cmdline;
+ strcpy(buf, p);
+ llen = strlen(buf);
+ lpos = llen;
+ cl_refresh(1, 0);
+ }
+ break;
+ case 14: /* C-n fetch the next command */
+ {
+ char *p;
- grub_strcpy (buf, p);
- llen = grub_strlen (buf);
- lpos = llen;
- cl_refresh (1, 0);
- }
- break;
- }
- }
+ if (history < 0) {
+ break;
+ } else if (strcmp(get_history(history), buf) != 0)
+ /* If BUF is modified, add it into the history list. */
+ add_history(buf, history);
- /* ESC, C-d and C-h are always handled. Actually C-d is not
- functional if READLINE is zero, as the cursor cannot go
- backward, but that's ok. */
- switch (c)
- {
- case 27: /* ESC immediately return 1 */
- return 1;
- case 4: /* C-d delete character under cursor */
- if (lpos == llen)
- break;
- cl_delete (1);
- break;
- case 8: /* C-h backspace */
- case 127: /* also backspace */
- if (lpos > 0)
- {
- cl_backward (1);
- cl_delete (1);
- }
- break;
- default: /* insert printable character into line */
- if (c >= ' ' && c <= '~')
- {
- char str[2];
+ history--;
+ p = get_history(history);
+ if (!p)
+ p = cmdline;
- str[0] = c;
- str[1] = 0;
- cl_insert (str);
- }
+ strcpy(buf, p);
+ llen = strlen(buf);
+ lpos = llen;
+ cl_refresh(1, 0);
+ }
+ break;
+ }
+ }
+
+ /* ESC, C-d and C-h are always handled. Actually C-d is not
+ functional if READLINE is zero, as the cursor cannot go
+ backward, but that's ok. */
+ switch (c) {
+ case 27: /* ESC immediately return 1 */
+ return 1;
+ case 4: /* C-d delete character under cursor */
+ if (lpos == llen)
+ break;
+ cl_delete(1);
+ break;
+ case 8: /* C-h backspace */
+ case 127: /* also backspace */
+ if (lpos > 0) {
+ cl_backward(1);
+ cl_delete(1);
+ }
+ break;
+ default: /* insert printable character into line */
+ if (c >= ' ' && c <= '~') {
+ char str[2];
+
+ str[0] = c;
+ str[1] = 0;
+ cl_insert(str);
+ }
+ }
}
- }
- grub_putchar ('\n');
+ grub_putchar('\n');
- /* If ECHO_CHAR is NUL, remove the leading spaces. */
- lpos = 0;
- if (! echo_char)
- while (buf[lpos] == ' ')
- lpos++;
+ /* If ECHO_CHAR is NUL, remove the leading spaces. */
+ lpos = 0;
+ if (!echo_char)
+ while (buf[lpos] == ' ')
+ lpos++;
- /* Copy the working buffer to CMDLINE. */
- grub_memmove (cmdline, buf + lpos, llen - lpos + 1);
+ /* Copy the working buffer to CMDLINE. */
+ memmove(cmdline, buf + lpos, llen - lpos + 1);
- /* If the readline-like feature is turned on and CMDLINE is not
- empty, add it into the history list. */
- if (readline && lpos < llen)
- add_history (cmdline, 0);
+ /* If the readline-like feature is turned on and CMDLINE is not
+ empty, add it into the history list. */
+ if (readline && lpos < llen)
+ add_history(cmdline, 0);
- return 0;
+ refresh();
+
+ return 0;
}
/* Don't use this with a MAXLEN greater than 1600 or so! The problem
@@ -753,257 +629,394 @@
or zero-length).
If ECHO_CHAR is nonzero, echo it instead of the typed character. */
-int
-get_cmdline (char *prompt, char *cmdline, int maxlen,
- int echo_char, int readline)
+int get_cmdline(char *prompt, char *cmdline, int maxlen, int echo_char, int readline)
{
- int old_cursor;
- int ret;
+ int old_cursor;
+ int ret;
- old_cursor = setcursor (1);
-
- /* Because it is hard to deal with different conditions simultaneously,
- less functional cases are handled here. Assume that TERM_NO_ECHO
- implies TERM_NO_EDIT. */
- if (current_term->flags & (TERM_NO_ECHO | TERM_NO_EDIT))
- {
- char *p = cmdline;
- int c;
-
- /* Make sure that MAXLEN is not too large. */
- if (maxlen > MAX_CMDLINE)
- maxlen = MAX_CMDLINE;
+ old_cursor = setcursor(1);
- /* Print only the prompt. The contents of CMDLINE is simply discarded,
- even if it is not empty. */
- grub_printf ("%s", prompt);
+ /* Because it is hard to deal with different conditions simultaneously,
+ less functional cases are handled here. Assume that TERM_NO_ECHO
+ implies TERM_NO_EDIT. */
+ if (terminal_flags & (TERM_NO_ECHO | TERM_NO_EDIT)) {
+ char *p = cmdline;
+ int c;
- /* Gather characters until a newline is gotten. */
- while ((c = ASCII_CHAR (getkey ())) != '\n' && c != '\r')
- {
- /* Return immediately if ESC is pressed. */
- if (c == 27)
- {
- setcursor (old_cursor);
- return 1;
- }
+ /* Make sure that MAXLEN is not too large. */
+ if (maxlen > MAX_CMDLINE)
+ maxlen = MAX_CMDLINE;
- /* Printable characters are added into CMDLINE. */
- if (c >= ' ' && c <= '~')
- {
- if (! (current_term->flags & TERM_NO_ECHO))
- grub_putchar (c);
+ /* Print only the prompt. The contents of CMDLINE is simply discarded,
+ even if it is not empty. */
+ grub_printf("%s", prompt);
- /* Preceding space characters must be ignored. */
- if (c != ' ' || p != cmdline)
- *p++ = c;
- }
- }
+ /* Gather characters until a newline is gotten. */
+ while ((c = ASCII_CHAR(getkey())) != '\n' && c != '\r') {
+ /* Return immediately if ESC is pressed. */
+ if (c == 27) {
+ setcursor(old_cursor);
+ return 1;
+ }
- *p = 0;
+ /* Printable characters are added into CMDLINE. */
+ if (c >= ' ' && c <= '~') {
+ if (!(terminal_flags & TERM_NO_ECHO))
+ grub_putchar(c);
- if (! (current_term->flags & TERM_NO_ECHO))
- grub_putchar ('\n');
+ /* Preceding space characters must be ignored. */
+ if (c != ' ' || p != cmdline)
+ *p++ = c;
+ }
+ }
- setcursor (old_cursor);
- return 0;
- }
+ *p = 0;
- /* Complicated features are left to real_get_cmdline. */
- ret = real_get_cmdline (prompt, cmdline, maxlen, echo_char, readline);
- setcursor (old_cursor);
- return ret;
+ if (!(terminal_flags & TERM_NO_ECHO))
+ grub_putchar('\n');
+
+ setcursor(old_cursor);
+ refresh();
+ return 0;
+ }
+
+ /* Complicated features are left to real_get_cmdline. */
+ ret = real_get_cmdline(prompt, cmdline, maxlen, echo_char, readline);
+ setcursor(old_cursor);
+ refresh();
+ return ret;
}
-int
-safe_parse_maxint (char **str_ptr, int *myint_ptr)
+int safe_parse_maxint(char **str_ptr, int *myint_ptr)
{
- char *ptr = *str_ptr;
- int myint = 0;
- int mult = 10, found = 0;
+ char *ptr = *str_ptr;
+ int myint = 0;
+ int mult = 10, found = 0;
- /*
- * Is this a hex number?
- */
- if (*ptr == '0' && tolower (*(ptr + 1)) == 'x')
- {
- ptr += 2;
- mult = 16;
- }
+ /*
+ * Is this a hex number?
+ */
+ if (*ptr == '0' && tolower(*(ptr + 1)) == 'x') {
+ ptr += 2;
+ mult = 16;
+ }
- while (1)
- {
- /* A bit tricky. This below makes use of the equivalence:
- (A >= B && A <= C) <=> ((A - B) <= (C - B))
- when C > B and A is unsigned. */
- unsigned int digit;
+ while (1) {
+ /* A bit tricky. This below makes use of the equivalence:
+ (A >= B && A <= C) <=> ((A - B) <= (C - B))
+ when C > B and A is unsigned. */
+ unsigned int digit;
- digit = tolower (*ptr) - '0';
- if (digit > 9)
- {
- digit -= 'a' - '0';
- if (mult == 10 || digit > 5)
- break;
- digit += 10;
+ digit = tolower(*ptr) - '0';
+ if (digit > 9) {
+ digit -= 'a' - '0';
+ if (mult == 10 || digit > 5)
+ break;
+ digit += 10;
+ }
+
+ found = 1;
+ if (myint > ((MAXINT - digit) / mult)) {
+ errnum = ERR_NUMBER_OVERFLOW;
+ return 0;
+ }
+ myint = (myint * mult) + digit;
+ ptr++;
}
- found = 1;
- if (myint > ((MAXINT - digit) / mult))
- {
- errnum = ERR_NUMBER_OVERFLOW;
- return 0;
+ if (!found) {
+ errnum = ERR_NUMBER_PARSING;
+ return 0;
}
- myint = (myint * mult) + digit;
- ptr++;
- }
- if (!found)
- {
- errnum = ERR_NUMBER_PARSING;
- return 0;
- }
+ *str_ptr = ptr;
+ *myint_ptr = myint;
- *str_ptr = ptr;
- *myint_ptr = myint;
+ return 1;
+}
- return 1;
+int terminal_flags;
+
+static int console_current_color = A_NORMAL;
+static int console_standard_color = A_NORMAL;
+static int console_normal_color = A_NORMAL;
+static int console_highlight_color = A_REVERSE;
+static color_state console_color_state = COLOR_STATE_STANDARD;
+
+void console_setcolorstate(color_state state)
+{
+ switch (state) {
+ case COLOR_STATE_STANDARD:
+ console_current_color = console_standard_color;
+ break;
+ case COLOR_STATE_NORMAL:
+ console_current_color = console_normal_color;
+ break;
+ case COLOR_STATE_HIGHLIGHT:
+ console_current_color = console_highlight_color;
+ break;
+ default:
+ console_current_color = console_standard_color;
+ break;
+ }
+
+ console_color_state = state;
}
-/* Wait for a keypress and return its code. */
-int
-getkey (void)
+void console_setcolor(int normal_color, int highlight_color)
{
- return current_term->getkey ();
+ console_normal_color = normal_color;
+ console_highlight_color = highlight_color;
+
+ console_setcolorstate(console_color_state);
}
-/* Check if a key code is available. */
-int
-checkkey (void)
+/* The store for ungetch simulation. This is necessary, because
+ ncurses-1.9.9g is still used in the world and its ungetch is
+ completely broken. */
+static int save_char = ERR;
+
+static int console_translate_key(int c)
{
- return current_term->checkkey ();
+ switch (c) {
+ case KEY_LEFT:
+ return 2;
+ case KEY_RIGHT:
+ return 6;
+ case KEY_UP:
+ return 16;
+ case KEY_DOWN:
+ return 14;
+ case KEY_DC:
+ return 4;
+ case KEY_BACKSPACE:
+ return 8;
+ case KEY_HOME:
+ return 1;
+ case KEY_END:
+ return 5;
+ case KEY_PPAGE:
+ return 7;
+ case KEY_NPAGE:
+ return 3;
+ case KEY_ENTER:
+ return 13;
+ default:
+ break;
+ }
+
+ return c;
}
+/* like 'getkey', but doesn't wait, returns -1 if nothing available */
+int checkkey(void)
+{
+ int c;
+
+ /* Check for SAVE_CHAR. This should not be true, because this
+ means checkkey is called twice continuously. */
+ if (save_char != ERR)
+ return save_char;
+
+ c = getch();
+ /* If C is not ERR, then put it back in the input queue. */
+ if (c != ERR)
+ save_char = c;
+ return console_translate_key(c);
+
+}
+
+/* returns packed BIOS/ASCII code */
+int getkey(void)
+{
+ int c;
+
+ /* If checkkey has already got a character, then return it. */
+ if (save_char != ERR) {
+ c = save_char;
+ save_char = ERR;
+ return console_translate_key(c);
+ }
+
+ wtimeout(stdscr, -1);
+ c = getch();
+ wtimeout(stdscr, 100);
+
+ return console_translate_key(c);
+}
+
/* Display an ASCII character. */
-void
-grub_putchar (int c)
+void grub_putchar(int c)
{
- if (c == '\n')
- grub_putchar ('\r');
- else if (c == '\t' && current_term->getxy)
- {
- int n;
-
- n = 8 - ((current_term->getxy () >> 8) & 3);
- while (n--)
- grub_putchar (' ');
-
- return;
- }
-
- if (c == '\n')
- {
- /* Internal `more'-like feature. */
- if (count_lines >= 0)
- {
- count_lines++;
- if (count_lines >= max_lines - 2)
- {
- int tmp;
-
- /* It's important to disable the feature temporarily, because
- the following grub_printf call will print newlines. */
- count_lines = -1;
+ if (c == '\t') {
+ int n;
- if (current_term->setcolorstate)
- current_term->setcolorstate (COLOR_STATE_HIGHLIGHT);
-
- grub_printf ("\n[Hit return to continue]");
+ n = 8 - ((getxy() >> 8) & 3);
+ while (n--)
+ grub_putchar(' ');
- if (current_term->setcolorstate)
- current_term->setcolorstate (COLOR_STATE_NORMAL);
-
- do
- {
- tmp = ASCII_CHAR (getkey ());
+ return;
+ }
+
+ if (c == '\n') {
+ grub_putchar('\r');
+
+ /* Internal `more'-like feature. */
+ if (count_lines >= 0) {
+ count_lines++;
+ if (count_lines >= max_lines - 2) {
+ int tmp;
+
+ /* It's important to disable the feature temporarily, because
+ the following grub_printf call will print newlines. */
+ count_lines = -1;
+
+ console_setcolorstate(COLOR_STATE_HIGHLIGHT);
+
+ grub_printf("\n[Hit return to continue]");
+
+ console_setcolorstate(COLOR_STATE_NORMAL);
+
+ do {
+ tmp = ASCII_CHAR(getkey());
+ }
+ while (tmp != '\n' && tmp != '\r');
+ grub_printf("\r \r");
+
+ /* Restart to count lines. */
+ count_lines = 0;
+ return;
+ }
}
- while (tmp != '\n' && tmp != '\r');
- grub_printf ("\r \r");
-
- /* Restart to count lines. */
- count_lines = 0;
- return;
- }
}
- }
- current_term->putchar (c);
-
+ console_putchar(c);
}
-void
-gotoxy (int x, int y)
+void console_putchar(int c)
{
- current_term->gotoxy (x, y);
+ int x, y;
+ /* displays an ASCII character. IBM displays will translate some
+ characters to special graphical ones */
+
+ /* Curses doesn't have VGA fonts. */
+ switch (c) {
+ case DISP_UL:
+ c = ACS_ULCORNER;
+ break;
+ case DISP_UR:
+ c = ACS_URCORNER;
+ break;
+ case DISP_LL:
+ c = ACS_LLCORNER;
+ break;
+ case DISP_LR:
+ c = ACS_LRCORNER;
+ break;
+ case DISP_HORIZ:
+ c = ACS_HLINE;
+ break;
+ case DISP_VERT:
+ c = ACS_VLINE;
+ break;
+ case DISP_LEFT:
+ c = ACS_LARROW;
+ break;
+ case DISP_RIGHT:
+ c = ACS_RARROW;
+ break;
+ case DISP_UP:
+ c = ACS_UARROW;
+ break;
+ case DISP_DOWN:
+ c = ACS_DARROW;
+ break;
+ default:
+ break;
+ }
+
+ /* In ncurses, a newline is treated badly, so we emulate it in our
+ own way. */
+
+ if (c == '\n') {
+ getyx(stdscr, y, x);
+ if (y + 1 == LINES) {
+ scroll(stdscr);
+ refresh();
+ } else {
+ move(y + 1, x);
+ }
+ } else if (c == '\r') {
+ getyx(stdscr, y, x);
+ move(y, 0);
+ } else if (isprint(c)) {
+ getyx(stdscr, y, x);
+ if (x + 1 == COLS) {
+ console_putchar('\n');
+ }
+ addch(c | console_current_color);
+ } else {
+ addch(c);
+ }
}
-int
-getxy (void)
+void gotoxy(int x, int y)
{
- return current_term->getxy ();
+ move(y, x);
}
-void
-cls (void)
+int getxy(void)
{
- /* If the terminal is dumb, there is no way to clean the terminal. */
- if (current_term->flags & TERM_DUMB)
- grub_putchar ('\n');
- else
- current_term->cls ();
+ unsigned int x, y;
+
+ getyx(stdscr, y, x);
+
+ return (x << 8) | (y & 0xff);
}
-int
-setcursor (int on)
+void cls(void)
{
- if (current_term->setcursor)
- return current_term->setcursor (on);
-
- return 1;
+ clear();
+ move(0, 0);
}
-int
-substring (const char *s1, const char *s2)
+static int cursor_state = 0;
+int setcursor(int on)
{
- while (*s1 == *s2)
- {
- /* The strings match exactly. */
- if (! *(s1++))
- return 0;
- s2 ++;
- }
+ int old = cursor_state;
- /* S1 is a substring of S2. */
- if (*s1 == 0)
- return -1;
+ cursor_state = on;
+ curs_set(on);
- /* S1 isn't a substring. */
- return 1;
+ return old;
}
+int substring(const char *s1, const char *s2)
+{
+ while (*s1 == *s2) {
+ /* The strings match exactly. */
+ if (!*(s1++))
+ return 0;
+ s2++;
+ }
+ /* S1 is a substring of S2. */
+ if (*s1 == 0)
+ return -1;
+ /* S1 isn't a substring. */
+ return 1;
+}
/* Terminate the string STR with NUL. */
-int
-nul_terminate (char *str)
+int nul_terminate(char *str)
{
- int ch;
+ int ch;
- while (*str && ! grub_isspace (*str))
- str++;
+ while (*str && !isspace(*str))
+ str++;
- ch = *str;
- *str = 0;
- return ch;
+ ch = *str;
+ *str = 0;
+ return ch;
}
-
Modified: trunk/filo/main/grub/cmdline.c
===================================================================
--- trunk/filo/main/grub/cmdline.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/cmdline.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -2,6 +2,7 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2004 Free Software Foundation, Inc.
+ * Copyright (C) 2005-2008 coresystems GmbH
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,37 +24,42 @@
#include <grub/shared.h>
/* Find the next word from CMDLINE and return the pointer. If
- AFTER_EQUAL is non-zero, assume that the character `=' is treated as
- a space. Caution: this assumption is for backward compatibility. */
-char *
-skip_to (int after_equal, char *cmdline)
+ * AFTER_EQUAL is non-zero, assume that the character `=' is treated as
+ * a space. Caution: this assumption is for backward compatibility.
+ */
+char *skip_to(int after_equal, char *cmdline)
{
- /* Skip until we hit whitespace, or maybe an equal sign. */
- while (*cmdline && *cmdline != ' ' && *cmdline != '\t' &&
- ! (after_equal && *cmdline == '='))
- cmdline ++;
+ /* Skip until we hit whitespace, or maybe an equal sign. */
+ while (*cmdline && *cmdline != ' ' && *cmdline != '\t' && !(after_equal && *cmdline == '='))
+ cmdline++;
- /* Skip whitespace, and maybe equal signs. */
- while (*cmdline == ' ' || *cmdline == '\t' ||
- (after_equal && *cmdline == '='))
- cmdline ++;
+ /* Skip whitespace, and maybe equal signs. */
+ while (*cmdline == ' ' || *cmdline == '\t' || (after_equal && *cmdline == '='))
+ cmdline++;
- return cmdline;
+ return cmdline;
}
/* Print a helpful message for the command-line interface. */
-void print_cmdline_message (int type)
+void print_cmdline_message(int type)
{
- grub_printf(" [ Minimal BASH-like line editing is supported. For the first word, TAB\n"
- " lists possible command completions. Anywhere else TAB lists the possible\n"
- " completions of a device/filename.");
+#if 0
+ // We don't have file completion (yet?)
+ grub_printf
+ (" [ Minimal BASH-like line editing is supported. For the first word, TAB\n"
+ " lists possible command completions. Anywhere else TAB lists the possible\n"
+ " completions of a device/filename.");
+#else
+ grub_printf
+ (" [ Minimal BASH-like line editing is supported. For the first word, TAB\n"
+ " lists possible command completions.");
+#endif
if (type == CMDLINE_NORMAL_MODE)
grub_printf(" ESC at any time exits.");
if (type == CMDLINE_EDIT_MODE)
- grub_printf(" ESC at any time cancels. ENTER \n"
- " at any time accepts your changes.");
+ grub_printf(" ESC at any time cancels. ENTER \n" " at any time accepts your changes.");
grub_printf("]\n");
@@ -63,200 +69,172 @@
}
/* Find the builtin whose command name is COMMAND and return the
- pointer. If not found, return 0. */
-struct builtin *
-find_command (char *command)
+ * pointer. If not found, return 0.
+ */
+struct builtin *find_command(char *command)
{
- char *ptr;
- char c;
- struct builtin **builtin;
+ char *ptr;
+ char c;
+ struct builtin **builtin;
- /* Find the first space and terminate the command name. */
- ptr = command;
- while (*ptr && *ptr != ' ' && *ptr != '\t' && *ptr != '=')
- ptr ++;
+ /* Find the first space and terminate the command name. */
+ ptr = command;
+ while (*ptr && *ptr != ' ' && *ptr != '\t' && *ptr != '=')
+ ptr++;
- c = *ptr;
- *ptr = 0;
+ c = *ptr;
+ *ptr = 0;
- /* Seek out the builtin whose command name is COMMAND. */
- for (builtin = builtin_table; *builtin != 0; builtin++)
- {
- int ret = grub_strcmp (command, (*builtin)->name);
+ /* Seek out the builtin whose command name is COMMAND. */
+ for (builtin = builtin_table; *builtin != 0; builtin++) {
+ int ret = strcmp(command, (*builtin)->name);
- if (ret == 0)
- {
- /* Find the builtin for COMMAND. */
- *ptr = c;
- return *builtin;
+ if (ret == 0) {
+ /* Find the builtin for COMMAND. */
+ *ptr = c;
+ return *builtin;
+ } else if (ret < 0)
+ break;
}
- else if (ret < 0)
- break;
- }
- /* Cannot find COMMAND. */
- errnum = ERR_UNRECOGNIZED;
- *ptr = c;
- return 0;
+ /* Cannot find COMMAND. */
+ errnum = ERR_UNRECOGNIZED;
+ *ptr = c;
+ return 0;
}
+int keep_cmdline_running;
+
/* Initialize the data for the command-line. */
-static void
-init_cmdline (void)
+static void init_cmdline(void)
{
- /* Initialization. */
- saved_drive = boot_drive;
- saved_partition = install_partition;
- current_drive = GRUB_INVALID_DRIVE;
- errnum = 0;
- count_lines = -1;
-
-#if 0
- /* Restore memory probe state. */
- mbi.mem_upper = saved_mem_upper;
- if (mbi.mmap_length)
- mbi.flags |= MB_INFO_MEM_MAP;
-#endif
-
- /* Initialize the data for the builtin commands. */
- init_builtins ();
+ /* Initialization. */
+ errnum = 0;
+ count_lines = -1;
+
+ keep_cmdline_running = 1;
+
+ /* Initialize the data for the builtin commands. */
+ init_builtins();
}
/* Enter the command-line interface. HEAP is used for the command-line
- buffer. Return only if FOREVER is nonzero and get_cmdline returns
- nonzero (ESC is pushed). */
-void
-enter_cmdline (char *heap, int forever)
+ * buffer. Return only if FOREVER is nonzero and get_cmdline returns
+ * nonzero (ESC is pushed).
+ */
+void enter_cmdline(char *heap, int forever)
{
- /* Initialize the data and print a message. */
- init_cmdline ();
+ /* Initialize the data and print a message. */
+ init_cmdline();
- init_page ();
-
- print_cmdline_message (forever ? CMDLINE_FOREVER_MODE : CMDLINE_NORMAL_MODE );
-
- while (1)
- {
- struct builtin *builtin;
- char *arg;
+ init_page();
- *heap = 0;
- print_error ();
- errnum = ERR_NONE;
+ print_cmdline_message(forever ? CMDLINE_FOREVER_MODE : CMDLINE_NORMAL_MODE);
- /* Get the command-line with the minimal BASH-like interface. */
- if (get_cmdline (CONFIG_PROMPT "> ", heap, 2048, 0, 1))
- return;
+ while (keep_cmdline_running) {
+ struct builtin *builtin;
+ char *arg;
- /* If there was no command, grab a new one. */
- if (! heap[0])
- continue;
+ *heap = 0;
+ print_error();
+ errnum = ERR_NONE;
- /* Find a builtin. */
- builtin = find_command (heap);
- if (! builtin)
- continue;
+ /* Get the command-line with the minimal BASH-like interface. */
+ if (get_cmdline(CONFIG_PROMPT "> ", heap, 2048, 0, 1))
+ return;
- /* If BUILTIN cannot be run in the command-line, skip it. */
- if (! (builtin->flags & BUILTIN_CMDLINE))
- {
- errnum = ERR_UNRECOGNIZED;
- continue;
- }
+ /* If there was no command, grab a new one. */
+ if (!heap[0])
+ continue;
- /* Invalidate the cache, because the user may exchange removable
- disks. */
- buf_drive = -1;
+ /* Find a builtin. */
+ builtin = find_command(heap);
+ if (!builtin)
+ continue;
- /* Start to count lines, only if the internal pager is in use. */
- if (use_pager)
- count_lines = 0;
-
- /* Run BUILTIN->FUNC. */
- arg = skip_to (1, heap);
- (builtin->func) (arg, BUILTIN_CMDLINE);
+ /* If BUILTIN cannot be run in the command-line, skip it. */
+ if (!(builtin->flags & BUILTIN_CMDLINE)) {
+ errnum = ERR_UNRECOGNIZED;
+ continue;
+ }
- /* Finish the line count. */
- count_lines = -1;
- }
+ /* Start to count lines, only if the internal pager is in use. */
+ if (use_pager)
+ count_lines = 0;
+
+ /* Run BUILTIN->FUNC. */
+ arg = skip_to(1, heap);
+ (builtin->func) (arg, BUILTIN_CMDLINE);
+
+ /* Finish the line count. */
+ count_lines = -1;
+ }
}
/* Run an entry from the script SCRIPT. HEAP is used for the
command-line buffer. If an error occurs, return non-zero, otherwise
return zero. */
-int
-run_script (char *script, char *heap)
+int run_script(char *script, char *heap)
{
- char *old_entry;
- char *cur_entry = script;
+ char *old_entry;
+ char *cur_entry = script;
- /* Initialize the data. */
- init_cmdline ();
+ /* Initialize the data. */
+ init_cmdline();
- while (1)
- {
- struct builtin *builtin;
- char *arg;
+ while (1) {
+ struct builtin *builtin;
+ char *arg;
- print_error ();
+ print_error();
- if (errnum)
- {
- errnum = ERR_NONE;
+ if (errnum) {
+ errnum = ERR_NONE;
- /* If a fallback entry is defined, don't prompt a user's
- intervention. */
- if (fallback_entryno < 0)
- {
- grub_printf ("\nPress any key to continue...");
- (void) getkey ();
- }
-
- return 1;
- }
+ /* If a fallback entry is defined, don't prompt a user's
+ intervention. */
+ if (fallback_entryno < 0) {
+ grub_printf("\nPress any key to continue...");
+ (void) getkey();
+ }
- /* Copy the first string in CUR_ENTRY to HEAP. */
- old_entry = cur_entry;
- while (*cur_entry++)
- ;
+ return 1;
+ }
- grub_memmove (heap, old_entry, (int) cur_entry - (int) old_entry);
- if (! *heap)
- {
- /* If there is no more command in SCRIPT... */
+ /* Copy the first string in CUR_ENTRY to HEAP. */
+ old_entry = cur_entry;
+ while (*cur_entry++);
- /* If any kernel is not loaded, just exit successfully. */
- if (kernel_type == KERNEL_TYPE_NONE)
- return 0;
+ memmove(heap, old_entry, (int) cur_entry - (int) old_entry);
+ if (!*heap) {
+ /* If there is no more command in SCRIPT... */
- /* Otherwise, the command boot is run implicitly. */
- grub_memmove (heap, "boot", 5);
- }
+ /* If any kernel is not loaded, just exit successfully. */
+ if (kernel_type == KERNEL_TYPE_NONE)
+ return 0;
- /* Find a builtin. */
- builtin = find_command (heap);
- if (! builtin)
- {
- grub_printf ("%s\n", old_entry);
- continue;
- }
+ /* Otherwise, the command boot is run implicitly. */
+ memmove(heap, "boot", 5);
+ }
- if (! (builtin->flags & BUILTIN_NO_ECHO))
- grub_printf ("%s\n", old_entry);
+ /* Find a builtin. */
+ builtin = find_command(heap);
+ if (!builtin) {
+ grub_printf("%s\n", old_entry);
+ continue;
+ }
- /* If BUILTIN cannot be run in the command-line, skip it. */
- if (! (builtin->flags & BUILTIN_CMDLINE))
- {
- errnum = ERR_UNRECOGNIZED;
- continue;
- }
+ if (!(builtin->flags & BUILTIN_NO_ECHO))
+ grub_printf("%s\n", old_entry);
- /* Invalidate the cache, because the user may exchange removable
- disks. */
- buf_drive = -1;
+ /* If BUILTIN cannot be run in the command-line, skip it. */
+ if (!(builtin->flags & BUILTIN_CMDLINE)) {
+ errnum = ERR_UNRECOGNIZED;
+ continue;
+ }
- /* Run BUILTIN->FUNC. */
- arg = skip_to (1, heap);
- (builtin->func) (arg, BUILTIN_SCRIPT);
- }
+ /* Run BUILTIN->FUNC. */
+ arg = skip_to(1, heap);
+ (builtin->func) (arg, BUILTIN_SCRIPT);
+ }
}
Modified: trunk/filo/main/grub/completions.c
===================================================================
--- trunk/filo/main/grub/completions.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/completions.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -2,6 +2,7 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ * Copyright (C) 2005-2008 coresystems GmbH
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,35 +30,29 @@
/* If DO_COMPLETION is true, just print NAME. Otherwise save the unique
part into UNIQUE_STRING. */
-void
-print_a_completion (char *name)
+void print_a_completion(char *name)
{
- /* If NAME is "." or "..", do not count it. */
- if (grub_strcmp (name, ".") == 0 || grub_strcmp (name, "..") == 0)
- return;
+ /* If NAME is "." or "..", do not count it. */
+ if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
+ return;
- if (do_completion)
- {
- char *buf = unique_string;
+ if (do_completion) {
+ char *buf = unique_string;
- if (! unique)
- while ((*buf++ = *name++))
- ;
- else
- {
- while (*buf && (*buf == *name))
- {
- buf++;
- name++;
- }
- /* mismatch, strip it. */
- *buf = '\0';
- }
- }
- else
- grub_printf (" %s", name);
+ if (!unique)
+ while ((*buf++ = *name++));
+ else {
+ while (*buf && (*buf == *name)) {
+ buf++;
+ name++;
+ }
+ /* mismatch, strip it. */
+ *buf = '\0';
+ }
+ } else
+ grub_printf(" %s", name);
- unique++;
+ unique++;
}
/*
@@ -65,31 +60,31 @@
* any sane combination of the two.
*/
-int print_completions (int is_filename, int is_completion)
+int print_completions(int is_filename, int is_completion)
{
#if CONFIG_EXPERIMENTAL
- char *buf = (char *) COMPLETION_BUF;
- char *ptr = buf;
+ char *buf = (char *) COMPLETION_BUF;
+ char *ptr = buf;
- unique_string = (char *) UNIQUE_BUF;
- *unique_string = 0;
- unique = 0;
- do_completion = is_completion;
+ unique_string = (char *) UNIQUE_BUF;
+ *unique_string = 0;
+ unique = 0;
+ do_completion = is_completion;
- #warning FIXME implement print_completions
- // FIXME: This function is a dummy, returning an error.
- errnum = ERR_BAD_FILENAME;
-
+#warning FIXME implement print_completions
+ // FIXME: This function is a dummy, returning an error.
+ errnum = ERR_BAD_FILENAME;
- print_error ();
- do_completion = 0;
- if (errnum)
- return -1;
- else
- return unique - 1;
+
+ print_error();
+ do_completion = 0;
+ if (errnum)
+ return -1;
+ else
+ return unique - 1;
#else
- errnum = ERR_BAD_FILENAME;
- print_error ();
- return -1;
+ errnum = ERR_BAD_FILENAME;
+ print_error();
+ return -1;
#endif
}
Modified: trunk/filo/main/grub/grub.c
===================================================================
--- trunk/filo/main/grub/grub.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/grub.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,28 +1,44 @@
/*
- * This file is part of FILO.
+ * This file is part of FILO.
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2000,2001,2002,2004,2005 Free Software Foundation, Inc.
+ * Copyright (C) 2005-2008 coresystems GmbH
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <libpayload.h>
#include <config.h>
+#include <grub/shared.h>
+#include <fs.h>
#include <lib.h>
-#include <fs.h>
#include <arch/timer.h>
extern char config_file[];
+char PASSWORD_BUF[PASSWORD_BUFLEN]; /* The buffer for the password. */
+char DEFAULT_FILE_BUF[DEFAULT_FILE_BUFLEN]; /* THe buffer for the filename of "/boot/grub/default". */
+char CMDLINE_BUF[CMDLINE_BUFLEN]; /* The buffer for the command-line. */
+char HISTORY_BUF[HISTORY_BUFLEN]; /* The history buffer for the command-line. */
+char COMPLETION_BUF[COMPLETION_BUFLEN]; /* The buffer for the completion. */
+char UNIQUE_BUF[UNIQUE_BUFLEN]; /* The buffer for the unique string. */
+char KILL_BUF[KILL_BUFLEN]; /* The kill buffer for the command-line. */
+char MENU_BUF[MENU_BUFLEN]; /* The buffer for the menu entries. */
+static char configs[16384];
+
#define ENTER '\r'
#define ESCAPE '\x1b'
@@ -30,87 +46,991 @@
#define CONFIG_MENULST_TIMEOUT 0
#endif
#if !CONFIG_MENULST_TIMEOUT
-#define menulst_delay() 0 /* success */
+#define menulst_delay() 0 /* success */
#endif
#if CONFIG_MENULST_TIMEOUT
static inline int menulst_delay(void)
{
- u64 timeout;
- int sec, tmp;
- char key;
-
- key = 0;
+ u64 timeout;
+ int sec, tmp;
+ char key;
+ key = 0;
+
#ifdef CONFIG_MENULST_FILE
- printf("Press <Enter> for default menu.lst (%s), or <Esc> for prompt... ",
- CONFIG_MENULST_FILE);
+ printf("Press <Enter> for default menu.lst (%s), or <Esc> for prompt... ", CONFIG_MENULST_FILE);
#else
- printf("Press <Enter> for the FILO shell or <ESC> to enter a menu.lst path...");
-#endif
- for (sec = CONFIG_MENULST_TIMEOUT; sec>0 && key==0; sec--) {
- printf("%d", sec);
- timeout = currticks() + TICKS_PER_SEC;
- while (currticks() < timeout) {
- if (havechar()) {
- key = getchar();
- if (key==ENTER || key==ESCAPE)
- break;
- }
+ printf("Press <Enter> for the FILO shell or <ESC> to enter a menu.lst path...");
+#endif
+ for (sec = CONFIG_MENULST_TIMEOUT; sec > 0 && key == 0; sec--) {
+ printf("%d", sec);
+ timeout = currticks() + TICKS_PER_SEC;
+ while (currticks() < timeout) {
+ if (havechar()) {
+ key = getchar();
+ if (key == ENTER || key == ESCAPE)
+ break;
+ }
+ }
+ for (tmp = sec; tmp; tmp /= 10)
+ printf("\b \b");
}
- for (tmp = sec; tmp; tmp /= 10)
- printf("\b \b");
- }
- if (key == 0) {
- printf("timed out\n");
- return 0; /* success */
- } else {
- putchar('\n');
- if (key == ESCAPE)
- return -1; /* canceled */
- else
- return 0; /* default accepted */
- }
+ if (key == 0) {
+ printf("timed out\n");
+ return 0; /* success */
+ } else {
+ putchar('\n');
+ if (key == ESCAPE)
+ return -1; /* canceled */
+ else
+ return 0; /* default accepted */
+ }
}
-#endif /* CONFIG_MENULST_TIMEOUT */
+#endif /* CONFIG_MENULST_TIMEOUT */
void grub_menulst(void)
{
- char line[256];
+ char line[256];
- /* If Escape key is pressed already, skip autoboot */
- if (havechar() && getchar()==ESCAPE)
- return;
+ /* If Escape key is pressed already, skip autoboot */
+ if (havechar() && getchar() == ESCAPE)
+ return;
- if (menulst_delay()==0) {
+ if (menulst_delay() == 0) {
#ifdef CONFIG_MENULST_FILE
- printf("menu: %s\n", CONFIG_MENULST_FILE);
- strcpy(config_file, CONFIG_MENULST_FILE);
+ printf("menu: %s\n", CONFIG_MENULST_FILE);
+ strcpy(config_file, CONFIG_MENULST_FILE);
#endif
- } else {
- /* The above didn't work, ask user */
- while (havechar())
- getchar();
+ } else {
+ /* The above didn't work, ask user */
+ while (havechar())
+ getchar();
#ifdef CONFIG_MENULST_FILE
- strncpy(line, CONFIG_MENULST_FILE, sizeof(line)-1);
- line[sizeof(line)-1] = '\0';
+ strncpy(line, CONFIG_MENULST_FILE, sizeof(line) - 1);
+ line[sizeof(line) - 1] = '\0';
#else
- line[0] = '\0';
+ line[0] = '\0';
#endif
- for (;;) {
- printf("menu: ");
- getline(line, sizeof line);
+ for (;;) {
+ printf("menu: ");
+ getline(line, sizeof line);
- if (strcmp(line,"quit")==0) break;
+ if (strcmp(line, "quit") == 0)
+ break;
- if (line[0]) {
- strcpy(config_file, line);
- break;
- }
- }
- }
+ if (line[0]) {
+ copy_path_to_filo_bootline(line, config_file, 0);
+ break;
+ }
+ }
+ }
-
+
}
+/* Define if there is user specified preset menu string */
+/* #undef PRESET_MENU_STRING */
+
+#if defined(PRESET_MENU_STRING)
+
+static const char *preset_menu = PRESET_MENU_STRING;
+
+static int preset_menu_offset;
+
+static int open_preset_menu(void)
+{
+ preset_menu_offset = 0;
+ return preset_menu != 0;
+}
+
+static int read_from_preset_menu(char *buf, int maxlen)
+{
+ int len = strlen(preset_menu + preset_menu_offset);
+
+ if (len > maxlen)
+ len = maxlen;
+
+ memmove(buf, preset_menu + preset_menu_offset, len);
+ preset_menu_offset += len;
+
+ return len;
+}
+
+static void close_preset_menu(void)
+{
+ /* Disable the preset menu. */
+ preset_menu = 0;
+}
+
+#else /* ! PRESET_MENU_STRING */
+
+#define open_preset_menu() 0
+#define read_from_preset_menu(buf, maxlen) 0
+#define close_preset_menu()
+
+#endif /* ! PRESET_MENU_STRING */
+
+static char *get_entry(char *list, int num, int nested)
+{
+ int i;
+
+ for (i = 0; i < num; i++) {
+ do {
+ while (*(list++));
+ }
+ while (nested && *(list++));
+ }
+
+ return list;
+}
+
+/* Print an entry in a line of the menu box. */
+static void print_entry(int y, int highlight, char *entry)
+{
+ int x;
+
+ console_setcolorstate(COLOR_STATE_NORMAL);
+
+ if (highlight)
+ console_setcolorstate(COLOR_STATE_HIGHLIGHT);
+
+ gotoxy(2, y);
+ grub_putchar(' ');
+ for (x = 3; x < 75; x++) {
+ if (*entry && x <= 72) {
+ if (x == 72)
+ grub_putchar(DISP_RIGHT);
+ else
+ grub_putchar(*entry++);
+ } else
+ grub_putchar(' ');
+ }
+ gotoxy(74, y);
+
+ console_setcolorstate(COLOR_STATE_STANDARD);
+ refresh();
+}
+
+/* Print entries in the menu box. */
+static void print_entries(int y, int size, int first, int entryno, char *menu_entries)
+{
+ int i;
+
+ gotoxy(77, y + 1);
+
+ if (first)
+ grub_putchar(DISP_UP);
+ else
+ grub_putchar(' ');
+
+ menu_entries = get_entry(menu_entries, first, 0);
+
+ for (i = 0; i < size; i++) {
+ print_entry(y + i + 1, entryno == i, menu_entries);
+
+ while (*menu_entries)
+ menu_entries++;
+
+ if (*(menu_entries - 1))
+ menu_entries++;
+ }
+
+ gotoxy(77, y + size);
+
+ if (*menu_entries)
+ grub_putchar(DISP_DOWN);
+ else
+ grub_putchar(' ');
+
+ gotoxy(74, y + entryno + 1);
+ refresh();
+}
+
+static void print_border(int y, int size)
+{
+ int i;
+
+ console_setcolorstate(COLOR_STATE_NORMAL);
+
+ gotoxy(1, y);
+
+ grub_putchar(DISP_UL);
+ for (i = 0; i < 73; i++)
+ grub_putchar(DISP_HORIZ);
+ grub_putchar(DISP_UR);
+
+ i = 1;
+ while (1) {
+ gotoxy(1, y + i);
+
+ if (i > size)
+ break;
+
+ grub_putchar(DISP_VERT);
+ gotoxy(75, y + i);
+ grub_putchar(DISP_VERT);
+
+ i++;
+ }
+
+ grub_putchar(DISP_LL);
+ for (i = 0; i < 73; i++)
+ grub_putchar(DISP_HORIZ);
+ grub_putchar(DISP_LR);
+
+ console_setcolorstate(COLOR_STATE_STANDARD);
+}
+
+static void run_menu(char *menu_entries, char *config_entries, int num_entries, char *heap, int entryno)
+{
+ int c, time1, time2 = -1, first_entry = 0;
+ char *cur_entry = 0;
+
+ /*
+ * Main loop for menu UI.
+ */
+
+ restart:
+ while (entryno > 11) {
+ first_entry++;
+ entryno--;
+ }
+
+ /* If the timeout was expired or wasn't set, force to show the menu
+ interface. */
+ if (grub_timeout < 0)
+ show_menu = 1;
+
+ /* If SHOW_MENU is false, don't display the menu until ESC is pressed. */
+ if (!show_menu) {
+ /* Get current time. */
+ while ((time1 = getrtsecs()) == 0xFF);
+
+ while (1) {
+ /* Check if ESC is pressed. */
+ if (checkkey() != -1 && ASCII_CHAR(getkey()) == '\e') {
+ grub_timeout = -1;
+ show_menu = 1;
+ break;
+ }
+
+ /* If GRUB_TIMEOUT is expired, boot the default entry. */
+ if (grub_timeout >= 0 && (time1 = getrtsecs()) != time2 && time1 != 0xFF) {
+ if (grub_timeout <= 0) {
+ grub_timeout = -1;
+ goto boot_entry;
+ }
+
+ time2 = time1;
+ grub_timeout--;
+
+ /* Print a message. */
+ grub_printf("\rPress `ESC' to enter the menu... %d ", grub_timeout);
+ }
+ }
+ }
+
+ /* Only display the menu if the user wants to see it. */
+ if (show_menu) {
+ init_page();
+ setcursor(0);
+
+ print_border(3, 12);
+
+ grub_printf("\n\
+ Use the %c and %c keys to select which entry is highlighted.\n", DISP_UP, DISP_DOWN);
+
+ if (!auth && password) {
+ grub_printf("\
+ Press enter to boot the selected OS or \'p\' to enter a\n\
+ password to unlock the next set of features.");
+ } else {
+ if (config_entries)
+ grub_printf("\
+ Press enter to boot the selected OS, \'e\' to edit the\n\
+ commands before booting, \'a\' to modify the kernel arguments\n\
+ before booting, or \'c\' for a command-line.");
+ else
+ grub_printf("\
+ Press \'b\' to boot, \'e\' to edit the selected command in the\n\
+ boot sequence, \'c\' for a command-line, \'o\' to open a new line\n\
+ after (\'O\' for before) the selected line, \'d\' to remove the\n\
+ selected line, or escape to go back to the main menu.");
+ }
+
+ print_entries(3, 12, first_entry, entryno, menu_entries);
+ }
+
+ /* XXX using RT clock now, need to initialize value */
+ while ((time1 = getrtsecs()) == 0xFF);
+
+ while (1) {
+ /* Initialize to NULL just in case... */
+ cur_entry = NULL;
+
+ if (grub_timeout >= 0 && (time1 = getrtsecs()) != time2 && time1 != 0xFF) {
+ if (grub_timeout <= 0) {
+ grub_timeout = -1;
+ break;
+ }
+
+ /* else not booting yet! */
+ time2 = time1;
+
+ gotoxy(3, 22);
+ grub_printf("The highlighted entry will be booted automatically in %d seconds. ",
+ grub_timeout);
+ gotoxy(74, 4 + entryno);
+
+ grub_timeout--;
+ }
+
+ /* Check for a keypress, however if TIMEOUT has been expired
+ (GRUB_TIMEOUT == -1) relax in GETKEY even if no key has been
+ pressed.
+ This avoids polling (relevant in the grub-shell and later on
+ in grub if interrupt driven I/O is done). */
+ if (checkkey() >= 0 || grub_timeout < 0) {
+ /* Key was pressed, show which entry is selected before GETKEY,
+ since we're comming in here also on GRUB_TIMEOUT == -1 and
+ hang in GETKEY */
+
+ c = ASCII_CHAR(getkey());
+
+ if (grub_timeout >= 0) {
+ gotoxy(3, 22);
+ grub_printf(" ");
+ grub_timeout = -1;
+ fallback_entryno = -1;
+ gotoxy(74, 4 + entryno);
+ }
+
+ /* On serial console, arrow keys might not work,
+ * therefore accept '^' and 'v' as replacement keys.
+ */
+ if (c == 16 || c == '^') {
+ if (entryno > 0) {
+ print_entry(4 + entryno, 0,
+ get_entry(menu_entries, first_entry + entryno, 0));
+ entryno--;
+ print_entry(4 + entryno, 1,
+ get_entry(menu_entries, first_entry + entryno, 0));
+ } else if (first_entry > 0) {
+ first_entry--;
+ print_entries(3, 12, first_entry, entryno, menu_entries);
+ }
+ } else if ((c == 14 || c == 'v')
+ && first_entry + entryno + 1 < num_entries) {
+ if (entryno < 11) {
+ print_entry(4 + entryno, 0,
+ get_entry(menu_entries, first_entry + entryno, 0));
+ entryno++;
+ print_entry(4 + entryno, 1,
+ get_entry(menu_entries, first_entry + entryno, 0));
+ } else if (num_entries > 12 + first_entry) {
+ first_entry++;
+ print_entries(3, 12, first_entry, entryno, menu_entries);
+ }
+ } else if (c == 7) {
+ /* Page Up */
+ first_entry -= 12;
+ if (first_entry < 0) {
+ entryno += first_entry;
+ first_entry = 0;
+ if (entryno < 0)
+ entryno = 0;
+ }
+ print_entries(3, 12, first_entry, entryno, menu_entries);
+ } else if (c == 3) {
+ /* Page Down */
+ first_entry += 12;
+ if (first_entry + entryno + 1 >= num_entries) {
+ first_entry = num_entries - 12;
+ if (first_entry < 0)
+ first_entry = 0;
+ entryno = num_entries - first_entry - 1;
+ }
+ print_entries(3, 12, first_entry, entryno, menu_entries);
+ }
+
+ if (config_entries) {
+ if ((c == '\n') || (c == '\r') || (c == 6))
+ break;
+ } else {
+ if ((c == 'd') || (c == 'o') || (c == 'O')) {
+ print_entry(4 + entryno, 0,
+ get_entry(menu_entries, first_entry + entryno, 0));
+
+ /* insert after is almost exactly like insert before */
+ if (c == 'o') {
+ /* But `o' differs from `O', since it may causes
+ the menu screen to scroll up. */
+ if (entryno < 11)
+ entryno++;
+ else
+ first_entry++;
+
+ c = 'O';
+ }
+
+ cur_entry = get_entry(menu_entries, first_entry + entryno, 0);
+
+ if (c == 'O') {
+ memmove(cur_entry + 2, cur_entry, ((int) heap) - ((int)cur_entry));
+
+ cur_entry[0] = ' ';
+ cur_entry[1] = 0;
+
+ heap += 2;
+
+ num_entries++;
+ } else if (num_entries > 0) {
+ char *ptr = get_entry(menu_entries,
+ first_entry + entryno + 1,
+ 0);
+
+ memmove(cur_entry, ptr, ((int) heap) - ((int) ptr));
+ heap -= (((int) ptr) - ((int) cur_entry));
+
+ num_entries--;
+
+ if (entryno >= num_entries)
+ entryno--;
+ if (first_entry && num_entries < 12 + first_entry)
+ first_entry--;
+ }
+
+ print_entries(3, 12, first_entry, entryno, menu_entries);
+ }
+
+ cur_entry = menu_entries;
+ if (c == 27)
+ return;
+ if (c == 'b')
+ break;
+ }
+
+ if (!auth && password) {
+ if (c == 'p') {
+ /* Do password check here! */
+ char entered[32];
+ char *pptr = password;
+
+ gotoxy(1, 21);
+
+ /* Wipe out the previously entered password */
+ memset(entered, 0, sizeof(entered));
+ get_cmdline(" Password: ", entered, 31, '*', 0);
+
+ while (!isspace(*pptr) && *pptr)
+ pptr++;
+
+ /* Make sure that PASSWORD is NUL-terminated. */
+ *pptr++ = 0;
+
+ if (!check_password(entered, password, password_type)) {
+ char *new_file = config_file;
+ while (isspace(*pptr))
+ pptr++;
+
+ /* If *PPTR is NUL, then allow the user to use
+ privileged instructions, otherwise, load
+ another configuration file. */
+ if (*pptr != 0) {
+ while ((*(new_file++)
+ = *(pptr++))
+ != 0);
+
+ /* Make sure that the user will not have
+ authority in the next configuration. */
+ auth = 0;
+ return;
+ } else {
+ /* Now the user is superhuman. */
+ auth = 1;
+ goto restart;
+ }
+ } else {
+ grub_printf("Failed!\n Press any key to continue...");
+ getkey();
+ goto restart;
+ }
+ }
+ } else {
+ if (c == 'e') {
+ int new_num_entries = 0, i = 0;
+ char *new_heap;
+
+ if (config_entries) {
+ new_heap = heap;
+ cur_entry = get_entry(config_entries, first_entry + entryno, 1);
+ } else {
+ /* safe area! */
+ new_heap = heap + NEW_HEAPSIZE + 1;
+ cur_entry = get_entry(menu_entries, first_entry + entryno, 0);
+ }
+
+ do {
+ while ((*(new_heap++) = cur_entry[i++]) != 0);
+ new_num_entries++;
+ }
+ while (config_entries && cur_entry[i]);
+
+ /* this only needs to be done if config_entries is non-NULL,
+ but it doesn't hurt to do it always */
+ *(new_heap++) = 0;
+
+ if (config_entries)
+ run_menu(heap, NULL, new_num_entries, new_heap, 0);
+ else {
+ cls();
+ print_cmdline_message(CMDLINE_EDIT_MODE);
+
+ new_heap = heap + NEW_HEAPSIZE + 1;
+
+ if (!get_cmdline
+ (CONFIG_PROMPT " edit> ", new_heap, NEW_HEAPSIZE + 1, 0, 1)) {
+ int j = 0;
+
+ /* get length of new command */
+ while (new_heap[j++]);
+
+ if (j < 2) {
+ j = 2;
+ new_heap[0]
+ = ' ';
+ new_heap[1]
+ = 0;
+ }
+
+ /* align rest of commands properly */
+ memmove(cur_entry + j, cur_entry + i, (int) heap - ((int) cur_entry + i));
+
+ /* copy command to correct area */
+ memmove(cur_entry, new_heap, j);
+
+ heap += (j - i);
+ }
+ }
+
+ goto restart;
+ }
+ if (c == 'c') {
+ extern int keep_cmdline_running;
+ enter_cmdline(heap, 0);
+ if (keep_cmdline_running)
+ goto restart;
+ else
+ return;
+ }
+ if (config_entries && c == 'a') {
+ int new_num_entries = 0, i = 0, j;
+ int needs_padding, amount;
+ char *new_heap;
+ char *entries;
+ char *entry_copy;
+ char *append_line;
+ char *start;
+
+ entry_copy = new_heap = heap;
+ cur_entry = get_entry(config_entries, first_entry + entryno, 1);
+
+ do {
+ while ((*(new_heap++) = cur_entry[i++]) != 0);
+ new_num_entries++;
+ }
+ while (config_entries && cur_entry[i]);
+
+ /* this only needs to be done if config_entries is non-NULL,
+ but it doesn't hurt to do it always */
+ *(new_heap++) = 0;
+
+ new_heap = heap + NEW_HEAPSIZE + 1;
+
+ entries = entry_copy;
+ while (*entries) {
+ if ((strstr(entries, "kernel") == entries)
+ && isspace(entries[6]))
+ break;
+
+ while (*entries)
+ entries++;
+ entries++;
+ }
+
+ if (!*entries)
+ goto restart;
+
+ start = entries + 6;
+
+ /* skip the white space */
+ while (*start && isspace(*start))
+ start++;
+ /* skip the kernel name */
+ while (*start && !isspace(*start))
+ start++;
+
+ /* skip the white space */
+ needs_padding = (!*start || !isspace(*start));
+ while (*start && isspace(*start))
+ start++;
+
+ append_line = new_heap;
+ strcpy(append_line, start);
+
+ cls();
+ print_cmdline_message(CMDLINE_EDIT_MODE);
+
+ if (get_cmdline(CONFIG_PROMPT " append> ", append_line, NEW_HEAPSIZE + 1, 0, 1))
+ goto restart;
+
+ /* have new args; append_line points to the
+ new args and start points to the old
+ args */
+
+ i = strlen(start);
+ j = strlen(append_line);
+
+ if (i > (j + needs_padding))
+ amount = i;
+ else
+ amount = j + needs_padding;
+
+ /* align rest of commands properly */
+ memmove(start + j + needs_padding,
+ start + i, ((int) append_line) - ((int) start) - (amount));
+
+ if (needs_padding)
+ *start = ' ';
+
+ /* copy command to correct area */
+ memmove(start + needs_padding, append_line, j);
+
+ /* set up this entry to boot */
+ config_entries = NULL;
+ cur_entry = entry_copy;
+ heap = new_heap;
+
+ break;
+ }
+ }
+ }
+ }
+
+ /* Attempt to boot an entry. */
+
+ boot_entry:
+
+ cls();
+ setcursor(1);
+
+ while (1) {
+ if (config_entries)
+ grub_printf(" Booting \'%s\'\n\n", get_entry(menu_entries, first_entry + entryno, 0));
+ else
+ grub_printf(" Booting command-list\n\n");
+
+ if (!cur_entry)
+ cur_entry = get_entry(config_entries, first_entry + entryno, 1);
+
+ /* Set CURRENT_ENTRYNO for the command "savedefault". */
+ current_entryno = first_entry + entryno;
+ if (run_script(cur_entry, heap)) {
+ if (fallback_entryno >= 0) {
+ cur_entry = NULL;
+ first_entry = 0;
+ entryno = fallback_entries[fallback_entryno];
+ fallback_entryno++;
+ if (fallback_entryno >= MAX_FALLBACK_ENTRIES || fallback_entries[fallback_entryno] < 0)
+ fallback_entryno = -1;
+ } else
+ break;
+ } else
+ break;
+ }
+
+ for (;;);
+ show_menu = 1;
+ goto restart;
+}
+
+
+static int get_line_from_config(char *cmdline, int maxlen, int read_from_file)
+{
+ int pos = 0, literal = 0, comment = 0;
+ char c; /* since we're loading it a byte at a time! */
+
+ while (1) {
+ if (read_from_file) {
+ if (!file_read(&c, 1))
+ break;
+ } else {
+ if (!read_from_preset_menu(&c, 1))
+ break;
+ }
+
+ /* Skip all carriage returns. */
+ if (c == '\r')
+ continue;
+
+ /* Replace tabs with spaces. */
+ if (c == '\t')
+ c = ' ';
+
+ /* The previous is a backslash, then... */
+ if (literal) {
+ /* If it is a newline, replace it with a space and continue. */
+ if (c == '\n') {
+ c = ' ';
+
+ /* Go back to overwrite a backslash. */
+ if (pos > 0)
+ pos--;
+ }
+
+ literal = 0;
+ }
+
+ /* translate characters first! */
+ if (c == '\\' && !literal)
+ literal = 1;
+
+ if (comment) {
+ if (c == '\n')
+ comment = 0;
+ } else if (!pos) {
+ if (c == '#')
+ comment = 1;
+ else if ((c != ' ') && (c != '\n'))
+ cmdline[pos++] = c;
+ } else {
+ if (c == '\n')
+ break;
+
+ if (pos < maxlen)
+ cmdline[pos++] = c;
+ }
+ }
+
+ cmdline[pos] = 0;
+
+ return pos;
+}
+
+int is_opened = 0, is_preset = 0;
+
+/* This is the starting function in C. */
+void grub_main(void)
+{
+ int config_len, menu_len, num_entries;
+ char *config_entries, *menu_entries;
+ char *kill_buf = (char *) KILL_BUF;
+
+ auto void reset(void);
+ void reset(void) {
+ count_lines = -1;
+ config_len = 0;
+ menu_len = 0;
+ num_entries = 0;
+ config_entries = (char *) configs;
+ memset(configs, 0, 16384);
+ menu_entries = MENU_BUF;
+ memset(MENU_BUF, 0, MENU_BUFLEN);
+ init_config();
+ }
+
+ /* Initialize TinyCurses */
+ initscr();
+ cbreak();
+ noecho();
+ nonl();
+ scrollok(stdscr, TRUE);
+ keypad(stdscr, TRUE);
+ wtimeout(stdscr, 100);
+ endwin();
+
+ /* Initialize the kill buffer. */
+ *kill_buf = 0;
+
+ /* Never return. */
+ for (;;) {
+ char *default_file = (char *) DEFAULT_FILE_BUF;
+ int i;
+
+ reset();
+
+ /* Here load the configuration file. */
+
+ /* Get a saved default entry if possible. */
+ saved_entryno = 0;
+ *default_file = 0;
+
+ strncat(default_file, config_file, DEFAULT_FILE_BUFLEN);
+ for (i = strlen(default_file); i >= 0; i--)
+ if (default_file[i] == '/') {
+ i++;
+ break;
+ }
+ default_file[i] = 0;
+ strncat(default_file + i, "default", DEFAULT_FILE_BUFLEN - i);
+ if (file_open(default_file)) {
+ char buf[10]; /* This is good enough. */
+ char *p = buf;
+ int len;
+
+ len = file_read(buf, sizeof(buf));
+ if (len > 0) {
+ buf[sizeof(buf) - 1] = 0;
+ safe_parse_maxint(&p, &saved_entryno);
+ }
+
+ file_close();
+ }
+
+ errnum = ERR_NONE;
+
+ do {
+ /* STATE 0: Before any title command.
+ STATE 1: In a title command.
+ STATE >1: In a entry after a title command. */
+ int state = 0, prev_config_len = 0, prev_menu_len = 0;
+ char *cmdline;
+
+ /* Try the preset menu first. This will succeed at most once,
+ because close_preset_menu disables the preset menu. */
+ is_opened = is_preset = open_preset_menu();
+ if (!is_opened) {
+ is_opened = file_open(config_file);
+ errnum = ERR_NONE;
+ }
+
+ if (!is_opened) {
+ grub_printf("Could not open menu.lst file '%s'. Entering command line.\n", config_file);
+ // memset(myheap, 0, 256);
+ // run_script("terminal console\n\0", myheap);
+ break;
+ }
+
+ /* This is necessary, because the menu must be overrided. */
+ reset();
+
+ cmdline = (char *) CMDLINE_BUF;
+ while (get_line_from_config(cmdline, NEW_HEAPSIZE, !is_preset)) {
+ struct builtin *builtin;
+
+ /* Get the pointer to the builtin structure. */
+ builtin = find_command(cmdline);
+ errnum = 0;
+ if (!builtin)
+ /* Unknown command. Just skip now. */
+ continue;
+
+ if (builtin->flags & BUILTIN_TITLE) {
+ char *ptr;
+
+ /* the command "title" is specially treated. */
+ if (state > 1) {
+ /* The next title is found. */
+ num_entries++;
+ config_entries[config_len++]
+ = 0;
+ prev_menu_len = menu_len;
+ prev_config_len = config_len;
+ } else {
+ /* The first title is found. */
+ menu_len = prev_menu_len;
+ config_len = prev_config_len;
+ }
+
+ /* Reset the state. */
+ state = 1;
+
+ /* Copy title into menu area. */
+ ptr = skip_to(1, cmdline);
+ while ((menu_entries[menu_len++] = *(ptr++)) != 0);
+ } else if (!state) {
+ /* Run a command found is possible. */
+ if (builtin->flags & BUILTIN_MENU) {
+ char *arg = skip_to(1,
+ cmdline);
+ (builtin->func) (arg, BUILTIN_MENU);
+ errnum = 0;
+ } else
+ /* Ignored. */
+ continue;
+ } else {
+ char *ptr = cmdline;
+
+ state++;
+ /* Copy config file data to config area. */
+ while ((config_entries[config_len++] = *ptr++) != 0);
+ }
+ }
+
+ if (state > 1) {
+ /* Finish the last entry. */
+ num_entries++;
+ config_entries[config_len++] = 0;
+ } else {
+ menu_len = prev_menu_len;
+ config_len = prev_config_len;
+ }
+
+ menu_entries[menu_len++] = 0;
+ config_entries[config_len++] = 0;
+ memmove(config_entries + config_len, menu_entries, menu_len);
+ menu_entries = config_entries + config_len;
+
+ /* Make sure that all fallback entries are valid. */
+ if (fallback_entryno >= 0) {
+ for (i = 0; i < MAX_FALLBACK_ENTRIES; i++) {
+ if (fallback_entries[i] < 0)
+ break;
+ if (fallback_entries[i] >= num_entries) {
+ memmove (fallback_entries + i,
+ fallback_entries + i + 1, ((MAX_FALLBACK_ENTRIES - i - 1)
+ * sizeof(int)));
+ i--;
+ }
+ }
+
+ if (fallback_entries[0] < 0)
+ fallback_entryno = -1;
+ }
+
+ /* Check if the default entry is present. Otherwise reset
+ * it to fallback if fallback is valid, or to DEFAULT_ENTRY
+ * if not.
+ */
+ if (default_entry >= num_entries) {
+ if (fallback_entryno >= 0) {
+ default_entry = fallback_entries[0];
+ fallback_entryno++;
+ if (fallback_entryno >= MAX_FALLBACK_ENTRIES ||
+ fallback_entries[fallback_entryno] < 0)
+ fallback_entryno = -1;
+ } else {
+ default_entry = 0;
+ }
+ }
+
+ if (is_preset)
+ close_preset_menu();
+ else
+ file_close();
+
+ } while (is_preset);
+
+ if (!num_entries) {
+ /* If no acceptable config file, goto command-line, starting
+ heap from where the config entries would have been stored
+ if there were any. */
+ enter_cmdline(config_entries, 1);
+ } else {
+ /* Run menu interface. */
+ run_menu(menu_entries, config_entries, num_entries, menu_entries + menu_len, default_entry);
+ }
+ }
+}
Deleted: trunk/filo/main/grub/grubcons.c
===================================================================
--- trunk/filo/main/grub/grubcons.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/grubcons.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,105 +0,0 @@
-/* term_console.c - console input and output */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2002 Free Software Foundation, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <libpayload.h>
-#include <config.h>
-
-#if (CONFIG_VGA_CONSOLE == 1) && (CONFIG_PC_KEYBOARD == 1)
-
-#include <grub/shared.h>
-#include <grub/term.h>
-
-static int console_current_color = A_NORMAL;
-static int console_standard_color = A_NORMAL;
-static int console_normal_color = A_NORMAL;
-static int console_highlight_color = A_REVERSE;
-static color_state console_color_state = COLOR_STATE_STANDARD;
-
-void console_setcolorstate (color_state state)
-{
- switch (state) {
- case COLOR_STATE_STANDARD:
- console_current_color = console_standard_color;
- break;
- case COLOR_STATE_NORMAL:
- console_current_color = console_normal_color;
- break;
- case COLOR_STATE_HIGHLIGHT:
- console_current_color = console_highlight_color;
- break;
- default:
- console_current_color = console_standard_color;
- break;
- }
-
- console_color_state = state;
-}
-
-void console_setcolor (int normal_color, int highlight_color)
-{
- console_normal_color = normal_color;
- console_highlight_color = highlight_color;
-
- console_setcolorstate (console_color_state);
-}
-
-int console_checkkey (void)
-{
- if(keyboard_havechar())
- return 0;
- return -1;
-}
-
-int console_getkey (void)
-{
- return keyboard_getchar();
-}
-
-int console_getxy (void)
-{
- unsigned int x, y, en;
- video_console_get_cursor(&x, &y, &en);
- return (x<<8)|(y);
-}
-
-void console_gotoxy (int x, int y)
-{
- video_console_set_cursor(x, y);
-}
-
-void console_cls (void)
-{
- video_console_clear();
-}
-
-int console_setcursor (int on)
-{
- video_console_cursor_enable(on);
- return 0;
-}
-
-void console_putchar (int c)
-{
- c|=(console_current_color<<8);
- video_console_putchar(c);
-}
-
-#endif
-
Modified: trunk/filo/main/grub/md5.c
===================================================================
--- trunk/filo/main/grub/md5.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/md5.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -56,148 +56,146 @@
*/
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x >> (32 - (n)))))
-static UINT4 initstate[4] =
-{
- 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476
+static UINT4 initstate[4] = {
+ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476
};
-static char s1[4] = { 7, 12, 17, 22 };
-static char s2[4] = { 5, 9, 14, 20 };
-static char s3[4] = { 4, 11, 16, 23 };
-static char s4[4] = { 6, 10, 15, 21 };
+static char s1[4] = { 7, 12, 17, 22 };
+static char s2[4] = { 5, 9, 14, 20 };
+static char s3[4] = { 4, 11, 16, 23 };
+static char s4[4] = { 6, 10, 15, 21 };
-static UINT4 T[64] =
-{
- 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
- 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
- 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
- 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
- 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
- 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
- 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
- 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
- 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
- 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
- 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
- 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
- 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
- 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
- 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
- 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
+static UINT4 T[64] = {
+ 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
+ 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
+ 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
+ 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
+ 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
+ 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
+ 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
+ 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
+ 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
+ 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
+ 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
+ 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
+ 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
+ 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
+ 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
+ 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
};
-static const char *b64t =
-"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+static const char *b64t = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
static UINT4 state[4];
static unsigned int length;
static unsigned char buffer[64];
-static void
-md5_transform (const unsigned char block[64])
+static void md5_transform(const unsigned char block[64])
{
- int i, j;
- UINT4 a,b,c,d,tmp;
- const UINT4 *x = (UINT4 *) block;
+ int i, j;
+ UINT4 a, b, c, d, tmp;
+ const UINT4 *x = (UINT4 *) block;
- a = state[0];
- b = state[1];
- c = state[2];
- d = state[3];
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
- /* Round 1 */
- for (i = 0; i < 16; i++)
- {
- tmp = a + F (b, c, d) + le32_to_cpu (x[i]) + T[i];
- tmp = ROTATE_LEFT (tmp, s1[i & 3]);
- tmp += b;
- a = d; d = c; c = b; b = tmp;
- }
- /* Round 2 */
- for (i = 0, j = 1; i < 16; i++, j += 5)
- {
- tmp = a + G (b, c, d) + le32_to_cpu (x[j & 15]) + T[i+16];
- tmp = ROTATE_LEFT (tmp, s2[i & 3]);
- tmp += b;
- a = d; d = c; c = b; b = tmp;
- }
- /* Round 3 */
- for (i = 0, j = 5; i < 16; i++, j += 3)
- {
- tmp = a + H (b, c, d) + le32_to_cpu (x[j & 15]) + T[i+32];
- tmp = ROTATE_LEFT (tmp, s3[i & 3]);
- tmp += b;
- a = d; d = c; c = b; b = tmp;
- }
- /* Round 4 */
- for (i = 0, j = 0; i < 16; i++, j += 7)
- {
- tmp = a + I (b, c, d) + le32_to_cpu (x[j & 15]) + T[i+48];
- tmp = ROTATE_LEFT (tmp, s4[i & 3]);
- tmp += b;
- a = d; d = c; c = b; b = tmp;
- }
+ /* Round 1 */
+ for (i = 0; i < 16; i++) {
+ tmp = a + F(b, c, d) + le32_to_cpu(x[i]) + T[i];
+ tmp = ROTATE_LEFT(tmp, s1[i & 3]);
+ tmp += b;
+ a = d;
+ d = c;
+ c = b;
+ b = tmp;
+ }
+ /* Round 2 */
+ for (i = 0, j = 1; i < 16; i++, j += 5) {
+ tmp = a + G(b, c, d) + le32_to_cpu(x[j & 15]) + T[i + 16];
+ tmp = ROTATE_LEFT(tmp, s2[i & 3]);
+ tmp += b;
+ a = d;
+ d = c;
+ c = b;
+ b = tmp;
+ }
+ /* Round 3 */
+ for (i = 0, j = 5; i < 16; i++, j += 3) {
+ tmp = a + H(b, c, d) + le32_to_cpu(x[j & 15]) + T[i + 32];
+ tmp = ROTATE_LEFT(tmp, s3[i & 3]);
+ tmp += b;
+ a = d;
+ d = c;
+ c = b;
+ b = tmp;
+ }
+ /* Round 4 */
+ for (i = 0, j = 0; i < 16; i++, j += 7) {
+ tmp = a + I(b, c, d) + le32_to_cpu(x[j & 15]) + T[i + 48];
+ tmp = ROTATE_LEFT(tmp, s4[i & 3]);
+ tmp += b;
+ a = d;
+ d = c;
+ c = b;
+ b = tmp;
+ }
- state[0] += a;
- state[1] += b;
- state[2] += c;
- state[3] += d;
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
}
-static void
-md5_init(void)
+static void md5_init(void)
{
- memcpy ((char *) state, (char *) initstate, sizeof (initstate));
- length = 0;
+ memcpy((char *) state, (char *) initstate, sizeof(initstate));
+ length = 0;
}
-static void
-md5_update (const char *input, int inputlen)
+static void md5_update(const char *input, int inputlen)
{
- int buflen = length & 63;
- length += inputlen;
- if (buflen + inputlen < 64)
- {
- memcpy (buffer + buflen, input, inputlen);
- buflen += inputlen;
- return;
- }
-
- memcpy (buffer + buflen, input, 64 - buflen);
- md5_transform (buffer);
- input += 64 - buflen;
- inputlen -= 64 - buflen;
- while (inputlen >= 64)
- {
- md5_transform ((const unsigned char *)input);
- input += 64;
- inputlen -= 64;
- }
- memcpy (buffer, input, inputlen);
- buflen = inputlen;
+ int buflen = length & 63;
+ length += inputlen;
+ if (buflen + inputlen < 64) {
+ memcpy(buffer + buflen, input, inputlen);
+ buflen += inputlen;
+ return;
+ }
+
+ memcpy(buffer + buflen, input, 64 - buflen);
+ md5_transform(buffer);
+ input += 64 - buflen;
+ inputlen -= 64 - buflen;
+ while (inputlen >= 64) {
+ md5_transform((const unsigned char *) input);
+ input += 64;
+ inputlen -= 64;
+ }
+ memcpy(buffer, input, inputlen);
+ buflen = inputlen;
}
-static unsigned char *
-md5_final()
+static unsigned char *md5_final()
{
- int i, buflen = length & 63;
+ int i, buflen = length & 63;
- buffer[buflen++] = 0x80;
- memset (buffer+buflen, 0, 64 - buflen);
- if (buflen > 56)
- {
- md5_transform (buffer);
- memset (buffer, 0, 64);
- buflen = 0;
- }
-
- *(UINT4 *) (buffer + 56) = cpu_to_le32 (8 * length);
- *(UINT4 *) (buffer + 60) = 0;
- md5_transform (buffer);
+ buffer[buflen++] = 0x80;
+ memset(buffer + buflen, 0, 64 - buflen);
+ if (buflen > 56) {
+ md5_transform(buffer);
+ memset(buffer, 0, 64);
+ buflen = 0;
+ }
- for (i = 0; i < 4; i++)
- state[i] = cpu_to_le32 (state[i]);
- return (unsigned char *) state;
+ *(UINT4 *) (buffer + 56) = cpu_to_le32(8 * length);
+ *(UINT4 *) (buffer + 60) = 0;
+ md5_transform(buffer);
+
+ for (i = 0; i < 4; i++)
+ state[i] = cpu_to_le32(state[i]);
+ return (unsigned char *) state;
}
#ifdef CONFIG_USE_MD5_PASSWORDS
@@ -206,180 +204,156 @@
to strcmp.
If CHECK is false, crypt KEY and save the result in CRYPTED.
CRYPTED must have a salt. */
-int
-md5_password (const char *key, char *crypted, int check)
+int md5_password(const char *key, char *crypted, int check)
{
- int keylen = strlen (key);
- char *salt = crypted + 3; /* skip $1$ header */
- char *p;
- int saltlen;
- int i, n;
- char alt_result[16];
- unsigned char *digest;
+ int keylen = strlen(key);
+ char *salt = crypted + 3; /* skip $1$ header */
+ char *p;
+ int saltlen;
+ int i, n;
+ char alt_result[16];
+ unsigned char *digest;
- if (check)
- {
- /* If our crypted password isn't 3 chars, then it can't be md5
- crypted. So, they don't match. */
- if (strlen(crypted) <= 3)
- return 1;
-
- saltlen = strstr (salt, "$") - salt;
- }
- else
- {
- char *end = strstr (salt, "$");
- if (end && end - salt < 8)
- saltlen = end - salt;
- else
- saltlen = 8;
+ if (check) {
+ /* If our crypted password isn't 3 chars, then it can't be md5
+ crypted. So, they don't match. */
+ if (strlen(crypted) <= 3)
+ return 1;
- salt[saltlen] = '$';
- }
-
- md5_init ();
- md5_update (key, keylen);
- md5_update (salt, saltlen);
- md5_update (key, keylen);
- digest = md5_final ();
- memcpy (alt_result, digest, 16);
-
- memcpy ((char *) state, (char *) initstate, sizeof (initstate));
- length = 0;
- md5_update (key, keylen);
- md5_update (crypted, 3 + saltlen); /* include the $1$ header */
- for (i = keylen; i > 16; i -= 16)
- md5_update (alt_result, 16);
- md5_update (alt_result, i);
+ saltlen = strstr(salt, "$") - salt;
+ } else {
+ char *end = strstr(salt, "$");
+ if (end && end - salt < 8)
+ saltlen = end - salt;
+ else
+ saltlen = 8;
- for (i = keylen; i > 0; i >>= 1)
- md5_update (key + ((i & 1) ? keylen : 0), 1);
- digest = md5_final ();
+ salt[saltlen] = '$';
+ }
- for (i = 0; i < 1000; i++)
- {
- memcpy (alt_result, digest, 16);
+ md5_init();
+ md5_update(key, keylen);
+ md5_update(salt, saltlen);
+ md5_update(key, keylen);
+ digest = md5_final();
+ memcpy(alt_result, digest, 16);
- memcpy ((char *) state, (char *) initstate, sizeof (initstate));
- length = 0;
- if ((i & 1) != 0)
- md5_update (key, keylen);
- else
- md5_update (alt_result, 16);
-
- if (i % 3 != 0)
- md5_update (salt, saltlen);
+ memcpy((char *) state, (char *) initstate, sizeof(initstate));
+ length = 0;
+ md5_update(key, keylen);
+ md5_update(crypted, 3 + saltlen); /* include the $1$ header */
+ for (i = keylen; i > 16; i -= 16)
+ md5_update(alt_result, 16);
+ md5_update(alt_result, i);
- if (i % 7 != 0)
- md5_update (key, keylen);
+ for (i = keylen; i > 0; i >>= 1)
+ md5_update(key + ((i & 1) ? keylen : 0), 1);
+ digest = md5_final();
- if ((i & 1) != 0)
- md5_update (alt_result, 16);
- else
- md5_update (key, keylen);
- digest = md5_final ();
- }
+ for (i = 0; i < 1000; i++) {
+ memcpy(alt_result, digest, 16);
- p = salt + saltlen + 1;
- for (i = 0; i < 5; i++)
- {
- unsigned int w =
- digest[i == 4 ? 5 : 12+i] | (digest[6+i] << 8) | (digest[i] << 16);
- for (n = 4; n-- > 0;)
+ memcpy((char *) state, (char *) initstate, sizeof(initstate));
+ length = 0;
+ if ((i & 1) != 0)
+ md5_update(key, keylen);
+ else
+ md5_update(alt_result, 16);
+
+ if (i % 3 != 0)
+ md5_update(salt, saltlen);
+
+ if (i % 7 != 0)
+ md5_update(key, keylen);
+
+ if ((i & 1) != 0)
+ md5_update(alt_result, 16);
+ else
+ md5_update(key, keylen);
+ digest = md5_final();
+ }
+
+ p = salt + saltlen + 1;
+ for (i = 0; i < 5; i++) {
+ unsigned int w = digest[i == 4 ? 5 : 12 + i] | (digest[6 + i] << 8) | (digest[i]
+ << 16);
+ for (n = 4; n-- > 0;) {
+ if (check) {
+ if (*p++ != b64t[w & 0x3f])
+ return 1;
+ } else {
+ *p++ = b64t[w & 0x3f];
+ }
+
+ w >>= 6;
+ }
+ }
{
- if (check)
- {
- if (*p++ != b64t[w & 0x3f])
- return 1;
- }
- else
- {
- *p++ = b64t[w & 0x3f];
- }
-
- w >>= 6;
+ unsigned int w = digest[11];
+ for (n = 2; n-- > 0;) {
+ if (check) {
+ if (*p++ != b64t[w & 0x3f])
+ return 1;
+ } else {
+ *p++ = b64t[w & 0x3f];
+ }
+
+ w >>= 6;
+ }
}
- }
- {
- unsigned int w = digest[11];
- for (n = 2; n-- > 0;)
- {
- if (check)
- {
- if (*p++ != b64t[w & 0x3f])
- return 1;
- }
- else
- {
- *p++ = b64t[w & 0x3f];
- }
-
- w >>= 6;
- }
- }
- if (! check)
- *p = '\0';
-
- return *p;
+ if (!check)
+ *p = '\0';
+
+ return *p;
}
#endif
#ifdef TEST
-static char *
-md5 (const char *input)
+static char *md5(const char *input)
{
- memcpy ((char *) state, (char *) initstate, sizeof (initstate));
- length = 0;
- md5_update (input, strlen (input));
- return md5_final ();
+ memcpy((char *) state, (char *) initstate, sizeof(initstate));
+ length = 0;
+ md5_update(input, strlen(input));
+ return md5_final();
}
-static void
-test (char *buffer, char *expected)
+static void test(char *buffer, char *expected)
{
- char result[16 * 3 +1];
- unsigned char* digest = md5 (buffer);
- int i;
+ char result[16 * 3 + 1];
+ unsigned char *digest = md5(buffer);
+ int i;
- for (i=0; i < 16; i++)
- sprintf (result+2*i, "%02x", digest[i]);
+ for (i = 0; i < 16; i++)
+ sprintf(result + 2 * i, "%02x", digest[i]);
- if (strcmp (result, expected))
- printf ("MD5(%s) failed: %s\n", buffer, result);
- else
- printf ("MD5(%s) OK\n", buffer);
+ if (strcmp(result, expected))
+ printf("MD5(%s) failed: %s\n", buffer, result);
+ else
+ printf("MD5(%s) OK\n", buffer);
}
-int
-main (void)
+int main(void)
{
- test ("", "d41d8cd98f00b204e9800998ecf8427e");
- test ("a", "0cc175b9c0f1b6a831c399e269772661");
- test ("abc", "900150983cd24fb0d6963f7d28e17f72");
- test ("message digest", "f96b697d7cb7938d525a2f31aaf161d0");
- test ("abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b");
- test ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- "d174ab98d277d9f5a5611c2c9f419d9f");
- test ("12345678901234567890123456789012345678901234567890123456789012345678901234567890",
- "57edf4a22be3c955ac49da2e2107b67a");
- test ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz3456",
- "6831fa90115bb9a54fbcd4f9fee0b5c4");
- test ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz345",
- "bc40505cc94a43b7ff3e2ac027325233");
- test ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz34567",
- "fa94b73a6f072a0239b52acacfbcf9fa");
- test ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz345678901234",
- "bd201eae17f29568927414fa326f1267");
- test ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz34567890123",
- "80063db1e6b70a2e91eac903f0e46b85");
+ test("", "d41d8cd98f00b204e9800998ecf8427e");
+ test("a", "0cc175b9c0f1b6a831c399e269772661");
+ test("abc", "900150983cd24fb0d6963f7d28e17f72");
+ test("message digest", "f96b697d7cb7938d525a2f31aaf161d0");
+ test("abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b");
+ test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "d174ab98d277d9f5a5611c2c9f419d9f");
+ test("12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+ "57edf4a22be3c955ac49da2e2107b67a");
+ test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz3456", "6831fa90115bb9a54fbcd4f9fee0b5c4");
+ test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz345", "bc40505cc94a43b7ff3e2ac027325233");
+ test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz34567", "fa94b73a6f072a0239b52acacfbcf9fa");
+ test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz345678901234", "bd201eae17f29568927414fa326f1267");
+ test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz34567890123", "80063db1e6b70a2e91eac903f0e46b85");
- if (check_md5_password ("Hello world!",
- "$1$saltstri$YMyguxXMBpd2TEZ.vS/3q1"))
- printf ("Password differs\n");
- else
- printf ("Password OK\n");
- return 0;
+ if (check_md5_password("Hello world!", "$1$saltstri$YMyguxXMBpd2TEZ.vS/3q1"))
+ printf("Password differs\n");
+ else
+ printf("Password OK\n");
+ return 0;
}
#endif
Deleted: trunk/filo/main/grub/serial.c
===================================================================
--- trunk/filo/main/grub/serial.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/serial.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,341 +0,0 @@
-/* serial.c - serial device interface */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <libpayload.h>
-#include <config.h>
-#include <grub/shared.h>
-#include <grub/term.h>
-#include <grub/terminfo.h>
-
-/* An input buffer. */
-static char input_buf[8];
-static int npending = 0;
-
-static int serial_x;
-static int serial_y;
-
-static int keep_track = 1;
-
-/* Fetch a key. */
-int
-serial_hw_fetch (void)
-{
-#if CONFIG_SERIAL_CONSOLE
- if(serial_havechar())
- return serial_getchar();
-#endif
- return -1;
-}
-
-/* Put a chararacter. */
-void
-serial_hw_put (int c)
-{
-#if CONFIG_SERIAL_CONSOLE
- serial_putchar(c);
-#endif
-}
-
-/* Return the port number for the UNITth serial device. */
-unsigned short
-serial_hw_get_port (int unit)
-{
-#if CONFIG_SERIAL_CONSOLE
- return CONFIG_SERIAL_IOBASE;
-#else
- return 0;
-#endif
-}
-
-/* Initialize a serial device. PORT is the port number for a serial device.
- SPEED is a DTE-DTE speed which must be one of these: 2400, 4800, 9600,
- 19200, 38400, 57600 and 115200. WORD_LEN is the word length to be used
- for the device. Likewise, PARITY is the type of the parity and
- STOP_BIT_LEN is the length of the stop bit. The possible values for
- WORD_LEN, PARITY and STOP_BIT_LEN are defined in the header file as
- macros. */
-int
-serial_hw_init (unsigned short port, unsigned int speed,
- int word_len, int parity, int stop_bit_len)
-{
-#if CONFIG_CONSOLE_SERIAL
- int i;
- /* Drain the input buffer. */
- while (serial_checkkey () != -1) {
- (void) serial_getkey ();
- }
-
- /* Get rid of TERM_NEED_INIT from the serial terminal. */
- for (i = 0; term_table[i].name; i++)
- if (grub_strcmp (term_table[i].name, "serial") == 0)
- {
- term_table[i].flags &= ~TERM_NEED_INIT;
- break;
- }
-#endif
- return 1;
-}
-
-/* Generic definitions. */
-
-#if CONFIG_SERIAL_CONSOLE
-static void
-serial_translate_key_sequence (void)
-{
- const struct
- {
- char key;
- char ascii;
- }
- three_code_table[] =
- {
- {'A', 16},
- {'B', 14},
- {'C', 6},
- {'D', 2},
- {'F', 5},
- {'H', 1},
- {'4', 4}
- };
-
- const struct
- {
- short key;
- char ascii;
- }
- four_code_table[] =
- {
- {('1' | ('~' << 8)), 1},
- {('3' | ('~' << 8)), 4},
- {('5' | ('~' << 8)), 7},
- {('6' | ('~' << 8)), 3},
- };
-
- /* The buffer must start with ``ESC [''. */
- if (*((unsigned short *) input_buf) != ('\e' | ('[' << 8)))
- return;
-
- if (npending >= 3)
- {
- int i;
-
- for (i = 0;
- i < sizeof (three_code_table) / sizeof (three_code_table[0]);
- i++)
- if (three_code_table[i].key == input_buf[2])
- {
- input_buf[0] = three_code_table[i].ascii;
- npending -= 2;
- memmove (input_buf + 1, input_buf + 3, npending - 1);
- return;
- }
- }
-
- if (npending >= 4)
- {
- int i;
- short key = *((short *) (input_buf + 2));
-
- for (i = 0;
- i < sizeof (four_code_table) / sizeof (four_code_table[0]);
- i++)
- if (four_code_table[i].key == key)
- {
- input_buf[0] = four_code_table[i].ascii;
- npending -= 3;
- memmove (input_buf + 1, input_buf + 4, npending - 1);
- return;
- }
- }
-}
-
-static
-int fill_input_buf (int nowait)
-{
- int i;
-
- for (i = 0; i < 10000 && npending < sizeof (input_buf); i++)
- {
- int c;
-
- c = serial_hw_fetch ();
- if (c >= 0)
- {
- input_buf[npending++] = c;
-
- /* Reset the counter to zero, to wait for the same interval. */
- i = 0;
- }
-
- if (nowait)
- break;
- }
-
- /* Translate some key sequences. */
- serial_translate_key_sequence ();
-
- return npending;
-}
-#endif
-
-/* The serial version of getkey. */
-int
-serial_getkey (void)
-{
- int c;
-#if CONFIG_SERIAL_CONSOLE
- while (! fill_input_buf (0))
- ;
-#endif
-
- c = input_buf[0];
- npending--;
- memmove (input_buf, input_buf + 1, npending);
-
- return c;
-}
-
-/* The serial version of checkkey. */
-int
-serial_checkkey (void)
-{
-#if CONFIG_SERIAL_CONSOLE
- if (fill_input_buf (1))
- return input_buf[0];
-#endif
-
- return -1;
-}
-
-/* The serial version of grub_putchar. */
-void
-grub_serial_putchar (int c)
-{
- /* Keep track of the cursor. */
- if (keep_track)
- {
- /* The serial terminal doesn't have VGA fonts. */
- switch (c)
- {
- case DISP_UL:
- c = ACS_ULCORNER;
- break;
- case DISP_UR:
- c = ACS_URCORNER;
- break;
- case DISP_LL:
- c = ACS_LLCORNER;
- break;
- case DISP_LR:
- c = ACS_LRCORNER;
- break;
- case DISP_HORIZ:
- c = ACS_HLINE;
- break;
- case DISP_VERT:
- c = ACS_VLINE;
- break;
- case DISP_LEFT:
- c = ACS_LARROW;
- break;
- case DISP_RIGHT:
- c = ACS_RARROW;
- break;
- case DISP_UP:
- c = ACS_UARROW;
- break;
- case DISP_DOWN:
- c = ACS_DARROW;
- break;
- default:
- break;
- }
-
- switch (c)
- {
- case '\r':
- serial_x = 0;
- break;
-
- case '\n':
- serial_y++;
- break;
-
- case '\b':
- case 127:
- if (serial_x > 0)
- serial_x--;
- break;
-
- case '\a':
- break;
-
- default:
- if (serial_x >= 79)
- {
- grub_serial_putchar ('\r');
- grub_serial_putchar ('\n');
- }
- serial_x++;
- break;
- }
- }
-
- serial_hw_put (c);
-}
-
-int
-serial_getxy (void)
-{
- return (serial_x << 8) | serial_y;
-}
-
-void
-serial_gotoxy (int x, int y)
-{
- keep_track = 0;
- ti_cursor_address (x, y);
- keep_track = 1;
-
- serial_x = x;
- serial_y = y;
-}
-
-void
-serial_cls (void)
-{
- keep_track = 0;
- ti_clear_screen ();
- keep_track = 1;
-
- serial_x = serial_y = 0;
-}
-
-void
-serial_setcolorstate (color_state state)
-{
- keep_track = 0;
- if (state == COLOR_STATE_HIGHLIGHT)
- ti_enter_standout_mode ();
- else
- ti_exit_standout_mode ();
- keep_track = 1;
-}
-
Deleted: trunk/filo/main/grub/stage2.c
===================================================================
--- trunk/filo/main/grub/stage2.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/stage2.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,1172 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2000,2001,2002,2004,2005 Free Software Foundation, Inc.
- * Copyright (C) 2005-2008 coresystems GmbH
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <libpayload.h>
-#include <config.h>
-#include <grub/shared.h>
-#include <grub/term.h>
-#include <fs.h>
-
-/* Define if there is user specified preset menu string */
-/* #undef PRESET_MENU_STRING */
-
-void grub_menulst(void);
-
-struct multiboot_info mbi;
-
-#if defined(PRESET_MENU_STRING)
-
-static const char *preset_menu = PRESET_MENU_STRING;
-
-static int preset_menu_offset;
-
-static int
-open_preset_menu (void)
-{
- preset_menu_offset = 0;
- return preset_menu != 0;
-}
-
-static int
-read_from_preset_menu (char *buf, int maxlen)
-{
- int len = grub_strlen (preset_menu + preset_menu_offset);
-
- if (len > maxlen)
- len = maxlen;
-
- grub_memmove (buf, preset_menu + preset_menu_offset, len);
- preset_menu_offset += len;
-
- return len;
-}
-
-static void
-close_preset_menu (void)
-{
- /* Disable the preset menu. */
- preset_menu = 0;
-}
-
-#else /* ! PRESET_MENU_STRING */
-
-#define open_preset_menu() 0
-#define read_from_preset_menu(buf, maxlen) 0
-#define close_preset_menu()
-
-#endif /* ! PRESET_MENU_STRING */
-
-static char *
-get_entry (char *list, int num, int nested)
-{
- int i;
-
- for (i = 0; i < num; i++)
- {
- do
- {
- while (*(list++));
- }
- while (nested && *(list++));
- }
-
- return list;
-}
-
-/* Print an entry in a line of the menu box. */
-static void
-print_entry (int y, int highlight, char *entry)
-{
- int x;
-
- if (current_term->setcolorstate)
- current_term->setcolorstate (COLOR_STATE_NORMAL);
-
- if (highlight && current_term->setcolorstate)
- current_term->setcolorstate (COLOR_STATE_HIGHLIGHT);
-
- gotoxy (2, y);
- grub_putchar (' ');
- for (x = 3; x < 75; x++)
- {
- if (*entry && x <= 72)
- {
- if (x == 72)
- grub_putchar (DISP_RIGHT);
- else
- grub_putchar (*entry++);
- }
- else
- grub_putchar (' ');
- }
- gotoxy (74, y);
-
- if (current_term->setcolorstate)
- current_term->setcolorstate (COLOR_STATE_STANDARD);
-}
-
-/* Print entries in the menu box. */
-static void
-print_entries (int y, int size, int first, int entryno, char *menu_entries)
-{
- int i;
-
- gotoxy (77, y + 1);
-
- if (first)
- grub_putchar (DISP_UP);
- else
- grub_putchar (' ');
-
- menu_entries = get_entry (menu_entries, first, 0);
-
- for (i = 0; i < size; i++)
- {
- print_entry (y + i + 1, entryno == i, menu_entries);
-
- while (*menu_entries)
- menu_entries++;
-
- if (*(menu_entries - 1))
- menu_entries++;
- }
-
- gotoxy (77, y + size);
-
- if (*menu_entries)
- grub_putchar (DISP_DOWN);
- else
- grub_putchar (' ');
-
- gotoxy (74, y + entryno + 1);
-}
-
-static void
-print_entries_raw (int size, int first, char *menu_entries)
-{
- int i;
-
-#define LINE_LENGTH 67
-
- for (i = 0; i < LINE_LENGTH; i++)
- grub_putchar ('-');
- grub_putchar ('\n');
-
- for (i = first; i < size; i++)
- {
- /* grub's printf can't %02d so ... */
- if (i < 10)
- grub_putchar (' ');
- grub_printf ("%d: %s\n", i, get_entry (menu_entries, i, 0));
- }
-
- for (i = 0; i < LINE_LENGTH; i++)
- grub_putchar ('-');
- grub_putchar ('\n');
-
-#undef LINE_LENGTH
-}
-
-
-static void
-print_border (int y, int size)
-{
- int i;
-
- if (current_term->setcolorstate)
- current_term->setcolorstate (COLOR_STATE_NORMAL);
-
- gotoxy (1, y);
-
- grub_putchar (DISP_UL);
- for (i = 0; i < 73; i++)
- grub_putchar (DISP_HORIZ);
- grub_putchar (DISP_UR);
-
- i = 1;
- while (1)
- {
- gotoxy (1, y + i);
-
- if (i > size)
- break;
-
- grub_putchar (DISP_VERT);
- gotoxy (75, y + i);
- grub_putchar (DISP_VERT);
-
- i++;
- }
-
- grub_putchar (DISP_LL);
- for (i = 0; i < 73; i++)
- grub_putchar (DISP_HORIZ);
- grub_putchar (DISP_LR);
-
- if (current_term->setcolorstate)
- current_term->setcolorstate (COLOR_STATE_STANDARD);
-}
-
-static void
-run_menu (char *menu_entries, char *config_entries, int num_entries,
- char *heap, int entryno)
-{
- int c, time1, time2 = -1, first_entry = 0;
- char *cur_entry = 0;
-
- /*
- * Main loop for menu UI.
- */
-
-restart:
- /* Dumb terminal always use all entries for display
- invariant for TERM_DUMB: first_entry == 0 */
- if (! (current_term->flags & TERM_DUMB))
- {
- while (entryno > 11)
- {
- first_entry++;
- entryno--;
- }
- }
-
- /* If the timeout was expired or wasn't set, force to show the menu
- interface. */
- if (grub_timeout < 0)
- show_menu = 1;
-
- /* If SHOW_MENU is false, don't display the menu until ESC is pressed. */
- if (! show_menu)
- {
- /* Get current time. */
- while ((time1 = getrtsecs ()) == 0xFF)
- ;
-
- while (1)
- {
- /* Check if ESC is pressed. */
- if (checkkey () != -1 && ASCII_CHAR (getkey ()) == '\e')
- {
- grub_timeout = -1;
- show_menu = 1;
- break;
- }
-
- /* If GRUB_TIMEOUT is expired, boot the default entry. */
- if (grub_timeout >=0
- && (time1 = getrtsecs ()) != time2
- && time1 != 0xFF)
- {
- if (grub_timeout <= 0)
- {
- grub_timeout = -1;
- goto boot_entry;
- }
-
- time2 = time1;
- grub_timeout--;
-
- /* Print a message. */
- grub_printf ("\rPress `ESC' to enter the menu... %d ",
- grub_timeout);
- }
- }
- }
-
- /* Only display the menu if the user wants to see it. */
- if (show_menu)
- {
- init_page ();
- setcursor (0);
-
- if (current_term->flags & TERM_DUMB)
- print_entries_raw (num_entries, first_entry, menu_entries);
- else
- print_border (3, 12);
-
- grub_printf ("\n\
- Use the %c and %c keys to select which entry is highlighted.\n",
- DISP_UP, DISP_DOWN);
-
- if (! auth && password)
- {
- grub_printf ("\
- Press enter to boot the selected OS or \'p\' to enter a\n\
- password to unlock the next set of features.");
- }
- else
- {
- if (config_entries)
- grub_printf ("\
- Press enter to boot the selected OS, \'e\' to edit the\n\
- commands before booting, \'a\' to modify the kernel arguments\n\
- before booting, or \'c\' for a command-line.");
- else
- grub_printf ("\
- Press \'b\' to boot, \'e\' to edit the selected command in the\n\
- boot sequence, \'c\' for a command-line, \'o\' to open a new line\n\
- after (\'O\' for before) the selected line, \'d\' to remove the\n\
- selected line, or escape to go back to the main menu.");
- }
-
- if (current_term->flags & TERM_DUMB)
- grub_printf ("\n\nThe selected entry is %d ", entryno);
- else
- print_entries (3, 12, first_entry, entryno, menu_entries);
- }
-
- /* XX using RT clock now, need to initialize value */
- while ((time1 = getrtsecs()) == 0xFF);
-
- while (1)
- {
- /* Initialize to NULL just in case... */
- cur_entry = NULL;
-
- if (grub_timeout >= 0 && (time1 = getrtsecs()) != time2 && time1 != 0xFF)
- {
- if (grub_timeout <= 0)
- {
- grub_timeout = -1;
- break;
- }
-
- /* else not booting yet! */
- time2 = time1;
-
- if (current_term->flags & TERM_DUMB)
- grub_printf ("\r Entry %d will be booted automatically in %d seconds. ",
- entryno, grub_timeout);
- else
- {
- gotoxy (3, 22);
- grub_printf ("The highlighted entry will be booted automatically in %d seconds. ",
- grub_timeout);
- gotoxy (74, 4 + entryno);
- }
-
- grub_timeout--;
- }
-
- /* Check for a keypress, however if TIMEOUT has been expired
- (GRUB_TIMEOUT == -1) relax in GETKEY even if no key has been
- pressed.
- This avoids polling (relevant in the grub-shell and later on
- in grub if interrupt driven I/O is done). */
- if (checkkey () >= 0 || grub_timeout < 0)
- {
- /* Key was pressed, show which entry is selected before GETKEY,
- since we're comming in here also on GRUB_TIMEOUT == -1 and
- hang in GETKEY */
- if (current_term->flags & TERM_DUMB)
- grub_printf ("\r Highlighted entry is %d: ", entryno);
-
- c = ASCII_CHAR (getkey ());
-
- if (grub_timeout >= 0)
- {
- if (current_term->flags & TERM_DUMB)
- grub_putchar ('\r');
- else
- gotoxy (3, 22);
- grub_printf (" ");
- grub_timeout = -1;
- fallback_entryno = -1;
- if (! (current_term->flags & TERM_DUMB))
- gotoxy (74, 4 + entryno);
- }
-
- /* We told them above (at least in SUPPORT_SERIAL) to use
- '^' or 'v' so accept these keys. */
- if (c == 16 || c == '^')
- {
- if (current_term->flags & TERM_DUMB)
- {
- if (entryno > 0)
- entryno--;
- }
- else
- {
- if (entryno > 0)
- {
- print_entry (4 + entryno, 0,
- get_entry (menu_entries,
- first_entry + entryno,
- 0));
- entryno--;
- print_entry (4 + entryno, 1,
- get_entry (menu_entries,
- first_entry + entryno,
- 0));
- }
- else if (first_entry > 0)
- {
- first_entry--;
- print_entries (3, 12, first_entry, entryno,
- menu_entries);
- }
- }
- }
- else if ((c == 14 || c == 'v')
- && first_entry + entryno + 1 < num_entries)
- {
- if (current_term->flags & TERM_DUMB)
- entryno++;
- else
- {
- if (entryno < 11)
- {
- print_entry (4 + entryno, 0,
- get_entry (menu_entries,
- first_entry + entryno,
- 0));
- entryno++;
- print_entry (4 + entryno, 1,
- get_entry (menu_entries,
- first_entry + entryno,
- 0));
- }
- else if (num_entries > 12 + first_entry)
- {
- first_entry++;
- print_entries (3, 12, first_entry, entryno, menu_entries);
- }
- }
- }
- else if (c == 7)
- {
- /* Page Up */
- first_entry -= 12;
- if (first_entry < 0)
- {
- entryno += first_entry;
- first_entry = 0;
- if (entryno < 0)
- entryno = 0;
- }
- print_entries (3, 12, first_entry, entryno, menu_entries);
- }
- else if (c == 3)
- {
- /* Page Down */
- first_entry += 12;
- if (first_entry + entryno + 1 >= num_entries)
- {
- first_entry = num_entries - 12;
- if (first_entry < 0)
- first_entry = 0;
- entryno = num_entries - first_entry - 1;
- }
- print_entries (3, 12, first_entry, entryno, menu_entries);
- }
-
- if (config_entries)
- {
- if ((c == '\n') || (c == '\r') || (c == 6))
- break;
- }
- else
- {
- if ((c == 'd') || (c == 'o') || (c == 'O'))
- {
- if (! (current_term->flags & TERM_DUMB))
- print_entry (4 + entryno, 0,
- get_entry (menu_entries,
- first_entry + entryno,
- 0));
-
- /* insert after is almost exactly like insert before */
- if (c == 'o')
- {
- /* But `o' differs from `O', since it may causes
- the menu screen to scroll up. */
- if (entryno < 11 || (current_term->flags & TERM_DUMB))
- entryno++;
- else
- first_entry++;
-
- c = 'O';
- }
-
- cur_entry = get_entry (menu_entries,
- first_entry + entryno,
- 0);
-
- if (c == 'O')
- {
- grub_memmove (cur_entry + 2, cur_entry,
- ((int) heap) - ((int) cur_entry));
-
- cur_entry[0] = ' ';
- cur_entry[1] = 0;
-
- heap += 2;
-
- num_entries++;
- }
- else if (num_entries > 0)
- {
- char *ptr = get_entry(menu_entries,
- first_entry + entryno + 1,
- 0);
-
- grub_memmove (cur_entry, ptr,
- ((int) heap) - ((int) ptr));
- heap -= (((int) ptr) - ((int) cur_entry));
-
- num_entries--;
-
- if (entryno >= num_entries)
- entryno--;
- if (first_entry && num_entries < 12 + first_entry)
- first_entry--;
- }
-
- if (current_term->flags & TERM_DUMB)
- {
- grub_printf ("\n\n");
- print_entries_raw (num_entries, first_entry,
- menu_entries);
- grub_printf ("\n");
- }
- else
- print_entries (3, 12, first_entry, entryno, menu_entries);
- }
-
- cur_entry = menu_entries;
- if (c == 27)
- return;
- if (c == 'b')
- break;
- }
-
- if (! auth && password)
- {
- if (c == 'p')
- {
- /* Do password check here! */
- char entered[32];
- char *pptr = password;
-
- if (current_term->flags & TERM_DUMB)
- grub_printf ("\r ");
- else
- gotoxy (1, 21);
-
- /* Wipe out the previously entered password */
- grub_memset (entered, 0, sizeof (entered));
- get_cmdline (" Password: ", entered, 31, '*', 0);
-
- while (! isspace (*pptr) && *pptr)
- pptr++;
-
- /* Make sure that PASSWORD is NUL-terminated. */
- *pptr++ = 0;
-
- if (! check_password (entered, password, password_type))
- {
- char *new_file = config_file;
- while (isspace (*pptr))
- pptr++;
-
- /* If *PPTR is NUL, then allow the user to use
- privileged instructions, otherwise, load
- another configuration file. */
- if (*pptr != 0)
- {
- while ((*(new_file++) = *(pptr++)) != 0)
- ;
-
- /* Make sure that the user will not have
- authority in the next configuration. */
- auth = 0;
- return;
- }
- else
- {
- /* Now the user is superhuman. */
- auth = 1;
- goto restart;
- }
- }
- else
- {
- grub_printf ("Failed!\n Press any key to continue...");
- getkey ();
- goto restart;
- }
- }
- }
- else
- {
- if (c == 'e')
- {
- int new_num_entries = 0, i = 0;
- char *new_heap;
-
- if (config_entries)
- {
- new_heap = heap;
- cur_entry = get_entry (config_entries,
- first_entry + entryno,
- 1);
- }
- else
- {
- /* safe area! */
- new_heap = heap + NEW_HEAPSIZE + 1;
- cur_entry = get_entry (menu_entries,
- first_entry + entryno,
- 0);
- }
-
- do
- {
- while ((*(new_heap++) = cur_entry[i++]) != 0);
- new_num_entries++;
- }
- while (config_entries && cur_entry[i]);
-
- /* this only needs to be done if config_entries is non-NULL,
- but it doesn't hurt to do it always */
- *(new_heap++) = 0;
-
- if (config_entries)
- run_menu (heap, NULL, new_num_entries, new_heap, 0);
- else
- {
- cls ();
- print_cmdline_message (CMDLINE_EDIT_MODE);
-
- new_heap = heap + NEW_HEAPSIZE + 1;
-
- saved_drive = boot_drive;
- saved_partition = install_partition;
- current_drive = GRUB_INVALID_DRIVE;
-
- if (! get_cmdline (CONFIG_PROMPT " edit> ", new_heap,
- NEW_HEAPSIZE + 1, 0, 1))
- {
- int j = 0;
-
- /* get length of new command */
- while (new_heap[j++])
- ;
-
- if (j < 2)
- {
- j = 2;
- new_heap[0] = ' ';
- new_heap[1] = 0;
- }
-
- /* align rest of commands properly */
- grub_memmove (cur_entry + j, cur_entry + i,
- (int) heap - ((int) cur_entry + i));
-
- /* copy command to correct area */
- grub_memmove (cur_entry, new_heap, j);
-
- heap += (j - i);
- }
- }
-
- goto restart;
- }
- if (c == 'c')
- {
- enter_cmdline (heap, 0);
- goto restart;
- }
- if (config_entries && c == 'a')
- {
- int new_num_entries = 0, i = 0, j;
- int needs_padding, amount;
- char *new_heap;
- char * entries;
- char * entry_copy;
- char * append_line;
- char * start;
-
- entry_copy = new_heap = heap;
- cur_entry = get_entry (config_entries, first_entry + entryno,
- 1);
-
- do
- {
- while ((*(new_heap++) = cur_entry[i++]) != 0);
- new_num_entries++;
- }
- while (config_entries && cur_entry[i]);
-
- /* this only needs to be done if config_entries is non-NULL,
- but it doesn't hurt to do it always */
- *(new_heap++) = 0;
-
- new_heap = heap + NEW_HEAPSIZE + 1;
-
- entries = entry_copy;
- while (*entries)
- {
- if ((strstr(entries, "kernel") == entries) &&
- isspace(entries[6]))
- break;
-
- while (*entries) entries++;
- entries++;
- }
-
- if (!*entries)
- goto restart;
-
- start = entries + 6;
-
- /* skip the white space */
- while (*start && isspace(*start)) start++;
- /* skip the kernel name */
- while (*start && !isspace(*start)) start++;
-
- /* skip the white space */
- needs_padding = (!*start || !isspace(*start));
- while (*start && isspace(*start)) start++;
-
- append_line = new_heap;
- grub_strcpy(append_line, start);
-
- cls();
- print_cmdline_message (CMDLINE_EDIT_MODE);
-
- if (get_cmdline(CONFIG_PROMPT " append> ",
- append_line, NEW_HEAPSIZE + 1,
- 0, 1))
- goto restart;
-
- /* have new args; append_line points to the
- new args and start points to the old
- args */
-
- i = grub_strlen(start);
- j = grub_strlen(append_line);
-
- if (i > (j + needs_padding))
- amount = i;
- else
- amount = j + needs_padding;
-
- /* align rest of commands properly */
- memmove (start + j + needs_padding, start + i,
- ((int) append_line) - ((int) start) - (amount));
-
- if (needs_padding)
- *start = ' ';
-
- /* copy command to correct area */
- memmove (start + needs_padding, append_line, j);
-
- /* set up this entry to boot */
- config_entries = NULL;
- cur_entry = entry_copy;
- heap = new_heap;
-
- break;
- }
- }
- }
- }
-
- /* Attempt to boot an entry. */
-
- boot_entry:
-
- cls ();
- setcursor (1);
-
- while (1)
- {
- if (config_entries)
- grub_printf (" Booting \'%s\'\n\n",
- get_entry (menu_entries, first_entry + entryno, 0));
- else
- grub_printf (" Booting command-list\n\n");
-
- if (! cur_entry)
- cur_entry = get_entry (config_entries, first_entry + entryno, 1);
-
- /* Set CURRENT_ENTRYNO for the command "savedefault". */
- current_entryno = first_entry + entryno;
- if (run_script (cur_entry, heap))
- {
- if (fallback_entryno >= 0)
- {
- cur_entry = NULL;
- first_entry = 0;
- entryno = fallback_entries[fallback_entryno];
- fallback_entryno++;
- if (fallback_entryno >= MAX_FALLBACK_ENTRIES
- || fallback_entries[fallback_entryno] < 0)
- fallback_entryno = -1;
- }
- else
- break;
- }
- else
- break;
- }
-
- for(;;) ;
- show_menu = 1;
- goto restart;
-}
-
-
-static int
-get_line_from_config (char *cmdline, int maxlen, int read_from_file)
-{
- int pos = 0, literal = 0, comment = 0;
- char c; /* since we're loading it a byte at a time! */
-
- while (1)
- {
- if (read_from_file)
- {
- if (! grub_read (&c, 1))
- break;
- }
- else
- {
- if (! read_from_preset_menu (&c, 1))
- break;
- }
-
- /* Skip all carriage returns. */
- if (c == '\r')
- continue;
-
- /* Replace tabs with spaces. */
- if (c == '\t')
- c = ' ';
-
- /* The previous is a backslash, then... */
- if (literal)
- {
- /* If it is a newline, replace it with a space and continue. */
- if (c == '\n')
- {
- c = ' ';
-
- /* Go back to overwrite a backslash. */
- if (pos > 0)
- pos--;
- }
-
- literal = 0;
- }
-
- /* translate characters first! */
- if (c == '\\' && ! literal)
- literal = 1;
-
- if (comment)
- {
- if (c == '\n')
- comment = 0;
- }
- else if (! pos)
- {
- if (c == '#')
- comment = 1;
- else if ((c != ' ') && (c != '\n'))
- cmdline[pos++] = c;
- }
- else
- {
- if (c == '\n')
- break;
-
- if (pos < maxlen)
- cmdline[pos++] = c;
- }
- }
-
- cmdline[pos] = 0;
-
- return pos;
-}
-
-static char configs[16384];
-
-/* This is the starting function in C. */
-void
-grub_main (void)
-{
- int config_len, menu_len, num_entries;
- char *config_entries, *menu_entries;
- char *kill_buf = (char *) KILL_BUF;
- char myheap[256];
-
- auto void reset (void);
- void reset (void)
- {
- count_lines = -1;
- config_len = 0;
- menu_len = 0;
- num_entries = 0;
- config_entries = (char *)configs;// (char *) mbi.drives_addr + mbi.drives_length;
- menu_entries = (char *) MENU_BUF;
- init_config ();
- }
-
- /* Initialize the kill buffer. */
- *kill_buf = 0;
-
-#ifdef CONFIG_SERIAL_CONSOLE
- {
- errnum=0;
- memset(myheap, 0, 256);
- run_script("serial --unit=0 --speed=9600\n\0", myheap); // dummy call
- memset(myheap, 0, 256);
-#ifndef CONFIG_VGA_CONSOLE
- run_script("terminal serial\n\0", myheap);
-#endif
- }
-#endif
-
- /* Never return. */
- for (;;)
- {
- int is_opened=0, is_preset=0;
-
- reset ();
-
-
- /* Here load the configuration file. */
-
- {
- char *default_file = (char *) DEFAULT_FILE_BUF;
- int i;
-
- /* Get a saved default entry if possible. */
- saved_entryno = 0;
- *default_file = 0;
-#if 0
- grub_strncat (default_file, config_file, DEFAULT_FILE_BUFLEN);
- for (i = grub_strlen(default_file); i >= 0; i--)
- if (default_file[i] == '/')
- {
- i++;
- break;
- }
- default_file[i] = 0;
- grub_strncat (default_file + i, "default", DEFAULT_FILE_BUFLEN - i);
- if (grub_open (default_file))
- {
- char buf[10]; /* This is good enough. */
- char *p = buf;
- int len;
-
- len = grub_read (buf, sizeof (buf));
- if (len > 0)
- {
- buf[sizeof (buf) - 1] = 0;
- safe_parse_maxint (&p, &saved_entryno);
- }
-
- grub_close ();
- }
-#endif
- errnum = ERR_NONE;
-
- do
- {
- /* STATE 0: Before any title command.
- STATE 1: In a title command.
- STATE >1: In a entry after a title command. */
- int state = 0, prev_config_len = 0, prev_menu_len = 0;
- char *cmdline;
-
- /* Try the preset menu first. This will succeed at most once,
- because close_preset_menu disables the preset menu. */
- is_opened = is_preset = open_preset_menu ();
- if (! is_opened)
- {
- grub_menulst();
- is_opened = grub_open (config_file);
- errnum = ERR_NONE;
- }
-
- if (! is_opened) {
- memset(myheap, 0, 256);
- printf("Could not open menu.lst file '%s'. Entering command line.\n", config_file);
-#if CONFIG_VGA_CONSOLE && ! CONFIG_SERIAL_CONSOLE
- run_script("terminal console\n\0", myheap);
-#elif !CONFIG_VGA_CONSOLE && CONFIG_SERIAL_CONSOLE
- run_script("terminal serial\n\0", myheap);
-#elif CONFIG_VGA_CONSOLE && CONFIG_SERIAL_CONSOLE
- run_script("terminal serial console\n\0", myheap);
-#endif
- break;
- }
-
- /* This is necessary, because the menu must be overrided. */
- reset ();
-
- cmdline = (char *) CMDLINE_BUF;
- while (get_line_from_config (cmdline, NEW_HEAPSIZE,
- ! is_preset))
- {
- struct builtin *builtin;
-
- /* Get the pointer to the builtin structure. */
- builtin = find_command (cmdline);
- errnum = 0;
- if (! builtin)
- /* Unknown command. Just skip now. */
- continue;
-
- if (builtin->flags & BUILTIN_TITLE)
- {
- char *ptr;
-
- /* the command "title" is specially treated. */
- if (state > 1)
- {
- /* The next title is found. */
- num_entries++;
- config_entries[config_len++] = 0;
- prev_menu_len = menu_len;
- prev_config_len = config_len;
- }
- else
- {
- /* The first title is found. */
- menu_len = prev_menu_len;
- config_len = prev_config_len;
- }
-
- /* Reset the state. */
- state = 1;
-
- /* Copy title into menu area. */
- ptr = skip_to (1, cmdline);
- while ((menu_entries[menu_len++] = *(ptr++)) != 0)
- ;
- }
- else if (! state)
- {
- /* Run a command found is possible. */
- if (builtin->flags & BUILTIN_MENU)
- {
- char *arg = skip_to (1, cmdline);
- (builtin->func) (arg, BUILTIN_MENU);
- errnum = 0;
- }
- else
- /* Ignored. */
- continue;
- }
- else
- {
- char *ptr = cmdline;
-
- state++;
- /* Copy config file data to config area. */
- while ((config_entries[config_len++] = *ptr++) != 0)
- ;
- }
- }
-
- if (state > 1)
- {
- /* Finish the last entry. */
- num_entries++;
- config_entries[config_len++] = 0;
- }
- else
- {
- menu_len = prev_menu_len;
- config_len = prev_config_len;
- }
-
- menu_entries[menu_len++] = 0;
- config_entries[config_len++] = 0;
- grub_memmove (config_entries + config_len, menu_entries,
- menu_len);
- menu_entries = config_entries + config_len;
-
- /* Make sure that all fallback entries are valid. */
- if (fallback_entryno >= 0)
- {
- for (i = 0; i < MAX_FALLBACK_ENTRIES; i++)
- {
- if (fallback_entries[i] < 0)
- break;
- if (fallback_entries[i] >= num_entries)
- {
- grub_memmove (fallback_entries + i,
- fallback_entries + i + 1,
- ((MAX_FALLBACK_ENTRIES - i - 1)
- * sizeof (int)));
- i--;
- }
- }
-
- if (fallback_entries[0] < 0)
- fallback_entryno = -1;
- }
- /* Check if the default entry is present. Otherwise reset
- it to fallback if fallback is valid, or to DEFAULT_ENTRY
- if not. */
- if (default_entry >= num_entries)
- {
- if (fallback_entryno >= 0)
- {
- default_entry = fallback_entries[0];
- fallback_entryno++;
- if (fallback_entryno >= MAX_FALLBACK_ENTRIES
- || fallback_entries[fallback_entryno] < 0)
- fallback_entryno = -1;
- }
- else
- default_entry = 0;
- }
-
- if (is_preset)
- close_preset_menu ();
- else
- grub_close ();
- }
- while (is_preset);
- }
-
- if (! num_entries)
- {
- /* If no acceptable config file, goto command-line, starting
- heap from where the config entries would have been stored
- if there were any. */
- enter_cmdline (config_entries, 1);
- }
- else
- {
- /* Run menu interface. */
- run_menu (menu_entries, config_entries, num_entries,
- menu_entries + menu_len, default_entry);
- }
- }
-}
Deleted: trunk/filo/main/grub/terminfo.c
===================================================================
--- trunk/filo/main/grub/terminfo.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/terminfo.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,259 +0,0 @@
-/* terminfo.c - read a terminfo entry from the command line */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2002,2004 Free Software Foundation, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * ######################################################################
- *
- * This file contains various functions dealing with different
- * terminal capabilities. It knows the difference between a vt52 and vt100
- * terminal (and much more) and is mainly used the terminal emulation
- * in the serial driver.
- */
-
-#include <libpayload.h>
-#include <grub/shared.h>
-#include <grub/terminfo.h>
-#include <grub/tparm.h>
-#include <grub/serial.h>
-
-/* Current terminal capabilities. Default is "vt100". */
-struct terminfo term =
- {
- .name = "vt100",
- .cursor_address = "\e[%i%p1%d;%p2%dH",
- .clear_screen = "\e[H\e[J",
- .enter_standout_mode = "\e[7m",
- .exit_standout_mode = "\e[m"
- };
-
-/* A number of escape sequences are provided in the string valued
- capabilities for easy encoding of characters there. Both \E and \e
- map to an ESCAPE character, ^x maps to a control-x for any
- appropriate x, and the sequences \n \l \r \t \b \f \s give a
- newline, line-feed, return, tab, backspace, form-feed, and space.
- Other escapes include \^ for ^, \\ for \, \, for comma, \: for :,
- and \0 for null. (\0 will produce \200, which does not terminate a
- string but behaves as a null character on most terminals, provid
- ing CS7 is specified. See stty(1).) Finally, characters may be
- given as three octal digits after a \. */
-
-char *
-ti_unescape_memory (const char *in, const char *end)
-{
- static char out_buffer[256];
- char c;
- char *out;
-
- out = out_buffer;
- do
- {
- c = *(in++);
- switch (c)
- {
- case '^':
- if (*in >= 'A' && *in <= 'Z')
- {
- *out = (*in) - 'A';
- in++;
- }
- else
- {
- *out = '^';
- }
- break;
- case '\\':
- c = *(in++);
- if (c >= '0' && c <= '9')
- {
- // octal number
- int n = 0;
- do
- {
- n = (n << 4) | (c - '0');
- c = *(in++);
- }
- while (c >= '0' && c <= '9');
-
- *out++ = (char)(n & 0xff);
-
- // redo last character
- in--;
-
- break;
- }
-
- switch (c)
- {
- case 'e':
- case 'E':
- *out++ = '\e';
- break;
- case 'n':
- *out++ = '\n';
- break;
- case 'r':
- *out++ = '\r';
- break;
- case 't':
- *out++ = '\t';
- break;
- case 'b':
- *out++ = '\b';
- break;
- case 'f':
- *out++ = '\f';
- break;
- case 's':
- *out++ = ' ';
- break;
- case '\\':
- *out++ = '\\';
- break;
- case '^':
- *out++ = '^';
- break;
- case ',':
- *out++ = ',';
- break;
- case ':':
- *out++ = ':';
- break;
- case '0':
- *out++ = '\200';
- break;
- }
- break;
- default:
- *out++ = c;
- break;
- }
- }
- while (in <= end);
-
- return out_buffer;
-}
-
-char *
-ti_unescape_string (const char *in)
-{
- return ti_unescape_memory (in, in + grub_strlen (in));
-}
-
-/* convert a memory region containing binary character into an external
- * ascii representation. The binary characters will be replaced by an
- * "ecsape notation". E.g. "033" will become "\e". */
-char *
-ti_escape_memory (const char *in, const char *end)
-{
- static char out_buffer[256];
- char c;
- char *out;
-
- out = out_buffer;
- do
- {
- c = *(in++);
- switch (c)
- {
- case '\e':
- *out++ = '\\'; *out++ = 'e'; break;
- case ' ':
- *out++ = '\\'; *out++ = 's'; break;
- case '\\':
- *out++ = '\\'; *out++ = '\\'; break;
- case '0' ... '9':
- case 'a' ... 'z':
- case 'A' ... 'Z':
- case '%':
- case '+':
- case '-':
- case '*':
- case '/':
- case ';':
- case ':':
- case '{':
- case '}':
- case '[':
- case ']':
- *out++ = c; break;
- case 0 ... 25:
- *out++ = '^'; *out++ = 'A' + c; break;
- default:
- *out++ = '\\';
- *out++ = ((c >> 8) & 7) + '0';
- *out++ = ((c >> 4) & 7) + '0';
- *out++ = ((c >> 0) & 7) + '0';
- break;
- }
- }
- while (in < end);
-
- *out++ = 0;
-
- return out_buffer;
-}
-
-/* convert a string containing binary character into an external ascii
- * representation. */
-char *
-ti_escape_string (const char *in)
-{
- return ti_escape_memory (in, in + grub_strlen (in));
-}
-
-/* move the cursor to the given position starting with "0". */
-void
-ti_cursor_address (int x, int y)
-{
- grub_putstr (grub_tparm (term.cursor_address, y, x));
-}
-
-/* clear the screen. */
-void
-ti_clear_screen (void)
-{
- grub_putstr (grub_tparm (term.clear_screen));
-}
-
-/* enter reverse video */
-void
-ti_enter_standout_mode (void)
-{
- grub_putstr (grub_tparm (term.enter_standout_mode));
-}
-
-/* exit reverse video */
-void
-ti_exit_standout_mode (void)
-{
- grub_putstr (grub_tparm (term.exit_standout_mode));
-}
-
-/* set the current terminal emulation to use */
-void
-ti_set_term (const struct terminfo *new)
-{
- grub_memmove (&term, new, sizeof (struct terminfo));
-}
-
-/* get the current terminal emulation */
-void
-ti_get_term(struct terminfo *copy)
-{
- grub_memmove (copy, &term, sizeof (struct terminfo));
-}
Deleted: trunk/filo/main/grub/tparm.c
===================================================================
--- trunk/filo/main/grub/tparm.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/main/grub/tparm.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -1,724 +0,0 @@
-/****************************************************************************
- * Copyright (c) 1998,2000,2002 Free Software Foundation, Inc. *
- * *
- * Permission is hereby granted, free of charge, to any person obtaining a *
- * copy of this software and associated documentation files (the *
- * "Software"), to deal in the Software without restriction, including *
- * without limitation the rights to use, copy, modify, merge, publish, *
- * distribute, distribute with modifications, sublicense, and/or sell *
- * copies of the Software, and to permit persons to whom the Software is *
- * furnished to do so, subject to the following conditions: *
- * *
- * The above copyright notice and this permission notice shall be included *
- * in all copies or substantial portions of the Software. *
- * *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
- * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
- * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
- * *
- * Except as contained in this notice, the name(s) of the above copyright *
- * holders shall not be used in advertising or otherwise to promote the *
- * sale, use or other dealings in this Software without prior written *
- * authorization. *
- ****************************************************************************/
-
-/**********************************************************************
- * This code is a modification of lib_tparm.c found in ncurses-5.2. The
- * modification are for use in grub by replacing all libc function through
- * special grub functions. This also meant to delete all dynamic memory
- * allocation and replace it by a number of fixed buffers.
- *
- * Modifications by Tilmann Bubeck <t.bubeck at reinform.de> 2002
- **********************************************************************/
-
-/****************************************************************************
- * Author: Zeyd M. Ben-Halim <zmbenhal at netcom.com> 1992,1995 *
- * and: Eric S. Raymond <esr at snark.thyrsus.com> *
- ****************************************************************************/
-
-/*
- * tparm.c
- *
- */
-
-#include <libpayload.h>
-#include <grub/shared.h>
-#include <grub/tparm.h>
-
-/*
- * Common/troublesome character definitions
- */
-typedef char grub_bool;
-#define isdigit(c) ((c) >= '0' && (c) <= '9')
-#ifndef FALSE
-# define FALSE (0)
-#endif
-#ifndef TRUE
-# define TRUE (!FALSE)
-#endif
-#define MAX_FORMAT_LEN 256
-#define max(a,b) ((a) > (b) ? (a) : (b))
-
-/*
- * char *
- * tparm(string, ...)
- *
- * Substitute the given parameters into the given string by the following
- * rules (taken from terminfo(5)):
- *
- * Cursor addressing and other strings requiring parame-
- * ters in the terminal are described by a parameterized string
- * capability, with like escapes %x in it. For example, to
- * address the cursor, the cup capability is given, using two
- * parameters: the row and column to address to. (Rows and
- * columns are numbered from zero and refer to the physical
- * screen visible to the user, not to any unseen memory.) If
- * the terminal has memory relative cursor addressing, that can
- * be indicated by
- *
- * The parameter mechanism uses a stack and special %
- * codes to manipulate it. Typically a sequence will push one
- * of the parameters onto the stack and then print it in some
- * format. Often more complex operations are necessary.
- *
- * The % encodings have the following meanings:
- *
- * %% outputs `%'
- * %c print pop() like %c in printf()
- * %s print pop() like %s in printf()
- * %[[:]flags][width[.precision]][doxXs]
- * as in printf, flags are [-+#] and space
- * The ':' is used to avoid making %+ or %-
- * patterns (see below).
- *
- * %p[1-9] push ith parm
- * %P[a-z] set dynamic variable [a-z] to pop()
- * %g[a-z] get dynamic variable [a-z] and push it
- * %P[A-Z] set static variable [A-Z] to pop()
- * %g[A-Z] get static variable [A-Z] and push it
- * %l push strlen(pop)
- * %'c' push char constant c
- * %{nn} push integer constant nn
- *
- * %+ %- %* %/ %m
- * arithmetic (%m is mod): push(pop() op pop())
- * %& %| %^ bit operations: push(pop() op pop())
- * %= %> %< logical operations: push(pop() op pop())
- * %A %O logical and & or operations for conditionals
- * %! %~ unary operations push(op pop())
- * %i add 1 to first two parms (for ANSI terminals)
- *
- * %? expr %t thenpart %e elsepart %;
- * if-then-else, %e elsepart is optional.
- * else-if's are possible ala Algol 68:
- * %? c1 %t b1 %e c2 %t b2 %e c3 %t b3 %e c4 %t b4 %e b5 %;
- *
- * For those of the above operators which are binary and not commutative,
- * the stack works in the usual way, with
- * %gx %gy %m
- * resulting in x mod y, not the reverse.
- */
-
-#define STACKSIZE 20
-
-typedef struct {
- union {
- unsigned int num;
- char *str;
- } data;
- grub_bool num_type;
-} stack_frame;
-
-static stack_frame stack[STACKSIZE];
-static int stack_ptr;
-
-static char out_buff[256];
-static int out_size = 256;
-static int out_used;
-
-static inline void
-get_space(int need)
-{
- need += out_used;
- if (need > out_size) {
- // FIX ME! buffer full, what now?
- ;
- }
-}
-
-static inline void
-save_text(const char *fmt, const char *s, int len)
-{
- int s_len = grub_strlen(s);
- if (len > (int) s_len)
- s_len = len;
-
- get_space(s_len + 1);
-
- (void) grub_sprintf(out_buff + out_used, fmt, s);
- out_used += grub_strlen(out_buff + out_used);
-}
-
-static inline void
-save_number(const char *fmt, int number, int len)
-{
- if (len < 30)
- len = 30; /* actually log10(MAX_INT)+1 */
-
- get_space(len + 1);
-
- (void) grub_sprintf(out_buff + out_used, fmt, number);
- out_used += grub_strlen(out_buff + out_used);
-}
-
-static inline void
-save_char(int c)
-{
- if (c == 0)
- c = 0200;
- get_space(1);
- out_buff[out_used++] = c;
-}
-
-static inline void
-npush(int x)
-{
- if (stack_ptr < STACKSIZE) {
- stack[stack_ptr].num_type = TRUE;
- stack[stack_ptr].data.num = x;
- stack_ptr++;
- }
-}
-
-static inline int
-npop(void)
-{
- int result = 0;
- if (stack_ptr > 0) {
- stack_ptr--;
- if (stack[stack_ptr].num_type)
- result = stack[stack_ptr].data.num;
- }
- return result;
-}
-
-static inline void
-spush(char *x)
-{
- if (stack_ptr < STACKSIZE) {
- stack[stack_ptr].num_type = FALSE;
- stack[stack_ptr].data.str = x;
- stack_ptr++;
- }
-}
-
-static inline char *
-spop(void)
-{
- static char dummy[] = ""; /* avoid const-cast */
- char *result = dummy;
- if (stack_ptr > 0) {
- stack_ptr--;
- if (!stack[stack_ptr].num_type && stack[stack_ptr].data.str != 0)
- result = stack[stack_ptr].data.str;
- }
- return result;
-}
-
-static inline const char *
-parse_format(const char *s, char *format, int *len)
-{
- grub_bool done = FALSE;
- grub_bool allowminus = FALSE;
- grub_bool dot = FALSE;
- grub_bool err = FALSE;
- char *fmt = format;
- int prec = 0;
- int width = 0;
- int value = 0;
-
- *len = 0;
- *format++ = '%';
- while (*s != '\0' && !done) {
- switch (*s) {
- case 'c': /* FALLTHRU */
- case 'd': /* FALLTHRU */
- case 'o': /* FALLTHRU */
- case 'x': /* FALLTHRU */
- case 'X': /* FALLTHRU */
- case 's':
- *format++ = *s;
- done = TRUE;
- break;
- case '.':
- *format++ = *s++;
- if (dot) {
- err = TRUE;
- } else {
- dot = TRUE;
- prec = value;
- }
- value = 0;
- break;
- case '#':
- *format++ = *s++;
- break;
- case ' ':
- *format++ = *s++;
- break;
- case ':':
- s++;
- allowminus = TRUE;
- break;
- case '-':
- if (allowminus) {
- *format++ = *s++;
- } else {
- done = TRUE;
- }
- break;
- default:
- if (isdigit(*s)) {
- value = (value * 10) + (*s - '0');
- if (value > 10000)
- err = TRUE;
- *format++ = *s++;
- } else {
- done = TRUE;
- }
- }
- }
-
- /*
- * If we found an error, ignore (and remove) the flags.
- */
- if (err) {
- prec = width = value = 0;
- format = fmt;
- *format++ = '%';
- *format++ = *s;
- }
-
- if (dot)
- width = value;
- else
- prec = value;
-
- *format = '\0';
- /* return maximum string length in print */
- *len = (prec > width) ? prec : width;
- return s;
-}
-
-#define isUPPER(c) ((c) >= 'A' && (c) <= 'Z')
-#define isLOWER(c) ((c) >= 'a' && (c) <= 'z')
-
-static inline char *
-tparam_internal(const char *string, int *dataptr)
-{
-#define NUM_VARS 26
- char *p_is_s[9];
- int param[9];
- int lastpop;
- int popcount;
- int number;
- int len;
- int level;
- int x, y;
- int i;
- int len2;
- register const char *cp;
- static int len_fmt = MAX_FORMAT_LEN;
- static char dummy[] = "";
- static char format[MAX_FORMAT_LEN];
- static int dynamic_var[NUM_VARS];
- static int static_vars[NUM_VARS];
-
- out_used = 0;
- if (string == NULL)
- return NULL;
-
- if ((len2 = grub_strlen(string)) > len_fmt) {
- return NULL;
- }
-
- /*
- * Find the highest parameter-number referred to in the format string.
- * Use this value to limit the number of arguments copied from the
- * variable-length argument list.
- */
-
- number = 0;
- lastpop = -1;
- popcount = 0;
- grub_memset(p_is_s, 0, sizeof(p_is_s));
-
- /*
- * Analyze the string to see how many parameters we need from the varargs
- * list, and what their types are. We will only accept string parameters
- * if they appear as a %l or %s format following an explicit parameter
- * reference (e.g., %p2%s). All other parameters are numbers.
- *
- * 'number' counts coarsely the number of pop's we see in the string, and
- * 'popcount' shows the highest parameter number in the string. We would
- * like to simply use the latter count, but if we are reading termcap
- * strings, there may be cases that we cannot see the explicit parameter
- * numbers.
- */
- for (cp = string; (cp - string) < (int) len2;) {
- if (*cp == '%') {
- cp++;
- cp = parse_format(cp, format, &len);
- switch (*cp) {
- default:
- break;
-
- case 'd': /* FALLTHRU */
- case 'o': /* FALLTHRU */
- case 'x': /* FALLTHRU */
- case 'X': /* FALLTHRU */
- case 'c': /* FALLTHRU */
- number++;
- lastpop = -1;
- break;
-
- case 'l':
- case 's':
- if (lastpop > 0)
- p_is_s[lastpop - 1] = dummy;
- ++number;
- break;
-
- case 'p':
- cp++;
- i = (*cp - '0');
- if (i >= 0 && i <= 9) {
- lastpop = i;
- if (lastpop > popcount)
- popcount = lastpop;
- }
- break;
-
- case 'P':
- case 'g':
- cp++;
- break;
-
- case '\'':
- cp += 2;
- lastpop = -1;
- break;
-
- case '{':
- cp++;
- while (*cp >= '0' && *cp <= '9') {
- cp++;
- }
- break;
-
- case '+':
- case '-':
- case '*':
- case '/':
- case 'm':
- case 'A':
- case 'O':
- case '&':
- case '|':
- case '^':
- case '=':
- case '<':
- case '>':
- case '!':
- case '~':
- lastpop = -1;
- number += 2;
- break;
-
- case 'i':
- lastpop = -1;
- if (popcount < 2)
- popcount = 2;
- break;
- }
- }
- if (*cp != '\0')
- cp++;
- }
-
- if (number > 9)
- number = 9;
- for (i = 0; i < max(popcount, number); i++) {
- /*
- * A few caps (such as plab_norm) have string-valued parms.
- * We'll have to assume that the caller knows the difference, since
- * a char* and an int may not be the same size on the stack.
- */
- if (p_is_s[i] != 0) {
- p_is_s[i] = (char *)(*(dataptr++));
- } else {
- param[i] = (int)(*(dataptr++));
- }
- }
-
- /*
- * This is a termcap compatibility hack. If there are no explicit pop
- * operations in the string, load the stack in such a way that
- * successive pops will grab successive parameters. That will make
- * the expansion of (for example) \E[%d;%dH work correctly in termcap
- * style, which means tparam() will expand termcap strings OK.
- */
- stack_ptr = 0;
- if (popcount == 0) {
- popcount = number;
- for (i = number - 1; i >= 0; i--)
- npush(param[i]);
- }
-
- while (*string) {
- /* skip delay timings */
- if (*string == '$' && *(string + 1) == '<') {
- while( *string && *string != '>')
- string++;
- if ( *string == '>' ) string++;
- } else if ( *string == '%') {
- string++;
- string = parse_format(string, format, &len);
- switch (*string) {
- default:
- break;
- case '%':
- save_char('%');
- break;
-
- case 'd': /* FALLTHRU */
- case 'o': /* FALLTHRU */
- case 'x': /* FALLTHRU */
- case 'X': /* FALLTHRU */
- case 'c': /* FALLTHRU */
- save_number(format, npop(), len);
- break;
-
- case 'l':
- save_number("%d", strlen(spop()), 0);
- break;
-
- case 's':
- save_text(format, spop(), len);
- break;
-
- case 'p':
- string++;
- i = (*string - '1');
- if (i >= 0 && i < 9) {
- if (p_is_s[i])
- spush(p_is_s[i]);
- else
- npush(param[i]);
- }
- break;
-
- case 'P':
- string++;
- if (isUPPER(*string)) {
- i = (*string - 'A');
- static_vars[i] = npop();
- } else if (isLOWER(*string)) {
- i = (*string - 'a');
- dynamic_var[i] = npop();
- }
- break;
-
- case 'g':
- string++;
- if (isUPPER(*string)) {
- i = (*string - 'A');
- npush(static_vars[i]);
- } else if (isLOWER(*string)) {
- i = (*string - 'a');
- npush(dynamic_var[i]);
- }
- break;
-
- case '\'':
- string++;
- npush(*string);
- string++;
- break;
-
- case '{':
- number = 0;
- string++;
- while (*string >= '0' && *string <= '9') {
- number = number * 10 + *string - '0';
- string++;
- }
- npush(number);
- break;
-
- case '+':
- npush(npop() + npop());
- break;
-
- case '-':
- y = npop();
- x = npop();
- npush(x - y);
- break;
-
- case '*':
- npush(npop() * npop());
- break;
-
- case '/':
- y = npop();
- x = npop();
- npush(y ? (x / y) : 0);
- break;
-
- case 'm':
- y = npop();
- x = npop();
- npush(y ? (x % y) : 0);
- break;
-
- case 'A':
- npush(npop() && npop());
- break;
-
- case 'O':
- npush(npop() || npop());
- break;
-
- case '&':
- npush(npop() & npop());
- break;
-
- case '|':
- npush(npop() | npop());
- break;
-
- case '^':
- npush(npop() ^ npop());
- break;
-
- case '=':
- y = npop();
- x = npop();
- npush(x == y);
- break;
-
- case '<':
- y = npop();
- x = npop();
- npush(x < y);
- break;
-
- case '>':
- y = npop();
- x = npop();
- npush(x > y);
- break;
-
- case '!':
- npush(!npop());
- break;
-
- case '~':
- npush(~npop());
- break;
-
- case 'i':
- if (p_is_s[0] == 0)
- param[0]++;
- if (p_is_s[1] == 0)
- param[1]++;
- break;
-
- case '?':
- break;
-
- case 't':
- x = npop();
- if (!x) {
- /* scan forward for %e or %; at level zero */
- string++;
- level = 0;
- while (*string) {
- if (*string == '%') {
- string++;
- if (*string == '?')
- level++;
- else if (*string == ';') {
- if (level > 0)
- level--;
- else
- break;
- } else if (*string == 'e' && level == 0)
- break;
- }
-
- if (*string)
- string++;
- }
- }
- break;
-
- case 'e':
- /* scan forward for a %; at level zero */
- string++;
- level = 0;
- while (*string) {
- if (*string == '%') {
- string++;
- if (*string == '?')
- level++;
- else if (*string == ';') {
- if (level > 0)
- level--;
- else
- break;
- }
- }
-
- if (*string)
- string++;
- }
- break;
-
- case ';':
- break;
-
- } /* endswitch (*string) */
- } else { /* endelse (*string == '%') */
- save_char(*string);
- }
-
- if (*string == '\0')
- break;
-
- string++;
- } /* endwhile (*string) */
-
- get_space(1);
- out_buff[out_used] = '\0';
-
- return (out_buff);
-}
-
-char *
-grub_tparm(const char *string,...)
-{
- char *result;
- int *dataptr = (int *) &string;
-
- dataptr++;
-
- result = tparam_internal(string, dataptr);
-
- return result;
-}
Modified: trunk/filo/util/Makefile.inc
===================================================================
--- trunk/filo/util/Makefile.inc 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/util/Makefile.inc 2008-09-18 08:04:13 UTC (rev 63)
@@ -20,31 +20,34 @@
EBCHECKSUM_OBJS := $(patsubst %,$(obj)/util/%,$(EBCHECKSUM))
$(obj)/util/ebchecksum: $(EBCHECKSUM_OBJS)
- @echo " HOSTCC $@"
+ @echo " HOSTCC $(subst $(shell pwd)/,,$(@))"
@$(HOSTCC) $(HOSTCFLAGS) $(EBCHECKSUM_OBJS) -o $@
$(obj)/util/%.o: $(src)/util/%.c
- @echo " HOSTCC $<"
+ @echo " HOSTCC $(subst $(shell pwd)/,,$(<))"
@$(HOSTCC) $(HOSTCFLAGS) -Iinclude -c $< -o $@
$(obj)/util/ipchecksum.o: $(src)/main/ipchecksum.c
- @echo " HOSTCC $<"
+ @echo " HOSTCC $(subst $(shell pwd)/,,$(<))"
@$(HOSTCC) $(HOSTCFLAGS) -Iinclude -c $< -o $@
$(obj)/util/checksum_elf32le.o: util/checksum_elf.c
- @echo " HOSTCC $< -> `basename $@`"
+ @echo " HOSTCC $< -> $(subst $(shell pwd)/,,$(@))"
@$(HOSTCC) $(HOSTCFLAGS) -Iinclude -DTARGET_CLASS=ELFCLASS32 -DTARGET_DATA=ELFDATA2LSB -c $< -o $@
$(obj)/util/checksum_elf32be.o: util/checksum_elf.c
- @echo " HOSTCC $< -> `basename $@`"
+ @echo " HOSTCC $< -> $(subst $(shell pwd)/,,$(@))"
@$(HOSTCC) $(HOSTCFLAGS) -Iinclude -DTARGET_CLASS=ELFCLASS32 -DTARGET_DATA=ELFDATA2MSB -c $< -o $@
$(obj)/util/checksum_elf64le.o: util/checksum_elf.c
- @echo " HOSTCC $< -> `basename $@`"
+ @echo " HOSTCC $< -> $(subst $(shell pwd)/,,$(@))"
@$(HOSTCC) $(HOSTCFLAGS) -Iinclude -DTARGET_CLASS=ELFCLASS64 -DTARGET_DATA=ELFDATA2LSB -c $< -o $@
$(obj)/util/checksum_elf64be.o: util/checksum_elf.c
- @echo " HOSTCC $< -> `basename $@`"
+ @echo " HOSTCC $< -> $(subst $(shell pwd)/,,$(@))"
@$(HOSTCC) $(HOSTCFLAGS) -Iinclude -DTARGET_CLASS=ELFCLASS64 -DTARGET_DATA=ELFDATA2MSB -c $< -o $@
-$(obj)/util/vmser: vmser.o
- @echo " HOSTCC $<"
- @$(HOSTCC) $(HOSTCFLAGS) vmser.o -lcurses -o $@
+$(obj)/util/vmser: util/vmser.c
+ @echo " HOSTCC $(subst $(shell pwd)/,,$(<))"
+ @$(HOSTCC) $(HOSTCFLAGS) $< -lcurses -o $@
+vmser: $(obj)/util/vmser
+
+.PHONY : vmser
Modified: trunk/filo/util/vmser.c
===================================================================
--- trunk/filo/util/vmser.c 2008-09-11 18:51:46 UTC (rev 62)
+++ trunk/filo/util/vmser.c 2008-09-18 08:04:13 UTC (rev 63)
@@ -20,6 +20,7 @@
* Simple terminal for VMware serial port
*/
#include <stdio.h>
+#include <string.h>
#include <curses.h>
#include <unistd.h>
#include <sys/types.h>
More information about the coreboot
mailing list