diff --git a/kernel/src/arch/x86_64/CPU.cpp b/kernel/src/arch/x86_64/CPU.cpp index 5a725e88..f343c4af 100644 --- a/kernel/src/arch/x86_64/CPU.cpp +++ b/kernel/src/arch/x86_64/CPU.cpp @@ -28,6 +28,8 @@ extern void setup_idt(); [[noreturn]] void handle_page_fault(Registers* regs) { + CPU::disable_interrupts(); + u64 cr2; asm volatile("mov %%cr2, %0" : "=r"(cr2)); kerrorln("Page fault at RIP %lx while accessing %lx!", regs->rip, cr2); @@ -37,6 +39,17 @@ extern void setup_idt(); CPU::efficient_halt(); } +[[noreturn]] void handle_general_protection_fault(Registers* regs) +{ + CPU::disable_interrupts(); + + kerrorln("General protection fault at RIP %lx, error code %lx!", regs->rip, regs->error); + + CPU::print_stack_trace_at(regs); + + CPU::efficient_halt(); +} + extern "C" void handle_x86_exception(Registers* regs) { switch (regs->isr) @@ -52,7 +65,7 @@ extern "C" void handle_x86_exception(Registers* regs) case 10: FIXME_UNHANDLED_INTERRUPT("Invalid TSS"); case 11: FIXME_UNHANDLED_INTERRUPT("Segment not present"); case 12: FIXME_UNHANDLED_INTERRUPT("Stack-segment fault"); - case 13: FIXME_UNHANDLED_INTERRUPT("General protection fault"); + case 13: handle_general_protection_fault(regs); case 14: handle_page_fault(regs); case 16: FIXME_UNHANDLED_INTERRUPT("x87 floating-point exception"); case 17: FIXME_UNHANDLED_INTERRUPT("Alignment check");