Ver código fonte

Merge pull request #3 from wyfcyx/master

Fix multiboot for qemu/k210
Luo Jia 4 anos atrás
pai
commit
ccf2fd297b

+ 0 - 4
platform/k210/src/main.rs

@@ -202,10 +202,6 @@ fn main() -> ! {
             pac::PLIC::unmask(mhartid::read(), Interrupt::GPIOHS0);
         }
         boot.clear_interrupt_pending_bits();
-
-        // wake other harts, especially hart1 on k210
-        k210_hal::clint::msip::set_ipi(1);
-        k210_hal::clint::msip::clear_ipi(1);
     }
     
     unsafe {

+ 6 - 6
platform/qemu/src/hal/clint.rs

@@ -32,12 +32,12 @@ impl Clint {
         }
     }
 
-    // pub fn clear_soft(&mut self, hart_id: usize) {
-    //     unsafe {
-    //         let base = self.base as *mut u8;
-    //         core::ptr::write_volatile((base as *mut u32).add(hart_id), 0);
-    //     }
-    // }
+    pub fn clear_soft(&mut self, hart_id: usize) {
+        unsafe {
+            let base = self.base as *mut u8;
+            core::ptr::write_volatile((base as *mut u32).add(hart_id), 0);
+        }
+    }
 }
 
 use rustsbi::{HartMask, Ipi, Timer};

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

@@ -41,8 +41,34 @@ fn oom(_layout: Layout) -> ! {
 }
 
 // #[export_name = "_mp_hook"]
-pub extern "C" fn _mp_hook() -> bool {
-    mhartid::read() == 0
+pub extern "C" fn mp_hook() -> bool {
+    let hartid = mhartid::read();
+    if hartid == 0 {
+        true
+    } else {
+        use riscv::asm::wfi;
+        use hal::Clint;
+        unsafe {
+            let mut clint = Clint::new(0x200_0000 as *mut u8);
+            // Clear IPI
+            clint.clear_soft(hartid);
+            // Start listening for software interrupts
+            mie::set_msoft();
+
+            loop {
+                wfi();
+                if mip::read().msoft() {
+                    break;
+                }
+            }
+
+            // Stop listening for software interrupts
+            mie::clear_msoft();
+            // Clear IPI
+            clint.clear_soft(hartid);
+        }
+        false
+    }
 }
 
 #[export_name = "_start"]
@@ -90,7 +116,7 @@ fn main() -> ! {
         dtb_pa
     };
 
-    if _mp_hook() {
+    if mp_hook() {
         // init
     }