summaryrefslogtreecommitdiff
path: root/sys/vm/vm_init.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-06-05 23:27:21 -0400
committerIan Moffett <ian@osmora.org>2024-06-05 23:27:21 -0400
commite67e3a62edf7d1948d721e0fc62917906798add1 (patch)
treeecee899d0cac034b370959bd6434490176732adb /sys/vm/vm_init.c
parent694b5c9b8f1964fc6bf4352637055b85db135368 (diff)
kernel: vm: Add port of TLSF
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/vm/vm_init.c')
-rw-r--r--sys/vm/vm_init.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/sys/vm/vm_init.c b/sys/vm/vm_init.c
index 3e9718d..703942b 100644
--- a/sys/vm/vm_init.c
+++ b/sys/vm/vm_init.c
@@ -28,16 +28,40 @@
*/
#include <sys/limine.h>
+#include <sys/panic.h>
#include <vm/vm.h>
#include <vm/physmem.h>
+#include <assert.h>
+#define DYNALLOC_POOL_SZ 0x400000 /* 4 MiB */
+#define DYNALLOC_POOL_PAGES (DYNALLOC_POOL_SZ / DEFAULT_PAGESIZE)
+
+static struct vm_ctx vm_ctx;
volatile struct limine_hhdm_request g_hhdm_request = {
.id = LIMINE_HHDM_REQUEST,
.revision = 0
};
+struct vm_ctx *
+vm_get_ctx(void)
+{
+ return &vm_ctx;
+}
+
void
vm_init(void)
{
+ void *pool;
+
vm_physmem_init();
+
+ vm_ctx.dynalloc_pool_sz = DYNALLOC_POOL_SZ;
+ vm_ctx.dynalloc_pool_pa = vm_alloc_frame(DYNALLOC_POOL_PAGES);
+ if (vm_ctx.dynalloc_pool_pa == 0) {
+ panic("Failed to allocate dynamic pool\n");
+ }
+
+ pool = PHYS_TO_VIRT(vm_ctx.dynalloc_pool_pa);
+ vm_ctx.tlsf_ctx = tlsf_create_with_pool(pool, DYNALLOC_POOL_SZ);
+ __assert(vm_ctx.tlsf_ctx != 0);
}