summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2025-08-19 16:16:10 -0400
committerJon Santmyer <jon@jonsantmyer.com>2025-08-19 16:16:10 -0400
commit18c389411a0f6283c1b6dffc78bbcfcb237e367b (patch)
treeb3f03adbfc4d7f3dd1477b078ac686eb9d42f0c3
parent858a52c06a4615bd58a6a906333f2ad707d41c0a (diff)
downloadjove-os-18c389411a0f6283c1b6dffc78bbcfcb237e367b.tar.gz
jove-os-18c389411a0f6283c1b6dffc78bbcfcb237e367b.tar.bz2
jove-os-18c389411a0f6283c1b6dffc78bbcfcb237e367b.zip
move pager to libjove
-rw-r--r--apps/init/arch/x86_64/paging.c103
-rw-r--r--apps/init/main.c22
-rwxr-xr-xinitrd/files/bin/initbin16600 -> 16656 bytes
-rw-r--r--lib/libjove/Makefile2
-rw-r--r--lib/libjove/arch/x86_64/invoke-pagemap.c6
-rw-r--r--lib/libjove/arch/x86_64/object/pagemap.c4
-rw-r--r--lib/libjove/arch/x86_64/pager/ensure.c88
-rw-r--r--lib/libjove/include/arch/x86_64/pager.h12
-rw-r--r--lib/libjove/include/jove.h6
-rw-r--r--lib/libjove/include/object-dir.h1
-rw-r--r--lib/libjove/include/object-untyped.h2
-rw-r--r--lib/libjove/libjove.c17
-rw-r--r--lib/libjove/syscall/debug_putc.c4
-rw-r--r--lib/libjove/syscall/invoke-objdir.c6
-rw-r--r--lib/libjove/syscall/invoke-untyped.c6
-rw-r--r--lib/libjove/syscall/invoke.c2
-rw-r--r--sysroot/boot/initrd.tarbin20480 -> 20480 bytes
17 files changed, 136 insertions, 145 deletions
diff --git a/apps/init/arch/x86_64/paging.c b/apps/init/arch/x86_64/paging.c
index 6c1c386..641fc8a 100644
--- a/apps/init/arch/x86_64/paging.c
+++ b/apps/init/arch/x86_64/paging.c
@@ -1,109 +1,18 @@
#include "../../memory.h"
#include "jove/object-dir.h"
-#include "jove/jove.h"
+#include "kernel/object.h"
#include <jove/arch/x86_64/object-pagemap.h>
+#include <jove/arch/x86_64/pager.h>
#include <stdbool.h>
-KernelObjectPageMap init_pagemap;
-unsigned d_cache[3] = { -1, -1, -1 };
-uintptr_t vptr_cache = 0;
-
-KernelObjectUntyped work_page;
-
-#define PMLI_SHL(d) (((4 - d) * 9) + 3)
-#define PMLI_DL(v, d) ((v >> PMLI_SHL(d)) % 512)
-
-uint64_t
-pager_write_path(uintptr_t vptr, uint8_t depth)
-{
- uint64_t r = 0;
- if(depth >= 4) return -1;
-
- uint16_t *path = (uint16_t*)&r;
- for(uint8_t i = 0; i < depth; i++) path[i] = PMLI_DL(vptr, i);
- return r;
-}
-
-bool
-pager_depth_exists(uintptr_t vptr, uint8_t depth)
-{
- uint64_t path = pager_write_path(vptr, depth);
- if(path == -1) return false;
-
- return jove_pagemap_exists(&init_pagemap, depth, (uint16_t*)&path);
-}
-/* Places new page in work_page. */
-JoveError
-pager_alloc_page_untyped(void)
-{
- uint8_t lastmemb = jove_objdir_lastmemb(&untypedDirectory);
- if(jove_errno) {
- JoveError err = jove_errno;
- jove_errno = EJOVE_OK;
- return err;
- }
-
- KernelObjectUntyped last_untyped;
- _jove_alloc_untyped_inplace(&last_untyped, &untypedDirectory, lastmemb);
-
- if(jove_untyped_size(&last_untyped) == 0x1000) {
- jove_objdir_move(&untypedDirectory, lastmemb, &__rootdir, work_page.typed.membi);
- return EJOVE_OK;
- }
-
- return jove_untyped_split_inplace(&last_untyped, 0x1000, &work_page);
-}
-
-JoveError
-pager_ensure_at_depth(uint8_t depth, uint16_t *path)
-{
- int exists = jove_pagemap_exists(&init_pagemap, depth, path);
- if(exists) {
- return EJOVE_OK;
- }
-
- JoveError pagealloc_err = pager_alloc_page_untyped();
- if(pagealloc_err) {
- jove_kprintf("Failed to allocate page with error %i\n", pagealloc_err);
- return pagealloc_err;
- }
- return jove_pagemap_map(&init_pagemap, depth, path, &work_page);
-}
-
-#define PAGER_CACHE_ENSURE_DEPTH(path_seg, d) \
- if(path_seg[d] != d_cache[d]) { \
- JoveError d_err = pager_ensure_at_depth(d, path_seg); \
- if(d_err) return d_err; \
- d_cache[d] = path_seg[d]; \
- }
-
-JoveError
-pager_ensure(uintptr_t vptr)
-{
- uint64_t path = pager_write_path(vptr, 3);
- if(path == -1) return EJOVE_BADARG;
-
- vptr &= ~0xFFFULL;
- uint16_t *path_seg = (uint16_t*)&path;
- jove_kprintf("%x:%x:%x:%x\n", path_seg[0], path_seg[1], path_seg[2], path_seg[3]);
-
- PAGER_CACHE_ENSURE_DEPTH(path_seg, 0);
- PAGER_CACHE_ENSURE_DEPTH(path_seg, 1);
- PAGER_CACHE_ENSURE_DEPTH(path_seg, 2);
- if(vptr != vptr_cache) {
- return pager_ensure_at_depth(3, path_seg);
- }
- return EJOVE_OK;
-}
-
void
pager_setup(void)
{
- _jove_alloc_objdir_inplace(&untypedDirectory, &__rootdir, INIT_OBJECT_UNTYPED_DIR);
- _jove_alloc_pagemap_inplace(&init_pagemap, &__rootdir, INIT_OBJECT_PAGEMAP);
+ _jove_alloc_pagemap_inplace(&__jove_pagemap, &__rootdir, INIT_OBJECT_PAGEMAP);
size_t lastfree = jove_objdir_lastmemb(&__rootdir) + 1;
- _jove_alloc_untyped_inplace(&work_page, &__rootdir, lastfree++);
+ __jove_work_obj.membi = lastfree;
+ __jove_work_obj.parent = &__rootdir;
- pager_ensure(0x00000000F0000000);
+ jove_pager_ensure(0x00000000F0000000);
}
diff --git a/apps/init/main.c b/apps/init/main.c
index 17b825e..9ed2579 100644
--- a/apps/init/main.c
+++ b/apps/init/main.c
@@ -9,11 +9,6 @@
/**This program acts as a memory and process server.*/
-#define INIT_HEAP_START_BYTES 8192
-__attribute__((section(".bss.heap")))
-uint8_t init_heap[INIT_HEAP_START_BYTES];
-size_t init_heap_start = (uintptr_t)init_heap;
-
__attribute__((noreturn))
static void
spin_fail(void)
@@ -21,23 +16,12 @@ spin_fail(void)
for(;;);
}
-void*
-init_bumpalloc(size_t bytes)
-{
- void *r = (void*)init_heap_start;
- init_heap_start += bytes;
- return r;
-}
-
-KernelObjectDirectory untypedDirectory;
-
void
main(void *message_ptr)
{
- libjove_init(
- INIT_OBJECT_MESSAGE,
- message_ptr);
- _jove_alloc = init_bumpalloc;
+ __jove_syscall_obj = INIT_OBJECT_MESSAGE;
+ __jove_syscall_ptr = message_ptr;
+ _jove_alloc_objdir_inplace(&__jove_untyped_directory, &__rootdir, INIT_OBJECT_UNTYPED_DIR);
jove_kprintf("Hello, Userland!\n");
pager_setup();
diff --git a/initrd/files/bin/init b/initrd/files/bin/init
index c86f9d1..e76918a 100755
--- a/initrd/files/bin/init
+++ b/initrd/files/bin/init
Binary files differ
diff --git a/lib/libjove/Makefile b/lib/libjove/Makefile
index 024d4fe..b82de22 100644
--- a/lib/libjove/Makefile
+++ b/lib/libjove/Makefile
@@ -1,6 +1,6 @@
include $(CONFIG)
-CDIRS := syscall object
+CDIRS := syscall object pager
CFILES := $(wildcard *.c)
CFILES += $(foreach dir,$(CDIRS),$(wildcard $(dir)/*.c))
diff --git a/lib/libjove/arch/x86_64/invoke-pagemap.c b/lib/libjove/arch/x86_64/invoke-pagemap.c
index e3f3dff..131b22a 100644
--- a/lib/libjove/arch/x86_64/invoke-pagemap.c
+++ b/lib/libjove/arch/x86_64/invoke-pagemap.c
@@ -10,7 +10,7 @@
int
_syscall_invoke_mapping_exists(KernelObjectPageMap *map, uint8_t depth, uint16_t *path)
{
- uint8_t *syscallData = _syscall_message_ptr;
+ uint8_t *syscallData = __jove_syscall_ptr;
int syscall_at = 0;
SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, map);
@@ -23,7 +23,7 @@ _syscall_invoke_mapping_exists(KernelObjectPageMap *map, uint8_t depth, uint16_t
int
_syscall_invoke_mapping_map(KernelObjectPageMap *map, uint8_t depth, uint16_t *path, KernelObjectUntyped *untyped)
{
- uint8_t *syscallData = _syscall_message_ptr;
+ uint8_t *syscallData = __jove_syscall_ptr;
int syscall_at = 0;
SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, map);
@@ -37,7 +37,7 @@ _syscall_invoke_mapping_map(KernelObjectPageMap *map, uint8_t depth, uint16_t *p
int
_syscall_invoke_mapping_unmap(KernelObjectPageMap *map, uint8_t depth, uint16_t *path, KernelObjectUntyped *dest)
{
- uint8_t *syscallData = _syscall_message_ptr;
+ uint8_t *syscallData = __jove_syscall_ptr;
int syscall_at = 0;
SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, map);
diff --git a/lib/libjove/arch/x86_64/object/pagemap.c b/lib/libjove/arch/x86_64/object/pagemap.c
index c58d7c6..0c03028 100644
--- a/lib/libjove/arch/x86_64/object/pagemap.c
+++ b/lib/libjove/arch/x86_64/object/pagemap.c
@@ -59,10 +59,6 @@ jove_pagemap_exists(
uint16_t *path
)
{
- if(!_jove_alloc) {
- jove_errno = EJOVE_NOALLOC;
- return 0;
- }
int kerr = _syscall_invoke_mapping_exists(map, depth, path);
if(kerr == KE_DNE) return 0;
diff --git a/lib/libjove/arch/x86_64/pager/ensure.c b/lib/libjove/arch/x86_64/pager/ensure.c
new file mode 100644
index 0000000..bfe68ff
--- /dev/null
+++ b/lib/libjove/arch/x86_64/pager/ensure.c
@@ -0,0 +1,88 @@
+#include "arch/x86_64/pager.h"
+#include "object-untyped.h"
+#include "jove.h"
+#include <stdbool.h>
+
+KernelObjectPageMap __jove_pagemap;
+static unsigned d_cache[3] = { -1, -1, -1 };
+static uintptr_t vptr_cache = 0;
+static KernelObjectUntyped work_untyped;
+
+#define PMLI_SHL(d) (((4 - d) * 9) + 3)
+#define PMLI_DL(v, d) ((v >> PMLI_SHL(d)) % 512)
+
+static uint64_t
+pager_write_path(uintptr_t vptr, uint8_t depth)
+{
+ uint64_t r = 0;
+ if(depth >= 4) return -1;
+
+ uint16_t *path = (uint16_t*)&r;
+ for(uint8_t i = 0; i < depth; i++) path[i] = PMLI_DL(vptr, i);
+ return r;
+}
+
+/* Places new page in work_page. */
+static JoveError
+pager_alloc_page_untyped(void)
+{
+ uint8_t lastmemb = jove_objdir_lastmemb(&__jove_untyped_directory);
+ if(jove_errno) {
+ JoveError err = jove_errno;
+ jove_errno = EJOVE_OK;
+ return err;
+ }
+
+ KernelObjectUntyped last_untyped;
+ _jove_alloc_untyped_inplace(&last_untyped, &__jove_untyped_directory, lastmemb);
+
+ if(jove_untyped_size(&last_untyped) == 0x1000) {
+ jove_objdir_move(&__jove_untyped_directory, lastmemb, &__rootdir, __jove_work_obj.membi);
+ return EJOVE_OK;
+ }
+
+ work_untyped.typed = __jove_work_obj;
+ return jove_untyped_split_inplace(&last_untyped, 0x1000, &work_untyped);
+}
+
+static JoveError
+pager_ensure_at_depth(KernelObjectPageMap *map, uint8_t depth, uint16_t *path)
+{
+ int exists = jove_pagemap_exists(map, depth, path);
+ if(exists) {
+ return EJOVE_OK;
+ }
+
+ JoveError pagealloc_err = pager_alloc_page_untyped();
+ if(pagealloc_err) {
+ return pagealloc_err;
+ }
+ return jove_pagemap_map(map, depth, path, &work_untyped);
+}
+
+#define PAGER_CACHE_ENSURE_DEPTH(map, path_seg, d) \
+ if(path_seg[d] != d_cache[d]) { \
+ JoveError d_err = pager_ensure_at_depth(map, d, path_seg); \
+ if(d_err) return d_err; \
+ d_cache[d] = path_seg[d]; \
+ }
+
+JoveError
+jove_pager_ensure_for(KernelObjectPageMap *map, uintptr_t vptr)
+{
+ uint64_t path = pager_write_path(vptr, 3);
+ if(path == -1) return EJOVE_BADARG;
+
+ vptr &= ~0xFFFULL;
+ uint16_t *path_seg = (uint16_t*)&path;
+
+ jove_kprintf("%p Alloc %p : %x:%x:%x:%x\n", map, vptr, path_seg[0], path_seg[1], path_seg[2], path_seg[3]);
+
+ PAGER_CACHE_ENSURE_DEPTH(map, path_seg, 0);
+ PAGER_CACHE_ENSURE_DEPTH(map, path_seg, 1);
+ PAGER_CACHE_ENSURE_DEPTH(map, path_seg, 2);
+ if(vptr != vptr_cache) {
+ return pager_ensure_at_depth(map, 3, path_seg);
+ }
+ return EJOVE_OK;
+}
diff --git a/lib/libjove/include/arch/x86_64/pager.h b/lib/libjove/include/arch/x86_64/pager.h
new file mode 100644
index 0000000..7e47ed1
--- /dev/null
+++ b/lib/libjove/include/arch/x86_64/pager.h
@@ -0,0 +1,12 @@
+#ifndef _LIBJOVE_ARCH_x86_64_PAGER_H
+#define _LIBJOVE_ARCH_x86_64_PAGER_H 1
+
+#include <jove/error.h>
+#include <jove/arch/x86_64/object-pagemap.h>
+
+extern KernelObjectPageMap __jove_pagemap;
+
+JoveError jove_pager_ensure_for(KernelObjectPageMap *map, uintptr_t vptr);
+#define jove_pager_ensure(vptr) jove_pager_ensure_for(&__jove_pagemap, vptr)
+
+#endif
diff --git a/lib/libjove/include/jove.h b/lib/libjove/include/jove.h
index 87eecb3..e333485 100644
--- a/lib/libjove/include/jove.h
+++ b/lib/libjove/include/jove.h
@@ -4,14 +4,14 @@
#include <stdint.h>
#include <stddef.h>
-extern uintmax_t _syscall_message_box;
-extern void *_syscall_message_ptr;
+extern uintmax_t __jove_syscall_obj;
+extern void *__jove_syscall_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);
+extern uintptr_t __program_end;
void jove_kprintf(const char *restrict fmt, ...);
diff --git a/lib/libjove/include/object-dir.h b/lib/libjove/include/object-dir.h
index e4d9aaf..53aada8 100644
--- a/lib/libjove/include/object-dir.h
+++ b/lib/libjove/include/object-dir.h
@@ -19,6 +19,7 @@ typedef struct _KernelObjectDirectory {
KernelObjectTyped *children[256];
} KernelObjectDirectory;
extern KernelObjectDirectory __rootdir;
+extern KernelObjectTyped __jove_work_obj;
KernelObjectDirectory *jove_object_as_objdir(KernelObjectTyped *typed);
diff --git a/lib/libjove/include/object-untyped.h b/lib/libjove/include/object-untyped.h
index e7715b0..a947c23 100644
--- a/lib/libjove/include/object-untyped.h
+++ b/lib/libjove/include/object-untyped.h
@@ -15,6 +15,8 @@ typedef struct _KernelObjectUntyped
KernelObjectTyped *sibling;
} KernelObjectUntyped;
+extern KernelObjectDirectory __jove_untyped_directory;
+
/**@FUNC INTERNAL FUNCTION DO NOT USE.
* Initializes a block of memory as an untyped object.
* @PARAM untyped pointer to new block of memory.
diff --git a/lib/libjove/libjove.c b/lib/libjove/libjove.c
index 5ad45ac..6b40a54 100644
--- a/lib/libjove/libjove.c
+++ b/lib/libjove/libjove.c
@@ -1,18 +1,17 @@
#include "include/jove.h"
+#include "include/object-untyped.h"
#include "error.h"
-uintmax_t _syscall_message_box = 0;
-void *_syscall_message_ptr = 0;
+uintmax_t __jove_syscall_obj = 0;
+void *__jove_syscall_ptr = 0;
JoveError jove_errno;
+KernelObjectDirectory __jove_untyped_directory;
+KernelObjectTyped __jove_work_obj;
+
+uintptr_t __program_end;
+
void *(*_jove_alloc)(size_t) = NULL;
void (*_jove_free)(void*) = NULL;
void *(*_jove_realloc)(void*, size_t) = NULL;
-
-void
-libjove_init(uint64_t box, void *boxptr)
-{
- _syscall_message_box = box;
- _syscall_message_ptr = boxptr;
-}
diff --git a/lib/libjove/syscall/debug_putc.c b/lib/libjove/syscall/debug_putc.c
index 2d68ee1..9215a09 100644
--- a/lib/libjove/syscall/debug_putc.c
+++ b/lib/libjove/syscall/debug_putc.c
@@ -5,8 +5,8 @@
void
_syscall_debug_putc(char c)
{
- *((char*)_syscall_message_ptr) = c;
- register uint64_t box asm ("rdi") = _syscall_message_box;
+ *((char*)__jove_syscall_ptr) = c;
+ register uint64_t box asm ("rdi") = __jove_syscall_obj;
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
index 6ee39e4..6558d6d 100644
--- a/lib/libjove/syscall/invoke-objdir.c
+++ b/lib/libjove/syscall/invoke-objdir.c
@@ -7,7 +7,7 @@
int
_syscall_invoke_objdir_getmemb(KernelObjectDirectory *dir, uint8_t member, obj_type_t *result)
{
- uint8_t *syscallData = _syscall_message_ptr;
+ uint8_t *syscallData = __jove_syscall_ptr;
int syscall_at = 0;
obj_type_t *syscall_result;
@@ -24,7 +24,7 @@ _syscall_invoke_objdir_getmemb(KernelObjectDirectory *dir, uint8_t member, obj_t
int
_syscall_invoke_objdir_lastmemb(KernelObjectDirectory *dir, uint8_t *result)
{
- uint8_t *syscallData = _syscall_message_ptr;
+ uint8_t *syscallData = __jove_syscall_ptr;
int syscall_at = 0;
uint8_t *syscall_result;
@@ -44,7 +44,7 @@ _syscall_invoke_objdir_move(
KernelObjectDirectory *dest_dir,
uint8_t dest_memb)
{
- uint8_t *syscallData = _syscall_message_ptr;
+ uint8_t *syscallData = __jove_syscall_ptr;
int syscall_at = 0;
SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, dir);
diff --git a/lib/libjove/syscall/invoke-untyped.c b/lib/libjove/syscall/invoke-untyped.c
index 3f718c2..470d19f 100644
--- a/lib/libjove/syscall/invoke-untyped.c
+++ b/lib/libjove/syscall/invoke-untyped.c
@@ -8,7 +8,7 @@
int
_syscall_invoke_untyped_size(KernelObjectUntyped *untyped, size_t *bytes)
{
- uint8_t *syscallData = _syscall_message_ptr;
+ uint8_t *syscallData = __jove_syscall_ptr;
int syscall_at = 0;
size_t *syscall_bytes;
@@ -24,7 +24,7 @@ _syscall_invoke_untyped_size(KernelObjectUntyped *untyped, size_t *bytes)
int
_syscall_invoke_untyped_split(KernelObjectUntyped *untyped, size_t bytes, KernelObjectUntyped *dest)
{
- uint8_t *syscallData = _syscall_message_ptr;
+ uint8_t *syscallData = __jove_syscall_ptr;
int syscall_at = 0;
SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, untyped);
@@ -38,7 +38,7 @@ _syscall_invoke_untyped_split(KernelObjectUntyped *untyped, size_t bytes, Kernel
int
_syscall_invoke_untyped_alignment(KernelObjectUntyped *untyped, size_t *alignment)
{
- uint8_t *syscallData = _syscall_message_ptr;
+ uint8_t *syscallData = __jove_syscall_ptr;
int syscall_at = 0;
size_t *syscall_alignment;
diff --git a/lib/libjove/syscall/invoke.c b/lib/libjove/syscall/invoke.c
index e673623..66fa095 100644
--- a/lib/libjove/syscall/invoke.c
+++ b/lib/libjove/syscall/invoke.c
@@ -5,7 +5,7 @@
int
_syscall_invoke(void)
{
- register uint64_t box asm ("rdi") = _syscall_message_box;
+ register uint64_t box asm ("rdi") = __jove_syscall_obj;
register uint64_t call asm ("rsi") = SYSCALL_INVOKE;
int status = 0;
diff --git a/sysroot/boot/initrd.tar b/sysroot/boot/initrd.tar
index 171b978..8b6baa4 100644
--- a/sysroot/boot/initrd.tar
+++ b/sysroot/boot/initrd.tar
Binary files differ