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