working on reading elf from initrd, and getting it launched with the new scheduler

This commit is contained in:
2026-06-30 19:26:31 -05:00
parent ce81d4eb31
commit af6c1c94cf
21 changed files with 253 additions and 151 deletions

View File

@@ -8,6 +8,7 @@
#include "common.h"
#include "process.h"
#include "scheduler.h"
#include "gdt.h"
static process_t* process_table;
@@ -68,9 +69,10 @@ uint32_t switch_context(uint32_t current_esp) {
current_process = next_process;
tss.esp0 = process_table[current_process].esp0;
if (fetch_cr3() != process_table[current_process].cr3) {
extern void load_pd(uint32_t table);
load_pd(process_table[current_process].cr3);
load_pd((void*)process_table[current_process].cr3);
}
return process_table[current_process].esp;
@@ -88,12 +90,12 @@ void init_scheduler() {
process->sleep = 0;
total_processes++;
create_task((uint32_t)idle_task, fetch_cr3());
create_task((uint32_t)idle_task, fetch_cr3(), 0);
current_process = 0;
}
int create_task(uint32_t entry_point, uint32_t cr3) {
int create_task(uint32_t entry_point, uint32_t cr3, int user) {
if (total_processes >= 16) {
return 0;
}
@@ -117,10 +119,20 @@ int create_task(uint32_t entry_point, uint32_t cr3) {
void* stack_bottom = kalloc(4096);
uint32_t* esp = (uint32_t*)((uint32_t)stack_bottom + 4096);
process->esp0 = (uint32_t)esp;
*(--esp) = 0x0202; // EFLAGS
*(--esp) = 0x08; // CS
*(--esp) = entry_point; // EIP
if (user) {
*(--esp) = 0x23; // User Data Segment (SS) with RPL 3 (0x20 | 3)
*(--esp) = 0xBFFFF000; // User Stack Pointer (ESP) - location mapped in user space
*(--esp) = 0x0202; // 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) = 0x08; // Kernel Code Segment (CS)
*(--esp) = entry_point; // EIP
}
*(--esp) = 0; // EAX
*(--esp) = 0; // ECX