summaryrefslogtreecommitdiff
path: root/payloads/libpayload
diff options
context:
space:
mode:
authorJordan Crouse <jordan.crouse@amd.com>2008-10-20 16:51:43 +0000
committerJordan Crouse <jordan.crouse@amd.com>2008-10-20 16:51:43 +0000
commit20c9cf12a4a8bc2a7939e7bbf490324984f5b055 (patch)
tree3ea6c90e80780dfcdda5d35b0a426d83349a0b49 /payloads/libpayload
parent369a5f6c7a18516cb4da054d0e328f7464da9da7 (diff)
downloadcoreboot-20c9cf12a4a8bc2a7939e7bbf490324984f5b055.tar.xz
[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@amd.com> Acked-by: Peter Stuge <peter@stuge.se> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3673 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'payloads/libpayload')
-rw-r--r--payloads/libpayload/Config.in8
-rw-r--r--payloads/libpayload/Makefile5
-rw-r--r--payloads/libpayload/i386/Makefile.inc2
-rw-r--r--payloads/libpayload/i386/head.S21
-rw-r--r--payloads/libpayload/i386/main.c13
-rw-r--r--payloads/libpayload/i386/multiboot.c96
-rw-r--r--payloads/libpayload/i386/sysinfo.c11
-rw-r--r--payloads/libpayload/include/libpayload.h3
-rw-r--r--payloads/libpayload/include/multiboot_tables.h76
-rw-r--r--payloads/libpayload/lib/libpayload.ldscript2
10 files changed, 234 insertions, 3 deletions
diff --git a/payloads/libpayload/Config.in b/payloads/libpayload/Config.in
index 572e14f6b4..55f09f7b2d 100644
--- a/payloads/libpayload/Config.in
+++ b/payloads/libpayload/Config.in
@@ -35,6 +35,14 @@ config TARGET_I386
bool
default y
+menu "Architecture Options"
+
+config MULTIBOOT
+ bool "Multiboot header support"
+ default y
+
+endmenu
+
menu "Standard Libraries"
config LIBC
diff --git a/payloads/libpayload/Makefile b/payloads/libpayload/Makefile
index a52054cd63..57f6bd8bcd 100644
--- a/payloads/libpayload/Makefile
+++ b/payloads/libpayload/Makefile
@@ -76,6 +76,11 @@ TARGETS-y :=
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))
diff --git a/payloads/libpayload/i386/Makefile.inc b/payloads/libpayload/i386/Makefile.inc
index bb6bcb5a11..40d2699062 100644
--- a/payloads/libpayload/i386/Makefile.inc
+++ b/payloads/libpayload/i386/Makefile.inc
@@ -31,3 +31,5 @@ TARGETS-y += i386/head.S.o i386/main.o i386/sysinfo.o
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
diff --git a/payloads/libpayload/i386/head.S b/payloads/libpayload/i386/head.S
index 54f60e1469..db18a5195f 100644
--- a/payloads/libpayload/i386/head.S
+++ b/payloads/libpayload/i386/head.S
@@ -27,6 +27,7 @@
* SUCH DAMAGE.
*/
+ .code32
.global _entry, _leave
.text
.align 4
@@ -42,6 +43,21 @@ _entry:
/* 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 @@ _init:
/* 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
diff --git a/payloads/libpayload/i386/main.c b/payloads/libpayload/i386/main.c
index 25e4de46d7..48d6ef5495 100644
--- a/payloads/libpayload/i386/main.c
+++ b/payloads/libpayload/i386/main.c
@@ -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,7 +60,8 @@ void start_main(void)
* 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
diff --git a/payloads/libpayload/i386/multiboot.c b/payloads/libpayload/i386/multiboot.c
new file mode 100644
index 0000000000..09e72c768b
--- /dev/null
+++ b/payloads/libpayload/i386/multiboot.c
@@ -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;
+}
diff --git a/payloads/libpayload/i386/sysinfo.c b/payloads/libpayload/i386/sysinfo.c
index a845a2817b..a074361f4f 100644
--- a/payloads/libpayload/i386/sysinfo.c
+++ b/payloads/libpayload/i386/sysinfo.c
@@ -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 @@ void lib_get_sysinfo(void)
/* 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) {
diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h
index 060e6b1919..dd7fe9a29c 100644
--- a/payloads/libpayload/include/libpayload.h
+++ b/payloads/libpayload/include/libpayload.h
@@ -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 lfclose(struct LFILE *file);
* @{
*/
int get_coreboot_info(struct sysinfo_t *info);
+int get_multiboot_info(struct sysinfo_t *info);
void lib_get_sysinfo(void);
diff --git a/payloads/libpayload/include/multiboot_tables.h b/payloads/libpayload/include/multiboot_tables.h
new file mode 100644
index 0000000000..ac27f8a766
--- /dev/null
+++ b/payloads/libpayload/include/multiboot_tables.h
@@ -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
diff --git a/payloads/libpayload/lib/libpayload.ldscript b/payloads/libpayload/lib/libpayload.ldscript
index 400c1377a5..c2208cffd3 100644
--- a/payloads/libpayload/lib/libpayload.ldscript
+++ b/payloads/libpayload/lib/libpayload.ldscript
@@ -60,6 +60,8 @@ SECTIONS
*(.data.*)
}
+ _edata = .;
+
.bss : {
*(.bss)
*(.bss.*)