From bf993baa59e5897af06d6473b3859108363e55d9 Mon Sep 17 00:00:00 2001 From: 0x35c <> Date: Fri, 7 Nov 2025 16:58:11 +0100 Subject: [PATCH] wip: uncrampt the stack thing in the irq --- headers/thread.h | 2 +- src/multitasking/switch_to_thread.s | 2 +- src/multitasking/thread.c | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/headers/thread.h b/headers/thread.h index 0db58aa..9f5eadb 100644 --- a/headers/thread.h +++ b/headers/thread.h @@ -22,6 +22,6 @@ struct tcb { struct tcb *next; }; -struct tcb *create_thread(struct pcb *process, void (*routine)(void)); +struct tcb *create_thread(struct pcb *process, void (*entry)(void)); void delete_thread(struct tcb *thread); void switch_thread(struct tcb *thread_to_switch); diff --git a/src/multitasking/switch_to_thread.s b/src/multitasking/switch_to_thread.s index 9629db1..26fca10 100644 --- a/src/multitasking/switch_to_thread.s +++ b/src/multitasking/switch_to_thread.s @@ -15,7 +15,7 @@ switch_thread: // stack pointer + the 4 regs pushed // and + 1 to get the argument (next thread) .LABEL1: - mov esi, [esp+(4+1)*4] + mov esi, [esp+4] mov [current_tcb], esi mov eax, [current_tcb] diff --git a/src/multitasking/thread.c b/src/multitasking/thread.c index 25419b4..bcba614 100644 --- a/src/multitasking/thread.c +++ b/src/multitasking/thread.c @@ -6,7 +6,7 @@ #include "string.h" #include "thread.h" -struct tcb *create_thread(struct pcb *process, void (*routine)(void)) +struct tcb *create_thread(struct pcb *process, void (*entry)(void)) { static uint32_t tid = 1; struct tcb *new_tcb = vmalloc(sizeof(struct tcb)); @@ -21,8 +21,14 @@ struct tcb *create_thread(struct pcb *process, void (*routine)(void)) } // set esp to "skip" the 4 GPRs and eip later to be used as the context // of the thread - new_tcb->esp = new_tcb->esp0 + STACK_SIZE - 5 * 4; - new_tcb->esp[4] = (uint32_t)routine; + uint32_t *stack = + (uint32_t *)((uint8_t *)new_tcb->esp0 + STACK_SIZE - 5 * 4); + + // testing out some stuff + *(--stack) = 0x202; // EFLAGS + *(--stack) = 0x08; // CS = kernel code segment + *(--stack) = (uint32_t)entry; + new_tcb->esp = stack; new_tcb->process = process; new_tcb->next = NULL; new_tcb->state = NEW;