AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
arch.h File Reference
#include <cpu/cpu.h>

Go to the source code of this file.

Data Structures

struct  aarch64_ctx
 Where a thread goes on in the kernel when it runs again: the registers that a function call keeps (AAPCS64: x19 to x29, and the link register), and the stack pointer. More...
struct  aarch64_thread
 A thread's aarch64 state (thread->arch). More...

Macros

#define FPSIMD_STATE_SIZE   528
#define USER_STACK   (0x0000800000000000UL)
#define USER_STACK_BASE   (USER_STACK - USER_STACK_SIZE)
#define SIGCODE_ADDR   (USER_STACK_BASE - 0x1000)
#define KERN_STACK_SIZE   (16384U)

Functions

int aarch64_ctx_save (struct aarch64_ctx *ctx)
void aarch64_ctx_load (struct aarch64_ctx *ctx)
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.
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_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.
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().
static void arch_interrupts_enable (void)
 Unmasks IRQs (DAIF.I).
static void arch_interrupts_disable (void)
 Masks IRQs.
void aarch64_jump_user (uintptr_t pc, uintptr_t sp, uintptr_t x0, uintptr_t x1, uintptr_t x2, uintptr_t kstack)
void aarch64_goto (uintptr_t fn, uintptr_t sp)
void aarch64_return_to_user (struct aarch64_regs *r, int syscall)
 Takes the current thread's signals on its way back to user mode, and restarts or fails the system call that a signal interrupted.
void arch_syscall (struct aarch64_regs *r)

Macro Definition Documentation

◆ FPSIMD_STATE_SIZE

#define FPSIMD_STATE_SIZE   528

Definition at line 44 of file arch.h.

Referenced by aarch64_fpsimd_fork(), aarch64_fpsimd_restore(), aarch64_fpsimd_trap(), and deliver().

◆ KERN_STACK_SIZE

#define KERN_STACK_SIZE   (16384U)

◆ SIGCODE_ADDR

#define SIGCODE_ADDR   (USER_STACK_BASE - 0x1000)

Definition at line 65 of file arch.h.

Referenced by arch_sigcode_map(), deliver(), and deliver().

◆ USER_STACK

#define USER_STACK   (0x0000800000000000UL)

Definition at line 60 of file arch.h.

Referenced by abort(), arch_proc_init(), exec_stack_build(), isr_dispatch(), and pmap_remove_all().

◆ USER_STACK_BASE

#define USER_STACK_BASE   (USER_STACK - USER_STACK_SIZE)

Definition at line 61 of file arch.h.

Referenced by binfmt_elf_load_segments(), binfmt_fmt_load(), and sys_sbrk().

Function Documentation

◆ aarch64_ctx_load()

void aarch64_ctx_load ( struct aarch64_ctx * ctx)

◆ aarch64_ctx_save()

int aarch64_ctx_save ( struct aarch64_ctx * ctx)

◆ 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_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_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().

◆ aarch64_goto()

◆ aarch64_jump_user()

void aarch64_jump_user ( uintptr_t pc,
uintptr_t sp,
uintptr_t x0,
uintptr_t x1,
uintptr_t x2,
uintptr_t kstack )

References aarch64_jump_user().

Referenced by aarch64_jump_user(), and thread_spawn().

◆ aarch64_return_to_user()

void aarch64_return_to_user ( struct aarch64_regs * r,
int syscall )

Takes the current thread's signals on its way back to user mode, and restarts or fails the system call that a signal interrupted.

Parameters
rthe user context saved on the kernel stack
syscallwhether the thread is returning from a system call

Definition at line 201 of file signal.c.

References aarch64_return_to_user(), thread::arch, curthread, deliver(), ERESTARTNOHAND, ERESTARTSYS, aarch64_regs::orig_x0, thread::owner, aarch64_regs::pc, REGS_USER, thread::restarting, thread::sig_oldmask, thread::sig_oldmask_set, proc::sigaction, proc::sigmask, signal_take(), and aarch64_regs::x.

Referenced by aarch64_goto(), aarch64_irq(), aarch64_return_to_user(), abort(), arch_syscall(), and sync_dispatch().

◆ arch_interrupts_disable()

void arch_interrupts_disable ( void )
inlinestatic

Masks IRQs.

Definition at line 77 of file arch.h.

References arch_interrupts_disable().

Referenced by arch_halt(), arch_interrupts_disable(), and proc_kill().

◆ arch_interrupts_enable()

void arch_interrupts_enable ( void )
inlinestatic

Unmasks IRQs (DAIF.I).

The kernel runs with them masked.

Definition at line 71 of file arch.h.

References arch_interrupts_enable().

Referenced by arch_interrupts_enable().

◆ arch_syscall()