Allocating Space for VMM to place Page Structures
Posted: Mon Jun 24, 2013 10:27 am
I was banging my head over this problem forever, and I was convinced it was an implementation problem in my mapping code.
BUT. It was a conceptual design flaw. I'm sure all the smart people here have solved this problem already.
Basically, this is how the mapping code works:
So this pseudo-code might look all fine and dandy (forgive me if I left out some details). However, the issue comes where AllocateMappedPage() returns an *unmapped* physical address that is beyond what is currently mapped.
No problem right? Just map it! So it calls MapAddr(returning_address, returning_address)... Which realises that the Page Structure for the virtual address (return_address) doesn't exist, therefore it calls AllocateMappedPage()...
See the problem?
Right now I've solved it by dedicating 1MB of physical and virtual address space right above my kernel (because in my naïve PMM implementation, if you want a mapped address it's gonna be identity mapped), where the VMM can get its memory that is guaranteed to be mapped already.
This will, of course, come back to bite me in my @$$; it is totally inelegant, and will eventually deplete the 1MB set aside.
Thoughts?
BUT. It was a conceptual design flaw. I'm sure all the smart people here have solved this problem already.
Basically, this is how the mapping code works:
Code: Select all
void MapAddr(uint64_t v, uint64_t p)
{
...
if(ParentStructure->Entry[Index1]_Does_not_exist())
ParentStructure->Entry[Index1] = (Entry*)(AllocateMappedPage() | FLAGS);
...
}
No problem right? Just map it! So it calls MapAddr(returning_address, returning_address)... Which realises that the Page Structure for the virtual address (return_address) doesn't exist, therefore it calls AllocateMappedPage()...
See the problem?
Right now I've solved it by dedicating 1MB of physical and virtual address space right above my kernel (because in my naïve PMM implementation, if you want a mapped address it's gonna be identity mapped), where the VMM can get its memory that is guaranteed to be mapped already.
This will, of course, come back to bite me in my @$$; it is totally inelegant, and will eventually deplete the 1MB set aside.
Thoughts?