From: Andrew Cooper Date: Fri, 29 Apr 2016 12:08:20 +0000 (+0100) Subject: Print more information when dumping exceptions X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=aefbd90634cb7bf9e177e5be022caafb18ddfeb6;p=people%2Froyger%2Fxen-test-framework.git Print more information when dumping exceptions Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/traps.c b/arch/x86/traps.c index 8906e47..a54f672 100644 --- a/arch/x86/traps.c +++ b/arch/x86/traps.c @@ -2,6 +2,7 @@ #include #include +#include #include bool (*xtf_unhandled_exception_hook)(struct cpu_regs *regs); @@ -78,9 +79,29 @@ void do_exception(struct cpu_regs *regs) if ( !safe && xtf_unhandled_exception_hook ) safe = xtf_unhandled_exception_hook(regs); + /* Still unresolved? Give up and panic() with some relevent information. */ if ( !safe ) - panic("Unhandled exception: vec %u at %04x:%p\n", - regs->entry_vector, regs->cs, _p(regs->ip)); + { + char buf[16]; + + x86_exc_decode_ec(buf, ARRAY_SIZE(buf), + regs->entry_vector, regs->error_code); + + if ( regs->entry_vector == X86_EXC_PF ) + { + unsigned long cr2 = read_cr2(); + + panic("Unhandled exception at %04x:%p\n" + "Vec %u %s[%s] %%cr2 %p\n", + regs->cs, _p(regs->ip), regs->entry_vector, + x86_exc_short_name(regs->entry_vector), buf, _p(cr2)); + } + else + panic("Unhandled exception at %04x:%p\n" + "Vec %u %s[%s]\n", + regs->cs, _p(regs->ip), regs->entry_vector, + x86_exc_short_name(regs->entry_vector), buf); + } } /* diff --git a/include/arch/x86/lib.h b/include/arch/x86/lib.h index 67af0dd..b1b2bf1 100644 --- a/include/arch/x86/lib.h +++ b/include/arch/x86/lib.h @@ -195,6 +195,15 @@ static inline unsigned long read_dr7(void) return val; } +static inline unsigned long read_cr2(void) +{ + unsigned long cr2; + + asm volatile ("mov %%cr2, %0" : "=r" (cr2)); + + return cr2; +} + static inline unsigned long read_cr3(void) { unsigned long cr3;