2007-10-31 Robert Millan <rmh@aybabtu.com>

* configure.ac: Add `i386-linuxbios' to the list of supported targets.

	* conf/i386-linuxbios.rmk: New file.

	* kern/i386/pc/hardware.c: Likewise.
	* term/i386/pc/at_keyboard.c: Likewise.
	* term/i386/pc/vga_text.c: Likewise.

	* include/grub/i386/linuxbios/boot.h: Likewise.
	* include/grub/i386/linuxbios/console.h: Likewise.
	* include/grub/i386/linuxbios/init.h: Likewise.
	* include/grub/i386/linuxbios/kernel.h: Likewise.
	* include/grub/i386/linuxbios/loader.h: Likewise.
	* include/grub/i386/linuxbios/memory.h: Likewise.
	* include/grub/i386/linuxbios/serial.h: Likewise.
	* include/grub/i386/linuxbios/time.h: Likewise.

	* kern/i386/linuxbios/init.c: Likewise.
	* kern/i386/linuxbios/startup.S: Likewise.
	* kern/i386/linuxbios/table.c: Likewise.
This commit is contained in:
robertmh 2007-10-31 22:35:13 +00:00
parent e911ecc1c2
commit ca25d8f0c1
19 changed files with 6147 additions and 3373 deletions

View file

@ -1,3 +1,26 @@
2007-10-31 Robert Millan <rmh@aybabtu.com>
* configure.ac: Add `i386-linuxbios' to the list of supported targets.
* conf/i386-linuxbios.rmk: New file.
* kern/i386/pc/hardware.c: Likewise.
* term/i386/pc/at_keyboard.c: Likewise.
* term/i386/pc/vga_text.c: Likewise.
* include/grub/i386/linuxbios/boot.h: Likewise.
* include/grub/i386/linuxbios/console.h: Likewise.
* include/grub/i386/linuxbios/init.h: Likewise.
* include/grub/i386/linuxbios/kernel.h: Likewise.
* include/grub/i386/linuxbios/loader.h: Likewise.
* include/grub/i386/linuxbios/memory.h: Likewise.
* include/grub/i386/linuxbios/serial.h: Likewise.
* include/grub/i386/linuxbios/time.h: Likewise.
* kern/i386/linuxbios/init.c: Likewise.
* kern/i386/linuxbios/startup.S: Likewise.
* kern/i386/linuxbios/table.c: Likewise.
2007-10-31 Marco Gerards <marco@gnu.org>
* conf/i386-pc.rmk (pkgdata_MODULES): Add `ata.mod'.

View file

@ -56,6 +56,8 @@ conf/common.mk
conf/common.rmk
conf/i386-efi.mk
conf/i386-efi.rmk
conf/i386-linuxbios.rmk
conf/i386-linuxbios.mk
conf/i386-pc.mk
conf/i386-pc.rmk
conf/powerpc-ieee1275.mk
@ -145,6 +147,14 @@ include/grub/i386/efi/kernel.h
include/grub/i386/efi/loader.h
include/grub/i386/efi/time.h
include/grub/i386/io.h
include/grub/i386/linuxbios/boot.h
include/grub/i386/linuxbios/console.h
include/grub/i386/linuxbios/init.h
include/grub/i386/linuxbios/kernel.h
include/grub/i386/linuxbios/loader.h
include/grub/i386/linuxbios/memory.h
include/grub/i386/linuxbios/serial.h
include/grub/i386/linuxbios/time.h
include/grub/i386/pc/biosdisk.h
include/grub/i386/pc/boot.h
include/grub/i386/pc/chainloader.h
@ -211,9 +221,14 @@ kern/i386/dl.c
kern/i386/efi/init.c
kern/i386/efi/startup.S
kern/i386/loader.S
kern/i386/linuxbios/init.c
kern/i386/linuxbios/startup.S
kern/i386/linuxbios/table.c
term/i386/pc/at_keyboard.c
kern/i386/pc/init.c
kern/i386/pc/lzo1x.S
kern/i386/pc/startup.S
term/i386/pc/vga_text.c
kern/i386/realmode.S
kern/ieee1275/ieee1275.c
kern/powerpc/cache.S

1327
conf/i386-linuxbios.mk Normal file

File diff suppressed because it is too large Load diff

149
conf/i386-linuxbios.rmk Normal file
View file

@ -0,0 +1,149 @@
# -*- makefile -*-
COMMON_ASFLAGS = -m32 -nostdinc -fno-builtin
COMMON_CFLAGS = -ffreestanding -mrtd -mregparm=3
COMMON_LDFLAGS = -nostdlib -static -lgcc
# Images.
pkgdata_PROGRAMS = kernel.elf
# For kernel.elf.
kernel_elf_SOURCES = kern/i386/linuxbios/startup.S kern/i386/linuxbios/init.c \
kern/i386/linuxbios/table.c \
kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
kern/i386/dl.c kern/parser.c kern/partition.c \
kern/env.c \
term/i386/pc/console.c \
term/i386/pc/at_keyboard.c term/i386/pc/vga_text.c \
symlist.c
kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
machine/boot.h machine/console.h machine/init.h \
machine/memory.h machine/loader.h
kernel_elf_CFLAGS = $(COMMON_CFLAGS)
kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x8200,-Bstatic
MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst
symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh
/bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
kernel_syms.lst: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h genkernsyms.sh
/bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
# Utilities.
bin_UTILITIES = grub-mkimage
sbin_UTILITIES = grub-mkdevicemap grub-probe
ifeq ($(enable_grub_emu), yes)
sbin_UTILITIES += grub-emu
endif
# For grub-mkimage.
grub_mkimage_SOURCES = util/elf/grub-mkimage.c util/misc.c \
util/resolve.c
grub_mkimage_LDFLAGS = $(LIBLZO)
# For grub-mkdevicemap.
grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c \
util/i386/get_disk_name.c
# For grub-probe.
util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
grub_probe_SOURCES = util/grub-probe.c \
util/biosdisk.c util/misc.c util/getroot.c \
kern/device.c kern/disk.c kern/err.c kern/misc.c fs/fat.c \
fs/ext2.c kern/parser.c kern/partition.c \
partmap/pc.c partmap/apple.c partmap/gpt.c \
fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c fs/ntfs.c kern/fs.c \
kern/env.c fs/fshelp.c fs/xfs.c fs/affs.c fs/sfs.c fs/hfsplus.c \
disk/lvm.c disk/raid.c grub_probe_init.c
# For grub-emu.
grub_emu_DEPENDENCIES = grub_script.tab.c grub_script.tab.h \
grub_emu_init.h
grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
commands/configfile.c commands/echo.c commands/help.c \
commands/terminal.c commands/ls.c commands/test.c \
commands/search.c commands/blocklist.c \
commands/i386/pc/halt.c commands/i386/pc/reboot.c \
commands/i386/cpuid.c \
disk/host.c disk/loopback.c disk/raid.c disk/lvm.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
fs/ntfs.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \
normal/execute.c kern/file.c kern/fs.c normal/lexer.c \
kern/loader.c kern/main.c kern/misc.c kern/parser.c \
grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \
normal/arg.c normal/cmdline.c normal/command.c normal/function.c\
normal/completion.c normal/main.c \
normal/menu.c normal/menu_entry.c normal/misc.c normal/script.c \
partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \
partmap/acorn.c partmap/gpt.c \
util/console.c util/hostfs.c util/grub-emu.c util/misc.c \
util/biosdisk.c util/getroot.c \
util/i386/pc/misc.c grub_emu_init.c
grub_emu_LDFLAGS = $(LIBCURSES)
# Modules.
pkgdata_MODULES = _linux.mod linux.mod normal.mod \
_multiboot.mod multiboot.mod play.mod \
cpuid.mod serial.mod
# For _linux.mod.
_linux_mod_SOURCES = loader/i386/pc/linux.c
_linux_mod_CFLAGS = $(COMMON_CFLAGS)
_linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For linux.mod.
linux_mod_SOURCES = loader/i386/pc/linux_normal.c
linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For normal.mod.
normal_mod_DEPENDENCIES = grub_script.tab.c grub_script.tab.h
normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
normal/completion.c normal/execute.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_entry.c normal/misc.c grub_script.tab.c \
normal/script.c normal/i386/setjmp.S
normal_mod_CFLAGS = $(COMMON_CFLAGS)
normal_mod_ASFLAGS = $(COMMON_ASFLAGS)
normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For serial.mod.
serial_mod_SOURCES = term/i386/pc/serial.c
serial_mod_CFLAGS = $(COMMON_CFLAGS)
serial_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For _multiboot.mod.
_multiboot_mod_SOURCES = loader/i386/pc/multiboot.c \
loader/i386/pc/multiboot2.c \
loader/multiboot2.c \
loader/multiboot_loader.c
_multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
_multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For multiboot.mod.
multiboot_mod_SOURCES = loader/multiboot_loader_normal.c
multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For play.mod.
play_mod_SOURCES = commands/i386/pc/play.c
play_mod_CFLAGS = $(COMMON_CFLAGS)
play_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For cpuid.mod.
cpuid_mod_SOURCES = commands/i386/cpuid.c
cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
include $(srcdir)/conf/common.mk

7251
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -78,6 +78,7 @@ fi
case "$target_cpu"-"$platform" in
i386-efi) ;;
i386-pc) ;;
i386-linuxbios) ;;
powerpc-ieee1275) ;;
sparc64-ieee1275) ;;
*) AC_MSG_ERROR([unsupported machine type]) ;;

View file

@ -0,0 +1 @@
#include <grub/i386/pc/boot.h>

View file

@ -0,0 +1 @@
#include <grub/i386/pc/console.h>

View file

@ -0,0 +1,28 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_INIT_I386_LINUXBIOS_HEADER
#define GRUB_INIT_I386_LINUXBIOS_HEADER 1
#include <grub/symbol.h>
#include <grub/i386/pc/memory.h>
void EXPORT_FUNC(grub_stop) (void);
void EXPORT_FUNC(grub_stop_floppy) (void);
#endif

View file

@ -0,0 +1,26 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2006,2007 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_KERNEL_MACHINE_HEADER
#define GRUB_KERNEL_MACHINE_HEADER 1
#include <grub/symbol.h>
#define GRUB_MOD_ALIGN 0x1000
#endif /* ! GRUB_KERNEL_MACHINE_HEADER */

View file

@ -0,0 +1 @@
#include <grub/cpu/loader.h>

View file

@ -0,0 +1,70 @@
/* memory.h - describe the memory map */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2007 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _GRUB_MEMORY_MACHINE_LB_HEADER
#define _GRUB_MEMORY_MACHINE_LB_HEADER 1
#include <grub/symbol.h>
#include <grub/i386/pc/memory.h>
#ifndef ASM_FILE
#include <grub/types.h>
#include <grub/err.h>
#endif
#define GRUB_MEMORY_MACHINE_LINUXBIOS_TABLE_ADDR 0x500
#define GRUB_MEMORY_MACHINE_LOWER_USABLE 0x9fc00 /* 640 kiB - 1 kiB */
#define GRUB_MEMORY_MACHINE_LOWER_SIZE 0xf0000 /* 960 kiB */
#define GRUB_MEMORY_MACHINE_UPPER_START 0x100000 /* 1 MiB */
#ifndef ASM_FILE
struct grub_linuxbios_table_header
{
char signature[4];
grub_uint32_t size;
};
typedef struct grub_linuxbios_table_header *grub_linuxbios_table_header_t;
struct grub_linuxbios_table_item
{
#define GRUB_LINUXBIOS_MEMBER_UNUSED 0
#define GRUB_LINUXBIOS_MEMBER_MEMORY 1
grub_uint32_t tag;
grub_uint32_t size;
};
typedef struct grub_linuxbios_table_item *grub_linuxbios_table_item_t;
struct grub_linuxbios_mem_region
{
grub_uint64_t addr;
grub_uint64_t size;
#define GRUB_LINUXBIOS_MEMORY_AVAILABLE 1
grub_uint32_t type;
};
typedef struct grub_linuxbios_mem_region *mem_region_t;
grub_err_t EXPORT_FUNC(grub_available_iterate)
(int (*hook) (mem_region_t));
#endif
#endif /* ! _GRUB_MEMORY_MACHINE_HEADER */

View file

@ -0,0 +1 @@
#include <grub/i386/pc/serial.h>

View file

@ -0,0 +1 @@
#include <grub/i386/pc/time.h>

186
kern/i386/linuxbios/init.c Normal file
View file

@ -0,0 +1,186 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/kernel.h>
#include <grub/mm.h>
#include <grub/machine/time.h>
#include <grub/machine/init.h>
#include <grub/machine/memory.h>
#include <grub/machine/console.h>
#include <grub/machine/kernel.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/loader.h>
#include <grub/env.h>
#include <grub/cache.h>
#include <grub/time.h>
#include <grub/symbol.h>
#include <grub/cpu/io.h>
#define GRUB_FLOPPY_REG_DIGITAL_OUTPUT 0x3f2
extern char _start[];
extern char _end[];
grub_addr_t grub_os_area_addr;
grub_size_t grub_os_area_size;
grub_size_t grub_lower_mem, grub_upper_mem;
/* FIXME: we need interrupts to do this right */
static grub_uint32_t grub_time_tics = 0;
grub_uint32_t
grub_get_rtc (void)
{
return grub_time_tics;
}
/* Stop the floppy drive from spinning, so that other software is
jumped to with a known state. */
void
grub_stop_floppy (void)
{
grub_outb (0, GRUB_FLOPPY_REG_DIGITAL_OUTPUT);
}
void
grub_millisleep (grub_uint32_t ms __attribute__ ((unused)))
{
}
void
grub_exit ()
{
grub_printf ("grub_exit() is not implemented.\n");
grub_stop ();
}
void
grub_reboot ()
{
grub_printf ("grub_reboot() is not implemented.\n");
grub_stop ();
}
void
grub_halt (int no_apm __attribute__ ((unused)))
{
grub_printf ("grub_halt() is not implemented.\n");
grub_stop ();
}
void
grub_arch_sync_caches (void *address __attribute__ ((unused)),
grub_size_t len __attribute__ ((unused)))
{
}
static char *
make_install_device (void)
{
return NULL;
}
void
grub_machine_init (void)
{
/* Initialize the console as early as possible. */
grub_console_init ();
grub_lower_mem = GRUB_MEMORY_MACHINE_LOWER_USABLE;
grub_upper_mem = 0;
auto int heap_init (mem_region_t);
int heap_init (mem_region_t mem_region)
{
grub_uint64_t addr = mem_region->addr;
grub_uint64_t size = mem_region->size;
#if GRUB_CPU_SIZEOF_VOID_P == 4
/* Restrict ourselves to 32-bit memory space. */
if (addr > ULONG_MAX)
{
grub_upper_mem = ULONG_MAX;
return 0;
}
if (addr + size > ULONG_MAX)
size = ULONG_MAX - addr;
#endif
grub_upper_mem = grub_max (grub_upper_mem, addr + size);
if (mem_region->type != GRUB_LINUXBIOS_MEMORY_AVAILABLE)
return 0;
/* Avoid the lower memory. */
if (addr < GRUB_MEMORY_MACHINE_LOWER_SIZE)
{
if (addr + size <= GRUB_MEMORY_MACHINE_LOWER_SIZE)
return 0;
else
{
size -= GRUB_MEMORY_MACHINE_LOWER_SIZE - addr;
addr = GRUB_MEMORY_MACHINE_LOWER_SIZE;
}
}
if (addr == GRUB_MEMORY_MACHINE_UPPER_START
|| (addr >= GRUB_MEMORY_MACHINE_LOWER_SIZE
&& addr <= GRUB_MEMORY_MACHINE_UPPER_START
&& (addr + size > GRUB_MEMORY_MACHINE_UPPER_START)))
{
grub_size_t quarter = size >> 2;
grub_os_area_addr = addr;
grub_os_area_size = size - quarter;
grub_mm_init_region ((void *) (grub_os_area_addr + grub_os_area_size),
quarter);
}
else
grub_mm_init_region ((void *) addr, (grub_size_t) size);
return 0;
}
grub_available_iterate (heap_init);
/* This variable indicates size, not offset. */
grub_upper_mem -= GRUB_MEMORY_MACHINE_UPPER_START;
}
void
grub_machine_set_prefix (void)
{
/* Initialize the prefix. */
grub_env_set ("prefix", make_install_device ());
}
void
grub_machine_fini (void)
{
grub_console_fini ();
}
/* Return the end of the core image. */
grub_addr_t
grub_arch_modules_addr (void)
{
return ALIGN_UP(_end, GRUB_MOD_ALIGN);
}

View file

@ -0,0 +1,77 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#define ASM_FILE 1
#include <grub/symbol.h>
#include <grub/machine/memory.h>
#include <grub/cpu/linux.h>
#include <multiboot.h>
#include <multiboot2.h>
/*
* Note: GRUB is compiled with the options -mrtd and -mregparm=3.
* So the first three arguments are passed in %eax, %edx, and %ecx,
* respectively, and if a function has a fixed number of arguments
* and the number if greater than three, the function must return
* with "ret $N" where N is ((the number of arguments) - 3) * 4.
*/
.file "startup.S"
.text
.globl start, _start
#if 0
/*
* Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself).
*/
multiboot_header:
/* magic */
.long 0x1BADB002
/* flags */
.long 0
/* checksum */
.long -0x1BADB002
#endif
start:
_start:
/* initialize the stack */
movl $GRUB_MEMORY_MACHINE_PROT_STACK, %esp
/* jump to the main body of C code */
jmp EXT_C(grub_main)
/*
* This call is special... it never returns... in fact it should simply
* hang at this point!
*/
FUNCTION(grub_stop)
hlt
jmp EXT_C(grub_stop)
/*
* prot_to_real and associated structures (but NOT real_to_prot, that is
* only needed for BIOS gates).
*/
#include "../realmode.S"
/*
* Routines needed by Linux and Multiboot loaders.
*/
#include "../loader.S"

View file

@ -0,0 +1,69 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/machine/memory.h>
#include <grub/types.h>
#include <grub/err.h>
static grub_err_t
grub_linuxbios_table_iterate (grub_linuxbios_table_header_t table_header,
int (*hook) (grub_linuxbios_table_item_t))
{
grub_linuxbios_table_item_t table_item;
if (grub_memcmp (table_header->signature, "LBIO", 4))
grub_fatal ("Could not find LinuxBIOS table\n");
table_item =
(grub_linuxbios_table_item_t) ((long) table_header +
(long) table_header->size);
for (; table_item->size;
table_item = (grub_linuxbios_table_item_t) ((long) table_item + (long) table_item->size))
if (hook (table_item))
return 1;
return 0;
}
grub_err_t
grub_available_iterate (int (*hook) (mem_region_t))
{
mem_region_t mem_region;
auto int iterate_linuxbios_table (grub_linuxbios_table_item_t);
int iterate_linuxbios_table (grub_linuxbios_table_item_t table_item)
{
if (table_item->tag != GRUB_LINUXBIOS_MEMBER_MEMORY)
return 0;
mem_region =
(mem_region_t) ((long) table_item +
sizeof (struct grub_linuxbios_table_item));
for (; (long) mem_region < (long) table_item + (long) table_item->size;
mem_region++)
if (hook (mem_region))
return 1;
return 0;
}
grub_linuxbios_table_iterate (GRUB_MEMORY_MACHINE_LINUXBIOS_TABLE_ADDR,
iterate_linuxbios_table);
return 0;
}

182
term/i386/pc/at_keyboard.c Normal file
View file

@ -0,0 +1,182 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/machine/console.h>
#include <grub/cpu/io.h>
#include <grub/misc.h>
#define SHIFT_L 0x2a
#define SHIFT_R 0x36
#define CTRL 0x1d
#define ALT 0x38
#define CAPS_LOCK 0x3a
#define KEYBOARD_STATUS_SHIFT_L (1 << 0)
#define KEYBOARD_STATUS_SHIFT_R (1 << 1)
#define KEYBOARD_STATUS_ALT_L (1 << 2)
#define KEYBOARD_STATUS_ALT_R (1 << 3)
#define KEYBOARD_STATUS_CTRL_L (1 << 4)
#define KEYBOARD_STATUS_CTRL_R (1 << 5)
#define KEYBOARD_STATUS_CAPS_LOCK (1 << 6)
#define KEYBOARD_REG_DATA 0x60
#define KEYBOARD_REG_STATUS 0x64
#define KEYBOARD_ISMAKE(x) !((x) & 0x80)
#define KEYBOARD_ISREADY(x) (((x) & 0x01) == 0)
#define KEYBOARD_SCANCODE(x) ((x) & 0x7f)
static short at_keyboard_status = 0;
static char keyboard_map[128] =
{
'\0', '\0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '-', '=', '\b', '\t',
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', '[', ']', '\n', '\0', 'a', 's',
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
'\'', '`', '\0', '\\', 'z', 'x', 'c', 'v',
'b', 'n', 'm', ',', '.', '/', '\0', '*',
'\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '7',
'8', '9', '-', '4', '5', '6', '+', '1',
'2', '3',
};
static char keyboard_map_shift[128] =
{
'\0', '\0', '!', '@', '#', '$', '%', '^',
'&', '*', '(', ')', '_', '+', '\b', '\t',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
'O', 'P', '{', '}', '\n', '\0', 'A', 'S',
'D', 'F', 'G', 'H', 'J', 'K', 'L', ':',
'\"', '~', '\0', '|', 'Z', 'X', 'C', 'V',
'B', 'N', 'M', '<', '>', '?', '\0', '*',
'\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '7',
'8', '9', '-', '4', '5', '6', '+', '1',
'2', '3',
};
/* FIXME: This should become an interrupt service routine. For now
it's just used to catch events from control keys. */
static void
grub_keyboard_isr (char key)
{
char is_make = KEYBOARD_ISMAKE (key);
key = KEYBOARD_SCANCODE (key);
if (is_make)
switch (key)
{
case SHIFT_L:
at_keyboard_status |= KEYBOARD_STATUS_SHIFT_L;
break;
case SHIFT_R:
at_keyboard_status |= KEYBOARD_STATUS_SHIFT_R;
break;
case CTRL:
at_keyboard_status |= KEYBOARD_STATUS_CTRL_L;
break;
case ALT:
at_keyboard_status |= KEYBOARD_STATUS_ALT_L;
break;
default:
/* Skip grub_dprintf. */
return;
}
else
switch (key)
{
case SHIFT_L:
at_keyboard_status &= ~KEYBOARD_STATUS_SHIFT_L;
break;
case SHIFT_R:
at_keyboard_status &= ~KEYBOARD_STATUS_SHIFT_R;
break;
case CTRL:
at_keyboard_status &= ~KEYBOARD_STATUS_CTRL_L;
break;
case ALT:
at_keyboard_status &= ~KEYBOARD_STATUS_ALT_L;
break;
default:
/* Skip grub_dprintf. */
return;
}
grub_dprintf ("atkeyb", "Control key 0x%0x was %s\n", key, is_make ? "pressed" : "unpressed");
}
/* If there is a raw key pending, return it; otherwise return -1. */
static int
grub_keyboard_getkey ()
{
grub_uint8_t key;
if (KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS)))
return -1;
key = grub_inb (KEYBOARD_REG_DATA);
/* FIXME */ grub_keyboard_isr (key);
if (! KEYBOARD_ISMAKE (key))
return -1;
return (KEYBOARD_SCANCODE (key));
}
/* If there is a character pending, return it; otherwise return -1. */
int
grub_console_checkkey ()
{
int key;
key = grub_keyboard_getkey ();
if (key == -1)
return -1;
grub_dprintf ("atkeyb", "Detected key 0x%x\n", key);
switch (key)
{
case CAPS_LOCK:
if (at_keyboard_status & KEYBOARD_STATUS_CAPS_LOCK)
at_keyboard_status &= ~KEYBOARD_STATUS_CAPS_LOCK;
else
at_keyboard_status |= KEYBOARD_STATUS_CAPS_LOCK;
grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_CAPS_LOCK));
key = -1;
break;
default:
if (at_keyboard_status & (KEYBOARD_STATUS_SHIFT_L | KEYBOARD_STATUS_SHIFT_R))
key = keyboard_map_shift[key];
else
key = keyboard_map[key];
if (at_keyboard_status & KEYBOARD_STATUS_CAPS_LOCK)
{
if ((key >= 'a') && (key <= 'z'))
key += 'A' - 'a';
else if ((key >= 'A') && (key <= 'Z'))
key += 'a' - 'A';
}
}
return (int) key;
}
int
grub_console_getkey ()
{
int key;
do
{
key = grub_console_checkkey ();
} while (key == -1);
return key;
}

111
term/i386/pc/vga_text.c Normal file
View file

@ -0,0 +1,111 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/machine/console.h>
#include <grub/types.h>
#define COLS 80
#define ROWS 25
static int grub_curr_x, grub_curr_y;
#define VGA_TEXT_SCREEN 0xb8000
static void
screen_write_char (int x, int y, short c)
{
((short *) VGA_TEXT_SCREEN)[y * COLS + x] = c;
}
static short
screen_read_char (int x, int y)
{
return ((short *) VGA_TEXT_SCREEN)[y * COLS + x];
}
static void
inc_y ()
{
grub_curr_x = 0;
if (grub_curr_y < ROWS - 1)
grub_curr_y++;
else
{
int x, y;
for (y = 0; y < ROWS; y++)
for (x = 0; x < COLS; x++)
screen_write_char (x, y, screen_read_char (x, y + 1));
}
}
static void
inc_x ()
{
if (grub_curr_x >= COLS - 2)
inc_y ();
else
grub_curr_x++;
}
void
grub_console_real_putchar (int c)
{
switch (c)
{
case '\b':
if (grub_curr_x != 0)
screen_write_char (grub_curr_x--, grub_curr_y, ' ');
break;
case '\n':
inc_y ();
break;
case '\r':
grub_curr_x = 0;
break;
default:
screen_write_char (grub_curr_x, grub_curr_y, c | (grub_console_cur_color << 8));
inc_x ();
}
}
grub_uint16_t
grub_console_getxy ()
{
return (grub_curr_x << 8) | grub_curr_y;
}
void
grub_console_gotoxy (grub_uint8_t x, grub_uint8_t y)
{
grub_curr_x = x;
grub_curr_y = y;
}
void
grub_console_cls ()
{
int i;
for (i = 0; i < ROWS * COLS; i++)
((short *) VGA_TEXT_SCREEN)[i] = ' ';
}
void
grub_console_setcursor (int on __attribute__ ((unused)))
{
/* Not implemented. */
}