AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
cpu.h
Go to the documentation of this file.
1#ifndef _AARCH64_CPU_H
2#define _AARCH64_CPU_H
3
4#include <core/system.h>
5
13 uint64_t x[31]; /* x0 to x30 (x30 is the link register) */
14 uint64_t sp; /* SP_EL0: user mode's stack pointer */
15 uint64_t pc; /* ELR_EL1: where it goes on from */
16 uint64_t pstate; /* SPSR_EL1 */
18 uint64_t esr; /* ESR_EL1: why a synchronous exception came */
19};
20
21/* SPSR_EL1 and PSTATE's fields: the exception level and stack it returns
22 * to, and the interrupt masks (D, A, I, F). */
23#define PSTATE_EL0t 0x0
24#define PSTATE_EL1h 0x5
25#define PSTATE_MODE 0xF
26#define PSTATE_DAIF (0xF << 6)
27
28/* Whether the saved context was user mode's. */
29#define REGS_USER(r) (((r)->pstate & PSTATE_MODE) == PSTATE_EL0t)
30
31/* Reads, or writes, a system register. */
32
33#define read_sysreg(r) ({ \
34 uint64_t __v; \
35 asm volatile("mrs %0, " #r : "=r"(__v)); \
36 __v; \
37})
38
39#define write_sysreg(r, v) do { \
40 uint64_t __v = (uint64_t) (v); \
41 asm volatile("msr " #r ", %0" :: "r"(__v)); \
42} while (0)
43
44/* Barriers: an instruction barrier, and a full data barrier. */
45#define isb() asm volatile("isb" ::: "memory")
46#define dsb() asm volatile("dsb sy" ::: "memory")
47
48struct pmap;
49
51struct arch_cpu {
52 struct pmap *pmap; /* the address space in TTBR0_EL1 (pmap_switch()) */
53 int tick_switch; /* the tick asked for a thread switch */
54 struct thread *fp_thread; /* the thread whose FP/SIMD registers it has */
55 uintptr_t idle_stack; /* the top of the idle loop's stack */
56};
57
58struct cpu;
59
62static inline struct cpu *curcpu(void)
63{
64 return (struct cpu *) read_sysreg(tpidr_el1);
65}
66
67#include_next <cpu/cpu.h>
68
69#endif /* ! _AARCH64_CPU_H */
#define read_sysreg(r)
Definition cpu.h:33
static struct cpu * curcpu(void)
Returns the running CPU's struct cpu, which TPIDR_EL1, the register meant for it, holds.
Definition cpu.h:62
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
unsigned long long int uint64_t
Definition stddef.h:23
What an exception saves on the kernel stack (cpu/vectors.S): the context it interrupted.
Definition cpu.h:12
uint64_t pstate
Definition cpu.h:16
uint64_t orig_x0
Definition cpu.h:17
uint64_t sp
Definition cpu.h:14
uint64_t esr
Definition cpu.h:18
uint64_t pc
Definition cpu.h:15
uint64_t x[31]
Definition cpu.h:13
A CPU's aarch64 state (struct cpu's arch).
Definition cpu.h:51
struct thread * fp_thread
Definition cpu.h:54
int tick_switch
Definition cpu.h:53
uintptr_t idle_stack
Definition cpu.h:55
struct pmap * pmap
Definition cpu.h:52
A processor, and what runs on it.
Definition cpu.h:11
An address space's page tables, on x86.
Definition pmap.h:9
A thread.
Definition thread.h:23