@@ -41,6 +41,15 @@ pub enum FS {
4141 Dirty = 3 ,
4242}
4343
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+
4453/// Machine Previous Privilege Mode
4554#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
4655pub enum MPP {
@@ -216,6 +225,19 @@ impl Mstatus {
216225 }
217226 }
218227
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+
219241 /// Update Floating-point extension state
220242 ///
221243 /// Note this updates a previously read [`Mstatus`] value, but does not
@@ -226,6 +248,16 @@ impl Mstatus {
226248 self . bits = bf_insert ( self . bits , 13 , 2 , fs as usize ) ;
227249 }
228250
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+
229261 /// Additional extension state
230262 ///
231263 /// Encodes the status of additional user-mode extensions and associated
@@ -559,6 +591,15 @@ pub unsafe fn set_fs(fs: FS) {
559591 _write ( value) ;
560592}
561593
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+
562603/// Set S-mode non-instruction-fetch memory endianness
563604///
564605/// # Note
0 commit comments