[PATCH kvm-unit-tests 08/15] x86: import initrd

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If an initrd is provided on the qemu command line, then set a
pointer to it during setup.

Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 x86/Makefile.common |  1 +
 lib/x86/setup.c     | 31 +++++++++++++++++++++++++++++++
 x86/cstart.S        |  2 ++
 x86/cstart64.S      |  6 ++++--
 4 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 lib/x86/setup.c

diff --git a/x86/Makefile.common b/x86/Makefile.common
index 1dad18ba26e1..fbab82c85c00 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -4,6 +4,7 @@ all: test_cases
 
 cflatobjs += lib/pci.o
 cflatobjs += lib/pci-edu.o
+cflatobjs += lib/x86/setup.o
 cflatobjs += lib/x86/io.o
 cflatobjs += lib/x86/smp.o
 cflatobjs += lib/x86/vm.o
diff --git a/lib/x86/setup.c b/lib/x86/setup.c
new file mode 100644
index 000000000000..e5df6ce95b64
--- /dev/null
+++ b/lib/x86/setup.c
@@ -0,0 +1,31 @@
+/*
+ * Initialize machine setup information
+ *
+ * Copyright (C) 2017, Red Hat Inc, Andrew Jones <drjones@xxxxxxxxxx>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include "libcflat.h"
+
+#define MBI_MODS_COUNT	20
+#define MBI_MODS_ADDR	24
+#define MB_MOD_START	 0
+#define MB_MOD_END	 4
+
+char *initrd;
+u32 initrd_size;
+
+void setup_get_initrd(u8 *bootinfo)
+{
+	u32 *mods_addr, *mod_start, *mod_end;
+
+	if (*((u32 *)&bootinfo[MBI_MODS_COUNT]) != 1)
+		return;
+
+	mods_addr = (u32 *)&bootinfo[MBI_MODS_ADDR];
+	mod_start = (u32 *)(ulong)(*mods_addr + MB_MOD_START);
+	mod_end = (u32 *)(ulong)(*mods_addr + MB_MOD_END);
+
+	initrd = (char *)(ulong)*mod_start;
+	initrd_size = *mod_end - *mod_start;
+}
diff --git a/x86/cstart.S b/x86/cstart.S
index 3dc8e710925a..7ab99cd20b7f 100644
--- a/x86/cstart.S
+++ b/x86/cstart.S
@@ -94,6 +94,8 @@ MSR_GS_BASE = 0xc0000101
 
 .globl start
 start:
+        push %ebx
+        call setup_get_initrd
         mov mb_cmdline(%ebx), %eax
         mov %eax, __args
         call __setup_args
diff --git a/x86/cstart64.S b/x86/cstart64.S
index 0240507519cd..1c5182043703 100644
--- a/x86/cstart64.S
+++ b/x86/cstart64.S
@@ -197,8 +197,10 @@ start64:
 	call enable_apic
 	call smp_init
 	call enable_x2apic
-	mov mb_boot_info(%rip), %rax
-	mov mb_cmdline(%rax), %eax
+	mov mb_boot_info(%rip), %rbx
+	mov %rbx, %rdi
+	call setup_get_initrd
+	mov mb_cmdline(%rbx), %eax
 	mov %rax, __args(%rip)
 	call __setup_args
 	mov __argc(%rip), %edi
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux