From cc23ea5a4b38807e79aceb23e6f43e965926618f Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Fri, 9 Oct 2026 10:24:41 -0400 Subject: add basic scheduler logic. rename init rootdir indexes --- sys/objdir.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 sys/objdir.c (limited to 'sys/objdir.c') diff --git a/sys/objdir.c b/sys/objdir.c new file mode 100644 index 0000000..c448e85 --- /dev/null +++ b/sys/objdir.c @@ -0,0 +1,114 @@ +#include "api/error.h" +#include "arch/x86_64/hal/obj.h" +#include "hal/memory.h" +#include "hal/obj.h" +#include "lib/string.h" +#include "jove.h" +#include + +int +objdir_new(jove_owned_obj_t *untyped_obj) +{ + jove_untyped_t *untyped = obj_deref(untyped_obj); + if((uintptr_t)untyped & (JOVE_OBJDIR_SIZE - 1)) return -EALIGN; + if(untyped->limit != JOVE_OBJDIR_SIZE) return -EBADSIZE; + + memset(untyped, 0, JOVE_OBJDIR_SIZE); + obj_settype(untyped_obj, JOVE_OBJ_OBJDIR); + return 0; +} + +jove_obj_t +objdir_peeklocal( + jove_owned_obj_t *objdir_obj, + uint16_t entry) +{ + if(obj_gettype(objdir_obj) != JOVE_OBJ_OBJDIR) { + errno = EBADOBJ; + return (jove_obj_t) { 0 }; + } + if(entry >= JOVE_OBJDIR_ENTRIES) { + errno = EBADPATH; + return (jove_obj_t) { 0 }; + } + + jove_objdir_t *objtab = obj_deref(objdir_obj); + return objtab->entries[entry]; +} + +jove_owned_obj_t* +objdir_getlocal( + jove_owned_obj_t *objdir_obj, + uint16_t entry) +{ + if(obj_gettype(objdir_obj) != JOVE_OBJ_OBJDIR) { + reterr(EBADOBJ); + } + if(entry >= JOVE_OBJDIR_ENTRIES) { + reterr(EBADPATH); + } + + jove_objdir_t *objtab = obj_deref(objdir_obj); + return obj_take(&objtab->entries[entry]); +} + +jove_owned_obj_t* +objdir_trygetlocal( + jove_owned_obj_t *objdir_obj, + uint16_t entry) +{ + if(obj_gettype(objdir_obj) != JOVE_OBJ_OBJDIR) { + reterr(EBADOBJ); + } + if(entry >= JOVE_OBJDIR_ENTRIES) { + reterr(EBADPATH); + } + + jove_objdir_t *objtab = obj_deref(objdir_obj); + return obj_trytake(&objtab->entries[entry]); +} + +jove_owned_obj_t* +objdir_getobj( + jove_owned_obj_t *objdir_obj, + const uint16_t *path, + size_t path_len) +{ + errno = 0; + if(path_len == 0) { + return objdir_obj; + } + { + jove_owned_obj_t *child_objdir = objdir_getlocal(objdir_obj, path[0]); + if(child_objdir == 0) { + reterr(EBADPATH); + } + + jove_owned_obj_t *target_obj = objdir_getobj(child_objdir, path + 1, path_len - 1); + obj_release(child_objdir); + return target_obj; + } +} + +jove_owned_obj_t* +objdir_trygetobj( + jove_owned_obj_t *objdir_obj, + const uint16_t *path, + size_t path_len) +{ + errno = 0; + if(path_len == 0) { + return objdir_obj; + } + { + jove_owned_obj_t *child_objdir = objdir_trygetlocal(objdir_obj, path[0]); + if(child_objdir == 0) { + return 0; + } + + jove_owned_obj_t *target_obj = objdir_trygetobj(child_objdir, path + 1, path_len - 1); + obj_release(child_objdir); + return target_obj; + } +} + -- cgit v1.2.3