From 2041a7c0d4edc1d73aa0ce31fb4d7af7a5cd3503 Mon Sep 17 00:00:00 2001 From: Yifan Wu Date: Sat, 13 Nov 2021 03:06:44 -0800 Subject: [PATCH] Now construction of PA/VA only uses 56/39 bits. --- os/src/mm/address.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/os/src/mm/address.rs b/os/src/mm/address.rs index d5828ed2..107f35c6 100644 --- a/os/src/mm/address.rs +++ b/os/src/mm/address.rs @@ -2,6 +2,11 @@ use crate::config::{PAGE_SIZE, PAGE_SIZE_BITS}; use super::PageTableEntry; use core::fmt::{self, Debug, Formatter}; +const PA_WIDTH_SV39: usize = 56; +const VA_WIDTH_SV39: usize = 39; +const PPN_WIDTH_SV39: usize = PA_WIDTH_SV39 - PAGE_SIZE_BITS; +const VPN_WIDTH_SV39: usize = VA_WIDTH_SV39 - PAGE_SIZE_BITS; + /// Definitions #[repr(C)] #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq)] @@ -47,16 +52,16 @@ impl Debug for PhysPageNum { /// usize -> T: usize.into() impl From for PhysAddr { - fn from(v: usize) -> Self { Self(v) } + fn from(v: usize) -> Self { Self(v & ( (1 << PA_WIDTH_SV39) - 1 )) } } impl From for PhysPageNum { - fn from(v: usize) -> Self { Self(v) } + fn from(v: usize) -> Self { Self(v & ( (1 << PPN_WIDTH_SV39) - 1 )) } } impl From for VirtAddr { - fn from(v: usize) -> Self { Self(v) } + fn from(v: usize) -> Self { Self(v & ( (1 << VA_WIDTH_SV39) - 1 )) } } impl From for VirtPageNum { - fn from(v: usize) -> Self { Self(v) } + fn from(v: usize) -> Self { Self(v & ( (1 << VPN_WIDTH_SV39) - 1 )) } } impl From for usize { fn from(v: PhysAddr) -> Self { v.0 } @@ -206,4 +211,4 @@ impl Iterator for SimpleRangeIterator where } } } -pub type VPNRange = SimpleRange; \ No newline at end of file +pub type VPNRange = SimpleRange;