mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-25 01:16:18 +04:00
fix serial interrupt on HiFiveU
This commit is contained in:
parent
c4df7cd3af
commit
f6352b2688
@ -318,7 +318,7 @@ ifeq ($(board), u540)
|
|||||||
.PHONY:
|
.PHONY:
|
||||||
install: $(kernel_img)
|
install: $(kernel_img)
|
||||||
@$(objcopy) -S -O binary --change-addresses -0x80000000 $< $(build_path)/bin
|
@$(objcopy) -S -O binary --change-addresses -0x80000000 $< $(build_path)/bin
|
||||||
@sudo sh ../tools/u540/mkimg.sh $(build_path)/bin $(build_path)/sd.img
|
@../tools/u540/mkimg.sh $(build_path)/bin $(build_path)/sd.img
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
|
18
kernel/src/arch/riscv32/board/u540/mod.rs
Normal file
18
kernel/src/arch/riscv32/board/u540/mod.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
use super::consts::KERNEL_OFFSET;
|
||||||
|
|
||||||
|
/// Mask all external interrupt except serial.
|
||||||
|
pub unsafe fn init_external_interrupt() {
|
||||||
|
const HART1_S_MODE_INTERRUPT_ENABLES: *mut u64 = (KERNEL_OFFSET + 0x0C00_2100) as *mut u64;
|
||||||
|
const SERIAL: u64 = 4;
|
||||||
|
HART1_S_MODE_INTERRUPT_ENABLES.write(1 << SERIAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Claim and complete external interrupt by reading and writing to
|
||||||
|
/// PLIC Interrupt Claim/Complete Register.
|
||||||
|
pub unsafe fn handle_external_interrupt() {
|
||||||
|
const HART1_S_MODE_INTERRUPT_CLAIM_COMPLETE: *mut u32 = (KERNEL_OFFSET + 0x0C20_2004) as *mut u32;
|
||||||
|
// claim
|
||||||
|
let source = HART1_S_MODE_INTERRUPT_CLAIM_COMPLETE.read();
|
||||||
|
// complete
|
||||||
|
HART1_S_MODE_INTERRUPT_CLAIM_COMPLETE.write(source);
|
||||||
|
}
|
@ -34,7 +34,8 @@ pub fn init() {
|
|||||||
xtvec::write(trap_entry as usize, xtvec::TrapMode::Direct);
|
xtvec::write(trap_entry as usize, xtvec::TrapMode::Direct);
|
||||||
// Enable IPI
|
// Enable IPI
|
||||||
sie::set_ssoft();
|
sie::set_ssoft();
|
||||||
// Enable serial interrupt
|
// Enable external interrupt
|
||||||
|
if super::cpu::id() == super::BOOT_HART_ID {
|
||||||
#[cfg(feature = "m_mode")]
|
#[cfg(feature = "m_mode")]
|
||||||
mie::set_mext();
|
mie::set_mext();
|
||||||
#[cfg(not(feature = "m_mode"))]
|
#[cfg(not(feature = "m_mode"))]
|
||||||
@ -43,6 +44,7 @@ pub fn init() {
|
|||||||
// mie.MEIE can not be set in QEMU v3.0
|
// mie.MEIE can not be set in QEMU v3.0
|
||||||
// (seems like a bug)
|
// (seems like a bug)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
info!("interrupt: init end");
|
info!("interrupt: init end");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,6 +132,9 @@ fn sbi(tf: &mut TrapFrame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn external() {
|
fn external() {
|
||||||
|
#[cfg(feature = "board_u540")]
|
||||||
|
unsafe { super::board::handle_external_interrupt(); }
|
||||||
|
|
||||||
// true means handled, false otherwise
|
// true means handled, false otherwise
|
||||||
let handlers = [try_process_serial, try_process_drivers];
|
let handlers = [try_process_serial, try_process_drivers];
|
||||||
for handler in handlers.iter() {
|
for handler in handlers.iter() {
|
||||||
|
@ -79,6 +79,10 @@ fn remap_the_kernel(dtb: usize) {
|
|||||||
ms.push(bootstack as usize, bootstacktop as usize, MemoryAttr::default(), Linear::new(offset), "stack");
|
ms.push(bootstack as usize, bootstacktop as usize, MemoryAttr::default(), Linear::new(offset), "stack");
|
||||||
ms.push(sbss as usize, ebss as usize, MemoryAttr::default(), Linear::new(offset), "bss");
|
ms.push(sbss as usize, ebss as usize, MemoryAttr::default(), Linear::new(offset), "bss");
|
||||||
ms.push(dtb, dtb + super::consts::MAX_DTB_SIZE, MemoryAttr::default().readonly(), Linear::new(offset), "dts");
|
ms.push(dtb, dtb + super::consts::MAX_DTB_SIZE, MemoryAttr::default().readonly(), Linear::new(offset), "dts");
|
||||||
|
// map PLIC for HiFiveU
|
||||||
|
let offset = -(KERNEL_OFFSET as isize);
|
||||||
|
ms.push(KERNEL_OFFSET + 0x0C00_2000, KERNEL_OFFSET + 0x0C00_2000 + PAGE_SIZE, MemoryAttr::default(), Linear::new(offset), "plic0");
|
||||||
|
ms.push(KERNEL_OFFSET + 0x0C20_2000, KERNEL_OFFSET + 0x0C20_2000 + PAGE_SIZE, MemoryAttr::default(), Linear::new(offset), "plic1");
|
||||||
unsafe { ms.activate(); }
|
unsafe { ms.activate(); }
|
||||||
unsafe { SATP = ms.token(); }
|
unsafe { SATP = ms.token(); }
|
||||||
mem::forget(ms);
|
mem::forget(ms);
|
||||||
|
@ -7,6 +7,9 @@ pub mod compiler_rt;
|
|||||||
pub mod consts;
|
pub mod consts;
|
||||||
pub mod cpu;
|
pub mod cpu;
|
||||||
pub mod syscall;
|
pub mod syscall;
|
||||||
|
#[cfg(feature = "board_u540")]
|
||||||
|
#[path = "board/u540/mod.rs"]
|
||||||
|
mod board;
|
||||||
mod sbi;
|
mod sbi;
|
||||||
|
|
||||||
use log::*;
|
use log::*;
|
||||||
@ -36,6 +39,8 @@ pub extern fn rust_main(hartid: usize, dtb: usize, hart_mask: usize, functions:
|
|||||||
// FIXME: init driver on u540
|
// FIXME: init driver on u540
|
||||||
#[cfg(not(feature = "board_u540"))]
|
#[cfg(not(feature = "board_u540"))]
|
||||||
crate::drivers::init(dtb);
|
crate::drivers::init(dtb);
|
||||||
|
#[cfg(feature = "board_u540")]
|
||||||
|
unsafe { board::init_external_interrupt(); }
|
||||||
crate::process::init();
|
crate::process::init();
|
||||||
|
|
||||||
unsafe { cpu::start_others(hart_mask); }
|
unsafe { cpu::start_others(hart_mask); }
|
||||||
|
2
riscv-pk
2
riscv-pk
@ -1 +1 @@
|
|||||||
Subproject commit 2829915ea12fba2e5fd4db2879e23311043a55b4
|
Subproject commit 405ea59dd7dd2762c5883822f21d9995bea32b0c
|
0
tools/u540/mkimg.sh
Normal file → Executable file
0
tools/u540/mkimg.sh
Normal file → Executable file
Loading…
Reference in New Issue
Block a user