fix bugs on K210

master
WangRunji 6 years ago
parent b3a8e95d78
commit daee1e9f94

@ -33,4 +33,6 @@ boot:
sw t0, 0(x1)
csrr a0, mhartid
// FIXME: enable core 1
li a2, 0 // hart_mask
j _start

@ -10,7 +10,10 @@ pub unsafe fn set_cpu_id(cpu_id: usize) {
pub fn id() -> usize {
let cpu_id;
#[cfg(not(feature = "m_mode"))]
unsafe { asm!("mv $0, tp" : "=r"(cpu_id)); }
#[cfg(feature = "m_mode")]
unsafe { asm!("csrr $0, mhartid" : "=r"(cpu_id)); }
cpu_id
}
@ -31,6 +34,5 @@ pub unsafe fn start_others(hart_mask: usize) {
}
pub fn halt() {
use riscv::asm::wfi;
unsafe { wfi() }
unsafe { riscv::asm::wfi() }
}

@ -10,7 +10,7 @@ use riscv::register::{
sscratch as xscratch,
stvec as xtvec,
};
use riscv::register::{mcause, mepc, sie};
use riscv::register::{mcause, mepc, sie, mie};
pub use self::context::*;
use crate::memory::{MemorySet, InactivePageTable0};
use log::*;
@ -35,6 +35,9 @@ pub fn init() {
// Enable IPI
sie::set_ssoft();
// Enable serial interrupt
#[cfg(feature = "m_mode")]
mie::set_mext();
#[cfg(not(feature = "m_mode"))]
sie::set_sext();
// NOTE: In M-mode: mie.MSIE is set by BBL.
// mie.MEIE can not be set in QEMU v3.0

@ -15,6 +15,8 @@ pub extern fn rust_main(hartid: usize, dtb: usize, hart_mask: usize, functions:
unsafe { cpu::set_cpu_id(hartid); }
if hartid != 0 {
#[cfg(feature = "board_k210")]
loop {} // K210: if not, an assert will fail in spin::RwLock ???
while unsafe { !cpu::has_started(hartid) } { }
println!("Hello RISCV! in hart {}, dtb @ {:#x}, functions @ {:#x}", hartid, dtb, functions);
others_main();
@ -28,16 +30,11 @@ pub extern fn rust_main(hartid: usize, dtb: usize, hart_mask: usize, functions:
crate::logging::init();
interrupt::init();
info!("interrupt::init end");
memory::init();
info!("memory::init end");
timer::init();
info!("timer::init end");
crate::process::init();
info!("crate::process::init end");
unsafe { cpu::start_others(hart_mask); }
info!("going to crate::kmain");
crate::kmain();
}

Loading…
Cancel
Save