From 69522dc86164d73825f1e3b8847450e1ce5fc2dd Mon Sep 17 00:00:00 2001 From: Binbin Wu Date: Mon, 13 Aug 2018 00:21:51 +0800 Subject: [PATCH] hv: move boot_ctx offset definitions Move the definitions of offset of fields in boot_ctx to the same header file that the struct boot_ctx is in, to reduce the possibility that some modification would make the offset inconsistant with the fields within the structure. Signed-off-by: Binbin Wu Acked-by: Eddie Dong --- hypervisor/arch/x86/cpu_save_boot_ctx.S | 17 +------- hypervisor/include/arch/x86/guest/vm0_boot.h | 44 +++++++++++++++++--- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/hypervisor/arch/x86/cpu_save_boot_ctx.S b/hypervisor/arch/x86/cpu_save_boot_ctx.S index c7b7be227..8e36c005a 100644 --- a/hypervisor/arch/x86/cpu_save_boot_ctx.S +++ b/hypervisor/arch/x86/cpu_save_boot_ctx.S @@ -4,22 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#define BOOT_CTX_CR0_OFFSET 0 -#define BOOT_CTX_CR3_OFFSET 8 -#define BOOT_CTX_CR4_OFFSET 16 -#define BOOT_CTX_IDT_OFFSET 24 -#define BOOT_CTX_GDT_OFFSET 34 -#define BOOT_CTX_LDT_SEL_OFFSET 44 -#define BOOT_CTX_TR_SEL_OFFSET 46 -#define BOOT_CTX_CS_SEL_OFFSET 48 -#define BOOT_CTX_SS_SEL_OFFSET 50 -#define BOOT_CTX_DS_SEL_OFFSET 52 -#define BOOT_CTX_ES_SEL_OFFSET 54 -#define BOOT_CTX_FS_SEL_OFFSET 56 -#define BOOT_CTX_GS_SEL_OFFSET 58 -#define BOOT_CTX_CS_AR_OFFSET 60 -#define BOOT_CTX_EFER_LOW_OFFSET 64 -#define BOOT_CTX_EFER_HIGH_OFFSET 68 +#include .section entry, "ax" .align 8 diff --git a/hypervisor/include/arch/x86/guest/vm0_boot.h b/hypervisor/include/arch/x86/guest/vm0_boot.h index aeace4338..b7e149be4 100644 --- a/hypervisor/include/arch/x86/guest/vm0_boot.h +++ b/hypervisor/include/arch/x86/guest/vm0_boot.h @@ -7,20 +7,54 @@ #ifndef VM0_BOOT_H #define VM0_BOOT_H +#ifdef ASSEMBLER +#define BOOT_CTX_CR0_OFFSET 0 +#define BOOT_CTX_CR3_OFFSET 8 +#define BOOT_CTX_CR4_OFFSET 16 +#define BOOT_CTX_IDT_OFFSET 24 +#define BOOT_CTX_GDT_OFFSET 34 +#define BOOT_CTX_LDT_SEL_OFFSET 44 +#define BOOT_CTX_TR_SEL_OFFSET 46 +#define BOOT_CTX_CS_SEL_OFFSET 48 +#define BOOT_CTX_SS_SEL_OFFSET 50 +#define BOOT_CTX_DS_SEL_OFFSET 52 +#define BOOT_CTX_ES_SEL_OFFSET 54 +#define BOOT_CTX_FS_SEL_OFFSET 56 +#define BOOT_CTX_GS_SEL_OFFSET 58 +#define BOOT_CTX_CS_AR_OFFSET 60 +#define BOOT_CTX_EFER_LOW_OFFSET 64 +#define BOOT_CTX_EFER_HIGH_OFFSET 68 +#else #include +#define BOOT_CTX_CR0_OFFSET 0U +#define BOOT_CTX_CR3_OFFSET 8U +#define BOOT_CTX_CR4_OFFSET 16U +#define BOOT_CTX_IDT_OFFSET 24U +#define BOOT_CTX_GDT_OFFSET 34U +#define BOOT_CTX_LDT_SEL_OFFSET 44U +#define BOOT_CTX_TR_SEL_OFFSET 46U +#define BOOT_CTX_CS_SEL_OFFSET 48U +#define BOOT_CTX_SS_SEL_OFFSET 50U +#define BOOT_CTX_DS_SEL_OFFSET 52U +#define BOOT_CTX_ES_SEL_OFFSET 54U +#define BOOT_CTX_FS_SEL_OFFSET 56U +#define BOOT_CTX_GS_SEL_OFFSET 58U +#define BOOT_CTX_CS_AR_OFFSET 60U +#define BOOT_CTX_EFER_LOW_OFFSET 64U +#define BOOT_CTX_EFER_HIGH_OFFSET 68U -typedef struct { +struct dt_addr { uint16_t limit; uint64_t base; -} __attribute__((packed)) dt_addr_t; +} __attribute__((packed)); struct boot_ctx { uint64_t cr0; uint64_t cr3; uint64_t cr4; - dt_addr_t idt; - dt_addr_t gdt; + struct dt_addr idt; + struct dt_addr gdt; uint16_t ldt_sel; uint16_t tr_sel; @@ -47,5 +81,5 @@ struct boot_ctx { void *get_rsdp_from_uefi(void); void *get_ap_trampoline_buf(void); #endif - +#endif /* ASSEMBLER */ #endif /* VM0_BOOT_H */