wip: context switch when switching to another process
This commit is contained in:
@ -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)
|
||||
;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
16
src/multitasking/switch_process.s
Normal file
16
src/multitasking/switch_process.s
Normal 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
|
||||
Reference in New Issue
Block a user