Skip to content

Commit 9f6cd9c

Browse files
committed
riscv: add the mvien + mvienh CSR
Adds the `mvien` + `mvienh` CSR to represent the `Machine Virtual Interrupt Enable` registers.
1 parent bedbc41 commit 9f6cd9c

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

riscv/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- Add `miselect` CSR
1414
- Improved assembly macro handling in asm.rs
1515
- New `rt` and `rt-v-trap` features to opt-in `riscv-rt`-related code in `riscv::pac_enum` macro.
16+
- Add `mvien` + `mvienh` CSR
1617

1718
# Changed
1819

riscv/src/register.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ pub mod mscratch;
9191
pub mod mtinst;
9292
pub mod mtval;
9393
pub mod mtval2;
94+
pub mod mvien;
95+
#[cfg(any(test, target_arch = "riscv32"))]
96+
pub mod mvienh;
9497

9598
// Machine Protection and Translation
9699
mod pmpcfgx;

riscv/src/register/mvien.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//! mvien register
2+
3+
#[cfg(target_arch = "riscv32")]
4+
const MASK: usize = 0xffff_e222;
5+
#[cfg(not(target_arch = "riscv32"))]
6+
const MASK: usize = 0xffff_ffff_ffff_e222;
7+
8+
read_write_csr! {
9+
/// `mvien` register
10+
Mvien: 0x308,
11+
mask: MASK,
12+
}
13+
14+
read_write_csr_field! {
15+
Mvien,
16+
/// Alias of `mip.SSIP`
17+
ssip: 1,
18+
}
19+
20+
read_write_csr_field! {
21+
Mvien,
22+
/// Alias of `mip.STIP`
23+
stip: 5,
24+
}
25+
26+
read_write_csr_field! {
27+
Mvien,
28+
/// Alias of `mip.SEIP`
29+
seip: 9,
30+
}
31+
32+
#[cfg(target_arch = "riscv32")]
33+
read_write_csr_field! {
34+
Mvien,
35+
/// Represents the enable status of a virtual major interrupt.
36+
interrupt: 13..=31,
37+
}
38+
39+
#[cfg(not(target_arch = "riscv32"))]
40+
read_write_csr_field! {
41+
Mvien,
42+
/// Represents the enable status of a virtual major interrupt.
43+
interrupt: 13..=63,
44+
}
45+
46+
set!(0x308);
47+
clear!(0x308);
48+
49+
#[cfg(test)]
50+
mod tests {
51+
use super::*;
52+
53+
#[test]
54+
fn test_mvien() {
55+
let mut m = Mvien::from_bits(0);
56+
57+
test_csr_field!(m, ssip);
58+
test_csr_field!(m, stip);
59+
test_csr_field!(m, seip);
60+
61+
(13..64).for_each(|idx| {
62+
test_csr_field!(m, interrupt, idx);
63+
});
64+
}
65+
}

riscv/src/register/mvienh.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//! mvienh register
2+
3+
read_write_csr! {
4+
/// `mvienh` register
5+
Mvienh: 0x318,
6+
mask: 0xffff_ffff,
7+
}
8+
9+
read_write_csr_field! {
10+
Mvienh,
11+
/// Represents the enable status of a virtual major interrupt.
12+
interrupt: 0..=31,
13+
}
14+
15+
set!(0x318);
16+
clear!(0x318);
17+
18+
#[cfg(test)]
19+
mod tests {
20+
use super::*;
21+
22+
#[test]
23+
fn test_mvienh() {
24+
let mut m = Mvienh::from_bits(0);
25+
26+
(0..32).for_each(|idx| {
27+
test_csr_field!(m, interrupt, idx);
28+
});
29+
}
30+
}

0 commit comments

Comments
 (0)