浏览代码

Reset handler for qemu

luojia65 4 年之前
父节点
当前提交
251a22d501
共有 2 个文件被更改,包括 20 次插入0 次删除
  1. 17 0
      platform/qemu/src/hal.rs
  2. 3 0
      platform/qemu/src/main.rs

+ 17 - 0
platform/qemu/src/hal.rs

@@ -5,3 +5,20 @@ pub use ns16550a::Ns16550a;
 
 mod clint;
 pub use clint::Clint;
+
+// Ref: https://github.com/repnop/vanadinite/blob/651163fd435d97dc9de728279b64176cdd46ec28/src/arch/virt/mod.rs#L45-L71
+
+pub struct Reset;
+
+impl rustsbi::Reset for Reset {
+    fn reset(&self) -> ! {
+        const VIRT_TEST: *mut u64 = 0x10_0000 as *mut u64;
+        // Fail = 0x3333,
+        // Pass = 0x5555,
+        // Reset = 0x7777,
+        unsafe {
+            core::ptr::write_volatile(VIRT_TEST, 0x5555);
+        }
+        unreachable!()
+    }
+}

+ 3 - 0
platform/qemu/src/main.rs

@@ -121,6 +121,9 @@ fn main() -> ! {
         use rustsbi::init_timer;
         init_timer(clint);
 
+        use rustsbi::init_reset;
+        init_reset(hal::Reset);
+
         println!("[rustsbi] Version 0.1.0");
 
         println!("{}", rustsbi::LOGO);