2
2
3
3
use super :: { PageSize , PhysFrame , Size4KiB } ;
4
4
use crate :: addr:: PhysAddr ;
5
+ use bitflags:: bitflags;
5
6
use core:: fmt;
6
7
#[ cfg( feature = "step_trait" ) ]
7
8
use core:: iter:: Step ;
8
9
use core:: ops:: { Index , IndexMut } ;
10
+ #[ cfg( feature = "dynamic_flags" ) ]
9
11
use core:: sync:: atomic:: { AtomicU64 , Ordering } ;
10
- use bitflags:: bitflags;
11
12
12
13
/// The error returned by the `PageTableEntry::frame` method.
13
14
#[ derive( Debug , Clone , Copy , PartialEq ) ]
@@ -49,19 +50,13 @@ impl PageTableEntry {
49
50
self . entry = 0 ;
50
51
}
51
52
52
- /// Returns the flags of this entry.
53
- #[ inline]
54
- pub fn flags ( & self ) -> PageTableFlags {
55
- PageTableFlags :: from_address_truncated ( self . entry )
56
- }
57
-
58
53
/// Returns the physical frame mapped by this entry.
59
54
///
60
55
/// Returns the following errors:
61
56
///
62
57
/// - `FrameError::FrameNotPresent` if the entry doesn't have the `PRESENT` flag set.
63
58
/// - `FrameError::HugeFrame` if the entry has the `HUGE_PAGE` flag set (for huge pages the
64
- /// `addr` function must be used)
59
+ /// `addr` function must be used)
65
60
#[ inline]
66
61
pub fn frame ( & self ) -> Result < PhysFrame , FrameError > {
67
62
if !self . flags ( ) . contains ( PageTableFlags :: PRESENT ) {
@@ -76,14 +71,14 @@ impl PageTableEntry {
76
71
/// Sets the flags of this entry.
77
72
#[ inline]
78
73
pub fn set_flags ( & mut self , flags : PageTableFlags ) {
79
- self . entry = self . addr ( ) . as_u64 ( ) | flags. bits_dynamic ( ) ;
74
+ self . entry = self . addr ( ) . as_u64 ( ) | flags. bits ( ) ;
80
75
}
81
76
82
77
/// Map the entry to the specified physical address with the specified flags.
83
78
#[ inline]
84
79
pub fn set_addr ( & mut self , addr : PhysAddr , flags : PageTableFlags ) {
85
80
assert ! ( addr. is_aligned( Size4KiB :: SIZE ) ) ;
86
- self . entry = ( addr. as_u64 ( ) ) | flags. bits_dynamic ( ) ;
81
+ self . entry = ( addr. as_u64 ( ) ) | flags. bits ( ) ;
87
82
}
88
83
89
84
/// Map the entry to the specified physical frame with the specified flags.
@@ -101,6 +96,14 @@ impl PageTableEntry {
101
96
pub fn addr ( & self ) -> PhysAddr {
102
97
PhysAddr :: new ( self . entry & PHYSICAL_ADDRESS_MASK . load ( Ordering :: Relaxed ) )
103
98
}
99
+
100
+ /// Returns the flags of this entry.
101
+ #[ inline]
102
+ pub fn flags ( & self ) -> PageTableFlags {
103
+ PageTableFlags :: from_bits_retain (
104
+ self . entry & !PHYSICAL_ADDRESS_MASK . load ( Ordering :: Relaxed ) ,
105
+ )
106
+ }
104
107
}
105
108
106
109
#[ cfg( not( feature = "dynamic_flags" ) ) ]
@@ -110,6 +113,12 @@ impl PageTableEntry {
110
113
pub fn addr ( & self ) -> PhysAddr {
111
114
PhysAddr :: new ( self . entry & 0x000f_ffff_ffff_f000u64 )
112
115
}
116
+
117
+ /// Returns the flags of this entry.
118
+ #[ inline]
119
+ pub fn flags ( & self ) -> PageTableFlags {
120
+ PageTableFlags :: from_bits_truncate ( self . entry )
121
+ }
113
122
}
114
123
115
124
impl Default for PageTableEntry {
@@ -193,28 +202,6 @@ bitflags! {
193
202
}
194
203
}
195
204
196
- #[ cfg( feature = "dynamic_flags" ) ]
197
- impl PageTableFlags {
198
- pub fn from_address_truncated ( address : u64 ) -> PageTableFlags {
199
- PageTableFlags :: from_bits_retain ( address & !PHYSICAL_ADDRESS_MASK . load ( Ordering :: Relaxed ) )
200
- }
201
-
202
- pub fn bits_dynamic ( & self ) -> u64 {
203
- self . bits ( ) & !PHYSICAL_ADDRESS_MASK . load ( Ordering :: Relaxed )
204
- }
205
- }
206
-
207
- #[ cfg( not( feature = "dynamic_flags" ) ) ]
208
- impl PageTableFlags {
209
- pub const fn from_address_truncated ( address : u64 ) -> PageTableFlags {
210
- PageTableFlags :: from_bits_truncate ( address)
211
- }
212
-
213
- pub const fn bits_dynamic ( & self ) -> u64 {
214
- self . bits ( )
215
- }
216
- }
217
-
218
205
/// The number of entries in a page table.
219
206
const ENTRY_COUNT : usize = 512 ;
220
207
0 commit comments