@@ -41,6 +41,15 @@ pub enum FS {
41
41
Dirty = 3 ,
42
42
}
43
43
44
+ /// Vector extension state
45
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
46
+ pub enum VS {
47
+ Off = 0 ,
48
+ Initial = 1 ,
49
+ Clean = 2 ,
50
+ Dirty = 3 ,
51
+ }
52
+
44
53
/// Machine Previous Privilege Mode
45
54
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
46
55
pub enum MPP {
@@ -216,6 +225,19 @@ impl Mstatus {
216
225
}
217
226
}
218
227
228
+ /// Vector extension state
229
+ #[ inline]
230
+ pub fn vs ( & self ) -> VS {
231
+ let fs = bf_extract ( self . bits , 9 , 2 ) ; // bits 9-10
232
+ match fs {
233
+ 0b00 => VS :: Off ,
234
+ 0b01 => VS :: Initial ,
235
+ 0b10 => VS :: Clean ,
236
+ 0b11 => VS :: Dirty ,
237
+ _ => unreachable ! ( ) ,
238
+ }
239
+ }
240
+
219
241
/// Update Floating-point extension state
220
242
///
221
243
/// Note this updates a previously read [`Mstatus`] value, but does not
@@ -226,6 +248,16 @@ impl Mstatus {
226
248
self . bits = bf_insert ( self . bits , 13 , 2 , fs as usize ) ;
227
249
}
228
250
251
+ /// Update vector extension state
252
+ ///
253
+ /// Note this updates a previously read [`Mstatus`] value, but does not
254
+ /// affect the mstatus CSR itself. See [`set_vs`] to directly update the
255
+ /// CSR.
256
+ #[ inline]
257
+ pub fn set_vs ( & mut self , vs : VS ) {
258
+ self . bits = bf_insert ( self . bits , 9 , 2 , vs as usize ) ;
259
+ }
260
+
229
261
/// Additional extension state
230
262
///
231
263
/// Encodes the status of additional user-mode extensions and associated
@@ -559,6 +591,15 @@ pub unsafe fn set_fs(fs: FS) {
559
591
_write ( value) ;
560
592
}
561
593
594
+ /// Vector extension state
595
+ #[ inline]
596
+ pub unsafe fn set_vs ( vs : VS ) {
597
+ let mut value = _read ( ) ;
598
+ value &= !( 0x3 << 9 ) ; // clear previous value
599
+ value |= ( vs as usize ) << 9 ;
600
+ _write ( value) ;
601
+ }
602
+
562
603
/// Set S-mode non-instruction-fetch memory endianness
563
604
///
564
605
/// # Note
0 commit comments