From: Amelia Coutard Date: Sun, 12 Jun 2022 11:00:07 +0000 (+0200) Subject: Added handlers for each one of the exceptions, instead of having generic ones, put... X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=ff9637b3cb21082b36723ca112f726611274a9eb;p=voyage-au-centre-des-fichiers.git Added handlers for each one of the exceptions, instead of having generic ones, put them in the IDT accordingly --- diff --git a/src/interrupts.S b/src/interrupts.S index 679a7f1..3ef3447 100644 --- a/src/interrupts.S +++ b/src/interrupts.S @@ -1,18 +1,36 @@ -#define PUSH_REGS pushq %rax; -#define POP_REGS popq %rax; +#define PUSH_REGS \ + pushq %rax; \ + pushq %rcx; \ + pushq %rdx; \ + pushq %rsi; \ + pushq %rdi; \ + pushq %r8; \ + pushq %r9; \ + pushq %r10; \ + pushq %r11; +#define POP_REGS \ + popq %r11; \ + popq %r10; \ + popq %r9; \ + popq %r8; \ + popq %rdi; \ + popq %rsi; \ + popq %rdx; \ + popq %rcx; \ + popq %rax; #define HANDLER_ERRCODE(n, handler) \ .globl handler_##n ;\ handler_##n: ;\ cli; \ PUSH_REGS \ - movl 8(%rsp), %edi ;\ + movl 72(%rsp), %edi ;\ call handler ;\ movq $0xB0, %rdi;\ movq $0, %rsi;\ call set_APIC_reg_asm; \ - POP_REGS \ sti; \ + POP_REGS \ addq 4, %rsp;\ iretq #define HANDLER_NOERRCODE(n, handler) \ @@ -28,35 +46,35 @@ sti; \ iretq -HANDLER_NOERRCODE(0x00, handler_impl_no_code) -HANDLER_NOERRCODE(0x01, handler_impl_no_code) -HANDLER_NOERRCODE(0x02, handler_impl_no_code) -HANDLER_NOERRCODE(0x03, handler_impl_no_code) -HANDLER_NOERRCODE(0x04, handler_impl_no_code) -HANDLER_NOERRCODE(0x05, handler_impl_no_code) -HANDLER_NOERRCODE(0x06, handler_impl_no_code) -HANDLER_NOERRCODE(0x07, handler_impl_no_code) -HANDLER_ERRCODE (0x08, handler_impl_code) -HANDLER_NOERRCODE(0x09, handler_impl_no_code) -HANDLER_ERRCODE (0x0a, handler_impl_code) -HANDLER_ERRCODE (0x0b, handler_impl_code) -HANDLER_ERRCODE (0x0c, handler_impl_code) -HANDLER_ERRCODE (0x0d, handler_impl_code) -HANDLER_ERRCODE (0x0e, handler_impl_code) -HANDLER_NOERRCODE(0x0f, handler_impl_no_code) -HANDLER_NOERRCODE(0x10, handler_impl_no_code) -HANDLER_ERRCODE (0x11, handler_impl_code) -HANDLER_NOERRCODE(0x12, handler_impl_no_code) -HANDLER_NOERRCODE(0x13, handler_impl_no_code) -HANDLER_NOERRCODE(0x14, handler_impl_no_code) -HANDLER_ERRCODE (0x15, handler_impl_code) -HANDLER_NOERRCODE(0x16, handler_impl_no_code) -HANDLER_NOERRCODE(0x17, handler_impl_no_code) -HANDLER_NOERRCODE(0x18, handler_impl_no_code) -HANDLER_NOERRCODE(0x19, handler_impl_no_code) -HANDLER_NOERRCODE(0x1a, handler_impl_no_code) -HANDLER_NOERRCODE(0x1b, handler_impl_no_code) -HANDLER_NOERRCODE(0x1c, handler_impl_no_code) -HANDLER_ERRCODE (0x1d, handler_impl_code) -HANDLER_ERRCODE (0x1e, handler_impl_code) -HANDLER_NOERRCODE(0x1f, handler_impl_no_code) +HANDLER_NOERRCODE(0x00, int_div_by_0) +HANDLER_NOERRCODE(0x01, int_debug) +HANDLER_NOERRCODE(0x02, int_NMI) +HANDLER_NOERRCODE(0x03, int_breakpoint) +HANDLER_NOERRCODE(0x04, int_overflow) +HANDLER_NOERRCODE(0x05, int_bound_range_exceeded) +HANDLER_NOERRCODE(0x06, int_invalid_opcode) +HANDLER_NOERRCODE(0x07, int_device_not_available) +HANDLER_ERRCODE (0x08, int_double_fault) +HANDLER_NOERRCODE(0x09, int_coprocessor_segment_overrun) +HANDLER_ERRCODE (0x0a, int_invalid_TSS) +HANDLER_ERRCODE (0x0b, int_segment_not_present) +HANDLER_ERRCODE (0x0c, int_stack_segment_fault) +HANDLER_ERRCODE (0x0d, int_general_protection_fault) +HANDLER_ERRCODE (0x0e, int_page_fault) +HANDLER_NOERRCODE(0x0f, int_default) +HANDLER_NOERRCODE(0x10, int_x87_floating_point_exception) +HANDLER_ERRCODE (0x11, int_alignment_check) +HANDLER_NOERRCODE(0x12, int_machine_check) +HANDLER_NOERRCODE(0x13, int_SIMD_floating_point_exception) +HANDLER_NOERRCODE(0x14, int_virtualization_exception) +HANDLER_ERRCODE (0x15, int_control_protection_exception) +HANDLER_NOERRCODE(0x16, int_default) +HANDLER_NOERRCODE(0x17, int_default) +HANDLER_NOERRCODE(0x18, int_default) +HANDLER_NOERRCODE(0x19, int_default) +HANDLER_NOERRCODE(0x1a, int_default) +HANDLER_NOERRCODE(0x1b, int_default) +HANDLER_NOERRCODE(0x1c, int_hypervisor_injection_exception) +HANDLER_ERRCODE (0x1d, int_VMM_communication_exception) +HANDLER_ERRCODE (0x1e, int_security_exception) +HANDLER_NOERRCODE(0x1f, int_default) diff --git a/src/interrupts.cpp b/src/interrupts.cpp index cd29ce9..c80d7d1 100644 --- a/src/interrupts.cpp +++ b/src/interrupts.cpp @@ -35,3 +35,115 @@ void os::set_APIC_reg(std::ptrdiff_t offset, std::uint32_t v) { extern "C" void set_APIC_reg_asm(std::ptrdiff_t offset, std::uint32_t v) { os::set_APIC_reg(offset, v); } + + +extern "C" void int_div_by_0() { + os::print("Interrupt: Divide-by-0 error.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_debug() { + os::print("Interrupt: Debug.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_NMI() { + os::print("Interrupt: Non-maskable interrupt.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_breakpoint() { + os::print("Interrupt: Breakpoint.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_overflow() { + os::print("Interrupt: Overflow.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_bound_range_exceeded() { + os::print("Interrupt: Bound Range Exceeded.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_invalid_opcode() { + os::print("Interrupt: Invalid Opcode.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_device_not_available() { + os::print("Interrupt: Device Not Available.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_double_fault(std::uint32_t err_code) { + os::print("Interrupt: Double Fault.\n"); + os::print("Err code: "); os::print(err_code); os::print(".\n"); + while (true) { os::hlt(); } +} +extern "C" void int_coprocessor_segment_overrun() { + os::print("Interrupt: Coprocessor Segment Overrun.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_invalid_TSS(std::uint32_t err_code) { + os::print("Interrupt: Invalid TSS.\n"); + os::print("Err code: "); os::print(err_code); os::print(".\n"); + while (true) { os::hlt(); } +} +extern "C" void int_segment_not_present(std::uint32_t err_code) { + os::print("Interrupt: Segment Not Present.\n"); + os::print("Err code: "); os::print(err_code); os::print(".\n"); + while (true) { os::hlt(); } +} +extern "C" void int_stack_segment_fault(std::uint32_t err_code) { + os::print("Interrupt: Stack-Segment Fault.\n"); + os::print("Err code: "); os::print(err_code); os::print(".\n"); + while (true) { os::hlt(); } +} +extern "C" void int_general_protection_fault(std::uint32_t err_code) { + os::print("Interrupt: General Protection Fault.\n"); + os::print("Err code: "); os::print(err_code); os::print(".\n"); + while (true) { os::hlt(); } +} +extern "C" void int_page_fault(std::uint32_t err_code) { + os::print("Interrupt: Page Fault.\n"); + os::print("Err code: "); os::print(err_code); os::print(".\n"); + while (true) { os::hlt(); } +} +extern "C" void int_x87_floating_point_exception() { + os::print("Interrupt: x87 Floating-Point Exception.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_alignment_check(std::uint32_t err_code) { + os::print("Interrupt: Alignment Check.\n"); + os::print("Err code: "); os::print(err_code); os::print(".\n"); + while (true) { os::hlt(); } +} +extern "C" void int_machine_check() { + os::print("Interrupt: Machine Check.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_SIMD_floating_point_exception() { + os::print("Interrupt: SIMD Floating-Point Exception.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_virtualization_exception() { + os::print("Interrupt: Virtualization Exception.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_control_protection_exception(std::uint32_t err_code) { + os::print("Interrupt: Control Protection Exception.\n"); + os::print("Err code: "); os::print(err_code); os::print(".\n"); + while (true) { os::hlt(); } +} +extern "C" void int_hypervisor_injection_exception() { + os::print("Interrupt: Hypervisor Injection Exception.\n"); + while (true) { os::hlt(); } +} +extern "C" void int_VMM_communication_exception(std::uint32_t err_code) { + os::print("Interrupt: VMM Communication Exception.\n"); + os::print("Err code: "); os::print(err_code); os::print(".\n"); + while (true) { os::hlt(); } +} +extern "C" void int_security_exception(std::uint32_t err_code) { + os::print("Interrupt: Security Exception.\n"); + os::print("Err code: "); os::print(err_code); os::print(".\n"); + while (true) { os::hlt(); } +} +extern "C" void int_default() { + os::print("Interrupt: Unknown interrupt.\n"); + while (true) { os::hlt(); } +} diff --git a/src/kernel.cpp b/src/kernel.cpp index 3994028..fe6a38c 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -29,20 +29,6 @@ void remove_some_mem(os::phys_ptr mem_start, } os::idt<32> idt; -extern "C" void handler_impl_code(std::uint32_t err_code) { - os::println("Interrupt !"); - os::print("Err code: "); os::print(err_code); os::println("."); - while (true) { - os::hlt(); - } -} -extern "C" void handler_impl_no_code() { - os::println("Interrupt !"); - os::println("No error code."); - while (true) { - os::hlt(); - } -} extern "C" void kmain(unsigned long magic, os::phys_ptr info) { os::assert(magic == 0x36D76289, "Incorrect magic number: wasn't booted with multiboot2.");