Skip to content

Commit

Permalink
vc: Update unhandled #VC message information
Browse files Browse the repository at this point in the history
Update to the unhandled #VC message to print the the RIP in hexadecimal
and include the CR2 register, which can be relative to the #VC taken.

Signed-off-by: Tom Lendacky <[email protected]>
  • Loading branch information
tlendacky committed Sep 19, 2023
1 parent 0de111e commit 6265c2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/cpu/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ use core::arch::asm;
/// Bit 12
pub const EFER_SVME: u64 = BIT!(12);

/// Read Cr2
pub fn read_cr2() -> u64 {
let cr2: u64;

unsafe {
asm!("mov {0}, cr2",
out(reg) cr2,
options(nostack));
}

cr2
}

/// Read MSR
pub fn rdmsr(msr: u32) -> u64 {
let lo: u32;
Expand Down
3 changes: 2 additions & 1 deletion src/cpu/vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,10 @@ fn vc_msr_protocol(request: u64) -> u64 {

pub extern "x86-interrupt" fn vc_handler(stack_frame: InterruptStackFrame, error_code: u64) {
let rip: u64 = stack_frame.instruction_pointer.as_u64();
let cr2: u64 = read_cr2();

prints!(
"Unhandled #VC exception: {:#?}\n{:#?}\nRIP={rip}\n",
"Unhandled #VC exception: {:#x}\n{:#?}\nRIP={rip:#x}, CR2={cr2:#x}\n",
error_code,
stack_frame
);
Expand Down

0 comments on commit 6265c2d

Please sign in to comment.