1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 08:26:17 +04:00

fix bugs on K210

This commit is contained in:
WangRunji 2018-12-27 21:33:55 +08:00
parent b3a8e95d78
commit daee1e9f94
4 changed files with 12 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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