1 use system_error::SystemError; 2 3 use crate::{ 4 driver::irqchip::riscv_intc::riscv_intc_init, 5 exception::{InterruptArch, IrqFlags, IrqFlagsGuard, IrqNumber}, 6 }; 7 8 pub mod ipi; 9 10 pub struct RiscV64InterruptArch; 11 12 impl InterruptArch for RiscV64InterruptArch { 13 unsafe fn arch_irq_init() -> Result<(), SystemError> { 14 riscv_intc_init()?; 15 16 Ok(()) 17 } 18 unsafe fn interrupt_enable() { 19 riscv::interrupt::enable(); 20 } 21 22 unsafe fn interrupt_disable() { 23 riscv::interrupt::disable(); 24 } 25 26 fn is_irq_enabled() -> bool { 27 riscv::register::sstatus::read().sie() 28 } 29 30 unsafe fn save_and_disable_irq() -> IrqFlagsGuard { 31 let sie = riscv::register::sstatus::read().sie(); 32 IrqFlagsGuard::new(IrqFlags::new(sie.into())) 33 } 34 35 unsafe fn restore_irq(flags: IrqFlags) { 36 let sie: bool = flags.flags() != 0; 37 if sie { 38 riscv::register::sstatus::set_sie(); 39 } else { 40 riscv::register::sstatus::clear_sie(); 41 } 42 } 43 44 fn probe_total_irq_num() -> u32 { 45 // todo: 获取中断总数 46 256 47 } 48 49 fn ack_bad_irq(irq: IrqNumber) { 50 todo!("ack_bad_irq: {}", irq.data()); 51 } 52 } 53 54 /// 中断栈帧结构体 55 #[repr(C)] 56 #[derive(Debug, Copy, Clone)] 57 pub struct TrapFrame { 58 // todo 59 } 60 61 impl TrapFrame { 62 /// 判断当前中断是否来自用户模式 63 pub fn from_user(&self) -> bool { 64 unimplemented!("TrapFrame::from_user") 65 } 66 } 67