4 * This code is licensed under the GNU GPL v2 or later.
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "qemu/osdep.h"
10 #include "qemu/units.h"
11 #include "target/arm/idau.h"
14 #include "internals.h"
15 #include "exec/gdbstub.h"
16 #include "exec/helper-proto.h"
17 #include "qemu/host-utils.h"
18 #include "qemu/main-loop.h"
19 #include "qemu/bitops.h"
20 #include "qemu/crc32c.h"
21 #include "qemu/qemu-print.h"
22 #include "exec/exec-all.h"
23 #include <zlib.h> /* For crc32 */
25 #include "semihosting/semihost.h"
26 #include "sysemu/cpus.h"
27 #include "sysemu/cpu-timers.h"
28 #include "sysemu/kvm.h"
29 #include "sysemu/tcg.h"
30 #include "qemu/range.h"
31 #include "qapi/qapi-commands-machine-target.h"
32 #include "qapi/error.h"
33 #include "qemu/guest-random.h"
36 #include "exec/cpu_ldst.h"
37 #include "semihosting/common-semi.h"
40 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */
41 #define PMCR_NUM_COUNTERS 4 /* QEMU IMPDEF choice */
43 #ifndef CONFIG_USER_ONLY
45 static bool get_phys_addr_lpae(CPUARMState
*env
, uint64_t address
,
46 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
48 hwaddr
*phys_ptr
, MemTxAttrs
*txattrs
, int *prot
,
49 target_ulong
*page_size_ptr
,
50 ARMMMUFaultInfo
*fi
, ARMCacheAttrs
*cacheattrs
)
51 __attribute__((nonnull
));
54 static void switch_mode(CPUARMState
*env
, int mode
);
55 static int aa64_va_parameter_tbi(uint64_t tcr
, ARMMMUIdx mmu_idx
);
57 static int vfp_gdb_get_reg(CPUARMState
*env
, GByteArray
*buf
, int reg
)
59 ARMCPU
*cpu
= env_archcpu(env
);
60 int nregs
= cpu_isar_feature(aa32_simd_r32
, cpu
) ? 32 : 16;
62 /* VFP data registers are always little-endian. */
64 return gdb_get_reg64(buf
, *aa32_vfp_dreg(env
, reg
));
66 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
67 /* Aliases for Q regs. */
70 uint64_t *q
= aa32_vfp_qreg(env
, reg
- 32);
71 return gdb_get_reg128(buf
, q
[0], q
[1]);
74 switch (reg
- nregs
) {
75 case 0: return gdb_get_reg32(buf
, env
->vfp
.xregs
[ARM_VFP_FPSID
]); break;
76 case 1: return gdb_get_reg32(buf
, vfp_get_fpscr(env
)); break;
77 case 2: return gdb_get_reg32(buf
, env
->vfp
.xregs
[ARM_VFP_FPEXC
]); break;
82 static int vfp_gdb_set_reg(CPUARMState
*env
, uint8_t *buf
, int reg
)
84 ARMCPU
*cpu
= env_archcpu(env
);
85 int nregs
= cpu_isar_feature(aa32_simd_r32
, cpu
) ? 32 : 16;
88 *aa32_vfp_dreg(env
, reg
) = ldq_le_p(buf
);
91 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
94 uint64_t *q
= aa32_vfp_qreg(env
, reg
- 32);
96 q
[1] = ldq_le_p(buf
+ 8);
100 switch (reg
- nregs
) {
101 case 0: env
->vfp
.xregs
[ARM_VFP_FPSID
] = ldl_p(buf
); return 4;
102 case 1: vfp_set_fpscr(env
, ldl_p(buf
)); return 4;
103 case 2: env
->vfp
.xregs
[ARM_VFP_FPEXC
] = ldl_p(buf
) & (1 << 30); return 4;
108 static int aarch64_fpu_gdb_get_reg(CPUARMState
*env
, GByteArray
*buf
, int reg
)
113 /* 128 bit FP register - quads are in LE order */
114 uint64_t *q
= aa64_vfp_qreg(env
, reg
);
115 return gdb_get_reg128(buf
, q
[1], q
[0]);
119 return gdb_get_reg32(buf
, vfp_get_fpsr(env
));
122 return gdb_get_reg32(buf
,vfp_get_fpcr(env
));
128 static int aarch64_fpu_gdb_set_reg(CPUARMState
*env
, uint8_t *buf
, int reg
)
132 /* 128 bit FP register */
134 uint64_t *q
= aa64_vfp_qreg(env
, reg
);
135 q
[0] = ldq_le_p(buf
);
136 q
[1] = ldq_le_p(buf
+ 8);
141 vfp_set_fpsr(env
, ldl_p(buf
));
145 vfp_set_fpcr(env
, ldl_p(buf
));
152 static uint64_t raw_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
154 assert(ri
->fieldoffset
);
155 if (cpreg_field_is_64bit(ri
)) {
156 return CPREG_FIELD64(env
, ri
);
158 return CPREG_FIELD32(env
, ri
);
162 static void raw_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
165 assert(ri
->fieldoffset
);
166 if (cpreg_field_is_64bit(ri
)) {
167 CPREG_FIELD64(env
, ri
) = value
;
169 CPREG_FIELD32(env
, ri
) = value
;
173 static void *raw_ptr(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
175 return (char *)env
+ ri
->fieldoffset
;
178 uint64_t read_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
180 /* Raw read of a coprocessor register (as needed for migration, etc). */
181 if (ri
->type
& ARM_CP_CONST
) {
182 return ri
->resetvalue
;
183 } else if (ri
->raw_readfn
) {
184 return ri
->raw_readfn(env
, ri
);
185 } else if (ri
->readfn
) {
186 return ri
->readfn(env
, ri
);
188 return raw_read(env
, ri
);
192 static void write_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
195 /* Raw write of a coprocessor register (as needed for migration, etc).
196 * Note that constant registers are treated as write-ignored; the
197 * caller should check for success by whether a readback gives the
200 if (ri
->type
& ARM_CP_CONST
) {
202 } else if (ri
->raw_writefn
) {
203 ri
->raw_writefn(env
, ri
, v
);
204 } else if (ri
->writefn
) {
205 ri
->writefn(env
, ri
, v
);
207 raw_write(env
, ri
, v
);
212 * arm_get/set_gdb_*: get/set a gdb register
213 * @env: the CPU state
214 * @buf: a buffer to copy to/from
215 * @reg: register number (offset from start of group)
217 * We return the number of bytes copied
220 static int arm_gdb_get_sysreg(CPUARMState
*env
, GByteArray
*buf
, int reg
)
222 ARMCPU
*cpu
= env_archcpu(env
);
223 const ARMCPRegInfo
*ri
;
226 key
= cpu
->dyn_sysreg_xml
.data
.cpregs
.keys
[reg
];
227 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, key
);
229 if (cpreg_field_is_64bit(ri
)) {
230 return gdb_get_reg64(buf
, (uint64_t)read_raw_cp_reg(env
, ri
));
232 return gdb_get_reg32(buf
, (uint32_t)read_raw_cp_reg(env
, ri
));
238 static int arm_gdb_set_sysreg(CPUARMState
*env
, uint8_t *buf
, int reg
)
243 #ifdef TARGET_AARCH64
244 static int arm_gdb_get_svereg(CPUARMState
*env
, GByteArray
*buf
, int reg
)
246 ARMCPU
*cpu
= env_archcpu(env
);
249 /* The first 32 registers are the zregs */
253 for (vq
= 0; vq
< cpu
->sve_max_vq
; vq
++) {
254 len
+= gdb_get_reg128(buf
,
255 env
->vfp
.zregs
[reg
].d
[vq
* 2 + 1],
256 env
->vfp
.zregs
[reg
].d
[vq
* 2]);
261 return gdb_get_reg32(buf
, vfp_get_fpsr(env
));
263 return gdb_get_reg32(buf
, vfp_get_fpcr(env
));
264 /* then 16 predicates and the ffr */
269 for (vq
= 0; vq
< cpu
->sve_max_vq
; vq
= vq
+ 4) {
270 len
+= gdb_get_reg64(buf
, env
->vfp
.pregs
[preg
].p
[vq
/ 4]);
277 * We report in Vector Granules (VG) which is 64bit in a Z reg
278 * while the ZCR works in Vector Quads (VQ) which is 128bit chunks.
280 int vq
= sve_zcr_len_for_el(env
, arm_current_el(env
)) + 1;
281 return gdb_get_reg64(buf
, vq
* 2);
284 /* gdbstub asked for something out our range */
285 qemu_log_mask(LOG_UNIMP
, "%s: out of range register %d", __func__
, reg
);
292 static int arm_gdb_set_svereg(CPUARMState
*env
, uint8_t *buf
, int reg
)
294 ARMCPU
*cpu
= env_archcpu(env
);
296 /* The first 32 registers are the zregs */
298 /* The first 32 registers are the zregs */
302 uint64_t *p
= (uint64_t *) buf
;
303 for (vq
= 0; vq
< cpu
->sve_max_vq
; vq
++) {
304 env
->vfp
.zregs
[reg
].d
[vq
* 2 + 1] = *p
++;
305 env
->vfp
.zregs
[reg
].d
[vq
* 2] = *p
++;
311 vfp_set_fpsr(env
, *(uint32_t *)buf
);
314 vfp_set_fpcr(env
, *(uint32_t *)buf
);
320 uint64_t *p
= (uint64_t *) buf
;
321 for (vq
= 0; vq
< cpu
->sve_max_vq
; vq
= vq
+ 4) {
322 env
->vfp
.pregs
[preg
].p
[vq
/ 4] = *p
++;
328 /* cannot set vg via gdbstub */
331 /* gdbstub asked for something out our range */
337 #endif /* TARGET_AARCH64 */
339 static bool raw_accessors_invalid(const ARMCPRegInfo
*ri
)
341 /* Return true if the regdef would cause an assertion if you called
342 * read_raw_cp_reg() or write_raw_cp_reg() on it (ie if it is a
343 * program bug for it not to have the NO_RAW flag).
344 * NB that returning false here doesn't necessarily mean that calling
345 * read/write_raw_cp_reg() is safe, because we can't distinguish "has
346 * read/write access functions which are safe for raw use" from "has
347 * read/write access functions which have side effects but has forgotten
348 * to provide raw access functions".
349 * The tests here line up with the conditions in read/write_raw_cp_reg()
350 * and assertions in raw_read()/raw_write().
352 if ((ri
->type
& ARM_CP_CONST
) ||
354 ((ri
->raw_writefn
|| ri
->writefn
) && (ri
->raw_readfn
|| ri
->readfn
))) {
360 bool write_cpustate_to_list(ARMCPU
*cpu
, bool kvm_sync
)
362 /* Write the coprocessor state from cpu->env to the (index,value) list. */
366 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
367 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
368 const ARMCPRegInfo
*ri
;
371 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
376 if (ri
->type
& ARM_CP_NO_RAW
) {
380 newval
= read_raw_cp_reg(&cpu
->env
, ri
);
383 * Only sync if the previous list->cpustate sync succeeded.
384 * Rather than tracking the success/failure state for every
385 * item in the list, we just recheck "does the raw write we must
386 * have made in write_list_to_cpustate() read back OK" here.
388 uint64_t oldval
= cpu
->cpreg_values
[i
];
390 if (oldval
== newval
) {
394 write_raw_cp_reg(&cpu
->env
, ri
, oldval
);
395 if (read_raw_cp_reg(&cpu
->env
, ri
) != oldval
) {
399 write_raw_cp_reg(&cpu
->env
, ri
, newval
);
401 cpu
->cpreg_values
[i
] = newval
;
406 bool write_list_to_cpustate(ARMCPU
*cpu
)
411 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
412 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
413 uint64_t v
= cpu
->cpreg_values
[i
];
414 const ARMCPRegInfo
*ri
;
416 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
421 if (ri
->type
& ARM_CP_NO_RAW
) {
424 /* Write value and confirm it reads back as written
425 * (to catch read-only registers and partially read-only
426 * registers where the incoming migration value doesn't match)
428 write_raw_cp_reg(&cpu
->env
, ri
, v
);
429 if (read_raw_cp_reg(&cpu
->env
, ri
) != v
) {
436 static void add_cpreg_to_list(gpointer key
, gpointer opaque
)
438 ARMCPU
*cpu
= opaque
;
440 const ARMCPRegInfo
*ri
;
442 regidx
= *(uint32_t *)key
;
443 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
445 if (!(ri
->type
& (ARM_CP_NO_RAW
|ARM_CP_ALIAS
))) {
446 cpu
->cpreg_indexes
[cpu
->cpreg_array_len
] = cpreg_to_kvm_id(regidx
);
447 /* The value array need not be initialized at this point */
448 cpu
->cpreg_array_len
++;
452 static void count_cpreg(gpointer key
, gpointer opaque
)
454 ARMCPU
*cpu
= opaque
;
456 const ARMCPRegInfo
*ri
;
458 regidx
= *(uint32_t *)key
;
459 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
461 if (!(ri
->type
& (ARM_CP_NO_RAW
|ARM_CP_ALIAS
))) {
462 cpu
->cpreg_array_len
++;
466 static gint
cpreg_key_compare(gconstpointer a
, gconstpointer b
)
468 uint64_t aidx
= cpreg_to_kvm_id(*(uint32_t *)a
);
469 uint64_t bidx
= cpreg_to_kvm_id(*(uint32_t *)b
);
480 void init_cpreg_list(ARMCPU
*cpu
)
482 /* Initialise the cpreg_tuples[] array based on the cp_regs hash.
483 * Note that we require cpreg_tuples[] to be sorted by key ID.
488 keys
= g_hash_table_get_keys(cpu
->cp_regs
);
489 keys
= g_list_sort(keys
, cpreg_key_compare
);
491 cpu
->cpreg_array_len
= 0;
493 g_list_foreach(keys
, count_cpreg
, cpu
);
495 arraylen
= cpu
->cpreg_array_len
;
496 cpu
->cpreg_indexes
= g_new(uint64_t, arraylen
);
497 cpu
->cpreg_values
= g_new(uint64_t, arraylen
);
498 cpu
->cpreg_vmstate_indexes
= g_new(uint64_t, arraylen
);
499 cpu
->cpreg_vmstate_values
= g_new(uint64_t, arraylen
);
500 cpu
->cpreg_vmstate_array_len
= cpu
->cpreg_array_len
;
501 cpu
->cpreg_array_len
= 0;
503 g_list_foreach(keys
, add_cpreg_to_list
, cpu
);
505 assert(cpu
->cpreg_array_len
== arraylen
);
511 * Some registers are not accessible from AArch32 EL3 if SCR.NS == 0.
513 static CPAccessResult
access_el3_aa32ns(CPUARMState
*env
,
514 const ARMCPRegInfo
*ri
,
517 if (!is_a64(env
) && arm_current_el(env
) == 3 &&
518 arm_is_secure_below_el3(env
)) {
519 return CP_ACCESS_TRAP_UNCATEGORIZED
;
524 /* Some secure-only AArch32 registers trap to EL3 if used from
525 * Secure EL1 (but are just ordinary UNDEF in other non-EL3 contexts).
526 * Note that an access from Secure EL1 can only happen if EL3 is AArch64.
527 * We assume that the .access field is set to PL1_RW.
529 static CPAccessResult
access_trap_aa32s_el1(CPUARMState
*env
,
530 const ARMCPRegInfo
*ri
,
533 if (arm_current_el(env
) == 3) {
536 if (arm_is_secure_below_el3(env
)) {
537 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
538 return CP_ACCESS_TRAP_EL2
;
540 return CP_ACCESS_TRAP_EL3
;
542 /* This will be EL1 NS and EL2 NS, which just UNDEF */
543 return CP_ACCESS_TRAP_UNCATEGORIZED
;
546 static uint64_t arm_mdcr_el2_eff(CPUARMState
*env
)
548 return arm_is_el2_enabled(env
) ? env
->cp15
.mdcr_el2
: 0;
551 /* Check for traps to "powerdown debug" registers, which are controlled
554 static CPAccessResult
access_tdosa(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
557 int el
= arm_current_el(env
);
558 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
559 bool mdcr_el2_tdosa
= (mdcr_el2
& MDCR_TDOSA
) || (mdcr_el2
& MDCR_TDE
) ||
560 (arm_hcr_el2_eff(env
) & HCR_TGE
);
562 if (el
< 2 && mdcr_el2_tdosa
) {
563 return CP_ACCESS_TRAP_EL2
;
565 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDOSA
)) {
566 return CP_ACCESS_TRAP_EL3
;
571 /* Check for traps to "debug ROM" registers, which are controlled
572 * by MDCR_EL2.TDRA for EL2 but by the more general MDCR_EL3.TDA for EL3.
574 static CPAccessResult
access_tdra(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
577 int el
= arm_current_el(env
);
578 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
579 bool mdcr_el2_tdra
= (mdcr_el2
& MDCR_TDRA
) || (mdcr_el2
& MDCR_TDE
) ||
580 (arm_hcr_el2_eff(env
) & HCR_TGE
);
582 if (el
< 2 && mdcr_el2_tdra
) {
583 return CP_ACCESS_TRAP_EL2
;
585 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDA
)) {
586 return CP_ACCESS_TRAP_EL3
;
591 /* Check for traps to general debug registers, which are controlled
592 * by MDCR_EL2.TDA for EL2 and MDCR_EL3.TDA for EL3.
594 static CPAccessResult
access_tda(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
597 int el
= arm_current_el(env
);
598 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
599 bool mdcr_el2_tda
= (mdcr_el2
& MDCR_TDA
) || (mdcr_el2
& MDCR_TDE
) ||
600 (arm_hcr_el2_eff(env
) & HCR_TGE
);
602 if (el
< 2 && mdcr_el2_tda
) {
603 return CP_ACCESS_TRAP_EL2
;
605 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDA
)) {
606 return CP_ACCESS_TRAP_EL3
;
611 /* Check for traps to performance monitor registers, which are controlled
612 * by MDCR_EL2.TPM for EL2 and MDCR_EL3.TPM for EL3.
614 static CPAccessResult
access_tpm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
617 int el
= arm_current_el(env
);
618 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
620 if (el
< 2 && (mdcr_el2
& MDCR_TPM
)) {
621 return CP_ACCESS_TRAP_EL2
;
623 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
624 return CP_ACCESS_TRAP_EL3
;
629 /* Check for traps from EL1 due to HCR_EL2.TVM and HCR_EL2.TRVM. */
630 static CPAccessResult
access_tvm_trvm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
633 if (arm_current_el(env
) == 1) {
634 uint64_t trap
= isread
? HCR_TRVM
: HCR_TVM
;
635 if (arm_hcr_el2_eff(env
) & trap
) {
636 return CP_ACCESS_TRAP_EL2
;
642 /* Check for traps from EL1 due to HCR_EL2.TSW. */
643 static CPAccessResult
access_tsw(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
646 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TSW
)) {
647 return CP_ACCESS_TRAP_EL2
;
652 /* Check for traps from EL1 due to HCR_EL2.TACR. */
653 static CPAccessResult
access_tacr(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
656 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TACR
)) {
657 return CP_ACCESS_TRAP_EL2
;
662 /* Check for traps from EL1 due to HCR_EL2.TTLB. */
663 static CPAccessResult
access_ttlb(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
666 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TTLB
)) {
667 return CP_ACCESS_TRAP_EL2
;
672 static void dacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
674 ARMCPU
*cpu
= env_archcpu(env
);
676 raw_write(env
, ri
, value
);
677 tlb_flush(CPU(cpu
)); /* Flush TLB as domain not tracked in TLB */
680 static void fcse_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
682 ARMCPU
*cpu
= env_archcpu(env
);
684 if (raw_read(env
, ri
) != value
) {
685 /* Unlike real hardware the qemu TLB uses virtual addresses,
686 * not modified virtual addresses, so this causes a TLB flush.
689 raw_write(env
, ri
, value
);
693 static void contextidr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
696 ARMCPU
*cpu
= env_archcpu(env
);
698 if (raw_read(env
, ri
) != value
&& !arm_feature(env
, ARM_FEATURE_PMSA
)
699 && !extended_addresses_enabled(env
)) {
700 /* For VMSA (when not using the LPAE long descriptor page table
701 * format) this register includes the ASID, so do a TLB flush.
702 * For PMSA it is purely a process ID and no action is needed.
706 raw_write(env
, ri
, value
);
709 /* IS variants of TLB operations must affect all cores */
710 static void tlbiall_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
713 CPUState
*cs
= env_cpu(env
);
715 tlb_flush_all_cpus_synced(cs
);
718 static void tlbiasid_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
721 CPUState
*cs
= env_cpu(env
);
723 tlb_flush_all_cpus_synced(cs
);
726 static void tlbimva_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
729 CPUState
*cs
= env_cpu(env
);
731 tlb_flush_page_all_cpus_synced(cs
, value
& TARGET_PAGE_MASK
);
734 static void tlbimvaa_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
737 CPUState
*cs
= env_cpu(env
);
739 tlb_flush_page_all_cpus_synced(cs
, value
& TARGET_PAGE_MASK
);
743 * Non-IS variants of TLB operations are upgraded to
744 * IS versions if we are at EL1 and HCR_EL2.FB is effectively set to
745 * force broadcast of these operations.
747 static bool tlb_force_broadcast(CPUARMState
*env
)
749 return arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_FB
);
752 static void tlbiall_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
755 /* Invalidate all (TLBIALL) */
756 CPUState
*cs
= env_cpu(env
);
758 if (tlb_force_broadcast(env
)) {
759 tlb_flush_all_cpus_synced(cs
);
765 static void tlbimva_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
768 /* Invalidate single TLB entry by MVA and ASID (TLBIMVA) */
769 CPUState
*cs
= env_cpu(env
);
771 value
&= TARGET_PAGE_MASK
;
772 if (tlb_force_broadcast(env
)) {
773 tlb_flush_page_all_cpus_synced(cs
, value
);
775 tlb_flush_page(cs
, value
);
779 static void tlbiasid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
782 /* Invalidate by ASID (TLBIASID) */
783 CPUState
*cs
= env_cpu(env
);
785 if (tlb_force_broadcast(env
)) {
786 tlb_flush_all_cpus_synced(cs
);
792 static void tlbimvaa_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
795 /* Invalidate single entry by MVA, all ASIDs (TLBIMVAA) */
796 CPUState
*cs
= env_cpu(env
);
798 value
&= TARGET_PAGE_MASK
;
799 if (tlb_force_broadcast(env
)) {
800 tlb_flush_page_all_cpus_synced(cs
, value
);
802 tlb_flush_page(cs
, value
);
806 static void tlbiall_nsnh_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
809 CPUState
*cs
= env_cpu(env
);
811 tlb_flush_by_mmuidx(cs
,
813 ARMMMUIdxBit_E10_1_PAN
|
817 static void tlbiall_nsnh_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
820 CPUState
*cs
= env_cpu(env
);
822 tlb_flush_by_mmuidx_all_cpus_synced(cs
,
824 ARMMMUIdxBit_E10_1_PAN
|
829 static void tlbiall_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
832 CPUState
*cs
= env_cpu(env
);
834 tlb_flush_by_mmuidx(cs
, ARMMMUIdxBit_E2
);
837 static void tlbiall_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
840 CPUState
*cs
= env_cpu(env
);
842 tlb_flush_by_mmuidx_all_cpus_synced(cs
, ARMMMUIdxBit_E2
);
845 static void tlbimva_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
848 CPUState
*cs
= env_cpu(env
);
849 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
851 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_E2
);
854 static void tlbimva_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
857 CPUState
*cs
= env_cpu(env
);
858 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
860 tlb_flush_page_by_mmuidx_all_cpus_synced(cs
, pageaddr
,
864 static const ARMCPRegInfo cp_reginfo
[] = {
865 /* Define the secure and non-secure FCSE identifier CP registers
866 * separately because there is no secure bank in V8 (no _EL3). This allows
867 * the secure register to be properly reset and migrated. There is also no
868 * v8 EL1 version of the register so the non-secure instance stands alone.
871 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
872 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_NS
,
873 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_ns
),
874 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
875 { .name
= "FCSEIDR_S",
876 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
877 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_S
,
878 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_s
),
879 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
880 /* Define the secure and non-secure context identifier CP registers
881 * separately because there is no secure bank in V8 (no _EL3). This allows
882 * the secure register to be properly reset and migrated. In the
883 * non-secure case, the 32-bit register will have reset and migration
884 * disabled during registration as it is handled by the 64-bit instance.
886 { .name
= "CONTEXTIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
887 .opc0
= 3, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
888 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
889 .secure
= ARM_CP_SECSTATE_NS
,
890 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[1]),
891 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
892 { .name
= "CONTEXTIDR_S", .state
= ARM_CP_STATE_AA32
,
893 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
894 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
895 .secure
= ARM_CP_SECSTATE_S
,
896 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_s
),
897 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
901 static const ARMCPRegInfo not_v8_cp_reginfo
[] = {
902 /* NB: Some of these registers exist in v8 but with more precise
903 * definitions that don't use CP_ANY wildcards (mostly in v8_cp_reginfo[]).
905 /* MMU Domain access control / MPU write buffer control */
907 .cp
= 15, .opc1
= CP_ANY
, .crn
= 3, .crm
= CP_ANY
, .opc2
= CP_ANY
,
908 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
909 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
910 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
911 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
912 /* ARMv7 allocates a range of implementation defined TLB LOCKDOWN regs.
913 * For v6 and v5, these mappings are overly broad.
915 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 0,
916 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
917 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 1,
918 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
919 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 4,
920 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
921 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 8,
922 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
923 /* Cache maintenance ops; some of this space may be overridden later. */
924 { .name
= "CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
925 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
926 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
},
930 static const ARMCPRegInfo not_v6_cp_reginfo
[] = {
931 /* Not all pre-v6 cores implemented this WFI, so this is slightly
934 { .name
= "WFI_v5", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= 2,
935 .access
= PL1_W
, .type
= ARM_CP_WFI
},
939 static const ARMCPRegInfo not_v7_cp_reginfo
[] = {
940 /* Standard v6 WFI (also used in some pre-v6 cores); not in v7 (which
941 * is UNPREDICTABLE; we choose to NOP as most implementations do).
943 { .name
= "WFI_v6", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
944 .access
= PL1_W
, .type
= ARM_CP_WFI
},
945 /* L1 cache lockdown. Not architectural in v6 and earlier but in practice
946 * implemented in 926, 946, 1026, 1136, 1176 and 11MPCore. StrongARM and
947 * OMAPCP will override this space.
949 { .name
= "DLOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 0,
950 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_data
),
952 { .name
= "ILOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 1,
953 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_insn
),
955 /* v6 doesn't have the cache ID registers but Linux reads them anyway */
956 { .name
= "DUMMY", .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= CP_ANY
,
957 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
959 /* We don't implement pre-v7 debug but most CPUs had at least a DBGDIDR;
960 * implementing it as RAZ means the "debug architecture version" bits
961 * will read as a reserved value, which should cause Linux to not try
962 * to use the debug hardware.
964 { .name
= "DBGDIDR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 0,
965 .access
= PL0_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
966 /* MMU TLB control. Note that the wildcarding means we cover not just
967 * the unified TLB ops but also the dside/iside/inner-shareable variants.
969 { .name
= "TLBIALL", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
970 .opc1
= CP_ANY
, .opc2
= 0, .access
= PL1_W
, .writefn
= tlbiall_write
,
971 .type
= ARM_CP_NO_RAW
},
972 { .name
= "TLBIMVA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
973 .opc1
= CP_ANY
, .opc2
= 1, .access
= PL1_W
, .writefn
= tlbimva_write
,
974 .type
= ARM_CP_NO_RAW
},
975 { .name
= "TLBIASID", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
976 .opc1
= CP_ANY
, .opc2
= 2, .access
= PL1_W
, .writefn
= tlbiasid_write
,
977 .type
= ARM_CP_NO_RAW
},
978 { .name
= "TLBIMVAA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
979 .opc1
= CP_ANY
, .opc2
= 3, .access
= PL1_W
, .writefn
= tlbimvaa_write
,
980 .type
= ARM_CP_NO_RAW
},
981 { .name
= "PRRR", .cp
= 15, .crn
= 10, .crm
= 2,
982 .opc1
= 0, .opc2
= 0, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
983 { .name
= "NMRR", .cp
= 15, .crn
= 10, .crm
= 2,
984 .opc1
= 0, .opc2
= 1, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
988 static void cpacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
993 /* In ARMv8 most bits of CPACR_EL1 are RES0. */
994 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
995 /* ARMv7 defines bits for unimplemented coprocessors as RAZ/WI.
996 * ASEDIS [31] and D32DIS [30] are both UNK/SBZP without VFP.
997 * TRCDIS [28] is RAZ/WI since we do not implement a trace macrocell.
999 if (cpu_isar_feature(aa32_vfp_simd
, env_archcpu(env
))) {
1000 /* VFP coprocessor: cp10 & cp11 [23:20] */
1001 mask
|= (1 << 31) | (1 << 30) | (0xf << 20);
1003 if (!arm_feature(env
, ARM_FEATURE_NEON
)) {
1004 /* ASEDIS [31] bit is RAO/WI */
1008 /* VFPv3 and upwards with NEON implement 32 double precision
1009 * registers (D0-D31).
1011 if (!cpu_isar_feature(aa32_simd_r32
, env_archcpu(env
))) {
1012 /* D32DIS [30] is RAO/WI if D16-31 are not implemented. */
1020 * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10
1021 * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00.
1023 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
1024 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
1025 value
&= ~(0xf << 20);
1026 value
|= env
->cp15
.cpacr_el1
& (0xf << 20);
1029 env
->cp15
.cpacr_el1
= value
;
1032 static uint64_t cpacr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1035 * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10
1036 * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00.
1038 uint64_t value
= env
->cp15
.cpacr_el1
;
1040 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
1041 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
1042 value
&= ~(0xf << 20);
1048 static void cpacr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1050 /* Call cpacr_write() so that we reset with the correct RAO bits set
1051 * for our CPU features.
1053 cpacr_write(env
, ri
, 0);
1056 static CPAccessResult
cpacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1059 if (arm_feature(env
, ARM_FEATURE_V8
)) {
1060 /* Check if CPACR accesses are to be trapped to EL2 */
1061 if (arm_current_el(env
) == 1 && arm_is_el2_enabled(env
) &&
1062 (env
->cp15
.cptr_el
[2] & CPTR_TCPAC
)) {
1063 return CP_ACCESS_TRAP_EL2
;
1064 /* Check if CPACR accesses are to be trapped to EL3 */
1065 } else if (arm_current_el(env
) < 3 &&
1066 (env
->cp15
.cptr_el
[3] & CPTR_TCPAC
)) {
1067 return CP_ACCESS_TRAP_EL3
;
1071 return CP_ACCESS_OK
;
1074 static CPAccessResult
cptr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1077 /* Check if CPTR accesses are set to trap to EL3 */
1078 if (arm_current_el(env
) == 2 && (env
->cp15
.cptr_el
[3] & CPTR_TCPAC
)) {
1079 return CP_ACCESS_TRAP_EL3
;
1082 return CP_ACCESS_OK
;
1085 static const ARMCPRegInfo v6_cp_reginfo
[] = {
1086 /* prefetch by MVA in v6, NOP in v7 */
1087 { .name
= "MVA_prefetch",
1088 .cp
= 15, .crn
= 7, .crm
= 13, .opc1
= 0, .opc2
= 1,
1089 .access
= PL1_W
, .type
= ARM_CP_NOP
},
1090 /* We need to break the TB after ISB to execute self-modifying code
1091 * correctly and also to take any pending interrupts immediately.
1092 * So use arm_cp_write_ignore() function instead of ARM_CP_NOP flag.
1094 { .name
= "ISB", .cp
= 15, .crn
= 7, .crm
= 5, .opc1
= 0, .opc2
= 4,
1095 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
, .writefn
= arm_cp_write_ignore
},
1096 { .name
= "DSB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 4,
1097 .access
= PL0_W
, .type
= ARM_CP_NOP
},
1098 { .name
= "DMB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 5,
1099 .access
= PL0_W
, .type
= ARM_CP_NOP
},
1100 { .name
= "IFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 2,
1101 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
1102 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ifar_s
),
1103 offsetof(CPUARMState
, cp15
.ifar_ns
) },
1105 /* Watchpoint Fault Address Register : should actually only be present
1106 * for 1136, 1176, 11MPCore.
1108 { .name
= "WFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 1,
1109 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0, },
1110 { .name
= "CPACR", .state
= ARM_CP_STATE_BOTH
, .opc0
= 3,
1111 .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 2, .accessfn
= cpacr_access
,
1112 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.cpacr_el1
),
1113 .resetfn
= cpacr_reset
, .writefn
= cpacr_write
, .readfn
= cpacr_read
},
1117 /* Definitions for the PMU registers */
1118 #define PMCRN_MASK 0xf800
1119 #define PMCRN_SHIFT 11
1128 * Mask of PMCR bits writeable by guest (not including WO bits like C, P,
1129 * which can be written as 1 to trigger behaviour but which stay RAZ).
1131 #define PMCR_WRITEABLE_MASK (PMCRLC | PMCRDP | PMCRX | PMCRD | PMCRE)
1133 #define PMXEVTYPER_P 0x80000000
1134 #define PMXEVTYPER_U 0x40000000
1135 #define PMXEVTYPER_NSK 0x20000000
1136 #define PMXEVTYPER_NSU 0x10000000
1137 #define PMXEVTYPER_NSH 0x08000000
1138 #define PMXEVTYPER_M 0x04000000
1139 #define PMXEVTYPER_MT 0x02000000
1140 #define PMXEVTYPER_EVTCOUNT 0x0000ffff
1141 #define PMXEVTYPER_MASK (PMXEVTYPER_P | PMXEVTYPER_U | PMXEVTYPER_NSK | \
1142 PMXEVTYPER_NSU | PMXEVTYPER_NSH | \
1143 PMXEVTYPER_M | PMXEVTYPER_MT | \
1144 PMXEVTYPER_EVTCOUNT)
1146 #define PMCCFILTR 0xf8000000
1147 #define PMCCFILTR_M PMXEVTYPER_M
1148 #define PMCCFILTR_EL0 (PMCCFILTR | PMCCFILTR_M)
1150 static inline uint32_t pmu_num_counters(CPUARMState
*env
)
1152 return (env
->cp15
.c9_pmcr
& PMCRN_MASK
) >> PMCRN_SHIFT
;
1155 /* Bits allowed to be set/cleared for PMCNTEN* and PMINTEN* */
1156 static inline uint64_t pmu_counter_mask(CPUARMState
*env
)
1158 return (1 << 31) | ((1 << pmu_num_counters(env
)) - 1);
1161 typedef struct pm_event
{
1162 uint16_t number
; /* PMEVTYPER.evtCount is 16 bits wide */
1163 /* If the event is supported on this CPU (used to generate PMCEID[01]) */
1164 bool (*supported
)(CPUARMState
*);
1166 * Retrieve the current count of the underlying event. The programmed
1167 * counters hold a difference from the return value from this function
1169 uint64_t (*get_count
)(CPUARMState
*);
1171 * Return how many nanoseconds it will take (at a minimum) for count events
1172 * to occur. A negative value indicates the counter will never overflow, or
1173 * that the counter has otherwise arranged for the overflow bit to be set
1174 * and the PMU interrupt to be raised on overflow.
1176 int64_t (*ns_per_count
)(uint64_t);
1179 static bool event_always_supported(CPUARMState
*env
)
1184 static uint64_t swinc_get_count(CPUARMState
*env
)
1187 * SW_INCR events are written directly to the pmevcntr's by writes to
1188 * PMSWINC, so there is no underlying count maintained by the PMU itself
1193 static int64_t swinc_ns_per(uint64_t ignored
)
1199 * Return the underlying cycle count for the PMU cycle counters. If we're in
1200 * usermode, simply return 0.
1202 static uint64_t cycles_get_count(CPUARMState
*env
)
1204 #ifndef CONFIG_USER_ONLY
1205 return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
1206 ARM_CPU_FREQ
, NANOSECONDS_PER_SECOND
);
1208 return cpu_get_host_ticks();
1212 #ifndef CONFIG_USER_ONLY
1213 static int64_t cycles_ns_per(uint64_t cycles
)
1215 return (ARM_CPU_FREQ
/ NANOSECONDS_PER_SECOND
) * cycles
;
1218 static bool instructions_supported(CPUARMState
*env
)
1220 return icount_enabled() == 1; /* Precise instruction counting */
1223 static uint64_t instructions_get_count(CPUARMState
*env
)
1225 return (uint64_t)icount_get_raw();
1228 static int64_t instructions_ns_per(uint64_t icount
)
1230 return icount_to_ns((int64_t)icount
);
1234 static bool pmu_8_1_events_supported(CPUARMState
*env
)
1236 /* For events which are supported in any v8.1 PMU */
1237 return cpu_isar_feature(any_pmu_8_1
, env_archcpu(env
));
1240 static bool pmu_8_4_events_supported(CPUARMState
*env
)
1242 /* For events which are supported in any v8.1 PMU */
1243 return cpu_isar_feature(any_pmu_8_4
, env_archcpu(env
));
1246 static uint64_t zero_event_get_count(CPUARMState
*env
)
1248 /* For events which on QEMU never fire, so their count is always zero */
1252 static int64_t zero_event_ns_per(uint64_t cycles
)
1254 /* An event which never fires can never overflow */
1258 static const pm_event pm_events
[] = {
1259 { .number
= 0x000, /* SW_INCR */
1260 .supported
= event_always_supported
,
1261 .get_count
= swinc_get_count
,
1262 .ns_per_count
= swinc_ns_per
,
1264 #ifndef CONFIG_USER_ONLY
1265 { .number
= 0x008, /* INST_RETIRED, Instruction architecturally executed */
1266 .supported
= instructions_supported
,
1267 .get_count
= instructions_get_count
,
1268 .ns_per_count
= instructions_ns_per
,
1270 { .number
= 0x011, /* CPU_CYCLES, Cycle */
1271 .supported
= event_always_supported
,
1272 .get_count
= cycles_get_count
,
1273 .ns_per_count
= cycles_ns_per
,
1276 { .number
= 0x023, /* STALL_FRONTEND */
1277 .supported
= pmu_8_1_events_supported
,
1278 .get_count
= zero_event_get_count
,
1279 .ns_per_count
= zero_event_ns_per
,
1281 { .number
= 0x024, /* STALL_BACKEND */
1282 .supported
= pmu_8_1_events_supported
,
1283 .get_count
= zero_event_get_count
,
1284 .ns_per_count
= zero_event_ns_per
,
1286 { .number
= 0x03c, /* STALL */
1287 .supported
= pmu_8_4_events_supported
,
1288 .get_count
= zero_event_get_count
,
1289 .ns_per_count
= zero_event_ns_per
,
1294 * Note: Before increasing MAX_EVENT_ID beyond 0x3f into the 0x40xx range of
1295 * events (i.e. the statistical profiling extension), this implementation
1296 * should first be updated to something sparse instead of the current
1297 * supported_event_map[] array.
1299 #define MAX_EVENT_ID 0x3c
1300 #define UNSUPPORTED_EVENT UINT16_MAX
1301 static uint16_t supported_event_map
[MAX_EVENT_ID
+ 1];
1304 * Called upon CPU initialization to initialize PMCEID[01]_EL0 and build a map
1305 * of ARM event numbers to indices in our pm_events array.
1307 * Note: Events in the 0x40XX range are not currently supported.
1309 void pmu_init(ARMCPU
*cpu
)
1314 * Empty supported_event_map and cpu->pmceid[01] before adding supported
1317 for (i
= 0; i
< ARRAY_SIZE(supported_event_map
); i
++) {
1318 supported_event_map
[i
] = UNSUPPORTED_EVENT
;
1323 for (i
= 0; i
< ARRAY_SIZE(pm_events
); i
++) {
1324 const pm_event
*cnt
= &pm_events
[i
];
1325 assert(cnt
->number
<= MAX_EVENT_ID
);
1326 /* We do not currently support events in the 0x40xx range */
1327 assert(cnt
->number
<= 0x3f);
1329 if (cnt
->supported(&cpu
->env
)) {
1330 supported_event_map
[cnt
->number
] = i
;
1331 uint64_t event_mask
= 1ULL << (cnt
->number
& 0x1f);
1332 if (cnt
->number
& 0x20) {
1333 cpu
->pmceid1
|= event_mask
;
1335 cpu
->pmceid0
|= event_mask
;
1342 * Check at runtime whether a PMU event is supported for the current machine
1344 static bool event_supported(uint16_t number
)
1346 if (number
> MAX_EVENT_ID
) {
1349 return supported_event_map
[number
] != UNSUPPORTED_EVENT
;
1352 static CPAccessResult
pmreg_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1355 /* Performance monitor registers user accessibility is controlled
1356 * by PMUSERENR. MDCR_EL2.TPM and MDCR_EL3.TPM allow configurable
1357 * trapping to EL2 or EL3 for other accesses.
1359 int el
= arm_current_el(env
);
1360 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
1362 if (el
== 0 && !(env
->cp15
.c9_pmuserenr
& 1)) {
1363 return CP_ACCESS_TRAP
;
1365 if (el
< 2 && (mdcr_el2
& MDCR_TPM
)) {
1366 return CP_ACCESS_TRAP_EL2
;
1368 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
1369 return CP_ACCESS_TRAP_EL3
;
1372 return CP_ACCESS_OK
;
1375 static CPAccessResult
pmreg_access_xevcntr(CPUARMState
*env
,
1376 const ARMCPRegInfo
*ri
,
1379 /* ER: event counter read trap control */
1380 if (arm_feature(env
, ARM_FEATURE_V8
)
1381 && arm_current_el(env
) == 0
1382 && (env
->cp15
.c9_pmuserenr
& (1 << 3)) != 0
1384 return CP_ACCESS_OK
;
1387 return pmreg_access(env
, ri
, isread
);
1390 static CPAccessResult
pmreg_access_swinc(CPUARMState
*env
,
1391 const ARMCPRegInfo
*ri
,
1394 /* SW: software increment write trap control */
1395 if (arm_feature(env
, ARM_FEATURE_V8
)
1396 && arm_current_el(env
) == 0
1397 && (env
->cp15
.c9_pmuserenr
& (1 << 1)) != 0
1399 return CP_ACCESS_OK
;
1402 return pmreg_access(env
, ri
, isread
);
1405 static CPAccessResult
pmreg_access_selr(CPUARMState
*env
,
1406 const ARMCPRegInfo
*ri
,
1409 /* ER: event counter read trap control */
1410 if (arm_feature(env
, ARM_FEATURE_V8
)
1411 && arm_current_el(env
) == 0
1412 && (env
->cp15
.c9_pmuserenr
& (1 << 3)) != 0) {
1413 return CP_ACCESS_OK
;
1416 return pmreg_access(env
, ri
, isread
);
1419 static CPAccessResult
pmreg_access_ccntr(CPUARMState
*env
,
1420 const ARMCPRegInfo
*ri
,
1423 /* CR: cycle counter read trap control */
1424 if (arm_feature(env
, ARM_FEATURE_V8
)
1425 && arm_current_el(env
) == 0
1426 && (env
->cp15
.c9_pmuserenr
& (1 << 2)) != 0
1428 return CP_ACCESS_OK
;
1431 return pmreg_access(env
, ri
, isread
);
1434 /* Returns true if the counter (pass 31 for PMCCNTR) should count events using
1435 * the current EL, security state, and register configuration.
1437 static bool pmu_counter_enabled(CPUARMState
*env
, uint8_t counter
)
1440 bool e
, p
, u
, nsk
, nsu
, nsh
, m
;
1441 bool enabled
, prohibited
, filtered
;
1442 bool secure
= arm_is_secure(env
);
1443 int el
= arm_current_el(env
);
1444 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
1445 uint8_t hpmn
= mdcr_el2
& MDCR_HPMN
;
1447 if (!arm_feature(env
, ARM_FEATURE_PMU
)) {
1451 if (!arm_feature(env
, ARM_FEATURE_EL2
) ||
1452 (counter
< hpmn
|| counter
== 31)) {
1453 e
= env
->cp15
.c9_pmcr
& PMCRE
;
1455 e
= mdcr_el2
& MDCR_HPME
;
1457 enabled
= e
&& (env
->cp15
.c9_pmcnten
& (1 << counter
));
1460 if (el
== 2 && (counter
< hpmn
|| counter
== 31)) {
1461 prohibited
= mdcr_el2
& MDCR_HPMD
;
1466 prohibited
= arm_feature(env
, ARM_FEATURE_EL3
) &&
1467 !(env
->cp15
.mdcr_el3
& MDCR_SPME
);
1470 if (prohibited
&& counter
== 31) {
1471 prohibited
= env
->cp15
.c9_pmcr
& PMCRDP
;
1474 if (counter
== 31) {
1475 filter
= env
->cp15
.pmccfiltr_el0
;
1477 filter
= env
->cp15
.c14_pmevtyper
[counter
];
1480 p
= filter
& PMXEVTYPER_P
;
1481 u
= filter
& PMXEVTYPER_U
;
1482 nsk
= arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_NSK
);
1483 nsu
= arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_NSU
);
1484 nsh
= arm_feature(env
, ARM_FEATURE_EL2
) && (filter
& PMXEVTYPER_NSH
);
1485 m
= arm_el_is_aa64(env
, 1) &&
1486 arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_M
);
1489 filtered
= secure
? u
: u
!= nsu
;
1490 } else if (el
== 1) {
1491 filtered
= secure
? p
: p
!= nsk
;
1492 } else if (el
== 2) {
1498 if (counter
!= 31) {
1500 * If not checking PMCCNTR, ensure the counter is setup to an event we
1503 uint16_t event
= filter
& PMXEVTYPER_EVTCOUNT
;
1504 if (!event_supported(event
)) {
1509 return enabled
&& !prohibited
&& !filtered
;
1512 static void pmu_update_irq(CPUARMState
*env
)
1514 ARMCPU
*cpu
= env_archcpu(env
);
1515 qemu_set_irq(cpu
->pmu_interrupt
, (env
->cp15
.c9_pmcr
& PMCRE
) &&
1516 (env
->cp15
.c9_pminten
& env
->cp15
.c9_pmovsr
));
1520 * Ensure c15_ccnt is the guest-visible count so that operations such as
1521 * enabling/disabling the counter or filtering, modifying the count itself,
1522 * etc. can be done logically. This is essentially a no-op if the counter is
1523 * not enabled at the time of the call.
1525 static void pmccntr_op_start(CPUARMState
*env
)
1527 uint64_t cycles
= cycles_get_count(env
);
1529 if (pmu_counter_enabled(env
, 31)) {
1530 uint64_t eff_cycles
= cycles
;
1531 if (env
->cp15
.c9_pmcr
& PMCRD
) {
1532 /* Increment once every 64 processor clock cycles */
1536 uint64_t new_pmccntr
= eff_cycles
- env
->cp15
.c15_ccnt_delta
;
1538 uint64_t overflow_mask
= env
->cp15
.c9_pmcr
& PMCRLC
? \
1539 1ull << 63 : 1ull << 31;
1540 if (env
->cp15
.c15_ccnt
& ~new_pmccntr
& overflow_mask
) {
1541 env
->cp15
.c9_pmovsr
|= (1 << 31);
1542 pmu_update_irq(env
);
1545 env
->cp15
.c15_ccnt
= new_pmccntr
;
1547 env
->cp15
.c15_ccnt_delta
= cycles
;
1551 * If PMCCNTR is enabled, recalculate the delta between the clock and the
1552 * guest-visible count. A call to pmccntr_op_finish should follow every call to
1555 static void pmccntr_op_finish(CPUARMState
*env
)
1557 if (pmu_counter_enabled(env
, 31)) {
1558 #ifndef CONFIG_USER_ONLY
1559 /* Calculate when the counter will next overflow */
1560 uint64_t remaining_cycles
= -env
->cp15
.c15_ccnt
;
1561 if (!(env
->cp15
.c9_pmcr
& PMCRLC
)) {
1562 remaining_cycles
= (uint32_t)remaining_cycles
;
1564 int64_t overflow_in
= cycles_ns_per(remaining_cycles
);
1566 if (overflow_in
> 0) {
1567 int64_t overflow_at
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
1569 ARMCPU
*cpu
= env_archcpu(env
);
1570 timer_mod_anticipate_ns(cpu
->pmu_timer
, overflow_at
);
1574 uint64_t prev_cycles
= env
->cp15
.c15_ccnt_delta
;
1575 if (env
->cp15
.c9_pmcr
& PMCRD
) {
1576 /* Increment once every 64 processor clock cycles */
1579 env
->cp15
.c15_ccnt_delta
= prev_cycles
- env
->cp15
.c15_ccnt
;
1583 static void pmevcntr_op_start(CPUARMState
*env
, uint8_t counter
)
1586 uint16_t event
= env
->cp15
.c14_pmevtyper
[counter
] & PMXEVTYPER_EVTCOUNT
;
1588 if (event_supported(event
)) {
1589 uint16_t event_idx
= supported_event_map
[event
];
1590 count
= pm_events
[event_idx
].get_count(env
);
1593 if (pmu_counter_enabled(env
, counter
)) {
1594 uint32_t new_pmevcntr
= count
- env
->cp15
.c14_pmevcntr_delta
[counter
];
1596 if (env
->cp15
.c14_pmevcntr
[counter
] & ~new_pmevcntr
& INT32_MIN
) {
1597 env
->cp15
.c9_pmovsr
|= (1 << counter
);
1598 pmu_update_irq(env
);
1600 env
->cp15
.c14_pmevcntr
[counter
] = new_pmevcntr
;
1602 env
->cp15
.c14_pmevcntr_delta
[counter
] = count
;
1605 static void pmevcntr_op_finish(CPUARMState
*env
, uint8_t counter
)
1607 if (pmu_counter_enabled(env
, counter
)) {
1608 #ifndef CONFIG_USER_ONLY
1609 uint16_t event
= env
->cp15
.c14_pmevtyper
[counter
] & PMXEVTYPER_EVTCOUNT
;
1610 uint16_t event_idx
= supported_event_map
[event
];
1611 uint64_t delta
= UINT32_MAX
-
1612 (uint32_t)env
->cp15
.c14_pmevcntr
[counter
] + 1;
1613 int64_t overflow_in
= pm_events
[event_idx
].ns_per_count(delta
);
1615 if (overflow_in
> 0) {
1616 int64_t overflow_at
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
1618 ARMCPU
*cpu
= env_archcpu(env
);
1619 timer_mod_anticipate_ns(cpu
->pmu_timer
, overflow_at
);
1623 env
->cp15
.c14_pmevcntr_delta
[counter
] -=
1624 env
->cp15
.c14_pmevcntr
[counter
];
1628 void pmu_op_start(CPUARMState
*env
)
1631 pmccntr_op_start(env
);
1632 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1633 pmevcntr_op_start(env
, i
);
1637 void pmu_op_finish(CPUARMState
*env
)
1640 pmccntr_op_finish(env
);
1641 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1642 pmevcntr_op_finish(env
, i
);
1646 void pmu_pre_el_change(ARMCPU
*cpu
, void *ignored
)
1648 pmu_op_start(&cpu
->env
);
1651 void pmu_post_el_change(ARMCPU
*cpu
, void *ignored
)
1653 pmu_op_finish(&cpu
->env
);
1656 void arm_pmu_timer_cb(void *opaque
)
1658 ARMCPU
*cpu
= opaque
;
1661 * Update all the counter values based on the current underlying counts,
1662 * triggering interrupts to be raised, if necessary. pmu_op_finish() also
1663 * has the effect of setting the cpu->pmu_timer to the next earliest time a
1664 * counter may expire.
1666 pmu_op_start(&cpu
->env
);
1667 pmu_op_finish(&cpu
->env
);
1670 static void pmcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1675 if (value
& PMCRC
) {
1676 /* The counter has been reset */
1677 env
->cp15
.c15_ccnt
= 0;
1680 if (value
& PMCRP
) {
1682 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1683 env
->cp15
.c14_pmevcntr
[i
] = 0;
1687 env
->cp15
.c9_pmcr
&= ~PMCR_WRITEABLE_MASK
;
1688 env
->cp15
.c9_pmcr
|= (value
& PMCR_WRITEABLE_MASK
);
1693 static void pmswinc_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1697 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1698 /* Increment a counter's count iff: */
1699 if ((value
& (1 << i
)) && /* counter's bit is set */
1700 /* counter is enabled and not filtered */
1701 pmu_counter_enabled(env
, i
) &&
1702 /* counter is SW_INCR */
1703 (env
->cp15
.c14_pmevtyper
[i
] & PMXEVTYPER_EVTCOUNT
) == 0x0) {
1704 pmevcntr_op_start(env
, i
);
1707 * Detect if this write causes an overflow since we can't predict
1708 * PMSWINC overflows like we can for other events
1710 uint32_t new_pmswinc
= env
->cp15
.c14_pmevcntr
[i
] + 1;
1712 if (env
->cp15
.c14_pmevcntr
[i
] & ~new_pmswinc
& INT32_MIN
) {
1713 env
->cp15
.c9_pmovsr
|= (1 << i
);
1714 pmu_update_irq(env
);
1717 env
->cp15
.c14_pmevcntr
[i
] = new_pmswinc
;
1719 pmevcntr_op_finish(env
, i
);
1724 static uint64_t pmccntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1727 pmccntr_op_start(env
);
1728 ret
= env
->cp15
.c15_ccnt
;
1729 pmccntr_op_finish(env
);
1733 static void pmselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1736 /* The value of PMSELR.SEL affects the behavior of PMXEVTYPER and
1737 * PMXEVCNTR. We allow [0..31] to be written to PMSELR here; in the
1738 * meanwhile, we check PMSELR.SEL when PMXEVTYPER and PMXEVCNTR are
1741 env
->cp15
.c9_pmselr
= value
& 0x1f;
1744 static void pmccntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1747 pmccntr_op_start(env
);
1748 env
->cp15
.c15_ccnt
= value
;
1749 pmccntr_op_finish(env
);
1752 static void pmccntr_write32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1755 uint64_t cur_val
= pmccntr_read(env
, NULL
);
1757 pmccntr_write(env
, ri
, deposit64(cur_val
, 0, 32, value
));
1760 static void pmccfiltr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1763 pmccntr_op_start(env
);
1764 env
->cp15
.pmccfiltr_el0
= value
& PMCCFILTR_EL0
;
1765 pmccntr_op_finish(env
);
1768 static void pmccfiltr_write_a32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1771 pmccntr_op_start(env
);
1772 /* M is not accessible from AArch32 */
1773 env
->cp15
.pmccfiltr_el0
= (env
->cp15
.pmccfiltr_el0
& PMCCFILTR_M
) |
1774 (value
& PMCCFILTR
);
1775 pmccntr_op_finish(env
);
1778 static uint64_t pmccfiltr_read_a32(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1780 /* M is not visible in AArch32 */
1781 return env
->cp15
.pmccfiltr_el0
& PMCCFILTR
;
1784 static void pmcntenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1787 value
&= pmu_counter_mask(env
);
1788 env
->cp15
.c9_pmcnten
|= value
;
1791 static void pmcntenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1794 value
&= pmu_counter_mask(env
);
1795 env
->cp15
.c9_pmcnten
&= ~value
;
1798 static void pmovsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1801 value
&= pmu_counter_mask(env
);
1802 env
->cp15
.c9_pmovsr
&= ~value
;
1803 pmu_update_irq(env
);
1806 static void pmovsset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1809 value
&= pmu_counter_mask(env
);
1810 env
->cp15
.c9_pmovsr
|= value
;
1811 pmu_update_irq(env
);
1814 static void pmevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1815 uint64_t value
, const uint8_t counter
)
1817 if (counter
== 31) {
1818 pmccfiltr_write(env
, ri
, value
);
1819 } else if (counter
< pmu_num_counters(env
)) {
1820 pmevcntr_op_start(env
, counter
);
1823 * If this counter's event type is changing, store the current
1824 * underlying count for the new type in c14_pmevcntr_delta[counter] so
1825 * pmevcntr_op_finish has the correct baseline when it converts back to
1828 uint16_t old_event
= env
->cp15
.c14_pmevtyper
[counter
] &
1829 PMXEVTYPER_EVTCOUNT
;
1830 uint16_t new_event
= value
& PMXEVTYPER_EVTCOUNT
;
1831 if (old_event
!= new_event
) {
1833 if (event_supported(new_event
)) {
1834 uint16_t event_idx
= supported_event_map
[new_event
];
1835 count
= pm_events
[event_idx
].get_count(env
);
1837 env
->cp15
.c14_pmevcntr_delta
[counter
] = count
;
1840 env
->cp15
.c14_pmevtyper
[counter
] = value
& PMXEVTYPER_MASK
;
1841 pmevcntr_op_finish(env
, counter
);
1843 /* Attempts to access PMXEVTYPER are CONSTRAINED UNPREDICTABLE when
1844 * PMSELR value is equal to or greater than the number of implemented
1845 * counters, but not equal to 0x1f. We opt to behave as a RAZ/WI.
1849 static uint64_t pmevtyper_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1850 const uint8_t counter
)
1852 if (counter
== 31) {
1853 return env
->cp15
.pmccfiltr_el0
;
1854 } else if (counter
< pmu_num_counters(env
)) {
1855 return env
->cp15
.c14_pmevtyper
[counter
];
1858 * We opt to behave as a RAZ/WI when attempts to access PMXEVTYPER
1859 * are CONSTRAINED UNPREDICTABLE. See comments in pmevtyper_write().
1865 static void pmevtyper_writefn(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1868 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1869 pmevtyper_write(env
, ri
, value
, counter
);
1872 static void pmevtyper_rawwrite(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1875 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1876 env
->cp15
.c14_pmevtyper
[counter
] = value
;
1879 * pmevtyper_rawwrite is called between a pair of pmu_op_start and
1880 * pmu_op_finish calls when loading saved state for a migration. Because
1881 * we're potentially updating the type of event here, the value written to
1882 * c14_pmevcntr_delta by the preceeding pmu_op_start call may be for a
1883 * different counter type. Therefore, we need to set this value to the
1884 * current count for the counter type we're writing so that pmu_op_finish
1885 * has the correct count for its calculation.
1887 uint16_t event
= value
& PMXEVTYPER_EVTCOUNT
;
1888 if (event_supported(event
)) {
1889 uint16_t event_idx
= supported_event_map
[event
];
1890 env
->cp15
.c14_pmevcntr_delta
[counter
] =
1891 pm_events
[event_idx
].get_count(env
);
1895 static uint64_t pmevtyper_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1897 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1898 return pmevtyper_read(env
, ri
, counter
);
1901 static void pmxevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1904 pmevtyper_write(env
, ri
, value
, env
->cp15
.c9_pmselr
& 31);
1907 static uint64_t pmxevtyper_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1909 return pmevtyper_read(env
, ri
, env
->cp15
.c9_pmselr
& 31);
1912 static void pmevcntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1913 uint64_t value
, uint8_t counter
)
1915 if (counter
< pmu_num_counters(env
)) {
1916 pmevcntr_op_start(env
, counter
);
1917 env
->cp15
.c14_pmevcntr
[counter
] = value
;
1918 pmevcntr_op_finish(env
, counter
);
1921 * We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
1922 * are CONSTRAINED UNPREDICTABLE.
1926 static uint64_t pmevcntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1929 if (counter
< pmu_num_counters(env
)) {
1931 pmevcntr_op_start(env
, counter
);
1932 ret
= env
->cp15
.c14_pmevcntr
[counter
];
1933 pmevcntr_op_finish(env
, counter
);
1936 /* We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
1937 * are CONSTRAINED UNPREDICTABLE. */
1942 static void pmevcntr_writefn(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1945 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1946 pmevcntr_write(env
, ri
, value
, counter
);
1949 static uint64_t pmevcntr_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1951 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1952 return pmevcntr_read(env
, ri
, counter
);
1955 static void pmevcntr_rawwrite(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1958 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1959 assert(counter
< pmu_num_counters(env
));
1960 env
->cp15
.c14_pmevcntr
[counter
] = value
;
1961 pmevcntr_write(env
, ri
, value
, counter
);
1964 static uint64_t pmevcntr_rawread(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1966 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1967 assert(counter
< pmu_num_counters(env
));
1968 return env
->cp15
.c14_pmevcntr
[counter
];
1971 static void pmxevcntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1974 pmevcntr_write(env
, ri
, value
, env
->cp15
.c9_pmselr
& 31);
1977 static uint64_t pmxevcntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1979 return pmevcntr_read(env
, ri
, env
->cp15
.c9_pmselr
& 31);
1982 static void pmuserenr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1985 if (arm_feature(env
, ARM_FEATURE_V8
)) {
1986 env
->cp15
.c9_pmuserenr
= value
& 0xf;
1988 env
->cp15
.c9_pmuserenr
= value
& 1;
1992 static void pmintenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1995 /* We have no event counters so only the C bit can be changed */
1996 value
&= pmu_counter_mask(env
);
1997 env
->cp15
.c9_pminten
|= value
;
1998 pmu_update_irq(env
);
2001 static void pmintenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2004 value
&= pmu_counter_mask(env
);
2005 env
->cp15
.c9_pminten
&= ~value
;
2006 pmu_update_irq(env
);
2009 static void vbar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2012 /* Note that even though the AArch64 view of this register has bits
2013 * [10:0] all RES0 we can only mask the bottom 5, to comply with the
2014 * architectural requirements for bits which are RES0 only in some
2015 * contexts. (ARMv8 would permit us to do no masking at all, but ARMv7
2016 * requires the bottom five bits to be RAZ/WI because they're UNK/SBZP.)
2018 raw_write(env
, ri
, value
& ~0x1FULL
);
2021 static void scr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
2023 /* Begin with base v8.0 state. */
2024 uint32_t valid_mask
= 0x3fff;
2025 ARMCPU
*cpu
= env_archcpu(env
);
2027 if (ri
->state
== ARM_CP_STATE_AA64
) {
2028 if (arm_feature(env
, ARM_FEATURE_AARCH64
) &&
2029 !cpu_isar_feature(aa64_aa32_el1
, cpu
)) {
2030 value
|= SCR_FW
| SCR_AW
; /* these two bits are RES1. */
2032 valid_mask
&= ~SCR_NET
;
2034 if (cpu_isar_feature(aa64_lor
, cpu
)) {
2035 valid_mask
|= SCR_TLOR
;
2037 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
2038 valid_mask
|= SCR_API
| SCR_APK
;
2040 if (cpu_isar_feature(aa64_sel2
, cpu
)) {
2041 valid_mask
|= SCR_EEL2
;
2043 if (cpu_isar_feature(aa64_mte
, cpu
)) {
2044 valid_mask
|= SCR_ATA
;
2047 valid_mask
&= ~(SCR_RW
| SCR_ST
);
2050 if (!arm_feature(env
, ARM_FEATURE_EL2
)) {
2051 valid_mask
&= ~SCR_HCE
;
2053 /* On ARMv7, SMD (or SCD as it is called in v7) is only
2054 * supported if EL2 exists. The bit is UNK/SBZP when
2055 * EL2 is unavailable. In QEMU ARMv7, we force it to always zero
2056 * when EL2 is unavailable.
2057 * On ARMv8, this bit is always available.
2059 if (arm_feature(env
, ARM_FEATURE_V7
) &&
2060 !arm_feature(env
, ARM_FEATURE_V8
)) {
2061 valid_mask
&= ~SCR_SMD
;
2065 /* Clear all-context RES0 bits. */
2066 value
&= valid_mask
;
2067 raw_write(env
, ri
, value
);
2070 static void scr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2073 * scr_write will set the RES1 bits on an AArch64-only CPU.
2074 * The reset value will be 0x30 on an AArch64-only CPU and 0 otherwise.
2076 scr_write(env
, ri
, 0);
2079 static CPAccessResult
access_aa64_tid2(CPUARMState
*env
,
2080 const ARMCPRegInfo
*ri
,
2083 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID2
)) {
2084 return CP_ACCESS_TRAP_EL2
;
2087 return CP_ACCESS_OK
;
2090 static uint64_t ccsidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2092 ARMCPU
*cpu
= env_archcpu(env
);
2094 /* Acquire the CSSELR index from the bank corresponding to the CCSIDR
2097 uint32_t index
= A32_BANKED_REG_GET(env
, csselr
,
2098 ri
->secure
& ARM_CP_SECSTATE_S
);
2100 return cpu
->ccsidr
[index
];
2103 static void csselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2106 raw_write(env
, ri
, value
& 0xf);
2109 static uint64_t isr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2111 CPUState
*cs
= env_cpu(env
);
2112 bool el1
= arm_current_el(env
) == 1;
2113 uint64_t hcr_el2
= el1
? arm_hcr_el2_eff(env
) : 0;
2116 if (hcr_el2
& HCR_IMO
) {
2117 if (cs
->interrupt_request
& CPU_INTERRUPT_VIRQ
) {
2121 if (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) {
2126 if (hcr_el2
& HCR_FMO
) {
2127 if (cs
->interrupt_request
& CPU_INTERRUPT_VFIQ
) {
2131 if (cs
->interrupt_request
& CPU_INTERRUPT_FIQ
) {
2136 /* External aborts are not possible in QEMU so A bit is always clear */
2140 static CPAccessResult
access_aa64_tid1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2143 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID1
)) {
2144 return CP_ACCESS_TRAP_EL2
;
2147 return CP_ACCESS_OK
;
2150 static CPAccessResult
access_aa32_tid1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2153 if (arm_feature(env
, ARM_FEATURE_V8
)) {
2154 return access_aa64_tid1(env
, ri
, isread
);
2157 return CP_ACCESS_OK
;
2160 static const ARMCPRegInfo v7_cp_reginfo
[] = {
2161 /* the old v6 WFI, UNPREDICTABLE in v7 but we choose to NOP */
2162 { .name
= "NOP", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
2163 .access
= PL1_W
, .type
= ARM_CP_NOP
},
2164 /* Performance monitors are implementation defined in v7,
2165 * but with an ARM recommended set of registers, which we
2168 * Performance registers fall into three categories:
2169 * (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR)
2170 * (b) RO in PL0 (ie UNDEF on write), RW in PL1 (PMUSERENR)
2171 * (c) UNDEF in PL0 if PMUSERENR.EN==0, otherwise accessible (all others)
2172 * For the cases controlled by PMUSERENR we must set .access to PL0_RW
2173 * or PL0_RO as appropriate and then check PMUSERENR in the helper fn.
2175 { .name
= "PMCNTENSET", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 1,
2176 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
,
2177 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
2178 .writefn
= pmcntenset_write
,
2179 .accessfn
= pmreg_access
,
2180 .raw_writefn
= raw_write
},
2181 { .name
= "PMCNTENSET_EL0", .state
= ARM_CP_STATE_AA64
,
2182 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 1,
2183 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2184 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
), .resetvalue
= 0,
2185 .writefn
= pmcntenset_write
, .raw_writefn
= raw_write
},
2186 { .name
= "PMCNTENCLR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 2,
2188 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
2189 .accessfn
= pmreg_access
,
2190 .writefn
= pmcntenclr_write
,
2191 .type
= ARM_CP_ALIAS
},
2192 { .name
= "PMCNTENCLR_EL0", .state
= ARM_CP_STATE_AA64
,
2193 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 2,
2194 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2195 .type
= ARM_CP_ALIAS
,
2196 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
),
2197 .writefn
= pmcntenclr_write
},
2198 { .name
= "PMOVSR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 3,
2199 .access
= PL0_RW
, .type
= ARM_CP_IO
,
2200 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmovsr
),
2201 .accessfn
= pmreg_access
,
2202 .writefn
= pmovsr_write
,
2203 .raw_writefn
= raw_write
},
2204 { .name
= "PMOVSCLR_EL0", .state
= ARM_CP_STATE_AA64
,
2205 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 3,
2206 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2207 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2208 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
2209 .writefn
= pmovsr_write
,
2210 .raw_writefn
= raw_write
},
2211 { .name
= "PMSWINC", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 4,
2212 .access
= PL0_W
, .accessfn
= pmreg_access_swinc
,
2213 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2214 .writefn
= pmswinc_write
},
2215 { .name
= "PMSWINC_EL0", .state
= ARM_CP_STATE_AA64
,
2216 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 4,
2217 .access
= PL0_W
, .accessfn
= pmreg_access_swinc
,
2218 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2219 .writefn
= pmswinc_write
},
2220 { .name
= "PMSELR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 5,
2221 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
,
2222 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmselr
),
2223 .accessfn
= pmreg_access_selr
, .writefn
= pmselr_write
,
2224 .raw_writefn
= raw_write
},
2225 { .name
= "PMSELR_EL0", .state
= ARM_CP_STATE_AA64
,
2226 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 5,
2227 .access
= PL0_RW
, .accessfn
= pmreg_access_selr
,
2228 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmselr
),
2229 .writefn
= pmselr_write
, .raw_writefn
= raw_write
, },
2230 { .name
= "PMCCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 0,
2231 .access
= PL0_RW
, .resetvalue
= 0, .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2232 .readfn
= pmccntr_read
, .writefn
= pmccntr_write32
,
2233 .accessfn
= pmreg_access_ccntr
},
2234 { .name
= "PMCCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
2235 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 0,
2236 .access
= PL0_RW
, .accessfn
= pmreg_access_ccntr
,
2238 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ccnt
),
2239 .readfn
= pmccntr_read
, .writefn
= pmccntr_write
,
2240 .raw_readfn
= raw_read
, .raw_writefn
= raw_write
, },
2241 { .name
= "PMCCFILTR", .cp
= 15, .opc1
= 0, .crn
= 14, .crm
= 15, .opc2
= 7,
2242 .writefn
= pmccfiltr_write_a32
, .readfn
= pmccfiltr_read_a32
,
2243 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2244 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2246 { .name
= "PMCCFILTR_EL0", .state
= ARM_CP_STATE_AA64
,
2247 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 15, .opc2
= 7,
2248 .writefn
= pmccfiltr_write
, .raw_writefn
= raw_write
,
2249 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2251 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmccfiltr_el0
),
2253 { .name
= "PMXEVTYPER", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 1,
2254 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2255 .accessfn
= pmreg_access
,
2256 .writefn
= pmxevtyper_write
, .readfn
= pmxevtyper_read
},
2257 { .name
= "PMXEVTYPER_EL0", .state
= ARM_CP_STATE_AA64
,
2258 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 1,
2259 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2260 .accessfn
= pmreg_access
,
2261 .writefn
= pmxevtyper_write
, .readfn
= pmxevtyper_read
},
2262 { .name
= "PMXEVCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 2,
2263 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2264 .accessfn
= pmreg_access_xevcntr
,
2265 .writefn
= pmxevcntr_write
, .readfn
= pmxevcntr_read
},
2266 { .name
= "PMXEVCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
2267 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 2,
2268 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2269 .accessfn
= pmreg_access_xevcntr
,
2270 .writefn
= pmxevcntr_write
, .readfn
= pmxevcntr_read
},
2271 { .name
= "PMUSERENR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 0,
2272 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
,
2273 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmuserenr
),
2275 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
2276 { .name
= "PMUSERENR_EL0", .state
= ARM_CP_STATE_AA64
,
2277 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 0,
2278 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
, .type
= ARM_CP_ALIAS
,
2279 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmuserenr
),
2281 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
2282 { .name
= "PMINTENSET", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 1,
2283 .access
= PL1_RW
, .accessfn
= access_tpm
,
2284 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2285 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pminten
),
2287 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
},
2288 { .name
= "PMINTENSET_EL1", .state
= ARM_CP_STATE_AA64
,
2289 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 1,
2290 .access
= PL1_RW
, .accessfn
= access_tpm
,
2292 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2293 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
,
2294 .resetvalue
= 0x0 },
2295 { .name
= "PMINTENCLR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 2,
2296 .access
= PL1_RW
, .accessfn
= access_tpm
,
2297 .type
= ARM_CP_ALIAS
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2298 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2299 .writefn
= pmintenclr_write
, },
2300 { .name
= "PMINTENCLR_EL1", .state
= ARM_CP_STATE_AA64
,
2301 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 2,
2302 .access
= PL1_RW
, .accessfn
= access_tpm
,
2303 .type
= ARM_CP_ALIAS
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2304 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2305 .writefn
= pmintenclr_write
},
2306 { .name
= "CCSIDR", .state
= ARM_CP_STATE_BOTH
,
2307 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 0,
2309 .accessfn
= access_aa64_tid2
,
2310 .readfn
= ccsidr_read
, .type
= ARM_CP_NO_RAW
},
2311 { .name
= "CSSELR", .state
= ARM_CP_STATE_BOTH
,
2312 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 2, .opc2
= 0,
2314 .accessfn
= access_aa64_tid2
,
2315 .writefn
= csselr_write
, .resetvalue
= 0,
2316 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.csselr_s
),
2317 offsetof(CPUARMState
, cp15
.csselr_ns
) } },
2318 /* Auxiliary ID register: this actually has an IMPDEF value but for now
2319 * just RAZ for all cores:
2321 { .name
= "AIDR", .state
= ARM_CP_STATE_BOTH
,
2322 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 7,
2323 .access
= PL1_R
, .type
= ARM_CP_CONST
,
2324 .accessfn
= access_aa64_tid1
,
2326 /* Auxiliary fault status registers: these also are IMPDEF, and we
2327 * choose to RAZ/WI for all cores.
2329 { .name
= "AFSR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2330 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 0,
2331 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2332 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
2333 { .name
= "AFSR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2334 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 1,
2335 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2336 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
2337 /* MAIR can just read-as-written because we don't implement caches
2338 * and so don't need to care about memory attributes.
2340 { .name
= "MAIR_EL1", .state
= ARM_CP_STATE_AA64
,
2341 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
2342 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2343 .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[1]),
2345 { .name
= "MAIR_EL3", .state
= ARM_CP_STATE_AA64
,
2346 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 2, .opc2
= 0,
2347 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[3]),
2349 /* For non-long-descriptor page tables these are PRRR and NMRR;
2350 * regardless they still act as reads-as-written for QEMU.
2352 /* MAIR0/1 are defined separately from their 64-bit counterpart which
2353 * allows them to assign the correct fieldoffset based on the endianness
2354 * handled in the field definitions.
2356 { .name
= "MAIR0", .state
= ARM_CP_STATE_AA32
,
2357 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
2358 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2359 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair0_s
),
2360 offsetof(CPUARMState
, cp15
.mair0_ns
) },
2361 .resetfn
= arm_cp_reset_ignore
},
2362 { .name
= "MAIR1", .state
= ARM_CP_STATE_AA32
,
2363 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 1,
2364 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2365 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair1_s
),
2366 offsetof(CPUARMState
, cp15
.mair1_ns
) },
2367 .resetfn
= arm_cp_reset_ignore
},
2368 { .name
= "ISR_EL1", .state
= ARM_CP_STATE_BOTH
,
2369 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 1, .opc2
= 0,
2370 .type
= ARM_CP_NO_RAW
, .access
= PL1_R
, .readfn
= isr_read
},
2371 /* 32 bit ITLB invalidates */
2372 { .name
= "ITLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 0,
2373 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2374 .writefn
= tlbiall_write
},
2375 { .name
= "ITLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
2376 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2377 .writefn
= tlbimva_write
},
2378 { .name
= "ITLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 2,
2379 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2380 .writefn
= tlbiasid_write
},
2381 /* 32 bit DTLB invalidates */
2382 { .name
= "DTLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 0,
2383 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2384 .writefn
= tlbiall_write
},
2385 { .name
= "DTLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
2386 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2387 .writefn
= tlbimva_write
},
2388 { .name
= "DTLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 2,
2389 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2390 .writefn
= tlbiasid_write
},
2391 /* 32 bit TLB invalidates */
2392 { .name
= "TLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
2393 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2394 .writefn
= tlbiall_write
},
2395 { .name
= "TLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
2396 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2397 .writefn
= tlbimva_write
},
2398 { .name
= "TLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
2399 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2400 .writefn
= tlbiasid_write
},
2401 { .name
= "TLBIMVAA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
2402 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2403 .writefn
= tlbimvaa_write
},
2407 static const ARMCPRegInfo v7mp_cp_reginfo
[] = {
2408 /* 32 bit TLB invalidates, Inner Shareable */
2409 { .name
= "TLBIALLIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
2410 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2411 .writefn
= tlbiall_is_write
},
2412 { .name
= "TLBIMVAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
2413 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2414 .writefn
= tlbimva_is_write
},
2415 { .name
= "TLBIASIDIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
2416 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2417 .writefn
= tlbiasid_is_write
},
2418 { .name
= "TLBIMVAAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
2419 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2420 .writefn
= tlbimvaa_is_write
},
2424 static const ARMCPRegInfo pmovsset_cp_reginfo
[] = {
2425 /* PMOVSSET is not implemented in v7 before v7ve */
2426 { .name
= "PMOVSSET", .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 3,
2427 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2428 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2429 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmovsr
),
2430 .writefn
= pmovsset_write
,
2431 .raw_writefn
= raw_write
},
2432 { .name
= "PMOVSSET_EL0", .state
= ARM_CP_STATE_AA64
,
2433 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 3,
2434 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2435 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2436 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
2437 .writefn
= pmovsset_write
,
2438 .raw_writefn
= raw_write
},
2442 static void teecr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2449 static CPAccessResult
teehbr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2452 if (arm_current_el(env
) == 0 && (env
->teecr
& 1)) {
2453 return CP_ACCESS_TRAP
;
2455 return CP_ACCESS_OK
;
2458 static const ARMCPRegInfo t2ee_cp_reginfo
[] = {
2459 { .name
= "TEECR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 6, .opc2
= 0,
2460 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, teecr
),
2462 .writefn
= teecr_write
},
2463 { .name
= "TEEHBR", .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 6, .opc2
= 0,
2464 .access
= PL0_RW
, .fieldoffset
= offsetof(CPUARMState
, teehbr
),
2465 .accessfn
= teehbr_access
, .resetvalue
= 0 },
2469 static const ARMCPRegInfo v6k_cp_reginfo
[] = {
2470 { .name
= "TPIDR_EL0", .state
= ARM_CP_STATE_AA64
,
2471 .opc0
= 3, .opc1
= 3, .opc2
= 2, .crn
= 13, .crm
= 0,
2473 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[0]), .resetvalue
= 0 },
2474 { .name
= "TPIDRURW", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 2,
2476 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrurw_s
),
2477 offsetoflow32(CPUARMState
, cp15
.tpidrurw_ns
) },
2478 .resetfn
= arm_cp_reset_ignore
},
2479 { .name
= "TPIDRRO_EL0", .state
= ARM_CP_STATE_AA64
,
2480 .opc0
= 3, .opc1
= 3, .opc2
= 3, .crn
= 13, .crm
= 0,
2481 .access
= PL0_R
|PL1_W
,
2482 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidrro_el
[0]),
2484 { .name
= "TPIDRURO", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 3,
2485 .access
= PL0_R
|PL1_W
,
2486 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidruro_s
),
2487 offsetoflow32(CPUARMState
, cp15
.tpidruro_ns
) },
2488 .resetfn
= arm_cp_reset_ignore
},
2489 { .name
= "TPIDR_EL1", .state
= ARM_CP_STATE_AA64
,
2490 .opc0
= 3, .opc1
= 0, .opc2
= 4, .crn
= 13, .crm
= 0,
2492 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[1]), .resetvalue
= 0 },
2493 { .name
= "TPIDRPRW", .opc1
= 0, .cp
= 15, .crn
= 13, .crm
= 0, .opc2
= 4,
2495 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrprw_s
),
2496 offsetoflow32(CPUARMState
, cp15
.tpidrprw_ns
) },
2501 #ifndef CONFIG_USER_ONLY
2503 static CPAccessResult
gt_cntfrq_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2506 /* CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero.
2507 * Writable only at the highest implemented exception level.
2509 int el
= arm_current_el(env
);
2515 hcr
= arm_hcr_el2_eff(env
);
2516 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2517 cntkctl
= env
->cp15
.cnthctl_el2
;
2519 cntkctl
= env
->cp15
.c14_cntkctl
;
2521 if (!extract32(cntkctl
, 0, 2)) {
2522 return CP_ACCESS_TRAP
;
2526 if (!isread
&& ri
->state
== ARM_CP_STATE_AA32
&&
2527 arm_is_secure_below_el3(env
)) {
2528 /* Accesses from 32-bit Secure EL1 UNDEF (*not* trap to EL3!) */
2529 return CP_ACCESS_TRAP_UNCATEGORIZED
;
2537 if (!isread
&& el
< arm_highest_el(env
)) {
2538 return CP_ACCESS_TRAP_UNCATEGORIZED
;
2541 return CP_ACCESS_OK
;
2544 static CPAccessResult
gt_counter_access(CPUARMState
*env
, int timeridx
,
2547 unsigned int cur_el
= arm_current_el(env
);
2548 bool has_el2
= arm_is_el2_enabled(env
);
2549 uint64_t hcr
= arm_hcr_el2_eff(env
);
2553 /* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]CTEN. */
2554 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2555 return (extract32(env
->cp15
.cnthctl_el2
, timeridx
, 1)
2556 ? CP_ACCESS_OK
: CP_ACCESS_TRAP_EL2
);
2559 /* CNT[PV]CT: not visible from PL0 if EL0[PV]CTEN is zero */
2560 if (!extract32(env
->cp15
.c14_cntkctl
, timeridx
, 1)) {
2561 return CP_ACCESS_TRAP
;
2564 /* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PCTEN. */
2565 if (hcr
& HCR_E2H
) {
2566 if (timeridx
== GTIMER_PHYS
&&
2567 !extract32(env
->cp15
.cnthctl_el2
, 10, 1)) {
2568 return CP_ACCESS_TRAP_EL2
;
2571 /* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */
2572 if (has_el2
&& timeridx
== GTIMER_PHYS
&&
2573 !extract32(env
->cp15
.cnthctl_el2
, 1, 1)) {
2574 return CP_ACCESS_TRAP_EL2
;
2580 /* Check CNTHCTL_EL2.EL1PCTEN, which changes location based on E2H. */
2581 if (has_el2
&& timeridx
== GTIMER_PHYS
&&
2583 ? !extract32(env
->cp15
.cnthctl_el2
, 10, 1)
2584 : !extract32(env
->cp15
.cnthctl_el2
, 0, 1))) {
2585 return CP_ACCESS_TRAP_EL2
;
2589 return CP_ACCESS_OK
;
2592 static CPAccessResult
gt_timer_access(CPUARMState
*env
, int timeridx
,
2595 unsigned int cur_el
= arm_current_el(env
);
2596 bool has_el2
= arm_is_el2_enabled(env
);
2597 uint64_t hcr
= arm_hcr_el2_eff(env
);
2601 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2602 /* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]TEN. */
2603 return (extract32(env
->cp15
.cnthctl_el2
, 9 - timeridx
, 1)
2604 ? CP_ACCESS_OK
: CP_ACCESS_TRAP_EL2
);
2608 * CNT[PV]_CVAL, CNT[PV]_CTL, CNT[PV]_TVAL: not visible from
2609 * EL0 if EL0[PV]TEN is zero.
2611 if (!extract32(env
->cp15
.c14_cntkctl
, 9 - timeridx
, 1)) {
2612 return CP_ACCESS_TRAP
;
2617 if (has_el2
&& timeridx
== GTIMER_PHYS
) {
2618 if (hcr
& HCR_E2H
) {
2619 /* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PTEN. */
2620 if (!extract32(env
->cp15
.cnthctl_el2
, 11, 1)) {
2621 return CP_ACCESS_TRAP_EL2
;
2624 /* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */
2625 if (!extract32(env
->cp15
.cnthctl_el2
, 1, 1)) {
2626 return CP_ACCESS_TRAP_EL2
;
2632 return CP_ACCESS_OK
;
2635 static CPAccessResult
gt_pct_access(CPUARMState
*env
,
2636 const ARMCPRegInfo
*ri
,
2639 return gt_counter_access(env
, GTIMER_PHYS
, isread
);
2642 static CPAccessResult
gt_vct_access(CPUARMState
*env
,
2643 const ARMCPRegInfo
*ri
,
2646 return gt_counter_access(env
, GTIMER_VIRT
, isread
);
2649 static CPAccessResult
gt_ptimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2652 return gt_timer_access(env
, GTIMER_PHYS
, isread
);
2655 static CPAccessResult
gt_vtimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2658 return gt_timer_access(env
, GTIMER_VIRT
, isread
);
2661 static CPAccessResult
gt_stimer_access(CPUARMState
*env
,
2662 const ARMCPRegInfo
*ri
,
2665 /* The AArch64 register view of the secure physical timer is
2666 * always accessible from EL3, and configurably accessible from
2669 switch (arm_current_el(env
)) {
2671 if (!arm_is_secure(env
)) {
2672 return CP_ACCESS_TRAP
;
2674 if (!(env
->cp15
.scr_el3
& SCR_ST
)) {
2675 return CP_ACCESS_TRAP_EL3
;
2677 return CP_ACCESS_OK
;
2680 return CP_ACCESS_TRAP
;
2682 return CP_ACCESS_OK
;
2684 g_assert_not_reached();
2688 static uint64_t gt_get_countervalue(CPUARMState
*env
)
2690 ARMCPU
*cpu
= env_archcpu(env
);
2692 return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) / gt_cntfrq_period_ns(cpu
);
2695 static void gt_recalc_timer(ARMCPU
*cpu
, int timeridx
)
2697 ARMGenericTimer
*gt
= &cpu
->env
.cp15
.c14_timer
[timeridx
];
2700 /* Timer enabled: calculate and set current ISTATUS, irq, and
2701 * reset timer to when ISTATUS next has to change
2703 uint64_t offset
= timeridx
== GTIMER_VIRT
?
2704 cpu
->env
.cp15
.cntvoff_el2
: 0;
2705 uint64_t count
= gt_get_countervalue(&cpu
->env
);
2706 /* Note that this must be unsigned 64 bit arithmetic: */
2707 int istatus
= count
- offset
>= gt
->cval
;
2711 gt
->ctl
= deposit32(gt
->ctl
, 2, 1, istatus
);
2713 irqstate
= (istatus
&& !(gt
->ctl
& 2));
2714 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], irqstate
);
2717 /* Next transition is when count rolls back over to zero */
2718 nexttick
= UINT64_MAX
;
2720 /* Next transition is when we hit cval */
2721 nexttick
= gt
->cval
+ offset
;
2723 /* Note that the desired next expiry time might be beyond the
2724 * signed-64-bit range of a QEMUTimer -- in this case we just
2725 * set the timer for as far in the future as possible. When the
2726 * timer expires we will reset the timer for any remaining period.
2728 if (nexttick
> INT64_MAX
/ gt_cntfrq_period_ns(cpu
)) {
2729 timer_mod_ns(cpu
->gt_timer
[timeridx
], INT64_MAX
);
2731 timer_mod(cpu
->gt_timer
[timeridx
], nexttick
);
2733 trace_arm_gt_recalc(timeridx
, irqstate
, nexttick
);
2735 /* Timer disabled: ISTATUS and timer output always clear */
2737 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], 0);
2738 timer_del(cpu
->gt_timer
[timeridx
]);
2739 trace_arm_gt_recalc_disabled(timeridx
);
2743 static void gt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2746 ARMCPU
*cpu
= env_archcpu(env
);
2748 timer_del(cpu
->gt_timer
[timeridx
]);
2751 static uint64_t gt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2753 return gt_get_countervalue(env
);
2756 static uint64_t gt_virt_cnt_offset(CPUARMState
*env
)
2760 switch (arm_current_el(env
)) {
2762 hcr
= arm_hcr_el2_eff(env
);
2763 if (hcr
& HCR_E2H
) {
2768 hcr
= arm_hcr_el2_eff(env
);
2769 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2775 return env
->cp15
.cntvoff_el2
;
2778 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2780 return gt_get_countervalue(env
) - gt_virt_cnt_offset(env
);
2783 static void gt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2787 trace_arm_gt_cval_write(timeridx
, value
);
2788 env
->cp15
.c14_timer
[timeridx
].cval
= value
;
2789 gt_recalc_timer(env_archcpu(env
), timeridx
);
2792 static uint64_t gt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2795 uint64_t offset
= 0;
2799 case GTIMER_HYPVIRT
:
2800 offset
= gt_virt_cnt_offset(env
);
2804 return (uint32_t)(env
->cp15
.c14_timer
[timeridx
].cval
-
2805 (gt_get_countervalue(env
) - offset
));
2808 static void gt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2812 uint64_t offset
= 0;
2816 case GTIMER_HYPVIRT
:
2817 offset
= gt_virt_cnt_offset(env
);
2821 trace_arm_gt_tval_write(timeridx
, value
);
2822 env
->cp15
.c14_timer
[timeridx
].cval
= gt_get_countervalue(env
) - offset
+
2823 sextract64(value
, 0, 32);
2824 gt_recalc_timer(env_archcpu(env
), timeridx
);
2827 static void gt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2831 ARMCPU
*cpu
= env_archcpu(env
);
2832 uint32_t oldval
= env
->cp15
.c14_timer
[timeridx
].ctl
;
2834 trace_arm_gt_ctl_write(timeridx
, value
);
2835 env
->cp15
.c14_timer
[timeridx
].ctl
= deposit64(oldval
, 0, 2, value
);
2836 if ((oldval
^ value
) & 1) {
2837 /* Enable toggled */
2838 gt_recalc_timer(cpu
, timeridx
);
2839 } else if ((oldval
^ value
) & 2) {
2840 /* IMASK toggled: don't need to recalculate,
2841 * just set the interrupt line based on ISTATUS
2843 int irqstate
= (oldval
& 4) && !(value
& 2);
2845 trace_arm_gt_imask_toggle(timeridx
, irqstate
);
2846 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], irqstate
);
2850 static void gt_phys_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2852 gt_timer_reset(env
, ri
, GTIMER_PHYS
);
2855 static void gt_phys_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2858 gt_cval_write(env
, ri
, GTIMER_PHYS
, value
);
2861 static uint64_t gt_phys_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2863 return gt_tval_read(env
, ri
, GTIMER_PHYS
);
2866 static void gt_phys_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2869 gt_tval_write(env
, ri
, GTIMER_PHYS
, value
);
2872 static void gt_phys_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2875 gt_ctl_write(env
, ri
, GTIMER_PHYS
, value
);
2878 static int gt_phys_redir_timeridx(CPUARMState
*env
)
2880 switch (arm_mmu_idx(env
)) {
2881 case ARMMMUIdx_E20_0
:
2882 case ARMMMUIdx_E20_2
:
2883 case ARMMMUIdx_E20_2_PAN
:
2884 case ARMMMUIdx_SE20_0
:
2885 case ARMMMUIdx_SE20_2
:
2886 case ARMMMUIdx_SE20_2_PAN
:
2893 static int gt_virt_redir_timeridx(CPUARMState
*env
)
2895 switch (arm_mmu_idx(env
)) {
2896 case ARMMMUIdx_E20_0
:
2897 case ARMMMUIdx_E20_2
:
2898 case ARMMMUIdx_E20_2_PAN
:
2899 case ARMMMUIdx_SE20_0
:
2900 case ARMMMUIdx_SE20_2
:
2901 case ARMMMUIdx_SE20_2_PAN
:
2902 return GTIMER_HYPVIRT
;
2908 static uint64_t gt_phys_redir_cval_read(CPUARMState
*env
,
2909 const ARMCPRegInfo
*ri
)
2911 int timeridx
= gt_phys_redir_timeridx(env
);
2912 return env
->cp15
.c14_timer
[timeridx
].cval
;
2915 static void gt_phys_redir_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2918 int timeridx
= gt_phys_redir_timeridx(env
);
2919 gt_cval_write(env
, ri
, timeridx
, value
);
2922 static uint64_t gt_phys_redir_tval_read(CPUARMState
*env
,
2923 const ARMCPRegInfo
*ri
)
2925 int timeridx
= gt_phys_redir_timeridx(env
);
2926 return gt_tval_read(env
, ri
, timeridx
);
2929 static void gt_phys_redir_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2932 int timeridx
= gt_phys_redir_timeridx(env
);
2933 gt_tval_write(env
, ri
, timeridx
, value
);
2936 static uint64_t gt_phys_redir_ctl_read(CPUARMState
*env
,
2937 const ARMCPRegInfo
*ri
)
2939 int timeridx
= gt_phys_redir_timeridx(env
);
2940 return env
->cp15
.c14_timer
[timeridx
].ctl
;
2943 static void gt_phys_redir_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2946 int timeridx
= gt_phys_redir_timeridx(env
);
2947 gt_ctl_write(env
, ri
, timeridx
, value
);
2950 static void gt_virt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2952 gt_timer_reset(env
, ri
, GTIMER_VIRT
);
2955 static void gt_virt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2958 gt_cval_write(env
, ri
, GTIMER_VIRT
, value
);
2961 static uint64_t gt_virt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2963 return gt_tval_read(env
, ri
, GTIMER_VIRT
);
2966 static void gt_virt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2969 gt_tval_write(env
, ri
, GTIMER_VIRT
, value
);
2972 static void gt_virt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2975 gt_ctl_write(env
, ri
, GTIMER_VIRT
, value
);
2978 static void gt_cntvoff_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2981 ARMCPU
*cpu
= env_archcpu(env
);
2983 trace_arm_gt_cntvoff_write(value
);
2984 raw_write(env
, ri
, value
);
2985 gt_recalc_timer(cpu
, GTIMER_VIRT
);
2988 static uint64_t gt_virt_redir_cval_read(CPUARMState
*env
,
2989 const ARMCPRegInfo
*ri
)
2991 int timeridx
= gt_virt_redir_timeridx(env
);
2992 return env
->cp15
.c14_timer
[timeridx
].cval
;
2995 static void gt_virt_redir_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2998 int timeridx
= gt_virt_redir_timeridx(env
);
2999 gt_cval_write(env
, ri
, timeridx
, value
);
3002 static uint64_t gt_virt_redir_tval_read(CPUARMState
*env
,
3003 const ARMCPRegInfo
*ri
)
3005 int timeridx
= gt_virt_redir_timeridx(env
);
3006 return gt_tval_read(env
, ri
, timeridx
);
3009 static void gt_virt_redir_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3012 int timeridx
= gt_virt_redir_timeridx(env
);
3013 gt_tval_write(env
, ri
, timeridx
, value
);
3016 static uint64_t gt_virt_redir_ctl_read(CPUARMState
*env
,
3017 const ARMCPRegInfo
*ri
)
3019 int timeridx
= gt_virt_redir_timeridx(env
);
3020 return env
->cp15
.c14_timer
[timeridx
].ctl
;
3023 static void gt_virt_redir_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3026 int timeridx
= gt_virt_redir_timeridx(env
);
3027 gt_ctl_write(env
, ri
, timeridx
, value
);
3030 static void gt_hyp_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3032 gt_timer_reset(env
, ri
, GTIMER_HYP
);
3035 static void gt_hyp_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3038 gt_cval_write(env
, ri
, GTIMER_HYP
, value
);
3041 static uint64_t gt_hyp_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3043 return gt_tval_read(env
, ri
, GTIMER_HYP
);
3046 static void gt_hyp_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3049 gt_tval_write(env
, ri
, GTIMER_HYP
, value
);
3052 static void gt_hyp_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3055 gt_ctl_write(env
, ri
, GTIMER_HYP
, value
);
3058 static void gt_sec_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3060 gt_timer_reset(env
, ri
, GTIMER_SEC
);
3063 static void gt_sec_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3066 gt_cval_write(env
, ri
, GTIMER_SEC
, value
);
3069 static uint64_t gt_sec_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3071 return gt_tval_read(env
, ri
, GTIMER_SEC
);
3074 static void gt_sec_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3077 gt_tval_write(env
, ri
, GTIMER_SEC
, value
);
3080 static void gt_sec_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3083 gt_ctl_write(env
, ri
, GTIMER_SEC
, value
);
3086 static void gt_hv_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3088 gt_timer_reset(env
, ri
, GTIMER_HYPVIRT
);
3091 static void gt_hv_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3094 gt_cval_write(env
, ri
, GTIMER_HYPVIRT
, value
);
3097 static uint64_t gt_hv_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3099 return gt_tval_read(env
, ri
, GTIMER_HYPVIRT
);
3102 static void gt_hv_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3105 gt_tval_write(env
, ri
, GTIMER_HYPVIRT
, value
);
3108 static void gt_hv_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3111 gt_ctl_write(env
, ri
, GTIMER_HYPVIRT
, value
);
3114 void arm_gt_ptimer_cb(void *opaque
)
3116 ARMCPU
*cpu
= opaque
;
3118 gt_recalc_timer(cpu
, GTIMER_PHYS
);
3121 void arm_gt_vtimer_cb(void *opaque
)
3123 ARMCPU
*cpu
= opaque
;
3125 gt_recalc_timer(cpu
, GTIMER_VIRT
);
3128 void arm_gt_htimer_cb(void *opaque
)
3130 ARMCPU
*cpu
= opaque
;
3132 gt_recalc_timer(cpu
, GTIMER_HYP
);
3135 void arm_gt_stimer_cb(void *opaque
)
3137 ARMCPU
*cpu
= opaque
;
3139 gt_recalc_timer(cpu
, GTIMER_SEC
);
3142 void arm_gt_hvtimer_cb(void *opaque
)
3144 ARMCPU
*cpu
= opaque
;
3146 gt_recalc_timer(cpu
, GTIMER_HYPVIRT
);
3149 static void arm_gt_cntfrq_reset(CPUARMState
*env
, const ARMCPRegInfo
*opaque
)
3151 ARMCPU
*cpu
= env_archcpu(env
);
3153 cpu
->env
.cp15
.c14_cntfrq
= cpu
->gt_cntfrq_hz
;
3156 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
3157 /* Note that CNTFRQ is purely reads-as-written for the benefit
3158 * of software; writing it doesn't actually change the timer frequency.
3159 * Our reset value matches the fixed frequency we implement the timer at.
3161 { .name
= "CNTFRQ", .cp
= 15, .crn
= 14, .crm
= 0, .opc1
= 0, .opc2
= 0,
3162 .type
= ARM_CP_ALIAS
,
3163 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
3164 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c14_cntfrq
),
3166 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
3167 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
3168 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
3169 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
3170 .resetfn
= arm_gt_cntfrq_reset
,
3172 /* overall control: mostly access permissions */
3173 { .name
= "CNTKCTL", .state
= ARM_CP_STATE_BOTH
,
3174 .opc0
= 3, .opc1
= 0, .crn
= 14, .crm
= 1, .opc2
= 0,
3176 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntkctl
),
3179 /* per-timer control */
3180 { .name
= "CNTP_CTL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
3181 .secure
= ARM_CP_SECSTATE_NS
,
3182 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
3183 .accessfn
= gt_ptimer_access
,
3184 .fieldoffset
= offsetoflow32(CPUARMState
,
3185 cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
3186 .readfn
= gt_phys_redir_ctl_read
, .raw_readfn
= raw_read
,
3187 .writefn
= gt_phys_redir_ctl_write
, .raw_writefn
= raw_write
,
3189 { .name
= "CNTP_CTL_S",
3190 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
3191 .secure
= ARM_CP_SECSTATE_S
,
3192 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
3193 .accessfn
= gt_ptimer_access
,
3194 .fieldoffset
= offsetoflow32(CPUARMState
,
3195 cp15
.c14_timer
[GTIMER_SEC
].ctl
),
3196 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
3198 { .name
= "CNTP_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
3199 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 1,
3200 .type
= ARM_CP_IO
, .access
= PL0_RW
,
3201 .accessfn
= gt_ptimer_access
,
3202 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
3204 .readfn
= gt_phys_redir_ctl_read
, .raw_readfn
= raw_read
,
3205 .writefn
= gt_phys_redir_ctl_write
, .raw_writefn
= raw_write
,
3207 { .name
= "CNTV_CTL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 1,
3208 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
3209 .accessfn
= gt_vtimer_access
,
3210 .fieldoffset
= offsetoflow32(CPUARMState
,
3211 cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
3212 .readfn
= gt_virt_redir_ctl_read
, .raw_readfn
= raw_read
,
3213 .writefn
= gt_virt_redir_ctl_write
, .raw_writefn
= raw_write
,
3215 { .name
= "CNTV_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
3216 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 1,
3217 .type
= ARM_CP_IO
, .access
= PL0_RW
,
3218 .accessfn
= gt_vtimer_access
,
3219 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
3221 .readfn
= gt_virt_redir_ctl_read
, .raw_readfn
= raw_read
,
3222 .writefn
= gt_virt_redir_ctl_write
, .raw_writefn
= raw_write
,
3224 /* TimerValue views: a 32 bit downcounting view of the underlying state */
3225 { .name
= "CNTP_TVAL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
3226 .secure
= ARM_CP_SECSTATE_NS
,
3227 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3228 .accessfn
= gt_ptimer_access
,
3229 .readfn
= gt_phys_redir_tval_read
, .writefn
= gt_phys_redir_tval_write
,
3231 { .name
= "CNTP_TVAL_S",
3232 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
3233 .secure
= ARM_CP_SECSTATE_S
,
3234 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3235 .accessfn
= gt_ptimer_access
,
3236 .readfn
= gt_sec_tval_read
, .writefn
= gt_sec_tval_write
,
3238 { .name
= "CNTP_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3239 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 0,
3240 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3241 .accessfn
= gt_ptimer_access
, .resetfn
= gt_phys_timer_reset
,
3242 .readfn
= gt_phys_redir_tval_read
, .writefn
= gt_phys_redir_tval_write
,
3244 { .name
= "CNTV_TVAL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 0,
3245 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3246 .accessfn
= gt_vtimer_access
,
3247 .readfn
= gt_virt_redir_tval_read
, .writefn
= gt_virt_redir_tval_write
,
3249 { .name
= "CNTV_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3250 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 0,
3251 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3252 .accessfn
= gt_vtimer_access
, .resetfn
= gt_virt_timer_reset
,
3253 .readfn
= gt_virt_redir_tval_read
, .writefn
= gt_virt_redir_tval_write
,
3255 /* The counter itself */
3256 { .name
= "CNTPCT", .cp
= 15, .crm
= 14, .opc1
= 0,
3257 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3258 .accessfn
= gt_pct_access
,
3259 .readfn
= gt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3261 { .name
= "CNTPCT_EL0", .state
= ARM_CP_STATE_AA64
,
3262 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 1,
3263 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3264 .accessfn
= gt_pct_access
, .readfn
= gt_cnt_read
,
3266 { .name
= "CNTVCT", .cp
= 15, .crm
= 14, .opc1
= 1,
3267 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3268 .accessfn
= gt_vct_access
,
3269 .readfn
= gt_virt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3271 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
3272 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
3273 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3274 .accessfn
= gt_vct_access
, .readfn
= gt_virt_cnt_read
,
3276 /* Comparison value, indicating when the timer goes off */
3277 { .name
= "CNTP_CVAL", .cp
= 15, .crm
= 14, .opc1
= 2,
3278 .secure
= ARM_CP_SECSTATE_NS
,
3280 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3281 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
3282 .accessfn
= gt_ptimer_access
,
3283 .readfn
= gt_phys_redir_cval_read
, .raw_readfn
= raw_read
,
3284 .writefn
= gt_phys_redir_cval_write
, .raw_writefn
= raw_write
,
3286 { .name
= "CNTP_CVAL_S", .cp
= 15, .crm
= 14, .opc1
= 2,
3287 .secure
= ARM_CP_SECSTATE_S
,
3289 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3290 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
3291 .accessfn
= gt_ptimer_access
,
3292 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
3294 { .name
= "CNTP_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3295 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 2,
3298 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
3299 .resetvalue
= 0, .accessfn
= gt_ptimer_access
,
3300 .readfn
= gt_phys_redir_cval_read
, .raw_readfn
= raw_read
,
3301 .writefn
= gt_phys_redir_cval_write
, .raw_writefn
= raw_write
,
3303 { .name
= "CNTV_CVAL", .cp
= 15, .crm
= 14, .opc1
= 3,
3305 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3306 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
3307 .accessfn
= gt_vtimer_access
,
3308 .readfn
= gt_virt_redir_cval_read
, .raw_readfn
= raw_read
,
3309 .writefn
= gt_virt_redir_cval_write
, .raw_writefn
= raw_write
,
3311 { .name
= "CNTV_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3312 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 2,
3315 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
3316 .resetvalue
= 0, .accessfn
= gt_vtimer_access
,
3317 .readfn
= gt_virt_redir_cval_read
, .raw_readfn
= raw_read
,
3318 .writefn
= gt_virt_redir_cval_write
, .raw_writefn
= raw_write
,
3320 /* Secure timer -- this is actually restricted to only EL3
3321 * and configurably Secure-EL1 via the accessfn.
3323 { .name
= "CNTPS_TVAL_EL1", .state
= ARM_CP_STATE_AA64
,
3324 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 0,
3325 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
,
3326 .accessfn
= gt_stimer_access
,
3327 .readfn
= gt_sec_tval_read
,
3328 .writefn
= gt_sec_tval_write
,
3329 .resetfn
= gt_sec_timer_reset
,
3331 { .name
= "CNTPS_CTL_EL1", .state
= ARM_CP_STATE_AA64
,
3332 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 1,
3333 .type
= ARM_CP_IO
, .access
= PL1_RW
,
3334 .accessfn
= gt_stimer_access
,
3335 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].ctl
),
3337 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
3339 { .name
= "CNTPS_CVAL_EL1", .state
= ARM_CP_STATE_AA64
,
3340 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 2,
3341 .type
= ARM_CP_IO
, .access
= PL1_RW
,
3342 .accessfn
= gt_stimer_access
,
3343 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
3344 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
3349 static CPAccessResult
e2h_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3352 if (!(arm_hcr_el2_eff(env
) & HCR_E2H
)) {
3353 return CP_ACCESS_TRAP
;
3355 return CP_ACCESS_OK
;
3360 /* In user-mode most of the generic timer registers are inaccessible
3361 * however modern kernels (4.12+) allow access to cntvct_el0
3364 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3366 ARMCPU
*cpu
= env_archcpu(env
);
3368 /* Currently we have no support for QEMUTimer in linux-user so we
3369 * can't call gt_get_countervalue(env), instead we directly
3370 * call the lower level functions.
3372 return cpu_get_clock() / gt_cntfrq_period_ns(cpu
);
3375 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
3376 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
3377 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
3378 .type
= ARM_CP_CONST
, .access
= PL0_R
/* no PL1_RW in linux-user */,
3379 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
3380 .resetvalue
= NANOSECONDS_PER_SECOND
/ GTIMER_SCALE
,
3382 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
3383 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
3384 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3385 .readfn
= gt_virt_cnt_read
,
3392 static void par_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
3394 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3395 raw_write(env
, ri
, value
);
3396 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
3397 raw_write(env
, ri
, value
& 0xfffff6ff);
3399 raw_write(env
, ri
, value
& 0xfffff1ff);
3403 #ifndef CONFIG_USER_ONLY
3404 /* get_phys_addr() isn't present for user-mode-only targets */
3406 static CPAccessResult
ats_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3410 /* The ATS12NSO* operations must trap to EL3 or EL2 if executed in
3411 * Secure EL1 (which can only happen if EL3 is AArch64).
3412 * They are simply UNDEF if executed from NS EL1.
3413 * They function normally from EL2 or EL3.
3415 if (arm_current_el(env
) == 1) {
3416 if (arm_is_secure_below_el3(env
)) {
3417 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
3418 return CP_ACCESS_TRAP_UNCATEGORIZED_EL2
;
3420 return CP_ACCESS_TRAP_UNCATEGORIZED_EL3
;
3422 return CP_ACCESS_TRAP_UNCATEGORIZED
;
3425 return CP_ACCESS_OK
;
3429 static uint64_t do_ats_write(CPUARMState
*env
, uint64_t value
,
3430 MMUAccessType access_type
, ARMMMUIdx mmu_idx
)
3433 target_ulong page_size
;
3437 bool format64
= false;
3438 MemTxAttrs attrs
= {};
3439 ARMMMUFaultInfo fi
= {};
3440 ARMCacheAttrs cacheattrs
= {};
3442 ret
= get_phys_addr(env
, value
, access_type
, mmu_idx
, &phys_addr
, &attrs
,
3443 &prot
, &page_size
, &fi
, &cacheattrs
);
3447 * Some kinds of translation fault must cause exceptions rather
3448 * than being reported in the PAR.
3450 int current_el
= arm_current_el(env
);
3452 uint32_t syn
, fsr
, fsc
;
3453 bool take_exc
= false;
3455 if (fi
.s1ptw
&& current_el
== 1
3456 && arm_mmu_idx_is_stage1_of_2(mmu_idx
)) {
3458 * Synchronous stage 2 fault on an access made as part of the
3459 * translation table walk for AT S1E0* or AT S1E1* insn
3460 * executed from NS EL1. If this is a synchronous external abort
3461 * and SCR_EL3.EA == 1, then we take a synchronous external abort
3462 * to EL3. Otherwise the fault is taken as an exception to EL2,
3463 * and HPFAR_EL2 holds the faulting IPA.
3465 if (fi
.type
== ARMFault_SyncExternalOnWalk
&&
3466 (env
->cp15
.scr_el3
& SCR_EA
)) {
3469 env
->cp15
.hpfar_el2
= extract64(fi
.s2addr
, 12, 47) << 4;
3470 if (arm_is_secure_below_el3(env
) && fi
.s1ns
) {
3471 env
->cp15
.hpfar_el2
|= HPFAR_NS
;
3476 } else if (fi
.type
== ARMFault_SyncExternalOnWalk
) {
3478 * Synchronous external aborts during a translation table walk
3479 * are taken as Data Abort exceptions.
3482 if (current_el
== 3) {
3488 target_el
= exception_target_el(env
);
3494 /* Construct FSR and FSC using same logic as arm_deliver_fault() */
3495 if (target_el
== 2 || arm_el_is_aa64(env
, target_el
) ||
3496 arm_s1_regime_using_lpae_format(env
, mmu_idx
)) {
3497 fsr
= arm_fi_to_lfsc(&fi
);
3498 fsc
= extract32(fsr
, 0, 6);
3500 fsr
= arm_fi_to_sfsc(&fi
);
3504 * Report exception with ESR indicating a fault due to a
3505 * translation table walk for a cache maintenance instruction.
3507 syn
= syn_data_abort_no_iss(current_el
== target_el
, 0,
3508 fi
.ea
, 1, fi
.s1ptw
, 1, fsc
);
3509 env
->exception
.vaddress
= value
;
3510 env
->exception
.fsr
= fsr
;
3511 raise_exception(env
, EXCP_DATA_ABORT
, syn
, target_el
);
3517 } else if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3520 * * TTBCR.EAE determines whether the result is returned using the
3521 * 32-bit or the 64-bit PAR format
3522 * * Instructions executed in Hyp mode always use the 64bit format
3524 * ATS1S2NSOxx uses the 64bit format if any of the following is true:
3525 * * The Non-secure TTBCR.EAE bit is set to 1
3526 * * The implementation includes EL2, and the value of HCR.VM is 1
3528 * (Note that HCR.DC makes HCR.VM behave as if it is 1.)
3530 * ATS1Hx always uses the 64bit format.
3532 format64
= arm_s1_regime_using_lpae_format(env
, mmu_idx
);
3534 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
3535 if (mmu_idx
== ARMMMUIdx_E10_0
||
3536 mmu_idx
== ARMMMUIdx_E10_1
||
3537 mmu_idx
== ARMMMUIdx_E10_1_PAN
) {
3538 format64
|= env
->cp15
.hcr_el2
& (HCR_VM
| HCR_DC
);
3540 format64
|= arm_current_el(env
) == 2;
3546 /* Create a 64-bit PAR */
3547 par64
= (1 << 11); /* LPAE bit always set */
3549 par64
|= phys_addr
& ~0xfffULL
;
3550 if (!attrs
.secure
) {
3551 par64
|= (1 << 9); /* NS */
3553 par64
|= (uint64_t)cacheattrs
.attrs
<< 56; /* ATTR */
3554 par64
|= cacheattrs
.shareability
<< 7; /* SH */
3556 uint32_t fsr
= arm_fi_to_lfsc(&fi
);
3559 par64
|= (fsr
& 0x3f) << 1; /* FS */
3561 par64
|= (1 << 9); /* S */
3564 par64
|= (1 << 8); /* PTW */
3568 /* fsr is a DFSR/IFSR value for the short descriptor
3569 * translation table format (with WnR always clear).
3570 * Convert it to a 32-bit PAR.
3573 /* We do not set any attribute bits in the PAR */
3574 if (page_size
== (1 << 24)
3575 && arm_feature(env
, ARM_FEATURE_V7
)) {
3576 par64
= (phys_addr
& 0xff000000) | (1 << 1);
3578 par64
= phys_addr
& 0xfffff000;
3580 if (!attrs
.secure
) {
3581 par64
|= (1 << 9); /* NS */
3584 uint32_t fsr
= arm_fi_to_sfsc(&fi
);
3586 par64
= ((fsr
& (1 << 10)) >> 5) | ((fsr
& (1 << 12)) >> 6) |
3587 ((fsr
& 0xf) << 1) | 1;
3592 #endif /* CONFIG_TCG */
3594 static void ats_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
3597 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3600 int el
= arm_current_el(env
);
3601 bool secure
= arm_is_secure_below_el3(env
);
3603 switch (ri
->opc2
& 6) {
3605 /* stage 1 current state PL1: ATS1CPR, ATS1CPW, ATS1CPRP, ATS1CPWP */
3608 mmu_idx
= ARMMMUIdx_SE3
;
3611 g_assert(!secure
); /* ARMv8.4-SecEL2 is 64-bit only */
3614 if (ri
->crm
== 9 && (env
->uncached_cpsr
& CPSR_PAN
)) {
3615 mmu_idx
= (secure
? ARMMMUIdx_Stage1_SE1_PAN
3616 : ARMMMUIdx_Stage1_E1_PAN
);
3618 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE1
: ARMMMUIdx_Stage1_E1
;
3622 g_assert_not_reached();
3626 /* stage 1 current state PL0: ATS1CUR, ATS1CUW */
3629 mmu_idx
= ARMMMUIdx_SE10_0
;
3632 g_assert(!secure
); /* ARMv8.4-SecEL2 is 64-bit only */
3633 mmu_idx
= ARMMMUIdx_Stage1_E0
;
3636 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE0
: ARMMMUIdx_Stage1_E0
;
3639 g_assert_not_reached();
3643 /* stage 1+2 NonSecure PL1: ATS12NSOPR, ATS12NSOPW */
3644 mmu_idx
= ARMMMUIdx_E10_1
;
3647 /* stage 1+2 NonSecure PL0: ATS12NSOUR, ATS12NSOUW */
3648 mmu_idx
= ARMMMUIdx_E10_0
;
3651 g_assert_not_reached();
3654 par64
= do_ats_write(env
, value
, access_type
, mmu_idx
);
3656 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
3658 /* Handled by hardware accelerator. */
3659 g_assert_not_reached();
3660 #endif /* CONFIG_TCG */
3663 static void ats1h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3667 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3670 par64
= do_ats_write(env
, value
, access_type
, ARMMMUIdx_E2
);
3672 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
3674 /* Handled by hardware accelerator. */
3675 g_assert_not_reached();
3676 #endif /* CONFIG_TCG */
3679 static CPAccessResult
at_s1e2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3682 if (arm_current_el(env
) == 3 &&
3683 !(env
->cp15
.scr_el3
& (SCR_NS
| SCR_EEL2
))) {
3684 return CP_ACCESS_TRAP
;
3686 return CP_ACCESS_OK
;
3689 static void ats_write64(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3693 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3695 int secure
= arm_is_secure_below_el3(env
);
3697 switch (ri
->opc2
& 6) {
3700 case 0: /* AT S1E1R, AT S1E1W, AT S1E1RP, AT S1E1WP */
3701 if (ri
->crm
== 9 && (env
->pstate
& PSTATE_PAN
)) {
3702 mmu_idx
= (secure
? ARMMMUIdx_Stage1_SE1_PAN
3703 : ARMMMUIdx_Stage1_E1_PAN
);
3705 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE1
: ARMMMUIdx_Stage1_E1
;
3708 case 4: /* AT S1E2R, AT S1E2W */
3709 mmu_idx
= secure
? ARMMMUIdx_SE2
: ARMMMUIdx_E2
;
3711 case 6: /* AT S1E3R, AT S1E3W */
3712 mmu_idx
= ARMMMUIdx_SE3
;
3715 g_assert_not_reached();
3718 case 2: /* AT S1E0R, AT S1E0W */
3719 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE0
: ARMMMUIdx_Stage1_E0
;
3721 case 4: /* AT S12E1R, AT S12E1W */
3722 mmu_idx
= secure
? ARMMMUIdx_SE10_1
: ARMMMUIdx_E10_1
;
3724 case 6: /* AT S12E0R, AT S12E0W */
3725 mmu_idx
= secure
? ARMMMUIdx_SE10_0
: ARMMMUIdx_E10_0
;
3728 g_assert_not_reached();
3731 env
->cp15
.par_el
[1] = do_ats_write(env
, value
, access_type
, mmu_idx
);
3733 /* Handled by hardware accelerator. */
3734 g_assert_not_reached();
3735 #endif /* CONFIG_TCG */
3739 static const ARMCPRegInfo vapa_cp_reginfo
[] = {
3740 { .name
= "PAR", .cp
= 15, .crn
= 7, .crm
= 4, .opc1
= 0, .opc2
= 0,
3741 .access
= PL1_RW
, .resetvalue
= 0,
3742 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.par_s
),
3743 offsetoflow32(CPUARMState
, cp15
.par_ns
) },
3744 .writefn
= par_write
},
3745 #ifndef CONFIG_USER_ONLY
3746 /* This underdecoding is safe because the reginfo is NO_RAW. */
3747 { .name
= "ATS", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= CP_ANY
,
3748 .access
= PL1_W
, .accessfn
= ats_access
,
3749 .writefn
= ats_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
3754 /* Return basic MPU access permission bits. */
3755 static uint32_t simple_mpu_ap_bits(uint32_t val
)
3762 for (i
= 0; i
< 16; i
+= 2) {
3763 ret
|= (val
>> i
) & mask
;
3769 /* Pad basic MPU access permission bits to extended format. */
3770 static uint32_t extended_mpu_ap_bits(uint32_t val
)
3777 for (i
= 0; i
< 16; i
+= 2) {
3778 ret
|= (val
& mask
) << i
;
3784 static void pmsav5_data_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3787 env
->cp15
.pmsav5_data_ap
= extended_mpu_ap_bits(value
);
3790 static uint64_t pmsav5_data_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3792 return simple_mpu_ap_bits(env
->cp15
.pmsav5_data_ap
);
3795 static void pmsav5_insn_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3798 env
->cp15
.pmsav5_insn_ap
= extended_mpu_ap_bits(value
);
3801 static uint64_t pmsav5_insn_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3803 return simple_mpu_ap_bits(env
->cp15
.pmsav5_insn_ap
);
3806 static uint64_t pmsav7_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3808 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
3814 u32p
+= env
->pmsav7
.rnr
[M_REG_NS
];
3818 static void pmsav7_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3821 ARMCPU
*cpu
= env_archcpu(env
);
3822 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
3828 u32p
+= env
->pmsav7
.rnr
[M_REG_NS
];
3829 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
3833 static void pmsav7_rgnr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3836 ARMCPU
*cpu
= env_archcpu(env
);
3837 uint32_t nrgs
= cpu
->pmsav7_dregion
;
3839 if (value
>= nrgs
) {
3840 qemu_log_mask(LOG_GUEST_ERROR
,
3841 "PMSAv7 RGNR write >= # supported regions, %" PRIu32
3842 " > %" PRIu32
"\n", (uint32_t)value
, nrgs
);
3846 raw_write(env
, ri
, value
);
3849 static const ARMCPRegInfo pmsav7_cp_reginfo
[] = {
3850 /* Reset for all these registers is handled in arm_cpu_reset(),
3851 * because the PMSAv7 is also used by M-profile CPUs, which do
3852 * not register cpregs but still need the state to be reset.
3854 { .name
= "DRBAR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 0,
3855 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
3856 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drbar
),
3857 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
3858 .resetfn
= arm_cp_reset_ignore
},
3859 { .name
= "DRSR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 2,
3860 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
3861 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drsr
),
3862 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
3863 .resetfn
= arm_cp_reset_ignore
},
3864 { .name
= "DRACR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 4,
3865 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
3866 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.dracr
),
3867 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
3868 .resetfn
= arm_cp_reset_ignore
},
3869 { .name
= "RGNR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 2, .opc2
= 0,
3871 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.rnr
[M_REG_NS
]),
3872 .writefn
= pmsav7_rgnr_write
,
3873 .resetfn
= arm_cp_reset_ignore
},
3877 static const ARMCPRegInfo pmsav5_cp_reginfo
[] = {
3878 { .name
= "DATA_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
3879 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
3880 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
3881 .readfn
= pmsav5_data_ap_read
, .writefn
= pmsav5_data_ap_write
, },
3882 { .name
= "INSN_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
3883 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
3884 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
3885 .readfn
= pmsav5_insn_ap_read
, .writefn
= pmsav5_insn_ap_write
, },
3886 { .name
= "DATA_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 2,
3888 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
3890 { .name
= "INSN_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 3,
3892 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
3894 { .name
= "DCACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 0,
3896 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_data
), .resetvalue
= 0, },
3897 { .name
= "ICACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 1,
3899 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_insn
), .resetvalue
= 0, },
3900 /* Protection region base and size registers */
3901 { .name
= "946_PRBS0", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0,
3902 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3903 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[0]) },
3904 { .name
= "946_PRBS1", .cp
= 15, .crn
= 6, .crm
= 1, .opc1
= 0,
3905 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3906 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[1]) },
3907 { .name
= "946_PRBS2", .cp
= 15, .crn
= 6, .crm
= 2, .opc1
= 0,
3908 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3909 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[2]) },
3910 { .name
= "946_PRBS3", .cp
= 15, .crn
= 6, .crm
= 3, .opc1
= 0,
3911 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3912 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[3]) },
3913 { .name
= "946_PRBS4", .cp
= 15, .crn
= 6, .crm
= 4, .opc1
= 0,
3914 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3915 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[4]) },
3916 { .name
= "946_PRBS5", .cp
= 15, .crn
= 6, .crm
= 5, .opc1
= 0,
3917 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3918 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[5]) },
3919 { .name
= "946_PRBS6", .cp
= 15, .crn
= 6, .crm
= 6, .opc1
= 0,
3920 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3921 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[6]) },
3922 { .name
= "946_PRBS7", .cp
= 15, .crn
= 6, .crm
= 7, .opc1
= 0,
3923 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3924 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[7]) },
3928 static void vmsa_ttbcr_raw_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3931 TCR
*tcr
= raw_ptr(env
, ri
);
3932 int maskshift
= extract32(value
, 0, 3);
3934 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
3935 if (arm_feature(env
, ARM_FEATURE_LPAE
) && (value
& TTBCR_EAE
)) {
3936 /* Pre ARMv8 bits [21:19], [15:14] and [6:3] are UNK/SBZP when
3937 * using Long-desciptor translation table format */
3938 value
&= ~((7 << 19) | (3 << 14) | (0xf << 3));
3939 } else if (arm_feature(env
, ARM_FEATURE_EL3
)) {
3940 /* In an implementation that includes the Security Extensions
3941 * TTBCR has additional fields PD0 [4] and PD1 [5] for
3942 * Short-descriptor translation table format.
3944 value
&= TTBCR_PD1
| TTBCR_PD0
| TTBCR_N
;
3950 /* Update the masks corresponding to the TCR bank being written
3951 * Note that we always calculate mask and base_mask, but
3952 * they are only used for short-descriptor tables (ie if EAE is 0);
3953 * for long-descriptor tables the TCR fields are used differently
3954 * and the mask and base_mask values are meaningless.
3956 tcr
->raw_tcr
= value
;
3957 tcr
->mask
= ~(((uint32_t)0xffffffffu
) >> maskshift
);
3958 tcr
->base_mask
= ~((uint32_t)0x3fffu
>> maskshift
);
3961 static void vmsa_ttbcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3964 ARMCPU
*cpu
= env_archcpu(env
);
3965 TCR
*tcr
= raw_ptr(env
, ri
);
3967 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3968 /* With LPAE the TTBCR could result in a change of ASID
3969 * via the TTBCR.A1 bit, so do a TLB flush.
3971 tlb_flush(CPU(cpu
));
3973 /* Preserve the high half of TCR_EL1, set via TTBCR2. */
3974 value
= deposit64(tcr
->raw_tcr
, 0, 32, value
);
3975 vmsa_ttbcr_raw_write(env
, ri
, value
);
3978 static void vmsa_ttbcr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3980 TCR
*tcr
= raw_ptr(env
, ri
);
3982 /* Reset both the TCR as well as the masks corresponding to the bank of
3983 * the TCR being reset.
3987 tcr
->base_mask
= 0xffffc000u
;
3990 static void vmsa_tcr_el12_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3993 ARMCPU
*cpu
= env_archcpu(env
);
3994 TCR
*tcr
= raw_ptr(env
, ri
);
3996 /* For AArch64 the A1 bit could result in a change of ASID, so TLB flush. */
3997 tlb_flush(CPU(cpu
));
3998 tcr
->raw_tcr
= value
;
4001 static void vmsa_ttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4004 /* If the ASID changes (with a 64-bit write), we must flush the TLB. */
4005 if (cpreg_field_is_64bit(ri
) &&
4006 extract64(raw_read(env
, ri
) ^ value
, 48, 16) != 0) {
4007 ARMCPU
*cpu
= env_archcpu(env
);
4008 tlb_flush(CPU(cpu
));
4010 raw_write(env
, ri
, value
);
4013 static void vmsa_tcr_ttbr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4017 * If we are running with E2&0 regime, then an ASID is active.
4018 * Flush if that might be changing. Note we're not checking
4019 * TCR_EL2.A1 to know if this is really the TTBRx_EL2 that
4020 * holds the active ASID, only checking the field that might.
4022 if (extract64(raw_read(env
, ri
) ^ value
, 48, 16) &&
4023 (arm_hcr_el2_eff(env
) & HCR_E2H
)) {
4024 uint16_t mask
= ARMMMUIdxBit_E20_2
|
4025 ARMMMUIdxBit_E20_2_PAN
|
4028 if (arm_is_secure_below_el3(env
)) {
4029 mask
>>= ARM_MMU_IDX_A_NS
;
4032 tlb_flush_by_mmuidx(env_cpu(env
), mask
);
4034 raw_write(env
, ri
, value
);
4037 static void vttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4040 ARMCPU
*cpu
= env_archcpu(env
);
4041 CPUState
*cs
= CPU(cpu
);
4044 * A change in VMID to the stage2 page table (Stage2) invalidates
4045 * the combined stage 1&2 tlbs (EL10_1 and EL10_0).
4047 if (raw_read(env
, ri
) != value
) {
4048 uint16_t mask
= ARMMMUIdxBit_E10_1
|
4049 ARMMMUIdxBit_E10_1_PAN
|
4052 if (arm_is_secure_below_el3(env
)) {
4053 mask
>>= ARM_MMU_IDX_A_NS
;
4056 tlb_flush_by_mmuidx(cs
, mask
);
4057 raw_write(env
, ri
, value
);
4061 static const ARMCPRegInfo vmsa_pmsa_cp_reginfo
[] = {
4062 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
4063 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .type
= ARM_CP_ALIAS
,
4064 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dfsr_s
),
4065 offsetoflow32(CPUARMState
, cp15
.dfsr_ns
) }, },
4066 { .name
= "IFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
4067 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
4068 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.ifsr_s
),
4069 offsetoflow32(CPUARMState
, cp15
.ifsr_ns
) } },
4070 { .name
= "DFAR", .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 0, .opc2
= 0,
4071 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
4072 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.dfar_s
),
4073 offsetof(CPUARMState
, cp15
.dfar_ns
) } },
4074 { .name
= "FAR_EL1", .state
= ARM_CP_STATE_AA64
,
4075 .opc0
= 3, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 0,
4076 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4077 .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[1]),
4082 static const ARMCPRegInfo vmsa_cp_reginfo
[] = {
4083 { .name
= "ESR_EL1", .state
= ARM_CP_STATE_AA64
,
4084 .opc0
= 3, .crn
= 5, .crm
= 2, .opc1
= 0, .opc2
= 0,
4085 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4086 .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[1]), .resetvalue
= 0, },
4087 { .name
= "TTBR0_EL1", .state
= ARM_CP_STATE_BOTH
,
4088 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 0,
4089 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4090 .writefn
= vmsa_ttbr_write
, .resetvalue
= 0,
4091 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
4092 offsetof(CPUARMState
, cp15
.ttbr0_ns
) } },
4093 { .name
= "TTBR1_EL1", .state
= ARM_CP_STATE_BOTH
,
4094 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 1,
4095 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4096 .writefn
= vmsa_ttbr_write
, .resetvalue
= 0,
4097 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
4098 offsetof(CPUARMState
, cp15
.ttbr1_ns
) } },
4099 { .name
= "TCR_EL1", .state
= ARM_CP_STATE_AA64
,
4100 .opc0
= 3, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
4101 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4102 .writefn
= vmsa_tcr_el12_write
,
4103 .resetfn
= vmsa_ttbcr_reset
, .raw_writefn
= raw_write
,
4104 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[1]) },
4105 { .name
= "TTBCR", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
4106 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4107 .type
= ARM_CP_ALIAS
, .writefn
= vmsa_ttbcr_write
,
4108 .raw_writefn
= vmsa_ttbcr_raw_write
,
4109 /* No offsetoflow32 -- pass the entire TCR to writefn/raw_writefn. */
4110 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.tcr_el
[3]),
4111 offsetof(CPUARMState
, cp15
.tcr_el
[1])} },
4115 /* Note that unlike TTBCR, writing to TTBCR2 does not require flushing
4116 * qemu tlbs nor adjusting cached masks.
4118 static const ARMCPRegInfo ttbcr2_reginfo
= {
4119 .name
= "TTBCR2", .cp
= 15, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 3,
4120 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4121 .type
= ARM_CP_ALIAS
,
4122 .bank_fieldoffsets
= {
4123 offsetofhigh32(CPUARMState
, cp15
.tcr_el
[3].raw_tcr
),
4124 offsetofhigh32(CPUARMState
, cp15
.tcr_el
[1].raw_tcr
),
4128 static void omap_ticonfig_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4131 env
->cp15
.c15_ticonfig
= value
& 0xe7;
4132 /* The OS_TYPE bit in this register changes the reported CPUID! */
4133 env
->cp15
.c0_cpuid
= (value
& (1 << 5)) ?
4134 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
4137 static void omap_threadid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4140 env
->cp15
.c15_threadid
= value
& 0xffff;
4143 static void omap_wfi_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4146 /* Wait-for-interrupt (deprecated) */
4147 cpu_interrupt(env_cpu(env
), CPU_INTERRUPT_HALT
);
4150 static void omap_cachemaint_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4153 /* On OMAP there are registers indicating the max/min index of dcache lines
4154 * containing a dirty line; cache flush operations have to reset these.
4156 env
->cp15
.c15_i_max
= 0x000;
4157 env
->cp15
.c15_i_min
= 0xff0;
4160 static const ARMCPRegInfo omap_cp_reginfo
[] = {
4161 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= CP_ANY
,
4162 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_OVERRIDE
,
4163 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.esr_el
[1]),
4165 { .name
= "", .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 0, .opc2
= 0,
4166 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
4167 { .name
= "TICONFIG", .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0,
4169 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ticonfig
), .resetvalue
= 0,
4170 .writefn
= omap_ticonfig_write
},
4171 { .name
= "IMAX", .cp
= 15, .crn
= 15, .crm
= 2, .opc1
= 0, .opc2
= 0,
4173 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_max
), .resetvalue
= 0, },
4174 { .name
= "IMIN", .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 0, .opc2
= 0,
4175 .access
= PL1_RW
, .resetvalue
= 0xff0,
4176 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_min
) },
4177 { .name
= "THREADID", .cp
= 15, .crn
= 15, .crm
= 4, .opc1
= 0, .opc2
= 0,
4179 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_threadid
), .resetvalue
= 0,
4180 .writefn
= omap_threadid_write
},
4181 { .name
= "TI925T_STATUS", .cp
= 15, .crn
= 15,
4182 .crm
= 8, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
4183 .type
= ARM_CP_NO_RAW
,
4184 .readfn
= arm_cp_read_zero
, .writefn
= omap_wfi_write
, },
4185 /* TODO: Peripheral port remap register:
4186 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt controller
4187 * base address at $rn & ~0xfff and map size of 0x200 << ($rn & 0xfff),
4190 { .name
= "OMAP_CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
4191 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
4192 .type
= ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
,
4193 .writefn
= omap_cachemaint_write
},
4194 { .name
= "C9", .cp
= 15, .crn
= 9,
4195 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
,
4196 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
, .resetvalue
= 0 },
4200 static void xscale_cpar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4203 env
->cp15
.c15_cpar
= value
& 0x3fff;
4206 static const ARMCPRegInfo xscale_cp_reginfo
[] = {
4207 { .name
= "XSCALE_CPAR",
4208 .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
4209 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_cpar
), .resetvalue
= 0,
4210 .writefn
= xscale_cpar_write
, },
4211 { .name
= "XSCALE_AUXCR",
4212 .cp
= 15, .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 1, .access
= PL1_RW
,
4213 .fieldoffset
= offsetof(CPUARMState
, cp15
.c1_xscaleauxcr
),
4215 /* XScale specific cache-lockdown: since we have no cache we NOP these
4216 * and hope the guest does not really rely on cache behaviour.
4218 { .name
= "XSCALE_LOCK_ICACHE_LINE",
4219 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 0,
4220 .access
= PL1_W
, .type
= ARM_CP_NOP
},
4221 { .name
= "XSCALE_UNLOCK_ICACHE",
4222 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 1,
4223 .access
= PL1_W
, .type
= ARM_CP_NOP
},
4224 { .name
= "XSCALE_DCACHE_LOCK",
4225 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 0,
4226 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
4227 { .name
= "XSCALE_UNLOCK_DCACHE",
4228 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 1,
4229 .access
= PL1_W
, .type
= ARM_CP_NOP
},
4233 static const ARMCPRegInfo dummy_c15_cp_reginfo
[] = {
4234 /* RAZ/WI the whole crn=15 space, when we don't have a more specific
4235 * implementation of this implementation-defined space.
4236 * Ideally this should eventually disappear in favour of actually
4237 * implementing the correct behaviour for all cores.
4239 { .name
= "C15_IMPDEF", .cp
= 15, .crn
= 15,
4240 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
4242 .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
| ARM_CP_OVERRIDE
,
4247 static const ARMCPRegInfo cache_dirty_status_cp_reginfo
[] = {
4248 /* Cache status: RAZ because we have no cache so it's always clean */
4249 { .name
= "CDSR", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 6,
4250 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4255 static const ARMCPRegInfo cache_block_ops_cp_reginfo
[] = {
4256 /* We never have a a block transfer operation in progress */
4257 { .name
= "BXSR", .cp
= 15, .crn
= 7, .crm
= 12, .opc1
= 0, .opc2
= 4,
4258 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4260 /* The cache ops themselves: these all NOP for QEMU */
4261 { .name
= "IICR", .cp
= 15, .crm
= 5, .opc1
= 0,
4262 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4263 { .name
= "IDCR", .cp
= 15, .crm
= 6, .opc1
= 0,
4264 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4265 { .name
= "CDCR", .cp
= 15, .crm
= 12, .opc1
= 0,
4266 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4267 { .name
= "PIR", .cp
= 15, .crm
= 12, .opc1
= 1,
4268 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4269 { .name
= "PDR", .cp
= 15, .crm
= 12, .opc1
= 2,
4270 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4271 { .name
= "CIDCR", .cp
= 15, .crm
= 14, .opc1
= 0,
4272 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4276 static const ARMCPRegInfo cache_test_clean_cp_reginfo
[] = {
4277 /* The cache test-and-clean instructions always return (1 << 30)
4278 * to indicate that there are no dirty cache lines.
4280 { .name
= "TC_DCACHE", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 3,
4281 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4282 .resetvalue
= (1 << 30) },
4283 { .name
= "TCI_DCACHE", .cp
= 15, .crn
= 7, .crm
= 14, .opc1
= 0, .opc2
= 3,
4284 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4285 .resetvalue
= (1 << 30) },
4289 static const ARMCPRegInfo strongarm_cp_reginfo
[] = {
4290 /* Ignore ReadBuffer accesses */
4291 { .name
= "C9_READBUFFER", .cp
= 15, .crn
= 9,
4292 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
4293 .access
= PL1_RW
, .resetvalue
= 0,
4294 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
},
4298 static uint64_t midr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4300 unsigned int cur_el
= arm_current_el(env
);
4302 if (arm_is_el2_enabled(env
) && cur_el
== 1) {
4303 return env
->cp15
.vpidr_el2
;
4305 return raw_read(env
, ri
);
4308 static uint64_t mpidr_read_val(CPUARMState
*env
)
4310 ARMCPU
*cpu
= env_archcpu(env
);
4311 uint64_t mpidr
= cpu
->mp_affinity
;
4313 if (arm_feature(env
, ARM_FEATURE_V7MP
)) {
4314 mpidr
|= (1U << 31);
4315 /* Cores which are uniprocessor (non-coherent)
4316 * but still implement the MP extensions set
4317 * bit 30. (For instance, Cortex-R5).
4319 if (cpu
->mp_is_up
) {
4320 mpidr
|= (1u << 30);
4326 static uint64_t mpidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4328 unsigned int cur_el
= arm_current_el(env
);
4330 if (arm_is_el2_enabled(env
) && cur_el
== 1) {
4331 return env
->cp15
.vmpidr_el2
;
4333 return mpidr_read_val(env
);
4336 static const ARMCPRegInfo lpae_cp_reginfo
[] = {
4338 { .name
= "AMAIR0", .state
= ARM_CP_STATE_BOTH
,
4339 .opc0
= 3, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 0,
4340 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4341 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4342 /* AMAIR1 is mapped to AMAIR_EL1[63:32] */
4343 { .name
= "AMAIR1", .cp
= 15, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 1,
4344 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4345 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4346 { .name
= "PAR", .cp
= 15, .crm
= 7, .opc1
= 0,
4347 .access
= PL1_RW
, .type
= ARM_CP_64BIT
, .resetvalue
= 0,
4348 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.par_s
),
4349 offsetof(CPUARMState
, cp15
.par_ns
)} },
4350 { .name
= "TTBR0", .cp
= 15, .crm
= 2, .opc1
= 0,
4351 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4352 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
4353 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
4354 offsetof(CPUARMState
, cp15
.ttbr0_ns
) },
4355 .writefn
= vmsa_ttbr_write
, },
4356 { .name
= "TTBR1", .cp
= 15, .crm
= 2, .opc1
= 1,
4357 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4358 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
4359 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
4360 offsetof(CPUARMState
, cp15
.ttbr1_ns
) },
4361 .writefn
= vmsa_ttbr_write
, },
4365 static uint64_t aa64_fpcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4367 return vfp_get_fpcr(env
);
4370 static void aa64_fpcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4373 vfp_set_fpcr(env
, value
);
4376 static uint64_t aa64_fpsr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4378 return vfp_get_fpsr(env
);
4381 static void aa64_fpsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4384 vfp_set_fpsr(env
, value
);
4387 static CPAccessResult
aa64_daif_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4390 if (arm_current_el(env
) == 0 && !(arm_sctlr(env
, 0) & SCTLR_UMA
)) {
4391 return CP_ACCESS_TRAP
;
4393 return CP_ACCESS_OK
;
4396 static void aa64_daif_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4399 env
->daif
= value
& PSTATE_DAIF
;
4402 static uint64_t aa64_pan_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4404 return env
->pstate
& PSTATE_PAN
;
4407 static void aa64_pan_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4410 env
->pstate
= (env
->pstate
& ~PSTATE_PAN
) | (value
& PSTATE_PAN
);
4413 static const ARMCPRegInfo pan_reginfo
= {
4414 .name
= "PAN", .state
= ARM_CP_STATE_AA64
,
4415 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 3,
4416 .type
= ARM_CP_NO_RAW
, .access
= PL1_RW
,
4417 .readfn
= aa64_pan_read
, .writefn
= aa64_pan_write
4420 static uint64_t aa64_uao_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4422 return env
->pstate
& PSTATE_UAO
;
4425 static void aa64_uao_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4428 env
->pstate
= (env
->pstate
& ~PSTATE_UAO
) | (value
& PSTATE_UAO
);
4431 static const ARMCPRegInfo uao_reginfo
= {
4432 .name
= "UAO", .state
= ARM_CP_STATE_AA64
,
4433 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 4,
4434 .type
= ARM_CP_NO_RAW
, .access
= PL1_RW
,
4435 .readfn
= aa64_uao_read
, .writefn
= aa64_uao_write
4438 static uint64_t aa64_dit_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4440 return env
->pstate
& PSTATE_DIT
;
4443 static void aa64_dit_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4446 env
->pstate
= (env
->pstate
& ~PSTATE_DIT
) | (value
& PSTATE_DIT
);
4449 static const ARMCPRegInfo dit_reginfo
= {
4450 .name
= "DIT", .state
= ARM_CP_STATE_AA64
,
4451 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 5,
4452 .type
= ARM_CP_NO_RAW
, .access
= PL0_RW
,
4453 .readfn
= aa64_dit_read
, .writefn
= aa64_dit_write
4456 static uint64_t aa64_ssbs_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4458 return env
->pstate
& PSTATE_SSBS
;
4461 static void aa64_ssbs_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4464 env
->pstate
= (env
->pstate
& ~PSTATE_SSBS
) | (value
& PSTATE_SSBS
);
4467 static const ARMCPRegInfo ssbs_reginfo
= {
4468 .name
= "SSBS", .state
= ARM_CP_STATE_AA64
,
4469 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 6,
4470 .type
= ARM_CP_NO_RAW
, .access
= PL0_RW
,
4471 .readfn
= aa64_ssbs_read
, .writefn
= aa64_ssbs_write
4474 static CPAccessResult
aa64_cacheop_poc_access(CPUARMState
*env
,
4475 const ARMCPRegInfo
*ri
,
4478 /* Cache invalidate/clean to Point of Coherency or Persistence... */
4479 switch (arm_current_el(env
)) {
4481 /* ... EL0 must UNDEF unless SCTLR_EL1.UCI is set. */
4482 if (!(arm_sctlr(env
, 0) & SCTLR_UCI
)) {
4483 return CP_ACCESS_TRAP
;
4487 /* ... EL1 must trap to EL2 if HCR_EL2.TPCP is set. */
4488 if (arm_hcr_el2_eff(env
) & HCR_TPCP
) {
4489 return CP_ACCESS_TRAP_EL2
;
4493 return CP_ACCESS_OK
;
4496 static CPAccessResult
aa64_cacheop_pou_access(CPUARMState
*env
,
4497 const ARMCPRegInfo
*ri
,
4500 /* Cache invalidate/clean to Point of Unification... */
4501 switch (arm_current_el(env
)) {
4503 /* ... EL0 must UNDEF unless SCTLR_EL1.UCI is set. */
4504 if (!(arm_sctlr(env
, 0) & SCTLR_UCI
)) {
4505 return CP_ACCESS_TRAP
;
4509 /* ... EL1 must trap to EL2 if HCR_EL2.TPU is set. */
4510 if (arm_hcr_el2_eff(env
) & HCR_TPU
) {
4511 return CP_ACCESS_TRAP_EL2
;
4515 return CP_ACCESS_OK
;
4518 /* See: D4.7.2 TLB maintenance requirements and the TLB maintenance instructions
4519 * Page D4-1736 (DDI0487A.b)
4522 static int vae1_tlbmask(CPUARMState
*env
)
4524 uint64_t hcr
= arm_hcr_el2_eff(env
);
4527 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4528 mask
= ARMMMUIdxBit_E20_2
|
4529 ARMMMUIdxBit_E20_2_PAN
|
4532 mask
= ARMMMUIdxBit_E10_1
|
4533 ARMMMUIdxBit_E10_1_PAN
|
4537 if (arm_is_secure_below_el3(env
)) {
4538 mask
>>= ARM_MMU_IDX_A_NS
;
4544 /* Return 56 if TBI is enabled, 64 otherwise. */
4545 static int tlbbits_for_regime(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
4548 uint64_t tcr
= regime_tcr(env
, mmu_idx
)->raw_tcr
;
4549 int tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
4550 int select
= extract64(addr
, 55, 1);
4552 return (tbi
>> select
) & 1 ? 56 : 64;
4555 static int vae1_tlbbits(CPUARMState
*env
, uint64_t addr
)
4557 uint64_t hcr
= arm_hcr_el2_eff(env
);
4560 /* Only the regime of the mmu_idx below is significant. */
4561 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4562 mmu_idx
= ARMMMUIdx_E20_0
;
4564 mmu_idx
= ARMMMUIdx_E10_0
;
4567 if (arm_is_secure_below_el3(env
)) {
4568 mmu_idx
&= ~ARM_MMU_IDX_A_NS
;
4571 return tlbbits_for_regime(env
, mmu_idx
, addr
);
4574 static void tlbi_aa64_vmalle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4577 CPUState
*cs
= env_cpu(env
);
4578 int mask
= vae1_tlbmask(env
);
4580 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4583 static void tlbi_aa64_vmalle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4586 CPUState
*cs
= env_cpu(env
);
4587 int mask
= vae1_tlbmask(env
);
4589 if (tlb_force_broadcast(env
)) {
4590 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4592 tlb_flush_by_mmuidx(cs
, mask
);
4596 static int alle1_tlbmask(CPUARMState
*env
)
4599 * Note that the 'ALL' scope must invalidate both stage 1 and
4600 * stage 2 translations, whereas most other scopes only invalidate
4601 * stage 1 translations.
4603 if (arm_is_secure_below_el3(env
)) {
4604 return ARMMMUIdxBit_SE10_1
|
4605 ARMMMUIdxBit_SE10_1_PAN
|
4606 ARMMMUIdxBit_SE10_0
;
4608 return ARMMMUIdxBit_E10_1
|
4609 ARMMMUIdxBit_E10_1_PAN
|
4614 static int e2_tlbmask(CPUARMState
*env
)
4616 if (arm_is_secure_below_el3(env
)) {
4617 return ARMMMUIdxBit_SE20_0
|
4618 ARMMMUIdxBit_SE20_2
|
4619 ARMMMUIdxBit_SE20_2_PAN
|
4622 return ARMMMUIdxBit_E20_0
|
4623 ARMMMUIdxBit_E20_2
|
4624 ARMMMUIdxBit_E20_2_PAN
|
4629 static void tlbi_aa64_alle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4632 CPUState
*cs
= env_cpu(env
);
4633 int mask
= alle1_tlbmask(env
);
4635 tlb_flush_by_mmuidx(cs
, mask
);
4638 static void tlbi_aa64_alle2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4641 CPUState
*cs
= env_cpu(env
);
4642 int mask
= e2_tlbmask(env
);
4644 tlb_flush_by_mmuidx(cs
, mask
);
4647 static void tlbi_aa64_alle3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4650 ARMCPU
*cpu
= env_archcpu(env
);
4651 CPUState
*cs
= CPU(cpu
);
4653 tlb_flush_by_mmuidx(cs
, ARMMMUIdxBit_SE3
);
4656 static void tlbi_aa64_alle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4659 CPUState
*cs
= env_cpu(env
);
4660 int mask
= alle1_tlbmask(env
);
4662 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4665 static void tlbi_aa64_alle2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4668 CPUState
*cs
= env_cpu(env
);
4669 int mask
= e2_tlbmask(env
);
4671 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4674 static void tlbi_aa64_alle3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4677 CPUState
*cs
= env_cpu(env
);
4679 tlb_flush_by_mmuidx_all_cpus_synced(cs
, ARMMMUIdxBit_SE3
);
4682 static void tlbi_aa64_vae2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4685 /* Invalidate by VA, EL2
4686 * Currently handles both VAE2 and VALE2, since we don't support
4687 * flush-last-level-only.
4689 CPUState
*cs
= env_cpu(env
);
4690 int mask
= e2_tlbmask(env
);
4691 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4693 tlb_flush_page_by_mmuidx(cs
, pageaddr
, mask
);
4696 static void tlbi_aa64_vae3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4699 /* Invalidate by VA, EL3
4700 * Currently handles both VAE3 and VALE3, since we don't support
4701 * flush-last-level-only.
4703 ARMCPU
*cpu
= env_archcpu(env
);
4704 CPUState
*cs
= CPU(cpu
);
4705 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4707 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_SE3
);
4710 static void tlbi_aa64_vae1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4713 CPUState
*cs
= env_cpu(env
);
4714 int mask
= vae1_tlbmask(env
);
4715 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4716 int bits
= vae1_tlbbits(env
, pageaddr
);
4718 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4721 static void tlbi_aa64_vae1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4724 /* Invalidate by VA, EL1&0 (AArch64 version).
4725 * Currently handles all of VAE1, VAAE1, VAALE1 and VALE1,
4726 * since we don't support flush-for-specific-ASID-only or
4727 * flush-last-level-only.
4729 CPUState
*cs
= env_cpu(env
);
4730 int mask
= vae1_tlbmask(env
);
4731 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4732 int bits
= vae1_tlbbits(env
, pageaddr
);
4734 if (tlb_force_broadcast(env
)) {
4735 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4737 tlb_flush_page_bits_by_mmuidx(cs
, pageaddr
, mask
, bits
);
4741 static void tlbi_aa64_vae2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4744 CPUState
*cs
= env_cpu(env
);
4745 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4746 bool secure
= arm_is_secure_below_el3(env
);
4747 int mask
= secure
? ARMMMUIdxBit_SE2
: ARMMMUIdxBit_E2
;
4748 int bits
= tlbbits_for_regime(env
, secure
? ARMMMUIdx_SE2
: ARMMMUIdx_E2
,
4751 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4754 static void tlbi_aa64_vae3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4757 CPUState
*cs
= env_cpu(env
);
4758 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4759 int bits
= tlbbits_for_regime(env
, ARMMMUIdx_SE3
, pageaddr
);
4761 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
,
4762 ARMMMUIdxBit_SE3
, bits
);
4765 #ifdef TARGET_AARCH64
4766 static uint64_t tlbi_aa64_range_get_length(CPUARMState
*env
,
4769 unsigned int page_shift
;
4770 unsigned int page_size_granule
;
4776 num
= extract64(value
, 39, 4);
4777 scale
= extract64(value
, 44, 2);
4778 page_size_granule
= extract64(value
, 46, 2);
4780 page_shift
= page_size_granule
* 2 + 12;
4782 if (page_size_granule
== 0) {
4783 qemu_log_mask(LOG_GUEST_ERROR
, "Invalid page size granule %d\n",
4788 exponent
= (5 * scale
) + 1;
4789 length
= (num
+ 1) << (exponent
+ page_shift
);
4794 static uint64_t tlbi_aa64_range_get_base(CPUARMState
*env
, uint64_t value
,
4797 /* TODO: ARMv8.7 FEAT_LPA2 */
4801 pageaddr
= sextract64(value
, 0, 37) << TARGET_PAGE_BITS
;
4803 pageaddr
= extract64(value
, 0, 37) << TARGET_PAGE_BITS
;
4809 static void do_rvae_write(CPUARMState
*env
, uint64_t value
,
4810 int idxmap
, bool synced
)
4812 ARMMMUIdx one_idx
= ARM_MMU_IDX_A
| ctz32(idxmap
);
4813 bool two_ranges
= regime_has_2_ranges(one_idx
);
4814 uint64_t baseaddr
, length
;
4817 baseaddr
= tlbi_aa64_range_get_base(env
, value
, two_ranges
);
4818 length
= tlbi_aa64_range_get_length(env
, value
);
4819 bits
= tlbbits_for_regime(env
, one_idx
, baseaddr
);
4822 tlb_flush_range_by_mmuidx_all_cpus_synced(env_cpu(env
),
4828 tlb_flush_range_by_mmuidx(env_cpu(env
), baseaddr
,
4829 length
, idxmap
, bits
);
4833 static void tlbi_aa64_rvae1_write(CPUARMState
*env
,
4834 const ARMCPRegInfo
*ri
,
4838 * Invalidate by VA range, EL1&0.
4839 * Currently handles all of RVAE1, RVAAE1, RVAALE1 and RVALE1,
4840 * since we don't support flush-for-specific-ASID-only or
4841 * flush-last-level-only.
4844 do_rvae_write(env
, value
, vae1_tlbmask(env
),
4845 tlb_force_broadcast(env
));
4848 static void tlbi_aa64_rvae1is_write(CPUARMState
*env
,
4849 const ARMCPRegInfo
*ri
,
4853 * Invalidate by VA range, Inner/Outer Shareable EL1&0.
4854 * Currently handles all of RVAE1IS, RVAE1OS, RVAAE1IS, RVAAE1OS,
4855 * RVAALE1IS, RVAALE1OS, RVALE1IS and RVALE1OS, since we don't support
4856 * flush-for-specific-ASID-only, flush-last-level-only or inner/outer
4857 * shareable specific flushes.
4860 do_rvae_write(env
, value
, vae1_tlbmask(env
), true);
4863 static int vae2_tlbmask(CPUARMState
*env
)
4865 return (arm_is_secure_below_el3(env
)
4866 ? ARMMMUIdxBit_SE2
: ARMMMUIdxBit_E2
);
4869 static void tlbi_aa64_rvae2_write(CPUARMState
*env
,
4870 const ARMCPRegInfo
*ri
,
4874 * Invalidate by VA range, EL2.
4875 * Currently handles all of RVAE2 and RVALE2,
4876 * since we don't support flush-for-specific-ASID-only or
4877 * flush-last-level-only.
4880 do_rvae_write(env
, value
, vae2_tlbmask(env
),
4881 tlb_force_broadcast(env
));
4886 static void tlbi_aa64_rvae2is_write(CPUARMState
*env
,
4887 const ARMCPRegInfo
*ri
,
4891 * Invalidate by VA range, Inner/Outer Shareable, EL2.
4892 * Currently handles all of RVAE2IS, RVAE2OS, RVALE2IS and RVALE2OS,
4893 * since we don't support flush-for-specific-ASID-only,
4894 * flush-last-level-only or inner/outer shareable specific flushes.
4897 do_rvae_write(env
, value
, vae2_tlbmask(env
), true);
4901 static void tlbi_aa64_rvae3_write(CPUARMState
*env
,
4902 const ARMCPRegInfo
*ri
,
4906 * Invalidate by VA range, EL3.
4907 * Currently handles all of RVAE3 and RVALE3,
4908 * since we don't support flush-for-specific-ASID-only or
4909 * flush-last-level-only.
4912 do_rvae_write(env
, value
, ARMMMUIdxBit_SE3
,
4913 tlb_force_broadcast(env
));
4916 static void tlbi_aa64_rvae3is_write(CPUARMState
*env
,
4917 const ARMCPRegInfo
*ri
,
4921 * Invalidate by VA range, EL3, Inner/Outer Shareable.
4922 * Currently handles all of RVAE3IS, RVAE3OS, RVALE3IS and RVALE3OS,
4923 * since we don't support flush-for-specific-ASID-only,
4924 * flush-last-level-only or inner/outer specific flushes.
4927 do_rvae_write(env
, value
, ARMMMUIdxBit_SE3
, true);
4931 static CPAccessResult
aa64_zva_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4934 int cur_el
= arm_current_el(env
);
4937 uint64_t hcr
= arm_hcr_el2_eff(env
);
4940 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4941 if (!(env
->cp15
.sctlr_el
[2] & SCTLR_DZE
)) {
4942 return CP_ACCESS_TRAP_EL2
;
4945 if (!(env
->cp15
.sctlr_el
[1] & SCTLR_DZE
)) {
4946 return CP_ACCESS_TRAP
;
4948 if (hcr
& HCR_TDZ
) {
4949 return CP_ACCESS_TRAP_EL2
;
4952 } else if (hcr
& HCR_TDZ
) {
4953 return CP_ACCESS_TRAP_EL2
;
4956 return CP_ACCESS_OK
;
4959 static uint64_t aa64_dczid_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4961 ARMCPU
*cpu
= env_archcpu(env
);
4962 int dzp_bit
= 1 << 4;
4964 /* DZP indicates whether DC ZVA access is allowed */
4965 if (aa64_zva_access(env
, NULL
, false) == CP_ACCESS_OK
) {
4968 return cpu
->dcz_blocksize
| dzp_bit
;
4971 static CPAccessResult
sp_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4974 if (!(env
->pstate
& PSTATE_SP
)) {
4975 /* Access to SP_EL0 is undefined if it's being used as
4976 * the stack pointer.
4978 return CP_ACCESS_TRAP_UNCATEGORIZED
;
4980 return CP_ACCESS_OK
;
4983 static uint64_t spsel_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4985 return env
->pstate
& PSTATE_SP
;
4988 static void spsel_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
4990 update_spsel(env
, val
);
4993 static void sctlr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4996 ARMCPU
*cpu
= env_archcpu(env
);
4998 if (arm_feature(env
, ARM_FEATURE_PMSA
) && !cpu
->has_mpu
) {
4999 /* M bit is RAZ/WI for PMSA with no MPU implemented */
5003 /* ??? Lots of these bits are not implemented. */
5005 if (ri
->state
== ARM_CP_STATE_AA64
&& !cpu_isar_feature(aa64_mte
, cpu
)) {
5006 if (ri
->opc1
== 6) { /* SCTLR_EL3 */
5007 value
&= ~(SCTLR_ITFSB
| SCTLR_TCF
| SCTLR_ATA
);
5009 value
&= ~(SCTLR_ITFSB
| SCTLR_TCF0
| SCTLR_TCF
|
5010 SCTLR_ATA0
| SCTLR_ATA
);
5014 if (raw_read(env
, ri
) == value
) {
5015 /* Skip the TLB flush if nothing actually changed; Linux likes
5016 * to do a lot of pointless SCTLR writes.
5021 raw_write(env
, ri
, value
);
5023 /* This may enable/disable the MMU, so do a TLB flush. */
5024 tlb_flush(CPU(cpu
));
5026 if (ri
->type
& ARM_CP_SUPPRESS_TB_END
) {
5028 * Normally we would always end the TB on an SCTLR write; see the
5029 * comment in ARMCPRegInfo sctlr initialization below for why Xscale
5030 * is special. Setting ARM_CP_SUPPRESS_TB_END also stops the rebuild
5031 * of hflags from the translator, so do it here.
5033 arm_rebuild_hflags(env
);
5037 static CPAccessResult
fpexc32_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5040 if ((env
->cp15
.cptr_el
[2] & CPTR_TFP
) && arm_current_el(env
) == 2) {
5041 return CP_ACCESS_TRAP_FP_EL2
;
5043 if (env
->cp15
.cptr_el
[3] & CPTR_TFP
) {
5044 return CP_ACCESS_TRAP_FP_EL3
;
5046 return CP_ACCESS_OK
;
5049 static void sdcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5052 env
->cp15
.mdcr_el3
= value
& SDCR_VALID_MASK
;
5055 static const ARMCPRegInfo v8_cp_reginfo
[] = {
5056 /* Minimal set of EL0-visible registers. This will need to be expanded
5057 * significantly for system emulation of AArch64 CPUs.
5059 { .name
= "NZCV", .state
= ARM_CP_STATE_AA64
,
5060 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 2,
5061 .access
= PL0_RW
, .type
= ARM_CP_NZCV
},
5062 { .name
= "DAIF", .state
= ARM_CP_STATE_AA64
,
5063 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 2,
5064 .type
= ARM_CP_NO_RAW
,
5065 .access
= PL0_RW
, .accessfn
= aa64_daif_access
,
5066 .fieldoffset
= offsetof(CPUARMState
, daif
),
5067 .writefn
= aa64_daif_write
, .resetfn
= arm_cp_reset_ignore
},
5068 { .name
= "FPCR", .state
= ARM_CP_STATE_AA64
,
5069 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 4,
5070 .access
= PL0_RW
, .type
= ARM_CP_FPU
| ARM_CP_SUPPRESS_TB_END
,
5071 .readfn
= aa64_fpcr_read
, .writefn
= aa64_fpcr_write
},
5072 { .name
= "FPSR", .state
= ARM_CP_STATE_AA64
,
5073 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 4,
5074 .access
= PL0_RW
, .type
= ARM_CP_FPU
| ARM_CP_SUPPRESS_TB_END
,
5075 .readfn
= aa64_fpsr_read
, .writefn
= aa64_fpsr_write
},
5076 { .name
= "DCZID_EL0", .state
= ARM_CP_STATE_AA64
,
5077 .opc0
= 3, .opc1
= 3, .opc2
= 7, .crn
= 0, .crm
= 0,
5078 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
,
5079 .readfn
= aa64_dczid_read
},
5080 { .name
= "DC_ZVA", .state
= ARM_CP_STATE_AA64
,
5081 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 1,
5082 .access
= PL0_W
, .type
= ARM_CP_DC_ZVA
,
5083 #ifndef CONFIG_USER_ONLY
5084 /* Avoid overhead of an access check that always passes in user-mode */
5085 .accessfn
= aa64_zva_access
,
5088 { .name
= "CURRENTEL", .state
= ARM_CP_STATE_AA64
,
5089 .opc0
= 3, .opc1
= 0, .opc2
= 2, .crn
= 4, .crm
= 2,
5090 .access
= PL1_R
, .type
= ARM_CP_CURRENTEL
},
5091 /* Cache ops: all NOPs since we don't emulate caches */
5092 { .name
= "IC_IALLUIS", .state
= ARM_CP_STATE_AA64
,
5093 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
5094 .access
= PL1_W
, .type
= ARM_CP_NOP
,
5095 .accessfn
= aa64_cacheop_pou_access
},
5096 { .name
= "IC_IALLU", .state
= ARM_CP_STATE_AA64
,
5097 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
5098 .access
= PL1_W
, .type
= ARM_CP_NOP
,
5099 .accessfn
= aa64_cacheop_pou_access
},
5100 { .name
= "IC_IVAU", .state
= ARM_CP_STATE_AA64
,
5101 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 5, .opc2
= 1,
5102 .access
= PL0_W
, .type
= ARM_CP_NOP
,
5103 .accessfn
= aa64_cacheop_pou_access
},
5104 { .name
= "DC_IVAC", .state
= ARM_CP_STATE_AA64
,
5105 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
5106 .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
,
5107 .type
= ARM_CP_NOP
},
5108 { .name
= "DC_ISW", .state
= ARM_CP_STATE_AA64
,
5109 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
5110 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
5111 { .name
= "DC_CVAC", .state
= ARM_CP_STATE_AA64
,
5112 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 1,
5113 .access
= PL0_W
, .type
= ARM_CP_NOP
,
5114 .accessfn
= aa64_cacheop_poc_access
},
5115 { .name
= "DC_CSW", .state
= ARM_CP_STATE_AA64
,
5116 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
5117 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
5118 { .name
= "DC_CVAU", .state
= ARM_CP_STATE_AA64
,
5119 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 11, .opc2
= 1,
5120 .access
= PL0_W
, .type
= ARM_CP_NOP
,
5121 .accessfn
= aa64_cacheop_pou_access
},
5122 { .name
= "DC_CIVAC", .state
= ARM_CP_STATE_AA64
,
5123 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 1,
5124 .access
= PL0_W
, .type
= ARM_CP_NOP
,
5125 .accessfn
= aa64_cacheop_poc_access
},
5126 { .name
= "DC_CISW", .state
= ARM_CP_STATE_AA64
,
5127 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
5128 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
5129 /* TLBI operations */
5130 { .name
= "TLBI_VMALLE1IS", .state
= ARM_CP_STATE_AA64
,
5131 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
5132 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5133 .writefn
= tlbi_aa64_vmalle1is_write
},
5134 { .name
= "TLBI_VAE1IS", .state
= ARM_CP_STATE_AA64
,
5135 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
5136 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5137 .writefn
= tlbi_aa64_vae1is_write
},
5138 { .name
= "TLBI_ASIDE1IS", .state
= ARM_CP_STATE_AA64
,
5139 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
5140 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5141 .writefn
= tlbi_aa64_vmalle1is_write
},
5142 { .name
= "TLBI_VAAE1IS", .state
= ARM_CP_STATE_AA64
,
5143 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
5144 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5145 .writefn
= tlbi_aa64_vae1is_write
},
5146 { .name
= "TLBI_VALE1IS", .state
= ARM_CP_STATE_AA64
,
5147 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
5148 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5149 .writefn
= tlbi_aa64_vae1is_write
},
5150 { .name
= "TLBI_VAALE1IS", .state
= ARM_CP_STATE_AA64
,
5151 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
5152 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5153 .writefn
= tlbi_aa64_vae1is_write
},
5154 { .name
= "TLBI_VMALLE1", .state
= ARM_CP_STATE_AA64
,
5155 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
5156 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5157 .writefn
= tlbi_aa64_vmalle1_write
},
5158 { .name
= "TLBI_VAE1", .state
= ARM_CP_STATE_AA64
,
5159 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
5160 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5161 .writefn
= tlbi_aa64_vae1_write
},
5162 { .name
= "TLBI_ASIDE1", .state
= ARM_CP_STATE_AA64
,
5163 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
5164 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5165 .writefn
= tlbi_aa64_vmalle1_write
},
5166 { .name
= "TLBI_VAAE1", .state
= ARM_CP_STATE_AA64
,
5167 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
5168 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5169 .writefn
= tlbi_aa64_vae1_write
},
5170 { .name
= "TLBI_VALE1", .state
= ARM_CP_STATE_AA64
,
5171 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
5172 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5173 .writefn
= tlbi_aa64_vae1_write
},
5174 { .name
= "TLBI_VAALE1", .state
= ARM_CP_STATE_AA64
,
5175 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
5176 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5177 .writefn
= tlbi_aa64_vae1_write
},
5178 { .name
= "TLBI_IPAS2E1IS", .state
= ARM_CP_STATE_AA64
,
5179 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
5180 .access
= PL2_W
, .type
= ARM_CP_NOP
},
5181 { .name
= "TLBI_IPAS2LE1IS", .state
= ARM_CP_STATE_AA64
,
5182 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
5183 .access
= PL2_W
, .type
= ARM_CP_NOP
},
5184 { .name
= "TLBI_ALLE1IS", .state
= ARM_CP_STATE_AA64
,
5185 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
5186 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5187 .writefn
= tlbi_aa64_alle1is_write
},
5188 { .name
= "TLBI_VMALLS12E1IS", .state
= ARM_CP_STATE_AA64
,
5189 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 6,
5190 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5191 .writefn
= tlbi_aa64_alle1is_write
},
5192 { .name
= "TLBI_IPAS2E1", .state
= ARM_CP_STATE_AA64
,
5193 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
5194 .access
= PL2_W
, .type
= ARM_CP_NOP
},
5195 { .name
= "TLBI_IPAS2LE1", .state
= ARM_CP_STATE_AA64
,
5196 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
5197 .access
= PL2_W
, .type
= ARM_CP_NOP
},
5198 { .name
= "TLBI_ALLE1", .state
= ARM_CP_STATE_AA64
,
5199 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
5200 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5201 .writefn
= tlbi_aa64_alle1_write
},
5202 { .name
= "TLBI_VMALLS12E1", .state
= ARM_CP_STATE_AA64
,
5203 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 6,
5204 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5205 .writefn
= tlbi_aa64_alle1is_write
},
5206 #ifndef CONFIG_USER_ONLY
5207 /* 64 bit address translation operations */
5208 { .name
= "AT_S1E1R", .state
= ARM_CP_STATE_AA64
,
5209 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 0,
5210 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5211 .writefn
= ats_write64
},
5212 { .name
= "AT_S1E1W", .state
= ARM_CP_STATE_AA64
,
5213 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 1,
5214 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5215 .writefn
= ats_write64
},
5216 { .name
= "AT_S1E0R", .state
= ARM_CP_STATE_AA64
,
5217 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 2,
5218 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5219 .writefn
= ats_write64
},
5220 { .name
= "AT_S1E0W", .state
= ARM_CP_STATE_AA64
,
5221 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 3,
5222 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5223 .writefn
= ats_write64
},
5224 { .name
= "AT_S12E1R", .state
= ARM_CP_STATE_AA64
,
5225 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 4,
5226 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5227 .writefn
= ats_write64
},
5228 { .name
= "AT_S12E1W", .state
= ARM_CP_STATE_AA64
,
5229 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 5,
5230 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5231 .writefn
= ats_write64
},
5232 { .name
= "AT_S12E0R", .state
= ARM_CP_STATE_AA64
,
5233 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 6,
5234 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5235 .writefn
= ats_write64
},
5236 { .name
= "AT_S12E0W", .state
= ARM_CP_STATE_AA64
,
5237 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 7,
5238 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5239 .writefn
= ats_write64
},
5240 /* AT S1E2* are elsewhere as they UNDEF from EL3 if EL2 is not present */
5241 { .name
= "AT_S1E3R", .state
= ARM_CP_STATE_AA64
,
5242 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 0,
5243 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5244 .writefn
= ats_write64
},
5245 { .name
= "AT_S1E3W", .state
= ARM_CP_STATE_AA64
,
5246 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 1,
5247 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5248 .writefn
= ats_write64
},
5249 { .name
= "PAR_EL1", .state
= ARM_CP_STATE_AA64
,
5250 .type
= ARM_CP_ALIAS
,
5251 .opc0
= 3, .opc1
= 0, .crn
= 7, .crm
= 4, .opc2
= 0,
5252 .access
= PL1_RW
, .resetvalue
= 0,
5253 .fieldoffset
= offsetof(CPUARMState
, cp15
.par_el
[1]),
5254 .writefn
= par_write
},
5256 /* TLB invalidate last level of translation table walk */
5257 { .name
= "TLBIMVALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
5258 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5259 .writefn
= tlbimva_is_write
},
5260 { .name
= "TLBIMVAALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
5261 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5262 .writefn
= tlbimvaa_is_write
},
5263 { .name
= "TLBIMVAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
5264 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5265 .writefn
= tlbimva_write
},
5266 { .name
= "TLBIMVAAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
5267 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5268 .writefn
= tlbimvaa_write
},
5269 { .name
= "TLBIMVALH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
5270 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5271 .writefn
= tlbimva_hyp_write
},
5272 { .name
= "TLBIMVALHIS",
5273 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
5274 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5275 .writefn
= tlbimva_hyp_is_write
},
5276 { .name
= "TLBIIPAS2",
5277 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
5278 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5279 { .name
= "TLBIIPAS2IS",
5280 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
5281 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5282 { .name
= "TLBIIPAS2L",
5283 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
5284 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5285 { .name
= "TLBIIPAS2LIS",
5286 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
5287 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5288 /* 32 bit cache operations */
5289 { .name
= "ICIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
5290 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5291 { .name
= "BPIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 6,
5292 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5293 { .name
= "ICIALLU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
5294 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5295 { .name
= "ICIMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 1,
5296 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5297 { .name
= "BPIALL", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 6,
5298 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5299 { .name
= "BPIMVA", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 7,
5300 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5301 { .name
= "DCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
5302 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5303 { .name
= "DCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
5304 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5305 { .name
= "DCCMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 1,
5306 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5307 { .name
= "DCCSW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
5308 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5309 { .name
= "DCCMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 11, .opc2
= 1,
5310 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5311 { .name
= "DCCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 1,
5312 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5313 { .name
= "DCCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
5314 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5315 /* MMU Domain access control / MPU write buffer control */
5316 { .name
= "DACR", .cp
= 15, .opc1
= 0, .crn
= 3, .crm
= 0, .opc2
= 0,
5317 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
5318 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
5319 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
5320 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
5321 { .name
= "ELR_EL1", .state
= ARM_CP_STATE_AA64
,
5322 .type
= ARM_CP_ALIAS
,
5323 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 1,
5325 .fieldoffset
= offsetof(CPUARMState
, elr_el
[1]) },
5326 { .name
= "SPSR_EL1", .state
= ARM_CP_STATE_AA64
,
5327 .type
= ARM_CP_ALIAS
,
5328 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 0,
5330 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_SVC
]) },
5331 /* We rely on the access checks not allowing the guest to write to the
5332 * state field when SPSel indicates that it's being used as the stack
5335 { .name
= "SP_EL0", .state
= ARM_CP_STATE_AA64
,
5336 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 1, .opc2
= 0,
5337 .access
= PL1_RW
, .accessfn
= sp_el0_access
,
5338 .type
= ARM_CP_ALIAS
,
5339 .fieldoffset
= offsetof(CPUARMState
, sp_el
[0]) },
5340 { .name
= "SP_EL1", .state
= ARM_CP_STATE_AA64
,
5341 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 1, .opc2
= 0,
5342 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
,
5343 .fieldoffset
= offsetof(CPUARMState
, sp_el
[1]) },
5344 { .name
= "SPSel", .state
= ARM_CP_STATE_AA64
,
5345 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 0,
5346 .type
= ARM_CP_NO_RAW
,
5347 .access
= PL1_RW
, .readfn
= spsel_read
, .writefn
= spsel_write
},
5348 { .name
= "FPEXC32_EL2", .state
= ARM_CP_STATE_AA64
,
5349 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 3, .opc2
= 0,
5350 .type
= ARM_CP_ALIAS
,
5351 .fieldoffset
= offsetof(CPUARMState
, vfp
.xregs
[ARM_VFP_FPEXC
]),
5352 .access
= PL2_RW
, .accessfn
= fpexc32_access
},
5353 { .name
= "DACR32_EL2", .state
= ARM_CP_STATE_AA64
,
5354 .opc0
= 3, .opc1
= 4, .crn
= 3, .crm
= 0, .opc2
= 0,
5355 .access
= PL2_RW
, .resetvalue
= 0,
5356 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
5357 .fieldoffset
= offsetof(CPUARMState
, cp15
.dacr32_el2
) },
5358 { .name
= "IFSR32_EL2", .state
= ARM_CP_STATE_AA64
,
5359 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 0, .opc2
= 1,
5360 .access
= PL2_RW
, .resetvalue
= 0,
5361 .fieldoffset
= offsetof(CPUARMState
, cp15
.ifsr32_el2
) },
5362 { .name
= "SPSR_IRQ", .state
= ARM_CP_STATE_AA64
,
5363 .type
= ARM_CP_ALIAS
,
5364 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 0,
5366 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_IRQ
]) },
5367 { .name
= "SPSR_ABT", .state
= ARM_CP_STATE_AA64
,
5368 .type
= ARM_CP_ALIAS
,
5369 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 1,
5371 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_ABT
]) },
5372 { .name
= "SPSR_UND", .state
= ARM_CP_STATE_AA64
,
5373 .type
= ARM_CP_ALIAS
,
5374 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 2,
5376 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_UND
]) },
5377 { .name
= "SPSR_FIQ", .state
= ARM_CP_STATE_AA64
,
5378 .type
= ARM_CP_ALIAS
,
5379 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 3,
5381 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_FIQ
]) },
5382 { .name
= "MDCR_EL3", .state
= ARM_CP_STATE_AA64
,
5383 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 3, .opc2
= 1,
5385 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el3
) },
5386 { .name
= "SDCR", .type
= ARM_CP_ALIAS
,
5387 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 3, .opc2
= 1,
5388 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
5389 .writefn
= sdcr_write
,
5390 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.mdcr_el3
) },
5394 /* Used to describe the behaviour of EL2 regs when EL2 does not exist. */
5395 static const ARMCPRegInfo el3_no_el2_cp_reginfo
[] = {
5396 { .name
= "VBAR_EL2", .state
= ARM_CP_STATE_BOTH
,
5397 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 0,
5399 .readfn
= arm_cp_read_zero
, .writefn
= arm_cp_write_ignore
},
5400 { .name
= "HCR_EL2", .state
= ARM_CP_STATE_BOTH
,
5401 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
5403 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5404 { .name
= "HACR_EL2", .state
= ARM_CP_STATE_BOTH
,
5405 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 7,
5406 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5407 { .name
= "ESR_EL2", .state
= ARM_CP_STATE_BOTH
,
5408 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 2, .opc2
= 0,
5410 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5411 { .name
= "CPTR_EL2", .state
= ARM_CP_STATE_BOTH
,
5412 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 2,
5413 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5414 { .name
= "MAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
5415 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 0,
5416 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5418 { .name
= "HMAIR1", .state
= ARM_CP_STATE_AA32
,
5419 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 1,
5420 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5421 { .name
= "AMAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
5422 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 0,
5423 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5425 { .name
= "HAMAIR1", .state
= ARM_CP_STATE_AA32
,
5426 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 1,
5427 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5429 { .name
= "AFSR0_EL2", .state
= ARM_CP_STATE_BOTH
,
5430 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 0,
5431 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5433 { .name
= "AFSR1_EL2", .state
= ARM_CP_STATE_BOTH
,
5434 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 1,
5435 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5437 { .name
= "TCR_EL2", .state
= ARM_CP_STATE_BOTH
,
5438 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 2,
5439 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5440 { .name
= "VTCR_EL2", .state
= ARM_CP_STATE_BOTH
,
5441 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
5442 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5443 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5444 { .name
= "VTTBR", .state
= ARM_CP_STATE_AA32
,
5445 .cp
= 15, .opc1
= 6, .crm
= 2,
5446 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5447 .type
= ARM_CP_CONST
| ARM_CP_64BIT
, .resetvalue
= 0 },
5448 { .name
= "VTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
5449 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 0,
5450 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5451 { .name
= "SCTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
5452 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 0,
5453 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5454 { .name
= "TPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
5455 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 2,
5456 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5457 { .name
= "TTBR0_EL2", .state
= ARM_CP_STATE_AA64
,
5458 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 0,
5459 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5460 { .name
= "HTTBR", .cp
= 15, .opc1
= 4, .crm
= 2,
5461 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_CONST
,
5463 { .name
= "CNTHCTL_EL2", .state
= ARM_CP_STATE_BOTH
,
5464 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 1, .opc2
= 0,
5465 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5466 { .name
= "CNTVOFF_EL2", .state
= ARM_CP_STATE_AA64
,
5467 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 0, .opc2
= 3,
5468 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5469 { .name
= "CNTVOFF", .cp
= 15, .opc1
= 4, .crm
= 14,
5470 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_CONST
,
5472 { .name
= "CNTHP_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
5473 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 2,
5474 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5475 { .name
= "CNTHP_CVAL", .cp
= 15, .opc1
= 6, .crm
= 14,
5476 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_CONST
,
5478 { .name
= "CNTHP_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
5479 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 0,
5480 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5481 { .name
= "CNTHP_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
5482 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 1,
5483 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5484 { .name
= "MDCR_EL2", .state
= ARM_CP_STATE_BOTH
,
5485 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 1,
5486 .access
= PL2_RW
, .accessfn
= access_tda
,
5487 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5488 { .name
= "HPFAR_EL2", .state
= ARM_CP_STATE_BOTH
,
5489 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
5490 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5491 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5492 { .name
= "HSTR_EL2", .state
= ARM_CP_STATE_BOTH
,
5493 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 3,
5494 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5495 { .name
= "FAR_EL2", .state
= ARM_CP_STATE_BOTH
,
5496 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 0,
5497 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5498 { .name
= "HIFAR", .state
= ARM_CP_STATE_AA32
,
5499 .type
= ARM_CP_CONST
,
5500 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 2,
5501 .access
= PL2_RW
, .resetvalue
= 0 },
5505 /* Ditto, but for registers which exist in ARMv8 but not v7 */
5506 static const ARMCPRegInfo el3_no_el2_v8_cp_reginfo
[] = {
5507 { .name
= "HCR2", .state
= ARM_CP_STATE_AA32
,
5508 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 4,
5510 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5514 static void do_hcr_write(CPUARMState
*env
, uint64_t value
, uint64_t valid_mask
)
5516 ARMCPU
*cpu
= env_archcpu(env
);
5518 if (arm_feature(env
, ARM_FEATURE_V8
)) {
5519 valid_mask
|= MAKE_64BIT_MASK(0, 34); /* ARMv8.0 */
5521 valid_mask
|= MAKE_64BIT_MASK(0, 28); /* ARMv7VE */
5524 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
5525 valid_mask
&= ~HCR_HCD
;
5526 } else if (cpu
->psci_conduit
!= QEMU_PSCI_CONDUIT_SMC
) {
5527 /* Architecturally HCR.TSC is RES0 if EL3 is not implemented.
5528 * However, if we're using the SMC PSCI conduit then QEMU is
5529 * effectively acting like EL3 firmware and so the guest at
5530 * EL2 should retain the ability to prevent EL1 from being
5531 * able to make SMC calls into the ersatz firmware, so in
5532 * that case HCR.TSC should be read/write.
5534 valid_mask
&= ~HCR_TSC
;
5537 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
5538 if (cpu_isar_feature(aa64_vh
, cpu
)) {
5539 valid_mask
|= HCR_E2H
;
5541 if (cpu_isar_feature(aa64_lor
, cpu
)) {
5542 valid_mask
|= HCR_TLOR
;
5544 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
5545 valid_mask
|= HCR_API
| HCR_APK
;
5547 if (cpu_isar_feature(aa64_mte
, cpu
)) {
5548 valid_mask
|= HCR_ATA
| HCR_DCT
| HCR_TID5
;
5552 /* Clear RES0 bits. */
5553 value
&= valid_mask
;
5556 * These bits change the MMU setup:
5557 * HCR_VM enables stage 2 translation
5558 * HCR_PTW forbids certain page-table setups
5559 * HCR_DC disables stage1 and enables stage2 translation
5560 * HCR_DCT enables tagging on (disabled) stage1 translation
5562 if ((env
->cp15
.hcr_el2
^ value
) & (HCR_VM
| HCR_PTW
| HCR_DC
| HCR_DCT
)) {
5563 tlb_flush(CPU(cpu
));
5565 env
->cp15
.hcr_el2
= value
;
5568 * Updates to VI and VF require us to update the status of
5569 * virtual interrupts, which are the logical OR of these bits
5570 * and the state of the input lines from the GIC. (This requires
5571 * that we have the iothread lock, which is done by marking the
5572 * reginfo structs as ARM_CP_IO.)
5573 * Note that if a write to HCR pends a VIRQ or VFIQ it is never
5574 * possible for it to be taken immediately, because VIRQ and
5575 * VFIQ are masked unless running at EL0 or EL1, and HCR
5576 * can only be written at EL2.
5578 g_assert(qemu_mutex_iothread_locked());
5579 arm_cpu_update_virq(cpu
);
5580 arm_cpu_update_vfiq(cpu
);
5583 static void hcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
5585 do_hcr_write(env
, value
, 0);
5588 static void hcr_writehigh(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5591 /* Handle HCR2 write, i.e. write to high half of HCR_EL2 */
5592 value
= deposit64(env
->cp15
.hcr_el2
, 32, 32, value
);
5593 do_hcr_write(env
, value
, MAKE_64BIT_MASK(0, 32));
5596 static void hcr_writelow(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5599 /* Handle HCR write, i.e. write to low half of HCR_EL2 */
5600 value
= deposit64(env
->cp15
.hcr_el2
, 0, 32, value
);
5601 do_hcr_write(env
, value
, MAKE_64BIT_MASK(32, 32));
5605 * Return the effective value of HCR_EL2.
5606 * Bits that are not included here:
5607 * RW (read from SCR_EL3.RW as needed)
5609 uint64_t arm_hcr_el2_eff(CPUARMState
*env
)
5611 uint64_t ret
= env
->cp15
.hcr_el2
;
5613 if (!arm_is_el2_enabled(env
)) {
5615 * "This register has no effect if EL2 is not enabled in the
5616 * current Security state". This is ARMv8.4-SecEL2 speak for
5617 * !(SCR_EL3.NS==1 || SCR_EL3.EEL2==1).
5619 * Prior to that, the language was "In an implementation that
5620 * includes EL3, when the value of SCR_EL3.NS is 0 the PE behaves
5621 * as if this field is 0 for all purposes other than a direct
5622 * read or write access of HCR_EL2". With lots of enumeration
5623 * on a per-field basis. In current QEMU, this is condition
5624 * is arm_is_secure_below_el3.
5626 * Since the v8.4 language applies to the entire register, and
5627 * appears to be backward compatible, use that.
5633 * For a cpu that supports both aarch64 and aarch32, we can set bits
5634 * in HCR_EL2 (e.g. via EL3) that are RES0 when we enter EL2 as aa32.
5635 * Ignore all of the bits in HCR+HCR2 that are not valid for aarch32.
5637 if (!arm_el_is_aa64(env
, 2)) {
5638 uint64_t aa32_valid
;
5641 * These bits are up-to-date as of ARMv8.6.
5642 * For HCR, it's easiest to list just the 2 bits that are invalid.
5643 * For HCR2, list those that are valid.
5645 aa32_valid
= MAKE_64BIT_MASK(0, 32) & ~(HCR_RW
| HCR_TDZ
);
5646 aa32_valid
|= (HCR_CD
| HCR_ID
| HCR_TERR
| HCR_TEA
| HCR_MIOCNCE
|
5647 HCR_TID4
| HCR_TICAB
| HCR_TOCU
| HCR_TTLBIS
);
5651 if (ret
& HCR_TGE
) {
5652 /* These bits are up-to-date as of ARMv8.6. */
5653 if (ret
& HCR_E2H
) {
5654 ret
&= ~(HCR_VM
| HCR_FMO
| HCR_IMO
| HCR_AMO
|
5655 HCR_BSU_MASK
| HCR_DC
| HCR_TWI
| HCR_TWE
|
5656 HCR_TID0
| HCR_TID2
| HCR_TPCP
| HCR_TPU
|
5657 HCR_TDZ
| HCR_CD
| HCR_ID
| HCR_MIOCNCE
|
5658 HCR_TID4
| HCR_TICAB
| HCR_TOCU
| HCR_ENSCXT
|
5659 HCR_TTLBIS
| HCR_TTLBOS
| HCR_TID5
);
5661 ret
|= HCR_FMO
| HCR_IMO
| HCR_AMO
;
5663 ret
&= ~(HCR_SWIO
| HCR_PTW
| HCR_VF
| HCR_VI
| HCR_VSE
|
5664 HCR_FB
| HCR_TID1
| HCR_TID3
| HCR_TSC
| HCR_TACR
|
5665 HCR_TSW
| HCR_TTLB
| HCR_TVM
| HCR_HCD
| HCR_TRVM
|
5672 static void cptr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5676 * For A-profile AArch32 EL3, if NSACR.CP10
5677 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
5679 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
5680 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
5681 value
&= ~(0x3 << 10);
5682 value
|= env
->cp15
.cptr_el
[2] & (0x3 << 10);
5684 env
->cp15
.cptr_el
[2] = value
;
5687 static uint64_t cptr_el2_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
5690 * For A-profile AArch32 EL3, if NSACR.CP10
5691 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
5693 uint64_t value
= env
->cp15
.cptr_el
[2];
5695 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
5696 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
5702 static const ARMCPRegInfo el2_cp_reginfo
[] = {
5703 { .name
= "HCR_EL2", .state
= ARM_CP_STATE_AA64
,
5705 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
5706 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.hcr_el2
),
5707 .writefn
= hcr_write
},
5708 { .name
= "HCR", .state
= ARM_CP_STATE_AA32
,
5709 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
5710 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
5711 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.hcr_el2
),
5712 .writefn
= hcr_writelow
},
5713 { .name
= "HACR_EL2", .state
= ARM_CP_STATE_BOTH
,
5714 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 7,
5715 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5716 { .name
= "ELR_EL2", .state
= ARM_CP_STATE_AA64
,
5717 .type
= ARM_CP_ALIAS
,
5718 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 1,
5720 .fieldoffset
= offsetof(CPUARMState
, elr_el
[2]) },
5721 { .name
= "ESR_EL2", .state
= ARM_CP_STATE_BOTH
,
5722 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 2, .opc2
= 0,
5723 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[2]) },
5724 { .name
= "FAR_EL2", .state
= ARM_CP_STATE_BOTH
,
5725 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 0,
5726 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[2]) },
5727 { .name
= "HIFAR", .state
= ARM_CP_STATE_AA32
,
5728 .type
= ARM_CP_ALIAS
,
5729 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 2,
5731 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.far_el
[2]) },
5732 { .name
= "SPSR_EL2", .state
= ARM_CP_STATE_AA64
,
5733 .type
= ARM_CP_ALIAS
,
5734 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 0,
5736 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_HYP
]) },
5737 { .name
= "VBAR_EL2", .state
= ARM_CP_STATE_BOTH
,
5738 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 0,
5739 .access
= PL2_RW
, .writefn
= vbar_write
,
5740 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[2]),
5742 { .name
= "SP_EL2", .state
= ARM_CP_STATE_AA64
,
5743 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 1, .opc2
= 0,
5744 .access
= PL3_RW
, .type
= ARM_CP_ALIAS
,
5745 .fieldoffset
= offsetof(CPUARMState
, sp_el
[2]) },
5746 { .name
= "CPTR_EL2", .state
= ARM_CP_STATE_BOTH
,
5747 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 2,
5748 .access
= PL2_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
5749 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[2]),
5750 .readfn
= cptr_el2_read
, .writefn
= cptr_el2_write
},
5751 { .name
= "MAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
5752 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 0,
5753 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[2]),
5755 { .name
= "HMAIR1", .state
= ARM_CP_STATE_AA32
,
5756 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 1,
5757 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
,
5758 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.mair_el
[2]) },
5759 { .name
= "AMAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
5760 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 0,
5761 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5763 /* HAMAIR1 is mapped to AMAIR_EL2[63:32] */
5764 { .name
= "HAMAIR1", .state
= ARM_CP_STATE_AA32
,
5765 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 1,
5766 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5768 { .name
= "AFSR0_EL2", .state
= ARM_CP_STATE_BOTH
,
5769 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 0,
5770 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5772 { .name
= "AFSR1_EL2", .state
= ARM_CP_STATE_BOTH
,
5773 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 1,
5774 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5776 { .name
= "TCR_EL2", .state
= ARM_CP_STATE_BOTH
,
5777 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 2,
5778 .access
= PL2_RW
, .writefn
= vmsa_tcr_el12_write
,
5779 /* no .raw_writefn or .resetfn needed as we never use mask/base_mask */
5780 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[2]) },
5781 { .name
= "VTCR", .state
= ARM_CP_STATE_AA32
,
5782 .cp
= 15, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
5783 .type
= ARM_CP_ALIAS
,
5784 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5785 .fieldoffset
= offsetof(CPUARMState
, cp15
.vtcr_el2
) },
5786 { .name
= "VTCR_EL2", .state
= ARM_CP_STATE_AA64
,
5787 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
5789 /* no .writefn needed as this can't cause an ASID change;
5790 * no .raw_writefn or .resetfn needed as we never use mask/base_mask
5792 .fieldoffset
= offsetof(CPUARMState
, cp15
.vtcr_el2
) },
5793 { .name
= "VTTBR", .state
= ARM_CP_STATE_AA32
,
5794 .cp
= 15, .opc1
= 6, .crm
= 2,
5795 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
5796 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5797 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
),
5798 .writefn
= vttbr_write
},
5799 { .name
= "VTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
5800 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 0,
5801 .access
= PL2_RW
, .writefn
= vttbr_write
,
5802 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
) },
5803 { .name
= "SCTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
5804 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 0,
5805 .access
= PL2_RW
, .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
5806 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[2]) },
5807 { .name
= "TPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
5808 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 2,
5809 .access
= PL2_RW
, .resetvalue
= 0,
5810 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[2]) },
5811 { .name
= "TTBR0_EL2", .state
= ARM_CP_STATE_AA64
,
5812 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 0,
5813 .access
= PL2_RW
, .resetvalue
= 0, .writefn
= vmsa_tcr_ttbr_el2_write
,
5814 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
5815 { .name
= "HTTBR", .cp
= 15, .opc1
= 4, .crm
= 2,
5816 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
5817 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
5818 { .name
= "TLBIALLNSNH",
5819 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
5820 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5821 .writefn
= tlbiall_nsnh_write
},
5822 { .name
= "TLBIALLNSNHIS",
5823 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
5824 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5825 .writefn
= tlbiall_nsnh_is_write
},
5826 { .name
= "TLBIALLH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
5827 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5828 .writefn
= tlbiall_hyp_write
},
5829 { .name
= "TLBIALLHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
5830 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5831 .writefn
= tlbiall_hyp_is_write
},
5832 { .name
= "TLBIMVAH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
5833 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5834 .writefn
= tlbimva_hyp_write
},
5835 { .name
= "TLBIMVAHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
5836 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5837 .writefn
= tlbimva_hyp_is_write
},
5838 { .name
= "TLBI_ALLE2", .state
= ARM_CP_STATE_AA64
,
5839 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
5840 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5841 .writefn
= tlbi_aa64_alle2_write
},
5842 { .name
= "TLBI_VAE2", .state
= ARM_CP_STATE_AA64
,
5843 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
5844 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5845 .writefn
= tlbi_aa64_vae2_write
},
5846 { .name
= "TLBI_VALE2", .state
= ARM_CP_STATE_AA64
,
5847 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
5848 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5849 .writefn
= tlbi_aa64_vae2_write
},
5850 { .name
= "TLBI_ALLE2IS", .state
= ARM_CP_STATE_AA64
,
5851 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
5852 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5853 .writefn
= tlbi_aa64_alle2is_write
},
5854 { .name
= "TLBI_VAE2IS", .state
= ARM_CP_STATE_AA64
,
5855 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
5856 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5857 .writefn
= tlbi_aa64_vae2is_write
},
5858 { .name
= "TLBI_VALE2IS", .state
= ARM_CP_STATE_AA64
,
5859 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
5860 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5861 .writefn
= tlbi_aa64_vae2is_write
},
5862 #ifndef CONFIG_USER_ONLY
5863 /* Unlike the other EL2-related AT operations, these must
5864 * UNDEF from EL3 if EL2 is not implemented, which is why we
5865 * define them here rather than with the rest of the AT ops.
5867 { .name
= "AT_S1E2R", .state
= ARM_CP_STATE_AA64
,
5868 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
5869 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
5870 .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
, .writefn
= ats_write64
},
5871 { .name
= "AT_S1E2W", .state
= ARM_CP_STATE_AA64
,
5872 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
5873 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
5874 .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
, .writefn
= ats_write64
},
5875 /* The AArch32 ATS1H* operations are CONSTRAINED UNPREDICTABLE
5876 * if EL2 is not implemented; we choose to UNDEF. Behaviour at EL3
5877 * with SCR.NS == 0 outside Monitor mode is UNPREDICTABLE; we choose
5878 * to behave as if SCR.NS was 1.
5880 { .name
= "ATS1HR", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
5882 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
5883 { .name
= "ATS1HW", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
5885 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
5886 { .name
= "CNTHCTL_EL2", .state
= ARM_CP_STATE_BOTH
,
5887 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 1, .opc2
= 0,
5888 /* ARMv7 requires bit 0 and 1 to reset to 1. ARMv8 defines the
5889 * reset values as IMPDEF. We choose to reset to 3 to comply with
5890 * both ARMv7 and ARMv8.
5892 .access
= PL2_RW
, .resetvalue
= 3,
5893 .fieldoffset
= offsetof(CPUARMState
, cp15
.cnthctl_el2
) },
5894 { .name
= "CNTVOFF_EL2", .state
= ARM_CP_STATE_AA64
,
5895 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 0, .opc2
= 3,
5896 .access
= PL2_RW
, .type
= ARM_CP_IO
, .resetvalue
= 0,
5897 .writefn
= gt_cntvoff_write
,
5898 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
5899 { .name
= "CNTVOFF", .cp
= 15, .opc1
= 4, .crm
= 14,
5900 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
| ARM_CP_IO
,
5901 .writefn
= gt_cntvoff_write
,
5902 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
5903 { .name
= "CNTHP_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
5904 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 2,
5905 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
5906 .type
= ARM_CP_IO
, .access
= PL2_RW
,
5907 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
5908 { .name
= "CNTHP_CVAL", .cp
= 15, .opc1
= 6, .crm
= 14,
5909 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
5910 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_IO
,
5911 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
5912 { .name
= "CNTHP_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
5913 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 0,
5914 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL2_RW
,
5915 .resetfn
= gt_hyp_timer_reset
,
5916 .readfn
= gt_hyp_tval_read
, .writefn
= gt_hyp_tval_write
},
5917 { .name
= "CNTHP_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
5919 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 1,
5921 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].ctl
),
5923 .writefn
= gt_hyp_ctl_write
, .raw_writefn
= raw_write
},
5925 /* The only field of MDCR_EL2 that has a defined architectural reset value
5926 * is MDCR_EL2.HPMN which should reset to the value of PMCR_EL0.N.
5928 { .name
= "MDCR_EL2", .state
= ARM_CP_STATE_BOTH
,
5929 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 1,
5930 .access
= PL2_RW
, .resetvalue
= PMCR_NUM_COUNTERS
,
5931 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el2
), },
5932 { .name
= "HPFAR", .state
= ARM_CP_STATE_AA32
,
5933 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
5934 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5935 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
5936 { .name
= "HPFAR_EL2", .state
= ARM_CP_STATE_AA64
,
5937 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
5939 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
5940 { .name
= "HSTR_EL2", .state
= ARM_CP_STATE_BOTH
,
5941 .cp
= 15, .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 3,
5943 .fieldoffset
= offsetof(CPUARMState
, cp15
.hstr_el2
) },
5947 static const ARMCPRegInfo el2_v8_cp_reginfo
[] = {
5948 { .name
= "HCR2", .state
= ARM_CP_STATE_AA32
,
5949 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
5950 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 4,
5952 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.hcr_el2
),
5953 .writefn
= hcr_writehigh
},
5957 static CPAccessResult
sel2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5960 if (arm_current_el(env
) == 3 || arm_is_secure_below_el3(env
)) {
5961 return CP_ACCESS_OK
;
5963 return CP_ACCESS_TRAP_UNCATEGORIZED
;
5966 static const ARMCPRegInfo el2_sec_cp_reginfo
[] = {
5967 { .name
= "VSTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
5968 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 6, .opc2
= 0,
5969 .access
= PL2_RW
, .accessfn
= sel2_access
,
5970 .fieldoffset
= offsetof(CPUARMState
, cp15
.vsttbr_el2
) },
5971 { .name
= "VSTCR_EL2", .state
= ARM_CP_STATE_AA64
,
5972 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 6, .opc2
= 2,
5973 .access
= PL2_RW
, .accessfn
= sel2_access
,
5974 .fieldoffset
= offsetof(CPUARMState
, cp15
.vstcr_el2
) },
5978 static CPAccessResult
nsacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5981 /* The NSACR is RW at EL3, and RO for NS EL1 and NS EL2.
5982 * At Secure EL1 it traps to EL3 or EL2.
5984 if (arm_current_el(env
) == 3) {
5985 return CP_ACCESS_OK
;
5987 if (arm_is_secure_below_el3(env
)) {
5988 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
5989 return CP_ACCESS_TRAP_EL2
;
5991 return CP_ACCESS_TRAP_EL3
;
5993 /* Accesses from EL1 NS and EL2 NS are UNDEF for write but allow reads. */
5995 return CP_ACCESS_OK
;
5997 return CP_ACCESS_TRAP_UNCATEGORIZED
;
6000 static const ARMCPRegInfo el3_cp_reginfo
[] = {
6001 { .name
= "SCR_EL3", .state
= ARM_CP_STATE_AA64
,
6002 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 0,
6003 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.scr_el3
),
6004 .resetfn
= scr_reset
, .writefn
= scr_write
},
6005 { .name
= "SCR", .type
= ARM_CP_ALIAS
| ARM_CP_NEWEL
,
6006 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 0,
6007 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
6008 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.scr_el3
),
6009 .writefn
= scr_write
},
6010 { .name
= "SDER32_EL3", .state
= ARM_CP_STATE_AA64
,
6011 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 1,
6012 .access
= PL3_RW
, .resetvalue
= 0,
6013 .fieldoffset
= offsetof(CPUARMState
, cp15
.sder
) },
6015 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 1,
6016 .access
= PL3_RW
, .resetvalue
= 0,
6017 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.sder
) },
6018 { .name
= "MVBAR", .cp
= 15, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
6019 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
6020 .writefn
= vbar_write
, .resetvalue
= 0,
6021 .fieldoffset
= offsetof(CPUARMState
, cp15
.mvbar
) },
6022 { .name
= "TTBR0_EL3", .state
= ARM_CP_STATE_AA64
,
6023 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 0,
6024 .access
= PL3_RW
, .resetvalue
= 0,
6025 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[3]) },
6026 { .name
= "TCR_EL3", .state
= ARM_CP_STATE_AA64
,
6027 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 2,
6029 /* no .writefn needed as this can't cause an ASID change;
6030 * we must provide a .raw_writefn and .resetfn because we handle
6031 * reset and migration for the AArch32 TTBCR(S), which might be
6032 * using mask and base_mask.
6034 .resetfn
= vmsa_ttbcr_reset
, .raw_writefn
= vmsa_ttbcr_raw_write
,
6035 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[3]) },
6036 { .name
= "ELR_EL3", .state
= ARM_CP_STATE_AA64
,
6037 .type
= ARM_CP_ALIAS
,
6038 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 1,
6040 .fieldoffset
= offsetof(CPUARMState
, elr_el
[3]) },
6041 { .name
= "ESR_EL3", .state
= ARM_CP_STATE_AA64
,
6042 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 2, .opc2
= 0,
6043 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[3]) },
6044 { .name
= "FAR_EL3", .state
= ARM_CP_STATE_AA64
,
6045 .opc0
= 3, .opc1
= 6, .crn
= 6, .crm
= 0, .opc2
= 0,
6046 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[3]) },
6047 { .name
= "SPSR_EL3", .state
= ARM_CP_STATE_AA64
,
6048 .type
= ARM_CP_ALIAS
,
6049 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 0,
6051 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_MON
]) },
6052 { .name
= "VBAR_EL3", .state
= ARM_CP_STATE_AA64
,
6053 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 0,
6054 .access
= PL3_RW
, .writefn
= vbar_write
,
6055 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[3]),
6057 { .name
= "CPTR_EL3", .state
= ARM_CP_STATE_AA64
,
6058 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 2,
6059 .access
= PL3_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
6060 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[3]) },
6061 { .name
= "TPIDR_EL3", .state
= ARM_CP_STATE_AA64
,
6062 .opc0
= 3, .opc1
= 6, .crn
= 13, .crm
= 0, .opc2
= 2,
6063 .access
= PL3_RW
, .resetvalue
= 0,
6064 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[3]) },
6065 { .name
= "AMAIR_EL3", .state
= ARM_CP_STATE_AA64
,
6066 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 3, .opc2
= 0,
6067 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
6069 { .name
= "AFSR0_EL3", .state
= ARM_CP_STATE_BOTH
,
6070 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 0,
6071 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
6073 { .name
= "AFSR1_EL3", .state
= ARM_CP_STATE_BOTH
,
6074 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 1,
6075 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
6077 { .name
= "TLBI_ALLE3IS", .state
= ARM_CP_STATE_AA64
,
6078 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 0,
6079 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6080 .writefn
= tlbi_aa64_alle3is_write
},
6081 { .name
= "TLBI_VAE3IS", .state
= ARM_CP_STATE_AA64
,
6082 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 1,
6083 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6084 .writefn
= tlbi_aa64_vae3is_write
},
6085 { .name
= "TLBI_VALE3IS", .state
= ARM_CP_STATE_AA64
,
6086 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 5,
6087 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6088 .writefn
= tlbi_aa64_vae3is_write
},
6089 { .name
= "TLBI_ALLE3", .state
= ARM_CP_STATE_AA64
,
6090 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 0,
6091 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6092 .writefn
= tlbi_aa64_alle3_write
},
6093 { .name
= "TLBI_VAE3", .state
= ARM_CP_STATE_AA64
,
6094 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 1,
6095 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6096 .writefn
= tlbi_aa64_vae3_write
},
6097 { .name
= "TLBI_VALE3", .state
= ARM_CP_STATE_AA64
,
6098 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 5,
6099 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6100 .writefn
= tlbi_aa64_vae3_write
},
6104 #ifndef CONFIG_USER_ONLY
6105 /* Test if system register redirection is to occur in the current state. */
6106 static bool redirect_for_e2h(CPUARMState
*env
)
6108 return arm_current_el(env
) == 2 && (arm_hcr_el2_eff(env
) & HCR_E2H
);
6111 static uint64_t el2_e2h_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6115 if (redirect_for_e2h(env
)) {
6116 /* Switch to the saved EL2 version of the register. */
6118 readfn
= ri
->readfn
;
6120 readfn
= ri
->orig_readfn
;
6122 if (readfn
== NULL
) {
6125 return readfn(env
, ri
);
6128 static void el2_e2h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6133 if (redirect_for_e2h(env
)) {
6134 /* Switch to the saved EL2 version of the register. */
6136 writefn
= ri
->writefn
;
6138 writefn
= ri
->orig_writefn
;
6140 if (writefn
== NULL
) {
6141 writefn
= raw_write
;
6143 writefn(env
, ri
, value
);
6146 static void define_arm_vh_e2h_redirects_aliases(ARMCPU
*cpu
)
6149 uint32_t src_key
, dst_key
, new_key
;
6150 const char *src_name
, *dst_name
, *new_name
;
6151 bool (*feature
)(const ARMISARegisters
*id
);
6154 #define K(op0, op1, crn, crm, op2) \
6155 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP, crn, crm, op0, op1, op2)
6157 static const struct E2HAlias aliases
[] = {
6158 { K(3, 0, 1, 0, 0), K(3, 4, 1, 0, 0), K(3, 5, 1, 0, 0),
6159 "SCTLR", "SCTLR_EL2", "SCTLR_EL12" },
6160 { K(3, 0, 1, 0, 2), K(3, 4, 1, 1, 2), K(3, 5, 1, 0, 2),
6161 "CPACR", "CPTR_EL2", "CPACR_EL12" },
6162 { K(3, 0, 2, 0, 0), K(3, 4, 2, 0, 0), K(3, 5, 2, 0, 0),
6163 "TTBR0_EL1", "TTBR0_EL2", "TTBR0_EL12" },
6164 { K(3, 0, 2, 0, 1), K(3, 4, 2, 0, 1), K(3, 5, 2, 0, 1),
6165 "TTBR1_EL1", "TTBR1_EL2", "TTBR1_EL12" },
6166 { K(3, 0, 2, 0, 2), K(3, 4, 2, 0, 2), K(3, 5, 2, 0, 2),
6167 "TCR_EL1", "TCR_EL2", "TCR_EL12" },
6168 { K(3, 0, 4, 0, 0), K(3, 4, 4, 0, 0), K(3, 5, 4, 0, 0),
6169 "SPSR_EL1", "SPSR_EL2", "SPSR_EL12" },
6170 { K(3, 0, 4, 0, 1), K(3, 4, 4, 0, 1), K(3, 5, 4, 0, 1),
6171 "ELR_EL1", "ELR_EL2", "ELR_EL12" },
6172 { K(3, 0, 5, 1, 0), K(3, 4, 5, 1, 0), K(3, 5, 5, 1, 0),
6173 "AFSR0_EL1", "AFSR0_EL2", "AFSR0_EL12" },
6174 { K(3, 0, 5, 1, 1), K(3, 4, 5, 1, 1), K(3, 5, 5, 1, 1),
6175 "AFSR1_EL1", "AFSR1_EL2", "AFSR1_EL12" },
6176 { K(3, 0, 5, 2, 0), K(3, 4, 5, 2, 0), K(3, 5, 5, 2, 0),
6177 "ESR_EL1", "ESR_EL2", "ESR_EL12" },
6178 { K(3, 0, 6, 0, 0), K(3, 4, 6, 0, 0), K(3, 5, 6, 0, 0),
6179 "FAR_EL1", "FAR_EL2", "FAR_EL12" },
6180 { K(3, 0, 10, 2, 0), K(3, 4, 10, 2, 0), K(3, 5, 10, 2, 0),
6181 "MAIR_EL1", "MAIR_EL2", "MAIR_EL12" },
6182 { K(3, 0, 10, 3, 0), K(3, 4, 10, 3, 0), K(3, 5, 10, 3, 0),
6183 "AMAIR0", "AMAIR_EL2", "AMAIR_EL12" },
6184 { K(3, 0, 12, 0, 0), K(3, 4, 12, 0, 0), K(3, 5, 12, 0, 0),
6185 "VBAR", "VBAR_EL2", "VBAR_EL12" },
6186 { K(3, 0, 13, 0, 1), K(3, 4, 13, 0, 1), K(3, 5, 13, 0, 1),
6187 "CONTEXTIDR_EL1", "CONTEXTIDR_EL2", "CONTEXTIDR_EL12" },
6188 { K(3, 0, 14, 1, 0), K(3, 4, 14, 1, 0), K(3, 5, 14, 1, 0),
6189 "CNTKCTL", "CNTHCTL_EL2", "CNTKCTL_EL12" },
6192 * Note that redirection of ZCR is mentioned in the description
6193 * of ZCR_EL2, and aliasing in the description of ZCR_EL1, but
6194 * not in the summary table.
6196 { K(3, 0, 1, 2, 0), K(3, 4, 1, 2, 0), K(3, 5, 1, 2, 0),
6197 "ZCR_EL1", "ZCR_EL2", "ZCR_EL12", isar_feature_aa64_sve
},
6199 { K(3, 0, 5, 6, 0), K(3, 4, 5, 6, 0), K(3, 5, 5, 6, 0),
6200 "TFSR_EL1", "TFSR_EL2", "TFSR_EL12", isar_feature_aa64_mte
},
6202 /* TODO: ARMv8.2-SPE -- PMSCR_EL2 */
6203 /* TODO: ARMv8.4-Trace -- TRFCR_EL2 */
6209 for (i
= 0; i
< ARRAY_SIZE(aliases
); i
++) {
6210 const struct E2HAlias
*a
= &aliases
[i
];
6211 ARMCPRegInfo
*src_reg
, *dst_reg
;
6213 if (a
->feature
&& !a
->feature(&cpu
->isar
)) {
6217 src_reg
= g_hash_table_lookup(cpu
->cp_regs
, &a
->src_key
);
6218 dst_reg
= g_hash_table_lookup(cpu
->cp_regs
, &a
->dst_key
);
6219 g_assert(src_reg
!= NULL
);
6220 g_assert(dst_reg
!= NULL
);
6222 /* Cross-compare names to detect typos in the keys. */
6223 g_assert(strcmp(src_reg
->name
, a
->src_name
) == 0);
6224 g_assert(strcmp(dst_reg
->name
, a
->dst_name
) == 0);
6226 /* None of the core system registers use opaque; we will. */
6227 g_assert(src_reg
->opaque
== NULL
);
6229 /* Create alias before redirection so we dup the right data. */
6231 ARMCPRegInfo
*new_reg
= g_memdup(src_reg
, sizeof(ARMCPRegInfo
));
6232 uint32_t *new_key
= g_memdup(&a
->new_key
, sizeof(uint32_t));
6235 new_reg
->name
= a
->new_name
;
6236 new_reg
->type
|= ARM_CP_ALIAS
;
6237 /* Remove PL1/PL0 access, leaving PL2/PL3 R/W in place. */
6238 new_reg
->access
&= PL2_RW
| PL3_RW
;
6240 ok
= g_hash_table_insert(cpu
->cp_regs
, new_key
, new_reg
);
6244 src_reg
->opaque
= dst_reg
;
6245 src_reg
->orig_readfn
= src_reg
->readfn
?: raw_read
;
6246 src_reg
->orig_writefn
= src_reg
->writefn
?: raw_write
;
6247 if (!src_reg
->raw_readfn
) {
6248 src_reg
->raw_readfn
= raw_read
;
6250 if (!src_reg
->raw_writefn
) {
6251 src_reg
->raw_writefn
= raw_write
;
6253 src_reg
->readfn
= el2_e2h_read
;
6254 src_reg
->writefn
= el2_e2h_write
;
6259 static CPAccessResult
ctr_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6262 int cur_el
= arm_current_el(env
);
6265 uint64_t hcr
= arm_hcr_el2_eff(env
);
6268 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
6269 if (!(env
->cp15
.sctlr_el
[2] & SCTLR_UCT
)) {
6270 return CP_ACCESS_TRAP_EL2
;
6273 if (!(env
->cp15
.sctlr_el
[1] & SCTLR_UCT
)) {
6274 return CP_ACCESS_TRAP
;
6276 if (hcr
& HCR_TID2
) {
6277 return CP_ACCESS_TRAP_EL2
;
6280 } else if (hcr
& HCR_TID2
) {
6281 return CP_ACCESS_TRAP_EL2
;
6285 if (arm_current_el(env
) < 2 && arm_hcr_el2_eff(env
) & HCR_TID2
) {
6286 return CP_ACCESS_TRAP_EL2
;
6289 return CP_ACCESS_OK
;
6292 static void oslar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6295 /* Writes to OSLAR_EL1 may update the OS lock status, which can be
6296 * read via a bit in OSLSR_EL1.
6300 if (ri
->state
== ARM_CP_STATE_AA32
) {
6301 oslock
= (value
== 0xC5ACCE55);
6306 env
->cp15
.oslsr_el1
= deposit32(env
->cp15
.oslsr_el1
, 1, 1, oslock
);
6309 static const ARMCPRegInfo debug_cp_reginfo
[] = {
6310 /* DBGDRAR, DBGDSAR: always RAZ since we don't implement memory mapped
6311 * debug components. The AArch64 version of DBGDRAR is named MDRAR_EL1;
6312 * unlike DBGDRAR it is never accessible from EL0.
6313 * DBGDSAR is deprecated and must RAZ from v8 anyway, so it has no AArch64
6316 { .name
= "DBGDRAR", .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 0,
6317 .access
= PL0_R
, .accessfn
= access_tdra
,
6318 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6319 { .name
= "MDRAR_EL1", .state
= ARM_CP_STATE_AA64
,
6320 .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 0,
6321 .access
= PL1_R
, .accessfn
= access_tdra
,
6322 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6323 { .name
= "DBGDSAR", .cp
= 14, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 0,
6324 .access
= PL0_R
, .accessfn
= access_tdra
,
6325 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6326 /* Monitor debug system control register; the 32-bit alias is DBGDSCRext. */
6327 { .name
= "MDSCR_EL1", .state
= ARM_CP_STATE_BOTH
,
6328 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 2,
6329 .access
= PL1_RW
, .accessfn
= access_tda
,
6330 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdscr_el1
),
6333 * MDCCSR_EL0[30:29] map to EDSCR[30:29]. Simply RAZ as the external
6334 * Debug Communication Channel is not implemented.
6336 { .name
= "MDCCSR_EL0", .state
= ARM_CP_STATE_AA64
,
6337 .opc0
= 2, .opc1
= 3, .crn
= 0, .crm
= 1, .opc2
= 0,
6338 .access
= PL0_R
, .accessfn
= access_tda
,
6339 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6341 * DBGDSCRint[15,12,5:2] map to MDSCR_EL1[15,12,5:2]. Map all bits as
6342 * it is unlikely a guest will care.
6343 * We don't implement the configurable EL0 access.
6345 { .name
= "DBGDSCRint", .state
= ARM_CP_STATE_AA32
,
6346 .cp
= 14, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 0,
6347 .type
= ARM_CP_ALIAS
,
6348 .access
= PL1_R
, .accessfn
= access_tda
,
6349 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdscr_el1
), },
6350 { .name
= "OSLAR_EL1", .state
= ARM_CP_STATE_BOTH
,
6351 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 4,
6352 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6353 .accessfn
= access_tdosa
,
6354 .writefn
= oslar_write
},
6355 { .name
= "OSLSR_EL1", .state
= ARM_CP_STATE_BOTH
,
6356 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 4,
6357 .access
= PL1_R
, .resetvalue
= 10,
6358 .accessfn
= access_tdosa
,
6359 .fieldoffset
= offsetof(CPUARMState
, cp15
.oslsr_el1
) },
6360 /* Dummy OSDLR_EL1: 32-bit Linux will read this */
6361 { .name
= "OSDLR_EL1", .state
= ARM_CP_STATE_BOTH
,
6362 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 3, .opc2
= 4,
6363 .access
= PL1_RW
, .accessfn
= access_tdosa
,
6364 .type
= ARM_CP_NOP
},
6365 /* Dummy DBGVCR: Linux wants to clear this on startup, but we don't
6366 * implement vector catch debug events yet.
6369 .cp
= 14, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 0,
6370 .access
= PL1_RW
, .accessfn
= access_tda
,
6371 .type
= ARM_CP_NOP
},
6372 /* Dummy DBGVCR32_EL2 (which is only for a 64-bit hypervisor
6373 * to save and restore a 32-bit guest's DBGVCR)
6375 { .name
= "DBGVCR32_EL2", .state
= ARM_CP_STATE_AA64
,
6376 .opc0
= 2, .opc1
= 4, .crn
= 0, .crm
= 7, .opc2
= 0,
6377 .access
= PL2_RW
, .accessfn
= access_tda
,
6378 .type
= ARM_CP_NOP
},
6379 /* Dummy MDCCINT_EL1, since we don't implement the Debug Communications
6380 * Channel but Linux may try to access this register. The 32-bit
6381 * alias is DBGDCCINT.
6383 { .name
= "MDCCINT_EL1", .state
= ARM_CP_STATE_BOTH
,
6384 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 0,
6385 .access
= PL1_RW
, .accessfn
= access_tda
,
6386 .type
= ARM_CP_NOP
},
6390 static const ARMCPRegInfo debug_lpae_cp_reginfo
[] = {
6391 /* 64 bit access versions of the (dummy) debug registers */
6392 { .name
= "DBGDRAR", .cp
= 14, .crm
= 1, .opc1
= 0,
6393 .access
= PL0_R
, .type
= ARM_CP_CONST
|ARM_CP_64BIT
, .resetvalue
= 0 },
6394 { .name
= "DBGDSAR", .cp
= 14, .crm
= 2, .opc1
= 0,
6395 .access
= PL0_R
, .type
= ARM_CP_CONST
|ARM_CP_64BIT
, .resetvalue
= 0 },
6399 /* Return the exception level to which exceptions should be taken
6400 * via SVEAccessTrap. If an exception should be routed through
6401 * AArch64.AdvSIMDFPAccessTrap, return 0; fp_exception_el should
6402 * take care of raising that exception.
6403 * C.f. the ARM pseudocode function CheckSVEEnabled.
6405 int sve_exception_el(CPUARMState
*env
, int el
)
6407 #ifndef CONFIG_USER_ONLY
6408 uint64_t hcr_el2
= arm_hcr_el2_eff(env
);
6410 if (el
<= 1 && (hcr_el2
& (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
6411 bool disabled
= false;
6413 /* The CPACR.ZEN controls traps to EL1:
6414 * 0, 2 : trap EL0 and EL1 accesses
6415 * 1 : trap only EL0 accesses
6416 * 3 : trap no accesses
6418 if (!extract32(env
->cp15
.cpacr_el1
, 16, 1)) {
6420 } else if (!extract32(env
->cp15
.cpacr_el1
, 17, 1)) {
6425 return hcr_el2
& HCR_TGE
? 2 : 1;
6428 /* Check CPACR.FPEN. */
6429 if (!extract32(env
->cp15
.cpacr_el1
, 20, 1)) {
6431 } else if (!extract32(env
->cp15
.cpacr_el1
, 21, 1)) {
6439 /* CPTR_EL2. Since TZ and TFP are positive,
6440 * they will be zero when EL2 is not present.
6442 if (el
<= 2 && arm_is_el2_enabled(env
)) {
6443 if (env
->cp15
.cptr_el
[2] & CPTR_TZ
) {
6446 if (env
->cp15
.cptr_el
[2] & CPTR_TFP
) {
6451 /* CPTR_EL3. Since EZ is negative we must check for EL3. */
6452 if (arm_feature(env
, ARM_FEATURE_EL3
)
6453 && !(env
->cp15
.cptr_el
[3] & CPTR_EZ
)) {
6460 static uint32_t sve_zcr_get_valid_len(ARMCPU
*cpu
, uint32_t start_len
)
6464 end_len
= start_len
&= 0xf;
6465 if (!test_bit(start_len
, cpu
->sve_vq_map
)) {
6466 end_len
= find_last_bit(cpu
->sve_vq_map
, start_len
);
6467 assert(end_len
< start_len
);
6473 * Given that SVE is enabled, return the vector length for EL.
6475 uint32_t sve_zcr_len_for_el(CPUARMState
*env
, int el
)
6477 ARMCPU
*cpu
= env_archcpu(env
);
6478 uint32_t zcr_len
= cpu
->sve_max_vq
- 1;
6481 zcr_len
= MIN(zcr_len
, 0xf & (uint32_t)env
->vfp
.zcr_el
[1]);
6483 if (el
<= 2 && arm_feature(env
, ARM_FEATURE_EL2
)) {
6484 zcr_len
= MIN(zcr_len
, 0xf & (uint32_t)env
->vfp
.zcr_el
[2]);
6486 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
6487 zcr_len
= MIN(zcr_len
, 0xf & (uint32_t)env
->vfp
.zcr_el
[3]);
6490 return sve_zcr_get_valid_len(cpu
, zcr_len
);
6493 static void zcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6496 int cur_el
= arm_current_el(env
);
6497 int old_len
= sve_zcr_len_for_el(env
, cur_el
);
6500 /* Bits other than [3:0] are RAZ/WI. */
6501 QEMU_BUILD_BUG_ON(ARM_MAX_VQ
> 16);
6502 raw_write(env
, ri
, value
& 0xf);
6505 * Because we arrived here, we know both FP and SVE are enabled;
6506 * otherwise we would have trapped access to the ZCR_ELn register.
6508 new_len
= sve_zcr_len_for_el(env
, cur_el
);
6509 if (new_len
< old_len
) {
6510 aarch64_sve_narrow_vq(env
, new_len
+ 1);
6514 static const ARMCPRegInfo zcr_el1_reginfo
= {
6515 .name
= "ZCR_EL1", .state
= ARM_CP_STATE_AA64
,
6516 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 2, .opc2
= 0,
6517 .access
= PL1_RW
, .type
= ARM_CP_SVE
,
6518 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[1]),
6519 .writefn
= zcr_write
, .raw_writefn
= raw_write
6522 static const ARMCPRegInfo zcr_el2_reginfo
= {
6523 .name
= "ZCR_EL2", .state
= ARM_CP_STATE_AA64
,
6524 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 0,
6525 .access
= PL2_RW
, .type
= ARM_CP_SVE
,
6526 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[2]),
6527 .writefn
= zcr_write
, .raw_writefn
= raw_write
6530 static const ARMCPRegInfo zcr_no_el2_reginfo
= {
6531 .name
= "ZCR_EL2", .state
= ARM_CP_STATE_AA64
,
6532 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 0,
6533 .access
= PL2_RW
, .type
= ARM_CP_SVE
,
6534 .readfn
= arm_cp_read_zero
, .writefn
= arm_cp_write_ignore
6537 static const ARMCPRegInfo zcr_el3_reginfo
= {
6538 .name
= "ZCR_EL3", .state
= ARM_CP_STATE_AA64
,
6539 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 2, .opc2
= 0,
6540 .access
= PL3_RW
, .type
= ARM_CP_SVE
,
6541 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[3]),
6542 .writefn
= zcr_write
, .raw_writefn
= raw_write
6545 void hw_watchpoint_update(ARMCPU
*cpu
, int n
)
6547 CPUARMState
*env
= &cpu
->env
;
6549 vaddr wvr
= env
->cp15
.dbgwvr
[n
];
6550 uint64_t wcr
= env
->cp15
.dbgwcr
[n
];
6552 int flags
= BP_CPU
| BP_STOP_BEFORE_ACCESS
;
6554 if (env
->cpu_watchpoint
[n
]) {
6555 cpu_watchpoint_remove_by_ref(CPU(cpu
), env
->cpu_watchpoint
[n
]);
6556 env
->cpu_watchpoint
[n
] = NULL
;
6559 if (!extract64(wcr
, 0, 1)) {
6560 /* E bit clear : watchpoint disabled */
6564 switch (extract64(wcr
, 3, 2)) {
6566 /* LSC 00 is reserved and must behave as if the wp is disabled */
6569 flags
|= BP_MEM_READ
;
6572 flags
|= BP_MEM_WRITE
;
6575 flags
|= BP_MEM_ACCESS
;
6579 /* Attempts to use both MASK and BAS fields simultaneously are
6580 * CONSTRAINED UNPREDICTABLE; we opt to ignore BAS in this case,
6581 * thus generating a watchpoint for every byte in the masked region.
6583 mask
= extract64(wcr
, 24, 4);
6584 if (mask
== 1 || mask
== 2) {
6585 /* Reserved values of MASK; we must act as if the mask value was
6586 * some non-reserved value, or as if the watchpoint were disabled.
6587 * We choose the latter.
6591 /* Watchpoint covers an aligned area up to 2GB in size */
6593 /* If masked bits in WVR are not zero it's CONSTRAINED UNPREDICTABLE
6594 * whether the watchpoint fires when the unmasked bits match; we opt
6595 * to generate the exceptions.
6599 /* Watchpoint covers bytes defined by the byte address select bits */
6600 int bas
= extract64(wcr
, 5, 8);
6603 if (extract64(wvr
, 2, 1)) {
6604 /* Deprecated case of an only 4-aligned address. BAS[7:4] are
6605 * ignored, and BAS[3:0] define which bytes to watch.
6611 /* This must act as if the watchpoint is disabled */
6615 /* The BAS bits are supposed to be programmed to indicate a contiguous
6616 * range of bytes. Otherwise it is CONSTRAINED UNPREDICTABLE whether
6617 * we fire for each byte in the word/doubleword addressed by the WVR.
6618 * We choose to ignore any non-zero bits after the first range of 1s.
6620 basstart
= ctz32(bas
);
6621 len
= cto32(bas
>> basstart
);
6625 cpu_watchpoint_insert(CPU(cpu
), wvr
, len
, flags
,
6626 &env
->cpu_watchpoint
[n
]);
6629 void hw_watchpoint_update_all(ARMCPU
*cpu
)
6632 CPUARMState
*env
= &cpu
->env
;
6634 /* Completely clear out existing QEMU watchpoints and our array, to
6635 * avoid possible stale entries following migration load.
6637 cpu_watchpoint_remove_all(CPU(cpu
), BP_CPU
);
6638 memset(env
->cpu_watchpoint
, 0, sizeof(env
->cpu_watchpoint
));
6640 for (i
= 0; i
< ARRAY_SIZE(cpu
->env
.cpu_watchpoint
); i
++) {
6641 hw_watchpoint_update(cpu
, i
);
6645 static void dbgwvr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6648 ARMCPU
*cpu
= env_archcpu(env
);
6651 /* Bits [63:49] are hardwired to the value of bit [48]; that is, the
6652 * register reads and behaves as if values written are sign extended.
6653 * Bits [1:0] are RES0.
6655 value
= sextract64(value
, 0, 49) & ~3ULL;
6657 raw_write(env
, ri
, value
);
6658 hw_watchpoint_update(cpu
, i
);
6661 static void dbgwcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6664 ARMCPU
*cpu
= env_archcpu(env
);
6667 raw_write(env
, ri
, value
);
6668 hw_watchpoint_update(cpu
, i
);
6671 void hw_breakpoint_update(ARMCPU
*cpu
, int n
)
6673 CPUARMState
*env
= &cpu
->env
;
6674 uint64_t bvr
= env
->cp15
.dbgbvr
[n
];
6675 uint64_t bcr
= env
->cp15
.dbgbcr
[n
];
6680 if (env
->cpu_breakpoint
[n
]) {
6681 cpu_breakpoint_remove_by_ref(CPU(cpu
), env
->cpu_breakpoint
[n
]);
6682 env
->cpu_breakpoint
[n
] = NULL
;
6685 if (!extract64(bcr
, 0, 1)) {
6686 /* E bit clear : watchpoint disabled */
6690 bt
= extract64(bcr
, 20, 4);
6693 case 4: /* unlinked address mismatch (reserved if AArch64) */
6694 case 5: /* linked address mismatch (reserved if AArch64) */
6695 qemu_log_mask(LOG_UNIMP
,
6696 "arm: address mismatch breakpoint types not implemented\n");
6698 case 0: /* unlinked address match */
6699 case 1: /* linked address match */
6701 /* Bits [63:49] are hardwired to the value of bit [48]; that is,
6702 * we behave as if the register was sign extended. Bits [1:0] are
6703 * RES0. The BAS field is used to allow setting breakpoints on 16
6704 * bit wide instructions; it is CONSTRAINED UNPREDICTABLE whether
6705 * a bp will fire if the addresses covered by the bp and the addresses
6706 * covered by the insn overlap but the insn doesn't start at the
6707 * start of the bp address range. We choose to require the insn and
6708 * the bp to have the same address. The constraints on writing to
6709 * BAS enforced in dbgbcr_write mean we have only four cases:
6710 * 0b0000 => no breakpoint
6711 * 0b0011 => breakpoint on addr
6712 * 0b1100 => breakpoint on addr + 2
6713 * 0b1111 => breakpoint on addr
6714 * See also figure D2-3 in the v8 ARM ARM (DDI0487A.c).
6716 int bas
= extract64(bcr
, 5, 4);
6717 addr
= sextract64(bvr
, 0, 49) & ~3ULL;
6726 case 2: /* unlinked context ID match */
6727 case 8: /* unlinked VMID match (reserved if no EL2) */
6728 case 10: /* unlinked context ID and VMID match (reserved if no EL2) */
6729 qemu_log_mask(LOG_UNIMP
,
6730 "arm: unlinked context breakpoint types not implemented\n");
6732 case 9: /* linked VMID match (reserved if no EL2) */
6733 case 11: /* linked context ID and VMID match (reserved if no EL2) */
6734 case 3: /* linked context ID match */
6736 /* We must generate no events for Linked context matches (unless
6737 * they are linked to by some other bp/wp, which is handled in
6738 * updates for the linking bp/wp). We choose to also generate no events
6739 * for reserved values.
6744 cpu_breakpoint_insert(CPU(cpu
), addr
, flags
, &env
->cpu_breakpoint
[n
]);
6747 void hw_breakpoint_update_all(ARMCPU
*cpu
)
6750 CPUARMState
*env
= &cpu
->env
;
6752 /* Completely clear out existing QEMU breakpoints and our array, to
6753 * avoid possible stale entries following migration load.
6755 cpu_breakpoint_remove_all(CPU(cpu
), BP_CPU
);
6756 memset(env
->cpu_breakpoint
, 0, sizeof(env
->cpu_breakpoint
));
6758 for (i
= 0; i
< ARRAY_SIZE(cpu
->env
.cpu_breakpoint
); i
++) {
6759 hw_breakpoint_update(cpu
, i
);
6763 static void dbgbvr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6766 ARMCPU
*cpu
= env_archcpu(env
);
6769 raw_write(env
, ri
, value
);
6770 hw_breakpoint_update(cpu
, i
);
6773 static void dbgbcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6776 ARMCPU
*cpu
= env_archcpu(env
);
6779 /* BAS[3] is a read-only copy of BAS[2], and BAS[1] a read-only
6782 value
= deposit64(value
, 6, 1, extract64(value
, 5, 1));
6783 value
= deposit64(value
, 8, 1, extract64(value
, 7, 1));
6785 raw_write(env
, ri
, value
);
6786 hw_breakpoint_update(cpu
, i
);
6789 static void define_debug_regs(ARMCPU
*cpu
)
6791 /* Define v7 and v8 architectural debug registers.
6792 * These are just dummy implementations for now.
6795 int wrps
, brps
, ctx_cmps
;
6798 * The Arm ARM says DBGDIDR is optional and deprecated if EL1 cannot
6799 * use AArch32. Given that bit 15 is RES1, if the value is 0 then
6800 * the register must not exist for this cpu.
6802 if (cpu
->isar
.dbgdidr
!= 0) {
6803 ARMCPRegInfo dbgdidr
= {
6804 .name
= "DBGDIDR", .cp
= 14, .crn
= 0, .crm
= 0,
6805 .opc1
= 0, .opc2
= 0,
6806 .access
= PL0_R
, .accessfn
= access_tda
,
6807 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->isar
.dbgdidr
,
6809 define_one_arm_cp_reg(cpu
, &dbgdidr
);
6812 /* Note that all these register fields hold "number of Xs minus 1". */
6813 brps
= arm_num_brps(cpu
);
6814 wrps
= arm_num_wrps(cpu
);
6815 ctx_cmps
= arm_num_ctx_cmps(cpu
);
6817 assert(ctx_cmps
<= brps
);
6819 define_arm_cp_regs(cpu
, debug_cp_reginfo
);
6821 if (arm_feature(&cpu
->env
, ARM_FEATURE_LPAE
)) {
6822 define_arm_cp_regs(cpu
, debug_lpae_cp_reginfo
);
6825 for (i
= 0; i
< brps
; i
++) {
6826 ARMCPRegInfo dbgregs
[] = {
6827 { .name
= "DBGBVR", .state
= ARM_CP_STATE_BOTH
,
6828 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 4,
6829 .access
= PL1_RW
, .accessfn
= access_tda
,
6830 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgbvr
[i
]),
6831 .writefn
= dbgbvr_write
, .raw_writefn
= raw_write
6833 { .name
= "DBGBCR", .state
= ARM_CP_STATE_BOTH
,
6834 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 5,
6835 .access
= PL1_RW
, .accessfn
= access_tda
,
6836 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgbcr
[i
]),
6837 .writefn
= dbgbcr_write
, .raw_writefn
= raw_write
6841 define_arm_cp_regs(cpu
, dbgregs
);
6844 for (i
= 0; i
< wrps
; i
++) {
6845 ARMCPRegInfo dbgregs
[] = {
6846 { .name
= "DBGWVR", .state
= ARM_CP_STATE_BOTH
,
6847 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 6,
6848 .access
= PL1_RW
, .accessfn
= access_tda
,
6849 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgwvr
[i
]),
6850 .writefn
= dbgwvr_write
, .raw_writefn
= raw_write
6852 { .name
= "DBGWCR", .state
= ARM_CP_STATE_BOTH
,
6853 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 7,
6854 .access
= PL1_RW
, .accessfn
= access_tda
,
6855 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgwcr
[i
]),
6856 .writefn
= dbgwcr_write
, .raw_writefn
= raw_write
6860 define_arm_cp_regs(cpu
, dbgregs
);
6864 static void define_pmu_regs(ARMCPU
*cpu
)
6867 * v7 performance monitor control register: same implementor
6868 * field as main ID register, and we implement four counters in
6869 * addition to the cycle count register.
6871 unsigned int i
, pmcrn
= PMCR_NUM_COUNTERS
;
6872 ARMCPRegInfo pmcr
= {
6873 .name
= "PMCR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 0,
6875 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
6876 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcr
),
6877 .accessfn
= pmreg_access
, .writefn
= pmcr_write
,
6878 .raw_writefn
= raw_write
,
6880 ARMCPRegInfo pmcr64
= {
6881 .name
= "PMCR_EL0", .state
= ARM_CP_STATE_AA64
,
6882 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 0,
6883 .access
= PL0_RW
, .accessfn
= pmreg_access
,
6885 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcr
),
6886 .resetvalue
= (cpu
->midr
& 0xff000000) | (pmcrn
<< PMCRN_SHIFT
) |
6888 .writefn
= pmcr_write
, .raw_writefn
= raw_write
,
6890 define_one_arm_cp_reg(cpu
, &pmcr
);
6891 define_one_arm_cp_reg(cpu
, &pmcr64
);
6892 for (i
= 0; i
< pmcrn
; i
++) {
6893 char *pmevcntr_name
= g_strdup_printf("PMEVCNTR%d", i
);
6894 char *pmevcntr_el0_name
= g_strdup_printf("PMEVCNTR%d_EL0", i
);
6895 char *pmevtyper_name
= g_strdup_printf("PMEVTYPER%d", i
);
6896 char *pmevtyper_el0_name
= g_strdup_printf("PMEVTYPER%d_EL0", i
);
6897 ARMCPRegInfo pmev_regs
[] = {
6898 { .name
= pmevcntr_name
, .cp
= 15, .crn
= 14,
6899 .crm
= 8 | (3 & (i
>> 3)), .opc1
= 0, .opc2
= i
& 7,
6900 .access
= PL0_RW
, .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
6901 .readfn
= pmevcntr_readfn
, .writefn
= pmevcntr_writefn
,
6902 .accessfn
= pmreg_access
},
6903 { .name
= pmevcntr_el0_name
, .state
= ARM_CP_STATE_AA64
,
6904 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 8 | (3 & (i
>> 3)),
6905 .opc2
= i
& 7, .access
= PL0_RW
, .accessfn
= pmreg_access
,
6907 .readfn
= pmevcntr_readfn
, .writefn
= pmevcntr_writefn
,
6908 .raw_readfn
= pmevcntr_rawread
,
6909 .raw_writefn
= pmevcntr_rawwrite
},
6910 { .name
= pmevtyper_name
, .cp
= 15, .crn
= 14,
6911 .crm
= 12 | (3 & (i
>> 3)), .opc1
= 0, .opc2
= i
& 7,
6912 .access
= PL0_RW
, .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
6913 .readfn
= pmevtyper_readfn
, .writefn
= pmevtyper_writefn
,
6914 .accessfn
= pmreg_access
},
6915 { .name
= pmevtyper_el0_name
, .state
= ARM_CP_STATE_AA64
,
6916 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 12 | (3 & (i
>> 3)),
6917 .opc2
= i
& 7, .access
= PL0_RW
, .accessfn
= pmreg_access
,
6919 .readfn
= pmevtyper_readfn
, .writefn
= pmevtyper_writefn
,
6920 .raw_writefn
= pmevtyper_rawwrite
},
6923 define_arm_cp_regs(cpu
, pmev_regs
);
6924 g_free(pmevcntr_name
);
6925 g_free(pmevcntr_el0_name
);
6926 g_free(pmevtyper_name
);
6927 g_free(pmevtyper_el0_name
);
6929 if (cpu_isar_feature(aa32_pmu_8_1
, cpu
)) {
6930 ARMCPRegInfo v81_pmu_regs
[] = {
6931 { .name
= "PMCEID2", .state
= ARM_CP_STATE_AA32
,
6932 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 4,
6933 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
6934 .resetvalue
= extract64(cpu
->pmceid0
, 32, 32) },
6935 { .name
= "PMCEID3", .state
= ARM_CP_STATE_AA32
,
6936 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 5,
6937 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
6938 .resetvalue
= extract64(cpu
->pmceid1
, 32, 32) },
6941 define_arm_cp_regs(cpu
, v81_pmu_regs
);
6943 if (cpu_isar_feature(any_pmu_8_4
, cpu
)) {
6944 static const ARMCPRegInfo v84_pmmir
= {
6945 .name
= "PMMIR_EL1", .state
= ARM_CP_STATE_BOTH
,
6946 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 6,
6947 .access
= PL1_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
6950 define_one_arm_cp_reg(cpu
, &v84_pmmir
);
6954 /* We don't know until after realize whether there's a GICv3
6955 * attached, and that is what registers the gicv3 sysregs.
6956 * So we have to fill in the GIC fields in ID_PFR/ID_PFR1_EL1/ID_AA64PFR0_EL1
6959 static uint64_t id_pfr1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6961 ARMCPU
*cpu
= env_archcpu(env
);
6962 uint64_t pfr1
= cpu
->isar
.id_pfr1
;
6964 if (env
->gicv3state
) {
6970 #ifndef CONFIG_USER_ONLY
6971 static uint64_t id_aa64pfr0_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6973 ARMCPU
*cpu
= env_archcpu(env
);
6974 uint64_t pfr0
= cpu
->isar
.id_aa64pfr0
;
6976 if (env
->gicv3state
) {
6983 /* Shared logic between LORID and the rest of the LOR* registers.
6984 * Secure state exclusion has already been dealt with.
6986 static CPAccessResult
access_lor_ns(CPUARMState
*env
,
6987 const ARMCPRegInfo
*ri
, bool isread
)
6989 int el
= arm_current_el(env
);
6991 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_TLOR
)) {
6992 return CP_ACCESS_TRAP_EL2
;
6994 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_TLOR
)) {
6995 return CP_ACCESS_TRAP_EL3
;
6997 return CP_ACCESS_OK
;
7000 static CPAccessResult
access_lor_other(CPUARMState
*env
,
7001 const ARMCPRegInfo
*ri
, bool isread
)
7003 if (arm_is_secure_below_el3(env
)) {
7004 /* Access denied in secure mode. */
7005 return CP_ACCESS_TRAP
;
7007 return access_lor_ns(env
, ri
, isread
);
7011 * A trivial implementation of ARMv8.1-LOR leaves all of these
7012 * registers fixed at 0, which indicates that there are zero
7013 * supported Limited Ordering regions.
7015 static const ARMCPRegInfo lor_reginfo
[] = {
7016 { .name
= "LORSA_EL1", .state
= ARM_CP_STATE_AA64
,
7017 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 0,
7018 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7019 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7020 { .name
= "LOREA_EL1", .state
= ARM_CP_STATE_AA64
,
7021 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 1,
7022 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7023 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7024 { .name
= "LORN_EL1", .state
= ARM_CP_STATE_AA64
,
7025 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 2,
7026 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7027 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7028 { .name
= "LORC_EL1", .state
= ARM_CP_STATE_AA64
,
7029 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 3,
7030 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7031 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7032 { .name
= "LORID_EL1", .state
= ARM_CP_STATE_AA64
,
7033 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 7,
7034 .access
= PL1_R
, .accessfn
= access_lor_ns
,
7035 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7039 #ifdef TARGET_AARCH64
7040 static CPAccessResult
access_pauth(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7043 int el
= arm_current_el(env
);
7046 arm_feature(env
, ARM_FEATURE_EL2
) &&
7047 !(arm_hcr_el2_eff(env
) & HCR_APK
)) {
7048 return CP_ACCESS_TRAP_EL2
;
7051 arm_feature(env
, ARM_FEATURE_EL3
) &&
7052 !(env
->cp15
.scr_el3
& SCR_APK
)) {
7053 return CP_ACCESS_TRAP_EL3
;
7055 return CP_ACCESS_OK
;
7058 static const ARMCPRegInfo pauth_reginfo
[] = {
7059 { .name
= "APDAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7060 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 0,
7061 .access
= PL1_RW
, .accessfn
= access_pauth
,
7062 .fieldoffset
= offsetof(CPUARMState
, keys
.apda
.lo
) },
7063 { .name
= "APDAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7064 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 1,
7065 .access
= PL1_RW
, .accessfn
= access_pauth
,
7066 .fieldoffset
= offsetof(CPUARMState
, keys
.apda
.hi
) },
7067 { .name
= "APDBKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7068 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 2,
7069 .access
= PL1_RW
, .accessfn
= access_pauth
,
7070 .fieldoffset
= offsetof(CPUARMState
, keys
.apdb
.lo
) },
7071 { .name
= "APDBKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7072 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 3,
7073 .access
= PL1_RW
, .accessfn
= access_pauth
,
7074 .fieldoffset
= offsetof(CPUARMState
, keys
.apdb
.hi
) },
7075 { .name
= "APGAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7076 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 3, .opc2
= 0,
7077 .access
= PL1_RW
, .accessfn
= access_pauth
,
7078 .fieldoffset
= offsetof(CPUARMState
, keys
.apga
.lo
) },
7079 { .name
= "APGAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7080 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 3, .opc2
= 1,
7081 .access
= PL1_RW
, .accessfn
= access_pauth
,
7082 .fieldoffset
= offsetof(CPUARMState
, keys
.apga
.hi
) },
7083 { .name
= "APIAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7084 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 0,
7085 .access
= PL1_RW
, .accessfn
= access_pauth
,
7086 .fieldoffset
= offsetof(CPUARMState
, keys
.apia
.lo
) },
7087 { .name
= "APIAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7088 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 1,
7089 .access
= PL1_RW
, .accessfn
= access_pauth
,
7090 .fieldoffset
= offsetof(CPUARMState
, keys
.apia
.hi
) },
7091 { .name
= "APIBKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7092 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 2,
7093 .access
= PL1_RW
, .accessfn
= access_pauth
,
7094 .fieldoffset
= offsetof(CPUARMState
, keys
.apib
.lo
) },
7095 { .name
= "APIBKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7096 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 3,
7097 .access
= PL1_RW
, .accessfn
= access_pauth
,
7098 .fieldoffset
= offsetof(CPUARMState
, keys
.apib
.hi
) },
7102 static const ARMCPRegInfo tlbirange_reginfo
[] = {
7103 { .name
= "TLBI_RVAE1IS", .state
= ARM_CP_STATE_AA64
,
7104 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 1,
7105 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7106 .writefn
= tlbi_aa64_rvae1is_write
},
7107 { .name
= "TLBI_RVAAE1IS", .state
= ARM_CP_STATE_AA64
,
7108 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 3,
7109 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7110 .writefn
= tlbi_aa64_rvae1is_write
},
7111 { .name
= "TLBI_RVALE1IS", .state
= ARM_CP_STATE_AA64
,
7112 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 5,
7113 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7114 .writefn
= tlbi_aa64_rvae1is_write
},
7115 { .name
= "TLBI_RVAALE1IS", .state
= ARM_CP_STATE_AA64
,
7116 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 7,
7117 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7118 .writefn
= tlbi_aa64_rvae1is_write
},
7119 { .name
= "TLBI_RVAE1OS", .state
= ARM_CP_STATE_AA64
,
7120 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
7121 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7122 .writefn
= tlbi_aa64_rvae1is_write
},
7123 { .name
= "TLBI_RVAAE1OS", .state
= ARM_CP_STATE_AA64
,
7124 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 3,
7125 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7126 .writefn
= tlbi_aa64_rvae1is_write
},
7127 { .name
= "TLBI_RVALE1OS", .state
= ARM_CP_STATE_AA64
,
7128 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 5,
7129 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7130 .writefn
= tlbi_aa64_rvae1is_write
},
7131 { .name
= "TLBI_RVAALE1OS", .state
= ARM_CP_STATE_AA64
,
7132 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 7,
7133 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7134 .writefn
= tlbi_aa64_rvae1is_write
},
7135 { .name
= "TLBI_RVAE1", .state
= ARM_CP_STATE_AA64
,
7136 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
7137 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7138 .writefn
= tlbi_aa64_rvae1_write
},
7139 { .name
= "TLBI_RVAAE1", .state
= ARM_CP_STATE_AA64
,
7140 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 3,
7141 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7142 .writefn
= tlbi_aa64_rvae1_write
},
7143 { .name
= "TLBI_RVALE1", .state
= ARM_CP_STATE_AA64
,
7144 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 5,
7145 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7146 .writefn
= tlbi_aa64_rvae1_write
},
7147 { .name
= "TLBI_RVAALE1", .state
= ARM_CP_STATE_AA64
,
7148 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 7,
7149 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7150 .writefn
= tlbi_aa64_rvae1_write
},
7151 { .name
= "TLBI_RIPAS2E1IS", .state
= ARM_CP_STATE_AA64
,
7152 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 2,
7153 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7154 { .name
= "TLBI_RIPAS2LE1IS", .state
= ARM_CP_STATE_AA64
,
7155 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 6,
7156 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7157 { .name
= "TLBI_RVAE2IS", .state
= ARM_CP_STATE_AA64
,
7158 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 2, .opc2
= 1,
7159 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7160 .writefn
= tlbi_aa64_rvae2is_write
},
7161 { .name
= "TLBI_RVALE2IS", .state
= ARM_CP_STATE_AA64
,
7162 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 2, .opc2
= 5,
7163 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7164 .writefn
= tlbi_aa64_rvae2is_write
},
7165 { .name
= "TLBI_RIPAS2E1", .state
= ARM_CP_STATE_AA64
,
7166 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 2,
7167 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7168 { .name
= "TLBI_RIPAS2LE1", .state
= ARM_CP_STATE_AA64
,
7169 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 6,
7170 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7171 { .name
= "TLBI_RVAE2OS", .state
= ARM_CP_STATE_AA64
,
7172 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 5, .opc2
= 1,
7173 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7174 .writefn
= tlbi_aa64_rvae2is_write
},
7175 { .name
= "TLBI_RVALE2OS", .state
= ARM_CP_STATE_AA64
,
7176 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 5, .opc2
= 5,
7177 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7178 .writefn
= tlbi_aa64_rvae2is_write
},
7179 { .name
= "TLBI_RVAE2", .state
= ARM_CP_STATE_AA64
,
7180 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 6, .opc2
= 1,
7181 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7182 .writefn
= tlbi_aa64_rvae2_write
},
7183 { .name
= "TLBI_RVALE2", .state
= ARM_CP_STATE_AA64
,
7184 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 6, .opc2
= 5,
7185 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7186 .writefn
= tlbi_aa64_rvae2_write
},
7187 { .name
= "TLBI_RVAE3IS", .state
= ARM_CP_STATE_AA64
,
7188 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 2, .opc2
= 1,
7189 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7190 .writefn
= tlbi_aa64_rvae3is_write
},
7191 { .name
= "TLBI_RVALE3IS", .state
= ARM_CP_STATE_AA64
,
7192 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 2, .opc2
= 5,
7193 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7194 .writefn
= tlbi_aa64_rvae3is_write
},
7195 { .name
= "TLBI_RVAE3OS", .state
= ARM_CP_STATE_AA64
,
7196 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 5, .opc2
= 1,
7197 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7198 .writefn
= tlbi_aa64_rvae3is_write
},
7199 { .name
= "TLBI_RVALE3OS", .state
= ARM_CP_STATE_AA64
,
7200 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 5, .opc2
= 5,
7201 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7202 .writefn
= tlbi_aa64_rvae3is_write
},
7203 { .name
= "TLBI_RVAE3", .state
= ARM_CP_STATE_AA64
,
7204 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 6, .opc2
= 1,
7205 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7206 .writefn
= tlbi_aa64_rvae3_write
},
7207 { .name
= "TLBI_RVALE3", .state
= ARM_CP_STATE_AA64
,
7208 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 6, .opc2
= 5,
7209 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7210 .writefn
= tlbi_aa64_rvae3_write
},
7214 static const ARMCPRegInfo tlbios_reginfo
[] = {
7215 { .name
= "TLBI_VMALLE1OS", .state
= ARM_CP_STATE_AA64
,
7216 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 0,
7217 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7218 .writefn
= tlbi_aa64_vmalle1is_write
},
7219 { .name
= "TLBI_ASIDE1OS", .state
= ARM_CP_STATE_AA64
,
7220 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 2,
7221 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7222 .writefn
= tlbi_aa64_vmalle1is_write
},
7223 { .name
= "TLBI_ALLE2OS", .state
= ARM_CP_STATE_AA64
,
7224 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 0,
7225 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7226 .writefn
= tlbi_aa64_alle2is_write
},
7227 { .name
= "TLBI_ALLE1OS", .state
= ARM_CP_STATE_AA64
,
7228 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 4,
7229 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7230 .writefn
= tlbi_aa64_alle1is_write
},
7231 { .name
= "TLBI_VMALLS12E1OS", .state
= ARM_CP_STATE_AA64
,
7232 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 6,
7233 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7234 .writefn
= tlbi_aa64_alle1is_write
},
7235 { .name
= "TLBI_IPAS2E1OS", .state
= ARM_CP_STATE_AA64
,
7236 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 0,
7237 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7238 { .name
= "TLBI_RIPAS2E1OS", .state
= ARM_CP_STATE_AA64
,
7239 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 3,
7240 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7241 { .name
= "TLBI_IPAS2LE1OS", .state
= ARM_CP_STATE_AA64
,
7242 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 4,
7243 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7244 { .name
= "TLBI_RIPAS2LE1OS", .state
= ARM_CP_STATE_AA64
,
7245 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 7,
7246 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7247 { .name
= "TLBI_ALLE3OS", .state
= ARM_CP_STATE_AA64
,
7248 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 0,
7249 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7250 .writefn
= tlbi_aa64_alle3is_write
},
7254 static uint64_t rndr_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7259 /* Success sets NZCV = 0000. */
7260 env
->NF
= env
->CF
= env
->VF
= 0, env
->ZF
= 1;
7262 if (qemu_guest_getrandom(&ret
, sizeof(ret
), &err
) < 0) {
7264 * ??? Failed, for unknown reasons in the crypto subsystem.
7265 * The best we can do is log the reason and return the
7266 * timed-out indication to the guest. There is no reason
7267 * we know to expect this failure to be transitory, so the
7268 * guest may well hang retrying the operation.
7270 qemu_log_mask(LOG_UNIMP
, "%s: Crypto failure: %s",
7271 ri
->name
, error_get_pretty(err
));
7274 env
->ZF
= 0; /* NZCF = 0100 */
7280 /* We do not support re-seeding, so the two registers operate the same. */
7281 static const ARMCPRegInfo rndr_reginfo
[] = {
7282 { .name
= "RNDR", .state
= ARM_CP_STATE_AA64
,
7283 .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
| ARM_CP_IO
,
7284 .opc0
= 3, .opc1
= 3, .crn
= 2, .crm
= 4, .opc2
= 0,
7285 .access
= PL0_R
, .readfn
= rndr_readfn
},
7286 { .name
= "RNDRRS", .state
= ARM_CP_STATE_AA64
,
7287 .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
| ARM_CP_IO
,
7288 .opc0
= 3, .opc1
= 3, .crn
= 2, .crm
= 4, .opc2
= 1,
7289 .access
= PL0_R
, .readfn
= rndr_readfn
},
7293 #ifndef CONFIG_USER_ONLY
7294 static void dccvap_writefn(CPUARMState
*env
, const ARMCPRegInfo
*opaque
,
7297 ARMCPU
*cpu
= env_archcpu(env
);
7298 /* CTR_EL0 System register -> DminLine, bits [19:16] */
7299 uint64_t dline_size
= 4 << ((cpu
->ctr
>> 16) & 0xF);
7300 uint64_t vaddr_in
= (uint64_t) value
;
7301 uint64_t vaddr
= vaddr_in
& ~(dline_size
- 1);
7303 int mem_idx
= cpu_mmu_index(env
, false);
7305 /* This won't be crossing page boundaries */
7306 haddr
= probe_read(env
, vaddr
, dline_size
, mem_idx
, GETPC());
7312 /* RCU lock is already being held */
7313 mr
= memory_region_from_host(haddr
, &offset
);
7316 memory_region_writeback(mr
, offset
, dline_size
);
7321 static const ARMCPRegInfo dcpop_reg
[] = {
7322 { .name
= "DC_CVAP", .state
= ARM_CP_STATE_AA64
,
7323 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 1,
7324 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
,
7325 .accessfn
= aa64_cacheop_poc_access
, .writefn
= dccvap_writefn
},
7329 static const ARMCPRegInfo dcpodp_reg
[] = {
7330 { .name
= "DC_CVADP", .state
= ARM_CP_STATE_AA64
,
7331 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 1,
7332 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
,
7333 .accessfn
= aa64_cacheop_poc_access
, .writefn
= dccvap_writefn
},
7336 #endif /*CONFIG_USER_ONLY*/
7338 static CPAccessResult
access_aa64_tid5(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7341 if ((arm_current_el(env
) < 2) && (arm_hcr_el2_eff(env
) & HCR_TID5
)) {
7342 return CP_ACCESS_TRAP_EL2
;
7345 return CP_ACCESS_OK
;
7348 static CPAccessResult
access_mte(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7351 int el
= arm_current_el(env
);
7353 if (el
< 2 && arm_feature(env
, ARM_FEATURE_EL2
)) {
7354 uint64_t hcr
= arm_hcr_el2_eff(env
);
7355 if (!(hcr
& HCR_ATA
) && (!(hcr
& HCR_E2H
) || !(hcr
& HCR_TGE
))) {
7356 return CP_ACCESS_TRAP_EL2
;
7360 arm_feature(env
, ARM_FEATURE_EL3
) &&
7361 !(env
->cp15
.scr_el3
& SCR_ATA
)) {
7362 return CP_ACCESS_TRAP_EL3
;
7364 return CP_ACCESS_OK
;
7367 static uint64_t tco_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7369 return env
->pstate
& PSTATE_TCO
;
7372 static void tco_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
7374 env
->pstate
= (env
->pstate
& ~PSTATE_TCO
) | (val
& PSTATE_TCO
);
7377 static const ARMCPRegInfo mte_reginfo
[] = {
7378 { .name
= "TFSRE0_EL1", .state
= ARM_CP_STATE_AA64
,
7379 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 6, .opc2
= 1,
7380 .access
= PL1_RW
, .accessfn
= access_mte
,
7381 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[0]) },
7382 { .name
= "TFSR_EL1", .state
= ARM_CP_STATE_AA64
,
7383 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 6, .opc2
= 0,
7384 .access
= PL1_RW
, .accessfn
= access_mte
,
7385 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[1]) },
7386 { .name
= "TFSR_EL2", .state
= ARM_CP_STATE_AA64
,
7387 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 6, .opc2
= 0,
7388 .access
= PL2_RW
, .accessfn
= access_mte
,
7389 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[2]) },
7390 { .name
= "TFSR_EL3", .state
= ARM_CP_STATE_AA64
,
7391 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 6, .opc2
= 0,
7393 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[3]) },
7394 { .name
= "RGSR_EL1", .state
= ARM_CP_STATE_AA64
,
7395 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 5,
7396 .access
= PL1_RW
, .accessfn
= access_mte
,
7397 .fieldoffset
= offsetof(CPUARMState
, cp15
.rgsr_el1
) },
7398 { .name
= "GCR_EL1", .state
= ARM_CP_STATE_AA64
,
7399 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 6,
7400 .access
= PL1_RW
, .accessfn
= access_mte
,
7401 .fieldoffset
= offsetof(CPUARMState
, cp15
.gcr_el1
) },
7402 { .name
= "GMID_EL1", .state
= ARM_CP_STATE_AA64
,
7403 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 4,
7404 .access
= PL1_R
, .accessfn
= access_aa64_tid5
,
7405 .type
= ARM_CP_CONST
, .resetvalue
= GMID_EL1_BS
},
7406 { .name
= "TCO", .state
= ARM_CP_STATE_AA64
,
7407 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 7,
7408 .type
= ARM_CP_NO_RAW
,
7409 .access
= PL0_RW
, .readfn
= tco_read
, .writefn
= tco_write
},
7410 { .name
= "DC_IGVAC", .state
= ARM_CP_STATE_AA64
,
7411 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 3,
7412 .type
= ARM_CP_NOP
, .access
= PL1_W
,
7413 .accessfn
= aa64_cacheop_poc_access
},
7414 { .name
= "DC_IGSW", .state
= ARM_CP_STATE_AA64
,
7415 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 4,
7416 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7417 { .name
= "DC_IGDVAC", .state
= ARM_CP_STATE_AA64
,
7418 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 5,
7419 .type
= ARM_CP_NOP
, .access
= PL1_W
,
7420 .accessfn
= aa64_cacheop_poc_access
},
7421 { .name
= "DC_IGDSW", .state
= ARM_CP_STATE_AA64
,
7422 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 6,
7423 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7424 { .name
= "DC_CGSW", .state
= ARM_CP_STATE_AA64
,
7425 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 4,
7426 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7427 { .name
= "DC_CGDSW", .state
= ARM_CP_STATE_AA64
,
7428 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 6,
7429 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7430 { .name
= "DC_CIGSW", .state
= ARM_CP_STATE_AA64
,
7431 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 4,
7432 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7433 { .name
= "DC_CIGDSW", .state
= ARM_CP_STATE_AA64
,
7434 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 6,
7435 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7439 static const ARMCPRegInfo mte_tco_ro_reginfo
[] = {
7440 { .name
= "TCO", .state
= ARM_CP_STATE_AA64
,
7441 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 7,
7442 .type
= ARM_CP_CONST
, .access
= PL0_RW
, },
7446 static const ARMCPRegInfo mte_el0_cacheop_reginfo
[] = {
7447 { .name
= "DC_CGVAC", .state
= ARM_CP_STATE_AA64
,
7448 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 3,
7449 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7450 .accessfn
= aa64_cacheop_poc_access
},
7451 { .name
= "DC_CGDVAC", .state
= ARM_CP_STATE_AA64
,
7452 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 5,
7453 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7454 .accessfn
= aa64_cacheop_poc_access
},
7455 { .name
= "DC_CGVAP", .state
= ARM_CP_STATE_AA64
,
7456 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 3,
7457 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7458 .accessfn
= aa64_cacheop_poc_access
},
7459 { .name
= "DC_CGDVAP", .state
= ARM_CP_STATE_AA64
,
7460 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 5,
7461 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7462 .accessfn
= aa64_cacheop_poc_access
},
7463 { .name
= "DC_CGVADP", .state
= ARM_CP_STATE_AA64
,
7464 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 3,
7465 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7466 .accessfn
= aa64_cacheop_poc_access
},
7467 { .name
= "DC_CGDVADP", .state
= ARM_CP_STATE_AA64
,
7468 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 5,
7469 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7470 .accessfn
= aa64_cacheop_poc_access
},
7471 { .name
= "DC_CIGVAC", .state
= ARM_CP_STATE_AA64
,
7472 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 3,
7473 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7474 .accessfn
= aa64_cacheop_poc_access
},
7475 { .name
= "DC_CIGDVAC", .state
= ARM_CP_STATE_AA64
,
7476 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 5,
7477 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7478 .accessfn
= aa64_cacheop_poc_access
},
7479 { .name
= "DC_GVA", .state
= ARM_CP_STATE_AA64
,
7480 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 3,
7481 .access
= PL0_W
, .type
= ARM_CP_DC_GVA
,
7482 #ifndef CONFIG_USER_ONLY
7483 /* Avoid overhead of an access check that always passes in user-mode */
7484 .accessfn
= aa64_zva_access
,
7487 { .name
= "DC_GZVA", .state
= ARM_CP_STATE_AA64
,
7488 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 4,
7489 .access
= PL0_W
, .type
= ARM_CP_DC_GZVA
,
7490 #ifndef CONFIG_USER_ONLY
7491 /* Avoid overhead of an access check that always passes in user-mode */
7492 .accessfn
= aa64_zva_access
,
7500 static CPAccessResult
access_predinv(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7503 int el
= arm_current_el(env
);
7506 uint64_t sctlr
= arm_sctlr(env
, el
);
7507 if (!(sctlr
& SCTLR_EnRCTX
)) {
7508 return CP_ACCESS_TRAP
;
7510 } else if (el
== 1) {
7511 uint64_t hcr
= arm_hcr_el2_eff(env
);
7513 return CP_ACCESS_TRAP_EL2
;
7516 return CP_ACCESS_OK
;
7519 static const ARMCPRegInfo predinv_reginfo
[] = {
7520 { .name
= "CFP_RCTX", .state
= ARM_CP_STATE_AA64
,
7521 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 4,
7522 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7523 { .name
= "DVP_RCTX", .state
= ARM_CP_STATE_AA64
,
7524 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 5,
7525 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7526 { .name
= "CPP_RCTX", .state
= ARM_CP_STATE_AA64
,
7527 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 7,
7528 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7530 * Note the AArch32 opcodes have a different OPC1.
7532 { .name
= "CFPRCTX", .state
= ARM_CP_STATE_AA32
,
7533 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 4,
7534 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7535 { .name
= "DVPRCTX", .state
= ARM_CP_STATE_AA32
,
7536 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 5,
7537 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7538 { .name
= "CPPRCTX", .state
= ARM_CP_STATE_AA32
,
7539 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 7,
7540 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7544 static uint64_t ccsidr2_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7546 /* Read the high 32 bits of the current CCSIDR */
7547 return extract64(ccsidr_read(env
, ri
), 32, 32);
7550 static const ARMCPRegInfo ccsidr2_reginfo
[] = {
7551 { .name
= "CCSIDR2", .state
= ARM_CP_STATE_BOTH
,
7552 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 2,
7554 .accessfn
= access_aa64_tid2
,
7555 .readfn
= ccsidr2_read
, .type
= ARM_CP_NO_RAW
},
7559 static CPAccessResult
access_aa64_tid3(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7562 if ((arm_current_el(env
) < 2) && (arm_hcr_el2_eff(env
) & HCR_TID3
)) {
7563 return CP_ACCESS_TRAP_EL2
;
7566 return CP_ACCESS_OK
;
7569 static CPAccessResult
access_aa32_tid3(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7572 if (arm_feature(env
, ARM_FEATURE_V8
)) {
7573 return access_aa64_tid3(env
, ri
, isread
);
7576 return CP_ACCESS_OK
;
7579 static CPAccessResult
access_jazelle(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7582 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID0
)) {
7583 return CP_ACCESS_TRAP_EL2
;
7586 return CP_ACCESS_OK
;
7589 static const ARMCPRegInfo jazelle_regs
[] = {
7591 .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 7, .opc2
= 0,
7592 .access
= PL1_R
, .accessfn
= access_jazelle
,
7593 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7595 .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 7, .opc2
= 0,
7596 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7598 .cp
= 14, .crn
= 2, .crm
= 0, .opc1
= 7, .opc2
= 0,
7599 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7603 static const ARMCPRegInfo vhe_reginfo
[] = {
7604 { .name
= "CONTEXTIDR_EL2", .state
= ARM_CP_STATE_AA64
,
7605 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 1,
7607 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[2]) },
7608 { .name
= "TTBR1_EL2", .state
= ARM_CP_STATE_AA64
,
7609 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 1,
7610 .access
= PL2_RW
, .writefn
= vmsa_tcr_ttbr_el2_write
,
7611 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr1_el
[2]) },
7612 #ifndef CONFIG_USER_ONLY
7613 { .name
= "CNTHV_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
7614 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 2,
7616 offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYPVIRT
].cval
),
7617 .type
= ARM_CP_IO
, .access
= PL2_RW
,
7618 .writefn
= gt_hv_cval_write
, .raw_writefn
= raw_write
},
7619 { .name
= "CNTHV_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
7620 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 0,
7621 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL2_RW
,
7622 .resetfn
= gt_hv_timer_reset
,
7623 .readfn
= gt_hv_tval_read
, .writefn
= gt_hv_tval_write
},
7624 { .name
= "CNTHV_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
7626 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 1,
7628 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYPVIRT
].ctl
),
7629 .writefn
= gt_hv_ctl_write
, .raw_writefn
= raw_write
},
7630 { .name
= "CNTP_CTL_EL02", .state
= ARM_CP_STATE_AA64
,
7631 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 1,
7632 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7633 .access
= PL2_RW
, .accessfn
= e2h_access
,
7634 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
7635 .writefn
= gt_phys_ctl_write
, .raw_writefn
= raw_write
},
7636 { .name
= "CNTV_CTL_EL02", .state
= ARM_CP_STATE_AA64
,
7637 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 1,
7638 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7639 .access
= PL2_RW
, .accessfn
= e2h_access
,
7640 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
7641 .writefn
= gt_virt_ctl_write
, .raw_writefn
= raw_write
},
7642 { .name
= "CNTP_TVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7643 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 0,
7644 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
| ARM_CP_ALIAS
,
7645 .access
= PL2_RW
, .accessfn
= e2h_access
,
7646 .readfn
= gt_phys_tval_read
, .writefn
= gt_phys_tval_write
},
7647 { .name
= "CNTV_TVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7648 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 0,
7649 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
| ARM_CP_ALIAS
,
7650 .access
= PL2_RW
, .accessfn
= e2h_access
,
7651 .readfn
= gt_virt_tval_read
, .writefn
= gt_virt_tval_write
},
7652 { .name
= "CNTP_CVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7653 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 2,
7654 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7655 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
7656 .access
= PL2_RW
, .accessfn
= e2h_access
,
7657 .writefn
= gt_phys_cval_write
, .raw_writefn
= raw_write
},
7658 { .name
= "CNTV_CVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7659 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 2,
7660 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7661 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
7662 .access
= PL2_RW
, .accessfn
= e2h_access
,
7663 .writefn
= gt_virt_cval_write
, .raw_writefn
= raw_write
},
7668 #ifndef CONFIG_USER_ONLY
7669 static const ARMCPRegInfo ats1e1_reginfo
[] = {
7670 { .name
= "AT_S1E1R", .state
= ARM_CP_STATE_AA64
,
7671 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 0,
7672 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7673 .writefn
= ats_write64
},
7674 { .name
= "AT_S1E1W", .state
= ARM_CP_STATE_AA64
,
7675 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 1,
7676 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7677 .writefn
= ats_write64
},
7681 static const ARMCPRegInfo ats1cp_reginfo
[] = {
7682 { .name
= "ATS1CPRP",
7683 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 0,
7684 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7685 .writefn
= ats_write
},
7686 { .name
= "ATS1CPWP",
7687 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 1,
7688 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7689 .writefn
= ats_write
},
7695 * ACTLR2 and HACTLR2 map to ACTLR_EL1[63:32] and
7696 * ACTLR_EL2[63:32]. They exist only if the ID_MMFR4.AC2 field
7697 * is non-zero, which is never for ARMv7, optionally in ARMv8
7698 * and mandatorily for ARMv8.2 and up.
7699 * ACTLR2 is banked for S and NS if EL3 is AArch32. Since QEMU's
7700 * implementation is RAZ/WI we can ignore this detail, as we
7703 static const ARMCPRegInfo actlr2_hactlr2_reginfo
[] = {
7704 { .name
= "ACTLR2", .state
= ARM_CP_STATE_AA32
,
7705 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 3,
7706 .access
= PL1_RW
, .accessfn
= access_tacr
,
7707 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7708 { .name
= "HACTLR2", .state
= ARM_CP_STATE_AA32
,
7709 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 3,
7710 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
7715 void register_cp_regs_for_features(ARMCPU
*cpu
)
7717 /* Register all the coprocessor registers based on feature bits */
7718 CPUARMState
*env
= &cpu
->env
;
7719 if (arm_feature(env
, ARM_FEATURE_M
)) {
7720 /* M profile has no coprocessor registers */
7724 define_arm_cp_regs(cpu
, cp_reginfo
);
7725 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
7726 /* Must go early as it is full of wildcards that may be
7727 * overridden by later definitions.
7729 define_arm_cp_regs(cpu
, not_v8_cp_reginfo
);
7732 if (arm_feature(env
, ARM_FEATURE_V6
)) {
7733 /* The ID registers all have impdef reset values */
7734 ARMCPRegInfo v6_idregs
[] = {
7735 { .name
= "ID_PFR0", .state
= ARM_CP_STATE_BOTH
,
7736 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 0,
7737 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7738 .accessfn
= access_aa32_tid3
,
7739 .resetvalue
= cpu
->isar
.id_pfr0
},
7740 /* ID_PFR1 is not a plain ARM_CP_CONST because we don't know
7741 * the value of the GIC field until after we define these regs.
7743 { .name
= "ID_PFR1", .state
= ARM_CP_STATE_BOTH
,
7744 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 1,
7745 .access
= PL1_R
, .type
= ARM_CP_NO_RAW
,
7746 .accessfn
= access_aa32_tid3
,
7747 .readfn
= id_pfr1_read
,
7748 .writefn
= arm_cp_write_ignore
},
7749 { .name
= "ID_DFR0", .state
= ARM_CP_STATE_BOTH
,
7750 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 2,
7751 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7752 .accessfn
= access_aa32_tid3
,
7753 .resetvalue
= cpu
->isar
.id_dfr0
},
7754 { .name
= "ID_AFR0", .state
= ARM_CP_STATE_BOTH
,
7755 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 3,
7756 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7757 .accessfn
= access_aa32_tid3
,
7758 .resetvalue
= cpu
->id_afr0
},
7759 { .name
= "ID_MMFR0", .state
= ARM_CP_STATE_BOTH
,
7760 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 4,
7761 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7762 .accessfn
= access_aa32_tid3
,
7763 .resetvalue
= cpu
->isar
.id_mmfr0
},
7764 { .name
= "ID_MMFR1", .state
= ARM_CP_STATE_BOTH
,
7765 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 5,
7766 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7767 .accessfn
= access_aa32_tid3
,
7768 .resetvalue
= cpu
->isar
.id_mmfr1
},
7769 { .name
= "ID_MMFR2", .state
= ARM_CP_STATE_BOTH
,
7770 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 6,
7771 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7772 .accessfn
= access_aa32_tid3
,
7773 .resetvalue
= cpu
->isar
.id_mmfr2
},
7774 { .name
= "ID_MMFR3", .state
= ARM_CP_STATE_BOTH
,
7775 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 7,
7776 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7777 .accessfn
= access_aa32_tid3
,
7778 .resetvalue
= cpu
->isar
.id_mmfr3
},
7779 { .name
= "ID_ISAR0", .state
= ARM_CP_STATE_BOTH
,
7780 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 0,
7781 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7782 .accessfn
= access_aa32_tid3
,
7783 .resetvalue
= cpu
->isar
.id_isar0
},
7784 { .name
= "ID_ISAR1", .state
= ARM_CP_STATE_BOTH
,
7785 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 1,
7786 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7787 .accessfn
= access_aa32_tid3
,
7788 .resetvalue
= cpu
->isar
.id_isar1
},
7789 { .name
= "ID_ISAR2", .state
= ARM_CP_STATE_BOTH
,
7790 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 2,
7791 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7792 .accessfn
= access_aa32_tid3
,
7793 .resetvalue
= cpu
->isar
.id_isar2
},
7794 { .name
= "ID_ISAR3", .state
= ARM_CP_STATE_BOTH
,
7795 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 3,
7796 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7797 .accessfn
= access_aa32_tid3
,
7798 .resetvalue
= cpu
->isar
.id_isar3
},
7799 { .name
= "ID_ISAR4", .state
= ARM_CP_STATE_BOTH
,
7800 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 4,
7801 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7802 .accessfn
= access_aa32_tid3
,
7803 .resetvalue
= cpu
->isar
.id_isar4
},
7804 { .name
= "ID_ISAR5", .state
= ARM_CP_STATE_BOTH
,
7805 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 5,
7806 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7807 .accessfn
= access_aa32_tid3
,
7808 .resetvalue
= cpu
->isar
.id_isar5
},
7809 { .name
= "ID_MMFR4", .state
= ARM_CP_STATE_BOTH
,
7810 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 6,
7811 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7812 .accessfn
= access_aa32_tid3
,
7813 .resetvalue
= cpu
->isar
.id_mmfr4
},
7814 { .name
= "ID_ISAR6", .state
= ARM_CP_STATE_BOTH
,
7815 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 7,
7816 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7817 .accessfn
= access_aa32_tid3
,
7818 .resetvalue
= cpu
->isar
.id_isar6
},
7821 define_arm_cp_regs(cpu
, v6_idregs
);
7822 define_arm_cp_regs(cpu
, v6_cp_reginfo
);
7824 define_arm_cp_regs(cpu
, not_v6_cp_reginfo
);
7826 if (arm_feature(env
, ARM_FEATURE_V6K
)) {
7827 define_arm_cp_regs(cpu
, v6k_cp_reginfo
);
7829 if (arm_feature(env
, ARM_FEATURE_V7MP
) &&
7830 !arm_feature(env
, ARM_FEATURE_PMSA
)) {
7831 define_arm_cp_regs(cpu
, v7mp_cp_reginfo
);
7833 if (arm_feature(env
, ARM_FEATURE_V7VE
)) {
7834 define_arm_cp_regs(cpu
, pmovsset_cp_reginfo
);
7836 if (arm_feature(env
, ARM_FEATURE_V7
)) {
7837 ARMCPRegInfo clidr
= {
7838 .name
= "CLIDR", .state
= ARM_CP_STATE_BOTH
,
7839 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 1,
7840 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7841 .accessfn
= access_aa64_tid2
,
7842 .resetvalue
= cpu
->clidr
7844 define_one_arm_cp_reg(cpu
, &clidr
);
7845 define_arm_cp_regs(cpu
, v7_cp_reginfo
);
7846 define_debug_regs(cpu
);
7847 define_pmu_regs(cpu
);
7849 define_arm_cp_regs(cpu
, not_v7_cp_reginfo
);
7851 if (arm_feature(env
, ARM_FEATURE_V8
)) {
7852 /* AArch64 ID registers, which all have impdef reset values.
7853 * Note that within the ID register ranges the unused slots
7854 * must all RAZ, not UNDEF; future architecture versions may
7855 * define new registers here.
7857 ARMCPRegInfo v8_idregs
[] = {
7859 * ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST in system
7860 * emulation because we don't know the right value for the
7861 * GIC field until after we define these regs.
7863 { .name
= "ID_AA64PFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7864 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 0,
7866 #ifdef CONFIG_USER_ONLY
7867 .type
= ARM_CP_CONST
,
7868 .resetvalue
= cpu
->isar
.id_aa64pfr0
7870 .type
= ARM_CP_NO_RAW
,
7871 .accessfn
= access_aa64_tid3
,
7872 .readfn
= id_aa64pfr0_read
,
7873 .writefn
= arm_cp_write_ignore
7876 { .name
= "ID_AA64PFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7877 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 1,
7878 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7879 .accessfn
= access_aa64_tid3
,
7880 .resetvalue
= cpu
->isar
.id_aa64pfr1
},
7881 { .name
= "ID_AA64PFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7882 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 2,
7883 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7884 .accessfn
= access_aa64_tid3
,
7886 { .name
= "ID_AA64PFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7887 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 3,
7888 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7889 .accessfn
= access_aa64_tid3
,
7891 { .name
= "ID_AA64ZFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7892 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 4,
7893 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7894 .accessfn
= access_aa64_tid3
,
7895 .resetvalue
= cpu
->isar
.id_aa64zfr0
},
7896 { .name
= "ID_AA64PFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7897 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 5,
7898 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7899 .accessfn
= access_aa64_tid3
,
7901 { .name
= "ID_AA64PFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7902 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 6,
7903 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7904 .accessfn
= access_aa64_tid3
,
7906 { .name
= "ID_AA64PFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7907 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 7,
7908 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7909 .accessfn
= access_aa64_tid3
,
7911 { .name
= "ID_AA64DFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7912 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 0,
7913 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7914 .accessfn
= access_aa64_tid3
,
7915 .resetvalue
= cpu
->isar
.id_aa64dfr0
},
7916 { .name
= "ID_AA64DFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7917 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 1,
7918 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7919 .accessfn
= access_aa64_tid3
,
7920 .resetvalue
= cpu
->isar
.id_aa64dfr1
},
7921 { .name
= "ID_AA64DFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7922 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 2,
7923 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7924 .accessfn
= access_aa64_tid3
,
7926 { .name
= "ID_AA64DFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7927 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 3,
7928 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7929 .accessfn
= access_aa64_tid3
,
7931 { .name
= "ID_AA64AFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7932 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 4,
7933 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7934 .accessfn
= access_aa64_tid3
,
7935 .resetvalue
= cpu
->id_aa64afr0
},
7936 { .name
= "ID_AA64AFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7937 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 5,
7938 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7939 .accessfn
= access_aa64_tid3
,
7940 .resetvalue
= cpu
->id_aa64afr1
},
7941 { .name
= "ID_AA64AFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7942 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 6,
7943 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7944 .accessfn
= access_aa64_tid3
,
7946 { .name
= "ID_AA64AFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7947 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 7,
7948 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7949 .accessfn
= access_aa64_tid3
,
7951 { .name
= "ID_AA64ISAR0_EL1", .state
= ARM_CP_STATE_AA64
,
7952 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 0,
7953 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7954 .accessfn
= access_aa64_tid3
,
7955 .resetvalue
= cpu
->isar
.id_aa64isar0
},
7956 { .name
= "ID_AA64ISAR1_EL1", .state
= ARM_CP_STATE_AA64
,
7957 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 1,
7958 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7959 .accessfn
= access_aa64_tid3
,
7960 .resetvalue
= cpu
->isar
.id_aa64isar1
},
7961 { .name
= "ID_AA64ISAR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7962 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 2,
7963 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7964 .accessfn
= access_aa64_tid3
,
7966 { .name
= "ID_AA64ISAR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7967 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 3,
7968 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7969 .accessfn
= access_aa64_tid3
,
7971 { .name
= "ID_AA64ISAR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7972 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 4,
7973 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7974 .accessfn
= access_aa64_tid3
,
7976 { .name
= "ID_AA64ISAR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7977 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 5,
7978 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7979 .accessfn
= access_aa64_tid3
,
7981 { .name
= "ID_AA64ISAR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7982 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 6,
7983 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7984 .accessfn
= access_aa64_tid3
,
7986 { .name
= "ID_AA64ISAR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7987 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 7,
7988 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7989 .accessfn
= access_aa64_tid3
,
7991 { .name
= "ID_AA64MMFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7992 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 0,
7993 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7994 .accessfn
= access_aa64_tid3
,
7995 .resetvalue
= cpu
->isar
.id_aa64mmfr0
},
7996 { .name
= "ID_AA64MMFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7997 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 1,
7998 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7999 .accessfn
= access_aa64_tid3
,
8000 .resetvalue
= cpu
->isar
.id_aa64mmfr1
},
8001 { .name
= "ID_AA64MMFR2_EL1", .state
= ARM_CP_STATE_AA64
,
8002 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 2,
8003 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8004 .accessfn
= access_aa64_tid3
,
8005 .resetvalue
= cpu
->isar
.id_aa64mmfr2
},
8006 { .name
= "ID_AA64MMFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8007 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 3,
8008 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8009 .accessfn
= access_aa64_tid3
,
8011 { .name
= "ID_AA64MMFR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8012 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 4,
8013 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8014 .accessfn
= access_aa64_tid3
,
8016 { .name
= "ID_AA64MMFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8017 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 5,
8018 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8019 .accessfn
= access_aa64_tid3
,
8021 { .name
= "ID_AA64MMFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8022 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 6,
8023 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8024 .accessfn
= access_aa64_tid3
,
8026 { .name
= "ID_AA64MMFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8027 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 7,
8028 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8029 .accessfn
= access_aa64_tid3
,
8031 { .name
= "MVFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8032 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 0,
8033 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8034 .accessfn
= access_aa64_tid3
,
8035 .resetvalue
= cpu
->isar
.mvfr0
},
8036 { .name
= "MVFR1_EL1", .state
= ARM_CP_STATE_AA64
,
8037 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 1,
8038 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8039 .accessfn
= access_aa64_tid3
,
8040 .resetvalue
= cpu
->isar
.mvfr1
},
8041 { .name
= "MVFR2_EL1", .state
= ARM_CP_STATE_AA64
,
8042 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 2,
8043 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8044 .accessfn
= access_aa64_tid3
,
8045 .resetvalue
= cpu
->isar
.mvfr2
},
8046 { .name
= "MVFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8047 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 3,
8048 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8049 .accessfn
= access_aa64_tid3
,
8051 { .name
= "ID_PFR2", .state
= ARM_CP_STATE_BOTH
,
8052 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 4,
8053 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8054 .accessfn
= access_aa64_tid3
,
8055 .resetvalue
= cpu
->isar
.id_pfr2
},
8056 { .name
= "MVFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8057 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 5,
8058 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8059 .accessfn
= access_aa64_tid3
,
8061 { .name
= "MVFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8062 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 6,
8063 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8064 .accessfn
= access_aa64_tid3
,
8066 { .name
= "MVFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8067 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 7,
8068 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8069 .accessfn
= access_aa64_tid3
,
8071 { .name
= "PMCEID0", .state
= ARM_CP_STATE_AA32
,
8072 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 6,
8073 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
8074 .resetvalue
= extract64(cpu
->pmceid0
, 0, 32) },
8075 { .name
= "PMCEID0_EL0", .state
= ARM_CP_STATE_AA64
,
8076 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 6,
8077 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
8078 .resetvalue
= cpu
->pmceid0
},
8079 { .name
= "PMCEID1", .state
= ARM_CP_STATE_AA32
,
8080 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 7,
8081 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
8082 .resetvalue
= extract64(cpu
->pmceid1
, 0, 32) },
8083 { .name
= "PMCEID1_EL0", .state
= ARM_CP_STATE_AA64
,
8084 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 7,
8085 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
8086 .resetvalue
= cpu
->pmceid1
},
8089 #ifdef CONFIG_USER_ONLY
8090 ARMCPRegUserSpaceInfo v8_user_idregs
[] = {
8091 { .name
= "ID_AA64PFR0_EL1",
8092 .exported_bits
= 0x000f000f00ff0000,
8093 .fixed_bits
= 0x0000000000000011 },
8094 { .name
= "ID_AA64PFR1_EL1",
8095 .exported_bits
= 0x00000000000000f0 },
8096 { .name
= "ID_AA64PFR*_EL1_RESERVED",
8098 { .name
= "ID_AA64ZFR0_EL1" },
8099 { .name
= "ID_AA64MMFR0_EL1",
8100 .fixed_bits
= 0x00000000ff000000 },
8101 { .name
= "ID_AA64MMFR1_EL1" },
8102 { .name
= "ID_AA64MMFR*_EL1_RESERVED",
8104 { .name
= "ID_AA64DFR0_EL1",
8105 .fixed_bits
= 0x0000000000000006 },
8106 { .name
= "ID_AA64DFR1_EL1" },
8107 { .name
= "ID_AA64DFR*_EL1_RESERVED",
8109 { .name
= "ID_AA64AFR*",
8111 { .name
= "ID_AA64ISAR0_EL1",
8112 .exported_bits
= 0x00fffffff0fffff0 },
8113 { .name
= "ID_AA64ISAR1_EL1",
8114 .exported_bits
= 0x000000f0ffffffff },
8115 { .name
= "ID_AA64ISAR*_EL1_RESERVED",
8117 REGUSERINFO_SENTINEL
8119 modify_arm_cp_regs(v8_idregs
, v8_user_idregs
);
8121 /* RVBAR_EL1 is only implemented if EL1 is the highest EL */
8122 if (!arm_feature(env
, ARM_FEATURE_EL3
) &&
8123 !arm_feature(env
, ARM_FEATURE_EL2
)) {
8124 ARMCPRegInfo rvbar
= {
8125 .name
= "RVBAR_EL1", .state
= ARM_CP_STATE_AA64
,
8126 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
8127 .type
= ARM_CP_CONST
, .access
= PL1_R
, .resetvalue
= cpu
->rvbar
8129 define_one_arm_cp_reg(cpu
, &rvbar
);
8131 define_arm_cp_regs(cpu
, v8_idregs
);
8132 define_arm_cp_regs(cpu
, v8_cp_reginfo
);
8134 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
8135 uint64_t vmpidr_def
= mpidr_read_val(env
);
8136 ARMCPRegInfo vpidr_regs
[] = {
8137 { .name
= "VPIDR", .state
= ARM_CP_STATE_AA32
,
8138 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
8139 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
8140 .resetvalue
= cpu
->midr
, .type
= ARM_CP_ALIAS
,
8141 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vpidr_el2
) },
8142 { .name
= "VPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
8143 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
8144 .access
= PL2_RW
, .resetvalue
= cpu
->midr
,
8145 .fieldoffset
= offsetof(CPUARMState
, cp15
.vpidr_el2
) },
8146 { .name
= "VMPIDR", .state
= ARM_CP_STATE_AA32
,
8147 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
8148 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
8149 .resetvalue
= vmpidr_def
, .type
= ARM_CP_ALIAS
,
8150 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vmpidr_el2
) },
8151 { .name
= "VMPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
8152 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
8154 .resetvalue
= vmpidr_def
,
8155 .fieldoffset
= offsetof(CPUARMState
, cp15
.vmpidr_el2
) },
8158 define_arm_cp_regs(cpu
, vpidr_regs
);
8159 define_arm_cp_regs(cpu
, el2_cp_reginfo
);
8160 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8161 define_arm_cp_regs(cpu
, el2_v8_cp_reginfo
);
8163 if (cpu_isar_feature(aa64_sel2
, cpu
)) {
8164 define_arm_cp_regs(cpu
, el2_sec_cp_reginfo
);
8166 /* RVBAR_EL2 is only implemented if EL2 is the highest EL */
8167 if (!arm_feature(env
, ARM_FEATURE_EL3
)) {
8168 ARMCPRegInfo rvbar
= {
8169 .name
= "RVBAR_EL2", .state
= ARM_CP_STATE_AA64
,
8170 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 1,
8171 .type
= ARM_CP_CONST
, .access
= PL2_R
, .resetvalue
= cpu
->rvbar
8173 define_one_arm_cp_reg(cpu
, &rvbar
);
8176 /* If EL2 is missing but higher ELs are enabled, we need to
8177 * register the no_el2 reginfos.
8179 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
8180 /* When EL3 exists but not EL2, VPIDR and VMPIDR take the value
8181 * of MIDR_EL1 and MPIDR_EL1.
8183 ARMCPRegInfo vpidr_regs
[] = {
8184 { .name
= "VPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
8185 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
8186 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
8187 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->midr
,
8188 .fieldoffset
= offsetof(CPUARMState
, cp15
.vpidr_el2
) },
8189 { .name
= "VMPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
8190 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
8191 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
8192 .type
= ARM_CP_NO_RAW
,
8193 .writefn
= arm_cp_write_ignore
, .readfn
= mpidr_read
},
8196 define_arm_cp_regs(cpu
, vpidr_regs
);
8197 define_arm_cp_regs(cpu
, el3_no_el2_cp_reginfo
);
8198 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8199 define_arm_cp_regs(cpu
, el3_no_el2_v8_cp_reginfo
);
8203 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
8204 define_arm_cp_regs(cpu
, el3_cp_reginfo
);
8205 ARMCPRegInfo el3_regs
[] = {
8206 { .name
= "RVBAR_EL3", .state
= ARM_CP_STATE_AA64
,
8207 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 1,
8208 .type
= ARM_CP_CONST
, .access
= PL3_R
, .resetvalue
= cpu
->rvbar
},
8209 { .name
= "SCTLR_EL3", .state
= ARM_CP_STATE_AA64
,
8210 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 0,
8212 .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
8213 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[3]),
8214 .resetvalue
= cpu
->reset_sctlr
},
8218 define_arm_cp_regs(cpu
, el3_regs
);
8220 /* The behaviour of NSACR is sufficiently various that we don't
8221 * try to describe it in a single reginfo:
8222 * if EL3 is 64 bit, then trap to EL3 from S EL1,
8223 * reads as constant 0xc00 from NS EL1 and NS EL2
8224 * if EL3 is 32 bit, then RW at EL3, RO at NS EL1 and NS EL2
8225 * if v7 without EL3, register doesn't exist
8226 * if v8 without EL3, reads as constant 0xc00 from NS EL1 and NS EL2
8228 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
8229 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
8230 ARMCPRegInfo nsacr
= {
8231 .name
= "NSACR", .type
= ARM_CP_CONST
,
8232 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
8233 .access
= PL1_RW
, .accessfn
= nsacr_access
,
8236 define_one_arm_cp_reg(cpu
, &nsacr
);
8238 ARMCPRegInfo nsacr
= {
8240 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
8241 .access
= PL3_RW
| PL1_R
,
8243 .fieldoffset
= offsetof(CPUARMState
, cp15
.nsacr
)
8245 define_one_arm_cp_reg(cpu
, &nsacr
);
8248 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8249 ARMCPRegInfo nsacr
= {
8250 .name
= "NSACR", .type
= ARM_CP_CONST
,
8251 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
8255 define_one_arm_cp_reg(cpu
, &nsacr
);
8259 if (arm_feature(env
, ARM_FEATURE_PMSA
)) {
8260 if (arm_feature(env
, ARM_FEATURE_V6
)) {
8261 /* PMSAv6 not implemented */
8262 assert(arm_feature(env
, ARM_FEATURE_V7
));
8263 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
8264 define_arm_cp_regs(cpu
, pmsav7_cp_reginfo
);
8266 define_arm_cp_regs(cpu
, pmsav5_cp_reginfo
);
8269 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
8270 define_arm_cp_regs(cpu
, vmsa_cp_reginfo
);
8271 /* TTCBR2 is introduced with ARMv8.2-AA32HPD. */
8272 if (cpu_isar_feature(aa32_hpd
, cpu
)) {
8273 define_one_arm_cp_reg(cpu
, &ttbcr2_reginfo
);
8276 if (arm_feature(env
, ARM_FEATURE_THUMB2EE
)) {
8277 define_arm_cp_regs(cpu
, t2ee_cp_reginfo
);
8279 if (arm_feature(env
, ARM_FEATURE_GENERIC_TIMER
)) {
8280 define_arm_cp_regs(cpu
, generic_timer_cp_reginfo
);
8282 if (arm_feature(env
, ARM_FEATURE_VAPA
)) {
8283 define_arm_cp_regs(cpu
, vapa_cp_reginfo
);
8285 if (arm_feature(env
, ARM_FEATURE_CACHE_TEST_CLEAN
)) {
8286 define_arm_cp_regs(cpu
, cache_test_clean_cp_reginfo
);
8288 if (arm_feature(env
, ARM_FEATURE_CACHE_DIRTY_REG
)) {
8289 define_arm_cp_regs(cpu
, cache_dirty_status_cp_reginfo
);
8291 if (arm_feature(env
, ARM_FEATURE_CACHE_BLOCK_OPS
)) {
8292 define_arm_cp_regs(cpu
, cache_block_ops_cp_reginfo
);
8294 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
8295 define_arm_cp_regs(cpu
, omap_cp_reginfo
);
8297 if (arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
8298 define_arm_cp_regs(cpu
, strongarm_cp_reginfo
);
8300 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
8301 define_arm_cp_regs(cpu
, xscale_cp_reginfo
);
8303 if (arm_feature(env
, ARM_FEATURE_DUMMY_C15_REGS
)) {
8304 define_arm_cp_regs(cpu
, dummy_c15_cp_reginfo
);
8306 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
8307 define_arm_cp_regs(cpu
, lpae_cp_reginfo
);
8309 if (cpu_isar_feature(aa32_jazelle
, cpu
)) {
8310 define_arm_cp_regs(cpu
, jazelle_regs
);
8312 /* Slightly awkwardly, the OMAP and StrongARM cores need all of
8313 * cp15 crn=0 to be writes-ignored, whereas for other cores they should
8314 * be read-only (ie write causes UNDEF exception).
8317 ARMCPRegInfo id_pre_v8_midr_cp_reginfo
[] = {
8318 /* Pre-v8 MIDR space.
8319 * Note that the MIDR isn't a simple constant register because
8320 * of the TI925 behaviour where writes to another register can
8321 * cause the MIDR value to change.
8323 * Unimplemented registers in the c15 0 0 0 space default to
8324 * MIDR. Define MIDR first as this entire space, then CTR, TCMTR
8325 * and friends override accordingly.
8328 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= CP_ANY
,
8329 .access
= PL1_R
, .resetvalue
= cpu
->midr
,
8330 .writefn
= arm_cp_write_ignore
, .raw_writefn
= raw_write
,
8331 .readfn
= midr_read
,
8332 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
8333 .type
= ARM_CP_OVERRIDE
},
8334 /* crn = 0 op1 = 0 crm = 3..7 : currently unassigned; we RAZ. */
8336 .cp
= 15, .crn
= 0, .crm
= 3, .opc1
= 0, .opc2
= CP_ANY
,
8337 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8339 .cp
= 15, .crn
= 0, .crm
= 4, .opc1
= 0, .opc2
= CP_ANY
,
8340 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8342 .cp
= 15, .crn
= 0, .crm
= 5, .opc1
= 0, .opc2
= CP_ANY
,
8343 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8345 .cp
= 15, .crn
= 0, .crm
= 6, .opc1
= 0, .opc2
= CP_ANY
,
8346 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8348 .cp
= 15, .crn
= 0, .crm
= 7, .opc1
= 0, .opc2
= CP_ANY
,
8349 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8352 ARMCPRegInfo id_v8_midr_cp_reginfo
[] = {
8353 { .name
= "MIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
8354 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 0,
8355 .access
= PL1_R
, .type
= ARM_CP_NO_RAW
, .resetvalue
= cpu
->midr
,
8356 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
8357 .readfn
= midr_read
},
8358 /* crn = 0 op1 = 0 crm = 0 op2 = 4,7 : AArch32 aliases of MIDR */
8359 { .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
,
8360 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
8361 .access
= PL1_R
, .resetvalue
= cpu
->midr
},
8362 { .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
,
8363 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 7,
8364 .access
= PL1_R
, .resetvalue
= cpu
->midr
},
8365 { .name
= "REVIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
8366 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 6,
8368 .accessfn
= access_aa64_tid1
,
8369 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->revidr
},
8372 ARMCPRegInfo id_cp_reginfo
[] = {
8373 /* These are common to v8 and pre-v8 */
8375 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 1,
8376 .access
= PL1_R
, .accessfn
= ctr_el0_access
,
8377 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
8378 { .name
= "CTR_EL0", .state
= ARM_CP_STATE_AA64
,
8379 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 0, .crm
= 0,
8380 .access
= PL0_R
, .accessfn
= ctr_el0_access
,
8381 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
8382 /* TCMTR and TLBTR exist in v8 but have no 64-bit versions */
8384 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 2,
8386 .accessfn
= access_aa32_tid1
,
8387 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8390 /* TLBTR is specific to VMSA */
8391 ARMCPRegInfo id_tlbtr_reginfo
= {
8393 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 3,
8395 .accessfn
= access_aa32_tid1
,
8396 .type
= ARM_CP_CONST
, .resetvalue
= 0,
8398 /* MPUIR is specific to PMSA V6+ */
8399 ARMCPRegInfo id_mpuir_reginfo
= {
8401 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
8402 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8403 .resetvalue
= cpu
->pmsav7_dregion
<< 8
8405 ARMCPRegInfo crn0_wi_reginfo
= {
8406 .name
= "CRN0_WI", .cp
= 15, .crn
= 0, .crm
= CP_ANY
,
8407 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_W
,
8408 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
8410 #ifdef CONFIG_USER_ONLY
8411 ARMCPRegUserSpaceInfo id_v8_user_midr_cp_reginfo
[] = {
8412 { .name
= "MIDR_EL1",
8413 .exported_bits
= 0x00000000ffffffff },
8414 { .name
= "REVIDR_EL1" },
8415 REGUSERINFO_SENTINEL
8417 modify_arm_cp_regs(id_v8_midr_cp_reginfo
, id_v8_user_midr_cp_reginfo
);
8419 if (arm_feature(env
, ARM_FEATURE_OMAPCP
) ||
8420 arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
8422 /* Register the blanket "writes ignored" value first to cover the
8423 * whole space. Then update the specific ID registers to allow write
8424 * access, so that they ignore writes rather than causing them to
8427 define_one_arm_cp_reg(cpu
, &crn0_wi_reginfo
);
8428 for (r
= id_pre_v8_midr_cp_reginfo
;
8429 r
->type
!= ARM_CP_SENTINEL
; r
++) {
8432 for (r
= id_cp_reginfo
; r
->type
!= ARM_CP_SENTINEL
; r
++) {
8435 id_mpuir_reginfo
.access
= PL1_RW
;
8436 id_tlbtr_reginfo
.access
= PL1_RW
;
8438 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8439 define_arm_cp_regs(cpu
, id_v8_midr_cp_reginfo
);
8441 define_arm_cp_regs(cpu
, id_pre_v8_midr_cp_reginfo
);
8443 define_arm_cp_regs(cpu
, id_cp_reginfo
);
8444 if (!arm_feature(env
, ARM_FEATURE_PMSA
)) {
8445 define_one_arm_cp_reg(cpu
, &id_tlbtr_reginfo
);
8446 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
8447 define_one_arm_cp_reg(cpu
, &id_mpuir_reginfo
);
8451 if (arm_feature(env
, ARM_FEATURE_MPIDR
)) {
8452 ARMCPRegInfo mpidr_cp_reginfo
[] = {
8453 { .name
= "MPIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
8454 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 5,
8455 .access
= PL1_R
, .readfn
= mpidr_read
, .type
= ARM_CP_NO_RAW
},
8458 #ifdef CONFIG_USER_ONLY
8459 ARMCPRegUserSpaceInfo mpidr_user_cp_reginfo
[] = {
8460 { .name
= "MPIDR_EL1",
8461 .fixed_bits
= 0x0000000080000000 },
8462 REGUSERINFO_SENTINEL
8464 modify_arm_cp_regs(mpidr_cp_reginfo
, mpidr_user_cp_reginfo
);
8466 define_arm_cp_regs(cpu
, mpidr_cp_reginfo
);
8469 if (arm_feature(env
, ARM_FEATURE_AUXCR
)) {
8470 ARMCPRegInfo auxcr_reginfo
[] = {
8471 { .name
= "ACTLR_EL1", .state
= ARM_CP_STATE_BOTH
,
8472 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 1,
8473 .access
= PL1_RW
, .accessfn
= access_tacr
,
8474 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->reset_auxcr
},
8475 { .name
= "ACTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
8476 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 1,
8477 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
8479 { .name
= "ACTLR_EL3", .state
= ARM_CP_STATE_AA64
,
8480 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 1,
8481 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
8485 define_arm_cp_regs(cpu
, auxcr_reginfo
);
8486 if (cpu_isar_feature(aa32_ac2
, cpu
)) {
8487 define_arm_cp_regs(cpu
, actlr2_hactlr2_reginfo
);
8491 if (arm_feature(env
, ARM_FEATURE_CBAR
)) {
8493 * CBAR is IMPDEF, but common on Arm Cortex-A implementations.
8494 * There are two flavours:
8495 * (1) older 32-bit only cores have a simple 32-bit CBAR
8496 * (2) 64-bit cores have a 64-bit CBAR visible to AArch64, plus a
8497 * 32-bit register visible to AArch32 at a different encoding
8498 * to the "flavour 1" register and with the bits rearranged to
8499 * be able to squash a 64-bit address into the 32-bit view.
8500 * We distinguish the two via the ARM_FEATURE_AARCH64 flag, but
8501 * in future if we support AArch32-only configs of some of the
8502 * AArch64 cores we might need to add a specific feature flag
8503 * to indicate cores with "flavour 2" CBAR.
8505 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
8506 /* 32 bit view is [31:18] 0...0 [43:32]. */
8507 uint32_t cbar32
= (extract64(cpu
->reset_cbar
, 18, 14) << 18)
8508 | extract64(cpu
->reset_cbar
, 32, 12);
8509 ARMCPRegInfo cbar_reginfo
[] = {
8511 .type
= ARM_CP_CONST
,
8512 .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 1, .opc2
= 0,
8513 .access
= PL1_R
, .resetvalue
= cbar32
},
8514 { .name
= "CBAR_EL1", .state
= ARM_CP_STATE_AA64
,
8515 .type
= ARM_CP_CONST
,
8516 .opc0
= 3, .opc1
= 1, .crn
= 15, .crm
= 3, .opc2
= 0,
8517 .access
= PL1_R
, .resetvalue
= cpu
->reset_cbar
},
8520 /* We don't implement a r/w 64 bit CBAR currently */
8521 assert(arm_feature(env
, ARM_FEATURE_CBAR_RO
));
8522 define_arm_cp_regs(cpu
, cbar_reginfo
);
8524 ARMCPRegInfo cbar
= {
8526 .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 4, .opc2
= 0,
8527 .access
= PL1_R
|PL3_W
, .resetvalue
= cpu
->reset_cbar
,
8528 .fieldoffset
= offsetof(CPUARMState
,
8529 cp15
.c15_config_base_address
)
8531 if (arm_feature(env
, ARM_FEATURE_CBAR_RO
)) {
8532 cbar
.access
= PL1_R
;
8533 cbar
.fieldoffset
= 0;
8534 cbar
.type
= ARM_CP_CONST
;
8536 define_one_arm_cp_reg(cpu
, &cbar
);
8540 if (arm_feature(env
, ARM_FEATURE_VBAR
)) {
8541 ARMCPRegInfo vbar_cp_reginfo
[] = {
8542 { .name
= "VBAR", .state
= ARM_CP_STATE_BOTH
,
8543 .opc0
= 3, .crn
= 12, .crm
= 0, .opc1
= 0, .opc2
= 0,
8544 .access
= PL1_RW
, .writefn
= vbar_write
,
8545 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.vbar_s
),
8546 offsetof(CPUARMState
, cp15
.vbar_ns
) },
8550 define_arm_cp_regs(cpu
, vbar_cp_reginfo
);
8553 /* Generic registers whose values depend on the implementation */
8555 ARMCPRegInfo sctlr
= {
8556 .name
= "SCTLR", .state
= ARM_CP_STATE_BOTH
,
8557 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 0,
8558 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
8559 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.sctlr_s
),
8560 offsetof(CPUARMState
, cp15
.sctlr_ns
) },
8561 .writefn
= sctlr_write
, .resetvalue
= cpu
->reset_sctlr
,
8562 .raw_writefn
= raw_write
,
8564 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
8565 /* Normally we would always end the TB on an SCTLR write, but Linux
8566 * arch/arm/mach-pxa/sleep.S expects two instructions following
8567 * an MMU enable to execute from cache. Imitate this behaviour.
8569 sctlr
.type
|= ARM_CP_SUPPRESS_TB_END
;
8571 define_one_arm_cp_reg(cpu
, &sctlr
);
8574 if (cpu_isar_feature(aa64_lor
, cpu
)) {
8575 define_arm_cp_regs(cpu
, lor_reginfo
);
8577 if (cpu_isar_feature(aa64_pan
, cpu
)) {
8578 define_one_arm_cp_reg(cpu
, &pan_reginfo
);
8580 #ifndef CONFIG_USER_ONLY
8581 if (cpu_isar_feature(aa64_ats1e1
, cpu
)) {
8582 define_arm_cp_regs(cpu
, ats1e1_reginfo
);
8584 if (cpu_isar_feature(aa32_ats1e1
, cpu
)) {
8585 define_arm_cp_regs(cpu
, ats1cp_reginfo
);
8588 if (cpu_isar_feature(aa64_uao
, cpu
)) {
8589 define_one_arm_cp_reg(cpu
, &uao_reginfo
);
8592 if (cpu_isar_feature(aa64_dit
, cpu
)) {
8593 define_one_arm_cp_reg(cpu
, &dit_reginfo
);
8595 if (cpu_isar_feature(aa64_ssbs
, cpu
)) {
8596 define_one_arm_cp_reg(cpu
, &ssbs_reginfo
);
8599 if (arm_feature(env
, ARM_FEATURE_EL2
) && cpu_isar_feature(aa64_vh
, cpu
)) {
8600 define_arm_cp_regs(cpu
, vhe_reginfo
);
8603 if (cpu_isar_feature(aa64_sve
, cpu
)) {
8604 define_one_arm_cp_reg(cpu
, &zcr_el1_reginfo
);
8605 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
8606 define_one_arm_cp_reg(cpu
, &zcr_el2_reginfo
);
8608 define_one_arm_cp_reg(cpu
, &zcr_no_el2_reginfo
);
8610 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
8611 define_one_arm_cp_reg(cpu
, &zcr_el3_reginfo
);
8615 #ifdef TARGET_AARCH64
8616 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
8617 define_arm_cp_regs(cpu
, pauth_reginfo
);
8619 if (cpu_isar_feature(aa64_rndr
, cpu
)) {
8620 define_arm_cp_regs(cpu
, rndr_reginfo
);
8622 if (cpu_isar_feature(aa64_tlbirange
, cpu
)) {
8623 define_arm_cp_regs(cpu
, tlbirange_reginfo
);
8625 if (cpu_isar_feature(aa64_tlbios
, cpu
)) {
8626 define_arm_cp_regs(cpu
, tlbios_reginfo
);
8628 #ifndef CONFIG_USER_ONLY
8629 /* Data Cache clean instructions up to PoP */
8630 if (cpu_isar_feature(aa64_dcpop
, cpu
)) {
8631 define_one_arm_cp_reg(cpu
, dcpop_reg
);
8633 if (cpu_isar_feature(aa64_dcpodp
, cpu
)) {
8634 define_one_arm_cp_reg(cpu
, dcpodp_reg
);
8637 #endif /*CONFIG_USER_ONLY*/
8640 * If full MTE is enabled, add all of the system registers.
8641 * If only "instructions available at EL0" are enabled,
8642 * then define only a RAZ/WI version of PSTATE.TCO.
8644 if (cpu_isar_feature(aa64_mte
, cpu
)) {
8645 define_arm_cp_regs(cpu
, mte_reginfo
);
8646 define_arm_cp_regs(cpu
, mte_el0_cacheop_reginfo
);
8647 } else if (cpu_isar_feature(aa64_mte_insn_reg
, cpu
)) {
8648 define_arm_cp_regs(cpu
, mte_tco_ro_reginfo
);
8649 define_arm_cp_regs(cpu
, mte_el0_cacheop_reginfo
);
8653 if (cpu_isar_feature(any_predinv
, cpu
)) {
8654 define_arm_cp_regs(cpu
, predinv_reginfo
);
8657 if (cpu_isar_feature(any_ccidx
, cpu
)) {
8658 define_arm_cp_regs(cpu
, ccsidr2_reginfo
);
8661 #ifndef CONFIG_USER_ONLY
8663 * Register redirections and aliases must be done last,
8664 * after the registers from the other extensions have been defined.
8666 if (arm_feature(env
, ARM_FEATURE_EL2
) && cpu_isar_feature(aa64_vh
, cpu
)) {
8667 define_arm_vh_e2h_redirects_aliases(cpu
);
8672 void arm_cpu_register_gdb_regs_for_features(ARMCPU
*cpu
)
8674 CPUState
*cs
= CPU(cpu
);
8675 CPUARMState
*env
= &cpu
->env
;
8677 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
8679 * The lower part of each SVE register aliases to the FPU
8680 * registers so we don't need to include both.
8682 #ifdef TARGET_AARCH64
8683 if (isar_feature_aa64_sve(&cpu
->isar
)) {
8684 gdb_register_coprocessor(cs
, arm_gdb_get_svereg
, arm_gdb_set_svereg
,
8685 arm_gen_dynamic_svereg_xml(cs
, cs
->gdb_num_regs
),
8686 "sve-registers.xml", 0);
8690 gdb_register_coprocessor(cs
, aarch64_fpu_gdb_get_reg
,
8691 aarch64_fpu_gdb_set_reg
,
8692 34, "aarch64-fpu.xml", 0);
8694 } else if (arm_feature(env
, ARM_FEATURE_NEON
)) {
8695 gdb_register_coprocessor(cs
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
8696 51, "arm-neon.xml", 0);
8697 } else if (cpu_isar_feature(aa32_simd_r32
, cpu
)) {
8698 gdb_register_coprocessor(cs
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
8699 35, "arm-vfp3.xml", 0);
8700 } else if (cpu_isar_feature(aa32_vfp_simd
, cpu
)) {
8701 gdb_register_coprocessor(cs
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
8702 19, "arm-vfp.xml", 0);
8704 gdb_register_coprocessor(cs
, arm_gdb_get_sysreg
, arm_gdb_set_sysreg
,
8705 arm_gen_dynamic_sysreg_xml(cs
, cs
->gdb_num_regs
),
8706 "system-registers.xml", 0);
8710 /* Sort alphabetically by type name, except for "any". */
8711 static gint
arm_cpu_list_compare(gconstpointer a
, gconstpointer b
)
8713 ObjectClass
*class_a
= (ObjectClass
*)a
;
8714 ObjectClass
*class_b
= (ObjectClass
*)b
;
8715 const char *name_a
, *name_b
;
8717 name_a
= object_class_get_name(class_a
);
8718 name_b
= object_class_get_name(class_b
);
8719 if (strcmp(name_a
, "any-" TYPE_ARM_CPU
) == 0) {
8721 } else if (strcmp(name_b
, "any-" TYPE_ARM_CPU
) == 0) {
8724 return strcmp(name_a
, name_b
);
8728 static void arm_cpu_list_entry(gpointer data
, gpointer user_data
)
8730 ObjectClass
*oc
= data
;
8731 const char *typename
;
8734 typename
= object_class_get_name(oc
);
8735 name
= g_strndup(typename
, strlen(typename
) - strlen("-" TYPE_ARM_CPU
));
8736 qemu_printf(" %s\n", name
);
8740 void arm_cpu_list(void)
8744 list
= object_class_get_list(TYPE_ARM_CPU
, false);
8745 list
= g_slist_sort(list
, arm_cpu_list_compare
);
8746 qemu_printf("Available CPUs:\n");
8747 g_slist_foreach(list
, arm_cpu_list_entry
, NULL
);
8751 static void arm_cpu_add_definition(gpointer data
, gpointer user_data
)
8753 ObjectClass
*oc
= data
;
8754 CpuDefinitionInfoList
**cpu_list
= user_data
;
8755 CpuDefinitionInfo
*info
;
8756 const char *typename
;
8758 typename
= object_class_get_name(oc
);
8759 info
= g_malloc0(sizeof(*info
));
8760 info
->name
= g_strndup(typename
,
8761 strlen(typename
) - strlen("-" TYPE_ARM_CPU
));
8762 info
->q_typename
= g_strdup(typename
);
8764 QAPI_LIST_PREPEND(*cpu_list
, info
);
8767 CpuDefinitionInfoList
*qmp_query_cpu_definitions(Error
**errp
)
8769 CpuDefinitionInfoList
*cpu_list
= NULL
;
8772 list
= object_class_get_list(TYPE_ARM_CPU
, false);
8773 g_slist_foreach(list
, arm_cpu_add_definition
, &cpu_list
);
8779 static void add_cpreg_to_hashtable(ARMCPU
*cpu
, const ARMCPRegInfo
*r
,
8780 void *opaque
, int state
, int secstate
,
8781 int crm
, int opc1
, int opc2
,
8784 /* Private utility function for define_one_arm_cp_reg_with_opaque():
8785 * add a single reginfo struct to the hash table.
8787 uint32_t *key
= g_new(uint32_t, 1);
8788 ARMCPRegInfo
*r2
= g_memdup(r
, sizeof(ARMCPRegInfo
));
8789 int is64
= (r
->type
& ARM_CP_64BIT
) ? 1 : 0;
8790 int ns
= (secstate
& ARM_CP_SECSTATE_NS
) ? 1 : 0;
8792 r2
->name
= g_strdup(name
);
8793 /* Reset the secure state to the specific incoming state. This is
8794 * necessary as the register may have been defined with both states.
8796 r2
->secure
= secstate
;
8798 if (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1]) {
8799 /* Register is banked (using both entries in array).
8800 * Overwriting fieldoffset as the array is only used to define
8801 * banked registers but later only fieldoffset is used.
8803 r2
->fieldoffset
= r
->bank_fieldoffsets
[ns
];
8806 if (state
== ARM_CP_STATE_AA32
) {
8807 if (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1]) {
8808 /* If the register is banked then we don't need to migrate or
8809 * reset the 32-bit instance in certain cases:
8811 * 1) If the register has both 32-bit and 64-bit instances then we
8812 * can count on the 64-bit instance taking care of the
8814 * 2) If ARMv8 is enabled then we can count on a 64-bit version
8815 * taking care of the secure bank. This requires that separate
8816 * 32 and 64-bit definitions are provided.
8818 if ((r
->state
== ARM_CP_STATE_BOTH
&& ns
) ||
8819 (arm_feature(&cpu
->env
, ARM_FEATURE_V8
) && !ns
)) {
8820 r2
->type
|= ARM_CP_ALIAS
;
8822 } else if ((secstate
!= r
->secure
) && !ns
) {
8823 /* The register is not banked so we only want to allow migration of
8824 * the non-secure instance.
8826 r2
->type
|= ARM_CP_ALIAS
;
8829 if (r
->state
== ARM_CP_STATE_BOTH
) {
8830 /* We assume it is a cp15 register if the .cp field is left unset.
8836 #ifdef HOST_WORDS_BIGENDIAN
8837 if (r2
->fieldoffset
) {
8838 r2
->fieldoffset
+= sizeof(uint32_t);
8843 if (state
== ARM_CP_STATE_AA64
) {
8844 /* To allow abbreviation of ARMCPRegInfo
8845 * definitions, we treat cp == 0 as equivalent to
8846 * the value for "standard guest-visible sysreg".
8847 * STATE_BOTH definitions are also always "standard
8848 * sysreg" in their AArch64 view (the .cp value may
8849 * be non-zero for the benefit of the AArch32 view).
8851 if (r
->cp
== 0 || r
->state
== ARM_CP_STATE_BOTH
) {
8852 r2
->cp
= CP_REG_ARM64_SYSREG_CP
;
8854 *key
= ENCODE_AA64_CP_REG(r2
->cp
, r2
->crn
, crm
,
8855 r2
->opc0
, opc1
, opc2
);
8857 *key
= ENCODE_CP_REG(r2
->cp
, is64
, ns
, r2
->crn
, crm
, opc1
, opc2
);
8860 r2
->opaque
= opaque
;
8862 /* reginfo passed to helpers is correct for the actual access,
8863 * and is never ARM_CP_STATE_BOTH:
8866 /* Make sure reginfo passed to helpers for wildcarded regs
8867 * has the correct crm/opc1/opc2 for this reg, not CP_ANY:
8872 /* By convention, for wildcarded registers only the first
8873 * entry is used for migration; the others are marked as
8874 * ALIAS so we don't try to transfer the register
8875 * multiple times. Special registers (ie NOP/WFI) are
8876 * never migratable and not even raw-accessible.
8878 if ((r
->type
& ARM_CP_SPECIAL
)) {
8879 r2
->type
|= ARM_CP_NO_RAW
;
8881 if (((r
->crm
== CP_ANY
) && crm
!= 0) ||
8882 ((r
->opc1
== CP_ANY
) && opc1
!= 0) ||
8883 ((r
->opc2
== CP_ANY
) && opc2
!= 0)) {
8884 r2
->type
|= ARM_CP_ALIAS
| ARM_CP_NO_GDB
;
8887 /* Check that raw accesses are either forbidden or handled. Note that
8888 * we can't assert this earlier because the setup of fieldoffset for
8889 * banked registers has to be done first.
8891 if (!(r2
->type
& ARM_CP_NO_RAW
)) {
8892 assert(!raw_accessors_invalid(r2
));
8895 /* Overriding of an existing definition must be explicitly
8898 if (!(r
->type
& ARM_CP_OVERRIDE
)) {
8899 ARMCPRegInfo
*oldreg
;
8900 oldreg
= g_hash_table_lookup(cpu
->cp_regs
, key
);
8901 if (oldreg
&& !(oldreg
->type
& ARM_CP_OVERRIDE
)) {
8902 fprintf(stderr
, "Register redefined: cp=%d %d bit "
8903 "crn=%d crm=%d opc1=%d opc2=%d, "
8904 "was %s, now %s\n", r2
->cp
, 32 + 32 * is64
,
8905 r2
->crn
, r2
->crm
, r2
->opc1
, r2
->opc2
,
8906 oldreg
->name
, r2
->name
);
8907 g_assert_not_reached();
8910 g_hash_table_insert(cpu
->cp_regs
, key
, r2
);
8914 void define_one_arm_cp_reg_with_opaque(ARMCPU
*cpu
,
8915 const ARMCPRegInfo
*r
, void *opaque
)
8917 /* Define implementations of coprocessor registers.
8918 * We store these in a hashtable because typically
8919 * there are less than 150 registers in a space which
8920 * is 16*16*16*8*8 = 262144 in size.
8921 * Wildcarding is supported for the crm, opc1 and opc2 fields.
8922 * If a register is defined twice then the second definition is
8923 * used, so this can be used to define some generic registers and
8924 * then override them with implementation specific variations.
8925 * At least one of the original and the second definition should
8926 * include ARM_CP_OVERRIDE in its type bits -- this is just a guard
8927 * against accidental use.
8929 * The state field defines whether the register is to be
8930 * visible in the AArch32 or AArch64 execution state. If the
8931 * state is set to ARM_CP_STATE_BOTH then we synthesise a
8932 * reginfo structure for the AArch32 view, which sees the lower
8933 * 32 bits of the 64 bit register.
8935 * Only registers visible in AArch64 may set r->opc0; opc0 cannot
8936 * be wildcarded. AArch64 registers are always considered to be 64
8937 * bits; the ARM_CP_64BIT* flag applies only to the AArch32 view of
8938 * the register, if any.
8940 int crm
, opc1
, opc2
, state
;
8941 int crmmin
= (r
->crm
== CP_ANY
) ? 0 : r
->crm
;
8942 int crmmax
= (r
->crm
== CP_ANY
) ? 15 : r
->crm
;
8943 int opc1min
= (r
->opc1
== CP_ANY
) ? 0 : r
->opc1
;
8944 int opc1max
= (r
->opc1
== CP_ANY
) ? 7 : r
->opc1
;
8945 int opc2min
= (r
->opc2
== CP_ANY
) ? 0 : r
->opc2
;
8946 int opc2max
= (r
->opc2
== CP_ANY
) ? 7 : r
->opc2
;
8947 /* 64 bit registers have only CRm and Opc1 fields */
8948 assert(!((r
->type
& ARM_CP_64BIT
) && (r
->opc2
|| r
->crn
)));
8949 /* op0 only exists in the AArch64 encodings */
8950 assert((r
->state
!= ARM_CP_STATE_AA32
) || (r
->opc0
== 0));
8951 /* AArch64 regs are all 64 bit so ARM_CP_64BIT is meaningless */
8952 assert((r
->state
!= ARM_CP_STATE_AA64
) || !(r
->type
& ARM_CP_64BIT
));
8954 * This API is only for Arm's system coprocessors (14 and 15) or
8955 * (M-profile or v7A-and-earlier only) for implementation defined
8956 * coprocessors in the range 0..7. Our decode assumes this, since
8957 * 8..13 can be used for other insns including VFP and Neon. See
8958 * valid_cp() in translate.c. Assert here that we haven't tried
8959 * to use an invalid coprocessor number.
8962 case ARM_CP_STATE_BOTH
:
8963 /* 0 has a special meaning, but otherwise the same rules as AA32. */
8968 case ARM_CP_STATE_AA32
:
8969 if (arm_feature(&cpu
->env
, ARM_FEATURE_V8
) &&
8970 !arm_feature(&cpu
->env
, ARM_FEATURE_M
)) {
8971 assert(r
->cp
>= 14 && r
->cp
<= 15);
8973 assert(r
->cp
< 8 || (r
->cp
>= 14 && r
->cp
<= 15));
8976 case ARM_CP_STATE_AA64
:
8977 assert(r
->cp
== 0 || r
->cp
== CP_REG_ARM64_SYSREG_CP
);
8980 g_assert_not_reached();
8982 /* The AArch64 pseudocode CheckSystemAccess() specifies that op1
8983 * encodes a minimum access level for the register. We roll this
8984 * runtime check into our general permission check code, so check
8985 * here that the reginfo's specified permissions are strict enough
8986 * to encompass the generic architectural permission check.
8988 if (r
->state
!= ARM_CP_STATE_AA32
) {
8992 /* min_EL EL1, but some accessible to EL0 via kernel ABI */
8993 mask
= PL0U_R
| PL1_RW
;
9013 /* min_EL EL1, secure mode only (we don't check the latter) */
9017 /* broken reginfo with out-of-range opc1 */
9021 /* assert our permissions are not too lax (stricter is fine) */
9022 assert((r
->access
& ~mask
) == 0);
9025 /* Check that the register definition has enough info to handle
9026 * reads and writes if they are permitted.
9028 if (!(r
->type
& (ARM_CP_SPECIAL
|ARM_CP_CONST
))) {
9029 if (r
->access
& PL3_R
) {
9030 assert((r
->fieldoffset
||
9031 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
9034 if (r
->access
& PL3_W
) {
9035 assert((r
->fieldoffset
||
9036 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
9040 /* Bad type field probably means missing sentinel at end of reg list */
9041 assert(cptype_valid(r
->type
));
9042 for (crm
= crmmin
; crm
<= crmmax
; crm
++) {
9043 for (opc1
= opc1min
; opc1
<= opc1max
; opc1
++) {
9044 for (opc2
= opc2min
; opc2
<= opc2max
; opc2
++) {
9045 for (state
= ARM_CP_STATE_AA32
;
9046 state
<= ARM_CP_STATE_AA64
; state
++) {
9047 if (r
->state
!= state
&& r
->state
!= ARM_CP_STATE_BOTH
) {
9050 if (state
== ARM_CP_STATE_AA32
) {
9051 /* Under AArch32 CP registers can be common
9052 * (same for secure and non-secure world) or banked.
9056 switch (r
->secure
) {
9057 case ARM_CP_SECSTATE_S
:
9058 case ARM_CP_SECSTATE_NS
:
9059 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
9060 r
->secure
, crm
, opc1
, opc2
,
9064 name
= g_strdup_printf("%s_S", r
->name
);
9065 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
9067 crm
, opc1
, opc2
, name
);
9069 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
9071 crm
, opc1
, opc2
, r
->name
);
9075 /* AArch64 registers get mapped to non-secure instance
9077 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
9079 crm
, opc1
, opc2
, r
->name
);
9087 void define_arm_cp_regs_with_opaque(ARMCPU
*cpu
,
9088 const ARMCPRegInfo
*regs
, void *opaque
)
9090 /* Define a whole list of registers */
9091 const ARMCPRegInfo
*r
;
9092 for (r
= regs
; r
->type
!= ARM_CP_SENTINEL
; r
++) {
9093 define_one_arm_cp_reg_with_opaque(cpu
, r
, opaque
);
9098 * Modify ARMCPRegInfo for access from userspace.
9100 * This is a data driven modification directed by
9101 * ARMCPRegUserSpaceInfo. All registers become ARM_CP_CONST as
9102 * user-space cannot alter any values and dynamic values pertaining to
9103 * execution state are hidden from user space view anyway.
9105 void modify_arm_cp_regs(ARMCPRegInfo
*regs
, const ARMCPRegUserSpaceInfo
*mods
)
9107 const ARMCPRegUserSpaceInfo
*m
;
9110 for (m
= mods
; m
->name
; m
++) {
9111 GPatternSpec
*pat
= NULL
;
9113 pat
= g_pattern_spec_new(m
->name
);
9115 for (r
= regs
; r
->type
!= ARM_CP_SENTINEL
; r
++) {
9116 if (pat
&& g_pattern_match_string(pat
, r
->name
)) {
9117 r
->type
= ARM_CP_CONST
;
9121 } else if (strcmp(r
->name
, m
->name
) == 0) {
9122 r
->type
= ARM_CP_CONST
;
9124 r
->resetvalue
&= m
->exported_bits
;
9125 r
->resetvalue
|= m
->fixed_bits
;
9130 g_pattern_spec_free(pat
);
9135 const ARMCPRegInfo
*get_arm_cp_reginfo(GHashTable
*cpregs
, uint32_t encoded_cp
)
9137 return g_hash_table_lookup(cpregs
, &encoded_cp
);
9140 void arm_cp_write_ignore(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
9143 /* Helper coprocessor write function for write-ignore registers */
9146 uint64_t arm_cp_read_zero(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
9148 /* Helper coprocessor write function for read-as-zero registers */
9152 void arm_cp_reset_ignore(CPUARMState
*env
, const ARMCPRegInfo
*opaque
)
9154 /* Helper coprocessor reset function for do-nothing-on-reset registers */
9157 static int bad_mode_switch(CPUARMState
*env
, int mode
, CPSRWriteType write_type
)
9159 /* Return true if it is not valid for us to switch to
9160 * this CPU mode (ie all the UNPREDICTABLE cases in
9161 * the ARM ARM CPSRWriteByInstr pseudocode).
9164 /* Changes to or from Hyp via MSR and CPS are illegal. */
9165 if (write_type
== CPSRWriteByInstr
&&
9166 ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_HYP
||
9167 mode
== ARM_CPU_MODE_HYP
)) {
9172 case ARM_CPU_MODE_USR
:
9174 case ARM_CPU_MODE_SYS
:
9175 case ARM_CPU_MODE_SVC
:
9176 case ARM_CPU_MODE_ABT
:
9177 case ARM_CPU_MODE_UND
:
9178 case ARM_CPU_MODE_IRQ
:
9179 case ARM_CPU_MODE_FIQ
:
9180 /* Note that we don't implement the IMPDEF NSACR.RFR which in v7
9181 * allows FIQ mode to be Secure-only. (In v8 this doesn't exist.)
9183 /* If HCR.TGE is set then changes from Monitor to NS PL1 via MSR
9184 * and CPS are treated as illegal mode changes.
9186 if (write_type
== CPSRWriteByInstr
&&
9187 (env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
&&
9188 (arm_hcr_el2_eff(env
) & HCR_TGE
)) {
9192 case ARM_CPU_MODE_HYP
:
9193 return !arm_is_el2_enabled(env
) || arm_current_el(env
) < 2;
9194 case ARM_CPU_MODE_MON
:
9195 return arm_current_el(env
) < 3;
9201 uint32_t cpsr_read(CPUARMState
*env
)
9204 ZF
= (env
->ZF
== 0);
9205 return env
->uncached_cpsr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
9206 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3) | (env
->QF
<< 27)
9207 | (env
->thumb
<< 5) | ((env
->condexec_bits
& 3) << 25)
9208 | ((env
->condexec_bits
& 0xfc) << 8)
9209 | (env
->GE
<< 16) | (env
->daif
& CPSR_AIF
);
9212 void cpsr_write(CPUARMState
*env
, uint32_t val
, uint32_t mask
,
9213 CPSRWriteType write_type
)
9215 uint32_t changed_daif
;
9217 if (mask
& CPSR_NZCV
) {
9218 env
->ZF
= (~val
) & CPSR_Z
;
9220 env
->CF
= (val
>> 29) & 1;
9221 env
->VF
= (val
<< 3) & 0x80000000;
9224 env
->QF
= ((val
& CPSR_Q
) != 0);
9226 env
->thumb
= ((val
& CPSR_T
) != 0);
9227 if (mask
& CPSR_IT_0_1
) {
9228 env
->condexec_bits
&= ~3;
9229 env
->condexec_bits
|= (val
>> 25) & 3;
9231 if (mask
& CPSR_IT_2_7
) {
9232 env
->condexec_bits
&= 3;
9233 env
->condexec_bits
|= (val
>> 8) & 0xfc;
9235 if (mask
& CPSR_GE
) {
9236 env
->GE
= (val
>> 16) & 0xf;
9239 /* In a V7 implementation that includes the security extensions but does
9240 * not include Virtualization Extensions the SCR.FW and SCR.AW bits control
9241 * whether non-secure software is allowed to change the CPSR_F and CPSR_A
9242 * bits respectively.
9244 * In a V8 implementation, it is permitted for privileged software to
9245 * change the CPSR A/F bits regardless of the SCR.AW/FW bits.
9247 if (write_type
!= CPSRWriteRaw
&& !arm_feature(env
, ARM_FEATURE_V8
) &&
9248 arm_feature(env
, ARM_FEATURE_EL3
) &&
9249 !arm_feature(env
, ARM_FEATURE_EL2
) &&
9250 !arm_is_secure(env
)) {
9252 changed_daif
= (env
->daif
^ val
) & mask
;
9254 if (changed_daif
& CPSR_A
) {
9255 /* Check to see if we are allowed to change the masking of async
9256 * abort exceptions from a non-secure state.
9258 if (!(env
->cp15
.scr_el3
& SCR_AW
)) {
9259 qemu_log_mask(LOG_GUEST_ERROR
,
9260 "Ignoring attempt to switch CPSR_A flag from "
9261 "non-secure world with SCR.AW bit clear\n");
9266 if (changed_daif
& CPSR_F
) {
9267 /* Check to see if we are allowed to change the masking of FIQ
9268 * exceptions from a non-secure state.
9270 if (!(env
->cp15
.scr_el3
& SCR_FW
)) {
9271 qemu_log_mask(LOG_GUEST_ERROR
,
9272 "Ignoring attempt to switch CPSR_F flag from "
9273 "non-secure world with SCR.FW bit clear\n");
9277 /* Check whether non-maskable FIQ (NMFI) support is enabled.
9278 * If this bit is set software is not allowed to mask
9279 * FIQs, but is allowed to set CPSR_F to 0.
9281 if ((A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_NMFI
) &&
9283 qemu_log_mask(LOG_GUEST_ERROR
,
9284 "Ignoring attempt to enable CPSR_F flag "
9285 "(non-maskable FIQ [NMFI] support enabled)\n");
9291 env
->daif
&= ~(CPSR_AIF
& mask
);
9292 env
->daif
|= val
& CPSR_AIF
& mask
;
9294 if (write_type
!= CPSRWriteRaw
&&
9295 ((env
->uncached_cpsr
^ val
) & mask
& CPSR_M
)) {
9296 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_USR
) {
9297 /* Note that we can only get here in USR mode if this is a
9298 * gdb stub write; for this case we follow the architectural
9299 * behaviour for guest writes in USR mode of ignoring an attempt
9300 * to switch mode. (Those are caught by translate.c for writes
9301 * triggered by guest instructions.)
9304 } else if (bad_mode_switch(env
, val
& CPSR_M
, write_type
)) {
9305 /* Attempt to switch to an invalid mode: this is UNPREDICTABLE in
9306 * v7, and has defined behaviour in v8:
9307 * + leave CPSR.M untouched
9308 * + allow changes to the other CPSR fields
9310 * For user changes via the GDB stub, we don't set PSTATE.IL,
9311 * as this would be unnecessarily harsh for a user error.
9314 if (write_type
!= CPSRWriteByGDBStub
&&
9315 arm_feature(env
, ARM_FEATURE_V8
)) {
9319 qemu_log_mask(LOG_GUEST_ERROR
,
9320 "Illegal AArch32 mode switch attempt from %s to %s\n",
9321 aarch32_mode_name(env
->uncached_cpsr
),
9322 aarch32_mode_name(val
));
9324 qemu_log_mask(CPU_LOG_INT
, "%s %s to %s PC 0x%" PRIx32
"\n",
9325 write_type
== CPSRWriteExceptionReturn
?
9326 "Exception return from AArch32" :
9327 "AArch32 mode switch from",
9328 aarch32_mode_name(env
->uncached_cpsr
),
9329 aarch32_mode_name(val
), env
->regs
[15]);
9330 switch_mode(env
, val
& CPSR_M
);
9333 mask
&= ~CACHED_CPSR_BITS
;
9334 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~mask
) | (val
& mask
);
9337 /* Sign/zero extend */
9338 uint32_t HELPER(sxtb16
)(uint32_t x
)
9341 res
= (uint16_t)(int8_t)x
;
9342 res
|= (uint32_t)(int8_t)(x
>> 16) << 16;
9346 uint32_t HELPER(uxtb16
)(uint32_t x
)
9349 res
= (uint16_t)(uint8_t)x
;
9350 res
|= (uint32_t)(uint8_t)(x
>> 16) << 16;
9354 int32_t HELPER(sdiv
)(int32_t num
, int32_t den
)
9358 if (num
== INT_MIN
&& den
== -1)
9363 uint32_t HELPER(udiv
)(uint32_t num
, uint32_t den
)
9370 uint32_t HELPER(rbit
)(uint32_t x
)
9375 #ifdef CONFIG_USER_ONLY
9377 static void switch_mode(CPUARMState
*env
, int mode
)
9379 ARMCPU
*cpu
= env_archcpu(env
);
9381 if (mode
!= ARM_CPU_MODE_USR
) {
9382 cpu_abort(CPU(cpu
), "Tried to switch out of user mode\n");
9386 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
9387 uint32_t cur_el
, bool secure
)
9392 void aarch64_sync_64_to_32(CPUARMState
*env
)
9394 g_assert_not_reached();
9399 static void switch_mode(CPUARMState
*env
, int mode
)
9404 old_mode
= env
->uncached_cpsr
& CPSR_M
;
9405 if (mode
== old_mode
)
9408 if (old_mode
== ARM_CPU_MODE_FIQ
) {
9409 memcpy (env
->fiq_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
9410 memcpy (env
->regs
+ 8, env
->usr_regs
, 5 * sizeof(uint32_t));
9411 } else if (mode
== ARM_CPU_MODE_FIQ
) {
9412 memcpy (env
->usr_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
9413 memcpy (env
->regs
+ 8, env
->fiq_regs
, 5 * sizeof(uint32_t));
9416 i
= bank_number(old_mode
);
9417 env
->banked_r13
[i
] = env
->regs
[13];
9418 env
->banked_spsr
[i
] = env
->spsr
;
9420 i
= bank_number(mode
);
9421 env
->regs
[13] = env
->banked_r13
[i
];
9422 env
->spsr
= env
->banked_spsr
[i
];
9424 env
->banked_r14
[r14_bank_number(old_mode
)] = env
->regs
[14];
9425 env
->regs
[14] = env
->banked_r14
[r14_bank_number(mode
)];
9428 /* Physical Interrupt Target EL Lookup Table
9430 * [ From ARM ARM section G1.13.4 (Table G1-15) ]
9432 * The below multi-dimensional table is used for looking up the target
9433 * exception level given numerous condition criteria. Specifically, the
9434 * target EL is based on SCR and HCR routing controls as well as the
9435 * currently executing EL and secure state.
9438 * target_el_table[2][2][2][2][2][4]
9439 * | | | | | +--- Current EL
9440 * | | | | +------ Non-secure(0)/Secure(1)
9441 * | | | +--------- HCR mask override
9442 * | | +------------ SCR exec state control
9443 * | +--------------- SCR mask override
9444 * +------------------ 32-bit(0)/64-bit(1) EL3
9446 * The table values are as such:
9450 * The ARM ARM target EL table includes entries indicating that an "exception
9451 * is not taken". The two cases where this is applicable are:
9452 * 1) An exception is taken from EL3 but the SCR does not have the exception
9454 * 2) An exception is taken from EL2 but the HCR does not have the exception
9456 * In these two cases, the below table contain a target of EL1. This value is
9457 * returned as it is expected that the consumer of the table data will check
9458 * for "target EL >= current EL" to ensure the exception is not taken.
9462 * BIT IRQ IMO Non-secure Secure
9463 * EL3 FIQ RW FMO EL0 EL1 EL2 EL3 EL0 EL1 EL2 EL3
9465 static const int8_t target_el_table
[2][2][2][2][2][4] = {
9466 {{{{/* 0 0 0 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
9467 {/* 0 0 0 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},
9468 {{/* 0 0 1 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
9469 {/* 0 0 1 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},},
9470 {{{/* 0 1 0 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
9471 {/* 0 1 0 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},
9472 {{/* 0 1 1 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
9473 {/* 0 1 1 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},},},
9474 {{{{/* 1 0 0 0 */{ 1, 1, 2, -1 },{ 1, 1, -1, 1 },},
9475 {/* 1 0 0 1 */{ 2, 2, 2, -1 },{ 2, 2, -1, 1 },},},
9476 {{/* 1 0 1 0 */{ 1, 1, 1, -1 },{ 1, 1, 1, 1 },},
9477 {/* 1 0 1 1 */{ 2, 2, 2, -1 },{ 2, 2, 2, 1 },},},},
9478 {{{/* 1 1 0 0 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},
9479 {/* 1 1 0 1 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},},
9480 {{/* 1 1 1 0 */{ 3, 3, 3, -1 },{ 3, 3, 3, 3 },},
9481 {/* 1 1 1 1 */{ 3, 3, 3, -1 },{ 3, 3, 3, 3 },},},},},
9485 * Determine the target EL for physical exceptions
9487 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
9488 uint32_t cur_el
, bool secure
)
9490 CPUARMState
*env
= cs
->env_ptr
;
9495 /* Is the highest EL AArch64? */
9496 bool is64
= arm_feature(env
, ARM_FEATURE_AARCH64
);
9499 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
9500 rw
= ((env
->cp15
.scr_el3
& SCR_RW
) == SCR_RW
);
9502 /* Either EL2 is the highest EL (and so the EL2 register width
9503 * is given by is64); or there is no EL2 or EL3, in which case
9504 * the value of 'rw' does not affect the table lookup anyway.
9509 hcr_el2
= arm_hcr_el2_eff(env
);
9512 scr
= ((env
->cp15
.scr_el3
& SCR_IRQ
) == SCR_IRQ
);
9513 hcr
= hcr_el2
& HCR_IMO
;
9516 scr
= ((env
->cp15
.scr_el3
& SCR_FIQ
) == SCR_FIQ
);
9517 hcr
= hcr_el2
& HCR_FMO
;
9520 scr
= ((env
->cp15
.scr_el3
& SCR_EA
) == SCR_EA
);
9521 hcr
= hcr_el2
& HCR_AMO
;
9526 * For these purposes, TGE and AMO/IMO/FMO both force the
9527 * interrupt to EL2. Fold TGE into the bit extracted above.
9529 hcr
|= (hcr_el2
& HCR_TGE
) != 0;
9531 /* Perform a table-lookup for the target EL given the current state */
9532 target_el
= target_el_table
[is64
][scr
][rw
][hcr
][secure
][cur_el
];
9534 assert(target_el
> 0);
9539 void arm_log_exception(int idx
)
9541 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
9542 const char *exc
= NULL
;
9543 static const char * const excnames
[] = {
9544 [EXCP_UDEF
] = "Undefined Instruction",
9546 [EXCP_PREFETCH_ABORT
] = "Prefetch Abort",
9547 [EXCP_DATA_ABORT
] = "Data Abort",
9550 [EXCP_BKPT
] = "Breakpoint",
9551 [EXCP_EXCEPTION_EXIT
] = "QEMU v7M exception exit",
9552 [EXCP_KERNEL_TRAP
] = "QEMU intercept of kernel commpage",
9553 [EXCP_HVC
] = "Hypervisor Call",
9554 [EXCP_HYP_TRAP
] = "Hypervisor Trap",
9555 [EXCP_SMC
] = "Secure Monitor Call",
9556 [EXCP_VIRQ
] = "Virtual IRQ",
9557 [EXCP_VFIQ
] = "Virtual FIQ",
9558 [EXCP_SEMIHOST
] = "Semihosting call",
9559 [EXCP_NOCP
] = "v7M NOCP UsageFault",
9560 [EXCP_INVSTATE
] = "v7M INVSTATE UsageFault",
9561 [EXCP_STKOF
] = "v8M STKOF UsageFault",
9562 [EXCP_LAZYFP
] = "v7M exception during lazy FP stacking",
9563 [EXCP_LSERR
] = "v8M LSERR UsageFault",
9564 [EXCP_UNALIGNED
] = "v7M UNALIGNED UsageFault",
9567 if (idx
>= 0 && idx
< ARRAY_SIZE(excnames
)) {
9568 exc
= excnames
[idx
];
9573 qemu_log_mask(CPU_LOG_INT
, "Taking exception %d [%s]\n", idx
, exc
);
9578 * Function used to synchronize QEMU's AArch64 register set with AArch32
9579 * register set. This is necessary when switching between AArch32 and AArch64
9582 void aarch64_sync_32_to_64(CPUARMState
*env
)
9585 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
9587 /* We can blanket copy R[0:7] to X[0:7] */
9588 for (i
= 0; i
< 8; i
++) {
9589 env
->xregs
[i
] = env
->regs
[i
];
9593 * Unless we are in FIQ mode, x8-x12 come from the user registers r8-r12.
9594 * Otherwise, they come from the banked user regs.
9596 if (mode
== ARM_CPU_MODE_FIQ
) {
9597 for (i
= 8; i
< 13; i
++) {
9598 env
->xregs
[i
] = env
->usr_regs
[i
- 8];
9601 for (i
= 8; i
< 13; i
++) {
9602 env
->xregs
[i
] = env
->regs
[i
];
9607 * Registers x13-x23 are the various mode SP and FP registers. Registers
9608 * r13 and r14 are only copied if we are in that mode, otherwise we copy
9609 * from the mode banked register.
9611 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
9612 env
->xregs
[13] = env
->regs
[13];
9613 env
->xregs
[14] = env
->regs
[14];
9615 env
->xregs
[13] = env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)];
9616 /* HYP is an exception in that it is copied from r14 */
9617 if (mode
== ARM_CPU_MODE_HYP
) {
9618 env
->xregs
[14] = env
->regs
[14];
9620 env
->xregs
[14] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_USR
)];
9624 if (mode
== ARM_CPU_MODE_HYP
) {
9625 env
->xregs
[15] = env
->regs
[13];
9627 env
->xregs
[15] = env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)];
9630 if (mode
== ARM_CPU_MODE_IRQ
) {
9631 env
->xregs
[16] = env
->regs
[14];
9632 env
->xregs
[17] = env
->regs
[13];
9634 env
->xregs
[16] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_IRQ
)];
9635 env
->xregs
[17] = env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)];
9638 if (mode
== ARM_CPU_MODE_SVC
) {
9639 env
->xregs
[18] = env
->regs
[14];
9640 env
->xregs
[19] = env
->regs
[13];
9642 env
->xregs
[18] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_SVC
)];
9643 env
->xregs
[19] = env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)];
9646 if (mode
== ARM_CPU_MODE_ABT
) {
9647 env
->xregs
[20] = env
->regs
[14];
9648 env
->xregs
[21] = env
->regs
[13];
9650 env
->xregs
[20] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_ABT
)];
9651 env
->xregs
[21] = env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)];
9654 if (mode
== ARM_CPU_MODE_UND
) {
9655 env
->xregs
[22] = env
->regs
[14];
9656 env
->xregs
[23] = env
->regs
[13];
9658 env
->xregs
[22] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_UND
)];
9659 env
->xregs
[23] = env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)];
9663 * Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
9664 * mode, then we can copy from r8-r14. Otherwise, we copy from the
9665 * FIQ bank for r8-r14.
9667 if (mode
== ARM_CPU_MODE_FIQ
) {
9668 for (i
= 24; i
< 31; i
++) {
9669 env
->xregs
[i
] = env
->regs
[i
- 16]; /* X[24:30] <- R[8:14] */
9672 for (i
= 24; i
< 29; i
++) {
9673 env
->xregs
[i
] = env
->fiq_regs
[i
- 24];
9675 env
->xregs
[29] = env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)];
9676 env
->xregs
[30] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_FIQ
)];
9679 env
->pc
= env
->regs
[15];
9683 * Function used to synchronize QEMU's AArch32 register set with AArch64
9684 * register set. This is necessary when switching between AArch32 and AArch64
9687 void aarch64_sync_64_to_32(CPUARMState
*env
)
9690 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
9692 /* We can blanket copy X[0:7] to R[0:7] */
9693 for (i
= 0; i
< 8; i
++) {
9694 env
->regs
[i
] = env
->xregs
[i
];
9698 * Unless we are in FIQ mode, r8-r12 come from the user registers x8-x12.
9699 * Otherwise, we copy x8-x12 into the banked user regs.
9701 if (mode
== ARM_CPU_MODE_FIQ
) {
9702 for (i
= 8; i
< 13; i
++) {
9703 env
->usr_regs
[i
- 8] = env
->xregs
[i
];
9706 for (i
= 8; i
< 13; i
++) {
9707 env
->regs
[i
] = env
->xregs
[i
];
9712 * Registers r13 & r14 depend on the current mode.
9713 * If we are in a given mode, we copy the corresponding x registers to r13
9714 * and r14. Otherwise, we copy the x register to the banked r13 and r14
9717 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
9718 env
->regs
[13] = env
->xregs
[13];
9719 env
->regs
[14] = env
->xregs
[14];
9721 env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[13];
9724 * HYP is an exception in that it does not have its own banked r14 but
9725 * shares the USR r14
9727 if (mode
== ARM_CPU_MODE_HYP
) {
9728 env
->regs
[14] = env
->xregs
[14];
9730 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[14];
9734 if (mode
== ARM_CPU_MODE_HYP
) {
9735 env
->regs
[13] = env
->xregs
[15];
9737 env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)] = env
->xregs
[15];
9740 if (mode
== ARM_CPU_MODE_IRQ
) {
9741 env
->regs
[14] = env
->xregs
[16];
9742 env
->regs
[13] = env
->xregs
[17];
9744 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[16];
9745 env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[17];
9748 if (mode
== ARM_CPU_MODE_SVC
) {
9749 env
->regs
[14] = env
->xregs
[18];
9750 env
->regs
[13] = env
->xregs
[19];
9752 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[18];
9753 env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[19];
9756 if (mode
== ARM_CPU_MODE_ABT
) {
9757 env
->regs
[14] = env
->xregs
[20];
9758 env
->regs
[13] = env
->xregs
[21];
9760 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[20];
9761 env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[21];
9764 if (mode
== ARM_CPU_MODE_UND
) {
9765 env
->regs
[14] = env
->xregs
[22];
9766 env
->regs
[13] = env
->xregs
[23];
9768 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[22];
9769 env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[23];
9772 /* Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
9773 * mode, then we can copy to r8-r14. Otherwise, we copy to the
9774 * FIQ bank for r8-r14.
9776 if (mode
== ARM_CPU_MODE_FIQ
) {
9777 for (i
= 24; i
< 31; i
++) {
9778 env
->regs
[i
- 16] = env
->xregs
[i
]; /* X[24:30] -> R[8:14] */
9781 for (i
= 24; i
< 29; i
++) {
9782 env
->fiq_regs
[i
- 24] = env
->xregs
[i
];
9784 env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[29];
9785 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[30];
9788 env
->regs
[15] = env
->pc
;
9791 static void take_aarch32_exception(CPUARMState
*env
, int new_mode
,
9792 uint32_t mask
, uint32_t offset
,
9797 /* Change the CPU state so as to actually take the exception. */
9798 switch_mode(env
, new_mode
);
9801 * For exceptions taken to AArch32 we must clear the SS bit in both
9802 * PSTATE and in the old-state value we save to SPSR_<mode>, so zero it now.
9804 env
->pstate
&= ~PSTATE_SS
;
9805 env
->spsr
= cpsr_read(env
);
9806 /* Clear IT bits. */
9807 env
->condexec_bits
= 0;
9808 /* Switch to the new mode, and to the correct instruction set. */
9809 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~CPSR_M
) | new_mode
;
9811 /* This must be after mode switching. */
9812 new_el
= arm_current_el(env
);
9814 /* Set new mode endianness */
9815 env
->uncached_cpsr
&= ~CPSR_E
;
9816 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_EE
) {
9817 env
->uncached_cpsr
|= CPSR_E
;
9819 /* J and IL must always be cleared for exception entry */
9820 env
->uncached_cpsr
&= ~(CPSR_IL
| CPSR_J
);
9823 if (cpu_isar_feature(aa32_ssbs
, env_archcpu(env
))) {
9824 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_DSSBS_32
) {
9825 env
->uncached_cpsr
|= CPSR_SSBS
;
9827 env
->uncached_cpsr
&= ~CPSR_SSBS
;
9831 if (new_mode
== ARM_CPU_MODE_HYP
) {
9832 env
->thumb
= (env
->cp15
.sctlr_el
[2] & SCTLR_TE
) != 0;
9833 env
->elr_el
[2] = env
->regs
[15];
9835 /* CPSR.PAN is normally preserved preserved unless... */
9836 if (cpu_isar_feature(aa32_pan
, env_archcpu(env
))) {
9839 if (!arm_is_secure_below_el3(env
)) {
9840 /* ... the target is EL3, from non-secure state. */
9841 env
->uncached_cpsr
&= ~CPSR_PAN
;
9844 /* ... the target is EL3, from secure state ... */
9847 /* ... the target is EL1 and SCTLR.SPAN is 0. */
9848 if (!(env
->cp15
.sctlr_el
[new_el
] & SCTLR_SPAN
)) {
9849 env
->uncached_cpsr
|= CPSR_PAN
;
9855 * this is a lie, as there was no c1_sys on V4T/V5, but who cares
9856 * and we should just guard the thumb mode on V4
9858 if (arm_feature(env
, ARM_FEATURE_V4T
)) {
9860 (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_TE
) != 0;
9862 env
->regs
[14] = env
->regs
[15] + offset
;
9864 env
->regs
[15] = newpc
;
9865 arm_rebuild_hflags(env
);
9868 static void arm_cpu_do_interrupt_aarch32_hyp(CPUState
*cs
)
9871 * Handle exception entry to Hyp mode; this is sufficiently
9872 * different to entry to other AArch32 modes that we handle it
9875 * The vector table entry used is always the 0x14 Hyp mode entry point,
9876 * unless this is an UNDEF/HVC/abort taken from Hyp to Hyp.
9877 * The offset applied to the preferred return address is always zero
9878 * (see DDI0487C.a section G1.12.3).
9879 * PSTATE A/I/F masks are set based only on the SCR.EA/IRQ/FIQ values.
9881 uint32_t addr
, mask
;
9882 ARMCPU
*cpu
= ARM_CPU(cs
);
9883 CPUARMState
*env
= &cpu
->env
;
9885 switch (cs
->exception_index
) {
9893 /* Fall through to prefetch abort. */
9894 case EXCP_PREFETCH_ABORT
:
9895 env
->cp15
.ifar_s
= env
->exception
.vaddress
;
9896 qemu_log_mask(CPU_LOG_INT
, "...with HIFAR 0x%x\n",
9897 (uint32_t)env
->exception
.vaddress
);
9900 case EXCP_DATA_ABORT
:
9901 env
->cp15
.dfar_s
= env
->exception
.vaddress
;
9902 qemu_log_mask(CPU_LOG_INT
, "...with HDFAR 0x%x\n",
9903 (uint32_t)env
->exception
.vaddress
);
9919 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
9922 if (cs
->exception_index
!= EXCP_IRQ
&& cs
->exception_index
!= EXCP_FIQ
) {
9923 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
9925 * QEMU syndrome values are v8-style. v7 has the IL bit
9926 * UNK/SBZP for "field not valid" cases, where v8 uses RES1.
9927 * If this is a v7 CPU, squash the IL bit in those cases.
9929 if (cs
->exception_index
== EXCP_PREFETCH_ABORT
||
9930 (cs
->exception_index
== EXCP_DATA_ABORT
&&
9931 !(env
->exception
.syndrome
& ARM_EL_ISV
)) ||
9932 syn_get_ec(env
->exception
.syndrome
) == EC_UNCATEGORIZED
) {
9933 env
->exception
.syndrome
&= ~ARM_EL_IL
;
9936 env
->cp15
.esr_el
[2] = env
->exception
.syndrome
;
9939 if (arm_current_el(env
) != 2 && addr
< 0x14) {
9944 if (!(env
->cp15
.scr_el3
& SCR_EA
)) {
9947 if (!(env
->cp15
.scr_el3
& SCR_IRQ
)) {
9950 if (!(env
->cp15
.scr_el3
& SCR_FIQ
)) {
9954 addr
+= env
->cp15
.hvbar
;
9956 take_aarch32_exception(env
, ARM_CPU_MODE_HYP
, mask
, 0, addr
);
9959 static void arm_cpu_do_interrupt_aarch32(CPUState
*cs
)
9961 ARMCPU
*cpu
= ARM_CPU(cs
);
9962 CPUARMState
*env
= &cpu
->env
;
9969 /* If this is a debug exception we must update the DBGDSCR.MOE bits */
9970 switch (syn_get_ec(env
->exception
.syndrome
)) {
9972 case EC_BREAKPOINT_SAME_EL
:
9976 case EC_WATCHPOINT_SAME_EL
:
9982 case EC_VECTORCATCH
:
9991 env
->cp15
.mdscr_el1
= deposit64(env
->cp15
.mdscr_el1
, 2, 4, moe
);
9994 if (env
->exception
.target_el
== 2) {
9995 arm_cpu_do_interrupt_aarch32_hyp(cs
);
9999 switch (cs
->exception_index
) {
10001 new_mode
= ARM_CPU_MODE_UND
;
10010 new_mode
= ARM_CPU_MODE_SVC
;
10013 /* The PC already points to the next instruction. */
10017 /* Fall through to prefetch abort. */
10018 case EXCP_PREFETCH_ABORT
:
10019 A32_BANKED_CURRENT_REG_SET(env
, ifsr
, env
->exception
.fsr
);
10020 A32_BANKED_CURRENT_REG_SET(env
, ifar
, env
->exception
.vaddress
);
10021 qemu_log_mask(CPU_LOG_INT
, "...with IFSR 0x%x IFAR 0x%x\n",
10022 env
->exception
.fsr
, (uint32_t)env
->exception
.vaddress
);
10023 new_mode
= ARM_CPU_MODE_ABT
;
10025 mask
= CPSR_A
| CPSR_I
;
10028 case EXCP_DATA_ABORT
:
10029 A32_BANKED_CURRENT_REG_SET(env
, dfsr
, env
->exception
.fsr
);
10030 A32_BANKED_CURRENT_REG_SET(env
, dfar
, env
->exception
.vaddress
);
10031 qemu_log_mask(CPU_LOG_INT
, "...with DFSR 0x%x DFAR 0x%x\n",
10032 env
->exception
.fsr
,
10033 (uint32_t)env
->exception
.vaddress
);
10034 new_mode
= ARM_CPU_MODE_ABT
;
10036 mask
= CPSR_A
| CPSR_I
;
10040 new_mode
= ARM_CPU_MODE_IRQ
;
10042 /* Disable IRQ and imprecise data aborts. */
10043 mask
= CPSR_A
| CPSR_I
;
10045 if (env
->cp15
.scr_el3
& SCR_IRQ
) {
10046 /* IRQ routed to monitor mode */
10047 new_mode
= ARM_CPU_MODE_MON
;
10052 new_mode
= ARM_CPU_MODE_FIQ
;
10054 /* Disable FIQ, IRQ and imprecise data aborts. */
10055 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
10056 if (env
->cp15
.scr_el3
& SCR_FIQ
) {
10057 /* FIQ routed to monitor mode */
10058 new_mode
= ARM_CPU_MODE_MON
;
10063 new_mode
= ARM_CPU_MODE_IRQ
;
10065 /* Disable IRQ and imprecise data aborts. */
10066 mask
= CPSR_A
| CPSR_I
;
10070 new_mode
= ARM_CPU_MODE_FIQ
;
10072 /* Disable FIQ, IRQ and imprecise data aborts. */
10073 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
10077 new_mode
= ARM_CPU_MODE_MON
;
10079 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
10083 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
10084 return; /* Never happens. Keep compiler happy. */
10087 if (new_mode
== ARM_CPU_MODE_MON
) {
10088 addr
+= env
->cp15
.mvbar
;
10089 } else if (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_V
) {
10090 /* High vectors. When enabled, base address cannot be remapped. */
10091 addr
+= 0xffff0000;
10093 /* ARM v7 architectures provide a vector base address register to remap
10094 * the interrupt vector table.
10095 * This register is only followed in non-monitor mode, and is banked.
10096 * Note: only bits 31:5 are valid.
10098 addr
+= A32_BANKED_CURRENT_REG_GET(env
, vbar
);
10101 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
) {
10102 env
->cp15
.scr_el3
&= ~SCR_NS
;
10105 take_aarch32_exception(env
, new_mode
, mask
, offset
, addr
);
10108 static int aarch64_regnum(CPUARMState
*env
, int aarch32_reg
)
10111 * Return the register number of the AArch64 view of the AArch32
10112 * register @aarch32_reg. The CPUARMState CPSR is assumed to still
10113 * be that of the AArch32 mode the exception came from.
10115 int mode
= env
->uncached_cpsr
& CPSR_M
;
10117 switch (aarch32_reg
) {
10119 return aarch32_reg
;
10121 return mode
== ARM_CPU_MODE_FIQ
? aarch32_reg
+ 16 : aarch32_reg
;
10124 case ARM_CPU_MODE_USR
:
10125 case ARM_CPU_MODE_SYS
:
10127 case ARM_CPU_MODE_HYP
:
10129 case ARM_CPU_MODE_IRQ
:
10131 case ARM_CPU_MODE_SVC
:
10133 case ARM_CPU_MODE_ABT
:
10135 case ARM_CPU_MODE_UND
:
10137 case ARM_CPU_MODE_FIQ
:
10140 g_assert_not_reached();
10144 case ARM_CPU_MODE_USR
:
10145 case ARM_CPU_MODE_SYS
:
10146 case ARM_CPU_MODE_HYP
:
10148 case ARM_CPU_MODE_IRQ
:
10150 case ARM_CPU_MODE_SVC
:
10152 case ARM_CPU_MODE_ABT
:
10154 case ARM_CPU_MODE_UND
:
10156 case ARM_CPU_MODE_FIQ
:
10159 g_assert_not_reached();
10164 g_assert_not_reached();
10168 static uint32_t cpsr_read_for_spsr_elx(CPUARMState
*env
)
10170 uint32_t ret
= cpsr_read(env
);
10172 /* Move DIT to the correct location for SPSR_ELx */
10173 if (ret
& CPSR_DIT
) {
10177 /* Merge PSTATE.SS into SPSR_ELx */
10178 ret
|= env
->pstate
& PSTATE_SS
;
10183 /* Handle exception entry to a target EL which is using AArch64 */
10184 static void arm_cpu_do_interrupt_aarch64(CPUState
*cs
)
10186 ARMCPU
*cpu
= ARM_CPU(cs
);
10187 CPUARMState
*env
= &cpu
->env
;
10188 unsigned int new_el
= env
->exception
.target_el
;
10189 target_ulong addr
= env
->cp15
.vbar_el
[new_el
];
10190 unsigned int new_mode
= aarch64_pstate_mode(new_el
, true);
10191 unsigned int old_mode
;
10192 unsigned int cur_el
= arm_current_el(env
);
10196 * Note that new_el can never be 0. If cur_el is 0, then
10197 * el0_a64 is is_a64(), else el0_a64 is ignored.
10199 aarch64_sve_change_el(env
, cur_el
, new_el
, is_a64(env
));
10201 if (cur_el
< new_el
) {
10202 /* Entry vector offset depends on whether the implemented EL
10203 * immediately lower than the target level is using AArch32 or AArch64
10210 is_aa64
= (env
->cp15
.scr_el3
& SCR_RW
) != 0;
10213 hcr
= arm_hcr_el2_eff(env
);
10214 if ((hcr
& (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
10215 is_aa64
= (hcr
& HCR_RW
) != 0;
10220 is_aa64
= is_a64(env
);
10223 g_assert_not_reached();
10231 } else if (pstate_read(env
) & PSTATE_SP
) {
10235 switch (cs
->exception_index
) {
10236 case EXCP_PREFETCH_ABORT
:
10237 case EXCP_DATA_ABORT
:
10238 env
->cp15
.far_el
[new_el
] = env
->exception
.vaddress
;
10239 qemu_log_mask(CPU_LOG_INT
, "...with FAR 0x%" PRIx64
"\n",
10240 env
->cp15
.far_el
[new_el
]);
10246 case EXCP_HYP_TRAP
:
10248 switch (syn_get_ec(env
->exception
.syndrome
)) {
10249 case EC_ADVSIMDFPACCESSTRAP
:
10251 * QEMU internal FP/SIMD syndromes from AArch32 include the
10252 * TA and coproc fields which are only exposed if the exception
10253 * is taken to AArch32 Hyp mode. Mask them out to get a valid
10254 * AArch64 format syndrome.
10256 env
->exception
.syndrome
&= ~MAKE_64BIT_MASK(0, 20);
10258 case EC_CP14RTTRAP
:
10259 case EC_CP15RTTRAP
:
10260 case EC_CP14DTTRAP
:
10262 * For a trap on AArch32 MRC/MCR/LDC/STC the Rt field is currently
10263 * the raw register field from the insn; when taking this to
10264 * AArch64 we must convert it to the AArch64 view of the register
10265 * number. Notice that we read a 4-bit AArch32 register number and
10266 * write back a 5-bit AArch64 one.
10268 rt
= extract32(env
->exception
.syndrome
, 5, 4);
10269 rt
= aarch64_regnum(env
, rt
);
10270 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
10273 case EC_CP15RRTTRAP
:
10274 case EC_CP14RRTTRAP
:
10275 /* Similarly for MRRC/MCRR traps for Rt and Rt2 fields */
10276 rt
= extract32(env
->exception
.syndrome
, 5, 4);
10277 rt
= aarch64_regnum(env
, rt
);
10278 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
10280 rt
= extract32(env
->exception
.syndrome
, 10, 4);
10281 rt
= aarch64_regnum(env
, rt
);
10282 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
10286 env
->cp15
.esr_el
[new_el
] = env
->exception
.syndrome
;
10297 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
10301 old_mode
= pstate_read(env
);
10302 aarch64_save_sp(env
, arm_current_el(env
));
10303 env
->elr_el
[new_el
] = env
->pc
;
10305 old_mode
= cpsr_read_for_spsr_elx(env
);
10306 env
->elr_el
[new_el
] = env
->regs
[15];
10308 aarch64_sync_32_to_64(env
);
10310 env
->condexec_bits
= 0;
10312 env
->banked_spsr
[aarch64_banked_spsr_index(new_el
)] = old_mode
;
10314 qemu_log_mask(CPU_LOG_INT
, "...with ELR 0x%" PRIx64
"\n",
10315 env
->elr_el
[new_el
]);
10317 if (cpu_isar_feature(aa64_pan
, cpu
)) {
10318 /* The value of PSTATE.PAN is normally preserved, except when ... */
10319 new_mode
|= old_mode
& PSTATE_PAN
;
10322 /* ... the target is EL2 with HCR_EL2.{E2H,TGE} == '11' ... */
10323 if ((arm_hcr_el2_eff(env
) & (HCR_E2H
| HCR_TGE
))
10324 != (HCR_E2H
| HCR_TGE
)) {
10329 /* ... the target is EL1 ... */
10330 /* ... and SCTLR_ELx.SPAN == 0, then set to 1. */
10331 if ((env
->cp15
.sctlr_el
[new_el
] & SCTLR_SPAN
) == 0) {
10332 new_mode
|= PSTATE_PAN
;
10337 if (cpu_isar_feature(aa64_mte
, cpu
)) {
10338 new_mode
|= PSTATE_TCO
;
10341 if (cpu_isar_feature(aa64_ssbs
, cpu
)) {
10342 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_DSSBS_64
) {
10343 new_mode
|= PSTATE_SSBS
;
10345 new_mode
&= ~PSTATE_SSBS
;
10349 pstate_write(env
, PSTATE_DAIF
| new_mode
);
10351 aarch64_restore_sp(env
, new_el
);
10352 helper_rebuild_hflags_a64(env
, new_el
);
10356 qemu_log_mask(CPU_LOG_INT
, "...to EL%d PC 0x%" PRIx64
" PSTATE 0x%x\n",
10357 new_el
, env
->pc
, pstate_read(env
));
10361 * Do semihosting call and set the appropriate return value. All the
10362 * permission and validity checks have been done at translate time.
10364 * We only see semihosting exceptions in TCG only as they are not
10365 * trapped to the hypervisor in KVM.
10368 static void handle_semihosting(CPUState
*cs
)
10370 ARMCPU
*cpu
= ARM_CPU(cs
);
10371 CPUARMState
*env
= &cpu
->env
;
10374 qemu_log_mask(CPU_LOG_INT
,
10375 "...handling as semihosting call 0x%" PRIx64
"\n",
10377 env
->xregs
[0] = do_common_semihosting(cs
);
10380 qemu_log_mask(CPU_LOG_INT
,
10381 "...handling as semihosting call 0x%x\n",
10383 env
->regs
[0] = do_common_semihosting(cs
);
10384 env
->regs
[15] += env
->thumb
? 2 : 4;
10389 /* Handle a CPU exception for A and R profile CPUs.
10390 * Do any appropriate logging, handle PSCI calls, and then hand off
10391 * to the AArch64-entry or AArch32-entry function depending on the
10392 * target exception level's register width.
10394 * Note: this is used for both TCG (as the do_interrupt tcg op),
10395 * and KVM to re-inject guest debug exceptions, and to
10396 * inject a Synchronous-External-Abort.
10398 void arm_cpu_do_interrupt(CPUState
*cs
)
10400 ARMCPU
*cpu
= ARM_CPU(cs
);
10401 CPUARMState
*env
= &cpu
->env
;
10402 unsigned int new_el
= env
->exception
.target_el
;
10404 assert(!arm_feature(env
, ARM_FEATURE_M
));
10406 arm_log_exception(cs
->exception_index
);
10407 qemu_log_mask(CPU_LOG_INT
, "...from EL%d to EL%d\n", arm_current_el(env
),
10409 if (qemu_loglevel_mask(CPU_LOG_INT
)
10410 && !excp_is_internal(cs
->exception_index
)) {
10411 qemu_log_mask(CPU_LOG_INT
, "...with ESR 0x%x/0x%" PRIx32
"\n",
10412 syn_get_ec(env
->exception
.syndrome
),
10413 env
->exception
.syndrome
);
10416 if (arm_is_psci_call(cpu
, cs
->exception_index
)) {
10417 arm_handle_psci_call(cpu
);
10418 qemu_log_mask(CPU_LOG_INT
, "...handled as PSCI call\n");
10423 * Semihosting semantics depend on the register width of the code
10424 * that caused the exception, not the target exception level, so
10425 * must be handled here.
10428 if (cs
->exception_index
== EXCP_SEMIHOST
) {
10429 handle_semihosting(cs
);
10434 /* Hooks may change global state so BQL should be held, also the
10435 * BQL needs to be held for any modification of
10436 * cs->interrupt_request.
10438 g_assert(qemu_mutex_iothread_locked());
10440 arm_call_pre_el_change_hook(cpu
);
10442 assert(!excp_is_internal(cs
->exception_index
));
10443 if (arm_el_is_aa64(env
, new_el
)) {
10444 arm_cpu_do_interrupt_aarch64(cs
);
10446 arm_cpu_do_interrupt_aarch32(cs
);
10449 arm_call_el_change_hook(cpu
);
10451 if (!kvm_enabled()) {
10452 cs
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
10455 #endif /* !CONFIG_USER_ONLY */
10457 uint64_t arm_sctlr(CPUARMState
*env
, int el
)
10459 /* Only EL0 needs to be adjusted for EL1&0 or EL2&0. */
10461 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, 0);
10462 el
= (mmu_idx
== ARMMMUIdx_E20_0
|| mmu_idx
== ARMMMUIdx_SE20_0
)
10465 return env
->cp15
.sctlr_el
[el
];
10468 /* Return the SCTLR value which controls this address translation regime */
10469 static inline uint64_t regime_sctlr(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
10471 return env
->cp15
.sctlr_el
[regime_el(env
, mmu_idx
)];
10474 #ifndef CONFIG_USER_ONLY
10476 /* Return true if the specified stage of address translation is disabled */
10477 static inline bool regime_translation_disabled(CPUARMState
*env
,
10482 if (arm_feature(env
, ARM_FEATURE_M
)) {
10483 switch (env
->v7m
.mpu_ctrl
[regime_is_secure(env
, mmu_idx
)] &
10484 (R_V7M_MPU_CTRL_ENABLE_MASK
| R_V7M_MPU_CTRL_HFNMIENA_MASK
)) {
10485 case R_V7M_MPU_CTRL_ENABLE_MASK
:
10486 /* Enabled, but not for HardFault and NMI */
10487 return mmu_idx
& ARM_MMU_IDX_M_NEGPRI
;
10488 case R_V7M_MPU_CTRL_ENABLE_MASK
| R_V7M_MPU_CTRL_HFNMIENA_MASK
:
10489 /* Enabled for all cases */
10493 /* HFNMIENA set and ENABLE clear is UNPREDICTABLE, but
10494 * we warned about that in armv7m_nvic.c when the guest set it.
10500 hcr_el2
= arm_hcr_el2_eff(env
);
10502 if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
10503 /* HCR.DC means HCR.VM behaves as 1 */
10504 return (hcr_el2
& (HCR_DC
| HCR_VM
)) == 0;
10507 if (hcr_el2
& HCR_TGE
) {
10508 /* TGE means that NS EL0/1 act as if SCTLR_EL1.M is zero */
10509 if (!regime_is_secure(env
, mmu_idx
) && regime_el(env
, mmu_idx
) == 1) {
10514 if ((hcr_el2
& HCR_DC
) && arm_mmu_idx_is_stage1_of_2(mmu_idx
)) {
10515 /* HCR.DC means SCTLR_EL1.M behaves as 0 */
10519 return (regime_sctlr(env
, mmu_idx
) & SCTLR_M
) == 0;
10522 static inline bool regime_translation_big_endian(CPUARMState
*env
,
10525 return (regime_sctlr(env
, mmu_idx
) & SCTLR_EE
) != 0;
10528 /* Return the TTBR associated with this translation regime */
10529 static inline uint64_t regime_ttbr(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
10532 if (mmu_idx
== ARMMMUIdx_Stage2
) {
10533 return env
->cp15
.vttbr_el2
;
10535 if (mmu_idx
== ARMMMUIdx_Stage2_S
) {
10536 return env
->cp15
.vsttbr_el2
;
10539 return env
->cp15
.ttbr0_el
[regime_el(env
, mmu_idx
)];
10541 return env
->cp15
.ttbr1_el
[regime_el(env
, mmu_idx
)];
10545 #endif /* !CONFIG_USER_ONLY */
10547 /* Convert a possible stage1+2 MMU index into the appropriate
10548 * stage 1 MMU index
10550 static inline ARMMMUIdx
stage_1_mmu_idx(ARMMMUIdx mmu_idx
)
10553 case ARMMMUIdx_SE10_0
:
10554 return ARMMMUIdx_Stage1_SE0
;
10555 case ARMMMUIdx_SE10_1
:
10556 return ARMMMUIdx_Stage1_SE1
;
10557 case ARMMMUIdx_SE10_1_PAN
:
10558 return ARMMMUIdx_Stage1_SE1_PAN
;
10559 case ARMMMUIdx_E10_0
:
10560 return ARMMMUIdx_Stage1_E0
;
10561 case ARMMMUIdx_E10_1
:
10562 return ARMMMUIdx_Stage1_E1
;
10563 case ARMMMUIdx_E10_1_PAN
:
10564 return ARMMMUIdx_Stage1_E1_PAN
;
10570 /* Return true if the translation regime is using LPAE format page tables */
10571 static inline bool regime_using_lpae_format(CPUARMState
*env
,
10574 int el
= regime_el(env
, mmu_idx
);
10575 if (el
== 2 || arm_el_is_aa64(env
, el
)) {
10578 if (arm_feature(env
, ARM_FEATURE_LPAE
)
10579 && (regime_tcr(env
, mmu_idx
)->raw_tcr
& TTBCR_EAE
)) {
10585 /* Returns true if the stage 1 translation regime is using LPAE format page
10586 * tables. Used when raising alignment exceptions, whose FSR changes depending
10587 * on whether the long or short descriptor format is in use. */
10588 bool arm_s1_regime_using_lpae_format(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
10590 mmu_idx
= stage_1_mmu_idx(mmu_idx
);
10592 return regime_using_lpae_format(env
, mmu_idx
);
10595 #ifndef CONFIG_USER_ONLY
10596 static inline bool regime_is_user(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
10599 case ARMMMUIdx_SE10_0
:
10600 case ARMMMUIdx_E20_0
:
10601 case ARMMMUIdx_SE20_0
:
10602 case ARMMMUIdx_Stage1_E0
:
10603 case ARMMMUIdx_Stage1_SE0
:
10604 case ARMMMUIdx_MUser
:
10605 case ARMMMUIdx_MSUser
:
10606 case ARMMMUIdx_MUserNegPri
:
10607 case ARMMMUIdx_MSUserNegPri
:
10611 case ARMMMUIdx_E10_0
:
10612 case ARMMMUIdx_E10_1
:
10613 case ARMMMUIdx_E10_1_PAN
:
10614 g_assert_not_reached();
10618 /* Translate section/page access permissions to page
10619 * R/W protection flags
10621 * @env: CPUARMState
10622 * @mmu_idx: MMU index indicating required translation regime
10623 * @ap: The 3-bit access permissions (AP[2:0])
10624 * @domain_prot: The 2-bit domain access permissions
10626 static inline int ap_to_rw_prot(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
10627 int ap
, int domain_prot
)
10629 bool is_user
= regime_is_user(env
, mmu_idx
);
10631 if (domain_prot
== 3) {
10632 return PAGE_READ
| PAGE_WRITE
;
10637 if (arm_feature(env
, ARM_FEATURE_V7
)) {
10640 switch (regime_sctlr(env
, mmu_idx
) & (SCTLR_S
| SCTLR_R
)) {
10642 return is_user
? 0 : PAGE_READ
;
10649 return is_user
? 0 : PAGE_READ
| PAGE_WRITE
;
10654 return PAGE_READ
| PAGE_WRITE
;
10657 return PAGE_READ
| PAGE_WRITE
;
10658 case 4: /* Reserved. */
10661 return is_user
? 0 : PAGE_READ
;
10665 if (!arm_feature(env
, ARM_FEATURE_V6K
)) {
10670 g_assert_not_reached();
10674 /* Translate section/page access permissions to page
10675 * R/W protection flags.
10677 * @ap: The 2-bit simple AP (AP[2:1])
10678 * @is_user: TRUE if accessing from PL0
10680 static inline int simple_ap_to_rw_prot_is_user(int ap
, bool is_user
)
10684 return is_user
? 0 : PAGE_READ
| PAGE_WRITE
;
10686 return PAGE_READ
| PAGE_WRITE
;
10688 return is_user
? 0 : PAGE_READ
;
10692 g_assert_not_reached();
10697 simple_ap_to_rw_prot(CPUARMState
*env
, ARMMMUIdx mmu_idx
, int ap
)
10699 return simple_ap_to_rw_prot_is_user(ap
, regime_is_user(env
, mmu_idx
));
10702 /* Translate S2 section/page access permissions to protection flags
10704 * @env: CPUARMState
10705 * @s2ap: The 2-bit stage2 access permissions (S2AP)
10706 * @xn: XN (execute-never) bits
10707 * @s1_is_el0: true if this is S2 of an S1+2 walk for EL0
10709 static int get_S2prot(CPUARMState
*env
, int s2ap
, int xn
, bool s1_is_el0
)
10717 prot
|= PAGE_WRITE
;
10720 if (cpu_isar_feature(any_tts2uxn
, env_archcpu(env
))) {
10738 g_assert_not_reached();
10741 if (!extract32(xn
, 1, 1)) {
10742 if (arm_el_is_aa64(env
, 2) || prot
& PAGE_READ
) {
10750 /* Translate section/page access permissions to protection flags
10752 * @env: CPUARMState
10753 * @mmu_idx: MMU index indicating required translation regime
10754 * @is_aa64: TRUE if AArch64
10755 * @ap: The 2-bit simple AP (AP[2:1])
10756 * @ns: NS (non-secure) bit
10757 * @xn: XN (execute-never) bit
10758 * @pxn: PXN (privileged execute-never) bit
10760 static int get_S1prot(CPUARMState
*env
, ARMMMUIdx mmu_idx
, bool is_aa64
,
10761 int ap
, int ns
, int xn
, int pxn
)
10763 bool is_user
= regime_is_user(env
, mmu_idx
);
10764 int prot_rw
, user_rw
;
10768 assert(mmu_idx
!= ARMMMUIdx_Stage2
);
10769 assert(mmu_idx
!= ARMMMUIdx_Stage2_S
);
10771 user_rw
= simple_ap_to_rw_prot_is_user(ap
, true);
10775 if (user_rw
&& regime_is_pan(env
, mmu_idx
)) {
10776 /* PAN forbids data accesses but doesn't affect insn fetch */
10779 prot_rw
= simple_ap_to_rw_prot_is_user(ap
, false);
10783 if (ns
&& arm_is_secure(env
) && (env
->cp15
.scr_el3
& SCR_SIF
)) {
10787 /* TODO have_wxn should be replaced with
10788 * ARM_FEATURE_V8 || (ARM_FEATURE_V7 && ARM_FEATURE_EL2)
10789 * when ARM_FEATURE_EL2 starts getting set. For now we assume all LPAE
10790 * compatible processors have EL2, which is required for [U]WXN.
10792 have_wxn
= arm_feature(env
, ARM_FEATURE_LPAE
);
10795 wxn
= regime_sctlr(env
, mmu_idx
) & SCTLR_WXN
;
10799 if (regime_has_2_ranges(mmu_idx
) && !is_user
) {
10800 xn
= pxn
|| (user_rw
& PAGE_WRITE
);
10802 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
10803 switch (regime_el(env
, mmu_idx
)) {
10807 xn
= xn
|| !(user_rw
& PAGE_READ
);
10811 uwxn
= regime_sctlr(env
, mmu_idx
) & SCTLR_UWXN
;
10813 xn
= xn
|| !(prot_rw
& PAGE_READ
) || pxn
||
10814 (uwxn
&& (user_rw
& PAGE_WRITE
));
10824 if (xn
|| (wxn
&& (prot_rw
& PAGE_WRITE
))) {
10827 return prot_rw
| PAGE_EXEC
;
10830 static bool get_level1_table_address(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
10831 uint32_t *table
, uint32_t address
)
10833 /* Note that we can only get here for an AArch32 PL0/PL1 lookup */
10834 TCR
*tcr
= regime_tcr(env
, mmu_idx
);
10836 if (address
& tcr
->mask
) {
10837 if (tcr
->raw_tcr
& TTBCR_PD1
) {
10838 /* Translation table walk disabled for TTBR1 */
10841 *table
= regime_ttbr(env
, mmu_idx
, 1) & 0xffffc000;
10843 if (tcr
->raw_tcr
& TTBCR_PD0
) {
10844 /* Translation table walk disabled for TTBR0 */
10847 *table
= regime_ttbr(env
, mmu_idx
, 0) & tcr
->base_mask
;
10849 *table
|= (address
>> 18) & 0x3ffc;
10853 /* Translate a S1 pagetable walk through S2 if needed. */
10854 static hwaddr
S1_ptw_translate(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
10855 hwaddr addr
, bool *is_secure
,
10856 ARMMMUFaultInfo
*fi
)
10858 if (arm_mmu_idx_is_stage1_of_2(mmu_idx
) &&
10859 !regime_translation_disabled(env
, ARMMMUIdx_Stage2
)) {
10860 target_ulong s2size
;
10864 ARMMMUIdx s2_mmu_idx
= *is_secure
? ARMMMUIdx_Stage2_S
10865 : ARMMMUIdx_Stage2
;
10866 ARMCacheAttrs cacheattrs
= {};
10867 MemTxAttrs txattrs
= {};
10869 ret
= get_phys_addr_lpae(env
, addr
, MMU_DATA_LOAD
, s2_mmu_idx
, false,
10870 &s2pa
, &txattrs
, &s2prot
, &s2size
, fi
,
10873 assert(fi
->type
!= ARMFault_None
);
10877 fi
->s1ns
= !*is_secure
;
10880 if ((arm_hcr_el2_eff(env
) & HCR_PTW
) &&
10881 (cacheattrs
.attrs
& 0xf0) == 0) {
10883 * PTW set and S1 walk touched S2 Device memory:
10884 * generate Permission fault.
10886 fi
->type
= ARMFault_Permission
;
10890 fi
->s1ns
= !*is_secure
;
10894 if (arm_is_secure_below_el3(env
)) {
10895 /* Check if page table walk is to secure or non-secure PA space. */
10897 *is_secure
= !(env
->cp15
.vstcr_el2
.raw_tcr
& VSTCR_SW
);
10899 *is_secure
= !(env
->cp15
.vtcr_el2
.raw_tcr
& VTCR_NSW
);
10902 assert(!*is_secure
);
10910 /* All loads done in the course of a page table walk go through here. */
10911 static uint32_t arm_ldl_ptw(CPUState
*cs
, hwaddr addr
, bool is_secure
,
10912 ARMMMUIdx mmu_idx
, ARMMMUFaultInfo
*fi
)
10914 ARMCPU
*cpu
= ARM_CPU(cs
);
10915 CPUARMState
*env
= &cpu
->env
;
10916 MemTxAttrs attrs
= {};
10917 MemTxResult result
= MEMTX_OK
;
10921 addr
= S1_ptw_translate(env
, mmu_idx
, addr
, &is_secure
, fi
);
10922 attrs
.secure
= is_secure
;
10923 as
= arm_addressspace(cs
, attrs
);
10927 if (regime_translation_big_endian(env
, mmu_idx
)) {
10928 data
= address_space_ldl_be(as
, addr
, attrs
, &result
);
10930 data
= address_space_ldl_le(as
, addr
, attrs
, &result
);
10932 if (result
== MEMTX_OK
) {
10935 fi
->type
= ARMFault_SyncExternalOnWalk
;
10936 fi
->ea
= arm_extabort_type(result
);
10940 static uint64_t arm_ldq_ptw(CPUState
*cs
, hwaddr addr
, bool is_secure
,
10941 ARMMMUIdx mmu_idx
, ARMMMUFaultInfo
*fi
)
10943 ARMCPU
*cpu
= ARM_CPU(cs
);
10944 CPUARMState
*env
= &cpu
->env
;
10945 MemTxAttrs attrs
= {};
10946 MemTxResult result
= MEMTX_OK
;
10950 addr
= S1_ptw_translate(env
, mmu_idx
, addr
, &is_secure
, fi
);
10951 attrs
.secure
= is_secure
;
10952 as
= arm_addressspace(cs
, attrs
);
10956 if (regime_translation_big_endian(env
, mmu_idx
)) {
10957 data
= address_space_ldq_be(as
, addr
, attrs
, &result
);
10959 data
= address_space_ldq_le(as
, addr
, attrs
, &result
);
10961 if (result
== MEMTX_OK
) {
10964 fi
->type
= ARMFault_SyncExternalOnWalk
;
10965 fi
->ea
= arm_extabort_type(result
);
10969 static bool get_phys_addr_v5(CPUARMState
*env
, uint32_t address
,
10970 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
10971 hwaddr
*phys_ptr
, int *prot
,
10972 target_ulong
*page_size
,
10973 ARMMMUFaultInfo
*fi
)
10975 CPUState
*cs
= env_cpu(env
);
10986 /* Pagetable walk. */
10987 /* Lookup l1 descriptor. */
10988 if (!get_level1_table_address(env
, mmu_idx
, &table
, address
)) {
10989 /* Section translation fault if page walk is disabled by PD0 or PD1 */
10990 fi
->type
= ARMFault_Translation
;
10993 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
10995 if (fi
->type
!= ARMFault_None
) {
10999 domain
= (desc
>> 5) & 0x0f;
11000 if (regime_el(env
, mmu_idx
) == 1) {
11001 dacr
= env
->cp15
.dacr_ns
;
11003 dacr
= env
->cp15
.dacr_s
;
11005 domain_prot
= (dacr
>> (domain
* 2)) & 3;
11007 /* Section translation fault. */
11008 fi
->type
= ARMFault_Translation
;
11014 if (domain_prot
== 0 || domain_prot
== 2) {
11015 fi
->type
= ARMFault_Domain
;
11020 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
11021 ap
= (desc
>> 10) & 3;
11022 *page_size
= 1024 * 1024;
11024 /* Lookup l2 entry. */
11026 /* Coarse pagetable. */
11027 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
11029 /* Fine pagetable. */
11030 table
= (desc
& 0xfffff000) | ((address
>> 8) & 0xffc);
11032 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
11034 if (fi
->type
!= ARMFault_None
) {
11037 switch (desc
& 3) {
11038 case 0: /* Page translation fault. */
11039 fi
->type
= ARMFault_Translation
;
11041 case 1: /* 64k page. */
11042 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
11043 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
11044 *page_size
= 0x10000;
11046 case 2: /* 4k page. */
11047 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
11048 ap
= (desc
>> (4 + ((address
>> 9) & 6))) & 3;
11049 *page_size
= 0x1000;
11051 case 3: /* 1k page, or ARMv6/XScale "extended small (4k) page" */
11053 /* ARMv6/XScale extended small page format */
11054 if (arm_feature(env
, ARM_FEATURE_XSCALE
)
11055 || arm_feature(env
, ARM_FEATURE_V6
)) {
11056 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
11057 *page_size
= 0x1000;
11059 /* UNPREDICTABLE in ARMv5; we choose to take a
11060 * page translation fault.
11062 fi
->type
= ARMFault_Translation
;
11066 phys_addr
= (desc
& 0xfffffc00) | (address
& 0x3ff);
11067 *page_size
= 0x400;
11069 ap
= (desc
>> 4) & 3;
11072 /* Never happens, but compiler isn't smart enough to tell. */
11076 *prot
= ap_to_rw_prot(env
, mmu_idx
, ap
, domain_prot
);
11077 *prot
|= *prot
? PAGE_EXEC
: 0;
11078 if (!(*prot
& (1 << access_type
))) {
11079 /* Access permission fault. */
11080 fi
->type
= ARMFault_Permission
;
11083 *phys_ptr
= phys_addr
;
11086 fi
->domain
= domain
;
11091 static bool get_phys_addr_v6(CPUARMState
*env
, uint32_t address
,
11092 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
11093 hwaddr
*phys_ptr
, MemTxAttrs
*attrs
, int *prot
,
11094 target_ulong
*page_size
, ARMMMUFaultInfo
*fi
)
11096 CPUState
*cs
= env_cpu(env
);
11097 ARMCPU
*cpu
= env_archcpu(env
);
11111 /* Pagetable walk. */
11112 /* Lookup l1 descriptor. */
11113 if (!get_level1_table_address(env
, mmu_idx
, &table
, address
)) {
11114 /* Section translation fault if page walk is disabled by PD0 or PD1 */
11115 fi
->type
= ARMFault_Translation
;
11118 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
11120 if (fi
->type
!= ARMFault_None
) {
11124 if (type
== 0 || (type
== 3 && !cpu_isar_feature(aa32_pxn
, cpu
))) {
11125 /* Section translation fault, or attempt to use the encoding
11126 * which is Reserved on implementations without PXN.
11128 fi
->type
= ARMFault_Translation
;
11131 if ((type
== 1) || !(desc
& (1 << 18))) {
11132 /* Page or Section. */
11133 domain
= (desc
>> 5) & 0x0f;
11135 if (regime_el(env
, mmu_idx
) == 1) {
11136 dacr
= env
->cp15
.dacr_ns
;
11138 dacr
= env
->cp15
.dacr_s
;
11143 domain_prot
= (dacr
>> (domain
* 2)) & 3;
11144 if (domain_prot
== 0 || domain_prot
== 2) {
11145 /* Section or Page domain fault */
11146 fi
->type
= ARMFault_Domain
;
11150 if (desc
& (1 << 18)) {
11151 /* Supersection. */
11152 phys_addr
= (desc
& 0xff000000) | (address
& 0x00ffffff);
11153 phys_addr
|= (uint64_t)extract32(desc
, 20, 4) << 32;
11154 phys_addr
|= (uint64_t)extract32(desc
, 5, 4) << 36;
11155 *page_size
= 0x1000000;
11158 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
11159 *page_size
= 0x100000;
11161 ap
= ((desc
>> 10) & 3) | ((desc
>> 13) & 4);
11162 xn
= desc
& (1 << 4);
11164 ns
= extract32(desc
, 19, 1);
11166 if (cpu_isar_feature(aa32_pxn
, cpu
)) {
11167 pxn
= (desc
>> 2) & 1;
11169 ns
= extract32(desc
, 3, 1);
11170 /* Lookup l2 entry. */
11171 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
11172 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
11174 if (fi
->type
!= ARMFault_None
) {
11177 ap
= ((desc
>> 4) & 3) | ((desc
>> 7) & 4);
11178 switch (desc
& 3) {
11179 case 0: /* Page translation fault. */
11180 fi
->type
= ARMFault_Translation
;
11182 case 1: /* 64k page. */
11183 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
11184 xn
= desc
& (1 << 15);
11185 *page_size
= 0x10000;
11187 case 2: case 3: /* 4k page. */
11188 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
11190 *page_size
= 0x1000;
11193 /* Never happens, but compiler isn't smart enough to tell. */
11197 if (domain_prot
== 3) {
11198 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
11200 if (pxn
&& !regime_is_user(env
, mmu_idx
)) {
11203 if (xn
&& access_type
== MMU_INST_FETCH
) {
11204 fi
->type
= ARMFault_Permission
;
11208 if (arm_feature(env
, ARM_FEATURE_V6K
) &&
11209 (regime_sctlr(env
, mmu_idx
) & SCTLR_AFE
)) {
11210 /* The simplified model uses AP[0] as an access control bit. */
11211 if ((ap
& 1) == 0) {
11212 /* Access flag fault. */
11213 fi
->type
= ARMFault_AccessFlag
;
11216 *prot
= simple_ap_to_rw_prot(env
, mmu_idx
, ap
>> 1);
11218 *prot
= ap_to_rw_prot(env
, mmu_idx
, ap
, domain_prot
);
11220 if (*prot
&& !xn
) {
11221 *prot
|= PAGE_EXEC
;
11223 if (!(*prot
& (1 << access_type
))) {
11224 /* Access permission fault. */
11225 fi
->type
= ARMFault_Permission
;
11230 /* The NS bit will (as required by the architecture) have no effect if
11231 * the CPU doesn't support TZ or this is a non-secure translation
11232 * regime, because the attribute will already be non-secure.
11234 attrs
->secure
= false;
11236 *phys_ptr
= phys_addr
;
11239 fi
->domain
= domain
;
11245 * check_s2_mmu_setup
11247 * @is_aa64: True if the translation regime is in AArch64 state
11248 * @startlevel: Suggested starting level
11249 * @inputsize: Bitsize of IPAs
11250 * @stride: Page-table stride (See the ARM ARM)
11252 * Returns true if the suggested S2 translation parameters are OK and
11255 static bool check_s2_mmu_setup(ARMCPU
*cpu
, bool is_aa64
, int level
,
11256 int inputsize
, int stride
)
11258 const int grainsize
= stride
+ 3;
11259 int startsizecheck
;
11261 /* Negative levels are never allowed. */
11266 startsizecheck
= inputsize
- ((3 - level
) * stride
+ grainsize
);
11267 if (startsizecheck
< 1 || startsizecheck
> stride
+ 4) {
11272 CPUARMState
*env
= &cpu
->env
;
11273 unsigned int pamax
= arm_pamax(cpu
);
11276 case 13: /* 64KB Pages. */
11277 if (level
== 0 || (level
== 1 && pamax
<= 42)) {
11281 case 11: /* 16KB Pages. */
11282 if (level
== 0 || (level
== 1 && pamax
<= 40)) {
11286 case 9: /* 4KB Pages. */
11287 if (level
== 0 && pamax
<= 42) {
11292 g_assert_not_reached();
11295 /* Inputsize checks. */
11296 if (inputsize
> pamax
&&
11297 (arm_el_is_aa64(env
, 1) || inputsize
> 40)) {
11298 /* This is CONSTRAINED UNPREDICTABLE and we choose to fault. */
11302 /* AArch32 only supports 4KB pages. Assert on that. */
11303 assert(stride
== 9);
11312 /* Translate from the 4-bit stage 2 representation of
11313 * memory attributes (without cache-allocation hints) to
11314 * the 8-bit representation of the stage 1 MAIR registers
11315 * (which includes allocation hints).
11317 * ref: shared/translation/attrs/S2AttrDecode()
11318 * .../S2ConvertAttrsHints()
11320 static uint8_t convert_stage2_attrs(CPUARMState
*env
, uint8_t s2attrs
)
11322 uint8_t hiattr
= extract32(s2attrs
, 2, 2);
11323 uint8_t loattr
= extract32(s2attrs
, 0, 2);
11324 uint8_t hihint
= 0, lohint
= 0;
11326 if (hiattr
!= 0) { /* normal memory */
11327 if (arm_hcr_el2_eff(env
) & HCR_CD
) { /* cache disabled */
11328 hiattr
= loattr
= 1; /* non-cacheable */
11330 if (hiattr
!= 1) { /* Write-through or write-back */
11331 hihint
= 3; /* RW allocate */
11333 if (loattr
!= 1) { /* Write-through or write-back */
11334 lohint
= 3; /* RW allocate */
11339 return (hiattr
<< 6) | (hihint
<< 4) | (loattr
<< 2) | lohint
;
11341 #endif /* !CONFIG_USER_ONLY */
11343 static int aa64_va_parameter_tbi(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11345 if (regime_has_2_ranges(mmu_idx
)) {
11346 return extract64(tcr
, 37, 2);
11347 } else if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11348 return 0; /* VTCR_EL2 */
11350 /* Replicate the single TBI bit so we always have 2 bits. */
11351 return extract32(tcr
, 20, 1) * 3;
11355 static int aa64_va_parameter_tbid(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11357 if (regime_has_2_ranges(mmu_idx
)) {
11358 return extract64(tcr
, 51, 2);
11359 } else if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11360 return 0; /* VTCR_EL2 */
11362 /* Replicate the single TBID bit so we always have 2 bits. */
11363 return extract32(tcr
, 29, 1) * 3;
11367 static int aa64_va_parameter_tcma(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11369 if (regime_has_2_ranges(mmu_idx
)) {
11370 return extract64(tcr
, 57, 2);
11372 /* Replicate the single TCMA bit so we always have 2 bits. */
11373 return extract32(tcr
, 30, 1) * 3;
11377 ARMVAParameters
aa64_va_parameters(CPUARMState
*env
, uint64_t va
,
11378 ARMMMUIdx mmu_idx
, bool data
)
11380 uint64_t tcr
= regime_tcr(env
, mmu_idx
)->raw_tcr
;
11381 bool epd
, hpd
, using16k
, using64k
;
11382 int select
, tsz
, tbi
, max_tsz
;
11384 if (!regime_has_2_ranges(mmu_idx
)) {
11386 tsz
= extract32(tcr
, 0, 6);
11387 using64k
= extract32(tcr
, 14, 1);
11388 using16k
= extract32(tcr
, 15, 1);
11389 if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11393 hpd
= extract32(tcr
, 24, 1);
11398 * Bit 55 is always between the two regions, and is canonical for
11399 * determining if address tagging is enabled.
11401 select
= extract64(va
, 55, 1);
11403 tsz
= extract32(tcr
, 0, 6);
11404 epd
= extract32(tcr
, 7, 1);
11405 using64k
= extract32(tcr
, 14, 1);
11406 using16k
= extract32(tcr
, 15, 1);
11407 hpd
= extract64(tcr
, 41, 1);
11409 int tg
= extract32(tcr
, 30, 2);
11410 using16k
= tg
== 1;
11411 using64k
= tg
== 3;
11412 tsz
= extract32(tcr
, 16, 6);
11413 epd
= extract32(tcr
, 23, 1);
11414 hpd
= extract64(tcr
, 42, 1);
11418 if (cpu_isar_feature(aa64_st
, env_archcpu(env
))) {
11419 max_tsz
= 48 - using64k
;
11424 tsz
= MIN(tsz
, max_tsz
);
11425 tsz
= MAX(tsz
, 16); /* TODO: ARMv8.2-LVA */
11427 /* Present TBI as a composite with TBID. */
11428 tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
11430 tbi
&= ~aa64_va_parameter_tbid(tcr
, mmu_idx
);
11432 tbi
= (tbi
>> select
) & 1;
11434 return (ARMVAParameters
) {
11440 .using16k
= using16k
,
11441 .using64k
= using64k
,
11445 #ifndef CONFIG_USER_ONLY
11446 static ARMVAParameters
aa32_va_parameters(CPUARMState
*env
, uint32_t va
,
11449 uint64_t tcr
= regime_tcr(env
, mmu_idx
)->raw_tcr
;
11450 uint32_t el
= regime_el(env
, mmu_idx
);
11454 assert(mmu_idx
!= ARMMMUIdx_Stage2_S
);
11456 if (mmu_idx
== ARMMMUIdx_Stage2
) {
11458 bool sext
= extract32(tcr
, 4, 1);
11459 bool sign
= extract32(tcr
, 3, 1);
11462 * If the sign-extend bit is not the same as t0sz[3], the result
11463 * is unpredictable. Flag this as a guest error.
11465 if (sign
!= sext
) {
11466 qemu_log_mask(LOG_GUEST_ERROR
,
11467 "AArch32: VTCR.S / VTCR.T0SZ[3] mismatch\n");
11469 tsz
= sextract32(tcr
, 0, 4) + 8;
11473 } else if (el
== 2) {
11475 tsz
= extract32(tcr
, 0, 3);
11477 hpd
= extract64(tcr
, 24, 1);
11480 int t0sz
= extract32(tcr
, 0, 3);
11481 int t1sz
= extract32(tcr
, 16, 3);
11484 select
= va
> (0xffffffffu
>> t0sz
);
11486 /* Note that we will detect errors later. */
11487 select
= va
>= ~(0xffffffffu
>> t1sz
);
11491 epd
= extract32(tcr
, 7, 1);
11492 hpd
= extract64(tcr
, 41, 1);
11495 epd
= extract32(tcr
, 23, 1);
11496 hpd
= extract64(tcr
, 42, 1);
11498 /* For aarch32, hpd0 is not enabled without t2e as well. */
11499 hpd
&= extract32(tcr
, 6, 1);
11502 return (ARMVAParameters
) {
11511 * get_phys_addr_lpae: perform one stage of page table walk, LPAE format
11513 * Returns false if the translation was successful. Otherwise, phys_ptr, attrs,
11514 * prot and page_size may not be filled in, and the populated fsr value provides
11515 * information on why the translation aborted, in the format of a long-format
11516 * DFSR/IFSR fault register, with the following caveats:
11517 * * the WnR bit is never set (the caller must do this).
11519 * @env: CPUARMState
11520 * @address: virtual address to get physical address for
11521 * @access_type: MMU_DATA_LOAD, MMU_DATA_STORE or MMU_INST_FETCH
11522 * @mmu_idx: MMU index indicating required translation regime
11523 * @s1_is_el0: if @mmu_idx is ARMMMUIdx_Stage2 (so this is a stage 2 page table
11524 * walk), must be true if this is stage 2 of a stage 1+2 walk for an
11525 * EL0 access). If @mmu_idx is anything else, @s1_is_el0 is ignored.
11526 * @phys_ptr: set to the physical address corresponding to the virtual address
11527 * @attrs: set to the memory transaction attributes to use
11528 * @prot: set to the permissions for the page containing phys_ptr
11529 * @page_size_ptr: set to the size of the page containing phys_ptr
11530 * @fi: set to fault info if the translation fails
11531 * @cacheattrs: (if non-NULL) set to the cacheability/shareability attributes
11533 static bool get_phys_addr_lpae(CPUARMState
*env
, uint64_t address
,
11534 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
11536 hwaddr
*phys_ptr
, MemTxAttrs
*txattrs
, int *prot
,
11537 target_ulong
*page_size_ptr
,
11538 ARMMMUFaultInfo
*fi
, ARMCacheAttrs
*cacheattrs
)
11540 ARMCPU
*cpu
= env_archcpu(env
);
11541 CPUState
*cs
= CPU(cpu
);
11542 /* Read an LPAE long-descriptor translation table. */
11543 ARMFaultType fault_type
= ARMFault_Translation
;
11545 ARMVAParameters param
;
11547 hwaddr descaddr
, indexmask
, indexmask_grainsize
;
11548 uint32_t tableattrs
;
11549 target_ulong page_size
;
11552 int addrsize
, inputsize
;
11553 TCR
*tcr
= regime_tcr(env
, mmu_idx
);
11554 int ap
, ns
, xn
, pxn
;
11555 uint32_t el
= regime_el(env
, mmu_idx
);
11556 uint64_t descaddrmask
;
11557 bool aarch64
= arm_el_is_aa64(env
, el
);
11558 bool guarded
= false;
11560 /* TODO: This code does not support shareability levels. */
11562 param
= aa64_va_parameters(env
, address
, mmu_idx
,
11563 access_type
!= MMU_INST_FETCH
);
11565 addrsize
= 64 - 8 * param
.tbi
;
11566 inputsize
= 64 - param
.tsz
;
11568 param
= aa32_va_parameters(env
, address
, mmu_idx
);
11570 addrsize
= (mmu_idx
== ARMMMUIdx_Stage2
? 40 : 32);
11571 inputsize
= addrsize
- param
.tsz
;
11575 * We determined the region when collecting the parameters, but we
11576 * have not yet validated that the address is valid for the region.
11577 * Extract the top bits and verify that they all match select.
11579 * For aa32, if inputsize == addrsize, then we have selected the
11580 * region by exclusion in aa32_va_parameters and there is no more
11581 * validation to do here.
11583 if (inputsize
< addrsize
) {
11584 target_ulong top_bits
= sextract64(address
, inputsize
,
11585 addrsize
- inputsize
);
11586 if (-top_bits
!= param
.select
) {
11587 /* The gap between the two regions is a Translation fault */
11588 fault_type
= ARMFault_Translation
;
11593 if (param
.using64k
) {
11595 } else if (param
.using16k
) {
11601 /* Note that QEMU ignores shareability and cacheability attributes,
11602 * so we don't need to do anything with the SH, ORGN, IRGN fields
11603 * in the TTBCR. Similarly, TTBCR:A1 selects whether we get the
11604 * ASID from TTBR0 or TTBR1, but QEMU's TLB doesn't currently
11605 * implement any ASID-like capability so we can ignore it (instead
11606 * we will always flush the TLB any time the ASID is changed).
11608 ttbr
= regime_ttbr(env
, mmu_idx
, param
.select
);
11610 /* Here we should have set up all the parameters for the translation:
11611 * inputsize, ttbr, epd, stride, tbi
11615 /* Translation table walk disabled => Translation fault on TLB miss
11616 * Note: This is always 0 on 64-bit EL2 and EL3.
11621 if (mmu_idx
!= ARMMMUIdx_Stage2
&& mmu_idx
!= ARMMMUIdx_Stage2_S
) {
11622 /* The starting level depends on the virtual address size (which can
11623 * be up to 48 bits) and the translation granule size. It indicates
11624 * the number of strides (stride bits at a time) needed to
11625 * consume the bits of the input address. In the pseudocode this is:
11626 * level = 4 - RoundUp((inputsize - grainsize) / stride)
11627 * where their 'inputsize' is our 'inputsize', 'grainsize' is
11628 * our 'stride + 3' and 'stride' is our 'stride'.
11629 * Applying the usual "rounded up m/n is (m+n-1)/n" and simplifying:
11630 * = 4 - (inputsize - stride - 3 + stride - 1) / stride
11631 * = 4 - (inputsize - 4) / stride;
11633 level
= 4 - (inputsize
- 4) / stride
;
11635 /* For stage 2 translations the starting level is specified by the
11636 * VTCR_EL2.SL0 field (whose interpretation depends on the page size)
11638 uint32_t sl0
= extract32(tcr
->raw_tcr
, 6, 2);
11639 uint32_t startlevel
;
11642 if (!aarch64
|| stride
== 9) {
11643 /* AArch32 or 4KB pages */
11644 startlevel
= 2 - sl0
;
11646 if (cpu_isar_feature(aa64_st
, cpu
)) {
11650 /* 16KB or 64KB pages */
11651 startlevel
= 3 - sl0
;
11654 /* Check that the starting level is valid. */
11655 ok
= check_s2_mmu_setup(cpu
, aarch64
, startlevel
,
11656 inputsize
, stride
);
11658 fault_type
= ARMFault_Translation
;
11661 level
= startlevel
;
11664 indexmask_grainsize
= (1ULL << (stride
+ 3)) - 1;
11665 indexmask
= (1ULL << (inputsize
- (stride
* (4 - level
)))) - 1;
11667 /* Now we can extract the actual base address from the TTBR */
11668 descaddr
= extract64(ttbr
, 0, 48);
11670 * We rely on this masking to clear the RES0 bits at the bottom of the TTBR
11671 * and also to mask out CnP (bit 0) which could validly be non-zero.
11673 descaddr
&= ~indexmask
;
11675 /* The address field in the descriptor goes up to bit 39 for ARMv7
11676 * but up to bit 47 for ARMv8, but we use the descaddrmask
11677 * up to bit 39 for AArch32, because we don't need other bits in that case
11678 * to construct next descriptor address (anyway they should be all zeroes).
11680 descaddrmask
= ((1ull << (aarch64
? 48 : 40)) - 1) &
11681 ~indexmask_grainsize
;
11683 /* Secure accesses start with the page table in secure memory and
11684 * can be downgraded to non-secure at any step. Non-secure accesses
11685 * remain non-secure. We implement this by just ORing in the NSTable/NS
11686 * bits at each step.
11688 tableattrs
= regime_is_secure(env
, mmu_idx
) ? 0 : (1 << 4);
11690 uint64_t descriptor
;
11693 descaddr
|= (address
>> (stride
* (4 - level
))) & indexmask
;
11695 nstable
= extract32(tableattrs
, 4, 1);
11696 descriptor
= arm_ldq_ptw(cs
, descaddr
, !nstable
, mmu_idx
, fi
);
11697 if (fi
->type
!= ARMFault_None
) {
11701 if (!(descriptor
& 1) ||
11702 (!(descriptor
& 2) && (level
== 3))) {
11703 /* Invalid, or the Reserved level 3 encoding */
11706 descaddr
= descriptor
& descaddrmask
;
11708 if ((descriptor
& 2) && (level
< 3)) {
11709 /* Table entry. The top five bits are attributes which may
11710 * propagate down through lower levels of the table (and
11711 * which are all arranged so that 0 means "no effect", so
11712 * we can gather them up by ORing in the bits at each level).
11714 tableattrs
|= extract64(descriptor
, 59, 5);
11716 indexmask
= indexmask_grainsize
;
11719 /* Block entry at level 1 or 2, or page entry at level 3.
11720 * These are basically the same thing, although the number
11721 * of bits we pull in from the vaddr varies.
11723 page_size
= (1ULL << ((stride
* (4 - level
)) + 3));
11724 descaddr
|= (address
& (page_size
- 1));
11725 /* Extract attributes from the descriptor */
11726 attrs
= extract64(descriptor
, 2, 10)
11727 | (extract64(descriptor
, 52, 12) << 10);
11729 if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11730 /* Stage 2 table descriptors do not include any attribute fields */
11733 /* Merge in attributes from table descriptors */
11734 attrs
|= nstable
<< 3; /* NS */
11735 guarded
= extract64(descriptor
, 50, 1); /* GP */
11737 /* HPD disables all the table attributes except NSTable. */
11740 attrs
|= extract32(tableattrs
, 0, 2) << 11; /* XN, PXN */
11741 /* The sense of AP[1] vs APTable[0] is reversed, as APTable[0] == 1
11742 * means "force PL1 access only", which means forcing AP[1] to 0.
11744 attrs
&= ~(extract32(tableattrs
, 2, 1) << 4); /* !APT[0] => AP[1] */
11745 attrs
|= extract32(tableattrs
, 3, 1) << 5; /* APT[1] => AP[2] */
11748 /* Here descaddr is the final physical address, and attributes
11749 * are all in attrs.
11751 fault_type
= ARMFault_AccessFlag
;
11752 if ((attrs
& (1 << 8)) == 0) {
11757 ap
= extract32(attrs
, 4, 2);
11759 if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11760 ns
= mmu_idx
== ARMMMUIdx_Stage2
;
11761 xn
= extract32(attrs
, 11, 2);
11762 *prot
= get_S2prot(env
, ap
, xn
, s1_is_el0
);
11764 ns
= extract32(attrs
, 3, 1);
11765 xn
= extract32(attrs
, 12, 1);
11766 pxn
= extract32(attrs
, 11, 1);
11767 *prot
= get_S1prot(env
, mmu_idx
, aarch64
, ap
, ns
, xn
, pxn
);
11770 fault_type
= ARMFault_Permission
;
11771 if (!(*prot
& (1 << access_type
))) {
11776 /* The NS bit will (as required by the architecture) have no effect if
11777 * the CPU doesn't support TZ or this is a non-secure translation
11778 * regime, because the attribute will already be non-secure.
11780 txattrs
->secure
= false;
11782 /* When in aarch64 mode, and BTI is enabled, remember GP in the IOTLB. */
11783 if (aarch64
&& guarded
&& cpu_isar_feature(aa64_bti
, cpu
)) {
11784 arm_tlb_bti_gp(txattrs
) = true;
11787 if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11788 cacheattrs
->attrs
= convert_stage2_attrs(env
, extract32(attrs
, 0, 4));
11790 /* Index into MAIR registers for cache attributes */
11791 uint8_t attrindx
= extract32(attrs
, 0, 3);
11792 uint64_t mair
= env
->cp15
.mair_el
[regime_el(env
, mmu_idx
)];
11793 assert(attrindx
<= 7);
11794 cacheattrs
->attrs
= extract64(mair
, attrindx
* 8, 8);
11796 cacheattrs
->shareability
= extract32(attrs
, 6, 2);
11798 *phys_ptr
= descaddr
;
11799 *page_size_ptr
= page_size
;
11803 fi
->type
= fault_type
;
11805 /* Tag the error as S2 for failed S1 PTW at S2 or ordinary S2. */
11806 fi
->stage2
= fi
->s1ptw
|| (mmu_idx
== ARMMMUIdx_Stage2
||
11807 mmu_idx
== ARMMMUIdx_Stage2_S
);
11808 fi
->s1ns
= mmu_idx
== ARMMMUIdx_Stage2
;
11812 static inline void get_phys_addr_pmsav7_default(CPUARMState
*env
,
11814 int32_t address
, int *prot
)
11816 if (!arm_feature(env
, ARM_FEATURE_M
)) {
11817 *prot
= PAGE_READ
| PAGE_WRITE
;
11819 case 0xF0000000 ... 0xFFFFFFFF:
11820 if (regime_sctlr(env
, mmu_idx
) & SCTLR_V
) {
11821 /* hivecs execing is ok */
11822 *prot
|= PAGE_EXEC
;
11825 case 0x00000000 ... 0x7FFFFFFF:
11826 *prot
|= PAGE_EXEC
;
11830 /* Default system address map for M profile cores.
11831 * The architecture specifies which regions are execute-never;
11832 * at the MPU level no other checks are defined.
11835 case 0x00000000 ... 0x1fffffff: /* ROM */
11836 case 0x20000000 ... 0x3fffffff: /* SRAM */
11837 case 0x60000000 ... 0x7fffffff: /* RAM */
11838 case 0x80000000 ... 0x9fffffff: /* RAM */
11839 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
11841 case 0x40000000 ... 0x5fffffff: /* Peripheral */
11842 case 0xa0000000 ... 0xbfffffff: /* Device */
11843 case 0xc0000000 ... 0xdfffffff: /* Device */
11844 case 0xe0000000 ... 0xffffffff: /* System */
11845 *prot
= PAGE_READ
| PAGE_WRITE
;
11848 g_assert_not_reached();
11853 static bool pmsav7_use_background_region(ARMCPU
*cpu
,
11854 ARMMMUIdx mmu_idx
, bool is_user
)
11856 /* Return true if we should use the default memory map as a
11857 * "background" region if there are no hits against any MPU regions.
11859 CPUARMState
*env
= &cpu
->env
;
11865 if (arm_feature(env
, ARM_FEATURE_M
)) {
11866 return env
->v7m
.mpu_ctrl
[regime_is_secure(env
, mmu_idx
)]
11867 & R_V7M_MPU_CTRL_PRIVDEFENA_MASK
;
11869 return regime_sctlr(env
, mmu_idx
) & SCTLR_BR
;
11873 static inline bool m_is_ppb_region(CPUARMState
*env
, uint32_t address
)
11875 /* True if address is in the M profile PPB region 0xe0000000 - 0xe00fffff */
11876 return arm_feature(env
, ARM_FEATURE_M
) &&
11877 extract32(address
, 20, 12) == 0xe00;
11880 static inline bool m_is_system_region(CPUARMState
*env
, uint32_t address
)
11882 /* True if address is in the M profile system region
11883 * 0xe0000000 - 0xffffffff
11885 return arm_feature(env
, ARM_FEATURE_M
) && extract32(address
, 29, 3) == 0x7;
11888 static bool get_phys_addr_pmsav7(CPUARMState
*env
, uint32_t address
,
11889 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
11890 hwaddr
*phys_ptr
, int *prot
,
11891 target_ulong
*page_size
,
11892 ARMMMUFaultInfo
*fi
)
11894 ARMCPU
*cpu
= env_archcpu(env
);
11896 bool is_user
= regime_is_user(env
, mmu_idx
);
11898 *phys_ptr
= address
;
11899 *page_size
= TARGET_PAGE_SIZE
;
11902 if (regime_translation_disabled(env
, mmu_idx
) ||
11903 m_is_ppb_region(env
, address
)) {
11904 /* MPU disabled or M profile PPB access: use default memory map.
11905 * The other case which uses the default memory map in the
11906 * v7M ARM ARM pseudocode is exception vector reads from the vector
11907 * table. In QEMU those accesses are done in arm_v7m_load_vector(),
11908 * which always does a direct read using address_space_ldl(), rather
11909 * than going via this function, so we don't need to check that here.
11911 get_phys_addr_pmsav7_default(env
, mmu_idx
, address
, prot
);
11912 } else { /* MPU enabled */
11913 for (n
= (int)cpu
->pmsav7_dregion
- 1; n
>= 0; n
--) {
11914 /* region search */
11915 uint32_t base
= env
->pmsav7
.drbar
[n
];
11916 uint32_t rsize
= extract32(env
->pmsav7
.drsr
[n
], 1, 5);
11918 bool srdis
= false;
11920 if (!(env
->pmsav7
.drsr
[n
] & 0x1)) {
11925 qemu_log_mask(LOG_GUEST_ERROR
,
11926 "DRSR[%d]: Rsize field cannot be 0\n", n
);
11930 rmask
= (1ull << rsize
) - 1;
11932 if (base
& rmask
) {
11933 qemu_log_mask(LOG_GUEST_ERROR
,
11934 "DRBAR[%d]: 0x%" PRIx32
" misaligned "
11935 "to DRSR region size, mask = 0x%" PRIx32
"\n",
11940 if (address
< base
|| address
> base
+ rmask
) {
11942 * Address not in this region. We must check whether the
11943 * region covers addresses in the same page as our address.
11944 * In that case we must not report a size that covers the
11945 * whole page for a subsequent hit against a different MPU
11946 * region or the background region, because it would result in
11947 * incorrect TLB hits for subsequent accesses to addresses that
11948 * are in this MPU region.
11950 if (ranges_overlap(base
, rmask
,
11951 address
& TARGET_PAGE_MASK
,
11952 TARGET_PAGE_SIZE
)) {
11958 /* Region matched */
11960 if (rsize
>= 8) { /* no subregions for regions < 256 bytes */
11962 uint32_t srdis_mask
;
11964 rsize
-= 3; /* sub region size (power of 2) */
11965 snd
= ((address
- base
) >> rsize
) & 0x7;
11966 srdis
= extract32(env
->pmsav7
.drsr
[n
], snd
+ 8, 1);
11968 srdis_mask
= srdis
? 0x3 : 0x0;
11969 for (i
= 2; i
<= 8 && rsize
< TARGET_PAGE_BITS
; i
*= 2) {
11970 /* This will check in groups of 2, 4 and then 8, whether
11971 * the subregion bits are consistent. rsize is incremented
11972 * back up to give the region size, considering consistent
11973 * adjacent subregions as one region. Stop testing if rsize
11974 * is already big enough for an entire QEMU page.
11976 int snd_rounded
= snd
& ~(i
- 1);
11977 uint32_t srdis_multi
= extract32(env
->pmsav7
.drsr
[n
],
11978 snd_rounded
+ 8, i
);
11979 if (srdis_mask
^ srdis_multi
) {
11982 srdis_mask
= (srdis_mask
<< i
) | srdis_mask
;
11989 if (rsize
< TARGET_PAGE_BITS
) {
11990 *page_size
= 1 << rsize
;
11995 if (n
== -1) { /* no hits */
11996 if (!pmsav7_use_background_region(cpu
, mmu_idx
, is_user
)) {
11997 /* background fault */
11998 fi
->type
= ARMFault_Background
;
12001 get_phys_addr_pmsav7_default(env
, mmu_idx
, address
, prot
);
12002 } else { /* a MPU hit! */
12003 uint32_t ap
= extract32(env
->pmsav7
.dracr
[n
], 8, 3);
12004 uint32_t xn
= extract32(env
->pmsav7
.dracr
[n
], 12, 1);
12006 if (m_is_system_region(env
, address
)) {
12007 /* System space is always execute never */
12011 if (is_user
) { /* User mode AP bit decoding */
12016 break; /* no access */
12018 *prot
|= PAGE_WRITE
;
12022 *prot
|= PAGE_READ
| PAGE_EXEC
;
12025 /* for v7M, same as 6; for R profile a reserved value */
12026 if (arm_feature(env
, ARM_FEATURE_M
)) {
12027 *prot
|= PAGE_READ
| PAGE_EXEC
;
12032 qemu_log_mask(LOG_GUEST_ERROR
,
12033 "DRACR[%d]: Bad value for AP bits: 0x%"
12034 PRIx32
"\n", n
, ap
);
12036 } else { /* Priv. mode AP bits decoding */
12039 break; /* no access */
12043 *prot
|= PAGE_WRITE
;
12047 *prot
|= PAGE_READ
| PAGE_EXEC
;
12050 /* for v7M, same as 6; for R profile a reserved value */
12051 if (arm_feature(env
, ARM_FEATURE_M
)) {
12052 *prot
|= PAGE_READ
| PAGE_EXEC
;
12057 qemu_log_mask(LOG_GUEST_ERROR
,
12058 "DRACR[%d]: Bad value for AP bits: 0x%"
12059 PRIx32
"\n", n
, ap
);
12063 /* execute never */
12065 *prot
&= ~PAGE_EXEC
;
12070 fi
->type
= ARMFault_Permission
;
12072 return !(*prot
& (1 << access_type
));
12075 static bool v8m_is_sau_exempt(CPUARMState
*env
,
12076 uint32_t address
, MMUAccessType access_type
)
12078 /* The architecture specifies that certain address ranges are
12079 * exempt from v8M SAU/IDAU checks.
12082 (access_type
== MMU_INST_FETCH
&& m_is_system_region(env
, address
)) ||
12083 (address
>= 0xe0000000 && address
<= 0xe0002fff) ||
12084 (address
>= 0xe000e000 && address
<= 0xe000efff) ||
12085 (address
>= 0xe002e000 && address
<= 0xe002efff) ||
12086 (address
>= 0xe0040000 && address
<= 0xe0041fff) ||
12087 (address
>= 0xe00ff000 && address
<= 0xe00fffff);
12090 void v8m_security_lookup(CPUARMState
*env
, uint32_t address
,
12091 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
12092 V8M_SAttributes
*sattrs
)
12094 /* Look up the security attributes for this address. Compare the
12095 * pseudocode SecurityCheck() function.
12096 * We assume the caller has zero-initialized *sattrs.
12098 ARMCPU
*cpu
= env_archcpu(env
);
12100 bool idau_exempt
= false, idau_ns
= true, idau_nsc
= true;
12101 int idau_region
= IREGION_NOTVALID
;
12102 uint32_t addr_page_base
= address
& TARGET_PAGE_MASK
;
12103 uint32_t addr_page_limit
= addr_page_base
+ (TARGET_PAGE_SIZE
- 1);
12106 IDAUInterfaceClass
*iic
= IDAU_INTERFACE_GET_CLASS(cpu
->idau
);
12107 IDAUInterface
*ii
= IDAU_INTERFACE(cpu
->idau
);
12109 iic
->check(ii
, address
, &idau_region
, &idau_exempt
, &idau_ns
,
12113 if (access_type
== MMU_INST_FETCH
&& extract32(address
, 28, 4) == 0xf) {
12114 /* 0xf0000000..0xffffffff is always S for insn fetches */
12118 if (idau_exempt
|| v8m_is_sau_exempt(env
, address
, access_type
)) {
12119 sattrs
->ns
= !regime_is_secure(env
, mmu_idx
);
12123 if (idau_region
!= IREGION_NOTVALID
) {
12124 sattrs
->irvalid
= true;
12125 sattrs
->iregion
= idau_region
;
12128 switch (env
->sau
.ctrl
& 3) {
12129 case 0: /* SAU.ENABLE == 0, SAU.ALLNS == 0 */
12131 case 2: /* SAU.ENABLE == 0, SAU.ALLNS == 1 */
12134 default: /* SAU.ENABLE == 1 */
12135 for (r
= 0; r
< cpu
->sau_sregion
; r
++) {
12136 if (env
->sau
.rlar
[r
] & 1) {
12137 uint32_t base
= env
->sau
.rbar
[r
] & ~0x1f;
12138 uint32_t limit
= env
->sau
.rlar
[r
] | 0x1f;
12140 if (base
<= address
&& limit
>= address
) {
12141 if (base
> addr_page_base
|| limit
< addr_page_limit
) {
12142 sattrs
->subpage
= true;
12144 if (sattrs
->srvalid
) {
12145 /* If we hit in more than one region then we must report
12146 * as Secure, not NS-Callable, with no valid region
12149 sattrs
->ns
= false;
12150 sattrs
->nsc
= false;
12151 sattrs
->sregion
= 0;
12152 sattrs
->srvalid
= false;
12155 if (env
->sau
.rlar
[r
] & 2) {
12156 sattrs
->nsc
= true;
12160 sattrs
->srvalid
= true;
12161 sattrs
->sregion
= r
;
12165 * Address not in this region. We must check whether the
12166 * region covers addresses in the same page as our address.
12167 * In that case we must not report a size that covers the
12168 * whole page for a subsequent hit against a different MPU
12169 * region or the background region, because it would result
12170 * in incorrect TLB hits for subsequent accesses to
12171 * addresses that are in this MPU region.
12173 if (limit
>= base
&&
12174 ranges_overlap(base
, limit
- base
+ 1,
12176 TARGET_PAGE_SIZE
)) {
12177 sattrs
->subpage
= true;
12186 * The IDAU will override the SAU lookup results if it specifies
12187 * higher security than the SAU does.
12190 if (sattrs
->ns
|| (!idau_nsc
&& sattrs
->nsc
)) {
12191 sattrs
->ns
= false;
12192 sattrs
->nsc
= idau_nsc
;
12197 bool pmsav8_mpu_lookup(CPUARMState
*env
, uint32_t address
,
12198 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
12199 hwaddr
*phys_ptr
, MemTxAttrs
*txattrs
,
12200 int *prot
, bool *is_subpage
,
12201 ARMMMUFaultInfo
*fi
, uint32_t *mregion
)
12203 /* Perform a PMSAv8 MPU lookup (without also doing the SAU check
12204 * that a full phys-to-virt translation does).
12205 * mregion is (if not NULL) set to the region number which matched,
12206 * or -1 if no region number is returned (MPU off, address did not
12207 * hit a region, address hit in multiple regions).
12208 * We set is_subpage to true if the region hit doesn't cover the
12209 * entire TARGET_PAGE the address is within.
12211 ARMCPU
*cpu
= env_archcpu(env
);
12212 bool is_user
= regime_is_user(env
, mmu_idx
);
12213 uint32_t secure
= regime_is_secure(env
, mmu_idx
);
12215 int matchregion
= -1;
12217 uint32_t addr_page_base
= address
& TARGET_PAGE_MASK
;
12218 uint32_t addr_page_limit
= addr_page_base
+ (TARGET_PAGE_SIZE
- 1);
12220 *is_subpage
= false;
12221 *phys_ptr
= address
;
12227 /* Unlike the ARM ARM pseudocode, we don't need to check whether this
12228 * was an exception vector read from the vector table (which is always
12229 * done using the default system address map), because those accesses
12230 * are done in arm_v7m_load_vector(), which always does a direct
12231 * read using address_space_ldl(), rather than going via this function.
12233 if (regime_translation_disabled(env
, mmu_idx
)) { /* MPU disabled */
12235 } else if (m_is_ppb_region(env
, address
)) {
12238 if (pmsav7_use_background_region(cpu
, mmu_idx
, is_user
)) {
12242 for (n
= (int)cpu
->pmsav7_dregion
- 1; n
>= 0; n
--) {
12243 /* region search */
12244 /* Note that the base address is bits [31:5] from the register
12245 * with bits [4:0] all zeroes, but the limit address is bits
12246 * [31:5] from the register with bits [4:0] all ones.
12248 uint32_t base
= env
->pmsav8
.rbar
[secure
][n
] & ~0x1f;
12249 uint32_t limit
= env
->pmsav8
.rlar
[secure
][n
] | 0x1f;
12251 if (!(env
->pmsav8
.rlar
[secure
][n
] & 0x1)) {
12252 /* Region disabled */
12256 if (address
< base
|| address
> limit
) {
12258 * Address not in this region. We must check whether the
12259 * region covers addresses in the same page as our address.
12260 * In that case we must not report a size that covers the
12261 * whole page for a subsequent hit against a different MPU
12262 * region or the background region, because it would result in
12263 * incorrect TLB hits for subsequent accesses to addresses that
12264 * are in this MPU region.
12266 if (limit
>= base
&&
12267 ranges_overlap(base
, limit
- base
+ 1,
12269 TARGET_PAGE_SIZE
)) {
12270 *is_subpage
= true;
12275 if (base
> addr_page_base
|| limit
< addr_page_limit
) {
12276 *is_subpage
= true;
12279 if (matchregion
!= -1) {
12280 /* Multiple regions match -- always a failure (unlike
12281 * PMSAv7 where highest-numbered-region wins)
12283 fi
->type
= ARMFault_Permission
;
12294 /* background fault */
12295 fi
->type
= ARMFault_Background
;
12299 if (matchregion
== -1) {
12300 /* hit using the background region */
12301 get_phys_addr_pmsav7_default(env
, mmu_idx
, address
, prot
);
12303 uint32_t ap
= extract32(env
->pmsav8
.rbar
[secure
][matchregion
], 1, 2);
12304 uint32_t xn
= extract32(env
->pmsav8
.rbar
[secure
][matchregion
], 0, 1);
12307 if (arm_feature(env
, ARM_FEATURE_V8_1M
)) {
12308 pxn
= extract32(env
->pmsav8
.rlar
[secure
][matchregion
], 4, 1);
12311 if (m_is_system_region(env
, address
)) {
12312 /* System space is always execute never */
12316 *prot
= simple_ap_to_rw_prot(env
, mmu_idx
, ap
);
12317 if (*prot
&& !xn
&& !(pxn
&& !is_user
)) {
12318 *prot
|= PAGE_EXEC
;
12320 /* We don't need to look the attribute up in the MAIR0/MAIR1
12321 * registers because that only tells us about cacheability.
12324 *mregion
= matchregion
;
12328 fi
->type
= ARMFault_Permission
;
12330 return !(*prot
& (1 << access_type
));
12334 static bool get_phys_addr_pmsav8(CPUARMState
*env
, uint32_t address
,
12335 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
12336 hwaddr
*phys_ptr
, MemTxAttrs
*txattrs
,
12337 int *prot
, target_ulong
*page_size
,
12338 ARMMMUFaultInfo
*fi
)
12340 uint32_t secure
= regime_is_secure(env
, mmu_idx
);
12341 V8M_SAttributes sattrs
= {};
12343 bool mpu_is_subpage
;
12345 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
)) {
12346 v8m_security_lookup(env
, address
, access_type
, mmu_idx
, &sattrs
);
12347 if (access_type
== MMU_INST_FETCH
) {
12348 /* Instruction fetches always use the MMU bank and the
12349 * transaction attribute determined by the fetch address,
12350 * regardless of CPU state. This is painful for QEMU
12351 * to handle, because it would mean we need to encode
12352 * into the mmu_idx not just the (user, negpri) information
12353 * for the current security state but also that for the
12354 * other security state, which would balloon the number
12355 * of mmu_idx values needed alarmingly.
12356 * Fortunately we can avoid this because it's not actually
12357 * possible to arbitrarily execute code from memory with
12358 * the wrong security attribute: it will always generate
12359 * an exception of some kind or another, apart from the
12360 * special case of an NS CPU executing an SG instruction
12361 * in S&NSC memory. So we always just fail the translation
12362 * here and sort things out in the exception handler
12363 * (including possibly emulating an SG instruction).
12365 if (sattrs
.ns
!= !secure
) {
12367 fi
->type
= ARMFault_QEMU_NSCExec
;
12369 fi
->type
= ARMFault_QEMU_SFault
;
12371 *page_size
= sattrs
.subpage
? 1 : TARGET_PAGE_SIZE
;
12372 *phys_ptr
= address
;
12377 /* For data accesses we always use the MMU bank indicated
12378 * by the current CPU state, but the security attributes
12379 * might downgrade a secure access to nonsecure.
12382 txattrs
->secure
= false;
12383 } else if (!secure
) {
12384 /* NS access to S memory must fault.
12385 * Architecturally we should first check whether the
12386 * MPU information for this address indicates that we
12387 * are doing an unaligned access to Device memory, which
12388 * should generate a UsageFault instead. QEMU does not
12389 * currently check for that kind of unaligned access though.
12390 * If we added it we would need to do so as a special case
12391 * for M_FAKE_FSR_SFAULT in arm_v7m_cpu_do_interrupt().
12393 fi
->type
= ARMFault_QEMU_SFault
;
12394 *page_size
= sattrs
.subpage
? 1 : TARGET_PAGE_SIZE
;
12395 *phys_ptr
= address
;
12402 ret
= pmsav8_mpu_lookup(env
, address
, access_type
, mmu_idx
, phys_ptr
,
12403 txattrs
, prot
, &mpu_is_subpage
, fi
, NULL
);
12404 *page_size
= sattrs
.subpage
|| mpu_is_subpage
? 1 : TARGET_PAGE_SIZE
;
12408 static bool get_phys_addr_pmsav5(CPUARMState
*env
, uint32_t address
,
12409 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
12410 hwaddr
*phys_ptr
, int *prot
,
12411 ARMMMUFaultInfo
*fi
)
12416 bool is_user
= regime_is_user(env
, mmu_idx
);
12418 if (regime_translation_disabled(env
, mmu_idx
)) {
12419 /* MPU disabled. */
12420 *phys_ptr
= address
;
12421 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
12425 *phys_ptr
= address
;
12426 for (n
= 7; n
>= 0; n
--) {
12427 base
= env
->cp15
.c6_region
[n
];
12428 if ((base
& 1) == 0) {
12431 mask
= 1 << ((base
>> 1) & 0x1f);
12432 /* Keep this shift separate from the above to avoid an
12433 (undefined) << 32. */
12434 mask
= (mask
<< 1) - 1;
12435 if (((base
^ address
) & ~mask
) == 0) {
12440 fi
->type
= ARMFault_Background
;
12444 if (access_type
== MMU_INST_FETCH
) {
12445 mask
= env
->cp15
.pmsav5_insn_ap
;
12447 mask
= env
->cp15
.pmsav5_data_ap
;
12449 mask
= (mask
>> (n
* 4)) & 0xf;
12452 fi
->type
= ARMFault_Permission
;
12457 fi
->type
= ARMFault_Permission
;
12461 *prot
= PAGE_READ
| PAGE_WRITE
;
12466 *prot
|= PAGE_WRITE
;
12470 *prot
= PAGE_READ
| PAGE_WRITE
;
12474 fi
->type
= ARMFault_Permission
;
12484 /* Bad permission. */
12485 fi
->type
= ARMFault_Permission
;
12489 *prot
|= PAGE_EXEC
;
12493 /* Combine either inner or outer cacheability attributes for normal
12494 * memory, according to table D4-42 and pseudocode procedure
12495 * CombineS1S2AttrHints() of ARM DDI 0487B.b (the ARMv8 ARM).
12497 * NB: only stage 1 includes allocation hints (RW bits), leading to
12500 static uint8_t combine_cacheattr_nibble(uint8_t s1
, uint8_t s2
)
12502 if (s1
== 4 || s2
== 4) {
12503 /* non-cacheable has precedence */
12505 } else if (extract32(s1
, 2, 2) == 0 || extract32(s1
, 2, 2) == 2) {
12506 /* stage 1 write-through takes precedence */
12508 } else if (extract32(s2
, 2, 2) == 2) {
12509 /* stage 2 write-through takes precedence, but the allocation hint
12510 * is still taken from stage 1
12512 return (2 << 2) | extract32(s1
, 0, 2);
12513 } else { /* write-back */
12518 /* Combine S1 and S2 cacheability/shareability attributes, per D4.5.4
12519 * and CombineS1S2Desc()
12521 * @s1: Attributes from stage 1 walk
12522 * @s2: Attributes from stage 2 walk
12524 static ARMCacheAttrs
combine_cacheattrs(ARMCacheAttrs s1
, ARMCacheAttrs s2
)
12526 uint8_t s1lo
, s2lo
, s1hi
, s2hi
;
12528 bool tagged
= false;
12530 if (s1
.attrs
== 0xf0) {
12535 s1lo
= extract32(s1
.attrs
, 0, 4);
12536 s2lo
= extract32(s2
.attrs
, 0, 4);
12537 s1hi
= extract32(s1
.attrs
, 4, 4);
12538 s2hi
= extract32(s2
.attrs
, 4, 4);
12540 /* Combine shareability attributes (table D4-43) */
12541 if (s1
.shareability
== 2 || s2
.shareability
== 2) {
12542 /* if either are outer-shareable, the result is outer-shareable */
12543 ret
.shareability
= 2;
12544 } else if (s1
.shareability
== 3 || s2
.shareability
== 3) {
12545 /* if either are inner-shareable, the result is inner-shareable */
12546 ret
.shareability
= 3;
12548 /* both non-shareable */
12549 ret
.shareability
= 0;
12552 /* Combine memory type and cacheability attributes */
12553 if (s1hi
== 0 || s2hi
== 0) {
12554 /* Device has precedence over normal */
12555 if (s1lo
== 0 || s2lo
== 0) {
12556 /* nGnRnE has precedence over anything */
12558 } else if (s1lo
== 4 || s2lo
== 4) {
12559 /* non-Reordering has precedence over Reordering */
12560 ret
.attrs
= 4; /* nGnRE */
12561 } else if (s1lo
== 8 || s2lo
== 8) {
12562 /* non-Gathering has precedence over Gathering */
12563 ret
.attrs
= 8; /* nGRE */
12565 ret
.attrs
= 0xc; /* GRE */
12568 /* Any location for which the resultant memory type is any
12569 * type of Device memory is always treated as Outer Shareable.
12571 ret
.shareability
= 2;
12572 } else { /* Normal memory */
12573 /* Outer/inner cacheability combine independently */
12574 ret
.attrs
= combine_cacheattr_nibble(s1hi
, s2hi
) << 4
12575 | combine_cacheattr_nibble(s1lo
, s2lo
);
12577 if (ret
.attrs
== 0x44) {
12578 /* Any location for which the resultant memory type is Normal
12579 * Inner Non-cacheable, Outer Non-cacheable is always treated
12580 * as Outer Shareable.
12582 ret
.shareability
= 2;
12586 /* TODO: CombineS1S2Desc does not consider transient, only WB, RWA. */
12587 if (tagged
&& ret
.attrs
== 0xff) {
12595 /* get_phys_addr - get the physical address for this virtual address
12597 * Find the physical address corresponding to the given virtual address,
12598 * by doing a translation table walk on MMU based systems or using the
12599 * MPU state on MPU based systems.
12601 * Returns false if the translation was successful. Otherwise, phys_ptr, attrs,
12602 * prot and page_size may not be filled in, and the populated fsr value provides
12603 * information on why the translation aborted, in the format of a
12604 * DFSR/IFSR fault register, with the following caveats:
12605 * * we honour the short vs long DFSR format differences.
12606 * * the WnR bit is never set (the caller must do this).
12607 * * for PSMAv5 based systems we don't bother to return a full FSR format
12610 * @env: CPUARMState
12611 * @address: virtual address to get physical address for
12612 * @access_type: 0 for read, 1 for write, 2 for execute
12613 * @mmu_idx: MMU index indicating required translation regime
12614 * @phys_ptr: set to the physical address corresponding to the virtual address
12615 * @attrs: set to the memory transaction attributes to use
12616 * @prot: set to the permissions for the page containing phys_ptr
12617 * @page_size: set to the size of the page containing phys_ptr
12618 * @fi: set to fault info if the translation fails
12619 * @cacheattrs: (if non-NULL) set to the cacheability/shareability attributes
12621 bool get_phys_addr(CPUARMState
*env
, target_ulong address
,
12622 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
12623 hwaddr
*phys_ptr
, MemTxAttrs
*attrs
, int *prot
,
12624 target_ulong
*page_size
,
12625 ARMMMUFaultInfo
*fi
, ARMCacheAttrs
*cacheattrs
)
12627 ARMMMUIdx s1_mmu_idx
= stage_1_mmu_idx(mmu_idx
);
12629 if (mmu_idx
!= s1_mmu_idx
) {
12630 /* Call ourselves recursively to do the stage 1 and then stage 2
12631 * translations if mmu_idx is a two-stage regime.
12633 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
12637 ARMCacheAttrs cacheattrs2
= {};
12638 ARMMMUIdx s2_mmu_idx
;
12641 ret
= get_phys_addr(env
, address
, access_type
, s1_mmu_idx
, &ipa
,
12642 attrs
, prot
, page_size
, fi
, cacheattrs
);
12644 /* If S1 fails or S2 is disabled, return early. */
12645 if (ret
|| regime_translation_disabled(env
, ARMMMUIdx_Stage2
)) {
12650 s2_mmu_idx
= attrs
->secure
? ARMMMUIdx_Stage2_S
: ARMMMUIdx_Stage2
;
12651 is_el0
= mmu_idx
== ARMMMUIdx_E10_0
|| mmu_idx
== ARMMMUIdx_SE10_0
;
12653 /* S1 is done. Now do S2 translation. */
12654 ret
= get_phys_addr_lpae(env
, ipa
, access_type
, s2_mmu_idx
, is_el0
,
12655 phys_ptr
, attrs
, &s2_prot
,
12656 page_size
, fi
, &cacheattrs2
);
12658 /* Combine the S1 and S2 perms. */
12661 /* If S2 fails, return early. */
12666 /* Combine the S1 and S2 cache attributes. */
12667 if (arm_hcr_el2_eff(env
) & HCR_DC
) {
12669 * HCR.DC forces the first stage attributes to
12670 * Normal Non-Shareable,
12671 * Inner Write-Back Read-Allocate Write-Allocate,
12672 * Outer Write-Back Read-Allocate Write-Allocate.
12673 * Do not overwrite Tagged within attrs.
12675 if (cacheattrs
->attrs
!= 0xf0) {
12676 cacheattrs
->attrs
= 0xff;
12678 cacheattrs
->shareability
= 0;
12680 *cacheattrs
= combine_cacheattrs(*cacheattrs
, cacheattrs2
);
12682 /* Check if IPA translates to secure or non-secure PA space. */
12683 if (arm_is_secure_below_el3(env
)) {
12684 if (attrs
->secure
) {
12686 !(env
->cp15
.vstcr_el2
.raw_tcr
& (VSTCR_SA
| VSTCR_SW
));
12689 !((env
->cp15
.vtcr_el2
.raw_tcr
& (VTCR_NSA
| VTCR_NSW
))
12690 || (env
->cp15
.vstcr_el2
.raw_tcr
& VSTCR_SA
));
12696 * For non-EL2 CPUs a stage1+stage2 translation is just stage 1.
12698 mmu_idx
= stage_1_mmu_idx(mmu_idx
);
12702 /* The page table entries may downgrade secure to non-secure, but
12703 * cannot upgrade an non-secure translation regime's attributes
12706 attrs
->secure
= regime_is_secure(env
, mmu_idx
);
12707 attrs
->user
= regime_is_user(env
, mmu_idx
);
12709 /* Fast Context Switch Extension. This doesn't exist at all in v8.
12710 * In v7 and earlier it affects all stage 1 translations.
12712 if (address
< 0x02000000 && mmu_idx
!= ARMMMUIdx_Stage2
12713 && !arm_feature(env
, ARM_FEATURE_V8
)) {
12714 if (regime_el(env
, mmu_idx
) == 3) {
12715 address
+= env
->cp15
.fcseidr_s
;
12717 address
+= env
->cp15
.fcseidr_ns
;
12721 if (arm_feature(env
, ARM_FEATURE_PMSA
)) {
12723 *page_size
= TARGET_PAGE_SIZE
;
12725 if (arm_feature(env
, ARM_FEATURE_V8
)) {
12727 ret
= get_phys_addr_pmsav8(env
, address
, access_type
, mmu_idx
,
12728 phys_ptr
, attrs
, prot
, page_size
, fi
);
12729 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
12731 ret
= get_phys_addr_pmsav7(env
, address
, access_type
, mmu_idx
,
12732 phys_ptr
, prot
, page_size
, fi
);
12735 ret
= get_phys_addr_pmsav5(env
, address
, access_type
, mmu_idx
,
12736 phys_ptr
, prot
, fi
);
12738 qemu_log_mask(CPU_LOG_MMU
, "PMSA MPU lookup for %s at 0x%08" PRIx32
12739 " mmu_idx %u -> %s (prot %c%c%c)\n",
12740 access_type
== MMU_DATA_LOAD
? "reading" :
12741 (access_type
== MMU_DATA_STORE
? "writing" : "execute"),
12742 (uint32_t)address
, mmu_idx
,
12743 ret
? "Miss" : "Hit",
12744 *prot
& PAGE_READ
? 'r' : '-',
12745 *prot
& PAGE_WRITE
? 'w' : '-',
12746 *prot
& PAGE_EXEC
? 'x' : '-');
12751 /* Definitely a real MMU, not an MPU */
12753 if (regime_translation_disabled(env
, mmu_idx
)) {
12758 * MMU disabled. S1 addresses within aa64 translation regimes are
12759 * still checked for bounds -- see AArch64.TranslateAddressS1Off.
12761 if (mmu_idx
!= ARMMMUIdx_Stage2
&& mmu_idx
!= ARMMMUIdx_Stage2_S
) {
12762 int r_el
= regime_el(env
, mmu_idx
);
12763 if (arm_el_is_aa64(env
, r_el
)) {
12764 int pamax
= arm_pamax(env_archcpu(env
));
12765 uint64_t tcr
= env
->cp15
.tcr_el
[r_el
].raw_tcr
;
12768 tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
12769 if (access_type
== MMU_INST_FETCH
) {
12770 tbi
&= ~aa64_va_parameter_tbid(tcr
, mmu_idx
);
12772 tbi
= (tbi
>> extract64(address
, 55, 1)) & 1;
12773 addrtop
= (tbi
? 55 : 63);
12775 if (extract64(address
, pamax
, addrtop
- pamax
+ 1) != 0) {
12776 fi
->type
= ARMFault_AddressSize
;
12778 fi
->stage2
= false;
12783 * When TBI is disabled, we've just validated that all of the
12784 * bits above PAMax are zero, so logically we only need to
12785 * clear the top byte for TBI. But it's clearer to follow
12786 * the pseudocode set of addrdesc.paddress.
12788 address
= extract64(address
, 0, 52);
12791 *phys_ptr
= address
;
12792 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
12793 *page_size
= TARGET_PAGE_SIZE
;
12795 /* Fill in cacheattr a-la AArch64.TranslateAddressS1Off. */
12796 hcr
= arm_hcr_el2_eff(env
);
12797 cacheattrs
->shareability
= 0;
12798 if (hcr
& HCR_DC
) {
12799 if (hcr
& HCR_DCT
) {
12800 memattr
= 0xf0; /* Tagged, Normal, WB, RWA */
12802 memattr
= 0xff; /* Normal, WB, RWA */
12804 } else if (access_type
== MMU_INST_FETCH
) {
12805 if (regime_sctlr(env
, mmu_idx
) & SCTLR_I
) {
12806 memattr
= 0xee; /* Normal, WT, RA, NT */
12808 memattr
= 0x44; /* Normal, NC, No */
12810 cacheattrs
->shareability
= 2; /* outer sharable */
12812 memattr
= 0x00; /* Device, nGnRnE */
12814 cacheattrs
->attrs
= memattr
;
12818 if (regime_using_lpae_format(env
, mmu_idx
)) {
12819 return get_phys_addr_lpae(env
, address
, access_type
, mmu_idx
, false,
12820 phys_ptr
, attrs
, prot
, page_size
,
12822 } else if (regime_sctlr(env
, mmu_idx
) & SCTLR_XP
) {
12823 return get_phys_addr_v6(env
, address
, access_type
, mmu_idx
,
12824 phys_ptr
, attrs
, prot
, page_size
, fi
);
12826 return get_phys_addr_v5(env
, address
, access_type
, mmu_idx
,
12827 phys_ptr
, prot
, page_size
, fi
);
12831 hwaddr
arm_cpu_get_phys_page_attrs_debug(CPUState
*cs
, vaddr addr
,
12834 ARMCPU
*cpu
= ARM_CPU(cs
);
12835 CPUARMState
*env
= &cpu
->env
;
12837 target_ulong page_size
;
12840 ARMMMUFaultInfo fi
= {};
12841 ARMMMUIdx mmu_idx
= arm_mmu_idx(env
);
12842 ARMCacheAttrs cacheattrs
= {};
12844 *attrs
= (MemTxAttrs
) {};
12846 ret
= get_phys_addr(env
, addr
, MMU_DATA_LOAD
, mmu_idx
, &phys_addr
,
12847 attrs
, &prot
, &page_size
, &fi
, &cacheattrs
);
12857 /* Note that signed overflow is undefined in C. The following routines are
12858 careful to use unsigned types where modulo arithmetic is required.
12859 Failure to do so _will_ break on newer gcc. */
12861 /* Signed saturating arithmetic. */
12863 /* Perform 16-bit signed saturating addition. */
12864 static inline uint16_t add16_sat(uint16_t a
, uint16_t b
)
12869 if (((res
^ a
) & 0x8000) && !((a
^ b
) & 0x8000)) {
12878 /* Perform 8-bit signed saturating addition. */
12879 static inline uint8_t add8_sat(uint8_t a
, uint8_t b
)
12884 if (((res
^ a
) & 0x80) && !((a
^ b
) & 0x80)) {
12893 /* Perform 16-bit signed saturating subtraction. */
12894 static inline uint16_t sub16_sat(uint16_t a
, uint16_t b
)
12899 if (((res
^ a
) & 0x8000) && ((a
^ b
) & 0x8000)) {
12908 /* Perform 8-bit signed saturating subtraction. */
12909 static inline uint8_t sub8_sat(uint8_t a
, uint8_t b
)
12914 if (((res
^ a
) & 0x80) && ((a
^ b
) & 0x80)) {
12923 #define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
12924 #define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
12925 #define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
12926 #define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
12929 #include "op_addsub.h"
12931 /* Unsigned saturating arithmetic. */
12932 static inline uint16_t add16_usat(uint16_t a
, uint16_t b
)
12941 static inline uint16_t sub16_usat(uint16_t a
, uint16_t b
)
12949 static inline uint8_t add8_usat(uint8_t a
, uint8_t b
)
12958 static inline uint8_t sub8_usat(uint8_t a
, uint8_t b
)
12966 #define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
12967 #define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
12968 #define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
12969 #define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
12972 #include "op_addsub.h"
12974 /* Signed modulo arithmetic. */
12975 #define SARITH16(a, b, n, op) do { \
12977 sum = (int32_t)(int16_t)(a) op (int32_t)(int16_t)(b); \
12978 RESULT(sum, n, 16); \
12980 ge |= 3 << (n * 2); \
12983 #define SARITH8(a, b, n, op) do { \
12985 sum = (int32_t)(int8_t)(a) op (int32_t)(int8_t)(b); \
12986 RESULT(sum, n, 8); \
12992 #define ADD16(a, b, n) SARITH16(a, b, n, +)
12993 #define SUB16(a, b, n) SARITH16(a, b, n, -)
12994 #define ADD8(a, b, n) SARITH8(a, b, n, +)
12995 #define SUB8(a, b, n) SARITH8(a, b, n, -)
12999 #include "op_addsub.h"
13001 /* Unsigned modulo arithmetic. */
13002 #define ADD16(a, b, n) do { \
13004 sum = (uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b); \
13005 RESULT(sum, n, 16); \
13006 if ((sum >> 16) == 1) \
13007 ge |= 3 << (n * 2); \
13010 #define ADD8(a, b, n) do { \
13012 sum = (uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b); \
13013 RESULT(sum, n, 8); \
13014 if ((sum >> 8) == 1) \
13018 #define SUB16(a, b, n) do { \
13020 sum = (uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b); \
13021 RESULT(sum, n, 16); \
13022 if ((sum >> 16) == 0) \
13023 ge |= 3 << (n * 2); \
13026 #define SUB8(a, b, n) do { \
13028 sum = (uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b); \
13029 RESULT(sum, n, 8); \
13030 if ((sum >> 8) == 0) \
13037 #include "op_addsub.h"
13039 /* Halved signed arithmetic. */
13040 #define ADD16(a, b, n) \
13041 RESULT(((int32_t)(int16_t)(a) + (int32_t)(int16_t)(b)) >> 1, n, 16)
13042 #define SUB16(a, b, n) \
13043 RESULT(((int32_t)(int16_t)(a) - (int32_t)(int16_t)(b)) >> 1, n, 16)
13044 #define ADD8(a, b, n) \
13045 RESULT(((int32_t)(int8_t)(a) + (int32_t)(int8_t)(b)) >> 1, n, 8)
13046 #define SUB8(a, b, n) \
13047 RESULT(((int32_t)(int8_t)(a) - (int32_t)(int8_t)(b)) >> 1, n, 8)
13050 #include "op_addsub.h"
13052 /* Halved unsigned arithmetic. */
13053 #define ADD16(a, b, n) \
13054 RESULT(((uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b)) >> 1, n, 16)
13055 #define SUB16(a, b, n) \
13056 RESULT(((uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b)) >> 1, n, 16)
13057 #define ADD8(a, b, n) \
13058 RESULT(((uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b)) >> 1, n, 8)
13059 #define SUB8(a, b, n) \
13060 RESULT(((uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b)) >> 1, n, 8)
13063 #include "op_addsub.h"
13065 static inline uint8_t do_usad(uint8_t a
, uint8_t b
)
13073 /* Unsigned sum of absolute byte differences. */
13074 uint32_t HELPER(usad8
)(uint32_t a
, uint32_t b
)
13077 sum
= do_usad(a
, b
);
13078 sum
+= do_usad(a
>> 8, b
>> 8);
13079 sum
+= do_usad(a
>> 16, b
>> 16);
13080 sum
+= do_usad(a
>> 24, b
>> 24);
13084 /* For ARMv6 SEL instruction. */
13085 uint32_t HELPER(sel_flags
)(uint32_t flags
, uint32_t a
, uint32_t b
)
13097 mask
|= 0xff000000;
13098 return (a
& mask
) | (b
& ~mask
);
13102 * The upper bytes of val (above the number specified by 'bytes') must have
13103 * been zeroed out by the caller.
13105 uint32_t HELPER(crc32
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
13109 stl_le_p(buf
, val
);
13111 /* zlib crc32 converts the accumulator and output to one's complement. */
13112 return crc32(acc
^ 0xffffffff, buf
, bytes
) ^ 0xffffffff;
13115 uint32_t HELPER(crc32c
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
13119 stl_le_p(buf
, val
);
13121 /* Linux crc32c converts the output to one's complement. */
13122 return crc32c(acc
, buf
, bytes
) ^ 0xffffffff;
13125 /* Return the exception level to which FP-disabled exceptions should
13126 * be taken, or 0 if FP is enabled.
13128 int fp_exception_el(CPUARMState
*env
, int cur_el
)
13130 #ifndef CONFIG_USER_ONLY
13131 /* CPACR and the CPTR registers don't exist before v6, so FP is
13132 * always accessible
13134 if (!arm_feature(env
, ARM_FEATURE_V6
)) {
13138 if (arm_feature(env
, ARM_FEATURE_M
)) {
13139 /* CPACR can cause a NOCP UsageFault taken to current security state */
13140 if (!v7m_cpacr_pass(env
, env
->v7m
.secure
, cur_el
!= 0)) {
13144 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
) && !env
->v7m
.secure
) {
13145 if (!extract32(env
->v7m
.nsacr
, 10, 1)) {
13146 /* FP insns cause a NOCP UsageFault taken to Secure */
13154 /* The CPACR controls traps to EL1, or PL1 if we're 32 bit:
13155 * 0, 2 : trap EL0 and EL1/PL1 accesses
13156 * 1 : trap only EL0 accesses
13157 * 3 : trap no accesses
13158 * This register is ignored if E2H+TGE are both set.
13160 if ((arm_hcr_el2_eff(env
) & (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
13161 int fpen
= extract32(env
->cp15
.cpacr_el1
, 20, 2);
13166 if (cur_el
== 0 || cur_el
== 1) {
13167 /* Trap to PL1, which might be EL1 or EL3 */
13168 if (arm_is_secure(env
) && !arm_el_is_aa64(env
, 3)) {
13173 if (cur_el
== 3 && !is_a64(env
)) {
13174 /* Secure PL1 running at EL3 */
13189 * The NSACR allows A-profile AArch32 EL3 and M-profile secure mode
13190 * to control non-secure access to the FPU. It doesn't have any
13191 * effect if EL3 is AArch64 or if EL3 doesn't exist at all.
13193 if ((arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
13194 cur_el
<= 2 && !arm_is_secure_below_el3(env
))) {
13195 if (!extract32(env
->cp15
.nsacr
, 10, 1)) {
13196 /* FP insns act as UNDEF */
13197 return cur_el
== 2 ? 2 : 1;
13201 /* For the CPTR registers we don't need to guard with an ARM_FEATURE
13202 * check because zero bits in the registers mean "don't trap".
13205 /* CPTR_EL2 : present in v7VE or v8 */
13206 if (cur_el
<= 2 && extract32(env
->cp15
.cptr_el
[2], 10, 1)
13207 && arm_is_el2_enabled(env
)) {
13208 /* Trap FP ops at EL2, NS-EL1 or NS-EL0 to EL2 */
13212 /* CPTR_EL3 : present in v8 */
13213 if (extract32(env
->cp15
.cptr_el
[3], 10, 1)) {
13214 /* Trap all FP ops to EL3 */
13221 /* Return the exception level we're running at if this is our mmu_idx */
13222 int arm_mmu_idx_to_el(ARMMMUIdx mmu_idx
)
13224 if (mmu_idx
& ARM_MMU_IDX_M
) {
13225 return mmu_idx
& ARM_MMU_IDX_M_PRIV
;
13229 case ARMMMUIdx_E10_0
:
13230 case ARMMMUIdx_E20_0
:
13231 case ARMMMUIdx_SE10_0
:
13232 case ARMMMUIdx_SE20_0
:
13234 case ARMMMUIdx_E10_1
:
13235 case ARMMMUIdx_E10_1_PAN
:
13236 case ARMMMUIdx_SE10_1
:
13237 case ARMMMUIdx_SE10_1_PAN
:
13240 case ARMMMUIdx_E20_2
:
13241 case ARMMMUIdx_E20_2_PAN
:
13242 case ARMMMUIdx_SE2
:
13243 case ARMMMUIdx_SE20_2
:
13244 case ARMMMUIdx_SE20_2_PAN
:
13246 case ARMMMUIdx_SE3
:
13249 g_assert_not_reached();
13254 ARMMMUIdx
arm_v7m_mmu_idx_for_secstate(CPUARMState
*env
, bool secstate
)
13256 g_assert_not_reached();
13260 ARMMMUIdx
arm_mmu_idx_el(CPUARMState
*env
, int el
)
13265 if (arm_feature(env
, ARM_FEATURE_M
)) {
13266 return arm_v7m_mmu_idx_for_secstate(env
, env
->v7m
.secure
);
13269 /* See ARM pseudo-function ELIsInHost. */
13272 hcr
= arm_hcr_el2_eff(env
);
13273 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
13274 idx
= ARMMMUIdx_E20_0
;
13276 idx
= ARMMMUIdx_E10_0
;
13280 if (env
->pstate
& PSTATE_PAN
) {
13281 idx
= ARMMMUIdx_E10_1_PAN
;
13283 idx
= ARMMMUIdx_E10_1
;
13287 /* Note that TGE does not apply at EL2. */
13288 if (arm_hcr_el2_eff(env
) & HCR_E2H
) {
13289 if (env
->pstate
& PSTATE_PAN
) {
13290 idx
= ARMMMUIdx_E20_2_PAN
;
13292 idx
= ARMMMUIdx_E20_2
;
13295 idx
= ARMMMUIdx_E2
;
13299 return ARMMMUIdx_SE3
;
13301 g_assert_not_reached();
13304 if (arm_is_secure_below_el3(env
)) {
13305 idx
&= ~ARM_MMU_IDX_A_NS
;
13311 ARMMMUIdx
arm_mmu_idx(CPUARMState
*env
)
13313 return arm_mmu_idx_el(env
, arm_current_el(env
));
13316 #ifndef CONFIG_USER_ONLY
13317 ARMMMUIdx
arm_stage1_mmu_idx(CPUARMState
*env
)
13319 return stage_1_mmu_idx(arm_mmu_idx(env
));
13323 static CPUARMTBFlags
rebuild_hflags_common(CPUARMState
*env
, int fp_el
,
13325 CPUARMTBFlags flags
)
13327 DP_TBFLAG_ANY(flags
, FPEXC_EL
, fp_el
);
13328 DP_TBFLAG_ANY(flags
, MMUIDX
, arm_to_core_mmu_idx(mmu_idx
));
13330 if (arm_singlestep_active(env
)) {
13331 DP_TBFLAG_ANY(flags
, SS_ACTIVE
, 1);
13336 static CPUARMTBFlags
rebuild_hflags_common_32(CPUARMState
*env
, int fp_el
,
13338 CPUARMTBFlags flags
)
13340 bool sctlr_b
= arm_sctlr_b(env
);
13343 DP_TBFLAG_A32(flags
, SCTLR__B
, 1);
13345 if (arm_cpu_data_is_big_endian_a32(env
, sctlr_b
)) {
13346 DP_TBFLAG_ANY(flags
, BE_DATA
, 1);
13348 DP_TBFLAG_A32(flags
, NS
, !access_secure_reg(env
));
13350 return rebuild_hflags_common(env
, fp_el
, mmu_idx
, flags
);
13353 static CPUARMTBFlags
rebuild_hflags_m32(CPUARMState
*env
, int fp_el
,
13356 CPUARMTBFlags flags
= {};
13357 uint32_t ccr
= env
->v7m
.ccr
[env
->v7m
.secure
];
13359 /* Without HaveMainExt, CCR.UNALIGN_TRP is RES1. */
13360 if (ccr
& R_V7M_CCR_UNALIGN_TRP_MASK
) {
13361 DP_TBFLAG_ANY(flags
, ALIGN_MEM
, 1);
13364 if (arm_v7m_is_handler_mode(env
)) {
13365 DP_TBFLAG_M32(flags
, HANDLER
, 1);
13369 * v8M always applies stack limit checks unless CCR.STKOFHFNMIGN
13370 * is suppressing them because the requested execution priority
13373 if (arm_feature(env
, ARM_FEATURE_V8
) &&
13374 !((mmu_idx
& ARM_MMU_IDX_M_NEGPRI
) &&
13375 (ccr
& R_V7M_CCR_STKOFHFNMIGN_MASK
))) {
13376 DP_TBFLAG_M32(flags
, STACKCHECK
, 1);
13379 return rebuild_hflags_common_32(env
, fp_el
, mmu_idx
, flags
);
13382 static CPUARMTBFlags
rebuild_hflags_aprofile(CPUARMState
*env
)
13384 CPUARMTBFlags flags
= {};
13386 DP_TBFLAG_ANY(flags
, DEBUG_TARGET_EL
, arm_debug_target_el(env
));
13390 static CPUARMTBFlags
rebuild_hflags_a32(CPUARMState
*env
, int fp_el
,
13393 CPUARMTBFlags flags
= rebuild_hflags_aprofile(env
);
13394 int el
= arm_current_el(env
);
13396 if (arm_sctlr(env
, el
) & SCTLR_A
) {
13397 DP_TBFLAG_ANY(flags
, ALIGN_MEM
, 1);
13400 if (arm_el_is_aa64(env
, 1)) {
13401 DP_TBFLAG_A32(flags
, VFPEN
, 1);
13404 if (el
< 2 && env
->cp15
.hstr_el2
&&
13405 (arm_hcr_el2_eff(env
) & (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
13406 DP_TBFLAG_A32(flags
, HSTR_ACTIVE
, 1);
13409 return rebuild_hflags_common_32(env
, fp_el
, mmu_idx
, flags
);
13412 static CPUARMTBFlags
rebuild_hflags_a64(CPUARMState
*env
, int el
, int fp_el
,
13415 CPUARMTBFlags flags
= rebuild_hflags_aprofile(env
);
13416 ARMMMUIdx stage1
= stage_1_mmu_idx(mmu_idx
);
13417 uint64_t tcr
= regime_tcr(env
, mmu_idx
)->raw_tcr
;
13421 DP_TBFLAG_ANY(flags
, AARCH64_STATE
, 1);
13423 /* Get control bits for tagged addresses. */
13424 tbid
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
13425 tbii
= tbid
& ~aa64_va_parameter_tbid(tcr
, mmu_idx
);
13427 DP_TBFLAG_A64(flags
, TBII
, tbii
);
13428 DP_TBFLAG_A64(flags
, TBID
, tbid
);
13430 if (cpu_isar_feature(aa64_sve
, env_archcpu(env
))) {
13431 int sve_el
= sve_exception_el(env
, el
);
13435 * If SVE is disabled, but FP is enabled,
13436 * then the effective len is 0.
13438 if (sve_el
!= 0 && fp_el
== 0) {
13441 zcr_len
= sve_zcr_len_for_el(env
, el
);
13443 DP_TBFLAG_A64(flags
, SVEEXC_EL
, sve_el
);
13444 DP_TBFLAG_A64(flags
, ZCR_LEN
, zcr_len
);
13447 sctlr
= regime_sctlr(env
, stage1
);
13449 if (sctlr
& SCTLR_A
) {
13450 DP_TBFLAG_ANY(flags
, ALIGN_MEM
, 1);
13453 if (arm_cpu_data_is_big_endian_a64(el
, sctlr
)) {
13454 DP_TBFLAG_ANY(flags
, BE_DATA
, 1);
13457 if (cpu_isar_feature(aa64_pauth
, env_archcpu(env
))) {
13459 * In order to save space in flags, we record only whether
13460 * pauth is "inactive", meaning all insns are implemented as
13461 * a nop, or "active" when some action must be performed.
13462 * The decision of which action to take is left to a helper.
13464 if (sctlr
& (SCTLR_EnIA
| SCTLR_EnIB
| SCTLR_EnDA
| SCTLR_EnDB
)) {
13465 DP_TBFLAG_A64(flags
, PAUTH_ACTIVE
, 1);
13469 if (cpu_isar_feature(aa64_bti
, env_archcpu(env
))) {
13470 /* Note that SCTLR_EL[23].BT == SCTLR_BT1. */
13471 if (sctlr
& (el
== 0 ? SCTLR_BT0
: SCTLR_BT1
)) {
13472 DP_TBFLAG_A64(flags
, BT
, 1);
13476 /* Compute the condition for using AccType_UNPRIV for LDTR et al. */
13477 if (!(env
->pstate
& PSTATE_UAO
)) {
13479 case ARMMMUIdx_E10_1
:
13480 case ARMMMUIdx_E10_1_PAN
:
13481 case ARMMMUIdx_SE10_1
:
13482 case ARMMMUIdx_SE10_1_PAN
:
13483 /* TODO: ARMv8.3-NV */
13484 DP_TBFLAG_A64(flags
, UNPRIV
, 1);
13486 case ARMMMUIdx_E20_2
:
13487 case ARMMMUIdx_E20_2_PAN
:
13488 case ARMMMUIdx_SE20_2
:
13489 case ARMMMUIdx_SE20_2_PAN
:
13491 * Note that EL20_2 is gated by HCR_EL2.E2H == 1, but EL20_0 is
13492 * gated by HCR_EL2.<E2H,TGE> == '11', and so is LDTR.
13494 if (env
->cp15
.hcr_el2
& HCR_TGE
) {
13495 DP_TBFLAG_A64(flags
, UNPRIV
, 1);
13503 if (cpu_isar_feature(aa64_mte
, env_archcpu(env
))) {
13505 * Set MTE_ACTIVE if any access may be Checked, and leave clear
13506 * if all accesses must be Unchecked:
13507 * 1) If no TBI, then there are no tags in the address to check,
13508 * 2) If Tag Check Override, then all accesses are Unchecked,
13509 * 3) If Tag Check Fail == 0, then Checked access have no effect,
13510 * 4) If no Allocation Tag Access, then all accesses are Unchecked.
13512 if (allocation_tag_access_enabled(env
, el
, sctlr
)) {
13513 DP_TBFLAG_A64(flags
, ATA
, 1);
13515 && !(env
->pstate
& PSTATE_TCO
)
13516 && (sctlr
& (el
== 0 ? SCTLR_TCF0
: SCTLR_TCF
))) {
13517 DP_TBFLAG_A64(flags
, MTE_ACTIVE
, 1);
13520 /* And again for unprivileged accesses, if required. */
13521 if (EX_TBFLAG_A64(flags
, UNPRIV
)
13523 && !(env
->pstate
& PSTATE_TCO
)
13524 && (sctlr
& SCTLR_TCF0
)
13525 && allocation_tag_access_enabled(env
, 0, sctlr
)) {
13526 DP_TBFLAG_A64(flags
, MTE0_ACTIVE
, 1);
13528 /* Cache TCMA as well as TBI. */
13529 DP_TBFLAG_A64(flags
, TCMA
, aa64_va_parameter_tcma(tcr
, mmu_idx
));
13532 return rebuild_hflags_common(env
, fp_el
, mmu_idx
, flags
);
13535 static CPUARMTBFlags
rebuild_hflags_internal(CPUARMState
*env
)
13537 int el
= arm_current_el(env
);
13538 int fp_el
= fp_exception_el(env
, el
);
13539 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13542 return rebuild_hflags_a64(env
, el
, fp_el
, mmu_idx
);
13543 } else if (arm_feature(env
, ARM_FEATURE_M
)) {
13544 return rebuild_hflags_m32(env
, fp_el
, mmu_idx
);
13546 return rebuild_hflags_a32(env
, fp_el
, mmu_idx
);
13550 void arm_rebuild_hflags(CPUARMState
*env
)
13552 env
->hflags
= rebuild_hflags_internal(env
);
13556 * If we have triggered a EL state change we can't rely on the
13557 * translator having passed it to us, we need to recompute.
13559 void HELPER(rebuild_hflags_m32_newel
)(CPUARMState
*env
)
13561 int el
= arm_current_el(env
);
13562 int fp_el
= fp_exception_el(env
, el
);
13563 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13565 env
->hflags
= rebuild_hflags_m32(env
, fp_el
, mmu_idx
);
13568 void HELPER(rebuild_hflags_m32
)(CPUARMState
*env
, int el
)
13570 int fp_el
= fp_exception_el(env
, el
);
13571 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13573 env
->hflags
= rebuild_hflags_m32(env
, fp_el
, mmu_idx
);
13577 * If we have triggered a EL state change we can't rely on the
13578 * translator having passed it to us, we need to recompute.
13580 void HELPER(rebuild_hflags_a32_newel
)(CPUARMState
*env
)
13582 int el
= arm_current_el(env
);
13583 int fp_el
= fp_exception_el(env
, el
);
13584 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13585 env
->hflags
= rebuild_hflags_a32(env
, fp_el
, mmu_idx
);
13588 void HELPER(rebuild_hflags_a32
)(CPUARMState
*env
, int el
)
13590 int fp_el
= fp_exception_el(env
, el
);
13591 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13593 env
->hflags
= rebuild_hflags_a32(env
, fp_el
, mmu_idx
);
13596 void HELPER(rebuild_hflags_a64
)(CPUARMState
*env
, int el
)
13598 int fp_el
= fp_exception_el(env
, el
);
13599 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13601 env
->hflags
= rebuild_hflags_a64(env
, el
, fp_el
, mmu_idx
);
13604 static inline void assert_hflags_rebuild_correctly(CPUARMState
*env
)
13606 #ifdef CONFIG_DEBUG_TCG
13607 CPUARMTBFlags c
= env
->hflags
;
13608 CPUARMTBFlags r
= rebuild_hflags_internal(env
);
13610 if (unlikely(c
.flags
!= r
.flags
|| c
.flags2
!= r
.flags2
)) {
13611 fprintf(stderr
, "TCG hflags mismatch "
13612 "(current:(0x%08x,0x" TARGET_FMT_lx
")"
13613 " rebuilt:(0x%08x,0x" TARGET_FMT_lx
")\n",
13614 c
.flags
, c
.flags2
, r
.flags
, r
.flags2
);
13620 void cpu_get_tb_cpu_state(CPUARMState
*env
, target_ulong
*pc
,
13621 target_ulong
*cs_base
, uint32_t *pflags
)
13623 CPUARMTBFlags flags
;
13625 assert_hflags_rebuild_correctly(env
);
13626 flags
= env
->hflags
;
13628 if (EX_TBFLAG_ANY(flags
, AARCH64_STATE
)) {
13630 if (cpu_isar_feature(aa64_bti
, env_archcpu(env
))) {
13631 DP_TBFLAG_A64(flags
, BTYPE
, env
->btype
);
13634 *pc
= env
->regs
[15];
13636 if (arm_feature(env
, ARM_FEATURE_M
)) {
13637 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
) &&
13638 FIELD_EX32(env
->v7m
.fpccr
[M_REG_S
], V7M_FPCCR
, S
)
13639 != env
->v7m
.secure
) {
13640 DP_TBFLAG_M32(flags
, FPCCR_S_WRONG
, 1);
13643 if ((env
->v7m
.fpccr
[env
->v7m
.secure
] & R_V7M_FPCCR_ASPEN_MASK
) &&
13644 (!(env
->v7m
.control
[M_REG_S
] & R_V7M_CONTROL_FPCA_MASK
) ||
13645 (env
->v7m
.secure
&&
13646 !(env
->v7m
.control
[M_REG_S
] & R_V7M_CONTROL_SFPA_MASK
)))) {
13648 * ASPEN is set, but FPCA/SFPA indicate that there is no
13649 * active FP context; we must create a new FP context before
13650 * executing any FP insn.
13652 DP_TBFLAG_M32(flags
, NEW_FP_CTXT_NEEDED
, 1);
13655 bool is_secure
= env
->v7m
.fpccr
[M_REG_S
] & R_V7M_FPCCR_S_MASK
;
13656 if (env
->v7m
.fpccr
[is_secure
] & R_V7M_FPCCR_LSPACT_MASK
) {
13657 DP_TBFLAG_M32(flags
, LSPACT
, 1);
13661 * Note that XSCALE_CPAR shares bits with VECSTRIDE.
13662 * Note that VECLEN+VECSTRIDE are RES0 for M-profile.
13664 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
13665 DP_TBFLAG_A32(flags
, XSCALE_CPAR
, env
->cp15
.c15_cpar
);
13667 DP_TBFLAG_A32(flags
, VECLEN
, env
->vfp
.vec_len
);
13668 DP_TBFLAG_A32(flags
, VECSTRIDE
, env
->vfp
.vec_stride
);
13670 if (env
->vfp
.xregs
[ARM_VFP_FPEXC
] & (1 << 30)) {
13671 DP_TBFLAG_A32(flags
, VFPEN
, 1);
13675 DP_TBFLAG_AM32(flags
, THUMB
, env
->thumb
);
13676 DP_TBFLAG_AM32(flags
, CONDEXEC
, env
->condexec_bits
);
13680 * The SS_ACTIVE and PSTATE_SS bits correspond to the state machine
13681 * states defined in the ARM ARM for software singlestep:
13682 * SS_ACTIVE PSTATE.SS State
13683 * 0 x Inactive (the TB flag for SS is always 0)
13684 * 1 0 Active-pending
13685 * 1 1 Active-not-pending
13686 * SS_ACTIVE is set in hflags; PSTATE__SS is computed every TB.
13688 if (EX_TBFLAG_ANY(flags
, SS_ACTIVE
) && (env
->pstate
& PSTATE_SS
)) {
13689 DP_TBFLAG_ANY(flags
, PSTATE__SS
, 1);
13692 *pflags
= flags
.flags
;
13693 *cs_base
= flags
.flags2
;
13696 #ifdef TARGET_AARCH64
13698 * The manual says that when SVE is enabled and VQ is widened the
13699 * implementation is allowed to zero the previously inaccessible
13700 * portion of the registers. The corollary to that is that when
13701 * SVE is enabled and VQ is narrowed we are also allowed to zero
13702 * the now inaccessible portion of the registers.
13704 * The intent of this is that no predicate bit beyond VQ is ever set.
13705 * Which means that some operations on predicate registers themselves
13706 * may operate on full uint64_t or even unrolled across the maximum
13707 * uint64_t[4]. Performing 4 bits of host arithmetic unconditionally
13708 * may well be cheaper than conditionals to restrict the operation
13709 * to the relevant portion of a uint16_t[16].
13711 void aarch64_sve_narrow_vq(CPUARMState
*env
, unsigned vq
)
13716 assert(vq
>= 1 && vq
<= ARM_MAX_VQ
);
13717 assert(vq
<= env_archcpu(env
)->sve_max_vq
);
13719 /* Zap the high bits of the zregs. */
13720 for (i
= 0; i
< 32; i
++) {
13721 memset(&env
->vfp
.zregs
[i
].d
[2 * vq
], 0, 16 * (ARM_MAX_VQ
- vq
));
13724 /* Zap the high bits of the pregs and ffr. */
13727 pmask
= ~(-1ULL << (16 * (vq
& 3)));
13729 for (j
= vq
/ 4; j
< ARM_MAX_VQ
/ 4; j
++) {
13730 for (i
= 0; i
< 17; ++i
) {
13731 env
->vfp
.pregs
[i
].p
[j
] &= pmask
;
13738 * Notice a change in SVE vector size when changing EL.
13740 void aarch64_sve_change_el(CPUARMState
*env
, int old_el
,
13741 int new_el
, bool el0_a64
)
13743 ARMCPU
*cpu
= env_archcpu(env
);
13744 int old_len
, new_len
;
13745 bool old_a64
, new_a64
;
13747 /* Nothing to do if no SVE. */
13748 if (!cpu_isar_feature(aa64_sve
, cpu
)) {
13752 /* Nothing to do if FP is disabled in either EL. */
13753 if (fp_exception_el(env
, old_el
) || fp_exception_el(env
, new_el
)) {
13758 * DDI0584A.d sec 3.2: "If SVE instructions are disabled or trapped
13759 * at ELx, or not available because the EL is in AArch32 state, then
13760 * for all purposes other than a direct read, the ZCR_ELx.LEN field
13761 * has an effective value of 0".
13763 * Consider EL2 (aa64, vq=4) -> EL0 (aa32) -> EL1 (aa64, vq=0).
13764 * If we ignore aa32 state, we would fail to see the vq4->vq0 transition
13765 * from EL2->EL1. Thus we go ahead and narrow when entering aa32 so that
13766 * we already have the correct register contents when encountering the
13767 * vq0->vq0 transition between EL0->EL1.
13769 old_a64
= old_el
? arm_el_is_aa64(env
, old_el
) : el0_a64
;
13770 old_len
= (old_a64
&& !sve_exception_el(env
, old_el
)
13771 ? sve_zcr_len_for_el(env
, old_el
) : 0);
13772 new_a64
= new_el
? arm_el_is_aa64(env
, new_el
) : el0_a64
;
13773 new_len
= (new_a64
&& !sve_exception_el(env
, new_el
)
13774 ? sve_zcr_len_for_el(env
, new_el
) : 0);
13776 /* When changing vector length, clear inaccessible state. */
13777 if (new_len
< old_len
) {
13778 aarch64_sve_narrow_vq(env
, new_len
+ 1);