diff --git a/xernel/kernel/src/mem/paging.rs b/xernel/kernel/src/mem/paging.rs index 776132ea..a71b1068 100644 --- a/xernel/kernel/src/mem/paging.rs +++ b/xernel/kernel/src/mem/paging.rs @@ -9,7 +9,7 @@ use limine::KernelAddressRequest; use x86_64::{ align_down, registers::control::{Cr3, Cr3Flags}, - structures::paging::{Page, PageSize, Size1GiB, Size2MiB, Size4KiB}, + structures::paging::{Page, PageSize, PageTableIndex, Size1GiB, Size2MiB, Size4KiB}, }; use x86_64::{ structures::paging::{PageTable, PageTableFlags, PhysFrame}, @@ -294,6 +294,10 @@ impl Pagemap { } } + unsafe fn get_next_pt(pt: *mut PageTable, pt_index: PageTableIndex) -> *mut PageTable { + (*pt)[pt_index].addr().as_u64() as *mut PageTable + } + /// Only works with 4KiB pages pub fn translate(&self, virt: VirtAddr) -> Option { let pml4 = self.page_table; @@ -303,19 +307,19 @@ impl Pagemap { return None; } - let pml3 = (*pml4)[virt.p4_index()].addr().as_u64() as *mut PageTable; + let pml3 = Self::get_next_pt(pml4, virt.p4_index()); if !(*pml3)[virt.p3_index()].flags().contains(PageTableFlags::PRESENT) { return None; } - let pml2 = (*pml3)[virt.p3_index()].addr().as_u64() as *mut PageTable; + let pml2 = Self::get_next_pt(pml3, virt.p3_index()); if !(*pml2)[virt.p2_index()].flags().contains(PageTableFlags::PRESENT) { return None; } - let pml1 = (*pml2)[virt.p2_index()].addr().as_u64() as *mut PageTable; + let pml1 = Self::get_next_pt(pml2, virt.p2_index()); if !(*pml1)[virt.p1_index()].flags().contains(PageTableFlags::PRESENT) { return None;