Add new and delete operator implementations to the kernel heap.
For now delete does nothing.
This commit is contained in:
parent
2d719d0443
commit
4380590af2
|
@ -17,12 +17,14 @@ target_include_directories(zion
|
|||
|
||||
# -c -- Don't run the linker (only necessary for the assembler)
|
||||
# -ffreestanding
|
||||
# -fno-rtti -- No runtime type information (might mess with polymorphism?)
|
||||
# -fno-exceptions -- Disable exceptions.
|
||||
# -nostdlib -- Don't include the standard library.
|
||||
# -mabi=sysv -- Explicitly specify the ABI since we will rely on it.
|
||||
# -mno-red-zone -- Don't put data below the stack pointer (clobbered by interrupts).
|
||||
# -mcmodel=kernel -- Assume the kernel code is running in the higher half.
|
||||
# -mgeneral-regs-only -- Prevent GCC from using a whole host of nonsense registers (that we have to enable).
|
||||
set(_Z_COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -c -ffreestanding -nostdlib -mabi=sysv -mno-red-zone -mcmodel=kernel -mgeneral-regs-only")
|
||||
set(_Z_COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -c -ffreestanding -fno-rtti -fno-exceptions -nostdlib -mabi=sysv -mno-red-zone -mcmodel=kernel -mgeneral-regs-only")
|
||||
|
||||
set(_Z_LINK_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/linker.ld")
|
||||
|
||||
|
|
|
@ -3,8 +3,22 @@
|
|||
#include "debug/debug.h"
|
||||
#include "memory/paging_util.h"
|
||||
|
||||
namespace {
|
||||
|
||||
static KernelHeap* gKernelHeap = nullptr;
|
||||
|
||||
KernelHeap& GetKernelHeap() {
|
||||
if (!gKernelHeap) {
|
||||
panic("Kernel Heap not initialized.");
|
||||
}
|
||||
return *gKernelHeap;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
KernelHeap::KernelHeap(uint64_t lower_bound, uint64_t upper_bound)
|
||||
: next_addr_(lower_bound), upper_bound_(upper_bound) {}
|
||||
: next_addr_(lower_bound), upper_bound_(upper_bound) {
|
||||
gKernelHeap = this;
|
||||
}
|
||||
|
||||
void* KernelHeap::Allocate(uint64_t size) {
|
||||
if (next_addr_ + size >= upper_bound_) {
|
||||
|
@ -15,3 +29,7 @@ void* KernelHeap::Allocate(uint64_t size) {
|
|||
next_addr_ += size;
|
||||
return reinterpret_cast<void*>(address);
|
||||
}
|
||||
|
||||
void* operator new(uint64_t size) { return GetKernelHeap().Allocate(size); }
|
||||
|
||||
void operator delete(void*, uint64_t) {}
|
||||
|
|
Loading…
Reference in New Issue