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"
13 #include "internals.h"
14 #include "cpu-features.h"
15 #include "exec/helper-proto.h"
16 #include "qemu/main-loop.h"
17 #include "qemu/timer.h"
18 #include "qemu/bitops.h"
19 #include "qemu/crc32c.h"
20 #include "qemu/qemu-print.h"
21 #include "exec/exec-all.h"
22 #include <zlib.h> /* For crc32 */
24 #include "sysemu/cpu-timers.h"
25 #include "sysemu/kvm.h"
26 #include "sysemu/tcg.h"
27 #include "qapi/error.h"
28 #include "qemu/guest-random.h"
30 #include "semihosting/common-semi.h"
33 #include "target/arm/gtimer.h"
35 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */
37 static void switch_mode(CPUARMState
*env
, int mode
);
39 static uint64_t raw_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
41 assert(ri
->fieldoffset
);
42 if (cpreg_field_is_64bit(ri
)) {
43 return CPREG_FIELD64(env
, ri
);
45 return CPREG_FIELD32(env
, ri
);
49 void raw_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
51 assert(ri
->fieldoffset
);
52 if (cpreg_field_is_64bit(ri
)) {
53 CPREG_FIELD64(env
, ri
) = value
;
55 CPREG_FIELD32(env
, ri
) = value
;
59 static void *raw_ptr(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
61 return (char *)env
+ ri
->fieldoffset
;
64 uint64_t read_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
66 /* Raw read of a coprocessor register (as needed for migration, etc). */
67 if (ri
->type
& ARM_CP_CONST
) {
68 return ri
->resetvalue
;
69 } else if (ri
->raw_readfn
) {
70 return ri
->raw_readfn(env
, ri
);
71 } else if (ri
->readfn
) {
72 return ri
->readfn(env
, ri
);
74 return raw_read(env
, ri
);
78 static void write_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
82 * Raw write of a coprocessor register (as needed for migration, etc).
83 * Note that constant registers are treated as write-ignored; the
84 * caller should check for success by whether a readback gives the
87 if (ri
->type
& ARM_CP_CONST
) {
89 } else if (ri
->raw_writefn
) {
90 ri
->raw_writefn(env
, ri
, v
);
91 } else if (ri
->writefn
) {
92 ri
->writefn(env
, ri
, v
);
94 raw_write(env
, ri
, v
);
98 static bool raw_accessors_invalid(const ARMCPRegInfo
*ri
)
101 * Return true if the regdef would cause an assertion if you called
102 * read_raw_cp_reg() or write_raw_cp_reg() on it (ie if it is a
103 * program bug for it not to have the NO_RAW flag).
104 * NB that returning false here doesn't necessarily mean that calling
105 * read/write_raw_cp_reg() is safe, because we can't distinguish "has
106 * read/write access functions which are safe for raw use" from "has
107 * read/write access functions which have side effects but has forgotten
108 * to provide raw access functions".
109 * The tests here line up with the conditions in read/write_raw_cp_reg()
110 * and assertions in raw_read()/raw_write().
112 if ((ri
->type
& ARM_CP_CONST
) ||
114 ((ri
->raw_writefn
|| ri
->writefn
) && (ri
->raw_readfn
|| ri
->readfn
))) {
120 bool write_cpustate_to_list(ARMCPU
*cpu
, bool kvm_sync
)
122 /* Write the coprocessor state from cpu->env to the (index,value) list. */
126 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
127 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
128 const ARMCPRegInfo
*ri
;
131 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
136 if (ri
->type
& ARM_CP_NO_RAW
) {
140 newval
= read_raw_cp_reg(&cpu
->env
, ri
);
143 * Only sync if the previous list->cpustate sync succeeded.
144 * Rather than tracking the success/failure state for every
145 * item in the list, we just recheck "does the raw write we must
146 * have made in write_list_to_cpustate() read back OK" here.
148 uint64_t oldval
= cpu
->cpreg_values
[i
];
150 if (oldval
== newval
) {
154 write_raw_cp_reg(&cpu
->env
, ri
, oldval
);
155 if (read_raw_cp_reg(&cpu
->env
, ri
) != oldval
) {
159 write_raw_cp_reg(&cpu
->env
, ri
, newval
);
161 cpu
->cpreg_values
[i
] = newval
;
166 bool write_list_to_cpustate(ARMCPU
*cpu
)
171 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
172 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
173 uint64_t v
= cpu
->cpreg_values
[i
];
174 const ARMCPRegInfo
*ri
;
176 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
181 if (ri
->type
& ARM_CP_NO_RAW
) {
185 * Write value and confirm it reads back as written
186 * (to catch read-only registers and partially read-only
187 * registers where the incoming migration value doesn't match)
189 write_raw_cp_reg(&cpu
->env
, ri
, v
);
190 if (read_raw_cp_reg(&cpu
->env
, ri
) != v
) {
197 static void add_cpreg_to_list(gpointer key
, gpointer opaque
)
199 ARMCPU
*cpu
= opaque
;
200 uint32_t regidx
= (uintptr_t)key
;
201 const ARMCPRegInfo
*ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
203 if (!(ri
->type
& (ARM_CP_NO_RAW
| ARM_CP_ALIAS
))) {
204 cpu
->cpreg_indexes
[cpu
->cpreg_array_len
] = cpreg_to_kvm_id(regidx
);
205 /* The value array need not be initialized at this point */
206 cpu
->cpreg_array_len
++;
210 static void count_cpreg(gpointer key
, gpointer opaque
)
212 ARMCPU
*cpu
= opaque
;
213 const ARMCPRegInfo
*ri
;
215 ri
= g_hash_table_lookup(cpu
->cp_regs
, key
);
217 if (!(ri
->type
& (ARM_CP_NO_RAW
| ARM_CP_ALIAS
))) {
218 cpu
->cpreg_array_len
++;
222 static gint
cpreg_key_compare(gconstpointer a
, gconstpointer b
)
224 uint64_t aidx
= cpreg_to_kvm_id((uintptr_t)a
);
225 uint64_t bidx
= cpreg_to_kvm_id((uintptr_t)b
);
236 void init_cpreg_list(ARMCPU
*cpu
)
239 * Initialise the cpreg_tuples[] array based on the cp_regs hash.
240 * Note that we require cpreg_tuples[] to be sorted by key ID.
245 keys
= g_hash_table_get_keys(cpu
->cp_regs
);
246 keys
= g_list_sort(keys
, cpreg_key_compare
);
248 cpu
->cpreg_array_len
= 0;
250 g_list_foreach(keys
, count_cpreg
, cpu
);
252 arraylen
= cpu
->cpreg_array_len
;
253 cpu
->cpreg_indexes
= g_new(uint64_t, arraylen
);
254 cpu
->cpreg_values
= g_new(uint64_t, arraylen
);
255 cpu
->cpreg_vmstate_indexes
= g_new(uint64_t, arraylen
);
256 cpu
->cpreg_vmstate_values
= g_new(uint64_t, arraylen
);
257 cpu
->cpreg_vmstate_array_len
= cpu
->cpreg_array_len
;
258 cpu
->cpreg_array_len
= 0;
260 g_list_foreach(keys
, add_cpreg_to_list
, cpu
);
262 assert(cpu
->cpreg_array_len
== arraylen
);
267 static bool arm_pan_enabled(CPUARMState
*env
)
270 if ((arm_hcr_el2_eff(env
) & (HCR_NV
| HCR_NV1
)) == (HCR_NV
| HCR_NV1
)) {
273 return env
->pstate
& PSTATE_PAN
;
275 return env
->uncached_cpsr
& CPSR_PAN
;
280 * Some registers are not accessible from AArch32 EL3 if SCR.NS == 0.
282 static CPAccessResult
access_el3_aa32ns(CPUARMState
*env
,
283 const ARMCPRegInfo
*ri
,
286 if (!is_a64(env
) && arm_current_el(env
) == 3 &&
287 arm_is_secure_below_el3(env
)) {
288 return CP_ACCESS_TRAP_UNCATEGORIZED
;
294 * Some secure-only AArch32 registers trap to EL3 if used from
295 * Secure EL1 (but are just ordinary UNDEF in other non-EL3 contexts).
296 * Note that an access from Secure EL1 can only happen if EL3 is AArch64.
297 * We assume that the .access field is set to PL1_RW.
299 static CPAccessResult
access_trap_aa32s_el1(CPUARMState
*env
,
300 const ARMCPRegInfo
*ri
,
303 if (arm_current_el(env
) == 3) {
306 if (arm_is_secure_below_el3(env
)) {
307 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
308 return CP_ACCESS_TRAP_EL2
;
310 return CP_ACCESS_TRAP_EL3
;
312 /* This will be EL1 NS and EL2 NS, which just UNDEF */
313 return CP_ACCESS_TRAP_UNCATEGORIZED
;
317 * Check for traps to performance monitor registers, which are controlled
318 * by MDCR_EL2.TPM for EL2 and MDCR_EL3.TPM for EL3.
320 static CPAccessResult
access_tpm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
323 int el
= arm_current_el(env
);
324 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
326 if (el
< 2 && (mdcr_el2
& MDCR_TPM
)) {
327 return CP_ACCESS_TRAP_EL2
;
329 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
330 return CP_ACCESS_TRAP_EL3
;
335 /* Check for traps from EL1 due to HCR_EL2.TVM and HCR_EL2.TRVM. */
336 CPAccessResult
access_tvm_trvm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
339 if (arm_current_el(env
) == 1) {
340 uint64_t trap
= isread
? HCR_TRVM
: HCR_TVM
;
341 if (arm_hcr_el2_eff(env
) & trap
) {
342 return CP_ACCESS_TRAP_EL2
;
348 /* Check for traps from EL1 due to HCR_EL2.TSW. */
349 static CPAccessResult
access_tsw(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
352 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TSW
)) {
353 return CP_ACCESS_TRAP_EL2
;
358 /* Check for traps from EL1 due to HCR_EL2.TACR. */
359 static CPAccessResult
access_tacr(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
362 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TACR
)) {
363 return CP_ACCESS_TRAP_EL2
;
368 /* Check for traps from EL1 due to HCR_EL2.TTLB. */
369 static CPAccessResult
access_ttlb(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
372 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TTLB
)) {
373 return CP_ACCESS_TRAP_EL2
;
378 /* Check for traps from EL1 due to HCR_EL2.TTLB or TTLBIS. */
379 static CPAccessResult
access_ttlbis(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
382 if (arm_current_el(env
) == 1 &&
383 (arm_hcr_el2_eff(env
) & (HCR_TTLB
| HCR_TTLBIS
))) {
384 return CP_ACCESS_TRAP_EL2
;
389 #ifdef TARGET_AARCH64
390 /* Check for traps from EL1 due to HCR_EL2.TTLB or TTLBOS. */
391 static CPAccessResult
access_ttlbos(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
394 if (arm_current_el(env
) == 1 &&
395 (arm_hcr_el2_eff(env
) & (HCR_TTLB
| HCR_TTLBOS
))) {
396 return CP_ACCESS_TRAP_EL2
;
402 static void dacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
404 ARMCPU
*cpu
= env_archcpu(env
);
406 raw_write(env
, ri
, value
);
407 tlb_flush(CPU(cpu
)); /* Flush TLB as domain not tracked in TLB */
410 static void fcse_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
412 ARMCPU
*cpu
= env_archcpu(env
);
414 if (raw_read(env
, ri
) != value
) {
416 * Unlike real hardware the qemu TLB uses virtual addresses,
417 * not modified virtual addresses, so this causes a TLB flush.
420 raw_write(env
, ri
, value
);
424 static void contextidr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
427 ARMCPU
*cpu
= env_archcpu(env
);
429 if (raw_read(env
, ri
) != value
&& !arm_feature(env
, ARM_FEATURE_PMSA
)
430 && !extended_addresses_enabled(env
)) {
432 * For VMSA (when not using the LPAE long descriptor page table
433 * format) this register includes the ASID, so do a TLB flush.
434 * For PMSA it is purely a process ID and no action is needed.
438 raw_write(env
, ri
, value
);
441 static int alle1_tlbmask(CPUARMState
*env
)
444 * Note that the 'ALL' scope must invalidate both stage 1 and
445 * stage 2 translations, whereas most other scopes only invalidate
446 * stage 1 translations.
448 return (ARMMMUIdxBit_E10_1
|
449 ARMMMUIdxBit_E10_1_PAN
|
451 ARMMMUIdxBit_Stage2
|
452 ARMMMUIdxBit_Stage2_S
);
456 /* IS variants of TLB operations must affect all cores */
457 static void tlbiall_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
460 CPUState
*cs
= env_cpu(env
);
462 tlb_flush_all_cpus_synced(cs
);
465 static void tlbiasid_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
468 CPUState
*cs
= env_cpu(env
);
470 tlb_flush_all_cpus_synced(cs
);
473 static void tlbimva_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
476 CPUState
*cs
= env_cpu(env
);
478 tlb_flush_page_all_cpus_synced(cs
, value
& TARGET_PAGE_MASK
);
481 static void tlbimvaa_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
484 CPUState
*cs
= env_cpu(env
);
486 tlb_flush_page_all_cpus_synced(cs
, value
& TARGET_PAGE_MASK
);
490 * Non-IS variants of TLB operations are upgraded to
491 * IS versions if we are at EL1 and HCR_EL2.FB is effectively set to
492 * force broadcast of these operations.
494 static bool tlb_force_broadcast(CPUARMState
*env
)
496 return arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_FB
);
499 static void tlbiall_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
502 /* Invalidate all (TLBIALL) */
503 CPUState
*cs
= env_cpu(env
);
505 if (tlb_force_broadcast(env
)) {
506 tlb_flush_all_cpus_synced(cs
);
512 static void tlbimva_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
515 /* Invalidate single TLB entry by MVA and ASID (TLBIMVA) */
516 CPUState
*cs
= env_cpu(env
);
518 value
&= TARGET_PAGE_MASK
;
519 if (tlb_force_broadcast(env
)) {
520 tlb_flush_page_all_cpus_synced(cs
, value
);
522 tlb_flush_page(cs
, value
);
526 static void tlbiasid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
529 /* Invalidate by ASID (TLBIASID) */
530 CPUState
*cs
= env_cpu(env
);
532 if (tlb_force_broadcast(env
)) {
533 tlb_flush_all_cpus_synced(cs
);
539 static void tlbimvaa_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
542 /* Invalidate single entry by MVA, all ASIDs (TLBIMVAA) */
543 CPUState
*cs
= env_cpu(env
);
545 value
&= TARGET_PAGE_MASK
;
546 if (tlb_force_broadcast(env
)) {
547 tlb_flush_page_all_cpus_synced(cs
, value
);
549 tlb_flush_page(cs
, value
);
553 static void tlbiall_nsnh_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
556 CPUState
*cs
= env_cpu(env
);
558 tlb_flush_by_mmuidx(cs
, alle1_tlbmask(env
));
561 static void tlbiall_nsnh_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
564 CPUState
*cs
= env_cpu(env
);
566 tlb_flush_by_mmuidx_all_cpus_synced(cs
, alle1_tlbmask(env
));
570 static void tlbiall_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
573 CPUState
*cs
= env_cpu(env
);
575 tlb_flush_by_mmuidx(cs
, ARMMMUIdxBit_E2
);
578 static void tlbiall_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
581 CPUState
*cs
= env_cpu(env
);
583 tlb_flush_by_mmuidx_all_cpus_synced(cs
, ARMMMUIdxBit_E2
);
586 static void tlbimva_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
589 CPUState
*cs
= env_cpu(env
);
590 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
592 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_E2
);
595 static void tlbimva_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
598 CPUState
*cs
= env_cpu(env
);
599 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
601 tlb_flush_page_by_mmuidx_all_cpus_synced(cs
, pageaddr
,
605 static void tlbiipas2_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
608 CPUState
*cs
= env_cpu(env
);
609 uint64_t pageaddr
= (value
& MAKE_64BIT_MASK(0, 28)) << 12;
611 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_Stage2
);
614 static void tlbiipas2is_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
617 CPUState
*cs
= env_cpu(env
);
618 uint64_t pageaddr
= (value
& MAKE_64BIT_MASK(0, 28)) << 12;
620 tlb_flush_page_by_mmuidx_all_cpus_synced(cs
, pageaddr
, ARMMMUIdxBit_Stage2
);
623 static const ARMCPRegInfo cp_reginfo
[] = {
625 * Define the secure and non-secure FCSE identifier CP registers
626 * separately because there is no secure bank in V8 (no _EL3). This allows
627 * the secure register to be properly reset and migrated. There is also no
628 * v8 EL1 version of the register so the non-secure instance stands alone.
631 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
632 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_NS
,
633 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_ns
),
634 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
635 { .name
= "FCSEIDR_S",
636 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
637 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_S
,
638 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_s
),
639 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
641 * Define the secure and non-secure context identifier CP registers
642 * separately because there is no secure bank in V8 (no _EL3). This allows
643 * the secure register to be properly reset and migrated. In the
644 * non-secure case, the 32-bit register will have reset and migration
645 * disabled during registration as it is handled by the 64-bit instance.
647 { .name
= "CONTEXTIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
648 .opc0
= 3, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
649 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
650 .fgt
= FGT_CONTEXTIDR_EL1
,
651 .nv2_redirect_offset
= 0x108 | NV2_REDIR_NV1
,
652 .secure
= ARM_CP_SECSTATE_NS
,
653 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[1]),
654 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
655 { .name
= "CONTEXTIDR_S", .state
= ARM_CP_STATE_AA32
,
656 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
657 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
658 .secure
= ARM_CP_SECSTATE_S
,
659 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_s
),
660 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
663 static const ARMCPRegInfo not_v8_cp_reginfo
[] = {
665 * NB: Some of these registers exist in v8 but with more precise
666 * definitions that don't use CP_ANY wildcards (mostly in v8_cp_reginfo[]).
668 /* MMU Domain access control / MPU write buffer control */
670 .cp
= 15, .opc1
= CP_ANY
, .crn
= 3, .crm
= CP_ANY
, .opc2
= CP_ANY
,
671 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
672 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
673 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
674 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
676 * ARMv7 allocates a range of implementation defined TLB LOCKDOWN regs.
677 * For v6 and v5, these mappings are overly broad.
679 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 0,
680 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
681 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 1,
682 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
683 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 4,
684 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
685 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 8,
686 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
687 /* Cache maintenance ops; some of this space may be overridden later. */
688 { .name
= "CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
689 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
690 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
},
693 static const ARMCPRegInfo not_v6_cp_reginfo
[] = {
695 * Not all pre-v6 cores implemented this WFI, so this is slightly
698 { .name
= "WFI_v5", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= 2,
699 .access
= PL1_W
, .type
= ARM_CP_WFI
},
702 static const ARMCPRegInfo not_v7_cp_reginfo
[] = {
704 * Standard v6 WFI (also used in some pre-v6 cores); not in v7 (which
705 * is UNPREDICTABLE; we choose to NOP as most implementations do).
707 { .name
= "WFI_v6", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
708 .access
= PL1_W
, .type
= ARM_CP_WFI
},
710 * L1 cache lockdown. Not architectural in v6 and earlier but in practice
711 * implemented in 926, 946, 1026, 1136, 1176 and 11MPCore. StrongARM and
712 * OMAPCP will override this space.
714 { .name
= "DLOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 0,
715 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_data
),
717 { .name
= "ILOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 1,
718 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_insn
),
720 /* v6 doesn't have the cache ID registers but Linux reads them anyway */
721 { .name
= "DUMMY", .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= CP_ANY
,
722 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
725 * We don't implement pre-v7 debug but most CPUs had at least a DBGDIDR;
726 * implementing it as RAZ means the "debug architecture version" bits
727 * will read as a reserved value, which should cause Linux to not try
728 * to use the debug hardware.
730 { .name
= "DBGDIDR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 0,
731 .access
= PL0_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
733 * MMU TLB control. Note that the wildcarding means we cover not just
734 * the unified TLB ops but also the dside/iside/inner-shareable variants.
736 { .name
= "TLBIALL", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
737 .opc1
= CP_ANY
, .opc2
= 0, .access
= PL1_W
, .writefn
= tlbiall_write
,
738 .type
= ARM_CP_NO_RAW
},
739 { .name
= "TLBIMVA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
740 .opc1
= CP_ANY
, .opc2
= 1, .access
= PL1_W
, .writefn
= tlbimva_write
,
741 .type
= ARM_CP_NO_RAW
},
742 { .name
= "TLBIASID", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
743 .opc1
= CP_ANY
, .opc2
= 2, .access
= PL1_W
, .writefn
= tlbiasid_write
,
744 .type
= ARM_CP_NO_RAW
},
745 { .name
= "TLBIMVAA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
746 .opc1
= CP_ANY
, .opc2
= 3, .access
= PL1_W
, .writefn
= tlbimvaa_write
,
747 .type
= ARM_CP_NO_RAW
},
748 { .name
= "PRRR", .cp
= 15, .crn
= 10, .crm
= 2,
749 .opc1
= 0, .opc2
= 0, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
750 { .name
= "NMRR", .cp
= 15, .crn
= 10, .crm
= 2,
751 .opc1
= 0, .opc2
= 1, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
754 static void cpacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
759 /* In ARMv8 most bits of CPACR_EL1 are RES0. */
760 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
762 * ARMv7 defines bits for unimplemented coprocessors as RAZ/WI.
763 * ASEDIS [31] and D32DIS [30] are both UNK/SBZP without VFP.
764 * TRCDIS [28] is RAZ/WI since we do not implement a trace macrocell.
766 if (cpu_isar_feature(aa32_vfp_simd
, env_archcpu(env
))) {
767 /* VFP coprocessor: cp10 & cp11 [23:20] */
768 mask
|= R_CPACR_ASEDIS_MASK
|
769 R_CPACR_D32DIS_MASK
|
773 if (!arm_feature(env
, ARM_FEATURE_NEON
)) {
774 /* ASEDIS [31] bit is RAO/WI */
775 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
)
822 * Call cpacr_write() so that we reset with the correct RAO bits set
823 * for our CPU features.
825 cpacr_write(env
, ri
, 0);
828 static CPAccessResult
cpacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
831 if (arm_feature(env
, ARM_FEATURE_V8
)) {
832 /* Check if CPACR accesses are to be trapped to EL2 */
833 if (arm_current_el(env
) == 1 && arm_is_el2_enabled(env
) &&
834 FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TCPAC
)) {
835 return CP_ACCESS_TRAP_EL2
;
836 /* Check if CPACR accesses are to be trapped to EL3 */
837 } else if (arm_current_el(env
) < 3 &&
838 FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TCPAC
)) {
839 return CP_ACCESS_TRAP_EL3
;
846 static CPAccessResult
cptr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
849 /* Check if CPTR accesses are set to trap to EL3 */
850 if (arm_current_el(env
) == 2 &&
851 FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TCPAC
)) {
852 return CP_ACCESS_TRAP_EL3
;
858 static const ARMCPRegInfo v6_cp_reginfo
[] = {
859 /* prefetch by MVA in v6, NOP in v7 */
860 { .name
= "MVA_prefetch",
861 .cp
= 15, .crn
= 7, .crm
= 13, .opc1
= 0, .opc2
= 1,
862 .access
= PL1_W
, .type
= ARM_CP_NOP
},
864 * We need to break the TB after ISB to execute self-modifying code
865 * correctly and also to take any pending interrupts immediately.
866 * So use arm_cp_write_ignore() function instead of ARM_CP_NOP flag.
868 { .name
= "ISB", .cp
= 15, .crn
= 7, .crm
= 5, .opc1
= 0, .opc2
= 4,
869 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
, .writefn
= arm_cp_write_ignore
},
870 { .name
= "DSB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 4,
871 .access
= PL0_W
, .type
= ARM_CP_NOP
},
872 { .name
= "DMB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 5,
873 .access
= PL0_W
, .type
= ARM_CP_NOP
},
874 { .name
= "IFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 2,
875 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
876 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ifar_s
),
877 offsetof(CPUARMState
, cp15
.ifar_ns
) },
880 * Watchpoint Fault Address Register : should actually only be present
881 * for 1136, 1176, 11MPCore.
883 { .name
= "WFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 1,
884 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0, },
885 { .name
= "CPACR", .state
= ARM_CP_STATE_BOTH
, .opc0
= 3,
886 .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 2, .accessfn
= cpacr_access
,
887 .fgt
= FGT_CPACR_EL1
,
888 .nv2_redirect_offset
= 0x100 | NV2_REDIR_NV1
,
889 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.cpacr_el1
),
890 .resetfn
= cpacr_reset
, .writefn
= cpacr_write
, .readfn
= cpacr_read
},
893 typedef struct pm_event
{
894 uint16_t number
; /* PMEVTYPER.evtCount is 16 bits wide */
895 /* If the event is supported on this CPU (used to generate PMCEID[01]) */
896 bool (*supported
)(CPUARMState
*);
898 * Retrieve the current count of the underlying event. The programmed
899 * counters hold a difference from the return value from this function
901 uint64_t (*get_count
)(CPUARMState
*);
903 * Return how many nanoseconds it will take (at a minimum) for count events
904 * to occur. A negative value indicates the counter will never overflow, or
905 * that the counter has otherwise arranged for the overflow bit to be set
906 * and the PMU interrupt to be raised on overflow.
908 int64_t (*ns_per_count
)(uint64_t);
911 static bool event_always_supported(CPUARMState
*env
)
916 static uint64_t swinc_get_count(CPUARMState
*env
)
919 * SW_INCR events are written directly to the pmevcntr's by writes to
920 * PMSWINC, so there is no underlying count maintained by the PMU itself
925 static int64_t swinc_ns_per(uint64_t ignored
)
931 * Return the underlying cycle count for the PMU cycle counters. If we're in
932 * usermode, simply return 0.
934 static uint64_t cycles_get_count(CPUARMState
*env
)
936 #ifndef CONFIG_USER_ONLY
937 return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
938 ARM_CPU_FREQ
, NANOSECONDS_PER_SECOND
);
940 return cpu_get_host_ticks();
944 #ifndef CONFIG_USER_ONLY
945 static int64_t cycles_ns_per(uint64_t cycles
)
947 return (ARM_CPU_FREQ
/ NANOSECONDS_PER_SECOND
) * cycles
;
950 static bool instructions_supported(CPUARMState
*env
)
952 /* Precise instruction counting */
953 return icount_enabled() == ICOUNT_PRECISE
;
956 static uint64_t instructions_get_count(CPUARMState
*env
)
958 assert(icount_enabled() == ICOUNT_PRECISE
);
959 return (uint64_t)icount_get_raw();
962 static int64_t instructions_ns_per(uint64_t icount
)
964 assert(icount_enabled() == ICOUNT_PRECISE
);
965 return icount_to_ns((int64_t)icount
);
969 static bool pmuv3p1_events_supported(CPUARMState
*env
)
971 /* For events which are supported in any v8.1 PMU */
972 return cpu_isar_feature(any_pmuv3p1
, env_archcpu(env
));
975 static bool pmuv3p4_events_supported(CPUARMState
*env
)
977 /* For events which are supported in any v8.1 PMU */
978 return cpu_isar_feature(any_pmuv3p4
, env_archcpu(env
));
981 static uint64_t zero_event_get_count(CPUARMState
*env
)
983 /* For events which on QEMU never fire, so their count is always zero */
987 static int64_t zero_event_ns_per(uint64_t cycles
)
989 /* An event which never fires can never overflow */
993 static const pm_event pm_events
[] = {
994 { .number
= 0x000, /* SW_INCR */
995 .supported
= event_always_supported
,
996 .get_count
= swinc_get_count
,
997 .ns_per_count
= swinc_ns_per
,
999 #ifndef CONFIG_USER_ONLY
1000 { .number
= 0x008, /* INST_RETIRED, Instruction architecturally executed */
1001 .supported
= instructions_supported
,
1002 .get_count
= instructions_get_count
,
1003 .ns_per_count
= instructions_ns_per
,
1005 { .number
= 0x011, /* CPU_CYCLES, Cycle */
1006 .supported
= event_always_supported
,
1007 .get_count
= cycles_get_count
,
1008 .ns_per_count
= cycles_ns_per
,
1011 { .number
= 0x023, /* STALL_FRONTEND */
1012 .supported
= pmuv3p1_events_supported
,
1013 .get_count
= zero_event_get_count
,
1014 .ns_per_count
= zero_event_ns_per
,
1016 { .number
= 0x024, /* STALL_BACKEND */
1017 .supported
= pmuv3p1_events_supported
,
1018 .get_count
= zero_event_get_count
,
1019 .ns_per_count
= zero_event_ns_per
,
1021 { .number
= 0x03c, /* STALL */
1022 .supported
= pmuv3p4_events_supported
,
1023 .get_count
= zero_event_get_count
,
1024 .ns_per_count
= zero_event_ns_per
,
1029 * Note: Before increasing MAX_EVENT_ID beyond 0x3f into the 0x40xx range of
1030 * events (i.e. the statistical profiling extension), this implementation
1031 * should first be updated to something sparse instead of the current
1032 * supported_event_map[] array.
1034 #define MAX_EVENT_ID 0x3c
1035 #define UNSUPPORTED_EVENT UINT16_MAX
1036 static uint16_t supported_event_map
[MAX_EVENT_ID
+ 1];
1039 * Called upon CPU initialization to initialize PMCEID[01]_EL0 and build a map
1040 * of ARM event numbers to indices in our pm_events array.
1042 * Note: Events in the 0x40XX range are not currently supported.
1044 void pmu_init(ARMCPU
*cpu
)
1049 * Empty supported_event_map and cpu->pmceid[01] before adding supported
1052 for (i
= 0; i
< ARRAY_SIZE(supported_event_map
); i
++) {
1053 supported_event_map
[i
] = UNSUPPORTED_EVENT
;
1058 for (i
= 0; i
< ARRAY_SIZE(pm_events
); i
++) {
1059 const pm_event
*cnt
= &pm_events
[i
];
1060 assert(cnt
->number
<= MAX_EVENT_ID
);
1061 /* We do not currently support events in the 0x40xx range */
1062 assert(cnt
->number
<= 0x3f);
1064 if (cnt
->supported(&cpu
->env
)) {
1065 supported_event_map
[cnt
->number
] = i
;
1066 uint64_t event_mask
= 1ULL << (cnt
->number
& 0x1f);
1067 if (cnt
->number
& 0x20) {
1068 cpu
->pmceid1
|= event_mask
;
1070 cpu
->pmceid0
|= event_mask
;
1077 * Check at runtime whether a PMU event is supported for the current machine
1079 static bool event_supported(uint16_t number
)
1081 if (number
> MAX_EVENT_ID
) {
1084 return supported_event_map
[number
] != UNSUPPORTED_EVENT
;
1087 static CPAccessResult
pmreg_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1091 * Performance monitor registers user accessibility is controlled
1092 * by PMUSERENR. MDCR_EL2.TPM and MDCR_EL3.TPM allow configurable
1093 * trapping to EL2 or EL3 for other accesses.
1095 int el
= arm_current_el(env
);
1096 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
1098 if (el
== 0 && !(env
->cp15
.c9_pmuserenr
& 1)) {
1099 return CP_ACCESS_TRAP
;
1101 if (el
< 2 && (mdcr_el2
& MDCR_TPM
)) {
1102 return CP_ACCESS_TRAP_EL2
;
1104 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
1105 return CP_ACCESS_TRAP_EL3
;
1108 return CP_ACCESS_OK
;
1111 static CPAccessResult
pmreg_access_xevcntr(CPUARMState
*env
,
1112 const ARMCPRegInfo
*ri
,
1115 /* ER: event counter read trap control */
1116 if (arm_feature(env
, ARM_FEATURE_V8
)
1117 && arm_current_el(env
) == 0
1118 && (env
->cp15
.c9_pmuserenr
& (1 << 3)) != 0
1120 return CP_ACCESS_OK
;
1123 return pmreg_access(env
, ri
, isread
);
1126 static CPAccessResult
pmreg_access_swinc(CPUARMState
*env
,
1127 const ARMCPRegInfo
*ri
,
1130 /* SW: software increment write trap control */
1131 if (arm_feature(env
, ARM_FEATURE_V8
)
1132 && arm_current_el(env
) == 0
1133 && (env
->cp15
.c9_pmuserenr
& (1 << 1)) != 0
1135 return CP_ACCESS_OK
;
1138 return pmreg_access(env
, ri
, isread
);
1141 static CPAccessResult
pmreg_access_selr(CPUARMState
*env
,
1142 const ARMCPRegInfo
*ri
,
1145 /* ER: event counter read trap control */
1146 if (arm_feature(env
, ARM_FEATURE_V8
)
1147 && arm_current_el(env
) == 0
1148 && (env
->cp15
.c9_pmuserenr
& (1 << 3)) != 0) {
1149 return CP_ACCESS_OK
;
1152 return pmreg_access(env
, ri
, isread
);
1155 static CPAccessResult
pmreg_access_ccntr(CPUARMState
*env
,
1156 const ARMCPRegInfo
*ri
,
1159 /* CR: cycle counter read trap control */
1160 if (arm_feature(env
, ARM_FEATURE_V8
)
1161 && arm_current_el(env
) == 0
1162 && (env
->cp15
.c9_pmuserenr
& (1 << 2)) != 0
1164 return CP_ACCESS_OK
;
1167 return pmreg_access(env
, ri
, isread
);
1171 * Bits in MDCR_EL2 and MDCR_EL3 which pmu_counter_enabled() looks at.
1172 * We use these to decide whether we need to wrap a write to MDCR_EL2
1173 * or MDCR_EL3 in pmu_op_start()/pmu_op_finish() calls.
1175 #define MDCR_EL2_PMU_ENABLE_BITS \
1176 (MDCR_HPME | MDCR_HPMD | MDCR_HPMN | MDCR_HCCD | MDCR_HLP)
1177 #define MDCR_EL3_PMU_ENABLE_BITS (MDCR_SPME | MDCR_SCCD)
1180 * Returns true if the counter (pass 31 for PMCCNTR) should count events using
1181 * the current EL, security state, and register configuration.
1183 static bool pmu_counter_enabled(CPUARMState
*env
, uint8_t counter
)
1186 bool e
, p
, u
, nsk
, nsu
, nsh
, m
;
1187 bool enabled
, prohibited
= false, filtered
;
1188 bool secure
= arm_is_secure(env
);
1189 int el
= arm_current_el(env
);
1194 * We might be called for M-profile cores where MDCR_EL2 doesn't
1195 * exist and arm_mdcr_el2_eff() will assert, so this early-exit check
1196 * must be before we read that value.
1198 if (!arm_feature(env
, ARM_FEATURE_PMU
)) {
1202 mdcr_el2
= arm_mdcr_el2_eff(env
);
1203 hpmn
= mdcr_el2
& MDCR_HPMN
;
1205 if (!arm_feature(env
, ARM_FEATURE_EL2
) ||
1206 (counter
< hpmn
|| counter
== 31)) {
1207 e
= env
->cp15
.c9_pmcr
& PMCRE
;
1209 e
= mdcr_el2
& MDCR_HPME
;
1211 enabled
= e
&& (env
->cp15
.c9_pmcnten
& (1 << counter
));
1213 /* Is event counting prohibited? */
1214 if (el
== 2 && (counter
< hpmn
|| counter
== 31)) {
1215 prohibited
= mdcr_el2
& MDCR_HPMD
;
1218 prohibited
= prohibited
|| !(env
->cp15
.mdcr_el3
& MDCR_SPME
);
1221 if (counter
== 31) {
1223 * The cycle counter defaults to running. PMCR.DP says "disable
1224 * the cycle counter when event counting is prohibited".
1225 * Some MDCR bits disable the cycle counter specifically.
1227 prohibited
= prohibited
&& env
->cp15
.c9_pmcr
& PMCRDP
;
1228 if (cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1230 prohibited
= prohibited
|| (env
->cp15
.mdcr_el3
& MDCR_SCCD
);
1233 prohibited
= prohibited
|| (mdcr_el2
& MDCR_HCCD
);
1238 if (counter
== 31) {
1239 filter
= env
->cp15
.pmccfiltr_el0
;
1241 filter
= env
->cp15
.c14_pmevtyper
[counter
];
1244 p
= filter
& PMXEVTYPER_P
;
1245 u
= filter
& PMXEVTYPER_U
;
1246 nsk
= arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_NSK
);
1247 nsu
= arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_NSU
);
1248 nsh
= arm_feature(env
, ARM_FEATURE_EL2
) && (filter
& PMXEVTYPER_NSH
);
1249 m
= arm_el_is_aa64(env
, 1) &&
1250 arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_M
);
1253 filtered
= secure
? u
: u
!= nsu
;
1254 } else if (el
== 1) {
1255 filtered
= secure
? p
: p
!= nsk
;
1256 } else if (el
== 2) {
1262 if (counter
!= 31) {
1264 * If not checking PMCCNTR, ensure the counter is setup to an event we
1267 uint16_t event
= filter
& PMXEVTYPER_EVTCOUNT
;
1268 if (!event_supported(event
)) {
1273 return enabled
&& !prohibited
&& !filtered
;
1276 static void pmu_update_irq(CPUARMState
*env
)
1278 ARMCPU
*cpu
= env_archcpu(env
);
1279 qemu_set_irq(cpu
->pmu_interrupt
, (env
->cp15
.c9_pmcr
& PMCRE
) &&
1280 (env
->cp15
.c9_pminten
& env
->cp15
.c9_pmovsr
));
1283 static bool pmccntr_clockdiv_enabled(CPUARMState
*env
)
1286 * Return true if the clock divider is enabled and the cycle counter
1287 * is supposed to tick only once every 64 clock cycles. This is
1288 * controlled by PMCR.D, but if PMCR.LC is set to enable the long
1289 * (64-bit) cycle counter PMCR.D has no effect.
1291 return (env
->cp15
.c9_pmcr
& (PMCRD
| PMCRLC
)) == PMCRD
;
1294 static bool pmevcntr_is_64_bit(CPUARMState
*env
, int counter
)
1296 /* Return true if the specified event counter is configured to be 64 bit */
1298 /* This isn't intended to be used with the cycle counter */
1299 assert(counter
< 31);
1301 if (!cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1305 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
1307 * MDCR_EL2.HLP still applies even when EL2 is disabled in the
1308 * current security state, so we don't use arm_mdcr_el2_eff() here.
1310 bool hlp
= env
->cp15
.mdcr_el2
& MDCR_HLP
;
1311 int hpmn
= env
->cp15
.mdcr_el2
& MDCR_HPMN
;
1313 if (counter
>= hpmn
) {
1317 return env
->cp15
.c9_pmcr
& PMCRLP
;
1321 * Ensure c15_ccnt is the guest-visible count so that operations such as
1322 * enabling/disabling the counter or filtering, modifying the count itself,
1323 * etc. can be done logically. This is essentially a no-op if the counter is
1324 * not enabled at the time of the call.
1326 static void pmccntr_op_start(CPUARMState
*env
)
1328 uint64_t cycles
= cycles_get_count(env
);
1330 if (pmu_counter_enabled(env
, 31)) {
1331 uint64_t eff_cycles
= cycles
;
1332 if (pmccntr_clockdiv_enabled(env
)) {
1336 uint64_t new_pmccntr
= eff_cycles
- env
->cp15
.c15_ccnt_delta
;
1338 uint64_t overflow_mask
= env
->cp15
.c9_pmcr
& PMCRLC
? \
1339 1ull << 63 : 1ull << 31;
1340 if (env
->cp15
.c15_ccnt
& ~new_pmccntr
& overflow_mask
) {
1341 env
->cp15
.c9_pmovsr
|= (1ULL << 31);
1342 pmu_update_irq(env
);
1345 env
->cp15
.c15_ccnt
= new_pmccntr
;
1347 env
->cp15
.c15_ccnt_delta
= cycles
;
1351 * If PMCCNTR is enabled, recalculate the delta between the clock and the
1352 * guest-visible count. A call to pmccntr_op_finish should follow every call to
1355 static void pmccntr_op_finish(CPUARMState
*env
)
1357 if (pmu_counter_enabled(env
, 31)) {
1358 #ifndef CONFIG_USER_ONLY
1359 /* Calculate when the counter will next overflow */
1360 uint64_t remaining_cycles
= -env
->cp15
.c15_ccnt
;
1361 if (!(env
->cp15
.c9_pmcr
& PMCRLC
)) {
1362 remaining_cycles
= (uint32_t)remaining_cycles
;
1364 int64_t overflow_in
= cycles_ns_per(remaining_cycles
);
1366 if (overflow_in
> 0) {
1367 int64_t overflow_at
;
1369 if (!sadd64_overflow(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
1370 overflow_in
, &overflow_at
)) {
1371 ARMCPU
*cpu
= env_archcpu(env
);
1372 timer_mod_anticipate_ns(cpu
->pmu_timer
, overflow_at
);
1377 uint64_t prev_cycles
= env
->cp15
.c15_ccnt_delta
;
1378 if (pmccntr_clockdiv_enabled(env
)) {
1381 env
->cp15
.c15_ccnt_delta
= prev_cycles
- env
->cp15
.c15_ccnt
;
1385 static void pmevcntr_op_start(CPUARMState
*env
, uint8_t counter
)
1388 uint16_t event
= env
->cp15
.c14_pmevtyper
[counter
] & PMXEVTYPER_EVTCOUNT
;
1390 if (event_supported(event
)) {
1391 uint16_t event_idx
= supported_event_map
[event
];
1392 count
= pm_events
[event_idx
].get_count(env
);
1395 if (pmu_counter_enabled(env
, counter
)) {
1396 uint64_t new_pmevcntr
= count
- env
->cp15
.c14_pmevcntr_delta
[counter
];
1397 uint64_t overflow_mask
= pmevcntr_is_64_bit(env
, counter
) ?
1398 1ULL << 63 : 1ULL << 31;
1400 if (env
->cp15
.c14_pmevcntr
[counter
] & ~new_pmevcntr
& overflow_mask
) {
1401 env
->cp15
.c9_pmovsr
|= (1 << counter
);
1402 pmu_update_irq(env
);
1404 env
->cp15
.c14_pmevcntr
[counter
] = new_pmevcntr
;
1406 env
->cp15
.c14_pmevcntr_delta
[counter
] = count
;
1409 static void pmevcntr_op_finish(CPUARMState
*env
, uint8_t counter
)
1411 if (pmu_counter_enabled(env
, counter
)) {
1412 #ifndef CONFIG_USER_ONLY
1413 uint16_t event
= env
->cp15
.c14_pmevtyper
[counter
] & PMXEVTYPER_EVTCOUNT
;
1414 uint16_t event_idx
= supported_event_map
[event
];
1415 uint64_t delta
= -(env
->cp15
.c14_pmevcntr
[counter
] + 1);
1416 int64_t overflow_in
;
1418 if (!pmevcntr_is_64_bit(env
, counter
)) {
1419 delta
= (uint32_t)delta
;
1421 overflow_in
= pm_events
[event_idx
].ns_per_count(delta
);
1423 if (overflow_in
> 0) {
1424 int64_t overflow_at
;
1426 if (!sadd64_overflow(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
1427 overflow_in
, &overflow_at
)) {
1428 ARMCPU
*cpu
= env_archcpu(env
);
1429 timer_mod_anticipate_ns(cpu
->pmu_timer
, overflow_at
);
1434 env
->cp15
.c14_pmevcntr_delta
[counter
] -=
1435 env
->cp15
.c14_pmevcntr
[counter
];
1439 void pmu_op_start(CPUARMState
*env
)
1442 pmccntr_op_start(env
);
1443 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1444 pmevcntr_op_start(env
, i
);
1448 void pmu_op_finish(CPUARMState
*env
)
1451 pmccntr_op_finish(env
);
1452 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1453 pmevcntr_op_finish(env
, i
);
1457 void pmu_pre_el_change(ARMCPU
*cpu
, void *ignored
)
1459 pmu_op_start(&cpu
->env
);
1462 void pmu_post_el_change(ARMCPU
*cpu
, void *ignored
)
1464 pmu_op_finish(&cpu
->env
);
1467 void arm_pmu_timer_cb(void *opaque
)
1469 ARMCPU
*cpu
= opaque
;
1472 * Update all the counter values based on the current underlying counts,
1473 * triggering interrupts to be raised, if necessary. pmu_op_finish() also
1474 * has the effect of setting the cpu->pmu_timer to the next earliest time a
1475 * counter may expire.
1477 pmu_op_start(&cpu
->env
);
1478 pmu_op_finish(&cpu
->env
);
1481 static void pmcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1486 if (value
& PMCRC
) {
1487 /* The counter has been reset */
1488 env
->cp15
.c15_ccnt
= 0;
1491 if (value
& PMCRP
) {
1493 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1494 env
->cp15
.c14_pmevcntr
[i
] = 0;
1498 env
->cp15
.c9_pmcr
&= ~PMCR_WRITABLE_MASK
;
1499 env
->cp15
.c9_pmcr
|= (value
& PMCR_WRITABLE_MASK
);
1504 static uint64_t pmcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1506 uint64_t pmcr
= env
->cp15
.c9_pmcr
;
1509 * If EL2 is implemented and enabled for the current security state, reads
1510 * of PMCR.N from EL1 or EL0 return the value of MDCR_EL2.HPMN or HDCR.HPMN.
1512 if (arm_current_el(env
) <= 1 && arm_is_el2_enabled(env
)) {
1513 pmcr
&= ~PMCRN_MASK
;
1514 pmcr
|= (env
->cp15
.mdcr_el2
& MDCR_HPMN
) << PMCRN_SHIFT
;
1520 static void pmswinc_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1524 uint64_t overflow_mask
, new_pmswinc
;
1526 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1527 /* Increment a counter's count iff: */
1528 if ((value
& (1 << i
)) && /* counter's bit is set */
1529 /* counter is enabled and not filtered */
1530 pmu_counter_enabled(env
, i
) &&
1531 /* counter is SW_INCR */
1532 (env
->cp15
.c14_pmevtyper
[i
] & PMXEVTYPER_EVTCOUNT
) == 0x0) {
1533 pmevcntr_op_start(env
, i
);
1536 * Detect if this write causes an overflow since we can't predict
1537 * PMSWINC overflows like we can for other events
1539 new_pmswinc
= env
->cp15
.c14_pmevcntr
[i
] + 1;
1541 overflow_mask
= pmevcntr_is_64_bit(env
, i
) ?
1542 1ULL << 63 : 1ULL << 31;
1544 if (env
->cp15
.c14_pmevcntr
[i
] & ~new_pmswinc
& overflow_mask
) {
1545 env
->cp15
.c9_pmovsr
|= (1 << i
);
1546 pmu_update_irq(env
);
1549 env
->cp15
.c14_pmevcntr
[i
] = new_pmswinc
;
1551 pmevcntr_op_finish(env
, i
);
1556 static uint64_t pmccntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1559 pmccntr_op_start(env
);
1560 ret
= env
->cp15
.c15_ccnt
;
1561 pmccntr_op_finish(env
);
1565 static void pmselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1569 * The value of PMSELR.SEL affects the behavior of PMXEVTYPER and
1570 * PMXEVCNTR. We allow [0..31] to be written to PMSELR here; in the
1571 * meanwhile, we check PMSELR.SEL when PMXEVTYPER and PMXEVCNTR are
1574 env
->cp15
.c9_pmselr
= value
& 0x1f;
1577 static void pmccntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1580 pmccntr_op_start(env
);
1581 env
->cp15
.c15_ccnt
= value
;
1582 pmccntr_op_finish(env
);
1585 static void pmccntr_write32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1588 uint64_t cur_val
= pmccntr_read(env
, NULL
);
1590 pmccntr_write(env
, ri
, deposit64(cur_val
, 0, 32, value
));
1593 static void pmccfiltr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1596 pmccntr_op_start(env
);
1597 env
->cp15
.pmccfiltr_el0
= value
& PMCCFILTR_EL0
;
1598 pmccntr_op_finish(env
);
1601 static void pmccfiltr_write_a32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1604 pmccntr_op_start(env
);
1605 /* M is not accessible from AArch32 */
1606 env
->cp15
.pmccfiltr_el0
= (env
->cp15
.pmccfiltr_el0
& PMCCFILTR_M
) |
1607 (value
& PMCCFILTR
);
1608 pmccntr_op_finish(env
);
1611 static uint64_t pmccfiltr_read_a32(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1613 /* M is not visible in AArch32 */
1614 return env
->cp15
.pmccfiltr_el0
& PMCCFILTR
;
1617 static void pmcntenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1621 value
&= pmu_counter_mask(env
);
1622 env
->cp15
.c9_pmcnten
|= value
;
1626 static void pmcntenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1630 value
&= pmu_counter_mask(env
);
1631 env
->cp15
.c9_pmcnten
&= ~value
;
1635 static void pmovsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1638 value
&= pmu_counter_mask(env
);
1639 env
->cp15
.c9_pmovsr
&= ~value
;
1640 pmu_update_irq(env
);
1643 static void pmovsset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1646 value
&= pmu_counter_mask(env
);
1647 env
->cp15
.c9_pmovsr
|= value
;
1648 pmu_update_irq(env
);
1651 static void pmevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1652 uint64_t value
, const uint8_t counter
)
1654 if (counter
== 31) {
1655 pmccfiltr_write(env
, ri
, value
);
1656 } else if (counter
< pmu_num_counters(env
)) {
1657 pmevcntr_op_start(env
, counter
);
1660 * If this counter's event type is changing, store the current
1661 * underlying count for the new type in c14_pmevcntr_delta[counter] so
1662 * pmevcntr_op_finish has the correct baseline when it converts back to
1665 uint16_t old_event
= env
->cp15
.c14_pmevtyper
[counter
] &
1666 PMXEVTYPER_EVTCOUNT
;
1667 uint16_t new_event
= value
& PMXEVTYPER_EVTCOUNT
;
1668 if (old_event
!= new_event
) {
1670 if (event_supported(new_event
)) {
1671 uint16_t event_idx
= supported_event_map
[new_event
];
1672 count
= pm_events
[event_idx
].get_count(env
);
1674 env
->cp15
.c14_pmevcntr_delta
[counter
] = count
;
1677 env
->cp15
.c14_pmevtyper
[counter
] = value
& PMXEVTYPER_MASK
;
1678 pmevcntr_op_finish(env
, counter
);
1681 * Attempts to access PMXEVTYPER are CONSTRAINED UNPREDICTABLE when
1682 * PMSELR value is equal to or greater than the number of implemented
1683 * counters, but not equal to 0x1f. We opt to behave as a RAZ/WI.
1687 static uint64_t pmevtyper_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1688 const uint8_t counter
)
1690 if (counter
== 31) {
1691 return env
->cp15
.pmccfiltr_el0
;
1692 } else if (counter
< pmu_num_counters(env
)) {
1693 return env
->cp15
.c14_pmevtyper
[counter
];
1696 * We opt to behave as a RAZ/WI when attempts to access PMXEVTYPER
1697 * are CONSTRAINED UNPREDICTABLE. See comments in pmevtyper_write().
1703 static void pmevtyper_writefn(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1706 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1707 pmevtyper_write(env
, ri
, value
, counter
);
1710 static void pmevtyper_rawwrite(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1713 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1714 env
->cp15
.c14_pmevtyper
[counter
] = value
;
1717 * pmevtyper_rawwrite is called between a pair of pmu_op_start and
1718 * pmu_op_finish calls when loading saved state for a migration. Because
1719 * we're potentially updating the type of event here, the value written to
1720 * c14_pmevcntr_delta by the preceding pmu_op_start call may be for a
1721 * different counter type. Therefore, we need to set this value to the
1722 * current count for the counter type we're writing so that pmu_op_finish
1723 * has the correct count for its calculation.
1725 uint16_t event
= value
& PMXEVTYPER_EVTCOUNT
;
1726 if (event_supported(event
)) {
1727 uint16_t event_idx
= supported_event_map
[event
];
1728 env
->cp15
.c14_pmevcntr_delta
[counter
] =
1729 pm_events
[event_idx
].get_count(env
);
1733 static uint64_t pmevtyper_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1735 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1736 return pmevtyper_read(env
, ri
, counter
);
1739 static void pmxevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1742 pmevtyper_write(env
, ri
, value
, env
->cp15
.c9_pmselr
& 31);
1745 static uint64_t pmxevtyper_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1747 return pmevtyper_read(env
, ri
, env
->cp15
.c9_pmselr
& 31);
1750 static void pmevcntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1751 uint64_t value
, uint8_t counter
)
1753 if (!cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1754 /* Before FEAT_PMUv3p5, top 32 bits of event counters are RES0 */
1755 value
&= MAKE_64BIT_MASK(0, 32);
1757 if (counter
< pmu_num_counters(env
)) {
1758 pmevcntr_op_start(env
, counter
);
1759 env
->cp15
.c14_pmevcntr
[counter
] = value
;
1760 pmevcntr_op_finish(env
, counter
);
1763 * We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
1764 * are CONSTRAINED UNPREDICTABLE.
1768 static uint64_t pmevcntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1771 if (counter
< pmu_num_counters(env
)) {
1773 pmevcntr_op_start(env
, counter
);
1774 ret
= env
->cp15
.c14_pmevcntr
[counter
];
1775 pmevcntr_op_finish(env
, counter
);
1776 if (!cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1777 /* Before FEAT_PMUv3p5, top 32 bits of event counters are RES0 */
1778 ret
&= MAKE_64BIT_MASK(0, 32);
1783 * We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
1784 * are CONSTRAINED UNPREDICTABLE.
1790 static void pmevcntr_writefn(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1793 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1794 pmevcntr_write(env
, ri
, value
, counter
);
1797 static uint64_t pmevcntr_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1799 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1800 return pmevcntr_read(env
, ri
, counter
);
1803 static void pmevcntr_rawwrite(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1806 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1807 assert(counter
< pmu_num_counters(env
));
1808 env
->cp15
.c14_pmevcntr
[counter
] = value
;
1809 pmevcntr_write(env
, ri
, value
, counter
);
1812 static uint64_t pmevcntr_rawread(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1814 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1815 assert(counter
< pmu_num_counters(env
));
1816 return env
->cp15
.c14_pmevcntr
[counter
];
1819 static void pmxevcntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1822 pmevcntr_write(env
, ri
, value
, env
->cp15
.c9_pmselr
& 31);
1825 static uint64_t pmxevcntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1827 return pmevcntr_read(env
, ri
, env
->cp15
.c9_pmselr
& 31);
1830 static void pmuserenr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1833 if (arm_feature(env
, ARM_FEATURE_V8
)) {
1834 env
->cp15
.c9_pmuserenr
= value
& 0xf;
1836 env
->cp15
.c9_pmuserenr
= value
& 1;
1840 static void pmintenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1843 /* We have no event counters so only the C bit can be changed */
1844 value
&= pmu_counter_mask(env
);
1845 env
->cp15
.c9_pminten
|= value
;
1846 pmu_update_irq(env
);
1849 static void pmintenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1852 value
&= pmu_counter_mask(env
);
1853 env
->cp15
.c9_pminten
&= ~value
;
1854 pmu_update_irq(env
);
1857 static void vbar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1861 * Note that even though the AArch64 view of this register has bits
1862 * [10:0] all RES0 we can only mask the bottom 5, to comply with the
1863 * architectural requirements for bits which are RES0 only in some
1864 * contexts. (ARMv8 would permit us to do no masking at all, but ARMv7
1865 * requires the bottom five bits to be RAZ/WI because they're UNK/SBZP.)
1867 raw_write(env
, ri
, value
& ~0x1FULL
);
1870 static void scr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
1872 /* Begin with base v8.0 state. */
1873 uint64_t valid_mask
= 0x3fff;
1874 ARMCPU
*cpu
= env_archcpu(env
);
1878 * Because SCR_EL3 is the "real" cpreg and SCR is the alias, reset always
1879 * passes the reginfo for SCR_EL3, which has type ARM_CP_STATE_AA64.
1880 * Instead, choose the format based on the mode of EL3.
1882 if (arm_el_is_aa64(env
, 3)) {
1883 value
|= SCR_FW
| SCR_AW
; /* RES1 */
1884 valid_mask
&= ~SCR_NET
; /* RES0 */
1886 if (!cpu_isar_feature(aa64_aa32_el1
, cpu
) &&
1887 !cpu_isar_feature(aa64_aa32_el2
, cpu
)) {
1888 value
|= SCR_RW
; /* RAO/WI */
1890 if (cpu_isar_feature(aa64_ras
, cpu
)) {
1891 valid_mask
|= SCR_TERR
;
1893 if (cpu_isar_feature(aa64_lor
, cpu
)) {
1894 valid_mask
|= SCR_TLOR
;
1896 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
1897 valid_mask
|= SCR_API
| SCR_APK
;
1899 if (cpu_isar_feature(aa64_sel2
, cpu
)) {
1900 valid_mask
|= SCR_EEL2
;
1901 } else if (cpu_isar_feature(aa64_rme
, cpu
)) {
1902 /* With RME and without SEL2, NS is RES1 (R_GSWWH, I_DJJQJ). */
1905 if (cpu_isar_feature(aa64_mte
, cpu
)) {
1906 valid_mask
|= SCR_ATA
;
1908 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
1909 valid_mask
|= SCR_ENSCXT
;
1911 if (cpu_isar_feature(aa64_doublefault
, cpu
)) {
1912 valid_mask
|= SCR_EASE
| SCR_NMEA
;
1914 if (cpu_isar_feature(aa64_sme
, cpu
)) {
1915 valid_mask
|= SCR_ENTP2
;
1917 if (cpu_isar_feature(aa64_hcx
, cpu
)) {
1918 valid_mask
|= SCR_HXEN
;
1920 if (cpu_isar_feature(aa64_fgt
, cpu
)) {
1921 valid_mask
|= SCR_FGTEN
;
1923 if (cpu_isar_feature(aa64_rme
, cpu
)) {
1924 valid_mask
|= SCR_NSE
| SCR_GPF
;
1926 if (cpu_isar_feature(aa64_ecv
, cpu
)) {
1927 valid_mask
|= SCR_ECVEN
;
1930 valid_mask
&= ~(SCR_RW
| SCR_ST
);
1931 if (cpu_isar_feature(aa32_ras
, cpu
)) {
1932 valid_mask
|= SCR_TERR
;
1936 if (!arm_feature(env
, ARM_FEATURE_EL2
)) {
1937 valid_mask
&= ~SCR_HCE
;
1940 * On ARMv7, SMD (or SCD as it is called in v7) is only
1941 * supported if EL2 exists. The bit is UNK/SBZP when
1942 * EL2 is unavailable. In QEMU ARMv7, we force it to always zero
1943 * when EL2 is unavailable.
1944 * On ARMv8, this bit is always available.
1946 if (arm_feature(env
, ARM_FEATURE_V7
) &&
1947 !arm_feature(env
, ARM_FEATURE_V8
)) {
1948 valid_mask
&= ~SCR_SMD
;
1952 /* Clear all-context RES0 bits. */
1953 value
&= valid_mask
;
1954 changed
= env
->cp15
.scr_el3
^ value
;
1955 env
->cp15
.scr_el3
= value
;
1958 * If SCR_EL3.{NS,NSE} changes, i.e. change of security state,
1959 * we must invalidate all TLBs below EL3.
1961 if (changed
& (SCR_NS
| SCR_NSE
)) {
1962 tlb_flush_by_mmuidx(env_cpu(env
), (ARMMMUIdxBit_E10_0
|
1963 ARMMMUIdxBit_E20_0
|
1964 ARMMMUIdxBit_E10_1
|
1965 ARMMMUIdxBit_E20_2
|
1966 ARMMMUIdxBit_E10_1_PAN
|
1967 ARMMMUIdxBit_E20_2_PAN
|
1972 static void scr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1975 * scr_write will set the RES1 bits on an AArch64-only CPU.
1976 * The reset value will be 0x30 on an AArch64-only CPU and 0 otherwise.
1978 scr_write(env
, ri
, 0);
1981 static CPAccessResult
access_tid4(CPUARMState
*env
,
1982 const ARMCPRegInfo
*ri
,
1985 if (arm_current_el(env
) == 1 &&
1986 (arm_hcr_el2_eff(env
) & (HCR_TID2
| HCR_TID4
))) {
1987 return CP_ACCESS_TRAP_EL2
;
1990 return CP_ACCESS_OK
;
1993 static uint64_t ccsidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1995 ARMCPU
*cpu
= env_archcpu(env
);
1998 * Acquire the CSSELR index from the bank corresponding to the CCSIDR
2001 uint32_t index
= A32_BANKED_REG_GET(env
, csselr
,
2002 ri
->secure
& ARM_CP_SECSTATE_S
);
2004 return cpu
->ccsidr
[index
];
2007 static void csselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2010 raw_write(env
, ri
, value
& 0xf);
2013 static uint64_t isr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2015 CPUState
*cs
= env_cpu(env
);
2016 bool el1
= arm_current_el(env
) == 1;
2017 uint64_t hcr_el2
= el1
? arm_hcr_el2_eff(env
) : 0;
2020 if (hcr_el2
& HCR_IMO
) {
2021 if (cs
->interrupt_request
& CPU_INTERRUPT_VIRQ
) {
2025 if (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) {
2030 if (hcr_el2
& HCR_FMO
) {
2031 if (cs
->interrupt_request
& CPU_INTERRUPT_VFIQ
) {
2035 if (cs
->interrupt_request
& CPU_INTERRUPT_FIQ
) {
2040 if (hcr_el2
& HCR_AMO
) {
2041 if (cs
->interrupt_request
& CPU_INTERRUPT_VSERR
) {
2049 static CPAccessResult
access_aa64_tid1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2052 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID1
)) {
2053 return CP_ACCESS_TRAP_EL2
;
2056 return CP_ACCESS_OK
;
2059 static CPAccessResult
access_aa32_tid1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2062 if (arm_feature(env
, ARM_FEATURE_V8
)) {
2063 return access_aa64_tid1(env
, ri
, isread
);
2066 return CP_ACCESS_OK
;
2069 static const ARMCPRegInfo v7_cp_reginfo
[] = {
2070 /* the old v6 WFI, UNPREDICTABLE in v7 but we choose to NOP */
2071 { .name
= "NOP", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
2072 .access
= PL1_W
, .type
= ARM_CP_NOP
},
2074 * Performance monitors are implementation defined in v7,
2075 * but with an ARM recommended set of registers, which we
2078 * Performance registers fall into three categories:
2079 * (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR)
2080 * (b) RO in PL0 (ie UNDEF on write), RW in PL1 (PMUSERENR)
2081 * (c) UNDEF in PL0 if PMUSERENR.EN==0, otherwise accessible (all others)
2082 * For the cases controlled by PMUSERENR we must set .access to PL0_RW
2083 * or PL0_RO as appropriate and then check PMUSERENR in the helper fn.
2085 { .name
= "PMCNTENSET", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 1,
2086 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2087 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
2088 .writefn
= pmcntenset_write
,
2089 .accessfn
= pmreg_access
,
2091 .raw_writefn
= raw_write
},
2092 { .name
= "PMCNTENSET_EL0", .state
= ARM_CP_STATE_AA64
, .type
= ARM_CP_IO
,
2093 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 1,
2094 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2096 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
), .resetvalue
= 0,
2097 .writefn
= pmcntenset_write
, .raw_writefn
= raw_write
},
2098 { .name
= "PMCNTENCLR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 2,
2100 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
2101 .accessfn
= pmreg_access
,
2103 .writefn
= pmcntenclr_write
,
2104 .type
= ARM_CP_ALIAS
| ARM_CP_IO
},
2105 { .name
= "PMCNTENCLR_EL0", .state
= ARM_CP_STATE_AA64
,
2106 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 2,
2107 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2109 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2110 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
),
2111 .writefn
= pmcntenclr_write
},
2112 { .name
= "PMOVSR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 3,
2113 .access
= PL0_RW
, .type
= ARM_CP_IO
,
2114 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmovsr
),
2115 .accessfn
= pmreg_access
,
2117 .writefn
= pmovsr_write
,
2118 .raw_writefn
= raw_write
},
2119 { .name
= "PMOVSCLR_EL0", .state
= ARM_CP_STATE_AA64
,
2120 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 3,
2121 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2123 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2124 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
2125 .writefn
= pmovsr_write
,
2126 .raw_writefn
= raw_write
},
2127 { .name
= "PMSWINC", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 4,
2128 .access
= PL0_W
, .accessfn
= pmreg_access_swinc
,
2129 .fgt
= FGT_PMSWINC_EL0
,
2130 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2131 .writefn
= pmswinc_write
},
2132 { .name
= "PMSWINC_EL0", .state
= ARM_CP_STATE_AA64
,
2133 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 4,
2134 .access
= PL0_W
, .accessfn
= pmreg_access_swinc
,
2135 .fgt
= FGT_PMSWINC_EL0
,
2136 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2137 .writefn
= pmswinc_write
},
2138 { .name
= "PMSELR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 5,
2139 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
,
2140 .fgt
= FGT_PMSELR_EL0
,
2141 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmselr
),
2142 .accessfn
= pmreg_access_selr
, .writefn
= pmselr_write
,
2143 .raw_writefn
= raw_write
},
2144 { .name
= "PMSELR_EL0", .state
= ARM_CP_STATE_AA64
,
2145 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 5,
2146 .access
= PL0_RW
, .accessfn
= pmreg_access_selr
,
2147 .fgt
= FGT_PMSELR_EL0
,
2148 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmselr
),
2149 .writefn
= pmselr_write
, .raw_writefn
= raw_write
, },
2150 { .name
= "PMCCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 0,
2151 .access
= PL0_RW
, .resetvalue
= 0, .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2152 .fgt
= FGT_PMCCNTR_EL0
,
2153 .readfn
= pmccntr_read
, .writefn
= pmccntr_write32
,
2154 .accessfn
= pmreg_access_ccntr
},
2155 { .name
= "PMCCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
2156 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 0,
2157 .access
= PL0_RW
, .accessfn
= pmreg_access_ccntr
,
2158 .fgt
= FGT_PMCCNTR_EL0
,
2160 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ccnt
),
2161 .readfn
= pmccntr_read
, .writefn
= pmccntr_write
,
2162 .raw_readfn
= raw_read
, .raw_writefn
= raw_write
, },
2163 { .name
= "PMCCFILTR", .cp
= 15, .opc1
= 0, .crn
= 14, .crm
= 15, .opc2
= 7,
2164 .writefn
= pmccfiltr_write_a32
, .readfn
= pmccfiltr_read_a32
,
2165 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2166 .fgt
= FGT_PMCCFILTR_EL0
,
2167 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2169 { .name
= "PMCCFILTR_EL0", .state
= ARM_CP_STATE_AA64
,
2170 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 15, .opc2
= 7,
2171 .writefn
= pmccfiltr_write
, .raw_writefn
= raw_write
,
2172 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2173 .fgt
= FGT_PMCCFILTR_EL0
,
2175 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmccfiltr_el0
),
2177 { .name
= "PMXEVTYPER", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 1,
2178 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2179 .accessfn
= pmreg_access
,
2180 .fgt
= FGT_PMEVTYPERN_EL0
,
2181 .writefn
= pmxevtyper_write
, .readfn
= pmxevtyper_read
},
2182 { .name
= "PMXEVTYPER_EL0", .state
= ARM_CP_STATE_AA64
,
2183 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 1,
2184 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2185 .accessfn
= pmreg_access
,
2186 .fgt
= FGT_PMEVTYPERN_EL0
,
2187 .writefn
= pmxevtyper_write
, .readfn
= pmxevtyper_read
},
2188 { .name
= "PMXEVCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 2,
2189 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2190 .accessfn
= pmreg_access_xevcntr
,
2191 .fgt
= FGT_PMEVCNTRN_EL0
,
2192 .writefn
= pmxevcntr_write
, .readfn
= pmxevcntr_read
},
2193 { .name
= "PMXEVCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
2194 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 2,
2195 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2196 .accessfn
= pmreg_access_xevcntr
,
2197 .fgt
= FGT_PMEVCNTRN_EL0
,
2198 .writefn
= pmxevcntr_write
, .readfn
= pmxevcntr_read
},
2199 { .name
= "PMUSERENR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 0,
2200 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
,
2201 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmuserenr
),
2203 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
2204 { .name
= "PMUSERENR_EL0", .state
= ARM_CP_STATE_AA64
,
2205 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 0,
2206 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
, .type
= ARM_CP_ALIAS
,
2207 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmuserenr
),
2209 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
2210 { .name
= "PMINTENSET", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 1,
2211 .access
= PL1_RW
, .accessfn
= access_tpm
,
2213 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2214 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pminten
),
2216 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
},
2217 { .name
= "PMINTENSET_EL1", .state
= ARM_CP_STATE_AA64
,
2218 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 1,
2219 .access
= PL1_RW
, .accessfn
= access_tpm
,
2222 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2223 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
,
2224 .resetvalue
= 0x0 },
2225 { .name
= "PMINTENCLR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 2,
2226 .access
= PL1_RW
, .accessfn
= access_tpm
,
2228 .type
= ARM_CP_ALIAS
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2229 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2230 .writefn
= pmintenclr_write
, },
2231 { .name
= "PMINTENCLR_EL1", .state
= ARM_CP_STATE_AA64
,
2232 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 2,
2233 .access
= PL1_RW
, .accessfn
= access_tpm
,
2235 .type
= ARM_CP_ALIAS
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2236 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2237 .writefn
= pmintenclr_write
},
2238 { .name
= "CCSIDR", .state
= ARM_CP_STATE_BOTH
,
2239 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 0,
2241 .accessfn
= access_tid4
,
2242 .fgt
= FGT_CCSIDR_EL1
,
2243 .readfn
= ccsidr_read
, .type
= ARM_CP_NO_RAW
},
2244 { .name
= "CSSELR", .state
= ARM_CP_STATE_BOTH
,
2245 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 2, .opc2
= 0,
2247 .accessfn
= access_tid4
,
2248 .fgt
= FGT_CSSELR_EL1
,
2249 .writefn
= csselr_write
, .resetvalue
= 0,
2250 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.csselr_s
),
2251 offsetof(CPUARMState
, cp15
.csselr_ns
) } },
2253 * Auxiliary ID register: this actually has an IMPDEF value but for now
2254 * just RAZ for all cores:
2256 { .name
= "AIDR", .state
= ARM_CP_STATE_BOTH
,
2257 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 7,
2258 .access
= PL1_R
, .type
= ARM_CP_CONST
,
2259 .accessfn
= access_aa64_tid1
,
2260 .fgt
= FGT_AIDR_EL1
,
2263 * Auxiliary fault status registers: these also are IMPDEF, and we
2264 * choose to RAZ/WI for all cores.
2266 { .name
= "AFSR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2267 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 0,
2268 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2269 .fgt
= FGT_AFSR0_EL1
,
2270 .nv2_redirect_offset
= 0x128 | NV2_REDIR_NV1
,
2271 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
2272 { .name
= "AFSR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2273 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 1,
2274 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2275 .fgt
= FGT_AFSR1_EL1
,
2276 .nv2_redirect_offset
= 0x130 | NV2_REDIR_NV1
,
2277 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
2279 * MAIR can just read-as-written because we don't implement caches
2280 * and so don't need to care about memory attributes.
2282 { .name
= "MAIR_EL1", .state
= ARM_CP_STATE_AA64
,
2283 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
2284 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2285 .fgt
= FGT_MAIR_EL1
,
2286 .nv2_redirect_offset
= 0x140 | NV2_REDIR_NV1
,
2287 .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[1]),
2289 { .name
= "MAIR_EL3", .state
= ARM_CP_STATE_AA64
,
2290 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 2, .opc2
= 0,
2291 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[3]),
2294 * For non-long-descriptor page tables these are PRRR and NMRR;
2295 * regardless they still act as reads-as-written for QEMU.
2298 * MAIR0/1 are defined separately from their 64-bit counterpart which
2299 * allows them to assign the correct fieldoffset based on the endianness
2300 * handled in the field definitions.
2302 { .name
= "MAIR0", .state
= ARM_CP_STATE_AA32
,
2303 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
2304 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2305 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair0_s
),
2306 offsetof(CPUARMState
, cp15
.mair0_ns
) },
2307 .resetfn
= arm_cp_reset_ignore
},
2308 { .name
= "MAIR1", .state
= ARM_CP_STATE_AA32
,
2309 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 1,
2310 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2311 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair1_s
),
2312 offsetof(CPUARMState
, cp15
.mair1_ns
) },
2313 .resetfn
= arm_cp_reset_ignore
},
2314 { .name
= "ISR_EL1", .state
= ARM_CP_STATE_BOTH
,
2315 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 1, .opc2
= 0,
2317 .type
= ARM_CP_NO_RAW
, .access
= PL1_R
, .readfn
= isr_read
},
2318 /* 32 bit ITLB invalidates */
2319 { .name
= "ITLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 0,
2320 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2321 .writefn
= tlbiall_write
},
2322 { .name
= "ITLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
2323 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2324 .writefn
= tlbimva_write
},
2325 { .name
= "ITLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 2,
2326 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2327 .writefn
= tlbiasid_write
},
2328 /* 32 bit DTLB invalidates */
2329 { .name
= "DTLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 0,
2330 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2331 .writefn
= tlbiall_write
},
2332 { .name
= "DTLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
2333 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2334 .writefn
= tlbimva_write
},
2335 { .name
= "DTLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 2,
2336 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2337 .writefn
= tlbiasid_write
},
2338 /* 32 bit TLB invalidates */
2339 { .name
= "TLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
2340 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2341 .writefn
= tlbiall_write
},
2342 { .name
= "TLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
2343 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2344 .writefn
= tlbimva_write
},
2345 { .name
= "TLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
2346 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2347 .writefn
= tlbiasid_write
},
2348 { .name
= "TLBIMVAA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
2349 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2350 .writefn
= tlbimvaa_write
},
2353 static const ARMCPRegInfo v7mp_cp_reginfo
[] = {
2354 /* 32 bit TLB invalidates, Inner Shareable */
2355 { .name
= "TLBIALLIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
2356 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
2357 .writefn
= tlbiall_is_write
},
2358 { .name
= "TLBIMVAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
2359 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
2360 .writefn
= tlbimva_is_write
},
2361 { .name
= "TLBIASIDIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
2362 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
2363 .writefn
= tlbiasid_is_write
},
2364 { .name
= "TLBIMVAAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
2365 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
2366 .writefn
= tlbimvaa_is_write
},
2369 static const ARMCPRegInfo pmovsset_cp_reginfo
[] = {
2370 /* PMOVSSET is not implemented in v7 before v7ve */
2371 { .name
= "PMOVSSET", .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 3,
2372 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2374 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2375 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmovsr
),
2376 .writefn
= pmovsset_write
,
2377 .raw_writefn
= raw_write
},
2378 { .name
= "PMOVSSET_EL0", .state
= ARM_CP_STATE_AA64
,
2379 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 3,
2380 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2382 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2383 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
2384 .writefn
= pmovsset_write
,
2385 .raw_writefn
= raw_write
},
2388 static void teecr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2395 static CPAccessResult
teecr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2399 * HSTR.TTEE only exists in v7A, not v8A, but v8A doesn't have T2EE
2400 * at all, so we don't need to check whether we're v8A.
2402 if (arm_current_el(env
) < 2 && !arm_is_secure_below_el3(env
) &&
2403 (env
->cp15
.hstr_el2
& HSTR_TTEE
)) {
2404 return CP_ACCESS_TRAP_EL2
;
2406 return CP_ACCESS_OK
;
2409 static CPAccessResult
teehbr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2412 if (arm_current_el(env
) == 0 && (env
->teecr
& 1)) {
2413 return CP_ACCESS_TRAP
;
2415 return teecr_access(env
, ri
, isread
);
2418 static const ARMCPRegInfo t2ee_cp_reginfo
[] = {
2419 { .name
= "TEECR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 6, .opc2
= 0,
2420 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, teecr
),
2422 .writefn
= teecr_write
, .accessfn
= teecr_access
},
2423 { .name
= "TEEHBR", .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 6, .opc2
= 0,
2424 .access
= PL0_RW
, .fieldoffset
= offsetof(CPUARMState
, teehbr
),
2425 .accessfn
= teehbr_access
, .resetvalue
= 0 },
2428 static const ARMCPRegInfo v6k_cp_reginfo
[] = {
2429 { .name
= "TPIDR_EL0", .state
= ARM_CP_STATE_AA64
,
2430 .opc0
= 3, .opc1
= 3, .opc2
= 2, .crn
= 13, .crm
= 0,
2432 .fgt
= FGT_TPIDR_EL0
,
2433 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[0]), .resetvalue
= 0 },
2434 { .name
= "TPIDRURW", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 2,
2436 .fgt
= FGT_TPIDR_EL0
,
2437 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrurw_s
),
2438 offsetoflow32(CPUARMState
, cp15
.tpidrurw_ns
) },
2439 .resetfn
= arm_cp_reset_ignore
},
2440 { .name
= "TPIDRRO_EL0", .state
= ARM_CP_STATE_AA64
,
2441 .opc0
= 3, .opc1
= 3, .opc2
= 3, .crn
= 13, .crm
= 0,
2442 .access
= PL0_R
| PL1_W
,
2443 .fgt
= FGT_TPIDRRO_EL0
,
2444 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidrro_el
[0]),
2446 { .name
= "TPIDRURO", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 3,
2447 .access
= PL0_R
| PL1_W
,
2448 .fgt
= FGT_TPIDRRO_EL0
,
2449 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidruro_s
),
2450 offsetoflow32(CPUARMState
, cp15
.tpidruro_ns
) },
2451 .resetfn
= arm_cp_reset_ignore
},
2452 { .name
= "TPIDR_EL1", .state
= ARM_CP_STATE_AA64
,
2453 .opc0
= 3, .opc1
= 0, .opc2
= 4, .crn
= 13, .crm
= 0,
2455 .fgt
= FGT_TPIDR_EL1
,
2456 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[1]), .resetvalue
= 0 },
2457 { .name
= "TPIDRPRW", .opc1
= 0, .cp
= 15, .crn
= 13, .crm
= 0, .opc2
= 4,
2459 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrprw_s
),
2460 offsetoflow32(CPUARMState
, cp15
.tpidrprw_ns
) },
2464 #ifndef CONFIG_USER_ONLY
2466 static CPAccessResult
gt_cntfrq_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2470 * CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero.
2471 * Writable only at the highest implemented exception level.
2473 int el
= arm_current_el(env
);
2479 hcr
= arm_hcr_el2_eff(env
);
2480 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2481 cntkctl
= env
->cp15
.cnthctl_el2
;
2483 cntkctl
= env
->cp15
.c14_cntkctl
;
2485 if (!extract32(cntkctl
, 0, 2)) {
2486 return CP_ACCESS_TRAP
;
2490 if (!isread
&& ri
->state
== ARM_CP_STATE_AA32
&&
2491 arm_is_secure_below_el3(env
)) {
2492 /* Accesses from 32-bit Secure EL1 UNDEF (*not* trap to EL3!) */
2493 return CP_ACCESS_TRAP_UNCATEGORIZED
;
2501 if (!isread
&& el
< arm_highest_el(env
)) {
2502 return CP_ACCESS_TRAP_UNCATEGORIZED
;
2505 return CP_ACCESS_OK
;
2508 static CPAccessResult
gt_counter_access(CPUARMState
*env
, int timeridx
,
2511 unsigned int cur_el
= arm_current_el(env
);
2512 bool has_el2
= arm_is_el2_enabled(env
);
2513 uint64_t hcr
= arm_hcr_el2_eff(env
);
2517 /* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]CTEN. */
2518 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2519 return (extract32(env
->cp15
.cnthctl_el2
, timeridx
, 1)
2520 ? CP_ACCESS_OK
: CP_ACCESS_TRAP_EL2
);
2523 /* CNT[PV]CT: not visible from PL0 if EL0[PV]CTEN is zero */
2524 if (!extract32(env
->cp15
.c14_cntkctl
, timeridx
, 1)) {
2525 return CP_ACCESS_TRAP
;
2529 /* Check CNTHCTL_EL2.EL1PCTEN, which changes location based on E2H. */
2530 if (has_el2
&& timeridx
== GTIMER_PHYS
&&
2532 ? !extract32(env
->cp15
.cnthctl_el2
, 10, 1)
2533 : !extract32(env
->cp15
.cnthctl_el2
, 0, 1))) {
2534 return CP_ACCESS_TRAP_EL2
;
2536 if (has_el2
&& timeridx
== GTIMER_VIRT
) {
2537 if (FIELD_EX64(env
->cp15
.cnthctl_el2
, CNTHCTL
, EL1TVCT
)) {
2538 return CP_ACCESS_TRAP_EL2
;
2543 return CP_ACCESS_OK
;
2546 static CPAccessResult
gt_timer_access(CPUARMState
*env
, int timeridx
,
2549 unsigned int cur_el
= arm_current_el(env
);
2550 bool has_el2
= arm_is_el2_enabled(env
);
2551 uint64_t hcr
= arm_hcr_el2_eff(env
);
2555 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2556 /* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]TEN. */
2557 return (extract32(env
->cp15
.cnthctl_el2
, 9 - timeridx
, 1)
2558 ? CP_ACCESS_OK
: CP_ACCESS_TRAP_EL2
);
2562 * CNT[PV]_CVAL, CNT[PV]_CTL, CNT[PV]_TVAL: not visible from
2563 * EL0 if EL0[PV]TEN is zero.
2565 if (!extract32(env
->cp15
.c14_cntkctl
, 9 - timeridx
, 1)) {
2566 return CP_ACCESS_TRAP
;
2571 if (has_el2
&& timeridx
== GTIMER_PHYS
) {
2572 if (hcr
& HCR_E2H
) {
2573 /* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PTEN. */
2574 if (!extract32(env
->cp15
.cnthctl_el2
, 11, 1)) {
2575 return CP_ACCESS_TRAP_EL2
;
2578 /* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */
2579 if (!extract32(env
->cp15
.cnthctl_el2
, 1, 1)) {
2580 return CP_ACCESS_TRAP_EL2
;
2584 if (has_el2
&& timeridx
== GTIMER_VIRT
) {
2585 if (FIELD_EX64(env
->cp15
.cnthctl_el2
, CNTHCTL
, EL1TVT
)) {
2586 return CP_ACCESS_TRAP_EL2
;
2591 return CP_ACCESS_OK
;
2594 static CPAccessResult
gt_pct_access(CPUARMState
*env
,
2595 const ARMCPRegInfo
*ri
,
2598 return gt_counter_access(env
, GTIMER_PHYS
, isread
);
2601 static CPAccessResult
gt_vct_access(CPUARMState
*env
,
2602 const ARMCPRegInfo
*ri
,
2605 return gt_counter_access(env
, GTIMER_VIRT
, isread
);
2608 static CPAccessResult
gt_ptimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2611 return gt_timer_access(env
, GTIMER_PHYS
, isread
);
2614 static CPAccessResult
gt_vtimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2617 return gt_timer_access(env
, GTIMER_VIRT
, isread
);
2620 static CPAccessResult
gt_stimer_access(CPUARMState
*env
,
2621 const ARMCPRegInfo
*ri
,
2625 * The AArch64 register view of the secure physical timer is
2626 * always accessible from EL3, and configurably accessible from
2629 switch (arm_current_el(env
)) {
2631 if (!arm_is_secure(env
)) {
2632 return CP_ACCESS_TRAP
;
2634 if (!(env
->cp15
.scr_el3
& SCR_ST
)) {
2635 return CP_ACCESS_TRAP_EL3
;
2637 return CP_ACCESS_OK
;
2640 return CP_ACCESS_TRAP
;
2642 return CP_ACCESS_OK
;
2644 g_assert_not_reached();
2648 static uint64_t gt_get_countervalue(CPUARMState
*env
)
2650 ARMCPU
*cpu
= env_archcpu(env
);
2652 return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) / gt_cntfrq_period_ns(cpu
);
2655 static void gt_update_irq(ARMCPU
*cpu
, int timeridx
)
2657 CPUARMState
*env
= &cpu
->env
;
2658 uint64_t cnthctl
= env
->cp15
.cnthctl_el2
;
2659 ARMSecuritySpace ss
= arm_security_space(env
);
2660 /* ISTATUS && !IMASK */
2661 int irqstate
= (env
->cp15
.c14_timer
[timeridx
].ctl
& 6) == 4;
2664 * If bit CNTHCTL_EL2.CNT[VP]MASK is set, it overrides IMASK.
2665 * It is RES0 in Secure and NonSecure state.
2667 if ((ss
== ARMSS_Root
|| ss
== ARMSS_Realm
) &&
2668 ((timeridx
== GTIMER_VIRT
&& (cnthctl
& R_CNTHCTL_CNTVMASK_MASK
)) ||
2669 (timeridx
== GTIMER_PHYS
&& (cnthctl
& R_CNTHCTL_CNTPMASK_MASK
)))) {
2673 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], irqstate
);
2674 trace_arm_gt_update_irq(timeridx
, irqstate
);
2677 void gt_rme_post_el_change(ARMCPU
*cpu
, void *ignored
)
2680 * Changing security state between Root and Secure/NonSecure, which may
2681 * happen when switching EL, can change the effective value of CNTHCTL_EL2
2682 * mask bits. Update the IRQ state accordingly.
2684 gt_update_irq(cpu
, GTIMER_VIRT
);
2685 gt_update_irq(cpu
, GTIMER_PHYS
);
2688 static uint64_t gt_phys_raw_cnt_offset(CPUARMState
*env
)
2690 if ((env
->cp15
.scr_el3
& SCR_ECVEN
) &&
2691 FIELD_EX64(env
->cp15
.cnthctl_el2
, CNTHCTL
, ECV
) &&
2692 arm_is_el2_enabled(env
) &&
2693 (arm_hcr_el2_eff(env
) & (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
2694 return env
->cp15
.cntpoff_el2
;
2699 static uint64_t gt_phys_cnt_offset(CPUARMState
*env
)
2701 if (arm_current_el(env
) >= 2) {
2704 return gt_phys_raw_cnt_offset(env
);
2707 static void gt_recalc_timer(ARMCPU
*cpu
, int timeridx
)
2709 ARMGenericTimer
*gt
= &cpu
->env
.cp15
.c14_timer
[timeridx
];
2713 * Timer enabled: calculate and set current ISTATUS, irq, and
2714 * reset timer to when ISTATUS next has to change
2716 uint64_t offset
= timeridx
== GTIMER_VIRT
?
2717 cpu
->env
.cp15
.cntvoff_el2
: gt_phys_raw_cnt_offset(&cpu
->env
);
2718 uint64_t count
= gt_get_countervalue(&cpu
->env
);
2719 /* Note that this must be unsigned 64 bit arithmetic: */
2720 int istatus
= count
- offset
>= gt
->cval
;
2723 gt
->ctl
= deposit32(gt
->ctl
, 2, 1, istatus
);
2727 * Next transition is when (count - offset) rolls back over to 0.
2728 * If offset > count then this is when count == offset;
2729 * if offset <= count then this is when count == offset + 2^64
2730 * For the latter case we set nexttick to an "as far in future
2731 * as possible" value and let the code below handle it.
2733 if (offset
> count
) {
2736 nexttick
= UINT64_MAX
;
2740 * Next transition is when (count - offset) == cval, i.e.
2741 * when count == (cval + offset).
2742 * If that would overflow, then again we set up the next interrupt
2743 * for "as far in the future as possible" for the code below.
2745 if (uadd64_overflow(gt
->cval
, offset
, &nexttick
)) {
2746 nexttick
= UINT64_MAX
;
2750 * Note that the desired next expiry time might be beyond the
2751 * signed-64-bit range of a QEMUTimer -- in this case we just
2752 * set the timer for as far in the future as possible. When the
2753 * timer expires we will reset the timer for any remaining period.
2755 if (nexttick
> INT64_MAX
/ gt_cntfrq_period_ns(cpu
)) {
2756 timer_mod_ns(cpu
->gt_timer
[timeridx
], INT64_MAX
);
2758 timer_mod(cpu
->gt_timer
[timeridx
], nexttick
);
2760 trace_arm_gt_recalc(timeridx
, nexttick
);
2762 /* Timer disabled: ISTATUS and timer output always clear */
2764 timer_del(cpu
->gt_timer
[timeridx
]);
2765 trace_arm_gt_recalc_disabled(timeridx
);
2767 gt_update_irq(cpu
, timeridx
);
2770 static void gt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2773 ARMCPU
*cpu
= env_archcpu(env
);
2775 timer_del(cpu
->gt_timer
[timeridx
]);
2778 static uint64_t gt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2780 return gt_get_countervalue(env
) - gt_phys_cnt_offset(env
);
2783 static uint64_t gt_virt_cnt_offset(CPUARMState
*env
)
2787 switch (arm_current_el(env
)) {
2789 hcr
= arm_hcr_el2_eff(env
);
2790 if (hcr
& HCR_E2H
) {
2795 hcr
= arm_hcr_el2_eff(env
);
2796 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2802 return env
->cp15
.cntvoff_el2
;
2805 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2807 return gt_get_countervalue(env
) - gt_virt_cnt_offset(env
);
2810 static void gt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2814 trace_arm_gt_cval_write(timeridx
, value
);
2815 env
->cp15
.c14_timer
[timeridx
].cval
= value
;
2816 gt_recalc_timer(env_archcpu(env
), timeridx
);
2819 static uint64_t gt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2822 uint64_t offset
= 0;
2826 case GTIMER_HYPVIRT
:
2827 offset
= gt_virt_cnt_offset(env
);
2830 offset
= gt_phys_cnt_offset(env
);
2834 return (uint32_t)(env
->cp15
.c14_timer
[timeridx
].cval
-
2835 (gt_get_countervalue(env
) - offset
));
2838 static void gt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2842 uint64_t offset
= 0;
2846 case GTIMER_HYPVIRT
:
2847 offset
= gt_virt_cnt_offset(env
);
2850 offset
= gt_phys_cnt_offset(env
);
2854 trace_arm_gt_tval_write(timeridx
, value
);
2855 env
->cp15
.c14_timer
[timeridx
].cval
= gt_get_countervalue(env
) - offset
+
2856 sextract64(value
, 0, 32);
2857 gt_recalc_timer(env_archcpu(env
), timeridx
);
2860 static void gt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2864 ARMCPU
*cpu
= env_archcpu(env
);
2865 uint32_t oldval
= env
->cp15
.c14_timer
[timeridx
].ctl
;
2867 trace_arm_gt_ctl_write(timeridx
, value
);
2868 env
->cp15
.c14_timer
[timeridx
].ctl
= deposit64(oldval
, 0, 2, value
);
2869 if ((oldval
^ value
) & 1) {
2870 /* Enable toggled */
2871 gt_recalc_timer(cpu
, timeridx
);
2872 } else if ((oldval
^ value
) & 2) {
2874 * IMASK toggled: don't need to recalculate,
2875 * just set the interrupt line based on ISTATUS
2877 trace_arm_gt_imask_toggle(timeridx
);
2878 gt_update_irq(cpu
, timeridx
);
2882 static void gt_phys_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2884 gt_timer_reset(env
, ri
, GTIMER_PHYS
);
2887 static void gt_phys_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2890 gt_cval_write(env
, ri
, GTIMER_PHYS
, value
);
2893 static uint64_t gt_phys_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2895 return gt_tval_read(env
, ri
, GTIMER_PHYS
);
2898 static void gt_phys_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2901 gt_tval_write(env
, ri
, GTIMER_PHYS
, value
);
2904 static void gt_phys_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2907 gt_ctl_write(env
, ri
, GTIMER_PHYS
, value
);
2910 static int gt_phys_redir_timeridx(CPUARMState
*env
)
2912 switch (arm_mmu_idx(env
)) {
2913 case ARMMMUIdx_E20_0
:
2914 case ARMMMUIdx_E20_2
:
2915 case ARMMMUIdx_E20_2_PAN
:
2922 static int gt_virt_redir_timeridx(CPUARMState
*env
)
2924 switch (arm_mmu_idx(env
)) {
2925 case ARMMMUIdx_E20_0
:
2926 case ARMMMUIdx_E20_2
:
2927 case ARMMMUIdx_E20_2_PAN
:
2928 return GTIMER_HYPVIRT
;
2934 static uint64_t gt_phys_redir_cval_read(CPUARMState
*env
,
2935 const ARMCPRegInfo
*ri
)
2937 int timeridx
= gt_phys_redir_timeridx(env
);
2938 return env
->cp15
.c14_timer
[timeridx
].cval
;
2941 static void gt_phys_redir_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2944 int timeridx
= gt_phys_redir_timeridx(env
);
2945 gt_cval_write(env
, ri
, timeridx
, value
);
2948 static uint64_t gt_phys_redir_tval_read(CPUARMState
*env
,
2949 const ARMCPRegInfo
*ri
)
2951 int timeridx
= gt_phys_redir_timeridx(env
);
2952 return gt_tval_read(env
, ri
, timeridx
);
2955 static void gt_phys_redir_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2958 int timeridx
= gt_phys_redir_timeridx(env
);
2959 gt_tval_write(env
, ri
, timeridx
, value
);
2962 static uint64_t gt_phys_redir_ctl_read(CPUARMState
*env
,
2963 const ARMCPRegInfo
*ri
)
2965 int timeridx
= gt_phys_redir_timeridx(env
);
2966 return env
->cp15
.c14_timer
[timeridx
].ctl
;
2969 static void gt_phys_redir_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2972 int timeridx
= gt_phys_redir_timeridx(env
);
2973 gt_ctl_write(env
, ri
, timeridx
, value
);
2976 static void gt_virt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2978 gt_timer_reset(env
, ri
, GTIMER_VIRT
);
2981 static void gt_virt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2984 gt_cval_write(env
, ri
, GTIMER_VIRT
, value
);
2987 static uint64_t gt_virt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2989 return gt_tval_read(env
, ri
, GTIMER_VIRT
);
2992 static void gt_virt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2995 gt_tval_write(env
, ri
, GTIMER_VIRT
, value
);
2998 static void gt_virt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3001 gt_ctl_write(env
, ri
, GTIMER_VIRT
, value
);
3004 static void gt_cnthctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3007 ARMCPU
*cpu
= env_archcpu(env
);
3008 uint32_t oldval
= env
->cp15
.cnthctl_el2
;
3009 uint32_t valid_mask
=
3010 R_CNTHCTL_EL0PCTEN_E2H1_MASK
|
3011 R_CNTHCTL_EL0VCTEN_E2H1_MASK
|
3012 R_CNTHCTL_EVNTEN_MASK
|
3013 R_CNTHCTL_EVNTDIR_MASK
|
3014 R_CNTHCTL_EVNTI_MASK
|
3015 R_CNTHCTL_EL0VTEN_MASK
|
3016 R_CNTHCTL_EL0PTEN_MASK
|
3017 R_CNTHCTL_EL1PCTEN_E2H1_MASK
|
3018 R_CNTHCTL_EL1PTEN_MASK
;
3020 if (cpu_isar_feature(aa64_rme
, cpu
)) {
3021 valid_mask
|= R_CNTHCTL_CNTVMASK_MASK
| R_CNTHCTL_CNTPMASK_MASK
;
3023 if (cpu_isar_feature(aa64_ecv_traps
, cpu
)) {
3025 R_CNTHCTL_EL1TVT_MASK
|
3026 R_CNTHCTL_EL1TVCT_MASK
|
3027 R_CNTHCTL_EL1NVPCT_MASK
|
3028 R_CNTHCTL_EL1NVVCT_MASK
|
3029 R_CNTHCTL_EVNTIS_MASK
;
3031 if (cpu_isar_feature(aa64_ecv
, cpu
)) {
3032 valid_mask
|= R_CNTHCTL_ECV_MASK
;
3035 /* Clear RES0 bits */
3036 value
&= valid_mask
;
3038 raw_write(env
, ri
, value
);
3040 if ((oldval
^ value
) & R_CNTHCTL_CNTVMASK_MASK
) {
3041 gt_update_irq(cpu
, GTIMER_VIRT
);
3042 } else if ((oldval
^ value
) & R_CNTHCTL_CNTPMASK_MASK
) {
3043 gt_update_irq(cpu
, GTIMER_PHYS
);
3047 static void gt_cntvoff_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3050 ARMCPU
*cpu
= env_archcpu(env
);
3052 trace_arm_gt_cntvoff_write(value
);
3053 raw_write(env
, ri
, value
);
3054 gt_recalc_timer(cpu
, GTIMER_VIRT
);
3057 static uint64_t gt_virt_redir_cval_read(CPUARMState
*env
,
3058 const ARMCPRegInfo
*ri
)
3060 int timeridx
= gt_virt_redir_timeridx(env
);
3061 return env
->cp15
.c14_timer
[timeridx
].cval
;
3064 static void gt_virt_redir_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3067 int timeridx
= gt_virt_redir_timeridx(env
);
3068 gt_cval_write(env
, ri
, timeridx
, value
);
3071 static uint64_t gt_virt_redir_tval_read(CPUARMState
*env
,
3072 const ARMCPRegInfo
*ri
)
3074 int timeridx
= gt_virt_redir_timeridx(env
);
3075 return gt_tval_read(env
, ri
, timeridx
);
3078 static void gt_virt_redir_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3081 int timeridx
= gt_virt_redir_timeridx(env
);
3082 gt_tval_write(env
, ri
, timeridx
, value
);
3085 static uint64_t gt_virt_redir_ctl_read(CPUARMState
*env
,
3086 const ARMCPRegInfo
*ri
)
3088 int timeridx
= gt_virt_redir_timeridx(env
);
3089 return env
->cp15
.c14_timer
[timeridx
].ctl
;
3092 static void gt_virt_redir_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3095 int timeridx
= gt_virt_redir_timeridx(env
);
3096 gt_ctl_write(env
, ri
, timeridx
, value
);
3099 static void gt_hyp_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3101 gt_timer_reset(env
, ri
, GTIMER_HYP
);
3104 static void gt_hyp_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3107 gt_cval_write(env
, ri
, GTIMER_HYP
, value
);
3110 static uint64_t gt_hyp_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3112 return gt_tval_read(env
, ri
, GTIMER_HYP
);
3115 static void gt_hyp_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3118 gt_tval_write(env
, ri
, GTIMER_HYP
, value
);
3121 static void gt_hyp_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3124 gt_ctl_write(env
, ri
, GTIMER_HYP
, value
);
3127 static void gt_sec_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3129 gt_timer_reset(env
, ri
, GTIMER_SEC
);
3132 static void gt_sec_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3135 gt_cval_write(env
, ri
, GTIMER_SEC
, value
);
3138 static uint64_t gt_sec_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3140 return gt_tval_read(env
, ri
, GTIMER_SEC
);
3143 static void gt_sec_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3146 gt_tval_write(env
, ri
, GTIMER_SEC
, value
);
3149 static void gt_sec_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3152 gt_ctl_write(env
, ri
, GTIMER_SEC
, value
);
3155 static void gt_hv_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3157 gt_timer_reset(env
, ri
, GTIMER_HYPVIRT
);
3160 static void gt_hv_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3163 gt_cval_write(env
, ri
, GTIMER_HYPVIRT
, value
);
3166 static uint64_t gt_hv_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3168 return gt_tval_read(env
, ri
, GTIMER_HYPVIRT
);
3171 static void gt_hv_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3174 gt_tval_write(env
, ri
, GTIMER_HYPVIRT
, value
);
3177 static void gt_hv_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3180 gt_ctl_write(env
, ri
, GTIMER_HYPVIRT
, value
);
3183 void arm_gt_ptimer_cb(void *opaque
)
3185 ARMCPU
*cpu
= opaque
;
3187 gt_recalc_timer(cpu
, GTIMER_PHYS
);
3190 void arm_gt_vtimer_cb(void *opaque
)
3192 ARMCPU
*cpu
= opaque
;
3194 gt_recalc_timer(cpu
, GTIMER_VIRT
);
3197 void arm_gt_htimer_cb(void *opaque
)
3199 ARMCPU
*cpu
= opaque
;
3201 gt_recalc_timer(cpu
, GTIMER_HYP
);
3204 void arm_gt_stimer_cb(void *opaque
)
3206 ARMCPU
*cpu
= opaque
;
3208 gt_recalc_timer(cpu
, GTIMER_SEC
);
3211 void arm_gt_hvtimer_cb(void *opaque
)
3213 ARMCPU
*cpu
= opaque
;
3215 gt_recalc_timer(cpu
, GTIMER_HYPVIRT
);
3218 static void arm_gt_cntfrq_reset(CPUARMState
*env
, const ARMCPRegInfo
*opaque
)
3220 ARMCPU
*cpu
= env_archcpu(env
);
3222 cpu
->env
.cp15
.c14_cntfrq
= cpu
->gt_cntfrq_hz
;
3225 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
3227 * Note that CNTFRQ is purely reads-as-written for the benefit
3228 * of software; writing it doesn't actually change the timer frequency.
3229 * Our reset value matches the fixed frequency we implement the timer at.
3231 { .name
= "CNTFRQ", .cp
= 15, .crn
= 14, .crm
= 0, .opc1
= 0, .opc2
= 0,
3232 .type
= ARM_CP_ALIAS
,
3233 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
3234 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c14_cntfrq
),
3236 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
3237 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
3238 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
3239 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
3240 .resetfn
= arm_gt_cntfrq_reset
,
3242 /* overall control: mostly access permissions */
3243 { .name
= "CNTKCTL", .state
= ARM_CP_STATE_BOTH
,
3244 .opc0
= 3, .opc1
= 0, .crn
= 14, .crm
= 1, .opc2
= 0,
3246 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntkctl
),
3249 /* per-timer control */
3250 { .name
= "CNTP_CTL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
3251 .secure
= ARM_CP_SECSTATE_NS
,
3252 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
3253 .accessfn
= gt_ptimer_access
,
3254 .fieldoffset
= offsetoflow32(CPUARMState
,
3255 cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
3256 .readfn
= gt_phys_redir_ctl_read
, .raw_readfn
= raw_read
,
3257 .writefn
= gt_phys_redir_ctl_write
, .raw_writefn
= raw_write
,
3259 { .name
= "CNTP_CTL_S",
3260 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
3261 .secure
= ARM_CP_SECSTATE_S
,
3262 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
3263 .accessfn
= gt_ptimer_access
,
3264 .fieldoffset
= offsetoflow32(CPUARMState
,
3265 cp15
.c14_timer
[GTIMER_SEC
].ctl
),
3266 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
3268 { .name
= "CNTP_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
3269 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 1,
3270 .type
= ARM_CP_IO
, .access
= PL0_RW
,
3271 .accessfn
= gt_ptimer_access
,
3272 .nv2_redirect_offset
= 0x180 | NV2_REDIR_NV1
,
3273 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
3275 .readfn
= gt_phys_redir_ctl_read
, .raw_readfn
= raw_read
,
3276 .writefn
= gt_phys_redir_ctl_write
, .raw_writefn
= raw_write
,
3278 { .name
= "CNTV_CTL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 1,
3279 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
3280 .accessfn
= gt_vtimer_access
,
3281 .fieldoffset
= offsetoflow32(CPUARMState
,
3282 cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
3283 .readfn
= gt_virt_redir_ctl_read
, .raw_readfn
= raw_read
,
3284 .writefn
= gt_virt_redir_ctl_write
, .raw_writefn
= raw_write
,
3286 { .name
= "CNTV_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
3287 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 1,
3288 .type
= ARM_CP_IO
, .access
= PL0_RW
,
3289 .accessfn
= gt_vtimer_access
,
3290 .nv2_redirect_offset
= 0x170 | NV2_REDIR_NV1
,
3291 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
3293 .readfn
= gt_virt_redir_ctl_read
, .raw_readfn
= raw_read
,
3294 .writefn
= gt_virt_redir_ctl_write
, .raw_writefn
= raw_write
,
3296 /* TimerValue views: a 32 bit downcounting view of the underlying state */
3297 { .name
= "CNTP_TVAL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
3298 .secure
= ARM_CP_SECSTATE_NS
,
3299 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3300 .accessfn
= gt_ptimer_access
,
3301 .readfn
= gt_phys_redir_tval_read
, .writefn
= gt_phys_redir_tval_write
,
3303 { .name
= "CNTP_TVAL_S",
3304 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
3305 .secure
= ARM_CP_SECSTATE_S
,
3306 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3307 .accessfn
= gt_ptimer_access
,
3308 .readfn
= gt_sec_tval_read
, .writefn
= gt_sec_tval_write
,
3310 { .name
= "CNTP_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3311 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 0,
3312 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3313 .accessfn
= gt_ptimer_access
, .resetfn
= gt_phys_timer_reset
,
3314 .readfn
= gt_phys_redir_tval_read
, .writefn
= gt_phys_redir_tval_write
,
3316 { .name
= "CNTV_TVAL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 0,
3317 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3318 .accessfn
= gt_vtimer_access
,
3319 .readfn
= gt_virt_redir_tval_read
, .writefn
= gt_virt_redir_tval_write
,
3321 { .name
= "CNTV_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3322 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 0,
3323 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3324 .accessfn
= gt_vtimer_access
, .resetfn
= gt_virt_timer_reset
,
3325 .readfn
= gt_virt_redir_tval_read
, .writefn
= gt_virt_redir_tval_write
,
3327 /* The counter itself */
3328 { .name
= "CNTPCT", .cp
= 15, .crm
= 14, .opc1
= 0,
3329 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3330 .accessfn
= gt_pct_access
,
3331 .readfn
= gt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3333 { .name
= "CNTPCT_EL0", .state
= ARM_CP_STATE_AA64
,
3334 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 1,
3335 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3336 .accessfn
= gt_pct_access
, .readfn
= gt_cnt_read
,
3338 { .name
= "CNTVCT", .cp
= 15, .crm
= 14, .opc1
= 1,
3339 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3340 .accessfn
= gt_vct_access
,
3341 .readfn
= gt_virt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3343 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
3344 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
3345 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3346 .accessfn
= gt_vct_access
, .readfn
= gt_virt_cnt_read
,
3348 /* Comparison value, indicating when the timer goes off */
3349 { .name
= "CNTP_CVAL", .cp
= 15, .crm
= 14, .opc1
= 2,
3350 .secure
= ARM_CP_SECSTATE_NS
,
3352 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3353 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
3354 .accessfn
= gt_ptimer_access
,
3355 .readfn
= gt_phys_redir_cval_read
, .raw_readfn
= raw_read
,
3356 .writefn
= gt_phys_redir_cval_write
, .raw_writefn
= raw_write
,
3358 { .name
= "CNTP_CVAL_S", .cp
= 15, .crm
= 14, .opc1
= 2,
3359 .secure
= ARM_CP_SECSTATE_S
,
3361 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3362 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
3363 .accessfn
= gt_ptimer_access
,
3364 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
3366 { .name
= "CNTP_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3367 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 2,
3370 .nv2_redirect_offset
= 0x178 | NV2_REDIR_NV1
,
3371 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
3372 .resetvalue
= 0, .accessfn
= gt_ptimer_access
,
3373 .readfn
= gt_phys_redir_cval_read
, .raw_readfn
= raw_read
,
3374 .writefn
= gt_phys_redir_cval_write
, .raw_writefn
= raw_write
,
3376 { .name
= "CNTV_CVAL", .cp
= 15, .crm
= 14, .opc1
= 3,
3378 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3379 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
3380 .accessfn
= gt_vtimer_access
,
3381 .readfn
= gt_virt_redir_cval_read
, .raw_readfn
= raw_read
,
3382 .writefn
= gt_virt_redir_cval_write
, .raw_writefn
= raw_write
,
3384 { .name
= "CNTV_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3385 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 2,
3388 .nv2_redirect_offset
= 0x168 | NV2_REDIR_NV1
,
3389 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
3390 .resetvalue
= 0, .accessfn
= gt_vtimer_access
,
3391 .readfn
= gt_virt_redir_cval_read
, .raw_readfn
= raw_read
,
3392 .writefn
= gt_virt_redir_cval_write
, .raw_writefn
= raw_write
,
3395 * Secure timer -- this is actually restricted to only EL3
3396 * and configurably Secure-EL1 via the accessfn.
3398 { .name
= "CNTPS_TVAL_EL1", .state
= ARM_CP_STATE_AA64
,
3399 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 0,
3400 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
,
3401 .accessfn
= gt_stimer_access
,
3402 .readfn
= gt_sec_tval_read
,
3403 .writefn
= gt_sec_tval_write
,
3404 .resetfn
= gt_sec_timer_reset
,
3406 { .name
= "CNTPS_CTL_EL1", .state
= ARM_CP_STATE_AA64
,
3407 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 1,
3408 .type
= ARM_CP_IO
, .access
= PL1_RW
,
3409 .accessfn
= gt_stimer_access
,
3410 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].ctl
),
3412 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
3414 { .name
= "CNTPS_CVAL_EL1", .state
= ARM_CP_STATE_AA64
,
3415 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 2,
3416 .type
= ARM_CP_IO
, .access
= PL1_RW
,
3417 .accessfn
= gt_stimer_access
,
3418 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
3419 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
3424 * FEAT_ECV adds extra views of CNTVCT_EL0 and CNTPCT_EL0 which
3425 * are "self-synchronizing". For QEMU all sysregs are self-synchronizing,
3426 * so our implementations here are identical to the normal registers.
3428 static const ARMCPRegInfo gen_timer_ecv_cp_reginfo
[] = {
3429 { .name
= "CNTVCTSS", .cp
= 15, .crm
= 14, .opc1
= 9,
3430 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3431 .accessfn
= gt_vct_access
,
3432 .readfn
= gt_virt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3434 { .name
= "CNTVCTSS_EL0", .state
= ARM_CP_STATE_AA64
,
3435 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 6,
3436 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3437 .accessfn
= gt_vct_access
, .readfn
= gt_virt_cnt_read
,
3439 { .name
= "CNTPCTSS", .cp
= 15, .crm
= 14, .opc1
= 8,
3440 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3441 .accessfn
= gt_pct_access
,
3442 .readfn
= gt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3444 { .name
= "CNTPCTSS_EL0", .state
= ARM_CP_STATE_AA64
,
3445 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 5,
3446 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3447 .accessfn
= gt_pct_access
, .readfn
= gt_cnt_read
,
3451 static CPAccessResult
gt_cntpoff_access(CPUARMState
*env
,
3452 const ARMCPRegInfo
*ri
,
3455 if (arm_current_el(env
) == 2 && !(env
->cp15
.scr_el3
& SCR_ECVEN
)) {
3456 return CP_ACCESS_TRAP_EL3
;
3458 return CP_ACCESS_OK
;
3461 static void gt_cntpoff_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3464 ARMCPU
*cpu
= env_archcpu(env
);
3466 trace_arm_gt_cntpoff_write(value
);
3467 raw_write(env
, ri
, value
);
3468 gt_recalc_timer(cpu
, GTIMER_PHYS
);
3471 static const ARMCPRegInfo gen_timer_cntpoff_reginfo
= {
3472 .name
= "CNTPOFF_EL2", .state
= ARM_CP_STATE_AA64
,
3473 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 0, .opc2
= 6,
3474 .access
= PL2_RW
, .type
= ARM_CP_IO
, .resetvalue
= 0,
3475 .accessfn
= gt_cntpoff_access
, .writefn
= gt_cntpoff_write
,
3476 .nv2_redirect_offset
= 0x1a8,
3477 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntpoff_el2
),
3482 * In user-mode most of the generic timer registers are inaccessible
3483 * however modern kernels (4.12+) allow access to cntvct_el0
3486 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3488 ARMCPU
*cpu
= env_archcpu(env
);
3491 * Currently we have no support for QEMUTimer in linux-user so we
3492 * can't call gt_get_countervalue(env), instead we directly
3493 * call the lower level functions.
3495 return cpu_get_clock() / gt_cntfrq_period_ns(cpu
);
3498 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
3499 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
3500 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
3501 .type
= ARM_CP_CONST
, .access
= PL0_R
/* no PL1_RW in linux-user */,
3502 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
3503 .resetvalue
= NANOSECONDS_PER_SECOND
/ GTIMER_SCALE
,
3505 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
3506 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
3507 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3508 .readfn
= gt_virt_cnt_read
,
3513 * CNTVCTSS_EL0 has the same trap conditions as CNTVCT_EL0, so it also
3514 * is exposed to userspace by Linux.
3516 static const ARMCPRegInfo gen_timer_ecv_cp_reginfo
[] = {
3517 { .name
= "CNTVCTSS_EL0", .state
= ARM_CP_STATE_AA64
,
3518 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 6,
3519 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3520 .readfn
= gt_virt_cnt_read
,
3526 static void par_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
3528 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3529 raw_write(env
, ri
, value
);
3530 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
3531 raw_write(env
, ri
, value
& 0xfffff6ff);
3533 raw_write(env
, ri
, value
& 0xfffff1ff);
3537 #ifndef CONFIG_USER_ONLY
3538 /* get_phys_addr() isn't present for user-mode-only targets */
3540 static CPAccessResult
ats_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3545 * The ATS12NSO* operations must trap to EL3 or EL2 if executed in
3546 * Secure EL1 (which can only happen if EL3 is AArch64).
3547 * They are simply UNDEF if executed from NS EL1.
3548 * They function normally from EL2 or EL3.
3550 if (arm_current_el(env
) == 1) {
3551 if (arm_is_secure_below_el3(env
)) {
3552 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
3553 return CP_ACCESS_TRAP_EL2
;
3555 return CP_ACCESS_TRAP_EL3
;
3557 return CP_ACCESS_TRAP_UNCATEGORIZED
;
3560 return CP_ACCESS_OK
;
3564 static int par_el1_shareability(GetPhysAddrResult
*res
)
3567 * The PAR_EL1.SH field must be 0b10 for Device or Normal-NC
3568 * memory -- see pseudocode PAREncodeShareability().
3570 if (((res
->cacheattrs
.attrs
& 0xf0) == 0) ||
3571 res
->cacheattrs
.attrs
== 0x44 || res
->cacheattrs
.attrs
== 0x40) {
3574 return res
->cacheattrs
.shareability
;
3577 static uint64_t do_ats_write(CPUARMState
*env
, uint64_t value
,
3578 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
3579 ARMSecuritySpace ss
)
3583 bool format64
= false;
3584 ARMMMUFaultInfo fi
= {};
3585 GetPhysAddrResult res
= {};
3588 * I_MXTJT: Granule protection checks are not performed on the final address
3589 * of a successful translation.
3591 ret
= get_phys_addr_with_space_nogpc(env
, value
, access_type
, mmu_idx
, ss
,
3595 * ATS operations only do S1 or S1+S2 translations, so we never
3596 * have to deal with the ARMCacheAttrs format for S2 only.
3598 assert(!res
.cacheattrs
.is_s2_format
);
3602 * Some kinds of translation fault must cause exceptions rather
3603 * than being reported in the PAR.
3605 int current_el
= arm_current_el(env
);
3607 uint32_t syn
, fsr
, fsc
;
3608 bool take_exc
= false;
3610 if (fi
.s1ptw
&& current_el
== 1
3611 && arm_mmu_idx_is_stage1_of_2(mmu_idx
)) {
3613 * Synchronous stage 2 fault on an access made as part of the
3614 * translation table walk for AT S1E0* or AT S1E1* insn
3615 * executed from NS EL1. If this is a synchronous external abort
3616 * and SCR_EL3.EA == 1, then we take a synchronous external abort
3617 * to EL3. Otherwise the fault is taken as an exception to EL2,
3618 * and HPFAR_EL2 holds the faulting IPA.
3620 if (fi
.type
== ARMFault_SyncExternalOnWalk
&&
3621 (env
->cp15
.scr_el3
& SCR_EA
)) {
3624 env
->cp15
.hpfar_el2
= extract64(fi
.s2addr
, 12, 47) << 4;
3625 if (arm_is_secure_below_el3(env
) && fi
.s1ns
) {
3626 env
->cp15
.hpfar_el2
|= HPFAR_NS
;
3631 } else if (fi
.type
== ARMFault_SyncExternalOnWalk
) {
3633 * Synchronous external aborts during a translation table walk
3634 * are taken as Data Abort exceptions.
3637 if (current_el
== 3) {
3643 target_el
= exception_target_el(env
);
3649 /* Construct FSR and FSC using same logic as arm_deliver_fault() */
3650 if (target_el
== 2 || arm_el_is_aa64(env
, target_el
) ||
3651 arm_s1_regime_using_lpae_format(env
, mmu_idx
)) {
3652 fsr
= arm_fi_to_lfsc(&fi
);
3653 fsc
= extract32(fsr
, 0, 6);
3655 fsr
= arm_fi_to_sfsc(&fi
);
3659 * Report exception with ESR indicating a fault due to a
3660 * translation table walk for a cache maintenance instruction.
3662 syn
= syn_data_abort_no_iss(current_el
== target_el
, 0,
3663 fi
.ea
, 1, fi
.s1ptw
, 1, fsc
);
3664 env
->exception
.vaddress
= value
;
3665 env
->exception
.fsr
= fsr
;
3666 raise_exception(env
, EXCP_DATA_ABORT
, syn
, target_el
);
3672 } else if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3675 * * TTBCR.EAE determines whether the result is returned using the
3676 * 32-bit or the 64-bit PAR format
3677 * * Instructions executed in Hyp mode always use the 64bit format
3679 * ATS1S2NSOxx uses the 64bit format if any of the following is true:
3680 * * The Non-secure TTBCR.EAE bit is set to 1
3681 * * The implementation includes EL2, and the value of HCR.VM is 1
3683 * (Note that HCR.DC makes HCR.VM behave as if it is 1.)
3685 * ATS1Hx always uses the 64bit format.
3687 format64
= arm_s1_regime_using_lpae_format(env
, mmu_idx
);
3689 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
3690 if (mmu_idx
== ARMMMUIdx_E10_0
||
3691 mmu_idx
== ARMMMUIdx_E10_1
||
3692 mmu_idx
== ARMMMUIdx_E10_1_PAN
) {
3693 format64
|= env
->cp15
.hcr_el2
& (HCR_VM
| HCR_DC
);
3695 format64
|= arm_current_el(env
) == 2;
3701 /* Create a 64-bit PAR */
3702 par64
= (1 << 11); /* LPAE bit always set */
3704 par64
|= res
.f
.phys_addr
& ~0xfffULL
;
3705 if (!res
.f
.attrs
.secure
) {
3706 par64
|= (1 << 9); /* NS */
3708 par64
|= (uint64_t)res
.cacheattrs
.attrs
<< 56; /* ATTR */
3709 par64
|= par_el1_shareability(&res
) << 7; /* SH */
3711 uint32_t fsr
= arm_fi_to_lfsc(&fi
);
3714 par64
|= (fsr
& 0x3f) << 1; /* FS */
3716 par64
|= (1 << 9); /* S */
3719 par64
|= (1 << 8); /* PTW */
3724 * fsr is a DFSR/IFSR value for the short descriptor
3725 * translation table format (with WnR always clear).
3726 * Convert it to a 32-bit PAR.
3729 /* We do not set any attribute bits in the PAR */
3730 if (res
.f
.lg_page_size
== 24
3731 && arm_feature(env
, ARM_FEATURE_V7
)) {
3732 par64
= (res
.f
.phys_addr
& 0xff000000) | (1 << 1);
3734 par64
= res
.f
.phys_addr
& 0xfffff000;
3736 if (!res
.f
.attrs
.secure
) {
3737 par64
|= (1 << 9); /* NS */
3740 uint32_t fsr
= arm_fi_to_sfsc(&fi
);
3742 par64
= ((fsr
& (1 << 10)) >> 5) | ((fsr
& (1 << 12)) >> 6) |
3743 ((fsr
& 0xf) << 1) | 1;
3748 #endif /* CONFIG_TCG */
3750 static void ats_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
3753 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3756 int el
= arm_current_el(env
);
3757 ARMSecuritySpace ss
= arm_security_space(env
);
3759 switch (ri
->opc2
& 6) {
3761 /* stage 1 current state PL1: ATS1CPR, ATS1CPW, ATS1CPRP, ATS1CPWP */
3764 mmu_idx
= ARMMMUIdx_E3
;
3767 g_assert(ss
!= ARMSS_Secure
); /* ARMv8.4-SecEL2 is 64-bit only */
3770 if (ri
->crm
== 9 && arm_pan_enabled(env
)) {
3771 mmu_idx
= ARMMMUIdx_Stage1_E1_PAN
;
3773 mmu_idx
= ARMMMUIdx_Stage1_E1
;
3777 g_assert_not_reached();
3781 /* stage 1 current state PL0: ATS1CUR, ATS1CUW */
3784 mmu_idx
= ARMMMUIdx_E10_0
;
3787 g_assert(ss
!= ARMSS_Secure
); /* ARMv8.4-SecEL2 is 64-bit only */
3788 mmu_idx
= ARMMMUIdx_Stage1_E0
;
3791 mmu_idx
= ARMMMUIdx_Stage1_E0
;
3794 g_assert_not_reached();
3798 /* stage 1+2 NonSecure PL1: ATS12NSOPR, ATS12NSOPW */
3799 mmu_idx
= ARMMMUIdx_E10_1
;
3800 ss
= ARMSS_NonSecure
;
3803 /* stage 1+2 NonSecure PL0: ATS12NSOUR, ATS12NSOUW */
3804 mmu_idx
= ARMMMUIdx_E10_0
;
3805 ss
= ARMSS_NonSecure
;
3808 g_assert_not_reached();
3811 par64
= do_ats_write(env
, value
, access_type
, mmu_idx
, ss
);
3813 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
3815 /* Handled by hardware accelerator. */
3816 g_assert_not_reached();
3817 #endif /* CONFIG_TCG */
3820 static void ats1h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3824 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3827 /* There is no SecureEL2 for AArch32. */
3828 par64
= do_ats_write(env
, value
, access_type
, ARMMMUIdx_E2
,
3831 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
3833 /* Handled by hardware accelerator. */
3834 g_assert_not_reached();
3835 #endif /* CONFIG_TCG */
3838 static CPAccessResult
at_e012_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3842 * R_NYXTL: instruction is UNDEFINED if it applies to an Exception level
3843 * lower than EL3 and the combination SCR_EL3.{NSE,NS} is reserved. This can
3844 * only happen when executing at EL3 because that combination also causes an
3845 * illegal exception return. We don't need to check FEAT_RME either, because
3846 * scr_write() ensures that the NSE bit is not set otherwise.
3848 if ((env
->cp15
.scr_el3
& (SCR_NSE
| SCR_NS
)) == SCR_NSE
) {
3849 return CP_ACCESS_TRAP
;
3851 return CP_ACCESS_OK
;
3854 static CPAccessResult
at_s1e2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3857 if (arm_current_el(env
) == 3 &&
3858 !(env
->cp15
.scr_el3
& (SCR_NS
| SCR_EEL2
))) {
3859 return CP_ACCESS_TRAP
;
3861 return at_e012_access(env
, ri
, isread
);
3864 static CPAccessResult
at_s1e01_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3867 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_AT
)) {
3868 return CP_ACCESS_TRAP_EL2
;
3870 return at_e012_access(env
, ri
, isread
);
3873 static void ats_write64(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3877 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3879 uint64_t hcr_el2
= arm_hcr_el2_eff(env
);
3880 bool regime_e20
= (hcr_el2
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
);
3882 switch (ri
->opc2
& 6) {
3885 case 0: /* AT S1E1R, AT S1E1W, AT S1E1RP, AT S1E1WP */
3886 if (ri
->crm
== 9 && arm_pan_enabled(env
)) {
3887 mmu_idx
= regime_e20
?
3888 ARMMMUIdx_E20_2_PAN
: ARMMMUIdx_Stage1_E1_PAN
;
3890 mmu_idx
= regime_e20
? ARMMMUIdx_E20_2
: ARMMMUIdx_Stage1_E1
;
3893 case 4: /* AT S1E2R, AT S1E2W */
3894 mmu_idx
= hcr_el2
& HCR_E2H
? ARMMMUIdx_E20_2
: ARMMMUIdx_E2
;
3896 case 6: /* AT S1E3R, AT S1E3W */
3897 mmu_idx
= ARMMMUIdx_E3
;
3900 g_assert_not_reached();
3903 case 2: /* AT S1E0R, AT S1E0W */
3904 mmu_idx
= regime_e20
? ARMMMUIdx_E20_0
: ARMMMUIdx_Stage1_E0
;
3906 case 4: /* AT S12E1R, AT S12E1W */
3907 mmu_idx
= regime_e20
? ARMMMUIdx_E20_2
: ARMMMUIdx_E10_1
;
3909 case 6: /* AT S12E0R, AT S12E0W */
3910 mmu_idx
= regime_e20
? ARMMMUIdx_E20_0
: ARMMMUIdx_E10_0
;
3913 g_assert_not_reached();
3916 env
->cp15
.par_el
[1] = do_ats_write(env
, value
, access_type
,
3917 mmu_idx
, arm_security_space(env
));
3919 /* Handled by hardware accelerator. */
3920 g_assert_not_reached();
3921 #endif /* CONFIG_TCG */
3925 /* Return basic MPU access permission bits. */
3926 static uint32_t simple_mpu_ap_bits(uint32_t val
)
3933 for (i
= 0; i
< 16; i
+= 2) {
3934 ret
|= (val
>> i
) & mask
;
3940 /* Pad basic MPU access permission bits to extended format. */
3941 static uint32_t extended_mpu_ap_bits(uint32_t val
)
3948 for (i
= 0; i
< 16; i
+= 2) {
3949 ret
|= (val
& mask
) << i
;
3955 static void pmsav5_data_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3958 env
->cp15
.pmsav5_data_ap
= extended_mpu_ap_bits(value
);
3961 static uint64_t pmsav5_data_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3963 return simple_mpu_ap_bits(env
->cp15
.pmsav5_data_ap
);
3966 static void pmsav5_insn_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3969 env
->cp15
.pmsav5_insn_ap
= extended_mpu_ap_bits(value
);
3972 static uint64_t pmsav5_insn_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3974 return simple_mpu_ap_bits(env
->cp15
.pmsav5_insn_ap
);
3977 static uint64_t pmsav7_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3979 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
3985 u32p
+= env
->pmsav7
.rnr
[M_REG_NS
];
3989 static void pmsav7_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3992 ARMCPU
*cpu
= env_archcpu(env
);
3993 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
3999 u32p
+= env
->pmsav7
.rnr
[M_REG_NS
];
4000 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
4004 static void pmsav7_rgnr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4007 ARMCPU
*cpu
= env_archcpu(env
);
4008 uint32_t nrgs
= cpu
->pmsav7_dregion
;
4010 if (value
>= nrgs
) {
4011 qemu_log_mask(LOG_GUEST_ERROR
,
4012 "PMSAv7 RGNR write >= # supported regions, %" PRIu32
4013 " > %" PRIu32
"\n", (uint32_t)value
, nrgs
);
4017 raw_write(env
, ri
, value
);
4020 static void prbar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4023 ARMCPU
*cpu
= env_archcpu(env
);
4025 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
4026 env
->pmsav8
.rbar
[M_REG_NS
][env
->pmsav7
.rnr
[M_REG_NS
]] = value
;
4029 static uint64_t prbar_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4031 return env
->pmsav8
.rbar
[M_REG_NS
][env
->pmsav7
.rnr
[M_REG_NS
]];
4034 static void prlar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4037 ARMCPU
*cpu
= env_archcpu(env
);
4039 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
4040 env
->pmsav8
.rlar
[M_REG_NS
][env
->pmsav7
.rnr
[M_REG_NS
]] = value
;
4043 static uint64_t prlar_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4045 return env
->pmsav8
.rlar
[M_REG_NS
][env
->pmsav7
.rnr
[M_REG_NS
]];
4048 static void prselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4051 ARMCPU
*cpu
= env_archcpu(env
);
4054 * Ignore writes that would select not implemented region.
4055 * This is architecturally UNPREDICTABLE.
4057 if (value
>= cpu
->pmsav7_dregion
) {
4061 env
->pmsav7
.rnr
[M_REG_NS
] = value
;
4064 static void hprbar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4067 ARMCPU
*cpu
= env_archcpu(env
);
4069 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
4070 env
->pmsav8
.hprbar
[env
->pmsav8
.hprselr
] = value
;
4073 static uint64_t hprbar_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4075 return env
->pmsav8
.hprbar
[env
->pmsav8
.hprselr
];
4078 static void hprlar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4081 ARMCPU
*cpu
= env_archcpu(env
);
4083 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
4084 env
->pmsav8
.hprlar
[env
->pmsav8
.hprselr
] = value
;
4087 static uint64_t hprlar_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4089 return env
->pmsav8
.hprlar
[env
->pmsav8
.hprselr
];
4092 static void hprenr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4097 ARMCPU
*cpu
= env_archcpu(env
);
4099 /* Ignore writes to unimplemented regions */
4100 int rmax
= MIN(cpu
->pmsav8r_hdregion
, 32);
4101 value
&= MAKE_64BIT_MASK(0, rmax
);
4103 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
4105 /* Register alias is only valid for first 32 indexes */
4106 for (n
= 0; n
< rmax
; ++n
) {
4107 bit
= extract32(value
, n
, 1);
4108 env
->pmsav8
.hprlar
[n
] = deposit32(
4109 env
->pmsav8
.hprlar
[n
], 0, 1, bit
);
4113 static uint64_t hprenr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4116 uint32_t result
= 0x0;
4117 ARMCPU
*cpu
= env_archcpu(env
);
4119 /* Register alias is only valid for first 32 indexes */
4120 for (n
= 0; n
< MIN(cpu
->pmsav8r_hdregion
, 32); ++n
) {
4121 if (env
->pmsav8
.hprlar
[n
] & 0x1) {
4122 result
|= (0x1 << n
);
4128 static void hprselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4131 ARMCPU
*cpu
= env_archcpu(env
);
4134 * Ignore writes that would select not implemented region.
4135 * This is architecturally UNPREDICTABLE.
4137 if (value
>= cpu
->pmsav8r_hdregion
) {
4141 env
->pmsav8
.hprselr
= value
;
4144 static void pmsav8r_regn_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4147 ARMCPU
*cpu
= env_archcpu(env
);
4148 uint8_t index
= (extract32(ri
->opc0
, 0, 1) << 4) |
4149 (extract32(ri
->crm
, 0, 3) << 1) | extract32(ri
->opc2
, 2, 1);
4151 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
4154 if (index
>= cpu
->pmsav8r_hdregion
) {
4157 if (ri
->opc2
& 0x1) {
4158 env
->pmsav8
.hprlar
[index
] = value
;
4160 env
->pmsav8
.hprbar
[index
] = value
;
4163 if (index
>= cpu
->pmsav7_dregion
) {
4166 if (ri
->opc2
& 0x1) {
4167 env
->pmsav8
.rlar
[M_REG_NS
][index
] = value
;
4169 env
->pmsav8
.rbar
[M_REG_NS
][index
] = value
;
4174 static uint64_t pmsav8r_regn_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4176 ARMCPU
*cpu
= env_archcpu(env
);
4177 uint8_t index
= (extract32(ri
->opc0
, 0, 1) << 4) |
4178 (extract32(ri
->crm
, 0, 3) << 1) | extract32(ri
->opc2
, 2, 1);
4181 if (index
>= cpu
->pmsav8r_hdregion
) {
4184 if (ri
->opc2
& 0x1) {
4185 return env
->pmsav8
.hprlar
[index
];
4187 return env
->pmsav8
.hprbar
[index
];
4190 if (index
>= cpu
->pmsav7_dregion
) {
4193 if (ri
->opc2
& 0x1) {
4194 return env
->pmsav8
.rlar
[M_REG_NS
][index
];
4196 return env
->pmsav8
.rbar
[M_REG_NS
][index
];
4201 static const ARMCPRegInfo pmsav8r_cp_reginfo
[] = {
4203 .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 3, .opc2
= 0,
4204 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
4205 .accessfn
= access_tvm_trvm
,
4206 .readfn
= prbar_read
, .writefn
= prbar_write
},
4208 .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 3, .opc2
= 1,
4209 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
4210 .accessfn
= access_tvm_trvm
,
4211 .readfn
= prlar_read
, .writefn
= prlar_write
},
4212 { .name
= "PRSELR", .resetvalue
= 0,
4213 .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 2, .opc2
= 1,
4214 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4215 .writefn
= prselr_write
,
4216 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.rnr
[M_REG_NS
]) },
4217 { .name
= "HPRBAR", .resetvalue
= 0,
4218 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 3, .opc2
= 0,
4219 .access
= PL2_RW
, .type
= ARM_CP_NO_RAW
,
4220 .readfn
= hprbar_read
, .writefn
= hprbar_write
},
4222 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 3, .opc2
= 1,
4223 .access
= PL2_RW
, .type
= ARM_CP_NO_RAW
,
4224 .readfn
= hprlar_read
, .writefn
= hprlar_write
},
4225 { .name
= "HPRSELR", .resetvalue
= 0,
4226 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 2, .opc2
= 1,
4228 .writefn
= hprselr_write
,
4229 .fieldoffset
= offsetof(CPUARMState
, pmsav8
.hprselr
) },
4231 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 1, .opc2
= 1,
4232 .access
= PL2_RW
, .type
= ARM_CP_NO_RAW
,
4233 .readfn
= hprenr_read
, .writefn
= hprenr_write
},
4236 static const ARMCPRegInfo pmsav7_cp_reginfo
[] = {
4238 * Reset for all these registers is handled in arm_cpu_reset(),
4239 * because the PMSAv7 is also used by M-profile CPUs, which do
4240 * not register cpregs but still need the state to be reset.
4242 { .name
= "DRBAR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 0,
4243 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
4244 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drbar
),
4245 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
4246 .resetfn
= arm_cp_reset_ignore
},
4247 { .name
= "DRSR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 2,
4248 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
4249 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drsr
),
4250 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
4251 .resetfn
= arm_cp_reset_ignore
},
4252 { .name
= "DRACR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 4,
4253 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
4254 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.dracr
),
4255 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
4256 .resetfn
= arm_cp_reset_ignore
},
4257 { .name
= "RGNR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 2, .opc2
= 0,
4259 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.rnr
[M_REG_NS
]),
4260 .writefn
= pmsav7_rgnr_write
,
4261 .resetfn
= arm_cp_reset_ignore
},
4264 static const ARMCPRegInfo pmsav5_cp_reginfo
[] = {
4265 { .name
= "DATA_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
4266 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
4267 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
4268 .readfn
= pmsav5_data_ap_read
, .writefn
= pmsav5_data_ap_write
, },
4269 { .name
= "INSN_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
4270 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
4271 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
4272 .readfn
= pmsav5_insn_ap_read
, .writefn
= pmsav5_insn_ap_write
, },
4273 { .name
= "DATA_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 2,
4275 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
4277 { .name
= "INSN_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 3,
4279 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
4281 { .name
= "DCACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 0,
4283 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_data
), .resetvalue
= 0, },
4284 { .name
= "ICACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 1,
4286 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_insn
), .resetvalue
= 0, },
4287 /* Protection region base and size registers */
4288 { .name
= "946_PRBS0", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0,
4289 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4290 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[0]) },
4291 { .name
= "946_PRBS1", .cp
= 15, .crn
= 6, .crm
= 1, .opc1
= 0,
4292 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4293 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[1]) },
4294 { .name
= "946_PRBS2", .cp
= 15, .crn
= 6, .crm
= 2, .opc1
= 0,
4295 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4296 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[2]) },
4297 { .name
= "946_PRBS3", .cp
= 15, .crn
= 6, .crm
= 3, .opc1
= 0,
4298 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4299 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[3]) },
4300 { .name
= "946_PRBS4", .cp
= 15, .crn
= 6, .crm
= 4, .opc1
= 0,
4301 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4302 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[4]) },
4303 { .name
= "946_PRBS5", .cp
= 15, .crn
= 6, .crm
= 5, .opc1
= 0,
4304 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4305 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[5]) },
4306 { .name
= "946_PRBS6", .cp
= 15, .crn
= 6, .crm
= 6, .opc1
= 0,
4307 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4308 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[6]) },
4309 { .name
= "946_PRBS7", .cp
= 15, .crn
= 6, .crm
= 7, .opc1
= 0,
4310 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4311 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[7]) },
4314 static void vmsa_ttbcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4317 ARMCPU
*cpu
= env_archcpu(env
);
4319 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
4320 if (arm_feature(env
, ARM_FEATURE_LPAE
) && (value
& TTBCR_EAE
)) {
4322 * Pre ARMv8 bits [21:19], [15:14] and [6:3] are UNK/SBZP when
4323 * using Long-descriptor translation table format
4325 value
&= ~((7 << 19) | (3 << 14) | (0xf << 3));
4326 } else if (arm_feature(env
, ARM_FEATURE_EL3
)) {
4328 * In an implementation that includes the Security Extensions
4329 * TTBCR has additional fields PD0 [4] and PD1 [5] for
4330 * Short-descriptor translation table format.
4332 value
&= TTBCR_PD1
| TTBCR_PD0
| TTBCR_N
;
4338 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
4340 * With LPAE the TTBCR could result in a change of ASID
4341 * via the TTBCR.A1 bit, so do a TLB flush.
4343 tlb_flush(CPU(cpu
));
4345 raw_write(env
, ri
, value
);
4348 static void vmsa_tcr_el12_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4351 ARMCPU
*cpu
= env_archcpu(env
);
4353 /* For AArch64 the A1 bit could result in a change of ASID, so TLB flush. */
4354 tlb_flush(CPU(cpu
));
4355 raw_write(env
, ri
, value
);
4358 static void vmsa_ttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4361 /* If the ASID changes (with a 64-bit write), we must flush the TLB. */
4362 if (cpreg_field_is_64bit(ri
) &&
4363 extract64(raw_read(env
, ri
) ^ value
, 48, 16) != 0) {
4364 ARMCPU
*cpu
= env_archcpu(env
);
4365 tlb_flush(CPU(cpu
));
4367 raw_write(env
, ri
, value
);
4370 static void vmsa_tcr_ttbr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4374 * If we are running with E2&0 regime, then an ASID is active.
4375 * Flush if that might be changing. Note we're not checking
4376 * TCR_EL2.A1 to know if this is really the TTBRx_EL2 that
4377 * holds the active ASID, only checking the field that might.
4379 if (extract64(raw_read(env
, ri
) ^ value
, 48, 16) &&
4380 (arm_hcr_el2_eff(env
) & HCR_E2H
)) {
4381 uint16_t mask
= ARMMMUIdxBit_E20_2
|
4382 ARMMMUIdxBit_E20_2_PAN
|
4384 tlb_flush_by_mmuidx(env_cpu(env
), mask
);
4386 raw_write(env
, ri
, value
);
4389 static void vttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4392 ARMCPU
*cpu
= env_archcpu(env
);
4393 CPUState
*cs
= CPU(cpu
);
4396 * A change in VMID to the stage2 page table (Stage2) invalidates
4397 * the stage2 and combined stage 1&2 tlbs (EL10_1 and EL10_0).
4399 if (extract64(raw_read(env
, ri
) ^ value
, 48, 16) != 0) {
4400 tlb_flush_by_mmuidx(cs
, alle1_tlbmask(env
));
4402 raw_write(env
, ri
, value
);
4405 static const ARMCPRegInfo vmsa_pmsa_cp_reginfo
[] = {
4406 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
4407 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .type
= ARM_CP_ALIAS
,
4408 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dfsr_s
),
4409 offsetoflow32(CPUARMState
, cp15
.dfsr_ns
) }, },
4410 { .name
= "IFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
4411 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
4412 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.ifsr_s
),
4413 offsetoflow32(CPUARMState
, cp15
.ifsr_ns
) } },
4414 { .name
= "DFAR", .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 0, .opc2
= 0,
4415 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
4416 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.dfar_s
),
4417 offsetof(CPUARMState
, cp15
.dfar_ns
) } },
4418 { .name
= "FAR_EL1", .state
= ARM_CP_STATE_AA64
,
4419 .opc0
= 3, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 0,
4420 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4422 .nv2_redirect_offset
= 0x220 | NV2_REDIR_NV1
,
4423 .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[1]),
4427 static const ARMCPRegInfo vmsa_cp_reginfo
[] = {
4428 { .name
= "ESR_EL1", .state
= ARM_CP_STATE_AA64
,
4429 .opc0
= 3, .crn
= 5, .crm
= 2, .opc1
= 0, .opc2
= 0,
4430 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4432 .nv2_redirect_offset
= 0x138 | NV2_REDIR_NV1
,
4433 .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[1]), .resetvalue
= 0, },
4434 { .name
= "TTBR0_EL1", .state
= ARM_CP_STATE_BOTH
,
4435 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 0,
4436 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4437 .fgt
= FGT_TTBR0_EL1
,
4438 .nv2_redirect_offset
= 0x200 | NV2_REDIR_NV1
,
4439 .writefn
= vmsa_ttbr_write
, .resetvalue
= 0, .raw_writefn
= raw_write
,
4440 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
4441 offsetof(CPUARMState
, cp15
.ttbr0_ns
) } },
4442 { .name
= "TTBR1_EL1", .state
= ARM_CP_STATE_BOTH
,
4443 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 1,
4444 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4445 .fgt
= FGT_TTBR1_EL1
,
4446 .nv2_redirect_offset
= 0x210 | NV2_REDIR_NV1
,
4447 .writefn
= vmsa_ttbr_write
, .resetvalue
= 0, .raw_writefn
= raw_write
,
4448 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
4449 offsetof(CPUARMState
, cp15
.ttbr1_ns
) } },
4450 { .name
= "TCR_EL1", .state
= ARM_CP_STATE_AA64
,
4451 .opc0
= 3, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
4452 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4454 .nv2_redirect_offset
= 0x120 | NV2_REDIR_NV1
,
4455 .writefn
= vmsa_tcr_el12_write
,
4456 .raw_writefn
= raw_write
,
4458 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[1]) },
4459 { .name
= "TTBCR", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
4460 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4461 .type
= ARM_CP_ALIAS
, .writefn
= vmsa_ttbcr_write
,
4462 .raw_writefn
= raw_write
,
4463 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tcr_el
[3]),
4464 offsetoflow32(CPUARMState
, cp15
.tcr_el
[1])} },
4468 * Note that unlike TTBCR, writing to TTBCR2 does not require flushing
4469 * qemu tlbs nor adjusting cached masks.
4471 static const ARMCPRegInfo ttbcr2_reginfo
= {
4472 .name
= "TTBCR2", .cp
= 15, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 3,
4473 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4474 .type
= ARM_CP_ALIAS
,
4475 .bank_fieldoffsets
= {
4476 offsetofhigh32(CPUARMState
, cp15
.tcr_el
[3]),
4477 offsetofhigh32(CPUARMState
, cp15
.tcr_el
[1]),
4481 static void omap_ticonfig_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4484 env
->cp15
.c15_ticonfig
= value
& 0xe7;
4485 /* The OS_TYPE bit in this register changes the reported CPUID! */
4486 env
->cp15
.c0_cpuid
= (value
& (1 << 5)) ?
4487 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
4490 static void omap_threadid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4493 env
->cp15
.c15_threadid
= value
& 0xffff;
4496 static void omap_wfi_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4499 /* Wait-for-interrupt (deprecated) */
4500 cpu_interrupt(env_cpu(env
), CPU_INTERRUPT_HALT
);
4503 static void omap_cachemaint_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4507 * On OMAP there are registers indicating the max/min index of dcache lines
4508 * containing a dirty line; cache flush operations have to reset these.
4510 env
->cp15
.c15_i_max
= 0x000;
4511 env
->cp15
.c15_i_min
= 0xff0;
4514 static const ARMCPRegInfo omap_cp_reginfo
[] = {
4515 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= CP_ANY
,
4516 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_OVERRIDE
,
4517 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.esr_el
[1]),
4519 { .name
= "", .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 0, .opc2
= 0,
4520 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
4521 { .name
= "TICONFIG", .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0,
4523 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ticonfig
), .resetvalue
= 0,
4524 .writefn
= omap_ticonfig_write
},
4525 { .name
= "IMAX", .cp
= 15, .crn
= 15, .crm
= 2, .opc1
= 0, .opc2
= 0,
4527 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_max
), .resetvalue
= 0, },
4528 { .name
= "IMIN", .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 0, .opc2
= 0,
4529 .access
= PL1_RW
, .resetvalue
= 0xff0,
4530 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_min
) },
4531 { .name
= "THREADID", .cp
= 15, .crn
= 15, .crm
= 4, .opc1
= 0, .opc2
= 0,
4533 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_threadid
), .resetvalue
= 0,
4534 .writefn
= omap_threadid_write
},
4535 { .name
= "TI925T_STATUS", .cp
= 15, .crn
= 15,
4536 .crm
= 8, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
4537 .type
= ARM_CP_NO_RAW
,
4538 .readfn
= arm_cp_read_zero
, .writefn
= omap_wfi_write
, },
4540 * TODO: Peripheral port remap register:
4541 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt controller
4542 * base address at $rn & ~0xfff and map size of 0x200 << ($rn & 0xfff),
4545 { .name
= "OMAP_CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
4546 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
4547 .type
= ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
,
4548 .writefn
= omap_cachemaint_write
},
4549 { .name
= "C9", .cp
= 15, .crn
= 9,
4550 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
,
4551 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
, .resetvalue
= 0 },
4554 static void xscale_cpar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4557 env
->cp15
.c15_cpar
= value
& 0x3fff;
4560 static const ARMCPRegInfo xscale_cp_reginfo
[] = {
4561 { .name
= "XSCALE_CPAR",
4562 .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
4563 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_cpar
), .resetvalue
= 0,
4564 .writefn
= xscale_cpar_write
, },
4565 { .name
= "XSCALE_AUXCR",
4566 .cp
= 15, .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 1, .access
= PL1_RW
,
4567 .fieldoffset
= offsetof(CPUARMState
, cp15
.c1_xscaleauxcr
),
4570 * XScale specific cache-lockdown: since we have no cache we NOP these
4571 * and hope the guest does not really rely on cache behaviour.
4573 { .name
= "XSCALE_LOCK_ICACHE_LINE",
4574 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 0,
4575 .access
= PL1_W
, .type
= ARM_CP_NOP
},
4576 { .name
= "XSCALE_UNLOCK_ICACHE",
4577 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 1,
4578 .access
= PL1_W
, .type
= ARM_CP_NOP
},
4579 { .name
= "XSCALE_DCACHE_LOCK",
4580 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 0,
4581 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
4582 { .name
= "XSCALE_UNLOCK_DCACHE",
4583 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 1,
4584 .access
= PL1_W
, .type
= ARM_CP_NOP
},
4587 static const ARMCPRegInfo dummy_c15_cp_reginfo
[] = {
4589 * RAZ/WI the whole crn=15 space, when we don't have a more specific
4590 * implementation of this implementation-defined space.
4591 * Ideally this should eventually disappear in favour of actually
4592 * implementing the correct behaviour for all cores.
4594 { .name
= "C15_IMPDEF", .cp
= 15, .crn
= 15,
4595 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
4597 .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
| ARM_CP_OVERRIDE
,
4601 static const ARMCPRegInfo cache_dirty_status_cp_reginfo
[] = {
4602 /* Cache status: RAZ because we have no cache so it's always clean */
4603 { .name
= "CDSR", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 6,
4604 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4608 static const ARMCPRegInfo cache_block_ops_cp_reginfo
[] = {
4609 /* We never have a block transfer operation in progress */
4610 { .name
= "BXSR", .cp
= 15, .crn
= 7, .crm
= 12, .opc1
= 0, .opc2
= 4,
4611 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4613 /* The cache ops themselves: these all NOP for QEMU */
4614 { .name
= "IICR", .cp
= 15, .crm
= 5, .opc1
= 0,
4615 .access
= PL1_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4616 { .name
= "IDCR", .cp
= 15, .crm
= 6, .opc1
= 0,
4617 .access
= PL1_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4618 { .name
= "CDCR", .cp
= 15, .crm
= 12, .opc1
= 0,
4619 .access
= PL0_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4620 { .name
= "PIR", .cp
= 15, .crm
= 12, .opc1
= 1,
4621 .access
= PL0_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4622 { .name
= "PDR", .cp
= 15, .crm
= 12, .opc1
= 2,
4623 .access
= PL0_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4624 { .name
= "CIDCR", .cp
= 15, .crm
= 14, .opc1
= 0,
4625 .access
= PL1_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4628 static const ARMCPRegInfo cache_test_clean_cp_reginfo
[] = {
4630 * The cache test-and-clean instructions always return (1 << 30)
4631 * to indicate that there are no dirty cache lines.
4633 { .name
= "TC_DCACHE", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 3,
4634 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4635 .resetvalue
= (1 << 30) },
4636 { .name
= "TCI_DCACHE", .cp
= 15, .crn
= 7, .crm
= 14, .opc1
= 0, .opc2
= 3,
4637 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4638 .resetvalue
= (1 << 30) },
4641 static const ARMCPRegInfo strongarm_cp_reginfo
[] = {
4642 /* Ignore ReadBuffer accesses */
4643 { .name
= "C9_READBUFFER", .cp
= 15, .crn
= 9,
4644 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
4645 .access
= PL1_RW
, .resetvalue
= 0,
4646 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
},
4649 static uint64_t midr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4651 unsigned int cur_el
= arm_current_el(env
);
4653 if (arm_is_el2_enabled(env
) && cur_el
== 1) {
4654 return env
->cp15
.vpidr_el2
;
4656 return raw_read(env
, ri
);
4659 static uint64_t mpidr_read_val(CPUARMState
*env
)
4661 ARMCPU
*cpu
= env_archcpu(env
);
4662 uint64_t mpidr
= cpu
->mp_affinity
;
4664 if (arm_feature(env
, ARM_FEATURE_V7MP
)) {
4665 mpidr
|= (1U << 31);
4667 * Cores which are uniprocessor (non-coherent)
4668 * but still implement the MP extensions set
4669 * bit 30. (For instance, Cortex-R5).
4671 if (cpu
->mp_is_up
) {
4672 mpidr
|= (1u << 30);
4678 static uint64_t mpidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4680 unsigned int cur_el
= arm_current_el(env
);
4682 if (arm_is_el2_enabled(env
) && cur_el
== 1) {
4683 return env
->cp15
.vmpidr_el2
;
4685 return mpidr_read_val(env
);
4688 static const ARMCPRegInfo lpae_cp_reginfo
[] = {
4690 { .name
= "AMAIR0", .state
= ARM_CP_STATE_BOTH
,
4691 .opc0
= 3, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 0,
4692 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4693 .fgt
= FGT_AMAIR_EL1
,
4694 .nv2_redirect_offset
= 0x148 | NV2_REDIR_NV1
,
4695 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4696 /* AMAIR1 is mapped to AMAIR_EL1[63:32] */
4697 { .name
= "AMAIR1", .cp
= 15, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 1,
4698 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4699 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4700 { .name
= "PAR", .cp
= 15, .crm
= 7, .opc1
= 0,
4701 .access
= PL1_RW
, .type
= ARM_CP_64BIT
, .resetvalue
= 0,
4702 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.par_s
),
4703 offsetof(CPUARMState
, cp15
.par_ns
)} },
4704 { .name
= "TTBR0", .cp
= 15, .crm
= 2, .opc1
= 0,
4705 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4706 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
4707 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
4708 offsetof(CPUARMState
, cp15
.ttbr0_ns
) },
4709 .writefn
= vmsa_ttbr_write
, .raw_writefn
= raw_write
},
4710 { .name
= "TTBR1", .cp
= 15, .crm
= 2, .opc1
= 1,
4711 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4712 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
4713 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
4714 offsetof(CPUARMState
, cp15
.ttbr1_ns
) },
4715 .writefn
= vmsa_ttbr_write
, .raw_writefn
= raw_write
},
4718 static uint64_t aa64_fpcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4720 return vfp_get_fpcr(env
);
4723 static void aa64_fpcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4726 vfp_set_fpcr(env
, value
);
4729 static uint64_t aa64_fpsr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4731 return vfp_get_fpsr(env
);
4734 static void aa64_fpsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4737 vfp_set_fpsr(env
, value
);
4740 static CPAccessResult
aa64_daif_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4743 if (arm_current_el(env
) == 0 && !(arm_sctlr(env
, 0) & SCTLR_UMA
)) {
4744 return CP_ACCESS_TRAP
;
4746 return CP_ACCESS_OK
;
4749 static void aa64_daif_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4752 env
->daif
= value
& PSTATE_DAIF
;
4755 static uint64_t aa64_pan_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4757 return env
->pstate
& PSTATE_PAN
;
4760 static void aa64_pan_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4763 env
->pstate
= (env
->pstate
& ~PSTATE_PAN
) | (value
& PSTATE_PAN
);
4766 static const ARMCPRegInfo pan_reginfo
= {
4767 .name
= "PAN", .state
= ARM_CP_STATE_AA64
,
4768 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 3,
4769 .type
= ARM_CP_NO_RAW
, .access
= PL1_RW
,
4770 .readfn
= aa64_pan_read
, .writefn
= aa64_pan_write
4773 static uint64_t aa64_uao_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4775 return env
->pstate
& PSTATE_UAO
;
4778 static void aa64_uao_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4781 env
->pstate
= (env
->pstate
& ~PSTATE_UAO
) | (value
& PSTATE_UAO
);
4784 static const ARMCPRegInfo uao_reginfo
= {
4785 .name
= "UAO", .state
= ARM_CP_STATE_AA64
,
4786 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 4,
4787 .type
= ARM_CP_NO_RAW
, .access
= PL1_RW
,
4788 .readfn
= aa64_uao_read
, .writefn
= aa64_uao_write
4791 static uint64_t aa64_dit_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4793 return env
->pstate
& PSTATE_DIT
;
4796 static void aa64_dit_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4799 env
->pstate
= (env
->pstate
& ~PSTATE_DIT
) | (value
& PSTATE_DIT
);
4802 static const ARMCPRegInfo dit_reginfo
= {
4803 .name
= "DIT", .state
= ARM_CP_STATE_AA64
,
4804 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 5,
4805 .type
= ARM_CP_NO_RAW
, .access
= PL0_RW
,
4806 .readfn
= aa64_dit_read
, .writefn
= aa64_dit_write
4809 static uint64_t aa64_ssbs_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4811 return env
->pstate
& PSTATE_SSBS
;
4814 static void aa64_ssbs_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4817 env
->pstate
= (env
->pstate
& ~PSTATE_SSBS
) | (value
& PSTATE_SSBS
);
4820 static const ARMCPRegInfo ssbs_reginfo
= {
4821 .name
= "SSBS", .state
= ARM_CP_STATE_AA64
,
4822 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 6,
4823 .type
= ARM_CP_NO_RAW
, .access
= PL0_RW
,
4824 .readfn
= aa64_ssbs_read
, .writefn
= aa64_ssbs_write
4827 static CPAccessResult
aa64_cacheop_poc_access(CPUARMState
*env
,
4828 const ARMCPRegInfo
*ri
,
4831 /* Cache invalidate/clean to Point of Coherency or Persistence... */
4832 switch (arm_current_el(env
)) {
4834 /* ... EL0 must UNDEF unless SCTLR_EL1.UCI is set. */
4835 if (!(arm_sctlr(env
, 0) & SCTLR_UCI
)) {
4836 return CP_ACCESS_TRAP
;
4840 /* ... EL1 must trap to EL2 if HCR_EL2.TPCP is set. */
4841 if (arm_hcr_el2_eff(env
) & HCR_TPCP
) {
4842 return CP_ACCESS_TRAP_EL2
;
4846 return CP_ACCESS_OK
;
4849 static CPAccessResult
do_cacheop_pou_access(CPUARMState
*env
, uint64_t hcrflags
)
4851 /* Cache invalidate/clean to Point of Unification... */
4852 switch (arm_current_el(env
)) {
4854 /* ... EL0 must UNDEF unless SCTLR_EL1.UCI is set. */
4855 if (!(arm_sctlr(env
, 0) & SCTLR_UCI
)) {
4856 return CP_ACCESS_TRAP
;
4860 /* ... EL1 must trap to EL2 if relevant HCR_EL2 flags are set. */
4861 if (arm_hcr_el2_eff(env
) & hcrflags
) {
4862 return CP_ACCESS_TRAP_EL2
;
4866 return CP_ACCESS_OK
;
4869 static CPAccessResult
access_ticab(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4872 return do_cacheop_pou_access(env
, HCR_TICAB
| HCR_TPU
);
4875 static CPAccessResult
access_tocu(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4878 return do_cacheop_pou_access(env
, HCR_TOCU
| HCR_TPU
);
4882 * See: D4.7.2 TLB maintenance requirements and the TLB maintenance instructions
4883 * Page D4-1736 (DDI0487A.b)
4886 static int vae1_tlbmask(CPUARMState
*env
)
4888 uint64_t hcr
= arm_hcr_el2_eff(env
);
4891 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4892 mask
= ARMMMUIdxBit_E20_2
|
4893 ARMMMUIdxBit_E20_2_PAN
|
4896 mask
= ARMMMUIdxBit_E10_1
|
4897 ARMMMUIdxBit_E10_1_PAN
|
4903 static int vae2_tlbmask(CPUARMState
*env
)
4905 uint64_t hcr
= arm_hcr_el2_eff(env
);
4908 if (hcr
& HCR_E2H
) {
4909 mask
= ARMMMUIdxBit_E20_2
|
4910 ARMMMUIdxBit_E20_2_PAN
|
4913 mask
= ARMMMUIdxBit_E2
;
4918 /* Return 56 if TBI is enabled, 64 otherwise. */
4919 static int tlbbits_for_regime(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
4922 uint64_t tcr
= regime_tcr(env
, mmu_idx
);
4923 int tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
4924 int select
= extract64(addr
, 55, 1);
4926 return (tbi
>> select
) & 1 ? 56 : 64;
4929 static int vae1_tlbbits(CPUARMState
*env
, uint64_t addr
)
4931 uint64_t hcr
= arm_hcr_el2_eff(env
);
4934 /* Only the regime of the mmu_idx below is significant. */
4935 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4936 mmu_idx
= ARMMMUIdx_E20_0
;
4938 mmu_idx
= ARMMMUIdx_E10_0
;
4941 return tlbbits_for_regime(env
, mmu_idx
, addr
);
4944 static int vae2_tlbbits(CPUARMState
*env
, uint64_t addr
)
4946 uint64_t hcr
= arm_hcr_el2_eff(env
);
4950 * Only the regime of the mmu_idx below is significant.
4951 * Regime EL2&0 has two ranges with separate TBI configuration, while EL2
4954 if (hcr
& HCR_E2H
) {
4955 mmu_idx
= ARMMMUIdx_E20_2
;
4957 mmu_idx
= ARMMMUIdx_E2
;
4960 return tlbbits_for_regime(env
, mmu_idx
, addr
);
4963 static void tlbi_aa64_vmalle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4966 CPUState
*cs
= env_cpu(env
);
4967 int mask
= vae1_tlbmask(env
);
4969 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4972 static void tlbi_aa64_vmalle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4975 CPUState
*cs
= env_cpu(env
);
4976 int mask
= vae1_tlbmask(env
);
4978 if (tlb_force_broadcast(env
)) {
4979 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4981 tlb_flush_by_mmuidx(cs
, mask
);
4985 static int e2_tlbmask(CPUARMState
*env
)
4987 return (ARMMMUIdxBit_E20_0
|
4988 ARMMMUIdxBit_E20_2
|
4989 ARMMMUIdxBit_E20_2_PAN
|
4993 static void tlbi_aa64_alle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4996 CPUState
*cs
= env_cpu(env
);
4997 int mask
= alle1_tlbmask(env
);
4999 tlb_flush_by_mmuidx(cs
, mask
);
5002 static void tlbi_aa64_alle2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5005 CPUState
*cs
= env_cpu(env
);
5006 int mask
= e2_tlbmask(env
);
5008 tlb_flush_by_mmuidx(cs
, mask
);
5011 static void tlbi_aa64_alle3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5014 ARMCPU
*cpu
= env_archcpu(env
);
5015 CPUState
*cs
= CPU(cpu
);
5017 tlb_flush_by_mmuidx(cs
, ARMMMUIdxBit_E3
);
5020 static void tlbi_aa64_alle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5023 CPUState
*cs
= env_cpu(env
);
5024 int mask
= alle1_tlbmask(env
);
5026 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
5029 static void tlbi_aa64_alle2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5032 CPUState
*cs
= env_cpu(env
);
5033 int mask
= e2_tlbmask(env
);
5035 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
5038 static void tlbi_aa64_alle3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5041 CPUState
*cs
= env_cpu(env
);
5043 tlb_flush_by_mmuidx_all_cpus_synced(cs
, ARMMMUIdxBit_E3
);
5046 static void tlbi_aa64_vae2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5050 * Invalidate by VA, EL2
5051 * Currently handles both VAE2 and VALE2, since we don't support
5052 * flush-last-level-only.
5054 CPUState
*cs
= env_cpu(env
);
5055 int mask
= vae2_tlbmask(env
);
5056 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
5057 int bits
= vae2_tlbbits(env
, pageaddr
);
5059 tlb_flush_page_bits_by_mmuidx(cs
, pageaddr
, mask
, bits
);
5062 static void tlbi_aa64_vae3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5066 * Invalidate by VA, EL3
5067 * Currently handles both VAE3 and VALE3, since we don't support
5068 * flush-last-level-only.
5070 ARMCPU
*cpu
= env_archcpu(env
);
5071 CPUState
*cs
= CPU(cpu
);
5072 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
5074 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_E3
);
5077 static void tlbi_aa64_vae1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5080 CPUState
*cs
= env_cpu(env
);
5081 int mask
= vae1_tlbmask(env
);
5082 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
5083 int bits
= vae1_tlbbits(env
, pageaddr
);
5085 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
5088 static void tlbi_aa64_vae1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5092 * Invalidate by VA, EL1&0 (AArch64 version).
5093 * Currently handles all of VAE1, VAAE1, VAALE1 and VALE1,
5094 * since we don't support flush-for-specific-ASID-only or
5095 * flush-last-level-only.
5097 CPUState
*cs
= env_cpu(env
);
5098 int mask
= vae1_tlbmask(env
);
5099 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
5100 int bits
= vae1_tlbbits(env
, pageaddr
);
5102 if (tlb_force_broadcast(env
)) {
5103 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
5105 tlb_flush_page_bits_by_mmuidx(cs
, pageaddr
, mask
, bits
);
5109 static void tlbi_aa64_vae2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5112 CPUState
*cs
= env_cpu(env
);
5113 int mask
= vae2_tlbmask(env
);
5114 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
5115 int bits
= vae2_tlbbits(env
, pageaddr
);
5117 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
5120 static void tlbi_aa64_vae3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5123 CPUState
*cs
= env_cpu(env
);
5124 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
5125 int bits
= tlbbits_for_regime(env
, ARMMMUIdx_E3
, pageaddr
);
5127 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
,
5128 ARMMMUIdxBit_E3
, bits
);
5131 static int ipas2e1_tlbmask(CPUARMState
*env
, int64_t value
)
5134 * The MSB of value is the NS field, which only applies if SEL2
5135 * is implemented and SCR_EL3.NS is not set (i.e. in secure mode).
5138 && cpu_isar_feature(aa64_sel2
, env_archcpu(env
))
5139 && arm_is_secure_below_el3(env
)
5140 ? ARMMMUIdxBit_Stage2_S
5141 : ARMMMUIdxBit_Stage2
);
5144 static void tlbi_aa64_ipas2e1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5147 CPUState
*cs
= env_cpu(env
);
5148 int mask
= ipas2e1_tlbmask(env
, value
);
5149 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
5151 if (tlb_force_broadcast(env
)) {
5152 tlb_flush_page_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
);
5154 tlb_flush_page_by_mmuidx(cs
, pageaddr
, mask
);
5158 static void tlbi_aa64_ipas2e1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5161 CPUState
*cs
= env_cpu(env
);
5162 int mask
= ipas2e1_tlbmask(env
, value
);
5163 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
5165 tlb_flush_page_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
);
5168 #ifdef TARGET_AARCH64
5174 static ARMGranuleSize
tlbi_range_tg_to_gran_size(int tg
)
5177 * Note that the TLBI range TG field encoding differs from both
5178 * TG0 and TG1 encodings.
5192 static TLBIRange
tlbi_aa64_get_range(CPUARMState
*env
, ARMMMUIdx mmuidx
,
5195 unsigned int page_size_granule
, page_shift
, num
, scale
, exponent
;
5196 /* Extract one bit to represent the va selector in use. */
5197 uint64_t select
= sextract64(value
, 36, 1);
5198 ARMVAParameters param
= aa64_va_parameters(env
, select
, mmuidx
, true, false);
5199 TLBIRange ret
= { };
5200 ARMGranuleSize gran
;
5202 page_size_granule
= extract64(value
, 46, 2);
5203 gran
= tlbi_range_tg_to_gran_size(page_size_granule
);
5205 /* The granule encoded in value must match the granule in use. */
5206 if (gran
!= param
.gran
) {
5207 qemu_log_mask(LOG_GUEST_ERROR
, "Invalid tlbi page size granule %d\n",
5212 page_shift
= arm_granule_bits(gran
);
5213 num
= extract64(value
, 39, 5);
5214 scale
= extract64(value
, 44, 2);
5215 exponent
= (5 * scale
) + 1;
5217 ret
.length
= (num
+ 1) << (exponent
+ page_shift
);
5220 ret
.base
= sextract64(value
, 0, 37);
5222 ret
.base
= extract64(value
, 0, 37);
5226 * With DS=1, BaseADDR is always shifted 16 so that it is able
5227 * to address all 52 va bits. The input address is perforce
5228 * aligned on a 64k boundary regardless of translation granule.
5232 ret
.base
<<= page_shift
;
5237 static void do_rvae_write(CPUARMState
*env
, uint64_t value
,
5238 int idxmap
, bool synced
)
5240 ARMMMUIdx one_idx
= ARM_MMU_IDX_A
| ctz32(idxmap
);
5244 range
= tlbi_aa64_get_range(env
, one_idx
, value
);
5245 bits
= tlbbits_for_regime(env
, one_idx
, range
.base
);
5248 tlb_flush_range_by_mmuidx_all_cpus_synced(env_cpu(env
),
5254 tlb_flush_range_by_mmuidx(env_cpu(env
), range
.base
,
5255 range
.length
, idxmap
, bits
);
5259 static void tlbi_aa64_rvae1_write(CPUARMState
*env
,
5260 const ARMCPRegInfo
*ri
,
5264 * Invalidate by VA range, EL1&0.
5265 * Currently handles all of RVAE1, RVAAE1, RVAALE1 and RVALE1,
5266 * since we don't support flush-for-specific-ASID-only or
5267 * flush-last-level-only.
5270 do_rvae_write(env
, value
, vae1_tlbmask(env
),
5271 tlb_force_broadcast(env
));
5274 static void tlbi_aa64_rvae1is_write(CPUARMState
*env
,
5275 const ARMCPRegInfo
*ri
,
5279 * Invalidate by VA range, Inner/Outer Shareable EL1&0.
5280 * Currently handles all of RVAE1IS, RVAE1OS, RVAAE1IS, RVAAE1OS,
5281 * RVAALE1IS, RVAALE1OS, RVALE1IS and RVALE1OS, since we don't support
5282 * flush-for-specific-ASID-only, flush-last-level-only or inner/outer
5283 * shareable specific flushes.
5286 do_rvae_write(env
, value
, vae1_tlbmask(env
), true);
5289 static void tlbi_aa64_rvae2_write(CPUARMState
*env
,
5290 const ARMCPRegInfo
*ri
,
5294 * Invalidate by VA range, EL2.
5295 * Currently handles all of RVAE2 and RVALE2,
5296 * since we don't support flush-for-specific-ASID-only or
5297 * flush-last-level-only.
5300 do_rvae_write(env
, value
, vae2_tlbmask(env
),
5301 tlb_force_broadcast(env
));
5306 static void tlbi_aa64_rvae2is_write(CPUARMState
*env
,
5307 const ARMCPRegInfo
*ri
,
5311 * Invalidate by VA range, Inner/Outer Shareable, EL2.
5312 * Currently handles all of RVAE2IS, RVAE2OS, RVALE2IS and RVALE2OS,
5313 * since we don't support flush-for-specific-ASID-only,
5314 * flush-last-level-only or inner/outer shareable specific flushes.
5317 do_rvae_write(env
, value
, vae2_tlbmask(env
), true);
5321 static void tlbi_aa64_rvae3_write(CPUARMState
*env
,
5322 const ARMCPRegInfo
*ri
,
5326 * Invalidate by VA range, EL3.
5327 * Currently handles all of RVAE3 and RVALE3,
5328 * since we don't support flush-for-specific-ASID-only or
5329 * flush-last-level-only.
5332 do_rvae_write(env
, value
, ARMMMUIdxBit_E3
, tlb_force_broadcast(env
));
5335 static void tlbi_aa64_rvae3is_write(CPUARMState
*env
,
5336 const ARMCPRegInfo
*ri
,
5340 * Invalidate by VA range, EL3, Inner/Outer Shareable.
5341 * Currently handles all of RVAE3IS, RVAE3OS, RVALE3IS and RVALE3OS,
5342 * since we don't support flush-for-specific-ASID-only,
5343 * flush-last-level-only or inner/outer specific flushes.
5346 do_rvae_write(env
, value
, ARMMMUIdxBit_E3
, true);
5349 static void tlbi_aa64_ripas2e1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5352 do_rvae_write(env
, value
, ipas2e1_tlbmask(env
, value
),
5353 tlb_force_broadcast(env
));
5356 static void tlbi_aa64_ripas2e1is_write(CPUARMState
*env
,
5357 const ARMCPRegInfo
*ri
,
5360 do_rvae_write(env
, value
, ipas2e1_tlbmask(env
, value
), true);
5364 static CPAccessResult
aa64_zva_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5367 int cur_el
= arm_current_el(env
);
5370 uint64_t hcr
= arm_hcr_el2_eff(env
);
5373 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
5374 if (!(env
->cp15
.sctlr_el
[2] & SCTLR_DZE
)) {
5375 return CP_ACCESS_TRAP_EL2
;
5378 if (!(env
->cp15
.sctlr_el
[1] & SCTLR_DZE
)) {
5379 return CP_ACCESS_TRAP
;
5381 if (hcr
& HCR_TDZ
) {
5382 return CP_ACCESS_TRAP_EL2
;
5385 } else if (hcr
& HCR_TDZ
) {
5386 return CP_ACCESS_TRAP_EL2
;
5389 return CP_ACCESS_OK
;
5392 static uint64_t aa64_dczid_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
5394 ARMCPU
*cpu
= env_archcpu(env
);
5395 int dzp_bit
= 1 << 4;
5397 /* DZP indicates whether DC ZVA access is allowed */
5398 if (aa64_zva_access(env
, NULL
, false) == CP_ACCESS_OK
) {
5401 return cpu
->dcz_blocksize
| dzp_bit
;
5404 static CPAccessResult
sp_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5407 if (!(env
->pstate
& PSTATE_SP
)) {
5409 * Access to SP_EL0 is undefined if it's being used as
5410 * the stack pointer.
5412 return CP_ACCESS_TRAP_UNCATEGORIZED
;
5414 return CP_ACCESS_OK
;
5417 static uint64_t spsel_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
5419 return env
->pstate
& PSTATE_SP
;
5422 static void spsel_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
5424 update_spsel(env
, val
);
5427 static void sctlr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5430 ARMCPU
*cpu
= env_archcpu(env
);
5432 if (arm_feature(env
, ARM_FEATURE_PMSA
) && !cpu
->has_mpu
) {
5433 /* M bit is RAZ/WI for PMSA with no MPU implemented */
5437 /* ??? Lots of these bits are not implemented. */
5439 if (ri
->state
== ARM_CP_STATE_AA64
&& !cpu_isar_feature(aa64_mte
, cpu
)) {
5440 if (ri
->opc1
== 6) { /* SCTLR_EL3 */
5441 value
&= ~(SCTLR_ITFSB
| SCTLR_TCF
| SCTLR_ATA
);
5443 value
&= ~(SCTLR_ITFSB
| SCTLR_TCF0
| SCTLR_TCF
|
5444 SCTLR_ATA0
| SCTLR_ATA
);
5448 if (raw_read(env
, ri
) == value
) {
5450 * Skip the TLB flush if nothing actually changed; Linux likes
5451 * to do a lot of pointless SCTLR writes.
5456 raw_write(env
, ri
, value
);
5458 /* This may enable/disable the MMU, so do a TLB flush. */
5459 tlb_flush(CPU(cpu
));
5461 if (tcg_enabled() && ri
->type
& ARM_CP_SUPPRESS_TB_END
) {
5463 * Normally we would always end the TB on an SCTLR write; see the
5464 * comment in ARMCPRegInfo sctlr initialization below for why Xscale
5465 * is special. Setting ARM_CP_SUPPRESS_TB_END also stops the rebuild
5466 * of hflags from the translator, so do it here.
5468 arm_rebuild_hflags(env
);
5472 static void mdcr_el3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5476 * Some MDCR_EL3 bits affect whether PMU counters are running:
5477 * if we are trying to change any of those then we must
5478 * bracket this update with PMU start/finish calls.
5480 bool pmu_op
= (env
->cp15
.mdcr_el3
^ value
) & MDCR_EL3_PMU_ENABLE_BITS
;
5485 env
->cp15
.mdcr_el3
= value
;
5491 static void sdcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5494 /* Not all bits defined for MDCR_EL3 exist in the AArch32 SDCR */
5495 mdcr_el3_write(env
, ri
, value
& SDCR_VALID_MASK
);
5498 static void mdcr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5502 * Some MDCR_EL2 bits affect whether PMU counters are running:
5503 * if we are trying to change any of those then we must
5504 * bracket this update with PMU start/finish calls.
5506 bool pmu_op
= (env
->cp15
.mdcr_el2
^ value
) & MDCR_EL2_PMU_ENABLE_BITS
;
5511 env
->cp15
.mdcr_el2
= value
;
5517 static CPAccessResult
access_nv1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5520 if (arm_current_el(env
) == 1) {
5521 uint64_t hcr_nv
= arm_hcr_el2_eff(env
) & (HCR_NV
| HCR_NV1
| HCR_NV2
);
5523 if (hcr_nv
== (HCR_NV
| HCR_NV1
)) {
5524 return CP_ACCESS_TRAP_EL2
;
5527 return CP_ACCESS_OK
;
5530 #ifdef CONFIG_USER_ONLY
5532 * `IC IVAU` is handled to improve compatibility with JITs that dual-map their
5533 * code to get around W^X restrictions, where one region is writable and the
5534 * other is executable.
5536 * Since the executable region is never written to we cannot detect code
5537 * changes when running in user mode, and rely on the emulated JIT telling us
5538 * that the code has changed by executing this instruction.
5540 static void ic_ivau_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5543 uint64_t icache_line_mask
, start_address
, end_address
;
5546 cpu
= env_archcpu(env
);
5548 icache_line_mask
= (4 << extract32(cpu
->ctr
, 0, 4)) - 1;
5549 start_address
= value
& ~icache_line_mask
;
5550 end_address
= value
| icache_line_mask
;
5554 tb_invalidate_phys_range(start_address
, end_address
);
5560 static const ARMCPRegInfo v8_cp_reginfo
[] = {
5562 * Minimal set of EL0-visible registers. This will need to be expanded
5563 * significantly for system emulation of AArch64 CPUs.
5565 { .name
= "NZCV", .state
= ARM_CP_STATE_AA64
,
5566 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 2,
5567 .access
= PL0_RW
, .type
= ARM_CP_NZCV
},
5568 { .name
= "DAIF", .state
= ARM_CP_STATE_AA64
,
5569 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 2,
5570 .type
= ARM_CP_NO_RAW
,
5571 .access
= PL0_RW
, .accessfn
= aa64_daif_access
,
5572 .fieldoffset
= offsetof(CPUARMState
, daif
),
5573 .writefn
= aa64_daif_write
, .resetfn
= arm_cp_reset_ignore
},
5574 { .name
= "FPCR", .state
= ARM_CP_STATE_AA64
,
5575 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 4,
5576 .access
= PL0_RW
, .type
= ARM_CP_FPU
| ARM_CP_SUPPRESS_TB_END
,
5577 .readfn
= aa64_fpcr_read
, .writefn
= aa64_fpcr_write
},
5578 { .name
= "FPSR", .state
= ARM_CP_STATE_AA64
,
5579 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 4,
5580 .access
= PL0_RW
, .type
= ARM_CP_FPU
| ARM_CP_SUPPRESS_TB_END
,
5581 .readfn
= aa64_fpsr_read
, .writefn
= aa64_fpsr_write
},
5582 { .name
= "DCZID_EL0", .state
= ARM_CP_STATE_AA64
,
5583 .opc0
= 3, .opc1
= 3, .opc2
= 7, .crn
= 0, .crm
= 0,
5584 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
,
5585 .fgt
= FGT_DCZID_EL0
,
5586 .readfn
= aa64_dczid_read
},
5587 { .name
= "DC_ZVA", .state
= ARM_CP_STATE_AA64
,
5588 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 1,
5589 .access
= PL0_W
, .type
= ARM_CP_DC_ZVA
,
5590 #ifndef CONFIG_USER_ONLY
5591 /* Avoid overhead of an access check that always passes in user-mode */
5592 .accessfn
= aa64_zva_access
,
5596 { .name
= "CURRENTEL", .state
= ARM_CP_STATE_AA64
,
5597 .opc0
= 3, .opc1
= 0, .opc2
= 2, .crn
= 4, .crm
= 2,
5598 .access
= PL1_R
, .type
= ARM_CP_CURRENTEL
},
5600 * Instruction cache ops. All of these except `IC IVAU` NOP because we
5601 * don't emulate caches.
5603 { .name
= "IC_IALLUIS", .state
= ARM_CP_STATE_AA64
,
5604 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
5605 .access
= PL1_W
, .type
= ARM_CP_NOP
,
5606 .fgt
= FGT_ICIALLUIS
,
5607 .accessfn
= access_ticab
},
5608 { .name
= "IC_IALLU", .state
= ARM_CP_STATE_AA64
,
5609 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
5610 .access
= PL1_W
, .type
= ARM_CP_NOP
,
5612 .accessfn
= access_tocu
},
5613 { .name
= "IC_IVAU", .state
= ARM_CP_STATE_AA64
,
5614 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 5, .opc2
= 1,
5617 .accessfn
= access_tocu
,
5618 #ifdef CONFIG_USER_ONLY
5619 .type
= ARM_CP_NO_RAW
,
5620 .writefn
= ic_ivau_write
5625 /* Cache ops: all NOPs since we don't emulate caches */
5626 { .name
= "DC_IVAC", .state
= ARM_CP_STATE_AA64
,
5627 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
5628 .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
,
5630 .type
= ARM_CP_NOP
},
5631 { .name
= "DC_ISW", .state
= ARM_CP_STATE_AA64
,
5632 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
5634 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
5635 { .name
= "DC_CVAC", .state
= ARM_CP_STATE_AA64
,
5636 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 1,
5637 .access
= PL0_W
, .type
= ARM_CP_NOP
,
5639 .accessfn
= aa64_cacheop_poc_access
},
5640 { .name
= "DC_CSW", .state
= ARM_CP_STATE_AA64
,
5641 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
5643 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
5644 { .name
= "DC_CVAU", .state
= ARM_CP_STATE_AA64
,
5645 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 11, .opc2
= 1,
5646 .access
= PL0_W
, .type
= ARM_CP_NOP
,
5648 .accessfn
= access_tocu
},
5649 { .name
= "DC_CIVAC", .state
= ARM_CP_STATE_AA64
,
5650 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 1,
5651 .access
= PL0_W
, .type
= ARM_CP_NOP
,
5653 .accessfn
= aa64_cacheop_poc_access
},
5654 { .name
= "DC_CISW", .state
= ARM_CP_STATE_AA64
,
5655 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
5657 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
5658 /* TLBI operations */
5659 { .name
= "TLBI_VMALLE1IS", .state
= ARM_CP_STATE_AA64
,
5660 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
5661 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5662 .fgt
= FGT_TLBIVMALLE1IS
,
5663 .writefn
= tlbi_aa64_vmalle1is_write
},
5664 { .name
= "TLBI_VAE1IS", .state
= ARM_CP_STATE_AA64
,
5665 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
5666 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5667 .fgt
= FGT_TLBIVAE1IS
,
5668 .writefn
= tlbi_aa64_vae1is_write
},
5669 { .name
= "TLBI_ASIDE1IS", .state
= ARM_CP_STATE_AA64
,
5670 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
5671 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5672 .fgt
= FGT_TLBIASIDE1IS
,
5673 .writefn
= tlbi_aa64_vmalle1is_write
},
5674 { .name
= "TLBI_VAAE1IS", .state
= ARM_CP_STATE_AA64
,
5675 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
5676 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5677 .fgt
= FGT_TLBIVAAE1IS
,
5678 .writefn
= tlbi_aa64_vae1is_write
},
5679 { .name
= "TLBI_VALE1IS", .state
= ARM_CP_STATE_AA64
,
5680 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
5681 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5682 .fgt
= FGT_TLBIVALE1IS
,
5683 .writefn
= tlbi_aa64_vae1is_write
},
5684 { .name
= "TLBI_VAALE1IS", .state
= ARM_CP_STATE_AA64
,
5685 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
5686 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5687 .fgt
= FGT_TLBIVAALE1IS
,
5688 .writefn
= tlbi_aa64_vae1is_write
},
5689 { .name
= "TLBI_VMALLE1", .state
= ARM_CP_STATE_AA64
,
5690 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
5691 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5692 .fgt
= FGT_TLBIVMALLE1
,
5693 .writefn
= tlbi_aa64_vmalle1_write
},
5694 { .name
= "TLBI_VAE1", .state
= ARM_CP_STATE_AA64
,
5695 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
5696 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5697 .fgt
= FGT_TLBIVAE1
,
5698 .writefn
= tlbi_aa64_vae1_write
},
5699 { .name
= "TLBI_ASIDE1", .state
= ARM_CP_STATE_AA64
,
5700 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
5701 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5702 .fgt
= FGT_TLBIASIDE1
,
5703 .writefn
= tlbi_aa64_vmalle1_write
},
5704 { .name
= "TLBI_VAAE1", .state
= ARM_CP_STATE_AA64
,
5705 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
5706 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5707 .fgt
= FGT_TLBIVAAE1
,
5708 .writefn
= tlbi_aa64_vae1_write
},
5709 { .name
= "TLBI_VALE1", .state
= ARM_CP_STATE_AA64
,
5710 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
5711 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5712 .fgt
= FGT_TLBIVALE1
,
5713 .writefn
= tlbi_aa64_vae1_write
},
5714 { .name
= "TLBI_VAALE1", .state
= ARM_CP_STATE_AA64
,
5715 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
5716 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5717 .fgt
= FGT_TLBIVAALE1
,
5718 .writefn
= tlbi_aa64_vae1_write
},
5719 { .name
= "TLBI_IPAS2E1IS", .state
= ARM_CP_STATE_AA64
,
5720 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
5721 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5722 .writefn
= tlbi_aa64_ipas2e1is_write
},
5723 { .name
= "TLBI_IPAS2LE1IS", .state
= ARM_CP_STATE_AA64
,
5724 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
5725 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5726 .writefn
= tlbi_aa64_ipas2e1is_write
},
5727 { .name
= "TLBI_ALLE1IS", .state
= ARM_CP_STATE_AA64
,
5728 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
5729 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5730 .writefn
= tlbi_aa64_alle1is_write
},
5731 { .name
= "TLBI_VMALLS12E1IS", .state
= ARM_CP_STATE_AA64
,
5732 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 6,
5733 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5734 .writefn
= tlbi_aa64_alle1is_write
},
5735 { .name
= "TLBI_IPAS2E1", .state
= ARM_CP_STATE_AA64
,
5736 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
5737 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5738 .writefn
= tlbi_aa64_ipas2e1_write
},
5739 { .name
= "TLBI_IPAS2LE1", .state
= ARM_CP_STATE_AA64
,
5740 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
5741 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5742 .writefn
= tlbi_aa64_ipas2e1_write
},
5743 { .name
= "TLBI_ALLE1", .state
= ARM_CP_STATE_AA64
,
5744 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
5745 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5746 .writefn
= tlbi_aa64_alle1_write
},
5747 { .name
= "TLBI_VMALLS12E1", .state
= ARM_CP_STATE_AA64
,
5748 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 6,
5749 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5750 .writefn
= tlbi_aa64_alle1is_write
},
5751 #ifndef CONFIG_USER_ONLY
5752 /* 64 bit address translation operations */
5753 { .name
= "AT_S1E1R", .state
= ARM_CP_STATE_AA64
,
5754 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 0,
5755 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5757 .accessfn
= at_s1e01_access
, .writefn
= ats_write64
},
5758 { .name
= "AT_S1E1W", .state
= ARM_CP_STATE_AA64
,
5759 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 1,
5760 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5762 .accessfn
= at_s1e01_access
, .writefn
= ats_write64
},
5763 { .name
= "AT_S1E0R", .state
= ARM_CP_STATE_AA64
,
5764 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 2,
5765 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5767 .accessfn
= at_s1e01_access
, .writefn
= ats_write64
},
5768 { .name
= "AT_S1E0W", .state
= ARM_CP_STATE_AA64
,
5769 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 3,
5770 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5772 .accessfn
= at_s1e01_access
, .writefn
= ats_write64
},
5773 { .name
= "AT_S12E1R", .state
= ARM_CP_STATE_AA64
,
5774 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 4,
5775 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5776 .accessfn
= at_e012_access
, .writefn
= ats_write64
},
5777 { .name
= "AT_S12E1W", .state
= ARM_CP_STATE_AA64
,
5778 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 5,
5779 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5780 .accessfn
= at_e012_access
, .writefn
= ats_write64
},
5781 { .name
= "AT_S12E0R", .state
= ARM_CP_STATE_AA64
,
5782 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 6,
5783 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5784 .accessfn
= at_e012_access
, .writefn
= ats_write64
},
5785 { .name
= "AT_S12E0W", .state
= ARM_CP_STATE_AA64
,
5786 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 7,
5787 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5788 .accessfn
= at_e012_access
, .writefn
= ats_write64
},
5789 /* AT S1E2* are elsewhere as they UNDEF from EL3 if EL2 is not present */
5790 { .name
= "AT_S1E3R", .state
= ARM_CP_STATE_AA64
,
5791 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 0,
5792 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5793 .writefn
= ats_write64
},
5794 { .name
= "AT_S1E3W", .state
= ARM_CP_STATE_AA64
,
5795 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 1,
5796 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5797 .writefn
= ats_write64
},
5798 { .name
= "PAR_EL1", .state
= ARM_CP_STATE_AA64
,
5799 .type
= ARM_CP_ALIAS
,
5800 .opc0
= 3, .opc1
= 0, .crn
= 7, .crm
= 4, .opc2
= 0,
5801 .access
= PL1_RW
, .resetvalue
= 0,
5803 .fieldoffset
= offsetof(CPUARMState
, cp15
.par_el
[1]),
5804 .writefn
= par_write
},
5806 /* TLB invalidate last level of translation table walk */
5807 { .name
= "TLBIMVALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
5808 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
5809 .writefn
= tlbimva_is_write
},
5810 { .name
= "TLBIMVAALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
5811 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
5812 .writefn
= tlbimvaa_is_write
},
5813 { .name
= "TLBIMVAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
5814 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5815 .writefn
= tlbimva_write
},
5816 { .name
= "TLBIMVAAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
5817 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5818 .writefn
= tlbimvaa_write
},
5819 { .name
= "TLBIMVALH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
5820 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5821 .writefn
= tlbimva_hyp_write
},
5822 { .name
= "TLBIMVALHIS",
5823 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
5824 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5825 .writefn
= tlbimva_hyp_is_write
},
5826 { .name
= "TLBIIPAS2",
5827 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
5828 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5829 .writefn
= tlbiipas2_hyp_write
},
5830 { .name
= "TLBIIPAS2IS",
5831 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
5832 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5833 .writefn
= tlbiipas2is_hyp_write
},
5834 { .name
= "TLBIIPAS2L",
5835 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
5836 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5837 .writefn
= tlbiipas2_hyp_write
},
5838 { .name
= "TLBIIPAS2LIS",
5839 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
5840 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5841 .writefn
= tlbiipas2is_hyp_write
},
5842 /* 32 bit cache operations */
5843 { .name
= "ICIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
5844 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_ticab
},
5845 { .name
= "BPIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 6,
5846 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5847 { .name
= "ICIALLU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
5848 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tocu
},
5849 { .name
= "ICIMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 1,
5850 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tocu
},
5851 { .name
= "BPIALL", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 6,
5852 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5853 { .name
= "BPIMVA", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 7,
5854 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5855 { .name
= "DCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
5856 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5857 { .name
= "DCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
5858 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5859 { .name
= "DCCMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 1,
5860 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5861 { .name
= "DCCSW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
5862 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5863 { .name
= "DCCMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 11, .opc2
= 1,
5864 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tocu
},
5865 { .name
= "DCCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 1,
5866 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5867 { .name
= "DCCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
5868 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5869 /* MMU Domain access control / MPU write buffer control */
5870 { .name
= "DACR", .cp
= 15, .opc1
= 0, .crn
= 3, .crm
= 0, .opc2
= 0,
5871 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
5872 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
5873 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
5874 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
5875 { .name
= "ELR_EL1", .state
= ARM_CP_STATE_AA64
,
5876 .type
= ARM_CP_ALIAS
,
5877 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 1,
5878 .access
= PL1_RW
, .accessfn
= access_nv1
,
5879 .nv2_redirect_offset
= 0x230 | NV2_REDIR_NV1
,
5880 .fieldoffset
= offsetof(CPUARMState
, elr_el
[1]) },
5881 { .name
= "SPSR_EL1", .state
= ARM_CP_STATE_AA64
,
5882 .type
= ARM_CP_ALIAS
,
5883 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 0,
5884 .access
= PL1_RW
, .accessfn
= access_nv1
,
5885 .nv2_redirect_offset
= 0x160 | NV2_REDIR_NV1
,
5886 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_SVC
]) },
5888 * We rely on the access checks not allowing the guest to write to the
5889 * state field when SPSel indicates that it's being used as the stack
5892 { .name
= "SP_EL0", .state
= ARM_CP_STATE_AA64
,
5893 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 1, .opc2
= 0,
5894 .access
= PL1_RW
, .accessfn
= sp_el0_access
,
5895 .type
= ARM_CP_ALIAS
,
5896 .fieldoffset
= offsetof(CPUARMState
, sp_el
[0]) },
5897 { .name
= "SP_EL1", .state
= ARM_CP_STATE_AA64
,
5898 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 1, .opc2
= 0,
5899 .nv2_redirect_offset
= 0x240,
5900 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
| ARM_CP_EL3_NO_EL2_KEEP
,
5901 .fieldoffset
= offsetof(CPUARMState
, sp_el
[1]) },
5902 { .name
= "SPSel", .state
= ARM_CP_STATE_AA64
,
5903 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 0,
5904 .type
= ARM_CP_NO_RAW
,
5905 .access
= PL1_RW
, .readfn
= spsel_read
, .writefn
= spsel_write
},
5906 { .name
= "SPSR_IRQ", .state
= ARM_CP_STATE_AA64
,
5907 .type
= ARM_CP_ALIAS
,
5908 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 0,
5910 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_IRQ
]) },
5911 { .name
= "SPSR_ABT", .state
= ARM_CP_STATE_AA64
,
5912 .type
= ARM_CP_ALIAS
,
5913 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 1,
5915 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_ABT
]) },
5916 { .name
= "SPSR_UND", .state
= ARM_CP_STATE_AA64
,
5917 .type
= ARM_CP_ALIAS
,
5918 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 2,
5920 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_UND
]) },
5921 { .name
= "SPSR_FIQ", .state
= ARM_CP_STATE_AA64
,
5922 .type
= ARM_CP_ALIAS
,
5923 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 3,
5925 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_FIQ
]) },
5926 { .name
= "MDCR_EL3", .state
= ARM_CP_STATE_AA64
,
5928 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 3, .opc2
= 1,
5931 .writefn
= mdcr_el3_write
,
5932 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el3
) },
5933 { .name
= "SDCR", .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
5934 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 3, .opc2
= 1,
5935 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
5936 .writefn
= sdcr_write
,
5937 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.mdcr_el3
) },
5940 /* These are present only when EL1 supports AArch32 */
5941 static const ARMCPRegInfo v8_aa32_el1_reginfo
[] = {
5942 { .name
= "FPEXC32_EL2", .state
= ARM_CP_STATE_AA64
,
5943 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 3, .opc2
= 0,
5945 .type
= ARM_CP_ALIAS
| ARM_CP_FPU
| ARM_CP_EL3_NO_EL2_KEEP
,
5946 .fieldoffset
= offsetof(CPUARMState
, vfp
.xregs
[ARM_VFP_FPEXC
]) },
5947 { .name
= "DACR32_EL2", .state
= ARM_CP_STATE_AA64
,
5948 .opc0
= 3, .opc1
= 4, .crn
= 3, .crm
= 0, .opc2
= 0,
5949 .access
= PL2_RW
, .resetvalue
= 0, .type
= ARM_CP_EL3_NO_EL2_KEEP
,
5950 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
5951 .fieldoffset
= offsetof(CPUARMState
, cp15
.dacr32_el2
) },
5952 { .name
= "IFSR32_EL2", .state
= ARM_CP_STATE_AA64
,
5953 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 0, .opc2
= 1,
5954 .access
= PL2_RW
, .resetvalue
= 0, .type
= ARM_CP_EL3_NO_EL2_KEEP
,
5955 .fieldoffset
= offsetof(CPUARMState
, cp15
.ifsr32_el2
) },
5958 static void do_hcr_write(CPUARMState
*env
, uint64_t value
, uint64_t valid_mask
)
5960 ARMCPU
*cpu
= env_archcpu(env
);
5962 if (arm_feature(env
, ARM_FEATURE_V8
)) {
5963 valid_mask
|= MAKE_64BIT_MASK(0, 34); /* ARMv8.0 */
5965 valid_mask
|= MAKE_64BIT_MASK(0, 28); /* ARMv7VE */
5968 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
5969 valid_mask
&= ~HCR_HCD
;
5970 } else if (cpu
->psci_conduit
!= QEMU_PSCI_CONDUIT_SMC
) {
5972 * Architecturally HCR.TSC is RES0 if EL3 is not implemented.
5973 * However, if we're using the SMC PSCI conduit then QEMU is
5974 * effectively acting like EL3 firmware and so the guest at
5975 * EL2 should retain the ability to prevent EL1 from being
5976 * able to make SMC calls into the ersatz firmware, so in
5977 * that case HCR.TSC should be read/write.
5979 valid_mask
&= ~HCR_TSC
;
5982 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
5983 if (cpu_isar_feature(aa64_vh
, cpu
)) {
5984 valid_mask
|= HCR_E2H
;
5986 if (cpu_isar_feature(aa64_ras
, cpu
)) {
5987 valid_mask
|= HCR_TERR
| HCR_TEA
;
5989 if (cpu_isar_feature(aa64_lor
, cpu
)) {
5990 valid_mask
|= HCR_TLOR
;
5992 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
5993 valid_mask
|= HCR_API
| HCR_APK
;
5995 if (cpu_isar_feature(aa64_mte
, cpu
)) {
5996 valid_mask
|= HCR_ATA
| HCR_DCT
| HCR_TID5
;
5998 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
5999 valid_mask
|= HCR_ENSCXT
;
6001 if (cpu_isar_feature(aa64_fwb
, cpu
)) {
6002 valid_mask
|= HCR_FWB
;
6004 if (cpu_isar_feature(aa64_rme
, cpu
)) {
6005 valid_mask
|= HCR_GPF
;
6007 if (cpu_isar_feature(aa64_nv
, cpu
)) {
6008 valid_mask
|= HCR_NV
| HCR_NV1
| HCR_AT
;
6010 if (cpu_isar_feature(aa64_nv2
, cpu
)) {
6011 valid_mask
|= HCR_NV2
;
6015 if (cpu_isar_feature(any_evt
, cpu
)) {
6016 valid_mask
|= HCR_TTLBIS
| HCR_TTLBOS
| HCR_TICAB
| HCR_TOCU
| HCR_TID4
;
6017 } else if (cpu_isar_feature(any_half_evt
, cpu
)) {
6018 valid_mask
|= HCR_TICAB
| HCR_TOCU
| HCR_TID4
;
6021 /* Clear RES0 bits. */
6022 value
&= valid_mask
;
6025 * These bits change the MMU setup:
6026 * HCR_VM enables stage 2 translation
6027 * HCR_PTW forbids certain page-table setups
6028 * HCR_DC disables stage1 and enables stage2 translation
6029 * HCR_DCT enables tagging on (disabled) stage1 translation
6030 * HCR_FWB changes the interpretation of stage2 descriptor bits
6031 * HCR_NV and HCR_NV1 affect interpretation of descriptor bits
6033 if ((env
->cp15
.hcr_el2
^ value
) &
6034 (HCR_VM
| HCR_PTW
| HCR_DC
| HCR_DCT
| HCR_FWB
| HCR_NV
| HCR_NV1
)) {
6035 tlb_flush(CPU(cpu
));
6037 env
->cp15
.hcr_el2
= value
;
6040 * Updates to VI and VF require us to update the status of
6041 * virtual interrupts, which are the logical OR of these bits
6042 * and the state of the input lines from the GIC. (This requires
6043 * that we have the BQL, which is done by marking the
6044 * reginfo structs as ARM_CP_IO.)
6045 * Note that if a write to HCR pends a VIRQ or VFIQ it is never
6046 * possible for it to be taken immediately, because VIRQ and
6047 * VFIQ are masked unless running at EL0 or EL1, and HCR
6048 * can only be written at EL2.
6050 g_assert(bql_locked());
6051 arm_cpu_update_virq(cpu
);
6052 arm_cpu_update_vfiq(cpu
);
6053 arm_cpu_update_vserr(cpu
);
6056 static void hcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
6058 do_hcr_write(env
, value
, 0);
6061 static void hcr_writehigh(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6064 /* Handle HCR2 write, i.e. write to high half of HCR_EL2 */
6065 value
= deposit64(env
->cp15
.hcr_el2
, 32, 32, value
);
6066 do_hcr_write(env
, value
, MAKE_64BIT_MASK(0, 32));
6069 static void hcr_writelow(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6072 /* Handle HCR write, i.e. write to low half of HCR_EL2 */
6073 value
= deposit64(env
->cp15
.hcr_el2
, 0, 32, value
);
6074 do_hcr_write(env
, value
, MAKE_64BIT_MASK(32, 32));
6078 * Return the effective value of HCR_EL2, at the given security state.
6079 * Bits that are not included here:
6080 * RW (read from SCR_EL3.RW as needed)
6082 uint64_t arm_hcr_el2_eff_secstate(CPUARMState
*env
, ARMSecuritySpace space
)
6084 uint64_t ret
= env
->cp15
.hcr_el2
;
6086 assert(space
!= ARMSS_Root
);
6088 if (!arm_is_el2_enabled_secstate(env
, space
)) {
6090 * "This register has no effect if EL2 is not enabled in the
6091 * current Security state". This is ARMv8.4-SecEL2 speak for
6092 * !(SCR_EL3.NS==1 || SCR_EL3.EEL2==1).
6094 * Prior to that, the language was "In an implementation that
6095 * includes EL3, when the value of SCR_EL3.NS is 0 the PE behaves
6096 * as if this field is 0 for all purposes other than a direct
6097 * read or write access of HCR_EL2". With lots of enumeration
6098 * on a per-field basis. In current QEMU, this is condition
6099 * is arm_is_secure_below_el3.
6101 * Since the v8.4 language applies to the entire register, and
6102 * appears to be backward compatible, use that.
6108 * For a cpu that supports both aarch64 and aarch32, we can set bits
6109 * in HCR_EL2 (e.g. via EL3) that are RES0 when we enter EL2 as aa32.
6110 * Ignore all of the bits in HCR+HCR2 that are not valid for aarch32.
6112 if (!arm_el_is_aa64(env
, 2)) {
6113 uint64_t aa32_valid
;
6116 * These bits are up-to-date as of ARMv8.6.
6117 * For HCR, it's easiest to list just the 2 bits that are invalid.
6118 * For HCR2, list those that are valid.
6120 aa32_valid
= MAKE_64BIT_MASK(0, 32) & ~(HCR_RW
| HCR_TDZ
);
6121 aa32_valid
|= (HCR_CD
| HCR_ID
| HCR_TERR
| HCR_TEA
| HCR_MIOCNCE
|
6122 HCR_TID4
| HCR_TICAB
| HCR_TOCU
| HCR_TTLBIS
);
6126 if (ret
& HCR_TGE
) {
6127 /* These bits are up-to-date as of ARMv8.6. */
6128 if (ret
& HCR_E2H
) {
6129 ret
&= ~(HCR_VM
| HCR_FMO
| HCR_IMO
| HCR_AMO
|
6130 HCR_BSU_MASK
| HCR_DC
| HCR_TWI
| HCR_TWE
|
6131 HCR_TID0
| HCR_TID2
| HCR_TPCP
| HCR_TPU
|
6132 HCR_TDZ
| HCR_CD
| HCR_ID
| HCR_MIOCNCE
|
6133 HCR_TID4
| HCR_TICAB
| HCR_TOCU
| HCR_ENSCXT
|
6134 HCR_TTLBIS
| HCR_TTLBOS
| HCR_TID5
);
6136 ret
|= HCR_FMO
| HCR_IMO
| HCR_AMO
;
6138 ret
&= ~(HCR_SWIO
| HCR_PTW
| HCR_VF
| HCR_VI
| HCR_VSE
|
6139 HCR_FB
| HCR_TID1
| HCR_TID3
| HCR_TSC
| HCR_TACR
|
6140 HCR_TSW
| HCR_TTLB
| HCR_TVM
| HCR_HCD
| HCR_TRVM
|
6147 uint64_t arm_hcr_el2_eff(CPUARMState
*env
)
6149 if (arm_feature(env
, ARM_FEATURE_M
)) {
6152 return arm_hcr_el2_eff_secstate(env
, arm_security_space_below_el3(env
));
6156 * Corresponds to ARM pseudocode function ELIsInHost().
6158 bool el_is_in_host(CPUARMState
*env
, int el
)
6163 * Since we only care about E2H and TGE, we can skip arm_hcr_el2_eff().
6164 * Perform the simplest bit tests first, and validate EL2 afterward.
6167 return false; /* EL1 or EL3 */
6171 * Note that hcr_write() checks isar_feature_aa64_vh(),
6172 * aka HaveVirtHostExt(), in allowing HCR_E2H to be set.
6174 mask
= el
? HCR_E2H
: HCR_E2H
| HCR_TGE
;
6175 if ((env
->cp15
.hcr_el2
& mask
) != mask
) {
6179 /* TGE and/or E2H set: double check those bits are currently legal. */
6180 return arm_is_el2_enabled(env
) && arm_el_is_aa64(env
, 2);
6183 static void hcrx_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6186 uint64_t valid_mask
= 0;
6188 /* FEAT_MOPS adds MSCEn and MCE2 */
6189 if (cpu_isar_feature(aa64_mops
, env_archcpu(env
))) {
6190 valid_mask
|= HCRX_MSCEN
| HCRX_MCE2
;
6193 /* Clear RES0 bits. */
6194 env
->cp15
.hcrx_el2
= value
& valid_mask
;
6197 static CPAccessResult
access_hxen(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6200 if (arm_current_el(env
) == 2
6201 && arm_feature(env
, ARM_FEATURE_EL3
)
6202 && !(env
->cp15
.scr_el3
& SCR_HXEN
)) {
6203 return CP_ACCESS_TRAP_EL3
;
6205 return CP_ACCESS_OK
;
6208 static const ARMCPRegInfo hcrx_el2_reginfo
= {
6209 .name
= "HCRX_EL2", .state
= ARM_CP_STATE_AA64
,
6210 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 2,
6211 .access
= PL2_RW
, .writefn
= hcrx_write
, .accessfn
= access_hxen
,
6212 .nv2_redirect_offset
= 0xa0,
6213 .fieldoffset
= offsetof(CPUARMState
, cp15
.hcrx_el2
),
6216 /* Return the effective value of HCRX_EL2. */
6217 uint64_t arm_hcrx_el2_eff(CPUARMState
*env
)
6220 * The bits in this register behave as 0 for all purposes other than
6221 * direct reads of the register if SCR_EL3.HXEn is 0.
6222 * If EL2 is not enabled in the current security state, then the
6223 * bit may behave as if 0, or as if 1, depending on the bit.
6224 * For the moment, we treat the EL2-disabled case as taking
6225 * priority over the HXEn-disabled case. This is true for the only
6226 * bit for a feature which we implement where the answer is different
6227 * for the two cases (MSCEn for FEAT_MOPS).
6228 * This may need to be revisited for future bits.
6230 if (!arm_is_el2_enabled(env
)) {
6232 if (cpu_isar_feature(aa64_mops
, env_archcpu(env
))) {
6233 /* MSCEn behaves as 1 if EL2 is not enabled */
6238 if (arm_feature(env
, ARM_FEATURE_EL3
) && !(env
->cp15
.scr_el3
& SCR_HXEN
)) {
6241 return env
->cp15
.hcrx_el2
;
6244 static void cptr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6248 * For A-profile AArch32 EL3, if NSACR.CP10
6249 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
6251 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
6252 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
6253 uint64_t mask
= R_HCPTR_TCP11_MASK
| R_HCPTR_TCP10_MASK
;
6254 value
= (value
& ~mask
) | (env
->cp15
.cptr_el
[2] & mask
);
6256 env
->cp15
.cptr_el
[2] = value
;
6259 static uint64_t cptr_el2_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6262 * For A-profile AArch32 EL3, if NSACR.CP10
6263 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
6265 uint64_t value
= env
->cp15
.cptr_el
[2];
6267 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
6268 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
6269 value
|= R_HCPTR_TCP11_MASK
| R_HCPTR_TCP10_MASK
;
6274 static const ARMCPRegInfo el2_cp_reginfo
[] = {
6275 { .name
= "HCR_EL2", .state
= ARM_CP_STATE_AA64
,
6277 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
6278 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.hcr_el2
),
6279 .nv2_redirect_offset
= 0x78,
6280 .writefn
= hcr_write
, .raw_writefn
= raw_write
},
6281 { .name
= "HCR", .state
= ARM_CP_STATE_AA32
,
6282 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
6283 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
6284 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.hcr_el2
),
6285 .writefn
= hcr_writelow
},
6286 { .name
= "HACR_EL2", .state
= ARM_CP_STATE_BOTH
,
6287 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 7,
6288 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6289 { .name
= "ELR_EL2", .state
= ARM_CP_STATE_AA64
,
6290 .type
= ARM_CP_ALIAS
| ARM_CP_NV2_REDIRECT
,
6291 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 1,
6293 .fieldoffset
= offsetof(CPUARMState
, elr_el
[2]) },
6294 { .name
= "ESR_EL2", .state
= ARM_CP_STATE_BOTH
,
6295 .type
= ARM_CP_NV2_REDIRECT
,
6296 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 2, .opc2
= 0,
6297 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[2]) },
6298 { .name
= "FAR_EL2", .state
= ARM_CP_STATE_BOTH
,
6299 .type
= ARM_CP_NV2_REDIRECT
,
6300 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 0,
6301 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[2]) },
6302 { .name
= "HIFAR", .state
= ARM_CP_STATE_AA32
,
6303 .type
= ARM_CP_ALIAS
,
6304 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 2,
6306 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.far_el
[2]) },
6307 { .name
= "SPSR_EL2", .state
= ARM_CP_STATE_AA64
,
6308 .type
= ARM_CP_ALIAS
| ARM_CP_NV2_REDIRECT
,
6309 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 0,
6311 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_HYP
]) },
6312 { .name
= "VBAR_EL2", .state
= ARM_CP_STATE_BOTH
,
6313 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 0,
6314 .access
= PL2_RW
, .writefn
= vbar_write
,
6315 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[2]),
6317 { .name
= "SP_EL2", .state
= ARM_CP_STATE_AA64
,
6318 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 1, .opc2
= 0,
6319 .access
= PL3_RW
, .type
= ARM_CP_ALIAS
,
6320 .fieldoffset
= offsetof(CPUARMState
, sp_el
[2]) },
6321 { .name
= "CPTR_EL2", .state
= ARM_CP_STATE_BOTH
,
6322 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 2,
6323 .access
= PL2_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
6324 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[2]),
6325 .readfn
= cptr_el2_read
, .writefn
= cptr_el2_write
},
6326 { .name
= "MAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
6327 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 0,
6328 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[2]),
6330 { .name
= "HMAIR1", .state
= ARM_CP_STATE_AA32
,
6331 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 1,
6332 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
,
6333 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.mair_el
[2]) },
6334 { .name
= "AMAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
6335 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 0,
6336 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
6338 /* HAMAIR1 is mapped to AMAIR_EL2[63:32] */
6339 { .name
= "HAMAIR1", .state
= ARM_CP_STATE_AA32
,
6340 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 1,
6341 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
6343 { .name
= "AFSR0_EL2", .state
= ARM_CP_STATE_BOTH
,
6344 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 0,
6345 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
6347 { .name
= "AFSR1_EL2", .state
= ARM_CP_STATE_BOTH
,
6348 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 1,
6349 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
6351 { .name
= "TCR_EL2", .state
= ARM_CP_STATE_BOTH
,
6352 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 2,
6353 .access
= PL2_RW
, .writefn
= vmsa_tcr_el12_write
,
6354 .raw_writefn
= raw_write
,
6355 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[2]) },
6356 { .name
= "VTCR", .state
= ARM_CP_STATE_AA32
,
6357 .cp
= 15, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
6358 .type
= ARM_CP_ALIAS
,
6359 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
6360 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vtcr_el2
) },
6361 { .name
= "VTCR_EL2", .state
= ARM_CP_STATE_AA64
,
6362 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
6364 .nv2_redirect_offset
= 0x40,
6365 /* no .writefn needed as this can't cause an ASID change */
6366 .fieldoffset
= offsetof(CPUARMState
, cp15
.vtcr_el2
) },
6367 { .name
= "VTTBR", .state
= ARM_CP_STATE_AA32
,
6368 .cp
= 15, .opc1
= 6, .crm
= 2,
6369 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
6370 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
6371 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
),
6372 .writefn
= vttbr_write
, .raw_writefn
= raw_write
},
6373 { .name
= "VTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
6374 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 0,
6375 .access
= PL2_RW
, .writefn
= vttbr_write
, .raw_writefn
= raw_write
,
6376 .nv2_redirect_offset
= 0x20,
6377 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
) },
6378 { .name
= "SCTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
6379 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 0,
6380 .access
= PL2_RW
, .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
6381 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[2]) },
6382 { .name
= "TPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
6383 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 2,
6384 .access
= PL2_RW
, .resetvalue
= 0,
6385 .nv2_redirect_offset
= 0x90,
6386 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[2]) },
6387 { .name
= "TTBR0_EL2", .state
= ARM_CP_STATE_AA64
,
6388 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 0,
6389 .access
= PL2_RW
, .resetvalue
= 0,
6390 .writefn
= vmsa_tcr_ttbr_el2_write
, .raw_writefn
= raw_write
,
6391 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
6392 { .name
= "HTTBR", .cp
= 15, .opc1
= 4, .crm
= 2,
6393 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
6394 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
6395 { .name
= "TLBIALLNSNH",
6396 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
6397 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6398 .writefn
= tlbiall_nsnh_write
},
6399 { .name
= "TLBIALLNSNHIS",
6400 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
6401 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6402 .writefn
= tlbiall_nsnh_is_write
},
6403 { .name
= "TLBIALLH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
6404 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6405 .writefn
= tlbiall_hyp_write
},
6406 { .name
= "TLBIALLHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
6407 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6408 .writefn
= tlbiall_hyp_is_write
},
6409 { .name
= "TLBIMVAH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
6410 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6411 .writefn
= tlbimva_hyp_write
},
6412 { .name
= "TLBIMVAHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
6413 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6414 .writefn
= tlbimva_hyp_is_write
},
6415 { .name
= "TLBI_ALLE2", .state
= ARM_CP_STATE_AA64
,
6416 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
6417 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6418 .writefn
= tlbi_aa64_alle2_write
},
6419 { .name
= "TLBI_VAE2", .state
= ARM_CP_STATE_AA64
,
6420 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
6421 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6422 .writefn
= tlbi_aa64_vae2_write
},
6423 { .name
= "TLBI_VALE2", .state
= ARM_CP_STATE_AA64
,
6424 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
6425 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6426 .writefn
= tlbi_aa64_vae2_write
},
6427 { .name
= "TLBI_ALLE2IS", .state
= ARM_CP_STATE_AA64
,
6428 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
6429 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6430 .writefn
= tlbi_aa64_alle2is_write
},
6431 { .name
= "TLBI_VAE2IS", .state
= ARM_CP_STATE_AA64
,
6432 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
6433 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6434 .writefn
= tlbi_aa64_vae2is_write
},
6435 { .name
= "TLBI_VALE2IS", .state
= ARM_CP_STATE_AA64
,
6436 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
6437 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6438 .writefn
= tlbi_aa64_vae2is_write
},
6439 #ifndef CONFIG_USER_ONLY
6441 * Unlike the other EL2-related AT operations, these must
6442 * UNDEF from EL3 if EL2 is not implemented, which is why we
6443 * define them here rather than with the rest of the AT ops.
6445 { .name
= "AT_S1E2R", .state
= ARM_CP_STATE_AA64
,
6446 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
6447 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
6448 .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
| ARM_CP_EL3_NO_EL2_UNDEF
,
6449 .writefn
= ats_write64
},
6450 { .name
= "AT_S1E2W", .state
= ARM_CP_STATE_AA64
,
6451 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
6452 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
6453 .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
| ARM_CP_EL3_NO_EL2_UNDEF
,
6454 .writefn
= ats_write64
},
6456 * The AArch32 ATS1H* operations are CONSTRAINED UNPREDICTABLE
6457 * if EL2 is not implemented; we choose to UNDEF. Behaviour at EL3
6458 * with SCR.NS == 0 outside Monitor mode is UNPREDICTABLE; we choose
6459 * to behave as if SCR.NS was 1.
6461 { .name
= "ATS1HR", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
6463 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
6464 { .name
= "ATS1HW", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
6466 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
6467 { .name
= "CNTHCTL_EL2", .state
= ARM_CP_STATE_BOTH
,
6468 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 1, .opc2
= 0,
6470 * ARMv7 requires bit 0 and 1 to reset to 1. ARMv8 defines the
6471 * reset values as IMPDEF. We choose to reset to 3 to comply with
6472 * both ARMv7 and ARMv8.
6474 .access
= PL2_RW
, .type
= ARM_CP_IO
, .resetvalue
= 3,
6475 .writefn
= gt_cnthctl_write
, .raw_writefn
= raw_write
,
6476 .fieldoffset
= offsetof(CPUARMState
, cp15
.cnthctl_el2
) },
6477 { .name
= "CNTVOFF_EL2", .state
= ARM_CP_STATE_AA64
,
6478 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 0, .opc2
= 3,
6479 .access
= PL2_RW
, .type
= ARM_CP_IO
, .resetvalue
= 0,
6480 .writefn
= gt_cntvoff_write
,
6481 .nv2_redirect_offset
= 0x60,
6482 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
6483 { .name
= "CNTVOFF", .cp
= 15, .opc1
= 4, .crm
= 14,
6484 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
| ARM_CP_IO
,
6485 .writefn
= gt_cntvoff_write
,
6486 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
6487 { .name
= "CNTHP_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
6488 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 2,
6489 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
6490 .type
= ARM_CP_IO
, .access
= PL2_RW
,
6491 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
6492 { .name
= "CNTHP_CVAL", .cp
= 15, .opc1
= 6, .crm
= 14,
6493 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
6494 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_IO
,
6495 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
6496 { .name
= "CNTHP_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
6497 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 0,
6498 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL2_RW
,
6499 .resetfn
= gt_hyp_timer_reset
,
6500 .readfn
= gt_hyp_tval_read
, .writefn
= gt_hyp_tval_write
},
6501 { .name
= "CNTHP_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
6503 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 1,
6505 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].ctl
),
6507 .writefn
= gt_hyp_ctl_write
, .raw_writefn
= raw_write
},
6509 { .name
= "HPFAR", .state
= ARM_CP_STATE_AA32
,
6510 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
6511 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
6512 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
6513 { .name
= "HPFAR_EL2", .state
= ARM_CP_STATE_AA64
,
6514 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
6516 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
6517 { .name
= "HSTR_EL2", .state
= ARM_CP_STATE_BOTH
,
6518 .cp
= 15, .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 3,
6520 .nv2_redirect_offset
= 0x80,
6521 .fieldoffset
= offsetof(CPUARMState
, cp15
.hstr_el2
) },
6524 static const ARMCPRegInfo el2_v8_cp_reginfo
[] = {
6525 { .name
= "HCR2", .state
= ARM_CP_STATE_AA32
,
6526 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
6527 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 4,
6529 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.hcr_el2
),
6530 .writefn
= hcr_writehigh
},
6533 static CPAccessResult
sel2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6536 if (arm_current_el(env
) == 3 || arm_is_secure_below_el3(env
)) {
6537 return CP_ACCESS_OK
;
6539 return CP_ACCESS_TRAP_UNCATEGORIZED
;
6542 static const ARMCPRegInfo el2_sec_cp_reginfo
[] = {
6543 { .name
= "VSTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
6544 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 6, .opc2
= 0,
6545 .access
= PL2_RW
, .accessfn
= sel2_access
,
6546 .nv2_redirect_offset
= 0x30,
6547 .fieldoffset
= offsetof(CPUARMState
, cp15
.vsttbr_el2
) },
6548 { .name
= "VSTCR_EL2", .state
= ARM_CP_STATE_AA64
,
6549 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 6, .opc2
= 2,
6550 .access
= PL2_RW
, .accessfn
= sel2_access
,
6551 .nv2_redirect_offset
= 0x48,
6552 .fieldoffset
= offsetof(CPUARMState
, cp15
.vstcr_el2
) },
6555 static CPAccessResult
nsacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6559 * The NSACR is RW at EL3, and RO for NS EL1 and NS EL2.
6560 * At Secure EL1 it traps to EL3 or EL2.
6562 if (arm_current_el(env
) == 3) {
6563 return CP_ACCESS_OK
;
6565 if (arm_is_secure_below_el3(env
)) {
6566 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
6567 return CP_ACCESS_TRAP_EL2
;
6569 return CP_ACCESS_TRAP_EL3
;
6571 /* Accesses from EL1 NS and EL2 NS are UNDEF for write but allow reads. */
6573 return CP_ACCESS_OK
;
6575 return CP_ACCESS_TRAP_UNCATEGORIZED
;
6578 static const ARMCPRegInfo el3_cp_reginfo
[] = {
6579 { .name
= "SCR_EL3", .state
= ARM_CP_STATE_AA64
,
6580 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 0,
6581 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.scr_el3
),
6582 .resetfn
= scr_reset
, .writefn
= scr_write
, .raw_writefn
= raw_write
},
6583 { .name
= "SCR", .type
= ARM_CP_ALIAS
| ARM_CP_NEWEL
,
6584 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 0,
6585 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
6586 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.scr_el3
),
6587 .writefn
= scr_write
, .raw_writefn
= raw_write
},
6588 { .name
= "SDER32_EL3", .state
= ARM_CP_STATE_AA64
,
6589 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 1,
6590 .access
= PL3_RW
, .resetvalue
= 0,
6591 .fieldoffset
= offsetof(CPUARMState
, cp15
.sder
) },
6593 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 1,
6594 .access
= PL3_RW
, .resetvalue
= 0,
6595 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.sder
) },
6596 { .name
= "MVBAR", .cp
= 15, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
6597 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
6598 .writefn
= vbar_write
, .resetvalue
= 0,
6599 .fieldoffset
= offsetof(CPUARMState
, cp15
.mvbar
) },
6600 { .name
= "TTBR0_EL3", .state
= ARM_CP_STATE_AA64
,
6601 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 0,
6602 .access
= PL3_RW
, .resetvalue
= 0,
6603 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[3]) },
6604 { .name
= "TCR_EL3", .state
= ARM_CP_STATE_AA64
,
6605 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 2,
6607 /* no .writefn needed as this can't cause an ASID change */
6609 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[3]) },
6610 { .name
= "ELR_EL3", .state
= ARM_CP_STATE_AA64
,
6611 .type
= ARM_CP_ALIAS
,
6612 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 1,
6614 .fieldoffset
= offsetof(CPUARMState
, elr_el
[3]) },
6615 { .name
= "ESR_EL3", .state
= ARM_CP_STATE_AA64
,
6616 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 2, .opc2
= 0,
6617 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[3]) },
6618 { .name
= "FAR_EL3", .state
= ARM_CP_STATE_AA64
,
6619 .opc0
= 3, .opc1
= 6, .crn
= 6, .crm
= 0, .opc2
= 0,
6620 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[3]) },
6621 { .name
= "SPSR_EL3", .state
= ARM_CP_STATE_AA64
,
6622 .type
= ARM_CP_ALIAS
,
6623 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 0,
6625 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_MON
]) },
6626 { .name
= "VBAR_EL3", .state
= ARM_CP_STATE_AA64
,
6627 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 0,
6628 .access
= PL3_RW
, .writefn
= vbar_write
,
6629 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[3]),
6631 { .name
= "CPTR_EL3", .state
= ARM_CP_STATE_AA64
,
6632 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 2,
6633 .access
= PL3_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
6634 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[3]) },
6635 { .name
= "TPIDR_EL3", .state
= ARM_CP_STATE_AA64
,
6636 .opc0
= 3, .opc1
= 6, .crn
= 13, .crm
= 0, .opc2
= 2,
6637 .access
= PL3_RW
, .resetvalue
= 0,
6638 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[3]) },
6639 { .name
= "AMAIR_EL3", .state
= ARM_CP_STATE_AA64
,
6640 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 3, .opc2
= 0,
6641 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
6643 { .name
= "AFSR0_EL3", .state
= ARM_CP_STATE_BOTH
,
6644 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 0,
6645 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
6647 { .name
= "AFSR1_EL3", .state
= ARM_CP_STATE_BOTH
,
6648 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 1,
6649 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
6651 { .name
= "TLBI_ALLE3IS", .state
= ARM_CP_STATE_AA64
,
6652 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 0,
6653 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6654 .writefn
= tlbi_aa64_alle3is_write
},
6655 { .name
= "TLBI_VAE3IS", .state
= ARM_CP_STATE_AA64
,
6656 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 1,
6657 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6658 .writefn
= tlbi_aa64_vae3is_write
},
6659 { .name
= "TLBI_VALE3IS", .state
= ARM_CP_STATE_AA64
,
6660 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 5,
6661 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6662 .writefn
= tlbi_aa64_vae3is_write
},
6663 { .name
= "TLBI_ALLE3", .state
= ARM_CP_STATE_AA64
,
6664 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 0,
6665 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6666 .writefn
= tlbi_aa64_alle3_write
},
6667 { .name
= "TLBI_VAE3", .state
= ARM_CP_STATE_AA64
,
6668 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 1,
6669 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6670 .writefn
= tlbi_aa64_vae3_write
},
6671 { .name
= "TLBI_VALE3", .state
= ARM_CP_STATE_AA64
,
6672 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 5,
6673 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6674 .writefn
= tlbi_aa64_vae3_write
},
6677 #ifndef CONFIG_USER_ONLY
6679 static CPAccessResult
e2h_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6682 if (arm_current_el(env
) == 1) {
6683 /* This must be a FEAT_NV access */
6684 return CP_ACCESS_OK
;
6686 if (!(arm_hcr_el2_eff(env
) & HCR_E2H
)) {
6687 return CP_ACCESS_TRAP_UNCATEGORIZED
;
6689 return CP_ACCESS_OK
;
6692 static CPAccessResult
access_el1nvpct(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6695 if (arm_current_el(env
) == 1) {
6696 /* This must be a FEAT_NV access with NVx == 101 */
6697 if (FIELD_EX64(env
->cp15
.cnthctl_el2
, CNTHCTL
, EL1NVPCT
)) {
6698 return CP_ACCESS_TRAP_EL2
;
6701 return e2h_access(env
, ri
, isread
);
6704 static CPAccessResult
access_el1nvvct(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6707 if (arm_current_el(env
) == 1) {
6708 /* This must be a FEAT_NV access with NVx == 101 */
6709 if (FIELD_EX64(env
->cp15
.cnthctl_el2
, CNTHCTL
, EL1NVVCT
)) {
6710 return CP_ACCESS_TRAP_EL2
;
6713 return e2h_access(env
, ri
, isread
);
6716 /* Test if system register redirection is to occur in the current state. */
6717 static bool redirect_for_e2h(CPUARMState
*env
)
6719 return arm_current_el(env
) == 2 && (arm_hcr_el2_eff(env
) & HCR_E2H
);
6722 static uint64_t el2_e2h_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6726 if (redirect_for_e2h(env
)) {
6727 /* Switch to the saved EL2 version of the register. */
6729 readfn
= ri
->readfn
;
6731 readfn
= ri
->orig_readfn
;
6733 if (readfn
== NULL
) {
6736 return readfn(env
, ri
);
6739 static void el2_e2h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6744 if (redirect_for_e2h(env
)) {
6745 /* Switch to the saved EL2 version of the register. */
6747 writefn
= ri
->writefn
;
6749 writefn
= ri
->orig_writefn
;
6751 if (writefn
== NULL
) {
6752 writefn
= raw_write
;
6754 writefn(env
, ri
, value
);
6757 static uint64_t el2_e2h_e12_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6759 /* Pass the EL1 register accessor its ri, not the EL12 alias ri */
6760 return ri
->orig_readfn(env
, ri
->opaque
);
6763 static void el2_e2h_e12_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6766 /* Pass the EL1 register accessor its ri, not the EL12 alias ri */
6767 return ri
->orig_writefn(env
, ri
->opaque
, value
);
6770 static CPAccessResult
el2_e2h_e12_access(CPUARMState
*env
,
6771 const ARMCPRegInfo
*ri
,
6774 if (arm_current_el(env
) == 1) {
6776 * This must be a FEAT_NV access (will either trap or redirect
6777 * to memory). None of the registers with _EL12 aliases want to
6778 * apply their trap controls for this kind of access, so don't
6779 * call the orig_accessfn or do the "UNDEF when E2H is 0" check.
6781 return CP_ACCESS_OK
;
6783 /* FOO_EL12 aliases only exist when E2H is 1; otherwise they UNDEF */
6784 if (!(arm_hcr_el2_eff(env
) & HCR_E2H
)) {
6785 return CP_ACCESS_TRAP_UNCATEGORIZED
;
6787 if (ri
->orig_accessfn
) {
6788 return ri
->orig_accessfn(env
, ri
->opaque
, isread
);
6790 return CP_ACCESS_OK
;
6793 static void define_arm_vh_e2h_redirects_aliases(ARMCPU
*cpu
)
6796 uint32_t src_key
, dst_key
, new_key
;
6797 const char *src_name
, *dst_name
, *new_name
;
6798 bool (*feature
)(const ARMISARegisters
*id
);
6801 #define K(op0, op1, crn, crm, op2) \
6802 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP, crn, crm, op0, op1, op2)
6804 static const struct E2HAlias aliases
[] = {
6805 { K(3, 0, 1, 0, 0), K(3, 4, 1, 0, 0), K(3, 5, 1, 0, 0),
6806 "SCTLR", "SCTLR_EL2", "SCTLR_EL12" },
6807 { K(3, 0, 1, 0, 2), K(3, 4, 1, 1, 2), K(3, 5, 1, 0, 2),
6808 "CPACR", "CPTR_EL2", "CPACR_EL12" },
6809 { K(3, 0, 2, 0, 0), K(3, 4, 2, 0, 0), K(3, 5, 2, 0, 0),
6810 "TTBR0_EL1", "TTBR0_EL2", "TTBR0_EL12" },
6811 { K(3, 0, 2, 0, 1), K(3, 4, 2, 0, 1), K(3, 5, 2, 0, 1),
6812 "TTBR1_EL1", "TTBR1_EL2", "TTBR1_EL12" },
6813 { K(3, 0, 2, 0, 2), K(3, 4, 2, 0, 2), K(3, 5, 2, 0, 2),
6814 "TCR_EL1", "TCR_EL2", "TCR_EL12" },
6815 { K(3, 0, 4, 0, 0), K(3, 4, 4, 0, 0), K(3, 5, 4, 0, 0),
6816 "SPSR_EL1", "SPSR_EL2", "SPSR_EL12" },
6817 { K(3, 0, 4, 0, 1), K(3, 4, 4, 0, 1), K(3, 5, 4, 0, 1),
6818 "ELR_EL1", "ELR_EL2", "ELR_EL12" },
6819 { K(3, 0, 5, 1, 0), K(3, 4, 5, 1, 0), K(3, 5, 5, 1, 0),
6820 "AFSR0_EL1", "AFSR0_EL2", "AFSR0_EL12" },
6821 { K(3, 0, 5, 1, 1), K(3, 4, 5, 1, 1), K(3, 5, 5, 1, 1),
6822 "AFSR1_EL1", "AFSR1_EL2", "AFSR1_EL12" },
6823 { K(3, 0, 5, 2, 0), K(3, 4, 5, 2, 0), K(3, 5, 5, 2, 0),
6824 "ESR_EL1", "ESR_EL2", "ESR_EL12" },
6825 { K(3, 0, 6, 0, 0), K(3, 4, 6, 0, 0), K(3, 5, 6, 0, 0),
6826 "FAR_EL1", "FAR_EL2", "FAR_EL12" },
6827 { K(3, 0, 10, 2, 0), K(3, 4, 10, 2, 0), K(3, 5, 10, 2, 0),
6828 "MAIR_EL1", "MAIR_EL2", "MAIR_EL12" },
6829 { K(3, 0, 10, 3, 0), K(3, 4, 10, 3, 0), K(3, 5, 10, 3, 0),
6830 "AMAIR0", "AMAIR_EL2", "AMAIR_EL12" },
6831 { K(3, 0, 12, 0, 0), K(3, 4, 12, 0, 0), K(3, 5, 12, 0, 0),
6832 "VBAR", "VBAR_EL2", "VBAR_EL12" },
6833 { K(3, 0, 13, 0, 1), K(3, 4, 13, 0, 1), K(3, 5, 13, 0, 1),
6834 "CONTEXTIDR_EL1", "CONTEXTIDR_EL2", "CONTEXTIDR_EL12" },
6835 { K(3, 0, 14, 1, 0), K(3, 4, 14, 1, 0), K(3, 5, 14, 1, 0),
6836 "CNTKCTL", "CNTHCTL_EL2", "CNTKCTL_EL12" },
6839 * Note that redirection of ZCR is mentioned in the description
6840 * of ZCR_EL2, and aliasing in the description of ZCR_EL1, but
6841 * not in the summary table.
6843 { K(3, 0, 1, 2, 0), K(3, 4, 1, 2, 0), K(3, 5, 1, 2, 0),
6844 "ZCR_EL1", "ZCR_EL2", "ZCR_EL12", isar_feature_aa64_sve
},
6845 { K(3, 0, 1, 2, 6), K(3, 4, 1, 2, 6), K(3, 5, 1, 2, 6),
6846 "SMCR_EL1", "SMCR_EL2", "SMCR_EL12", isar_feature_aa64_sme
},
6848 { K(3, 0, 5, 6, 0), K(3, 4, 5, 6, 0), K(3, 5, 5, 6, 0),
6849 "TFSR_EL1", "TFSR_EL2", "TFSR_EL12", isar_feature_aa64_mte
},
6851 { K(3, 0, 13, 0, 7), K(3, 4, 13, 0, 7), K(3, 5, 13, 0, 7),
6852 "SCXTNUM_EL1", "SCXTNUM_EL2", "SCXTNUM_EL12",
6853 isar_feature_aa64_scxtnum
},
6855 /* TODO: ARMv8.2-SPE -- PMSCR_EL2 */
6856 /* TODO: ARMv8.4-Trace -- TRFCR_EL2 */
6862 for (i
= 0; i
< ARRAY_SIZE(aliases
); i
++) {
6863 const struct E2HAlias
*a
= &aliases
[i
];
6864 ARMCPRegInfo
*src_reg
, *dst_reg
, *new_reg
;
6867 if (a
->feature
&& !a
->feature(&cpu
->isar
)) {
6871 src_reg
= g_hash_table_lookup(cpu
->cp_regs
,
6872 (gpointer
)(uintptr_t)a
->src_key
);
6873 dst_reg
= g_hash_table_lookup(cpu
->cp_regs
,
6874 (gpointer
)(uintptr_t)a
->dst_key
);
6875 g_assert(src_reg
!= NULL
);
6876 g_assert(dst_reg
!= NULL
);
6878 /* Cross-compare names to detect typos in the keys. */
6879 g_assert(strcmp(src_reg
->name
, a
->src_name
) == 0);
6880 g_assert(strcmp(dst_reg
->name
, a
->dst_name
) == 0);
6882 /* None of the core system registers use opaque; we will. */
6883 g_assert(src_reg
->opaque
== NULL
);
6885 /* Create alias before redirection so we dup the right data. */
6886 new_reg
= g_memdup(src_reg
, sizeof(ARMCPRegInfo
));
6888 new_reg
->name
= a
->new_name
;
6889 new_reg
->type
|= ARM_CP_ALIAS
;
6890 /* Remove PL1/PL0 access, leaving PL2/PL3 R/W in place. */
6891 new_reg
->access
&= PL2_RW
| PL3_RW
;
6892 /* The new_reg op fields are as per new_key, not the target reg */
6893 new_reg
->crn
= (a
->new_key
& CP_REG_ARM64_SYSREG_CRN_MASK
)
6894 >> CP_REG_ARM64_SYSREG_CRN_SHIFT
;
6895 new_reg
->crm
= (a
->new_key
& CP_REG_ARM64_SYSREG_CRM_MASK
)
6896 >> CP_REG_ARM64_SYSREG_CRM_SHIFT
;
6897 new_reg
->opc0
= (a
->new_key
& CP_REG_ARM64_SYSREG_OP0_MASK
)
6898 >> CP_REG_ARM64_SYSREG_OP0_SHIFT
;
6899 new_reg
->opc1
= (a
->new_key
& CP_REG_ARM64_SYSREG_OP1_MASK
)
6900 >> CP_REG_ARM64_SYSREG_OP1_SHIFT
;
6901 new_reg
->opc2
= (a
->new_key
& CP_REG_ARM64_SYSREG_OP2_MASK
)
6902 >> CP_REG_ARM64_SYSREG_OP2_SHIFT
;
6903 new_reg
->opaque
= src_reg
;
6904 new_reg
->orig_readfn
= src_reg
->readfn
?: raw_read
;
6905 new_reg
->orig_writefn
= src_reg
->writefn
?: raw_write
;
6906 new_reg
->orig_accessfn
= src_reg
->accessfn
;
6907 if (!new_reg
->raw_readfn
) {
6908 new_reg
->raw_readfn
= raw_read
;
6910 if (!new_reg
->raw_writefn
) {
6911 new_reg
->raw_writefn
= raw_write
;
6913 new_reg
->readfn
= el2_e2h_e12_read
;
6914 new_reg
->writefn
= el2_e2h_e12_write
;
6915 new_reg
->accessfn
= el2_e2h_e12_access
;
6918 * If the _EL1 register is redirected to memory by FEAT_NV2,
6919 * then it shares the offset with the _EL12 register,
6920 * and which one is redirected depends on HCR_EL2.NV1.
6922 if (new_reg
->nv2_redirect_offset
) {
6923 assert(new_reg
->nv2_redirect_offset
& NV2_REDIR_NV1
);
6924 new_reg
->nv2_redirect_offset
&= ~NV2_REDIR_NV1
;
6925 new_reg
->nv2_redirect_offset
|= NV2_REDIR_NO_NV1
;
6928 ok
= g_hash_table_insert(cpu
->cp_regs
,
6929 (gpointer
)(uintptr_t)a
->new_key
, new_reg
);
6932 src_reg
->opaque
= dst_reg
;
6933 src_reg
->orig_readfn
= src_reg
->readfn
?: raw_read
;
6934 src_reg
->orig_writefn
= src_reg
->writefn
?: raw_write
;
6935 if (!src_reg
->raw_readfn
) {
6936 src_reg
->raw_readfn
= raw_read
;
6938 if (!src_reg
->raw_writefn
) {
6939 src_reg
->raw_writefn
= raw_write
;
6941 src_reg
->readfn
= el2_e2h_read
;
6942 src_reg
->writefn
= el2_e2h_write
;
6947 static CPAccessResult
ctr_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6950 int cur_el
= arm_current_el(env
);
6953 uint64_t hcr
= arm_hcr_el2_eff(env
);
6956 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
6957 if (!(env
->cp15
.sctlr_el
[2] & SCTLR_UCT
)) {
6958 return CP_ACCESS_TRAP_EL2
;
6961 if (!(env
->cp15
.sctlr_el
[1] & SCTLR_UCT
)) {
6962 return CP_ACCESS_TRAP
;
6964 if (hcr
& HCR_TID2
) {
6965 return CP_ACCESS_TRAP_EL2
;
6968 } else if (hcr
& HCR_TID2
) {
6969 return CP_ACCESS_TRAP_EL2
;
6973 if (arm_current_el(env
) < 2 && arm_hcr_el2_eff(env
) & HCR_TID2
) {
6974 return CP_ACCESS_TRAP_EL2
;
6977 return CP_ACCESS_OK
;
6981 * Check for traps to RAS registers, which are controlled
6982 * by HCR_EL2.TERR and SCR_EL3.TERR.
6984 static CPAccessResult
access_terr(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6987 int el
= arm_current_el(env
);
6989 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_TERR
)) {
6990 return CP_ACCESS_TRAP_EL2
;
6992 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_TERR
)) {
6993 return CP_ACCESS_TRAP_EL3
;
6995 return CP_ACCESS_OK
;
6998 static uint64_t disr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7000 int el
= arm_current_el(env
);
7002 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_AMO
)) {
7003 return env
->cp15
.vdisr_el2
;
7005 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_EA
)) {
7006 return 0; /* RAZ/WI */
7008 return env
->cp15
.disr_el1
;
7011 static void disr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
7013 int el
= arm_current_el(env
);
7015 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_AMO
)) {
7016 env
->cp15
.vdisr_el2
= val
;
7019 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_EA
)) {
7020 return; /* RAZ/WI */
7022 env
->cp15
.disr_el1
= val
;
7026 * Minimal RAS implementation with no Error Records.
7027 * Which means that all of the Error Record registers:
7035 * ERXPFGCDN_EL1 (RASv1p1)
7036 * ERXPFGCTL_EL1 (RASv1p1)
7037 * ERXPFGF_EL1 (RASv1p1)
7041 * may generate UNDEFINED, which is the effect we get by not
7042 * listing them at all.
7044 * These registers have fine-grained trap bits, but UNDEF-to-EL1
7045 * is higher priority than FGT-to-EL2 so we do not need to list them
7046 * in order to check for an FGT.
7048 static const ARMCPRegInfo minimal_ras_reginfo
[] = {
7049 { .name
= "DISR_EL1", .state
= ARM_CP_STATE_BOTH
,
7050 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 1, .opc2
= 1,
7051 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.disr_el1
),
7052 .readfn
= disr_read
, .writefn
= disr_write
, .raw_writefn
= raw_write
},
7053 { .name
= "ERRIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
7054 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 3, .opc2
= 0,
7055 .access
= PL1_R
, .accessfn
= access_terr
,
7056 .fgt
= FGT_ERRIDR_EL1
,
7057 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7058 { .name
= "VDISR_EL2", .state
= ARM_CP_STATE_BOTH
,
7059 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 1, .opc2
= 1,
7060 .nv2_redirect_offset
= 0x500,
7061 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.vdisr_el2
) },
7062 { .name
= "VSESR_EL2", .state
= ARM_CP_STATE_BOTH
,
7063 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 2, .opc2
= 3,
7064 .nv2_redirect_offset
= 0x508,
7065 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.vsesr_el2
) },
7069 * Return the exception level to which exceptions should be taken
7070 * via SVEAccessTrap. This excludes the check for whether the exception
7071 * should be routed through AArch64.AdvSIMDFPAccessTrap. That can easily
7072 * be found by testing 0 < fp_exception_el < sve_exception_el.
7074 * C.f. the ARM pseudocode function CheckSVEEnabled. Note that the
7075 * pseudocode does *not* separate out the FP trap checks, but has them
7076 * all in one function.
7078 int sve_exception_el(CPUARMState
*env
, int el
)
7080 #ifndef CONFIG_USER_ONLY
7081 if (el
<= 1 && !el_is_in_host(env
, el
)) {
7082 switch (FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, ZEN
)) {
7094 if (el
<= 2 && arm_is_el2_enabled(env
)) {
7095 /* CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE). */
7096 if (env
->cp15
.hcr_el2
& HCR_E2H
) {
7097 switch (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, ZEN
)) {
7099 if (el
!= 0 || !(env
->cp15
.hcr_el2
& HCR_TGE
)) {
7108 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TZ
)) {
7114 /* CPTR_EL3. Since EZ is negative we must check for EL3. */
7115 if (arm_feature(env
, ARM_FEATURE_EL3
)
7116 && !FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, EZ
)) {
7124 * Return the exception level to which exceptions should be taken for SME.
7125 * C.f. the ARM pseudocode function CheckSMEAccess.
7127 int sme_exception_el(CPUARMState
*env
, int el
)
7129 #ifndef CONFIG_USER_ONLY
7130 if (el
<= 1 && !el_is_in_host(env
, el
)) {
7131 switch (FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, SMEN
)) {
7143 if (el
<= 2 && arm_is_el2_enabled(env
)) {
7144 /* CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE). */
7145 if (env
->cp15
.hcr_el2
& HCR_E2H
) {
7146 switch (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, SMEN
)) {
7148 if (el
!= 0 || !(env
->cp15
.hcr_el2
& HCR_TGE
)) {
7157 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TSM
)) {
7163 /* CPTR_EL3. Since ESM is negative we must check for EL3. */
7164 if (arm_feature(env
, ARM_FEATURE_EL3
)
7165 && !FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, ESM
)) {
7173 * Given that SVE is enabled, return the vector length for EL.
7175 uint32_t sve_vqm1_for_el_sm(CPUARMState
*env
, int el
, bool sm
)
7177 ARMCPU
*cpu
= env_archcpu(env
);
7178 uint64_t *cr
= env
->vfp
.zcr_el
;
7179 uint32_t map
= cpu
->sve_vq
.map
;
7180 uint32_t len
= ARM_MAX_VQ
- 1;
7183 cr
= env
->vfp
.smcr_el
;
7184 map
= cpu
->sme_vq
.map
;
7187 if (el
<= 1 && !el_is_in_host(env
, el
)) {
7188 len
= MIN(len
, 0xf & (uint32_t)cr
[1]);
7190 if (el
<= 2 && arm_feature(env
, ARM_FEATURE_EL2
)) {
7191 len
= MIN(len
, 0xf & (uint32_t)cr
[2]);
7193 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
7194 len
= MIN(len
, 0xf & (uint32_t)cr
[3]);
7197 map
&= MAKE_64BIT_MASK(0, len
+ 1);
7199 return 31 - clz32(map
);
7202 /* Bit 0 is always set for Normal SVE -- not so for Streaming SVE. */
7204 return ctz32(cpu
->sme_vq
.map
);
7207 uint32_t sve_vqm1_for_el(CPUARMState
*env
, int el
)
7209 return sve_vqm1_for_el_sm(env
, el
, FIELD_EX64(env
->svcr
, SVCR
, SM
));
7212 static void zcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7215 int cur_el
= arm_current_el(env
);
7216 int old_len
= sve_vqm1_for_el(env
, cur_el
);
7219 /* Bits other than [3:0] are RAZ/WI. */
7220 QEMU_BUILD_BUG_ON(ARM_MAX_VQ
> 16);
7221 raw_write(env
, ri
, value
& 0xf);
7224 * Because we arrived here, we know both FP and SVE are enabled;
7225 * otherwise we would have trapped access to the ZCR_ELn register.
7227 new_len
= sve_vqm1_for_el(env
, cur_el
);
7228 if (new_len
< old_len
) {
7229 aarch64_sve_narrow_vq(env
, new_len
+ 1);
7233 static const ARMCPRegInfo zcr_reginfo
[] = {
7234 { .name
= "ZCR_EL1", .state
= ARM_CP_STATE_AA64
,
7235 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 2, .opc2
= 0,
7236 .nv2_redirect_offset
= 0x1e0 | NV2_REDIR_NV1
,
7237 .access
= PL1_RW
, .type
= ARM_CP_SVE
,
7238 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[1]),
7239 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
7240 { .name
= "ZCR_EL2", .state
= ARM_CP_STATE_AA64
,
7241 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 0,
7242 .access
= PL2_RW
, .type
= ARM_CP_SVE
,
7243 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[2]),
7244 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
7245 { .name
= "ZCR_EL3", .state
= ARM_CP_STATE_AA64
,
7246 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 2, .opc2
= 0,
7247 .access
= PL3_RW
, .type
= ARM_CP_SVE
,
7248 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[3]),
7249 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
7252 #ifdef TARGET_AARCH64
7253 static CPAccessResult
access_tpidr2(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7256 int el
= arm_current_el(env
);
7259 uint64_t sctlr
= arm_sctlr(env
, el
);
7260 if (!(sctlr
& SCTLR_EnTP2
)) {
7261 return CP_ACCESS_TRAP
;
7264 /* TODO: FEAT_FGT */
7266 && arm_feature(env
, ARM_FEATURE_EL3
)
7267 && !(env
->cp15
.scr_el3
& SCR_ENTP2
)) {
7268 return CP_ACCESS_TRAP_EL3
;
7270 return CP_ACCESS_OK
;
7273 static CPAccessResult
access_smprimap(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7276 /* If EL1 this is a FEAT_NV access and CPTR_EL3.ESM doesn't apply */
7277 if (arm_current_el(env
) == 2
7278 && arm_feature(env
, ARM_FEATURE_EL3
)
7279 && !FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, ESM
)) {
7280 return CP_ACCESS_TRAP_EL3
;
7282 return CP_ACCESS_OK
;
7285 static CPAccessResult
access_smpri(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7288 if (arm_current_el(env
) < 3
7289 && arm_feature(env
, ARM_FEATURE_EL3
)
7290 && !FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, ESM
)) {
7291 return CP_ACCESS_TRAP_EL3
;
7293 return CP_ACCESS_OK
;
7297 static void arm_reset_sve_state(CPUARMState
*env
)
7299 memset(env
->vfp
.zregs
, 0, sizeof(env
->vfp
.zregs
));
7300 /* Recall that FFR is stored as pregs[16]. */
7301 memset(env
->vfp
.pregs
, 0, sizeof(env
->vfp
.pregs
));
7302 vfp_set_fpcr(env
, 0x0800009f);
7305 void aarch64_set_svcr(CPUARMState
*env
, uint64_t new, uint64_t mask
)
7307 uint64_t change
= (env
->svcr
^ new) & mask
;
7312 env
->svcr
^= change
;
7314 if (change
& R_SVCR_SM_MASK
) {
7315 arm_reset_sve_state(env
);
7321 * SetPSTATE_ZA zeros on enable and disable. We can zero this only
7322 * on enable: while disabled, the storage is inaccessible and the
7323 * value does not matter. We're not saving the storage in vmstate
7324 * when disabled either.
7326 if (change
& new & R_SVCR_ZA_MASK
) {
7327 memset(env
->zarray
, 0, sizeof(env
->zarray
));
7330 if (tcg_enabled()) {
7331 arm_rebuild_hflags(env
);
7335 static void svcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7338 aarch64_set_svcr(env
, value
, -1);
7341 static void smcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7344 int cur_el
= arm_current_el(env
);
7345 int old_len
= sve_vqm1_for_el(env
, cur_el
);
7348 QEMU_BUILD_BUG_ON(ARM_MAX_VQ
> R_SMCR_LEN_MASK
+ 1);
7349 value
&= R_SMCR_LEN_MASK
| R_SMCR_FA64_MASK
;
7350 raw_write(env
, ri
, value
);
7353 * Note that it is CONSTRAINED UNPREDICTABLE what happens to ZA storage
7354 * when SVL is widened (old values kept, or zeros). Choose to keep the
7355 * current values for simplicity. But for QEMU internals, we must still
7356 * apply the narrower SVL to the Zregs and Pregs -- see the comment
7357 * above aarch64_sve_narrow_vq.
7359 new_len
= sve_vqm1_for_el(env
, cur_el
);
7360 if (new_len
< old_len
) {
7361 aarch64_sve_narrow_vq(env
, new_len
+ 1);
7365 static const ARMCPRegInfo sme_reginfo
[] = {
7366 { .name
= "TPIDR2_EL0", .state
= ARM_CP_STATE_AA64
,
7367 .opc0
= 3, .opc1
= 3, .crn
= 13, .crm
= 0, .opc2
= 5,
7368 .access
= PL0_RW
, .accessfn
= access_tpidr2
,
7369 .fgt
= FGT_NTPIDR2_EL0
,
7370 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr2_el0
) },
7371 { .name
= "SVCR", .state
= ARM_CP_STATE_AA64
,
7372 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 2,
7373 .access
= PL0_RW
, .type
= ARM_CP_SME
,
7374 .fieldoffset
= offsetof(CPUARMState
, svcr
),
7375 .writefn
= svcr_write
, .raw_writefn
= raw_write
},
7376 { .name
= "SMCR_EL1", .state
= ARM_CP_STATE_AA64
,
7377 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 2, .opc2
= 6,
7378 .nv2_redirect_offset
= 0x1f0 | NV2_REDIR_NV1
,
7379 .access
= PL1_RW
, .type
= ARM_CP_SME
,
7380 .fieldoffset
= offsetof(CPUARMState
, vfp
.smcr_el
[1]),
7381 .writefn
= smcr_write
, .raw_writefn
= raw_write
},
7382 { .name
= "SMCR_EL2", .state
= ARM_CP_STATE_AA64
,
7383 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 6,
7384 .access
= PL2_RW
, .type
= ARM_CP_SME
,
7385 .fieldoffset
= offsetof(CPUARMState
, vfp
.smcr_el
[2]),
7386 .writefn
= smcr_write
, .raw_writefn
= raw_write
},
7387 { .name
= "SMCR_EL3", .state
= ARM_CP_STATE_AA64
,
7388 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 2, .opc2
= 6,
7389 .access
= PL3_RW
, .type
= ARM_CP_SME
,
7390 .fieldoffset
= offsetof(CPUARMState
, vfp
.smcr_el
[3]),
7391 .writefn
= smcr_write
, .raw_writefn
= raw_write
},
7392 { .name
= "SMIDR_EL1", .state
= ARM_CP_STATE_AA64
,
7393 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 6,
7394 .access
= PL1_R
, .accessfn
= access_aa64_tid1
,
7396 * IMPLEMENTOR = 0 (software)
7397 * REVISION = 0 (implementation defined)
7398 * SMPS = 0 (no streaming execution priority in QEMU)
7399 * AFFINITY = 0 (streaming sve mode not shared with other PEs)
7401 .type
= ARM_CP_CONST
, .resetvalue
= 0, },
7403 * Because SMIDR_EL1.SMPS is 0, SMPRI_EL1 and SMPRIMAP_EL2 are RES 0.
7405 { .name
= "SMPRI_EL1", .state
= ARM_CP_STATE_AA64
,
7406 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 2, .opc2
= 4,
7407 .access
= PL1_RW
, .accessfn
= access_smpri
,
7408 .fgt
= FGT_NSMPRI_EL1
,
7409 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7410 { .name
= "SMPRIMAP_EL2", .state
= ARM_CP_STATE_AA64
,
7411 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 5,
7412 .nv2_redirect_offset
= 0x1f8,
7413 .access
= PL2_RW
, .accessfn
= access_smprimap
,
7414 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7417 static void tlbi_aa64_paall_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7420 CPUState
*cs
= env_cpu(env
);
7425 static void gpccr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7428 /* L0GPTSZ is RO; other bits not mentioned are RES0. */
7429 uint64_t rw_mask
= R_GPCCR_PPS_MASK
| R_GPCCR_IRGN_MASK
|
7430 R_GPCCR_ORGN_MASK
| R_GPCCR_SH_MASK
| R_GPCCR_PGS_MASK
|
7431 R_GPCCR_GPC_MASK
| R_GPCCR_GPCP_MASK
;
7433 env
->cp15
.gpccr_el3
= (value
& rw_mask
) | (env
->cp15
.gpccr_el3
& ~rw_mask
);
7436 static void gpccr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7438 env
->cp15
.gpccr_el3
= FIELD_DP64(0, GPCCR
, L0GPTSZ
,
7439 env_archcpu(env
)->reset_l0gptsz
);
7442 static void tlbi_aa64_paallos_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7445 CPUState
*cs
= env_cpu(env
);
7447 tlb_flush_all_cpus_synced(cs
);
7450 static const ARMCPRegInfo rme_reginfo
[] = {
7451 { .name
= "GPCCR_EL3", .state
= ARM_CP_STATE_AA64
,
7452 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 1, .opc2
= 6,
7453 .access
= PL3_RW
, .writefn
= gpccr_write
, .resetfn
= gpccr_reset
,
7454 .fieldoffset
= offsetof(CPUARMState
, cp15
.gpccr_el3
) },
7455 { .name
= "GPTBR_EL3", .state
= ARM_CP_STATE_AA64
,
7456 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 1, .opc2
= 4,
7457 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.gptbr_el3
) },
7458 { .name
= "MFAR_EL3", .state
= ARM_CP_STATE_AA64
,
7459 .opc0
= 3, .opc1
= 6, .crn
= 6, .crm
= 0, .opc2
= 5,
7460 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mfar_el3
) },
7461 { .name
= "TLBI_PAALL", .state
= ARM_CP_STATE_AA64
,
7462 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 4,
7463 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7464 .writefn
= tlbi_aa64_paall_write
},
7465 { .name
= "TLBI_PAALLOS", .state
= ARM_CP_STATE_AA64
,
7466 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 4,
7467 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7468 .writefn
= tlbi_aa64_paallos_write
},
7470 * QEMU does not have a way to invalidate by physical address, thus
7471 * invalidating a range of physical addresses is accomplished by
7472 * flushing all tlb entries in the outer shareable domain,
7473 * just like PAALLOS.
7475 { .name
= "TLBI_RPALOS", .state
= ARM_CP_STATE_AA64
,
7476 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 4, .opc2
= 7,
7477 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7478 .writefn
= tlbi_aa64_paallos_write
},
7479 { .name
= "TLBI_RPAOS", .state
= ARM_CP_STATE_AA64
,
7480 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 4, .opc2
= 3,
7481 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7482 .writefn
= tlbi_aa64_paallos_write
},
7483 { .name
= "DC_CIPAPA", .state
= ARM_CP_STATE_AA64
,
7484 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 14, .opc2
= 1,
7485 .access
= PL3_W
, .type
= ARM_CP_NOP
},
7488 static const ARMCPRegInfo rme_mte_reginfo
[] = {
7489 { .name
= "DC_CIGDPAPA", .state
= ARM_CP_STATE_AA64
,
7490 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 14, .opc2
= 5,
7491 .access
= PL3_W
, .type
= ARM_CP_NOP
},
7493 #endif /* TARGET_AARCH64 */
7495 static void define_pmu_regs(ARMCPU
*cpu
)
7498 * v7 performance monitor control register: same implementor
7499 * field as main ID register, and we implement four counters in
7500 * addition to the cycle count register.
7502 unsigned int i
, pmcrn
= pmu_num_counters(&cpu
->env
);
7503 ARMCPRegInfo pmcr
= {
7504 .name
= "PMCR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 0,
7506 .fgt
= FGT_PMCR_EL0
,
7507 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7508 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcr
),
7509 .accessfn
= pmreg_access
,
7510 .readfn
= pmcr_read
, .raw_readfn
= raw_read
,
7511 .writefn
= pmcr_write
, .raw_writefn
= raw_write
,
7513 ARMCPRegInfo pmcr64
= {
7514 .name
= "PMCR_EL0", .state
= ARM_CP_STATE_AA64
,
7515 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 0,
7516 .access
= PL0_RW
, .accessfn
= pmreg_access
,
7517 .fgt
= FGT_PMCR_EL0
,
7519 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcr
),
7520 .resetvalue
= cpu
->isar
.reset_pmcr_el0
,
7521 .readfn
= pmcr_read
, .raw_readfn
= raw_read
,
7522 .writefn
= pmcr_write
, .raw_writefn
= raw_write
,
7525 define_one_arm_cp_reg(cpu
, &pmcr
);
7526 define_one_arm_cp_reg(cpu
, &pmcr64
);
7527 for (i
= 0; i
< pmcrn
; i
++) {
7528 char *pmevcntr_name
= g_strdup_printf("PMEVCNTR%d", i
);
7529 char *pmevcntr_el0_name
= g_strdup_printf("PMEVCNTR%d_EL0", i
);
7530 char *pmevtyper_name
= g_strdup_printf("PMEVTYPER%d", i
);
7531 char *pmevtyper_el0_name
= g_strdup_printf("PMEVTYPER%d_EL0", i
);
7532 ARMCPRegInfo pmev_regs
[] = {
7533 { .name
= pmevcntr_name
, .cp
= 15, .crn
= 14,
7534 .crm
= 8 | (3 & (i
>> 3)), .opc1
= 0, .opc2
= i
& 7,
7535 .access
= PL0_RW
, .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7536 .fgt
= FGT_PMEVCNTRN_EL0
,
7537 .readfn
= pmevcntr_readfn
, .writefn
= pmevcntr_writefn
,
7538 .accessfn
= pmreg_access_xevcntr
},
7539 { .name
= pmevcntr_el0_name
, .state
= ARM_CP_STATE_AA64
,
7540 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 8 | (3 & (i
>> 3)),
7541 .opc2
= i
& 7, .access
= PL0_RW
, .accessfn
= pmreg_access_xevcntr
,
7543 .fgt
= FGT_PMEVCNTRN_EL0
,
7544 .readfn
= pmevcntr_readfn
, .writefn
= pmevcntr_writefn
,
7545 .raw_readfn
= pmevcntr_rawread
,
7546 .raw_writefn
= pmevcntr_rawwrite
},
7547 { .name
= pmevtyper_name
, .cp
= 15, .crn
= 14,
7548 .crm
= 12 | (3 & (i
>> 3)), .opc1
= 0, .opc2
= i
& 7,
7549 .access
= PL0_RW
, .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7550 .fgt
= FGT_PMEVTYPERN_EL0
,
7551 .readfn
= pmevtyper_readfn
, .writefn
= pmevtyper_writefn
,
7552 .accessfn
= pmreg_access
},
7553 { .name
= pmevtyper_el0_name
, .state
= ARM_CP_STATE_AA64
,
7554 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 12 | (3 & (i
>> 3)),
7555 .opc2
= i
& 7, .access
= PL0_RW
, .accessfn
= pmreg_access
,
7556 .fgt
= FGT_PMEVTYPERN_EL0
,
7558 .readfn
= pmevtyper_readfn
, .writefn
= pmevtyper_writefn
,
7559 .raw_writefn
= pmevtyper_rawwrite
},
7561 define_arm_cp_regs(cpu
, pmev_regs
);
7562 g_free(pmevcntr_name
);
7563 g_free(pmevcntr_el0_name
);
7564 g_free(pmevtyper_name
);
7565 g_free(pmevtyper_el0_name
);
7567 if (cpu_isar_feature(aa32_pmuv3p1
, cpu
)) {
7568 ARMCPRegInfo v81_pmu_regs
[] = {
7569 { .name
= "PMCEID2", .state
= ARM_CP_STATE_AA32
,
7570 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 4,
7571 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7572 .fgt
= FGT_PMCEIDN_EL0
,
7573 .resetvalue
= extract64(cpu
->pmceid0
, 32, 32) },
7574 { .name
= "PMCEID3", .state
= ARM_CP_STATE_AA32
,
7575 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 5,
7576 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7577 .fgt
= FGT_PMCEIDN_EL0
,
7578 .resetvalue
= extract64(cpu
->pmceid1
, 32, 32) },
7580 define_arm_cp_regs(cpu
, v81_pmu_regs
);
7582 if (cpu_isar_feature(any_pmuv3p4
, cpu
)) {
7583 static const ARMCPRegInfo v84_pmmir
= {
7584 .name
= "PMMIR_EL1", .state
= ARM_CP_STATE_BOTH
,
7585 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 6,
7586 .access
= PL1_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7587 .fgt
= FGT_PMMIR_EL1
,
7590 define_one_arm_cp_reg(cpu
, &v84_pmmir
);
7594 #ifndef CONFIG_USER_ONLY
7596 * We don't know until after realize whether there's a GICv3
7597 * attached, and that is what registers the gicv3 sysregs.
7598 * So we have to fill in the GIC fields in ID_PFR/ID_PFR1_EL1/ID_AA64PFR0_EL1
7601 static uint64_t id_pfr1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7603 ARMCPU
*cpu
= env_archcpu(env
);
7604 uint64_t pfr1
= cpu
->isar
.id_pfr1
;
7606 if (env
->gicv3state
) {
7612 static uint64_t id_aa64pfr0_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7614 ARMCPU
*cpu
= env_archcpu(env
);
7615 uint64_t pfr0
= cpu
->isar
.id_aa64pfr0
;
7617 if (env
->gicv3state
) {
7625 * Shared logic between LORID and the rest of the LOR* registers.
7626 * Secure state exclusion has already been dealt with.
7628 static CPAccessResult
access_lor_ns(CPUARMState
*env
,
7629 const ARMCPRegInfo
*ri
, bool isread
)
7631 int el
= arm_current_el(env
);
7633 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_TLOR
)) {
7634 return CP_ACCESS_TRAP_EL2
;
7636 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_TLOR
)) {
7637 return CP_ACCESS_TRAP_EL3
;
7639 return CP_ACCESS_OK
;
7642 static CPAccessResult
access_lor_other(CPUARMState
*env
,
7643 const ARMCPRegInfo
*ri
, bool isread
)
7645 if (arm_is_secure_below_el3(env
)) {
7646 /* Access denied in secure mode. */
7647 return CP_ACCESS_TRAP
;
7649 return access_lor_ns(env
, ri
, isread
);
7653 * A trivial implementation of ARMv8.1-LOR leaves all of these
7654 * registers fixed at 0, which indicates that there are zero
7655 * supported Limited Ordering regions.
7657 static const ARMCPRegInfo lor_reginfo
[] = {
7658 { .name
= "LORSA_EL1", .state
= ARM_CP_STATE_AA64
,
7659 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 0,
7660 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7661 .fgt
= FGT_LORSA_EL1
,
7662 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7663 { .name
= "LOREA_EL1", .state
= ARM_CP_STATE_AA64
,
7664 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 1,
7665 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7666 .fgt
= FGT_LOREA_EL1
,
7667 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7668 { .name
= "LORN_EL1", .state
= ARM_CP_STATE_AA64
,
7669 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 2,
7670 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7671 .fgt
= FGT_LORN_EL1
,
7672 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7673 { .name
= "LORC_EL1", .state
= ARM_CP_STATE_AA64
,
7674 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 3,
7675 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7676 .fgt
= FGT_LORC_EL1
,
7677 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7678 { .name
= "LORID_EL1", .state
= ARM_CP_STATE_AA64
,
7679 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 7,
7680 .access
= PL1_R
, .accessfn
= access_lor_ns
,
7681 .fgt
= FGT_LORID_EL1
,
7682 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7685 #ifdef TARGET_AARCH64
7686 static CPAccessResult
access_pauth(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7689 int el
= arm_current_el(env
);
7692 arm_is_el2_enabled(env
) &&
7693 !(arm_hcr_el2_eff(env
) & HCR_APK
)) {
7694 return CP_ACCESS_TRAP_EL2
;
7697 arm_feature(env
, ARM_FEATURE_EL3
) &&
7698 !(env
->cp15
.scr_el3
& SCR_APK
)) {
7699 return CP_ACCESS_TRAP_EL3
;
7701 return CP_ACCESS_OK
;
7704 static const ARMCPRegInfo pauth_reginfo
[] = {
7705 { .name
= "APDAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7706 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 0,
7707 .access
= PL1_RW
, .accessfn
= access_pauth
,
7709 .fieldoffset
= offsetof(CPUARMState
, keys
.apda
.lo
) },
7710 { .name
= "APDAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7711 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 1,
7712 .access
= PL1_RW
, .accessfn
= access_pauth
,
7714 .fieldoffset
= offsetof(CPUARMState
, keys
.apda
.hi
) },
7715 { .name
= "APDBKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7716 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 2,
7717 .access
= PL1_RW
, .accessfn
= access_pauth
,
7719 .fieldoffset
= offsetof(CPUARMState
, keys
.apdb
.lo
) },
7720 { .name
= "APDBKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7721 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 3,
7722 .access
= PL1_RW
, .accessfn
= access_pauth
,
7724 .fieldoffset
= offsetof(CPUARMState
, keys
.apdb
.hi
) },
7725 { .name
= "APGAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7726 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 3, .opc2
= 0,
7727 .access
= PL1_RW
, .accessfn
= access_pauth
,
7729 .fieldoffset
= offsetof(CPUARMState
, keys
.apga
.lo
) },
7730 { .name
= "APGAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7731 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 3, .opc2
= 1,
7732 .access
= PL1_RW
, .accessfn
= access_pauth
,
7734 .fieldoffset
= offsetof(CPUARMState
, keys
.apga
.hi
) },
7735 { .name
= "APIAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7736 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 0,
7737 .access
= PL1_RW
, .accessfn
= access_pauth
,
7739 .fieldoffset
= offsetof(CPUARMState
, keys
.apia
.lo
) },
7740 { .name
= "APIAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7741 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 1,
7742 .access
= PL1_RW
, .accessfn
= access_pauth
,
7744 .fieldoffset
= offsetof(CPUARMState
, keys
.apia
.hi
) },
7745 { .name
= "APIBKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7746 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 2,
7747 .access
= PL1_RW
, .accessfn
= access_pauth
,
7749 .fieldoffset
= offsetof(CPUARMState
, keys
.apib
.lo
) },
7750 { .name
= "APIBKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7751 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 3,
7752 .access
= PL1_RW
, .accessfn
= access_pauth
,
7754 .fieldoffset
= offsetof(CPUARMState
, keys
.apib
.hi
) },
7757 static const ARMCPRegInfo tlbirange_reginfo
[] = {
7758 { .name
= "TLBI_RVAE1IS", .state
= ARM_CP_STATE_AA64
,
7759 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 1,
7760 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
7761 .fgt
= FGT_TLBIRVAE1IS
,
7762 .writefn
= tlbi_aa64_rvae1is_write
},
7763 { .name
= "TLBI_RVAAE1IS", .state
= ARM_CP_STATE_AA64
,
7764 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 3,
7765 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
7766 .fgt
= FGT_TLBIRVAAE1IS
,
7767 .writefn
= tlbi_aa64_rvae1is_write
},
7768 { .name
= "TLBI_RVALE1IS", .state
= ARM_CP_STATE_AA64
,
7769 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 5,
7770 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
7771 .fgt
= FGT_TLBIRVALE1IS
,
7772 .writefn
= tlbi_aa64_rvae1is_write
},
7773 { .name
= "TLBI_RVAALE1IS", .state
= ARM_CP_STATE_AA64
,
7774 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 7,
7775 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
7776 .fgt
= FGT_TLBIRVAALE1IS
,
7777 .writefn
= tlbi_aa64_rvae1is_write
},
7778 { .name
= "TLBI_RVAE1OS", .state
= ARM_CP_STATE_AA64
,
7779 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
7780 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7781 .fgt
= FGT_TLBIRVAE1OS
,
7782 .writefn
= tlbi_aa64_rvae1is_write
},
7783 { .name
= "TLBI_RVAAE1OS", .state
= ARM_CP_STATE_AA64
,
7784 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 3,
7785 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7786 .fgt
= FGT_TLBIRVAAE1OS
,
7787 .writefn
= tlbi_aa64_rvae1is_write
},
7788 { .name
= "TLBI_RVALE1OS", .state
= ARM_CP_STATE_AA64
,
7789 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 5,
7790 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7791 .fgt
= FGT_TLBIRVALE1OS
,
7792 .writefn
= tlbi_aa64_rvae1is_write
},
7793 { .name
= "TLBI_RVAALE1OS", .state
= ARM_CP_STATE_AA64
,
7794 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 7,
7795 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7796 .fgt
= FGT_TLBIRVAALE1OS
,
7797 .writefn
= tlbi_aa64_rvae1is_write
},
7798 { .name
= "TLBI_RVAE1", .state
= ARM_CP_STATE_AA64
,
7799 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
7800 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
7801 .fgt
= FGT_TLBIRVAE1
,
7802 .writefn
= tlbi_aa64_rvae1_write
},
7803 { .name
= "TLBI_RVAAE1", .state
= ARM_CP_STATE_AA64
,
7804 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 3,
7805 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
7806 .fgt
= FGT_TLBIRVAAE1
,
7807 .writefn
= tlbi_aa64_rvae1_write
},
7808 { .name
= "TLBI_RVALE1", .state
= ARM_CP_STATE_AA64
,
7809 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 5,
7810 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
7811 .fgt
= FGT_TLBIRVALE1
,
7812 .writefn
= tlbi_aa64_rvae1_write
},
7813 { .name
= "TLBI_RVAALE1", .state
= ARM_CP_STATE_AA64
,
7814 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 7,
7815 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
7816 .fgt
= FGT_TLBIRVAALE1
,
7817 .writefn
= tlbi_aa64_rvae1_write
},
7818 { .name
= "TLBI_RIPAS2E1IS", .state
= ARM_CP_STATE_AA64
,
7819 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 2,
7820 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7821 .writefn
= tlbi_aa64_ripas2e1is_write
},
7822 { .name
= "TLBI_RIPAS2LE1IS", .state
= ARM_CP_STATE_AA64
,
7823 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 6,
7824 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7825 .writefn
= tlbi_aa64_ripas2e1is_write
},
7826 { .name
= "TLBI_RVAE2IS", .state
= ARM_CP_STATE_AA64
,
7827 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 2, .opc2
= 1,
7828 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7829 .writefn
= tlbi_aa64_rvae2is_write
},
7830 { .name
= "TLBI_RVALE2IS", .state
= ARM_CP_STATE_AA64
,
7831 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 2, .opc2
= 5,
7832 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7833 .writefn
= tlbi_aa64_rvae2is_write
},
7834 { .name
= "TLBI_RIPAS2E1", .state
= ARM_CP_STATE_AA64
,
7835 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 2,
7836 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7837 .writefn
= tlbi_aa64_ripas2e1_write
},
7838 { .name
= "TLBI_RIPAS2LE1", .state
= ARM_CP_STATE_AA64
,
7839 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 6,
7840 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7841 .writefn
= tlbi_aa64_ripas2e1_write
},
7842 { .name
= "TLBI_RVAE2OS", .state
= ARM_CP_STATE_AA64
,
7843 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 5, .opc2
= 1,
7844 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7845 .writefn
= tlbi_aa64_rvae2is_write
},
7846 { .name
= "TLBI_RVALE2OS", .state
= ARM_CP_STATE_AA64
,
7847 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 5, .opc2
= 5,
7848 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7849 .writefn
= tlbi_aa64_rvae2is_write
},
7850 { .name
= "TLBI_RVAE2", .state
= ARM_CP_STATE_AA64
,
7851 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 6, .opc2
= 1,
7852 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7853 .writefn
= tlbi_aa64_rvae2_write
},
7854 { .name
= "TLBI_RVALE2", .state
= ARM_CP_STATE_AA64
,
7855 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 6, .opc2
= 5,
7856 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7857 .writefn
= tlbi_aa64_rvae2_write
},
7858 { .name
= "TLBI_RVAE3IS", .state
= ARM_CP_STATE_AA64
,
7859 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 2, .opc2
= 1,
7860 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7861 .writefn
= tlbi_aa64_rvae3is_write
},
7862 { .name
= "TLBI_RVALE3IS", .state
= ARM_CP_STATE_AA64
,
7863 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 2, .opc2
= 5,
7864 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7865 .writefn
= tlbi_aa64_rvae3is_write
},
7866 { .name
= "TLBI_RVAE3OS", .state
= ARM_CP_STATE_AA64
,
7867 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 5, .opc2
= 1,
7868 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7869 .writefn
= tlbi_aa64_rvae3is_write
},
7870 { .name
= "TLBI_RVALE3OS", .state
= ARM_CP_STATE_AA64
,
7871 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 5, .opc2
= 5,
7872 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7873 .writefn
= tlbi_aa64_rvae3is_write
},
7874 { .name
= "TLBI_RVAE3", .state
= ARM_CP_STATE_AA64
,
7875 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 6, .opc2
= 1,
7876 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7877 .writefn
= tlbi_aa64_rvae3_write
},
7878 { .name
= "TLBI_RVALE3", .state
= ARM_CP_STATE_AA64
,
7879 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 6, .opc2
= 5,
7880 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7881 .writefn
= tlbi_aa64_rvae3_write
},
7884 static const ARMCPRegInfo tlbios_reginfo
[] = {
7885 { .name
= "TLBI_VMALLE1OS", .state
= ARM_CP_STATE_AA64
,
7886 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 0,
7887 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7888 .fgt
= FGT_TLBIVMALLE1OS
,
7889 .writefn
= tlbi_aa64_vmalle1is_write
},
7890 { .name
= "TLBI_VAE1OS", .state
= ARM_CP_STATE_AA64
,
7891 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 1,
7892 .fgt
= FGT_TLBIVAE1OS
,
7893 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7894 .writefn
= tlbi_aa64_vae1is_write
},
7895 { .name
= "TLBI_ASIDE1OS", .state
= ARM_CP_STATE_AA64
,
7896 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 2,
7897 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7898 .fgt
= FGT_TLBIASIDE1OS
,
7899 .writefn
= tlbi_aa64_vmalle1is_write
},
7900 { .name
= "TLBI_VAAE1OS", .state
= ARM_CP_STATE_AA64
,
7901 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 3,
7902 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7903 .fgt
= FGT_TLBIVAAE1OS
,
7904 .writefn
= tlbi_aa64_vae1is_write
},
7905 { .name
= "TLBI_VALE1OS", .state
= ARM_CP_STATE_AA64
,
7906 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 5,
7907 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7908 .fgt
= FGT_TLBIVALE1OS
,
7909 .writefn
= tlbi_aa64_vae1is_write
},
7910 { .name
= "TLBI_VAALE1OS", .state
= ARM_CP_STATE_AA64
,
7911 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 7,
7912 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7913 .fgt
= FGT_TLBIVAALE1OS
,
7914 .writefn
= tlbi_aa64_vae1is_write
},
7915 { .name
= "TLBI_ALLE2OS", .state
= ARM_CP_STATE_AA64
,
7916 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 0,
7917 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7918 .writefn
= tlbi_aa64_alle2is_write
},
7919 { .name
= "TLBI_VAE2OS", .state
= ARM_CP_STATE_AA64
,
7920 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 1,
7921 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7922 .writefn
= tlbi_aa64_vae2is_write
},
7923 { .name
= "TLBI_ALLE1OS", .state
= ARM_CP_STATE_AA64
,
7924 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 4,
7925 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7926 .writefn
= tlbi_aa64_alle1is_write
},
7927 { .name
= "TLBI_VALE2OS", .state
= ARM_CP_STATE_AA64
,
7928 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 5,
7929 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7930 .writefn
= tlbi_aa64_vae2is_write
},
7931 { .name
= "TLBI_VMALLS12E1OS", .state
= ARM_CP_STATE_AA64
,
7932 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 6,
7933 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7934 .writefn
= tlbi_aa64_alle1is_write
},
7935 { .name
= "TLBI_IPAS2E1OS", .state
= ARM_CP_STATE_AA64
,
7936 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 0,
7937 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7938 { .name
= "TLBI_RIPAS2E1OS", .state
= ARM_CP_STATE_AA64
,
7939 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 3,
7940 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7941 { .name
= "TLBI_IPAS2LE1OS", .state
= ARM_CP_STATE_AA64
,
7942 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 4,
7943 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7944 { .name
= "TLBI_RIPAS2LE1OS", .state
= ARM_CP_STATE_AA64
,
7945 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 7,
7946 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7947 { .name
= "TLBI_ALLE3OS", .state
= ARM_CP_STATE_AA64
,
7948 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 0,
7949 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7950 .writefn
= tlbi_aa64_alle3is_write
},
7951 { .name
= "TLBI_VAE3OS", .state
= ARM_CP_STATE_AA64
,
7952 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 1,
7953 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7954 .writefn
= tlbi_aa64_vae3is_write
},
7955 { .name
= "TLBI_VALE3OS", .state
= ARM_CP_STATE_AA64
,
7956 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 5,
7957 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7958 .writefn
= tlbi_aa64_vae3is_write
},
7961 static uint64_t rndr_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7966 /* Success sets NZCV = 0000. */
7967 env
->NF
= env
->CF
= env
->VF
= 0, env
->ZF
= 1;
7969 if (qemu_guest_getrandom(&ret
, sizeof(ret
), &err
) < 0) {
7971 * ??? Failed, for unknown reasons in the crypto subsystem.
7972 * The best we can do is log the reason and return the
7973 * timed-out indication to the guest. There is no reason
7974 * we know to expect this failure to be transitory, so the
7975 * guest may well hang retrying the operation.
7977 qemu_log_mask(LOG_UNIMP
, "%s: Crypto failure: %s",
7978 ri
->name
, error_get_pretty(err
));
7981 env
->ZF
= 0; /* NZCF = 0100 */
7987 /* We do not support re-seeding, so the two registers operate the same. */
7988 static const ARMCPRegInfo rndr_reginfo
[] = {
7989 { .name
= "RNDR", .state
= ARM_CP_STATE_AA64
,
7990 .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
| ARM_CP_IO
,
7991 .opc0
= 3, .opc1
= 3, .crn
= 2, .crm
= 4, .opc2
= 0,
7992 .access
= PL0_R
, .readfn
= rndr_readfn
},
7993 { .name
= "RNDRRS", .state
= ARM_CP_STATE_AA64
,
7994 .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
| ARM_CP_IO
,
7995 .opc0
= 3, .opc1
= 3, .crn
= 2, .crm
= 4, .opc2
= 1,
7996 .access
= PL0_R
, .readfn
= rndr_readfn
},
7999 static void dccvap_writefn(CPUARMState
*env
, const ARMCPRegInfo
*opaque
,
8003 ARMCPU
*cpu
= env_archcpu(env
);
8004 /* CTR_EL0 System register -> DminLine, bits [19:16] */
8005 uint64_t dline_size
= 4 << ((cpu
->ctr
>> 16) & 0xF);
8006 uint64_t vaddr_in
= (uint64_t) value
;
8007 uint64_t vaddr
= vaddr_in
& ~(dline_size
- 1);
8009 int mem_idx
= arm_env_mmu_index(env
);
8011 /* This won't be crossing page boundaries */
8012 haddr
= probe_read(env
, vaddr
, dline_size
, mem_idx
, GETPC());
8014 #ifndef CONFIG_USER_ONLY
8019 /* RCU lock is already being held */
8020 mr
= memory_region_from_host(haddr
, &offset
);
8023 memory_region_writeback(mr
, offset
, dline_size
);
8025 #endif /*CONFIG_USER_ONLY*/
8028 /* Handled by hardware accelerator. */
8029 g_assert_not_reached();
8030 #endif /* CONFIG_TCG */
8033 static const ARMCPRegInfo dcpop_reg
[] = {
8034 { .name
= "DC_CVAP", .state
= ARM_CP_STATE_AA64
,
8035 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 1,
8036 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
,
8038 .accessfn
= aa64_cacheop_poc_access
, .writefn
= dccvap_writefn
},
8041 static const ARMCPRegInfo dcpodp_reg
[] = {
8042 { .name
= "DC_CVADP", .state
= ARM_CP_STATE_AA64
,
8043 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 1,
8044 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
,
8046 .accessfn
= aa64_cacheop_poc_access
, .writefn
= dccvap_writefn
},
8049 static CPAccessResult
access_aa64_tid5(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8052 if ((arm_current_el(env
) < 2) && (arm_hcr_el2_eff(env
) & HCR_TID5
)) {
8053 return CP_ACCESS_TRAP_EL2
;
8056 return CP_ACCESS_OK
;
8059 static CPAccessResult
access_mte(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8062 int el
= arm_current_el(env
);
8063 if (el
< 2 && arm_is_el2_enabled(env
)) {
8064 uint64_t hcr
= arm_hcr_el2_eff(env
);
8065 if (!(hcr
& HCR_ATA
) && (!(hcr
& HCR_E2H
) || !(hcr
& HCR_TGE
))) {
8066 return CP_ACCESS_TRAP_EL2
;
8070 arm_feature(env
, ARM_FEATURE_EL3
) &&
8071 !(env
->cp15
.scr_el3
& SCR_ATA
)) {
8072 return CP_ACCESS_TRAP_EL3
;
8074 return CP_ACCESS_OK
;
8077 static CPAccessResult
access_tfsr_el1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8080 CPAccessResult nv1
= access_nv1(env
, ri
, isread
);
8082 if (nv1
!= CP_ACCESS_OK
) {
8085 return access_mte(env
, ri
, isread
);
8088 static CPAccessResult
access_tfsr_el2(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8092 * TFSR_EL2: similar to generic access_mte(), but we need to
8093 * account for FEAT_NV. At EL1 this must be a FEAT_NV access;
8094 * if NV2 is enabled then we will redirect this to TFSR_EL1
8095 * after doing the HCR and SCR ATA traps; otherwise this will
8096 * be a trap to EL2 and the HCR/SCR traps do not apply.
8098 int el
= arm_current_el(env
);
8100 if (el
== 1 && (arm_hcr_el2_eff(env
) & HCR_NV2
)) {
8101 return CP_ACCESS_OK
;
8103 if (el
< 2 && arm_is_el2_enabled(env
)) {
8104 uint64_t hcr
= arm_hcr_el2_eff(env
);
8105 if (!(hcr
& HCR_ATA
) && (!(hcr
& HCR_E2H
) || !(hcr
& HCR_TGE
))) {
8106 return CP_ACCESS_TRAP_EL2
;
8110 arm_feature(env
, ARM_FEATURE_EL3
) &&
8111 !(env
->cp15
.scr_el3
& SCR_ATA
)) {
8112 return CP_ACCESS_TRAP_EL3
;
8114 return CP_ACCESS_OK
;
8117 static uint64_t tco_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
8119 return env
->pstate
& PSTATE_TCO
;
8122 static void tco_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
8124 env
->pstate
= (env
->pstate
& ~PSTATE_TCO
) | (val
& PSTATE_TCO
);
8127 static const ARMCPRegInfo mte_reginfo
[] = {
8128 { .name
= "TFSRE0_EL1", .state
= ARM_CP_STATE_AA64
,
8129 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 6, .opc2
= 1,
8130 .access
= PL1_RW
, .accessfn
= access_mte
,
8131 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[0]) },
8132 { .name
= "TFSR_EL1", .state
= ARM_CP_STATE_AA64
,
8133 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 6, .opc2
= 0,
8134 .access
= PL1_RW
, .accessfn
= access_tfsr_el1
,
8135 .nv2_redirect_offset
= 0x190 | NV2_REDIR_NV1
,
8136 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[1]) },
8137 { .name
= "TFSR_EL2", .state
= ARM_CP_STATE_AA64
,
8138 .type
= ARM_CP_NV2_REDIRECT
,
8139 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 6, .opc2
= 0,
8140 .access
= PL2_RW
, .accessfn
= access_tfsr_el2
,
8141 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[2]) },
8142 { .name
= "TFSR_EL3", .state
= ARM_CP_STATE_AA64
,
8143 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 6, .opc2
= 0,
8145 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[3]) },
8146 { .name
= "RGSR_EL1", .state
= ARM_CP_STATE_AA64
,
8147 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 5,
8148 .access
= PL1_RW
, .accessfn
= access_mte
,
8149 .fieldoffset
= offsetof(CPUARMState
, cp15
.rgsr_el1
) },
8150 { .name
= "GCR_EL1", .state
= ARM_CP_STATE_AA64
,
8151 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 6,
8152 .access
= PL1_RW
, .accessfn
= access_mte
,
8153 .fieldoffset
= offsetof(CPUARMState
, cp15
.gcr_el1
) },
8154 { .name
= "TCO", .state
= ARM_CP_STATE_AA64
,
8155 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 7,
8156 .type
= ARM_CP_NO_RAW
,
8157 .access
= PL0_RW
, .readfn
= tco_read
, .writefn
= tco_write
},
8158 { .name
= "DC_IGVAC", .state
= ARM_CP_STATE_AA64
,
8159 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 3,
8160 .type
= ARM_CP_NOP
, .access
= PL1_W
,
8162 .accessfn
= aa64_cacheop_poc_access
},
8163 { .name
= "DC_IGSW", .state
= ARM_CP_STATE_AA64
,
8164 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 4,
8166 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
8167 { .name
= "DC_IGDVAC", .state
= ARM_CP_STATE_AA64
,
8168 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 5,
8169 .type
= ARM_CP_NOP
, .access
= PL1_W
,
8171 .accessfn
= aa64_cacheop_poc_access
},
8172 { .name
= "DC_IGDSW", .state
= ARM_CP_STATE_AA64
,
8173 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 6,
8175 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
8176 { .name
= "DC_CGSW", .state
= ARM_CP_STATE_AA64
,
8177 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 4,
8179 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
8180 { .name
= "DC_CGDSW", .state
= ARM_CP_STATE_AA64
,
8181 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 6,
8183 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
8184 { .name
= "DC_CIGSW", .state
= ARM_CP_STATE_AA64
,
8185 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 4,
8187 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
8188 { .name
= "DC_CIGDSW", .state
= ARM_CP_STATE_AA64
,
8189 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 6,
8191 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
8194 static const ARMCPRegInfo mte_tco_ro_reginfo
[] = {
8195 { .name
= "TCO", .state
= ARM_CP_STATE_AA64
,
8196 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 7,
8197 .type
= ARM_CP_CONST
, .access
= PL0_RW
, },
8200 static const ARMCPRegInfo mte_el0_cacheop_reginfo
[] = {
8201 { .name
= "DC_CGVAC", .state
= ARM_CP_STATE_AA64
,
8202 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 3,
8203 .type
= ARM_CP_NOP
, .access
= PL0_W
,
8205 .accessfn
= aa64_cacheop_poc_access
},
8206 { .name
= "DC_CGDVAC", .state
= ARM_CP_STATE_AA64
,
8207 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 5,
8208 .type
= ARM_CP_NOP
, .access
= PL0_W
,
8210 .accessfn
= aa64_cacheop_poc_access
},
8211 { .name
= "DC_CGVAP", .state
= ARM_CP_STATE_AA64
,
8212 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 3,
8213 .type
= ARM_CP_NOP
, .access
= PL0_W
,
8215 .accessfn
= aa64_cacheop_poc_access
},
8216 { .name
= "DC_CGDVAP", .state
= ARM_CP_STATE_AA64
,
8217 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 5,
8218 .type
= ARM_CP_NOP
, .access
= PL0_W
,
8220 .accessfn
= aa64_cacheop_poc_access
},
8221 { .name
= "DC_CGVADP", .state
= ARM_CP_STATE_AA64
,
8222 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 3,
8223 .type
= ARM_CP_NOP
, .access
= PL0_W
,
8225 .accessfn
= aa64_cacheop_poc_access
},
8226 { .name
= "DC_CGDVADP", .state
= ARM_CP_STATE_AA64
,
8227 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 5,
8228 .type
= ARM_CP_NOP
, .access
= PL0_W
,
8230 .accessfn
= aa64_cacheop_poc_access
},
8231 { .name
= "DC_CIGVAC", .state
= ARM_CP_STATE_AA64
,
8232 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 3,
8233 .type
= ARM_CP_NOP
, .access
= PL0_W
,
8235 .accessfn
= aa64_cacheop_poc_access
},
8236 { .name
= "DC_CIGDVAC", .state
= ARM_CP_STATE_AA64
,
8237 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 5,
8238 .type
= ARM_CP_NOP
, .access
= PL0_W
,
8240 .accessfn
= aa64_cacheop_poc_access
},
8241 { .name
= "DC_GVA", .state
= ARM_CP_STATE_AA64
,
8242 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 3,
8243 .access
= PL0_W
, .type
= ARM_CP_DC_GVA
,
8244 #ifndef CONFIG_USER_ONLY
8245 /* Avoid overhead of an access check that always passes in user-mode */
8246 .accessfn
= aa64_zva_access
,
8250 { .name
= "DC_GZVA", .state
= ARM_CP_STATE_AA64
,
8251 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 4,
8252 .access
= PL0_W
, .type
= ARM_CP_DC_GZVA
,
8253 #ifndef CONFIG_USER_ONLY
8254 /* Avoid overhead of an access check that always passes in user-mode */
8255 .accessfn
= aa64_zva_access
,
8261 static CPAccessResult
access_scxtnum(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8264 uint64_t hcr
= arm_hcr_el2_eff(env
);
8265 int el
= arm_current_el(env
);
8267 if (el
== 0 && !((hcr
& HCR_E2H
) && (hcr
& HCR_TGE
))) {
8268 if (env
->cp15
.sctlr_el
[1] & SCTLR_TSCXT
) {
8269 if (hcr
& HCR_TGE
) {
8270 return CP_ACCESS_TRAP_EL2
;
8272 return CP_ACCESS_TRAP
;
8274 } else if (el
< 2 && (env
->cp15
.sctlr_el
[2] & SCTLR_TSCXT
)) {
8275 return CP_ACCESS_TRAP_EL2
;
8277 if (el
< 2 && arm_is_el2_enabled(env
) && !(hcr
& HCR_ENSCXT
)) {
8278 return CP_ACCESS_TRAP_EL2
;
8281 && arm_feature(env
, ARM_FEATURE_EL3
)
8282 && !(env
->cp15
.scr_el3
& SCR_ENSCXT
)) {
8283 return CP_ACCESS_TRAP_EL3
;
8285 return CP_ACCESS_OK
;
8288 static CPAccessResult
access_scxtnum_el1(CPUARMState
*env
,
8289 const ARMCPRegInfo
*ri
,
8292 CPAccessResult nv1
= access_nv1(env
, ri
, isread
);
8294 if (nv1
!= CP_ACCESS_OK
) {
8297 return access_scxtnum(env
, ri
, isread
);
8300 static const ARMCPRegInfo scxtnum_reginfo
[] = {
8301 { .name
= "SCXTNUM_EL0", .state
= ARM_CP_STATE_AA64
,
8302 .opc0
= 3, .opc1
= 3, .crn
= 13, .crm
= 0, .opc2
= 7,
8303 .access
= PL0_RW
, .accessfn
= access_scxtnum
,
8304 .fgt
= FGT_SCXTNUM_EL0
,
8305 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[0]) },
8306 { .name
= "SCXTNUM_EL1", .state
= ARM_CP_STATE_AA64
,
8307 .opc0
= 3, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 7,
8308 .access
= PL1_RW
, .accessfn
= access_scxtnum_el1
,
8309 .fgt
= FGT_SCXTNUM_EL1
,
8310 .nv2_redirect_offset
= 0x188 | NV2_REDIR_NV1
,
8311 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[1]) },
8312 { .name
= "SCXTNUM_EL2", .state
= ARM_CP_STATE_AA64
,
8313 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 7,
8314 .access
= PL2_RW
, .accessfn
= access_scxtnum
,
8315 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[2]) },
8316 { .name
= "SCXTNUM_EL3", .state
= ARM_CP_STATE_AA64
,
8317 .opc0
= 3, .opc1
= 6, .crn
= 13, .crm
= 0, .opc2
= 7,
8319 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[3]) },
8322 static CPAccessResult
access_fgt(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8325 if (arm_current_el(env
) == 2 &&
8326 arm_feature(env
, ARM_FEATURE_EL3
) && !(env
->cp15
.scr_el3
& SCR_FGTEN
)) {
8327 return CP_ACCESS_TRAP_EL3
;
8329 return CP_ACCESS_OK
;
8332 static const ARMCPRegInfo fgt_reginfo
[] = {
8333 { .name
= "HFGRTR_EL2", .state
= ARM_CP_STATE_AA64
,
8334 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 4,
8335 .nv2_redirect_offset
= 0x1b8,
8336 .access
= PL2_RW
, .accessfn
= access_fgt
,
8337 .fieldoffset
= offsetof(CPUARMState
, cp15
.fgt_read
[FGTREG_HFGRTR
]) },
8338 { .name
= "HFGWTR_EL2", .state
= ARM_CP_STATE_AA64
,
8339 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 5,
8340 .nv2_redirect_offset
= 0x1c0,
8341 .access
= PL2_RW
, .accessfn
= access_fgt
,
8342 .fieldoffset
= offsetof(CPUARMState
, cp15
.fgt_write
[FGTREG_HFGWTR
]) },
8343 { .name
= "HDFGRTR_EL2", .state
= ARM_CP_STATE_AA64
,
8344 .opc0
= 3, .opc1
= 4, .crn
= 3, .crm
= 1, .opc2
= 4,
8345 .nv2_redirect_offset
= 0x1d0,
8346 .access
= PL2_RW
, .accessfn
= access_fgt
,
8347 .fieldoffset
= offsetof(CPUARMState
, cp15
.fgt_read
[FGTREG_HDFGRTR
]) },
8348 { .name
= "HDFGWTR_EL2", .state
= ARM_CP_STATE_AA64
,
8349 .opc0
= 3, .opc1
= 4, .crn
= 3, .crm
= 1, .opc2
= 5,
8350 .nv2_redirect_offset
= 0x1d8,
8351 .access
= PL2_RW
, .accessfn
= access_fgt
,
8352 .fieldoffset
= offsetof(CPUARMState
, cp15
.fgt_write
[FGTREG_HDFGWTR
]) },
8353 { .name
= "HFGITR_EL2", .state
= ARM_CP_STATE_AA64
,
8354 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 6,
8355 .nv2_redirect_offset
= 0x1c8,
8356 .access
= PL2_RW
, .accessfn
= access_fgt
,
8357 .fieldoffset
= offsetof(CPUARMState
, cp15
.fgt_exec
[FGTREG_HFGITR
]) },
8360 static void vncr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8364 * Clear the RES0 bottom 12 bits; this means at runtime we can guarantee
8365 * that VNCR_EL2 + offset is 64-bit aligned. We don't need to do anything
8366 * about the RESS bits at the top -- we choose the "generate an EL2
8367 * translation abort on use" CONSTRAINED UNPREDICTABLE option (i.e. let
8368 * the ptw.c code detect the resulting invalid address).
8370 env
->cp15
.vncr_el2
= value
& ~0xfffULL
;
8373 static const ARMCPRegInfo nv2_reginfo
[] = {
8374 { .name
= "VNCR_EL2", .state
= ARM_CP_STATE_AA64
,
8375 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 2, .opc2
= 0,
8377 .writefn
= vncr_write
,
8378 .nv2_redirect_offset
= 0xb0,
8379 .fieldoffset
= offsetof(CPUARMState
, cp15
.vncr_el2
) },
8382 #endif /* TARGET_AARCH64 */
8384 static CPAccessResult
access_predinv(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8387 int el
= arm_current_el(env
);
8390 uint64_t sctlr
= arm_sctlr(env
, el
);
8391 if (!(sctlr
& SCTLR_EnRCTX
)) {
8392 return CP_ACCESS_TRAP
;
8394 } else if (el
== 1) {
8395 uint64_t hcr
= arm_hcr_el2_eff(env
);
8397 return CP_ACCESS_TRAP_EL2
;
8400 return CP_ACCESS_OK
;
8403 static const ARMCPRegInfo predinv_reginfo
[] = {
8404 { .name
= "CFP_RCTX", .state
= ARM_CP_STATE_AA64
,
8405 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 4,
8407 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
8408 { .name
= "DVP_RCTX", .state
= ARM_CP_STATE_AA64
,
8409 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 5,
8411 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
8412 { .name
= "CPP_RCTX", .state
= ARM_CP_STATE_AA64
,
8413 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 7,
8415 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
8417 * Note the AArch32 opcodes have a different OPC1.
8419 { .name
= "CFPRCTX", .state
= ARM_CP_STATE_AA32
,
8420 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 4,
8422 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
8423 { .name
= "DVPRCTX", .state
= ARM_CP_STATE_AA32
,
8424 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 5,
8426 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
8427 { .name
= "CPPRCTX", .state
= ARM_CP_STATE_AA32
,
8428 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 7,
8430 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
8433 static uint64_t ccsidr2_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
8435 /* Read the high 32 bits of the current CCSIDR */
8436 return extract64(ccsidr_read(env
, ri
), 32, 32);
8439 static const ARMCPRegInfo ccsidr2_reginfo
[] = {
8440 { .name
= "CCSIDR2", .state
= ARM_CP_STATE_BOTH
,
8441 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 2,
8443 .accessfn
= access_tid4
,
8444 .readfn
= ccsidr2_read
, .type
= ARM_CP_NO_RAW
},
8447 static CPAccessResult
access_aa64_tid3(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8450 if ((arm_current_el(env
) < 2) && (arm_hcr_el2_eff(env
) & HCR_TID3
)) {
8451 return CP_ACCESS_TRAP_EL2
;
8454 return CP_ACCESS_OK
;
8457 static CPAccessResult
access_aa32_tid3(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8460 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8461 return access_aa64_tid3(env
, ri
, isread
);
8464 return CP_ACCESS_OK
;
8467 static CPAccessResult
access_jazelle(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8470 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID0
)) {
8471 return CP_ACCESS_TRAP_EL2
;
8474 return CP_ACCESS_OK
;
8477 static CPAccessResult
access_joscr_jmcr(CPUARMState
*env
,
8478 const ARMCPRegInfo
*ri
, bool isread
)
8481 * HSTR.TJDBX traps JOSCR and JMCR accesses, but it exists only
8482 * in v7A, not in v8A.
8484 if (!arm_feature(env
, ARM_FEATURE_V8
) &&
8485 arm_current_el(env
) < 2 && !arm_is_secure_below_el3(env
) &&
8486 (env
->cp15
.hstr_el2
& HSTR_TJDBX
)) {
8487 return CP_ACCESS_TRAP_EL2
;
8489 return CP_ACCESS_OK
;
8492 static const ARMCPRegInfo jazelle_regs
[] = {
8494 .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 7, .opc2
= 0,
8495 .access
= PL1_R
, .accessfn
= access_jazelle
,
8496 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8498 .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 7, .opc2
= 0,
8499 .accessfn
= access_joscr_jmcr
,
8500 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8502 .cp
= 14, .crn
= 2, .crm
= 0, .opc1
= 7, .opc2
= 0,
8503 .accessfn
= access_joscr_jmcr
,
8504 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8507 static const ARMCPRegInfo contextidr_el2
= {
8508 .name
= "CONTEXTIDR_EL2", .state
= ARM_CP_STATE_AA64
,
8509 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 1,
8511 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[2])
8514 static const ARMCPRegInfo vhe_reginfo
[] = {
8515 { .name
= "TTBR1_EL2", .state
= ARM_CP_STATE_AA64
,
8516 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 1,
8517 .access
= PL2_RW
, .writefn
= vmsa_tcr_ttbr_el2_write
,
8518 .raw_writefn
= raw_write
,
8519 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr1_el
[2]) },
8520 #ifndef CONFIG_USER_ONLY
8521 { .name
= "CNTHV_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
8522 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 2,
8524 offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYPVIRT
].cval
),
8525 .type
= ARM_CP_IO
, .access
= PL2_RW
,
8526 .writefn
= gt_hv_cval_write
, .raw_writefn
= raw_write
},
8527 { .name
= "CNTHV_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
8528 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 0,
8529 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL2_RW
,
8530 .resetfn
= gt_hv_timer_reset
,
8531 .readfn
= gt_hv_tval_read
, .writefn
= gt_hv_tval_write
},
8532 { .name
= "CNTHV_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
8534 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 1,
8536 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYPVIRT
].ctl
),
8537 .writefn
= gt_hv_ctl_write
, .raw_writefn
= raw_write
},
8538 { .name
= "CNTP_CTL_EL02", .state
= ARM_CP_STATE_AA64
,
8539 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 1,
8540 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
8541 .access
= PL2_RW
, .accessfn
= access_el1nvpct
,
8542 .nv2_redirect_offset
= 0x180 | NV2_REDIR_NO_NV1
,
8543 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
8544 .writefn
= gt_phys_ctl_write
, .raw_writefn
= raw_write
},
8545 { .name
= "CNTV_CTL_EL02", .state
= ARM_CP_STATE_AA64
,
8546 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 1,
8547 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
8548 .access
= PL2_RW
, .accessfn
= access_el1nvvct
,
8549 .nv2_redirect_offset
= 0x170 | NV2_REDIR_NO_NV1
,
8550 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
8551 .writefn
= gt_virt_ctl_write
, .raw_writefn
= raw_write
},
8552 { .name
= "CNTP_TVAL_EL02", .state
= ARM_CP_STATE_AA64
,
8553 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 0,
8554 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
| ARM_CP_ALIAS
,
8555 .access
= PL2_RW
, .accessfn
= e2h_access
,
8556 .readfn
= gt_phys_tval_read
, .writefn
= gt_phys_tval_write
},
8557 { .name
= "CNTV_TVAL_EL02", .state
= ARM_CP_STATE_AA64
,
8558 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 0,
8559 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
| ARM_CP_ALIAS
,
8560 .access
= PL2_RW
, .accessfn
= e2h_access
,
8561 .readfn
= gt_virt_tval_read
, .writefn
= gt_virt_tval_write
},
8562 { .name
= "CNTP_CVAL_EL02", .state
= ARM_CP_STATE_AA64
,
8563 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 2,
8564 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
8565 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
8566 .nv2_redirect_offset
= 0x178 | NV2_REDIR_NO_NV1
,
8567 .access
= PL2_RW
, .accessfn
= access_el1nvpct
,
8568 .writefn
= gt_phys_cval_write
, .raw_writefn
= raw_write
},
8569 { .name
= "CNTV_CVAL_EL02", .state
= ARM_CP_STATE_AA64
,
8570 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 2,
8571 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
8572 .nv2_redirect_offset
= 0x168 | NV2_REDIR_NO_NV1
,
8573 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
8574 .access
= PL2_RW
, .accessfn
= access_el1nvvct
,
8575 .writefn
= gt_virt_cval_write
, .raw_writefn
= raw_write
},
8579 #ifndef CONFIG_USER_ONLY
8580 static const ARMCPRegInfo ats1e1_reginfo
[] = {
8581 { .name
= "AT_S1E1RP", .state
= ARM_CP_STATE_AA64
,
8582 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 0,
8583 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
8584 .fgt
= FGT_ATS1E1RP
,
8585 .accessfn
= at_s1e01_access
, .writefn
= ats_write64
},
8586 { .name
= "AT_S1E1WP", .state
= ARM_CP_STATE_AA64
,
8587 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 1,
8588 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
8589 .fgt
= FGT_ATS1E1WP
,
8590 .accessfn
= at_s1e01_access
, .writefn
= ats_write64
},
8593 static const ARMCPRegInfo ats1cp_reginfo
[] = {
8594 { .name
= "ATS1CPRP",
8595 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 0,
8596 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
8597 .writefn
= ats_write
},
8598 { .name
= "ATS1CPWP",
8599 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 1,
8600 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
8601 .writefn
= ats_write
},
8606 * ACTLR2 and HACTLR2 map to ACTLR_EL1[63:32] and
8607 * ACTLR_EL2[63:32]. They exist only if the ID_MMFR4.AC2 field
8608 * is non-zero, which is never for ARMv7, optionally in ARMv8
8609 * and mandatorily for ARMv8.2 and up.
8610 * ACTLR2 is banked for S and NS if EL3 is AArch32. Since QEMU's
8611 * implementation is RAZ/WI we can ignore this detail, as we
8614 static const ARMCPRegInfo actlr2_hactlr2_reginfo
[] = {
8615 { .name
= "ACTLR2", .state
= ARM_CP_STATE_AA32
,
8616 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 3,
8617 .access
= PL1_RW
, .accessfn
= access_tacr
,
8618 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8619 { .name
= "HACTLR2", .state
= ARM_CP_STATE_AA32
,
8620 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 3,
8621 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
8625 void register_cp_regs_for_features(ARMCPU
*cpu
)
8627 /* Register all the coprocessor registers based on feature bits */
8628 CPUARMState
*env
= &cpu
->env
;
8629 if (arm_feature(env
, ARM_FEATURE_M
)) {
8630 /* M profile has no coprocessor registers */
8634 define_arm_cp_regs(cpu
, cp_reginfo
);
8635 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
8637 * Must go early as it is full of wildcards that may be
8638 * overridden by later definitions.
8640 define_arm_cp_regs(cpu
, not_v8_cp_reginfo
);
8643 if (arm_feature(env
, ARM_FEATURE_V6
)) {
8644 /* The ID registers all have impdef reset values */
8645 ARMCPRegInfo v6_idregs
[] = {
8646 { .name
= "ID_PFR0", .state
= ARM_CP_STATE_BOTH
,
8647 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 0,
8648 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8649 .accessfn
= access_aa32_tid3
,
8650 .resetvalue
= cpu
->isar
.id_pfr0
},
8652 * ID_PFR1 is not a plain ARM_CP_CONST because we don't know
8653 * the value of the GIC field until after we define these regs.
8655 { .name
= "ID_PFR1", .state
= ARM_CP_STATE_BOTH
,
8656 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 1,
8657 .access
= PL1_R
, .type
= ARM_CP_NO_RAW
,
8658 .accessfn
= access_aa32_tid3
,
8659 #ifdef CONFIG_USER_ONLY
8660 .type
= ARM_CP_CONST
,
8661 .resetvalue
= cpu
->isar
.id_pfr1
,
8663 .type
= ARM_CP_NO_RAW
,
8664 .accessfn
= access_aa32_tid3
,
8665 .readfn
= id_pfr1_read
,
8666 .writefn
= arm_cp_write_ignore
8669 { .name
= "ID_DFR0", .state
= ARM_CP_STATE_BOTH
,
8670 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 2,
8671 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8672 .accessfn
= access_aa32_tid3
,
8673 .resetvalue
= cpu
->isar
.id_dfr0
},
8674 { .name
= "ID_AFR0", .state
= ARM_CP_STATE_BOTH
,
8675 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 3,
8676 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8677 .accessfn
= access_aa32_tid3
,
8678 .resetvalue
= cpu
->id_afr0
},
8679 { .name
= "ID_MMFR0", .state
= ARM_CP_STATE_BOTH
,
8680 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 4,
8681 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8682 .accessfn
= access_aa32_tid3
,
8683 .resetvalue
= cpu
->isar
.id_mmfr0
},
8684 { .name
= "ID_MMFR1", .state
= ARM_CP_STATE_BOTH
,
8685 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 5,
8686 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8687 .accessfn
= access_aa32_tid3
,
8688 .resetvalue
= cpu
->isar
.id_mmfr1
},
8689 { .name
= "ID_MMFR2", .state
= ARM_CP_STATE_BOTH
,
8690 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 6,
8691 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8692 .accessfn
= access_aa32_tid3
,
8693 .resetvalue
= cpu
->isar
.id_mmfr2
},
8694 { .name
= "ID_MMFR3", .state
= ARM_CP_STATE_BOTH
,
8695 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 7,
8696 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8697 .accessfn
= access_aa32_tid3
,
8698 .resetvalue
= cpu
->isar
.id_mmfr3
},
8699 { .name
= "ID_ISAR0", .state
= ARM_CP_STATE_BOTH
,
8700 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 0,
8701 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8702 .accessfn
= access_aa32_tid3
,
8703 .resetvalue
= cpu
->isar
.id_isar0
},
8704 { .name
= "ID_ISAR1", .state
= ARM_CP_STATE_BOTH
,
8705 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 1,
8706 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8707 .accessfn
= access_aa32_tid3
,
8708 .resetvalue
= cpu
->isar
.id_isar1
},
8709 { .name
= "ID_ISAR2", .state
= ARM_CP_STATE_BOTH
,
8710 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 2,
8711 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8712 .accessfn
= access_aa32_tid3
,
8713 .resetvalue
= cpu
->isar
.id_isar2
},
8714 { .name
= "ID_ISAR3", .state
= ARM_CP_STATE_BOTH
,
8715 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 3,
8716 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8717 .accessfn
= access_aa32_tid3
,
8718 .resetvalue
= cpu
->isar
.id_isar3
},
8719 { .name
= "ID_ISAR4", .state
= ARM_CP_STATE_BOTH
,
8720 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 4,
8721 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8722 .accessfn
= access_aa32_tid3
,
8723 .resetvalue
= cpu
->isar
.id_isar4
},
8724 { .name
= "ID_ISAR5", .state
= ARM_CP_STATE_BOTH
,
8725 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 5,
8726 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8727 .accessfn
= access_aa32_tid3
,
8728 .resetvalue
= cpu
->isar
.id_isar5
},
8729 { .name
= "ID_MMFR4", .state
= ARM_CP_STATE_BOTH
,
8730 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 6,
8731 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8732 .accessfn
= access_aa32_tid3
,
8733 .resetvalue
= cpu
->isar
.id_mmfr4
},
8734 { .name
= "ID_ISAR6", .state
= ARM_CP_STATE_BOTH
,
8735 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 7,
8736 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8737 .accessfn
= access_aa32_tid3
,
8738 .resetvalue
= cpu
->isar
.id_isar6
},
8740 define_arm_cp_regs(cpu
, v6_idregs
);
8741 define_arm_cp_regs(cpu
, v6_cp_reginfo
);
8743 define_arm_cp_regs(cpu
, not_v6_cp_reginfo
);
8745 if (arm_feature(env
, ARM_FEATURE_V6K
)) {
8746 define_arm_cp_regs(cpu
, v6k_cp_reginfo
);
8748 if (arm_feature(env
, ARM_FEATURE_V7MP
) &&
8749 !arm_feature(env
, ARM_FEATURE_PMSA
)) {
8750 define_arm_cp_regs(cpu
, v7mp_cp_reginfo
);
8752 if (arm_feature(env
, ARM_FEATURE_V7VE
)) {
8753 define_arm_cp_regs(cpu
, pmovsset_cp_reginfo
);
8755 if (arm_feature(env
, ARM_FEATURE_V7
)) {
8756 ARMCPRegInfo clidr
= {
8757 .name
= "CLIDR", .state
= ARM_CP_STATE_BOTH
,
8758 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 1,
8759 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8760 .accessfn
= access_tid4
,
8761 .fgt
= FGT_CLIDR_EL1
,
8762 .resetvalue
= cpu
->clidr
8764 define_one_arm_cp_reg(cpu
, &clidr
);
8765 define_arm_cp_regs(cpu
, v7_cp_reginfo
);
8766 define_debug_regs(cpu
);
8767 define_pmu_regs(cpu
);
8769 define_arm_cp_regs(cpu
, not_v7_cp_reginfo
);
8771 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8773 * v8 ID registers, which all have impdef reset values.
8774 * Note that within the ID register ranges the unused slots
8775 * must all RAZ, not UNDEF; future architecture versions may
8776 * define new registers here.
8777 * ID registers which are AArch64 views of the AArch32 ID registers
8778 * which already existed in v6 and v7 are handled elsewhere,
8782 ARMCPRegInfo v8_idregs
[] = {
8784 * ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST in system
8785 * emulation because we don't know the right value for the
8786 * GIC field until after we define these regs.
8788 { .name
= "ID_AA64PFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8789 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 0,
8791 #ifdef CONFIG_USER_ONLY
8792 .type
= ARM_CP_CONST
,
8793 .resetvalue
= cpu
->isar
.id_aa64pfr0
8795 .type
= ARM_CP_NO_RAW
,
8796 .accessfn
= access_aa64_tid3
,
8797 .readfn
= id_aa64pfr0_read
,
8798 .writefn
= arm_cp_write_ignore
8801 { .name
= "ID_AA64PFR1_EL1", .state
= ARM_CP_STATE_AA64
,
8802 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 1,
8803 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8804 .accessfn
= access_aa64_tid3
,
8805 .resetvalue
= cpu
->isar
.id_aa64pfr1
},
8806 { .name
= "ID_AA64PFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8807 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 2,
8808 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8809 .accessfn
= access_aa64_tid3
,
8811 { .name
= "ID_AA64PFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8812 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 3,
8813 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8814 .accessfn
= access_aa64_tid3
,
8816 { .name
= "ID_AA64ZFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8817 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 4,
8818 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8819 .accessfn
= access_aa64_tid3
,
8820 .resetvalue
= cpu
->isar
.id_aa64zfr0
},
8821 { .name
= "ID_AA64SMFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8822 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 5,
8823 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8824 .accessfn
= access_aa64_tid3
,
8825 .resetvalue
= cpu
->isar
.id_aa64smfr0
},
8826 { .name
= "ID_AA64PFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8827 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 6,
8828 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8829 .accessfn
= access_aa64_tid3
,
8831 { .name
= "ID_AA64PFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8832 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 7,
8833 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8834 .accessfn
= access_aa64_tid3
,
8836 { .name
= "ID_AA64DFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8837 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 0,
8838 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8839 .accessfn
= access_aa64_tid3
,
8840 .resetvalue
= cpu
->isar
.id_aa64dfr0
},
8841 { .name
= "ID_AA64DFR1_EL1", .state
= ARM_CP_STATE_AA64
,
8842 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 1,
8843 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8844 .accessfn
= access_aa64_tid3
,
8845 .resetvalue
= cpu
->isar
.id_aa64dfr1
},
8846 { .name
= "ID_AA64DFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8847 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 2,
8848 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8849 .accessfn
= access_aa64_tid3
,
8851 { .name
= "ID_AA64DFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8852 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 3,
8853 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8854 .accessfn
= access_aa64_tid3
,
8856 { .name
= "ID_AA64AFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8857 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 4,
8858 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8859 .accessfn
= access_aa64_tid3
,
8860 .resetvalue
= cpu
->id_aa64afr0
},
8861 { .name
= "ID_AA64AFR1_EL1", .state
= ARM_CP_STATE_AA64
,
8862 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 5,
8863 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8864 .accessfn
= access_aa64_tid3
,
8865 .resetvalue
= cpu
->id_aa64afr1
},
8866 { .name
= "ID_AA64AFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8867 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 6,
8868 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8869 .accessfn
= access_aa64_tid3
,
8871 { .name
= "ID_AA64AFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8872 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 7,
8873 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8874 .accessfn
= access_aa64_tid3
,
8876 { .name
= "ID_AA64ISAR0_EL1", .state
= ARM_CP_STATE_AA64
,
8877 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 0,
8878 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8879 .accessfn
= access_aa64_tid3
,
8880 .resetvalue
= cpu
->isar
.id_aa64isar0
},
8881 { .name
= "ID_AA64ISAR1_EL1", .state
= ARM_CP_STATE_AA64
,
8882 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 1,
8883 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8884 .accessfn
= access_aa64_tid3
,
8885 .resetvalue
= cpu
->isar
.id_aa64isar1
},
8886 { .name
= "ID_AA64ISAR2_EL1", .state
= ARM_CP_STATE_AA64
,
8887 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 2,
8888 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8889 .accessfn
= access_aa64_tid3
,
8890 .resetvalue
= cpu
->isar
.id_aa64isar2
},
8891 { .name
= "ID_AA64ISAR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8892 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 3,
8893 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8894 .accessfn
= access_aa64_tid3
,
8896 { .name
= "ID_AA64ISAR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8897 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 4,
8898 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8899 .accessfn
= access_aa64_tid3
,
8901 { .name
= "ID_AA64ISAR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8902 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 5,
8903 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8904 .accessfn
= access_aa64_tid3
,
8906 { .name
= "ID_AA64ISAR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8907 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 6,
8908 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8909 .accessfn
= access_aa64_tid3
,
8911 { .name
= "ID_AA64ISAR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8912 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 7,
8913 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8914 .accessfn
= access_aa64_tid3
,
8916 { .name
= "ID_AA64MMFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8917 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 0,
8918 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8919 .accessfn
= access_aa64_tid3
,
8920 .resetvalue
= cpu
->isar
.id_aa64mmfr0
},
8921 { .name
= "ID_AA64MMFR1_EL1", .state
= ARM_CP_STATE_AA64
,
8922 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 1,
8923 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8924 .accessfn
= access_aa64_tid3
,
8925 .resetvalue
= cpu
->isar
.id_aa64mmfr1
},
8926 { .name
= "ID_AA64MMFR2_EL1", .state
= ARM_CP_STATE_AA64
,
8927 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 2,
8928 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8929 .accessfn
= access_aa64_tid3
,
8930 .resetvalue
= cpu
->isar
.id_aa64mmfr2
},
8931 { .name
= "ID_AA64MMFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8932 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 3,
8933 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8934 .accessfn
= access_aa64_tid3
,
8936 { .name
= "ID_AA64MMFR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8937 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 4,
8938 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8939 .accessfn
= access_aa64_tid3
,
8941 { .name
= "ID_AA64MMFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8942 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 5,
8943 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8944 .accessfn
= access_aa64_tid3
,
8946 { .name
= "ID_AA64MMFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8947 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 6,
8948 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8949 .accessfn
= access_aa64_tid3
,
8951 { .name
= "ID_AA64MMFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8952 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 7,
8953 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8954 .accessfn
= access_aa64_tid3
,
8956 { .name
= "MVFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8957 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 0,
8958 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8959 .accessfn
= access_aa64_tid3
,
8960 .resetvalue
= cpu
->isar
.mvfr0
},
8961 { .name
= "MVFR1_EL1", .state
= ARM_CP_STATE_AA64
,
8962 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 1,
8963 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8964 .accessfn
= access_aa64_tid3
,
8965 .resetvalue
= cpu
->isar
.mvfr1
},
8966 { .name
= "MVFR2_EL1", .state
= ARM_CP_STATE_AA64
,
8967 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 2,
8968 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8969 .accessfn
= access_aa64_tid3
,
8970 .resetvalue
= cpu
->isar
.mvfr2
},
8972 * "0, c0, c3, {0,1,2}" are the encodings corresponding to
8973 * AArch64 MVFR[012]_EL1. Define the STATE_AA32 encoding
8974 * as RAZ, since it is in the "reserved for future ID
8975 * registers, RAZ" part of the AArch32 encoding space.
8977 { .name
= "RES_0_C0_C3_0", .state
= ARM_CP_STATE_AA32
,
8978 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 0,
8979 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8980 .accessfn
= access_aa64_tid3
,
8982 { .name
= "RES_0_C0_C3_1", .state
= ARM_CP_STATE_AA32
,
8983 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 1,
8984 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8985 .accessfn
= access_aa64_tid3
,
8987 { .name
= "RES_0_C0_C3_2", .state
= ARM_CP_STATE_AA32
,
8988 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 2,
8989 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8990 .accessfn
= access_aa64_tid3
,
8993 * Other encodings in "0, c0, c3, ..." are STATE_BOTH because
8994 * they're also RAZ for AArch64, and in v8 are gradually
8995 * being filled with AArch64-view-of-AArch32-ID-register
8996 * for new ID registers.
8998 { .name
= "RES_0_C0_C3_3", .state
= ARM_CP_STATE_BOTH
,
8999 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 3,
9000 .access
= PL1_R
, .type
= ARM_CP_CONST
,
9001 .accessfn
= access_aa64_tid3
,
9003 { .name
= "ID_PFR2", .state
= ARM_CP_STATE_BOTH
,
9004 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 4,
9005 .access
= PL1_R
, .type
= ARM_CP_CONST
,
9006 .accessfn
= access_aa64_tid3
,
9007 .resetvalue
= cpu
->isar
.id_pfr2
},
9008 { .name
= "ID_DFR1", .state
= ARM_CP_STATE_BOTH
,
9009 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 5,
9010 .access
= PL1_R
, .type
= ARM_CP_CONST
,
9011 .accessfn
= access_aa64_tid3
,
9012 .resetvalue
= cpu
->isar
.id_dfr1
},
9013 { .name
= "ID_MMFR5", .state
= ARM_CP_STATE_BOTH
,
9014 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 6,
9015 .access
= PL1_R
, .type
= ARM_CP_CONST
,
9016 .accessfn
= access_aa64_tid3
,
9017 .resetvalue
= cpu
->isar
.id_mmfr5
},
9018 { .name
= "RES_0_C0_C3_7", .state
= ARM_CP_STATE_BOTH
,
9019 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 7,
9020 .access
= PL1_R
, .type
= ARM_CP_CONST
,
9021 .accessfn
= access_aa64_tid3
,
9023 { .name
= "PMCEID0", .state
= ARM_CP_STATE_AA32
,
9024 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 6,
9025 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
9026 .fgt
= FGT_PMCEIDN_EL0
,
9027 .resetvalue
= extract64(cpu
->pmceid0
, 0, 32) },
9028 { .name
= "PMCEID0_EL0", .state
= ARM_CP_STATE_AA64
,
9029 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 6,
9030 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
9031 .fgt
= FGT_PMCEIDN_EL0
,
9032 .resetvalue
= cpu
->pmceid0
},
9033 { .name
= "PMCEID1", .state
= ARM_CP_STATE_AA32
,
9034 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 7,
9035 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
9036 .fgt
= FGT_PMCEIDN_EL0
,
9037 .resetvalue
= extract64(cpu
->pmceid1
, 0, 32) },
9038 { .name
= "PMCEID1_EL0", .state
= ARM_CP_STATE_AA64
,
9039 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 7,
9040 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
9041 .fgt
= FGT_PMCEIDN_EL0
,
9042 .resetvalue
= cpu
->pmceid1
},
9044 #ifdef CONFIG_USER_ONLY
9045 static const ARMCPRegUserSpaceInfo v8_user_idregs
[] = {
9046 { .name
= "ID_AA64PFR0_EL1",
9047 .exported_bits
= R_ID_AA64PFR0_FP_MASK
|
9048 R_ID_AA64PFR0_ADVSIMD_MASK
|
9049 R_ID_AA64PFR0_SVE_MASK
|
9050 R_ID_AA64PFR0_DIT_MASK
,
9051 .fixed_bits
= (0x1u
<< R_ID_AA64PFR0_EL0_SHIFT
) |
9052 (0x1u
<< R_ID_AA64PFR0_EL1_SHIFT
) },
9053 { .name
= "ID_AA64PFR1_EL1",
9054 .exported_bits
= R_ID_AA64PFR1_BT_MASK
|
9055 R_ID_AA64PFR1_SSBS_MASK
|
9056 R_ID_AA64PFR1_MTE_MASK
|
9057 R_ID_AA64PFR1_SME_MASK
},
9058 { .name
= "ID_AA64PFR*_EL1_RESERVED",
9060 { .name
= "ID_AA64ZFR0_EL1",
9061 .exported_bits
= R_ID_AA64ZFR0_SVEVER_MASK
|
9062 R_ID_AA64ZFR0_AES_MASK
|
9063 R_ID_AA64ZFR0_BITPERM_MASK
|
9064 R_ID_AA64ZFR0_BFLOAT16_MASK
|
9065 R_ID_AA64ZFR0_B16B16_MASK
|
9066 R_ID_AA64ZFR0_SHA3_MASK
|
9067 R_ID_AA64ZFR0_SM4_MASK
|
9068 R_ID_AA64ZFR0_I8MM_MASK
|
9069 R_ID_AA64ZFR0_F32MM_MASK
|
9070 R_ID_AA64ZFR0_F64MM_MASK
},
9071 { .name
= "ID_AA64SMFR0_EL1",
9072 .exported_bits
= R_ID_AA64SMFR0_F32F32_MASK
|
9073 R_ID_AA64SMFR0_BI32I32_MASK
|
9074 R_ID_AA64SMFR0_B16F32_MASK
|
9075 R_ID_AA64SMFR0_F16F32_MASK
|
9076 R_ID_AA64SMFR0_I8I32_MASK
|
9077 R_ID_AA64SMFR0_F16F16_MASK
|
9078 R_ID_AA64SMFR0_B16B16_MASK
|
9079 R_ID_AA64SMFR0_I16I32_MASK
|
9080 R_ID_AA64SMFR0_F64F64_MASK
|
9081 R_ID_AA64SMFR0_I16I64_MASK
|
9082 R_ID_AA64SMFR0_SMEVER_MASK
|
9083 R_ID_AA64SMFR0_FA64_MASK
},
9084 { .name
= "ID_AA64MMFR0_EL1",
9085 .exported_bits
= R_ID_AA64MMFR0_ECV_MASK
,
9086 .fixed_bits
= (0xfu
<< R_ID_AA64MMFR0_TGRAN64_SHIFT
) |
9087 (0xfu
<< R_ID_AA64MMFR0_TGRAN4_SHIFT
) },
9088 { .name
= "ID_AA64MMFR1_EL1",
9089 .exported_bits
= R_ID_AA64MMFR1_AFP_MASK
},
9090 { .name
= "ID_AA64MMFR2_EL1",
9091 .exported_bits
= R_ID_AA64MMFR2_AT_MASK
},
9092 { .name
= "ID_AA64MMFR*_EL1_RESERVED",
9094 { .name
= "ID_AA64DFR0_EL1",
9095 .fixed_bits
= (0x6u
<< R_ID_AA64DFR0_DEBUGVER_SHIFT
) },
9096 { .name
= "ID_AA64DFR1_EL1" },
9097 { .name
= "ID_AA64DFR*_EL1_RESERVED",
9099 { .name
= "ID_AA64AFR*",
9101 { .name
= "ID_AA64ISAR0_EL1",
9102 .exported_bits
= R_ID_AA64ISAR0_AES_MASK
|
9103 R_ID_AA64ISAR0_SHA1_MASK
|
9104 R_ID_AA64ISAR0_SHA2_MASK
|
9105 R_ID_AA64ISAR0_CRC32_MASK
|
9106 R_ID_AA64ISAR0_ATOMIC_MASK
|
9107 R_ID_AA64ISAR0_RDM_MASK
|
9108 R_ID_AA64ISAR0_SHA3_MASK
|
9109 R_ID_AA64ISAR0_SM3_MASK
|
9110 R_ID_AA64ISAR0_SM4_MASK
|
9111 R_ID_AA64ISAR0_DP_MASK
|
9112 R_ID_AA64ISAR0_FHM_MASK
|
9113 R_ID_AA64ISAR0_TS_MASK
|
9114 R_ID_AA64ISAR0_RNDR_MASK
},
9115 { .name
= "ID_AA64ISAR1_EL1",
9116 .exported_bits
= R_ID_AA64ISAR1_DPB_MASK
|
9117 R_ID_AA64ISAR1_APA_MASK
|
9118 R_ID_AA64ISAR1_API_MASK
|
9119 R_ID_AA64ISAR1_JSCVT_MASK
|
9120 R_ID_AA64ISAR1_FCMA_MASK
|
9121 R_ID_AA64ISAR1_LRCPC_MASK
|
9122 R_ID_AA64ISAR1_GPA_MASK
|
9123 R_ID_AA64ISAR1_GPI_MASK
|
9124 R_ID_AA64ISAR1_FRINTTS_MASK
|
9125 R_ID_AA64ISAR1_SB_MASK
|
9126 R_ID_AA64ISAR1_BF16_MASK
|
9127 R_ID_AA64ISAR1_DGH_MASK
|
9128 R_ID_AA64ISAR1_I8MM_MASK
},
9129 { .name
= "ID_AA64ISAR2_EL1",
9130 .exported_bits
= R_ID_AA64ISAR2_WFXT_MASK
|
9131 R_ID_AA64ISAR2_RPRES_MASK
|
9132 R_ID_AA64ISAR2_GPA3_MASK
|
9133 R_ID_AA64ISAR2_APA3_MASK
|
9134 R_ID_AA64ISAR2_MOPS_MASK
|
9135 R_ID_AA64ISAR2_BC_MASK
|
9136 R_ID_AA64ISAR2_RPRFM_MASK
|
9137 R_ID_AA64ISAR2_CSSC_MASK
},
9138 { .name
= "ID_AA64ISAR*_EL1_RESERVED",
9141 modify_arm_cp_regs(v8_idregs
, v8_user_idregs
);
9144 * RVBAR_EL1 and RMR_EL1 only implemented if EL1 is the highest EL.
9145 * TODO: For RMR, a write with bit 1 set should do something with
9146 * cpu_reset(). In the meantime, "the bit is strictly a request",
9147 * so we are in spec just ignoring writes.
9149 if (!arm_feature(env
, ARM_FEATURE_EL3
) &&
9150 !arm_feature(env
, ARM_FEATURE_EL2
)) {
9151 ARMCPRegInfo el1_reset_regs
[] = {
9152 { .name
= "RVBAR_EL1", .state
= ARM_CP_STATE_BOTH
,
9153 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
9155 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
) },
9156 { .name
= "RMR_EL1", .state
= ARM_CP_STATE_BOTH
,
9157 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 2,
9158 .access
= PL1_RW
, .type
= ARM_CP_CONST
,
9159 .resetvalue
= arm_feature(env
, ARM_FEATURE_AARCH64
) }
9161 define_arm_cp_regs(cpu
, el1_reset_regs
);
9163 define_arm_cp_regs(cpu
, v8_idregs
);
9164 define_arm_cp_regs(cpu
, v8_cp_reginfo
);
9165 if (cpu_isar_feature(aa64_aa32_el1
, cpu
)) {
9166 define_arm_cp_regs(cpu
, v8_aa32_el1_reginfo
);
9169 for (i
= 4; i
< 16; i
++) {
9171 * Encodings in "0, c0, {c4-c7}, {0-7}" are RAZ for AArch32.
9172 * For pre-v8 cores there are RAZ patterns for these in
9173 * id_pre_v8_midr_cp_reginfo[]; for v8 we do that here.
9174 * v8 extends the "must RAZ" part of the ID register space
9175 * to also cover c0, 0, c{8-15}, {0-7}.
9176 * These are STATE_AA32 because in the AArch64 sysreg space
9177 * c4-c7 is where the AArch64 ID registers live (and we've
9178 * already defined those in v8_idregs[]), and c8-c15 are not
9179 * "must RAZ" for AArch64.
9181 g_autofree
char *name
= g_strdup_printf("RES_0_C0_C%d_X", i
);
9182 ARMCPRegInfo v8_aa32_raz_idregs
= {
9184 .state
= ARM_CP_STATE_AA32
,
9185 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= CP_ANY
,
9186 .access
= PL1_R
, .type
= ARM_CP_CONST
,
9187 .accessfn
= access_aa64_tid3
,
9189 define_one_arm_cp_reg(cpu
, &v8_aa32_raz_idregs
);
9194 * Register the base EL2 cpregs.
9195 * Pre v8, these registers are implemented only as part of the
9196 * Virtualization Extensions (EL2 present). Beginning with v8,
9197 * if EL2 is missing but EL3 is enabled, mostly these become
9198 * RES0 from EL3, with some specific exceptions.
9200 if (arm_feature(env
, ARM_FEATURE_EL2
)
9201 || (arm_feature(env
, ARM_FEATURE_EL3
)
9202 && arm_feature(env
, ARM_FEATURE_V8
))) {
9203 uint64_t vmpidr_def
= mpidr_read_val(env
);
9204 ARMCPRegInfo vpidr_regs
[] = {
9205 { .name
= "VPIDR", .state
= ARM_CP_STATE_AA32
,
9206 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
9207 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
9208 .resetvalue
= cpu
->midr
,
9209 .type
= ARM_CP_ALIAS
| ARM_CP_EL3_NO_EL2_C_NZ
,
9210 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vpidr_el2
) },
9211 { .name
= "VPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
9212 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
9213 .access
= PL2_RW
, .resetvalue
= cpu
->midr
,
9214 .type
= ARM_CP_EL3_NO_EL2_C_NZ
,
9215 .nv2_redirect_offset
= 0x88,
9216 .fieldoffset
= offsetof(CPUARMState
, cp15
.vpidr_el2
) },
9217 { .name
= "VMPIDR", .state
= ARM_CP_STATE_AA32
,
9218 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
9219 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
9220 .resetvalue
= vmpidr_def
,
9221 .type
= ARM_CP_ALIAS
| ARM_CP_EL3_NO_EL2_C_NZ
,
9222 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vmpidr_el2
) },
9223 { .name
= "VMPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
9224 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
9225 .access
= PL2_RW
, .resetvalue
= vmpidr_def
,
9226 .type
= ARM_CP_EL3_NO_EL2_C_NZ
,
9227 .nv2_redirect_offset
= 0x50,
9228 .fieldoffset
= offsetof(CPUARMState
, cp15
.vmpidr_el2
) },
9231 * The only field of MDCR_EL2 that has a defined architectural reset
9232 * value is MDCR_EL2.HPMN which should reset to the value of PMCR_EL0.N.
9234 ARMCPRegInfo mdcr_el2
= {
9235 .name
= "MDCR_EL2", .state
= ARM_CP_STATE_BOTH
, .type
= ARM_CP_IO
,
9236 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 1,
9237 .writefn
= mdcr_el2_write
,
9238 .access
= PL2_RW
, .resetvalue
= pmu_num_counters(env
),
9239 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el2
),
9241 define_one_arm_cp_reg(cpu
, &mdcr_el2
);
9242 define_arm_cp_regs(cpu
, vpidr_regs
);
9243 define_arm_cp_regs(cpu
, el2_cp_reginfo
);
9244 if (arm_feature(env
, ARM_FEATURE_V8
)) {
9245 define_arm_cp_regs(cpu
, el2_v8_cp_reginfo
);
9247 if (cpu_isar_feature(aa64_sel2
, cpu
)) {
9248 define_arm_cp_regs(cpu
, el2_sec_cp_reginfo
);
9251 * RVBAR_EL2 and RMR_EL2 only implemented if EL2 is the highest EL.
9252 * See commentary near RMR_EL1.
9254 if (!arm_feature(env
, ARM_FEATURE_EL3
)) {
9255 static const ARMCPRegInfo el2_reset_regs
[] = {
9256 { .name
= "RVBAR_EL2", .state
= ARM_CP_STATE_AA64
,
9257 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 1,
9259 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
) },
9260 { .name
= "RVBAR", .type
= ARM_CP_ALIAS
,
9261 .cp
= 15, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
9263 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
) },
9264 { .name
= "RMR_EL2", .state
= ARM_CP_STATE_AA64
,
9265 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 2,
9266 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 1 },
9268 define_arm_cp_regs(cpu
, el2_reset_regs
);
9272 /* Register the base EL3 cpregs. */
9273 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
9274 define_arm_cp_regs(cpu
, el3_cp_reginfo
);
9275 ARMCPRegInfo el3_regs
[] = {
9276 { .name
= "RVBAR_EL3", .state
= ARM_CP_STATE_AA64
,
9277 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 1,
9279 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
), },
9280 { .name
= "RMR_EL3", .state
= ARM_CP_STATE_AA64
,
9281 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 2,
9282 .access
= PL3_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 1 },
9283 { .name
= "RMR", .state
= ARM_CP_STATE_AA32
,
9284 .cp
= 15, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 2,
9285 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
9286 .resetvalue
= arm_feature(env
, ARM_FEATURE_AARCH64
) },
9287 { .name
= "SCTLR_EL3", .state
= ARM_CP_STATE_AA64
,
9288 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 0,
9290 .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
9291 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[3]),
9292 .resetvalue
= cpu
->reset_sctlr
},
9295 define_arm_cp_regs(cpu
, el3_regs
);
9298 * The behaviour of NSACR is sufficiently various that we don't
9299 * try to describe it in a single reginfo:
9300 * if EL3 is 64 bit, then trap to EL3 from S EL1,
9301 * reads as constant 0xc00 from NS EL1 and NS EL2
9302 * if EL3 is 32 bit, then RW at EL3, RO at NS EL1 and NS EL2
9303 * if v7 without EL3, register doesn't exist
9304 * if v8 without EL3, reads as constant 0xc00 from NS EL1 and NS EL2
9306 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
9307 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
9308 static const ARMCPRegInfo nsacr
= {
9309 .name
= "NSACR", .type
= ARM_CP_CONST
,
9310 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
9311 .access
= PL1_RW
, .accessfn
= nsacr_access
,
9314 define_one_arm_cp_reg(cpu
, &nsacr
);
9316 static const ARMCPRegInfo nsacr
= {
9318 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
9319 .access
= PL3_RW
| PL1_R
,
9321 .fieldoffset
= offsetof(CPUARMState
, cp15
.nsacr
)
9323 define_one_arm_cp_reg(cpu
, &nsacr
);
9326 if (arm_feature(env
, ARM_FEATURE_V8
)) {
9327 static const ARMCPRegInfo nsacr
= {
9328 .name
= "NSACR", .type
= ARM_CP_CONST
,
9329 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
9333 define_one_arm_cp_reg(cpu
, &nsacr
);
9337 if (arm_feature(env
, ARM_FEATURE_PMSA
)) {
9338 if (arm_feature(env
, ARM_FEATURE_V6
)) {
9339 /* PMSAv6 not implemented */
9340 assert(arm_feature(env
, ARM_FEATURE_V7
));
9341 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
9342 define_arm_cp_regs(cpu
, pmsav7_cp_reginfo
);
9344 define_arm_cp_regs(cpu
, pmsav5_cp_reginfo
);
9347 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
9348 define_arm_cp_regs(cpu
, vmsa_cp_reginfo
);
9349 /* TTCBR2 is introduced with ARMv8.2-AA32HPD. */
9350 if (cpu_isar_feature(aa32_hpd
, cpu
)) {
9351 define_one_arm_cp_reg(cpu
, &ttbcr2_reginfo
);
9354 if (arm_feature(env
, ARM_FEATURE_THUMB2EE
)) {
9355 define_arm_cp_regs(cpu
, t2ee_cp_reginfo
);
9357 if (arm_feature(env
, ARM_FEATURE_GENERIC_TIMER
)) {
9358 define_arm_cp_regs(cpu
, generic_timer_cp_reginfo
);
9360 if (cpu_isar_feature(aa64_ecv_traps
, cpu
)) {
9361 define_arm_cp_regs(cpu
, gen_timer_ecv_cp_reginfo
);
9363 #ifndef CONFIG_USER_ONLY
9364 if (cpu_isar_feature(aa64_ecv
, cpu
)) {
9365 define_one_arm_cp_reg(cpu
, &gen_timer_cntpoff_reginfo
);
9368 if (arm_feature(env
, ARM_FEATURE_VAPA
)) {
9369 ARMCPRegInfo vapa_cp_reginfo
[] = {
9370 { .name
= "PAR", .cp
= 15, .crn
= 7, .crm
= 4, .opc1
= 0, .opc2
= 0,
9371 .access
= PL1_RW
, .resetvalue
= 0,
9372 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.par_s
),
9373 offsetoflow32(CPUARMState
, cp15
.par_ns
) },
9374 .writefn
= par_write
},
9375 #ifndef CONFIG_USER_ONLY
9376 /* This underdecoding is safe because the reginfo is NO_RAW. */
9377 { .name
= "ATS", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= CP_ANY
,
9378 .access
= PL1_W
, .accessfn
= ats_access
,
9379 .writefn
= ats_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
9384 * When LPAE exists this 32-bit PAR register is an alias of the
9385 * 64-bit AArch32 PAR register defined in lpae_cp_reginfo[]
9387 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
9388 vapa_cp_reginfo
[0].type
= ARM_CP_ALIAS
| ARM_CP_NO_GDB
;
9390 define_arm_cp_regs(cpu
, vapa_cp_reginfo
);
9392 if (arm_feature(env
, ARM_FEATURE_CACHE_TEST_CLEAN
)) {
9393 define_arm_cp_regs(cpu
, cache_test_clean_cp_reginfo
);
9395 if (arm_feature(env
, ARM_FEATURE_CACHE_DIRTY_REG
)) {
9396 define_arm_cp_regs(cpu
, cache_dirty_status_cp_reginfo
);
9398 if (arm_feature(env
, ARM_FEATURE_CACHE_BLOCK_OPS
)) {
9399 define_arm_cp_regs(cpu
, cache_block_ops_cp_reginfo
);
9401 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
9402 define_arm_cp_regs(cpu
, omap_cp_reginfo
);
9404 if (arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
9405 define_arm_cp_regs(cpu
, strongarm_cp_reginfo
);
9407 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
9408 define_arm_cp_regs(cpu
, xscale_cp_reginfo
);
9410 if (arm_feature(env
, ARM_FEATURE_DUMMY_C15_REGS
)) {
9411 define_arm_cp_regs(cpu
, dummy_c15_cp_reginfo
);
9413 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
9414 define_arm_cp_regs(cpu
, lpae_cp_reginfo
);
9416 if (cpu_isar_feature(aa32_jazelle
, cpu
)) {
9417 define_arm_cp_regs(cpu
, jazelle_regs
);
9420 * Slightly awkwardly, the OMAP and StrongARM cores need all of
9421 * cp15 crn=0 to be writes-ignored, whereas for other cores they should
9422 * be read-only (ie write causes UNDEF exception).
9425 ARMCPRegInfo id_pre_v8_midr_cp_reginfo
[] = {
9427 * Pre-v8 MIDR space.
9428 * Note that the MIDR isn't a simple constant register because
9429 * of the TI925 behaviour where writes to another register can
9430 * cause the MIDR value to change.
9432 * Unimplemented registers in the c15 0 0 0 space default to
9433 * MIDR. Define MIDR first as this entire space, then CTR, TCMTR
9434 * and friends override accordingly.
9437 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= CP_ANY
,
9438 .access
= PL1_R
, .resetvalue
= cpu
->midr
,
9439 .writefn
= arm_cp_write_ignore
, .raw_writefn
= raw_write
,
9440 .readfn
= midr_read
,
9441 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
9442 .type
= ARM_CP_OVERRIDE
},
9443 /* crn = 0 op1 = 0 crm = 3..7 : currently unassigned; we RAZ. */
9445 .cp
= 15, .crn
= 0, .crm
= 3, .opc1
= 0, .opc2
= CP_ANY
,
9446 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
9448 .cp
= 15, .crn
= 0, .crm
= 4, .opc1
= 0, .opc2
= CP_ANY
,
9449 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
9451 .cp
= 15, .crn
= 0, .crm
= 5, .opc1
= 0, .opc2
= CP_ANY
,
9452 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
9454 .cp
= 15, .crn
= 0, .crm
= 6, .opc1
= 0, .opc2
= CP_ANY
,
9455 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
9457 .cp
= 15, .crn
= 0, .crm
= 7, .opc1
= 0, .opc2
= CP_ANY
,
9458 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
9460 ARMCPRegInfo id_v8_midr_cp_reginfo
[] = {
9461 { .name
= "MIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
9462 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 0,
9463 .access
= PL1_R
, .type
= ARM_CP_NO_RAW
, .resetvalue
= cpu
->midr
,
9464 .fgt
= FGT_MIDR_EL1
,
9465 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
9466 .readfn
= midr_read
},
9467 /* crn = 0 op1 = 0 crm = 0 op2 = 7 : AArch32 aliases of MIDR */
9468 { .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
,
9469 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 7,
9470 .access
= PL1_R
, .resetvalue
= cpu
->midr
},
9471 { .name
= "REVIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
9472 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 6,
9474 .accessfn
= access_aa64_tid1
,
9475 .fgt
= FGT_REVIDR_EL1
,
9476 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->revidr
},
9478 ARMCPRegInfo id_v8_midr_alias_cp_reginfo
= {
9479 .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
| ARM_CP_NO_GDB
,
9480 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
9481 .access
= PL1_R
, .resetvalue
= cpu
->midr
9483 ARMCPRegInfo id_cp_reginfo
[] = {
9484 /* These are common to v8 and pre-v8 */
9486 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 1,
9487 .access
= PL1_R
, .accessfn
= ctr_el0_access
,
9488 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
9489 { .name
= "CTR_EL0", .state
= ARM_CP_STATE_AA64
,
9490 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 0, .crm
= 0,
9491 .access
= PL0_R
, .accessfn
= ctr_el0_access
,
9493 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
9494 /* TCMTR and TLBTR exist in v8 but have no 64-bit versions */
9496 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 2,
9498 .accessfn
= access_aa32_tid1
,
9499 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
9501 /* TLBTR is specific to VMSA */
9502 ARMCPRegInfo id_tlbtr_reginfo
= {
9504 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 3,
9506 .accessfn
= access_aa32_tid1
,
9507 .type
= ARM_CP_CONST
, .resetvalue
= 0,
9509 /* MPUIR is specific to PMSA V6+ */
9510 ARMCPRegInfo id_mpuir_reginfo
= {
9512 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
9513 .access
= PL1_R
, .type
= ARM_CP_CONST
,
9514 .resetvalue
= cpu
->pmsav7_dregion
<< 8
9516 /* HMPUIR is specific to PMSA V8 */
9517 ARMCPRegInfo id_hmpuir_reginfo
= {
9519 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 4,
9520 .access
= PL2_R
, .type
= ARM_CP_CONST
,
9521 .resetvalue
= cpu
->pmsav8r_hdregion
9523 static const ARMCPRegInfo crn0_wi_reginfo
= {
9524 .name
= "CRN0_WI", .cp
= 15, .crn
= 0, .crm
= CP_ANY
,
9525 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_W
,
9526 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
9528 #ifdef CONFIG_USER_ONLY
9529 static const ARMCPRegUserSpaceInfo id_v8_user_midr_cp_reginfo
[] = {
9530 { .name
= "MIDR_EL1",
9531 .exported_bits
= R_MIDR_EL1_REVISION_MASK
|
9532 R_MIDR_EL1_PARTNUM_MASK
|
9533 R_MIDR_EL1_ARCHITECTURE_MASK
|
9534 R_MIDR_EL1_VARIANT_MASK
|
9535 R_MIDR_EL1_IMPLEMENTER_MASK
},
9536 { .name
= "REVIDR_EL1" },
9538 modify_arm_cp_regs(id_v8_midr_cp_reginfo
, id_v8_user_midr_cp_reginfo
);
9540 if (arm_feature(env
, ARM_FEATURE_OMAPCP
) ||
9541 arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
9544 * Register the blanket "writes ignored" value first to cover the
9545 * whole space. Then update the specific ID registers to allow write
9546 * access, so that they ignore writes rather than causing them to
9549 define_one_arm_cp_reg(cpu
, &crn0_wi_reginfo
);
9550 for (i
= 0; i
< ARRAY_SIZE(id_pre_v8_midr_cp_reginfo
); ++i
) {
9551 id_pre_v8_midr_cp_reginfo
[i
].access
= PL1_RW
;
9553 for (i
= 0; i
< ARRAY_SIZE(id_cp_reginfo
); ++i
) {
9554 id_cp_reginfo
[i
].access
= PL1_RW
;
9556 id_mpuir_reginfo
.access
= PL1_RW
;
9557 id_tlbtr_reginfo
.access
= PL1_RW
;
9559 if (arm_feature(env
, ARM_FEATURE_V8
)) {
9560 define_arm_cp_regs(cpu
, id_v8_midr_cp_reginfo
);
9561 if (!arm_feature(env
, ARM_FEATURE_PMSA
)) {
9562 define_one_arm_cp_reg(cpu
, &id_v8_midr_alias_cp_reginfo
);
9565 define_arm_cp_regs(cpu
, id_pre_v8_midr_cp_reginfo
);
9567 define_arm_cp_regs(cpu
, id_cp_reginfo
);
9568 if (!arm_feature(env
, ARM_FEATURE_PMSA
)) {
9569 define_one_arm_cp_reg(cpu
, &id_tlbtr_reginfo
);
9570 } else if (arm_feature(env
, ARM_FEATURE_PMSA
) &&
9571 arm_feature(env
, ARM_FEATURE_V8
)) {
9575 define_one_arm_cp_reg(cpu
, &id_mpuir_reginfo
);
9576 define_one_arm_cp_reg(cpu
, &id_hmpuir_reginfo
);
9577 define_arm_cp_regs(cpu
, pmsav8r_cp_reginfo
);
9579 /* Register alias is only valid for first 32 indexes */
9580 for (i
= 0; i
< MIN(cpu
->pmsav7_dregion
, 32); ++i
) {
9581 uint8_t crm
= 0b1000 | extract32(i
, 1, 3);
9582 uint8_t opc1
= extract32(i
, 4, 1);
9583 uint8_t opc2
= extract32(i
, 0, 1) << 2;
9585 tmp_string
= g_strdup_printf("PRBAR%u", i
);
9586 ARMCPRegInfo tmp_prbarn_reginfo
= {
9587 .name
= tmp_string
, .type
= ARM_CP_ALIAS
| ARM_CP_NO_RAW
,
9588 .cp
= 15, .opc1
= opc1
, .crn
= 6, .crm
= crm
, .opc2
= opc2
,
9589 .access
= PL1_RW
, .resetvalue
= 0,
9590 .accessfn
= access_tvm_trvm
,
9591 .writefn
= pmsav8r_regn_write
, .readfn
= pmsav8r_regn_read
9593 define_one_arm_cp_reg(cpu
, &tmp_prbarn_reginfo
);
9596 opc2
= extract32(i
, 0, 1) << 2 | 0x1;
9597 tmp_string
= g_strdup_printf("PRLAR%u", i
);
9598 ARMCPRegInfo tmp_prlarn_reginfo
= {
9599 .name
= tmp_string
, .type
= ARM_CP_ALIAS
| ARM_CP_NO_RAW
,
9600 .cp
= 15, .opc1
= opc1
, .crn
= 6, .crm
= crm
, .opc2
= opc2
,
9601 .access
= PL1_RW
, .resetvalue
= 0,
9602 .accessfn
= access_tvm_trvm
,
9603 .writefn
= pmsav8r_regn_write
, .readfn
= pmsav8r_regn_read
9605 define_one_arm_cp_reg(cpu
, &tmp_prlarn_reginfo
);
9609 /* Register alias is only valid for first 32 indexes */
9610 for (i
= 0; i
< MIN(cpu
->pmsav8r_hdregion
, 32); ++i
) {
9611 uint8_t crm
= 0b1000 | extract32(i
, 1, 3);
9612 uint8_t opc1
= 0b100 | extract32(i
, 4, 1);
9613 uint8_t opc2
= extract32(i
, 0, 1) << 2;
9615 tmp_string
= g_strdup_printf("HPRBAR%u", i
);
9616 ARMCPRegInfo tmp_hprbarn_reginfo
= {
9618 .type
= ARM_CP_NO_RAW
,
9619 .cp
= 15, .opc1
= opc1
, .crn
= 6, .crm
= crm
, .opc2
= opc2
,
9620 .access
= PL2_RW
, .resetvalue
= 0,
9621 .writefn
= pmsav8r_regn_write
, .readfn
= pmsav8r_regn_read
9623 define_one_arm_cp_reg(cpu
, &tmp_hprbarn_reginfo
);
9626 opc2
= extract32(i
, 0, 1) << 2 | 0x1;
9627 tmp_string
= g_strdup_printf("HPRLAR%u", i
);
9628 ARMCPRegInfo tmp_hprlarn_reginfo
= {
9630 .type
= ARM_CP_NO_RAW
,
9631 .cp
= 15, .opc1
= opc1
, .crn
= 6, .crm
= crm
, .opc2
= opc2
,
9632 .access
= PL2_RW
, .resetvalue
= 0,
9633 .writefn
= pmsav8r_regn_write
, .readfn
= pmsav8r_regn_read
9635 define_one_arm_cp_reg(cpu
, &tmp_hprlarn_reginfo
);
9638 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
9639 define_one_arm_cp_reg(cpu
, &id_mpuir_reginfo
);
9643 if (arm_feature(env
, ARM_FEATURE_MPIDR
)) {
9644 ARMCPRegInfo mpidr_cp_reginfo
[] = {
9645 { .name
= "MPIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
9646 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 5,
9647 .fgt
= FGT_MPIDR_EL1
,
9648 .access
= PL1_R
, .readfn
= mpidr_read
, .type
= ARM_CP_NO_RAW
},
9650 #ifdef CONFIG_USER_ONLY
9651 static const ARMCPRegUserSpaceInfo mpidr_user_cp_reginfo
[] = {
9652 { .name
= "MPIDR_EL1",
9653 .fixed_bits
= 0x0000000080000000 },
9655 modify_arm_cp_regs(mpidr_cp_reginfo
, mpidr_user_cp_reginfo
);
9657 define_arm_cp_regs(cpu
, mpidr_cp_reginfo
);
9660 if (arm_feature(env
, ARM_FEATURE_AUXCR
)) {
9661 ARMCPRegInfo auxcr_reginfo
[] = {
9662 { .name
= "ACTLR_EL1", .state
= ARM_CP_STATE_BOTH
,
9663 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 1,
9664 .access
= PL1_RW
, .accessfn
= access_tacr
,
9665 .nv2_redirect_offset
= 0x118,
9666 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->reset_auxcr
},
9667 { .name
= "ACTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
9668 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 1,
9669 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
9671 { .name
= "ACTLR_EL3", .state
= ARM_CP_STATE_AA64
,
9672 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 1,
9673 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
9676 define_arm_cp_regs(cpu
, auxcr_reginfo
);
9677 if (cpu_isar_feature(aa32_ac2
, cpu
)) {
9678 define_arm_cp_regs(cpu
, actlr2_hactlr2_reginfo
);
9682 if (arm_feature(env
, ARM_FEATURE_CBAR
)) {
9684 * CBAR is IMPDEF, but common on Arm Cortex-A implementations.
9685 * There are two flavours:
9686 * (1) older 32-bit only cores have a simple 32-bit CBAR
9687 * (2) 64-bit cores have a 64-bit CBAR visible to AArch64, plus a
9688 * 32-bit register visible to AArch32 at a different encoding
9689 * to the "flavour 1" register and with the bits rearranged to
9690 * be able to squash a 64-bit address into the 32-bit view.
9691 * We distinguish the two via the ARM_FEATURE_AARCH64 flag, but
9692 * in future if we support AArch32-only configs of some of the
9693 * AArch64 cores we might need to add a specific feature flag
9694 * to indicate cores with "flavour 2" CBAR.
9696 if (arm_feature(env
, ARM_FEATURE_V8
)) {
9697 /* 32 bit view is [31:18] 0...0 [43:32]. */
9698 uint32_t cbar32
= (extract64(cpu
->reset_cbar
, 18, 14) << 18)
9699 | extract64(cpu
->reset_cbar
, 32, 12);
9700 ARMCPRegInfo cbar_reginfo
[] = {
9702 .type
= ARM_CP_CONST
,
9703 .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 1, .opc2
= 0,
9704 .access
= PL1_R
, .resetvalue
= cbar32
},
9705 { .name
= "CBAR_EL1", .state
= ARM_CP_STATE_AA64
,
9706 .type
= ARM_CP_CONST
,
9707 .opc0
= 3, .opc1
= 1, .crn
= 15, .crm
= 3, .opc2
= 0,
9708 .access
= PL1_R
, .resetvalue
= cpu
->reset_cbar
},
9710 /* We don't implement a r/w 64 bit CBAR currently */
9711 assert(arm_feature(env
, ARM_FEATURE_CBAR_RO
));
9712 define_arm_cp_regs(cpu
, cbar_reginfo
);
9714 ARMCPRegInfo cbar
= {
9716 .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 4, .opc2
= 0,
9717 .access
= PL1_R
| PL3_W
, .resetvalue
= cpu
->reset_cbar
,
9718 .fieldoffset
= offsetof(CPUARMState
,
9719 cp15
.c15_config_base_address
)
9721 if (arm_feature(env
, ARM_FEATURE_CBAR_RO
)) {
9722 cbar
.access
= PL1_R
;
9723 cbar
.fieldoffset
= 0;
9724 cbar
.type
= ARM_CP_CONST
;
9726 define_one_arm_cp_reg(cpu
, &cbar
);
9730 if (arm_feature(env
, ARM_FEATURE_VBAR
)) {
9731 static const ARMCPRegInfo vbar_cp_reginfo
[] = {
9732 { .name
= "VBAR", .state
= ARM_CP_STATE_BOTH
,
9733 .opc0
= 3, .crn
= 12, .crm
= 0, .opc1
= 0, .opc2
= 0,
9734 .access
= PL1_RW
, .writefn
= vbar_write
,
9735 .accessfn
= access_nv1
,
9736 .fgt
= FGT_VBAR_EL1
,
9737 .nv2_redirect_offset
= 0x250 | NV2_REDIR_NV1
,
9738 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.vbar_s
),
9739 offsetof(CPUARMState
, cp15
.vbar_ns
) },
9742 define_arm_cp_regs(cpu
, vbar_cp_reginfo
);
9745 /* Generic registers whose values depend on the implementation */
9747 ARMCPRegInfo sctlr
= {
9748 .name
= "SCTLR", .state
= ARM_CP_STATE_BOTH
,
9749 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 0,
9750 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
9751 .fgt
= FGT_SCTLR_EL1
,
9752 .nv2_redirect_offset
= 0x110 | NV2_REDIR_NV1
,
9753 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.sctlr_s
),
9754 offsetof(CPUARMState
, cp15
.sctlr_ns
) },
9755 .writefn
= sctlr_write
, .resetvalue
= cpu
->reset_sctlr
,
9756 .raw_writefn
= raw_write
,
9758 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
9760 * Normally we would always end the TB on an SCTLR write, but Linux
9761 * arch/arm/mach-pxa/sleep.S expects two instructions following
9762 * an MMU enable to execute from cache. Imitate this behaviour.
9764 sctlr
.type
|= ARM_CP_SUPPRESS_TB_END
;
9766 define_one_arm_cp_reg(cpu
, &sctlr
);
9768 if (arm_feature(env
, ARM_FEATURE_PMSA
) &&
9769 arm_feature(env
, ARM_FEATURE_V8
)) {
9770 ARMCPRegInfo vsctlr
= {
9771 .name
= "VSCTLR", .state
= ARM_CP_STATE_AA32
,
9772 .cp
= 15, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 0,
9773 .access
= PL2_RW
, .resetvalue
= 0x0,
9774 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vsctlr
),
9776 define_one_arm_cp_reg(cpu
, &vsctlr
);
9780 if (cpu_isar_feature(aa64_lor
, cpu
)) {
9781 define_arm_cp_regs(cpu
, lor_reginfo
);
9783 if (cpu_isar_feature(aa64_pan
, cpu
)) {
9784 define_one_arm_cp_reg(cpu
, &pan_reginfo
);
9786 #ifndef CONFIG_USER_ONLY
9787 if (cpu_isar_feature(aa64_ats1e1
, cpu
)) {
9788 define_arm_cp_regs(cpu
, ats1e1_reginfo
);
9790 if (cpu_isar_feature(aa32_ats1e1
, cpu
)) {
9791 define_arm_cp_regs(cpu
, ats1cp_reginfo
);
9794 if (cpu_isar_feature(aa64_uao
, cpu
)) {
9795 define_one_arm_cp_reg(cpu
, &uao_reginfo
);
9798 if (cpu_isar_feature(aa64_dit
, cpu
)) {
9799 define_one_arm_cp_reg(cpu
, &dit_reginfo
);
9801 if (cpu_isar_feature(aa64_ssbs
, cpu
)) {
9802 define_one_arm_cp_reg(cpu
, &ssbs_reginfo
);
9804 if (cpu_isar_feature(any_ras
, cpu
)) {
9805 define_arm_cp_regs(cpu
, minimal_ras_reginfo
);
9808 if (cpu_isar_feature(aa64_vh
, cpu
) ||
9809 cpu_isar_feature(aa64_debugv8p2
, cpu
)) {
9810 define_one_arm_cp_reg(cpu
, &contextidr_el2
);
9812 if (arm_feature(env
, ARM_FEATURE_EL2
) && cpu_isar_feature(aa64_vh
, cpu
)) {
9813 define_arm_cp_regs(cpu
, vhe_reginfo
);
9816 if (cpu_isar_feature(aa64_sve
, cpu
)) {
9817 define_arm_cp_regs(cpu
, zcr_reginfo
);
9820 if (cpu_isar_feature(aa64_hcx
, cpu
)) {
9821 define_one_arm_cp_reg(cpu
, &hcrx_el2_reginfo
);
9824 #ifdef TARGET_AARCH64
9825 if (cpu_isar_feature(aa64_sme
, cpu
)) {
9826 define_arm_cp_regs(cpu
, sme_reginfo
);
9828 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
9829 define_arm_cp_regs(cpu
, pauth_reginfo
);
9831 if (cpu_isar_feature(aa64_rndr
, cpu
)) {
9832 define_arm_cp_regs(cpu
, rndr_reginfo
);
9834 if (cpu_isar_feature(aa64_tlbirange
, cpu
)) {
9835 define_arm_cp_regs(cpu
, tlbirange_reginfo
);
9837 if (cpu_isar_feature(aa64_tlbios
, cpu
)) {
9838 define_arm_cp_regs(cpu
, tlbios_reginfo
);
9840 /* Data Cache clean instructions up to PoP */
9841 if (cpu_isar_feature(aa64_dcpop
, cpu
)) {
9842 define_one_arm_cp_reg(cpu
, dcpop_reg
);
9844 if (cpu_isar_feature(aa64_dcpodp
, cpu
)) {
9845 define_one_arm_cp_reg(cpu
, dcpodp_reg
);
9850 * If full MTE is enabled, add all of the system registers.
9851 * If only "instructions available at EL0" are enabled,
9852 * then define only a RAZ/WI version of PSTATE.TCO.
9854 if (cpu_isar_feature(aa64_mte
, cpu
)) {
9855 ARMCPRegInfo gmid_reginfo
= {
9856 .name
= "GMID_EL1", .state
= ARM_CP_STATE_AA64
,
9857 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 4,
9858 .access
= PL1_R
, .accessfn
= access_aa64_tid5
,
9859 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->gm_blocksize
,
9861 define_one_arm_cp_reg(cpu
, &gmid_reginfo
);
9862 define_arm_cp_regs(cpu
, mte_reginfo
);
9863 define_arm_cp_regs(cpu
, mte_el0_cacheop_reginfo
);
9864 } else if (cpu_isar_feature(aa64_mte_insn_reg
, cpu
)) {
9865 define_arm_cp_regs(cpu
, mte_tco_ro_reginfo
);
9866 define_arm_cp_regs(cpu
, mte_el0_cacheop_reginfo
);
9869 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
9870 define_arm_cp_regs(cpu
, scxtnum_reginfo
);
9873 if (cpu_isar_feature(aa64_fgt
, cpu
)) {
9874 define_arm_cp_regs(cpu
, fgt_reginfo
);
9877 if (cpu_isar_feature(aa64_rme
, cpu
)) {
9878 define_arm_cp_regs(cpu
, rme_reginfo
);
9879 if (cpu_isar_feature(aa64_mte
, cpu
)) {
9880 define_arm_cp_regs(cpu
, rme_mte_reginfo
);
9884 if (cpu_isar_feature(aa64_nv2
, cpu
)) {
9885 define_arm_cp_regs(cpu
, nv2_reginfo
);
9889 if (cpu_isar_feature(any_predinv
, cpu
)) {
9890 define_arm_cp_regs(cpu
, predinv_reginfo
);
9893 if (cpu_isar_feature(any_ccidx
, cpu
)) {
9894 define_arm_cp_regs(cpu
, ccsidr2_reginfo
);
9897 #ifndef CONFIG_USER_ONLY
9899 * Register redirections and aliases must be done last,
9900 * after the registers from the other extensions have been defined.
9902 if (arm_feature(env
, ARM_FEATURE_EL2
) && cpu_isar_feature(aa64_vh
, cpu
)) {
9903 define_arm_vh_e2h_redirects_aliases(cpu
);
9909 * Private utility function for define_one_arm_cp_reg_with_opaque():
9910 * add a single reginfo struct to the hash table.
9912 static void add_cpreg_to_hashtable(ARMCPU
*cpu
, const ARMCPRegInfo
*r
,
9913 void *opaque
, CPState state
,
9914 CPSecureState secstate
,
9915 int crm
, int opc1
, int opc2
,
9918 CPUARMState
*env
= &cpu
->env
;
9921 bool is64
= r
->type
& ARM_CP_64BIT
;
9922 bool ns
= secstate
& ARM_CP_SECSTATE_NS
;
9928 case ARM_CP_STATE_AA32
:
9929 /* We assume it is a cp15 register if the .cp field is left unset. */
9930 if (cp
== 0 && r
->state
== ARM_CP_STATE_BOTH
) {
9933 key
= ENCODE_CP_REG(cp
, is64
, ns
, r
->crn
, crm
, opc1
, opc2
);
9935 case ARM_CP_STATE_AA64
:
9937 * To allow abbreviation of ARMCPRegInfo definitions, we treat
9938 * cp == 0 as equivalent to the value for "standard guest-visible
9939 * sysreg". STATE_BOTH definitions are also always "standard sysreg"
9940 * in their AArch64 view (the .cp value may be non-zero for the
9941 * benefit of the AArch32 view).
9943 if (cp
== 0 || r
->state
== ARM_CP_STATE_BOTH
) {
9944 cp
= CP_REG_ARM64_SYSREG_CP
;
9946 key
= ENCODE_AA64_CP_REG(cp
, r
->crn
, crm
, r
->opc0
, opc1
, opc2
);
9949 g_assert_not_reached();
9952 /* Overriding of an existing definition must be explicitly requested. */
9953 if (!(r
->type
& ARM_CP_OVERRIDE
)) {
9954 const ARMCPRegInfo
*oldreg
= get_arm_cp_reginfo(cpu
->cp_regs
, key
);
9956 assert(oldreg
->type
& ARM_CP_OVERRIDE
);
9961 * Eliminate registers that are not present because the EL is missing.
9962 * Doing this here makes it easier to put all registers for a given
9963 * feature into the same ARMCPRegInfo array and define them all at once.
9966 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
9968 * An EL2 register without EL2 but with EL3 is (usually) RES0.
9969 * See rule RJFFP in section D1.1.3 of DDI0487H.a.
9971 int min_el
= ctz32(r
->access
) / 2;
9972 if (min_el
== 2 && !arm_feature(env
, ARM_FEATURE_EL2
)) {
9973 if (r
->type
& ARM_CP_EL3_NO_EL2_UNDEF
) {
9976 make_const
= !(r
->type
& ARM_CP_EL3_NO_EL2_KEEP
);
9979 CPAccessRights max_el
= (arm_feature(env
, ARM_FEATURE_EL2
)
9981 if ((r
->access
& max_el
) == 0) {
9986 /* Combine cpreg and name into one allocation. */
9987 name_len
= strlen(name
) + 1;
9988 r2
= g_malloc(sizeof(*r2
) + name_len
);
9990 r2
->name
= memcpy(r2
+ 1, name
, name_len
);
9993 * Update fields to match the instantiation, overwiting wildcards
9994 * such as CP_ANY, ARM_CP_STATE_BOTH, or ARM_CP_SECSTATE_BOTH.
10001 r2
->secure
= secstate
;
10003 r2
->opaque
= opaque
;
10007 /* This should not have been a very special register to begin. */
10008 int old_special
= r2
->type
& ARM_CP_SPECIAL_MASK
;
10009 assert(old_special
== 0 || old_special
== ARM_CP_NOP
);
10011 * Set the special function to CONST, retaining the other flags.
10012 * This is important for e.g. ARM_CP_SVE so that we still
10013 * take the SVE trap if CPTR_EL3.EZ == 0.
10015 r2
->type
= (r2
->type
& ~ARM_CP_SPECIAL_MASK
) | ARM_CP_CONST
;
10017 * Usually, these registers become RES0, but there are a few
10018 * special cases like VPIDR_EL2 which have a constant non-zero
10019 * value with writes ignored.
10021 if (!(r
->type
& ARM_CP_EL3_NO_EL2_C_NZ
)) {
10022 r2
->resetvalue
= 0;
10025 * ARM_CP_CONST has precedence, so removing the callbacks and
10026 * offsets are not strictly necessary, but it is potentially
10027 * less confusing to debug later.
10030 r2
->writefn
= NULL
;
10031 r2
->raw_readfn
= NULL
;
10032 r2
->raw_writefn
= NULL
;
10033 r2
->resetfn
= NULL
;
10034 r2
->fieldoffset
= 0;
10035 r2
->bank_fieldoffsets
[0] = 0;
10036 r2
->bank_fieldoffsets
[1] = 0;
10038 bool isbanked
= r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1];
10042 * Register is banked (using both entries in array).
10043 * Overwriting fieldoffset as the array is only used to define
10044 * banked registers but later only fieldoffset is used.
10046 r2
->fieldoffset
= r
->bank_fieldoffsets
[ns
];
10048 if (state
== ARM_CP_STATE_AA32
) {
10051 * If the register is banked then we don't need to migrate or
10052 * reset the 32-bit instance in certain cases:
10054 * 1) If the register has both 32-bit and 64-bit instances
10055 * then we can count on the 64-bit instance taking care
10056 * of the non-secure bank.
10057 * 2) If ARMv8 is enabled then we can count on a 64-bit
10058 * version taking care of the secure bank. This requires
10059 * that separate 32 and 64-bit definitions are provided.
10061 if ((r
->state
== ARM_CP_STATE_BOTH
&& ns
) ||
10062 (arm_feature(env
, ARM_FEATURE_V8
) && !ns
)) {
10063 r2
->type
|= ARM_CP_ALIAS
;
10065 } else if ((secstate
!= r
->secure
) && !ns
) {
10067 * The register is not banked so we only want to allow
10068 * migration of the non-secure instance.
10070 r2
->type
|= ARM_CP_ALIAS
;
10073 if (HOST_BIG_ENDIAN
&&
10074 r
->state
== ARM_CP_STATE_BOTH
&& r2
->fieldoffset
) {
10075 r2
->fieldoffset
+= sizeof(uint32_t);
10081 * By convention, for wildcarded registers only the first
10082 * entry is used for migration; the others are marked as
10083 * ALIAS so we don't try to transfer the register
10084 * multiple times. Special registers (ie NOP/WFI) are
10085 * never migratable and not even raw-accessible.
10087 if (r2
->type
& ARM_CP_SPECIAL_MASK
) {
10088 r2
->type
|= ARM_CP_NO_RAW
;
10090 if (((r
->crm
== CP_ANY
) && crm
!= 0) ||
10091 ((r
->opc1
== CP_ANY
) && opc1
!= 0) ||
10092 ((r
->opc2
== CP_ANY
) && opc2
!= 0)) {
10093 r2
->type
|= ARM_CP_ALIAS
| ARM_CP_NO_GDB
;
10097 * Check that raw accesses are either forbidden or handled. Note that
10098 * we can't assert this earlier because the setup of fieldoffset for
10099 * banked registers has to be done first.
10101 if (!(r2
->type
& ARM_CP_NO_RAW
)) {
10102 assert(!raw_accessors_invalid(r2
));
10105 g_hash_table_insert(cpu
->cp_regs
, (gpointer
)(uintptr_t)key
, r2
);
10109 void define_one_arm_cp_reg_with_opaque(ARMCPU
*cpu
,
10110 const ARMCPRegInfo
*r
, void *opaque
)
10113 * Define implementations of coprocessor registers.
10114 * We store these in a hashtable because typically
10115 * there are less than 150 registers in a space which
10116 * is 16*16*16*8*8 = 262144 in size.
10117 * Wildcarding is supported for the crm, opc1 and opc2 fields.
10118 * If a register is defined twice then the second definition is
10119 * used, so this can be used to define some generic registers and
10120 * then override them with implementation specific variations.
10121 * At least one of the original and the second definition should
10122 * include ARM_CP_OVERRIDE in its type bits -- this is just a guard
10123 * against accidental use.
10125 * The state field defines whether the register is to be
10126 * visible in the AArch32 or AArch64 execution state. If the
10127 * state is set to ARM_CP_STATE_BOTH then we synthesise a
10128 * reginfo structure for the AArch32 view, which sees the lower
10129 * 32 bits of the 64 bit register.
10131 * Only registers visible in AArch64 may set r->opc0; opc0 cannot
10132 * be wildcarded. AArch64 registers are always considered to be 64
10133 * bits; the ARM_CP_64BIT* flag applies only to the AArch32 view of
10134 * the register, if any.
10136 int crm
, opc1
, opc2
;
10137 int crmmin
= (r
->crm
== CP_ANY
) ? 0 : r
->crm
;
10138 int crmmax
= (r
->crm
== CP_ANY
) ? 15 : r
->crm
;
10139 int opc1min
= (r
->opc1
== CP_ANY
) ? 0 : r
->opc1
;
10140 int opc1max
= (r
->opc1
== CP_ANY
) ? 7 : r
->opc1
;
10141 int opc2min
= (r
->opc2
== CP_ANY
) ? 0 : r
->opc2
;
10142 int opc2max
= (r
->opc2
== CP_ANY
) ? 7 : r
->opc2
;
10145 /* 64 bit registers have only CRm and Opc1 fields */
10146 assert(!((r
->type
& ARM_CP_64BIT
) && (r
->opc2
|| r
->crn
)));
10147 /* op0 only exists in the AArch64 encodings */
10148 assert((r
->state
!= ARM_CP_STATE_AA32
) || (r
->opc0
== 0));
10149 /* AArch64 regs are all 64 bit so ARM_CP_64BIT is meaningless */
10150 assert((r
->state
!= ARM_CP_STATE_AA64
) || !(r
->type
& ARM_CP_64BIT
));
10152 * This API is only for Arm's system coprocessors (14 and 15) or
10153 * (M-profile or v7A-and-earlier only) for implementation defined
10154 * coprocessors in the range 0..7. Our decode assumes this, since
10155 * 8..13 can be used for other insns including VFP and Neon. See
10156 * valid_cp() in translate.c. Assert here that we haven't tried
10157 * to use an invalid coprocessor number.
10159 switch (r
->state
) {
10160 case ARM_CP_STATE_BOTH
:
10161 /* 0 has a special meaning, but otherwise the same rules as AA32. */
10166 case ARM_CP_STATE_AA32
:
10167 if (arm_feature(&cpu
->env
, ARM_FEATURE_V8
) &&
10168 !arm_feature(&cpu
->env
, ARM_FEATURE_M
)) {
10169 assert(r
->cp
>= 14 && r
->cp
<= 15);
10171 assert(r
->cp
< 8 || (r
->cp
>= 14 && r
->cp
<= 15));
10174 case ARM_CP_STATE_AA64
:
10175 assert(r
->cp
== 0 || r
->cp
== CP_REG_ARM64_SYSREG_CP
);
10178 g_assert_not_reached();
10181 * The AArch64 pseudocode CheckSystemAccess() specifies that op1
10182 * encodes a minimum access level for the register. We roll this
10183 * runtime check into our general permission check code, so check
10184 * here that the reginfo's specified permissions are strict enough
10185 * to encompass the generic architectural permission check.
10187 if (r
->state
!= ARM_CP_STATE_AA32
) {
10188 CPAccessRights mask
;
10191 /* min_EL EL1, but some accessible to EL0 via kernel ABI */
10192 mask
= PL0U_R
| PL1_RW
;
10212 /* min_EL EL1, secure mode only (we don't check the latter) */
10216 /* broken reginfo with out-of-range opc1 */
10217 g_assert_not_reached();
10219 /* assert our permissions are not too lax (stricter is fine) */
10220 assert((r
->access
& ~mask
) == 0);
10224 * Check that the register definition has enough info to handle
10225 * reads and writes if they are permitted.
10227 if (!(r
->type
& (ARM_CP_SPECIAL_MASK
| ARM_CP_CONST
))) {
10228 if (r
->access
& PL3_R
) {
10229 assert((r
->fieldoffset
||
10230 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
10233 if (r
->access
& PL3_W
) {
10234 assert((r
->fieldoffset
||
10235 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
10240 for (crm
= crmmin
; crm
<= crmmax
; crm
++) {
10241 for (opc1
= opc1min
; opc1
<= opc1max
; opc1
++) {
10242 for (opc2
= opc2min
; opc2
<= opc2max
; opc2
++) {
10243 for (state
= ARM_CP_STATE_AA32
;
10244 state
<= ARM_CP_STATE_AA64
; state
++) {
10245 if (r
->state
!= state
&& r
->state
!= ARM_CP_STATE_BOTH
) {
10248 if (state
== ARM_CP_STATE_AA32
) {
10250 * Under AArch32 CP registers can be common
10251 * (same for secure and non-secure world) or banked.
10255 switch (r
->secure
) {
10256 case ARM_CP_SECSTATE_S
:
10257 case ARM_CP_SECSTATE_NS
:
10258 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
10259 r
->secure
, crm
, opc1
, opc2
,
10262 case ARM_CP_SECSTATE_BOTH
:
10263 name
= g_strdup_printf("%s_S", r
->name
);
10264 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
10266 crm
, opc1
, opc2
, name
);
10268 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
10269 ARM_CP_SECSTATE_NS
,
10270 crm
, opc1
, opc2
, r
->name
);
10273 g_assert_not_reached();
10277 * AArch64 registers get mapped to non-secure instance
10280 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
10281 ARM_CP_SECSTATE_NS
,
10282 crm
, opc1
, opc2
, r
->name
);
10290 /* Define a whole list of registers */
10291 void define_arm_cp_regs_with_opaque_len(ARMCPU
*cpu
, const ARMCPRegInfo
*regs
,
10292 void *opaque
, size_t len
)
10295 for (i
= 0; i
< len
; ++i
) {
10296 define_one_arm_cp_reg_with_opaque(cpu
, regs
+ i
, opaque
);
10301 * Modify ARMCPRegInfo for access from userspace.
10303 * This is a data driven modification directed by
10304 * ARMCPRegUserSpaceInfo. All registers become ARM_CP_CONST as
10305 * user-space cannot alter any values and dynamic values pertaining to
10306 * execution state are hidden from user space view anyway.
10308 void modify_arm_cp_regs_with_len(ARMCPRegInfo
*regs
, size_t regs_len
,
10309 const ARMCPRegUserSpaceInfo
*mods
,
10312 for (size_t mi
= 0; mi
< mods_len
; ++mi
) {
10313 const ARMCPRegUserSpaceInfo
*m
= mods
+ mi
;
10314 GPatternSpec
*pat
= NULL
;
10317 pat
= g_pattern_spec_new(m
->name
);
10319 for (size_t ri
= 0; ri
< regs_len
; ++ri
) {
10320 ARMCPRegInfo
*r
= regs
+ ri
;
10322 if (pat
&& g_pattern_match_string(pat
, r
->name
)) {
10323 r
->type
= ARM_CP_CONST
;
10324 r
->access
= PL0U_R
;
10327 } else if (strcmp(r
->name
, m
->name
) == 0) {
10328 r
->type
= ARM_CP_CONST
;
10329 r
->access
= PL0U_R
;
10330 r
->resetvalue
&= m
->exported_bits
;
10331 r
->resetvalue
|= m
->fixed_bits
;
10336 g_pattern_spec_free(pat
);
10341 const ARMCPRegInfo
*get_arm_cp_reginfo(GHashTable
*cpregs
, uint32_t encoded_cp
)
10343 return g_hash_table_lookup(cpregs
, (gpointer
)(uintptr_t)encoded_cp
);
10346 void arm_cp_write_ignore(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
10349 /* Helper coprocessor write function for write-ignore registers */
10352 uint64_t arm_cp_read_zero(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
10354 /* Helper coprocessor write function for read-as-zero registers */
10358 void arm_cp_reset_ignore(CPUARMState
*env
, const ARMCPRegInfo
*opaque
)
10360 /* Helper coprocessor reset function for do-nothing-on-reset registers */
10363 static int bad_mode_switch(CPUARMState
*env
, int mode
, CPSRWriteType write_type
)
10366 * Return true if it is not valid for us to switch to
10367 * this CPU mode (ie all the UNPREDICTABLE cases in
10368 * the ARM ARM CPSRWriteByInstr pseudocode).
10371 /* Changes to or from Hyp via MSR and CPS are illegal. */
10372 if (write_type
== CPSRWriteByInstr
&&
10373 ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_HYP
||
10374 mode
== ARM_CPU_MODE_HYP
)) {
10379 case ARM_CPU_MODE_USR
:
10381 case ARM_CPU_MODE_SYS
:
10382 case ARM_CPU_MODE_SVC
:
10383 case ARM_CPU_MODE_ABT
:
10384 case ARM_CPU_MODE_UND
:
10385 case ARM_CPU_MODE_IRQ
:
10386 case ARM_CPU_MODE_FIQ
:
10388 * Note that we don't implement the IMPDEF NSACR.RFR which in v7
10389 * allows FIQ mode to be Secure-only. (In v8 this doesn't exist.)
10392 * If HCR.TGE is set then changes from Monitor to NS PL1 via MSR
10393 * and CPS are treated as illegal mode changes.
10395 if (write_type
== CPSRWriteByInstr
&&
10396 (env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
&&
10397 (arm_hcr_el2_eff(env
) & HCR_TGE
)) {
10401 case ARM_CPU_MODE_HYP
:
10402 return !arm_is_el2_enabled(env
) || arm_current_el(env
) < 2;
10403 case ARM_CPU_MODE_MON
:
10404 return arm_current_el(env
) < 3;
10410 uint32_t cpsr_read(CPUARMState
*env
)
10413 ZF
= (env
->ZF
== 0);
10414 return env
->uncached_cpsr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
10415 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3) | (env
->QF
<< 27)
10416 | (env
->thumb
<< 5) | ((env
->condexec_bits
& 3) << 25)
10417 | ((env
->condexec_bits
& 0xfc) << 8)
10418 | (env
->GE
<< 16) | (env
->daif
& CPSR_AIF
);
10421 void cpsr_write(CPUARMState
*env
, uint32_t val
, uint32_t mask
,
10422 CPSRWriteType write_type
)
10424 uint32_t changed_daif
;
10425 bool rebuild_hflags
= (write_type
!= CPSRWriteRaw
) &&
10426 (mask
& (CPSR_M
| CPSR_E
| CPSR_IL
));
10428 if (mask
& CPSR_NZCV
) {
10429 env
->ZF
= (~val
) & CPSR_Z
;
10431 env
->CF
= (val
>> 29) & 1;
10432 env
->VF
= (val
<< 3) & 0x80000000;
10434 if (mask
& CPSR_Q
) {
10435 env
->QF
= ((val
& CPSR_Q
) != 0);
10437 if (mask
& CPSR_T
) {
10438 env
->thumb
= ((val
& CPSR_T
) != 0);
10440 if (mask
& CPSR_IT_0_1
) {
10441 env
->condexec_bits
&= ~3;
10442 env
->condexec_bits
|= (val
>> 25) & 3;
10444 if (mask
& CPSR_IT_2_7
) {
10445 env
->condexec_bits
&= 3;
10446 env
->condexec_bits
|= (val
>> 8) & 0xfc;
10448 if (mask
& CPSR_GE
) {
10449 env
->GE
= (val
>> 16) & 0xf;
10453 * In a V7 implementation that includes the security extensions but does
10454 * not include Virtualization Extensions the SCR.FW and SCR.AW bits control
10455 * whether non-secure software is allowed to change the CPSR_F and CPSR_A
10456 * bits respectively.
10458 * In a V8 implementation, it is permitted for privileged software to
10459 * change the CPSR A/F bits regardless of the SCR.AW/FW bits.
10461 if (write_type
!= CPSRWriteRaw
&& !arm_feature(env
, ARM_FEATURE_V8
) &&
10462 arm_feature(env
, ARM_FEATURE_EL3
) &&
10463 !arm_feature(env
, ARM_FEATURE_EL2
) &&
10464 !arm_is_secure(env
)) {
10466 changed_daif
= (env
->daif
^ val
) & mask
;
10468 if (changed_daif
& CPSR_A
) {
10470 * Check to see if we are allowed to change the masking of async
10471 * abort exceptions from a non-secure state.
10473 if (!(env
->cp15
.scr_el3
& SCR_AW
)) {
10474 qemu_log_mask(LOG_GUEST_ERROR
,
10475 "Ignoring attempt to switch CPSR_A flag from "
10476 "non-secure world with SCR.AW bit clear\n");
10481 if (changed_daif
& CPSR_F
) {
10483 * Check to see if we are allowed to change the masking of FIQ
10484 * exceptions from a non-secure state.
10486 if (!(env
->cp15
.scr_el3
& SCR_FW
)) {
10487 qemu_log_mask(LOG_GUEST_ERROR
,
10488 "Ignoring attempt to switch CPSR_F flag from "
10489 "non-secure world with SCR.FW bit clear\n");
10494 * Check whether non-maskable FIQ (NMFI) support is enabled.
10495 * If this bit is set software is not allowed to mask
10496 * FIQs, but is allowed to set CPSR_F to 0.
10498 if ((A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_NMFI
) &&
10500 qemu_log_mask(LOG_GUEST_ERROR
,
10501 "Ignoring attempt to enable CPSR_F flag "
10502 "(non-maskable FIQ [NMFI] support enabled)\n");
10508 env
->daif
&= ~(CPSR_AIF
& mask
);
10509 env
->daif
|= val
& CPSR_AIF
& mask
;
10511 if (write_type
!= CPSRWriteRaw
&&
10512 ((env
->uncached_cpsr
^ val
) & mask
& CPSR_M
)) {
10513 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_USR
) {
10515 * Note that we can only get here in USR mode if this is a
10516 * gdb stub write; for this case we follow the architectural
10517 * behaviour for guest writes in USR mode of ignoring an attempt
10518 * to switch mode. (Those are caught by translate.c for writes
10519 * triggered by guest instructions.)
10522 } else if (bad_mode_switch(env
, val
& CPSR_M
, write_type
)) {
10524 * Attempt to switch to an invalid mode: this is UNPREDICTABLE in
10525 * v7, and has defined behaviour in v8:
10526 * + leave CPSR.M untouched
10527 * + allow changes to the other CPSR fields
10529 * For user changes via the GDB stub, we don't set PSTATE.IL,
10530 * as this would be unnecessarily harsh for a user error.
10533 if (write_type
!= CPSRWriteByGDBStub
&&
10534 arm_feature(env
, ARM_FEATURE_V8
)) {
10538 qemu_log_mask(LOG_GUEST_ERROR
,
10539 "Illegal AArch32 mode switch attempt from %s to %s\n",
10540 aarch32_mode_name(env
->uncached_cpsr
),
10541 aarch32_mode_name(val
));
10543 qemu_log_mask(CPU_LOG_INT
, "%s %s to %s PC 0x%" PRIx32
"\n",
10544 write_type
== CPSRWriteExceptionReturn
?
10545 "Exception return from AArch32" :
10546 "AArch32 mode switch from",
10547 aarch32_mode_name(env
->uncached_cpsr
),
10548 aarch32_mode_name(val
), env
->regs
[15]);
10549 switch_mode(env
, val
& CPSR_M
);
10552 mask
&= ~CACHED_CPSR_BITS
;
10553 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~mask
) | (val
& mask
);
10554 if (tcg_enabled() && rebuild_hflags
) {
10555 arm_rebuild_hflags(env
);
10559 #ifdef CONFIG_USER_ONLY
10561 static void switch_mode(CPUARMState
*env
, int mode
)
10563 ARMCPU
*cpu
= env_archcpu(env
);
10565 if (mode
!= ARM_CPU_MODE_USR
) {
10566 cpu_abort(CPU(cpu
), "Tried to switch out of user mode\n");
10570 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
10571 uint32_t cur_el
, bool secure
)
10576 void aarch64_sync_64_to_32(CPUARMState
*env
)
10578 g_assert_not_reached();
10583 static void switch_mode(CPUARMState
*env
, int mode
)
10588 old_mode
= env
->uncached_cpsr
& CPSR_M
;
10589 if (mode
== old_mode
) {
10593 if (old_mode
== ARM_CPU_MODE_FIQ
) {
10594 memcpy(env
->fiq_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
10595 memcpy(env
->regs
+ 8, env
->usr_regs
, 5 * sizeof(uint32_t));
10596 } else if (mode
== ARM_CPU_MODE_FIQ
) {
10597 memcpy(env
->usr_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
10598 memcpy(env
->regs
+ 8, env
->fiq_regs
, 5 * sizeof(uint32_t));
10601 i
= bank_number(old_mode
);
10602 env
->banked_r13
[i
] = env
->regs
[13];
10603 env
->banked_spsr
[i
] = env
->spsr
;
10605 i
= bank_number(mode
);
10606 env
->regs
[13] = env
->banked_r13
[i
];
10607 env
->spsr
= env
->banked_spsr
[i
];
10609 env
->banked_r14
[r14_bank_number(old_mode
)] = env
->regs
[14];
10610 env
->regs
[14] = env
->banked_r14
[r14_bank_number(mode
)];
10614 * Physical Interrupt Target EL Lookup Table
10616 * [ From ARM ARM section G1.13.4 (Table G1-15) ]
10618 * The below multi-dimensional table is used for looking up the target
10619 * exception level given numerous condition criteria. Specifically, the
10620 * target EL is based on SCR and HCR routing controls as well as the
10621 * currently executing EL and secure state.
10624 * target_el_table[2][2][2][2][2][4]
10625 * | | | | | +--- Current EL
10626 * | | | | +------ Non-secure(0)/Secure(1)
10627 * | | | +--------- HCR mask override
10628 * | | +------------ SCR exec state control
10629 * | +--------------- SCR mask override
10630 * +------------------ 32-bit(0)/64-bit(1) EL3
10632 * The table values are as such:
10634 * -1 = Cannot occur
10636 * The ARM ARM target EL table includes entries indicating that an "exception
10637 * is not taken". The two cases where this is applicable are:
10638 * 1) An exception is taken from EL3 but the SCR does not have the exception
10640 * 2) An exception is taken from EL2 but the HCR does not have the exception
10642 * In these two cases, the below table contain a target of EL1. This value is
10643 * returned as it is expected that the consumer of the table data will check
10644 * for "target EL >= current EL" to ensure the exception is not taken.
10648 * BIT IRQ IMO Non-secure Secure
10649 * EL3 FIQ RW FMO EL0 EL1 EL2 EL3 EL0 EL1 EL2 EL3
10651 static const int8_t target_el_table
[2][2][2][2][2][4] = {
10652 {{{{/* 0 0 0 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
10653 {/* 0 0 0 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},
10654 {{/* 0 0 1 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
10655 {/* 0 0 1 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},},
10656 {{{/* 0 1 0 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
10657 {/* 0 1 0 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},
10658 {{/* 0 1 1 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
10659 {/* 0 1 1 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},},},
10660 {{{{/* 1 0 0 0 */{ 1, 1, 2, -1 },{ 1, 1, -1, 1 },},
10661 {/* 1 0 0 1 */{ 2, 2, 2, -1 },{ 2, 2, -1, 1 },},},
10662 {{/* 1 0 1 0 */{ 1, 1, 1, -1 },{ 1, 1, 1, 1 },},
10663 {/* 1 0 1 1 */{ 2, 2, 2, -1 },{ 2, 2, 2, 1 },},},},
10664 {{{/* 1 1 0 0 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},
10665 {/* 1 1 0 1 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},},
10666 {{/* 1 1 1 0 */{ 3, 3, 3, -1 },{ 3, 3, 3, 3 },},
10667 {/* 1 1 1 1 */{ 3, 3, 3, -1 },{ 3, 3, 3, 3 },},},},},
10671 * Determine the target EL for physical exceptions
10673 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
10674 uint32_t cur_el
, bool secure
)
10676 CPUARMState
*env
= cpu_env(cs
);
10681 /* Is the highest EL AArch64? */
10682 bool is64
= arm_feature(env
, ARM_FEATURE_AARCH64
);
10685 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
10686 rw
= ((env
->cp15
.scr_el3
& SCR_RW
) == SCR_RW
);
10689 * Either EL2 is the highest EL (and so the EL2 register width
10690 * is given by is64); or there is no EL2 or EL3, in which case
10691 * the value of 'rw' does not affect the table lookup anyway.
10696 hcr_el2
= arm_hcr_el2_eff(env
);
10697 switch (excp_idx
) {
10699 scr
= ((env
->cp15
.scr_el3
& SCR_IRQ
) == SCR_IRQ
);
10700 hcr
= hcr_el2
& HCR_IMO
;
10703 scr
= ((env
->cp15
.scr_el3
& SCR_FIQ
) == SCR_FIQ
);
10704 hcr
= hcr_el2
& HCR_FMO
;
10707 scr
= ((env
->cp15
.scr_el3
& SCR_EA
) == SCR_EA
);
10708 hcr
= hcr_el2
& HCR_AMO
;
10713 * For these purposes, TGE and AMO/IMO/FMO both force the
10714 * interrupt to EL2. Fold TGE into the bit extracted above.
10716 hcr
|= (hcr_el2
& HCR_TGE
) != 0;
10718 /* Perform a table-lookup for the target EL given the current state */
10719 target_el
= target_el_table
[is64
][scr
][rw
][hcr
][secure
][cur_el
];
10721 assert(target_el
> 0);
10726 void arm_log_exception(CPUState
*cs
)
10728 int idx
= cs
->exception_index
;
10730 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
10731 const char *exc
= NULL
;
10732 static const char * const excnames
[] = {
10733 [EXCP_UDEF
] = "Undefined Instruction",
10734 [EXCP_SWI
] = "SVC",
10735 [EXCP_PREFETCH_ABORT
] = "Prefetch Abort",
10736 [EXCP_DATA_ABORT
] = "Data Abort",
10737 [EXCP_IRQ
] = "IRQ",
10738 [EXCP_FIQ
] = "FIQ",
10739 [EXCP_BKPT
] = "Breakpoint",
10740 [EXCP_EXCEPTION_EXIT
] = "QEMU v7M exception exit",
10741 [EXCP_KERNEL_TRAP
] = "QEMU intercept of kernel commpage",
10742 [EXCP_HVC
] = "Hypervisor Call",
10743 [EXCP_HYP_TRAP
] = "Hypervisor Trap",
10744 [EXCP_SMC
] = "Secure Monitor Call",
10745 [EXCP_VIRQ
] = "Virtual IRQ",
10746 [EXCP_VFIQ
] = "Virtual FIQ",
10747 [EXCP_SEMIHOST
] = "Semihosting call",
10748 [EXCP_NOCP
] = "v7M NOCP UsageFault",
10749 [EXCP_INVSTATE
] = "v7M INVSTATE UsageFault",
10750 [EXCP_STKOF
] = "v8M STKOF UsageFault",
10751 [EXCP_LAZYFP
] = "v7M exception during lazy FP stacking",
10752 [EXCP_LSERR
] = "v8M LSERR UsageFault",
10753 [EXCP_UNALIGNED
] = "v7M UNALIGNED UsageFault",
10754 [EXCP_DIVBYZERO
] = "v7M DIVBYZERO UsageFault",
10755 [EXCP_VSERR
] = "Virtual SERR",
10756 [EXCP_GPC
] = "Granule Protection Check",
10759 if (idx
>= 0 && idx
< ARRAY_SIZE(excnames
)) {
10760 exc
= excnames
[idx
];
10765 qemu_log_mask(CPU_LOG_INT
, "Taking exception %d [%s] on CPU %d\n",
10766 idx
, exc
, cs
->cpu_index
);
10771 * Function used to synchronize QEMU's AArch64 register set with AArch32
10772 * register set. This is necessary when switching between AArch32 and AArch64
10775 void aarch64_sync_32_to_64(CPUARMState
*env
)
10778 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
10780 /* We can blanket copy R[0:7] to X[0:7] */
10781 for (i
= 0; i
< 8; i
++) {
10782 env
->xregs
[i
] = env
->regs
[i
];
10786 * Unless we are in FIQ mode, x8-x12 come from the user registers r8-r12.
10787 * Otherwise, they come from the banked user regs.
10789 if (mode
== ARM_CPU_MODE_FIQ
) {
10790 for (i
= 8; i
< 13; i
++) {
10791 env
->xregs
[i
] = env
->usr_regs
[i
- 8];
10794 for (i
= 8; i
< 13; i
++) {
10795 env
->xregs
[i
] = env
->regs
[i
];
10800 * Registers x13-x23 are the various mode SP and FP registers. Registers
10801 * r13 and r14 are only copied if we are in that mode, otherwise we copy
10802 * from the mode banked register.
10804 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
10805 env
->xregs
[13] = env
->regs
[13];
10806 env
->xregs
[14] = env
->regs
[14];
10808 env
->xregs
[13] = env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)];
10809 /* HYP is an exception in that it is copied from r14 */
10810 if (mode
== ARM_CPU_MODE_HYP
) {
10811 env
->xregs
[14] = env
->regs
[14];
10813 env
->xregs
[14] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_USR
)];
10817 if (mode
== ARM_CPU_MODE_HYP
) {
10818 env
->xregs
[15] = env
->regs
[13];
10820 env
->xregs
[15] = env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)];
10823 if (mode
== ARM_CPU_MODE_IRQ
) {
10824 env
->xregs
[16] = env
->regs
[14];
10825 env
->xregs
[17] = env
->regs
[13];
10827 env
->xregs
[16] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_IRQ
)];
10828 env
->xregs
[17] = env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)];
10831 if (mode
== ARM_CPU_MODE_SVC
) {
10832 env
->xregs
[18] = env
->regs
[14];
10833 env
->xregs
[19] = env
->regs
[13];
10835 env
->xregs
[18] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_SVC
)];
10836 env
->xregs
[19] = env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)];
10839 if (mode
== ARM_CPU_MODE_ABT
) {
10840 env
->xregs
[20] = env
->regs
[14];
10841 env
->xregs
[21] = env
->regs
[13];
10843 env
->xregs
[20] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_ABT
)];
10844 env
->xregs
[21] = env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)];
10847 if (mode
== ARM_CPU_MODE_UND
) {
10848 env
->xregs
[22] = env
->regs
[14];
10849 env
->xregs
[23] = env
->regs
[13];
10851 env
->xregs
[22] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_UND
)];
10852 env
->xregs
[23] = env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)];
10856 * Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
10857 * mode, then we can copy from r8-r14. Otherwise, we copy from the
10858 * FIQ bank for r8-r14.
10860 if (mode
== ARM_CPU_MODE_FIQ
) {
10861 for (i
= 24; i
< 31; i
++) {
10862 env
->xregs
[i
] = env
->regs
[i
- 16]; /* X[24:30] <- R[8:14] */
10865 for (i
= 24; i
< 29; i
++) {
10866 env
->xregs
[i
] = env
->fiq_regs
[i
- 24];
10868 env
->xregs
[29] = env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)];
10869 env
->xregs
[30] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_FIQ
)];
10872 env
->pc
= env
->regs
[15];
10876 * Function used to synchronize QEMU's AArch32 register set with AArch64
10877 * register set. This is necessary when switching between AArch32 and AArch64
10880 void aarch64_sync_64_to_32(CPUARMState
*env
)
10883 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
10885 /* We can blanket copy X[0:7] to R[0:7] */
10886 for (i
= 0; i
< 8; i
++) {
10887 env
->regs
[i
] = env
->xregs
[i
];
10891 * Unless we are in FIQ mode, r8-r12 come from the user registers x8-x12.
10892 * Otherwise, we copy x8-x12 into the banked user regs.
10894 if (mode
== ARM_CPU_MODE_FIQ
) {
10895 for (i
= 8; i
< 13; i
++) {
10896 env
->usr_regs
[i
- 8] = env
->xregs
[i
];
10899 for (i
= 8; i
< 13; i
++) {
10900 env
->regs
[i
] = env
->xregs
[i
];
10905 * Registers r13 & r14 depend on the current mode.
10906 * If we are in a given mode, we copy the corresponding x registers to r13
10907 * and r14. Otherwise, we copy the x register to the banked r13 and r14
10910 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
10911 env
->regs
[13] = env
->xregs
[13];
10912 env
->regs
[14] = env
->xregs
[14];
10914 env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[13];
10917 * HYP is an exception in that it does not have its own banked r14 but
10918 * shares the USR r14
10920 if (mode
== ARM_CPU_MODE_HYP
) {
10921 env
->regs
[14] = env
->xregs
[14];
10923 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[14];
10927 if (mode
== ARM_CPU_MODE_HYP
) {
10928 env
->regs
[13] = env
->xregs
[15];
10930 env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)] = env
->xregs
[15];
10933 if (mode
== ARM_CPU_MODE_IRQ
) {
10934 env
->regs
[14] = env
->xregs
[16];
10935 env
->regs
[13] = env
->xregs
[17];
10937 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[16];
10938 env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[17];
10941 if (mode
== ARM_CPU_MODE_SVC
) {
10942 env
->regs
[14] = env
->xregs
[18];
10943 env
->regs
[13] = env
->xregs
[19];
10945 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[18];
10946 env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[19];
10949 if (mode
== ARM_CPU_MODE_ABT
) {
10950 env
->regs
[14] = env
->xregs
[20];
10951 env
->regs
[13] = env
->xregs
[21];
10953 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[20];
10954 env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[21];
10957 if (mode
== ARM_CPU_MODE_UND
) {
10958 env
->regs
[14] = env
->xregs
[22];
10959 env
->regs
[13] = env
->xregs
[23];
10961 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[22];
10962 env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[23];
10966 * Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
10967 * mode, then we can copy to r8-r14. Otherwise, we copy to the
10968 * FIQ bank for r8-r14.
10970 if (mode
== ARM_CPU_MODE_FIQ
) {
10971 for (i
= 24; i
< 31; i
++) {
10972 env
->regs
[i
- 16] = env
->xregs
[i
]; /* X[24:30] -> R[8:14] */
10975 for (i
= 24; i
< 29; i
++) {
10976 env
->fiq_regs
[i
- 24] = env
->xregs
[i
];
10978 env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[29];
10979 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[30];
10982 env
->regs
[15] = env
->pc
;
10985 static void take_aarch32_exception(CPUARMState
*env
, int new_mode
,
10986 uint32_t mask
, uint32_t offset
,
10991 /* Change the CPU state so as to actually take the exception. */
10992 switch_mode(env
, new_mode
);
10995 * For exceptions taken to AArch32 we must clear the SS bit in both
10996 * PSTATE and in the old-state value we save to SPSR_<mode>, so zero it now.
10998 env
->pstate
&= ~PSTATE_SS
;
10999 env
->spsr
= cpsr_read(env
);
11000 /* Clear IT bits. */
11001 env
->condexec_bits
= 0;
11002 /* Switch to the new mode, and to the correct instruction set. */
11003 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~CPSR_M
) | new_mode
;
11005 /* This must be after mode switching. */
11006 new_el
= arm_current_el(env
);
11008 /* Set new mode endianness */
11009 env
->uncached_cpsr
&= ~CPSR_E
;
11010 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_EE
) {
11011 env
->uncached_cpsr
|= CPSR_E
;
11013 /* J and IL must always be cleared for exception entry */
11014 env
->uncached_cpsr
&= ~(CPSR_IL
| CPSR_J
);
11017 if (cpu_isar_feature(aa32_ssbs
, env_archcpu(env
))) {
11018 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_DSSBS_32
) {
11019 env
->uncached_cpsr
|= CPSR_SSBS
;
11021 env
->uncached_cpsr
&= ~CPSR_SSBS
;
11025 if (new_mode
== ARM_CPU_MODE_HYP
) {
11026 env
->thumb
= (env
->cp15
.sctlr_el
[2] & SCTLR_TE
) != 0;
11027 env
->elr_el
[2] = env
->regs
[15];
11029 /* CPSR.PAN is normally preserved preserved unless... */
11030 if (cpu_isar_feature(aa32_pan
, env_archcpu(env
))) {
11033 if (!arm_is_secure_below_el3(env
)) {
11034 /* ... the target is EL3, from non-secure state. */
11035 env
->uncached_cpsr
&= ~CPSR_PAN
;
11038 /* ... the target is EL3, from secure state ... */
11041 /* ... the target is EL1 and SCTLR.SPAN is 0. */
11042 if (!(env
->cp15
.sctlr_el
[new_el
] & SCTLR_SPAN
)) {
11043 env
->uncached_cpsr
|= CPSR_PAN
;
11049 * this is a lie, as there was no c1_sys on V4T/V5, but who cares
11050 * and we should just guard the thumb mode on V4
11052 if (arm_feature(env
, ARM_FEATURE_V4T
)) {
11054 (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_TE
) != 0;
11056 env
->regs
[14] = env
->regs
[15] + offset
;
11058 env
->regs
[15] = newpc
;
11060 if (tcg_enabled()) {
11061 arm_rebuild_hflags(env
);
11065 static void arm_cpu_do_interrupt_aarch32_hyp(CPUState
*cs
)
11068 * Handle exception entry to Hyp mode; this is sufficiently
11069 * different to entry to other AArch32 modes that we handle it
11072 * The vector table entry used is always the 0x14 Hyp mode entry point,
11073 * unless this is an UNDEF/SVC/HVC/abort taken from Hyp to Hyp.
11074 * The offset applied to the preferred return address is always zero
11075 * (see DDI0487C.a section G1.12.3).
11076 * PSTATE A/I/F masks are set based only on the SCR.EA/IRQ/FIQ values.
11078 uint32_t addr
, mask
;
11079 ARMCPU
*cpu
= ARM_CPU(cs
);
11080 CPUARMState
*env
= &cpu
->env
;
11082 switch (cs
->exception_index
) {
11090 /* Fall through to prefetch abort. */
11091 case EXCP_PREFETCH_ABORT
:
11092 env
->cp15
.ifar_s
= env
->exception
.vaddress
;
11093 qemu_log_mask(CPU_LOG_INT
, "...with HIFAR 0x%x\n",
11094 (uint32_t)env
->exception
.vaddress
);
11097 case EXCP_DATA_ABORT
:
11098 env
->cp15
.dfar_s
= env
->exception
.vaddress
;
11099 qemu_log_mask(CPU_LOG_INT
, "...with HDFAR 0x%x\n",
11100 (uint32_t)env
->exception
.vaddress
);
11112 case EXCP_HYP_TRAP
:
11116 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
11119 if (cs
->exception_index
!= EXCP_IRQ
&& cs
->exception_index
!= EXCP_FIQ
) {
11120 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
11122 * QEMU syndrome values are v8-style. v7 has the IL bit
11123 * UNK/SBZP for "field not valid" cases, where v8 uses RES1.
11124 * If this is a v7 CPU, squash the IL bit in those cases.
11126 if (cs
->exception_index
== EXCP_PREFETCH_ABORT
||
11127 (cs
->exception_index
== EXCP_DATA_ABORT
&&
11128 !(env
->exception
.syndrome
& ARM_EL_ISV
)) ||
11129 syn_get_ec(env
->exception
.syndrome
) == EC_UNCATEGORIZED
) {
11130 env
->exception
.syndrome
&= ~ARM_EL_IL
;
11133 env
->cp15
.esr_el
[2] = env
->exception
.syndrome
;
11136 if (arm_current_el(env
) != 2 && addr
< 0x14) {
11141 if (!(env
->cp15
.scr_el3
& SCR_EA
)) {
11144 if (!(env
->cp15
.scr_el3
& SCR_IRQ
)) {
11147 if (!(env
->cp15
.scr_el3
& SCR_FIQ
)) {
11151 addr
+= env
->cp15
.hvbar
;
11153 take_aarch32_exception(env
, ARM_CPU_MODE_HYP
, mask
, 0, addr
);
11156 static void arm_cpu_do_interrupt_aarch32(CPUState
*cs
)
11158 ARMCPU
*cpu
= ARM_CPU(cs
);
11159 CPUARMState
*env
= &cpu
->env
;
11166 /* If this is a debug exception we must update the DBGDSCR.MOE bits */
11167 switch (syn_get_ec(env
->exception
.syndrome
)) {
11168 case EC_BREAKPOINT
:
11169 case EC_BREAKPOINT_SAME_EL
:
11172 case EC_WATCHPOINT
:
11173 case EC_WATCHPOINT_SAME_EL
:
11179 case EC_VECTORCATCH
:
11188 env
->cp15
.mdscr_el1
= deposit64(env
->cp15
.mdscr_el1
, 2, 4, moe
);
11191 if (env
->exception
.target_el
== 2) {
11192 /* Debug exceptions are reported differently on AArch32 */
11193 switch (syn_get_ec(env
->exception
.syndrome
)) {
11194 case EC_BREAKPOINT
:
11195 case EC_BREAKPOINT_SAME_EL
:
11197 case EC_VECTORCATCH
:
11198 env
->exception
.syndrome
= syn_insn_abort(arm_current_el(env
) == 2,
11201 case EC_WATCHPOINT
:
11202 env
->exception
.syndrome
= syn_set_ec(env
->exception
.syndrome
,
11205 case EC_WATCHPOINT_SAME_EL
:
11206 env
->exception
.syndrome
= syn_set_ec(env
->exception
.syndrome
,
11207 EC_DATAABORT_SAME_EL
);
11210 arm_cpu_do_interrupt_aarch32_hyp(cs
);
11214 switch (cs
->exception_index
) {
11216 new_mode
= ARM_CPU_MODE_UND
;
11226 new_mode
= ARM_CPU_MODE_SVC
;
11229 /* The PC already points to the next instruction. */
11233 /* Fall through to prefetch abort. */
11234 case EXCP_PREFETCH_ABORT
:
11235 A32_BANKED_CURRENT_REG_SET(env
, ifsr
, env
->exception
.fsr
);
11236 A32_BANKED_CURRENT_REG_SET(env
, ifar
, env
->exception
.vaddress
);
11237 qemu_log_mask(CPU_LOG_INT
, "...with IFSR 0x%x IFAR 0x%x\n",
11238 env
->exception
.fsr
, (uint32_t)env
->exception
.vaddress
);
11239 new_mode
= ARM_CPU_MODE_ABT
;
11241 mask
= CPSR_A
| CPSR_I
;
11244 case EXCP_DATA_ABORT
:
11245 A32_BANKED_CURRENT_REG_SET(env
, dfsr
, env
->exception
.fsr
);
11246 A32_BANKED_CURRENT_REG_SET(env
, dfar
, env
->exception
.vaddress
);
11247 qemu_log_mask(CPU_LOG_INT
, "...with DFSR 0x%x DFAR 0x%x\n",
11248 env
->exception
.fsr
,
11249 (uint32_t)env
->exception
.vaddress
);
11250 new_mode
= ARM_CPU_MODE_ABT
;
11252 mask
= CPSR_A
| CPSR_I
;
11256 new_mode
= ARM_CPU_MODE_IRQ
;
11258 /* Disable IRQ and imprecise data aborts. */
11259 mask
= CPSR_A
| CPSR_I
;
11261 if (env
->cp15
.scr_el3
& SCR_IRQ
) {
11262 /* IRQ routed to monitor mode */
11263 new_mode
= ARM_CPU_MODE_MON
;
11268 new_mode
= ARM_CPU_MODE_FIQ
;
11270 /* Disable FIQ, IRQ and imprecise data aborts. */
11271 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
11272 if (env
->cp15
.scr_el3
& SCR_FIQ
) {
11273 /* FIQ routed to monitor mode */
11274 new_mode
= ARM_CPU_MODE_MON
;
11279 new_mode
= ARM_CPU_MODE_IRQ
;
11281 /* Disable IRQ and imprecise data aborts. */
11282 mask
= CPSR_A
| CPSR_I
;
11286 new_mode
= ARM_CPU_MODE_FIQ
;
11288 /* Disable FIQ, IRQ and imprecise data aborts. */
11289 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
11295 * Note that this is reported as a data abort, but the DFAR
11296 * has an UNKNOWN value. Construct the SError syndrome from
11297 * AET and ExT fields.
11299 ARMMMUFaultInfo fi
= { .type
= ARMFault_AsyncExternal
, };
11301 if (extended_addresses_enabled(env
)) {
11302 env
->exception
.fsr
= arm_fi_to_lfsc(&fi
);
11304 env
->exception
.fsr
= arm_fi_to_sfsc(&fi
);
11306 env
->exception
.fsr
|= env
->cp15
.vsesr_el2
& 0xd000;
11307 A32_BANKED_CURRENT_REG_SET(env
, dfsr
, env
->exception
.fsr
);
11308 qemu_log_mask(CPU_LOG_INT
, "...with IFSR 0x%x\n",
11309 env
->exception
.fsr
);
11311 new_mode
= ARM_CPU_MODE_ABT
;
11313 mask
= CPSR_A
| CPSR_I
;
11318 new_mode
= ARM_CPU_MODE_MON
;
11320 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
11324 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
11325 return; /* Never happens. Keep compiler happy. */
11328 if (new_mode
== ARM_CPU_MODE_MON
) {
11329 addr
+= env
->cp15
.mvbar
;
11330 } else if (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_V
) {
11331 /* High vectors. When enabled, base address cannot be remapped. */
11332 addr
+= 0xffff0000;
11335 * ARM v7 architectures provide a vector base address register to remap
11336 * the interrupt vector table.
11337 * This register is only followed in non-monitor mode, and is banked.
11338 * Note: only bits 31:5 are valid.
11340 addr
+= A32_BANKED_CURRENT_REG_GET(env
, vbar
);
11343 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
) {
11344 env
->cp15
.scr_el3
&= ~SCR_NS
;
11347 take_aarch32_exception(env
, new_mode
, mask
, offset
, addr
);
11350 static int aarch64_regnum(CPUARMState
*env
, int aarch32_reg
)
11353 * Return the register number of the AArch64 view of the AArch32
11354 * register @aarch32_reg. The CPUARMState CPSR is assumed to still
11355 * be that of the AArch32 mode the exception came from.
11357 int mode
= env
->uncached_cpsr
& CPSR_M
;
11359 switch (aarch32_reg
) {
11361 return aarch32_reg
;
11363 return mode
== ARM_CPU_MODE_FIQ
? aarch32_reg
+ 16 : aarch32_reg
;
11366 case ARM_CPU_MODE_USR
:
11367 case ARM_CPU_MODE_SYS
:
11369 case ARM_CPU_MODE_HYP
:
11371 case ARM_CPU_MODE_IRQ
:
11373 case ARM_CPU_MODE_SVC
:
11375 case ARM_CPU_MODE_ABT
:
11377 case ARM_CPU_MODE_UND
:
11379 case ARM_CPU_MODE_FIQ
:
11382 g_assert_not_reached();
11386 case ARM_CPU_MODE_USR
:
11387 case ARM_CPU_MODE_SYS
:
11388 case ARM_CPU_MODE_HYP
:
11390 case ARM_CPU_MODE_IRQ
:
11392 case ARM_CPU_MODE_SVC
:
11394 case ARM_CPU_MODE_ABT
:
11396 case ARM_CPU_MODE_UND
:
11398 case ARM_CPU_MODE_FIQ
:
11401 g_assert_not_reached();
11406 g_assert_not_reached();
11410 static uint32_t cpsr_read_for_spsr_elx(CPUARMState
*env
)
11412 uint32_t ret
= cpsr_read(env
);
11414 /* Move DIT to the correct location for SPSR_ELx */
11415 if (ret
& CPSR_DIT
) {
11419 /* Merge PSTATE.SS into SPSR_ELx */
11420 ret
|= env
->pstate
& PSTATE_SS
;
11425 static bool syndrome_is_sync_extabt(uint32_t syndrome
)
11427 /* Return true if this syndrome value is a synchronous external abort */
11428 switch (syn_get_ec(syndrome
)) {
11430 case EC_INSNABORT_SAME_EL
:
11432 case EC_DATAABORT_SAME_EL
:
11433 /* Look at fault status code for all the synchronous ext abort cases */
11434 switch (syndrome
& 0x3f) {
11450 /* Handle exception entry to a target EL which is using AArch64 */
11451 static void arm_cpu_do_interrupt_aarch64(CPUState
*cs
)
11453 ARMCPU
*cpu
= ARM_CPU(cs
);
11454 CPUARMState
*env
= &cpu
->env
;
11455 unsigned int new_el
= env
->exception
.target_el
;
11456 target_ulong addr
= env
->cp15
.vbar_el
[new_el
];
11457 unsigned int new_mode
= aarch64_pstate_mode(new_el
, true);
11458 unsigned int old_mode
;
11459 unsigned int cur_el
= arm_current_el(env
);
11462 if (tcg_enabled()) {
11464 * Note that new_el can never be 0. If cur_el is 0, then
11465 * el0_a64 is is_a64(), else el0_a64 is ignored.
11467 aarch64_sve_change_el(env
, cur_el
, new_el
, is_a64(env
));
11470 if (cur_el
< new_el
) {
11472 * Entry vector offset depends on whether the implemented EL
11473 * immediately lower than the target level is using AArch32 or AArch64
11480 is_aa64
= (env
->cp15
.scr_el3
& SCR_RW
) != 0;
11483 hcr
= arm_hcr_el2_eff(env
);
11484 if ((hcr
& (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
11485 is_aa64
= (hcr
& HCR_RW
) != 0;
11490 is_aa64
= is_a64(env
);
11493 g_assert_not_reached();
11501 } else if (pstate_read(env
) & PSTATE_SP
) {
11505 switch (cs
->exception_index
) {
11507 qemu_log_mask(CPU_LOG_INT
, "...with MFAR 0x%" PRIx64
"\n",
11508 env
->cp15
.mfar_el3
);
11510 case EXCP_PREFETCH_ABORT
:
11511 case EXCP_DATA_ABORT
:
11513 * FEAT_DoubleFault allows synchronous external aborts taken to EL3
11514 * to be taken to the SError vector entrypoint.
11516 if (new_el
== 3 && (env
->cp15
.scr_el3
& SCR_EASE
) &&
11517 syndrome_is_sync_extabt(env
->exception
.syndrome
)) {
11520 env
->cp15
.far_el
[new_el
] = env
->exception
.vaddress
;
11521 qemu_log_mask(CPU_LOG_INT
, "...with FAR 0x%" PRIx64
"\n",
11522 env
->cp15
.far_el
[new_el
]);
11528 case EXCP_HYP_TRAP
:
11530 switch (syn_get_ec(env
->exception
.syndrome
)) {
11531 case EC_ADVSIMDFPACCESSTRAP
:
11533 * QEMU internal FP/SIMD syndromes from AArch32 include the
11534 * TA and coproc fields which are only exposed if the exception
11535 * is taken to AArch32 Hyp mode. Mask them out to get a valid
11536 * AArch64 format syndrome.
11538 env
->exception
.syndrome
&= ~MAKE_64BIT_MASK(0, 20);
11540 case EC_CP14RTTRAP
:
11541 case EC_CP15RTTRAP
:
11542 case EC_CP14DTTRAP
:
11544 * For a trap on AArch32 MRC/MCR/LDC/STC the Rt field is currently
11545 * the raw register field from the insn; when taking this to
11546 * AArch64 we must convert it to the AArch64 view of the register
11547 * number. Notice that we read a 4-bit AArch32 register number and
11548 * write back a 5-bit AArch64 one.
11550 rt
= extract32(env
->exception
.syndrome
, 5, 4);
11551 rt
= aarch64_regnum(env
, rt
);
11552 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
11555 case EC_CP15RRTTRAP
:
11556 case EC_CP14RRTTRAP
:
11557 /* Similarly for MRRC/MCRR traps for Rt and Rt2 fields */
11558 rt
= extract32(env
->exception
.syndrome
, 5, 4);
11559 rt
= aarch64_regnum(env
, rt
);
11560 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
11562 rt
= extract32(env
->exception
.syndrome
, 10, 4);
11563 rt
= aarch64_regnum(env
, rt
);
11564 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
11568 env
->cp15
.esr_el
[new_el
] = env
->exception
.syndrome
;
11580 /* Construct the SError syndrome from IDS and ISS fields. */
11581 env
->exception
.syndrome
= syn_serror(env
->cp15
.vsesr_el2
& 0x1ffffff);
11582 env
->cp15
.esr_el
[new_el
] = env
->exception
.syndrome
;
11585 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
11589 old_mode
= pstate_read(env
);
11590 aarch64_save_sp(env
, arm_current_el(env
));
11591 env
->elr_el
[new_el
] = env
->pc
;
11593 if (cur_el
== 1 && new_el
== 1) {
11594 uint64_t hcr
= arm_hcr_el2_eff(env
);
11595 if ((hcr
& (HCR_NV
| HCR_NV1
| HCR_NV2
)) == HCR_NV
||
11596 (hcr
& (HCR_NV
| HCR_NV2
)) == (HCR_NV
| HCR_NV2
)) {
11598 * FEAT_NV, FEAT_NV2 may need to report EL2 in the SPSR
11599 * by setting M[3:2] to 0b10.
11600 * If NV2 is disabled, change SPSR when NV,NV1 == 1,0 (I_ZJRNN)
11601 * If NV2 is enabled, change SPSR when NV is 1 (I_DBTLM)
11603 old_mode
= deposit32(old_mode
, 2, 2, 2);
11607 old_mode
= cpsr_read_for_spsr_elx(env
);
11608 env
->elr_el
[new_el
] = env
->regs
[15];
11610 aarch64_sync_32_to_64(env
);
11612 env
->condexec_bits
= 0;
11614 env
->banked_spsr
[aarch64_banked_spsr_index(new_el
)] = old_mode
;
11616 qemu_log_mask(CPU_LOG_INT
, "...with SPSR 0x%x\n", old_mode
);
11617 qemu_log_mask(CPU_LOG_INT
, "...with ELR 0x%" PRIx64
"\n",
11618 env
->elr_el
[new_el
]);
11620 if (cpu_isar_feature(aa64_pan
, cpu
)) {
11621 /* The value of PSTATE.PAN is normally preserved, except when ... */
11622 new_mode
|= old_mode
& PSTATE_PAN
;
11625 /* ... the target is EL2 with HCR_EL2.{E2H,TGE} == '11' ... */
11626 if ((arm_hcr_el2_eff(env
) & (HCR_E2H
| HCR_TGE
))
11627 != (HCR_E2H
| HCR_TGE
)) {
11632 /* ... the target is EL1 ... */
11633 /* ... and SCTLR_ELx.SPAN == 0, then set to 1. */
11634 if ((env
->cp15
.sctlr_el
[new_el
] & SCTLR_SPAN
) == 0) {
11635 new_mode
|= PSTATE_PAN
;
11640 if (cpu_isar_feature(aa64_mte
, cpu
)) {
11641 new_mode
|= PSTATE_TCO
;
11644 if (cpu_isar_feature(aa64_ssbs
, cpu
)) {
11645 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_DSSBS_64
) {
11646 new_mode
|= PSTATE_SSBS
;
11648 new_mode
&= ~PSTATE_SSBS
;
11652 pstate_write(env
, PSTATE_DAIF
| new_mode
);
11653 env
->aarch64
= true;
11654 aarch64_restore_sp(env
, new_el
);
11656 if (tcg_enabled()) {
11657 helper_rebuild_hflags_a64(env
, new_el
);
11662 qemu_log_mask(CPU_LOG_INT
, "...to EL%d PC 0x%" PRIx64
" PSTATE 0x%x\n",
11663 new_el
, env
->pc
, pstate_read(env
));
11667 * Do semihosting call and set the appropriate return value. All the
11668 * permission and validity checks have been done at translate time.
11670 * We only see semihosting exceptions in TCG only as they are not
11671 * trapped to the hypervisor in KVM.
11674 static void tcg_handle_semihosting(CPUState
*cs
)
11676 ARMCPU
*cpu
= ARM_CPU(cs
);
11677 CPUARMState
*env
= &cpu
->env
;
11680 qemu_log_mask(CPU_LOG_INT
,
11681 "...handling as semihosting call 0x%" PRIx64
"\n",
11683 do_common_semihosting(cs
);
11686 qemu_log_mask(CPU_LOG_INT
,
11687 "...handling as semihosting call 0x%x\n",
11689 do_common_semihosting(cs
);
11690 env
->regs
[15] += env
->thumb
? 2 : 4;
11696 * Handle a CPU exception for A and R profile CPUs.
11697 * Do any appropriate logging, handle PSCI calls, and then hand off
11698 * to the AArch64-entry or AArch32-entry function depending on the
11699 * target exception level's register width.
11701 * Note: this is used for both TCG (as the do_interrupt tcg op),
11702 * and KVM to re-inject guest debug exceptions, and to
11703 * inject a Synchronous-External-Abort.
11705 void arm_cpu_do_interrupt(CPUState
*cs
)
11707 ARMCPU
*cpu
= ARM_CPU(cs
);
11708 CPUARMState
*env
= &cpu
->env
;
11709 unsigned int new_el
= env
->exception
.target_el
;
11711 assert(!arm_feature(env
, ARM_FEATURE_M
));
11713 arm_log_exception(cs
);
11714 qemu_log_mask(CPU_LOG_INT
, "...from EL%d to EL%d\n", arm_current_el(env
),
11716 if (qemu_loglevel_mask(CPU_LOG_INT
)
11717 && !excp_is_internal(cs
->exception_index
)) {
11718 qemu_log_mask(CPU_LOG_INT
, "...with ESR 0x%x/0x%" PRIx32
"\n",
11719 syn_get_ec(env
->exception
.syndrome
),
11720 env
->exception
.syndrome
);
11723 if (tcg_enabled() && arm_is_psci_call(cpu
, cs
->exception_index
)) {
11724 arm_handle_psci_call(cpu
);
11725 qemu_log_mask(CPU_LOG_INT
, "...handled as PSCI call\n");
11730 * Semihosting semantics depend on the register width of the code
11731 * that caused the exception, not the target exception level, so
11732 * must be handled here.
11735 if (cs
->exception_index
== EXCP_SEMIHOST
) {
11736 tcg_handle_semihosting(cs
);
11742 * Hooks may change global state so BQL should be held, also the
11743 * BQL needs to be held for any modification of
11744 * cs->interrupt_request.
11746 g_assert(bql_locked());
11748 arm_call_pre_el_change_hook(cpu
);
11750 assert(!excp_is_internal(cs
->exception_index
));
11751 if (arm_el_is_aa64(env
, new_el
)) {
11752 arm_cpu_do_interrupt_aarch64(cs
);
11754 arm_cpu_do_interrupt_aarch32(cs
);
11757 arm_call_el_change_hook(cpu
);
11759 if (!kvm_enabled()) {
11760 cs
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
11763 #endif /* !CONFIG_USER_ONLY */
11765 uint64_t arm_sctlr(CPUARMState
*env
, int el
)
11767 /* Only EL0 needs to be adjusted for EL1&0 or EL2&0. */
11769 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, 0);
11770 el
= mmu_idx
== ARMMMUIdx_E20_0
? 2 : 1;
11772 return env
->cp15
.sctlr_el
[el
];
11775 int aa64_va_parameter_tbi(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11777 if (regime_has_2_ranges(mmu_idx
)) {
11778 return extract64(tcr
, 37, 2);
11779 } else if (regime_is_stage2(mmu_idx
)) {
11780 return 0; /* VTCR_EL2 */
11782 /* Replicate the single TBI bit so we always have 2 bits. */
11783 return extract32(tcr
, 20, 1) * 3;
11787 int aa64_va_parameter_tbid(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11789 if (regime_has_2_ranges(mmu_idx
)) {
11790 return extract64(tcr
, 51, 2);
11791 } else if (regime_is_stage2(mmu_idx
)) {
11792 return 0; /* VTCR_EL2 */
11794 /* Replicate the single TBID bit so we always have 2 bits. */
11795 return extract32(tcr
, 29, 1) * 3;
11799 int aa64_va_parameter_tcma(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11801 if (regime_has_2_ranges(mmu_idx
)) {
11802 return extract64(tcr
, 57, 2);
11804 /* Replicate the single TCMA bit so we always have 2 bits. */
11805 return extract32(tcr
, 30, 1) * 3;
11809 static ARMGranuleSize
tg0_to_gran_size(int tg
)
11819 return GranInvalid
;
11823 static ARMGranuleSize
tg1_to_gran_size(int tg
)
11833 return GranInvalid
;
11837 static inline bool have4k(ARMCPU
*cpu
, bool stage2
)
11839 return stage2
? cpu_isar_feature(aa64_tgran4_2
, cpu
)
11840 : cpu_isar_feature(aa64_tgran4
, cpu
);
11843 static inline bool have16k(ARMCPU
*cpu
, bool stage2
)
11845 return stage2
? cpu_isar_feature(aa64_tgran16_2
, cpu
)
11846 : cpu_isar_feature(aa64_tgran16
, cpu
);
11849 static inline bool have64k(ARMCPU
*cpu
, bool stage2
)
11851 return stage2
? cpu_isar_feature(aa64_tgran64_2
, cpu
)
11852 : cpu_isar_feature(aa64_tgran64
, cpu
);
11855 static ARMGranuleSize
sanitize_gran_size(ARMCPU
*cpu
, ARMGranuleSize gran
,
11860 if (have4k(cpu
, stage2
)) {
11865 if (have16k(cpu
, stage2
)) {
11870 if (have64k(cpu
, stage2
)) {
11878 * If the guest selects a granule size that isn't implemented,
11879 * the architecture requires that we behave as if it selected one
11880 * that is (with an IMPDEF choice of which one to pick). We choose
11881 * to implement the smallest supported granule size.
11883 if (have4k(cpu
, stage2
)) {
11886 if (have16k(cpu
, stage2
)) {
11889 assert(have64k(cpu
, stage2
));
11893 ARMVAParameters
aa64_va_parameters(CPUARMState
*env
, uint64_t va
,
11894 ARMMMUIdx mmu_idx
, bool data
,
11897 uint64_t tcr
= regime_tcr(env
, mmu_idx
);
11898 bool epd
, hpd
, tsz_oob
, ds
, ha
, hd
;
11899 int select
, tsz
, tbi
, max_tsz
, min_tsz
, ps
, sh
;
11900 ARMGranuleSize gran
;
11901 ARMCPU
*cpu
= env_archcpu(env
);
11902 bool stage2
= regime_is_stage2(mmu_idx
);
11904 if (!regime_has_2_ranges(mmu_idx
)) {
11906 tsz
= extract32(tcr
, 0, 6);
11907 gran
= tg0_to_gran_size(extract32(tcr
, 14, 2));
11912 hpd
= extract32(tcr
, 24, 1);
11915 sh
= extract32(tcr
, 12, 2);
11916 ps
= extract32(tcr
, 16, 3);
11917 ha
= extract32(tcr
, 21, 1) && cpu_isar_feature(aa64_hafs
, cpu
);
11918 hd
= extract32(tcr
, 22, 1) && cpu_isar_feature(aa64_hdbs
, cpu
);
11919 ds
= extract64(tcr
, 32, 1);
11924 * Bit 55 is always between the two regions, and is canonical for
11925 * determining if address tagging is enabled.
11927 select
= extract64(va
, 55, 1);
11929 tsz
= extract32(tcr
, 0, 6);
11930 gran
= tg0_to_gran_size(extract32(tcr
, 14, 2));
11931 epd
= extract32(tcr
, 7, 1);
11932 sh
= extract32(tcr
, 12, 2);
11933 hpd
= extract64(tcr
, 41, 1);
11934 e0pd
= extract64(tcr
, 55, 1);
11936 tsz
= extract32(tcr
, 16, 6);
11937 gran
= tg1_to_gran_size(extract32(tcr
, 30, 2));
11938 epd
= extract32(tcr
, 23, 1);
11939 sh
= extract32(tcr
, 28, 2);
11940 hpd
= extract64(tcr
, 42, 1);
11941 e0pd
= extract64(tcr
, 56, 1);
11943 ps
= extract64(tcr
, 32, 3);
11944 ha
= extract64(tcr
, 39, 1) && cpu_isar_feature(aa64_hafs
, cpu
);
11945 hd
= extract64(tcr
, 40, 1) && cpu_isar_feature(aa64_hdbs
, cpu
);
11946 ds
= extract64(tcr
, 59, 1);
11948 if (e0pd
&& cpu_isar_feature(aa64_e0pd
, cpu
) &&
11949 regime_is_user(env
, mmu_idx
)) {
11954 gran
= sanitize_gran_size(cpu
, gran
, stage2
);
11956 if (cpu_isar_feature(aa64_st
, cpu
)) {
11957 max_tsz
= 48 - (gran
== Gran64K
);
11963 * DS is RES0 unless FEAT_LPA2 is supported for the given page size;
11964 * adjust the effective value of DS, as documented.
11967 if (gran
== Gran64K
) {
11968 if (cpu_isar_feature(aa64_lva
, cpu
)) {
11973 if (regime_is_stage2(mmu_idx
)) {
11974 if (gran
== Gran16K
) {
11975 ds
= cpu_isar_feature(aa64_tgran16_2_lpa2
, cpu
);
11977 ds
= cpu_isar_feature(aa64_tgran4_2_lpa2
, cpu
);
11980 if (gran
== Gran16K
) {
11981 ds
= cpu_isar_feature(aa64_tgran16_lpa2
, cpu
);
11983 ds
= cpu_isar_feature(aa64_tgran4_lpa2
, cpu
);
11991 if (stage2
&& el1_is_aa32
) {
11993 * For AArch32 EL1 the min txsz (and thus max IPA size) requirements
11994 * are loosened: a configured IPA of 40 bits is permitted even if
11995 * the implemented PA is less than that (and so a 40 bit IPA would
11996 * fault for an AArch64 EL1). See R_DTLMN.
11998 min_tsz
= MIN(min_tsz
, 24);
12001 if (tsz
> max_tsz
) {
12004 } else if (tsz
< min_tsz
) {
12011 /* Present TBI as a composite with TBID. */
12012 tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
12014 tbi
&= ~aa64_va_parameter_tbid(tcr
, mmu_idx
);
12016 tbi
= (tbi
>> select
) & 1;
12018 return (ARMVAParameters
) {
12026 .tsz_oob
= tsz_oob
,
12035 * Note that signed overflow is undefined in C. The following routines are
12036 * careful to use unsigned types where modulo arithmetic is required.
12037 * Failure to do so _will_ break on newer gcc.
12040 /* Signed saturating arithmetic. */
12042 /* Perform 16-bit signed saturating addition. */
12043 static inline uint16_t add16_sat(uint16_t a
, uint16_t b
)
12048 if (((res
^ a
) & 0x8000) && !((a
^ b
) & 0x8000)) {
12058 /* Perform 8-bit signed saturating addition. */
12059 static inline uint8_t add8_sat(uint8_t a
, uint8_t b
)
12064 if (((res
^ a
) & 0x80) && !((a
^ b
) & 0x80)) {
12074 /* Perform 16-bit signed saturating subtraction. */
12075 static inline uint16_t sub16_sat(uint16_t a
, uint16_t b
)
12080 if (((res
^ a
) & 0x8000) && ((a
^ b
) & 0x8000)) {
12090 /* Perform 8-bit signed saturating subtraction. */
12091 static inline uint8_t sub8_sat(uint8_t a
, uint8_t b
)
12096 if (((res
^ a
) & 0x80) && ((a
^ b
) & 0x80)) {
12106 #define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
12107 #define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
12108 #define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
12109 #define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
12112 #include "op_addsub.h"
12114 /* Unsigned saturating arithmetic. */
12115 static inline uint16_t add16_usat(uint16_t a
, uint16_t b
)
12125 static inline uint16_t sub16_usat(uint16_t a
, uint16_t b
)
12134 static inline uint8_t add8_usat(uint8_t a
, uint8_t b
)
12144 static inline uint8_t sub8_usat(uint8_t a
, uint8_t b
)
12153 #define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
12154 #define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
12155 #define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
12156 #define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
12159 #include "op_addsub.h"
12161 /* Signed modulo arithmetic. */
12162 #define SARITH16(a, b, n, op) do { \
12164 sum = (int32_t)(int16_t)(a) op (int32_t)(int16_t)(b); \
12165 RESULT(sum, n, 16); \
12167 ge |= 3 << (n * 2); \
12170 #define SARITH8(a, b, n, op) do { \
12172 sum = (int32_t)(int8_t)(a) op (int32_t)(int8_t)(b); \
12173 RESULT(sum, n, 8); \
12179 #define ADD16(a, b, n) SARITH16(a, b, n, +)
12180 #define SUB16(a, b, n) SARITH16(a, b, n, -)
12181 #define ADD8(a, b, n) SARITH8(a, b, n, +)
12182 #define SUB8(a, b, n) SARITH8(a, b, n, -)
12186 #include "op_addsub.h"
12188 /* Unsigned modulo arithmetic. */
12189 #define ADD16(a, b, n) do { \
12191 sum = (uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b); \
12192 RESULT(sum, n, 16); \
12193 if ((sum >> 16) == 1) \
12194 ge |= 3 << (n * 2); \
12197 #define ADD8(a, b, n) do { \
12199 sum = (uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b); \
12200 RESULT(sum, n, 8); \
12201 if ((sum >> 8) == 1) \
12205 #define SUB16(a, b, n) do { \
12207 sum = (uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b); \
12208 RESULT(sum, n, 16); \
12209 if ((sum >> 16) == 0) \
12210 ge |= 3 << (n * 2); \
12213 #define SUB8(a, b, n) do { \
12215 sum = (uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b); \
12216 RESULT(sum, n, 8); \
12217 if ((sum >> 8) == 0) \
12224 #include "op_addsub.h"
12226 /* Halved signed arithmetic. */
12227 #define ADD16(a, b, n) \
12228 RESULT(((int32_t)(int16_t)(a) + (int32_t)(int16_t)(b)) >> 1, n, 16)
12229 #define SUB16(a, b, n) \
12230 RESULT(((int32_t)(int16_t)(a) - (int32_t)(int16_t)(b)) >> 1, n, 16)
12231 #define ADD8(a, b, n) \
12232 RESULT(((int32_t)(int8_t)(a) + (int32_t)(int8_t)(b)) >> 1, n, 8)
12233 #define SUB8(a, b, n) \
12234 RESULT(((int32_t)(int8_t)(a) - (int32_t)(int8_t)(b)) >> 1, n, 8)
12237 #include "op_addsub.h"
12239 /* Halved unsigned arithmetic. */
12240 #define ADD16(a, b, n) \
12241 RESULT(((uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b)) >> 1, n, 16)
12242 #define SUB16(a, b, n) \
12243 RESULT(((uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b)) >> 1, n, 16)
12244 #define ADD8(a, b, n) \
12245 RESULT(((uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b)) >> 1, n, 8)
12246 #define SUB8(a, b, n) \
12247 RESULT(((uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b)) >> 1, n, 8)
12250 #include "op_addsub.h"
12252 static inline uint8_t do_usad(uint8_t a
, uint8_t b
)
12261 /* Unsigned sum of absolute byte differences. */
12262 uint32_t HELPER(usad8
)(uint32_t a
, uint32_t b
)
12265 sum
= do_usad(a
, b
);
12266 sum
+= do_usad(a
>> 8, b
>> 8);
12267 sum
+= do_usad(a
>> 16, b
>> 16);
12268 sum
+= do_usad(a
>> 24, b
>> 24);
12272 /* For ARMv6 SEL instruction. */
12273 uint32_t HELPER(sel_flags
)(uint32_t flags
, uint32_t a
, uint32_t b
)
12288 mask
|= 0xff000000;
12290 return (a
& mask
) | (b
& ~mask
);
12295 * The upper bytes of val (above the number specified by 'bytes') must have
12296 * been zeroed out by the caller.
12298 uint32_t HELPER(crc32
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
12302 stl_le_p(buf
, val
);
12304 /* zlib crc32 converts the accumulator and output to one's complement. */
12305 return crc32(acc
^ 0xffffffff, buf
, bytes
) ^ 0xffffffff;
12308 uint32_t HELPER(crc32c
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
12312 stl_le_p(buf
, val
);
12314 /* Linux crc32c converts the output to one's complement. */
12315 return crc32c(acc
, buf
, bytes
) ^ 0xffffffff;
12319 * Return the exception level to which FP-disabled exceptions should
12320 * be taken, or 0 if FP is enabled.
12322 int fp_exception_el(CPUARMState
*env
, int cur_el
)
12324 #ifndef CONFIG_USER_ONLY
12328 * CPACR and the CPTR registers don't exist before v6, so FP is
12329 * always accessible
12331 if (!arm_feature(env
, ARM_FEATURE_V6
)) {
12335 if (arm_feature(env
, ARM_FEATURE_M
)) {
12336 /* CPACR can cause a NOCP UsageFault taken to current security state */
12337 if (!v7m_cpacr_pass(env
, env
->v7m
.secure
, cur_el
!= 0)) {
12341 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
) && !env
->v7m
.secure
) {
12342 if (!extract32(env
->v7m
.nsacr
, 10, 1)) {
12343 /* FP insns cause a NOCP UsageFault taken to Secure */
12351 hcr_el2
= arm_hcr_el2_eff(env
);
12354 * The CPACR controls traps to EL1, or PL1 if we're 32 bit:
12355 * 0, 2 : trap EL0 and EL1/PL1 accesses
12356 * 1 : trap only EL0 accesses
12357 * 3 : trap no accesses
12358 * This register is ignored if E2H+TGE are both set.
12360 if ((hcr_el2
& (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
12361 int fpen
= FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, FPEN
);
12371 /* Trap from Secure PL0 or PL1 to Secure PL1. */
12372 if (!arm_el_is_aa64(env
, 3)
12373 && (cur_el
== 3 || arm_is_secure_below_el3(env
))) {
12384 * The NSACR allows A-profile AArch32 EL3 and M-profile secure mode
12385 * to control non-secure access to the FPU. It doesn't have any
12386 * effect if EL3 is AArch64 or if EL3 doesn't exist at all.
12388 if ((arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
12389 cur_el
<= 2 && !arm_is_secure_below_el3(env
))) {
12390 if (!extract32(env
->cp15
.nsacr
, 10, 1)) {
12391 /* FP insns act as UNDEF */
12392 return cur_el
== 2 ? 2 : 1;
12397 * CPTR_EL2 is present in v7VE or v8, and changes format
12398 * with HCR_EL2.E2H (regardless of TGE).
12401 if (hcr_el2
& HCR_E2H
) {
12402 switch (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, FPEN
)) {
12404 if (cur_el
!= 0 || !(hcr_el2
& HCR_TGE
)) {
12412 } else if (arm_is_el2_enabled(env
)) {
12413 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TFP
)) {
12419 /* CPTR_EL3 : present in v8 */
12420 if (FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TFP
)) {
12421 /* Trap all FP ops to EL3 */
12428 /* Return the exception level we're running at if this is our mmu_idx */
12429 int arm_mmu_idx_to_el(ARMMMUIdx mmu_idx
)
12431 if (mmu_idx
& ARM_MMU_IDX_M
) {
12432 return mmu_idx
& ARM_MMU_IDX_M_PRIV
;
12436 case ARMMMUIdx_E10_0
:
12437 case ARMMMUIdx_E20_0
:
12439 case ARMMMUIdx_E10_1
:
12440 case ARMMMUIdx_E10_1_PAN
:
12443 case ARMMMUIdx_E20_2
:
12444 case ARMMMUIdx_E20_2_PAN
:
12449 g_assert_not_reached();
12454 ARMMMUIdx
arm_v7m_mmu_idx_for_secstate(CPUARMState
*env
, bool secstate
)
12456 g_assert_not_reached();
12460 ARMMMUIdx
arm_mmu_idx_el(CPUARMState
*env
, int el
)
12465 if (arm_feature(env
, ARM_FEATURE_M
)) {
12466 return arm_v7m_mmu_idx_for_secstate(env
, env
->v7m
.secure
);
12469 /* See ARM pseudo-function ELIsInHost. */
12472 hcr
= arm_hcr_el2_eff(env
);
12473 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
12474 idx
= ARMMMUIdx_E20_0
;
12476 idx
= ARMMMUIdx_E10_0
;
12480 if (arm_pan_enabled(env
)) {
12481 idx
= ARMMMUIdx_E10_1_PAN
;
12483 idx
= ARMMMUIdx_E10_1
;
12487 /* Note that TGE does not apply at EL2. */
12488 if (arm_hcr_el2_eff(env
) & HCR_E2H
) {
12489 if (arm_pan_enabled(env
)) {
12490 idx
= ARMMMUIdx_E20_2_PAN
;
12492 idx
= ARMMMUIdx_E20_2
;
12495 idx
= ARMMMUIdx_E2
;
12499 return ARMMMUIdx_E3
;
12501 g_assert_not_reached();
12507 ARMMMUIdx
arm_mmu_idx(CPUARMState
*env
)
12509 return arm_mmu_idx_el(env
, arm_current_el(env
));
12512 static bool mve_no_pred(CPUARMState
*env
)
12515 * Return true if there is definitely no predication of MVE
12516 * instructions by VPR or LTPSIZE. (Returning false even if there
12517 * isn't any predication is OK; generated code will just be
12519 * If the CPU does not implement MVE then this TB flag is always 0.
12521 * NOTE: if you change this logic, the "recalculate s->mve_no_pred"
12522 * logic in gen_update_fp_context() needs to be updated to match.
12524 * We do not include the effect of the ECI bits here -- they are
12525 * tracked in other TB flags. This simplifies the logic for
12526 * "when did we emit code that changes the MVE_NO_PRED TB flag
12527 * and thus need to end the TB?".
12529 if (cpu_isar_feature(aa32_mve
, env_archcpu(env
))) {
12532 if (env
->v7m
.vpr
) {
12535 if (env
->v7m
.ltpsize
< 4) {
12541 void cpu_get_tb_cpu_state(CPUARMState
*env
, vaddr
*pc
,
12542 uint64_t *cs_base
, uint32_t *pflags
)
12544 CPUARMTBFlags flags
;
12546 assert_hflags_rebuild_correctly(env
);
12547 flags
= env
->hflags
;
12549 if (EX_TBFLAG_ANY(flags
, AARCH64_STATE
)) {
12551 if (cpu_isar_feature(aa64_bti
, env_archcpu(env
))) {
12552 DP_TBFLAG_A64(flags
, BTYPE
, env
->btype
);
12555 *pc
= env
->regs
[15];
12557 if (arm_feature(env
, ARM_FEATURE_M
)) {
12558 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
) &&
12559 FIELD_EX32(env
->v7m
.fpccr
[M_REG_S
], V7M_FPCCR
, S
)
12560 != env
->v7m
.secure
) {
12561 DP_TBFLAG_M32(flags
, FPCCR_S_WRONG
, 1);
12564 if ((env
->v7m
.fpccr
[env
->v7m
.secure
] & R_V7M_FPCCR_ASPEN_MASK
) &&
12565 (!(env
->v7m
.control
[M_REG_S
] & R_V7M_CONTROL_FPCA_MASK
) ||
12566 (env
->v7m
.secure
&&
12567 !(env
->v7m
.control
[M_REG_S
] & R_V7M_CONTROL_SFPA_MASK
)))) {
12569 * ASPEN is set, but FPCA/SFPA indicate that there is no
12570 * active FP context; we must create a new FP context before
12571 * executing any FP insn.
12573 DP_TBFLAG_M32(flags
, NEW_FP_CTXT_NEEDED
, 1);
12576 bool is_secure
= env
->v7m
.fpccr
[M_REG_S
] & R_V7M_FPCCR_S_MASK
;
12577 if (env
->v7m
.fpccr
[is_secure
] & R_V7M_FPCCR_LSPACT_MASK
) {
12578 DP_TBFLAG_M32(flags
, LSPACT
, 1);
12581 if (mve_no_pred(env
)) {
12582 DP_TBFLAG_M32(flags
, MVE_NO_PRED
, 1);
12586 * Note that XSCALE_CPAR shares bits with VECSTRIDE.
12587 * Note that VECLEN+VECSTRIDE are RES0 for M-profile.
12589 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
12590 DP_TBFLAG_A32(flags
, XSCALE_CPAR
, env
->cp15
.c15_cpar
);
12592 DP_TBFLAG_A32(flags
, VECLEN
, env
->vfp
.vec_len
);
12593 DP_TBFLAG_A32(flags
, VECSTRIDE
, env
->vfp
.vec_stride
);
12595 if (env
->vfp
.xregs
[ARM_VFP_FPEXC
] & (1 << 30)) {
12596 DP_TBFLAG_A32(flags
, VFPEN
, 1);
12600 DP_TBFLAG_AM32(flags
, THUMB
, env
->thumb
);
12601 DP_TBFLAG_AM32(flags
, CONDEXEC
, env
->condexec_bits
);
12605 * The SS_ACTIVE and PSTATE_SS bits correspond to the state machine
12606 * states defined in the ARM ARM for software singlestep:
12607 * SS_ACTIVE PSTATE.SS State
12608 * 0 x Inactive (the TB flag for SS is always 0)
12609 * 1 0 Active-pending
12610 * 1 1 Active-not-pending
12611 * SS_ACTIVE is set in hflags; PSTATE__SS is computed every TB.
12613 if (EX_TBFLAG_ANY(flags
, SS_ACTIVE
) && (env
->pstate
& PSTATE_SS
)) {
12614 DP_TBFLAG_ANY(flags
, PSTATE__SS
, 1);
12617 *pflags
= flags
.flags
;
12618 *cs_base
= flags
.flags2
;
12621 #ifdef TARGET_AARCH64
12623 * The manual says that when SVE is enabled and VQ is widened the
12624 * implementation is allowed to zero the previously inaccessible
12625 * portion of the registers. The corollary to that is that when
12626 * SVE is enabled and VQ is narrowed we are also allowed to zero
12627 * the now inaccessible portion of the registers.
12629 * The intent of this is that no predicate bit beyond VQ is ever set.
12630 * Which means that some operations on predicate registers themselves
12631 * may operate on full uint64_t or even unrolled across the maximum
12632 * uint64_t[4]. Performing 4 bits of host arithmetic unconditionally
12633 * may well be cheaper than conditionals to restrict the operation
12634 * to the relevant portion of a uint16_t[16].
12636 void aarch64_sve_narrow_vq(CPUARMState
*env
, unsigned vq
)
12641 assert(vq
>= 1 && vq
<= ARM_MAX_VQ
);
12642 assert(vq
<= env_archcpu(env
)->sve_max_vq
);
12644 /* Zap the high bits of the zregs. */
12645 for (i
= 0; i
< 32; i
++) {
12646 memset(&env
->vfp
.zregs
[i
].d
[2 * vq
], 0, 16 * (ARM_MAX_VQ
- vq
));
12649 /* Zap the high bits of the pregs and ffr. */
12652 pmask
= ~(-1ULL << (16 * (vq
& 3)));
12654 for (j
= vq
/ 4; j
< ARM_MAX_VQ
/ 4; j
++) {
12655 for (i
= 0; i
< 17; ++i
) {
12656 env
->vfp
.pregs
[i
].p
[j
] &= pmask
;
12662 static uint32_t sve_vqm1_for_el_sm_ena(CPUARMState
*env
, int el
, bool sm
)
12667 exc_el
= sme_exception_el(env
, el
);
12669 exc_el
= sve_exception_el(env
, el
);
12672 return 0; /* disabled */
12674 return sve_vqm1_for_el_sm(env
, el
, sm
);
12678 * Notice a change in SVE vector size when changing EL.
12680 void aarch64_sve_change_el(CPUARMState
*env
, int old_el
,
12681 int new_el
, bool el0_a64
)
12683 ARMCPU
*cpu
= env_archcpu(env
);
12684 int old_len
, new_len
;
12685 bool old_a64
, new_a64
, sm
;
12687 /* Nothing to do if no SVE. */
12688 if (!cpu_isar_feature(aa64_sve
, cpu
)) {
12692 /* Nothing to do if FP is disabled in either EL. */
12693 if (fp_exception_el(env
, old_el
) || fp_exception_el(env
, new_el
)) {
12697 old_a64
= old_el
? arm_el_is_aa64(env
, old_el
) : el0_a64
;
12698 new_a64
= new_el
? arm_el_is_aa64(env
, new_el
) : el0_a64
;
12701 * Both AArch64.TakeException and AArch64.ExceptionReturn
12702 * invoke ResetSVEState when taking an exception from, or
12703 * returning to, AArch32 state when PSTATE.SM is enabled.
12705 sm
= FIELD_EX64(env
->svcr
, SVCR
, SM
);
12706 if (old_a64
!= new_a64
&& sm
) {
12707 arm_reset_sve_state(env
);
12712 * DDI0584A.d sec 3.2: "If SVE instructions are disabled or trapped
12713 * at ELx, or not available because the EL is in AArch32 state, then
12714 * for all purposes other than a direct read, the ZCR_ELx.LEN field
12715 * has an effective value of 0".
12717 * Consider EL2 (aa64, vq=4) -> EL0 (aa32) -> EL1 (aa64, vq=0).
12718 * If we ignore aa32 state, we would fail to see the vq4->vq0 transition
12719 * from EL2->EL1. Thus we go ahead and narrow when entering aa32 so that
12720 * we already have the correct register contents when encountering the
12721 * vq0->vq0 transition between EL0->EL1.
12723 old_len
= new_len
= 0;
12725 old_len
= sve_vqm1_for_el_sm_ena(env
, old_el
, sm
);
12728 new_len
= sve_vqm1_for_el_sm_ena(env
, new_el
, sm
);
12731 /* When changing vector length, clear inaccessible state. */
12732 if (new_len
< old_len
) {
12733 aarch64_sve_narrow_vq(env
, new_len
+ 1);
12738 #ifndef CONFIG_USER_ONLY
12739 ARMSecuritySpace
arm_security_space(CPUARMState
*env
)
12741 if (arm_feature(env
, ARM_FEATURE_M
)) {
12742 return arm_secure_to_space(env
->v7m
.secure
);
12746 * If EL3 is not supported then the secure state is implementation
12747 * defined, in which case QEMU defaults to non-secure.
12749 if (!arm_feature(env
, ARM_FEATURE_EL3
)) {
12750 return ARMSS_NonSecure
;
12753 /* Check for AArch64 EL3 or AArch32 Mon. */
12755 if (extract32(env
->pstate
, 2, 2) == 3) {
12756 if (cpu_isar_feature(aa64_rme
, env_archcpu(env
))) {
12759 return ARMSS_Secure
;
12763 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
) {
12764 return ARMSS_Secure
;
12768 return arm_security_space_below_el3(env
);
12771 ARMSecuritySpace
arm_security_space_below_el3(CPUARMState
*env
)
12773 assert(!arm_feature(env
, ARM_FEATURE_M
));
12776 * If EL3 is not supported then the secure state is implementation
12777 * defined, in which case QEMU defaults to non-secure.
12779 if (!arm_feature(env
, ARM_FEATURE_EL3
)) {
12780 return ARMSS_NonSecure
;
12784 * Note NSE cannot be set without RME, and NSE & !NS is Reserved.
12785 * Ignoring NSE when !NS retains consistency without having to
12786 * modify other predicates.
12788 if (!(env
->cp15
.scr_el3
& SCR_NS
)) {
12789 return ARMSS_Secure
;
12790 } else if (env
->cp15
.scr_el3
& SCR_NSE
) {
12791 return ARMSS_Realm
;
12793 return ARMSS_NonSecure
;
12796 #endif /* !CONFIG_USER_ONLY */