Trying to get interrupt handling ABIs to work

This commit is contained in:
August 2025-07-07 12:44:50 -04:00
parent e124f3c2c6
commit c6ea6e46cc
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
2 changed files with 27 additions and 30 deletions

View File

@ -9,37 +9,34 @@ lazy_static! {
let idt = InterruptDescriptorTable::new();
// TODO: Re-implement this once the x86-interrupt ABI is fixed.
// Alternatively: Write our own interrupt handler wrappers.
//idt.double_fault.set_handler_fn(double_fault);
//idt.page_fault.set_handler_fn(page_fault);
idt
};
}
//extern "x86-interrupt" fn double_fault(info: InterruptStackFrame, _: u64) -> ! {
// crate::interrupt::double_fault(&format!("{info:#?}"));
//}
// For all these handlers, they will be called from a purely naked ASM
// function. That function will first push all registers to the stack.
// It is the responsibility of these functions to recover this info.
/*
#[allow(dead_code)]
extern "x86-interrupt" fn page_fault(info: InterruptStackFrame, errcode: PageFaultErrorCode) {
if errcode.contains(PageFaultErrorCode::USER_MODE) {
// Fault occurred in usermode. Non fatal.
todo!()
} else {
// Fault occurred in kernel mode. This is possibly fatal.
// This is recoverable if we simply hit an unavailable page,
// but unrecoverable if we hit a nonexistent or invalid page.
if errcode.contains(PageFaultErrorCode::PROTECTION_VIOLATION)
| errcode.contains(PageFaultErrorCode::MALFORMED_TABLE)
{
let addr = unsafe {
let a: usize;
core::arch::asm! {"mov {}, cr2", out(reg) a};
a
};
let info_formatted = format!("{info:#?}");
crate::interrupt::page_fault(addr, info_formatted.as_str().as_ptr(), info_formatted.as_str().len())
}
}
}
*/
// Recoverable exception: Occurs on division failure.
#[unsafe(no_mangle)]
pub extern "C" fn x86_divide_error() {
}
// Recoverable exception: Occurs on failure in BOUND instruction.
#[unsafe(no_mangle)]
pub extern "C" fn x86_bound_range() {
}
// Recoverable exception: Invalid opcode.
#[unsafe(no_mangle)]
pub extern "C" fn x86_invalid_opcode() {
}
// Recoverable exception: FPU not available or enabled.
#[unsafe(no_mangle)]
pub extern "C" fn x86_device_unavailable() {
}

View File

@ -13,4 +13,4 @@ extern "C" fn double_fault(info: *const u8, info_len: usize) -> ! {
pub extern "C" fn page_fault(addr: usize, info: *const u8, info_len: usize) -> ! {
let info_slice = unsafe { &str::from_raw_parts(info, info_len) };
panic!("Page fault at 0x{:X}: {}", addr, info_slice);
}
}