First Hello world syscall
All checks were successful
Build documentation / build-and-deploy (push) Successful in 26s

This commit is contained in:
2026-01-03 02:04:09 +01:00
parent 1341dc00d9
commit e52268cd8e
26 changed files with 228 additions and 140 deletions

View File

@@ -1,12 +1,17 @@
#include <amd64/gdt.h>
#include <aux/elf.h>
#include <libk/std.h>
#include <libk/string.h>
#include <limine/requests.h>
#include <mm/liballoc.h>
#include <mm/pmm.h>
#include <proc/proc.h>
#include <sync/spin_lock.h>
#include <sys/debug.h>
struct proc* proc_from_elf (uint8_t* elf_contents) {
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
struct proc* proc = malloc (sizeof (*proc));
if (proc == NULL)
return NULL;
@@ -20,22 +25,21 @@ struct proc* proc_from_elf (uint8_t* elf_contents) {
return NULL;
}
proc->pdata.syscall_stack = pmm_alloc (KSTACK_SIZE / PAGE_SIZE);
if (proc->pdata.syscall_stack == PMM_ALLOC_ERR) {
proc->pdata.kernel_stack = pmm_alloc (KSTACK_SIZE / PAGE_SIZE);
if (proc->pdata.kernel_stack == PMM_ALLOC_ERR) {
free (proc);
return NULL;
}
uintptr_t kernel_stack = proc->pdata.kernel_stack;
proc->pdata.kernel_stack += (uintptr_t)hhdm->offset + KSTACK_SIZE;
proc->pdata.user_stack = pmm_alloc (USTACK_SIZE / PAGE_SIZE);
if (proc->pdata.user_stack == PMM_ALLOC_ERR) {
free (proc);
pmm_free (proc->pdata.syscall_stack, USTACK_SIZE / PAGE_SIZE);
pmm_free (kernel_stack, USTACK_SIZE / PAGE_SIZE);
return NULL;
}
uintptr_t user_stack = proc->pdata.user_stack;
proc->pdata.syscall_stack += KSTACK_SIZE;
proc->pdata.user_stack += USTACK_SIZE;
proc_map (proc, user_stack, PROC_USTACK_TOP - USTACK_SIZE, USTACK_SIZE / PAGE_SIZE,
@@ -43,10 +47,10 @@ struct proc* proc_from_elf (uint8_t* elf_contents) {
struct elf_aux aux = proc_load_segments (proc, elf_contents);
proc->pdata.regs.ss = 0x20 | 0x03;
proc->pdata.regs.ss = GDT_UDATA | 0x03;
proc->pdata.regs.rsp = (uint64_t)PROC_USTACK_TOP;
proc->pdata.regs.rflags = 0x202;
proc->pdata.regs.cs = 0x18 | 0x03;
proc->pdata.regs.cs = GDT_UCODE | 0x03;
proc->pdata.regs.rip = aux.entry;
proc->lock = SPIN_LOCK_INIT;
atomic_store (&proc->state, PROC_READY);