mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Provide more context in code example
This commit is contained in:
@@ -445,10 +445,17 @@ 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:
|
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
|
```rust
|
||||||
|
// in the for loop in src/main.rs
|
||||||
|
|
||||||
|
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
|
// get the physical address from the entry and convert it
|
||||||
let phys = entry.frame().unwrap().start_address();
|
let phys = entry.frame().unwrap().start_address();
|
||||||
let virt = phys.as_u64() + boot_info.physical_memory_offset;
|
let virt = phys.as_u64() + boot_info.physical_memory_offset;
|
||||||
let ptr = VirtAddr::new(virt).as_mut_ptr()
|
let ptr = VirtAddr::new(virt).as_mut_ptr();
|
||||||
let l3_table: &PageTable = unsafe { &*ptr };
|
let l3_table: &PageTable = unsafe { &*ptr };
|
||||||
|
|
||||||
// print non-empty entries of the level 3 table
|
// print non-empty entries of the level 3 table
|
||||||
@@ -457,6 +464,7 @@ for (i, entry) in l3_table.iter().enumerate() {
|
|||||||
println!(" L3 Entry {}: {:?}", i, entry);
|
println!(" L3 Entry {}: {:?}", i, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
For looking at the level 2 and level 1 tables, we repeat that process for the level 3 and level 2 entries. As you can imagine, this gets very verbose quickly, so we don't show the full code here.
|
For looking at the level 2 and level 1 tables, we repeat that process for the level 3 and level 2 entries. As you can imagine, this gets very verbose quickly, so we don't show the full code here.
|
||||||
|
|||||||
Reference in New Issue
Block a user