AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
arch.h
Go to the documentation of this file.
1#ifndef _AARCH64_ARCH_H
2#define _AARCH64_ARCH_H
3
4#include <cpu/cpu.h>
5
15 uint64_t fp; /* x29 */
16 uint64_t lr; /* x30 */
18};
19
20/* Saves the current context, or switches to a saved one (cpu/switch.S). */
21int aarch64_ctx_save(struct aarch64_ctx *ctx) __attribute__((returns_twice));
22void aarch64_ctx_load(struct aarch64_ctx *ctx) __attribute__((noreturn));
23
26 uintptr_t kstack; /* the top of its kernel stack */
27 uintptr_t kstack_base; /* where its kernel stack was allocated */
28
29 struct aarch64_ctx ctx; /* where it was switched away from, in the kernel */
30
31 /* its user registers, saved at the top of its kernel stack when it
32 * entered the kernel */
34
35 /* for a thread that never ran, the user mode registers it starts
36 * with */
38
39 /* its FP/SIMD registers, once it has used them (cpu/fpsimd.c) */
40 void *fpsimd;
41};
42
43/* The size of the FP/SIMD state: v0 to v31, FPSR and FPCR. */
44#define FPSIMD_STATE_SIZE 528
45
46/* The FP/SIMD registers, switched lazily (cpu/fpsimd.c). */
47struct thread;
49int aarch64_fpsimd_trap(void);
52int aarch64_fpsimd_fork(struct thread *parent, struct aarch64_thread *child);
53void aarch64_fpsimd_restore(struct thread *thread, const void *state);
54
55MALLOC_DECLARE(M_AARCH64_THREAD);
56MALLOC_DECLARE(M_KERN_STACK);
57
58/* The top of the lower half of the address space, which is user space
59 * (48 bits), where the user stack ends, as on x86-64. */
60#define USER_STACK (0x0000800000000000UL)
61#define USER_STACK_BASE (USER_STACK - USER_STACK_SIZE)
62
63/* The page with the code that calls sigreturn() (sys/signal.c), below
64 * the stack. */
65#define SIGCODE_ADDR (USER_STACK_BASE - 0x1000)
66
67/* The size of a thread's kernel stack. */
68#define KERN_STACK_SIZE (16384U) /* 16 KiB */
69
71static inline void arch_interrupts_enable(void)
72{
73 asm volatile ("msr daifclr, #2" ::: "memory");
74}
75
77static inline void arch_interrupts_disable(void)
78{
79 asm volatile ("msr daifset, #2" ::: "memory");
80}
81
82/* Goes to user mode at `pc`, with `sp` and x0 to x2. `kstack` becomes the
83 * kernel stack that the next exception from user mode lands on. */
85 uintptr_t x2, uintptr_t kstack) __attribute__((noreturn));
86
87/* Runs `fn`, which must not return, on the kernel stack `sp`. */
88void aarch64_goto(uintptr_t fn, uintptr_t sp) __attribute__((noreturn));
89
90/* Delivers the signals and restarts the system call, on the way back to
91 * user mode (sys/signal.c). */
92void aarch64_return_to_user(struct aarch64_regs *r, int syscall);
93
94/* Runs a system call (sys/syscall.c). */
95void arch_syscall(struct aarch64_regs *r);
96
97#include_next <core/arch.h>
98
99#endif /* ! _AARCH64_ARCH_H */
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 cal...
Definition signal.c:201
int aarch64_ctx_save(struct aarch64_ctx *ctx)
void aarch64_jump_user(uintptr_t pc, uintptr_t sp, uintptr_t x0, uintptr_t x1, uintptr_t x2, uintptr_t kstack)
void arch_syscall(struct aarch64_regs *r)
Definition syscall.c:23
void aarch64_ctx_load(struct aarch64_ctx *ctx)
static void arch_interrupts_disable(void)
Masks IRQs.
Definition arch.h:77
void aarch64_goto(uintptr_t fn, uintptr_t sp)
static void arch_interrupts_enable(void)
Unmasks IRQs (DAIF.I).
Definition arch.h:71
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.
Definition fpsimd.c:64
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 ...
Definition fpsimd.c:106
void aarch64_fpsimd_switch(struct thread *thread)
Gets the registers ready for a thread that is about to run: its use of them traps,...
Definition fpsimd.c:52
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.
Definition fpsimd.c:129
int aarch64_fpsimd_trap(void)
Handles the trap of user mode's use of the registers: they get the running thread's values,...
Definition fpsimd.c:80
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().
Definition fpsimd.c:151
#define MALLOC_DECLARE(type)
Definition kvmem.h:29
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
unsigned long long int uint64_t
Definition stddef.h:23
Where a thread goes on in the kernel when it runs again: the registers that a function call keeps (AA...
Definition arch.h:13
uint64_t x26
Definition arch.h:14
uint64_t lr
Definition arch.h:16
uint64_t sp
Definition arch.h:17
uint64_t x22
Definition arch.h:14
uint64_t x19
Definition arch.h:14
uint64_t x25
Definition arch.h:14
uint64_t x28
Definition arch.h:14
uint64_t x27
Definition arch.h:14
uint64_t fp
Definition arch.h:15
uint64_t x20
Definition arch.h:14
uint64_t x21
Definition arch.h:14
uint64_t x23
Definition arch.h:14
uint64_t x24
Definition arch.h:14
What an exception saves on the kernel stack (cpu/vectors.S): the context it interrupted.
Definition cpu.h:12
A thread's aarch64 state (thread->arch).
Definition arch.h:25
uint64_t x1
Definition arch.h:37
uint64_t sp
Definition arch.h:37
struct aarch64_ctx ctx
Definition arch.h:29
uint64_t x0
Definition arch.h:37
uintptr_t kstack_base
Definition arch.h:27
uint64_t x2
Definition arch.h:37
uintptr_t kstack
Definition arch.h:26
struct aarch64_regs * regs
Definition arch.h:33
uint64_t pc
Definition arch.h:37
void * fpsimd
Definition arch.h:40
A thread.
Definition thread.h:23
state_t state
its state
Definition thread.h:28