]> xenbits.xensource.com Git - people/royger/xen-test-framework.git/commitdiff
Setup for HVM userspace execution
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 24 Dec 2015 20:45:43 +0000 (20:45 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 5 Jan 2016 18:59:28 +0000 (18:59 +0000)
* Introduce definitions for a task state segment and load one.
* Use __USER_DS for the regular data segment selectors.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/boot/head_hvm.S
arch/x86/hvm/traps.c
include/arch/x86/desc.h

index dfdfa1ed86fb6c50332b40f206d121d82c0cb70f..b350799ecdc9c51069ba65d78acf39c317f83a5b 100644 (file)
@@ -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. */
index 07e66dc17d6fc51374f7111e2f1c397d91fb9548..5f478bcf88956e3080a596f1e64bcea2bd928abb 100644 (file)
@@ -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)
index d80750cebc7184de8a6bece9302406a5150a0348..dc55726a395c2c908b34da621f7c1b8ac732243b 100644 (file)
@@ -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 */