@@ -86,10 +86,8 @@ pub mod pmpcfg0 {
86
86
87
87
read_csr_as ! ( Pmpcsr , 0x3A0 , __read_pmpcfg0) ;
88
88
write_csr_as_usize ! ( 0x3A0 , __write_pmpcfg0) ;
89
- set ! ( 0x3A0 , __set_pmpcfg0) ;
90
- clear ! ( 0x3A0 , __clear_pmpcfg0) ;
91
89
92
- /// set the configuration for pmp(x)
90
+ /// set the configuration for the defined index in pmpcfg3
93
91
pub unsafe fn set_pmp ( index : usize , range : Range , permission : Permission , locked : bool ) {
94
92
#[ cfg( riscv32) ]
95
93
assert ! ( index < 4 ) ;
@@ -100,7 +98,21 @@ pub mod pmpcfg0 {
100
98
let mut value = _read ( ) ;
101
99
let byte = ( locked as usize ) << 7 | ( range as usize ) << 3 | ( permission as usize ) ;
102
100
value. set_bits ( 8 * index..=8 * index + 7 , byte) ;
103
- _set ( value)
101
+ _write ( value)
102
+ }
103
+
104
+ /// clear the configuration for the defined index in pmpcfg0
105
+ /// will not work when pmp is locked
106
+ pub unsafe fn clear_pmp ( index : usize ) {
107
+ #[ cfg( riscv32) ]
108
+ assert ! ( index < 4 ) ;
109
+
110
+ #[ cfg( riscv64) ]
111
+ assert ! ( index < 8 ) ;
112
+
113
+ let mut value = _read ( ) ;
114
+ value. set_bits ( 8 * index..=8 * index + 7 , 0 ) ;
115
+ _write ( value) ;
104
116
}
105
117
}
106
118
@@ -113,17 +125,25 @@ pub mod pmpcfg1 {
113
125
114
126
read_csr_as ! ( Pmpcsr , 0x3A1 , __read_pmpcfg1) ;
115
127
write_csr_as_usize_rv32 ! ( 0x3A1 , __write_pmpcfg1) ;
116
- set ! ( 0x3A1 , __set_pmpcfg1) ;
117
- clear ! ( 0x3A1 , __clear_pmpcfg1) ;
118
128
119
- /// set the configuration for pmp(x)
129
+ /// set the configuration for the defined index in pmpcfg3
120
130
pub unsafe fn set_pmp ( index : usize , range : Range , permission : Permission , locked : bool ) {
121
131
assert ! ( index < 4 ) ;
122
132
123
133
let mut value = _read ( ) ;
124
134
let byte = ( locked as usize ) << 7 | ( range as usize ) << 3 | ( permission as usize ) ;
125
135
value. set_bits ( 8 * index..=8 * index + 7 , byte) ;
126
- _set ( value)
136
+ _write ( value)
137
+ }
138
+
139
+ /// clear the configuration for the defined index in pmpcfg1
140
+ /// will not work when pmp is locked
141
+ pub unsafe fn clear_pmp ( index : usize ) {
142
+ assert ! ( index < 4 ) ;
143
+
144
+ let mut value = _read ( ) ;
145
+ value. set_bits ( 8 * index..=8 * index + 7 , 0 ) ;
146
+ _write ( value) ;
127
147
}
128
148
}
129
149
@@ -135,10 +155,8 @@ pub mod pmpcfg2 {
135
155
136
156
read_csr_as ! ( Pmpcsr , 0x3A2 , __read_pmpcfg2) ;
137
157
write_csr_as_usize ! ( 0x3A2 , __write_pmpcfg2) ;
138
- set ! ( 0x3A2 , __set_pmpcfg2) ;
139
- clear ! ( 0x3A2 , __clear_pmpcfg2) ;
140
158
141
- /// set the configuration for pmp(x)
159
+ /// set the configuration for the defined index in pmpcfg3
142
160
pub unsafe fn set_pmp ( index : usize , range : Range , permission : Permission , locked : bool ) {
143
161
#[ cfg( riscv32) ]
144
162
assert ! ( index < 4 ) ;
@@ -149,7 +167,21 @@ pub mod pmpcfg2 {
149
167
let mut value = _read ( ) ;
150
168
let byte = ( locked as usize ) << 7 | ( range as usize ) << 3 | ( permission as usize ) ;
151
169
value. set_bits ( 8 * index..=8 * index + 7 , byte) ;
152
- _set ( value)
170
+ _write ( value)
171
+ }
172
+
173
+ /// clear the configuration for the defined index in pmpcfg2
174
+ /// will not work when pmp is locked
175
+ pub unsafe fn clear_pmp ( index : usize ) {
176
+ #[ cfg( riscv32) ]
177
+ assert ! ( index < 4 ) ;
178
+
179
+ #[ cfg( riscv64) ]
180
+ assert ! ( index < 8 ) ;
181
+
182
+ let mut value = _read ( ) ;
183
+ value. set_bits ( 8 * index..=8 * index + 7 , 0 ) ;
184
+ _write ( value) ;
153
185
}
154
186
}
155
187
@@ -162,16 +194,27 @@ pub mod pmpcfg3 {
162
194
163
195
read_csr_as ! ( Pmpcsr , 0x3A3 , __read_pmpcfg3) ;
164
196
write_csr_as_usize_rv32 ! ( 0x3A3 , __write_pmpcfg3) ;
165
- set ! ( 0x3A3 , __set_pmpcfg3) ;
166
- clear ! ( 0x3A3 , __clear_pmpcfg3) ;
167
197
168
- /// set the configuration for pmp(x)
198
+ /// set the configuration for the defined index in pmpcfg3
169
199
pub unsafe fn set_pmp ( index : usize , range : Range , permission : Permission , locked : bool ) {
170
200
assert ! ( index < 4 ) ;
171
201
172
202
let mut value = _read ( ) ;
173
203
let byte = ( locked as usize ) << 7 | ( range as usize ) << 3 | ( permission as usize ) ;
174
204
value. set_bits ( 8 * index..=8 * index + 7 , byte) ;
175
- _set ( value)
205
+ _write ( value)
206
+ }
207
+ /// clear the configuration for the defined index in pmpcfg3
208
+ /// will not work when pmp is locked
209
+ pub unsafe fn clear_pmp ( index : usize ) {
210
+ #[ cfg( riscv32) ]
211
+ assert ! ( index < 4 ) ;
212
+
213
+ #[ cfg( riscv64) ]
214
+ assert ! ( index < 8 ) ;
215
+
216
+ let mut value = _read ( ) ;
217
+ value. set_bits ( 8 * index..=8 * index + 7 , 0 ) ;
218
+ _write ( value) ;
176
219
}
177
220
}
0 commit comments