diff --git a/src/main.rs b/src/main.rs index 5445717a..965fc680 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ entry_point!(kernel_main); fn kernel_main(boot_info: &'static BootInfo) -> ! { use blog_os::interrupts::PICS; use blog_os::memory::active_level_4_table; + use x86_64::{structures::paging::PageTable, VirtAddr}; println!("Hello World{}", "!"); @@ -24,6 +25,19 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { for (i, entry) in l4_table.iter().enumerate() { if !entry.is_unused() { println!("L4 Entry {}: {:?}", i, entry); + + // get the physical address from the entry and convert it + let phys = entry.frame().unwrap().start_address(); + let virt = phys.as_u64() + boot_info.physical_memory_offset; + let ptr = VirtAddr::new(virt).as_mut_ptr(); + let l3_table: &PageTable = unsafe { &*ptr }; + + // print non-empty entries of the level 3 table + for (i, entry) in l3_table.iter().enumerate() { + if !entry.is_unused() { + println!(" L3 Entry {}: {:?}", i, entry); + } + } } }