AquilaOS documentation
How it works, and its code
Toggle main menu visibility
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
12
struct
aarch64_regs
{
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 */
17
uint64_t
orig_x0
;
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
48
struct
pmap
;
49
51
struct
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
58
struct
cpu
;
59
62
static
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 */
read_sysreg
#define read_sysreg(r)
Definition
cpu.h:33
curcpu
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
system.h
uintptr_t
__SIZE_TYPE__ uintptr_t
Definition
stddef.h:12
uint64_t
unsigned long long int uint64_t
Definition
stddef.h:23
aarch64_regs
What an exception saves on the kernel stack (cpu/vectors.S): the context it interrupted.
Definition
cpu.h:12
aarch64_regs::pstate
uint64_t pstate
Definition
cpu.h:16
aarch64_regs::orig_x0
uint64_t orig_x0
Definition
cpu.h:17
aarch64_regs::sp
uint64_t sp
Definition
cpu.h:14
aarch64_regs::esr
uint64_t esr
Definition
cpu.h:18
aarch64_regs::pc
uint64_t pc
Definition
cpu.h:15
aarch64_regs::x
uint64_t x[31]
Definition
cpu.h:13
arch_cpu
A CPU's aarch64 state (struct cpu's arch).
Definition
cpu.h:51
arch_cpu::fp_thread
struct thread * fp_thread
Definition
cpu.h:54
arch_cpu::tick_switch
int tick_switch
Definition
cpu.h:53
arch_cpu::idle_stack
uintptr_t idle_stack
Definition
cpu.h:55
arch_cpu::pmap
struct pmap * pmap
Definition
cpu.h:52
cpu
A processor, and what runs on it.
Definition
cpu.h:11
pmap
An address space's page tables, on x86.
Definition
pmap.h:9
thread
A thread.
Definition
thread.h:23
kernel
arch
aarch64
include
cpu
cpu.h
Generated by
1.18.0