Implement syscalls, hello world from userspace

This commit is contained in:
2025-09-02 23:51:14 +02:00
parent 920de10025
commit 8a12f23b69
24 changed files with 313 additions and 44 deletions

View File

@ -15,12 +15,6 @@
#define PROC_REAPER_FREQ 30
#define PROC_DIE() \
do { \
proc_killself(); \
for(;;); \
} while(0)
uint64_t pids = 0;
uint64_t sched_ticks = 0;
@ -161,8 +155,16 @@ void proc_register(Proc *proc) {
}
Proc *proc_nextready(void) {
Proc *next = PROCS.current->next;
Proc *proc = next == NULL ? PROCS.procs : next;
Proc *proc = PROCS.current->next;
for (;;) {
if (proc == NULL) {
proc = PROCS.procs;
}
if (proc->state != PROC_ZOMBIE) {
return proc;
}
proc = proc->next;
}
return proc;
}
@ -183,7 +185,7 @@ void proc_reaper(void) {
while (vashead) {
VasRange *tmp = vashead;
vashead = vashead->next;
hal_vmm_unmap_range(zombie->platformdata.cr3, tmp->virtstart, tmp->physstart, tmp->size);
hal_vmm_unmap_range(VIRT(zombie->platformdata.cr3), tmp->virtstart, tmp->physstart, tmp->size);
// first pmm mapping is for the elf itself
if (i == 0) {
pmm_free((uintptr_t)tmp->physstart, tmp->size / HAL_PAGE_SIZE);
@ -218,6 +220,7 @@ void proc_sched(void *cpustate) {
PROCS.current->state = PROC_RUNNING;
hal_cpu_wrmsr(HAL_CPU_FSBASE, PROCS.current->platformdata.fsbase);
HAL_CPUS[0].syscall_kstack = VIRT(PROCS.current->platformdata.kstack);
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
}
@ -239,11 +242,12 @@ void proc_idle(void) {
}
void proc_status(void) {
static const char *statuses[] = {"ready", "running", "zombie", "waiting"};
for (;;) {
spinlock_acquire(&PROCS.spinlock);
Proc *head = PROCS.procs;
while (head) {
kprintf("%s %s\n", head->kern ? "kern" : "user", head->name);
kprintf("%s %s %s\n", head->kern ? "kern" : "user", statuses[head->state], head->name);
head = head->next;
}
kprintf("\n\n");