diff --git a/headers/thread.h b/headers/thread.h index 6f12a6e..71a54bb 100644 --- a/headers/thread.h +++ b/headers/thread.h @@ -24,4 +24,4 @@ struct tcb { struct tcb *create_thread(struct pcb *process, void (*entry)(void)); void delete_thread(struct tcb *thread); -void switch_thread(uint32_t *esp); +void switch_thread(struct tcb *thread_to_switch); diff --git a/src/multitasking/scheduler.c b/src/multitasking/scheduler.c index cec7a18..dd857ac 100644 --- a/src/multitasking/scheduler.c +++ b/src/multitasking/scheduler.c @@ -39,8 +39,6 @@ void scheduler(uint32_t *esp) struct tcb *thread_to_switch = (struct tcb *)list_node->content; if (current_tcb) CURRENT_TCB->esp = esp; - if (thread_to_switch->process != current_pcb) - switch_process(thread_to_switch->process); current_tcb = list_node; - switch_thread(thread_to_switch->esp); + switch_thread(thread_to_switch); } diff --git a/src/multitasking/switch_process.s b/src/multitasking/switch_process.s deleted file mode 100644 index c420004..0000000 --- a/src/multitasking/switch_process.s +++ /dev/null @@ -1,16 +0,0 @@ -.intel_syntax noprefix -.extern current_pcb - -.section .text - .global switch_process - -switch_process: - // change current_pcb global - mov eax, [esp + 4] - mov [current_pcb], eax - - // reload cr3 with the new heap - mov edx, [eax + 0] - mov cr3, edx - - ret diff --git a/src/multitasking/switch_to_thread.s b/src/multitasking/switch_to_thread.s index 281960c..2af33f3 100644 --- a/src/multitasking/switch_to_thread.s +++ b/src/multitasking/switch_to_thread.s @@ -7,8 +7,20 @@ switch_thread: mov eax, [esp + 4] - mov esp, eax + mov esp, [eax] + mov edx, [eax + 16] + cmp [current_pcb], edx + je LABEL1 + + // change current_pcb + mov [current_pcb], edx + + // reload cr3 with the new heap + mov edx, [edx] + mov cr3, edx + +LABEL1: pop eax mov ds, eax