Adds marking the memory used by the kernel as used.

This commit is contained in:
Felix Queißner 2016-05-04 18:00:16 +02:00
parent 3f77600a86
commit 3b6bd5ca87
2 changed files with 26 additions and 8 deletions

View file

@ -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);

View file

@ -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 = .;
}