This is a simple patch to parse and read the multiboot table
in libpayload.  It doesn't do much more then read the memory
map for now, but the important thing is that we are storing off
%eax and %ebx in the init code and using it when we need it.

The next step is probably an API where upon a multiboot aware
payload could insert new things into the table (say, the drive
structure, or the cmdline or other interesting information), and then
pass it to a child payload.

I'm not sure what else we would need to do to libpayload so that
grub will load the payloads, but I'm sure Robert will enlighten us.

Jordan
-- 
Jordan Crouse
Systems Software Development Engineer 
Advanced Micro Devices, Inc.
libpayload:  Add support for reading the multiboot tables

Support reading the multiboot tables, and the goodness within.
Right now we are only reading the memory map, but more options
will no doubt come later.

Signed-off-by: Jordan Crouse <[EMAIL PROTECTED]>
Index: libpayload/Config.in
===================================================================
--- libpayload.orig/Config.in	2008-09-25 11:46:59.000000000 -0600
+++ libpayload/Config.in	2008-09-25 11:47:29.000000000 -0600
@@ -35,6 +35,14 @@
 	bool
 	default y
 
+menu "Architecture Options"
+
+config MULTIBOOT
+	bool "Multiboot header support"
+	default y
+
+endmenu
+
 menu "Standard Libraries"
 
 config LIBC
Index: libpayload/i386/Makefile.inc
===================================================================
--- libpayload.orig/i386/Makefile.inc	2008-09-25 11:46:59.000000000 -0600
+++ libpayload/i386/Makefile.inc	2008-09-25 11:47:29.000000000 -0600
@@ -31,3 +31,5 @@
 TARGETS-y += i386/timer.o i386/coreboot.o i386/util.S.o
 TARGETS-y += i386/exec.S.o i386/virtual.o
 
+# Multiboot support is configurable
+TARGETS-$(CONFIG_MULTIBOOT) += i386/multiboot.o
Index: libpayload/i386/head.S
===================================================================
--- libpayload.orig/i386/head.S	2008-09-25 11:46:59.000000000 -0600
+++ libpayload/i386/head.S	2008-09-25 11:47:29.000000000 -0600
@@ -53,6 +53,13 @@
 	/* Store current stack pointer. */
 	movl %esp, %esi
 
+	/* Store EAX and EBX for possible use by
+	   multiboot
+	*/
+
+	movl %eax,loader_eax
+	movl %ebx,loader_ebx
+
 	/* Setup new stack. */
 	movl $_stack, %ebx
 
Index: libpayload/i386/main.c
===================================================================
--- libpayload.orig/i386/main.c	2008-09-25 11:46:59.000000000 -0600
+++ libpayload/i386/main.c	2008-09-25 11:47:52.000000000 -0600
@@ -29,6 +29,9 @@
 
 #include <libpayload.h>
 
+unsigned long loader_eax;  /**< The value of EAX passed from the loader */
+unsigned long loader_ebx;  /**< The value of EBX passed from the loader */
+
 /**
  * This is our C entry function - set up the system
  * and jump into the payload entry point.
Index: libpayload/i386/multiboot.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ libpayload/i386/multiboot.c	2008-09-25 11:48:34.000000000 -0600
@@ -0,0 +1,75 @@
+/*
+ * This file is part of the libpayload project.
+ *
+ * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <config.h>
+#include <libpayload.h>
+#include <multiboot_tables.h>
+
+extern unsigned long loader_eax;
+extern unsigned long loader_ebx;
+
+static void mb_parse_mmap(struct multiboot_header *table,
+			struct sysinfo_t *info)
+{
+	u8 *start = (u8 *) phys_to_virt(table->mmap_addr);
+	u8 *ptr = start;
+
+	info->n_memranges = 0;
+
+	while(ptr < (start + table->mmap_length)) {
+		struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr;
+
+		/* 1 == normal RAM.  Ignore everything else for now */
+
+		if (mmap->type == 1) {
+			info->memrange[info->n_memranges].base = mmap->addr;
+			info->memrange[info->n_memranges].size = mmap->length;
+
+			if (++info->n_memranges == SYSINFO_MAX_MEM_RANGES)
+				return;
+		}
+
+		ptr += (mmap->size + sizeof(mmap->size));
+	}
+}
+
+int get_multiboot_info(struct sysinfo_t *info)
+{
+	struct multiboot_header *table;
+
+	if (loader_eax != MULTIBOOT_MAGIC)
+		return -1;
+
+	table = (struct multiboot_header *) phys_to_virt(loader_ebx);
+
+	if (table->flags & MULTIBOOT_FLAGS_MMAP)
+		mb_parse_mmap(table, info);
+
+	return 0;
+}
Index: libpayload/i386/sysinfo.c
===================================================================
--- libpayload.orig/i386/sysinfo.c	2008-09-25 11:46:59.000000000 -0600
+++ libpayload/i386/sysinfo.c	2008-09-25 11:49:18.000000000 -0600
@@ -29,6 +29,7 @@
 
 #include <config.h>
 #include <libpayload.h>
+#include <multiboot_tables.h>
 
 /**
  * This is a global structure that is used through the library - we set it
@@ -48,7 +49,15 @@
 	/* Get the CPU speed (for delays). */
 	lib_sysinfo.cpu_khz = get_cpu_speed();
 
-	/* Get the memory information. */
+#ifdef CONFIG_MULTIBOOT
+	/* Get the information from the multiboot tables,
+	 * if they exist */
+	get_multiboot_info(&lib_sysinfo);
+#endif
+
+	/* Get information from the coreboot tables,
+	 * if they exist */
+
 	get_coreboot_info(&lib_sysinfo);
 
 	if (!lib_sysinfo.n_memranges) {
Index: libpayload/include/multiboot_tables.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ libpayload/include/multiboot_tables.h	2008-09-25 11:47:29.000000000 -0600
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the libpayload project.
+ *
+ * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef MULTIBOOT_TABLES_H_
+#define MULTIBOOT_TABLES_H_
+
+#include <arch/types.h>
+
+#define MULTIBOOT_MAGIC      0x2BADB002UL
+#define MULTIBOOT_FLAGS_MMAP (1 << 6)
+
+struct multiboot_header {
+	u32 flags;
+	u32 mem_lower;
+	u32 mem_higher;
+	u32 boot_device;
+	u32 cmdline;
+	u32 mods_count;
+	u32 mods_addr;
+
+	u32 syms[4];
+
+	u32 mmap_length;
+	u32 mmap_addr;
+
+	u32 drives_length;
+	u32 drives_addr;
+
+	u32 config_table;
+
+	u32 boot_loader_name;
+
+	u32 apm_table;
+
+	u32 vbe_control_info;
+	u32 vbe_mode_info;
+	u32 vbe_mode;
+	u32 vbe_interface_seg;
+	u32 vbe_interface_off;
+	u32 vbe_interface_len;
+};
+
+struct multiboot_mmap {
+	u32 size;
+	u64 addr;
+	u64 length;
+	u32 type;
+} __attribute((packed));
+
+#endif
Index: libpayload/include/libpayload.h
===================================================================
--- libpayload.orig/include/libpayload.h	2008-09-25 11:46:59.000000000 -0600
+++ libpayload/include/libpayload.h	2008-09-25 11:47:29.000000000 -0600
@@ -391,6 +391,7 @@
  * @{
  */
 int get_coreboot_info(struct sysinfo_t *info);
+int get_multiboot_info(struct sysinfo_t *info);
 
 void lib_get_sysinfo(void);
 
--
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to