diff --git a/kernel/src/arch/riscv32/boot/trap.asm b/kernel/src/arch/riscv32/boot/trap.asm index d4008266..37afaf11 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 cee4bc17..bad1812e 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 c6ccc1c9..de43a259 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 a0369a46..2b8b1889 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 b9a57f89..b739925d 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 b8614ecb..1e5d83cd 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 749a0b26..529fd203 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();