wip: context switch when switching to another process

This commit is contained in:
0x35c
2025-11-11 17:31:08 +01:00
parent e4f5a377a3
commit f9832ff151
3 changed files with 20 additions and 1 deletions

View File

@ -55,7 +55,8 @@ void kernel_main(multiboot_info_t *mbd, uint32_t magic)
terminal_initialize(); terminal_initialize();
create_process(1); create_process(1);
create_thread(current_pcb, shell_init); create_thread(current_pcb, shell_init);
create_thread(current_pcb, uwu); create_process(2);
create_thread(current_pcb->next, uwu);
toris(); toris();
while (true) while (true)
; ;

View File

@ -37,6 +37,8 @@ void scheduler(uint32_t *esp)
kpanic("No existing threads \n"); kpanic("No existing threads \n");
if (current_tcb) if (current_tcb)
current_tcb->esp = esp; current_tcb->esp = esp;
if (thread_to_switch->process != current_pcb)
switch_process(thread_to_switch->process);
current_tcb = thread_to_switch; current_tcb = thread_to_switch;
switch_thread(thread_to_switch->esp); switch_thread(thread_to_switch->esp);
} }

View File

@ -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