diff --git a/posts/DRAFT-paging.md b/posts/DRAFT-paging.md index 9d75fc7f..3558c0da 100644 --- a/posts/DRAFT-paging.md +++ b/posts/DRAFT-paging.md @@ -738,8 +738,29 @@ We can also free the P1, P2, or even P3 table when the last entry is freed. But _Spoiler_: There is an ugly bug in this function, which we will find in the next section. ## Testing it -TODO +To test it, we add a `test_paging` function in `memory/paging/mod.rs`: +```rust +pub fn test_paging(allocator: &mut A) + where A: FrameAllocator +{ + let page_table = unsafe { RecursivePageTable::new() }; + + // test it +} +``` +We borrow the frame allocator since we will need it for the mapping functions. To be able to call that function from main, we need to reexport it in `memory/mod.rs`: + +```rust +// in memory/mod.rs +pub use self::paging::test_paging; + +// lib.rs +let mut frame_allocator = ...; +memory::test_paging(&mut frame_allocator); +``` + +TODO ## What's next? In the next post we will extend this module and add a function to modify inactive page tables. Through that function, we will create a new page table hierarchy that maps the kernel correctly using 4KiB pages. Then we will switch to the new table to get a safer kernel environment. diff --git a/src/lib.rs b/src/lib.rs index 2350abfd..35e160e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,13 +59,7 @@ pub extern fn rust_main(multiboot_information_address: usize) { let mut frame_allocator = memory::AreaFrameAllocator::new(kernel_start as usize, kernel_end as usize, multiboot_start, multiboot_end, memory_map_tag.memory_areas()); - for i in 0.. { - use memory::FrameAllocator; - if let None = frame_allocator.allocate_frame() { - println!("allocated {} frames", i); - break; - } - } + memory::test_paging(&mut frame_allocator); loop{} } diff --git a/src/memory/mod.rs b/src/memory/mod.rs index 064be1c1..ab420af7 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -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; diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs index 0b9c22ed..38cda373 100644 --- a/src/memory/paging/mod.rs +++ b/src/memory/paging/mod.rs @@ -143,3 +143,9 @@ impl RecursivePageTable { allocator.deallocate_frame(frame); } } + +pub fn test_paging(allocator: &mut A) + where A: FrameAllocator +{ + let page_table = unsafe { RecursivePageTable::new() }; +}