mm: fix mapping memory in non-present PDEs
This commit is contained in:
+16
-5
@@ -48,11 +48,22 @@ void map_page(void *physaddr, void *virtualaddr, unsigned int flags) {
|
||||
// adjust the PDE accordingly.
|
||||
|
||||
if (!(pd[pdindex] & 0x1)) { // If PDE not present
|
||||
unsigned long *new_pt = alloc_page();
|
||||
unsigned long *virt_pt = (unsigned long *)(0xC0000000 + new_pt);
|
||||
memset(virt_pt, 0, 4096);
|
||||
//pd[pdindex] = (uint32_t)new_pt | 0x3; // Present, R/W
|
||||
pd[pdindex] = (uint32_t)new_pt | (flags & 0x7); // Add User bit if needed
|
||||
void *new_pt_phys = alloc_page();
|
||||
if (!new_pt_phys) {
|
||||
printf("failed to allocate a new page table\n");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int pde_flags = PAGE_PRESENT | PAGE_RW;
|
||||
if (flags & PAGE_USER) {
|
||||
pde_flags |= PAGE_USER;
|
||||
}
|
||||
pd[pdindex] = (unsigned long)new_pt_phys | pde_flags;
|
||||
|
||||
uint32_t *pt_virt = (uint32_t*)(0xFFC00000 + (pdindex << 12));
|
||||
asm volatile("invlpg (%0)" : : "r" (pt_virt) : "memory");
|
||||
|
||||
memset(pt_virt, 0, 4096);
|
||||
}
|
||||
|
||||
uint32_t *pt = (uint32_t*)(0xFFC00000 + (pdindex << 12));
|
||||
|
||||
Reference in New Issue
Block a user