diff --git a/src/paging.rs b/src/paging.rs index c552ef4..2689499 100644 --- a/src/paging.rs +++ b/src/paging.rs @@ -31,6 +31,11 @@ fn align_up(addr: u64, align: u64) -> u64 { pub struct PhysAddr(pub u64); impl PhysAddr { + #[inline] + pub const fn new(addr: u64) -> Self { + Self(addr) + } + /// Convert to `u64` pub fn as_u64(self) -> u64 { self.0 @@ -113,14 +118,6 @@ impl Into for PhysAddr { } } -impl ops::Add for PhysAddr { - type Output = PhysAddr; - - fn add(self, rhs: PhysAddr) -> Self::Output { - PhysAddr(self.0 + rhs.0) - } -} - impl ops::Add for PhysAddr { type Output = PhysAddr; @@ -129,20 +126,6 @@ impl ops::Add for PhysAddr { } } -impl ops::Add for PhysAddr { - type Output = PhysAddr; - - fn add(self, rhs: usize) -> Self::Output { - PhysAddr::from(self.0 + rhs as u64) - } -} - -impl ops::AddAssign for PhysAddr { - fn add_assign(&mut self, other: PhysAddr) { - *self = PhysAddr::from(self.0 + other.0); - } -} - impl ops::AddAssign for PhysAddr { fn add_assign(&mut self, offset: u64) { *self = PhysAddr::from(self.0 + offset); @@ -150,10 +133,10 @@ impl ops::AddAssign for PhysAddr { } impl ops::Sub for PhysAddr { - type Output = PhysAddr; + type Output = u64; fn sub(self, rhs: PhysAddr) -> Self::Output { - PhysAddr::from(self.0 - rhs.0) + self.as_u64().checked_sub(rhs.as_u64()).unwrap() } } @@ -165,14 +148,6 @@ impl ops::Sub for PhysAddr { } } -impl ops::Sub for PhysAddr { - type Output = PhysAddr; - - fn sub(self, rhs: usize) -> Self::Output { - PhysAddr::from(self.0 - rhs as u64) - } -} - impl ops::Rem for PhysAddr { type Output = PhysAddr; @@ -287,6 +262,11 @@ impl fmt::Pointer for PhysAddr { pub struct VirtAddr(pub u64); impl VirtAddr { + #[inline] + pub const fn new(addr: u64) -> Self { + Self(addr) + } + /// Convert from `u64` pub const fn from_u64(v: u64) -> Self { VirtAddr(v) @@ -429,14 +409,6 @@ impl Into for VirtAddr { } } -impl ops::Add for VirtAddr { - type Output = VirtAddr; - - fn add(self, rhs: VirtAddr) -> Self::Output { - VirtAddr(self.0 + rhs.0) - } -} - impl ops::Add for VirtAddr { type Output = VirtAddr; @@ -445,37 +417,17 @@ impl ops::Add for VirtAddr { } } -impl ops::Add for VirtAddr { - type Output = VirtAddr; - - fn add(self, rhs: usize) -> Self::Output { - VirtAddr::from(self.0 + rhs as u64) - } -} - -impl ops::AddAssign for VirtAddr { - fn add_assign(&mut self, other: VirtAddr) { - *self = VirtAddr::from(self.0 + other.0); - } -} - impl ops::AddAssign for VirtAddr { fn add_assign(&mut self, offset: u64) { *self = VirtAddr::from(self.0 + offset); } } -impl ops::AddAssign for VirtAddr { - fn add_assign(&mut self, offset: usize) { - *self = VirtAddr::from(self.0 + offset as u64); - } -} - impl ops::Sub for VirtAddr { - type Output = VirtAddr; + type Output = u64; fn sub(self, rhs: VirtAddr) -> Self::Output { - VirtAddr::from(self.0 - rhs.0) + self.as_u64().checked_sub(rhs.as_u64()).unwrap() } } @@ -487,14 +439,6 @@ impl ops::Sub for VirtAddr { } } -impl ops::Sub for VirtAddr { - type Output = VirtAddr; - - fn sub(self, rhs: usize) -> Self::Output { - VirtAddr::from(self.0 - rhs as u64) - } -} - impl ops::Rem for VirtAddr { type Output = VirtAddr;