diff options
author | Alex Auvolat <alex@adnab.me> | 2016-07-15 20:51:05 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2016-07-15 20:51:05 +0200 |
commit | d415aca695956c79110c88fa58c12bf55c0e2163 (patch) | |
tree | 61c9589fe1cf1a78f7f582eff410e047eada604e /src | |
parent | 327d62f7d56f79999cac6407bdfdcc0b90510aef (diff) | |
download | kogata-d415aca695956c79110c88fa58c12bf55c0e2163.tar.gz kogata-d415aca695956c79110c88fa58c12bf55c0e2163.zip |
Fix nasty task switching bu
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/core/context_switch.s | 9 | ||||
-rw-r--r-- | src/kernel/core/frame.c | 3 | ||||
-rw-r--r-- | src/kernel/core/interrupt.s | 1 | ||||
-rw-r--r-- | src/kernel/core/sys.c | 2 | ||||
-rw-r--r-- | src/kernel/core/thread.c | 20 |
5 files changed, 21 insertions, 14 deletions
diff --git a/src/kernel/core/context_switch.s b/src/kernel/core/context_switch.s index b8f6bb8..e81fa56 100644 --- a/src/kernel/core/context_switch.s +++ b/src/kernel/core/context_switch.s @@ -4,13 +4,15 @@ [GLOBAL save_context_and_enter_scheduler] ; void save_context_and_enter_scheduler(struct saved_context *ctx); save_context_and_enter_scheduler: + push ebp ; save stack frame for debugging + mov ebp, esp pushf ; push flags cli pusha ; push general registers mov eax, cr3 ; push CR3 push eax - mov eax, [esp+44] ; get address of saved_context structure + mov eax, [ebp+8] ; get address of saved_context structure mov [eax], esp ; save esp mov dword [eax+4], resume_saved_context ; save eip @@ -22,12 +24,15 @@ resume_saved_context: mov cr3, eax popa ; restore general registers popf ; restore flags + pop ebp ret [GLOBAL resume_context] resume_context: - mov eax, [esp+4] ; get address of saved context + push ebp + mov ebp, esp + mov eax, [ebp+8] ; get address of saved context mov esp, [eax] ; resume esp mov ecx, [eax+4] ; jump to specified eip jmp ecx diff --git a/src/kernel/core/frame.c b/src/kernel/core/frame.c index e74f9ad..7cc9bca 100644 --- a/src/kernel/core/frame.c +++ b/src/kernel/core/frame.c @@ -16,8 +16,9 @@ static uint32_t begin_search_at; void frame_init_allocator(size_t total_ram, void** kernel_data_end) { nframes = PAGE_ID(total_ram); + // Statically allocate space after kernel data end frame_bitset = (uint32_t*)ALIGN4_UP((size_t)*kernel_data_end); - *kernel_data_end = (void*)frame_bitset + ALIGN4_UP(nframes / 8); + *kernel_data_end = (void*)((size_t)frame_bitset + ALIGN4_UP(nframes / 8)); for (size_t i = 0; i < ALIGN4_UP(nframes / 8)/4; i++) frame_bitset[i] = 0; diff --git a/src/kernel/core/interrupt.s b/src/kernel/core/interrupt.s index 8fb71e8..084d7c9 100644 --- a/src/kernel/core/interrupt.s +++ b/src/kernel/core/interrupt.s @@ -2,6 +2,7 @@ %macro COMMONSTUB 1 [EXTERN idt_%1_handler] +[GLOBAL %1_common_stub] ; For debugging %1_common_stub: pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax diff --git a/src/kernel/core/sys.c b/src/kernel/core/sys.c index e852274..8cc1407 100644 --- a/src/kernel/core/sys.c +++ b/src/kernel/core/sys.c @@ -80,7 +80,7 @@ void kernel_stacktrace(uint32_t ebp, uint32_t eip) { sym = btree_lower(kernel_symbol_map, (void*)eip, &fn_ptr); } - dbg_printf("| 0x%p EIP: 0x%p %s +0x%p\n", ebp, eip, sym, ((void*)eip - fn_ptr)); + dbg_printf("| 0x%p EIP: 0x%p %s +%d\n", ebp, eip, sym, ((void*)eip - fn_ptr)); uint32_t *d = (uint32_t*)ebp; ebp = d[0]; diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index 37226ae..342cead 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -127,19 +127,22 @@ void run_scheduler() { if (current_thread->proc) current_thread->proc->last_ran = current_thread->last_ran; enqueue_thread(current_thread, true); } - current_thread = dequeue_thread(); + current_thread = 0; - if (current_thread != prev_thread && SPAM_CONTEXT_SWITCH) dbg_printf("[0x%p]\n", current_thread); + thread_t *next_thread = dequeue_thread(); - if (current_thread != 0) { - thread_t *ptr = current_thread; - prng_add_entropy((uint8_t*)&ptr, sizeof(ptr)); + if (next_thread != prev_thread && SPAM_CONTEXT_SWITCH) dbg_printf("[0x%p]\n", next_thread); - set_kernel_stack(current_thread->stack_region->addr + current_thread->stack_region->size); + if (next_thread != 0) { + prng_add_entropy((uint8_t*)&next_thread, sizeof(next_thread)); + + set_kernel_stack(next_thread->stack_region->addr + next_thread->stack_region->size); + + current_thread = next_thread; resume_context(¤t_thread->ctx); } else { // Wait for an IRQ - asm volatile("sti; hlt"); + asm volatile("sti; hlt; cli"); // At this point an IRQ has happenned // and has been processed. Loop around. run_scheduler(); @@ -247,9 +250,6 @@ void threading_setup(entry_t cont, void* arg) { ASSERT(t != 0); start_thread(t); - - exit_critical(CL_USER); - run_scheduler(); // never returns ASSERT(false); } |