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/).
15
15
- Add ` scontext ` CSR
16
16
- Add ` mconfigptr ` CSR
17
17
- Bump MSRV to 1.67.0 for ` log ` to ` ilog ` name change
18
+ - Add ` mtval2 ` CSR
18
19
19
20
### Changed
20
21
Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ pub mod mip;
90
90
pub mod mscratch;
91
91
pub mod mtinst;
92
92
pub mod mtval;
93
+ pub mod mtval2;
93
94
94
95
// Machine Protection and Translation
95
96
mod 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