From 182c595a20eb9bef51eb1bc45140a6fccf8cd103 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Wed, 31 Oct 2018 11:45:25 +0800 Subject: [PATCH] Enable multi-core on RV32. --- kernel/src/arch/riscv32/boot/trap.asm | 5 +++-- kernel/src/arch/riscv32/interrupt.rs | 3 +-- kernel/src/arch/riscv32/mod.rs | 6 ++++-- kernel/src/arch/x86_64/interrupt/handler.rs | 1 - kernel/src/arch/x86_64/mod.rs | 3 +++ kernel/src/lib.rs | 5 ----- kernel/src/trap.rs | 3 --- 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/kernel/src/arch/riscv32/boot/trap.asm b/kernel/src/arch/riscv32/boot/trap.asm index d400826..37afaf1 100644 --- a/kernel/src/arch/riscv32/boot/trap.asm +++ b/kernel/src/arch/riscv32/boot/trap.asm @@ -13,7 +13,8 @@ _save_context: # save x registers except x2 (sp) sw x1, 1*4(sp) sw x3, 3*4(sp) - sw x4, 4*4(sp) + # tp(x4) = hartid. DON'T change. + # sw x4, 4*4(sp) sw x5, 5*4(sp) sw x6, 6*4(sp) sw x7, 7*4(sp) @@ -73,7 +74,7 @@ _restore_context: # restore x registers except x2 (sp) lw x1, 1*4(sp) lw x3, 3*4(sp) - lw x4, 4*4(sp) + # lw x4, 4*4(sp) lw x5, 5*4(sp) lw x6, 6*4(sp) lw x7, 7*4(sp) diff --git a/kernel/src/arch/riscv32/interrupt.rs b/kernel/src/arch/riscv32/interrupt.rs index cee4bc1..bad1812 100644 --- a/kernel/src/arch/riscv32/interrupt.rs +++ b/kernel/src/arch/riscv32/interrupt.rs @@ -42,7 +42,7 @@ pub unsafe fn restore(flags: usize) { #[no_mangle] pub extern fn rust_trap(tf: &mut TrapFrame) { use super::riscv::register::scause::{Trap, Interrupt as I, Exception as E}; - trace!("Interrupt: {:?}", tf.scause.cause()); + trace!("Interrupt @ CPU{}: {:?} ", super::cpu::id(), tf.scause.cause()); match tf.scause.cause() { Trap::Interrupt(I::SupervisorSoft) => ipi(), Trap::Interrupt(I::SupervisorTimer) => timer(), @@ -50,7 +50,6 @@ pub extern fn rust_trap(tf: &mut TrapFrame) { Trap::Exception(E::UserEnvCall) => syscall(tf), _ => ::trap::error(tf), } - ::trap::before_return(); trace!("Interrupt end"); } diff --git a/kernel/src/arch/riscv32/mod.rs b/kernel/src/arch/riscv32/mod.rs index c6ccc1c..de43a25 100644 --- a/kernel/src/arch/riscv32/mod.rs +++ b/kernel/src/arch/riscv32/mod.rs @@ -26,6 +26,9 @@ pub extern fn rust_main(hartid: usize, dtb: usize, hart_mask: usize) -> ! { memory::init(); timer::init(); + ::process::init(); + ::thread::spawn(::fs::shell); + unsafe { cpu::start_others(hart_mask); } ::kmain(); } @@ -33,8 +36,7 @@ pub extern fn rust_main(hartid: usize, dtb: usize, hart_mask: usize) -> ! { fn others_main() -> ! { interrupt::init(); timer::init(); - cpu::send_ipi(0); - loop { } + ::kmain(); } #[cfg(feature = "no_bbl")] diff --git a/kernel/src/arch/x86_64/interrupt/handler.rs b/kernel/src/arch/x86_64/interrupt/handler.rs index a0369a4..2b8b188 100644 --- a/kernel/src/arch/x86_64/interrupt/handler.rs +++ b/kernel/src/arch/x86_64/interrupt/handler.rs @@ -97,7 +97,6 @@ pub extern fn rust_trap(tf: &mut TrapFrame) { T_DIVIDE | T_GPFLT | T_ILLOP => error(tf), _ => panic!("Unhandled interrupt {:x}", tf.trap_num), } - ::trap::before_return(); } fn breakpoint() { diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index b9a57f8..b739925 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -47,6 +47,9 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! { driver::init(); + ::process::init(); + ::thread::spawn(::fs::shell); + AP_CAN_INIT.store(true, Ordering::Relaxed); ::kmain(); diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index b8614ec..1e5d83c 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -62,11 +62,6 @@ pub mod arch; pub mod arch; pub fn kmain() -> ! { - if arch::cpu::id() == 0 { - process::init(); - thread::spawn(fs::shell); - } - process::processor().run(); // thread::test::local_key(); diff --git a/kernel/src/trap.rs b/kernel/src/trap.rs index 749a0b2..529fd20 100644 --- a/kernel/src/trap.rs +++ b/kernel/src/trap.rs @@ -11,9 +11,6 @@ pub fn timer() { } } -pub fn before_return() { -} - pub fn error(tf: &TrapFrame) -> ! { error!("{:#x?}", tf); let pid = processor().pid();