diff options
| -rw-r--r-- | arch/x86_64/src/cpu/interrupts.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/arch/x86_64/src/cpu/interrupts.cpp b/arch/x86_64/src/cpu/interrupts.cpp index 1f12898..4e52d71 100644 --- a/arch/x86_64/src/cpu/interrupts.cpp +++ b/arch/x86_64/src/cpu/interrupts.cpp @@ -43,6 +43,8 @@ namespace arch::cpu security_exception, }; + constexpr auto number_of_exception_vectors = 32u; + constexpr auto pic_master_irq_start = 0x20; constexpr auto pic_master_irq_end = pic_master_irq_start + 8; constexpr auto pic_slave_irq_start = pic_master_irq_end; @@ -72,6 +74,25 @@ namespace arch::cpu } } + constexpr auto has_error_code(exception e) + { + switch (e) + { + case exception::double_fault: + case exception::invalid_tss: + case exception::segment_not_present: + case exception::stack_segment_fault: + case exception::general_protection_fault: + case exception::page_fault: + case exception::alignment_check: + case exception::control_protection_exception: + case exception::security_exception: + return true; + default: + return false; + } + } + auto dispatch_exception(interrupt_frame * frame) -> bool { auto type = to_exception_type(static_cast<exception>(frame->interrupt.number)); @@ -113,12 +134,20 @@ namespace arch::cpu { auto [number, code] = frame->interrupt; - if (number < pic_master_irq_start && !dispatch_exception(frame)) + if (number < number_of_exception_vectors && !dispatch_exception(frame)) { - kstd::println(kstd::print_sink::stderr, - "[x86_64:CPU] Unhandled exception number {:#04x} received with code {:#04x}", number, code); + if (has_error_code(static_cast<exception>(number))) + { + kstd::println(kstd::print_sink::stderr, + "[x86_64:CPU] Unhandled exception number {:#04x} received with code {:#04x}", number, code); + } + else + { + kstd::println(kstd::print_sink::stderr, "[x86_64:CPU] Unhandled exception number {:#04x} received", number); + } } - else if (number >= pic_master_irq_start && kapi::cpu::dispatch_interrupt(number) == kapi::cpu::status::unhandled) + else if (number >= number_of_exception_vectors && + kapi::cpu::dispatch_interrupt(number) == kapi::cpu::status::unhandled) { kstd::println(kstd::print_sink::stderr, "[x86_64:CPU] Unhandled interrupt {:#04x}", number); } |
