@@ -31,26 +31,14 @@ pub mod pmpcfg0 {
31
31
}
32
32
33
33
#[ derive( Clone , Copy , Debug ) ]
34
- pub struct Pmpcfg0 {
35
- bits : usize ,
34
+ pub struct PmpByte {
35
+ byte : u8 ,
36
36
}
37
37
38
- impl Pmpcfg0 {
39
- ///Returns the pmp byte associated with the index
40
- #[ inline]
41
- pub fn pmp_byte ( & self , index : usize ) -> usize {
42
- #[ cfg( riscv32) ]
43
- assert ! ( index < 4 ) ;
44
-
45
- #[ cfg( riscv64) ]
46
- assert ! ( index < 8 ) ;
47
-
48
- self . bits . get_bits ( 8 * index..8 * ( index + 1 ) )
49
- }
50
-
38
+ impl PmpByte {
51
39
#[ inline]
52
- fn range ( & self , byte : usize ) -> Range {
53
- match byte. get_bits ( 4 ..6 ) {
40
+ fn range ( & self ) -> Range {
41
+ match self . byte . get_bits ( 4 ..= 5 ) {
54
42
0 => Range :: OFF ,
55
43
1 => Range :: TOR ,
56
44
2 => Range :: NA4 ,
@@ -60,9 +48,9 @@ pub mod pmpcfg0 {
60
48
}
61
49
62
50
#[ inline]
63
- fn permission ( & self , byte : usize ) -> Option < Permission > {
64
- match byte. get_bits ( 0 ..3 ) {
65
- 0 => Some ( Permission :: NONE ) ,
51
+ fn permission ( & self ) -> Option < Permission > {
52
+ match self . byte . get_bits ( 0 ..= 2 ) {
53
+ 0 => None ,
66
54
1 => Some ( Permission :: R ) ,
67
55
2 => Some ( Permission :: W ) ,
68
56
3 => Some ( Permission :: RW ) ,
@@ -74,14 +62,39 @@ pub mod pmpcfg0 {
74
62
}
75
63
}
76
64
65
+ #[ inline]
66
+ fn locked ( & self ) -> bool {
67
+ self . byte . get_bit ( 7 )
68
+ }
69
+ }
70
+
71
+ #[ derive( Clone , Copy , Debug ) ]
72
+ pub struct Pmpcfg0 {
73
+ bits : usize ,
74
+ }
75
+
76
+ impl Pmpcfg0 {
77
+ ///Returns the pmp byte associated with the index
78
+ #[ inline]
79
+ fn pmp_byte ( & self , index : usize ) -> PmpByte {
80
+ #[ cfg( riscv32) ]
81
+ assert ! ( index < 4 ) ;
82
+
83
+ #[ cfg( riscv64) ]
84
+ assert ! ( index < 8 ) ;
85
+
86
+ PmpByte { byte : self . bits . get_bits ( 8 * index..8 * ( index + 1 ) ) as u8 }
87
+ }
88
+
89
+
90
+
77
91
///Returns pmp[x]cfg configuration structure
78
92
#[ inline]
79
93
pub fn pmp_cfg ( & self , index : usize ) -> Pmpconfig {
80
- assert ! ( index < 8 ) ;
81
94
let byte = self . pmp_byte ( index) ;
82
- let p = self . permission ( byte ) . unwrap ( ) ;
83
- let r = self . range ( byte ) ;
84
- let l = byte. get_bit ( 7 ) ;
95
+ let p = byte . permission ( ) . unwrap ( ) ;
96
+ let r = byte . range ( ) ;
97
+ let l = byte. locked ( ) ;
85
98
86
99
Pmpconfig {
87
100
permission : p,
@@ -98,25 +111,45 @@ pub mod pmpcfg0 {
98
111
99
112
#[ inline]
100
113
pub unsafe fn set_permissions ( permission : Permission , index : usize ) {
114
+ #[ cfg( riscv32) ]
115
+ assert ! ( index < 4 ) ;
116
+
117
+ #[ cfg( riscv64) ]
101
118
assert ! ( index < 8 ) ;
102
- _set ( ( permission as usize ) << ( index * 8 ) ) ;
119
+
120
+ _write ( ( permission as usize ) << ( index * 8 ) ) ;
103
121
}
104
122
105
123
#[ inline]
106
124
pub unsafe fn set_range ( range : Range , index : usize ) {
125
+ #[ cfg( riscv32) ]
126
+ assert ! ( index < 4 ) ;
127
+
128
+ #[ cfg( riscv64) ]
107
129
assert ! ( index < 8 ) ;
108
- _set ( ( range as usize ) << ( 3 + ( index * 8 ) ) ) ;
130
+
131
+ _write ( ( range as usize ) << ( 3 + ( index * 8 ) ) ) ;
109
132
}
110
133
111
134
#[ inline]
112
135
pub unsafe fn set_lock ( index : usize ) {
136
+ #[ cfg( riscv32) ]
137
+ assert ! ( index < 4 ) ;
138
+
139
+ #[ cfg( riscv64) ]
113
140
assert ! ( index < 8 ) ;
141
+
114
142
_set ( 1 << ( 7 + ( index * 8 ) ) ) ;
115
143
}
116
144
117
145
#[ inline]
118
146
pub unsafe fn clear_lock ( index : usize ) {
147
+ #[ cfg( riscv32) ]
148
+ assert ! ( index < 4 ) ;
149
+
150
+ #[ cfg( riscv64) ]
119
151
assert ! ( index < 8 ) ;
152
+
120
153
_clear ( 1 << ( 7 + ( index * 8 ) ) ) ;
121
154
}
122
155
}
0 commit comments