feature (kernel): Implemented global kernel heap

This commit is contained in:
antifallobst 2023-02-12 17:45:42 +01:00
parent 08eaddb0ed
commit cce511c9c3
3 changed files with 26 additions and 29 deletions

View File

@ -18,8 +18,11 @@
#include "stdtypes.h"
void memory_copy (void* source, void* destination, uint32_t num);
void memory_set (void* destination, uint8_t data, uint32_t num);
bool memory_compare (void* a, void* b, uint32_t num);
void memory_copy (void* source, void* destination, uint32_t num);
void memory_set (void* destination, uint8_t data, uint32_t num);
bool memory_compare (void* a, void* b, uint32_t num);
void* memory_allocate (uint64_t size);
void memory_free (void* address);
void memory_allocator_init (void* base);
#endif //NOX_MEMORY_H

View File

@ -15,14 +15,13 @@
#include "utils/logger.h"
#include "utils/core.h"
#include "utils/memory.h"
#include "boot/boot_info.h"
#include "platform/gdt.h"
#include "platform/interrupts.h"
#include "mm/page_frame.h"
#include "mm/page_map.h"
#include "mm/heap.h"
void limine_terminal_print(boot_info_T* boot_info, string_t string) {
boot_info->terminal->write(boot_info->terminal->terminals[0], string, string_length(string));
}
@ -32,6 +31,7 @@ void kernel_init(boot_info_T* boot_info) {
pframe_manager_init(boot_info);
idt_init();
paging_init();
memory_allocator_init((void*)0x100000000000);
}
void kmain(boot_info_T boot_info) {
@ -41,30 +41,7 @@ void kmain(boot_info_T boot_info) {
kernel_init(&boot_info);
heap_T test_heap = heap_create((void*)0x100000000000);
void *debug1, *debug2, *debug3, *debug4 = NULL;
heap_dump_segments(&test_heap);
debug1 = heap_memory_allocate(&test_heap, 16);
heap_dump_segments(&test_heap);
debug2 = heap_memory_allocate(&test_heap, 16);
heap_dump_segments(&test_heap);
debug3 = heap_memory_allocate(&test_heap, 0x3000);
heap_dump_segments(&test_heap);
heap_memory_free(&test_heap, debug2);
heap_dump_segments(&test_heap);
heap_memory_free(&test_heap, debug3);
heap_dump_segments(&test_heap);
debug4 = heap_memory_allocate(&test_heap, 16);
heap_dump_segments(&test_heap);
heap_destruct(&test_heap);
void* debug = memory_allocate(1312);
CORE_HALT_FOREVER
}

View File

@ -14,6 +14,9 @@
*/
#include "utils/memory.h"
#include "mm/heap.h"
heap_T g_kernel_heap;
void memory_copy (void* source, void* destination, uint32_t num) {
uint8_t* src_8 = (uint8_t*)source;
@ -44,3 +47,17 @@ bool memory_compare (void* a, void* b, uint32_t num) {
return true;
}
void* memory_allocate(uint64_t size) {
return heap_memory_allocate(&g_kernel_heap, size);
}
void memory_free(void* address) {
return heap_memory_free(&g_kernel_heap, address);
}
void memory_allocator_init(void* base) {
if (g_kernel_heap.start != NULL) { return; }
heap_init(&g_kernel_heap, base);
}