summaryrefslogtreecommitdiffstats
path: root/lib/libjove/include
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libjove/include')
-rw-r--r--lib/libjove/include/arch/x86_64/object-pagemap.h44
-rw-r--r--lib/libjove/include/arch/x86_64/syscall.h12
-rw-r--r--lib/libjove/include/error.h22
-rw-r--r--lib/libjove/include/jove.h5
-rw-r--r--lib/libjove/include/object-dir.h82
-rw-r--r--lib/libjove/include/object-untyped.h91
-rw-r--r--lib/libjove/include/syscall.h11
7 files changed, 229 insertions, 38 deletions
diff --git a/lib/libjove/include/arch/x86_64/object-pagemap.h b/lib/libjove/include/arch/x86_64/object-pagemap.h
index 55b0570..48e959e 100644
--- a/lib/libjove/include/arch/x86_64/object-pagemap.h
+++ b/lib/libjove/include/arch/x86_64/object-pagemap.h
@@ -2,13 +2,51 @@
#define _LIBJOVE_ARCH_x86_64_OBJECT_PAGEMAP_H 1
#include <jove/object-typed.h>
+#include <jove/object-dir.h>
+#include <jove/object-untyped.h>
-typedef struct KernelObjectPageMapping
+typedef struct KernelObjectPageMap
{
KernelObjectTyped typed;
- uint8_t level;
-} KernelObjectPageMapping;
+} KernelObjectPageMap;
+KernelObjectPageMap *jove_object_as_pagemap(KernelObjectTyped *typed);
+/**@FUNC Populates a given region of memory for a page map value.
+ * @PARAM pagemap address of pagemap cache object.
+ * @PARAM dir directory this memory is a member of.
+ * @PARAM memb index into directory to place object.*/
+void _jove_alloc_pagemap_inplace(
+ KernelObjectPageMap *pagemap,
+ KernelObjectDirectory *dir,
+ uint8_t memb);
+
+/**@FUNC Allocates a region of memory to represent a page map.
+ * @PARAM dir directory to place new value in.
+ * @PARAM memb index into directory to place object.
+ * @RETURN newly allocated object. NULL on failure.
+ * Possible failures:
+ * EJOVE_FULL: Slot is already taken by an existing object.
+ * EJOVE_NOALLOC: libjove does not have an allocator yet.*/
+KernelObjectPageMap* _jove_alloc_pagemap(
+ KernelObjectDirectory *dir,
+ uint8_t memb);
+
+int jove_pagemap_exists(
+ KernelObjectPageMap *map,
+ uint8_t depth,
+ uint16_t *path);
+
+JoveError jove_pagemap_map(
+ KernelObjectPageMap *map,
+ uint8_t depth,
+ uint16_t *path,
+ KernelObjectUntyped *page);
+
+JoveError jove_pagemap_map_unmap(
+ KernelObjectPageMap *map,
+ uint8_t depth,
+ uint16_t *path,
+ KernelObjectUntyped *dest);
#endif
diff --git a/lib/libjove/include/arch/x86_64/syscall.h b/lib/libjove/include/arch/x86_64/syscall.h
index 1d7df53..74fb389 100644
--- a/lib/libjove/include/arch/x86_64/syscall.h
+++ b/lib/libjove/include/arch/x86_64/syscall.h
@@ -4,9 +4,17 @@
#include <stdint.h>
#include <kernel/object.h>
-#include <jove/object-path.h>
+#include <jove/arch/x86_64/object-pagemap.h>
+#include <jove/syscall.h>
-int _syscall_invoke_mapping_get(KernelObjectPath path, uint16_t pmli, KernelObjectPath destPath);
+#define SYSCALL_PAYLOAD_PUTPML(payload, payload_at, depth, path) \
+ if(payload_at + 1 + ((depth + 1) * sizeof(uint16_t)) > KO_MESSAGE_BYTES) return -1; \
+ *((uint8_t*)&payload[payload_at++]) = depth; \
+ for(uint8_t i = 0; i < depth + 1; i++) *((uint16_t*)&payload[payload_at + (i * 2)]) = path[i]; \
+ payload_at += (depth + 1) * 2
+int _syscall_invoke_mapping_exists(KernelObjectPageMap *map, uint8_t depth, uint16_t *path);
+int _syscall_invoke_mapping_map(KernelObjectPageMap *map, uint8_t depth, uint16_t *path, KernelObjectUntyped *untyped);
+int _syscall_invoke_mapping_unmap(KernelObjectPageMap *map, uint8_t depth, uint16_t *path, KernelObjectUntyped *dest);
#endif
diff --git a/lib/libjove/include/error.h b/lib/libjove/include/error.h
new file mode 100644
index 0000000..bbf7a51
--- /dev/null
+++ b/lib/libjove/include/error.h
@@ -0,0 +1,22 @@
+#ifndef _LIBJOVE_ERROR_H
+#define _LIBJOVE_ERROR_H 1
+
+typedef enum _JoveError{
+ EJOVE_OK = 0,
+ EJOVE_KERROR,
+ EJOVE_NOALLOC,
+ EJOVE_NOFREE,
+ EJOVE_NOIMPL,
+ EJOVE_FULL,
+ EJOVE_BADOBJ,
+ EJOVE_BADSIZE,
+ EJOVE_BADARG,
+ EJOVE_DNE,
+ EJOVE_TOOBIG
+} JoveError;
+
+extern JoveError jove_errno;
+
+JoveError jove_error_from_kerror(int kerror);
+
+#endif
diff --git a/lib/libjove/include/jove.h b/lib/libjove/include/jove.h
index 2efef3e..87eecb3 100644
--- a/lib/libjove/include/jove.h
+++ b/lib/libjove/include/jove.h
@@ -2,10 +2,15 @@
#define _LIBJOVE_JOVE_H 1
#include <stdint.h>
+#include <stddef.h>
extern uintmax_t _syscall_message_box;
extern void *_syscall_message_ptr;
+extern void *(*_jove_alloc)(size_t);
+extern void (*_jove_free)(void*);
+extern void *(*_jove_realloc)(void*, size_t);
+
void libjove_init(uintmax_t box, void *boxptr);
void jove_kprintf(const char *restrict fmt, ...);
diff --git a/lib/libjove/include/object-dir.h b/lib/libjove/include/object-dir.h
index f258089..e4d9aaf 100644
--- a/lib/libjove/include/object-dir.h
+++ b/lib/libjove/include/object-dir.h
@@ -6,12 +6,92 @@
#include <kernel/object.h>
#include <jove/object-typed.h>
+#include <jove/error.h>
-/**@STRUCT Represents a kobjdir.*/
+/**@STRUCT Represents cached information about a KO_OBJDIR.
+ * To update the information this struct contains, call jove_objdir_sync.*/
typedef struct _KernelObjectDirectory {
KernelObjectTyped typed;
+
+ uint8_t lastmemb;
+ uint8_t firstfree;
+
KernelObjectTyped *children[256];
} KernelObjectDirectory;
extern KernelObjectDirectory __rootdir;
+KernelObjectDirectory *jove_object_as_objdir(KernelObjectTyped *typed);
+
+/**@FUNC Populates a objdir struct for an empty directory at dir:memb.
+ * @PARAM dir address to populate.
+ * @PARAM parent directory to make dir child of.
+ * @PARAM memb index to place new objdir.*/
+void _jove_alloc_objdir_inplace(
+ KernelObjectDirectory *dir,
+ KernelObjectDirectory *parent,
+ uint8_t memb);
+
+/**@FUNC Allocates a block of memory to represent a kernel objdir.
+ * @PARAM parent directory to place new member into.
+ * @PARAM memb index to place new objdir.
+ * @RETURN pointer to new objdir.
+ * Possible failures:
+ * EJOVE_NOALLOC: libjove is missing an allocator.
+ * EJOVE_FULL: space at memb is already taken.*/
+KernelObjectDirectory *_jove_alloc_objdir(
+ KernelObjectDirectory *parent,
+ uint8_t memb);
+
+/**@FUNC Updates the dir struct with information obtained through the kernel.
+ * @PARAM dir directory to sync.
+ * @RETURN error code. 0 on success*/
+JoveError jove_objdir_sync(KernelObjectDirectory *dir);
+
+/**@FUNC Updates the dir struct at the given index with information obtained
+ * through the kernel.
+ * @PARAM dir directory to sync.
+ * @PARAM i index to sync.
+ * @PARAM memb pointer to place typed object in. Nullable
+ * @RETURN error code. 0 on success.*/
+JoveError jove_objdir_sync_at(KernelObjectDirectory *dir, uint8_t i, KernelObjectTyped** memb);
+
+/**@FUNC Returns the number of populated entries this directory holds.
+ * @PARAM dir directory to check
+ * @RETURN number of entries. negative return values indicate an error.*/
+int jove_objdir_nmemb(KernelObjectDirectory *dir);
+
+/**@FUNC Gets the highest populated index in a given directory.
+ * @PARAM dir directory to check.
+ * @RETURN last populated entry. negative return values indicate an error.*/
+int jove_objdir_lastmemb(KernelObjectDirectory *dir);
+
+/**@FUNC Gets the kernel object at a given index.
+ * This function only checks the cached result. If the directory has changed
+ * without updating the cache, jove_objdir_sync MUST be called first.
+ *
+ * @PARAM dir directory to check in.
+ * @PARAM index index to check.
+ * @RETURN the object at the given index. NULL if the spot is empty.*/
+KernelObjectTyped *jove_objdir_get(KernelObjectDirectory *dir, uint8_t index);
+
+/**@FUNC Moves a kernel object in this directory to a different place/directory.
+ * @PARAM dir directory holding the object.
+ * @PARAM memb member index of the object.
+ * @PARAM dest_dir destination directory.
+ * @PARAM dest_memb destination member.*/
+JoveError jove_objdir_move(
+ KernelObjectDirectory *dir,
+ uint8_t memb,
+ KernelObjectDirectory *dest_dir,
+ uint8_t dest_memb);
+
+JoveError jove_object_move(
+ KernelObjectTyped *typed,
+ KernelObjectDirectory *dest_dir,
+ uint8_t dest_memb);
+
+JoveError jove_object_move_inplace(
+ KernelObjectTyped *typed,
+ KernelObjectTyped *dest);
+
#endif
diff --git a/lib/libjove/include/object-untyped.h b/lib/libjove/include/object-untyped.h
index ea1185d..e7715b0 100644
--- a/lib/libjove/include/object-untyped.h
+++ b/lib/libjove/include/object-untyped.h
@@ -2,38 +2,73 @@
#define _LIBJOVE_OBJECT_UNTYPED_H 1
#include <jove/object-typed.h>
+#include <jove/object-dir.h>
/**@STRUCT Represents a KO_MEMOY_UNTYPED*/
-typedef struct KernelObjectUntyped
+typedef struct _KernelObjectUntyped
{
KernelObjectTyped typed;
- size_t bytes, alignment;
+ size_t bytes;
+ intmax_t alignment;
+
+ KernelObjectTyped *children_head;
+ KernelObjectTyped *sibling;
} KernelObjectUntyped;
-/**@FUNC Gets the size of the given untyped memory block.
- * @PARAM untyped block of memory to get size of.
- * @PARAM bytes address to put size variable into.
- * @RETURN error code. 0 on success.*/
-int jove_untyped_size(KernelObjectUntyped *untyped, size_t *bytes);
-
-/**@FUNC Splits an untyped block of memory into a given size and the remainder.
- * @PARAM untyped block of memory to split.
- * @PARAM bytes number of bytes to split for.
- * @PARAM dest destination slot to place the new block.
- * @RETURN error code. 0 on success.*/
-int jove_untyped_split(KernelObjectUntyped *untyped, size_t bytes, KernelObjectUntyped *dest);
-
-/**@FUNC Merges two untyped memory blocks into a single memory block.
- * The two blocks are expected to be adjacent.
- * If successful, b is merged _into_ a and becomes empty.
- * @PARAM a first block.
- * @PARAM b second block.
- * @RETURN error code. 0 on success.*/
-int jove_untyped_merge(KernelObjectUntyped *a, KernelObjectUntyped *b);
-
-/**@FUNC Gets the page alignment of the given untyped memory block.
- * @PARAM untyped block of memory to get alignment of.
- * @PARAM align pointer to returned value.
- * @RETURN error code. 0 on success.*/
-int jove_untyped_alignment(KernelObjectUntyped *untyped, size_t *align);
+/**@FUNC INTERNAL FUNCTION DO NOT USE.
+ * Initializes a block of memory as an untyped object.
+ * @PARAM untyped pointer to new block of memory.
+ * @PARAM parent directory this new object is a member of.
+ * @PARAM membi index to place this new object.*/
+void _jove_alloc_untyped_inplace(KernelObjectUntyped *untyped, struct _KernelObjectDirectory *parent, uint8_t membi);
+
+/**@FUNC INTERNAL FUNCTION DO NOT USE.
+ * Allocates a block of memory representing an untyped object into the heap.
+ * @PARAM parent directory this new object is a member of.
+ * @PARAM membi index to place this new object.
+ * @RETURN pointer to allocated object. NULL on failure.
+ * Possible failures:
+ * EJOVE_NOALLOC: libjove does not have an allocator set yet.
+ * EJOVE_FULL: destination is already taken.*/
+KernelObjectUntyped *_jove_alloc_untyped(struct _KernelObjectDirectory *parent, uint8_t membi);
+
+/**@FUNC Changes pointer type of typed object to untyped if correct.
+ * @PARAM typed pointer to convert.
+ * @RETURN pointer as KernelObjectUntyped*, NULL on failure.
+ * Possible failures:
+ * EJOVE_BADOBJ: passed object is not an untyped.*/
+KernelObjectUntyped *jove_object_as_untyped(KernelObjectTyped *typed);
+
+/**@FUNC Gets the number of bytes a given untyped block represents.
+ * @PARAM untyped block of untyped memory.
+ * @RETURN number of bytes. negative on failure.
+ * Possible failures:
+ * EJOVE_BADOBJ: passed object does not exist / is not an untyped. */
+int jove_untyped_size(KernelObjectUntyped *untyped);
+
+/**@FUNC Gets the byte alignment of a given untyped block up to a page.
+ * @PARAM untyped block of untyped memory.
+ * @RETURN alignment in bytes. negative on failure.*/
+int jove_untyped_alignment(KernelObjectUntyped *untyped);
+
+/**@FUNC Splits a given untyped block of memory into a block with the given size
+ * and the remainder. New untyped object is stored in dest at destmemb.
+ * @PARAM untyped block of untyped memory to split.
+ * @PARAM bytes number of bytes the new block should have.
+ * Minimum sizeof(size_t)
+ * @PARAM dest directory to store the new block.
+ * @PARAM destmemb index in dest to store new block.
+ * @RETURN Newly created block of memory. NULL on failure.
+ * Possible failures:
+ * EJOVE_BADSIZE: bytes < sizeof(size_t)
+ * EJOVE_BADOBJ: dest or untyped are incorrect types / do not exist.*/
+KernelObjectUntyped *jove_untyped_split(
+ KernelObjectUntyped *untyped, size_t bytes,
+ KernelObjectDirectory *dest, uint8_t destmemb);
+
+JoveError jove_untyped_split_inplace(
+ KernelObjectUntyped *untyped,
+ size_t bytes,
+ KernelObjectUntyped *dest);
+
#endif
diff --git a/lib/libjove/include/syscall.h b/lib/libjove/include/syscall.h
index 432be85..5d872a3 100644
--- a/lib/libjove/include/syscall.h
+++ b/lib/libjove/include/syscall.h
@@ -7,25 +7,28 @@
#include <jove/object.h>
#define SYSCALL_PAYLOAD_PUTL(buf, at, v, type) \
- if(at + sizeof(type) > KO_MESSAGE_BYTES) return -1; \
+ if(at + sizeof(type) > KO_MESSAGE_BYTES) return EJOVE_TOOBIG; \
*((type*)(&buf[at])) = v; \
at += sizeof(type)
#define SYSCALL_PAYLOAD_SAVEPTR(buf, at, type, val) \
- if(at + sizeof(type) >= KO_MESSAGE_BYTES) return -1; \
+ if(at + sizeof(type) >= KO_MESSAGE_BYTES) return EJOVE_TOOBIG; \
val = (type*)(&buf[at]); \
at += sizeof(type)
#define SYSCALL_PAYLOAD_PUTOBJ(buf, at, obj) \
at = path_tobuf(JOVE_OBJECT_TYPED(obj), buf, at, KO_MESSAGE_BYTES); \
- if(at < 0) return at
+ if(at < 0) return -at
int _syscall_invoke(void);
void _syscall_debug_putc(char c);
-int _syscall_invoke_objdir_nmemb(KernelObjectDirectory *dir, uint8_t *result);
int _syscall_invoke_objdir_getmemb(KernelObjectDirectory *dir, uint8_t member, obj_type_t *result);
+int _syscall_invoke_objdir_lastmemb(KernelObjectDirectory *dir, uint8_t *result);
+int _syscall_invoke_objdir_move(
+ KernelObjectDirectory *dir, uint8_t memb,
+ KernelObjectDirectory *dest_dir, uint8_t dest_memb);
int _syscall_invoke_untyped_size(KernelObjectUntyped *untyped, size_t *bytes);
int _syscall_invoke_untyped_split(KernelObjectUntyped *path, size_t bytes, KernelObjectUntyped *dest);