1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "mos/x86/tasks/fpu_context.hpp"
4
5#include "mos/platform/platform.hpp"
6#include "mos/syslog/printk.hpp"
7#include "mos/tasks/task_types.hpp"
8
9#include <mos/allocator.hpp>
10#include <mos_stdlib.hpp>
11
12static const u64 RFBM = ~0ULL;
13const reg32_t low = RFBM & 0xFFFFFFFF;
14const reg32_t high = RFBM >> 32;
15
16void x86_xsave_thread(Thread *thread)
17{
18 if (!thread || thread->mode == THREAD_MODE_KERNEL)
19 return; // no, kernel threads don't have these
20
21 if (!thread->platform_options.xsaveptr)
22 return; // this happens when the thread is being execve'd
23
24 pr_dcont(scheduler, "saved.");
25 __asm__ volatile("xsave %0" ::"m"(*thread->platform_options.xsaveptr), "a"(low), "d"(high));
26}
27
28void x86_xrstor_thread(Thread *thread)
29{
30 if (!thread || thread->mode == THREAD_MODE_KERNEL)
31 return; // no, kernel threads don't have these
32
33 if (!thread->platform_options.xsaveptr)
34 return; // this happens when the thread is being execve'd
35
36 pr_dcont(scheduler, "restored.");
37 __asm__ volatile("xrstor %0" ::"m"(*thread->platform_options.xsaveptr), "a"(low), "d"(high));
38}
39