From e67e3a62edf7d1948d721e0fc62917906798add1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 5 Jun 2024 23:27:21 -0400 Subject: kernel: vm: Add port of TLSF Signed-off-by: Ian Moffett --- sys/vm/vm_init.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'sys/vm/vm_init.c') 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 +#include #include #include +#include +#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); } -- cgit v1.2.3