From cab5b78b12aae7e333a259baf7641daf603720d8 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 23 Dec 2022 15:37:32 +0400 Subject: [PATCH] Move heap to separate file --- src/Makefile | 1 + src/heap.c | 15 +++++++++++++++ src/heap.h | 10 ++++++++++ src/main.c | 11 +++-------- 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 src/heap.c create mode 100644 src/heap.h diff --git a/src/Makefile b/src/Makefile index c4b485c..5287f2d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -35,6 +35,7 @@ OBJS += info.c.o OBJS += protected.c.o OBJS += interrupts.c.o interrupts.asm.cpp.o +OBJS += heap.c.o all: $(KERNEL) diff --git a/src/heap.c b/src/heap.c new file mode 100644 index 0000000..4e189a8 --- /dev/null +++ b/src/heap.c @@ -0,0 +1,15 @@ +#include +#include + +#include + +static char memory[8192]; +static struct KernAux_FreeList free_list; + +const KernAux_Malloc heap_malloc = &free_list.malloc; + +void heap_initialize() +{ + KernAux_FreeList_init(&free_list, NULL); + KernAux_FreeList_add_zone(&free_list, memory, sizeof(memory)); +} diff --git a/src/heap.h b/src/heap.h new file mode 100644 index 0000000..10d8859 --- /dev/null +++ b/src/heap.h @@ -0,0 +1,10 @@ +#ifndef KERNAUX_INCLUDED_HEAP +#define KERNAUX_INCLUDED_HEAP + +#include + +extern const KernAux_Malloc heap_malloc; + +void heap_initialize(); + +#endif diff --git a/src/main.c b/src/main.c index 2f6ba46..934bb7b 100644 --- a/src/main.c +++ b/src/main.c @@ -4,12 +4,12 @@ #include "info.h" +#include "heap.h" #include "panic.h" #include "protected.h" #include "interrupts.h" #include -#include #include #include #include @@ -29,9 +29,6 @@ extern uint8_t _kernel_virt_base; extern uint8_t _kernel_stack_start; extern uint8_t _kernel_stack_size; -static char free_list_memory[8192]; -static struct KernAux_FreeList free_list; - static KernAux_Memmap memmap = NULL; static struct Kernel_Info kinfo; @@ -62,15 +59,13 @@ void main( panic("Multiboot 2 info is invalid."); } - KernAux_FreeList_init(&free_list, NULL); - KernAux_FreeList_add_zone(&free_list, - free_list_memory, sizeof(free_list_memory)); + heap_initialize(); { const KernAux_Memmap_Builder builder = KernAux_Multiboot2_Info_to_memmap_builder( multiboot2_info, - &free_list.malloc + heap_malloc ); assert(builder, "builder"); memmap = KernAux_Memmap_Builder_finish_and_free(builder);