Parcourir la source

update sie and spp (#4)

LoGin il y a 1 an
Parent
commit
b25fb62d28
1 fichiers modifiés avec 20 ajouts et 1 suppressions
  1. 20 1
      riscv/src/register/sstatus.rs

+ 20 - 1
riscv/src/register/sstatus.rs

@@ -23,6 +23,16 @@ impl Sstatus {
         self.bits & (1 << 1) != 0
         self.bits & (1 << 1) != 0
     }
     }
 
 
+    /// update the Supervisor Interrupt Enable field
+    #[inline]
+    pub fn update_sie(&mut self, value: bool) {
+        if value {
+            self.bits |= 1 << 1;
+        } else {
+            self.bits &= !(1 << 1);
+        }
+    }
+
     /// Supervisor Previous Interrupt Enable
     /// Supervisor Previous Interrupt Enable
     #[inline]
     #[inline]
     pub fn spie(&self) -> bool {
     pub fn spie(&self) -> bool {
@@ -38,6 +48,15 @@ impl Sstatus {
         }
         }
     }
     }
 
 
+    /// update the Supervisor Previous Privilege Mode field
+    #[inline]
+    pub fn update_spp(&mut self, spp: SPP) {
+        match spp {
+            SPP::Supervisor => self.bits |= 1 << 8,
+            SPP::User => self.bits &= !(1 << 8),
+        }
+    }
+
     /// The status of the floating-point unit
     /// The status of the floating-point unit
     #[inline]
     #[inline]
     pub fn fs(&self) -> FS {
     pub fn fs(&self) -> FS {
@@ -52,7 +71,7 @@ impl Sstatus {
     }
     }
 
 
     /// Update the status of the floating-point unit
     /// Update the status of the floating-point unit
-    /// 
+    ///
     /// Note: This function only updates the FS field.
     /// Note: This function only updates the FS field.
     #[inline]
     #[inline]
     pub fn update_fs(&mut self, fs: FS) {
     pub fn update_fs(&mut self, fs: FS) {