Commit 69d8fe0e authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

x86: unify GDT format between 32-bit and 64-bit



Except the TSS, which is 16-bytes in 64-bit mode, we can use the same
structure and share the constants.  This will aid in porting tests
to 64-bit.

Multiple bitwidth and ring 3 selectors aren't used yet.  I couldn't
make my mind on keeping vs. dropping them, in the end I kept the ring 3
selectors which have a chance of being used for SMAP or paging unit tests.

With this change, vmx.c can start using desc.h's constants and those
in vm.h (why vm.h?) can be dropped.

Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 5b0bf08b
......@@ -191,11 +191,13 @@ unsigned exception_error_code(void)
/*
* GDT, with 6 entries:
* 0x00 - NULL descriptor
* 0x08 - Code segment
* 0x10 - Data segment
* 0x18 - Not present code segment
* 0x20 - Interrupt task
* 0x28 to 0x78 - Free to use for test cases
* 0x08 - Code segment (ring 0)
* 0x10 - Data segment (ring 0)
* 0x18 - Not present code segment (ring 0)
* 0x20 - Code segment (ring 3)
* 0x28 - Data segment (ring 3)
* 0x30 - Interrupt task
* 0x38 to 0x78 - Free to use for test cases
* 0x80 - Primary task (CPU 0)
*/
......
......@@ -72,8 +72,10 @@ typedef struct {
#define KERNEL_CS 0x08
#define KERNEL_DS 0x10
#define NP_SEL 0x18
#define TSS_INTR 0x20
#define FIRST_SPARE_SEL 0x28
#define USER_CS 0x23
#define USER_DS 0x2b
#define TSS_INTR 0x30
#define FIRST_SPARE_SEL 0x38
#define TSS_MAIN 0x80
typedef struct {
......
......@@ -28,19 +28,6 @@
#define X86_CR4_PAE 0x00000020
#define X86_CR4_PCIDE 0x00020000
#ifdef __x86_64__
#define SEL_NULL_DESC 0x0
#define SEL_KERN_CODE_64 0x8
#define SEL_KERN_DATA_64 0x10
#define SEL_USER_CODE_64 0x18
#define SEL_USER_DATA_64 0x20
#define SEL_CODE_32 0x28
#define SEL_DATA_32 0x30
#define SEL_CODE_16 0x38
#define SEL_DATA_16 0x40
#define SEL_TSS_RUN 0x48
#endif
void setup_vm();
void *vmalloc(unsigned long size);
......
......@@ -553,8 +553,8 @@ int ac_test_do_access(ac_test_t *at)
[write]"r"(at->flags[AC_ACCESS_WRITE]),
[user]"r"(at->flags[AC_ACCESS_USER]),
[fetch]"r"(at->flags[AC_ACCESS_FETCH]),
[user_ds]"i"(32+3),
[user_cs]"i"(24+3),
[user_ds]"i"(USER_DS),
[user_cs]"i"(USER_CS),
[user_stack_top]"r"(user_stack + sizeof user_stack),
[kernel_entry_vector]"i"(0x20)
: "rsi");
......
......@@ -34,10 +34,10 @@ gdt32:
.quad 0x00cf9b000000ffff // flat 32-bit code segment
.quad 0x00cf93000000ffff // flat 32-bit data segment
.quad 0x00cf1b000000ffff // flat 32-bit code segment, not present
.quad 0x00cffb000000ffff // 64-bit code segment (user)
.quad 0x00cff3000000ffff // 64-bit data segment (user)
.quad 0 // 12 spare selectors
.quad 0
.quad 0
.quad 0 // 10 spare selectors
.quad 0
.quad 0
.quad 0
......
......@@ -54,12 +54,20 @@ gdt64:
.quad 0
.quad 0x00af9b000000ffff // 64-bit code segment
.quad 0x00cf93000000ffff // 64-bit data segment
.quad 0x00af1b000000ffff // 64-bit code segment, not present
.quad 0x00affb000000ffff // 64-bit code segment (user)
.quad 0x00cff3000000ffff // 64-bit data segment (user)
.quad 0x00cf9b000000ffff // 32-bit code segment
.quad 0x00cf92000000ffff // 32-bit code segment
.quad 0x008F9A000000FFFF // 16-bit code segment
.quad 0x008F92000000FFFF // 16-bit data segment
.quad 0 // 10 spare selectors
.quad 0
.quad 0
.quad 0
.quad 0
.quad 0
.quad 0
.quad 0
.quad 0
.quad 0
tss_descr:
.rept max_cpus
......
......@@ -346,16 +346,16 @@ static void init_vmcs_host(void)
vmcs_write(HOST_CR3, read_cr3());
vmcs_write(HOST_CR4, read_cr4());
vmcs_write(HOST_SYSENTER_EIP, (u64)(&entry_sysenter));
vmcs_write(HOST_SYSENTER_CS, SEL_KERN_CODE_64);
vmcs_write(HOST_SYSENTER_CS, KERNEL_CS);
/* 26.2.3 */
vmcs_write(HOST_SEL_CS, SEL_KERN_CODE_64);
vmcs_write(HOST_SEL_SS, SEL_KERN_DATA_64);
vmcs_write(HOST_SEL_DS, SEL_KERN_DATA_64);
vmcs_write(HOST_SEL_ES, SEL_KERN_DATA_64);
vmcs_write(HOST_SEL_FS, SEL_KERN_DATA_64);
vmcs_write(HOST_SEL_GS, SEL_KERN_DATA_64);
vmcs_write(HOST_SEL_TR, SEL_TSS_RUN);
vmcs_write(HOST_SEL_CS, KERNEL_CS);
vmcs_write(HOST_SEL_SS, KERNEL_DS);
vmcs_write(HOST_SEL_DS, KERNEL_DS);
vmcs_write(HOST_SEL_ES, KERNEL_DS);
vmcs_write(HOST_SEL_FS, KERNEL_DS);
vmcs_write(HOST_SEL_GS, KERNEL_DS);
vmcs_write(HOST_SEL_TR, TSS_MAIN);
vmcs_write(HOST_BASE_TR, tss_descr.base);
vmcs_write(HOST_BASE_GDTR, gdt64_desc.base);
vmcs_write(HOST_BASE_IDTR, idt_descr.base);
......@@ -389,7 +389,7 @@ static void init_vmcs_guest(void)
vmcs_write(GUEST_CR0, guest_cr0);
vmcs_write(GUEST_CR3, guest_cr3);
vmcs_write(GUEST_CR4, guest_cr4);
vmcs_write(GUEST_SYSENTER_CS, SEL_KERN_CODE_64);
vmcs_write(GUEST_SYSENTER_CS, KERNEL_CS);
vmcs_write(GUEST_SYSENTER_ESP,
(u64)(guest_syscall_stack + PAGE_SIZE - 1));
vmcs_write(GUEST_SYSENTER_EIP, (u64)(&entry_sysenter));
......@@ -397,13 +397,13 @@ static void init_vmcs_guest(void)
vmcs_write(GUEST_EFER, rdmsr(MSR_EFER));
/* 26.3.1.2 */
vmcs_write(GUEST_SEL_CS, SEL_KERN_CODE_64);
vmcs_write(GUEST_SEL_SS, SEL_KERN_DATA_64);
vmcs_write(GUEST_SEL_DS, SEL_KERN_DATA_64);
vmcs_write(GUEST_SEL_ES, SEL_KERN_DATA_64);
vmcs_write(GUEST_SEL_FS, SEL_KERN_DATA_64);
vmcs_write(GUEST_SEL_GS, SEL_KERN_DATA_64);
vmcs_write(GUEST_SEL_TR, SEL_TSS_RUN);
vmcs_write(GUEST_SEL_CS, KERNEL_CS);
vmcs_write(GUEST_SEL_SS, KERNEL_DS);
vmcs_write(GUEST_SEL_DS, KERNEL_DS);
vmcs_write(GUEST_SEL_ES, KERNEL_DS);
vmcs_write(GUEST_SEL_FS, KERNEL_DS);
vmcs_write(GUEST_SEL_GS, KERNEL_DS);
vmcs_write(GUEST_SEL_TR, TSS_MAIN);
vmcs_write(GUEST_SEL_LDTR, 0);
vmcs_write(GUEST_BASE_CS, 0);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment