From 835af7ef6a851ff2aea5773fb968926e307d240f Mon Sep 17 00:00:00 2001 From: "Zheng, Gen" Date: Fri, 30 Mar 2018 12:31:35 +0800 Subject: [PATCH] UEFI: change the efi_ctx passing method Save the pointer of efi_ctx in mi_drivers_addr field of multiboot structure and pass to hypervisor, not by saving in register RDX(the third default parameter in 64bit call function). With this method, we can be compatible with the original 32bit boot parameters passing method and no need to large the array size of boot_regs in hypervisor. Signed-off-by: Zheng, Gen --- arch/x86/cpu_primary.S | 6 ------ bsp/uefi/efi/boot.c | 7 +++++-- bsp/uefi/uefi.c | 16 +++++++++++++--- include/arch/x86/multiboot.h | 1 + 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/arch/x86/cpu_primary.S b/arch/x86/cpu_primary.S index 0c54e2e6d..066bac0fe 100644 --- a/arch/x86/cpu_primary.S +++ b/arch/x86/cpu_primary.S @@ -118,9 +118,6 @@ cpu_primary_start_64: /* save the MULTBOOT magic number & MBI */ movl %edi, (boot_regs) movl %esi, (boot_regs+4) -#ifdef CONFIG_EFI_STUB - movl %edx, (boot_regs+8) -#endif primary_start_long_mode: @@ -187,9 +184,6 @@ loop: boot_regs: .long 0x00000000 .long 0x00000000 -#ifdef CONFIG_EFI_STUB - .long 0x00000000 -#endif /* GDT table */ .align 4 diff --git a/bsp/uefi/efi/boot.c b/bsp/uefi/efi/boot.c index 4a4f9f59c..4500de85d 100644 --- a/bsp/uefi/efi/boot.c +++ b/bsp/uefi/efi/boot.c @@ -155,7 +155,7 @@ struct acpi_table_header { UINT32 asl_compiler_revision; /* ASL compiler version */ }; -typedef void(*hv_func)(int, struct multiboot_info*, struct efi_ctx*); +typedef void(*hv_func)(int, struct multiboot_info*); EFI_IMAGE_ENTRY_POINT get_pe_entry(CHAR8 *base); static inline void hv_jump(EFI_PHYSICAL_ADDRESS hv_start, @@ -177,7 +177,7 @@ static inline void hv_jump(EFI_PHYSICAL_ADDRESS hv_start, asm volatile ("cli"); /* jump to acrn hypervisor */ - hf(MULTIBOOT_INFO_MAGIC, mbi, efi_ctx); + hf(MULTIBOOT_INFO_MAGIC, mbi); } EFI_STATUS get_path(CHAR16* name, EFI_LOADED_IMAGE *info, EFI_DEVICE_PATH **path) @@ -410,6 +410,9 @@ again: mbi->mi_cmdline = (UINTN)"uart=disabled"; mbi->mi_mmap_addr = (UINTN)mmap; + mbi->mi_flags |= MULTIBOOT_INFO_HAS_DRIVES; + mbi->mi_drives_addr = (UINT32)(UINTN)efi_ctx; + efi_ctx->rsdp = rsdp; //Print(L"start 9!\n"); diff --git a/bsp/uefi/uefi.c b/bsp/uefi/uefi.c index b12f80fc4..e0b13d242 100644 --- a/bsp/uefi/uefi.c +++ b/bsp/uefi/uefi.c @@ -138,7 +138,7 @@ int uefi_sw_loader(struct vm *vm, struct vcpu *vcpu) vlapic_restore(vcpu->arch_vcpu.vlapic, &uefi_lapic_regs); - vcpu->entry_addr = efi_ctx->rip; + vcpu->entry_addr = (void *)efi_ctx->rip; cur_context->guest_cpu_regs.regs.rax = efi_ctx->rax; cur_context->guest_cpu_regs.regs.rbx = efi_ctx->rbx; cur_context->guest_cpu_regs.regs.rdx = efi_ctx->rcx; @@ -171,8 +171,18 @@ void *get_rsdp_from_uefi(void) static void efi_init(void) { - efi_ctx = (struct efi_ctx *)(uint64_t)(uint32_t)boot_regs[2]; - ASSERT(efi_ctx != NULL, ""); + struct multiboot_info *mbi = NULL; + + if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) + ASSERT(0, "no multiboot info found"); + + mbi = (struct multiboot_info *)((uint64_t)(uint32_t)boot_regs[1]); + + if (!(mbi->mi_flags & MULTIBOOT_INFO_HAS_DRIVES)) + ASSERT(0, "no multiboot drivers for uefi found"); + + efi_ctx = (struct efi_ctx *)(uint64_t)mbi->mi_drives_addr; + ASSERT(efi_ctx != NULL, "no uefi context found"); vm_sw_loader = uefi_sw_loader; diff --git a/include/arch/x86/multiboot.h b/include/arch/x86/multiboot.h index 0792866a6..64ed9ed8f 100644 --- a/include/arch/x86/multiboot.h +++ b/include/arch/x86/multiboot.h @@ -34,6 +34,7 @@ #define MULTIBOOT_INFO_MAGIC 0x2BADB002 #define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004 #define MULTIBOOT_INFO_HAS_MODS 0x00000008 +#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080 struct multiboot_info { uint32_t mi_flags;