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// i386 namespace
29namespace igros::i386 {
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
61
63 // cppcheck-suppress-begin unusedStructMember ; fixed layout read by the CPU, not by C++ code
68 // cppcheck-suppress-end unusedStructMember
69
70#pragma pack(pop)
71
73 using table_t = std::array<entry_t, IDT_SIZE>;
74
76 using offset_t = std::add_pointer_t<void()>;
77
79 idt() noexcept = default;
81 ~idt() noexcept = default;
82
88 [[nodiscard]]
89 static auto setEntry(const offset_t handle, const igros_word_t selector, const igros_byte_t type) noexcept -> entry_t;
93 [[nodiscard]]
94 constexpr static auto calcSize(const table_t &table) noexcept -> igros_word_t;
95
98 static void setPointer(const pointer_t &pointer) noexcept;
99
101 static void init() noexcept;
102 };
103
104
106 [[nodiscard]]
107 inline auto idt::setEntry(const offset_t handle, const igros_word_t selector, const igros_byte_t type) noexcept -> entry_t {
108 // Handler address
109 const auto address {std::bit_cast<igros_usize_t>(handle)};
110 return entry_t {
111 .offsetLow = static_cast<igros_word_t>(address & 0xFFFF_usize),
112 .selector = selector,
113 .reserved = 0_u8,
114 .type = type,
115 .offsetHigh = static_cast<igros_word_t>((address >> 16) & 0xFFFF_usize),
116 };
117 }
118
120 [[nodiscard]]
121 constexpr auto idt::calcSize(const table_t &table) noexcept -> igros_word_t {
122 return static_cast<igros_word_t>(table.size() * sizeof(entry_t)) - 1_u16;
123 }
124
125
126} // namespace igros::i386
127
static void setPointer(const pointer_t &pointer) noexcept
Set IDT pointer.
static constexpr auto calcSize(const table_t &table) noexcept -> igros_word_t
Calc IDT size.
Definition idt.hpp:121
auto operator=(idt &&other) -> idt &=delete
Move assignment.
std::array< entry_t, IDT_SIZE > table_t
IDT table type.
Definition idt.hpp:73
static void init() noexcept
Init IDT table.
idt(idt &&other)=delete
Move c-tor.
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:107
auto operator=(const idt &other) -> idt &=delete
Copy assignment.
std::add_pointer_t< void()> offset_t
IDT offset type.
Definition idt.hpp:76
idt(const idt &other)=delete
Copy c-tor.
idt() noexcept=default
Default c-tor.
static constexpr auto IDT_SIZE
Number of IDT entries.
Definition idt.hpp:36
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
i386 (32-bit protected mode): GDT, IDT, TSS, CPU registers
IDT table entry.
Definition idt.hpp:54
igros_byte_t type
Type attributes.
Definition idt.hpp:58
igros_word_t offsetHigh
Offset higher part (16..31).
Definition idt.hpp:59
igros_word_t offsetLow
Offset lower part (0..15).
Definition idt.hpp:55
igros_byte_t reserved
Must be zero.
Definition idt.hpp:57
igros_word_t selector
Selectod from GDT/LDT.
Definition idt.hpp:56
IDT table pointer.
Definition idt.hpp:64
const entry_t * pointer
IDT pointer.
Definition idt.hpp:66
igros_word_t size
IDT size.
Definition idt.hpp:65
Common C++ types redefinition.
Interrupts low-level operations.