From 7f350e7ee1c2c38e5ac0b6c22c17388f6c78f0b5 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Wed, 10 Sep 2025 13:28:28 -0400 Subject: refactor paging code. regression on loading init program --- lib/untyped-retype.c | 38 +++++++++++++++++++++++++++++++++++--- lib/untyped.c | 16 ++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 lib/untyped.c (limited to 'lib') diff --git a/lib/untyped-retype.c b/lib/untyped-retype.c index 70fb4d2..526f19e 100644 --- a/lib/untyped-retype.c +++ b/lib/untyped-retype.c @@ -1,11 +1,43 @@ -#include -#include +#include "object.h" +#include "memory.h" #include -#include +#include "error.h" +#include "string.h" int ko_untyped_retype_objdir(objdir_entry_t *target) { size_t *untyped = ko_entry_data(target); if(*untyped != 0x1000) return -KE_BADSIZE; + + objdir_t *objdir = (objdir_t*)untyped; + memset(objdir, 0, 0x1000); + + objdir->self = (objdir_entry_t) { + .type = KO_OBJECT_DIRECTORY, + .data = target->data + }; + *target = (objdir_entry_t) { + .type = KO_OBJECT_DIRECTORY, + .lock = 0, + .extra = 0, + .data = objdir->self.data + }; + return 0; +} + +int +ko_untyped_retype_message(objdir_entry_t *target, uintptr_t vptr) +{ + size_t *untyped = ko_entry_data(target); + if(*untyped != 0x1000) return -KE_BADSIZE; + + memset(untyped, 0, KO_MESSAGE_BYTES); + *target = (objdir_entry_t) { + .type = KO_OBJECT_DIRECTORY, + .lock = 0, + .extra = 0, + .data = target->data + }; + return 0; } diff --git a/lib/untyped.c b/lib/untyped.c new file mode 100644 index 0000000..8a20f63 --- /dev/null +++ b/lib/untyped.c @@ -0,0 +1,16 @@ +#include "include/object.h" +#include "error.h" + +int +ko_untyped_split(objdir_entry_t *target, objdir_entry_t *dest, size_t bytes) +{ + size_t *untyped = ko_entry_data(target); + if(*untyped <= bytes) return KE_TOOSMALL; + + *untyped -= bytes; + dest->data = target->data + *untyped; + *(size_t*)ko_entry_data(dest) = bytes; + dest->type = KO_MEMORY_UNTYPED; + + return 0; +} -- cgit v1.2.1