diff options
Diffstat (limited to 'lib/libjove')
-rw-r--r-- | lib/libjove/Makefile | 18 | ||||
-rw-r--r-- | lib/libjove/arch/x86_64/invoke-pagemap.c | 21 | ||||
-rw-r--r-- | lib/libjove/include/arch/x86_64/object-pagemap.h | 14 | ||||
-rw-r--r-- | lib/libjove/include/arch/x86_64/syscall.h | 12 | ||||
-rw-r--r-- | lib/libjove/include/jove.h | 13 | ||||
-rw-r--r-- | lib/libjove/include/object-dir.h | 17 | ||||
-rw-r--r-- | lib/libjove/include/object-message.h | 13 | ||||
-rw-r--r-- | lib/libjove/include/object-typed.h | 15 | ||||
-rw-r--r-- | lib/libjove/include/object-untyped.h | 39 | ||||
-rw-r--r-- | lib/libjove/include/object.h | 11 | ||||
-rw-r--r-- | lib/libjove/include/path-fromobj.h | 13 | ||||
-rw-r--r-- | lib/libjove/include/syscall.h | 35 | ||||
-rw-r--r-- | lib/libjove/kprintf.c | 16 | ||||
-rw-r--r-- | lib/libjove/libjove.c | 11 | ||||
-rw-r--r-- | lib/libjove/object/directory.c | 4 | ||||
-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 |
20 files changed, 403 insertions, 0 deletions
diff --git a/lib/libjove/Makefile b/lib/libjove/Makefile new file mode 100644 index 0000000..cc5f347 --- /dev/null +++ b/lib/libjove/Makefile @@ -0,0 +1,18 @@ +include $(CONFIG) + +CDIRS := syscall object arch/$(TARGET_MACHINE) +CFILES := $(wildcard *.c) +CFILES += $(foreach dir,$(CDIRS),$(wildcard $(dir)/*.c)) + +OFILES := $(patsubst %.c,%.o,$(CFILES)) + +CFLAGS := -ffreestanding -nostdlib -Iinclude -g + +all: ${OFILES} + ar rcs $(OUT)/libjove.a $(OFILES) + +clean: + -rm $(OFILES) + +%.o:%.c + $(CC) $(CFLAGS) -c $< -o $@ diff --git a/lib/libjove/arch/x86_64/invoke-pagemap.c b/lib/libjove/arch/x86_64/invoke-pagemap.c new file mode 100644 index 0000000..8357904 --- /dev/null +++ b/lib/libjove/arch/x86_64/invoke-pagemap.c @@ -0,0 +1,21 @@ +#include <arch/x86_64/object-pagemap.h> +#include <kernel/syscall.h> +#include <kernel/arch/x86_64/syscall.h> +#include <object.h> +#include <path-fromobj.h> +#include <syscall.h> +#include <jove/jove.h> + +int +_syscall_invoke_mapping_get(KernelObjectPageMapping *mapping, uint16_t pmli, KernelObjectPageMapping *dest) +{ + uint8_t *syscallData = _syscall_message_ptr; + int syscall_at = 0; + + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, mapping); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, INVOKE_MAPPING_GET, uint8_t); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, pmli, uint16_t); + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, dest); + + return _syscall_invoke(); +} diff --git a/lib/libjove/include/arch/x86_64/object-pagemap.h b/lib/libjove/include/arch/x86_64/object-pagemap.h new file mode 100644 index 0000000..55b0570 --- /dev/null +++ b/lib/libjove/include/arch/x86_64/object-pagemap.h @@ -0,0 +1,14 @@ +#ifndef _LIBJOVE_ARCH_x86_64_OBJECT_PAGEMAP_H +#define _LIBJOVE_ARCH_x86_64_OBJECT_PAGEMAP_H 1 + +#include <jove/object-typed.h> + +typedef struct KernelObjectPageMapping +{ + KernelObjectTyped typed; + uint8_t level; +} KernelObjectPageMapping; + + + +#endif diff --git a/lib/libjove/include/arch/x86_64/syscall.h b/lib/libjove/include/arch/x86_64/syscall.h new file mode 100644 index 0000000..1d7df53 --- /dev/null +++ b/lib/libjove/include/arch/x86_64/syscall.h @@ -0,0 +1,12 @@ +#ifndef _LIBJOVE_ARCH_x86_64_SYSCALL_H +#define _LIBJOVE_ARCH_x86_64_SYSCALL_H 1 + +#include <stdint.h> + +#include <kernel/object.h> +#include <jove/object-path.h> + +int _syscall_invoke_mapping_get(KernelObjectPath path, uint16_t pmli, KernelObjectPath destPath); + + +#endif diff --git a/lib/libjove/include/jove.h b/lib/libjove/include/jove.h new file mode 100644 index 0000000..2efef3e --- /dev/null +++ b/lib/libjove/include/jove.h @@ -0,0 +1,13 @@ +#ifndef _LIBJOVE_JOVE_H +#define _LIBJOVE_JOVE_H 1 + +#include <stdint.h> + +extern uintmax_t _syscall_message_box; +extern void *_syscall_message_ptr; + +void libjove_init(uintmax_t box, void *boxptr); + +void jove_kprintf(const char *restrict fmt, ...); + +#endif diff --git a/lib/libjove/include/object-dir.h b/lib/libjove/include/object-dir.h new file mode 100644 index 0000000..f258089 --- /dev/null +++ b/lib/libjove/include/object-dir.h @@ -0,0 +1,17 @@ +#ifndef _LIBJOVE_OBJDIR_H +#define _LIBJOVE_OBJDIR_H 1 + +#include <stdint.h> +#include <stddef.h> +#include <kernel/object.h> + +#include <jove/object-typed.h> + +/**@STRUCT Represents a kobjdir.*/ +typedef struct _KernelObjectDirectory { + KernelObjectTyped typed; + KernelObjectTyped *children[256]; +} KernelObjectDirectory; +extern KernelObjectDirectory __rootdir; + +#endif diff --git a/lib/libjove/include/object-message.h b/lib/libjove/include/object-message.h new file mode 100644 index 0000000..a4b7d35 --- /dev/null +++ b/lib/libjove/include/object-message.h @@ -0,0 +1,13 @@ +#ifndef _LIBJOVE_OBJECT_MESSAGE_H +#define _LIBJOVE_OBJECT_MESSAGE_H 1 + +#include <jove/object-typed.h> + +typedef struct _KernelObjectMessage +{ + KernelObjectTyped typed; + uint16_t pages; + void *data; +} KernelObjectMessage; + +#endif diff --git a/lib/libjove/include/object-typed.h b/lib/libjove/include/object-typed.h new file mode 100644 index 0000000..750cf08 --- /dev/null +++ b/lib/libjove/include/object-typed.h @@ -0,0 +1,15 @@ +#ifndef _LIBJOVE_OBJPATH_H +#define _LIBJOVE_OBJPATH_H 1 + +#include <stddef.h> +#include <stdint.h> +#include <kernel/object.h> + +typedef struct KernelObjectTyped +{ + void *parent; + obj_type_t type; + uint8_t membi; +} KernelObjectTyped; + +#endif diff --git a/lib/libjove/include/object-untyped.h b/lib/libjove/include/object-untyped.h new file mode 100644 index 0000000..ea1185d --- /dev/null +++ b/lib/libjove/include/object-untyped.h @@ -0,0 +1,39 @@ +#ifndef _LIBJOVE_OBJECT_UNTYPED_H +#define _LIBJOVE_OBJECT_UNTYPED_H 1 + +#include <jove/object-typed.h> + +/**@STRUCT Represents a KO_MEMOY_UNTYPED*/ +typedef struct KernelObjectUntyped +{ + KernelObjectTyped typed; + size_t bytes, alignment; +} 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); +#endif diff --git a/lib/libjove/include/object.h b/lib/libjove/include/object.h new file mode 100644 index 0000000..5b0cc82 --- /dev/null +++ b/lib/libjove/include/object.h @@ -0,0 +1,11 @@ +#ifndef _LIBJOVE_OBJECT_H +#define _LIBJOVE_OBJECT_H 1 + +#include <jove/object-typed.h> +#include <jove/object-dir.h> +#include <jove/object-untyped.h> +#include <jove/object-message.h> + +#define JOVE_OBJECT_TYPED(o) (KernelObjectTyped*)o + +#endif diff --git a/lib/libjove/include/path-fromobj.h b/lib/libjove/include/path-fromobj.h new file mode 100644 index 0000000..252be29 --- /dev/null +++ b/lib/libjove/include/path-fromobj.h @@ -0,0 +1,13 @@ +#ifndef _LIBJOVE_PATH_FROMOBJ_H +#define _LIBJOVE_PATH_FROMOBJ_H 1 + +#include <jove/object-typed.h> +#include <kernel/object.h> + +int path_fromobj_s(KernelObjectTyped *obj, uint8_t *buffer, int size); +inline int path_fromobj(KernelObjectTyped *obj, uint8_t *buffer) +{ return path_fromobj_s(obj, buffer, -1); } + +int path_tobuf(KernelObjectTyped *obj, uint8_t *buffer, size_t at, size_t bufferw); + +#endif diff --git a/lib/libjove/include/syscall.h b/lib/libjove/include/syscall.h new file mode 100644 index 0000000..432be85 --- /dev/null +++ b/lib/libjove/include/syscall.h @@ -0,0 +1,35 @@ +#ifndef _LIBJOVE_SYSCALL_H +#define _LIBJOVE_SYSCALL_H 1 + +#include <stdint.h> + +#include <kernel/object.h> +#include <jove/object.h> + +#define SYSCALL_PAYLOAD_PUTL(buf, at, v, type) \ + if(at + sizeof(type) > KO_MESSAGE_BYTES) return -1; \ + *((type*)(&buf[at])) = v; \ + at += sizeof(type) + +#define SYSCALL_PAYLOAD_SAVEPTR(buf, at, type, val) \ + if(at + sizeof(type) >= KO_MESSAGE_BYTES) return -1; \ + 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 + + +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_untyped_size(KernelObjectUntyped *untyped, size_t *bytes); +int _syscall_invoke_untyped_split(KernelObjectUntyped *path, size_t bytes, KernelObjectUntyped *dest); +int _syscall_invoke_untyped_merge(KernelObjectUntyped *a, KernelObjectUntyped *b); +int _syscall_invoke_untyped_alignment(KernelObjectUntyped *path, size_t *alignment); + +#endif diff --git a/lib/libjove/kprintf.c b/lib/libjove/kprintf.c new file mode 100644 index 0000000..c04756a --- /dev/null +++ b/lib/libjove/kprintf.c @@ -0,0 +1,16 @@ +#include <jove/jove.h> +#include <jove/syscall.h> +#include <stdio.h> +#include <stdarg.h> + +void +jove_kprintf(const char *restrict fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + char buffer[256]; + vsnprintf(buffer, 256, fmt, ap); + va_end(ap); + + for(char *c = buffer; *c; c++) _syscall_debug_putc(*c); +} diff --git a/lib/libjove/libjove.c b/lib/libjove/libjove.c new file mode 100644 index 0000000..fe1c080 --- /dev/null +++ b/lib/libjove/libjove.c @@ -0,0 +1,11 @@ +#include "include/jove.h" + +uintmax_t _syscall_message_box = 0; +void *_syscall_message_ptr = 0; + +void +libjove_init(uint64_t box, void *boxptr) +{ + _syscall_message_box = box; + _syscall_message_ptr = boxptr; +} diff --git a/lib/libjove/object/directory.c b/lib/libjove/object/directory.c new file mode 100644 index 0000000..a9487e8 --- /dev/null +++ b/lib/libjove/object/directory.c @@ -0,0 +1,4 @@ +#include <object.h> +#include <syscall.h> + +KernelObjectDirectory __rootdir; 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; +} |