]> Git Repo - qemu.git/blame - target-arm/cpu.h
target-arm: Add a Hypervisor Trap exception type
[qemu.git] / target-arm / cpu.h
CommitLineData
2c0262af
FB
1/*
2 * ARM virtual CPU header
5fafdf24 3 *
2c0262af
FB
4 * Copyright (c) 2003 Fabrice Bellard
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU Lesser General Public
8167ee88 17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
2c0262af
FB
18 */
19#ifndef CPU_ARM_H
20#define CPU_ARM_H
21
3926cc84 22#include "config.h"
3cf1e035 23
72b0cd35
PM
24#include "kvm-consts.h"
25
3926cc84
AG
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
9042c0e2 34
9349b4f9 35#define CPUArchState struct CPUARMState
c2764719 36
9a78eead 37#include "qemu-common.h"
022c62cb 38#include "exec/cpu-defs.h"
2c0262af 39
6b4c305c 40#include "fpu/softfloat.h"
53cd6637 41
1fddef4b
FB
42#define TARGET_HAS_ICE 1
43
b8a9e8f1
FB
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
b5ff1b31
FB
48#define EXCP_IRQ 5
49#define EXCP_FIQ 6
06c949e6 50#define EXCP_BKPT 7
9ee6e8bb 51#define EXCP_EXCEPTION_EXIT 8 /* Return from v7M exception. */
fbb4a2e3 52#define EXCP_KERNEL_TRAP 9 /* Jumped to kernel code page. */
426f5abc 53#define EXCP_STREX 10
35979d71 54#define EXCP_HVC 11 /* HyperVisor Call */
607d98b8 55#define EXCP_HYP_TRAP 12
9ee6e8bb
PB
56
57#define ARMV7M_EXCP_RESET 1
58#define ARMV7M_EXCP_NMI 2
59#define ARMV7M_EXCP_HARD 3
60#define ARMV7M_EXCP_MEM 4
61#define ARMV7M_EXCP_BUS 5
62#define ARMV7M_EXCP_USAGE 6
63#define ARMV7M_EXCP_SVC 11
64#define ARMV7M_EXCP_DEBUG 12
65#define ARMV7M_EXCP_PENDSV 14
66#define ARMV7M_EXCP_SYSTICK 15
2c0262af 67
403946c0
RH
68/* ARM-specific interrupt pending bits. */
69#define CPU_INTERRUPT_FIQ CPU_INTERRUPT_TGT_EXT_1
70
e4fe830b
PM
71/* The usual mapping for an AArch64 system register to its AArch32
72 * counterpart is for the 32 bit world to have access to the lower
73 * half only (with writes leaving the upper half untouched). It's
74 * therefore useful to be able to pass TCG the offset of the least
75 * significant half of a uint64_t struct member.
76 */
77#ifdef HOST_WORDS_BIGENDIAN
5cd8a118 78#define offsetoflow32(S, M) (offsetof(S, M) + sizeof(uint32_t))
b0fe2427 79#define offsetofhigh32(S, M) offsetof(S, M)
e4fe830b
PM
80#else
81#define offsetoflow32(S, M) offsetof(S, M)
b0fe2427 82#define offsetofhigh32(S, M) (offsetof(S, M) + sizeof(uint32_t))
e4fe830b
PM
83#endif
84
7c1840b6
PM
85/* Meanings of the ARMCPU object's two inbound GPIO lines */
86#define ARM_CPU_IRQ 0
87#define ARM_CPU_FIQ 1
403946c0 88
c1713132
AZ
89typedef void ARMWriteCPFunc(void *opaque, int cp_info,
90 int srcreg, int operand, uint32_t value);
91typedef uint32_t ARMReadCPFunc(void *opaque, int cp_info,
92 int dstreg, int operand);
93
f93eb9ff
AZ
94struct arm_boot_info;
95
6ebbf390
JM
96#define NB_MMU_MODES 2
97
b7bcbe95
FB
98/* We currently assume float and double are IEEE single and double
99 precision respectively.
100 Doing runtime conversions is tricky because VFP registers may contain
101 integer values (eg. as the result of a FTOSI instruction).
8e96005d
FB
102 s<2n> maps to the least significant half of d<n>
103 s<2n+1> maps to the most significant half of d<n>
104 */
b7bcbe95 105
55d284af
PM
106/* CPU state for each instance of a generic timer (in cp15 c14) */
107typedef struct ARMGenericTimer {
108 uint64_t cval; /* Timer CompareValue register */
a7adc4b7 109 uint64_t ctl; /* Timer Control register */
55d284af
PM
110} ARMGenericTimer;
111
112#define GTIMER_PHYS 0
113#define GTIMER_VIRT 1
114#define NUM_GTIMERS 2
115
2c0262af 116typedef struct CPUARMState {
b5ff1b31 117 /* Regs for current mode. */
2c0262af 118 uint32_t regs[16];
3926cc84
AG
119
120 /* 32/64 switch only happens when taking and returning from
121 * exceptions so the overlap semantics are taken care of then
122 * instead of having a complicated union.
123 */
124 /* Regs for A64 mode. */
125 uint64_t xregs[32];
126 uint64_t pc;
d356312f
PM
127 /* PSTATE isn't an architectural register for ARMv8. However, it is
128 * convenient for us to assemble the underlying state into a 32 bit format
129 * identical to the architectural format used for the SPSR. (This is also
130 * what the Linux kernel's 'pstate' field in signal handlers and KVM's
131 * 'pstate' register are.) Of the PSTATE bits:
132 * NZCV are kept in the split out env->CF/VF/NF/ZF, (which have the same
133 * semantics as for AArch32, as described in the comments on each field)
134 * nRW (also known as M[4]) is kept, inverted, in env->aarch64
4cc35614 135 * DAIF (exception masks) are kept in env->daif
d356312f 136 * all other bits are stored in their correct places in env->pstate
3926cc84
AG
137 */
138 uint32_t pstate;
139 uint32_t aarch64; /* 1 if CPU is in aarch64 state; inverse of PSTATE.nRW */
140
b90372ad 141 /* Frequently accessed CPSR bits are stored separately for efficiency.
d37aca66 142 This contains all the other bits. Use cpsr_{read,write} to access
b5ff1b31
FB
143 the whole CPSR. */
144 uint32_t uncached_cpsr;
145 uint32_t spsr;
146
147 /* Banked registers. */
28c9457d 148 uint64_t banked_spsr[8];
b5ff1b31
FB
149 uint32_t banked_r13[6];
150 uint32_t banked_r14[6];
3b46e624 151
b5ff1b31
FB
152 /* These hold r8-r12. */
153 uint32_t usr_regs[5];
154 uint32_t fiq_regs[5];
3b46e624 155
2c0262af
FB
156 /* cpsr flag cache for faster execution */
157 uint32_t CF; /* 0 or 1 */
158 uint32_t VF; /* V is the bit 31. All other bits are undefined */
6fbe23d5
PB
159 uint32_t NF; /* N is bit 31. All other bits are undefined. */
160 uint32_t ZF; /* Z set if zero. */
99c475ab 161 uint32_t QF; /* 0 or 1 */
9ee6e8bb 162 uint32_t GE; /* cpsr[19:16] */
b26eefb6 163 uint32_t thumb; /* cpsr[5]. 0 = arm mode, 1 = thumb mode. */
9ee6e8bb 164 uint32_t condexec_bits; /* IT bits. cpsr[15:10,26:25]. */
c2b820fe 165 uint64_t daif; /* exception masks, in the bits they are in in PSTATE */
2c0262af 166
1b174238 167 uint64_t elr_el[4]; /* AArch64 exception link regs */
73fb3b76 168 uint64_t sp_el[4]; /* AArch64 banked stack pointers */
a0618a19 169
b5ff1b31
FB
170 /* System control coprocessor (cp15) */
171 struct {
40f137e1 172 uint32_t c0_cpuid;
7da845b0 173 uint64_t c0_cssel; /* Cache size selection. */
5ebafdf3 174 uint64_t c1_sys; /* System control register. */
34222fb8 175 uint64_t c1_coproc; /* Coprocessor access register. */
610c3c8a 176 uint32_t c1_xscaleauxcr; /* XScale auxiliary control register. */
327ed10f
PM
177 uint64_t ttbr0_el1; /* MMU translation table base 0. */
178 uint64_t ttbr1_el1; /* MMU translation table base 1. */
cb2e37df 179 uint64_t c2_control; /* MMU translation table base control. */
b2fa1797
PB
180 uint32_t c2_mask; /* MMU translation table base selection mask. */
181 uint32_t c2_base_mask; /* MMU translation table base 0 mask. */
ce819861
PB
182 uint32_t c2_data; /* MPU data cachable bits. */
183 uint32_t c2_insn; /* MPU instruction cachable bits. */
184 uint32_t c3; /* MMU domain access control register
185 MPU write buffer control. */
7e09797c
PM
186 uint32_t pmsav5_data_ap; /* PMSAv5 MPU data access permissions */
187 uint32_t pmsav5_insn_ap; /* PMSAv5 MPU insn access permissions */
f149e3e8 188 uint64_t hcr_el2; /* Hypervisor configuration register */
64e0e2de 189 uint64_t scr_el3; /* Secure configuration register. */
6cd8a264 190 uint32_t ifsr_el2; /* Fault status registers. */
f2c30f42 191 uint64_t esr_el[4];
ce819861 192 uint32_t c6_region[8]; /* MPU base/size registers. */
63b60551 193 uint64_t far_el[4]; /* Fault address registers. */
19525524 194 uint64_t par_el1; /* Translation result. */
b5ff1b31
FB
195 uint32_t c9_insn; /* Cache lockdown registers. */
196 uint32_t c9_data;
8521466b
AF
197 uint64_t c9_pmcr; /* performance monitor control register */
198 uint64_t c9_pmcnten; /* perf monitor counter enables */
74594c9d
PM
199 uint32_t c9_pmovsr; /* perf monitor overflow status */
200 uint32_t c9_pmxevtyper; /* perf monitor event type */
201 uint32_t c9_pmuserenr; /* perf monitor user enable */
202 uint32_t c9_pminten; /* perf monitor interrupt enables */
b0fe2427 203 uint64_t mair_el1;
a1ba125c 204 uint64_t vbar_el[4]; /* vector base address register */
b5ff1b31 205 uint32_t c13_fcse; /* FCSE PID. */
014406b5 206 uint64_t contextidr_el1; /* Context ID. */
e4fe830b
PM
207 uint64_t tpidr_el0; /* User RW Thread register. */
208 uint64_t tpidrro_el0; /* User RO Thread register. */
209 uint64_t tpidr_el1; /* Privileged Thread register. */
a7adc4b7
PM
210 uint64_t c14_cntfrq; /* Counter Frequency register */
211 uint64_t c14_cntkctl; /* Timer Control register */
55d284af 212 ARMGenericTimer c14_timer[NUM_GTIMERS];
c1713132 213 uint32_t c15_cpar; /* XScale Coprocessor Access Register */
c3d2689d
AZ
214 uint32_t c15_ticonfig; /* TI925T configuration byte. */
215 uint32_t c15_i_max; /* Maximum D-cache dirty line index. */
216 uint32_t c15_i_min; /* Minimum D-cache dirty line index. */
217 uint32_t c15_threadid; /* TI debugger thread-ID. */
7da362d0
ML
218 uint32_t c15_config_base_address; /* SCU base address. */
219 uint32_t c15_diagnostic; /* diagnostic register */
220 uint32_t c15_power_diagnostic;
221 uint32_t c15_power_control; /* power control */
0b45451e
PM
222 uint64_t dbgbvr[16]; /* breakpoint value registers */
223 uint64_t dbgbcr[16]; /* breakpoint control registers */
224 uint64_t dbgwvr[16]; /* watchpoint value registers */
225 uint64_t dbgwcr[16]; /* watchpoint control registers */
3a298203 226 uint64_t mdscr_el1;
7c2cb42b
AF
227 /* If the counter is enabled, this stores the last time the counter
228 * was reset. Otherwise it stores the counter value
229 */
c92c0687 230 uint64_t c15_ccnt;
8521466b 231 uint64_t pmccfiltr_el0; /* Performance Monitor Filter Register */
b5ff1b31 232 } cp15;
40f137e1 233
9ee6e8bb
PB
234 struct {
235 uint32_t other_sp;
236 uint32_t vecbase;
237 uint32_t basepri;
238 uint32_t control;
239 int current_sp;
240 int exception;
241 int pending_exception;
9ee6e8bb
PB
242 } v7m;
243
abf1172f
PM
244 /* Information associated with an exception about to be taken:
245 * code which raises an exception must set cs->exception_index and
246 * the relevant parts of this structure; the cpu_do_interrupt function
247 * will then set the guest-visible registers as part of the exception
248 * entry process.
249 */
250 struct {
251 uint32_t syndrome; /* AArch64 format syndrome register */
252 uint32_t fsr; /* AArch32 format fault status register info */
253 uint64_t vaddress; /* virtual addr associated with exception, if any */
254 /* If we implement EL2 we will also need to store information
255 * about the intermediate physical address for stage 2 faults.
256 */
257 } exception;
258
fe1479c3
PB
259 /* Thumb-2 EE state. */
260 uint32_t teecr;
261 uint32_t teehbr;
262
b7bcbe95
FB
263 /* VFP coprocessor state. */
264 struct {
3926cc84
AG
265 /* VFP/Neon register state. Note that the mapping between S, D and Q
266 * views of the register bank differs between AArch64 and AArch32:
267 * In AArch32:
268 * Qn = regs[2n+1]:regs[2n]
269 * Dn = regs[n]
270 * Sn = regs[n/2] bits 31..0 for even n, and bits 63..32 for odd n
271 * (and regs[32] to regs[63] are inaccessible)
272 * In AArch64:
273 * Qn = regs[2n+1]:regs[2n]
274 * Dn = regs[2n]
275 * Sn = regs[2n] bits 31..0
276 * This corresponds to the architecturally defined mapping between
277 * the two execution states, and means we do not need to explicitly
278 * map these registers when changing states.
279 */
280 float64 regs[64];
b7bcbe95 281
40f137e1 282 uint32_t xregs[16];
b7bcbe95
FB
283 /* We store these fpcsr fields separately for convenience. */
284 int vec_len;
285 int vec_stride;
286
9ee6e8bb
PB
287 /* scratch space when Tn are not sufficient. */
288 uint32_t scratch[8];
3b46e624 289
3a492f3a
PM
290 /* fp_status is the "normal" fp status. standard_fp_status retains
291 * values corresponding to the ARM "Standard FPSCR Value", ie
292 * default-NaN, flush-to-zero, round-to-nearest and is used by
293 * any operations (generally Neon) which the architecture defines
294 * as controlled by the standard FPSCR value rather than the FPSCR.
295 *
296 * To avoid having to transfer exception bits around, we simply
297 * say that the FPSCR cumulative exception flags are the logical
298 * OR of the flags in the two fp statuses. This relies on the
299 * only thing which needs to read the exception flags being
300 * an explicit FPSCR read.
301 */
53cd6637 302 float_status fp_status;
3a492f3a 303 float_status standard_fp_status;
b7bcbe95 304 } vfp;
03d05e2d
PM
305 uint64_t exclusive_addr;
306 uint64_t exclusive_val;
307 uint64_t exclusive_high;
9ee6e8bb 308#if defined(CONFIG_USER_ONLY)
03d05e2d 309 uint64_t exclusive_test;
426f5abc 310 uint32_t exclusive_info;
9ee6e8bb 311#endif
b7bcbe95 312
18c9b560
AZ
313 /* iwMMXt coprocessor state. */
314 struct {
315 uint64_t regs[16];
316 uint64_t val;
317
318 uint32_t cregs[16];
319 } iwmmxt;
320
d8fd2954
PB
321 /* For mixed endian mode. */
322 bool bswap_code;
323
ce4defa0
PB
324#if defined(CONFIG_USER_ONLY)
325 /* For usermode syscall translation. */
326 int eabi;
327#endif
328
46747d15 329 struct CPUBreakpoint *cpu_breakpoint[16];
9ee98ce8
PM
330 struct CPUWatchpoint *cpu_watchpoint[16];
331
a316d335
FB
332 CPU_COMMON
333
9d551997 334 /* These fields after the common ones so they are preserved on reset. */
9ba8c3f4 335
581be094 336 /* Internal CPU feature flags. */
918f5dca 337 uint64_t features;
581be094 338
983fe826 339 void *nvic;
462a8bc6 340 const struct arm_boot_info *boot_info;
2c0262af
FB
341} CPUARMState;
342
778c3a06
AF
343#include "cpu-qom.h"
344
345ARMCPU *cpu_arm_init(const char *cpu_model);
2c0262af 346int cpu_arm_exec(CPUARMState *s);
9ee6e8bb 347uint32_t do_arm_semihosting(CPUARMState *env);
b5ff1b31 348
3926cc84
AG
349static inline bool is_a64(CPUARMState *env)
350{
351 return env->aarch64;
352}
353
2c0262af
FB
354/* you can call this signal handler from your SIGBUS and SIGSEGV
355 signal handlers to inform the virtual CPU of exceptions. non zero
356 is returned if the signal was handled by the virtual CPU. */
5fafdf24 357int cpu_arm_signal_handler(int host_signum, void *pinfo,
2c0262af 358 void *puc);
7510454e
AF
359int arm_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw,
360 int mmu_idx);
2c0262af 361
ec7b4ce4
AF
362/**
363 * pmccntr_sync
364 * @env: CPUARMState
365 *
366 * Synchronises the counter in the PMCCNTR. This must always be called twice,
367 * once before any action that might affect the timer and again afterwards.
368 * The function is used to swap the state of the register if required.
369 * This only happens when not in user mode (!CONFIG_USER_ONLY)
370 */
371void pmccntr_sync(CPUARMState *env);
372
76e3e1bc
PM
373/* SCTLR bit meanings. Several bits have been reused in newer
374 * versions of the architecture; in that case we define constants
375 * for both old and new bit meanings. Code which tests against those
376 * bits should probably check or otherwise arrange that the CPU
377 * is the architectural version it expects.
378 */
379#define SCTLR_M (1U << 0)
380#define SCTLR_A (1U << 1)
381#define SCTLR_C (1U << 2)
382#define SCTLR_W (1U << 3) /* up to v6; RAO in v7 */
383#define SCTLR_SA (1U << 3)
384#define SCTLR_P (1U << 4) /* up to v5; RAO in v6 and v7 */
385#define SCTLR_SA0 (1U << 4) /* v8 onward, AArch64 only */
386#define SCTLR_D (1U << 5) /* up to v5; RAO in v6 */
387#define SCTLR_CP15BEN (1U << 5) /* v7 onward */
388#define SCTLR_L (1U << 6) /* up to v5; RAO in v6 and v7; RAZ in v8 */
389#define SCTLR_B (1U << 7) /* up to v6; RAZ in v7 */
390#define SCTLR_ITD (1U << 7) /* v8 onward */
391#define SCTLR_S (1U << 8) /* up to v6; RAZ in v7 */
392#define SCTLR_SED (1U << 8) /* v8 onward */
393#define SCTLR_R (1U << 9) /* up to v6; RAZ in v7 */
394#define SCTLR_UMA (1U << 9) /* v8 onward, AArch64 only */
395#define SCTLR_F (1U << 10) /* up to v6 */
396#define SCTLR_SW (1U << 10) /* v7 onward */
397#define SCTLR_Z (1U << 11)
398#define SCTLR_I (1U << 12)
399#define SCTLR_V (1U << 13)
400#define SCTLR_RR (1U << 14) /* up to v7 */
401#define SCTLR_DZE (1U << 14) /* v8 onward, AArch64 only */
402#define SCTLR_L4 (1U << 15) /* up to v6; RAZ in v7 */
403#define SCTLR_UCT (1U << 15) /* v8 onward, AArch64 only */
404#define SCTLR_DT (1U << 16) /* up to ??, RAO in v6 and v7 */
405#define SCTLR_nTWI (1U << 16) /* v8 onward */
406#define SCTLR_HA (1U << 17)
407#define SCTLR_IT (1U << 18) /* up to ??, RAO in v6 and v7 */
408#define SCTLR_nTWE (1U << 18) /* v8 onward */
409#define SCTLR_WXN (1U << 19)
410#define SCTLR_ST (1U << 20) /* up to ??, RAZ in v6 */
411#define SCTLR_UWXN (1U << 20) /* v7 onward */
412#define SCTLR_FI (1U << 21)
413#define SCTLR_U (1U << 22)
414#define SCTLR_XP (1U << 23) /* up to v6; v7 onward RAO */
415#define SCTLR_VE (1U << 24) /* up to v7 */
416#define SCTLR_E0E (1U << 24) /* v8 onward, AArch64 only */
417#define SCTLR_EE (1U << 25)
418#define SCTLR_L2 (1U << 26) /* up to v6, RAZ in v7 */
419#define SCTLR_UCI (1U << 26) /* v8 onward, AArch64 only */
420#define SCTLR_NMFI (1U << 27)
421#define SCTLR_TRE (1U << 28)
422#define SCTLR_AFE (1U << 29)
423#define SCTLR_TE (1U << 30)
424
78dbbbe4
PM
425#define CPSR_M (0x1fU)
426#define CPSR_T (1U << 5)
427#define CPSR_F (1U << 6)
428#define CPSR_I (1U << 7)
429#define CPSR_A (1U << 8)
430#define CPSR_E (1U << 9)
431#define CPSR_IT_2_7 (0xfc00U)
432#define CPSR_GE (0xfU << 16)
4051e12c
PM
433#define CPSR_IL (1U << 20)
434/* Note that the RESERVED bits include bit 21, which is PSTATE_SS in
435 * an AArch64 SPSR but RES0 in AArch32 SPSR and CPSR. In QEMU we use
436 * env->uncached_cpsr bit 21 to store PSTATE.SS when executing in AArch32,
437 * where it is live state but not accessible to the AArch32 code.
438 */
439#define CPSR_RESERVED (0x7U << 21)
78dbbbe4
PM
440#define CPSR_J (1U << 24)
441#define CPSR_IT_0_1 (3U << 25)
442#define CPSR_Q (1U << 27)
443#define CPSR_V (1U << 28)
444#define CPSR_C (1U << 29)
445#define CPSR_Z (1U << 30)
446#define CPSR_N (1U << 31)
9ee6e8bb 447#define CPSR_NZCV (CPSR_N | CPSR_Z | CPSR_C | CPSR_V)
4cc35614 448#define CPSR_AIF (CPSR_A | CPSR_I | CPSR_F)
9ee6e8bb
PB
449
450#define CPSR_IT (CPSR_IT_0_1 | CPSR_IT_2_7)
4cc35614
PM
451#define CACHED_CPSR_BITS (CPSR_T | CPSR_AIF | CPSR_GE | CPSR_IT | CPSR_Q \
452 | CPSR_NZCV)
9ee6e8bb
PB
453/* Bits writable in user mode. */
454#define CPSR_USER (CPSR_NZCV | CPSR_Q | CPSR_GE)
455/* Execution state bits. MRS read as zero, MSR writes ignored. */
4051e12c
PM
456#define CPSR_EXEC (CPSR_T | CPSR_IT | CPSR_J | CPSR_IL)
457/* Mask of bits which may be set by exception return copying them from SPSR */
458#define CPSR_ERET_MASK (~CPSR_RESERVED)
b5ff1b31 459
e389be16
FA
460#define TTBCR_N (7U << 0) /* TTBCR.EAE==0 */
461#define TTBCR_T0SZ (7U << 0) /* TTBCR.EAE==1 */
462#define TTBCR_PD0 (1U << 4)
463#define TTBCR_PD1 (1U << 5)
464#define TTBCR_EPD0 (1U << 7)
465#define TTBCR_IRGN0 (3U << 8)
466#define TTBCR_ORGN0 (3U << 10)
467#define TTBCR_SH0 (3U << 12)
468#define TTBCR_T1SZ (3U << 16)
469#define TTBCR_A1 (1U << 22)
470#define TTBCR_EPD1 (1U << 23)
471#define TTBCR_IRGN1 (3U << 24)
472#define TTBCR_ORGN1 (3U << 26)
473#define TTBCR_SH1 (1U << 28)
474#define TTBCR_EAE (1U << 31)
475
d356312f
PM
476/* Bit definitions for ARMv8 SPSR (PSTATE) format.
477 * Only these are valid when in AArch64 mode; in
478 * AArch32 mode SPSRs are basically CPSR-format.
479 */
f502cfc2 480#define PSTATE_SP (1U)
d356312f
PM
481#define PSTATE_M (0xFU)
482#define PSTATE_nRW (1U << 4)
483#define PSTATE_F (1U << 6)
484#define PSTATE_I (1U << 7)
485#define PSTATE_A (1U << 8)
486#define PSTATE_D (1U << 9)
487#define PSTATE_IL (1U << 20)
488#define PSTATE_SS (1U << 21)
489#define PSTATE_V (1U << 28)
490#define PSTATE_C (1U << 29)
491#define PSTATE_Z (1U << 30)
492#define PSTATE_N (1U << 31)
493#define PSTATE_NZCV (PSTATE_N | PSTATE_Z | PSTATE_C | PSTATE_V)
4cc35614
PM
494#define PSTATE_DAIF (PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F)
495#define CACHED_PSTATE_BITS (PSTATE_NZCV | PSTATE_DAIF)
d356312f
PM
496/* Mode values for AArch64 */
497#define PSTATE_MODE_EL3h 13
498#define PSTATE_MODE_EL3t 12
499#define PSTATE_MODE_EL2h 9
500#define PSTATE_MODE_EL2t 8
501#define PSTATE_MODE_EL1h 5
502#define PSTATE_MODE_EL1t 4
503#define PSTATE_MODE_EL0t 0
504
9e729b57
EI
505/* Map EL and handler into a PSTATE_MODE. */
506static inline unsigned int aarch64_pstate_mode(unsigned int el, bool handler)
507{
508 return (el << 2) | handler;
509}
510
d356312f
PM
511/* Return the current PSTATE value. For the moment we don't support 32<->64 bit
512 * interprocessing, so we don't attempt to sync with the cpsr state used by
513 * the 32 bit decoder.
514 */
515static inline uint32_t pstate_read(CPUARMState *env)
516{
517 int ZF;
518
519 ZF = (env->ZF == 0);
520 return (env->NF & 0x80000000) | (ZF << 30)
521 | (env->CF << 29) | ((env->VF & 0x80000000) >> 3)
4cc35614 522 | env->pstate | env->daif;
d356312f
PM
523}
524
525static inline void pstate_write(CPUARMState *env, uint32_t val)
526{
527 env->ZF = (~val) & PSTATE_Z;
528 env->NF = val;
529 env->CF = (val >> 29) & 1;
530 env->VF = (val << 3) & 0x80000000;
4cc35614 531 env->daif = val & PSTATE_DAIF;
d356312f
PM
532 env->pstate = val & ~CACHED_PSTATE_BITS;
533}
534
b5ff1b31 535/* Return the current CPSR value. */
2f4a40e5
AZ
536uint32_t cpsr_read(CPUARMState *env);
537/* Set the CPSR. Note that some bits of mask must be all-set or all-clear. */
538void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask);
9ee6e8bb
PB
539
540/* Return the current xPSR value. */
541static inline uint32_t xpsr_read(CPUARMState *env)
542{
543 int ZF;
6fbe23d5
PB
544 ZF = (env->ZF == 0);
545 return (env->NF & 0x80000000) | (ZF << 30)
9ee6e8bb
PB
546 | (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | (env->QF << 27)
547 | (env->thumb << 24) | ((env->condexec_bits & 3) << 25)
548 | ((env->condexec_bits & 0xfc) << 8)
549 | env->v7m.exception;
b5ff1b31
FB
550}
551
9ee6e8bb
PB
552/* Set the xPSR. Note that some bits of mask must be all-set or all-clear. */
553static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
554{
9ee6e8bb 555 if (mask & CPSR_NZCV) {
6fbe23d5
PB
556 env->ZF = (~val) & CPSR_Z;
557 env->NF = val;
9ee6e8bb
PB
558 env->CF = (val >> 29) & 1;
559 env->VF = (val << 3) & 0x80000000;
560 }
561 if (mask & CPSR_Q)
562 env->QF = ((val & CPSR_Q) != 0);
563 if (mask & (1 << 24))
564 env->thumb = ((val & (1 << 24)) != 0);
565 if (mask & CPSR_IT_0_1) {
566 env->condexec_bits &= ~3;
567 env->condexec_bits |= (val >> 25) & 3;
568 }
569 if (mask & CPSR_IT_2_7) {
570 env->condexec_bits &= 3;
571 env->condexec_bits |= (val >> 8) & 0xfc;
572 }
573 if (mask & 0x1ff) {
574 env->v7m.exception = val & 0x1ff;
575 }
576}
577
f149e3e8
EI
578#define HCR_VM (1ULL << 0)
579#define HCR_SWIO (1ULL << 1)
580#define HCR_PTW (1ULL << 2)
581#define HCR_FMO (1ULL << 3)
582#define HCR_IMO (1ULL << 4)
583#define HCR_AMO (1ULL << 5)
584#define HCR_VF (1ULL << 6)
585#define HCR_VI (1ULL << 7)
586#define HCR_VSE (1ULL << 8)
587#define HCR_FB (1ULL << 9)
588#define HCR_BSU_MASK (3ULL << 10)
589#define HCR_DC (1ULL << 12)
590#define HCR_TWI (1ULL << 13)
591#define HCR_TWE (1ULL << 14)
592#define HCR_TID0 (1ULL << 15)
593#define HCR_TID1 (1ULL << 16)
594#define HCR_TID2 (1ULL << 17)
595#define HCR_TID3 (1ULL << 18)
596#define HCR_TSC (1ULL << 19)
597#define HCR_TIDCP (1ULL << 20)
598#define HCR_TACR (1ULL << 21)
599#define HCR_TSW (1ULL << 22)
600#define HCR_TPC (1ULL << 23)
601#define HCR_TPU (1ULL << 24)
602#define HCR_TTLB (1ULL << 25)
603#define HCR_TVM (1ULL << 26)
604#define HCR_TGE (1ULL << 27)
605#define HCR_TDZ (1ULL << 28)
606#define HCR_HCD (1ULL << 29)
607#define HCR_TRVM (1ULL << 30)
608#define HCR_RW (1ULL << 31)
609#define HCR_CD (1ULL << 32)
610#define HCR_ID (1ULL << 33)
611#define HCR_MASK ((1ULL << 34) - 1)
612
64e0e2de
EI
613#define SCR_NS (1U << 0)
614#define SCR_IRQ (1U << 1)
615#define SCR_FIQ (1U << 2)
616#define SCR_EA (1U << 3)
617#define SCR_FW (1U << 4)
618#define SCR_AW (1U << 5)
619#define SCR_NET (1U << 6)
620#define SCR_SMD (1U << 7)
621#define SCR_HCE (1U << 8)
622#define SCR_SIF (1U << 9)
623#define SCR_RW (1U << 10)
624#define SCR_ST (1U << 11)
625#define SCR_TWI (1U << 12)
626#define SCR_TWE (1U << 13)
627#define SCR_AARCH32_MASK (0x3fff & ~(SCR_RW | SCR_ST))
628#define SCR_AARCH64_MASK (0x3fff & ~SCR_NET)
629
01653295
PM
630/* Return the current FPSCR value. */
631uint32_t vfp_get_fpscr(CPUARMState *env);
632void vfp_set_fpscr(CPUARMState *env, uint32_t val);
633
f903fa22
PM
634/* For A64 the FPSCR is split into two logically distinct registers,
635 * FPCR and FPSR. However since they still use non-overlapping bits
636 * we store the underlying state in fpscr and just mask on read/write.
637 */
638#define FPSR_MASK 0xf800009f
639#define FPCR_MASK 0x07f79f00
640static inline uint32_t vfp_get_fpsr(CPUARMState *env)
641{
642 return vfp_get_fpscr(env) & FPSR_MASK;
643}
644
645static inline void vfp_set_fpsr(CPUARMState *env, uint32_t val)
646{
647 uint32_t new_fpscr = (vfp_get_fpscr(env) & ~FPSR_MASK) | (val & FPSR_MASK);
648 vfp_set_fpscr(env, new_fpscr);
649}
650
651static inline uint32_t vfp_get_fpcr(CPUARMState *env)
652{
653 return vfp_get_fpscr(env) & FPCR_MASK;
654}
655
656static inline void vfp_set_fpcr(CPUARMState *env, uint32_t val)
657{
658 uint32_t new_fpscr = (vfp_get_fpscr(env) & ~FPCR_MASK) | (val & FPCR_MASK);
659 vfp_set_fpscr(env, new_fpscr);
660}
661
b5ff1b31
FB
662enum arm_cpu_mode {
663 ARM_CPU_MODE_USR = 0x10,
664 ARM_CPU_MODE_FIQ = 0x11,
665 ARM_CPU_MODE_IRQ = 0x12,
666 ARM_CPU_MODE_SVC = 0x13,
28c9457d 667 ARM_CPU_MODE_MON = 0x16,
b5ff1b31 668 ARM_CPU_MODE_ABT = 0x17,
28c9457d 669 ARM_CPU_MODE_HYP = 0x1a,
b5ff1b31
FB
670 ARM_CPU_MODE_UND = 0x1b,
671 ARM_CPU_MODE_SYS = 0x1f
672};
673
40f137e1
PB
674/* VFP system registers. */
675#define ARM_VFP_FPSID 0
676#define ARM_VFP_FPSCR 1
a50c0f51 677#define ARM_VFP_MVFR2 5
9ee6e8bb
PB
678#define ARM_VFP_MVFR1 6
679#define ARM_VFP_MVFR0 7
40f137e1
PB
680#define ARM_VFP_FPEXC 8
681#define ARM_VFP_FPINST 9
682#define ARM_VFP_FPINST2 10
683
18c9b560
AZ
684/* iwMMXt coprocessor control registers. */
685#define ARM_IWMMXT_wCID 0
686#define ARM_IWMMXT_wCon 1
687#define ARM_IWMMXT_wCSSF 2
688#define ARM_IWMMXT_wCASF 3
689#define ARM_IWMMXT_wCGR0 8
690#define ARM_IWMMXT_wCGR1 9
691#define ARM_IWMMXT_wCGR2 10
692#define ARM_IWMMXT_wCGR3 11
693
ce854d7c
BC
694/* If adding a feature bit which corresponds to a Linux ELF
695 * HWCAP bit, remember to update the feature-bit-to-hwcap
696 * mapping in linux-user/elfload.c:get_elf_hwcap().
697 */
40f137e1
PB
698enum arm_features {
699 ARM_FEATURE_VFP,
c1713132
AZ
700 ARM_FEATURE_AUXCR, /* ARM1026 Auxiliary control register. */
701 ARM_FEATURE_XSCALE, /* Intel XScale extensions. */
ce819861 702 ARM_FEATURE_IWMMXT, /* Intel iwMMXt extension. */
9ee6e8bb
PB
703 ARM_FEATURE_V6,
704 ARM_FEATURE_V6K,
705 ARM_FEATURE_V7,
706 ARM_FEATURE_THUMB2,
c3d2689d 707 ARM_FEATURE_MPU, /* Only has Memory Protection Unit, not full MMU. */
9ee6e8bb 708 ARM_FEATURE_VFP3,
60011498 709 ARM_FEATURE_VFP_FP16,
9ee6e8bb 710 ARM_FEATURE_NEON,
47789990 711 ARM_FEATURE_THUMB_DIV, /* divide supported in Thumb encoding */
9ee6e8bb 712 ARM_FEATURE_M, /* Microcontroller profile. */
fe1479c3 713 ARM_FEATURE_OMAPCP, /* OMAP specific CP15 ops handling. */
e1bbf446 714 ARM_FEATURE_THUMB2EE,
be5e7a76
DES
715 ARM_FEATURE_V7MP, /* v7 Multiprocessing Extensions */
716 ARM_FEATURE_V4T,
717 ARM_FEATURE_V5,
5bc95aa2 718 ARM_FEATURE_STRONGARM,
906879a9 719 ARM_FEATURE_VAPA, /* cp15 VA to PA lookups */
b8b8ea05 720 ARM_FEATURE_ARM_DIV, /* divide supported in ARM encoding */
da97f52c 721 ARM_FEATURE_VFP4, /* VFPv4 (implies that NEON is v2) */
0383ac00 722 ARM_FEATURE_GENERIC_TIMER,
06ed5d66 723 ARM_FEATURE_MVFR, /* Media and VFP Feature Registers 0 and 1 */
1047b9d7 724 ARM_FEATURE_DUMMY_C15_REGS, /* RAZ/WI all of cp15 crn=15 */
c4804214
PM
725 ARM_FEATURE_CACHE_TEST_CLEAN, /* 926/1026 style test-and-clean ops */
726 ARM_FEATURE_CACHE_DIRTY_REG, /* 1136/1176 cache dirty status register */
727 ARM_FEATURE_CACHE_BLOCK_OPS, /* v6 optional cache block operations */
81bdde9d 728 ARM_FEATURE_MPIDR, /* has cp15 MPIDR */
de9b05b8
PM
729 ARM_FEATURE_PXN, /* has Privileged Execute Never bit */
730 ARM_FEATURE_LPAE, /* has Large Physical Address Extension */
81e69fb0 731 ARM_FEATURE_V8,
3926cc84 732 ARM_FEATURE_AARCH64, /* supports 64 bit mode */
9d935509 733 ARM_FEATURE_V8_AES, /* implements AES part of v8 Crypto Extensions */
d8ba780b 734 ARM_FEATURE_CBAR, /* has cp15 CBAR */
eb0ecd5a 735 ARM_FEATURE_CRC, /* ARMv8 CRC instructions */
f318cec6 736 ARM_FEATURE_CBAR_RO, /* has cp15 CBAR and it is read-only */
cca7c2f5 737 ARM_FEATURE_EL2, /* has EL2 Virtualization support */
1fe8141e 738 ARM_FEATURE_EL3, /* has EL3 Secure monitor support */
f1ecb913
AB
739 ARM_FEATURE_V8_SHA1, /* implements SHA1 part of v8 Crypto Extensions */
740 ARM_FEATURE_V8_SHA256, /* implements SHA256 part of v8 Crypto Extensions */
4e624eda 741 ARM_FEATURE_V8_PMULL, /* implements PMULL part of v8 Crypto Extensions */
40f137e1
PB
742};
743
744static inline int arm_feature(CPUARMState *env, int feature)
745{
918f5dca 746 return (env->features & (1ULL << feature)) != 0;
40f137e1
PB
747}
748
1f79ee32
PM
749/* Return true if the specified exception level is running in AArch64 state. */
750static inline bool arm_el_is_aa64(CPUARMState *env, int el)
751{
752 /* We don't currently support EL2 or EL3, and this isn't valid for EL0
753 * (if we're in EL0, is_a64() is what you want, and if we're not in EL0
754 * then the state of EL0 isn't well defined.)
755 */
756 assert(el == 1);
757 /* AArch64-capable CPUs always run with EL1 in AArch64 mode. This
758 * is a QEMU-imposed simplification which we may wish to change later.
759 * If we in future support EL2 and/or EL3, then the state of lower
760 * exception levels is controlled by the HCR.RW and SCR.RW bits.
761 */
762 return arm_feature(env, ARM_FEATURE_AARCH64);
763}
764
9a78eead 765void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf);
9e729b57 766unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx);
40f137e1 767
9ee6e8bb
PB
768/* Interface between CPU and Interrupt controller. */
769void armv7m_nvic_set_pending(void *opaque, int irq);
770int armv7m_nvic_acknowledge_irq(void *opaque);
771void armv7m_nvic_complete_irq(void *opaque, int irq);
772
4b6a83fb
PM
773/* Interface for defining coprocessor registers.
774 * Registers are defined in tables of arm_cp_reginfo structs
775 * which are passed to define_arm_cp_regs().
776 */
777
778/* When looking up a coprocessor register we look for it
779 * via an integer which encodes all of:
780 * coprocessor number
781 * Crn, Crm, opc1, opc2 fields
782 * 32 or 64 bit register (ie is it accessed via MRC/MCR
783 * or via MRRC/MCRR?)
784 * We allow 4 bits for opc1 because MRRC/MCRR have a 4 bit field.
785 * (In this case crn and opc2 should be zero.)
f5a0a5a5
PM
786 * For AArch64, there is no 32/64 bit size distinction;
787 * instead all registers have a 2 bit op0, 3 bit op1 and op2,
788 * and 4 bit CRn and CRm. The encoding patterns are chosen
789 * to be easy to convert to and from the KVM encodings, and also
790 * so that the hashtable can contain both AArch32 and AArch64
791 * registers (to allow for interprocessing where we might run
792 * 32 bit code on a 64 bit core).
4b6a83fb 793 */
f5a0a5a5
PM
794/* This bit is private to our hashtable cpreg; in KVM register
795 * IDs the AArch64/32 distinction is the KVM_REG_ARM/ARM64
796 * in the upper bits of the 64 bit ID.
797 */
798#define CP_REG_AA64_SHIFT 28
799#define CP_REG_AA64_MASK (1 << CP_REG_AA64_SHIFT)
800
4b6a83fb
PM
801#define ENCODE_CP_REG(cp, is64, crn, crm, opc1, opc2) \
802 (((cp) << 16) | ((is64) << 15) | ((crn) << 11) | \
803 ((crm) << 7) | ((opc1) << 3) | (opc2))
804
f5a0a5a5
PM
805#define ENCODE_AA64_CP_REG(cp, crn, crm, op0, op1, op2) \
806 (CP_REG_AA64_MASK | \
807 ((cp) << CP_REG_ARM_COPROC_SHIFT) | \
808 ((op0) << CP_REG_ARM64_SYSREG_OP0_SHIFT) | \
809 ((op1) << CP_REG_ARM64_SYSREG_OP1_SHIFT) | \
810 ((crn) << CP_REG_ARM64_SYSREG_CRN_SHIFT) | \
811 ((crm) << CP_REG_ARM64_SYSREG_CRM_SHIFT) | \
812 ((op2) << CP_REG_ARM64_SYSREG_OP2_SHIFT))
813
721fae12
PM
814/* Convert a full 64 bit KVM register ID to the truncated 32 bit
815 * version used as a key for the coprocessor register hashtable
816 */
817static inline uint32_t kvm_to_cpreg_id(uint64_t kvmid)
818{
819 uint32_t cpregid = kvmid;
f5a0a5a5
PM
820 if ((kvmid & CP_REG_ARCH_MASK) == CP_REG_ARM64) {
821 cpregid |= CP_REG_AA64_MASK;
822 } else if ((kvmid & CP_REG_SIZE_MASK) == CP_REG_SIZE_U64) {
721fae12
PM
823 cpregid |= (1 << 15);
824 }
825 return cpregid;
826}
827
828/* Convert a truncated 32 bit hashtable key into the full
829 * 64 bit KVM register ID.
830 */
831static inline uint64_t cpreg_to_kvm_id(uint32_t cpregid)
832{
f5a0a5a5
PM
833 uint64_t kvmid;
834
835 if (cpregid & CP_REG_AA64_MASK) {
836 kvmid = cpregid & ~CP_REG_AA64_MASK;
837 kvmid |= CP_REG_SIZE_U64 | CP_REG_ARM64;
721fae12 838 } else {
f5a0a5a5
PM
839 kvmid = cpregid & ~(1 << 15);
840 if (cpregid & (1 << 15)) {
841 kvmid |= CP_REG_SIZE_U64 | CP_REG_ARM;
842 } else {
843 kvmid |= CP_REG_SIZE_U32 | CP_REG_ARM;
844 }
721fae12
PM
845 }
846 return kvmid;
847}
848
4b6a83fb
PM
849/* ARMCPRegInfo type field bits. If the SPECIAL bit is set this is a
850 * special-behaviour cp reg and bits [15..8] indicate what behaviour
851 * it has. Otherwise it is a simple cp reg, where CONST indicates that
852 * TCG can assume the value to be constant (ie load at translate time)
853 * and 64BIT indicates a 64 bit wide coprocessor register. SUPPRESS_TB_END
854 * indicates that the TB should not be ended after a write to this register
855 * (the default is that the TB ends after cp writes). OVERRIDE permits
856 * a register definition to override a previous definition for the
857 * same (cp, is64, crn, crm, opc1, opc2) tuple: either the new or the
858 * old must have the OVERRIDE bit set.
7023ec7e
PM
859 * NO_MIGRATE indicates that this register should be ignored for migration;
860 * (eg because any state is accessed via some other coprocessor register).
2452731c
PM
861 * IO indicates that this register does I/O and therefore its accesses
862 * need to be surrounded by gen_io_start()/gen_io_end(). In particular,
863 * registers which implement clocks or timers require this.
4b6a83fb
PM
864 */
865#define ARM_CP_SPECIAL 1
866#define ARM_CP_CONST 2
867#define ARM_CP_64BIT 4
868#define ARM_CP_SUPPRESS_TB_END 8
869#define ARM_CP_OVERRIDE 16
7023ec7e 870#define ARM_CP_NO_MIGRATE 32
2452731c 871#define ARM_CP_IO 64
4b6a83fb
PM
872#define ARM_CP_NOP (ARM_CP_SPECIAL | (1 << 8))
873#define ARM_CP_WFI (ARM_CP_SPECIAL | (2 << 8))
b0d2b7d0 874#define ARM_CP_NZCV (ARM_CP_SPECIAL | (3 << 8))
0eef9d98 875#define ARM_CP_CURRENTEL (ARM_CP_SPECIAL | (4 << 8))
aca3f40b
PM
876#define ARM_CP_DC_ZVA (ARM_CP_SPECIAL | (5 << 8))
877#define ARM_LAST_SPECIAL ARM_CP_DC_ZVA
4b6a83fb
PM
878/* Used only as a terminator for ARMCPRegInfo lists */
879#define ARM_CP_SENTINEL 0xffff
880/* Mask of only the flag bits in a type field */
2452731c 881#define ARM_CP_FLAG_MASK 0x7f
4b6a83fb 882
f5a0a5a5
PM
883/* Valid values for ARMCPRegInfo state field, indicating which of
884 * the AArch32 and AArch64 execution states this register is visible in.
885 * If the reginfo doesn't explicitly specify then it is AArch32 only.
886 * If the reginfo is declared to be visible in both states then a second
887 * reginfo is synthesised for the AArch32 view of the AArch64 register,
888 * such that the AArch32 view is the lower 32 bits of the AArch64 one.
889 * Note that we rely on the values of these enums as we iterate through
890 * the various states in some places.
891 */
892enum {
893 ARM_CP_STATE_AA32 = 0,
894 ARM_CP_STATE_AA64 = 1,
895 ARM_CP_STATE_BOTH = 2,
896};
897
4b6a83fb
PM
898/* Return true if cptype is a valid type field. This is used to try to
899 * catch errors where the sentinel has been accidentally left off the end
900 * of a list of registers.
901 */
902static inline bool cptype_valid(int cptype)
903{
904 return ((cptype & ~ARM_CP_FLAG_MASK) == 0)
905 || ((cptype & ARM_CP_SPECIAL) &&
34affeef 906 ((cptype & ~ARM_CP_FLAG_MASK) <= ARM_LAST_SPECIAL));
4b6a83fb
PM
907}
908
909/* Access rights:
910 * We define bits for Read and Write access for what rev C of the v7-AR ARM ARM
911 * defines as PL0 (user), PL1 (fiq/irq/svc/abt/und/sys, ie privileged), and
912 * PL2 (hyp). The other level which has Read and Write bits is Secure PL1
913 * (ie any of the privileged modes in Secure state, or Monitor mode).
914 * If a register is accessible in one privilege level it's always accessible
915 * in higher privilege levels too. Since "Secure PL1" also follows this rule
916 * (ie anything visible in PL2 is visible in S-PL1, some things are only
917 * visible in S-PL1) but "Secure PL1" is a bit of a mouthful, we bend the
918 * terminology a little and call this PL3.
f5a0a5a5
PM
919 * In AArch64 things are somewhat simpler as the PLx bits line up exactly
920 * with the ELx exception levels.
4b6a83fb
PM
921 *
922 * If access permissions for a register are more complex than can be
923 * described with these bits, then use a laxer set of restrictions, and
924 * do the more restrictive/complex check inside a helper function.
925 */
926#define PL3_R 0x80
927#define PL3_W 0x40
928#define PL2_R (0x20 | PL3_R)
929#define PL2_W (0x10 | PL3_W)
930#define PL1_R (0x08 | PL2_R)
931#define PL1_W (0x04 | PL2_W)
932#define PL0_R (0x02 | PL1_R)
933#define PL0_W (0x01 | PL1_W)
934
935#define PL3_RW (PL3_R | PL3_W)
936#define PL2_RW (PL2_R | PL2_W)
937#define PL1_RW (PL1_R | PL1_W)
938#define PL0_RW (PL0_R | PL0_W)
939
940static inline int arm_current_pl(CPUARMState *env)
941{
f5a0a5a5
PM
942 if (env->aarch64) {
943 return extract32(env->pstate, 2, 2);
944 }
945
4b6a83fb
PM
946 if ((env->uncached_cpsr & 0x1f) == ARM_CPU_MODE_USR) {
947 return 0;
948 }
949 /* We don't currently implement the Virtualization or TrustZone
950 * extensions, so PL2 and PL3 don't exist for us.
951 */
952 return 1;
953}
954
955typedef struct ARMCPRegInfo ARMCPRegInfo;
956
f59df3f2
PM
957typedef enum CPAccessResult {
958 /* Access is permitted */
959 CP_ACCESS_OK = 0,
960 /* Access fails due to a configurable trap or enable which would
961 * result in a categorized exception syndrome giving information about
962 * the failing instruction (ie syndrome category 0x3, 0x4, 0x5, 0x6,
963 * 0xc or 0x18).
964 */
965 CP_ACCESS_TRAP = 1,
966 /* Access fails and results in an exception syndrome 0x0 ("uncategorized").
967 * Note that this is not a catch-all case -- the set of cases which may
968 * result in this failure is specifically defined by the architecture.
969 */
970 CP_ACCESS_TRAP_UNCATEGORIZED = 2,
971} CPAccessResult;
972
c4241c7d
PM
973/* Access functions for coprocessor registers. These cannot fail and
974 * may not raise exceptions.
975 */
976typedef uint64_t CPReadFn(CPUARMState *env, const ARMCPRegInfo *opaque);
977typedef void CPWriteFn(CPUARMState *env, const ARMCPRegInfo *opaque,
978 uint64_t value);
f59df3f2
PM
979/* Access permission check functions for coprocessor registers. */
980typedef CPAccessResult CPAccessFn(CPUARMState *env, const ARMCPRegInfo *opaque);
4b6a83fb
PM
981/* Hook function for register reset */
982typedef void CPResetFn(CPUARMState *env, const ARMCPRegInfo *opaque);
983
984#define CP_ANY 0xff
985
986/* Definition of an ARM coprocessor register */
987struct ARMCPRegInfo {
988 /* Name of register (useful mainly for debugging, need not be unique) */
989 const char *name;
990 /* Location of register: coprocessor number and (crn,crm,opc1,opc2)
991 * tuple. Any of crm, opc1 and opc2 may be CP_ANY to indicate a
992 * 'wildcard' field -- any value of that field in the MRC/MCR insn
993 * will be decoded to this register. The register read and write
994 * callbacks will be passed an ARMCPRegInfo with the crn/crm/opc1/opc2
995 * used by the program, so it is possible to register a wildcard and
996 * then behave differently on read/write if necessary.
997 * For 64 bit registers, only crm and opc1 are relevant; crn and opc2
998 * must both be zero.
f5a0a5a5
PM
999 * For AArch64-visible registers, opc0 is also used.
1000 * Since there are no "coprocessors" in AArch64, cp is purely used as a
1001 * way to distinguish (for KVM's benefit) guest-visible system registers
1002 * from demuxed ones provided to preserve the "no side effects on
1003 * KVM register read/write from QEMU" semantics. cp==0x13 is guest
1004 * visible (to match KVM's encoding); cp==0 will be converted to
1005 * cp==0x13 when the ARMCPRegInfo is registered, for convenience.
4b6a83fb
PM
1006 */
1007 uint8_t cp;
1008 uint8_t crn;
1009 uint8_t crm;
f5a0a5a5 1010 uint8_t opc0;
4b6a83fb
PM
1011 uint8_t opc1;
1012 uint8_t opc2;
f5a0a5a5
PM
1013 /* Execution state in which this register is visible: ARM_CP_STATE_* */
1014 int state;
4b6a83fb
PM
1015 /* Register type: ARM_CP_* bits/values */
1016 int type;
1017 /* Access rights: PL*_[RW] */
1018 int access;
1019 /* The opaque pointer passed to define_arm_cp_regs_with_opaque() when
1020 * this register was defined: can be used to hand data through to the
1021 * register read/write functions, since they are passed the ARMCPRegInfo*.
1022 */
1023 void *opaque;
1024 /* Value of this register, if it is ARM_CP_CONST. Otherwise, if
1025 * fieldoffset is non-zero, the reset value of the register.
1026 */
1027 uint64_t resetvalue;
1028 /* Offset of the field in CPUARMState for this register. This is not
1029 * needed if either:
1030 * 1. type is ARM_CP_CONST or one of the ARM_CP_SPECIALs
1031 * 2. both readfn and writefn are specified
1032 */
1033 ptrdiff_t fieldoffset; /* offsetof(CPUARMState, field) */
f59df3f2
PM
1034 /* Function for making any access checks for this register in addition to
1035 * those specified by the 'access' permissions bits. If NULL, no extra
1036 * checks required. The access check is performed at runtime, not at
1037 * translate time.
1038 */
1039 CPAccessFn *accessfn;
4b6a83fb
PM
1040 /* Function for handling reads of this register. If NULL, then reads
1041 * will be done by loading from the offset into CPUARMState specified
1042 * by fieldoffset.
1043 */
1044 CPReadFn *readfn;
1045 /* Function for handling writes of this register. If NULL, then writes
1046 * will be done by writing to the offset into CPUARMState specified
1047 * by fieldoffset.
1048 */
1049 CPWriteFn *writefn;
7023ec7e
PM
1050 /* Function for doing a "raw" read; used when we need to copy
1051 * coprocessor state to the kernel for KVM or out for
1052 * migration. This only needs to be provided if there is also a
c4241c7d 1053 * readfn and it has side effects (for instance clear-on-read bits).
7023ec7e
PM
1054 */
1055 CPReadFn *raw_readfn;
1056 /* Function for doing a "raw" write; used when we need to copy KVM
1057 * kernel coprocessor state into userspace, or for inbound
1058 * migration. This only needs to be provided if there is also a
c4241c7d
PM
1059 * writefn and it masks out "unwritable" bits or has write-one-to-clear
1060 * or similar behaviour.
7023ec7e
PM
1061 */
1062 CPWriteFn *raw_writefn;
4b6a83fb
PM
1063 /* Function for resetting the register. If NULL, then reset will be done
1064 * by writing resetvalue to the field specified in fieldoffset. If
1065 * fieldoffset is 0 then no reset will be done.
1066 */
1067 CPResetFn *resetfn;
1068};
1069
1070/* Macros which are lvalues for the field in CPUARMState for the
1071 * ARMCPRegInfo *ri.
1072 */
1073#define CPREG_FIELD32(env, ri) \
1074 (*(uint32_t *)((char *)(env) + (ri)->fieldoffset))
1075#define CPREG_FIELD64(env, ri) \
1076 (*(uint64_t *)((char *)(env) + (ri)->fieldoffset))
1077
1078#define REGINFO_SENTINEL { .type = ARM_CP_SENTINEL }
1079
1080void define_arm_cp_regs_with_opaque(ARMCPU *cpu,
1081 const ARMCPRegInfo *regs, void *opaque);
1082void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
1083 const ARMCPRegInfo *regs, void *opaque);
1084static inline void define_arm_cp_regs(ARMCPU *cpu, const ARMCPRegInfo *regs)
1085{
1086 define_arm_cp_regs_with_opaque(cpu, regs, 0);
1087}
1088static inline void define_one_arm_cp_reg(ARMCPU *cpu, const ARMCPRegInfo *regs)
1089{
1090 define_one_arm_cp_reg_with_opaque(cpu, regs, 0);
1091}
60322b39 1092const ARMCPRegInfo *get_arm_cp_reginfo(GHashTable *cpregs, uint32_t encoded_cp);
4b6a83fb
PM
1093
1094/* CPWriteFn that can be used to implement writes-ignored behaviour */
c4241c7d
PM
1095void arm_cp_write_ignore(CPUARMState *env, const ARMCPRegInfo *ri,
1096 uint64_t value);
4b6a83fb 1097/* CPReadFn that can be used for read-as-zero behaviour */
c4241c7d 1098uint64_t arm_cp_read_zero(CPUARMState *env, const ARMCPRegInfo *ri);
4b6a83fb 1099
f5a0a5a5
PM
1100/* CPResetFn that does nothing, for use if no reset is required even
1101 * if fieldoffset is non zero.
1102 */
1103void arm_cp_reset_ignore(CPUARMState *env, const ARMCPRegInfo *opaque);
1104
67ed771d
PM
1105/* Return true if this reginfo struct's field in the cpu state struct
1106 * is 64 bits wide.
1107 */
1108static inline bool cpreg_field_is_64bit(const ARMCPRegInfo *ri)
1109{
1110 return (ri->state == ARM_CP_STATE_AA64) || (ri->type & ARM_CP_64BIT);
1111}
1112
60322b39 1113static inline bool cp_access_ok(int current_pl,
4b6a83fb
PM
1114 const ARMCPRegInfo *ri, int isread)
1115{
60322b39 1116 return (ri->access >> ((current_pl * 2) + isread)) & 1;
4b6a83fb
PM
1117}
1118
721fae12
PM
1119/**
1120 * write_list_to_cpustate
1121 * @cpu: ARMCPU
1122 *
1123 * For each register listed in the ARMCPU cpreg_indexes list, write
1124 * its value from the cpreg_values list into the ARMCPUState structure.
1125 * This updates TCG's working data structures from KVM data or
1126 * from incoming migration state.
1127 *
1128 * Returns: true if all register values were updated correctly,
1129 * false if some register was unknown or could not be written.
1130 * Note that we do not stop early on failure -- we will attempt
1131 * writing all registers in the list.
1132 */
1133bool write_list_to_cpustate(ARMCPU *cpu);
1134
1135/**
1136 * write_cpustate_to_list:
1137 * @cpu: ARMCPU
1138 *
1139 * For each register listed in the ARMCPU cpreg_indexes list, write
1140 * its value from the ARMCPUState structure into the cpreg_values list.
1141 * This is used to copy info from TCG's working data structures into
1142 * KVM or for outbound migration.
1143 *
1144 * Returns: true if all register values were read correctly,
1145 * false if some register was unknown or could not be read.
1146 * Note that we do not stop early on failure -- we will attempt
1147 * reading all registers in the list.
1148 */
1149bool write_cpustate_to_list(ARMCPU *cpu);
1150
9ee6e8bb
PB
1151/* Does the core conform to the the "MicroController" profile. e.g. Cortex-M3.
1152 Note the M in older cores (eg. ARM7TDMI) stands for Multiply. These are
1153 conventional cores (ie. Application or Realtime profile). */
1154
1155#define IS_M(env) arm_feature(env, ARM_FEATURE_M)
9ee6e8bb 1156
9ee6e8bb
PB
1157#define ARM_CPUID_TI915T 0x54029152
1158#define ARM_CPUID_TI925T 0x54029252
40f137e1 1159
b5ff1b31 1160#if defined(CONFIG_USER_ONLY)
2c0262af 1161#define TARGET_PAGE_BITS 12
b5ff1b31
FB
1162#else
1163/* The ARM MMU allows 1k pages. */
1164/* ??? Linux doesn't actually use these, and they're deprecated in recent
82d17978 1165 architecture revisions. Maybe a configure option to disable them. */
b5ff1b31
FB
1166#define TARGET_PAGE_BITS 10
1167#endif
9467d44c 1168
3926cc84
AG
1169#if defined(TARGET_AARCH64)
1170# define TARGET_PHYS_ADDR_SPACE_BITS 48
1171# define TARGET_VIRT_ADDR_SPACE_BITS 64
1172#else
1173# define TARGET_PHYS_ADDR_SPACE_BITS 40
1174# define TARGET_VIRT_ADDR_SPACE_BITS 32
1175#endif
52705890 1176
043b7f8d
EI
1177static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)
1178{
1179 CPUARMState *env = cs->env_ptr;
dfafd090
EI
1180 unsigned int cur_el = arm_current_pl(env);
1181 unsigned int target_el = arm_excp_target_el(cs, excp_idx);
1182
1183 /* Don't take exceptions if they target a lower EL. */
1184 if (cur_el > target_el) {
1185 return false;
1186 }
043b7f8d
EI
1187
1188 switch (excp_idx) {
1189 case EXCP_FIQ:
1190 return !(env->daif & PSTATE_F);
1191 case EXCP_IRQ:
1192 return !(env->daif & PSTATE_I)
1193 && (!IS_M(env) || env->regs[15] < 0xfffffff0);
1194 default:
1195 g_assert_not_reached();
1196 }
1197}
1198
ad37ad5b
PM
1199static inline CPUARMState *cpu_init(const char *cpu_model)
1200{
1201 ARMCPU *cpu = cpu_arm_init(cpu_model);
1202 if (cpu) {
1203 return &cpu->env;
1204 }
1205 return NULL;
1206}
1207
9467d44c
TS
1208#define cpu_exec cpu_arm_exec
1209#define cpu_gen_code cpu_arm_gen_code
1210#define cpu_signal_handler cpu_arm_signal_handler
c732abe2 1211#define cpu_list arm_cpu_list
9467d44c 1212
6ebbf390 1213/* MMU modes definitions */
f79fbf39
EI
1214#define MMU_MODE0_SUFFIX _user
1215#define MMU_MODE1_SUFFIX _kernel
1216#define MMU_USER_IDX 0
0ecb72a5 1217static inline int cpu_mmu_index (CPUARMState *env)
6ebbf390 1218{
f79fbf39 1219 return arm_current_pl(env);
6ebbf390
JM
1220}
1221
3a298203
PM
1222/* Return the Exception Level targeted by debug exceptions;
1223 * currently always EL1 since we don't implement EL2 or EL3.
1224 */
1225static inline int arm_debug_target_el(CPUARMState *env)
1226{
1227 return 1;
1228}
1229
1230static inline bool aa64_generate_debug_exceptions(CPUARMState *env)
1231{
1232 if (arm_current_pl(env) == arm_debug_target_el(env)) {
1233 if ((extract32(env->cp15.mdscr_el1, 13, 1) == 0)
1234 || (env->daif & PSTATE_D)) {
1235 return false;
1236 }
1237 }
1238 return true;
1239}
1240
1241static inline bool aa32_generate_debug_exceptions(CPUARMState *env)
1242{
1243 if (arm_current_pl(env) == 0 && arm_el_is_aa64(env, 1)) {
1244 return aa64_generate_debug_exceptions(env);
1245 }
1246 return arm_current_pl(env) != 2;
1247}
1248
1249/* Return true if debugging exceptions are currently enabled.
1250 * This corresponds to what in ARM ARM pseudocode would be
1251 * if UsingAArch32() then
1252 * return AArch32.GenerateDebugExceptions()
1253 * else
1254 * return AArch64.GenerateDebugExceptions()
1255 * We choose to push the if() down into this function for clarity,
1256 * since the pseudocode has it at all callsites except for the one in
1257 * CheckSoftwareStep(), where it is elided because both branches would
1258 * always return the same value.
1259 *
1260 * Parts of the pseudocode relating to EL2 and EL3 are omitted because we
1261 * don't yet implement those exception levels or their associated trap bits.
1262 */
1263static inline bool arm_generate_debug_exceptions(CPUARMState *env)
1264{
1265 if (env->aarch64) {
1266 return aa64_generate_debug_exceptions(env);
1267 } else {
1268 return aa32_generate_debug_exceptions(env);
1269 }
1270}
1271
1272/* Is single-stepping active? (Note that the "is EL_D AArch64?" check
1273 * implicitly means this always returns false in pre-v8 CPUs.)
1274 */
1275static inline bool arm_singlestep_active(CPUARMState *env)
1276{
1277 return extract32(env->cp15.mdscr_el1, 0, 1)
1278 && arm_el_is_aa64(env, arm_debug_target_el(env))
1279 && arm_generate_debug_exceptions(env);
1280}
1281
022c62cb 1282#include "exec/cpu-all.h"
622ed360 1283
3926cc84
AG
1284/* Bit usage in the TB flags field: bit 31 indicates whether we are
1285 * in 32 or 64 bit mode. The meaning of the other bits depends on that.
1286 */
1287#define ARM_TBFLAG_AARCH64_STATE_SHIFT 31
1288#define ARM_TBFLAG_AARCH64_STATE_MASK (1U << ARM_TBFLAG_AARCH64_STATE_SHIFT)
1289
1290/* Bit usage when in AArch32 state: */
a1705768
PM
1291#define ARM_TBFLAG_THUMB_SHIFT 0
1292#define ARM_TBFLAG_THUMB_MASK (1 << ARM_TBFLAG_THUMB_SHIFT)
1293#define ARM_TBFLAG_VECLEN_SHIFT 1
1294#define ARM_TBFLAG_VECLEN_MASK (0x7 << ARM_TBFLAG_VECLEN_SHIFT)
1295#define ARM_TBFLAG_VECSTRIDE_SHIFT 4
1296#define ARM_TBFLAG_VECSTRIDE_MASK (0x3 << ARM_TBFLAG_VECSTRIDE_SHIFT)
1297#define ARM_TBFLAG_PRIV_SHIFT 6
1298#define ARM_TBFLAG_PRIV_MASK (1 << ARM_TBFLAG_PRIV_SHIFT)
1299#define ARM_TBFLAG_VFPEN_SHIFT 7
1300#define ARM_TBFLAG_VFPEN_MASK (1 << ARM_TBFLAG_VFPEN_SHIFT)
1301#define ARM_TBFLAG_CONDEXEC_SHIFT 8
1302#define ARM_TBFLAG_CONDEXEC_MASK (0xff << ARM_TBFLAG_CONDEXEC_SHIFT)
d8fd2954
PB
1303#define ARM_TBFLAG_BSWAP_CODE_SHIFT 16
1304#define ARM_TBFLAG_BSWAP_CODE_MASK (1 << ARM_TBFLAG_BSWAP_CODE_SHIFT)
2c7ffc41
PM
1305#define ARM_TBFLAG_CPACR_FPEN_SHIFT 17
1306#define ARM_TBFLAG_CPACR_FPEN_MASK (1 << ARM_TBFLAG_CPACR_FPEN_SHIFT)
50225ad0
PM
1307#define ARM_TBFLAG_SS_ACTIVE_SHIFT 18
1308#define ARM_TBFLAG_SS_ACTIVE_MASK (1 << ARM_TBFLAG_SS_ACTIVE_SHIFT)
1309#define ARM_TBFLAG_PSTATE_SS_SHIFT 19
1310#define ARM_TBFLAG_PSTATE_SS_MASK (1 << ARM_TBFLAG_PSTATE_SS_SHIFT)
c0f4af17
PM
1311/* We store the bottom two bits of the CPAR as TB flags and handle
1312 * checks on the other bits at runtime
1313 */
1314#define ARM_TBFLAG_XSCALE_CPAR_SHIFT 20
1315#define ARM_TBFLAG_XSCALE_CPAR_MASK (3 << ARM_TBFLAG_XSCALE_CPAR_SHIFT)
3926cc84 1316
d9ea7d29
PM
1317/* Bit usage when in AArch64 state */
1318#define ARM_TBFLAG_AA64_EL_SHIFT 0
1319#define ARM_TBFLAG_AA64_EL_MASK (0x3 << ARM_TBFLAG_AA64_EL_SHIFT)
8c6afa6a
PM
1320#define ARM_TBFLAG_AA64_FPEN_SHIFT 2
1321#define ARM_TBFLAG_AA64_FPEN_MASK (1 << ARM_TBFLAG_AA64_FPEN_SHIFT)
7ea47fe7
PM
1322#define ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT 3
1323#define ARM_TBFLAG_AA64_SS_ACTIVE_MASK (1 << ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT)
1324#define ARM_TBFLAG_AA64_PSTATE_SS_SHIFT 4
1325#define ARM_TBFLAG_AA64_PSTATE_SS_MASK (1 << ARM_TBFLAG_AA64_PSTATE_SS_SHIFT)
a1705768
PM
1326
1327/* some convenience accessor macros */
3926cc84
AG
1328#define ARM_TBFLAG_AARCH64_STATE(F) \
1329 (((F) & ARM_TBFLAG_AARCH64_STATE_MASK) >> ARM_TBFLAG_AARCH64_STATE_SHIFT)
a1705768
PM
1330#define ARM_TBFLAG_THUMB(F) \
1331 (((F) & ARM_TBFLAG_THUMB_MASK) >> ARM_TBFLAG_THUMB_SHIFT)
1332#define ARM_TBFLAG_VECLEN(F) \
1333 (((F) & ARM_TBFLAG_VECLEN_MASK) >> ARM_TBFLAG_VECLEN_SHIFT)
1334#define ARM_TBFLAG_VECSTRIDE(F) \
1335 (((F) & ARM_TBFLAG_VECSTRIDE_MASK) >> ARM_TBFLAG_VECSTRIDE_SHIFT)
1336#define ARM_TBFLAG_PRIV(F) \
1337 (((F) & ARM_TBFLAG_PRIV_MASK) >> ARM_TBFLAG_PRIV_SHIFT)
1338#define ARM_TBFLAG_VFPEN(F) \
1339 (((F) & ARM_TBFLAG_VFPEN_MASK) >> ARM_TBFLAG_VFPEN_SHIFT)
1340#define ARM_TBFLAG_CONDEXEC(F) \
1341 (((F) & ARM_TBFLAG_CONDEXEC_MASK) >> ARM_TBFLAG_CONDEXEC_SHIFT)
d8fd2954
PB
1342#define ARM_TBFLAG_BSWAP_CODE(F) \
1343 (((F) & ARM_TBFLAG_BSWAP_CODE_MASK) >> ARM_TBFLAG_BSWAP_CODE_SHIFT)
2c7ffc41
PM
1344#define ARM_TBFLAG_CPACR_FPEN(F) \
1345 (((F) & ARM_TBFLAG_CPACR_FPEN_MASK) >> ARM_TBFLAG_CPACR_FPEN_SHIFT)
50225ad0
PM
1346#define ARM_TBFLAG_SS_ACTIVE(F) \
1347 (((F) & ARM_TBFLAG_SS_ACTIVE_MASK) >> ARM_TBFLAG_SS_ACTIVE_SHIFT)
1348#define ARM_TBFLAG_PSTATE_SS(F) \
1349 (((F) & ARM_TBFLAG_PSTATE_SS_MASK) >> ARM_TBFLAG_PSTATE_SS_SHIFT)
c0f4af17
PM
1350#define ARM_TBFLAG_XSCALE_CPAR(F) \
1351 (((F) & ARM_TBFLAG_XSCALE_CPAR_MASK) >> ARM_TBFLAG_XSCALE_CPAR_SHIFT)
d9ea7d29
PM
1352#define ARM_TBFLAG_AA64_EL(F) \
1353 (((F) & ARM_TBFLAG_AA64_EL_MASK) >> ARM_TBFLAG_AA64_EL_SHIFT)
8c6afa6a
PM
1354#define ARM_TBFLAG_AA64_FPEN(F) \
1355 (((F) & ARM_TBFLAG_AA64_FPEN_MASK) >> ARM_TBFLAG_AA64_FPEN_SHIFT)
7ea47fe7
PM
1356#define ARM_TBFLAG_AA64_SS_ACTIVE(F) \
1357 (((F) & ARM_TBFLAG_AA64_SS_ACTIVE_MASK) >> ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT)
1358#define ARM_TBFLAG_AA64_PSTATE_SS(F) \
1359 (((F) & ARM_TBFLAG_AA64_PSTATE_SS_MASK) >> ARM_TBFLAG_AA64_PSTATE_SS_SHIFT)
a1705768 1360
0ecb72a5 1361static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc,
6b917547
AL
1362 target_ulong *cs_base, int *flags)
1363{
ed1f13d6
PM
1364 int fpen;
1365
1366 if (arm_feature(env, ARM_FEATURE_V6)) {
1367 fpen = extract32(env->cp15.c1_coproc, 20, 2);
1368 } else {
1369 /* CPACR doesn't exist before v6, so VFP is always accessible */
1370 fpen = 3;
1371 }
8c6afa6a 1372
3926cc84
AG
1373 if (is_a64(env)) {
1374 *pc = env->pc;
d9ea7d29
PM
1375 *flags = ARM_TBFLAG_AARCH64_STATE_MASK
1376 | (arm_current_pl(env) << ARM_TBFLAG_AA64_EL_SHIFT);
8c6afa6a
PM
1377 if (fpen == 3 || (fpen == 1 && arm_current_pl(env) != 0)) {
1378 *flags |= ARM_TBFLAG_AA64_FPEN_MASK;
1379 }
7ea47fe7
PM
1380 /* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine
1381 * states defined in the ARM ARM for software singlestep:
1382 * SS_ACTIVE PSTATE.SS State
1383 * 0 x Inactive (the TB flag for SS is always 0)
1384 * 1 0 Active-pending
1385 * 1 1 Active-not-pending
1386 */
1387 if (arm_singlestep_active(env)) {
1388 *flags |= ARM_TBFLAG_AA64_SS_ACTIVE_MASK;
1389 if (env->pstate & PSTATE_SS) {
1390 *flags |= ARM_TBFLAG_AA64_PSTATE_SS_MASK;
1391 }
1392 }
05ed9a99 1393 } else {
3926cc84
AG
1394 int privmode;
1395 *pc = env->regs[15];
1396 *flags = (env->thumb << ARM_TBFLAG_THUMB_SHIFT)
1397 | (env->vfp.vec_len << ARM_TBFLAG_VECLEN_SHIFT)
1398 | (env->vfp.vec_stride << ARM_TBFLAG_VECSTRIDE_SHIFT)
1399 | (env->condexec_bits << ARM_TBFLAG_CONDEXEC_SHIFT)
1400 | (env->bswap_code << ARM_TBFLAG_BSWAP_CODE_SHIFT);
1401 if (arm_feature(env, ARM_FEATURE_M)) {
1402 privmode = !((env->v7m.exception == 0) && (env->v7m.control & 1));
1403 } else {
1404 privmode = (env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_USR;
1405 }
1406 if (privmode) {
1407 *flags |= ARM_TBFLAG_PRIV_MASK;
1408 }
2c7ffc41
PM
1409 if (env->vfp.xregs[ARM_VFP_FPEXC] & (1 << 30)
1410 || arm_el_is_aa64(env, 1)) {
3926cc84
AG
1411 *flags |= ARM_TBFLAG_VFPEN_MASK;
1412 }
2c7ffc41
PM
1413 if (fpen == 3 || (fpen == 1 && arm_current_pl(env) != 0)) {
1414 *flags |= ARM_TBFLAG_CPACR_FPEN_MASK;
1415 }
50225ad0
PM
1416 /* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine
1417 * states defined in the ARM ARM for software singlestep:
1418 * SS_ACTIVE PSTATE.SS State
1419 * 0 x Inactive (the TB flag for SS is always 0)
1420 * 1 0 Active-pending
1421 * 1 1 Active-not-pending
1422 */
1423 if (arm_singlestep_active(env)) {
1424 *flags |= ARM_TBFLAG_SS_ACTIVE_MASK;
1425 if (env->uncached_cpsr & PSTATE_SS) {
1426 *flags |= ARM_TBFLAG_PSTATE_SS_MASK;
1427 }
1428 }
c0f4af17
PM
1429 *flags |= (extract32(env->cp15.c15_cpar, 0, 2)
1430 << ARM_TBFLAG_XSCALE_CPAR_SHIFT);
a1705768 1431 }
3926cc84
AG
1432
1433 *cs_base = 0;
6b917547
AL
1434}
1435
022c62cb 1436#include "exec/exec-all.h"
f081c76c 1437
3926cc84
AG
1438static inline void cpu_pc_from_tb(CPUARMState *env, TranslationBlock *tb)
1439{
1440 if (ARM_TBFLAG_AARCH64_STATE(tb->flags)) {
1441 env->pc = tb->pc;
1442 } else {
1443 env->regs[15] = tb->pc;
1444 }
1445}
1446
2c0262af 1447#endif
This page took 1.119095 seconds and 4 git commands to generate.