target-arm: make TTBCR banked
[qemu/ar7.git] / target-arm / cpu.h
blob0eaf981b58406671d97501eb4743e5970e2a98b4
1 /*
2 * ARM virtual CPU header
4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #ifndef CPU_ARM_H
20 #define CPU_ARM_H
22 #include "config.h"
24 #include "kvm-consts.h"
26 #if defined(TARGET_AARCH64)
27 /* AArch64 definitions */
28 # define TARGET_LONG_BITS 64
29 # define ELF_MACHINE EM_AARCH64
30 #else
31 # define TARGET_LONG_BITS 32
32 # define ELF_MACHINE EM_ARM
33 #endif
35 #define CPUArchState struct CPUARMState
37 #include "qemu-common.h"
38 #include "exec/cpu-defs.h"
40 #include "fpu/softfloat.h"
42 #define TARGET_HAS_ICE 1
44 #define EXCP_UDEF 1 /* undefined instruction */
45 #define EXCP_SWI 2 /* software interrupt */
46 #define EXCP_PREFETCH_ABORT 3
47 #define EXCP_DATA_ABORT 4
48 #define EXCP_IRQ 5
49 #define EXCP_FIQ 6
50 #define EXCP_BKPT 7
51 #define EXCP_EXCEPTION_EXIT 8 /* Return from v7M exception. */
52 #define EXCP_KERNEL_TRAP 9 /* Jumped to kernel code page. */
53 #define EXCP_STREX 10
54 #define EXCP_HVC 11 /* HyperVisor Call */
55 #define EXCP_HYP_TRAP 12
56 #define EXCP_SMC 13 /* Secure Monitor Call */
57 #define EXCP_VIRQ 14
58 #define EXCP_VFIQ 15
60 #define ARMV7M_EXCP_RESET 1
61 #define ARMV7M_EXCP_NMI 2
62 #define ARMV7M_EXCP_HARD 3
63 #define ARMV7M_EXCP_MEM 4
64 #define ARMV7M_EXCP_BUS 5
65 #define ARMV7M_EXCP_USAGE 6
66 #define ARMV7M_EXCP_SVC 11
67 #define ARMV7M_EXCP_DEBUG 12
68 #define ARMV7M_EXCP_PENDSV 14
69 #define ARMV7M_EXCP_SYSTICK 15
71 /* ARM-specific interrupt pending bits. */
72 #define CPU_INTERRUPT_FIQ CPU_INTERRUPT_TGT_EXT_1
73 #define CPU_INTERRUPT_VIRQ CPU_INTERRUPT_TGT_EXT_2
74 #define CPU_INTERRUPT_VFIQ CPU_INTERRUPT_TGT_EXT_3
76 /* The usual mapping for an AArch64 system register to its AArch32
77 * counterpart is for the 32 bit world to have access to the lower
78 * half only (with writes leaving the upper half untouched). It's
79 * therefore useful to be able to pass TCG the offset of the least
80 * significant half of a uint64_t struct member.
82 #ifdef HOST_WORDS_BIGENDIAN
83 #define offsetoflow32(S, M) (offsetof(S, M) + sizeof(uint32_t))
84 #define offsetofhigh32(S, M) offsetof(S, M)
85 #else
86 #define offsetoflow32(S, M) offsetof(S, M)
87 #define offsetofhigh32(S, M) (offsetof(S, M) + sizeof(uint32_t))
88 #endif
90 /* Meanings of the ARMCPU object's four inbound GPIO lines */
91 #define ARM_CPU_IRQ 0
92 #define ARM_CPU_FIQ 1
93 #define ARM_CPU_VIRQ 2
94 #define ARM_CPU_VFIQ 3
96 typedef void ARMWriteCPFunc(void *opaque, int cp_info,
97 int srcreg, int operand, uint32_t value);
98 typedef uint32_t ARMReadCPFunc(void *opaque, int cp_info,
99 int dstreg, int operand);
101 struct arm_boot_info;
103 #define NB_MMU_MODES 4
105 /* We currently assume float and double are IEEE single and double
106 precision respectively.
107 Doing runtime conversions is tricky because VFP registers may contain
108 integer values (eg. as the result of a FTOSI instruction).
109 s<2n> maps to the least significant half of d<n>
110 s<2n+1> maps to the most significant half of d<n>
113 /* CPU state for each instance of a generic timer (in cp15 c14) */
114 typedef struct ARMGenericTimer {
115 uint64_t cval; /* Timer CompareValue register */
116 uint64_t ctl; /* Timer Control register */
117 } ARMGenericTimer;
119 #define GTIMER_PHYS 0
120 #define GTIMER_VIRT 1
121 #define NUM_GTIMERS 2
123 typedef struct {
124 uint64_t raw_tcr;
125 uint32_t mask;
126 uint32_t base_mask;
127 } TCR;
129 typedef struct CPUARMState {
130 /* Regs for current mode. */
131 uint32_t regs[16];
133 /* 32/64 switch only happens when taking and returning from
134 * exceptions so the overlap semantics are taken care of then
135 * instead of having a complicated union.
137 /* Regs for A64 mode. */
138 uint64_t xregs[32];
139 uint64_t pc;
140 /* PSTATE isn't an architectural register for ARMv8. However, it is
141 * convenient for us to assemble the underlying state into a 32 bit format
142 * identical to the architectural format used for the SPSR. (This is also
143 * what the Linux kernel's 'pstate' field in signal handlers and KVM's
144 * 'pstate' register are.) Of the PSTATE bits:
145 * NZCV are kept in the split out env->CF/VF/NF/ZF, (which have the same
146 * semantics as for AArch32, as described in the comments on each field)
147 * nRW (also known as M[4]) is kept, inverted, in env->aarch64
148 * DAIF (exception masks) are kept in env->daif
149 * all other bits are stored in their correct places in env->pstate
151 uint32_t pstate;
152 uint32_t aarch64; /* 1 if CPU is in aarch64 state; inverse of PSTATE.nRW */
154 /* Frequently accessed CPSR bits are stored separately for efficiency.
155 This contains all the other bits. Use cpsr_{read,write} to access
156 the whole CPSR. */
157 uint32_t uncached_cpsr;
158 uint32_t spsr;
160 /* Banked registers. */
161 uint64_t banked_spsr[8];
162 uint32_t banked_r13[8];
163 uint32_t banked_r14[8];
165 /* These hold r8-r12. */
166 uint32_t usr_regs[5];
167 uint32_t fiq_regs[5];
169 /* cpsr flag cache for faster execution */
170 uint32_t CF; /* 0 or 1 */
171 uint32_t VF; /* V is the bit 31. All other bits are undefined */
172 uint32_t NF; /* N is bit 31. All other bits are undefined. */
173 uint32_t ZF; /* Z set if zero. */
174 uint32_t QF; /* 0 or 1 */
175 uint32_t GE; /* cpsr[19:16] */
176 uint32_t thumb; /* cpsr[5]. 0 = arm mode, 1 = thumb mode. */
177 uint32_t condexec_bits; /* IT bits. cpsr[15:10,26:25]. */
178 uint64_t daif; /* exception masks, in the bits they are in in PSTATE */
180 uint64_t elr_el[4]; /* AArch64 exception link regs */
181 uint64_t sp_el[4]; /* AArch64 banked stack pointers */
183 /* System control coprocessor (cp15) */
184 struct {
185 uint32_t c0_cpuid;
186 union { /* Cache size selection */
187 struct {
188 uint64_t _unused_csselr0;
189 uint64_t csselr_ns;
190 uint64_t _unused_csselr1;
191 uint64_t csselr_s;
193 uint64_t csselr_el[4];
195 union { /* System control register. */
196 struct {
197 uint64_t _unused_sctlr;
198 uint64_t sctlr_ns;
199 uint64_t hsctlr;
200 uint64_t sctlr_s;
202 uint64_t sctlr_el[4];
204 uint64_t c1_coproc; /* Coprocessor access register. */
205 uint32_t c1_xscaleauxcr; /* XScale auxiliary control register. */
206 uint64_t sder; /* Secure debug enable register. */
207 uint32_t nsacr; /* Non-secure access control register. */
208 union { /* MMU translation table base 0. */
209 struct {
210 uint64_t _unused_ttbr0_0;
211 uint64_t ttbr0_ns;
212 uint64_t _unused_ttbr0_1;
213 uint64_t ttbr0_s;
215 uint64_t ttbr0_el[4];
217 union { /* MMU translation table base 1. */
218 struct {
219 uint64_t _unused_ttbr1_0;
220 uint64_t ttbr1_ns;
221 uint64_t _unused_ttbr1_1;
222 uint64_t ttbr1_s;
224 uint64_t ttbr1_el[4];
226 /* MMU translation table base control. */
227 TCR tcr_el[4];
228 uint32_t c2_data; /* MPU data cachable bits. */
229 uint32_t c2_insn; /* MPU instruction cachable bits. */
230 uint32_t c3; /* MMU domain access control register
231 MPU write buffer control. */
232 uint32_t pmsav5_data_ap; /* PMSAv5 MPU data access permissions */
233 uint32_t pmsav5_insn_ap; /* PMSAv5 MPU insn access permissions */
234 uint64_t hcr_el2; /* Hypervisor configuration register */
235 uint64_t scr_el3; /* Secure configuration register. */
236 uint32_t ifsr_el2; /* Fault status registers. */
237 uint64_t esr_el[4];
238 uint32_t c6_region[8]; /* MPU base/size registers. */
239 uint64_t far_el[4]; /* Fault address registers. */
240 uint64_t par_el1; /* Translation result. */
241 uint32_t c9_insn; /* Cache lockdown registers. */
242 uint32_t c9_data;
243 uint64_t c9_pmcr; /* performance monitor control register */
244 uint64_t c9_pmcnten; /* perf monitor counter enables */
245 uint32_t c9_pmovsr; /* perf monitor overflow status */
246 uint32_t c9_pmxevtyper; /* perf monitor event type */
247 uint32_t c9_pmuserenr; /* perf monitor user enable */
248 uint32_t c9_pminten; /* perf monitor interrupt enables */
249 uint64_t mair_el1;
250 uint64_t vbar_el[4]; /* vector base address register */
251 uint32_t mvbar; /* (monitor) vector base address register */
252 uint32_t c13_fcse; /* FCSE PID. */
253 uint64_t contextidr_el1; /* Context ID. */
254 uint64_t tpidr_el0; /* User RW Thread register. */
255 uint64_t tpidrro_el0; /* User RO Thread register. */
256 uint64_t tpidr_el1; /* Privileged Thread register. */
257 uint64_t c14_cntfrq; /* Counter Frequency register */
258 uint64_t c14_cntkctl; /* Timer Control register */
259 ARMGenericTimer c14_timer[NUM_GTIMERS];
260 uint32_t c15_cpar; /* XScale Coprocessor Access Register */
261 uint32_t c15_ticonfig; /* TI925T configuration byte. */
262 uint32_t c15_i_max; /* Maximum D-cache dirty line index. */
263 uint32_t c15_i_min; /* Minimum D-cache dirty line index. */
264 uint32_t c15_threadid; /* TI debugger thread-ID. */
265 uint32_t c15_config_base_address; /* SCU base address. */
266 uint32_t c15_diagnostic; /* diagnostic register */
267 uint32_t c15_power_diagnostic;
268 uint32_t c15_power_control; /* power control */
269 uint64_t dbgbvr[16]; /* breakpoint value registers */
270 uint64_t dbgbcr[16]; /* breakpoint control registers */
271 uint64_t dbgwvr[16]; /* watchpoint value registers */
272 uint64_t dbgwcr[16]; /* watchpoint control registers */
273 uint64_t mdscr_el1;
274 /* If the counter is enabled, this stores the last time the counter
275 * was reset. Otherwise it stores the counter value
277 uint64_t c15_ccnt;
278 uint64_t pmccfiltr_el0; /* Performance Monitor Filter Register */
279 } cp15;
281 struct {
282 uint32_t other_sp;
283 uint32_t vecbase;
284 uint32_t basepri;
285 uint32_t control;
286 int current_sp;
287 int exception;
288 int pending_exception;
289 } v7m;
291 /* Information associated with an exception about to be taken:
292 * code which raises an exception must set cs->exception_index and
293 * the relevant parts of this structure; the cpu_do_interrupt function
294 * will then set the guest-visible registers as part of the exception
295 * entry process.
297 struct {
298 uint32_t syndrome; /* AArch64 format syndrome register */
299 uint32_t fsr; /* AArch32 format fault status register info */
300 uint64_t vaddress; /* virtual addr associated with exception, if any */
301 /* If we implement EL2 we will also need to store information
302 * about the intermediate physical address for stage 2 faults.
304 } exception;
306 /* Thumb-2 EE state. */
307 uint32_t teecr;
308 uint32_t teehbr;
310 /* VFP coprocessor state. */
311 struct {
312 /* VFP/Neon register state. Note that the mapping between S, D and Q
313 * views of the register bank differs between AArch64 and AArch32:
314 * In AArch32:
315 * Qn = regs[2n+1]:regs[2n]
316 * Dn = regs[n]
317 * Sn = regs[n/2] bits 31..0 for even n, and bits 63..32 for odd n
318 * (and regs[32] to regs[63] are inaccessible)
319 * In AArch64:
320 * Qn = regs[2n+1]:regs[2n]
321 * Dn = regs[2n]
322 * Sn = regs[2n] bits 31..0
323 * This corresponds to the architecturally defined mapping between
324 * the two execution states, and means we do not need to explicitly
325 * map these registers when changing states.
327 float64 regs[64];
329 uint32_t xregs[16];
330 /* We store these fpcsr fields separately for convenience. */
331 int vec_len;
332 int vec_stride;
334 /* scratch space when Tn are not sufficient. */
335 uint32_t scratch[8];
337 /* fp_status is the "normal" fp status. standard_fp_status retains
338 * values corresponding to the ARM "Standard FPSCR Value", ie
339 * default-NaN, flush-to-zero, round-to-nearest and is used by
340 * any operations (generally Neon) which the architecture defines
341 * as controlled by the standard FPSCR value rather than the FPSCR.
343 * To avoid having to transfer exception bits around, we simply
344 * say that the FPSCR cumulative exception flags are the logical
345 * OR of the flags in the two fp statuses. This relies on the
346 * only thing which needs to read the exception flags being
347 * an explicit FPSCR read.
349 float_status fp_status;
350 float_status standard_fp_status;
351 } vfp;
352 uint64_t exclusive_addr;
353 uint64_t exclusive_val;
354 uint64_t exclusive_high;
355 #if defined(CONFIG_USER_ONLY)
356 uint64_t exclusive_test;
357 uint32_t exclusive_info;
358 #endif
360 /* iwMMXt coprocessor state. */
361 struct {
362 uint64_t regs[16];
363 uint64_t val;
365 uint32_t cregs[16];
366 } iwmmxt;
368 /* For mixed endian mode. */
369 bool bswap_code;
371 #if defined(CONFIG_USER_ONLY)
372 /* For usermode syscall translation. */
373 int eabi;
374 #endif
376 struct CPUBreakpoint *cpu_breakpoint[16];
377 struct CPUWatchpoint *cpu_watchpoint[16];
379 CPU_COMMON
381 /* These fields after the common ones so they are preserved on reset. */
383 /* Internal CPU feature flags. */
384 uint64_t features;
386 void *nvic;
387 const struct arm_boot_info *boot_info;
388 } CPUARMState;
390 #include "cpu-qom.h"
392 ARMCPU *cpu_arm_init(const char *cpu_model);
393 int cpu_arm_exec(CPUARMState *s);
394 uint32_t do_arm_semihosting(CPUARMState *env);
396 static inline bool is_a64(CPUARMState *env)
398 return env->aarch64;
401 /* you can call this signal handler from your SIGBUS and SIGSEGV
402 signal handlers to inform the virtual CPU of exceptions. non zero
403 is returned if the signal was handled by the virtual CPU. */
404 int cpu_arm_signal_handler(int host_signum, void *pinfo,
405 void *puc);
406 int arm_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw,
407 int mmu_idx);
410 * pmccntr_sync
411 * @env: CPUARMState
413 * Synchronises the counter in the PMCCNTR. This must always be called twice,
414 * once before any action that might affect the timer and again afterwards.
415 * The function is used to swap the state of the register if required.
416 * This only happens when not in user mode (!CONFIG_USER_ONLY)
418 void pmccntr_sync(CPUARMState *env);
420 /* SCTLR bit meanings. Several bits have been reused in newer
421 * versions of the architecture; in that case we define constants
422 * for both old and new bit meanings. Code which tests against those
423 * bits should probably check or otherwise arrange that the CPU
424 * is the architectural version it expects.
426 #define SCTLR_M (1U << 0)
427 #define SCTLR_A (1U << 1)
428 #define SCTLR_C (1U << 2)
429 #define SCTLR_W (1U << 3) /* up to v6; RAO in v7 */
430 #define SCTLR_SA (1U << 3)
431 #define SCTLR_P (1U << 4) /* up to v5; RAO in v6 and v7 */
432 #define SCTLR_SA0 (1U << 4) /* v8 onward, AArch64 only */
433 #define SCTLR_D (1U << 5) /* up to v5; RAO in v6 */
434 #define SCTLR_CP15BEN (1U << 5) /* v7 onward */
435 #define SCTLR_L (1U << 6) /* up to v5; RAO in v6 and v7; RAZ in v8 */
436 #define SCTLR_B (1U << 7) /* up to v6; RAZ in v7 */
437 #define SCTLR_ITD (1U << 7) /* v8 onward */
438 #define SCTLR_S (1U << 8) /* up to v6; RAZ in v7 */
439 #define SCTLR_SED (1U << 8) /* v8 onward */
440 #define SCTLR_R (1U << 9) /* up to v6; RAZ in v7 */
441 #define SCTLR_UMA (1U << 9) /* v8 onward, AArch64 only */
442 #define SCTLR_F (1U << 10) /* up to v6 */
443 #define SCTLR_SW (1U << 10) /* v7 onward */
444 #define SCTLR_Z (1U << 11)
445 #define SCTLR_I (1U << 12)
446 #define SCTLR_V (1U << 13)
447 #define SCTLR_RR (1U << 14) /* up to v7 */
448 #define SCTLR_DZE (1U << 14) /* v8 onward, AArch64 only */
449 #define SCTLR_L4 (1U << 15) /* up to v6; RAZ in v7 */
450 #define SCTLR_UCT (1U << 15) /* v8 onward, AArch64 only */
451 #define SCTLR_DT (1U << 16) /* up to ??, RAO in v6 and v7 */
452 #define SCTLR_nTWI (1U << 16) /* v8 onward */
453 #define SCTLR_HA (1U << 17)
454 #define SCTLR_IT (1U << 18) /* up to ??, RAO in v6 and v7 */
455 #define SCTLR_nTWE (1U << 18) /* v8 onward */
456 #define SCTLR_WXN (1U << 19)
457 #define SCTLR_ST (1U << 20) /* up to ??, RAZ in v6 */
458 #define SCTLR_UWXN (1U << 20) /* v7 onward */
459 #define SCTLR_FI (1U << 21)
460 #define SCTLR_U (1U << 22)
461 #define SCTLR_XP (1U << 23) /* up to v6; v7 onward RAO */
462 #define SCTLR_VE (1U << 24) /* up to v7 */
463 #define SCTLR_E0E (1U << 24) /* v8 onward, AArch64 only */
464 #define SCTLR_EE (1U << 25)
465 #define SCTLR_L2 (1U << 26) /* up to v6, RAZ in v7 */
466 #define SCTLR_UCI (1U << 26) /* v8 onward, AArch64 only */
467 #define SCTLR_NMFI (1U << 27)
468 #define SCTLR_TRE (1U << 28)
469 #define SCTLR_AFE (1U << 29)
470 #define SCTLR_TE (1U << 30)
472 #define CPSR_M (0x1fU)
473 #define CPSR_T (1U << 5)
474 #define CPSR_F (1U << 6)
475 #define CPSR_I (1U << 7)
476 #define CPSR_A (1U << 8)
477 #define CPSR_E (1U << 9)
478 #define CPSR_IT_2_7 (0xfc00U)
479 #define CPSR_GE (0xfU << 16)
480 #define CPSR_IL (1U << 20)
481 /* Note that the RESERVED bits include bit 21, which is PSTATE_SS in
482 * an AArch64 SPSR but RES0 in AArch32 SPSR and CPSR. In QEMU we use
483 * env->uncached_cpsr bit 21 to store PSTATE.SS when executing in AArch32,
484 * where it is live state but not accessible to the AArch32 code.
486 #define CPSR_RESERVED (0x7U << 21)
487 #define CPSR_J (1U << 24)
488 #define CPSR_IT_0_1 (3U << 25)
489 #define CPSR_Q (1U << 27)
490 #define CPSR_V (1U << 28)
491 #define CPSR_C (1U << 29)
492 #define CPSR_Z (1U << 30)
493 #define CPSR_N (1U << 31)
494 #define CPSR_NZCV (CPSR_N | CPSR_Z | CPSR_C | CPSR_V)
495 #define CPSR_AIF (CPSR_A | CPSR_I | CPSR_F)
497 #define CPSR_IT (CPSR_IT_0_1 | CPSR_IT_2_7)
498 #define CACHED_CPSR_BITS (CPSR_T | CPSR_AIF | CPSR_GE | CPSR_IT | CPSR_Q \
499 | CPSR_NZCV)
500 /* Bits writable in user mode. */
501 #define CPSR_USER (CPSR_NZCV | CPSR_Q | CPSR_GE)
502 /* Execution state bits. MRS read as zero, MSR writes ignored. */
503 #define CPSR_EXEC (CPSR_T | CPSR_IT | CPSR_J | CPSR_IL)
504 /* Mask of bits which may be set by exception return copying them from SPSR */
505 #define CPSR_ERET_MASK (~CPSR_RESERVED)
507 #define TTBCR_N (7U << 0) /* TTBCR.EAE==0 */
508 #define TTBCR_T0SZ (7U << 0) /* TTBCR.EAE==1 */
509 #define TTBCR_PD0 (1U << 4)
510 #define TTBCR_PD1 (1U << 5)
511 #define TTBCR_EPD0 (1U << 7)
512 #define TTBCR_IRGN0 (3U << 8)
513 #define TTBCR_ORGN0 (3U << 10)
514 #define TTBCR_SH0 (3U << 12)
515 #define TTBCR_T1SZ (3U << 16)
516 #define TTBCR_A1 (1U << 22)
517 #define TTBCR_EPD1 (1U << 23)
518 #define TTBCR_IRGN1 (3U << 24)
519 #define TTBCR_ORGN1 (3U << 26)
520 #define TTBCR_SH1 (1U << 28)
521 #define TTBCR_EAE (1U << 31)
523 /* Bit definitions for ARMv8 SPSR (PSTATE) format.
524 * Only these are valid when in AArch64 mode; in
525 * AArch32 mode SPSRs are basically CPSR-format.
527 #define PSTATE_SP (1U)
528 #define PSTATE_M (0xFU)
529 #define PSTATE_nRW (1U << 4)
530 #define PSTATE_F (1U << 6)
531 #define PSTATE_I (1U << 7)
532 #define PSTATE_A (1U << 8)
533 #define PSTATE_D (1U << 9)
534 #define PSTATE_IL (1U << 20)
535 #define PSTATE_SS (1U << 21)
536 #define PSTATE_V (1U << 28)
537 #define PSTATE_C (1U << 29)
538 #define PSTATE_Z (1U << 30)
539 #define PSTATE_N (1U << 31)
540 #define PSTATE_NZCV (PSTATE_N | PSTATE_Z | PSTATE_C | PSTATE_V)
541 #define PSTATE_DAIF (PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F)
542 #define CACHED_PSTATE_BITS (PSTATE_NZCV | PSTATE_DAIF)
543 /* Mode values for AArch64 */
544 #define PSTATE_MODE_EL3h 13
545 #define PSTATE_MODE_EL3t 12
546 #define PSTATE_MODE_EL2h 9
547 #define PSTATE_MODE_EL2t 8
548 #define PSTATE_MODE_EL1h 5
549 #define PSTATE_MODE_EL1t 4
550 #define PSTATE_MODE_EL0t 0
552 /* Map EL and handler into a PSTATE_MODE. */
553 static inline unsigned int aarch64_pstate_mode(unsigned int el, bool handler)
555 return (el << 2) | handler;
558 /* Return the current PSTATE value. For the moment we don't support 32<->64 bit
559 * interprocessing, so we don't attempt to sync with the cpsr state used by
560 * the 32 bit decoder.
562 static inline uint32_t pstate_read(CPUARMState *env)
564 int ZF;
566 ZF = (env->ZF == 0);
567 return (env->NF & 0x80000000) | (ZF << 30)
568 | (env->CF << 29) | ((env->VF & 0x80000000) >> 3)
569 | env->pstate | env->daif;
572 static inline void pstate_write(CPUARMState *env, uint32_t val)
574 env->ZF = (~val) & PSTATE_Z;
575 env->NF = val;
576 env->CF = (val >> 29) & 1;
577 env->VF = (val << 3) & 0x80000000;
578 env->daif = val & PSTATE_DAIF;
579 env->pstate = val & ~CACHED_PSTATE_BITS;
582 /* Return the current CPSR value. */
583 uint32_t cpsr_read(CPUARMState *env);
584 /* Set the CPSR. Note that some bits of mask must be all-set or all-clear. */
585 void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask);
587 /* Return the current xPSR value. */
588 static inline uint32_t xpsr_read(CPUARMState *env)
590 int ZF;
591 ZF = (env->ZF == 0);
592 return (env->NF & 0x80000000) | (ZF << 30)
593 | (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | (env->QF << 27)
594 | (env->thumb << 24) | ((env->condexec_bits & 3) << 25)
595 | ((env->condexec_bits & 0xfc) << 8)
596 | env->v7m.exception;
599 /* Set the xPSR. Note that some bits of mask must be all-set or all-clear. */
600 static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
602 if (mask & CPSR_NZCV) {
603 env->ZF = (~val) & CPSR_Z;
604 env->NF = val;
605 env->CF = (val >> 29) & 1;
606 env->VF = (val << 3) & 0x80000000;
608 if (mask & CPSR_Q)
609 env->QF = ((val & CPSR_Q) != 0);
610 if (mask & (1 << 24))
611 env->thumb = ((val & (1 << 24)) != 0);
612 if (mask & CPSR_IT_0_1) {
613 env->condexec_bits &= ~3;
614 env->condexec_bits |= (val >> 25) & 3;
616 if (mask & CPSR_IT_2_7) {
617 env->condexec_bits &= 3;
618 env->condexec_bits |= (val >> 8) & 0xfc;
620 if (mask & 0x1ff) {
621 env->v7m.exception = val & 0x1ff;
625 #define HCR_VM (1ULL << 0)
626 #define HCR_SWIO (1ULL << 1)
627 #define HCR_PTW (1ULL << 2)
628 #define HCR_FMO (1ULL << 3)
629 #define HCR_IMO (1ULL << 4)
630 #define HCR_AMO (1ULL << 5)
631 #define HCR_VF (1ULL << 6)
632 #define HCR_VI (1ULL << 7)
633 #define HCR_VSE (1ULL << 8)
634 #define HCR_FB (1ULL << 9)
635 #define HCR_BSU_MASK (3ULL << 10)
636 #define HCR_DC (1ULL << 12)
637 #define HCR_TWI (1ULL << 13)
638 #define HCR_TWE (1ULL << 14)
639 #define HCR_TID0 (1ULL << 15)
640 #define HCR_TID1 (1ULL << 16)
641 #define HCR_TID2 (1ULL << 17)
642 #define HCR_TID3 (1ULL << 18)
643 #define HCR_TSC (1ULL << 19)
644 #define HCR_TIDCP (1ULL << 20)
645 #define HCR_TACR (1ULL << 21)
646 #define HCR_TSW (1ULL << 22)
647 #define HCR_TPC (1ULL << 23)
648 #define HCR_TPU (1ULL << 24)
649 #define HCR_TTLB (1ULL << 25)
650 #define HCR_TVM (1ULL << 26)
651 #define HCR_TGE (1ULL << 27)
652 #define HCR_TDZ (1ULL << 28)
653 #define HCR_HCD (1ULL << 29)
654 #define HCR_TRVM (1ULL << 30)
655 #define HCR_RW (1ULL << 31)
656 #define HCR_CD (1ULL << 32)
657 #define HCR_ID (1ULL << 33)
658 #define HCR_MASK ((1ULL << 34) - 1)
660 #define SCR_NS (1U << 0)
661 #define SCR_IRQ (1U << 1)
662 #define SCR_FIQ (1U << 2)
663 #define SCR_EA (1U << 3)
664 #define SCR_FW (1U << 4)
665 #define SCR_AW (1U << 5)
666 #define SCR_NET (1U << 6)
667 #define SCR_SMD (1U << 7)
668 #define SCR_HCE (1U << 8)
669 #define SCR_SIF (1U << 9)
670 #define SCR_RW (1U << 10)
671 #define SCR_ST (1U << 11)
672 #define SCR_TWI (1U << 12)
673 #define SCR_TWE (1U << 13)
674 #define SCR_AARCH32_MASK (0x3fff & ~(SCR_RW | SCR_ST))
675 #define SCR_AARCH64_MASK (0x3fff & ~SCR_NET)
677 /* Return the current FPSCR value. */
678 uint32_t vfp_get_fpscr(CPUARMState *env);
679 void vfp_set_fpscr(CPUARMState *env, uint32_t val);
681 /* For A64 the FPSCR is split into two logically distinct registers,
682 * FPCR and FPSR. However since they still use non-overlapping bits
683 * we store the underlying state in fpscr and just mask on read/write.
685 #define FPSR_MASK 0xf800009f
686 #define FPCR_MASK 0x07f79f00
687 static inline uint32_t vfp_get_fpsr(CPUARMState *env)
689 return vfp_get_fpscr(env) & FPSR_MASK;
692 static inline void vfp_set_fpsr(CPUARMState *env, uint32_t val)
694 uint32_t new_fpscr = (vfp_get_fpscr(env) & ~FPSR_MASK) | (val & FPSR_MASK);
695 vfp_set_fpscr(env, new_fpscr);
698 static inline uint32_t vfp_get_fpcr(CPUARMState *env)
700 return vfp_get_fpscr(env) & FPCR_MASK;
703 static inline void vfp_set_fpcr(CPUARMState *env, uint32_t val)
705 uint32_t new_fpscr = (vfp_get_fpscr(env) & ~FPCR_MASK) | (val & FPCR_MASK);
706 vfp_set_fpscr(env, new_fpscr);
709 enum arm_cpu_mode {
710 ARM_CPU_MODE_USR = 0x10,
711 ARM_CPU_MODE_FIQ = 0x11,
712 ARM_CPU_MODE_IRQ = 0x12,
713 ARM_CPU_MODE_SVC = 0x13,
714 ARM_CPU_MODE_MON = 0x16,
715 ARM_CPU_MODE_ABT = 0x17,
716 ARM_CPU_MODE_HYP = 0x1a,
717 ARM_CPU_MODE_UND = 0x1b,
718 ARM_CPU_MODE_SYS = 0x1f
721 /* VFP system registers. */
722 #define ARM_VFP_FPSID 0
723 #define ARM_VFP_FPSCR 1
724 #define ARM_VFP_MVFR2 5
725 #define ARM_VFP_MVFR1 6
726 #define ARM_VFP_MVFR0 7
727 #define ARM_VFP_FPEXC 8
728 #define ARM_VFP_FPINST 9
729 #define ARM_VFP_FPINST2 10
731 /* iwMMXt coprocessor control registers. */
732 #define ARM_IWMMXT_wCID 0
733 #define ARM_IWMMXT_wCon 1
734 #define ARM_IWMMXT_wCSSF 2
735 #define ARM_IWMMXT_wCASF 3
736 #define ARM_IWMMXT_wCGR0 8
737 #define ARM_IWMMXT_wCGR1 9
738 #define ARM_IWMMXT_wCGR2 10
739 #define ARM_IWMMXT_wCGR3 11
741 /* If adding a feature bit which corresponds to a Linux ELF
742 * HWCAP bit, remember to update the feature-bit-to-hwcap
743 * mapping in linux-user/elfload.c:get_elf_hwcap().
745 enum arm_features {
746 ARM_FEATURE_VFP,
747 ARM_FEATURE_AUXCR, /* ARM1026 Auxiliary control register. */
748 ARM_FEATURE_XSCALE, /* Intel XScale extensions. */
749 ARM_FEATURE_IWMMXT, /* Intel iwMMXt extension. */
750 ARM_FEATURE_V6,
751 ARM_FEATURE_V6K,
752 ARM_FEATURE_V7,
753 ARM_FEATURE_THUMB2,
754 ARM_FEATURE_MPU, /* Only has Memory Protection Unit, not full MMU. */
755 ARM_FEATURE_VFP3,
756 ARM_FEATURE_VFP_FP16,
757 ARM_FEATURE_NEON,
758 ARM_FEATURE_THUMB_DIV, /* divide supported in Thumb encoding */
759 ARM_FEATURE_M, /* Microcontroller profile. */
760 ARM_FEATURE_OMAPCP, /* OMAP specific CP15 ops handling. */
761 ARM_FEATURE_THUMB2EE,
762 ARM_FEATURE_V7MP, /* v7 Multiprocessing Extensions */
763 ARM_FEATURE_V4T,
764 ARM_FEATURE_V5,
765 ARM_FEATURE_STRONGARM,
766 ARM_FEATURE_VAPA, /* cp15 VA to PA lookups */
767 ARM_FEATURE_ARM_DIV, /* divide supported in ARM encoding */
768 ARM_FEATURE_VFP4, /* VFPv4 (implies that NEON is v2) */
769 ARM_FEATURE_GENERIC_TIMER,
770 ARM_FEATURE_MVFR, /* Media and VFP Feature Registers 0 and 1 */
771 ARM_FEATURE_DUMMY_C15_REGS, /* RAZ/WI all of cp15 crn=15 */
772 ARM_FEATURE_CACHE_TEST_CLEAN, /* 926/1026 style test-and-clean ops */
773 ARM_FEATURE_CACHE_DIRTY_REG, /* 1136/1176 cache dirty status register */
774 ARM_FEATURE_CACHE_BLOCK_OPS, /* v6 optional cache block operations */
775 ARM_FEATURE_MPIDR, /* has cp15 MPIDR */
776 ARM_FEATURE_PXN, /* has Privileged Execute Never bit */
777 ARM_FEATURE_LPAE, /* has Large Physical Address Extension */
778 ARM_FEATURE_V8,
779 ARM_FEATURE_AARCH64, /* supports 64 bit mode */
780 ARM_FEATURE_V8_AES, /* implements AES part of v8 Crypto Extensions */
781 ARM_FEATURE_CBAR, /* has cp15 CBAR */
782 ARM_FEATURE_CRC, /* ARMv8 CRC instructions */
783 ARM_FEATURE_CBAR_RO, /* has cp15 CBAR and it is read-only */
784 ARM_FEATURE_EL2, /* has EL2 Virtualization support */
785 ARM_FEATURE_EL3, /* has EL3 Secure monitor support */
786 ARM_FEATURE_V8_SHA1, /* implements SHA1 part of v8 Crypto Extensions */
787 ARM_FEATURE_V8_SHA256, /* implements SHA256 part of v8 Crypto Extensions */
788 ARM_FEATURE_V8_PMULL, /* implements PMULL part of v8 Crypto Extensions */
791 static inline int arm_feature(CPUARMState *env, int feature)
793 return (env->features & (1ULL << feature)) != 0;
796 #if !defined(CONFIG_USER_ONLY)
797 /* Return true if exception levels below EL3 are in secure state,
798 * or would be following an exception return to that level.
799 * Unlike arm_is_secure() (which is always a question about the
800 * _current_ state of the CPU) this doesn't care about the current
801 * EL or mode.
803 static inline bool arm_is_secure_below_el3(CPUARMState *env)
805 if (arm_feature(env, ARM_FEATURE_EL3)) {
806 return !(env->cp15.scr_el3 & SCR_NS);
807 } else {
808 /* If EL2 is not supported then the secure state is implementation
809 * defined, in which case QEMU defaults to non-secure.
811 return false;
815 /* Return true if the processor is in secure state */
816 static inline bool arm_is_secure(CPUARMState *env)
818 if (arm_feature(env, ARM_FEATURE_EL3)) {
819 if (is_a64(env) && extract32(env->pstate, 2, 2) == 3) {
820 /* CPU currently in AArch64 state and EL3 */
821 return true;
822 } else if (!is_a64(env) &&
823 (env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_MON) {
824 /* CPU currently in AArch32 state and monitor mode */
825 return true;
828 return arm_is_secure_below_el3(env);
831 #else
832 static inline bool arm_is_secure_below_el3(CPUARMState *env)
834 return false;
837 static inline bool arm_is_secure(CPUARMState *env)
839 return false;
841 #endif
843 /* Return true if the specified exception level is running in AArch64 state. */
844 static inline bool arm_el_is_aa64(CPUARMState *env, int el)
846 /* We don't currently support EL2, and this isn't valid for EL0
847 * (if we're in EL0, is_a64() is what you want, and if we're not in EL0
848 * then the state of EL0 isn't well defined.)
850 assert(el == 1 || el == 3);
852 /* AArch64-capable CPUs always run with EL1 in AArch64 mode. This
853 * is a QEMU-imposed simplification which we may wish to change later.
854 * If we in future support EL2 and/or EL3, then the state of lower
855 * exception levels is controlled by the HCR.RW and SCR.RW bits.
857 return arm_feature(env, ARM_FEATURE_AARCH64);
860 /* Function for determing whether guest cp register reads and writes should
861 * access the secure or non-secure bank of a cp register. When EL3 is
862 * operating in AArch32 state, the NS-bit determines whether the secure
863 * instance of a cp register should be used. When EL3 is AArch64 (or if
864 * it doesn't exist at all) then there is no register banking, and all
865 * accesses are to the non-secure version.
867 static inline bool access_secure_reg(CPUARMState *env)
869 bool ret = (arm_feature(env, ARM_FEATURE_EL3) &&
870 !arm_el_is_aa64(env, 3) &&
871 !(env->cp15.scr_el3 & SCR_NS));
873 return ret;
876 /* Macros for accessing a specified CP register bank */
877 #define A32_BANKED_REG_GET(_env, _regname, _secure) \
878 ((_secure) ? (_env)->cp15._regname##_s : (_env)->cp15._regname##_ns)
880 #define A32_BANKED_REG_SET(_env, _regname, _secure, _val) \
881 do { \
882 if (_secure) { \
883 (_env)->cp15._regname##_s = (_val); \
884 } else { \
885 (_env)->cp15._regname##_ns = (_val); \
887 } while (0)
889 /* Macros for automatically accessing a specific CP register bank depending on
890 * the current secure state of the system. These macros are not intended for
891 * supporting instruction translation reads/writes as these are dependent
892 * solely on the SCR.NS bit and not the mode.
894 #define A32_BANKED_CURRENT_REG_GET(_env, _regname) \
895 A32_BANKED_REG_GET((_env), _regname, \
896 ((!arm_el_is_aa64((_env), 3) && arm_is_secure(_env))))
898 #define A32_BANKED_CURRENT_REG_SET(_env, _regname, _val) \
899 A32_BANKED_REG_SET((_env), _regname, \
900 ((!arm_el_is_aa64((_env), 3) && arm_is_secure(_env))), \
901 (_val))
903 void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf);
904 unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx);
906 /* Interface between CPU and Interrupt controller. */
907 void armv7m_nvic_set_pending(void *opaque, int irq);
908 int armv7m_nvic_acknowledge_irq(void *opaque);
909 void armv7m_nvic_complete_irq(void *opaque, int irq);
911 /* Interface for defining coprocessor registers.
912 * Registers are defined in tables of arm_cp_reginfo structs
913 * which are passed to define_arm_cp_regs().
916 /* When looking up a coprocessor register we look for it
917 * via an integer which encodes all of:
918 * coprocessor number
919 * Crn, Crm, opc1, opc2 fields
920 * 32 or 64 bit register (ie is it accessed via MRC/MCR
921 * or via MRRC/MCRR?)
922 * non-secure/secure bank (AArch32 only)
923 * We allow 4 bits for opc1 because MRRC/MCRR have a 4 bit field.
924 * (In this case crn and opc2 should be zero.)
925 * For AArch64, there is no 32/64 bit size distinction;
926 * instead all registers have a 2 bit op0, 3 bit op1 and op2,
927 * and 4 bit CRn and CRm. The encoding patterns are chosen
928 * to be easy to convert to and from the KVM encodings, and also
929 * so that the hashtable can contain both AArch32 and AArch64
930 * registers (to allow for interprocessing where we might run
931 * 32 bit code on a 64 bit core).
933 /* This bit is private to our hashtable cpreg; in KVM register
934 * IDs the AArch64/32 distinction is the KVM_REG_ARM/ARM64
935 * in the upper bits of the 64 bit ID.
937 #define CP_REG_AA64_SHIFT 28
938 #define CP_REG_AA64_MASK (1 << CP_REG_AA64_SHIFT)
940 /* To enable banking of coprocessor registers depending on ns-bit we
941 * add a bit to distinguish between secure and non-secure cpregs in the
942 * hashtable.
944 #define CP_REG_NS_SHIFT 29
945 #define CP_REG_NS_MASK (1 << CP_REG_NS_SHIFT)
947 #define ENCODE_CP_REG(cp, is64, ns, crn, crm, opc1, opc2) \
948 ((ns) << CP_REG_NS_SHIFT | ((cp) << 16) | ((is64) << 15) | \
949 ((crn) << 11) | ((crm) << 7) | ((opc1) << 3) | (opc2))
951 #define ENCODE_AA64_CP_REG(cp, crn, crm, op0, op1, op2) \
952 (CP_REG_AA64_MASK | \
953 ((cp) << CP_REG_ARM_COPROC_SHIFT) | \
954 ((op0) << CP_REG_ARM64_SYSREG_OP0_SHIFT) | \
955 ((op1) << CP_REG_ARM64_SYSREG_OP1_SHIFT) | \
956 ((crn) << CP_REG_ARM64_SYSREG_CRN_SHIFT) | \
957 ((crm) << CP_REG_ARM64_SYSREG_CRM_SHIFT) | \
958 ((op2) << CP_REG_ARM64_SYSREG_OP2_SHIFT))
960 /* Convert a full 64 bit KVM register ID to the truncated 32 bit
961 * version used as a key for the coprocessor register hashtable
963 static inline uint32_t kvm_to_cpreg_id(uint64_t kvmid)
965 uint32_t cpregid = kvmid;
966 if ((kvmid & CP_REG_ARCH_MASK) == CP_REG_ARM64) {
967 cpregid |= CP_REG_AA64_MASK;
968 } else {
969 if ((kvmid & CP_REG_SIZE_MASK) == CP_REG_SIZE_U64) {
970 cpregid |= (1 << 15);
973 /* KVM is always non-secure so add the NS flag on AArch32 register
974 * entries.
976 cpregid |= 1 << CP_REG_NS_SHIFT;
978 return cpregid;
981 /* Convert a truncated 32 bit hashtable key into the full
982 * 64 bit KVM register ID.
984 static inline uint64_t cpreg_to_kvm_id(uint32_t cpregid)
986 uint64_t kvmid;
988 if (cpregid & CP_REG_AA64_MASK) {
989 kvmid = cpregid & ~CP_REG_AA64_MASK;
990 kvmid |= CP_REG_SIZE_U64 | CP_REG_ARM64;
991 } else {
992 kvmid = cpregid & ~(1 << 15);
993 if (cpregid & (1 << 15)) {
994 kvmid |= CP_REG_SIZE_U64 | CP_REG_ARM;
995 } else {
996 kvmid |= CP_REG_SIZE_U32 | CP_REG_ARM;
999 return kvmid;
1002 /* ARMCPRegInfo type field bits. If the SPECIAL bit is set this is a
1003 * special-behaviour cp reg and bits [15..8] indicate what behaviour
1004 * it has. Otherwise it is a simple cp reg, where CONST indicates that
1005 * TCG can assume the value to be constant (ie load at translate time)
1006 * and 64BIT indicates a 64 bit wide coprocessor register. SUPPRESS_TB_END
1007 * indicates that the TB should not be ended after a write to this register
1008 * (the default is that the TB ends after cp writes). OVERRIDE permits
1009 * a register definition to override a previous definition for the
1010 * same (cp, is64, crn, crm, opc1, opc2) tuple: either the new or the
1011 * old must have the OVERRIDE bit set.
1012 * NO_MIGRATE indicates that this register should be ignored for migration;
1013 * (eg because any state is accessed via some other coprocessor register).
1014 * IO indicates that this register does I/O and therefore its accesses
1015 * need to be surrounded by gen_io_start()/gen_io_end(). In particular,
1016 * registers which implement clocks or timers require this.
1018 #define ARM_CP_SPECIAL 1
1019 #define ARM_CP_CONST 2
1020 #define ARM_CP_64BIT 4
1021 #define ARM_CP_SUPPRESS_TB_END 8
1022 #define ARM_CP_OVERRIDE 16
1023 #define ARM_CP_NO_MIGRATE 32
1024 #define ARM_CP_IO 64
1025 #define ARM_CP_NOP (ARM_CP_SPECIAL | (1 << 8))
1026 #define ARM_CP_WFI (ARM_CP_SPECIAL | (2 << 8))
1027 #define ARM_CP_NZCV (ARM_CP_SPECIAL | (3 << 8))
1028 #define ARM_CP_CURRENTEL (ARM_CP_SPECIAL | (4 << 8))
1029 #define ARM_CP_DC_ZVA (ARM_CP_SPECIAL | (5 << 8))
1030 #define ARM_LAST_SPECIAL ARM_CP_DC_ZVA
1031 /* Used only as a terminator for ARMCPRegInfo lists */
1032 #define ARM_CP_SENTINEL 0xffff
1033 /* Mask of only the flag bits in a type field */
1034 #define ARM_CP_FLAG_MASK 0x7f
1036 /* Valid values for ARMCPRegInfo state field, indicating which of
1037 * the AArch32 and AArch64 execution states this register is visible in.
1038 * If the reginfo doesn't explicitly specify then it is AArch32 only.
1039 * If the reginfo is declared to be visible in both states then a second
1040 * reginfo is synthesised for the AArch32 view of the AArch64 register,
1041 * such that the AArch32 view is the lower 32 bits of the AArch64 one.
1042 * Note that we rely on the values of these enums as we iterate through
1043 * the various states in some places.
1045 enum {
1046 ARM_CP_STATE_AA32 = 0,
1047 ARM_CP_STATE_AA64 = 1,
1048 ARM_CP_STATE_BOTH = 2,
1051 /* ARM CP register secure state flags. These flags identify security state
1052 * attributes for a given CP register entry.
1053 * The existence of both or neither secure and non-secure flags indicates that
1054 * the register has both a secure and non-secure hash entry. A single one of
1055 * these flags causes the register to only be hashed for the specified
1056 * security state.
1057 * Although definitions may have any combination of the S/NS bits, each
1058 * registered entry will only have one to identify whether the entry is secure
1059 * or non-secure.
1061 enum {
1062 ARM_CP_SECSTATE_S = (1 << 0), /* bit[0]: Secure state register */
1063 ARM_CP_SECSTATE_NS = (1 << 1), /* bit[1]: Non-secure state register */
1066 /* Return true if cptype is a valid type field. This is used to try to
1067 * catch errors where the sentinel has been accidentally left off the end
1068 * of a list of registers.
1070 static inline bool cptype_valid(int cptype)
1072 return ((cptype & ~ARM_CP_FLAG_MASK) == 0)
1073 || ((cptype & ARM_CP_SPECIAL) &&
1074 ((cptype & ~ARM_CP_FLAG_MASK) <= ARM_LAST_SPECIAL));
1077 /* Access rights:
1078 * We define bits for Read and Write access for what rev C of the v7-AR ARM ARM
1079 * defines as PL0 (user), PL1 (fiq/irq/svc/abt/und/sys, ie privileged), and
1080 * PL2 (hyp). The other level which has Read and Write bits is Secure PL1
1081 * (ie any of the privileged modes in Secure state, or Monitor mode).
1082 * If a register is accessible in one privilege level it's always accessible
1083 * in higher privilege levels too. Since "Secure PL1" also follows this rule
1084 * (ie anything visible in PL2 is visible in S-PL1, some things are only
1085 * visible in S-PL1) but "Secure PL1" is a bit of a mouthful, we bend the
1086 * terminology a little and call this PL3.
1087 * In AArch64 things are somewhat simpler as the PLx bits line up exactly
1088 * with the ELx exception levels.
1090 * If access permissions for a register are more complex than can be
1091 * described with these bits, then use a laxer set of restrictions, and
1092 * do the more restrictive/complex check inside a helper function.
1094 #define PL3_R 0x80
1095 #define PL3_W 0x40
1096 #define PL2_R (0x20 | PL3_R)
1097 #define PL2_W (0x10 | PL3_W)
1098 #define PL1_R (0x08 | PL2_R)
1099 #define PL1_W (0x04 | PL2_W)
1100 #define PL0_R (0x02 | PL1_R)
1101 #define PL0_W (0x01 | PL1_W)
1103 #define PL3_RW (PL3_R | PL3_W)
1104 #define PL2_RW (PL2_R | PL2_W)
1105 #define PL1_RW (PL1_R | PL1_W)
1106 #define PL0_RW (PL0_R | PL0_W)
1108 /* Return the current Exception Level (as per ARMv8; note that this differs
1109 * from the ARMv7 Privilege Level).
1111 static inline int arm_current_el(CPUARMState *env)
1113 if (is_a64(env)) {
1114 return extract32(env->pstate, 2, 2);
1117 switch (env->uncached_cpsr & 0x1f) {
1118 case ARM_CPU_MODE_USR:
1119 return 0;
1120 case ARM_CPU_MODE_HYP:
1121 return 2;
1122 case ARM_CPU_MODE_MON:
1123 return 3;
1124 default:
1125 if (arm_is_secure(env) && !arm_el_is_aa64(env, 3)) {
1126 /* If EL3 is 32-bit then all secure privileged modes run in
1127 * EL3
1129 return 3;
1132 return 1;
1136 typedef struct ARMCPRegInfo ARMCPRegInfo;
1138 typedef enum CPAccessResult {
1139 /* Access is permitted */
1140 CP_ACCESS_OK = 0,
1141 /* Access fails due to a configurable trap or enable which would
1142 * result in a categorized exception syndrome giving information about
1143 * the failing instruction (ie syndrome category 0x3, 0x4, 0x5, 0x6,
1144 * 0xc or 0x18).
1146 CP_ACCESS_TRAP = 1,
1147 /* Access fails and results in an exception syndrome 0x0 ("uncategorized").
1148 * Note that this is not a catch-all case -- the set of cases which may
1149 * result in this failure is specifically defined by the architecture.
1151 CP_ACCESS_TRAP_UNCATEGORIZED = 2,
1152 } CPAccessResult;
1154 /* Access functions for coprocessor registers. These cannot fail and
1155 * may not raise exceptions.
1157 typedef uint64_t CPReadFn(CPUARMState *env, const ARMCPRegInfo *opaque);
1158 typedef void CPWriteFn(CPUARMState *env, const ARMCPRegInfo *opaque,
1159 uint64_t value);
1160 /* Access permission check functions for coprocessor registers. */
1161 typedef CPAccessResult CPAccessFn(CPUARMState *env, const ARMCPRegInfo *opaque);
1162 /* Hook function for register reset */
1163 typedef void CPResetFn(CPUARMState *env, const ARMCPRegInfo *opaque);
1165 #define CP_ANY 0xff
1167 /* Definition of an ARM coprocessor register */
1168 struct ARMCPRegInfo {
1169 /* Name of register (useful mainly for debugging, need not be unique) */
1170 const char *name;
1171 /* Location of register: coprocessor number and (crn,crm,opc1,opc2)
1172 * tuple. Any of crm, opc1 and opc2 may be CP_ANY to indicate a
1173 * 'wildcard' field -- any value of that field in the MRC/MCR insn
1174 * will be decoded to this register. The register read and write
1175 * callbacks will be passed an ARMCPRegInfo with the crn/crm/opc1/opc2
1176 * used by the program, so it is possible to register a wildcard and
1177 * then behave differently on read/write if necessary.
1178 * For 64 bit registers, only crm and opc1 are relevant; crn and opc2
1179 * must both be zero.
1180 * For AArch64-visible registers, opc0 is also used.
1181 * Since there are no "coprocessors" in AArch64, cp is purely used as a
1182 * way to distinguish (for KVM's benefit) guest-visible system registers
1183 * from demuxed ones provided to preserve the "no side effects on
1184 * KVM register read/write from QEMU" semantics. cp==0x13 is guest
1185 * visible (to match KVM's encoding); cp==0 will be converted to
1186 * cp==0x13 when the ARMCPRegInfo is registered, for convenience.
1188 uint8_t cp;
1189 uint8_t crn;
1190 uint8_t crm;
1191 uint8_t opc0;
1192 uint8_t opc1;
1193 uint8_t opc2;
1194 /* Execution state in which this register is visible: ARM_CP_STATE_* */
1195 int state;
1196 /* Register type: ARM_CP_* bits/values */
1197 int type;
1198 /* Access rights: PL*_[RW] */
1199 int access;
1200 /* Security state: ARM_CP_SECSTATE_* bits/values */
1201 int secure;
1202 /* The opaque pointer passed to define_arm_cp_regs_with_opaque() when
1203 * this register was defined: can be used to hand data through to the
1204 * register read/write functions, since they are passed the ARMCPRegInfo*.
1206 void *opaque;
1207 /* Value of this register, if it is ARM_CP_CONST. Otherwise, if
1208 * fieldoffset is non-zero, the reset value of the register.
1210 uint64_t resetvalue;
1211 /* Offset of the field in CPUARMState for this register.
1213 * This is not needed if either:
1214 * 1. type is ARM_CP_CONST or one of the ARM_CP_SPECIALs
1215 * 2. both readfn and writefn are specified
1217 ptrdiff_t fieldoffset; /* offsetof(CPUARMState, field) */
1219 /* Offsets of the secure and non-secure fields in CPUARMState for the
1220 * register if it is banked. These fields are only used during the static
1221 * registration of a register. During hashing the bank associated
1222 * with a given security state is copied to fieldoffset which is used from
1223 * there on out.
1225 * It is expected that register definitions use either fieldoffset or
1226 * bank_fieldoffsets in the definition but not both. It is also expected
1227 * that both bank offsets are set when defining a banked register. This
1228 * use indicates that a register is banked.
1230 ptrdiff_t bank_fieldoffsets[2];
1232 /* Function for making any access checks for this register in addition to
1233 * those specified by the 'access' permissions bits. If NULL, no extra
1234 * checks required. The access check is performed at runtime, not at
1235 * translate time.
1237 CPAccessFn *accessfn;
1238 /* Function for handling reads of this register. If NULL, then reads
1239 * will be done by loading from the offset into CPUARMState specified
1240 * by fieldoffset.
1242 CPReadFn *readfn;
1243 /* Function for handling writes of this register. If NULL, then writes
1244 * will be done by writing to the offset into CPUARMState specified
1245 * by fieldoffset.
1247 CPWriteFn *writefn;
1248 /* Function for doing a "raw" read; used when we need to copy
1249 * coprocessor state to the kernel for KVM or out for
1250 * migration. This only needs to be provided if there is also a
1251 * readfn and it has side effects (for instance clear-on-read bits).
1253 CPReadFn *raw_readfn;
1254 /* Function for doing a "raw" write; used when we need to copy KVM
1255 * kernel coprocessor state into userspace, or for inbound
1256 * migration. This only needs to be provided if there is also a
1257 * writefn and it masks out "unwritable" bits or has write-one-to-clear
1258 * or similar behaviour.
1260 CPWriteFn *raw_writefn;
1261 /* Function for resetting the register. If NULL, then reset will be done
1262 * by writing resetvalue to the field specified in fieldoffset. If
1263 * fieldoffset is 0 then no reset will be done.
1265 CPResetFn *resetfn;
1268 /* Macros which are lvalues for the field in CPUARMState for the
1269 * ARMCPRegInfo *ri.
1271 #define CPREG_FIELD32(env, ri) \
1272 (*(uint32_t *)((char *)(env) + (ri)->fieldoffset))
1273 #define CPREG_FIELD64(env, ri) \
1274 (*(uint64_t *)((char *)(env) + (ri)->fieldoffset))
1276 #define REGINFO_SENTINEL { .type = ARM_CP_SENTINEL }
1278 void define_arm_cp_regs_with_opaque(ARMCPU *cpu,
1279 const ARMCPRegInfo *regs, void *opaque);
1280 void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
1281 const ARMCPRegInfo *regs, void *opaque);
1282 static inline void define_arm_cp_regs(ARMCPU *cpu, const ARMCPRegInfo *regs)
1284 define_arm_cp_regs_with_opaque(cpu, regs, 0);
1286 static inline void define_one_arm_cp_reg(ARMCPU *cpu, const ARMCPRegInfo *regs)
1288 define_one_arm_cp_reg_with_opaque(cpu, regs, 0);
1290 const ARMCPRegInfo *get_arm_cp_reginfo(GHashTable *cpregs, uint32_t encoded_cp);
1292 /* CPWriteFn that can be used to implement writes-ignored behaviour */
1293 void arm_cp_write_ignore(CPUARMState *env, const ARMCPRegInfo *ri,
1294 uint64_t value);
1295 /* CPReadFn that can be used for read-as-zero behaviour */
1296 uint64_t arm_cp_read_zero(CPUARMState *env, const ARMCPRegInfo *ri);
1298 /* CPResetFn that does nothing, for use if no reset is required even
1299 * if fieldoffset is non zero.
1301 void arm_cp_reset_ignore(CPUARMState *env, const ARMCPRegInfo *opaque);
1303 /* Return true if this reginfo struct's field in the cpu state struct
1304 * is 64 bits wide.
1306 static inline bool cpreg_field_is_64bit(const ARMCPRegInfo *ri)
1308 return (ri->state == ARM_CP_STATE_AA64) || (ri->type & ARM_CP_64BIT);
1311 static inline bool cp_access_ok(int current_el,
1312 const ARMCPRegInfo *ri, int isread)
1314 return (ri->access >> ((current_el * 2) + isread)) & 1;
1318 * write_list_to_cpustate
1319 * @cpu: ARMCPU
1321 * For each register listed in the ARMCPU cpreg_indexes list, write
1322 * its value from the cpreg_values list into the ARMCPUState structure.
1323 * This updates TCG's working data structures from KVM data or
1324 * from incoming migration state.
1326 * Returns: true if all register values were updated correctly,
1327 * false if some register was unknown or could not be written.
1328 * Note that we do not stop early on failure -- we will attempt
1329 * writing all registers in the list.
1331 bool write_list_to_cpustate(ARMCPU *cpu);
1334 * write_cpustate_to_list:
1335 * @cpu: ARMCPU
1337 * For each register listed in the ARMCPU cpreg_indexes list, write
1338 * its value from the ARMCPUState structure into the cpreg_values list.
1339 * This is used to copy info from TCG's working data structures into
1340 * KVM or for outbound migration.
1342 * Returns: true if all register values were read correctly,
1343 * false if some register was unknown or could not be read.
1344 * Note that we do not stop early on failure -- we will attempt
1345 * reading all registers in the list.
1347 bool write_cpustate_to_list(ARMCPU *cpu);
1349 /* Does the core conform to the the "MicroController" profile. e.g. Cortex-M3.
1350 Note the M in older cores (eg. ARM7TDMI) stands for Multiply. These are
1351 conventional cores (ie. Application or Realtime profile). */
1353 #define IS_M(env) arm_feature(env, ARM_FEATURE_M)
1355 #define ARM_CPUID_TI915T 0x54029152
1356 #define ARM_CPUID_TI925T 0x54029252
1358 #if defined(CONFIG_USER_ONLY)
1359 #define TARGET_PAGE_BITS 12
1360 #else
1361 /* The ARM MMU allows 1k pages. */
1362 /* ??? Linux doesn't actually use these, and they're deprecated in recent
1363 architecture revisions. Maybe a configure option to disable them. */
1364 #define TARGET_PAGE_BITS 10
1365 #endif
1367 #if defined(TARGET_AARCH64)
1368 # define TARGET_PHYS_ADDR_SPACE_BITS 48
1369 # define TARGET_VIRT_ADDR_SPACE_BITS 64
1370 #else
1371 # define TARGET_PHYS_ADDR_SPACE_BITS 40
1372 # define TARGET_VIRT_ADDR_SPACE_BITS 32
1373 #endif
1375 static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)
1377 CPUARMState *env = cs->env_ptr;
1378 unsigned int cur_el = arm_current_el(env);
1379 unsigned int target_el = arm_excp_target_el(cs, excp_idx);
1380 bool secure = arm_is_secure(env);
1381 uint32_t scr;
1382 uint32_t hcr;
1383 bool pstate_unmasked;
1384 int8_t unmasked = 0;
1386 /* Don't take exceptions if they target a lower EL.
1387 * This check should catch any exceptions that would not be taken but left
1388 * pending.
1390 if (cur_el > target_el) {
1391 return false;
1394 switch (excp_idx) {
1395 case EXCP_FIQ:
1396 /* If FIQs are routed to EL3 or EL2 then there are cases where we
1397 * override the CPSR.F in determining if the exception is masked or
1398 * not. If neither of these are set then we fall back to the CPSR.F
1399 * setting otherwise we further assess the state below.
1401 hcr = (env->cp15.hcr_el2 & HCR_FMO);
1402 scr = (env->cp15.scr_el3 & SCR_FIQ);
1404 /* When EL3 is 32-bit, the SCR.FW bit controls whether the CPSR.F bit
1405 * masks FIQ interrupts when taken in non-secure state. If SCR.FW is
1406 * set then FIQs can be masked by CPSR.F when non-secure but only
1407 * when FIQs are only routed to EL3.
1409 scr &= !((env->cp15.scr_el3 & SCR_FW) && !hcr);
1410 pstate_unmasked = !(env->daif & PSTATE_F);
1411 break;
1413 case EXCP_IRQ:
1414 /* When EL3 execution state is 32-bit, if HCR.IMO is set then we may
1415 * override the CPSR.I masking when in non-secure state. The SCR.IRQ
1416 * setting has already been taken into consideration when setting the
1417 * target EL, so it does not have a further affect here.
1419 hcr = (env->cp15.hcr_el2 & HCR_IMO);
1420 scr = false;
1421 pstate_unmasked = !(env->daif & PSTATE_I);
1422 break;
1424 case EXCP_VFIQ:
1425 if (secure || !(env->cp15.hcr_el2 & HCR_FMO)) {
1426 /* VFIQs are only taken when hypervized and non-secure. */
1427 return false;
1429 return !(env->daif & PSTATE_F);
1430 case EXCP_VIRQ:
1431 if (secure || !(env->cp15.hcr_el2 & HCR_IMO)) {
1432 /* VIRQs are only taken when hypervized and non-secure. */
1433 return false;
1435 return !(env->daif & PSTATE_I);
1436 default:
1437 g_assert_not_reached();
1440 /* Use the target EL, current execution state and SCR/HCR settings to
1441 * determine whether the corresponding CPSR bit is used to mask the
1442 * interrupt.
1444 if ((target_el > cur_el) && (target_el != 1)) {
1445 if (arm_el_is_aa64(env, 3) || ((scr || hcr) && (!secure))) {
1446 unmasked = 1;
1450 /* The PSTATE bits only mask the interrupt if we have not overriden the
1451 * ability above.
1453 return unmasked || pstate_unmasked;
1456 static inline CPUARMState *cpu_init(const char *cpu_model)
1458 ARMCPU *cpu = cpu_arm_init(cpu_model);
1459 if (cpu) {
1460 return &cpu->env;
1462 return NULL;
1465 #define cpu_exec cpu_arm_exec
1466 #define cpu_gen_code cpu_arm_gen_code
1467 #define cpu_signal_handler cpu_arm_signal_handler
1468 #define cpu_list arm_cpu_list
1470 /* MMU modes definitions */
1471 #define MMU_MODE0_SUFFIX _user
1472 #define MMU_MODE1_SUFFIX _kernel
1473 #define MMU_USER_IDX 0
1474 static inline int cpu_mmu_index (CPUARMState *env)
1476 return arm_current_el(env);
1479 /* Return the Exception Level targeted by debug exceptions;
1480 * currently always EL1 since we don't implement EL2 or EL3.
1482 static inline int arm_debug_target_el(CPUARMState *env)
1484 return 1;
1487 static inline bool aa64_generate_debug_exceptions(CPUARMState *env)
1489 if (arm_current_el(env) == arm_debug_target_el(env)) {
1490 if ((extract32(env->cp15.mdscr_el1, 13, 1) == 0)
1491 || (env->daif & PSTATE_D)) {
1492 return false;
1495 return true;
1498 static inline bool aa32_generate_debug_exceptions(CPUARMState *env)
1500 if (arm_current_el(env) == 0 && arm_el_is_aa64(env, 1)) {
1501 return aa64_generate_debug_exceptions(env);
1503 return arm_current_el(env) != 2;
1506 /* Return true if debugging exceptions are currently enabled.
1507 * This corresponds to what in ARM ARM pseudocode would be
1508 * if UsingAArch32() then
1509 * return AArch32.GenerateDebugExceptions()
1510 * else
1511 * return AArch64.GenerateDebugExceptions()
1512 * We choose to push the if() down into this function for clarity,
1513 * since the pseudocode has it at all callsites except for the one in
1514 * CheckSoftwareStep(), where it is elided because both branches would
1515 * always return the same value.
1517 * Parts of the pseudocode relating to EL2 and EL3 are omitted because we
1518 * don't yet implement those exception levels or their associated trap bits.
1520 static inline bool arm_generate_debug_exceptions(CPUARMState *env)
1522 if (env->aarch64) {
1523 return aa64_generate_debug_exceptions(env);
1524 } else {
1525 return aa32_generate_debug_exceptions(env);
1529 /* Is single-stepping active? (Note that the "is EL_D AArch64?" check
1530 * implicitly means this always returns false in pre-v8 CPUs.)
1532 static inline bool arm_singlestep_active(CPUARMState *env)
1534 return extract32(env->cp15.mdscr_el1, 0, 1)
1535 && arm_el_is_aa64(env, arm_debug_target_el(env))
1536 && arm_generate_debug_exceptions(env);
1539 #include "exec/cpu-all.h"
1541 /* Bit usage in the TB flags field: bit 31 indicates whether we are
1542 * in 32 or 64 bit mode. The meaning of the other bits depends on that.
1544 #define ARM_TBFLAG_AARCH64_STATE_SHIFT 31
1545 #define ARM_TBFLAG_AARCH64_STATE_MASK (1U << ARM_TBFLAG_AARCH64_STATE_SHIFT)
1547 /* Bit usage when in AArch32 state: */
1548 #define ARM_TBFLAG_THUMB_SHIFT 0
1549 #define ARM_TBFLAG_THUMB_MASK (1 << ARM_TBFLAG_THUMB_SHIFT)
1550 #define ARM_TBFLAG_VECLEN_SHIFT 1
1551 #define ARM_TBFLAG_VECLEN_MASK (0x7 << ARM_TBFLAG_VECLEN_SHIFT)
1552 #define ARM_TBFLAG_VECSTRIDE_SHIFT 4
1553 #define ARM_TBFLAG_VECSTRIDE_MASK (0x3 << ARM_TBFLAG_VECSTRIDE_SHIFT)
1554 #define ARM_TBFLAG_PRIV_SHIFT 6
1555 #define ARM_TBFLAG_PRIV_MASK (1 << ARM_TBFLAG_PRIV_SHIFT)
1556 #define ARM_TBFLAG_VFPEN_SHIFT 7
1557 #define ARM_TBFLAG_VFPEN_MASK (1 << ARM_TBFLAG_VFPEN_SHIFT)
1558 #define ARM_TBFLAG_CONDEXEC_SHIFT 8
1559 #define ARM_TBFLAG_CONDEXEC_MASK (0xff << ARM_TBFLAG_CONDEXEC_SHIFT)
1560 #define ARM_TBFLAG_BSWAP_CODE_SHIFT 16
1561 #define ARM_TBFLAG_BSWAP_CODE_MASK (1 << ARM_TBFLAG_BSWAP_CODE_SHIFT)
1562 #define ARM_TBFLAG_CPACR_FPEN_SHIFT 17
1563 #define ARM_TBFLAG_CPACR_FPEN_MASK (1 << ARM_TBFLAG_CPACR_FPEN_SHIFT)
1564 #define ARM_TBFLAG_SS_ACTIVE_SHIFT 18
1565 #define ARM_TBFLAG_SS_ACTIVE_MASK (1 << ARM_TBFLAG_SS_ACTIVE_SHIFT)
1566 #define ARM_TBFLAG_PSTATE_SS_SHIFT 19
1567 #define ARM_TBFLAG_PSTATE_SS_MASK (1 << ARM_TBFLAG_PSTATE_SS_SHIFT)
1568 /* We store the bottom two bits of the CPAR as TB flags and handle
1569 * checks on the other bits at runtime
1571 #define ARM_TBFLAG_XSCALE_CPAR_SHIFT 20
1572 #define ARM_TBFLAG_XSCALE_CPAR_MASK (3 << ARM_TBFLAG_XSCALE_CPAR_SHIFT)
1573 /* Indicates whether cp register reads and writes by guest code should access
1574 * the secure or nonsecure bank of banked registers; note that this is not
1575 * the same thing as the current security state of the processor!
1577 #define ARM_TBFLAG_NS_SHIFT 22
1578 #define ARM_TBFLAG_NS_MASK (1 << ARM_TBFLAG_NS_SHIFT)
1580 /* Bit usage when in AArch64 state */
1581 #define ARM_TBFLAG_AA64_EL_SHIFT 0
1582 #define ARM_TBFLAG_AA64_EL_MASK (0x3 << ARM_TBFLAG_AA64_EL_SHIFT)
1583 #define ARM_TBFLAG_AA64_FPEN_SHIFT 2
1584 #define ARM_TBFLAG_AA64_FPEN_MASK (1 << ARM_TBFLAG_AA64_FPEN_SHIFT)
1585 #define ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT 3
1586 #define ARM_TBFLAG_AA64_SS_ACTIVE_MASK (1 << ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT)
1587 #define ARM_TBFLAG_AA64_PSTATE_SS_SHIFT 4
1588 #define ARM_TBFLAG_AA64_PSTATE_SS_MASK (1 << ARM_TBFLAG_AA64_PSTATE_SS_SHIFT)
1590 /* some convenience accessor macros */
1591 #define ARM_TBFLAG_AARCH64_STATE(F) \
1592 (((F) & ARM_TBFLAG_AARCH64_STATE_MASK) >> ARM_TBFLAG_AARCH64_STATE_SHIFT)
1593 #define ARM_TBFLAG_THUMB(F) \
1594 (((F) & ARM_TBFLAG_THUMB_MASK) >> ARM_TBFLAG_THUMB_SHIFT)
1595 #define ARM_TBFLAG_VECLEN(F) \
1596 (((F) & ARM_TBFLAG_VECLEN_MASK) >> ARM_TBFLAG_VECLEN_SHIFT)
1597 #define ARM_TBFLAG_VECSTRIDE(F) \
1598 (((F) & ARM_TBFLAG_VECSTRIDE_MASK) >> ARM_TBFLAG_VECSTRIDE_SHIFT)
1599 #define ARM_TBFLAG_PRIV(F) \
1600 (((F) & ARM_TBFLAG_PRIV_MASK) >> ARM_TBFLAG_PRIV_SHIFT)
1601 #define ARM_TBFLAG_VFPEN(F) \
1602 (((F) & ARM_TBFLAG_VFPEN_MASK) >> ARM_TBFLAG_VFPEN_SHIFT)
1603 #define ARM_TBFLAG_CONDEXEC(F) \
1604 (((F) & ARM_TBFLAG_CONDEXEC_MASK) >> ARM_TBFLAG_CONDEXEC_SHIFT)
1605 #define ARM_TBFLAG_BSWAP_CODE(F) \
1606 (((F) & ARM_TBFLAG_BSWAP_CODE_MASK) >> ARM_TBFLAG_BSWAP_CODE_SHIFT)
1607 #define ARM_TBFLAG_CPACR_FPEN(F) \
1608 (((F) & ARM_TBFLAG_CPACR_FPEN_MASK) >> ARM_TBFLAG_CPACR_FPEN_SHIFT)
1609 #define ARM_TBFLAG_SS_ACTIVE(F) \
1610 (((F) & ARM_TBFLAG_SS_ACTIVE_MASK) >> ARM_TBFLAG_SS_ACTIVE_SHIFT)
1611 #define ARM_TBFLAG_PSTATE_SS(F) \
1612 (((F) & ARM_TBFLAG_PSTATE_SS_MASK) >> ARM_TBFLAG_PSTATE_SS_SHIFT)
1613 #define ARM_TBFLAG_XSCALE_CPAR(F) \
1614 (((F) & ARM_TBFLAG_XSCALE_CPAR_MASK) >> ARM_TBFLAG_XSCALE_CPAR_SHIFT)
1615 #define ARM_TBFLAG_AA64_EL(F) \
1616 (((F) & ARM_TBFLAG_AA64_EL_MASK) >> ARM_TBFLAG_AA64_EL_SHIFT)
1617 #define ARM_TBFLAG_AA64_FPEN(F) \
1618 (((F) & ARM_TBFLAG_AA64_FPEN_MASK) >> ARM_TBFLAG_AA64_FPEN_SHIFT)
1619 #define ARM_TBFLAG_AA64_SS_ACTIVE(F) \
1620 (((F) & ARM_TBFLAG_AA64_SS_ACTIVE_MASK) >> ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT)
1621 #define ARM_TBFLAG_AA64_PSTATE_SS(F) \
1622 (((F) & ARM_TBFLAG_AA64_PSTATE_SS_MASK) >> ARM_TBFLAG_AA64_PSTATE_SS_SHIFT)
1623 #define ARM_TBFLAG_NS(F) \
1624 (((F) & ARM_TBFLAG_NS_MASK) >> ARM_TBFLAG_NS_SHIFT)
1626 static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc,
1627 target_ulong *cs_base, int *flags)
1629 int fpen;
1631 if (arm_feature(env, ARM_FEATURE_V6)) {
1632 fpen = extract32(env->cp15.c1_coproc, 20, 2);
1633 } else {
1634 /* CPACR doesn't exist before v6, so VFP is always accessible */
1635 fpen = 3;
1638 if (is_a64(env)) {
1639 *pc = env->pc;
1640 *flags = ARM_TBFLAG_AARCH64_STATE_MASK
1641 | (arm_current_el(env) << ARM_TBFLAG_AA64_EL_SHIFT);
1642 if (fpen == 3 || (fpen == 1 && arm_current_el(env) != 0)) {
1643 *flags |= ARM_TBFLAG_AA64_FPEN_MASK;
1645 /* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine
1646 * states defined in the ARM ARM for software singlestep:
1647 * SS_ACTIVE PSTATE.SS State
1648 * 0 x Inactive (the TB flag for SS is always 0)
1649 * 1 0 Active-pending
1650 * 1 1 Active-not-pending
1652 if (arm_singlestep_active(env)) {
1653 *flags |= ARM_TBFLAG_AA64_SS_ACTIVE_MASK;
1654 if (env->pstate & PSTATE_SS) {
1655 *flags |= ARM_TBFLAG_AA64_PSTATE_SS_MASK;
1658 } else {
1659 int privmode;
1660 *pc = env->regs[15];
1661 *flags = (env->thumb << ARM_TBFLAG_THUMB_SHIFT)
1662 | (env->vfp.vec_len << ARM_TBFLAG_VECLEN_SHIFT)
1663 | (env->vfp.vec_stride << ARM_TBFLAG_VECSTRIDE_SHIFT)
1664 | (env->condexec_bits << ARM_TBFLAG_CONDEXEC_SHIFT)
1665 | (env->bswap_code << ARM_TBFLAG_BSWAP_CODE_SHIFT);
1666 if (arm_feature(env, ARM_FEATURE_M)) {
1667 privmode = !((env->v7m.exception == 0) && (env->v7m.control & 1));
1668 } else {
1669 privmode = (env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_USR;
1671 if (privmode) {
1672 *flags |= ARM_TBFLAG_PRIV_MASK;
1674 if (!(access_secure_reg(env))) {
1675 *flags |= ARM_TBFLAG_NS_MASK;
1677 if (env->vfp.xregs[ARM_VFP_FPEXC] & (1 << 30)
1678 || arm_el_is_aa64(env, 1)) {
1679 *flags |= ARM_TBFLAG_VFPEN_MASK;
1681 if (fpen == 3 || (fpen == 1 && arm_current_el(env) != 0)) {
1682 *flags |= ARM_TBFLAG_CPACR_FPEN_MASK;
1684 /* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine
1685 * states defined in the ARM ARM for software singlestep:
1686 * SS_ACTIVE PSTATE.SS State
1687 * 0 x Inactive (the TB flag for SS is always 0)
1688 * 1 0 Active-pending
1689 * 1 1 Active-not-pending
1691 if (arm_singlestep_active(env)) {
1692 *flags |= ARM_TBFLAG_SS_ACTIVE_MASK;
1693 if (env->uncached_cpsr & PSTATE_SS) {
1694 *flags |= ARM_TBFLAG_PSTATE_SS_MASK;
1697 *flags |= (extract32(env->cp15.c15_cpar, 0, 2)
1698 << ARM_TBFLAG_XSCALE_CPAR_SHIFT);
1701 *cs_base = 0;
1704 #include "exec/exec-all.h"
1706 static inline void cpu_pc_from_tb(CPUARMState *env, TranslationBlock *tb)
1708 if (ARM_TBFLAG_AARCH64_STATE(tb->flags)) {
1709 env->pc = tb->pc;
1710 } else {
1711 env->regs[15] = tb->pc;
1715 enum {
1716 QEMU_PSCI_CONDUIT_DISABLED = 0,
1717 QEMU_PSCI_CONDUIT_SMC = 1,
1718 QEMU_PSCI_CONDUIT_HVC = 2,
1721 #endif