IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
tss.cpp
Go to the documentation of this file.
1
11
12
13// C++
14#include <bit>
15#include <cstddef>
16// IgrOS-Kernel arch x86_64
17#include <arch/x86_64/tss.hpp>
18
19
20// x86_64 namespace
21namespace igros::x86_64 {
22
23
24 // Set up task state segment interrupt stacks
25 [[nodiscard]]
26 auto tss::init() noexcept -> const segment_t & {
27
28 // Interrupt stacks (one per IST entry in use)
29 alignas(16) constinit static std::array<std::array<igros_byte_t, STACK_SIZE>, 3> stacks {};
30 // Quad fields of the packed layout are at offsets 4 + 8n: segment starts 4 bytes
31 // past an 8 byte boundary, so they are naturally aligned (misaligned access is UB)
32 struct alignas(igros_quad_t) storage_t {
33 igros_dword_t padding;
34 segment_t segment;
35 };
36 static_assert(sizeof(igros_dword_t) == offsetof(storage_t, segment), "TSS quad fields must be aligned");
37 // Task state segment (no I/O permission bitmap: offset past segment limit)
38 constinit static storage_t storage {
39 .padding = 0_u32,
40 .segment = {
41 .reserved0 = 0_u32,
42 .rsp = {},
43 .reserved1 = 0_u64,
44 .ist = {},
45 .reserved2 = 0_u64,
46 .reserved3 = 0_u16,
47 .iomapBase = static_cast<igros_word_t>(sizeof(segment_t)),
48 },
49 };
50 auto &segment {storage.segment};
51
52 // Stacks grow down: IST entry holds stack top
53 for (auto index {0_usize}; index < stacks.size(); ++index) {
54 segment.ist[index] = static_cast<igros_quad_t>(std::bit_cast<igros_usize_t>(stacks[index].data() + stacks[index].size()));
55 }
56 return segment;
57 }
58
59
60} // namespace igros::x86_64
static auto init() noexcept -> const segment_t &
Set up task state segment interrupt stacks (returns static segment for GDT).
Definition tss.cpp:26
std::uint16_t igros_word_t
16-bit unsigned integer
Definition types.hpp:42
std::uint32_t igros_dword_t
32-bit unsigned integer
Definition types.hpp:43
std::uint64_t igros_quad_t
64-bit unsigned integer
Definition types.hpp:44
x86_64 (long mode): GDT, IDT, TSS, CPUID, MSR, CPU registers
Task state segment layout.
Definition tss.hpp:55
Task state segment (x86_64).