FreeNOS
ARM64Control.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Ivan Tan
3 * Copyright (C) 2015 Niek Linnenbank
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef __ARM64_CONTROL_H
20#define __ARM64_CONTROL_H
21
22#include <Types.h>
23#include <Macros.h>
24
48namespace ARM64Control
49{
85
86
91 {
93 SMPBit = (1 << 6)
94 };
95
104
112 u64 read(Register reg);
113
120 void write(Register reg, u64 value);
121
128
135};
136
143/* Macros for registers
144 *
145 */
146
147//AArch64 Memory Model Feature Register 0
148//https://developer.arm.com/documentation/ddi0601/2025-03/AArch64-Registers/ID-AA64MMFR0-EL1--AArch64-Memory-Model-Feature-Register-0
149#define PA_RANGE(r) ((r)&0xF) //Physical Address range supported.
150#define TGRAN4(r) (((r)>>28)&0xF) //Indicates support for 4KB memory translation granule size.
151
152#define tlb_invalidate(virt) \
153({ \
154 asm volatile ("dsb ishst\n"\
155 "tlbi vaae1is, %0\n" \
156 "dsb ish\n" \
157 "isb" : : "r" (virt>>12UL) );\
158})
159
163#define isb() { asm volatile ("isb" ::: "memory"); }
164
173#define dsb(type) { asm volatile ("dsb "#type ::: "memory"); }
174
183//FIXME: sy isn't appropriate for all scenarioes
184#define dmb() { asm volatile ("dmb sy" ::: "memory"); }
185
186#define enable_interrupt() { asm volatile ("msr daifclr, #2") ; }
187#define disable_interrupt() { asm volatile ("msr daifset, #2") ; }
188
194#define timestamp() 0
195
199#define cpu_reboot()
200
207#define cpu_shutdown()
208
212#define idle() \
213 asm volatile ("wfi")
214
219 enum {
220 MMUEnabled = (1 << 0),
222 Stage1Cache = (1 << 2),
223 SA = (1 << 2), // SP Alignment check enable
224 SA0 = (1 << 3), // SP Alignment check enable for EL0
225 InstrCache = (1 << 12),
226 WXN = (1 << 19), // Write permission implies XN (Execute-never).
227 E0E = (1 << 24), // Endianness of data accesses at EL0.
228 EE = (1 << 25), //Endianness of data accesses at EL1, and stage 1 translation table walks in the EL1&0 translation regime.
229 };
230};
231
235typedef struct CPUState
236{
237 u64 x0, x1, x2, x3, x4, x5;
240 u64 x17, x18, fp, lr, sp; //sp_el0
242}
243ALIGN(8) CPUState;
244
245#define exception_code(esr) (((esr)>>26)&0x3f)
246
247#endif /* __ARM64_CONTROL_H */
u32 flags
Definition IntelACPI.h:3
unsigned long long u64
Unsigned 64-bit number.
Definition Types.h:50
#define ALIGN(n)
Aligns a symbol at the given boundary.
Definition Macros.h:167
ARM64 System Control Coprocessor (CP15).
u64 read(Register reg)
Read a register from the CP15.
void write(Register reg, u64 value)
Write register to the CP15.
DomainControlFlags
Domain Control flags.
AuxControlFlags
Aux Control flags.
Register
System Control Registers.
@ InstructionFaultAddress
void set(Register reg, u64 flags)
System Control flags.
Contains all the CPU registers.
Definition ARMCore.h:244
u32 pc
Definition ARMCore.h:249
u32 sp
Definition ARMCore.h:247
u32 lr
Definition ARMCore.h:247