aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/context_switching
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2025-03-26 09:33:44 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2025-03-26 09:33:44 +0000
commit96711d45ad7fb5b96cfd2b4fffda8756fe68fcd4 (patch)
treee9d3aaeb05d796ecee9fcf5064c1304e057fc321 /arch/x86_64/src/context_switching
parent66fefaeb16bcbc4eae5ce5256ae76f51a155cded (diff)
downloadteachos-96711d45ad7fb5b96cfd2b4fffda8756fe68fcd4.tar.xz
teachos-96711d45ad7fb5b96cfd2b4fffda8756fe68fcd4.zip
Fixing pointer values and adding basic idt value
Diffstat (limited to 'arch/x86_64/src/context_switching')
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp20
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table.cpp5
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();