Browse Source

lib: add new uninitialized RustSBI constructor

Those constructors would help with global static variable initialization.
Since RustSBI is internally `Option`al with all the extensions intenally
mutable (i.e. callable using &self, even if internal states could be changed),
it does not require `static` variables to be `static mut` or with any kind of locks externally.

Signed-off-by: Zhouqi Jiang <[email protected]>
Zhouqi Jiang 1 year ago
parent
commit
1d2c09f4d6
1 changed files with 36 additions and 0 deletions
  1. 36 0
      src/instance.rs

+ 36 - 0
src/instance.rs

@@ -70,6 +70,23 @@ impl<T: Timer, I: Ipi, R: Fence, H: Hsm, S: Reset, P: Pmu, C: Console, SU: Susp,
         }
     }
 
+    /// Create an uninitialized RustSBI instance on current machine environment.
+    #[cfg(feature = "machine")]
+    #[inline]
+    pub const fn new_uninit_machine() -> Self {
+        Self {
+            timer: None,
+            ipi: None,
+            rfnc: None,
+            hsm: None,
+            srst: None,
+            pmu: None,
+            dbcn: None,
+            susp: None,
+            cppc: None,
+        }
+    }
+
     /// Create RustSBI instance on given machine information for all the SBI extensions
     #[cfg(not(feature = "machine"))]
     #[allow(clippy::too_many_arguments)] // fixme: is it possible to have a better design here?
@@ -99,6 +116,25 @@ impl<T: Timer, I: Ipi, R: Fence, H: Hsm, S: Reset, P: Pmu, C: Console, SU: Susp,
             info,
         }
     }
+
+    /// Create an uninitialized RustSBI instance on current machine environment.
+    #[cfg(not(feature = "machine"))]
+    #[inline]
+    pub const fn uninit_with_machine_info(info: MachineInfo) -> Self {
+        Self {
+            timer: None,
+            ipi: None,
+            rfnc: None,
+            hsm: None,
+            srst: None,
+            pmu: None,
+            dbcn: None,
+            susp: None,
+            cppc: None,
+            info,
+        }
+    }
+
     /// Handle supervisor environment call with given parameters and return the `SbiRet` result.
     #[inline]
     pub fn handle_ecall(&mut self, extension: usize, function: usize, param: [usize; 6]) -> SbiRet {