22
33pub use crate :: interrupt:: Trap ;
44
5- /// mcause register
6- # [ derive ( Clone , Copy , Debug ) ]
7- pub struct Mcause {
8- bits : usize ,
5+ read_only_csr ! {
6+ /// `mcause` register
7+ Mcause : 0x342 ,
8+ mask : 0xffff_ffff ,
99}
1010
11- impl From < usize > for Mcause {
12- # [ inline ]
13- fn from ( bits : usize ) -> Self {
14- Self { bits }
15- }
11+ # [ cfg ( target_arch = "riscv32" ) ]
12+ read_only_csr_field ! {
13+ Mcause ,
14+ /// Returns the `code` field.
15+ code : [ 0 : 30 ] ,
1616}
1717
18- impl Mcause {
19- /// Returns the contents of the register as raw bits
20- # [ inline ]
21- pub fn bits ( & self ) -> usize {
22- self . bits
23- }
18+ # [ cfg ( not ( target_arch = "riscv32" ) ) ]
19+ read_only_csr_field ! {
20+ Mcause ,
21+ /// Returns the `code` field.
22+ code : [ 0 : 62 ] ,
23+ }
2424
25- /// Returns the code field
26- #[ inline]
27- pub fn code ( & self ) -> usize {
28- self . bits & !( 1 << ( usize:: BITS as usize - 1 ) )
29- }
25+ #[ cfg( target_arch = "riscv32" ) ]
26+ read_only_csr_field ! {
27+ Mcause ,
28+ /// Is the trap cause an interrupt.
29+ is_interrupt: 31 ,
30+ }
31+
32+ #[ cfg( not( target_arch = "riscv32" ) ) ]
33+ read_only_csr_field ! {
34+ Mcause ,
35+ /// Is the trap cause an interrupt.
36+ is_interrupt: 63 ,
37+ }
3038
39+ impl Mcause {
3140 /// Returns the trap cause represented by this register.
3241 ///
3342 /// # Note
@@ -43,17 +52,9 @@ impl Mcause {
4352 }
4453 }
4554
46- /// Is trap cause an interrupt.
47- #[ inline]
48- pub fn is_interrupt ( & self ) -> bool {
49- self . bits & ( 1 << ( usize:: BITS as usize - 1 ) ) != 0
50- }
51-
5255 /// Is trap cause an exception.
5356 #[ inline]
5457 pub fn is_exception ( & self ) -> bool {
5558 !self . is_interrupt ( )
5659 }
5760}
58-
59- read_csr_as ! ( Mcause , 0x342 ) ;
0 commit comments