From 16a31b0cd150e20752ed794f75aecb49ced99f76 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Fri, 25 Dec 2020 17:47:14 +0100 Subject: [PATCH] Add linear_phys_to_virt and vice versa. However, since not all platforms will allow the entire physical address space to be simultaneously mapped to part of the virtual address space, we may still require some dynamic mapping. --- src/arch/x86_64/paging/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/arch/x86_64/paging/mod.rs b/src/arch/x86_64/paging/mod.rs index c34c0e66..eff4acfb 100644 --- a/src/arch/x86_64/paging/mod.rs +++ b/src/arch/x86_64/paging/mod.rs @@ -335,6 +335,14 @@ impl InactivePageTable { } } +pub fn linear_phys_to_virt(physical: PhysicalAddress) -> Option<VirtualAddress> { + physical.data().checked_add(crate::KERNEL_OFFSET).map(VirtualAddress::new) +} +pub fn linear_virt_to_phys(virt: VirtualAddress) -> Option<PhysicalAddress> { + virt.data().checked_sub(crate::KERNEL_OFFSET).map(PhysicalAddress::new) +} + + /// Page #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct Page { -- GitLab