@@ -15,60 +15,68 @@ pub enum Trap {
15
15
16
16
/// Interrupt
17
17
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
18
+ #[ repr( usize ) ]
18
19
pub enum Interrupt {
19
- UserSoft ,
20
- SupervisorSoft ,
21
- MachineSoft ,
22
- UserTimer ,
23
- SupervisorTimer ,
24
- MachineTimer ,
25
- UserExternal ,
26
- SupervisorExternal ,
27
- MachineExternal ,
20
+ SupervisorSoft = 1 ,
21
+ MachineSoft = 3 ,
22
+ SupervisorTimer = 5 ,
23
+ MachineTimer = 7 ,
24
+ SupervisorExternal = 9 ,
25
+ MachineExternal = 11 ,
28
26
Unknown ,
29
27
}
30
28
31
29
/// Exception
32
30
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
31
+ #[ repr( usize ) ]
33
32
pub enum Exception {
34
- InstructionMisaligned ,
35
- InstructionFault ,
36
- IllegalInstruction ,
37
- Breakpoint ,
38
- LoadMisaligned ,
39
- LoadFault ,
40
- StoreMisaligned ,
41
- StoreFault ,
42
- UserEnvCall ,
43
- SupervisorEnvCall ,
44
- MachineEnvCall ,
45
- InstructionPageFault ,
46
- LoadPageFault ,
47
- StorePageFault ,
33
+ InstructionMisaligned = 0 ,
34
+ InstructionFault = 1 ,
35
+ IllegalInstruction = 2 ,
36
+ Breakpoint = 3 ,
37
+ LoadMisaligned = 4 ,
38
+ LoadFault = 5 ,
39
+ StoreMisaligned = 6 ,
40
+ StoreFault = 7 ,
41
+ UserEnvCall = 8 ,
42
+ SupervisorEnvCall = 9 ,
43
+ MachineEnvCall = 11 ,
44
+ InstructionPageFault = 12 ,
45
+ LoadPageFault = 13 ,
46
+ StorePageFault = 15 ,
48
47
Unknown ,
49
48
}
50
49
51
- impl Interrupt {
50
+ impl From < usize > for Interrupt {
52
51
#[ inline]
53
- pub fn from ( nr : usize ) -> Self {
52
+ fn from ( nr : usize ) -> Self {
54
53
match nr {
55
- 0 => Interrupt :: UserSoft ,
56
54
1 => Interrupt :: SupervisorSoft ,
57
55
3 => Interrupt :: MachineSoft ,
58
- 4 => Interrupt :: UserTimer ,
59
56
5 => Interrupt :: SupervisorTimer ,
60
57
7 => Interrupt :: MachineTimer ,
61
- 8 => Interrupt :: UserExternal ,
62
58
9 => Interrupt :: SupervisorExternal ,
63
59
11 => Interrupt :: MachineExternal ,
64
60
_ => Interrupt :: Unknown ,
65
61
}
66
62
}
67
63
}
68
64
69
- impl Exception {
65
+ impl TryFrom < Interrupt > for usize {
66
+ type Error = Interrupt ;
67
+
70
68
#[ inline]
71
- pub fn from ( nr : usize ) -> Self {
69
+ fn try_from ( value : Interrupt ) -> Result < Self , Self :: Error > {
70
+ match value {
71
+ Interrupt :: Unknown => Err ( Interrupt :: Unknown ) ,
72
+ _ => Ok ( value as Self ) ,
73
+ }
74
+ }
75
+ }
76
+
77
+ impl From < usize > for Exception {
78
+ #[ inline]
79
+ fn from ( nr : usize ) -> Self {
72
80
match nr {
73
81
0 => Exception :: InstructionMisaligned ,
74
82
1 => Exception :: InstructionFault ,
@@ -88,6 +96,19 @@ impl Exception {
88
96
}
89
97
}
90
98
}
99
+
100
+ impl TryFrom < Exception > for usize {
101
+ type Error = Exception ;
102
+
103
+ #[ inline]
104
+ fn try_from ( value : Exception ) -> Result < Self , Self :: Error > {
105
+ match value {
106
+ Exception :: Unknown => Err ( Exception :: Unknown ) ,
107
+ _ => Ok ( value as Self ) ,
108
+ }
109
+ }
110
+ }
111
+
91
112
impl Mcause {
92
113
/// Returns the contents of the register as raw bits
93
114
#[ inline]
0 commit comments