update ch4 with more comments
This commit is contained in:
parent
76056c8626
commit
5946903948
24 changed files with 205 additions and 20 deletions
|
@ -1,7 +1,10 @@
|
|||
//! Implementation of physical and virtual address and page number.
|
||||
|
||||
use super::PageTableEntry;
|
||||
use crate::config::{PAGE_SIZE, PAGE_SIZE_BITS};
|
||||
use core::fmt::{self, Debug, Formatter};
|
||||
|
||||
/// physical address
|
||||
const PA_WIDTH_SV39: usize = 56;
|
||||
const VA_WIDTH_SV39: usize = 39;
|
||||
const PPN_WIDTH_SV39: usize = PA_WIDTH_SV39 - PAGE_SIZE_BITS;
|
||||
|
@ -11,12 +14,15 @@ const VPN_WIDTH_SV39: usize = VA_WIDTH_SV39 - PAGE_SIZE_BITS;
|
|||
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct PhysAddr(pub usize);
|
||||
|
||||
/// virtual address
|
||||
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct VirtAddr(pub usize);
|
||||
|
||||
/// physical page number
|
||||
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct PhysPageNum(pub usize);
|
||||
|
||||
/// virtual page number
|
||||
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct VirtPageNum(pub usize);
|
||||
|
||||
|
@ -176,6 +182,7 @@ impl StepByOne for VirtPageNum {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
/// a simple range structure for type T
|
||||
pub struct SimpleRange<T>
|
||||
where
|
||||
T: StepByOne + Copy + PartialEq + PartialOrd + Debug,
|
||||
|
@ -208,6 +215,7 @@ where
|
|||
SimpleRangeIterator::new(self.l, self.r)
|
||||
}
|
||||
}
|
||||
/// iterator for the simple range structure
|
||||
pub struct SimpleRangeIterator<T>
|
||||
where
|
||||
T: StepByOne + Copy + PartialEq + PartialOrd + Debug,
|
||||
|
@ -238,4 +246,6 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// a simple range structure for virtual page number
|
||||
pub type VPNRange = SimpleRange<VirtPageNum>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue