Add a basic kernel heap object.

Currently allocation always fails because we don't
have a way to allocate a physical page.
This commit is contained in:
Drew Galbraith 2023-05-18 09:46:41 -07:00
parent 45b5817a36
commit 0b7e667368
6 changed files with 140 additions and 6 deletions

View file

@ -0,0 +1,17 @@
#include "memory/kernel_heap.h"
#include "debug/debug.h"
#include "memory/paging_util.h"
KernelHeap::KernelHeap(uint64_t lower_bound, uint64_t upper_bound)
: next_addr_(lower_bound), upper_bound_(upper_bound) {}
void* KernelHeap::Allocate(uint64_t size) {
if (next_addr_ + size >= upper_bound_) {
panic("Kernel Heap Overrun");
}
EnsureResident(next_addr_, size);
uint64_t address = next_addr_;
next_addr_ += size;
return reinterpret_cast<void*>(address);
}