Skip to content

Commit d882f66

Browse files
committed
Remove set! macros in pmpcfgs, use _write. Add clear_pmp functions.
Tested and working in hardware
1 parent a178758 commit d882f66

File tree

1 file changed

+59
-16
lines changed

1 file changed

+59
-16
lines changed

src/register/pmpcfgx.rs

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ pub mod pmpcfg0 {
8686

8787
read_csr_as!(Pmpcsr, 0x3A0, __read_pmpcfg0);
8888
write_csr_as_usize!(0x3A0, __write_pmpcfg0);
89-
set!(0x3A0, __set_pmpcfg0);
90-
clear!(0x3A0, __clear_pmpcfg0);
9189

92-
/// set the configuration for pmp(x)
90+
/// set the configuration for the defined index in pmpcfg3
9391
pub unsafe fn set_pmp(index: usize, range: Range, permission: Permission, locked: bool) {
9492
#[cfg(riscv32)]
9593
assert!(index < 4);
@@ -100,7 +98,21 @@ pub mod pmpcfg0 {
10098
let mut value = _read();
10199
let byte = (locked as usize) << 7 | (range as usize) << 3 | (permission as usize);
102100
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);
104116
}
105117
}
106118

@@ -113,17 +125,25 @@ pub mod pmpcfg1 {
113125

114126
read_csr_as!(Pmpcsr, 0x3A1, __read_pmpcfg1);
115127
write_csr_as_usize_rv32!(0x3A1, __write_pmpcfg1);
116-
set!(0x3A1, __set_pmpcfg1);
117-
clear!(0x3A1, __clear_pmpcfg1);
118128

119-
/// set the configuration for pmp(x)
129+
/// set the configuration for the defined index in pmpcfg3
120130
pub unsafe fn set_pmp(index: usize, range: Range, permission: Permission, locked: bool) {
121131
assert!(index < 4);
122132

123133
let mut value = _read();
124134
let byte = (locked as usize) << 7 | (range as usize) << 3 | (permission as usize);
125135
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);
127147
}
128148
}
129149

@@ -135,10 +155,8 @@ pub mod pmpcfg2 {
135155

136156
read_csr_as!(Pmpcsr, 0x3A2, __read_pmpcfg2);
137157
write_csr_as_usize!(0x3A2, __write_pmpcfg2);
138-
set!(0x3A2, __set_pmpcfg2);
139-
clear!(0x3A2, __clear_pmpcfg2);
140158

141-
/// set the configuration for pmp(x)
159+
/// set the configuration for the defined index in pmpcfg3
142160
pub unsafe fn set_pmp(index: usize, range: Range, permission: Permission, locked: bool) {
143161
#[cfg(riscv32)]
144162
assert!(index < 4);
@@ -149,7 +167,21 @@ pub mod pmpcfg2 {
149167
let mut value = _read();
150168
let byte = (locked as usize) << 7 | (range as usize) << 3 | (permission as usize);
151169
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);
153185
}
154186
}
155187

@@ -162,16 +194,27 @@ pub mod pmpcfg3 {
162194

163195
read_csr_as!(Pmpcsr, 0x3A3, __read_pmpcfg3);
164196
write_csr_as_usize_rv32!(0x3A3, __write_pmpcfg3);
165-
set!(0x3A3, __set_pmpcfg3);
166-
clear!(0x3A3, __clear_pmpcfg3);
167197

168-
/// set the configuration for pmp(x)
198+
/// set the configuration for the defined index in pmpcfg3
169199
pub unsafe fn set_pmp(index: usize, range: Range, permission: Permission, locked: bool) {
170200
assert!(index < 4);
171201

172202
let mut value = _read();
173203
let byte = (locked as usize) << 7 | (range as usize) << 3 | (permission as usize);
174204
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);
176219
}
177220
}

0 commit comments

Comments
 (0)