Skip to content

Commit 3ae60cc

Browse files
committed
access the page tables
We look at the page tables that define how our kernel is mapped. When we run it, we see the following output: "Level 4 page table at: PhysAddr(0x1000)" So, the currently active level 4 page table is stored at address `0x1000` in physical memory.
1 parent 4913540 commit 3ae60cc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ pub extern "C" fn _start() -> ! {
1919

2020
tiny_os::init();
2121

22+
// Access the page tables.
23+
use x86_64::registers::control::Cr3;
24+
let (level_4_page_table, _) = Cr3::read(); // returns the currently active level 4 page table from the CR3 register.
25+
println!("Level 4 page table at: {:?}", level_4_page_table.start_address()); // print "Level 4 page table at: PhysAddr(0x1000)"
26+
2227
// Uncomment lines below to trigger a stack overflow.
2328
// fn stack_overflow() {
2429
// stack_overflow(); // for each recursion, the return address is pushed

0 commit comments

Comments
 (0)