4 * This code is licensed under the GNU GPL v2 or later.
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "qemu/osdep.h"
10 #include "qemu/units.h"
14 #include "internals.h"
15 #include "exec/helper-proto.h"
16 #include "qemu/host-utils.h"
17 #include "qemu/main-loop.h"
18 #include "qemu/timer.h"
19 #include "qemu/bitops.h"
20 #include "qemu/crc32c.h"
21 #include "qemu/qemu-print.h"
22 #include "exec/exec-all.h"
23 #include <zlib.h> /* For crc32 */
25 #include "semihosting/semihost.h"
26 #include "sysemu/cpus.h"
27 #include "sysemu/cpu-timers.h"
28 #include "sysemu/kvm.h"
29 #include "qemu/range.h"
30 #include "qapi/qapi-commands-machine-target.h"
31 #include "qapi/error.h"
32 #include "qemu/guest-random.h"
35 #include "exec/cpu_ldst.h"
36 #include "semihosting/common-semi.h"
40 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */
42 static void switch_mode(CPUARMState
*env
, int mode
);
44 static uint64_t raw_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
46 assert(ri
->fieldoffset
);
47 if (cpreg_field_is_64bit(ri
)) {
48 return CPREG_FIELD64(env
, ri
);
50 return CPREG_FIELD32(env
, ri
);
54 void raw_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
56 assert(ri
->fieldoffset
);
57 if (cpreg_field_is_64bit(ri
)) {
58 CPREG_FIELD64(env
, ri
) = value
;
60 CPREG_FIELD32(env
, ri
) = value
;
64 static void *raw_ptr(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
66 return (char *)env
+ ri
->fieldoffset
;
69 uint64_t read_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
71 /* Raw read of a coprocessor register (as needed for migration, etc). */
72 if (ri
->type
& ARM_CP_CONST
) {
73 return ri
->resetvalue
;
74 } else if (ri
->raw_readfn
) {
75 return ri
->raw_readfn(env
, ri
);
76 } else if (ri
->readfn
) {
77 return ri
->readfn(env
, ri
);
79 return raw_read(env
, ri
);
83 static void write_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
86 /* Raw write of a coprocessor register (as needed for migration, etc).
87 * Note that constant registers are treated as write-ignored; the
88 * caller should check for success by whether a readback gives the
91 if (ri
->type
& ARM_CP_CONST
) {
93 } else if (ri
->raw_writefn
) {
94 ri
->raw_writefn(env
, ri
, v
);
95 } else if (ri
->writefn
) {
96 ri
->writefn(env
, ri
, v
);
98 raw_write(env
, ri
, v
);
102 static bool raw_accessors_invalid(const ARMCPRegInfo
*ri
)
104 /* Return true if the regdef would cause an assertion if you called
105 * read_raw_cp_reg() or write_raw_cp_reg() on it (ie if it is a
106 * program bug for it not to have the NO_RAW flag).
107 * NB that returning false here doesn't necessarily mean that calling
108 * read/write_raw_cp_reg() is safe, because we can't distinguish "has
109 * read/write access functions which are safe for raw use" from "has
110 * read/write access functions which have side effects but has forgotten
111 * to provide raw access functions".
112 * The tests here line up with the conditions in read/write_raw_cp_reg()
113 * and assertions in raw_read()/raw_write().
115 if ((ri
->type
& ARM_CP_CONST
) ||
117 ((ri
->raw_writefn
|| ri
->writefn
) && (ri
->raw_readfn
|| ri
->readfn
))) {
123 bool write_cpustate_to_list(ARMCPU
*cpu
, bool kvm_sync
)
125 /* Write the coprocessor state from cpu->env to the (index,value) list. */
129 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
130 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
131 const ARMCPRegInfo
*ri
;
134 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
139 if (ri
->type
& ARM_CP_NO_RAW
) {
143 newval
= read_raw_cp_reg(&cpu
->env
, ri
);
146 * Only sync if the previous list->cpustate sync succeeded.
147 * Rather than tracking the success/failure state for every
148 * item in the list, we just recheck "does the raw write we must
149 * have made in write_list_to_cpustate() read back OK" here.
151 uint64_t oldval
= cpu
->cpreg_values
[i
];
153 if (oldval
== newval
) {
157 write_raw_cp_reg(&cpu
->env
, ri
, oldval
);
158 if (read_raw_cp_reg(&cpu
->env
, ri
) != oldval
) {
162 write_raw_cp_reg(&cpu
->env
, ri
, newval
);
164 cpu
->cpreg_values
[i
] = newval
;
169 bool write_list_to_cpustate(ARMCPU
*cpu
)
174 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
175 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
176 uint64_t v
= cpu
->cpreg_values
[i
];
177 const ARMCPRegInfo
*ri
;
179 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
184 if (ri
->type
& ARM_CP_NO_RAW
) {
187 /* Write value and confirm it reads back as written
188 * (to catch read-only registers and partially read-only
189 * registers where the incoming migration value doesn't match)
191 write_raw_cp_reg(&cpu
->env
, ri
, v
);
192 if (read_raw_cp_reg(&cpu
->env
, ri
) != v
) {
199 static void add_cpreg_to_list(gpointer key
, gpointer opaque
)
201 ARMCPU
*cpu
= opaque
;
202 uint32_t regidx
= (uintptr_t)key
;
203 const ARMCPRegInfo
*ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
205 if (!(ri
->type
& (ARM_CP_NO_RAW
|ARM_CP_ALIAS
))) {
206 cpu
->cpreg_indexes
[cpu
->cpreg_array_len
] = cpreg_to_kvm_id(regidx
);
207 /* The value array need not be initialized at this point */
208 cpu
->cpreg_array_len
++;
212 static void count_cpreg(gpointer key
, gpointer opaque
)
214 ARMCPU
*cpu
= opaque
;
215 const ARMCPRegInfo
*ri
;
217 ri
= g_hash_table_lookup(cpu
->cp_regs
, key
);
219 if (!(ri
->type
& (ARM_CP_NO_RAW
|ARM_CP_ALIAS
))) {
220 cpu
->cpreg_array_len
++;
224 static gint
cpreg_key_compare(gconstpointer a
, gconstpointer b
)
226 uint64_t aidx
= cpreg_to_kvm_id((uintptr_t)a
);
227 uint64_t bidx
= cpreg_to_kvm_id((uintptr_t)b
);
238 void init_cpreg_list(ARMCPU
*cpu
)
240 /* Initialise the cpreg_tuples[] array based on the cp_regs hash.
241 * Note that we require cpreg_tuples[] to be sorted by key ID.
246 keys
= g_hash_table_get_keys(cpu
->cp_regs
);
247 keys
= g_list_sort(keys
, cpreg_key_compare
);
249 cpu
->cpreg_array_len
= 0;
251 g_list_foreach(keys
, count_cpreg
, cpu
);
253 arraylen
= cpu
->cpreg_array_len
;
254 cpu
->cpreg_indexes
= g_new(uint64_t, arraylen
);
255 cpu
->cpreg_values
= g_new(uint64_t, arraylen
);
256 cpu
->cpreg_vmstate_indexes
= g_new(uint64_t, arraylen
);
257 cpu
->cpreg_vmstate_values
= g_new(uint64_t, arraylen
);
258 cpu
->cpreg_vmstate_array_len
= cpu
->cpreg_array_len
;
259 cpu
->cpreg_array_len
= 0;
261 g_list_foreach(keys
, add_cpreg_to_list
, cpu
);
263 assert(cpu
->cpreg_array_len
== arraylen
);
269 * Some registers are not accessible from AArch32 EL3 if SCR.NS == 0.
271 static CPAccessResult
access_el3_aa32ns(CPUARMState
*env
,
272 const ARMCPRegInfo
*ri
,
275 if (!is_a64(env
) && arm_current_el(env
) == 3 &&
276 arm_is_secure_below_el3(env
)) {
277 return CP_ACCESS_TRAP_UNCATEGORIZED
;
282 /* Some secure-only AArch32 registers trap to EL3 if used from
283 * Secure EL1 (but are just ordinary UNDEF in other non-EL3 contexts).
284 * Note that an access from Secure EL1 can only happen if EL3 is AArch64.
285 * We assume that the .access field is set to PL1_RW.
287 static CPAccessResult
access_trap_aa32s_el1(CPUARMState
*env
,
288 const ARMCPRegInfo
*ri
,
291 if (arm_current_el(env
) == 3) {
294 if (arm_is_secure_below_el3(env
)) {
295 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
296 return CP_ACCESS_TRAP_EL2
;
298 return CP_ACCESS_TRAP_EL3
;
300 /* This will be EL1 NS and EL2 NS, which just UNDEF */
301 return CP_ACCESS_TRAP_UNCATEGORIZED
;
304 /* Check for traps to performance monitor registers, which are controlled
305 * by MDCR_EL2.TPM for EL2 and MDCR_EL3.TPM for EL3.
307 static CPAccessResult
access_tpm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
310 int el
= arm_current_el(env
);
311 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
313 if (el
< 2 && (mdcr_el2
& MDCR_TPM
)) {
314 return CP_ACCESS_TRAP_EL2
;
316 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
317 return CP_ACCESS_TRAP_EL3
;
322 /* Check for traps from EL1 due to HCR_EL2.TVM and HCR_EL2.TRVM. */
323 static CPAccessResult
access_tvm_trvm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
326 if (arm_current_el(env
) == 1) {
327 uint64_t trap
= isread
? HCR_TRVM
: HCR_TVM
;
328 if (arm_hcr_el2_eff(env
) & trap
) {
329 return CP_ACCESS_TRAP_EL2
;
335 /* Check for traps from EL1 due to HCR_EL2.TSW. */
336 static CPAccessResult
access_tsw(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
339 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TSW
)) {
340 return CP_ACCESS_TRAP_EL2
;
345 /* Check for traps from EL1 due to HCR_EL2.TACR. */
346 static CPAccessResult
access_tacr(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
349 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TACR
)) {
350 return CP_ACCESS_TRAP_EL2
;
355 /* Check for traps from EL1 due to HCR_EL2.TTLB. */
356 static CPAccessResult
access_ttlb(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
359 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TTLB
)) {
360 return CP_ACCESS_TRAP_EL2
;
365 static void dacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
367 ARMCPU
*cpu
= env_archcpu(env
);
369 raw_write(env
, ri
, value
);
370 tlb_flush(CPU(cpu
)); /* Flush TLB as domain not tracked in TLB */
373 static void fcse_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
375 ARMCPU
*cpu
= env_archcpu(env
);
377 if (raw_read(env
, ri
) != value
) {
378 /* Unlike real hardware the qemu TLB uses virtual addresses,
379 * not modified virtual addresses, so this causes a TLB flush.
382 raw_write(env
, ri
, value
);
386 static void contextidr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
389 ARMCPU
*cpu
= env_archcpu(env
);
391 if (raw_read(env
, ri
) != value
&& !arm_feature(env
, ARM_FEATURE_PMSA
)
392 && !extended_addresses_enabled(env
)) {
393 /* For VMSA (when not using the LPAE long descriptor page table
394 * format) this register includes the ASID, so do a TLB flush.
395 * For PMSA it is purely a process ID and no action is needed.
399 raw_write(env
, ri
, value
);
402 /* IS variants of TLB operations must affect all cores */
403 static void tlbiall_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
406 CPUState
*cs
= env_cpu(env
);
408 tlb_flush_all_cpus_synced(cs
);
411 static void tlbiasid_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
414 CPUState
*cs
= env_cpu(env
);
416 tlb_flush_all_cpus_synced(cs
);
419 static void tlbimva_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
422 CPUState
*cs
= env_cpu(env
);
424 tlb_flush_page_all_cpus_synced(cs
, value
& TARGET_PAGE_MASK
);
427 static void tlbimvaa_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
430 CPUState
*cs
= env_cpu(env
);
432 tlb_flush_page_all_cpus_synced(cs
, value
& TARGET_PAGE_MASK
);
436 * Non-IS variants of TLB operations are upgraded to
437 * IS versions if we are at EL1 and HCR_EL2.FB is effectively set to
438 * force broadcast of these operations.
440 static bool tlb_force_broadcast(CPUARMState
*env
)
442 return arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_FB
);
445 static void tlbiall_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
448 /* Invalidate all (TLBIALL) */
449 CPUState
*cs
= env_cpu(env
);
451 if (tlb_force_broadcast(env
)) {
452 tlb_flush_all_cpus_synced(cs
);
458 static void tlbimva_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
461 /* Invalidate single TLB entry by MVA and ASID (TLBIMVA) */
462 CPUState
*cs
= env_cpu(env
);
464 value
&= TARGET_PAGE_MASK
;
465 if (tlb_force_broadcast(env
)) {
466 tlb_flush_page_all_cpus_synced(cs
, value
);
468 tlb_flush_page(cs
, value
);
472 static void tlbiasid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
475 /* Invalidate by ASID (TLBIASID) */
476 CPUState
*cs
= env_cpu(env
);
478 if (tlb_force_broadcast(env
)) {
479 tlb_flush_all_cpus_synced(cs
);
485 static void tlbimvaa_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
488 /* Invalidate single entry by MVA, all ASIDs (TLBIMVAA) */
489 CPUState
*cs
= env_cpu(env
);
491 value
&= TARGET_PAGE_MASK
;
492 if (tlb_force_broadcast(env
)) {
493 tlb_flush_page_all_cpus_synced(cs
, value
);
495 tlb_flush_page(cs
, value
);
499 static void tlbiall_nsnh_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
502 CPUState
*cs
= env_cpu(env
);
504 tlb_flush_by_mmuidx(cs
,
506 ARMMMUIdxBit_E10_1_PAN
|
510 static void tlbiall_nsnh_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
513 CPUState
*cs
= env_cpu(env
);
515 tlb_flush_by_mmuidx_all_cpus_synced(cs
,
517 ARMMMUIdxBit_E10_1_PAN
|
522 static void tlbiall_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
525 CPUState
*cs
= env_cpu(env
);
527 tlb_flush_by_mmuidx(cs
, ARMMMUIdxBit_E2
);
530 static void tlbiall_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
533 CPUState
*cs
= env_cpu(env
);
535 tlb_flush_by_mmuidx_all_cpus_synced(cs
, ARMMMUIdxBit_E2
);
538 static void tlbimva_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
541 CPUState
*cs
= env_cpu(env
);
542 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
544 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_E2
);
547 static void tlbimva_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
550 CPUState
*cs
= env_cpu(env
);
551 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
553 tlb_flush_page_by_mmuidx_all_cpus_synced(cs
, pageaddr
,
557 static const ARMCPRegInfo cp_reginfo
[] = {
558 /* Define the secure and non-secure FCSE identifier CP registers
559 * separately because there is no secure bank in V8 (no _EL3). This allows
560 * the secure register to be properly reset and migrated. There is also no
561 * v8 EL1 version of the register so the non-secure instance stands alone.
564 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
565 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_NS
,
566 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_ns
),
567 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
568 { .name
= "FCSEIDR_S",
569 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
570 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_S
,
571 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_s
),
572 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
573 /* Define the secure and non-secure context identifier CP registers
574 * separately because there is no secure bank in V8 (no _EL3). This allows
575 * the secure register to be properly reset and migrated. In the
576 * non-secure case, the 32-bit register will have reset and migration
577 * disabled during registration as it is handled by the 64-bit instance.
579 { .name
= "CONTEXTIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
580 .opc0
= 3, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
581 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
582 .secure
= ARM_CP_SECSTATE_NS
,
583 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[1]),
584 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
585 { .name
= "CONTEXTIDR_S", .state
= ARM_CP_STATE_AA32
,
586 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
587 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
588 .secure
= ARM_CP_SECSTATE_S
,
589 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_s
),
590 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
593 static const ARMCPRegInfo not_v8_cp_reginfo
[] = {
594 /* NB: Some of these registers exist in v8 but with more precise
595 * definitions that don't use CP_ANY wildcards (mostly in v8_cp_reginfo[]).
597 /* MMU Domain access control / MPU write buffer control */
599 .cp
= 15, .opc1
= CP_ANY
, .crn
= 3, .crm
= CP_ANY
, .opc2
= CP_ANY
,
600 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
601 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
602 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
603 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
604 /* ARMv7 allocates a range of implementation defined TLB LOCKDOWN regs.
605 * For v6 and v5, these mappings are overly broad.
607 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 0,
608 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
609 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 1,
610 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
611 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 4,
612 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
613 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 8,
614 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
615 /* Cache maintenance ops; some of this space may be overridden later. */
616 { .name
= "CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
617 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
618 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
},
621 static const ARMCPRegInfo not_v6_cp_reginfo
[] = {
622 /* Not all pre-v6 cores implemented this WFI, so this is slightly
625 { .name
= "WFI_v5", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= 2,
626 .access
= PL1_W
, .type
= ARM_CP_WFI
},
629 static const ARMCPRegInfo not_v7_cp_reginfo
[] = {
630 /* Standard v6 WFI (also used in some pre-v6 cores); not in v7 (which
631 * is UNPREDICTABLE; we choose to NOP as most implementations do).
633 { .name
= "WFI_v6", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
634 .access
= PL1_W
, .type
= ARM_CP_WFI
},
635 /* L1 cache lockdown. Not architectural in v6 and earlier but in practice
636 * implemented in 926, 946, 1026, 1136, 1176 and 11MPCore. StrongARM and
637 * OMAPCP will override this space.
639 { .name
= "DLOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 0,
640 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_data
),
642 { .name
= "ILOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 1,
643 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_insn
),
645 /* v6 doesn't have the cache ID registers but Linux reads them anyway */
646 { .name
= "DUMMY", .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= CP_ANY
,
647 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
649 /* We don't implement pre-v7 debug but most CPUs had at least a DBGDIDR;
650 * implementing it as RAZ means the "debug architecture version" bits
651 * will read as a reserved value, which should cause Linux to not try
652 * to use the debug hardware.
654 { .name
= "DBGDIDR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 0,
655 .access
= PL0_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
656 /* MMU TLB control. Note that the wildcarding means we cover not just
657 * the unified TLB ops but also the dside/iside/inner-shareable variants.
659 { .name
= "TLBIALL", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
660 .opc1
= CP_ANY
, .opc2
= 0, .access
= PL1_W
, .writefn
= tlbiall_write
,
661 .type
= ARM_CP_NO_RAW
},
662 { .name
= "TLBIMVA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
663 .opc1
= CP_ANY
, .opc2
= 1, .access
= PL1_W
, .writefn
= tlbimva_write
,
664 .type
= ARM_CP_NO_RAW
},
665 { .name
= "TLBIASID", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
666 .opc1
= CP_ANY
, .opc2
= 2, .access
= PL1_W
, .writefn
= tlbiasid_write
,
667 .type
= ARM_CP_NO_RAW
},
668 { .name
= "TLBIMVAA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
669 .opc1
= CP_ANY
, .opc2
= 3, .access
= PL1_W
, .writefn
= tlbimvaa_write
,
670 .type
= ARM_CP_NO_RAW
},
671 { .name
= "PRRR", .cp
= 15, .crn
= 10, .crm
= 2,
672 .opc1
= 0, .opc2
= 0, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
673 { .name
= "NMRR", .cp
= 15, .crn
= 10, .crm
= 2,
674 .opc1
= 0, .opc2
= 1, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
677 static void cpacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
682 /* In ARMv8 most bits of CPACR_EL1 are RES0. */
683 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
684 /* ARMv7 defines bits for unimplemented coprocessors as RAZ/WI.
685 * ASEDIS [31] and D32DIS [30] are both UNK/SBZP without VFP.
686 * TRCDIS [28] is RAZ/WI since we do not implement a trace macrocell.
688 if (cpu_isar_feature(aa32_vfp_simd
, env_archcpu(env
))) {
689 /* VFP coprocessor: cp10 & cp11 [23:20] */
690 mask
|= R_CPACR_ASEDIS_MASK
|
691 R_CPACR_D32DIS_MASK
|
695 if (!arm_feature(env
, ARM_FEATURE_NEON
)) {
696 /* ASEDIS [31] bit is RAO/WI */
697 value
|= R_CPACR_ASEDIS_MASK
;
700 /* VFPv3 and upwards with NEON implement 32 double precision
701 * registers (D0-D31).
703 if (!cpu_isar_feature(aa32_simd_r32
, env_archcpu(env
))) {
704 /* D32DIS [30] is RAO/WI if D16-31 are not implemented. */
705 value
|= R_CPACR_D32DIS_MASK
;
712 * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10
713 * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00.
715 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
716 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
717 mask
= R_CPACR_CP11_MASK
| R_CPACR_CP10_MASK
;
718 value
= (value
& ~mask
) | (env
->cp15
.cpacr_el1
& mask
);
721 env
->cp15
.cpacr_el1
= value
;
724 static uint64_t cpacr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
727 * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10
728 * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00.
730 uint64_t value
= env
->cp15
.cpacr_el1
;
732 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
733 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
734 value
= ~(R_CPACR_CP11_MASK
| R_CPACR_CP10_MASK
);
740 static void cpacr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
742 /* Call cpacr_write() so that we reset with the correct RAO bits set
743 * for our CPU features.
745 cpacr_write(env
, ri
, 0);
748 static CPAccessResult
cpacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
751 if (arm_feature(env
, ARM_FEATURE_V8
)) {
752 /* Check if CPACR accesses are to be trapped to EL2 */
753 if (arm_current_el(env
) == 1 && arm_is_el2_enabled(env
) &&
754 FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TCPAC
)) {
755 return CP_ACCESS_TRAP_EL2
;
756 /* Check if CPACR accesses are to be trapped to EL3 */
757 } else if (arm_current_el(env
) < 3 &&
758 FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TCPAC
)) {
759 return CP_ACCESS_TRAP_EL3
;
766 static CPAccessResult
cptr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
769 /* Check if CPTR accesses are set to trap to EL3 */
770 if (arm_current_el(env
) == 2 &&
771 FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TCPAC
)) {
772 return CP_ACCESS_TRAP_EL3
;
778 static const ARMCPRegInfo v6_cp_reginfo
[] = {
779 /* prefetch by MVA in v6, NOP in v7 */
780 { .name
= "MVA_prefetch",
781 .cp
= 15, .crn
= 7, .crm
= 13, .opc1
= 0, .opc2
= 1,
782 .access
= PL1_W
, .type
= ARM_CP_NOP
},
783 /* We need to break the TB after ISB to execute self-modifying code
784 * correctly and also to take any pending interrupts immediately.
785 * So use arm_cp_write_ignore() function instead of ARM_CP_NOP flag.
787 { .name
= "ISB", .cp
= 15, .crn
= 7, .crm
= 5, .opc1
= 0, .opc2
= 4,
788 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
, .writefn
= arm_cp_write_ignore
},
789 { .name
= "DSB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 4,
790 .access
= PL0_W
, .type
= ARM_CP_NOP
},
791 { .name
= "DMB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 5,
792 .access
= PL0_W
, .type
= ARM_CP_NOP
},
793 { .name
= "IFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 2,
794 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
795 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ifar_s
),
796 offsetof(CPUARMState
, cp15
.ifar_ns
) },
798 /* Watchpoint Fault Address Register : should actually only be present
799 * for 1136, 1176, 11MPCore.
801 { .name
= "WFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 1,
802 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0, },
803 { .name
= "CPACR", .state
= ARM_CP_STATE_BOTH
, .opc0
= 3,
804 .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 2, .accessfn
= cpacr_access
,
805 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.cpacr_el1
),
806 .resetfn
= cpacr_reset
, .writefn
= cpacr_write
, .readfn
= cpacr_read
},
809 typedef struct pm_event
{
810 uint16_t number
; /* PMEVTYPER.evtCount is 16 bits wide */
811 /* If the event is supported on this CPU (used to generate PMCEID[01]) */
812 bool (*supported
)(CPUARMState
*);
814 * Retrieve the current count of the underlying event. The programmed
815 * counters hold a difference from the return value from this function
817 uint64_t (*get_count
)(CPUARMState
*);
819 * Return how many nanoseconds it will take (at a minimum) for count events
820 * to occur. A negative value indicates the counter will never overflow, or
821 * that the counter has otherwise arranged for the overflow bit to be set
822 * and the PMU interrupt to be raised on overflow.
824 int64_t (*ns_per_count
)(uint64_t);
827 static bool event_always_supported(CPUARMState
*env
)
832 static uint64_t swinc_get_count(CPUARMState
*env
)
835 * SW_INCR events are written directly to the pmevcntr's by writes to
836 * PMSWINC, so there is no underlying count maintained by the PMU itself
841 static int64_t swinc_ns_per(uint64_t ignored
)
847 * Return the underlying cycle count for the PMU cycle counters. If we're in
848 * usermode, simply return 0.
850 static uint64_t cycles_get_count(CPUARMState
*env
)
852 #ifndef CONFIG_USER_ONLY
853 return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
854 ARM_CPU_FREQ
, NANOSECONDS_PER_SECOND
);
856 return cpu_get_host_ticks();
860 #ifndef CONFIG_USER_ONLY
861 static int64_t cycles_ns_per(uint64_t cycles
)
863 return (ARM_CPU_FREQ
/ NANOSECONDS_PER_SECOND
) * cycles
;
866 static bool instructions_supported(CPUARMState
*env
)
868 return icount_enabled() == 1; /* Precise instruction counting */
871 static uint64_t instructions_get_count(CPUARMState
*env
)
873 return (uint64_t)icount_get_raw();
876 static int64_t instructions_ns_per(uint64_t icount
)
878 return icount_to_ns((int64_t)icount
);
882 static bool pmuv3p1_events_supported(CPUARMState
*env
)
884 /* For events which are supported in any v8.1 PMU */
885 return cpu_isar_feature(any_pmuv3p1
, env_archcpu(env
));
888 static bool pmuv3p4_events_supported(CPUARMState
*env
)
890 /* For events which are supported in any v8.1 PMU */
891 return cpu_isar_feature(any_pmuv3p4
, env_archcpu(env
));
894 static uint64_t zero_event_get_count(CPUARMState
*env
)
896 /* For events which on QEMU never fire, so their count is always zero */
900 static int64_t zero_event_ns_per(uint64_t cycles
)
902 /* An event which never fires can never overflow */
906 static const pm_event pm_events
[] = {
907 { .number
= 0x000, /* SW_INCR */
908 .supported
= event_always_supported
,
909 .get_count
= swinc_get_count
,
910 .ns_per_count
= swinc_ns_per
,
912 #ifndef CONFIG_USER_ONLY
913 { .number
= 0x008, /* INST_RETIRED, Instruction architecturally executed */
914 .supported
= instructions_supported
,
915 .get_count
= instructions_get_count
,
916 .ns_per_count
= instructions_ns_per
,
918 { .number
= 0x011, /* CPU_CYCLES, Cycle */
919 .supported
= event_always_supported
,
920 .get_count
= cycles_get_count
,
921 .ns_per_count
= cycles_ns_per
,
924 { .number
= 0x023, /* STALL_FRONTEND */
925 .supported
= pmuv3p1_events_supported
,
926 .get_count
= zero_event_get_count
,
927 .ns_per_count
= zero_event_ns_per
,
929 { .number
= 0x024, /* STALL_BACKEND */
930 .supported
= pmuv3p1_events_supported
,
931 .get_count
= zero_event_get_count
,
932 .ns_per_count
= zero_event_ns_per
,
934 { .number
= 0x03c, /* STALL */
935 .supported
= pmuv3p4_events_supported
,
936 .get_count
= zero_event_get_count
,
937 .ns_per_count
= zero_event_ns_per
,
942 * Note: Before increasing MAX_EVENT_ID beyond 0x3f into the 0x40xx range of
943 * events (i.e. the statistical profiling extension), this implementation
944 * should first be updated to something sparse instead of the current
945 * supported_event_map[] array.
947 #define MAX_EVENT_ID 0x3c
948 #define UNSUPPORTED_EVENT UINT16_MAX
949 static uint16_t supported_event_map
[MAX_EVENT_ID
+ 1];
952 * Called upon CPU initialization to initialize PMCEID[01]_EL0 and build a map
953 * of ARM event numbers to indices in our pm_events array.
955 * Note: Events in the 0x40XX range are not currently supported.
957 void pmu_init(ARMCPU
*cpu
)
962 * Empty supported_event_map and cpu->pmceid[01] before adding supported
965 for (i
= 0; i
< ARRAY_SIZE(supported_event_map
); i
++) {
966 supported_event_map
[i
] = UNSUPPORTED_EVENT
;
971 for (i
= 0; i
< ARRAY_SIZE(pm_events
); i
++) {
972 const pm_event
*cnt
= &pm_events
[i
];
973 assert(cnt
->number
<= MAX_EVENT_ID
);
974 /* We do not currently support events in the 0x40xx range */
975 assert(cnt
->number
<= 0x3f);
977 if (cnt
->supported(&cpu
->env
)) {
978 supported_event_map
[cnt
->number
] = i
;
979 uint64_t event_mask
= 1ULL << (cnt
->number
& 0x1f);
980 if (cnt
->number
& 0x20) {
981 cpu
->pmceid1
|= event_mask
;
983 cpu
->pmceid0
|= event_mask
;
990 * Check at runtime whether a PMU event is supported for the current machine
992 static bool event_supported(uint16_t number
)
994 if (number
> MAX_EVENT_ID
) {
997 return supported_event_map
[number
] != UNSUPPORTED_EVENT
;
1000 static CPAccessResult
pmreg_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1003 /* Performance monitor registers user accessibility is controlled
1004 * by PMUSERENR. MDCR_EL2.TPM and MDCR_EL3.TPM allow configurable
1005 * trapping to EL2 or EL3 for other accesses.
1007 int el
= arm_current_el(env
);
1008 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
1010 if (el
== 0 && !(env
->cp15
.c9_pmuserenr
& 1)) {
1011 return CP_ACCESS_TRAP
;
1013 if (el
< 2 && (mdcr_el2
& MDCR_TPM
)) {
1014 return CP_ACCESS_TRAP_EL2
;
1016 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
1017 return CP_ACCESS_TRAP_EL3
;
1020 return CP_ACCESS_OK
;
1023 static CPAccessResult
pmreg_access_xevcntr(CPUARMState
*env
,
1024 const ARMCPRegInfo
*ri
,
1027 /* ER: event counter read trap control */
1028 if (arm_feature(env
, ARM_FEATURE_V8
)
1029 && arm_current_el(env
) == 0
1030 && (env
->cp15
.c9_pmuserenr
& (1 << 3)) != 0
1032 return CP_ACCESS_OK
;
1035 return pmreg_access(env
, ri
, isread
);
1038 static CPAccessResult
pmreg_access_swinc(CPUARMState
*env
,
1039 const ARMCPRegInfo
*ri
,
1042 /* SW: software increment write trap control */
1043 if (arm_feature(env
, ARM_FEATURE_V8
)
1044 && arm_current_el(env
) == 0
1045 && (env
->cp15
.c9_pmuserenr
& (1 << 1)) != 0
1047 return CP_ACCESS_OK
;
1050 return pmreg_access(env
, ri
, isread
);
1053 static CPAccessResult
pmreg_access_selr(CPUARMState
*env
,
1054 const ARMCPRegInfo
*ri
,
1057 /* ER: event counter read trap control */
1058 if (arm_feature(env
, ARM_FEATURE_V8
)
1059 && arm_current_el(env
) == 0
1060 && (env
->cp15
.c9_pmuserenr
& (1 << 3)) != 0) {
1061 return CP_ACCESS_OK
;
1064 return pmreg_access(env
, ri
, isread
);
1067 static CPAccessResult
pmreg_access_ccntr(CPUARMState
*env
,
1068 const ARMCPRegInfo
*ri
,
1071 /* CR: cycle counter read trap control */
1072 if (arm_feature(env
, ARM_FEATURE_V8
)
1073 && arm_current_el(env
) == 0
1074 && (env
->cp15
.c9_pmuserenr
& (1 << 2)) != 0
1076 return CP_ACCESS_OK
;
1079 return pmreg_access(env
, ri
, isread
);
1083 * Bits in MDCR_EL2 and MDCR_EL3 which pmu_counter_enabled() looks at.
1084 * We use these to decide whether we need to wrap a write to MDCR_EL2
1085 * or MDCR_EL3 in pmu_op_start()/pmu_op_finish() calls.
1087 #define MDCR_EL2_PMU_ENABLE_BITS \
1088 (MDCR_HPME | MDCR_HPMD | MDCR_HPMN | MDCR_HCCD | MDCR_HLP)
1089 #define MDCR_EL3_PMU_ENABLE_BITS (MDCR_SPME | MDCR_SCCD)
1091 /* Returns true if the counter (pass 31 for PMCCNTR) should count events using
1092 * the current EL, security state, and register configuration.
1094 static bool pmu_counter_enabled(CPUARMState
*env
, uint8_t counter
)
1097 bool e
, p
, u
, nsk
, nsu
, nsh
, m
;
1098 bool enabled
, prohibited
= false, filtered
;
1099 bool secure
= arm_is_secure(env
);
1100 int el
= arm_current_el(env
);
1101 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
1102 uint8_t hpmn
= mdcr_el2
& MDCR_HPMN
;
1104 if (!arm_feature(env
, ARM_FEATURE_PMU
)) {
1108 if (!arm_feature(env
, ARM_FEATURE_EL2
) ||
1109 (counter
< hpmn
|| counter
== 31)) {
1110 e
= env
->cp15
.c9_pmcr
& PMCRE
;
1112 e
= mdcr_el2
& MDCR_HPME
;
1114 enabled
= e
&& (env
->cp15
.c9_pmcnten
& (1 << counter
));
1116 /* Is event counting prohibited? */
1117 if (el
== 2 && (counter
< hpmn
|| counter
== 31)) {
1118 prohibited
= mdcr_el2
& MDCR_HPMD
;
1121 prohibited
= prohibited
|| !(env
->cp15
.mdcr_el3
& MDCR_SPME
);
1124 if (counter
== 31) {
1126 * The cycle counter defaults to running. PMCR.DP says "disable
1127 * the cycle counter when event counting is prohibited".
1128 * Some MDCR bits disable the cycle counter specifically.
1130 prohibited
= prohibited
&& env
->cp15
.c9_pmcr
& PMCRDP
;
1131 if (cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1133 prohibited
= prohibited
|| (env
->cp15
.mdcr_el3
& MDCR_SCCD
);
1136 prohibited
= prohibited
|| (mdcr_el2
& MDCR_HCCD
);
1141 if (counter
== 31) {
1142 filter
= env
->cp15
.pmccfiltr_el0
;
1144 filter
= env
->cp15
.c14_pmevtyper
[counter
];
1147 p
= filter
& PMXEVTYPER_P
;
1148 u
= filter
& PMXEVTYPER_U
;
1149 nsk
= arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_NSK
);
1150 nsu
= arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_NSU
);
1151 nsh
= arm_feature(env
, ARM_FEATURE_EL2
) && (filter
& PMXEVTYPER_NSH
);
1152 m
= arm_el_is_aa64(env
, 1) &&
1153 arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_M
);
1156 filtered
= secure
? u
: u
!= nsu
;
1157 } else if (el
== 1) {
1158 filtered
= secure
? p
: p
!= nsk
;
1159 } else if (el
== 2) {
1165 if (counter
!= 31) {
1167 * If not checking PMCCNTR, ensure the counter is setup to an event we
1170 uint16_t event
= filter
& PMXEVTYPER_EVTCOUNT
;
1171 if (!event_supported(event
)) {
1176 return enabled
&& !prohibited
&& !filtered
;
1179 static void pmu_update_irq(CPUARMState
*env
)
1181 ARMCPU
*cpu
= env_archcpu(env
);
1182 qemu_set_irq(cpu
->pmu_interrupt
, (env
->cp15
.c9_pmcr
& PMCRE
) &&
1183 (env
->cp15
.c9_pminten
& env
->cp15
.c9_pmovsr
));
1186 static bool pmccntr_clockdiv_enabled(CPUARMState
*env
)
1189 * Return true if the clock divider is enabled and the cycle counter
1190 * is supposed to tick only once every 64 clock cycles. This is
1191 * controlled by PMCR.D, but if PMCR.LC is set to enable the long
1192 * (64-bit) cycle counter PMCR.D has no effect.
1194 return (env
->cp15
.c9_pmcr
& (PMCRD
| PMCRLC
)) == PMCRD
;
1197 static bool pmevcntr_is_64_bit(CPUARMState
*env
, int counter
)
1199 /* Return true if the specified event counter is configured to be 64 bit */
1201 /* This isn't intended to be used with the cycle counter */
1202 assert(counter
< 31);
1204 if (!cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1208 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
1210 * MDCR_EL2.HLP still applies even when EL2 is disabled in the
1211 * current security state, so we don't use arm_mdcr_el2_eff() here.
1213 bool hlp
= env
->cp15
.mdcr_el2
& MDCR_HLP
;
1214 int hpmn
= env
->cp15
.mdcr_el2
& MDCR_HPMN
;
1216 if (hpmn
!= 0 && counter
>= hpmn
) {
1220 return env
->cp15
.c9_pmcr
& PMCRLP
;
1224 * Ensure c15_ccnt is the guest-visible count so that operations such as
1225 * enabling/disabling the counter or filtering, modifying the count itself,
1226 * etc. can be done logically. This is essentially a no-op if the counter is
1227 * not enabled at the time of the call.
1229 static void pmccntr_op_start(CPUARMState
*env
)
1231 uint64_t cycles
= cycles_get_count(env
);
1233 if (pmu_counter_enabled(env
, 31)) {
1234 uint64_t eff_cycles
= cycles
;
1235 if (pmccntr_clockdiv_enabled(env
)) {
1239 uint64_t new_pmccntr
= eff_cycles
- env
->cp15
.c15_ccnt_delta
;
1241 uint64_t overflow_mask
= env
->cp15
.c9_pmcr
& PMCRLC
? \
1242 1ull << 63 : 1ull << 31;
1243 if (env
->cp15
.c15_ccnt
& ~new_pmccntr
& overflow_mask
) {
1244 env
->cp15
.c9_pmovsr
|= (1ULL << 31);
1245 pmu_update_irq(env
);
1248 env
->cp15
.c15_ccnt
= new_pmccntr
;
1250 env
->cp15
.c15_ccnt_delta
= cycles
;
1254 * If PMCCNTR is enabled, recalculate the delta between the clock and the
1255 * guest-visible count. A call to pmccntr_op_finish should follow every call to
1258 static void pmccntr_op_finish(CPUARMState
*env
)
1260 if (pmu_counter_enabled(env
, 31)) {
1261 #ifndef CONFIG_USER_ONLY
1262 /* Calculate when the counter will next overflow */
1263 uint64_t remaining_cycles
= -env
->cp15
.c15_ccnt
;
1264 if (!(env
->cp15
.c9_pmcr
& PMCRLC
)) {
1265 remaining_cycles
= (uint32_t)remaining_cycles
;
1267 int64_t overflow_in
= cycles_ns_per(remaining_cycles
);
1269 if (overflow_in
> 0) {
1270 int64_t overflow_at
;
1272 if (!sadd64_overflow(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
1273 overflow_in
, &overflow_at
)) {
1274 ARMCPU
*cpu
= env_archcpu(env
);
1275 timer_mod_anticipate_ns(cpu
->pmu_timer
, overflow_at
);
1280 uint64_t prev_cycles
= env
->cp15
.c15_ccnt_delta
;
1281 if (pmccntr_clockdiv_enabled(env
)) {
1284 env
->cp15
.c15_ccnt_delta
= prev_cycles
- env
->cp15
.c15_ccnt
;
1288 static void pmevcntr_op_start(CPUARMState
*env
, uint8_t counter
)
1291 uint16_t event
= env
->cp15
.c14_pmevtyper
[counter
] & PMXEVTYPER_EVTCOUNT
;
1293 if (event_supported(event
)) {
1294 uint16_t event_idx
= supported_event_map
[event
];
1295 count
= pm_events
[event_idx
].get_count(env
);
1298 if (pmu_counter_enabled(env
, counter
)) {
1299 uint64_t new_pmevcntr
= count
- env
->cp15
.c14_pmevcntr_delta
[counter
];
1300 uint64_t overflow_mask
= pmevcntr_is_64_bit(env
, counter
) ?
1301 1ULL << 63 : 1ULL << 31;
1303 if (env
->cp15
.c14_pmevcntr
[counter
] & ~new_pmevcntr
& overflow_mask
) {
1304 env
->cp15
.c9_pmovsr
|= (1 << counter
);
1305 pmu_update_irq(env
);
1307 env
->cp15
.c14_pmevcntr
[counter
] = new_pmevcntr
;
1309 env
->cp15
.c14_pmevcntr_delta
[counter
] = count
;
1312 static void pmevcntr_op_finish(CPUARMState
*env
, uint8_t counter
)
1314 if (pmu_counter_enabled(env
, counter
)) {
1315 #ifndef CONFIG_USER_ONLY
1316 uint16_t event
= env
->cp15
.c14_pmevtyper
[counter
] & PMXEVTYPER_EVTCOUNT
;
1317 uint16_t event_idx
= supported_event_map
[event
];
1318 uint64_t delta
= -(env
->cp15
.c14_pmevcntr
[counter
] + 1);
1319 int64_t overflow_in
;
1321 if (!pmevcntr_is_64_bit(env
, counter
)) {
1322 delta
= (uint32_t)delta
;
1324 overflow_in
= pm_events
[event_idx
].ns_per_count(delta
);
1326 if (overflow_in
> 0) {
1327 int64_t overflow_at
;
1329 if (!sadd64_overflow(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
1330 overflow_in
, &overflow_at
)) {
1331 ARMCPU
*cpu
= env_archcpu(env
);
1332 timer_mod_anticipate_ns(cpu
->pmu_timer
, overflow_at
);
1337 env
->cp15
.c14_pmevcntr_delta
[counter
] -=
1338 env
->cp15
.c14_pmevcntr
[counter
];
1342 void pmu_op_start(CPUARMState
*env
)
1345 pmccntr_op_start(env
);
1346 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1347 pmevcntr_op_start(env
, i
);
1351 void pmu_op_finish(CPUARMState
*env
)
1354 pmccntr_op_finish(env
);
1355 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1356 pmevcntr_op_finish(env
, i
);
1360 void pmu_pre_el_change(ARMCPU
*cpu
, void *ignored
)
1362 pmu_op_start(&cpu
->env
);
1365 void pmu_post_el_change(ARMCPU
*cpu
, void *ignored
)
1367 pmu_op_finish(&cpu
->env
);
1370 void arm_pmu_timer_cb(void *opaque
)
1372 ARMCPU
*cpu
= opaque
;
1375 * Update all the counter values based on the current underlying counts,
1376 * triggering interrupts to be raised, if necessary. pmu_op_finish() also
1377 * has the effect of setting the cpu->pmu_timer to the next earliest time a
1378 * counter may expire.
1380 pmu_op_start(&cpu
->env
);
1381 pmu_op_finish(&cpu
->env
);
1384 static void pmcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1389 if (value
& PMCRC
) {
1390 /* The counter has been reset */
1391 env
->cp15
.c15_ccnt
= 0;
1394 if (value
& PMCRP
) {
1396 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1397 env
->cp15
.c14_pmevcntr
[i
] = 0;
1401 env
->cp15
.c9_pmcr
&= ~PMCR_WRITABLE_MASK
;
1402 env
->cp15
.c9_pmcr
|= (value
& PMCR_WRITABLE_MASK
);
1407 static void pmswinc_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1411 uint64_t overflow_mask
, new_pmswinc
;
1413 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1414 /* Increment a counter's count iff: */
1415 if ((value
& (1 << i
)) && /* counter's bit is set */
1416 /* counter is enabled and not filtered */
1417 pmu_counter_enabled(env
, i
) &&
1418 /* counter is SW_INCR */
1419 (env
->cp15
.c14_pmevtyper
[i
] & PMXEVTYPER_EVTCOUNT
) == 0x0) {
1420 pmevcntr_op_start(env
, i
);
1423 * Detect if this write causes an overflow since we can't predict
1424 * PMSWINC overflows like we can for other events
1426 new_pmswinc
= env
->cp15
.c14_pmevcntr
[i
] + 1;
1428 overflow_mask
= pmevcntr_is_64_bit(env
, i
) ?
1429 1ULL << 63 : 1ULL << 31;
1431 if (env
->cp15
.c14_pmevcntr
[i
] & ~new_pmswinc
& overflow_mask
) {
1432 env
->cp15
.c9_pmovsr
|= (1 << i
);
1433 pmu_update_irq(env
);
1436 env
->cp15
.c14_pmevcntr
[i
] = new_pmswinc
;
1438 pmevcntr_op_finish(env
, i
);
1443 static uint64_t pmccntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1446 pmccntr_op_start(env
);
1447 ret
= env
->cp15
.c15_ccnt
;
1448 pmccntr_op_finish(env
);
1452 static void pmselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1455 /* The value of PMSELR.SEL affects the behavior of PMXEVTYPER and
1456 * PMXEVCNTR. We allow [0..31] to be written to PMSELR here; in the
1457 * meanwhile, we check PMSELR.SEL when PMXEVTYPER and PMXEVCNTR are
1460 env
->cp15
.c9_pmselr
= value
& 0x1f;
1463 static void pmccntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1466 pmccntr_op_start(env
);
1467 env
->cp15
.c15_ccnt
= value
;
1468 pmccntr_op_finish(env
);
1471 static void pmccntr_write32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1474 uint64_t cur_val
= pmccntr_read(env
, NULL
);
1476 pmccntr_write(env
, ri
, deposit64(cur_val
, 0, 32, value
));
1479 static void pmccfiltr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1482 pmccntr_op_start(env
);
1483 env
->cp15
.pmccfiltr_el0
= value
& PMCCFILTR_EL0
;
1484 pmccntr_op_finish(env
);
1487 static void pmccfiltr_write_a32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1490 pmccntr_op_start(env
);
1491 /* M is not accessible from AArch32 */
1492 env
->cp15
.pmccfiltr_el0
= (env
->cp15
.pmccfiltr_el0
& PMCCFILTR_M
) |
1493 (value
& PMCCFILTR
);
1494 pmccntr_op_finish(env
);
1497 static uint64_t pmccfiltr_read_a32(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1499 /* M is not visible in AArch32 */
1500 return env
->cp15
.pmccfiltr_el0
& PMCCFILTR
;
1503 static void pmcntenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1507 value
&= pmu_counter_mask(env
);
1508 env
->cp15
.c9_pmcnten
|= value
;
1512 static void pmcntenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1516 value
&= pmu_counter_mask(env
);
1517 env
->cp15
.c9_pmcnten
&= ~value
;
1521 static void pmovsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1524 value
&= pmu_counter_mask(env
);
1525 env
->cp15
.c9_pmovsr
&= ~value
;
1526 pmu_update_irq(env
);
1529 static void pmovsset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1532 value
&= pmu_counter_mask(env
);
1533 env
->cp15
.c9_pmovsr
|= value
;
1534 pmu_update_irq(env
);
1537 static void pmevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1538 uint64_t value
, const uint8_t counter
)
1540 if (counter
== 31) {
1541 pmccfiltr_write(env
, ri
, value
);
1542 } else if (counter
< pmu_num_counters(env
)) {
1543 pmevcntr_op_start(env
, counter
);
1546 * If this counter's event type is changing, store the current
1547 * underlying count for the new type in c14_pmevcntr_delta[counter] so
1548 * pmevcntr_op_finish has the correct baseline when it converts back to
1551 uint16_t old_event
= env
->cp15
.c14_pmevtyper
[counter
] &
1552 PMXEVTYPER_EVTCOUNT
;
1553 uint16_t new_event
= value
& PMXEVTYPER_EVTCOUNT
;
1554 if (old_event
!= new_event
) {
1556 if (event_supported(new_event
)) {
1557 uint16_t event_idx
= supported_event_map
[new_event
];
1558 count
= pm_events
[event_idx
].get_count(env
);
1560 env
->cp15
.c14_pmevcntr_delta
[counter
] = count
;
1563 env
->cp15
.c14_pmevtyper
[counter
] = value
& PMXEVTYPER_MASK
;
1564 pmevcntr_op_finish(env
, counter
);
1566 /* Attempts to access PMXEVTYPER are CONSTRAINED UNPREDICTABLE when
1567 * PMSELR value is equal to or greater than the number of implemented
1568 * counters, but not equal to 0x1f. We opt to behave as a RAZ/WI.
1572 static uint64_t pmevtyper_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1573 const uint8_t counter
)
1575 if (counter
== 31) {
1576 return env
->cp15
.pmccfiltr_el0
;
1577 } else if (counter
< pmu_num_counters(env
)) {
1578 return env
->cp15
.c14_pmevtyper
[counter
];
1581 * We opt to behave as a RAZ/WI when attempts to access PMXEVTYPER
1582 * are CONSTRAINED UNPREDICTABLE. See comments in pmevtyper_write().
1588 static void pmevtyper_writefn(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1591 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1592 pmevtyper_write(env
, ri
, value
, counter
);
1595 static void pmevtyper_rawwrite(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1598 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1599 env
->cp15
.c14_pmevtyper
[counter
] = value
;
1602 * pmevtyper_rawwrite is called between a pair of pmu_op_start and
1603 * pmu_op_finish calls when loading saved state for a migration. Because
1604 * we're potentially updating the type of event here, the value written to
1605 * c14_pmevcntr_delta by the preceeding pmu_op_start call may be for a
1606 * different counter type. Therefore, we need to set this value to the
1607 * current count for the counter type we're writing so that pmu_op_finish
1608 * has the correct count for its calculation.
1610 uint16_t event
= value
& PMXEVTYPER_EVTCOUNT
;
1611 if (event_supported(event
)) {
1612 uint16_t event_idx
= supported_event_map
[event
];
1613 env
->cp15
.c14_pmevcntr_delta
[counter
] =
1614 pm_events
[event_idx
].get_count(env
);
1618 static uint64_t pmevtyper_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1620 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1621 return pmevtyper_read(env
, ri
, counter
);
1624 static void pmxevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1627 pmevtyper_write(env
, ri
, value
, env
->cp15
.c9_pmselr
& 31);
1630 static uint64_t pmxevtyper_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1632 return pmevtyper_read(env
, ri
, env
->cp15
.c9_pmselr
& 31);
1635 static void pmevcntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1636 uint64_t value
, uint8_t counter
)
1638 if (!cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1639 /* Before FEAT_PMUv3p5, top 32 bits of event counters are RES0 */
1640 value
&= MAKE_64BIT_MASK(0, 32);
1642 if (counter
< pmu_num_counters(env
)) {
1643 pmevcntr_op_start(env
, counter
);
1644 env
->cp15
.c14_pmevcntr
[counter
] = value
;
1645 pmevcntr_op_finish(env
, counter
);
1648 * We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
1649 * are CONSTRAINED UNPREDICTABLE.
1653 static uint64_t pmevcntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1656 if (counter
< pmu_num_counters(env
)) {
1658 pmevcntr_op_start(env
, counter
);
1659 ret
= env
->cp15
.c14_pmevcntr
[counter
];
1660 pmevcntr_op_finish(env
, counter
);
1661 if (!cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1662 /* Before FEAT_PMUv3p5, top 32 bits of event counters are RES0 */
1663 ret
&= MAKE_64BIT_MASK(0, 32);
1667 /* We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
1668 * are CONSTRAINED UNPREDICTABLE. */
1673 static void pmevcntr_writefn(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1676 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1677 pmevcntr_write(env
, ri
, value
, counter
);
1680 static uint64_t pmevcntr_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1682 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1683 return pmevcntr_read(env
, ri
, counter
);
1686 static void pmevcntr_rawwrite(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1689 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1690 assert(counter
< pmu_num_counters(env
));
1691 env
->cp15
.c14_pmevcntr
[counter
] = value
;
1692 pmevcntr_write(env
, ri
, value
, counter
);
1695 static uint64_t pmevcntr_rawread(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1697 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1698 assert(counter
< pmu_num_counters(env
));
1699 return env
->cp15
.c14_pmevcntr
[counter
];
1702 static void pmxevcntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1705 pmevcntr_write(env
, ri
, value
, env
->cp15
.c9_pmselr
& 31);
1708 static uint64_t pmxevcntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1710 return pmevcntr_read(env
, ri
, env
->cp15
.c9_pmselr
& 31);
1713 static void pmuserenr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1716 if (arm_feature(env
, ARM_FEATURE_V8
)) {
1717 env
->cp15
.c9_pmuserenr
= value
& 0xf;
1719 env
->cp15
.c9_pmuserenr
= value
& 1;
1723 static void pmintenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1726 /* We have no event counters so only the C bit can be changed */
1727 value
&= pmu_counter_mask(env
);
1728 env
->cp15
.c9_pminten
|= value
;
1729 pmu_update_irq(env
);
1732 static void pmintenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1735 value
&= pmu_counter_mask(env
);
1736 env
->cp15
.c9_pminten
&= ~value
;
1737 pmu_update_irq(env
);
1740 static void vbar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1743 /* Note that even though the AArch64 view of this register has bits
1744 * [10:0] all RES0 we can only mask the bottom 5, to comply with the
1745 * architectural requirements for bits which are RES0 only in some
1746 * contexts. (ARMv8 would permit us to do no masking at all, but ARMv7
1747 * requires the bottom five bits to be RAZ/WI because they're UNK/SBZP.)
1749 raw_write(env
, ri
, value
& ~0x1FULL
);
1752 static void scr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
1754 /* Begin with base v8.0 state. */
1755 uint32_t valid_mask
= 0x3fff;
1756 ARMCPU
*cpu
= env_archcpu(env
);
1759 * Because SCR_EL3 is the "real" cpreg and SCR is the alias, reset always
1760 * passes the reginfo for SCR_EL3, which has type ARM_CP_STATE_AA64.
1761 * Instead, choose the format based on the mode of EL3.
1763 if (arm_el_is_aa64(env
, 3)) {
1764 value
|= SCR_FW
| SCR_AW
; /* RES1 */
1765 valid_mask
&= ~SCR_NET
; /* RES0 */
1767 if (!cpu_isar_feature(aa64_aa32_el1
, cpu
) &&
1768 !cpu_isar_feature(aa64_aa32_el2
, cpu
)) {
1769 value
|= SCR_RW
; /* RAO/WI */
1771 if (cpu_isar_feature(aa64_ras
, cpu
)) {
1772 valid_mask
|= SCR_TERR
;
1774 if (cpu_isar_feature(aa64_lor
, cpu
)) {
1775 valid_mask
|= SCR_TLOR
;
1777 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
1778 valid_mask
|= SCR_API
| SCR_APK
;
1780 if (cpu_isar_feature(aa64_sel2
, cpu
)) {
1781 valid_mask
|= SCR_EEL2
;
1783 if (cpu_isar_feature(aa64_mte
, cpu
)) {
1784 valid_mask
|= SCR_ATA
;
1786 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
1787 valid_mask
|= SCR_ENSCXT
;
1789 if (cpu_isar_feature(aa64_doublefault
, cpu
)) {
1790 valid_mask
|= SCR_EASE
| SCR_NMEA
;
1793 valid_mask
&= ~(SCR_RW
| SCR_ST
);
1794 if (cpu_isar_feature(aa32_ras
, cpu
)) {
1795 valid_mask
|= SCR_TERR
;
1799 if (!arm_feature(env
, ARM_FEATURE_EL2
)) {
1800 valid_mask
&= ~SCR_HCE
;
1802 /* On ARMv7, SMD (or SCD as it is called in v7) is only
1803 * supported if EL2 exists. The bit is UNK/SBZP when
1804 * EL2 is unavailable. In QEMU ARMv7, we force it to always zero
1805 * when EL2 is unavailable.
1806 * On ARMv8, this bit is always available.
1808 if (arm_feature(env
, ARM_FEATURE_V7
) &&
1809 !arm_feature(env
, ARM_FEATURE_V8
)) {
1810 valid_mask
&= ~SCR_SMD
;
1814 /* Clear all-context RES0 bits. */
1815 value
&= valid_mask
;
1816 raw_write(env
, ri
, value
);
1819 static void scr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1822 * scr_write will set the RES1 bits on an AArch64-only CPU.
1823 * The reset value will be 0x30 on an AArch64-only CPU and 0 otherwise.
1825 scr_write(env
, ri
, 0);
1828 static CPAccessResult
access_aa64_tid2(CPUARMState
*env
,
1829 const ARMCPRegInfo
*ri
,
1832 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID2
)) {
1833 return CP_ACCESS_TRAP_EL2
;
1836 return CP_ACCESS_OK
;
1839 static uint64_t ccsidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1841 ARMCPU
*cpu
= env_archcpu(env
);
1843 /* Acquire the CSSELR index from the bank corresponding to the CCSIDR
1846 uint32_t index
= A32_BANKED_REG_GET(env
, csselr
,
1847 ri
->secure
& ARM_CP_SECSTATE_S
);
1849 return cpu
->ccsidr
[index
];
1852 static void csselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1855 raw_write(env
, ri
, value
& 0xf);
1858 static uint64_t isr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1860 CPUState
*cs
= env_cpu(env
);
1861 bool el1
= arm_current_el(env
) == 1;
1862 uint64_t hcr_el2
= el1
? arm_hcr_el2_eff(env
) : 0;
1865 if (hcr_el2
& HCR_IMO
) {
1866 if (cs
->interrupt_request
& CPU_INTERRUPT_VIRQ
) {
1870 if (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) {
1875 if (hcr_el2
& HCR_FMO
) {
1876 if (cs
->interrupt_request
& CPU_INTERRUPT_VFIQ
) {
1880 if (cs
->interrupt_request
& CPU_INTERRUPT_FIQ
) {
1885 if (hcr_el2
& HCR_AMO
) {
1886 if (cs
->interrupt_request
& CPU_INTERRUPT_VSERR
) {
1894 static CPAccessResult
access_aa64_tid1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1897 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID1
)) {
1898 return CP_ACCESS_TRAP_EL2
;
1901 return CP_ACCESS_OK
;
1904 static CPAccessResult
access_aa32_tid1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1907 if (arm_feature(env
, ARM_FEATURE_V8
)) {
1908 return access_aa64_tid1(env
, ri
, isread
);
1911 return CP_ACCESS_OK
;
1914 static const ARMCPRegInfo v7_cp_reginfo
[] = {
1915 /* the old v6 WFI, UNPREDICTABLE in v7 but we choose to NOP */
1916 { .name
= "NOP", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
1917 .access
= PL1_W
, .type
= ARM_CP_NOP
},
1918 /* Performance monitors are implementation defined in v7,
1919 * but with an ARM recommended set of registers, which we
1922 * Performance registers fall into three categories:
1923 * (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR)
1924 * (b) RO in PL0 (ie UNDEF on write), RW in PL1 (PMUSERENR)
1925 * (c) UNDEF in PL0 if PMUSERENR.EN==0, otherwise accessible (all others)
1926 * For the cases controlled by PMUSERENR we must set .access to PL0_RW
1927 * or PL0_RO as appropriate and then check PMUSERENR in the helper fn.
1929 { .name
= "PMCNTENSET", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 1,
1930 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
,
1931 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
1932 .writefn
= pmcntenset_write
,
1933 .accessfn
= pmreg_access
,
1934 .raw_writefn
= raw_write
},
1935 { .name
= "PMCNTENSET_EL0", .state
= ARM_CP_STATE_AA64
,
1936 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 1,
1937 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1938 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
), .resetvalue
= 0,
1939 .writefn
= pmcntenset_write
, .raw_writefn
= raw_write
},
1940 { .name
= "PMCNTENCLR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 2,
1942 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
1943 .accessfn
= pmreg_access
,
1944 .writefn
= pmcntenclr_write
,
1945 .type
= ARM_CP_ALIAS
},
1946 { .name
= "PMCNTENCLR_EL0", .state
= ARM_CP_STATE_AA64
,
1947 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 2,
1948 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1949 .type
= ARM_CP_ALIAS
,
1950 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
),
1951 .writefn
= pmcntenclr_write
},
1952 { .name
= "PMOVSR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 3,
1953 .access
= PL0_RW
, .type
= ARM_CP_IO
,
1954 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmovsr
),
1955 .accessfn
= pmreg_access
,
1956 .writefn
= pmovsr_write
,
1957 .raw_writefn
= raw_write
},
1958 { .name
= "PMOVSCLR_EL0", .state
= ARM_CP_STATE_AA64
,
1959 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 3,
1960 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1961 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
1962 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
1963 .writefn
= pmovsr_write
,
1964 .raw_writefn
= raw_write
},
1965 { .name
= "PMSWINC", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 4,
1966 .access
= PL0_W
, .accessfn
= pmreg_access_swinc
,
1967 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
1968 .writefn
= pmswinc_write
},
1969 { .name
= "PMSWINC_EL0", .state
= ARM_CP_STATE_AA64
,
1970 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 4,
1971 .access
= PL0_W
, .accessfn
= pmreg_access_swinc
,
1972 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
1973 .writefn
= pmswinc_write
},
1974 { .name
= "PMSELR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 5,
1975 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
,
1976 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmselr
),
1977 .accessfn
= pmreg_access_selr
, .writefn
= pmselr_write
,
1978 .raw_writefn
= raw_write
},
1979 { .name
= "PMSELR_EL0", .state
= ARM_CP_STATE_AA64
,
1980 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 5,
1981 .access
= PL0_RW
, .accessfn
= pmreg_access_selr
,
1982 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmselr
),
1983 .writefn
= pmselr_write
, .raw_writefn
= raw_write
, },
1984 { .name
= "PMCCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 0,
1985 .access
= PL0_RW
, .resetvalue
= 0, .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
1986 .readfn
= pmccntr_read
, .writefn
= pmccntr_write32
,
1987 .accessfn
= pmreg_access_ccntr
},
1988 { .name
= "PMCCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
1989 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 0,
1990 .access
= PL0_RW
, .accessfn
= pmreg_access_ccntr
,
1992 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ccnt
),
1993 .readfn
= pmccntr_read
, .writefn
= pmccntr_write
,
1994 .raw_readfn
= raw_read
, .raw_writefn
= raw_write
, },
1995 { .name
= "PMCCFILTR", .cp
= 15, .opc1
= 0, .crn
= 14, .crm
= 15, .opc2
= 7,
1996 .writefn
= pmccfiltr_write_a32
, .readfn
= pmccfiltr_read_a32
,
1997 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1998 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2000 { .name
= "PMCCFILTR_EL0", .state
= ARM_CP_STATE_AA64
,
2001 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 15, .opc2
= 7,
2002 .writefn
= pmccfiltr_write
, .raw_writefn
= raw_write
,
2003 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2005 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmccfiltr_el0
),
2007 { .name
= "PMXEVTYPER", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 1,
2008 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2009 .accessfn
= pmreg_access
,
2010 .writefn
= pmxevtyper_write
, .readfn
= pmxevtyper_read
},
2011 { .name
= "PMXEVTYPER_EL0", .state
= ARM_CP_STATE_AA64
,
2012 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 1,
2013 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2014 .accessfn
= pmreg_access
,
2015 .writefn
= pmxevtyper_write
, .readfn
= pmxevtyper_read
},
2016 { .name
= "PMXEVCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 2,
2017 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2018 .accessfn
= pmreg_access_xevcntr
,
2019 .writefn
= pmxevcntr_write
, .readfn
= pmxevcntr_read
},
2020 { .name
= "PMXEVCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
2021 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 2,
2022 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2023 .accessfn
= pmreg_access_xevcntr
,
2024 .writefn
= pmxevcntr_write
, .readfn
= pmxevcntr_read
},
2025 { .name
= "PMUSERENR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 0,
2026 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
,
2027 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmuserenr
),
2029 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
2030 { .name
= "PMUSERENR_EL0", .state
= ARM_CP_STATE_AA64
,
2031 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 0,
2032 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
, .type
= ARM_CP_ALIAS
,
2033 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmuserenr
),
2035 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
2036 { .name
= "PMINTENSET", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 1,
2037 .access
= PL1_RW
, .accessfn
= access_tpm
,
2038 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2039 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pminten
),
2041 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
},
2042 { .name
= "PMINTENSET_EL1", .state
= ARM_CP_STATE_AA64
,
2043 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 1,
2044 .access
= PL1_RW
, .accessfn
= access_tpm
,
2046 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2047 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
,
2048 .resetvalue
= 0x0 },
2049 { .name
= "PMINTENCLR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 2,
2050 .access
= PL1_RW
, .accessfn
= access_tpm
,
2051 .type
= ARM_CP_ALIAS
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2052 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2053 .writefn
= pmintenclr_write
, },
2054 { .name
= "PMINTENCLR_EL1", .state
= ARM_CP_STATE_AA64
,
2055 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 2,
2056 .access
= PL1_RW
, .accessfn
= access_tpm
,
2057 .type
= ARM_CP_ALIAS
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2058 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2059 .writefn
= pmintenclr_write
},
2060 { .name
= "CCSIDR", .state
= ARM_CP_STATE_BOTH
,
2061 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 0,
2063 .accessfn
= access_aa64_tid2
,
2064 .readfn
= ccsidr_read
, .type
= ARM_CP_NO_RAW
},
2065 { .name
= "CSSELR", .state
= ARM_CP_STATE_BOTH
,
2066 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 2, .opc2
= 0,
2068 .accessfn
= access_aa64_tid2
,
2069 .writefn
= csselr_write
, .resetvalue
= 0,
2070 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.csselr_s
),
2071 offsetof(CPUARMState
, cp15
.csselr_ns
) } },
2072 /* Auxiliary ID register: this actually has an IMPDEF value but for now
2073 * just RAZ for all cores:
2075 { .name
= "AIDR", .state
= ARM_CP_STATE_BOTH
,
2076 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 7,
2077 .access
= PL1_R
, .type
= ARM_CP_CONST
,
2078 .accessfn
= access_aa64_tid1
,
2080 /* Auxiliary fault status registers: these also are IMPDEF, and we
2081 * choose to RAZ/WI for all cores.
2083 { .name
= "AFSR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2084 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 0,
2085 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2086 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
2087 { .name
= "AFSR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2088 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 1,
2089 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2090 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
2091 /* MAIR can just read-as-written because we don't implement caches
2092 * and so don't need to care about memory attributes.
2094 { .name
= "MAIR_EL1", .state
= ARM_CP_STATE_AA64
,
2095 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
2096 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2097 .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[1]),
2099 { .name
= "MAIR_EL3", .state
= ARM_CP_STATE_AA64
,
2100 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 2, .opc2
= 0,
2101 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[3]),
2103 /* For non-long-descriptor page tables these are PRRR and NMRR;
2104 * regardless they still act as reads-as-written for QEMU.
2106 /* MAIR0/1 are defined separately from their 64-bit counterpart which
2107 * allows them to assign the correct fieldoffset based on the endianness
2108 * handled in the field definitions.
2110 { .name
= "MAIR0", .state
= ARM_CP_STATE_AA32
,
2111 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
2112 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2113 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair0_s
),
2114 offsetof(CPUARMState
, cp15
.mair0_ns
) },
2115 .resetfn
= arm_cp_reset_ignore
},
2116 { .name
= "MAIR1", .state
= ARM_CP_STATE_AA32
,
2117 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 1,
2118 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2119 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair1_s
),
2120 offsetof(CPUARMState
, cp15
.mair1_ns
) },
2121 .resetfn
= arm_cp_reset_ignore
},
2122 { .name
= "ISR_EL1", .state
= ARM_CP_STATE_BOTH
,
2123 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 1, .opc2
= 0,
2124 .type
= ARM_CP_NO_RAW
, .access
= PL1_R
, .readfn
= isr_read
},
2125 /* 32 bit ITLB invalidates */
2126 { .name
= "ITLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 0,
2127 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2128 .writefn
= tlbiall_write
},
2129 { .name
= "ITLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
2130 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2131 .writefn
= tlbimva_write
},
2132 { .name
= "ITLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 2,
2133 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2134 .writefn
= tlbiasid_write
},
2135 /* 32 bit DTLB invalidates */
2136 { .name
= "DTLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 0,
2137 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2138 .writefn
= tlbiall_write
},
2139 { .name
= "DTLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
2140 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2141 .writefn
= tlbimva_write
},
2142 { .name
= "DTLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 2,
2143 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2144 .writefn
= tlbiasid_write
},
2145 /* 32 bit TLB invalidates */
2146 { .name
= "TLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
2147 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2148 .writefn
= tlbiall_write
},
2149 { .name
= "TLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
2150 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2151 .writefn
= tlbimva_write
},
2152 { .name
= "TLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
2153 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2154 .writefn
= tlbiasid_write
},
2155 { .name
= "TLBIMVAA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
2156 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2157 .writefn
= tlbimvaa_write
},
2160 static const ARMCPRegInfo v7mp_cp_reginfo
[] = {
2161 /* 32 bit TLB invalidates, Inner Shareable */
2162 { .name
= "TLBIALLIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
2163 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2164 .writefn
= tlbiall_is_write
},
2165 { .name
= "TLBIMVAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
2166 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2167 .writefn
= tlbimva_is_write
},
2168 { .name
= "TLBIASIDIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
2169 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2170 .writefn
= tlbiasid_is_write
},
2171 { .name
= "TLBIMVAAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
2172 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2173 .writefn
= tlbimvaa_is_write
},
2176 static const ARMCPRegInfo pmovsset_cp_reginfo
[] = {
2177 /* PMOVSSET is not implemented in v7 before v7ve */
2178 { .name
= "PMOVSSET", .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 3,
2179 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2180 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2181 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmovsr
),
2182 .writefn
= pmovsset_write
,
2183 .raw_writefn
= raw_write
},
2184 { .name
= "PMOVSSET_EL0", .state
= ARM_CP_STATE_AA64
,
2185 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 3,
2186 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2187 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2188 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
2189 .writefn
= pmovsset_write
,
2190 .raw_writefn
= raw_write
},
2193 static void teecr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2200 static CPAccessResult
teecr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2204 * HSTR.TTEE only exists in v7A, not v8A, but v8A doesn't have T2EE
2205 * at all, so we don't need to check whether we're v8A.
2207 if (arm_current_el(env
) < 2 && !arm_is_secure_below_el3(env
) &&
2208 (env
->cp15
.hstr_el2
& HSTR_TTEE
)) {
2209 return CP_ACCESS_TRAP_EL2
;
2211 return CP_ACCESS_OK
;
2214 static CPAccessResult
teehbr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2217 if (arm_current_el(env
) == 0 && (env
->teecr
& 1)) {
2218 return CP_ACCESS_TRAP
;
2220 return teecr_access(env
, ri
, isread
);
2223 static const ARMCPRegInfo t2ee_cp_reginfo
[] = {
2224 { .name
= "TEECR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 6, .opc2
= 0,
2225 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, teecr
),
2227 .writefn
= teecr_write
, .accessfn
= teecr_access
},
2228 { .name
= "TEEHBR", .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 6, .opc2
= 0,
2229 .access
= PL0_RW
, .fieldoffset
= offsetof(CPUARMState
, teehbr
),
2230 .accessfn
= teehbr_access
, .resetvalue
= 0 },
2233 static const ARMCPRegInfo v6k_cp_reginfo
[] = {
2234 { .name
= "TPIDR_EL0", .state
= ARM_CP_STATE_AA64
,
2235 .opc0
= 3, .opc1
= 3, .opc2
= 2, .crn
= 13, .crm
= 0,
2237 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[0]), .resetvalue
= 0 },
2238 { .name
= "TPIDRURW", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 2,
2240 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrurw_s
),
2241 offsetoflow32(CPUARMState
, cp15
.tpidrurw_ns
) },
2242 .resetfn
= arm_cp_reset_ignore
},
2243 { .name
= "TPIDRRO_EL0", .state
= ARM_CP_STATE_AA64
,
2244 .opc0
= 3, .opc1
= 3, .opc2
= 3, .crn
= 13, .crm
= 0,
2245 .access
= PL0_R
|PL1_W
,
2246 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidrro_el
[0]),
2248 { .name
= "TPIDRURO", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 3,
2249 .access
= PL0_R
|PL1_W
,
2250 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidruro_s
),
2251 offsetoflow32(CPUARMState
, cp15
.tpidruro_ns
) },
2252 .resetfn
= arm_cp_reset_ignore
},
2253 { .name
= "TPIDR_EL1", .state
= ARM_CP_STATE_AA64
,
2254 .opc0
= 3, .opc1
= 0, .opc2
= 4, .crn
= 13, .crm
= 0,
2256 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[1]), .resetvalue
= 0 },
2257 { .name
= "TPIDRPRW", .opc1
= 0, .cp
= 15, .crn
= 13, .crm
= 0, .opc2
= 4,
2259 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrprw_s
),
2260 offsetoflow32(CPUARMState
, cp15
.tpidrprw_ns
) },
2264 #ifndef CONFIG_USER_ONLY
2266 static CPAccessResult
gt_cntfrq_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2269 /* CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero.
2270 * Writable only at the highest implemented exception level.
2272 int el
= arm_current_el(env
);
2278 hcr
= arm_hcr_el2_eff(env
);
2279 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2280 cntkctl
= env
->cp15
.cnthctl_el2
;
2282 cntkctl
= env
->cp15
.c14_cntkctl
;
2284 if (!extract32(cntkctl
, 0, 2)) {
2285 return CP_ACCESS_TRAP
;
2289 if (!isread
&& ri
->state
== ARM_CP_STATE_AA32
&&
2290 arm_is_secure_below_el3(env
)) {
2291 /* Accesses from 32-bit Secure EL1 UNDEF (*not* trap to EL3!) */
2292 return CP_ACCESS_TRAP_UNCATEGORIZED
;
2300 if (!isread
&& el
< arm_highest_el(env
)) {
2301 return CP_ACCESS_TRAP_UNCATEGORIZED
;
2304 return CP_ACCESS_OK
;
2307 static CPAccessResult
gt_counter_access(CPUARMState
*env
, int timeridx
,
2310 unsigned int cur_el
= arm_current_el(env
);
2311 bool has_el2
= arm_is_el2_enabled(env
);
2312 uint64_t hcr
= arm_hcr_el2_eff(env
);
2316 /* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]CTEN. */
2317 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2318 return (extract32(env
->cp15
.cnthctl_el2
, timeridx
, 1)
2319 ? CP_ACCESS_OK
: CP_ACCESS_TRAP_EL2
);
2322 /* CNT[PV]CT: not visible from PL0 if EL0[PV]CTEN is zero */
2323 if (!extract32(env
->cp15
.c14_cntkctl
, timeridx
, 1)) {
2324 return CP_ACCESS_TRAP
;
2327 /* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PCTEN. */
2328 if (hcr
& HCR_E2H
) {
2329 if (timeridx
== GTIMER_PHYS
&&
2330 !extract32(env
->cp15
.cnthctl_el2
, 10, 1)) {
2331 return CP_ACCESS_TRAP_EL2
;
2334 /* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */
2335 if (has_el2
&& timeridx
== GTIMER_PHYS
&&
2336 !extract32(env
->cp15
.cnthctl_el2
, 1, 1)) {
2337 return CP_ACCESS_TRAP_EL2
;
2343 /* Check CNTHCTL_EL2.EL1PCTEN, which changes location based on E2H. */
2344 if (has_el2
&& timeridx
== GTIMER_PHYS
&&
2346 ? !extract32(env
->cp15
.cnthctl_el2
, 10, 1)
2347 : !extract32(env
->cp15
.cnthctl_el2
, 0, 1))) {
2348 return CP_ACCESS_TRAP_EL2
;
2352 return CP_ACCESS_OK
;
2355 static CPAccessResult
gt_timer_access(CPUARMState
*env
, int timeridx
,
2358 unsigned int cur_el
= arm_current_el(env
);
2359 bool has_el2
= arm_is_el2_enabled(env
);
2360 uint64_t hcr
= arm_hcr_el2_eff(env
);
2364 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2365 /* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]TEN. */
2366 return (extract32(env
->cp15
.cnthctl_el2
, 9 - timeridx
, 1)
2367 ? CP_ACCESS_OK
: CP_ACCESS_TRAP_EL2
);
2371 * CNT[PV]_CVAL, CNT[PV]_CTL, CNT[PV]_TVAL: not visible from
2372 * EL0 if EL0[PV]TEN is zero.
2374 if (!extract32(env
->cp15
.c14_cntkctl
, 9 - timeridx
, 1)) {
2375 return CP_ACCESS_TRAP
;
2380 if (has_el2
&& timeridx
== GTIMER_PHYS
) {
2381 if (hcr
& HCR_E2H
) {
2382 /* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PTEN. */
2383 if (!extract32(env
->cp15
.cnthctl_el2
, 11, 1)) {
2384 return CP_ACCESS_TRAP_EL2
;
2387 /* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */
2388 if (!extract32(env
->cp15
.cnthctl_el2
, 1, 1)) {
2389 return CP_ACCESS_TRAP_EL2
;
2395 return CP_ACCESS_OK
;
2398 static CPAccessResult
gt_pct_access(CPUARMState
*env
,
2399 const ARMCPRegInfo
*ri
,
2402 return gt_counter_access(env
, GTIMER_PHYS
, isread
);
2405 static CPAccessResult
gt_vct_access(CPUARMState
*env
,
2406 const ARMCPRegInfo
*ri
,
2409 return gt_counter_access(env
, GTIMER_VIRT
, isread
);
2412 static CPAccessResult
gt_ptimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2415 return gt_timer_access(env
, GTIMER_PHYS
, isread
);
2418 static CPAccessResult
gt_vtimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2421 return gt_timer_access(env
, GTIMER_VIRT
, isread
);
2424 static CPAccessResult
gt_stimer_access(CPUARMState
*env
,
2425 const ARMCPRegInfo
*ri
,
2428 /* The AArch64 register view of the secure physical timer is
2429 * always accessible from EL3, and configurably accessible from
2432 switch (arm_current_el(env
)) {
2434 if (!arm_is_secure(env
)) {
2435 return CP_ACCESS_TRAP
;
2437 if (!(env
->cp15
.scr_el3
& SCR_ST
)) {
2438 return CP_ACCESS_TRAP_EL3
;
2440 return CP_ACCESS_OK
;
2443 return CP_ACCESS_TRAP
;
2445 return CP_ACCESS_OK
;
2447 g_assert_not_reached();
2451 static uint64_t gt_get_countervalue(CPUARMState
*env
)
2453 ARMCPU
*cpu
= env_archcpu(env
);
2455 return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) / gt_cntfrq_period_ns(cpu
);
2458 static void gt_recalc_timer(ARMCPU
*cpu
, int timeridx
)
2460 ARMGenericTimer
*gt
= &cpu
->env
.cp15
.c14_timer
[timeridx
];
2463 /* Timer enabled: calculate and set current ISTATUS, irq, and
2464 * reset timer to when ISTATUS next has to change
2466 uint64_t offset
= timeridx
== GTIMER_VIRT
?
2467 cpu
->env
.cp15
.cntvoff_el2
: 0;
2468 uint64_t count
= gt_get_countervalue(&cpu
->env
);
2469 /* Note that this must be unsigned 64 bit arithmetic: */
2470 int istatus
= count
- offset
>= gt
->cval
;
2474 gt
->ctl
= deposit32(gt
->ctl
, 2, 1, istatus
);
2476 irqstate
= (istatus
&& !(gt
->ctl
& 2));
2477 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], irqstate
);
2480 /* Next transition is when count rolls back over to zero */
2481 nexttick
= UINT64_MAX
;
2483 /* Next transition is when we hit cval */
2484 nexttick
= gt
->cval
+ offset
;
2486 /* Note that the desired next expiry time might be beyond the
2487 * signed-64-bit range of a QEMUTimer -- in this case we just
2488 * set the timer for as far in the future as possible. When the
2489 * timer expires we will reset the timer for any remaining period.
2491 if (nexttick
> INT64_MAX
/ gt_cntfrq_period_ns(cpu
)) {
2492 timer_mod_ns(cpu
->gt_timer
[timeridx
], INT64_MAX
);
2494 timer_mod(cpu
->gt_timer
[timeridx
], nexttick
);
2496 trace_arm_gt_recalc(timeridx
, irqstate
, nexttick
);
2498 /* Timer disabled: ISTATUS and timer output always clear */
2500 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], 0);
2501 timer_del(cpu
->gt_timer
[timeridx
]);
2502 trace_arm_gt_recalc_disabled(timeridx
);
2506 static void gt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2509 ARMCPU
*cpu
= env_archcpu(env
);
2511 timer_del(cpu
->gt_timer
[timeridx
]);
2514 static uint64_t gt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2516 return gt_get_countervalue(env
);
2519 static uint64_t gt_virt_cnt_offset(CPUARMState
*env
)
2523 switch (arm_current_el(env
)) {
2525 hcr
= arm_hcr_el2_eff(env
);
2526 if (hcr
& HCR_E2H
) {
2531 hcr
= arm_hcr_el2_eff(env
);
2532 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2538 return env
->cp15
.cntvoff_el2
;
2541 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2543 return gt_get_countervalue(env
) - gt_virt_cnt_offset(env
);
2546 static void gt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2550 trace_arm_gt_cval_write(timeridx
, value
);
2551 env
->cp15
.c14_timer
[timeridx
].cval
= value
;
2552 gt_recalc_timer(env_archcpu(env
), timeridx
);
2555 static uint64_t gt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2558 uint64_t offset
= 0;
2562 case GTIMER_HYPVIRT
:
2563 offset
= gt_virt_cnt_offset(env
);
2567 return (uint32_t)(env
->cp15
.c14_timer
[timeridx
].cval
-
2568 (gt_get_countervalue(env
) - offset
));
2571 static void gt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2575 uint64_t offset
= 0;
2579 case GTIMER_HYPVIRT
:
2580 offset
= gt_virt_cnt_offset(env
);
2584 trace_arm_gt_tval_write(timeridx
, value
);
2585 env
->cp15
.c14_timer
[timeridx
].cval
= gt_get_countervalue(env
) - offset
+
2586 sextract64(value
, 0, 32);
2587 gt_recalc_timer(env_archcpu(env
), timeridx
);
2590 static void gt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2594 ARMCPU
*cpu
= env_archcpu(env
);
2595 uint32_t oldval
= env
->cp15
.c14_timer
[timeridx
].ctl
;
2597 trace_arm_gt_ctl_write(timeridx
, value
);
2598 env
->cp15
.c14_timer
[timeridx
].ctl
= deposit64(oldval
, 0, 2, value
);
2599 if ((oldval
^ value
) & 1) {
2600 /* Enable toggled */
2601 gt_recalc_timer(cpu
, timeridx
);
2602 } else if ((oldval
^ value
) & 2) {
2603 /* IMASK toggled: don't need to recalculate,
2604 * just set the interrupt line based on ISTATUS
2606 int irqstate
= (oldval
& 4) && !(value
& 2);
2608 trace_arm_gt_imask_toggle(timeridx
, irqstate
);
2609 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], irqstate
);
2613 static void gt_phys_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2615 gt_timer_reset(env
, ri
, GTIMER_PHYS
);
2618 static void gt_phys_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2621 gt_cval_write(env
, ri
, GTIMER_PHYS
, value
);
2624 static uint64_t gt_phys_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2626 return gt_tval_read(env
, ri
, GTIMER_PHYS
);
2629 static void gt_phys_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2632 gt_tval_write(env
, ri
, GTIMER_PHYS
, value
);
2635 static void gt_phys_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2638 gt_ctl_write(env
, ri
, GTIMER_PHYS
, value
);
2641 static int gt_phys_redir_timeridx(CPUARMState
*env
)
2643 switch (arm_mmu_idx(env
)) {
2644 case ARMMMUIdx_E20_0
:
2645 case ARMMMUIdx_E20_2
:
2646 case ARMMMUIdx_E20_2_PAN
:
2647 case ARMMMUIdx_SE20_0
:
2648 case ARMMMUIdx_SE20_2
:
2649 case ARMMMUIdx_SE20_2_PAN
:
2656 static int gt_virt_redir_timeridx(CPUARMState
*env
)
2658 switch (arm_mmu_idx(env
)) {
2659 case ARMMMUIdx_E20_0
:
2660 case ARMMMUIdx_E20_2
:
2661 case ARMMMUIdx_E20_2_PAN
:
2662 case ARMMMUIdx_SE20_0
:
2663 case ARMMMUIdx_SE20_2
:
2664 case ARMMMUIdx_SE20_2_PAN
:
2665 return GTIMER_HYPVIRT
;
2671 static uint64_t gt_phys_redir_cval_read(CPUARMState
*env
,
2672 const ARMCPRegInfo
*ri
)
2674 int timeridx
= gt_phys_redir_timeridx(env
);
2675 return env
->cp15
.c14_timer
[timeridx
].cval
;
2678 static void gt_phys_redir_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2681 int timeridx
= gt_phys_redir_timeridx(env
);
2682 gt_cval_write(env
, ri
, timeridx
, value
);
2685 static uint64_t gt_phys_redir_tval_read(CPUARMState
*env
,
2686 const ARMCPRegInfo
*ri
)
2688 int timeridx
= gt_phys_redir_timeridx(env
);
2689 return gt_tval_read(env
, ri
, timeridx
);
2692 static void gt_phys_redir_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2695 int timeridx
= gt_phys_redir_timeridx(env
);
2696 gt_tval_write(env
, ri
, timeridx
, value
);
2699 static uint64_t gt_phys_redir_ctl_read(CPUARMState
*env
,
2700 const ARMCPRegInfo
*ri
)
2702 int timeridx
= gt_phys_redir_timeridx(env
);
2703 return env
->cp15
.c14_timer
[timeridx
].ctl
;
2706 static void gt_phys_redir_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2709 int timeridx
= gt_phys_redir_timeridx(env
);
2710 gt_ctl_write(env
, ri
, timeridx
, value
);
2713 static void gt_virt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2715 gt_timer_reset(env
, ri
, GTIMER_VIRT
);
2718 static void gt_virt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2721 gt_cval_write(env
, ri
, GTIMER_VIRT
, value
);
2724 static uint64_t gt_virt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2726 return gt_tval_read(env
, ri
, GTIMER_VIRT
);
2729 static void gt_virt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2732 gt_tval_write(env
, ri
, GTIMER_VIRT
, value
);
2735 static void gt_virt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2738 gt_ctl_write(env
, ri
, GTIMER_VIRT
, value
);
2741 static void gt_cntvoff_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2744 ARMCPU
*cpu
= env_archcpu(env
);
2746 trace_arm_gt_cntvoff_write(value
);
2747 raw_write(env
, ri
, value
);
2748 gt_recalc_timer(cpu
, GTIMER_VIRT
);
2751 static uint64_t gt_virt_redir_cval_read(CPUARMState
*env
,
2752 const ARMCPRegInfo
*ri
)
2754 int timeridx
= gt_virt_redir_timeridx(env
);
2755 return env
->cp15
.c14_timer
[timeridx
].cval
;
2758 static void gt_virt_redir_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2761 int timeridx
= gt_virt_redir_timeridx(env
);
2762 gt_cval_write(env
, ri
, timeridx
, value
);
2765 static uint64_t gt_virt_redir_tval_read(CPUARMState
*env
,
2766 const ARMCPRegInfo
*ri
)
2768 int timeridx
= gt_virt_redir_timeridx(env
);
2769 return gt_tval_read(env
, ri
, timeridx
);
2772 static void gt_virt_redir_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2775 int timeridx
= gt_virt_redir_timeridx(env
);
2776 gt_tval_write(env
, ri
, timeridx
, value
);
2779 static uint64_t gt_virt_redir_ctl_read(CPUARMState
*env
,
2780 const ARMCPRegInfo
*ri
)
2782 int timeridx
= gt_virt_redir_timeridx(env
);
2783 return env
->cp15
.c14_timer
[timeridx
].ctl
;
2786 static void gt_virt_redir_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2789 int timeridx
= gt_virt_redir_timeridx(env
);
2790 gt_ctl_write(env
, ri
, timeridx
, value
);
2793 static void gt_hyp_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2795 gt_timer_reset(env
, ri
, GTIMER_HYP
);
2798 static void gt_hyp_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2801 gt_cval_write(env
, ri
, GTIMER_HYP
, value
);
2804 static uint64_t gt_hyp_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2806 return gt_tval_read(env
, ri
, GTIMER_HYP
);
2809 static void gt_hyp_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2812 gt_tval_write(env
, ri
, GTIMER_HYP
, value
);
2815 static void gt_hyp_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2818 gt_ctl_write(env
, ri
, GTIMER_HYP
, value
);
2821 static void gt_sec_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2823 gt_timer_reset(env
, ri
, GTIMER_SEC
);
2826 static void gt_sec_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2829 gt_cval_write(env
, ri
, GTIMER_SEC
, value
);
2832 static uint64_t gt_sec_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2834 return gt_tval_read(env
, ri
, GTIMER_SEC
);
2837 static void gt_sec_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2840 gt_tval_write(env
, ri
, GTIMER_SEC
, value
);
2843 static void gt_sec_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2846 gt_ctl_write(env
, ri
, GTIMER_SEC
, value
);
2849 static void gt_hv_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2851 gt_timer_reset(env
, ri
, GTIMER_HYPVIRT
);
2854 static void gt_hv_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2857 gt_cval_write(env
, ri
, GTIMER_HYPVIRT
, value
);
2860 static uint64_t gt_hv_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2862 return gt_tval_read(env
, ri
, GTIMER_HYPVIRT
);
2865 static void gt_hv_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2868 gt_tval_write(env
, ri
, GTIMER_HYPVIRT
, value
);
2871 static void gt_hv_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2874 gt_ctl_write(env
, ri
, GTIMER_HYPVIRT
, value
);
2877 void arm_gt_ptimer_cb(void *opaque
)
2879 ARMCPU
*cpu
= opaque
;
2881 gt_recalc_timer(cpu
, GTIMER_PHYS
);
2884 void arm_gt_vtimer_cb(void *opaque
)
2886 ARMCPU
*cpu
= opaque
;
2888 gt_recalc_timer(cpu
, GTIMER_VIRT
);
2891 void arm_gt_htimer_cb(void *opaque
)
2893 ARMCPU
*cpu
= opaque
;
2895 gt_recalc_timer(cpu
, GTIMER_HYP
);
2898 void arm_gt_stimer_cb(void *opaque
)
2900 ARMCPU
*cpu
= opaque
;
2902 gt_recalc_timer(cpu
, GTIMER_SEC
);
2905 void arm_gt_hvtimer_cb(void *opaque
)
2907 ARMCPU
*cpu
= opaque
;
2909 gt_recalc_timer(cpu
, GTIMER_HYPVIRT
);
2912 static void arm_gt_cntfrq_reset(CPUARMState
*env
, const ARMCPRegInfo
*opaque
)
2914 ARMCPU
*cpu
= env_archcpu(env
);
2916 cpu
->env
.cp15
.c14_cntfrq
= cpu
->gt_cntfrq_hz
;
2919 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
2920 /* Note that CNTFRQ is purely reads-as-written for the benefit
2921 * of software; writing it doesn't actually change the timer frequency.
2922 * Our reset value matches the fixed frequency we implement the timer at.
2924 { .name
= "CNTFRQ", .cp
= 15, .crn
= 14, .crm
= 0, .opc1
= 0, .opc2
= 0,
2925 .type
= ARM_CP_ALIAS
,
2926 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
2927 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c14_cntfrq
),
2929 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
2930 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
2931 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
2932 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
2933 .resetfn
= arm_gt_cntfrq_reset
,
2935 /* overall control: mostly access permissions */
2936 { .name
= "CNTKCTL", .state
= ARM_CP_STATE_BOTH
,
2937 .opc0
= 3, .opc1
= 0, .crn
= 14, .crm
= 1, .opc2
= 0,
2939 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntkctl
),
2942 /* per-timer control */
2943 { .name
= "CNTP_CTL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
2944 .secure
= ARM_CP_SECSTATE_NS
,
2945 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
2946 .accessfn
= gt_ptimer_access
,
2947 .fieldoffset
= offsetoflow32(CPUARMState
,
2948 cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
2949 .readfn
= gt_phys_redir_ctl_read
, .raw_readfn
= raw_read
,
2950 .writefn
= gt_phys_redir_ctl_write
, .raw_writefn
= raw_write
,
2952 { .name
= "CNTP_CTL_S",
2953 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
2954 .secure
= ARM_CP_SECSTATE_S
,
2955 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
2956 .accessfn
= gt_ptimer_access
,
2957 .fieldoffset
= offsetoflow32(CPUARMState
,
2958 cp15
.c14_timer
[GTIMER_SEC
].ctl
),
2959 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
2961 { .name
= "CNTP_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
2962 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 1,
2963 .type
= ARM_CP_IO
, .access
= PL0_RW
,
2964 .accessfn
= gt_ptimer_access
,
2965 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
2967 .readfn
= gt_phys_redir_ctl_read
, .raw_readfn
= raw_read
,
2968 .writefn
= gt_phys_redir_ctl_write
, .raw_writefn
= raw_write
,
2970 { .name
= "CNTV_CTL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 1,
2971 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
2972 .accessfn
= gt_vtimer_access
,
2973 .fieldoffset
= offsetoflow32(CPUARMState
,
2974 cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
2975 .readfn
= gt_virt_redir_ctl_read
, .raw_readfn
= raw_read
,
2976 .writefn
= gt_virt_redir_ctl_write
, .raw_writefn
= raw_write
,
2978 { .name
= "CNTV_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
2979 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 1,
2980 .type
= ARM_CP_IO
, .access
= PL0_RW
,
2981 .accessfn
= gt_vtimer_access
,
2982 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
2984 .readfn
= gt_virt_redir_ctl_read
, .raw_readfn
= raw_read
,
2985 .writefn
= gt_virt_redir_ctl_write
, .raw_writefn
= raw_write
,
2987 /* TimerValue views: a 32 bit downcounting view of the underlying state */
2988 { .name
= "CNTP_TVAL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
2989 .secure
= ARM_CP_SECSTATE_NS
,
2990 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
2991 .accessfn
= gt_ptimer_access
,
2992 .readfn
= gt_phys_redir_tval_read
, .writefn
= gt_phys_redir_tval_write
,
2994 { .name
= "CNTP_TVAL_S",
2995 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
2996 .secure
= ARM_CP_SECSTATE_S
,
2997 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
2998 .accessfn
= gt_ptimer_access
,
2999 .readfn
= gt_sec_tval_read
, .writefn
= gt_sec_tval_write
,
3001 { .name
= "CNTP_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3002 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 0,
3003 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3004 .accessfn
= gt_ptimer_access
, .resetfn
= gt_phys_timer_reset
,
3005 .readfn
= gt_phys_redir_tval_read
, .writefn
= gt_phys_redir_tval_write
,
3007 { .name
= "CNTV_TVAL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 0,
3008 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3009 .accessfn
= gt_vtimer_access
,
3010 .readfn
= gt_virt_redir_tval_read
, .writefn
= gt_virt_redir_tval_write
,
3012 { .name
= "CNTV_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3013 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 0,
3014 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3015 .accessfn
= gt_vtimer_access
, .resetfn
= gt_virt_timer_reset
,
3016 .readfn
= gt_virt_redir_tval_read
, .writefn
= gt_virt_redir_tval_write
,
3018 /* The counter itself */
3019 { .name
= "CNTPCT", .cp
= 15, .crm
= 14, .opc1
= 0,
3020 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3021 .accessfn
= gt_pct_access
,
3022 .readfn
= gt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3024 { .name
= "CNTPCT_EL0", .state
= ARM_CP_STATE_AA64
,
3025 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 1,
3026 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3027 .accessfn
= gt_pct_access
, .readfn
= gt_cnt_read
,
3029 { .name
= "CNTVCT", .cp
= 15, .crm
= 14, .opc1
= 1,
3030 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3031 .accessfn
= gt_vct_access
,
3032 .readfn
= gt_virt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3034 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
3035 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
3036 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3037 .accessfn
= gt_vct_access
, .readfn
= gt_virt_cnt_read
,
3039 /* Comparison value, indicating when the timer goes off */
3040 { .name
= "CNTP_CVAL", .cp
= 15, .crm
= 14, .opc1
= 2,
3041 .secure
= ARM_CP_SECSTATE_NS
,
3043 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3044 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
3045 .accessfn
= gt_ptimer_access
,
3046 .readfn
= gt_phys_redir_cval_read
, .raw_readfn
= raw_read
,
3047 .writefn
= gt_phys_redir_cval_write
, .raw_writefn
= raw_write
,
3049 { .name
= "CNTP_CVAL_S", .cp
= 15, .crm
= 14, .opc1
= 2,
3050 .secure
= ARM_CP_SECSTATE_S
,
3052 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3053 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
3054 .accessfn
= gt_ptimer_access
,
3055 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
3057 { .name
= "CNTP_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3058 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 2,
3061 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
3062 .resetvalue
= 0, .accessfn
= gt_ptimer_access
,
3063 .readfn
= gt_phys_redir_cval_read
, .raw_readfn
= raw_read
,
3064 .writefn
= gt_phys_redir_cval_write
, .raw_writefn
= raw_write
,
3066 { .name
= "CNTV_CVAL", .cp
= 15, .crm
= 14, .opc1
= 3,
3068 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3069 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
3070 .accessfn
= gt_vtimer_access
,
3071 .readfn
= gt_virt_redir_cval_read
, .raw_readfn
= raw_read
,
3072 .writefn
= gt_virt_redir_cval_write
, .raw_writefn
= raw_write
,
3074 { .name
= "CNTV_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3075 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 2,
3078 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
3079 .resetvalue
= 0, .accessfn
= gt_vtimer_access
,
3080 .readfn
= gt_virt_redir_cval_read
, .raw_readfn
= raw_read
,
3081 .writefn
= gt_virt_redir_cval_write
, .raw_writefn
= raw_write
,
3083 /* Secure timer -- this is actually restricted to only EL3
3084 * and configurably Secure-EL1 via the accessfn.
3086 { .name
= "CNTPS_TVAL_EL1", .state
= ARM_CP_STATE_AA64
,
3087 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 0,
3088 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
,
3089 .accessfn
= gt_stimer_access
,
3090 .readfn
= gt_sec_tval_read
,
3091 .writefn
= gt_sec_tval_write
,
3092 .resetfn
= gt_sec_timer_reset
,
3094 { .name
= "CNTPS_CTL_EL1", .state
= ARM_CP_STATE_AA64
,
3095 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 1,
3096 .type
= ARM_CP_IO
, .access
= PL1_RW
,
3097 .accessfn
= gt_stimer_access
,
3098 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].ctl
),
3100 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
3102 { .name
= "CNTPS_CVAL_EL1", .state
= ARM_CP_STATE_AA64
,
3103 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 2,
3104 .type
= ARM_CP_IO
, .access
= PL1_RW
,
3105 .accessfn
= gt_stimer_access
,
3106 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
3107 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
3111 static CPAccessResult
e2h_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3114 if (!(arm_hcr_el2_eff(env
) & HCR_E2H
)) {
3115 return CP_ACCESS_TRAP
;
3117 return CP_ACCESS_OK
;
3122 /* In user-mode most of the generic timer registers are inaccessible
3123 * however modern kernels (4.12+) allow access to cntvct_el0
3126 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3128 ARMCPU
*cpu
= env_archcpu(env
);
3130 /* Currently we have no support for QEMUTimer in linux-user so we
3131 * can't call gt_get_countervalue(env), instead we directly
3132 * call the lower level functions.
3134 return cpu_get_clock() / gt_cntfrq_period_ns(cpu
);
3137 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
3138 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
3139 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
3140 .type
= ARM_CP_CONST
, .access
= PL0_R
/* no PL1_RW in linux-user */,
3141 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
3142 .resetvalue
= NANOSECONDS_PER_SECOND
/ GTIMER_SCALE
,
3144 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
3145 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
3146 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3147 .readfn
= gt_virt_cnt_read
,
3153 static void par_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
3155 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3156 raw_write(env
, ri
, value
);
3157 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
3158 raw_write(env
, ri
, value
& 0xfffff6ff);
3160 raw_write(env
, ri
, value
& 0xfffff1ff);
3164 #ifndef CONFIG_USER_ONLY
3165 /* get_phys_addr() isn't present for user-mode-only targets */
3167 static CPAccessResult
ats_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3171 /* The ATS12NSO* operations must trap to EL3 or EL2 if executed in
3172 * Secure EL1 (which can only happen if EL3 is AArch64).
3173 * They are simply UNDEF if executed from NS EL1.
3174 * They function normally from EL2 or EL3.
3176 if (arm_current_el(env
) == 1) {
3177 if (arm_is_secure_below_el3(env
)) {
3178 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
3179 return CP_ACCESS_TRAP_UNCATEGORIZED_EL2
;
3181 return CP_ACCESS_TRAP_UNCATEGORIZED_EL3
;
3183 return CP_ACCESS_TRAP_UNCATEGORIZED
;
3186 return CP_ACCESS_OK
;
3190 static uint64_t do_ats_write(CPUARMState
*env
, uint64_t value
,
3191 MMUAccessType access_type
, ARMMMUIdx mmu_idx
)
3194 target_ulong page_size
;
3198 bool format64
= false;
3199 MemTxAttrs attrs
= {};
3200 ARMMMUFaultInfo fi
= {};
3201 ARMCacheAttrs cacheattrs
= {};
3203 ret
= get_phys_addr(env
, value
, access_type
, mmu_idx
, &phys_addr
, &attrs
,
3204 &prot
, &page_size
, &fi
, &cacheattrs
);
3207 * ATS operations only do S1 or S1+S2 translations, so we never
3208 * have to deal with the ARMCacheAttrs format for S2 only.
3210 assert(!cacheattrs
.is_s2_format
);
3214 * Some kinds of translation fault must cause exceptions rather
3215 * than being reported in the PAR.
3217 int current_el
= arm_current_el(env
);
3219 uint32_t syn
, fsr
, fsc
;
3220 bool take_exc
= false;
3222 if (fi
.s1ptw
&& current_el
== 1
3223 && arm_mmu_idx_is_stage1_of_2(mmu_idx
)) {
3225 * Synchronous stage 2 fault on an access made as part of the
3226 * translation table walk for AT S1E0* or AT S1E1* insn
3227 * executed from NS EL1. If this is a synchronous external abort
3228 * and SCR_EL3.EA == 1, then we take a synchronous external abort
3229 * to EL3. Otherwise the fault is taken as an exception to EL2,
3230 * and HPFAR_EL2 holds the faulting IPA.
3232 if (fi
.type
== ARMFault_SyncExternalOnWalk
&&
3233 (env
->cp15
.scr_el3
& SCR_EA
)) {
3236 env
->cp15
.hpfar_el2
= extract64(fi
.s2addr
, 12, 47) << 4;
3237 if (arm_is_secure_below_el3(env
) && fi
.s1ns
) {
3238 env
->cp15
.hpfar_el2
|= HPFAR_NS
;
3243 } else if (fi
.type
== ARMFault_SyncExternalOnWalk
) {
3245 * Synchronous external aborts during a translation table walk
3246 * are taken as Data Abort exceptions.
3249 if (current_el
== 3) {
3255 target_el
= exception_target_el(env
);
3261 /* Construct FSR and FSC using same logic as arm_deliver_fault() */
3262 if (target_el
== 2 || arm_el_is_aa64(env
, target_el
) ||
3263 arm_s1_regime_using_lpae_format(env
, mmu_idx
)) {
3264 fsr
= arm_fi_to_lfsc(&fi
);
3265 fsc
= extract32(fsr
, 0, 6);
3267 fsr
= arm_fi_to_sfsc(&fi
);
3271 * Report exception with ESR indicating a fault due to a
3272 * translation table walk for a cache maintenance instruction.
3274 syn
= syn_data_abort_no_iss(current_el
== target_el
, 0,
3275 fi
.ea
, 1, fi
.s1ptw
, 1, fsc
);
3276 env
->exception
.vaddress
= value
;
3277 env
->exception
.fsr
= fsr
;
3278 raise_exception(env
, EXCP_DATA_ABORT
, syn
, target_el
);
3284 } else if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3287 * * TTBCR.EAE determines whether the result is returned using the
3288 * 32-bit or the 64-bit PAR format
3289 * * Instructions executed in Hyp mode always use the 64bit format
3291 * ATS1S2NSOxx uses the 64bit format if any of the following is true:
3292 * * The Non-secure TTBCR.EAE bit is set to 1
3293 * * The implementation includes EL2, and the value of HCR.VM is 1
3295 * (Note that HCR.DC makes HCR.VM behave as if it is 1.)
3297 * ATS1Hx always uses the 64bit format.
3299 format64
= arm_s1_regime_using_lpae_format(env
, mmu_idx
);
3301 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
3302 if (mmu_idx
== ARMMMUIdx_E10_0
||
3303 mmu_idx
== ARMMMUIdx_E10_1
||
3304 mmu_idx
== ARMMMUIdx_E10_1_PAN
) {
3305 format64
|= env
->cp15
.hcr_el2
& (HCR_VM
| HCR_DC
);
3307 format64
|= arm_current_el(env
) == 2;
3313 /* Create a 64-bit PAR */
3314 par64
= (1 << 11); /* LPAE bit always set */
3316 par64
|= phys_addr
& ~0xfffULL
;
3317 if (!attrs
.secure
) {
3318 par64
|= (1 << 9); /* NS */
3320 par64
|= (uint64_t)cacheattrs
.attrs
<< 56; /* ATTR */
3321 par64
|= cacheattrs
.shareability
<< 7; /* SH */
3323 uint32_t fsr
= arm_fi_to_lfsc(&fi
);
3326 par64
|= (fsr
& 0x3f) << 1; /* FS */
3328 par64
|= (1 << 9); /* S */
3331 par64
|= (1 << 8); /* PTW */
3335 /* fsr is a DFSR/IFSR value for the short descriptor
3336 * translation table format (with WnR always clear).
3337 * Convert it to a 32-bit PAR.
3340 /* We do not set any attribute bits in the PAR */
3341 if (page_size
== (1 << 24)
3342 && arm_feature(env
, ARM_FEATURE_V7
)) {
3343 par64
= (phys_addr
& 0xff000000) | (1 << 1);
3345 par64
= phys_addr
& 0xfffff000;
3347 if (!attrs
.secure
) {
3348 par64
|= (1 << 9); /* NS */
3351 uint32_t fsr
= arm_fi_to_sfsc(&fi
);
3353 par64
= ((fsr
& (1 << 10)) >> 5) | ((fsr
& (1 << 12)) >> 6) |
3354 ((fsr
& 0xf) << 1) | 1;
3359 #endif /* CONFIG_TCG */
3361 static void ats_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
3364 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3367 int el
= arm_current_el(env
);
3368 bool secure
= arm_is_secure_below_el3(env
);
3370 switch (ri
->opc2
& 6) {
3372 /* stage 1 current state PL1: ATS1CPR, ATS1CPW, ATS1CPRP, ATS1CPWP */
3375 mmu_idx
= ARMMMUIdx_SE3
;
3378 g_assert(!secure
); /* ARMv8.4-SecEL2 is 64-bit only */
3381 if (ri
->crm
== 9 && (env
->uncached_cpsr
& CPSR_PAN
)) {
3382 mmu_idx
= (secure
? ARMMMUIdx_Stage1_SE1_PAN
3383 : ARMMMUIdx_Stage1_E1_PAN
);
3385 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE1
: ARMMMUIdx_Stage1_E1
;
3389 g_assert_not_reached();
3393 /* stage 1 current state PL0: ATS1CUR, ATS1CUW */
3396 mmu_idx
= ARMMMUIdx_SE10_0
;
3399 g_assert(!secure
); /* ARMv8.4-SecEL2 is 64-bit only */
3400 mmu_idx
= ARMMMUIdx_Stage1_E0
;
3403 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE0
: ARMMMUIdx_Stage1_E0
;
3406 g_assert_not_reached();
3410 /* stage 1+2 NonSecure PL1: ATS12NSOPR, ATS12NSOPW */
3411 mmu_idx
= ARMMMUIdx_E10_1
;
3414 /* stage 1+2 NonSecure PL0: ATS12NSOUR, ATS12NSOUW */
3415 mmu_idx
= ARMMMUIdx_E10_0
;
3418 g_assert_not_reached();
3421 par64
= do_ats_write(env
, value
, access_type
, mmu_idx
);
3423 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
3425 /* Handled by hardware accelerator. */
3426 g_assert_not_reached();
3427 #endif /* CONFIG_TCG */
3430 static void ats1h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3434 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3437 par64
= do_ats_write(env
, value
, access_type
, ARMMMUIdx_E2
);
3439 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
3441 /* Handled by hardware accelerator. */
3442 g_assert_not_reached();
3443 #endif /* CONFIG_TCG */
3446 static CPAccessResult
at_s1e2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3449 if (arm_current_el(env
) == 3 &&
3450 !(env
->cp15
.scr_el3
& (SCR_NS
| SCR_EEL2
))) {
3451 return CP_ACCESS_TRAP
;
3453 return CP_ACCESS_OK
;
3456 static void ats_write64(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3460 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3462 int secure
= arm_is_secure_below_el3(env
);
3464 switch (ri
->opc2
& 6) {
3467 case 0: /* AT S1E1R, AT S1E1W, AT S1E1RP, AT S1E1WP */
3468 if (ri
->crm
== 9 && (env
->pstate
& PSTATE_PAN
)) {
3469 mmu_idx
= (secure
? ARMMMUIdx_Stage1_SE1_PAN
3470 : ARMMMUIdx_Stage1_E1_PAN
);
3472 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE1
: ARMMMUIdx_Stage1_E1
;
3475 case 4: /* AT S1E2R, AT S1E2W */
3476 mmu_idx
= secure
? ARMMMUIdx_SE2
: ARMMMUIdx_E2
;
3478 case 6: /* AT S1E3R, AT S1E3W */
3479 mmu_idx
= ARMMMUIdx_SE3
;
3482 g_assert_not_reached();
3485 case 2: /* AT S1E0R, AT S1E0W */
3486 mmu_idx
= secure
? ARMMMUIdx_Stage1_SE0
: ARMMMUIdx_Stage1_E0
;
3488 case 4: /* AT S12E1R, AT S12E1W */
3489 mmu_idx
= secure
? ARMMMUIdx_SE10_1
: ARMMMUIdx_E10_1
;
3491 case 6: /* AT S12E0R, AT S12E0W */
3492 mmu_idx
= secure
? ARMMMUIdx_SE10_0
: ARMMMUIdx_E10_0
;
3495 g_assert_not_reached();
3498 env
->cp15
.par_el
[1] = do_ats_write(env
, value
, access_type
, mmu_idx
);
3500 /* Handled by hardware accelerator. */
3501 g_assert_not_reached();
3502 #endif /* CONFIG_TCG */
3506 static const ARMCPRegInfo vapa_cp_reginfo
[] = {
3507 { .name
= "PAR", .cp
= 15, .crn
= 7, .crm
= 4, .opc1
= 0, .opc2
= 0,
3508 .access
= PL1_RW
, .resetvalue
= 0,
3509 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.par_s
),
3510 offsetoflow32(CPUARMState
, cp15
.par_ns
) },
3511 .writefn
= par_write
},
3512 #ifndef CONFIG_USER_ONLY
3513 /* This underdecoding is safe because the reginfo is NO_RAW. */
3514 { .name
= "ATS", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= CP_ANY
,
3515 .access
= PL1_W
, .accessfn
= ats_access
,
3516 .writefn
= ats_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
3520 /* Return basic MPU access permission bits. */
3521 static uint32_t simple_mpu_ap_bits(uint32_t val
)
3528 for (i
= 0; i
< 16; i
+= 2) {
3529 ret
|= (val
>> i
) & mask
;
3535 /* Pad basic MPU access permission bits to extended format. */
3536 static uint32_t extended_mpu_ap_bits(uint32_t val
)
3543 for (i
= 0; i
< 16; i
+= 2) {
3544 ret
|= (val
& mask
) << i
;
3550 static void pmsav5_data_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3553 env
->cp15
.pmsav5_data_ap
= extended_mpu_ap_bits(value
);
3556 static uint64_t pmsav5_data_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3558 return simple_mpu_ap_bits(env
->cp15
.pmsav5_data_ap
);
3561 static void pmsav5_insn_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3564 env
->cp15
.pmsav5_insn_ap
= extended_mpu_ap_bits(value
);
3567 static uint64_t pmsav5_insn_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3569 return simple_mpu_ap_bits(env
->cp15
.pmsav5_insn_ap
);
3572 static uint64_t pmsav7_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3574 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
3580 u32p
+= env
->pmsav7
.rnr
[M_REG_NS
];
3584 static void pmsav7_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3587 ARMCPU
*cpu
= env_archcpu(env
);
3588 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
3594 u32p
+= env
->pmsav7
.rnr
[M_REG_NS
];
3595 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
3599 static void pmsav7_rgnr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3602 ARMCPU
*cpu
= env_archcpu(env
);
3603 uint32_t nrgs
= cpu
->pmsav7_dregion
;
3605 if (value
>= nrgs
) {
3606 qemu_log_mask(LOG_GUEST_ERROR
,
3607 "PMSAv7 RGNR write >= # supported regions, %" PRIu32
3608 " > %" PRIu32
"\n", (uint32_t)value
, nrgs
);
3612 raw_write(env
, ri
, value
);
3615 static const ARMCPRegInfo pmsav7_cp_reginfo
[] = {
3616 /* Reset for all these registers is handled in arm_cpu_reset(),
3617 * because the PMSAv7 is also used by M-profile CPUs, which do
3618 * not register cpregs but still need the state to be reset.
3620 { .name
= "DRBAR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 0,
3621 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
3622 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drbar
),
3623 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
3624 .resetfn
= arm_cp_reset_ignore
},
3625 { .name
= "DRSR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 2,
3626 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
3627 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drsr
),
3628 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
3629 .resetfn
= arm_cp_reset_ignore
},
3630 { .name
= "DRACR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 4,
3631 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
3632 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.dracr
),
3633 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
3634 .resetfn
= arm_cp_reset_ignore
},
3635 { .name
= "RGNR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 2, .opc2
= 0,
3637 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.rnr
[M_REG_NS
]),
3638 .writefn
= pmsav7_rgnr_write
,
3639 .resetfn
= arm_cp_reset_ignore
},
3642 static const ARMCPRegInfo pmsav5_cp_reginfo
[] = {
3643 { .name
= "DATA_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
3644 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
3645 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
3646 .readfn
= pmsav5_data_ap_read
, .writefn
= pmsav5_data_ap_write
, },
3647 { .name
= "INSN_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
3648 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
3649 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
3650 .readfn
= pmsav5_insn_ap_read
, .writefn
= pmsav5_insn_ap_write
, },
3651 { .name
= "DATA_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 2,
3653 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
3655 { .name
= "INSN_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 3,
3657 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
3659 { .name
= "DCACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 0,
3661 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_data
), .resetvalue
= 0, },
3662 { .name
= "ICACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 1,
3664 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_insn
), .resetvalue
= 0, },
3665 /* Protection region base and size registers */
3666 { .name
= "946_PRBS0", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0,
3667 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3668 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[0]) },
3669 { .name
= "946_PRBS1", .cp
= 15, .crn
= 6, .crm
= 1, .opc1
= 0,
3670 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3671 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[1]) },
3672 { .name
= "946_PRBS2", .cp
= 15, .crn
= 6, .crm
= 2, .opc1
= 0,
3673 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3674 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[2]) },
3675 { .name
= "946_PRBS3", .cp
= 15, .crn
= 6, .crm
= 3, .opc1
= 0,
3676 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3677 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[3]) },
3678 { .name
= "946_PRBS4", .cp
= 15, .crn
= 6, .crm
= 4, .opc1
= 0,
3679 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3680 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[4]) },
3681 { .name
= "946_PRBS5", .cp
= 15, .crn
= 6, .crm
= 5, .opc1
= 0,
3682 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3683 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[5]) },
3684 { .name
= "946_PRBS6", .cp
= 15, .crn
= 6, .crm
= 6, .opc1
= 0,
3685 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3686 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[6]) },
3687 { .name
= "946_PRBS7", .cp
= 15, .crn
= 6, .crm
= 7, .opc1
= 0,
3688 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
3689 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[7]) },
3692 static void vmsa_ttbcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3695 ARMCPU
*cpu
= env_archcpu(env
);
3697 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
3698 if (arm_feature(env
, ARM_FEATURE_LPAE
) && (value
& TTBCR_EAE
)) {
3700 * Pre ARMv8 bits [21:19], [15:14] and [6:3] are UNK/SBZP when
3701 * using Long-descriptor translation table format
3703 value
&= ~((7 << 19) | (3 << 14) | (0xf << 3));
3704 } else if (arm_feature(env
, ARM_FEATURE_EL3
)) {
3706 * In an implementation that includes the Security Extensions
3707 * TTBCR has additional fields PD0 [4] and PD1 [5] for
3708 * Short-descriptor translation table format.
3710 value
&= TTBCR_PD1
| TTBCR_PD0
| TTBCR_N
;
3716 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3717 /* With LPAE the TTBCR could result in a change of ASID
3718 * via the TTBCR.A1 bit, so do a TLB flush.
3720 tlb_flush(CPU(cpu
));
3722 raw_write(env
, ri
, value
);
3725 static void vmsa_tcr_el12_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3728 ARMCPU
*cpu
= env_archcpu(env
);
3730 /* For AArch64 the A1 bit could result in a change of ASID, so TLB flush. */
3731 tlb_flush(CPU(cpu
));
3732 raw_write(env
, ri
, value
);
3735 static void vmsa_ttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3738 /* If the ASID changes (with a 64-bit write), we must flush the TLB. */
3739 if (cpreg_field_is_64bit(ri
) &&
3740 extract64(raw_read(env
, ri
) ^ value
, 48, 16) != 0) {
3741 ARMCPU
*cpu
= env_archcpu(env
);
3742 tlb_flush(CPU(cpu
));
3744 raw_write(env
, ri
, value
);
3747 static void vmsa_tcr_ttbr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3751 * If we are running with E2&0 regime, then an ASID is active.
3752 * Flush if that might be changing. Note we're not checking
3753 * TCR_EL2.A1 to know if this is really the TTBRx_EL2 that
3754 * holds the active ASID, only checking the field that might.
3756 if (extract64(raw_read(env
, ri
) ^ value
, 48, 16) &&
3757 (arm_hcr_el2_eff(env
) & HCR_E2H
)) {
3758 uint16_t mask
= ARMMMUIdxBit_E20_2
|
3759 ARMMMUIdxBit_E20_2_PAN
|
3762 if (arm_is_secure_below_el3(env
)) {
3763 mask
>>= ARM_MMU_IDX_A_NS
;
3766 tlb_flush_by_mmuidx(env_cpu(env
), mask
);
3768 raw_write(env
, ri
, value
);
3771 static void vttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3774 ARMCPU
*cpu
= env_archcpu(env
);
3775 CPUState
*cs
= CPU(cpu
);
3778 * A change in VMID to the stage2 page table (Stage2) invalidates
3779 * the combined stage 1&2 tlbs (EL10_1 and EL10_0).
3781 if (raw_read(env
, ri
) != value
) {
3782 uint16_t mask
= ARMMMUIdxBit_E10_1
|
3783 ARMMMUIdxBit_E10_1_PAN
|
3786 if (arm_is_secure_below_el3(env
)) {
3787 mask
>>= ARM_MMU_IDX_A_NS
;
3790 tlb_flush_by_mmuidx(cs
, mask
);
3791 raw_write(env
, ri
, value
);
3795 static const ARMCPRegInfo vmsa_pmsa_cp_reginfo
[] = {
3796 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
3797 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .type
= ARM_CP_ALIAS
,
3798 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dfsr_s
),
3799 offsetoflow32(CPUARMState
, cp15
.dfsr_ns
) }, },
3800 { .name
= "IFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
3801 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
3802 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.ifsr_s
),
3803 offsetoflow32(CPUARMState
, cp15
.ifsr_ns
) } },
3804 { .name
= "DFAR", .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 0, .opc2
= 0,
3805 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
3806 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.dfar_s
),
3807 offsetof(CPUARMState
, cp15
.dfar_ns
) } },
3808 { .name
= "FAR_EL1", .state
= ARM_CP_STATE_AA64
,
3809 .opc0
= 3, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 0,
3810 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3811 .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[1]),
3815 static const ARMCPRegInfo vmsa_cp_reginfo
[] = {
3816 { .name
= "ESR_EL1", .state
= ARM_CP_STATE_AA64
,
3817 .opc0
= 3, .crn
= 5, .crm
= 2, .opc1
= 0, .opc2
= 0,
3818 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3819 .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[1]), .resetvalue
= 0, },
3820 { .name
= "TTBR0_EL1", .state
= ARM_CP_STATE_BOTH
,
3821 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 0,
3822 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3823 .writefn
= vmsa_ttbr_write
, .resetvalue
= 0,
3824 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
3825 offsetof(CPUARMState
, cp15
.ttbr0_ns
) } },
3826 { .name
= "TTBR1_EL1", .state
= ARM_CP_STATE_BOTH
,
3827 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 1,
3828 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3829 .writefn
= vmsa_ttbr_write
, .resetvalue
= 0,
3830 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
3831 offsetof(CPUARMState
, cp15
.ttbr1_ns
) } },
3832 { .name
= "TCR_EL1", .state
= ARM_CP_STATE_AA64
,
3833 .opc0
= 3, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
3834 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3835 .writefn
= vmsa_tcr_el12_write
,
3836 .raw_writefn
= raw_write
,
3838 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[1]) },
3839 { .name
= "TTBCR", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
3840 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3841 .type
= ARM_CP_ALIAS
, .writefn
= vmsa_ttbcr_write
,
3842 .raw_writefn
= raw_write
,
3843 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tcr_el
[3]),
3844 offsetoflow32(CPUARMState
, cp15
.tcr_el
[1])} },
3847 /* Note that unlike TTBCR, writing to TTBCR2 does not require flushing
3848 * qemu tlbs nor adjusting cached masks.
3850 static const ARMCPRegInfo ttbcr2_reginfo
= {
3851 .name
= "TTBCR2", .cp
= 15, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 3,
3852 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3853 .type
= ARM_CP_ALIAS
,
3854 .bank_fieldoffsets
= {
3855 offsetofhigh32(CPUARMState
, cp15
.tcr_el
[3]),
3856 offsetofhigh32(CPUARMState
, cp15
.tcr_el
[1]),
3860 static void omap_ticonfig_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3863 env
->cp15
.c15_ticonfig
= value
& 0xe7;
3864 /* The OS_TYPE bit in this register changes the reported CPUID! */
3865 env
->cp15
.c0_cpuid
= (value
& (1 << 5)) ?
3866 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
3869 static void omap_threadid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3872 env
->cp15
.c15_threadid
= value
& 0xffff;
3875 static void omap_wfi_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3878 /* Wait-for-interrupt (deprecated) */
3879 cpu_interrupt(env_cpu(env
), CPU_INTERRUPT_HALT
);
3882 static void omap_cachemaint_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3885 /* On OMAP there are registers indicating the max/min index of dcache lines
3886 * containing a dirty line; cache flush operations have to reset these.
3888 env
->cp15
.c15_i_max
= 0x000;
3889 env
->cp15
.c15_i_min
= 0xff0;
3892 static const ARMCPRegInfo omap_cp_reginfo
[] = {
3893 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= CP_ANY
,
3894 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_OVERRIDE
,
3895 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.esr_el
[1]),
3897 { .name
= "", .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 0, .opc2
= 0,
3898 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
3899 { .name
= "TICONFIG", .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0,
3901 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ticonfig
), .resetvalue
= 0,
3902 .writefn
= omap_ticonfig_write
},
3903 { .name
= "IMAX", .cp
= 15, .crn
= 15, .crm
= 2, .opc1
= 0, .opc2
= 0,
3905 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_max
), .resetvalue
= 0, },
3906 { .name
= "IMIN", .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 0, .opc2
= 0,
3907 .access
= PL1_RW
, .resetvalue
= 0xff0,
3908 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_min
) },
3909 { .name
= "THREADID", .cp
= 15, .crn
= 15, .crm
= 4, .opc1
= 0, .opc2
= 0,
3911 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_threadid
), .resetvalue
= 0,
3912 .writefn
= omap_threadid_write
},
3913 { .name
= "TI925T_STATUS", .cp
= 15, .crn
= 15,
3914 .crm
= 8, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
3915 .type
= ARM_CP_NO_RAW
,
3916 .readfn
= arm_cp_read_zero
, .writefn
= omap_wfi_write
, },
3917 /* TODO: Peripheral port remap register:
3918 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt controller
3919 * base address at $rn & ~0xfff and map size of 0x200 << ($rn & 0xfff),
3922 { .name
= "OMAP_CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
3923 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
3924 .type
= ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
,
3925 .writefn
= omap_cachemaint_write
},
3926 { .name
= "C9", .cp
= 15, .crn
= 9,
3927 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
,
3928 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
, .resetvalue
= 0 },
3931 static void xscale_cpar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3934 env
->cp15
.c15_cpar
= value
& 0x3fff;
3937 static const ARMCPRegInfo xscale_cp_reginfo
[] = {
3938 { .name
= "XSCALE_CPAR",
3939 .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
3940 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_cpar
), .resetvalue
= 0,
3941 .writefn
= xscale_cpar_write
, },
3942 { .name
= "XSCALE_AUXCR",
3943 .cp
= 15, .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 1, .access
= PL1_RW
,
3944 .fieldoffset
= offsetof(CPUARMState
, cp15
.c1_xscaleauxcr
),
3946 /* XScale specific cache-lockdown: since we have no cache we NOP these
3947 * and hope the guest does not really rely on cache behaviour.
3949 { .name
= "XSCALE_LOCK_ICACHE_LINE",
3950 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 0,
3951 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3952 { .name
= "XSCALE_UNLOCK_ICACHE",
3953 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 1,
3954 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3955 { .name
= "XSCALE_DCACHE_LOCK",
3956 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 0,
3957 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
3958 { .name
= "XSCALE_UNLOCK_DCACHE",
3959 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 1,
3960 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3963 static const ARMCPRegInfo dummy_c15_cp_reginfo
[] = {
3964 /* RAZ/WI the whole crn=15 space, when we don't have a more specific
3965 * implementation of this implementation-defined space.
3966 * Ideally this should eventually disappear in favour of actually
3967 * implementing the correct behaviour for all cores.
3969 { .name
= "C15_IMPDEF", .cp
= 15, .crn
= 15,
3970 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
3972 .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
| ARM_CP_OVERRIDE
,
3976 static const ARMCPRegInfo cache_dirty_status_cp_reginfo
[] = {
3977 /* Cache status: RAZ because we have no cache so it's always clean */
3978 { .name
= "CDSR", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 6,
3979 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
3983 static const ARMCPRegInfo cache_block_ops_cp_reginfo
[] = {
3984 /* We never have a block transfer operation in progress */
3985 { .name
= "BXSR", .cp
= 15, .crn
= 7, .crm
= 12, .opc1
= 0, .opc2
= 4,
3986 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
3988 /* The cache ops themselves: these all NOP for QEMU */
3989 { .name
= "IICR", .cp
= 15, .crm
= 5, .opc1
= 0,
3990 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
3991 { .name
= "IDCR", .cp
= 15, .crm
= 6, .opc1
= 0,
3992 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
3993 { .name
= "CDCR", .cp
= 15, .crm
= 12, .opc1
= 0,
3994 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
3995 { .name
= "PIR", .cp
= 15, .crm
= 12, .opc1
= 1,
3996 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
3997 { .name
= "PDR", .cp
= 15, .crm
= 12, .opc1
= 2,
3998 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
3999 { .name
= "CIDCR", .cp
= 15, .crm
= 14, .opc1
= 0,
4000 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
4003 static const ARMCPRegInfo cache_test_clean_cp_reginfo
[] = {
4004 /* The cache test-and-clean instructions always return (1 << 30)
4005 * to indicate that there are no dirty cache lines.
4007 { .name
= "TC_DCACHE", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 3,
4008 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4009 .resetvalue
= (1 << 30) },
4010 { .name
= "TCI_DCACHE", .cp
= 15, .crn
= 7, .crm
= 14, .opc1
= 0, .opc2
= 3,
4011 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4012 .resetvalue
= (1 << 30) },
4015 static const ARMCPRegInfo strongarm_cp_reginfo
[] = {
4016 /* Ignore ReadBuffer accesses */
4017 { .name
= "C9_READBUFFER", .cp
= 15, .crn
= 9,
4018 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
4019 .access
= PL1_RW
, .resetvalue
= 0,
4020 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
},
4023 static uint64_t midr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4025 unsigned int cur_el
= arm_current_el(env
);
4027 if (arm_is_el2_enabled(env
) && cur_el
== 1) {
4028 return env
->cp15
.vpidr_el2
;
4030 return raw_read(env
, ri
);
4033 static uint64_t mpidr_read_val(CPUARMState
*env
)
4035 ARMCPU
*cpu
= env_archcpu(env
);
4036 uint64_t mpidr
= cpu
->mp_affinity
;
4038 if (arm_feature(env
, ARM_FEATURE_V7MP
)) {
4039 mpidr
|= (1U << 31);
4040 /* Cores which are uniprocessor (non-coherent)
4041 * but still implement the MP extensions set
4042 * bit 30. (For instance, Cortex-R5).
4044 if (cpu
->mp_is_up
) {
4045 mpidr
|= (1u << 30);
4051 static uint64_t mpidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4053 unsigned int cur_el
= arm_current_el(env
);
4055 if (arm_is_el2_enabled(env
) && cur_el
== 1) {
4056 return env
->cp15
.vmpidr_el2
;
4058 return mpidr_read_val(env
);
4061 static const ARMCPRegInfo lpae_cp_reginfo
[] = {
4063 { .name
= "AMAIR0", .state
= ARM_CP_STATE_BOTH
,
4064 .opc0
= 3, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 0,
4065 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4066 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4067 /* AMAIR1 is mapped to AMAIR_EL1[63:32] */
4068 { .name
= "AMAIR1", .cp
= 15, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 1,
4069 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4070 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4071 { .name
= "PAR", .cp
= 15, .crm
= 7, .opc1
= 0,
4072 .access
= PL1_RW
, .type
= ARM_CP_64BIT
, .resetvalue
= 0,
4073 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.par_s
),
4074 offsetof(CPUARMState
, cp15
.par_ns
)} },
4075 { .name
= "TTBR0", .cp
= 15, .crm
= 2, .opc1
= 0,
4076 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4077 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
4078 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
4079 offsetof(CPUARMState
, cp15
.ttbr0_ns
) },
4080 .writefn
= vmsa_ttbr_write
, },
4081 { .name
= "TTBR1", .cp
= 15, .crm
= 2, .opc1
= 1,
4082 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4083 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
4084 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
4085 offsetof(CPUARMState
, cp15
.ttbr1_ns
) },
4086 .writefn
= vmsa_ttbr_write
, },
4089 static uint64_t aa64_fpcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4091 return vfp_get_fpcr(env
);
4094 static void aa64_fpcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4097 vfp_set_fpcr(env
, value
);
4100 static uint64_t aa64_fpsr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4102 return vfp_get_fpsr(env
);
4105 static void aa64_fpsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4108 vfp_set_fpsr(env
, value
);
4111 static CPAccessResult
aa64_daif_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4114 if (arm_current_el(env
) == 0 && !(arm_sctlr(env
, 0) & SCTLR_UMA
)) {
4115 return CP_ACCESS_TRAP
;
4117 return CP_ACCESS_OK
;
4120 static void aa64_daif_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4123 env
->daif
= value
& PSTATE_DAIF
;
4126 static uint64_t aa64_pan_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4128 return env
->pstate
& PSTATE_PAN
;
4131 static void aa64_pan_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4134 env
->pstate
= (env
->pstate
& ~PSTATE_PAN
) | (value
& PSTATE_PAN
);
4137 static const ARMCPRegInfo pan_reginfo
= {
4138 .name
= "PAN", .state
= ARM_CP_STATE_AA64
,
4139 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 3,
4140 .type
= ARM_CP_NO_RAW
, .access
= PL1_RW
,
4141 .readfn
= aa64_pan_read
, .writefn
= aa64_pan_write
4144 static uint64_t aa64_uao_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4146 return env
->pstate
& PSTATE_UAO
;
4149 static void aa64_uao_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4152 env
->pstate
= (env
->pstate
& ~PSTATE_UAO
) | (value
& PSTATE_UAO
);
4155 static const ARMCPRegInfo uao_reginfo
= {
4156 .name
= "UAO", .state
= ARM_CP_STATE_AA64
,
4157 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 4,
4158 .type
= ARM_CP_NO_RAW
, .access
= PL1_RW
,
4159 .readfn
= aa64_uao_read
, .writefn
= aa64_uao_write
4162 static uint64_t aa64_dit_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4164 return env
->pstate
& PSTATE_DIT
;
4167 static void aa64_dit_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4170 env
->pstate
= (env
->pstate
& ~PSTATE_DIT
) | (value
& PSTATE_DIT
);
4173 static const ARMCPRegInfo dit_reginfo
= {
4174 .name
= "DIT", .state
= ARM_CP_STATE_AA64
,
4175 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 5,
4176 .type
= ARM_CP_NO_RAW
, .access
= PL0_RW
,
4177 .readfn
= aa64_dit_read
, .writefn
= aa64_dit_write
4180 static uint64_t aa64_ssbs_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4182 return env
->pstate
& PSTATE_SSBS
;
4185 static void aa64_ssbs_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4188 env
->pstate
= (env
->pstate
& ~PSTATE_SSBS
) | (value
& PSTATE_SSBS
);
4191 static const ARMCPRegInfo ssbs_reginfo
= {
4192 .name
= "SSBS", .state
= ARM_CP_STATE_AA64
,
4193 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 6,
4194 .type
= ARM_CP_NO_RAW
, .access
= PL0_RW
,
4195 .readfn
= aa64_ssbs_read
, .writefn
= aa64_ssbs_write
4198 static CPAccessResult
aa64_cacheop_poc_access(CPUARMState
*env
,
4199 const ARMCPRegInfo
*ri
,
4202 /* Cache invalidate/clean to Point of Coherency or Persistence... */
4203 switch (arm_current_el(env
)) {
4205 /* ... EL0 must UNDEF unless SCTLR_EL1.UCI is set. */
4206 if (!(arm_sctlr(env
, 0) & SCTLR_UCI
)) {
4207 return CP_ACCESS_TRAP
;
4211 /* ... EL1 must trap to EL2 if HCR_EL2.TPCP is set. */
4212 if (arm_hcr_el2_eff(env
) & HCR_TPCP
) {
4213 return CP_ACCESS_TRAP_EL2
;
4217 return CP_ACCESS_OK
;
4220 static CPAccessResult
aa64_cacheop_pou_access(CPUARMState
*env
,
4221 const ARMCPRegInfo
*ri
,
4224 /* Cache invalidate/clean to Point of Unification... */
4225 switch (arm_current_el(env
)) {
4227 /* ... EL0 must UNDEF unless SCTLR_EL1.UCI is set. */
4228 if (!(arm_sctlr(env
, 0) & SCTLR_UCI
)) {
4229 return CP_ACCESS_TRAP
;
4233 /* ... EL1 must trap to EL2 if HCR_EL2.TPU is set. */
4234 if (arm_hcr_el2_eff(env
) & HCR_TPU
) {
4235 return CP_ACCESS_TRAP_EL2
;
4239 return CP_ACCESS_OK
;
4242 /* See: D4.7.2 TLB maintenance requirements and the TLB maintenance instructions
4243 * Page D4-1736 (DDI0487A.b)
4246 static int vae1_tlbmask(CPUARMState
*env
)
4248 uint64_t hcr
= arm_hcr_el2_eff(env
);
4251 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4252 mask
= ARMMMUIdxBit_E20_2
|
4253 ARMMMUIdxBit_E20_2_PAN
|
4256 mask
= ARMMMUIdxBit_E10_1
|
4257 ARMMMUIdxBit_E10_1_PAN
|
4261 if (arm_is_secure_below_el3(env
)) {
4262 mask
>>= ARM_MMU_IDX_A_NS
;
4268 /* Return 56 if TBI is enabled, 64 otherwise. */
4269 static int tlbbits_for_regime(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
4272 uint64_t tcr
= regime_tcr(env
, mmu_idx
);
4273 int tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
4274 int select
= extract64(addr
, 55, 1);
4276 return (tbi
>> select
) & 1 ? 56 : 64;
4279 static int vae1_tlbbits(CPUARMState
*env
, uint64_t addr
)
4281 uint64_t hcr
= arm_hcr_el2_eff(env
);
4284 /* Only the regime of the mmu_idx below is significant. */
4285 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4286 mmu_idx
= ARMMMUIdx_E20_0
;
4288 mmu_idx
= ARMMMUIdx_E10_0
;
4291 if (arm_is_secure_below_el3(env
)) {
4292 mmu_idx
&= ~ARM_MMU_IDX_A_NS
;
4295 return tlbbits_for_regime(env
, mmu_idx
, addr
);
4298 static void tlbi_aa64_vmalle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4301 CPUState
*cs
= env_cpu(env
);
4302 int mask
= vae1_tlbmask(env
);
4304 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4307 static void tlbi_aa64_vmalle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4310 CPUState
*cs
= env_cpu(env
);
4311 int mask
= vae1_tlbmask(env
);
4313 if (tlb_force_broadcast(env
)) {
4314 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4316 tlb_flush_by_mmuidx(cs
, mask
);
4320 static int alle1_tlbmask(CPUARMState
*env
)
4323 * Note that the 'ALL' scope must invalidate both stage 1 and
4324 * stage 2 translations, whereas most other scopes only invalidate
4325 * stage 1 translations.
4327 if (arm_is_secure_below_el3(env
)) {
4328 return ARMMMUIdxBit_SE10_1
|
4329 ARMMMUIdxBit_SE10_1_PAN
|
4330 ARMMMUIdxBit_SE10_0
;
4332 return ARMMMUIdxBit_E10_1
|
4333 ARMMMUIdxBit_E10_1_PAN
|
4338 static int e2_tlbmask(CPUARMState
*env
)
4340 if (arm_is_secure_below_el3(env
)) {
4341 return ARMMMUIdxBit_SE20_0
|
4342 ARMMMUIdxBit_SE20_2
|
4343 ARMMMUIdxBit_SE20_2_PAN
|
4346 return ARMMMUIdxBit_E20_0
|
4347 ARMMMUIdxBit_E20_2
|
4348 ARMMMUIdxBit_E20_2_PAN
|
4353 static void tlbi_aa64_alle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4356 CPUState
*cs
= env_cpu(env
);
4357 int mask
= alle1_tlbmask(env
);
4359 tlb_flush_by_mmuidx(cs
, mask
);
4362 static void tlbi_aa64_alle2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4365 CPUState
*cs
= env_cpu(env
);
4366 int mask
= e2_tlbmask(env
);
4368 tlb_flush_by_mmuidx(cs
, mask
);
4371 static void tlbi_aa64_alle3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4374 ARMCPU
*cpu
= env_archcpu(env
);
4375 CPUState
*cs
= CPU(cpu
);
4377 tlb_flush_by_mmuidx(cs
, ARMMMUIdxBit_SE3
);
4380 static void tlbi_aa64_alle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4383 CPUState
*cs
= env_cpu(env
);
4384 int mask
= alle1_tlbmask(env
);
4386 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4389 static void tlbi_aa64_alle2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4392 CPUState
*cs
= env_cpu(env
);
4393 int mask
= e2_tlbmask(env
);
4395 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4398 static void tlbi_aa64_alle3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4401 CPUState
*cs
= env_cpu(env
);
4403 tlb_flush_by_mmuidx_all_cpus_synced(cs
, ARMMMUIdxBit_SE3
);
4406 static void tlbi_aa64_vae2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4409 /* Invalidate by VA, EL2
4410 * Currently handles both VAE2 and VALE2, since we don't support
4411 * flush-last-level-only.
4413 CPUState
*cs
= env_cpu(env
);
4414 int mask
= e2_tlbmask(env
);
4415 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4417 tlb_flush_page_by_mmuidx(cs
, pageaddr
, mask
);
4420 static void tlbi_aa64_vae3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4423 /* Invalidate by VA, EL3
4424 * Currently handles both VAE3 and VALE3, since we don't support
4425 * flush-last-level-only.
4427 ARMCPU
*cpu
= env_archcpu(env
);
4428 CPUState
*cs
= CPU(cpu
);
4429 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4431 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_SE3
);
4434 static void tlbi_aa64_vae1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4437 CPUState
*cs
= env_cpu(env
);
4438 int mask
= vae1_tlbmask(env
);
4439 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4440 int bits
= vae1_tlbbits(env
, pageaddr
);
4442 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4445 static void tlbi_aa64_vae1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4448 /* Invalidate by VA, EL1&0 (AArch64 version).
4449 * Currently handles all of VAE1, VAAE1, VAALE1 and VALE1,
4450 * since we don't support flush-for-specific-ASID-only or
4451 * flush-last-level-only.
4453 CPUState
*cs
= env_cpu(env
);
4454 int mask
= vae1_tlbmask(env
);
4455 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4456 int bits
= vae1_tlbbits(env
, pageaddr
);
4458 if (tlb_force_broadcast(env
)) {
4459 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4461 tlb_flush_page_bits_by_mmuidx(cs
, pageaddr
, mask
, bits
);
4465 static void tlbi_aa64_vae2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4468 CPUState
*cs
= env_cpu(env
);
4469 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4470 bool secure
= arm_is_secure_below_el3(env
);
4471 int mask
= secure
? ARMMMUIdxBit_SE2
: ARMMMUIdxBit_E2
;
4472 int bits
= tlbbits_for_regime(env
, secure
? ARMMMUIdx_SE2
: ARMMMUIdx_E2
,
4475 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4478 static void tlbi_aa64_vae3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4481 CPUState
*cs
= env_cpu(env
);
4482 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4483 int bits
= tlbbits_for_regime(env
, ARMMMUIdx_SE3
, pageaddr
);
4485 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
,
4486 ARMMMUIdxBit_SE3
, bits
);
4489 #ifdef TARGET_AARCH64
4495 static TLBIRange
tlbi_aa64_get_range(CPUARMState
*env
, ARMMMUIdx mmuidx
,
4498 unsigned int page_size_granule
, page_shift
, num
, scale
, exponent
;
4499 /* Extract one bit to represent the va selector in use. */
4500 uint64_t select
= sextract64(value
, 36, 1);
4501 ARMVAParameters param
= aa64_va_parameters(env
, select
, mmuidx
, true);
4502 TLBIRange ret
= { };
4504 page_size_granule
= extract64(value
, 46, 2);
4506 /* The granule encoded in value must match the granule in use. */
4507 if (page_size_granule
!= (param
.using64k
? 3 : param
.using16k
? 2 : 1)) {
4508 qemu_log_mask(LOG_GUEST_ERROR
, "Invalid tlbi page size granule %d\n",
4513 page_shift
= (page_size_granule
- 1) * 2 + 12;
4514 num
= extract64(value
, 39, 5);
4515 scale
= extract64(value
, 44, 2);
4516 exponent
= (5 * scale
) + 1;
4518 ret
.length
= (num
+ 1) << (exponent
+ page_shift
);
4521 ret
.base
= sextract64(value
, 0, 37);
4523 ret
.base
= extract64(value
, 0, 37);
4527 * With DS=1, BaseADDR is always shifted 16 so that it is able
4528 * to address all 52 va bits. The input address is perforce
4529 * aligned on a 64k boundary regardless of translation granule.
4533 ret
.base
<<= page_shift
;
4538 static void do_rvae_write(CPUARMState
*env
, uint64_t value
,
4539 int idxmap
, bool synced
)
4541 ARMMMUIdx one_idx
= ARM_MMU_IDX_A
| ctz32(idxmap
);
4545 range
= tlbi_aa64_get_range(env
, one_idx
, value
);
4546 bits
= tlbbits_for_regime(env
, one_idx
, range
.base
);
4549 tlb_flush_range_by_mmuidx_all_cpus_synced(env_cpu(env
),
4555 tlb_flush_range_by_mmuidx(env_cpu(env
), range
.base
,
4556 range
.length
, idxmap
, bits
);
4560 static void tlbi_aa64_rvae1_write(CPUARMState
*env
,
4561 const ARMCPRegInfo
*ri
,
4565 * Invalidate by VA range, EL1&0.
4566 * Currently handles all of RVAE1, RVAAE1, RVAALE1 and RVALE1,
4567 * since we don't support flush-for-specific-ASID-only or
4568 * flush-last-level-only.
4571 do_rvae_write(env
, value
, vae1_tlbmask(env
),
4572 tlb_force_broadcast(env
));
4575 static void tlbi_aa64_rvae1is_write(CPUARMState
*env
,
4576 const ARMCPRegInfo
*ri
,
4580 * Invalidate by VA range, Inner/Outer Shareable EL1&0.
4581 * Currently handles all of RVAE1IS, RVAE1OS, RVAAE1IS, RVAAE1OS,
4582 * RVAALE1IS, RVAALE1OS, RVALE1IS and RVALE1OS, since we don't support
4583 * flush-for-specific-ASID-only, flush-last-level-only or inner/outer
4584 * shareable specific flushes.
4587 do_rvae_write(env
, value
, vae1_tlbmask(env
), true);
4590 static int vae2_tlbmask(CPUARMState
*env
)
4592 return (arm_is_secure_below_el3(env
)
4593 ? ARMMMUIdxBit_SE2
: ARMMMUIdxBit_E2
);
4596 static void tlbi_aa64_rvae2_write(CPUARMState
*env
,
4597 const ARMCPRegInfo
*ri
,
4601 * Invalidate by VA range, EL2.
4602 * Currently handles all of RVAE2 and RVALE2,
4603 * since we don't support flush-for-specific-ASID-only or
4604 * flush-last-level-only.
4607 do_rvae_write(env
, value
, vae2_tlbmask(env
),
4608 tlb_force_broadcast(env
));
4613 static void tlbi_aa64_rvae2is_write(CPUARMState
*env
,
4614 const ARMCPRegInfo
*ri
,
4618 * Invalidate by VA range, Inner/Outer Shareable, EL2.
4619 * Currently handles all of RVAE2IS, RVAE2OS, RVALE2IS and RVALE2OS,
4620 * since we don't support flush-for-specific-ASID-only,
4621 * flush-last-level-only or inner/outer shareable specific flushes.
4624 do_rvae_write(env
, value
, vae2_tlbmask(env
), true);
4628 static void tlbi_aa64_rvae3_write(CPUARMState
*env
,
4629 const ARMCPRegInfo
*ri
,
4633 * Invalidate by VA range, EL3.
4634 * Currently handles all of RVAE3 and RVALE3,
4635 * since we don't support flush-for-specific-ASID-only or
4636 * flush-last-level-only.
4639 do_rvae_write(env
, value
, ARMMMUIdxBit_SE3
,
4640 tlb_force_broadcast(env
));
4643 static void tlbi_aa64_rvae3is_write(CPUARMState
*env
,
4644 const ARMCPRegInfo
*ri
,
4648 * Invalidate by VA range, EL3, Inner/Outer Shareable.
4649 * Currently handles all of RVAE3IS, RVAE3OS, RVALE3IS and RVALE3OS,
4650 * since we don't support flush-for-specific-ASID-only,
4651 * flush-last-level-only or inner/outer specific flushes.
4654 do_rvae_write(env
, value
, ARMMMUIdxBit_SE3
, true);
4658 static CPAccessResult
aa64_zva_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4661 int cur_el
= arm_current_el(env
);
4664 uint64_t hcr
= arm_hcr_el2_eff(env
);
4667 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4668 if (!(env
->cp15
.sctlr_el
[2] & SCTLR_DZE
)) {
4669 return CP_ACCESS_TRAP_EL2
;
4672 if (!(env
->cp15
.sctlr_el
[1] & SCTLR_DZE
)) {
4673 return CP_ACCESS_TRAP
;
4675 if (hcr
& HCR_TDZ
) {
4676 return CP_ACCESS_TRAP_EL2
;
4679 } else if (hcr
& HCR_TDZ
) {
4680 return CP_ACCESS_TRAP_EL2
;
4683 return CP_ACCESS_OK
;
4686 static uint64_t aa64_dczid_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4688 ARMCPU
*cpu
= env_archcpu(env
);
4689 int dzp_bit
= 1 << 4;
4691 /* DZP indicates whether DC ZVA access is allowed */
4692 if (aa64_zva_access(env
, NULL
, false) == CP_ACCESS_OK
) {
4695 return cpu
->dcz_blocksize
| dzp_bit
;
4698 static CPAccessResult
sp_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4701 if (!(env
->pstate
& PSTATE_SP
)) {
4702 /* Access to SP_EL0 is undefined if it's being used as
4703 * the stack pointer.
4705 return CP_ACCESS_TRAP_UNCATEGORIZED
;
4707 return CP_ACCESS_OK
;
4710 static uint64_t spsel_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4712 return env
->pstate
& PSTATE_SP
;
4715 static void spsel_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
4717 update_spsel(env
, val
);
4720 static void sctlr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4723 ARMCPU
*cpu
= env_archcpu(env
);
4725 if (arm_feature(env
, ARM_FEATURE_PMSA
) && !cpu
->has_mpu
) {
4726 /* M bit is RAZ/WI for PMSA with no MPU implemented */
4730 /* ??? Lots of these bits are not implemented. */
4732 if (ri
->state
== ARM_CP_STATE_AA64
&& !cpu_isar_feature(aa64_mte
, cpu
)) {
4733 if (ri
->opc1
== 6) { /* SCTLR_EL3 */
4734 value
&= ~(SCTLR_ITFSB
| SCTLR_TCF
| SCTLR_ATA
);
4736 value
&= ~(SCTLR_ITFSB
| SCTLR_TCF0
| SCTLR_TCF
|
4737 SCTLR_ATA0
| SCTLR_ATA
);
4741 if (raw_read(env
, ri
) == value
) {
4742 /* Skip the TLB flush if nothing actually changed; Linux likes
4743 * to do a lot of pointless SCTLR writes.
4748 raw_write(env
, ri
, value
);
4750 /* This may enable/disable the MMU, so do a TLB flush. */
4751 tlb_flush(CPU(cpu
));
4753 if (ri
->type
& ARM_CP_SUPPRESS_TB_END
) {
4755 * Normally we would always end the TB on an SCTLR write; see the
4756 * comment in ARMCPRegInfo sctlr initialization below for why Xscale
4757 * is special. Setting ARM_CP_SUPPRESS_TB_END also stops the rebuild
4758 * of hflags from the translator, so do it here.
4760 arm_rebuild_hflags(env
);
4764 static void sdcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4768 * Some MDCR_EL3 bits affect whether PMU counters are running:
4769 * if we are trying to change any of those then we must
4770 * bracket this update with PMU start/finish calls.
4772 bool pmu_op
= (env
->cp15
.mdcr_el3
^ value
) & MDCR_EL3_PMU_ENABLE_BITS
;
4777 env
->cp15
.mdcr_el3
= value
& SDCR_VALID_MASK
;
4783 static void mdcr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4787 * Some MDCR_EL2 bits affect whether PMU counters are running:
4788 * if we are trying to change any of those then we must
4789 * bracket this update with PMU start/finish calls.
4791 bool pmu_op
= (env
->cp15
.mdcr_el2
^ value
) & MDCR_EL2_PMU_ENABLE_BITS
;
4796 env
->cp15
.mdcr_el2
= value
;
4802 static const ARMCPRegInfo v8_cp_reginfo
[] = {
4803 /* Minimal set of EL0-visible registers. This will need to be expanded
4804 * significantly for system emulation of AArch64 CPUs.
4806 { .name
= "NZCV", .state
= ARM_CP_STATE_AA64
,
4807 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 2,
4808 .access
= PL0_RW
, .type
= ARM_CP_NZCV
},
4809 { .name
= "DAIF", .state
= ARM_CP_STATE_AA64
,
4810 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 2,
4811 .type
= ARM_CP_NO_RAW
,
4812 .access
= PL0_RW
, .accessfn
= aa64_daif_access
,
4813 .fieldoffset
= offsetof(CPUARMState
, daif
),
4814 .writefn
= aa64_daif_write
, .resetfn
= arm_cp_reset_ignore
},
4815 { .name
= "FPCR", .state
= ARM_CP_STATE_AA64
,
4816 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 4,
4817 .access
= PL0_RW
, .type
= ARM_CP_FPU
| ARM_CP_SUPPRESS_TB_END
,
4818 .readfn
= aa64_fpcr_read
, .writefn
= aa64_fpcr_write
},
4819 { .name
= "FPSR", .state
= ARM_CP_STATE_AA64
,
4820 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 4,
4821 .access
= PL0_RW
, .type
= ARM_CP_FPU
| ARM_CP_SUPPRESS_TB_END
,
4822 .readfn
= aa64_fpsr_read
, .writefn
= aa64_fpsr_write
},
4823 { .name
= "DCZID_EL0", .state
= ARM_CP_STATE_AA64
,
4824 .opc0
= 3, .opc1
= 3, .opc2
= 7, .crn
= 0, .crm
= 0,
4825 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
,
4826 .readfn
= aa64_dczid_read
},
4827 { .name
= "DC_ZVA", .state
= ARM_CP_STATE_AA64
,
4828 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 1,
4829 .access
= PL0_W
, .type
= ARM_CP_DC_ZVA
,
4830 #ifndef CONFIG_USER_ONLY
4831 /* Avoid overhead of an access check that always passes in user-mode */
4832 .accessfn
= aa64_zva_access
,
4835 { .name
= "CURRENTEL", .state
= ARM_CP_STATE_AA64
,
4836 .opc0
= 3, .opc1
= 0, .opc2
= 2, .crn
= 4, .crm
= 2,
4837 .access
= PL1_R
, .type
= ARM_CP_CURRENTEL
},
4838 /* Cache ops: all NOPs since we don't emulate caches */
4839 { .name
= "IC_IALLUIS", .state
= ARM_CP_STATE_AA64
,
4840 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
4841 .access
= PL1_W
, .type
= ARM_CP_NOP
,
4842 .accessfn
= aa64_cacheop_pou_access
},
4843 { .name
= "IC_IALLU", .state
= ARM_CP_STATE_AA64
,
4844 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
4845 .access
= PL1_W
, .type
= ARM_CP_NOP
,
4846 .accessfn
= aa64_cacheop_pou_access
},
4847 { .name
= "IC_IVAU", .state
= ARM_CP_STATE_AA64
,
4848 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 5, .opc2
= 1,
4849 .access
= PL0_W
, .type
= ARM_CP_NOP
,
4850 .accessfn
= aa64_cacheop_pou_access
},
4851 { .name
= "DC_IVAC", .state
= ARM_CP_STATE_AA64
,
4852 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
4853 .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
,
4854 .type
= ARM_CP_NOP
},
4855 { .name
= "DC_ISW", .state
= ARM_CP_STATE_AA64
,
4856 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
4857 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
4858 { .name
= "DC_CVAC", .state
= ARM_CP_STATE_AA64
,
4859 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 1,
4860 .access
= PL0_W
, .type
= ARM_CP_NOP
,
4861 .accessfn
= aa64_cacheop_poc_access
},
4862 { .name
= "DC_CSW", .state
= ARM_CP_STATE_AA64
,
4863 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
4864 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
4865 { .name
= "DC_CVAU", .state
= ARM_CP_STATE_AA64
,
4866 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 11, .opc2
= 1,
4867 .access
= PL0_W
, .type
= ARM_CP_NOP
,
4868 .accessfn
= aa64_cacheop_pou_access
},
4869 { .name
= "DC_CIVAC", .state
= ARM_CP_STATE_AA64
,
4870 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 1,
4871 .access
= PL0_W
, .type
= ARM_CP_NOP
,
4872 .accessfn
= aa64_cacheop_poc_access
},
4873 { .name
= "DC_CISW", .state
= ARM_CP_STATE_AA64
,
4874 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
4875 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
4876 /* TLBI operations */
4877 { .name
= "TLBI_VMALLE1IS", .state
= ARM_CP_STATE_AA64
,
4878 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
4879 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4880 .writefn
= tlbi_aa64_vmalle1is_write
},
4881 { .name
= "TLBI_VAE1IS", .state
= ARM_CP_STATE_AA64
,
4882 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
4883 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4884 .writefn
= tlbi_aa64_vae1is_write
},
4885 { .name
= "TLBI_ASIDE1IS", .state
= ARM_CP_STATE_AA64
,
4886 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
4887 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4888 .writefn
= tlbi_aa64_vmalle1is_write
},
4889 { .name
= "TLBI_VAAE1IS", .state
= ARM_CP_STATE_AA64
,
4890 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
4891 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4892 .writefn
= tlbi_aa64_vae1is_write
},
4893 { .name
= "TLBI_VALE1IS", .state
= ARM_CP_STATE_AA64
,
4894 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
4895 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4896 .writefn
= tlbi_aa64_vae1is_write
},
4897 { .name
= "TLBI_VAALE1IS", .state
= ARM_CP_STATE_AA64
,
4898 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
4899 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4900 .writefn
= tlbi_aa64_vae1is_write
},
4901 { .name
= "TLBI_VMALLE1", .state
= ARM_CP_STATE_AA64
,
4902 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
4903 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4904 .writefn
= tlbi_aa64_vmalle1_write
},
4905 { .name
= "TLBI_VAE1", .state
= ARM_CP_STATE_AA64
,
4906 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
4907 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4908 .writefn
= tlbi_aa64_vae1_write
},
4909 { .name
= "TLBI_ASIDE1", .state
= ARM_CP_STATE_AA64
,
4910 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
4911 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4912 .writefn
= tlbi_aa64_vmalle1_write
},
4913 { .name
= "TLBI_VAAE1", .state
= ARM_CP_STATE_AA64
,
4914 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
4915 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4916 .writefn
= tlbi_aa64_vae1_write
},
4917 { .name
= "TLBI_VALE1", .state
= ARM_CP_STATE_AA64
,
4918 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
4919 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4920 .writefn
= tlbi_aa64_vae1_write
},
4921 { .name
= "TLBI_VAALE1", .state
= ARM_CP_STATE_AA64
,
4922 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
4923 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
4924 .writefn
= tlbi_aa64_vae1_write
},
4925 { .name
= "TLBI_IPAS2E1IS", .state
= ARM_CP_STATE_AA64
,
4926 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
4927 .access
= PL2_W
, .type
= ARM_CP_NOP
},
4928 { .name
= "TLBI_IPAS2LE1IS", .state
= ARM_CP_STATE_AA64
,
4929 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
4930 .access
= PL2_W
, .type
= ARM_CP_NOP
},
4931 { .name
= "TLBI_ALLE1IS", .state
= ARM_CP_STATE_AA64
,
4932 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
4933 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
4934 .writefn
= tlbi_aa64_alle1is_write
},
4935 { .name
= "TLBI_VMALLS12E1IS", .state
= ARM_CP_STATE_AA64
,
4936 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 6,
4937 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
4938 .writefn
= tlbi_aa64_alle1is_write
},
4939 { .name
= "TLBI_IPAS2E1", .state
= ARM_CP_STATE_AA64
,
4940 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
4941 .access
= PL2_W
, .type
= ARM_CP_NOP
},
4942 { .name
= "TLBI_IPAS2LE1", .state
= ARM_CP_STATE_AA64
,
4943 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
4944 .access
= PL2_W
, .type
= ARM_CP_NOP
},
4945 { .name
= "TLBI_ALLE1", .state
= ARM_CP_STATE_AA64
,
4946 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
4947 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
4948 .writefn
= tlbi_aa64_alle1_write
},
4949 { .name
= "TLBI_VMALLS12E1", .state
= ARM_CP_STATE_AA64
,
4950 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 6,
4951 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
4952 .writefn
= tlbi_aa64_alle1is_write
},
4953 #ifndef CONFIG_USER_ONLY
4954 /* 64 bit address translation operations */
4955 { .name
= "AT_S1E1R", .state
= ARM_CP_STATE_AA64
,
4956 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 0,
4957 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4958 .writefn
= ats_write64
},
4959 { .name
= "AT_S1E1W", .state
= ARM_CP_STATE_AA64
,
4960 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 1,
4961 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4962 .writefn
= ats_write64
},
4963 { .name
= "AT_S1E0R", .state
= ARM_CP_STATE_AA64
,
4964 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 2,
4965 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4966 .writefn
= ats_write64
},
4967 { .name
= "AT_S1E0W", .state
= ARM_CP_STATE_AA64
,
4968 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 3,
4969 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4970 .writefn
= ats_write64
},
4971 { .name
= "AT_S12E1R", .state
= ARM_CP_STATE_AA64
,
4972 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 4,
4973 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4974 .writefn
= ats_write64
},
4975 { .name
= "AT_S12E1W", .state
= ARM_CP_STATE_AA64
,
4976 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 5,
4977 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4978 .writefn
= ats_write64
},
4979 { .name
= "AT_S12E0R", .state
= ARM_CP_STATE_AA64
,
4980 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 6,
4981 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4982 .writefn
= ats_write64
},
4983 { .name
= "AT_S12E0W", .state
= ARM_CP_STATE_AA64
,
4984 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 7,
4985 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4986 .writefn
= ats_write64
},
4987 /* AT S1E2* are elsewhere as they UNDEF from EL3 if EL2 is not present */
4988 { .name
= "AT_S1E3R", .state
= ARM_CP_STATE_AA64
,
4989 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 0,
4990 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4991 .writefn
= ats_write64
},
4992 { .name
= "AT_S1E3W", .state
= ARM_CP_STATE_AA64
,
4993 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 1,
4994 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
4995 .writefn
= ats_write64
},
4996 { .name
= "PAR_EL1", .state
= ARM_CP_STATE_AA64
,
4997 .type
= ARM_CP_ALIAS
,
4998 .opc0
= 3, .opc1
= 0, .crn
= 7, .crm
= 4, .opc2
= 0,
4999 .access
= PL1_RW
, .resetvalue
= 0,
5000 .fieldoffset
= offsetof(CPUARMState
, cp15
.par_el
[1]),
5001 .writefn
= par_write
},
5003 /* TLB invalidate last level of translation table walk */
5004 { .name
= "TLBIMVALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
5005 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5006 .writefn
= tlbimva_is_write
},
5007 { .name
= "TLBIMVAALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
5008 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5009 .writefn
= tlbimvaa_is_write
},
5010 { .name
= "TLBIMVAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
5011 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5012 .writefn
= tlbimva_write
},
5013 { .name
= "TLBIMVAAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
5014 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5015 .writefn
= tlbimvaa_write
},
5016 { .name
= "TLBIMVALH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
5017 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5018 .writefn
= tlbimva_hyp_write
},
5019 { .name
= "TLBIMVALHIS",
5020 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
5021 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5022 .writefn
= tlbimva_hyp_is_write
},
5023 { .name
= "TLBIIPAS2",
5024 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
5025 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5026 { .name
= "TLBIIPAS2IS",
5027 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
5028 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5029 { .name
= "TLBIIPAS2L",
5030 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
5031 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5032 { .name
= "TLBIIPAS2LIS",
5033 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
5034 .type
= ARM_CP_NOP
, .access
= PL2_W
},
5035 /* 32 bit cache operations */
5036 { .name
= "ICIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
5037 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5038 { .name
= "BPIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 6,
5039 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5040 { .name
= "ICIALLU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
5041 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5042 { .name
= "ICIMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 1,
5043 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5044 { .name
= "BPIALL", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 6,
5045 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5046 { .name
= "BPIMVA", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 7,
5047 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5048 { .name
= "DCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
5049 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5050 { .name
= "DCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
5051 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5052 { .name
= "DCCMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 1,
5053 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5054 { .name
= "DCCSW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
5055 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5056 { .name
= "DCCMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 11, .opc2
= 1,
5057 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_pou_access
},
5058 { .name
= "DCCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 1,
5059 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5060 { .name
= "DCCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
5061 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5062 /* MMU Domain access control / MPU write buffer control */
5063 { .name
= "DACR", .cp
= 15, .opc1
= 0, .crn
= 3, .crm
= 0, .opc2
= 0,
5064 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
5065 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
5066 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
5067 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
5068 { .name
= "ELR_EL1", .state
= ARM_CP_STATE_AA64
,
5069 .type
= ARM_CP_ALIAS
,
5070 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 1,
5072 .fieldoffset
= offsetof(CPUARMState
, elr_el
[1]) },
5073 { .name
= "SPSR_EL1", .state
= ARM_CP_STATE_AA64
,
5074 .type
= ARM_CP_ALIAS
,
5075 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 0,
5077 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_SVC
]) },
5078 /* We rely on the access checks not allowing the guest to write to the
5079 * state field when SPSel indicates that it's being used as the stack
5082 { .name
= "SP_EL0", .state
= ARM_CP_STATE_AA64
,
5083 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 1, .opc2
= 0,
5084 .access
= PL1_RW
, .accessfn
= sp_el0_access
,
5085 .type
= ARM_CP_ALIAS
,
5086 .fieldoffset
= offsetof(CPUARMState
, sp_el
[0]) },
5087 { .name
= "SP_EL1", .state
= ARM_CP_STATE_AA64
,
5088 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 1, .opc2
= 0,
5089 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
,
5090 .fieldoffset
= offsetof(CPUARMState
, sp_el
[1]) },
5091 { .name
= "SPSel", .state
= ARM_CP_STATE_AA64
,
5092 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 0,
5093 .type
= ARM_CP_NO_RAW
,
5094 .access
= PL1_RW
, .readfn
= spsel_read
, .writefn
= spsel_write
},
5095 { .name
= "FPEXC32_EL2", .state
= ARM_CP_STATE_AA64
,
5096 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 3, .opc2
= 0,
5098 .type
= ARM_CP_ALIAS
| ARM_CP_FPU
| ARM_CP_EL3_NO_EL2_KEEP
,
5099 .fieldoffset
= offsetof(CPUARMState
, vfp
.xregs
[ARM_VFP_FPEXC
]) },
5100 { .name
= "DACR32_EL2", .state
= ARM_CP_STATE_AA64
,
5101 .opc0
= 3, .opc1
= 4, .crn
= 3, .crm
= 0, .opc2
= 0,
5102 .access
= PL2_RW
, .resetvalue
= 0, .type
= ARM_CP_EL3_NO_EL2_KEEP
,
5103 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
5104 .fieldoffset
= offsetof(CPUARMState
, cp15
.dacr32_el2
) },
5105 { .name
= "IFSR32_EL2", .state
= ARM_CP_STATE_AA64
,
5106 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 0, .opc2
= 1,
5107 .access
= PL2_RW
, .resetvalue
= 0, .type
= ARM_CP_EL3_NO_EL2_KEEP
,
5108 .fieldoffset
= offsetof(CPUARMState
, cp15
.ifsr32_el2
) },
5109 { .name
= "SPSR_IRQ", .state
= ARM_CP_STATE_AA64
,
5110 .type
= ARM_CP_ALIAS
,
5111 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 0,
5113 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_IRQ
]) },
5114 { .name
= "SPSR_ABT", .state
= ARM_CP_STATE_AA64
,
5115 .type
= ARM_CP_ALIAS
,
5116 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 1,
5118 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_ABT
]) },
5119 { .name
= "SPSR_UND", .state
= ARM_CP_STATE_AA64
,
5120 .type
= ARM_CP_ALIAS
,
5121 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 2,
5123 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_UND
]) },
5124 { .name
= "SPSR_FIQ", .state
= ARM_CP_STATE_AA64
,
5125 .type
= ARM_CP_ALIAS
,
5126 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 3,
5128 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_FIQ
]) },
5129 { .name
= "MDCR_EL3", .state
= ARM_CP_STATE_AA64
,
5130 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 3, .opc2
= 1,
5132 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el3
) },
5133 { .name
= "SDCR", .type
= ARM_CP_ALIAS
,
5134 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 3, .opc2
= 1,
5135 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
5136 .writefn
= sdcr_write
,
5137 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.mdcr_el3
) },
5140 static void do_hcr_write(CPUARMState
*env
, uint64_t value
, uint64_t valid_mask
)
5142 ARMCPU
*cpu
= env_archcpu(env
);
5144 if (arm_feature(env
, ARM_FEATURE_V8
)) {
5145 valid_mask
|= MAKE_64BIT_MASK(0, 34); /* ARMv8.0 */
5147 valid_mask
|= MAKE_64BIT_MASK(0, 28); /* ARMv7VE */
5150 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
5151 valid_mask
&= ~HCR_HCD
;
5152 } else if (cpu
->psci_conduit
!= QEMU_PSCI_CONDUIT_SMC
) {
5153 /* Architecturally HCR.TSC is RES0 if EL3 is not implemented.
5154 * However, if we're using the SMC PSCI conduit then QEMU is
5155 * effectively acting like EL3 firmware and so the guest at
5156 * EL2 should retain the ability to prevent EL1 from being
5157 * able to make SMC calls into the ersatz firmware, so in
5158 * that case HCR.TSC should be read/write.
5160 valid_mask
&= ~HCR_TSC
;
5163 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
5164 if (cpu_isar_feature(aa64_vh
, cpu
)) {
5165 valid_mask
|= HCR_E2H
;
5167 if (cpu_isar_feature(aa64_ras
, cpu
)) {
5168 valid_mask
|= HCR_TERR
| HCR_TEA
;
5170 if (cpu_isar_feature(aa64_lor
, cpu
)) {
5171 valid_mask
|= HCR_TLOR
;
5173 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
5174 valid_mask
|= HCR_API
| HCR_APK
;
5176 if (cpu_isar_feature(aa64_mte
, cpu
)) {
5177 valid_mask
|= HCR_ATA
| HCR_DCT
| HCR_TID5
;
5179 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
5180 valid_mask
|= HCR_ENSCXT
;
5182 if (cpu_isar_feature(aa64_fwb
, cpu
)) {
5183 valid_mask
|= HCR_FWB
;
5187 /* Clear RES0 bits. */
5188 value
&= valid_mask
;
5191 * These bits change the MMU setup:
5192 * HCR_VM enables stage 2 translation
5193 * HCR_PTW forbids certain page-table setups
5194 * HCR_DC disables stage1 and enables stage2 translation
5195 * HCR_DCT enables tagging on (disabled) stage1 translation
5196 * HCR_FWB changes the interpretation of stage2 descriptor bits
5198 if ((env
->cp15
.hcr_el2
^ value
) &
5199 (HCR_VM
| HCR_PTW
| HCR_DC
| HCR_DCT
| HCR_FWB
)) {
5200 tlb_flush(CPU(cpu
));
5202 env
->cp15
.hcr_el2
= value
;
5205 * Updates to VI and VF require us to update the status of
5206 * virtual interrupts, which are the logical OR of these bits
5207 * and the state of the input lines from the GIC. (This requires
5208 * that we have the iothread lock, which is done by marking the
5209 * reginfo structs as ARM_CP_IO.)
5210 * Note that if a write to HCR pends a VIRQ or VFIQ it is never
5211 * possible for it to be taken immediately, because VIRQ and
5212 * VFIQ are masked unless running at EL0 or EL1, and HCR
5213 * can only be written at EL2.
5215 g_assert(qemu_mutex_iothread_locked());
5216 arm_cpu_update_virq(cpu
);
5217 arm_cpu_update_vfiq(cpu
);
5218 arm_cpu_update_vserr(cpu
);
5221 static void hcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
5223 do_hcr_write(env
, value
, 0);
5226 static void hcr_writehigh(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5229 /* Handle HCR2 write, i.e. write to high half of HCR_EL2 */
5230 value
= deposit64(env
->cp15
.hcr_el2
, 32, 32, value
);
5231 do_hcr_write(env
, value
, MAKE_64BIT_MASK(0, 32));
5234 static void hcr_writelow(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5237 /* Handle HCR write, i.e. write to low half of HCR_EL2 */
5238 value
= deposit64(env
->cp15
.hcr_el2
, 0, 32, value
);
5239 do_hcr_write(env
, value
, MAKE_64BIT_MASK(32, 32));
5243 * Return the effective value of HCR_EL2.
5244 * Bits that are not included here:
5245 * RW (read from SCR_EL3.RW as needed)
5247 uint64_t arm_hcr_el2_eff(CPUARMState
*env
)
5249 uint64_t ret
= env
->cp15
.hcr_el2
;
5251 if (!arm_is_el2_enabled(env
)) {
5253 * "This register has no effect if EL2 is not enabled in the
5254 * current Security state". This is ARMv8.4-SecEL2 speak for
5255 * !(SCR_EL3.NS==1 || SCR_EL3.EEL2==1).
5257 * Prior to that, the language was "In an implementation that
5258 * includes EL3, when the value of SCR_EL3.NS is 0 the PE behaves
5259 * as if this field is 0 for all purposes other than a direct
5260 * read or write access of HCR_EL2". With lots of enumeration
5261 * on a per-field basis. In current QEMU, this is condition
5262 * is arm_is_secure_below_el3.
5264 * Since the v8.4 language applies to the entire register, and
5265 * appears to be backward compatible, use that.
5271 * For a cpu that supports both aarch64 and aarch32, we can set bits
5272 * in HCR_EL2 (e.g. via EL3) that are RES0 when we enter EL2 as aa32.
5273 * Ignore all of the bits in HCR+HCR2 that are not valid for aarch32.
5275 if (!arm_el_is_aa64(env
, 2)) {
5276 uint64_t aa32_valid
;
5279 * These bits are up-to-date as of ARMv8.6.
5280 * For HCR, it's easiest to list just the 2 bits that are invalid.
5281 * For HCR2, list those that are valid.
5283 aa32_valid
= MAKE_64BIT_MASK(0, 32) & ~(HCR_RW
| HCR_TDZ
);
5284 aa32_valid
|= (HCR_CD
| HCR_ID
| HCR_TERR
| HCR_TEA
| HCR_MIOCNCE
|
5285 HCR_TID4
| HCR_TICAB
| HCR_TOCU
| HCR_TTLBIS
);
5289 if (ret
& HCR_TGE
) {
5290 /* These bits are up-to-date as of ARMv8.6. */
5291 if (ret
& HCR_E2H
) {
5292 ret
&= ~(HCR_VM
| HCR_FMO
| HCR_IMO
| HCR_AMO
|
5293 HCR_BSU_MASK
| HCR_DC
| HCR_TWI
| HCR_TWE
|
5294 HCR_TID0
| HCR_TID2
| HCR_TPCP
| HCR_TPU
|
5295 HCR_TDZ
| HCR_CD
| HCR_ID
| HCR_MIOCNCE
|
5296 HCR_TID4
| HCR_TICAB
| HCR_TOCU
| HCR_ENSCXT
|
5297 HCR_TTLBIS
| HCR_TTLBOS
| HCR_TID5
);
5299 ret
|= HCR_FMO
| HCR_IMO
| HCR_AMO
;
5301 ret
&= ~(HCR_SWIO
| HCR_PTW
| HCR_VF
| HCR_VI
| HCR_VSE
|
5302 HCR_FB
| HCR_TID1
| HCR_TID3
| HCR_TSC
| HCR_TACR
|
5303 HCR_TSW
| HCR_TTLB
| HCR_TVM
| HCR_HCD
| HCR_TRVM
|
5311 * Corresponds to ARM pseudocode function ELIsInHost().
5313 bool el_is_in_host(CPUARMState
*env
, int el
)
5318 * Since we only care about E2H and TGE, we can skip arm_hcr_el2_eff().
5319 * Perform the simplest bit tests first, and validate EL2 afterward.
5322 return false; /* EL1 or EL3 */
5326 * Note that hcr_write() checks isar_feature_aa64_vh(),
5327 * aka HaveVirtHostExt(), in allowing HCR_E2H to be set.
5329 mask
= el
? HCR_E2H
: HCR_E2H
| HCR_TGE
;
5330 if ((env
->cp15
.hcr_el2
& mask
) != mask
) {
5334 /* TGE and/or E2H set: double check those bits are currently legal. */
5335 return arm_is_el2_enabled(env
) && arm_el_is_aa64(env
, 2);
5338 static void hcrx_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5341 uint64_t valid_mask
= 0;
5343 /* No features adding bits to HCRX are implemented. */
5345 /* Clear RES0 bits. */
5346 env
->cp15
.hcrx_el2
= value
& valid_mask
;
5349 static CPAccessResult
access_hxen(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5352 if (arm_current_el(env
) < 3
5353 && arm_feature(env
, ARM_FEATURE_EL3
)
5354 && !(env
->cp15
.scr_el3
& SCR_HXEN
)) {
5355 return CP_ACCESS_TRAP_EL3
;
5357 return CP_ACCESS_OK
;
5360 static const ARMCPRegInfo hcrx_el2_reginfo
= {
5361 .name
= "HCRX_EL2", .state
= ARM_CP_STATE_AA64
,
5362 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 2,
5363 .access
= PL2_RW
, .writefn
= hcrx_write
, .accessfn
= access_hxen
,
5364 .fieldoffset
= offsetof(CPUARMState
, cp15
.hcrx_el2
),
5367 /* Return the effective value of HCRX_EL2. */
5368 uint64_t arm_hcrx_el2_eff(CPUARMState
*env
)
5371 * The bits in this register behave as 0 for all purposes other than
5372 * direct reads of the register if:
5373 * - EL2 is not enabled in the current security state,
5374 * - SCR_EL3.HXEn is 0.
5376 if (!arm_is_el2_enabled(env
)
5377 || (arm_feature(env
, ARM_FEATURE_EL3
)
5378 && !(env
->cp15
.scr_el3
& SCR_HXEN
))) {
5381 return env
->cp15
.hcrx_el2
;
5384 static void cptr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5388 * For A-profile AArch32 EL3, if NSACR.CP10
5389 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
5391 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
5392 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
5393 uint64_t mask
= R_HCPTR_TCP11_MASK
| R_HCPTR_TCP10_MASK
;
5394 value
= (value
& ~mask
) | (env
->cp15
.cptr_el
[2] & mask
);
5396 env
->cp15
.cptr_el
[2] = value
;
5399 static uint64_t cptr_el2_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
5402 * For A-profile AArch32 EL3, if NSACR.CP10
5403 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
5405 uint64_t value
= env
->cp15
.cptr_el
[2];
5407 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
5408 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
5409 value
|= R_HCPTR_TCP11_MASK
| R_HCPTR_TCP10_MASK
;
5414 static const ARMCPRegInfo el2_cp_reginfo
[] = {
5415 { .name
= "HCR_EL2", .state
= ARM_CP_STATE_AA64
,
5417 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
5418 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.hcr_el2
),
5419 .writefn
= hcr_write
},
5420 { .name
= "HCR", .state
= ARM_CP_STATE_AA32
,
5421 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
5422 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
5423 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.hcr_el2
),
5424 .writefn
= hcr_writelow
},
5425 { .name
= "HACR_EL2", .state
= ARM_CP_STATE_BOTH
,
5426 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 7,
5427 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
5428 { .name
= "ELR_EL2", .state
= ARM_CP_STATE_AA64
,
5429 .type
= ARM_CP_ALIAS
,
5430 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 1,
5432 .fieldoffset
= offsetof(CPUARMState
, elr_el
[2]) },
5433 { .name
= "ESR_EL2", .state
= ARM_CP_STATE_BOTH
,
5434 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 2, .opc2
= 0,
5435 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[2]) },
5436 { .name
= "FAR_EL2", .state
= ARM_CP_STATE_BOTH
,
5437 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 0,
5438 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[2]) },
5439 { .name
= "HIFAR", .state
= ARM_CP_STATE_AA32
,
5440 .type
= ARM_CP_ALIAS
,
5441 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 2,
5443 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.far_el
[2]) },
5444 { .name
= "SPSR_EL2", .state
= ARM_CP_STATE_AA64
,
5445 .type
= ARM_CP_ALIAS
,
5446 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 0,
5448 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_HYP
]) },
5449 { .name
= "VBAR_EL2", .state
= ARM_CP_STATE_BOTH
,
5450 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 0,
5451 .access
= PL2_RW
, .writefn
= vbar_write
,
5452 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[2]),
5454 { .name
= "SP_EL2", .state
= ARM_CP_STATE_AA64
,
5455 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 1, .opc2
= 0,
5456 .access
= PL3_RW
, .type
= ARM_CP_ALIAS
,
5457 .fieldoffset
= offsetof(CPUARMState
, sp_el
[2]) },
5458 { .name
= "CPTR_EL2", .state
= ARM_CP_STATE_BOTH
,
5459 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 2,
5460 .access
= PL2_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
5461 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[2]),
5462 .readfn
= cptr_el2_read
, .writefn
= cptr_el2_write
},
5463 { .name
= "MAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
5464 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 0,
5465 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[2]),
5467 { .name
= "HMAIR1", .state
= ARM_CP_STATE_AA32
,
5468 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 1,
5469 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
,
5470 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.mair_el
[2]) },
5471 { .name
= "AMAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
5472 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 0,
5473 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5475 /* HAMAIR1 is mapped to AMAIR_EL2[63:32] */
5476 { .name
= "HAMAIR1", .state
= ARM_CP_STATE_AA32
,
5477 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 1,
5478 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5480 { .name
= "AFSR0_EL2", .state
= ARM_CP_STATE_BOTH
,
5481 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 0,
5482 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5484 { .name
= "AFSR1_EL2", .state
= ARM_CP_STATE_BOTH
,
5485 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 1,
5486 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5488 { .name
= "TCR_EL2", .state
= ARM_CP_STATE_BOTH
,
5489 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 2,
5490 .access
= PL2_RW
, .writefn
= vmsa_tcr_el12_write
,
5491 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[2]) },
5492 { .name
= "VTCR", .state
= ARM_CP_STATE_AA32
,
5493 .cp
= 15, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
5494 .type
= ARM_CP_ALIAS
,
5495 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5496 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vtcr_el2
) },
5497 { .name
= "VTCR_EL2", .state
= ARM_CP_STATE_AA64
,
5498 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
5500 /* no .writefn needed as this can't cause an ASID change */
5501 .fieldoffset
= offsetof(CPUARMState
, cp15
.vtcr_el2
) },
5502 { .name
= "VTTBR", .state
= ARM_CP_STATE_AA32
,
5503 .cp
= 15, .opc1
= 6, .crm
= 2,
5504 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
5505 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5506 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
),
5507 .writefn
= vttbr_write
},
5508 { .name
= "VTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
5509 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 0,
5510 .access
= PL2_RW
, .writefn
= vttbr_write
,
5511 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
) },
5512 { .name
= "SCTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
5513 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 0,
5514 .access
= PL2_RW
, .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
5515 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[2]) },
5516 { .name
= "TPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
5517 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 2,
5518 .access
= PL2_RW
, .resetvalue
= 0,
5519 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[2]) },
5520 { .name
= "TTBR0_EL2", .state
= ARM_CP_STATE_AA64
,
5521 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 0,
5522 .access
= PL2_RW
, .resetvalue
= 0, .writefn
= vmsa_tcr_ttbr_el2_write
,
5523 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
5524 { .name
= "HTTBR", .cp
= 15, .opc1
= 4, .crm
= 2,
5525 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
5526 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
5527 { .name
= "TLBIALLNSNH",
5528 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
5529 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5530 .writefn
= tlbiall_nsnh_write
},
5531 { .name
= "TLBIALLNSNHIS",
5532 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
5533 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5534 .writefn
= tlbiall_nsnh_is_write
},
5535 { .name
= "TLBIALLH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
5536 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5537 .writefn
= tlbiall_hyp_write
},
5538 { .name
= "TLBIALLHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
5539 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5540 .writefn
= tlbiall_hyp_is_write
},
5541 { .name
= "TLBIMVAH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
5542 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5543 .writefn
= tlbimva_hyp_write
},
5544 { .name
= "TLBIMVAHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
5545 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5546 .writefn
= tlbimva_hyp_is_write
},
5547 { .name
= "TLBI_ALLE2", .state
= ARM_CP_STATE_AA64
,
5548 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
5549 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5550 .writefn
= tlbi_aa64_alle2_write
},
5551 { .name
= "TLBI_VAE2", .state
= ARM_CP_STATE_AA64
,
5552 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
5553 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5554 .writefn
= tlbi_aa64_vae2_write
},
5555 { .name
= "TLBI_VALE2", .state
= ARM_CP_STATE_AA64
,
5556 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
5557 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5558 .writefn
= tlbi_aa64_vae2_write
},
5559 { .name
= "TLBI_ALLE2IS", .state
= ARM_CP_STATE_AA64
,
5560 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
5561 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5562 .writefn
= tlbi_aa64_alle2is_write
},
5563 { .name
= "TLBI_VAE2IS", .state
= ARM_CP_STATE_AA64
,
5564 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
5565 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5566 .writefn
= tlbi_aa64_vae2is_write
},
5567 { .name
= "TLBI_VALE2IS", .state
= ARM_CP_STATE_AA64
,
5568 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
5569 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
5570 .writefn
= tlbi_aa64_vae2is_write
},
5571 #ifndef CONFIG_USER_ONLY
5572 /* Unlike the other EL2-related AT operations, these must
5573 * UNDEF from EL3 if EL2 is not implemented, which is why we
5574 * define them here rather than with the rest of the AT ops.
5576 { .name
= "AT_S1E2R", .state
= ARM_CP_STATE_AA64
,
5577 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
5578 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
5579 .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
| ARM_CP_EL3_NO_EL2_UNDEF
,
5580 .writefn
= ats_write64
},
5581 { .name
= "AT_S1E2W", .state
= ARM_CP_STATE_AA64
,
5582 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
5583 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
5584 .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
| ARM_CP_EL3_NO_EL2_UNDEF
,
5585 .writefn
= ats_write64
},
5586 /* The AArch32 ATS1H* operations are CONSTRAINED UNPREDICTABLE
5587 * if EL2 is not implemented; we choose to UNDEF. Behaviour at EL3
5588 * with SCR.NS == 0 outside Monitor mode is UNPREDICTABLE; we choose
5589 * to behave as if SCR.NS was 1.
5591 { .name
= "ATS1HR", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
5593 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
5594 { .name
= "ATS1HW", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
5596 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
5597 { .name
= "CNTHCTL_EL2", .state
= ARM_CP_STATE_BOTH
,
5598 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 1, .opc2
= 0,
5599 /* ARMv7 requires bit 0 and 1 to reset to 1. ARMv8 defines the
5600 * reset values as IMPDEF. We choose to reset to 3 to comply with
5601 * both ARMv7 and ARMv8.
5603 .access
= PL2_RW
, .resetvalue
= 3,
5604 .fieldoffset
= offsetof(CPUARMState
, cp15
.cnthctl_el2
) },
5605 { .name
= "CNTVOFF_EL2", .state
= ARM_CP_STATE_AA64
,
5606 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 0, .opc2
= 3,
5607 .access
= PL2_RW
, .type
= ARM_CP_IO
, .resetvalue
= 0,
5608 .writefn
= gt_cntvoff_write
,
5609 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
5610 { .name
= "CNTVOFF", .cp
= 15, .opc1
= 4, .crm
= 14,
5611 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
| ARM_CP_IO
,
5612 .writefn
= gt_cntvoff_write
,
5613 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
5614 { .name
= "CNTHP_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
5615 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 2,
5616 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
5617 .type
= ARM_CP_IO
, .access
= PL2_RW
,
5618 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
5619 { .name
= "CNTHP_CVAL", .cp
= 15, .opc1
= 6, .crm
= 14,
5620 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
5621 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_IO
,
5622 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
5623 { .name
= "CNTHP_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
5624 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 0,
5625 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL2_RW
,
5626 .resetfn
= gt_hyp_timer_reset
,
5627 .readfn
= gt_hyp_tval_read
, .writefn
= gt_hyp_tval_write
},
5628 { .name
= "CNTHP_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
5630 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 1,
5632 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].ctl
),
5634 .writefn
= gt_hyp_ctl_write
, .raw_writefn
= raw_write
},
5636 { .name
= "HPFAR", .state
= ARM_CP_STATE_AA32
,
5637 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
5638 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
5639 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
5640 { .name
= "HPFAR_EL2", .state
= ARM_CP_STATE_AA64
,
5641 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
5643 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
5644 { .name
= "HSTR_EL2", .state
= ARM_CP_STATE_BOTH
,
5645 .cp
= 15, .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 3,
5647 .fieldoffset
= offsetof(CPUARMState
, cp15
.hstr_el2
) },
5650 static const ARMCPRegInfo el2_v8_cp_reginfo
[] = {
5651 { .name
= "HCR2", .state
= ARM_CP_STATE_AA32
,
5652 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
5653 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 4,
5655 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.hcr_el2
),
5656 .writefn
= hcr_writehigh
},
5659 static CPAccessResult
sel2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5662 if (arm_current_el(env
) == 3 || arm_is_secure_below_el3(env
)) {
5663 return CP_ACCESS_OK
;
5665 return CP_ACCESS_TRAP_UNCATEGORIZED
;
5668 static const ARMCPRegInfo el2_sec_cp_reginfo
[] = {
5669 { .name
= "VSTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
5670 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 6, .opc2
= 0,
5671 .access
= PL2_RW
, .accessfn
= sel2_access
,
5672 .fieldoffset
= offsetof(CPUARMState
, cp15
.vsttbr_el2
) },
5673 { .name
= "VSTCR_EL2", .state
= ARM_CP_STATE_AA64
,
5674 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 6, .opc2
= 2,
5675 .access
= PL2_RW
, .accessfn
= sel2_access
,
5676 .fieldoffset
= offsetof(CPUARMState
, cp15
.vstcr_el2
) },
5679 static CPAccessResult
nsacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5682 /* The NSACR is RW at EL3, and RO for NS EL1 and NS EL2.
5683 * At Secure EL1 it traps to EL3 or EL2.
5685 if (arm_current_el(env
) == 3) {
5686 return CP_ACCESS_OK
;
5688 if (arm_is_secure_below_el3(env
)) {
5689 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
5690 return CP_ACCESS_TRAP_EL2
;
5692 return CP_ACCESS_TRAP_EL3
;
5694 /* Accesses from EL1 NS and EL2 NS are UNDEF for write but allow reads. */
5696 return CP_ACCESS_OK
;
5698 return CP_ACCESS_TRAP_UNCATEGORIZED
;
5701 static const ARMCPRegInfo el3_cp_reginfo
[] = {
5702 { .name
= "SCR_EL3", .state
= ARM_CP_STATE_AA64
,
5703 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 0,
5704 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.scr_el3
),
5705 .resetfn
= scr_reset
, .writefn
= scr_write
},
5706 { .name
= "SCR", .type
= ARM_CP_ALIAS
| ARM_CP_NEWEL
,
5707 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 0,
5708 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
5709 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.scr_el3
),
5710 .writefn
= scr_write
},
5711 { .name
= "SDER32_EL3", .state
= ARM_CP_STATE_AA64
,
5712 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 1,
5713 .access
= PL3_RW
, .resetvalue
= 0,
5714 .fieldoffset
= offsetof(CPUARMState
, cp15
.sder
) },
5716 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 1,
5717 .access
= PL3_RW
, .resetvalue
= 0,
5718 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.sder
) },
5719 { .name
= "MVBAR", .cp
= 15, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
5720 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
5721 .writefn
= vbar_write
, .resetvalue
= 0,
5722 .fieldoffset
= offsetof(CPUARMState
, cp15
.mvbar
) },
5723 { .name
= "TTBR0_EL3", .state
= ARM_CP_STATE_AA64
,
5724 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 0,
5725 .access
= PL3_RW
, .resetvalue
= 0,
5726 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[3]) },
5727 { .name
= "TCR_EL3", .state
= ARM_CP_STATE_AA64
,
5728 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 2,
5730 /* no .writefn needed as this can't cause an ASID change */
5732 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[3]) },
5733 { .name
= "ELR_EL3", .state
= ARM_CP_STATE_AA64
,
5734 .type
= ARM_CP_ALIAS
,
5735 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 1,
5737 .fieldoffset
= offsetof(CPUARMState
, elr_el
[3]) },
5738 { .name
= "ESR_EL3", .state
= ARM_CP_STATE_AA64
,
5739 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 2, .opc2
= 0,
5740 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[3]) },
5741 { .name
= "FAR_EL3", .state
= ARM_CP_STATE_AA64
,
5742 .opc0
= 3, .opc1
= 6, .crn
= 6, .crm
= 0, .opc2
= 0,
5743 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[3]) },
5744 { .name
= "SPSR_EL3", .state
= ARM_CP_STATE_AA64
,
5745 .type
= ARM_CP_ALIAS
,
5746 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 0,
5748 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_MON
]) },
5749 { .name
= "VBAR_EL3", .state
= ARM_CP_STATE_AA64
,
5750 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 0,
5751 .access
= PL3_RW
, .writefn
= vbar_write
,
5752 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[3]),
5754 { .name
= "CPTR_EL3", .state
= ARM_CP_STATE_AA64
,
5755 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 2,
5756 .access
= PL3_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
5757 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[3]) },
5758 { .name
= "TPIDR_EL3", .state
= ARM_CP_STATE_AA64
,
5759 .opc0
= 3, .opc1
= 6, .crn
= 13, .crm
= 0, .opc2
= 2,
5760 .access
= PL3_RW
, .resetvalue
= 0,
5761 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[3]) },
5762 { .name
= "AMAIR_EL3", .state
= ARM_CP_STATE_AA64
,
5763 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 3, .opc2
= 0,
5764 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
5766 { .name
= "AFSR0_EL3", .state
= ARM_CP_STATE_BOTH
,
5767 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 0,
5768 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
5770 { .name
= "AFSR1_EL3", .state
= ARM_CP_STATE_BOTH
,
5771 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 1,
5772 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
5774 { .name
= "TLBI_ALLE3IS", .state
= ARM_CP_STATE_AA64
,
5775 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 0,
5776 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5777 .writefn
= tlbi_aa64_alle3is_write
},
5778 { .name
= "TLBI_VAE3IS", .state
= ARM_CP_STATE_AA64
,
5779 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 1,
5780 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5781 .writefn
= tlbi_aa64_vae3is_write
},
5782 { .name
= "TLBI_VALE3IS", .state
= ARM_CP_STATE_AA64
,
5783 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 5,
5784 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5785 .writefn
= tlbi_aa64_vae3is_write
},
5786 { .name
= "TLBI_ALLE3", .state
= ARM_CP_STATE_AA64
,
5787 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 0,
5788 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5789 .writefn
= tlbi_aa64_alle3_write
},
5790 { .name
= "TLBI_VAE3", .state
= ARM_CP_STATE_AA64
,
5791 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 1,
5792 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5793 .writefn
= tlbi_aa64_vae3_write
},
5794 { .name
= "TLBI_VALE3", .state
= ARM_CP_STATE_AA64
,
5795 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 5,
5796 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
5797 .writefn
= tlbi_aa64_vae3_write
},
5800 #ifndef CONFIG_USER_ONLY
5801 /* Test if system register redirection is to occur in the current state. */
5802 static bool redirect_for_e2h(CPUARMState
*env
)
5804 return arm_current_el(env
) == 2 && (arm_hcr_el2_eff(env
) & HCR_E2H
);
5807 static uint64_t el2_e2h_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
5811 if (redirect_for_e2h(env
)) {
5812 /* Switch to the saved EL2 version of the register. */
5814 readfn
= ri
->readfn
;
5816 readfn
= ri
->orig_readfn
;
5818 if (readfn
== NULL
) {
5821 return readfn(env
, ri
);
5824 static void el2_e2h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5829 if (redirect_for_e2h(env
)) {
5830 /* Switch to the saved EL2 version of the register. */
5832 writefn
= ri
->writefn
;
5834 writefn
= ri
->orig_writefn
;
5836 if (writefn
== NULL
) {
5837 writefn
= raw_write
;
5839 writefn(env
, ri
, value
);
5842 static void define_arm_vh_e2h_redirects_aliases(ARMCPU
*cpu
)
5845 uint32_t src_key
, dst_key
, new_key
;
5846 const char *src_name
, *dst_name
, *new_name
;
5847 bool (*feature
)(const ARMISARegisters
*id
);
5850 #define K(op0, op1, crn, crm, op2) \
5851 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP, crn, crm, op0, op1, op2)
5853 static const struct E2HAlias aliases
[] = {
5854 { K(3, 0, 1, 0, 0), K(3, 4, 1, 0, 0), K(3, 5, 1, 0, 0),
5855 "SCTLR", "SCTLR_EL2", "SCTLR_EL12" },
5856 { K(3, 0, 1, 0, 2), K(3, 4, 1, 1, 2), K(3, 5, 1, 0, 2),
5857 "CPACR", "CPTR_EL2", "CPACR_EL12" },
5858 { K(3, 0, 2, 0, 0), K(3, 4, 2, 0, 0), K(3, 5, 2, 0, 0),
5859 "TTBR0_EL1", "TTBR0_EL2", "TTBR0_EL12" },
5860 { K(3, 0, 2, 0, 1), K(3, 4, 2, 0, 1), K(3, 5, 2, 0, 1),
5861 "TTBR1_EL1", "TTBR1_EL2", "TTBR1_EL12" },
5862 { K(3, 0, 2, 0, 2), K(3, 4, 2, 0, 2), K(3, 5, 2, 0, 2),
5863 "TCR_EL1", "TCR_EL2", "TCR_EL12" },
5864 { K(3, 0, 4, 0, 0), K(3, 4, 4, 0, 0), K(3, 5, 4, 0, 0),
5865 "SPSR_EL1", "SPSR_EL2", "SPSR_EL12" },
5866 { K(3, 0, 4, 0, 1), K(3, 4, 4, 0, 1), K(3, 5, 4, 0, 1),
5867 "ELR_EL1", "ELR_EL2", "ELR_EL12" },
5868 { K(3, 0, 5, 1, 0), K(3, 4, 5, 1, 0), K(3, 5, 5, 1, 0),
5869 "AFSR0_EL1", "AFSR0_EL2", "AFSR0_EL12" },
5870 { K(3, 0, 5, 1, 1), K(3, 4, 5, 1, 1), K(3, 5, 5, 1, 1),
5871 "AFSR1_EL1", "AFSR1_EL2", "AFSR1_EL12" },
5872 { K(3, 0, 5, 2, 0), K(3, 4, 5, 2, 0), K(3, 5, 5, 2, 0),
5873 "ESR_EL1", "ESR_EL2", "ESR_EL12" },
5874 { K(3, 0, 6, 0, 0), K(3, 4, 6, 0, 0), K(3, 5, 6, 0, 0),
5875 "FAR_EL1", "FAR_EL2", "FAR_EL12" },
5876 { K(3, 0, 10, 2, 0), K(3, 4, 10, 2, 0), K(3, 5, 10, 2, 0),
5877 "MAIR_EL1", "MAIR_EL2", "MAIR_EL12" },
5878 { K(3, 0, 10, 3, 0), K(3, 4, 10, 3, 0), K(3, 5, 10, 3, 0),
5879 "AMAIR0", "AMAIR_EL2", "AMAIR_EL12" },
5880 { K(3, 0, 12, 0, 0), K(3, 4, 12, 0, 0), K(3, 5, 12, 0, 0),
5881 "VBAR", "VBAR_EL2", "VBAR_EL12" },
5882 { K(3, 0, 13, 0, 1), K(3, 4, 13, 0, 1), K(3, 5, 13, 0, 1),
5883 "CONTEXTIDR_EL1", "CONTEXTIDR_EL2", "CONTEXTIDR_EL12" },
5884 { K(3, 0, 14, 1, 0), K(3, 4, 14, 1, 0), K(3, 5, 14, 1, 0),
5885 "CNTKCTL", "CNTHCTL_EL2", "CNTKCTL_EL12" },
5888 * Note that redirection of ZCR is mentioned in the description
5889 * of ZCR_EL2, and aliasing in the description of ZCR_EL1, but
5890 * not in the summary table.
5892 { K(3, 0, 1, 2, 0), K(3, 4, 1, 2, 0), K(3, 5, 1, 2, 0),
5893 "ZCR_EL1", "ZCR_EL2", "ZCR_EL12", isar_feature_aa64_sve
},
5894 { K(3, 0, 1, 2, 6), K(3, 4, 1, 2, 6), K(3, 5, 1, 2, 6),
5895 "SMCR_EL1", "SMCR_EL2", "SMCR_EL12", isar_feature_aa64_sme
},
5897 { K(3, 0, 5, 6, 0), K(3, 4, 5, 6, 0), K(3, 5, 5, 6, 0),
5898 "TFSR_EL1", "TFSR_EL2", "TFSR_EL12", isar_feature_aa64_mte
},
5900 { K(3, 0, 13, 0, 7), K(3, 4, 13, 0, 7), K(3, 5, 13, 0, 7),
5901 "SCXTNUM_EL1", "SCXTNUM_EL2", "SCXTNUM_EL12",
5902 isar_feature_aa64_scxtnum
},
5904 /* TODO: ARMv8.2-SPE -- PMSCR_EL2 */
5905 /* TODO: ARMv8.4-Trace -- TRFCR_EL2 */
5911 for (i
= 0; i
< ARRAY_SIZE(aliases
); i
++) {
5912 const struct E2HAlias
*a
= &aliases
[i
];
5913 ARMCPRegInfo
*src_reg
, *dst_reg
, *new_reg
;
5916 if (a
->feature
&& !a
->feature(&cpu
->isar
)) {
5920 src_reg
= g_hash_table_lookup(cpu
->cp_regs
,
5921 (gpointer
)(uintptr_t)a
->src_key
);
5922 dst_reg
= g_hash_table_lookup(cpu
->cp_regs
,
5923 (gpointer
)(uintptr_t)a
->dst_key
);
5924 g_assert(src_reg
!= NULL
);
5925 g_assert(dst_reg
!= NULL
);
5927 /* Cross-compare names to detect typos in the keys. */
5928 g_assert(strcmp(src_reg
->name
, a
->src_name
) == 0);
5929 g_assert(strcmp(dst_reg
->name
, a
->dst_name
) == 0);
5931 /* None of the core system registers use opaque; we will. */
5932 g_assert(src_reg
->opaque
== NULL
);
5934 /* Create alias before redirection so we dup the right data. */
5935 new_reg
= g_memdup(src_reg
, sizeof(ARMCPRegInfo
));
5937 new_reg
->name
= a
->new_name
;
5938 new_reg
->type
|= ARM_CP_ALIAS
;
5939 /* Remove PL1/PL0 access, leaving PL2/PL3 R/W in place. */
5940 new_reg
->access
&= PL2_RW
| PL3_RW
;
5942 ok
= g_hash_table_insert(cpu
->cp_regs
,
5943 (gpointer
)(uintptr_t)a
->new_key
, new_reg
);
5946 src_reg
->opaque
= dst_reg
;
5947 src_reg
->orig_readfn
= src_reg
->readfn
?: raw_read
;
5948 src_reg
->orig_writefn
= src_reg
->writefn
?: raw_write
;
5949 if (!src_reg
->raw_readfn
) {
5950 src_reg
->raw_readfn
= raw_read
;
5952 if (!src_reg
->raw_writefn
) {
5953 src_reg
->raw_writefn
= raw_write
;
5955 src_reg
->readfn
= el2_e2h_read
;
5956 src_reg
->writefn
= el2_e2h_write
;
5961 static CPAccessResult
ctr_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5964 int cur_el
= arm_current_el(env
);
5967 uint64_t hcr
= arm_hcr_el2_eff(env
);
5970 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
5971 if (!(env
->cp15
.sctlr_el
[2] & SCTLR_UCT
)) {
5972 return CP_ACCESS_TRAP_EL2
;
5975 if (!(env
->cp15
.sctlr_el
[1] & SCTLR_UCT
)) {
5976 return CP_ACCESS_TRAP
;
5978 if (hcr
& HCR_TID2
) {
5979 return CP_ACCESS_TRAP_EL2
;
5982 } else if (hcr
& HCR_TID2
) {
5983 return CP_ACCESS_TRAP_EL2
;
5987 if (arm_current_el(env
) < 2 && arm_hcr_el2_eff(env
) & HCR_TID2
) {
5988 return CP_ACCESS_TRAP_EL2
;
5991 return CP_ACCESS_OK
;
5995 * Check for traps to RAS registers, which are controlled
5996 * by HCR_EL2.TERR and SCR_EL3.TERR.
5998 static CPAccessResult
access_terr(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6001 int el
= arm_current_el(env
);
6003 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_TERR
)) {
6004 return CP_ACCESS_TRAP_EL2
;
6006 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_TERR
)) {
6007 return CP_ACCESS_TRAP_EL3
;
6009 return CP_ACCESS_OK
;
6012 static uint64_t disr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6014 int el
= arm_current_el(env
);
6016 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_AMO
)) {
6017 return env
->cp15
.vdisr_el2
;
6019 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_EA
)) {
6020 return 0; /* RAZ/WI */
6022 return env
->cp15
.disr_el1
;
6025 static void disr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
6027 int el
= arm_current_el(env
);
6029 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_AMO
)) {
6030 env
->cp15
.vdisr_el2
= val
;
6033 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_EA
)) {
6034 return; /* RAZ/WI */
6036 env
->cp15
.disr_el1
= val
;
6040 * Minimal RAS implementation with no Error Records.
6041 * Which means that all of the Error Record registers:
6049 * ERXPFGCDN_EL1 (RASv1p1)
6050 * ERXPFGCTL_EL1 (RASv1p1)
6051 * ERXPFGF_EL1 (RASv1p1)
6055 * may generate UNDEFINED, which is the effect we get by not
6056 * listing them at all.
6058 static const ARMCPRegInfo minimal_ras_reginfo
[] = {
6059 { .name
= "DISR_EL1", .state
= ARM_CP_STATE_BOTH
,
6060 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 1, .opc2
= 1,
6061 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.disr_el1
),
6062 .readfn
= disr_read
, .writefn
= disr_write
, .raw_writefn
= raw_write
},
6063 { .name
= "ERRIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
6064 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 3, .opc2
= 0,
6065 .access
= PL1_R
, .accessfn
= access_terr
,
6066 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6067 { .name
= "VDISR_EL2", .state
= ARM_CP_STATE_BOTH
,
6068 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 1, .opc2
= 1,
6069 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.vdisr_el2
) },
6070 { .name
= "VSESR_EL2", .state
= ARM_CP_STATE_BOTH
,
6071 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 2, .opc2
= 3,
6072 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.vsesr_el2
) },
6076 * Return the exception level to which exceptions should be taken
6077 * via SVEAccessTrap. This excludes the check for whether the exception
6078 * should be routed through AArch64.AdvSIMDFPAccessTrap. That can easily
6079 * be found by testing 0 < fp_exception_el < sve_exception_el.
6081 * C.f. the ARM pseudocode function CheckSVEEnabled. Note that the
6082 * pseudocode does *not* separate out the FP trap checks, but has them
6083 * all in one function.
6085 int sve_exception_el(CPUARMState
*env
, int el
)
6087 #ifndef CONFIG_USER_ONLY
6088 if (el
<= 1 && !el_is_in_host(env
, el
)) {
6089 switch (FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, ZEN
)) {
6101 if (el
<= 2 && arm_is_el2_enabled(env
)) {
6102 /* CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE). */
6103 if (env
->cp15
.hcr_el2
& HCR_E2H
) {
6104 switch (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, ZEN
)) {
6106 if (el
!= 0 || !(env
->cp15
.hcr_el2
& HCR_TGE
)) {
6115 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TZ
)) {
6121 /* CPTR_EL3. Since EZ is negative we must check for EL3. */
6122 if (arm_feature(env
, ARM_FEATURE_EL3
)
6123 && !FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, EZ
)) {
6131 * Return the exception level to which exceptions should be taken for SME.
6132 * C.f. the ARM pseudocode function CheckSMEAccess.
6134 int sme_exception_el(CPUARMState
*env
, int el
)
6136 #ifndef CONFIG_USER_ONLY
6137 if (el
<= 1 && !el_is_in_host(env
, el
)) {
6138 switch (FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, SMEN
)) {
6150 if (el
<= 2 && arm_is_el2_enabled(env
)) {
6151 /* CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE). */
6152 if (env
->cp15
.hcr_el2
& HCR_E2H
) {
6153 switch (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, SMEN
)) {
6155 if (el
!= 0 || !(env
->cp15
.hcr_el2
& HCR_TGE
)) {
6164 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TSM
)) {
6170 /* CPTR_EL3. Since ESM is negative we must check for EL3. */
6171 if (arm_feature(env
, ARM_FEATURE_EL3
)
6172 && !FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, ESM
)) {
6179 /* This corresponds to the ARM pseudocode function IsFullA64Enabled(). */
6180 static bool sme_fa64(CPUARMState
*env
, int el
)
6182 if (!cpu_isar_feature(aa64_sme_fa64
, env_archcpu(env
))) {
6186 if (el
<= 1 && !el_is_in_host(env
, el
)) {
6187 if (!FIELD_EX64(env
->vfp
.smcr_el
[1], SMCR
, FA64
)) {
6191 if (el
<= 2 && arm_is_el2_enabled(env
)) {
6192 if (!FIELD_EX64(env
->vfp
.smcr_el
[2], SMCR
, FA64
)) {
6196 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
6197 if (!FIELD_EX64(env
->vfp
.smcr_el
[3], SMCR
, FA64
)) {
6206 * Given that SVE is enabled, return the vector length for EL.
6208 uint32_t sve_vqm1_for_el_sm(CPUARMState
*env
, int el
, bool sm
)
6210 ARMCPU
*cpu
= env_archcpu(env
);
6211 uint64_t *cr
= env
->vfp
.zcr_el
;
6212 uint32_t map
= cpu
->sve_vq
.map
;
6213 uint32_t len
= ARM_MAX_VQ
- 1;
6216 cr
= env
->vfp
.smcr_el
;
6217 map
= cpu
->sme_vq
.map
;
6220 if (el
<= 1 && !el_is_in_host(env
, el
)) {
6221 len
= MIN(len
, 0xf & (uint32_t)cr
[1]);
6223 if (el
<= 2 && arm_feature(env
, ARM_FEATURE_EL2
)) {
6224 len
= MIN(len
, 0xf & (uint32_t)cr
[2]);
6226 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
6227 len
= MIN(len
, 0xf & (uint32_t)cr
[3]);
6230 map
&= MAKE_64BIT_MASK(0, len
+ 1);
6232 return 31 - clz32(map
);
6235 /* Bit 0 is always set for Normal SVE -- not so for Streaming SVE. */
6237 return ctz32(cpu
->sme_vq
.map
);
6240 uint32_t sve_vqm1_for_el(CPUARMState
*env
, int el
)
6242 return sve_vqm1_for_el_sm(env
, el
, FIELD_EX64(env
->svcr
, SVCR
, SM
));
6245 static void zcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6248 int cur_el
= arm_current_el(env
);
6249 int old_len
= sve_vqm1_for_el(env
, cur_el
);
6252 /* Bits other than [3:0] are RAZ/WI. */
6253 QEMU_BUILD_BUG_ON(ARM_MAX_VQ
> 16);
6254 raw_write(env
, ri
, value
& 0xf);
6257 * Because we arrived here, we know both FP and SVE are enabled;
6258 * otherwise we would have trapped access to the ZCR_ELn register.
6260 new_len
= sve_vqm1_for_el(env
, cur_el
);
6261 if (new_len
< old_len
) {
6262 aarch64_sve_narrow_vq(env
, new_len
+ 1);
6266 static const ARMCPRegInfo zcr_reginfo
[] = {
6267 { .name
= "ZCR_EL1", .state
= ARM_CP_STATE_AA64
,
6268 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 2, .opc2
= 0,
6269 .access
= PL1_RW
, .type
= ARM_CP_SVE
,
6270 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[1]),
6271 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
6272 { .name
= "ZCR_EL2", .state
= ARM_CP_STATE_AA64
,
6273 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 0,
6274 .access
= PL2_RW
, .type
= ARM_CP_SVE
,
6275 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[2]),
6276 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
6277 { .name
= "ZCR_EL3", .state
= ARM_CP_STATE_AA64
,
6278 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 2, .opc2
= 0,
6279 .access
= PL3_RW
, .type
= ARM_CP_SVE
,
6280 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[3]),
6281 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
6284 #ifdef TARGET_AARCH64
6285 static CPAccessResult
access_tpidr2(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6288 int el
= arm_current_el(env
);
6291 uint64_t sctlr
= arm_sctlr(env
, el
);
6292 if (!(sctlr
& SCTLR_EnTP2
)) {
6293 return CP_ACCESS_TRAP
;
6296 /* TODO: FEAT_FGT */
6298 && arm_feature(env
, ARM_FEATURE_EL3
)
6299 && !(env
->cp15
.scr_el3
& SCR_ENTP2
)) {
6300 return CP_ACCESS_TRAP_EL3
;
6302 return CP_ACCESS_OK
;
6305 static CPAccessResult
access_esm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6308 /* TODO: FEAT_FGT for SMPRI_EL1 but not SMPRIMAP_EL2 */
6309 if (arm_current_el(env
) < 3
6310 && arm_feature(env
, ARM_FEATURE_EL3
)
6311 && !FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, ESM
)) {
6312 return CP_ACCESS_TRAP_EL3
;
6314 return CP_ACCESS_OK
;
6317 static void svcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6320 helper_set_pstate_sm(env
, FIELD_EX64(value
, SVCR
, SM
));
6321 helper_set_pstate_za(env
, FIELD_EX64(value
, SVCR
, ZA
));
6322 arm_rebuild_hflags(env
);
6325 static void smcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6328 int cur_el
= arm_current_el(env
);
6329 int old_len
= sve_vqm1_for_el(env
, cur_el
);
6332 QEMU_BUILD_BUG_ON(ARM_MAX_VQ
> R_SMCR_LEN_MASK
+ 1);
6333 value
&= R_SMCR_LEN_MASK
| R_SMCR_FA64_MASK
;
6334 raw_write(env
, ri
, value
);
6337 * Note that it is CONSTRAINED UNPREDICTABLE what happens to ZA storage
6338 * when SVL is widened (old values kept, or zeros). Choose to keep the
6339 * current values for simplicity. But for QEMU internals, we must still
6340 * apply the narrower SVL to the Zregs and Pregs -- see the comment
6341 * above aarch64_sve_narrow_vq.
6343 new_len
= sve_vqm1_for_el(env
, cur_el
);
6344 if (new_len
< old_len
) {
6345 aarch64_sve_narrow_vq(env
, new_len
+ 1);
6349 static const ARMCPRegInfo sme_reginfo
[] = {
6350 { .name
= "TPIDR2_EL0", .state
= ARM_CP_STATE_AA64
,
6351 .opc0
= 3, .opc1
= 3, .crn
= 13, .crm
= 0, .opc2
= 5,
6352 .access
= PL0_RW
, .accessfn
= access_tpidr2
,
6353 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr2_el0
) },
6354 { .name
= "SVCR", .state
= ARM_CP_STATE_AA64
,
6355 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 2,
6356 .access
= PL0_RW
, .type
= ARM_CP_SME
,
6357 .fieldoffset
= offsetof(CPUARMState
, svcr
),
6358 .writefn
= svcr_write
, .raw_writefn
= raw_write
},
6359 { .name
= "SMCR_EL1", .state
= ARM_CP_STATE_AA64
,
6360 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 2, .opc2
= 6,
6361 .access
= PL1_RW
, .type
= ARM_CP_SME
,
6362 .fieldoffset
= offsetof(CPUARMState
, vfp
.smcr_el
[1]),
6363 .writefn
= smcr_write
, .raw_writefn
= raw_write
},
6364 { .name
= "SMCR_EL2", .state
= ARM_CP_STATE_AA64
,
6365 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 6,
6366 .access
= PL2_RW
, .type
= ARM_CP_SME
,
6367 .fieldoffset
= offsetof(CPUARMState
, vfp
.smcr_el
[2]),
6368 .writefn
= smcr_write
, .raw_writefn
= raw_write
},
6369 { .name
= "SMCR_EL3", .state
= ARM_CP_STATE_AA64
,
6370 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 2, .opc2
= 6,
6371 .access
= PL3_RW
, .type
= ARM_CP_SME
,
6372 .fieldoffset
= offsetof(CPUARMState
, vfp
.smcr_el
[3]),
6373 .writefn
= smcr_write
, .raw_writefn
= raw_write
},
6374 { .name
= "SMIDR_EL1", .state
= ARM_CP_STATE_AA64
,
6375 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 6,
6376 .access
= PL1_R
, .accessfn
= access_aa64_tid1
,
6378 * IMPLEMENTOR = 0 (software)
6379 * REVISION = 0 (implementation defined)
6380 * SMPS = 0 (no streaming execution priority in QEMU)
6381 * AFFINITY = 0 (streaming sve mode not shared with other PEs)
6383 .type
= ARM_CP_CONST
, .resetvalue
= 0, },
6385 * Because SMIDR_EL1.SMPS is 0, SMPRI_EL1 and SMPRIMAP_EL2 are RES 0.
6387 { .name
= "SMPRI_EL1", .state
= ARM_CP_STATE_AA64
,
6388 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 2, .opc2
= 4,
6389 .access
= PL1_RW
, .accessfn
= access_esm
,
6390 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6391 { .name
= "SMPRIMAP_EL2", .state
= ARM_CP_STATE_AA64
,
6392 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 5,
6393 .access
= PL2_RW
, .accessfn
= access_esm
,
6394 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6396 #endif /* TARGET_AARCH64 */
6398 static void define_pmu_regs(ARMCPU
*cpu
)
6401 * v7 performance monitor control register: same implementor
6402 * field as main ID register, and we implement four counters in
6403 * addition to the cycle count register.
6405 unsigned int i
, pmcrn
= pmu_num_counters(&cpu
->env
);
6406 ARMCPRegInfo pmcr
= {
6407 .name
= "PMCR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 0,
6409 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
6410 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcr
),
6411 .accessfn
= pmreg_access
, .writefn
= pmcr_write
,
6412 .raw_writefn
= raw_write
,
6414 ARMCPRegInfo pmcr64
= {
6415 .name
= "PMCR_EL0", .state
= ARM_CP_STATE_AA64
,
6416 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 0,
6417 .access
= PL0_RW
, .accessfn
= pmreg_access
,
6419 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcr
),
6420 .resetvalue
= cpu
->isar
.reset_pmcr_el0
,
6421 .writefn
= pmcr_write
, .raw_writefn
= raw_write
,
6424 define_one_arm_cp_reg(cpu
, &pmcr
);
6425 define_one_arm_cp_reg(cpu
, &pmcr64
);
6426 for (i
= 0; i
< pmcrn
; i
++) {
6427 char *pmevcntr_name
= g_strdup_printf("PMEVCNTR%d", i
);
6428 char *pmevcntr_el0_name
= g_strdup_printf("PMEVCNTR%d_EL0", i
);
6429 char *pmevtyper_name
= g_strdup_printf("PMEVTYPER%d", i
);
6430 char *pmevtyper_el0_name
= g_strdup_printf("PMEVTYPER%d_EL0", i
);
6431 ARMCPRegInfo pmev_regs
[] = {
6432 { .name
= pmevcntr_name
, .cp
= 15, .crn
= 14,
6433 .crm
= 8 | (3 & (i
>> 3)), .opc1
= 0, .opc2
= i
& 7,
6434 .access
= PL0_RW
, .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
6435 .readfn
= pmevcntr_readfn
, .writefn
= pmevcntr_writefn
,
6436 .accessfn
= pmreg_access_xevcntr
},
6437 { .name
= pmevcntr_el0_name
, .state
= ARM_CP_STATE_AA64
,
6438 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 8 | (3 & (i
>> 3)),
6439 .opc2
= i
& 7, .access
= PL0_RW
, .accessfn
= pmreg_access_xevcntr
,
6441 .readfn
= pmevcntr_readfn
, .writefn
= pmevcntr_writefn
,
6442 .raw_readfn
= pmevcntr_rawread
,
6443 .raw_writefn
= pmevcntr_rawwrite
},
6444 { .name
= pmevtyper_name
, .cp
= 15, .crn
= 14,
6445 .crm
= 12 | (3 & (i
>> 3)), .opc1
= 0, .opc2
= i
& 7,
6446 .access
= PL0_RW
, .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
6447 .readfn
= pmevtyper_readfn
, .writefn
= pmevtyper_writefn
,
6448 .accessfn
= pmreg_access
},
6449 { .name
= pmevtyper_el0_name
, .state
= ARM_CP_STATE_AA64
,
6450 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 12 | (3 & (i
>> 3)),
6451 .opc2
= i
& 7, .access
= PL0_RW
, .accessfn
= pmreg_access
,
6453 .readfn
= pmevtyper_readfn
, .writefn
= pmevtyper_writefn
,
6454 .raw_writefn
= pmevtyper_rawwrite
},
6456 define_arm_cp_regs(cpu
, pmev_regs
);
6457 g_free(pmevcntr_name
);
6458 g_free(pmevcntr_el0_name
);
6459 g_free(pmevtyper_name
);
6460 g_free(pmevtyper_el0_name
);
6462 if (cpu_isar_feature(aa32_pmuv3p1
, cpu
)) {
6463 ARMCPRegInfo v81_pmu_regs
[] = {
6464 { .name
= "PMCEID2", .state
= ARM_CP_STATE_AA32
,
6465 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 4,
6466 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
6467 .resetvalue
= extract64(cpu
->pmceid0
, 32, 32) },
6468 { .name
= "PMCEID3", .state
= ARM_CP_STATE_AA32
,
6469 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 5,
6470 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
6471 .resetvalue
= extract64(cpu
->pmceid1
, 32, 32) },
6473 define_arm_cp_regs(cpu
, v81_pmu_regs
);
6475 if (cpu_isar_feature(any_pmuv3p4
, cpu
)) {
6476 static const ARMCPRegInfo v84_pmmir
= {
6477 .name
= "PMMIR_EL1", .state
= ARM_CP_STATE_BOTH
,
6478 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 6,
6479 .access
= PL1_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
6482 define_one_arm_cp_reg(cpu
, &v84_pmmir
);
6486 /* We don't know until after realize whether there's a GICv3
6487 * attached, and that is what registers the gicv3 sysregs.
6488 * So we have to fill in the GIC fields in ID_PFR/ID_PFR1_EL1/ID_AA64PFR0_EL1
6491 static uint64_t id_pfr1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6493 ARMCPU
*cpu
= env_archcpu(env
);
6494 uint64_t pfr1
= cpu
->isar
.id_pfr1
;
6496 if (env
->gicv3state
) {
6502 #ifndef CONFIG_USER_ONLY
6503 static uint64_t id_aa64pfr0_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6505 ARMCPU
*cpu
= env_archcpu(env
);
6506 uint64_t pfr0
= cpu
->isar
.id_aa64pfr0
;
6508 if (env
->gicv3state
) {
6515 /* Shared logic between LORID and the rest of the LOR* registers.
6516 * Secure state exclusion has already been dealt with.
6518 static CPAccessResult
access_lor_ns(CPUARMState
*env
,
6519 const ARMCPRegInfo
*ri
, bool isread
)
6521 int el
= arm_current_el(env
);
6523 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_TLOR
)) {
6524 return CP_ACCESS_TRAP_EL2
;
6526 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_TLOR
)) {
6527 return CP_ACCESS_TRAP_EL3
;
6529 return CP_ACCESS_OK
;
6532 static CPAccessResult
access_lor_other(CPUARMState
*env
,
6533 const ARMCPRegInfo
*ri
, bool isread
)
6535 if (arm_is_secure_below_el3(env
)) {
6536 /* Access denied in secure mode. */
6537 return CP_ACCESS_TRAP
;
6539 return access_lor_ns(env
, ri
, isread
);
6543 * A trivial implementation of ARMv8.1-LOR leaves all of these
6544 * registers fixed at 0, which indicates that there are zero
6545 * supported Limited Ordering regions.
6547 static const ARMCPRegInfo lor_reginfo
[] = {
6548 { .name
= "LORSA_EL1", .state
= ARM_CP_STATE_AA64
,
6549 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 0,
6550 .access
= PL1_RW
, .accessfn
= access_lor_other
,
6551 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6552 { .name
= "LOREA_EL1", .state
= ARM_CP_STATE_AA64
,
6553 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 1,
6554 .access
= PL1_RW
, .accessfn
= access_lor_other
,
6555 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6556 { .name
= "LORN_EL1", .state
= ARM_CP_STATE_AA64
,
6557 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 2,
6558 .access
= PL1_RW
, .accessfn
= access_lor_other
,
6559 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6560 { .name
= "LORC_EL1", .state
= ARM_CP_STATE_AA64
,
6561 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 3,
6562 .access
= PL1_RW
, .accessfn
= access_lor_other
,
6563 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6564 { .name
= "LORID_EL1", .state
= ARM_CP_STATE_AA64
,
6565 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 7,
6566 .access
= PL1_R
, .accessfn
= access_lor_ns
,
6567 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6570 #ifdef TARGET_AARCH64
6571 static CPAccessResult
access_pauth(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6574 int el
= arm_current_el(env
);
6577 arm_is_el2_enabled(env
) &&
6578 !(arm_hcr_el2_eff(env
) & HCR_APK
)) {
6579 return CP_ACCESS_TRAP_EL2
;
6582 arm_feature(env
, ARM_FEATURE_EL3
) &&
6583 !(env
->cp15
.scr_el3
& SCR_APK
)) {
6584 return CP_ACCESS_TRAP_EL3
;
6586 return CP_ACCESS_OK
;
6589 static const ARMCPRegInfo pauth_reginfo
[] = {
6590 { .name
= "APDAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
6591 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 0,
6592 .access
= PL1_RW
, .accessfn
= access_pauth
,
6593 .fieldoffset
= offsetof(CPUARMState
, keys
.apda
.lo
) },
6594 { .name
= "APDAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
6595 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 1,
6596 .access
= PL1_RW
, .accessfn
= access_pauth
,
6597 .fieldoffset
= offsetof(CPUARMState
, keys
.apda
.hi
) },
6598 { .name
= "APDBKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
6599 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 2,
6600 .access
= PL1_RW
, .accessfn
= access_pauth
,
6601 .fieldoffset
= offsetof(CPUARMState
, keys
.apdb
.lo
) },
6602 { .name
= "APDBKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
6603 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 3,
6604 .access
= PL1_RW
, .accessfn
= access_pauth
,
6605 .fieldoffset
= offsetof(CPUARMState
, keys
.apdb
.hi
) },
6606 { .name
= "APGAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
6607 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 3, .opc2
= 0,
6608 .access
= PL1_RW
, .accessfn
= access_pauth
,
6609 .fieldoffset
= offsetof(CPUARMState
, keys
.apga
.lo
) },
6610 { .name
= "APGAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
6611 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 3, .opc2
= 1,
6612 .access
= PL1_RW
, .accessfn
= access_pauth
,
6613 .fieldoffset
= offsetof(CPUARMState
, keys
.apga
.hi
) },
6614 { .name
= "APIAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
6615 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 0,
6616 .access
= PL1_RW
, .accessfn
= access_pauth
,
6617 .fieldoffset
= offsetof(CPUARMState
, keys
.apia
.lo
) },
6618 { .name
= "APIAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
6619 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 1,
6620 .access
= PL1_RW
, .accessfn
= access_pauth
,
6621 .fieldoffset
= offsetof(CPUARMState
, keys
.apia
.hi
) },
6622 { .name
= "APIBKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
6623 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 2,
6624 .access
= PL1_RW
, .accessfn
= access_pauth
,
6625 .fieldoffset
= offsetof(CPUARMState
, keys
.apib
.lo
) },
6626 { .name
= "APIBKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
6627 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 3,
6628 .access
= PL1_RW
, .accessfn
= access_pauth
,
6629 .fieldoffset
= offsetof(CPUARMState
, keys
.apib
.hi
) },
6632 static const ARMCPRegInfo tlbirange_reginfo
[] = {
6633 { .name
= "TLBI_RVAE1IS", .state
= ARM_CP_STATE_AA64
,
6634 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 1,
6635 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6636 .writefn
= tlbi_aa64_rvae1is_write
},
6637 { .name
= "TLBI_RVAAE1IS", .state
= ARM_CP_STATE_AA64
,
6638 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 3,
6639 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6640 .writefn
= tlbi_aa64_rvae1is_write
},
6641 { .name
= "TLBI_RVALE1IS", .state
= ARM_CP_STATE_AA64
,
6642 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 5,
6643 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6644 .writefn
= tlbi_aa64_rvae1is_write
},
6645 { .name
= "TLBI_RVAALE1IS", .state
= ARM_CP_STATE_AA64
,
6646 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 7,
6647 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6648 .writefn
= tlbi_aa64_rvae1is_write
},
6649 { .name
= "TLBI_RVAE1OS", .state
= ARM_CP_STATE_AA64
,
6650 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
6651 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6652 .writefn
= tlbi_aa64_rvae1is_write
},
6653 { .name
= "TLBI_RVAAE1OS", .state
= ARM_CP_STATE_AA64
,
6654 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 3,
6655 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6656 .writefn
= tlbi_aa64_rvae1is_write
},
6657 { .name
= "TLBI_RVALE1OS", .state
= ARM_CP_STATE_AA64
,
6658 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 5,
6659 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6660 .writefn
= tlbi_aa64_rvae1is_write
},
6661 { .name
= "TLBI_RVAALE1OS", .state
= ARM_CP_STATE_AA64
,
6662 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 7,
6663 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6664 .writefn
= tlbi_aa64_rvae1is_write
},
6665 { .name
= "TLBI_RVAE1", .state
= ARM_CP_STATE_AA64
,
6666 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
6667 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6668 .writefn
= tlbi_aa64_rvae1_write
},
6669 { .name
= "TLBI_RVAAE1", .state
= ARM_CP_STATE_AA64
,
6670 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 3,
6671 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6672 .writefn
= tlbi_aa64_rvae1_write
},
6673 { .name
= "TLBI_RVALE1", .state
= ARM_CP_STATE_AA64
,
6674 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 5,
6675 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6676 .writefn
= tlbi_aa64_rvae1_write
},
6677 { .name
= "TLBI_RVAALE1", .state
= ARM_CP_STATE_AA64
,
6678 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 7,
6679 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6680 .writefn
= tlbi_aa64_rvae1_write
},
6681 { .name
= "TLBI_RIPAS2E1IS", .state
= ARM_CP_STATE_AA64
,
6682 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 2,
6683 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6684 { .name
= "TLBI_RIPAS2LE1IS", .state
= ARM_CP_STATE_AA64
,
6685 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 6,
6686 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6687 { .name
= "TLBI_RVAE2IS", .state
= ARM_CP_STATE_AA64
,
6688 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 2, .opc2
= 1,
6689 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6690 .writefn
= tlbi_aa64_rvae2is_write
},
6691 { .name
= "TLBI_RVALE2IS", .state
= ARM_CP_STATE_AA64
,
6692 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 2, .opc2
= 5,
6693 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6694 .writefn
= tlbi_aa64_rvae2is_write
},
6695 { .name
= "TLBI_RIPAS2E1", .state
= ARM_CP_STATE_AA64
,
6696 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 2,
6697 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6698 { .name
= "TLBI_RIPAS2LE1", .state
= ARM_CP_STATE_AA64
,
6699 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 6,
6700 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6701 { .name
= "TLBI_RVAE2OS", .state
= ARM_CP_STATE_AA64
,
6702 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 5, .opc2
= 1,
6703 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6704 .writefn
= tlbi_aa64_rvae2is_write
},
6705 { .name
= "TLBI_RVALE2OS", .state
= ARM_CP_STATE_AA64
,
6706 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 5, .opc2
= 5,
6707 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6708 .writefn
= tlbi_aa64_rvae2is_write
},
6709 { .name
= "TLBI_RVAE2", .state
= ARM_CP_STATE_AA64
,
6710 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 6, .opc2
= 1,
6711 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6712 .writefn
= tlbi_aa64_rvae2_write
},
6713 { .name
= "TLBI_RVALE2", .state
= ARM_CP_STATE_AA64
,
6714 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 6, .opc2
= 5,
6715 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6716 .writefn
= tlbi_aa64_rvae2_write
},
6717 { .name
= "TLBI_RVAE3IS", .state
= ARM_CP_STATE_AA64
,
6718 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 2, .opc2
= 1,
6719 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6720 .writefn
= tlbi_aa64_rvae3is_write
},
6721 { .name
= "TLBI_RVALE3IS", .state
= ARM_CP_STATE_AA64
,
6722 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 2, .opc2
= 5,
6723 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6724 .writefn
= tlbi_aa64_rvae3is_write
},
6725 { .name
= "TLBI_RVAE3OS", .state
= ARM_CP_STATE_AA64
,
6726 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 5, .opc2
= 1,
6727 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6728 .writefn
= tlbi_aa64_rvae3is_write
},
6729 { .name
= "TLBI_RVALE3OS", .state
= ARM_CP_STATE_AA64
,
6730 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 5, .opc2
= 5,
6731 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6732 .writefn
= tlbi_aa64_rvae3is_write
},
6733 { .name
= "TLBI_RVAE3", .state
= ARM_CP_STATE_AA64
,
6734 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 6, .opc2
= 1,
6735 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6736 .writefn
= tlbi_aa64_rvae3_write
},
6737 { .name
= "TLBI_RVALE3", .state
= ARM_CP_STATE_AA64
,
6738 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 6, .opc2
= 5,
6739 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6740 .writefn
= tlbi_aa64_rvae3_write
},
6743 static const ARMCPRegInfo tlbios_reginfo
[] = {
6744 { .name
= "TLBI_VMALLE1OS", .state
= ARM_CP_STATE_AA64
,
6745 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 0,
6746 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6747 .writefn
= tlbi_aa64_vmalle1is_write
},
6748 { .name
= "TLBI_VAE1OS", .state
= ARM_CP_STATE_AA64
,
6749 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 1,
6750 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6751 .writefn
= tlbi_aa64_vae1is_write
},
6752 { .name
= "TLBI_ASIDE1OS", .state
= ARM_CP_STATE_AA64
,
6753 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 2,
6754 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6755 .writefn
= tlbi_aa64_vmalle1is_write
},
6756 { .name
= "TLBI_VAAE1OS", .state
= ARM_CP_STATE_AA64
,
6757 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 3,
6758 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6759 .writefn
= tlbi_aa64_vae1is_write
},
6760 { .name
= "TLBI_VALE1OS", .state
= ARM_CP_STATE_AA64
,
6761 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 5,
6762 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6763 .writefn
= tlbi_aa64_vae1is_write
},
6764 { .name
= "TLBI_VAALE1OS", .state
= ARM_CP_STATE_AA64
,
6765 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 7,
6766 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
6767 .writefn
= tlbi_aa64_vae1is_write
},
6768 { .name
= "TLBI_ALLE2OS", .state
= ARM_CP_STATE_AA64
,
6769 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 0,
6770 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6771 .writefn
= tlbi_aa64_alle2is_write
},
6772 { .name
= "TLBI_VAE2OS", .state
= ARM_CP_STATE_AA64
,
6773 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 1,
6774 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6775 .writefn
= tlbi_aa64_vae2is_write
},
6776 { .name
= "TLBI_ALLE1OS", .state
= ARM_CP_STATE_AA64
,
6777 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 4,
6778 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
6779 .writefn
= tlbi_aa64_alle1is_write
},
6780 { .name
= "TLBI_VALE2OS", .state
= ARM_CP_STATE_AA64
,
6781 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 5,
6782 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6783 .writefn
= tlbi_aa64_vae2is_write
},
6784 { .name
= "TLBI_VMALLS12E1OS", .state
= ARM_CP_STATE_AA64
,
6785 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 6,
6786 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
6787 .writefn
= tlbi_aa64_alle1is_write
},
6788 { .name
= "TLBI_IPAS2E1OS", .state
= ARM_CP_STATE_AA64
,
6789 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 0,
6790 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6791 { .name
= "TLBI_RIPAS2E1OS", .state
= ARM_CP_STATE_AA64
,
6792 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 3,
6793 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6794 { .name
= "TLBI_IPAS2LE1OS", .state
= ARM_CP_STATE_AA64
,
6795 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 4,
6796 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6797 { .name
= "TLBI_RIPAS2LE1OS", .state
= ARM_CP_STATE_AA64
,
6798 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 7,
6799 .access
= PL2_W
, .type
= ARM_CP_NOP
},
6800 { .name
= "TLBI_ALLE3OS", .state
= ARM_CP_STATE_AA64
,
6801 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 0,
6802 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6803 .writefn
= tlbi_aa64_alle3is_write
},
6804 { .name
= "TLBI_VAE3OS", .state
= ARM_CP_STATE_AA64
,
6805 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 1,
6806 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6807 .writefn
= tlbi_aa64_vae3is_write
},
6808 { .name
= "TLBI_VALE3OS", .state
= ARM_CP_STATE_AA64
,
6809 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 5,
6810 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6811 .writefn
= tlbi_aa64_vae3is_write
},
6814 static uint64_t rndr_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6819 /* Success sets NZCV = 0000. */
6820 env
->NF
= env
->CF
= env
->VF
= 0, env
->ZF
= 1;
6822 if (qemu_guest_getrandom(&ret
, sizeof(ret
), &err
) < 0) {
6824 * ??? Failed, for unknown reasons in the crypto subsystem.
6825 * The best we can do is log the reason and return the
6826 * timed-out indication to the guest. There is no reason
6827 * we know to expect this failure to be transitory, so the
6828 * guest may well hang retrying the operation.
6830 qemu_log_mask(LOG_UNIMP
, "%s: Crypto failure: %s",
6831 ri
->name
, error_get_pretty(err
));
6834 env
->ZF
= 0; /* NZCF = 0100 */
6840 /* We do not support re-seeding, so the two registers operate the same. */
6841 static const ARMCPRegInfo rndr_reginfo
[] = {
6842 { .name
= "RNDR", .state
= ARM_CP_STATE_AA64
,
6843 .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
| ARM_CP_IO
,
6844 .opc0
= 3, .opc1
= 3, .crn
= 2, .crm
= 4, .opc2
= 0,
6845 .access
= PL0_R
, .readfn
= rndr_readfn
},
6846 { .name
= "RNDRRS", .state
= ARM_CP_STATE_AA64
,
6847 .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
| ARM_CP_IO
,
6848 .opc0
= 3, .opc1
= 3, .crn
= 2, .crm
= 4, .opc2
= 1,
6849 .access
= PL0_R
, .readfn
= rndr_readfn
},
6852 #ifndef CONFIG_USER_ONLY
6853 static void dccvap_writefn(CPUARMState
*env
, const ARMCPRegInfo
*opaque
,
6856 ARMCPU
*cpu
= env_archcpu(env
);
6857 /* CTR_EL0 System register -> DminLine, bits [19:16] */
6858 uint64_t dline_size
= 4 << ((cpu
->ctr
>> 16) & 0xF);
6859 uint64_t vaddr_in
= (uint64_t) value
;
6860 uint64_t vaddr
= vaddr_in
& ~(dline_size
- 1);
6862 int mem_idx
= cpu_mmu_index(env
, false);
6864 /* This won't be crossing page boundaries */
6865 haddr
= probe_read(env
, vaddr
, dline_size
, mem_idx
, GETPC());
6871 /* RCU lock is already being held */
6872 mr
= memory_region_from_host(haddr
, &offset
);
6875 memory_region_writeback(mr
, offset
, dline_size
);
6880 static const ARMCPRegInfo dcpop_reg
[] = {
6881 { .name
= "DC_CVAP", .state
= ARM_CP_STATE_AA64
,
6882 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 1,
6883 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
,
6884 .accessfn
= aa64_cacheop_poc_access
, .writefn
= dccvap_writefn
},
6887 static const ARMCPRegInfo dcpodp_reg
[] = {
6888 { .name
= "DC_CVADP", .state
= ARM_CP_STATE_AA64
,
6889 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 1,
6890 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
,
6891 .accessfn
= aa64_cacheop_poc_access
, .writefn
= dccvap_writefn
},
6893 #endif /*CONFIG_USER_ONLY*/
6895 static CPAccessResult
access_aa64_tid5(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6898 if ((arm_current_el(env
) < 2) && (arm_hcr_el2_eff(env
) & HCR_TID5
)) {
6899 return CP_ACCESS_TRAP_EL2
;
6902 return CP_ACCESS_OK
;
6905 static CPAccessResult
access_mte(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6908 int el
= arm_current_el(env
);
6910 if (el
< 2 && arm_is_el2_enabled(env
)) {
6911 uint64_t hcr
= arm_hcr_el2_eff(env
);
6912 if (!(hcr
& HCR_ATA
) && (!(hcr
& HCR_E2H
) || !(hcr
& HCR_TGE
))) {
6913 return CP_ACCESS_TRAP_EL2
;
6917 arm_feature(env
, ARM_FEATURE_EL3
) &&
6918 !(env
->cp15
.scr_el3
& SCR_ATA
)) {
6919 return CP_ACCESS_TRAP_EL3
;
6921 return CP_ACCESS_OK
;
6924 static uint64_t tco_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6926 return env
->pstate
& PSTATE_TCO
;
6929 static void tco_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
6931 env
->pstate
= (env
->pstate
& ~PSTATE_TCO
) | (val
& PSTATE_TCO
);
6934 static const ARMCPRegInfo mte_reginfo
[] = {
6935 { .name
= "TFSRE0_EL1", .state
= ARM_CP_STATE_AA64
,
6936 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 6, .opc2
= 1,
6937 .access
= PL1_RW
, .accessfn
= access_mte
,
6938 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[0]) },
6939 { .name
= "TFSR_EL1", .state
= ARM_CP_STATE_AA64
,
6940 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 6, .opc2
= 0,
6941 .access
= PL1_RW
, .accessfn
= access_mte
,
6942 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[1]) },
6943 { .name
= "TFSR_EL2", .state
= ARM_CP_STATE_AA64
,
6944 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 6, .opc2
= 0,
6945 .access
= PL2_RW
, .accessfn
= access_mte
,
6946 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[2]) },
6947 { .name
= "TFSR_EL3", .state
= ARM_CP_STATE_AA64
,
6948 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 6, .opc2
= 0,
6950 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[3]) },
6951 { .name
= "RGSR_EL1", .state
= ARM_CP_STATE_AA64
,
6952 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 5,
6953 .access
= PL1_RW
, .accessfn
= access_mte
,
6954 .fieldoffset
= offsetof(CPUARMState
, cp15
.rgsr_el1
) },
6955 { .name
= "GCR_EL1", .state
= ARM_CP_STATE_AA64
,
6956 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 6,
6957 .access
= PL1_RW
, .accessfn
= access_mte
,
6958 .fieldoffset
= offsetof(CPUARMState
, cp15
.gcr_el1
) },
6959 { .name
= "GMID_EL1", .state
= ARM_CP_STATE_AA64
,
6960 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 4,
6961 .access
= PL1_R
, .accessfn
= access_aa64_tid5
,
6962 .type
= ARM_CP_CONST
, .resetvalue
= GMID_EL1_BS
},
6963 { .name
= "TCO", .state
= ARM_CP_STATE_AA64
,
6964 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 7,
6965 .type
= ARM_CP_NO_RAW
,
6966 .access
= PL0_RW
, .readfn
= tco_read
, .writefn
= tco_write
},
6967 { .name
= "DC_IGVAC", .state
= ARM_CP_STATE_AA64
,
6968 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 3,
6969 .type
= ARM_CP_NOP
, .access
= PL1_W
,
6970 .accessfn
= aa64_cacheop_poc_access
},
6971 { .name
= "DC_IGSW", .state
= ARM_CP_STATE_AA64
,
6972 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 4,
6973 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
6974 { .name
= "DC_IGDVAC", .state
= ARM_CP_STATE_AA64
,
6975 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 5,
6976 .type
= ARM_CP_NOP
, .access
= PL1_W
,
6977 .accessfn
= aa64_cacheop_poc_access
},
6978 { .name
= "DC_IGDSW", .state
= ARM_CP_STATE_AA64
,
6979 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 6,
6980 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
6981 { .name
= "DC_CGSW", .state
= ARM_CP_STATE_AA64
,
6982 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 4,
6983 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
6984 { .name
= "DC_CGDSW", .state
= ARM_CP_STATE_AA64
,
6985 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 6,
6986 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
6987 { .name
= "DC_CIGSW", .state
= ARM_CP_STATE_AA64
,
6988 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 4,
6989 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
6990 { .name
= "DC_CIGDSW", .state
= ARM_CP_STATE_AA64
,
6991 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 6,
6992 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
6995 static const ARMCPRegInfo mte_tco_ro_reginfo
[] = {
6996 { .name
= "TCO", .state
= ARM_CP_STATE_AA64
,
6997 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 7,
6998 .type
= ARM_CP_CONST
, .access
= PL0_RW
, },
7001 static const ARMCPRegInfo mte_el0_cacheop_reginfo
[] = {
7002 { .name
= "DC_CGVAC", .state
= ARM_CP_STATE_AA64
,
7003 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 3,
7004 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7005 .accessfn
= aa64_cacheop_poc_access
},
7006 { .name
= "DC_CGDVAC", .state
= ARM_CP_STATE_AA64
,
7007 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 5,
7008 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7009 .accessfn
= aa64_cacheop_poc_access
},
7010 { .name
= "DC_CGVAP", .state
= ARM_CP_STATE_AA64
,
7011 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 3,
7012 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7013 .accessfn
= aa64_cacheop_poc_access
},
7014 { .name
= "DC_CGDVAP", .state
= ARM_CP_STATE_AA64
,
7015 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 5,
7016 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7017 .accessfn
= aa64_cacheop_poc_access
},
7018 { .name
= "DC_CGVADP", .state
= ARM_CP_STATE_AA64
,
7019 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 3,
7020 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7021 .accessfn
= aa64_cacheop_poc_access
},
7022 { .name
= "DC_CGDVADP", .state
= ARM_CP_STATE_AA64
,
7023 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 5,
7024 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7025 .accessfn
= aa64_cacheop_poc_access
},
7026 { .name
= "DC_CIGVAC", .state
= ARM_CP_STATE_AA64
,
7027 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 3,
7028 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7029 .accessfn
= aa64_cacheop_poc_access
},
7030 { .name
= "DC_CIGDVAC", .state
= ARM_CP_STATE_AA64
,
7031 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 5,
7032 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7033 .accessfn
= aa64_cacheop_poc_access
},
7034 { .name
= "DC_GVA", .state
= ARM_CP_STATE_AA64
,
7035 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 3,
7036 .access
= PL0_W
, .type
= ARM_CP_DC_GVA
,
7037 #ifndef CONFIG_USER_ONLY
7038 /* Avoid overhead of an access check that always passes in user-mode */
7039 .accessfn
= aa64_zva_access
,
7042 { .name
= "DC_GZVA", .state
= ARM_CP_STATE_AA64
,
7043 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 4,
7044 .access
= PL0_W
, .type
= ARM_CP_DC_GZVA
,
7045 #ifndef CONFIG_USER_ONLY
7046 /* Avoid overhead of an access check that always passes in user-mode */
7047 .accessfn
= aa64_zva_access
,
7052 static CPAccessResult
access_scxtnum(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7055 uint64_t hcr
= arm_hcr_el2_eff(env
);
7056 int el
= arm_current_el(env
);
7058 if (el
== 0 && !((hcr
& HCR_E2H
) && (hcr
& HCR_TGE
))) {
7059 if (env
->cp15
.sctlr_el
[1] & SCTLR_TSCXT
) {
7060 if (hcr
& HCR_TGE
) {
7061 return CP_ACCESS_TRAP_EL2
;
7063 return CP_ACCESS_TRAP
;
7065 } else if (el
< 2 && (env
->cp15
.sctlr_el
[2] & SCTLR_TSCXT
)) {
7066 return CP_ACCESS_TRAP_EL2
;
7068 if (el
< 2 && arm_is_el2_enabled(env
) && !(hcr
& HCR_ENSCXT
)) {
7069 return CP_ACCESS_TRAP_EL2
;
7072 && arm_feature(env
, ARM_FEATURE_EL3
)
7073 && !(env
->cp15
.scr_el3
& SCR_ENSCXT
)) {
7074 return CP_ACCESS_TRAP_EL3
;
7076 return CP_ACCESS_OK
;
7079 static const ARMCPRegInfo scxtnum_reginfo
[] = {
7080 { .name
= "SCXTNUM_EL0", .state
= ARM_CP_STATE_AA64
,
7081 .opc0
= 3, .opc1
= 3, .crn
= 13, .crm
= 0, .opc2
= 7,
7082 .access
= PL0_RW
, .accessfn
= access_scxtnum
,
7083 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[0]) },
7084 { .name
= "SCXTNUM_EL1", .state
= ARM_CP_STATE_AA64
,
7085 .opc0
= 3, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 7,
7086 .access
= PL1_RW
, .accessfn
= access_scxtnum
,
7087 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[1]) },
7088 { .name
= "SCXTNUM_EL2", .state
= ARM_CP_STATE_AA64
,
7089 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 7,
7090 .access
= PL2_RW
, .accessfn
= access_scxtnum
,
7091 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[2]) },
7092 { .name
= "SCXTNUM_EL3", .state
= ARM_CP_STATE_AA64
,
7093 .opc0
= 3, .opc1
= 6, .crn
= 13, .crm
= 0, .opc2
= 7,
7095 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[3]) },
7097 #endif /* TARGET_AARCH64 */
7099 static CPAccessResult
access_predinv(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7102 int el
= arm_current_el(env
);
7105 uint64_t sctlr
= arm_sctlr(env
, el
);
7106 if (!(sctlr
& SCTLR_EnRCTX
)) {
7107 return CP_ACCESS_TRAP
;
7109 } else if (el
== 1) {
7110 uint64_t hcr
= arm_hcr_el2_eff(env
);
7112 return CP_ACCESS_TRAP_EL2
;
7115 return CP_ACCESS_OK
;
7118 static const ARMCPRegInfo predinv_reginfo
[] = {
7119 { .name
= "CFP_RCTX", .state
= ARM_CP_STATE_AA64
,
7120 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 4,
7121 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7122 { .name
= "DVP_RCTX", .state
= ARM_CP_STATE_AA64
,
7123 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 5,
7124 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7125 { .name
= "CPP_RCTX", .state
= ARM_CP_STATE_AA64
,
7126 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 7,
7127 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7129 * Note the AArch32 opcodes have a different OPC1.
7131 { .name
= "CFPRCTX", .state
= ARM_CP_STATE_AA32
,
7132 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 4,
7133 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7134 { .name
= "DVPRCTX", .state
= ARM_CP_STATE_AA32
,
7135 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 5,
7136 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7137 { .name
= "CPPRCTX", .state
= ARM_CP_STATE_AA32
,
7138 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 7,
7139 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7142 static uint64_t ccsidr2_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7144 /* Read the high 32 bits of the current CCSIDR */
7145 return extract64(ccsidr_read(env
, ri
), 32, 32);
7148 static const ARMCPRegInfo ccsidr2_reginfo
[] = {
7149 { .name
= "CCSIDR2", .state
= ARM_CP_STATE_BOTH
,
7150 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 2,
7152 .accessfn
= access_aa64_tid2
,
7153 .readfn
= ccsidr2_read
, .type
= ARM_CP_NO_RAW
},
7156 static CPAccessResult
access_aa64_tid3(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7159 if ((arm_current_el(env
) < 2) && (arm_hcr_el2_eff(env
) & HCR_TID3
)) {
7160 return CP_ACCESS_TRAP_EL2
;
7163 return CP_ACCESS_OK
;
7166 static CPAccessResult
access_aa32_tid3(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7169 if (arm_feature(env
, ARM_FEATURE_V8
)) {
7170 return access_aa64_tid3(env
, ri
, isread
);
7173 return CP_ACCESS_OK
;
7176 static CPAccessResult
access_jazelle(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7179 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID0
)) {
7180 return CP_ACCESS_TRAP_EL2
;
7183 return CP_ACCESS_OK
;
7186 static CPAccessResult
access_joscr_jmcr(CPUARMState
*env
,
7187 const ARMCPRegInfo
*ri
, bool isread
)
7190 * HSTR.TJDBX traps JOSCR and JMCR accesses, but it exists only
7191 * in v7A, not in v8A.
7193 if (!arm_feature(env
, ARM_FEATURE_V8
) &&
7194 arm_current_el(env
) < 2 && !arm_is_secure_below_el3(env
) &&
7195 (env
->cp15
.hstr_el2
& HSTR_TJDBX
)) {
7196 return CP_ACCESS_TRAP_EL2
;
7198 return CP_ACCESS_OK
;
7201 static const ARMCPRegInfo jazelle_regs
[] = {
7203 .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 7, .opc2
= 0,
7204 .access
= PL1_R
, .accessfn
= access_jazelle
,
7205 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7207 .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 7, .opc2
= 0,
7208 .accessfn
= access_joscr_jmcr
,
7209 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7211 .cp
= 14, .crn
= 2, .crm
= 0, .opc1
= 7, .opc2
= 0,
7212 .accessfn
= access_joscr_jmcr
,
7213 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7216 static const ARMCPRegInfo contextidr_el2
= {
7217 .name
= "CONTEXTIDR_EL2", .state
= ARM_CP_STATE_AA64
,
7218 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 1,
7220 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[2])
7223 static const ARMCPRegInfo vhe_reginfo
[] = {
7224 { .name
= "TTBR1_EL2", .state
= ARM_CP_STATE_AA64
,
7225 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 1,
7226 .access
= PL2_RW
, .writefn
= vmsa_tcr_ttbr_el2_write
,
7227 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr1_el
[2]) },
7228 #ifndef CONFIG_USER_ONLY
7229 { .name
= "CNTHV_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
7230 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 2,
7232 offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYPVIRT
].cval
),
7233 .type
= ARM_CP_IO
, .access
= PL2_RW
,
7234 .writefn
= gt_hv_cval_write
, .raw_writefn
= raw_write
},
7235 { .name
= "CNTHV_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
7236 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 0,
7237 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL2_RW
,
7238 .resetfn
= gt_hv_timer_reset
,
7239 .readfn
= gt_hv_tval_read
, .writefn
= gt_hv_tval_write
},
7240 { .name
= "CNTHV_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
7242 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 1,
7244 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYPVIRT
].ctl
),
7245 .writefn
= gt_hv_ctl_write
, .raw_writefn
= raw_write
},
7246 { .name
= "CNTP_CTL_EL02", .state
= ARM_CP_STATE_AA64
,
7247 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 1,
7248 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7249 .access
= PL2_RW
, .accessfn
= e2h_access
,
7250 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
7251 .writefn
= gt_phys_ctl_write
, .raw_writefn
= raw_write
},
7252 { .name
= "CNTV_CTL_EL02", .state
= ARM_CP_STATE_AA64
,
7253 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 1,
7254 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7255 .access
= PL2_RW
, .accessfn
= e2h_access
,
7256 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
7257 .writefn
= gt_virt_ctl_write
, .raw_writefn
= raw_write
},
7258 { .name
= "CNTP_TVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7259 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 0,
7260 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
| ARM_CP_ALIAS
,
7261 .access
= PL2_RW
, .accessfn
= e2h_access
,
7262 .readfn
= gt_phys_tval_read
, .writefn
= gt_phys_tval_write
},
7263 { .name
= "CNTV_TVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7264 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 0,
7265 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
| ARM_CP_ALIAS
,
7266 .access
= PL2_RW
, .accessfn
= e2h_access
,
7267 .readfn
= gt_virt_tval_read
, .writefn
= gt_virt_tval_write
},
7268 { .name
= "CNTP_CVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7269 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 2,
7270 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7271 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
7272 .access
= PL2_RW
, .accessfn
= e2h_access
,
7273 .writefn
= gt_phys_cval_write
, .raw_writefn
= raw_write
},
7274 { .name
= "CNTV_CVAL_EL02", .state
= ARM_CP_STATE_AA64
,
7275 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 2,
7276 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7277 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
7278 .access
= PL2_RW
, .accessfn
= e2h_access
,
7279 .writefn
= gt_virt_cval_write
, .raw_writefn
= raw_write
},
7283 #ifndef CONFIG_USER_ONLY
7284 static const ARMCPRegInfo ats1e1_reginfo
[] = {
7285 { .name
= "AT_S1E1R", .state
= ARM_CP_STATE_AA64
,
7286 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 0,
7287 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7288 .writefn
= ats_write64
},
7289 { .name
= "AT_S1E1W", .state
= ARM_CP_STATE_AA64
,
7290 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 1,
7291 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7292 .writefn
= ats_write64
},
7295 static const ARMCPRegInfo ats1cp_reginfo
[] = {
7296 { .name
= "ATS1CPRP",
7297 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 0,
7298 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7299 .writefn
= ats_write
},
7300 { .name
= "ATS1CPWP",
7301 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 1,
7302 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
7303 .writefn
= ats_write
},
7308 * ACTLR2 and HACTLR2 map to ACTLR_EL1[63:32] and
7309 * ACTLR_EL2[63:32]. They exist only if the ID_MMFR4.AC2 field
7310 * is non-zero, which is never for ARMv7, optionally in ARMv8
7311 * and mandatorily for ARMv8.2 and up.
7312 * ACTLR2 is banked for S and NS if EL3 is AArch32. Since QEMU's
7313 * implementation is RAZ/WI we can ignore this detail, as we
7316 static const ARMCPRegInfo actlr2_hactlr2_reginfo
[] = {
7317 { .name
= "ACTLR2", .state
= ARM_CP_STATE_AA32
,
7318 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 3,
7319 .access
= PL1_RW
, .accessfn
= access_tacr
,
7320 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7321 { .name
= "HACTLR2", .state
= ARM_CP_STATE_AA32
,
7322 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 3,
7323 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
7327 void register_cp_regs_for_features(ARMCPU
*cpu
)
7329 /* Register all the coprocessor registers based on feature bits */
7330 CPUARMState
*env
= &cpu
->env
;
7331 if (arm_feature(env
, ARM_FEATURE_M
)) {
7332 /* M profile has no coprocessor registers */
7336 define_arm_cp_regs(cpu
, cp_reginfo
);
7337 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
7338 /* Must go early as it is full of wildcards that may be
7339 * overridden by later definitions.
7341 define_arm_cp_regs(cpu
, not_v8_cp_reginfo
);
7344 if (arm_feature(env
, ARM_FEATURE_V6
)) {
7345 /* The ID registers all have impdef reset values */
7346 ARMCPRegInfo v6_idregs
[] = {
7347 { .name
= "ID_PFR0", .state
= ARM_CP_STATE_BOTH
,
7348 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 0,
7349 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7350 .accessfn
= access_aa32_tid3
,
7351 .resetvalue
= cpu
->isar
.id_pfr0
},
7352 /* ID_PFR1 is not a plain ARM_CP_CONST because we don't know
7353 * the value of the GIC field until after we define these regs.
7355 { .name
= "ID_PFR1", .state
= ARM_CP_STATE_BOTH
,
7356 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 1,
7357 .access
= PL1_R
, .type
= ARM_CP_NO_RAW
,
7358 .accessfn
= access_aa32_tid3
,
7359 .readfn
= id_pfr1_read
,
7360 .writefn
= arm_cp_write_ignore
},
7361 { .name
= "ID_DFR0", .state
= ARM_CP_STATE_BOTH
,
7362 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 2,
7363 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7364 .accessfn
= access_aa32_tid3
,
7365 .resetvalue
= cpu
->isar
.id_dfr0
},
7366 { .name
= "ID_AFR0", .state
= ARM_CP_STATE_BOTH
,
7367 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 3,
7368 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7369 .accessfn
= access_aa32_tid3
,
7370 .resetvalue
= cpu
->id_afr0
},
7371 { .name
= "ID_MMFR0", .state
= ARM_CP_STATE_BOTH
,
7372 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 4,
7373 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7374 .accessfn
= access_aa32_tid3
,
7375 .resetvalue
= cpu
->isar
.id_mmfr0
},
7376 { .name
= "ID_MMFR1", .state
= ARM_CP_STATE_BOTH
,
7377 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 5,
7378 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7379 .accessfn
= access_aa32_tid3
,
7380 .resetvalue
= cpu
->isar
.id_mmfr1
},
7381 { .name
= "ID_MMFR2", .state
= ARM_CP_STATE_BOTH
,
7382 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 6,
7383 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7384 .accessfn
= access_aa32_tid3
,
7385 .resetvalue
= cpu
->isar
.id_mmfr2
},
7386 { .name
= "ID_MMFR3", .state
= ARM_CP_STATE_BOTH
,
7387 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 7,
7388 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7389 .accessfn
= access_aa32_tid3
,
7390 .resetvalue
= cpu
->isar
.id_mmfr3
},
7391 { .name
= "ID_ISAR0", .state
= ARM_CP_STATE_BOTH
,
7392 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 0,
7393 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7394 .accessfn
= access_aa32_tid3
,
7395 .resetvalue
= cpu
->isar
.id_isar0
},
7396 { .name
= "ID_ISAR1", .state
= ARM_CP_STATE_BOTH
,
7397 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 1,
7398 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7399 .accessfn
= access_aa32_tid3
,
7400 .resetvalue
= cpu
->isar
.id_isar1
},
7401 { .name
= "ID_ISAR2", .state
= ARM_CP_STATE_BOTH
,
7402 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 2,
7403 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7404 .accessfn
= access_aa32_tid3
,
7405 .resetvalue
= cpu
->isar
.id_isar2
},
7406 { .name
= "ID_ISAR3", .state
= ARM_CP_STATE_BOTH
,
7407 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 3,
7408 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7409 .accessfn
= access_aa32_tid3
,
7410 .resetvalue
= cpu
->isar
.id_isar3
},
7411 { .name
= "ID_ISAR4", .state
= ARM_CP_STATE_BOTH
,
7412 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 4,
7413 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7414 .accessfn
= access_aa32_tid3
,
7415 .resetvalue
= cpu
->isar
.id_isar4
},
7416 { .name
= "ID_ISAR5", .state
= ARM_CP_STATE_BOTH
,
7417 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 5,
7418 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7419 .accessfn
= access_aa32_tid3
,
7420 .resetvalue
= cpu
->isar
.id_isar5
},
7421 { .name
= "ID_MMFR4", .state
= ARM_CP_STATE_BOTH
,
7422 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 6,
7423 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7424 .accessfn
= access_aa32_tid3
,
7425 .resetvalue
= cpu
->isar
.id_mmfr4
},
7426 { .name
= "ID_ISAR6", .state
= ARM_CP_STATE_BOTH
,
7427 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 7,
7428 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7429 .accessfn
= access_aa32_tid3
,
7430 .resetvalue
= cpu
->isar
.id_isar6
},
7432 define_arm_cp_regs(cpu
, v6_idregs
);
7433 define_arm_cp_regs(cpu
, v6_cp_reginfo
);
7435 define_arm_cp_regs(cpu
, not_v6_cp_reginfo
);
7437 if (arm_feature(env
, ARM_FEATURE_V6K
)) {
7438 define_arm_cp_regs(cpu
, v6k_cp_reginfo
);
7440 if (arm_feature(env
, ARM_FEATURE_V7MP
) &&
7441 !arm_feature(env
, ARM_FEATURE_PMSA
)) {
7442 define_arm_cp_regs(cpu
, v7mp_cp_reginfo
);
7444 if (arm_feature(env
, ARM_FEATURE_V7VE
)) {
7445 define_arm_cp_regs(cpu
, pmovsset_cp_reginfo
);
7447 if (arm_feature(env
, ARM_FEATURE_V7
)) {
7448 ARMCPRegInfo clidr
= {
7449 .name
= "CLIDR", .state
= ARM_CP_STATE_BOTH
,
7450 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 1,
7451 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7452 .accessfn
= access_aa64_tid2
,
7453 .resetvalue
= cpu
->clidr
7455 define_one_arm_cp_reg(cpu
, &clidr
);
7456 define_arm_cp_regs(cpu
, v7_cp_reginfo
);
7457 define_debug_regs(cpu
);
7458 define_pmu_regs(cpu
);
7460 define_arm_cp_regs(cpu
, not_v7_cp_reginfo
);
7462 if (arm_feature(env
, ARM_FEATURE_V8
)) {
7464 * v8 ID registers, which all have impdef reset values.
7465 * Note that within the ID register ranges the unused slots
7466 * must all RAZ, not UNDEF; future architecture versions may
7467 * define new registers here.
7468 * ID registers which are AArch64 views of the AArch32 ID registers
7469 * which already existed in v6 and v7 are handled elsewhere,
7473 ARMCPRegInfo v8_idregs
[] = {
7475 * ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST in system
7476 * emulation because we don't know the right value for the
7477 * GIC field until after we define these regs.
7479 { .name
= "ID_AA64PFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7480 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 0,
7482 #ifdef CONFIG_USER_ONLY
7483 .type
= ARM_CP_CONST
,
7484 .resetvalue
= cpu
->isar
.id_aa64pfr0
7486 .type
= ARM_CP_NO_RAW
,
7487 .accessfn
= access_aa64_tid3
,
7488 .readfn
= id_aa64pfr0_read
,
7489 .writefn
= arm_cp_write_ignore
7492 { .name
= "ID_AA64PFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7493 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 1,
7494 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7495 .accessfn
= access_aa64_tid3
,
7496 .resetvalue
= cpu
->isar
.id_aa64pfr1
},
7497 { .name
= "ID_AA64PFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7498 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 2,
7499 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7500 .accessfn
= access_aa64_tid3
,
7502 { .name
= "ID_AA64PFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7503 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 3,
7504 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7505 .accessfn
= access_aa64_tid3
,
7507 { .name
= "ID_AA64ZFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7508 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 4,
7509 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7510 .accessfn
= access_aa64_tid3
,
7511 .resetvalue
= cpu
->isar
.id_aa64zfr0
},
7512 { .name
= "ID_AA64SMFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7513 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 5,
7514 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7515 .accessfn
= access_aa64_tid3
,
7516 .resetvalue
= cpu
->isar
.id_aa64smfr0
},
7517 { .name
= "ID_AA64PFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7518 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 6,
7519 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7520 .accessfn
= access_aa64_tid3
,
7522 { .name
= "ID_AA64PFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7523 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 7,
7524 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7525 .accessfn
= access_aa64_tid3
,
7527 { .name
= "ID_AA64DFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7528 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 0,
7529 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7530 .accessfn
= access_aa64_tid3
,
7531 .resetvalue
= cpu
->isar
.id_aa64dfr0
},
7532 { .name
= "ID_AA64DFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7533 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 1,
7534 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7535 .accessfn
= access_aa64_tid3
,
7536 .resetvalue
= cpu
->isar
.id_aa64dfr1
},
7537 { .name
= "ID_AA64DFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7538 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 2,
7539 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7540 .accessfn
= access_aa64_tid3
,
7542 { .name
= "ID_AA64DFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7543 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 3,
7544 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7545 .accessfn
= access_aa64_tid3
,
7547 { .name
= "ID_AA64AFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7548 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 4,
7549 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7550 .accessfn
= access_aa64_tid3
,
7551 .resetvalue
= cpu
->id_aa64afr0
},
7552 { .name
= "ID_AA64AFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7553 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 5,
7554 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7555 .accessfn
= access_aa64_tid3
,
7556 .resetvalue
= cpu
->id_aa64afr1
},
7557 { .name
= "ID_AA64AFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7558 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 6,
7559 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7560 .accessfn
= access_aa64_tid3
,
7562 { .name
= "ID_AA64AFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7563 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 7,
7564 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7565 .accessfn
= access_aa64_tid3
,
7567 { .name
= "ID_AA64ISAR0_EL1", .state
= ARM_CP_STATE_AA64
,
7568 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 0,
7569 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7570 .accessfn
= access_aa64_tid3
,
7571 .resetvalue
= cpu
->isar
.id_aa64isar0
},
7572 { .name
= "ID_AA64ISAR1_EL1", .state
= ARM_CP_STATE_AA64
,
7573 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 1,
7574 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7575 .accessfn
= access_aa64_tid3
,
7576 .resetvalue
= cpu
->isar
.id_aa64isar1
},
7577 { .name
= "ID_AA64ISAR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7578 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 2,
7579 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7580 .accessfn
= access_aa64_tid3
,
7582 { .name
= "ID_AA64ISAR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7583 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 3,
7584 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7585 .accessfn
= access_aa64_tid3
,
7587 { .name
= "ID_AA64ISAR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7588 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 4,
7589 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7590 .accessfn
= access_aa64_tid3
,
7592 { .name
= "ID_AA64ISAR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7593 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 5,
7594 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7595 .accessfn
= access_aa64_tid3
,
7597 { .name
= "ID_AA64ISAR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7598 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 6,
7599 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7600 .accessfn
= access_aa64_tid3
,
7602 { .name
= "ID_AA64ISAR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7603 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 7,
7604 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7605 .accessfn
= access_aa64_tid3
,
7607 { .name
= "ID_AA64MMFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7608 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 0,
7609 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7610 .accessfn
= access_aa64_tid3
,
7611 .resetvalue
= cpu
->isar
.id_aa64mmfr0
},
7612 { .name
= "ID_AA64MMFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7613 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 1,
7614 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7615 .accessfn
= access_aa64_tid3
,
7616 .resetvalue
= cpu
->isar
.id_aa64mmfr1
},
7617 { .name
= "ID_AA64MMFR2_EL1", .state
= ARM_CP_STATE_AA64
,
7618 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 2,
7619 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7620 .accessfn
= access_aa64_tid3
,
7621 .resetvalue
= cpu
->isar
.id_aa64mmfr2
},
7622 { .name
= "ID_AA64MMFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7623 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 3,
7624 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7625 .accessfn
= access_aa64_tid3
,
7627 { .name
= "ID_AA64MMFR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7628 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 4,
7629 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7630 .accessfn
= access_aa64_tid3
,
7632 { .name
= "ID_AA64MMFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7633 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 5,
7634 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7635 .accessfn
= access_aa64_tid3
,
7637 { .name
= "ID_AA64MMFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7638 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 6,
7639 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7640 .accessfn
= access_aa64_tid3
,
7642 { .name
= "ID_AA64MMFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
7643 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 7,
7644 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7645 .accessfn
= access_aa64_tid3
,
7647 { .name
= "MVFR0_EL1", .state
= ARM_CP_STATE_AA64
,
7648 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 0,
7649 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7650 .accessfn
= access_aa64_tid3
,
7651 .resetvalue
= cpu
->isar
.mvfr0
},
7652 { .name
= "MVFR1_EL1", .state
= ARM_CP_STATE_AA64
,
7653 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 1,
7654 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7655 .accessfn
= access_aa64_tid3
,
7656 .resetvalue
= cpu
->isar
.mvfr1
},
7657 { .name
= "MVFR2_EL1", .state
= ARM_CP_STATE_AA64
,
7658 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 2,
7659 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7660 .accessfn
= access_aa64_tid3
,
7661 .resetvalue
= cpu
->isar
.mvfr2
},
7663 * "0, c0, c3, {0,1,2}" are the encodings corresponding to
7664 * AArch64 MVFR[012]_EL1. Define the STATE_AA32 encoding
7665 * as RAZ, since it is in the "reserved for future ID
7666 * registers, RAZ" part of the AArch32 encoding space.
7668 { .name
= "RES_0_C0_C3_0", .state
= ARM_CP_STATE_AA32
,
7669 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 0,
7670 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7671 .accessfn
= access_aa64_tid3
,
7673 { .name
= "RES_0_C0_C3_1", .state
= ARM_CP_STATE_AA32
,
7674 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 1,
7675 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7676 .accessfn
= access_aa64_tid3
,
7678 { .name
= "RES_0_C0_C3_2", .state
= ARM_CP_STATE_AA32
,
7679 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 2,
7680 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7681 .accessfn
= access_aa64_tid3
,
7684 * Other encodings in "0, c0, c3, ..." are STATE_BOTH because
7685 * they're also RAZ for AArch64, and in v8 are gradually
7686 * being filled with AArch64-view-of-AArch32-ID-register
7687 * for new ID registers.
7689 { .name
= "RES_0_C0_C3_3", .state
= ARM_CP_STATE_BOTH
,
7690 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 3,
7691 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7692 .accessfn
= access_aa64_tid3
,
7694 { .name
= "ID_PFR2", .state
= ARM_CP_STATE_BOTH
,
7695 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 4,
7696 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7697 .accessfn
= access_aa64_tid3
,
7698 .resetvalue
= cpu
->isar
.id_pfr2
},
7699 { .name
= "ID_DFR1", .state
= ARM_CP_STATE_BOTH
,
7700 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 5,
7701 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7702 .accessfn
= access_aa64_tid3
,
7703 .resetvalue
= cpu
->isar
.id_dfr1
},
7704 { .name
= "ID_MMFR5", .state
= ARM_CP_STATE_BOTH
,
7705 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 6,
7706 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7707 .accessfn
= access_aa64_tid3
,
7708 .resetvalue
= cpu
->isar
.id_mmfr5
},
7709 { .name
= "RES_0_C0_C3_7", .state
= ARM_CP_STATE_BOTH
,
7710 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 7,
7711 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7712 .accessfn
= access_aa64_tid3
,
7714 { .name
= "PMCEID0", .state
= ARM_CP_STATE_AA32
,
7715 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 6,
7716 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7717 .resetvalue
= extract64(cpu
->pmceid0
, 0, 32) },
7718 { .name
= "PMCEID0_EL0", .state
= ARM_CP_STATE_AA64
,
7719 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 6,
7720 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7721 .resetvalue
= cpu
->pmceid0
},
7722 { .name
= "PMCEID1", .state
= ARM_CP_STATE_AA32
,
7723 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 7,
7724 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7725 .resetvalue
= extract64(cpu
->pmceid1
, 0, 32) },
7726 { .name
= "PMCEID1_EL0", .state
= ARM_CP_STATE_AA64
,
7727 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 7,
7728 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7729 .resetvalue
= cpu
->pmceid1
},
7731 #ifdef CONFIG_USER_ONLY
7732 static const ARMCPRegUserSpaceInfo v8_user_idregs
[] = {
7733 { .name
= "ID_AA64PFR0_EL1",
7734 .exported_bits
= 0x000f000f00ff0000,
7735 .fixed_bits
= 0x0000000000000011 },
7736 { .name
= "ID_AA64PFR1_EL1",
7737 .exported_bits
= 0x00000000000000f0 },
7738 { .name
= "ID_AA64PFR*_EL1_RESERVED",
7740 { .name
= "ID_AA64ZFR0_EL1" },
7741 { .name
= "ID_AA64MMFR0_EL1",
7742 .fixed_bits
= 0x00000000ff000000 },
7743 { .name
= "ID_AA64MMFR1_EL1" },
7744 { .name
= "ID_AA64MMFR*_EL1_RESERVED",
7746 { .name
= "ID_AA64DFR0_EL1",
7747 .fixed_bits
= 0x0000000000000006 },
7748 { .name
= "ID_AA64DFR1_EL1" },
7749 { .name
= "ID_AA64DFR*_EL1_RESERVED",
7751 { .name
= "ID_AA64AFR*",
7753 { .name
= "ID_AA64ISAR0_EL1",
7754 .exported_bits
= 0x00fffffff0fffff0 },
7755 { .name
= "ID_AA64ISAR1_EL1",
7756 .exported_bits
= 0x000000f0ffffffff },
7757 { .name
= "ID_AA64ISAR*_EL1_RESERVED",
7760 modify_arm_cp_regs(v8_idregs
, v8_user_idregs
);
7762 /* RVBAR_EL1 is only implemented if EL1 is the highest EL */
7763 if (!arm_feature(env
, ARM_FEATURE_EL3
) &&
7764 !arm_feature(env
, ARM_FEATURE_EL2
)) {
7765 ARMCPRegInfo rvbar
= {
7766 .name
= "RVBAR_EL1", .state
= ARM_CP_STATE_AA64
,
7767 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
7769 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
),
7771 define_one_arm_cp_reg(cpu
, &rvbar
);
7773 define_arm_cp_regs(cpu
, v8_idregs
);
7774 define_arm_cp_regs(cpu
, v8_cp_reginfo
);
7776 for (i
= 4; i
< 16; i
++) {
7778 * Encodings in "0, c0, {c4-c7}, {0-7}" are RAZ for AArch32.
7779 * For pre-v8 cores there are RAZ patterns for these in
7780 * id_pre_v8_midr_cp_reginfo[]; for v8 we do that here.
7781 * v8 extends the "must RAZ" part of the ID register space
7782 * to also cover c0, 0, c{8-15}, {0-7}.
7783 * These are STATE_AA32 because in the AArch64 sysreg space
7784 * c4-c7 is where the AArch64 ID registers live (and we've
7785 * already defined those in v8_idregs[]), and c8-c15 are not
7786 * "must RAZ" for AArch64.
7788 g_autofree
char *name
= g_strdup_printf("RES_0_C0_C%d_X", i
);
7789 ARMCPRegInfo v8_aa32_raz_idregs
= {
7791 .state
= ARM_CP_STATE_AA32
,
7792 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= CP_ANY
,
7793 .access
= PL1_R
, .type
= ARM_CP_CONST
,
7794 .accessfn
= access_aa64_tid3
,
7796 define_one_arm_cp_reg(cpu
, &v8_aa32_raz_idregs
);
7801 * Register the base EL2 cpregs.
7802 * Pre v8, these registers are implemented only as part of the
7803 * Virtualization Extensions (EL2 present). Beginning with v8,
7804 * if EL2 is missing but EL3 is enabled, mostly these become
7805 * RES0 from EL3, with some specific exceptions.
7807 if (arm_feature(env
, ARM_FEATURE_EL2
)
7808 || (arm_feature(env
, ARM_FEATURE_EL3
)
7809 && arm_feature(env
, ARM_FEATURE_V8
))) {
7810 uint64_t vmpidr_def
= mpidr_read_val(env
);
7811 ARMCPRegInfo vpidr_regs
[] = {
7812 { .name
= "VPIDR", .state
= ARM_CP_STATE_AA32
,
7813 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
7814 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
7815 .resetvalue
= cpu
->midr
,
7816 .type
= ARM_CP_ALIAS
| ARM_CP_EL3_NO_EL2_C_NZ
,
7817 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vpidr_el2
) },
7818 { .name
= "VPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
7819 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
7820 .access
= PL2_RW
, .resetvalue
= cpu
->midr
,
7821 .type
= ARM_CP_EL3_NO_EL2_C_NZ
,
7822 .fieldoffset
= offsetof(CPUARMState
, cp15
.vpidr_el2
) },
7823 { .name
= "VMPIDR", .state
= ARM_CP_STATE_AA32
,
7824 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
7825 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
7826 .resetvalue
= vmpidr_def
,
7827 .type
= ARM_CP_ALIAS
| ARM_CP_EL3_NO_EL2_C_NZ
,
7828 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vmpidr_el2
) },
7829 { .name
= "VMPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
7830 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
7831 .access
= PL2_RW
, .resetvalue
= vmpidr_def
,
7832 .type
= ARM_CP_EL3_NO_EL2_C_NZ
,
7833 .fieldoffset
= offsetof(CPUARMState
, cp15
.vmpidr_el2
) },
7836 * The only field of MDCR_EL2 that has a defined architectural reset
7837 * value is MDCR_EL2.HPMN which should reset to the value of PMCR_EL0.N.
7839 ARMCPRegInfo mdcr_el2
= {
7840 .name
= "MDCR_EL2", .state
= ARM_CP_STATE_BOTH
,
7841 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 1,
7842 .writefn
= mdcr_el2_write
,
7843 .access
= PL2_RW
, .resetvalue
= pmu_num_counters(env
),
7844 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el2
),
7846 define_one_arm_cp_reg(cpu
, &mdcr_el2
);
7847 define_arm_cp_regs(cpu
, vpidr_regs
);
7848 define_arm_cp_regs(cpu
, el2_cp_reginfo
);
7849 if (arm_feature(env
, ARM_FEATURE_V8
)) {
7850 define_arm_cp_regs(cpu
, el2_v8_cp_reginfo
);
7852 if (cpu_isar_feature(aa64_sel2
, cpu
)) {
7853 define_arm_cp_regs(cpu
, el2_sec_cp_reginfo
);
7855 /* RVBAR_EL2 is only implemented if EL2 is the highest EL */
7856 if (!arm_feature(env
, ARM_FEATURE_EL3
)) {
7857 ARMCPRegInfo rvbar
= {
7858 .name
= "RVBAR_EL2", .state
= ARM_CP_STATE_AA64
,
7859 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 1,
7861 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
),
7863 define_one_arm_cp_reg(cpu
, &rvbar
);
7867 /* Register the base EL3 cpregs. */
7868 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
7869 define_arm_cp_regs(cpu
, el3_cp_reginfo
);
7870 ARMCPRegInfo el3_regs
[] = {
7871 { .name
= "RVBAR_EL3", .state
= ARM_CP_STATE_AA64
,
7872 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 1,
7874 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
),
7876 { .name
= "SCTLR_EL3", .state
= ARM_CP_STATE_AA64
,
7877 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 0,
7879 .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
7880 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[3]),
7881 .resetvalue
= cpu
->reset_sctlr
},
7884 define_arm_cp_regs(cpu
, el3_regs
);
7886 /* The behaviour of NSACR is sufficiently various that we don't
7887 * try to describe it in a single reginfo:
7888 * if EL3 is 64 bit, then trap to EL3 from S EL1,
7889 * reads as constant 0xc00 from NS EL1 and NS EL2
7890 * if EL3 is 32 bit, then RW at EL3, RO at NS EL1 and NS EL2
7891 * if v7 without EL3, register doesn't exist
7892 * if v8 without EL3, reads as constant 0xc00 from NS EL1 and NS EL2
7894 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
7895 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
7896 static const ARMCPRegInfo nsacr
= {
7897 .name
= "NSACR", .type
= ARM_CP_CONST
,
7898 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
7899 .access
= PL1_RW
, .accessfn
= nsacr_access
,
7902 define_one_arm_cp_reg(cpu
, &nsacr
);
7904 static const ARMCPRegInfo nsacr
= {
7906 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
7907 .access
= PL3_RW
| PL1_R
,
7909 .fieldoffset
= offsetof(CPUARMState
, cp15
.nsacr
)
7911 define_one_arm_cp_reg(cpu
, &nsacr
);
7914 if (arm_feature(env
, ARM_FEATURE_V8
)) {
7915 static const ARMCPRegInfo nsacr
= {
7916 .name
= "NSACR", .type
= ARM_CP_CONST
,
7917 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
7921 define_one_arm_cp_reg(cpu
, &nsacr
);
7925 if (arm_feature(env
, ARM_FEATURE_PMSA
)) {
7926 if (arm_feature(env
, ARM_FEATURE_V6
)) {
7927 /* PMSAv6 not implemented */
7928 assert(arm_feature(env
, ARM_FEATURE_V7
));
7929 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
7930 define_arm_cp_regs(cpu
, pmsav7_cp_reginfo
);
7932 define_arm_cp_regs(cpu
, pmsav5_cp_reginfo
);
7935 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
7936 define_arm_cp_regs(cpu
, vmsa_cp_reginfo
);
7937 /* TTCBR2 is introduced with ARMv8.2-AA32HPD. */
7938 if (cpu_isar_feature(aa32_hpd
, cpu
)) {
7939 define_one_arm_cp_reg(cpu
, &ttbcr2_reginfo
);
7942 if (arm_feature(env
, ARM_FEATURE_THUMB2EE
)) {
7943 define_arm_cp_regs(cpu
, t2ee_cp_reginfo
);
7945 if (arm_feature(env
, ARM_FEATURE_GENERIC_TIMER
)) {
7946 define_arm_cp_regs(cpu
, generic_timer_cp_reginfo
);
7948 if (arm_feature(env
, ARM_FEATURE_VAPA
)) {
7949 define_arm_cp_regs(cpu
, vapa_cp_reginfo
);
7951 if (arm_feature(env
, ARM_FEATURE_CACHE_TEST_CLEAN
)) {
7952 define_arm_cp_regs(cpu
, cache_test_clean_cp_reginfo
);
7954 if (arm_feature(env
, ARM_FEATURE_CACHE_DIRTY_REG
)) {
7955 define_arm_cp_regs(cpu
, cache_dirty_status_cp_reginfo
);
7957 if (arm_feature(env
, ARM_FEATURE_CACHE_BLOCK_OPS
)) {
7958 define_arm_cp_regs(cpu
, cache_block_ops_cp_reginfo
);
7960 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
7961 define_arm_cp_regs(cpu
, omap_cp_reginfo
);
7963 if (arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
7964 define_arm_cp_regs(cpu
, strongarm_cp_reginfo
);
7966 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
7967 define_arm_cp_regs(cpu
, xscale_cp_reginfo
);
7969 if (arm_feature(env
, ARM_FEATURE_DUMMY_C15_REGS
)) {
7970 define_arm_cp_regs(cpu
, dummy_c15_cp_reginfo
);
7972 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
7973 define_arm_cp_regs(cpu
, lpae_cp_reginfo
);
7975 if (cpu_isar_feature(aa32_jazelle
, cpu
)) {
7976 define_arm_cp_regs(cpu
, jazelle_regs
);
7978 /* Slightly awkwardly, the OMAP and StrongARM cores need all of
7979 * cp15 crn=0 to be writes-ignored, whereas for other cores they should
7980 * be read-only (ie write causes UNDEF exception).
7983 ARMCPRegInfo id_pre_v8_midr_cp_reginfo
[] = {
7984 /* Pre-v8 MIDR space.
7985 * Note that the MIDR isn't a simple constant register because
7986 * of the TI925 behaviour where writes to another register can
7987 * cause the MIDR value to change.
7989 * Unimplemented registers in the c15 0 0 0 space default to
7990 * MIDR. Define MIDR first as this entire space, then CTR, TCMTR
7991 * and friends override accordingly.
7994 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= CP_ANY
,
7995 .access
= PL1_R
, .resetvalue
= cpu
->midr
,
7996 .writefn
= arm_cp_write_ignore
, .raw_writefn
= raw_write
,
7997 .readfn
= midr_read
,
7998 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
7999 .type
= ARM_CP_OVERRIDE
},
8000 /* crn = 0 op1 = 0 crm = 3..7 : currently unassigned; we RAZ. */
8002 .cp
= 15, .crn
= 0, .crm
= 3, .opc1
= 0, .opc2
= CP_ANY
,
8003 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8005 .cp
= 15, .crn
= 0, .crm
= 4, .opc1
= 0, .opc2
= CP_ANY
,
8006 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8008 .cp
= 15, .crn
= 0, .crm
= 5, .opc1
= 0, .opc2
= CP_ANY
,
8009 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8011 .cp
= 15, .crn
= 0, .crm
= 6, .opc1
= 0, .opc2
= CP_ANY
,
8012 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8014 .cp
= 15, .crn
= 0, .crm
= 7, .opc1
= 0, .opc2
= CP_ANY
,
8015 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8017 ARMCPRegInfo id_v8_midr_cp_reginfo
[] = {
8018 { .name
= "MIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
8019 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 0,
8020 .access
= PL1_R
, .type
= ARM_CP_NO_RAW
, .resetvalue
= cpu
->midr
,
8021 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
8022 .readfn
= midr_read
},
8023 /* crn = 0 op1 = 0 crm = 0 op2 = 4,7 : AArch32 aliases of MIDR */
8024 { .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
,
8025 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
8026 .access
= PL1_R
, .resetvalue
= cpu
->midr
},
8027 { .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
,
8028 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 7,
8029 .access
= PL1_R
, .resetvalue
= cpu
->midr
},
8030 { .name
= "REVIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
8031 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 6,
8033 .accessfn
= access_aa64_tid1
,
8034 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->revidr
},
8036 ARMCPRegInfo id_cp_reginfo
[] = {
8037 /* These are common to v8 and pre-v8 */
8039 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 1,
8040 .access
= PL1_R
, .accessfn
= ctr_el0_access
,
8041 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
8042 { .name
= "CTR_EL0", .state
= ARM_CP_STATE_AA64
,
8043 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 0, .crm
= 0,
8044 .access
= PL0_R
, .accessfn
= ctr_el0_access
,
8045 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
8046 /* TCMTR and TLBTR exist in v8 but have no 64-bit versions */
8048 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 2,
8050 .accessfn
= access_aa32_tid1
,
8051 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8053 /* TLBTR is specific to VMSA */
8054 ARMCPRegInfo id_tlbtr_reginfo
= {
8056 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 3,
8058 .accessfn
= access_aa32_tid1
,
8059 .type
= ARM_CP_CONST
, .resetvalue
= 0,
8061 /* MPUIR is specific to PMSA V6+ */
8062 ARMCPRegInfo id_mpuir_reginfo
= {
8064 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
8065 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8066 .resetvalue
= cpu
->pmsav7_dregion
<< 8
8068 static const ARMCPRegInfo crn0_wi_reginfo
= {
8069 .name
= "CRN0_WI", .cp
= 15, .crn
= 0, .crm
= CP_ANY
,
8070 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_W
,
8071 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
8073 #ifdef CONFIG_USER_ONLY
8074 static const ARMCPRegUserSpaceInfo id_v8_user_midr_cp_reginfo
[] = {
8075 { .name
= "MIDR_EL1",
8076 .exported_bits
= 0x00000000ffffffff },
8077 { .name
= "REVIDR_EL1" },
8079 modify_arm_cp_regs(id_v8_midr_cp_reginfo
, id_v8_user_midr_cp_reginfo
);
8081 if (arm_feature(env
, ARM_FEATURE_OMAPCP
) ||
8082 arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
8084 /* Register the blanket "writes ignored" value first to cover the
8085 * whole space. Then update the specific ID registers to allow write
8086 * access, so that they ignore writes rather than causing them to
8089 define_one_arm_cp_reg(cpu
, &crn0_wi_reginfo
);
8090 for (i
= 0; i
< ARRAY_SIZE(id_pre_v8_midr_cp_reginfo
); ++i
) {
8091 id_pre_v8_midr_cp_reginfo
[i
].access
= PL1_RW
;
8093 for (i
= 0; i
< ARRAY_SIZE(id_cp_reginfo
); ++i
) {
8094 id_cp_reginfo
[i
].access
= PL1_RW
;
8096 id_mpuir_reginfo
.access
= PL1_RW
;
8097 id_tlbtr_reginfo
.access
= PL1_RW
;
8099 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8100 define_arm_cp_regs(cpu
, id_v8_midr_cp_reginfo
);
8102 define_arm_cp_regs(cpu
, id_pre_v8_midr_cp_reginfo
);
8104 define_arm_cp_regs(cpu
, id_cp_reginfo
);
8105 if (!arm_feature(env
, ARM_FEATURE_PMSA
)) {
8106 define_one_arm_cp_reg(cpu
, &id_tlbtr_reginfo
);
8107 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
8108 define_one_arm_cp_reg(cpu
, &id_mpuir_reginfo
);
8112 if (arm_feature(env
, ARM_FEATURE_MPIDR
)) {
8113 ARMCPRegInfo mpidr_cp_reginfo
[] = {
8114 { .name
= "MPIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
8115 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 5,
8116 .access
= PL1_R
, .readfn
= mpidr_read
, .type
= ARM_CP_NO_RAW
},
8118 #ifdef CONFIG_USER_ONLY
8119 static const ARMCPRegUserSpaceInfo mpidr_user_cp_reginfo
[] = {
8120 { .name
= "MPIDR_EL1",
8121 .fixed_bits
= 0x0000000080000000 },
8123 modify_arm_cp_regs(mpidr_cp_reginfo
, mpidr_user_cp_reginfo
);
8125 define_arm_cp_regs(cpu
, mpidr_cp_reginfo
);
8128 if (arm_feature(env
, ARM_FEATURE_AUXCR
)) {
8129 ARMCPRegInfo auxcr_reginfo
[] = {
8130 { .name
= "ACTLR_EL1", .state
= ARM_CP_STATE_BOTH
,
8131 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 1,
8132 .access
= PL1_RW
, .accessfn
= access_tacr
,
8133 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->reset_auxcr
},
8134 { .name
= "ACTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
8135 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 1,
8136 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
8138 { .name
= "ACTLR_EL3", .state
= ARM_CP_STATE_AA64
,
8139 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 1,
8140 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
8143 define_arm_cp_regs(cpu
, auxcr_reginfo
);
8144 if (cpu_isar_feature(aa32_ac2
, cpu
)) {
8145 define_arm_cp_regs(cpu
, actlr2_hactlr2_reginfo
);
8149 if (arm_feature(env
, ARM_FEATURE_CBAR
)) {
8151 * CBAR is IMPDEF, but common on Arm Cortex-A implementations.
8152 * There are two flavours:
8153 * (1) older 32-bit only cores have a simple 32-bit CBAR
8154 * (2) 64-bit cores have a 64-bit CBAR visible to AArch64, plus a
8155 * 32-bit register visible to AArch32 at a different encoding
8156 * to the "flavour 1" register and with the bits rearranged to
8157 * be able to squash a 64-bit address into the 32-bit view.
8158 * We distinguish the two via the ARM_FEATURE_AARCH64 flag, but
8159 * in future if we support AArch32-only configs of some of the
8160 * AArch64 cores we might need to add a specific feature flag
8161 * to indicate cores with "flavour 2" CBAR.
8163 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
8164 /* 32 bit view is [31:18] 0...0 [43:32]. */
8165 uint32_t cbar32
= (extract64(cpu
->reset_cbar
, 18, 14) << 18)
8166 | extract64(cpu
->reset_cbar
, 32, 12);
8167 ARMCPRegInfo cbar_reginfo
[] = {
8169 .type
= ARM_CP_CONST
,
8170 .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 1, .opc2
= 0,
8171 .access
= PL1_R
, .resetvalue
= cbar32
},
8172 { .name
= "CBAR_EL1", .state
= ARM_CP_STATE_AA64
,
8173 .type
= ARM_CP_CONST
,
8174 .opc0
= 3, .opc1
= 1, .crn
= 15, .crm
= 3, .opc2
= 0,
8175 .access
= PL1_R
, .resetvalue
= cpu
->reset_cbar
},
8177 /* We don't implement a r/w 64 bit CBAR currently */
8178 assert(arm_feature(env
, ARM_FEATURE_CBAR_RO
));
8179 define_arm_cp_regs(cpu
, cbar_reginfo
);
8181 ARMCPRegInfo cbar
= {
8183 .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 4, .opc2
= 0,
8184 .access
= PL1_R
|PL3_W
, .resetvalue
= cpu
->reset_cbar
,
8185 .fieldoffset
= offsetof(CPUARMState
,
8186 cp15
.c15_config_base_address
)
8188 if (arm_feature(env
, ARM_FEATURE_CBAR_RO
)) {
8189 cbar
.access
= PL1_R
;
8190 cbar
.fieldoffset
= 0;
8191 cbar
.type
= ARM_CP_CONST
;
8193 define_one_arm_cp_reg(cpu
, &cbar
);
8197 if (arm_feature(env
, ARM_FEATURE_VBAR
)) {
8198 static const ARMCPRegInfo vbar_cp_reginfo
[] = {
8199 { .name
= "VBAR", .state
= ARM_CP_STATE_BOTH
,
8200 .opc0
= 3, .crn
= 12, .crm
= 0, .opc1
= 0, .opc2
= 0,
8201 .access
= PL1_RW
, .writefn
= vbar_write
,
8202 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.vbar_s
),
8203 offsetof(CPUARMState
, cp15
.vbar_ns
) },
8206 define_arm_cp_regs(cpu
, vbar_cp_reginfo
);
8209 /* Generic registers whose values depend on the implementation */
8211 ARMCPRegInfo sctlr
= {
8212 .name
= "SCTLR", .state
= ARM_CP_STATE_BOTH
,
8213 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 0,
8214 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
8215 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.sctlr_s
),
8216 offsetof(CPUARMState
, cp15
.sctlr_ns
) },
8217 .writefn
= sctlr_write
, .resetvalue
= cpu
->reset_sctlr
,
8218 .raw_writefn
= raw_write
,
8220 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
8221 /* Normally we would always end the TB on an SCTLR write, but Linux
8222 * arch/arm/mach-pxa/sleep.S expects two instructions following
8223 * an MMU enable to execute from cache. Imitate this behaviour.
8225 sctlr
.type
|= ARM_CP_SUPPRESS_TB_END
;
8227 define_one_arm_cp_reg(cpu
, &sctlr
);
8230 if (cpu_isar_feature(aa64_lor
, cpu
)) {
8231 define_arm_cp_regs(cpu
, lor_reginfo
);
8233 if (cpu_isar_feature(aa64_pan
, cpu
)) {
8234 define_one_arm_cp_reg(cpu
, &pan_reginfo
);
8236 #ifndef CONFIG_USER_ONLY
8237 if (cpu_isar_feature(aa64_ats1e1
, cpu
)) {
8238 define_arm_cp_regs(cpu
, ats1e1_reginfo
);
8240 if (cpu_isar_feature(aa32_ats1e1
, cpu
)) {
8241 define_arm_cp_regs(cpu
, ats1cp_reginfo
);
8244 if (cpu_isar_feature(aa64_uao
, cpu
)) {
8245 define_one_arm_cp_reg(cpu
, &uao_reginfo
);
8248 if (cpu_isar_feature(aa64_dit
, cpu
)) {
8249 define_one_arm_cp_reg(cpu
, &dit_reginfo
);
8251 if (cpu_isar_feature(aa64_ssbs
, cpu
)) {
8252 define_one_arm_cp_reg(cpu
, &ssbs_reginfo
);
8254 if (cpu_isar_feature(any_ras
, cpu
)) {
8255 define_arm_cp_regs(cpu
, minimal_ras_reginfo
);
8258 if (cpu_isar_feature(aa64_vh
, cpu
) ||
8259 cpu_isar_feature(aa64_debugv8p2
, cpu
)) {
8260 define_one_arm_cp_reg(cpu
, &contextidr_el2
);
8262 if (arm_feature(env
, ARM_FEATURE_EL2
) && cpu_isar_feature(aa64_vh
, cpu
)) {
8263 define_arm_cp_regs(cpu
, vhe_reginfo
);
8266 if (cpu_isar_feature(aa64_sve
, cpu
)) {
8267 define_arm_cp_regs(cpu
, zcr_reginfo
);
8270 if (cpu_isar_feature(aa64_hcx
, cpu
)) {
8271 define_one_arm_cp_reg(cpu
, &hcrx_el2_reginfo
);
8274 #ifdef TARGET_AARCH64
8275 if (cpu_isar_feature(aa64_sme
, cpu
)) {
8276 define_arm_cp_regs(cpu
, sme_reginfo
);
8278 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
8279 define_arm_cp_regs(cpu
, pauth_reginfo
);
8281 if (cpu_isar_feature(aa64_rndr
, cpu
)) {
8282 define_arm_cp_regs(cpu
, rndr_reginfo
);
8284 if (cpu_isar_feature(aa64_tlbirange
, cpu
)) {
8285 define_arm_cp_regs(cpu
, tlbirange_reginfo
);
8287 if (cpu_isar_feature(aa64_tlbios
, cpu
)) {
8288 define_arm_cp_regs(cpu
, tlbios_reginfo
);
8290 #ifndef CONFIG_USER_ONLY
8291 /* Data Cache clean instructions up to PoP */
8292 if (cpu_isar_feature(aa64_dcpop
, cpu
)) {
8293 define_one_arm_cp_reg(cpu
, dcpop_reg
);
8295 if (cpu_isar_feature(aa64_dcpodp
, cpu
)) {
8296 define_one_arm_cp_reg(cpu
, dcpodp_reg
);
8299 #endif /*CONFIG_USER_ONLY*/
8302 * If full MTE is enabled, add all of the system registers.
8303 * If only "instructions available at EL0" are enabled,
8304 * then define only a RAZ/WI version of PSTATE.TCO.
8306 if (cpu_isar_feature(aa64_mte
, cpu
)) {
8307 define_arm_cp_regs(cpu
, mte_reginfo
);
8308 define_arm_cp_regs(cpu
, mte_el0_cacheop_reginfo
);
8309 } else if (cpu_isar_feature(aa64_mte_insn_reg
, cpu
)) {
8310 define_arm_cp_regs(cpu
, mte_tco_ro_reginfo
);
8311 define_arm_cp_regs(cpu
, mte_el0_cacheop_reginfo
);
8314 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
8315 define_arm_cp_regs(cpu
, scxtnum_reginfo
);
8319 if (cpu_isar_feature(any_predinv
, cpu
)) {
8320 define_arm_cp_regs(cpu
, predinv_reginfo
);
8323 if (cpu_isar_feature(any_ccidx
, cpu
)) {
8324 define_arm_cp_regs(cpu
, ccsidr2_reginfo
);
8327 #ifndef CONFIG_USER_ONLY
8329 * Register redirections and aliases must be done last,
8330 * after the registers from the other extensions have been defined.
8332 if (arm_feature(env
, ARM_FEATURE_EL2
) && cpu_isar_feature(aa64_vh
, cpu
)) {
8333 define_arm_vh_e2h_redirects_aliases(cpu
);
8338 /* Sort alphabetically by type name, except for "any". */
8339 static gint
arm_cpu_list_compare(gconstpointer a
, gconstpointer b
)
8341 ObjectClass
*class_a
= (ObjectClass
*)a
;
8342 ObjectClass
*class_b
= (ObjectClass
*)b
;
8343 const char *name_a
, *name_b
;
8345 name_a
= object_class_get_name(class_a
);
8346 name_b
= object_class_get_name(class_b
);
8347 if (strcmp(name_a
, "any-" TYPE_ARM_CPU
) == 0) {
8349 } else if (strcmp(name_b
, "any-" TYPE_ARM_CPU
) == 0) {
8352 return strcmp(name_a
, name_b
);
8356 static void arm_cpu_list_entry(gpointer data
, gpointer user_data
)
8358 ObjectClass
*oc
= data
;
8359 CPUClass
*cc
= CPU_CLASS(oc
);
8360 const char *typename
;
8363 typename
= object_class_get_name(oc
);
8364 name
= g_strndup(typename
, strlen(typename
) - strlen("-" TYPE_ARM_CPU
));
8365 if (cc
->deprecation_note
) {
8366 qemu_printf(" %s (deprecated)\n", name
);
8368 qemu_printf(" %s\n", name
);
8373 void arm_cpu_list(void)
8377 list
= object_class_get_list(TYPE_ARM_CPU
, false);
8378 list
= g_slist_sort(list
, arm_cpu_list_compare
);
8379 qemu_printf("Available CPUs:\n");
8380 g_slist_foreach(list
, arm_cpu_list_entry
, NULL
);
8384 static void arm_cpu_add_definition(gpointer data
, gpointer user_data
)
8386 ObjectClass
*oc
= data
;
8387 CpuDefinitionInfoList
**cpu_list
= user_data
;
8388 CpuDefinitionInfo
*info
;
8389 const char *typename
;
8391 typename
= object_class_get_name(oc
);
8392 info
= g_malloc0(sizeof(*info
));
8393 info
->name
= g_strndup(typename
,
8394 strlen(typename
) - strlen("-" TYPE_ARM_CPU
));
8395 info
->q_typename
= g_strdup(typename
);
8397 QAPI_LIST_PREPEND(*cpu_list
, info
);
8400 CpuDefinitionInfoList
*qmp_query_cpu_definitions(Error
**errp
)
8402 CpuDefinitionInfoList
*cpu_list
= NULL
;
8405 list
= object_class_get_list(TYPE_ARM_CPU
, false);
8406 g_slist_foreach(list
, arm_cpu_add_definition
, &cpu_list
);
8413 * Private utility function for define_one_arm_cp_reg_with_opaque():
8414 * add a single reginfo struct to the hash table.
8416 static void add_cpreg_to_hashtable(ARMCPU
*cpu
, const ARMCPRegInfo
*r
,
8417 void *opaque
, CPState state
,
8418 CPSecureState secstate
,
8419 int crm
, int opc1
, int opc2
,
8422 CPUARMState
*env
= &cpu
->env
;
8425 bool is64
= r
->type
& ARM_CP_64BIT
;
8426 bool ns
= secstate
& ARM_CP_SECSTATE_NS
;
8432 case ARM_CP_STATE_AA32
:
8433 /* We assume it is a cp15 register if the .cp field is left unset. */
8434 if (cp
== 0 && r
->state
== ARM_CP_STATE_BOTH
) {
8437 key
= ENCODE_CP_REG(cp
, is64
, ns
, r
->crn
, crm
, opc1
, opc2
);
8439 case ARM_CP_STATE_AA64
:
8441 * To allow abbreviation of ARMCPRegInfo definitions, we treat
8442 * cp == 0 as equivalent to the value for "standard guest-visible
8443 * sysreg". STATE_BOTH definitions are also always "standard sysreg"
8444 * in their AArch64 view (the .cp value may be non-zero for the
8445 * benefit of the AArch32 view).
8447 if (cp
== 0 || r
->state
== ARM_CP_STATE_BOTH
) {
8448 cp
= CP_REG_ARM64_SYSREG_CP
;
8450 key
= ENCODE_AA64_CP_REG(cp
, r
->crn
, crm
, r
->opc0
, opc1
, opc2
);
8453 g_assert_not_reached();
8456 /* Overriding of an existing definition must be explicitly requested. */
8457 if (!(r
->type
& ARM_CP_OVERRIDE
)) {
8458 const ARMCPRegInfo
*oldreg
= get_arm_cp_reginfo(cpu
->cp_regs
, key
);
8460 assert(oldreg
->type
& ARM_CP_OVERRIDE
);
8465 * Eliminate registers that are not present because the EL is missing.
8466 * Doing this here makes it easier to put all registers for a given
8467 * feature into the same ARMCPRegInfo array and define them all at once.
8470 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
8472 * An EL2 register without EL2 but with EL3 is (usually) RES0.
8473 * See rule RJFFP in section D1.1.3 of DDI0487H.a.
8475 int min_el
= ctz32(r
->access
) / 2;
8476 if (min_el
== 2 && !arm_feature(env
, ARM_FEATURE_EL2
)) {
8477 if (r
->type
& ARM_CP_EL3_NO_EL2_UNDEF
) {
8480 make_const
= !(r
->type
& ARM_CP_EL3_NO_EL2_KEEP
);
8483 CPAccessRights max_el
= (arm_feature(env
, ARM_FEATURE_EL2
)
8485 if ((r
->access
& max_el
) == 0) {
8490 /* Combine cpreg and name into one allocation. */
8491 name_len
= strlen(name
) + 1;
8492 r2
= g_malloc(sizeof(*r2
) + name_len
);
8494 r2
->name
= memcpy(r2
+ 1, name
, name_len
);
8497 * Update fields to match the instantiation, overwiting wildcards
8498 * such as CP_ANY, ARM_CP_STATE_BOTH, or ARM_CP_SECSTATE_BOTH.
8505 r2
->secure
= secstate
;
8507 r2
->opaque
= opaque
;
8511 /* This should not have been a very special register to begin. */
8512 int old_special
= r2
->type
& ARM_CP_SPECIAL_MASK
;
8513 assert(old_special
== 0 || old_special
== ARM_CP_NOP
);
8515 * Set the special function to CONST, retaining the other flags.
8516 * This is important for e.g. ARM_CP_SVE so that we still
8517 * take the SVE trap if CPTR_EL3.EZ == 0.
8519 r2
->type
= (r2
->type
& ~ARM_CP_SPECIAL_MASK
) | ARM_CP_CONST
;
8521 * Usually, these registers become RES0, but there are a few
8522 * special cases like VPIDR_EL2 which have a constant non-zero
8523 * value with writes ignored.
8525 if (!(r
->type
& ARM_CP_EL3_NO_EL2_C_NZ
)) {
8529 * ARM_CP_CONST has precedence, so removing the callbacks and
8530 * offsets are not strictly necessary, but it is potentially
8531 * less confusing to debug later.
8535 r2
->raw_readfn
= NULL
;
8536 r2
->raw_writefn
= NULL
;
8538 r2
->fieldoffset
= 0;
8539 r2
->bank_fieldoffsets
[0] = 0;
8540 r2
->bank_fieldoffsets
[1] = 0;
8542 bool isbanked
= r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1];
8546 * Register is banked (using both entries in array).
8547 * Overwriting fieldoffset as the array is only used to define
8548 * banked registers but later only fieldoffset is used.
8550 r2
->fieldoffset
= r
->bank_fieldoffsets
[ns
];
8552 if (state
== ARM_CP_STATE_AA32
) {
8555 * If the register is banked then we don't need to migrate or
8556 * reset the 32-bit instance in certain cases:
8558 * 1) If the register has both 32-bit and 64-bit instances
8559 * then we can count on the 64-bit instance taking care
8560 * of the non-secure bank.
8561 * 2) If ARMv8 is enabled then we can count on a 64-bit
8562 * version taking care of the secure bank. This requires
8563 * that separate 32 and 64-bit definitions are provided.
8565 if ((r
->state
== ARM_CP_STATE_BOTH
&& ns
) ||
8566 (arm_feature(env
, ARM_FEATURE_V8
) && !ns
)) {
8567 r2
->type
|= ARM_CP_ALIAS
;
8569 } else if ((secstate
!= r
->secure
) && !ns
) {
8571 * The register is not banked so we only want to allow
8572 * migration of the non-secure instance.
8574 r2
->type
|= ARM_CP_ALIAS
;
8577 if (HOST_BIG_ENDIAN
&&
8578 r
->state
== ARM_CP_STATE_BOTH
&& r2
->fieldoffset
) {
8579 r2
->fieldoffset
+= sizeof(uint32_t);
8585 * By convention, for wildcarded registers only the first
8586 * entry is used for migration; the others are marked as
8587 * ALIAS so we don't try to transfer the register
8588 * multiple times. Special registers (ie NOP/WFI) are
8589 * never migratable and not even raw-accessible.
8591 if (r2
->type
& ARM_CP_SPECIAL_MASK
) {
8592 r2
->type
|= ARM_CP_NO_RAW
;
8594 if (((r
->crm
== CP_ANY
) && crm
!= 0) ||
8595 ((r
->opc1
== CP_ANY
) && opc1
!= 0) ||
8596 ((r
->opc2
== CP_ANY
) && opc2
!= 0)) {
8597 r2
->type
|= ARM_CP_ALIAS
| ARM_CP_NO_GDB
;
8601 * Check that raw accesses are either forbidden or handled. Note that
8602 * we can't assert this earlier because the setup of fieldoffset for
8603 * banked registers has to be done first.
8605 if (!(r2
->type
& ARM_CP_NO_RAW
)) {
8606 assert(!raw_accessors_invalid(r2
));
8609 g_hash_table_insert(cpu
->cp_regs
, (gpointer
)(uintptr_t)key
, r2
);
8613 void define_one_arm_cp_reg_with_opaque(ARMCPU
*cpu
,
8614 const ARMCPRegInfo
*r
, void *opaque
)
8616 /* Define implementations of coprocessor registers.
8617 * We store these in a hashtable because typically
8618 * there are less than 150 registers in a space which
8619 * is 16*16*16*8*8 = 262144 in size.
8620 * Wildcarding is supported for the crm, opc1 and opc2 fields.
8621 * If a register is defined twice then the second definition is
8622 * used, so this can be used to define some generic registers and
8623 * then override them with implementation specific variations.
8624 * At least one of the original and the second definition should
8625 * include ARM_CP_OVERRIDE in its type bits -- this is just a guard
8626 * against accidental use.
8628 * The state field defines whether the register is to be
8629 * visible in the AArch32 or AArch64 execution state. If the
8630 * state is set to ARM_CP_STATE_BOTH then we synthesise a
8631 * reginfo structure for the AArch32 view, which sees the lower
8632 * 32 bits of the 64 bit register.
8634 * Only registers visible in AArch64 may set r->opc0; opc0 cannot
8635 * be wildcarded. AArch64 registers are always considered to be 64
8636 * bits; the ARM_CP_64BIT* flag applies only to the AArch32 view of
8637 * the register, if any.
8639 int crm
, opc1
, opc2
;
8640 int crmmin
= (r
->crm
== CP_ANY
) ? 0 : r
->crm
;
8641 int crmmax
= (r
->crm
== CP_ANY
) ? 15 : r
->crm
;
8642 int opc1min
= (r
->opc1
== CP_ANY
) ? 0 : r
->opc1
;
8643 int opc1max
= (r
->opc1
== CP_ANY
) ? 7 : r
->opc1
;
8644 int opc2min
= (r
->opc2
== CP_ANY
) ? 0 : r
->opc2
;
8645 int opc2max
= (r
->opc2
== CP_ANY
) ? 7 : r
->opc2
;
8648 /* 64 bit registers have only CRm and Opc1 fields */
8649 assert(!((r
->type
& ARM_CP_64BIT
) && (r
->opc2
|| r
->crn
)));
8650 /* op0 only exists in the AArch64 encodings */
8651 assert((r
->state
!= ARM_CP_STATE_AA32
) || (r
->opc0
== 0));
8652 /* AArch64 regs are all 64 bit so ARM_CP_64BIT is meaningless */
8653 assert((r
->state
!= ARM_CP_STATE_AA64
) || !(r
->type
& ARM_CP_64BIT
));
8655 * This API is only for Arm's system coprocessors (14 and 15) or
8656 * (M-profile or v7A-and-earlier only) for implementation defined
8657 * coprocessors in the range 0..7. Our decode assumes this, since
8658 * 8..13 can be used for other insns including VFP and Neon. See
8659 * valid_cp() in translate.c. Assert here that we haven't tried
8660 * to use an invalid coprocessor number.
8663 case ARM_CP_STATE_BOTH
:
8664 /* 0 has a special meaning, but otherwise the same rules as AA32. */
8669 case ARM_CP_STATE_AA32
:
8670 if (arm_feature(&cpu
->env
, ARM_FEATURE_V8
) &&
8671 !arm_feature(&cpu
->env
, ARM_FEATURE_M
)) {
8672 assert(r
->cp
>= 14 && r
->cp
<= 15);
8674 assert(r
->cp
< 8 || (r
->cp
>= 14 && r
->cp
<= 15));
8677 case ARM_CP_STATE_AA64
:
8678 assert(r
->cp
== 0 || r
->cp
== CP_REG_ARM64_SYSREG_CP
);
8681 g_assert_not_reached();
8683 /* The AArch64 pseudocode CheckSystemAccess() specifies that op1
8684 * encodes a minimum access level for the register. We roll this
8685 * runtime check into our general permission check code, so check
8686 * here that the reginfo's specified permissions are strict enough
8687 * to encompass the generic architectural permission check.
8689 if (r
->state
!= ARM_CP_STATE_AA32
) {
8690 CPAccessRights mask
;
8693 /* min_EL EL1, but some accessible to EL0 via kernel ABI */
8694 mask
= PL0U_R
| PL1_RW
;
8714 /* min_EL EL1, secure mode only (we don't check the latter) */
8718 /* broken reginfo with out-of-range opc1 */
8719 g_assert_not_reached();
8721 /* assert our permissions are not too lax (stricter is fine) */
8722 assert((r
->access
& ~mask
) == 0);
8725 /* Check that the register definition has enough info to handle
8726 * reads and writes if they are permitted.
8728 if (!(r
->type
& (ARM_CP_SPECIAL_MASK
| ARM_CP_CONST
))) {
8729 if (r
->access
& PL3_R
) {
8730 assert((r
->fieldoffset
||
8731 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
8734 if (r
->access
& PL3_W
) {
8735 assert((r
->fieldoffset
||
8736 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
8741 for (crm
= crmmin
; crm
<= crmmax
; crm
++) {
8742 for (opc1
= opc1min
; opc1
<= opc1max
; opc1
++) {
8743 for (opc2
= opc2min
; opc2
<= opc2max
; opc2
++) {
8744 for (state
= ARM_CP_STATE_AA32
;
8745 state
<= ARM_CP_STATE_AA64
; state
++) {
8746 if (r
->state
!= state
&& r
->state
!= ARM_CP_STATE_BOTH
) {
8749 if (state
== ARM_CP_STATE_AA32
) {
8750 /* Under AArch32 CP registers can be common
8751 * (same for secure and non-secure world) or banked.
8755 switch (r
->secure
) {
8756 case ARM_CP_SECSTATE_S
:
8757 case ARM_CP_SECSTATE_NS
:
8758 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
8759 r
->secure
, crm
, opc1
, opc2
,
8762 case ARM_CP_SECSTATE_BOTH
:
8763 name
= g_strdup_printf("%s_S", r
->name
);
8764 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
8766 crm
, opc1
, opc2
, name
);
8768 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
8770 crm
, opc1
, opc2
, r
->name
);
8773 g_assert_not_reached();
8776 /* AArch64 registers get mapped to non-secure instance
8778 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
8780 crm
, opc1
, opc2
, r
->name
);
8788 /* Define a whole list of registers */
8789 void define_arm_cp_regs_with_opaque_len(ARMCPU
*cpu
, const ARMCPRegInfo
*regs
,
8790 void *opaque
, size_t len
)
8793 for (i
= 0; i
< len
; ++i
) {
8794 define_one_arm_cp_reg_with_opaque(cpu
, regs
+ i
, opaque
);
8799 * Modify ARMCPRegInfo for access from userspace.
8801 * This is a data driven modification directed by
8802 * ARMCPRegUserSpaceInfo. All registers become ARM_CP_CONST as
8803 * user-space cannot alter any values and dynamic values pertaining to
8804 * execution state are hidden from user space view anyway.
8806 void modify_arm_cp_regs_with_len(ARMCPRegInfo
*regs
, size_t regs_len
,
8807 const ARMCPRegUserSpaceInfo
*mods
,
8810 for (size_t mi
= 0; mi
< mods_len
; ++mi
) {
8811 const ARMCPRegUserSpaceInfo
*m
= mods
+ mi
;
8812 GPatternSpec
*pat
= NULL
;
8815 pat
= g_pattern_spec_new(m
->name
);
8817 for (size_t ri
= 0; ri
< regs_len
; ++ri
) {
8818 ARMCPRegInfo
*r
= regs
+ ri
;
8820 if (pat
&& g_pattern_match_string(pat
, r
->name
)) {
8821 r
->type
= ARM_CP_CONST
;
8825 } else if (strcmp(r
->name
, m
->name
) == 0) {
8826 r
->type
= ARM_CP_CONST
;
8828 r
->resetvalue
&= m
->exported_bits
;
8829 r
->resetvalue
|= m
->fixed_bits
;
8834 g_pattern_spec_free(pat
);
8839 const ARMCPRegInfo
*get_arm_cp_reginfo(GHashTable
*cpregs
, uint32_t encoded_cp
)
8841 return g_hash_table_lookup(cpregs
, (gpointer
)(uintptr_t)encoded_cp
);
8844 void arm_cp_write_ignore(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
8847 /* Helper coprocessor write function for write-ignore registers */
8850 uint64_t arm_cp_read_zero(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
8852 /* Helper coprocessor write function for read-as-zero registers */
8856 void arm_cp_reset_ignore(CPUARMState
*env
, const ARMCPRegInfo
*opaque
)
8858 /* Helper coprocessor reset function for do-nothing-on-reset registers */
8861 static int bad_mode_switch(CPUARMState
*env
, int mode
, CPSRWriteType write_type
)
8863 /* Return true if it is not valid for us to switch to
8864 * this CPU mode (ie all the UNPREDICTABLE cases in
8865 * the ARM ARM CPSRWriteByInstr pseudocode).
8868 /* Changes to or from Hyp via MSR and CPS are illegal. */
8869 if (write_type
== CPSRWriteByInstr
&&
8870 ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_HYP
||
8871 mode
== ARM_CPU_MODE_HYP
)) {
8876 case ARM_CPU_MODE_USR
:
8878 case ARM_CPU_MODE_SYS
:
8879 case ARM_CPU_MODE_SVC
:
8880 case ARM_CPU_MODE_ABT
:
8881 case ARM_CPU_MODE_UND
:
8882 case ARM_CPU_MODE_IRQ
:
8883 case ARM_CPU_MODE_FIQ
:
8884 /* Note that we don't implement the IMPDEF NSACR.RFR which in v7
8885 * allows FIQ mode to be Secure-only. (In v8 this doesn't exist.)
8887 /* If HCR.TGE is set then changes from Monitor to NS PL1 via MSR
8888 * and CPS are treated as illegal mode changes.
8890 if (write_type
== CPSRWriteByInstr
&&
8891 (env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
&&
8892 (arm_hcr_el2_eff(env
) & HCR_TGE
)) {
8896 case ARM_CPU_MODE_HYP
:
8897 return !arm_is_el2_enabled(env
) || arm_current_el(env
) < 2;
8898 case ARM_CPU_MODE_MON
:
8899 return arm_current_el(env
) < 3;
8905 uint32_t cpsr_read(CPUARMState
*env
)
8908 ZF
= (env
->ZF
== 0);
8909 return env
->uncached_cpsr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
8910 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3) | (env
->QF
<< 27)
8911 | (env
->thumb
<< 5) | ((env
->condexec_bits
& 3) << 25)
8912 | ((env
->condexec_bits
& 0xfc) << 8)
8913 | (env
->GE
<< 16) | (env
->daif
& CPSR_AIF
);
8916 void cpsr_write(CPUARMState
*env
, uint32_t val
, uint32_t mask
,
8917 CPSRWriteType write_type
)
8919 uint32_t changed_daif
;
8920 bool rebuild_hflags
= (write_type
!= CPSRWriteRaw
) &&
8921 (mask
& (CPSR_M
| CPSR_E
| CPSR_IL
));
8923 if (mask
& CPSR_NZCV
) {
8924 env
->ZF
= (~val
) & CPSR_Z
;
8926 env
->CF
= (val
>> 29) & 1;
8927 env
->VF
= (val
<< 3) & 0x80000000;
8930 env
->QF
= ((val
& CPSR_Q
) != 0);
8932 env
->thumb
= ((val
& CPSR_T
) != 0);
8933 if (mask
& CPSR_IT_0_1
) {
8934 env
->condexec_bits
&= ~3;
8935 env
->condexec_bits
|= (val
>> 25) & 3;
8937 if (mask
& CPSR_IT_2_7
) {
8938 env
->condexec_bits
&= 3;
8939 env
->condexec_bits
|= (val
>> 8) & 0xfc;
8941 if (mask
& CPSR_GE
) {
8942 env
->GE
= (val
>> 16) & 0xf;
8945 /* In a V7 implementation that includes the security extensions but does
8946 * not include Virtualization Extensions the SCR.FW and SCR.AW bits control
8947 * whether non-secure software is allowed to change the CPSR_F and CPSR_A
8948 * bits respectively.
8950 * In a V8 implementation, it is permitted for privileged software to
8951 * change the CPSR A/F bits regardless of the SCR.AW/FW bits.
8953 if (write_type
!= CPSRWriteRaw
&& !arm_feature(env
, ARM_FEATURE_V8
) &&
8954 arm_feature(env
, ARM_FEATURE_EL3
) &&
8955 !arm_feature(env
, ARM_FEATURE_EL2
) &&
8956 !arm_is_secure(env
)) {
8958 changed_daif
= (env
->daif
^ val
) & mask
;
8960 if (changed_daif
& CPSR_A
) {
8961 /* Check to see if we are allowed to change the masking of async
8962 * abort exceptions from a non-secure state.
8964 if (!(env
->cp15
.scr_el3
& SCR_AW
)) {
8965 qemu_log_mask(LOG_GUEST_ERROR
,
8966 "Ignoring attempt to switch CPSR_A flag from "
8967 "non-secure world with SCR.AW bit clear\n");
8972 if (changed_daif
& CPSR_F
) {
8973 /* Check to see if we are allowed to change the masking of FIQ
8974 * exceptions from a non-secure state.
8976 if (!(env
->cp15
.scr_el3
& SCR_FW
)) {
8977 qemu_log_mask(LOG_GUEST_ERROR
,
8978 "Ignoring attempt to switch CPSR_F flag from "
8979 "non-secure world with SCR.FW bit clear\n");
8983 /* Check whether non-maskable FIQ (NMFI) support is enabled.
8984 * If this bit is set software is not allowed to mask
8985 * FIQs, but is allowed to set CPSR_F to 0.
8987 if ((A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_NMFI
) &&
8989 qemu_log_mask(LOG_GUEST_ERROR
,
8990 "Ignoring attempt to enable CPSR_F flag "
8991 "(non-maskable FIQ [NMFI] support enabled)\n");
8997 env
->daif
&= ~(CPSR_AIF
& mask
);
8998 env
->daif
|= val
& CPSR_AIF
& mask
;
9000 if (write_type
!= CPSRWriteRaw
&&
9001 ((env
->uncached_cpsr
^ val
) & mask
& CPSR_M
)) {
9002 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_USR
) {
9003 /* Note that we can only get here in USR mode if this is a
9004 * gdb stub write; for this case we follow the architectural
9005 * behaviour for guest writes in USR mode of ignoring an attempt
9006 * to switch mode. (Those are caught by translate.c for writes
9007 * triggered by guest instructions.)
9010 } else if (bad_mode_switch(env
, val
& CPSR_M
, write_type
)) {
9011 /* Attempt to switch to an invalid mode: this is UNPREDICTABLE in
9012 * v7, and has defined behaviour in v8:
9013 * + leave CPSR.M untouched
9014 * + allow changes to the other CPSR fields
9016 * For user changes via the GDB stub, we don't set PSTATE.IL,
9017 * as this would be unnecessarily harsh for a user error.
9020 if (write_type
!= CPSRWriteByGDBStub
&&
9021 arm_feature(env
, ARM_FEATURE_V8
)) {
9025 qemu_log_mask(LOG_GUEST_ERROR
,
9026 "Illegal AArch32 mode switch attempt from %s to %s\n",
9027 aarch32_mode_name(env
->uncached_cpsr
),
9028 aarch32_mode_name(val
));
9030 qemu_log_mask(CPU_LOG_INT
, "%s %s to %s PC 0x%" PRIx32
"\n",
9031 write_type
== CPSRWriteExceptionReturn
?
9032 "Exception return from AArch32" :
9033 "AArch32 mode switch from",
9034 aarch32_mode_name(env
->uncached_cpsr
),
9035 aarch32_mode_name(val
), env
->regs
[15]);
9036 switch_mode(env
, val
& CPSR_M
);
9039 mask
&= ~CACHED_CPSR_BITS
;
9040 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~mask
) | (val
& mask
);
9041 if (rebuild_hflags
) {
9042 arm_rebuild_hflags(env
);
9046 /* Sign/zero extend */
9047 uint32_t HELPER(sxtb16
)(uint32_t x
)
9050 res
= (uint16_t)(int8_t)x
;
9051 res
|= (uint32_t)(int8_t)(x
>> 16) << 16;
9055 static void handle_possible_div0_trap(CPUARMState
*env
, uintptr_t ra
)
9058 * Take a division-by-zero exception if necessary; otherwise return
9059 * to get the usual non-trapping division behaviour (result of 0)
9061 if (arm_feature(env
, ARM_FEATURE_M
)
9062 && (env
->v7m
.ccr
[env
->v7m
.secure
] & R_V7M_CCR_DIV_0_TRP_MASK
)) {
9063 raise_exception_ra(env
, EXCP_DIVBYZERO
, 0, 1, ra
);
9067 uint32_t HELPER(uxtb16
)(uint32_t x
)
9070 res
= (uint16_t)(uint8_t)x
;
9071 res
|= (uint32_t)(uint8_t)(x
>> 16) << 16;
9075 int32_t HELPER(sdiv
)(CPUARMState
*env
, int32_t num
, int32_t den
)
9078 handle_possible_div0_trap(env
, GETPC());
9081 if (num
== INT_MIN
&& den
== -1) {
9087 uint32_t HELPER(udiv
)(CPUARMState
*env
, uint32_t num
, uint32_t den
)
9090 handle_possible_div0_trap(env
, GETPC());
9096 uint32_t HELPER(rbit
)(uint32_t x
)
9101 #ifdef CONFIG_USER_ONLY
9103 static void switch_mode(CPUARMState
*env
, int mode
)
9105 ARMCPU
*cpu
= env_archcpu(env
);
9107 if (mode
!= ARM_CPU_MODE_USR
) {
9108 cpu_abort(CPU(cpu
), "Tried to switch out of user mode\n");
9112 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
9113 uint32_t cur_el
, bool secure
)
9118 void aarch64_sync_64_to_32(CPUARMState
*env
)
9120 g_assert_not_reached();
9125 static void switch_mode(CPUARMState
*env
, int mode
)
9130 old_mode
= env
->uncached_cpsr
& CPSR_M
;
9131 if (mode
== old_mode
)
9134 if (old_mode
== ARM_CPU_MODE_FIQ
) {
9135 memcpy (env
->fiq_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
9136 memcpy (env
->regs
+ 8, env
->usr_regs
, 5 * sizeof(uint32_t));
9137 } else if (mode
== ARM_CPU_MODE_FIQ
) {
9138 memcpy (env
->usr_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
9139 memcpy (env
->regs
+ 8, env
->fiq_regs
, 5 * sizeof(uint32_t));
9142 i
= bank_number(old_mode
);
9143 env
->banked_r13
[i
] = env
->regs
[13];
9144 env
->banked_spsr
[i
] = env
->spsr
;
9146 i
= bank_number(mode
);
9147 env
->regs
[13] = env
->banked_r13
[i
];
9148 env
->spsr
= env
->banked_spsr
[i
];
9150 env
->banked_r14
[r14_bank_number(old_mode
)] = env
->regs
[14];
9151 env
->regs
[14] = env
->banked_r14
[r14_bank_number(mode
)];
9154 /* Physical Interrupt Target EL Lookup Table
9156 * [ From ARM ARM section G1.13.4 (Table G1-15) ]
9158 * The below multi-dimensional table is used for looking up the target
9159 * exception level given numerous condition criteria. Specifically, the
9160 * target EL is based on SCR and HCR routing controls as well as the
9161 * currently executing EL and secure state.
9164 * target_el_table[2][2][2][2][2][4]
9165 * | | | | | +--- Current EL
9166 * | | | | +------ Non-secure(0)/Secure(1)
9167 * | | | +--------- HCR mask override
9168 * | | +------------ SCR exec state control
9169 * | +--------------- SCR mask override
9170 * +------------------ 32-bit(0)/64-bit(1) EL3
9172 * The table values are as such:
9176 * The ARM ARM target EL table includes entries indicating that an "exception
9177 * is not taken". The two cases where this is applicable are:
9178 * 1) An exception is taken from EL3 but the SCR does not have the exception
9180 * 2) An exception is taken from EL2 but the HCR does not have the exception
9182 * In these two cases, the below table contain a target of EL1. This value is
9183 * returned as it is expected that the consumer of the table data will check
9184 * for "target EL >= current EL" to ensure the exception is not taken.
9188 * BIT IRQ IMO Non-secure Secure
9189 * EL3 FIQ RW FMO EL0 EL1 EL2 EL3 EL0 EL1 EL2 EL3
9191 static const int8_t target_el_table
[2][2][2][2][2][4] = {
9192 {{{{/* 0 0 0 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
9193 {/* 0 0 0 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},
9194 {{/* 0 0 1 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
9195 {/* 0 0 1 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},},
9196 {{{/* 0 1 0 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
9197 {/* 0 1 0 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},
9198 {{/* 0 1 1 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
9199 {/* 0 1 1 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},},},
9200 {{{{/* 1 0 0 0 */{ 1, 1, 2, -1 },{ 1, 1, -1, 1 },},
9201 {/* 1 0 0 1 */{ 2, 2, 2, -1 },{ 2, 2, -1, 1 },},},
9202 {{/* 1 0 1 0 */{ 1, 1, 1, -1 },{ 1, 1, 1, 1 },},
9203 {/* 1 0 1 1 */{ 2, 2, 2, -1 },{ 2, 2, 2, 1 },},},},
9204 {{{/* 1 1 0 0 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},
9205 {/* 1 1 0 1 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},},
9206 {{/* 1 1 1 0 */{ 3, 3, 3, -1 },{ 3, 3, 3, 3 },},
9207 {/* 1 1 1 1 */{ 3, 3, 3, -1 },{ 3, 3, 3, 3 },},},},},
9211 * Determine the target EL for physical exceptions
9213 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
9214 uint32_t cur_el
, bool secure
)
9216 CPUARMState
*env
= cs
->env_ptr
;
9221 /* Is the highest EL AArch64? */
9222 bool is64
= arm_feature(env
, ARM_FEATURE_AARCH64
);
9225 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
9226 rw
= ((env
->cp15
.scr_el3
& SCR_RW
) == SCR_RW
);
9228 /* Either EL2 is the highest EL (and so the EL2 register width
9229 * is given by is64); or there is no EL2 or EL3, in which case
9230 * the value of 'rw' does not affect the table lookup anyway.
9235 hcr_el2
= arm_hcr_el2_eff(env
);
9238 scr
= ((env
->cp15
.scr_el3
& SCR_IRQ
) == SCR_IRQ
);
9239 hcr
= hcr_el2
& HCR_IMO
;
9242 scr
= ((env
->cp15
.scr_el3
& SCR_FIQ
) == SCR_FIQ
);
9243 hcr
= hcr_el2
& HCR_FMO
;
9246 scr
= ((env
->cp15
.scr_el3
& SCR_EA
) == SCR_EA
);
9247 hcr
= hcr_el2
& HCR_AMO
;
9252 * For these purposes, TGE and AMO/IMO/FMO both force the
9253 * interrupt to EL2. Fold TGE into the bit extracted above.
9255 hcr
|= (hcr_el2
& HCR_TGE
) != 0;
9257 /* Perform a table-lookup for the target EL given the current state */
9258 target_el
= target_el_table
[is64
][scr
][rw
][hcr
][secure
][cur_el
];
9260 assert(target_el
> 0);
9265 void arm_log_exception(CPUState
*cs
)
9267 int idx
= cs
->exception_index
;
9269 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
9270 const char *exc
= NULL
;
9271 static const char * const excnames
[] = {
9272 [EXCP_UDEF
] = "Undefined Instruction",
9274 [EXCP_PREFETCH_ABORT
] = "Prefetch Abort",
9275 [EXCP_DATA_ABORT
] = "Data Abort",
9278 [EXCP_BKPT
] = "Breakpoint",
9279 [EXCP_EXCEPTION_EXIT
] = "QEMU v7M exception exit",
9280 [EXCP_KERNEL_TRAP
] = "QEMU intercept of kernel commpage",
9281 [EXCP_HVC
] = "Hypervisor Call",
9282 [EXCP_HYP_TRAP
] = "Hypervisor Trap",
9283 [EXCP_SMC
] = "Secure Monitor Call",
9284 [EXCP_VIRQ
] = "Virtual IRQ",
9285 [EXCP_VFIQ
] = "Virtual FIQ",
9286 [EXCP_SEMIHOST
] = "Semihosting call",
9287 [EXCP_NOCP
] = "v7M NOCP UsageFault",
9288 [EXCP_INVSTATE
] = "v7M INVSTATE UsageFault",
9289 [EXCP_STKOF
] = "v8M STKOF UsageFault",
9290 [EXCP_LAZYFP
] = "v7M exception during lazy FP stacking",
9291 [EXCP_LSERR
] = "v8M LSERR UsageFault",
9292 [EXCP_UNALIGNED
] = "v7M UNALIGNED UsageFault",
9293 [EXCP_DIVBYZERO
] = "v7M DIVBYZERO UsageFault",
9294 [EXCP_VSERR
] = "Virtual SERR",
9297 if (idx
>= 0 && idx
< ARRAY_SIZE(excnames
)) {
9298 exc
= excnames
[idx
];
9303 qemu_log_mask(CPU_LOG_INT
, "Taking exception %d [%s] on CPU %d\n",
9304 idx
, exc
, cs
->cpu_index
);
9309 * Function used to synchronize QEMU's AArch64 register set with AArch32
9310 * register set. This is necessary when switching between AArch32 and AArch64
9313 void aarch64_sync_32_to_64(CPUARMState
*env
)
9316 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
9318 /* We can blanket copy R[0:7] to X[0:7] */
9319 for (i
= 0; i
< 8; i
++) {
9320 env
->xregs
[i
] = env
->regs
[i
];
9324 * Unless we are in FIQ mode, x8-x12 come from the user registers r8-r12.
9325 * Otherwise, they come from the banked user regs.
9327 if (mode
== ARM_CPU_MODE_FIQ
) {
9328 for (i
= 8; i
< 13; i
++) {
9329 env
->xregs
[i
] = env
->usr_regs
[i
- 8];
9332 for (i
= 8; i
< 13; i
++) {
9333 env
->xregs
[i
] = env
->regs
[i
];
9338 * Registers x13-x23 are the various mode SP and FP registers. Registers
9339 * r13 and r14 are only copied if we are in that mode, otherwise we copy
9340 * from the mode banked register.
9342 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
9343 env
->xregs
[13] = env
->regs
[13];
9344 env
->xregs
[14] = env
->regs
[14];
9346 env
->xregs
[13] = env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)];
9347 /* HYP is an exception in that it is copied from r14 */
9348 if (mode
== ARM_CPU_MODE_HYP
) {
9349 env
->xregs
[14] = env
->regs
[14];
9351 env
->xregs
[14] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_USR
)];
9355 if (mode
== ARM_CPU_MODE_HYP
) {
9356 env
->xregs
[15] = env
->regs
[13];
9358 env
->xregs
[15] = env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)];
9361 if (mode
== ARM_CPU_MODE_IRQ
) {
9362 env
->xregs
[16] = env
->regs
[14];
9363 env
->xregs
[17] = env
->regs
[13];
9365 env
->xregs
[16] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_IRQ
)];
9366 env
->xregs
[17] = env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)];
9369 if (mode
== ARM_CPU_MODE_SVC
) {
9370 env
->xregs
[18] = env
->regs
[14];
9371 env
->xregs
[19] = env
->regs
[13];
9373 env
->xregs
[18] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_SVC
)];
9374 env
->xregs
[19] = env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)];
9377 if (mode
== ARM_CPU_MODE_ABT
) {
9378 env
->xregs
[20] = env
->regs
[14];
9379 env
->xregs
[21] = env
->regs
[13];
9381 env
->xregs
[20] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_ABT
)];
9382 env
->xregs
[21] = env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)];
9385 if (mode
== ARM_CPU_MODE_UND
) {
9386 env
->xregs
[22] = env
->regs
[14];
9387 env
->xregs
[23] = env
->regs
[13];
9389 env
->xregs
[22] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_UND
)];
9390 env
->xregs
[23] = env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)];
9394 * Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
9395 * mode, then we can copy from r8-r14. Otherwise, we copy from the
9396 * FIQ bank for r8-r14.
9398 if (mode
== ARM_CPU_MODE_FIQ
) {
9399 for (i
= 24; i
< 31; i
++) {
9400 env
->xregs
[i
] = env
->regs
[i
- 16]; /* X[24:30] <- R[8:14] */
9403 for (i
= 24; i
< 29; i
++) {
9404 env
->xregs
[i
] = env
->fiq_regs
[i
- 24];
9406 env
->xregs
[29] = env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)];
9407 env
->xregs
[30] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_FIQ
)];
9410 env
->pc
= env
->regs
[15];
9414 * Function used to synchronize QEMU's AArch32 register set with AArch64
9415 * register set. This is necessary when switching between AArch32 and AArch64
9418 void aarch64_sync_64_to_32(CPUARMState
*env
)
9421 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
9423 /* We can blanket copy X[0:7] to R[0:7] */
9424 for (i
= 0; i
< 8; i
++) {
9425 env
->regs
[i
] = env
->xregs
[i
];
9429 * Unless we are in FIQ mode, r8-r12 come from the user registers x8-x12.
9430 * Otherwise, we copy x8-x12 into the banked user regs.
9432 if (mode
== ARM_CPU_MODE_FIQ
) {
9433 for (i
= 8; i
< 13; i
++) {
9434 env
->usr_regs
[i
- 8] = env
->xregs
[i
];
9437 for (i
= 8; i
< 13; i
++) {
9438 env
->regs
[i
] = env
->xregs
[i
];
9443 * Registers r13 & r14 depend on the current mode.
9444 * If we are in a given mode, we copy the corresponding x registers to r13
9445 * and r14. Otherwise, we copy the x register to the banked r13 and r14
9448 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
9449 env
->regs
[13] = env
->xregs
[13];
9450 env
->regs
[14] = env
->xregs
[14];
9452 env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[13];
9455 * HYP is an exception in that it does not have its own banked r14 but
9456 * shares the USR r14
9458 if (mode
== ARM_CPU_MODE_HYP
) {
9459 env
->regs
[14] = env
->xregs
[14];
9461 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[14];
9465 if (mode
== ARM_CPU_MODE_HYP
) {
9466 env
->regs
[13] = env
->xregs
[15];
9468 env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)] = env
->xregs
[15];
9471 if (mode
== ARM_CPU_MODE_IRQ
) {
9472 env
->regs
[14] = env
->xregs
[16];
9473 env
->regs
[13] = env
->xregs
[17];
9475 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[16];
9476 env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[17];
9479 if (mode
== ARM_CPU_MODE_SVC
) {
9480 env
->regs
[14] = env
->xregs
[18];
9481 env
->regs
[13] = env
->xregs
[19];
9483 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[18];
9484 env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[19];
9487 if (mode
== ARM_CPU_MODE_ABT
) {
9488 env
->regs
[14] = env
->xregs
[20];
9489 env
->regs
[13] = env
->xregs
[21];
9491 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[20];
9492 env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[21];
9495 if (mode
== ARM_CPU_MODE_UND
) {
9496 env
->regs
[14] = env
->xregs
[22];
9497 env
->regs
[13] = env
->xregs
[23];
9499 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[22];
9500 env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[23];
9503 /* Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
9504 * mode, then we can copy to r8-r14. Otherwise, we copy to the
9505 * FIQ bank for r8-r14.
9507 if (mode
== ARM_CPU_MODE_FIQ
) {
9508 for (i
= 24; i
< 31; i
++) {
9509 env
->regs
[i
- 16] = env
->xregs
[i
]; /* X[24:30] -> R[8:14] */
9512 for (i
= 24; i
< 29; i
++) {
9513 env
->fiq_regs
[i
- 24] = env
->xregs
[i
];
9515 env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[29];
9516 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[30];
9519 env
->regs
[15] = env
->pc
;
9522 static void take_aarch32_exception(CPUARMState
*env
, int new_mode
,
9523 uint32_t mask
, uint32_t offset
,
9528 /* Change the CPU state so as to actually take the exception. */
9529 switch_mode(env
, new_mode
);
9532 * For exceptions taken to AArch32 we must clear the SS bit in both
9533 * PSTATE and in the old-state value we save to SPSR_<mode>, so zero it now.
9535 env
->pstate
&= ~PSTATE_SS
;
9536 env
->spsr
= cpsr_read(env
);
9537 /* Clear IT bits. */
9538 env
->condexec_bits
= 0;
9539 /* Switch to the new mode, and to the correct instruction set. */
9540 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~CPSR_M
) | new_mode
;
9542 /* This must be after mode switching. */
9543 new_el
= arm_current_el(env
);
9545 /* Set new mode endianness */
9546 env
->uncached_cpsr
&= ~CPSR_E
;
9547 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_EE
) {
9548 env
->uncached_cpsr
|= CPSR_E
;
9550 /* J and IL must always be cleared for exception entry */
9551 env
->uncached_cpsr
&= ~(CPSR_IL
| CPSR_J
);
9554 if (cpu_isar_feature(aa32_ssbs
, env_archcpu(env
))) {
9555 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_DSSBS_32
) {
9556 env
->uncached_cpsr
|= CPSR_SSBS
;
9558 env
->uncached_cpsr
&= ~CPSR_SSBS
;
9562 if (new_mode
== ARM_CPU_MODE_HYP
) {
9563 env
->thumb
= (env
->cp15
.sctlr_el
[2] & SCTLR_TE
) != 0;
9564 env
->elr_el
[2] = env
->regs
[15];
9566 /* CPSR.PAN is normally preserved preserved unless... */
9567 if (cpu_isar_feature(aa32_pan
, env_archcpu(env
))) {
9570 if (!arm_is_secure_below_el3(env
)) {
9571 /* ... the target is EL3, from non-secure state. */
9572 env
->uncached_cpsr
&= ~CPSR_PAN
;
9575 /* ... the target is EL3, from secure state ... */
9578 /* ... the target is EL1 and SCTLR.SPAN is 0. */
9579 if (!(env
->cp15
.sctlr_el
[new_el
] & SCTLR_SPAN
)) {
9580 env
->uncached_cpsr
|= CPSR_PAN
;
9586 * this is a lie, as there was no c1_sys on V4T/V5, but who cares
9587 * and we should just guard the thumb mode on V4
9589 if (arm_feature(env
, ARM_FEATURE_V4T
)) {
9591 (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_TE
) != 0;
9593 env
->regs
[14] = env
->regs
[15] + offset
;
9595 env
->regs
[15] = newpc
;
9596 arm_rebuild_hflags(env
);
9599 static void arm_cpu_do_interrupt_aarch32_hyp(CPUState
*cs
)
9602 * Handle exception entry to Hyp mode; this is sufficiently
9603 * different to entry to other AArch32 modes that we handle it
9606 * The vector table entry used is always the 0x14 Hyp mode entry point,
9607 * unless this is an UNDEF/SVC/HVC/abort taken from Hyp to Hyp.
9608 * The offset applied to the preferred return address is always zero
9609 * (see DDI0487C.a section G1.12.3).
9610 * PSTATE A/I/F masks are set based only on the SCR.EA/IRQ/FIQ values.
9612 uint32_t addr
, mask
;
9613 ARMCPU
*cpu
= ARM_CPU(cs
);
9614 CPUARMState
*env
= &cpu
->env
;
9616 switch (cs
->exception_index
) {
9624 /* Fall through to prefetch abort. */
9625 case EXCP_PREFETCH_ABORT
:
9626 env
->cp15
.ifar_s
= env
->exception
.vaddress
;
9627 qemu_log_mask(CPU_LOG_INT
, "...with HIFAR 0x%x\n",
9628 (uint32_t)env
->exception
.vaddress
);
9631 case EXCP_DATA_ABORT
:
9632 env
->cp15
.dfar_s
= env
->exception
.vaddress
;
9633 qemu_log_mask(CPU_LOG_INT
, "...with HDFAR 0x%x\n",
9634 (uint32_t)env
->exception
.vaddress
);
9650 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
9653 if (cs
->exception_index
!= EXCP_IRQ
&& cs
->exception_index
!= EXCP_FIQ
) {
9654 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
9656 * QEMU syndrome values are v8-style. v7 has the IL bit
9657 * UNK/SBZP for "field not valid" cases, where v8 uses RES1.
9658 * If this is a v7 CPU, squash the IL bit in those cases.
9660 if (cs
->exception_index
== EXCP_PREFETCH_ABORT
||
9661 (cs
->exception_index
== EXCP_DATA_ABORT
&&
9662 !(env
->exception
.syndrome
& ARM_EL_ISV
)) ||
9663 syn_get_ec(env
->exception
.syndrome
) == EC_UNCATEGORIZED
) {
9664 env
->exception
.syndrome
&= ~ARM_EL_IL
;
9667 env
->cp15
.esr_el
[2] = env
->exception
.syndrome
;
9670 if (arm_current_el(env
) != 2 && addr
< 0x14) {
9675 if (!(env
->cp15
.scr_el3
& SCR_EA
)) {
9678 if (!(env
->cp15
.scr_el3
& SCR_IRQ
)) {
9681 if (!(env
->cp15
.scr_el3
& SCR_FIQ
)) {
9685 addr
+= env
->cp15
.hvbar
;
9687 take_aarch32_exception(env
, ARM_CPU_MODE_HYP
, mask
, 0, addr
);
9690 static void arm_cpu_do_interrupt_aarch32(CPUState
*cs
)
9692 ARMCPU
*cpu
= ARM_CPU(cs
);
9693 CPUARMState
*env
= &cpu
->env
;
9700 /* If this is a debug exception we must update the DBGDSCR.MOE bits */
9701 switch (syn_get_ec(env
->exception
.syndrome
)) {
9703 case EC_BREAKPOINT_SAME_EL
:
9707 case EC_WATCHPOINT_SAME_EL
:
9713 case EC_VECTORCATCH
:
9722 env
->cp15
.mdscr_el1
= deposit64(env
->cp15
.mdscr_el1
, 2, 4, moe
);
9725 if (env
->exception
.target_el
== 2) {
9726 arm_cpu_do_interrupt_aarch32_hyp(cs
);
9730 switch (cs
->exception_index
) {
9732 new_mode
= ARM_CPU_MODE_UND
;
9741 new_mode
= ARM_CPU_MODE_SVC
;
9744 /* The PC already points to the next instruction. */
9748 /* Fall through to prefetch abort. */
9749 case EXCP_PREFETCH_ABORT
:
9750 A32_BANKED_CURRENT_REG_SET(env
, ifsr
, env
->exception
.fsr
);
9751 A32_BANKED_CURRENT_REG_SET(env
, ifar
, env
->exception
.vaddress
);
9752 qemu_log_mask(CPU_LOG_INT
, "...with IFSR 0x%x IFAR 0x%x\n",
9753 env
->exception
.fsr
, (uint32_t)env
->exception
.vaddress
);
9754 new_mode
= ARM_CPU_MODE_ABT
;
9756 mask
= CPSR_A
| CPSR_I
;
9759 case EXCP_DATA_ABORT
:
9760 A32_BANKED_CURRENT_REG_SET(env
, dfsr
, env
->exception
.fsr
);
9761 A32_BANKED_CURRENT_REG_SET(env
, dfar
, env
->exception
.vaddress
);
9762 qemu_log_mask(CPU_LOG_INT
, "...with DFSR 0x%x DFAR 0x%x\n",
9764 (uint32_t)env
->exception
.vaddress
);
9765 new_mode
= ARM_CPU_MODE_ABT
;
9767 mask
= CPSR_A
| CPSR_I
;
9771 new_mode
= ARM_CPU_MODE_IRQ
;
9773 /* Disable IRQ and imprecise data aborts. */
9774 mask
= CPSR_A
| CPSR_I
;
9776 if (env
->cp15
.scr_el3
& SCR_IRQ
) {
9777 /* IRQ routed to monitor mode */
9778 new_mode
= ARM_CPU_MODE_MON
;
9783 new_mode
= ARM_CPU_MODE_FIQ
;
9785 /* Disable FIQ, IRQ and imprecise data aborts. */
9786 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
9787 if (env
->cp15
.scr_el3
& SCR_FIQ
) {
9788 /* FIQ routed to monitor mode */
9789 new_mode
= ARM_CPU_MODE_MON
;
9794 new_mode
= ARM_CPU_MODE_IRQ
;
9796 /* Disable IRQ and imprecise data aborts. */
9797 mask
= CPSR_A
| CPSR_I
;
9801 new_mode
= ARM_CPU_MODE_FIQ
;
9803 /* Disable FIQ, IRQ and imprecise data aborts. */
9804 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
9810 * Note that this is reported as a data abort, but the DFAR
9811 * has an UNKNOWN value. Construct the SError syndrome from
9812 * AET and ExT fields.
9814 ARMMMUFaultInfo fi
= { .type
= ARMFault_AsyncExternal
, };
9816 if (extended_addresses_enabled(env
)) {
9817 env
->exception
.fsr
= arm_fi_to_lfsc(&fi
);
9819 env
->exception
.fsr
= arm_fi_to_sfsc(&fi
);
9821 env
->exception
.fsr
|= env
->cp15
.vsesr_el2
& 0xd000;
9822 A32_BANKED_CURRENT_REG_SET(env
, dfsr
, env
->exception
.fsr
);
9823 qemu_log_mask(CPU_LOG_INT
, "...with IFSR 0x%x\n",
9824 env
->exception
.fsr
);
9826 new_mode
= ARM_CPU_MODE_ABT
;
9828 mask
= CPSR_A
| CPSR_I
;
9833 new_mode
= ARM_CPU_MODE_MON
;
9835 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
9839 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
9840 return; /* Never happens. Keep compiler happy. */
9843 if (new_mode
== ARM_CPU_MODE_MON
) {
9844 addr
+= env
->cp15
.mvbar
;
9845 } else if (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_V
) {
9846 /* High vectors. When enabled, base address cannot be remapped. */
9849 /* ARM v7 architectures provide a vector base address register to remap
9850 * the interrupt vector table.
9851 * This register is only followed in non-monitor mode, and is banked.
9852 * Note: only bits 31:5 are valid.
9854 addr
+= A32_BANKED_CURRENT_REG_GET(env
, vbar
);
9857 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
) {
9858 env
->cp15
.scr_el3
&= ~SCR_NS
;
9861 take_aarch32_exception(env
, new_mode
, mask
, offset
, addr
);
9864 static int aarch64_regnum(CPUARMState
*env
, int aarch32_reg
)
9867 * Return the register number of the AArch64 view of the AArch32
9868 * register @aarch32_reg. The CPUARMState CPSR is assumed to still
9869 * be that of the AArch32 mode the exception came from.
9871 int mode
= env
->uncached_cpsr
& CPSR_M
;
9873 switch (aarch32_reg
) {
9877 return mode
== ARM_CPU_MODE_FIQ
? aarch32_reg
+ 16 : aarch32_reg
;
9880 case ARM_CPU_MODE_USR
:
9881 case ARM_CPU_MODE_SYS
:
9883 case ARM_CPU_MODE_HYP
:
9885 case ARM_CPU_MODE_IRQ
:
9887 case ARM_CPU_MODE_SVC
:
9889 case ARM_CPU_MODE_ABT
:
9891 case ARM_CPU_MODE_UND
:
9893 case ARM_CPU_MODE_FIQ
:
9896 g_assert_not_reached();
9900 case ARM_CPU_MODE_USR
:
9901 case ARM_CPU_MODE_SYS
:
9902 case ARM_CPU_MODE_HYP
:
9904 case ARM_CPU_MODE_IRQ
:
9906 case ARM_CPU_MODE_SVC
:
9908 case ARM_CPU_MODE_ABT
:
9910 case ARM_CPU_MODE_UND
:
9912 case ARM_CPU_MODE_FIQ
:
9915 g_assert_not_reached();
9920 g_assert_not_reached();
9924 static uint32_t cpsr_read_for_spsr_elx(CPUARMState
*env
)
9926 uint32_t ret
= cpsr_read(env
);
9928 /* Move DIT to the correct location for SPSR_ELx */
9929 if (ret
& CPSR_DIT
) {
9933 /* Merge PSTATE.SS into SPSR_ELx */
9934 ret
|= env
->pstate
& PSTATE_SS
;
9939 static bool syndrome_is_sync_extabt(uint32_t syndrome
)
9941 /* Return true if this syndrome value is a synchronous external abort */
9942 switch (syn_get_ec(syndrome
)) {
9944 case EC_INSNABORT_SAME_EL
:
9946 case EC_DATAABORT_SAME_EL
:
9947 /* Look at fault status code for all the synchronous ext abort cases */
9948 switch (syndrome
& 0x3f) {
9964 /* Handle exception entry to a target EL which is using AArch64 */
9965 static void arm_cpu_do_interrupt_aarch64(CPUState
*cs
)
9967 ARMCPU
*cpu
= ARM_CPU(cs
);
9968 CPUARMState
*env
= &cpu
->env
;
9969 unsigned int new_el
= env
->exception
.target_el
;
9970 target_ulong addr
= env
->cp15
.vbar_el
[new_el
];
9971 unsigned int new_mode
= aarch64_pstate_mode(new_el
, true);
9972 unsigned int old_mode
;
9973 unsigned int cur_el
= arm_current_el(env
);
9977 * Note that new_el can never be 0. If cur_el is 0, then
9978 * el0_a64 is is_a64(), else el0_a64 is ignored.
9980 aarch64_sve_change_el(env
, cur_el
, new_el
, is_a64(env
));
9982 if (cur_el
< new_el
) {
9983 /* Entry vector offset depends on whether the implemented EL
9984 * immediately lower than the target level is using AArch32 or AArch64
9991 is_aa64
= (env
->cp15
.scr_el3
& SCR_RW
) != 0;
9994 hcr
= arm_hcr_el2_eff(env
);
9995 if ((hcr
& (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
9996 is_aa64
= (hcr
& HCR_RW
) != 0;
10001 is_aa64
= is_a64(env
);
10004 g_assert_not_reached();
10012 } else if (pstate_read(env
) & PSTATE_SP
) {
10016 switch (cs
->exception_index
) {
10017 case EXCP_PREFETCH_ABORT
:
10018 case EXCP_DATA_ABORT
:
10020 * FEAT_DoubleFault allows synchronous external aborts taken to EL3
10021 * to be taken to the SError vector entrypoint.
10023 if (new_el
== 3 && (env
->cp15
.scr_el3
& SCR_EASE
) &&
10024 syndrome_is_sync_extabt(env
->exception
.syndrome
)) {
10027 env
->cp15
.far_el
[new_el
] = env
->exception
.vaddress
;
10028 qemu_log_mask(CPU_LOG_INT
, "...with FAR 0x%" PRIx64
"\n",
10029 env
->cp15
.far_el
[new_el
]);
10035 case EXCP_HYP_TRAP
:
10037 switch (syn_get_ec(env
->exception
.syndrome
)) {
10038 case EC_ADVSIMDFPACCESSTRAP
:
10040 * QEMU internal FP/SIMD syndromes from AArch32 include the
10041 * TA and coproc fields which are only exposed if the exception
10042 * is taken to AArch32 Hyp mode. Mask them out to get a valid
10043 * AArch64 format syndrome.
10045 env
->exception
.syndrome
&= ~MAKE_64BIT_MASK(0, 20);
10047 case EC_CP14RTTRAP
:
10048 case EC_CP15RTTRAP
:
10049 case EC_CP14DTTRAP
:
10051 * For a trap on AArch32 MRC/MCR/LDC/STC the Rt field is currently
10052 * the raw register field from the insn; when taking this to
10053 * AArch64 we must convert it to the AArch64 view of the register
10054 * number. Notice that we read a 4-bit AArch32 register number and
10055 * write back a 5-bit AArch64 one.
10057 rt
= extract32(env
->exception
.syndrome
, 5, 4);
10058 rt
= aarch64_regnum(env
, rt
);
10059 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
10062 case EC_CP15RRTTRAP
:
10063 case EC_CP14RRTTRAP
:
10064 /* Similarly for MRRC/MCRR traps for Rt and Rt2 fields */
10065 rt
= extract32(env
->exception
.syndrome
, 5, 4);
10066 rt
= aarch64_regnum(env
, rt
);
10067 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
10069 rt
= extract32(env
->exception
.syndrome
, 10, 4);
10070 rt
= aarch64_regnum(env
, rt
);
10071 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
10075 env
->cp15
.esr_el
[new_el
] = env
->exception
.syndrome
;
10087 /* Construct the SError syndrome from IDS and ISS fields. */
10088 env
->exception
.syndrome
= syn_serror(env
->cp15
.vsesr_el2
& 0x1ffffff);
10089 env
->cp15
.esr_el
[new_el
] = env
->exception
.syndrome
;
10092 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
10096 old_mode
= pstate_read(env
);
10097 aarch64_save_sp(env
, arm_current_el(env
));
10098 env
->elr_el
[new_el
] = env
->pc
;
10100 old_mode
= cpsr_read_for_spsr_elx(env
);
10101 env
->elr_el
[new_el
] = env
->regs
[15];
10103 aarch64_sync_32_to_64(env
);
10105 env
->condexec_bits
= 0;
10107 env
->banked_spsr
[aarch64_banked_spsr_index(new_el
)] = old_mode
;
10109 qemu_log_mask(CPU_LOG_INT
, "...with ELR 0x%" PRIx64
"\n",
10110 env
->elr_el
[new_el
]);
10112 if (cpu_isar_feature(aa64_pan
, cpu
)) {
10113 /* The value of PSTATE.PAN is normally preserved, except when ... */
10114 new_mode
|= old_mode
& PSTATE_PAN
;
10117 /* ... the target is EL2 with HCR_EL2.{E2H,TGE} == '11' ... */
10118 if ((arm_hcr_el2_eff(env
) & (HCR_E2H
| HCR_TGE
))
10119 != (HCR_E2H
| HCR_TGE
)) {
10124 /* ... the target is EL1 ... */
10125 /* ... and SCTLR_ELx.SPAN == 0, then set to 1. */
10126 if ((env
->cp15
.sctlr_el
[new_el
] & SCTLR_SPAN
) == 0) {
10127 new_mode
|= PSTATE_PAN
;
10132 if (cpu_isar_feature(aa64_mte
, cpu
)) {
10133 new_mode
|= PSTATE_TCO
;
10136 if (cpu_isar_feature(aa64_ssbs
, cpu
)) {
10137 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_DSSBS_64
) {
10138 new_mode
|= PSTATE_SSBS
;
10140 new_mode
&= ~PSTATE_SSBS
;
10144 pstate_write(env
, PSTATE_DAIF
| new_mode
);
10145 env
->aarch64
= true;
10146 aarch64_restore_sp(env
, new_el
);
10147 helper_rebuild_hflags_a64(env
, new_el
);
10151 qemu_log_mask(CPU_LOG_INT
, "...to EL%d PC 0x%" PRIx64
" PSTATE 0x%x\n",
10152 new_el
, env
->pc
, pstate_read(env
));
10156 * Do semihosting call and set the appropriate return value. All the
10157 * permission and validity checks have been done at translate time.
10159 * We only see semihosting exceptions in TCG only as they are not
10160 * trapped to the hypervisor in KVM.
10163 static void handle_semihosting(CPUState
*cs
)
10165 ARMCPU
*cpu
= ARM_CPU(cs
);
10166 CPUARMState
*env
= &cpu
->env
;
10169 qemu_log_mask(CPU_LOG_INT
,
10170 "...handling as semihosting call 0x%" PRIx64
"\n",
10172 do_common_semihosting(cs
);
10175 qemu_log_mask(CPU_LOG_INT
,
10176 "...handling as semihosting call 0x%x\n",
10178 do_common_semihosting(cs
);
10179 env
->regs
[15] += env
->thumb
? 2 : 4;
10184 /* Handle a CPU exception for A and R profile CPUs.
10185 * Do any appropriate logging, handle PSCI calls, and then hand off
10186 * to the AArch64-entry or AArch32-entry function depending on the
10187 * target exception level's register width.
10189 * Note: this is used for both TCG (as the do_interrupt tcg op),
10190 * and KVM to re-inject guest debug exceptions, and to
10191 * inject a Synchronous-External-Abort.
10193 void arm_cpu_do_interrupt(CPUState
*cs
)
10195 ARMCPU
*cpu
= ARM_CPU(cs
);
10196 CPUARMState
*env
= &cpu
->env
;
10197 unsigned int new_el
= env
->exception
.target_el
;
10199 assert(!arm_feature(env
, ARM_FEATURE_M
));
10201 arm_log_exception(cs
);
10202 qemu_log_mask(CPU_LOG_INT
, "...from EL%d to EL%d\n", arm_current_el(env
),
10204 if (qemu_loglevel_mask(CPU_LOG_INT
)
10205 && !excp_is_internal(cs
->exception_index
)) {
10206 qemu_log_mask(CPU_LOG_INT
, "...with ESR 0x%x/0x%" PRIx32
"\n",
10207 syn_get_ec(env
->exception
.syndrome
),
10208 env
->exception
.syndrome
);
10211 if (arm_is_psci_call(cpu
, cs
->exception_index
)) {
10212 arm_handle_psci_call(cpu
);
10213 qemu_log_mask(CPU_LOG_INT
, "...handled as PSCI call\n");
10218 * Semihosting semantics depend on the register width of the code
10219 * that caused the exception, not the target exception level, so
10220 * must be handled here.
10223 if (cs
->exception_index
== EXCP_SEMIHOST
) {
10224 handle_semihosting(cs
);
10229 /* Hooks may change global state so BQL should be held, also the
10230 * BQL needs to be held for any modification of
10231 * cs->interrupt_request.
10233 g_assert(qemu_mutex_iothread_locked());
10235 arm_call_pre_el_change_hook(cpu
);
10237 assert(!excp_is_internal(cs
->exception_index
));
10238 if (arm_el_is_aa64(env
, new_el
)) {
10239 arm_cpu_do_interrupt_aarch64(cs
);
10241 arm_cpu_do_interrupt_aarch32(cs
);
10244 arm_call_el_change_hook(cpu
);
10246 if (!kvm_enabled()) {
10247 cs
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
10250 #endif /* !CONFIG_USER_ONLY */
10252 uint64_t arm_sctlr(CPUARMState
*env
, int el
)
10254 /* Only EL0 needs to be adjusted for EL1&0 or EL2&0. */
10256 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, 0);
10257 el
= (mmu_idx
== ARMMMUIdx_E20_0
|| mmu_idx
== ARMMMUIdx_SE20_0
)
10260 return env
->cp15
.sctlr_el
[el
];
10263 int aa64_va_parameter_tbi(uint64_t tcr
, ARMMMUIdx mmu_idx
)
10265 if (regime_has_2_ranges(mmu_idx
)) {
10266 return extract64(tcr
, 37, 2);
10267 } else if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
10268 return 0; /* VTCR_EL2 */
10270 /* Replicate the single TBI bit so we always have 2 bits. */
10271 return extract32(tcr
, 20, 1) * 3;
10275 int aa64_va_parameter_tbid(uint64_t tcr
, ARMMMUIdx mmu_idx
)
10277 if (regime_has_2_ranges(mmu_idx
)) {
10278 return extract64(tcr
, 51, 2);
10279 } else if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
10280 return 0; /* VTCR_EL2 */
10282 /* Replicate the single TBID bit so we always have 2 bits. */
10283 return extract32(tcr
, 29, 1) * 3;
10287 static int aa64_va_parameter_tcma(uint64_t tcr
, ARMMMUIdx mmu_idx
)
10289 if (regime_has_2_ranges(mmu_idx
)) {
10290 return extract64(tcr
, 57, 2);
10292 /* Replicate the single TCMA bit so we always have 2 bits. */
10293 return extract32(tcr
, 30, 1) * 3;
10297 ARMVAParameters
aa64_va_parameters(CPUARMState
*env
, uint64_t va
,
10298 ARMMMUIdx mmu_idx
, bool data
)
10300 uint64_t tcr
= regime_tcr(env
, mmu_idx
);
10301 bool epd
, hpd
, using16k
, using64k
, tsz_oob
, ds
;
10302 int select
, tsz
, tbi
, max_tsz
, min_tsz
, ps
, sh
;
10303 ARMCPU
*cpu
= env_archcpu(env
);
10305 if (!regime_has_2_ranges(mmu_idx
)) {
10307 tsz
= extract32(tcr
, 0, 6);
10308 using64k
= extract32(tcr
, 14, 1);
10309 using16k
= extract32(tcr
, 15, 1);
10310 if (mmu_idx
== ARMMMUIdx_Stage2
|| mmu_idx
== ARMMMUIdx_Stage2_S
) {
10314 hpd
= extract32(tcr
, 24, 1);
10317 sh
= extract32(tcr
, 12, 2);
10318 ps
= extract32(tcr
, 16, 3);
10319 ds
= extract64(tcr
, 32, 1);
10322 * Bit 55 is always between the two regions, and is canonical for
10323 * determining if address tagging is enabled.
10325 select
= extract64(va
, 55, 1);
10327 tsz
= extract32(tcr
, 0, 6);
10328 epd
= extract32(tcr
, 7, 1);
10329 sh
= extract32(tcr
, 12, 2);
10330 using64k
= extract32(tcr
, 14, 1);
10331 using16k
= extract32(tcr
, 15, 1);
10332 hpd
= extract64(tcr
, 41, 1);
10334 int tg
= extract32(tcr
, 30, 2);
10335 using16k
= tg
== 1;
10336 using64k
= tg
== 3;
10337 tsz
= extract32(tcr
, 16, 6);
10338 epd
= extract32(tcr
, 23, 1);
10339 sh
= extract32(tcr
, 28, 2);
10340 hpd
= extract64(tcr
, 42, 1);
10342 ps
= extract64(tcr
, 32, 3);
10343 ds
= extract64(tcr
, 59, 1);
10346 if (cpu_isar_feature(aa64_st
, cpu
)) {
10347 max_tsz
= 48 - using64k
;
10353 * DS is RES0 unless FEAT_LPA2 is supported for the given page size;
10354 * adjust the effective value of DS, as documented.
10358 if (cpu_isar_feature(aa64_lva
, cpu
)) {
10364 case ARMMMUIdx_Stage2
:
10365 case ARMMMUIdx_Stage2_S
:
10367 ds
= cpu_isar_feature(aa64_tgran16_2_lpa2
, cpu
);
10369 ds
= cpu_isar_feature(aa64_tgran4_2_lpa2
, cpu
);
10374 ds
= cpu_isar_feature(aa64_tgran16_lpa2
, cpu
);
10376 ds
= cpu_isar_feature(aa64_tgran4_lpa2
, cpu
);
10385 if (tsz
> max_tsz
) {
10388 } else if (tsz
< min_tsz
) {
10395 /* Present TBI as a composite with TBID. */
10396 tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
10398 tbi
&= ~aa64_va_parameter_tbid(tcr
, mmu_idx
);
10400 tbi
= (tbi
>> select
) & 1;
10402 return (ARMVAParameters
) {
10410 .using16k
= using16k
,
10411 .using64k
= using64k
,
10412 .tsz_oob
= tsz_oob
,
10417 /* Note that signed overflow is undefined in C. The following routines are
10418 careful to use unsigned types where modulo arithmetic is required.
10419 Failure to do so _will_ break on newer gcc. */
10421 /* Signed saturating arithmetic. */
10423 /* Perform 16-bit signed saturating addition. */
10424 static inline uint16_t add16_sat(uint16_t a
, uint16_t b
)
10429 if (((res
^ a
) & 0x8000) && !((a
^ b
) & 0x8000)) {
10438 /* Perform 8-bit signed saturating addition. */
10439 static inline uint8_t add8_sat(uint8_t a
, uint8_t b
)
10444 if (((res
^ a
) & 0x80) && !((a
^ b
) & 0x80)) {
10453 /* Perform 16-bit signed saturating subtraction. */
10454 static inline uint16_t sub16_sat(uint16_t a
, uint16_t b
)
10459 if (((res
^ a
) & 0x8000) && ((a
^ b
) & 0x8000)) {
10468 /* Perform 8-bit signed saturating subtraction. */
10469 static inline uint8_t sub8_sat(uint8_t a
, uint8_t b
)
10474 if (((res
^ a
) & 0x80) && ((a
^ b
) & 0x80)) {
10483 #define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
10484 #define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
10485 #define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
10486 #define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
10489 #include "op_addsub.h"
10491 /* Unsigned saturating arithmetic. */
10492 static inline uint16_t add16_usat(uint16_t a
, uint16_t b
)
10501 static inline uint16_t sub16_usat(uint16_t a
, uint16_t b
)
10509 static inline uint8_t add8_usat(uint8_t a
, uint8_t b
)
10518 static inline uint8_t sub8_usat(uint8_t a
, uint8_t b
)
10526 #define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
10527 #define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
10528 #define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
10529 #define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
10532 #include "op_addsub.h"
10534 /* Signed modulo arithmetic. */
10535 #define SARITH16(a, b, n, op) do { \
10537 sum = (int32_t)(int16_t)(a) op (int32_t)(int16_t)(b); \
10538 RESULT(sum, n, 16); \
10540 ge |= 3 << (n * 2); \
10543 #define SARITH8(a, b, n, op) do { \
10545 sum = (int32_t)(int8_t)(a) op (int32_t)(int8_t)(b); \
10546 RESULT(sum, n, 8); \
10552 #define ADD16(a, b, n) SARITH16(a, b, n, +)
10553 #define SUB16(a, b, n) SARITH16(a, b, n, -)
10554 #define ADD8(a, b, n) SARITH8(a, b, n, +)
10555 #define SUB8(a, b, n) SARITH8(a, b, n, -)
10559 #include "op_addsub.h"
10561 /* Unsigned modulo arithmetic. */
10562 #define ADD16(a, b, n) do { \
10564 sum = (uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b); \
10565 RESULT(sum, n, 16); \
10566 if ((sum >> 16) == 1) \
10567 ge |= 3 << (n * 2); \
10570 #define ADD8(a, b, n) do { \
10572 sum = (uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b); \
10573 RESULT(sum, n, 8); \
10574 if ((sum >> 8) == 1) \
10578 #define SUB16(a, b, n) do { \
10580 sum = (uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b); \
10581 RESULT(sum, n, 16); \
10582 if ((sum >> 16) == 0) \
10583 ge |= 3 << (n * 2); \
10586 #define SUB8(a, b, n) do { \
10588 sum = (uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b); \
10589 RESULT(sum, n, 8); \
10590 if ((sum >> 8) == 0) \
10597 #include "op_addsub.h"
10599 /* Halved signed arithmetic. */
10600 #define ADD16(a, b, n) \
10601 RESULT(((int32_t)(int16_t)(a) + (int32_t)(int16_t)(b)) >> 1, n, 16)
10602 #define SUB16(a, b, n) \
10603 RESULT(((int32_t)(int16_t)(a) - (int32_t)(int16_t)(b)) >> 1, n, 16)
10604 #define ADD8(a, b, n) \
10605 RESULT(((int32_t)(int8_t)(a) + (int32_t)(int8_t)(b)) >> 1, n, 8)
10606 #define SUB8(a, b, n) \
10607 RESULT(((int32_t)(int8_t)(a) - (int32_t)(int8_t)(b)) >> 1, n, 8)
10610 #include "op_addsub.h"
10612 /* Halved unsigned arithmetic. */
10613 #define ADD16(a, b, n) \
10614 RESULT(((uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b)) >> 1, n, 16)
10615 #define SUB16(a, b, n) \
10616 RESULT(((uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b)) >> 1, n, 16)
10617 #define ADD8(a, b, n) \
10618 RESULT(((uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b)) >> 1, n, 8)
10619 #define SUB8(a, b, n) \
10620 RESULT(((uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b)) >> 1, n, 8)
10623 #include "op_addsub.h"
10625 static inline uint8_t do_usad(uint8_t a
, uint8_t b
)
10633 /* Unsigned sum of absolute byte differences. */
10634 uint32_t HELPER(usad8
)(uint32_t a
, uint32_t b
)
10637 sum
= do_usad(a
, b
);
10638 sum
+= do_usad(a
>> 8, b
>> 8);
10639 sum
+= do_usad(a
>> 16, b
>> 16);
10640 sum
+= do_usad(a
>> 24, b
>> 24);
10644 /* For ARMv6 SEL instruction. */
10645 uint32_t HELPER(sel_flags
)(uint32_t flags
, uint32_t a
, uint32_t b
)
10657 mask
|= 0xff000000;
10658 return (a
& mask
) | (b
& ~mask
);
10662 * The upper bytes of val (above the number specified by 'bytes') must have
10663 * been zeroed out by the caller.
10665 uint32_t HELPER(crc32
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
10669 stl_le_p(buf
, val
);
10671 /* zlib crc32 converts the accumulator and output to one's complement. */
10672 return crc32(acc
^ 0xffffffff, buf
, bytes
) ^ 0xffffffff;
10675 uint32_t HELPER(crc32c
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
10679 stl_le_p(buf
, val
);
10681 /* Linux crc32c converts the output to one's complement. */
10682 return crc32c(acc
, buf
, bytes
) ^ 0xffffffff;
10685 /* Return the exception level to which FP-disabled exceptions should
10686 * be taken, or 0 if FP is enabled.
10688 int fp_exception_el(CPUARMState
*env
, int cur_el
)
10690 #ifndef CONFIG_USER_ONLY
10693 /* CPACR and the CPTR registers don't exist before v6, so FP is
10694 * always accessible
10696 if (!arm_feature(env
, ARM_FEATURE_V6
)) {
10700 if (arm_feature(env
, ARM_FEATURE_M
)) {
10701 /* CPACR can cause a NOCP UsageFault taken to current security state */
10702 if (!v7m_cpacr_pass(env
, env
->v7m
.secure
, cur_el
!= 0)) {
10706 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
) && !env
->v7m
.secure
) {
10707 if (!extract32(env
->v7m
.nsacr
, 10, 1)) {
10708 /* FP insns cause a NOCP UsageFault taken to Secure */
10716 hcr_el2
= arm_hcr_el2_eff(env
);
10718 /* The CPACR controls traps to EL1, or PL1 if we're 32 bit:
10719 * 0, 2 : trap EL0 and EL1/PL1 accesses
10720 * 1 : trap only EL0 accesses
10721 * 3 : trap no accesses
10722 * This register is ignored if E2H+TGE are both set.
10724 if ((hcr_el2
& (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
10725 int fpen
= FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, FPEN
);
10735 /* Trap from Secure PL0 or PL1 to Secure PL1. */
10736 if (!arm_el_is_aa64(env
, 3)
10737 && (cur_el
== 3 || arm_is_secure_below_el3(env
))) {
10748 * The NSACR allows A-profile AArch32 EL3 and M-profile secure mode
10749 * to control non-secure access to the FPU. It doesn't have any
10750 * effect if EL3 is AArch64 or if EL3 doesn't exist at all.
10752 if ((arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
10753 cur_el
<= 2 && !arm_is_secure_below_el3(env
))) {
10754 if (!extract32(env
->cp15
.nsacr
, 10, 1)) {
10755 /* FP insns act as UNDEF */
10756 return cur_el
== 2 ? 2 : 1;
10761 * CPTR_EL2 is present in v7VE or v8, and changes format
10762 * with HCR_EL2.E2H (regardless of TGE).
10765 if (hcr_el2
& HCR_E2H
) {
10766 switch (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, FPEN
)) {
10768 if (cur_el
!= 0 || !(hcr_el2
& HCR_TGE
)) {
10776 } else if (arm_is_el2_enabled(env
)) {
10777 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TFP
)) {
10783 /* CPTR_EL3 : present in v8 */
10784 if (FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TFP
)) {
10785 /* Trap all FP ops to EL3 */
10792 /* Return the exception level we're running at if this is our mmu_idx */
10793 int arm_mmu_idx_to_el(ARMMMUIdx mmu_idx
)
10795 if (mmu_idx
& ARM_MMU_IDX_M
) {
10796 return mmu_idx
& ARM_MMU_IDX_M_PRIV
;
10800 case ARMMMUIdx_E10_0
:
10801 case ARMMMUIdx_E20_0
:
10802 case ARMMMUIdx_SE10_0
:
10803 case ARMMMUIdx_SE20_0
:
10805 case ARMMMUIdx_E10_1
:
10806 case ARMMMUIdx_E10_1_PAN
:
10807 case ARMMMUIdx_SE10_1
:
10808 case ARMMMUIdx_SE10_1_PAN
:
10811 case ARMMMUIdx_E20_2
:
10812 case ARMMMUIdx_E20_2_PAN
:
10813 case ARMMMUIdx_SE2
:
10814 case ARMMMUIdx_SE20_2
:
10815 case ARMMMUIdx_SE20_2_PAN
:
10817 case ARMMMUIdx_SE3
:
10820 g_assert_not_reached();
10825 ARMMMUIdx
arm_v7m_mmu_idx_for_secstate(CPUARMState
*env
, bool secstate
)
10827 g_assert_not_reached();
10831 ARMMMUIdx
arm_mmu_idx_el(CPUARMState
*env
, int el
)
10836 if (arm_feature(env
, ARM_FEATURE_M
)) {
10837 return arm_v7m_mmu_idx_for_secstate(env
, env
->v7m
.secure
);
10840 /* See ARM pseudo-function ELIsInHost. */
10843 hcr
= arm_hcr_el2_eff(env
);
10844 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
10845 idx
= ARMMMUIdx_E20_0
;
10847 idx
= ARMMMUIdx_E10_0
;
10851 if (env
->pstate
& PSTATE_PAN
) {
10852 idx
= ARMMMUIdx_E10_1_PAN
;
10854 idx
= ARMMMUIdx_E10_1
;
10858 /* Note that TGE does not apply at EL2. */
10859 if (arm_hcr_el2_eff(env
) & HCR_E2H
) {
10860 if (env
->pstate
& PSTATE_PAN
) {
10861 idx
= ARMMMUIdx_E20_2_PAN
;
10863 idx
= ARMMMUIdx_E20_2
;
10866 idx
= ARMMMUIdx_E2
;
10870 return ARMMMUIdx_SE3
;
10872 g_assert_not_reached();
10875 if (arm_is_secure_below_el3(env
)) {
10876 idx
&= ~ARM_MMU_IDX_A_NS
;
10882 ARMMMUIdx
arm_mmu_idx(CPUARMState
*env
)
10884 return arm_mmu_idx_el(env
, arm_current_el(env
));
10887 static CPUARMTBFlags
rebuild_hflags_common(CPUARMState
*env
, int fp_el
,
10889 CPUARMTBFlags flags
)
10891 DP_TBFLAG_ANY(flags
, FPEXC_EL
, fp_el
);
10892 DP_TBFLAG_ANY(flags
, MMUIDX
, arm_to_core_mmu_idx(mmu_idx
));
10894 if (arm_singlestep_active(env
)) {
10895 DP_TBFLAG_ANY(flags
, SS_ACTIVE
, 1);
10900 static CPUARMTBFlags
rebuild_hflags_common_32(CPUARMState
*env
, int fp_el
,
10902 CPUARMTBFlags flags
)
10904 bool sctlr_b
= arm_sctlr_b(env
);
10907 DP_TBFLAG_A32(flags
, SCTLR__B
, 1);
10909 if (arm_cpu_data_is_big_endian_a32(env
, sctlr_b
)) {
10910 DP_TBFLAG_ANY(flags
, BE_DATA
, 1);
10912 DP_TBFLAG_A32(flags
, NS
, !access_secure_reg(env
));
10914 return rebuild_hflags_common(env
, fp_el
, mmu_idx
, flags
);
10917 static CPUARMTBFlags
rebuild_hflags_m32(CPUARMState
*env
, int fp_el
,
10920 CPUARMTBFlags flags
= {};
10921 uint32_t ccr
= env
->v7m
.ccr
[env
->v7m
.secure
];
10923 /* Without HaveMainExt, CCR.UNALIGN_TRP is RES1. */
10924 if (ccr
& R_V7M_CCR_UNALIGN_TRP_MASK
) {
10925 DP_TBFLAG_ANY(flags
, ALIGN_MEM
, 1);
10928 if (arm_v7m_is_handler_mode(env
)) {
10929 DP_TBFLAG_M32(flags
, HANDLER
, 1);
10933 * v8M always applies stack limit checks unless CCR.STKOFHFNMIGN
10934 * is suppressing them because the requested execution priority
10937 if (arm_feature(env
, ARM_FEATURE_V8
) &&
10938 !((mmu_idx
& ARM_MMU_IDX_M_NEGPRI
) &&
10939 (ccr
& R_V7M_CCR_STKOFHFNMIGN_MASK
))) {
10940 DP_TBFLAG_M32(flags
, STACKCHECK
, 1);
10943 return rebuild_hflags_common_32(env
, fp_el
, mmu_idx
, flags
);
10946 static CPUARMTBFlags
rebuild_hflags_a32(CPUARMState
*env
, int fp_el
,
10949 CPUARMTBFlags flags
= {};
10950 int el
= arm_current_el(env
);
10952 if (arm_sctlr(env
, el
) & SCTLR_A
) {
10953 DP_TBFLAG_ANY(flags
, ALIGN_MEM
, 1);
10956 if (arm_el_is_aa64(env
, 1)) {
10957 DP_TBFLAG_A32(flags
, VFPEN
, 1);
10960 if (el
< 2 && env
->cp15
.hstr_el2
&&
10961 (arm_hcr_el2_eff(env
) & (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
10962 DP_TBFLAG_A32(flags
, HSTR_ACTIVE
, 1);
10965 if (env
->uncached_cpsr
& CPSR_IL
) {
10966 DP_TBFLAG_ANY(flags
, PSTATE__IL
, 1);
10970 * The SME exception we are testing for is raised via
10971 * AArch64.CheckFPAdvSIMDEnabled(), as called from
10972 * AArch32.CheckAdvSIMDOrFPEnabled().
10975 && FIELD_EX64(env
->svcr
, SVCR
, SM
)
10976 && (!arm_is_el2_enabled(env
)
10977 || (arm_el_is_aa64(env
, 2) && !(env
->cp15
.hcr_el2
& HCR_TGE
)))
10978 && arm_el_is_aa64(env
, 1)
10979 && !sme_fa64(env
, el
)) {
10980 DP_TBFLAG_A32(flags
, SME_TRAP_NONSTREAMING
, 1);
10983 return rebuild_hflags_common_32(env
, fp_el
, mmu_idx
, flags
);
10986 static CPUARMTBFlags
rebuild_hflags_a64(CPUARMState
*env
, int el
, int fp_el
,
10989 CPUARMTBFlags flags
= {};
10990 ARMMMUIdx stage1
= stage_1_mmu_idx(mmu_idx
);
10991 uint64_t tcr
= regime_tcr(env
, mmu_idx
);
10995 DP_TBFLAG_ANY(flags
, AARCH64_STATE
, 1);
10997 /* Get control bits for tagged addresses. */
10998 tbid
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
10999 tbii
= tbid
& ~aa64_va_parameter_tbid(tcr
, mmu_idx
);
11001 DP_TBFLAG_A64(flags
, TBII
, tbii
);
11002 DP_TBFLAG_A64(flags
, TBID
, tbid
);
11004 if (cpu_isar_feature(aa64_sve
, env_archcpu(env
))) {
11005 int sve_el
= sve_exception_el(env
, el
);
11008 * If either FP or SVE are disabled, translator does not need len.
11009 * If SVE EL > FP EL, FP exception has precedence, and translator
11010 * does not need SVE EL. Save potential re-translations by forcing
11011 * the unneeded data to zero.
11014 if (sve_el
> fp_el
) {
11017 } else if (sve_el
== 0) {
11018 DP_TBFLAG_A64(flags
, VL
, sve_vqm1_for_el(env
, el
));
11020 DP_TBFLAG_A64(flags
, SVEEXC_EL
, sve_el
);
11022 if (cpu_isar_feature(aa64_sme
, env_archcpu(env
))) {
11023 int sme_el
= sme_exception_el(env
, el
);
11024 bool sm
= FIELD_EX64(env
->svcr
, SVCR
, SM
);
11026 DP_TBFLAG_A64(flags
, SMEEXC_EL
, sme_el
);
11028 /* Similarly, do not compute SVL if SME is disabled. */
11029 int svl
= sve_vqm1_for_el_sm(env
, el
, true);
11030 DP_TBFLAG_A64(flags
, SVL
, svl
);
11032 /* If SVE is disabled, we will not have set VL above. */
11033 DP_TBFLAG_A64(flags
, VL
, svl
);
11037 DP_TBFLAG_A64(flags
, PSTATE_SM
, 1);
11038 DP_TBFLAG_A64(flags
, SME_TRAP_NONSTREAMING
, !sme_fa64(env
, el
));
11040 DP_TBFLAG_A64(flags
, PSTATE_ZA
, FIELD_EX64(env
->svcr
, SVCR
, ZA
));
11043 sctlr
= regime_sctlr(env
, stage1
);
11045 if (sctlr
& SCTLR_A
) {
11046 DP_TBFLAG_ANY(flags
, ALIGN_MEM
, 1);
11049 if (arm_cpu_data_is_big_endian_a64(el
, sctlr
)) {
11050 DP_TBFLAG_ANY(flags
, BE_DATA
, 1);
11053 if (cpu_isar_feature(aa64_pauth
, env_archcpu(env
))) {
11055 * In order to save space in flags, we record only whether
11056 * pauth is "inactive", meaning all insns are implemented as
11057 * a nop, or "active" when some action must be performed.
11058 * The decision of which action to take is left to a helper.
11060 if (sctlr
& (SCTLR_EnIA
| SCTLR_EnIB
| SCTLR_EnDA
| SCTLR_EnDB
)) {
11061 DP_TBFLAG_A64(flags
, PAUTH_ACTIVE
, 1);
11065 if (cpu_isar_feature(aa64_bti
, env_archcpu(env
))) {
11066 /* Note that SCTLR_EL[23].BT == SCTLR_BT1. */
11067 if (sctlr
& (el
== 0 ? SCTLR_BT0
: SCTLR_BT1
)) {
11068 DP_TBFLAG_A64(flags
, BT
, 1);
11072 /* Compute the condition for using AccType_UNPRIV for LDTR et al. */
11073 if (!(env
->pstate
& PSTATE_UAO
)) {
11075 case ARMMMUIdx_E10_1
:
11076 case ARMMMUIdx_E10_1_PAN
:
11077 case ARMMMUIdx_SE10_1
:
11078 case ARMMMUIdx_SE10_1_PAN
:
11079 /* TODO: ARMv8.3-NV */
11080 DP_TBFLAG_A64(flags
, UNPRIV
, 1);
11082 case ARMMMUIdx_E20_2
:
11083 case ARMMMUIdx_E20_2_PAN
:
11084 case ARMMMUIdx_SE20_2
:
11085 case ARMMMUIdx_SE20_2_PAN
:
11087 * Note that EL20_2 is gated by HCR_EL2.E2H == 1, but EL20_0 is
11088 * gated by HCR_EL2.<E2H,TGE> == '11', and so is LDTR.
11090 if (env
->cp15
.hcr_el2
& HCR_TGE
) {
11091 DP_TBFLAG_A64(flags
, UNPRIV
, 1);
11099 if (env
->pstate
& PSTATE_IL
) {
11100 DP_TBFLAG_ANY(flags
, PSTATE__IL
, 1);
11103 if (cpu_isar_feature(aa64_mte
, env_archcpu(env
))) {
11105 * Set MTE_ACTIVE if any access may be Checked, and leave clear
11106 * if all accesses must be Unchecked:
11107 * 1) If no TBI, then there are no tags in the address to check,
11108 * 2) If Tag Check Override, then all accesses are Unchecked,
11109 * 3) If Tag Check Fail == 0, then Checked access have no effect,
11110 * 4) If no Allocation Tag Access, then all accesses are Unchecked.
11112 if (allocation_tag_access_enabled(env
, el
, sctlr
)) {
11113 DP_TBFLAG_A64(flags
, ATA
, 1);
11115 && !(env
->pstate
& PSTATE_TCO
)
11116 && (sctlr
& (el
== 0 ? SCTLR_TCF0
: SCTLR_TCF
))) {
11117 DP_TBFLAG_A64(flags
, MTE_ACTIVE
, 1);
11120 /* And again for unprivileged accesses, if required. */
11121 if (EX_TBFLAG_A64(flags
, UNPRIV
)
11123 && !(env
->pstate
& PSTATE_TCO
)
11124 && (sctlr
& SCTLR_TCF0
)
11125 && allocation_tag_access_enabled(env
, 0, sctlr
)) {
11126 DP_TBFLAG_A64(flags
, MTE0_ACTIVE
, 1);
11128 /* Cache TCMA as well as TBI. */
11129 DP_TBFLAG_A64(flags
, TCMA
, aa64_va_parameter_tcma(tcr
, mmu_idx
));
11132 return rebuild_hflags_common(env
, fp_el
, mmu_idx
, flags
);
11135 static CPUARMTBFlags
rebuild_hflags_internal(CPUARMState
*env
)
11137 int el
= arm_current_el(env
);
11138 int fp_el
= fp_exception_el(env
, el
);
11139 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
11142 return rebuild_hflags_a64(env
, el
, fp_el
, mmu_idx
);
11143 } else if (arm_feature(env
, ARM_FEATURE_M
)) {
11144 return rebuild_hflags_m32(env
, fp_el
, mmu_idx
);
11146 return rebuild_hflags_a32(env
, fp_el
, mmu_idx
);
11150 void arm_rebuild_hflags(CPUARMState
*env
)
11152 env
->hflags
= rebuild_hflags_internal(env
);
11156 * If we have triggered a EL state change we can't rely on the
11157 * translator having passed it to us, we need to recompute.
11159 void HELPER(rebuild_hflags_m32_newel
)(CPUARMState
*env
)
11161 int el
= arm_current_el(env
);
11162 int fp_el
= fp_exception_el(env
, el
);
11163 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
11165 env
->hflags
= rebuild_hflags_m32(env
, fp_el
, mmu_idx
);
11168 void HELPER(rebuild_hflags_m32
)(CPUARMState
*env
, int el
)
11170 int fp_el
= fp_exception_el(env
, el
);
11171 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
11173 env
->hflags
= rebuild_hflags_m32(env
, fp_el
, mmu_idx
);
11177 * If we have triggered a EL state change we can't rely on the
11178 * translator having passed it to us, we need to recompute.
11180 void HELPER(rebuild_hflags_a32_newel
)(CPUARMState
*env
)
11182 int el
= arm_current_el(env
);
11183 int fp_el
= fp_exception_el(env
, el
);
11184 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
11185 env
->hflags
= rebuild_hflags_a32(env
, fp_el
, mmu_idx
);
11188 void HELPER(rebuild_hflags_a32
)(CPUARMState
*env
, int el
)
11190 int fp_el
= fp_exception_el(env
, el
);
11191 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
11193 env
->hflags
= rebuild_hflags_a32(env
, fp_el
, mmu_idx
);
11196 void HELPER(rebuild_hflags_a64
)(CPUARMState
*env
, int el
)
11198 int fp_el
= fp_exception_el(env
, el
);
11199 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, el
);
11201 env
->hflags
= rebuild_hflags_a64(env
, el
, fp_el
, mmu_idx
);
11204 static inline void assert_hflags_rebuild_correctly(CPUARMState
*env
)
11206 #ifdef CONFIG_DEBUG_TCG
11207 CPUARMTBFlags c
= env
->hflags
;
11208 CPUARMTBFlags r
= rebuild_hflags_internal(env
);
11210 if (unlikely(c
.flags
!= r
.flags
|| c
.flags2
!= r
.flags2
)) {
11211 fprintf(stderr
, "TCG hflags mismatch "
11212 "(current:(0x%08x,0x" TARGET_FMT_lx
")"
11213 " rebuilt:(0x%08x,0x" TARGET_FMT_lx
")\n",
11214 c
.flags
, c
.flags2
, r
.flags
, r
.flags2
);
11220 static bool mve_no_pred(CPUARMState
*env
)
11223 * Return true if there is definitely no predication of MVE
11224 * instructions by VPR or LTPSIZE. (Returning false even if there
11225 * isn't any predication is OK; generated code will just be
11227 * If the CPU does not implement MVE then this TB flag is always 0.
11229 * NOTE: if you change this logic, the "recalculate s->mve_no_pred"
11230 * logic in gen_update_fp_context() needs to be updated to match.
11232 * We do not include the effect of the ECI bits here -- they are
11233 * tracked in other TB flags. This simplifies the logic for
11234 * "when did we emit code that changes the MVE_NO_PRED TB flag
11235 * and thus need to end the TB?".
11237 if (cpu_isar_feature(aa32_mve
, env_archcpu(env
))) {
11240 if (env
->v7m
.vpr
) {
11243 if (env
->v7m
.ltpsize
< 4) {
11249 void cpu_get_tb_cpu_state(CPUARMState
*env
, target_ulong
*pc
,
11250 target_ulong
*cs_base
, uint32_t *pflags
)
11252 CPUARMTBFlags flags
;
11254 assert_hflags_rebuild_correctly(env
);
11255 flags
= env
->hflags
;
11257 if (EX_TBFLAG_ANY(flags
, AARCH64_STATE
)) {
11259 if (cpu_isar_feature(aa64_bti
, env_archcpu(env
))) {
11260 DP_TBFLAG_A64(flags
, BTYPE
, env
->btype
);
11263 *pc
= env
->regs
[15];
11265 if (arm_feature(env
, ARM_FEATURE_M
)) {
11266 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
) &&
11267 FIELD_EX32(env
->v7m
.fpccr
[M_REG_S
], V7M_FPCCR
, S
)
11268 != env
->v7m
.secure
) {
11269 DP_TBFLAG_M32(flags
, FPCCR_S_WRONG
, 1);
11272 if ((env
->v7m
.fpccr
[env
->v7m
.secure
] & R_V7M_FPCCR_ASPEN_MASK
) &&
11273 (!(env
->v7m
.control
[M_REG_S
] & R_V7M_CONTROL_FPCA_MASK
) ||
11274 (env
->v7m
.secure
&&
11275 !(env
->v7m
.control
[M_REG_S
] & R_V7M_CONTROL_SFPA_MASK
)))) {
11277 * ASPEN is set, but FPCA/SFPA indicate that there is no
11278 * active FP context; we must create a new FP context before
11279 * executing any FP insn.
11281 DP_TBFLAG_M32(flags
, NEW_FP_CTXT_NEEDED
, 1);
11284 bool is_secure
= env
->v7m
.fpccr
[M_REG_S
] & R_V7M_FPCCR_S_MASK
;
11285 if (env
->v7m
.fpccr
[is_secure
] & R_V7M_FPCCR_LSPACT_MASK
) {
11286 DP_TBFLAG_M32(flags
, LSPACT
, 1);
11289 if (mve_no_pred(env
)) {
11290 DP_TBFLAG_M32(flags
, MVE_NO_PRED
, 1);
11294 * Note that XSCALE_CPAR shares bits with VECSTRIDE.
11295 * Note that VECLEN+VECSTRIDE are RES0 for M-profile.
11297 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
11298 DP_TBFLAG_A32(flags
, XSCALE_CPAR
, env
->cp15
.c15_cpar
);
11300 DP_TBFLAG_A32(flags
, VECLEN
, env
->vfp
.vec_len
);
11301 DP_TBFLAG_A32(flags
, VECSTRIDE
, env
->vfp
.vec_stride
);
11303 if (env
->vfp
.xregs
[ARM_VFP_FPEXC
] & (1 << 30)) {
11304 DP_TBFLAG_A32(flags
, VFPEN
, 1);
11308 DP_TBFLAG_AM32(flags
, THUMB
, env
->thumb
);
11309 DP_TBFLAG_AM32(flags
, CONDEXEC
, env
->condexec_bits
);
11313 * The SS_ACTIVE and PSTATE_SS bits correspond to the state machine
11314 * states defined in the ARM ARM for software singlestep:
11315 * SS_ACTIVE PSTATE.SS State
11316 * 0 x Inactive (the TB flag for SS is always 0)
11317 * 1 0 Active-pending
11318 * 1 1 Active-not-pending
11319 * SS_ACTIVE is set in hflags; PSTATE__SS is computed every TB.
11321 if (EX_TBFLAG_ANY(flags
, SS_ACTIVE
) && (env
->pstate
& PSTATE_SS
)) {
11322 DP_TBFLAG_ANY(flags
, PSTATE__SS
, 1);
11325 *pflags
= flags
.flags
;
11326 *cs_base
= flags
.flags2
;
11329 #ifdef TARGET_AARCH64
11331 * The manual says that when SVE is enabled and VQ is widened the
11332 * implementation is allowed to zero the previously inaccessible
11333 * portion of the registers. The corollary to that is that when
11334 * SVE is enabled and VQ is narrowed we are also allowed to zero
11335 * the now inaccessible portion of the registers.
11337 * The intent of this is that no predicate bit beyond VQ is ever set.
11338 * Which means that some operations on predicate registers themselves
11339 * may operate on full uint64_t or even unrolled across the maximum
11340 * uint64_t[4]. Performing 4 bits of host arithmetic unconditionally
11341 * may well be cheaper than conditionals to restrict the operation
11342 * to the relevant portion of a uint16_t[16].
11344 void aarch64_sve_narrow_vq(CPUARMState
*env
, unsigned vq
)
11349 assert(vq
>= 1 && vq
<= ARM_MAX_VQ
);
11350 assert(vq
<= env_archcpu(env
)->sve_max_vq
);
11352 /* Zap the high bits of the zregs. */
11353 for (i
= 0; i
< 32; i
++) {
11354 memset(&env
->vfp
.zregs
[i
].d
[2 * vq
], 0, 16 * (ARM_MAX_VQ
- vq
));
11357 /* Zap the high bits of the pregs and ffr. */
11360 pmask
= ~(-1ULL << (16 * (vq
& 3)));
11362 for (j
= vq
/ 4; j
< ARM_MAX_VQ
/ 4; j
++) {
11363 for (i
= 0; i
< 17; ++i
) {
11364 env
->vfp
.pregs
[i
].p
[j
] &= pmask
;
11370 static uint32_t sve_vqm1_for_el_sm_ena(CPUARMState
*env
, int el
, bool sm
)
11375 exc_el
= sme_exception_el(env
, el
);
11377 exc_el
= sve_exception_el(env
, el
);
11380 return 0; /* disabled */
11382 return sve_vqm1_for_el_sm(env
, el
, sm
);
11386 * Notice a change in SVE vector size when changing EL.
11388 void aarch64_sve_change_el(CPUARMState
*env
, int old_el
,
11389 int new_el
, bool el0_a64
)
11391 ARMCPU
*cpu
= env_archcpu(env
);
11392 int old_len
, new_len
;
11393 bool old_a64
, new_a64
, sm
;
11395 /* Nothing to do if no SVE. */
11396 if (!cpu_isar_feature(aa64_sve
, cpu
)) {
11400 /* Nothing to do if FP is disabled in either EL. */
11401 if (fp_exception_el(env
, old_el
) || fp_exception_el(env
, new_el
)) {
11405 old_a64
= old_el
? arm_el_is_aa64(env
, old_el
) : el0_a64
;
11406 new_a64
= new_el
? arm_el_is_aa64(env
, new_el
) : el0_a64
;
11409 * Both AArch64.TakeException and AArch64.ExceptionReturn
11410 * invoke ResetSVEState when taking an exception from, or
11411 * returning to, AArch32 state when PSTATE.SM is enabled.
11413 sm
= FIELD_EX64(env
->svcr
, SVCR
, SM
);
11414 if (old_a64
!= new_a64
&& sm
) {
11415 arm_reset_sve_state(env
);
11420 * DDI0584A.d sec 3.2: "If SVE instructions are disabled or trapped
11421 * at ELx, or not available because the EL is in AArch32 state, then
11422 * for all purposes other than a direct read, the ZCR_ELx.LEN field
11423 * has an effective value of 0".
11425 * Consider EL2 (aa64, vq=4) -> EL0 (aa32) -> EL1 (aa64, vq=0).
11426 * If we ignore aa32 state, we would fail to see the vq4->vq0 transition
11427 * from EL2->EL1. Thus we go ahead and narrow when entering aa32 so that
11428 * we already have the correct register contents when encountering the
11429 * vq0->vq0 transition between EL0->EL1.
11431 old_len
= new_len
= 0;
11433 old_len
= sve_vqm1_for_el_sm_ena(env
, old_el
, sm
);
11436 new_len
= sve_vqm1_for_el_sm_ena(env
, new_el
, sm
);
11439 /* When changing vector length, clear inaccessible state. */
11440 if (new_len
< old_len
) {
11441 aarch64_sve_narrow_vq(env
, new_len
+ 1);