diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-09-04 20:24:06 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-09-04 20:24:06 +0200 |
| commit | a5848c037e6e681d586312ddddddd200b9f7a5b0 (patch) | |
| tree | 136075c68d36d6a671cd97c0df6567c6e3f90755 /arch | |
| parent | aee4582fb5144e1dd493041a8d1fc0c08146a622 (diff) | |
| download | kernel-a5848c037e6e681d586312ddddddd200b9f7a5b0.tar.xz kernel-a5848c037e6e681d586312ddddddd200b9f7a5b0.zip | |
x86_64/cpu: use IST1 as the stack for #DF
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/x86_64/arch/cpu/initialization.cpp | 20 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/interrupts.cpp | 4 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/task_state_segment.hpp | 21 |
3 files changed, 33 insertions, 12 deletions
diff --git a/arch/x86_64/arch/cpu/initialization.cpp b/arch/x86_64/arch/cpu/initialization.cpp index 67bc2a4d..be1cc9f8 100644 --- a/arch/x86_64/arch/cpu/initialization.cpp +++ b/arch/x86_64/arch/cpu/initialization.cpp @@ -8,7 +8,9 @@ #include <kstd/print.hpp> +#include <array> #include <bit> +#include <cstddef> #include <cstdint> namespace arch::cpu @@ -111,11 +113,27 @@ namespace arch::cpu (address >> 32) & 0xffff'ffff, // NOLINT(readability-magic-numbers) }; } + + [[gnu::section(".ist1_stack")]] auto constinit ist1_stack = std::array<std::byte, 4096>{}; + + auto constinit tss = task_state_segment{ + .rsp0 = nullptr, + .rsp1 = nullptr, + .rsp2 = nullptr, + .ist1 = ist1_stack.data() + ist1_stack.size(), + .ist2 = nullptr, + .ist3 = nullptr, + .ist4 = nullptr, + .ist5 = nullptr, + .ist6 = nullptr, + .ist7 = nullptr, + .io_map_base_address = 0, + }; + } // namespace auto initialize_descriptors() -> void { - auto static tss = task_state_segment{}; auto static tss_descriptor = make_tss_descriptor(&tss); auto static gdt = global_descriptor_table{ diff --git a/arch/x86_64/arch/cpu/interrupts.cpp b/arch/x86_64/arch/cpu/interrupts.cpp index 2fdc4671..cf225a90 100644 --- a/arch/x86_64/arch/cpu/interrupts.cpp +++ b/arch/x86_64/arch/cpu/interrupts.cpp @@ -167,10 +167,12 @@ namespace arch::cpu { for (auto i = 0uz; i < 256; ++i) { + auto ist_selector = static_cast<std::uint8_t>(i == 8 ? 1 : 0); + m_descriptors[i] = gate_descriptor{ .offset_low = static_cast<std::uint16_t>(isr_stub_table[i] & 0xffff), // NOLINT(readability-magic-numbers) .m_code_segment = segment_selector{0, false, 1}, - .interrupt_stack_table_selector = 0, + .interrupt_stack_table_selector = ist_selector, .gate_type = (i < 32 && i != 2) ? gate_type::trap_gate : gate_type::interrupt_gate, .descriptor_privilege_level = 0, .present = true, diff --git a/arch/x86_64/arch/cpu/task_state_segment.hpp b/arch/x86_64/arch/cpu/task_state_segment.hpp index ab141f4c..f8b257d4 100644 --- a/arch/x86_64/arch/cpu/task_state_segment.hpp +++ b/arch/x86_64/arch/cpu/task_state_segment.hpp @@ -1,6 +1,7 @@ #ifndef TEACHOS_ARCH_X86_64_TASK_STATE_SEGMENT_HPP #define TEACHOS_ARCH_X86_64_TASK_STATE_SEGMENT_HPP +#include <cstddef> #include <cstdint> namespace arch::cpu @@ -9,17 +10,17 @@ namespace arch::cpu struct [[gnu::packed]] task_state_segment { std::uint32_t : 32; - std::uint64_t rsp0 = {}; - std::uint64_t rsp1 = {}; - std::uint64_t rsp2 = {}; + std::byte * rsp0 = {}; + std::byte * rsp1 = {}; + std::byte * rsp2 = {}; std::uint64_t : 64; - std::uint64_t ist1 = {}; - std::uint64_t ist2 = {}; - std::uint64_t ist3 = {}; - std::uint64_t ist4 = {}; - std::uint64_t ist5 = {}; - std::uint64_t ist6 = {}; - std::uint64_t ist7 = {}; + std::byte * ist1 = {}; + std::byte * ist2 = {}; + std::byte * ist3 = {}; + std::byte * ist4 = {}; + std::byte * ist5 = {}; + std::byte * ist6 = {}; + std::byte * ist7 = {}; std::uint64_t : 64; std::uint16_t : 16; std::uint16_t io_map_base_address = {}; |
