From 6b399c882d7d6b8a548f8739ef35bc11e576a47a Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Sun, 26 Nov 2023 18:51:37 -0600 Subject: kernel: mem: add a simple kmalloc implementation Add a simple implementation of kmalloc. This system only works on x86-based processors at the time of commit. Signed-off-by: Danny Holman --- kernel/mem.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 kernel/mem.c (limited to 'kernel') diff --git a/kernel/mem.c b/kernel/mem.c new file mode 100644 index 0000000..e2f1889 --- /dev/null +++ b/kernel/mem.c @@ -0,0 +1,23 @@ +#include +#include +#include + +extern uint32_t _kernel_end; +static uint32_t *heap_start = &_kernel_end; +static uint32_t *heap_end = &_kernel_end; + +int _alloc_new_page(void) { + uint32_t paddr = pfa_alloc_frame(); + if (paddr == 0xFFFFFFFF) + return -1; + map_page(paddr, heap_end, 0x003); +} + +void* kmalloc(size_t sz) { + void *ret = heap_end; + heap_end += sz; + return ret; +} + +void kfree(void *ptr) { +} -- cgit v1.2.3