feat: added a basic malloc implementation and started work on memory

management
This commit is contained in:
2024-03-29 21:25:14 +01:00
parent 21f15f4575
commit 32ca1bfe18
7 changed files with 984 additions and 11 deletions

View File

@@ -0,0 +1,41 @@
//
// Created by rick on 4-10-23.
//
#include <stdint.h>
#include <stdio.h>
#include <yak/rt/panic.h>
#include <yak/rt/core/mem/memmap.h>
#define MEMMAP_ENTRIES 64
typedef struct {
uintptr_t address;
size_t length;
uint8_t type;
} mmap_entry;
mmap_entry memmap[MEMMAP_ENTRIES] = {0};
void memmap_put_entry(uintptr_t address, size_t length, uint8_t type) {
if (type == MMAP_TYPE_UNDEFINED || type > MMAP_LAST_TYPE) {
panic("Bad memory type");
}
if ((address & 0xFFF) != 0) {
printf("MMap entry %8lx is not page aligned\n", address);
}
if (length % 4096 != 0) {
printf("MMap entry %8lx not a full page %8lx\n", address, length);
}
for (int i = 0; i < MEMMAP_ENTRIES; ++i) {
if (memmap[i].type == 0) {
memmap[i].address = address;
memmap[i].length = length;
memmap[i].type = type;
return;
}
}
panic("No space left in memory map");
}