From 3b6bd5ca8757513001092e4f0b21ed3c26b13baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Quei=C3=9Fner?= Date: Wed, 4 May 2016 18:00:16 +0200 Subject: [PATCH] Adds marking the memory used by the kernel as used. --- prototypes/base/init.cpp | 30 ++++++++++++++++++++++++------ prototypes/base/linker.ld | 4 ++-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/prototypes/base/init.cpp b/prototypes/base/init.cpp index 3d062e5..fbed94a 100644 --- a/prototypes/base/init.cpp +++ b/prototypes/base/init.cpp @@ -10,6 +10,12 @@ using namespace multiboot; using namespace console_tools; +struct dummy; + +// Symbols generated by linker, no useful content in there... +extern dummy kernelStartMarker; +extern dummy kernelEndMarker; + extern "C" void init(Structure const & data) { Console::main @@ -38,17 +44,29 @@ extern "C" void init(Structure const & data) Console::main << "mmap out of 4 gigabyte range." << "\n"; continue; } - if(mmap.isFree()) { + if(mmap.isFree()) { // Mark all free memory free... - uintptr_t lower = (mmap.base + 0x0FFF) & 0xFFFFF000; // align at upper 4096 - uintptr_t upper = (mmap.base + mmap.length) & 0xFFFFF000; // align at lower 4096 - while (lower < upper) { - PMM::markFree(physical_t(lower)); - lower += 0x1000; + physical_t lower = physical_t(mmap.base).alignUpper(4096); + physical_t upper = physical_t(mmap.base + mmap.length).alignLower(4096); + + uint32_t ptr = lower.numeric(); + while (ptr < upper.numeric()) { + PMM::markFree(physical_t(ptr)); + ptr += 0x1000; } } } + // Mark all memory used by the kernel used... + physical_t lower = physical_t(&kernelStartMarker).alignLower(4096); + physical_t upper = physical_t(&kernelEndMarker).alignUpper(4096); + + uint32_t ptr = lower.numeric(); + while (ptr < upper.numeric()) { + PMM::markUsed(physical_t(ptr)); + ptr += 0x1000; + } + for(int i = 0; i < 10; i++) { bool success; physical_t page = PMM::alloc(success); diff --git a/prototypes/base/linker.ld b/prototypes/base/linker.ld index fd6acd8..ed97bd5 100644 --- a/prototypes/base/linker.ld +++ b/prototypes/base/linker.ld @@ -6,7 +6,7 @@ SECTIONS { . = 0x100000; - kernelStart = .; + kernelStartMarker = .; .text : { *(multiboot) @@ -33,5 +33,5 @@ SECTIONS /* Align the end of the kernel to the page size */ . = ALIGN(4096); - kernelEnd = .; + kernelEndMarker = .; } \ No newline at end of file