diff options
Diffstat (limited to 'arch/x86_64/src/context_switching')
2 files changed, 22 insertions, 3 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 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<uint16_t>(idt.size() - 1), &idt}; + interrupt_descriptor_table_pointer idt_pointer{static_cast<uint16_t>((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<uint16_t>(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<uint16_t>((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(); |
