diff --git a/src/kernel.c b/src/kernel.c index a7e7db5..a3e3917 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -55,7 +55,8 @@ void kernel_main(multiboot_info_t *mbd, uint32_t magic) terminal_initialize(); create_process(1); create_thread(current_pcb, shell_init); - create_thread(current_pcb, uwu); + create_process(2); + create_thread(current_pcb->next, uwu); toris(); while (true) ; diff --git a/src/multitasking/scheduler.c b/src/multitasking/scheduler.c index a6bcb52..05b3d04 100644 --- a/src/multitasking/scheduler.c +++ b/src/multitasking/scheduler.c @@ -37,6 +37,8 @@ void scheduler(uint32_t *esp) kpanic("No existing threads \n"); if (current_tcb) current_tcb->esp = esp; + if (thread_to_switch->process != current_pcb) + switch_process(thread_to_switch->process); current_tcb = thread_to_switch; switch_thread(thread_to_switch->esp); } diff --git a/src/multitasking/switch_process.s b/src/multitasking/switch_process.s new file mode 100644 index 0000000..c420004 --- /dev/null +++ b/src/multitasking/switch_process.s @@ -0,0 +1,16 @@ +.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