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"
12 #include "target/arm/idau.h"
15 #include "internals.h"
16 #include "exec/helper-proto.h"
17 #include "qemu/host-utils.h"
18 #include "qemu/main-loop.h"
19 #include "qemu/timer.h"
20 #include "qemu/bitops.h"
21 #include "qemu/crc32c.h"
22 #include "qemu/qemu-print.h"
23 #include "exec/exec-all.h"
24 #include <zlib.h> /* For crc32 */
26 #include "semihosting/semihost.h"
27 #include "sysemu/cpus.h"
28 #include "sysemu/cpu-timers.h"
29 #include "sysemu/kvm.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"
41 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */
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 uint64_t raw_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
59 assert(ri
->fieldoffset
);
60 if (cpreg_field_is_64bit(ri
)) {
61 return CPREG_FIELD64(env
, ri
);
63 return CPREG_FIELD32(env
, ri
);
67 static void raw_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
70 assert(ri
->fieldoffset
);
71 if (cpreg_field_is_64bit(ri
)) {
72 CPREG_FIELD64(env
, ri
) = value
;
74 CPREG_FIELD32(env
, ri
) = value
;
78 static void *raw_ptr(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
80 return (char *)env
+ ri
->fieldoffset
;
83 uint64_t read_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
85 /* Raw read of a coprocessor register (as needed for migration, etc). */
86 if (ri
->type
& ARM_CP_CONST
) {
87 return ri
->resetvalue
;
88 } else if (ri
->raw_readfn
) {
89 return ri
->raw_readfn(env
, ri
);
90 } else if (ri
->readfn
) {
91 return ri
->readfn(env
, ri
);
93 return raw_read(env
, ri
);
97 static void write_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
100 /* Raw write of a coprocessor register (as needed for migration, etc).
101 * Note that constant registers are treated as write-ignored; the
102 * caller should check for success by whether a readback gives the
105 if (ri
->type
& ARM_CP_CONST
) {
107 } else if (ri
->raw_writefn
) {
108 ri
->raw_writefn(env
, ri
, v
);
109 } else if (ri
->writefn
) {
110 ri
->writefn(env
, ri
, v
);
112 raw_write(env
, ri
, v
);
116 static bool raw_accessors_invalid(const ARMCPRegInfo
*ri
)
118 /* Return true if the regdef would cause an assertion if you called
119 * read_raw_cp_reg() or write_raw_cp_reg() on it (ie if it is a
120 * program bug for it not to have the NO_RAW flag).
121 * NB that returning false here doesn't necessarily mean that calling
122 * read/write_raw_cp_reg() is safe, because we can't distinguish "has
123 * read/write access functions which are safe for raw use" from "has
124 * read/write access functions which have side effects but has forgotten
125 * to provide raw access functions".
126 * The tests here line up with the conditions in read/write_raw_cp_reg()
127 * and assertions in raw_read()/raw_write().
129 if ((ri
->type
& ARM_CP_CONST
) ||
131 ((ri
->raw_writefn
|| ri
->writefn
) && (ri
->raw_readfn
|| ri
->readfn
))) {
137 bool write_cpustate_to_list(ARMCPU
*cpu
, bool kvm_sync
)
139 /* Write the coprocessor state from cpu->env to the (index,value) list. */
143 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
144 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
145 const ARMCPRegInfo
*ri
;
148 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
153 if (ri
->type
& ARM_CP_NO_RAW
) {
157 newval
= read_raw_cp_reg(&cpu
->env
, ri
);
160 * Only sync if the previous list->cpustate sync succeeded.
161 * Rather than tracking the success/failure state for every
162 * item in the list, we just recheck "does the raw write we must
163 * have made in write_list_to_cpustate() read back OK" here.
165 uint64_t oldval
= cpu
->cpreg_values
[i
];
167 if (oldval
== newval
) {
171 write_raw_cp_reg(&cpu
->env
, ri
, oldval
);
172 if (read_raw_cp_reg(&cpu
->env
, ri
) != oldval
) {
176 write_raw_cp_reg(&cpu
->env
, ri
, newval
);
178 cpu
->cpreg_values
[i
] = newval
;
183 bool write_list_to_cpustate(ARMCPU
*cpu
)
188 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
189 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
190 uint64_t v
= cpu
->cpreg_values
[i
];
191 const ARMCPRegInfo
*ri
;
193 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
198 if (ri
->type
& ARM_CP_NO_RAW
) {
201 /* Write value and confirm it reads back as written
202 * (to catch read-only registers and partially read-only
203 * registers where the incoming migration value doesn't match)
205 write_raw_cp_reg(&cpu
->env
, ri
, v
);
206 if (read_raw_cp_reg(&cpu
->env
, ri
) != v
) {
213 static void add_cpreg_to_list(gpointer key
, gpointer opaque
)
215 ARMCPU
*cpu
= opaque
;
216 uint32_t regidx
= (uintptr_t)key
;
217 const ARMCPRegInfo
*ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
219 if (!(ri
->type
& (ARM_CP_NO_RAW
|ARM_CP_ALIAS
))) {
220 cpu
->cpreg_indexes
[cpu
->cpreg_array_len
] = cpreg_to_kvm_id(regidx
);
221 /* The value array need not be initialized at this point */
222 cpu
->cpreg_array_len
++;
226 static void count_cpreg(gpointer key
, gpointer opaque
)
228 ARMCPU
*cpu
= opaque
;
229 const ARMCPRegInfo
*ri
;
231 ri
= g_hash_table_lookup(cpu
->cp_regs
, key
);
233 if (!(ri
->type
& (ARM_CP_NO_RAW
|ARM_CP_ALIAS
))) {
234 cpu
->cpreg_array_len
++;
238 static gint
cpreg_key_compare(gconstpointer a
, gconstpointer b
)
240 uint64_t aidx
= cpreg_to_kvm_id((uintptr_t)a
);
241 uint64_t bidx
= cpreg_to_kvm_id((uintptr_t)b
);
252 void init_cpreg_list(ARMCPU
*cpu
)
254 /* Initialise the cpreg_tuples[] array based on the cp_regs hash.
255 * Note that we require cpreg_tuples[] to be sorted by key ID.
260 keys
= g_hash_table_get_keys(cpu
->cp_regs
);
261 keys
= g_list_sort(keys
, cpreg_key_compare
);
263 cpu
->cpreg_array_len
= 0;
265 g_list_foreach(keys
, count_cpreg
, cpu
);
267 arraylen
= cpu
->cpreg_array_len
;
268 cpu
->cpreg_indexes
= g_new(uint64_t, arraylen
);
269 cpu
->cpreg_values
= g_new(uint64_t, arraylen
);
270 cpu
->cpreg_vmstate_indexes
= g_new(uint64_t, arraylen
);
271 cpu
->cpreg_vmstate_values
= g_new(uint64_t, arraylen
);
272 cpu
->cpreg_vmstate_array_len
= cpu
->cpreg_array_len
;
273 cpu
->cpreg_array_len
= 0;
275 g_list_foreach(keys
, add_cpreg_to_list
, cpu
);
277 assert(cpu
->cpreg_array_len
== arraylen
);
283 * Some registers are not accessible from AArch32 EL3 if SCR.NS == 0.
285 static CPAccessResult
access_el3_aa32ns(CPUARMState
*env
,
286 const ARMCPRegInfo
*ri
,
289 if (!is_a64(env
) && arm_current_el(env
) == 3 &&
290 arm_is_secure_below_el3(env
)) {
291 return CP_ACCESS_TRAP_UNCATEGORIZED
;
296 /* Some secure-only AArch32 registers trap to EL3 if used from
297 * Secure EL1 (but are just ordinary UNDEF in other non-EL3 contexts).
298 * Note that an access from Secure EL1 can only happen if EL3 is AArch64.
299 * We assume that the .access field is set to PL1_RW.
301 static CPAccessResult
access_trap_aa32s_el1(CPUARMState
*env
,
302 const ARMCPRegInfo
*ri
,
305 if (arm_current_el(env
) == 3) {
308 if (arm_is_secure_below_el3(env
)) {
309 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
310 return CP_ACCESS_TRAP_EL2
;
312 return CP_ACCESS_TRAP_EL3
;
314 /* This will be EL1 NS and EL2 NS, which just UNDEF */
315 return CP_ACCESS_TRAP_UNCATEGORIZED
;
318 static uint64_t arm_mdcr_el2_eff(CPUARMState
*env
)
320 return arm_is_el2_enabled(env
) ? env
->cp15
.mdcr_el2
: 0;
323 /* Check for traps to "powerdown debug" registers, which are controlled
326 static CPAccessResult
access_tdosa(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
329 int el
= arm_current_el(env
);
330 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
331 bool mdcr_el2_tdosa
= (mdcr_el2
& MDCR_TDOSA
) || (mdcr_el2
& MDCR_TDE
) ||
332 (arm_hcr_el2_eff(env
) & HCR_TGE
);
334 if (el
< 2 && mdcr_el2_tdosa
) {
335 return CP_ACCESS_TRAP_EL2
;
337 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDOSA
)) {
338 return CP_ACCESS_TRAP_EL3
;
343 /* Check for traps to "debug ROM" registers, which are controlled
344 * by MDCR_EL2.TDRA for EL2 but by the more general MDCR_EL3.TDA for EL3.
346 static CPAccessResult
access_tdra(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
349 int el
= arm_current_el(env
);
350 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
351 bool mdcr_el2_tdra
= (mdcr_el2
& MDCR_TDRA
) || (mdcr_el2
& MDCR_TDE
) ||
352 (arm_hcr_el2_eff(env
) & HCR_TGE
);
354 if (el
< 2 && mdcr_el2_tdra
) {
355 return CP_ACCESS_TRAP_EL2
;
357 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDA
)) {
358 return CP_ACCESS_TRAP_EL3
;
363 /* Check for traps to general debug registers, which are controlled
364 * by MDCR_EL2.TDA for EL2 and MDCR_EL3.TDA for EL3.
366 static CPAccessResult
access_tda(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
369 int el
= arm_current_el(env
);
370 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
371 bool mdcr_el2_tda
= (mdcr_el2
& MDCR_TDA
) || (mdcr_el2
& MDCR_TDE
) ||
372 (arm_hcr_el2_eff(env
) & HCR_TGE
);
374 if (el
< 2 && mdcr_el2_tda
) {
375 return CP_ACCESS_TRAP_EL2
;
377 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDA
)) {
378 return CP_ACCESS_TRAP_EL3
;
383 /* Check for traps to performance monitor registers, which are controlled
384 * by MDCR_EL2.TPM for EL2 and MDCR_EL3.TPM for EL3.
386 static CPAccessResult
access_tpm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
389 int el
= arm_current_el(env
);
390 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
392 if (el
< 2 && (mdcr_el2
& MDCR_TPM
)) {
393 return CP_ACCESS_TRAP_EL2
;
395 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
396 return CP_ACCESS_TRAP_EL3
;
401 /* Check for traps from EL1 due to HCR_EL2.TVM and HCR_EL2.TRVM. */
402 static CPAccessResult
access_tvm_trvm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
405 if (arm_current_el(env
) == 1) {
406 uint64_t trap
= isread
? HCR_TRVM
: HCR_TVM
;
407 if (arm_hcr_el2_eff(env
) & trap
) {
408 return CP_ACCESS_TRAP_EL2
;
414 /* Check for traps from EL1 due to HCR_EL2.TSW. */
415 static CPAccessResult
access_tsw(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
418 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TSW
)) {
419 return CP_ACCESS_TRAP_EL2
;
424 /* Check for traps from EL1 due to HCR_EL2.TACR. */
425 static CPAccessResult
access_tacr(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
428 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TACR
)) {
429 return CP_ACCESS_TRAP_EL2
;
434 /* Check for traps from EL1 due to HCR_EL2.TTLB. */
435 static CPAccessResult
access_ttlb(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
438 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TTLB
)) {
439 return CP_ACCESS_TRAP_EL2
;
444 static void dacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
446 ARMCPU
*cpu
= env_archcpu(env
);
448 raw_write(env
, ri
, value
);
449 tlb_flush(CPU(cpu
)); /* Flush TLB as domain not tracked in TLB */
452 static void fcse_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
454 ARMCPU
*cpu
= env_archcpu(env
);
456 if (raw_read(env
, ri
) != value
) {
457 /* Unlike real hardware the qemu TLB uses virtual addresses,
458 * not modified virtual addresses, so this causes a TLB flush.
461 raw_write(env
, ri
, value
);
465 static void contextidr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
468 ARMCPU
*cpu
= env_archcpu(env
);
470 if (raw_read(env
, ri
) != value
&& !arm_feature(env
, ARM_FEATURE_PMSA
)
471 && !extended_addresses_enabled(env
)) {
472 /* For VMSA (when not using the LPAE long descriptor page table
473 * format) this register includes the ASID, so do a TLB flush.
474 * For PMSA it is purely a process ID and no action is needed.
478 raw_write(env
, ri
, value
);
481 /* IS variants of TLB operations must affect all cores */
482 static void tlbiall_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
485 CPUState
*cs
= env_cpu(env
);
487 tlb_flush_all_cpus_synced(cs
);
490 static void tlbiasid_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
493 CPUState
*cs
= env_cpu(env
);
495 tlb_flush_all_cpus_synced(cs
);
498 static void tlbimva_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
501 CPUState
*cs
= env_cpu(env
);
503 tlb_flush_page_all_cpus_synced(cs
, value
& TARGET_PAGE_MASK
);
506 static void tlbimvaa_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
509 CPUState
*cs
= env_cpu(env
);
511 tlb_flush_page_all_cpus_synced(cs
, value
& TARGET_PAGE_MASK
);
515 * Non-IS variants of TLB operations are upgraded to
516 * IS versions if we are at EL1 and HCR_EL2.FB is effectively set to
517 * force broadcast of these operations.
519 static bool tlb_force_broadcast(CPUARMState
*env
)
521 return arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_FB
);
524 static void tlbiall_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
527 /* Invalidate all (TLBIALL) */
528 CPUState
*cs
= env_cpu(env
);
530 if (tlb_force_broadcast(env
)) {
531 tlb_flush_all_cpus_synced(cs
);
537 static void tlbimva_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
540 /* Invalidate single TLB entry by MVA and ASID (TLBIMVA) */
541 CPUState
*cs
= env_cpu(env
);
543 value
&= TARGET_PAGE_MASK
;
544 if (tlb_force_broadcast(env
)) {
545 tlb_flush_page_all_cpus_synced(cs
, value
);
547 tlb_flush_page(cs
, value
);
551 static void tlbiasid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
554 /* Invalidate by ASID (TLBIASID) */
555 CPUState
*cs
= env_cpu(env
);
557 if (tlb_force_broadcast(env
)) {
558 tlb_flush_all_cpus_synced(cs
);
564 static void tlbimvaa_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
567 /* Invalidate single entry by MVA, all ASIDs (TLBIMVAA) */
568 CPUState
*cs
= env_cpu(env
);
570 value
&= TARGET_PAGE_MASK
;
571 if (tlb_force_broadcast(env
)) {
572 tlb_flush_page_all_cpus_synced(cs
, value
);
574 tlb_flush_page(cs
, value
);
578 static void tlbiall_nsnh_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
581 CPUState
*cs
= env_cpu(env
);
583 tlb_flush_by_mmuidx(cs
,
585 ARMMMUIdxBit_E10_1_PAN
|
589 static void tlbiall_nsnh_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
592 CPUState
*cs
= env_cpu(env
);
594 tlb_flush_by_mmuidx_all_cpus_synced(cs
,
596 ARMMMUIdxBit_E10_1_PAN
|
601 static void tlbiall_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
604 CPUState
*cs
= env_cpu(env
);
606 tlb_flush_by_mmuidx(cs
, ARMMMUIdxBit_E2
);
609 static void tlbiall_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
612 CPUState
*cs
= env_cpu(env
);
614 tlb_flush_by_mmuidx_all_cpus_synced(cs
, ARMMMUIdxBit_E2
);
617 static void tlbimva_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
620 CPUState
*cs
= env_cpu(env
);
621 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
623 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_E2
);
626 static void tlbimva_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
629 CPUState
*cs
= env_cpu(env
);
630 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
632 tlb_flush_page_by_mmuidx_all_cpus_synced(cs
, pageaddr
,
636 static const ARMCPRegInfo cp_reginfo
[] = {
637 /* Define the secure and non-secure FCSE identifier CP registers
638 * separately because there is no secure bank in V8 (no _EL3). This allows
639 * the secure register to be properly reset and migrated. There is also no
640 * v8 EL1 version of the register so the non-secure instance stands alone.
643 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
644 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_NS
,
645 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_ns
),
646 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
647 { .name
= "FCSEIDR_S",
648 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
649 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_S
,
650 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_s
),
651 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
652 /* Define the secure and non-secure context identifier CP registers
653 * separately because there is no secure bank in V8 (no _EL3). This allows
654 * the secure register to be properly reset and migrated. In the
655 * non-secure case, the 32-bit register will have reset and migration
656 * disabled during registration as it is handled by the 64-bit instance.
658 { .name
= "CONTEXTIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
659 .opc0
= 3, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
660 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
661 .secure
= ARM_CP_SECSTATE_NS
,
662 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[1]),
663 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
664 { .name
= "CONTEXTIDR_S", .state
= ARM_CP_STATE_AA32
,
665 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
666 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
667 .secure
= ARM_CP_SECSTATE_S
,
668 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_s
),
669 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
672 static const ARMCPRegInfo not_v8_cp_reginfo
[] = {
673 /* NB: Some of these registers exist in v8 but with more precise
674 * definitions that don't use CP_ANY wildcards (mostly in v8_cp_reginfo[]).
676 /* MMU Domain access control / MPU write buffer control */
678 .cp
= 15, .opc1
= CP_ANY
, .crn
= 3, .crm
= CP_ANY
, .opc2
= CP_ANY
,
679 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
680 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
681 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
682 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
683 /* ARMv7 allocates a range of implementation defined TLB LOCKDOWN regs.
684 * For v6 and v5, these mappings are overly broad.
686 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 0,
687 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
688 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 1,
689 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
690 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 4,
691 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
692 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 8,
693 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
694 /* Cache maintenance ops; some of this space may be overridden later. */
695 { .name
= "CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
696 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
697 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
},
700 static const ARMCPRegInfo not_v6_cp_reginfo
[] = {
701 /* Not all pre-v6 cores implemented this WFI, so this is slightly
704 { .name
= "WFI_v5", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= 2,
705 .access
= PL1_W
, .type
= ARM_CP_WFI
},
708 static const ARMCPRegInfo not_v7_cp_reginfo
[] = {
709 /* Standard v6 WFI (also used in some pre-v6 cores); not in v7 (which
710 * is UNPREDICTABLE; we choose to NOP as most implementations do).
712 { .name
= "WFI_v6", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
713 .access
= PL1_W
, .type
= ARM_CP_WFI
},
714 /* L1 cache lockdown. Not architectural in v6 and earlier but in practice
715 * implemented in 926, 946, 1026, 1136, 1176 and 11MPCore. StrongARM and
716 * OMAPCP will override this space.
718 { .name
= "DLOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 0,
719 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_data
),
721 { .name
= "ILOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 1,
722 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_insn
),
724 /* v6 doesn't have the cache ID registers but Linux reads them anyway */
725 { .name
= "DUMMY", .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= CP_ANY
,
726 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
728 /* We don't implement pre-v7 debug but most CPUs had at least a DBGDIDR;
729 * implementing it as RAZ means the "debug architecture version" bits
730 * will read as a reserved value, which should cause Linux to not try
731 * to use the debug hardware.
733 { .name
= "DBGDIDR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 0,
734 .access
= PL0_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
735 /* MMU TLB control. Note that the wildcarding means we cover not just
736 * the unified TLB ops but also the dside/iside/inner-shareable variants.
738 { .name
= "TLBIALL", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
739 .opc1
= CP_ANY
, .opc2
= 0, .access
= PL1_W
, .writefn
= tlbiall_write
,
740 .type
= ARM_CP_NO_RAW
},
741 { .name
= "TLBIMVA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
742 .opc1
= CP_ANY
, .opc2
= 1, .access
= PL1_W
, .writefn
= tlbimva_write
,
743 .type
= ARM_CP_NO_RAW
},
744 { .name
= "TLBIASID", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
745 .opc1
= CP_ANY
, .opc2
= 2, .access
= PL1_W
, .writefn
= tlbiasid_write
,
746 .type
= ARM_CP_NO_RAW
},
747 { .name
= "TLBIMVAA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
748 .opc1
= CP_ANY
, .opc2
= 3, .access
= PL1_W
, .writefn
= tlbimvaa_write
,
749 .type
= ARM_CP_NO_RAW
},
750 { .name
= "PRRR", .cp
= 15, .crn
= 10, .crm
= 2,
751 .opc1
= 0, .opc2
= 0, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
752 { .name
= "NMRR", .cp
= 15, .crn
= 10, .crm
= 2,
753 .opc1
= 0, .opc2
= 1, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
756 static void cpacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
761 /* In ARMv8 most bits of CPACR_EL1 are RES0. */
762 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
763 /* ARMv7 defines bits for unimplemented coprocessors as RAZ/WI.
764 * ASEDIS [31] and D32DIS [30] are both UNK/SBZP without VFP.
765 * TRCDIS [28] is RAZ/WI since we do not implement a trace macrocell.
767 if (cpu_isar_feature(aa32_vfp_simd
, env_archcpu(env
))) {
768 /* VFP coprocessor: cp10 & cp11 [23:20] */
769 mask
|= R_CPACR_ASEDIS_MASK
|
770 R_CPACR_D32DIS_MASK
|
774 if (!arm_feature(env
, ARM_FEATURE_NEON
)) {
775 /* ASEDIS [31] bit is RAO/WI */
776 value
|= R_CPACR_ASEDIS_MASK
;
779 /* VFPv3 and upwards with NEON implement 32 double precision
780 * registers (D0-D31).
782 if (!cpu_isar_feature(aa32_simd_r32
, env_archcpu(env
))) {
783 /* D32DIS [30] is RAO/WI if D16-31 are not implemented. */
784 value
|= R_CPACR_D32DIS_MASK
;
791 * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10
792 * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00.
794 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
795 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
796 mask
= R_CPACR_CP11_MASK
| R_CPACR_CP10_MASK
;
797 value
= (value
& ~mask
) | (env
->cp15
.cpacr_el1
& mask
);
800 env
->cp15
.cpacr_el1
= value
;
803 static uint64_t cpacr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
806 * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10
807 * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00.
809 uint64_t value
= env
->cp15
.cpacr_el1
;
811 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
812 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
813 value
= ~(R_CPACR_CP11_MASK
| R_CPACR_CP10_MASK
);
819 static void cpacr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
821 /* Call cpacr_write() so that we reset with the correct RAO bits set
822 * for our CPU features.
824 cpacr_write(env
, ri
, 0);
827 static CPAccessResult
cpacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
830 if (arm_feature(env
, ARM_FEATURE_V8
)) {
831 /* Check if CPACR accesses are to be trapped to EL2 */
832 if (arm_current_el(env
) == 1 && arm_is_el2_enabled(env
) &&
833 FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TCPAC
)) {
834 return CP_ACCESS_TRAP_EL2
;
835 /* Check if CPACR accesses are to be trapped to EL3 */
836 } else if (arm_current_el(env
) < 3 &&
837 FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TCPAC
)) {
838 return CP_ACCESS_TRAP_EL3
;
845 static CPAccessResult
cptr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
848 /* Check if CPTR accesses are set to trap to EL3 */
849 if (arm_current_el(env
) == 2 &&
850 FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TCPAC
)) {
851 return CP_ACCESS_TRAP_EL3
;
857 static const ARMCPRegInfo v6_cp_reginfo
[] = {
858 /* prefetch by MVA in v6, NOP in v7 */
859 { .name
= "MVA_prefetch",
860 .cp
= 15, .crn
= 7, .crm
= 13, .opc1
= 0, .opc2
= 1,
861 .access
= PL1_W
, .type
= ARM_CP_NOP
},
862 /* We need to break the TB after ISB to execute self-modifying code
863 * correctly and also to take any pending interrupts immediately.
864 * So use arm_cp_write_ignore() function instead of ARM_CP_NOP flag.
866 { .name
= "ISB", .cp
= 15, .crn
= 7, .crm
= 5, .opc1
= 0, .opc2
= 4,
867 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
, .writefn
= arm_cp_write_ignore
},
868 { .name
= "DSB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 4,
869 .access
= PL0_W
, .type
= ARM_CP_NOP
},
870 { .name
= "DMB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 5,
871 .access
= PL0_W
, .type
= ARM_CP_NOP
},
872 { .name
= "IFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 2,
873 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
874 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ifar_s
),
875 offsetof(CPUARMState
, cp15
.ifar_ns
) },
877 /* Watchpoint Fault Address Register : should actually only be present
878 * for 1136, 1176, 11MPCore.
880 { .name
= "WFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 1,
881 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0, },
882 { .name
= "CPACR", .state
= ARM_CP_STATE_BOTH
, .opc0
= 3,
883 .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 2, .accessfn
= cpacr_access
,
884 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.cpacr_el1
),
885 .resetfn
= cpacr_reset
, .writefn
= cpacr_write
, .readfn
= cpacr_read
},
888 typedef struct pm_event
{
889 uint16_t number
; /* PMEVTYPER.evtCount is 16 bits wide */
890 /* If the event is supported on this CPU (used to generate PMCEID[01]) */
891 bool (*supported
)(CPUARMState
*);
893 * Retrieve the current count of the underlying event. The programmed
894 * counters hold a difference from the return value from this function
896 uint64_t (*get_count
)(CPUARMState
*);
898 * Return how many nanoseconds it will take (at a minimum) for count events
899 * to occur. A negative value indicates the counter will never overflow, or
900 * that the counter has otherwise arranged for the overflow bit to be set
901 * and the PMU interrupt to be raised on overflow.
903 int64_t (*ns_per_count
)(uint64_t);
906 static bool event_always_supported(CPUARMState
*env
)
911 static uint64_t swinc_get_count(CPUARMState
*env
)
914 * SW_INCR events are written directly to the pmevcntr's by writes to
915 * PMSWINC, so there is no underlying count maintained by the PMU itself
920 static int64_t swinc_ns_per(uint64_t ignored
)
926 * Return the underlying cycle count for the PMU cycle counters. If we're in
927 * usermode, simply return 0.
929 static uint64_t cycles_get_count(CPUARMState
*env
)
931 #ifndef CONFIG_USER_ONLY
932 return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
933 ARM_CPU_FREQ
, NANOSECONDS_PER_SECOND
);
935 return cpu_get_host_ticks();
939 #ifndef CONFIG_USER_ONLY
940 static int64_t cycles_ns_per(uint64_t cycles
)
942 return (ARM_CPU_FREQ
/ NANOSECONDS_PER_SECOND
) * cycles
;
945 static bool instructions_supported(CPUARMState
*env
)
947 return icount_enabled() == 1; /* Precise instruction counting */
950 static uint64_t instructions_get_count(CPUARMState
*env
)
952 return (uint64_t)icount_get_raw();
955 static int64_t instructions_ns_per(uint64_t icount
)
957 return icount_to_ns((int64_t)icount
);
961 static bool pmu_8_1_events_supported(CPUARMState
*env
)
963 /* For events which are supported in any v8.1 PMU */
964 return cpu_isar_feature(any_pmu_8_1
, env_archcpu(env
));
967 static bool pmu_8_4_events_supported(CPUARMState
*env
)
969 /* For events which are supported in any v8.1 PMU */
970 return cpu_isar_feature(any_pmu_8_4
, env_archcpu(env
));
973 static uint64_t zero_event_get_count(CPUARMState
*env
)
975 /* For events which on QEMU never fire, so their count is always zero */
979 static int64_t zero_event_ns_per(uint64_t cycles
)
981 /* An event which never fires can never overflow */
985 static const pm_event pm_events
[] = {
986 { .number
= 0x000, /* SW_INCR */
987 .supported
= event_always_supported
,
988 .get_count
= swinc_get_count
,
989 .ns_per_count
= swinc_ns_per
,
991 #ifndef CONFIG_USER_ONLY
992 { .number
= 0x008, /* INST_RETIRED, Instruction architecturally executed */
993 .supported
= instructions_supported
,
994 .get_count
= instructions_get_count
,
995 .ns_per_count
= instructions_ns_per
,
997 { .number
= 0x011, /* CPU_CYCLES, Cycle */
998 .supported
= event_always_supported
,
999 .get_count
= cycles_get_count
,
1000 .ns_per_count
= cycles_ns_per
,
1003 { .number
= 0x023, /* STALL_FRONTEND */
1004 .supported
= pmu_8_1_events_supported
,
1005 .get_count
= zero_event_get_count
,
1006 .ns_per_count
= zero_event_ns_per
,
1008 { .number
= 0x024, /* STALL_BACKEND */
1009 .supported
= pmu_8_1_events_supported
,
1010 .get_count
= zero_event_get_count
,
1011 .ns_per_count
= zero_event_ns_per
,
1013 { .number
= 0x03c, /* STALL */
1014 .supported
= pmu_8_4_events_supported
,
1015 .get_count
= zero_event_get_count
,
1016 .ns_per_count
= zero_event_ns_per
,
1021 * Note: Before increasing MAX_EVENT_ID beyond 0x3f into the 0x40xx range of
1022 * events (i.e. the statistical profiling extension), this implementation
1023 * should first be updated to something sparse instead of the current
1024 * supported_event_map[] array.
1026 #define MAX_EVENT_ID 0x3c
1027 #define UNSUPPORTED_EVENT UINT16_MAX
1028 static uint16_t supported_event_map
[MAX_EVENT_ID
+ 1];
1031 * Called upon CPU initialization to initialize PMCEID[01]_EL0 and build a map
1032 * of ARM event numbers to indices in our pm_events array.
1034 * Note: Events in the 0x40XX range are not currently supported.
1036 void pmu_init(ARMCPU
*cpu
)
1041 * Empty supported_event_map and cpu->pmceid[01] before adding supported
1044 for (i
= 0; i
< ARRAY_SIZE(supported_event_map
); i
++) {
1045 supported_event_map
[i
] = UNSUPPORTED_EVENT
;
1050 for (i
= 0; i
< ARRAY_SIZE(pm_events
); i
++) {
1051 const pm_event
*cnt
= &pm_events
[i
];
1052 assert(cnt
->number
<= MAX_EVENT_ID
);
1053 /* We do not currently support events in the 0x40xx range */
1054 assert(cnt
->number
<= 0x3f);
1056 if (cnt
->supported(&cpu
->env
)) {
1057 supported_event_map
[cnt
->number
] = i
;
1058 uint64_t event_mask
= 1ULL << (cnt
->number
& 0x1f);
1059 if (cnt
->number
& 0x20) {
1060 cpu
->pmceid1
|= event_mask
;
1062 cpu
->pmceid0
|= event_mask
;
1069 * Check at runtime whether a PMU event is supported for the current machine
1071 static bool event_supported(uint16_t number
)
1073 if (number
> MAX_EVENT_ID
) {
1076 return supported_event_map
[number
] != UNSUPPORTED_EVENT
;
1079 static CPAccessResult
pmreg_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1082 /* Performance monitor registers user accessibility is controlled
1083 * by PMUSERENR. MDCR_EL2.TPM and MDCR_EL3.TPM allow configurable
1084 * trapping to EL2 or EL3 for other accesses.
1086 int el
= arm_current_el(env
);
1087 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
1089 if (el
== 0 && !(env
->cp15
.c9_pmuserenr
& 1)) {
1090 return CP_ACCESS_TRAP
;
1092 if (el
< 2 && (mdcr_el2
& MDCR_TPM
)) {
1093 return CP_ACCESS_TRAP_EL2
;
1095 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
1096 return CP_ACCESS_TRAP_EL3
;
1099 return CP_ACCESS_OK
;
1102 static CPAccessResult
pmreg_access_xevcntr(CPUARMState
*env
,
1103 const ARMCPRegInfo
*ri
,
1106 /* ER: event counter read trap control */
1107 if (arm_feature(env
, ARM_FEATURE_V8
)
1108 && arm_current_el(env
) == 0
1109 && (env
->cp15
.c9_pmuserenr
& (1 << 3)) != 0
1111 return CP_ACCESS_OK
;
1114 return pmreg_access(env
, ri
, isread
);
1117 static CPAccessResult
pmreg_access_swinc(CPUARMState
*env
,
1118 const ARMCPRegInfo
*ri
,
1121 /* SW: software increment write trap control */
1122 if (arm_feature(env
, ARM_FEATURE_V8
)
1123 && arm_current_el(env
) == 0
1124 && (env
->cp15
.c9_pmuserenr
& (1 << 1)) != 0
1126 return CP_ACCESS_OK
;
1129 return pmreg_access(env
, ri
, isread
);
1132 static CPAccessResult
pmreg_access_selr(CPUARMState
*env
,
1133 const ARMCPRegInfo
*ri
,
1136 /* ER: event counter read trap control */
1137 if (arm_feature(env
, ARM_FEATURE_V8
)
1138 && arm_current_el(env
) == 0
1139 && (env
->cp15
.c9_pmuserenr
& (1 << 3)) != 0) {
1140 return CP_ACCESS_OK
;
1143 return pmreg_access(env
, ri
, isread
);
1146 static CPAccessResult
pmreg_access_ccntr(CPUARMState
*env
,
1147 const ARMCPRegInfo
*ri
,
1150 /* CR: cycle counter read trap control */
1151 if (arm_feature(env
, ARM_FEATURE_V8
)
1152 && arm_current_el(env
) == 0
1153 && (env
->cp15
.c9_pmuserenr
& (1 << 2)) != 0
1155 return CP_ACCESS_OK
;
1158 return pmreg_access(env
, ri
, isread
);
1161 /* Returns true if the counter (pass 31 for PMCCNTR) should count events using
1162 * the current EL, security state, and register configuration.
1164 static bool pmu_counter_enabled(CPUARMState
*env
, uint8_t counter
)
1167 bool e
, p
, u
, nsk
, nsu
, nsh
, m
;
1168 bool enabled
, prohibited
, filtered
;
1169 bool secure
= arm_is_secure(env
);
1170 int el
= arm_current_el(env
);
1171 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
1172 uint8_t hpmn
= mdcr_el2
& MDCR_HPMN
;
1174 if (!arm_feature(env
, ARM_FEATURE_PMU
)) {
1178 if (!arm_feature(env
, ARM_FEATURE_EL2
) ||
1179 (counter
< hpmn
|| counter
== 31)) {
1180 e
= env
->cp15
.c9_pmcr
& PMCRE
;
1182 e
= mdcr_el2
& MDCR_HPME
;
1184 enabled
= e
&& (env
->cp15
.c9_pmcnten
& (1 << counter
));
1187 if (el
== 2 && (counter
< hpmn
|| counter
== 31)) {
1188 prohibited
= mdcr_el2
& MDCR_HPMD
;
1193 prohibited
= arm_feature(env
, ARM_FEATURE_EL3
) &&
1194 !(env
->cp15
.mdcr_el3
& MDCR_SPME
);
1197 if (prohibited
&& counter
== 31) {
1198 prohibited
= env
->cp15
.c9_pmcr
& PMCRDP
;
1201 if (counter
== 31) {
1202 filter
= env
->cp15
.pmccfiltr_el0
;
1204 filter
= env
->cp15
.c14_pmevtyper
[counter
];
1207 p
= filter
& PMXEVTYPER_P
;
1208 u
= filter
& PMXEVTYPER_U
;
1209 nsk
= arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_NSK
);
1210 nsu
= arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_NSU
);
1211 nsh
= arm_feature(env
, ARM_FEATURE_EL2
) && (filter
& PMXEVTYPER_NSH
);
1212 m
= arm_el_is_aa64(env
, 1) &&
1213 arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_M
);
1216 filtered
= secure
? u
: u
!= nsu
;
1217 } else if (el
== 1) {
1218 filtered
= secure
? p
: p
!= nsk
;
1219 } else if (el
== 2) {
1225 if (counter
!= 31) {
1227 * If not checking PMCCNTR, ensure the counter is setup to an event we
1230 uint16_t event
= filter
& PMXEVTYPER_EVTCOUNT
;
1231 if (!event_supported(event
)) {
1236 return enabled
&& !prohibited
&& !filtered
;
1239 static void pmu_update_irq(CPUARMState
*env
)
1241 ARMCPU
*cpu
= env_archcpu(env
);
1242 qemu_set_irq(cpu
->pmu_interrupt
, (env
->cp15
.c9_pmcr
& PMCRE
) &&
1243 (env
->cp15
.c9_pminten
& env
->cp15
.c9_pmovsr
));
1247 * Ensure c15_ccnt is the guest-visible count so that operations such as
1248 * enabling/disabling the counter or filtering, modifying the count itself,
1249 * etc. can be done logically. This is essentially a no-op if the counter is
1250 * not enabled at the time of the call.
1252 static void pmccntr_op_start(CPUARMState
*env
)
1254 uint64_t cycles
= cycles_get_count(env
);
1256 if (pmu_counter_enabled(env
, 31)) {
1257 uint64_t eff_cycles
= cycles
;
1258 if (env
->cp15
.c9_pmcr
& PMCRD
) {
1259 /* Increment once every 64 processor clock cycles */
1263 uint64_t new_pmccntr
= eff_cycles
- env
->cp15
.c15_ccnt_delta
;
1265 uint64_t overflow_mask
= env
->cp15
.c9_pmcr
& PMCRLC
? \
1266 1ull << 63 : 1ull << 31;
1267 if (env
->cp15
.c15_ccnt
& ~new_pmccntr
& overflow_mask
) {
1268 env
->cp15
.c9_pmovsr
|= (1 << 31);
1269 pmu_update_irq(env
);
1272 env
->cp15
.c15_ccnt
= new_pmccntr
;
1274 env
->cp15
.c15_ccnt_delta
= cycles
;
1278 * If PMCCNTR is enabled, recalculate the delta between the clock and the
1279 * guest-visible count. A call to pmccntr_op_finish should follow every call to
1282 static void pmccntr_op_finish(CPUARMState
*env
)
1284 if (pmu_counter_enabled(env
, 31)) {
1285 #ifndef CONFIG_USER_ONLY
1286 /* Calculate when the counter will next overflow */
1287 uint64_t remaining_cycles
= -env
->cp15
.c15_ccnt
;
1288 if (!(env
->cp15
.c9_pmcr
& PMCRLC
)) {
1289 remaining_cycles
= (uint32_t)remaining_cycles
;
1291 int64_t overflow_in
= cycles_ns_per(remaining_cycles
);
1293 if (overflow_in
> 0) {
1294 int64_t overflow_at
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
1296 ARMCPU
*cpu
= env_archcpu(env
);
1297 timer_mod_anticipate_ns(cpu
->pmu_timer
, overflow_at
);
1301 uint64_t prev_cycles
= env
->cp15
.c15_ccnt_delta
;
1302 if (env
->cp15
.c9_pmcr
& PMCRD
) {
1303 /* Increment once every 64 processor clock cycles */
1306 env
->cp15
.c15_ccnt_delta
= prev_cycles
- env
->cp15
.c15_ccnt
;
1310 static void pmevcntr_op_start(CPUARMState
*env
, uint8_t counter
)
1313 uint16_t event
= env
->cp15
.c14_pmevtyper
[counter
] & PMXEVTYPER_EVTCOUNT
;
1315 if (event_supported(event
)) {
1316 uint16_t event_idx
= supported_event_map
[event
];
1317 count
= pm_events
[event_idx
].get_count(env
);
1320 if (pmu_counter_enabled(env
, counter
)) {
1321 uint32_t new_pmevcntr
= count
- env
->cp15
.c14_pmevcntr_delta
[counter
];
1323 if (env
->cp15
.c14_pmevcntr
[counter
] & ~new_pmevcntr
& INT32_MIN
) {
1324 env
->cp15
.c9_pmovsr
|= (1 << counter
);
1325 pmu_update_irq(env
);
1327 env
->cp15
.c14_pmevcntr
[counter
] = new_pmevcntr
;
1329 env
->cp15
.c14_pmevcntr_delta
[counter
] = count
;
1332 static void pmevcntr_op_finish(CPUARMState
*env
, uint8_t counter
)
1334 if (pmu_counter_enabled(env
, counter
)) {
1335 #ifndef CONFIG_USER_ONLY
1336 uint16_t event
= env
->cp15
.c14_pmevtyper
[counter
] & PMXEVTYPER_EVTCOUNT
;
1337 uint16_t event_idx
= supported_event_map
[event
];
1338 uint64_t delta
= UINT32_MAX
-
1339 (uint32_t)env
->cp15
.c14_pmevcntr
[counter
] + 1;
1340 int64_t overflow_in
= pm_events
[event_idx
].ns_per_count(delta
);
1342 if (overflow_in
> 0) {
1343 int64_t overflow_at
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) +
1345 ARMCPU
*cpu
= env_archcpu(env
);
1346 timer_mod_anticipate_ns(cpu
->pmu_timer
, overflow_at
);
1350 env
->cp15
.c14_pmevcntr_delta
[counter
] -=
1351 env
->cp15
.c14_pmevcntr
[counter
];
1355 void pmu_op_start(CPUARMState
*env
)
1358 pmccntr_op_start(env
);
1359 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1360 pmevcntr_op_start(env
, i
);
1364 void pmu_op_finish(CPUARMState
*env
)
1367 pmccntr_op_finish(env
);
1368 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1369 pmevcntr_op_finish(env
, i
);
1373 void pmu_pre_el_change(ARMCPU
*cpu
, void *ignored
)
1375 pmu_op_start(&cpu
->env
);
1378 void pmu_post_el_change(ARMCPU
*cpu
, void *ignored
)
1380 pmu_op_finish(&cpu
->env
);
1383 void arm_pmu_timer_cb(void *opaque
)
1385 ARMCPU
*cpu
= opaque
;
1388 * Update all the counter values based on the current underlying counts,
1389 * triggering interrupts to be raised, if necessary. pmu_op_finish() also
1390 * has the effect of setting the cpu->pmu_timer to the next earliest time a
1391 * counter may expire.
1393 pmu_op_start(&cpu
->env
);
1394 pmu_op_finish(&cpu
->env
);
1397 static void pmcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1402 if (value
& PMCRC
) {
1403 /* The counter has been reset */
1404 env
->cp15
.c15_ccnt
= 0;
1407 if (value
& PMCRP
) {
1409 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1410 env
->cp15
.c14_pmevcntr
[i
] = 0;
1414 env
->cp15
.c9_pmcr
&= ~PMCR_WRITABLE_MASK
;
1415 env
->cp15
.c9_pmcr
|= (value
& PMCR_WRITABLE_MASK
);
1420 static void pmswinc_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1424 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1425 /* Increment a counter's count iff: */
1426 if ((value
& (1 << i
)) && /* counter's bit is set */
1427 /* counter is enabled and not filtered */
1428 pmu_counter_enabled(env
, i
) &&
1429 /* counter is SW_INCR */
1430 (env
->cp15
.c14_pmevtyper
[i
] & PMXEVTYPER_EVTCOUNT
) == 0x0) {
1431 pmevcntr_op_start(env
, i
);
1434 * Detect if this write causes an overflow since we can't predict
1435 * PMSWINC overflows like we can for other events
1437 uint32_t new_pmswinc
= env
->cp15
.c14_pmevcntr
[i
] + 1;
1439 if (env
->cp15
.c14_pmevcntr
[i
] & ~new_pmswinc
& INT32_MIN
) {
1440 env
->cp15
.c9_pmovsr
|= (1 << i
);
1441 pmu_update_irq(env
);
1444 env
->cp15
.c14_pmevcntr
[i
] = new_pmswinc
;
1446 pmevcntr_op_finish(env
, i
);
1451 static uint64_t pmccntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1454 pmccntr_op_start(env
);
1455 ret
= env
->cp15
.c15_ccnt
;
1456 pmccntr_op_finish(env
);
1460 static void pmselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1463 /* The value of PMSELR.SEL affects the behavior of PMXEVTYPER and
1464 * PMXEVCNTR. We allow [0..31] to be written to PMSELR here; in the
1465 * meanwhile, we check PMSELR.SEL when PMXEVTYPER and PMXEVCNTR are
1468 env
->cp15
.c9_pmselr
= value
& 0x1f;
1471 static void pmccntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1474 pmccntr_op_start(env
);
1475 env
->cp15
.c15_ccnt
= value
;
1476 pmccntr_op_finish(env
);
1479 static void pmccntr_write32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1482 uint64_t cur_val
= pmccntr_read(env
, NULL
);
1484 pmccntr_write(env
, ri
, deposit64(cur_val
, 0, 32, value
));
1487 static void pmccfiltr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1490 pmccntr_op_start(env
);
1491 env
->cp15
.pmccfiltr_el0
= value
& PMCCFILTR_EL0
;
1492 pmccntr_op_finish(env
);
1495 static void pmccfiltr_write_a32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1498 pmccntr_op_start(env
);
1499 /* M is not accessible from AArch32 */
1500 env
->cp15
.pmccfiltr_el0
= (env
->cp15
.pmccfiltr_el0
& PMCCFILTR_M
) |
1501 (value
& PMCCFILTR
);
1502 pmccntr_op_finish(env
);
1505 static uint64_t pmccfiltr_read_a32(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1507 /* M is not visible in AArch32 */
1508 return env
->cp15
.pmccfiltr_el0
& PMCCFILTR
;
1511 static void pmcntenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1514 value
&= pmu_counter_mask(env
);
1515 env
->cp15
.c9_pmcnten
|= value
;
1518 static void pmcntenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1521 value
&= pmu_counter_mask(env
);
1522 env
->cp15
.c9_pmcnten
&= ~value
;
1525 static void pmovsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1528 value
&= pmu_counter_mask(env
);
1529 env
->cp15
.c9_pmovsr
&= ~value
;
1530 pmu_update_irq(env
);
1533 static void pmovsset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1536 value
&= pmu_counter_mask(env
);
1537 env
->cp15
.c9_pmovsr
|= value
;
1538 pmu_update_irq(env
);
1541 static void pmevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1542 uint64_t value
, const uint8_t counter
)
1544 if (counter
== 31) {
1545 pmccfiltr_write(env
, ri
, value
);
1546 } else if (counter
< pmu_num_counters(env
)) {
1547 pmevcntr_op_start(env
, counter
);
1550 * If this counter's event type is changing, store the current
1551 * underlying count for the new type in c14_pmevcntr_delta[counter] so
1552 * pmevcntr_op_finish has the correct baseline when it converts back to
1555 uint16_t old_event
= env
->cp15
.c14_pmevtyper
[counter
] &
1556 PMXEVTYPER_EVTCOUNT
;
1557 uint16_t new_event
= value
& PMXEVTYPER_EVTCOUNT
;
1558 if (old_event
!= new_event
) {
1560 if (event_supported(new_event
)) {
1561 uint16_t event_idx
= supported_event_map
[new_event
];
1562 count
= pm_events
[event_idx
].get_count(env
);
1564 env
->cp15
.c14_pmevcntr_delta
[counter
] = count
;
1567 env
->cp15
.c14_pmevtyper
[counter
] = value
& PMXEVTYPER_MASK
;
1568 pmevcntr_op_finish(env
, counter
);
1570 /* Attempts to access PMXEVTYPER are CONSTRAINED UNPREDICTABLE when
1571 * PMSELR value is equal to or greater than the number of implemented
1572 * counters, but not equal to 0x1f. We opt to behave as a RAZ/WI.
1576 static uint64_t pmevtyper_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1577 const uint8_t counter
)
1579 if (counter
== 31) {
1580 return env
->cp15
.pmccfiltr_el0
;
1581 } else if (counter
< pmu_num_counters(env
)) {
1582 return env
->cp15
.c14_pmevtyper
[counter
];
1585 * We opt to behave as a RAZ/WI when attempts to access PMXEVTYPER
1586 * are CONSTRAINED UNPREDICTABLE. See comments in pmevtyper_write().
1592 static void pmevtyper_writefn(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1595 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1596 pmevtyper_write(env
, ri
, value
, counter
);
1599 static void pmevtyper_rawwrite(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1602 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1603 env
->cp15
.c14_pmevtyper
[counter
] = value
;
1606 * pmevtyper_rawwrite is called between a pair of pmu_op_start and
1607 * pmu_op_finish calls when loading saved state for a migration. Because
1608 * we're potentially updating the type of event here, the value written to
1609 * c14_pmevcntr_delta by the preceeding pmu_op_start call may be for a
1610 * different counter type. Therefore, we need to set this value to the
1611 * current count for the counter type we're writing so that pmu_op_finish
1612 * has the correct count for its calculation.
1614 uint16_t event
= value
& PMXEVTYPER_EVTCOUNT
;
1615 if (event_supported(event
)) {
1616 uint16_t event_idx
= supported_event_map
[event
];
1617 env
->cp15
.c14_pmevcntr_delta
[counter
] =
1618 pm_events
[event_idx
].get_count(env
);
1622 static uint64_t pmevtyper_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1624 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1625 return pmevtyper_read(env
, ri
, counter
);
1628 static void pmxevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1631 pmevtyper_write(env
, ri
, value
, env
->cp15
.c9_pmselr
& 31);
1634 static uint64_t pmxevtyper_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1636 return pmevtyper_read(env
, ri
, env
->cp15
.c9_pmselr
& 31);
1639 static void pmevcntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1640 uint64_t value
, uint8_t counter
)
1642 if (counter
< pmu_num_counters(env
)) {
1643 pmevcntr_op_start(env
, counter
);
1644 env
->cp15
.c14_pmevcntr
[counter
] = value
;
1645 pmevcntr_op_finish(env
, counter
);
1648 * We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
1649 * are CONSTRAINED UNPREDICTABLE.
1653 static uint64_t pmevcntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1656 if (counter
< pmu_num_counters(env
)) {
1658 pmevcntr_op_start(env
, counter
);
1659 ret
= env
->cp15
.c14_pmevcntr
[counter
];
1660 pmevcntr_op_finish(env
, counter
);
1663 /* We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
1664 * are CONSTRAINED UNPREDICTABLE. */
1669 static void pmevcntr_writefn(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1672 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1673 pmevcntr_write(env
, ri
, value
, counter
);
1676 static uint64_t pmevcntr_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1678 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1679 return pmevcntr_read(env
, ri
, counter
);
1682 static void pmevcntr_rawwrite(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1685 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1686 assert(counter
< pmu_num_counters(env
));
1687 env
->cp15
.c14_pmevcntr
[counter
] = value
;
1688 pmevcntr_write(env
, ri
, value
, counter
);
1691 static uint64_t pmevcntr_rawread(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1693 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1694 assert(counter
< pmu_num_counters(env
));
1695 return env
->cp15
.c14_pmevcntr
[counter
];
1698 static void pmxevcntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1701 pmevcntr_write(env
, ri
, value
, env
->cp15
.c9_pmselr
& 31);
1704 static uint64_t pmxevcntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1706 return pmevcntr_read(env
, ri
, env
->cp15
.c9_pmselr
& 31);
1709 static void pmuserenr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1712 if (arm_feature(env
, ARM_FEATURE_V8
)) {
1713 env
->cp15
.c9_pmuserenr
= value
& 0xf;
1715 env
->cp15
.c9_pmuserenr
= value
& 1;
1719 static void pmintenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1722 /* We have no event counters so only the C bit can be changed */
1723 value
&= pmu_counter_mask(env
);
1724 env
->cp15
.c9_pminten
|= value
;
1725 pmu_update_irq(env
);
1728 static void pmintenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1731 value
&= pmu_counter_mask(env
);
1732 env
->cp15
.c9_pminten
&= ~value
;
1733 pmu_update_irq(env
);
1736 static void vbar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1739 /* Note that even though the AArch64 view of this register has bits
1740 * [10:0] all RES0 we can only mask the bottom 5, to comply with the
1741 * architectural requirements for bits which are RES0 only in some
1742 * contexts. (ARMv8 would permit us to do no masking at all, but ARMv7
1743 * requires the bottom five bits to be RAZ/WI because they're UNK/SBZP.)
1745 raw_write(env
, ri
, value
& ~0x1FULL
);
1748 static void scr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
1750 /* Begin with base v8.0 state. */
1751 uint32_t valid_mask
= 0x3fff;
1752 ARMCPU
*cpu
= env_archcpu(env
);
1754 if (ri
->state
== ARM_CP_STATE_AA64
) {
1755 if (arm_feature(env
, ARM_FEATURE_AARCH64
) &&
1756 !cpu_isar_feature(aa64_aa32_el1
, cpu
)) {
1757 value
|= SCR_FW
| SCR_AW
; /* these two bits are RES1. */
1759 valid_mask
&= ~SCR_NET
;
1761 if (cpu_isar_feature(aa64_ras
, cpu
)) {
1762 valid_mask
|= SCR_TERR
;
1764 if (cpu_isar_feature(aa64_lor
, cpu
)) {
1765 valid_mask
|= SCR_TLOR
;
1767 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
1768 valid_mask
|= SCR_API
| SCR_APK
;
1770 if (cpu_isar_feature(aa64_sel2
, cpu
)) {
1771 valid_mask
|= SCR_EEL2
;
1773 if (cpu_isar_feature(aa64_mte
, cpu
)) {
1774 valid_mask
|= SCR_ATA
;
1776 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
1777 valid_mask
|= SCR_ENSCXT
;
1779 if (cpu_isar_feature(aa64_doublefault
, cpu
)) {
1780 valid_mask
|= SCR_EASE
| SCR_NMEA
;
1783 valid_mask
&= ~(SCR_RW
| SCR_ST
);
1784 if (cpu_isar_feature(aa32_ras
, cpu
)) {
1785 valid_mask
|= SCR_TERR
;
1789 if (!arm_feature(env
, ARM_FEATURE_EL2
)) {
1790 valid_mask
&= ~SCR_HCE
;
1792 /* On ARMv7, SMD (or SCD as it is called in v7) is only
1793 * supported if EL2 exists. The bit is UNK/SBZP when
1794 * EL2 is unavailable. In QEMU ARMv7, we force it to always zero
1795 * when EL2 is unavailable.
1796 * On ARMv8, this bit is always available.
1798 if (arm_feature(env
, ARM_FEATURE_V7
) &&
1799 !arm_feature(env
, ARM_FEATURE_V8
)) {
1800 valid_mask
&= ~SCR_SMD
;
1804 /* Clear all-context RES0 bits. */
1805 value
&= valid_mask
;
1806 raw_write(env
, ri
, value
);
1809 static void scr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1812 * scr_write will set the RES1 bits on an AArch64-only CPU.
1813 * The reset value will be 0x30 on an AArch64-only CPU and 0 otherwise.
1815 scr_write(env
, ri
, 0);
1818 static CPAccessResult
access_aa64_tid2(CPUARMState
*env
,
1819 const ARMCPRegInfo
*ri
,
1822 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID2
)) {
1823 return CP_ACCESS_TRAP_EL2
;
1826 return CP_ACCESS_OK
;
1829 static uint64_t ccsidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1831 ARMCPU
*cpu
= env_archcpu(env
);
1833 /* Acquire the CSSELR index from the bank corresponding to the CCSIDR
1836 uint32_t index
= A32_BANKED_REG_GET(env
, csselr
,
1837 ri
->secure
& ARM_CP_SECSTATE_S
);
1839 return cpu
->ccsidr
[index
];
1842 static void csselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1845 raw_write(env
, ri
, value
& 0xf);
1848 static uint64_t isr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1850 CPUState
*cs
= env_cpu(env
);
1851 bool el1
= arm_current_el(env
) == 1;
1852 uint64_t hcr_el2
= el1
? arm_hcr_el2_eff(env
) : 0;
1855 if (hcr_el2
& HCR_IMO
) {
1856 if (cs
->interrupt_request
& CPU_INTERRUPT_VIRQ
) {
1860 if (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) {
1865 if (hcr_el2
& HCR_FMO
) {
1866 if (cs
->interrupt_request
& CPU_INTERRUPT_VFIQ
) {
1870 if (cs
->interrupt_request
& CPU_INTERRUPT_FIQ
) {
1875 if (hcr_el2
& HCR_AMO
) {
1876 if (cs
->interrupt_request
& CPU_INTERRUPT_VSERR
) {
1884 static CPAccessResult
access_aa64_tid1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1887 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID1
)) {
1888 return CP_ACCESS_TRAP_EL2
;
1891 return CP_ACCESS_OK
;
1894 static CPAccessResult
access_aa32_tid1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1897 if (arm_feature(env
, ARM_FEATURE_V8
)) {
1898 return access_aa64_tid1(env
, ri
, isread
);
1901 return CP_ACCESS_OK
;
1904 static const ARMCPRegInfo v7_cp_reginfo
[] = {
1905 /* the old v6 WFI, UNPREDICTABLE in v7 but we choose to NOP */
1906 { .name
= "NOP", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
1907 .access
= PL1_W
, .type
= ARM_CP_NOP
},
1908 /* Performance monitors are implementation defined in v7,
1909 * but with an ARM recommended set of registers, which we
1912 * Performance registers fall into three categories:
1913 * (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR)
1914 * (b) RO in PL0 (ie UNDEF on write), RW in PL1 (PMUSERENR)
1915 * (c) UNDEF in PL0 if PMUSERENR.EN==0, otherwise accessible (all others)
1916 * For the cases controlled by PMUSERENR we must set .access to PL0_RW
1917 * or PL0_RO as appropriate and then check PMUSERENR in the helper fn.
1919 { .name
= "PMCNTENSET", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 1,
1920 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
,
1921 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
1922 .writefn
= pmcntenset_write
,
1923 .accessfn
= pmreg_access
,
1924 .raw_writefn
= raw_write
},
1925 { .name
= "PMCNTENSET_EL0", .state
= ARM_CP_STATE_AA64
,
1926 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 1,
1927 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1928 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
), .resetvalue
= 0,
1929 .writefn
= pmcntenset_write
, .raw_writefn
= raw_write
},
1930 { .name
= "PMCNTENCLR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 2,
1932 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
1933 .accessfn
= pmreg_access
,
1934 .writefn
= pmcntenclr_write
,
1935 .type
= ARM_CP_ALIAS
},
1936 { .name
= "PMCNTENCLR_EL0", .state
= ARM_CP_STATE_AA64
,
1937 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 2,
1938 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1939 .type
= ARM_CP_ALIAS
,
1940 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
),
1941 .writefn
= pmcntenclr_write
},
1942 { .name
= "PMOVSR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 3,
1943 .access
= PL0_RW
, .type
= ARM_CP_IO
,
1944 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmovsr
),
1945 .accessfn
= pmreg_access
,
1946 .writefn
= pmovsr_write
,
1947 .raw_writefn
= raw_write
},
1948 { .name
= "PMOVSCLR_EL0", .state
= ARM_CP_STATE_AA64
,
1949 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 3,
1950 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1951 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
1952 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
1953 .writefn
= pmovsr_write
,
1954 .raw_writefn
= raw_write
},
1955 { .name
= "PMSWINC", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 4,
1956 .access
= PL0_W
, .accessfn
= pmreg_access_swinc
,
1957 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
1958 .writefn
= pmswinc_write
},
1959 { .name
= "PMSWINC_EL0", .state
= ARM_CP_STATE_AA64
,
1960 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 4,
1961 .access
= PL0_W
, .accessfn
= pmreg_access_swinc
,
1962 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
1963 .writefn
= pmswinc_write
},
1964 { .name
= "PMSELR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 5,
1965 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
,
1966 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmselr
),
1967 .accessfn
= pmreg_access_selr
, .writefn
= pmselr_write
,
1968 .raw_writefn
= raw_write
},
1969 { .name
= "PMSELR_EL0", .state
= ARM_CP_STATE_AA64
,
1970 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 5,
1971 .access
= PL0_RW
, .accessfn
= pmreg_access_selr
,
1972 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmselr
),
1973 .writefn
= pmselr_write
, .raw_writefn
= raw_write
, },
1974 { .name
= "PMCCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 0,
1975 .access
= PL0_RW
, .resetvalue
= 0, .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
1976 .readfn
= pmccntr_read
, .writefn
= pmccntr_write32
,
1977 .accessfn
= pmreg_access_ccntr
},
1978 { .name
= "PMCCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
1979 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 0,
1980 .access
= PL0_RW
, .accessfn
= pmreg_access_ccntr
,
1982 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ccnt
),
1983 .readfn
= pmccntr_read
, .writefn
= pmccntr_write
,
1984 .raw_readfn
= raw_read
, .raw_writefn
= raw_write
, },
1985 { .name
= "PMCCFILTR", .cp
= 15, .opc1
= 0, .crn
= 14, .crm
= 15, .opc2
= 7,
1986 .writefn
= pmccfiltr_write_a32
, .readfn
= pmccfiltr_read_a32
,
1987 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1988 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
1990 { .name
= "PMCCFILTR_EL0", .state
= ARM_CP_STATE_AA64
,
1991 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 15, .opc2
= 7,
1992 .writefn
= pmccfiltr_write
, .raw_writefn
= raw_write
,
1993 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1995 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmccfiltr_el0
),
1997 { .name
= "PMXEVTYPER", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 1,
1998 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
1999 .accessfn
= pmreg_access
,
2000 .writefn
= pmxevtyper_write
, .readfn
= pmxevtyper_read
},
2001 { .name
= "PMXEVTYPER_EL0", .state
= ARM_CP_STATE_AA64
,
2002 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 1,
2003 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2004 .accessfn
= pmreg_access
,
2005 .writefn
= pmxevtyper_write
, .readfn
= pmxevtyper_read
},
2006 { .name
= "PMXEVCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 2,
2007 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2008 .accessfn
= pmreg_access_xevcntr
,
2009 .writefn
= pmxevcntr_write
, .readfn
= pmxevcntr_read
},
2010 { .name
= "PMXEVCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
2011 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 2,
2012 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2013 .accessfn
= pmreg_access_xevcntr
,
2014 .writefn
= pmxevcntr_write
, .readfn
= pmxevcntr_read
},
2015 { .name
= "PMUSERENR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 0,
2016 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
,
2017 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmuserenr
),
2019 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
2020 { .name
= "PMUSERENR_EL0", .state
= ARM_CP_STATE_AA64
,
2021 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 0,
2022 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
, .type
= ARM_CP_ALIAS
,
2023 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmuserenr
),
2025 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
2026 { .name
= "PMINTENSET", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 1,
2027 .access
= PL1_RW
, .accessfn
= access_tpm
,
2028 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2029 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pminten
),
2031 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
},
2032 { .name
= "PMINTENSET_EL1", .state
= ARM_CP_STATE_AA64
,
2033 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 1,
2034 .access
= PL1_RW
, .accessfn
= access_tpm
,
2036 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2037 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
,
2038 .resetvalue
= 0x0 },
2039 { .name
= "PMINTENCLR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 2,
2040 .access
= PL1_RW
, .accessfn
= access_tpm
,
2041 .type
= ARM_CP_ALIAS
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2042 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2043 .writefn
= pmintenclr_write
, },
2044 { .name
= "PMINTENCLR_EL1", .state
= ARM_CP_STATE_AA64
,
2045 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 2,
2046 .access
= PL1_RW
, .accessfn
= access_tpm
,
2047 .type
= ARM_CP_ALIAS
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2048 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2049 .writefn
= pmintenclr_write
},
2050 { .name
= "CCSIDR", .state
= ARM_CP_STATE_BOTH
,
2051 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 0,
2053 .accessfn
= access_aa64_tid2
,
2054 .readfn
= ccsidr_read
, .type
= ARM_CP_NO_RAW
},
2055 { .name
= "CSSELR", .state
= ARM_CP_STATE_BOTH
,
2056 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 2, .opc2
= 0,
2058 .accessfn
= access_aa64_tid2
,
2059 .writefn
= csselr_write
, .resetvalue
= 0,
2060 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.csselr_s
),
2061 offsetof(CPUARMState
, cp15
.csselr_ns
) } },
2062 /* Auxiliary ID register: this actually has an IMPDEF value but for now
2063 * just RAZ for all cores:
2065 { .name
= "AIDR", .state
= ARM_CP_STATE_BOTH
,
2066 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 7,
2067 .access
= PL1_R
, .type
= ARM_CP_CONST
,
2068 .accessfn
= access_aa64_tid1
,
2070 /* Auxiliary fault status registers: these also are IMPDEF, and we
2071 * choose to RAZ/WI for all cores.
2073 { .name
= "AFSR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2074 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 0,
2075 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2076 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
2077 { .name
= "AFSR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2078 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 1,
2079 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2080 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
2081 /* MAIR can just read-as-written because we don't implement caches
2082 * and so don't need to care about memory attributes.
2084 { .name
= "MAIR_EL1", .state
= ARM_CP_STATE_AA64
,
2085 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
2086 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2087 .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[1]),
2089 { .name
= "MAIR_EL3", .state
= ARM_CP_STATE_AA64
,
2090 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 2, .opc2
= 0,
2091 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[3]),
2093 /* For non-long-descriptor page tables these are PRRR and NMRR;
2094 * regardless they still act as reads-as-written for QEMU.
2096 /* MAIR0/1 are defined separately from their 64-bit counterpart which
2097 * allows them to assign the correct fieldoffset based on the endianness
2098 * handled in the field definitions.
2100 { .name
= "MAIR0", .state
= ARM_CP_STATE_AA32
,
2101 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
2102 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2103 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair0_s
),
2104 offsetof(CPUARMState
, cp15
.mair0_ns
) },
2105 .resetfn
= arm_cp_reset_ignore
},
2106 { .name
= "MAIR1", .state
= ARM_CP_STATE_AA32
,
2107 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 1,
2108 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2109 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair1_s
),
2110 offsetof(CPUARMState
, cp15
.mair1_ns
) },
2111 .resetfn
= arm_cp_reset_ignore
},
2112 { .name
= "ISR_EL1", .state
= ARM_CP_STATE_BOTH
,
2113 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 1, .opc2
= 0,
2114 .type
= ARM_CP_NO_RAW
, .access
= PL1_R
, .readfn
= isr_read
},
2115 /* 32 bit ITLB invalidates */
2116 { .name
= "ITLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 0,
2117 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2118 .writefn
= tlbiall_write
},
2119 { .name
= "ITLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
2120 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2121 .writefn
= tlbimva_write
},
2122 { .name
= "ITLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 2,
2123 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2124 .writefn
= tlbiasid_write
},
2125 /* 32 bit DTLB invalidates */
2126 { .name
= "DTLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 0,
2127 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2128 .writefn
= tlbiall_write
},
2129 { .name
= "DTLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
2130 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2131 .writefn
= tlbimva_write
},
2132 { .name
= "DTLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 2,
2133 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2134 .writefn
= tlbiasid_write
},
2135 /* 32 bit TLB invalidates */
2136 { .name
= "TLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
2137 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2138 .writefn
= tlbiall_write
},
2139 { .name
= "TLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
2140 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2141 .writefn
= tlbimva_write
},
2142 { .name
= "TLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
2143 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2144 .writefn
= tlbiasid_write
},
2145 { .name
= "TLBIMVAA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
2146 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2147 .writefn
= tlbimvaa_write
},
2150 static const ARMCPRegInfo v7mp_cp_reginfo
[] = {
2151 /* 32 bit TLB invalidates, Inner Shareable */
2152 { .name
= "TLBIALLIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
2153 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2154 .writefn
= tlbiall_is_write
},
2155 { .name
= "TLBIMVAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
2156 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2157 .writefn
= tlbimva_is_write
},
2158 { .name
= "TLBIASIDIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
2159 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2160 .writefn
= tlbiasid_is_write
},
2161 { .name
= "TLBIMVAAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
2162 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2163 .writefn
= tlbimvaa_is_write
},
2166 static const ARMCPRegInfo pmovsset_cp_reginfo
[] = {
2167 /* PMOVSSET is not implemented in v7 before v7ve */
2168 { .name
= "PMOVSSET", .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 3,
2169 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2170 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2171 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmovsr
),
2172 .writefn
= pmovsset_write
,
2173 .raw_writefn
= raw_write
},
2174 { .name
= "PMOVSSET_EL0", .state
= ARM_CP_STATE_AA64
,
2175 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 3,
2176 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2177 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2178 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
2179 .writefn
= pmovsset_write
,
2180 .raw_writefn
= raw_write
},
2183 static void teecr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2190 static CPAccessResult
teecr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2194 * HSTR.TTEE only exists in v7A, not v8A, but v8A doesn't have T2EE
2195 * at all, so we don't need to check whether we're v8A.
2197 if (arm_current_el(env
) < 2 && !arm_is_secure_below_el3(env
) &&
2198 (env
->cp15
.hstr_el2
& HSTR_TTEE
)) {
2199 return CP_ACCESS_TRAP_EL2
;
2201 return CP_ACCESS_OK
;
2204 static CPAccessResult
teehbr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2207 if (arm_current_el(env
) == 0 && (env
->teecr
& 1)) {
2208 return CP_ACCESS_TRAP
;
2210 return teecr_access(env
, ri
, isread
);
2213 static const ARMCPRegInfo t2ee_cp_reginfo
[] = {
2214 { .name
= "TEECR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 6, .opc2
= 0,
2215 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, teecr
),
2217 .writefn
= teecr_write
, .accessfn
= teecr_access
},
2218 { .name
= "TEEHBR", .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 6, .opc2
= 0,
2219 .access
= PL0_RW
, .fieldoffset
= offsetof(CPUARMState
, teehbr
),
2220 .accessfn
= teehbr_access
, .resetvalue
= 0 },
2223 static const ARMCPRegInfo v6k_cp_reginfo
[] = {
2224 { .name
= "TPIDR_EL0", .state
= ARM_CP_STATE_AA64
,
2225 .opc0
= 3, .opc1
= 3, .opc2
= 2, .crn
= 13, .crm
= 0,
2227 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[0]), .resetvalue
= 0 },
2228 { .name
= "TPIDRURW", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 2,
2230 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrurw_s
),
2231 offsetoflow32(CPUARMState
, cp15
.tpidrurw_ns
) },
2232 .resetfn
= arm_cp_reset_ignore
},
2233 { .name
= "TPIDRRO_EL0", .state
= ARM_CP_STATE_AA64
,
2234 .opc0
= 3, .opc1
= 3, .opc2
= 3, .crn
= 13, .crm
= 0,
2235 .access
= PL0_R
|PL1_W
,
2236 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidrro_el
[0]),
2238 { .name
= "TPIDRURO", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 3,
2239 .access
= PL0_R
|PL1_W
,
2240 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidruro_s
),
2241 offsetoflow32(CPUARMState
, cp15
.tpidruro_ns
) },
2242 .resetfn
= arm_cp_reset_ignore
},
2243 { .name
= "TPIDR_EL1", .state
= ARM_CP_STATE_AA64
,
2244 .opc0
= 3, .opc1
= 0, .opc2
= 4, .crn
= 13, .crm
= 0,
2246 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[1]), .resetvalue
= 0 },
2247 { .name
= "TPIDRPRW", .opc1
= 0, .cp
= 15, .crn
= 13, .crm
= 0, .opc2
= 4,
2249 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrprw_s
),
2250 offsetoflow32(CPUARMState
, cp15
.tpidrprw_ns
) },
2254 #ifndef CONFIG_USER_ONLY
2256 static CPAccessResult
gt_cntfrq_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2259 /* CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero.
2260 * Writable only at the highest implemented exception level.
2262 int el
= arm_current_el(env
);
2268 hcr
= arm_hcr_el2_eff(env
);
2269 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2270 cntkctl
= env
->cp15
.cnthctl_el2
;
2272 cntkctl
= env
->cp15
.c14_cntkctl
;
2274 if (!extract32(cntkctl
, 0, 2)) {
2275 return CP_ACCESS_TRAP
;
2279 if (!isread
&& ri
->state
== ARM_CP_STATE_AA32
&&
2280 arm_is_secure_below_el3(env
)) {
2281 /* Accesses from 32-bit Secure EL1 UNDEF (*not* trap to EL3!) */
2282 return CP_ACCESS_TRAP_UNCATEGORIZED
;
2290 if (!isread
&& el
< arm_highest_el(env
)) {
2291 return CP_ACCESS_TRAP_UNCATEGORIZED
;
2294 return CP_ACCESS_OK
;
2297 static CPAccessResult
gt_counter_access(CPUARMState
*env
, int timeridx
,
2300 unsigned int cur_el
= arm_current_el(env
);
2301 bool has_el2
= arm_is_el2_enabled(env
);
2302 uint64_t hcr
= arm_hcr_el2_eff(env
);
2306 /* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]CTEN. */
2307 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2308 return (extract32(env
->cp15
.cnthctl_el2
, timeridx
, 1)
2309 ? CP_ACCESS_OK
: CP_ACCESS_TRAP_EL2
);
2312 /* CNT[PV]CT: not visible from PL0 if EL0[PV]CTEN is zero */
2313 if (!extract32(env
->cp15
.c14_cntkctl
, timeridx
, 1)) {
2314 return CP_ACCESS_TRAP
;
2317 /* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PCTEN. */
2318 if (hcr
& HCR_E2H
) {
2319 if (timeridx
== GTIMER_PHYS
&&
2320 !extract32(env
->cp15
.cnthctl_el2
, 10, 1)) {
2321 return CP_ACCESS_TRAP_EL2
;
2324 /* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */
2325 if (has_el2
&& timeridx
== GTIMER_PHYS
&&
2326 !extract32(env
->cp15
.cnthctl_el2
, 1, 1)) {
2327 return CP_ACCESS_TRAP_EL2
;
2333 /* Check CNTHCTL_EL2.EL1PCTEN, which changes location based on E2H. */
2334 if (has_el2
&& timeridx
== GTIMER_PHYS
&&
2336 ? !extract32(env
->cp15
.cnthctl_el2
, 10, 1)
2337 : !extract32(env
->cp15
.cnthctl_el2
, 0, 1))) {
2338 return CP_ACCESS_TRAP_EL2
;
2342 return CP_ACCESS_OK
;
2345 static CPAccessResult
gt_timer_access(CPUARMState
*env
, int timeridx
,
2348 unsigned int cur_el
= arm_current_el(env
);
2349 bool has_el2
= arm_is_el2_enabled(env
);
2350 uint64_t hcr
= arm_hcr_el2_eff(env
);
2354 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2355 /* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]TEN. */
2356 return (extract32(env
->cp15
.cnthctl_el2
, 9 - timeridx
, 1)
2357 ? CP_ACCESS_OK
: CP_ACCESS_TRAP_EL2
);
2361 * CNT[PV]_CVAL, CNT[PV]_CTL, CNT[PV]_TVAL: not visible from
2362 * EL0 if EL0[PV]TEN is zero.
2364 if (!extract32(env
->cp15
.c14_cntkctl
, 9 - timeridx
, 1)) {
2365 return CP_ACCESS_TRAP
;
2370 if (has_el2
&& timeridx
== GTIMER_PHYS
) {
2371 if (hcr
& HCR_E2H
) {
2372 /* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PTEN. */
2373 if (!extract32(env
->cp15
.cnthctl_el2
, 11, 1)) {
2374 return CP_ACCESS_TRAP_EL2
;
2377 /* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */
2378 if (!extract32(env
->cp15
.cnthctl_el2
, 1, 1)) {
2379 return CP_ACCESS_TRAP_EL2
;
2385 return CP_ACCESS_OK
;
2388 static CPAccessResult
gt_pct_access(CPUARMState
*env
,
2389 const ARMCPRegInfo
*ri
,
2392 return gt_counter_access(env
, GTIMER_PHYS
, isread
);
2395 static CPAccessResult
gt_vct_access(CPUARMState
*env
,
2396 const ARMCPRegInfo
*ri
,
2399 return gt_counter_access(env
, GTIMER_VIRT
, isread
);
2402 static CPAccessResult
gt_ptimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2405 return gt_timer_access(env
, GTIMER_PHYS
, isread
);
2408 static CPAccessResult
gt_vtimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2411 return gt_timer_access(env
, GTIMER_VIRT
, isread
);
2414 static CPAccessResult
gt_stimer_access(CPUARMState
*env
,
2415 const ARMCPRegInfo
*ri
,
2418 /* The AArch64 register view of the secure physical timer is
2419 * always accessible from EL3, and configurably accessible from
2422 switch (arm_current_el(env
)) {
2424 if (!arm_is_secure(env
)) {
2425 return CP_ACCESS_TRAP
;
2427 if (!(env
->cp15
.scr_el3
& SCR_ST
)) {
2428 return CP_ACCESS_TRAP_EL3
;
2430 return CP_ACCESS_OK
;
2433 return CP_ACCESS_TRAP
;
2435 return CP_ACCESS_OK
;
2437 g_assert_not_reached();
2441 static uint64_t gt_get_countervalue(CPUARMState
*env
)
2443 ARMCPU
*cpu
= env_archcpu(env
);
2445 return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) / gt_cntfrq_period_ns(cpu
);
2448 static void gt_recalc_timer(ARMCPU
*cpu
, int timeridx
)
2450 ARMGenericTimer
*gt
= &cpu
->env
.cp15
.c14_timer
[timeridx
];
2453 /* Timer enabled: calculate and set current ISTATUS, irq, and
2454 * reset timer to when ISTATUS next has to change
2456 uint64_t offset
= timeridx
== GTIMER_VIRT
?
2457 cpu
->env
.cp15
.cntvoff_el2
: 0;
2458 uint64_t count
= gt_get_countervalue(&cpu
->env
);
2459 /* Note that this must be unsigned 64 bit arithmetic: */
2460 int istatus
= count
- offset
>= gt
->cval
;
2464 gt
->ctl
= deposit32(gt
->ctl
, 2, 1, istatus
);
2466 irqstate
= (istatus
&& !(gt
->ctl
& 2));
2467 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], irqstate
);
2470 /* Next transition is when count rolls back over to zero */
2471 nexttick
= UINT64_MAX
;
2473 /* Next transition is when we hit cval */
2474 nexttick
= gt
->cval
+ offset
;
2476 /* Note that the desired next expiry time might be beyond the
2477 * signed-64-bit range of a QEMUTimer -- in this case we just
2478 * set the timer for as far in the future as possible. When the
2479 * timer expires we will reset the timer for any remaining period.
2481 if (nexttick
> INT64_MAX
/ gt_cntfrq_period_ns(cpu
)) {
2482 timer_mod_ns(cpu
->gt_timer
[timeridx
], INT64_MAX
);
2484 timer_mod(cpu
->gt_timer
[timeridx
], nexttick
);
2486 trace_arm_gt_recalc(timeridx
, irqstate
, nexttick
);
2488 /* Timer disabled: ISTATUS and timer output always clear */
2490 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], 0);
2491 timer_del(cpu
->gt_timer
[timeridx
]);
2492 trace_arm_gt_recalc_disabled(timeridx
);
2496 static void gt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2499 ARMCPU
*cpu
= env_archcpu(env
);
2501 timer_del(cpu
->gt_timer
[timeridx
]);
2504 static uint64_t gt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2506 return gt_get_countervalue(env
);
2509 static uint64_t gt_virt_cnt_offset(CPUARMState
*env
)
2513 switch (arm_current_el(env
)) {
2515 hcr
= arm_hcr_el2_eff(env
);
2516 if (hcr
& HCR_E2H
) {
2521 hcr
= arm_hcr_el2_eff(env
);
2522 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2528 return env
->cp15
.cntvoff_el2
;
2531 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2533 return gt_get_countervalue(env
) - gt_virt_cnt_offset(env
);
2536 static void gt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2540 trace_arm_gt_cval_write(timeridx
, value
);
2541 env
->cp15
.c14_timer
[timeridx
].cval
= value
;
2542 gt_recalc_timer(env_archcpu(env
), timeridx
);
2545 static uint64_t gt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2548 uint64_t offset
= 0;
2552 case GTIMER_HYPVIRT
:
2553 offset
= gt_virt_cnt_offset(env
);
2557 return (uint32_t)(env
->cp15
.c14_timer
[timeridx
].cval
-
2558 (gt_get_countervalue(env
) - offset
));
2561 static void gt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2565 uint64_t offset
= 0;
2569 case GTIMER_HYPVIRT
:
2570 offset
= gt_virt_cnt_offset(env
);
2574 trace_arm_gt_tval_write(timeridx
, value
);
2575 env
->cp15
.c14_timer
[timeridx
].cval
= gt_get_countervalue(env
) - offset
+
2576 sextract64(value
, 0, 32);
2577 gt_recalc_timer(env_archcpu(env
), timeridx
);
2580 static void gt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2584 ARMCPU
*cpu
= env_archcpu(env
);
2585 uint32_t oldval
= env
->cp15
.c14_timer
[timeridx
].ctl
;
2587 trace_arm_gt_ctl_write(timeridx
, value
);
2588 env
->cp15
.c14_timer
[timeridx
].ctl
= deposit64(oldval
, 0, 2, value
);
2589 if ((oldval
^ value
) & 1) {
2590 /* Enable toggled */
2591 gt_recalc_timer(cpu
, timeridx
);
2592 } else if ((oldval
^ value
) & 2) {
2593 /* IMASK toggled: don't need to recalculate,
2594 * just set the interrupt line based on ISTATUS
2596 int irqstate
= (oldval
& 4) && !(value
& 2);
2598 trace_arm_gt_imask_toggle(timeridx
, irqstate
);
2599 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], irqstate
);
2603 static void gt_phys_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2605 gt_timer_reset(env
, ri
, GTIMER_PHYS
);
2608 static void gt_phys_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2611 gt_cval_write(env
, ri
, GTIMER_PHYS
, value
);
2614 static uint64_t gt_phys_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2616 return gt_tval_read(env
, ri
, GTIMER_PHYS
);
2619 static void gt_phys_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2622 gt_tval_write(env
, ri
, GTIMER_PHYS
, value
);
2625 static void gt_phys_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2628 gt_ctl_write(env
, ri
, GTIMER_PHYS
, value
);
2631 static int gt_phys_redir_timeridx(CPUARMState
*env
)
2633 switch (arm_mmu_idx(env
)) {
2634 case ARMMMUIdx_E20_0
:
2635 case ARMMMUIdx_E20_2
:
2636 case ARMMMUIdx_E20_2_PAN
:
2637 case ARMMMUIdx_SE20_0
:
2638 case ARMMMUIdx_SE20_2
:
2639 case ARMMMUIdx_SE20_2_PAN
:
2646 static int gt_virt_redir_timeridx(CPUARMState
*env
)
2648 switch (arm_mmu_idx(env
)) {
2649 case ARMMMUIdx_E20_0
:
2650 case ARMMMUIdx_E20_2
:
2651 case ARMMMUIdx_E20_2_PAN
:
2652 case ARMMMUIdx_SE20_0
:
2653 case ARMMMUIdx_SE20_2
:
2654 case ARMMMUIdx_SE20_2_PAN
:
2655 return GTIMER_HYPVIRT
;
2661 static uint64_t gt_phys_redir_cval_read(CPUARMState
*env
,
2662 const ARMCPRegInfo
*ri
)
2664 int timeridx
= gt_phys_redir_timeridx(env
);
2665 return env
->cp15
.c14_timer
[timeridx
].cval
;
2668 static void gt_phys_redir_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2671 int timeridx
= gt_phys_redir_timeridx(env
);
2672 gt_cval_write(env
, ri
, timeridx
, value
);
2675 static uint64_t gt_phys_redir_tval_read(CPUARMState
*env
,
2676 const ARMCPRegInfo
*ri
)
2678 int timeridx
= gt_phys_redir_timeridx(env
);
2679 return gt_tval_read(env
, ri
, timeridx
);
2682 static void gt_phys_redir_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2685 int timeridx
= gt_phys_redir_timeridx(env
);
2686 gt_tval_write(env
, ri
, timeridx
, value
);
2689 static uint64_t gt_phys_redir_ctl_read(CPUARMState
*env
,
2690 const ARMCPRegInfo
*ri
)
2692 int timeridx
= gt_phys_redir_timeridx(env
);
2693 return env
->cp15
.c14_timer
[timeridx
].ctl
;
2696 static void gt_phys_redir_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2699 int timeridx
= gt_phys_redir_timeridx(env
);
2700 gt_ctl_write(env
, ri
, timeridx
, value
);
2703 static void gt_virt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2705 gt_timer_reset(env
, ri
, GTIMER_VIRT
);
2708 static void gt_virt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2711 gt_cval_write(env
, ri
, GTIMER_VIRT
, value
);
2714 static uint64_t gt_virt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2716 return gt_tval_read(env
, ri
, GTIMER_VIRT
);
2719 static void gt_virt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2722 gt_tval_write(env
, ri
, GTIMER_VIRT
, value
);
2725 static void gt_virt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2728 gt_ctl_write(env
, ri
, GTIMER_VIRT
, value
);
2731 static void gt_cntvoff_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2734 ARMCPU
*cpu
= env_archcpu(env
);
2736 trace_arm_gt_cntvoff_write(value
);
2737 raw_write(env
, ri
, value
);
2738 gt_recalc_timer(cpu
, GTIMER_VIRT
);
2741 static uint64_t gt_virt_redir_cval_read(CPUARMState
*env
,
2742 const ARMCPRegInfo
*ri
)
2744 int timeridx
= gt_virt_redir_timeridx(env
);
2745 return env
->cp15
.c14_timer
[timeridx
].cval
;
2748 static void gt_virt_redir_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2751 int timeridx
= gt_virt_redir_timeridx(env
);
2752 gt_cval_write(env
, ri
, timeridx
, value
);
2755 static uint64_t gt_virt_redir_tval_read(CPUARMState
*env
,
2756 const ARMCPRegInfo
*ri
)
2758 int timeridx
= gt_virt_redir_timeridx(env
);
2759 return gt_tval_read(env
, ri
, timeridx
);
2762 static void gt_virt_redir_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2765 int timeridx
= gt_virt_redir_timeridx(env
);
2766 gt_tval_write(env
, ri
, timeridx
, value
);
2769 static uint64_t gt_virt_redir_ctl_read(CPUARMState
*env
,
2770 const ARMCPRegInfo
*ri
)
2772 int timeridx
= gt_virt_redir_timeridx(env
);
2773 return env
->cp15
.c14_timer
[timeridx
].ctl
;
2776 static void gt_virt_redir_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2779 int timeridx
= gt_virt_redir_timeridx(env
);
2780 gt_ctl_write(env
, ri
, timeridx
, value
);
2783 static void gt_hyp_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2785 gt_timer_reset(env
, ri
, GTIMER_HYP
);
2788 static void gt_hyp_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2791 gt_cval_write(env
, ri
, GTIMER_HYP
, value
);
2794 static uint64_t gt_hyp_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2796 return gt_tval_read(env
, ri
, GTIMER_HYP
);
2799 static void gt_hyp_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2802 gt_tval_write(env
, ri
, GTIMER_HYP
, value
);
2805 static void gt_hyp_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2808 gt_ctl_write(env
, ri
, GTIMER_HYP
, value
);
2811 static void gt_sec_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2813 gt_timer_reset(env
, ri
, GTIMER_SEC
);
2816 static void gt_sec_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2819 gt_cval_write(env
, ri
, GTIMER_SEC
, value
);
2822 static uint64_t gt_sec_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2824 return gt_tval_read(env
, ri
, GTIMER_SEC
);
2827 static void gt_sec_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2830 gt_tval_write(env
, ri
, GTIMER_SEC
, value
);
2833 static void gt_sec_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2836 gt_ctl_write(env
, ri
, GTIMER_SEC
, value
);
2839 static void gt_hv_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2841 gt_timer_reset(env
, ri
, GTIMER_HYPVIRT
);
2844 static void gt_hv_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2847 gt_cval_write(env
, ri
, GTIMER_HYPVIRT
, value
);
2850 static uint64_t gt_hv_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2852 return gt_tval_read(env
, ri
, GTIMER_HYPVIRT
);
2855 static void gt_hv_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2858 gt_tval_write(env
, ri
, GTIMER_HYPVIRT
, value
);
2861 static void gt_hv_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2864 gt_ctl_write(env
, ri
, GTIMER_HYPVIRT
, value
);
2867 void arm_gt_ptimer_cb(void *opaque
)
2869 ARMCPU
*cpu
= opaque
;
2871 gt_recalc_timer(cpu
, GTIMER_PHYS
);
2874 void arm_gt_vtimer_cb(void *opaque
)
2876 ARMCPU
*cpu
= opaque
;
2878 gt_recalc_timer(cpu
, GTIMER_VIRT
);
2881 void arm_gt_htimer_cb(void *opaque
)
2883 ARMCPU
*cpu
= opaque
;
2885 gt_recalc_timer(cpu
, GTIMER_HYP
);
2888 void arm_gt_stimer_cb(void *opaque
)
2890 ARMCPU
*cpu
= opaque
;
2892 gt_recalc_timer(cpu
, GTIMER_SEC
);
2895 void arm_gt_hvtimer_cb(void *opaque
)
2897 ARMCPU
*cpu
= opaque
;
2899 gt_recalc_timer(cpu
, GTIMER_HYPVIRT
);
2902 static void arm_gt_cntfrq_reset(CPUARMState
*env
, const ARMCPRegInfo
*opaque
)
2904 ARMCPU
*cpu
= env_archcpu(env
);
2906 cpu
->env
.cp15
.c14_cntfrq
= cpu
->gt_cntfrq_hz
;
2909 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
2910 /* Note that CNTFRQ is purely reads-as-written for the benefit
2911 * of software; writing it doesn't actually change the timer frequency.
2912 * Our reset value matches the fixed frequency we implement the timer at.
2914 { .name
= "CNTFRQ", .cp
= 15, .crn
= 14, .crm
= 0, .opc1
= 0, .opc2
= 0,
2915 .type
= ARM_CP_ALIAS
,
2916 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
2917 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c14_cntfrq
),
2919 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
2920 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
2921 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
2922 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
2923 .resetfn
= arm_gt_cntfrq_reset
,
2925 /* overall control: mostly access permissions */
2926 { .name
= "CNTKCTL", .state
= ARM_CP_STATE_BOTH
,
2927 .opc0
= 3, .opc1
= 0, .crn
= 14, .crm
= 1, .opc2
= 0,
2929 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntkctl
),
2932 /* per-timer control */
2933 { .name
= "CNTP_CTL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
2934 .secure
= ARM_CP_SECSTATE_NS
,
2935 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
2936 .accessfn
= gt_ptimer_access
,
2937 .fieldoffset
= offsetoflow32(CPUARMState
,
2938 cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
2939 .readfn
= gt_phys_redir_ctl_read
, .raw_readfn
= raw_read
,
2940 .writefn
= gt_phys_redir_ctl_write
, .raw_writefn
= raw_write
,
2942 { .name
= "CNTP_CTL_S",
2943 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
2944 .secure
= ARM_CP_SECSTATE_S
,
2945 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
2946 .accessfn
= gt_ptimer_access
,
2947 .fieldoffset
= offsetoflow32(CPUARMState
,
2948 cp15
.c14_timer
[GTIMER_SEC
].ctl
),
2949 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
2951 { .name
= "CNTP_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
2952 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 1,
2953 .type
= ARM_CP_IO
, .access
= PL0_RW
,
2954 .accessfn
= gt_ptimer_access
,
2955 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
2957 .readfn
= gt_phys_redir_ctl_read
, .raw_readfn
= raw_read
,
2958 .writefn
= gt_phys_redir_ctl_write
, .raw_writefn
= raw_write
,
2960 { .name
= "CNTV_CTL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 1,
2961 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
2962 .accessfn
= gt_vtimer_access
,
2963 .fieldoffset
= offsetoflow32(CPUARMState
,
2964 cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
2965 .readfn
= gt_virt_redir_ctl_read
, .raw_readfn
= raw_read
,
2966 .writefn
= gt_virt_redir_ctl_write
, .raw_writefn
= raw_write
,
2968 { .name
= "CNTV_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
2969 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 1,
2970 .type
= ARM_CP_IO
, .access
= PL0_RW
,
2971 .accessfn
= gt_vtimer_access
,
2972 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
2974 .readfn
= gt_virt_redir_ctl_read
, .raw_readfn
= raw_read
,
2975 .writefn
= gt_virt_redir_ctl_write
, .raw_writefn
= raw_write
,
2977 /* TimerValue views: a 32 bit downcounting view of the underlying state */
2978 { .name
= "CNTP_TVAL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
2979 .secure
= ARM_CP_SECSTATE_NS
,
2980 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
2981 .accessfn
= gt_ptimer_access
,
2982 .readfn
= gt_phys_redir_tval_read
, .writefn
= gt_phys_redir_tval_write
,
2984 { .name
= "CNTP_TVAL_S",
2985 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
2986 .secure
= ARM_CP_SECSTATE_S
,
2987 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
2988 .accessfn
= gt_ptimer_access
,
2989 .readfn
= gt_sec_tval_read
, .writefn
= gt_sec_tval_write
,
2991 { .name
= "CNTP_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
2992 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 0,
2993 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
2994 .accessfn
= gt_ptimer_access
, .resetfn
= gt_phys_timer_reset
,
2995 .readfn
= gt_phys_redir_tval_read
, .writefn
= gt_phys_redir_tval_write
,
2997 { .name
= "CNTV_TVAL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 0,
2998 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
2999 .accessfn
= gt_vtimer_access
,
3000 .readfn
= gt_virt_redir_tval_read
, .writefn
= gt_virt_redir_tval_write
,
3002 { .name
= "CNTV_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3003 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 0,
3004 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3005 .accessfn
= gt_vtimer_access
, .resetfn
= gt_virt_timer_reset
,
3006 .readfn
= gt_virt_redir_tval_read
, .writefn
= gt_virt_redir_tval_write
,
3008 /* The counter itself */
3009 { .name
= "CNTPCT", .cp
= 15, .crm
= 14, .opc1
= 0,
3010 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3011 .accessfn
= gt_pct_access
,
3012 .readfn
= gt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3014 { .name
= "CNTPCT_EL0", .state
= ARM_CP_STATE_AA64
,
3015 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 1,
3016 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3017 .accessfn
= gt_pct_access
, .readfn
= gt_cnt_read
,
3019 { .name
= "CNTVCT", .cp
= 15, .crm
= 14, .opc1
= 1,
3020 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3021 .accessfn
= gt_vct_access
,
3022 .readfn
= gt_virt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3024 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
3025 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
3026 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3027 .accessfn
= gt_vct_access
, .readfn
= gt_virt_cnt_read
,
3029 /* Comparison value, indicating when the timer goes off */
3030 { .name
= "CNTP_CVAL", .cp
= 15, .crm
= 14, .opc1
= 2,
3031 .secure
= ARM_CP_SECSTATE_NS
,
3033 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3034 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
3035 .accessfn
= gt_ptimer_access
,
3036 .readfn
= gt_phys_redir_cval_read
, .raw_readfn
= raw_read
,
3037 .writefn
= gt_phys_redir_cval_write
, .raw_writefn
= raw_write
,
3039 { .name
= "CNTP_CVAL_S", .cp
= 15, .crm
= 14, .opc1
= 2,
3040 .secure
= ARM_CP_SECSTATE_S
,
3042 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3043 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
3044 .accessfn
= gt_ptimer_access
,
3045 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
3047 { .name
= "CNTP_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3048 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 2,
3051 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
3052 .resetvalue
= 0, .accessfn
= gt_ptimer_access
,
3053 .readfn
= gt_phys_redir_cval_read
, .raw_readfn
= raw_read
,
3054 .writefn
= gt_phys_redir_cval_write
, .raw_writefn
= raw_write
,
3056 { .name
= "CNTV_CVAL", .cp
= 15, .crm
= 14, .opc1
= 3,
3058 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3059 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
3060 .accessfn
= gt_vtimer_access
,
3061 .readfn
= gt_virt_redir_cval_read
, .raw_readfn
= raw_read
,
3062 .writefn
= gt_virt_redir_cval_write
, .raw_writefn
= raw_write
,
3064 { .name
= "CNTV_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3065 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 2,
3068 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
3069 .resetvalue
= 0, .accessfn
= gt_vtimer_access
,
3070 .readfn
= gt_virt_redir_cval_read
, .raw_readfn
= raw_read
,
3071 .writefn
= gt_virt_redir_cval_write
, .raw_writefn
= raw_write
,
3073 /* Secure timer -- this is actually restricted to only EL3
3074 * and configurably Secure-EL1 via the accessfn.
3076 { .name
= "CNTPS_TVAL_EL1", .state
= ARM_CP_STATE_AA64
,
3077 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 0,
3078 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
,
3079 .accessfn
= gt_stimer_access
,
3080 .readfn
= gt_sec_tval_read
,
3081 .writefn
= gt_sec_tval_write
,
3082 .resetfn
= gt_sec_timer_reset
,
3084 { .name
= "CNTPS_CTL_EL1", .state
= ARM_CP_STATE_AA64
,
3085 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 1,
3086 .type
= ARM_CP_IO
, .access
= PL1_RW
,
3087 .accessfn
= gt_stimer_access
,
3088 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].ctl
),
3090 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
3092 { .name
= "CNTPS_CVAL_EL1", .state
= ARM_CP_STATE_AA64
,
3093 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 2,
3094 .type
= ARM_CP_IO
, .access
= PL1_RW
,
3095 .accessfn
= gt_stimer_access
,
3096 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
3097 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
3101 static CPAccessResult
e2h_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3104 if (!(arm_hcr_el2_eff(env
) & HCR_E2H
)) {
3105 return CP_ACCESS_TRAP
;
3107 return CP_ACCESS_OK
;
3112 /* In user-mode most of the generic timer registers are inaccessible
3113 * however modern kernels (4.12+) allow access to cntvct_el0
3116 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3118 ARMCPU
*cpu
= env_archcpu(env
);
3120 /* Currently we have no support for QEMUTimer in linux-user so we
3121 * can't call gt_get_countervalue(env), instead we directly
3122 * call the lower level functions.
3124 return cpu_get_clock() / gt_cntfrq_period_ns(cpu
);
3127 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
3128 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
3129 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
3130 .type
= ARM_CP_CONST
, .access
= PL0_R
/* no PL1_RW in linux-user */,
3131 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
3132 .resetvalue
= NANOSECONDS_PER_SECOND
/ GTIMER_SCALE
,
3134 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
3135 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
3136 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3137 .readfn
= gt_virt_cnt_read
,
3143 static void par_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
3145 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3146 raw_write(env
, ri
, value
);
3147 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
3148 raw_write(env
, ri
, value
& 0xfffff6ff);
3150 raw_write(env
, ri
, value
& 0xfffff1ff);
3154 #ifndef CONFIG_USER_ONLY
3155 /* get_phys_addr() isn't present for user-mode-only targets */
3157 static CPAccessResult
ats_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3161 /* The ATS12NSO* operations must trap to EL3 or EL2 if executed in
3162 * Secure EL1 (which can only happen if EL3 is AArch64).
3163 * They are simply UNDEF if executed from NS EL1.
3164 * They function normally from EL2 or EL3.
3166 if (arm_current_el(env
) == 1) {
3167 if (arm_is_secure_below_el3(env
)) {
3168 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
3169 return CP_ACCESS_TRAP_UNCATEGORIZED_EL2
;
3171 return CP_ACCESS_TRAP_UNCATEGORIZED_EL3
;
3173 return CP_ACCESS_TRAP_UNCATEGORIZED
;
3176 return CP_ACCESS_OK
;
3180 static uint64_t do_ats_write(CPUARMState
*env
, uint64_t value
,
3181 MMUAccessType access_type
, ARMMMUIdx mmu_idx
)
3184 target_ulong page_size
;
3188 bool format64
= false;
3189 MemTxAttrs attrs
= {};
3190 ARMMMUFaultInfo fi
= {};
3191 ARMCacheAttrs cacheattrs
= {};
3193 ret
= get_phys_addr(env
, value
, access_type
, mmu_idx
, &phys_addr
, &attrs
,
3194 &prot
, &page_size
, &fi
, &cacheattrs
);
3197 * ATS operations only do S1 or S1+S2 translations, so we never
3198 * have to deal with the ARMCacheAttrs format for S2 only.
3200 assert(!cacheattrs
.is_s2_format
);
3204 * Some kinds of translation fault must cause exceptions rather
3205 * than being reported in the PAR.
3207 int current_el
= arm_current_el(env
);
3209 uint32_t syn
, fsr
, fsc
;
3210 bool take_exc
= false;
3212 if (fi
.s1ptw
&& current_el
== 1
3213 && arm_mmu_idx_is_stage1_of_2(mmu_idx
)) {
3215 * Synchronous stage 2 fault on an access made as part of the
3216 * translation table walk for AT S1E0* or AT S1E1* insn
3217 * executed from NS EL1. If this is a synchronous external abort
3218 * and SCR_EL3.EA == 1, then we take a synchronous external abort
3219 * to EL3. Otherwise the fault is taken as an exception to EL2,
3220 * and HPFAR_EL2 holds the faulting IPA.
3222 if (fi
.type
== ARMFault_SyncExternalOnWalk
&&
3223 (env
->cp15
.scr_el3
& SCR_EA
)) {
3226 env
->cp15
.hpfar_el2
= extract64(fi
.s2addr
, 12, 47) << 4;
3227 if (arm_is_secure_below_el3(env
) && fi
.s1ns
) {
3228 env
->cp15
.hpfar_el2
|= HPFAR_NS
;
3233 } else if (fi
.type
== ARMFault_SyncExternalOnWalk
) {
3235 * Synchronous external aborts during a translation table walk
3236 * are taken as Data Abort exceptions.
3239 if (current_el
== 3) {
3245 target_el
= exception_target_el(env
);
3251 /* Construct FSR and FSC using same logic as arm_deliver_fault() */
3252 if (target_el
== 2 || arm_el_is_aa64(env
, target_el
) ||
3253 arm_s1_regime_using_lpae_format(env
, mmu_idx
)) {
3254 fsr
= arm_fi_to_lfsc(&fi
);
3255 fsc
= extract32(fsr
, 0, 6);
3257 fsr
= arm_fi_to_sfsc(&fi
);
3261 * Report exception with ESR indicating a fault due to a
3262 * translation table walk for a cache maintenance instruction.
3264 syn
= syn_data_abort_no_iss(current_el
== target_el
, 0,
3265 fi
.ea
, 1, fi
.s1ptw
, 1, fsc
);
3266 env
->exception
.vaddress
= value
;
3267 env
->exception
.fsr
= fsr
;
3268 raise_exception(env
, EXCP_DATA_ABORT
, syn
, target_el
);
3274 } else if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3277 * * TTBCR.EAE determines whether the result is returned using the
3278 * 32-bit or the 64-bit PAR format
3279 * * Instructions executed in Hyp mode always use the 64bit format
3281 * ATS1S2NSOxx uses the 64bit format if any of the following is true:
3282 * * The Non-secure TTBCR.EAE bit is set to 1
3283 * * The implementation includes EL2, and the value of HCR.VM is 1
3285 * (Note that HCR.DC makes HCR.VM behave as if it is 1.)
3287 * ATS1Hx always uses the 64bit format.
3289 format64
= arm_s1_regime_using_lpae_format(env
, mmu_idx
);
3291 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
3292 if (mmu_idx
== ARMMMUIdx_E10_0
||
3293 mmu_idx
== ARMMMUIdx_E10_1
||
3294 mmu_idx
== ARMMMUIdx_E10_1_PAN
) {
3295 format64
|= env
->cp15
.hcr_el2
& (HCR_VM
| HCR_DC
);
3297 format64
|= arm_current_el(env
) == 2;
3303 /* Create a 64-bit PAR */
3304 par64
= (1 << 11); /* LPAE bit always set */
3306 par64
|= phys_addr
& ~0xfffULL
;
3307 if (!attrs
.secure
) {
3308 par64
|= (1 << 9); /* NS */
3310 par64
|= (uint64_t)cacheattrs
.attrs
<< 56; /* ATTR */
3311 par64
|= cacheattrs
.shareability
<< 7; /* SH */
3313 uint32_t fsr
= arm_fi_to_lfsc(&fi
);
3316 par64
|= (fsr
& 0x3f) << 1; /* FS */
3318 par64
|= (1 << 9); /* S */
3321 par64
|= (1 << 8); /* PTW */
3325 /* fsr is a DFSR/IFSR value for the short descriptor
3326 * translation table format (with WnR always clear).
3327 * Convert it to a 32-bit PAR.
3330 /* We do not set any attribute bits in the PAR */
3331 if (page_size
== (1 << 24)
3332 && arm_feature(env
, ARM_FEATURE_V7
)) {
3333 par64
= (phys_addr
& 0xff000000) | (1 << 1);
3335 par64
= phys_addr
& 0xfffff000;
3337 if (!attrs
.secure
) {
3338 par64
|= (1 << 9); /* NS */
3341 uint32_t fsr
= arm_fi_to_sfsc(&fi
);
3343 par64
= ((fsr
& (1 << 10)) >> 5) | ((fsr
& (1 << 12)) >> 6) |
3344 ((fsr
& 0xf) << 1) | 1;
3349 #endif /* CONFIG_TCG */
3351 static void ats_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
3354 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3357 int el
= arm_current_el(env
);
3358 bool secure
= arm_is_secure_below_el3(env
);
3360 switch (ri
->opc2
& 6) {
3362 /* stage 1 current state PL1: ATS1CPR, ATS1CPW, ATS1CPRP, ATS1CPWP */
3365 mmu_idx
= ARMMMUIdx_SE3
;
3368 g_assert(!secure
); /* ARMv8.4-SecEL2 is 64-bit only */
3371 if (ri
->crm
== 9 && (env
->uncached_cpsr
& CPSR_PAN
)) {
3372 mmu_idx
= (secure
? ARMMMUIdx_Stage1_SE1_PAN
3373 : ARMMMUIdx_Stage1_E1_PAN
);
3375 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE1
: ARMMMUIdx_Stage1_E1
;
3379 g_assert_not_reached();
3383 /* stage 1 current state PL0: ATS1CUR, ATS1CUW */
3386 mmu_idx
= ARMMMUIdx_SE10_0
;
3389 g_assert(!secure
); /* ARMv8.4-SecEL2 is 64-bit only */
3390 mmu_idx
= ARMMMUIdx_Stage1_E0
;
3393 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE0
: ARMMMUIdx_Stage1_E0
;
3396 g_assert_not_reached();
3400 /* stage 1+2 NonSecure PL1: ATS12NSOPR, ATS12NSOPW */
3401 mmu_idx
= ARMMMUIdx_E10_1
;
3404 /* stage 1+2 NonSecure PL0: ATS12NSOUR, ATS12NSOUW */
3405 mmu_idx
= ARMMMUIdx_E10_0
;
3408 g_assert_not_reached();
3411 par64
= do_ats_write(env
, value
, access_type
, mmu_idx
);
3413 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
3415 /* Handled by hardware accelerator. */
3416 g_assert_not_reached();
3417 #endif /* CONFIG_TCG */
3420 static void ats1h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3424 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3427 par64
= do_ats_write(env
, value
, access_type
, ARMMMUIdx_E2
);
3429 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
3431 /* Handled by hardware accelerator. */
3432 g_assert_not_reached();
3433 #endif /* CONFIG_TCG */
3436 static CPAccessResult
at_s1e2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3439 if (arm_current_el(env
) == 3 &&
3440 !(env
->cp15
.scr_el3
& (SCR_NS
| SCR_EEL2
))) {
3441 return CP_ACCESS_TRAP
;
3443 return CP_ACCESS_OK
;
3446 static void ats_write64(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3450 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3452 int secure
= arm_is_secure_below_el3(env
);
3454 switch (ri
->opc2
& 6) {
3457 case 0: /* AT S1E1R, AT S1E1W, AT S1E1RP, AT S1E1WP */
3458 if (ri
->crm
== 9 && (env
->pstate
& PSTATE_PAN
)) {
3459 mmu_idx
= (secure
? ARMMMUIdx_Stage1_SE1_PAN
3460 : ARMMMUIdx_Stage1_E1_PAN
);
3462 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE1
: ARMMMUIdx_Stage1_E1
;
3465 case 4: /* AT S1E2R, AT S1E2W */
3466 mmu_idx
= secure
? ARMMMUIdx_SE2
: ARMMMUIdx_E2
;
3468 case 6: /* AT S1E3R, AT S1E3W */
3469 mmu_idx
= ARMMMUIdx_SE3
;
3472 g_assert_not_reached();
3475 case 2: /* AT S1E0R, AT S1E0W */
3476 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE0
: ARMMMUIdx_Stage1_E0
;
3478 case 4: /* AT S12E1R, AT S12E1W */
3479 mmu_idx
= secure
? ARMMMUIdx_SE10_1
: ARMMMUIdx_E10_1
;
3481 case 6: /* AT S12E0R, AT S12E0W */
3482 mmu_idx
= secure
? ARMMMUIdx_SE10_0
: ARMMMUIdx_E10_0
;
3485 g_assert_not_reached();
3488 env
->cp15
.par_el
[1] = do_ats_write(env
, value
, access_type
, mmu_idx
);
3490 /* Handled by hardware accelerator. */
3491 g_assert_not_reached();
3492 #endif /* CONFIG_TCG */
3496 static const ARMCPRegInfo vapa_cp_reginfo
[] = {
3497 { .name
= "PAR", .cp
= 15, .crn
= 7, .crm
= 4, .opc1
= 0, .opc2
= 0,
3498 .access
= PL1_RW
, .resetvalue
= 0,
3499 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.par_s
),
3500 offsetoflow32(CPUARMState
, cp15
.par_ns
) },
3501 .writefn
= par_write
},
3502 #ifndef CONFIG_USER_ONLY
3503 /* This underdecoding is safe because the reginfo is NO_RAW. */
3504 { .name
= "ATS", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= CP_ANY
,
3505 .access
= PL1_W
, .accessfn
= ats_access
,
3506 .writefn
= ats_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
3510 /* Return basic MPU access permission bits. */
3511 static uint32_t simple_mpu_ap_bits(uint32_t val
)
3518 for (i
= 0; i
< 16; i
+= 2) {
3519 ret
|= (val
>> i
) & mask
;
3525 /* Pad basic MPU access permission bits to extended format. */
3526 static uint32_t extended_mpu_ap_bits(uint32_t val
)
3533 for (i
= 0; i
< 16; i
+= 2) {
3534 ret
|= (val
& mask
) << i
;
3540 static void pmsav5_data_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3543 env
->cp15
.pmsav5_data_ap
= extended_mpu_ap_bits(value
);
3546 static uint64_t pmsav5_data_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3548 return simple_mpu_ap_bits(env
->cp15
.pmsav5_data_ap
);
3551 static void pmsav5_insn_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3554 env
->cp15
.pmsav5_insn_ap
= extended_mpu_ap_bits(value
);
3557 static uint64_t pmsav5_insn_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3559 return simple_mpu_ap_bits(env
->cp15
.pmsav5_insn_ap
);
3562 static uint64_t pmsav7_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3564 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
3570 u32p
+= env
->pmsav7
.rnr
[M_REG_NS
];
3574 static void pmsav7_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3577 ARMCPU
*cpu
= env_archcpu(env
);
3578 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
3584 u32p
+= env
->pmsav7
.rnr
[M_REG_NS
];
3585 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
3589 static void pmsav7_rgnr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3592 ARMCPU
*cpu
= env_archcpu(env
);
3593 uint32_t nrgs
= cpu
->pmsav7_dregion
;
3595 if (value
>= nrgs
) {
3596 qemu_log_mask(LOG_GUEST_ERROR
,
3597 "PMSAv7 RGNR write >= # supported regions, %" PRIu32
3598 " > %" PRIu32
"\n", (uint32_t)value
, nrgs
);
3602 raw_write(env
, ri
, value
);
3605 static const ARMCPRegInfo pmsav7_cp_reginfo
[] = {
3606 /* Reset for all these registers is handled in arm_cpu_reset(),
3607 * because the PMSAv7 is also used by M-profile CPUs, which do
3608 * not register cpregs but still need the state to be reset.
3610 { .name
= "DRBAR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 0,
3611 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
3612 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drbar
),
3613 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
3614 .resetfn
= arm_cp_reset_ignore
},
3615 { .name
= "DRSR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 2,
3616 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
3617 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drsr
),
3618 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
3619 .resetfn
= arm_cp_reset_ignore
},
3620 { .name
= "DRACR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 4,
3621 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
3622 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.dracr
),
3623 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
3624 .resetfn
= arm_cp_reset_ignore
},
3625 { .name
= "RGNR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 2, .opc2
= 0,
3627 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.rnr
[M_REG_NS
]),
3628 .writefn
= pmsav7_rgnr_write
,
3629 .resetfn
= arm_cp_reset_ignore
},
3632 static const ARMCPRegInfo pmsav5_cp_reginfo
[] = {
3633 { .name
= "DATA_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
3634 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
3635 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
3636 .readfn
= pmsav5_data_ap_read
, .writefn
= pmsav5_data_ap_write
, },
3637 { .name
= "INSN_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
3638 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
3639 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
3640 .readfn
= pmsav5_insn_ap_read
, .writefn
= pmsav5_insn_ap_write
, },
3641 { .name
= "DATA_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 2,
3643 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
3645 { .name
= "INSN_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 3,
3647 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
3649 { .name
= "DCACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 0,
3651 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_data
), .resetvalue
= 0, },
3652 { .name
= "ICACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 1,
3654 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_insn
), .resetvalue
= 0, },
3655 /* Protection region base and size registers */
3656 { .name
= "946_PRBS0", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0,
3657 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3658 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[0]) },
3659 { .name
= "946_PRBS1", .cp
= 15, .crn
= 6, .crm
= 1, .opc1
= 0,
3660 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3661 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[1]) },
3662 { .name
= "946_PRBS2", .cp
= 15, .crn
= 6, .crm
= 2, .opc1
= 0,
3663 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3664 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[2]) },
3665 { .name
= "946_PRBS3", .cp
= 15, .crn
= 6, .crm
= 3, .opc1
= 0,
3666 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3667 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[3]) },
3668 { .name
= "946_PRBS4", .cp
= 15, .crn
= 6, .crm
= 4, .opc1
= 0,
3669 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3670 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[4]) },
3671 { .name
= "946_PRBS5", .cp
= 15, .crn
= 6, .crm
= 5, .opc1
= 0,
3672 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3673 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[5]) },
3674 { .name
= "946_PRBS6", .cp
= 15, .crn
= 6, .crm
= 6, .opc1
= 0,
3675 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3676 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[6]) },
3677 { .name
= "946_PRBS7", .cp
= 15, .crn
= 6, .crm
= 7, .opc1
= 0,
3678 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3679 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[7]) },
3682 static void vmsa_ttbcr_raw_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3685 TCR
*tcr
= raw_ptr(env
, ri
);
3686 int maskshift
= extract32(value
, 0, 3);
3688 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
3689 if (arm_feature(env
, ARM_FEATURE_LPAE
) && (value
& TTBCR_EAE
)) {
3690 /* Pre ARMv8 bits [21:19], [15:14] and [6:3] are UNK/SBZP when
3691 * using Long-desciptor translation table format */
3692 value
&= ~((7 << 19) | (3 << 14) | (0xf << 3));
3693 } else if (arm_feature(env
, ARM_FEATURE_EL3
)) {
3694 /* In an implementation that includes the Security Extensions
3695 * TTBCR has additional fields PD0 [4] and PD1 [5] for
3696 * Short-descriptor translation table format.
3698 value
&= TTBCR_PD1
| TTBCR_PD0
| TTBCR_N
;
3704 /* Update the masks corresponding to the TCR bank being written
3705 * Note that we always calculate mask and base_mask, but
3706 * they are only used for short-descriptor tables (ie if EAE is 0);
3707 * for long-descriptor tables the TCR fields are used differently
3708 * and the mask and base_mask values are meaningless.
3710 tcr
->raw_tcr
= value
;
3711 tcr
->mask
= ~(((uint32_t)0xffffffffu
) >> maskshift
);
3712 tcr
->base_mask
= ~((uint32_t)0x3fffu
>> maskshift
);
3715 static void vmsa_ttbcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3718 ARMCPU
*cpu
= env_archcpu(env
);
3719 TCR
*tcr
= raw_ptr(env
, ri
);
3721 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3722 /* With LPAE the TTBCR could result in a change of ASID
3723 * via the TTBCR.A1 bit, so do a TLB flush.
3725 tlb_flush(CPU(cpu
));
3727 /* Preserve the high half of TCR_EL1, set via TTBCR2. */
3728 value
= deposit64(tcr
->raw_tcr
, 0, 32, value
);
3729 vmsa_ttbcr_raw_write(env
, ri
, value
);
3732 static void vmsa_ttbcr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3734 TCR
*tcr
= raw_ptr(env
, ri
);
3736 /* Reset both the TCR as well as the masks corresponding to the bank of
3737 * the TCR being reset.
3741 tcr
->base_mask
= 0xffffc000u
;
3744 static void vmsa_tcr_el12_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3747 ARMCPU
*cpu
= env_archcpu(env
);
3748 TCR
*tcr
= raw_ptr(env
, ri
);
3750 /* For AArch64 the A1 bit could result in a change of ASID, so TLB flush. */
3751 tlb_flush(CPU(cpu
));
3752 tcr
->raw_tcr
= value
;
3755 static void vmsa_ttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3758 /* If the ASID changes (with a 64-bit write), we must flush the TLB. */
3759 if (cpreg_field_is_64bit(ri
) &&
3760 extract64(raw_read(env
, ri
) ^ value
, 48, 16) != 0) {
3761 ARMCPU
*cpu
= env_archcpu(env
);
3762 tlb_flush(CPU(cpu
));
3764 raw_write(env
, ri
, value
);
3767 static void vmsa_tcr_ttbr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3771 * If we are running with E2&0 regime, then an ASID is active.
3772 * Flush if that might be changing. Note we're not checking
3773 * TCR_EL2.A1 to know if this is really the TTBRx_EL2 that
3774 * holds the active ASID, only checking the field that might.
3776 if (extract64(raw_read(env
, ri
) ^ value
, 48, 16) &&
3777 (arm_hcr_el2_eff(env
) & HCR_E2H
)) {
3778 uint16_t mask
= ARMMMUIdxBit_E20_2
|
3779 ARMMMUIdxBit_E20_2_PAN
|
3782 if (arm_is_secure_below_el3(env
)) {
3783 mask
>>= ARM_MMU_IDX_A_NS
;
3786 tlb_flush_by_mmuidx(env_cpu(env
), mask
);
3788 raw_write(env
, ri
, value
);
3791 static void vttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3794 ARMCPU
*cpu
= env_archcpu(env
);
3795 CPUState
*cs
= CPU(cpu
);
3798 * A change in VMID to the stage2 page table (Stage2) invalidates
3799 * the combined stage 1&2 tlbs (EL10_1 and EL10_0).
3801 if (raw_read(env
, ri
) != value
) {
3802 uint16_t mask
= ARMMMUIdxBit_E10_1
|
3803 ARMMMUIdxBit_E10_1_PAN
|
3806 if (arm_is_secure_below_el3(env
)) {
3807 mask
>>= ARM_MMU_IDX_A_NS
;
3810 tlb_flush_by_mmuidx(cs
, mask
);
3811 raw_write(env
, ri
, value
);
3815 static const ARMCPRegInfo vmsa_pmsa_cp_reginfo
[] = {
3816 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
3817 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .type
= ARM_CP_ALIAS
,
3818 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dfsr_s
),
3819 offsetoflow32(CPUARMState
, cp15
.dfsr_ns
) }, },
3820 { .name
= "IFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
3821 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
3822 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.ifsr_s
),
3823 offsetoflow32(CPUARMState
, cp15
.ifsr_ns
) } },
3824 { .name
= "DFAR", .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 0, .opc2
= 0,
3825 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
3826 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.dfar_s
),
3827 offsetof(CPUARMState
, cp15
.dfar_ns
) } },
3828 { .name
= "FAR_EL1", .state
= ARM_CP_STATE_AA64
,
3829 .opc0
= 3, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 0,
3830 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3831 .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[1]),
3835 static const ARMCPRegInfo vmsa_cp_reginfo
[] = {
3836 { .name
= "ESR_EL1", .state
= ARM_CP_STATE_AA64
,
3837 .opc0
= 3, .crn
= 5, .crm
= 2, .opc1
= 0, .opc2
= 0,
3838 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3839 .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[1]), .resetvalue
= 0, },
3840 { .name
= "TTBR0_EL1", .state
= ARM_CP_STATE_BOTH
,
3841 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 0,
3842 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3843 .writefn
= vmsa_ttbr_write
, .resetvalue
= 0,
3844 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
3845 offsetof(CPUARMState
, cp15
.ttbr0_ns
) } },
3846 { .name
= "TTBR1_EL1", .state
= ARM_CP_STATE_BOTH
,
3847 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 1,
3848 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3849 .writefn
= vmsa_ttbr_write
, .resetvalue
= 0,
3850 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
3851 offsetof(CPUARMState
, cp15
.ttbr1_ns
) } },
3852 { .name
= "TCR_EL1", .state
= ARM_CP_STATE_AA64
,
3853 .opc0
= 3, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
3854 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3855 .writefn
= vmsa_tcr_el12_write
,
3856 .resetfn
= vmsa_ttbcr_reset
, .raw_writefn
= raw_write
,
3857 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[1]) },
3858 { .name
= "TTBCR", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
3859 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3860 .type
= ARM_CP_ALIAS
, .writefn
= vmsa_ttbcr_write
,
3861 .raw_writefn
= vmsa_ttbcr_raw_write
,
3862 /* No offsetoflow32 -- pass the entire TCR to writefn/raw_writefn. */
3863 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.tcr_el
[3]),
3864 offsetof(CPUARMState
, cp15
.tcr_el
[1])} },
3867 /* Note that unlike TTBCR, writing to TTBCR2 does not require flushing
3868 * qemu tlbs nor adjusting cached masks.
3870 static const ARMCPRegInfo ttbcr2_reginfo
= {
3871 .name
= "TTBCR2", .cp
= 15, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 3,
3872 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3873 .type
= ARM_CP_ALIAS
,
3874 .bank_fieldoffsets
= {
3875 offsetofhigh32(CPUARMState
, cp15
.tcr_el
[3].raw_tcr
),
3876 offsetofhigh32(CPUARMState
, cp15
.tcr_el
[1].raw_tcr
),
3880 static void omap_ticonfig_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3883 env
->cp15
.c15_ticonfig
= value
& 0xe7;
3884 /* The OS_TYPE bit in this register changes the reported CPUID! */
3885 env
->cp15
.c0_cpuid
= (value
& (1 << 5)) ?
3886 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
3889 static void omap_threadid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3892 env
->cp15
.c15_threadid
= value
& 0xffff;
3895 static void omap_wfi_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3898 /* Wait-for-interrupt (deprecated) */
3899 cpu_interrupt(env_cpu(env
), CPU_INTERRUPT_HALT
);
3902 static void omap_cachemaint_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3905 /* On OMAP there are registers indicating the max/min index of dcache lines
3906 * containing a dirty line; cache flush operations have to reset these.
3908 env
->cp15
.c15_i_max
= 0x000;
3909 env
->cp15
.c15_i_min
= 0xff0;
3912 static const ARMCPRegInfo omap_cp_reginfo
[] = {
3913 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= CP_ANY
,
3914 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_OVERRIDE
,
3915 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.esr_el
[1]),
3917 { .name
= "", .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 0, .opc2
= 0,
3918 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
3919 { .name
= "TICONFIG", .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0,
3921 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ticonfig
), .resetvalue
= 0,
3922 .writefn
= omap_ticonfig_write
},
3923 { .name
= "IMAX", .cp
= 15, .crn
= 15, .crm
= 2, .opc1
= 0, .opc2
= 0,
3925 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_max
), .resetvalue
= 0, },
3926 { .name
= "IMIN", .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 0, .opc2
= 0,
3927 .access
= PL1_RW
, .resetvalue
= 0xff0,
3928 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_min
) },
3929 { .name
= "THREADID", .cp
= 15, .crn
= 15, .crm
= 4, .opc1
= 0, .opc2
= 0,
3931 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_threadid
), .resetvalue
= 0,
3932 .writefn
= omap_threadid_write
},
3933 { .name
= "TI925T_STATUS", .cp
= 15, .crn
= 15,
3934 .crm
= 8, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
3935 .type
= ARM_CP_NO_RAW
,
3936 .readfn
= arm_cp_read_zero
, .writefn
= omap_wfi_write
, },
3937 /* TODO: Peripheral port remap register:
3938 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt controller
3939 * base address at $rn & ~0xfff and map size of 0x200 << ($rn & 0xfff),
3942 { .name
= "OMAP_CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
3943 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
3944 .type
= ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
,
3945 .writefn
= omap_cachemaint_write
},
3946 { .name
= "C9", .cp
= 15, .crn
= 9,
3947 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
,
3948 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
, .resetvalue
= 0 },
3951 static void xscale_cpar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3954 env
->cp15
.c15_cpar
= value
& 0x3fff;
3957 static const ARMCPRegInfo xscale_cp_reginfo
[] = {
3958 { .name
= "XSCALE_CPAR",
3959 .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
3960 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_cpar
), .resetvalue
= 0,
3961 .writefn
= xscale_cpar_write
, },
3962 { .name
= "XSCALE_AUXCR",
3963 .cp
= 15, .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 1, .access
= PL1_RW
,
3964 .fieldoffset
= offsetof(CPUARMState
, cp15
.c1_xscaleauxcr
),
3966 /* XScale specific cache-lockdown: since we have no cache we NOP these
3967 * and hope the guest does not really rely on cache behaviour.
3969 { .name
= "XSCALE_LOCK_ICACHE_LINE",
3970 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 0,
3971 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3972 { .name
= "XSCALE_UNLOCK_ICACHE",
3973 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 1,
3974 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3975 { .name
= "XSCALE_DCACHE_LOCK",
3976 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 0,
3977 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
3978 { .name
= "XSCALE_UNLOCK_DCACHE",
3979 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 1,
3980 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3983 static const ARMCPRegInfo dummy_c15_cp_reginfo
[] = {
3984 /* RAZ/WI the whole crn=15 space, when we don't have a more specific
3985 * implementation of this implementation-defined space.
3986 * Ideally this should eventually disappear in favour of actually
3987 * implementing the correct behaviour for all cores.
3989 { .name
= "C15_IMPDEF", .cp
= 15, .crn
= 15,
3990 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
3992 .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
| ARM_CP_OVERRIDE
,
3996 static const ARMCPRegInfo cache_dirty_status_cp_reginfo
[] = {
3997 /* Cache status: RAZ because we have no cache so it's always clean */
3998 { .name
= "CDSR", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 6,
3999 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4003 static const ARMCPRegInfo cache_block_ops_cp_reginfo
[] = {
4004 /* We never have a a block transfer operation in progress */
4005 { .name
= "BXSR", .cp
= 15, .crn
= 7, .crm
= 12, .opc1
= 0, .opc2
= 4,
4006 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4008 /* The cache ops themselves: these all NOP for QEMU */
4009 { .name
= "IICR", .cp
= 15, .crm
= 5, .opc1
= 0,
4010 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4011 { .name
= "IDCR", .cp
= 15, .crm
= 6, .opc1
= 0,
4012 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4013 { .name
= "CDCR", .cp
= 15, .crm
= 12, .opc1
= 0,
4014 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4015 { .name
= "PIR", .cp
= 15, .crm
= 12, .opc1
= 1,
4016 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4017 { .name
= "PDR", .cp
= 15, .crm
= 12, .opc1
= 2,
4018 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4019 { .name
= "CIDCR", .cp
= 15, .crm
= 14, .opc1
= 0,
4020 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4023 static const ARMCPRegInfo cache_test_clean_cp_reginfo
[] = {
4024 /* The cache test-and-clean instructions always return (1 << 30)
4025 * to indicate that there are no dirty cache lines.
4027 { .name
= "TC_DCACHE", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 3,
4028 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4029 .resetvalue
= (1 << 30) },
4030 { .name
= "TCI_DCACHE", .cp
= 15, .crn
= 7, .crm
= 14, .opc1
= 0, .opc2
= 3,
4031 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4032 .resetvalue
= (1 << 30) },
4035 static const ARMCPRegInfo strongarm_cp_reginfo
[] = {
4036 /* Ignore ReadBuffer accesses */
4037 { .name
= "C9_READBUFFER", .cp
= 15, .crn
= 9,
4038 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
4039 .access
= PL1_RW
, .resetvalue
= 0,
4040 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
},
4043 static uint64_t midr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4045 unsigned int cur_el
= arm_current_el(env
);
4047 if (arm_is_el2_enabled(env
) && cur_el
== 1) {
4048 return env
->cp15
.vpidr_el2
;
4050 return raw_read(env
, ri
);
4053 static uint64_t mpidr_read_val(CPUARMState
*env
)
4055 ARMCPU
*cpu
= env_archcpu(env
);
4056 uint64_t mpidr
= cpu
->mp_affinity
;
4058 if (arm_feature(env
, ARM_FEATURE_V7MP
)) {
4059 mpidr
|= (1U << 31);
4060 /* Cores which are uniprocessor (non-coherent)
4061 * but still implement the MP extensions set
4062 * bit 30. (For instance, Cortex-R5).
4064 if (cpu
->mp_is_up
) {
4065 mpidr
|= (1u << 30);
4071 static uint64_t mpidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4073 unsigned int cur_el
= arm_current_el(env
);
4075 if (arm_is_el2_enabled(env
) && cur_el
== 1) {
4076 return env
->cp15
.vmpidr_el2
;
4078 return mpidr_read_val(env
);
4081 static const ARMCPRegInfo lpae_cp_reginfo
[] = {
4083 { .name
= "AMAIR0", .state
= ARM_CP_STATE_BOTH
,
4084 .opc0
= 3, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 0,
4085 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4086 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4087 /* AMAIR1 is mapped to AMAIR_EL1[63:32] */
4088 { .name
= "AMAIR1", .cp
= 15, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 1,
4089 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4090 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4091 { .name
= "PAR", .cp
= 15, .crm
= 7, .opc1
= 0,
4092 .access
= PL1_RW
, .type
= ARM_CP_64BIT
, .resetvalue
= 0,
4093 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.par_s
),
4094 offsetof(CPUARMState
, cp15
.par_ns
)} },
4095 { .name
= "TTBR0", .cp
= 15, .crm
= 2, .opc1
= 0,
4096 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4097 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
4098 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
4099 offsetof(CPUARMState
, cp15
.ttbr0_ns
) },
4100 .writefn
= vmsa_ttbr_write
, },
4101 { .name
= "TTBR1", .cp
= 15, .crm
= 2, .opc1
= 1,
4102 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4103 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
4104 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
4105 offsetof(CPUARMState
, cp15
.ttbr1_ns
) },
4106 .writefn
= vmsa_ttbr_write
, },
4109 static uint64_t aa64_fpcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4111 return vfp_get_fpcr(env
);
4114 static void aa64_fpcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4117 vfp_set_fpcr(env
, value
);
4120 static uint64_t aa64_fpsr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4122 return vfp_get_fpsr(env
);
4125 static void aa64_fpsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4128 vfp_set_fpsr(env
, value
);
4131 static CPAccessResult
aa64_daif_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4134 if (arm_current_el(env
) == 0 && !(arm_sctlr(env
, 0) & SCTLR_UMA
)) {
4135 return CP_ACCESS_TRAP
;
4137 return CP_ACCESS_OK
;
4140 static void aa64_daif_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4143 env
->daif
= value
& PSTATE_DAIF
;
4146 static uint64_t aa64_pan_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4148 return env
->pstate
& PSTATE_PAN
;
4151 static void aa64_pan_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4154 env
->pstate
= (env
->pstate
& ~PSTATE_PAN
) | (value
& PSTATE_PAN
);
4157 static const ARMCPRegInfo pan_reginfo
= {
4158 .name
= "PAN", .state
= ARM_CP_STATE_AA64
,
4159 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 3,
4160 .type
= ARM_CP_NO_RAW
, .access
= PL1_RW
,
4161 .readfn
= aa64_pan_read
, .writefn
= aa64_pan_write
4164 static uint64_t aa64_uao_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4166 return env
->pstate
& PSTATE_UAO
;
4169 static void aa64_uao_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4172 env
->pstate
= (env
->pstate
& ~PSTATE_UAO
) | (value
& PSTATE_UAO
);
4175 static const ARMCPRegInfo uao_reginfo
= {
4176 .name
= "UAO", .state
= ARM_CP_STATE_AA64
,
4177 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 4,
4178 .type
= ARM_CP_NO_RAW
, .access
= PL1_RW
,
4179 .readfn
= aa64_uao_read
, .writefn
= aa64_uao_write
4182 static uint64_t aa64_dit_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4184 return env
->pstate
& PSTATE_DIT
;
4187 static void aa64_dit_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4190 env
->pstate
= (env
->pstate
& ~PSTATE_DIT
) | (value
& PSTATE_DIT
);
4193 static const ARMCPRegInfo dit_reginfo
= {
4194 .name
= "DIT", .state
= ARM_CP_STATE_AA64
,
4195 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 5,
4196 .type
= ARM_CP_NO_RAW
, .access
= PL0_RW
,
4197 .readfn
= aa64_dit_read
, .writefn
= aa64_dit_write
4200 static uint64_t aa64_ssbs_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4202 return env
->pstate
& PSTATE_SSBS
;
4205 static void aa64_ssbs_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4208 env
->pstate
= (env
->pstate
& ~PSTATE_SSBS
) | (value
& PSTATE_SSBS
);
4211 static const ARMCPRegInfo ssbs_reginfo
= {
4212 .name
= "SSBS", .state
= ARM_CP_STATE_AA64
,
4213 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 6,
4214 .type
= ARM_CP_NO_RAW
, .access
= PL0_RW
,
4215 .readfn
= aa64_ssbs_read
, .writefn
= aa64_ssbs_write
4218 static CPAccessResult
aa64_cacheop_poc_access(CPUARMState
*env
,
4219 const ARMCPRegInfo
*ri
,
4222 /* Cache invalidate/clean to Point of Coherency or Persistence... */
4223 switch (arm_current_el(env
)) {
4225 /* ... EL0 must UNDEF unless SCTLR_EL1.UCI is set. */
4226 if (!(arm_sctlr(env
, 0) & SCTLR_UCI
)) {
4227 return CP_ACCESS_TRAP
;
4231 /* ... EL1 must trap to EL2 if HCR_EL2.TPCP is set. */
4232 if (arm_hcr_el2_eff(env
) & HCR_TPCP
) {
4233 return CP_ACCESS_TRAP_EL2
;
4237 return CP_ACCESS_OK
;
4240 static CPAccessResult
aa64_cacheop_pou_access(CPUARMState
*env
,
4241 const ARMCPRegInfo
*ri
,
4244 /* Cache invalidate/clean to Point of Unification... */
4245 switch (arm_current_el(env
)) {
4247 /* ... EL0 must UNDEF unless SCTLR_EL1.UCI is set. */
4248 if (!(arm_sctlr(env
, 0) & SCTLR_UCI
)) {
4249 return CP_ACCESS_TRAP
;
4253 /* ... EL1 must trap to EL2 if HCR_EL2.TPU is set. */
4254 if (arm_hcr_el2_eff(env
) & HCR_TPU
) {
4255 return CP_ACCESS_TRAP_EL2
;
4259 return CP_ACCESS_OK
;
4262 /* See: D4.7.2 TLB maintenance requirements and the TLB maintenance instructions
4263 * Page D4-1736 (DDI0487A.b)
4266 static int vae1_tlbmask(CPUARMState
*env
)
4268 uint64_t hcr
= arm_hcr_el2_eff(env
);
4271 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4272 mask
= ARMMMUIdxBit_E20_2
|
4273 ARMMMUIdxBit_E20_2_PAN
|
4276 mask
= ARMMMUIdxBit_E10_1
|
4277 ARMMMUIdxBit_E10_1_PAN
|
4281 if (arm_is_secure_below_el3(env
)) {
4282 mask
>>= ARM_MMU_IDX_A_NS
;
4288 /* Return 56 if TBI is enabled, 64 otherwise. */
4289 static int tlbbits_for_regime(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
4292 uint64_t tcr
= regime_tcr(env
, mmu_idx
)->raw_tcr
;
4293 int tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
4294 int select
= extract64(addr
, 55, 1);
4296 return (tbi
>> select
) & 1 ? 56 : 64;
4299 static int vae1_tlbbits(CPUARMState
*env
, uint64_t addr
)
4301 uint64_t hcr
= arm_hcr_el2_eff(env
);
4304 /* Only the regime of the mmu_idx below is significant. */
4305 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4306 mmu_idx
= ARMMMUIdx_E20_0
;
4308 mmu_idx
= ARMMMUIdx_E10_0
;
4311 if (arm_is_secure_below_el3(env
)) {
4312 mmu_idx
&= ~ARM_MMU_IDX_A_NS
;
4315 return tlbbits_for_regime(env
, mmu_idx
, addr
);
4318 static void tlbi_aa64_vmalle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4321 CPUState
*cs
= env_cpu(env
);
4322 int mask
= vae1_tlbmask(env
);
4324 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4327 static void tlbi_aa64_vmalle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4330 CPUState
*cs
= env_cpu(env
);
4331 int mask
= vae1_tlbmask(env
);
4333 if (tlb_force_broadcast(env
)) {
4334 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4336 tlb_flush_by_mmuidx(cs
, mask
);
4340 static int alle1_tlbmask(CPUARMState
*env
)
4343 * Note that the 'ALL' scope must invalidate both stage 1 and
4344 * stage 2 translations, whereas most other scopes only invalidate
4345 * stage 1 translations.
4347 if (arm_is_secure_below_el3(env
)) {
4348 return ARMMMUIdxBit_SE10_1
|
4349 ARMMMUIdxBit_SE10_1_PAN
|
4350 ARMMMUIdxBit_SE10_0
;
4352 return ARMMMUIdxBit_E10_1
|
4353 ARMMMUIdxBit_E10_1_PAN
|
4358 static int e2_tlbmask(CPUARMState
*env
)
4360 if (arm_is_secure_below_el3(env
)) {
4361 return ARMMMUIdxBit_SE20_0
|
4362 ARMMMUIdxBit_SE20_2
|
4363 ARMMMUIdxBit_SE20_2_PAN
|
4366 return ARMMMUIdxBit_E20_0
|
4367 ARMMMUIdxBit_E20_2
|
4368 ARMMMUIdxBit_E20_2_PAN
|
4373 static void tlbi_aa64_alle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4376 CPUState
*cs
= env_cpu(env
);
4377 int mask
= alle1_tlbmask(env
);
4379 tlb_flush_by_mmuidx(cs
, mask
);
4382 static void tlbi_aa64_alle2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4385 CPUState
*cs
= env_cpu(env
);
4386 int mask
= e2_tlbmask(env
);
4388 tlb_flush_by_mmuidx(cs
, mask
);
4391 static void tlbi_aa64_alle3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4394 ARMCPU
*cpu
= env_archcpu(env
);
4395 CPUState
*cs
= CPU(cpu
);
4397 tlb_flush_by_mmuidx(cs
, ARMMMUIdxBit_SE3
);
4400 static void tlbi_aa64_alle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4403 CPUState
*cs
= env_cpu(env
);
4404 int mask
= alle1_tlbmask(env
);
4406 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4409 static void tlbi_aa64_alle2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4412 CPUState
*cs
= env_cpu(env
);
4413 int mask
= e2_tlbmask(env
);
4415 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4418 static void tlbi_aa64_alle3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4421 CPUState
*cs
= env_cpu(env
);
4423 tlb_flush_by_mmuidx_all_cpus_synced(cs
, ARMMMUIdxBit_SE3
);
4426 static void tlbi_aa64_vae2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4429 /* Invalidate by VA, EL2
4430 * Currently handles both VAE2 and VALE2, since we don't support
4431 * flush-last-level-only.
4433 CPUState
*cs
= env_cpu(env
);
4434 int mask
= e2_tlbmask(env
);
4435 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4437 tlb_flush_page_by_mmuidx(cs
, pageaddr
, mask
);
4440 static void tlbi_aa64_vae3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4443 /* Invalidate by VA, EL3
4444 * Currently handles both VAE3 and VALE3, since we don't support
4445 * flush-last-level-only.
4447 ARMCPU
*cpu
= env_archcpu(env
);
4448 CPUState
*cs
= CPU(cpu
);
4449 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4451 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_SE3
);
4454 static void tlbi_aa64_vae1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4457 CPUState
*cs
= env_cpu(env
);
4458 int mask
= vae1_tlbmask(env
);
4459 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4460 int bits
= vae1_tlbbits(env
, pageaddr
);
4462 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4465 static void tlbi_aa64_vae1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4468 /* Invalidate by VA, EL1&0 (AArch64 version).
4469 * Currently handles all of VAE1, VAAE1, VAALE1 and VALE1,
4470 * since we don't support flush-for-specific-ASID-only or
4471 * flush-last-level-only.
4473 CPUState
*cs
= env_cpu(env
);
4474 int mask
= vae1_tlbmask(env
);
4475 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4476 int bits
= vae1_tlbbits(env
, pageaddr
);
4478 if (tlb_force_broadcast(env
)) {
4479 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4481 tlb_flush_page_bits_by_mmuidx(cs
, pageaddr
, mask
, bits
);
4485 static void tlbi_aa64_vae2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4488 CPUState
*cs
= env_cpu(env
);
4489 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4490 bool secure
= arm_is_secure_below_el3(env
);
4491 int mask
= secure
? ARMMMUIdxBit_SE2
: ARMMMUIdxBit_E2
;
4492 int bits
= tlbbits_for_regime(env
, secure
? ARMMMUIdx_SE2
: ARMMMUIdx_E2
,
4495 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4498 static void tlbi_aa64_vae3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4501 CPUState
*cs
= env_cpu(env
);
4502 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4503 int bits
= tlbbits_for_regime(env
, ARMMMUIdx_SE3
, pageaddr
);
4505 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
,
4506 ARMMMUIdxBit_SE3
, bits
);
4509 #ifdef TARGET_AARCH64
4515 static TLBIRange
tlbi_aa64_get_range(CPUARMState
*env
, ARMMMUIdx mmuidx
,
4518 unsigned int page_size_granule
, page_shift
, num
, scale
, exponent
;
4519 /* Extract one bit to represent the va selector in use. */
4520 uint64_t select
= sextract64(value
, 36, 1);
4521 ARMVAParameters param
= aa64_va_parameters(env
, select
, mmuidx
, true);
4522 TLBIRange ret
= { };
4524 page_size_granule
= extract64(value
, 46, 2);
4526 /* The granule encoded in value must match the granule in use. */
4527 if (page_size_granule
!= (param
.using64k
? 3 : param
.using16k
? 2 : 1)) {
4528 qemu_log_mask(LOG_GUEST_ERROR
, "Invalid tlbi page size granule %d\n",
4533 page_shift
= (page_size_granule
- 1) * 2 + 12;
4534 num
= extract64(value
, 39, 5);
4535 scale
= extract64(value
, 44, 2);
4536 exponent
= (5 * scale
) + 1;
4538 ret
.length
= (num
+ 1) << (exponent
+ page_shift
);
4541 ret
.base
= sextract64(value
, 0, 37);
4543 ret
.base
= extract64(value
, 0, 37);
4547 * With DS=1, BaseADDR is always shifted 16 so that it is able
4548 * to address all 52 va bits. The input address is perforce
4549 * aligned on a 64k boundary regardless of translation granule.
4553 ret
.base
<<= page_shift
;
4558 static void do_rvae_write(CPUARMState
*env
, uint64_t value
,
4559 int idxmap
, bool synced
)
4561 ARMMMUIdx one_idx
= ARM_MMU_IDX_A
| ctz32(idxmap
);
4565 range
= tlbi_aa64_get_range(env
, one_idx
, value
);
4566 bits
= tlbbits_for_regime(env
, one_idx
, range
.base
);
4569 tlb_flush_range_by_mmuidx_all_cpus_synced(env_cpu(env
),
4575 tlb_flush_range_by_mmuidx(env_cpu(env
), range
.base
,
4576 range
.length
, idxmap
, bits
);
4580 static void tlbi_aa64_rvae1_write(CPUARMState
*env
,
4581 const ARMCPRegInfo
*ri
,
4585 * Invalidate by VA range, EL1&0.
4586 * Currently handles all of RVAE1, RVAAE1, RVAALE1 and RVALE1,
4587 * since we don't support flush-for-specific-ASID-only or
4588 * flush-last-level-only.
4591 do_rvae_write(env
, value
, vae1_tlbmask(env
),
4592 tlb_force_broadcast(env
));
4595 static void tlbi_aa64_rvae1is_write(CPUARMState
*env
,
4596 const ARMCPRegInfo
*ri
,
4600 * Invalidate by VA range, Inner/Outer Shareable EL1&0.
4601 * Currently handles all of RVAE1IS, RVAE1OS, RVAAE1IS, RVAAE1OS,
4602 * RVAALE1IS, RVAALE1OS, RVALE1IS and RVALE1OS, since we don't support
4603 * flush-for-specific-ASID-only, flush-last-level-only or inner/outer
4604 * shareable specific flushes.
4607 do_rvae_write(env
, value
, vae1_tlbmask(env
), true);
4610 static int vae2_tlbmask(CPUARMState
*env
)
4612 return (arm_is_secure_below_el3(env
)
4613 ? ARMMMUIdxBit_SE2
: ARMMMUIdxBit_E2
);
4616 static void tlbi_aa64_rvae2_write(CPUARMState
*env
,
4617 const ARMCPRegInfo
*ri
,
4621 * Invalidate by VA range, EL2.
4622 * Currently handles all of RVAE2 and RVALE2,
4623 * since we don't support flush-for-specific-ASID-only or
4624 * flush-last-level-only.
4627 do_rvae_write(env
, value
, vae2_tlbmask(env
),
4628 tlb_force_broadcast(env
));
4633 static void tlbi_aa64_rvae2is_write(CPUARMState
*env
,
4634 const ARMCPRegInfo
*ri
,
4638 * Invalidate by VA range, Inner/Outer Shareable, EL2.
4639 * Currently handles all of RVAE2IS, RVAE2OS, RVALE2IS and RVALE2OS,
4640 * since we don't support flush-for-specific-ASID-only,
4641 * flush-last-level-only or inner/outer shareable specific flushes.
4644 do_rvae_write(env
, value
, vae2_tlbmask(env
), true);
4648 static void tlbi_aa64_rvae3_write(CPUARMState
*env
,
4649 const ARMCPRegInfo
*ri
,
4653 * Invalidate by VA range, EL3.
4654 * Currently handles all of RVAE3 and RVALE3,
4655 * since we don't support flush-for-specific-ASID-only or
4656 * flush-last-level-only.
4659 do_rvae_write(env
, value
, ARMMMUIdxBit_SE3
,
4660 tlb_force_broadcast(env
));
4663 static void tlbi_aa64_rvae3is_write(CPUARMState
*env
,
4664 const ARMCPRegInfo
*ri
,
4668 * Invalidate by VA range, EL3, Inner/Outer Shareable.
4669 * Currently handles all of RVAE3IS, RVAE3OS, RVALE3IS and RVALE3OS,
4670 * since we don't support flush-for-specific-ASID-only,
4671 * flush-last-level-only or inner/outer specific flushes.
4674 do_rvae_write(env
, value
, ARMMMUIdxBit_SE3
, true);
4678 static CPAccessResult
aa64_zva_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4681 int cur_el
= arm_current_el(env
);
4684 uint64_t hcr
= arm_hcr_el2_eff(env
);
4687 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4688 if (!(env
->cp15
.sctlr_el
[2] & SCTLR_DZE
)) {
4689 return CP_ACCESS_TRAP_EL2
;
4692 if (!(env
->cp15
.sctlr_el
[1] & SCTLR_DZE
)) {
4693 return CP_ACCESS_TRAP
;
4695 if (hcr
& HCR_TDZ
) {
4696 return CP_ACCESS_TRAP_EL2
;
4699 } else if (hcr
& HCR_TDZ
) {
4700 return CP_ACCESS_TRAP_EL2
;
4703 return CP_ACCESS_OK
;
4706 static uint64_t aa64_dczid_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4708 ARMCPU
*cpu
= env_archcpu(env
);
4709 int dzp_bit
= 1 << 4;
4711 /* DZP indicates whether DC ZVA access is allowed */
4712 if (aa64_zva_access(env
, NULL
, false) == CP_ACCESS_OK
) {
4715 return cpu
->dcz_blocksize
| dzp_bit
;
4718 static CPAccessResult
sp_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4721 if (!(env
->pstate
& PSTATE_SP
)) {
4722 /* Access to SP_EL0 is undefined if it's being used as
4723 * the stack pointer.
4725 return CP_ACCESS_TRAP_UNCATEGORIZED
;
4727 return CP_ACCESS_OK
;
4730 static uint64_t spsel_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4732 return env
->pstate
& PSTATE_SP
;
4735 static void spsel_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
4737 update_spsel(env
, val
);
4740 static void sctlr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4743 ARMCPU
*cpu
= env_archcpu(env
);
4745 if (arm_feature(env
, ARM_FEATURE_PMSA
) && !cpu
->has_mpu
) {
4746 /* M bit is RAZ/WI for PMSA with no MPU implemented */
4750 /* ??? Lots of these bits are not implemented. */
4752 if (ri
->state
== ARM_CP_STATE_AA64
&& !cpu_isar_feature(aa64_mte
, cpu
)) {
4753 if (ri
->opc1
== 6) { /* SCTLR_EL3 */
4754 value
&= ~(SCTLR_ITFSB
| SCTLR_TCF
| SCTLR_ATA
);
4756 value
&= ~(SCTLR_ITFSB
| SCTLR_TCF0
| SCTLR_TCF
|
4757 SCTLR_ATA0
| SCTLR_ATA
);
4761 if (raw_read(env
, ri
) == value
) {
4762 /* Skip the TLB flush if nothing actually changed; Linux likes
4763 * to do a lot of pointless SCTLR writes.
4768 raw_write(env
, ri
, value
);
4770 /* This may enable/disable the MMU, so do a TLB flush. */
4771 tlb_flush(CPU(cpu
));
4773 if (ri
->type
& ARM_CP_SUPPRESS_TB_END
) {
4775 * Normally we would always end the TB on an SCTLR write; see the
4776 * comment in ARMCPRegInfo sctlr initialization below for why Xscale
4777 * is special. Setting ARM_CP_SUPPRESS_TB_END also stops the rebuild
4778 * of hflags from the translator, so do it here.
4780 arm_rebuild_hflags(env
);
4784 static void sdcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4787 env
->cp15
.mdcr_el3
= value
& SDCR_VALID_MASK
;
4790 static const ARMCPRegInfo v8_cp_reginfo
[] = {
4791 /* Minimal set of EL0-visible registers. This will need to be expanded
4792 * significantly for system emulation of AArch64 CPUs.
4794 { .name
= "NZCV", .state
= ARM_CP_STATE_AA64
,
4795 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 2,
4796 .access
= PL0_RW
, .type
= ARM_CP_NZCV
},
4797 { .name
= "DAIF", .state
= ARM_CP_STATE_AA64
,
4798 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 2,
4799 .type
= ARM_CP_NO_RAW
,
4800 .access
= PL0_RW
, .accessfn
= aa64_daif_access
,
4801 .fieldoffset
= offsetof(CPUARMState
, daif
),
4802 .writefn
= aa64_daif_write
, .resetfn
= arm_cp_reset_ignore
},
4803 { .name
= "FPCR", .state
= ARM_CP_STATE_AA64
,
4804 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 4,
4805 .access
= PL0_RW
, .type
= ARM_CP_FPU
| ARM_CP_SUPPRESS_TB_END
,
4806 .readfn
= aa64_fpcr_read
, .writefn
= aa64_fpcr_write
},
4807 { .name
= "FPSR", .state
= ARM_CP_STATE_AA64
,
4808 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 4,
4809 .access
= PL0_RW
, .type
= ARM_CP_FPU
| ARM_CP_SUPPRESS_TB_END
,
4810 .readfn
= aa64_fpsr_read
, .writefn
= aa64_fpsr_write
},
4811 { .name
= "DCZID_EL0", .state
= ARM_CP_STATE_AA64
,
4812 .opc0
= 3, .opc1
= 3, .opc2
= 7, .crn
= 0, .crm
= 0,
4813 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
,
4814 .readfn
= aa64_dczid_read
},
4815 { .name
= "DC_ZVA", .state
= ARM_CP_STATE_AA64
,
4816 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 1,
4817 .access
= PL0_W
, .type
= ARM_CP_DC_ZVA
,
4818 #ifndef CONFIG_USER_ONLY
4819 /* Avoid overhead of an access check that always passes in user-mode */
4820 .accessfn
= aa64_zva_access
,
4823 { .name
= "CURRENTEL", .state
= ARM_CP_STATE_AA64
,
4824 .opc0
= 3, .opc1
= 0, .opc2
= 2, .crn
= 4, .crm
= 2,
4825 .access
= PL1_R
, .type
= ARM_CP_CURRENTEL
},
4826 /* Cache ops: all NOPs since we don't emulate caches */
4827 { .name
= "IC_IALLUIS", .state
= ARM_CP_STATE_AA64
,
4828 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
4829 .access
= PL1_W
, .type
= ARM_CP_NOP
,
4830 .accessfn
= aa64_cacheop_pou_access
},
4831 { .name
= "IC_IALLU", .state
= ARM_CP_STATE_AA64
,
4832 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
4833 .access
= PL1_W
, .type
= ARM_CP_NOP
,
4834 .accessfn
= aa64_cacheop_pou_access
},
4835 { .name
= "IC_IVAU", .state
= ARM_CP_STATE_AA64
,
4836 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 5, .opc2
= 1,
4837 .access
= PL0_W
, .type
= ARM_CP_NOP
,
4838 .accessfn
= aa64_cacheop_pou_access
},
4839 { .name
= "DC_IVAC", .state
= ARM_CP_STATE_AA64
,
4840 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
4841 .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
,
4842 .type
= ARM_CP_NOP
},
4843 { .name
= "DC_ISW", .state
= ARM_CP_STATE_AA64
,
4844 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
4845 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
4846 { .name
= "DC_CVAC", .state
= ARM_CP_STATE_AA64
,
4847 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 1,
4848 .access
= PL0_W
, .type
= ARM_CP_NOP
,
4849 .accessfn
= aa64_cacheop_poc_access
},
4850 { .name
= "DC_CSW", .state
= ARM_CP_STATE_AA64
,
4851 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
4852 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
4853 { .name
= "DC_CVAU", .state
= ARM_CP_STATE_AA64
,
4854 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 11, .opc2
= 1,
4855 .access
= PL0_W
, .type
= ARM_CP_NOP
,
4856 .accessfn
= aa64_cacheop_pou_access
},
4857 { .name
= "DC_CIVAC", .state
= ARM_CP_STATE_AA64
,
4858 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 1,
4859 .access
= PL0_W
, .type
= ARM_CP_NOP
,
4860 .accessfn
= aa64_cacheop_poc_access
},
4861 { .name
= "DC_CISW", .state
= ARM_CP_STATE_AA64
,
4862 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
4863 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
4864 /* TLBI operations */
4865 { .name
= "TLBI_VMALLE1IS", .state
= ARM_CP_STATE_AA64
,
4866 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
4867 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4868 .writefn
= tlbi_aa64_vmalle1is_write
},
4869 { .name
= "TLBI_VAE1IS", .state
= ARM_CP_STATE_AA64
,
4870 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
4871 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4872 .writefn
= tlbi_aa64_vae1is_write
},
4873 { .name
= "TLBI_ASIDE1IS", .state
= ARM_CP_STATE_AA64
,
4874 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
4875 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4876 .writefn
= tlbi_aa64_vmalle1is_write
},
4877 { .name
= "TLBI_VAAE1IS", .state
= ARM_CP_STATE_AA64
,
4878 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
4879 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4880 .writefn
= tlbi_aa64_vae1is_write
},
4881 { .name
= "TLBI_VALE1IS", .state
= ARM_CP_STATE_AA64
,
4882 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
4883 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4884 .writefn
= tlbi_aa64_vae1is_write
},
4885 { .name
= "TLBI_VAALE1IS", .state
= ARM_CP_STATE_AA64
,
4886 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
4887 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4888 .writefn
= tlbi_aa64_vae1is_write
},
4889 { .name
= "TLBI_VMALLE1", .state
= ARM_CP_STATE_AA64
,
4890 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
4891 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4892 .writefn
= tlbi_aa64_vmalle1_write
},
4893 { .name
= "TLBI_VAE1", .state
= ARM_CP_STATE_AA64
,
4894 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
4895 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4896 .writefn
= tlbi_aa64_vae1_write
},
4897 { .name
= "TLBI_ASIDE1", .state
= ARM_CP_STATE_AA64
,
4898 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
4899 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4900 .writefn
= tlbi_aa64_vmalle1_write
},
4901 { .name
= "TLBI_VAAE1", .state
= ARM_CP_STATE_AA64
,
4902 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
4903 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4904 .writefn
= tlbi_aa64_vae1_write
},
4905 { .name
= "TLBI_VALE1", .state
= ARM_CP_STATE_AA64
,
4906 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
4907 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4908 .writefn
= tlbi_aa64_vae1_write
},
4909 { .name
= "TLBI_VAALE1", .state
= ARM_CP_STATE_AA64
,
4910 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
4911 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4912 .writefn
= tlbi_aa64_vae1_write
},
4913 { .name
= "TLBI_IPAS2E1IS", .state
= ARM_CP_STATE_AA64
,
4914 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
4915 .access
= PL2_W
, .type
= ARM_CP_NOP
},
4916 { .name
= "TLBI_IPAS2LE1IS", .state
= ARM_CP_STATE_AA64
,
4917 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
4918 .access
= PL2_W
, .type
= ARM_CP_NOP
},
4919 { .name
= "TLBI_ALLE1IS", .state
= ARM_CP_STATE_AA64
,
4920 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
4921 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
4922 .writefn
= tlbi_aa64_alle1is_write
},
4923 { .name
= "TLBI_VMALLS12E1IS", .state
= ARM_CP_STATE_AA64
,
4924 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 6,
4925 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
4926 .writefn
= tlbi_aa64_alle1is_write
},
4927 { .name
= "TLBI_IPAS2E1", .state
= ARM_CP_STATE_AA64
,
4928 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
4929 .access
= PL2_W
, .type
= ARM_CP_NOP
},
4930 { .name
= "TLBI_IPAS2LE1", .state
= ARM_CP_STATE_AA64
,
4931 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
4932 .access
= PL2_W
, .type
= ARM_CP_NOP
},
4933 { .name
= "TLBI_ALLE1", .state
= ARM_CP_STATE_AA64
,
4934 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
4935 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
4936 .writefn
= tlbi_aa64_alle1_write
},
4937 { .name
= "TLBI_VMALLS12E1", .state
= ARM_CP_STATE_AA64
,
4938 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 6,
4939 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
4940 .writefn
= tlbi_aa64_alle1is_write
},
4941 #ifndef CONFIG_USER_ONLY
4942 /* 64 bit address translation operations */
4943 { .name
= "AT_S1E1R", .state
= ARM_CP_STATE_AA64
,
4944 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 0,
4945 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4946 .writefn
= ats_write64
},
4947 { .name
= "AT_S1E1W", .state
= ARM_CP_STATE_AA64
,
4948 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 1,
4949 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4950 .writefn
= ats_write64
},
4951 { .name
= "AT_S1E0R", .state
= ARM_CP_STATE_AA64
,
4952 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 2,
4953 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4954 .writefn
= ats_write64
},
4955 { .name
= "AT_S1E0W", .state
= ARM_CP_STATE_AA64
,
4956 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 3,
4957 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4958 .writefn
= ats_write64
},
4959 { .name
= "AT_S12E1R", .state
= ARM_CP_STATE_AA64
,
4960 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 4,
4961 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4962 .writefn
= ats_write64
},
4963 { .name
= "AT_S12E1W", .state
= ARM_CP_STATE_AA64
,
4964 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 5,
4965 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4966 .writefn
= ats_write64
},
4967 { .name
= "AT_S12E0R", .state
= ARM_CP_STATE_AA64
,
4968 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 6,
4969 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4970 .writefn
= ats_write64
},
4971 { .name
= "AT_S12E0W", .state
= ARM_CP_STATE_AA64
,
4972 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 7,
4973 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4974 .writefn
= ats_write64
},
4975 /* AT S1E2* are elsewhere as they UNDEF from EL3 if EL2 is not present */
4976 { .name
= "AT_S1E3R", .state
= ARM_CP_STATE_AA64
,
4977 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 0,
4978 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4979 .writefn
= ats_write64
},
4980 { .name
= "AT_S1E3W", .state
= ARM_CP_STATE_AA64
,
4981 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 1,
4982 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4983 .writefn
= ats_write64
},
4984 { .name
= "PAR_EL1", .state
= ARM_CP_STATE_AA64
,
4985 .type
= ARM_CP_ALIAS
,
4986 .opc0
= 3, .opc1
= 0, .crn
= 7, .crm
= 4, .opc2
= 0,
4987 .access
= PL1_RW
, .resetvalue
= 0,
4988 .fieldoffset
= offsetof(CPUARMState
, cp15
.par_el
[1]),
4989 .writefn
= par_write
},
4991 /* TLB invalidate last level of translation table walk */
4992 { .name
= "TLBIMVALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
4993 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
4994 .writefn
= tlbimva_is_write
},
4995 { .name
= "TLBIMVAALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
4996 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
4997 .writefn
= tlbimvaa_is_write
},
4998 { .name
= "TLBIMVAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
4999 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5000 .writefn
= tlbimva_write
},
5001 { .name
= "TLBIMVAAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
5002 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5003 .writefn
= tlbimvaa_write
},
5004 { .name
= "TLBIMVALH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
5005 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5006 .writefn
= tlbimva_hyp_write
},
5007 { .name
= "TLBIMVALHIS",
5008 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
5009 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5010 .writefn
= tlbimva_hyp_is_write
},
5011 { .name
= "TLBIIPAS2",
5012 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
5013 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5014 { .name
= "TLBIIPAS2IS",
5015 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
5016 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5017 { .name
= "TLBIIPAS2L",
5018 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
5019 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5020 { .name
= "TLBIIPAS2LIS",
5021 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
5022 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5023 /* 32 bit cache operations */
5024 { .name
= "ICIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
5025 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5026 { .name
= "BPIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 6,
5027 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5028 { .name
= "ICIALLU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
5029 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5030 { .name
= "ICIMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 1,
5031 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5032 { .name
= "BPIALL", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 6,
5033 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5034 { .name
= "BPIMVA", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 7,
5035 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5036 { .name
= "DCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
5037 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5038 { .name
= "DCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
5039 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5040 { .name
= "DCCMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 1,
5041 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5042 { .name
= "DCCSW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
5043 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5044 { .name
= "DCCMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 11, .opc2
= 1,
5045 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5046 { .name
= "DCCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 1,
5047 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5048 { .name
= "DCCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
5049 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5050 /* MMU Domain access control / MPU write buffer control */
5051 { .name
= "DACR", .cp
= 15, .opc1
= 0, .crn
= 3, .crm
= 0, .opc2
= 0,
5052 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
5053 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
5054 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
5055 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
5056 { .name
= "ELR_EL1", .state
= ARM_CP_STATE_AA64
,
5057 .type
= ARM_CP_ALIAS
,
5058 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 1,
5060 .fieldoffset
= offsetof(CPUARMState
, elr_el
[1]) },
5061 { .name
= "SPSR_EL1", .state
= ARM_CP_STATE_AA64
,
5062 .type
= ARM_CP_ALIAS
,
5063 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 0,
5065 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_SVC
]) },
5066 /* We rely on the access checks not allowing the guest to write to the
5067 * state field when SPSel indicates that it's being used as the stack
5070 { .name
= "SP_EL0", .state
= ARM_CP_STATE_AA64
,
5071 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 1, .opc2
= 0,
5072 .access
= PL1_RW
, .accessfn
= sp_el0_access
,
5073 .type
= ARM_CP_ALIAS
,
5074 .fieldoffset
= offsetof(CPUARMState
, sp_el
[0]) },
5075 { .name
= "SP_EL1", .state
= ARM_CP_STATE_AA64
,
5076 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 1, .opc2
= 0,
5077 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
,
5078 .fieldoffset
= offsetof(CPUARMState
, sp_el
[1]) },
5079 { .name
= "SPSel", .state
= ARM_CP_STATE_AA64
,
5080 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 0,
5081 .type
= ARM_CP_NO_RAW
,
5082 .access
= PL1_RW
, .readfn
= spsel_read
, .writefn
= spsel_write
},
5083 { .name
= "FPEXC32_EL2", .state
= ARM_CP_STATE_AA64
,
5084 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 3, .opc2
= 0,
5086 .type
= ARM_CP_ALIAS
| ARM_CP_FPU
| ARM_CP_EL3_NO_EL2_KEEP
,
5087 .fieldoffset
= offsetof(CPUARMState
, vfp
.xregs
[ARM_VFP_FPEXC
]) },
5088 { .name
= "DACR32_EL2", .state
= ARM_CP_STATE_AA64
,
5089 .opc0
= 3, .opc1
= 4, .crn
= 3, .crm
= 0, .opc2
= 0,
5090 .access
= PL2_RW
, .resetvalue
= 0, .type
= ARM_CP_EL3_NO_EL2_KEEP
,
5091 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
5092 .fieldoffset
= offsetof(CPUARMState
, cp15
.dacr32_el2
) },
5093 { .name
= "IFSR32_EL2", .state
= ARM_CP_STATE_AA64
,
5094 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 0, .opc2
= 1,
5095 .access
= PL2_RW
, .resetvalue
= 0, .type
= ARM_CP_EL3_NO_EL2_KEEP
,
5096 .fieldoffset
= offsetof(CPUARMState
, cp15
.ifsr32_el2
) },
5097 { .name
= "SPSR_IRQ", .state
= ARM_CP_STATE_AA64
,
5098 .type
= ARM_CP_ALIAS
,
5099 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 0,
5101 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_IRQ
]) },
5102 { .name
= "SPSR_ABT", .state
= ARM_CP_STATE_AA64
,
5103 .type
= ARM_CP_ALIAS
,
5104 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 1,
5106 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_ABT
]) },
5107 { .name
= "SPSR_UND", .state
= ARM_CP_STATE_AA64
,
5108 .type
= ARM_CP_ALIAS
,
5109 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 2,
5111 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_UND
]) },
5112 { .name
= "SPSR_FIQ", .state
= ARM_CP_STATE_AA64
,
5113 .type
= ARM_CP_ALIAS
,
5114 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 3,
5116 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_FIQ
]) },
5117 { .name
= "MDCR_EL3", .state
= ARM_CP_STATE_AA64
,
5118 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 3, .opc2
= 1,
5120 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el3
) },
5121 { .name
= "SDCR", .type
= ARM_CP_ALIAS
,
5122 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 3, .opc2
= 1,
5123 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
5124 .writefn
= sdcr_write
,
5125 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.mdcr_el3
) },
5128 static void do_hcr_write(CPUARMState
*env
, uint64_t value
, uint64_t valid_mask
)
5130 ARMCPU
*cpu
= env_archcpu(env
);
5132 if (arm_feature(env
, ARM_FEATURE_V8
)) {
5133 valid_mask
|= MAKE_64BIT_MASK(0, 34); /* ARMv8.0 */
5135 valid_mask
|= MAKE_64BIT_MASK(0, 28); /* ARMv7VE */
5138 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
5139 valid_mask
&= ~HCR_HCD
;
5140 } else if (cpu
->psci_conduit
!= QEMU_PSCI_CONDUIT_SMC
) {
5141 /* Architecturally HCR.TSC is RES0 if EL3 is not implemented.
5142 * However, if we're using the SMC PSCI conduit then QEMU is
5143 * effectively acting like EL3 firmware and so the guest at
5144 * EL2 should retain the ability to prevent EL1 from being
5145 * able to make SMC calls into the ersatz firmware, so in
5146 * that case HCR.TSC should be read/write.
5148 valid_mask
&= ~HCR_TSC
;
5151 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
5152 if (cpu_isar_feature(aa64_vh
, cpu
)) {
5153 valid_mask
|= HCR_E2H
;
5155 if (cpu_isar_feature(aa64_ras
, cpu
)) {
5156 valid_mask
|= HCR_TERR
| HCR_TEA
;
5158 if (cpu_isar_feature(aa64_lor
, cpu
)) {
5159 valid_mask
|= HCR_TLOR
;
5161 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
5162 valid_mask
|= HCR_API
| HCR_APK
;
5164 if (cpu_isar_feature(aa64_mte
, cpu
)) {
5165 valid_mask
|= HCR_ATA
| HCR_DCT
| HCR_TID5
;
5167 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
5168 valid_mask
|= HCR_ENSCXT
;
5170 if (cpu_isar_feature(aa64_fwb
, cpu
)) {
5171 valid_mask
|= HCR_FWB
;
5175 /* Clear RES0 bits. */
5176 value
&= valid_mask
;
5179 * These bits change the MMU setup:
5180 * HCR_VM enables stage 2 translation
5181 * HCR_PTW forbids certain page-table setups
5182 * HCR_DC disables stage1 and enables stage2 translation
5183 * HCR_DCT enables tagging on (disabled) stage1 translation
5184 * HCR_FWB changes the interpretation of stage2 descriptor bits
5186 if ((env
->cp15
.hcr_el2
^ value
) &
5187 (HCR_VM
| HCR_PTW
| HCR_DC
| HCR_DCT
| HCR_FWB
)) {
5188 tlb_flush(CPU(cpu
));
5190 env
->cp15
.hcr_el2
= value
;
5193 * Updates to VI and VF require us to update the status of
5194 * virtual interrupts, which are the logical OR of these bits
5195 * and the state of the input lines from the GIC. (This requires
5196 * that we have the iothread lock, which is done by marking the
5197 * reginfo structs as ARM_CP_IO.)
5198 * Note that if a write to HCR pends a VIRQ or VFIQ it is never
5199 * possible for it to be taken immediately, because VIRQ and
5200 * VFIQ are masked unless running at EL0 or EL1, and HCR
5201 * can only be written at EL2.
5203 g_assert(qemu_mutex_iothread_locked());
5204 arm_cpu_update_virq(cpu
);
5205 arm_cpu_update_vfiq(cpu
);
5206 arm_cpu_update_vserr(cpu
);
5209 static void hcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
5211 do_hcr_write(env
, value
, 0);
5214 static void hcr_writehigh(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5217 /* Handle HCR2 write, i.e. write to high half of HCR_EL2 */
5218 value
= deposit64(env
->cp15
.hcr_el2
, 32, 32, value
);
5219 do_hcr_write(env
, value
, MAKE_64BIT_MASK(0, 32));
5222 static void hcr_writelow(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5225 /* Handle HCR write, i.e. write to low half of HCR_EL2 */
5226 value
= deposit64(env
->cp15
.hcr_el2
, 0, 32, value
);
5227 do_hcr_write(env
, value
, MAKE_64BIT_MASK(32, 32));
5231 * Return the effective value of HCR_EL2.
5232 * Bits that are not included here:
5233 * RW (read from SCR_EL3.RW as needed)
5235 uint64_t arm_hcr_el2_eff(CPUARMState
*env
)
5237 uint64_t ret
= env
->cp15
.hcr_el2
;
5239 if (!arm_is_el2_enabled(env
)) {
5241 * "This register has no effect if EL2 is not enabled in the
5242 * current Security state". This is ARMv8.4-SecEL2 speak for
5243 * !(SCR_EL3.NS==1 || SCR_EL3.EEL2==1).
5245 * Prior to that, the language was "In an implementation that
5246 * includes EL3, when the value of SCR_EL3.NS is 0 the PE behaves
5247 * as if this field is 0 for all purposes other than a direct
5248 * read or write access of HCR_EL2". With lots of enumeration
5249 * on a per-field basis. In current QEMU, this is condition
5250 * is arm_is_secure_below_el3.
5252 * Since the v8.4 language applies to the entire register, and
5253 * appears to be backward compatible, use that.
5259 * For a cpu that supports both aarch64 and aarch32, we can set bits
5260 * in HCR_EL2 (e.g. via EL3) that are RES0 when we enter EL2 as aa32.
5261 * Ignore all of the bits in HCR+HCR2 that are not valid for aarch32.
5263 if (!arm_el_is_aa64(env
, 2)) {
5264 uint64_t aa32_valid
;
5267 * These bits are up-to-date as of ARMv8.6.
5268 * For HCR, it's easiest to list just the 2 bits that are invalid.
5269 * For HCR2, list those that are valid.
5271 aa32_valid
= MAKE_64BIT_MASK(0, 32) & ~(HCR_RW
| HCR_TDZ
);
5272 aa32_valid
|= (HCR_CD
| HCR_ID
| HCR_TERR
| HCR_TEA
| HCR_MIOCNCE
|
5273 HCR_TID4
| HCR_TICAB
| HCR_TOCU
| HCR_TTLBIS
);
5277 if (ret
& HCR_TGE
) {
5278 /* These bits are up-to-date as of ARMv8.6. */
5279 if (ret
& HCR_E2H
) {
5280 ret
&= ~(HCR_VM
| HCR_FMO
| HCR_IMO
| HCR_AMO
|
5281 HCR_BSU_MASK
| HCR_DC
| HCR_TWI
| HCR_TWE
|
5282 HCR_TID0
| HCR_TID2
| HCR_TPCP
| HCR_TPU
|
5283 HCR_TDZ
| HCR_CD
| HCR_ID
| HCR_MIOCNCE
|
5284 HCR_TID4
| HCR_TICAB
| HCR_TOCU
| HCR_ENSCXT
|
5285 HCR_TTLBIS
| HCR_TTLBOS
| HCR_TID5
);
5287 ret
|= HCR_FMO
| HCR_IMO
| HCR_AMO
;
5289 ret
&= ~(HCR_SWIO
| HCR_PTW
| HCR_VF
| HCR_VI
| HCR_VSE
|
5290 HCR_FB
| HCR_TID1
| HCR_TID3
| HCR_TSC
| HCR_TACR
|
5291 HCR_TSW
| HCR_TTLB
| HCR_TVM
| HCR_HCD
| HCR_TRVM
|
5298 static void hcrx_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5301 uint64_t valid_mask
= 0;
5303 /* No features adding bits to HCRX are implemented. */
5305 /* Clear RES0 bits. */
5306 env
->cp15
.hcrx_el2
= value
& valid_mask
;
5309 static CPAccessResult
access_hxen(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5312 if (arm_current_el(env
) < 3
5313 && arm_feature(env
, ARM_FEATURE_EL3
)
5314 && !(env
->cp15
.scr_el3
& SCR_HXEN
)) {
5315 return CP_ACCESS_TRAP_EL3
;
5317 return CP_ACCESS_OK
;
5320 static const ARMCPRegInfo hcrx_el2_reginfo
= {
5321 .name
= "HCRX_EL2", .state
= ARM_CP_STATE_AA64
,
5322 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 2,
5323 .access
= PL2_RW
, .writefn
= hcrx_write
, .accessfn
= access_hxen
,
5324 .fieldoffset
= offsetof(CPUARMState
, cp15
.hcrx_el2
),
5327 /* Return the effective value of HCRX_EL2. */
5328 uint64_t arm_hcrx_el2_eff(CPUARMState
*env
)
5331 * The bits in this register behave as 0 for all purposes other than
5332 * direct reads of the register if:
5333 * - EL2 is not enabled in the current security state,
5334 * - SCR_EL3.HXEn is 0.
5336 if (!arm_is_el2_enabled(env
)
5337 || (arm_feature(env
, ARM_FEATURE_EL3
)
5338 && !(env
->cp15
.scr_el3
& SCR_HXEN
))) {
5341 return env
->cp15
.hcrx_el2
;
5344 static void cptr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5348 * For A-profile AArch32 EL3, if NSACR.CP10
5349 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
5351 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
5352 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
5353 uint64_t mask
= R_HCPTR_TCP11_MASK
| R_HCPTR_TCP10_MASK
;
5354 value
= (value
& ~mask
) | (env
->cp15
.cptr_el
[2] & mask
);
5356 env
->cp15
.cptr_el
[2] = value
;
5359 static uint64_t cptr_el2_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
5362 * For A-profile AArch32 EL3, if NSACR.CP10
5363 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
5365 uint64_t value
= env
->cp15
.cptr_el
[2];
5367 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
5368 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
5369 value
|= R_HCPTR_TCP11_MASK
| R_HCPTR_TCP10_MASK
;
5374 static const ARMCPRegInfo el2_cp_reginfo
[] = {
5375 { .name
= "HCR_EL2", .state
= ARM_CP_STATE_AA64
,
5377 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
5378 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.hcr_el2
),
5379 .writefn
= hcr_write
},
5380 { .name
= "HCR", .state
= ARM_CP_STATE_AA32
,
5381 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
5382 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
5383 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.hcr_el2
),
5384 .writefn
= hcr_writelow
},
5385 { .name
= "HACR_EL2", .state
= ARM_CP_STATE_BOTH
,
5386 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 7,
5387 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5388 { .name
= "ELR_EL2", .state
= ARM_CP_STATE_AA64
,
5389 .type
= ARM_CP_ALIAS
,
5390 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 1,
5392 .fieldoffset
= offsetof(CPUARMState
, elr_el
[2]) },
5393 { .name
= "ESR_EL2", .state
= ARM_CP_STATE_BOTH
,
5394 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 2, .opc2
= 0,
5395 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[2]) },
5396 { .name
= "FAR_EL2", .state
= ARM_CP_STATE_BOTH
,
5397 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 0,
5398 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[2]) },
5399 { .name
= "HIFAR", .state
= ARM_CP_STATE_AA32
,
5400 .type
= ARM_CP_ALIAS
,
5401 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 2,
5403 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.far_el
[2]) },
5404 { .name
= "SPSR_EL2", .state
= ARM_CP_STATE_AA64
,
5405 .type
= ARM_CP_ALIAS
,
5406 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 0,
5408 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_HYP
]) },
5409 { .name
= "VBAR_EL2", .state
= ARM_CP_STATE_BOTH
,
5410 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 0,
5411 .access
= PL2_RW
, .writefn
= vbar_write
,
5412 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[2]),
5414 { .name
= "SP_EL2", .state
= ARM_CP_STATE_AA64
,
5415 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 1, .opc2
= 0,
5416 .access
= PL3_RW
, .type
= ARM_CP_ALIAS
,
5417 .fieldoffset
= offsetof(CPUARMState
, sp_el
[2]) },
5418 { .name
= "CPTR_EL2", .state
= ARM_CP_STATE_BOTH
,
5419 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 2,
5420 .access
= PL2_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
5421 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[2]),
5422 .readfn
= cptr_el2_read
, .writefn
= cptr_el2_write
},
5423 { .name
= "MAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
5424 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 0,
5425 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[2]),
5427 { .name
= "HMAIR1", .state
= ARM_CP_STATE_AA32
,
5428 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 1,
5429 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
,
5430 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.mair_el
[2]) },
5431 { .name
= "AMAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
5432 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 0,
5433 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5435 /* HAMAIR1 is mapped to AMAIR_EL2[63:32] */
5436 { .name
= "HAMAIR1", .state
= ARM_CP_STATE_AA32
,
5437 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 1,
5438 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5440 { .name
= "AFSR0_EL2", .state
= ARM_CP_STATE_BOTH
,
5441 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 0,
5442 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5444 { .name
= "AFSR1_EL2", .state
= ARM_CP_STATE_BOTH
,
5445 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 1,
5446 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5448 { .name
= "TCR_EL2", .state
= ARM_CP_STATE_BOTH
,
5449 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 2,
5450 .access
= PL2_RW
, .writefn
= vmsa_tcr_el12_write
,
5451 /* no .raw_writefn or .resetfn needed as we never use mask/base_mask */
5452 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[2]) },
5453 { .name
= "VTCR", .state
= ARM_CP_STATE_AA32
,
5454 .cp
= 15, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
5455 .type
= ARM_CP_ALIAS
,
5456 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5457 .fieldoffset
= offsetof(CPUARMState
, cp15
.vtcr_el2
) },
5458 { .name
= "VTCR_EL2", .state
= ARM_CP_STATE_AA64
,
5459 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
5461 /* no .writefn needed as this can't cause an ASID change;
5462 * no .raw_writefn or .resetfn needed as we never use mask/base_mask
5464 .fieldoffset
= offsetof(CPUARMState
, cp15
.vtcr_el2
) },
5465 { .name
= "VTTBR", .state
= ARM_CP_STATE_AA32
,
5466 .cp
= 15, .opc1
= 6, .crm
= 2,
5467 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
5468 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5469 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
),
5470 .writefn
= vttbr_write
},
5471 { .name
= "VTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
5472 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 0,
5473 .access
= PL2_RW
, .writefn
= vttbr_write
,
5474 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
) },
5475 { .name
= "SCTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
5476 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 0,
5477 .access
= PL2_RW
, .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
5478 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[2]) },
5479 { .name
= "TPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
5480 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 2,
5481 .access
= PL2_RW
, .resetvalue
= 0,
5482 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[2]) },
5483 { .name
= "TTBR0_EL2", .state
= ARM_CP_STATE_AA64
,
5484 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 0,
5485 .access
= PL2_RW
, .resetvalue
= 0, .writefn
= vmsa_tcr_ttbr_el2_write
,
5486 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
5487 { .name
= "HTTBR", .cp
= 15, .opc1
= 4, .crm
= 2,
5488 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
5489 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
5490 { .name
= "TLBIALLNSNH",
5491 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
5492 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5493 .writefn
= tlbiall_nsnh_write
},
5494 { .name
= "TLBIALLNSNHIS",
5495 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
5496 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5497 .writefn
= tlbiall_nsnh_is_write
},
5498 { .name
= "TLBIALLH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
5499 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5500 .writefn
= tlbiall_hyp_write
},
5501 { .name
= "TLBIALLHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
5502 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5503 .writefn
= tlbiall_hyp_is_write
},
5504 { .name
= "TLBIMVAH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
5505 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5506 .writefn
= tlbimva_hyp_write
},
5507 { .name
= "TLBIMVAHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
5508 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5509 .writefn
= tlbimva_hyp_is_write
},
5510 { .name
= "TLBI_ALLE2", .state
= ARM_CP_STATE_AA64
,
5511 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
5512 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5513 .writefn
= tlbi_aa64_alle2_write
},
5514 { .name
= "TLBI_VAE2", .state
= ARM_CP_STATE_AA64
,
5515 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
5516 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5517 .writefn
= tlbi_aa64_vae2_write
},
5518 { .name
= "TLBI_VALE2", .state
= ARM_CP_STATE_AA64
,
5519 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
5520 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5521 .writefn
= tlbi_aa64_vae2_write
},
5522 { .name
= "TLBI_ALLE2IS", .state
= ARM_CP_STATE_AA64
,
5523 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
5524 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5525 .writefn
= tlbi_aa64_alle2is_write
},
5526 { .name
= "TLBI_VAE2IS", .state
= ARM_CP_STATE_AA64
,
5527 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
5528 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5529 .writefn
= tlbi_aa64_vae2is_write
},
5530 { .name
= "TLBI_VALE2IS", .state
= ARM_CP_STATE_AA64
,
5531 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
5532 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5533 .writefn
= tlbi_aa64_vae2is_write
},
5534 #ifndef CONFIG_USER_ONLY
5535 /* Unlike the other EL2-related AT operations, these must
5536 * UNDEF from EL3 if EL2 is not implemented, which is why we
5537 * define them here rather than with the rest of the AT ops.
5539 { .name
= "AT_S1E2R", .state
= ARM_CP_STATE_AA64
,
5540 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
5541 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
5542 .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
| ARM_CP_EL3_NO_EL2_UNDEF
,
5543 .writefn
= ats_write64
},
5544 { .name
= "AT_S1E2W", .state
= ARM_CP_STATE_AA64
,
5545 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
5546 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
5547 .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
| ARM_CP_EL3_NO_EL2_UNDEF
,
5548 .writefn
= ats_write64
},
5549 /* The AArch32 ATS1H* operations are CONSTRAINED UNPREDICTABLE
5550 * if EL2 is not implemented; we choose to UNDEF. Behaviour at EL3
5551 * with SCR.NS == 0 outside Monitor mode is UNPREDICTABLE; we choose
5552 * to behave as if SCR.NS was 1.
5554 { .name
= "ATS1HR", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
5556 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
5557 { .name
= "ATS1HW", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
5559 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
5560 { .name
= "CNTHCTL_EL2", .state
= ARM_CP_STATE_BOTH
,
5561 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 1, .opc2
= 0,
5562 /* ARMv7 requires bit 0 and 1 to reset to 1. ARMv8 defines the
5563 * reset values as IMPDEF. We choose to reset to 3 to comply with
5564 * both ARMv7 and ARMv8.
5566 .access
= PL2_RW
, .resetvalue
= 3,
5567 .fieldoffset
= offsetof(CPUARMState
, cp15
.cnthctl_el2
) },
5568 { .name
= "CNTVOFF_EL2", .state
= ARM_CP_STATE_AA64
,
5569 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 0, .opc2
= 3,
5570 .access
= PL2_RW
, .type
= ARM_CP_IO
, .resetvalue
= 0,
5571 .writefn
= gt_cntvoff_write
,
5572 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
5573 { .name
= "CNTVOFF", .cp
= 15, .opc1
= 4, .crm
= 14,
5574 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
| ARM_CP_IO
,
5575 .writefn
= gt_cntvoff_write
,
5576 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
5577 { .name
= "CNTHP_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
5578 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 2,
5579 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
5580 .type
= ARM_CP_IO
, .access
= PL2_RW
,
5581 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
5582 { .name
= "CNTHP_CVAL", .cp
= 15, .opc1
= 6, .crm
= 14,
5583 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
5584 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_IO
,
5585 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
5586 { .name
= "CNTHP_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
5587 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 0,
5588 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL2_RW
,
5589 .resetfn
= gt_hyp_timer_reset
,
5590 .readfn
= gt_hyp_tval_read
, .writefn
= gt_hyp_tval_write
},
5591 { .name
= "CNTHP_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
5593 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 1,
5595 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].ctl
),
5597 .writefn
= gt_hyp_ctl_write
, .raw_writefn
= raw_write
},
5599 { .name
= "HPFAR", .state
= ARM_CP_STATE_AA32
,
5600 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
5601 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5602 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
5603 { .name
= "HPFAR_EL2", .state
= ARM_CP_STATE_AA64
,
5604 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
5606 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
5607 { .name
= "HSTR_EL2", .state
= ARM_CP_STATE_BOTH
,
5608 .cp
= 15, .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 3,
5610 .fieldoffset
= offsetof(CPUARMState
, cp15
.hstr_el2
) },
5613 static const ARMCPRegInfo el2_v8_cp_reginfo
[] = {
5614 { .name
= "HCR2", .state
= ARM_CP_STATE_AA32
,
5615 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
5616 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 4,
5618 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.hcr_el2
),
5619 .writefn
= hcr_writehigh
},
5622 static CPAccessResult
sel2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5625 if (arm_current_el(env
) == 3 || arm_is_secure_below_el3(env
)) {
5626 return CP_ACCESS_OK
;
5628 return CP_ACCESS_TRAP_UNCATEGORIZED
;
5631 static const ARMCPRegInfo el2_sec_cp_reginfo
[] = {
5632 { .name
= "VSTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
5633 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 6, .opc2
= 0,
5634 .access
= PL2_RW
, .accessfn
= sel2_access
,
5635 .fieldoffset
= offsetof(CPUARMState
, cp15
.vsttbr_el2
) },
5636 { .name
= "VSTCR_EL2", .state
= ARM_CP_STATE_AA64
,
5637 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 6, .opc2
= 2,
5638 .access
= PL2_RW
, .accessfn
= sel2_access
,
5639 .fieldoffset
= offsetof(CPUARMState
, cp15
.vstcr_el2
) },
5642 static CPAccessResult
nsacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5645 /* The NSACR is RW at EL3, and RO for NS EL1 and NS EL2.
5646 * At Secure EL1 it traps to EL3 or EL2.
5648 if (arm_current_el(env
) == 3) {
5649 return CP_ACCESS_OK
;
5651 if (arm_is_secure_below_el3(env
)) {
5652 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
5653 return CP_ACCESS_TRAP_EL2
;
5655 return CP_ACCESS_TRAP_EL3
;
5657 /* Accesses from EL1 NS and EL2 NS are UNDEF for write but allow reads. */
5659 return CP_ACCESS_OK
;
5661 return CP_ACCESS_TRAP_UNCATEGORIZED
;
5664 static const ARMCPRegInfo el3_cp_reginfo
[] = {
5665 { .name
= "SCR_EL3", .state
= ARM_CP_STATE_AA64
,
5666 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 0,
5667 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.scr_el3
),
5668 .resetfn
= scr_reset
, .writefn
= scr_write
},
5669 { .name
= "SCR", .type
= ARM_CP_ALIAS
| ARM_CP_NEWEL
,
5670 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 0,
5671 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
5672 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.scr_el3
),
5673 .writefn
= scr_write
},
5674 { .name
= "SDER32_EL3", .state
= ARM_CP_STATE_AA64
,
5675 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 1,
5676 .access
= PL3_RW
, .resetvalue
= 0,
5677 .fieldoffset
= offsetof(CPUARMState
, cp15
.sder
) },
5679 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 1,
5680 .access
= PL3_RW
, .resetvalue
= 0,
5681 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.sder
) },
5682 { .name
= "MVBAR", .cp
= 15, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
5683 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
5684 .writefn
= vbar_write
, .resetvalue
= 0,
5685 .fieldoffset
= offsetof(CPUARMState
, cp15
.mvbar
) },
5686 { .name
= "TTBR0_EL3", .state
= ARM_CP_STATE_AA64
,
5687 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 0,
5688 .access
= PL3_RW
, .resetvalue
= 0,
5689 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[3]) },
5690 { .name
= "TCR_EL3", .state
= ARM_CP_STATE_AA64
,
5691 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 2,
5693 /* no .writefn needed as this can't cause an ASID change;
5694 * we must provide a .raw_writefn and .resetfn because we handle
5695 * reset and migration for the AArch32 TTBCR(S), which might be
5696 * using mask and base_mask.
5698 .resetfn
= vmsa_ttbcr_reset
, .raw_writefn
= vmsa_ttbcr_raw_write
,
5699 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[3]) },
5700 { .name
= "ELR_EL3", .state
= ARM_CP_STATE_AA64
,
5701 .type
= ARM_CP_ALIAS
,
5702 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 1,
5704 .fieldoffset
= offsetof(CPUARMState
, elr_el
[3]) },
5705 { .name
= "ESR_EL3", .state
= ARM_CP_STATE_AA64
,
5706 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 2, .opc2
= 0,
5707 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[3]) },
5708 { .name
= "FAR_EL3", .state
= ARM_CP_STATE_AA64
,
5709 .opc0
= 3, .opc1
= 6, .crn
= 6, .crm
= 0, .opc2
= 0,
5710 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[3]) },
5711 { .name
= "SPSR_EL3", .state
= ARM_CP_STATE_AA64
,
5712 .type
= ARM_CP_ALIAS
,
5713 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 0,
5715 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_MON
]) },
5716 { .name
= "VBAR_EL3", .state
= ARM_CP_STATE_AA64
,
5717 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 0,
5718 .access
= PL3_RW
, .writefn
= vbar_write
,
5719 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[3]),
5721 { .name
= "CPTR_EL3", .state
= ARM_CP_STATE_AA64
,
5722 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 2,
5723 .access
= PL3_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
5724 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[3]) },
5725 { .name
= "TPIDR_EL3", .state
= ARM_CP_STATE_AA64
,
5726 .opc0
= 3, .opc1
= 6, .crn
= 13, .crm
= 0, .opc2
= 2,
5727 .access
= PL3_RW
, .resetvalue
= 0,
5728 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[3]) },
5729 { .name
= "AMAIR_EL3", .state
= ARM_CP_STATE_AA64
,
5730 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 3, .opc2
= 0,
5731 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
5733 { .name
= "AFSR0_EL3", .state
= ARM_CP_STATE_BOTH
,
5734 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 0,
5735 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
5737 { .name
= "AFSR1_EL3", .state
= ARM_CP_STATE_BOTH
,
5738 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 1,
5739 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
5741 { .name
= "TLBI_ALLE3IS", .state
= ARM_CP_STATE_AA64
,
5742 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 0,
5743 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5744 .writefn
= tlbi_aa64_alle3is_write
},
5745 { .name
= "TLBI_VAE3IS", .state
= ARM_CP_STATE_AA64
,
5746 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 1,
5747 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5748 .writefn
= tlbi_aa64_vae3is_write
},
5749 { .name
= "TLBI_VALE3IS", .state
= ARM_CP_STATE_AA64
,
5750 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 5,
5751 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5752 .writefn
= tlbi_aa64_vae3is_write
},
5753 { .name
= "TLBI_ALLE3", .state
= ARM_CP_STATE_AA64
,
5754 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 0,
5755 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5756 .writefn
= tlbi_aa64_alle3_write
},
5757 { .name
= "TLBI_VAE3", .state
= ARM_CP_STATE_AA64
,
5758 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 1,
5759 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5760 .writefn
= tlbi_aa64_vae3_write
},
5761 { .name
= "TLBI_VALE3", .state
= ARM_CP_STATE_AA64
,
5762 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 5,
5763 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5764 .writefn
= tlbi_aa64_vae3_write
},
5767 #ifndef CONFIG_USER_ONLY
5768 /* Test if system register redirection is to occur in the current state. */
5769 static bool redirect_for_e2h(CPUARMState
*env
)
5771 return arm_current_el(env
) == 2 && (arm_hcr_el2_eff(env
) & HCR_E2H
);
5774 static uint64_t el2_e2h_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
5778 if (redirect_for_e2h(env
)) {
5779 /* Switch to the saved EL2 version of the register. */
5781 readfn
= ri
->readfn
;
5783 readfn
= ri
->orig_readfn
;
5785 if (readfn
== NULL
) {
5788 return readfn(env
, ri
);
5791 static void el2_e2h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5796 if (redirect_for_e2h(env
)) {
5797 /* Switch to the saved EL2 version of the register. */
5799 writefn
= ri
->writefn
;
5801 writefn
= ri
->orig_writefn
;
5803 if (writefn
== NULL
) {
5804 writefn
= raw_write
;
5806 writefn(env
, ri
, value
);
5809 static void define_arm_vh_e2h_redirects_aliases(ARMCPU
*cpu
)
5812 uint32_t src_key
, dst_key
, new_key
;
5813 const char *src_name
, *dst_name
, *new_name
;
5814 bool (*feature
)(const ARMISARegisters
*id
);
5817 #define K(op0, op1, crn, crm, op2) \
5818 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP, crn, crm, op0, op1, op2)
5820 static const struct E2HAlias aliases
[] = {
5821 { K(3, 0, 1, 0, 0), K(3, 4, 1, 0, 0), K(3, 5, 1, 0, 0),
5822 "SCTLR", "SCTLR_EL2", "SCTLR_EL12" },
5823 { K(3, 0, 1, 0, 2), K(3, 4, 1, 1, 2), K(3, 5, 1, 0, 2),
5824 "CPACR", "CPTR_EL2", "CPACR_EL12" },
5825 { K(3, 0, 2, 0, 0), K(3, 4, 2, 0, 0), K(3, 5, 2, 0, 0),
5826 "TTBR0_EL1", "TTBR0_EL2", "TTBR0_EL12" },
5827 { K(3, 0, 2, 0, 1), K(3, 4, 2, 0, 1), K(3, 5, 2, 0, 1),
5828 "TTBR1_EL1", "TTBR1_EL2", "TTBR1_EL12" },
5829 { K(3, 0, 2, 0, 2), K(3, 4, 2, 0, 2), K(3, 5, 2, 0, 2),
5830 "TCR_EL1", "TCR_EL2", "TCR_EL12" },
5831 { K(3, 0, 4, 0, 0), K(3, 4, 4, 0, 0), K(3, 5, 4, 0, 0),
5832 "SPSR_EL1", "SPSR_EL2", "SPSR_EL12" },
5833 { K(3, 0, 4, 0, 1), K(3, 4, 4, 0, 1), K(3, 5, 4, 0, 1),
5834 "ELR_EL1", "ELR_EL2", "ELR_EL12" },
5835 { K(3, 0, 5, 1, 0), K(3, 4, 5, 1, 0), K(3, 5, 5, 1, 0),
5836 "AFSR0_EL1", "AFSR0_EL2", "AFSR0_EL12" },
5837 { K(3, 0, 5, 1, 1), K(3, 4, 5, 1, 1), K(3, 5, 5, 1, 1),
5838 "AFSR1_EL1", "AFSR1_EL2", "AFSR1_EL12" },
5839 { K(3, 0, 5, 2, 0), K(3, 4, 5, 2, 0), K(3, 5, 5, 2, 0),
5840 "ESR_EL1", "ESR_EL2", "ESR_EL12" },
5841 { K(3, 0, 6, 0, 0), K(3, 4, 6, 0, 0), K(3, 5, 6, 0, 0),
5842 "FAR_EL1", "FAR_EL2", "FAR_EL12" },
5843 { K(3, 0, 10, 2, 0), K(3, 4, 10, 2, 0), K(3, 5, 10, 2, 0),
5844 "MAIR_EL1", "MAIR_EL2", "MAIR_EL12" },
5845 { K(3, 0, 10, 3, 0), K(3, 4, 10, 3, 0), K(3, 5, 10, 3, 0),
5846 "AMAIR0", "AMAIR_EL2", "AMAIR_EL12" },
5847 { K(3, 0, 12, 0, 0), K(3, 4, 12, 0, 0), K(3, 5, 12, 0, 0),
5848 "VBAR", "VBAR_EL2", "VBAR_EL12" },
5849 { K(3, 0, 13, 0, 1), K(3, 4, 13, 0, 1), K(3, 5, 13, 0, 1),
5850 "CONTEXTIDR_EL1", "CONTEXTIDR_EL2", "CONTEXTIDR_EL12" },
5851 { K(3, 0, 14, 1, 0), K(3, 4, 14, 1, 0), K(3, 5, 14, 1, 0),
5852 "CNTKCTL", "CNTHCTL_EL2", "CNTKCTL_EL12" },
5855 * Note that redirection of ZCR is mentioned in the description
5856 * of ZCR_EL2, and aliasing in the description of ZCR_EL1, but
5857 * not in the summary table.
5859 { K(3, 0, 1, 2, 0), K(3, 4, 1, 2, 0), K(3, 5, 1, 2, 0),
5860 "ZCR_EL1", "ZCR_EL2", "ZCR_EL12", isar_feature_aa64_sve
},
5862 { K(3, 0, 5, 6, 0), K(3, 4, 5, 6, 0), K(3, 5, 5, 6, 0),
5863 "TFSR_EL1", "TFSR_EL2", "TFSR_EL12", isar_feature_aa64_mte
},
5865 { K(3, 0, 13, 0, 7), K(3, 4, 13, 0, 7), K(3, 5, 13, 0, 7),
5866 "SCXTNUM_EL1", "SCXTNUM_EL2", "SCXTNUM_EL12",
5867 isar_feature_aa64_scxtnum
},
5869 /* TODO: ARMv8.2-SPE -- PMSCR_EL2 */
5870 /* TODO: ARMv8.4-Trace -- TRFCR_EL2 */
5876 for (i
= 0; i
< ARRAY_SIZE(aliases
); i
++) {
5877 const struct E2HAlias
*a
= &aliases
[i
];
5878 ARMCPRegInfo
*src_reg
, *dst_reg
, *new_reg
;
5881 if (a
->feature
&& !a
->feature(&cpu
->isar
)) {
5885 src_reg
= g_hash_table_lookup(cpu
->cp_regs
,
5886 (gpointer
)(uintptr_t)a
->src_key
);
5887 dst_reg
= g_hash_table_lookup(cpu
->cp_regs
,
5888 (gpointer
)(uintptr_t)a
->dst_key
);
5889 g_assert(src_reg
!= NULL
);
5890 g_assert(dst_reg
!= NULL
);
5892 /* Cross-compare names to detect typos in the keys. */
5893 g_assert(strcmp(src_reg
->name
, a
->src_name
) == 0);
5894 g_assert(strcmp(dst_reg
->name
, a
->dst_name
) == 0);
5896 /* None of the core system registers use opaque; we will. */
5897 g_assert(src_reg
->opaque
== NULL
);
5899 /* Create alias before redirection so we dup the right data. */
5900 new_reg
= g_memdup(src_reg
, sizeof(ARMCPRegInfo
));
5902 new_reg
->name
= a
->new_name
;
5903 new_reg
->type
|= ARM_CP_ALIAS
;
5904 /* Remove PL1/PL0 access, leaving PL2/PL3 R/W in place. */
5905 new_reg
->access
&= PL2_RW
| PL3_RW
;
5907 ok
= g_hash_table_insert(cpu
->cp_regs
,
5908 (gpointer
)(uintptr_t)a
->new_key
, new_reg
);
5911 src_reg
->opaque
= dst_reg
;
5912 src_reg
->orig_readfn
= src_reg
->readfn
?: raw_read
;
5913 src_reg
->orig_writefn
= src_reg
->writefn
?: raw_write
;
5914 if (!src_reg
->raw_readfn
) {
5915 src_reg
->raw_readfn
= raw_read
;
5917 if (!src_reg
->raw_writefn
) {
5918 src_reg
->raw_writefn
= raw_write
;
5920 src_reg
->readfn
= el2_e2h_read
;
5921 src_reg
->writefn
= el2_e2h_write
;
5926 static CPAccessResult
ctr_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5929 int cur_el
= arm_current_el(env
);
5932 uint64_t hcr
= arm_hcr_el2_eff(env
);
5935 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
5936 if (!(env
->cp15
.sctlr_el
[2] & SCTLR_UCT
)) {
5937 return CP_ACCESS_TRAP_EL2
;
5940 if (!(env
->cp15
.sctlr_el
[1] & SCTLR_UCT
)) {
5941 return CP_ACCESS_TRAP
;
5943 if (hcr
& HCR_TID2
) {
5944 return CP_ACCESS_TRAP_EL2
;
5947 } else if (hcr
& HCR_TID2
) {
5948 return CP_ACCESS_TRAP_EL2
;
5952 if (arm_current_el(env
) < 2 && arm_hcr_el2_eff(env
) & HCR_TID2
) {
5953 return CP_ACCESS_TRAP_EL2
;
5956 return CP_ACCESS_OK
;
5959 static void oslar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5962 /* Writes to OSLAR_EL1 may update the OS lock status, which can be
5963 * read via a bit in OSLSR_EL1.
5967 if (ri
->state
== ARM_CP_STATE_AA32
) {
5968 oslock
= (value
== 0xC5ACCE55);
5973 env
->cp15
.oslsr_el1
= deposit32(env
->cp15
.oslsr_el1
, 1, 1, oslock
);
5976 static const ARMCPRegInfo debug_cp_reginfo
[] = {
5977 /* DBGDRAR, DBGDSAR: always RAZ since we don't implement memory mapped
5978 * debug components. The AArch64 version of DBGDRAR is named MDRAR_EL1;
5979 * unlike DBGDRAR it is never accessible from EL0.
5980 * DBGDSAR is deprecated and must RAZ from v8 anyway, so it has no AArch64
5983 { .name
= "DBGDRAR", .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 0,
5984 .access
= PL0_R
, .accessfn
= access_tdra
,
5985 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5986 { .name
= "MDRAR_EL1", .state
= ARM_CP_STATE_AA64
,
5987 .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 0,
5988 .access
= PL1_R
, .accessfn
= access_tdra
,
5989 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5990 { .name
= "DBGDSAR", .cp
= 14, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 0,
5991 .access
= PL0_R
, .accessfn
= access_tdra
,
5992 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5993 /* Monitor debug system control register; the 32-bit alias is DBGDSCRext. */
5994 { .name
= "MDSCR_EL1", .state
= ARM_CP_STATE_BOTH
,
5995 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 2,
5996 .access
= PL1_RW
, .accessfn
= access_tda
,
5997 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdscr_el1
),
6000 * MDCCSR_EL0[30:29] map to EDSCR[30:29]. Simply RAZ as the external
6001 * Debug Communication Channel is not implemented.
6003 { .name
= "MDCCSR_EL0", .state
= ARM_CP_STATE_AA64
,
6004 .opc0
= 2, .opc1
= 3, .crn
= 0, .crm
= 1, .opc2
= 0,
6005 .access
= PL0_R
, .accessfn
= access_tda
,
6006 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6008 * DBGDSCRint[15,12,5:2] map to MDSCR_EL1[15,12,5:2]. Map all bits as
6009 * it is unlikely a guest will care.
6010 * We don't implement the configurable EL0 access.
6012 { .name
= "DBGDSCRint", .state
= ARM_CP_STATE_AA32
,
6013 .cp
= 14, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 0,
6014 .type
= ARM_CP_ALIAS
,
6015 .access
= PL1_R
, .accessfn
= access_tda
,
6016 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdscr_el1
), },
6017 { .name
= "OSLAR_EL1", .state
= ARM_CP_STATE_BOTH
,
6018 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 4,
6019 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6020 .accessfn
= access_tdosa
,
6021 .writefn
= oslar_write
},
6022 { .name
= "OSLSR_EL1", .state
= ARM_CP_STATE_BOTH
,
6023 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 4,
6024 .access
= PL1_R
, .resetvalue
= 10,
6025 .accessfn
= access_tdosa
,
6026 .fieldoffset
= offsetof(CPUARMState
, cp15
.oslsr_el1
) },
6027 /* Dummy OSDLR_EL1: 32-bit Linux will read this */
6028 { .name
= "OSDLR_EL1", .state
= ARM_CP_STATE_BOTH
,
6029 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 3, .opc2
= 4,
6030 .access
= PL1_RW
, .accessfn
= access_tdosa
,
6031 .type
= ARM_CP_NOP
},
6032 /* Dummy DBGVCR: Linux wants to clear this on startup, but we don't
6033 * implement vector catch debug events yet.
6036 .cp
= 14, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 0,
6037 .access
= PL1_RW
, .accessfn
= access_tda
,
6038 .type
= ARM_CP_NOP
},
6039 /* Dummy DBGVCR32_EL2 (which is only for a 64-bit hypervisor
6040 * to save and restore a 32-bit guest's DBGVCR)
6042 { .name
= "DBGVCR32_EL2", .state
= ARM_CP_STATE_AA64
,
6043 .opc0
= 2, .opc1
= 4, .crn
= 0, .crm
= 7, .opc2
= 0,
6044 .access
= PL2_RW
, .accessfn
= access_tda
,
6045 .type
= ARM_CP_NOP
| ARM_CP_EL3_NO_EL2_KEEP
},
6046 /* Dummy MDCCINT_EL1, since we don't implement the Debug Communications
6047 * Channel but Linux may try to access this register. The 32-bit
6048 * alias is DBGDCCINT.
6050 { .name
= "MDCCINT_EL1", .state
= ARM_CP_STATE_BOTH
,
6051 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 0,
6052 .access
= PL1_RW
, .accessfn
= access_tda
,
6053 .type
= ARM_CP_NOP
},
6056 static const ARMCPRegInfo debug_lpae_cp_reginfo
[] = {
6057 /* 64 bit access versions of the (dummy) debug registers */
6058 { .name
= "DBGDRAR", .cp
= 14, .crm
= 1, .opc1
= 0,
6059 .access
= PL0_R
, .type
= ARM_CP_CONST
|ARM_CP_64BIT
, .resetvalue
= 0 },
6060 { .name
= "DBGDSAR", .cp
= 14, .crm
= 2, .opc1
= 0,
6061 .access
= PL0_R
, .type
= ARM_CP_CONST
|ARM_CP_64BIT
, .resetvalue
= 0 },
6065 * Check for traps to RAS registers, which are controlled
6066 * by HCR_EL2.TERR and SCR_EL3.TERR.
6068 static CPAccessResult
access_terr(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6071 int el
= arm_current_el(env
);
6073 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_TERR
)) {
6074 return CP_ACCESS_TRAP_EL2
;
6076 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_TERR
)) {
6077 return CP_ACCESS_TRAP_EL3
;
6079 return CP_ACCESS_OK
;
6082 static uint64_t disr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6084 int el
= arm_current_el(env
);
6086 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_AMO
)) {
6087 return env
->cp15
.vdisr_el2
;
6089 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_EA
)) {
6090 return 0; /* RAZ/WI */
6092 return env
->cp15
.disr_el1
;
6095 static void disr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
6097 int el
= arm_current_el(env
);
6099 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_AMO
)) {
6100 env
->cp15
.vdisr_el2
= val
;
6103 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_EA
)) {
6104 return; /* RAZ/WI */
6106 env
->cp15
.disr_el1
= val
;
6110 * Minimal RAS implementation with no Error Records.
6111 * Which means that all of the Error Record registers:
6119 * ERXPFGCDN_EL1 (RASv1p1)
6120 * ERXPFGCTL_EL1 (RASv1p1)
6121 * ERXPFGF_EL1 (RASv1p1)
6125 * may generate UNDEFINED, which is the effect we get by not
6126 * listing them at all.
6128 static const ARMCPRegInfo minimal_ras_reginfo
[] = {
6129 { .name
= "DISR_EL1", .state
= ARM_CP_STATE_BOTH
,
6130 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 1, .opc2
= 1,
6131 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.disr_el1
),
6132 .readfn
= disr_read
, .writefn
= disr_write
, .raw_writefn
= raw_write
},
6133 { .name
= "ERRIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
6134 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 3, .opc2
= 0,
6135 .access
= PL1_R
, .accessfn
= access_terr
,
6136 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6137 { .name
= "VDISR_EL2", .state
= ARM_CP_STATE_BOTH
,
6138 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 1, .opc2
= 1,
6139 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.vdisr_el2
) },
6140 { .name
= "VSESR_EL2", .state
= ARM_CP_STATE_BOTH
,
6141 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 2, .opc2
= 3,
6142 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.vsesr_el2
) },
6145 /* Return the exception level to which exceptions should be taken
6146 * via SVEAccessTrap. If an exception should be routed through
6147 * AArch64.AdvSIMDFPAccessTrap, return 0; fp_exception_el should
6148 * take care of raising that exception.
6149 * C.f. the ARM pseudocode function CheckSVEEnabled.
6151 int sve_exception_el(CPUARMState
*env
, int el
)
6153 #ifndef CONFIG_USER_ONLY
6154 uint64_t hcr_el2
= arm_hcr_el2_eff(env
);
6156 if (el
<= 1 && (hcr_el2
& (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
6157 switch (FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, ZEN
)) {
6166 return hcr_el2
& HCR_TGE
? 2 : 1;
6169 /* Check CPACR.FPEN. */
6170 switch (FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, FPEN
)) {
6183 * CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE).
6186 if (hcr_el2
& HCR_E2H
) {
6187 switch (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, ZEN
)) {
6189 if (el
!= 0 || !(hcr_el2
& HCR_TGE
)) {
6198 switch (FIELD_EX32(env
->cp15
.cptr_el
[2], CPTR_EL2
, FPEN
)) {
6200 if (el
== 2 || !(hcr_el2
& HCR_TGE
)) {
6208 } else if (arm_is_el2_enabled(env
)) {
6209 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TZ
)) {
6212 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TFP
)) {
6218 /* CPTR_EL3. Since EZ is negative we must check for EL3. */
6219 if (arm_feature(env
, ARM_FEATURE_EL3
)
6220 && !FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, EZ
)) {
6227 uint32_t aarch64_sve_zcr_get_valid_len(ARMCPU
*cpu
, uint32_t start_len
)
6231 start_len
= MIN(start_len
, ARM_MAX_VQ
- 1);
6232 end_len
= start_len
;
6234 if (!test_bit(start_len
, cpu
->sve_vq_map
)) {
6235 end_len
= find_last_bit(cpu
->sve_vq_map
, start_len
);
6236 assert(end_len
< start_len
);
6242 * Given that SVE is enabled, return the vector length for EL.
6244 uint32_t sve_zcr_len_for_el(CPUARMState
*env
, int el
)
6246 ARMCPU
*cpu
= env_archcpu(env
);
6247 uint32_t zcr_len
= cpu
->sve_max_vq
- 1;
6250 (arm_hcr_el2_eff(env
) & (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
6251 zcr_len
= MIN(zcr_len
, 0xf & (uint32_t)env
->vfp
.zcr_el
[1]);
6253 if (el
<= 2 && arm_feature(env
, ARM_FEATURE_EL2
)) {
6254 zcr_len
= MIN(zcr_len
, 0xf & (uint32_t)env
->vfp
.zcr_el
[2]);
6256 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
6257 zcr_len
= MIN(zcr_len
, 0xf & (uint32_t)env
->vfp
.zcr_el
[3]);
6260 return aarch64_sve_zcr_get_valid_len(cpu
, zcr_len
);
6263 static void zcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6266 int cur_el
= arm_current_el(env
);
6267 int old_len
= sve_zcr_len_for_el(env
, cur_el
);
6270 /* Bits other than [3:0] are RAZ/WI. */
6271 QEMU_BUILD_BUG_ON(ARM_MAX_VQ
> 16);
6272 raw_write(env
, ri
, value
& 0xf);
6275 * Because we arrived here, we know both FP and SVE are enabled;
6276 * otherwise we would have trapped access to the ZCR_ELn register.
6278 new_len
= sve_zcr_len_for_el(env
, cur_el
);
6279 if (new_len
< old_len
) {
6280 aarch64_sve_narrow_vq(env
, new_len
+ 1);
6284 static const ARMCPRegInfo zcr_reginfo
[] = {
6285 { .name
= "ZCR_EL1", .state
= ARM_CP_STATE_AA64
,
6286 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 2, .opc2
= 0,
6287 .access
= PL1_RW
, .type
= ARM_CP_SVE
,
6288 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[1]),
6289 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
6290 { .name
= "ZCR_EL2", .state
= ARM_CP_STATE_AA64
,
6291 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 0,
6292 .access
= PL2_RW
, .type
= ARM_CP_SVE
,
6293 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[2]),
6294 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
6295 { .name
= "ZCR_EL3", .state
= ARM_CP_STATE_AA64
,
6296 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 2, .opc2
= 0,
6297 .access
= PL3_RW
, .type
= ARM_CP_SVE
,
6298 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[3]),
6299 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
6302 void hw_watchpoint_update(ARMCPU
*cpu
, int n
)
6304 CPUARMState
*env
= &cpu
->env
;
6306 vaddr wvr
= env
->cp15
.dbgwvr
[n
];
6307 uint64_t wcr
= env
->cp15
.dbgwcr
[n
];
6309 int flags
= BP_CPU
| BP_STOP_BEFORE_ACCESS
;
6311 if (env
->cpu_watchpoint
[n
]) {
6312 cpu_watchpoint_remove_by_ref(CPU(cpu
), env
->cpu_watchpoint
[n
]);
6313 env
->cpu_watchpoint
[n
] = NULL
;
6316 if (!FIELD_EX64(wcr
, DBGWCR
, E
)) {
6317 /* E bit clear : watchpoint disabled */
6321 switch (FIELD_EX64(wcr
, DBGWCR
, LSC
)) {
6323 /* LSC 00 is reserved and must behave as if the wp is disabled */
6326 flags
|= BP_MEM_READ
;
6329 flags
|= BP_MEM_WRITE
;
6332 flags
|= BP_MEM_ACCESS
;
6336 /* Attempts to use both MASK and BAS fields simultaneously are
6337 * CONSTRAINED UNPREDICTABLE; we opt to ignore BAS in this case,
6338 * thus generating a watchpoint for every byte in the masked region.
6340 mask
= FIELD_EX64(wcr
, DBGWCR
, MASK
);
6341 if (mask
== 1 || mask
== 2) {
6342 /* Reserved values of MASK; we must act as if the mask value was
6343 * some non-reserved value, or as if the watchpoint were disabled.
6344 * We choose the latter.
6348 /* Watchpoint covers an aligned area up to 2GB in size */
6350 /* If masked bits in WVR are not zero it's CONSTRAINED UNPREDICTABLE
6351 * whether the watchpoint fires when the unmasked bits match; we opt
6352 * to generate the exceptions.
6356 /* Watchpoint covers bytes defined by the byte address select bits */
6357 int bas
= FIELD_EX64(wcr
, DBGWCR
, BAS
);
6360 if (extract64(wvr
, 2, 1)) {
6361 /* Deprecated case of an only 4-aligned address. BAS[7:4] are
6362 * ignored, and BAS[3:0] define which bytes to watch.
6368 /* This must act as if the watchpoint is disabled */
6372 /* The BAS bits are supposed to be programmed to indicate a contiguous
6373 * range of bytes. Otherwise it is CONSTRAINED UNPREDICTABLE whether
6374 * we fire for each byte in the word/doubleword addressed by the WVR.
6375 * We choose to ignore any non-zero bits after the first range of 1s.
6377 basstart
= ctz32(bas
);
6378 len
= cto32(bas
>> basstart
);
6382 cpu_watchpoint_insert(CPU(cpu
), wvr
, len
, flags
,
6383 &env
->cpu_watchpoint
[n
]);
6386 void hw_watchpoint_update_all(ARMCPU
*cpu
)
6389 CPUARMState
*env
= &cpu
->env
;
6391 /* Completely clear out existing QEMU watchpoints and our array, to
6392 * avoid possible stale entries following migration load.
6394 cpu_watchpoint_remove_all(CPU(cpu
), BP_CPU
);
6395 memset(env
->cpu_watchpoint
, 0, sizeof(env
->cpu_watchpoint
));
6397 for (i
= 0; i
< ARRAY_SIZE(cpu
->env
.cpu_watchpoint
); i
++) {
6398 hw_watchpoint_update(cpu
, i
);
6402 static void dbgwvr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6405 ARMCPU
*cpu
= env_archcpu(env
);
6409 * Bits [1:0] are RES0.
6411 * It is IMPLEMENTATION DEFINED whether [63:49] ([63:53] with FEAT_LVA)
6412 * are hardwired to the value of bit [48] ([52] with FEAT_LVA), or if
6413 * they contain the value written. It is CONSTRAINED UNPREDICTABLE
6414 * whether the RESS bits are ignored when comparing an address.
6416 * Therefore we are allowed to compare the entire register, which lets
6417 * us avoid considering whether or not FEAT_LVA is actually enabled.
6421 raw_write(env
, ri
, value
);
6422 hw_watchpoint_update(cpu
, i
);
6425 static void dbgwcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6428 ARMCPU
*cpu
= env_archcpu(env
);
6431 raw_write(env
, ri
, value
);
6432 hw_watchpoint_update(cpu
, i
);
6435 void hw_breakpoint_update(ARMCPU
*cpu
, int n
)
6437 CPUARMState
*env
= &cpu
->env
;
6438 uint64_t bvr
= env
->cp15
.dbgbvr
[n
];
6439 uint64_t bcr
= env
->cp15
.dbgbcr
[n
];
6444 if (env
->cpu_breakpoint
[n
]) {
6445 cpu_breakpoint_remove_by_ref(CPU(cpu
), env
->cpu_breakpoint
[n
]);
6446 env
->cpu_breakpoint
[n
] = NULL
;
6449 if (!extract64(bcr
, 0, 1)) {
6450 /* E bit clear : watchpoint disabled */
6454 bt
= extract64(bcr
, 20, 4);
6457 case 4: /* unlinked address mismatch (reserved if AArch64) */
6458 case 5: /* linked address mismatch (reserved if AArch64) */
6459 qemu_log_mask(LOG_UNIMP
,
6460 "arm: address mismatch breakpoint types not implemented\n");
6462 case 0: /* unlinked address match */
6463 case 1: /* linked address match */
6466 * Bits [1:0] are RES0.
6468 * It is IMPLEMENTATION DEFINED whether bits [63:49]
6469 * ([63:53] for FEAT_LVA) are hardwired to a copy of the sign bit
6470 * of the VA field ([48] or [52] for FEAT_LVA), or whether the
6471 * value is read as written. It is CONSTRAINED UNPREDICTABLE
6472 * whether the RESS bits are ignored when comparing an address.
6473 * Therefore we are allowed to compare the entire register, which
6474 * lets us avoid considering whether FEAT_LVA is actually enabled.
6476 * The BAS field is used to allow setting breakpoints on 16-bit
6477 * wide instructions; it is CONSTRAINED UNPREDICTABLE whether
6478 * a bp will fire if the addresses covered by the bp and the addresses
6479 * covered by the insn overlap but the insn doesn't start at the
6480 * start of the bp address range. We choose to require the insn and
6481 * the bp to have the same address. The constraints on writing to
6482 * BAS enforced in dbgbcr_write mean we have only four cases:
6483 * 0b0000 => no breakpoint
6484 * 0b0011 => breakpoint on addr
6485 * 0b1100 => breakpoint on addr + 2
6486 * 0b1111 => breakpoint on addr
6487 * See also figure D2-3 in the v8 ARM ARM (DDI0487A.c).
6489 int bas
= extract64(bcr
, 5, 4);
6499 case 2: /* unlinked context ID match */
6500 case 8: /* unlinked VMID match (reserved if no EL2) */
6501 case 10: /* unlinked context ID and VMID match (reserved if no EL2) */
6502 qemu_log_mask(LOG_UNIMP
,
6503 "arm: unlinked context breakpoint types not implemented\n");
6505 case 9: /* linked VMID match (reserved if no EL2) */
6506 case 11: /* linked context ID and VMID match (reserved if no EL2) */
6507 case 3: /* linked context ID match */
6509 /* We must generate no events for Linked context matches (unless
6510 * they are linked to by some other bp/wp, which is handled in
6511 * updates for the linking bp/wp). We choose to also generate no events
6512 * for reserved values.
6517 cpu_breakpoint_insert(CPU(cpu
), addr
, flags
, &env
->cpu_breakpoint
[n
]);
6520 void hw_breakpoint_update_all(ARMCPU
*cpu
)
6523 CPUARMState
*env
= &cpu
->env
;
6525 /* Completely clear out existing QEMU breakpoints and our array, to
6526 * avoid possible stale entries following migration load.
6528 cpu_breakpoint_remove_all(CPU(cpu
), BP_CPU
);
6529 memset(env
->cpu_breakpoint
, 0, sizeof(env
->cpu_breakpoint
));
6531 for (i
= 0; i
< ARRAY_SIZE(cpu
->env
.cpu_breakpoint
); i
++) {
6532 hw_breakpoint_update(cpu
, i
);
6536 static void dbgbvr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6539 ARMCPU
*cpu
= env_archcpu(env
);
6542 raw_write(env
, ri
, value
);
6543 hw_breakpoint_update(cpu
, i
);
6546 static void dbgbcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6549 ARMCPU
*cpu
= env_archcpu(env
);
6552 /* BAS[3] is a read-only copy of BAS[2], and BAS[1] a read-only
6555 value
= deposit64(value
, 6, 1, extract64(value
, 5, 1));
6556 value
= deposit64(value
, 8, 1, extract64(value
, 7, 1));
6558 raw_write(env
, ri
, value
);
6559 hw_breakpoint_update(cpu
, i
);
6562 static void define_debug_regs(ARMCPU
*cpu
)
6564 /* Define v7 and v8 architectural debug registers.
6565 * These are just dummy implementations for now.
6568 int wrps
, brps
, ctx_cmps
;
6571 * The Arm ARM says DBGDIDR is optional and deprecated if EL1 cannot
6572 * use AArch32. Given that bit 15 is RES1, if the value is 0 then
6573 * the register must not exist for this cpu.
6575 if (cpu
->isar
.dbgdidr
!= 0) {
6576 ARMCPRegInfo dbgdidr
= {
6577 .name
= "DBGDIDR", .cp
= 14, .crn
= 0, .crm
= 0,
6578 .opc1
= 0, .opc2
= 0,
6579 .access
= PL0_R
, .accessfn
= access_tda
,
6580 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->isar
.dbgdidr
,
6582 define_one_arm_cp_reg(cpu
, &dbgdidr
);
6585 brps
= arm_num_brps(cpu
);
6586 wrps
= arm_num_wrps(cpu
);
6587 ctx_cmps
= arm_num_ctx_cmps(cpu
);
6589 assert(ctx_cmps
<= brps
);
6591 define_arm_cp_regs(cpu
, debug_cp_reginfo
);
6593 if (arm_feature(&cpu
->env
, ARM_FEATURE_LPAE
)) {
6594 define_arm_cp_regs(cpu
, debug_lpae_cp_reginfo
);
6597 for (i
= 0; i
< brps
; i
++) {
6598 char *dbgbvr_el1_name
= g_strdup_printf("DBGBVR%d_EL1", i
);
6599 char *dbgbcr_el1_name
= g_strdup_printf("DBGBCR%d_EL1", i
);
6600 ARMCPRegInfo dbgregs
[] = {
6601 { .name
= dbgbvr_el1_name
, .state
= ARM_CP_STATE_BOTH
,
6602 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 4,
6603 .access
= PL1_RW
, .accessfn
= access_tda
,
6604 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgbvr
[i
]),
6605 .writefn
= dbgbvr_write
, .raw_writefn
= raw_write
6607 { .name
= dbgbcr_el1_name
, .state
= ARM_CP_STATE_BOTH
,
6608 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 5,
6609 .access
= PL1_RW
, .accessfn
= access_tda
,
6610 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgbcr
[i
]),
6611 .writefn
= dbgbcr_write
, .raw_writefn
= raw_write
6614 define_arm_cp_regs(cpu
, dbgregs
);
6615 g_free(dbgbvr_el1_name
);
6616 g_free(dbgbcr_el1_name
);
6619 for (i
= 0; i
< wrps
; i
++) {
6620 char *dbgwvr_el1_name
= g_strdup_printf("DBGWVR%d_EL1", i
);
6621 char *dbgwcr_el1_name
= g_strdup_printf("DBGWCR%d_EL1", i
);
6622 ARMCPRegInfo dbgregs
[] = {
6623 { .name
= dbgwvr_el1_name
, .state
= ARM_CP_STATE_BOTH
,
6624 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 6,
6625 .access
= PL1_RW
, .accessfn
= access_tda
,
6626 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgwvr
[i
]),
6627 .writefn
= dbgwvr_write
, .raw_writefn
= raw_write
6629 { .name
= dbgwcr_el1_name
, .state
= ARM_CP_STATE_BOTH
,
6630 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 7,
6631 .access
= PL1_RW
, .accessfn
= access_tda
,
6632 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgwcr
[i
]),
6633 .writefn
= dbgwcr_write
, .raw_writefn
= raw_write
6636 define_arm_cp_regs(cpu
, dbgregs
);
6637 g_free(dbgwvr_el1_name
);
6638 g_free(dbgwcr_el1_name
);
6642 static void define_pmu_regs(ARMCPU
*cpu
)
6645 * v7 performance monitor control register: same implementor
6646 * field as main ID register, and we implement four counters in
6647 * addition to the cycle count register.
6649 unsigned int i
, pmcrn
= pmu_num_counters(&cpu
->env
);
6650 ARMCPRegInfo pmcr
= {
6651 .name
= "PMCR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 0,
6653 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
6654 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcr
),
6655 .accessfn
= pmreg_access
, .writefn
= pmcr_write
,
6656 .raw_writefn
= raw_write
,
6658 ARMCPRegInfo pmcr64
= {
6659 .name
= "PMCR_EL0", .state
= ARM_CP_STATE_AA64
,
6660 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 0,
6661 .access
= PL0_RW
, .accessfn
= pmreg_access
,
6663 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcr
),
6664 .resetvalue
= cpu
->isar
.reset_pmcr_el0
,
6665 .writefn
= pmcr_write
, .raw_writefn
= raw_write
,
6668 define_one_arm_cp_reg(cpu
, &pmcr
);
6669 define_one_arm_cp_reg(cpu
, &pmcr64
);
6670 for (i
= 0; i
< pmcrn
; i
++) {
6671 char *pmevcntr_name
= g_strdup_printf("PMEVCNTR%d", i
);
6672 char *pmevcntr_el0_name
= g_strdup_printf("PMEVCNTR%d_EL0", i
);
6673 char *pmevtyper_name
= g_strdup_printf("PMEVTYPER%d", i
);
6674 char *pmevtyper_el0_name
= g_strdup_printf("PMEVTYPER%d_EL0", i
);
6675 ARMCPRegInfo pmev_regs
[] = {
6676 { .name
= pmevcntr_name
, .cp
= 15, .crn
= 14,
6677 .crm
= 8 | (3 & (i
>> 3)), .opc1
= 0, .opc2
= i
& 7,
6678 .access
= PL0_RW
, .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
6679 .readfn
= pmevcntr_readfn
, .writefn
= pmevcntr_writefn
,
6680 .accessfn
= pmreg_access_xevcntr
},
6681 { .name
= pmevcntr_el0_name
, .state
= ARM_CP_STATE_AA64
,
6682 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 8 | (3 & (i
>> 3)),
6683 .opc2
= i
& 7, .access
= PL0_RW
, .accessfn
= pmreg_access_xevcntr
,
6685 .readfn
= pmevcntr_readfn
, .writefn
= pmevcntr_writefn
,
6686 .raw_readfn
= pmevcntr_rawread
,
6687 .raw_writefn
= pmevcntr_rawwrite
},
6688 { .name
= pmevtyper_name
, .cp
= 15, .crn
= 14,
6689 .crm
= 12 | (3 & (i
>> 3)), .opc1
= 0, .opc2
= i
& 7,
6690 .access
= PL0_RW
, .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
6691 .readfn
= pmevtyper_readfn
, .writefn
= pmevtyper_writefn
,
6692 .accessfn
= pmreg_access
},
6693 { .name
= pmevtyper_el0_name
, .state
= ARM_CP_STATE_AA64
,
6694 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 12 | (3 & (i
>> 3)),
6695 .opc2
= i
& 7, .access
= PL0_RW
, .accessfn
= pmreg_access
,
6697 .readfn
= pmevtyper_readfn
, .writefn
= pmevtyper_writefn
,
6698 .raw_writefn
= pmevtyper_rawwrite
},
6700 define_arm_cp_regs(cpu
, pmev_regs
);
6701 g_free(pmevcntr_name
);
6702 g_free(pmevcntr_el0_name
);
6703 g_free(pmevtyper_name
);
6704 g_free(pmevtyper_el0_name
);
6706 if (cpu_isar_feature(aa32_pmu_8_1
, cpu
)) {
6707 ARMCPRegInfo v81_pmu_regs
[] = {
6708 { .name
= "PMCEID2", .state
= ARM_CP_STATE_AA32
,
6709 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 4,
6710 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
6711 .resetvalue
= extract64(cpu
->pmceid0
, 32, 32) },
6712 { .name
= "PMCEID3", .state
= ARM_CP_STATE_AA32
,
6713 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 5,
6714 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
6715 .resetvalue
= extract64(cpu
->pmceid1
, 32, 32) },
6717 define_arm_cp_regs(cpu
, v81_pmu_regs
);
6719 if (cpu_isar_feature(any_pmu_8_4
, cpu
)) {
6720 static const ARMCPRegInfo v84_pmmir
= {
6721 .name
= "PMMIR_EL1", .state
= ARM_CP_STATE_BOTH
,
6722 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 6,
6723 .access
= PL1_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
6726 define_one_arm_cp_reg(cpu
, &v84_pmmir
);
6730 /* We don't know until after realize whether there's a GICv3
6731 * attached, and that is what registers the gicv3 sysregs.
6732 * So we have to fill in the GIC fields in ID_PFR/ID_PFR1_EL1/ID_AA64PFR0_EL1
6735 static uint64_t id_pfr1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6737 ARMCPU
*cpu
= env_archcpu(env
);
6738 uint64_t pfr1
= cpu
->isar
.id_pfr1
;
6740 if (env
->gicv3state
) {
6746 #ifndef CONFIG_USER_ONLY
6747 static uint64_t id_aa64pfr0_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6749 ARMCPU
*cpu
= env_archcpu(env
);
6750 uint64_t pfr0
= cpu
->isar
.id_aa64pfr0
;
6752 if (env
->gicv3state
) {
6759 /* Shared logic between LORID and the rest of the LOR* registers.
6760 * Secure state exclusion has already been dealt with.
6762 static CPAccessResult
access_lor_ns(CPUARMState
*env
,
6763 const ARMCPRegInfo
*ri
, bool isread
)
6765 int el
= arm_current_el(env
);
6767 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_TLOR
)) {
6768 return CP_ACCESS_TRAP_EL2
;
6770 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_TLOR
)) {
6771 return CP_ACCESS_TRAP_EL3
;
6773 return CP_ACCESS_OK
;
6776 static CPAccessResult
access_lor_other(CPUARMState
*env
,
6777 const ARMCPRegInfo
*ri
, bool isread
)
6779 if (arm_is_secure_below_el3(env
)) {
6780 /* Access denied in secure mode. */
6781 return CP_ACCESS_TRAP
;
6783 return access_lor_ns(env
, ri
, isread
);
6787 * A trivial implementation of ARMv8.1-LOR leaves all of these
6788 * registers fixed at 0, which indicates that there are zero
6789 * supported Limited Ordering regions.
6791 static const ARMCPRegInfo lor_reginfo
[] = {
6792 { .name
= "LORSA_EL1", .state
= ARM_CP_STATE_AA64
,
6793 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 0,
6794 .access
= PL1_RW
, .accessfn
= access_lor_other
,
6795 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6796 { .name
= "LOREA_EL1", .state
= ARM_CP_STATE_AA64
,
6797 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 1,
6798 .access
= PL1_RW
, .accessfn
= access_lor_other
,
6799 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6800 { .name
= "LORN_EL1", .state
= ARM_CP_STATE_AA64
,
6801 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 2,
6802 .access
= PL1_RW
, .accessfn
= access_lor_other
,
6803 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6804 { .name
= "LORC_EL1", .state
= ARM_CP_STATE_AA64
,
6805 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 3,
6806 .access
= PL1_RW
, .accessfn
= access_lor_other
,
6807 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6808 { .name
= "LORID_EL1", .state
= ARM_CP_STATE_AA64
,
6809 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 7,
6810 .access
= PL1_R
, .accessfn
= access_lor_ns
,
6811 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6814 #ifdef TARGET_AARCH64
6815 static CPAccessResult
access_pauth(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6818 int el
= arm_current_el(env
);
6821 arm_is_el2_enabled(env
) &&
6822 !(arm_hcr_el2_eff(env
) & HCR_APK
)) {
6823 return CP_ACCESS_TRAP_EL2
;
6826 arm_feature(env
, ARM_FEATURE_EL3
) &&
6827 !(env
->cp15
.scr_el3
& SCR_APK
)) {
6828 return CP_ACCESS_TRAP_EL3
;
6830 return CP_ACCESS_OK
;
6833 static const ARMCPRegInfo pauth_reginfo
[] = {
6834 { .name
= "APDAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
6835 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 0,
6836 .access
= PL1_RW
, .accessfn
= access_pauth
,
6837 .fieldoffset
= offsetof(CPUARMState
, keys
.apda
.lo
) },
6838 { .name
= "APDAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
6839 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 1,
6840 .access
= PL1_RW
, .accessfn
= access_pauth
,
6841 .fieldoffset
= offsetof(CPUARMState
, keys
.apda
.hi
) },
6842 { .name
= "APDBKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
6843 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 2,
6844 .access
= PL1_RW
, .accessfn
= access_pauth
,
6845 .fieldoffset
= offsetof(CPUARMState
, keys
.apdb
.lo
) },
6846 { .name
= "APDBKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
6847 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 3,
6848 .access
= PL1_RW
, .accessfn
= access_pauth
,
6849 .fieldoffset
= offsetof(CPUARMState
, keys
.apdb
.hi
) },
6850 { .name
= "APGAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
6851 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 3, .opc2
= 0,
6852 .access
= PL1_RW
, .accessfn
= access_pauth
,
6853 .fieldoffset
= offsetof(CPUARMState
, keys
.apga
.lo
) },
6854 { .name
= "APGAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
6855 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 3, .opc2
= 1,
6856 .access
= PL1_RW
, .accessfn
= access_pauth
,
6857 .fieldoffset
= offsetof(CPUARMState
, keys
.apga
.hi
) },
6858 { .name
= "APIAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
6859 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 0,
6860 .access
= PL1_RW
, .accessfn
= access_pauth
,
6861 .fieldoffset
= offsetof(CPUARMState
, keys
.apia
.lo
) },
6862 { .name
= "APIAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
6863 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 1,
6864 .access
= PL1_RW
, .accessfn
= access_pauth
,
6865 .fieldoffset
= offsetof(CPUARMState
, keys
.apia
.hi
) },
6866 { .name
= "APIBKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
6867 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 2,
6868 .access
= PL1_RW
, .accessfn
= access_pauth
,
6869 .fieldoffset
= offsetof(CPUARMState
, keys
.apib
.lo
) },
6870 { .name
= "APIBKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
6871 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 3,
6872 .access
= PL1_RW
, .accessfn
= access_pauth
,
6873 .fieldoffset
= offsetof(CPUARMState
, keys
.apib
.hi
) },
6876 static const ARMCPRegInfo tlbirange_reginfo
[] = {
6877 { .name
= "TLBI_RVAE1IS", .state
= ARM_CP_STATE_AA64
,
6878 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 1,
6879 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6880 .writefn
= tlbi_aa64_rvae1is_write
},
6881 { .name
= "TLBI_RVAAE1IS", .state
= ARM_CP_STATE_AA64
,
6882 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 3,
6883 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6884 .writefn
= tlbi_aa64_rvae1is_write
},
6885 { .name
= "TLBI_RVALE1IS", .state
= ARM_CP_STATE_AA64
,
6886 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 5,
6887 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6888 .writefn
= tlbi_aa64_rvae1is_write
},
6889 { .name
= "TLBI_RVAALE1IS", .state
= ARM_CP_STATE_AA64
,
6890 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 7,
6891 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6892 .writefn
= tlbi_aa64_rvae1is_write
},
6893 { .name
= "TLBI_RVAE1OS", .state
= ARM_CP_STATE_AA64
,
6894 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
6895 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6896 .writefn
= tlbi_aa64_rvae1is_write
},
6897 { .name
= "TLBI_RVAAE1OS", .state
= ARM_CP_STATE_AA64
,
6898 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 3,
6899 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6900 .writefn
= tlbi_aa64_rvae1is_write
},
6901 { .name
= "TLBI_RVALE1OS", .state
= ARM_CP_STATE_AA64
,
6902 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 5,
6903 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6904 .writefn
= tlbi_aa64_rvae1is_write
},
6905 { .name
= "TLBI_RVAALE1OS", .state
= ARM_CP_STATE_AA64
,
6906 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 7,
6907 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6908 .writefn
= tlbi_aa64_rvae1is_write
},
6909 { .name
= "TLBI_RVAE1", .state
= ARM_CP_STATE_AA64
,
6910 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
6911 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6912 .writefn
= tlbi_aa64_rvae1_write
},
6913 { .name
= "TLBI_RVAAE1", .state
= ARM_CP_STATE_AA64
,
6914 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 3,
6915 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6916 .writefn
= tlbi_aa64_rvae1_write
},
6917 { .name
= "TLBI_RVALE1", .state
= ARM_CP_STATE_AA64
,
6918 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 5,
6919 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6920 .writefn
= tlbi_aa64_rvae1_write
},
6921 { .name
= "TLBI_RVAALE1", .state
= ARM_CP_STATE_AA64
,
6922 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 7,
6923 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6924 .writefn
= tlbi_aa64_rvae1_write
},
6925 { .name
= "TLBI_RIPAS2E1IS", .state
= ARM_CP_STATE_AA64
,
6926 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 2,
6927 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6928 { .name
= "TLBI_RIPAS2LE1IS", .state
= ARM_CP_STATE_AA64
,
6929 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 6,
6930 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6931 { .name
= "TLBI_RVAE2IS", .state
= ARM_CP_STATE_AA64
,
6932 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 2, .opc2
= 1,
6933 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6934 .writefn
= tlbi_aa64_rvae2is_write
},
6935 { .name
= "TLBI_RVALE2IS", .state
= ARM_CP_STATE_AA64
,
6936 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 2, .opc2
= 5,
6937 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6938 .writefn
= tlbi_aa64_rvae2is_write
},
6939 { .name
= "TLBI_RIPAS2E1", .state
= ARM_CP_STATE_AA64
,
6940 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 2,
6941 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6942 { .name
= "TLBI_RIPAS2LE1", .state
= ARM_CP_STATE_AA64
,
6943 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 6,
6944 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6945 { .name
= "TLBI_RVAE2OS", .state
= ARM_CP_STATE_AA64
,
6946 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 5, .opc2
= 1,
6947 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6948 .writefn
= tlbi_aa64_rvae2is_write
},
6949 { .name
= "TLBI_RVALE2OS", .state
= ARM_CP_STATE_AA64
,
6950 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 5, .opc2
= 5,
6951 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6952 .writefn
= tlbi_aa64_rvae2is_write
},
6953 { .name
= "TLBI_RVAE2", .state
= ARM_CP_STATE_AA64
,
6954 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 6, .opc2
= 1,
6955 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6956 .writefn
= tlbi_aa64_rvae2_write
},
6957 { .name
= "TLBI_RVALE2", .state
= ARM_CP_STATE_AA64
,
6958 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 6, .opc2
= 5,
6959 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6960 .writefn
= tlbi_aa64_rvae2_write
},
6961 { .name
= "TLBI_RVAE3IS", .state
= ARM_CP_STATE_AA64
,
6962 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 2, .opc2
= 1,
6963 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6964 .writefn
= tlbi_aa64_rvae3is_write
},
6965 { .name
= "TLBI_RVALE3IS", .state
= ARM_CP_STATE_AA64
,
6966 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 2, .opc2
= 5,
6967 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6968 .writefn
= tlbi_aa64_rvae3is_write
},
6969 { .name
= "TLBI_RVAE3OS", .state
= ARM_CP_STATE_AA64
,
6970 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 5, .opc2
= 1,
6971 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6972 .writefn
= tlbi_aa64_rvae3is_write
},
6973 { .name
= "TLBI_RVALE3OS", .state
= ARM_CP_STATE_AA64
,
6974 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 5, .opc2
= 5,
6975 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6976 .writefn
= tlbi_aa64_rvae3is_write
},
6977 { .name
= "TLBI_RVAE3", .state
= ARM_CP_STATE_AA64
,
6978 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 6, .opc2
= 1,
6979 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6980 .writefn
= tlbi_aa64_rvae3_write
},
6981 { .name
= "TLBI_RVALE3", .state
= ARM_CP_STATE_AA64
,
6982 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 6, .opc2
= 5,
6983 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6984 .writefn
= tlbi_aa64_rvae3_write
},
6987 static const ARMCPRegInfo tlbios_reginfo
[] = {
6988 { .name
= "TLBI_VMALLE1OS", .state
= ARM_CP_STATE_AA64
,
6989 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 0,
6990 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6991 .writefn
= tlbi_aa64_vmalle1is_write
},
6992 { .name
= "TLBI_VAE1OS", .state
= ARM_CP_STATE_AA64
,
6993 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 1,
6994 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6995 .writefn
= tlbi_aa64_vae1is_write
},
6996 { .name
= "TLBI_ASIDE1OS", .state
= ARM_CP_STATE_AA64
,
6997 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 2,
6998 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6999 .writefn
= tlbi_aa64_vmalle1is_write
},
7000 { .name
= "TLBI_VAAE1OS", .state
= ARM_CP_STATE_AA64
,
7001 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 3,
7002 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7003 .writefn
= tlbi_aa64_vae1is_write
},
7004 { .name
= "TLBI_VALE1OS", .state
= ARM_CP_STATE_AA64
,
7005 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 5,
7006 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7007 .writefn
= tlbi_aa64_vae1is_write
},
7008 { .name
= "TLBI_VAALE1OS", .state
= ARM_CP_STATE_AA64
,
7009 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 7,
7010 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
7011 .writefn
= tlbi_aa64_vae1is_write
},
7012 { .name
= "TLBI_ALLE2OS", .state
= ARM_CP_STATE_AA64
,
7013 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 0,
7014 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7015 .writefn
= tlbi_aa64_alle2is_write
},
7016 { .name
= "TLBI_VAE2OS", .state
= ARM_CP_STATE_AA64
,
7017 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 1,
7018 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7019 .writefn
= tlbi_aa64_vae2is_write
},
7020 { .name
= "TLBI_ALLE1OS", .state
= ARM_CP_STATE_AA64
,
7021 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 4,
7022 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7023 .writefn
= tlbi_aa64_alle1is_write
},
7024 { .name
= "TLBI_VALE2OS", .state
= ARM_CP_STATE_AA64
,
7025 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 5,
7026 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7027 .writefn
= tlbi_aa64_vae2is_write
},
7028 { .name
= "TLBI_VMALLS12E1OS", .state
= ARM_CP_STATE_AA64
,
7029 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 6,
7030 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7031 .writefn
= tlbi_aa64_alle1is_write
},
7032 { .name
= "TLBI_IPAS2E1OS", .state
= ARM_CP_STATE_AA64
,
7033 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 0,
7034 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7035 { .name
= "TLBI_RIPAS2E1OS", .state
= ARM_CP_STATE_AA64
,
7036 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 3,
7037 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7038 { .name
= "TLBI_IPAS2LE1OS", .state
= ARM_CP_STATE_AA64
,
7039 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 4,
7040 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7041 { .name
= "TLBI_RIPAS2LE1OS", .state
= ARM_CP_STATE_AA64
,
7042 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 7,
7043 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7044 { .name
= "TLBI_ALLE3OS", .state
= ARM_CP_STATE_AA64
,
7045 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 0,
7046 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7047 .writefn
= tlbi_aa64_alle3is_write
},
7048 { .name
= "TLBI_VAE3OS", .state
= ARM_CP_STATE_AA64
,
7049 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 1,
7050 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7051 .writefn
= tlbi_aa64_vae3is_write
},
7052 { .name
= "TLBI_VALE3OS", .state
= ARM_CP_STATE_AA64
,
7053 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 5,
7054 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7055 .writefn
= tlbi_aa64_vae3is_write
},
7058 static uint64_t rndr_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7063 /* Success sets NZCV = 0000. */
7064 env
->NF
= env
->CF
= env
->VF
= 0, env
->ZF
= 1;
7066 if (qemu_guest_getrandom(&ret
, sizeof(ret
), &err
) < 0) {
7068 * ??? Failed, for unknown reasons in the crypto subsystem.
7069 * The best we can do is log the reason and return the
7070 * timed-out indication to the guest. There is no reason
7071 * we know to expect this failure to be transitory, so the
7072 * guest may well hang retrying the operation.
7074 qemu_log_mask(LOG_UNIMP
, "%s: Crypto failure: %s",
7075 ri
->name
, error_get_pretty(err
));
7078 env
->ZF
= 0; /* NZCF = 0100 */
7084 /* We do not support re-seeding, so the two registers operate the same. */
7085 static const ARMCPRegInfo rndr_reginfo
[] = {
7086 { .name
= "RNDR", .state
= ARM_CP_STATE_AA64
,
7087 .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
| ARM_CP_IO
,
7088 .opc0
= 3, .opc1
= 3, .crn
= 2, .crm
= 4, .opc2
= 0,
7089 .access
= PL0_R
, .readfn
= rndr_readfn
},
7090 { .name
= "RNDRRS", .state
= ARM_CP_STATE_AA64
,
7091 .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
| ARM_CP_IO
,
7092 .opc0
= 3, .opc1
= 3, .crn
= 2, .crm
= 4, .opc2
= 1,
7093 .access
= PL0_R
, .readfn
= rndr_readfn
},
7096 #ifndef CONFIG_USER_ONLY
7097 static void dccvap_writefn(CPUARMState
*env
, const ARMCPRegInfo
*opaque
,
7100 ARMCPU
*cpu
= env_archcpu(env
);
7101 /* CTR_EL0 System register -> DminLine, bits [19:16] */
7102 uint64_t dline_size
= 4 << ((cpu
->ctr
>> 16) & 0xF);
7103 uint64_t vaddr_in
= (uint64_t) value
;
7104 uint64_t vaddr
= vaddr_in
& ~(dline_size
- 1);
7106 int mem_idx
= cpu_mmu_index(env
, false);
7108 /* This won't be crossing page boundaries */
7109 haddr
= probe_read(env
, vaddr
, dline_size
, mem_idx
, GETPC());
7115 /* RCU lock is already being held */
7116 mr
= memory_region_from_host(haddr
, &offset
);
7119 memory_region_writeback(mr
, offset
, dline_size
);
7124 static const ARMCPRegInfo dcpop_reg
[] = {
7125 { .name
= "DC_CVAP", .state
= ARM_CP_STATE_AA64
,
7126 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 1,
7127 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
,
7128 .accessfn
= aa64_cacheop_poc_access
, .writefn
= dccvap_writefn
},
7131 static const ARMCPRegInfo dcpodp_reg
[] = {
7132 { .name
= "DC_CVADP", .state
= ARM_CP_STATE_AA64
,
7133 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 1,
7134 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
,
7135 .accessfn
= aa64_cacheop_poc_access
, .writefn
= dccvap_writefn
},
7137 #endif /*CONFIG_USER_ONLY*/
7139 static CPAccessResult
access_aa64_tid5(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7142 if ((arm_current_el(env
) < 2) && (arm_hcr_el2_eff(env
) & HCR_TID5
)) {
7143 return CP_ACCESS_TRAP_EL2
;
7146 return CP_ACCESS_OK
;
7149 static CPAccessResult
access_mte(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7152 int el
= arm_current_el(env
);
7154 if (el
< 2 && arm_is_el2_enabled(env
)) {
7155 uint64_t hcr
= arm_hcr_el2_eff(env
);
7156 if (!(hcr
& HCR_ATA
) && (!(hcr
& HCR_E2H
) || !(hcr
& HCR_TGE
))) {
7157 return CP_ACCESS_TRAP_EL2
;
7161 arm_feature(env
, ARM_FEATURE_EL3
) &&
7162 !(env
->cp15
.scr_el3
& SCR_ATA
)) {
7163 return CP_ACCESS_TRAP_EL3
;
7165 return CP_ACCESS_OK
;
7168 static uint64_t tco_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7170 return env
->pstate
& PSTATE_TCO
;
7173 static void tco_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
7175 env
->pstate
= (env
->pstate
& ~PSTATE_TCO
) | (val
& PSTATE_TCO
);
7178 static const ARMCPRegInfo mte_reginfo
[] = {
7179 { .name
= "TFSRE0_EL1", .state
= ARM_CP_STATE_AA64
,
7180 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 6, .opc2
= 1,
7181 .access
= PL1_RW
, .accessfn
= access_mte
,
7182 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[0]) },
7183 { .name
= "TFSR_EL1", .state
= ARM_CP_STATE_AA64
,
7184 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 6, .opc2
= 0,
7185 .access
= PL1_RW
, .accessfn
= access_mte
,
7186 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[1]) },
7187 { .name
= "TFSR_EL2", .state
= ARM_CP_STATE_AA64
,
7188 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 6, .opc2
= 0,
7189 .access
= PL2_RW
, .accessfn
= access_mte
,
7190 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[2]) },
7191 { .name
= "TFSR_EL3", .state
= ARM_CP_STATE_AA64
,
7192 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 6, .opc2
= 0,
7194 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[3]) },
7195 { .name
= "RGSR_EL1", .state
= ARM_CP_STATE_AA64
,
7196 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 5,
7197 .access
= PL1_RW
, .accessfn
= access_mte
,
7198 .fieldoffset
= offsetof(CPUARMState
, cp15
.rgsr_el1
) },
7199 { .name
= "GCR_EL1", .state
= ARM_CP_STATE_AA64
,
7200 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 6,
7201 .access
= PL1_RW
, .accessfn
= access_mte
,
7202 .fieldoffset
= offsetof(CPUARMState
, cp15
.gcr_el1
) },
7203 { .name
= "GMID_EL1", .state
= ARM_CP_STATE_AA64
,
7204 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 4,
7205 .access
= PL1_R
, .accessfn
= access_aa64_tid5
,
7206 .type
= ARM_CP_CONST
, .resetvalue
= GMID_EL1_BS
},
7207 { .name
= "TCO", .state
= ARM_CP_STATE_AA64
,
7208 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 7,
7209 .type
= ARM_CP_NO_RAW
,
7210 .access
= PL0_RW
, .readfn
= tco_read
, .writefn
= tco_write
},
7211 { .name
= "DC_IGVAC", .state
= ARM_CP_STATE_AA64
,
7212 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 3,
7213 .type
= ARM_CP_NOP
, .access
= PL1_W
,
7214 .accessfn
= aa64_cacheop_poc_access
},
7215 { .name
= "DC_IGSW", .state
= ARM_CP_STATE_AA64
,
7216 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 4,
7217 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7218 { .name
= "DC_IGDVAC", .state
= ARM_CP_STATE_AA64
,
7219 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 5,
7220 .type
= ARM_CP_NOP
, .access
= PL1_W
,
7221 .accessfn
= aa64_cacheop_poc_access
},
7222 { .name
= "DC_IGDSW", .state
= ARM_CP_STATE_AA64
,
7223 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 6,
7224 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7225 { .name
= "DC_CGSW", .state
= ARM_CP_STATE_AA64
,
7226 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 4,
7227 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7228 { .name
= "DC_CGDSW", .state
= ARM_CP_STATE_AA64
,
7229 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 6,
7230 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7231 { .name
= "DC_CIGSW", .state
= ARM_CP_STATE_AA64
,
7232 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 4,
7233 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7234 { .name
= "DC_CIGDSW", .state
= ARM_CP_STATE_AA64
,
7235 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 6,
7236 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7239 static const ARMCPRegInfo mte_tco_ro_reginfo
[] = {
7240 { .name
= "TCO", .state
= ARM_CP_STATE_AA64
,
7241 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 7,
7242 .type
= ARM_CP_CONST
, .access
= PL0_RW
, },
7245 static const ARMCPRegInfo mte_el0_cacheop_reginfo
[] = {
7246 { .name
= "DC_CGVAC", .state
= ARM_CP_STATE_AA64
,
7247 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 3,
7248 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7249 .accessfn
= aa64_cacheop_poc_access
},
7250 { .name
= "DC_CGDVAC", .state
= ARM_CP_STATE_AA64
,
7251 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 5,
7252 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7253 .accessfn
= aa64_cacheop_poc_access
},
7254 { .name
= "DC_CGVAP", .state
= ARM_CP_STATE_AA64
,
7255 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 3,
7256 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7257 .accessfn
= aa64_cacheop_poc_access
},
7258 { .name
= "DC_CGDVAP", .state
= ARM_CP_STATE_AA64
,
7259 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 5,
7260 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7261 .accessfn
= aa64_cacheop_poc_access
},
7262 { .name
= "DC_CGVADP", .state
= ARM_CP_STATE_AA64
,
7263 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 3,
7264 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7265 .accessfn
= aa64_cacheop_poc_access
},
7266 { .name
= "DC_CGDVADP", .state
= ARM_CP_STATE_AA64
,
7267 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 5,
7268 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7269 .accessfn
= aa64_cacheop_poc_access
},
7270 { .name
= "DC_CIGVAC", .state
= ARM_CP_STATE_AA64
,
7271 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 3,
7272 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7273 .accessfn
= aa64_cacheop_poc_access
},
7274 { .name
= "DC_CIGDVAC", .state
= ARM_CP_STATE_AA64
,
7275 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 5,
7276 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7277 .accessfn
= aa64_cacheop_poc_access
},
7278 { .name
= "DC_GVA", .state
= ARM_CP_STATE_AA64
,
7279 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 3,
7280 .access
= PL0_W
, .type
= ARM_CP_DC_GVA
,
7281 #ifndef CONFIG_USER_ONLY
7282 /* Avoid overhead of an access check that always passes in user-mode */
7283 .accessfn
= aa64_zva_access
,
7286 { .name
= "DC_GZVA", .state
= ARM_CP_STATE_AA64
,
7287 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 4,
7288 .access
= PL0_W
, .type
= ARM_CP_DC_GZVA
,
7289 #ifndef CONFIG_USER_ONLY
7290 /* Avoid overhead of an access check that always passes in user-mode */
7291 .accessfn
= aa64_zva_access
,
7296 static CPAccessResult
access_scxtnum(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7299 uint64_t hcr
= arm_hcr_el2_eff(env
);
7300 int el
= arm_current_el(env
);
7302 if (el
== 0 && !((hcr
& HCR_E2H
) && (hcr
& HCR_TGE
))) {
7303 if (env
->cp15
.sctlr_el
[1] & SCTLR_TSCXT
) {
7304 if (hcr
& HCR_TGE
) {
7305 return CP_ACCESS_TRAP_EL2
;
7307 return CP_ACCESS_TRAP
;
7309 } else if (el
< 2 && (env
->cp15
.sctlr_el
[2] & SCTLR_TSCXT
)) {
7310 return CP_ACCESS_TRAP_EL2
;
7312 if (el
< 2 && arm_is_el2_enabled(env
) && !(hcr
& HCR_ENSCXT
)) {
7313 return CP_ACCESS_TRAP_EL2
;
7316 && arm_feature(env
, ARM_FEATURE_EL3
)
7317 && !(env
->cp15
.scr_el3
& SCR_ENSCXT
)) {
7318 return CP_ACCESS_TRAP_EL3
;
7320 return CP_ACCESS_OK
;
7323 static const ARMCPRegInfo scxtnum_reginfo
[] = {
7324 { .name
= "SCXTNUM_EL0", .state
= ARM_CP_STATE_AA64
,
7325 .opc0
= 3, .opc1
= 3, .crn
= 13, .crm
= 0, .opc2
= 7,
7326 .access
= PL0_RW
, .accessfn
= access_scxtnum
,
7327 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[0]) },
7328 { .name
= "SCXTNUM_EL1", .state
= ARM_CP_STATE_AA64
,
7329 .opc0
= 3, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 7,
7330 .access
= PL1_RW
, .accessfn
= access_scxtnum
,
7331 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[1]) },
7332 { .name
= "SCXTNUM_EL2", .state
= ARM_CP_STATE_AA64
,
7333 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 7,
7334 .access
= PL2_RW
, .accessfn
= access_scxtnum
,
7335 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[2]) },
7336 { .name
= "SCXTNUM_EL3", .state
= ARM_CP_STATE_AA64
,
7337 .opc0
= 3, .opc1
= 6, .crn
= 13, .crm
= 0, .opc2
= 7,
7339 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[3]) },
7341 #endif /* TARGET_AARCH64 */
7343 static CPAccessResult
access_predinv(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7346 int el
= arm_current_el(env
);
7349 uint64_t sctlr
= arm_sctlr(env
, el
);
7350 if (!(sctlr
& SCTLR_EnRCTX
)) {
7351 return CP_ACCESS_TRAP
;
7353 } else if (el
== 1) {
7354 uint64_t hcr
= arm_hcr_el2_eff(env
);
7356 return CP_ACCESS_TRAP_EL2
;
7359 return CP_ACCESS_OK
;
7362 static const ARMCPRegInfo predinv_reginfo
[] = {
7363 { .name
= "CFP_RCTX", .state
= ARM_CP_STATE_AA64
,
7364 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 4,
7365 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7366 { .name
= "DVP_RCTX", .state
= ARM_CP_STATE_AA64
,
7367 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 5,
7368 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7369 { .name
= "CPP_RCTX", .state
= ARM_CP_STATE_AA64
,
7370 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 7,
7371 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7373 * Note the AArch32 opcodes have a different OPC1.
7375 { .name
= "CFPRCTX", .state
= ARM_CP_STATE_AA32
,
7376 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 4,
7377 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7378 { .name
= "DVPRCTX", .state
= ARM_CP_STATE_AA32
,
7379 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 5,
7380 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7381 { .name
= "CPPRCTX", .state
= ARM_CP_STATE_AA32
,
7382 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 7,
7383 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7386 static uint64_t ccsidr2_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7388 /* Read the high 32 bits of the current CCSIDR */
7389 return extract64(ccsidr_read(env
, ri
), 32, 32);
7392 static const ARMCPRegInfo ccsidr2_reginfo
[] = {
7393 { .name
= "CCSIDR2", .state
= ARM_CP_STATE_BOTH
,
7394 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 2,
7396 .accessfn
= access_aa64_tid2
,
7397 .readfn
= ccsidr2_read
, .type
= ARM_CP_NO_RAW
},
7400 static CPAccessResult
access_aa64_tid3(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7403 if ((arm_current_el(env
) < 2) && (arm_hcr_el2_eff(env
) & HCR_TID3
)) {
7404 return CP_ACCESS_TRAP_EL2
;
7407 return CP_ACCESS_OK
;
7410 static CPAccessResult
access_aa32_tid3(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7413 if (arm_feature(env
, ARM_FEATURE_V8
)) {
7414 return access_aa64_tid3(env
, ri
, isread
);
7417 return CP_ACCESS_OK
;
7420 static CPAccessResult
access_jazelle(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7423 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID0
)) {
7424 return CP_ACCESS_TRAP_EL2
;
7427 return CP_ACCESS_OK
;
7430 static CPAccessResult
access_joscr_jmcr(CPUARMState
*env
,
7431 const ARMCPRegInfo
*ri
, bool isread
)
7434 * HSTR.TJDBX traps JOSCR and JMCR accesses, but it exists only
7435 * in v7A, not in v8A.
7437 if (!arm_feature(env
, ARM_FEATURE_V8
) &&
7438 arm_current_el(env
) < 2 && !arm_is_secure_below_el3(env
) &&
7439 (env
->cp15
.hstr_el2
& HSTR_TJDBX
)) {
7440 return CP_ACCESS_TRAP_EL2
;
7442 return CP_ACCESS_OK
;
7445 static const ARMCPRegInfo jazelle_regs
[] = {
7447 .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 7, .opc2
= 0,
7448 .access
= PL1_R
, .accessfn
= access_jazelle
,
7449 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7451 .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 7, .opc2
= 0,
7452 .accessfn
= access_joscr_jmcr
,
7453 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7455 .cp
= 14, .crn
= 2, .crm
= 0, .opc1
= 7, .opc2
= 0,
7456 .accessfn
= access_joscr_jmcr
,
7457 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7460 static const ARMCPRegInfo contextidr_el2
= {
7461 .name
= "CONTEXTIDR_EL2", .state
= ARM_CP_STATE_AA64
,
7462 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 1,
7464 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[2])
7467 static const ARMCPRegInfo vhe_reginfo
[] = {
7468 { .name
= "TTBR1_EL2", .state
= ARM_CP_STATE_AA64
,
7469 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 1,
7470 .access
= PL2_RW
, .writefn
= vmsa_tcr_ttbr_el2_write
,
7471 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr1_el
[2]) },
7472 #ifndef CONFIG_USER_ONLY
7473 { .name
= "CNTHV_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
7474 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 2,
7476 offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYPVIRT
].cval
),
7477 .type
= ARM_CP_IO
, .access
= PL2_RW
,
7478 .writefn
= gt_hv_cval_write
, .raw_writefn
= raw_write
},
7479 { .name
= "CNTHV_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
7480 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 0,
7481 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL2_RW
,
7482 .resetfn
= gt_hv_timer_reset
,
7483 .readfn
= gt_hv_tval_read
, .writefn
= gt_hv_tval_write
},
7484 { .name
= "CNTHV_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
7486 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 1,
7488 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYPVIRT
].ctl
),
7489 .writefn
= gt_hv_ctl_write
, .raw_writefn
= raw_write
},
7490 { .name
= "CNTP_CTL_EL02", .state
= ARM_CP_STATE_AA64
,
7491 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 1,
7492 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7493 .access
= PL2_RW
, .accessfn
= e2h_access
,
7494 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
7495 .writefn
= gt_phys_ctl_write
, .raw_writefn
= raw_write
},
7496 { .name
= "CNTV_CTL_EL02", .state
= ARM_CP_STATE_AA64
,
7497 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 1,
7498 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7499 .access
= PL2_RW
, .accessfn
= e2h_access
,
7500 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
7501 .writefn
= gt_virt_ctl_write
, .raw_writefn
= raw_write
},
7502 { .name
= "CNTP_TVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7503 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 0,
7504 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
| ARM_CP_ALIAS
,
7505 .access
= PL2_RW
, .accessfn
= e2h_access
,
7506 .readfn
= gt_phys_tval_read
, .writefn
= gt_phys_tval_write
},
7507 { .name
= "CNTV_TVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7508 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 0,
7509 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
| ARM_CP_ALIAS
,
7510 .access
= PL2_RW
, .accessfn
= e2h_access
,
7511 .readfn
= gt_virt_tval_read
, .writefn
= gt_virt_tval_write
},
7512 { .name
= "CNTP_CVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7513 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 2,
7514 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7515 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
7516 .access
= PL2_RW
, .accessfn
= e2h_access
,
7517 .writefn
= gt_phys_cval_write
, .raw_writefn
= raw_write
},
7518 { .name
= "CNTV_CVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7519 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 2,
7520 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7521 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
7522 .access
= PL2_RW
, .accessfn
= e2h_access
,
7523 .writefn
= gt_virt_cval_write
, .raw_writefn
= raw_write
},
7527 #ifndef CONFIG_USER_ONLY
7528 static const ARMCPRegInfo ats1e1_reginfo
[] = {
7529 { .name
= "AT_S1E1R", .state
= ARM_CP_STATE_AA64
,
7530 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 0,
7531 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7532 .writefn
= ats_write64
},
7533 { .name
= "AT_S1E1W", .state
= ARM_CP_STATE_AA64
,
7534 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 1,
7535 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7536 .writefn
= ats_write64
},
7539 static const ARMCPRegInfo ats1cp_reginfo
[] = {
7540 { .name
= "ATS1CPRP",
7541 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 0,
7542 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7543 .writefn
= ats_write
},
7544 { .name
= "ATS1CPWP",
7545 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 1,
7546 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7547 .writefn
= ats_write
},
7552 * ACTLR2 and HACTLR2 map to ACTLR_EL1[63:32] and
7553 * ACTLR_EL2[63:32]. They exist only if the ID_MMFR4.AC2 field
7554 * is non-zero, which is never for ARMv7, optionally in ARMv8
7555 * and mandatorily for ARMv8.2 and up.
7556 * ACTLR2 is banked for S and NS if EL3 is AArch32. Since QEMU's
7557 * implementation is RAZ/WI we can ignore this detail, as we
7560 static const ARMCPRegInfo actlr2_hactlr2_reginfo
[] = {
7561 { .name
= "ACTLR2", .state
= ARM_CP_STATE_AA32
,
7562 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 3,
7563 .access
= PL1_RW
, .accessfn
= access_tacr
,
7564 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7565 { .name
= "HACTLR2", .state
= ARM_CP_STATE_AA32
,
7566 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 3,
7567 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
7571 void register_cp_regs_for_features(ARMCPU
*cpu
)
7573 /* Register all the coprocessor registers based on feature bits */
7574 CPUARMState
*env
= &cpu
->env
;
7575 if (arm_feature(env
, ARM_FEATURE_M
)) {
7576 /* M profile has no coprocessor registers */
7580 define_arm_cp_regs(cpu
, cp_reginfo
);
7581 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
7582 /* Must go early as it is full of wildcards that may be
7583 * overridden by later definitions.
7585 define_arm_cp_regs(cpu
, not_v8_cp_reginfo
);
7588 if (arm_feature(env
, ARM_FEATURE_V6
)) {
7589 /* The ID registers all have impdef reset values */
7590 ARMCPRegInfo v6_idregs
[] = {
7591 { .name
= "ID_PFR0", .state
= ARM_CP_STATE_BOTH
,
7592 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 0,
7593 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7594 .accessfn
= access_aa32_tid3
,
7595 .resetvalue
= cpu
->isar
.id_pfr0
},
7596 /* ID_PFR1 is not a plain ARM_CP_CONST because we don't know
7597 * the value of the GIC field until after we define these regs.
7599 { .name
= "ID_PFR1", .state
= ARM_CP_STATE_BOTH
,
7600 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 1,
7601 .access
= PL1_R
, .type
= ARM_CP_NO_RAW
,
7602 .accessfn
= access_aa32_tid3
,
7603 .readfn
= id_pfr1_read
,
7604 .writefn
= arm_cp_write_ignore
},
7605 { .name
= "ID_DFR0", .state
= ARM_CP_STATE_BOTH
,
7606 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 2,
7607 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7608 .accessfn
= access_aa32_tid3
,
7609 .resetvalue
= cpu
->isar
.id_dfr0
},
7610 { .name
= "ID_AFR0", .state
= ARM_CP_STATE_BOTH
,
7611 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 3,
7612 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7613 .accessfn
= access_aa32_tid3
,
7614 .resetvalue
= cpu
->id_afr0
},
7615 { .name
= "ID_MMFR0", .state
= ARM_CP_STATE_BOTH
,
7616 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 4,
7617 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7618 .accessfn
= access_aa32_tid3
,
7619 .resetvalue
= cpu
->isar
.id_mmfr0
},
7620 { .name
= "ID_MMFR1", .state
= ARM_CP_STATE_BOTH
,
7621 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 5,
7622 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7623 .accessfn
= access_aa32_tid3
,
7624 .resetvalue
= cpu
->isar
.id_mmfr1
},
7625 { .name
= "ID_MMFR2", .state
= ARM_CP_STATE_BOTH
,
7626 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 6,
7627 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7628 .accessfn
= access_aa32_tid3
,
7629 .resetvalue
= cpu
->isar
.id_mmfr2
},
7630 { .name
= "ID_MMFR3", .state
= ARM_CP_STATE_BOTH
,
7631 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 7,
7632 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7633 .accessfn
= access_aa32_tid3
,
7634 .resetvalue
= cpu
->isar
.id_mmfr3
},
7635 { .name
= "ID_ISAR0", .state
= ARM_CP_STATE_BOTH
,
7636 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 0,
7637 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7638 .accessfn
= access_aa32_tid3
,
7639 .resetvalue
= cpu
->isar
.id_isar0
},
7640 { .name
= "ID_ISAR1", .state
= ARM_CP_STATE_BOTH
,
7641 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 1,
7642 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7643 .accessfn
= access_aa32_tid3
,
7644 .resetvalue
= cpu
->isar
.id_isar1
},
7645 { .name
= "ID_ISAR2", .state
= ARM_CP_STATE_BOTH
,
7646 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 2,
7647 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7648 .accessfn
= access_aa32_tid3
,
7649 .resetvalue
= cpu
->isar
.id_isar2
},
7650 { .name
= "ID_ISAR3", .state
= ARM_CP_STATE_BOTH
,
7651 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 3,
7652 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7653 .accessfn
= access_aa32_tid3
,
7654 .resetvalue
= cpu
->isar
.id_isar3
},
7655 { .name
= "ID_ISAR4", .state
= ARM_CP_STATE_BOTH
,
7656 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 4,
7657 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7658 .accessfn
= access_aa32_tid3
,
7659 .resetvalue
= cpu
->isar
.id_isar4
},
7660 { .name
= "ID_ISAR5", .state
= ARM_CP_STATE_BOTH
,
7661 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 5,
7662 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7663 .accessfn
= access_aa32_tid3
,
7664 .resetvalue
= cpu
->isar
.id_isar5
},
7665 { .name
= "ID_MMFR4", .state
= ARM_CP_STATE_BOTH
,
7666 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 6,
7667 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7668 .accessfn
= access_aa32_tid3
,
7669 .resetvalue
= cpu
->isar
.id_mmfr4
},
7670 { .name
= "ID_ISAR6", .state
= ARM_CP_STATE_BOTH
,
7671 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 7,
7672 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7673 .accessfn
= access_aa32_tid3
,
7674 .resetvalue
= cpu
->isar
.id_isar6
},
7676 define_arm_cp_regs(cpu
, v6_idregs
);
7677 define_arm_cp_regs(cpu
, v6_cp_reginfo
);
7679 define_arm_cp_regs(cpu
, not_v6_cp_reginfo
);
7681 if (arm_feature(env
, ARM_FEATURE_V6K
)) {
7682 define_arm_cp_regs(cpu
, v6k_cp_reginfo
);
7684 if (arm_feature(env
, ARM_FEATURE_V7MP
) &&
7685 !arm_feature(env
, ARM_FEATURE_PMSA
)) {
7686 define_arm_cp_regs(cpu
, v7mp_cp_reginfo
);
7688 if (arm_feature(env
, ARM_FEATURE_V7VE
)) {
7689 define_arm_cp_regs(cpu
, pmovsset_cp_reginfo
);
7691 if (arm_feature(env
, ARM_FEATURE_V7
)) {
7692 ARMCPRegInfo clidr
= {
7693 .name
= "CLIDR", .state
= ARM_CP_STATE_BOTH
,
7694 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 1,
7695 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7696 .accessfn
= access_aa64_tid2
,
7697 .resetvalue
= cpu
->clidr
7699 define_one_arm_cp_reg(cpu
, &clidr
);
7700 define_arm_cp_regs(cpu
, v7_cp_reginfo
);
7701 define_debug_regs(cpu
);
7702 define_pmu_regs(cpu
);
7704 define_arm_cp_regs(cpu
, not_v7_cp_reginfo
);
7706 if (arm_feature(env
, ARM_FEATURE_V8
)) {
7707 /* AArch64 ID registers, which all have impdef reset values.
7708 * Note that within the ID register ranges the unused slots
7709 * must all RAZ, not UNDEF; future architecture versions may
7710 * define new registers here.
7712 ARMCPRegInfo v8_idregs
[] = {
7714 * ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST in system
7715 * emulation because we don't know the right value for the
7716 * GIC field until after we define these regs.
7718 { .name
= "ID_AA64PFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7719 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 0,
7721 #ifdef CONFIG_USER_ONLY
7722 .type
= ARM_CP_CONST
,
7723 .resetvalue
= cpu
->isar
.id_aa64pfr0
7725 .type
= ARM_CP_NO_RAW
,
7726 .accessfn
= access_aa64_tid3
,
7727 .readfn
= id_aa64pfr0_read
,
7728 .writefn
= arm_cp_write_ignore
7731 { .name
= "ID_AA64PFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7732 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 1,
7733 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7734 .accessfn
= access_aa64_tid3
,
7735 .resetvalue
= cpu
->isar
.id_aa64pfr1
},
7736 { .name
= "ID_AA64PFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7737 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 2,
7738 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7739 .accessfn
= access_aa64_tid3
,
7741 { .name
= "ID_AA64PFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7742 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 3,
7743 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7744 .accessfn
= access_aa64_tid3
,
7746 { .name
= "ID_AA64ZFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7747 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 4,
7748 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7749 .accessfn
= access_aa64_tid3
,
7750 .resetvalue
= cpu
->isar
.id_aa64zfr0
},
7751 { .name
= "ID_AA64PFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7752 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 5,
7753 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7754 .accessfn
= access_aa64_tid3
,
7756 { .name
= "ID_AA64PFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7757 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 6,
7758 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7759 .accessfn
= access_aa64_tid3
,
7761 { .name
= "ID_AA64PFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7762 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 7,
7763 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7764 .accessfn
= access_aa64_tid3
,
7766 { .name
= "ID_AA64DFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7767 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 0,
7768 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7769 .accessfn
= access_aa64_tid3
,
7770 .resetvalue
= cpu
->isar
.id_aa64dfr0
},
7771 { .name
= "ID_AA64DFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7772 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 1,
7773 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7774 .accessfn
= access_aa64_tid3
,
7775 .resetvalue
= cpu
->isar
.id_aa64dfr1
},
7776 { .name
= "ID_AA64DFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7777 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 2,
7778 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7779 .accessfn
= access_aa64_tid3
,
7781 { .name
= "ID_AA64DFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7782 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 3,
7783 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7784 .accessfn
= access_aa64_tid3
,
7786 { .name
= "ID_AA64AFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7787 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 4,
7788 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7789 .accessfn
= access_aa64_tid3
,
7790 .resetvalue
= cpu
->id_aa64afr0
},
7791 { .name
= "ID_AA64AFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7792 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 5,
7793 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7794 .accessfn
= access_aa64_tid3
,
7795 .resetvalue
= cpu
->id_aa64afr1
},
7796 { .name
= "ID_AA64AFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7797 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 6,
7798 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7799 .accessfn
= access_aa64_tid3
,
7801 { .name
= "ID_AA64AFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7802 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 7,
7803 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7804 .accessfn
= access_aa64_tid3
,
7806 { .name
= "ID_AA64ISAR0_EL1", .state
= ARM_CP_STATE_AA64
,
7807 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 0,
7808 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7809 .accessfn
= access_aa64_tid3
,
7810 .resetvalue
= cpu
->isar
.id_aa64isar0
},
7811 { .name
= "ID_AA64ISAR1_EL1", .state
= ARM_CP_STATE_AA64
,
7812 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 1,
7813 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7814 .accessfn
= access_aa64_tid3
,
7815 .resetvalue
= cpu
->isar
.id_aa64isar1
},
7816 { .name
= "ID_AA64ISAR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7817 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 2,
7818 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7819 .accessfn
= access_aa64_tid3
,
7821 { .name
= "ID_AA64ISAR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7822 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 3,
7823 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7824 .accessfn
= access_aa64_tid3
,
7826 { .name
= "ID_AA64ISAR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7827 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 4,
7828 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7829 .accessfn
= access_aa64_tid3
,
7831 { .name
= "ID_AA64ISAR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7832 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 5,
7833 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7834 .accessfn
= access_aa64_tid3
,
7836 { .name
= "ID_AA64ISAR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7837 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 6,
7838 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7839 .accessfn
= access_aa64_tid3
,
7841 { .name
= "ID_AA64ISAR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7842 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 7,
7843 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7844 .accessfn
= access_aa64_tid3
,
7846 { .name
= "ID_AA64MMFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7847 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 0,
7848 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7849 .accessfn
= access_aa64_tid3
,
7850 .resetvalue
= cpu
->isar
.id_aa64mmfr0
},
7851 { .name
= "ID_AA64MMFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7852 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 1,
7853 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7854 .accessfn
= access_aa64_tid3
,
7855 .resetvalue
= cpu
->isar
.id_aa64mmfr1
},
7856 { .name
= "ID_AA64MMFR2_EL1", .state
= ARM_CP_STATE_AA64
,
7857 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 2,
7858 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7859 .accessfn
= access_aa64_tid3
,
7860 .resetvalue
= cpu
->isar
.id_aa64mmfr2
},
7861 { .name
= "ID_AA64MMFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7862 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 3,
7863 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7864 .accessfn
= access_aa64_tid3
,
7866 { .name
= "ID_AA64MMFR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7867 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 4,
7868 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7869 .accessfn
= access_aa64_tid3
,
7871 { .name
= "ID_AA64MMFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7872 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 5,
7873 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7874 .accessfn
= access_aa64_tid3
,
7876 { .name
= "ID_AA64MMFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7877 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 6,
7878 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7879 .accessfn
= access_aa64_tid3
,
7881 { .name
= "ID_AA64MMFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7882 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 7,
7883 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7884 .accessfn
= access_aa64_tid3
,
7886 { .name
= "MVFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7887 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 0,
7888 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7889 .accessfn
= access_aa64_tid3
,
7890 .resetvalue
= cpu
->isar
.mvfr0
},
7891 { .name
= "MVFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7892 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 1,
7893 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7894 .accessfn
= access_aa64_tid3
,
7895 .resetvalue
= cpu
->isar
.mvfr1
},
7896 { .name
= "MVFR2_EL1", .state
= ARM_CP_STATE_AA64
,
7897 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 2,
7898 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7899 .accessfn
= access_aa64_tid3
,
7900 .resetvalue
= cpu
->isar
.mvfr2
},
7901 { .name
= "MVFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7902 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 3,
7903 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7904 .accessfn
= access_aa64_tid3
,
7906 { .name
= "ID_PFR2", .state
= ARM_CP_STATE_BOTH
,
7907 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 4,
7908 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7909 .accessfn
= access_aa64_tid3
,
7910 .resetvalue
= cpu
->isar
.id_pfr2
},
7911 { .name
= "MVFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7912 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 5,
7913 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7914 .accessfn
= access_aa64_tid3
,
7916 { .name
= "MVFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7917 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 6,
7918 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7919 .accessfn
= access_aa64_tid3
,
7921 { .name
= "MVFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7922 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 7,
7923 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7924 .accessfn
= access_aa64_tid3
,
7926 { .name
= "PMCEID0", .state
= ARM_CP_STATE_AA32
,
7927 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 6,
7928 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7929 .resetvalue
= extract64(cpu
->pmceid0
, 0, 32) },
7930 { .name
= "PMCEID0_EL0", .state
= ARM_CP_STATE_AA64
,
7931 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 6,
7932 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7933 .resetvalue
= cpu
->pmceid0
},
7934 { .name
= "PMCEID1", .state
= ARM_CP_STATE_AA32
,
7935 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 7,
7936 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7937 .resetvalue
= extract64(cpu
->pmceid1
, 0, 32) },
7938 { .name
= "PMCEID1_EL0", .state
= ARM_CP_STATE_AA64
,
7939 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 7,
7940 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7941 .resetvalue
= cpu
->pmceid1
},
7943 #ifdef CONFIG_USER_ONLY
7944 static const ARMCPRegUserSpaceInfo v8_user_idregs
[] = {
7945 { .name
= "ID_AA64PFR0_EL1",
7946 .exported_bits
= 0x000f000f00ff0000,
7947 .fixed_bits
= 0x0000000000000011 },
7948 { .name
= "ID_AA64PFR1_EL1",
7949 .exported_bits
= 0x00000000000000f0 },
7950 { .name
= "ID_AA64PFR*_EL1_RESERVED",
7952 { .name
= "ID_AA64ZFR0_EL1" },
7953 { .name
= "ID_AA64MMFR0_EL1",
7954 .fixed_bits
= 0x00000000ff000000 },
7955 { .name
= "ID_AA64MMFR1_EL1" },
7956 { .name
= "ID_AA64MMFR*_EL1_RESERVED",
7958 { .name
= "ID_AA64DFR0_EL1",
7959 .fixed_bits
= 0x0000000000000006 },
7960 { .name
= "ID_AA64DFR1_EL1" },
7961 { .name
= "ID_AA64DFR*_EL1_RESERVED",
7963 { .name
= "ID_AA64AFR*",
7965 { .name
= "ID_AA64ISAR0_EL1",
7966 .exported_bits
= 0x00fffffff0fffff0 },
7967 { .name
= "ID_AA64ISAR1_EL1",
7968 .exported_bits
= 0x000000f0ffffffff },
7969 { .name
= "ID_AA64ISAR*_EL1_RESERVED",
7972 modify_arm_cp_regs(v8_idregs
, v8_user_idregs
);
7974 /* RVBAR_EL1 is only implemented if EL1 is the highest EL */
7975 if (!arm_feature(env
, ARM_FEATURE_EL3
) &&
7976 !arm_feature(env
, ARM_FEATURE_EL2
)) {
7977 ARMCPRegInfo rvbar
= {
7978 .name
= "RVBAR_EL1", .state
= ARM_CP_STATE_AA64
,
7979 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
7981 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
),
7983 define_one_arm_cp_reg(cpu
, &rvbar
);
7985 define_arm_cp_regs(cpu
, v8_idregs
);
7986 define_arm_cp_regs(cpu
, v8_cp_reginfo
);
7990 * Register the base EL2 cpregs.
7991 * Pre v8, these registers are implemented only as part of the
7992 * Virtualization Extensions (EL2 present). Beginning with v8,
7993 * if EL2 is missing but EL3 is enabled, mostly these become
7994 * RES0 from EL3, with some specific exceptions.
7996 if (arm_feature(env
, ARM_FEATURE_EL2
)
7997 || (arm_feature(env
, ARM_FEATURE_EL3
)
7998 && arm_feature(env
, ARM_FEATURE_V8
))) {
7999 uint64_t vmpidr_def
= mpidr_read_val(env
);
8000 ARMCPRegInfo vpidr_regs
[] = {
8001 { .name
= "VPIDR", .state
= ARM_CP_STATE_AA32
,
8002 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
8003 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
8004 .resetvalue
= cpu
->midr
,
8005 .type
= ARM_CP_ALIAS
| ARM_CP_EL3_NO_EL2_C_NZ
,
8006 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vpidr_el2
) },
8007 { .name
= "VPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
8008 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
8009 .access
= PL2_RW
, .resetvalue
= cpu
->midr
,
8010 .type
= ARM_CP_EL3_NO_EL2_C_NZ
,
8011 .fieldoffset
= offsetof(CPUARMState
, cp15
.vpidr_el2
) },
8012 { .name
= "VMPIDR", .state
= ARM_CP_STATE_AA32
,
8013 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
8014 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
8015 .resetvalue
= vmpidr_def
,
8016 .type
= ARM_CP_ALIAS
| ARM_CP_EL3_NO_EL2_C_NZ
,
8017 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vmpidr_el2
) },
8018 { .name
= "VMPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
8019 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
8020 .access
= PL2_RW
, .resetvalue
= vmpidr_def
,
8021 .type
= ARM_CP_EL3_NO_EL2_C_NZ
,
8022 .fieldoffset
= offsetof(CPUARMState
, cp15
.vmpidr_el2
) },
8025 * The only field of MDCR_EL2 that has a defined architectural reset
8026 * value is MDCR_EL2.HPMN which should reset to the value of PMCR_EL0.N.
8028 ARMCPRegInfo mdcr_el2
= {
8029 .name
= "MDCR_EL2", .state
= ARM_CP_STATE_BOTH
,
8030 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 1,
8031 .access
= PL2_RW
, .resetvalue
= pmu_num_counters(env
),
8032 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el2
),
8034 define_one_arm_cp_reg(cpu
, &mdcr_el2
);
8035 define_arm_cp_regs(cpu
, vpidr_regs
);
8036 define_arm_cp_regs(cpu
, el2_cp_reginfo
);
8037 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8038 define_arm_cp_regs(cpu
, el2_v8_cp_reginfo
);
8040 if (cpu_isar_feature(aa64_sel2
, cpu
)) {
8041 define_arm_cp_regs(cpu
, el2_sec_cp_reginfo
);
8043 /* RVBAR_EL2 is only implemented if EL2 is the highest EL */
8044 if (!arm_feature(env
, ARM_FEATURE_EL3
)) {
8045 ARMCPRegInfo rvbar
= {
8046 .name
= "RVBAR_EL2", .state
= ARM_CP_STATE_AA64
,
8047 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 1,
8049 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
),
8051 define_one_arm_cp_reg(cpu
, &rvbar
);
8055 /* Register the base EL3 cpregs. */
8056 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
8057 define_arm_cp_regs(cpu
, el3_cp_reginfo
);
8058 ARMCPRegInfo el3_regs
[] = {
8059 { .name
= "RVBAR_EL3", .state
= ARM_CP_STATE_AA64
,
8060 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 1,
8062 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
),
8064 { .name
= "SCTLR_EL3", .state
= ARM_CP_STATE_AA64
,
8065 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 0,
8067 .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
8068 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[3]),
8069 .resetvalue
= cpu
->reset_sctlr
},
8072 define_arm_cp_regs(cpu
, el3_regs
);
8074 /* The behaviour of NSACR is sufficiently various that we don't
8075 * try to describe it in a single reginfo:
8076 * if EL3 is 64 bit, then trap to EL3 from S EL1,
8077 * reads as constant 0xc00 from NS EL1 and NS EL2
8078 * if EL3 is 32 bit, then RW at EL3, RO at NS EL1 and NS EL2
8079 * if v7 without EL3, register doesn't exist
8080 * if v8 without EL3, reads as constant 0xc00 from NS EL1 and NS EL2
8082 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
8083 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
8084 static const ARMCPRegInfo nsacr
= {
8085 .name
= "NSACR", .type
= ARM_CP_CONST
,
8086 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
8087 .access
= PL1_RW
, .accessfn
= nsacr_access
,
8090 define_one_arm_cp_reg(cpu
, &nsacr
);
8092 static const ARMCPRegInfo nsacr
= {
8094 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
8095 .access
= PL3_RW
| PL1_R
,
8097 .fieldoffset
= offsetof(CPUARMState
, cp15
.nsacr
)
8099 define_one_arm_cp_reg(cpu
, &nsacr
);
8102 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8103 static const ARMCPRegInfo nsacr
= {
8104 .name
= "NSACR", .type
= ARM_CP_CONST
,
8105 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
8109 define_one_arm_cp_reg(cpu
, &nsacr
);
8113 if (arm_feature(env
, ARM_FEATURE_PMSA
)) {
8114 if (arm_feature(env
, ARM_FEATURE_V6
)) {
8115 /* PMSAv6 not implemented */
8116 assert(arm_feature(env
, ARM_FEATURE_V7
));
8117 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
8118 define_arm_cp_regs(cpu
, pmsav7_cp_reginfo
);
8120 define_arm_cp_regs(cpu
, pmsav5_cp_reginfo
);
8123 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
8124 define_arm_cp_regs(cpu
, vmsa_cp_reginfo
);
8125 /* TTCBR2 is introduced with ARMv8.2-AA32HPD. */
8126 if (cpu_isar_feature(aa32_hpd
, cpu
)) {
8127 define_one_arm_cp_reg(cpu
, &ttbcr2_reginfo
);
8130 if (arm_feature(env
, ARM_FEATURE_THUMB2EE
)) {
8131 define_arm_cp_regs(cpu
, t2ee_cp_reginfo
);
8133 if (arm_feature(env
, ARM_FEATURE_GENERIC_TIMER
)) {
8134 define_arm_cp_regs(cpu
, generic_timer_cp_reginfo
);
8136 if (arm_feature(env
, ARM_FEATURE_VAPA
)) {
8137 define_arm_cp_regs(cpu
, vapa_cp_reginfo
);
8139 if (arm_feature(env
, ARM_FEATURE_CACHE_TEST_CLEAN
)) {
8140 define_arm_cp_regs(cpu
, cache_test_clean_cp_reginfo
);
8142 if (arm_feature(env
, ARM_FEATURE_CACHE_DIRTY_REG
)) {
8143 define_arm_cp_regs(cpu
, cache_dirty_status_cp_reginfo
);
8145 if (arm_feature(env
, ARM_FEATURE_CACHE_BLOCK_OPS
)) {
8146 define_arm_cp_regs(cpu
, cache_block_ops_cp_reginfo
);
8148 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
8149 define_arm_cp_regs(cpu
, omap_cp_reginfo
);
8151 if (arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
8152 define_arm_cp_regs(cpu
, strongarm_cp_reginfo
);
8154 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
8155 define_arm_cp_regs(cpu
, xscale_cp_reginfo
);
8157 if (arm_feature(env
, ARM_FEATURE_DUMMY_C15_REGS
)) {
8158 define_arm_cp_regs(cpu
, dummy_c15_cp_reginfo
);
8160 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
8161 define_arm_cp_regs(cpu
, lpae_cp_reginfo
);
8163 if (cpu_isar_feature(aa32_jazelle
, cpu
)) {
8164 define_arm_cp_regs(cpu
, jazelle_regs
);
8166 /* Slightly awkwardly, the OMAP and StrongARM cores need all of
8167 * cp15 crn=0 to be writes-ignored, whereas for other cores they should
8168 * be read-only (ie write causes UNDEF exception).
8171 ARMCPRegInfo id_pre_v8_midr_cp_reginfo
[] = {
8172 /* Pre-v8 MIDR space.
8173 * Note that the MIDR isn't a simple constant register because
8174 * of the TI925 behaviour where writes to another register can
8175 * cause the MIDR value to change.
8177 * Unimplemented registers in the c15 0 0 0 space default to
8178 * MIDR. Define MIDR first as this entire space, then CTR, TCMTR
8179 * and friends override accordingly.
8182 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= CP_ANY
,
8183 .access
= PL1_R
, .resetvalue
= cpu
->midr
,
8184 .writefn
= arm_cp_write_ignore
, .raw_writefn
= raw_write
,
8185 .readfn
= midr_read
,
8186 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
8187 .type
= ARM_CP_OVERRIDE
},
8188 /* crn = 0 op1 = 0 crm = 3..7 : currently unassigned; we RAZ. */
8190 .cp
= 15, .crn
= 0, .crm
= 3, .opc1
= 0, .opc2
= CP_ANY
,
8191 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8193 .cp
= 15, .crn
= 0, .crm
= 4, .opc1
= 0, .opc2
= CP_ANY
,
8194 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8196 .cp
= 15, .crn
= 0, .crm
= 5, .opc1
= 0, .opc2
= CP_ANY
,
8197 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8199 .cp
= 15, .crn
= 0, .crm
= 6, .opc1
= 0, .opc2
= CP_ANY
,
8200 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8202 .cp
= 15, .crn
= 0, .crm
= 7, .opc1
= 0, .opc2
= CP_ANY
,
8203 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8205 ARMCPRegInfo id_v8_midr_cp_reginfo
[] = {
8206 { .name
= "MIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
8207 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 0,
8208 .access
= PL1_R
, .type
= ARM_CP_NO_RAW
, .resetvalue
= cpu
->midr
,
8209 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
8210 .readfn
= midr_read
},
8211 /* crn = 0 op1 = 0 crm = 0 op2 = 4,7 : AArch32 aliases of MIDR */
8212 { .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
,
8213 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
8214 .access
= PL1_R
, .resetvalue
= cpu
->midr
},
8215 { .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
,
8216 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 7,
8217 .access
= PL1_R
, .resetvalue
= cpu
->midr
},
8218 { .name
= "REVIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
8219 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 6,
8221 .accessfn
= access_aa64_tid1
,
8222 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->revidr
},
8224 ARMCPRegInfo id_cp_reginfo
[] = {
8225 /* These are common to v8 and pre-v8 */
8227 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 1,
8228 .access
= PL1_R
, .accessfn
= ctr_el0_access
,
8229 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
8230 { .name
= "CTR_EL0", .state
= ARM_CP_STATE_AA64
,
8231 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 0, .crm
= 0,
8232 .access
= PL0_R
, .accessfn
= ctr_el0_access
,
8233 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
8234 /* TCMTR and TLBTR exist in v8 but have no 64-bit versions */
8236 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 2,
8238 .accessfn
= access_aa32_tid1
,
8239 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8241 /* TLBTR is specific to VMSA */
8242 ARMCPRegInfo id_tlbtr_reginfo
= {
8244 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 3,
8246 .accessfn
= access_aa32_tid1
,
8247 .type
= ARM_CP_CONST
, .resetvalue
= 0,
8249 /* MPUIR is specific to PMSA V6+ */
8250 ARMCPRegInfo id_mpuir_reginfo
= {
8252 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
8253 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8254 .resetvalue
= cpu
->pmsav7_dregion
<< 8
8256 static const ARMCPRegInfo crn0_wi_reginfo
= {
8257 .name
= "CRN0_WI", .cp
= 15, .crn
= 0, .crm
= CP_ANY
,
8258 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_W
,
8259 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
8261 #ifdef CONFIG_USER_ONLY
8262 static const ARMCPRegUserSpaceInfo id_v8_user_midr_cp_reginfo
[] = {
8263 { .name
= "MIDR_EL1",
8264 .exported_bits
= 0x00000000ffffffff },
8265 { .name
= "REVIDR_EL1" },
8267 modify_arm_cp_regs(id_v8_midr_cp_reginfo
, id_v8_user_midr_cp_reginfo
);
8269 if (arm_feature(env
, ARM_FEATURE_OMAPCP
) ||
8270 arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
8272 /* Register the blanket "writes ignored" value first to cover the
8273 * whole space. Then update the specific ID registers to allow write
8274 * access, so that they ignore writes rather than causing them to
8277 define_one_arm_cp_reg(cpu
, &crn0_wi_reginfo
);
8278 for (i
= 0; i
< ARRAY_SIZE(id_pre_v8_midr_cp_reginfo
); ++i
) {
8279 id_pre_v8_midr_cp_reginfo
[i
].access
= PL1_RW
;
8281 for (i
= 0; i
< ARRAY_SIZE(id_cp_reginfo
); ++i
) {
8282 id_cp_reginfo
[i
].access
= PL1_RW
;
8284 id_mpuir_reginfo
.access
= PL1_RW
;
8285 id_tlbtr_reginfo
.access
= PL1_RW
;
8287 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8288 define_arm_cp_regs(cpu
, id_v8_midr_cp_reginfo
);
8290 define_arm_cp_regs(cpu
, id_pre_v8_midr_cp_reginfo
);
8292 define_arm_cp_regs(cpu
, id_cp_reginfo
);
8293 if (!arm_feature(env
, ARM_FEATURE_PMSA
)) {
8294 define_one_arm_cp_reg(cpu
, &id_tlbtr_reginfo
);
8295 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
8296 define_one_arm_cp_reg(cpu
, &id_mpuir_reginfo
);
8300 if (arm_feature(env
, ARM_FEATURE_MPIDR
)) {
8301 ARMCPRegInfo mpidr_cp_reginfo
[] = {
8302 { .name
= "MPIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
8303 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 5,
8304 .access
= PL1_R
, .readfn
= mpidr_read
, .type
= ARM_CP_NO_RAW
},
8306 #ifdef CONFIG_USER_ONLY
8307 static const ARMCPRegUserSpaceInfo mpidr_user_cp_reginfo
[] = {
8308 { .name
= "MPIDR_EL1",
8309 .fixed_bits
= 0x0000000080000000 },
8311 modify_arm_cp_regs(mpidr_cp_reginfo
, mpidr_user_cp_reginfo
);
8313 define_arm_cp_regs(cpu
, mpidr_cp_reginfo
);
8316 if (arm_feature(env
, ARM_FEATURE_AUXCR
)) {
8317 ARMCPRegInfo auxcr_reginfo
[] = {
8318 { .name
= "ACTLR_EL1", .state
= ARM_CP_STATE_BOTH
,
8319 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 1,
8320 .access
= PL1_RW
, .accessfn
= access_tacr
,
8321 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->reset_auxcr
},
8322 { .name
= "ACTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
8323 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 1,
8324 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
8326 { .name
= "ACTLR_EL3", .state
= ARM_CP_STATE_AA64
,
8327 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 1,
8328 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
8331 define_arm_cp_regs(cpu
, auxcr_reginfo
);
8332 if (cpu_isar_feature(aa32_ac2
, cpu
)) {
8333 define_arm_cp_regs(cpu
, actlr2_hactlr2_reginfo
);
8337 if (arm_feature(env
, ARM_FEATURE_CBAR
)) {
8339 * CBAR is IMPDEF, but common on Arm Cortex-A implementations.
8340 * There are two flavours:
8341 * (1) older 32-bit only cores have a simple 32-bit CBAR
8342 * (2) 64-bit cores have a 64-bit CBAR visible to AArch64, plus a
8343 * 32-bit register visible to AArch32 at a different encoding
8344 * to the "flavour 1" register and with the bits rearranged to
8345 * be able to squash a 64-bit address into the 32-bit view.
8346 * We distinguish the two via the ARM_FEATURE_AARCH64 flag, but
8347 * in future if we support AArch32-only configs of some of the
8348 * AArch64 cores we might need to add a specific feature flag
8349 * to indicate cores with "flavour 2" CBAR.
8351 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
8352 /* 32 bit view is [31:18] 0...0 [43:32]. */
8353 uint32_t cbar32
= (extract64(cpu
->reset_cbar
, 18, 14) << 18)
8354 | extract64(cpu
->reset_cbar
, 32, 12);
8355 ARMCPRegInfo cbar_reginfo
[] = {
8357 .type
= ARM_CP_CONST
,
8358 .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 1, .opc2
= 0,
8359 .access
= PL1_R
, .resetvalue
= cbar32
},
8360 { .name
= "CBAR_EL1", .state
= ARM_CP_STATE_AA64
,
8361 .type
= ARM_CP_CONST
,
8362 .opc0
= 3, .opc1
= 1, .crn
= 15, .crm
= 3, .opc2
= 0,
8363 .access
= PL1_R
, .resetvalue
= cpu
->reset_cbar
},
8365 /* We don't implement a r/w 64 bit CBAR currently */
8366 assert(arm_feature(env
, ARM_FEATURE_CBAR_RO
));
8367 define_arm_cp_regs(cpu
, cbar_reginfo
);
8369 ARMCPRegInfo cbar
= {
8371 .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 4, .opc2
= 0,
8372 .access
= PL1_R
|PL3_W
, .resetvalue
= cpu
->reset_cbar
,
8373 .fieldoffset
= offsetof(CPUARMState
,
8374 cp15
.c15_config_base_address
)
8376 if (arm_feature(env
, ARM_FEATURE_CBAR_RO
)) {
8377 cbar
.access
= PL1_R
;
8378 cbar
.fieldoffset
= 0;
8379 cbar
.type
= ARM_CP_CONST
;
8381 define_one_arm_cp_reg(cpu
, &cbar
);
8385 if (arm_feature(env
, ARM_FEATURE_VBAR
)) {
8386 static const ARMCPRegInfo vbar_cp_reginfo
[] = {
8387 { .name
= "VBAR", .state
= ARM_CP_STATE_BOTH
,
8388 .opc0
= 3, .crn
= 12, .crm
= 0, .opc1
= 0, .opc2
= 0,
8389 .access
= PL1_RW
, .writefn
= vbar_write
,
8390 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.vbar_s
),
8391 offsetof(CPUARMState
, cp15
.vbar_ns
) },
8394 define_arm_cp_regs(cpu
, vbar_cp_reginfo
);
8397 /* Generic registers whose values depend on the implementation */
8399 ARMCPRegInfo sctlr
= {
8400 .name
= "SCTLR", .state
= ARM_CP_STATE_BOTH
,
8401 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 0,
8402 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
8403 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.sctlr_s
),
8404 offsetof(CPUARMState
, cp15
.sctlr_ns
) },
8405 .writefn
= sctlr_write
, .resetvalue
= cpu
->reset_sctlr
,
8406 .raw_writefn
= raw_write
,
8408 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
8409 /* Normally we would always end the TB on an SCTLR write, but Linux
8410 * arch/arm/mach-pxa/sleep.S expects two instructions following
8411 * an MMU enable to execute from cache. Imitate this behaviour.
8413 sctlr
.type
|= ARM_CP_SUPPRESS_TB_END
;
8415 define_one_arm_cp_reg(cpu
, &sctlr
);
8418 if (cpu_isar_feature(aa64_lor
, cpu
)) {
8419 define_arm_cp_regs(cpu
, lor_reginfo
);
8421 if (cpu_isar_feature(aa64_pan
, cpu
)) {
8422 define_one_arm_cp_reg(cpu
, &pan_reginfo
);
8424 #ifndef CONFIG_USER_ONLY
8425 if (cpu_isar_feature(aa64_ats1e1
, cpu
)) {
8426 define_arm_cp_regs(cpu
, ats1e1_reginfo
);
8428 if (cpu_isar_feature(aa32_ats1e1
, cpu
)) {
8429 define_arm_cp_regs(cpu
, ats1cp_reginfo
);
8432 if (cpu_isar_feature(aa64_uao
, cpu
)) {
8433 define_one_arm_cp_reg(cpu
, &uao_reginfo
);
8436 if (cpu_isar_feature(aa64_dit
, cpu
)) {
8437 define_one_arm_cp_reg(cpu
, &dit_reginfo
);
8439 if (cpu_isar_feature(aa64_ssbs
, cpu
)) {
8440 define_one_arm_cp_reg(cpu
, &ssbs_reginfo
);
8442 if (cpu_isar_feature(any_ras
, cpu
)) {
8443 define_arm_cp_regs(cpu
, minimal_ras_reginfo
);
8446 if (cpu_isar_feature(aa64_vh
, cpu
) ||
8447 cpu_isar_feature(aa64_debugv8p2
, cpu
)) {
8448 define_one_arm_cp_reg(cpu
, &contextidr_el2
);
8450 if (arm_feature(env
, ARM_FEATURE_EL2
) && cpu_isar_feature(aa64_vh
, cpu
)) {
8451 define_arm_cp_regs(cpu
, vhe_reginfo
);
8454 if (cpu_isar_feature(aa64_sve
, cpu
)) {
8455 define_arm_cp_regs(cpu
, zcr_reginfo
);
8458 if (cpu_isar_feature(aa64_hcx
, cpu
)) {
8459 define_one_arm_cp_reg(cpu
, &hcrx_el2_reginfo
);
8462 #ifdef TARGET_AARCH64
8463 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
8464 define_arm_cp_regs(cpu
, pauth_reginfo
);
8466 if (cpu_isar_feature(aa64_rndr
, cpu
)) {
8467 define_arm_cp_regs(cpu
, rndr_reginfo
);
8469 if (cpu_isar_feature(aa64_tlbirange
, cpu
)) {
8470 define_arm_cp_regs(cpu
, tlbirange_reginfo
);
8472 if (cpu_isar_feature(aa64_tlbios
, cpu
)) {
8473 define_arm_cp_regs(cpu
, tlbios_reginfo
);
8475 #ifndef CONFIG_USER_ONLY
8476 /* Data Cache clean instructions up to PoP */
8477 if (cpu_isar_feature(aa64_dcpop
, cpu
)) {
8478 define_one_arm_cp_reg(cpu
, dcpop_reg
);
8480 if (cpu_isar_feature(aa64_dcpodp
, cpu
)) {
8481 define_one_arm_cp_reg(cpu
, dcpodp_reg
);
8484 #endif /*CONFIG_USER_ONLY*/
8487 * If full MTE is enabled, add all of the system registers.
8488 * If only "instructions available at EL0" are enabled,
8489 * then define only a RAZ/WI version of PSTATE.TCO.
8491 if (cpu_isar_feature(aa64_mte
, cpu
)) {
8492 define_arm_cp_regs(cpu
, mte_reginfo
);
8493 define_arm_cp_regs(cpu
, mte_el0_cacheop_reginfo
);
8494 } else if (cpu_isar_feature(aa64_mte_insn_reg
, cpu
)) {
8495 define_arm_cp_regs(cpu
, mte_tco_ro_reginfo
);
8496 define_arm_cp_regs(cpu
, mte_el0_cacheop_reginfo
);
8499 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
8500 define_arm_cp_regs(cpu
, scxtnum_reginfo
);
8504 if (cpu_isar_feature(any_predinv
, cpu
)) {
8505 define_arm_cp_regs(cpu
, predinv_reginfo
);
8508 if (cpu_isar_feature(any_ccidx
, cpu
)) {
8509 define_arm_cp_regs(cpu
, ccsidr2_reginfo
);
8512 #ifndef CONFIG_USER_ONLY
8514 * Register redirections and aliases must be done last,
8515 * after the registers from the other extensions have been defined.
8517 if (arm_feature(env
, ARM_FEATURE_EL2
) && cpu_isar_feature(aa64_vh
, cpu
)) {
8518 define_arm_vh_e2h_redirects_aliases(cpu
);
8523 /* Sort alphabetically by type name, except for "any". */
8524 static gint
arm_cpu_list_compare(gconstpointer a
, gconstpointer b
)
8526 ObjectClass
*class_a
= (ObjectClass
*)a
;
8527 ObjectClass
*class_b
= (ObjectClass
*)b
;
8528 const char *name_a
, *name_b
;
8530 name_a
= object_class_get_name(class_a
);
8531 name_b
= object_class_get_name(class_b
);
8532 if (strcmp(name_a
, "any-" TYPE_ARM_CPU
) == 0) {
8534 } else if (strcmp(name_b
, "any-" TYPE_ARM_CPU
) == 0) {
8537 return strcmp(name_a
, name_b
);
8541 static void arm_cpu_list_entry(gpointer data
, gpointer user_data
)
8543 ObjectClass
*oc
= data
;
8544 const char *typename
;
8547 typename
= object_class_get_name(oc
);
8548 name
= g_strndup(typename
, strlen(typename
) - strlen("-" TYPE_ARM_CPU
));
8549 qemu_printf(" %s\n", name
);
8553 void arm_cpu_list(void)
8557 list
= object_class_get_list(TYPE_ARM_CPU
, false);
8558 list
= g_slist_sort(list
, arm_cpu_list_compare
);
8559 qemu_printf("Available CPUs:\n");
8560 g_slist_foreach(list
, arm_cpu_list_entry
, NULL
);
8564 static void arm_cpu_add_definition(gpointer data
, gpointer user_data
)
8566 ObjectClass
*oc
= data
;
8567 CpuDefinitionInfoList
**cpu_list
= user_data
;
8568 CpuDefinitionInfo
*info
;
8569 const char *typename
;
8571 typename
= object_class_get_name(oc
);
8572 info
= g_malloc0(sizeof(*info
));
8573 info
->name
= g_strndup(typename
,
8574 strlen(typename
) - strlen("-" TYPE_ARM_CPU
));
8575 info
->q_typename
= g_strdup(typename
);
8577 QAPI_LIST_PREPEND(*cpu_list
, info
);
8580 CpuDefinitionInfoList
*qmp_query_cpu_definitions(Error
**errp
)
8582 CpuDefinitionInfoList
*cpu_list
= NULL
;
8585 list
= object_class_get_list(TYPE_ARM_CPU
, false);
8586 g_slist_foreach(list
, arm_cpu_add_definition
, &cpu_list
);
8593 * Private utility function for define_one_arm_cp_reg_with_opaque():
8594 * add a single reginfo struct to the hash table.
8596 static void add_cpreg_to_hashtable(ARMCPU
*cpu
, const ARMCPRegInfo
*r
,
8597 void *opaque
, CPState state
,
8598 CPSecureState secstate
,
8599 int crm
, int opc1
, int opc2
,
8602 CPUARMState
*env
= &cpu
->env
;
8605 bool is64
= r
->type
& ARM_CP_64BIT
;
8606 bool ns
= secstate
& ARM_CP_SECSTATE_NS
;
8612 case ARM_CP_STATE_AA32
:
8613 /* We assume it is a cp15 register if the .cp field is left unset. */
8614 if (cp
== 0 && r
->state
== ARM_CP_STATE_BOTH
) {
8617 key
= ENCODE_CP_REG(cp
, is64
, ns
, r
->crn
, crm
, opc1
, opc2
);
8619 case ARM_CP_STATE_AA64
:
8621 * To allow abbreviation of ARMCPRegInfo definitions, we treat
8622 * cp == 0 as equivalent to the value for "standard guest-visible
8623 * sysreg". STATE_BOTH definitions are also always "standard sysreg"
8624 * in their AArch64 view (the .cp value may be non-zero for the
8625 * benefit of the AArch32 view).
8627 if (cp
== 0 || r
->state
== ARM_CP_STATE_BOTH
) {
8628 cp
= CP_REG_ARM64_SYSREG_CP
;
8630 key
= ENCODE_AA64_CP_REG(cp
, r
->crn
, crm
, r
->opc0
, opc1
, opc2
);
8633 g_assert_not_reached();
8636 /* Overriding of an existing definition must be explicitly requested. */
8637 if (!(r
->type
& ARM_CP_OVERRIDE
)) {
8638 const ARMCPRegInfo
*oldreg
= get_arm_cp_reginfo(cpu
->cp_regs
, key
);
8640 assert(oldreg
->type
& ARM_CP_OVERRIDE
);
8645 * Eliminate registers that are not present because the EL is missing.
8646 * Doing this here makes it easier to put all registers for a given
8647 * feature into the same ARMCPRegInfo array and define them all at once.
8650 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
8652 * An EL2 register without EL2 but with EL3 is (usually) RES0.
8653 * See rule RJFFP in section D1.1.3 of DDI0487H.a.
8655 int min_el
= ctz32(r
->access
) / 2;
8656 if (min_el
== 2 && !arm_feature(env
, ARM_FEATURE_EL2
)) {
8657 if (r
->type
& ARM_CP_EL3_NO_EL2_UNDEF
) {
8660 make_const
= !(r
->type
& ARM_CP_EL3_NO_EL2_KEEP
);
8663 CPAccessRights max_el
= (arm_feature(env
, ARM_FEATURE_EL2
)
8665 if ((r
->access
& max_el
) == 0) {
8670 /* Combine cpreg and name into one allocation. */
8671 name_len
= strlen(name
) + 1;
8672 r2
= g_malloc(sizeof(*r2
) + name_len
);
8674 r2
->name
= memcpy(r2
+ 1, name
, name_len
);
8677 * Update fields to match the instantiation, overwiting wildcards
8678 * such as CP_ANY, ARM_CP_STATE_BOTH, or ARM_CP_SECSTATE_BOTH.
8685 r2
->secure
= secstate
;
8687 r2
->opaque
= opaque
;
8691 /* This should not have been a very special register to begin. */
8692 int old_special
= r2
->type
& ARM_CP_SPECIAL_MASK
;
8693 assert(old_special
== 0 || old_special
== ARM_CP_NOP
);
8695 * Set the special function to CONST, retaining the other flags.
8696 * This is important for e.g. ARM_CP_SVE so that we still
8697 * take the SVE trap if CPTR_EL3.EZ == 0.
8699 r2
->type
= (r2
->type
& ~ARM_CP_SPECIAL_MASK
) | ARM_CP_CONST
;
8701 * Usually, these registers become RES0, but there are a few
8702 * special cases like VPIDR_EL2 which have a constant non-zero
8703 * value with writes ignored.
8705 if (!(r
->type
& ARM_CP_EL3_NO_EL2_C_NZ
)) {
8709 * ARM_CP_CONST has precedence, so removing the callbacks and
8710 * offsets are not strictly necessary, but it is potentially
8711 * less confusing to debug later.
8715 r2
->raw_readfn
= NULL
;
8716 r2
->raw_writefn
= NULL
;
8718 r2
->fieldoffset
= 0;
8719 r2
->bank_fieldoffsets
[0] = 0;
8720 r2
->bank_fieldoffsets
[1] = 0;
8722 bool isbanked
= r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1];
8726 * Register is banked (using both entries in array).
8727 * Overwriting fieldoffset as the array is only used to define
8728 * banked registers but later only fieldoffset is used.
8730 r2
->fieldoffset
= r
->bank_fieldoffsets
[ns
];
8732 if (state
== ARM_CP_STATE_AA32
) {
8735 * If the register is banked then we don't need to migrate or
8736 * reset the 32-bit instance in certain cases:
8738 * 1) If the register has both 32-bit and 64-bit instances
8739 * then we can count on the 64-bit instance taking care
8740 * of the non-secure bank.
8741 * 2) If ARMv8 is enabled then we can count on a 64-bit
8742 * version taking care of the secure bank. This requires
8743 * that separate 32 and 64-bit definitions are provided.
8745 if ((r
->state
== ARM_CP_STATE_BOTH
&& ns
) ||
8746 (arm_feature(env
, ARM_FEATURE_V8
) && !ns
)) {
8747 r2
->type
|= ARM_CP_ALIAS
;
8749 } else if ((secstate
!= r
->secure
) && !ns
) {
8751 * The register is not banked so we only want to allow
8752 * migration of the non-secure instance.
8754 r2
->type
|= ARM_CP_ALIAS
;
8757 if (HOST_BIG_ENDIAN
&&
8758 r
->state
== ARM_CP_STATE_BOTH
&& r2
->fieldoffset
) {
8759 r2
->fieldoffset
+= sizeof(uint32_t);
8765 * By convention, for wildcarded registers only the first
8766 * entry is used for migration; the others are marked as
8767 * ALIAS so we don't try to transfer the register
8768 * multiple times. Special registers (ie NOP/WFI) are
8769 * never migratable and not even raw-accessible.
8771 if (r2
->type
& ARM_CP_SPECIAL_MASK
) {
8772 r2
->type
|= ARM_CP_NO_RAW
;
8774 if (((r
->crm
== CP_ANY
) && crm
!= 0) ||
8775 ((r
->opc1
== CP_ANY
) && opc1
!= 0) ||
8776 ((r
->opc2
== CP_ANY
) && opc2
!= 0)) {
8777 r2
->type
|= ARM_CP_ALIAS
| ARM_CP_NO_GDB
;
8781 * Check that raw accesses are either forbidden or handled. Note that
8782 * we can't assert this earlier because the setup of fieldoffset for
8783 * banked registers has to be done first.
8785 if (!(r2
->type
& ARM_CP_NO_RAW
)) {
8786 assert(!raw_accessors_invalid(r2
));
8789 g_hash_table_insert(cpu
->cp_regs
, (gpointer
)(uintptr_t)key
, r2
);
8793 void define_one_arm_cp_reg_with_opaque(ARMCPU
*cpu
,
8794 const ARMCPRegInfo
*r
, void *opaque
)
8796 /* Define implementations of coprocessor registers.
8797 * We store these in a hashtable because typically
8798 * there are less than 150 registers in a space which
8799 * is 16*16*16*8*8 = 262144 in size.
8800 * Wildcarding is supported for the crm, opc1 and opc2 fields.
8801 * If a register is defined twice then the second definition is
8802 * used, so this can be used to define some generic registers and
8803 * then override them with implementation specific variations.
8804 * At least one of the original and the second definition should
8805 * include ARM_CP_OVERRIDE in its type bits -- this is just a guard
8806 * against accidental use.
8808 * The state field defines whether the register is to be
8809 * visible in the AArch32 or AArch64 execution state. If the
8810 * state is set to ARM_CP_STATE_BOTH then we synthesise a
8811 * reginfo structure for the AArch32 view, which sees the lower
8812 * 32 bits of the 64 bit register.
8814 * Only registers visible in AArch64 may set r->opc0; opc0 cannot
8815 * be wildcarded. AArch64 registers are always considered to be 64
8816 * bits; the ARM_CP_64BIT* flag applies only to the AArch32 view of
8817 * the register, if any.
8819 int crm
, opc1
, opc2
;
8820 int crmmin
= (r
->crm
== CP_ANY
) ? 0 : r
->crm
;
8821 int crmmax
= (r
->crm
== CP_ANY
) ? 15 : r
->crm
;
8822 int opc1min
= (r
->opc1
== CP_ANY
) ? 0 : r
->opc1
;
8823 int opc1max
= (r
->opc1
== CP_ANY
) ? 7 : r
->opc1
;
8824 int opc2min
= (r
->opc2
== CP_ANY
) ? 0 : r
->opc2
;
8825 int opc2max
= (r
->opc2
== CP_ANY
) ? 7 : r
->opc2
;
8828 /* 64 bit registers have only CRm and Opc1 fields */
8829 assert(!((r
->type
& ARM_CP_64BIT
) && (r
->opc2
|| r
->crn
)));
8830 /* op0 only exists in the AArch64 encodings */
8831 assert((r
->state
!= ARM_CP_STATE_AA32
) || (r
->opc0
== 0));
8832 /* AArch64 regs are all 64 bit so ARM_CP_64BIT is meaningless */
8833 assert((r
->state
!= ARM_CP_STATE_AA64
) || !(r
->type
& ARM_CP_64BIT
));
8835 * This API is only for Arm's system coprocessors (14 and 15) or
8836 * (M-profile or v7A-and-earlier only) for implementation defined
8837 * coprocessors in the range 0..7. Our decode assumes this, since
8838 * 8..13 can be used for other insns including VFP and Neon. See
8839 * valid_cp() in translate.c. Assert here that we haven't tried
8840 * to use an invalid coprocessor number.
8843 case ARM_CP_STATE_BOTH
:
8844 /* 0 has a special meaning, but otherwise the same rules as AA32. */
8849 case ARM_CP_STATE_AA32
:
8850 if (arm_feature(&cpu
->env
, ARM_FEATURE_V8
) &&
8851 !arm_feature(&cpu
->env
, ARM_FEATURE_M
)) {
8852 assert(r
->cp
>= 14 && r
->cp
<= 15);
8854 assert(r
->cp
< 8 || (r
->cp
>= 14 && r
->cp
<= 15));
8857 case ARM_CP_STATE_AA64
:
8858 assert(r
->cp
== 0 || r
->cp
== CP_REG_ARM64_SYSREG_CP
);
8861 g_assert_not_reached();
8863 /* The AArch64 pseudocode CheckSystemAccess() specifies that op1
8864 * encodes a minimum access level for the register. We roll this
8865 * runtime check into our general permission check code, so check
8866 * here that the reginfo's specified permissions are strict enough
8867 * to encompass the generic architectural permission check.
8869 if (r
->state
!= ARM_CP_STATE_AA32
) {
8870 CPAccessRights mask
;
8873 /* min_EL EL1, but some accessible to EL0 via kernel ABI */
8874 mask
= PL0U_R
| PL1_RW
;
8894 /* min_EL EL1, secure mode only (we don't check the latter) */
8898 /* broken reginfo with out-of-range opc1 */
8899 g_assert_not_reached();
8901 /* assert our permissions are not too lax (stricter is fine) */
8902 assert((r
->access
& ~mask
) == 0);
8905 /* Check that the register definition has enough info to handle
8906 * reads and writes if they are permitted.
8908 if (!(r
->type
& (ARM_CP_SPECIAL_MASK
| ARM_CP_CONST
))) {
8909 if (r
->access
& PL3_R
) {
8910 assert((r
->fieldoffset
||
8911 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
8914 if (r
->access
& PL3_W
) {
8915 assert((r
->fieldoffset
||
8916 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
8921 for (crm
= crmmin
; crm
<= crmmax
; crm
++) {
8922 for (opc1
= opc1min
; opc1
<= opc1max
; opc1
++) {
8923 for (opc2
= opc2min
; opc2
<= opc2max
; opc2
++) {
8924 for (state
= ARM_CP_STATE_AA32
;
8925 state
<= ARM_CP_STATE_AA64
; state
++) {
8926 if (r
->state
!= state
&& r
->state
!= ARM_CP_STATE_BOTH
) {
8929 if (state
== ARM_CP_STATE_AA32
) {
8930 /* Under AArch32 CP registers can be common
8931 * (same for secure and non-secure world) or banked.
8935 switch (r
->secure
) {
8936 case ARM_CP_SECSTATE_S
:
8937 case ARM_CP_SECSTATE_NS
:
8938 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
8939 r
->secure
, crm
, opc1
, opc2
,
8942 case ARM_CP_SECSTATE_BOTH
:
8943 name
= g_strdup_printf("%s_S", r
->name
);
8944 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
8946 crm
, opc1
, opc2
, name
);
8948 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
8950 crm
, opc1
, opc2
, r
->name
);
8953 g_assert_not_reached();
8956 /* AArch64 registers get mapped to non-secure instance
8958 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
8960 crm
, opc1
, opc2
, r
->name
);
8968 /* Define a whole list of registers */
8969 void define_arm_cp_regs_with_opaque_len(ARMCPU
*cpu
, const ARMCPRegInfo
*regs
,
8970 void *opaque
, size_t len
)
8973 for (i
= 0; i
< len
; ++i
) {
8974 define_one_arm_cp_reg_with_opaque(cpu
, regs
+ i
, opaque
);
8979 * Modify ARMCPRegInfo for access from userspace.
8981 * This is a data driven modification directed by
8982 * ARMCPRegUserSpaceInfo. All registers become ARM_CP_CONST as
8983 * user-space cannot alter any values and dynamic values pertaining to
8984 * execution state are hidden from user space view anyway.
8986 void modify_arm_cp_regs_with_len(ARMCPRegInfo
*regs
, size_t regs_len
,
8987 const ARMCPRegUserSpaceInfo
*mods
,
8990 for (size_t mi
= 0; mi
< mods_len
; ++mi
) {
8991 const ARMCPRegUserSpaceInfo
*m
= mods
+ mi
;
8992 GPatternSpec
*pat
= NULL
;
8995 pat
= g_pattern_spec_new(m
->name
);
8997 for (size_t ri
= 0; ri
< regs_len
; ++ri
) {
8998 ARMCPRegInfo
*r
= regs
+ ri
;
9000 if (pat
&& g_pattern_match_string(pat
, r
->name
)) {
9001 r
->type
= ARM_CP_CONST
;
9005 } else if (strcmp(r
->name
, m
->name
) == 0) {
9006 r
->type
= ARM_CP_CONST
;
9008 r
->resetvalue
&= m
->exported_bits
;
9009 r
->resetvalue
|= m
->fixed_bits
;
9014 g_pattern_spec_free(pat
);
9019 const ARMCPRegInfo
*get_arm_cp_reginfo(GHashTable
*cpregs
, uint32_t encoded_cp
)
9021 return g_hash_table_lookup(cpregs
, (gpointer
)(uintptr_t)encoded_cp
);
9024 void arm_cp_write_ignore(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
9027 /* Helper coprocessor write function for write-ignore registers */
9030 uint64_t arm_cp_read_zero(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
9032 /* Helper coprocessor write function for read-as-zero registers */
9036 void arm_cp_reset_ignore(CPUARMState
*env
, const ARMCPRegInfo
*opaque
)
9038 /* Helper coprocessor reset function for do-nothing-on-reset registers */
9041 static int bad_mode_switch(CPUARMState
*env
, int mode
, CPSRWriteType write_type
)
9043 /* Return true if it is not valid for us to switch to
9044 * this CPU mode (ie all the UNPREDICTABLE cases in
9045 * the ARM ARM CPSRWriteByInstr pseudocode).
9048 /* Changes to or from Hyp via MSR and CPS are illegal. */
9049 if (write_type
== CPSRWriteByInstr
&&
9050 ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_HYP
||
9051 mode
== ARM_CPU_MODE_HYP
)) {
9056 case ARM_CPU_MODE_USR
:
9058 case ARM_CPU_MODE_SYS
:
9059 case ARM_CPU_MODE_SVC
:
9060 case ARM_CPU_MODE_ABT
:
9061 case ARM_CPU_MODE_UND
:
9062 case ARM_CPU_MODE_IRQ
:
9063 case ARM_CPU_MODE_FIQ
:
9064 /* Note that we don't implement the IMPDEF NSACR.RFR which in v7
9065 * allows FIQ mode to be Secure-only. (In v8 this doesn't exist.)
9067 /* If HCR.TGE is set then changes from Monitor to NS PL1 via MSR
9068 * and CPS are treated as illegal mode changes.
9070 if (write_type
== CPSRWriteByInstr
&&
9071 (env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
&&
9072 (arm_hcr_el2_eff(env
) & HCR_TGE
)) {
9076 case ARM_CPU_MODE_HYP
:
9077 return !arm_is_el2_enabled(env
) || arm_current_el(env
) < 2;
9078 case ARM_CPU_MODE_MON
:
9079 return arm_current_el(env
) < 3;
9085 uint32_t cpsr_read(CPUARMState
*env
)
9088 ZF
= (env
->ZF
== 0);
9089 return env
->uncached_cpsr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
9090 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3) | (env
->QF
<< 27)
9091 | (env
->thumb
<< 5) | ((env
->condexec_bits
& 3) << 25)
9092 | ((env
->condexec_bits
& 0xfc) << 8)
9093 | (env
->GE
<< 16) | (env
->daif
& CPSR_AIF
);
9096 void cpsr_write(CPUARMState
*env
, uint32_t val
, uint32_t mask
,
9097 CPSRWriteType write_type
)
9099 uint32_t changed_daif
;
9100 bool rebuild_hflags
= (write_type
!= CPSRWriteRaw
) &&
9101 (mask
& (CPSR_M
| CPSR_E
| CPSR_IL
));
9103 if (mask
& CPSR_NZCV
) {
9104 env
->ZF
= (~val
) & CPSR_Z
;
9106 env
->CF
= (val
>> 29) & 1;
9107 env
->VF
= (val
<< 3) & 0x80000000;
9110 env
->QF
= ((val
& CPSR_Q
) != 0);
9112 env
->thumb
= ((val
& CPSR_T
) != 0);
9113 if (mask
& CPSR_IT_0_1
) {
9114 env
->condexec_bits
&= ~3;
9115 env
->condexec_bits
|= (val
>> 25) & 3;
9117 if (mask
& CPSR_IT_2_7
) {
9118 env
->condexec_bits
&= 3;
9119 env
->condexec_bits
|= (val
>> 8) & 0xfc;
9121 if (mask
& CPSR_GE
) {
9122 env
->GE
= (val
>> 16) & 0xf;
9125 /* In a V7 implementation that includes the security extensions but does
9126 * not include Virtualization Extensions the SCR.FW and SCR.AW bits control
9127 * whether non-secure software is allowed to change the CPSR_F and CPSR_A
9128 * bits respectively.
9130 * In a V8 implementation, it is permitted for privileged software to
9131 * change the CPSR A/F bits regardless of the SCR.AW/FW bits.
9133 if (write_type
!= CPSRWriteRaw
&& !arm_feature(env
, ARM_FEATURE_V8
) &&
9134 arm_feature(env
, ARM_FEATURE_EL3
) &&
9135 !arm_feature(env
, ARM_FEATURE_EL2
) &&
9136 !arm_is_secure(env
)) {
9138 changed_daif
= (env
->daif
^ val
) & mask
;
9140 if (changed_daif
& CPSR_A
) {
9141 /* Check to see if we are allowed to change the masking of async
9142 * abort exceptions from a non-secure state.
9144 if (!(env
->cp15
.scr_el3
& SCR_AW
)) {
9145 qemu_log_mask(LOG_GUEST_ERROR
,
9146 "Ignoring attempt to switch CPSR_A flag from "
9147 "non-secure world with SCR.AW bit clear\n");
9152 if (changed_daif
& CPSR_F
) {
9153 /* Check to see if we are allowed to change the masking of FIQ
9154 * exceptions from a non-secure state.
9156 if (!(env
->cp15
.scr_el3
& SCR_FW
)) {
9157 qemu_log_mask(LOG_GUEST_ERROR
,
9158 "Ignoring attempt to switch CPSR_F flag from "
9159 "non-secure world with SCR.FW bit clear\n");
9163 /* Check whether non-maskable FIQ (NMFI) support is enabled.
9164 * If this bit is set software is not allowed to mask
9165 * FIQs, but is allowed to set CPSR_F to 0.
9167 if ((A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_NMFI
) &&
9169 qemu_log_mask(LOG_GUEST_ERROR
,
9170 "Ignoring attempt to enable CPSR_F flag "
9171 "(non-maskable FIQ [NMFI] support enabled)\n");
9177 env
->daif
&= ~(CPSR_AIF
& mask
);
9178 env
->daif
|= val
& CPSR_AIF
& mask
;
9180 if (write_type
!= CPSRWriteRaw
&&
9181 ((env
->uncached_cpsr
^ val
) & mask
& CPSR_M
)) {
9182 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_USR
) {
9183 /* Note that we can only get here in USR mode if this is a
9184 * gdb stub write; for this case we follow the architectural
9185 * behaviour for guest writes in USR mode of ignoring an attempt
9186 * to switch mode. (Those are caught by translate.c for writes
9187 * triggered by guest instructions.)
9190 } else if (bad_mode_switch(env
, val
& CPSR_M
, write_type
)) {
9191 /* Attempt to switch to an invalid mode: this is UNPREDICTABLE in
9192 * v7, and has defined behaviour in v8:
9193 * + leave CPSR.M untouched
9194 * + allow changes to the other CPSR fields
9196 * For user changes via the GDB stub, we don't set PSTATE.IL,
9197 * as this would be unnecessarily harsh for a user error.
9200 if (write_type
!= CPSRWriteByGDBStub
&&
9201 arm_feature(env
, ARM_FEATURE_V8
)) {
9205 qemu_log_mask(LOG_GUEST_ERROR
,
9206 "Illegal AArch32 mode switch attempt from %s to %s\n",
9207 aarch32_mode_name(env
->uncached_cpsr
),
9208 aarch32_mode_name(val
));
9210 qemu_log_mask(CPU_LOG_INT
, "%s %s to %s PC 0x%" PRIx32
"\n",
9211 write_type
== CPSRWriteExceptionReturn
?
9212 "Exception return from AArch32" :
9213 "AArch32 mode switch from",
9214 aarch32_mode_name(env
->uncached_cpsr
),
9215 aarch32_mode_name(val
), env
->regs
[15]);
9216 switch_mode(env
, val
& CPSR_M
);
9219 mask
&= ~CACHED_CPSR_BITS
;
9220 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~mask
) | (val
& mask
);
9221 if (rebuild_hflags
) {
9222 arm_rebuild_hflags(env
);
9226 /* Sign/zero extend */
9227 uint32_t HELPER(sxtb16
)(uint32_t x
)
9230 res
= (uint16_t)(int8_t)x
;
9231 res
|= (uint32_t)(int8_t)(x
>> 16) << 16;
9235 static void handle_possible_div0_trap(CPUARMState
*env
, uintptr_t ra
)
9238 * Take a division-by-zero exception if necessary; otherwise return
9239 * to get the usual non-trapping division behaviour (result of 0)
9241 if (arm_feature(env
, ARM_FEATURE_M
)
9242 && (env
->v7m
.ccr
[env
->v7m
.secure
] & R_V7M_CCR_DIV_0_TRP_MASK
)) {
9243 raise_exception_ra(env
, EXCP_DIVBYZERO
, 0, 1, ra
);
9247 uint32_t HELPER(uxtb16
)(uint32_t x
)
9250 res
= (uint16_t)(uint8_t)x
;
9251 res
|= (uint32_t)(uint8_t)(x
>> 16) << 16;
9255 int32_t HELPER(sdiv
)(CPUARMState
*env
, int32_t num
, int32_t den
)
9258 handle_possible_div0_trap(env
, GETPC());
9261 if (num
== INT_MIN
&& den
== -1) {
9267 uint32_t HELPER(udiv
)(CPUARMState
*env
, uint32_t num
, uint32_t den
)
9270 handle_possible_div0_trap(env
, GETPC());
9276 uint32_t HELPER(rbit
)(uint32_t x
)
9281 #ifdef CONFIG_USER_ONLY
9283 static void switch_mode(CPUARMState
*env
, int mode
)
9285 ARMCPU
*cpu
= env_archcpu(env
);
9287 if (mode
!= ARM_CPU_MODE_USR
) {
9288 cpu_abort(CPU(cpu
), "Tried to switch out of user mode\n");
9292 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
9293 uint32_t cur_el
, bool secure
)
9298 void aarch64_sync_64_to_32(CPUARMState
*env
)
9300 g_assert_not_reached();
9305 static void switch_mode(CPUARMState
*env
, int mode
)
9310 old_mode
= env
->uncached_cpsr
& CPSR_M
;
9311 if (mode
== old_mode
)
9314 if (old_mode
== ARM_CPU_MODE_FIQ
) {
9315 memcpy (env
->fiq_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
9316 memcpy (env
->regs
+ 8, env
->usr_regs
, 5 * sizeof(uint32_t));
9317 } else if (mode
== ARM_CPU_MODE_FIQ
) {
9318 memcpy (env
->usr_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
9319 memcpy (env
->regs
+ 8, env
->fiq_regs
, 5 * sizeof(uint32_t));
9322 i
= bank_number(old_mode
);
9323 env
->banked_r13
[i
] = env
->regs
[13];
9324 env
->banked_spsr
[i
] = env
->spsr
;
9326 i
= bank_number(mode
);
9327 env
->regs
[13] = env
->banked_r13
[i
];
9328 env
->spsr
= env
->banked_spsr
[i
];
9330 env
->banked_r14
[r14_bank_number(old_mode
)] = env
->regs
[14];
9331 env
->regs
[14] = env
->banked_r14
[r14_bank_number(mode
)];
9334 /* Physical Interrupt Target EL Lookup Table
9336 * [ From ARM ARM section G1.13.4 (Table G1-15) ]
9338 * The below multi-dimensional table is used for looking up the target
9339 * exception level given numerous condition criteria. Specifically, the
9340 * target EL is based on SCR and HCR routing controls as well as the
9341 * currently executing EL and secure state.
9344 * target_el_table[2][2][2][2][2][4]
9345 * | | | | | +--- Current EL
9346 * | | | | +------ Non-secure(0)/Secure(1)
9347 * | | | +--------- HCR mask override
9348 * | | +------------ SCR exec state control
9349 * | +--------------- SCR mask override
9350 * +------------------ 32-bit(0)/64-bit(1) EL3
9352 * The table values are as such:
9356 * The ARM ARM target EL table includes entries indicating that an "exception
9357 * is not taken". The two cases where this is applicable are:
9358 * 1) An exception is taken from EL3 but the SCR does not have the exception
9360 * 2) An exception is taken from EL2 but the HCR does not have the exception
9362 * In these two cases, the below table contain a target of EL1. This value is
9363 * returned as it is expected that the consumer of the table data will check
9364 * for "target EL >= current EL" to ensure the exception is not taken.
9368 * BIT IRQ IMO Non-secure Secure
9369 * EL3 FIQ RW FMO EL0 EL1 EL2 EL3 EL0 EL1 EL2 EL3
9371 static const int8_t target_el_table
[2][2][2][2][2][4] = {
9372 {{{{/* 0 0 0 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
9373 {/* 0 0 0 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},
9374 {{/* 0 0 1 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
9375 {/* 0 0 1 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},},
9376 {{{/* 0 1 0 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
9377 {/* 0 1 0 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},
9378 {{/* 0 1 1 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
9379 {/* 0 1 1 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},},},
9380 {{{{/* 1 0 0 0 */{ 1, 1, 2, -1 },{ 1, 1, -1, 1 },},
9381 {/* 1 0 0 1 */{ 2, 2, 2, -1 },{ 2, 2, -1, 1 },},},
9382 {{/* 1 0 1 0 */{ 1, 1, 1, -1 },{ 1, 1, 1, 1 },},
9383 {/* 1 0 1 1 */{ 2, 2, 2, -1 },{ 2, 2, 2, 1 },},},},
9384 {{{/* 1 1 0 0 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},
9385 {/* 1 1 0 1 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},},
9386 {{/* 1 1 1 0 */{ 3, 3, 3, -1 },{ 3, 3, 3, 3 },},
9387 {/* 1 1 1 1 */{ 3, 3, 3, -1 },{ 3, 3, 3, 3 },},},},},
9391 * Determine the target EL for physical exceptions
9393 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
9394 uint32_t cur_el
, bool secure
)
9396 CPUARMState
*env
= cs
->env_ptr
;
9401 /* Is the highest EL AArch64? */
9402 bool is64
= arm_feature(env
, ARM_FEATURE_AARCH64
);
9405 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
9406 rw
= ((env
->cp15
.scr_el3
& SCR_RW
) == SCR_RW
);
9408 /* Either EL2 is the highest EL (and so the EL2 register width
9409 * is given by is64); or there is no EL2 or EL3, in which case
9410 * the value of 'rw' does not affect the table lookup anyway.
9415 hcr_el2
= arm_hcr_el2_eff(env
);
9418 scr
= ((env
->cp15
.scr_el3
& SCR_IRQ
) == SCR_IRQ
);
9419 hcr
= hcr_el2
& HCR_IMO
;
9422 scr
= ((env
->cp15
.scr_el3
& SCR_FIQ
) == SCR_FIQ
);
9423 hcr
= hcr_el2
& HCR_FMO
;
9426 scr
= ((env
->cp15
.scr_el3
& SCR_EA
) == SCR_EA
);
9427 hcr
= hcr_el2
& HCR_AMO
;
9432 * For these purposes, TGE and AMO/IMO/FMO both force the
9433 * interrupt to EL2. Fold TGE into the bit extracted above.
9435 hcr
|= (hcr_el2
& HCR_TGE
) != 0;
9437 /* Perform a table-lookup for the target EL given the current state */
9438 target_el
= target_el_table
[is64
][scr
][rw
][hcr
][secure
][cur_el
];
9440 assert(target_el
> 0);
9445 void arm_log_exception(CPUState
*cs
)
9447 int idx
= cs
->exception_index
;
9449 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
9450 const char *exc
= NULL
;
9451 static const char * const excnames
[] = {
9452 [EXCP_UDEF
] = "Undefined Instruction",
9454 [EXCP_PREFETCH_ABORT
] = "Prefetch Abort",
9455 [EXCP_DATA_ABORT
] = "Data Abort",
9458 [EXCP_BKPT
] = "Breakpoint",
9459 [EXCP_EXCEPTION_EXIT
] = "QEMU v7M exception exit",
9460 [EXCP_KERNEL_TRAP
] = "QEMU intercept of kernel commpage",
9461 [EXCP_HVC
] = "Hypervisor Call",
9462 [EXCP_HYP_TRAP
] = "Hypervisor Trap",
9463 [EXCP_SMC
] = "Secure Monitor Call",
9464 [EXCP_VIRQ
] = "Virtual IRQ",
9465 [EXCP_VFIQ
] = "Virtual FIQ",
9466 [EXCP_SEMIHOST
] = "Semihosting call",
9467 [EXCP_NOCP
] = "v7M NOCP UsageFault",
9468 [EXCP_INVSTATE
] = "v7M INVSTATE UsageFault",
9469 [EXCP_STKOF
] = "v8M STKOF UsageFault",
9470 [EXCP_LAZYFP
] = "v7M exception during lazy FP stacking",
9471 [EXCP_LSERR
] = "v8M LSERR UsageFault",
9472 [EXCP_UNALIGNED
] = "v7M UNALIGNED UsageFault",
9473 [EXCP_DIVBYZERO
] = "v7M DIVBYZERO UsageFault",
9474 [EXCP_VSERR
] = "Virtual SERR",
9477 if (idx
>= 0 && idx
< ARRAY_SIZE(excnames
)) {
9478 exc
= excnames
[idx
];
9483 qemu_log_mask(CPU_LOG_INT
, "Taking exception %d [%s] on CPU %d\n",
9484 idx
, exc
, cs
->cpu_index
);
9489 * Function used to synchronize QEMU's AArch64 register set with AArch32
9490 * register set. This is necessary when switching between AArch32 and AArch64
9493 void aarch64_sync_32_to_64(CPUARMState
*env
)
9496 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
9498 /* We can blanket copy R[0:7] to X[0:7] */
9499 for (i
= 0; i
< 8; i
++) {
9500 env
->xregs
[i
] = env
->regs
[i
];
9504 * Unless we are in FIQ mode, x8-x12 come from the user registers r8-r12.
9505 * Otherwise, they come from the banked user regs.
9507 if (mode
== ARM_CPU_MODE_FIQ
) {
9508 for (i
= 8; i
< 13; i
++) {
9509 env
->xregs
[i
] = env
->usr_regs
[i
- 8];
9512 for (i
= 8; i
< 13; i
++) {
9513 env
->xregs
[i
] = env
->regs
[i
];
9518 * Registers x13-x23 are the various mode SP and FP registers. Registers
9519 * r13 and r14 are only copied if we are in that mode, otherwise we copy
9520 * from the mode banked register.
9522 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
9523 env
->xregs
[13] = env
->regs
[13];
9524 env
->xregs
[14] = env
->regs
[14];
9526 env
->xregs
[13] = env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)];
9527 /* HYP is an exception in that it is copied from r14 */
9528 if (mode
== ARM_CPU_MODE_HYP
) {
9529 env
->xregs
[14] = env
->regs
[14];
9531 env
->xregs
[14] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_USR
)];
9535 if (mode
== ARM_CPU_MODE_HYP
) {
9536 env
->xregs
[15] = env
->regs
[13];
9538 env
->xregs
[15] = env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)];
9541 if (mode
== ARM_CPU_MODE_IRQ
) {
9542 env
->xregs
[16] = env
->regs
[14];
9543 env
->xregs
[17] = env
->regs
[13];
9545 env
->xregs
[16] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_IRQ
)];
9546 env
->xregs
[17] = env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)];
9549 if (mode
== ARM_CPU_MODE_SVC
) {
9550 env
->xregs
[18] = env
->regs
[14];
9551 env
->xregs
[19] = env
->regs
[13];
9553 env
->xregs
[18] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_SVC
)];
9554 env
->xregs
[19] = env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)];
9557 if (mode
== ARM_CPU_MODE_ABT
) {
9558 env
->xregs
[20] = env
->regs
[14];
9559 env
->xregs
[21] = env
->regs
[13];
9561 env
->xregs
[20] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_ABT
)];
9562 env
->xregs
[21] = env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)];
9565 if (mode
== ARM_CPU_MODE_UND
) {
9566 env
->xregs
[22] = env
->regs
[14];
9567 env
->xregs
[23] = env
->regs
[13];
9569 env
->xregs
[22] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_UND
)];
9570 env
->xregs
[23] = env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)];
9574 * Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
9575 * mode, then we can copy from r8-r14. Otherwise, we copy from the
9576 * FIQ bank for r8-r14.
9578 if (mode
== ARM_CPU_MODE_FIQ
) {
9579 for (i
= 24; i
< 31; i
++) {
9580 env
->xregs
[i
] = env
->regs
[i
- 16]; /* X[24:30] <- R[8:14] */
9583 for (i
= 24; i
< 29; i
++) {
9584 env
->xregs
[i
] = env
->fiq_regs
[i
- 24];
9586 env
->xregs
[29] = env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)];
9587 env
->xregs
[30] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_FIQ
)];
9590 env
->pc
= env
->regs
[15];
9594 * Function used to synchronize QEMU's AArch32 register set with AArch64
9595 * register set. This is necessary when switching between AArch32 and AArch64
9598 void aarch64_sync_64_to_32(CPUARMState
*env
)
9601 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
9603 /* We can blanket copy X[0:7] to R[0:7] */
9604 for (i
= 0; i
< 8; i
++) {
9605 env
->regs
[i
] = env
->xregs
[i
];
9609 * Unless we are in FIQ mode, r8-r12 come from the user registers x8-x12.
9610 * Otherwise, we copy x8-x12 into the banked user regs.
9612 if (mode
== ARM_CPU_MODE_FIQ
) {
9613 for (i
= 8; i
< 13; i
++) {
9614 env
->usr_regs
[i
- 8] = env
->xregs
[i
];
9617 for (i
= 8; i
< 13; i
++) {
9618 env
->regs
[i
] = env
->xregs
[i
];
9623 * Registers r13 & r14 depend on the current mode.
9624 * If we are in a given mode, we copy the corresponding x registers to r13
9625 * and r14. Otherwise, we copy the x register to the banked r13 and r14
9628 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
9629 env
->regs
[13] = env
->xregs
[13];
9630 env
->regs
[14] = env
->xregs
[14];
9632 env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[13];
9635 * HYP is an exception in that it does not have its own banked r14 but
9636 * shares the USR r14
9638 if (mode
== ARM_CPU_MODE_HYP
) {
9639 env
->regs
[14] = env
->xregs
[14];
9641 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[14];
9645 if (mode
== ARM_CPU_MODE_HYP
) {
9646 env
->regs
[13] = env
->xregs
[15];
9648 env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)] = env
->xregs
[15];
9651 if (mode
== ARM_CPU_MODE_IRQ
) {
9652 env
->regs
[14] = env
->xregs
[16];
9653 env
->regs
[13] = env
->xregs
[17];
9655 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[16];
9656 env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[17];
9659 if (mode
== ARM_CPU_MODE_SVC
) {
9660 env
->regs
[14] = env
->xregs
[18];
9661 env
->regs
[13] = env
->xregs
[19];
9663 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[18];
9664 env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[19];
9667 if (mode
== ARM_CPU_MODE_ABT
) {
9668 env
->regs
[14] = env
->xregs
[20];
9669 env
->regs
[13] = env
->xregs
[21];
9671 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[20];
9672 env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[21];
9675 if (mode
== ARM_CPU_MODE_UND
) {
9676 env
->regs
[14] = env
->xregs
[22];
9677 env
->regs
[13] = env
->xregs
[23];
9679 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[22];
9680 env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[23];
9683 /* Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
9684 * mode, then we can copy to r8-r14. Otherwise, we copy to the
9685 * FIQ bank for r8-r14.
9687 if (mode
== ARM_CPU_MODE_FIQ
) {
9688 for (i
= 24; i
< 31; i
++) {
9689 env
->regs
[i
- 16] = env
->xregs
[i
]; /* X[24:30] -> R[8:14] */
9692 for (i
= 24; i
< 29; i
++) {
9693 env
->fiq_regs
[i
- 24] = env
->xregs
[i
];
9695 env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[29];
9696 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[30];
9699 env
->regs
[15] = env
->pc
;
9702 static void take_aarch32_exception(CPUARMState
*env
, int new_mode
,
9703 uint32_t mask
, uint32_t offset
,
9708 /* Change the CPU state so as to actually take the exception. */
9709 switch_mode(env
, new_mode
);
9712 * For exceptions taken to AArch32 we must clear the SS bit in both
9713 * PSTATE and in the old-state value we save to SPSR_<mode>, so zero it now.
9715 env
->pstate
&= ~PSTATE_SS
;
9716 env
->spsr
= cpsr_read(env
);
9717 /* Clear IT bits. */
9718 env
->condexec_bits
= 0;
9719 /* Switch to the new mode, and to the correct instruction set. */
9720 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~CPSR_M
) | new_mode
;
9722 /* This must be after mode switching. */
9723 new_el
= arm_current_el(env
);
9725 /* Set new mode endianness */
9726 env
->uncached_cpsr
&= ~CPSR_E
;
9727 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_EE
) {
9728 env
->uncached_cpsr
|= CPSR_E
;
9730 /* J and IL must always be cleared for exception entry */
9731 env
->uncached_cpsr
&= ~(CPSR_IL
| CPSR_J
);
9734 if (cpu_isar_feature(aa32_ssbs
, env_archcpu(env
))) {
9735 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_DSSBS_32
) {
9736 env
->uncached_cpsr
|= CPSR_SSBS
;
9738 env
->uncached_cpsr
&= ~CPSR_SSBS
;
9742 if (new_mode
== ARM_CPU_MODE_HYP
) {
9743 env
->thumb
= (env
->cp15
.sctlr_el
[2] & SCTLR_TE
) != 0;
9744 env
->elr_el
[2] = env
->regs
[15];
9746 /* CPSR.PAN is normally preserved preserved unless... */
9747 if (cpu_isar_feature(aa32_pan
, env_archcpu(env
))) {
9750 if (!arm_is_secure_below_el3(env
)) {
9751 /* ... the target is EL3, from non-secure state. */
9752 env
->uncached_cpsr
&= ~CPSR_PAN
;
9755 /* ... the target is EL3, from secure state ... */
9758 /* ... the target is EL1 and SCTLR.SPAN is 0. */
9759 if (!(env
->cp15
.sctlr_el
[new_el
] & SCTLR_SPAN
)) {
9760 env
->uncached_cpsr
|= CPSR_PAN
;
9766 * this is a lie, as there was no c1_sys on V4T/V5, but who cares
9767 * and we should just guard the thumb mode on V4
9769 if (arm_feature(env
, ARM_FEATURE_V4T
)) {
9771 (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_TE
) != 0;
9773 env
->regs
[14] = env
->regs
[15] + offset
;
9775 env
->regs
[15] = newpc
;
9776 arm_rebuild_hflags(env
);
9779 static void arm_cpu_do_interrupt_aarch32_hyp(CPUState
*cs
)
9782 * Handle exception entry to Hyp mode; this is sufficiently
9783 * different to entry to other AArch32 modes that we handle it
9786 * The vector table entry used is always the 0x14 Hyp mode entry point,
9787 * unless this is an UNDEF/SVC/HVC/abort taken from Hyp to Hyp.
9788 * The offset applied to the preferred return address is always zero
9789 * (see DDI0487C.a section G1.12.3).
9790 * PSTATE A/I/F masks are set based only on the SCR.EA/IRQ/FIQ values.
9792 uint32_t addr
, mask
;
9793 ARMCPU
*cpu
= ARM_CPU(cs
);
9794 CPUARMState
*env
= &cpu
->env
;
9796 switch (cs
->exception_index
) {
9804 /* Fall through to prefetch abort. */
9805 case EXCP_PREFETCH_ABORT
:
9806 env
->cp15
.ifar_s
= env
->exception
.vaddress
;
9807 qemu_log_mask(CPU_LOG_INT
, "...with HIFAR 0x%x\n",
9808 (uint32_t)env
->exception
.vaddress
);
9811 case EXCP_DATA_ABORT
:
9812 env
->cp15
.dfar_s
= env
->exception
.vaddress
;
9813 qemu_log_mask(CPU_LOG_INT
, "...with HDFAR 0x%x\n",
9814 (uint32_t)env
->exception
.vaddress
);
9830 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
9833 if (cs
->exception_index
!= EXCP_IRQ
&& cs
->exception_index
!= EXCP_FIQ
) {
9834 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
9836 * QEMU syndrome values are v8-style. v7 has the IL bit
9837 * UNK/SBZP for "field not valid" cases, where v8 uses RES1.
9838 * If this is a v7 CPU, squash the IL bit in those cases.
9840 if (cs
->exception_index
== EXCP_PREFETCH_ABORT
||
9841 (cs
->exception_index
== EXCP_DATA_ABORT
&&
9842 !(env
->exception
.syndrome
& ARM_EL_ISV
)) ||
9843 syn_get_ec(env
->exception
.syndrome
) == EC_UNCATEGORIZED
) {
9844 env
->exception
.syndrome
&= ~ARM_EL_IL
;
9847 env
->cp15
.esr_el
[2] = env
->exception
.syndrome
;
9850 if (arm_current_el(env
) != 2 && addr
< 0x14) {
9855 if (!(env
->cp15
.scr_el3
& SCR_EA
)) {
9858 if (!(env
->cp15
.scr_el3
& SCR_IRQ
)) {
9861 if (!(env
->cp15
.scr_el3
& SCR_FIQ
)) {
9865 addr
+= env
->cp15
.hvbar
;
9867 take_aarch32_exception(env
, ARM_CPU_MODE_HYP
, mask
, 0, addr
);
9870 static void arm_cpu_do_interrupt_aarch32(CPUState
*cs
)
9872 ARMCPU
*cpu
= ARM_CPU(cs
);
9873 CPUARMState
*env
= &cpu
->env
;
9880 /* If this is a debug exception we must update the DBGDSCR.MOE bits */
9881 switch (syn_get_ec(env
->exception
.syndrome
)) {
9883 case EC_BREAKPOINT_SAME_EL
:
9887 case EC_WATCHPOINT_SAME_EL
:
9893 case EC_VECTORCATCH
:
9902 env
->cp15
.mdscr_el1
= deposit64(env
->cp15
.mdscr_el1
, 2, 4, moe
);
9905 if (env
->exception
.target_el
== 2) {
9906 arm_cpu_do_interrupt_aarch32_hyp(cs
);
9910 switch (cs
->exception_index
) {
9912 new_mode
= ARM_CPU_MODE_UND
;
9921 new_mode
= ARM_CPU_MODE_SVC
;
9924 /* The PC already points to the next instruction. */
9928 /* Fall through to prefetch abort. */
9929 case EXCP_PREFETCH_ABORT
:
9930 A32_BANKED_CURRENT_REG_SET(env
, ifsr
, env
->exception
.fsr
);
9931 A32_BANKED_CURRENT_REG_SET(env
, ifar
, env
->exception
.vaddress
);
9932 qemu_log_mask(CPU_LOG_INT
, "...with IFSR 0x%x IFAR 0x%x\n",
9933 env
->exception
.fsr
, (uint32_t)env
->exception
.vaddress
);
9934 new_mode
= ARM_CPU_MODE_ABT
;
9936 mask
= CPSR_A
| CPSR_I
;
9939 case EXCP_DATA_ABORT
:
9940 A32_BANKED_CURRENT_REG_SET(env
, dfsr
, env
->exception
.fsr
);
9941 A32_BANKED_CURRENT_REG_SET(env
, dfar
, env
->exception
.vaddress
);
9942 qemu_log_mask(CPU_LOG_INT
, "...with DFSR 0x%x DFAR 0x%x\n",
9944 (uint32_t)env
->exception
.vaddress
);
9945 new_mode
= ARM_CPU_MODE_ABT
;
9947 mask
= CPSR_A
| CPSR_I
;
9951 new_mode
= ARM_CPU_MODE_IRQ
;
9953 /* Disable IRQ and imprecise data aborts. */
9954 mask
= CPSR_A
| CPSR_I
;
9956 if (env
->cp15
.scr_el3
& SCR_IRQ
) {
9957 /* IRQ routed to monitor mode */
9958 new_mode
= ARM_CPU_MODE_MON
;
9963 new_mode
= ARM_CPU_MODE_FIQ
;
9965 /* Disable FIQ, IRQ and imprecise data aborts. */
9966 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
9967 if (env
->cp15
.scr_el3
& SCR_FIQ
) {
9968 /* FIQ routed to monitor mode */
9969 new_mode
= ARM_CPU_MODE_MON
;
9974 new_mode
= ARM_CPU_MODE_IRQ
;
9976 /* Disable IRQ and imprecise data aborts. */
9977 mask
= CPSR_A
| CPSR_I
;
9981 new_mode
= ARM_CPU_MODE_FIQ
;
9983 /* Disable FIQ, IRQ and imprecise data aborts. */
9984 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
9990 * Note that this is reported as a data abort, but the DFAR
9991 * has an UNKNOWN value. Construct the SError syndrome from
9992 * AET and ExT fields.
9994 ARMMMUFaultInfo fi
= { .type
= ARMFault_AsyncExternal
, };
9996 if (extended_addresses_enabled(env
)) {
9997 env
->exception
.fsr
= arm_fi_to_lfsc(&fi
);
9999 env
->exception
.fsr
= arm_fi_to_sfsc(&fi
);
10001 env
->exception
.fsr
|= env
->cp15
.vsesr_el2
& 0xd000;
10002 A32_BANKED_CURRENT_REG_SET(env
, dfsr
, env
->exception
.fsr
);
10003 qemu_log_mask(CPU_LOG_INT
, "...with IFSR 0x%x\n",
10004 env
->exception
.fsr
);
10006 new_mode
= ARM_CPU_MODE_ABT
;
10008 mask
= CPSR_A
| CPSR_I
;
10013 new_mode
= ARM_CPU_MODE_MON
;
10015 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
10019 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
10020 return; /* Never happens. Keep compiler happy. */
10023 if (new_mode
== ARM_CPU_MODE_MON
) {
10024 addr
+= env
->cp15
.mvbar
;
10025 } else if (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_V
) {
10026 /* High vectors. When enabled, base address cannot be remapped. */
10027 addr
+= 0xffff0000;
10029 /* ARM v7 architectures provide a vector base address register to remap
10030 * the interrupt vector table.
10031 * This register is only followed in non-monitor mode, and is banked.
10032 * Note: only bits 31:5 are valid.
10034 addr
+= A32_BANKED_CURRENT_REG_GET(env
, vbar
);
10037 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
) {
10038 env
->cp15
.scr_el3
&= ~SCR_NS
;
10041 take_aarch32_exception(env
, new_mode
, mask
, offset
, addr
);
10044 static int aarch64_regnum(CPUARMState
*env
, int aarch32_reg
)
10047 * Return the register number of the AArch64 view of the AArch32
10048 * register @aarch32_reg. The CPUARMState CPSR is assumed to still
10049 * be that of the AArch32 mode the exception came from.
10051 int mode
= env
->uncached_cpsr
& CPSR_M
;
10053 switch (aarch32_reg
) {
10055 return aarch32_reg
;
10057 return mode
== ARM_CPU_MODE_FIQ
? aarch32_reg
+ 16 : aarch32_reg
;
10060 case ARM_CPU_MODE_USR
:
10061 case ARM_CPU_MODE_SYS
:
10063 case ARM_CPU_MODE_HYP
:
10065 case ARM_CPU_MODE_IRQ
:
10067 case ARM_CPU_MODE_SVC
:
10069 case ARM_CPU_MODE_ABT
:
10071 case ARM_CPU_MODE_UND
:
10073 case ARM_CPU_MODE_FIQ
:
10076 g_assert_not_reached();
10080 case ARM_CPU_MODE_USR
:
10081 case ARM_CPU_MODE_SYS
:
10082 case ARM_CPU_MODE_HYP
:
10084 case ARM_CPU_MODE_IRQ
:
10086 case ARM_CPU_MODE_SVC
:
10088 case ARM_CPU_MODE_ABT
:
10090 case ARM_CPU_MODE_UND
:
10092 case ARM_CPU_MODE_FIQ
:
10095 g_assert_not_reached();
10100 g_assert_not_reached();
10104 static uint32_t cpsr_read_for_spsr_elx(CPUARMState
*env
)
10106 uint32_t ret
= cpsr_read(env
);
10108 /* Move DIT to the correct location for SPSR_ELx */
10109 if (ret
& CPSR_DIT
) {
10113 /* Merge PSTATE.SS into SPSR_ELx */
10114 ret
|= env
->pstate
& PSTATE_SS
;
10119 static bool syndrome_is_sync_extabt(uint32_t syndrome
)
10121 /* Return true if this syndrome value is a synchronous external abort */
10122 switch (syn_get_ec(syndrome
)) {
10124 case EC_INSNABORT_SAME_EL
:
10126 case EC_DATAABORT_SAME_EL
:
10127 /* Look at fault status code for all the synchronous ext abort cases */
10128 switch (syndrome
& 0x3f) {
10144 /* Handle exception entry to a target EL which is using AArch64 */
10145 static void arm_cpu_do_interrupt_aarch64(CPUState
*cs
)
10147 ARMCPU
*cpu
= ARM_CPU(cs
);
10148 CPUARMState
*env
= &cpu
->env
;
10149 unsigned int new_el
= env
->exception
.target_el
;
10150 target_ulong addr
= env
->cp15
.vbar_el
[new_el
];
10151 unsigned int new_mode
= aarch64_pstate_mode(new_el
, true);
10152 unsigned int old_mode
;
10153 unsigned int cur_el
= arm_current_el(env
);
10157 * Note that new_el can never be 0. If cur_el is 0, then
10158 * el0_a64 is is_a64(), else el0_a64 is ignored.
10160 aarch64_sve_change_el(env
, cur_el
, new_el
, is_a64(env
));
10162 if (cur_el
< new_el
) {
10163 /* Entry vector offset depends on whether the implemented EL
10164 * immediately lower than the target level is using AArch32 or AArch64
10171 is_aa64
= (env
->cp15
.scr_el3
& SCR_RW
) != 0;
10174 hcr
= arm_hcr_el2_eff(env
);
10175 if ((hcr
& (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
10176 is_aa64
= (hcr
& HCR_RW
) != 0;
10181 is_aa64
= is_a64(env
);
10184 g_assert_not_reached();
10192 } else if (pstate_read(env
) & PSTATE_SP
) {
10196 switch (cs
->exception_index
) {
10197 case EXCP_PREFETCH_ABORT
:
10198 case EXCP_DATA_ABORT
:
10200 * FEAT_DoubleFault allows synchronous external aborts taken to EL3
10201 * to be taken to the SError vector entrypoint.
10203 if (new_el
== 3 && (env
->cp15
.scr_el3
& SCR_EASE
) &&
10204 syndrome_is_sync_extabt(env
->exception
.syndrome
)) {
10207 env
->cp15
.far_el
[new_el
] = env
->exception
.vaddress
;
10208 qemu_log_mask(CPU_LOG_INT
, "...with FAR 0x%" PRIx64
"\n",
10209 env
->cp15
.far_el
[new_el
]);
10215 case EXCP_HYP_TRAP
:
10217 switch (syn_get_ec(env
->exception
.syndrome
)) {
10218 case EC_ADVSIMDFPACCESSTRAP
:
10220 * QEMU internal FP/SIMD syndromes from AArch32 include the
10221 * TA and coproc fields which are only exposed if the exception
10222 * is taken to AArch32 Hyp mode. Mask them out to get a valid
10223 * AArch64 format syndrome.
10225 env
->exception
.syndrome
&= ~MAKE_64BIT_MASK(0, 20);
10227 case EC_CP14RTTRAP
:
10228 case EC_CP15RTTRAP
:
10229 case EC_CP14DTTRAP
:
10231 * For a trap on AArch32 MRC/MCR/LDC/STC the Rt field is currently
10232 * the raw register field from the insn; when taking this to
10233 * AArch64 we must convert it to the AArch64 view of the register
10234 * number. Notice that we read a 4-bit AArch32 register number and
10235 * write back a 5-bit AArch64 one.
10237 rt
= extract32(env
->exception
.syndrome
, 5, 4);
10238 rt
= aarch64_regnum(env
, rt
);
10239 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
10242 case EC_CP15RRTTRAP
:
10243 case EC_CP14RRTTRAP
:
10244 /* Similarly for MRRC/MCRR traps for Rt and Rt2 fields */
10245 rt
= extract32(env
->exception
.syndrome
, 5, 4);
10246 rt
= aarch64_regnum(env
, rt
);
10247 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
10249 rt
= extract32(env
->exception
.syndrome
, 10, 4);
10250 rt
= aarch64_regnum(env
, rt
);
10251 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
10255 env
->cp15
.esr_el
[new_el
] = env
->exception
.syndrome
;
10267 /* Construct the SError syndrome from IDS and ISS fields. */
10268 env
->exception
.syndrome
= syn_serror(env
->cp15
.vsesr_el2
& 0x1ffffff);
10269 env
->cp15
.esr_el
[new_el
] = env
->exception
.syndrome
;
10272 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
10276 old_mode
= pstate_read(env
);
10277 aarch64_save_sp(env
, arm_current_el(env
));
10278 env
->elr_el
[new_el
] = env
->pc
;
10280 old_mode
= cpsr_read_for_spsr_elx(env
);
10281 env
->elr_el
[new_el
] = env
->regs
[15];
10283 aarch64_sync_32_to_64(env
);
10285 env
->condexec_bits
= 0;
10287 env
->banked_spsr
[aarch64_banked_spsr_index(new_el
)] = old_mode
;
10289 qemu_log_mask(CPU_LOG_INT
, "...with ELR 0x%" PRIx64
"\n",
10290 env
->elr_el
[new_el
]);
10292 if (cpu_isar_feature(aa64_pan
, cpu
)) {
10293 /* The value of PSTATE.PAN is normally preserved, except when ... */
10294 new_mode
|= old_mode
& PSTATE_PAN
;
10297 /* ... the target is EL2 with HCR_EL2.{E2H,TGE} == '11' ... */
10298 if ((arm_hcr_el2_eff(env
) & (HCR_E2H
| HCR_TGE
))
10299 != (HCR_E2H
| HCR_TGE
)) {
10304 /* ... the target is EL1 ... */
10305 /* ... and SCTLR_ELx.SPAN == 0, then set to 1. */
10306 if ((env
->cp15
.sctlr_el
[new_el
] & SCTLR_SPAN
) == 0) {
10307 new_mode
|= PSTATE_PAN
;
10312 if (cpu_isar_feature(aa64_mte
, cpu
)) {
10313 new_mode
|= PSTATE_TCO
;
10316 if (cpu_isar_feature(aa64_ssbs
, cpu
)) {
10317 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_DSSBS_64
) {
10318 new_mode
|= PSTATE_SSBS
;
10320 new_mode
&= ~PSTATE_SSBS
;
10324 pstate_write(env
, PSTATE_DAIF
| new_mode
);
10325 env
->aarch64
= true;
10326 aarch64_restore_sp(env
, new_el
);
10327 helper_rebuild_hflags_a64(env
, new_el
);
10331 qemu_log_mask(CPU_LOG_INT
, "...to EL%d PC 0x%" PRIx64
" PSTATE 0x%x\n",
10332 new_el
, env
->pc
, pstate_read(env
));
10336 * Do semihosting call and set the appropriate return value. All the
10337 * permission and validity checks have been done at translate time.
10339 * We only see semihosting exceptions in TCG only as they are not
10340 * trapped to the hypervisor in KVM.
10343 static void handle_semihosting(CPUState
*cs
)
10345 ARMCPU
*cpu
= ARM_CPU(cs
);
10346 CPUARMState
*env
= &cpu
->env
;
10349 qemu_log_mask(CPU_LOG_INT
,
10350 "...handling as semihosting call 0x%" PRIx64
"\n",
10352 env
->xregs
[0] = do_common_semihosting(cs
);
10355 qemu_log_mask(CPU_LOG_INT
,
10356 "...handling as semihosting call 0x%x\n",
10358 env
->regs
[0] = do_common_semihosting(cs
);
10359 env
->regs
[15] += env
->thumb
? 2 : 4;
10364 /* Handle a CPU exception for A and R profile CPUs.
10365 * Do any appropriate logging, handle PSCI calls, and then hand off
10366 * to the AArch64-entry or AArch32-entry function depending on the
10367 * target exception level's register width.
10369 * Note: this is used for both TCG (as the do_interrupt tcg op),
10370 * and KVM to re-inject guest debug exceptions, and to
10371 * inject a Synchronous-External-Abort.
10373 void arm_cpu_do_interrupt(CPUState
*cs
)
10375 ARMCPU
*cpu
= ARM_CPU(cs
);
10376 CPUARMState
*env
= &cpu
->env
;
10377 unsigned int new_el
= env
->exception
.target_el
;
10379 assert(!arm_feature(env
, ARM_FEATURE_M
));
10381 arm_log_exception(cs
);
10382 qemu_log_mask(CPU_LOG_INT
, "...from EL%d to EL%d\n", arm_current_el(env
),
10384 if (qemu_loglevel_mask(CPU_LOG_INT
)
10385 && !excp_is_internal(cs
->exception_index
)) {
10386 qemu_log_mask(CPU_LOG_INT
, "...with ESR 0x%x/0x%" PRIx32
"\n",
10387 syn_get_ec(env
->exception
.syndrome
),
10388 env
->exception
.syndrome
);
10391 if (arm_is_psci_call(cpu
, cs
->exception_index
)) {
10392 arm_handle_psci_call(cpu
);
10393 qemu_log_mask(CPU_LOG_INT
, "...handled as PSCI call\n");
10398 * Semihosting semantics depend on the register width of the code
10399 * that caused the exception, not the target exception level, so
10400 * must be handled here.
10403 if (cs
->exception_index
== EXCP_SEMIHOST
) {
10404 handle_semihosting(cs
);
10409 /* Hooks may change global state so BQL should be held, also the
10410 * BQL needs to be held for any modification of
10411 * cs->interrupt_request.
10413 g_assert(qemu_mutex_iothread_locked());
10415 arm_call_pre_el_change_hook(cpu
);
10417 assert(!excp_is_internal(cs
->exception_index
));
10418 if (arm_el_is_aa64(env
, new_el
)) {
10419 arm_cpu_do_interrupt_aarch64(cs
);
10421 arm_cpu_do_interrupt_aarch32(cs
);
10424 arm_call_el_change_hook(cpu
);
10426 if (!kvm_enabled()) {
10427 cs
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
10430 #endif /* !CONFIG_USER_ONLY */
10432 uint64_t arm_sctlr(CPUARMState
*env
, int el
)
10434 /* Only EL0 needs to be adjusted for EL1&0 or EL2&0. */
10436 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, 0);
10437 el
= (mmu_idx
== ARMMMUIdx_E20_0
|| mmu_idx
== ARMMMUIdx_SE20_0
)
10440 return env
->cp15
.sctlr_el
[el
];
10443 /* Return the SCTLR value which controls this address translation regime */
10444 static inline uint64_t regime_sctlr(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
10446 return env
->cp15
.sctlr_el
[regime_el(env
, mmu_idx
)];
10449 #ifndef CONFIG_USER_ONLY
10451 /* Return true if the specified stage of address translation is disabled */
10452 static inline bool regime_translation_disabled(CPUARMState
*env
,
10457 if (arm_feature(env
, ARM_FEATURE_M
)) {
10458 switch (env
->v7m
.mpu_ctrl
[regime_is_secure(env
, mmu_idx
)] &
10459 (R_V7M_MPU_CTRL_ENABLE_MASK
| R_V7M_MPU_CTRL_HFNMIENA_MASK
)) {
10460 case R_V7M_MPU_CTRL_ENABLE_MASK
:
10461 /* Enabled, but not for HardFault and NMI */
10462 return mmu_idx
& ARM_MMU_IDX_M_NEGPRI
;
10463 case R_V7M_MPU_CTRL_ENABLE_MASK
| R_V7M_MPU_CTRL_HFNMIENA_MASK
:
10464 /* Enabled for all cases */
10468 /* HFNMIENA set and ENABLE clear is UNPREDICTABLE, but
10469 * we warned about that in armv7m_nvic.c when the guest set it.
10475 hcr_el2
= arm_hcr_el2_eff(env
);
10477 if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
10478 /* HCR.DC means HCR.VM behaves as 1 */
10479 return (hcr_el2
& (HCR_DC
| HCR_VM
)) == 0;
10482 if (hcr_el2
& HCR_TGE
) {
10483 /* TGE means that NS EL0/1 act as if SCTLR_EL1.M is zero */
10484 if (!regime_is_secure(env
, mmu_idx
) && regime_el(env
, mmu_idx
) == 1) {
10489 if ((hcr_el2
& HCR_DC
) && arm_mmu_idx_is_stage1_of_2(mmu_idx
)) {
10490 /* HCR.DC means SCTLR_EL1.M behaves as 0 */
10494 return (regime_sctlr(env
, mmu_idx
) & SCTLR_M
) == 0;
10497 static inline bool regime_translation_big_endian(CPUARMState
*env
,
10500 return (regime_sctlr(env
, mmu_idx
) & SCTLR_EE
) != 0;
10503 /* Return the TTBR associated with this translation regime */
10504 static inline uint64_t regime_ttbr(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
10507 if (mmu_idx
== ARMMMUIdx_Stage2
) {
10508 return env
->cp15
.vttbr_el2
;
10510 if (mmu_idx
== ARMMMUIdx_Stage2_S
) {
10511 return env
->cp15
.vsttbr_el2
;
10514 return env
->cp15
.ttbr0_el
[regime_el(env
, mmu_idx
)];
10516 return env
->cp15
.ttbr1_el
[regime_el(env
, mmu_idx
)];
10520 #endif /* !CONFIG_USER_ONLY */
10522 /* Convert a possible stage1+2 MMU index into the appropriate
10523 * stage 1 MMU index
10525 static inline ARMMMUIdx
stage_1_mmu_idx(ARMMMUIdx mmu_idx
)
10528 case ARMMMUIdx_SE10_0
:
10529 return ARMMMUIdx_Stage1_SE0
;
10530 case ARMMMUIdx_SE10_1
:
10531 return ARMMMUIdx_Stage1_SE1
;
10532 case ARMMMUIdx_SE10_1_PAN
:
10533 return ARMMMUIdx_Stage1_SE1_PAN
;
10534 case ARMMMUIdx_E10_0
:
10535 return ARMMMUIdx_Stage1_E0
;
10536 case ARMMMUIdx_E10_1
:
10537 return ARMMMUIdx_Stage1_E1
;
10538 case ARMMMUIdx_E10_1_PAN
:
10539 return ARMMMUIdx_Stage1_E1_PAN
;
10545 /* Return true if the translation regime is using LPAE format page tables */
10546 static inline bool regime_using_lpae_format(CPUARMState
*env
,
10549 int el
= regime_el(env
, mmu_idx
);
10550 if (el
== 2 || arm_el_is_aa64(env
, el
)) {
10553 if (arm_feature(env
, ARM_FEATURE_LPAE
)
10554 && (regime_tcr(env
, mmu_idx
)->raw_tcr
& TTBCR_EAE
)) {
10560 /* Returns true if the stage 1 translation regime is using LPAE format page
10561 * tables. Used when raising alignment exceptions, whose FSR changes depending
10562 * on whether the long or short descriptor format is in use. */
10563 bool arm_s1_regime_using_lpae_format(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
10565 mmu_idx
= stage_1_mmu_idx(mmu_idx
);
10567 return regime_using_lpae_format(env
, mmu_idx
);
10570 #ifndef CONFIG_USER_ONLY
10571 static inline bool regime_is_user(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
10574 case ARMMMUIdx_SE10_0
:
10575 case ARMMMUIdx_E20_0
:
10576 case ARMMMUIdx_SE20_0
:
10577 case ARMMMUIdx_Stage1_E0
:
10578 case ARMMMUIdx_Stage1_SE0
:
10579 case ARMMMUIdx_MUser
:
10580 case ARMMMUIdx_MSUser
:
10581 case ARMMMUIdx_MUserNegPri
:
10582 case ARMMMUIdx_MSUserNegPri
:
10586 case ARMMMUIdx_E10_0
:
10587 case ARMMMUIdx_E10_1
:
10588 case ARMMMUIdx_E10_1_PAN
:
10589 g_assert_not_reached();
10593 /* Translate section/page access permissions to page
10594 * R/W protection flags
10596 * @env: CPUARMState
10597 * @mmu_idx: MMU index indicating required translation regime
10598 * @ap: The 3-bit access permissions (AP[2:0])
10599 * @domain_prot: The 2-bit domain access permissions
10601 static inline int ap_to_rw_prot(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
10602 int ap
, int domain_prot
)
10604 bool is_user
= regime_is_user(env
, mmu_idx
);
10606 if (domain_prot
== 3) {
10607 return PAGE_READ
| PAGE_WRITE
;
10612 if (arm_feature(env
, ARM_FEATURE_V7
)) {
10615 switch (regime_sctlr(env
, mmu_idx
) & (SCTLR_S
| SCTLR_R
)) {
10617 return is_user
? 0 : PAGE_READ
;
10624 return is_user
? 0 : PAGE_READ
| PAGE_WRITE
;
10629 return PAGE_READ
| PAGE_WRITE
;
10632 return PAGE_READ
| PAGE_WRITE
;
10633 case 4: /* Reserved. */
10636 return is_user
? 0 : PAGE_READ
;
10640 if (!arm_feature(env
, ARM_FEATURE_V6K
)) {
10645 g_assert_not_reached();
10649 /* Translate section/page access permissions to page
10650 * R/W protection flags.
10652 * @ap: The 2-bit simple AP (AP[2:1])
10653 * @is_user: TRUE if accessing from PL0
10655 static inline int simple_ap_to_rw_prot_is_user(int ap
, bool is_user
)
10659 return is_user
? 0 : PAGE_READ
| PAGE_WRITE
;
10661 return PAGE_READ
| PAGE_WRITE
;
10663 return is_user
? 0 : PAGE_READ
;
10667 g_assert_not_reached();
10672 simple_ap_to_rw_prot(CPUARMState
*env
, ARMMMUIdx mmu_idx
, int ap
)
10674 return simple_ap_to_rw_prot_is_user(ap
, regime_is_user(env
, mmu_idx
));
10677 /* Translate S2 section/page access permissions to protection flags
10679 * @env: CPUARMState
10680 * @s2ap: The 2-bit stage2 access permissions (S2AP)
10681 * @xn: XN (execute-never) bits
10682 * @s1_is_el0: true if this is S2 of an S1+2 walk for EL0
10684 static int get_S2prot(CPUARMState
*env
, int s2ap
, int xn
, bool s1_is_el0
)
10692 prot
|= PAGE_WRITE
;
10695 if (cpu_isar_feature(any_tts2uxn
, env_archcpu(env
))) {
10713 g_assert_not_reached();
10716 if (!extract32(xn
, 1, 1)) {
10717 if (arm_el_is_aa64(env
, 2) || prot
& PAGE_READ
) {
10725 /* Translate section/page access permissions to protection flags
10727 * @env: CPUARMState
10728 * @mmu_idx: MMU index indicating required translation regime
10729 * @is_aa64: TRUE if AArch64
10730 * @ap: The 2-bit simple AP (AP[2:1])
10731 * @ns: NS (non-secure) bit
10732 * @xn: XN (execute-never) bit
10733 * @pxn: PXN (privileged execute-never) bit
10735 static int get_S1prot(CPUARMState
*env
, ARMMMUIdx mmu_idx
, bool is_aa64
,
10736 int ap
, int ns
, int xn
, int pxn
)
10738 bool is_user
= regime_is_user(env
, mmu_idx
);
10739 int prot_rw
, user_rw
;
10743 assert(mmu_idx
!= ARMMMUIdx_Stage2
);
10744 assert(mmu_idx
!= ARMMMUIdx_Stage2_S
);
10746 user_rw
= simple_ap_to_rw_prot_is_user(ap
, true);
10750 if (user_rw
&& regime_is_pan(env
, mmu_idx
)) {
10751 /* PAN forbids data accesses but doesn't affect insn fetch */
10754 prot_rw
= simple_ap_to_rw_prot_is_user(ap
, false);
10758 if (ns
&& arm_is_secure(env
) && (env
->cp15
.scr_el3
& SCR_SIF
)) {
10762 /* TODO have_wxn should be replaced with
10763 * ARM_FEATURE_V8 || (ARM_FEATURE_V7 && ARM_FEATURE_EL2)
10764 * when ARM_FEATURE_EL2 starts getting set. For now we assume all LPAE
10765 * compatible processors have EL2, which is required for [U]WXN.
10767 have_wxn
= arm_feature(env
, ARM_FEATURE_LPAE
);
10770 wxn
= regime_sctlr(env
, mmu_idx
) & SCTLR_WXN
;
10774 if (regime_has_2_ranges(mmu_idx
) && !is_user
) {
10775 xn
= pxn
|| (user_rw
& PAGE_WRITE
);
10777 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
10778 switch (regime_el(env
, mmu_idx
)) {
10782 xn
= xn
|| !(user_rw
& PAGE_READ
);
10786 uwxn
= regime_sctlr(env
, mmu_idx
) & SCTLR_UWXN
;
10788 xn
= xn
|| !(prot_rw
& PAGE_READ
) || pxn
||
10789 (uwxn
&& (user_rw
& PAGE_WRITE
));
10799 if (xn
|| (wxn
&& (prot_rw
& PAGE_WRITE
))) {
10802 return prot_rw
| PAGE_EXEC
;
10805 static bool get_level1_table_address(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
10806 uint32_t *table
, uint32_t address
)
10808 /* Note that we can only get here for an AArch32 PL0/PL1 lookup */
10809 TCR
*tcr
= regime_tcr(env
, mmu_idx
);
10811 if (address
& tcr
->mask
) {
10812 if (tcr
->raw_tcr
& TTBCR_PD1
) {
10813 /* Translation table walk disabled for TTBR1 */
10816 *table
= regime_ttbr(env
, mmu_idx
, 1) & 0xffffc000;
10818 if (tcr
->raw_tcr
& TTBCR_PD0
) {
10819 /* Translation table walk disabled for TTBR0 */
10822 *table
= regime_ttbr(env
, mmu_idx
, 0) & tcr
->base_mask
;
10824 *table
|= (address
>> 18) & 0x3ffc;
10828 static bool ptw_attrs_are_device(CPUARMState
*env
, ARMCacheAttrs cacheattrs
)
10831 * For an S1 page table walk, the stage 1 attributes are always
10832 * some form of "this is Normal memory". The combined S1+S2
10833 * attributes are therefore only Device if stage 2 specifies Device.
10834 * With HCR_EL2.FWB == 0 this is when descriptor bits [5:4] are 0b00,
10835 * ie when cacheattrs.attrs bits [3:2] are 0b00.
10836 * With HCR_EL2.FWB == 1 this is when descriptor bit [4] is 0, ie
10837 * when cacheattrs.attrs bit [2] is 0.
10839 assert(cacheattrs
.is_s2_format
);
10840 if (arm_hcr_el2_eff(env
) & HCR_FWB
) {
10841 return (cacheattrs
.attrs
& 0x4) == 0;
10843 return (cacheattrs
.attrs
& 0xc) == 0;
10847 /* Translate a S1 pagetable walk through S2 if needed. */
10848 static hwaddr
S1_ptw_translate(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
10849 hwaddr addr
, bool *is_secure
,
10850 ARMMMUFaultInfo
*fi
)
10852 if (arm_mmu_idx_is_stage1_of_2(mmu_idx
) &&
10853 !regime_translation_disabled(env
, ARMMMUIdx_Stage2
)) {
10854 target_ulong s2size
;
10858 ARMMMUIdx s2_mmu_idx
= *is_secure
? ARMMMUIdx_Stage2_S
10859 : ARMMMUIdx_Stage2
;
10860 ARMCacheAttrs cacheattrs
= {};
10861 MemTxAttrs txattrs
= {};
10863 ret
= get_phys_addr_lpae(env
, addr
, MMU_DATA_LOAD
, s2_mmu_idx
, false,
10864 &s2pa
, &txattrs
, &s2prot
, &s2size
, fi
,
10867 assert(fi
->type
!= ARMFault_None
);
10871 fi
->s1ns
= !*is_secure
;
10874 if ((arm_hcr_el2_eff(env
) & HCR_PTW
) &&
10875 ptw_attrs_are_device(env
, cacheattrs
)) {
10877 * PTW set and S1 walk touched S2 Device memory:
10878 * generate Permission fault.
10880 fi
->type
= ARMFault_Permission
;
10884 fi
->s1ns
= !*is_secure
;
10888 if (arm_is_secure_below_el3(env
)) {
10889 /* Check if page table walk is to secure or non-secure PA space. */
10891 *is_secure
= !(env
->cp15
.vstcr_el2
.raw_tcr
& VSTCR_SW
);
10893 *is_secure
= !(env
->cp15
.vtcr_el2
.raw_tcr
& VTCR_NSW
);
10896 assert(!*is_secure
);
10904 /* All loads done in the course of a page table walk go through here. */
10905 static uint32_t arm_ldl_ptw(CPUState
*cs
, hwaddr addr
, bool is_secure
,
10906 ARMMMUIdx mmu_idx
, ARMMMUFaultInfo
*fi
)
10908 ARMCPU
*cpu
= ARM_CPU(cs
);
10909 CPUARMState
*env
= &cpu
->env
;
10910 MemTxAttrs attrs
= {};
10911 MemTxResult result
= MEMTX_OK
;
10915 addr
= S1_ptw_translate(env
, mmu_idx
, addr
, &is_secure
, fi
);
10916 attrs
.secure
= is_secure
;
10917 as
= arm_addressspace(cs
, attrs
);
10921 if (regime_translation_big_endian(env
, mmu_idx
)) {
10922 data
= address_space_ldl_be(as
, addr
, attrs
, &result
);
10924 data
= address_space_ldl_le(as
, addr
, attrs
, &result
);
10926 if (result
== MEMTX_OK
) {
10929 fi
->type
= ARMFault_SyncExternalOnWalk
;
10930 fi
->ea
= arm_extabort_type(result
);
10934 static uint64_t arm_ldq_ptw(CPUState
*cs
, hwaddr addr
, bool is_secure
,
10935 ARMMMUIdx mmu_idx
, ARMMMUFaultInfo
*fi
)
10937 ARMCPU
*cpu
= ARM_CPU(cs
);
10938 CPUARMState
*env
= &cpu
->env
;
10939 MemTxAttrs attrs
= {};
10940 MemTxResult result
= MEMTX_OK
;
10944 addr
= S1_ptw_translate(env
, mmu_idx
, addr
, &is_secure
, fi
);
10945 attrs
.secure
= is_secure
;
10946 as
= arm_addressspace(cs
, attrs
);
10950 if (regime_translation_big_endian(env
, mmu_idx
)) {
10951 data
= address_space_ldq_be(as
, addr
, attrs
, &result
);
10953 data
= address_space_ldq_le(as
, addr
, attrs
, &result
);
10955 if (result
== MEMTX_OK
) {
10958 fi
->type
= ARMFault_SyncExternalOnWalk
;
10959 fi
->ea
= arm_extabort_type(result
);
10963 static bool get_phys_addr_v5(CPUARMState
*env
, uint32_t address
,
10964 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
10965 hwaddr
*phys_ptr
, int *prot
,
10966 target_ulong
*page_size
,
10967 ARMMMUFaultInfo
*fi
)
10969 CPUState
*cs
= env_cpu(env
);
10980 /* Pagetable walk. */
10981 /* Lookup l1 descriptor. */
10982 if (!get_level1_table_address(env
, mmu_idx
, &table
, address
)) {
10983 /* Section translation fault if page walk is disabled by PD0 or PD1 */
10984 fi
->type
= ARMFault_Translation
;
10987 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
10989 if (fi
->type
!= ARMFault_None
) {
10993 domain
= (desc
>> 5) & 0x0f;
10994 if (regime_el(env
, mmu_idx
) == 1) {
10995 dacr
= env
->cp15
.dacr_ns
;
10997 dacr
= env
->cp15
.dacr_s
;
10999 domain_prot
= (dacr
>> (domain
* 2)) & 3;
11001 /* Section translation fault. */
11002 fi
->type
= ARMFault_Translation
;
11008 if (domain_prot
== 0 || domain_prot
== 2) {
11009 fi
->type
= ARMFault_Domain
;
11014 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
11015 ap
= (desc
>> 10) & 3;
11016 *page_size
= 1024 * 1024;
11018 /* Lookup l2 entry. */
11020 /* Coarse pagetable. */
11021 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
11023 /* Fine pagetable. */
11024 table
= (desc
& 0xfffff000) | ((address
>> 8) & 0xffc);
11026 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
11028 if (fi
->type
!= ARMFault_None
) {
11031 switch (desc
& 3) {
11032 case 0: /* Page translation fault. */
11033 fi
->type
= ARMFault_Translation
;
11035 case 1: /* 64k page. */
11036 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
11037 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
11038 *page_size
= 0x10000;
11040 case 2: /* 4k page. */
11041 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
11042 ap
= (desc
>> (4 + ((address
>> 9) & 6))) & 3;
11043 *page_size
= 0x1000;
11045 case 3: /* 1k page, or ARMv6/XScale "extended small (4k) page" */
11047 /* ARMv6/XScale extended small page format */
11048 if (arm_feature(env
, ARM_FEATURE_XSCALE
)
11049 || arm_feature(env
, ARM_FEATURE_V6
)) {
11050 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
11051 *page_size
= 0x1000;
11053 /* UNPREDICTABLE in ARMv5; we choose to take a
11054 * page translation fault.
11056 fi
->type
= ARMFault_Translation
;
11060 phys_addr
= (desc
& 0xfffffc00) | (address
& 0x3ff);
11061 *page_size
= 0x400;
11063 ap
= (desc
>> 4) & 3;
11066 /* Never happens, but compiler isn't smart enough to tell. */
11067 g_assert_not_reached();
11070 *prot
= ap_to_rw_prot(env
, mmu_idx
, ap
, domain_prot
);
11071 *prot
|= *prot
? PAGE_EXEC
: 0;
11072 if (!(*prot
& (1 << access_type
))) {
11073 /* Access permission fault. */
11074 fi
->type
= ARMFault_Permission
;
11077 *phys_ptr
= phys_addr
;
11080 fi
->domain
= domain
;
11085 static bool get_phys_addr_v6(CPUARMState
*env
, uint32_t address
,
11086 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
11087 hwaddr
*phys_ptr
, MemTxAttrs
*attrs
, int *prot
,
11088 target_ulong
*page_size
, ARMMMUFaultInfo
*fi
)
11090 CPUState
*cs
= env_cpu(env
);
11091 ARMCPU
*cpu
= env_archcpu(env
);
11105 /* Pagetable walk. */
11106 /* Lookup l1 descriptor. */
11107 if (!get_level1_table_address(env
, mmu_idx
, &table
, address
)) {
11108 /* Section translation fault if page walk is disabled by PD0 or PD1 */
11109 fi
->type
= ARMFault_Translation
;
11112 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
11114 if (fi
->type
!= ARMFault_None
) {
11118 if (type
== 0 || (type
== 3 && !cpu_isar_feature(aa32_pxn
, cpu
))) {
11119 /* Section translation fault, or attempt to use the encoding
11120 * which is Reserved on implementations without PXN.
11122 fi
->type
= ARMFault_Translation
;
11125 if ((type
== 1) || !(desc
& (1 << 18))) {
11126 /* Page or Section. */
11127 domain
= (desc
>> 5) & 0x0f;
11129 if (regime_el(env
, mmu_idx
) == 1) {
11130 dacr
= env
->cp15
.dacr_ns
;
11132 dacr
= env
->cp15
.dacr_s
;
11137 domain_prot
= (dacr
>> (domain
* 2)) & 3;
11138 if (domain_prot
== 0 || domain_prot
== 2) {
11139 /* Section or Page domain fault */
11140 fi
->type
= ARMFault_Domain
;
11144 if (desc
& (1 << 18)) {
11145 /* Supersection. */
11146 phys_addr
= (desc
& 0xff000000) | (address
& 0x00ffffff);
11147 phys_addr
|= (uint64_t)extract32(desc
, 20, 4) << 32;
11148 phys_addr
|= (uint64_t)extract32(desc
, 5, 4) << 36;
11149 *page_size
= 0x1000000;
11152 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
11153 *page_size
= 0x100000;
11155 ap
= ((desc
>> 10) & 3) | ((desc
>> 13) & 4);
11156 xn
= desc
& (1 << 4);
11158 ns
= extract32(desc
, 19, 1);
11160 if (cpu_isar_feature(aa32_pxn
, cpu
)) {
11161 pxn
= (desc
>> 2) & 1;
11163 ns
= extract32(desc
, 3, 1);
11164 /* Lookup l2 entry. */
11165 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
11166 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
11168 if (fi
->type
!= ARMFault_None
) {
11171 ap
= ((desc
>> 4) & 3) | ((desc
>> 7) & 4);
11172 switch (desc
& 3) {
11173 case 0: /* Page translation fault. */
11174 fi
->type
= ARMFault_Translation
;
11176 case 1: /* 64k page. */
11177 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
11178 xn
= desc
& (1 << 15);
11179 *page_size
= 0x10000;
11181 case 2: case 3: /* 4k page. */
11182 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
11184 *page_size
= 0x1000;
11187 /* Never happens, but compiler isn't smart enough to tell. */
11188 g_assert_not_reached();
11191 if (domain_prot
== 3) {
11192 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
11194 if (pxn
&& !regime_is_user(env
, mmu_idx
)) {
11197 if (xn
&& access_type
== MMU_INST_FETCH
) {
11198 fi
->type
= ARMFault_Permission
;
11202 if (arm_feature(env
, ARM_FEATURE_V6K
) &&
11203 (regime_sctlr(env
, mmu_idx
) & SCTLR_AFE
)) {
11204 /* The simplified model uses AP[0] as an access control bit. */
11205 if ((ap
& 1) == 0) {
11206 /* Access flag fault. */
11207 fi
->type
= ARMFault_AccessFlag
;
11210 *prot
= simple_ap_to_rw_prot(env
, mmu_idx
, ap
>> 1);
11212 *prot
= ap_to_rw_prot(env
, mmu_idx
, ap
, domain_prot
);
11214 if (*prot
&& !xn
) {
11215 *prot
|= PAGE_EXEC
;
11217 if (!(*prot
& (1 << access_type
))) {
11218 /* Access permission fault. */
11219 fi
->type
= ARMFault_Permission
;
11224 /* The NS bit will (as required by the architecture) have no effect if
11225 * the CPU doesn't support TZ or this is a non-secure translation
11226 * regime, because the attribute will already be non-secure.
11228 attrs
->secure
= false;
11230 *phys_ptr
= phys_addr
;
11233 fi
->domain
= domain
;
11239 * check_s2_mmu_setup
11241 * @is_aa64: True if the translation regime is in AArch64 state
11242 * @startlevel: Suggested starting level
11243 * @inputsize: Bitsize of IPAs
11244 * @stride: Page-table stride (See the ARM ARM)
11246 * Returns true if the suggested S2 translation parameters are OK and
11249 static bool check_s2_mmu_setup(ARMCPU
*cpu
, bool is_aa64
, int level
,
11250 int inputsize
, int stride
, int outputsize
)
11252 const int grainsize
= stride
+ 3;
11253 int startsizecheck
;
11256 * Negative levels are usually not allowed...
11257 * Except for FEAT_LPA2, 4k page table, 52-bit address space, which
11258 * begins with level -1. Note that previous feature tests will have
11259 * eliminated this combination if it is not enabled.
11261 if (level
< (inputsize
== 52 && stride
== 9 ? -1 : 0)) {
11265 startsizecheck
= inputsize
- ((3 - level
) * stride
+ grainsize
);
11266 if (startsizecheck
< 1 || startsizecheck
> stride
+ 4) {
11272 case 13: /* 64KB Pages. */
11273 if (level
== 0 || (level
== 1 && outputsize
<= 42)) {
11277 case 11: /* 16KB Pages. */
11278 if (level
== 0 || (level
== 1 && outputsize
<= 40)) {
11282 case 9: /* 4KB Pages. */
11283 if (level
== 0 && outputsize
<= 42) {
11288 g_assert_not_reached();
11291 /* Inputsize checks. */
11292 if (inputsize
> outputsize
&&
11293 (arm_el_is_aa64(&cpu
->env
, 1) || inputsize
> 40)) {
11294 /* This is CONSTRAINED UNPREDICTABLE and we choose to fault. */
11298 /* AArch32 only supports 4KB pages. Assert on that. */
11299 assert(stride
== 9);
11308 /* Translate from the 4-bit stage 2 representation of
11309 * memory attributes (without cache-allocation hints) to
11310 * the 8-bit representation of the stage 1 MAIR registers
11311 * (which includes allocation hints).
11313 * ref: shared/translation/attrs/S2AttrDecode()
11314 * .../S2ConvertAttrsHints()
11316 static uint8_t convert_stage2_attrs(CPUARMState
*env
, uint8_t s2attrs
)
11318 uint8_t hiattr
= extract32(s2attrs
, 2, 2);
11319 uint8_t loattr
= extract32(s2attrs
, 0, 2);
11320 uint8_t hihint
= 0, lohint
= 0;
11322 if (hiattr
!= 0) { /* normal memory */
11323 if (arm_hcr_el2_eff(env
) & HCR_CD
) { /* cache disabled */
11324 hiattr
= loattr
= 1; /* non-cacheable */
11326 if (hiattr
!= 1) { /* Write-through or write-back */
11327 hihint
= 3; /* RW allocate */
11329 if (loattr
!= 1) { /* Write-through or write-back */
11330 lohint
= 3; /* RW allocate */
11335 return (hiattr
<< 6) | (hihint
<< 4) | (loattr
<< 2) | lohint
;
11337 #endif /* !CONFIG_USER_ONLY */
11339 /* This mapping is common between ID_AA64MMFR0.PARANGE and TCR_ELx.{I}PS. */
11340 static const uint8_t pamax_map
[] = {
11350 /* The cpu-specific constant value of PAMax; also used by hw/arm/virt. */
11351 unsigned int arm_pamax(ARMCPU
*cpu
)
11353 unsigned int parange
=
11354 FIELD_EX64(cpu
->isar
.id_aa64mmfr0
, ID_AA64MMFR0
, PARANGE
);
11357 * id_aa64mmfr0 is a read-only register so values outside of the
11358 * supported mappings can be considered an implementation error.
11360 assert(parange
< ARRAY_SIZE(pamax_map
));
11361 return pamax_map
[parange
];
11364 static int aa64_va_parameter_tbi(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11366 if (regime_has_2_ranges(mmu_idx
)) {
11367 return extract64(tcr
, 37, 2);
11368 } else if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11369 return 0; /* VTCR_EL2 */
11371 /* Replicate the single TBI bit so we always have 2 bits. */
11372 return extract32(tcr
, 20, 1) * 3;
11376 static int aa64_va_parameter_tbid(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11378 if (regime_has_2_ranges(mmu_idx
)) {
11379 return extract64(tcr
, 51, 2);
11380 } else if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11381 return 0; /* VTCR_EL2 */
11383 /* Replicate the single TBID bit so we always have 2 bits. */
11384 return extract32(tcr
, 29, 1) * 3;
11388 static int aa64_va_parameter_tcma(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11390 if (regime_has_2_ranges(mmu_idx
)) {
11391 return extract64(tcr
, 57, 2);
11393 /* Replicate the single TCMA bit so we always have 2 bits. */
11394 return extract32(tcr
, 30, 1) * 3;
11398 ARMVAParameters
aa64_va_parameters(CPUARMState
*env
, uint64_t va
,
11399 ARMMMUIdx mmu_idx
, bool data
)
11401 uint64_t tcr
= regime_tcr(env
, mmu_idx
)->raw_tcr
;
11402 bool epd
, hpd
, using16k
, using64k
, tsz_oob
, ds
;
11403 int select
, tsz
, tbi
, max_tsz
, min_tsz
, ps
, sh
;
11404 ARMCPU
*cpu
= env_archcpu(env
);
11406 if (!regime_has_2_ranges(mmu_idx
)) {
11408 tsz
= extract32(tcr
, 0, 6);
11409 using64k
= extract32(tcr
, 14, 1);
11410 using16k
= extract32(tcr
, 15, 1);
11411 if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11415 hpd
= extract32(tcr
, 24, 1);
11418 sh
= extract32(tcr
, 12, 2);
11419 ps
= extract32(tcr
, 16, 3);
11420 ds
= extract64(tcr
, 32, 1);
11423 * Bit 55 is always between the two regions, and is canonical for
11424 * determining if address tagging is enabled.
11426 select
= extract64(va
, 55, 1);
11428 tsz
= extract32(tcr
, 0, 6);
11429 epd
= extract32(tcr
, 7, 1);
11430 sh
= extract32(tcr
, 12, 2);
11431 using64k
= extract32(tcr
, 14, 1);
11432 using16k
= extract32(tcr
, 15, 1);
11433 hpd
= extract64(tcr
, 41, 1);
11435 int tg
= extract32(tcr
, 30, 2);
11436 using16k
= tg
== 1;
11437 using64k
= tg
== 3;
11438 tsz
= extract32(tcr
, 16, 6);
11439 epd
= extract32(tcr
, 23, 1);
11440 sh
= extract32(tcr
, 28, 2);
11441 hpd
= extract64(tcr
, 42, 1);
11443 ps
= extract64(tcr
, 32, 3);
11444 ds
= extract64(tcr
, 59, 1);
11447 if (cpu_isar_feature(aa64_st
, cpu
)) {
11448 max_tsz
= 48 - using64k
;
11454 * DS is RES0 unless FEAT_LPA2 is supported for the given page size;
11455 * adjust the effective value of DS, as documented.
11459 if (cpu_isar_feature(aa64_lva
, cpu
)) {
11465 case ARMMMUIdx_Stage2
:
11466 case ARMMMUIdx_Stage2_S
:
11468 ds
= cpu_isar_feature(aa64_tgran16_2_lpa2
, cpu
);
11470 ds
= cpu_isar_feature(aa64_tgran4_2_lpa2
, cpu
);
11475 ds
= cpu_isar_feature(aa64_tgran16_lpa2
, cpu
);
11477 ds
= cpu_isar_feature(aa64_tgran4_lpa2
, cpu
);
11486 if (tsz
> max_tsz
) {
11489 } else if (tsz
< min_tsz
) {
11496 /* Present TBI as a composite with TBID. */
11497 tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
11499 tbi
&= ~aa64_va_parameter_tbid(tcr
, mmu_idx
);
11501 tbi
= (tbi
>> select
) & 1;
11503 return (ARMVAParameters
) {
11511 .using16k
= using16k
,
11512 .using64k
= using64k
,
11513 .tsz_oob
= tsz_oob
,
11518 #ifndef CONFIG_USER_ONLY
11519 static ARMVAParameters
aa32_va_parameters(CPUARMState
*env
, uint32_t va
,
11522 uint64_t tcr
= regime_tcr(env
, mmu_idx
)->raw_tcr
;
11523 uint32_t el
= regime_el(env
, mmu_idx
);
11527 assert(mmu_idx
!= ARMMMUIdx_Stage2_S
);
11529 if (mmu_idx
== ARMMMUIdx_Stage2
) {
11531 bool sext
= extract32(tcr
, 4, 1);
11532 bool sign
= extract32(tcr
, 3, 1);
11535 * If the sign-extend bit is not the same as t0sz[3], the result
11536 * is unpredictable. Flag this as a guest error.
11538 if (sign
!= sext
) {
11539 qemu_log_mask(LOG_GUEST_ERROR
,
11540 "AArch32: VTCR.S / VTCR.T0SZ[3] mismatch\n");
11542 tsz
= sextract32(tcr
, 0, 4) + 8;
11546 } else if (el
== 2) {
11548 tsz
= extract32(tcr
, 0, 3);
11550 hpd
= extract64(tcr
, 24, 1);
11553 int t0sz
= extract32(tcr
, 0, 3);
11554 int t1sz
= extract32(tcr
, 16, 3);
11557 select
= va
> (0xffffffffu
>> t0sz
);
11559 /* Note that we will detect errors later. */
11560 select
= va
>= ~(0xffffffffu
>> t1sz
);
11564 epd
= extract32(tcr
, 7, 1);
11565 hpd
= extract64(tcr
, 41, 1);
11568 epd
= extract32(tcr
, 23, 1);
11569 hpd
= extract64(tcr
, 42, 1);
11571 /* For aarch32, hpd0 is not enabled without t2e as well. */
11572 hpd
&= extract32(tcr
, 6, 1);
11575 return (ARMVAParameters
) {
11584 * get_phys_addr_lpae: perform one stage of page table walk, LPAE format
11586 * Returns false if the translation was successful. Otherwise, phys_ptr, attrs,
11587 * prot and page_size may not be filled in, and the populated fsr value provides
11588 * information on why the translation aborted, in the format of a long-format
11589 * DFSR/IFSR fault register, with the following caveats:
11590 * * the WnR bit is never set (the caller must do this).
11592 * @env: CPUARMState
11593 * @address: virtual address to get physical address for
11594 * @access_type: MMU_DATA_LOAD, MMU_DATA_STORE or MMU_INST_FETCH
11595 * @mmu_idx: MMU index indicating required translation regime
11596 * @s1_is_el0: if @mmu_idx is ARMMMUIdx_Stage2 (so this is a stage 2 page table
11597 * walk), must be true if this is stage 2 of a stage 1+2 walk for an
11598 * EL0 access). If @mmu_idx is anything else, @s1_is_el0 is ignored.
11599 * @phys_ptr: set to the physical address corresponding to the virtual address
11600 * @attrs: set to the memory transaction attributes to use
11601 * @prot: set to the permissions for the page containing phys_ptr
11602 * @page_size_ptr: set to the size of the page containing phys_ptr
11603 * @fi: set to fault info if the translation fails
11604 * @cacheattrs: (if non-NULL) set to the cacheability/shareability attributes
11606 static bool get_phys_addr_lpae(CPUARMState
*env
, uint64_t address
,
11607 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
11609 hwaddr
*phys_ptr
, MemTxAttrs
*txattrs
, int *prot
,
11610 target_ulong
*page_size_ptr
,
11611 ARMMMUFaultInfo
*fi
, ARMCacheAttrs
*cacheattrs
)
11613 ARMCPU
*cpu
= env_archcpu(env
);
11614 CPUState
*cs
= CPU(cpu
);
11615 /* Read an LPAE long-descriptor translation table. */
11616 ARMFaultType fault_type
= ARMFault_Translation
;
11618 ARMVAParameters param
;
11620 hwaddr descaddr
, indexmask
, indexmask_grainsize
;
11621 uint32_t tableattrs
;
11622 target_ulong page_size
;
11625 int addrsize
, inputsize
, outputsize
;
11626 TCR
*tcr
= regime_tcr(env
, mmu_idx
);
11627 int ap
, ns
, xn
, pxn
;
11628 uint32_t el
= regime_el(env
, mmu_idx
);
11629 uint64_t descaddrmask
;
11630 bool aarch64
= arm_el_is_aa64(env
, el
);
11631 bool guarded
= false;
11633 /* TODO: This code does not support shareability levels. */
11637 param
= aa64_va_parameters(env
, address
, mmu_idx
,
11638 access_type
!= MMU_INST_FETCH
);
11642 * If TxSZ is programmed to a value larger than the maximum,
11643 * or smaller than the effective minimum, it is IMPLEMENTATION
11644 * DEFINED whether we behave as if the field were programmed
11645 * within bounds, or if a level 0 Translation fault is generated.
11647 * With FEAT_LVA, fault on less than minimum becomes required,
11648 * so our choice is to always raise the fault.
11650 if (param
.tsz_oob
) {
11651 fault_type
= ARMFault_Translation
;
11655 addrsize
= 64 - 8 * param
.tbi
;
11656 inputsize
= 64 - param
.tsz
;
11659 * Bound PS by PARANGE to find the effective output address size.
11660 * ID_AA64MMFR0 is a read-only register so values outside of the
11661 * supported mappings can be considered an implementation error.
11663 ps
= FIELD_EX64(cpu
->isar
.id_aa64mmfr0
, ID_AA64MMFR0
, PARANGE
);
11664 ps
= MIN(ps
, param
.ps
);
11665 assert(ps
< ARRAY_SIZE(pamax_map
));
11666 outputsize
= pamax_map
[ps
];
11668 param
= aa32_va_parameters(env
, address
, mmu_idx
);
11670 addrsize
= (mmu_idx
== ARMMMUIdx_Stage2
? 40 : 32);
11671 inputsize
= addrsize
- param
.tsz
;
11676 * We determined the region when collecting the parameters, but we
11677 * have not yet validated that the address is valid for the region.
11678 * Extract the top bits and verify that they all match select.
11680 * For aa32, if inputsize == addrsize, then we have selected the
11681 * region by exclusion in aa32_va_parameters and there is no more
11682 * validation to do here.
11684 if (inputsize
< addrsize
) {
11685 target_ulong top_bits
= sextract64(address
, inputsize
,
11686 addrsize
- inputsize
);
11687 if (-top_bits
!= param
.select
) {
11688 /* The gap between the two regions is a Translation fault */
11689 fault_type
= ARMFault_Translation
;
11694 if (param
.using64k
) {
11696 } else if (param
.using16k
) {
11702 /* Note that QEMU ignores shareability and cacheability attributes,
11703 * so we don't need to do anything with the SH, ORGN, IRGN fields
11704 * in the TTBCR. Similarly, TTBCR:A1 selects whether we get the
11705 * ASID from TTBR0 or TTBR1, but QEMU's TLB doesn't currently
11706 * implement any ASID-like capability so we can ignore it (instead
11707 * we will always flush the TLB any time the ASID is changed).
11709 ttbr
= regime_ttbr(env
, mmu_idx
, param
.select
);
11711 /* Here we should have set up all the parameters for the translation:
11712 * inputsize, ttbr, epd, stride, tbi
11716 /* Translation table walk disabled => Translation fault on TLB miss
11717 * Note: This is always 0 on 64-bit EL2 and EL3.
11722 if (mmu_idx
!= ARMMMUIdx_Stage2
&& mmu_idx
!= ARMMMUIdx_Stage2_S
) {
11723 /* The starting level depends on the virtual address size (which can
11724 * be up to 48 bits) and the translation granule size. It indicates
11725 * the number of strides (stride bits at a time) needed to
11726 * consume the bits of the input address. In the pseudocode this is:
11727 * level = 4 - RoundUp((inputsize - grainsize) / stride)
11728 * where their 'inputsize' is our 'inputsize', 'grainsize' is
11729 * our 'stride + 3' and 'stride' is our 'stride'.
11730 * Applying the usual "rounded up m/n is (m+n-1)/n" and simplifying:
11731 * = 4 - (inputsize - stride - 3 + stride - 1) / stride
11732 * = 4 - (inputsize - 4) / stride;
11734 level
= 4 - (inputsize
- 4) / stride
;
11736 /* For stage 2 translations the starting level is specified by the
11737 * VTCR_EL2.SL0 field (whose interpretation depends on the page size)
11739 uint32_t sl0
= extract32(tcr
->raw_tcr
, 6, 2);
11740 uint32_t sl2
= extract64(tcr
->raw_tcr
, 33, 1);
11741 uint32_t startlevel
;
11744 /* SL2 is RES0 unless DS=1 & 4kb granule. */
11745 if (param
.ds
&& stride
== 9 && sl2
) {
11748 fault_type
= ARMFault_Translation
;
11752 } else if (!aarch64
|| stride
== 9) {
11753 /* AArch32 or 4KB pages */
11754 startlevel
= 2 - sl0
;
11756 if (cpu_isar_feature(aa64_st
, cpu
)) {
11760 /* 16KB or 64KB pages */
11761 startlevel
= 3 - sl0
;
11764 /* Check that the starting level is valid. */
11765 ok
= check_s2_mmu_setup(cpu
, aarch64
, startlevel
,
11766 inputsize
, stride
, outputsize
);
11768 fault_type
= ARMFault_Translation
;
11771 level
= startlevel
;
11774 indexmask_grainsize
= MAKE_64BIT_MASK(0, stride
+ 3);
11775 indexmask
= MAKE_64BIT_MASK(0, inputsize
- (stride
* (4 - level
)));
11777 /* Now we can extract the actual base address from the TTBR */
11778 descaddr
= extract64(ttbr
, 0, 48);
11781 * For FEAT_LPA and PS=6, bits [51:48] of descaddr are in [5:2] of TTBR.
11783 * Otherwise, if the base address is out of range, raise AddressSizeFault.
11784 * In the pseudocode, this is !IsZero(baseregister<47:outputsize>),
11785 * but we've just cleared the bits above 47, so simplify the test.
11787 if (outputsize
> 48) {
11788 descaddr
|= extract64(ttbr
, 2, 4) << 48;
11789 } else if (descaddr
>> outputsize
) {
11791 fault_type
= ARMFault_AddressSize
;
11796 * We rely on this masking to clear the RES0 bits at the bottom of the TTBR
11797 * and also to mask out CnP (bit 0) which could validly be non-zero.
11799 descaddr
&= ~indexmask
;
11802 * For AArch32, the address field in the descriptor goes up to bit 39
11803 * for both v7 and v8. However, for v8 the SBZ bits [47:40] must be 0
11804 * or an AddressSize fault is raised. So for v8 we extract those SBZ
11805 * bits as part of the address, which will be checked via outputsize.
11806 * For AArch64, the address field goes up to bit 47, or 49 with FEAT_LPA2;
11807 * the highest bits of a 52-bit output are placed elsewhere.
11810 descaddrmask
= MAKE_64BIT_MASK(0, 50);
11811 } else if (arm_feature(env
, ARM_FEATURE_V8
)) {
11812 descaddrmask
= MAKE_64BIT_MASK(0, 48);
11814 descaddrmask
= MAKE_64BIT_MASK(0, 40);
11816 descaddrmask
&= ~indexmask_grainsize
;
11818 /* Secure accesses start with the page table in secure memory and
11819 * can be downgraded to non-secure at any step. Non-secure accesses
11820 * remain non-secure. We implement this by just ORing in the NSTable/NS
11821 * bits at each step.
11823 tableattrs
= regime_is_secure(env
, mmu_idx
) ? 0 : (1 << 4);
11825 uint64_t descriptor
;
11828 descaddr
|= (address
>> (stride
* (4 - level
))) & indexmask
;
11830 nstable
= extract32(tableattrs
, 4, 1);
11831 descriptor
= arm_ldq_ptw(cs
, descaddr
, !nstable
, mmu_idx
, fi
);
11832 if (fi
->type
!= ARMFault_None
) {
11836 if (!(descriptor
& 1) ||
11837 (!(descriptor
& 2) && (level
== 3))) {
11838 /* Invalid, or the Reserved level 3 encoding */
11842 descaddr
= descriptor
& descaddrmask
;
11845 * For FEAT_LPA and PS=6, bits [51:48] of descaddr are in [15:12]
11846 * of descriptor. For FEAT_LPA2 and effective DS, bits [51:50] of
11847 * descaddr are in [9:8]. Otherwise, if descaddr is out of range,
11848 * raise AddressSizeFault.
11850 if (outputsize
> 48) {
11852 descaddr
|= extract64(descriptor
, 8, 2) << 50;
11854 descaddr
|= extract64(descriptor
, 12, 4) << 48;
11856 } else if (descaddr
>> outputsize
) {
11857 fault_type
= ARMFault_AddressSize
;
11861 if ((descriptor
& 2) && (level
< 3)) {
11862 /* Table entry. The top five bits are attributes which may
11863 * propagate down through lower levels of the table (and
11864 * which are all arranged so that 0 means "no effect", so
11865 * we can gather them up by ORing in the bits at each level).
11867 tableattrs
|= extract64(descriptor
, 59, 5);
11869 indexmask
= indexmask_grainsize
;
11873 * Block entry at level 1 or 2, or page entry at level 3.
11874 * These are basically the same thing, although the number
11875 * of bits we pull in from the vaddr varies. Note that although
11876 * descaddrmask masks enough of the low bits of the descriptor
11877 * to give a correct page or table address, the address field
11878 * in a block descriptor is smaller; so we need to explicitly
11879 * clear the lower bits here before ORing in the low vaddr bits.
11881 page_size
= (1ULL << ((stride
* (4 - level
)) + 3));
11882 descaddr
&= ~(page_size
- 1);
11883 descaddr
|= (address
& (page_size
- 1));
11884 /* Extract attributes from the descriptor */
11885 attrs
= extract64(descriptor
, 2, 10)
11886 | (extract64(descriptor
, 52, 12) << 10);
11888 if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11889 /* Stage 2 table descriptors do not include any attribute fields */
11892 /* Merge in attributes from table descriptors */
11893 attrs
|= nstable
<< 3; /* NS */
11894 guarded
= extract64(descriptor
, 50, 1); /* GP */
11896 /* HPD disables all the table attributes except NSTable. */
11899 attrs
|= extract32(tableattrs
, 0, 2) << 11; /* XN, PXN */
11900 /* The sense of AP[1] vs APTable[0] is reversed, as APTable[0] == 1
11901 * means "force PL1 access only", which means forcing AP[1] to 0.
11903 attrs
&= ~(extract32(tableattrs
, 2, 1) << 4); /* !APT[0] => AP[1] */
11904 attrs
|= extract32(tableattrs
, 3, 1) << 5; /* APT[1] => AP[2] */
11907 /* Here descaddr is the final physical address, and attributes
11908 * are all in attrs.
11910 fault_type
= ARMFault_AccessFlag
;
11911 if ((attrs
& (1 << 8)) == 0) {
11916 ap
= extract32(attrs
, 4, 2);
11918 if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11919 ns
= mmu_idx
== ARMMMUIdx_Stage2
;
11920 xn
= extract32(attrs
, 11, 2);
11921 *prot
= get_S2prot(env
, ap
, xn
, s1_is_el0
);
11923 ns
= extract32(attrs
, 3, 1);
11924 xn
= extract32(attrs
, 12, 1);
11925 pxn
= extract32(attrs
, 11, 1);
11926 *prot
= get_S1prot(env
, mmu_idx
, aarch64
, ap
, ns
, xn
, pxn
);
11929 fault_type
= ARMFault_Permission
;
11930 if (!(*prot
& (1 << access_type
))) {
11935 /* The NS bit will (as required by the architecture) have no effect if
11936 * the CPU doesn't support TZ or this is a non-secure translation
11937 * regime, because the attribute will already be non-secure.
11939 txattrs
->secure
= false;
11941 /* When in aarch64 mode, and BTI is enabled, remember GP in the IOTLB. */
11942 if (aarch64
&& guarded
&& cpu_isar_feature(aa64_bti
, cpu
)) {
11943 arm_tlb_bti_gp(txattrs
) = true;
11946 if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
11947 cacheattrs
->is_s2_format
= true;
11948 cacheattrs
->attrs
= extract32(attrs
, 0, 4);
11950 /* Index into MAIR registers for cache attributes */
11951 uint8_t attrindx
= extract32(attrs
, 0, 3);
11952 uint64_t mair
= env
->cp15
.mair_el
[regime_el(env
, mmu_idx
)];
11953 assert(attrindx
<= 7);
11954 cacheattrs
->is_s2_format
= false;
11955 cacheattrs
->attrs
= extract64(mair
, attrindx
* 8, 8);
11959 * For FEAT_LPA2 and effective DS, the SH field in the attributes
11960 * was re-purposed for output address bits. The SH attribute in
11961 * that case comes from TCR_ELx, which we extracted earlier.
11964 cacheattrs
->shareability
= param
.sh
;
11966 cacheattrs
->shareability
= extract32(attrs
, 6, 2);
11969 *phys_ptr
= descaddr
;
11970 *page_size_ptr
= page_size
;
11974 fi
->type
= fault_type
;
11976 /* Tag the error as S2 for failed S1 PTW at S2 or ordinary S2. */
11977 fi
->stage2
= fi
->s1ptw
|| (mmu_idx
== ARMMMUIdx_Stage2
||
11978 mmu_idx
== ARMMMUIdx_Stage2_S
);
11979 fi
->s1ns
= mmu_idx
== ARMMMUIdx_Stage2
;
11983 static inline void get_phys_addr_pmsav7_default(CPUARMState
*env
,
11985 int32_t address
, int *prot
)
11987 if (!arm_feature(env
, ARM_FEATURE_M
)) {
11988 *prot
= PAGE_READ
| PAGE_WRITE
;
11990 case 0xF0000000 ... 0xFFFFFFFF:
11991 if (regime_sctlr(env
, mmu_idx
) & SCTLR_V
) {
11992 /* hivecs execing is ok */
11993 *prot
|= PAGE_EXEC
;
11996 case 0x00000000 ... 0x7FFFFFFF:
11997 *prot
|= PAGE_EXEC
;
12001 /* Default system address map for M profile cores.
12002 * The architecture specifies which regions are execute-never;
12003 * at the MPU level no other checks are defined.
12006 case 0x00000000 ... 0x1fffffff: /* ROM */
12007 case 0x20000000 ... 0x3fffffff: /* SRAM */
12008 case 0x60000000 ... 0x7fffffff: /* RAM */
12009 case 0x80000000 ... 0x9fffffff: /* RAM */
12010 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
12012 case 0x40000000 ... 0x5fffffff: /* Peripheral */
12013 case 0xa0000000 ... 0xbfffffff: /* Device */
12014 case 0xc0000000 ... 0xdfffffff: /* Device */
12015 case 0xe0000000 ... 0xffffffff: /* System */
12016 *prot
= PAGE_READ
| PAGE_WRITE
;
12019 g_assert_not_reached();
12024 static bool pmsav7_use_background_region(ARMCPU
*cpu
,
12025 ARMMMUIdx mmu_idx
, bool is_user
)
12027 /* Return true if we should use the default memory map as a
12028 * "background" region if there are no hits against any MPU regions.
12030 CPUARMState
*env
= &cpu
->env
;
12036 if (arm_feature(env
, ARM_FEATURE_M
)) {
12037 return env
->v7m
.mpu_ctrl
[regime_is_secure(env
, mmu_idx
)]
12038 & R_V7M_MPU_CTRL_PRIVDEFENA_MASK
;
12040 return regime_sctlr(env
, mmu_idx
) & SCTLR_BR
;
12044 static inline bool m_is_ppb_region(CPUARMState
*env
, uint32_t address
)
12046 /* True if address is in the M profile PPB region 0xe0000000 - 0xe00fffff */
12047 return arm_feature(env
, ARM_FEATURE_M
) &&
12048 extract32(address
, 20, 12) == 0xe00;
12051 static inline bool m_is_system_region(CPUARMState
*env
, uint32_t address
)
12053 /* True if address is in the M profile system region
12054 * 0xe0000000 - 0xffffffff
12056 return arm_feature(env
, ARM_FEATURE_M
) && extract32(address
, 29, 3) == 0x7;
12059 static bool get_phys_addr_pmsav7(CPUARMState
*env
, uint32_t address
,
12060 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
12061 hwaddr
*phys_ptr
, int *prot
,
12062 target_ulong
*page_size
,
12063 ARMMMUFaultInfo
*fi
)
12065 ARMCPU
*cpu
= env_archcpu(env
);
12067 bool is_user
= regime_is_user(env
, mmu_idx
);
12069 *phys_ptr
= address
;
12070 *page_size
= TARGET_PAGE_SIZE
;
12073 if (regime_translation_disabled(env
, mmu_idx
) ||
12074 m_is_ppb_region(env
, address
)) {
12075 /* MPU disabled or M profile PPB access: use default memory map.
12076 * The other case which uses the default memory map in the
12077 * v7M ARM ARM pseudocode is exception vector reads from the vector
12078 * table. In QEMU those accesses are done in arm_v7m_load_vector(),
12079 * which always does a direct read using address_space_ldl(), rather
12080 * than going via this function, so we don't need to check that here.
12082 get_phys_addr_pmsav7_default(env
, mmu_idx
, address
, prot
);
12083 } else { /* MPU enabled */
12084 for (n
= (int)cpu
->pmsav7_dregion
- 1; n
>= 0; n
--) {
12085 /* region search */
12086 uint32_t base
= env
->pmsav7
.drbar
[n
];
12087 uint32_t rsize
= extract32(env
->pmsav7
.drsr
[n
], 1, 5);
12089 bool srdis
= false;
12091 if (!(env
->pmsav7
.drsr
[n
] & 0x1)) {
12096 qemu_log_mask(LOG_GUEST_ERROR
,
12097 "DRSR[%d]: Rsize field cannot be 0\n", n
);
12101 rmask
= (1ull << rsize
) - 1;
12103 if (base
& rmask
) {
12104 qemu_log_mask(LOG_GUEST_ERROR
,
12105 "DRBAR[%d]: 0x%" PRIx32
" misaligned "
12106 "to DRSR region size, mask = 0x%" PRIx32
"\n",
12111 if (address
< base
|| address
> base
+ rmask
) {
12113 * Address not in this region. We must check whether the
12114 * region covers addresses in the same page as our address.
12115 * In that case we must not report a size that covers the
12116 * whole page for a subsequent hit against a different MPU
12117 * region or the background region, because it would result in
12118 * incorrect TLB hits for subsequent accesses to addresses that
12119 * are in this MPU region.
12121 if (ranges_overlap(base
, rmask
,
12122 address
& TARGET_PAGE_MASK
,
12123 TARGET_PAGE_SIZE
)) {
12129 /* Region matched */
12131 if (rsize
>= 8) { /* no subregions for regions < 256 bytes */
12133 uint32_t srdis_mask
;
12135 rsize
-= 3; /* sub region size (power of 2) */
12136 snd
= ((address
- base
) >> rsize
) & 0x7;
12137 srdis
= extract32(env
->pmsav7
.drsr
[n
], snd
+ 8, 1);
12139 srdis_mask
= srdis
? 0x3 : 0x0;
12140 for (i
= 2; i
<= 8 && rsize
< TARGET_PAGE_BITS
; i
*= 2) {
12141 /* This will check in groups of 2, 4 and then 8, whether
12142 * the subregion bits are consistent. rsize is incremented
12143 * back up to give the region size, considering consistent
12144 * adjacent subregions as one region. Stop testing if rsize
12145 * is already big enough for an entire QEMU page.
12147 int snd_rounded
= snd
& ~(i
- 1);
12148 uint32_t srdis_multi
= extract32(env
->pmsav7
.drsr
[n
],
12149 snd_rounded
+ 8, i
);
12150 if (srdis_mask
^ srdis_multi
) {
12153 srdis_mask
= (srdis_mask
<< i
) | srdis_mask
;
12160 if (rsize
< TARGET_PAGE_BITS
) {
12161 *page_size
= 1 << rsize
;
12166 if (n
== -1) { /* no hits */
12167 if (!pmsav7_use_background_region(cpu
, mmu_idx
, is_user
)) {
12168 /* background fault */
12169 fi
->type
= ARMFault_Background
;
12172 get_phys_addr_pmsav7_default(env
, mmu_idx
, address
, prot
);
12173 } else { /* a MPU hit! */
12174 uint32_t ap
= extract32(env
->pmsav7
.dracr
[n
], 8, 3);
12175 uint32_t xn
= extract32(env
->pmsav7
.dracr
[n
], 12, 1);
12177 if (m_is_system_region(env
, address
)) {
12178 /* System space is always execute never */
12182 if (is_user
) { /* User mode AP bit decoding */
12187 break; /* no access */
12189 *prot
|= PAGE_WRITE
;
12193 *prot
|= PAGE_READ
| PAGE_EXEC
;
12196 /* for v7M, same as 6; for R profile a reserved value */
12197 if (arm_feature(env
, ARM_FEATURE_M
)) {
12198 *prot
|= PAGE_READ
| PAGE_EXEC
;
12203 qemu_log_mask(LOG_GUEST_ERROR
,
12204 "DRACR[%d]: Bad value for AP bits: 0x%"
12205 PRIx32
"\n", n
, ap
);
12207 } else { /* Priv. mode AP bits decoding */
12210 break; /* no access */
12214 *prot
|= PAGE_WRITE
;
12218 *prot
|= PAGE_READ
| PAGE_EXEC
;
12221 /* for v7M, same as 6; for R profile a reserved value */
12222 if (arm_feature(env
, ARM_FEATURE_M
)) {
12223 *prot
|= PAGE_READ
| PAGE_EXEC
;
12228 qemu_log_mask(LOG_GUEST_ERROR
,
12229 "DRACR[%d]: Bad value for AP bits: 0x%"
12230 PRIx32
"\n", n
, ap
);
12234 /* execute never */
12236 *prot
&= ~PAGE_EXEC
;
12241 fi
->type
= ARMFault_Permission
;
12243 return !(*prot
& (1 << access_type
));
12246 static bool v8m_is_sau_exempt(CPUARMState
*env
,
12247 uint32_t address
, MMUAccessType access_type
)
12249 /* The architecture specifies that certain address ranges are
12250 * exempt from v8M SAU/IDAU checks.
12253 (access_type
== MMU_INST_FETCH
&& m_is_system_region(env
, address
)) ||
12254 (address
>= 0xe0000000 && address
<= 0xe0002fff) ||
12255 (address
>= 0xe000e000 && address
<= 0xe000efff) ||
12256 (address
>= 0xe002e000 && address
<= 0xe002efff) ||
12257 (address
>= 0xe0040000 && address
<= 0xe0041fff) ||
12258 (address
>= 0xe00ff000 && address
<= 0xe00fffff);
12261 void v8m_security_lookup(CPUARMState
*env
, uint32_t address
,
12262 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
12263 V8M_SAttributes
*sattrs
)
12265 /* Look up the security attributes for this address. Compare the
12266 * pseudocode SecurityCheck() function.
12267 * We assume the caller has zero-initialized *sattrs.
12269 ARMCPU
*cpu
= env_archcpu(env
);
12271 bool idau_exempt
= false, idau_ns
= true, idau_nsc
= true;
12272 int idau_region
= IREGION_NOTVALID
;
12273 uint32_t addr_page_base
= address
& TARGET_PAGE_MASK
;
12274 uint32_t addr_page_limit
= addr_page_base
+ (TARGET_PAGE_SIZE
- 1);
12277 IDAUInterfaceClass
*iic
= IDAU_INTERFACE_GET_CLASS(cpu
->idau
);
12278 IDAUInterface
*ii
= IDAU_INTERFACE(cpu
->idau
);
12280 iic
->check(ii
, address
, &idau_region
, &idau_exempt
, &idau_ns
,
12284 if (access_type
== MMU_INST_FETCH
&& extract32(address
, 28, 4) == 0xf) {
12285 /* 0xf0000000..0xffffffff is always S for insn fetches */
12289 if (idau_exempt
|| v8m_is_sau_exempt(env
, address
, access_type
)) {
12290 sattrs
->ns
= !regime_is_secure(env
, mmu_idx
);
12294 if (idau_region
!= IREGION_NOTVALID
) {
12295 sattrs
->irvalid
= true;
12296 sattrs
->iregion
= idau_region
;
12299 switch (env
->sau
.ctrl
& 3) {
12300 case 0: /* SAU.ENABLE == 0, SAU.ALLNS == 0 */
12302 case 2: /* SAU.ENABLE == 0, SAU.ALLNS == 1 */
12305 default: /* SAU.ENABLE == 1 */
12306 for (r
= 0; r
< cpu
->sau_sregion
; r
++) {
12307 if (env
->sau
.rlar
[r
] & 1) {
12308 uint32_t base
= env
->sau
.rbar
[r
] & ~0x1f;
12309 uint32_t limit
= env
->sau
.rlar
[r
] | 0x1f;
12311 if (base
<= address
&& limit
>= address
) {
12312 if (base
> addr_page_base
|| limit
< addr_page_limit
) {
12313 sattrs
->subpage
= true;
12315 if (sattrs
->srvalid
) {
12316 /* If we hit in more than one region then we must report
12317 * as Secure, not NS-Callable, with no valid region
12320 sattrs
->ns
= false;
12321 sattrs
->nsc
= false;
12322 sattrs
->sregion
= 0;
12323 sattrs
->srvalid
= false;
12326 if (env
->sau
.rlar
[r
] & 2) {
12327 sattrs
->nsc
= true;
12331 sattrs
->srvalid
= true;
12332 sattrs
->sregion
= r
;
12336 * Address not in this region. We must check whether the
12337 * region covers addresses in the same page as our address.
12338 * In that case we must not report a size that covers the
12339 * whole page for a subsequent hit against a different MPU
12340 * region or the background region, because it would result
12341 * in incorrect TLB hits for subsequent accesses to
12342 * addresses that are in this MPU region.
12344 if (limit
>= base
&&
12345 ranges_overlap(base
, limit
- base
+ 1,
12347 TARGET_PAGE_SIZE
)) {
12348 sattrs
->subpage
= true;
12357 * The IDAU will override the SAU lookup results if it specifies
12358 * higher security than the SAU does.
12361 if (sattrs
->ns
|| (!idau_nsc
&& sattrs
->nsc
)) {
12362 sattrs
->ns
= false;
12363 sattrs
->nsc
= idau_nsc
;
12368 bool pmsav8_mpu_lookup(CPUARMState
*env
, uint32_t address
,
12369 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
12370 hwaddr
*phys_ptr
, MemTxAttrs
*txattrs
,
12371 int *prot
, bool *is_subpage
,
12372 ARMMMUFaultInfo
*fi
, uint32_t *mregion
)
12374 /* Perform a PMSAv8 MPU lookup (without also doing the SAU check
12375 * that a full phys-to-virt translation does).
12376 * mregion is (if not NULL) set to the region number which matched,
12377 * or -1 if no region number is returned (MPU off, address did not
12378 * hit a region, address hit in multiple regions).
12379 * We set is_subpage to true if the region hit doesn't cover the
12380 * entire TARGET_PAGE the address is within.
12382 ARMCPU
*cpu
= env_archcpu(env
);
12383 bool is_user
= regime_is_user(env
, mmu_idx
);
12384 uint32_t secure
= regime_is_secure(env
, mmu_idx
);
12386 int matchregion
= -1;
12388 uint32_t addr_page_base
= address
& TARGET_PAGE_MASK
;
12389 uint32_t addr_page_limit
= addr_page_base
+ (TARGET_PAGE_SIZE
- 1);
12391 *is_subpage
= false;
12392 *phys_ptr
= address
;
12398 /* Unlike the ARM ARM pseudocode, we don't need to check whether this
12399 * was an exception vector read from the vector table (which is always
12400 * done using the default system address map), because those accesses
12401 * are done in arm_v7m_load_vector(), which always does a direct
12402 * read using address_space_ldl(), rather than going via this function.
12404 if (regime_translation_disabled(env
, mmu_idx
)) { /* MPU disabled */
12406 } else if (m_is_ppb_region(env
, address
)) {
12409 if (pmsav7_use_background_region(cpu
, mmu_idx
, is_user
)) {
12413 for (n
= (int)cpu
->pmsav7_dregion
- 1; n
>= 0; n
--) {
12414 /* region search */
12415 /* Note that the base address is bits [31:5] from the register
12416 * with bits [4:0] all zeroes, but the limit address is bits
12417 * [31:5] from the register with bits [4:0] all ones.
12419 uint32_t base
= env
->pmsav8
.rbar
[secure
][n
] & ~0x1f;
12420 uint32_t limit
= env
->pmsav8
.rlar
[secure
][n
] | 0x1f;
12422 if (!(env
->pmsav8
.rlar
[secure
][n
] & 0x1)) {
12423 /* Region disabled */
12427 if (address
< base
|| address
> limit
) {
12429 * Address not in this region. We must check whether the
12430 * region covers addresses in the same page as our address.
12431 * In that case we must not report a size that covers the
12432 * whole page for a subsequent hit against a different MPU
12433 * region or the background region, because it would result in
12434 * incorrect TLB hits for subsequent accesses to addresses that
12435 * are in this MPU region.
12437 if (limit
>= base
&&
12438 ranges_overlap(base
, limit
- base
+ 1,
12440 TARGET_PAGE_SIZE
)) {
12441 *is_subpage
= true;
12446 if (base
> addr_page_base
|| limit
< addr_page_limit
) {
12447 *is_subpage
= true;
12450 if (matchregion
!= -1) {
12451 /* Multiple regions match -- always a failure (unlike
12452 * PMSAv7 where highest-numbered-region wins)
12454 fi
->type
= ARMFault_Permission
;
12465 /* background fault */
12466 fi
->type
= ARMFault_Background
;
12470 if (matchregion
== -1) {
12471 /* hit using the background region */
12472 get_phys_addr_pmsav7_default(env
, mmu_idx
, address
, prot
);
12474 uint32_t ap
= extract32(env
->pmsav8
.rbar
[secure
][matchregion
], 1, 2);
12475 uint32_t xn
= extract32(env
->pmsav8
.rbar
[secure
][matchregion
], 0, 1);
12478 if (arm_feature(env
, ARM_FEATURE_V8_1M
)) {
12479 pxn
= extract32(env
->pmsav8
.rlar
[secure
][matchregion
], 4, 1);
12482 if (m_is_system_region(env
, address
)) {
12483 /* System space is always execute never */
12487 *prot
= simple_ap_to_rw_prot(env
, mmu_idx
, ap
);
12488 if (*prot
&& !xn
&& !(pxn
&& !is_user
)) {
12489 *prot
|= PAGE_EXEC
;
12491 /* We don't need to look the attribute up in the MAIR0/MAIR1
12492 * registers because that only tells us about cacheability.
12495 *mregion
= matchregion
;
12499 fi
->type
= ARMFault_Permission
;
12501 return !(*prot
& (1 << access_type
));
12505 static bool get_phys_addr_pmsav8(CPUARMState
*env
, uint32_t address
,
12506 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
12507 hwaddr
*phys_ptr
, MemTxAttrs
*txattrs
,
12508 int *prot
, target_ulong
*page_size
,
12509 ARMMMUFaultInfo
*fi
)
12511 uint32_t secure
= regime_is_secure(env
, mmu_idx
);
12512 V8M_SAttributes sattrs
= {};
12514 bool mpu_is_subpage
;
12516 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
)) {
12517 v8m_security_lookup(env
, address
, access_type
, mmu_idx
, &sattrs
);
12518 if (access_type
== MMU_INST_FETCH
) {
12519 /* Instruction fetches always use the MMU bank and the
12520 * transaction attribute determined by the fetch address,
12521 * regardless of CPU state. This is painful for QEMU
12522 * to handle, because it would mean we need to encode
12523 * into the mmu_idx not just the (user, negpri) information
12524 * for the current security state but also that for the
12525 * other security state, which would balloon the number
12526 * of mmu_idx values needed alarmingly.
12527 * Fortunately we can avoid this because it's not actually
12528 * possible to arbitrarily execute code from memory with
12529 * the wrong security attribute: it will always generate
12530 * an exception of some kind or another, apart from the
12531 * special case of an NS CPU executing an SG instruction
12532 * in S&NSC memory. So we always just fail the translation
12533 * here and sort things out in the exception handler
12534 * (including possibly emulating an SG instruction).
12536 if (sattrs
.ns
!= !secure
) {
12538 fi
->type
= ARMFault_QEMU_NSCExec
;
12540 fi
->type
= ARMFault_QEMU_SFault
;
12542 *page_size
= sattrs
.subpage
? 1 : TARGET_PAGE_SIZE
;
12543 *phys_ptr
= address
;
12548 /* For data accesses we always use the MMU bank indicated
12549 * by the current CPU state, but the security attributes
12550 * might downgrade a secure access to nonsecure.
12553 txattrs
->secure
= false;
12554 } else if (!secure
) {
12555 /* NS access to S memory must fault.
12556 * Architecturally we should first check whether the
12557 * MPU information for this address indicates that we
12558 * are doing an unaligned access to Device memory, which
12559 * should generate a UsageFault instead. QEMU does not
12560 * currently check for that kind of unaligned access though.
12561 * If we added it we would need to do so as a special case
12562 * for M_FAKE_FSR_SFAULT in arm_v7m_cpu_do_interrupt().
12564 fi
->type
= ARMFault_QEMU_SFault
;
12565 *page_size
= sattrs
.subpage
? 1 : TARGET_PAGE_SIZE
;
12566 *phys_ptr
= address
;
12573 ret
= pmsav8_mpu_lookup(env
, address
, access_type
, mmu_idx
, phys_ptr
,
12574 txattrs
, prot
, &mpu_is_subpage
, fi
, NULL
);
12575 *page_size
= sattrs
.subpage
|| mpu_is_subpage
? 1 : TARGET_PAGE_SIZE
;
12579 static bool get_phys_addr_pmsav5(CPUARMState
*env
, uint32_t address
,
12580 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
12581 hwaddr
*phys_ptr
, int *prot
,
12582 ARMMMUFaultInfo
*fi
)
12587 bool is_user
= regime_is_user(env
, mmu_idx
);
12589 if (regime_translation_disabled(env
, mmu_idx
)) {
12590 /* MPU disabled. */
12591 *phys_ptr
= address
;
12592 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
12596 *phys_ptr
= address
;
12597 for (n
= 7; n
>= 0; n
--) {
12598 base
= env
->cp15
.c6_region
[n
];
12599 if ((base
& 1) == 0) {
12602 mask
= 1 << ((base
>> 1) & 0x1f);
12603 /* Keep this shift separate from the above to avoid an
12604 (undefined) << 32. */
12605 mask
= (mask
<< 1) - 1;
12606 if (((base
^ address
) & ~mask
) == 0) {
12611 fi
->type
= ARMFault_Background
;
12615 if (access_type
== MMU_INST_FETCH
) {
12616 mask
= env
->cp15
.pmsav5_insn_ap
;
12618 mask
= env
->cp15
.pmsav5_data_ap
;
12620 mask
= (mask
>> (n
* 4)) & 0xf;
12623 fi
->type
= ARMFault_Permission
;
12628 fi
->type
= ARMFault_Permission
;
12632 *prot
= PAGE_READ
| PAGE_WRITE
;
12637 *prot
|= PAGE_WRITE
;
12641 *prot
= PAGE_READ
| PAGE_WRITE
;
12645 fi
->type
= ARMFault_Permission
;
12655 /* Bad permission. */
12656 fi
->type
= ARMFault_Permission
;
12660 *prot
|= PAGE_EXEC
;
12664 /* Combine either inner or outer cacheability attributes for normal
12665 * memory, according to table D4-42 and pseudocode procedure
12666 * CombineS1S2AttrHints() of ARM DDI 0487B.b (the ARMv8 ARM).
12668 * NB: only stage 1 includes allocation hints (RW bits), leading to
12671 static uint8_t combine_cacheattr_nibble(uint8_t s1
, uint8_t s2
)
12673 if (s1
== 4 || s2
== 4) {
12674 /* non-cacheable has precedence */
12676 } else if (extract32(s1
, 2, 2) == 0 || extract32(s1
, 2, 2) == 2) {
12677 /* stage 1 write-through takes precedence */
12679 } else if (extract32(s2
, 2, 2) == 2) {
12680 /* stage 2 write-through takes precedence, but the allocation hint
12681 * is still taken from stage 1
12683 return (2 << 2) | extract32(s1
, 0, 2);
12684 } else { /* write-back */
12690 * Combine the memory type and cacheability attributes of
12691 * s1 and s2 for the HCR_EL2.FWB == 0 case, returning the
12692 * combined attributes in MAIR_EL1 format.
12694 static uint8_t combined_attrs_nofwb(CPUARMState
*env
,
12695 ARMCacheAttrs s1
, ARMCacheAttrs s2
)
12697 uint8_t s1lo
, s2lo
, s1hi
, s2hi
, s2_mair_attrs
, ret_attrs
;
12699 s2_mair_attrs
= convert_stage2_attrs(env
, s2
.attrs
);
12701 s1lo
= extract32(s1
.attrs
, 0, 4);
12702 s2lo
= extract32(s2_mair_attrs
, 0, 4);
12703 s1hi
= extract32(s1
.attrs
, 4, 4);
12704 s2hi
= extract32(s2_mair_attrs
, 4, 4);
12706 /* Combine memory type and cacheability attributes */
12707 if (s1hi
== 0 || s2hi
== 0) {
12708 /* Device has precedence over normal */
12709 if (s1lo
== 0 || s2lo
== 0) {
12710 /* nGnRnE has precedence over anything */
12712 } else if (s1lo
== 4 || s2lo
== 4) {
12713 /* non-Reordering has precedence over Reordering */
12714 ret_attrs
= 4; /* nGnRE */
12715 } else if (s1lo
== 8 || s2lo
== 8) {
12716 /* non-Gathering has precedence over Gathering */
12717 ret_attrs
= 8; /* nGRE */
12719 ret_attrs
= 0xc; /* GRE */
12721 } else { /* Normal memory */
12722 /* Outer/inner cacheability combine independently */
12723 ret_attrs
= combine_cacheattr_nibble(s1hi
, s2hi
) << 4
12724 | combine_cacheattr_nibble(s1lo
, s2lo
);
12729 static uint8_t force_cacheattr_nibble_wb(uint8_t attr
)
12732 * Given the 4 bits specifying the outer or inner cacheability
12733 * in MAIR format, return a value specifying Normal Write-Back,
12734 * with the allocation and transient hints taken from the input
12735 * if the input specified some kind of cacheable attribute.
12737 if (attr
== 0 || attr
== 4) {
12739 * 0 == an UNPREDICTABLE encoding
12740 * 4 == Non-cacheable
12741 * Either way, force Write-Back RW allocate non-transient
12745 /* Change WriteThrough to WriteBack, keep allocation and transient hints */
12750 * Combine the memory type and cacheability attributes of
12751 * s1 and s2 for the HCR_EL2.FWB == 1 case, returning the
12752 * combined attributes in MAIR_EL1 format.
12754 static uint8_t combined_attrs_fwb(CPUARMState
*env
,
12755 ARMCacheAttrs s1
, ARMCacheAttrs s2
)
12757 switch (s2
.attrs
) {
12759 /* Use stage 1 attributes */
12763 * Force Normal Write-Back. Note that if S1 is Normal cacheable
12764 * then we take the allocation hints from it; otherwise it is
12765 * RW allocate, non-transient.
12767 if ((s1
.attrs
& 0xf0) == 0) {
12771 /* Need to check the Inner and Outer nibbles separately */
12772 return force_cacheattr_nibble_wb(s1
.attrs
& 0xf) |
12773 force_cacheattr_nibble_wb(s1
.attrs
>> 4) << 4;
12775 /* If S1 attrs are Device, use them; otherwise Normal Non-cacheable */
12776 if ((s1
.attrs
& 0xf0) == 0) {
12781 /* Force Device, of subtype specified by S2 */
12782 return s2
.attrs
<< 2;
12785 * RESERVED values (including RES0 descriptor bit [5] being nonzero);
12786 * arbitrarily force Device.
12792 /* Combine S1 and S2 cacheability/shareability attributes, per D4.5.4
12793 * and CombineS1S2Desc()
12795 * @env: CPUARMState
12796 * @s1: Attributes from stage 1 walk
12797 * @s2: Attributes from stage 2 walk
12799 static ARMCacheAttrs
combine_cacheattrs(CPUARMState
*env
,
12800 ARMCacheAttrs s1
, ARMCacheAttrs s2
)
12803 bool tagged
= false;
12805 assert(s2
.is_s2_format
&& !s1
.is_s2_format
);
12806 ret
.is_s2_format
= false;
12808 if (s1
.attrs
== 0xf0) {
12813 /* Combine shareability attributes (table D4-43) */
12814 if (s1
.shareability
== 2 || s2
.shareability
== 2) {
12815 /* if either are outer-shareable, the result is outer-shareable */
12816 ret
.shareability
= 2;
12817 } else if (s1
.shareability
== 3 || s2
.shareability
== 3) {
12818 /* if either are inner-shareable, the result is inner-shareable */
12819 ret
.shareability
= 3;
12821 /* both non-shareable */
12822 ret
.shareability
= 0;
12825 /* Combine memory type and cacheability attributes */
12826 if (arm_hcr_el2_eff(env
) & HCR_FWB
) {
12827 ret
.attrs
= combined_attrs_fwb(env
, s1
, s2
);
12829 ret
.attrs
= combined_attrs_nofwb(env
, s1
, s2
);
12833 * Any location for which the resultant memory type is any
12834 * type of Device memory is always treated as Outer Shareable.
12835 * Any location for which the resultant memory type is Normal
12836 * Inner Non-cacheable, Outer Non-cacheable is always treated
12837 * as Outer Shareable.
12838 * TODO: FEAT_XS adds another value (0x40) also meaning iNCoNC
12840 if ((ret
.attrs
& 0xf0) == 0 || ret
.attrs
== 0x44) {
12841 ret
.shareability
= 2;
12844 /* TODO: CombineS1S2Desc does not consider transient, only WB, RWA. */
12845 if (tagged
&& ret
.attrs
== 0xff) {
12853 /* get_phys_addr - get the physical address for this virtual address
12855 * Find the physical address corresponding to the given virtual address,
12856 * by doing a translation table walk on MMU based systems or using the
12857 * MPU state on MPU based systems.
12859 * Returns false if the translation was successful. Otherwise, phys_ptr, attrs,
12860 * prot and page_size may not be filled in, and the populated fsr value provides
12861 * information on why the translation aborted, in the format of a
12862 * DFSR/IFSR fault register, with the following caveats:
12863 * * we honour the short vs long DFSR format differences.
12864 * * the WnR bit is never set (the caller must do this).
12865 * * for PSMAv5 based systems we don't bother to return a full FSR format
12868 * @env: CPUARMState
12869 * @address: virtual address to get physical address for
12870 * @access_type: 0 for read, 1 for write, 2 for execute
12871 * @mmu_idx: MMU index indicating required translation regime
12872 * @phys_ptr: set to the physical address corresponding to the virtual address
12873 * @attrs: set to the memory transaction attributes to use
12874 * @prot: set to the permissions for the page containing phys_ptr
12875 * @page_size: set to the size of the page containing phys_ptr
12876 * @fi: set to fault info if the translation fails
12877 * @cacheattrs: (if non-NULL) set to the cacheability/shareability attributes
12879 bool get_phys_addr(CPUARMState
*env
, target_ulong address
,
12880 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
12881 hwaddr
*phys_ptr
, MemTxAttrs
*attrs
, int *prot
,
12882 target_ulong
*page_size
,
12883 ARMMMUFaultInfo
*fi
, ARMCacheAttrs
*cacheattrs
)
12885 ARMMMUIdx s1_mmu_idx
= stage_1_mmu_idx(mmu_idx
);
12887 if (mmu_idx
!= s1_mmu_idx
) {
12888 /* Call ourselves recursively to do the stage 1 and then stage 2
12889 * translations if mmu_idx is a two-stage regime.
12891 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
12896 ARMCacheAttrs cacheattrs2
= {};
12897 ARMMMUIdx s2_mmu_idx
;
12900 ret
= get_phys_addr(env
, address
, access_type
, s1_mmu_idx
, &ipa
,
12901 attrs
, prot
, page_size
, fi
, cacheattrs
);
12903 /* If S1 fails or S2 is disabled, return early. */
12904 if (ret
|| regime_translation_disabled(env
, ARMMMUIdx_Stage2
)) {
12909 ipa_secure
= attrs
->secure
;
12910 if (arm_is_secure_below_el3(env
)) {
12912 attrs
->secure
= !(env
->cp15
.vstcr_el2
.raw_tcr
& VSTCR_SW
);
12914 attrs
->secure
= !(env
->cp15
.vtcr_el2
.raw_tcr
& VTCR_NSW
);
12917 assert(!ipa_secure
);
12920 s2_mmu_idx
= attrs
->secure
? ARMMMUIdx_Stage2_S
: ARMMMUIdx_Stage2
;
12921 is_el0
= mmu_idx
== ARMMMUIdx_E10_0
|| mmu_idx
== ARMMMUIdx_SE10_0
;
12923 /* S1 is done. Now do S2 translation. */
12924 ret
= get_phys_addr_lpae(env
, ipa
, access_type
, s2_mmu_idx
, is_el0
,
12925 phys_ptr
, attrs
, &s2_prot
,
12926 page_size
, fi
, &cacheattrs2
);
12928 /* Combine the S1 and S2 perms. */
12931 /* If S2 fails, return early. */
12936 /* Combine the S1 and S2 cache attributes. */
12937 if (arm_hcr_el2_eff(env
) & HCR_DC
) {
12939 * HCR.DC forces the first stage attributes to
12940 * Normal Non-Shareable,
12941 * Inner Write-Back Read-Allocate Write-Allocate,
12942 * Outer Write-Back Read-Allocate Write-Allocate.
12943 * Do not overwrite Tagged within attrs.
12945 if (cacheattrs
->attrs
!= 0xf0) {
12946 cacheattrs
->attrs
= 0xff;
12948 cacheattrs
->shareability
= 0;
12950 *cacheattrs
= combine_cacheattrs(env
, *cacheattrs
, cacheattrs2
);
12952 /* Check if IPA translates to secure or non-secure PA space. */
12953 if (arm_is_secure_below_el3(env
)) {
12956 !(env
->cp15
.vstcr_el2
.raw_tcr
& (VSTCR_SA
| VSTCR_SW
));
12959 !((env
->cp15
.vtcr_el2
.raw_tcr
& (VTCR_NSA
| VTCR_NSW
))
12960 || (env
->cp15
.vstcr_el2
.raw_tcr
& (VSTCR_SA
| VSTCR_SW
)));
12966 * For non-EL2 CPUs a stage1+stage2 translation is just stage 1.
12968 mmu_idx
= stage_1_mmu_idx(mmu_idx
);
12972 /* The page table entries may downgrade secure to non-secure, but
12973 * cannot upgrade an non-secure translation regime's attributes
12976 attrs
->secure
= regime_is_secure(env
, mmu_idx
);
12977 attrs
->user
= regime_is_user(env
, mmu_idx
);
12979 /* Fast Context Switch Extension. This doesn't exist at all in v8.
12980 * In v7 and earlier it affects all stage 1 translations.
12982 if (address
< 0x02000000 && mmu_idx
!= ARMMMUIdx_Stage2
12983 && !arm_feature(env
, ARM_FEATURE_V8
)) {
12984 if (regime_el(env
, mmu_idx
) == 3) {
12985 address
+= env
->cp15
.fcseidr_s
;
12987 address
+= env
->cp15
.fcseidr_ns
;
12991 if (arm_feature(env
, ARM_FEATURE_PMSA
)) {
12993 *page_size
= TARGET_PAGE_SIZE
;
12995 if (arm_feature(env
, ARM_FEATURE_V8
)) {
12997 ret
= get_phys_addr_pmsav8(env
, address
, access_type
, mmu_idx
,
12998 phys_ptr
, attrs
, prot
, page_size
, fi
);
12999 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
13001 ret
= get_phys_addr_pmsav7(env
, address
, access_type
, mmu_idx
,
13002 phys_ptr
, prot
, page_size
, fi
);
13005 ret
= get_phys_addr_pmsav5(env
, address
, access_type
, mmu_idx
,
13006 phys_ptr
, prot
, fi
);
13008 qemu_log_mask(CPU_LOG_MMU
, "PMSA MPU lookup for %s at 0x%08" PRIx32
13009 " mmu_idx %u -> %s (prot %c%c%c)\n",
13010 access_type
== MMU_DATA_LOAD
? "reading" :
13011 (access_type
== MMU_DATA_STORE
? "writing" : "execute"),
13012 (uint32_t)address
, mmu_idx
,
13013 ret
? "Miss" : "Hit",
13014 *prot
& PAGE_READ
? 'r' : '-',
13015 *prot
& PAGE_WRITE
? 'w' : '-',
13016 *prot
& PAGE_EXEC
? 'x' : '-');
13021 /* Definitely a real MMU, not an MPU */
13023 if (regime_translation_disabled(env
, mmu_idx
)) {
13028 * MMU disabled. S1 addresses within aa64 translation regimes are
13029 * still checked for bounds -- see AArch64.TranslateAddressS1Off.
13031 if (mmu_idx
!= ARMMMUIdx_Stage2
&& mmu_idx
!= ARMMMUIdx_Stage2_S
) {
13032 int r_el
= regime_el(env
, mmu_idx
);
13033 if (arm_el_is_aa64(env
, r_el
)) {
13034 int pamax
= arm_pamax(env_archcpu(env
));
13035 uint64_t tcr
= env
->cp15
.tcr_el
[r_el
].raw_tcr
;
13038 tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
13039 if (access_type
== MMU_INST_FETCH
) {
13040 tbi
&= ~aa64_va_parameter_tbid(tcr
, mmu_idx
);
13042 tbi
= (tbi
>> extract64(address
, 55, 1)) & 1;
13043 addrtop
= (tbi
? 55 : 63);
13045 if (extract64(address
, pamax
, addrtop
- pamax
+ 1) != 0) {
13046 fi
->type
= ARMFault_AddressSize
;
13048 fi
->stage2
= false;
13053 * When TBI is disabled, we've just validated that all of the
13054 * bits above PAMax are zero, so logically we only need to
13055 * clear the top byte for TBI. But it's clearer to follow
13056 * the pseudocode set of addrdesc.paddress.
13058 address
= extract64(address
, 0, 52);
13061 *phys_ptr
= address
;
13062 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
13063 *page_size
= TARGET_PAGE_SIZE
;
13065 /* Fill in cacheattr a-la AArch64.TranslateAddressS1Off. */
13066 hcr
= arm_hcr_el2_eff(env
);
13067 cacheattrs
->shareability
= 0;
13068 cacheattrs
->is_s2_format
= false;
13069 if (hcr
& HCR_DC
) {
13070 if (hcr
& HCR_DCT
) {
13071 memattr
= 0xf0; /* Tagged, Normal, WB, RWA */
13073 memattr
= 0xff; /* Normal, WB, RWA */
13075 } else if (access_type
== MMU_INST_FETCH
) {
13076 if (regime_sctlr(env
, mmu_idx
) & SCTLR_I
) {
13077 memattr
= 0xee; /* Normal, WT, RA, NT */
13079 memattr
= 0x44; /* Normal, NC, No */
13081 cacheattrs
->shareability
= 2; /* outer sharable */
13083 memattr
= 0x00; /* Device, nGnRnE */
13085 cacheattrs
->attrs
= memattr
;
13089 if (regime_using_lpae_format(env
, mmu_idx
)) {
13090 return get_phys_addr_lpae(env
, address
, access_type
, mmu_idx
, false,
13091 phys_ptr
, attrs
, prot
, page_size
,
13093 } else if (regime_sctlr(env
, mmu_idx
) & SCTLR_XP
) {
13094 return get_phys_addr_v6(env
, address
, access_type
, mmu_idx
,
13095 phys_ptr
, attrs
, prot
, page_size
, fi
);
13097 return get_phys_addr_v5(env
, address
, access_type
, mmu_idx
,
13098 phys_ptr
, prot
, page_size
, fi
);
13102 hwaddr
arm_cpu_get_phys_page_attrs_debug(CPUState
*cs
, vaddr addr
,
13105 ARMCPU
*cpu
= ARM_CPU(cs
);
13106 CPUARMState
*env
= &cpu
->env
;
13108 target_ulong page_size
;
13111 ARMMMUFaultInfo fi
= {};
13112 ARMMMUIdx mmu_idx
= arm_mmu_idx(env
);
13113 ARMCacheAttrs cacheattrs
= {};
13115 *attrs
= (MemTxAttrs
) {};
13117 ret
= get_phys_addr(env
, addr
, MMU_DATA_LOAD
, mmu_idx
, &phys_addr
,
13118 attrs
, &prot
, &page_size
, &fi
, &cacheattrs
);
13128 /* Note that signed overflow is undefined in C. The following routines are
13129 careful to use unsigned types where modulo arithmetic is required.
13130 Failure to do so _will_ break on newer gcc. */
13132 /* Signed saturating arithmetic. */
13134 /* Perform 16-bit signed saturating addition. */
13135 static inline uint16_t add16_sat(uint16_t a
, uint16_t b
)
13140 if (((res
^ a
) & 0x8000) && !((a
^ b
) & 0x8000)) {
13149 /* Perform 8-bit signed saturating addition. */
13150 static inline uint8_t add8_sat(uint8_t a
, uint8_t b
)
13155 if (((res
^ a
) & 0x80) && !((a
^ b
) & 0x80)) {
13164 /* Perform 16-bit signed saturating subtraction. */
13165 static inline uint16_t sub16_sat(uint16_t a
, uint16_t b
)
13170 if (((res
^ a
) & 0x8000) && ((a
^ b
) & 0x8000)) {
13179 /* Perform 8-bit signed saturating subtraction. */
13180 static inline uint8_t sub8_sat(uint8_t a
, uint8_t b
)
13185 if (((res
^ a
) & 0x80) && ((a
^ b
) & 0x80)) {
13194 #define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
13195 #define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
13196 #define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
13197 #define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
13200 #include "op_addsub.h"
13202 /* Unsigned saturating arithmetic. */
13203 static inline uint16_t add16_usat(uint16_t a
, uint16_t b
)
13212 static inline uint16_t sub16_usat(uint16_t a
, uint16_t b
)
13220 static inline uint8_t add8_usat(uint8_t a
, uint8_t b
)
13229 static inline uint8_t sub8_usat(uint8_t a
, uint8_t b
)
13237 #define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
13238 #define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
13239 #define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
13240 #define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
13243 #include "op_addsub.h"
13245 /* Signed modulo arithmetic. */
13246 #define SARITH16(a, b, n, op) do { \
13248 sum = (int32_t)(int16_t)(a) op (int32_t)(int16_t)(b); \
13249 RESULT(sum, n, 16); \
13251 ge |= 3 << (n * 2); \
13254 #define SARITH8(a, b, n, op) do { \
13256 sum = (int32_t)(int8_t)(a) op (int32_t)(int8_t)(b); \
13257 RESULT(sum, n, 8); \
13263 #define ADD16(a, b, n) SARITH16(a, b, n, +)
13264 #define SUB16(a, b, n) SARITH16(a, b, n, -)
13265 #define ADD8(a, b, n) SARITH8(a, b, n, +)
13266 #define SUB8(a, b, n) SARITH8(a, b, n, -)
13270 #include "op_addsub.h"
13272 /* Unsigned modulo arithmetic. */
13273 #define ADD16(a, b, n) do { \
13275 sum = (uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b); \
13276 RESULT(sum, n, 16); \
13277 if ((sum >> 16) == 1) \
13278 ge |= 3 << (n * 2); \
13281 #define ADD8(a, b, n) do { \
13283 sum = (uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b); \
13284 RESULT(sum, n, 8); \
13285 if ((sum >> 8) == 1) \
13289 #define SUB16(a, b, n) do { \
13291 sum = (uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b); \
13292 RESULT(sum, n, 16); \
13293 if ((sum >> 16) == 0) \
13294 ge |= 3 << (n * 2); \
13297 #define SUB8(a, b, n) do { \
13299 sum = (uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b); \
13300 RESULT(sum, n, 8); \
13301 if ((sum >> 8) == 0) \
13308 #include "op_addsub.h"
13310 /* Halved signed arithmetic. */
13311 #define ADD16(a, b, n) \
13312 RESULT(((int32_t)(int16_t)(a) + (int32_t)(int16_t)(b)) >> 1, n, 16)
13313 #define SUB16(a, b, n) \
13314 RESULT(((int32_t)(int16_t)(a) - (int32_t)(int16_t)(b)) >> 1, n, 16)
13315 #define ADD8(a, b, n) \
13316 RESULT(((int32_t)(int8_t)(a) + (int32_t)(int8_t)(b)) >> 1, n, 8)
13317 #define SUB8(a, b, n) \
13318 RESULT(((int32_t)(int8_t)(a) - (int32_t)(int8_t)(b)) >> 1, n, 8)
13321 #include "op_addsub.h"
13323 /* Halved unsigned arithmetic. */
13324 #define ADD16(a, b, n) \
13325 RESULT(((uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b)) >> 1, n, 16)
13326 #define SUB16(a, b, n) \
13327 RESULT(((uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b)) >> 1, n, 16)
13328 #define ADD8(a, b, n) \
13329 RESULT(((uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b)) >> 1, n, 8)
13330 #define SUB8(a, b, n) \
13331 RESULT(((uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b)) >> 1, n, 8)
13334 #include "op_addsub.h"
13336 static inline uint8_t do_usad(uint8_t a
, uint8_t b
)
13344 /* Unsigned sum of absolute byte differences. */
13345 uint32_t HELPER(usad8
)(uint32_t a
, uint32_t b
)
13348 sum
= do_usad(a
, b
);
13349 sum
+= do_usad(a
>> 8, b
>> 8);
13350 sum
+= do_usad(a
>> 16, b
>> 16);
13351 sum
+= do_usad(a
>> 24, b
>> 24);
13355 /* For ARMv6 SEL instruction. */
13356 uint32_t HELPER(sel_flags
)(uint32_t flags
, uint32_t a
, uint32_t b
)
13368 mask
|= 0xff000000;
13369 return (a
& mask
) | (b
& ~mask
);
13373 * The upper bytes of val (above the number specified by 'bytes') must have
13374 * been zeroed out by the caller.
13376 uint32_t HELPER(crc32
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
13380 stl_le_p(buf
, val
);
13382 /* zlib crc32 converts the accumulator and output to one's complement. */
13383 return crc32(acc
^ 0xffffffff, buf
, bytes
) ^ 0xffffffff;
13386 uint32_t HELPER(crc32c
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
13390 stl_le_p(buf
, val
);
13392 /* Linux crc32c converts the output to one's complement. */
13393 return crc32c(acc
, buf
, bytes
) ^ 0xffffffff;
13396 /* Return the exception level to which FP-disabled exceptions should
13397 * be taken, or 0 if FP is enabled.
13399 int fp_exception_el(CPUARMState
*env
, int cur_el
)
13401 #ifndef CONFIG_USER_ONLY
13404 /* CPACR and the CPTR registers don't exist before v6, so FP is
13405 * always accessible
13407 if (!arm_feature(env
, ARM_FEATURE_V6
)) {
13411 if (arm_feature(env
, ARM_FEATURE_M
)) {
13412 /* CPACR can cause a NOCP UsageFault taken to current security state */
13413 if (!v7m_cpacr_pass(env
, env
->v7m
.secure
, cur_el
!= 0)) {
13417 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
) && !env
->v7m
.secure
) {
13418 if (!extract32(env
->v7m
.nsacr
, 10, 1)) {
13419 /* FP insns cause a NOCP UsageFault taken to Secure */
13427 hcr_el2
= arm_hcr_el2_eff(env
);
13429 /* The CPACR controls traps to EL1, or PL1 if we're 32 bit:
13430 * 0, 2 : trap EL0 and EL1/PL1 accesses
13431 * 1 : trap only EL0 accesses
13432 * 3 : trap no accesses
13433 * This register is ignored if E2H+TGE are both set.
13435 if ((hcr_el2
& (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
13436 int fpen
= FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, FPEN
);
13441 if (cur_el
== 0 || cur_el
== 1) {
13442 /* Trap to PL1, which might be EL1 or EL3 */
13443 if (arm_is_secure(env
) && !arm_el_is_aa64(env
, 3)) {
13448 if (cur_el
== 3 && !is_a64(env
)) {
13449 /* Secure PL1 running at EL3 */
13464 * The NSACR allows A-profile AArch32 EL3 and M-profile secure mode
13465 * to control non-secure access to the FPU. It doesn't have any
13466 * effect if EL3 is AArch64 or if EL3 doesn't exist at all.
13468 if ((arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
13469 cur_el
<= 2 && !arm_is_secure_below_el3(env
))) {
13470 if (!extract32(env
->cp15
.nsacr
, 10, 1)) {
13471 /* FP insns act as UNDEF */
13472 return cur_el
== 2 ? 2 : 1;
13477 * CPTR_EL2 is present in v7VE or v8, and changes format
13478 * with HCR_EL2.E2H (regardless of TGE).
13481 if (hcr_el2
& HCR_E2H
) {
13482 switch (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, FPEN
)) {
13484 if (cur_el
!= 0 || !(hcr_el2
& HCR_TGE
)) {
13492 } else if (arm_is_el2_enabled(env
)) {
13493 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TFP
)) {
13499 /* CPTR_EL3 : present in v8 */
13500 if (FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TFP
)) {
13501 /* Trap all FP ops to EL3 */
13508 /* Return the exception level we're running at if this is our mmu_idx */
13509 int arm_mmu_idx_to_el(ARMMMUIdx mmu_idx
)
13511 if (mmu_idx
& ARM_MMU_IDX_M
) {
13512 return mmu_idx
& ARM_MMU_IDX_M_PRIV
;
13516 case ARMMMUIdx_E10_0
:
13517 case ARMMMUIdx_E20_0
:
13518 case ARMMMUIdx_SE10_0
:
13519 case ARMMMUIdx_SE20_0
:
13521 case ARMMMUIdx_E10_1
:
13522 case ARMMMUIdx_E10_1_PAN
:
13523 case ARMMMUIdx_SE10_1
:
13524 case ARMMMUIdx_SE10_1_PAN
:
13527 case ARMMMUIdx_E20_2
:
13528 case ARMMMUIdx_E20_2_PAN
:
13529 case ARMMMUIdx_SE2
:
13530 case ARMMMUIdx_SE20_2
:
13531 case ARMMMUIdx_SE20_2_PAN
:
13533 case ARMMMUIdx_SE3
:
13536 g_assert_not_reached();
13541 ARMMMUIdx
arm_v7m_mmu_idx_for_secstate(CPUARMState
*env
, bool secstate
)
13543 g_assert_not_reached();
13547 ARMMMUIdx
arm_mmu_idx_el(CPUARMState
*env
, int el
)
13552 if (arm_feature(env
, ARM_FEATURE_M
)) {
13553 return arm_v7m_mmu_idx_for_secstate(env
, env
->v7m
.secure
);
13556 /* See ARM pseudo-function ELIsInHost. */
13559 hcr
= arm_hcr_el2_eff(env
);
13560 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
13561 idx
= ARMMMUIdx_E20_0
;
13563 idx
= ARMMMUIdx_E10_0
;
13567 if (env
->pstate
& PSTATE_PAN
) {
13568 idx
= ARMMMUIdx_E10_1_PAN
;
13570 idx
= ARMMMUIdx_E10_1
;
13574 /* Note that TGE does not apply at EL2. */
13575 if (arm_hcr_el2_eff(env
) & HCR_E2H
) {
13576 if (env
->pstate
& PSTATE_PAN
) {
13577 idx
= ARMMMUIdx_E20_2_PAN
;
13579 idx
= ARMMMUIdx_E20_2
;
13582 idx
= ARMMMUIdx_E2
;
13586 return ARMMMUIdx_SE3
;
13588 g_assert_not_reached();
13591 if (arm_is_secure_below_el3(env
)) {
13592 idx
&= ~ARM_MMU_IDX_A_NS
;
13598 ARMMMUIdx
arm_mmu_idx(CPUARMState
*env
)
13600 return arm_mmu_idx_el(env
, arm_current_el(env
));
13603 #ifndef CONFIG_USER_ONLY
13604 ARMMMUIdx
arm_stage1_mmu_idx(CPUARMState
*env
)
13606 return stage_1_mmu_idx(arm_mmu_idx(env
));
13610 static CPUARMTBFlags
rebuild_hflags_common(CPUARMState
*env
, int fp_el
,
13612 CPUARMTBFlags flags
)
13614 DP_TBFLAG_ANY(flags
, FPEXC_EL
, fp_el
);
13615 DP_TBFLAG_ANY(flags
, MMUIDX
, arm_to_core_mmu_idx(mmu_idx
));
13617 if (arm_singlestep_active(env
)) {
13618 DP_TBFLAG_ANY(flags
, SS_ACTIVE
, 1);
13623 static CPUARMTBFlags
rebuild_hflags_common_32(CPUARMState
*env
, int fp_el
,
13625 CPUARMTBFlags flags
)
13627 bool sctlr_b
= arm_sctlr_b(env
);
13630 DP_TBFLAG_A32(flags
, SCTLR__B
, 1);
13632 if (arm_cpu_data_is_big_endian_a32(env
, sctlr_b
)) {
13633 DP_TBFLAG_ANY(flags
, BE_DATA
, 1);
13635 DP_TBFLAG_A32(flags
, NS
, !access_secure_reg(env
));
13637 return rebuild_hflags_common(env
, fp_el
, mmu_idx
, flags
);
13640 static CPUARMTBFlags
rebuild_hflags_m32(CPUARMState
*env
, int fp_el
,
13643 CPUARMTBFlags flags
= {};
13644 uint32_t ccr
= env
->v7m
.ccr
[env
->v7m
.secure
];
13646 /* Without HaveMainExt, CCR.UNALIGN_TRP is RES1. */
13647 if (ccr
& R_V7M_CCR_UNALIGN_TRP_MASK
) {
13648 DP_TBFLAG_ANY(flags
, ALIGN_MEM
, 1);
13651 if (arm_v7m_is_handler_mode(env
)) {
13652 DP_TBFLAG_M32(flags
, HANDLER
, 1);
13656 * v8M always applies stack limit checks unless CCR.STKOFHFNMIGN
13657 * is suppressing them because the requested execution priority
13660 if (arm_feature(env
, ARM_FEATURE_V8
) &&
13661 !((mmu_idx
& ARM_MMU_IDX_M_NEGPRI
) &&
13662 (ccr
& R_V7M_CCR_STKOFHFNMIGN_MASK
))) {
13663 DP_TBFLAG_M32(flags
, STACKCHECK
, 1);
13666 return rebuild_hflags_common_32(env
, fp_el
, mmu_idx
, flags
);
13669 static CPUARMTBFlags
rebuild_hflags_aprofile(CPUARMState
*env
)
13671 CPUARMTBFlags flags
= {};
13673 DP_TBFLAG_ANY(flags
, DEBUG_TARGET_EL
, arm_debug_target_el(env
));
13677 static CPUARMTBFlags
rebuild_hflags_a32(CPUARMState
*env
, int fp_el
,
13680 CPUARMTBFlags flags
= rebuild_hflags_aprofile(env
);
13681 int el
= arm_current_el(env
);
13683 if (arm_sctlr(env
, el
) & SCTLR_A
) {
13684 DP_TBFLAG_ANY(flags
, ALIGN_MEM
, 1);
13687 if (arm_el_is_aa64(env
, 1)) {
13688 DP_TBFLAG_A32(flags
, VFPEN
, 1);
13691 if (el
< 2 && env
->cp15
.hstr_el2
&&
13692 (arm_hcr_el2_eff(env
) & (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
13693 DP_TBFLAG_A32(flags
, HSTR_ACTIVE
, 1);
13696 if (env
->uncached_cpsr
& CPSR_IL
) {
13697 DP_TBFLAG_ANY(flags
, PSTATE__IL
, 1);
13700 return rebuild_hflags_common_32(env
, fp_el
, mmu_idx
, flags
);
13703 static CPUARMTBFlags
rebuild_hflags_a64(CPUARMState
*env
, int el
, int fp_el
,
13706 CPUARMTBFlags flags
= rebuild_hflags_aprofile(env
);
13707 ARMMMUIdx stage1
= stage_1_mmu_idx(mmu_idx
);
13708 uint64_t tcr
= regime_tcr(env
, mmu_idx
)->raw_tcr
;
13712 DP_TBFLAG_ANY(flags
, AARCH64_STATE
, 1);
13714 /* Get control bits for tagged addresses. */
13715 tbid
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
13716 tbii
= tbid
& ~aa64_va_parameter_tbid(tcr
, mmu_idx
);
13718 DP_TBFLAG_A64(flags
, TBII
, tbii
);
13719 DP_TBFLAG_A64(flags
, TBID
, tbid
);
13721 if (cpu_isar_feature(aa64_sve
, env_archcpu(env
))) {
13722 int sve_el
= sve_exception_el(env
, el
);
13726 * If SVE is disabled, but FP is enabled,
13727 * then the effective len is 0.
13729 if (sve_el
!= 0 && fp_el
== 0) {
13732 zcr_len
= sve_zcr_len_for_el(env
, el
);
13734 DP_TBFLAG_A64(flags
, SVEEXC_EL
, sve_el
);
13735 DP_TBFLAG_A64(flags
, ZCR_LEN
, zcr_len
);
13738 sctlr
= regime_sctlr(env
, stage1
);
13740 if (sctlr
& SCTLR_A
) {
13741 DP_TBFLAG_ANY(flags
, ALIGN_MEM
, 1);
13744 if (arm_cpu_data_is_big_endian_a64(el
, sctlr
)) {
13745 DP_TBFLAG_ANY(flags
, BE_DATA
, 1);
13748 if (cpu_isar_feature(aa64_pauth
, env_archcpu(env
))) {
13750 * In order to save space in flags, we record only whether
13751 * pauth is "inactive", meaning all insns are implemented as
13752 * a nop, or "active" when some action must be performed.
13753 * The decision of which action to take is left to a helper.
13755 if (sctlr
& (SCTLR_EnIA
| SCTLR_EnIB
| SCTLR_EnDA
| SCTLR_EnDB
)) {
13756 DP_TBFLAG_A64(flags
, PAUTH_ACTIVE
, 1);
13760 if (cpu_isar_feature(aa64_bti
, env_archcpu(env
))) {
13761 /* Note that SCTLR_EL[23].BT == SCTLR_BT1. */
13762 if (sctlr
& (el
== 0 ? SCTLR_BT0
: SCTLR_BT1
)) {
13763 DP_TBFLAG_A64(flags
, BT
, 1);
13767 /* Compute the condition for using AccType_UNPRIV for LDTR et al. */
13768 if (!(env
->pstate
& PSTATE_UAO
)) {
13770 case ARMMMUIdx_E10_1
:
13771 case ARMMMUIdx_E10_1_PAN
:
13772 case ARMMMUIdx_SE10_1
:
13773 case ARMMMUIdx_SE10_1_PAN
:
13774 /* TODO: ARMv8.3-NV */
13775 DP_TBFLAG_A64(flags
, UNPRIV
, 1);
13777 case ARMMMUIdx_E20_2
:
13778 case ARMMMUIdx_E20_2_PAN
:
13779 case ARMMMUIdx_SE20_2
:
13780 case ARMMMUIdx_SE20_2_PAN
:
13782 * Note that EL20_2 is gated by HCR_EL2.E2H == 1, but EL20_0 is
13783 * gated by HCR_EL2.<E2H,TGE> == '11', and so is LDTR.
13785 if (env
->cp15
.hcr_el2
& HCR_TGE
) {
13786 DP_TBFLAG_A64(flags
, UNPRIV
, 1);
13794 if (env
->pstate
& PSTATE_IL
) {
13795 DP_TBFLAG_ANY(flags
, PSTATE__IL
, 1);
13798 if (cpu_isar_feature(aa64_mte
, env_archcpu(env
))) {
13800 * Set MTE_ACTIVE if any access may be Checked, and leave clear
13801 * if all accesses must be Unchecked:
13802 * 1) If no TBI, then there are no tags in the address to check,
13803 * 2) If Tag Check Override, then all accesses are Unchecked,
13804 * 3) If Tag Check Fail == 0, then Checked access have no effect,
13805 * 4) If no Allocation Tag Access, then all accesses are Unchecked.
13807 if (allocation_tag_access_enabled(env
, el
, sctlr
)) {
13808 DP_TBFLAG_A64(flags
, ATA
, 1);
13810 && !(env
->pstate
& PSTATE_TCO
)
13811 && (sctlr
& (el
== 0 ? SCTLR_TCF0
: SCTLR_TCF
))) {
13812 DP_TBFLAG_A64(flags
, MTE_ACTIVE
, 1);
13815 /* And again for unprivileged accesses, if required. */
13816 if (EX_TBFLAG_A64(flags
, UNPRIV
)
13818 && !(env
->pstate
& PSTATE_TCO
)
13819 && (sctlr
& SCTLR_TCF0
)
13820 && allocation_tag_access_enabled(env
, 0, sctlr
)) {
13821 DP_TBFLAG_A64(flags
, MTE0_ACTIVE
, 1);
13823 /* Cache TCMA as well as TBI. */
13824 DP_TBFLAG_A64(flags
, TCMA
, aa64_va_parameter_tcma(tcr
, mmu_idx
));
13827 return rebuild_hflags_common(env
, fp_el
, mmu_idx
, flags
);
13830 static CPUARMTBFlags
rebuild_hflags_internal(CPUARMState
*env
)
13832 int el
= arm_current_el(env
);
13833 int fp_el
= fp_exception_el(env
, el
);
13834 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13837 return rebuild_hflags_a64(env
, el
, fp_el
, mmu_idx
);
13838 } else if (arm_feature(env
, ARM_FEATURE_M
)) {
13839 return rebuild_hflags_m32(env
, fp_el
, mmu_idx
);
13841 return rebuild_hflags_a32(env
, fp_el
, mmu_idx
);
13845 void arm_rebuild_hflags(CPUARMState
*env
)
13847 env
->hflags
= rebuild_hflags_internal(env
);
13851 * If we have triggered a EL state change we can't rely on the
13852 * translator having passed it to us, we need to recompute.
13854 void HELPER(rebuild_hflags_m32_newel
)(CPUARMState
*env
)
13856 int el
= arm_current_el(env
);
13857 int fp_el
= fp_exception_el(env
, el
);
13858 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13860 env
->hflags
= rebuild_hflags_m32(env
, fp_el
, mmu_idx
);
13863 void HELPER(rebuild_hflags_m32
)(CPUARMState
*env
, int el
)
13865 int fp_el
= fp_exception_el(env
, el
);
13866 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13868 env
->hflags
= rebuild_hflags_m32(env
, fp_el
, mmu_idx
);
13872 * If we have triggered a EL state change we can't rely on the
13873 * translator having passed it to us, we need to recompute.
13875 void HELPER(rebuild_hflags_a32_newel
)(CPUARMState
*env
)
13877 int el
= arm_current_el(env
);
13878 int fp_el
= fp_exception_el(env
, el
);
13879 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13880 env
->hflags
= rebuild_hflags_a32(env
, fp_el
, mmu_idx
);
13883 void HELPER(rebuild_hflags_a32
)(CPUARMState
*env
, int el
)
13885 int fp_el
= fp_exception_el(env
, el
);
13886 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13888 env
->hflags
= rebuild_hflags_a32(env
, fp_el
, mmu_idx
);
13891 void HELPER(rebuild_hflags_a64
)(CPUARMState
*env
, int el
)
13893 int fp_el
= fp_exception_el(env
, el
);
13894 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
13896 env
->hflags
= rebuild_hflags_a64(env
, el
, fp_el
, mmu_idx
);
13899 static inline void assert_hflags_rebuild_correctly(CPUARMState
*env
)
13901 #ifdef CONFIG_DEBUG_TCG
13902 CPUARMTBFlags c
= env
->hflags
;
13903 CPUARMTBFlags r
= rebuild_hflags_internal(env
);
13905 if (unlikely(c
.flags
!= r
.flags
|| c
.flags2
!= r
.flags2
)) {
13906 fprintf(stderr
, "TCG hflags mismatch "
13907 "(current:(0x%08x,0x" TARGET_FMT_lx
")"
13908 " rebuilt:(0x%08x,0x" TARGET_FMT_lx
")\n",
13909 c
.flags
, c
.flags2
, r
.flags
, r
.flags2
);
13915 static bool mve_no_pred(CPUARMState
*env
)
13918 * Return true if there is definitely no predication of MVE
13919 * instructions by VPR or LTPSIZE. (Returning false even if there
13920 * isn't any predication is OK; generated code will just be
13922 * If the CPU does not implement MVE then this TB flag is always 0.
13924 * NOTE: if you change this logic, the "recalculate s->mve_no_pred"
13925 * logic in gen_update_fp_context() needs to be updated to match.
13927 * We do not include the effect of the ECI bits here -- they are
13928 * tracked in other TB flags. This simplifies the logic for
13929 * "when did we emit code that changes the MVE_NO_PRED TB flag
13930 * and thus need to end the TB?".
13932 if (cpu_isar_feature(aa32_mve
, env_archcpu(env
))) {
13935 if (env
->v7m
.vpr
) {
13938 if (env
->v7m
.ltpsize
< 4) {
13944 void cpu_get_tb_cpu_state(CPUARMState
*env
, target_ulong
*pc
,
13945 target_ulong
*cs_base
, uint32_t *pflags
)
13947 CPUARMTBFlags flags
;
13949 assert_hflags_rebuild_correctly(env
);
13950 flags
= env
->hflags
;
13952 if (EX_TBFLAG_ANY(flags
, AARCH64_STATE
)) {
13954 if (cpu_isar_feature(aa64_bti
, env_archcpu(env
))) {
13955 DP_TBFLAG_A64(flags
, BTYPE
, env
->btype
);
13958 *pc
= env
->regs
[15];
13960 if (arm_feature(env
, ARM_FEATURE_M
)) {
13961 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
) &&
13962 FIELD_EX32(env
->v7m
.fpccr
[M_REG_S
], V7M_FPCCR
, S
)
13963 != env
->v7m
.secure
) {
13964 DP_TBFLAG_M32(flags
, FPCCR_S_WRONG
, 1);
13967 if ((env
->v7m
.fpccr
[env
->v7m
.secure
] & R_V7M_FPCCR_ASPEN_MASK
) &&
13968 (!(env
->v7m
.control
[M_REG_S
] & R_V7M_CONTROL_FPCA_MASK
) ||
13969 (env
->v7m
.secure
&&
13970 !(env
->v7m
.control
[M_REG_S
] & R_V7M_CONTROL_SFPA_MASK
)))) {
13972 * ASPEN is set, but FPCA/SFPA indicate that there is no
13973 * active FP context; we must create a new FP context before
13974 * executing any FP insn.
13976 DP_TBFLAG_M32(flags
, NEW_FP_CTXT_NEEDED
, 1);
13979 bool is_secure
= env
->v7m
.fpccr
[M_REG_S
] & R_V7M_FPCCR_S_MASK
;
13980 if (env
->v7m
.fpccr
[is_secure
] & R_V7M_FPCCR_LSPACT_MASK
) {
13981 DP_TBFLAG_M32(flags
, LSPACT
, 1);
13984 if (mve_no_pred(env
)) {
13985 DP_TBFLAG_M32(flags
, MVE_NO_PRED
, 1);
13989 * Note that XSCALE_CPAR shares bits with VECSTRIDE.
13990 * Note that VECLEN+VECSTRIDE are RES0 for M-profile.
13992 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
13993 DP_TBFLAG_A32(flags
, XSCALE_CPAR
, env
->cp15
.c15_cpar
);
13995 DP_TBFLAG_A32(flags
, VECLEN
, env
->vfp
.vec_len
);
13996 DP_TBFLAG_A32(flags
, VECSTRIDE
, env
->vfp
.vec_stride
);
13998 if (env
->vfp
.xregs
[ARM_VFP_FPEXC
] & (1 << 30)) {
13999 DP_TBFLAG_A32(flags
, VFPEN
, 1);
14003 DP_TBFLAG_AM32(flags
, THUMB
, env
->thumb
);
14004 DP_TBFLAG_AM32(flags
, CONDEXEC
, env
->condexec_bits
);
14008 * The SS_ACTIVE and PSTATE_SS bits correspond to the state machine
14009 * states defined in the ARM ARM for software singlestep:
14010 * SS_ACTIVE PSTATE.SS State
14011 * 0 x Inactive (the TB flag for SS is always 0)
14012 * 1 0 Active-pending
14013 * 1 1 Active-not-pending
14014 * SS_ACTIVE is set in hflags; PSTATE__SS is computed every TB.
14016 if (EX_TBFLAG_ANY(flags
, SS_ACTIVE
) && (env
->pstate
& PSTATE_SS
)) {
14017 DP_TBFLAG_ANY(flags
, PSTATE__SS
, 1);
14020 *pflags
= flags
.flags
;
14021 *cs_base
= flags
.flags2
;
14024 #ifdef TARGET_AARCH64
14026 * The manual says that when SVE is enabled and VQ is widened the
14027 * implementation is allowed to zero the previously inaccessible
14028 * portion of the registers. The corollary to that is that when
14029 * SVE is enabled and VQ is narrowed we are also allowed to zero
14030 * the now inaccessible portion of the registers.
14032 * The intent of this is that no predicate bit beyond VQ is ever set.
14033 * Which means that some operations on predicate registers themselves
14034 * may operate on full uint64_t or even unrolled across the maximum
14035 * uint64_t[4]. Performing 4 bits of host arithmetic unconditionally
14036 * may well be cheaper than conditionals to restrict the operation
14037 * to the relevant portion of a uint16_t[16].
14039 void aarch64_sve_narrow_vq(CPUARMState
*env
, unsigned vq
)
14044 assert(vq
>= 1 && vq
<= ARM_MAX_VQ
);
14045 assert(vq
<= env_archcpu(env
)->sve_max_vq
);
14047 /* Zap the high bits of the zregs. */
14048 for (i
= 0; i
< 32; i
++) {
14049 memset(&env
->vfp
.zregs
[i
].d
[2 * vq
], 0, 16 * (ARM_MAX_VQ
- vq
));
14052 /* Zap the high bits of the pregs and ffr. */
14055 pmask
= ~(-1ULL << (16 * (vq
& 3)));
14057 for (j
= vq
/ 4; j
< ARM_MAX_VQ
/ 4; j
++) {
14058 for (i
= 0; i
< 17; ++i
) {
14059 env
->vfp
.pregs
[i
].p
[j
] &= pmask
;
14066 * Notice a change in SVE vector size when changing EL.
14068 void aarch64_sve_change_el(CPUARMState
*env
, int old_el
,
14069 int new_el
, bool el0_a64
)
14071 ARMCPU
*cpu
= env_archcpu(env
);
14072 int old_len
, new_len
;
14073 bool old_a64
, new_a64
;
14075 /* Nothing to do if no SVE. */
14076 if (!cpu_isar_feature(aa64_sve
, cpu
)) {
14080 /* Nothing to do if FP is disabled in either EL. */
14081 if (fp_exception_el(env
, old_el
) || fp_exception_el(env
, new_el
)) {
14086 * DDI0584A.d sec 3.2: "If SVE instructions are disabled or trapped
14087 * at ELx, or not available because the EL is in AArch32 state, then
14088 * for all purposes other than a direct read, the ZCR_ELx.LEN field
14089 * has an effective value of 0".
14091 * Consider EL2 (aa64, vq=4) -> EL0 (aa32) -> EL1 (aa64, vq=0).
14092 * If we ignore aa32 state, we would fail to see the vq4->vq0 transition
14093 * from EL2->EL1. Thus we go ahead and narrow when entering aa32 so that
14094 * we already have the correct register contents when encountering the
14095 * vq0->vq0 transition between EL0->EL1.
14097 old_a64
= old_el
? arm_el_is_aa64(env
, old_el
) : el0_a64
;
14098 old_len
= (old_a64
&& !sve_exception_el(env
, old_el
)
14099 ? sve_zcr_len_for_el(env
, old_el
) : 0);
14100 new_a64
= new_el
? arm_el_is_aa64(env
, new_el
) : el0_a64
;
14101 new_len
= (new_a64
&& !sve_exception_el(env
, new_el
)
14102 ? sve_zcr_len_for_el(env
, new_el
) : 0);
14104 /* When changing vector length, clear inaccessible state. */
14105 if (new_len
< old_len
) {
14106 aarch64_sve_narrow_vq(env
, new_len
+ 1);