Skip to main content

kernel/arch/x86_64/interrupts/exceptions/
invalid_fault_handler.rs

1// SPDX-License-Identifier: GPL-3.0-only
2//! Generic handler for interrupt vectors that cannot legally fire in 64-bit long mode.
3//!
4//! Authors: MarioS271
5
6use core::fmt::Write;
7use x86_64::structures::idt::InterruptStackFrame;
8use crate::types::fmt_buffer::FmtBuffer;
9use crate::panic::kernel_panic;
10use crate::types::panic_codes::PanicCode;
11
12/// Panic identifying the impossible vector (`VEC`) that fired, with the interrupt stack frame.
13pub extern "x86-interrupt" fn handler<const VEC: usize>(
14    isf: InterruptStackFrame
15) {
16    let mut fmt_buffer = FmtBuffer::<512>::new();
17    let _ = write!(
18        &mut fmt_buffer,
19        "WARNING: Vector #{VEC} fired which should be\nimpossible (reserved exception?), this suggests possible IDT corruption or similar\n\n{:#?}\n",
20        isf
21    );
22    kernel_panic(
23        PanicCode::IllegalInterrupt,
24        fmt_buffer.as_str(),
25    );
26}