mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Add and call test_paging function
This commit is contained in:
@@ -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<A>(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.
|
||||
|
||||
@@ -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{}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -143,3 +143,9 @@ impl RecursivePageTable {
|
||||
allocator.deallocate_frame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_paging<A>(allocator: &mut A)
|
||||
where A: FrameAllocator
|
||||
{
|
||||
let page_table = unsafe { RecursivePageTable::new() };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user