Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x64: Dump some important registers on an unsupported exception #138

Merged
merged 1 commit into from
Dec 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 39 additions & 20 deletions runtime/x64/interrupt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{address::UserVAddr, handler};

use core::fmt;

use super::{apic::ack_interrupt, ioapic::VECTOR_IRQ_BASE, serial::SERIAL0_IRQ, PageFaultReason};
use x86::{
controlregs::cr2,
Expand All @@ -8,7 +10,7 @@ use x86::{
};

/// The interrupt stack frame.
#[derive(Debug, Copy, Clone)]
#[derive(Copy, Clone)]
#[repr(C, packed)]
struct InterruptFrame {
rax: u64,
Expand All @@ -34,6 +36,17 @@ struct InterruptFrame {
ss: u64,
}

impl fmt::Debug for InterruptFrame {
#[allow(unaligned_references)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"RIP={:x}, RSP={:x}, CS={:x}, ERR={:x}",
self.rip, self.rsp, self.cs, self.error
)
}
}

extern "C" {
fn usercopy1();
fn usercopy2();
Expand Down Expand Up @@ -82,59 +95,65 @@ unsafe extern "C" fn x64_handle_interrupt(vec: u8, frame: *const InterruptFrame)
}
DIVIDE_ERROR_VECTOR => {
// TODO:
todo!("unsupported exception: DIVIDE_ERROR");
panic!("unsupported exception: DIVIDE_ERROR\n{:?}", frame);
}
DEBUG_VECTOR => {
// TODO:
todo!("unsupported exception: DEBUG");
panic!("unsupported exception: DEBUG\n{:?}", frame);
}
NONMASKABLE_INTERRUPT_VECTOR => {
// TODO:
todo!("unsupported exception: NONMASKABLE_INTERRUPT");
panic!("unsupported exception: NONMASKABLE_INTERRUPT\n{:?}", frame);
}
BREAKPOINT_VECTOR => {
// TODO:
todo!("unsupported exception: BREAKPOINT");
panic!("unsupported exception: BREAKPOINT\n{:?}", frame);
}
OVERFLOW_VECTOR => {
// TODO:
todo!("unsupported exception: OVERFLOW");
panic!("unsupported exception: OVERFLOW\n{:?}", frame);
}
BOUND_RANGE_EXCEEDED_VECTOR => {
// TODO:
todo!("unsupported exception: BOUND_RANGE_EXCEEDED");
panic!("unsupported exception: BOUND_RANGE_EXCEEDED\n{:?}", frame);
}
INVALID_OPCODE_VECTOR => {
// TODO:
todo!("unsupported exception: INVALID_OPCODE");
panic!("unsupported exception: INVALID_OPCODE\n{:?}", frame);
}
DEVICE_NOT_AVAILABLE_VECTOR => {
// TODO:
todo!("unsupported exception: DEVICE_NOT_AVAILABLE");
panic!("unsupported exception: DEVICE_NOT_AVAILABLE\n{:?}", frame);
}
DOUBLE_FAULT_VECTOR => {
// TODO:
todo!("unsupported exception: DOUBLE_FAULT");
panic!("unsupported exception: DOUBLE_FAULT\n{:?}", frame);
}
COPROCESSOR_SEGMENT_OVERRUN_VECTOR => {
// TODO:
todo!("unsupported exception: COPROCESSOR_SEGMENT_OVERRUN");
panic!(
"unsupported exception: COPROCESSOR_SEGMENT_OVERRUN\n{:?}",
frame
);
}
INVALID_TSS_VECTOR => {
// TODO:
todo!("unsupported exception: INVALID_TSS");
panic!("unsupported exception: INVALID_TSS\n{:?}", frame);
}
SEGMENT_NOT_PRESENT_VECTOR => {
// TODO:
todo!("unsupported exception: SEGMENT_NOT_PRESENT");
panic!("unsupported exception: SEGMENT_NOT_PRESENT\n{:?}", frame);
}
STACK_SEGEMENT_FAULT_VECTOR => {
// TODO:
todo!("unsupported exception: STACK_SEGEMENT_FAULT");
panic!("unsupported exception: STACK_SEGEMENT_FAULT\n{:?}", frame);
}
GENERAL_PROTECTION_FAULT_VECTOR => {
// TODO:
todo!("unsupported exception: GENERAL_PROTECTION_FAULT");
panic!(
"unsupported exception: GENERAL_PROTECTION_FAULT\n{:?}",
frame
);
}
PAGE_FAULT_VECTOR => {
let reason = PageFaultReason::from_bits_truncate(frame.error as u32);
Expand All @@ -159,23 +178,23 @@ unsafe extern "C" fn x64_handle_interrupt(vec: u8, frame: *const InterruptFrame)
}
X87_FPU_VECTOR => {
// TODO:
todo!("unsupported exception: X87_FPU");
panic!("unsupported exception: X87_FPU\n{:?}", frame);
}
ALIGNMENT_CHECK_VECTOR => {
// TODO:
todo!("unsupported exception: ALIGNMENT_CHECK");
panic!("unsupported exception: ALIGNMENT_CHECK\n{:?}", frame);
}
MACHINE_CHECK_VECTOR => {
// TODO:
todo!("unsupported exception: MACHINE_CHECK");
panic!("unsupported exception: MACHINE_CHECK\n{:?}", frame);
}
SIMD_FLOATING_POINT_VECTOR => {
// TODO:
todo!("unsupported exception: SIMD_FLOATING_POINT");
panic!("unsupported exception: SIMD_FLOATING_POINT\n{:?}", frame);
}
VIRTUALIZATION_VECTOR => {
// TODO:
todo!("unsupported exception: VIRTUALIZATION");
panic!("unsupported exception: VIRTUALIZATION\n{:?}", frame);
}
_ => {
panic!("unexpected interrupt: vec={}", vec);
Expand Down