f'd myself over of course, scheduler can now run user programs....

This commit is contained in:
2026-07-04 01:59:19 -05:00
parent 0b98ac0273
commit 17ccde3556
11 changed files with 109 additions and 60 deletions

View File

@@ -69,17 +69,13 @@ uint32_t switch_context(uint32_t current_esp) {
uint32_t current_cr3 = fetch_cr3();
if (current_cr3 != process_table[current_process].cr3) {
kprintf("switching cr3 | old: 0x%x | new: 0x%x\n", current_cr3, process_table[current_process].cr3);
load_pd((void*)process_table[current_process].cr3);
}
if (process_table[current_process].flags & PROCESS_FLAG_USER) {
tss.esp0 = process_table[current_process].kstack_top;
}
if (found_ready) {
kprintf("found ready task %d | cr3: 0x%x\n", current_process, process_table[current_process].cr3);
}
return process_table[current_process].esp;
}
@@ -123,12 +119,12 @@ int create_task(uint32_t entry_point, uint32_t cr3, int user, uint32_t u_esp) {
if (user) {
*(--esp) = 0x23; // User Data Segment (SS) with RPL 3 (0x20 | 3)
*(--esp) = u_esp; // User Stack Pointer (ESP) - location mapped in user space
*(--esp) = 0x0202; // EFLAGS (Interrupts enabled)
*(--esp) = 0x202; // EFLAGS (Interrupts enabled)
*(--esp) = 0x1B; // User Code Segment (CS) with RPL 3 (0x18 | 3)
*(--esp) = entry_point; // EIP
} else {
// IRET values for Ring 0
*(--esp) = 0x0202; // EFLAGS
*(--esp) = 0x202; // EFLAGS
*(--esp) = 0x08; // Kernel Code Segment (CS)
*(--esp) = entry_point; // EIP
}
@@ -142,6 +138,12 @@ int create_task(uint32_t entry_point, uint32_t cr3, int user, uint32_t u_esp) {
*(--esp) = 0; // ESI
*(--esp) = 0; // EDI
if (user) {
*(--esp) = 0x23; // User Data Segment Selector (RPL 3)
} else {
*(--esp) = 0x10; // Kernel Data Segment Selector (RPL 0)
}
process->esp = (uint32_t)esp;
return 1;
}