[coreboot] r3673 - in trunk/payloads/libpayload: . i386 include lib

svn at coreboot.org svn at coreboot.org
Mon Oct 20 18:51:43 CEST 2008


Author: jcrouse
Date: 2008-10-20 18:51:43 +0200 (Mon, 20 Oct 2008)
New Revision: 3673

Added:
   trunk/payloads/libpayload/i386/multiboot.c
   trunk/payloads/libpayload/include/multiboot_tables.h
Modified:
   trunk/payloads/libpayload/Config.in
   trunk/payloads/libpayload/Makefile
   trunk/payloads/libpayload/i386/Makefile.inc
   trunk/payloads/libpayload/i386/head.S
   trunk/payloads/libpayload/i386/main.c
   trunk/payloads/libpayload/i386/sysinfo.c
   trunk/payloads/libpayload/include/libpayload.h
   trunk/payloads/libpayload/lib/libpayload.ldscript
Log:
[PATCH] libpayload:  Add multiboot support

Make libpayload applications multiboot compatible.  Add the
multiboot OS table and grok the loader table, especially the
memory map and the command line.  This makes libpayload 
applications loadable by GRUB.

Signed-off-by: Jordan Crouse <jordan.crouse at amd.com>
Acked-by: Peter Stuge <peter at stuge.se>


Modified: trunk/payloads/libpayload/Config.in
===================================================================
--- trunk/payloads/libpayload/Config.in	2008-10-20 16:51:20 UTC (rev 3672)
+++ trunk/payloads/libpayload/Config.in	2008-10-20 16:51:43 UTC (rev 3673)
@@ -35,6 +35,14 @@
 	bool
 	default y
 
+menu "Architecture Options"
+
+config MULTIBOOT
+	bool "Multiboot header support"
+	default y
+
+endmenu
+
 menu "Standard Libraries"
 
 config LIBC

Modified: trunk/payloads/libpayload/Makefile
===================================================================
--- trunk/payloads/libpayload/Makefile	2008-10-20 16:51:20 UTC (rev 3672)
+++ trunk/payloads/libpayload/Makefile	2008-10-20 16:51:43 UTC (rev 3673)
@@ -76,6 +76,11 @@
 BUILD-y := crypto/Makefile.inc libc/Makefile.inc drivers/Makefile.inc
 BUILD-$(CONFIG_TINYCURSES) += curses/Makefile.inc
 
+# The primary target needs to be here before we include the
+# other files
+
+all: lib
+
 include $(PLATFORM-y) $(BUILD-y)
 
 OBJS     := $(patsubst %,$(obj)/%,$(TARGETS-y))

Modified: trunk/payloads/libpayload/i386/Makefile.inc
===================================================================
--- trunk/payloads/libpayload/i386/Makefile.inc	2008-10-20 16:51:20 UTC (rev 3672)
+++ trunk/payloads/libpayload/i386/Makefile.inc	2008-10-20 16:51:43 UTC (rev 3673)
@@ -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

Modified: trunk/payloads/libpayload/i386/head.S
===================================================================
--- trunk/payloads/libpayload/i386/head.S	2008-10-20 16:51:20 UTC (rev 3672)
+++ trunk/payloads/libpayload/i386/head.S	2008-10-20 16:51:43 UTC (rev 3673)
@@ -27,6 +27,7 @@
  * SUCH DAMAGE.
  */
 
+	.code32
 	.global _entry, _leave
 	.text
 	.align 4
@@ -42,6 +43,21 @@
 	/* We're back - go back to the bootloader. */
 	ret
 
+	.align 4
+
+#define MB_MAGIC 0x1BADB002
+#define MB_FLAGS 0x00010003
+
+mb_header:
+	.long MB_MAGIC
+	.long MB_FLAGS
+	.long -(MB_MAGIC + MB_FLAGS)
+	.long mb_header
+	.long _start
+	.long _edata
+	.long _end
+	.long _init
+
 /*
  * This function saves off the previous stack and switches us to our
  * own execution environment.
@@ -53,6 +69,11 @@
 	/* Store current stack pointer. */
 	movl %esp, %esi
 
+	/* Store EAX and EBX */
+
+	movl %eax,loader_eax
+	movl %ebx,loader_ebx
+
 	/* Setup new stack. */
 	movl $_stack, %ebx
 

Modified: trunk/payloads/libpayload/i386/main.c
===================================================================
--- trunk/payloads/libpayload/i386/main.c	2008-10-20 16:51:20 UTC (rev 3672)
+++ trunk/payloads/libpayload/i386/main.c	2008-10-20 16:51:43 UTC (rev 3673)
@@ -29,13 +29,21 @@
 
 #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 */
+
+unsigned int main_argc;    /**< The argc value to pass to main() */
+
+/** The argv value to pass to main() */
+char *main_argv[MAX_ARGC_COUNT];
+
 /**
  * This is our C entry function - set up the system
  * and jump into the payload entry point.
  */
 void start_main(void)
 {
-	extern int main(void);
+	extern int main(int argc, char **argv);
 
 	/* Set up the consoles. */
 	console_init();
@@ -52,8 +60,9 @@
 	 * Go to the entry point.
 	 * In the future we may care about the return value.
 	 */
-	(void) main();
 
+	(void) main(main_argc, (main_argc != 0) ? main_argv : NULL);
+
 	/*
 	 * Returning here will go to the _leave function to return
 	 * us to the original context.

Added: trunk/payloads/libpayload/i386/multiboot.c
===================================================================
--- trunk/payloads/libpayload/i386/multiboot.c	                        (rev 0)
+++ trunk/payloads/libpayload/i386/multiboot.c	2008-10-20 16:51:43 UTC (rev 3673)
@@ -0,0 +1,96 @@
+/*
+ * 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));
+	}
+}
+
+static void mb_parse_cmdline(struct multiboot_header *table)
+{
+	extern int main_argc;
+	extern char *main_argv[];
+	char *c = phys_to_virt(table->cmdline);
+
+	while(*c != '\0' && main_argc < MAX_ARGC_COUNT) {
+		main_argv[main_argc++] = c;
+
+		for( ; *c != '\0' && !isspace(*c); c++);
+
+		if (*c) {
+			*c = 0;
+			c++;
+		}
+	}
+}
+
+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);
+
+	if (table->flags & MULTIBOOT_FLAGS_CMDLINE)
+		mb_parse_cmdline(table);
+
+	return 0;
+}

Modified: trunk/payloads/libpayload/i386/sysinfo.c
===================================================================
--- trunk/payloads/libpayload/i386/sysinfo.c	2008-10-20 16:51:20 UTC (rev 3672)
+++ trunk/payloads/libpayload/i386/sysinfo.c	2008-10-20 16:51:43 UTC (rev 3673)
@@ -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) {

Modified: trunk/payloads/libpayload/include/libpayload.h
===================================================================
--- trunk/payloads/libpayload/include/libpayload.h	2008-10-20 16:51:20 UTC (rev 3672)
+++ trunk/payloads/libpayload/include/libpayload.h	2008-10-20 16:51:43 UTC (rev 3673)
@@ -64,6 +64,8 @@
 
 #define RAND_MAX 0x7fffffff
 
+#define MAX_ARGC_COUNT 10
+
 /*
  * Payload information parameters - these are used to pass information
  * to the entity loading the payload.
@@ -407,6 +409,7 @@
  * @{
  */
 int get_coreboot_info(struct sysinfo_t *info);
+int get_multiboot_info(struct sysinfo_t *info);
 
 void lib_get_sysinfo(void);
 

Added: trunk/payloads/libpayload/include/multiboot_tables.h
===================================================================
--- trunk/payloads/libpayload/include/multiboot_tables.h	                        (rev 0)
+++ trunk/payloads/libpayload/include/multiboot_tables.h	2008-10-20 16:51:43 UTC (rev 3673)
@@ -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)
+#define MULTIBOOT_FLAGS_CMDLINE (1 << 2)
+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

Modified: trunk/payloads/libpayload/lib/libpayload.ldscript
===================================================================
--- trunk/payloads/libpayload/lib/libpayload.ldscript	2008-10-20 16:51:20 UTC (rev 3672)
+++ trunk/payloads/libpayload/lib/libpayload.ldscript	2008-10-20 16:51:43 UTC (rev 3673)
@@ -60,6 +60,8 @@
 		*(.data.*)
 	}
 
+	_edata = .;
+
 	.bss : {
 		*(.bss)
 		*(.bss.*)





More information about the coreboot mailing list