From 779b7fc1fe91e5a355b6e15de882d46b26ab2270 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Sat, 5 Sep 2026 20:24:13 -0400 Subject: working syscalls. --- arch/x86_64/hal/obj.h | 2 +- arch/x86_64/hal/process.c | 37 +++++++++++++++++++++++++++++++++++-- arch/x86_64/hal/process.h | 14 ++------------ arch/x86_64/hal/smp.c | 8 ++------ arch/x86_64/hal/smp.h | 2 ++ 5 files changed, 42 insertions(+), 21 deletions(-) (limited to 'arch/x86_64/hal') diff --git a/arch/x86_64/hal/obj.h b/arch/x86_64/hal/obj.h index f7d7711..78d7383 100644 --- a/arch/x86_64/hal/obj.h +++ b/arch/x86_64/hal/obj.h @@ -7,7 +7,7 @@ enum { - JOVE_OBJ_SERIAL_COM = 0x81, + JOVE_OBJ_SERIAL_COM = 0x80, }; /*Represents a locked kernel object pointer inside of a object directory.*/ diff --git a/arch/x86_64/hal/process.c b/arch/x86_64/hal/process.c index 5c91238..872be5a 100644 --- a/arch/x86_64/hal/process.c +++ b/arch/x86_64/hal/process.c @@ -1,6 +1,8 @@ #include "process.h" #include "arch/x86_64/hal/obj.h" #include "hal/obj.h" +#include "hal/process.h" +#include "hal/smp.h" #include "init.h" #include "smp.h" #include "paging.h" @@ -9,22 +11,53 @@ PAGEALIGN char s_init_pcb_bytes[0x1000] = { 0 }; static pcb_t *s_init_pcb = (pcb_t*)&s_init_pcb_bytes; +jove_owned_obj_t* +process_current(void) +{ + return obj_take(((processor_t*)processor_current())->pcb_obj); +} + +pcb_t* +pcb_from_obj(jove_owned_obj_t *obj) +{ + if(obj_gettype(obj) != JOVE_OBJ_PROCESS) { + reterr(EBADOBJ); + } + return obj_deref(obj); +} + +pid_t +pcb_pid(pcb_t *pcb) +{ + return pcb->pid; +} + +jove_owned_obj_t* +pcb_rootdir(pcb_t *pcb) +{ + return obj_take(pcb->rootdir); +} + void processing_setup(void (*process_main)) { uintptr_t ksp = ((uintptr_t)&s_init_pcb_bytes) + 0xFF0; + + s_init_pcb->pid = 1; s_init_pcb->ksp = (void*)ksp; s_init_pcb->pml4 = paging_get_pml4(); + s_init_pcb->rootdir = _rootdir_obj; processor_t *proc = processor_current(); - proc->pcb = s_init_pcb; proc->tss.rsp[0] = (uintptr_t)s_init_pcb->ksp; { jove_owned_obj_t *process_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_PCB_I); obj_settype(process_obj, JOVE_OBJ_PROCESS); obj_setvalue(process_obj, (uintptr_t)s_init_pcb); - obj_release(process_obj); + + proc->pcb_obj = obj_release(process_obj); + proc->pcb = s_init_pcb; } __asm__ volatile("\ diff --git a/arch/x86_64/hal/process.h b/arch/x86_64/hal/process.h index 0c0fb5b..65b2318 100644 --- a/arch/x86_64/hal/process.h +++ b/arch/x86_64/hal/process.h @@ -1,22 +1,12 @@ #ifndef _JOVE_x86_64_HAL_PROCESS_H #define _JOVE_x86_64_HAL_PROCESS_H 1 -#include "hal/obj.h" +#include "hal/process.h" #include "arch/x86_64/x86_64.h" -enum pcb_state -{ - PCB_DEAD, PCB_READY, PCB_RUNNING, PCB_BLOCKED -}; - -struct pcb_mailbox -{ - jove_obj_t *obj; - uintmax_t pcbid; -}; - typedef struct process_control_block { + pid_t pid; jove_obj_t *rootdir; uintptr_t pml4; diff --git a/arch/x86_64/hal/smp.c b/arch/x86_64/hal/smp.c index e0945c1..85ba4ec 100644 --- a/arch/x86_64/hal/smp.c +++ b/arch/x86_64/hal/smp.c @@ -1,4 +1,5 @@ #include "smp.h" +#include "hal/process.h" #include "init.h" #include "hal/obj.h" #include "config.h" @@ -55,12 +56,7 @@ smp_init_bsp(void) } } -void *processor_current(void) +processor_t *processor_current(void) { return (processor_t*)msr_get_gs_base(); } - -jove_obj_t *processor_objdir(void *processor) -{ - return ((processor_t*)processor)->pcb->rootdir; -} diff --git a/arch/x86_64/hal/smp.h b/arch/x86_64/hal/smp.h index 68e420f..5813dd3 100644 --- a/arch/x86_64/hal/smp.h +++ b/arch/x86_64/hal/smp.h @@ -3,6 +3,7 @@ #include "gdt.h" #include "process.h" +#include "hal/obj.h" #include "hal/smp.h" typedef struct processor @@ -10,6 +11,7 @@ typedef struct processor struct gdt_entry gdt[GDT_TSS_HI+1]; struct tss tss; + jove_obj_t *pcb_obj; pcb_t *pcb; } processor_t; -- cgit v1.2.3