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.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 arch/x86_64/hal/obj.h (limited to 'arch/x86_64/hal/obj.h') diff --git a/arch/x86_64/hal/obj.h b/arch/x86_64/hal/obj.h new file mode 100644 index 0000000..645727d --- /dev/null +++ b/arch/x86_64/hal/obj.h @@ -0,0 +1,79 @@ +#ifndef _JOVE_ARCH_HAL_OBJ_H +#define _JOVE_ARCH_HAL_OBJ_H 1 + +#include +#include +#include + +enum +{ + JOVE_OBJ_SERIAL_COM = 0x81, + JOVE_OBJ_PAGE_FRAME, + JOVE_OBJ_PAGE_MAPPING, +}; + +/*Represents a locked kernel object pointer inside of a object directory.*/ +typedef union jove_obj +{ + struct { + uint8_t type; + atomic_flag lock; + /*Raw value or pointer to a data-structure located in kernel memory.*/ + uint64_t value : 48; + }; + uintmax_t data; +} jove_obj_t; + +/*Represents an unlocked kernel object pointer. + *This object should only exist temporarily while accessing the underlying + *structure this object points to.*/ +typedef union jove_obj_locked +{ + struct { + uint8_t type; + uint8_t lock; + uint64_t value : 48; + }; + uintmax_t data; +} jove_owned_obj_t; + +/*Object directories are always 1 page wide. Since an object inside the directory + * is a pointer width, on x86_64 that is 512 entries per directory.*/ +#define JOVE_OBJDIR_SIZE 0x1000 +#define JOVE_OBJDIR_ENTRIES (JOVE_OBJDIR_SIZE / sizeof(jove_obj_t)) + +typedef struct jove_objdir +{ + jove_obj_t entries[JOVE_OBJDIR_ENTRIES]; +} jove_objdir_t; +/*Locks the mutex of the kernel object provided. Returns the locked version. */ +jove_owned_obj_t *obj_take(jove_obj_t *obj); +/*Unlocks the mutex of the kernel object provided. Returns the unlocked version. */ +jove_obj_t *obj_release(jove_owned_obj_t *obj); + +/*Converts the value pointer of the object into a pointer to kernel memory.*/ +void *obj_deref(jove_owned_obj_t *obj); + +/*Getters and setters for accessing the type field of the kernel object. */ +uint8_t obj_gettype(jove_owned_obj_t *obj); +void obj_settype(jove_owned_obj_t *obj, uint8_t type); + +/*Getters and setters for accessing the value field of the kernel object. */ +uintmax_t obj_getvalue(jove_owned_obj_t *obj); +void obj_setvalue(jove_owned_obj_t *obj, uintmax_t value); + +/*Returns the n'th entry of the object directory passed. + * If the passed object is not an objdir, returns NULL and sets errno to EBADOBJ. + * If the passed entry index is out of bounds, returns NULL and sets errno to EOOB.*/ +jove_obj_t *objdir_getlocal(jove_owned_obj_t *objdir_obj, uint16_t entry); + +/*Recursively seeks through an object directory for an object following the passed + * path variable. + * If the path length is zero, returns the passed object. + * If the passed object is not an objdir, returns NULL and sets errno to EBADOBJ. + * If any object excluding the object at the end of the path is not an objdir, + * returns NULL and sets errno to EBADOBJ. + * If any entry in the path is out of bounds, returns NULL and sets errno to EBADOBJ.*/ +jove_owned_obj_t *objdir_getobj(jove_owned_obj_t *objdir_obj, const uint16_t *path, size_t path_len); + +#endif -- cgit v1.2.3