From 649ff9636fe7289749c91141bbf32b2dcbe6dde4 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 19 May 2024 13:27:11 -0400 Subject: add serial logging for exceptions, fix virtualbox issue --- kernel/source/interrupts.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'kernel/source/interrupts.cpp') diff --git a/kernel/source/interrupts.cpp b/kernel/source/interrupts.cpp index f8e613e..4046021 100644 --- a/kernel/source/interrupts.cpp +++ b/kernel/source/interrupts.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -36,13 +37,47 @@ struct [[gnu::packed]] exception_info_t { extern exception_info_t exception_info; +static inline void print_reg(const char *regname, uint64_t value) { + serial_putstr(" "); + serial_putstr(regname); + serial_putstr(" = 0x"); + serial_puthex<16>(value); + serial_putchar('\n'); +} + extern "C" [[noreturn]] void print_exception() { //so exception_info's type is known by gdb exception_info_t the_exception_info = exception_info; (void)the_exception_info; - //TODO: log exception, and recover if possible. + serial_putstr("exception 0x"); + serial_puthex<2>(exception_info.exception_number); + serial_putchar('\n'); + + if (exception_info.has_error) + print_reg("error code", exception_info.error); + + print_reg("rflags", exception_info.rflags); + print_reg("rip", exception_info.rip); + print_reg("cr2", exception_info.cr2); + print_reg("cr3", exception_info.cr3); + print_reg("rax", exception_info.rax); + print_reg("rbx", exception_info.rbx); + print_reg("rcx", exception_info.rcx); + print_reg("rdx", exception_info.rdx); + print_reg("rdi", exception_info.rdi); + print_reg("rsi", exception_info.rsi); + print_reg("rbp", exception_info.rbp); + print_reg("rsp", exception_info.rsp); + print_reg("r8 ", exception_info.r8 ); + print_reg("r9 ", exception_info.r9 ); + print_reg("r10", exception_info.r10); + print_reg("r11", exception_info.r11); + print_reg("r12", exception_info.r12); + print_reg("r13", exception_info.r13); + print_reg("r14", exception_info.r14); + print_reg("r15", exception_info.r15); panic(0xba40bb); -- cgit v1.2.3