From ed19bb11fe9dcefbb1218f9d2e7539dbff8c7db0 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 3 Nov 2024 20:22:28 +0200 Subject: [PATCH] Kernel: Cleanup thread default sse initialization --- kernel/kernel/Thread.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/kernel/kernel/Thread.cpp b/kernel/kernel/Thread.cpp index 6357b9c0..1e4148c8 100644 --- a/kernel/kernel/Thread.cpp +++ b/kernel/kernel/Thread.cpp @@ -36,6 +36,23 @@ namespace Kernel static pid_t s_next_tid = 1; +#if __enable_sse + alignas(16) static uint8_t s_default_sse_storage[512]; + static bool s_default_sse_storage_initialized = false; + + static void initialize_default_sse_storage() + { + const uint32_t mxcsr = 0x1F80; + asm volatile( + "finit;" + "ldmxcsr %[mxcsr];" + "fxsave %[storage];" + : [storage]"=m"(s_default_sse_storage) + : [mxcsr]"m"(mxcsr) + ); + } +#endif + BAN::ErrorOr Thread::create_kernel(entry_t entry, void* data, Process* process) { // Create the thread object @@ -113,8 +130,12 @@ namespace Kernel : m_tid(tid), m_process(process) { #if __enable_sse - // initializes sse storage to valid state - save_sse(); + if (!s_default_sse_storage_initialized) + { + initialize_default_sse_storage(); + s_default_sse_storage_initialized = true; + } + memcpy(m_sse_storage, s_default_sse_storage, sizeof(m_sse_storage)); #endif }