mm: fix mapping memory in non-present PDEs
This commit is contained in:
+1
-1
@@ -134,7 +134,7 @@ void kmain(unsigned int magic, unsigned int info)
|
|||||||
l9660_dir dir;
|
l9660_dir dir;
|
||||||
l9660_file file;
|
l9660_file file;
|
||||||
|
|
||||||
follow_path("/katau/caller.", &file, &dir);
|
follow_path("/katau/dash.", &file, &dir);
|
||||||
|
|
||||||
exec_from_file(&file, &dir);
|
exec_from_file(&file, &dir);
|
||||||
|
|
||||||
|
|||||||
+16
-5
@@ -48,11 +48,22 @@ void map_page(void *physaddr, void *virtualaddr, unsigned int flags) {
|
|||||||
// adjust the PDE accordingly.
|
// adjust the PDE accordingly.
|
||||||
|
|
||||||
if (!(pd[pdindex] & 0x1)) { // If PDE not present
|
if (!(pd[pdindex] & 0x1)) { // If PDE not present
|
||||||
unsigned long *new_pt = alloc_page();
|
void *new_pt_phys = alloc_page();
|
||||||
unsigned long *virt_pt = (unsigned long *)(0xC0000000 + new_pt);
|
if (!new_pt_phys) {
|
||||||
memset(virt_pt, 0, 4096);
|
printf("failed to allocate a new page table\n");
|
||||||
//pd[pdindex] = (uint32_t)new_pt | 0x3; // Present, R/W
|
return;
|
||||||
pd[pdindex] = (uint32_t)new_pt | (flags & 0x7); // Add User bit if needed
|
}
|
||||||
|
|
||||||
|
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));
|
uint32_t *pt = (uint32_t*)(0xFFC00000 + (pdindex << 12));
|
||||||
|
|||||||
+1
-1
@@ -138,7 +138,7 @@ uint32_t* create_page_dir()
|
|||||||
uint32_t* current_pd = (uint32_t*)0xFFFFF000; // Current PD (self-mapped)
|
uint32_t* current_pd = (uint32_t*)0xFFFFF000; // Current PD (self-mapped)
|
||||||
uint32_t* new_pd = (uint32_t*)phys_to_virt((uint32_t)ppp);
|
uint32_t* new_pd = (uint32_t*)phys_to_virt((uint32_t)ppp);
|
||||||
|
|
||||||
for(int i = 768; i < 1023; i++)
|
for(int i = 768; i < 1024; i++)
|
||||||
{
|
{
|
||||||
if(current_pd[i] & PAGE_PRESENT) {
|
if(current_pd[i] & PAGE_PRESENT) {
|
||||||
new_pd[i] = current_pd[i];
|
new_pd[i] = current_pd[i];
|
||||||
|
|||||||
Reference in New Issue
Block a user