浏览代码

instance: improve constructor under non-machine environment

luojia65 2 年之前
父节点
当前提交
0398d956a3
共有 3 个文件被更改,包括 24 次插入10 次删除
  1. 0 10
      .vscode/settings.json
  2. 1 0
      CHANGELOG.md
  3. 23 0
      src/instance.rs

+ 0 - 10
.vscode/settings.json

@@ -1,10 +0,0 @@
-{   
-    // Prevent error "can't find crate for `test`" in no_std
-    // Ref: https://github.com/rust-lang/vscode-rust/issues/729
-    // For vscode-rust plugin user:
-    "rust.target": "riscv64imac-unknown-none-elf",
-    "rust.all_targets": false,
-    // For Rust Analyzer:
-    "rust-analyzer.cargo.target": "riscv64imac-unknown-none-elf",
-    "rust-analyzer.checkOnSave.allTargets": false
-}

+ 1 - 0
CHANGELOG.md

@@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 ### Added
 
 - Instance based and/or machine independent RustSBI to support hypervisor development
+- Structure `MachineInfo` for non-machine environment, e.g. cross-architecture emulator
 - Feature `legacy` to gate SBI legacy extension
 - Expose `init_*` functions on instance based RustSBI implementation
 - LEGACY_CLEAR_IPI implemented

+ 23 - 0
src/instance.rs

@@ -50,6 +50,29 @@ impl<T: Timer, I: Ipi, R: Fence, H: Hsm, S: Reset, P: Pmu> RustSBI<T, I, R, H, S
         }
     }
 
+    /// Create RustSBI instance on given machine information for all the SBI extensions
+    #[cfg(not(feature = "machine"))]
+    #[inline]
+    pub const fn with_machine_info(
+        timer: T,
+        ipi: I,
+        rfnc: R,
+        hsm: H,
+        srst: S,
+        pmu: P,
+        info: MachineInfo,
+    ) -> Self {
+        Self {
+            timer: Some(timer),
+            ipi: Some(ipi),
+            rfnc: Some(rfnc),
+            hsm: Some(hsm),
+            srst: Some(srst),
+            pmu: Some(pmu),
+            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 {