mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Test the map_to function
This commit is contained in:
@@ -52,12 +52,7 @@ pub extern fn rust_main(multiboot_information_address: usize) {
|
||||
kernel_start as usize, kernel_end as usize, multiboot_start,
|
||||
multiboot_end, memory_map_tag.memory_areas());
|
||||
|
||||
for i in 0.. {
|
||||
if let None = frame_allocator.allocate_frame() {
|
||||
println!("allocated {} frames", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
memory::test_paging(&mut frame_allocator);
|
||||
|
||||
loop{}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub use self::area_frame_allocator::AreaFrameAllocator;
|
||||
pub use self::paging::test_paging;
|
||||
use self::paging::PhysicalAddress;
|
||||
|
||||
mod area_frame_allocator;
|
||||
|
||||
@@ -151,3 +151,20 @@ impl ActivePageTable {
|
||||
allocator.deallocate_frame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn test_paging<A>(allocator: &mut A)
|
||||
where A: FrameAllocator
|
||||
{
|
||||
let mut page_table = unsafe { ActivePageTable::new() };
|
||||
|
||||
let addr = 42 * 512 * 512 * 4096; // 42th P3 entry
|
||||
let page = Page::containing_address(addr);
|
||||
let frame = allocator.allocate_frame().expect("no more frames");
|
||||
println!("None = {:?}, map to {:?}",
|
||||
page_table.translate(addr),
|
||||
frame);
|
||||
page_table.map_to(page, frame, EntryFlags::empty(), allocator);
|
||||
println!("Some = {:?}", page_table.translate(addr));
|
||||
println!("next free frame: {:?}", allocator.allocate_frame());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user