mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Test translate function
This commit is contained in:
@@ -760,7 +760,36 @@ let mut frame_allocator = ...;
|
|||||||
memory::test_paging(&mut frame_allocator);
|
memory::test_paging(&mut frame_allocator);
|
||||||
```
|
```
|
||||||
|
|
||||||
TODO
|
### translate
|
||||||
|
First, we translate some addresses:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
// address 0 is mapped
|
||||||
|
println!("Some = {:?}", page_table.translate(0));
|
||||||
|
// second P1 entry
|
||||||
|
println!("Some = {:?}", page_table.translate(4096));
|
||||||
|
// second P2 entry
|
||||||
|
println!("Some = {:?}", page_table.translate(512 * 4096));
|
||||||
|
// 300th P2 entry
|
||||||
|
println!("Some = {:?}", page_table.translate(300 * 512 * 4096));
|
||||||
|
// second P3 entry
|
||||||
|
println!("None = {:?}", page_table.translate(512 * 512 * 4096));
|
||||||
|
// last mapped byte
|
||||||
|
println!("Some = {:?}", page_table.translate(512 * 512 * 4096 - 1));
|
||||||
|
```
|
||||||
|
Currently, the first GiB of the address space is identity-mapped. Thus all addresses in this area should translate to `Some(x)`, where `x` is the virtual address. Only the second last address, `512 * 512 * 4096`, is not in that area and should resolve to `None`.
|
||||||
|
|
||||||
|
But the output shows two `None` lines:
|
||||||
|
|
||||||
|
```
|
||||||
|
Some = Some(0)
|
||||||
|
Some = Some(4096)
|
||||||
|
Some = Some(2097152)
|
||||||
|
Some = Some(629145600)
|
||||||
|
None = None
|
||||||
|
Some = None
|
||||||
|
```
|
||||||
|
The last line is wrong. But why?
|
||||||
|
|
||||||
## What's next?
|
## 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.
|
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.
|
||||||
|
|||||||
@@ -148,4 +148,11 @@ pub fn test_paging<A>(allocator: &mut A)
|
|||||||
where A: FrameAllocator
|
where A: FrameAllocator
|
||||||
{
|
{
|
||||||
let page_table = unsafe { RecursivePageTable::new() };
|
let page_table = unsafe { RecursivePageTable::new() };
|
||||||
|
|
||||||
|
println!("Some = {:?}", page_table.translate(0));
|
||||||
|
println!("Some = {:?}", page_table.translate(4096)); // second P1 entry
|
||||||
|
println!("Some = {:?}", page_table.translate(512 * 4096)); // second P2 entry
|
||||||
|
println!("Some = {:?}", page_table.translate(300 * 512 * 4096)); // 300th P2 entry
|
||||||
|
println!("None = {:?}", page_table.translate(512 * 512 * 4096)); // second P3 entry
|
||||||
|
println!("Some = {:?}", page_table.translate(512 * 512 * 4096 - 1)); // last mapped byte
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user