diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2025-08-10 15:46:33 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2025-08-10 15:46:33 -0400 |
commit | 65ba015d6c1f248d36ad01a653bc49637804b15b (patch) | |
tree | a77c3fb3ca7ecac8f65eb9638d152f1e90307d0a /lib/libjove/syscall | |
download | jove-os-65ba015d6c1f248d36ad01a653bc49637804b15b.tar.gz jove-os-65ba015d6c1f248d36ad01a653bc49637804b15b.tar.bz2 jove-os-65ba015d6c1f248d36ad01a653bc49637804b15b.zip |
working usermode objdir iteration
Diffstat (limited to 'lib/libjove/syscall')
-rw-r--r-- | lib/libjove/syscall/debug_putc.c | 13 | ||||
-rw-r--r-- | lib/libjove/syscall/invoke-objdir.c | 39 | ||||
-rw-r--r-- | lib/libjove/syscall/invoke-untyped.c | 52 | ||||
-rw-r--r-- | lib/libjove/syscall/invoke.c | 14 | ||||
-rw-r--r-- | lib/libjove/syscall/path-fromobj.c | 33 |
5 files changed, 151 insertions, 0 deletions
diff --git a/lib/libjove/syscall/debug_putc.c b/lib/libjove/syscall/debug_putc.c new file mode 100644 index 0000000..2d68ee1 --- /dev/null +++ b/lib/libjove/syscall/debug_putc.c @@ -0,0 +1,13 @@ +#include "jove/syscall.h" +#include "jove/jove.h" +#include <kernel/syscall.h> + +void +_syscall_debug_putc(char c) +{ + *((char*)_syscall_message_ptr) = c; + register uint64_t box asm ("rdi") = _syscall_message_box; + register uint64_t call asm ("rsi") = SYSCALL_DEBUG_PUTC; + + __asm__ volatile("syscall"::: "memory"); +} diff --git a/lib/libjove/syscall/invoke-objdir.c b/lib/libjove/syscall/invoke-objdir.c new file mode 100644 index 0000000..462c282 --- /dev/null +++ b/lib/libjove/syscall/invoke-objdir.c @@ -0,0 +1,39 @@ +#include <jove.h> +#include <object.h> +#include <path-fromobj.h> +#include <syscall.h> +#include <kernel/syscall.h> + +int +_syscall_invoke_objdir_getmemb(KernelObjectDirectory *dir, uint8_t member, obj_type_t *result) +{ + uint8_t *syscallData = _syscall_message_ptr; + int syscall_at = 0; + obj_type_t *syscall_result; + + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, dir); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, INVOKE_OBJDIR_GETMEMB, uint8_t); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, member, uint8_t); + SYSCALL_PAYLOAD_SAVEPTR(syscallData, syscall_at, obj_type_t, syscall_result); + + int status = _syscall_invoke(); + *result = *syscall_result; + return status; +} + +int +_syscall_invoke_objdir_nmemb(KernelObjectDirectory *dir, uint8_t *result) +{ + uint8_t *syscallData = _syscall_message_ptr; + int syscall_at = 0; + uint8_t *syscall_result; + + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, dir); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, INVOKE_OBJDIR_NMEMB, uint8_t); + SYSCALL_PAYLOAD_SAVEPTR(syscallData, syscall_at, uint8_t, syscall_result); + + int status = _syscall_invoke(); + *result = *syscall_result; + + return status; +} diff --git a/lib/libjove/syscall/invoke-untyped.c b/lib/libjove/syscall/invoke-untyped.c new file mode 100644 index 0000000..3f718c2 --- /dev/null +++ b/lib/libjove/syscall/invoke-untyped.c @@ -0,0 +1,52 @@ +#include <jove.h> +#include <object.h> +#include <path-fromobj.h> +#include <syscall.h> +#include <kernel/syscall.h> +#include <string.h> + +int +_syscall_invoke_untyped_size(KernelObjectUntyped *untyped, size_t *bytes) +{ + uint8_t *syscallData = _syscall_message_ptr; + int syscall_at = 0; + size_t *syscall_bytes; + + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, untyped); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, INVOKE_UNTYPED_SIZE, uint8_t); + SYSCALL_PAYLOAD_SAVEPTR(syscallData, syscall_at, size_t, syscall_bytes); + + int status = _syscall_invoke(); + *bytes = *syscall_bytes; + return status; +} + +int +_syscall_invoke_untyped_split(KernelObjectUntyped *untyped, size_t bytes, KernelObjectUntyped *dest) +{ + uint8_t *syscallData = _syscall_message_ptr; + int syscall_at = 0; + + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, untyped); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, INVOKE_UNTYPED_SPLIT, uint8_t); + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, dest); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, bytes, size_t); + + return _syscall_invoke(); +} + +int +_syscall_invoke_untyped_alignment(KernelObjectUntyped *untyped, size_t *alignment) +{ + uint8_t *syscallData = _syscall_message_ptr; + int syscall_at = 0; + size_t *syscall_alignment; + + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, untyped); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, INVOKE_UNTYPED_ALIGNMENT, uint8_t); + SYSCALL_PAYLOAD_SAVEPTR(syscallData, syscall_at, size_t, syscall_alignment); + + int status = _syscall_invoke(); + *alignment = *syscall_alignment; + return status; +} diff --git a/lib/libjove/syscall/invoke.c b/lib/libjove/syscall/invoke.c new file mode 100644 index 0000000..e673623 --- /dev/null +++ b/lib/libjove/syscall/invoke.c @@ -0,0 +1,14 @@ +#include <syscall.h> +#include <kernel/syscall.h> +#include <jove.h> + +int +_syscall_invoke(void) +{ + register uint64_t box asm ("rdi") = _syscall_message_box; + register uint64_t call asm ("rsi") = SYSCALL_INVOKE; + + int status = 0; + __asm__ volatile("syscall": "=a"(status) :: "memory"); + return status; +} diff --git a/lib/libjove/syscall/path-fromobj.c b/lib/libjove/syscall/path-fromobj.c new file mode 100644 index 0000000..1c0c5d9 --- /dev/null +++ b/lib/libjove/syscall/path-fromobj.c @@ -0,0 +1,33 @@ +#include <path-fromobj.h> + +int +path_fromobj_s(KernelObjectTyped *obj, uint8_t *buffer, int size) +{ + size_t depth = 0, odepth = 0; + for(KernelObjectTyped *o = obj->parent; o; o = o->parent, depth++); + + odepth = depth; + if(depth > size) depth = size; + + for(int i = 0; i < depth; i++) { + buffer[depth - i - 1] = obj->membi; + obj = obj->parent; + } + return odepth; +} + +int +path_tobuf(KernelObjectTyped *obj, uint8_t *buffer, size_t at, size_t bufferw) +{ + if(at + sizeof(size_t) > bufferw) return -1; + + size_t *buffer_pathW = (size_t*)(&buffer[at]); + uint8_t *buffer_path = (uint8_t*)(&buffer_pathW[1]); + + size_t maxDepth = bufferw - (buffer_path - buffer); + size_t objDepth = path_fromobj_s(obj, buffer_path, bufferw - (size_t)(buffer_path - buffer)); + if(objDepth > maxDepth) return -1; + + *buffer_pathW = objDepth; + return (int)(buffer_path - buffer) + objDepth; +} |