From eb9a5e92418e4f3ce9a09d39ad89193991bb32f8 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Thu, 5 Apr 2018 18:41:31 +0800 Subject: [PATCH] Impl Debug for page table --- src/memory/mod.rs | 2 ++ src/memory/paging/entry.rs | 10 ++++++++ src/memory/paging/mapper.rs | 9 +++++++ src/memory/paging/mod.rs | 10 ++++++++ src/memory/paging/table.rs | 48 +++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+) diff --git a/src/memory/mod.rs b/src/memory/mod.rs index 2dde292..83df09e 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -40,6 +40,8 @@ pub fn init(boot_info: &BootInformation) -> MemoryController { let mut active_table = paging::remap_the_kernel(&mut frame_allocator, boot_info); + println!("{:?}", active_table); + use self::paging::Page; use {HEAP_START, HEAP_SIZE}; diff --git a/src/memory/paging/entry.rs b/src/memory/paging/entry.rs index 6571581..848f6d1 100644 --- a/src/memory/paging/entry.rs +++ b/src/memory/paging/entry.rs @@ -69,3 +69,13 @@ impl EntryFlags { flags } } + +use core::fmt; +use core::fmt::Debug; + +impl Debug for Entry { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(f, "{:#014X} {:?}", self.0 & 0x000fffff_fffff000, self.flags()); + Ok(()) + } +} diff --git a/src/memory/paging/mapper.rs b/src/memory/paging/mapper.rs index 8eda53d..677d330 100644 --- a/src/memory/paging/mapper.rs +++ b/src/memory/paging/mapper.rs @@ -116,3 +116,12 @@ impl Mapper { //allocator.deallocate_frame(frame); } } + +use core::fmt; +use core::fmt::Debug; + +impl Debug for Mapper { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(f, "{:?}", self.p4()) + } +} \ No newline at end of file diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs index 36a6dcb..2135a36 100644 --- a/src/memory/paging/mod.rs +++ b/src/memory/paging/mod.rs @@ -243,3 +243,13 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation) active_table } + +use core::fmt; +use core::fmt::Debug; + +impl Debug for ActivePageTable { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(f, "ActivePageTable:\n")?; + write!(f, "{:?}", &self.mapper) + } +} \ No newline at end of file diff --git a/src/memory/paging/table.rs b/src/memory/paging/table.rs index 8fecefe..84c17ea 100644 --- a/src/memory/paging/table.rs +++ b/src/memory/paging/table.rs @@ -98,3 +98,51 @@ impl HierarchicalLevel for Level3 { impl HierarchicalLevel for Level2 { type NextLevel = Level1; } + + +use core::fmt; +use core::fmt::Debug; + +impl Debug for Table { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + // Ignore the 511th recursive entry + let entries = self.entries.iter().enumerate().filter(|(i, e)| !e.is_unused() && *i != 511usize); + for (i, e) in entries { + write!(f, "{:3}: {:?}\n", i, e)?; + write!(f, "{:?}", self.next_table(i).unwrap())?; + } + Ok(()) + } +} + +impl Debug for Table { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + let entries = self.entries.iter().enumerate().filter(|(i, e)| !e.is_unused()); + for (i, e) in entries { + write!(f, " {:3}: {:?}\n", i, e)?; + write!(f, "{:?}", self.next_table(i).unwrap())?; + } + Ok(()) + } +} + +impl Debug for Table { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + let entries = self.entries.iter().enumerate().filter(|(i, e)| !e.is_unused()); + for (i, e) in entries { + write!(f, " {:3}: {:?}\n", i, e)?; + write!(f, "{:?}", self.next_table(i).unwrap())?; + } + Ok(()) + } +} + +impl Debug for Table { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + let entries = self.entries.iter().enumerate().filter(|(i, e)| !e.is_unused()); + for (i, e) in entries { + write!(f, " {:3}: {:?}\n", i, e)?; + } + Ok(()) + } +} \ No newline at end of file