From c4fb939e48f92b4e8510aa786773ecd7a8aeb4bf Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Fri, 2 Oct 2026 12:18:23 +0200 Subject: [PATCH] feat: add TSS --- kernel/gdt.hpp | 4 ++-- kernel/kmain.cpp | 12 +++++++++--- kernel/task.hpp | 24 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 kernel/task.hpp diff --git a/kernel/gdt.hpp b/kernel/gdt.hpp index ea22487..243ddf6 100644 --- a/kernel/gdt.hpp +++ b/kernel/gdt.hpp @@ -6,12 +6,12 @@ struct gdt_entry { u64 value; - constexpr gdt_entry(u32 base, u32 limit, u8 access, u8 flags) + constexpr gdt_entry(u32 base, u32 limit, u8 access, u8 flags) noexcept : value((static_cast(limit & 0xFFFF) << 0) | (static_cast(base & 0xFFFFFF) << 16) | (static_cast(access & 0xFF) << 40) | (static_cast(limit & 0x0F) << 48) | (static_cast(flags & 0x0F) << 52) | (static_cast((base >> 24) & 0xFF) << 56)) {} - constexpr gdt_entry(u64 value) + constexpr gdt_entry(u64 value) noexcept : value(value) {} static gdt_entry extend(u32 baseHi) { return { baseHi }; } diff --git a/kernel/kmain.cpp b/kernel/kmain.cpp index fd7b197..e0a739d 100644 --- a/kernel/kmain.cpp +++ b/kernel/kmain.cpp @@ -1,4 +1,5 @@ #include "gdt.hpp" +#include "task.hpp" #include "types.hpp" static volatile u16* const s_vga = reinterpret_cast(0xB8000); @@ -16,7 +17,9 @@ static inline void puts(const char* str, u8 row, u8 col) { s_vga[col + off + (VGA_COLS * row)] = 0x0700 | str[off]; } -static constexpr gdt_entry s_gdt[5] = { +static constexpr tss s_tss{}; + +static gdt_entry s_gdt[] = { // Null Descriptor gdt_entry{ 0, 0, 0, 0 }, // Kernel Mode Code Segment @@ -40,8 +43,11 @@ static constexpr gdt_entry s_gdt[5] = { gdt_entry::ACCESS_P | gdt_entry::ACCESS_DPL3 | gdt_entry::ACCESS_S | gdt_entry::ACCESS_E | gdt_entry::ACCESS_RW, gdt_entry::FLAG_G | gdt_entry::FLAG_L }, // Task State Segment - // gdt_entry{ 0, 0, gdt_entry::ACCESS_P | gdt_entry::ACCESS_E | gdt_entry::ACCESS_A, 0 }, - // gdt_entry{ 0 } + gdt_entry{ static_cast(reinterpret_cast(&s_tss) & 0xFFFFFFFF), + sizeof(s_tss) - 1, + gdt_entry::ACCESS_P | gdt_entry::ACCESS_E | gdt_entry::ACCESS_A, + 0 }, + gdt_entry{ static_cast(reinterpret_cast(&s_tss) >> 32) } }; extern "C" void kmain(void) { diff --git a/kernel/task.hpp b/kernel/task.hpp new file mode 100644 index 0000000..14b9789 --- /dev/null +++ b/kernel/task.hpp @@ -0,0 +1,24 @@ +#ifndef TSS_HPP +#define TSS_HPP + +#include "types.hpp" + +struct tss { + u32 rsv0; + u64 rsp0; + u64 rsp1; + u64 rsp2; + u64 rsv1; + u64 ist1; + u64 ist2; + u64 ist3; + u64 ist4; + u64 ist5; + u64 ist6; + u64 ist7; + u64 rsv2; + u16 rsv3; + u16 iopb; +} PACKED; + +#endif // TSS_HPP