Skip to main content

kernel/arch/x86_64/interrupts/irqs/
irq7.rs

1// SPDX-License-Identifier: GPL-3.0-only
2//! IRQ7 handler — detects and ignores spurious PIC interrupts.
3//!
4//! Authors: MarioS271
5
6use crate::arch::x86_64::interrupts::pic;
7use x86_64::instructions::port::Port;
8use x86_64::structures::idt::InterruptStackFrame;
9
10/// Check whether IRQ7 is spurious; send EOI only if the ISR bit 7 is set (real IRQ).
11pub extern "x86-interrupt" fn handler(
12    _: InterruptStackFrame
13) {
14    // Safe because raw asm is encapsulated in the trusted x86_64 crate
15    unsafe {
16        let mut port: Port<u8> = Port::new(pic::PIC_MASTER_CMD_PORT);
17        port.write(0x0B);
18        let isr: u8 = port.read();
19        if isr & (1 << 7) == 0 {
20            return;
21        }
22    }
23
24    pic::end_of_interrupt(pic::PIC_MASTER_OFFSET + 7);
25}