File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
27
27
- Use CSR helper macros to define ` mip ` register
28
28
- Use CSR helper macros to define ` mstatus ` register
29
29
- Use CSR helper macros to define ` mstatush ` register
30
+ - Use CSR helper macros to define ` mtvec ` register
30
31
31
32
## [ v0.12.1] - 2024-10-20
32
33
Original file line number Diff line number Diff line change @@ -63,3 +63,41 @@ impl Mtvec {
63
63
}
64
64
}
65
65
}
66
+
67
+ #[ cfg( test) ]
68
+ mod tests {
69
+ use super :: * ;
70
+
71
+ #[ test]
72
+ fn test_mtvec ( ) {
73
+ let mut m = Mtvec :: from_bits ( 0 ) ;
74
+
75
+ ( 1 ..=usize:: BITS )
76
+ . map ( |r| ( ( ( 1u128 << r) - 1 ) as usize ) & !TRAP_MASK )
77
+ . for_each ( |address| {
78
+ m. set_address ( address) ;
79
+ assert_eq ! ( m. address( ) , address) ;
80
+
81
+ assert_eq ! ( m. try_set_address( address) , Ok ( ( ) ) ) ;
82
+ assert_eq ! ( m. address( ) , address) ;
83
+ } ) ;
84
+
85
+ ( 1 ..=usize:: BITS )
86
+ . filter_map ( |r| match ( ( 1u128 << r) - 1 ) as usize {
87
+ addr if ( addr & TRAP_MASK ) != 0 => Some ( addr) ,
88
+ _ => None ,
89
+ } )
90
+ . for_each ( |address| {
91
+ assert_eq ! (
92
+ m. try_set_address( address) ,
93
+ Err ( Error :: InvalidFieldVariant {
94
+ field: "mtvec::address" ,
95
+ value: address,
96
+ } )
97
+ ) ;
98
+ } ) ;
99
+
100
+ test_csr_field ! ( m, trap_mode: TrapMode :: Direct ) ;
101
+ test_csr_field ! ( m, trap_mode: TrapMode :: Vectored ) ;
102
+ }
103
+ }
You can’t perform that action at this time.
0 commit comments