1
1
//! mstatus register
2
- // TODO: Virtualization, Memory Privilege and Extension Context Fields
2
+ // FIXME: in 1.12 spec there will be `SBE` and `MBE` bits.
3
+ // They allows to execute supervisor in given big endian,
4
+ // they would be in a new register `mstatush` in RV32; we should implement `mstatush`
5
+ // at that time.
6
+ // FIXME: `SXL` and `UXL` bits require a structure interpreting XLEN,
7
+ // which would be the best way we implement this using Rust?
3
8
4
9
use bit_field:: BitField ;
5
10
use core:: mem:: size_of;
@@ -136,6 +141,59 @@ impl Mstatus {
136
141
}
137
142
}
138
143
144
+ /// Permit Supervisor User Memory access
145
+ #[ inline]
146
+ pub fn sum ( & self ) -> bool {
147
+ self . bits . get_bit ( 18 )
148
+ }
149
+
150
+ /// Make eXecutable Readable
151
+ #[ inline]
152
+ pub fn mxr ( & self ) -> bool {
153
+ self . bits . get_bit ( 19 )
154
+ }
155
+
156
+ /// Trap Virtual Memory
157
+ ///
158
+ /// If this bit is set, reads or writes to `satp` CSR or execute `sfence.vma`
159
+ /// instruction when in S-mode will raise an illegal instruction exception.
160
+ ///
161
+ /// TVM is hard-wired to 0 when S-mode is not supported.
162
+ #[ inline]
163
+ pub fn tvm ( & self ) -> bool {
164
+ self . bits . get_bit ( 20 )
165
+ }
166
+
167
+ /// Timeout Wait
168
+ ///
169
+ /// Indicates that if WFI instruction should be intercepted.
170
+ ///
171
+ /// If this bit is set, when WFI is executed in S-mode, and it does not complete
172
+ /// within an implementation specific, bounded time limit, the WFI instruction will cause
173
+ /// an illegal instruction trap; or could always cause trap then the time limit is zero.
174
+ ///
175
+ /// TW is hard-wired to 0 when S-mode is not supported.
176
+ #[ inline]
177
+ pub fn tw ( & self ) -> bool {
178
+ self . bits . get_bit ( 21 )
179
+ }
180
+
181
+ /// Trap SRET
182
+ ///
183
+ /// Indicates that if SRET instruction should be trapped to raise illegal
184
+ /// instruction exception.
185
+ ///
186
+ /// If S-mode is not supported, TSR bit is hard-wired to 0.
187
+ #[ inline]
188
+ pub fn tsr ( & self ) -> bool {
189
+ self . bits . get_bit ( 22 )
190
+ }
191
+
192
+ /*
193
+ FIXME: There are MBE and SBE bits in 1.12; once Privileged Specification version 1.12
194
+ is ratified, there should be read functions of these bits as well.
195
+ */
196
+
139
197
/// Whether either the FS field or XS field
140
198
/// signals the presence of some dirty state
141
199
#[ inline]
@@ -152,26 +210,36 @@ clear!(0x300, __clear_mstatus);
152
210
set_clear_csr ! (
153
211
/// User Interrupt Enable
154
212
, set_uie, clear_uie, 1 << 0 ) ;
155
-
156
213
set_clear_csr ! (
157
214
/// Supervisor Interrupt Enable
158
215
, set_sie, clear_sie, 1 << 1 ) ;
159
-
160
216
set_clear_csr ! (
161
217
/// Machine Interrupt Enable
162
218
, set_mie, clear_mie, 1 << 3 ) ;
163
-
164
219
set_csr ! (
165
220
/// User Previous Interrupt Enable
166
221
, set_upie, 1 << 4 ) ;
167
-
168
222
set_csr ! (
169
223
/// Supervisor Previous Interrupt Enable
170
224
, set_spie, 1 << 5 ) ;
171
-
172
225
set_csr ! (
173
226
/// Machine Previous Interrupt Enable
174
227
, set_mpie, 1 << 7 ) ;
228
+ set_clear_csr ! (
229
+ /// Permit Supervisor User Memory access
230
+ , set_sum, clear_sum, 1 << 18 ) ;
231
+ set_clear_csr ! (
232
+ /// Make eXecutable Readable
233
+ , set_mxr, clear_mxr, 1 << 19 ) ;
234
+ set_clear_csr ! (
235
+ /// Trap Virtual Memory
236
+ , set_tvm, clear_tvm, 1 << 20 ) ;
237
+ set_clear_csr ! (
238
+ /// Timeout Wait
239
+ , set_tw, clear_tw, 1 << 21 ) ;
240
+ set_clear_csr ! (
241
+ /// Trap SRET
242
+ , set_tsr, clear_tsr, 1 << 22 ) ;
175
243
176
244
/// Supervisor Previous Privilege Mode
177
245
#[ inline]
0 commit comments