From 8251da342161767fe203627223ccd4a7026701c6 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Fri, 4 Sep 2026 11:31:40 -0400 Subject: initial commit. working on tasking --- arch/x86_64/hal/obj.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 arch/x86_64/hal/obj.c (limited to 'arch/x86_64/hal/obj.c') diff --git a/arch/x86_64/hal/obj.c b/arch/x86_64/hal/obj.c new file mode 100644 index 0000000..783d2f4 --- /dev/null +++ b/arch/x86_64/hal/obj.c @@ -0,0 +1,87 @@ +#include "obj.h" +#include "arch/x86_64/lock.h" +#include "hal/obj.h" +#include "jove.h" + +jove_owned_obj_t* +obj_take(jove_obj_t *obj) +{ + take_mutex(&obj->lock); + return (jove_owned_obj_t*)obj; +} + +jove_obj_t* +obj_release(jove_owned_obj_t *obj) +{ + release_mutex((atomic_flag*)&obj->lock); + return (jove_obj_t*)obj; +} + +void* +obj_deref(jove_owned_obj_t *obj) +{ + return (void*)(((uintptr_t)obj_getvalue(obj)) | 0xFFFF800000000000ULL); +} + +uint8_t +obj_gettype(jove_owned_obj_t *obj) +{ + return obj->type; +} + +void +obj_settype(jove_owned_obj_t *obj, uint8_t type) +{ + obj->type = type; +} + +uintmax_t +obj_getvalue(jove_owned_obj_t *obj) +{ + return obj->value; +} + +void +obj_setvalue(jove_owned_obj_t *obj, uintmax_t value) +{ + obj->value = value & 0x00007FFFFFFFFFFFULL; +} + +jove_obj_t* +objdir_getlocal( + jove_owned_obj_t *objdir_obj, + uint16_t entry) +{ + if(objdir_obj->type != JOVE_OBJ_OBJDIR) { + reterr(EBADOBJ); + } + if(entry >= JOVE_OBJDIR_ENTRIES) { + reterr(EOOB); + } + + jove_objdir_t *objtab = obj_deref(objdir_obj); + return &objtab->entries[entry]; +} + +jove_owned_obj_t* +objdir_getobj( + jove_owned_obj_t *objdir_obj, + const uint16_t *path, + size_t path_len) +{ + if(path_len == 0) { + return objdir_obj; + } + { + jove_obj_t *child_locked_objdir = objdir_getlocal(objdir_obj, path[0]); + if(child_locked_objdir == NULL) { + return 0; + } + + jove_owned_obj_t *child_objdir = obj_take(child_locked_objdir); + jove_owned_obj_t *target_obj = objdir_getobj(child_objdir, path + 1, path_len - 1); + obj_release(child_objdir); + return target_obj; + } +} + -- cgit v1.2.3