Skip to content

Commit 6c33cce

Browse files
committed
register: add mtval2 register
Adds the definition for the `mtval2` Machine trap value 2 CSR.
1 parent 392144e commit 6c33cce

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

riscv/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515
- Add `scontext` CSR
1616
- Add `mconfigptr` CSR
1717
- Bump MSRV to 1.67.0 for `log` to `ilog` name change
18+
- Add `mtval2` CSR
1819

1920
### Changed
2021

riscv/src/register.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub mod mip;
9090
pub mod mscratch;
9191
pub mod mtinst;
9292
pub mod mtval;
93+
pub mod mtval2;
9394

9495
// Machine Protection and Translation
9596
mod pmpcfgx;

riscv/src/register/mtval2.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! mtval register
2+
3+
const MASK: usize = usize::MAX;
4+
5+
read_only_csr! {
6+
/// mtval2 register
7+
Mtval2: 0x348,
8+
mask: MASK,
9+
}
10+
11+
impl Mtval2 {
12+
/// Represents the bitshift value of the guest-page address stored in `mtval2`.
13+
pub const GUEST_PAGE_SHIFT: usize = 2;
14+
15+
/// Gets the guest-page fault physical address.
16+
///
17+
/// # Note
18+
///
19+
/// The address is written when an invalid implicit memory access during address translation.
20+
pub const fn guest_fault_address(&self) -> usize {
21+
self.bits() << Self::GUEST_PAGE_SHIFT
22+
}
23+
}

0 commit comments

Comments
 (0)