IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
idt.hpp
Go to the documentation of this file.
1
11
12
13#pragma once
14
15
16// C++
17#include <array>
18#include <bit>
19#include <cstdint>
20#include <type_traits>
21// IgrOS-Kernel arch
22#include <arch/types.hpp>
23// IgrOS-Kernel arch x86
25#include <arch/x86/irq.hpp>
26
27
28// x86_64 namespace
29namespace igros::x86_64 {
30
31
33 class idt final {
34
36 constexpr static auto IDT_SIZE {256_usize};
37
38
39 public:
40
42 idt(const idt &other) = delete;
44 auto operator=(const idt &other) -> idt & = delete;
46 idt(idt &&other) = delete;
48 auto operator=(idt &&other) -> idt & = delete;
49
50
51#pragma pack(push, 1)
52
63
65 // cppcheck-suppress-begin unusedStructMember ; fixed layout read by the CPU, not by C++ code
70 // cppcheck-suppress-end unusedStructMember
71
72#pragma pack(pop)
73
75 using table_t = std::array<entry_t, IDT_SIZE>;
76
78 using offset_t = std::add_pointer_t<void()>;
79
81 idt() noexcept = default;
83 ~idt() noexcept = default;
84
90 [[nodiscard]]
91 static auto setEntry(const offset_t handle, const igros_word_t selector, const igros_byte_t type) noexcept -> entry_t;
95 [[nodiscard]]
96 constexpr static auto calcSize(const table_t &table) noexcept -> igros_word_t;
97
100 static void setPointer(const pointer_t &pointer) noexcept;
101
103 static void init() noexcept;
104 };
105
106
108 [[nodiscard]]
109 inline auto idt::setEntry(const offset_t handle, const igros_word_t selector, const igros_byte_t type) noexcept -> entry_t {
110 // Handler address
111 const auto address {std::bit_cast<igros_usize_t>(handle)};
112 return entry_t {
113 .offsetLow = static_cast<igros_word_t>(address & 0xFFFF_u64),
114 .selector = selector,
115 .ist = 0_u8,
116 .type = type,
117 .offsetMiddle = static_cast<igros_word_t>((address & 0xFFFF0000_u64) >> 16),
118 .offsetHigh = static_cast<igros_dword_t>((address & 0xFFFFFFFF00000000_u64) >> 32),
119 .reserved2 = 0_u32,
120 };
121 }
122
124 [[nodiscard]]
125 constexpr auto idt::calcSize(const table_t &table) noexcept -> igros_word_t {
126 return static_cast<igros_word_t>(table.size() * sizeof(entry_t)) - 1_u16;
127 }
128
129
130} // namespace igros::x86_64
131
std::add_pointer_t< void()> offset_t
IDT offset type.
Definition idt.hpp:78
static constexpr auto calcSize(const table_t &table) noexcept -> igros_word_t
Calc IDT size.
Definition idt.hpp:125
idt(const idt &other)=delete
Copy c-tor.
std::array< entry_t, IDT_SIZE > table_t
IDT table type.
Definition idt.hpp:75
auto operator=(const idt &other) -> idt &=delete
Copy assignment.
auto operator=(idt &&other) -> idt &=delete
Move assignment.
static constexpr auto IDT_SIZE
Number of IDT entries.
Definition idt.hpp:36
idt(idt &&other)=delete
Move c-tor.
static void init() noexcept
Init IDT table.
Definition idt.cpp:71
static auto setEntry(const offset_t handle, const igros_word_t selector, const igros_byte_t type) noexcept -> entry_t
Make IDT entry.
Definition idt.hpp:109
static void setPointer(const pointer_t &pointer) noexcept
Set IDT pointer.
Definition idt.cpp:64
idt() noexcept=default
Default c-tor.
Exceptions low-level operations.
std::uint16_t igros_word_t
16-bit unsigned integer
Definition types.hpp:42
std::uint8_t igros_byte_t
8-bit unsigned integer
Definition types.hpp:41
std::uint32_t igros_dword_t
32-bit unsigned integer
Definition types.hpp:43
x86_64 (long mode): GDT, IDT, TSS, CPUID, MSR, CPU registers
IDT table entry.
Definition idt.hpp:54
igros_word_t offsetLow
Offset lower part (0..15).
Definition idt.hpp:55
igros_dword_t reserved2
Must be zero.
Definition idt.hpp:61
igros_byte_t ist
Interrupt service table.
Definition idt.hpp:57
igros_dword_t offsetHigh
Offset higher part (32..63).
Definition idt.hpp:60
igros_word_t offsetMiddle
Offset middle part (16..31).
Definition idt.hpp:59
igros_byte_t type
Type attributes.
Definition idt.hpp:58
igros_word_t selector
Selectod from GDT/LDT.
Definition idt.hpp:56
IDT table pointer.
Definition idt.hpp:66
const entry_t * pointer
IDT pointer.
Definition idt.hpp:68
igros_word_t size
IDT size.
Definition idt.hpp:67
Common C++ types redefinition.
Interrupts low-level operations.