From: Andrew Cooper Date: Thu, 24 Dec 2015 20:45:43 +0000 (+0000) Subject: Setup for HVM userspace execution X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=1ecc92844b78513828b50d5d7f4d0413dcfd9c96;p=people%2Froyger%2Fxen-test-framework.git Setup for HVM userspace execution * Introduce definitions for a task state segment and load one. * Use __USER_DS for the regular data segment selectors. Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/boot/head_hvm.S b/arch/x86/boot/head_hvm.S index dfdfa1e..b350799 100644 --- a/arch/x86/boot/head_hvm.S +++ b/arch/x86/boot/head_hvm.S @@ -45,11 +45,12 @@ GLOBAL(_start) #endif /* Load data segments. */ -1: mov $__KERN_DS, %eax +1: mov $__USER_DS, %eax mov %eax, %ds mov %eax, %es mov %eax, %fs mov %eax, %gs + mov $__KERN_DS, %eax mov %eax, %ss /* Move onto the boot stack. */ diff --git a/arch/x86/hvm/traps.c b/arch/x86/hvm/traps.c index 07e66dc..5f478bc 100644 --- a/arch/x86/hvm/traps.c +++ b/arch/x86/hvm/traps.c @@ -25,6 +25,22 @@ void entry_MC(void); void entry_XM(void); void entry_VE(void); +hw_tss tss __aligned(16) = +{ +#if defined(__i386__) + + .esp0 = (unsigned long)&boot_stack[2 * PAGE_SIZE], + .ss0 = __KERN_DS, + +#elif defined(__x86_64__) + + .rsp0 = (unsigned long)&boot_stack[2 * PAGE_SIZE], + +#endif + + .iopb = X86_TSS_INVALID_IO_BITMAP, +}; + void pack_gate32(struct seg_gate32 *gate, unsigned type, uint32_t func, unsigned dpl, unsigned seg) { @@ -86,6 +102,9 @@ void arch_init_traps(void) setup_gate(X86_EXC_VE, &entry_VE, 0); asm volatile ("lidt idt_ptr"); + + gdt[GDTE_TSS] = (typeof(*gdt))INIT_GDTE_RAW((unsigned long)&tss, 0x67, 0x89); + asm volatile ("ltr %w0" :: "rm" (GDTE_TSS * 8)); } void __noreturn arch_crash_hard(void) diff --git a/include/arch/x86/desc.h b/include/arch/x86/desc.h index d80750c..dc55726 100644 --- a/include/arch/x86/desc.h +++ b/include/arch/x86/desc.h @@ -157,17 +157,72 @@ struct __packed desc_ptr32 { uint32_t base; }; +struct __packed hw_tss32 { + uint16_t link; uint16_t _r0; + + uint32_t esp0; + uint16_t ss0; uint16_t _r1; + + uint32_t esp1; + uint16_t ss1; uint16_t _r2; + + uint32_t esp2; + uint16_t ss2; uint16_t _r3; + + uint32_t cr3; + uint32_t eip; + uint32_t eflags; + uint32_t eax; + uint32_t ecx; + uint32_t edx; + uint32_t ebx; + uint32_t esp; + uint32_t ebp; + uint32_t esi; + uint32_t edi; + + uint16_t es; uint16_t _r4; + uint16_t cs; uint16_t _r5; + uint16_t ss; uint16_t _r6; + uint16_t ds; uint16_t _r7; + uint16_t fs; uint16_t _r8; + uint16_t gs; uint16_t _r9; + uint16_t ldtr; uint16_t _r10; + uint16_t t; uint16_t iopb; +}; + +struct __packed hw_tss64 { + uint16_t link; uint16_t _r0; + + uint64_t rsp0; + uint64_t rsp1; + uint64_t rsp2; + + uint64_t _r1; + + uint64_t ist[7]; /* 1-based structure */ + + uint64_t _r2; + + uint16_t t; + uint16_t iopb; +}; + +#define X86_TSS_INVALID_IO_BITMAP 0x8000 + #if defined(__x86_64__) typedef struct desc_ptr64 desc_ptr; typedef struct seg_desc32 user_desc; typedef struct seg_gate64 gate_desc; +typedef struct hw_tss64 hw_tss; #elif defined(__i386__) typedef struct desc_ptr32 desc_ptr; typedef struct seg_desc32 user_desc; typedef struct seg_gate32 gate_desc; +typedef struct hw_tss32 hw_tss; #else # error Bad architecture for descriptor infrastructure @@ -179,6 +234,8 @@ extern desc_ptr gdt_ptr; #if defined(CONFIG_ENV_hvm) extern gate_desc idt[256]; extern desc_ptr idt_ptr; + +extern hw_tss tss; #endif #endif /* XTF_X86_DESC_H */