From 96711d45ad7fb5b96cfd2b4fffda8756fe68fcd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Wed, 26 Mar 2025 09:33:44 +0000 Subject: Fixing pointer values and adding basic idt value --- .../interrupt_descriptor_table.cpp | 20 ++++++++++++++++++-- .../global_descriptor_table.cpp | 5 ++++- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'arch/x86_64/src/context_switching') 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 7346248..8bcce65 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 @@ -7,7 +7,22 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table { namespace { - auto create_interrupt_descriptor_table() -> interrupt_descriptor_table { return interrupt_descriptor_table{}; } + auto create_interrupt_descriptor_table() -> interrupt_descriptor_table + { + // TODO: Fix offset and ist and selector index + uint64_t const offset = 0x0; + segment_selector const selector{0U, segment_selector::REQUEST_LEVEL_KERNEL}; + ist_offset const ist{0U}; + idt_flags const flags{idt_flags::DESCRIPTOR_LEVEL_KERNEL | idt_flags::INTERRUPT_GATE}; + gate_descriptor const interrupt_gate{selector, ist, flags, offset}; + + segment_selector const selector{0U, segment_selector::REQUEST_LEVEL_KERNEL}; + ist_offset const ist{0U}; + idt_flags const flags{idt_flags::DESCRIPTOR_LEVEL_KERNEL | idt_flags::TRAP_GATE}; + gate_descriptor const trap_gate{selector, ist, flags, offset}; + + return interrupt_descriptor_table{interrupt_gate, trap_gate}; + } } // namespace auto initialize_interrupt_descriptor_table() -> interrupt_descriptor_table & @@ -15,7 +30,8 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table // Interrupt Descriptor Table needs to be kept alive static auto idt = create_interrupt_descriptor_table(); - interrupt_descriptor_table_pointer idt_pointer{static_cast(idt.size() - 1), &idt}; + interrupt_descriptor_table_pointer idt_pointer{static_cast((idt.size() * sizeof(gate_descriptor)) - 1), + &idt}; kernel::cpu::load_interrupt_descriptor_table(idt_pointer); auto const stored_gdt_pointer = kernel::cpu::store_interrupt_descriptor_table(); diff --git a/arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table.cpp b/arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table.cpp index 69cce19..e6a489c 100644 --- a/arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table.cpp +++ b/arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table.cpp @@ -75,7 +75,10 @@ namespace teachos::arch::context_switching::segment_descriptor_table // Global Descriptor Table needs to be kept alive static auto gdt = create_global_descriptor_table(); - global_descriptor_table_pointer gdt_pointer{static_cast(gdt.size() - 1), &gdt}; + // Calculate the size of the gdt in bytes - 1. This subtraction occurs because the maximum value of Size is 65535, + // while the GDT can be up to 65536 bytes in length (8192 entries). Further, no GDT can have a size of 0 bytes. + global_descriptor_table_pointer gdt_pointer{static_cast((gdt.size() * sizeof(segment_descriptor)) - 1), + &gdt}; kernel::cpu::load_global_descriptor_table(gdt_pointer); auto const stored_gdt_pointer = kernel::cpu::store_global_descriptor_table(); -- cgit v1.2.3