The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
fpu.c File Reference

the FPU (x87) and SSE register state of user programs. More...

#include "arch/arch.h"
#include "common/memory.h"

Macros

#define CR0_MP   0x00000002u
#define CR0_EM   0x00000004u
#define CR0_TS   0x00000008u
#define CR0_NE   0x00000020u
#define CR4_OSFXSR   0x00000200u
#define CR4_OSXMMEXCPT   0x00000400u
#define CPUID_EDX_FXSR   0x01000000u
#define CPUID_EDX_SSE   0x02000000u
#define MXCSR_VALID   0x0000FFBFu
#define FXSAVE_MXCSR_OFFSET   24

Functions

void arch_fpu_init_core (void)
 turn on the FPU (and SSE) on the core that runs the call.
void arch_fpu_init (void)
 turn on the FPU (and SSE) for user programs and make the clean state a new program starts with.
void arch_fpu_save (void *area)
 save the CPU's FPU/SSE registers.
void arch_fpu_restore (const void *area)
 load the FPU/SSE registers.
void arch_fpu_clean (void *area)
 fill an area with the state of a fresh program.
void arch_fpu_sanitize (void *area)
 make a state that came from user memory safe to load (a signal frame).

Detailed Description

the FPU (x87) and SSE register state of user programs.

the kernel itself never uses these registers, so a user program's state stays in the CPU while it is in the kernel. the scheduler saves it when it switches away and loads the next program's state, every time (no lazy switching). FXSAVE/FXRSTOR keep the x87 and SSE registers in 512 bytes; a CPU without them uses FNSAVE/FRSTOR (108 bytes, no SSE).

Macro Definition Documentation

◆ CR0_MP

#define CR0_MP   0x00000002u

◆ CR0_EM

#define CR0_EM   0x00000004u

◆ CR0_TS

#define CR0_TS   0x00000008u

◆ CR0_NE

#define CR0_NE   0x00000020u

◆ CR4_OSFXSR

#define CR4_OSFXSR   0x00000200u

◆ CR4_OSXMMEXCPT

#define CR4_OSXMMEXCPT   0x00000400u

◆ CPUID_EDX_FXSR

#define CPUID_EDX_FXSR   0x01000000u

◆ CPUID_EDX_SSE

#define CPUID_EDX_SSE   0x02000000u

◆ MXCSR_VALID

#define MXCSR_VALID   0x0000FFBFu

◆ FXSAVE_MXCSR_OFFSET

#define FXSAVE_MXCSR_OFFSET   24

Function Documentation

◆ arch_fpu_init_core()

void arch_fpu_init_core ( void )

turn on the FPU (and SSE) on the core that runs the call.

arch_fpu_init() does it for the boot core; each other core calls this when it starts.

◆ arch_fpu_init()

void arch_fpu_init ( void )

turn on the FPU (and SSE) for user programs and make the clean state a new program starts with.

call once at boot.

◆ arch_fpu_save()

void arch_fpu_save ( void * area)

save the CPU's FPU/SSE registers.

Parameters
areaARCH_FPU_STATE_SIZE bytes, 16-byte aligned.

◆ arch_fpu_restore()

void arch_fpu_restore ( const void * area)

load the FPU/SSE registers.

Parameters
areastate saved by arch_fpu_save (or arch_fpu_clean).

◆ arch_fpu_clean()

void arch_fpu_clean ( void * area)

fill an area with the state of a fresh program.

◆ arch_fpu_sanitize()

void arch_fpu_sanitize ( void * area)

make a state that came from user memory safe to load (a signal frame).