page_table_entry/lib.rs
1#![cfg_attr(not(test), no_std)]
2#![cfg_attr(doc, feature(doc_auto_cfg))]
3#![doc = include_str!("../README.md")]
4
5mod arch;
6
7use core::fmt::{self, Debug};
8use memory_addr::PhysAddr;
9
10pub use self::arch::*;
11
12bitflags::bitflags! {
13 /// Generic page table entry flags that indicate the corresponding mapped
14 /// memory region permissions and attributes.
15 #[derive(Clone, Copy, PartialEq)]
16 pub struct MappingFlags: usize {
17 /// The memory is readable.
18 const READ = 1 << 0;
19 /// The memory is writable.
20 const WRITE = 1 << 1;
21 /// The memory is executable.
22 const EXECUTE = 1 << 2;
23 /// The memory is user accessible.
24 const USER = 1 << 3;
25 /// The memory is device memory.
26 const DEVICE = 1 << 4;
27 /// The memory is uncached.
28 const UNCACHED = 1 << 5;
29 }
30}
31
32impl Debug for MappingFlags {
33 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34 Debug::fmt(&self.0, f)
35 }
36}
37
38/// A generic page table entry.
39///
40/// All architecture-specific page table entry types implement this trait.
41pub trait GenericPTE: Debug + Clone + Copy + Sync + Send + Sized {
42 /// Creates a page table entry point to a terminate page or block.
43 fn new_page(paddr: PhysAddr, flags: MappingFlags, is_huge: bool) -> Self;
44 /// Creates a page table entry point to a next level page table.
45 fn new_table(paddr: PhysAddr) -> Self;
46
47 /// Returns the physical address mapped by this entry.
48 fn paddr(&self) -> PhysAddr;
49 /// Returns the flags of this entry.
50 fn flags(&self) -> MappingFlags;
51
52 /// Set mapped physical address of the entry.
53 fn set_paddr(&mut self, paddr: PhysAddr);
54 /// Set flags of the entry.
55 fn set_flags(&mut self, flags: MappingFlags, is_huge: bool);
56
57 /// Returns the raw bits of this entry.
58 fn bits(self) -> usize;
59 /// Returns whether this entry is zero.
60 fn is_unused(&self) -> bool;
61 /// Returns whether this entry flag indicates present.
62 fn is_present(&self) -> bool;
63 /// For non-last level translation, returns whether this entry maps to a
64 /// huge frame.
65 fn is_huge(&self) -> bool;
66 /// Set this entry to zero.
67 fn clear(&mut self);
68}