Kernel: Start working on TLS, add SYS_{SET,GET}_TLS

This commit is contained in:
2025-04-15 23:16:20 +03:00
parent 254fd80088
commit 4bcd3ed86f
11 changed files with 60 additions and 3 deletions

View File

@@ -10,7 +10,10 @@ extern Kernel::TerminalDriver* g_terminal_driver;
namespace Kernel
{
#if ARCH(x86_64)
static constexpr uint32_t MSR_IA32_FS_BASE = 0xC0000100;
static constexpr uint32_t MSR_IA32_GS_BASE = 0xC0000101;
#endif
ProcessorID Processor::s_bsb_id { PROCESSOR_NONE };
BAN::Atomic<uint8_t> Processor::s_processor_count { 0 };
@@ -260,6 +263,18 @@ namespace Kernel
set_interrupt_state(state);
}
void Processor::load_tls()
{
const auto addr = scheduler().current_thread().get_tls();
#if ARCH(x86_64)
uint32_t ptr_hi = addr >> 32;
uint32_t ptr_lo = addr & 0xFFFFFFFF;
asm volatile("wrmsr" :: "d"(ptr_hi), "a"(ptr_lo), "c"(MSR_IA32_FS_BASE));
#elif ARCH(i686)
gdt().set_tls(addr);
#endif
}
void Processor::send_smp_message(ProcessorID processor_id, const SMPMessage& message, bool send_ipi)
{
ASSERT(processor_id != current_id());