-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor frame/paging into a single module, make Frame implement Drop
- Loading branch information
Showing
9 changed files
with
227 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! Memory handling module. Contains both a physical memory allocator, and the | ||
//! paging submodule. | ||
|
||
pub mod paging; | ||
pub mod frame_alloc; | ||
|
||
use core::fmt::{Formatter, Error, Display, Debug}; | ||
|
||
/// Represents a Physical address | ||
/// | ||
/// Should only be used when paging is off | ||
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct PhysicalAddress(pub usize); | ||
/// Represents a Virtual address | ||
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct VirtualAddress(pub usize); | ||
|
||
impl VirtualAddress { pub fn addr(&self) -> usize { self.0 } } | ||
impl PhysicalAddress { pub fn addr(&self) -> usize { self.0 } } | ||
|
||
impl ::core::ops::Add<usize> for VirtualAddress { | ||
type Output = VirtualAddress; | ||
|
||
fn add(self, other: usize) -> VirtualAddress { | ||
VirtualAddress(self.0 + other) | ||
} | ||
} | ||
|
||
impl ::core::ops::Add<usize> for PhysicalAddress { | ||
type Output = PhysicalAddress; | ||
|
||
fn add(self, other: usize) -> PhysicalAddress { | ||
PhysicalAddress(self.0 + other) | ||
} | ||
} | ||
|
||
impl Debug for PhysicalAddress { | ||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { | ||
write!(f, "P {:#010x}", self.0) | ||
} | ||
} | ||
|
||
impl Display for PhysicalAddress { | ||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { | ||
write!(f, "P {:#010x}", self.0) | ||
} | ||
} | ||
|
||
impl Debug for VirtualAddress { | ||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { | ||
write!(f, "V {:#010x}", self.0) | ||
} | ||
} | ||
|
||
impl Display for VirtualAddress { | ||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { | ||
write!(f, "V {:#010x}", self.0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.