summaryrefslogtreecommitdiff
path: root/payloads/libpayload/i386
diff options
context:
space:
mode:
Diffstat (limited to 'payloads/libpayload/i386')
-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
5 files changed, 140 insertions, 3 deletions
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) {