From 1041754c710e38bf75b42a68a6073f78e1f28d5c Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 13 Mar 2019 13:57:13 +0100 Subject: [PATCH] Provide more context in code example --- .../posts/10-paging-implementation/index.md | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/blog/content/second-edition/posts/10-paging-implementation/index.md b/blog/content/second-edition/posts/10-paging-implementation/index.md index b5c2b436..5f188da0 100644 --- a/blog/content/second-edition/posts/10-paging-implementation/index.md +++ b/blog/content/second-edition/posts/10-paging-implementation/index.md @@ -445,16 +445,24 @@ We see that there are various non-empty entries, which all map to different leve To traverse the page tables further and take a look at a level 3 table, we can take the mapped frame of an entry convert it to a virtual address again: ```rust -// 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}; +// in the for loop in src/main.rs -// 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); +use x86_64::{structures::paging::PageTable, VirtAddr}; + +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); + } } } ```