2
2
3
3
pub use crate :: interrupt:: Trap ;
4
4
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 ,
9
9
}
10
10
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 ] ,
16
16
}
17
17
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
+ }
24
24
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
+ }
30
38
39
+ impl Mcause {
31
40
/// Returns the trap cause represented by this register.
32
41
///
33
42
/// # Note
@@ -43,17 +52,9 @@ impl Mcause {
43
52
}
44
53
}
45
54
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
-
52
55
/// Is trap cause an exception.
53
56
#[ inline]
54
57
pub fn is_exception ( & self ) -> bool {
55
58
!self . is_interrupt ( )
56
59
}
57
60
}
58
-
59
- read_csr_as ! ( Mcause , 0x342 ) ;
0 commit comments