summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2023-11-26 18:51:37 -0600
committerDanny Holman <dholman@gymli.org>2023-11-26 18:51:37 -0600
commit6b399c882d7d6b8a548f8739ef35bc11e576a47a (patch)
tree9d7112dd3cdd28d6954b016e73c1759bbd817d1e /kernel
parent2740284a344209146fdc9b9fd852f277616e1fba (diff)
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 <dholman@gymli.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/mem.c23
1 files changed, 23 insertions, 0 deletions
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 <kernel/mem.h>
+#include <kernel/alloc.h>
+#include <kernel/paging.h>
+
+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) {
+}