Failure when mapping pages
Posted: Thu Oct 07, 2010 11:44 am
I'm trying to write a paging system, but there's something wrong with my function that maps physical to virtual addresses. I'm trying to map 0x27000 to 0x45000000, but it's mapping it to 0xFFFFFF00.
Here's my page mapping code:
The Bochs log is attached.
Any ideas on how to fix this function?
Here's my page mapping code:
Code: Select all
void paging_mapPage(uint32_t physical, uint32_t virtual, uint32_t flags) {
// Figure out the PDE and the PTE
uint32_t directoryAddr = (uint32_t)virtual >> 22;
uint32_t tableAddr = (uint32_t)virtual >> 12 & 0x03FF;
// Make sure that a PDE exists
uint32_t pde = c_pageDir->m_entries[directoryAddr];
if(pde & PDE_PRESENT) {
// PDE is present
} else {
// Create new PDE
struct page_table *pt = (struct page_table*)PHYSICAL_TO_VIRTUAL(kpmalloc(sizeof(struct page_table)));
memset(pt, 0, sizeof(struct page_table));
c_pageDir->m_entries[directoryAddr] = ((uint32_t)pt & ~0xFFF) | PTE_PRESENT | flags;
pde = c_pageDir->m_entries[directoryAddr];
// Wipe the newly allocated page table
memset((void*)pde, 0, sizeof(struct page_table));
}
// Create or modify the PTE
struct page_table *tbl = (struct page_table*)(pde & ~0xFFF);
tbl->m_pages[tableAddr] = ((unsigned long)physical) | (flags & 0x0FFF) | 0x01; // Set table entry
printf("PHYSICAL: 0x%H\n", physical);
//The TLB must be flushed now
}
Any ideas on how to fix this function?