xref: /DragonOS/kernel/src/arch/riscv64/interrupt/mod.rs (revision bc6f0a967c8cb1e9379ced184b25a7722fbda2a4)
1 use system_error::SystemError;
2 
3 use crate::exception::{InterruptArch, IrqFlags, IrqFlagsGuard, IrqNumber};
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     fn probe_total_irq_num() -> u32 {
40         // todo: 获取中断总数
41         256
42     }
43 
44     fn ack_bad_irq(irq: IrqNumber) {
45         todo!("ack_bad_irq: {}", irq.data());
46     }
47 }
48 
49 /// 中断栈帧结构体
50 #[repr(C)]
51 #[derive(Debug, Copy, Clone)]
52 pub struct TrapFrame {
53     // todo
54 }
55 
56 impl TrapFrame {
57     /// 判断当前中断是否来自用户模式
58     pub fn from_user(&self) -> bool {
59         unimplemented!("TrapFrame::from_user")
60     }
61 }
62