AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
fpsimd.c File Reference

aarch64: the FP/SIMD registers, switched lazily, as x86's FPU is (see docs/kernel/processes.md). More...

#include <core/system.h>
#include <core/arch.h>
#include <core/string.h>
#include <cpu/cpu.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <sys/signal.h>

Go to the source code of this file.

Macros

#define CPACR_FPEN_EL0_TRAP   (1UL << 20)
#define CPACR_FPEN_NONE   (3UL << 20)
#define fp_thread   (curcpu()->arch.fp_thread)

Functions

void aarch64_fpsimd_save (void *state)
void aarch64_fpsimd_load (const void *state)
static void fpen (uint64_t v)
 Sets CPACR_EL1.FPEN: whether user mode's use traps.
void aarch64_fpsimd_switch (struct thread *thread)
 Gets the registers ready for a thread that is about to run: its use of them traps, unless the registers already hold its values.
void * aarch64_fpsimd_current (struct thread *thread)
 Returns a thread's FP/SIMD state as it is now, saving it from the registers first if they hold it.
int aarch64_fpsimd_trap (void)
 Handles the trap of user mode's use of the registers: they get the running thread's values, and its use stops trapping.
void aarch64_fpsimd_drop (struct thread *thread)
 Throws away a thread's FP/SIMD state, when it goes or execs a new program, and the registers' values if they're the thread's.
int aarch64_fpsimd_fork (struct thread *parent, struct aarch64_thread *child)
 Gives a child of fork() a copy of its parent's FP/SIMD state, if the parent has one.
void aarch64_fpsimd_restore (struct thread *thread, const void *state)
 Gives a thread back the FP/SIMD state that a signal frame kept, for sigreturn().

Detailed Description

aarch64: the FP/SIMD registers, switched lazily, as x86's FPU is (see docs/kernel/processes.md).

User mode's use of the registers traps (CPACR_EL1.FPEN = 0b01: EL0's accesses trap, EL1's don't, and the kernel uses none), unless the CPU's registers already hold the running thread's values. At the trap, the thread whose values they hold (the CPU's fp_thread) gets them saved, the running thread's are loaded (zeros, the first time), and its use stops trapping.

References: [1] - Arm Architecture Reference Manual for A-profile, D19.2 (CPACR_EL1.FPEN) and the exception class 0x07

Definition in file fpsimd.c.

Macro Definition Documentation

◆ CPACR_FPEN_EL0_TRAP

#define CPACR_FPEN_EL0_TRAP   (1UL << 20)

Definition at line 28 of file fpsimd.c.

Referenced by aarch64_fpsimd_drop(), aarch64_fpsimd_restore(), and aarch64_fpsimd_switch().

◆ CPACR_FPEN_NONE

#define CPACR_FPEN_NONE   (3UL << 20)

Definition at line 29 of file fpsimd.c.

Referenced by aarch64_fpsimd_switch(), and aarch64_fpsimd_trap().

◆ fp_thread

#define fp_thread   (curcpu()->arch.fp_thread)

Function Documentation

◆ aarch64_fpsimd_current()

void * aarch64_fpsimd_current ( struct thread * thread)

Returns a thread's FP/SIMD state as it is now, saving it from the registers first if they hold it.

Parameters
threadthe thread
Returns
its saved state, or NULL if it never used the registers

Definition at line 64 of file fpsimd.c.

References aarch64_fpsimd_current(), aarch64_fpsimd_save(), thread::arch, fp_thread, and aarch64_thread::fpsimd.

Referenced by aarch64_fpsimd_current(), aarch64_fpsimd_fork(), and deliver().

◆ aarch64_fpsimd_drop()

void aarch64_fpsimd_drop ( struct thread * thread)

Throws away a thread's FP/SIMD state, when it goes or execs a new program, and the registers' values if they're the thread's.

Parameters
threadthe thread

Definition at line 106 of file fpsimd.c.

References aarch64_fpsimd_drop(), thread::arch, CPACR_FPEN_EL0_TRAP, fp_thread, fpen(), aarch64_thread::fpsimd, kfree(), and NULL.

Referenced by aarch64_fpsimd_drop(), arch_exec_start(), and arch_thread_kill().

◆ aarch64_fpsimd_fork()

int aarch64_fpsimd_fork ( struct thread * parent,
struct aarch64_thread * child )

Gives a child of fork() a copy of its parent's FP/SIMD state, if the parent has one.

Parameters
parentthe thread that forked
childthe child's aarch64 state
Returns
0, or -ENOMEM if there was no memory for the copy

Definition at line 129 of file fpsimd.c.

References aarch64_fpsimd_current(), aarch64_fpsimd_fork(), aarch64_thread::fpsimd, FPSIMD_STATE_SIZE, kmalloc(), and memcpy().

Referenced by aarch64_fpsimd_fork(), and arch_proc_fork().

◆ aarch64_fpsimd_load()

void aarch64_fpsimd_load ( const void * state)

◆ aarch64_fpsimd_restore()

void aarch64_fpsimd_restore ( struct thread * thread,
const void * state )

Gives a thread back the FP/SIMD state that a signal frame kept, for sigreturn().

The registers are loaded with it at their next use.

Parameters
threadthe thread
statethe state the frame kept, or NULL if it had none (the registers are then zeros)

Definition at line 151 of file fpsimd.c.

References aarch64_fpsimd_restore(), thread::arch, CPACR_FPEN_EL0_TRAP, fp_thread, fpen(), aarch64_thread::fpsimd, FPSIMD_STATE_SIZE, memcpy(), memset(), and NULL.

Referenced by aarch64_fpsimd_restore(), and arch_sigreturn().

◆ aarch64_fpsimd_save()

void aarch64_fpsimd_save ( void * state)

◆ aarch64_fpsimd_switch()

void aarch64_fpsimd_switch ( struct thread * thread)

Gets the registers ready for a thread that is about to run: its use of them traps, unless the registers already hold its values.

Parameters
threadthe thread about to run, or NULL

Definition at line 52 of file fpsimd.c.

References aarch64_fpsimd_switch(), CPACR_FPEN_EL0_TRAP, CPACR_FPEN_NONE, fp_thread, and fpen().

Referenced by aarch64_fpsimd_switch(), arch_thread_spawn(), and arch_thread_switch().

◆ aarch64_fpsimd_trap()

int aarch64_fpsimd_trap ( void )

Handles the trap of user mode's use of the registers: they get the running thread's values, and its use stops trapping.

Returns
0, or -ENOMEM if there was no memory for the thread's state

Definition at line 80 of file fpsimd.c.

References aarch64_fpsimd_load(), aarch64_fpsimd_save(), aarch64_fpsimd_trap(), thread::arch, CPACR_FPEN_NONE, curthread, fp_thread, fpen(), aarch64_thread::fpsimd, FPSIMD_STATE_SIZE, kmalloc(), and M_ZERO.

Referenced by aarch64_fpsimd_trap(), and sync_dispatch().

◆ fpen()

void fpen ( uint64_t v)
static

Sets CPACR_EL1.FPEN: whether user mode's use traps.

Definition at line 40 of file fpsimd.c.

References fpen(), isb, and write_sysreg.

Referenced by aarch64_fpsimd_drop(), aarch64_fpsimd_restore(), aarch64_fpsimd_switch(), aarch64_fpsimd_trap(), and fpen().