mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Move Frame::start_address to memory/mod.rs and use it in identity_map()
This commit is contained in:
@@ -130,18 +130,16 @@ pub fn set(&mut self, frame: Frame, flags: EntryFlags) {
|
|||||||
```
|
```
|
||||||
The start address of a frame should be page aligned and smaller than 2^52 (since x86 uses 52bit physical addresses). Since an invalid address could mess up the entry, we add an assertion. To actually set the entry, we just need to `or` the start address and the flag bits.
|
The start address of a frame should be page aligned and smaller than 2^52 (since x86 uses 52bit physical addresses). Since an invalid address could mess up the entry, we add an assertion. To actually set the entry, we just need to `or` the start address and the flag bits.
|
||||||
|
|
||||||
The missing `start_address` function is pretty simple:
|
The missing `Frame::start_address` method is pretty simple:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use memory::paging::PhysicalAddress;
|
use self::paging::PhysicalAddress;
|
||||||
|
|
||||||
impl Frame {
|
fn start_address(&self) -> PhysicalAddress {
|
||||||
fn start_address(&self) -> PhysicalAddress {
|
self.number * PAGE_SIZE
|
||||||
self.number << 12
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Since we only need it in the entry submodule, we put it in a new `impl Frame` block in `entry.rs`.
|
We add it to the `impl Frame` block in `memory/mod.rs`.
|
||||||
|
|
||||||
### Page Tables
|
### Page Tables
|
||||||
To model page tables, we create a basic `Table` struct in a new `table` submodule:
|
To model page tables, we create a basic `Table` struct in a new `table` submodule:
|
||||||
@@ -640,7 +638,7 @@ pub fn identity_map<A>(&mut self,
|
|||||||
allocator: &mut A)
|
allocator: &mut A)
|
||||||
where A: FrameAllocator
|
where A: FrameAllocator
|
||||||
{
|
{
|
||||||
let page = Page { number: frame.number };
|
let page = Page::containing_address(frame.start_address());
|
||||||
self.map_to(&page, frame, flags, allocator)
|
self.map_to(&page, frame, flags, allocator)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
pub use self::area_frame_allocator::AreaFrameAllocator;
|
pub use self::area_frame_allocator::AreaFrameAllocator;
|
||||||
|
use self::paging::PhysicalAddress;
|
||||||
|
|
||||||
pub mod paging;
|
pub mod paging;
|
||||||
mod area_frame_allocator;
|
mod area_frame_allocator;
|
||||||
@@ -14,6 +15,10 @@ impl Frame {
|
|||||||
fn containing_address(address: usize) -> Frame {
|
fn containing_address(address: usize) -> Frame {
|
||||||
Frame { number: address / PAGE_SIZE }
|
Frame { number: address / PAGE_SIZE }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn start_address(&self) -> PhysicalAddress {
|
||||||
|
self.number * PAGE_SIZE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FrameAllocator {
|
pub trait FrameAllocator {
|
||||||
|
|||||||
@@ -44,9 +44,3 @@ bitflags! {
|
|||||||
const NO_EXECUTE = 1 << 63,
|
const NO_EXECUTE = 1 << 63,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Frame {
|
|
||||||
fn start_address(&self) -> PhysicalAddress {
|
|
||||||
self.number << 12
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ impl RecursivePageTable {
|
|||||||
pub fn identity_map<A>(&mut self, frame: Frame, flags: EntryFlags, allocator: &mut A)
|
pub fn identity_map<A>(&mut self, frame: Frame, flags: EntryFlags, allocator: &mut A)
|
||||||
where A: FrameAllocator
|
where A: FrameAllocator
|
||||||
{
|
{
|
||||||
let page = Page { number: frame.number };
|
let page = Page::containing_address(frame.start_address());
|
||||||
self.map_to(&page, frame, flags, allocator)
|
self.map_to(&page, frame, flags, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user