Skip to content

Commit c0cbc1c

Browse files
Merge pull request #343 from 0xllx0/riscv/register/miselect
riscv: add the `miselect` CSR
2 parents 527f6e2 + b4385d0 commit c0cbc1c

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

riscv/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `miselect` CSR
13+
1014
## [v0.15.0] - 2025-09-08
1115

1216
### Added

riscv/src/register.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ pub mod mseccfg;
117117
#[cfg(any(test, target_arch = "riscv32"))]
118118
pub mod mseccfgh;
119119

120+
// Machine indirect access
121+
pub mod miselect;
122+
120123
#[cfg(test)]
121124
mod tests;
122125

riscv/src/register/miselect.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//! `miselect` register.
2+
3+
const MASK: usize = usize::MAX;
4+
5+
read_write_csr! {
6+
/// `miselect` register.
7+
Miselect: 0x350,
8+
mask: MASK,
9+
}
10+
11+
#[cfg(target_arch = "riscv32")]
12+
read_write_csr_field! {
13+
Miselect,
14+
/// Returns whether `miselect` is for custom use of indirect CSRs.
15+
is_custom: 31,
16+
}
17+
18+
#[cfg(not(target_arch = "riscv32"))]
19+
read_write_csr_field! {
20+
Miselect,
21+
/// Returns whether `miselect` is for custom use of indirect CSRs.
22+
is_custom: 63,
23+
}
24+
25+
#[cfg(target_arch = "riscv32")]
26+
read_write_csr_field! {
27+
Miselect,
28+
/// Gets the value stored in the `miselect` CSR.
29+
///
30+
/// # Note
31+
///
32+
/// The semantics of the value depend on the extension for the referenced CSR,
33+
/// and the relevant `mireg*` value.
34+
value: [0:30],
35+
}
36+
37+
#[cfg(not(target_arch = "riscv32"))]
38+
read_write_csr_field! {
39+
Miselect,
40+
/// Gets the value stored in the `miselect` CSR.
41+
///
42+
/// # Note
43+
///
44+
/// The semantics of the value depend on the extension for the referenced CSR,
45+
/// and the relevant `mireg*` value.
46+
value: [0:62],
47+
}
48+
49+
#[cfg(test)]
50+
mod tests {
51+
use super::*;
52+
53+
#[test]
54+
fn test() {
55+
(0..=usize::BITS)
56+
.map(|r| ((1u128 << r) - 1) as usize)
57+
.for_each(|bits| {
58+
let mut miselect = Miselect::from_bits(bits);
59+
60+
test_csr_field!(miselect, is_custom);
61+
test_csr_field!(miselect, value: [0, usize::BITS - 2], 0);
62+
});
63+
}
64+
}

0 commit comments

Comments
 (0)