浏览代码

fix(prototyper): delayed printing of dynamic info parsing errors

guttatus 5 月之前
父节点
当前提交
6c32c6860f
共有 2 个文件被更改,包括 16 次插入5 次删除
  1. 12 0
      prototyper/src/fail.rs
  2. 4 5
      prototyper/src/main.rs

+ 12 - 0
prototyper/src/fail.rs

@@ -70,3 +70,15 @@ pub fn no_dynamic_info_available(err: dynamic::DynamicReadError) -> dynamic::Dyn
     }
     reset::fail()
 }
+
+#[cold]
+pub fn use_lottery(_err: dynamic::DynamicReadError) -> dynamic::DynamicInfo {
+    dynamic::DynamicInfo {
+        magic: 0,
+        version: 0,
+        next_addr: 0,
+        next_mode: 0,
+        options: 0,
+        boot_hart: usize::MAX,
+    }
+}

+ 4 - 5
prototyper/src/main.rs

@@ -34,7 +34,7 @@ use crate::sbi::SBI;
 #[no_mangle]
 extern "C" fn rust_main(_hart_id: usize, opaque: usize, nonstandard_a2: usize) {
     // parse dynamic information
-    let info = dynamic::read_paddr(nonstandard_a2).unwrap_or_else(fail::no_dynamic_info_available);
+    let info = dynamic::read_paddr(nonstandard_a2).unwrap_or_else(fail::use_lottery);
     static GENESIS: AtomicBool = AtomicBool::new(true);
     static SBI_READY: AtomicBool = AtomicBool::new(false);
 
@@ -45,10 +45,6 @@ extern "C" fn rust_main(_hart_id: usize, opaque: usize, nonstandard_a2: usize) {
     };
 
     if is_boot_hart {
-        let (mpp, next_addr) =
-            dynamic::mpp_next_addr(&info).unwrap_or_else(fail::invalid_dynamic_data);
-
-        // parse the device tree
 
         // 1. Init FDT
         let dtb = dt::parse_device_tree(opaque).unwrap_or_else(fail::device_tree_format);
@@ -127,6 +123,9 @@ extern "C" fn rust_main(_hart_id: usize, opaque: usize, nonstandard_a2: usize) {
         // 设置陷入栈
         trap_stack::prepare_for_trap();
 
+        let dynamic_info = dynamic::read_paddr(nonstandard_a2).unwrap_or_else(fail::no_dynamic_info_available);
+        let (mpp, next_addr) =
+            dynamic::mpp_next_addr(&dynamic_info).unwrap_or_else(fail::invalid_dynamic_data);
         // 设置内核入口
         local_remote_hsm().start(NextStage {
             start_addr: next_addr,