From c71b6c6c8a2297b421e17e7fd53dc4cf654fb7f1 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Wed, 22 Jan 2014 12:07:29 +0100 Subject: [PATCH] Simplify code, add additional comments --- arch/x86/include/asm/tasks.h | 3 --- arch/x86/kernel/entry.asm | 5 +++++ arch/x86/kernel/gdt.c | 6 ++++-- kernel/main.c | 4 +--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/tasks.h b/arch/x86/include/asm/tasks.h index 2fae22a..e7e2ca8 100644 --- a/arch/x86/include/asm/tasks.h +++ b/arch/x86/include/asm/tasks.h @@ -61,9 +61,6 @@ void switch_context(size_t** stack); */ int create_default_frame(task_t* task, entry_point_t ep, void* arg); -/** @brief Copy kernel stack pointer to TSS */ -void set_kernel_stack(size_t stack); - /** @brief Register a task's TSS at GDT * * @return diff --git a/arch/x86/kernel/entry.asm b/arch/x86/kernel/entry.asm index 08a4c26..19df613 100644 --- a/arch/x86/kernel/entry.asm +++ b/arch/x86/kernel/entry.asm @@ -263,6 +263,8 @@ ALIGN 4 rollback: ret +extern set_kernel_stack + ALIGN 4 common_stub: pusha @@ -290,6 +292,9 @@ common_switch: or eax, 8 mov cr0, eax + ; set esp0 in the task state segment + call set_kernel_stack + ; call cleanup code call finish_task_switch diff --git a/arch/x86/kernel/gdt.c b/arch/x86/kernel/gdt.c index 3f23539..43190af 100644 --- a/arch/x86/kernel/gdt.c +++ b/arch/x86/kernel/gdt.c @@ -46,9 +46,11 @@ static gdt_entry_t gdt[GDT_ENTRIES] = {[0 ... GDT_ENTRIES-1] = {0, 0, 0, 0, 0, */ extern void gdt_flush(void); -void set_kernel_stack(size_t stack) +void set_kernel_stack(void) { - task_state_segment.esp0 = stack; + task_t* curr_task = current_task; + + task_state_segment.esp0 = (size_t) curr_task->stack + KERNEL_STACK_SIZE-16; } /* Setup a descriptor in the Global Descriptor Table */ diff --git a/kernel/main.c b/kernel/main.c index 429ae49..34b8642 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -65,9 +65,7 @@ static int wrapper(void* arg) memset(ustack, 0xCD, KERNEL_STACK_SIZE); *stack-- = (size_t) arg; - *stack = (size_t) leave_user_task; // add dummy return value - - set_kernel_stack((size_t) &stack); + *stack = (size_t) leave_user_task; // put exit function as caller on the stack return jump_to_user_code((uint32_t) userfoo, (uint32_t) stack); }