Skip to content

Commit 31f4127

Browse files
committed
Add PMP CSRs
1 parent f37ab22 commit 31f4127

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/register/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ pub mod mtval;
7676
pub mod mip;
7777

7878

79-
// TODO: Machine Protection and Translation
79+
// Machine Protection and Translation
80+
mod pmpcfgx;
81+
pub use self::pmpcfgx::*;
82+
mod pmpaddrx;
83+
pub use self::pmpaddrx::*;
84+
8085

8186
// Machine Counter/Timers
8287
pub mod mcycle;

src/register/pmpaddrx.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
macro_rules! reg {
2+
(
3+
$addr:expr, $csr:ident, $readf:ident, $writef:ident
4+
) => {
5+
/// Physical memory protection address register
6+
pub mod $csr {
7+
read_csr_as_usize!($addr, $readf);
8+
write_csr_as_usize!($addr, $writef);
9+
}
10+
}
11+
}
12+
13+
reg!(0x3B0, pmpaddr0, __read_pmpaddr0, __write_pmpaddr0);
14+
reg!(0x3B1, pmpaddr1, __read_pmpaddr1, __write_pmpaddr1);
15+
reg!(0x3B2, pmpaddr2, __read_pmpaddr2, __write_pmpaddr2);
16+
reg!(0x3B3, pmpaddr3, __read_pmpaddr3, __write_pmpaddr3);
17+
reg!(0x3B4, pmpaddr4, __read_pmpaddr4, __write_pmpaddr4);
18+
reg!(0x3B5, pmpaddr5, __read_pmpaddr5, __write_pmpaddr5);
19+
reg!(0x3B6, pmpaddr6, __read_pmpaddr6, __write_pmpaddr6);
20+
reg!(0x3B7, pmpaddr7, __read_pmpaddr7, __write_pmpaddr7);
21+
reg!(0x3B8, pmpaddr8, __read_pmpaddr8, __write_pmpaddr8);
22+
reg!(0x3B9, pmpaddr9, __read_pmpaddr9, __write_pmpaddr9);
23+
reg!(0x3BA, pmpaddr10, __read_pmpaddr10, __write_pmpaddr10);
24+
reg!(0x3BB, pmpaddr11, __read_pmpaddr11, __write_pmpaddr11);
25+
reg!(0x3BC, pmpaddr12, __read_pmpaddr12, __write_pmpaddr12);
26+
reg!(0x3BD, pmpaddr13, __read_pmpaddr13, __write_pmpaddr13);
27+
reg!(0x3BE, pmpaddr14, __read_pmpaddr14, __write_pmpaddr14);
28+
reg!(0x3BF, pmpaddr15, __read_pmpaddr15, __write_pmpaddr15);

src/register/pmpcfgx.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// Physical memory protection configuration
2+
pub mod pmpcfg0 {
3+
read_csr_as_usize!(0x3A0, __read_pmpcfg0);
4+
write_csr_as_usize!(0x3A0, __write_pmpcfg0);
5+
}
6+
7+
/// Physical memory protection configuration, RV32 only
8+
pub mod pmpcfg1 {
9+
read_csr_as_usize_rv32!(0x3A1, __read_pmpcfg1);
10+
write_csr_as_usize_rv32!(0x3A1, __write_pmpcfg1);
11+
}
12+
13+
/// Physical memory protection configuration
14+
pub mod pmpcfg2 {
15+
read_csr_as_usize!(0x3A2, __read_pmpcfg2);
16+
write_csr_as_usize!(0x3A2, __write_pmpcfg2);
17+
}
18+
19+
/// Physical memory protection configuration, RV32 only
20+
pub mod pmpcfg3 {
21+
read_csr_as_usize_rv32!(0x3A3, __read_pmpcfg3);
22+
write_csr_as_usize_rv32!(0x3A3, __write_pmpcfg3);
23+
}

0 commit comments

Comments
 (0)