aboutsummaryrefslogtreecommitdiffstats
path: root/grub-core/kern/i386/coreboot
diff options
context:
space:
mode:
authorJames <james.mckenzie@citrix.com>2012-11-16 10:41:01 +0000
committerJames <james.mckenzie@citrix.com>2012-11-16 10:41:01 +0000
commit041d1ea37802bf7178a31a53f96c26efa6b8fb7b (patch)
treec193e84ad1237f25a79d0f6a267722e44c73f56a /grub-core/kern/i386/coreboot
downloadgrub-1.99-041d1ea37802bf7178a31a53f96c26efa6b8fb7b.tar.gz
grub-1.99-041d1ea37802bf7178a31a53f96c26efa6b8fb7b.tar.bz2
grub-1.99-041d1ea37802bf7178a31a53f96c26efa6b8fb7b.zip
fish
Diffstat (limited to 'grub-core/kern/i386/coreboot')
-rw-r--r--grub-core/kern/i386/coreboot/init.c132
-rw-r--r--grub-core/kern/i386/coreboot/mmap.c108
-rw-r--r--grub-core/kern/i386/coreboot/startup.S89
3 files changed, 329 insertions, 0 deletions
diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c
new file mode 100644
index 0000000..434b9b5
--- /dev/null
+++ b/grub-core/kern/i386/coreboot/init.c
@@ -0,0 +1,132 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 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/memory.h>
+#include <grub/machine/console.h>
+#include <grub/offsets.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>
+#include <grub/cpu/floppy.h>
+#include <grub/cpu/tsc.h>
+#ifdef GRUB_MACHINE_QEMU
+#include <grub/machine/kernel.h>
+#endif
+
+extern char _start[];
+extern char _end[];
+
+grub_uint32_t
+grub_get_rtc (void)
+{
+ grub_fatal ("grub_get_rtc() is not implemented.\n");
+}
+
+void
+grub_exit (void)
+{
+ /* We can't use grub_fatal() in this function. This would create an infinite
+ loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */
+ while (1)
+ grub_cpu_idle ();
+}
+
+void
+grub_machine_init (void)
+{
+#ifdef GRUB_MACHINE_QEMU
+ grub_qemu_init_cirrus ();
+#endif
+ /* Initialize the console as early as possible. */
+ grub_vga_text_init ();
+
+ auto int NESTED_FUNC_ATTR heap_init (grub_uint64_t, grub_uint64_t,
+ grub_memory_type_t);
+ int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t size,
+ grub_memory_type_t type)
+ {
+#if GRUB_CPU_SIZEOF_VOID_P == 4
+ /* Restrict ourselves to 32-bit memory space. */
+ if (addr > GRUB_ULONG_MAX)
+ return 0;
+ if (addr + size > GRUB_ULONG_MAX)
+ size = GRUB_ULONG_MAX - addr;
+#endif
+
+ if (type != GRUB_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;
+ }
+ }
+
+ grub_mm_init_region ((void *) (grub_addr_t) addr, (grub_size_t) size);
+
+ return 0;
+ }
+
+#if defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_QEMU)
+ grub_machine_mmap_init ();
+#endif
+ grub_machine_mmap_iterate (heap_init);
+
+ grub_tsc_init ();
+}
+
+void
+grub_machine_set_prefix (void)
+{
+ /* Initialize the prefix. */
+ grub_env_set ("prefix", grub_prefix);
+}
+
+void
+grub_machine_fini (void)
+{
+ grub_vga_text_fini ();
+ grub_stop_floppy ();
+}
+
+/* Return the end of the core image. */
+grub_addr_t
+grub_arch_modules_addr (void)
+{
+#ifdef GRUB_MACHINE_QEMU
+ return grub_core_entry_addr + grub_kernel_image_size;
+#else
+ return ALIGN_UP((grub_addr_t) _end, GRUB_KERNEL_MACHINE_MOD_ALIGN);
+#endif
+}
diff --git a/grub-core/kern/i386/coreboot/mmap.c b/grub-core/kern/i386/coreboot/mmap.c
new file mode 100644
index 0000000..8b0b202
--- /dev/null
+++ b/grub-core/kern/i386/coreboot/mmap.c
@@ -0,0 +1,108 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007,2008 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/machine/lbio.h>
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/misc.h>
+
+static grub_err_t
+grub_linuxbios_table_iterate (int (*hook) (grub_linuxbios_table_item_t))
+{
+ grub_linuxbios_table_header_t table_header;
+ grub_linuxbios_table_item_t table_item;
+
+ auto int check_signature (grub_linuxbios_table_header_t);
+ int check_signature (grub_linuxbios_table_header_t tbl_header)
+ {
+ if (! grub_memcmp (tbl_header->signature, "LBIO", 4))
+ return 1;
+
+ return 0;
+ }
+
+ /* Assuming table_header is aligned to its size (8 bytes). */
+
+ for (table_header = (grub_linuxbios_table_header_t) 0x500;
+ table_header < (grub_linuxbios_table_header_t) 0x1000; table_header++)
+ if (check_signature (table_header))
+ goto signature_found;
+
+ for (table_header = (grub_linuxbios_table_header_t) 0xf0000;
+ table_header < (grub_linuxbios_table_header_t) 0x100000; table_header++)
+ if (check_signature (table_header))
+ goto signature_found;
+
+ grub_fatal ("Could not find coreboot table\n");
+
+signature_found:
+
+ 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 (table_item->tag == GRUB_LINUXBIOS_MEMBER_LINK
+ && check_signature ((grub_linuxbios_table_header_t) (grub_addr_t)
+ *(grub_uint64_t *) (table_item + 1)))
+ {
+ table_header = (grub_linuxbios_table_header_t) (grub_addr_t)
+ *(grub_uint64_t *) (table_item + 1);
+ goto signature_found;
+ }
+ if (hook (table_item))
+ return 1;
+ }
+
+ return 0;
+}
+
+grub_err_t
+grub_machine_mmap_iterate (grub_memory_hook_t hook)
+{
+ 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));
+ while ((long) mem_region < (long) table_item + (long) table_item->size)
+ {
+ if (hook (mem_region->addr, mem_region->size,
+ /* Multiboot mmaps match with the coreboot mmap definition.
+ Therefore, we can just pass type through. */
+ mem_region->type))
+ return 1;
+
+ mem_region++;
+ }
+
+ return 0;
+ }
+
+ grub_linuxbios_table_iterate (iterate_linuxbios_table);
+
+ return 0;
+}
diff --git a/grub-core/kern/i386/coreboot/startup.S b/grub-core/kern/i386/coreboot/startup.S
new file mode 100644
index 0000000..cac023d
--- /dev/null
+++ b/grub-core/kern/i386/coreboot/startup.S
@@ -0,0 +1,89 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008 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/symbol.h>
+/* For stack parameters. */
+#include <grub/i386/pc/memory.h>
+#include <grub/machine/memory.h>
+#include <grub/cpu/linux.h>
+#include <grub/offsets.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
+start:
+_start:
+ jmp codestart
+
+ /*
+ * This is a special data area at a fixed offset from the beginning.
+ */
+
+ . = _start + GRUB_KERNEL_MACHINE_PREFIX
+
+VARIABLE(grub_prefix)
+ /* to be filled by grub-mkimage */
+
+ /*
+ * Leave some breathing room for the prefix.
+ */
+
+ . = _start + GRUB_KERNEL_MACHINE_PREFIX_END
+
+/*
+ * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself).
+ */
+ .p2align 2 /* force 4-byte alignment */
+multiboot_header:
+ /* magic */
+ .long 0x1BADB002
+ /* flags */
+ .long MULTIBOOT_MEMORY_INFO
+ /* checksum */
+ .long -0x1BADB002 - MULTIBOOT_MEMORY_INFO
+
+codestart:
+#ifdef GRUB_MACHINE_MULTIBOOT
+ cmpl $MULTIBOOT_BOOTLOADER_MAGIC, %eax
+ jne 0f
+ movl %ebx, EXT_C(startup_multiboot_info)
+0:
+#endif
+
+ /* initialize the stack */
+ movl $GRUB_MEMORY_MACHINE_PROT_STACK, %esp
+
+ /* jump to the main body of C code */
+ jmp EXT_C(grub_main)
+
+/*
+ * prot_to_real and associated structures (but NOT real_to_prot, that is
+ * only needed for BIOS gates).
+ */
+#include "../realmode.S"
+