From 40cfa485cc2c9e344a0386419ed55c123312ec32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 31 Mar 2025 15:20:27 +0000 Subject: Add missing flag to idt entry. --- .../interrupt_descriptor_table.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp b/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp index db3351e..b520a57 100644 --- a/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp +++ b/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp @@ -10,15 +10,20 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table { auto create_interrupt_descriptor_table() -> interrupt_descriptor_table { - // @MTO: This address resolution is most certainly wrong -> numbers in dbg seem off (offset_3 = 0) - uint64_t offset = reinterpret_cast(&interrupt_handling::generic_interrupt_handler); - segment_selector selector{0U, segment_selector::REQUEST_LEVEL_KERNEL}; + // TODO: See 7.14 Vol. 3A Page 3299 Intel Manual, still crashes from time to time on setting interrupt flag? + // Probably an interrupt is generated but the interrupt descriptor table is not in a valid form and does not + // handle the interrupt. + interrupt_descriptor_table interrupt_descriptor_table{256}; + + uint64_t offset = 0U; + segment_selector selector{1U, segment_selector::REQUEST_LEVEL_KERNEL}; ist_offset ist{0U}; - idt_flags flags{idt_flags::DESCRIPTOR_LEVEL_KERNEL | idt_flags::PRESENT}; - gate_descriptor descriptor{selector, ist, flags, offset}; + idt_flags flags{idt_flags::DESCRIPTOR_LEVEL_KERNEL | idt_flags::INTERRUPT_GATE | idt_flags::PRESENT}; - // Interrupt Descriptor Table needs to be kept alive - static interrupt_descriptor_table interrupt_descriptor_table{descriptor}; + for (std::size_t i = 0; i < 256; i++) + { + interrupt_descriptor_table.at(i) = {selector, ist, flags, offset}; + } return interrupt_descriptor_table; } } // namespace @@ -32,7 +37,7 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table auto update_interrupt_descriptor_table_register() -> void { - static auto idt = get_or_create_interrupt_descriptor_table(); + decltype(auto) idt = get_or_create_interrupt_descriptor_table(); interrupt_descriptor_table_pointer idt_pointer{static_cast((idt.size() * sizeof(gate_descriptor)) - 1), idt.data()}; -- cgit v1.2.3