From 378f7ef23dec61748c60e32da26c012e42dc4f69 Mon Sep 17 00:00:00 2001 From: Nathan Singer Date: Fri, 6 Jun 2025 12:58:54 -0400 Subject: [PATCH] adds some more exception stuff --- kernel/arch/idt/idt.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/arch/idt/idt.c b/kernel/arch/idt/idt.c index eb185fb..52cecff 100644 --- a/kernel/arch/idt/idt.c +++ b/kernel/arch/idt/idt.c @@ -108,6 +108,16 @@ static void examine_page_fault(uint32_t error_code) #undef PF_SS #undef PF_SGX +static void dump_cpu_state(struct cpu_state cpu, struct stack_state stack) +{ + kinfo("DUMPING CPU STATE"); + printf("eax: %2\nebx: %2\necx: %2\nedx: %2\nesi: %2\nedi: %22\nebp: %2\n", + cpu.eax, cpu.ebx, cpu.ecx, cpu.edx, cpu.esi, cpu.edi, cpu.ebp); + kinfo("DUMPING STACK STATE FOR INTERRUPT"); + printf("eip: %2\ncs: %2\neflags: %2\n", + stack.eip, stack.cs, stack.eflags); +} + #define EXCEPTION_LOCATION() printf("Exception occurred at 0x%2\n", stack.eip) void exception_handler(struct cpu_state __attribute__((unused)) cpu, uint32_t interrupt, struct stack_state stack) @@ -229,6 +239,9 @@ void exception_handler(struct cpu_state __attribute__((unused)) cpu, uint32_t in default: kerror("EXCEPTION: UNHANDLED EXCEPTION OR INTERRUPT"); printf("Error code: 0x%2\n", stack.error_code); + dump_cpu_state(cpu, stack); + + // TODO i would love to track spurious interrupts as well, would be useful to dump their state and specify that its spurious (if possible) break; } }