aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/cpu/initialization.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/cpu/initialization.cpp')
-rw-r--r--arch/x86_64/src/cpu/initialization.cpp51
1 files changed, 31 insertions, 20 deletions
diff --git a/arch/x86_64/src/cpu/initialization.cpp b/arch/x86_64/src/cpu/initialization.cpp
index aae4f1f..214687c 100644
--- a/arch/x86_64/src/cpu/initialization.cpp
+++ b/arch/x86_64/src/cpu/initialization.cpp
@@ -1,6 +1,7 @@
#include "arch/cpu/initialization.hpp"
#include "arch/cpu/global_descriptor_table.hpp"
+#include "arch/cpu/interrupts.hpp"
#include "arch/cpu/segment_descriptor.hpp"
#include "arch/cpu/task_state_segment.hpp"
@@ -83,30 +84,38 @@ namespace arch::cpu
.granularity = segment_granularity::page,
.base_high = 0,
};
+
+ constexpr auto make_tss_descriptor(task_state_segment const * tss_ptr) -> system_segment_descriptor
+ {
+ auto const address = std::bit_cast<std::uintptr_t>(tss_ptr);
+ auto const limit = sizeof(task_state_segment) - 1;
+
+ return system_segment_descriptor{
+ {
+ .limit_low = limit & 0xffff, // NOLINT(readability-magic-numbers)
+ .base_low = address & 0xffffff, // NOLINT(readability-magic-numbers)
+ .accessed = false,
+ .read_write = false,
+ .direction_or_conforming = false,
+ .executable = false,
+ .type = segment_type::system,
+ .privilege_level = 0,
+ .present = true,
+ .limit_high = (limit >> 16) & 0xf, // NOLINT(readability-magic-numbers)
+ .long_mode = false,
+ .protected_mode = false,
+ .granularity = segment_granularity::byte,
+ .base_high = (address >> 24) & 0xff, // NOLINT(readability-magic-numbers)
+ },
+ (address >> 32) & 0xffff'ffff, // NOLINT(readability-magic-numbers)
+ };
+ }
} // namespace
auto initialize_descriptors() -> void
{
auto static tss = task_state_segment{};
- auto static tss_descriptor = system_segment_descriptor{
- {
- .limit_low = (sizeof(tss) - 1) & 0xffff, // NOLINT(readability-magic-numbers)
- .base_low = std::bit_cast<std::uintptr_t>(&tss) & 0xffffff, // NOLINT(readability-magic-numbers)
- .accessed = false,
- .read_write = false,
- .direction_or_conforming = false,
- .executable = false,
- .type = segment_type::system,
- .privilege_level = 0,
- .present = true,
- .limit_high = ((sizeof(tss) - 1) >> 16) & 0xf, // NOLINT(readability-magic-numbers)
- .long_mode = false,
- .protected_mode = false,
- .granularity = segment_granularity::byte,
- .base_high = (std::bit_cast<std::uintptr_t>(&tss) >> 24) & 0xff, // NOLINT(readability-magic-numbers)
- },
- (std::bit_cast<std::uintptr_t>(&tss) >> 32) & 0xffff'ffff, // NOLINT(readability-magic-numbers)
- };
+ auto static tss_descriptor = make_tss_descriptor(&tss);
auto static gdt = global_descriptor_table{
gdt_null_descriptor, gdt_kernel_code_descriptor, gdt_kernel_data_descriptor,
@@ -116,7 +125,9 @@ namespace arch::cpu
kstd::println("[x86_64:SYS] Reloading Global Descriptor Table.");
gdt.load(1, 2);
- kstd::println("[x86_64:SYS] TODO: initialize Interrupt Descriptor Table.");
+ kstd::println("[x86_64:SYS] Initializing Interrupt Descriptor Table.");
+ auto static idt = interrupt_descriptor_table{};
+ idt.load();
}
} // namespace arch::cpu