diff options
Diffstat (limited to 'hal/untyped.c')
| -rw-r--r-- | hal/untyped.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/hal/untyped.c b/hal/untyped.c new file mode 100644 index 0000000..243f3ec --- /dev/null +++ b/hal/untyped.c @@ -0,0 +1,54 @@ +#include "arch/x86_64/hal/obj.h" +#include "jove.h" +#include "memory.h" + +size_t +untyped_size(jove_owned_obj_t *tgt) +{ + return ((jove_untyped_t*)obj_deref(tgt))->limit; +} + +size_t +untyped_align(jove_owned_obj_t *tgt) +{ + return (uintptr_t)obj_deref(tgt) & 0xFFF; +} + +int +untyped_split(jove_owned_obj_t *tgt, jove_owned_obj_t *dst, size_t bytes) +{ + jove_untyped_t *tgt_untyped = obj_deref(tgt); + if(bytes < JOVE_UNTYPED_MINSIZE) return EBADARG; + if(tgt_untyped->limit - bytes < JOVE_UNTYPED_MINSIZE) return ETOOSMALL; + + tgt_untyped->limit -= bytes; + obj_settype(dst, JOVE_OBJ_UNTYPED); + obj_setvalue(dst, (uintptr_t)tgt_untyped + tgt_untyped->limit); + + jove_untyped_t *dst_untyped = obj_deref(dst); + dst_untyped->limit = bytes; + return 0; +} + +int +untyped_merge(jove_owned_obj_t *a, jove_owned_obj_t *b) +{ + jove_untyped_t *a_untyped = obj_deref(a); + jove_untyped_t *b_untyped = obj_deref(b); + if((uintptr_t)a_untyped + a_untyped->limit == (uintptr_t)b_untyped) { + return EBADARG; + } + if((uintptr_t)b_untyped + b_untyped->limit == (uintptr_t)a_untyped) { + return untyped_merge(b, a); + } + + a_untyped->limit += b_untyped->limit; + obj_settype(b, JOVE_OBJ_NONE); + return 0; +} + +int untyped_retype(jove_owned_obj_t *tgt, uint8_t newtype) +{ + obj_settype(tgt, newtype); + return 0; +} |
