From bf3c9258b916c2f50dfd6b935716bdeed50398d6 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 17 Aug 2015 17:07:34 +0200 Subject: [PATCH] add missing data segemnet for 32bit applications --- hermit/arch/x86/include/asm/processor.h | 2 +- hermit/arch/x86/include/asm/tasks.h | 2 +- hermit/arch/x86/kernel/gdt.c | 29 +++++++++++++------------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/hermit/arch/x86/include/asm/processor.h b/hermit/arch/x86/include/asm/processor.h index 2701e2aff..454ff0881 100644 --- a/hermit/arch/x86/include/asm/processor.h +++ b/hermit/arch/x86/include/asm/processor.h @@ -656,7 +656,7 @@ void udelay(uint32_t usecs); /// Register a task's TSS at GDT static inline void register_task(void) { - uint16_t sel = (CORE_ID*2+6) << 3; + uint16_t sel = (CORE_ID*2+7) << 3; asm volatile ("ltr %%ax" : : "a"(sel)); } diff --git a/hermit/arch/x86/include/asm/tasks.h b/hermit/arch/x86/include/asm/tasks.h index 5694ae0e2..26d52601f 100644 --- a/hermit/arch/x86/include/asm/tasks.h +++ b/hermit/arch/x86/include/asm/tasks.h @@ -71,7 +71,7 @@ int create_default_frame(task_t* task, entry_point_t ep, void* arg); static inline int jump_to_user_code(size_t ep, size_t stack) { // Create a pseudo interrupt on the stack and return to user function - asm volatile ("push %0; push %1; push $0x1202; push %2; push %3; iretq" :: "r"(0x23ULL), "r"(stack), "r"(0x2bULL), "r"(ep) : "memory"); + asm volatile ("push %0; push %1; push $0x1202; push %2; push %3; iretq" :: "r"(0x33ULL), "r"(stack), "r"(0x2bULL), "r"(ep) : "memory"); return 0; } diff --git a/hermit/arch/x86/kernel/gdt.c b/hermit/arch/x86/kernel/gdt.c index 0bbf5f941..5c200ca52 100644 --- a/hermit/arch/x86/kernel/gdt.c +++ b/hermit/arch/x86/kernel/gdt.c @@ -81,15 +81,10 @@ void configure_gdt_entry(gdt_entry_t *dest_entry, unsigned long base, unsigned l */ void gdt_install(void) { - unsigned long gran_ds, gran_cs, limit; int i, num = 0; memset(task_state_segments, 0x00, MAX_CORES*sizeof(tss_t)); - gran_cs = GDT_FLAG_64_BIT; - gran_ds = 0; - limit = 0; - /* Setup the GDT pointer and limit */ gp.limit = (sizeof(gdt_entry_t) * GDT_ENTRIES) - 1; gp.base = (size_t) &gdt; @@ -102,16 +97,16 @@ void gdt_install(void) * is 0, the limit is 4 GByte, it uses 4KByte granularity, * and is a Code Segment descriptor. */ - gdt_set_gate(num++, 0, limit, - GDT_FLAG_RING0 | GDT_FLAG_SEGMENT | GDT_FLAG_CODESEG | GDT_FLAG_PRESENT, gran_cs); + gdt_set_gate(num++, 0, 0, + GDT_FLAG_RING0 | GDT_FLAG_SEGMENT | GDT_FLAG_CODESEG | GDT_FLAG_PRESENT, GDT_FLAG_64_BIT); /* * The third entry is our Data Segment. It's EXACTLY the * same as our code segment, but the descriptor type in * this entry's access byte says it's a Data Segment */ - gdt_set_gate(num++, 0, limit, - GDT_FLAG_RING0 | GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT, gran_ds); + gdt_set_gate(num++, 0, 0, + GDT_FLAG_RING0 | GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT, 0); /* * Create code segment for 32bit user-space applications (ring 3) @@ -122,14 +117,20 @@ void gdt_install(void) /* * Create data segment for user-space applications (ring 3) */ - gdt_set_gate(num++, 0, limit, - GDT_FLAG_RING3 | GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT, gran_ds); + gdt_set_gate(num++, 0, 0xFFFFFFFF, + GDT_FLAG_RING3 | GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT, GDT_FLAG_32_BIT | GDT_FLAG_4K_GRAN); /* * Create code segment for 64bit user-space applications (ring 3) */ - gdt_set_gate(num++, 0, limit, - GDT_FLAG_RING3 | GDT_FLAG_SEGMENT | GDT_FLAG_CODESEG | GDT_FLAG_PRESENT, gran_cs); + gdt_set_gate(num++, 0, 0, + GDT_FLAG_RING3 | GDT_FLAG_SEGMENT | GDT_FLAG_CODESEG | GDT_FLAG_PRESENT, GDT_FLAG_64_BIT); + + /* + * Create data segment for 64bit user-space applications (ring 3) + */ + gdt_set_gate(num++, 0, 0, + GDT_FLAG_RING3 | GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT, 0); /* * Create TSS for each core (we use these segments for task switching) @@ -137,7 +138,7 @@ void gdt_install(void) for(i=0; i