From 89c792cc03191ff97a9c8d5912aae8b08458817f Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 19 Jul 2012 00:17:31 +0200 Subject: [PATCH] fix bug in the calculation of esp0 --- apps/tests.h | 8 ++++++-- arch/x86/kernel/entry32.asm | 20 -------------------- arch/x86/kernel/entry64.asm | 20 -------------------- arch/x86/kernel/gdt.c | 13 ++++++++----- arch/x86/kernel/processor.c | 5 +---- 5 files changed, 15 insertions(+), 51 deletions(-) diff --git a/apps/tests.h b/apps/tests.h index 19cf416f..fb27e1c8 100644 --- a/apps/tests.h +++ b/apps/tests.h @@ -32,15 +32,19 @@ //#define START_KERNEL_JACOBI #define START_MMNIF_TEST #endif +#ifdef CONFIG_LWIP #define START_ECHO +#ifndef CONFIG_TICKLESS //#define START_NETIO +#endif +#endif //#define START_CONSUMER_PRODUCER #define START_FOO //#define START_JOIN_TEST //#define START_PI //#define START_MEASURE_CTX_SWITCH -#define START_HELLO -//#define START_TESTS +//#define START_HELLO +#define START_TESTS //#define START_JACOBI // does our demos require GFX support? diff --git a/arch/x86/kernel/entry32.asm b/arch/x86/kernel/entry32.asm index c1e90e70..9f76d90e 100644 --- a/arch/x86/kernel/entry32.asm +++ b/arch/x86/kernel/entry32.asm @@ -753,8 +753,6 @@ apic_svr: extern irq_handler extern get_current_stack extern finish_task_switch -extern apic_cpu_id -extern task_state_segments global switch_context ALIGN 4 @@ -792,24 +790,6 @@ common_switch: call get_current_stack ; get new esp xchg eax, esp - ; determine TSS -%if MAX_CORES > 1 - call apic_cpu_id - mov ecx, DWORD 0x68 - mul ecx -%else - xor eax, eax -%endif - add eax, task_state_segments - - ; determine and set esp0 in TSS - mov ebx, esp - mov ecx, KERNEL_STACK_SIZE-1 - not ecx - and ebx, ecx - add ebx, KERNEL_STACK_SIZE-16 - mov [eax+4], ebx - ; set task switched flag mov eax, cr0 or eax, 8 diff --git a/arch/x86/kernel/entry64.asm b/arch/x86/kernel/entry64.asm index 627a8682..9fe2390f 100644 --- a/arch/x86/kernel/entry64.asm +++ b/arch/x86/kernel/entry64.asm @@ -1066,8 +1066,6 @@ apic_svr: extern irq_handler extern get_current_stack extern finish_task_switch -extern apic_cpu_id -extern task_state_segments global switch_context ALIGN 8 @@ -1137,24 +1135,6 @@ common_switch: call get_current_stack ; get new rsp xchg rax, rsp - ; determine TSS -%if MAX_CORES > 1 - call apic_cpu_id - mov rcx, QWORD 0x68 - mul rcx -%else - xor rax, rax -%endif - add rax, task_state_segments - - ; determine and set esp0 in TSS - mov rbx, rsp - mov rcx, KERNEL_STACK_SIZE-1 - not rcx - and rbx, rcx - add rbx, KERNEL_STACK_SIZE-16 - mov [rax+4], rbx - ; set task switched flag mov rax, cr0 or eax, 8 diff --git a/arch/x86/kernel/gdt.c b/arch/x86/kernel/gdt.c index 8bb3b827..78b4db9d 100644 --- a/arch/x86/kernel/gdt.c +++ b/arch/x86/kernel/gdt.c @@ -28,8 +28,8 @@ #include gdt_ptr_t gp; -tss_t task_state_segments[MAX_CORES] __attribute__ ((aligned (PAGE_SIZE))); -static unsigned char kstacks[MAX_TASKS][KERNEL_STACK_SIZE] __attribute__ ((aligned (PAGE_SIZE))) = {[0 ... MAX_TASKS-1][0 ... KERNEL_STACK_SIZE-1] = 0xCD}; +static tss_t task_state_segments[MAX_CORES] __attribute__ ((aligned (PAGE_SIZE))); +static unsigned char kstacks[MAX_TASKS][KERNEL_STACK_SIZE] __attribute__ ((aligned (PAGE_SIZE))) = {[0][0 ... KERNEL_STACK_SIZE-1] = 0xCD}; size_t default_stack_pointer = (size_t) kstacks[0] + KERNEL_STACK_SIZE - 16; // => stack is 16byte aligned // currently, our kernel has full access to the ioports static gdt_entry_t gdt[GDT_ENTRIES] = {[0 ... GDT_ENTRIES-1] = {0, 0, 0, 0, 0, 0}}; @@ -44,6 +44,10 @@ size_t* get_current_stack(void) { task_t* curr_task = per_core(current_task); + // determine and set esp0 + task_state_segments[CORE_ID].esp0 = (size_t) kstacks[curr_task->id] + KERNEL_STACK_SIZE - 16; // => stack is 16byte aligned + + // use new page table write_cr3(virt_to_phys((size_t)curr_task->pgd)); return curr_task->stack; @@ -58,7 +62,6 @@ size_t get_stack(uint32_t id) int arch_fork(task_t* task) { - uint16_t cs = 0x08; uint32_t id; struct state* state; task_t* curr_task = per_core(current_task); @@ -84,7 +87,7 @@ int arch_fork(task_t* task) esp += (size_t) kstacks[id]; state = (struct state*) (esp - state_size); - memset(state, 0x00, state_size); + //memset(state, 0x00, state_size); asm volatile ("pusha; pop %0" : "=m"(state->edi)); asm volatile ("pop %0" : "=m"(state->esi)); @@ -99,7 +102,7 @@ int arch_fork(task_t* task) task->stack = (size_t*) state; state->int_no = 0xB16B00B5; state->error = 0xC03DB4B3; - state->cs = cs; + state->cs = 0x08; // store the current EFLAGS asm volatile ("pushf; pop %0" : "=m"(state->eflags)); // enable interrupts diff --git a/arch/x86/kernel/processor.c b/arch/x86/kernel/processor.c index 7f6078f3..4802bc8e 100644 --- a/arch/x86/kernel/processor.c +++ b/arch/x86/kernel/processor.c @@ -102,13 +102,10 @@ int cpu_detection(void) cr4 |= 0x400; // set the OSXMMEXCPT bit write_cr4(cr4); - if (has_sse()) { - kprintf("Enable the usage of sfence\n"); + if (has_sse()) wmb = sfence; - } if (has_sse2()) { - kprintf("Enable the usage of lfence and mfence\n"); rmb = lfence; mb = mfence; }