Browse Source

memory: implement Page::rage_inclusive()

master
3moon 8 years ago
parent
commit
4e7fa1ad31
1 changed files with 29 additions and 2 deletions
  1. +29
    -2
      src/arch/x86_64/memory/paging/mod.rs

+ 29
- 2
src/arch/x86_64/memory/paging/mod.rs View File

@ -117,7 +117,8 @@ impl InactivePageTable {
} }
/// A representation of a virtual page. /// A representation of a virtual page.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Page { pub struct Page {
index: usize, index: usize,
} }
@ -127,7 +128,7 @@ impl Page {
pub fn containing_address(address: VirtualAddress) -> Page { pub fn containing_address(address: VirtualAddress) -> Page {
assert!(address < 0x0000_8000_0000_0000 || assert!(address < 0x0000_8000_0000_0000 ||
address >= 0xffff_8000_0000_0000, address >= 0xffff_8000_0000_0000,
"invalid address: 0x{:x}", address);
"invalid address: {:#x}", address);
Page { index: address / PAGE_SIZE } Page { index: address / PAGE_SIZE }
} }
@ -137,6 +138,13 @@ impl Page {
self.index * PAGE_SIZE self.index * PAGE_SIZE
} }
pub fn range_inclusive(start: Page, end: Page) -> PageIter {
PageIter {
start: start,
end: end,
}
}
fn p4_index(&self) -> usize { fn p4_index(&self) -> usize {
(self.index >> 27) & 0o777 (self.index >> 27) & 0o777
} }
@ -151,6 +159,25 @@ impl Page {
} }
} }
pub struct PageIter {
start: Page,
end: Page,
}
impl Iterator for PageIter {
type Item = Page;
fn next(&mut self) -> Option<Page> {
if self.start <= self.end {
let frame = self.start.clone();
self.start.index += 1;
Some(frame)
} else {
None
}
}
}
/// Remap the kernel /// Remap the kernel
pub fn remap_kernel<A>(allocator: &mut A, boot_info: &BootInformation) pub fn remap_kernel<A>(allocator: &mut A, boot_info: &BootInformation)
where A: FrameAllocator { where A: FrameAllocator {


Loading…
Cancel
Save