aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/paging/kheap.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/paging/kheap.h')
-rw-r--r--src/kernel/paging/kheap.h139
1 files changed, 100 insertions, 39 deletions
diff --git a/src/kernel/paging/kheap.h b/src/kernel/paging/kheap.h
index 7a92957..a1d946c 100644
--- a/src/kernel/paging/kheap.h
+++ b/src/kernel/paging/kheap.h
@@ -1,51 +1,112 @@
#ifndef MELVIX_KHEAP_H
#define MELVIX_KHEAP_H
-#include <stdbool.h>
-#include <stddef.h>
+#include "ordered_array.h"
-#define KHEAP_MAGIC 0x13374242
-#define KHEAP_MAGIC2 0xDEADBEEF
-#define KHEAP_END 0xFFFFDEAD
-#define MEM_END 0x8000000
+#define KHEAP_START 0xC0000000
+#define KHEAP_INITIAL_SIZE 0x100000
-extern unsigned int end;
+#define HEAP_INDEX_SIZE 0x20000
+#define HEAP_MAGIC 0x03A93A90
+#define HEAP_MIN_SIZE 0x70000
+/**
+ * Size information of holes/blocks
+ */
typedef struct {
- unsigned int magic;
- bool free;
- unsigned int size;
- unsigned int magic2;
-} heap_header_t;
+ uint32_t magic;
+ unsigned char is_hole; // 1 if hole
+ uint32_t size;
+} header_t;
typedef struct {
- unsigned int magic;
- unsigned int size;
- unsigned int magic2;
-} heap_footer_t;
+ uint32_t magic;
+ header_t *header;
+} footer_t;
-#define HEAP_S (sizeof(heap_header_t))
-#define HEAP_TOTAL (sizeof(heap_footer_t) + HEAP_S)
-#define HEAP_MINIMUM 1
-#define HEAP_FIND_SIZE (HEAP_TOTAL + HEAP_MINIMUM)
-
-void init_kheap();
-
-void *fmalloc(unsigned int size);
-
-void *kmalloc(unsigned int size);
-
-void *kmalloc_a(unsigned int size);
-
-void kfree(void *ptr);
-
-void *umalloc(size_t size);
-
-void ufree(void *address);
-
-void init_heap(heap_header_t *heap, size_t size);
-
-#define KHEAP_SIZE 0xFFFFF
-#define UHEAP_SIZE 0xFFFFF
+typedef struct {
+ ordered_array_t index;
+ uint32_t start_address;
+ uint32_t end_address;
+ uint32_t max_address;
+ unsigned char supervisor;
+ unsigned char readonly;
+} heap_t;
+
+/**
+ * Create a new heap
+ * @param start
+ * @param end
+ * @param max
+ * @param supervisor
+ * @param readonly
+ * @return The heap pointer
+ */
+heap_t *create_heap(uint32_t start, uint32_t end, uint32_t max, unsigned char supervisor, unsigned char readonly);
+
+/**
+ * Allocate a region of memory
+ * @param size The size of the memory
+ * @param page_align Start the block on a page boundary
+ * @param heap The Heap pointer
+ * @return
+ */
+void *alloc(uint32_t size, unsigned char page_align, heap_t *heap);
+
+/**
+ * Release an allocated block
+ * @param p The block
+ * @param heap The heap
+ */
+void free(void *p, heap_t *heap);
+
+/**
+ * Release an allocated block using kheap
+ * @param p The block
+ */
+void kfree(void *p);
+
+/**
+ * Allocate a chunk of memory
+ * @param sz The size of the memory
+ * @param align Start the block on a page boundary
+ * @param phys Location of the memory if not 0
+ * @return The memory address
+ */
+uint32_t kmalloc_int(uint32_t sz, int align, uint32_t *phys);
+
+/**
+ * Allocate a page-aligned chunk of memory
+ * @param sz The size of the memory
+ * @return The memory address
+ */
+uint32_t kmalloc_a(uint32_t sz);
+
+/**
+ * Allocate a chunk of memory in a physical address
+ * @param sz The size of the memory
+ * @param phys The physical address
+ * @return The memory address
+ */
+uint32_t kmalloc_p(uint32_t sz, uint32_t *phys);
+
+/**
+ * Allocate a page-aligned chunk of memory in a physical address
+ * @param sz The size of the memory
+ * @param phys The physical address
+ * @return The memory address
+ */
+uint32_t kmalloc_ap(uint32_t sz, uint32_t *phys);
+
+/**
+ * Allocate a chunk of memory (non page-aligned and no physical address)
+ * @param sz The size of the memory
+ * @return The memory address
+ */
+uint32_t kmalloc(uint32_t sz);
+
+/**
+ General deallocation function.
+**/
#endif