summaryrefslogtreecommitdiff
path: root/kernel/include
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksav013@gmail.com>2022-08-11 00:26:36 +0200
committerAleksa Vuckovic <aleksav013@gmail.com>2022-08-11 23:33:28 +0200
commit97c5f8569a845b6e9b3f75460b3b90a2de9b72a8 (patch)
tree26a0544493e7f692cf8600a28e01722062e7006d /kernel/include
parent78579419442f22641368db777120d7e75cbaee94 (diff)
heap
Diffstat (limited to 'kernel/include')
-rw-r--r--kernel/include/heap.h34
-rw-r--r--kernel/include/libk/math.h2
2 files changed, 30 insertions, 6 deletions
diff --git a/kernel/include/heap.h b/kernel/include/heap.h
index ae846bd..5997b7a 100644
--- a/kernel/include/heap.h
+++ b/kernel/include/heap.h
@@ -3,12 +3,34 @@
#include <types.h>
-#define HEAP_START_ADDR 0x00200000
-#define HEAP_SIZE 0x00100000
-#define HEAP_BLOCK_SIZE 0x00000100
+#define HEAP_START_ADDR 0x00400000
+#define HEAP_SIZE 0x01000000
+#define HEAP_BLOCK_SIZE 0x00000010
-void init_heap(uint64_t addr, uint64_t size, uint64_t block_size);
-void* kmalloc(uint32_t size);
-void kfree(void *addr);
+struct kheapblock_t {
+ struct kheapblock_t* next;
+ uint32_t size;
+ uint32_t used;
+ uint32_t bsize;
+};
+typedef struct kheapblock_t kheapblock_t;
+
+struct kheap_t {
+ struct kheapblock_t* fblock;
+};
+typedef struct kheap_t kheap_t;
+
+
+extern kheap_t main_kheap;
+
+void kheap_init(kheap_t* kheap);
+void kheap_add_block(kheap_t* kheap, uint64_t addr, uint32_t size, uint32_t block_size);
+void* kheap_alloc(kheap_t* kheap, uint32_t size);
+void kheap_free(kheap_t* kheap, void* pointer);
+
+void init_heap(void);
+
+#define kalloc(size) kheap_alloc(&main_kheap, size)
+#define kfree(pointer) kheap_free(&main_kheap, pointer)
#endif
diff --git a/kernel/include/libk/math.h b/kernel/include/libk/math.h
index 83ac7fe..27fee80 100644
--- a/kernel/include/libk/math.h
+++ b/kernel/include/libk/math.h
@@ -3,6 +3,8 @@
#include <types.h>
+#define upper_div(a,b) ((a / b) * b < a ? (a / b) + 1 : (a / b))
+
int64_t abs(int64_t val);
#endif