Physical Memory Map function not working as expected
Posted: Sun Jul 15, 2007 4:30 am
I've set my last page directory entry to the page directory itself, as that seemed the most elegant solution. I'm now trying to write a memory map function, but I can't seem to find out what is wrong with it. I'm betting it's something obvious, but after staring at code for all this time, I've probably become blind to the solution, so need a fresh set of eyes to look at it.
Forgive me if I've not provided enough information. Let me know if you need to see any more of my code:
The function itself executes without any faults, however, when trying to access the virtual address after mapping it, a page fault is thrown at the address which is trying to be accessed.
Let me know if you need more info.
Cheers,
Phill
Forgive me if I've not provided enough information. Let me know if you need to see any more of my code:
Code: Select all
#define PAGE_KERNEL_RW 0x3
#define PAGE_USER_RW 0x7
#define PAGE_NOT_PRESENT 0x0
#define PAGE_PRESENT 0x3
#define MAKE_ADDRESS(x,y,z) (((x)<<22) | ((y)<<12) | z)
/* Map virt_addr onto phys_addr */
void pmman_map(uint32 phys_addr, uint32 virt_addr, uint32 flags)
{
uint32 phys_page, virt_page;
uint32 *directory;
uint32 *table;
/* Get page boundary below address */
phys_page = phys_addr & 0xfffff000;
virt_page = virt_addr & 0xfffff000;
/* Get PDE and PTE */
directory = (uint32 *)MAKE_ADDRESS(1023, 1023, (virt_page>>20));
table = (uint32 *)MAKE_ADDRESS(1023, (virt_page>>22), 0);
/* If directory entry not present, set it */
if ((*directory & PAGE_PRESENT) == PAGE_NOT_PRESENT)
{
*directory = (uint32)table | PAGE_USER_RW;
}
/* Set page table entry */
table += (virt_page>>12) & 0x3ff;
*table = phys_page | flags;
}
Let me know if you need more info.
Cheers,
Phill