I tracked the bug down to the memory map I received from GRUB (picture of monitor below). It looks fine with several entries describing the whole 4 GiB of ram. But then we get to this last entry that seems to re-describe the first GiB or so as completely available. Which is of course wrong as there's all sorts of stuff in 0x9f000 to 0xfffff (at least).
And here is the code I'm using to read the memory map in case i'm making some obvious mistake
Code: Select all
void initialize(multiboot_info_t* multiboot, unsigned int multiboot_magic)
{
// Initialize the console (used only during preinitialization)
console& cout = console::instance();
// Clear the console
cout.clear();
// Print progress message
cout << "Preparing to boot... \r\n"
<< "Validating received multiboot information... \r\n";
// Validate the multiboot magic number
if (multiboot_magic != MULTIBOOT_BOOTLOADER_MAGIC)
{
// Error: we can't boot (yet) if we can't rely on the multiboot
// information integrity.
cout << "Error: multiboot validation failure";
// Return (and halt)
return;
}
// Print progress messages
cout << "Searching for reserved areas of physical memory... \r\n";
cout << "Parsing multiboot memory map... \r\n";
// Parse the multiboot memory map and append free memory to the
// direct memory stack
for (auto offset = multiboot->mmap_addr;
offset < multiboot->mmap_addr + multiboot->mmap_length;
offset += sizeof (unsigned int))
{
// Get memory map
auto mmap = reinterpret_cast<multiboot_memory_map_t*>(offset);
// Print information
cout << "\tFrom 0x"
<< reinterpret_cast<const void*>(mmap->addr)
<< " to 0x"
<< reinterpret_cast<const void*>(mmap->addr + mmap->len)
<< ": " << mmap->type << " ("
<< static_cast<unsigned int>(mmap->len / 1024)
<< " KiB)"
<< "\r\n";
// Advance to next memory map entry
offset += mmap->size;
}
}