File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ pub mod mip;
9090pub mod mscratch;
9191pub mod mtinst;
9292pub mod mtval;
93+ pub mod mtval2;
9394
9495// Machine Protection and Translation
9596mod pmpcfgx;
Original file line number Diff line number Diff line change 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+ }
24+
25+ #[ cfg( test) ]
26+ mod tests {
27+ use super :: * ;
28+
29+ #[ test]
30+ fn test_mtval2 ( ) {
31+ ( 1 ..=usize:: BITS )
32+ . map ( |r| ( ( 1u128 << r) - 1 ) as usize )
33+ . for_each ( |bits| {
34+ let mtval2 = Mtval2 :: from_bits ( bits) ;
35+ assert_eq ! ( mtval2. bits( ) , bits) ;
36+ assert_eq ! (
37+ mtval2. guest_fault_address( ) ,
38+ bits << Mtval2 :: GUEST_PAGE_SHIFT
39+ ) ;
40+ } ) ;
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments