24#define CPUID_EDX_FXSR _BV(24)
25#define CPUID_EDX_SSE _BV(25)
32#define last_fpu_thread (curcpu()->arch.fpu_thread)
53 asm volatile(
"cpuid":
"+a"(eax),
"=b"(ebx),
"=c"(ecx),
"=d"(edx));
68 asm volatile(
"fninit");
69 asm volatile(
"fxsave (%0)"::
"r"(
fpu_clean):
"memory");
90 write_cr0(read_cr0() |
CR0_TS);
101 asm volatile(
"fxrstor (%0)"::
"r"(
fpu_context):
"memory");
103 asm volatile(
"fninit");
111 asm volatile(
"fxsave (%0)"::
"r"(
fpu_context):
"memory");
113 asm volatile(
"fnsave (%0)"::
"r"(
fpu_context):
"memory");
120 asm volatile(
"fxrstor (%0)"::
"r"(
fpu_context):
"memory");
122 asm volatile(
"frstor (%0)"::
"r"(
fpu_context):
"memory");
134 panic(
"FPU trap without a current thread");
static void write_cr4(uintptr_t val)
static uintptr_t read_cr4(void)
#define assert_alignof(o, al)
static char fpu_context[512]
static char fpu_clean[512]
void x86_fpu_load_from(const void *buf, int valid)
Gives the current thread back the FPU state saved in a signal frame, at sigreturn.
void x86_fpu_trap(void)
Handles #NM, the current thread's first FPU or SSE instruction since it was switched in: it saves the...
int x86_fpu_save_to(void *buf)
Copies the current thread's FPU state, for a signal handler's frame (sys/signal.c).
static void fpu_restore(void)
Loads the FPU's state from fpu_context.
void x86_fpu_disable(void)
Makes the next FPU instruction trap (sets CR0.TS).
void x86_fpu_init(void)
Loads the clean starting state into the FPU, for a thread's first use of it.
void x86_fpu_setup(void)
Sets up the FPU on the running CPU, at boot: CR0.TS set so that the first FPU or SSE instruction rais...
void x86_fpu_enable(void)
Lets the running CPU use the FPU without trapping (clears CR0.TS).
void x86_fpu_reset(void)
Makes the current thread start with a clean FPU state at its next use of the FPU, as a signal handler...
static uint32_t mxcsr_mask
void x86_fpu_switch_out(void)
Saves the current thread's FPU state when it is switched out, if the FPU holds it,...
static void fpu_save(void)
Saves the FPU's state into fpu_context.
#define MALLOC_DEFINE(type, _name, _desc)
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
void * memcpy(void *dst, const void *src, size_t n)
Copies n bytes; dst and src must not overlap.
int signal_proc_send(struct proc *proc, int signal)
Sends a signal to a process.
A thread's x86 state: its kernel stack, and where it resumes.