diff --git a/ostd/src/arch/x86/cpu.rs b/ostd/src/arch/x86/cpu.rs index 5fbd56748..7692d472b 100644 --- a/ostd/src/arch/x86/cpu.rs +++ b/ostd/src/arch/x86/cpu.rs @@ -324,7 +324,7 @@ impl UserContextApiInternal for UserContext { } } }; - call_irq_callback_functions(&self.as_trap_frame()); + call_irq_callback_functions(&self.as_trap_frame(), self.as_trap_frame().trap_num); if has_kernel_event() { return_reason = ReturnReason::KernelEvent; break; diff --git a/ostd/src/arch/x86/mod.rs b/ostd/src/arch/x86/mod.rs index d3759d2f0..1a2f55d4c 100644 --- a/ostd/src/arch/x86/mod.rs +++ b/ostd/src/arch/x86/mod.rs @@ -85,10 +85,12 @@ pub(crate) fn after_all_init() { kernel::pic::init(); } -pub(crate) fn interrupts_ack() { - kernel::pic::ack(); - if let Some(apic) = kernel::apic::APIC_INSTANCE.get() { - apic.lock_irq_disabled().eoi(); +pub(crate) fn interrupts_ack(irq_number: usize) { + if !cpu::CpuException::is_cpu_exception(irq_number as u16) { + kernel::pic::ack(); + if let Some(apic) = kernel::apic::APIC_INSTANCE.get() { + apic.lock_irq_disabled().eoi(); + } } } diff --git a/ostd/src/arch/x86/trap.rs b/ostd/src/arch/x86/trap.rs index 4464f73e5..dc0ce8958 100644 --- a/ostd/src/arch/x86/trap.rs +++ b/ostd/src/arch/x86/trap.rs @@ -65,7 +65,7 @@ extern "sysv64" fn trap_handler(f: &mut TrapFrame) { } } else { IS_KERNEL_INTERRUPTED.store(true, Ordering::Release); - call_irq_callback_functions(f); + call_irq_callback_functions(f, f.trap_num); IS_KERNEL_INTERRUPTED.store(false, Ordering::Release); } } diff --git a/ostd/src/trap/handler.rs b/ostd/src/trap/handler.rs index 5ff07577e..d61bd2b23 100644 --- a/ostd/src/trap/handler.rs +++ b/ostd/src/trap/handler.rs @@ -4,25 +4,23 @@ use core::sync::atomic::{AtomicBool, Ordering}; use trapframe::TrapFrame; -use crate::{arch::irq::IRQ_LIST, cpu::CpuException, cpu_local}; +use crate::{arch::irq::IRQ_LIST, cpu_local}; -pub(crate) fn call_irq_callback_functions(trap_frame: &TrapFrame) { +pub(crate) fn call_irq_callback_functions(trap_frame: &TrapFrame, irq_number: usize) { // For x86 CPUs, interrupts are not re-entrant. Local interrupts will be disabled when // an interrupt handler is called (Unless interrupts are re-enabled in an interrupt handler). // // FIXME: For arch that supports re-entrant interrupts, we may need to record nested level here. IN_INTERRUPT_CONTEXT.store(true, Ordering::Release); - let irq_line = IRQ_LIST.get().unwrap().get(trap_frame.trap_num).unwrap(); + let irq_line = IRQ_LIST.get().unwrap().get(irq_number).unwrap(); let callback_functions = irq_line.callback_list(); for callback_function in callback_functions.iter() { callback_function.call(trap_frame); } drop(callback_functions); - if !CpuException::is_cpu_exception(trap_frame.trap_num as u16) { - crate::arch::interrupts_ack(); - } + crate::arch::interrupts_ack(irq_number); IN_INTERRUPT_CONTEXT.store(false, Ordering::Release);