From 44756d8f823146eaa632b7e91f52445f1401221b Mon Sep 17 00:00:00 2001 From: Jonathan Klimt Date: Wed, 20 Nov 2024 11:40:35 +0100 Subject: [PATCH] x86_64: Added pagetable pretty printing function for debugging --- src/arch/x86_64/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/arch/x86_64/mod.rs b/src/arch/x86_64/mod.rs index e8c356f0..5354b22b 100644 --- a/src/arch/x86_64/mod.rs +++ b/src/arch/x86_64/mod.rs @@ -189,6 +189,27 @@ pub fn initialize_pagetables(mem: &mut [u8]) { } } +#[allow(dead_code)] +/// Helper fn for debugging pagetables +fn pretty_print_pagetable(pt: &PageTable) { + println!("Idx Address Idx Address Idx Address Idx Address "); + println!("--------------------------------------------------------------------------------------------------------"); + for i in (0..512).step_by(4) { + println!( + "{:3}: {:#18x}, {:3}: {:#18x}, {:3}: {:#18x}, {:3}: {:#18x}", + i, + pt[i].addr(), + i + 1, + pt[i + 1].addr(), + i + 2, + pt[i + 2].addr(), + i + 3, + pt[i + 3].addr() + ); + } + println!("--------------------------------------------------------------------------------------------------------"); +} + /// Converts a virtual address in the guest to a physical address in the guest pub fn virt_to_phys( addr: GuestVirtAddr,