aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-01-16 12:52:15 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-01-16 12:52:15 +0100
commit9750405757396d006ab6992fb93baf414b3e2ae8 (patch)
tree3c26d2626e330bf3a3a603928101c29805528464
parent8128bc5b37842645d7c92aa765f68749b4229c31 (diff)
downloadteachos-9750405757396d006ab6992fb93baf414b3e2ae8.tar.xz
teachos-9750405757396d006ab6992fb93baf414b3e2ae8.zip
x86_64/cpu: add basic interrupt support types
-rw-r--r--arch/x86_64/include/x86_64/cpu/interrupts.hpp61
-rw-r--r--arch/x86_64/include/x86_64/cpu/segment_selector.hpp20
2 files changed, 81 insertions, 0 deletions
diff --git a/arch/x86_64/include/x86_64/cpu/interrupts.hpp b/arch/x86_64/include/x86_64/cpu/interrupts.hpp
new file mode 100644
index 0000000..88d0b78
--- /dev/null
+++ b/arch/x86_64/include/x86_64/cpu/interrupts.hpp
@@ -0,0 +1,61 @@
+#ifndef TEACHOS_X86_64_CPU_INTERRUPTS_HPP
+#define TEACHOS_X86_64_CPU_INTERRUPTS_HPP
+
+#include "x86_64/cpu/segment_selector.hpp"
+
+#include <array>
+#include <cstdint>
+#include <type_traits>
+
+namespace teachos::cpu::x86_64
+{
+
+ //! The types of supported gates.
+ enum struct gate_type : std::uint8_t
+ {
+ //! A gate entered through the @p INT instruction.
+ interrupt_gate = 0b1110,
+ //! A gate entered via an exception.
+ trap_gate = 0b1111,
+ };
+
+ struct alignas(std::uint64_t) gate_descriptor
+ {
+ //! The lowest 16 bits of the address of this gate's handler function.
+ std::uint16_t offset_low : 16;
+ //! The code segment used when handling the respective interrupt.
+ segment_selector m_code_segment;
+ //! The index into the Interrupt Stack Table naming the stack to use.
+ std::uint8_t interrupt_stack_table_selector : 3;
+ //! Reserved
+ std::uint8_t : 5;
+ //! The type of this gate.
+ gate_type gate_type : 4;
+ //! Reserved
+ std::uint8_t : 1;
+ //! The privilege level required to enter through this gate.
+ std::uint8_t descriptor_privilege_level : 2;
+ //! Whether this gate is present or not.
+ std::uint8_t present : 1;
+ //! The middle 16 bits of the address of this gate's handler function.
+ std::uint16_t offset_middle : 16;
+ //! The highest 32 bits of the address of this gate's handler function.
+ std::uint32_t offset_high : 32;
+ //! Reserved
+ std::uint32_t : 32;
+ };
+
+ static_assert(sizeof(gate_descriptor) == 2 * sizeof(std::uint64_t));
+ static_assert(std::is_aggregate_v<gate_descriptor>);
+
+ struct interrupt_descriptor_table
+ {
+ interrupt_descriptor_table();
+
+ private:
+ std::array<gate_descriptor, 256> m_descriptors{};
+ };
+
+} // namespace teachos::cpu::x86_64
+
+#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/cpu/segment_selector.hpp b/arch/x86_64/include/x86_64/cpu/segment_selector.hpp
new file mode 100644
index 0000000..bb07e28
--- /dev/null
+++ b/arch/x86_64/include/x86_64/cpu/segment_selector.hpp
@@ -0,0 +1,20 @@
+#ifndef TEACHOS_X86_64_SEGMENT_SELECTOR_HPP
+#define TEACHOS_X86_64_SEGMENT_SELECTOR_HPP
+
+#include <cstdint>
+namespace teachos::cpu::x86_64
+{
+
+ struct segment_selector
+ {
+ std::uint16_t request_privilege_level : 2;
+ bool use_local_descriptor_table : 1;
+ std::uint16_t table_index : 13;
+ };
+
+ static_assert(sizeof(segment_selector) == sizeof(std::uint16_t));
+ static_assert(alignof(segment_selector) == alignof(std::uint16_t));
+
+} // namespace teachos::cpu::x86_64
+
+#endif \ No newline at end of file