1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-11-20 11:16:10 -05:00

Move heap to separate file

This commit is contained in:
Alex Kotov 2022-12-23 15:37:32 +04:00
parent 872e01d3de
commit cab5b78b12
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 29 additions and 8 deletions

View file

@ -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)

15
src/heap.c Normal file
View file

@ -0,0 +1,15 @@
#include <kernaux/free_list.h>
#include <kernaux/generic/malloc.h>
#include <stddef.h>
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));
}

10
src/heap.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef KERNAUX_INCLUDED_HEAP
#define KERNAUX_INCLUDED_HEAP
#include <kernaux/generic/malloc.h>
extern const KernAux_Malloc heap_malloc;
void heap_initialize();
#endif

View file

@ -4,12 +4,12 @@
#include "info.h"
#include "heap.h"
#include "panic.h"
#include "protected.h"
#include "interrupts.h"
#include <drivers/console.h>
#include <kernaux/free_list.h>
#include <kernaux/generic/display.h>
#include <kernaux/macro.h>
#include <kernaux/memmap.h>
@ -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);