From: Andrew Cooper Date: Thu, 24 Dec 2015 20:22:30 +0000 (+0000) Subject: Common infrastructure for userspace execution X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d95225682d571164d70e8d04acc36ab20ebf0f0b;p=people%2Froyger%2Fxen-test-framework.git Common infrastructure for userspace execution Introduce __USER_{CS,DS}, expand the boot stack to two pages, add some DPL3 GDT descriptors, and space in GDT for a TSS. Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/desc.c b/arch/x86/desc.c index 9acd62c..6058769 100644 --- a/arch/x86/desc.c +++ b/arch/x86/desc.c @@ -6,6 +6,13 @@ user_desc gdt[NR_GDT_ENTRIES] = [GDTE_CS64_DPL0] = INIT_GDTE_SYM(0, 0xfffff, COMMON, CODE, DPL0, R, L), [GDTE_CS32_DPL0] = INIT_GDTE_SYM(0, 0xfffff, COMMON, CODE, DPL0, R, D), [GDTE_DS32_DPL0] = INIT_GDTE_SYM(0, 0xfffff, COMMON, DATA, DPL0, B, W), + + [GDTE_CS64_DPL3] = INIT_GDTE_SYM(0, 0xfffff, COMMON, CODE, DPL3, R, L), + [GDTE_CS32_DPL3] = INIT_GDTE_SYM(0, 0xfffff, COMMON, CODE, DPL3, R, D), + [GDTE_DS32_DPL3] = INIT_GDTE_SYM(0, 0xfffff, COMMON, DATA, DPL3, B, W), + + /* [GDTE_TSS] */ + /* [GDTE_TSS + 1] */ }; desc_ptr gdt_ptr = diff --git a/arch/x86/setup.c b/arch/x86/setup.c index 0bfff1e..914fd38 100644 --- a/arch/x86/setup.c +++ b/arch/x86/setup.c @@ -7,7 +7,13 @@ #include #include -uint8_t boot_stack[PAGE_SIZE] __aligned(PAGE_SIZE); +/* + * XTF Stack layout: + * + * boot_stack[page 2] Exception entrypoints + * boot_stack[page 1] Top of work stack + */ +uint8_t boot_stack[2 * PAGE_SIZE] __aligned(PAGE_SIZE); const char *environment_description = #if defined(CONFIG_ENV_pv32) diff --git a/include/arch/x86/segment.h b/include/arch/x86/segment.h index b34bce4..8082e62 100644 --- a/include/arch/x86/segment.h +++ b/include/arch/x86/segment.h @@ -13,23 +13,36 @@ * 1 - 64bit supervisor code * 2 - 32bit supervisor code * 3 - 32bit supervisor data + * 4 - 64bit userspace code + * 5 - 32bit userspace code + * 6 - 32bit userspace data + * 7 - TSS (two slots in long mode) */ #define GDTE_CS64_DPL0 1 #define GDTE_CS32_DPL0 2 #define GDTE_DS32_DPL0 3 +#define GDTE_CS64_DPL3 4 +#define GDTE_CS32_DPL3 5 +#define GDTE_DS32_DPL3 6 -#define NR_GDT_ENTRIES 4 +#define GDTE_TSS 7 + +#define NR_GDT_ENTRIES 9 #if defined(CONFIG_ENV_hvm64) #define __KERN_CS (GDTE_CS64_DPL0 * 8) #define __KERN_DS (0) +#define __USER_CS (GDTE_CS64_DPL3 * 8 + 3) +#define __USER_DS (GDTE_DS32_DPL3 * 8 + 3) #elif defined(CONFIG_ENV_hvm32) #define __KERN_CS (GDTE_CS32_DPL0 * 8) #define __KERN_DS (GDTE_DS32_DPL0 * 8) +#define __USER_CS (GDTE_CS32_DPL3 * 8 + 3) +#define __USER_DS (GDTE_DS32_DPL3 * 8 + 3) #endif @@ -46,11 +59,15 @@ */ #define __KERN_CS (FLAT_RING3_CS64 & ~3) #define __KERN_DS (FLAT_RING3_DS64 & ~3) +#define __USER_CS FLAT_RING3_CS64 +#define __USER_DS FLAT_RING3_DS64 #elif defined(CONFIG_ENV_pv32) #define __KERN_CS FLAT_RING1_CS #define __KERN_DS FLAT_RING1_DS +#define __USER_CS FLAT_RING3_CS +#define __USER_DS FLAT_RING3_DS #endif diff --git a/include/arch/x86/traps.h b/include/arch/x86/traps.h index 53eabb7..d6c0d0c 100644 --- a/include/arch/x86/traps.h +++ b/include/arch/x86/traps.h @@ -3,6 +3,7 @@ #include #include +#include /* * Arch-specific function to initialise the exception entry points, etc. @@ -15,6 +16,8 @@ void arch_init_traps(void); */ void __noreturn arch_crash_hard(void); +extern uint8_t boot_stack[2 * PAGE_SIZE]; + #endif /* XTF_X86_TRAPS_H */ /*