初始化riscv-sbi-timer (#716)

This commit is contained in:
LoGin
2024-04-12 14:46:47 +08:00
committed by GitHub
parent 3959e94df3
commit f049d1af01
13 changed files with 340 additions and 41 deletions

View File

@ -5,7 +5,10 @@ use core::hint::spin_loop;
use system_error::SystemError;
use crate::{arch::syscall::syscall_handler, kdebug, kerror};
use crate::{
arch::syscall::syscall_handler, driver::irqchip::riscv_intc::riscv_intc_irq,
exception::HardwareIrqNumber, kdebug, kerror,
};
use super::TrapFrame;
@ -40,11 +43,8 @@ unsafe extern "C" fn riscv64_do_irq(trap_frame: &mut TrapFrame) {
}
/// 处理中断
fn riscv64_do_interrupt(_trap_frame: &mut TrapFrame) {
kdebug!("todo: riscv64_do_irq: interrupt");
loop {
spin_loop();
}
fn riscv64_do_interrupt(trap_frame: &mut TrapFrame) {
riscv_intc_irq(trap_frame);
}
/// 处理异常

View File

@ -1,6 +1,8 @@
use core::hint::spin_loop;
use crate::{arch::CurrentIrqArch, exception::InterruptArch, kBUG, process::ProcessManager};
use crate::{
arch::CurrentIrqArch, exception::InterruptArch, kBUG, kdebug, process::ProcessManager,
};
impl ProcessManager {
/// 每个核的idle进程
@ -14,6 +16,8 @@ impl ProcessManager {
kBUG!("Idle process should not be scheduled with IRQs disabled.");
spin_loop();
}
kdebug!("idle loop");
}
}
}

View File

@ -18,7 +18,7 @@ use crate::{
CurrentIrqArch,
},
exception::InterruptArch,
kerror,
kdebug, kerror,
libs::spinlock::SpinLockGuard,
mm::VirtAddr,
process::{
@ -127,14 +127,22 @@ impl ProcessManager {
/// 参考: https://code.dragonos.org.cn/xref/linux-6.6.21/arch/riscv/include/asm/switch_to.h#76
pub unsafe fn switch_process(prev: Arc<ProcessControlBlock>, next: Arc<ProcessControlBlock>) {
assert!(!CurrentIrqArch::is_irq_enabled());
kdebug!(
"riscv switch process: prev: {:?}, next: {:?}",
prev.pid(),
next.pid()
);
Self::switch_process_fpu(&prev, &next);
kdebug!("riscv switch process: after switch_process_fpu");
Self::switch_local_context(&prev, &next);
kdebug!("riscv switch process: after switch_local_context");
// 切换地址空间
let next_addr_space = next.basic().user_vm().as_ref().unwrap().clone();
compiler_fence(Ordering::SeqCst);
next_addr_space.read().user_mapper.utable.make_current();
kdebug!("riscv switch process: after switch addr space");
drop(next_addr_space);
compiler_fence(Ordering::SeqCst);
@ -147,7 +155,7 @@ impl ProcessManager {
ProcessManager::current_pcb().preempt_enable();
PROCESS_SWITCH_RESULT.as_mut().unwrap().get_mut().prev_pcb = Some(prev);
PROCESS_SWITCH_RESULT.as_mut().unwrap().get_mut().next_pcb = Some(next);
// kdebug!("switch tss ok");
kdebug!("riscv switch process: before to inner");
compiler_fence(Ordering::SeqCst);
// 正式切换上下文
switch_to_inner(prev_arch, next_arch);
@ -244,7 +252,14 @@ unsafe extern "C" fn switch_to_inner(prev: *mut ArchPCBInfo, next: *mut ArchPCBI
/// 在切换上下文完成后的钩子函数(必须在这里加一个跳转函数否则会出现relocation truncated to fit: R_RISCV_JAL错误)
unsafe extern "C" fn before_switch_finish_hook() {
let pcb = ProcessManager::current_pcb();
kdebug!(
"before_switch_finish_hook, pid: {:?}, name: {:?}",
pcb.pid(),
pcb.basic().name()
);
switch_finish_hook();
kdebug!("after switch_finish_hook");
}
impl ProcessControlBlock {

View File

@ -1,4 +1,9 @@
use crate::sched::SchedArch;
use crate::{
driver::clocksource::timer_riscv::riscv_sbi_timer_init_local, exception::InterruptArch,
sched::SchedArch,
};
use super::CurrentIrqArch;
/// 发起调度
#[no_mangle]
@ -10,14 +15,13 @@ pub struct RiscV64SchedArch;
impl SchedArch for RiscV64SchedArch {
fn enable_sched_local() {
todo!()
riscv_sbi_timer_init_local();
unsafe { CurrentIrqArch::interrupt_enable() };
}
fn disable_sched_local() {
todo!()
}
fn initial_setup_sched_local() {
todo!()
}
fn initial_setup_sched_local() {}
}

View File

@ -64,3 +64,7 @@ impl TimeArch for RiscV64TimeArch {
cycles * 1000000000 / unsafe { TIME_FREQ }
}
}
pub fn riscv_time_base_freq() -> usize {
unsafe { TIME_FREQ }
}