mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 06:47:49 +00:00
Add and test a memory::translate_addr function
This commit is contained in:
35
src/main.rs
35
src/main.rs
@@ -11,8 +11,8 @@ entry_point!(kernel_main);
|
||||
#[cfg(not(test))]
|
||||
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};
|
||||
use blog_os::memory::translate_addr;
|
||||
use x86_64::VirtAddr;
|
||||
|
||||
println!("Hello World{}", "!");
|
||||
|
||||
@@ -21,24 +21,21 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
||||
unsafe { PICS.lock().initialize() };
|
||||
x86_64::instructions::interrupts::enable();
|
||||
|
||||
let l4_table = unsafe { active_level_4_table(boot_info.physical_memory_offset) };
|
||||
for (i, entry) in l4_table.iter().enumerate() {
|
||||
if !entry.is_unused() {
|
||||
println!("L4 Entry {}: {:?}", i, entry);
|
||||
let addresses = [
|
||||
// the identity-mapped vga buffer page
|
||||
0xb8000,
|
||||
// some code page
|
||||
0x20010a,
|
||||
// some stack page
|
||||
0x57ac_001f_fe48,
|
||||
// virtual address mapped to physical address 0
|
||||
boot_info.physical_memory_offset,
|
||||
];
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
for &address in &addresses {
|
||||
let virt = VirtAddr::new(address);
|
||||
let phys = unsafe { translate_addr(virt, boot_info.physical_memory_offset) };
|
||||
println!("{:?} -> {:?}", virt, phys);
|
||||
}
|
||||
|
||||
println!("It did not crash!");
|
||||
|
||||
Reference in New Issue
Block a user