xref: /DragonOS/kernel/src/arch/riscv64/interrupt/mod.rs (revision f2022a8a1cc4a8e2a85e9061e036e9c491a2fa00)
1 use system_error::SystemError;
2 
3 use crate::exception::{InterruptArch, IrqFlags, IrqFlagsGuard};
4 
5 pub mod ipi;
6 
7 pub struct RiscV64InterruptArch;
8 
9 impl InterruptArch for RiscV64InterruptArch {
10     unsafe fn arch_irq_init() -> Result<(), SystemError> {
11         todo!("RiscV64InterruptArch::arch_irq_init")
12     }
13     unsafe fn interrupt_enable() {
14         riscv::interrupt::enable();
15     }
16 
17     unsafe fn interrupt_disable() {
18         riscv::interrupt::disable();
19     }
20 
21     fn is_irq_enabled() -> bool {
22         riscv::register::sstatus::read().sie()
23     }
24 
25     unsafe fn save_and_disable_irq() -> IrqFlagsGuard {
26         let sie = riscv::register::sstatus::read().sie();
27         IrqFlagsGuard::new(IrqFlags::new(sie.into()))
28     }
29 
30     unsafe fn restore_irq(flags: IrqFlags) {
31         let sie: bool = flags.flags() != 0;
32         if sie {
33             riscv::register::sstatus::set_sie();
34         } else {
35             riscv::register::sstatus::clear_sie();
36         }
37     }
38 }
39 
40 /// 中断栈帧结构体
41 #[repr(C)]
42 #[derive(Debug, Copy, Clone)]
43 pub struct TrapFrame {
44     // todo
45 }
46 
47 impl TrapFrame {
48     /// 判断当前中断是否来自用户模式
49     pub fn from_user(&self) -> bool {
50         unimplemented!("TrapFrame::from_user")
51     }
52 }
53