From: Paolo Bonzini Subject: [PATCH kvm-unit-tests 06/18] x86: prepare for extending setup.c Date: Tue, 24 Oct 2017 17:21:33 +0200 Message-ID: <20171024152145.28456-7-pbonzini@redhat.com> References: <20171024152145.28456-1-pbonzini@redhat.com> Cc: drjones@redhat.com, david@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mail-wm0-f67.google.com ([74.125.82.67]:49110 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932434AbdJXPV5 (ORCPT ); Tue, 24 Oct 2017 11:21:57 -0400 Received: by mail-wm0-f67.google.com with SMTP id p75so16442972wmg.3 for ; Tue, 24 Oct 2017 08:21:56 -0700 (PDT) In-Reply-To: <20171024152145.28456-1-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Rename setup_get_initrd to setup_multiboot as we will get memory map information from there, and since we are at it setup_environ to setup_libcflat. Use C structs for multiboot information instead of offsets. Signed-off-by: Paolo Bonzini --- lib/x86/setup.c | 45 ++++++++++++++++++++++++++++++++------------- x86/cstart.S | 4 ++-- x86/cstart64.S | 4 ++-- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/x86/setup.c b/lib/x86/setup.c index 804ba3a..22257a7 100644 --- a/lib/x86/setup.c +++ b/lib/x86/setup.c @@ -6,11 +6,32 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ #include "libcflat.h" +#include "fwcfg.h" +#include "alloc_phys.h" -#define MBI_MODS_COUNT 20 -#define MBI_MODS_ADDR 24 -#define MB_MOD_START 0 -#define MB_MOD_END 4 +extern char edata; + +struct mbi_bootinfo { + u32 flags; + u32 mem_lower; + u32 mem_upper; + u32 boot_device; + u32 cmdline; + u32 mods_count; + u32 mods_addr; + u32 reserved[5]; /* 28-47 */ + u32 mmap_addr; + u32 reserved0[3]; /* 52-63 */ + u32 bootloader; + u32 reserved1[5]; /* 68-87 */ + u32 size; +}; + +struct mbi_module { + u32 start, end; + u32 cmdline; + u32 unused; +}; #define ENV_SIZE 16384 @@ -21,22 +42,20 @@ u32 initrd_size; static char env[ENV_SIZE]; -void setup_get_initrd(u8 *bootinfo) +void setup_multiboot(struct mbi_bootinfo *bootinfo) { - u32 *mods_addr, *mod_start, *mod_end; + struct mbi_module *mods; - if (*((u32 *)&bootinfo[MBI_MODS_COUNT]) != 1) + if (bootinfo->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); + mods = (struct mbi_module *)(uintptr_t) bootinfo->mods_addr; - initrd = (char *)(ulong)*mod_start; - initrd_size = *mod_end - *mod_start; + initrd = (char *)(uintptr_t) mods->start; + initrd_size = mods->end - mods->start; } -void setup_environ(void) +void setup_libcflat(void) { if (initrd) { /* environ is currently the only file in the initrd */ diff --git a/x86/cstart.S b/x86/cstart.S index a3c26a4..143317e 100644 --- a/x86/cstart.S +++ b/x86/cstart.S @@ -95,8 +95,8 @@ MSR_GS_BASE = 0xc0000101 .globl start start: push %ebx - call setup_get_initrd - call setup_environ + call setup_multiboot + call setup_libcflat mov mb_cmdline(%ebx), %eax mov %eax, __args call __setup_args diff --git a/x86/cstart64.S b/x86/cstart64.S index 8e4a1f3..21db10f 100644 --- a/x86/cstart64.S +++ b/x86/cstart64.S @@ -227,8 +227,8 @@ start64: call enable_x2apic mov mb_boot_info(%rip), %rbx mov %rbx, %rdi - call setup_get_initrd - call setup_environ + call setup_multiboot + call setup_libcflat mov mb_cmdline(%rbx), %eax mov %rax, __args(%rip) call __setup_args -- 2.14.2