feat: added a basic malloc implementation and started work on memory
management
This commit is contained in:
41
yak-kernel/src/rt/core/mem/memmap.c
Normal file
41
yak-kernel/src/rt/core/mem/memmap.c
Normal 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");
|
||||
}
|
||||
Reference in New Issue
Block a user