mirror of
https://github.com/hexagonal-sun/moss-kernel.git
synced 2025-12-23 22:47:55 -05:00
39 lines
797 B
Rust
39 lines
797 B
Rust
use core::fmt::Display;
|
|
|
|
use super::{PAGE_SHIFT, PAGE_SIZE, address::PA, region::PhysMemoryRegion};
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
|
pub struct PageFrame {
|
|
n: usize,
|
|
}
|
|
|
|
impl Display for PageFrame {
|
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
self.n.fmt(f)
|
|
}
|
|
}
|
|
|
|
impl PageFrame {
|
|
pub fn from_pfn(n: usize) -> Self {
|
|
Self { n }
|
|
}
|
|
|
|
pub fn pa(&self) -> PA {
|
|
PA::from_value(self.n << PAGE_SHIFT)
|
|
}
|
|
|
|
pub fn as_phys_range(&self) -> PhysMemoryRegion {
|
|
PhysMemoryRegion::new(self.pa(), PAGE_SIZE)
|
|
}
|
|
|
|
pub fn value(&self) -> usize {
|
|
self.n
|
|
}
|
|
|
|
pub(crate) fn buddy(self, order: usize) -> Self {
|
|
Self {
|
|
n: self.n ^ (1 << order),
|
|
}
|
|
}
|
|
}
|