From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Jones Subject: [PATCH kvm-unit-tests 08/15] x86: import initrd Date: Fri, 13 Jan 2017 19:15:26 +0100 Message-ID: <20170113181533.15145-9-drjones@redhat.com> References: <20170113181533.15145-1-drjones@redhat.com> Cc: rkrcmar@redhat.com, pbonzini@redhat.com, lvivier@redhat.com, thuth@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:36974 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751104AbdAMSPs (ORCPT ); Fri, 13 Jan 2017 13:15:48 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B5E0E4DB15 for ; Fri, 13 Jan 2017 18:15:49 +0000 (UTC) In-Reply-To: <20170113181533.15145-1-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: If an initrd is provided on the qemu command line, then set a pointer to it during setup. Signed-off-by: Andrew Jones --- 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 + * + * 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