4 * This code is licensed under the GNU GPL v2 or later.
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "qemu/osdep.h"
13 #include "internals.h"
14 #include "exec/helper-proto.h"
15 #include "qemu/main-loop.h"
16 #include "qemu/timer.h"
17 #include "qemu/bitops.h"
18 #include "qemu/crc32c.h"
19 #include "qemu/qemu-print.h"
20 #include "exec/exec-all.h"
21 #include <zlib.h> /* For crc32 */
23 #include "sysemu/cpu-timers.h"
24 #include "sysemu/kvm.h"
25 #include "sysemu/tcg.h"
26 #include "qapi/error.h"
27 #include "qemu/guest-random.h"
29 #include "semihosting/common-semi.h"
33 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */
35 static void switch_mode(CPUARMState
*env
, int mode
);
37 static uint64_t raw_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
39 assert(ri
->fieldoffset
);
40 if (cpreg_field_is_64bit(ri
)) {
41 return CPREG_FIELD64(env
, ri
);
43 return CPREG_FIELD32(env
, ri
);
47 void raw_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
49 assert(ri
->fieldoffset
);
50 if (cpreg_field_is_64bit(ri
)) {
51 CPREG_FIELD64(env
, ri
) = value
;
53 CPREG_FIELD32(env
, ri
) = value
;
57 static void *raw_ptr(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
59 return (char *)env
+ ri
->fieldoffset
;
62 uint64_t read_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
64 /* Raw read of a coprocessor register (as needed for migration, etc). */
65 if (ri
->type
& ARM_CP_CONST
) {
66 return ri
->resetvalue
;
67 } else if (ri
->raw_readfn
) {
68 return ri
->raw_readfn(env
, ri
);
69 } else if (ri
->readfn
) {
70 return ri
->readfn(env
, ri
);
72 return raw_read(env
, ri
);
76 static void write_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
80 * Raw write of a coprocessor register (as needed for migration, etc).
81 * Note that constant registers are treated as write-ignored; the
82 * caller should check for success by whether a readback gives the
85 if (ri
->type
& ARM_CP_CONST
) {
87 } else if (ri
->raw_writefn
) {
88 ri
->raw_writefn(env
, ri
, v
);
89 } else if (ri
->writefn
) {
90 ri
->writefn(env
, ri
, v
);
92 raw_write(env
, ri
, v
);
96 static bool raw_accessors_invalid(const ARMCPRegInfo
*ri
)
99 * Return true if the regdef would cause an assertion if you called
100 * read_raw_cp_reg() or write_raw_cp_reg() on it (ie if it is a
101 * program bug for it not to have the NO_RAW flag).
102 * NB that returning false here doesn't necessarily mean that calling
103 * read/write_raw_cp_reg() is safe, because we can't distinguish "has
104 * read/write access functions which are safe for raw use" from "has
105 * read/write access functions which have side effects but has forgotten
106 * to provide raw access functions".
107 * The tests here line up with the conditions in read/write_raw_cp_reg()
108 * and assertions in raw_read()/raw_write().
110 if ((ri
->type
& ARM_CP_CONST
) ||
112 ((ri
->raw_writefn
|| ri
->writefn
) && (ri
->raw_readfn
|| ri
->readfn
))) {
118 bool write_cpustate_to_list(ARMCPU
*cpu
, bool kvm_sync
)
120 /* Write the coprocessor state from cpu->env to the (index,value) list. */
124 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
125 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
126 const ARMCPRegInfo
*ri
;
129 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
134 if (ri
->type
& ARM_CP_NO_RAW
) {
138 newval
= read_raw_cp_reg(&cpu
->env
, ri
);
141 * Only sync if the previous list->cpustate sync succeeded.
142 * Rather than tracking the success/failure state for every
143 * item in the list, we just recheck "does the raw write we must
144 * have made in write_list_to_cpustate() read back OK" here.
146 uint64_t oldval
= cpu
->cpreg_values
[i
];
148 if (oldval
== newval
) {
152 write_raw_cp_reg(&cpu
->env
, ri
, oldval
);
153 if (read_raw_cp_reg(&cpu
->env
, ri
) != oldval
) {
157 write_raw_cp_reg(&cpu
->env
, ri
, newval
);
159 cpu
->cpreg_values
[i
] = newval
;
164 bool write_list_to_cpustate(ARMCPU
*cpu
)
169 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
170 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
171 uint64_t v
= cpu
->cpreg_values
[i
];
172 const ARMCPRegInfo
*ri
;
174 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
179 if (ri
->type
& ARM_CP_NO_RAW
) {
183 * Write value and confirm it reads back as written
184 * (to catch read-only registers and partially read-only
185 * registers where the incoming migration value doesn't match)
187 write_raw_cp_reg(&cpu
->env
, ri
, v
);
188 if (read_raw_cp_reg(&cpu
->env
, ri
) != v
) {
195 static void add_cpreg_to_list(gpointer key
, gpointer opaque
)
197 ARMCPU
*cpu
= opaque
;
198 uint32_t regidx
= (uintptr_t)key
;
199 const ARMCPRegInfo
*ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
201 if (!(ri
->type
& (ARM_CP_NO_RAW
| ARM_CP_ALIAS
))) {
202 cpu
->cpreg_indexes
[cpu
->cpreg_array_len
] = cpreg_to_kvm_id(regidx
);
203 /* The value array need not be initialized at this point */
204 cpu
->cpreg_array_len
++;
208 static void count_cpreg(gpointer key
, gpointer opaque
)
210 ARMCPU
*cpu
= opaque
;
211 const ARMCPRegInfo
*ri
;
213 ri
= g_hash_table_lookup(cpu
->cp_regs
, key
);
215 if (!(ri
->type
& (ARM_CP_NO_RAW
| ARM_CP_ALIAS
))) {
216 cpu
->cpreg_array_len
++;
220 static gint
cpreg_key_compare(gconstpointer a
, gconstpointer b
)
222 uint64_t aidx
= cpreg_to_kvm_id((uintptr_t)a
);
223 uint64_t bidx
= cpreg_to_kvm_id((uintptr_t)b
);
234 void init_cpreg_list(ARMCPU
*cpu
)
237 * Initialise the cpreg_tuples[] array based on the cp_regs hash.
238 * Note that we require cpreg_tuples[] to be sorted by key ID.
243 keys
= g_hash_table_get_keys(cpu
->cp_regs
);
244 keys
= g_list_sort(keys
, cpreg_key_compare
);
246 cpu
->cpreg_array_len
= 0;
248 g_list_foreach(keys
, count_cpreg
, cpu
);
250 arraylen
= cpu
->cpreg_array_len
;
251 cpu
->cpreg_indexes
= g_new(uint64_t, arraylen
);
252 cpu
->cpreg_values
= g_new(uint64_t, arraylen
);
253 cpu
->cpreg_vmstate_indexes
= g_new(uint64_t, arraylen
);
254 cpu
->cpreg_vmstate_values
= g_new(uint64_t, arraylen
);
255 cpu
->cpreg_vmstate_array_len
= cpu
->cpreg_array_len
;
256 cpu
->cpreg_array_len
= 0;
258 g_list_foreach(keys
, add_cpreg_to_list
, cpu
);
260 assert(cpu
->cpreg_array_len
== arraylen
);
266 * Some registers are not accessible from AArch32 EL3 if SCR.NS == 0.
268 static CPAccessResult
access_el3_aa32ns(CPUARMState
*env
,
269 const ARMCPRegInfo
*ri
,
272 if (!is_a64(env
) && arm_current_el(env
) == 3 &&
273 arm_is_secure_below_el3(env
)) {
274 return CP_ACCESS_TRAP_UNCATEGORIZED
;
280 * Some secure-only AArch32 registers trap to EL3 if used from
281 * Secure EL1 (but are just ordinary UNDEF in other non-EL3 contexts).
282 * Note that an access from Secure EL1 can only happen if EL3 is AArch64.
283 * We assume that the .access field is set to PL1_RW.
285 static CPAccessResult
access_trap_aa32s_el1(CPUARMState
*env
,
286 const ARMCPRegInfo
*ri
,
289 if (arm_current_el(env
) == 3) {
292 if (arm_is_secure_below_el3(env
)) {
293 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
294 return CP_ACCESS_TRAP_EL2
;
296 return CP_ACCESS_TRAP_EL3
;
298 /* This will be EL1 NS and EL2 NS, which just UNDEF */
299 return CP_ACCESS_TRAP_UNCATEGORIZED
;
303 * Check for traps to performance monitor registers, which are controlled
304 * by MDCR_EL2.TPM for EL2 and MDCR_EL3.TPM for EL3.
306 static CPAccessResult
access_tpm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
309 int el
= arm_current_el(env
);
310 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
312 if (el
< 2 && (mdcr_el2
& MDCR_TPM
)) {
313 return CP_ACCESS_TRAP_EL2
;
315 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
316 return CP_ACCESS_TRAP_EL3
;
321 /* Check for traps from EL1 due to HCR_EL2.TVM and HCR_EL2.TRVM. */
322 static CPAccessResult
access_tvm_trvm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
325 if (arm_current_el(env
) == 1) {
326 uint64_t trap
= isread
? HCR_TRVM
: HCR_TVM
;
327 if (arm_hcr_el2_eff(env
) & trap
) {
328 return CP_ACCESS_TRAP_EL2
;
334 /* Check for traps from EL1 due to HCR_EL2.TSW. */
335 static CPAccessResult
access_tsw(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
338 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TSW
)) {
339 return CP_ACCESS_TRAP_EL2
;
344 /* Check for traps from EL1 due to HCR_EL2.TACR. */
345 static CPAccessResult
access_tacr(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
348 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TACR
)) {
349 return CP_ACCESS_TRAP_EL2
;
354 /* Check for traps from EL1 due to HCR_EL2.TTLB. */
355 static CPAccessResult
access_ttlb(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
358 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TTLB
)) {
359 return CP_ACCESS_TRAP_EL2
;
364 /* Check for traps from EL1 due to HCR_EL2.TTLB or TTLBIS. */
365 static CPAccessResult
access_ttlbis(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
368 if (arm_current_el(env
) == 1 &&
369 (arm_hcr_el2_eff(env
) & (HCR_TTLB
| HCR_TTLBIS
))) {
370 return CP_ACCESS_TRAP_EL2
;
375 #ifdef TARGET_AARCH64
376 /* Check for traps from EL1 due to HCR_EL2.TTLB or TTLBOS. */
377 static CPAccessResult
access_ttlbos(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
380 if (arm_current_el(env
) == 1 &&
381 (arm_hcr_el2_eff(env
) & (HCR_TTLB
| HCR_TTLBOS
))) {
382 return CP_ACCESS_TRAP_EL2
;
388 static void dacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
390 ARMCPU
*cpu
= env_archcpu(env
);
392 raw_write(env
, ri
, value
);
393 tlb_flush(CPU(cpu
)); /* Flush TLB as domain not tracked in TLB */
396 static void fcse_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
398 ARMCPU
*cpu
= env_archcpu(env
);
400 if (raw_read(env
, ri
) != value
) {
402 * Unlike real hardware the qemu TLB uses virtual addresses,
403 * not modified virtual addresses, so this causes a TLB flush.
406 raw_write(env
, ri
, value
);
410 static void contextidr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
413 ARMCPU
*cpu
= env_archcpu(env
);
415 if (raw_read(env
, ri
) != value
&& !arm_feature(env
, ARM_FEATURE_PMSA
)
416 && !extended_addresses_enabled(env
)) {
418 * For VMSA (when not using the LPAE long descriptor page table
419 * format) this register includes the ASID, so do a TLB flush.
420 * For PMSA it is purely a process ID and no action is needed.
424 raw_write(env
, ri
, value
);
427 static int alle1_tlbmask(CPUARMState
*env
)
430 * Note that the 'ALL' scope must invalidate both stage 1 and
431 * stage 2 translations, whereas most other scopes only invalidate
432 * stage 1 translations.
434 return (ARMMMUIdxBit_E10_1
|
435 ARMMMUIdxBit_E10_1_PAN
|
437 ARMMMUIdxBit_Stage2
|
438 ARMMMUIdxBit_Stage2_S
);
442 /* IS variants of TLB operations must affect all cores */
443 static void tlbiall_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
446 CPUState
*cs
= env_cpu(env
);
448 tlb_flush_all_cpus_synced(cs
);
451 static void tlbiasid_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
454 CPUState
*cs
= env_cpu(env
);
456 tlb_flush_all_cpus_synced(cs
);
459 static void tlbimva_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
462 CPUState
*cs
= env_cpu(env
);
464 tlb_flush_page_all_cpus_synced(cs
, value
& TARGET_PAGE_MASK
);
467 static void tlbimvaa_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
470 CPUState
*cs
= env_cpu(env
);
472 tlb_flush_page_all_cpus_synced(cs
, value
& TARGET_PAGE_MASK
);
476 * Non-IS variants of TLB operations are upgraded to
477 * IS versions if we are at EL1 and HCR_EL2.FB is effectively set to
478 * force broadcast of these operations.
480 static bool tlb_force_broadcast(CPUARMState
*env
)
482 return arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_FB
);
485 static void tlbiall_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
488 /* Invalidate all (TLBIALL) */
489 CPUState
*cs
= env_cpu(env
);
491 if (tlb_force_broadcast(env
)) {
492 tlb_flush_all_cpus_synced(cs
);
498 static void tlbimva_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
501 /* Invalidate single TLB entry by MVA and ASID (TLBIMVA) */
502 CPUState
*cs
= env_cpu(env
);
504 value
&= TARGET_PAGE_MASK
;
505 if (tlb_force_broadcast(env
)) {
506 tlb_flush_page_all_cpus_synced(cs
, value
);
508 tlb_flush_page(cs
, value
);
512 static void tlbiasid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
515 /* Invalidate by ASID (TLBIASID) */
516 CPUState
*cs
= env_cpu(env
);
518 if (tlb_force_broadcast(env
)) {
519 tlb_flush_all_cpus_synced(cs
);
525 static void tlbimvaa_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
528 /* Invalidate single entry by MVA, all ASIDs (TLBIMVAA) */
529 CPUState
*cs
= env_cpu(env
);
531 value
&= TARGET_PAGE_MASK
;
532 if (tlb_force_broadcast(env
)) {
533 tlb_flush_page_all_cpus_synced(cs
, value
);
535 tlb_flush_page(cs
, value
);
539 static void tlbiall_nsnh_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
542 CPUState
*cs
= env_cpu(env
);
544 tlb_flush_by_mmuidx(cs
, alle1_tlbmask(env
));
547 static void tlbiall_nsnh_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
550 CPUState
*cs
= env_cpu(env
);
552 tlb_flush_by_mmuidx_all_cpus_synced(cs
, alle1_tlbmask(env
));
556 static void tlbiall_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
559 CPUState
*cs
= env_cpu(env
);
561 tlb_flush_by_mmuidx(cs
, ARMMMUIdxBit_E2
);
564 static void tlbiall_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
567 CPUState
*cs
= env_cpu(env
);
569 tlb_flush_by_mmuidx_all_cpus_synced(cs
, ARMMMUIdxBit_E2
);
572 static void tlbimva_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
575 CPUState
*cs
= env_cpu(env
);
576 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
578 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_E2
);
581 static void tlbimva_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
584 CPUState
*cs
= env_cpu(env
);
585 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
587 tlb_flush_page_by_mmuidx_all_cpus_synced(cs
, pageaddr
,
591 static void tlbiipas2_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
594 CPUState
*cs
= env_cpu(env
);
595 uint64_t pageaddr
= (value
& MAKE_64BIT_MASK(0, 28)) << 12;
597 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_Stage2
);
600 static void tlbiipas2is_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
603 CPUState
*cs
= env_cpu(env
);
604 uint64_t pageaddr
= (value
& MAKE_64BIT_MASK(0, 28)) << 12;
606 tlb_flush_page_by_mmuidx_all_cpus_synced(cs
, pageaddr
, ARMMMUIdxBit_Stage2
);
609 static const ARMCPRegInfo cp_reginfo
[] = {
611 * Define the secure and non-secure FCSE identifier CP registers
612 * separately because there is no secure bank in V8 (no _EL3). This allows
613 * the secure register to be properly reset and migrated. There is also no
614 * v8 EL1 version of the register so the non-secure instance stands alone.
617 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
618 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_NS
,
619 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_ns
),
620 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
621 { .name
= "FCSEIDR_S",
622 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
623 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_S
,
624 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_s
),
625 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
627 * Define the secure and non-secure context identifier CP registers
628 * separately because there is no secure bank in V8 (no _EL3). This allows
629 * the secure register to be properly reset and migrated. In the
630 * non-secure case, the 32-bit register will have reset and migration
631 * disabled during registration as it is handled by the 64-bit instance.
633 { .name
= "CONTEXTIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
634 .opc0
= 3, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
635 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
636 .fgt
= FGT_CONTEXTIDR_EL1
,
637 .secure
= ARM_CP_SECSTATE_NS
,
638 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[1]),
639 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
640 { .name
= "CONTEXTIDR_S", .state
= ARM_CP_STATE_AA32
,
641 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
642 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
643 .secure
= ARM_CP_SECSTATE_S
,
644 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_s
),
645 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
648 static const ARMCPRegInfo not_v8_cp_reginfo
[] = {
650 * NB: Some of these registers exist in v8 but with more precise
651 * definitions that don't use CP_ANY wildcards (mostly in v8_cp_reginfo[]).
653 /* MMU Domain access control / MPU write buffer control */
655 .cp
= 15, .opc1
= CP_ANY
, .crn
= 3, .crm
= CP_ANY
, .opc2
= CP_ANY
,
656 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
657 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
658 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
659 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
661 * ARMv7 allocates a range of implementation defined TLB LOCKDOWN regs.
662 * For v6 and v5, these mappings are overly broad.
664 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 0,
665 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
666 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 1,
667 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
668 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 4,
669 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
670 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 8,
671 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
672 /* Cache maintenance ops; some of this space may be overridden later. */
673 { .name
= "CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
674 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
675 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
},
678 static const ARMCPRegInfo not_v6_cp_reginfo
[] = {
680 * Not all pre-v6 cores implemented this WFI, so this is slightly
683 { .name
= "WFI_v5", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= 2,
684 .access
= PL1_W
, .type
= ARM_CP_WFI
},
687 static const ARMCPRegInfo not_v7_cp_reginfo
[] = {
689 * Standard v6 WFI (also used in some pre-v6 cores); not in v7 (which
690 * is UNPREDICTABLE; we choose to NOP as most implementations do).
692 { .name
= "WFI_v6", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
693 .access
= PL1_W
, .type
= ARM_CP_WFI
},
695 * L1 cache lockdown. Not architectural in v6 and earlier but in practice
696 * implemented in 926, 946, 1026, 1136, 1176 and 11MPCore. StrongARM and
697 * OMAPCP will override this space.
699 { .name
= "DLOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 0,
700 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_data
),
702 { .name
= "ILOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 1,
703 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_insn
),
705 /* v6 doesn't have the cache ID registers but Linux reads them anyway */
706 { .name
= "DUMMY", .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= CP_ANY
,
707 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
710 * We don't implement pre-v7 debug but most CPUs had at least a DBGDIDR;
711 * implementing it as RAZ means the "debug architecture version" bits
712 * will read as a reserved value, which should cause Linux to not try
713 * to use the debug hardware.
715 { .name
= "DBGDIDR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 0,
716 .access
= PL0_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
718 * MMU TLB control. Note that the wildcarding means we cover not just
719 * the unified TLB ops but also the dside/iside/inner-shareable variants.
721 { .name
= "TLBIALL", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
722 .opc1
= CP_ANY
, .opc2
= 0, .access
= PL1_W
, .writefn
= tlbiall_write
,
723 .type
= ARM_CP_NO_RAW
},
724 { .name
= "TLBIMVA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
725 .opc1
= CP_ANY
, .opc2
= 1, .access
= PL1_W
, .writefn
= tlbimva_write
,
726 .type
= ARM_CP_NO_RAW
},
727 { .name
= "TLBIASID", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
728 .opc1
= CP_ANY
, .opc2
= 2, .access
= PL1_W
, .writefn
= tlbiasid_write
,
729 .type
= ARM_CP_NO_RAW
},
730 { .name
= "TLBIMVAA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
731 .opc1
= CP_ANY
, .opc2
= 3, .access
= PL1_W
, .writefn
= tlbimvaa_write
,
732 .type
= ARM_CP_NO_RAW
},
733 { .name
= "PRRR", .cp
= 15, .crn
= 10, .crm
= 2,
734 .opc1
= 0, .opc2
= 0, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
735 { .name
= "NMRR", .cp
= 15, .crn
= 10, .crm
= 2,
736 .opc1
= 0, .opc2
= 1, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
739 static void cpacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
744 /* In ARMv8 most bits of CPACR_EL1 are RES0. */
745 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
747 * ARMv7 defines bits for unimplemented coprocessors as RAZ/WI.
748 * ASEDIS [31] and D32DIS [30] are both UNK/SBZP without VFP.
749 * TRCDIS [28] is RAZ/WI since we do not implement a trace macrocell.
751 if (cpu_isar_feature(aa32_vfp_simd
, env_archcpu(env
))) {
752 /* VFP coprocessor: cp10 & cp11 [23:20] */
753 mask
|= R_CPACR_ASEDIS_MASK
|
754 R_CPACR_D32DIS_MASK
|
758 if (!arm_feature(env
, ARM_FEATURE_NEON
)) {
759 /* ASEDIS [31] bit is RAO/WI */
760 value
|= R_CPACR_ASEDIS_MASK
;
764 * VFPv3 and upwards with NEON implement 32 double precision
765 * registers (D0-D31).
767 if (!cpu_isar_feature(aa32_simd_r32
, env_archcpu(env
))) {
768 /* D32DIS [30] is RAO/WI if D16-31 are not implemented. */
769 value
|= R_CPACR_D32DIS_MASK
;
776 * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10
777 * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00.
779 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
780 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
781 mask
= R_CPACR_CP11_MASK
| R_CPACR_CP10_MASK
;
782 value
= (value
& ~mask
) | (env
->cp15
.cpacr_el1
& mask
);
785 env
->cp15
.cpacr_el1
= value
;
788 static uint64_t cpacr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
791 * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10
792 * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00.
794 uint64_t value
= env
->cp15
.cpacr_el1
;
796 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
797 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
798 value
= ~(R_CPACR_CP11_MASK
| R_CPACR_CP10_MASK
);
804 static void cpacr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
807 * Call cpacr_write() so that we reset with the correct RAO bits set
808 * for our CPU features.
810 cpacr_write(env
, ri
, 0);
813 static CPAccessResult
cpacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
816 if (arm_feature(env
, ARM_FEATURE_V8
)) {
817 /* Check if CPACR accesses are to be trapped to EL2 */
818 if (arm_current_el(env
) == 1 && arm_is_el2_enabled(env
) &&
819 FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TCPAC
)) {
820 return CP_ACCESS_TRAP_EL2
;
821 /* Check if CPACR accesses are to be trapped to EL3 */
822 } else if (arm_current_el(env
) < 3 &&
823 FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TCPAC
)) {
824 return CP_ACCESS_TRAP_EL3
;
831 static CPAccessResult
cptr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
834 /* Check if CPTR accesses are set to trap to EL3 */
835 if (arm_current_el(env
) == 2 &&
836 FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TCPAC
)) {
837 return CP_ACCESS_TRAP_EL3
;
843 static const ARMCPRegInfo v6_cp_reginfo
[] = {
844 /* prefetch by MVA in v6, NOP in v7 */
845 { .name
= "MVA_prefetch",
846 .cp
= 15, .crn
= 7, .crm
= 13, .opc1
= 0, .opc2
= 1,
847 .access
= PL1_W
, .type
= ARM_CP_NOP
},
849 * We need to break the TB after ISB to execute self-modifying code
850 * correctly and also to take any pending interrupts immediately.
851 * So use arm_cp_write_ignore() function instead of ARM_CP_NOP flag.
853 { .name
= "ISB", .cp
= 15, .crn
= 7, .crm
= 5, .opc1
= 0, .opc2
= 4,
854 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
, .writefn
= arm_cp_write_ignore
},
855 { .name
= "DSB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 4,
856 .access
= PL0_W
, .type
= ARM_CP_NOP
},
857 { .name
= "DMB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 5,
858 .access
= PL0_W
, .type
= ARM_CP_NOP
},
859 { .name
= "IFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 2,
860 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
861 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ifar_s
),
862 offsetof(CPUARMState
, cp15
.ifar_ns
) },
865 * Watchpoint Fault Address Register : should actually only be present
866 * for 1136, 1176, 11MPCore.
868 { .name
= "WFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 1,
869 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0, },
870 { .name
= "CPACR", .state
= ARM_CP_STATE_BOTH
, .opc0
= 3,
871 .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 2, .accessfn
= cpacr_access
,
872 .fgt
= FGT_CPACR_EL1
,
873 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.cpacr_el1
),
874 .resetfn
= cpacr_reset
, .writefn
= cpacr_write
, .readfn
= cpacr_read
},
877 typedef struct pm_event
{
878 uint16_t number
; /* PMEVTYPER.evtCount is 16 bits wide */
879 /* If the event is supported on this CPU (used to generate PMCEID[01]) */
880 bool (*supported
)(CPUARMState
*);
882 * Retrieve the current count of the underlying event. The programmed
883 * counters hold a difference from the return value from this function
885 uint64_t (*get_count
)(CPUARMState
*);
887 * Return how many nanoseconds it will take (at a minimum) for count events
888 * to occur. A negative value indicates the counter will never overflow, or
889 * that the counter has otherwise arranged for the overflow bit to be set
890 * and the PMU interrupt to be raised on overflow.
892 int64_t (*ns_per_count
)(uint64_t);
895 static bool event_always_supported(CPUARMState
*env
)
900 static uint64_t swinc_get_count(CPUARMState
*env
)
903 * SW_INCR events are written directly to the pmevcntr's by writes to
904 * PMSWINC, so there is no underlying count maintained by the PMU itself
909 static int64_t swinc_ns_per(uint64_t ignored
)
915 * Return the underlying cycle count for the PMU cycle counters. If we're in
916 * usermode, simply return 0.
918 static uint64_t cycles_get_count(CPUARMState
*env
)
920 #ifndef CONFIG_USER_ONLY
921 return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
922 ARM_CPU_FREQ
, NANOSECONDS_PER_SECOND
);
924 return cpu_get_host_ticks();
928 #ifndef CONFIG_USER_ONLY
929 static int64_t cycles_ns_per(uint64_t cycles
)
931 return (ARM_CPU_FREQ
/ NANOSECONDS_PER_SECOND
) * cycles
;
934 static bool instructions_supported(CPUARMState
*env
)
936 return icount_enabled() == 1; /* Precise instruction counting */
939 static uint64_t instructions_get_count(CPUARMState
*env
)
941 return (uint64_t)icount_get_raw();
944 static int64_t instructions_ns_per(uint64_t icount
)
946 return icount_to_ns((int64_t)icount
);
950 static bool pmuv3p1_events_supported(CPUARMState
*env
)
952 /* For events which are supported in any v8.1 PMU */
953 return cpu_isar_feature(any_pmuv3p1
, env_archcpu(env
));
956 static bool pmuv3p4_events_supported(CPUARMState
*env
)
958 /* For events which are supported in any v8.1 PMU */
959 return cpu_isar_feature(any_pmuv3p4
, env_archcpu(env
));
962 static uint64_t zero_event_get_count(CPUARMState
*env
)
964 /* For events which on QEMU never fire, so their count is always zero */
968 static int64_t zero_event_ns_per(uint64_t cycles
)
970 /* An event which never fires can never overflow */
974 static const pm_event pm_events
[] = {
975 { .number
= 0x000, /* SW_INCR */
976 .supported
= event_always_supported
,
977 .get_count
= swinc_get_count
,
978 .ns_per_count
= swinc_ns_per
,
980 #ifndef CONFIG_USER_ONLY
981 { .number
= 0x008, /* INST_RETIRED, Instruction architecturally executed */
982 .supported
= instructions_supported
,
983 .get_count
= instructions_get_count
,
984 .ns_per_count
= instructions_ns_per
,
986 { .number
= 0x011, /* CPU_CYCLES, Cycle */
987 .supported
= event_always_supported
,
988 .get_count
= cycles_get_count
,
989 .ns_per_count
= cycles_ns_per
,
992 { .number
= 0x023, /* STALL_FRONTEND */
993 .supported
= pmuv3p1_events_supported
,
994 .get_count
= zero_event_get_count
,
995 .ns_per_count
= zero_event_ns_per
,
997 { .number
= 0x024, /* STALL_BACKEND */
998 .supported
= pmuv3p1_events_supported
,
999 .get_count
= zero_event_get_count
,
1000 .ns_per_count
= zero_event_ns_per
,
1002 { .number
= 0x03c, /* STALL */
1003 .supported
= pmuv3p4_events_supported
,
1004 .get_count
= zero_event_get_count
,
1005 .ns_per_count
= zero_event_ns_per
,
1010 * Note: Before increasing MAX_EVENT_ID beyond 0x3f into the 0x40xx range of
1011 * events (i.e. the statistical profiling extension), this implementation
1012 * should first be updated to something sparse instead of the current
1013 * supported_event_map[] array.
1015 #define MAX_EVENT_ID 0x3c
1016 #define UNSUPPORTED_EVENT UINT16_MAX
1017 static uint16_t supported_event_map
[MAX_EVENT_ID
+ 1];
1020 * Called upon CPU initialization to initialize PMCEID[01]_EL0 and build a map
1021 * of ARM event numbers to indices in our pm_events array.
1023 * Note: Events in the 0x40XX range are not currently supported.
1025 void pmu_init(ARMCPU
*cpu
)
1030 * Empty supported_event_map and cpu->pmceid[01] before adding supported
1033 for (i
= 0; i
< ARRAY_SIZE(supported_event_map
); i
++) {
1034 supported_event_map
[i
] = UNSUPPORTED_EVENT
;
1039 for (i
= 0; i
< ARRAY_SIZE(pm_events
); i
++) {
1040 const pm_event
*cnt
= &pm_events
[i
];
1041 assert(cnt
->number
<= MAX_EVENT_ID
);
1042 /* We do not currently support events in the 0x40xx range */
1043 assert(cnt
->number
<= 0x3f);
1045 if (cnt
->supported(&cpu
->env
)) {
1046 supported_event_map
[cnt
->number
] = i
;
1047 uint64_t event_mask
= 1ULL << (cnt
->number
& 0x1f);
1048 if (cnt
->number
& 0x20) {
1049 cpu
->pmceid1
|= event_mask
;
1051 cpu
->pmceid0
|= event_mask
;
1058 * Check at runtime whether a PMU event is supported for the current machine
1060 static bool event_supported(uint16_t number
)
1062 if (number
> MAX_EVENT_ID
) {
1065 return supported_event_map
[number
] != UNSUPPORTED_EVENT
;
1068 static CPAccessResult
pmreg_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1072 * Performance monitor registers user accessibility is controlled
1073 * by PMUSERENR. MDCR_EL2.TPM and MDCR_EL3.TPM allow configurable
1074 * trapping to EL2 or EL3 for other accesses.
1076 int el
= arm_current_el(env
);
1077 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
1079 if (el
== 0 && !(env
->cp15
.c9_pmuserenr
& 1)) {
1080 return CP_ACCESS_TRAP
;
1082 if (el
< 2 && (mdcr_el2
& MDCR_TPM
)) {
1083 return CP_ACCESS_TRAP_EL2
;
1085 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
1086 return CP_ACCESS_TRAP_EL3
;
1089 return CP_ACCESS_OK
;
1092 static CPAccessResult
pmreg_access_xevcntr(CPUARMState
*env
,
1093 const ARMCPRegInfo
*ri
,
1096 /* ER: event counter read trap control */
1097 if (arm_feature(env
, ARM_FEATURE_V8
)
1098 && arm_current_el(env
) == 0
1099 && (env
->cp15
.c9_pmuserenr
& (1 << 3)) != 0
1101 return CP_ACCESS_OK
;
1104 return pmreg_access(env
, ri
, isread
);
1107 static CPAccessResult
pmreg_access_swinc(CPUARMState
*env
,
1108 const ARMCPRegInfo
*ri
,
1111 /* SW: software increment write trap control */
1112 if (arm_feature(env
, ARM_FEATURE_V8
)
1113 && arm_current_el(env
) == 0
1114 && (env
->cp15
.c9_pmuserenr
& (1 << 1)) != 0
1116 return CP_ACCESS_OK
;
1119 return pmreg_access(env
, ri
, isread
);
1122 static CPAccessResult
pmreg_access_selr(CPUARMState
*env
,
1123 const ARMCPRegInfo
*ri
,
1126 /* ER: event counter read trap control */
1127 if (arm_feature(env
, ARM_FEATURE_V8
)
1128 && arm_current_el(env
) == 0
1129 && (env
->cp15
.c9_pmuserenr
& (1 << 3)) != 0) {
1130 return CP_ACCESS_OK
;
1133 return pmreg_access(env
, ri
, isread
);
1136 static CPAccessResult
pmreg_access_ccntr(CPUARMState
*env
,
1137 const ARMCPRegInfo
*ri
,
1140 /* CR: cycle counter read trap control */
1141 if (arm_feature(env
, ARM_FEATURE_V8
)
1142 && arm_current_el(env
) == 0
1143 && (env
->cp15
.c9_pmuserenr
& (1 << 2)) != 0
1145 return CP_ACCESS_OK
;
1148 return pmreg_access(env
, ri
, isread
);
1152 * Bits in MDCR_EL2 and MDCR_EL3 which pmu_counter_enabled() looks at.
1153 * We use these to decide whether we need to wrap a write to MDCR_EL2
1154 * or MDCR_EL3 in pmu_op_start()/pmu_op_finish() calls.
1156 #define MDCR_EL2_PMU_ENABLE_BITS \
1157 (MDCR_HPME | MDCR_HPMD | MDCR_HPMN | MDCR_HCCD | MDCR_HLP)
1158 #define MDCR_EL3_PMU_ENABLE_BITS (MDCR_SPME | MDCR_SCCD)
1161 * Returns true if the counter (pass 31 for PMCCNTR) should count events using
1162 * the current EL, security state, and register configuration.
1164 static bool pmu_counter_enabled(CPUARMState
*env
, uint8_t counter
)
1167 bool e
, p
, u
, nsk
, nsu
, nsh
, m
;
1168 bool enabled
, prohibited
= false, filtered
;
1169 bool secure
= arm_is_secure(env
);
1170 int el
= arm_current_el(env
);
1171 uint64_t mdcr_el2
= arm_mdcr_el2_eff(env
);
1172 uint8_t hpmn
= mdcr_el2
& MDCR_HPMN
;
1174 if (!arm_feature(env
, ARM_FEATURE_PMU
)) {
1178 if (!arm_feature(env
, ARM_FEATURE_EL2
) ||
1179 (counter
< hpmn
|| counter
== 31)) {
1180 e
= env
->cp15
.c9_pmcr
& PMCRE
;
1182 e
= mdcr_el2
& MDCR_HPME
;
1184 enabled
= e
&& (env
->cp15
.c9_pmcnten
& (1 << counter
));
1186 /* Is event counting prohibited? */
1187 if (el
== 2 && (counter
< hpmn
|| counter
== 31)) {
1188 prohibited
= mdcr_el2
& MDCR_HPMD
;
1191 prohibited
= prohibited
|| !(env
->cp15
.mdcr_el3
& MDCR_SPME
);
1194 if (counter
== 31) {
1196 * The cycle counter defaults to running. PMCR.DP says "disable
1197 * the cycle counter when event counting is prohibited".
1198 * Some MDCR bits disable the cycle counter specifically.
1200 prohibited
= prohibited
&& env
->cp15
.c9_pmcr
& PMCRDP
;
1201 if (cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1203 prohibited
= prohibited
|| (env
->cp15
.mdcr_el3
& MDCR_SCCD
);
1206 prohibited
= prohibited
|| (mdcr_el2
& MDCR_HCCD
);
1211 if (counter
== 31) {
1212 filter
= env
->cp15
.pmccfiltr_el0
;
1214 filter
= env
->cp15
.c14_pmevtyper
[counter
];
1217 p
= filter
& PMXEVTYPER_P
;
1218 u
= filter
& PMXEVTYPER_U
;
1219 nsk
= arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_NSK
);
1220 nsu
= arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_NSU
);
1221 nsh
= arm_feature(env
, ARM_FEATURE_EL2
) && (filter
& PMXEVTYPER_NSH
);
1222 m
= arm_el_is_aa64(env
, 1) &&
1223 arm_feature(env
, ARM_FEATURE_EL3
) && (filter
& PMXEVTYPER_M
);
1226 filtered
= secure
? u
: u
!= nsu
;
1227 } else if (el
== 1) {
1228 filtered
= secure
? p
: p
!= nsk
;
1229 } else if (el
== 2) {
1235 if (counter
!= 31) {
1237 * If not checking PMCCNTR, ensure the counter is setup to an event we
1240 uint16_t event
= filter
& PMXEVTYPER_EVTCOUNT
;
1241 if (!event_supported(event
)) {
1246 return enabled
&& !prohibited
&& !filtered
;
1249 static void pmu_update_irq(CPUARMState
*env
)
1251 ARMCPU
*cpu
= env_archcpu(env
);
1252 qemu_set_irq(cpu
->pmu_interrupt
, (env
->cp15
.c9_pmcr
& PMCRE
) &&
1253 (env
->cp15
.c9_pminten
& env
->cp15
.c9_pmovsr
));
1256 static bool pmccntr_clockdiv_enabled(CPUARMState
*env
)
1259 * Return true if the clock divider is enabled and the cycle counter
1260 * is supposed to tick only once every 64 clock cycles. This is
1261 * controlled by PMCR.D, but if PMCR.LC is set to enable the long
1262 * (64-bit) cycle counter PMCR.D has no effect.
1264 return (env
->cp15
.c9_pmcr
& (PMCRD
| PMCRLC
)) == PMCRD
;
1267 static bool pmevcntr_is_64_bit(CPUARMState
*env
, int counter
)
1269 /* Return true if the specified event counter is configured to be 64 bit */
1271 /* This isn't intended to be used with the cycle counter */
1272 assert(counter
< 31);
1274 if (!cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1278 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
1280 * MDCR_EL2.HLP still applies even when EL2 is disabled in the
1281 * current security state, so we don't use arm_mdcr_el2_eff() here.
1283 bool hlp
= env
->cp15
.mdcr_el2
& MDCR_HLP
;
1284 int hpmn
= env
->cp15
.mdcr_el2
& MDCR_HPMN
;
1286 if (hpmn
!= 0 && counter
>= hpmn
) {
1290 return env
->cp15
.c9_pmcr
& PMCRLP
;
1294 * Ensure c15_ccnt is the guest-visible count so that operations such as
1295 * enabling/disabling the counter or filtering, modifying the count itself,
1296 * etc. can be done logically. This is essentially a no-op if the counter is
1297 * not enabled at the time of the call.
1299 static void pmccntr_op_start(CPUARMState
*env
)
1301 uint64_t cycles
= cycles_get_count(env
);
1303 if (pmu_counter_enabled(env
, 31)) {
1304 uint64_t eff_cycles
= cycles
;
1305 if (pmccntr_clockdiv_enabled(env
)) {
1309 uint64_t new_pmccntr
= eff_cycles
- env
->cp15
.c15_ccnt_delta
;
1311 uint64_t overflow_mask
= env
->cp15
.c9_pmcr
& PMCRLC
? \
1312 1ull << 63 : 1ull << 31;
1313 if (env
->cp15
.c15_ccnt
& ~new_pmccntr
& overflow_mask
) {
1314 env
->cp15
.c9_pmovsr
|= (1ULL << 31);
1315 pmu_update_irq(env
);
1318 env
->cp15
.c15_ccnt
= new_pmccntr
;
1320 env
->cp15
.c15_ccnt_delta
= cycles
;
1324 * If PMCCNTR is enabled, recalculate the delta between the clock and the
1325 * guest-visible count. A call to pmccntr_op_finish should follow every call to
1328 static void pmccntr_op_finish(CPUARMState
*env
)
1330 if (pmu_counter_enabled(env
, 31)) {
1331 #ifndef CONFIG_USER_ONLY
1332 /* Calculate when the counter will next overflow */
1333 uint64_t remaining_cycles
= -env
->cp15
.c15_ccnt
;
1334 if (!(env
->cp15
.c9_pmcr
& PMCRLC
)) {
1335 remaining_cycles
= (uint32_t)remaining_cycles
;
1337 int64_t overflow_in
= cycles_ns_per(remaining_cycles
);
1339 if (overflow_in
> 0) {
1340 int64_t overflow_at
;
1342 if (!sadd64_overflow(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
1343 overflow_in
, &overflow_at
)) {
1344 ARMCPU
*cpu
= env_archcpu(env
);
1345 timer_mod_anticipate_ns(cpu
->pmu_timer
, overflow_at
);
1350 uint64_t prev_cycles
= env
->cp15
.c15_ccnt_delta
;
1351 if (pmccntr_clockdiv_enabled(env
)) {
1354 env
->cp15
.c15_ccnt_delta
= prev_cycles
- env
->cp15
.c15_ccnt
;
1358 static void pmevcntr_op_start(CPUARMState
*env
, uint8_t counter
)
1361 uint16_t event
= env
->cp15
.c14_pmevtyper
[counter
] & PMXEVTYPER_EVTCOUNT
;
1363 if (event_supported(event
)) {
1364 uint16_t event_idx
= supported_event_map
[event
];
1365 count
= pm_events
[event_idx
].get_count(env
);
1368 if (pmu_counter_enabled(env
, counter
)) {
1369 uint64_t new_pmevcntr
= count
- env
->cp15
.c14_pmevcntr_delta
[counter
];
1370 uint64_t overflow_mask
= pmevcntr_is_64_bit(env
, counter
) ?
1371 1ULL << 63 : 1ULL << 31;
1373 if (env
->cp15
.c14_pmevcntr
[counter
] & ~new_pmevcntr
& overflow_mask
) {
1374 env
->cp15
.c9_pmovsr
|= (1 << counter
);
1375 pmu_update_irq(env
);
1377 env
->cp15
.c14_pmevcntr
[counter
] = new_pmevcntr
;
1379 env
->cp15
.c14_pmevcntr_delta
[counter
] = count
;
1382 static void pmevcntr_op_finish(CPUARMState
*env
, uint8_t counter
)
1384 if (pmu_counter_enabled(env
, counter
)) {
1385 #ifndef CONFIG_USER_ONLY
1386 uint16_t event
= env
->cp15
.c14_pmevtyper
[counter
] & PMXEVTYPER_EVTCOUNT
;
1387 uint16_t event_idx
= supported_event_map
[event
];
1388 uint64_t delta
= -(env
->cp15
.c14_pmevcntr
[counter
] + 1);
1389 int64_t overflow_in
;
1391 if (!pmevcntr_is_64_bit(env
, counter
)) {
1392 delta
= (uint32_t)delta
;
1394 overflow_in
= pm_events
[event_idx
].ns_per_count(delta
);
1396 if (overflow_in
> 0) {
1397 int64_t overflow_at
;
1399 if (!sadd64_overflow(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
1400 overflow_in
, &overflow_at
)) {
1401 ARMCPU
*cpu
= env_archcpu(env
);
1402 timer_mod_anticipate_ns(cpu
->pmu_timer
, overflow_at
);
1407 env
->cp15
.c14_pmevcntr_delta
[counter
] -=
1408 env
->cp15
.c14_pmevcntr
[counter
];
1412 void pmu_op_start(CPUARMState
*env
)
1415 pmccntr_op_start(env
);
1416 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1417 pmevcntr_op_start(env
, i
);
1421 void pmu_op_finish(CPUARMState
*env
)
1424 pmccntr_op_finish(env
);
1425 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1426 pmevcntr_op_finish(env
, i
);
1430 void pmu_pre_el_change(ARMCPU
*cpu
, void *ignored
)
1432 pmu_op_start(&cpu
->env
);
1435 void pmu_post_el_change(ARMCPU
*cpu
, void *ignored
)
1437 pmu_op_finish(&cpu
->env
);
1440 void arm_pmu_timer_cb(void *opaque
)
1442 ARMCPU
*cpu
= opaque
;
1445 * Update all the counter values based on the current underlying counts,
1446 * triggering interrupts to be raised, if necessary. pmu_op_finish() also
1447 * has the effect of setting the cpu->pmu_timer to the next earliest time a
1448 * counter may expire.
1450 pmu_op_start(&cpu
->env
);
1451 pmu_op_finish(&cpu
->env
);
1454 static void pmcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1459 if (value
& PMCRC
) {
1460 /* The counter has been reset */
1461 env
->cp15
.c15_ccnt
= 0;
1464 if (value
& PMCRP
) {
1466 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1467 env
->cp15
.c14_pmevcntr
[i
] = 0;
1471 env
->cp15
.c9_pmcr
&= ~PMCR_WRITABLE_MASK
;
1472 env
->cp15
.c9_pmcr
|= (value
& PMCR_WRITABLE_MASK
);
1477 static void pmswinc_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1481 uint64_t overflow_mask
, new_pmswinc
;
1483 for (i
= 0; i
< pmu_num_counters(env
); i
++) {
1484 /* Increment a counter's count iff: */
1485 if ((value
& (1 << i
)) && /* counter's bit is set */
1486 /* counter is enabled and not filtered */
1487 pmu_counter_enabled(env
, i
) &&
1488 /* counter is SW_INCR */
1489 (env
->cp15
.c14_pmevtyper
[i
] & PMXEVTYPER_EVTCOUNT
) == 0x0) {
1490 pmevcntr_op_start(env
, i
);
1493 * Detect if this write causes an overflow since we can't predict
1494 * PMSWINC overflows like we can for other events
1496 new_pmswinc
= env
->cp15
.c14_pmevcntr
[i
] + 1;
1498 overflow_mask
= pmevcntr_is_64_bit(env
, i
) ?
1499 1ULL << 63 : 1ULL << 31;
1501 if (env
->cp15
.c14_pmevcntr
[i
] & ~new_pmswinc
& overflow_mask
) {
1502 env
->cp15
.c9_pmovsr
|= (1 << i
);
1503 pmu_update_irq(env
);
1506 env
->cp15
.c14_pmevcntr
[i
] = new_pmswinc
;
1508 pmevcntr_op_finish(env
, i
);
1513 static uint64_t pmccntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1516 pmccntr_op_start(env
);
1517 ret
= env
->cp15
.c15_ccnt
;
1518 pmccntr_op_finish(env
);
1522 static void pmselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1526 * The value of PMSELR.SEL affects the behavior of PMXEVTYPER and
1527 * PMXEVCNTR. We allow [0..31] to be written to PMSELR here; in the
1528 * meanwhile, we check PMSELR.SEL when PMXEVTYPER and PMXEVCNTR are
1531 env
->cp15
.c9_pmselr
= value
& 0x1f;
1534 static void pmccntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1537 pmccntr_op_start(env
);
1538 env
->cp15
.c15_ccnt
= value
;
1539 pmccntr_op_finish(env
);
1542 static void pmccntr_write32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1545 uint64_t cur_val
= pmccntr_read(env
, NULL
);
1547 pmccntr_write(env
, ri
, deposit64(cur_val
, 0, 32, value
));
1550 static void pmccfiltr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1553 pmccntr_op_start(env
);
1554 env
->cp15
.pmccfiltr_el0
= value
& PMCCFILTR_EL0
;
1555 pmccntr_op_finish(env
);
1558 static void pmccfiltr_write_a32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1561 pmccntr_op_start(env
);
1562 /* M is not accessible from AArch32 */
1563 env
->cp15
.pmccfiltr_el0
= (env
->cp15
.pmccfiltr_el0
& PMCCFILTR_M
) |
1564 (value
& PMCCFILTR
);
1565 pmccntr_op_finish(env
);
1568 static uint64_t pmccfiltr_read_a32(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1570 /* M is not visible in AArch32 */
1571 return env
->cp15
.pmccfiltr_el0
& PMCCFILTR
;
1574 static void pmcntenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1578 value
&= pmu_counter_mask(env
);
1579 env
->cp15
.c9_pmcnten
|= value
;
1583 static void pmcntenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1587 value
&= pmu_counter_mask(env
);
1588 env
->cp15
.c9_pmcnten
&= ~value
;
1592 static void pmovsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1595 value
&= pmu_counter_mask(env
);
1596 env
->cp15
.c9_pmovsr
&= ~value
;
1597 pmu_update_irq(env
);
1600 static void pmovsset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1603 value
&= pmu_counter_mask(env
);
1604 env
->cp15
.c9_pmovsr
|= value
;
1605 pmu_update_irq(env
);
1608 static void pmevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1609 uint64_t value
, const uint8_t counter
)
1611 if (counter
== 31) {
1612 pmccfiltr_write(env
, ri
, value
);
1613 } else if (counter
< pmu_num_counters(env
)) {
1614 pmevcntr_op_start(env
, counter
);
1617 * If this counter's event type is changing, store the current
1618 * underlying count for the new type in c14_pmevcntr_delta[counter] so
1619 * pmevcntr_op_finish has the correct baseline when it converts back to
1622 uint16_t old_event
= env
->cp15
.c14_pmevtyper
[counter
] &
1623 PMXEVTYPER_EVTCOUNT
;
1624 uint16_t new_event
= value
& PMXEVTYPER_EVTCOUNT
;
1625 if (old_event
!= new_event
) {
1627 if (event_supported(new_event
)) {
1628 uint16_t event_idx
= supported_event_map
[new_event
];
1629 count
= pm_events
[event_idx
].get_count(env
);
1631 env
->cp15
.c14_pmevcntr_delta
[counter
] = count
;
1634 env
->cp15
.c14_pmevtyper
[counter
] = value
& PMXEVTYPER_MASK
;
1635 pmevcntr_op_finish(env
, counter
);
1638 * Attempts to access PMXEVTYPER are CONSTRAINED UNPREDICTABLE when
1639 * PMSELR value is equal to or greater than the number of implemented
1640 * counters, but not equal to 0x1f. We opt to behave as a RAZ/WI.
1644 static uint64_t pmevtyper_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1645 const uint8_t counter
)
1647 if (counter
== 31) {
1648 return env
->cp15
.pmccfiltr_el0
;
1649 } else if (counter
< pmu_num_counters(env
)) {
1650 return env
->cp15
.c14_pmevtyper
[counter
];
1653 * We opt to behave as a RAZ/WI when attempts to access PMXEVTYPER
1654 * are CONSTRAINED UNPREDICTABLE. See comments in pmevtyper_write().
1660 static void pmevtyper_writefn(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1663 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1664 pmevtyper_write(env
, ri
, value
, counter
);
1667 static void pmevtyper_rawwrite(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1670 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1671 env
->cp15
.c14_pmevtyper
[counter
] = value
;
1674 * pmevtyper_rawwrite is called between a pair of pmu_op_start and
1675 * pmu_op_finish calls when loading saved state for a migration. Because
1676 * we're potentially updating the type of event here, the value written to
1677 * c14_pmevcntr_delta by the preceding pmu_op_start call may be for a
1678 * different counter type. Therefore, we need to set this value to the
1679 * current count for the counter type we're writing so that pmu_op_finish
1680 * has the correct count for its calculation.
1682 uint16_t event
= value
& PMXEVTYPER_EVTCOUNT
;
1683 if (event_supported(event
)) {
1684 uint16_t event_idx
= supported_event_map
[event
];
1685 env
->cp15
.c14_pmevcntr_delta
[counter
] =
1686 pm_events
[event_idx
].get_count(env
);
1690 static uint64_t pmevtyper_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1692 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1693 return pmevtyper_read(env
, ri
, counter
);
1696 static void pmxevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1699 pmevtyper_write(env
, ri
, value
, env
->cp15
.c9_pmselr
& 31);
1702 static uint64_t pmxevtyper_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1704 return pmevtyper_read(env
, ri
, env
->cp15
.c9_pmselr
& 31);
1707 static void pmevcntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1708 uint64_t value
, uint8_t counter
)
1710 if (!cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1711 /* Before FEAT_PMUv3p5, top 32 bits of event counters are RES0 */
1712 value
&= MAKE_64BIT_MASK(0, 32);
1714 if (counter
< pmu_num_counters(env
)) {
1715 pmevcntr_op_start(env
, counter
);
1716 env
->cp15
.c14_pmevcntr
[counter
] = value
;
1717 pmevcntr_op_finish(env
, counter
);
1720 * We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
1721 * are CONSTRAINED UNPREDICTABLE.
1725 static uint64_t pmevcntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1728 if (counter
< pmu_num_counters(env
)) {
1730 pmevcntr_op_start(env
, counter
);
1731 ret
= env
->cp15
.c14_pmevcntr
[counter
];
1732 pmevcntr_op_finish(env
, counter
);
1733 if (!cpu_isar_feature(any_pmuv3p5
, env_archcpu(env
))) {
1734 /* Before FEAT_PMUv3p5, top 32 bits of event counters are RES0 */
1735 ret
&= MAKE_64BIT_MASK(0, 32);
1740 * We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
1741 * are CONSTRAINED UNPREDICTABLE.
1747 static void pmevcntr_writefn(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1750 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1751 pmevcntr_write(env
, ri
, value
, counter
);
1754 static uint64_t pmevcntr_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1756 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1757 return pmevcntr_read(env
, ri
, counter
);
1760 static void pmevcntr_rawwrite(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1763 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1764 assert(counter
< pmu_num_counters(env
));
1765 env
->cp15
.c14_pmevcntr
[counter
] = value
;
1766 pmevcntr_write(env
, ri
, value
, counter
);
1769 static uint64_t pmevcntr_rawread(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1771 uint8_t counter
= ((ri
->crm
& 3) << 3) | (ri
->opc2
& 7);
1772 assert(counter
< pmu_num_counters(env
));
1773 return env
->cp15
.c14_pmevcntr
[counter
];
1776 static void pmxevcntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1779 pmevcntr_write(env
, ri
, value
, env
->cp15
.c9_pmselr
& 31);
1782 static uint64_t pmxevcntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1784 return pmevcntr_read(env
, ri
, env
->cp15
.c9_pmselr
& 31);
1787 static void pmuserenr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1790 if (arm_feature(env
, ARM_FEATURE_V8
)) {
1791 env
->cp15
.c9_pmuserenr
= value
& 0xf;
1793 env
->cp15
.c9_pmuserenr
= value
& 1;
1797 static void pmintenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1800 /* We have no event counters so only the C bit can be changed */
1801 value
&= pmu_counter_mask(env
);
1802 env
->cp15
.c9_pminten
|= value
;
1803 pmu_update_irq(env
);
1806 static void pmintenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1809 value
&= pmu_counter_mask(env
);
1810 env
->cp15
.c9_pminten
&= ~value
;
1811 pmu_update_irq(env
);
1814 static void vbar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1818 * Note that even though the AArch64 view of this register has bits
1819 * [10:0] all RES0 we can only mask the bottom 5, to comply with the
1820 * architectural requirements for bits which are RES0 only in some
1821 * contexts. (ARMv8 would permit us to do no masking at all, but ARMv7
1822 * requires the bottom five bits to be RAZ/WI because they're UNK/SBZP.)
1824 raw_write(env
, ri
, value
& ~0x1FULL
);
1827 static void scr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
1829 /* Begin with base v8.0 state. */
1830 uint64_t valid_mask
= 0x3fff;
1831 ARMCPU
*cpu
= env_archcpu(env
);
1835 * Because SCR_EL3 is the "real" cpreg and SCR is the alias, reset always
1836 * passes the reginfo for SCR_EL3, which has type ARM_CP_STATE_AA64.
1837 * Instead, choose the format based on the mode of EL3.
1839 if (arm_el_is_aa64(env
, 3)) {
1840 value
|= SCR_FW
| SCR_AW
; /* RES1 */
1841 valid_mask
&= ~SCR_NET
; /* RES0 */
1843 if (!cpu_isar_feature(aa64_aa32_el1
, cpu
) &&
1844 !cpu_isar_feature(aa64_aa32_el2
, cpu
)) {
1845 value
|= SCR_RW
; /* RAO/WI */
1847 if (cpu_isar_feature(aa64_ras
, cpu
)) {
1848 valid_mask
|= SCR_TERR
;
1850 if (cpu_isar_feature(aa64_lor
, cpu
)) {
1851 valid_mask
|= SCR_TLOR
;
1853 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
1854 valid_mask
|= SCR_API
| SCR_APK
;
1856 if (cpu_isar_feature(aa64_sel2
, cpu
)) {
1857 valid_mask
|= SCR_EEL2
;
1858 } else if (cpu_isar_feature(aa64_rme
, cpu
)) {
1859 /* With RME and without SEL2, NS is RES1 (R_GSWWH, I_DJJQJ). */
1862 if (cpu_isar_feature(aa64_mte
, cpu
)) {
1863 valid_mask
|= SCR_ATA
;
1865 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
1866 valid_mask
|= SCR_ENSCXT
;
1868 if (cpu_isar_feature(aa64_doublefault
, cpu
)) {
1869 valid_mask
|= SCR_EASE
| SCR_NMEA
;
1871 if (cpu_isar_feature(aa64_sme
, cpu
)) {
1872 valid_mask
|= SCR_ENTP2
;
1874 if (cpu_isar_feature(aa64_hcx
, cpu
)) {
1875 valid_mask
|= SCR_HXEN
;
1877 if (cpu_isar_feature(aa64_fgt
, cpu
)) {
1878 valid_mask
|= SCR_FGTEN
;
1880 if (cpu_isar_feature(aa64_rme
, cpu
)) {
1881 valid_mask
|= SCR_NSE
| SCR_GPF
;
1884 valid_mask
&= ~(SCR_RW
| SCR_ST
);
1885 if (cpu_isar_feature(aa32_ras
, cpu
)) {
1886 valid_mask
|= SCR_TERR
;
1890 if (!arm_feature(env
, ARM_FEATURE_EL2
)) {
1891 valid_mask
&= ~SCR_HCE
;
1894 * On ARMv7, SMD (or SCD as it is called in v7) is only
1895 * supported if EL2 exists. The bit is UNK/SBZP when
1896 * EL2 is unavailable. In QEMU ARMv7, we force it to always zero
1897 * when EL2 is unavailable.
1898 * On ARMv8, this bit is always available.
1900 if (arm_feature(env
, ARM_FEATURE_V7
) &&
1901 !arm_feature(env
, ARM_FEATURE_V8
)) {
1902 valid_mask
&= ~SCR_SMD
;
1906 /* Clear all-context RES0 bits. */
1907 value
&= valid_mask
;
1908 changed
= env
->cp15
.scr_el3
^ value
;
1909 env
->cp15
.scr_el3
= value
;
1912 * If SCR_EL3.{NS,NSE} changes, i.e. change of security state,
1913 * we must invalidate all TLBs below EL3.
1915 if (changed
& (SCR_NS
| SCR_NSE
)) {
1916 tlb_flush_by_mmuidx(env_cpu(env
), (ARMMMUIdxBit_E10_0
|
1917 ARMMMUIdxBit_E20_0
|
1918 ARMMMUIdxBit_E10_1
|
1919 ARMMMUIdxBit_E20_2
|
1920 ARMMMUIdxBit_E10_1_PAN
|
1921 ARMMMUIdxBit_E20_2_PAN
|
1926 static void scr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1929 * scr_write will set the RES1 bits on an AArch64-only CPU.
1930 * The reset value will be 0x30 on an AArch64-only CPU and 0 otherwise.
1932 scr_write(env
, ri
, 0);
1935 static CPAccessResult
access_tid4(CPUARMState
*env
,
1936 const ARMCPRegInfo
*ri
,
1939 if (arm_current_el(env
) == 1 &&
1940 (arm_hcr_el2_eff(env
) & (HCR_TID2
| HCR_TID4
))) {
1941 return CP_ACCESS_TRAP_EL2
;
1944 return CP_ACCESS_OK
;
1947 static uint64_t ccsidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1949 ARMCPU
*cpu
= env_archcpu(env
);
1952 * Acquire the CSSELR index from the bank corresponding to the CCSIDR
1955 uint32_t index
= A32_BANKED_REG_GET(env
, csselr
,
1956 ri
->secure
& ARM_CP_SECSTATE_S
);
1958 return cpu
->ccsidr
[index
];
1961 static void csselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1964 raw_write(env
, ri
, value
& 0xf);
1967 static uint64_t isr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1969 CPUState
*cs
= env_cpu(env
);
1970 bool el1
= arm_current_el(env
) == 1;
1971 uint64_t hcr_el2
= el1
? arm_hcr_el2_eff(env
) : 0;
1974 if (hcr_el2
& HCR_IMO
) {
1975 if (cs
->interrupt_request
& CPU_INTERRUPT_VIRQ
) {
1979 if (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) {
1984 if (hcr_el2
& HCR_FMO
) {
1985 if (cs
->interrupt_request
& CPU_INTERRUPT_VFIQ
) {
1989 if (cs
->interrupt_request
& CPU_INTERRUPT_FIQ
) {
1994 if (hcr_el2
& HCR_AMO
) {
1995 if (cs
->interrupt_request
& CPU_INTERRUPT_VSERR
) {
2003 static CPAccessResult
access_aa64_tid1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2006 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID1
)) {
2007 return CP_ACCESS_TRAP_EL2
;
2010 return CP_ACCESS_OK
;
2013 static CPAccessResult
access_aa32_tid1(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2016 if (arm_feature(env
, ARM_FEATURE_V8
)) {
2017 return access_aa64_tid1(env
, ri
, isread
);
2020 return CP_ACCESS_OK
;
2023 static const ARMCPRegInfo v7_cp_reginfo
[] = {
2024 /* the old v6 WFI, UNPREDICTABLE in v7 but we choose to NOP */
2025 { .name
= "NOP", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
2026 .access
= PL1_W
, .type
= ARM_CP_NOP
},
2028 * Performance monitors are implementation defined in v7,
2029 * but with an ARM recommended set of registers, which we
2032 * Performance registers fall into three categories:
2033 * (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR)
2034 * (b) RO in PL0 (ie UNDEF on write), RW in PL1 (PMUSERENR)
2035 * (c) UNDEF in PL0 if PMUSERENR.EN==0, otherwise accessible (all others)
2036 * For the cases controlled by PMUSERENR we must set .access to PL0_RW
2037 * or PL0_RO as appropriate and then check PMUSERENR in the helper fn.
2039 { .name
= "PMCNTENSET", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 1,
2040 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2041 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
2042 .writefn
= pmcntenset_write
,
2043 .accessfn
= pmreg_access
,
2045 .raw_writefn
= raw_write
},
2046 { .name
= "PMCNTENSET_EL0", .state
= ARM_CP_STATE_AA64
, .type
= ARM_CP_IO
,
2047 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 1,
2048 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2050 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
), .resetvalue
= 0,
2051 .writefn
= pmcntenset_write
, .raw_writefn
= raw_write
},
2052 { .name
= "PMCNTENCLR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 2,
2054 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
2055 .accessfn
= pmreg_access
,
2057 .writefn
= pmcntenclr_write
,
2058 .type
= ARM_CP_ALIAS
| ARM_CP_IO
},
2059 { .name
= "PMCNTENCLR_EL0", .state
= ARM_CP_STATE_AA64
,
2060 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 2,
2061 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2063 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2064 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
),
2065 .writefn
= pmcntenclr_write
},
2066 { .name
= "PMOVSR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 3,
2067 .access
= PL0_RW
, .type
= ARM_CP_IO
,
2068 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmovsr
),
2069 .accessfn
= pmreg_access
,
2071 .writefn
= pmovsr_write
,
2072 .raw_writefn
= raw_write
},
2073 { .name
= "PMOVSCLR_EL0", .state
= ARM_CP_STATE_AA64
,
2074 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 3,
2075 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2077 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2078 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
2079 .writefn
= pmovsr_write
,
2080 .raw_writefn
= raw_write
},
2081 { .name
= "PMSWINC", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 4,
2082 .access
= PL0_W
, .accessfn
= pmreg_access_swinc
,
2083 .fgt
= FGT_PMSWINC_EL0
,
2084 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2085 .writefn
= pmswinc_write
},
2086 { .name
= "PMSWINC_EL0", .state
= ARM_CP_STATE_AA64
,
2087 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 4,
2088 .access
= PL0_W
, .accessfn
= pmreg_access_swinc
,
2089 .fgt
= FGT_PMSWINC_EL0
,
2090 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2091 .writefn
= pmswinc_write
},
2092 { .name
= "PMSELR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 5,
2093 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
,
2094 .fgt
= FGT_PMSELR_EL0
,
2095 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmselr
),
2096 .accessfn
= pmreg_access_selr
, .writefn
= pmselr_write
,
2097 .raw_writefn
= raw_write
},
2098 { .name
= "PMSELR_EL0", .state
= ARM_CP_STATE_AA64
,
2099 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 5,
2100 .access
= PL0_RW
, .accessfn
= pmreg_access_selr
,
2101 .fgt
= FGT_PMSELR_EL0
,
2102 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmselr
),
2103 .writefn
= pmselr_write
, .raw_writefn
= raw_write
, },
2104 { .name
= "PMCCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 0,
2105 .access
= PL0_RW
, .resetvalue
= 0, .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2106 .fgt
= FGT_PMCCNTR_EL0
,
2107 .readfn
= pmccntr_read
, .writefn
= pmccntr_write32
,
2108 .accessfn
= pmreg_access_ccntr
},
2109 { .name
= "PMCCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
2110 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 0,
2111 .access
= PL0_RW
, .accessfn
= pmreg_access_ccntr
,
2112 .fgt
= FGT_PMCCNTR_EL0
,
2114 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ccnt
),
2115 .readfn
= pmccntr_read
, .writefn
= pmccntr_write
,
2116 .raw_readfn
= raw_read
, .raw_writefn
= raw_write
, },
2117 { .name
= "PMCCFILTR", .cp
= 15, .opc1
= 0, .crn
= 14, .crm
= 15, .opc2
= 7,
2118 .writefn
= pmccfiltr_write_a32
, .readfn
= pmccfiltr_read_a32
,
2119 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2120 .fgt
= FGT_PMCCFILTR_EL0
,
2121 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2123 { .name
= "PMCCFILTR_EL0", .state
= ARM_CP_STATE_AA64
,
2124 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 15, .opc2
= 7,
2125 .writefn
= pmccfiltr_write
, .raw_writefn
= raw_write
,
2126 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2127 .fgt
= FGT_PMCCFILTR_EL0
,
2129 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmccfiltr_el0
),
2131 { .name
= "PMXEVTYPER", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 1,
2132 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2133 .accessfn
= pmreg_access
,
2134 .fgt
= FGT_PMEVTYPERN_EL0
,
2135 .writefn
= pmxevtyper_write
, .readfn
= pmxevtyper_read
},
2136 { .name
= "PMXEVTYPER_EL0", .state
= ARM_CP_STATE_AA64
,
2137 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 1,
2138 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2139 .accessfn
= pmreg_access
,
2140 .fgt
= FGT_PMEVTYPERN_EL0
,
2141 .writefn
= pmxevtyper_write
, .readfn
= pmxevtyper_read
},
2142 { .name
= "PMXEVCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 2,
2143 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2144 .accessfn
= pmreg_access_xevcntr
,
2145 .fgt
= FGT_PMEVCNTRN_EL0
,
2146 .writefn
= pmxevcntr_write
, .readfn
= pmxevcntr_read
},
2147 { .name
= "PMXEVCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
2148 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 2,
2149 .access
= PL0_RW
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
2150 .accessfn
= pmreg_access_xevcntr
,
2151 .fgt
= FGT_PMEVCNTRN_EL0
,
2152 .writefn
= pmxevcntr_write
, .readfn
= pmxevcntr_read
},
2153 { .name
= "PMUSERENR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 0,
2154 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
,
2155 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmuserenr
),
2157 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
2158 { .name
= "PMUSERENR_EL0", .state
= ARM_CP_STATE_AA64
,
2159 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 0,
2160 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
, .type
= ARM_CP_ALIAS
,
2161 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmuserenr
),
2163 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
2164 { .name
= "PMINTENSET", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 1,
2165 .access
= PL1_RW
, .accessfn
= access_tpm
,
2167 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2168 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pminten
),
2170 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
},
2171 { .name
= "PMINTENSET_EL1", .state
= ARM_CP_STATE_AA64
,
2172 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 1,
2173 .access
= PL1_RW
, .accessfn
= access_tpm
,
2176 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2177 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
,
2178 .resetvalue
= 0x0 },
2179 { .name
= "PMINTENCLR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 2,
2180 .access
= PL1_RW
, .accessfn
= access_tpm
,
2182 .type
= ARM_CP_ALIAS
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2183 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2184 .writefn
= pmintenclr_write
, },
2185 { .name
= "PMINTENCLR_EL1", .state
= ARM_CP_STATE_AA64
,
2186 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 2,
2187 .access
= PL1_RW
, .accessfn
= access_tpm
,
2189 .type
= ARM_CP_ALIAS
| ARM_CP_IO
| ARM_CP_NO_RAW
,
2190 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
2191 .writefn
= pmintenclr_write
},
2192 { .name
= "CCSIDR", .state
= ARM_CP_STATE_BOTH
,
2193 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 0,
2195 .accessfn
= access_tid4
,
2196 .fgt
= FGT_CCSIDR_EL1
,
2197 .readfn
= ccsidr_read
, .type
= ARM_CP_NO_RAW
},
2198 { .name
= "CSSELR", .state
= ARM_CP_STATE_BOTH
,
2199 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 2, .opc2
= 0,
2201 .accessfn
= access_tid4
,
2202 .fgt
= FGT_CSSELR_EL1
,
2203 .writefn
= csselr_write
, .resetvalue
= 0,
2204 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.csselr_s
),
2205 offsetof(CPUARMState
, cp15
.csselr_ns
) } },
2207 * Auxiliary ID register: this actually has an IMPDEF value but for now
2208 * just RAZ for all cores:
2210 { .name
= "AIDR", .state
= ARM_CP_STATE_BOTH
,
2211 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 7,
2212 .access
= PL1_R
, .type
= ARM_CP_CONST
,
2213 .accessfn
= access_aa64_tid1
,
2214 .fgt
= FGT_AIDR_EL1
,
2217 * Auxiliary fault status registers: these also are IMPDEF, and we
2218 * choose to RAZ/WI for all cores.
2220 { .name
= "AFSR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2221 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 0,
2222 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2223 .fgt
= FGT_AFSR0_EL1
,
2224 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
2225 { .name
= "AFSR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2226 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 1,
2227 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2228 .fgt
= FGT_AFSR1_EL1
,
2229 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
2231 * MAIR can just read-as-written because we don't implement caches
2232 * and so don't need to care about memory attributes.
2234 { .name
= "MAIR_EL1", .state
= ARM_CP_STATE_AA64
,
2235 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
2236 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2237 .fgt
= FGT_MAIR_EL1
,
2238 .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[1]),
2240 { .name
= "MAIR_EL3", .state
= ARM_CP_STATE_AA64
,
2241 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 2, .opc2
= 0,
2242 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[3]),
2245 * For non-long-descriptor page tables these are PRRR and NMRR;
2246 * regardless they still act as reads-as-written for QEMU.
2249 * MAIR0/1 are defined separately from their 64-bit counterpart which
2250 * allows them to assign the correct fieldoffset based on the endianness
2251 * handled in the field definitions.
2253 { .name
= "MAIR0", .state
= ARM_CP_STATE_AA32
,
2254 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
2255 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2256 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair0_s
),
2257 offsetof(CPUARMState
, cp15
.mair0_ns
) },
2258 .resetfn
= arm_cp_reset_ignore
},
2259 { .name
= "MAIR1", .state
= ARM_CP_STATE_AA32
,
2260 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 1,
2261 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
2262 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair1_s
),
2263 offsetof(CPUARMState
, cp15
.mair1_ns
) },
2264 .resetfn
= arm_cp_reset_ignore
},
2265 { .name
= "ISR_EL1", .state
= ARM_CP_STATE_BOTH
,
2266 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 1, .opc2
= 0,
2268 .type
= ARM_CP_NO_RAW
, .access
= PL1_R
, .readfn
= isr_read
},
2269 /* 32 bit ITLB invalidates */
2270 { .name
= "ITLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 0,
2271 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2272 .writefn
= tlbiall_write
},
2273 { .name
= "ITLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
2274 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2275 .writefn
= tlbimva_write
},
2276 { .name
= "ITLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 2,
2277 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2278 .writefn
= tlbiasid_write
},
2279 /* 32 bit DTLB invalidates */
2280 { .name
= "DTLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 0,
2281 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2282 .writefn
= tlbiall_write
},
2283 { .name
= "DTLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
2284 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2285 .writefn
= tlbimva_write
},
2286 { .name
= "DTLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 2,
2287 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2288 .writefn
= tlbiasid_write
},
2289 /* 32 bit TLB invalidates */
2290 { .name
= "TLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
2291 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2292 .writefn
= tlbiall_write
},
2293 { .name
= "TLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
2294 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2295 .writefn
= tlbimva_write
},
2296 { .name
= "TLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
2297 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2298 .writefn
= tlbiasid_write
},
2299 { .name
= "TLBIMVAA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
2300 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
2301 .writefn
= tlbimvaa_write
},
2304 static const ARMCPRegInfo v7mp_cp_reginfo
[] = {
2305 /* 32 bit TLB invalidates, Inner Shareable */
2306 { .name
= "TLBIALLIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
2307 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
2308 .writefn
= tlbiall_is_write
},
2309 { .name
= "TLBIMVAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
2310 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
2311 .writefn
= tlbimva_is_write
},
2312 { .name
= "TLBIASIDIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
2313 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
2314 .writefn
= tlbiasid_is_write
},
2315 { .name
= "TLBIMVAAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
2316 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
2317 .writefn
= tlbimvaa_is_write
},
2320 static const ARMCPRegInfo pmovsset_cp_reginfo
[] = {
2321 /* PMOVSSET is not implemented in v7 before v7ve */
2322 { .name
= "PMOVSSET", .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 3,
2323 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2325 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2326 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmovsr
),
2327 .writefn
= pmovsset_write
,
2328 .raw_writefn
= raw_write
},
2329 { .name
= "PMOVSSET_EL0", .state
= ARM_CP_STATE_AA64
,
2330 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 3,
2331 .access
= PL0_RW
, .accessfn
= pmreg_access
,
2333 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
2334 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
2335 .writefn
= pmovsset_write
,
2336 .raw_writefn
= raw_write
},
2339 static void teecr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2346 static CPAccessResult
teecr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2350 * HSTR.TTEE only exists in v7A, not v8A, but v8A doesn't have T2EE
2351 * at all, so we don't need to check whether we're v8A.
2353 if (arm_current_el(env
) < 2 && !arm_is_secure_below_el3(env
) &&
2354 (env
->cp15
.hstr_el2
& HSTR_TTEE
)) {
2355 return CP_ACCESS_TRAP_EL2
;
2357 return CP_ACCESS_OK
;
2360 static CPAccessResult
teehbr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2363 if (arm_current_el(env
) == 0 && (env
->teecr
& 1)) {
2364 return CP_ACCESS_TRAP
;
2366 return teecr_access(env
, ri
, isread
);
2369 static const ARMCPRegInfo t2ee_cp_reginfo
[] = {
2370 { .name
= "TEECR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 6, .opc2
= 0,
2371 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, teecr
),
2373 .writefn
= teecr_write
, .accessfn
= teecr_access
},
2374 { .name
= "TEEHBR", .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 6, .opc2
= 0,
2375 .access
= PL0_RW
, .fieldoffset
= offsetof(CPUARMState
, teehbr
),
2376 .accessfn
= teehbr_access
, .resetvalue
= 0 },
2379 static const ARMCPRegInfo v6k_cp_reginfo
[] = {
2380 { .name
= "TPIDR_EL0", .state
= ARM_CP_STATE_AA64
,
2381 .opc0
= 3, .opc1
= 3, .opc2
= 2, .crn
= 13, .crm
= 0,
2383 .fgt
= FGT_TPIDR_EL0
,
2384 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[0]), .resetvalue
= 0 },
2385 { .name
= "TPIDRURW", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 2,
2387 .fgt
= FGT_TPIDR_EL0
,
2388 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrurw_s
),
2389 offsetoflow32(CPUARMState
, cp15
.tpidrurw_ns
) },
2390 .resetfn
= arm_cp_reset_ignore
},
2391 { .name
= "TPIDRRO_EL0", .state
= ARM_CP_STATE_AA64
,
2392 .opc0
= 3, .opc1
= 3, .opc2
= 3, .crn
= 13, .crm
= 0,
2393 .access
= PL0_R
| PL1_W
,
2394 .fgt
= FGT_TPIDRRO_EL0
,
2395 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidrro_el
[0]),
2397 { .name
= "TPIDRURO", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 3,
2398 .access
= PL0_R
| PL1_W
,
2399 .fgt
= FGT_TPIDRRO_EL0
,
2400 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidruro_s
),
2401 offsetoflow32(CPUARMState
, cp15
.tpidruro_ns
) },
2402 .resetfn
= arm_cp_reset_ignore
},
2403 { .name
= "TPIDR_EL1", .state
= ARM_CP_STATE_AA64
,
2404 .opc0
= 3, .opc1
= 0, .opc2
= 4, .crn
= 13, .crm
= 0,
2406 .fgt
= FGT_TPIDR_EL1
,
2407 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[1]), .resetvalue
= 0 },
2408 { .name
= "TPIDRPRW", .opc1
= 0, .cp
= 15, .crn
= 13, .crm
= 0, .opc2
= 4,
2410 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrprw_s
),
2411 offsetoflow32(CPUARMState
, cp15
.tpidrprw_ns
) },
2415 #ifndef CONFIG_USER_ONLY
2417 static CPAccessResult
gt_cntfrq_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2421 * CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero.
2422 * Writable only at the highest implemented exception level.
2424 int el
= arm_current_el(env
);
2430 hcr
= arm_hcr_el2_eff(env
);
2431 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2432 cntkctl
= env
->cp15
.cnthctl_el2
;
2434 cntkctl
= env
->cp15
.c14_cntkctl
;
2436 if (!extract32(cntkctl
, 0, 2)) {
2437 return CP_ACCESS_TRAP
;
2441 if (!isread
&& ri
->state
== ARM_CP_STATE_AA32
&&
2442 arm_is_secure_below_el3(env
)) {
2443 /* Accesses from 32-bit Secure EL1 UNDEF (*not* trap to EL3!) */
2444 return CP_ACCESS_TRAP_UNCATEGORIZED
;
2452 if (!isread
&& el
< arm_highest_el(env
)) {
2453 return CP_ACCESS_TRAP_UNCATEGORIZED
;
2456 return CP_ACCESS_OK
;
2459 static CPAccessResult
gt_counter_access(CPUARMState
*env
, int timeridx
,
2462 unsigned int cur_el
= arm_current_el(env
);
2463 bool has_el2
= arm_is_el2_enabled(env
);
2464 uint64_t hcr
= arm_hcr_el2_eff(env
);
2468 /* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]CTEN. */
2469 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2470 return (extract32(env
->cp15
.cnthctl_el2
, timeridx
, 1)
2471 ? CP_ACCESS_OK
: CP_ACCESS_TRAP_EL2
);
2474 /* CNT[PV]CT: not visible from PL0 if EL0[PV]CTEN is zero */
2475 if (!extract32(env
->cp15
.c14_cntkctl
, timeridx
, 1)) {
2476 return CP_ACCESS_TRAP
;
2479 /* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PCTEN. */
2480 if (hcr
& HCR_E2H
) {
2481 if (timeridx
== GTIMER_PHYS
&&
2482 !extract32(env
->cp15
.cnthctl_el2
, 10, 1)) {
2483 return CP_ACCESS_TRAP_EL2
;
2486 /* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */
2487 if (has_el2
&& timeridx
== GTIMER_PHYS
&&
2488 !extract32(env
->cp15
.cnthctl_el2
, 1, 1)) {
2489 return CP_ACCESS_TRAP_EL2
;
2495 /* Check CNTHCTL_EL2.EL1PCTEN, which changes location based on E2H. */
2496 if (has_el2
&& timeridx
== GTIMER_PHYS
&&
2498 ? !extract32(env
->cp15
.cnthctl_el2
, 10, 1)
2499 : !extract32(env
->cp15
.cnthctl_el2
, 0, 1))) {
2500 return CP_ACCESS_TRAP_EL2
;
2504 return CP_ACCESS_OK
;
2507 static CPAccessResult
gt_timer_access(CPUARMState
*env
, int timeridx
,
2510 unsigned int cur_el
= arm_current_el(env
);
2511 bool has_el2
= arm_is_el2_enabled(env
);
2512 uint64_t hcr
= arm_hcr_el2_eff(env
);
2516 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2517 /* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]TEN. */
2518 return (extract32(env
->cp15
.cnthctl_el2
, 9 - timeridx
, 1)
2519 ? CP_ACCESS_OK
: CP_ACCESS_TRAP_EL2
);
2523 * CNT[PV]_CVAL, CNT[PV]_CTL, CNT[PV]_TVAL: not visible from
2524 * EL0 if EL0[PV]TEN is zero.
2526 if (!extract32(env
->cp15
.c14_cntkctl
, 9 - timeridx
, 1)) {
2527 return CP_ACCESS_TRAP
;
2532 if (has_el2
&& timeridx
== GTIMER_PHYS
) {
2533 if (hcr
& HCR_E2H
) {
2534 /* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PTEN. */
2535 if (!extract32(env
->cp15
.cnthctl_el2
, 11, 1)) {
2536 return CP_ACCESS_TRAP_EL2
;
2539 /* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */
2540 if (!extract32(env
->cp15
.cnthctl_el2
, 1, 1)) {
2541 return CP_ACCESS_TRAP_EL2
;
2547 return CP_ACCESS_OK
;
2550 static CPAccessResult
gt_pct_access(CPUARMState
*env
,
2551 const ARMCPRegInfo
*ri
,
2554 return gt_counter_access(env
, GTIMER_PHYS
, isread
);
2557 static CPAccessResult
gt_vct_access(CPUARMState
*env
,
2558 const ARMCPRegInfo
*ri
,
2561 return gt_counter_access(env
, GTIMER_VIRT
, isread
);
2564 static CPAccessResult
gt_ptimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2567 return gt_timer_access(env
, GTIMER_PHYS
, isread
);
2570 static CPAccessResult
gt_vtimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2573 return gt_timer_access(env
, GTIMER_VIRT
, isread
);
2576 static CPAccessResult
gt_stimer_access(CPUARMState
*env
,
2577 const ARMCPRegInfo
*ri
,
2581 * The AArch64 register view of the secure physical timer is
2582 * always accessible from EL3, and configurably accessible from
2585 switch (arm_current_el(env
)) {
2587 if (!arm_is_secure(env
)) {
2588 return CP_ACCESS_TRAP
;
2590 if (!(env
->cp15
.scr_el3
& SCR_ST
)) {
2591 return CP_ACCESS_TRAP_EL3
;
2593 return CP_ACCESS_OK
;
2596 return CP_ACCESS_TRAP
;
2598 return CP_ACCESS_OK
;
2600 g_assert_not_reached();
2604 static uint64_t gt_get_countervalue(CPUARMState
*env
)
2606 ARMCPU
*cpu
= env_archcpu(env
);
2608 return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) / gt_cntfrq_period_ns(cpu
);
2611 static void gt_recalc_timer(ARMCPU
*cpu
, int timeridx
)
2613 ARMGenericTimer
*gt
= &cpu
->env
.cp15
.c14_timer
[timeridx
];
2617 * Timer enabled: calculate and set current ISTATUS, irq, and
2618 * reset timer to when ISTATUS next has to change
2620 uint64_t offset
= timeridx
== GTIMER_VIRT
?
2621 cpu
->env
.cp15
.cntvoff_el2
: 0;
2622 uint64_t count
= gt_get_countervalue(&cpu
->env
);
2623 /* Note that this must be unsigned 64 bit arithmetic: */
2624 int istatus
= count
- offset
>= gt
->cval
;
2628 gt
->ctl
= deposit32(gt
->ctl
, 2, 1, istatus
);
2630 irqstate
= (istatus
&& !(gt
->ctl
& 2));
2631 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], irqstate
);
2634 /* Next transition is when count rolls back over to zero */
2635 nexttick
= UINT64_MAX
;
2637 /* Next transition is when we hit cval */
2638 nexttick
= gt
->cval
+ offset
;
2641 * Note that the desired next expiry time might be beyond the
2642 * signed-64-bit range of a QEMUTimer -- in this case we just
2643 * set the timer for as far in the future as possible. When the
2644 * timer expires we will reset the timer for any remaining period.
2646 if (nexttick
> INT64_MAX
/ gt_cntfrq_period_ns(cpu
)) {
2647 timer_mod_ns(cpu
->gt_timer
[timeridx
], INT64_MAX
);
2649 timer_mod(cpu
->gt_timer
[timeridx
], nexttick
);
2651 trace_arm_gt_recalc(timeridx
, irqstate
, nexttick
);
2653 /* Timer disabled: ISTATUS and timer output always clear */
2655 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], 0);
2656 timer_del(cpu
->gt_timer
[timeridx
]);
2657 trace_arm_gt_recalc_disabled(timeridx
);
2661 static void gt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2664 ARMCPU
*cpu
= env_archcpu(env
);
2666 timer_del(cpu
->gt_timer
[timeridx
]);
2669 static uint64_t gt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2671 return gt_get_countervalue(env
);
2674 static uint64_t gt_virt_cnt_offset(CPUARMState
*env
)
2678 switch (arm_current_el(env
)) {
2680 hcr
= arm_hcr_el2_eff(env
);
2681 if (hcr
& HCR_E2H
) {
2686 hcr
= arm_hcr_el2_eff(env
);
2687 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
2693 return env
->cp15
.cntvoff_el2
;
2696 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2698 return gt_get_countervalue(env
) - gt_virt_cnt_offset(env
);
2701 static void gt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2705 trace_arm_gt_cval_write(timeridx
, value
);
2706 env
->cp15
.c14_timer
[timeridx
].cval
= value
;
2707 gt_recalc_timer(env_archcpu(env
), timeridx
);
2710 static uint64_t gt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2713 uint64_t offset
= 0;
2717 case GTIMER_HYPVIRT
:
2718 offset
= gt_virt_cnt_offset(env
);
2722 return (uint32_t)(env
->cp15
.c14_timer
[timeridx
].cval
-
2723 (gt_get_countervalue(env
) - offset
));
2726 static void gt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2730 uint64_t offset
= 0;
2734 case GTIMER_HYPVIRT
:
2735 offset
= gt_virt_cnt_offset(env
);
2739 trace_arm_gt_tval_write(timeridx
, value
);
2740 env
->cp15
.c14_timer
[timeridx
].cval
= gt_get_countervalue(env
) - offset
+
2741 sextract64(value
, 0, 32);
2742 gt_recalc_timer(env_archcpu(env
), timeridx
);
2745 static void gt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2749 ARMCPU
*cpu
= env_archcpu(env
);
2750 uint32_t oldval
= env
->cp15
.c14_timer
[timeridx
].ctl
;
2752 trace_arm_gt_ctl_write(timeridx
, value
);
2753 env
->cp15
.c14_timer
[timeridx
].ctl
= deposit64(oldval
, 0, 2, value
);
2754 if ((oldval
^ value
) & 1) {
2755 /* Enable toggled */
2756 gt_recalc_timer(cpu
, timeridx
);
2757 } else if ((oldval
^ value
) & 2) {
2759 * IMASK toggled: don't need to recalculate,
2760 * just set the interrupt line based on ISTATUS
2762 int irqstate
= (oldval
& 4) && !(value
& 2);
2764 trace_arm_gt_imask_toggle(timeridx
, irqstate
);
2765 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], irqstate
);
2769 static void gt_phys_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2771 gt_timer_reset(env
, ri
, GTIMER_PHYS
);
2774 static void gt_phys_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2777 gt_cval_write(env
, ri
, GTIMER_PHYS
, value
);
2780 static uint64_t gt_phys_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2782 return gt_tval_read(env
, ri
, GTIMER_PHYS
);
2785 static void gt_phys_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2788 gt_tval_write(env
, ri
, GTIMER_PHYS
, value
);
2791 static void gt_phys_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2794 gt_ctl_write(env
, ri
, GTIMER_PHYS
, value
);
2797 static int gt_phys_redir_timeridx(CPUARMState
*env
)
2799 switch (arm_mmu_idx(env
)) {
2800 case ARMMMUIdx_E20_0
:
2801 case ARMMMUIdx_E20_2
:
2802 case ARMMMUIdx_E20_2_PAN
:
2809 static int gt_virt_redir_timeridx(CPUARMState
*env
)
2811 switch (arm_mmu_idx(env
)) {
2812 case ARMMMUIdx_E20_0
:
2813 case ARMMMUIdx_E20_2
:
2814 case ARMMMUIdx_E20_2_PAN
:
2815 return GTIMER_HYPVIRT
;
2821 static uint64_t gt_phys_redir_cval_read(CPUARMState
*env
,
2822 const ARMCPRegInfo
*ri
)
2824 int timeridx
= gt_phys_redir_timeridx(env
);
2825 return env
->cp15
.c14_timer
[timeridx
].cval
;
2828 static void gt_phys_redir_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2831 int timeridx
= gt_phys_redir_timeridx(env
);
2832 gt_cval_write(env
, ri
, timeridx
, value
);
2835 static uint64_t gt_phys_redir_tval_read(CPUARMState
*env
,
2836 const ARMCPRegInfo
*ri
)
2838 int timeridx
= gt_phys_redir_timeridx(env
);
2839 return gt_tval_read(env
, ri
, timeridx
);
2842 static void gt_phys_redir_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2845 int timeridx
= gt_phys_redir_timeridx(env
);
2846 gt_tval_write(env
, ri
, timeridx
, value
);
2849 static uint64_t gt_phys_redir_ctl_read(CPUARMState
*env
,
2850 const ARMCPRegInfo
*ri
)
2852 int timeridx
= gt_phys_redir_timeridx(env
);
2853 return env
->cp15
.c14_timer
[timeridx
].ctl
;
2856 static void gt_phys_redir_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2859 int timeridx
= gt_phys_redir_timeridx(env
);
2860 gt_ctl_write(env
, ri
, timeridx
, value
);
2863 static void gt_virt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2865 gt_timer_reset(env
, ri
, GTIMER_VIRT
);
2868 static void gt_virt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2871 gt_cval_write(env
, ri
, GTIMER_VIRT
, value
);
2874 static uint64_t gt_virt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2876 return gt_tval_read(env
, ri
, GTIMER_VIRT
);
2879 static void gt_virt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2882 gt_tval_write(env
, ri
, GTIMER_VIRT
, value
);
2885 static void gt_virt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2888 gt_ctl_write(env
, ri
, GTIMER_VIRT
, value
);
2891 static void gt_cntvoff_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2894 ARMCPU
*cpu
= env_archcpu(env
);
2896 trace_arm_gt_cntvoff_write(value
);
2897 raw_write(env
, ri
, value
);
2898 gt_recalc_timer(cpu
, GTIMER_VIRT
);
2901 static uint64_t gt_virt_redir_cval_read(CPUARMState
*env
,
2902 const ARMCPRegInfo
*ri
)
2904 int timeridx
= gt_virt_redir_timeridx(env
);
2905 return env
->cp15
.c14_timer
[timeridx
].cval
;
2908 static void gt_virt_redir_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2911 int timeridx
= gt_virt_redir_timeridx(env
);
2912 gt_cval_write(env
, ri
, timeridx
, value
);
2915 static uint64_t gt_virt_redir_tval_read(CPUARMState
*env
,
2916 const ARMCPRegInfo
*ri
)
2918 int timeridx
= gt_virt_redir_timeridx(env
);
2919 return gt_tval_read(env
, ri
, timeridx
);
2922 static void gt_virt_redir_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2925 int timeridx
= gt_virt_redir_timeridx(env
);
2926 gt_tval_write(env
, ri
, timeridx
, value
);
2929 static uint64_t gt_virt_redir_ctl_read(CPUARMState
*env
,
2930 const ARMCPRegInfo
*ri
)
2932 int timeridx
= gt_virt_redir_timeridx(env
);
2933 return env
->cp15
.c14_timer
[timeridx
].ctl
;
2936 static void gt_virt_redir_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2939 int timeridx
= gt_virt_redir_timeridx(env
);
2940 gt_ctl_write(env
, ri
, timeridx
, value
);
2943 static void gt_hyp_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2945 gt_timer_reset(env
, ri
, GTIMER_HYP
);
2948 static void gt_hyp_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2951 gt_cval_write(env
, ri
, GTIMER_HYP
, value
);
2954 static uint64_t gt_hyp_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2956 return gt_tval_read(env
, ri
, GTIMER_HYP
);
2959 static void gt_hyp_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2962 gt_tval_write(env
, ri
, GTIMER_HYP
, value
);
2965 static void gt_hyp_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2968 gt_ctl_write(env
, ri
, GTIMER_HYP
, value
);
2971 static void gt_sec_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2973 gt_timer_reset(env
, ri
, GTIMER_SEC
);
2976 static void gt_sec_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2979 gt_cval_write(env
, ri
, GTIMER_SEC
, value
);
2982 static uint64_t gt_sec_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2984 return gt_tval_read(env
, ri
, GTIMER_SEC
);
2987 static void gt_sec_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2990 gt_tval_write(env
, ri
, GTIMER_SEC
, value
);
2993 static void gt_sec_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2996 gt_ctl_write(env
, ri
, GTIMER_SEC
, value
);
2999 static void gt_hv_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3001 gt_timer_reset(env
, ri
, GTIMER_HYPVIRT
);
3004 static void gt_hv_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3007 gt_cval_write(env
, ri
, GTIMER_HYPVIRT
, value
);
3010 static uint64_t gt_hv_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3012 return gt_tval_read(env
, ri
, GTIMER_HYPVIRT
);
3015 static void gt_hv_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3018 gt_tval_write(env
, ri
, GTIMER_HYPVIRT
, value
);
3021 static void gt_hv_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3024 gt_ctl_write(env
, ri
, GTIMER_HYPVIRT
, value
);
3027 void arm_gt_ptimer_cb(void *opaque
)
3029 ARMCPU
*cpu
= opaque
;
3031 gt_recalc_timer(cpu
, GTIMER_PHYS
);
3034 void arm_gt_vtimer_cb(void *opaque
)
3036 ARMCPU
*cpu
= opaque
;
3038 gt_recalc_timer(cpu
, GTIMER_VIRT
);
3041 void arm_gt_htimer_cb(void *opaque
)
3043 ARMCPU
*cpu
= opaque
;
3045 gt_recalc_timer(cpu
, GTIMER_HYP
);
3048 void arm_gt_stimer_cb(void *opaque
)
3050 ARMCPU
*cpu
= opaque
;
3052 gt_recalc_timer(cpu
, GTIMER_SEC
);
3055 void arm_gt_hvtimer_cb(void *opaque
)
3057 ARMCPU
*cpu
= opaque
;
3059 gt_recalc_timer(cpu
, GTIMER_HYPVIRT
);
3062 static void arm_gt_cntfrq_reset(CPUARMState
*env
, const ARMCPRegInfo
*opaque
)
3064 ARMCPU
*cpu
= env_archcpu(env
);
3066 cpu
->env
.cp15
.c14_cntfrq
= cpu
->gt_cntfrq_hz
;
3069 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
3071 * Note that CNTFRQ is purely reads-as-written for the benefit
3072 * of software; writing it doesn't actually change the timer frequency.
3073 * Our reset value matches the fixed frequency we implement the timer at.
3075 { .name
= "CNTFRQ", .cp
= 15, .crn
= 14, .crm
= 0, .opc1
= 0, .opc2
= 0,
3076 .type
= ARM_CP_ALIAS
,
3077 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
3078 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c14_cntfrq
),
3080 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
3081 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
3082 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
3083 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
3084 .resetfn
= arm_gt_cntfrq_reset
,
3086 /* overall control: mostly access permissions */
3087 { .name
= "CNTKCTL", .state
= ARM_CP_STATE_BOTH
,
3088 .opc0
= 3, .opc1
= 0, .crn
= 14, .crm
= 1, .opc2
= 0,
3090 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntkctl
),
3093 /* per-timer control */
3094 { .name
= "CNTP_CTL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
3095 .secure
= ARM_CP_SECSTATE_NS
,
3096 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
3097 .accessfn
= gt_ptimer_access
,
3098 .fieldoffset
= offsetoflow32(CPUARMState
,
3099 cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
3100 .readfn
= gt_phys_redir_ctl_read
, .raw_readfn
= raw_read
,
3101 .writefn
= gt_phys_redir_ctl_write
, .raw_writefn
= raw_write
,
3103 { .name
= "CNTP_CTL_S",
3104 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
3105 .secure
= ARM_CP_SECSTATE_S
,
3106 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
3107 .accessfn
= gt_ptimer_access
,
3108 .fieldoffset
= offsetoflow32(CPUARMState
,
3109 cp15
.c14_timer
[GTIMER_SEC
].ctl
),
3110 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
3112 { .name
= "CNTP_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
3113 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 1,
3114 .type
= ARM_CP_IO
, .access
= PL0_RW
,
3115 .accessfn
= gt_ptimer_access
,
3116 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
3118 .readfn
= gt_phys_redir_ctl_read
, .raw_readfn
= raw_read
,
3119 .writefn
= gt_phys_redir_ctl_write
, .raw_writefn
= raw_write
,
3121 { .name
= "CNTV_CTL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 1,
3122 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL0_RW
,
3123 .accessfn
= gt_vtimer_access
,
3124 .fieldoffset
= offsetoflow32(CPUARMState
,
3125 cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
3126 .readfn
= gt_virt_redir_ctl_read
, .raw_readfn
= raw_read
,
3127 .writefn
= gt_virt_redir_ctl_write
, .raw_writefn
= raw_write
,
3129 { .name
= "CNTV_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
3130 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 1,
3131 .type
= ARM_CP_IO
, .access
= PL0_RW
,
3132 .accessfn
= gt_vtimer_access
,
3133 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
3135 .readfn
= gt_virt_redir_ctl_read
, .raw_readfn
= raw_read
,
3136 .writefn
= gt_virt_redir_ctl_write
, .raw_writefn
= raw_write
,
3138 /* TimerValue views: a 32 bit downcounting view of the underlying state */
3139 { .name
= "CNTP_TVAL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
3140 .secure
= ARM_CP_SECSTATE_NS
,
3141 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3142 .accessfn
= gt_ptimer_access
,
3143 .readfn
= gt_phys_redir_tval_read
, .writefn
= gt_phys_redir_tval_write
,
3145 { .name
= "CNTP_TVAL_S",
3146 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
3147 .secure
= ARM_CP_SECSTATE_S
,
3148 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3149 .accessfn
= gt_ptimer_access
,
3150 .readfn
= gt_sec_tval_read
, .writefn
= gt_sec_tval_write
,
3152 { .name
= "CNTP_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3153 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 0,
3154 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3155 .accessfn
= gt_ptimer_access
, .resetfn
= gt_phys_timer_reset
,
3156 .readfn
= gt_phys_redir_tval_read
, .writefn
= gt_phys_redir_tval_write
,
3158 { .name
= "CNTV_TVAL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 0,
3159 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3160 .accessfn
= gt_vtimer_access
,
3161 .readfn
= gt_virt_redir_tval_read
, .writefn
= gt_virt_redir_tval_write
,
3163 { .name
= "CNTV_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3164 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 0,
3165 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL0_RW
,
3166 .accessfn
= gt_vtimer_access
, .resetfn
= gt_virt_timer_reset
,
3167 .readfn
= gt_virt_redir_tval_read
, .writefn
= gt_virt_redir_tval_write
,
3169 /* The counter itself */
3170 { .name
= "CNTPCT", .cp
= 15, .crm
= 14, .opc1
= 0,
3171 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3172 .accessfn
= gt_pct_access
,
3173 .readfn
= gt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3175 { .name
= "CNTPCT_EL0", .state
= ARM_CP_STATE_AA64
,
3176 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 1,
3177 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3178 .accessfn
= gt_pct_access
, .readfn
= gt_cnt_read
,
3180 { .name
= "CNTVCT", .cp
= 15, .crm
= 14, .opc1
= 1,
3181 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
3182 .accessfn
= gt_vct_access
,
3183 .readfn
= gt_virt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
3185 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
3186 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
3187 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3188 .accessfn
= gt_vct_access
, .readfn
= gt_virt_cnt_read
,
3190 /* Comparison value, indicating when the timer goes off */
3191 { .name
= "CNTP_CVAL", .cp
= 15, .crm
= 14, .opc1
= 2,
3192 .secure
= ARM_CP_SECSTATE_NS
,
3194 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3195 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
3196 .accessfn
= gt_ptimer_access
,
3197 .readfn
= gt_phys_redir_cval_read
, .raw_readfn
= raw_read
,
3198 .writefn
= gt_phys_redir_cval_write
, .raw_writefn
= raw_write
,
3200 { .name
= "CNTP_CVAL_S", .cp
= 15, .crm
= 14, .opc1
= 2,
3201 .secure
= ARM_CP_SECSTATE_S
,
3203 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3204 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
3205 .accessfn
= gt_ptimer_access
,
3206 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
3208 { .name
= "CNTP_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3209 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 2,
3212 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
3213 .resetvalue
= 0, .accessfn
= gt_ptimer_access
,
3214 .readfn
= gt_phys_redir_cval_read
, .raw_readfn
= raw_read
,
3215 .writefn
= gt_phys_redir_cval_write
, .raw_writefn
= raw_write
,
3217 { .name
= "CNTV_CVAL", .cp
= 15, .crm
= 14, .opc1
= 3,
3219 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
3220 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
3221 .accessfn
= gt_vtimer_access
,
3222 .readfn
= gt_virt_redir_cval_read
, .raw_readfn
= raw_read
,
3223 .writefn
= gt_virt_redir_cval_write
, .raw_writefn
= raw_write
,
3225 { .name
= "CNTV_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
3226 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 2,
3229 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
3230 .resetvalue
= 0, .accessfn
= gt_vtimer_access
,
3231 .readfn
= gt_virt_redir_cval_read
, .raw_readfn
= raw_read
,
3232 .writefn
= gt_virt_redir_cval_write
, .raw_writefn
= raw_write
,
3235 * Secure timer -- this is actually restricted to only EL3
3236 * and configurably Secure-EL1 via the accessfn.
3238 { .name
= "CNTPS_TVAL_EL1", .state
= ARM_CP_STATE_AA64
,
3239 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 0,
3240 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
,
3241 .accessfn
= gt_stimer_access
,
3242 .readfn
= gt_sec_tval_read
,
3243 .writefn
= gt_sec_tval_write
,
3244 .resetfn
= gt_sec_timer_reset
,
3246 { .name
= "CNTPS_CTL_EL1", .state
= ARM_CP_STATE_AA64
,
3247 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 1,
3248 .type
= ARM_CP_IO
, .access
= PL1_RW
,
3249 .accessfn
= gt_stimer_access
,
3250 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].ctl
),
3252 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
3254 { .name
= "CNTPS_CVAL_EL1", .state
= ARM_CP_STATE_AA64
,
3255 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 2,
3256 .type
= ARM_CP_IO
, .access
= PL1_RW
,
3257 .accessfn
= gt_stimer_access
,
3258 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
3259 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
3263 static CPAccessResult
e2h_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3266 if (!(arm_hcr_el2_eff(env
) & HCR_E2H
)) {
3267 return CP_ACCESS_TRAP
;
3269 return CP_ACCESS_OK
;
3275 * In user-mode most of the generic timer registers are inaccessible
3276 * however modern kernels (4.12+) allow access to cntvct_el0
3279 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3281 ARMCPU
*cpu
= env_archcpu(env
);
3284 * Currently we have no support for QEMUTimer in linux-user so we
3285 * can't call gt_get_countervalue(env), instead we directly
3286 * call the lower level functions.
3288 return cpu_get_clock() / gt_cntfrq_period_ns(cpu
);
3291 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
3292 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
3293 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
3294 .type
= ARM_CP_CONST
, .access
= PL0_R
/* no PL1_RW in linux-user */,
3295 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
3296 .resetvalue
= NANOSECONDS_PER_SECOND
/ GTIMER_SCALE
,
3298 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
3299 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
3300 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
3301 .readfn
= gt_virt_cnt_read
,
3307 static void par_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
3309 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3310 raw_write(env
, ri
, value
);
3311 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
3312 raw_write(env
, ri
, value
& 0xfffff6ff);
3314 raw_write(env
, ri
, value
& 0xfffff1ff);
3318 #ifndef CONFIG_USER_ONLY
3319 /* get_phys_addr() isn't present for user-mode-only targets */
3321 static CPAccessResult
ats_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3326 * The ATS12NSO* operations must trap to EL3 or EL2 if executed in
3327 * Secure EL1 (which can only happen if EL3 is AArch64).
3328 * They are simply UNDEF if executed from NS EL1.
3329 * They function normally from EL2 or EL3.
3331 if (arm_current_el(env
) == 1) {
3332 if (arm_is_secure_below_el3(env
)) {
3333 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
3334 return CP_ACCESS_TRAP_EL2
;
3336 return CP_ACCESS_TRAP_EL3
;
3338 return CP_ACCESS_TRAP_UNCATEGORIZED
;
3341 return CP_ACCESS_OK
;
3345 static int par_el1_shareability(GetPhysAddrResult
*res
)
3348 * The PAR_EL1.SH field must be 0b10 for Device or Normal-NC
3349 * memory -- see pseudocode PAREncodeShareability().
3351 if (((res
->cacheattrs
.attrs
& 0xf0) == 0) ||
3352 res
->cacheattrs
.attrs
== 0x44 || res
->cacheattrs
.attrs
== 0x40) {
3355 return res
->cacheattrs
.shareability
;
3358 static uint64_t do_ats_write(CPUARMState
*env
, uint64_t value
,
3359 MMUAccessType access_type
, ARMMMUIdx mmu_idx
,
3364 bool format64
= false;
3365 ARMMMUFaultInfo fi
= {};
3366 GetPhysAddrResult res
= {};
3369 * I_MXTJT: Granule protection checks are not performed on the final address
3370 * of a successful translation.
3372 ret
= get_phys_addr_with_secure_nogpc(env
, value
, access_type
, mmu_idx
,
3373 is_secure
, &res
, &fi
);
3376 * ATS operations only do S1 or S1+S2 translations, so we never
3377 * have to deal with the ARMCacheAttrs format for S2 only.
3379 assert(!res
.cacheattrs
.is_s2_format
);
3383 * Some kinds of translation fault must cause exceptions rather
3384 * than being reported in the PAR.
3386 int current_el
= arm_current_el(env
);
3388 uint32_t syn
, fsr
, fsc
;
3389 bool take_exc
= false;
3391 if (fi
.s1ptw
&& current_el
== 1
3392 && arm_mmu_idx_is_stage1_of_2(mmu_idx
)) {
3394 * Synchronous stage 2 fault on an access made as part of the
3395 * translation table walk for AT S1E0* or AT S1E1* insn
3396 * executed from NS EL1. If this is a synchronous external abort
3397 * and SCR_EL3.EA == 1, then we take a synchronous external abort
3398 * to EL3. Otherwise the fault is taken as an exception to EL2,
3399 * and HPFAR_EL2 holds the faulting IPA.
3401 if (fi
.type
== ARMFault_SyncExternalOnWalk
&&
3402 (env
->cp15
.scr_el3
& SCR_EA
)) {
3405 env
->cp15
.hpfar_el2
= extract64(fi
.s2addr
, 12, 47) << 4;
3406 if (arm_is_secure_below_el3(env
) && fi
.s1ns
) {
3407 env
->cp15
.hpfar_el2
|= HPFAR_NS
;
3412 } else if (fi
.type
== ARMFault_SyncExternalOnWalk
) {
3414 * Synchronous external aborts during a translation table walk
3415 * are taken as Data Abort exceptions.
3418 if (current_el
== 3) {
3424 target_el
= exception_target_el(env
);
3430 /* Construct FSR and FSC using same logic as arm_deliver_fault() */
3431 if (target_el
== 2 || arm_el_is_aa64(env
, target_el
) ||
3432 arm_s1_regime_using_lpae_format(env
, mmu_idx
)) {
3433 fsr
= arm_fi_to_lfsc(&fi
);
3434 fsc
= extract32(fsr
, 0, 6);
3436 fsr
= arm_fi_to_sfsc(&fi
);
3440 * Report exception with ESR indicating a fault due to a
3441 * translation table walk for a cache maintenance instruction.
3443 syn
= syn_data_abort_no_iss(current_el
== target_el
, 0,
3444 fi
.ea
, 1, fi
.s1ptw
, 1, fsc
);
3445 env
->exception
.vaddress
= value
;
3446 env
->exception
.fsr
= fsr
;
3447 raise_exception(env
, EXCP_DATA_ABORT
, syn
, target_el
);
3453 } else if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
3456 * * TTBCR.EAE determines whether the result is returned using the
3457 * 32-bit or the 64-bit PAR format
3458 * * Instructions executed in Hyp mode always use the 64bit format
3460 * ATS1S2NSOxx uses the 64bit format if any of the following is true:
3461 * * The Non-secure TTBCR.EAE bit is set to 1
3462 * * The implementation includes EL2, and the value of HCR.VM is 1
3464 * (Note that HCR.DC makes HCR.VM behave as if it is 1.)
3466 * ATS1Hx always uses the 64bit format.
3468 format64
= arm_s1_regime_using_lpae_format(env
, mmu_idx
);
3470 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
3471 if (mmu_idx
== ARMMMUIdx_E10_0
||
3472 mmu_idx
== ARMMMUIdx_E10_1
||
3473 mmu_idx
== ARMMMUIdx_E10_1_PAN
) {
3474 format64
|= env
->cp15
.hcr_el2
& (HCR_VM
| HCR_DC
);
3476 format64
|= arm_current_el(env
) == 2;
3482 /* Create a 64-bit PAR */
3483 par64
= (1 << 11); /* LPAE bit always set */
3485 par64
|= res
.f
.phys_addr
& ~0xfffULL
;
3486 if (!res
.f
.attrs
.secure
) {
3487 par64
|= (1 << 9); /* NS */
3489 par64
|= (uint64_t)res
.cacheattrs
.attrs
<< 56; /* ATTR */
3490 par64
|= par_el1_shareability(&res
) << 7; /* SH */
3492 uint32_t fsr
= arm_fi_to_lfsc(&fi
);
3495 par64
|= (fsr
& 0x3f) << 1; /* FS */
3497 par64
|= (1 << 9); /* S */
3500 par64
|= (1 << 8); /* PTW */
3505 * fsr is a DFSR/IFSR value for the short descriptor
3506 * translation table format (with WnR always clear).
3507 * Convert it to a 32-bit PAR.
3510 /* We do not set any attribute bits in the PAR */
3511 if (res
.f
.lg_page_size
== 24
3512 && arm_feature(env
, ARM_FEATURE_V7
)) {
3513 par64
= (res
.f
.phys_addr
& 0xff000000) | (1 << 1);
3515 par64
= res
.f
.phys_addr
& 0xfffff000;
3517 if (!res
.f
.attrs
.secure
) {
3518 par64
|= (1 << 9); /* NS */
3521 uint32_t fsr
= arm_fi_to_sfsc(&fi
);
3523 par64
= ((fsr
& (1 << 10)) >> 5) | ((fsr
& (1 << 12)) >> 6) |
3524 ((fsr
& 0xf) << 1) | 1;
3529 #endif /* CONFIG_TCG */
3531 static void ats_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
3534 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3537 int el
= arm_current_el(env
);
3538 bool secure
= arm_is_secure_below_el3(env
);
3540 switch (ri
->opc2
& 6) {
3542 /* stage 1 current state PL1: ATS1CPR, ATS1CPW, ATS1CPRP, ATS1CPWP */
3545 mmu_idx
= ARMMMUIdx_E3
;
3549 g_assert(!secure
); /* ARMv8.4-SecEL2 is 64-bit only */
3552 if (ri
->crm
== 9 && (env
->uncached_cpsr
& CPSR_PAN
)) {
3553 mmu_idx
= ARMMMUIdx_Stage1_E1_PAN
;
3555 mmu_idx
= ARMMMUIdx_Stage1_E1
;
3559 g_assert_not_reached();
3563 /* stage 1 current state PL0: ATS1CUR, ATS1CUW */
3566 mmu_idx
= ARMMMUIdx_E10_0
;
3570 g_assert(!secure
); /* ARMv8.4-SecEL2 is 64-bit only */
3571 mmu_idx
= ARMMMUIdx_Stage1_E0
;
3574 mmu_idx
= ARMMMUIdx_Stage1_E0
;
3577 g_assert_not_reached();
3581 /* stage 1+2 NonSecure PL1: ATS12NSOPR, ATS12NSOPW */
3582 mmu_idx
= ARMMMUIdx_E10_1
;
3586 /* stage 1+2 NonSecure PL0: ATS12NSOUR, ATS12NSOUW */
3587 mmu_idx
= ARMMMUIdx_E10_0
;
3591 g_assert_not_reached();
3594 par64
= do_ats_write(env
, value
, access_type
, mmu_idx
, secure
);
3596 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
3598 /* Handled by hardware accelerator. */
3599 g_assert_not_reached();
3600 #endif /* CONFIG_TCG */
3603 static void ats1h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3607 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3610 /* There is no SecureEL2 for AArch32. */
3611 par64
= do_ats_write(env
, value
, access_type
, ARMMMUIdx_E2
, false);
3613 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
3615 /* Handled by hardware accelerator. */
3616 g_assert_not_reached();
3617 #endif /* CONFIG_TCG */
3620 static CPAccessResult
at_s1e2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3623 if (arm_current_el(env
) == 3 &&
3624 !(env
->cp15
.scr_el3
& (SCR_NS
| SCR_EEL2
))) {
3625 return CP_ACCESS_TRAP
;
3627 return CP_ACCESS_OK
;
3630 static void ats_write64(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3634 MMUAccessType access_type
= ri
->opc2
& 1 ? MMU_DATA_STORE
: MMU_DATA_LOAD
;
3636 int secure
= arm_is_secure_below_el3(env
);
3637 uint64_t hcr_el2
= arm_hcr_el2_eff(env
);
3638 bool regime_e20
= (hcr_el2
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
);
3640 switch (ri
->opc2
& 6) {
3643 case 0: /* AT S1E1R, AT S1E1W, AT S1E1RP, AT S1E1WP */
3644 if (ri
->crm
== 9 && (env
->pstate
& PSTATE_PAN
)) {
3645 mmu_idx
= regime_e20
?
3646 ARMMMUIdx_E20_2_PAN
: ARMMMUIdx_Stage1_E1_PAN
;
3648 mmu_idx
= regime_e20
? ARMMMUIdx_E20_2
: ARMMMUIdx_Stage1_E1
;
3651 case 4: /* AT S1E2R, AT S1E2W */
3652 mmu_idx
= hcr_el2
& HCR_E2H
? ARMMMUIdx_E20_2
: ARMMMUIdx_E2
;
3654 case 6: /* AT S1E3R, AT S1E3W */
3655 mmu_idx
= ARMMMUIdx_E3
;
3659 g_assert_not_reached();
3662 case 2: /* AT S1E0R, AT S1E0W */
3663 mmu_idx
= regime_e20
? ARMMMUIdx_E20_0
: ARMMMUIdx_Stage1_E0
;
3665 case 4: /* AT S12E1R, AT S12E1W */
3666 mmu_idx
= regime_e20
? ARMMMUIdx_E20_2
: ARMMMUIdx_E10_1
;
3668 case 6: /* AT S12E0R, AT S12E0W */
3669 mmu_idx
= regime_e20
? ARMMMUIdx_E20_0
: ARMMMUIdx_E10_0
;
3672 g_assert_not_reached();
3675 env
->cp15
.par_el
[1] = do_ats_write(env
, value
, access_type
,
3678 /* Handled by hardware accelerator. */
3679 g_assert_not_reached();
3680 #endif /* CONFIG_TCG */
3684 static const ARMCPRegInfo vapa_cp_reginfo
[] = {
3685 { .name
= "PAR", .cp
= 15, .crn
= 7, .crm
= 4, .opc1
= 0, .opc2
= 0,
3686 .access
= PL1_RW
, .resetvalue
= 0,
3687 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.par_s
),
3688 offsetoflow32(CPUARMState
, cp15
.par_ns
) },
3689 .writefn
= par_write
},
3690 #ifndef CONFIG_USER_ONLY
3691 /* This underdecoding is safe because the reginfo is NO_RAW. */
3692 { .name
= "ATS", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= CP_ANY
,
3693 .access
= PL1_W
, .accessfn
= ats_access
,
3694 .writefn
= ats_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
3698 /* Return basic MPU access permission bits. */
3699 static uint32_t simple_mpu_ap_bits(uint32_t val
)
3706 for (i
= 0; i
< 16; i
+= 2) {
3707 ret
|= (val
>> i
) & mask
;
3713 /* Pad basic MPU access permission bits to extended format. */
3714 static uint32_t extended_mpu_ap_bits(uint32_t val
)
3721 for (i
= 0; i
< 16; i
+= 2) {
3722 ret
|= (val
& mask
) << i
;
3728 static void pmsav5_data_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3731 env
->cp15
.pmsav5_data_ap
= extended_mpu_ap_bits(value
);
3734 static uint64_t pmsav5_data_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3736 return simple_mpu_ap_bits(env
->cp15
.pmsav5_data_ap
);
3739 static void pmsav5_insn_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3742 env
->cp15
.pmsav5_insn_ap
= extended_mpu_ap_bits(value
);
3745 static uint64_t pmsav5_insn_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3747 return simple_mpu_ap_bits(env
->cp15
.pmsav5_insn_ap
);
3750 static uint64_t pmsav7_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3752 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
3758 u32p
+= env
->pmsav7
.rnr
[M_REG_NS
];
3762 static void pmsav7_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3765 ARMCPU
*cpu
= env_archcpu(env
);
3766 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
3772 u32p
+= env
->pmsav7
.rnr
[M_REG_NS
];
3773 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
3777 static void pmsav7_rgnr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3780 ARMCPU
*cpu
= env_archcpu(env
);
3781 uint32_t nrgs
= cpu
->pmsav7_dregion
;
3783 if (value
>= nrgs
) {
3784 qemu_log_mask(LOG_GUEST_ERROR
,
3785 "PMSAv7 RGNR write >= # supported regions, %" PRIu32
3786 " > %" PRIu32
"\n", (uint32_t)value
, nrgs
);
3790 raw_write(env
, ri
, value
);
3793 static void prbar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3796 ARMCPU
*cpu
= env_archcpu(env
);
3798 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
3799 env
->pmsav8
.rbar
[M_REG_NS
][env
->pmsav7
.rnr
[M_REG_NS
]] = value
;
3802 static uint64_t prbar_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3804 return env
->pmsav8
.rbar
[M_REG_NS
][env
->pmsav7
.rnr
[M_REG_NS
]];
3807 static void prlar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3810 ARMCPU
*cpu
= env_archcpu(env
);
3812 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
3813 env
->pmsav8
.rlar
[M_REG_NS
][env
->pmsav7
.rnr
[M_REG_NS
]] = value
;
3816 static uint64_t prlar_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3818 return env
->pmsav8
.rlar
[M_REG_NS
][env
->pmsav7
.rnr
[M_REG_NS
]];
3821 static void prselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3824 ARMCPU
*cpu
= env_archcpu(env
);
3827 * Ignore writes that would select not implemented region.
3828 * This is architecturally UNPREDICTABLE.
3830 if (value
>= cpu
->pmsav7_dregion
) {
3834 env
->pmsav7
.rnr
[M_REG_NS
] = value
;
3837 static void hprbar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3840 ARMCPU
*cpu
= env_archcpu(env
);
3842 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
3843 env
->pmsav8
.hprbar
[env
->pmsav8
.hprselr
] = value
;
3846 static uint64_t hprbar_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3848 return env
->pmsav8
.hprbar
[env
->pmsav8
.hprselr
];
3851 static void hprlar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3854 ARMCPU
*cpu
= env_archcpu(env
);
3856 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
3857 env
->pmsav8
.hprlar
[env
->pmsav8
.hprselr
] = value
;
3860 static uint64_t hprlar_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3862 return env
->pmsav8
.hprlar
[env
->pmsav8
.hprselr
];
3865 static void hprenr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3870 ARMCPU
*cpu
= env_archcpu(env
);
3872 /* Ignore writes to unimplemented regions */
3873 int rmax
= MIN(cpu
->pmsav8r_hdregion
, 32);
3874 value
&= MAKE_64BIT_MASK(0, rmax
);
3876 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
3878 /* Register alias is only valid for first 32 indexes */
3879 for (n
= 0; n
< rmax
; ++n
) {
3880 bit
= extract32(value
, n
, 1);
3881 env
->pmsav8
.hprlar
[n
] = deposit32(
3882 env
->pmsav8
.hprlar
[n
], 0, 1, bit
);
3886 static uint64_t hprenr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3889 uint32_t result
= 0x0;
3890 ARMCPU
*cpu
= env_archcpu(env
);
3892 /* Register alias is only valid for first 32 indexes */
3893 for (n
= 0; n
< MIN(cpu
->pmsav8r_hdregion
, 32); ++n
) {
3894 if (env
->pmsav8
.hprlar
[n
] & 0x1) {
3895 result
|= (0x1 << n
);
3901 static void hprselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3904 ARMCPU
*cpu
= env_archcpu(env
);
3907 * Ignore writes that would select not implemented region.
3908 * This is architecturally UNPREDICTABLE.
3910 if (value
>= cpu
->pmsav8r_hdregion
) {
3914 env
->pmsav8
.hprselr
= value
;
3917 static void pmsav8r_regn_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3920 ARMCPU
*cpu
= env_archcpu(env
);
3921 uint8_t index
= (extract32(ri
->opc0
, 0, 1) << 4) |
3922 (extract32(ri
->crm
, 0, 3) << 1) | extract32(ri
->opc2
, 2, 1);
3924 tlb_flush(CPU(cpu
)); /* Mappings may have changed - purge! */
3927 if (index
>= cpu
->pmsav8r_hdregion
) {
3930 if (ri
->opc2
& 0x1) {
3931 env
->pmsav8
.hprlar
[index
] = value
;
3933 env
->pmsav8
.hprbar
[index
] = value
;
3936 if (index
>= cpu
->pmsav7_dregion
) {
3939 if (ri
->opc2
& 0x1) {
3940 env
->pmsav8
.rlar
[M_REG_NS
][index
] = value
;
3942 env
->pmsav8
.rbar
[M_REG_NS
][index
] = value
;
3947 static uint64_t pmsav8r_regn_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3949 ARMCPU
*cpu
= env_archcpu(env
);
3950 uint8_t index
= (extract32(ri
->opc0
, 0, 1) << 4) |
3951 (extract32(ri
->crm
, 0, 3) << 1) | extract32(ri
->opc2
, 2, 1);
3954 if (index
>= cpu
->pmsav8r_hdregion
) {
3957 if (ri
->opc2
& 0x1) {
3958 return env
->pmsav8
.hprlar
[index
];
3960 return env
->pmsav8
.hprbar
[index
];
3963 if (index
>= cpu
->pmsav7_dregion
) {
3966 if (ri
->opc2
& 0x1) {
3967 return env
->pmsav8
.rlar
[M_REG_NS
][index
];
3969 return env
->pmsav8
.rbar
[M_REG_NS
][index
];
3974 static const ARMCPRegInfo pmsav8r_cp_reginfo
[] = {
3976 .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 3, .opc2
= 0,
3977 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
3978 .accessfn
= access_tvm_trvm
,
3979 .readfn
= prbar_read
, .writefn
= prbar_write
},
3981 .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 3, .opc2
= 1,
3982 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
3983 .accessfn
= access_tvm_trvm
,
3984 .readfn
= prlar_read
, .writefn
= prlar_write
},
3985 { .name
= "PRSELR", .resetvalue
= 0,
3986 .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 2, .opc2
= 1,
3987 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
3988 .writefn
= prselr_write
,
3989 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.rnr
[M_REG_NS
]) },
3990 { .name
= "HPRBAR", .resetvalue
= 0,
3991 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 3, .opc2
= 0,
3992 .access
= PL2_RW
, .type
= ARM_CP_NO_RAW
,
3993 .readfn
= hprbar_read
, .writefn
= hprbar_write
},
3995 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 3, .opc2
= 1,
3996 .access
= PL2_RW
, .type
= ARM_CP_NO_RAW
,
3997 .readfn
= hprlar_read
, .writefn
= hprlar_write
},
3998 { .name
= "HPRSELR", .resetvalue
= 0,
3999 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 2, .opc2
= 1,
4001 .writefn
= hprselr_write
,
4002 .fieldoffset
= offsetof(CPUARMState
, pmsav8
.hprselr
) },
4004 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 1, .opc2
= 1,
4005 .access
= PL2_RW
, .type
= ARM_CP_NO_RAW
,
4006 .readfn
= hprenr_read
, .writefn
= hprenr_write
},
4009 static const ARMCPRegInfo pmsav7_cp_reginfo
[] = {
4011 * Reset for all these registers is handled in arm_cpu_reset(),
4012 * because the PMSAv7 is also used by M-profile CPUs, which do
4013 * not register cpregs but still need the state to be reset.
4015 { .name
= "DRBAR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 0,
4016 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
4017 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drbar
),
4018 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
4019 .resetfn
= arm_cp_reset_ignore
},
4020 { .name
= "DRSR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 2,
4021 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
4022 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drsr
),
4023 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
4024 .resetfn
= arm_cp_reset_ignore
},
4025 { .name
= "DRACR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 4,
4026 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
4027 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.dracr
),
4028 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
,
4029 .resetfn
= arm_cp_reset_ignore
},
4030 { .name
= "RGNR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 2, .opc2
= 0,
4032 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.rnr
[M_REG_NS
]),
4033 .writefn
= pmsav7_rgnr_write
,
4034 .resetfn
= arm_cp_reset_ignore
},
4037 static const ARMCPRegInfo pmsav5_cp_reginfo
[] = {
4038 { .name
= "DATA_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
4039 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
4040 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
4041 .readfn
= pmsav5_data_ap_read
, .writefn
= pmsav5_data_ap_write
, },
4042 { .name
= "INSN_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
4043 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
4044 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
4045 .readfn
= pmsav5_insn_ap_read
, .writefn
= pmsav5_insn_ap_write
, },
4046 { .name
= "DATA_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 2,
4048 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
4050 { .name
= "INSN_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 3,
4052 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
4054 { .name
= "DCACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 0,
4056 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_data
), .resetvalue
= 0, },
4057 { .name
= "ICACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 1,
4059 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_insn
), .resetvalue
= 0, },
4060 /* Protection region base and size registers */
4061 { .name
= "946_PRBS0", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0,
4062 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4063 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[0]) },
4064 { .name
= "946_PRBS1", .cp
= 15, .crn
= 6, .crm
= 1, .opc1
= 0,
4065 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4066 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[1]) },
4067 { .name
= "946_PRBS2", .cp
= 15, .crn
= 6, .crm
= 2, .opc1
= 0,
4068 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4069 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[2]) },
4070 { .name
= "946_PRBS3", .cp
= 15, .crn
= 6, .crm
= 3, .opc1
= 0,
4071 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4072 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[3]) },
4073 { .name
= "946_PRBS4", .cp
= 15, .crn
= 6, .crm
= 4, .opc1
= 0,
4074 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4075 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[4]) },
4076 { .name
= "946_PRBS5", .cp
= 15, .crn
= 6, .crm
= 5, .opc1
= 0,
4077 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4078 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[5]) },
4079 { .name
= "946_PRBS6", .cp
= 15, .crn
= 6, .crm
= 6, .opc1
= 0,
4080 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4081 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[6]) },
4082 { .name
= "946_PRBS7", .cp
= 15, .crn
= 6, .crm
= 7, .opc1
= 0,
4083 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
4084 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[7]) },
4087 static void vmsa_ttbcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4090 ARMCPU
*cpu
= env_archcpu(env
);
4092 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
4093 if (arm_feature(env
, ARM_FEATURE_LPAE
) && (value
& TTBCR_EAE
)) {
4095 * Pre ARMv8 bits [21:19], [15:14] and [6:3] are UNK/SBZP when
4096 * using Long-descriptor translation table format
4098 value
&= ~((7 << 19) | (3 << 14) | (0xf << 3));
4099 } else if (arm_feature(env
, ARM_FEATURE_EL3
)) {
4101 * In an implementation that includes the Security Extensions
4102 * TTBCR has additional fields PD0 [4] and PD1 [5] for
4103 * Short-descriptor translation table format.
4105 value
&= TTBCR_PD1
| TTBCR_PD0
| TTBCR_N
;
4111 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
4113 * With LPAE the TTBCR could result in a change of ASID
4114 * via the TTBCR.A1 bit, so do a TLB flush.
4116 tlb_flush(CPU(cpu
));
4118 raw_write(env
, ri
, value
);
4121 static void vmsa_tcr_el12_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4124 ARMCPU
*cpu
= env_archcpu(env
);
4126 /* For AArch64 the A1 bit could result in a change of ASID, so TLB flush. */
4127 tlb_flush(CPU(cpu
));
4128 raw_write(env
, ri
, value
);
4131 static void vmsa_ttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4134 /* If the ASID changes (with a 64-bit write), we must flush the TLB. */
4135 if (cpreg_field_is_64bit(ri
) &&
4136 extract64(raw_read(env
, ri
) ^ value
, 48, 16) != 0) {
4137 ARMCPU
*cpu
= env_archcpu(env
);
4138 tlb_flush(CPU(cpu
));
4140 raw_write(env
, ri
, value
);
4143 static void vmsa_tcr_ttbr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4147 * If we are running with E2&0 regime, then an ASID is active.
4148 * Flush if that might be changing. Note we're not checking
4149 * TCR_EL2.A1 to know if this is really the TTBRx_EL2 that
4150 * holds the active ASID, only checking the field that might.
4152 if (extract64(raw_read(env
, ri
) ^ value
, 48, 16) &&
4153 (arm_hcr_el2_eff(env
) & HCR_E2H
)) {
4154 uint16_t mask
= ARMMMUIdxBit_E20_2
|
4155 ARMMMUIdxBit_E20_2_PAN
|
4157 tlb_flush_by_mmuidx(env_cpu(env
), mask
);
4159 raw_write(env
, ri
, value
);
4162 static void vttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4165 ARMCPU
*cpu
= env_archcpu(env
);
4166 CPUState
*cs
= CPU(cpu
);
4169 * A change in VMID to the stage2 page table (Stage2) invalidates
4170 * the stage2 and combined stage 1&2 tlbs (EL10_1 and EL10_0).
4172 if (extract64(raw_read(env
, ri
) ^ value
, 48, 16) != 0) {
4173 tlb_flush_by_mmuidx(cs
, alle1_tlbmask(env
));
4175 raw_write(env
, ri
, value
);
4178 static const ARMCPRegInfo vmsa_pmsa_cp_reginfo
[] = {
4179 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
4180 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .type
= ARM_CP_ALIAS
,
4181 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dfsr_s
),
4182 offsetoflow32(CPUARMState
, cp15
.dfsr_ns
) }, },
4183 { .name
= "IFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
4184 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
4185 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.ifsr_s
),
4186 offsetoflow32(CPUARMState
, cp15
.ifsr_ns
) } },
4187 { .name
= "DFAR", .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 0, .opc2
= 0,
4188 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
4189 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.dfar_s
),
4190 offsetof(CPUARMState
, cp15
.dfar_ns
) } },
4191 { .name
= "FAR_EL1", .state
= ARM_CP_STATE_AA64
,
4192 .opc0
= 3, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 0,
4193 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4195 .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[1]),
4199 static const ARMCPRegInfo vmsa_cp_reginfo
[] = {
4200 { .name
= "ESR_EL1", .state
= ARM_CP_STATE_AA64
,
4201 .opc0
= 3, .crn
= 5, .crm
= 2, .opc1
= 0, .opc2
= 0,
4202 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4204 .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[1]), .resetvalue
= 0, },
4205 { .name
= "TTBR0_EL1", .state
= ARM_CP_STATE_BOTH
,
4206 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 0,
4207 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4208 .fgt
= FGT_TTBR0_EL1
,
4209 .writefn
= vmsa_ttbr_write
, .resetvalue
= 0, .raw_writefn
= raw_write
,
4210 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
4211 offsetof(CPUARMState
, cp15
.ttbr0_ns
) } },
4212 { .name
= "TTBR1_EL1", .state
= ARM_CP_STATE_BOTH
,
4213 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 1,
4214 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4215 .fgt
= FGT_TTBR1_EL1
,
4216 .writefn
= vmsa_ttbr_write
, .resetvalue
= 0, .raw_writefn
= raw_write
,
4217 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
4218 offsetof(CPUARMState
, cp15
.ttbr1_ns
) } },
4219 { .name
= "TCR_EL1", .state
= ARM_CP_STATE_AA64
,
4220 .opc0
= 3, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
4221 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4223 .writefn
= vmsa_tcr_el12_write
,
4224 .raw_writefn
= raw_write
,
4226 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[1]) },
4227 { .name
= "TTBCR", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
4228 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4229 .type
= ARM_CP_ALIAS
, .writefn
= vmsa_ttbcr_write
,
4230 .raw_writefn
= raw_write
,
4231 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tcr_el
[3]),
4232 offsetoflow32(CPUARMState
, cp15
.tcr_el
[1])} },
4236 * Note that unlike TTBCR, writing to TTBCR2 does not require flushing
4237 * qemu tlbs nor adjusting cached masks.
4239 static const ARMCPRegInfo ttbcr2_reginfo
= {
4240 .name
= "TTBCR2", .cp
= 15, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 3,
4241 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4242 .type
= ARM_CP_ALIAS
,
4243 .bank_fieldoffsets
= {
4244 offsetofhigh32(CPUARMState
, cp15
.tcr_el
[3]),
4245 offsetofhigh32(CPUARMState
, cp15
.tcr_el
[1]),
4249 static void omap_ticonfig_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4252 env
->cp15
.c15_ticonfig
= value
& 0xe7;
4253 /* The OS_TYPE bit in this register changes the reported CPUID! */
4254 env
->cp15
.c0_cpuid
= (value
& (1 << 5)) ?
4255 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
4258 static void omap_threadid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4261 env
->cp15
.c15_threadid
= value
& 0xffff;
4264 static void omap_wfi_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4267 /* Wait-for-interrupt (deprecated) */
4268 cpu_interrupt(env_cpu(env
), CPU_INTERRUPT_HALT
);
4271 static void omap_cachemaint_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4275 * On OMAP there are registers indicating the max/min index of dcache lines
4276 * containing a dirty line; cache flush operations have to reset these.
4278 env
->cp15
.c15_i_max
= 0x000;
4279 env
->cp15
.c15_i_min
= 0xff0;
4282 static const ARMCPRegInfo omap_cp_reginfo
[] = {
4283 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= CP_ANY
,
4284 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_OVERRIDE
,
4285 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.esr_el
[1]),
4287 { .name
= "", .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 0, .opc2
= 0,
4288 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
4289 { .name
= "TICONFIG", .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0,
4291 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ticonfig
), .resetvalue
= 0,
4292 .writefn
= omap_ticonfig_write
},
4293 { .name
= "IMAX", .cp
= 15, .crn
= 15, .crm
= 2, .opc1
= 0, .opc2
= 0,
4295 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_max
), .resetvalue
= 0, },
4296 { .name
= "IMIN", .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 0, .opc2
= 0,
4297 .access
= PL1_RW
, .resetvalue
= 0xff0,
4298 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_min
) },
4299 { .name
= "THREADID", .cp
= 15, .crn
= 15, .crm
= 4, .opc1
= 0, .opc2
= 0,
4301 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_threadid
), .resetvalue
= 0,
4302 .writefn
= omap_threadid_write
},
4303 { .name
= "TI925T_STATUS", .cp
= 15, .crn
= 15,
4304 .crm
= 8, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
4305 .type
= ARM_CP_NO_RAW
,
4306 .readfn
= arm_cp_read_zero
, .writefn
= omap_wfi_write
, },
4308 * TODO: Peripheral port remap register:
4309 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt controller
4310 * base address at $rn & ~0xfff and map size of 0x200 << ($rn & 0xfff),
4313 { .name
= "OMAP_CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
4314 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
4315 .type
= ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
,
4316 .writefn
= omap_cachemaint_write
},
4317 { .name
= "C9", .cp
= 15, .crn
= 9,
4318 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
,
4319 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
, .resetvalue
= 0 },
4322 static void xscale_cpar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4325 env
->cp15
.c15_cpar
= value
& 0x3fff;
4328 static const ARMCPRegInfo xscale_cp_reginfo
[] = {
4329 { .name
= "XSCALE_CPAR",
4330 .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
4331 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_cpar
), .resetvalue
= 0,
4332 .writefn
= xscale_cpar_write
, },
4333 { .name
= "XSCALE_AUXCR",
4334 .cp
= 15, .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 1, .access
= PL1_RW
,
4335 .fieldoffset
= offsetof(CPUARMState
, cp15
.c1_xscaleauxcr
),
4338 * XScale specific cache-lockdown: since we have no cache we NOP these
4339 * and hope the guest does not really rely on cache behaviour.
4341 { .name
= "XSCALE_LOCK_ICACHE_LINE",
4342 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 0,
4343 .access
= PL1_W
, .type
= ARM_CP_NOP
},
4344 { .name
= "XSCALE_UNLOCK_ICACHE",
4345 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 1,
4346 .access
= PL1_W
, .type
= ARM_CP_NOP
},
4347 { .name
= "XSCALE_DCACHE_LOCK",
4348 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 0,
4349 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
4350 { .name
= "XSCALE_UNLOCK_DCACHE",
4351 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 1,
4352 .access
= PL1_W
, .type
= ARM_CP_NOP
},
4355 static const ARMCPRegInfo dummy_c15_cp_reginfo
[] = {
4357 * RAZ/WI the whole crn=15 space, when we don't have a more specific
4358 * implementation of this implementation-defined space.
4359 * Ideally this should eventually disappear in favour of actually
4360 * implementing the correct behaviour for all cores.
4362 { .name
= "C15_IMPDEF", .cp
= 15, .crn
= 15,
4363 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
4365 .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
| ARM_CP_OVERRIDE
,
4369 static const ARMCPRegInfo cache_dirty_status_cp_reginfo
[] = {
4370 /* Cache status: RAZ because we have no cache so it's always clean */
4371 { .name
= "CDSR", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 6,
4372 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4376 static const ARMCPRegInfo cache_block_ops_cp_reginfo
[] = {
4377 /* We never have a block transfer operation in progress */
4378 { .name
= "BXSR", .cp
= 15, .crn
= 7, .crm
= 12, .opc1
= 0, .opc2
= 4,
4379 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4381 /* The cache ops themselves: these all NOP for QEMU */
4382 { .name
= "IICR", .cp
= 15, .crm
= 5, .opc1
= 0,
4383 .access
= PL1_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4384 { .name
= "IDCR", .cp
= 15, .crm
= 6, .opc1
= 0,
4385 .access
= PL1_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4386 { .name
= "CDCR", .cp
= 15, .crm
= 12, .opc1
= 0,
4387 .access
= PL0_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4388 { .name
= "PIR", .cp
= 15, .crm
= 12, .opc1
= 1,
4389 .access
= PL0_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4390 { .name
= "PDR", .cp
= 15, .crm
= 12, .opc1
= 2,
4391 .access
= PL0_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4392 { .name
= "CIDCR", .cp
= 15, .crm
= 14, .opc1
= 0,
4393 .access
= PL1_W
, .type
= ARM_CP_NOP
| ARM_CP_64BIT
},
4396 static const ARMCPRegInfo cache_test_clean_cp_reginfo
[] = {
4398 * The cache test-and-clean instructions always return (1 << 30)
4399 * to indicate that there are no dirty cache lines.
4401 { .name
= "TC_DCACHE", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 3,
4402 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4403 .resetvalue
= (1 << 30) },
4404 { .name
= "TCI_DCACHE", .cp
= 15, .crn
= 7, .crm
= 14, .opc1
= 0, .opc2
= 3,
4405 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
4406 .resetvalue
= (1 << 30) },
4409 static const ARMCPRegInfo strongarm_cp_reginfo
[] = {
4410 /* Ignore ReadBuffer accesses */
4411 { .name
= "C9_READBUFFER", .cp
= 15, .crn
= 9,
4412 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
4413 .access
= PL1_RW
, .resetvalue
= 0,
4414 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
},
4417 static uint64_t midr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4419 unsigned int cur_el
= arm_current_el(env
);
4421 if (arm_is_el2_enabled(env
) && cur_el
== 1) {
4422 return env
->cp15
.vpidr_el2
;
4424 return raw_read(env
, ri
);
4427 static uint64_t mpidr_read_val(CPUARMState
*env
)
4429 ARMCPU
*cpu
= env_archcpu(env
);
4430 uint64_t mpidr
= cpu
->mp_affinity
;
4432 if (arm_feature(env
, ARM_FEATURE_V7MP
)) {
4433 mpidr
|= (1U << 31);
4435 * Cores which are uniprocessor (non-coherent)
4436 * but still implement the MP extensions set
4437 * bit 30. (For instance, Cortex-R5).
4439 if (cpu
->mp_is_up
) {
4440 mpidr
|= (1u << 30);
4446 static uint64_t mpidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4448 unsigned int cur_el
= arm_current_el(env
);
4450 if (arm_is_el2_enabled(env
) && cur_el
== 1) {
4451 return env
->cp15
.vmpidr_el2
;
4453 return mpidr_read_val(env
);
4456 static const ARMCPRegInfo lpae_cp_reginfo
[] = {
4458 { .name
= "AMAIR0", .state
= ARM_CP_STATE_BOTH
,
4459 .opc0
= 3, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 0,
4460 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4461 .fgt
= FGT_AMAIR_EL1
,
4462 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4463 /* AMAIR1 is mapped to AMAIR_EL1[63:32] */
4464 { .name
= "AMAIR1", .cp
= 15, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 1,
4465 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4466 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4467 { .name
= "PAR", .cp
= 15, .crm
= 7, .opc1
= 0,
4468 .access
= PL1_RW
, .type
= ARM_CP_64BIT
, .resetvalue
= 0,
4469 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.par_s
),
4470 offsetof(CPUARMState
, cp15
.par_ns
)} },
4471 { .name
= "TTBR0", .cp
= 15, .crm
= 2, .opc1
= 0,
4472 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4473 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
4474 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
4475 offsetof(CPUARMState
, cp15
.ttbr0_ns
) },
4476 .writefn
= vmsa_ttbr_write
, .raw_writefn
= raw_write
},
4477 { .name
= "TTBR1", .cp
= 15, .crm
= 2, .opc1
= 1,
4478 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
4479 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
4480 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
4481 offsetof(CPUARMState
, cp15
.ttbr1_ns
) },
4482 .writefn
= vmsa_ttbr_write
, .raw_writefn
= raw_write
},
4485 static uint64_t aa64_fpcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4487 return vfp_get_fpcr(env
);
4490 static void aa64_fpcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4493 vfp_set_fpcr(env
, value
);
4496 static uint64_t aa64_fpsr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4498 return vfp_get_fpsr(env
);
4501 static void aa64_fpsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4504 vfp_set_fpsr(env
, value
);
4507 static CPAccessResult
aa64_daif_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4510 if (arm_current_el(env
) == 0 && !(arm_sctlr(env
, 0) & SCTLR_UMA
)) {
4511 return CP_ACCESS_TRAP
;
4513 return CP_ACCESS_OK
;
4516 static void aa64_daif_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4519 env
->daif
= value
& PSTATE_DAIF
;
4522 static uint64_t aa64_pan_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4524 return env
->pstate
& PSTATE_PAN
;
4527 static void aa64_pan_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4530 env
->pstate
= (env
->pstate
& ~PSTATE_PAN
) | (value
& PSTATE_PAN
);
4533 static const ARMCPRegInfo pan_reginfo
= {
4534 .name
= "PAN", .state
= ARM_CP_STATE_AA64
,
4535 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 3,
4536 .type
= ARM_CP_NO_RAW
, .access
= PL1_RW
,
4537 .readfn
= aa64_pan_read
, .writefn
= aa64_pan_write
4540 static uint64_t aa64_uao_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4542 return env
->pstate
& PSTATE_UAO
;
4545 static void aa64_uao_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4548 env
->pstate
= (env
->pstate
& ~PSTATE_UAO
) | (value
& PSTATE_UAO
);
4551 static const ARMCPRegInfo uao_reginfo
= {
4552 .name
= "UAO", .state
= ARM_CP_STATE_AA64
,
4553 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 4,
4554 .type
= ARM_CP_NO_RAW
, .access
= PL1_RW
,
4555 .readfn
= aa64_uao_read
, .writefn
= aa64_uao_write
4558 static uint64_t aa64_dit_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4560 return env
->pstate
& PSTATE_DIT
;
4563 static void aa64_dit_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4566 env
->pstate
= (env
->pstate
& ~PSTATE_DIT
) | (value
& PSTATE_DIT
);
4569 static const ARMCPRegInfo dit_reginfo
= {
4570 .name
= "DIT", .state
= ARM_CP_STATE_AA64
,
4571 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 5,
4572 .type
= ARM_CP_NO_RAW
, .access
= PL0_RW
,
4573 .readfn
= aa64_dit_read
, .writefn
= aa64_dit_write
4576 static uint64_t aa64_ssbs_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
4578 return env
->pstate
& PSTATE_SSBS
;
4581 static void aa64_ssbs_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4584 env
->pstate
= (env
->pstate
& ~PSTATE_SSBS
) | (value
& PSTATE_SSBS
);
4587 static const ARMCPRegInfo ssbs_reginfo
= {
4588 .name
= "SSBS", .state
= ARM_CP_STATE_AA64
,
4589 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 6,
4590 .type
= ARM_CP_NO_RAW
, .access
= PL0_RW
,
4591 .readfn
= aa64_ssbs_read
, .writefn
= aa64_ssbs_write
4594 static CPAccessResult
aa64_cacheop_poc_access(CPUARMState
*env
,
4595 const ARMCPRegInfo
*ri
,
4598 /* Cache invalidate/clean to Point of Coherency or Persistence... */
4599 switch (arm_current_el(env
)) {
4601 /* ... EL0 must UNDEF unless SCTLR_EL1.UCI is set. */
4602 if (!(arm_sctlr(env
, 0) & SCTLR_UCI
)) {
4603 return CP_ACCESS_TRAP
;
4607 /* ... EL1 must trap to EL2 if HCR_EL2.TPCP is set. */
4608 if (arm_hcr_el2_eff(env
) & HCR_TPCP
) {
4609 return CP_ACCESS_TRAP_EL2
;
4613 return CP_ACCESS_OK
;
4616 static CPAccessResult
do_cacheop_pou_access(CPUARMState
*env
, uint64_t hcrflags
)
4618 /* Cache invalidate/clean to Point of Unification... */
4619 switch (arm_current_el(env
)) {
4621 /* ... EL0 must UNDEF unless SCTLR_EL1.UCI is set. */
4622 if (!(arm_sctlr(env
, 0) & SCTLR_UCI
)) {
4623 return CP_ACCESS_TRAP
;
4627 /* ... EL1 must trap to EL2 if relevant HCR_EL2 flags are set. */
4628 if (arm_hcr_el2_eff(env
) & hcrflags
) {
4629 return CP_ACCESS_TRAP_EL2
;
4633 return CP_ACCESS_OK
;
4636 static CPAccessResult
access_ticab(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4639 return do_cacheop_pou_access(env
, HCR_TICAB
| HCR_TPU
);
4642 static CPAccessResult
access_tocu(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4645 return do_cacheop_pou_access(env
, HCR_TOCU
| HCR_TPU
);
4649 * See: D4.7.2 TLB maintenance requirements and the TLB maintenance instructions
4650 * Page D4-1736 (DDI0487A.b)
4653 static int vae1_tlbmask(CPUARMState
*env
)
4655 uint64_t hcr
= arm_hcr_el2_eff(env
);
4658 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4659 mask
= ARMMMUIdxBit_E20_2
|
4660 ARMMMUIdxBit_E20_2_PAN
|
4663 mask
= ARMMMUIdxBit_E10_1
|
4664 ARMMMUIdxBit_E10_1_PAN
|
4670 static int vae2_tlbmask(CPUARMState
*env
)
4672 uint64_t hcr
= arm_hcr_el2_eff(env
);
4675 if (hcr
& HCR_E2H
) {
4676 mask
= ARMMMUIdxBit_E20_2
|
4677 ARMMMUIdxBit_E20_2_PAN
|
4680 mask
= ARMMMUIdxBit_E2
;
4685 /* Return 56 if TBI is enabled, 64 otherwise. */
4686 static int tlbbits_for_regime(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
4689 uint64_t tcr
= regime_tcr(env
, mmu_idx
);
4690 int tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
4691 int select
= extract64(addr
, 55, 1);
4693 return (tbi
>> select
) & 1 ? 56 : 64;
4696 static int vae1_tlbbits(CPUARMState
*env
, uint64_t addr
)
4698 uint64_t hcr
= arm_hcr_el2_eff(env
);
4701 /* Only the regime of the mmu_idx below is significant. */
4702 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
4703 mmu_idx
= ARMMMUIdx_E20_0
;
4705 mmu_idx
= ARMMMUIdx_E10_0
;
4708 return tlbbits_for_regime(env
, mmu_idx
, addr
);
4711 static int vae2_tlbbits(CPUARMState
*env
, uint64_t addr
)
4713 uint64_t hcr
= arm_hcr_el2_eff(env
);
4717 * Only the regime of the mmu_idx below is significant.
4718 * Regime EL2&0 has two ranges with separate TBI configuration, while EL2
4721 if (hcr
& HCR_E2H
) {
4722 mmu_idx
= ARMMMUIdx_E20_2
;
4724 mmu_idx
= ARMMMUIdx_E2
;
4727 return tlbbits_for_regime(env
, mmu_idx
, addr
);
4730 static void tlbi_aa64_vmalle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4733 CPUState
*cs
= env_cpu(env
);
4734 int mask
= vae1_tlbmask(env
);
4736 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4739 static void tlbi_aa64_vmalle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4742 CPUState
*cs
= env_cpu(env
);
4743 int mask
= vae1_tlbmask(env
);
4745 if (tlb_force_broadcast(env
)) {
4746 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4748 tlb_flush_by_mmuidx(cs
, mask
);
4752 static int e2_tlbmask(CPUARMState
*env
)
4754 return (ARMMMUIdxBit_E20_0
|
4755 ARMMMUIdxBit_E20_2
|
4756 ARMMMUIdxBit_E20_2_PAN
|
4760 static void tlbi_aa64_alle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4763 CPUState
*cs
= env_cpu(env
);
4764 int mask
= alle1_tlbmask(env
);
4766 tlb_flush_by_mmuidx(cs
, mask
);
4769 static void tlbi_aa64_alle2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4772 CPUState
*cs
= env_cpu(env
);
4773 int mask
= e2_tlbmask(env
);
4775 tlb_flush_by_mmuidx(cs
, mask
);
4778 static void tlbi_aa64_alle3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4781 ARMCPU
*cpu
= env_archcpu(env
);
4782 CPUState
*cs
= CPU(cpu
);
4784 tlb_flush_by_mmuidx(cs
, ARMMMUIdxBit_E3
);
4787 static void tlbi_aa64_alle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4790 CPUState
*cs
= env_cpu(env
);
4791 int mask
= alle1_tlbmask(env
);
4793 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4796 static void tlbi_aa64_alle2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4799 CPUState
*cs
= env_cpu(env
);
4800 int mask
= e2_tlbmask(env
);
4802 tlb_flush_by_mmuidx_all_cpus_synced(cs
, mask
);
4805 static void tlbi_aa64_alle3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4808 CPUState
*cs
= env_cpu(env
);
4810 tlb_flush_by_mmuidx_all_cpus_synced(cs
, ARMMMUIdxBit_E3
);
4813 static void tlbi_aa64_vae2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4817 * Invalidate by VA, EL2
4818 * Currently handles both VAE2 and VALE2, since we don't support
4819 * flush-last-level-only.
4821 CPUState
*cs
= env_cpu(env
);
4822 int mask
= vae2_tlbmask(env
);
4823 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4824 int bits
= vae2_tlbbits(env
, pageaddr
);
4826 tlb_flush_page_bits_by_mmuidx(cs
, pageaddr
, mask
, bits
);
4829 static void tlbi_aa64_vae3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4833 * Invalidate by VA, EL3
4834 * Currently handles both VAE3 and VALE3, since we don't support
4835 * flush-last-level-only.
4837 ARMCPU
*cpu
= env_archcpu(env
);
4838 CPUState
*cs
= CPU(cpu
);
4839 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4841 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdxBit_E3
);
4844 static void tlbi_aa64_vae1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4847 CPUState
*cs
= env_cpu(env
);
4848 int mask
= vae1_tlbmask(env
);
4849 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4850 int bits
= vae1_tlbbits(env
, pageaddr
);
4852 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4855 static void tlbi_aa64_vae1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4859 * Invalidate by VA, EL1&0 (AArch64 version).
4860 * Currently handles all of VAE1, VAAE1, VAALE1 and VALE1,
4861 * since we don't support flush-for-specific-ASID-only or
4862 * flush-last-level-only.
4864 CPUState
*cs
= env_cpu(env
);
4865 int mask
= vae1_tlbmask(env
);
4866 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4867 int bits
= vae1_tlbbits(env
, pageaddr
);
4869 if (tlb_force_broadcast(env
)) {
4870 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4872 tlb_flush_page_bits_by_mmuidx(cs
, pageaddr
, mask
, bits
);
4876 static void tlbi_aa64_vae2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4879 CPUState
*cs
= env_cpu(env
);
4880 int mask
= vae2_tlbmask(env
);
4881 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4882 int bits
= vae2_tlbbits(env
, pageaddr
);
4884 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
, bits
);
4887 static void tlbi_aa64_vae3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4890 CPUState
*cs
= env_cpu(env
);
4891 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4892 int bits
= tlbbits_for_regime(env
, ARMMMUIdx_E3
, pageaddr
);
4894 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(cs
, pageaddr
,
4895 ARMMMUIdxBit_E3
, bits
);
4898 static int ipas2e1_tlbmask(CPUARMState
*env
, int64_t value
)
4901 * The MSB of value is the NS field, which only applies if SEL2
4902 * is implemented and SCR_EL3.NS is not set (i.e. in secure mode).
4905 && cpu_isar_feature(aa64_sel2
, env_archcpu(env
))
4906 && arm_is_secure_below_el3(env
)
4907 ? ARMMMUIdxBit_Stage2_S
4908 : ARMMMUIdxBit_Stage2
);
4911 static void tlbi_aa64_ipas2e1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4914 CPUState
*cs
= env_cpu(env
);
4915 int mask
= ipas2e1_tlbmask(env
, value
);
4916 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4918 if (tlb_force_broadcast(env
)) {
4919 tlb_flush_page_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
);
4921 tlb_flush_page_by_mmuidx(cs
, pageaddr
, mask
);
4925 static void tlbi_aa64_ipas2e1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4928 CPUState
*cs
= env_cpu(env
);
4929 int mask
= ipas2e1_tlbmask(env
, value
);
4930 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
4932 tlb_flush_page_by_mmuidx_all_cpus_synced(cs
, pageaddr
, mask
);
4935 #ifdef TARGET_AARCH64
4941 static ARMGranuleSize
tlbi_range_tg_to_gran_size(int tg
)
4944 * Note that the TLBI range TG field encoding differs from both
4945 * TG0 and TG1 encodings.
4959 static TLBIRange
tlbi_aa64_get_range(CPUARMState
*env
, ARMMMUIdx mmuidx
,
4962 unsigned int page_size_granule
, page_shift
, num
, scale
, exponent
;
4963 /* Extract one bit to represent the va selector in use. */
4964 uint64_t select
= sextract64(value
, 36, 1);
4965 ARMVAParameters param
= aa64_va_parameters(env
, select
, mmuidx
, true, false);
4966 TLBIRange ret
= { };
4967 ARMGranuleSize gran
;
4969 page_size_granule
= extract64(value
, 46, 2);
4970 gran
= tlbi_range_tg_to_gran_size(page_size_granule
);
4972 /* The granule encoded in value must match the granule in use. */
4973 if (gran
!= param
.gran
) {
4974 qemu_log_mask(LOG_GUEST_ERROR
, "Invalid tlbi page size granule %d\n",
4979 page_shift
= arm_granule_bits(gran
);
4980 num
= extract64(value
, 39, 5);
4981 scale
= extract64(value
, 44, 2);
4982 exponent
= (5 * scale
) + 1;
4984 ret
.length
= (num
+ 1) << (exponent
+ page_shift
);
4987 ret
.base
= sextract64(value
, 0, 37);
4989 ret
.base
= extract64(value
, 0, 37);
4993 * With DS=1, BaseADDR is always shifted 16 so that it is able
4994 * to address all 52 va bits. The input address is perforce
4995 * aligned on a 64k boundary regardless of translation granule.
4999 ret
.base
<<= page_shift
;
5004 static void do_rvae_write(CPUARMState
*env
, uint64_t value
,
5005 int idxmap
, bool synced
)
5007 ARMMMUIdx one_idx
= ARM_MMU_IDX_A
| ctz32(idxmap
);
5011 range
= tlbi_aa64_get_range(env
, one_idx
, value
);
5012 bits
= tlbbits_for_regime(env
, one_idx
, range
.base
);
5015 tlb_flush_range_by_mmuidx_all_cpus_synced(env_cpu(env
),
5021 tlb_flush_range_by_mmuidx(env_cpu(env
), range
.base
,
5022 range
.length
, idxmap
, bits
);
5026 static void tlbi_aa64_rvae1_write(CPUARMState
*env
,
5027 const ARMCPRegInfo
*ri
,
5031 * Invalidate by VA range, EL1&0.
5032 * Currently handles all of RVAE1, RVAAE1, RVAALE1 and RVALE1,
5033 * since we don't support flush-for-specific-ASID-only or
5034 * flush-last-level-only.
5037 do_rvae_write(env
, value
, vae1_tlbmask(env
),
5038 tlb_force_broadcast(env
));
5041 static void tlbi_aa64_rvae1is_write(CPUARMState
*env
,
5042 const ARMCPRegInfo
*ri
,
5046 * Invalidate by VA range, Inner/Outer Shareable EL1&0.
5047 * Currently handles all of RVAE1IS, RVAE1OS, RVAAE1IS, RVAAE1OS,
5048 * RVAALE1IS, RVAALE1OS, RVALE1IS and RVALE1OS, since we don't support
5049 * flush-for-specific-ASID-only, flush-last-level-only or inner/outer
5050 * shareable specific flushes.
5053 do_rvae_write(env
, value
, vae1_tlbmask(env
), true);
5056 static void tlbi_aa64_rvae2_write(CPUARMState
*env
,
5057 const ARMCPRegInfo
*ri
,
5061 * Invalidate by VA range, EL2.
5062 * Currently handles all of RVAE2 and RVALE2,
5063 * since we don't support flush-for-specific-ASID-only or
5064 * flush-last-level-only.
5067 do_rvae_write(env
, value
, vae2_tlbmask(env
),
5068 tlb_force_broadcast(env
));
5073 static void tlbi_aa64_rvae2is_write(CPUARMState
*env
,
5074 const ARMCPRegInfo
*ri
,
5078 * Invalidate by VA range, Inner/Outer Shareable, EL2.
5079 * Currently handles all of RVAE2IS, RVAE2OS, RVALE2IS and RVALE2OS,
5080 * since we don't support flush-for-specific-ASID-only,
5081 * flush-last-level-only or inner/outer shareable specific flushes.
5084 do_rvae_write(env
, value
, vae2_tlbmask(env
), true);
5088 static void tlbi_aa64_rvae3_write(CPUARMState
*env
,
5089 const ARMCPRegInfo
*ri
,
5093 * Invalidate by VA range, EL3.
5094 * Currently handles all of RVAE3 and RVALE3,
5095 * since we don't support flush-for-specific-ASID-only or
5096 * flush-last-level-only.
5099 do_rvae_write(env
, value
, ARMMMUIdxBit_E3
, tlb_force_broadcast(env
));
5102 static void tlbi_aa64_rvae3is_write(CPUARMState
*env
,
5103 const ARMCPRegInfo
*ri
,
5107 * Invalidate by VA range, EL3, Inner/Outer Shareable.
5108 * Currently handles all of RVAE3IS, RVAE3OS, RVALE3IS and RVALE3OS,
5109 * since we don't support flush-for-specific-ASID-only,
5110 * flush-last-level-only or inner/outer specific flushes.
5113 do_rvae_write(env
, value
, ARMMMUIdxBit_E3
, true);
5116 static void tlbi_aa64_ripas2e1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5119 do_rvae_write(env
, value
, ipas2e1_tlbmask(env
, value
),
5120 tlb_force_broadcast(env
));
5123 static void tlbi_aa64_ripas2e1is_write(CPUARMState
*env
,
5124 const ARMCPRegInfo
*ri
,
5127 do_rvae_write(env
, value
, ipas2e1_tlbmask(env
, value
), true);
5131 static CPAccessResult
aa64_zva_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5134 int cur_el
= arm_current_el(env
);
5137 uint64_t hcr
= arm_hcr_el2_eff(env
);
5140 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
5141 if (!(env
->cp15
.sctlr_el
[2] & SCTLR_DZE
)) {
5142 return CP_ACCESS_TRAP_EL2
;
5145 if (!(env
->cp15
.sctlr_el
[1] & SCTLR_DZE
)) {
5146 return CP_ACCESS_TRAP
;
5148 if (hcr
& HCR_TDZ
) {
5149 return CP_ACCESS_TRAP_EL2
;
5152 } else if (hcr
& HCR_TDZ
) {
5153 return CP_ACCESS_TRAP_EL2
;
5156 return CP_ACCESS_OK
;
5159 static uint64_t aa64_dczid_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
5161 ARMCPU
*cpu
= env_archcpu(env
);
5162 int dzp_bit
= 1 << 4;
5164 /* DZP indicates whether DC ZVA access is allowed */
5165 if (aa64_zva_access(env
, NULL
, false) == CP_ACCESS_OK
) {
5168 return cpu
->dcz_blocksize
| dzp_bit
;
5171 static CPAccessResult
sp_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5174 if (!(env
->pstate
& PSTATE_SP
)) {
5176 * Access to SP_EL0 is undefined if it's being used as
5177 * the stack pointer.
5179 return CP_ACCESS_TRAP_UNCATEGORIZED
;
5181 return CP_ACCESS_OK
;
5184 static uint64_t spsel_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
5186 return env
->pstate
& PSTATE_SP
;
5189 static void spsel_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
5191 update_spsel(env
, val
);
5194 static void sctlr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5197 ARMCPU
*cpu
= env_archcpu(env
);
5199 if (arm_feature(env
, ARM_FEATURE_PMSA
) && !cpu
->has_mpu
) {
5200 /* M bit is RAZ/WI for PMSA with no MPU implemented */
5204 /* ??? Lots of these bits are not implemented. */
5206 if (ri
->state
== ARM_CP_STATE_AA64
&& !cpu_isar_feature(aa64_mte
, cpu
)) {
5207 if (ri
->opc1
== 6) { /* SCTLR_EL3 */
5208 value
&= ~(SCTLR_ITFSB
| SCTLR_TCF
| SCTLR_ATA
);
5210 value
&= ~(SCTLR_ITFSB
| SCTLR_TCF0
| SCTLR_TCF
|
5211 SCTLR_ATA0
| SCTLR_ATA
);
5215 if (raw_read(env
, ri
) == value
) {
5217 * Skip the TLB flush if nothing actually changed; Linux likes
5218 * to do a lot of pointless SCTLR writes.
5223 raw_write(env
, ri
, value
);
5225 /* This may enable/disable the MMU, so do a TLB flush. */
5226 tlb_flush(CPU(cpu
));
5228 if (tcg_enabled() && ri
->type
& ARM_CP_SUPPRESS_TB_END
) {
5230 * Normally we would always end the TB on an SCTLR write; see the
5231 * comment in ARMCPRegInfo sctlr initialization below for why Xscale
5232 * is special. Setting ARM_CP_SUPPRESS_TB_END also stops the rebuild
5233 * of hflags from the translator, so do it here.
5235 arm_rebuild_hflags(env
);
5239 static void mdcr_el3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5243 * Some MDCR_EL3 bits affect whether PMU counters are running:
5244 * if we are trying to change any of those then we must
5245 * bracket this update with PMU start/finish calls.
5247 bool pmu_op
= (env
->cp15
.mdcr_el3
^ value
) & MDCR_EL3_PMU_ENABLE_BITS
;
5252 env
->cp15
.mdcr_el3
= value
;
5258 static void sdcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5261 /* Not all bits defined for MDCR_EL3 exist in the AArch32 SDCR */
5262 mdcr_el3_write(env
, ri
, value
& SDCR_VALID_MASK
);
5265 static void mdcr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5269 * Some MDCR_EL2 bits affect whether PMU counters are running:
5270 * if we are trying to change any of those then we must
5271 * bracket this update with PMU start/finish calls.
5273 bool pmu_op
= (env
->cp15
.mdcr_el2
^ value
) & MDCR_EL2_PMU_ENABLE_BITS
;
5278 env
->cp15
.mdcr_el2
= value
;
5284 #ifdef CONFIG_USER_ONLY
5286 * `IC IVAU` is handled to improve compatibility with JITs that dual-map their
5287 * code to get around W^X restrictions, where one region is writable and the
5288 * other is executable.
5290 * Since the executable region is never written to we cannot detect code
5291 * changes when running in user mode, and rely on the emulated JIT telling us
5292 * that the code has changed by executing this instruction.
5294 static void ic_ivau_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5297 uint64_t icache_line_mask
, start_address
, end_address
;
5300 cpu
= env_archcpu(env
);
5302 icache_line_mask
= (4 << extract32(cpu
->ctr
, 0, 4)) - 1;
5303 start_address
= value
& ~icache_line_mask
;
5304 end_address
= value
| icache_line_mask
;
5308 tb_invalidate_phys_range(start_address
, end_address
);
5314 static const ARMCPRegInfo v8_cp_reginfo
[] = {
5316 * Minimal set of EL0-visible registers. This will need to be expanded
5317 * significantly for system emulation of AArch64 CPUs.
5319 { .name
= "NZCV", .state
= ARM_CP_STATE_AA64
,
5320 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 2,
5321 .access
= PL0_RW
, .type
= ARM_CP_NZCV
},
5322 { .name
= "DAIF", .state
= ARM_CP_STATE_AA64
,
5323 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 2,
5324 .type
= ARM_CP_NO_RAW
,
5325 .access
= PL0_RW
, .accessfn
= aa64_daif_access
,
5326 .fieldoffset
= offsetof(CPUARMState
, daif
),
5327 .writefn
= aa64_daif_write
, .resetfn
= arm_cp_reset_ignore
},
5328 { .name
= "FPCR", .state
= ARM_CP_STATE_AA64
,
5329 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 4,
5330 .access
= PL0_RW
, .type
= ARM_CP_FPU
| ARM_CP_SUPPRESS_TB_END
,
5331 .readfn
= aa64_fpcr_read
, .writefn
= aa64_fpcr_write
},
5332 { .name
= "FPSR", .state
= ARM_CP_STATE_AA64
,
5333 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 4,
5334 .access
= PL0_RW
, .type
= ARM_CP_FPU
| ARM_CP_SUPPRESS_TB_END
,
5335 .readfn
= aa64_fpsr_read
, .writefn
= aa64_fpsr_write
},
5336 { .name
= "DCZID_EL0", .state
= ARM_CP_STATE_AA64
,
5337 .opc0
= 3, .opc1
= 3, .opc2
= 7, .crn
= 0, .crm
= 0,
5338 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
,
5339 .fgt
= FGT_DCZID_EL0
,
5340 .readfn
= aa64_dczid_read
},
5341 { .name
= "DC_ZVA", .state
= ARM_CP_STATE_AA64
,
5342 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 1,
5343 .access
= PL0_W
, .type
= ARM_CP_DC_ZVA
,
5344 #ifndef CONFIG_USER_ONLY
5345 /* Avoid overhead of an access check that always passes in user-mode */
5346 .accessfn
= aa64_zva_access
,
5350 { .name
= "CURRENTEL", .state
= ARM_CP_STATE_AA64
,
5351 .opc0
= 3, .opc1
= 0, .opc2
= 2, .crn
= 4, .crm
= 2,
5352 .access
= PL1_R
, .type
= ARM_CP_CURRENTEL
},
5354 * Instruction cache ops. All of these except `IC IVAU` NOP because we
5355 * don't emulate caches.
5357 { .name
= "IC_IALLUIS", .state
= ARM_CP_STATE_AA64
,
5358 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
5359 .access
= PL1_W
, .type
= ARM_CP_NOP
,
5360 .fgt
= FGT_ICIALLUIS
,
5361 .accessfn
= access_ticab
},
5362 { .name
= "IC_IALLU", .state
= ARM_CP_STATE_AA64
,
5363 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
5364 .access
= PL1_W
, .type
= ARM_CP_NOP
,
5366 .accessfn
= access_tocu
},
5367 { .name
= "IC_IVAU", .state
= ARM_CP_STATE_AA64
,
5368 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 5, .opc2
= 1,
5371 .accessfn
= access_tocu
,
5372 #ifdef CONFIG_USER_ONLY
5373 .type
= ARM_CP_NO_RAW
,
5374 .writefn
= ic_ivau_write
5379 /* Cache ops: all NOPs since we don't emulate caches */
5380 { .name
= "DC_IVAC", .state
= ARM_CP_STATE_AA64
,
5381 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
5382 .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
,
5384 .type
= ARM_CP_NOP
},
5385 { .name
= "DC_ISW", .state
= ARM_CP_STATE_AA64
,
5386 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
5388 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
5389 { .name
= "DC_CVAC", .state
= ARM_CP_STATE_AA64
,
5390 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 1,
5391 .access
= PL0_W
, .type
= ARM_CP_NOP
,
5393 .accessfn
= aa64_cacheop_poc_access
},
5394 { .name
= "DC_CSW", .state
= ARM_CP_STATE_AA64
,
5395 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
5397 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
5398 { .name
= "DC_CVAU", .state
= ARM_CP_STATE_AA64
,
5399 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 11, .opc2
= 1,
5400 .access
= PL0_W
, .type
= ARM_CP_NOP
,
5402 .accessfn
= access_tocu
},
5403 { .name
= "DC_CIVAC", .state
= ARM_CP_STATE_AA64
,
5404 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 1,
5405 .access
= PL0_W
, .type
= ARM_CP_NOP
,
5407 .accessfn
= aa64_cacheop_poc_access
},
5408 { .name
= "DC_CISW", .state
= ARM_CP_STATE_AA64
,
5409 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
5411 .access
= PL1_W
, .accessfn
= access_tsw
, .type
= ARM_CP_NOP
},
5412 /* TLBI operations */
5413 { .name
= "TLBI_VMALLE1IS", .state
= ARM_CP_STATE_AA64
,
5414 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
5415 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5416 .fgt
= FGT_TLBIVMALLE1IS
,
5417 .writefn
= tlbi_aa64_vmalle1is_write
},
5418 { .name
= "TLBI_VAE1IS", .state
= ARM_CP_STATE_AA64
,
5419 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
5420 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5421 .fgt
= FGT_TLBIVAE1IS
,
5422 .writefn
= tlbi_aa64_vae1is_write
},
5423 { .name
= "TLBI_ASIDE1IS", .state
= ARM_CP_STATE_AA64
,
5424 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
5425 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5426 .fgt
= FGT_TLBIASIDE1IS
,
5427 .writefn
= tlbi_aa64_vmalle1is_write
},
5428 { .name
= "TLBI_VAAE1IS", .state
= ARM_CP_STATE_AA64
,
5429 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
5430 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5431 .fgt
= FGT_TLBIVAAE1IS
,
5432 .writefn
= tlbi_aa64_vae1is_write
},
5433 { .name
= "TLBI_VALE1IS", .state
= ARM_CP_STATE_AA64
,
5434 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
5435 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5436 .fgt
= FGT_TLBIVALE1IS
,
5437 .writefn
= tlbi_aa64_vae1is_write
},
5438 { .name
= "TLBI_VAALE1IS", .state
= ARM_CP_STATE_AA64
,
5439 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
5440 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
5441 .fgt
= FGT_TLBIVAALE1IS
,
5442 .writefn
= tlbi_aa64_vae1is_write
},
5443 { .name
= "TLBI_VMALLE1", .state
= ARM_CP_STATE_AA64
,
5444 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
5445 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5446 .fgt
= FGT_TLBIVMALLE1
,
5447 .writefn
= tlbi_aa64_vmalle1_write
},
5448 { .name
= "TLBI_VAE1", .state
= ARM_CP_STATE_AA64
,
5449 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
5450 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5451 .fgt
= FGT_TLBIVAE1
,
5452 .writefn
= tlbi_aa64_vae1_write
},
5453 { .name
= "TLBI_ASIDE1", .state
= ARM_CP_STATE_AA64
,
5454 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
5455 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5456 .fgt
= FGT_TLBIASIDE1
,
5457 .writefn
= tlbi_aa64_vmalle1_write
},
5458 { .name
= "TLBI_VAAE1", .state
= ARM_CP_STATE_AA64
,
5459 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
5460 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5461 .fgt
= FGT_TLBIVAAE1
,
5462 .writefn
= tlbi_aa64_vae1_write
},
5463 { .name
= "TLBI_VALE1", .state
= ARM_CP_STATE_AA64
,
5464 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
5465 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5466 .fgt
= FGT_TLBIVALE1
,
5467 .writefn
= tlbi_aa64_vae1_write
},
5468 { .name
= "TLBI_VAALE1", .state
= ARM_CP_STATE_AA64
,
5469 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
5470 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
5471 .fgt
= FGT_TLBIVAALE1
,
5472 .writefn
= tlbi_aa64_vae1_write
},
5473 { .name
= "TLBI_IPAS2E1IS", .state
= ARM_CP_STATE_AA64
,
5474 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
5475 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5476 .writefn
= tlbi_aa64_ipas2e1is_write
},
5477 { .name
= "TLBI_IPAS2LE1IS", .state
= ARM_CP_STATE_AA64
,
5478 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
5479 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5480 .writefn
= tlbi_aa64_ipas2e1is_write
},
5481 { .name
= "TLBI_ALLE1IS", .state
= ARM_CP_STATE_AA64
,
5482 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
5483 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5484 .writefn
= tlbi_aa64_alle1is_write
},
5485 { .name
= "TLBI_VMALLS12E1IS", .state
= ARM_CP_STATE_AA64
,
5486 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 6,
5487 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5488 .writefn
= tlbi_aa64_alle1is_write
},
5489 { .name
= "TLBI_IPAS2E1", .state
= ARM_CP_STATE_AA64
,
5490 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
5491 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5492 .writefn
= tlbi_aa64_ipas2e1_write
},
5493 { .name
= "TLBI_IPAS2LE1", .state
= ARM_CP_STATE_AA64
,
5494 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
5495 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5496 .writefn
= tlbi_aa64_ipas2e1_write
},
5497 { .name
= "TLBI_ALLE1", .state
= ARM_CP_STATE_AA64
,
5498 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
5499 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5500 .writefn
= tlbi_aa64_alle1_write
},
5501 { .name
= "TLBI_VMALLS12E1", .state
= ARM_CP_STATE_AA64
,
5502 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 6,
5503 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
5504 .writefn
= tlbi_aa64_alle1is_write
},
5505 #ifndef CONFIG_USER_ONLY
5506 /* 64 bit address translation operations */
5507 { .name
= "AT_S1E1R", .state
= ARM_CP_STATE_AA64
,
5508 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 0,
5509 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5511 .writefn
= ats_write64
},
5512 { .name
= "AT_S1E1W", .state
= ARM_CP_STATE_AA64
,
5513 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 1,
5514 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5516 .writefn
= ats_write64
},
5517 { .name
= "AT_S1E0R", .state
= ARM_CP_STATE_AA64
,
5518 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 2,
5519 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5521 .writefn
= ats_write64
},
5522 { .name
= "AT_S1E0W", .state
= ARM_CP_STATE_AA64
,
5523 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 3,
5524 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5526 .writefn
= ats_write64
},
5527 { .name
= "AT_S12E1R", .state
= ARM_CP_STATE_AA64
,
5528 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 4,
5529 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5530 .writefn
= ats_write64
},
5531 { .name
= "AT_S12E1W", .state
= ARM_CP_STATE_AA64
,
5532 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 5,
5533 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5534 .writefn
= ats_write64
},
5535 { .name
= "AT_S12E0R", .state
= ARM_CP_STATE_AA64
,
5536 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 6,
5537 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5538 .writefn
= ats_write64
},
5539 { .name
= "AT_S12E0W", .state
= ARM_CP_STATE_AA64
,
5540 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 7,
5541 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5542 .writefn
= ats_write64
},
5543 /* AT S1E2* are elsewhere as they UNDEF from EL3 if EL2 is not present */
5544 { .name
= "AT_S1E3R", .state
= ARM_CP_STATE_AA64
,
5545 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 0,
5546 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5547 .writefn
= ats_write64
},
5548 { .name
= "AT_S1E3W", .state
= ARM_CP_STATE_AA64
,
5549 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 1,
5550 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
5551 .writefn
= ats_write64
},
5552 { .name
= "PAR_EL1", .state
= ARM_CP_STATE_AA64
,
5553 .type
= ARM_CP_ALIAS
,
5554 .opc0
= 3, .opc1
= 0, .crn
= 7, .crm
= 4, .opc2
= 0,
5555 .access
= PL1_RW
, .resetvalue
= 0,
5557 .fieldoffset
= offsetof(CPUARMState
, cp15
.par_el
[1]),
5558 .writefn
= par_write
},
5560 /* TLB invalidate last level of translation table walk */
5561 { .name
= "TLBIMVALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
5562 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
5563 .writefn
= tlbimva_is_write
},
5564 { .name
= "TLBIMVAALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
5565 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlbis
,
5566 .writefn
= tlbimvaa_is_write
},
5567 { .name
= "TLBIMVAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
5568 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5569 .writefn
= tlbimva_write
},
5570 { .name
= "TLBIMVAAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
5571 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .accessfn
= access_ttlb
,
5572 .writefn
= tlbimvaa_write
},
5573 { .name
= "TLBIMVALH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
5574 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5575 .writefn
= tlbimva_hyp_write
},
5576 { .name
= "TLBIMVALHIS",
5577 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
5578 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5579 .writefn
= tlbimva_hyp_is_write
},
5580 { .name
= "TLBIIPAS2",
5581 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
5582 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5583 .writefn
= tlbiipas2_hyp_write
},
5584 { .name
= "TLBIIPAS2IS",
5585 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
5586 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5587 .writefn
= tlbiipas2is_hyp_write
},
5588 { .name
= "TLBIIPAS2L",
5589 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
5590 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5591 .writefn
= tlbiipas2_hyp_write
},
5592 { .name
= "TLBIIPAS2LIS",
5593 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
5594 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
5595 .writefn
= tlbiipas2is_hyp_write
},
5596 /* 32 bit cache operations */
5597 { .name
= "ICIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
5598 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_ticab
},
5599 { .name
= "BPIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 6,
5600 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5601 { .name
= "ICIALLU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
5602 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tocu
},
5603 { .name
= "ICIMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 1,
5604 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tocu
},
5605 { .name
= "BPIALL", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 6,
5606 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5607 { .name
= "BPIMVA", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 7,
5608 .type
= ARM_CP_NOP
, .access
= PL1_W
},
5609 { .name
= "DCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
5610 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5611 { .name
= "DCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
5612 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5613 { .name
= "DCCMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 1,
5614 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5615 { .name
= "DCCSW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
5616 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5617 { .name
= "DCCMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 11, .opc2
= 1,
5618 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tocu
},
5619 { .name
= "DCCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 1,
5620 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= aa64_cacheop_poc_access
},
5621 { .name
= "DCCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
5622 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
5623 /* MMU Domain access control / MPU write buffer control */
5624 { .name
= "DACR", .cp
= 15, .opc1
= 0, .crn
= 3, .crm
= 0, .opc2
= 0,
5625 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
, .resetvalue
= 0,
5626 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
5627 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
5628 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
5629 { .name
= "ELR_EL1", .state
= ARM_CP_STATE_AA64
,
5630 .type
= ARM_CP_ALIAS
,
5631 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 1,
5633 .fieldoffset
= offsetof(CPUARMState
, elr_el
[1]) },
5634 { .name
= "SPSR_EL1", .state
= ARM_CP_STATE_AA64
,
5635 .type
= ARM_CP_ALIAS
,
5636 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 0,
5638 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_SVC
]) },
5640 * We rely on the access checks not allowing the guest to write to the
5641 * state field when SPSel indicates that it's being used as the stack
5644 { .name
= "SP_EL0", .state
= ARM_CP_STATE_AA64
,
5645 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 1, .opc2
= 0,
5646 .access
= PL1_RW
, .accessfn
= sp_el0_access
,
5647 .type
= ARM_CP_ALIAS
,
5648 .fieldoffset
= offsetof(CPUARMState
, sp_el
[0]) },
5649 { .name
= "SP_EL1", .state
= ARM_CP_STATE_AA64
,
5650 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 1, .opc2
= 0,
5651 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
| ARM_CP_EL3_NO_EL2_KEEP
,
5652 .fieldoffset
= offsetof(CPUARMState
, sp_el
[1]) },
5653 { .name
= "SPSel", .state
= ARM_CP_STATE_AA64
,
5654 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 0,
5655 .type
= ARM_CP_NO_RAW
,
5656 .access
= PL1_RW
, .readfn
= spsel_read
, .writefn
= spsel_write
},
5657 { .name
= "FPEXC32_EL2", .state
= ARM_CP_STATE_AA64
,
5658 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 3, .opc2
= 0,
5660 .type
= ARM_CP_ALIAS
| ARM_CP_FPU
| ARM_CP_EL3_NO_EL2_KEEP
,
5661 .fieldoffset
= offsetof(CPUARMState
, vfp
.xregs
[ARM_VFP_FPEXC
]) },
5662 { .name
= "DACR32_EL2", .state
= ARM_CP_STATE_AA64
,
5663 .opc0
= 3, .opc1
= 4, .crn
= 3, .crm
= 0, .opc2
= 0,
5664 .access
= PL2_RW
, .resetvalue
= 0, .type
= ARM_CP_EL3_NO_EL2_KEEP
,
5665 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
5666 .fieldoffset
= offsetof(CPUARMState
, cp15
.dacr32_el2
) },
5667 { .name
= "IFSR32_EL2", .state
= ARM_CP_STATE_AA64
,
5668 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 0, .opc2
= 1,
5669 .access
= PL2_RW
, .resetvalue
= 0, .type
= ARM_CP_EL3_NO_EL2_KEEP
,
5670 .fieldoffset
= offsetof(CPUARMState
, cp15
.ifsr32_el2
) },
5671 { .name
= "SPSR_IRQ", .state
= ARM_CP_STATE_AA64
,
5672 .type
= ARM_CP_ALIAS
,
5673 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 0,
5675 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_IRQ
]) },
5676 { .name
= "SPSR_ABT", .state
= ARM_CP_STATE_AA64
,
5677 .type
= ARM_CP_ALIAS
,
5678 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 1,
5680 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_ABT
]) },
5681 { .name
= "SPSR_UND", .state
= ARM_CP_STATE_AA64
,
5682 .type
= ARM_CP_ALIAS
,
5683 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 2,
5685 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_UND
]) },
5686 { .name
= "SPSR_FIQ", .state
= ARM_CP_STATE_AA64
,
5687 .type
= ARM_CP_ALIAS
,
5688 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 3,
5690 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_FIQ
]) },
5691 { .name
= "MDCR_EL3", .state
= ARM_CP_STATE_AA64
,
5693 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 3, .opc2
= 1,
5696 .writefn
= mdcr_el3_write
,
5697 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el3
) },
5698 { .name
= "SDCR", .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
5699 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 3, .opc2
= 1,
5700 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
5701 .writefn
= sdcr_write
,
5702 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.mdcr_el3
) },
5705 static void do_hcr_write(CPUARMState
*env
, uint64_t value
, uint64_t valid_mask
)
5707 ARMCPU
*cpu
= env_archcpu(env
);
5709 if (arm_feature(env
, ARM_FEATURE_V8
)) {
5710 valid_mask
|= MAKE_64BIT_MASK(0, 34); /* ARMv8.0 */
5712 valid_mask
|= MAKE_64BIT_MASK(0, 28); /* ARMv7VE */
5715 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
5716 valid_mask
&= ~HCR_HCD
;
5717 } else if (cpu
->psci_conduit
!= QEMU_PSCI_CONDUIT_SMC
) {
5719 * Architecturally HCR.TSC is RES0 if EL3 is not implemented.
5720 * However, if we're using the SMC PSCI conduit then QEMU is
5721 * effectively acting like EL3 firmware and so the guest at
5722 * EL2 should retain the ability to prevent EL1 from being
5723 * able to make SMC calls into the ersatz firmware, so in
5724 * that case HCR.TSC should be read/write.
5726 valid_mask
&= ~HCR_TSC
;
5729 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
5730 if (cpu_isar_feature(aa64_vh
, cpu
)) {
5731 valid_mask
|= HCR_E2H
;
5733 if (cpu_isar_feature(aa64_ras
, cpu
)) {
5734 valid_mask
|= HCR_TERR
| HCR_TEA
;
5736 if (cpu_isar_feature(aa64_lor
, cpu
)) {
5737 valid_mask
|= HCR_TLOR
;
5739 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
5740 valid_mask
|= HCR_API
| HCR_APK
;
5742 if (cpu_isar_feature(aa64_mte
, cpu
)) {
5743 valid_mask
|= HCR_ATA
| HCR_DCT
| HCR_TID5
;
5745 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
5746 valid_mask
|= HCR_ENSCXT
;
5748 if (cpu_isar_feature(aa64_fwb
, cpu
)) {
5749 valid_mask
|= HCR_FWB
;
5751 if (cpu_isar_feature(aa64_rme
, cpu
)) {
5752 valid_mask
|= HCR_GPF
;
5756 if (cpu_isar_feature(any_evt
, cpu
)) {
5757 valid_mask
|= HCR_TTLBIS
| HCR_TTLBOS
| HCR_TICAB
| HCR_TOCU
| HCR_TID4
;
5758 } else if (cpu_isar_feature(any_half_evt
, cpu
)) {
5759 valid_mask
|= HCR_TICAB
| HCR_TOCU
| HCR_TID4
;
5762 /* Clear RES0 bits. */
5763 value
&= valid_mask
;
5766 * These bits change the MMU setup:
5767 * HCR_VM enables stage 2 translation
5768 * HCR_PTW forbids certain page-table setups
5769 * HCR_DC disables stage1 and enables stage2 translation
5770 * HCR_DCT enables tagging on (disabled) stage1 translation
5771 * HCR_FWB changes the interpretation of stage2 descriptor bits
5773 if ((env
->cp15
.hcr_el2
^ value
) &
5774 (HCR_VM
| HCR_PTW
| HCR_DC
| HCR_DCT
| HCR_FWB
)) {
5775 tlb_flush(CPU(cpu
));
5777 env
->cp15
.hcr_el2
= value
;
5780 * Updates to VI and VF require us to update the status of
5781 * virtual interrupts, which are the logical OR of these bits
5782 * and the state of the input lines from the GIC. (This requires
5783 * that we have the iothread lock, which is done by marking the
5784 * reginfo structs as ARM_CP_IO.)
5785 * Note that if a write to HCR pends a VIRQ or VFIQ it is never
5786 * possible for it to be taken immediately, because VIRQ and
5787 * VFIQ are masked unless running at EL0 or EL1, and HCR
5788 * can only be written at EL2.
5790 g_assert(qemu_mutex_iothread_locked());
5791 arm_cpu_update_virq(cpu
);
5792 arm_cpu_update_vfiq(cpu
);
5793 arm_cpu_update_vserr(cpu
);
5796 static void hcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
5798 do_hcr_write(env
, value
, 0);
5801 static void hcr_writehigh(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5804 /* Handle HCR2 write, i.e. write to high half of HCR_EL2 */
5805 value
= deposit64(env
->cp15
.hcr_el2
, 32, 32, value
);
5806 do_hcr_write(env
, value
, MAKE_64BIT_MASK(0, 32));
5809 static void hcr_writelow(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5812 /* Handle HCR write, i.e. write to low half of HCR_EL2 */
5813 value
= deposit64(env
->cp15
.hcr_el2
, 0, 32, value
);
5814 do_hcr_write(env
, value
, MAKE_64BIT_MASK(32, 32));
5818 * Return the effective value of HCR_EL2, at the given security state.
5819 * Bits that are not included here:
5820 * RW (read from SCR_EL3.RW as needed)
5822 uint64_t arm_hcr_el2_eff_secstate(CPUARMState
*env
, ARMSecuritySpace space
)
5824 uint64_t ret
= env
->cp15
.hcr_el2
;
5826 assert(space
!= ARMSS_Root
);
5828 if (!arm_is_el2_enabled_secstate(env
, space
)) {
5830 * "This register has no effect if EL2 is not enabled in the
5831 * current Security state". This is ARMv8.4-SecEL2 speak for
5832 * !(SCR_EL3.NS==1 || SCR_EL3.EEL2==1).
5834 * Prior to that, the language was "In an implementation that
5835 * includes EL3, when the value of SCR_EL3.NS is 0 the PE behaves
5836 * as if this field is 0 for all purposes other than a direct
5837 * read or write access of HCR_EL2". With lots of enumeration
5838 * on a per-field basis. In current QEMU, this is condition
5839 * is arm_is_secure_below_el3.
5841 * Since the v8.4 language applies to the entire register, and
5842 * appears to be backward compatible, use that.
5848 * For a cpu that supports both aarch64 and aarch32, we can set bits
5849 * in HCR_EL2 (e.g. via EL3) that are RES0 when we enter EL2 as aa32.
5850 * Ignore all of the bits in HCR+HCR2 that are not valid for aarch32.
5852 if (!arm_el_is_aa64(env
, 2)) {
5853 uint64_t aa32_valid
;
5856 * These bits are up-to-date as of ARMv8.6.
5857 * For HCR, it's easiest to list just the 2 bits that are invalid.
5858 * For HCR2, list those that are valid.
5860 aa32_valid
= MAKE_64BIT_MASK(0, 32) & ~(HCR_RW
| HCR_TDZ
);
5861 aa32_valid
|= (HCR_CD
| HCR_ID
| HCR_TERR
| HCR_TEA
| HCR_MIOCNCE
|
5862 HCR_TID4
| HCR_TICAB
| HCR_TOCU
| HCR_TTLBIS
);
5866 if (ret
& HCR_TGE
) {
5867 /* These bits are up-to-date as of ARMv8.6. */
5868 if (ret
& HCR_E2H
) {
5869 ret
&= ~(HCR_VM
| HCR_FMO
| HCR_IMO
| HCR_AMO
|
5870 HCR_BSU_MASK
| HCR_DC
| HCR_TWI
| HCR_TWE
|
5871 HCR_TID0
| HCR_TID2
| HCR_TPCP
| HCR_TPU
|
5872 HCR_TDZ
| HCR_CD
| HCR_ID
| HCR_MIOCNCE
|
5873 HCR_TID4
| HCR_TICAB
| HCR_TOCU
| HCR_ENSCXT
|
5874 HCR_TTLBIS
| HCR_TTLBOS
| HCR_TID5
);
5876 ret
|= HCR_FMO
| HCR_IMO
| HCR_AMO
;
5878 ret
&= ~(HCR_SWIO
| HCR_PTW
| HCR_VF
| HCR_VI
| HCR_VSE
|
5879 HCR_FB
| HCR_TID1
| HCR_TID3
| HCR_TSC
| HCR_TACR
|
5880 HCR_TSW
| HCR_TTLB
| HCR_TVM
| HCR_HCD
| HCR_TRVM
|
5887 uint64_t arm_hcr_el2_eff(CPUARMState
*env
)
5889 if (arm_feature(env
, ARM_FEATURE_M
)) {
5892 return arm_hcr_el2_eff_secstate(env
, arm_security_space_below_el3(env
));
5896 * Corresponds to ARM pseudocode function ELIsInHost().
5898 bool el_is_in_host(CPUARMState
*env
, int el
)
5903 * Since we only care about E2H and TGE, we can skip arm_hcr_el2_eff().
5904 * Perform the simplest bit tests first, and validate EL2 afterward.
5907 return false; /* EL1 or EL3 */
5911 * Note that hcr_write() checks isar_feature_aa64_vh(),
5912 * aka HaveVirtHostExt(), in allowing HCR_E2H to be set.
5914 mask
= el
? HCR_E2H
: HCR_E2H
| HCR_TGE
;
5915 if ((env
->cp15
.hcr_el2
& mask
) != mask
) {
5919 /* TGE and/or E2H set: double check those bits are currently legal. */
5920 return arm_is_el2_enabled(env
) && arm_el_is_aa64(env
, 2);
5923 static void hcrx_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5926 uint64_t valid_mask
= 0;
5928 /* No features adding bits to HCRX are implemented. */
5930 /* Clear RES0 bits. */
5931 env
->cp15
.hcrx_el2
= value
& valid_mask
;
5934 static CPAccessResult
access_hxen(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5937 if (arm_current_el(env
) < 3
5938 && arm_feature(env
, ARM_FEATURE_EL3
)
5939 && !(env
->cp15
.scr_el3
& SCR_HXEN
)) {
5940 return CP_ACCESS_TRAP_EL3
;
5942 return CP_ACCESS_OK
;
5945 static const ARMCPRegInfo hcrx_el2_reginfo
= {
5946 .name
= "HCRX_EL2", .state
= ARM_CP_STATE_AA64
,
5947 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 2,
5948 .access
= PL2_RW
, .writefn
= hcrx_write
, .accessfn
= access_hxen
,
5949 .fieldoffset
= offsetof(CPUARMState
, cp15
.hcrx_el2
),
5952 /* Return the effective value of HCRX_EL2. */
5953 uint64_t arm_hcrx_el2_eff(CPUARMState
*env
)
5956 * The bits in this register behave as 0 for all purposes other than
5957 * direct reads of the register if:
5958 * - EL2 is not enabled in the current security state,
5959 * - SCR_EL3.HXEn is 0.
5961 if (!arm_is_el2_enabled(env
)
5962 || (arm_feature(env
, ARM_FEATURE_EL3
)
5963 && !(env
->cp15
.scr_el3
& SCR_HXEN
))) {
5966 return env
->cp15
.hcrx_el2
;
5969 static void cptr_el2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5973 * For A-profile AArch32 EL3, if NSACR.CP10
5974 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
5976 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
5977 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
5978 uint64_t mask
= R_HCPTR_TCP11_MASK
| R_HCPTR_TCP10_MASK
;
5979 value
= (value
& ~mask
) | (env
->cp15
.cptr_el
[2] & mask
);
5981 env
->cp15
.cptr_el
[2] = value
;
5984 static uint64_t cptr_el2_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
5987 * For A-profile AArch32 EL3, if NSACR.CP10
5988 * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1.
5990 uint64_t value
= env
->cp15
.cptr_el
[2];
5992 if (arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
5993 !arm_is_secure(env
) && !extract32(env
->cp15
.nsacr
, 10, 1)) {
5994 value
|= R_HCPTR_TCP11_MASK
| R_HCPTR_TCP10_MASK
;
5999 static const ARMCPRegInfo el2_cp_reginfo
[] = {
6000 { .name
= "HCR_EL2", .state
= ARM_CP_STATE_AA64
,
6002 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
6003 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.hcr_el2
),
6004 .writefn
= hcr_write
, .raw_writefn
= raw_write
},
6005 { .name
= "HCR", .state
= ARM_CP_STATE_AA32
,
6006 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
6007 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
6008 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.hcr_el2
),
6009 .writefn
= hcr_writelow
},
6010 { .name
= "HACR_EL2", .state
= ARM_CP_STATE_BOTH
,
6011 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 7,
6012 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6013 { .name
= "ELR_EL2", .state
= ARM_CP_STATE_AA64
,
6014 .type
= ARM_CP_ALIAS
,
6015 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 1,
6017 .fieldoffset
= offsetof(CPUARMState
, elr_el
[2]) },
6018 { .name
= "ESR_EL2", .state
= ARM_CP_STATE_BOTH
,
6019 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 2, .opc2
= 0,
6020 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[2]) },
6021 { .name
= "FAR_EL2", .state
= ARM_CP_STATE_BOTH
,
6022 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 0,
6023 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[2]) },
6024 { .name
= "HIFAR", .state
= ARM_CP_STATE_AA32
,
6025 .type
= ARM_CP_ALIAS
,
6026 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 2,
6028 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.far_el
[2]) },
6029 { .name
= "SPSR_EL2", .state
= ARM_CP_STATE_AA64
,
6030 .type
= ARM_CP_ALIAS
,
6031 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 0,
6033 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_HYP
]) },
6034 { .name
= "VBAR_EL2", .state
= ARM_CP_STATE_BOTH
,
6035 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 0,
6036 .access
= PL2_RW
, .writefn
= vbar_write
,
6037 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[2]),
6039 { .name
= "SP_EL2", .state
= ARM_CP_STATE_AA64
,
6040 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 1, .opc2
= 0,
6041 .access
= PL3_RW
, .type
= ARM_CP_ALIAS
,
6042 .fieldoffset
= offsetof(CPUARMState
, sp_el
[2]) },
6043 { .name
= "CPTR_EL2", .state
= ARM_CP_STATE_BOTH
,
6044 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 2,
6045 .access
= PL2_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
6046 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[2]),
6047 .readfn
= cptr_el2_read
, .writefn
= cptr_el2_write
},
6048 { .name
= "MAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
6049 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 0,
6050 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[2]),
6052 { .name
= "HMAIR1", .state
= ARM_CP_STATE_AA32
,
6053 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 1,
6054 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
,
6055 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.mair_el
[2]) },
6056 { .name
= "AMAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
6057 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 0,
6058 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
6060 /* HAMAIR1 is mapped to AMAIR_EL2[63:32] */
6061 { .name
= "HAMAIR1", .state
= ARM_CP_STATE_AA32
,
6062 .cp
= 15, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 1,
6063 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
6065 { .name
= "AFSR0_EL2", .state
= ARM_CP_STATE_BOTH
,
6066 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 0,
6067 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
6069 { .name
= "AFSR1_EL2", .state
= ARM_CP_STATE_BOTH
,
6070 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 1,
6071 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
6073 { .name
= "TCR_EL2", .state
= ARM_CP_STATE_BOTH
,
6074 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 2,
6075 .access
= PL2_RW
, .writefn
= vmsa_tcr_el12_write
,
6076 .raw_writefn
= raw_write
,
6077 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[2]) },
6078 { .name
= "VTCR", .state
= ARM_CP_STATE_AA32
,
6079 .cp
= 15, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
6080 .type
= ARM_CP_ALIAS
,
6081 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
6082 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vtcr_el2
) },
6083 { .name
= "VTCR_EL2", .state
= ARM_CP_STATE_AA64
,
6084 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
6086 /* no .writefn needed as this can't cause an ASID change */
6087 .fieldoffset
= offsetof(CPUARMState
, cp15
.vtcr_el2
) },
6088 { .name
= "VTTBR", .state
= ARM_CP_STATE_AA32
,
6089 .cp
= 15, .opc1
= 6, .crm
= 2,
6090 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
6091 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
6092 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
),
6093 .writefn
= vttbr_write
, .raw_writefn
= raw_write
},
6094 { .name
= "VTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
6095 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 0,
6096 .access
= PL2_RW
, .writefn
= vttbr_write
, .raw_writefn
= raw_write
,
6097 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
) },
6098 { .name
= "SCTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
6099 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 0,
6100 .access
= PL2_RW
, .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
6101 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[2]) },
6102 { .name
= "TPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
6103 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 2,
6104 .access
= PL2_RW
, .resetvalue
= 0,
6105 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[2]) },
6106 { .name
= "TTBR0_EL2", .state
= ARM_CP_STATE_AA64
,
6107 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 0,
6108 .access
= PL2_RW
, .resetvalue
= 0,
6109 .writefn
= vmsa_tcr_ttbr_el2_write
, .raw_writefn
= raw_write
,
6110 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
6111 { .name
= "HTTBR", .cp
= 15, .opc1
= 4, .crm
= 2,
6112 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
6113 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
6114 { .name
= "TLBIALLNSNH",
6115 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
6116 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6117 .writefn
= tlbiall_nsnh_write
},
6118 { .name
= "TLBIALLNSNHIS",
6119 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
6120 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6121 .writefn
= tlbiall_nsnh_is_write
},
6122 { .name
= "TLBIALLH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
6123 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6124 .writefn
= tlbiall_hyp_write
},
6125 { .name
= "TLBIALLHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
6126 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6127 .writefn
= tlbiall_hyp_is_write
},
6128 { .name
= "TLBIMVAH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
6129 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6130 .writefn
= tlbimva_hyp_write
},
6131 { .name
= "TLBIMVAHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
6132 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
6133 .writefn
= tlbimva_hyp_is_write
},
6134 { .name
= "TLBI_ALLE2", .state
= ARM_CP_STATE_AA64
,
6135 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
6136 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6137 .writefn
= tlbi_aa64_alle2_write
},
6138 { .name
= "TLBI_VAE2", .state
= ARM_CP_STATE_AA64
,
6139 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
6140 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6141 .writefn
= tlbi_aa64_vae2_write
},
6142 { .name
= "TLBI_VALE2", .state
= ARM_CP_STATE_AA64
,
6143 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
6144 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6145 .writefn
= tlbi_aa64_vae2_write
},
6146 { .name
= "TLBI_ALLE2IS", .state
= ARM_CP_STATE_AA64
,
6147 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
6148 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6149 .writefn
= tlbi_aa64_alle2is_write
},
6150 { .name
= "TLBI_VAE2IS", .state
= ARM_CP_STATE_AA64
,
6151 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
6152 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6153 .writefn
= tlbi_aa64_vae2is_write
},
6154 { .name
= "TLBI_VALE2IS", .state
= ARM_CP_STATE_AA64
,
6155 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
6156 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
6157 .writefn
= tlbi_aa64_vae2is_write
},
6158 #ifndef CONFIG_USER_ONLY
6160 * Unlike the other EL2-related AT operations, these must
6161 * UNDEF from EL3 if EL2 is not implemented, which is why we
6162 * define them here rather than with the rest of the AT ops.
6164 { .name
= "AT_S1E2R", .state
= ARM_CP_STATE_AA64
,
6165 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
6166 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
6167 .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
| ARM_CP_EL3_NO_EL2_UNDEF
,
6168 .writefn
= ats_write64
},
6169 { .name
= "AT_S1E2W", .state
= ARM_CP_STATE_AA64
,
6170 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
6171 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
6172 .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
| ARM_CP_EL3_NO_EL2_UNDEF
,
6173 .writefn
= ats_write64
},
6175 * The AArch32 ATS1H* operations are CONSTRAINED UNPREDICTABLE
6176 * if EL2 is not implemented; we choose to UNDEF. Behaviour at EL3
6177 * with SCR.NS == 0 outside Monitor mode is UNPREDICTABLE; we choose
6178 * to behave as if SCR.NS was 1.
6180 { .name
= "ATS1HR", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
6182 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
6183 { .name
= "ATS1HW", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
6185 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
},
6186 { .name
= "CNTHCTL_EL2", .state
= ARM_CP_STATE_BOTH
,
6187 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 1, .opc2
= 0,
6189 * ARMv7 requires bit 0 and 1 to reset to 1. ARMv8 defines the
6190 * reset values as IMPDEF. We choose to reset to 3 to comply with
6191 * both ARMv7 and ARMv8.
6193 .access
= PL2_RW
, .resetvalue
= 3,
6194 .fieldoffset
= offsetof(CPUARMState
, cp15
.cnthctl_el2
) },
6195 { .name
= "CNTVOFF_EL2", .state
= ARM_CP_STATE_AA64
,
6196 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 0, .opc2
= 3,
6197 .access
= PL2_RW
, .type
= ARM_CP_IO
, .resetvalue
= 0,
6198 .writefn
= gt_cntvoff_write
,
6199 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
6200 { .name
= "CNTVOFF", .cp
= 15, .opc1
= 4, .crm
= 14,
6201 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
| ARM_CP_IO
,
6202 .writefn
= gt_cntvoff_write
,
6203 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
6204 { .name
= "CNTHP_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
6205 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 2,
6206 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
6207 .type
= ARM_CP_IO
, .access
= PL2_RW
,
6208 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
6209 { .name
= "CNTHP_CVAL", .cp
= 15, .opc1
= 6, .crm
= 14,
6210 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
6211 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_IO
,
6212 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
6213 { .name
= "CNTHP_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
6214 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 0,
6215 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL2_RW
,
6216 .resetfn
= gt_hyp_timer_reset
,
6217 .readfn
= gt_hyp_tval_read
, .writefn
= gt_hyp_tval_write
},
6218 { .name
= "CNTHP_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
6220 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 1,
6222 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].ctl
),
6224 .writefn
= gt_hyp_ctl_write
, .raw_writefn
= raw_write
},
6226 { .name
= "HPFAR", .state
= ARM_CP_STATE_AA32
,
6227 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
6228 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
6229 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
6230 { .name
= "HPFAR_EL2", .state
= ARM_CP_STATE_AA64
,
6231 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
6233 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
6234 { .name
= "HSTR_EL2", .state
= ARM_CP_STATE_BOTH
,
6235 .cp
= 15, .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 3,
6237 .fieldoffset
= offsetof(CPUARMState
, cp15
.hstr_el2
) },
6240 static const ARMCPRegInfo el2_v8_cp_reginfo
[] = {
6241 { .name
= "HCR2", .state
= ARM_CP_STATE_AA32
,
6242 .type
= ARM_CP_ALIAS
| ARM_CP_IO
,
6243 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 4,
6245 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.hcr_el2
),
6246 .writefn
= hcr_writehigh
},
6249 static CPAccessResult
sel2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6252 if (arm_current_el(env
) == 3 || arm_is_secure_below_el3(env
)) {
6253 return CP_ACCESS_OK
;
6255 return CP_ACCESS_TRAP_UNCATEGORIZED
;
6258 static const ARMCPRegInfo el2_sec_cp_reginfo
[] = {
6259 { .name
= "VSTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
6260 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 6, .opc2
= 0,
6261 .access
= PL2_RW
, .accessfn
= sel2_access
,
6262 .fieldoffset
= offsetof(CPUARMState
, cp15
.vsttbr_el2
) },
6263 { .name
= "VSTCR_EL2", .state
= ARM_CP_STATE_AA64
,
6264 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 6, .opc2
= 2,
6265 .access
= PL2_RW
, .accessfn
= sel2_access
,
6266 .fieldoffset
= offsetof(CPUARMState
, cp15
.vstcr_el2
) },
6269 static CPAccessResult
nsacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6273 * The NSACR is RW at EL3, and RO for NS EL1 and NS EL2.
6274 * At Secure EL1 it traps to EL3 or EL2.
6276 if (arm_current_el(env
) == 3) {
6277 return CP_ACCESS_OK
;
6279 if (arm_is_secure_below_el3(env
)) {
6280 if (env
->cp15
.scr_el3
& SCR_EEL2
) {
6281 return CP_ACCESS_TRAP_EL2
;
6283 return CP_ACCESS_TRAP_EL3
;
6285 /* Accesses from EL1 NS and EL2 NS are UNDEF for write but allow reads. */
6287 return CP_ACCESS_OK
;
6289 return CP_ACCESS_TRAP_UNCATEGORIZED
;
6292 static const ARMCPRegInfo el3_cp_reginfo
[] = {
6293 { .name
= "SCR_EL3", .state
= ARM_CP_STATE_AA64
,
6294 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 0,
6295 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.scr_el3
),
6296 .resetfn
= scr_reset
, .writefn
= scr_write
, .raw_writefn
= raw_write
},
6297 { .name
= "SCR", .type
= ARM_CP_ALIAS
| ARM_CP_NEWEL
,
6298 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 0,
6299 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
6300 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.scr_el3
),
6301 .writefn
= scr_write
, .raw_writefn
= raw_write
},
6302 { .name
= "SDER32_EL3", .state
= ARM_CP_STATE_AA64
,
6303 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 1,
6304 .access
= PL3_RW
, .resetvalue
= 0,
6305 .fieldoffset
= offsetof(CPUARMState
, cp15
.sder
) },
6307 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 1,
6308 .access
= PL3_RW
, .resetvalue
= 0,
6309 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.sder
) },
6310 { .name
= "MVBAR", .cp
= 15, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
6311 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
6312 .writefn
= vbar_write
, .resetvalue
= 0,
6313 .fieldoffset
= offsetof(CPUARMState
, cp15
.mvbar
) },
6314 { .name
= "TTBR0_EL3", .state
= ARM_CP_STATE_AA64
,
6315 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 0,
6316 .access
= PL3_RW
, .resetvalue
= 0,
6317 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[3]) },
6318 { .name
= "TCR_EL3", .state
= ARM_CP_STATE_AA64
,
6319 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 2,
6321 /* no .writefn needed as this can't cause an ASID change */
6323 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[3]) },
6324 { .name
= "ELR_EL3", .state
= ARM_CP_STATE_AA64
,
6325 .type
= ARM_CP_ALIAS
,
6326 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 1,
6328 .fieldoffset
= offsetof(CPUARMState
, elr_el
[3]) },
6329 { .name
= "ESR_EL3", .state
= ARM_CP_STATE_AA64
,
6330 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 2, .opc2
= 0,
6331 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[3]) },
6332 { .name
= "FAR_EL3", .state
= ARM_CP_STATE_AA64
,
6333 .opc0
= 3, .opc1
= 6, .crn
= 6, .crm
= 0, .opc2
= 0,
6334 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[3]) },
6335 { .name
= "SPSR_EL3", .state
= ARM_CP_STATE_AA64
,
6336 .type
= ARM_CP_ALIAS
,
6337 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 0,
6339 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_MON
]) },
6340 { .name
= "VBAR_EL3", .state
= ARM_CP_STATE_AA64
,
6341 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 0,
6342 .access
= PL3_RW
, .writefn
= vbar_write
,
6343 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[3]),
6345 { .name
= "CPTR_EL3", .state
= ARM_CP_STATE_AA64
,
6346 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 2,
6347 .access
= PL3_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
6348 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[3]) },
6349 { .name
= "TPIDR_EL3", .state
= ARM_CP_STATE_AA64
,
6350 .opc0
= 3, .opc1
= 6, .crn
= 13, .crm
= 0, .opc2
= 2,
6351 .access
= PL3_RW
, .resetvalue
= 0,
6352 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[3]) },
6353 { .name
= "AMAIR_EL3", .state
= ARM_CP_STATE_AA64
,
6354 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 3, .opc2
= 0,
6355 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
6357 { .name
= "AFSR0_EL3", .state
= ARM_CP_STATE_BOTH
,
6358 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 0,
6359 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
6361 { .name
= "AFSR1_EL3", .state
= ARM_CP_STATE_BOTH
,
6362 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 1,
6363 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
6365 { .name
= "TLBI_ALLE3IS", .state
= ARM_CP_STATE_AA64
,
6366 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 0,
6367 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6368 .writefn
= tlbi_aa64_alle3is_write
},
6369 { .name
= "TLBI_VAE3IS", .state
= ARM_CP_STATE_AA64
,
6370 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 1,
6371 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6372 .writefn
= tlbi_aa64_vae3is_write
},
6373 { .name
= "TLBI_VALE3IS", .state
= ARM_CP_STATE_AA64
,
6374 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 5,
6375 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6376 .writefn
= tlbi_aa64_vae3is_write
},
6377 { .name
= "TLBI_ALLE3", .state
= ARM_CP_STATE_AA64
,
6378 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 0,
6379 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6380 .writefn
= tlbi_aa64_alle3_write
},
6381 { .name
= "TLBI_VAE3", .state
= ARM_CP_STATE_AA64
,
6382 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 1,
6383 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6384 .writefn
= tlbi_aa64_vae3_write
},
6385 { .name
= "TLBI_VALE3", .state
= ARM_CP_STATE_AA64
,
6386 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 5,
6387 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
6388 .writefn
= tlbi_aa64_vae3_write
},
6391 #ifndef CONFIG_USER_ONLY
6392 /* Test if system register redirection is to occur in the current state. */
6393 static bool redirect_for_e2h(CPUARMState
*env
)
6395 return arm_current_el(env
) == 2 && (arm_hcr_el2_eff(env
) & HCR_E2H
);
6398 static uint64_t el2_e2h_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6402 if (redirect_for_e2h(env
)) {
6403 /* Switch to the saved EL2 version of the register. */
6405 readfn
= ri
->readfn
;
6407 readfn
= ri
->orig_readfn
;
6409 if (readfn
== NULL
) {
6412 return readfn(env
, ri
);
6415 static void el2_e2h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6420 if (redirect_for_e2h(env
)) {
6421 /* Switch to the saved EL2 version of the register. */
6423 writefn
= ri
->writefn
;
6425 writefn
= ri
->orig_writefn
;
6427 if (writefn
== NULL
) {
6428 writefn
= raw_write
;
6430 writefn(env
, ri
, value
);
6433 static void define_arm_vh_e2h_redirects_aliases(ARMCPU
*cpu
)
6436 uint32_t src_key
, dst_key
, new_key
;
6437 const char *src_name
, *dst_name
, *new_name
;
6438 bool (*feature
)(const ARMISARegisters
*id
);
6441 #define K(op0, op1, crn, crm, op2) \
6442 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP, crn, crm, op0, op1, op2)
6444 static const struct E2HAlias aliases
[] = {
6445 { K(3, 0, 1, 0, 0), K(3, 4, 1, 0, 0), K(3, 5, 1, 0, 0),
6446 "SCTLR", "SCTLR_EL2", "SCTLR_EL12" },
6447 { K(3, 0, 1, 0, 2), K(3, 4, 1, 1, 2), K(3, 5, 1, 0, 2),
6448 "CPACR", "CPTR_EL2", "CPACR_EL12" },
6449 { K(3, 0, 2, 0, 0), K(3, 4, 2, 0, 0), K(3, 5, 2, 0, 0),
6450 "TTBR0_EL1", "TTBR0_EL2", "TTBR0_EL12" },
6451 { K(3, 0, 2, 0, 1), K(3, 4, 2, 0, 1), K(3, 5, 2, 0, 1),
6452 "TTBR1_EL1", "TTBR1_EL2", "TTBR1_EL12" },
6453 { K(3, 0, 2, 0, 2), K(3, 4, 2, 0, 2), K(3, 5, 2, 0, 2),
6454 "TCR_EL1", "TCR_EL2", "TCR_EL12" },
6455 { K(3, 0, 4, 0, 0), K(3, 4, 4, 0, 0), K(3, 5, 4, 0, 0),
6456 "SPSR_EL1", "SPSR_EL2", "SPSR_EL12" },
6457 { K(3, 0, 4, 0, 1), K(3, 4, 4, 0, 1), K(3, 5, 4, 0, 1),
6458 "ELR_EL1", "ELR_EL2", "ELR_EL12" },
6459 { K(3, 0, 5, 1, 0), K(3, 4, 5, 1, 0), K(3, 5, 5, 1, 0),
6460 "AFSR0_EL1", "AFSR0_EL2", "AFSR0_EL12" },
6461 { K(3, 0, 5, 1, 1), K(3, 4, 5, 1, 1), K(3, 5, 5, 1, 1),
6462 "AFSR1_EL1", "AFSR1_EL2", "AFSR1_EL12" },
6463 { K(3, 0, 5, 2, 0), K(3, 4, 5, 2, 0), K(3, 5, 5, 2, 0),
6464 "ESR_EL1", "ESR_EL2", "ESR_EL12" },
6465 { K(3, 0, 6, 0, 0), K(3, 4, 6, 0, 0), K(3, 5, 6, 0, 0),
6466 "FAR_EL1", "FAR_EL2", "FAR_EL12" },
6467 { K(3, 0, 10, 2, 0), K(3, 4, 10, 2, 0), K(3, 5, 10, 2, 0),
6468 "MAIR_EL1", "MAIR_EL2", "MAIR_EL12" },
6469 { K(3, 0, 10, 3, 0), K(3, 4, 10, 3, 0), K(3, 5, 10, 3, 0),
6470 "AMAIR0", "AMAIR_EL2", "AMAIR_EL12" },
6471 { K(3, 0, 12, 0, 0), K(3, 4, 12, 0, 0), K(3, 5, 12, 0, 0),
6472 "VBAR", "VBAR_EL2", "VBAR_EL12" },
6473 { K(3, 0, 13, 0, 1), K(3, 4, 13, 0, 1), K(3, 5, 13, 0, 1),
6474 "CONTEXTIDR_EL1", "CONTEXTIDR_EL2", "CONTEXTIDR_EL12" },
6475 { K(3, 0, 14, 1, 0), K(3, 4, 14, 1, 0), K(3, 5, 14, 1, 0),
6476 "CNTKCTL", "CNTHCTL_EL2", "CNTKCTL_EL12" },
6479 * Note that redirection of ZCR is mentioned in the description
6480 * of ZCR_EL2, and aliasing in the description of ZCR_EL1, but
6481 * not in the summary table.
6483 { K(3, 0, 1, 2, 0), K(3, 4, 1, 2, 0), K(3, 5, 1, 2, 0),
6484 "ZCR_EL1", "ZCR_EL2", "ZCR_EL12", isar_feature_aa64_sve
},
6485 { K(3, 0, 1, 2, 6), K(3, 4, 1, 2, 6), K(3, 5, 1, 2, 6),
6486 "SMCR_EL1", "SMCR_EL2", "SMCR_EL12", isar_feature_aa64_sme
},
6488 { K(3, 0, 5, 6, 0), K(3, 4, 5, 6, 0), K(3, 5, 5, 6, 0),
6489 "TFSR_EL1", "TFSR_EL2", "TFSR_EL12", isar_feature_aa64_mte
},
6491 { K(3, 0, 13, 0, 7), K(3, 4, 13, 0, 7), K(3, 5, 13, 0, 7),
6492 "SCXTNUM_EL1", "SCXTNUM_EL2", "SCXTNUM_EL12",
6493 isar_feature_aa64_scxtnum
},
6495 /* TODO: ARMv8.2-SPE -- PMSCR_EL2 */
6496 /* TODO: ARMv8.4-Trace -- TRFCR_EL2 */
6502 for (i
= 0; i
< ARRAY_SIZE(aliases
); i
++) {
6503 const struct E2HAlias
*a
= &aliases
[i
];
6504 ARMCPRegInfo
*src_reg
, *dst_reg
, *new_reg
;
6507 if (a
->feature
&& !a
->feature(&cpu
->isar
)) {
6511 src_reg
= g_hash_table_lookup(cpu
->cp_regs
,
6512 (gpointer
)(uintptr_t)a
->src_key
);
6513 dst_reg
= g_hash_table_lookup(cpu
->cp_regs
,
6514 (gpointer
)(uintptr_t)a
->dst_key
);
6515 g_assert(src_reg
!= NULL
);
6516 g_assert(dst_reg
!= NULL
);
6518 /* Cross-compare names to detect typos in the keys. */
6519 g_assert(strcmp(src_reg
->name
, a
->src_name
) == 0);
6520 g_assert(strcmp(dst_reg
->name
, a
->dst_name
) == 0);
6522 /* None of the core system registers use opaque; we will. */
6523 g_assert(src_reg
->opaque
== NULL
);
6525 /* Create alias before redirection so we dup the right data. */
6526 new_reg
= g_memdup(src_reg
, sizeof(ARMCPRegInfo
));
6528 new_reg
->name
= a
->new_name
;
6529 new_reg
->type
|= ARM_CP_ALIAS
;
6530 /* Remove PL1/PL0 access, leaving PL2/PL3 R/W in place. */
6531 new_reg
->access
&= PL2_RW
| PL3_RW
;
6533 ok
= g_hash_table_insert(cpu
->cp_regs
,
6534 (gpointer
)(uintptr_t)a
->new_key
, new_reg
);
6537 src_reg
->opaque
= dst_reg
;
6538 src_reg
->orig_readfn
= src_reg
->readfn
?: raw_read
;
6539 src_reg
->orig_writefn
= src_reg
->writefn
?: raw_write
;
6540 if (!src_reg
->raw_readfn
) {
6541 src_reg
->raw_readfn
= raw_read
;
6543 if (!src_reg
->raw_writefn
) {
6544 src_reg
->raw_writefn
= raw_write
;
6546 src_reg
->readfn
= el2_e2h_read
;
6547 src_reg
->writefn
= el2_e2h_write
;
6552 static CPAccessResult
ctr_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6555 int cur_el
= arm_current_el(env
);
6558 uint64_t hcr
= arm_hcr_el2_eff(env
);
6561 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
6562 if (!(env
->cp15
.sctlr_el
[2] & SCTLR_UCT
)) {
6563 return CP_ACCESS_TRAP_EL2
;
6566 if (!(env
->cp15
.sctlr_el
[1] & SCTLR_UCT
)) {
6567 return CP_ACCESS_TRAP
;
6569 if (hcr
& HCR_TID2
) {
6570 return CP_ACCESS_TRAP_EL2
;
6573 } else if (hcr
& HCR_TID2
) {
6574 return CP_ACCESS_TRAP_EL2
;
6578 if (arm_current_el(env
) < 2 && arm_hcr_el2_eff(env
) & HCR_TID2
) {
6579 return CP_ACCESS_TRAP_EL2
;
6582 return CP_ACCESS_OK
;
6586 * Check for traps to RAS registers, which are controlled
6587 * by HCR_EL2.TERR and SCR_EL3.TERR.
6589 static CPAccessResult
access_terr(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6592 int el
= arm_current_el(env
);
6594 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_TERR
)) {
6595 return CP_ACCESS_TRAP_EL2
;
6597 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_TERR
)) {
6598 return CP_ACCESS_TRAP_EL3
;
6600 return CP_ACCESS_OK
;
6603 static uint64_t disr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
6605 int el
= arm_current_el(env
);
6607 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_AMO
)) {
6608 return env
->cp15
.vdisr_el2
;
6610 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_EA
)) {
6611 return 0; /* RAZ/WI */
6613 return env
->cp15
.disr_el1
;
6616 static void disr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
6618 int el
= arm_current_el(env
);
6620 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_AMO
)) {
6621 env
->cp15
.vdisr_el2
= val
;
6624 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_EA
)) {
6625 return; /* RAZ/WI */
6627 env
->cp15
.disr_el1
= val
;
6631 * Minimal RAS implementation with no Error Records.
6632 * Which means that all of the Error Record registers:
6640 * ERXPFGCDN_EL1 (RASv1p1)
6641 * ERXPFGCTL_EL1 (RASv1p1)
6642 * ERXPFGF_EL1 (RASv1p1)
6646 * may generate UNDEFINED, which is the effect we get by not
6647 * listing them at all.
6649 * These registers have fine-grained trap bits, but UNDEF-to-EL1
6650 * is higher priority than FGT-to-EL2 so we do not need to list them
6651 * in order to check for an FGT.
6653 static const ARMCPRegInfo minimal_ras_reginfo
[] = {
6654 { .name
= "DISR_EL1", .state
= ARM_CP_STATE_BOTH
,
6655 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 1, .opc2
= 1,
6656 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.disr_el1
),
6657 .readfn
= disr_read
, .writefn
= disr_write
, .raw_writefn
= raw_write
},
6658 { .name
= "ERRIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
6659 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 3, .opc2
= 0,
6660 .access
= PL1_R
, .accessfn
= access_terr
,
6661 .fgt
= FGT_ERRIDR_EL1
,
6662 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
6663 { .name
= "VDISR_EL2", .state
= ARM_CP_STATE_BOTH
,
6664 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 1, .opc2
= 1,
6665 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.vdisr_el2
) },
6666 { .name
= "VSESR_EL2", .state
= ARM_CP_STATE_BOTH
,
6667 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 2, .opc2
= 3,
6668 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.vsesr_el2
) },
6672 * Return the exception level to which exceptions should be taken
6673 * via SVEAccessTrap. This excludes the check for whether the exception
6674 * should be routed through AArch64.AdvSIMDFPAccessTrap. That can easily
6675 * be found by testing 0 < fp_exception_el < sve_exception_el.
6677 * C.f. the ARM pseudocode function CheckSVEEnabled. Note that the
6678 * pseudocode does *not* separate out the FP trap checks, but has them
6679 * all in one function.
6681 int sve_exception_el(CPUARMState
*env
, int el
)
6683 #ifndef CONFIG_USER_ONLY
6684 if (el
<= 1 && !el_is_in_host(env
, el
)) {
6685 switch (FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, ZEN
)) {
6697 if (el
<= 2 && arm_is_el2_enabled(env
)) {
6698 /* CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE). */
6699 if (env
->cp15
.hcr_el2
& HCR_E2H
) {
6700 switch (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, ZEN
)) {
6702 if (el
!= 0 || !(env
->cp15
.hcr_el2
& HCR_TGE
)) {
6711 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TZ
)) {
6717 /* CPTR_EL3. Since EZ is negative we must check for EL3. */
6718 if (arm_feature(env
, ARM_FEATURE_EL3
)
6719 && !FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, EZ
)) {
6727 * Return the exception level to which exceptions should be taken for SME.
6728 * C.f. the ARM pseudocode function CheckSMEAccess.
6730 int sme_exception_el(CPUARMState
*env
, int el
)
6732 #ifndef CONFIG_USER_ONLY
6733 if (el
<= 1 && !el_is_in_host(env
, el
)) {
6734 switch (FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, SMEN
)) {
6746 if (el
<= 2 && arm_is_el2_enabled(env
)) {
6747 /* CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE). */
6748 if (env
->cp15
.hcr_el2
& HCR_E2H
) {
6749 switch (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, SMEN
)) {
6751 if (el
!= 0 || !(env
->cp15
.hcr_el2
& HCR_TGE
)) {
6760 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TSM
)) {
6766 /* CPTR_EL3. Since ESM is negative we must check for EL3. */
6767 if (arm_feature(env
, ARM_FEATURE_EL3
)
6768 && !FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, ESM
)) {
6776 * Given that SVE is enabled, return the vector length for EL.
6778 uint32_t sve_vqm1_for_el_sm(CPUARMState
*env
, int el
, bool sm
)
6780 ARMCPU
*cpu
= env_archcpu(env
);
6781 uint64_t *cr
= env
->vfp
.zcr_el
;
6782 uint32_t map
= cpu
->sve_vq
.map
;
6783 uint32_t len
= ARM_MAX_VQ
- 1;
6786 cr
= env
->vfp
.smcr_el
;
6787 map
= cpu
->sme_vq
.map
;
6790 if (el
<= 1 && !el_is_in_host(env
, el
)) {
6791 len
= MIN(len
, 0xf & (uint32_t)cr
[1]);
6793 if (el
<= 2 && arm_feature(env
, ARM_FEATURE_EL2
)) {
6794 len
= MIN(len
, 0xf & (uint32_t)cr
[2]);
6796 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
6797 len
= MIN(len
, 0xf & (uint32_t)cr
[3]);
6800 map
&= MAKE_64BIT_MASK(0, len
+ 1);
6802 return 31 - clz32(map
);
6805 /* Bit 0 is always set for Normal SVE -- not so for Streaming SVE. */
6807 return ctz32(cpu
->sme_vq
.map
);
6810 uint32_t sve_vqm1_for_el(CPUARMState
*env
, int el
)
6812 return sve_vqm1_for_el_sm(env
, el
, FIELD_EX64(env
->svcr
, SVCR
, SM
));
6815 static void zcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6818 int cur_el
= arm_current_el(env
);
6819 int old_len
= sve_vqm1_for_el(env
, cur_el
);
6822 /* Bits other than [3:0] are RAZ/WI. */
6823 QEMU_BUILD_BUG_ON(ARM_MAX_VQ
> 16);
6824 raw_write(env
, ri
, value
& 0xf);
6827 * Because we arrived here, we know both FP and SVE are enabled;
6828 * otherwise we would have trapped access to the ZCR_ELn register.
6830 new_len
= sve_vqm1_for_el(env
, cur_el
);
6831 if (new_len
< old_len
) {
6832 aarch64_sve_narrow_vq(env
, new_len
+ 1);
6836 static const ARMCPRegInfo zcr_reginfo
[] = {
6837 { .name
= "ZCR_EL1", .state
= ARM_CP_STATE_AA64
,
6838 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 2, .opc2
= 0,
6839 .access
= PL1_RW
, .type
= ARM_CP_SVE
,
6840 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[1]),
6841 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
6842 { .name
= "ZCR_EL2", .state
= ARM_CP_STATE_AA64
,
6843 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 0,
6844 .access
= PL2_RW
, .type
= ARM_CP_SVE
,
6845 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[2]),
6846 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
6847 { .name
= "ZCR_EL3", .state
= ARM_CP_STATE_AA64
,
6848 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 2, .opc2
= 0,
6849 .access
= PL3_RW
, .type
= ARM_CP_SVE
,
6850 .fieldoffset
= offsetof(CPUARMState
, vfp
.zcr_el
[3]),
6851 .writefn
= zcr_write
, .raw_writefn
= raw_write
},
6854 #ifdef TARGET_AARCH64
6855 static CPAccessResult
access_tpidr2(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6858 int el
= arm_current_el(env
);
6861 uint64_t sctlr
= arm_sctlr(env
, el
);
6862 if (!(sctlr
& SCTLR_EnTP2
)) {
6863 return CP_ACCESS_TRAP
;
6866 /* TODO: FEAT_FGT */
6868 && arm_feature(env
, ARM_FEATURE_EL3
)
6869 && !(env
->cp15
.scr_el3
& SCR_ENTP2
)) {
6870 return CP_ACCESS_TRAP_EL3
;
6872 return CP_ACCESS_OK
;
6875 static CPAccessResult
access_esm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6878 /* TODO: FEAT_FGT for SMPRI_EL1 but not SMPRIMAP_EL2 */
6879 if (arm_current_el(env
) < 3
6880 && arm_feature(env
, ARM_FEATURE_EL3
)
6881 && !FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, ESM
)) {
6882 return CP_ACCESS_TRAP_EL3
;
6884 return CP_ACCESS_OK
;
6888 static void arm_reset_sve_state(CPUARMState
*env
)
6890 memset(env
->vfp
.zregs
, 0, sizeof(env
->vfp
.zregs
));
6891 /* Recall that FFR is stored as pregs[16]. */
6892 memset(env
->vfp
.pregs
, 0, sizeof(env
->vfp
.pregs
));
6893 vfp_set_fpcr(env
, 0x0800009f);
6896 void aarch64_set_svcr(CPUARMState
*env
, uint64_t new, uint64_t mask
)
6898 uint64_t change
= (env
->svcr
^ new) & mask
;
6903 env
->svcr
^= change
;
6905 if (change
& R_SVCR_SM_MASK
) {
6906 arm_reset_sve_state(env
);
6912 * SetPSTATE_ZA zeros on enable and disable. We can zero this only
6913 * on enable: while disabled, the storage is inaccessible and the
6914 * value does not matter. We're not saving the storage in vmstate
6915 * when disabled either.
6917 if (change
& new & R_SVCR_ZA_MASK
) {
6918 memset(env
->zarray
, 0, sizeof(env
->zarray
));
6921 if (tcg_enabled()) {
6922 arm_rebuild_hflags(env
);
6926 static void svcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6929 aarch64_set_svcr(env
, value
, -1);
6932 static void smcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
6935 int cur_el
= arm_current_el(env
);
6936 int old_len
= sve_vqm1_for_el(env
, cur_el
);
6939 QEMU_BUILD_BUG_ON(ARM_MAX_VQ
> R_SMCR_LEN_MASK
+ 1);
6940 value
&= R_SMCR_LEN_MASK
| R_SMCR_FA64_MASK
;
6941 raw_write(env
, ri
, value
);
6944 * Note that it is CONSTRAINED UNPREDICTABLE what happens to ZA storage
6945 * when SVL is widened (old values kept, or zeros). Choose to keep the
6946 * current values for simplicity. But for QEMU internals, we must still
6947 * apply the narrower SVL to the Zregs and Pregs -- see the comment
6948 * above aarch64_sve_narrow_vq.
6950 new_len
= sve_vqm1_for_el(env
, cur_el
);
6951 if (new_len
< old_len
) {
6952 aarch64_sve_narrow_vq(env
, new_len
+ 1);
6956 static const ARMCPRegInfo sme_reginfo
[] = {
6957 { .name
= "TPIDR2_EL0", .state
= ARM_CP_STATE_AA64
,
6958 .opc0
= 3, .opc1
= 3, .crn
= 13, .crm
= 0, .opc2
= 5,
6959 .access
= PL0_RW
, .accessfn
= access_tpidr2
,
6960 .fgt
= FGT_NTPIDR2_EL0
,
6961 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr2_el0
) },
6962 { .name
= "SVCR", .state
= ARM_CP_STATE_AA64
,
6963 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 2,
6964 .access
= PL0_RW
, .type
= ARM_CP_SME
,
6965 .fieldoffset
= offsetof(CPUARMState
, svcr
),
6966 .writefn
= svcr_write
, .raw_writefn
= raw_write
},
6967 { .name
= "SMCR_EL1", .state
= ARM_CP_STATE_AA64
,
6968 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 2, .opc2
= 6,
6969 .access
= PL1_RW
, .type
= ARM_CP_SME
,
6970 .fieldoffset
= offsetof(CPUARMState
, vfp
.smcr_el
[1]),
6971 .writefn
= smcr_write
, .raw_writefn
= raw_write
},
6972 { .name
= "SMCR_EL2", .state
= ARM_CP_STATE_AA64
,
6973 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 6,
6974 .access
= PL2_RW
, .type
= ARM_CP_SME
,
6975 .fieldoffset
= offsetof(CPUARMState
, vfp
.smcr_el
[2]),
6976 .writefn
= smcr_write
, .raw_writefn
= raw_write
},
6977 { .name
= "SMCR_EL3", .state
= ARM_CP_STATE_AA64
,
6978 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 2, .opc2
= 6,
6979 .access
= PL3_RW
, .type
= ARM_CP_SME
,
6980 .fieldoffset
= offsetof(CPUARMState
, vfp
.smcr_el
[3]),
6981 .writefn
= smcr_write
, .raw_writefn
= raw_write
},
6982 { .name
= "SMIDR_EL1", .state
= ARM_CP_STATE_AA64
,
6983 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 6,
6984 .access
= PL1_R
, .accessfn
= access_aa64_tid1
,
6986 * IMPLEMENTOR = 0 (software)
6987 * REVISION = 0 (implementation defined)
6988 * SMPS = 0 (no streaming execution priority in QEMU)
6989 * AFFINITY = 0 (streaming sve mode not shared with other PEs)
6991 .type
= ARM_CP_CONST
, .resetvalue
= 0, },
6993 * Because SMIDR_EL1.SMPS is 0, SMPRI_EL1 and SMPRIMAP_EL2 are RES 0.
6995 { .name
= "SMPRI_EL1", .state
= ARM_CP_STATE_AA64
,
6996 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 2, .opc2
= 4,
6997 .access
= PL1_RW
, .accessfn
= access_esm
,
6998 .fgt
= FGT_NSMPRI_EL1
,
6999 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7000 { .name
= "SMPRIMAP_EL2", .state
= ARM_CP_STATE_AA64
,
7001 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 2, .opc2
= 5,
7002 .access
= PL2_RW
, .accessfn
= access_esm
,
7003 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7006 static void tlbi_aa64_paall_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7009 CPUState
*cs
= env_cpu(env
);
7014 static void gpccr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7017 /* L0GPTSZ is RO; other bits not mentioned are RES0. */
7018 uint64_t rw_mask
= R_GPCCR_PPS_MASK
| R_GPCCR_IRGN_MASK
|
7019 R_GPCCR_ORGN_MASK
| R_GPCCR_SH_MASK
| R_GPCCR_PGS_MASK
|
7020 R_GPCCR_GPC_MASK
| R_GPCCR_GPCP_MASK
;
7022 env
->cp15
.gpccr_el3
= (value
& rw_mask
) | (env
->cp15
.gpccr_el3
& ~rw_mask
);
7025 static void gpccr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7027 env
->cp15
.gpccr_el3
= FIELD_DP64(0, GPCCR
, L0GPTSZ
,
7028 env_archcpu(env
)->reset_l0gptsz
);
7031 static void tlbi_aa64_paallos_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7034 CPUState
*cs
= env_cpu(env
);
7036 tlb_flush_all_cpus_synced(cs
);
7039 static const ARMCPRegInfo rme_reginfo
[] = {
7040 { .name
= "GPCCR_EL3", .state
= ARM_CP_STATE_AA64
,
7041 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 1, .opc2
= 6,
7042 .access
= PL3_RW
, .writefn
= gpccr_write
, .resetfn
= gpccr_reset
,
7043 .fieldoffset
= offsetof(CPUARMState
, cp15
.gpccr_el3
) },
7044 { .name
= "GPTBR_EL3", .state
= ARM_CP_STATE_AA64
,
7045 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 1, .opc2
= 4,
7046 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.gptbr_el3
) },
7047 { .name
= "MFAR_EL3", .state
= ARM_CP_STATE_AA64
,
7048 .opc0
= 3, .opc1
= 6, .crn
= 6, .crm
= 0, .opc2
= 5,
7049 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mfar_el3
) },
7050 { .name
= "TLBI_PAALL", .state
= ARM_CP_STATE_AA64
,
7051 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 4,
7052 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7053 .writefn
= tlbi_aa64_paall_write
},
7054 { .name
= "TLBI_PAALLOS", .state
= ARM_CP_STATE_AA64
,
7055 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 4,
7056 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7057 .writefn
= tlbi_aa64_paallos_write
},
7059 * QEMU does not have a way to invalidate by physical address, thus
7060 * invalidating a range of physical addresses is accomplished by
7061 * flushing all tlb entries in the outer shareable domain,
7062 * just like PAALLOS.
7064 { .name
= "TLBI_RPALOS", .state
= ARM_CP_STATE_AA64
,
7065 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 4, .opc2
= 7,
7066 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7067 .writefn
= tlbi_aa64_paallos_write
},
7068 { .name
= "TLBI_RPAOS", .state
= ARM_CP_STATE_AA64
,
7069 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 4, .opc2
= 3,
7070 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7071 .writefn
= tlbi_aa64_paallos_write
},
7072 { .name
= "DC_CIPAPA", .state
= ARM_CP_STATE_AA64
,
7073 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 14, .opc2
= 1,
7074 .access
= PL3_W
, .type
= ARM_CP_NOP
},
7077 static const ARMCPRegInfo rme_mte_reginfo
[] = {
7078 { .name
= "DC_CIGDPAPA", .state
= ARM_CP_STATE_AA64
,
7079 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 14, .opc2
= 5,
7080 .access
= PL3_W
, .type
= ARM_CP_NOP
},
7082 #endif /* TARGET_AARCH64 */
7084 static void define_pmu_regs(ARMCPU
*cpu
)
7087 * v7 performance monitor control register: same implementor
7088 * field as main ID register, and we implement four counters in
7089 * addition to the cycle count register.
7091 unsigned int i
, pmcrn
= pmu_num_counters(&cpu
->env
);
7092 ARMCPRegInfo pmcr
= {
7093 .name
= "PMCR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 0,
7095 .fgt
= FGT_PMCR_EL0
,
7096 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7097 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcr
),
7098 .accessfn
= pmreg_access
, .writefn
= pmcr_write
,
7099 .raw_writefn
= raw_write
,
7101 ARMCPRegInfo pmcr64
= {
7102 .name
= "PMCR_EL0", .state
= ARM_CP_STATE_AA64
,
7103 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 0,
7104 .access
= PL0_RW
, .accessfn
= pmreg_access
,
7105 .fgt
= FGT_PMCR_EL0
,
7107 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcr
),
7108 .resetvalue
= cpu
->isar
.reset_pmcr_el0
,
7109 .writefn
= pmcr_write
, .raw_writefn
= raw_write
,
7112 define_one_arm_cp_reg(cpu
, &pmcr
);
7113 define_one_arm_cp_reg(cpu
, &pmcr64
);
7114 for (i
= 0; i
< pmcrn
; i
++) {
7115 char *pmevcntr_name
= g_strdup_printf("PMEVCNTR%d", i
);
7116 char *pmevcntr_el0_name
= g_strdup_printf("PMEVCNTR%d_EL0", i
);
7117 char *pmevtyper_name
= g_strdup_printf("PMEVTYPER%d", i
);
7118 char *pmevtyper_el0_name
= g_strdup_printf("PMEVTYPER%d_EL0", i
);
7119 ARMCPRegInfo pmev_regs
[] = {
7120 { .name
= pmevcntr_name
, .cp
= 15, .crn
= 14,
7121 .crm
= 8 | (3 & (i
>> 3)), .opc1
= 0, .opc2
= i
& 7,
7122 .access
= PL0_RW
, .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7123 .fgt
= FGT_PMEVCNTRN_EL0
,
7124 .readfn
= pmevcntr_readfn
, .writefn
= pmevcntr_writefn
,
7125 .accessfn
= pmreg_access_xevcntr
},
7126 { .name
= pmevcntr_el0_name
, .state
= ARM_CP_STATE_AA64
,
7127 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 8 | (3 & (i
>> 3)),
7128 .opc2
= i
& 7, .access
= PL0_RW
, .accessfn
= pmreg_access_xevcntr
,
7130 .fgt
= FGT_PMEVCNTRN_EL0
,
7131 .readfn
= pmevcntr_readfn
, .writefn
= pmevcntr_writefn
,
7132 .raw_readfn
= pmevcntr_rawread
,
7133 .raw_writefn
= pmevcntr_rawwrite
},
7134 { .name
= pmevtyper_name
, .cp
= 15, .crn
= 14,
7135 .crm
= 12 | (3 & (i
>> 3)), .opc1
= 0, .opc2
= i
& 7,
7136 .access
= PL0_RW
, .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
7137 .fgt
= FGT_PMEVTYPERN_EL0
,
7138 .readfn
= pmevtyper_readfn
, .writefn
= pmevtyper_writefn
,
7139 .accessfn
= pmreg_access
},
7140 { .name
= pmevtyper_el0_name
, .state
= ARM_CP_STATE_AA64
,
7141 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 12 | (3 & (i
>> 3)),
7142 .opc2
= i
& 7, .access
= PL0_RW
, .accessfn
= pmreg_access
,
7143 .fgt
= FGT_PMEVTYPERN_EL0
,
7145 .readfn
= pmevtyper_readfn
, .writefn
= pmevtyper_writefn
,
7146 .raw_writefn
= pmevtyper_rawwrite
},
7148 define_arm_cp_regs(cpu
, pmev_regs
);
7149 g_free(pmevcntr_name
);
7150 g_free(pmevcntr_el0_name
);
7151 g_free(pmevtyper_name
);
7152 g_free(pmevtyper_el0_name
);
7154 if (cpu_isar_feature(aa32_pmuv3p1
, cpu
)) {
7155 ARMCPRegInfo v81_pmu_regs
[] = {
7156 { .name
= "PMCEID2", .state
= ARM_CP_STATE_AA32
,
7157 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 4,
7158 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7159 .fgt
= FGT_PMCEIDN_EL0
,
7160 .resetvalue
= extract64(cpu
->pmceid0
, 32, 32) },
7161 { .name
= "PMCEID3", .state
= ARM_CP_STATE_AA32
,
7162 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 5,
7163 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7164 .fgt
= FGT_PMCEIDN_EL0
,
7165 .resetvalue
= extract64(cpu
->pmceid1
, 32, 32) },
7167 define_arm_cp_regs(cpu
, v81_pmu_regs
);
7169 if (cpu_isar_feature(any_pmuv3p4
, cpu
)) {
7170 static const ARMCPRegInfo v84_pmmir
= {
7171 .name
= "PMMIR_EL1", .state
= ARM_CP_STATE_BOTH
,
7172 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 6,
7173 .access
= PL1_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
7174 .fgt
= FGT_PMMIR_EL1
,
7177 define_one_arm_cp_reg(cpu
, &v84_pmmir
);
7181 #ifndef CONFIG_USER_ONLY
7183 * We don't know until after realize whether there's a GICv3
7184 * attached, and that is what registers the gicv3 sysregs.
7185 * So we have to fill in the GIC fields in ID_PFR/ID_PFR1_EL1/ID_AA64PFR0_EL1
7188 static uint64_t id_pfr1_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7190 ARMCPU
*cpu
= env_archcpu(env
);
7191 uint64_t pfr1
= cpu
->isar
.id_pfr1
;
7193 if (env
->gicv3state
) {
7199 static uint64_t id_aa64pfr0_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7201 ARMCPU
*cpu
= env_archcpu(env
);
7202 uint64_t pfr0
= cpu
->isar
.id_aa64pfr0
;
7204 if (env
->gicv3state
) {
7212 * Shared logic between LORID and the rest of the LOR* registers.
7213 * Secure state exclusion has already been dealt with.
7215 static CPAccessResult
access_lor_ns(CPUARMState
*env
,
7216 const ARMCPRegInfo
*ri
, bool isread
)
7218 int el
= arm_current_el(env
);
7220 if (el
< 2 && (arm_hcr_el2_eff(env
) & HCR_TLOR
)) {
7221 return CP_ACCESS_TRAP_EL2
;
7223 if (el
< 3 && (env
->cp15
.scr_el3
& SCR_TLOR
)) {
7224 return CP_ACCESS_TRAP_EL3
;
7226 return CP_ACCESS_OK
;
7229 static CPAccessResult
access_lor_other(CPUARMState
*env
,
7230 const ARMCPRegInfo
*ri
, bool isread
)
7232 if (arm_is_secure_below_el3(env
)) {
7233 /* Access denied in secure mode. */
7234 return CP_ACCESS_TRAP
;
7236 return access_lor_ns(env
, ri
, isread
);
7240 * A trivial implementation of ARMv8.1-LOR leaves all of these
7241 * registers fixed at 0, which indicates that there are zero
7242 * supported Limited Ordering regions.
7244 static const ARMCPRegInfo lor_reginfo
[] = {
7245 { .name
= "LORSA_EL1", .state
= ARM_CP_STATE_AA64
,
7246 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 0,
7247 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7248 .fgt
= FGT_LORSA_EL1
,
7249 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7250 { .name
= "LOREA_EL1", .state
= ARM_CP_STATE_AA64
,
7251 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 1,
7252 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7253 .fgt
= FGT_LOREA_EL1
,
7254 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7255 { .name
= "LORN_EL1", .state
= ARM_CP_STATE_AA64
,
7256 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 2,
7257 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7258 .fgt
= FGT_LORN_EL1
,
7259 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7260 { .name
= "LORC_EL1", .state
= ARM_CP_STATE_AA64
,
7261 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 3,
7262 .access
= PL1_RW
, .accessfn
= access_lor_other
,
7263 .fgt
= FGT_LORC_EL1
,
7264 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7265 { .name
= "LORID_EL1", .state
= ARM_CP_STATE_AA64
,
7266 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 4, .opc2
= 7,
7267 .access
= PL1_R
, .accessfn
= access_lor_ns
,
7268 .fgt
= FGT_LORID_EL1
,
7269 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
7272 #ifdef TARGET_AARCH64
7273 static CPAccessResult
access_pauth(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7276 int el
= arm_current_el(env
);
7279 arm_is_el2_enabled(env
) &&
7280 !(arm_hcr_el2_eff(env
) & HCR_APK
)) {
7281 return CP_ACCESS_TRAP_EL2
;
7284 arm_feature(env
, ARM_FEATURE_EL3
) &&
7285 !(env
->cp15
.scr_el3
& SCR_APK
)) {
7286 return CP_ACCESS_TRAP_EL3
;
7288 return CP_ACCESS_OK
;
7291 static const ARMCPRegInfo pauth_reginfo
[] = {
7292 { .name
= "APDAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7293 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 0,
7294 .access
= PL1_RW
, .accessfn
= access_pauth
,
7296 .fieldoffset
= offsetof(CPUARMState
, keys
.apda
.lo
) },
7297 { .name
= "APDAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7298 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 1,
7299 .access
= PL1_RW
, .accessfn
= access_pauth
,
7301 .fieldoffset
= offsetof(CPUARMState
, keys
.apda
.hi
) },
7302 { .name
= "APDBKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7303 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 2,
7304 .access
= PL1_RW
, .accessfn
= access_pauth
,
7306 .fieldoffset
= offsetof(CPUARMState
, keys
.apdb
.lo
) },
7307 { .name
= "APDBKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7308 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 2, .opc2
= 3,
7309 .access
= PL1_RW
, .accessfn
= access_pauth
,
7311 .fieldoffset
= offsetof(CPUARMState
, keys
.apdb
.hi
) },
7312 { .name
= "APGAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7313 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 3, .opc2
= 0,
7314 .access
= PL1_RW
, .accessfn
= access_pauth
,
7316 .fieldoffset
= offsetof(CPUARMState
, keys
.apga
.lo
) },
7317 { .name
= "APGAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7318 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 3, .opc2
= 1,
7319 .access
= PL1_RW
, .accessfn
= access_pauth
,
7321 .fieldoffset
= offsetof(CPUARMState
, keys
.apga
.hi
) },
7322 { .name
= "APIAKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7323 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 0,
7324 .access
= PL1_RW
, .accessfn
= access_pauth
,
7326 .fieldoffset
= offsetof(CPUARMState
, keys
.apia
.lo
) },
7327 { .name
= "APIAKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7328 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 1,
7329 .access
= PL1_RW
, .accessfn
= access_pauth
,
7331 .fieldoffset
= offsetof(CPUARMState
, keys
.apia
.hi
) },
7332 { .name
= "APIBKEYLO_EL1", .state
= ARM_CP_STATE_AA64
,
7333 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 2,
7334 .access
= PL1_RW
, .accessfn
= access_pauth
,
7336 .fieldoffset
= offsetof(CPUARMState
, keys
.apib
.lo
) },
7337 { .name
= "APIBKEYHI_EL1", .state
= ARM_CP_STATE_AA64
,
7338 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 1, .opc2
= 3,
7339 .access
= PL1_RW
, .accessfn
= access_pauth
,
7341 .fieldoffset
= offsetof(CPUARMState
, keys
.apib
.hi
) },
7344 static const ARMCPRegInfo tlbirange_reginfo
[] = {
7345 { .name
= "TLBI_RVAE1IS", .state
= ARM_CP_STATE_AA64
,
7346 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 1,
7347 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
7348 .fgt
= FGT_TLBIRVAE1IS
,
7349 .writefn
= tlbi_aa64_rvae1is_write
},
7350 { .name
= "TLBI_RVAAE1IS", .state
= ARM_CP_STATE_AA64
,
7351 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 3,
7352 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
7353 .fgt
= FGT_TLBIRVAAE1IS
,
7354 .writefn
= tlbi_aa64_rvae1is_write
},
7355 { .name
= "TLBI_RVALE1IS", .state
= ARM_CP_STATE_AA64
,
7356 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 5,
7357 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
7358 .fgt
= FGT_TLBIRVALE1IS
,
7359 .writefn
= tlbi_aa64_rvae1is_write
},
7360 { .name
= "TLBI_RVAALE1IS", .state
= ARM_CP_STATE_AA64
,
7361 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 2, .opc2
= 7,
7362 .access
= PL1_W
, .accessfn
= access_ttlbis
, .type
= ARM_CP_NO_RAW
,
7363 .fgt
= FGT_TLBIRVAALE1IS
,
7364 .writefn
= tlbi_aa64_rvae1is_write
},
7365 { .name
= "TLBI_RVAE1OS", .state
= ARM_CP_STATE_AA64
,
7366 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
7367 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7368 .fgt
= FGT_TLBIRVAE1OS
,
7369 .writefn
= tlbi_aa64_rvae1is_write
},
7370 { .name
= "TLBI_RVAAE1OS", .state
= ARM_CP_STATE_AA64
,
7371 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 3,
7372 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7373 .fgt
= FGT_TLBIRVAAE1OS
,
7374 .writefn
= tlbi_aa64_rvae1is_write
},
7375 { .name
= "TLBI_RVALE1OS", .state
= ARM_CP_STATE_AA64
,
7376 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 5,
7377 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7378 .fgt
= FGT_TLBIRVALE1OS
,
7379 .writefn
= tlbi_aa64_rvae1is_write
},
7380 { .name
= "TLBI_RVAALE1OS", .state
= ARM_CP_STATE_AA64
,
7381 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 7,
7382 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7383 .fgt
= FGT_TLBIRVAALE1OS
,
7384 .writefn
= tlbi_aa64_rvae1is_write
},
7385 { .name
= "TLBI_RVAE1", .state
= ARM_CP_STATE_AA64
,
7386 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
7387 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
7388 .fgt
= FGT_TLBIRVAE1
,
7389 .writefn
= tlbi_aa64_rvae1_write
},
7390 { .name
= "TLBI_RVAAE1", .state
= ARM_CP_STATE_AA64
,
7391 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 3,
7392 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
7393 .fgt
= FGT_TLBIRVAAE1
,
7394 .writefn
= tlbi_aa64_rvae1_write
},
7395 { .name
= "TLBI_RVALE1", .state
= ARM_CP_STATE_AA64
,
7396 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 5,
7397 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
7398 .fgt
= FGT_TLBIRVALE1
,
7399 .writefn
= tlbi_aa64_rvae1_write
},
7400 { .name
= "TLBI_RVAALE1", .state
= ARM_CP_STATE_AA64
,
7401 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 7,
7402 .access
= PL1_W
, .accessfn
= access_ttlb
, .type
= ARM_CP_NO_RAW
,
7403 .fgt
= FGT_TLBIRVAALE1
,
7404 .writefn
= tlbi_aa64_rvae1_write
},
7405 { .name
= "TLBI_RIPAS2E1IS", .state
= ARM_CP_STATE_AA64
,
7406 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 2,
7407 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7408 .writefn
= tlbi_aa64_ripas2e1is_write
},
7409 { .name
= "TLBI_RIPAS2LE1IS", .state
= ARM_CP_STATE_AA64
,
7410 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 6,
7411 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7412 .writefn
= tlbi_aa64_ripas2e1is_write
},
7413 { .name
= "TLBI_RVAE2IS", .state
= ARM_CP_STATE_AA64
,
7414 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 2, .opc2
= 1,
7415 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7416 .writefn
= tlbi_aa64_rvae2is_write
},
7417 { .name
= "TLBI_RVALE2IS", .state
= ARM_CP_STATE_AA64
,
7418 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 2, .opc2
= 5,
7419 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7420 .writefn
= tlbi_aa64_rvae2is_write
},
7421 { .name
= "TLBI_RIPAS2E1", .state
= ARM_CP_STATE_AA64
,
7422 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 2,
7423 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7424 .writefn
= tlbi_aa64_ripas2e1_write
},
7425 { .name
= "TLBI_RIPAS2LE1", .state
= ARM_CP_STATE_AA64
,
7426 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 6,
7427 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7428 .writefn
= tlbi_aa64_ripas2e1_write
},
7429 { .name
= "TLBI_RVAE2OS", .state
= ARM_CP_STATE_AA64
,
7430 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 5, .opc2
= 1,
7431 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7432 .writefn
= tlbi_aa64_rvae2is_write
},
7433 { .name
= "TLBI_RVALE2OS", .state
= ARM_CP_STATE_AA64
,
7434 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 5, .opc2
= 5,
7435 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7436 .writefn
= tlbi_aa64_rvae2is_write
},
7437 { .name
= "TLBI_RVAE2", .state
= ARM_CP_STATE_AA64
,
7438 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 6, .opc2
= 1,
7439 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7440 .writefn
= tlbi_aa64_rvae2_write
},
7441 { .name
= "TLBI_RVALE2", .state
= ARM_CP_STATE_AA64
,
7442 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 6, .opc2
= 5,
7443 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7444 .writefn
= tlbi_aa64_rvae2_write
},
7445 { .name
= "TLBI_RVAE3IS", .state
= ARM_CP_STATE_AA64
,
7446 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 2, .opc2
= 1,
7447 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7448 .writefn
= tlbi_aa64_rvae3is_write
},
7449 { .name
= "TLBI_RVALE3IS", .state
= ARM_CP_STATE_AA64
,
7450 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 2, .opc2
= 5,
7451 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7452 .writefn
= tlbi_aa64_rvae3is_write
},
7453 { .name
= "TLBI_RVAE3OS", .state
= ARM_CP_STATE_AA64
,
7454 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 5, .opc2
= 1,
7455 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7456 .writefn
= tlbi_aa64_rvae3is_write
},
7457 { .name
= "TLBI_RVALE3OS", .state
= ARM_CP_STATE_AA64
,
7458 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 5, .opc2
= 5,
7459 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7460 .writefn
= tlbi_aa64_rvae3is_write
},
7461 { .name
= "TLBI_RVAE3", .state
= ARM_CP_STATE_AA64
,
7462 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 6, .opc2
= 1,
7463 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7464 .writefn
= tlbi_aa64_rvae3_write
},
7465 { .name
= "TLBI_RVALE3", .state
= ARM_CP_STATE_AA64
,
7466 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 6, .opc2
= 5,
7467 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7468 .writefn
= tlbi_aa64_rvae3_write
},
7471 static const ARMCPRegInfo tlbios_reginfo
[] = {
7472 { .name
= "TLBI_VMALLE1OS", .state
= ARM_CP_STATE_AA64
,
7473 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 0,
7474 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7475 .fgt
= FGT_TLBIVMALLE1OS
,
7476 .writefn
= tlbi_aa64_vmalle1is_write
},
7477 { .name
= "TLBI_VAE1OS", .state
= ARM_CP_STATE_AA64
,
7478 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 1,
7479 .fgt
= FGT_TLBIVAE1OS
,
7480 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7481 .writefn
= tlbi_aa64_vae1is_write
},
7482 { .name
= "TLBI_ASIDE1OS", .state
= ARM_CP_STATE_AA64
,
7483 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 2,
7484 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7485 .fgt
= FGT_TLBIASIDE1OS
,
7486 .writefn
= tlbi_aa64_vmalle1is_write
},
7487 { .name
= "TLBI_VAAE1OS", .state
= ARM_CP_STATE_AA64
,
7488 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 3,
7489 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7490 .fgt
= FGT_TLBIVAAE1OS
,
7491 .writefn
= tlbi_aa64_vae1is_write
},
7492 { .name
= "TLBI_VALE1OS", .state
= ARM_CP_STATE_AA64
,
7493 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 5,
7494 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7495 .fgt
= FGT_TLBIVALE1OS
,
7496 .writefn
= tlbi_aa64_vae1is_write
},
7497 { .name
= "TLBI_VAALE1OS", .state
= ARM_CP_STATE_AA64
,
7498 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 1, .opc2
= 7,
7499 .access
= PL1_W
, .accessfn
= access_ttlbos
, .type
= ARM_CP_NO_RAW
,
7500 .fgt
= FGT_TLBIVAALE1OS
,
7501 .writefn
= tlbi_aa64_vae1is_write
},
7502 { .name
= "TLBI_ALLE2OS", .state
= ARM_CP_STATE_AA64
,
7503 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 0,
7504 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7505 .writefn
= tlbi_aa64_alle2is_write
},
7506 { .name
= "TLBI_VAE2OS", .state
= ARM_CP_STATE_AA64
,
7507 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 1,
7508 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7509 .writefn
= tlbi_aa64_vae2is_write
},
7510 { .name
= "TLBI_ALLE1OS", .state
= ARM_CP_STATE_AA64
,
7511 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 4,
7512 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7513 .writefn
= tlbi_aa64_alle1is_write
},
7514 { .name
= "TLBI_VALE2OS", .state
= ARM_CP_STATE_AA64
,
7515 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 5,
7516 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_EL3_NO_EL2_UNDEF
,
7517 .writefn
= tlbi_aa64_vae2is_write
},
7518 { .name
= "TLBI_VMALLS12E1OS", .state
= ARM_CP_STATE_AA64
,
7519 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 1, .opc2
= 6,
7520 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
7521 .writefn
= tlbi_aa64_alle1is_write
},
7522 { .name
= "TLBI_IPAS2E1OS", .state
= ARM_CP_STATE_AA64
,
7523 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 0,
7524 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7525 { .name
= "TLBI_RIPAS2E1OS", .state
= ARM_CP_STATE_AA64
,
7526 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 3,
7527 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7528 { .name
= "TLBI_IPAS2LE1OS", .state
= ARM_CP_STATE_AA64
,
7529 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 4,
7530 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7531 { .name
= "TLBI_RIPAS2LE1OS", .state
= ARM_CP_STATE_AA64
,
7532 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 7,
7533 .access
= PL2_W
, .type
= ARM_CP_NOP
},
7534 { .name
= "TLBI_ALLE3OS", .state
= ARM_CP_STATE_AA64
,
7535 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 0,
7536 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7537 .writefn
= tlbi_aa64_alle3is_write
},
7538 { .name
= "TLBI_VAE3OS", .state
= ARM_CP_STATE_AA64
,
7539 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 1,
7540 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7541 .writefn
= tlbi_aa64_vae3is_write
},
7542 { .name
= "TLBI_VALE3OS", .state
= ARM_CP_STATE_AA64
,
7543 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 1, .opc2
= 5,
7544 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
7545 .writefn
= tlbi_aa64_vae3is_write
},
7548 static uint64_t rndr_readfn(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7553 /* Success sets NZCV = 0000. */
7554 env
->NF
= env
->CF
= env
->VF
= 0, env
->ZF
= 1;
7556 if (qemu_guest_getrandom(&ret
, sizeof(ret
), &err
) < 0) {
7558 * ??? Failed, for unknown reasons in the crypto subsystem.
7559 * The best we can do is log the reason and return the
7560 * timed-out indication to the guest. There is no reason
7561 * we know to expect this failure to be transitory, so the
7562 * guest may well hang retrying the operation.
7564 qemu_log_mask(LOG_UNIMP
, "%s: Crypto failure: %s",
7565 ri
->name
, error_get_pretty(err
));
7568 env
->ZF
= 0; /* NZCF = 0100 */
7574 /* We do not support re-seeding, so the two registers operate the same. */
7575 static const ARMCPRegInfo rndr_reginfo
[] = {
7576 { .name
= "RNDR", .state
= ARM_CP_STATE_AA64
,
7577 .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
| ARM_CP_IO
,
7578 .opc0
= 3, .opc1
= 3, .crn
= 2, .crm
= 4, .opc2
= 0,
7579 .access
= PL0_R
, .readfn
= rndr_readfn
},
7580 { .name
= "RNDRRS", .state
= ARM_CP_STATE_AA64
,
7581 .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
| ARM_CP_IO
,
7582 .opc0
= 3, .opc1
= 3, .crn
= 2, .crm
= 4, .opc2
= 1,
7583 .access
= PL0_R
, .readfn
= rndr_readfn
},
7586 static void dccvap_writefn(CPUARMState
*env
, const ARMCPRegInfo
*opaque
,
7589 ARMCPU
*cpu
= env_archcpu(env
);
7590 /* CTR_EL0 System register -> DminLine, bits [19:16] */
7591 uint64_t dline_size
= 4 << ((cpu
->ctr
>> 16) & 0xF);
7592 uint64_t vaddr_in
= (uint64_t) value
;
7593 uint64_t vaddr
= vaddr_in
& ~(dline_size
- 1);
7595 int mem_idx
= cpu_mmu_index(env
, false);
7597 /* This won't be crossing page boundaries */
7598 haddr
= probe_read(env
, vaddr
, dline_size
, mem_idx
, GETPC());
7600 #ifndef CONFIG_USER_ONLY
7605 /* RCU lock is already being held */
7606 mr
= memory_region_from_host(haddr
, &offset
);
7609 memory_region_writeback(mr
, offset
, dline_size
);
7611 #endif /*CONFIG_USER_ONLY*/
7615 static const ARMCPRegInfo dcpop_reg
[] = {
7616 { .name
= "DC_CVAP", .state
= ARM_CP_STATE_AA64
,
7617 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 1,
7618 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
,
7620 .accessfn
= aa64_cacheop_poc_access
, .writefn
= dccvap_writefn
},
7623 static const ARMCPRegInfo dcpodp_reg
[] = {
7624 { .name
= "DC_CVADP", .state
= ARM_CP_STATE_AA64
,
7625 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 1,
7626 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_SUPPRESS_TB_END
,
7628 .accessfn
= aa64_cacheop_poc_access
, .writefn
= dccvap_writefn
},
7631 static CPAccessResult
access_aa64_tid5(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7634 if ((arm_current_el(env
) < 2) && (arm_hcr_el2_eff(env
) & HCR_TID5
)) {
7635 return CP_ACCESS_TRAP_EL2
;
7638 return CP_ACCESS_OK
;
7641 static CPAccessResult
access_mte(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7644 int el
= arm_current_el(env
);
7646 if (el
< 2 && arm_is_el2_enabled(env
)) {
7647 uint64_t hcr
= arm_hcr_el2_eff(env
);
7648 if (!(hcr
& HCR_ATA
) && (!(hcr
& HCR_E2H
) || !(hcr
& HCR_TGE
))) {
7649 return CP_ACCESS_TRAP_EL2
;
7653 arm_feature(env
, ARM_FEATURE_EL3
) &&
7654 !(env
->cp15
.scr_el3
& SCR_ATA
)) {
7655 return CP_ACCESS_TRAP_EL3
;
7657 return CP_ACCESS_OK
;
7660 static uint64_t tco_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7662 return env
->pstate
& PSTATE_TCO
;
7665 static void tco_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
7667 env
->pstate
= (env
->pstate
& ~PSTATE_TCO
) | (val
& PSTATE_TCO
);
7670 static const ARMCPRegInfo mte_reginfo
[] = {
7671 { .name
= "TFSRE0_EL1", .state
= ARM_CP_STATE_AA64
,
7672 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 6, .opc2
= 1,
7673 .access
= PL1_RW
, .accessfn
= access_mte
,
7674 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[0]) },
7675 { .name
= "TFSR_EL1", .state
= ARM_CP_STATE_AA64
,
7676 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 6, .opc2
= 0,
7677 .access
= PL1_RW
, .accessfn
= access_mte
,
7678 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[1]) },
7679 { .name
= "TFSR_EL2", .state
= ARM_CP_STATE_AA64
,
7680 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 6, .opc2
= 0,
7681 .access
= PL2_RW
, .accessfn
= access_mte
,
7682 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[2]) },
7683 { .name
= "TFSR_EL3", .state
= ARM_CP_STATE_AA64
,
7684 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 6, .opc2
= 0,
7686 .fieldoffset
= offsetof(CPUARMState
, cp15
.tfsr_el
[3]) },
7687 { .name
= "RGSR_EL1", .state
= ARM_CP_STATE_AA64
,
7688 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 5,
7689 .access
= PL1_RW
, .accessfn
= access_mte
,
7690 .fieldoffset
= offsetof(CPUARMState
, cp15
.rgsr_el1
) },
7691 { .name
= "GCR_EL1", .state
= ARM_CP_STATE_AA64
,
7692 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 6,
7693 .access
= PL1_RW
, .accessfn
= access_mte
,
7694 .fieldoffset
= offsetof(CPUARMState
, cp15
.gcr_el1
) },
7695 { .name
= "GMID_EL1", .state
= ARM_CP_STATE_AA64
,
7696 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 4,
7697 .access
= PL1_R
, .accessfn
= access_aa64_tid5
,
7698 .type
= ARM_CP_CONST
, .resetvalue
= GMID_EL1_BS
},
7699 { .name
= "TCO", .state
= ARM_CP_STATE_AA64
,
7700 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 7,
7701 .type
= ARM_CP_NO_RAW
,
7702 .access
= PL0_RW
, .readfn
= tco_read
, .writefn
= tco_write
},
7703 { .name
= "DC_IGVAC", .state
= ARM_CP_STATE_AA64
,
7704 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 3,
7705 .type
= ARM_CP_NOP
, .access
= PL1_W
,
7707 .accessfn
= aa64_cacheop_poc_access
},
7708 { .name
= "DC_IGSW", .state
= ARM_CP_STATE_AA64
,
7709 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 4,
7711 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7712 { .name
= "DC_IGDVAC", .state
= ARM_CP_STATE_AA64
,
7713 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 5,
7714 .type
= ARM_CP_NOP
, .access
= PL1_W
,
7716 .accessfn
= aa64_cacheop_poc_access
},
7717 { .name
= "DC_IGDSW", .state
= ARM_CP_STATE_AA64
,
7718 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 6,
7720 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7721 { .name
= "DC_CGSW", .state
= ARM_CP_STATE_AA64
,
7722 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 4,
7724 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7725 { .name
= "DC_CGDSW", .state
= ARM_CP_STATE_AA64
,
7726 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 6,
7728 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7729 { .name
= "DC_CIGSW", .state
= ARM_CP_STATE_AA64
,
7730 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 4,
7732 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7733 { .name
= "DC_CIGDSW", .state
= ARM_CP_STATE_AA64
,
7734 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 6,
7736 .type
= ARM_CP_NOP
, .access
= PL1_W
, .accessfn
= access_tsw
},
7739 static const ARMCPRegInfo mte_tco_ro_reginfo
[] = {
7740 { .name
= "TCO", .state
= ARM_CP_STATE_AA64
,
7741 .opc0
= 3, .opc1
= 3, .crn
= 4, .crm
= 2, .opc2
= 7,
7742 .type
= ARM_CP_CONST
, .access
= PL0_RW
, },
7745 static const ARMCPRegInfo mte_el0_cacheop_reginfo
[] = {
7746 { .name
= "DC_CGVAC", .state
= ARM_CP_STATE_AA64
,
7747 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 3,
7748 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7750 .accessfn
= aa64_cacheop_poc_access
},
7751 { .name
= "DC_CGDVAC", .state
= ARM_CP_STATE_AA64
,
7752 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 5,
7753 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7755 .accessfn
= aa64_cacheop_poc_access
},
7756 { .name
= "DC_CGVAP", .state
= ARM_CP_STATE_AA64
,
7757 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 3,
7758 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7760 .accessfn
= aa64_cacheop_poc_access
},
7761 { .name
= "DC_CGDVAP", .state
= ARM_CP_STATE_AA64
,
7762 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 12, .opc2
= 5,
7763 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7765 .accessfn
= aa64_cacheop_poc_access
},
7766 { .name
= "DC_CGVADP", .state
= ARM_CP_STATE_AA64
,
7767 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 3,
7768 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7770 .accessfn
= aa64_cacheop_poc_access
},
7771 { .name
= "DC_CGDVADP", .state
= ARM_CP_STATE_AA64
,
7772 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 13, .opc2
= 5,
7773 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7775 .accessfn
= aa64_cacheop_poc_access
},
7776 { .name
= "DC_CIGVAC", .state
= ARM_CP_STATE_AA64
,
7777 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 3,
7778 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7780 .accessfn
= aa64_cacheop_poc_access
},
7781 { .name
= "DC_CIGDVAC", .state
= ARM_CP_STATE_AA64
,
7782 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 5,
7783 .type
= ARM_CP_NOP
, .access
= PL0_W
,
7785 .accessfn
= aa64_cacheop_poc_access
},
7786 { .name
= "DC_GVA", .state
= ARM_CP_STATE_AA64
,
7787 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 3,
7788 .access
= PL0_W
, .type
= ARM_CP_DC_GVA
,
7789 #ifndef CONFIG_USER_ONLY
7790 /* Avoid overhead of an access check that always passes in user-mode */
7791 .accessfn
= aa64_zva_access
,
7795 { .name
= "DC_GZVA", .state
= ARM_CP_STATE_AA64
,
7796 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 4,
7797 .access
= PL0_W
, .type
= ARM_CP_DC_GZVA
,
7798 #ifndef CONFIG_USER_ONLY
7799 /* Avoid overhead of an access check that always passes in user-mode */
7800 .accessfn
= aa64_zva_access
,
7806 static CPAccessResult
access_scxtnum(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7809 uint64_t hcr
= arm_hcr_el2_eff(env
);
7810 int el
= arm_current_el(env
);
7812 if (el
== 0 && !((hcr
& HCR_E2H
) && (hcr
& HCR_TGE
))) {
7813 if (env
->cp15
.sctlr_el
[1] & SCTLR_TSCXT
) {
7814 if (hcr
& HCR_TGE
) {
7815 return CP_ACCESS_TRAP_EL2
;
7817 return CP_ACCESS_TRAP
;
7819 } else if (el
< 2 && (env
->cp15
.sctlr_el
[2] & SCTLR_TSCXT
)) {
7820 return CP_ACCESS_TRAP_EL2
;
7822 if (el
< 2 && arm_is_el2_enabled(env
) && !(hcr
& HCR_ENSCXT
)) {
7823 return CP_ACCESS_TRAP_EL2
;
7826 && arm_feature(env
, ARM_FEATURE_EL3
)
7827 && !(env
->cp15
.scr_el3
& SCR_ENSCXT
)) {
7828 return CP_ACCESS_TRAP_EL3
;
7830 return CP_ACCESS_OK
;
7833 static const ARMCPRegInfo scxtnum_reginfo
[] = {
7834 { .name
= "SCXTNUM_EL0", .state
= ARM_CP_STATE_AA64
,
7835 .opc0
= 3, .opc1
= 3, .crn
= 13, .crm
= 0, .opc2
= 7,
7836 .access
= PL0_RW
, .accessfn
= access_scxtnum
,
7837 .fgt
= FGT_SCXTNUM_EL0
,
7838 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[0]) },
7839 { .name
= "SCXTNUM_EL1", .state
= ARM_CP_STATE_AA64
,
7840 .opc0
= 3, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 7,
7841 .access
= PL1_RW
, .accessfn
= access_scxtnum
,
7842 .fgt
= FGT_SCXTNUM_EL1
,
7843 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[1]) },
7844 { .name
= "SCXTNUM_EL2", .state
= ARM_CP_STATE_AA64
,
7845 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 7,
7846 .access
= PL2_RW
, .accessfn
= access_scxtnum
,
7847 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[2]) },
7848 { .name
= "SCXTNUM_EL3", .state
= ARM_CP_STATE_AA64
,
7849 .opc0
= 3, .opc1
= 6, .crn
= 13, .crm
= 0, .opc2
= 7,
7851 .fieldoffset
= offsetof(CPUARMState
, scxtnum_el
[3]) },
7854 static CPAccessResult
access_fgt(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7857 if (arm_current_el(env
) == 2 &&
7858 arm_feature(env
, ARM_FEATURE_EL3
) && !(env
->cp15
.scr_el3
& SCR_FGTEN
)) {
7859 return CP_ACCESS_TRAP_EL3
;
7861 return CP_ACCESS_OK
;
7864 static const ARMCPRegInfo fgt_reginfo
[] = {
7865 { .name
= "HFGRTR_EL2", .state
= ARM_CP_STATE_AA64
,
7866 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 4,
7867 .access
= PL2_RW
, .accessfn
= access_fgt
,
7868 .fieldoffset
= offsetof(CPUARMState
, cp15
.fgt_read
[FGTREG_HFGRTR
]) },
7869 { .name
= "HFGWTR_EL2", .state
= ARM_CP_STATE_AA64
,
7870 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 5,
7871 .access
= PL2_RW
, .accessfn
= access_fgt
,
7872 .fieldoffset
= offsetof(CPUARMState
, cp15
.fgt_write
[FGTREG_HFGWTR
]) },
7873 { .name
= "HDFGRTR_EL2", .state
= ARM_CP_STATE_AA64
,
7874 .opc0
= 3, .opc1
= 4, .crn
= 3, .crm
= 1, .opc2
= 4,
7875 .access
= PL2_RW
, .accessfn
= access_fgt
,
7876 .fieldoffset
= offsetof(CPUARMState
, cp15
.fgt_read
[FGTREG_HDFGRTR
]) },
7877 { .name
= "HDFGWTR_EL2", .state
= ARM_CP_STATE_AA64
,
7878 .opc0
= 3, .opc1
= 4, .crn
= 3, .crm
= 1, .opc2
= 5,
7879 .access
= PL2_RW
, .accessfn
= access_fgt
,
7880 .fieldoffset
= offsetof(CPUARMState
, cp15
.fgt_write
[FGTREG_HDFGWTR
]) },
7881 { .name
= "HFGITR_EL2", .state
= ARM_CP_STATE_AA64
,
7882 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 6,
7883 .access
= PL2_RW
, .accessfn
= access_fgt
,
7884 .fieldoffset
= offsetof(CPUARMState
, cp15
.fgt_exec
[FGTREG_HFGITR
]) },
7886 #endif /* TARGET_AARCH64 */
7888 static CPAccessResult
access_predinv(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7891 int el
= arm_current_el(env
);
7894 uint64_t sctlr
= arm_sctlr(env
, el
);
7895 if (!(sctlr
& SCTLR_EnRCTX
)) {
7896 return CP_ACCESS_TRAP
;
7898 } else if (el
== 1) {
7899 uint64_t hcr
= arm_hcr_el2_eff(env
);
7901 return CP_ACCESS_TRAP_EL2
;
7904 return CP_ACCESS_OK
;
7907 static const ARMCPRegInfo predinv_reginfo
[] = {
7908 { .name
= "CFP_RCTX", .state
= ARM_CP_STATE_AA64
,
7909 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 4,
7911 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7912 { .name
= "DVP_RCTX", .state
= ARM_CP_STATE_AA64
,
7913 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 5,
7915 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7916 { .name
= "CPP_RCTX", .state
= ARM_CP_STATE_AA64
,
7917 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 3, .opc2
= 7,
7919 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7921 * Note the AArch32 opcodes have a different OPC1.
7923 { .name
= "CFPRCTX", .state
= ARM_CP_STATE_AA32
,
7924 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 4,
7926 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7927 { .name
= "DVPRCTX", .state
= ARM_CP_STATE_AA32
,
7928 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 5,
7930 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7931 { .name
= "CPPRCTX", .state
= ARM_CP_STATE_AA32
,
7932 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 3, .opc2
= 7,
7934 .type
= ARM_CP_NOP
, .access
= PL0_W
, .accessfn
= access_predinv
},
7937 static uint64_t ccsidr2_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
7939 /* Read the high 32 bits of the current CCSIDR */
7940 return extract64(ccsidr_read(env
, ri
), 32, 32);
7943 static const ARMCPRegInfo ccsidr2_reginfo
[] = {
7944 { .name
= "CCSIDR2", .state
= ARM_CP_STATE_BOTH
,
7945 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 2,
7947 .accessfn
= access_tid4
,
7948 .readfn
= ccsidr2_read
, .type
= ARM_CP_NO_RAW
},
7951 static CPAccessResult
access_aa64_tid3(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7954 if ((arm_current_el(env
) < 2) && (arm_hcr_el2_eff(env
) & HCR_TID3
)) {
7955 return CP_ACCESS_TRAP_EL2
;
7958 return CP_ACCESS_OK
;
7961 static CPAccessResult
access_aa32_tid3(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7964 if (arm_feature(env
, ARM_FEATURE_V8
)) {
7965 return access_aa64_tid3(env
, ri
, isread
);
7968 return CP_ACCESS_OK
;
7971 static CPAccessResult
access_jazelle(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
7974 if (arm_current_el(env
) == 1 && (arm_hcr_el2_eff(env
) & HCR_TID0
)) {
7975 return CP_ACCESS_TRAP_EL2
;
7978 return CP_ACCESS_OK
;
7981 static CPAccessResult
access_joscr_jmcr(CPUARMState
*env
,
7982 const ARMCPRegInfo
*ri
, bool isread
)
7985 * HSTR.TJDBX traps JOSCR and JMCR accesses, but it exists only
7986 * in v7A, not in v8A.
7988 if (!arm_feature(env
, ARM_FEATURE_V8
) &&
7989 arm_current_el(env
) < 2 && !arm_is_secure_below_el3(env
) &&
7990 (env
->cp15
.hstr_el2
& HSTR_TJDBX
)) {
7991 return CP_ACCESS_TRAP_EL2
;
7993 return CP_ACCESS_OK
;
7996 static const ARMCPRegInfo jazelle_regs
[] = {
7998 .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 7, .opc2
= 0,
7999 .access
= PL1_R
, .accessfn
= access_jazelle
,
8000 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8002 .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 7, .opc2
= 0,
8003 .accessfn
= access_joscr_jmcr
,
8004 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8006 .cp
= 14, .crn
= 2, .crm
= 0, .opc1
= 7, .opc2
= 0,
8007 .accessfn
= access_joscr_jmcr
,
8008 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8011 static const ARMCPRegInfo contextidr_el2
= {
8012 .name
= "CONTEXTIDR_EL2", .state
= ARM_CP_STATE_AA64
,
8013 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 1,
8015 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[2])
8018 static const ARMCPRegInfo vhe_reginfo
[] = {
8019 { .name
= "TTBR1_EL2", .state
= ARM_CP_STATE_AA64
,
8020 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 1,
8021 .access
= PL2_RW
, .writefn
= vmsa_tcr_ttbr_el2_write
,
8022 .raw_writefn
= raw_write
,
8023 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr1_el
[2]) },
8024 #ifndef CONFIG_USER_ONLY
8025 { .name
= "CNTHV_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
8026 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 2,
8028 offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYPVIRT
].cval
),
8029 .type
= ARM_CP_IO
, .access
= PL2_RW
,
8030 .writefn
= gt_hv_cval_write
, .raw_writefn
= raw_write
},
8031 { .name
= "CNTHV_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
8032 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 0,
8033 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL2_RW
,
8034 .resetfn
= gt_hv_timer_reset
,
8035 .readfn
= gt_hv_tval_read
, .writefn
= gt_hv_tval_write
},
8036 { .name
= "CNTHV_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
8038 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 3, .opc2
= 1,
8040 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYPVIRT
].ctl
),
8041 .writefn
= gt_hv_ctl_write
, .raw_writefn
= raw_write
},
8042 { .name
= "CNTP_CTL_EL02", .state
= ARM_CP_STATE_AA64
,
8043 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 1,
8044 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
8045 .access
= PL2_RW
, .accessfn
= e2h_access
,
8046 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
8047 .writefn
= gt_phys_ctl_write
, .raw_writefn
= raw_write
},
8048 { .name
= "CNTV_CTL_EL02", .state
= ARM_CP_STATE_AA64
,
8049 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 1,
8050 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
8051 .access
= PL2_RW
, .accessfn
= e2h_access
,
8052 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
8053 .writefn
= gt_virt_ctl_write
, .raw_writefn
= raw_write
},
8054 { .name
= "CNTP_TVAL_EL02", .state
= ARM_CP_STATE_AA64
,
8055 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 0,
8056 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
| ARM_CP_ALIAS
,
8057 .access
= PL2_RW
, .accessfn
= e2h_access
,
8058 .readfn
= gt_phys_tval_read
, .writefn
= gt_phys_tval_write
},
8059 { .name
= "CNTV_TVAL_EL02", .state
= ARM_CP_STATE_AA64
,
8060 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 0,
8061 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
| ARM_CP_ALIAS
,
8062 .access
= PL2_RW
, .accessfn
= e2h_access
,
8063 .readfn
= gt_virt_tval_read
, .writefn
= gt_virt_tval_write
},
8064 { .name
= "CNTP_CVAL_EL02", .state
= ARM_CP_STATE_AA64
,
8065 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 2, .opc2
= 2,
8066 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
8067 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
8068 .access
= PL2_RW
, .accessfn
= e2h_access
,
8069 .writefn
= gt_phys_cval_write
, .raw_writefn
= raw_write
},
8070 { .name
= "CNTV_CVAL_EL02", .state
= ARM_CP_STATE_AA64
,
8071 .opc0
= 3, .opc1
= 5, .crn
= 14, .crm
= 3, .opc2
= 2,
8072 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
8073 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
8074 .access
= PL2_RW
, .accessfn
= e2h_access
,
8075 .writefn
= gt_virt_cval_write
, .raw_writefn
= raw_write
},
8079 #ifndef CONFIG_USER_ONLY
8080 static const ARMCPRegInfo ats1e1_reginfo
[] = {
8081 { .name
= "AT_S1E1RP", .state
= ARM_CP_STATE_AA64
,
8082 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 0,
8083 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
8084 .fgt
= FGT_ATS1E1RP
,
8085 .writefn
= ats_write64
},
8086 { .name
= "AT_S1E1WP", .state
= ARM_CP_STATE_AA64
,
8087 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 1,
8088 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
8089 .fgt
= FGT_ATS1E1WP
,
8090 .writefn
= ats_write64
},
8093 static const ARMCPRegInfo ats1cp_reginfo
[] = {
8094 { .name
= "ATS1CPRP",
8095 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 0,
8096 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
8097 .writefn
= ats_write
},
8098 { .name
= "ATS1CPWP",
8099 .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 9, .opc2
= 1,
8100 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
| ARM_CP_RAISES_EXC
,
8101 .writefn
= ats_write
},
8106 * ACTLR2 and HACTLR2 map to ACTLR_EL1[63:32] and
8107 * ACTLR_EL2[63:32]. They exist only if the ID_MMFR4.AC2 field
8108 * is non-zero, which is never for ARMv7, optionally in ARMv8
8109 * and mandatorily for ARMv8.2 and up.
8110 * ACTLR2 is banked for S and NS if EL3 is AArch32. Since QEMU's
8111 * implementation is RAZ/WI we can ignore this detail, as we
8114 static const ARMCPRegInfo actlr2_hactlr2_reginfo
[] = {
8115 { .name
= "ACTLR2", .state
= ARM_CP_STATE_AA32
,
8116 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 3,
8117 .access
= PL1_RW
, .accessfn
= access_tacr
,
8118 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8119 { .name
= "HACTLR2", .state
= ARM_CP_STATE_AA32
,
8120 .cp
= 15, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 3,
8121 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
8125 void register_cp_regs_for_features(ARMCPU
*cpu
)
8127 /* Register all the coprocessor registers based on feature bits */
8128 CPUARMState
*env
= &cpu
->env
;
8129 if (arm_feature(env
, ARM_FEATURE_M
)) {
8130 /* M profile has no coprocessor registers */
8134 define_arm_cp_regs(cpu
, cp_reginfo
);
8135 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
8137 * Must go early as it is full of wildcards that may be
8138 * overridden by later definitions.
8140 define_arm_cp_regs(cpu
, not_v8_cp_reginfo
);
8143 if (arm_feature(env
, ARM_FEATURE_V6
)) {
8144 /* The ID registers all have impdef reset values */
8145 ARMCPRegInfo v6_idregs
[] = {
8146 { .name
= "ID_PFR0", .state
= ARM_CP_STATE_BOTH
,
8147 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 0,
8148 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8149 .accessfn
= access_aa32_tid3
,
8150 .resetvalue
= cpu
->isar
.id_pfr0
},
8152 * ID_PFR1 is not a plain ARM_CP_CONST because we don't know
8153 * the value of the GIC field until after we define these regs.
8155 { .name
= "ID_PFR1", .state
= ARM_CP_STATE_BOTH
,
8156 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 1,
8157 .access
= PL1_R
, .type
= ARM_CP_NO_RAW
,
8158 .accessfn
= access_aa32_tid3
,
8159 #ifdef CONFIG_USER_ONLY
8160 .type
= ARM_CP_CONST
,
8161 .resetvalue
= cpu
->isar
.id_pfr1
,
8163 .type
= ARM_CP_NO_RAW
,
8164 .accessfn
= access_aa32_tid3
,
8165 .readfn
= id_pfr1_read
,
8166 .writefn
= arm_cp_write_ignore
8169 { .name
= "ID_DFR0", .state
= ARM_CP_STATE_BOTH
,
8170 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 2,
8171 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8172 .accessfn
= access_aa32_tid3
,
8173 .resetvalue
= cpu
->isar
.id_dfr0
},
8174 { .name
= "ID_AFR0", .state
= ARM_CP_STATE_BOTH
,
8175 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 3,
8176 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8177 .accessfn
= access_aa32_tid3
,
8178 .resetvalue
= cpu
->id_afr0
},
8179 { .name
= "ID_MMFR0", .state
= ARM_CP_STATE_BOTH
,
8180 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 4,
8181 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8182 .accessfn
= access_aa32_tid3
,
8183 .resetvalue
= cpu
->isar
.id_mmfr0
},
8184 { .name
= "ID_MMFR1", .state
= ARM_CP_STATE_BOTH
,
8185 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 5,
8186 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8187 .accessfn
= access_aa32_tid3
,
8188 .resetvalue
= cpu
->isar
.id_mmfr1
},
8189 { .name
= "ID_MMFR2", .state
= ARM_CP_STATE_BOTH
,
8190 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 6,
8191 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8192 .accessfn
= access_aa32_tid3
,
8193 .resetvalue
= cpu
->isar
.id_mmfr2
},
8194 { .name
= "ID_MMFR3", .state
= ARM_CP_STATE_BOTH
,
8195 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 7,
8196 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8197 .accessfn
= access_aa32_tid3
,
8198 .resetvalue
= cpu
->isar
.id_mmfr3
},
8199 { .name
= "ID_ISAR0", .state
= ARM_CP_STATE_BOTH
,
8200 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 0,
8201 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8202 .accessfn
= access_aa32_tid3
,
8203 .resetvalue
= cpu
->isar
.id_isar0
},
8204 { .name
= "ID_ISAR1", .state
= ARM_CP_STATE_BOTH
,
8205 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 1,
8206 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8207 .accessfn
= access_aa32_tid3
,
8208 .resetvalue
= cpu
->isar
.id_isar1
},
8209 { .name
= "ID_ISAR2", .state
= ARM_CP_STATE_BOTH
,
8210 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 2,
8211 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8212 .accessfn
= access_aa32_tid3
,
8213 .resetvalue
= cpu
->isar
.id_isar2
},
8214 { .name
= "ID_ISAR3", .state
= ARM_CP_STATE_BOTH
,
8215 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 3,
8216 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8217 .accessfn
= access_aa32_tid3
,
8218 .resetvalue
= cpu
->isar
.id_isar3
},
8219 { .name
= "ID_ISAR4", .state
= ARM_CP_STATE_BOTH
,
8220 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 4,
8221 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8222 .accessfn
= access_aa32_tid3
,
8223 .resetvalue
= cpu
->isar
.id_isar4
},
8224 { .name
= "ID_ISAR5", .state
= ARM_CP_STATE_BOTH
,
8225 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 5,
8226 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8227 .accessfn
= access_aa32_tid3
,
8228 .resetvalue
= cpu
->isar
.id_isar5
},
8229 { .name
= "ID_MMFR4", .state
= ARM_CP_STATE_BOTH
,
8230 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 6,
8231 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8232 .accessfn
= access_aa32_tid3
,
8233 .resetvalue
= cpu
->isar
.id_mmfr4
},
8234 { .name
= "ID_ISAR6", .state
= ARM_CP_STATE_BOTH
,
8235 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 7,
8236 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8237 .accessfn
= access_aa32_tid3
,
8238 .resetvalue
= cpu
->isar
.id_isar6
},
8240 define_arm_cp_regs(cpu
, v6_idregs
);
8241 define_arm_cp_regs(cpu
, v6_cp_reginfo
);
8243 define_arm_cp_regs(cpu
, not_v6_cp_reginfo
);
8245 if (arm_feature(env
, ARM_FEATURE_V6K
)) {
8246 define_arm_cp_regs(cpu
, v6k_cp_reginfo
);
8248 if (arm_feature(env
, ARM_FEATURE_V7MP
) &&
8249 !arm_feature(env
, ARM_FEATURE_PMSA
)) {
8250 define_arm_cp_regs(cpu
, v7mp_cp_reginfo
);
8252 if (arm_feature(env
, ARM_FEATURE_V7VE
)) {
8253 define_arm_cp_regs(cpu
, pmovsset_cp_reginfo
);
8255 if (arm_feature(env
, ARM_FEATURE_V7
)) {
8256 ARMCPRegInfo clidr
= {
8257 .name
= "CLIDR", .state
= ARM_CP_STATE_BOTH
,
8258 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 1,
8259 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8260 .accessfn
= access_tid4
,
8261 .fgt
= FGT_CLIDR_EL1
,
8262 .resetvalue
= cpu
->clidr
8264 define_one_arm_cp_reg(cpu
, &clidr
);
8265 define_arm_cp_regs(cpu
, v7_cp_reginfo
);
8266 define_debug_regs(cpu
);
8267 define_pmu_regs(cpu
);
8269 define_arm_cp_regs(cpu
, not_v7_cp_reginfo
);
8271 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8273 * v8 ID registers, which all have impdef reset values.
8274 * Note that within the ID register ranges the unused slots
8275 * must all RAZ, not UNDEF; future architecture versions may
8276 * define new registers here.
8277 * ID registers which are AArch64 views of the AArch32 ID registers
8278 * which already existed in v6 and v7 are handled elsewhere,
8282 ARMCPRegInfo v8_idregs
[] = {
8284 * ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST in system
8285 * emulation because we don't know the right value for the
8286 * GIC field until after we define these regs.
8288 { .name
= "ID_AA64PFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8289 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 0,
8291 #ifdef CONFIG_USER_ONLY
8292 .type
= ARM_CP_CONST
,
8293 .resetvalue
= cpu
->isar
.id_aa64pfr0
8295 .type
= ARM_CP_NO_RAW
,
8296 .accessfn
= access_aa64_tid3
,
8297 .readfn
= id_aa64pfr0_read
,
8298 .writefn
= arm_cp_write_ignore
8301 { .name
= "ID_AA64PFR1_EL1", .state
= ARM_CP_STATE_AA64
,
8302 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 1,
8303 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8304 .accessfn
= access_aa64_tid3
,
8305 .resetvalue
= cpu
->isar
.id_aa64pfr1
},
8306 { .name
= "ID_AA64PFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8307 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 2,
8308 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8309 .accessfn
= access_aa64_tid3
,
8311 { .name
= "ID_AA64PFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8312 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 3,
8313 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8314 .accessfn
= access_aa64_tid3
,
8316 { .name
= "ID_AA64ZFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8317 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 4,
8318 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8319 .accessfn
= access_aa64_tid3
,
8320 .resetvalue
= cpu
->isar
.id_aa64zfr0
},
8321 { .name
= "ID_AA64SMFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8322 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 5,
8323 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8324 .accessfn
= access_aa64_tid3
,
8325 .resetvalue
= cpu
->isar
.id_aa64smfr0
},
8326 { .name
= "ID_AA64PFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8327 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 6,
8328 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8329 .accessfn
= access_aa64_tid3
,
8331 { .name
= "ID_AA64PFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8332 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 7,
8333 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8334 .accessfn
= access_aa64_tid3
,
8336 { .name
= "ID_AA64DFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8337 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 0,
8338 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8339 .accessfn
= access_aa64_tid3
,
8340 .resetvalue
= cpu
->isar
.id_aa64dfr0
},
8341 { .name
= "ID_AA64DFR1_EL1", .state
= ARM_CP_STATE_AA64
,
8342 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 1,
8343 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8344 .accessfn
= access_aa64_tid3
,
8345 .resetvalue
= cpu
->isar
.id_aa64dfr1
},
8346 { .name
= "ID_AA64DFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8347 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 2,
8348 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8349 .accessfn
= access_aa64_tid3
,
8351 { .name
= "ID_AA64DFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8352 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 3,
8353 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8354 .accessfn
= access_aa64_tid3
,
8356 { .name
= "ID_AA64AFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8357 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 4,
8358 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8359 .accessfn
= access_aa64_tid3
,
8360 .resetvalue
= cpu
->id_aa64afr0
},
8361 { .name
= "ID_AA64AFR1_EL1", .state
= ARM_CP_STATE_AA64
,
8362 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 5,
8363 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8364 .accessfn
= access_aa64_tid3
,
8365 .resetvalue
= cpu
->id_aa64afr1
},
8366 { .name
= "ID_AA64AFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8367 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 6,
8368 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8369 .accessfn
= access_aa64_tid3
,
8371 { .name
= "ID_AA64AFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8372 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 7,
8373 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8374 .accessfn
= access_aa64_tid3
,
8376 { .name
= "ID_AA64ISAR0_EL1", .state
= ARM_CP_STATE_AA64
,
8377 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 0,
8378 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8379 .accessfn
= access_aa64_tid3
,
8380 .resetvalue
= cpu
->isar
.id_aa64isar0
},
8381 { .name
= "ID_AA64ISAR1_EL1", .state
= ARM_CP_STATE_AA64
,
8382 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 1,
8383 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8384 .accessfn
= access_aa64_tid3
,
8385 .resetvalue
= cpu
->isar
.id_aa64isar1
},
8386 { .name
= "ID_AA64ISAR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8387 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 2,
8388 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8389 .accessfn
= access_aa64_tid3
,
8391 { .name
= "ID_AA64ISAR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8392 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 3,
8393 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8394 .accessfn
= access_aa64_tid3
,
8396 { .name
= "ID_AA64ISAR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8397 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 4,
8398 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8399 .accessfn
= access_aa64_tid3
,
8401 { .name
= "ID_AA64ISAR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8402 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 5,
8403 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8404 .accessfn
= access_aa64_tid3
,
8406 { .name
= "ID_AA64ISAR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8407 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 6,
8408 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8409 .accessfn
= access_aa64_tid3
,
8411 { .name
= "ID_AA64ISAR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8412 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 7,
8413 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8414 .accessfn
= access_aa64_tid3
,
8416 { .name
= "ID_AA64MMFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8417 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 0,
8418 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8419 .accessfn
= access_aa64_tid3
,
8420 .resetvalue
= cpu
->isar
.id_aa64mmfr0
},
8421 { .name
= "ID_AA64MMFR1_EL1", .state
= ARM_CP_STATE_AA64
,
8422 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 1,
8423 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8424 .accessfn
= access_aa64_tid3
,
8425 .resetvalue
= cpu
->isar
.id_aa64mmfr1
},
8426 { .name
= "ID_AA64MMFR2_EL1", .state
= ARM_CP_STATE_AA64
,
8427 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 2,
8428 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8429 .accessfn
= access_aa64_tid3
,
8430 .resetvalue
= cpu
->isar
.id_aa64mmfr2
},
8431 { .name
= "ID_AA64MMFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8432 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 3,
8433 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8434 .accessfn
= access_aa64_tid3
,
8436 { .name
= "ID_AA64MMFR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8437 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 4,
8438 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8439 .accessfn
= access_aa64_tid3
,
8441 { .name
= "ID_AA64MMFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8442 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 5,
8443 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8444 .accessfn
= access_aa64_tid3
,
8446 { .name
= "ID_AA64MMFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8447 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 6,
8448 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8449 .accessfn
= access_aa64_tid3
,
8451 { .name
= "ID_AA64MMFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
8452 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 7,
8453 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8454 .accessfn
= access_aa64_tid3
,
8456 { .name
= "MVFR0_EL1", .state
= ARM_CP_STATE_AA64
,
8457 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 0,
8458 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8459 .accessfn
= access_aa64_tid3
,
8460 .resetvalue
= cpu
->isar
.mvfr0
},
8461 { .name
= "MVFR1_EL1", .state
= ARM_CP_STATE_AA64
,
8462 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 1,
8463 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8464 .accessfn
= access_aa64_tid3
,
8465 .resetvalue
= cpu
->isar
.mvfr1
},
8466 { .name
= "MVFR2_EL1", .state
= ARM_CP_STATE_AA64
,
8467 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 2,
8468 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8469 .accessfn
= access_aa64_tid3
,
8470 .resetvalue
= cpu
->isar
.mvfr2
},
8472 * "0, c0, c3, {0,1,2}" are the encodings corresponding to
8473 * AArch64 MVFR[012]_EL1. Define the STATE_AA32 encoding
8474 * as RAZ, since it is in the "reserved for future ID
8475 * registers, RAZ" part of the AArch32 encoding space.
8477 { .name
= "RES_0_C0_C3_0", .state
= ARM_CP_STATE_AA32
,
8478 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 0,
8479 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8480 .accessfn
= access_aa64_tid3
,
8482 { .name
= "RES_0_C0_C3_1", .state
= ARM_CP_STATE_AA32
,
8483 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 1,
8484 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8485 .accessfn
= access_aa64_tid3
,
8487 { .name
= "RES_0_C0_C3_2", .state
= ARM_CP_STATE_AA32
,
8488 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 2,
8489 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8490 .accessfn
= access_aa64_tid3
,
8493 * Other encodings in "0, c0, c3, ..." are STATE_BOTH because
8494 * they're also RAZ for AArch64, and in v8 are gradually
8495 * being filled with AArch64-view-of-AArch32-ID-register
8496 * for new ID registers.
8498 { .name
= "RES_0_C0_C3_3", .state
= ARM_CP_STATE_BOTH
,
8499 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 3,
8500 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8501 .accessfn
= access_aa64_tid3
,
8503 { .name
= "ID_PFR2", .state
= ARM_CP_STATE_BOTH
,
8504 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 4,
8505 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8506 .accessfn
= access_aa64_tid3
,
8507 .resetvalue
= cpu
->isar
.id_pfr2
},
8508 { .name
= "ID_DFR1", .state
= ARM_CP_STATE_BOTH
,
8509 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 5,
8510 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8511 .accessfn
= access_aa64_tid3
,
8512 .resetvalue
= cpu
->isar
.id_dfr1
},
8513 { .name
= "ID_MMFR5", .state
= ARM_CP_STATE_BOTH
,
8514 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 6,
8515 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8516 .accessfn
= access_aa64_tid3
,
8517 .resetvalue
= cpu
->isar
.id_mmfr5
},
8518 { .name
= "RES_0_C0_C3_7", .state
= ARM_CP_STATE_BOTH
,
8519 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 7,
8520 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8521 .accessfn
= access_aa64_tid3
,
8523 { .name
= "PMCEID0", .state
= ARM_CP_STATE_AA32
,
8524 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 6,
8525 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
8526 .fgt
= FGT_PMCEIDN_EL0
,
8527 .resetvalue
= extract64(cpu
->pmceid0
, 0, 32) },
8528 { .name
= "PMCEID0_EL0", .state
= ARM_CP_STATE_AA64
,
8529 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 6,
8530 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
8531 .fgt
= FGT_PMCEIDN_EL0
,
8532 .resetvalue
= cpu
->pmceid0
},
8533 { .name
= "PMCEID1", .state
= ARM_CP_STATE_AA32
,
8534 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 7,
8535 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
8536 .fgt
= FGT_PMCEIDN_EL0
,
8537 .resetvalue
= extract64(cpu
->pmceid1
, 0, 32) },
8538 { .name
= "PMCEID1_EL0", .state
= ARM_CP_STATE_AA64
,
8539 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 7,
8540 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
8541 .fgt
= FGT_PMCEIDN_EL0
,
8542 .resetvalue
= cpu
->pmceid1
},
8544 #ifdef CONFIG_USER_ONLY
8545 static const ARMCPRegUserSpaceInfo v8_user_idregs
[] = {
8546 { .name
= "ID_AA64PFR0_EL1",
8547 .exported_bits
= R_ID_AA64PFR0_FP_MASK
|
8548 R_ID_AA64PFR0_ADVSIMD_MASK
|
8549 R_ID_AA64PFR0_SVE_MASK
|
8550 R_ID_AA64PFR0_DIT_MASK
,
8551 .fixed_bits
= (0x1u
<< R_ID_AA64PFR0_EL0_SHIFT
) |
8552 (0x1u
<< R_ID_AA64PFR0_EL1_SHIFT
) },
8553 { .name
= "ID_AA64PFR1_EL1",
8554 .exported_bits
= R_ID_AA64PFR1_BT_MASK
|
8555 R_ID_AA64PFR1_SSBS_MASK
|
8556 R_ID_AA64PFR1_MTE_MASK
|
8557 R_ID_AA64PFR1_SME_MASK
},
8558 { .name
= "ID_AA64PFR*_EL1_RESERVED",
8560 { .name
= "ID_AA64ZFR0_EL1",
8561 .exported_bits
= R_ID_AA64ZFR0_SVEVER_MASK
|
8562 R_ID_AA64ZFR0_AES_MASK
|
8563 R_ID_AA64ZFR0_BITPERM_MASK
|
8564 R_ID_AA64ZFR0_BFLOAT16_MASK
|
8565 R_ID_AA64ZFR0_SHA3_MASK
|
8566 R_ID_AA64ZFR0_SM4_MASK
|
8567 R_ID_AA64ZFR0_I8MM_MASK
|
8568 R_ID_AA64ZFR0_F32MM_MASK
|
8569 R_ID_AA64ZFR0_F64MM_MASK
},
8570 { .name
= "ID_AA64SMFR0_EL1",
8571 .exported_bits
= R_ID_AA64SMFR0_F32F32_MASK
|
8572 R_ID_AA64SMFR0_B16F32_MASK
|
8573 R_ID_AA64SMFR0_F16F32_MASK
|
8574 R_ID_AA64SMFR0_I8I32_MASK
|
8575 R_ID_AA64SMFR0_F64F64_MASK
|
8576 R_ID_AA64SMFR0_I16I64_MASK
|
8577 R_ID_AA64SMFR0_FA64_MASK
},
8578 { .name
= "ID_AA64MMFR0_EL1",
8579 .exported_bits
= R_ID_AA64MMFR0_ECV_MASK
,
8580 .fixed_bits
= (0xfu
<< R_ID_AA64MMFR0_TGRAN64_SHIFT
) |
8581 (0xfu
<< R_ID_AA64MMFR0_TGRAN4_SHIFT
) },
8582 { .name
= "ID_AA64MMFR1_EL1",
8583 .exported_bits
= R_ID_AA64MMFR1_AFP_MASK
},
8584 { .name
= "ID_AA64MMFR2_EL1",
8585 .exported_bits
= R_ID_AA64MMFR2_AT_MASK
},
8586 { .name
= "ID_AA64MMFR*_EL1_RESERVED",
8588 { .name
= "ID_AA64DFR0_EL1",
8589 .fixed_bits
= (0x6u
<< R_ID_AA64DFR0_DEBUGVER_SHIFT
) },
8590 { .name
= "ID_AA64DFR1_EL1" },
8591 { .name
= "ID_AA64DFR*_EL1_RESERVED",
8593 { .name
= "ID_AA64AFR*",
8595 { .name
= "ID_AA64ISAR0_EL1",
8596 .exported_bits
= R_ID_AA64ISAR0_AES_MASK
|
8597 R_ID_AA64ISAR0_SHA1_MASK
|
8598 R_ID_AA64ISAR0_SHA2_MASK
|
8599 R_ID_AA64ISAR0_CRC32_MASK
|
8600 R_ID_AA64ISAR0_ATOMIC_MASK
|
8601 R_ID_AA64ISAR0_RDM_MASK
|
8602 R_ID_AA64ISAR0_SHA3_MASK
|
8603 R_ID_AA64ISAR0_SM3_MASK
|
8604 R_ID_AA64ISAR0_SM4_MASK
|
8605 R_ID_AA64ISAR0_DP_MASK
|
8606 R_ID_AA64ISAR0_FHM_MASK
|
8607 R_ID_AA64ISAR0_TS_MASK
|
8608 R_ID_AA64ISAR0_RNDR_MASK
},
8609 { .name
= "ID_AA64ISAR1_EL1",
8610 .exported_bits
= R_ID_AA64ISAR1_DPB_MASK
|
8611 R_ID_AA64ISAR1_APA_MASK
|
8612 R_ID_AA64ISAR1_API_MASK
|
8613 R_ID_AA64ISAR1_JSCVT_MASK
|
8614 R_ID_AA64ISAR1_FCMA_MASK
|
8615 R_ID_AA64ISAR1_LRCPC_MASK
|
8616 R_ID_AA64ISAR1_GPA_MASK
|
8617 R_ID_AA64ISAR1_GPI_MASK
|
8618 R_ID_AA64ISAR1_FRINTTS_MASK
|
8619 R_ID_AA64ISAR1_SB_MASK
|
8620 R_ID_AA64ISAR1_BF16_MASK
|
8621 R_ID_AA64ISAR1_DGH_MASK
|
8622 R_ID_AA64ISAR1_I8MM_MASK
},
8623 { .name
= "ID_AA64ISAR2_EL1",
8624 .exported_bits
= R_ID_AA64ISAR2_WFXT_MASK
|
8625 R_ID_AA64ISAR2_RPRES_MASK
|
8626 R_ID_AA64ISAR2_GPA3_MASK
|
8627 R_ID_AA64ISAR2_APA3_MASK
},
8628 { .name
= "ID_AA64ISAR*_EL1_RESERVED",
8631 modify_arm_cp_regs(v8_idregs
, v8_user_idregs
);
8633 /* RVBAR_EL1 is only implemented if EL1 is the highest EL */
8634 if (!arm_feature(env
, ARM_FEATURE_EL3
) &&
8635 !arm_feature(env
, ARM_FEATURE_EL2
)) {
8636 ARMCPRegInfo rvbar
= {
8637 .name
= "RVBAR_EL1", .state
= ARM_CP_STATE_BOTH
,
8638 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
8640 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
),
8642 define_one_arm_cp_reg(cpu
, &rvbar
);
8644 define_arm_cp_regs(cpu
, v8_idregs
);
8645 define_arm_cp_regs(cpu
, v8_cp_reginfo
);
8647 for (i
= 4; i
< 16; i
++) {
8649 * Encodings in "0, c0, {c4-c7}, {0-7}" are RAZ for AArch32.
8650 * For pre-v8 cores there are RAZ patterns for these in
8651 * id_pre_v8_midr_cp_reginfo[]; for v8 we do that here.
8652 * v8 extends the "must RAZ" part of the ID register space
8653 * to also cover c0, 0, c{8-15}, {0-7}.
8654 * These are STATE_AA32 because in the AArch64 sysreg space
8655 * c4-c7 is where the AArch64 ID registers live (and we've
8656 * already defined those in v8_idregs[]), and c8-c15 are not
8657 * "must RAZ" for AArch64.
8659 g_autofree
char *name
= g_strdup_printf("RES_0_C0_C%d_X", i
);
8660 ARMCPRegInfo v8_aa32_raz_idregs
= {
8662 .state
= ARM_CP_STATE_AA32
,
8663 .cp
= 15, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= CP_ANY
,
8664 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8665 .accessfn
= access_aa64_tid3
,
8667 define_one_arm_cp_reg(cpu
, &v8_aa32_raz_idregs
);
8672 * Register the base EL2 cpregs.
8673 * Pre v8, these registers are implemented only as part of the
8674 * Virtualization Extensions (EL2 present). Beginning with v8,
8675 * if EL2 is missing but EL3 is enabled, mostly these become
8676 * RES0 from EL3, with some specific exceptions.
8678 if (arm_feature(env
, ARM_FEATURE_EL2
)
8679 || (arm_feature(env
, ARM_FEATURE_EL3
)
8680 && arm_feature(env
, ARM_FEATURE_V8
))) {
8681 uint64_t vmpidr_def
= mpidr_read_val(env
);
8682 ARMCPRegInfo vpidr_regs
[] = {
8683 { .name
= "VPIDR", .state
= ARM_CP_STATE_AA32
,
8684 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
8685 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
8686 .resetvalue
= cpu
->midr
,
8687 .type
= ARM_CP_ALIAS
| ARM_CP_EL3_NO_EL2_C_NZ
,
8688 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vpidr_el2
) },
8689 { .name
= "VPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
8690 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
8691 .access
= PL2_RW
, .resetvalue
= cpu
->midr
,
8692 .type
= ARM_CP_EL3_NO_EL2_C_NZ
,
8693 .fieldoffset
= offsetof(CPUARMState
, cp15
.vpidr_el2
) },
8694 { .name
= "VMPIDR", .state
= ARM_CP_STATE_AA32
,
8695 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
8696 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
8697 .resetvalue
= vmpidr_def
,
8698 .type
= ARM_CP_ALIAS
| ARM_CP_EL3_NO_EL2_C_NZ
,
8699 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vmpidr_el2
) },
8700 { .name
= "VMPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
8701 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
8702 .access
= PL2_RW
, .resetvalue
= vmpidr_def
,
8703 .type
= ARM_CP_EL3_NO_EL2_C_NZ
,
8704 .fieldoffset
= offsetof(CPUARMState
, cp15
.vmpidr_el2
) },
8707 * The only field of MDCR_EL2 that has a defined architectural reset
8708 * value is MDCR_EL2.HPMN which should reset to the value of PMCR_EL0.N.
8710 ARMCPRegInfo mdcr_el2
= {
8711 .name
= "MDCR_EL2", .state
= ARM_CP_STATE_BOTH
, .type
= ARM_CP_IO
,
8712 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 1,
8713 .writefn
= mdcr_el2_write
,
8714 .access
= PL2_RW
, .resetvalue
= pmu_num_counters(env
),
8715 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el2
),
8717 define_one_arm_cp_reg(cpu
, &mdcr_el2
);
8718 define_arm_cp_regs(cpu
, vpidr_regs
);
8719 define_arm_cp_regs(cpu
, el2_cp_reginfo
);
8720 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8721 define_arm_cp_regs(cpu
, el2_v8_cp_reginfo
);
8723 if (cpu_isar_feature(aa64_sel2
, cpu
)) {
8724 define_arm_cp_regs(cpu
, el2_sec_cp_reginfo
);
8726 /* RVBAR_EL2 is only implemented if EL2 is the highest EL */
8727 if (!arm_feature(env
, ARM_FEATURE_EL3
)) {
8728 ARMCPRegInfo rvbar
[] = {
8730 .name
= "RVBAR_EL2", .state
= ARM_CP_STATE_AA64
,
8731 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 1,
8733 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
),
8735 { .name
= "RVBAR", .type
= ARM_CP_ALIAS
,
8736 .cp
= 15, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
8738 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
),
8741 define_arm_cp_regs(cpu
, rvbar
);
8745 /* Register the base EL3 cpregs. */
8746 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
8747 define_arm_cp_regs(cpu
, el3_cp_reginfo
);
8748 ARMCPRegInfo el3_regs
[] = {
8749 { .name
= "RVBAR_EL3", .state
= ARM_CP_STATE_AA64
,
8750 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 1,
8752 .fieldoffset
= offsetof(CPUARMState
, cp15
.rvbar
),
8754 { .name
= "SCTLR_EL3", .state
= ARM_CP_STATE_AA64
,
8755 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 0,
8757 .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
8758 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[3]),
8759 .resetvalue
= cpu
->reset_sctlr
},
8762 define_arm_cp_regs(cpu
, el3_regs
);
8765 * The behaviour of NSACR is sufficiently various that we don't
8766 * try to describe it in a single reginfo:
8767 * if EL3 is 64 bit, then trap to EL3 from S EL1,
8768 * reads as constant 0xc00 from NS EL1 and NS EL2
8769 * if EL3 is 32 bit, then RW at EL3, RO at NS EL1 and NS EL2
8770 * if v7 without EL3, register doesn't exist
8771 * if v8 without EL3, reads as constant 0xc00 from NS EL1 and NS EL2
8773 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
8774 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
8775 static const ARMCPRegInfo nsacr
= {
8776 .name
= "NSACR", .type
= ARM_CP_CONST
,
8777 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
8778 .access
= PL1_RW
, .accessfn
= nsacr_access
,
8781 define_one_arm_cp_reg(cpu
, &nsacr
);
8783 static const ARMCPRegInfo nsacr
= {
8785 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
8786 .access
= PL3_RW
| PL1_R
,
8788 .fieldoffset
= offsetof(CPUARMState
, cp15
.nsacr
)
8790 define_one_arm_cp_reg(cpu
, &nsacr
);
8793 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8794 static const ARMCPRegInfo nsacr
= {
8795 .name
= "NSACR", .type
= ARM_CP_CONST
,
8796 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
8800 define_one_arm_cp_reg(cpu
, &nsacr
);
8804 if (arm_feature(env
, ARM_FEATURE_PMSA
)) {
8805 if (arm_feature(env
, ARM_FEATURE_V6
)) {
8806 /* PMSAv6 not implemented */
8807 assert(arm_feature(env
, ARM_FEATURE_V7
));
8808 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
8809 define_arm_cp_regs(cpu
, pmsav7_cp_reginfo
);
8811 define_arm_cp_regs(cpu
, pmsav5_cp_reginfo
);
8814 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
8815 define_arm_cp_regs(cpu
, vmsa_cp_reginfo
);
8816 /* TTCBR2 is introduced with ARMv8.2-AA32HPD. */
8817 if (cpu_isar_feature(aa32_hpd
, cpu
)) {
8818 define_one_arm_cp_reg(cpu
, &ttbcr2_reginfo
);
8821 if (arm_feature(env
, ARM_FEATURE_THUMB2EE
)) {
8822 define_arm_cp_regs(cpu
, t2ee_cp_reginfo
);
8824 if (arm_feature(env
, ARM_FEATURE_GENERIC_TIMER
)) {
8825 define_arm_cp_regs(cpu
, generic_timer_cp_reginfo
);
8827 if (arm_feature(env
, ARM_FEATURE_VAPA
)) {
8828 define_arm_cp_regs(cpu
, vapa_cp_reginfo
);
8830 if (arm_feature(env
, ARM_FEATURE_CACHE_TEST_CLEAN
)) {
8831 define_arm_cp_regs(cpu
, cache_test_clean_cp_reginfo
);
8833 if (arm_feature(env
, ARM_FEATURE_CACHE_DIRTY_REG
)) {
8834 define_arm_cp_regs(cpu
, cache_dirty_status_cp_reginfo
);
8836 if (arm_feature(env
, ARM_FEATURE_CACHE_BLOCK_OPS
)) {
8837 define_arm_cp_regs(cpu
, cache_block_ops_cp_reginfo
);
8839 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
8840 define_arm_cp_regs(cpu
, omap_cp_reginfo
);
8842 if (arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
8843 define_arm_cp_regs(cpu
, strongarm_cp_reginfo
);
8845 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
8846 define_arm_cp_regs(cpu
, xscale_cp_reginfo
);
8848 if (arm_feature(env
, ARM_FEATURE_DUMMY_C15_REGS
)) {
8849 define_arm_cp_regs(cpu
, dummy_c15_cp_reginfo
);
8851 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
8852 define_arm_cp_regs(cpu
, lpae_cp_reginfo
);
8854 if (cpu_isar_feature(aa32_jazelle
, cpu
)) {
8855 define_arm_cp_regs(cpu
, jazelle_regs
);
8858 * Slightly awkwardly, the OMAP and StrongARM cores need all of
8859 * cp15 crn=0 to be writes-ignored, whereas for other cores they should
8860 * be read-only (ie write causes UNDEF exception).
8863 ARMCPRegInfo id_pre_v8_midr_cp_reginfo
[] = {
8865 * Pre-v8 MIDR space.
8866 * Note that the MIDR isn't a simple constant register because
8867 * of the TI925 behaviour where writes to another register can
8868 * cause the MIDR value to change.
8870 * Unimplemented registers in the c15 0 0 0 space default to
8871 * MIDR. Define MIDR first as this entire space, then CTR, TCMTR
8872 * and friends override accordingly.
8875 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= CP_ANY
,
8876 .access
= PL1_R
, .resetvalue
= cpu
->midr
,
8877 .writefn
= arm_cp_write_ignore
, .raw_writefn
= raw_write
,
8878 .readfn
= midr_read
,
8879 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
8880 .type
= ARM_CP_OVERRIDE
},
8881 /* crn = 0 op1 = 0 crm = 3..7 : currently unassigned; we RAZ. */
8883 .cp
= 15, .crn
= 0, .crm
= 3, .opc1
= 0, .opc2
= CP_ANY
,
8884 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8886 .cp
= 15, .crn
= 0, .crm
= 4, .opc1
= 0, .opc2
= CP_ANY
,
8887 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8889 .cp
= 15, .crn
= 0, .crm
= 5, .opc1
= 0, .opc2
= CP_ANY
,
8890 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8892 .cp
= 15, .crn
= 0, .crm
= 6, .opc1
= 0, .opc2
= CP_ANY
,
8893 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8895 .cp
= 15, .crn
= 0, .crm
= 7, .opc1
= 0, .opc2
= CP_ANY
,
8896 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8898 ARMCPRegInfo id_v8_midr_cp_reginfo
[] = {
8899 { .name
= "MIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
8900 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 0,
8901 .access
= PL1_R
, .type
= ARM_CP_NO_RAW
, .resetvalue
= cpu
->midr
,
8902 .fgt
= FGT_MIDR_EL1
,
8903 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
8904 .readfn
= midr_read
},
8905 /* crn = 0 op1 = 0 crm = 0 op2 = 7 : AArch32 aliases of MIDR */
8906 { .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
,
8907 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 7,
8908 .access
= PL1_R
, .resetvalue
= cpu
->midr
},
8909 { .name
= "REVIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
8910 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 6,
8912 .accessfn
= access_aa64_tid1
,
8913 .fgt
= FGT_REVIDR_EL1
,
8914 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->revidr
},
8916 ARMCPRegInfo id_v8_midr_alias_cp_reginfo
= {
8917 .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
,
8918 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
8919 .access
= PL1_R
, .resetvalue
= cpu
->midr
8921 ARMCPRegInfo id_cp_reginfo
[] = {
8922 /* These are common to v8 and pre-v8 */
8924 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 1,
8925 .access
= PL1_R
, .accessfn
= ctr_el0_access
,
8926 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
8927 { .name
= "CTR_EL0", .state
= ARM_CP_STATE_AA64
,
8928 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 0, .crm
= 0,
8929 .access
= PL0_R
, .accessfn
= ctr_el0_access
,
8931 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
8932 /* TCMTR and TLBTR exist in v8 but have no 64-bit versions */
8934 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 2,
8936 .accessfn
= access_aa32_tid1
,
8937 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
8939 /* TLBTR is specific to VMSA */
8940 ARMCPRegInfo id_tlbtr_reginfo
= {
8942 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 3,
8944 .accessfn
= access_aa32_tid1
,
8945 .type
= ARM_CP_CONST
, .resetvalue
= 0,
8947 /* MPUIR is specific to PMSA V6+ */
8948 ARMCPRegInfo id_mpuir_reginfo
= {
8950 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
8951 .access
= PL1_R
, .type
= ARM_CP_CONST
,
8952 .resetvalue
= cpu
->pmsav7_dregion
<< 8
8954 /* HMPUIR is specific to PMSA V8 */
8955 ARMCPRegInfo id_hmpuir_reginfo
= {
8957 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 4,
8958 .access
= PL2_R
, .type
= ARM_CP_CONST
,
8959 .resetvalue
= cpu
->pmsav8r_hdregion
8961 static const ARMCPRegInfo crn0_wi_reginfo
= {
8962 .name
= "CRN0_WI", .cp
= 15, .crn
= 0, .crm
= CP_ANY
,
8963 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_W
,
8964 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
8966 #ifdef CONFIG_USER_ONLY
8967 static const ARMCPRegUserSpaceInfo id_v8_user_midr_cp_reginfo
[] = {
8968 { .name
= "MIDR_EL1",
8969 .exported_bits
= R_MIDR_EL1_REVISION_MASK
|
8970 R_MIDR_EL1_PARTNUM_MASK
|
8971 R_MIDR_EL1_ARCHITECTURE_MASK
|
8972 R_MIDR_EL1_VARIANT_MASK
|
8973 R_MIDR_EL1_IMPLEMENTER_MASK
},
8974 { .name
= "REVIDR_EL1" },
8976 modify_arm_cp_regs(id_v8_midr_cp_reginfo
, id_v8_user_midr_cp_reginfo
);
8978 if (arm_feature(env
, ARM_FEATURE_OMAPCP
) ||
8979 arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
8982 * Register the blanket "writes ignored" value first to cover the
8983 * whole space. Then update the specific ID registers to allow write
8984 * access, so that they ignore writes rather than causing them to
8987 define_one_arm_cp_reg(cpu
, &crn0_wi_reginfo
);
8988 for (i
= 0; i
< ARRAY_SIZE(id_pre_v8_midr_cp_reginfo
); ++i
) {
8989 id_pre_v8_midr_cp_reginfo
[i
].access
= PL1_RW
;
8991 for (i
= 0; i
< ARRAY_SIZE(id_cp_reginfo
); ++i
) {
8992 id_cp_reginfo
[i
].access
= PL1_RW
;
8994 id_mpuir_reginfo
.access
= PL1_RW
;
8995 id_tlbtr_reginfo
.access
= PL1_RW
;
8997 if (arm_feature(env
, ARM_FEATURE_V8
)) {
8998 define_arm_cp_regs(cpu
, id_v8_midr_cp_reginfo
);
8999 if (!arm_feature(env
, ARM_FEATURE_PMSA
)) {
9000 define_one_arm_cp_reg(cpu
, &id_v8_midr_alias_cp_reginfo
);
9003 define_arm_cp_regs(cpu
, id_pre_v8_midr_cp_reginfo
);
9005 define_arm_cp_regs(cpu
, id_cp_reginfo
);
9006 if (!arm_feature(env
, ARM_FEATURE_PMSA
)) {
9007 define_one_arm_cp_reg(cpu
, &id_tlbtr_reginfo
);
9008 } else if (arm_feature(env
, ARM_FEATURE_PMSA
) &&
9009 arm_feature(env
, ARM_FEATURE_V8
)) {
9013 define_one_arm_cp_reg(cpu
, &id_mpuir_reginfo
);
9014 define_one_arm_cp_reg(cpu
, &id_hmpuir_reginfo
);
9015 define_arm_cp_regs(cpu
, pmsav8r_cp_reginfo
);
9017 /* Register alias is only valid for first 32 indexes */
9018 for (i
= 0; i
< MIN(cpu
->pmsav7_dregion
, 32); ++i
) {
9019 uint8_t crm
= 0b1000 | extract32(i
, 1, 3);
9020 uint8_t opc1
= extract32(i
, 4, 1);
9021 uint8_t opc2
= extract32(i
, 0, 1) << 2;
9023 tmp_string
= g_strdup_printf("PRBAR%u", i
);
9024 ARMCPRegInfo tmp_prbarn_reginfo
= {
9025 .name
= tmp_string
, .type
= ARM_CP_ALIAS
| ARM_CP_NO_RAW
,
9026 .cp
= 15, .opc1
= opc1
, .crn
= 6, .crm
= crm
, .opc2
= opc2
,
9027 .access
= PL1_RW
, .resetvalue
= 0,
9028 .accessfn
= access_tvm_trvm
,
9029 .writefn
= pmsav8r_regn_write
, .readfn
= pmsav8r_regn_read
9031 define_one_arm_cp_reg(cpu
, &tmp_prbarn_reginfo
);
9034 opc2
= extract32(i
, 0, 1) << 2 | 0x1;
9035 tmp_string
= g_strdup_printf("PRLAR%u", i
);
9036 ARMCPRegInfo tmp_prlarn_reginfo
= {
9037 .name
= tmp_string
, .type
= ARM_CP_ALIAS
| ARM_CP_NO_RAW
,
9038 .cp
= 15, .opc1
= opc1
, .crn
= 6, .crm
= crm
, .opc2
= opc2
,
9039 .access
= PL1_RW
, .resetvalue
= 0,
9040 .accessfn
= access_tvm_trvm
,
9041 .writefn
= pmsav8r_regn_write
, .readfn
= pmsav8r_regn_read
9043 define_one_arm_cp_reg(cpu
, &tmp_prlarn_reginfo
);
9047 /* Register alias is only valid for first 32 indexes */
9048 for (i
= 0; i
< MIN(cpu
->pmsav8r_hdregion
, 32); ++i
) {
9049 uint8_t crm
= 0b1000 | extract32(i
, 1, 3);
9050 uint8_t opc1
= 0b100 | extract32(i
, 4, 1);
9051 uint8_t opc2
= extract32(i
, 0, 1) << 2;
9053 tmp_string
= g_strdup_printf("HPRBAR%u", i
);
9054 ARMCPRegInfo tmp_hprbarn_reginfo
= {
9056 .type
= ARM_CP_NO_RAW
,
9057 .cp
= 15, .opc1
= opc1
, .crn
= 6, .crm
= crm
, .opc2
= opc2
,
9058 .access
= PL2_RW
, .resetvalue
= 0,
9059 .writefn
= pmsav8r_regn_write
, .readfn
= pmsav8r_regn_read
9061 define_one_arm_cp_reg(cpu
, &tmp_hprbarn_reginfo
);
9064 opc2
= extract32(i
, 0, 1) << 2 | 0x1;
9065 tmp_string
= g_strdup_printf("HPRLAR%u", i
);
9066 ARMCPRegInfo tmp_hprlarn_reginfo
= {
9068 .type
= ARM_CP_NO_RAW
,
9069 .cp
= 15, .opc1
= opc1
, .crn
= 6, .crm
= crm
, .opc2
= opc2
,
9070 .access
= PL2_RW
, .resetvalue
= 0,
9071 .writefn
= pmsav8r_regn_write
, .readfn
= pmsav8r_regn_read
9073 define_one_arm_cp_reg(cpu
, &tmp_hprlarn_reginfo
);
9076 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
9077 define_one_arm_cp_reg(cpu
, &id_mpuir_reginfo
);
9081 if (arm_feature(env
, ARM_FEATURE_MPIDR
)) {
9082 ARMCPRegInfo mpidr_cp_reginfo
[] = {
9083 { .name
= "MPIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
9084 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 5,
9085 .fgt
= FGT_MPIDR_EL1
,
9086 .access
= PL1_R
, .readfn
= mpidr_read
, .type
= ARM_CP_NO_RAW
},
9088 #ifdef CONFIG_USER_ONLY
9089 static const ARMCPRegUserSpaceInfo mpidr_user_cp_reginfo
[] = {
9090 { .name
= "MPIDR_EL1",
9091 .fixed_bits
= 0x0000000080000000 },
9093 modify_arm_cp_regs(mpidr_cp_reginfo
, mpidr_user_cp_reginfo
);
9095 define_arm_cp_regs(cpu
, mpidr_cp_reginfo
);
9098 if (arm_feature(env
, ARM_FEATURE_AUXCR
)) {
9099 ARMCPRegInfo auxcr_reginfo
[] = {
9100 { .name
= "ACTLR_EL1", .state
= ARM_CP_STATE_BOTH
,
9101 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 1,
9102 .access
= PL1_RW
, .accessfn
= access_tacr
,
9103 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->reset_auxcr
},
9104 { .name
= "ACTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
9105 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 1,
9106 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
9108 { .name
= "ACTLR_EL3", .state
= ARM_CP_STATE_AA64
,
9109 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 1,
9110 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
9113 define_arm_cp_regs(cpu
, auxcr_reginfo
);
9114 if (cpu_isar_feature(aa32_ac2
, cpu
)) {
9115 define_arm_cp_regs(cpu
, actlr2_hactlr2_reginfo
);
9119 if (arm_feature(env
, ARM_FEATURE_CBAR
)) {
9121 * CBAR is IMPDEF, but common on Arm Cortex-A implementations.
9122 * There are two flavours:
9123 * (1) older 32-bit only cores have a simple 32-bit CBAR
9124 * (2) 64-bit cores have a 64-bit CBAR visible to AArch64, plus a
9125 * 32-bit register visible to AArch32 at a different encoding
9126 * to the "flavour 1" register and with the bits rearranged to
9127 * be able to squash a 64-bit address into the 32-bit view.
9128 * We distinguish the two via the ARM_FEATURE_AARCH64 flag, but
9129 * in future if we support AArch32-only configs of some of the
9130 * AArch64 cores we might need to add a specific feature flag
9131 * to indicate cores with "flavour 2" CBAR.
9133 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
9134 /* 32 bit view is [31:18] 0...0 [43:32]. */
9135 uint32_t cbar32
= (extract64(cpu
->reset_cbar
, 18, 14) << 18)
9136 | extract64(cpu
->reset_cbar
, 32, 12);
9137 ARMCPRegInfo cbar_reginfo
[] = {
9139 .type
= ARM_CP_CONST
,
9140 .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 1, .opc2
= 0,
9141 .access
= PL1_R
, .resetvalue
= cbar32
},
9142 { .name
= "CBAR_EL1", .state
= ARM_CP_STATE_AA64
,
9143 .type
= ARM_CP_CONST
,
9144 .opc0
= 3, .opc1
= 1, .crn
= 15, .crm
= 3, .opc2
= 0,
9145 .access
= PL1_R
, .resetvalue
= cpu
->reset_cbar
},
9147 /* We don't implement a r/w 64 bit CBAR currently */
9148 assert(arm_feature(env
, ARM_FEATURE_CBAR_RO
));
9149 define_arm_cp_regs(cpu
, cbar_reginfo
);
9151 ARMCPRegInfo cbar
= {
9153 .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 4, .opc2
= 0,
9154 .access
= PL1_R
| PL3_W
, .resetvalue
= cpu
->reset_cbar
,
9155 .fieldoffset
= offsetof(CPUARMState
,
9156 cp15
.c15_config_base_address
)
9158 if (arm_feature(env
, ARM_FEATURE_CBAR_RO
)) {
9159 cbar
.access
= PL1_R
;
9160 cbar
.fieldoffset
= 0;
9161 cbar
.type
= ARM_CP_CONST
;
9163 define_one_arm_cp_reg(cpu
, &cbar
);
9167 if (arm_feature(env
, ARM_FEATURE_VBAR
)) {
9168 static const ARMCPRegInfo vbar_cp_reginfo
[] = {
9169 { .name
= "VBAR", .state
= ARM_CP_STATE_BOTH
,
9170 .opc0
= 3, .crn
= 12, .crm
= 0, .opc1
= 0, .opc2
= 0,
9171 .access
= PL1_RW
, .writefn
= vbar_write
,
9172 .fgt
= FGT_VBAR_EL1
,
9173 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.vbar_s
),
9174 offsetof(CPUARMState
, cp15
.vbar_ns
) },
9177 define_arm_cp_regs(cpu
, vbar_cp_reginfo
);
9180 /* Generic registers whose values depend on the implementation */
9182 ARMCPRegInfo sctlr
= {
9183 .name
= "SCTLR", .state
= ARM_CP_STATE_BOTH
,
9184 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 0,
9185 .access
= PL1_RW
, .accessfn
= access_tvm_trvm
,
9186 .fgt
= FGT_SCTLR_EL1
,
9187 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.sctlr_s
),
9188 offsetof(CPUARMState
, cp15
.sctlr_ns
) },
9189 .writefn
= sctlr_write
, .resetvalue
= cpu
->reset_sctlr
,
9190 .raw_writefn
= raw_write
,
9192 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
9194 * Normally we would always end the TB on an SCTLR write, but Linux
9195 * arch/arm/mach-pxa/sleep.S expects two instructions following
9196 * an MMU enable to execute from cache. Imitate this behaviour.
9198 sctlr
.type
|= ARM_CP_SUPPRESS_TB_END
;
9200 define_one_arm_cp_reg(cpu
, &sctlr
);
9202 if (arm_feature(env
, ARM_FEATURE_PMSA
) &&
9203 arm_feature(env
, ARM_FEATURE_V8
)) {
9204 ARMCPRegInfo vsctlr
= {
9205 .name
= "VSCTLR", .state
= ARM_CP_STATE_AA32
,
9206 .cp
= 15, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 0,
9207 .access
= PL2_RW
, .resetvalue
= 0x0,
9208 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.vsctlr
),
9210 define_one_arm_cp_reg(cpu
, &vsctlr
);
9214 if (cpu_isar_feature(aa64_lor
, cpu
)) {
9215 define_arm_cp_regs(cpu
, lor_reginfo
);
9217 if (cpu_isar_feature(aa64_pan
, cpu
)) {
9218 define_one_arm_cp_reg(cpu
, &pan_reginfo
);
9220 #ifndef CONFIG_USER_ONLY
9221 if (cpu_isar_feature(aa64_ats1e1
, cpu
)) {
9222 define_arm_cp_regs(cpu
, ats1e1_reginfo
);
9224 if (cpu_isar_feature(aa32_ats1e1
, cpu
)) {
9225 define_arm_cp_regs(cpu
, ats1cp_reginfo
);
9228 if (cpu_isar_feature(aa64_uao
, cpu
)) {
9229 define_one_arm_cp_reg(cpu
, &uao_reginfo
);
9232 if (cpu_isar_feature(aa64_dit
, cpu
)) {
9233 define_one_arm_cp_reg(cpu
, &dit_reginfo
);
9235 if (cpu_isar_feature(aa64_ssbs
, cpu
)) {
9236 define_one_arm_cp_reg(cpu
, &ssbs_reginfo
);
9238 if (cpu_isar_feature(any_ras
, cpu
)) {
9239 define_arm_cp_regs(cpu
, minimal_ras_reginfo
);
9242 if (cpu_isar_feature(aa64_vh
, cpu
) ||
9243 cpu_isar_feature(aa64_debugv8p2
, cpu
)) {
9244 define_one_arm_cp_reg(cpu
, &contextidr_el2
);
9246 if (arm_feature(env
, ARM_FEATURE_EL2
) && cpu_isar_feature(aa64_vh
, cpu
)) {
9247 define_arm_cp_regs(cpu
, vhe_reginfo
);
9250 if (cpu_isar_feature(aa64_sve
, cpu
)) {
9251 define_arm_cp_regs(cpu
, zcr_reginfo
);
9254 if (cpu_isar_feature(aa64_hcx
, cpu
)) {
9255 define_one_arm_cp_reg(cpu
, &hcrx_el2_reginfo
);
9258 #ifdef TARGET_AARCH64
9259 if (cpu_isar_feature(aa64_sme
, cpu
)) {
9260 define_arm_cp_regs(cpu
, sme_reginfo
);
9262 if (cpu_isar_feature(aa64_pauth
, cpu
)) {
9263 define_arm_cp_regs(cpu
, pauth_reginfo
);
9265 if (cpu_isar_feature(aa64_rndr
, cpu
)) {
9266 define_arm_cp_regs(cpu
, rndr_reginfo
);
9268 if (cpu_isar_feature(aa64_tlbirange
, cpu
)) {
9269 define_arm_cp_regs(cpu
, tlbirange_reginfo
);
9271 if (cpu_isar_feature(aa64_tlbios
, cpu
)) {
9272 define_arm_cp_regs(cpu
, tlbios_reginfo
);
9274 /* Data Cache clean instructions up to PoP */
9275 if (cpu_isar_feature(aa64_dcpop
, cpu
)) {
9276 define_one_arm_cp_reg(cpu
, dcpop_reg
);
9278 if (cpu_isar_feature(aa64_dcpodp
, cpu
)) {
9279 define_one_arm_cp_reg(cpu
, dcpodp_reg
);
9284 * If full MTE is enabled, add all of the system registers.
9285 * If only "instructions available at EL0" are enabled,
9286 * then define only a RAZ/WI version of PSTATE.TCO.
9288 if (cpu_isar_feature(aa64_mte
, cpu
)) {
9289 define_arm_cp_regs(cpu
, mte_reginfo
);
9290 define_arm_cp_regs(cpu
, mte_el0_cacheop_reginfo
);
9291 } else if (cpu_isar_feature(aa64_mte_insn_reg
, cpu
)) {
9292 define_arm_cp_regs(cpu
, mte_tco_ro_reginfo
);
9293 define_arm_cp_regs(cpu
, mte_el0_cacheop_reginfo
);
9296 if (cpu_isar_feature(aa64_scxtnum
, cpu
)) {
9297 define_arm_cp_regs(cpu
, scxtnum_reginfo
);
9300 if (cpu_isar_feature(aa64_fgt
, cpu
)) {
9301 define_arm_cp_regs(cpu
, fgt_reginfo
);
9304 if (cpu_isar_feature(aa64_rme
, cpu
)) {
9305 define_arm_cp_regs(cpu
, rme_reginfo
);
9306 if (cpu_isar_feature(aa64_mte
, cpu
)) {
9307 define_arm_cp_regs(cpu
, rme_mte_reginfo
);
9312 if (cpu_isar_feature(any_predinv
, cpu
)) {
9313 define_arm_cp_regs(cpu
, predinv_reginfo
);
9316 if (cpu_isar_feature(any_ccidx
, cpu
)) {
9317 define_arm_cp_regs(cpu
, ccsidr2_reginfo
);
9320 #ifndef CONFIG_USER_ONLY
9322 * Register redirections and aliases must be done last,
9323 * after the registers from the other extensions have been defined.
9325 if (arm_feature(env
, ARM_FEATURE_EL2
) && cpu_isar_feature(aa64_vh
, cpu
)) {
9326 define_arm_vh_e2h_redirects_aliases(cpu
);
9331 /* Sort alphabetically by type name, except for "any". */
9332 static gint
arm_cpu_list_compare(gconstpointer a
, gconstpointer b
)
9334 ObjectClass
*class_a
= (ObjectClass
*)a
;
9335 ObjectClass
*class_b
= (ObjectClass
*)b
;
9336 const char *name_a
, *name_b
;
9338 name_a
= object_class_get_name(class_a
);
9339 name_b
= object_class_get_name(class_b
);
9340 if (strcmp(name_a
, "any-" TYPE_ARM_CPU
) == 0) {
9342 } else if (strcmp(name_b
, "any-" TYPE_ARM_CPU
) == 0) {
9345 return strcmp(name_a
, name_b
);
9349 static void arm_cpu_list_entry(gpointer data
, gpointer user_data
)
9351 ObjectClass
*oc
= data
;
9352 CPUClass
*cc
= CPU_CLASS(oc
);
9353 const char *typename
;
9356 typename
= object_class_get_name(oc
);
9357 name
= g_strndup(typename
, strlen(typename
) - strlen("-" TYPE_ARM_CPU
));
9358 if (cc
->deprecation_note
) {
9359 qemu_printf(" %s (deprecated)\n", name
);
9361 qemu_printf(" %s\n", name
);
9366 void arm_cpu_list(void)
9370 list
= object_class_get_list(TYPE_ARM_CPU
, false);
9371 list
= g_slist_sort(list
, arm_cpu_list_compare
);
9372 qemu_printf("Available CPUs:\n");
9373 g_slist_foreach(list
, arm_cpu_list_entry
, NULL
);
9378 * Private utility function for define_one_arm_cp_reg_with_opaque():
9379 * add a single reginfo struct to the hash table.
9381 static void add_cpreg_to_hashtable(ARMCPU
*cpu
, const ARMCPRegInfo
*r
,
9382 void *opaque
, CPState state
,
9383 CPSecureState secstate
,
9384 int crm
, int opc1
, int opc2
,
9387 CPUARMState
*env
= &cpu
->env
;
9390 bool is64
= r
->type
& ARM_CP_64BIT
;
9391 bool ns
= secstate
& ARM_CP_SECSTATE_NS
;
9397 case ARM_CP_STATE_AA32
:
9398 /* We assume it is a cp15 register if the .cp field is left unset. */
9399 if (cp
== 0 && r
->state
== ARM_CP_STATE_BOTH
) {
9402 key
= ENCODE_CP_REG(cp
, is64
, ns
, r
->crn
, crm
, opc1
, opc2
);
9404 case ARM_CP_STATE_AA64
:
9406 * To allow abbreviation of ARMCPRegInfo definitions, we treat
9407 * cp == 0 as equivalent to the value for "standard guest-visible
9408 * sysreg". STATE_BOTH definitions are also always "standard sysreg"
9409 * in their AArch64 view (the .cp value may be non-zero for the
9410 * benefit of the AArch32 view).
9412 if (cp
== 0 || r
->state
== ARM_CP_STATE_BOTH
) {
9413 cp
= CP_REG_ARM64_SYSREG_CP
;
9415 key
= ENCODE_AA64_CP_REG(cp
, r
->crn
, crm
, r
->opc0
, opc1
, opc2
);
9418 g_assert_not_reached();
9421 /* Overriding of an existing definition must be explicitly requested. */
9422 if (!(r
->type
& ARM_CP_OVERRIDE
)) {
9423 const ARMCPRegInfo
*oldreg
= get_arm_cp_reginfo(cpu
->cp_regs
, key
);
9425 assert(oldreg
->type
& ARM_CP_OVERRIDE
);
9430 * Eliminate registers that are not present because the EL is missing.
9431 * Doing this here makes it easier to put all registers for a given
9432 * feature into the same ARMCPRegInfo array and define them all at once.
9435 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
9437 * An EL2 register without EL2 but with EL3 is (usually) RES0.
9438 * See rule RJFFP in section D1.1.3 of DDI0487H.a.
9440 int min_el
= ctz32(r
->access
) / 2;
9441 if (min_el
== 2 && !arm_feature(env
, ARM_FEATURE_EL2
)) {
9442 if (r
->type
& ARM_CP_EL3_NO_EL2_UNDEF
) {
9445 make_const
= !(r
->type
& ARM_CP_EL3_NO_EL2_KEEP
);
9448 CPAccessRights max_el
= (arm_feature(env
, ARM_FEATURE_EL2
)
9450 if ((r
->access
& max_el
) == 0) {
9455 /* Combine cpreg and name into one allocation. */
9456 name_len
= strlen(name
) + 1;
9457 r2
= g_malloc(sizeof(*r2
) + name_len
);
9459 r2
->name
= memcpy(r2
+ 1, name
, name_len
);
9462 * Update fields to match the instantiation, overwiting wildcards
9463 * such as CP_ANY, ARM_CP_STATE_BOTH, or ARM_CP_SECSTATE_BOTH.
9470 r2
->secure
= secstate
;
9472 r2
->opaque
= opaque
;
9476 /* This should not have been a very special register to begin. */
9477 int old_special
= r2
->type
& ARM_CP_SPECIAL_MASK
;
9478 assert(old_special
== 0 || old_special
== ARM_CP_NOP
);
9480 * Set the special function to CONST, retaining the other flags.
9481 * This is important for e.g. ARM_CP_SVE so that we still
9482 * take the SVE trap if CPTR_EL3.EZ == 0.
9484 r2
->type
= (r2
->type
& ~ARM_CP_SPECIAL_MASK
) | ARM_CP_CONST
;
9486 * Usually, these registers become RES0, but there are a few
9487 * special cases like VPIDR_EL2 which have a constant non-zero
9488 * value with writes ignored.
9490 if (!(r
->type
& ARM_CP_EL3_NO_EL2_C_NZ
)) {
9494 * ARM_CP_CONST has precedence, so removing the callbacks and
9495 * offsets are not strictly necessary, but it is potentially
9496 * less confusing to debug later.
9500 r2
->raw_readfn
= NULL
;
9501 r2
->raw_writefn
= NULL
;
9503 r2
->fieldoffset
= 0;
9504 r2
->bank_fieldoffsets
[0] = 0;
9505 r2
->bank_fieldoffsets
[1] = 0;
9507 bool isbanked
= r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1];
9511 * Register is banked (using both entries in array).
9512 * Overwriting fieldoffset as the array is only used to define
9513 * banked registers but later only fieldoffset is used.
9515 r2
->fieldoffset
= r
->bank_fieldoffsets
[ns
];
9517 if (state
== ARM_CP_STATE_AA32
) {
9520 * If the register is banked then we don't need to migrate or
9521 * reset the 32-bit instance in certain cases:
9523 * 1) If the register has both 32-bit and 64-bit instances
9524 * then we can count on the 64-bit instance taking care
9525 * of the non-secure bank.
9526 * 2) If ARMv8 is enabled then we can count on a 64-bit
9527 * version taking care of the secure bank. This requires
9528 * that separate 32 and 64-bit definitions are provided.
9530 if ((r
->state
== ARM_CP_STATE_BOTH
&& ns
) ||
9531 (arm_feature(env
, ARM_FEATURE_V8
) && !ns
)) {
9532 r2
->type
|= ARM_CP_ALIAS
;
9534 } else if ((secstate
!= r
->secure
) && !ns
) {
9536 * The register is not banked so we only want to allow
9537 * migration of the non-secure instance.
9539 r2
->type
|= ARM_CP_ALIAS
;
9542 if (HOST_BIG_ENDIAN
&&
9543 r
->state
== ARM_CP_STATE_BOTH
&& r2
->fieldoffset
) {
9544 r2
->fieldoffset
+= sizeof(uint32_t);
9550 * By convention, for wildcarded registers only the first
9551 * entry is used for migration; the others are marked as
9552 * ALIAS so we don't try to transfer the register
9553 * multiple times. Special registers (ie NOP/WFI) are
9554 * never migratable and not even raw-accessible.
9556 if (r2
->type
& ARM_CP_SPECIAL_MASK
) {
9557 r2
->type
|= ARM_CP_NO_RAW
;
9559 if (((r
->crm
== CP_ANY
) && crm
!= 0) ||
9560 ((r
->opc1
== CP_ANY
) && opc1
!= 0) ||
9561 ((r
->opc2
== CP_ANY
) && opc2
!= 0)) {
9562 r2
->type
|= ARM_CP_ALIAS
| ARM_CP_NO_GDB
;
9566 * Check that raw accesses are either forbidden or handled. Note that
9567 * we can't assert this earlier because the setup of fieldoffset for
9568 * banked registers has to be done first.
9570 if (!(r2
->type
& ARM_CP_NO_RAW
)) {
9571 assert(!raw_accessors_invalid(r2
));
9574 g_hash_table_insert(cpu
->cp_regs
, (gpointer
)(uintptr_t)key
, r2
);
9578 void define_one_arm_cp_reg_with_opaque(ARMCPU
*cpu
,
9579 const ARMCPRegInfo
*r
, void *opaque
)
9582 * Define implementations of coprocessor registers.
9583 * We store these in a hashtable because typically
9584 * there are less than 150 registers in a space which
9585 * is 16*16*16*8*8 = 262144 in size.
9586 * Wildcarding is supported for the crm, opc1 and opc2 fields.
9587 * If a register is defined twice then the second definition is
9588 * used, so this can be used to define some generic registers and
9589 * then override them with implementation specific variations.
9590 * At least one of the original and the second definition should
9591 * include ARM_CP_OVERRIDE in its type bits -- this is just a guard
9592 * against accidental use.
9594 * The state field defines whether the register is to be
9595 * visible in the AArch32 or AArch64 execution state. If the
9596 * state is set to ARM_CP_STATE_BOTH then we synthesise a
9597 * reginfo structure for the AArch32 view, which sees the lower
9598 * 32 bits of the 64 bit register.
9600 * Only registers visible in AArch64 may set r->opc0; opc0 cannot
9601 * be wildcarded. AArch64 registers are always considered to be 64
9602 * bits; the ARM_CP_64BIT* flag applies only to the AArch32 view of
9603 * the register, if any.
9605 int crm
, opc1
, opc2
;
9606 int crmmin
= (r
->crm
== CP_ANY
) ? 0 : r
->crm
;
9607 int crmmax
= (r
->crm
== CP_ANY
) ? 15 : r
->crm
;
9608 int opc1min
= (r
->opc1
== CP_ANY
) ? 0 : r
->opc1
;
9609 int opc1max
= (r
->opc1
== CP_ANY
) ? 7 : r
->opc1
;
9610 int opc2min
= (r
->opc2
== CP_ANY
) ? 0 : r
->opc2
;
9611 int opc2max
= (r
->opc2
== CP_ANY
) ? 7 : r
->opc2
;
9614 /* 64 bit registers have only CRm and Opc1 fields */
9615 assert(!((r
->type
& ARM_CP_64BIT
) && (r
->opc2
|| r
->crn
)));
9616 /* op0 only exists in the AArch64 encodings */
9617 assert((r
->state
!= ARM_CP_STATE_AA32
) || (r
->opc0
== 0));
9618 /* AArch64 regs are all 64 bit so ARM_CP_64BIT is meaningless */
9619 assert((r
->state
!= ARM_CP_STATE_AA64
) || !(r
->type
& ARM_CP_64BIT
));
9621 * This API is only for Arm's system coprocessors (14 and 15) or
9622 * (M-profile or v7A-and-earlier only) for implementation defined
9623 * coprocessors in the range 0..7. Our decode assumes this, since
9624 * 8..13 can be used for other insns including VFP and Neon. See
9625 * valid_cp() in translate.c. Assert here that we haven't tried
9626 * to use an invalid coprocessor number.
9629 case ARM_CP_STATE_BOTH
:
9630 /* 0 has a special meaning, but otherwise the same rules as AA32. */
9635 case ARM_CP_STATE_AA32
:
9636 if (arm_feature(&cpu
->env
, ARM_FEATURE_V8
) &&
9637 !arm_feature(&cpu
->env
, ARM_FEATURE_M
)) {
9638 assert(r
->cp
>= 14 && r
->cp
<= 15);
9640 assert(r
->cp
< 8 || (r
->cp
>= 14 && r
->cp
<= 15));
9643 case ARM_CP_STATE_AA64
:
9644 assert(r
->cp
== 0 || r
->cp
== CP_REG_ARM64_SYSREG_CP
);
9647 g_assert_not_reached();
9650 * The AArch64 pseudocode CheckSystemAccess() specifies that op1
9651 * encodes a minimum access level for the register. We roll this
9652 * runtime check into our general permission check code, so check
9653 * here that the reginfo's specified permissions are strict enough
9654 * to encompass the generic architectural permission check.
9656 if (r
->state
!= ARM_CP_STATE_AA32
) {
9657 CPAccessRights mask
;
9660 /* min_EL EL1, but some accessible to EL0 via kernel ABI */
9661 mask
= PL0U_R
| PL1_RW
;
9681 /* min_EL EL1, secure mode only (we don't check the latter) */
9685 /* broken reginfo with out-of-range opc1 */
9686 g_assert_not_reached();
9688 /* assert our permissions are not too lax (stricter is fine) */
9689 assert((r
->access
& ~mask
) == 0);
9693 * Check that the register definition has enough info to handle
9694 * reads and writes if they are permitted.
9696 if (!(r
->type
& (ARM_CP_SPECIAL_MASK
| ARM_CP_CONST
))) {
9697 if (r
->access
& PL3_R
) {
9698 assert((r
->fieldoffset
||
9699 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
9702 if (r
->access
& PL3_W
) {
9703 assert((r
->fieldoffset
||
9704 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
9709 for (crm
= crmmin
; crm
<= crmmax
; crm
++) {
9710 for (opc1
= opc1min
; opc1
<= opc1max
; opc1
++) {
9711 for (opc2
= opc2min
; opc2
<= opc2max
; opc2
++) {
9712 for (state
= ARM_CP_STATE_AA32
;
9713 state
<= ARM_CP_STATE_AA64
; state
++) {
9714 if (r
->state
!= state
&& r
->state
!= ARM_CP_STATE_BOTH
) {
9717 if (state
== ARM_CP_STATE_AA32
) {
9719 * Under AArch32 CP registers can be common
9720 * (same for secure and non-secure world) or banked.
9724 switch (r
->secure
) {
9725 case ARM_CP_SECSTATE_S
:
9726 case ARM_CP_SECSTATE_NS
:
9727 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
9728 r
->secure
, crm
, opc1
, opc2
,
9731 case ARM_CP_SECSTATE_BOTH
:
9732 name
= g_strdup_printf("%s_S", r
->name
);
9733 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
9735 crm
, opc1
, opc2
, name
);
9737 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
9739 crm
, opc1
, opc2
, r
->name
);
9742 g_assert_not_reached();
9746 * AArch64 registers get mapped to non-secure instance
9749 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
9751 crm
, opc1
, opc2
, r
->name
);
9759 /* Define a whole list of registers */
9760 void define_arm_cp_regs_with_opaque_len(ARMCPU
*cpu
, const ARMCPRegInfo
*regs
,
9761 void *opaque
, size_t len
)
9764 for (i
= 0; i
< len
; ++i
) {
9765 define_one_arm_cp_reg_with_opaque(cpu
, regs
+ i
, opaque
);
9770 * Modify ARMCPRegInfo for access from userspace.
9772 * This is a data driven modification directed by
9773 * ARMCPRegUserSpaceInfo. All registers become ARM_CP_CONST as
9774 * user-space cannot alter any values and dynamic values pertaining to
9775 * execution state are hidden from user space view anyway.
9777 void modify_arm_cp_regs_with_len(ARMCPRegInfo
*regs
, size_t regs_len
,
9778 const ARMCPRegUserSpaceInfo
*mods
,
9781 for (size_t mi
= 0; mi
< mods_len
; ++mi
) {
9782 const ARMCPRegUserSpaceInfo
*m
= mods
+ mi
;
9783 GPatternSpec
*pat
= NULL
;
9786 pat
= g_pattern_spec_new(m
->name
);
9788 for (size_t ri
= 0; ri
< regs_len
; ++ri
) {
9789 ARMCPRegInfo
*r
= regs
+ ri
;
9791 if (pat
&& g_pattern_match_string(pat
, r
->name
)) {
9792 r
->type
= ARM_CP_CONST
;
9796 } else if (strcmp(r
->name
, m
->name
) == 0) {
9797 r
->type
= ARM_CP_CONST
;
9799 r
->resetvalue
&= m
->exported_bits
;
9800 r
->resetvalue
|= m
->fixed_bits
;
9805 g_pattern_spec_free(pat
);
9810 const ARMCPRegInfo
*get_arm_cp_reginfo(GHashTable
*cpregs
, uint32_t encoded_cp
)
9812 return g_hash_table_lookup(cpregs
, (gpointer
)(uintptr_t)encoded_cp
);
9815 void arm_cp_write_ignore(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
9818 /* Helper coprocessor write function for write-ignore registers */
9821 uint64_t arm_cp_read_zero(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
9823 /* Helper coprocessor write function for read-as-zero registers */
9827 void arm_cp_reset_ignore(CPUARMState
*env
, const ARMCPRegInfo
*opaque
)
9829 /* Helper coprocessor reset function for do-nothing-on-reset registers */
9832 static int bad_mode_switch(CPUARMState
*env
, int mode
, CPSRWriteType write_type
)
9835 * Return true if it is not valid for us to switch to
9836 * this CPU mode (ie all the UNPREDICTABLE cases in
9837 * the ARM ARM CPSRWriteByInstr pseudocode).
9840 /* Changes to or from Hyp via MSR and CPS are illegal. */
9841 if (write_type
== CPSRWriteByInstr
&&
9842 ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_HYP
||
9843 mode
== ARM_CPU_MODE_HYP
)) {
9848 case ARM_CPU_MODE_USR
:
9850 case ARM_CPU_MODE_SYS
:
9851 case ARM_CPU_MODE_SVC
:
9852 case ARM_CPU_MODE_ABT
:
9853 case ARM_CPU_MODE_UND
:
9854 case ARM_CPU_MODE_IRQ
:
9855 case ARM_CPU_MODE_FIQ
:
9857 * Note that we don't implement the IMPDEF NSACR.RFR which in v7
9858 * allows FIQ mode to be Secure-only. (In v8 this doesn't exist.)
9861 * If HCR.TGE is set then changes from Monitor to NS PL1 via MSR
9862 * and CPS are treated as illegal mode changes.
9864 if (write_type
== CPSRWriteByInstr
&&
9865 (env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
&&
9866 (arm_hcr_el2_eff(env
) & HCR_TGE
)) {
9870 case ARM_CPU_MODE_HYP
:
9871 return !arm_is_el2_enabled(env
) || arm_current_el(env
) < 2;
9872 case ARM_CPU_MODE_MON
:
9873 return arm_current_el(env
) < 3;
9879 uint32_t cpsr_read(CPUARMState
*env
)
9882 ZF
= (env
->ZF
== 0);
9883 return env
->uncached_cpsr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
9884 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3) | (env
->QF
<< 27)
9885 | (env
->thumb
<< 5) | ((env
->condexec_bits
& 3) << 25)
9886 | ((env
->condexec_bits
& 0xfc) << 8)
9887 | (env
->GE
<< 16) | (env
->daif
& CPSR_AIF
);
9890 void cpsr_write(CPUARMState
*env
, uint32_t val
, uint32_t mask
,
9891 CPSRWriteType write_type
)
9893 uint32_t changed_daif
;
9894 bool rebuild_hflags
= (write_type
!= CPSRWriteRaw
) &&
9895 (mask
& (CPSR_M
| CPSR_E
| CPSR_IL
));
9897 if (mask
& CPSR_NZCV
) {
9898 env
->ZF
= (~val
) & CPSR_Z
;
9900 env
->CF
= (val
>> 29) & 1;
9901 env
->VF
= (val
<< 3) & 0x80000000;
9903 if (mask
& CPSR_Q
) {
9904 env
->QF
= ((val
& CPSR_Q
) != 0);
9906 if (mask
& CPSR_T
) {
9907 env
->thumb
= ((val
& CPSR_T
) != 0);
9909 if (mask
& CPSR_IT_0_1
) {
9910 env
->condexec_bits
&= ~3;
9911 env
->condexec_bits
|= (val
>> 25) & 3;
9913 if (mask
& CPSR_IT_2_7
) {
9914 env
->condexec_bits
&= 3;
9915 env
->condexec_bits
|= (val
>> 8) & 0xfc;
9917 if (mask
& CPSR_GE
) {
9918 env
->GE
= (val
>> 16) & 0xf;
9922 * In a V7 implementation that includes the security extensions but does
9923 * not include Virtualization Extensions the SCR.FW and SCR.AW bits control
9924 * whether non-secure software is allowed to change the CPSR_F and CPSR_A
9925 * bits respectively.
9927 * In a V8 implementation, it is permitted for privileged software to
9928 * change the CPSR A/F bits regardless of the SCR.AW/FW bits.
9930 if (write_type
!= CPSRWriteRaw
&& !arm_feature(env
, ARM_FEATURE_V8
) &&
9931 arm_feature(env
, ARM_FEATURE_EL3
) &&
9932 !arm_feature(env
, ARM_FEATURE_EL2
) &&
9933 !arm_is_secure(env
)) {
9935 changed_daif
= (env
->daif
^ val
) & mask
;
9937 if (changed_daif
& CPSR_A
) {
9939 * Check to see if we are allowed to change the masking of async
9940 * abort exceptions from a non-secure state.
9942 if (!(env
->cp15
.scr_el3
& SCR_AW
)) {
9943 qemu_log_mask(LOG_GUEST_ERROR
,
9944 "Ignoring attempt to switch CPSR_A flag from "
9945 "non-secure world with SCR.AW bit clear\n");
9950 if (changed_daif
& CPSR_F
) {
9952 * Check to see if we are allowed to change the masking of FIQ
9953 * exceptions from a non-secure state.
9955 if (!(env
->cp15
.scr_el3
& SCR_FW
)) {
9956 qemu_log_mask(LOG_GUEST_ERROR
,
9957 "Ignoring attempt to switch CPSR_F flag from "
9958 "non-secure world with SCR.FW bit clear\n");
9963 * Check whether non-maskable FIQ (NMFI) support is enabled.
9964 * If this bit is set software is not allowed to mask
9965 * FIQs, but is allowed to set CPSR_F to 0.
9967 if ((A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_NMFI
) &&
9969 qemu_log_mask(LOG_GUEST_ERROR
,
9970 "Ignoring attempt to enable CPSR_F flag "
9971 "(non-maskable FIQ [NMFI] support enabled)\n");
9977 env
->daif
&= ~(CPSR_AIF
& mask
);
9978 env
->daif
|= val
& CPSR_AIF
& mask
;
9980 if (write_type
!= CPSRWriteRaw
&&
9981 ((env
->uncached_cpsr
^ val
) & mask
& CPSR_M
)) {
9982 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_USR
) {
9984 * Note that we can only get here in USR mode if this is a
9985 * gdb stub write; for this case we follow the architectural
9986 * behaviour for guest writes in USR mode of ignoring an attempt
9987 * to switch mode. (Those are caught by translate.c for writes
9988 * triggered by guest instructions.)
9991 } else if (bad_mode_switch(env
, val
& CPSR_M
, write_type
)) {
9993 * Attempt to switch to an invalid mode: this is UNPREDICTABLE in
9994 * v7, and has defined behaviour in v8:
9995 * + leave CPSR.M untouched
9996 * + allow changes to the other CPSR fields
9998 * For user changes via the GDB stub, we don't set PSTATE.IL,
9999 * as this would be unnecessarily harsh for a user error.
10002 if (write_type
!= CPSRWriteByGDBStub
&&
10003 arm_feature(env
, ARM_FEATURE_V8
)) {
10007 qemu_log_mask(LOG_GUEST_ERROR
,
10008 "Illegal AArch32 mode switch attempt from %s to %s\n",
10009 aarch32_mode_name(env
->uncached_cpsr
),
10010 aarch32_mode_name(val
));
10012 qemu_log_mask(CPU_LOG_INT
, "%s %s to %s PC 0x%" PRIx32
"\n",
10013 write_type
== CPSRWriteExceptionReturn
?
10014 "Exception return from AArch32" :
10015 "AArch32 mode switch from",
10016 aarch32_mode_name(env
->uncached_cpsr
),
10017 aarch32_mode_name(val
), env
->regs
[15]);
10018 switch_mode(env
, val
& CPSR_M
);
10021 mask
&= ~CACHED_CPSR_BITS
;
10022 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~mask
) | (val
& mask
);
10023 if (tcg_enabled() && rebuild_hflags
) {
10024 arm_rebuild_hflags(env
);
10028 /* Sign/zero extend */
10029 uint32_t HELPER(sxtb16
)(uint32_t x
)
10032 res
= (uint16_t)(int8_t)x
;
10033 res
|= (uint32_t)(int8_t)(x
>> 16) << 16;
10037 static void handle_possible_div0_trap(CPUARMState
*env
, uintptr_t ra
)
10040 * Take a division-by-zero exception if necessary; otherwise return
10041 * to get the usual non-trapping division behaviour (result of 0)
10043 if (arm_feature(env
, ARM_FEATURE_M
)
10044 && (env
->v7m
.ccr
[env
->v7m
.secure
] & R_V7M_CCR_DIV_0_TRP_MASK
)) {
10045 raise_exception_ra(env
, EXCP_DIVBYZERO
, 0, 1, ra
);
10049 uint32_t HELPER(uxtb16
)(uint32_t x
)
10052 res
= (uint16_t)(uint8_t)x
;
10053 res
|= (uint32_t)(uint8_t)(x
>> 16) << 16;
10057 int32_t HELPER(sdiv
)(CPUARMState
*env
, int32_t num
, int32_t den
)
10060 handle_possible_div0_trap(env
, GETPC());
10063 if (num
== INT_MIN
&& den
== -1) {
10069 uint32_t HELPER(udiv
)(CPUARMState
*env
, uint32_t num
, uint32_t den
)
10072 handle_possible_div0_trap(env
, GETPC());
10078 uint32_t HELPER(rbit
)(uint32_t x
)
10080 return revbit32(x
);
10083 #ifdef CONFIG_USER_ONLY
10085 static void switch_mode(CPUARMState
*env
, int mode
)
10087 ARMCPU
*cpu
= env_archcpu(env
);
10089 if (mode
!= ARM_CPU_MODE_USR
) {
10090 cpu_abort(CPU(cpu
), "Tried to switch out of user mode\n");
10094 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
10095 uint32_t cur_el
, bool secure
)
10100 void aarch64_sync_64_to_32(CPUARMState
*env
)
10102 g_assert_not_reached();
10107 static void switch_mode(CPUARMState
*env
, int mode
)
10112 old_mode
= env
->uncached_cpsr
& CPSR_M
;
10113 if (mode
== old_mode
) {
10117 if (old_mode
== ARM_CPU_MODE_FIQ
) {
10118 memcpy(env
->fiq_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
10119 memcpy(env
->regs
+ 8, env
->usr_regs
, 5 * sizeof(uint32_t));
10120 } else if (mode
== ARM_CPU_MODE_FIQ
) {
10121 memcpy(env
->usr_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
10122 memcpy(env
->regs
+ 8, env
->fiq_regs
, 5 * sizeof(uint32_t));
10125 i
= bank_number(old_mode
);
10126 env
->banked_r13
[i
] = env
->regs
[13];
10127 env
->banked_spsr
[i
] = env
->spsr
;
10129 i
= bank_number(mode
);
10130 env
->regs
[13] = env
->banked_r13
[i
];
10131 env
->spsr
= env
->banked_spsr
[i
];
10133 env
->banked_r14
[r14_bank_number(old_mode
)] = env
->regs
[14];
10134 env
->regs
[14] = env
->banked_r14
[r14_bank_number(mode
)];
10138 * Physical Interrupt Target EL Lookup Table
10140 * [ From ARM ARM section G1.13.4 (Table G1-15) ]
10142 * The below multi-dimensional table is used for looking up the target
10143 * exception level given numerous condition criteria. Specifically, the
10144 * target EL is based on SCR and HCR routing controls as well as the
10145 * currently executing EL and secure state.
10148 * target_el_table[2][2][2][2][2][4]
10149 * | | | | | +--- Current EL
10150 * | | | | +------ Non-secure(0)/Secure(1)
10151 * | | | +--------- HCR mask override
10152 * | | +------------ SCR exec state control
10153 * | +--------------- SCR mask override
10154 * +------------------ 32-bit(0)/64-bit(1) EL3
10156 * The table values are as such:
10158 * -1 = Cannot occur
10160 * The ARM ARM target EL table includes entries indicating that an "exception
10161 * is not taken". The two cases where this is applicable are:
10162 * 1) An exception is taken from EL3 but the SCR does not have the exception
10164 * 2) An exception is taken from EL2 but the HCR does not have the exception
10166 * In these two cases, the below table contain a target of EL1. This value is
10167 * returned as it is expected that the consumer of the table data will check
10168 * for "target EL >= current EL" to ensure the exception is not taken.
10172 * BIT IRQ IMO Non-secure Secure
10173 * EL3 FIQ RW FMO EL0 EL1 EL2 EL3 EL0 EL1 EL2 EL3
10175 static const int8_t target_el_table
[2][2][2][2][2][4] = {
10176 {{{{/* 0 0 0 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
10177 {/* 0 0 0 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},
10178 {{/* 0 0 1 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
10179 {/* 0 0 1 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},},
10180 {{{/* 0 1 0 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
10181 {/* 0 1 0 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},
10182 {{/* 0 1 1 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
10183 {/* 0 1 1 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},},},
10184 {{{{/* 1 0 0 0 */{ 1, 1, 2, -1 },{ 1, 1, -1, 1 },},
10185 {/* 1 0 0 1 */{ 2, 2, 2, -1 },{ 2, 2, -1, 1 },},},
10186 {{/* 1 0 1 0 */{ 1, 1, 1, -1 },{ 1, 1, 1, 1 },},
10187 {/* 1 0 1 1 */{ 2, 2, 2, -1 },{ 2, 2, 2, 1 },},},},
10188 {{{/* 1 1 0 0 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},
10189 {/* 1 1 0 1 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},},
10190 {{/* 1 1 1 0 */{ 3, 3, 3, -1 },{ 3, 3, 3, 3 },},
10191 {/* 1 1 1 1 */{ 3, 3, 3, -1 },{ 3, 3, 3, 3 },},},},},
10195 * Determine the target EL for physical exceptions
10197 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
10198 uint32_t cur_el
, bool secure
)
10200 CPUARMState
*env
= cs
->env_ptr
;
10205 /* Is the highest EL AArch64? */
10206 bool is64
= arm_feature(env
, ARM_FEATURE_AARCH64
);
10209 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
10210 rw
= ((env
->cp15
.scr_el3
& SCR_RW
) == SCR_RW
);
10213 * Either EL2 is the highest EL (and so the EL2 register width
10214 * is given by is64); or there is no EL2 or EL3, in which case
10215 * the value of 'rw' does not affect the table lookup anyway.
10220 hcr_el2
= arm_hcr_el2_eff(env
);
10221 switch (excp_idx
) {
10223 scr
= ((env
->cp15
.scr_el3
& SCR_IRQ
) == SCR_IRQ
);
10224 hcr
= hcr_el2
& HCR_IMO
;
10227 scr
= ((env
->cp15
.scr_el3
& SCR_FIQ
) == SCR_FIQ
);
10228 hcr
= hcr_el2
& HCR_FMO
;
10231 scr
= ((env
->cp15
.scr_el3
& SCR_EA
) == SCR_EA
);
10232 hcr
= hcr_el2
& HCR_AMO
;
10237 * For these purposes, TGE and AMO/IMO/FMO both force the
10238 * interrupt to EL2. Fold TGE into the bit extracted above.
10240 hcr
|= (hcr_el2
& HCR_TGE
) != 0;
10242 /* Perform a table-lookup for the target EL given the current state */
10243 target_el
= target_el_table
[is64
][scr
][rw
][hcr
][secure
][cur_el
];
10245 assert(target_el
> 0);
10250 void arm_log_exception(CPUState
*cs
)
10252 int idx
= cs
->exception_index
;
10254 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
10255 const char *exc
= NULL
;
10256 static const char * const excnames
[] = {
10257 [EXCP_UDEF
] = "Undefined Instruction",
10258 [EXCP_SWI
] = "SVC",
10259 [EXCP_PREFETCH_ABORT
] = "Prefetch Abort",
10260 [EXCP_DATA_ABORT
] = "Data Abort",
10261 [EXCP_IRQ
] = "IRQ",
10262 [EXCP_FIQ
] = "FIQ",
10263 [EXCP_BKPT
] = "Breakpoint",
10264 [EXCP_EXCEPTION_EXIT
] = "QEMU v7M exception exit",
10265 [EXCP_KERNEL_TRAP
] = "QEMU intercept of kernel commpage",
10266 [EXCP_HVC
] = "Hypervisor Call",
10267 [EXCP_HYP_TRAP
] = "Hypervisor Trap",
10268 [EXCP_SMC
] = "Secure Monitor Call",
10269 [EXCP_VIRQ
] = "Virtual IRQ",
10270 [EXCP_VFIQ
] = "Virtual FIQ",
10271 [EXCP_SEMIHOST
] = "Semihosting call",
10272 [EXCP_NOCP
] = "v7M NOCP UsageFault",
10273 [EXCP_INVSTATE
] = "v7M INVSTATE UsageFault",
10274 [EXCP_STKOF
] = "v8M STKOF UsageFault",
10275 [EXCP_LAZYFP
] = "v7M exception during lazy FP stacking",
10276 [EXCP_LSERR
] = "v8M LSERR UsageFault",
10277 [EXCP_UNALIGNED
] = "v7M UNALIGNED UsageFault",
10278 [EXCP_DIVBYZERO
] = "v7M DIVBYZERO UsageFault",
10279 [EXCP_VSERR
] = "Virtual SERR",
10280 [EXCP_GPC
] = "Granule Protection Check",
10283 if (idx
>= 0 && idx
< ARRAY_SIZE(excnames
)) {
10284 exc
= excnames
[idx
];
10289 qemu_log_mask(CPU_LOG_INT
, "Taking exception %d [%s] on CPU %d\n",
10290 idx
, exc
, cs
->cpu_index
);
10295 * Function used to synchronize QEMU's AArch64 register set with AArch32
10296 * register set. This is necessary when switching between AArch32 and AArch64
10299 void aarch64_sync_32_to_64(CPUARMState
*env
)
10302 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
10304 /* We can blanket copy R[0:7] to X[0:7] */
10305 for (i
= 0; i
< 8; i
++) {
10306 env
->xregs
[i
] = env
->regs
[i
];
10310 * Unless we are in FIQ mode, x8-x12 come from the user registers r8-r12.
10311 * Otherwise, they come from the banked user regs.
10313 if (mode
== ARM_CPU_MODE_FIQ
) {
10314 for (i
= 8; i
< 13; i
++) {
10315 env
->xregs
[i
] = env
->usr_regs
[i
- 8];
10318 for (i
= 8; i
< 13; i
++) {
10319 env
->xregs
[i
] = env
->regs
[i
];
10324 * Registers x13-x23 are the various mode SP and FP registers. Registers
10325 * r13 and r14 are only copied if we are in that mode, otherwise we copy
10326 * from the mode banked register.
10328 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
10329 env
->xregs
[13] = env
->regs
[13];
10330 env
->xregs
[14] = env
->regs
[14];
10332 env
->xregs
[13] = env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)];
10333 /* HYP is an exception in that it is copied from r14 */
10334 if (mode
== ARM_CPU_MODE_HYP
) {
10335 env
->xregs
[14] = env
->regs
[14];
10337 env
->xregs
[14] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_USR
)];
10341 if (mode
== ARM_CPU_MODE_HYP
) {
10342 env
->xregs
[15] = env
->regs
[13];
10344 env
->xregs
[15] = env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)];
10347 if (mode
== ARM_CPU_MODE_IRQ
) {
10348 env
->xregs
[16] = env
->regs
[14];
10349 env
->xregs
[17] = env
->regs
[13];
10351 env
->xregs
[16] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_IRQ
)];
10352 env
->xregs
[17] = env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)];
10355 if (mode
== ARM_CPU_MODE_SVC
) {
10356 env
->xregs
[18] = env
->regs
[14];
10357 env
->xregs
[19] = env
->regs
[13];
10359 env
->xregs
[18] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_SVC
)];
10360 env
->xregs
[19] = env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)];
10363 if (mode
== ARM_CPU_MODE_ABT
) {
10364 env
->xregs
[20] = env
->regs
[14];
10365 env
->xregs
[21] = env
->regs
[13];
10367 env
->xregs
[20] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_ABT
)];
10368 env
->xregs
[21] = env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)];
10371 if (mode
== ARM_CPU_MODE_UND
) {
10372 env
->xregs
[22] = env
->regs
[14];
10373 env
->xregs
[23] = env
->regs
[13];
10375 env
->xregs
[22] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_UND
)];
10376 env
->xregs
[23] = env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)];
10380 * Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
10381 * mode, then we can copy from r8-r14. Otherwise, we copy from the
10382 * FIQ bank for r8-r14.
10384 if (mode
== ARM_CPU_MODE_FIQ
) {
10385 for (i
= 24; i
< 31; i
++) {
10386 env
->xregs
[i
] = env
->regs
[i
- 16]; /* X[24:30] <- R[8:14] */
10389 for (i
= 24; i
< 29; i
++) {
10390 env
->xregs
[i
] = env
->fiq_regs
[i
- 24];
10392 env
->xregs
[29] = env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)];
10393 env
->xregs
[30] = env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_FIQ
)];
10396 env
->pc
= env
->regs
[15];
10400 * Function used to synchronize QEMU's AArch32 register set with AArch64
10401 * register set. This is necessary when switching between AArch32 and AArch64
10404 void aarch64_sync_64_to_32(CPUARMState
*env
)
10407 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
10409 /* We can blanket copy X[0:7] to R[0:7] */
10410 for (i
= 0; i
< 8; i
++) {
10411 env
->regs
[i
] = env
->xregs
[i
];
10415 * Unless we are in FIQ mode, r8-r12 come from the user registers x8-x12.
10416 * Otherwise, we copy x8-x12 into the banked user regs.
10418 if (mode
== ARM_CPU_MODE_FIQ
) {
10419 for (i
= 8; i
< 13; i
++) {
10420 env
->usr_regs
[i
- 8] = env
->xregs
[i
];
10423 for (i
= 8; i
< 13; i
++) {
10424 env
->regs
[i
] = env
->xregs
[i
];
10429 * Registers r13 & r14 depend on the current mode.
10430 * If we are in a given mode, we copy the corresponding x registers to r13
10431 * and r14. Otherwise, we copy the x register to the banked r13 and r14
10434 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
10435 env
->regs
[13] = env
->xregs
[13];
10436 env
->regs
[14] = env
->xregs
[14];
10438 env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[13];
10441 * HYP is an exception in that it does not have its own banked r14 but
10442 * shares the USR r14
10444 if (mode
== ARM_CPU_MODE_HYP
) {
10445 env
->regs
[14] = env
->xregs
[14];
10447 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[14];
10451 if (mode
== ARM_CPU_MODE_HYP
) {
10452 env
->regs
[13] = env
->xregs
[15];
10454 env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)] = env
->xregs
[15];
10457 if (mode
== ARM_CPU_MODE_IRQ
) {
10458 env
->regs
[14] = env
->xregs
[16];
10459 env
->regs
[13] = env
->xregs
[17];
10461 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[16];
10462 env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[17];
10465 if (mode
== ARM_CPU_MODE_SVC
) {
10466 env
->regs
[14] = env
->xregs
[18];
10467 env
->regs
[13] = env
->xregs
[19];
10469 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[18];
10470 env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[19];
10473 if (mode
== ARM_CPU_MODE_ABT
) {
10474 env
->regs
[14] = env
->xregs
[20];
10475 env
->regs
[13] = env
->xregs
[21];
10477 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[20];
10478 env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[21];
10481 if (mode
== ARM_CPU_MODE_UND
) {
10482 env
->regs
[14] = env
->xregs
[22];
10483 env
->regs
[13] = env
->xregs
[23];
10485 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[22];
10486 env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[23];
10490 * Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
10491 * mode, then we can copy to r8-r14. Otherwise, we copy to the
10492 * FIQ bank for r8-r14.
10494 if (mode
== ARM_CPU_MODE_FIQ
) {
10495 for (i
= 24; i
< 31; i
++) {
10496 env
->regs
[i
- 16] = env
->xregs
[i
]; /* X[24:30] -> R[8:14] */
10499 for (i
= 24; i
< 29; i
++) {
10500 env
->fiq_regs
[i
- 24] = env
->xregs
[i
];
10502 env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[29];
10503 env
->banked_r14
[r14_bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[30];
10506 env
->regs
[15] = env
->pc
;
10509 static void take_aarch32_exception(CPUARMState
*env
, int new_mode
,
10510 uint32_t mask
, uint32_t offset
,
10515 /* Change the CPU state so as to actually take the exception. */
10516 switch_mode(env
, new_mode
);
10519 * For exceptions taken to AArch32 we must clear the SS bit in both
10520 * PSTATE and in the old-state value we save to SPSR_<mode>, so zero it now.
10522 env
->pstate
&= ~PSTATE_SS
;
10523 env
->spsr
= cpsr_read(env
);
10524 /* Clear IT bits. */
10525 env
->condexec_bits
= 0;
10526 /* Switch to the new mode, and to the correct instruction set. */
10527 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~CPSR_M
) | new_mode
;
10529 /* This must be after mode switching. */
10530 new_el
= arm_current_el(env
);
10532 /* Set new mode endianness */
10533 env
->uncached_cpsr
&= ~CPSR_E
;
10534 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_EE
) {
10535 env
->uncached_cpsr
|= CPSR_E
;
10537 /* J and IL must always be cleared for exception entry */
10538 env
->uncached_cpsr
&= ~(CPSR_IL
| CPSR_J
);
10541 if (cpu_isar_feature(aa32_ssbs
, env_archcpu(env
))) {
10542 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_DSSBS_32
) {
10543 env
->uncached_cpsr
|= CPSR_SSBS
;
10545 env
->uncached_cpsr
&= ~CPSR_SSBS
;
10549 if (new_mode
== ARM_CPU_MODE_HYP
) {
10550 env
->thumb
= (env
->cp15
.sctlr_el
[2] & SCTLR_TE
) != 0;
10551 env
->elr_el
[2] = env
->regs
[15];
10553 /* CPSR.PAN is normally preserved preserved unless... */
10554 if (cpu_isar_feature(aa32_pan
, env_archcpu(env
))) {
10557 if (!arm_is_secure_below_el3(env
)) {
10558 /* ... the target is EL3, from non-secure state. */
10559 env
->uncached_cpsr
&= ~CPSR_PAN
;
10562 /* ... the target is EL3, from secure state ... */
10565 /* ... the target is EL1 and SCTLR.SPAN is 0. */
10566 if (!(env
->cp15
.sctlr_el
[new_el
] & SCTLR_SPAN
)) {
10567 env
->uncached_cpsr
|= CPSR_PAN
;
10573 * this is a lie, as there was no c1_sys on V4T/V5, but who cares
10574 * and we should just guard the thumb mode on V4
10576 if (arm_feature(env
, ARM_FEATURE_V4T
)) {
10578 (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_TE
) != 0;
10580 env
->regs
[14] = env
->regs
[15] + offset
;
10582 env
->regs
[15] = newpc
;
10584 if (tcg_enabled()) {
10585 arm_rebuild_hflags(env
);
10589 static void arm_cpu_do_interrupt_aarch32_hyp(CPUState
*cs
)
10592 * Handle exception entry to Hyp mode; this is sufficiently
10593 * different to entry to other AArch32 modes that we handle it
10596 * The vector table entry used is always the 0x14 Hyp mode entry point,
10597 * unless this is an UNDEF/SVC/HVC/abort taken from Hyp to Hyp.
10598 * The offset applied to the preferred return address is always zero
10599 * (see DDI0487C.a section G1.12.3).
10600 * PSTATE A/I/F masks are set based only on the SCR.EA/IRQ/FIQ values.
10602 uint32_t addr
, mask
;
10603 ARMCPU
*cpu
= ARM_CPU(cs
);
10604 CPUARMState
*env
= &cpu
->env
;
10606 switch (cs
->exception_index
) {
10614 /* Fall through to prefetch abort. */
10615 case EXCP_PREFETCH_ABORT
:
10616 env
->cp15
.ifar_s
= env
->exception
.vaddress
;
10617 qemu_log_mask(CPU_LOG_INT
, "...with HIFAR 0x%x\n",
10618 (uint32_t)env
->exception
.vaddress
);
10621 case EXCP_DATA_ABORT
:
10622 env
->cp15
.dfar_s
= env
->exception
.vaddress
;
10623 qemu_log_mask(CPU_LOG_INT
, "...with HDFAR 0x%x\n",
10624 (uint32_t)env
->exception
.vaddress
);
10636 case EXCP_HYP_TRAP
:
10640 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
10643 if (cs
->exception_index
!= EXCP_IRQ
&& cs
->exception_index
!= EXCP_FIQ
) {
10644 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
10646 * QEMU syndrome values are v8-style. v7 has the IL bit
10647 * UNK/SBZP for "field not valid" cases, where v8 uses RES1.
10648 * If this is a v7 CPU, squash the IL bit in those cases.
10650 if (cs
->exception_index
== EXCP_PREFETCH_ABORT
||
10651 (cs
->exception_index
== EXCP_DATA_ABORT
&&
10652 !(env
->exception
.syndrome
& ARM_EL_ISV
)) ||
10653 syn_get_ec(env
->exception
.syndrome
) == EC_UNCATEGORIZED
) {
10654 env
->exception
.syndrome
&= ~ARM_EL_IL
;
10657 env
->cp15
.esr_el
[2] = env
->exception
.syndrome
;
10660 if (arm_current_el(env
) != 2 && addr
< 0x14) {
10665 if (!(env
->cp15
.scr_el3
& SCR_EA
)) {
10668 if (!(env
->cp15
.scr_el3
& SCR_IRQ
)) {
10671 if (!(env
->cp15
.scr_el3
& SCR_FIQ
)) {
10675 addr
+= env
->cp15
.hvbar
;
10677 take_aarch32_exception(env
, ARM_CPU_MODE_HYP
, mask
, 0, addr
);
10680 static void arm_cpu_do_interrupt_aarch32(CPUState
*cs
)
10682 ARMCPU
*cpu
= ARM_CPU(cs
);
10683 CPUARMState
*env
= &cpu
->env
;
10690 /* If this is a debug exception we must update the DBGDSCR.MOE bits */
10691 switch (syn_get_ec(env
->exception
.syndrome
)) {
10692 case EC_BREAKPOINT
:
10693 case EC_BREAKPOINT_SAME_EL
:
10696 case EC_WATCHPOINT
:
10697 case EC_WATCHPOINT_SAME_EL
:
10703 case EC_VECTORCATCH
:
10712 env
->cp15
.mdscr_el1
= deposit64(env
->cp15
.mdscr_el1
, 2, 4, moe
);
10715 if (env
->exception
.target_el
== 2) {
10716 arm_cpu_do_interrupt_aarch32_hyp(cs
);
10720 switch (cs
->exception_index
) {
10722 new_mode
= ARM_CPU_MODE_UND
;
10732 new_mode
= ARM_CPU_MODE_SVC
;
10735 /* The PC already points to the next instruction. */
10739 /* Fall through to prefetch abort. */
10740 case EXCP_PREFETCH_ABORT
:
10741 A32_BANKED_CURRENT_REG_SET(env
, ifsr
, env
->exception
.fsr
);
10742 A32_BANKED_CURRENT_REG_SET(env
, ifar
, env
->exception
.vaddress
);
10743 qemu_log_mask(CPU_LOG_INT
, "...with IFSR 0x%x IFAR 0x%x\n",
10744 env
->exception
.fsr
, (uint32_t)env
->exception
.vaddress
);
10745 new_mode
= ARM_CPU_MODE_ABT
;
10747 mask
= CPSR_A
| CPSR_I
;
10750 case EXCP_DATA_ABORT
:
10751 A32_BANKED_CURRENT_REG_SET(env
, dfsr
, env
->exception
.fsr
);
10752 A32_BANKED_CURRENT_REG_SET(env
, dfar
, env
->exception
.vaddress
);
10753 qemu_log_mask(CPU_LOG_INT
, "...with DFSR 0x%x DFAR 0x%x\n",
10754 env
->exception
.fsr
,
10755 (uint32_t)env
->exception
.vaddress
);
10756 new_mode
= ARM_CPU_MODE_ABT
;
10758 mask
= CPSR_A
| CPSR_I
;
10762 new_mode
= ARM_CPU_MODE_IRQ
;
10764 /* Disable IRQ and imprecise data aborts. */
10765 mask
= CPSR_A
| CPSR_I
;
10767 if (env
->cp15
.scr_el3
& SCR_IRQ
) {
10768 /* IRQ routed to monitor mode */
10769 new_mode
= ARM_CPU_MODE_MON
;
10774 new_mode
= ARM_CPU_MODE_FIQ
;
10776 /* Disable FIQ, IRQ and imprecise data aborts. */
10777 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
10778 if (env
->cp15
.scr_el3
& SCR_FIQ
) {
10779 /* FIQ routed to monitor mode */
10780 new_mode
= ARM_CPU_MODE_MON
;
10785 new_mode
= ARM_CPU_MODE_IRQ
;
10787 /* Disable IRQ and imprecise data aborts. */
10788 mask
= CPSR_A
| CPSR_I
;
10792 new_mode
= ARM_CPU_MODE_FIQ
;
10794 /* Disable FIQ, IRQ and imprecise data aborts. */
10795 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
10801 * Note that this is reported as a data abort, but the DFAR
10802 * has an UNKNOWN value. Construct the SError syndrome from
10803 * AET and ExT fields.
10805 ARMMMUFaultInfo fi
= { .type
= ARMFault_AsyncExternal
, };
10807 if (extended_addresses_enabled(env
)) {
10808 env
->exception
.fsr
= arm_fi_to_lfsc(&fi
);
10810 env
->exception
.fsr
= arm_fi_to_sfsc(&fi
);
10812 env
->exception
.fsr
|= env
->cp15
.vsesr_el2
& 0xd000;
10813 A32_BANKED_CURRENT_REG_SET(env
, dfsr
, env
->exception
.fsr
);
10814 qemu_log_mask(CPU_LOG_INT
, "...with IFSR 0x%x\n",
10815 env
->exception
.fsr
);
10817 new_mode
= ARM_CPU_MODE_ABT
;
10819 mask
= CPSR_A
| CPSR_I
;
10824 new_mode
= ARM_CPU_MODE_MON
;
10826 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
10830 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
10831 return; /* Never happens. Keep compiler happy. */
10834 if (new_mode
== ARM_CPU_MODE_MON
) {
10835 addr
+= env
->cp15
.mvbar
;
10836 } else if (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_V
) {
10837 /* High vectors. When enabled, base address cannot be remapped. */
10838 addr
+= 0xffff0000;
10841 * ARM v7 architectures provide a vector base address register to remap
10842 * the interrupt vector table.
10843 * This register is only followed in non-monitor mode, and is banked.
10844 * Note: only bits 31:5 are valid.
10846 addr
+= A32_BANKED_CURRENT_REG_GET(env
, vbar
);
10849 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
) {
10850 env
->cp15
.scr_el3
&= ~SCR_NS
;
10853 take_aarch32_exception(env
, new_mode
, mask
, offset
, addr
);
10856 static int aarch64_regnum(CPUARMState
*env
, int aarch32_reg
)
10859 * Return the register number of the AArch64 view of the AArch32
10860 * register @aarch32_reg. The CPUARMState CPSR is assumed to still
10861 * be that of the AArch32 mode the exception came from.
10863 int mode
= env
->uncached_cpsr
& CPSR_M
;
10865 switch (aarch32_reg
) {
10867 return aarch32_reg
;
10869 return mode
== ARM_CPU_MODE_FIQ
? aarch32_reg
+ 16 : aarch32_reg
;
10872 case ARM_CPU_MODE_USR
:
10873 case ARM_CPU_MODE_SYS
:
10875 case ARM_CPU_MODE_HYP
:
10877 case ARM_CPU_MODE_IRQ
:
10879 case ARM_CPU_MODE_SVC
:
10881 case ARM_CPU_MODE_ABT
:
10883 case ARM_CPU_MODE_UND
:
10885 case ARM_CPU_MODE_FIQ
:
10888 g_assert_not_reached();
10892 case ARM_CPU_MODE_USR
:
10893 case ARM_CPU_MODE_SYS
:
10894 case ARM_CPU_MODE_HYP
:
10896 case ARM_CPU_MODE_IRQ
:
10898 case ARM_CPU_MODE_SVC
:
10900 case ARM_CPU_MODE_ABT
:
10902 case ARM_CPU_MODE_UND
:
10904 case ARM_CPU_MODE_FIQ
:
10907 g_assert_not_reached();
10912 g_assert_not_reached();
10916 static uint32_t cpsr_read_for_spsr_elx(CPUARMState
*env
)
10918 uint32_t ret
= cpsr_read(env
);
10920 /* Move DIT to the correct location for SPSR_ELx */
10921 if (ret
& CPSR_DIT
) {
10925 /* Merge PSTATE.SS into SPSR_ELx */
10926 ret
|= env
->pstate
& PSTATE_SS
;
10931 static bool syndrome_is_sync_extabt(uint32_t syndrome
)
10933 /* Return true if this syndrome value is a synchronous external abort */
10934 switch (syn_get_ec(syndrome
)) {
10936 case EC_INSNABORT_SAME_EL
:
10938 case EC_DATAABORT_SAME_EL
:
10939 /* Look at fault status code for all the synchronous ext abort cases */
10940 switch (syndrome
& 0x3f) {
10956 /* Handle exception entry to a target EL which is using AArch64 */
10957 static void arm_cpu_do_interrupt_aarch64(CPUState
*cs
)
10959 ARMCPU
*cpu
= ARM_CPU(cs
);
10960 CPUARMState
*env
= &cpu
->env
;
10961 unsigned int new_el
= env
->exception
.target_el
;
10962 target_ulong addr
= env
->cp15
.vbar_el
[new_el
];
10963 unsigned int new_mode
= aarch64_pstate_mode(new_el
, true);
10964 unsigned int old_mode
;
10965 unsigned int cur_el
= arm_current_el(env
);
10968 if (tcg_enabled()) {
10970 * Note that new_el can never be 0. If cur_el is 0, then
10971 * el0_a64 is is_a64(), else el0_a64 is ignored.
10973 aarch64_sve_change_el(env
, cur_el
, new_el
, is_a64(env
));
10976 if (cur_el
< new_el
) {
10978 * Entry vector offset depends on whether the implemented EL
10979 * immediately lower than the target level is using AArch32 or AArch64
10986 is_aa64
= (env
->cp15
.scr_el3
& SCR_RW
) != 0;
10989 hcr
= arm_hcr_el2_eff(env
);
10990 if ((hcr
& (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
10991 is_aa64
= (hcr
& HCR_RW
) != 0;
10996 is_aa64
= is_a64(env
);
10999 g_assert_not_reached();
11007 } else if (pstate_read(env
) & PSTATE_SP
) {
11011 switch (cs
->exception_index
) {
11013 qemu_log_mask(CPU_LOG_INT
, "...with MFAR 0x%" PRIx64
"\n",
11014 env
->cp15
.mfar_el3
);
11016 case EXCP_PREFETCH_ABORT
:
11017 case EXCP_DATA_ABORT
:
11019 * FEAT_DoubleFault allows synchronous external aborts taken to EL3
11020 * to be taken to the SError vector entrypoint.
11022 if (new_el
== 3 && (env
->cp15
.scr_el3
& SCR_EASE
) &&
11023 syndrome_is_sync_extabt(env
->exception
.syndrome
)) {
11026 env
->cp15
.far_el
[new_el
] = env
->exception
.vaddress
;
11027 qemu_log_mask(CPU_LOG_INT
, "...with FAR 0x%" PRIx64
"\n",
11028 env
->cp15
.far_el
[new_el
]);
11034 case EXCP_HYP_TRAP
:
11036 switch (syn_get_ec(env
->exception
.syndrome
)) {
11037 case EC_ADVSIMDFPACCESSTRAP
:
11039 * QEMU internal FP/SIMD syndromes from AArch32 include the
11040 * TA and coproc fields which are only exposed if the exception
11041 * is taken to AArch32 Hyp mode. Mask them out to get a valid
11042 * AArch64 format syndrome.
11044 env
->exception
.syndrome
&= ~MAKE_64BIT_MASK(0, 20);
11046 case EC_CP14RTTRAP
:
11047 case EC_CP15RTTRAP
:
11048 case EC_CP14DTTRAP
:
11050 * For a trap on AArch32 MRC/MCR/LDC/STC the Rt field is currently
11051 * the raw register field from the insn; when taking this to
11052 * AArch64 we must convert it to the AArch64 view of the register
11053 * number. Notice that we read a 4-bit AArch32 register number and
11054 * write back a 5-bit AArch64 one.
11056 rt
= extract32(env
->exception
.syndrome
, 5, 4);
11057 rt
= aarch64_regnum(env
, rt
);
11058 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
11061 case EC_CP15RRTTRAP
:
11062 case EC_CP14RRTTRAP
:
11063 /* Similarly for MRRC/MCRR traps for Rt and Rt2 fields */
11064 rt
= extract32(env
->exception
.syndrome
, 5, 4);
11065 rt
= aarch64_regnum(env
, rt
);
11066 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
11068 rt
= extract32(env
->exception
.syndrome
, 10, 4);
11069 rt
= aarch64_regnum(env
, rt
);
11070 env
->exception
.syndrome
= deposit32(env
->exception
.syndrome
,
11074 env
->cp15
.esr_el
[new_el
] = env
->exception
.syndrome
;
11086 /* Construct the SError syndrome from IDS and ISS fields. */
11087 env
->exception
.syndrome
= syn_serror(env
->cp15
.vsesr_el2
& 0x1ffffff);
11088 env
->cp15
.esr_el
[new_el
] = env
->exception
.syndrome
;
11091 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
11095 old_mode
= pstate_read(env
);
11096 aarch64_save_sp(env
, arm_current_el(env
));
11097 env
->elr_el
[new_el
] = env
->pc
;
11099 old_mode
= cpsr_read_for_spsr_elx(env
);
11100 env
->elr_el
[new_el
] = env
->regs
[15];
11102 aarch64_sync_32_to_64(env
);
11104 env
->condexec_bits
= 0;
11106 env
->banked_spsr
[aarch64_banked_spsr_index(new_el
)] = old_mode
;
11108 qemu_log_mask(CPU_LOG_INT
, "...with ELR 0x%" PRIx64
"\n",
11109 env
->elr_el
[new_el
]);
11111 if (cpu_isar_feature(aa64_pan
, cpu
)) {
11112 /* The value of PSTATE.PAN is normally preserved, except when ... */
11113 new_mode
|= old_mode
& PSTATE_PAN
;
11116 /* ... the target is EL2 with HCR_EL2.{E2H,TGE} == '11' ... */
11117 if ((arm_hcr_el2_eff(env
) & (HCR_E2H
| HCR_TGE
))
11118 != (HCR_E2H
| HCR_TGE
)) {
11123 /* ... the target is EL1 ... */
11124 /* ... and SCTLR_ELx.SPAN == 0, then set to 1. */
11125 if ((env
->cp15
.sctlr_el
[new_el
] & SCTLR_SPAN
) == 0) {
11126 new_mode
|= PSTATE_PAN
;
11131 if (cpu_isar_feature(aa64_mte
, cpu
)) {
11132 new_mode
|= PSTATE_TCO
;
11135 if (cpu_isar_feature(aa64_ssbs
, cpu
)) {
11136 if (env
->cp15
.sctlr_el
[new_el
] & SCTLR_DSSBS_64
) {
11137 new_mode
|= PSTATE_SSBS
;
11139 new_mode
&= ~PSTATE_SSBS
;
11143 pstate_write(env
, PSTATE_DAIF
| new_mode
);
11144 env
->aarch64
= true;
11145 aarch64_restore_sp(env
, new_el
);
11147 if (tcg_enabled()) {
11148 helper_rebuild_hflags_a64(env
, new_el
);
11153 qemu_log_mask(CPU_LOG_INT
, "...to EL%d PC 0x%" PRIx64
" PSTATE 0x%x\n",
11154 new_el
, env
->pc
, pstate_read(env
));
11158 * Do semihosting call and set the appropriate return value. All the
11159 * permission and validity checks have been done at translate time.
11161 * We only see semihosting exceptions in TCG only as they are not
11162 * trapped to the hypervisor in KVM.
11165 static void tcg_handle_semihosting(CPUState
*cs
)
11167 ARMCPU
*cpu
= ARM_CPU(cs
);
11168 CPUARMState
*env
= &cpu
->env
;
11171 qemu_log_mask(CPU_LOG_INT
,
11172 "...handling as semihosting call 0x%" PRIx64
"\n",
11174 do_common_semihosting(cs
);
11177 qemu_log_mask(CPU_LOG_INT
,
11178 "...handling as semihosting call 0x%x\n",
11180 do_common_semihosting(cs
);
11181 env
->regs
[15] += env
->thumb
? 2 : 4;
11187 * Handle a CPU exception for A and R profile CPUs.
11188 * Do any appropriate logging, handle PSCI calls, and then hand off
11189 * to the AArch64-entry or AArch32-entry function depending on the
11190 * target exception level's register width.
11192 * Note: this is used for both TCG (as the do_interrupt tcg op),
11193 * and KVM to re-inject guest debug exceptions, and to
11194 * inject a Synchronous-External-Abort.
11196 void arm_cpu_do_interrupt(CPUState
*cs
)
11198 ARMCPU
*cpu
= ARM_CPU(cs
);
11199 CPUARMState
*env
= &cpu
->env
;
11200 unsigned int new_el
= env
->exception
.target_el
;
11202 assert(!arm_feature(env
, ARM_FEATURE_M
));
11204 arm_log_exception(cs
);
11205 qemu_log_mask(CPU_LOG_INT
, "...from EL%d to EL%d\n", arm_current_el(env
),
11207 if (qemu_loglevel_mask(CPU_LOG_INT
)
11208 && !excp_is_internal(cs
->exception_index
)) {
11209 qemu_log_mask(CPU_LOG_INT
, "...with ESR 0x%x/0x%" PRIx32
"\n",
11210 syn_get_ec(env
->exception
.syndrome
),
11211 env
->exception
.syndrome
);
11214 if (tcg_enabled() && arm_is_psci_call(cpu
, cs
->exception_index
)) {
11215 arm_handle_psci_call(cpu
);
11216 qemu_log_mask(CPU_LOG_INT
, "...handled as PSCI call\n");
11221 * Semihosting semantics depend on the register width of the code
11222 * that caused the exception, not the target exception level, so
11223 * must be handled here.
11226 if (cs
->exception_index
== EXCP_SEMIHOST
) {
11227 tcg_handle_semihosting(cs
);
11233 * Hooks may change global state so BQL should be held, also the
11234 * BQL needs to be held for any modification of
11235 * cs->interrupt_request.
11237 g_assert(qemu_mutex_iothread_locked());
11239 arm_call_pre_el_change_hook(cpu
);
11241 assert(!excp_is_internal(cs
->exception_index
));
11242 if (arm_el_is_aa64(env
, new_el
)) {
11243 arm_cpu_do_interrupt_aarch64(cs
);
11245 arm_cpu_do_interrupt_aarch32(cs
);
11248 arm_call_el_change_hook(cpu
);
11250 if (!kvm_enabled()) {
11251 cs
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
11254 #endif /* !CONFIG_USER_ONLY */
11256 uint64_t arm_sctlr(CPUARMState
*env
, int el
)
11258 /* Only EL0 needs to be adjusted for EL1&0 or EL2&0. */
11260 ARMMMUIdx mmu_idx
= arm_mmu_idx_el(env
, 0);
11261 el
= mmu_idx
== ARMMMUIdx_E20_0
? 2 : 1;
11263 return env
->cp15
.sctlr_el
[el
];
11266 int aa64_va_parameter_tbi(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11268 if (regime_has_2_ranges(mmu_idx
)) {
11269 return extract64(tcr
, 37, 2);
11270 } else if (regime_is_stage2(mmu_idx
)) {
11271 return 0; /* VTCR_EL2 */
11273 /* Replicate the single TBI bit so we always have 2 bits. */
11274 return extract32(tcr
, 20, 1) * 3;
11278 int aa64_va_parameter_tbid(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11280 if (regime_has_2_ranges(mmu_idx
)) {
11281 return extract64(tcr
, 51, 2);
11282 } else if (regime_is_stage2(mmu_idx
)) {
11283 return 0; /* VTCR_EL2 */
11285 /* Replicate the single TBID bit so we always have 2 bits. */
11286 return extract32(tcr
, 29, 1) * 3;
11290 int aa64_va_parameter_tcma(uint64_t tcr
, ARMMMUIdx mmu_idx
)
11292 if (regime_has_2_ranges(mmu_idx
)) {
11293 return extract64(tcr
, 57, 2);
11295 /* Replicate the single TCMA bit so we always have 2 bits. */
11296 return extract32(tcr
, 30, 1) * 3;
11300 static ARMGranuleSize
tg0_to_gran_size(int tg
)
11310 return GranInvalid
;
11314 static ARMGranuleSize
tg1_to_gran_size(int tg
)
11324 return GranInvalid
;
11328 static inline bool have4k(ARMCPU
*cpu
, bool stage2
)
11330 return stage2
? cpu_isar_feature(aa64_tgran4_2
, cpu
)
11331 : cpu_isar_feature(aa64_tgran4
, cpu
);
11334 static inline bool have16k(ARMCPU
*cpu
, bool stage2
)
11336 return stage2
? cpu_isar_feature(aa64_tgran16_2
, cpu
)
11337 : cpu_isar_feature(aa64_tgran16
, cpu
);
11340 static inline bool have64k(ARMCPU
*cpu
, bool stage2
)
11342 return stage2
? cpu_isar_feature(aa64_tgran64_2
, cpu
)
11343 : cpu_isar_feature(aa64_tgran64
, cpu
);
11346 static ARMGranuleSize
sanitize_gran_size(ARMCPU
*cpu
, ARMGranuleSize gran
,
11351 if (have4k(cpu
, stage2
)) {
11356 if (have16k(cpu
, stage2
)) {
11361 if (have64k(cpu
, stage2
)) {
11369 * If the guest selects a granule size that isn't implemented,
11370 * the architecture requires that we behave as if it selected one
11371 * that is (with an IMPDEF choice of which one to pick). We choose
11372 * to implement the smallest supported granule size.
11374 if (have4k(cpu
, stage2
)) {
11377 if (have16k(cpu
, stage2
)) {
11380 assert(have64k(cpu
, stage2
));
11384 ARMVAParameters
aa64_va_parameters(CPUARMState
*env
, uint64_t va
,
11385 ARMMMUIdx mmu_idx
, bool data
,
11388 uint64_t tcr
= regime_tcr(env
, mmu_idx
);
11389 bool epd
, hpd
, tsz_oob
, ds
, ha
, hd
;
11390 int select
, tsz
, tbi
, max_tsz
, min_tsz
, ps
, sh
;
11391 ARMGranuleSize gran
;
11392 ARMCPU
*cpu
= env_archcpu(env
);
11393 bool stage2
= regime_is_stage2(mmu_idx
);
11395 if (!regime_has_2_ranges(mmu_idx
)) {
11397 tsz
= extract32(tcr
, 0, 6);
11398 gran
= tg0_to_gran_size(extract32(tcr
, 14, 2));
11403 hpd
= extract32(tcr
, 24, 1);
11406 sh
= extract32(tcr
, 12, 2);
11407 ps
= extract32(tcr
, 16, 3);
11408 ha
= extract32(tcr
, 21, 1) && cpu_isar_feature(aa64_hafs
, cpu
);
11409 hd
= extract32(tcr
, 22, 1) && cpu_isar_feature(aa64_hdbs
, cpu
);
11410 ds
= extract64(tcr
, 32, 1);
11415 * Bit 55 is always between the two regions, and is canonical for
11416 * determining if address tagging is enabled.
11418 select
= extract64(va
, 55, 1);
11420 tsz
= extract32(tcr
, 0, 6);
11421 gran
= tg0_to_gran_size(extract32(tcr
, 14, 2));
11422 epd
= extract32(tcr
, 7, 1);
11423 sh
= extract32(tcr
, 12, 2);
11424 hpd
= extract64(tcr
, 41, 1);
11425 e0pd
= extract64(tcr
, 55, 1);
11427 tsz
= extract32(tcr
, 16, 6);
11428 gran
= tg1_to_gran_size(extract32(tcr
, 30, 2));
11429 epd
= extract32(tcr
, 23, 1);
11430 sh
= extract32(tcr
, 28, 2);
11431 hpd
= extract64(tcr
, 42, 1);
11432 e0pd
= extract64(tcr
, 56, 1);
11434 ps
= extract64(tcr
, 32, 3);
11435 ha
= extract64(tcr
, 39, 1) && cpu_isar_feature(aa64_hafs
, cpu
);
11436 hd
= extract64(tcr
, 40, 1) && cpu_isar_feature(aa64_hdbs
, cpu
);
11437 ds
= extract64(tcr
, 59, 1);
11439 if (e0pd
&& cpu_isar_feature(aa64_e0pd
, cpu
) &&
11440 regime_is_user(env
, mmu_idx
)) {
11445 gran
= sanitize_gran_size(cpu
, gran
, stage2
);
11447 if (cpu_isar_feature(aa64_st
, cpu
)) {
11448 max_tsz
= 48 - (gran
== Gran64K
);
11454 * DS is RES0 unless FEAT_LPA2 is supported for the given page size;
11455 * adjust the effective value of DS, as documented.
11458 if (gran
== Gran64K
) {
11459 if (cpu_isar_feature(aa64_lva
, cpu
)) {
11464 if (regime_is_stage2(mmu_idx
)) {
11465 if (gran
== Gran16K
) {
11466 ds
= cpu_isar_feature(aa64_tgran16_2_lpa2
, cpu
);
11468 ds
= cpu_isar_feature(aa64_tgran4_2_lpa2
, cpu
);
11471 if (gran
== Gran16K
) {
11472 ds
= cpu_isar_feature(aa64_tgran16_lpa2
, cpu
);
11474 ds
= cpu_isar_feature(aa64_tgran4_lpa2
, cpu
);
11482 if (stage2
&& el1_is_aa32
) {
11484 * For AArch32 EL1 the min txsz (and thus max IPA size) requirements
11485 * are loosened: a configured IPA of 40 bits is permitted even if
11486 * the implemented PA is less than that (and so a 40 bit IPA would
11487 * fault for an AArch64 EL1). See R_DTLMN.
11489 min_tsz
= MIN(min_tsz
, 24);
11492 if (tsz
> max_tsz
) {
11495 } else if (tsz
< min_tsz
) {
11502 /* Present TBI as a composite with TBID. */
11503 tbi
= aa64_va_parameter_tbi(tcr
, mmu_idx
);
11505 tbi
&= ~aa64_va_parameter_tbid(tcr
, mmu_idx
);
11507 tbi
= (tbi
>> select
) & 1;
11509 return (ARMVAParameters
) {
11517 .tsz_oob
= tsz_oob
,
11526 * Note that signed overflow is undefined in C. The following routines are
11527 * careful to use unsigned types where modulo arithmetic is required.
11528 * Failure to do so _will_ break on newer gcc.
11531 /* Signed saturating arithmetic. */
11533 /* Perform 16-bit signed saturating addition. */
11534 static inline uint16_t add16_sat(uint16_t a
, uint16_t b
)
11539 if (((res
^ a
) & 0x8000) && !((a
^ b
) & 0x8000)) {
11549 /* Perform 8-bit signed saturating addition. */
11550 static inline uint8_t add8_sat(uint8_t a
, uint8_t b
)
11555 if (((res
^ a
) & 0x80) && !((a
^ b
) & 0x80)) {
11565 /* Perform 16-bit signed saturating subtraction. */
11566 static inline uint16_t sub16_sat(uint16_t a
, uint16_t b
)
11571 if (((res
^ a
) & 0x8000) && ((a
^ b
) & 0x8000)) {
11581 /* Perform 8-bit signed saturating subtraction. */
11582 static inline uint8_t sub8_sat(uint8_t a
, uint8_t b
)
11587 if (((res
^ a
) & 0x80) && ((a
^ b
) & 0x80)) {
11597 #define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
11598 #define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
11599 #define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
11600 #define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
11603 #include "op_addsub.h"
11605 /* Unsigned saturating arithmetic. */
11606 static inline uint16_t add16_usat(uint16_t a
, uint16_t b
)
11616 static inline uint16_t sub16_usat(uint16_t a
, uint16_t b
)
11625 static inline uint8_t add8_usat(uint8_t a
, uint8_t b
)
11635 static inline uint8_t sub8_usat(uint8_t a
, uint8_t b
)
11644 #define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
11645 #define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
11646 #define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
11647 #define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
11650 #include "op_addsub.h"
11652 /* Signed modulo arithmetic. */
11653 #define SARITH16(a, b, n, op) do { \
11655 sum = (int32_t)(int16_t)(a) op (int32_t)(int16_t)(b); \
11656 RESULT(sum, n, 16); \
11658 ge |= 3 << (n * 2); \
11661 #define SARITH8(a, b, n, op) do { \
11663 sum = (int32_t)(int8_t)(a) op (int32_t)(int8_t)(b); \
11664 RESULT(sum, n, 8); \
11670 #define ADD16(a, b, n) SARITH16(a, b, n, +)
11671 #define SUB16(a, b, n) SARITH16(a, b, n, -)
11672 #define ADD8(a, b, n) SARITH8(a, b, n, +)
11673 #define SUB8(a, b, n) SARITH8(a, b, n, -)
11677 #include "op_addsub.h"
11679 /* Unsigned modulo arithmetic. */
11680 #define ADD16(a, b, n) do { \
11682 sum = (uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b); \
11683 RESULT(sum, n, 16); \
11684 if ((sum >> 16) == 1) \
11685 ge |= 3 << (n * 2); \
11688 #define ADD8(a, b, n) do { \
11690 sum = (uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b); \
11691 RESULT(sum, n, 8); \
11692 if ((sum >> 8) == 1) \
11696 #define SUB16(a, b, n) do { \
11698 sum = (uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b); \
11699 RESULT(sum, n, 16); \
11700 if ((sum >> 16) == 0) \
11701 ge |= 3 << (n * 2); \
11704 #define SUB8(a, b, n) do { \
11706 sum = (uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b); \
11707 RESULT(sum, n, 8); \
11708 if ((sum >> 8) == 0) \
11715 #include "op_addsub.h"
11717 /* Halved signed arithmetic. */
11718 #define ADD16(a, b, n) \
11719 RESULT(((int32_t)(int16_t)(a) + (int32_t)(int16_t)(b)) >> 1, n, 16)
11720 #define SUB16(a, b, n) \
11721 RESULT(((int32_t)(int16_t)(a) - (int32_t)(int16_t)(b)) >> 1, n, 16)
11722 #define ADD8(a, b, n) \
11723 RESULT(((int32_t)(int8_t)(a) + (int32_t)(int8_t)(b)) >> 1, n, 8)
11724 #define SUB8(a, b, n) \
11725 RESULT(((int32_t)(int8_t)(a) - (int32_t)(int8_t)(b)) >> 1, n, 8)
11728 #include "op_addsub.h"
11730 /* Halved unsigned arithmetic. */
11731 #define ADD16(a, b, n) \
11732 RESULT(((uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b)) >> 1, n, 16)
11733 #define SUB16(a, b, n) \
11734 RESULT(((uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b)) >> 1, n, 16)
11735 #define ADD8(a, b, n) \
11736 RESULT(((uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b)) >> 1, n, 8)
11737 #define SUB8(a, b, n) \
11738 RESULT(((uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b)) >> 1, n, 8)
11741 #include "op_addsub.h"
11743 static inline uint8_t do_usad(uint8_t a
, uint8_t b
)
11752 /* Unsigned sum of absolute byte differences. */
11753 uint32_t HELPER(usad8
)(uint32_t a
, uint32_t b
)
11756 sum
= do_usad(a
, b
);
11757 sum
+= do_usad(a
>> 8, b
>> 8);
11758 sum
+= do_usad(a
>> 16, b
>> 16);
11759 sum
+= do_usad(a
>> 24, b
>> 24);
11763 /* For ARMv6 SEL instruction. */
11764 uint32_t HELPER(sel_flags
)(uint32_t flags
, uint32_t a
, uint32_t b
)
11779 mask
|= 0xff000000;
11781 return (a
& mask
) | (b
& ~mask
);
11786 * The upper bytes of val (above the number specified by 'bytes') must have
11787 * been zeroed out by the caller.
11789 uint32_t HELPER(crc32
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
11793 stl_le_p(buf
, val
);
11795 /* zlib crc32 converts the accumulator and output to one's complement. */
11796 return crc32(acc
^ 0xffffffff, buf
, bytes
) ^ 0xffffffff;
11799 uint32_t HELPER(crc32c
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
11803 stl_le_p(buf
, val
);
11805 /* Linux crc32c converts the output to one's complement. */
11806 return crc32c(acc
, buf
, bytes
) ^ 0xffffffff;
11810 * Return the exception level to which FP-disabled exceptions should
11811 * be taken, or 0 if FP is enabled.
11813 int fp_exception_el(CPUARMState
*env
, int cur_el
)
11815 #ifndef CONFIG_USER_ONLY
11819 * CPACR and the CPTR registers don't exist before v6, so FP is
11820 * always accessible
11822 if (!arm_feature(env
, ARM_FEATURE_V6
)) {
11826 if (arm_feature(env
, ARM_FEATURE_M
)) {
11827 /* CPACR can cause a NOCP UsageFault taken to current security state */
11828 if (!v7m_cpacr_pass(env
, env
->v7m
.secure
, cur_el
!= 0)) {
11832 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
) && !env
->v7m
.secure
) {
11833 if (!extract32(env
->v7m
.nsacr
, 10, 1)) {
11834 /* FP insns cause a NOCP UsageFault taken to Secure */
11842 hcr_el2
= arm_hcr_el2_eff(env
);
11845 * The CPACR controls traps to EL1, or PL1 if we're 32 bit:
11846 * 0, 2 : trap EL0 and EL1/PL1 accesses
11847 * 1 : trap only EL0 accesses
11848 * 3 : trap no accesses
11849 * This register is ignored if E2H+TGE are both set.
11851 if ((hcr_el2
& (HCR_E2H
| HCR_TGE
)) != (HCR_E2H
| HCR_TGE
)) {
11852 int fpen
= FIELD_EX64(env
->cp15
.cpacr_el1
, CPACR_EL1
, FPEN
);
11862 /* Trap from Secure PL0 or PL1 to Secure PL1. */
11863 if (!arm_el_is_aa64(env
, 3)
11864 && (cur_el
== 3 || arm_is_secure_below_el3(env
))) {
11875 * The NSACR allows A-profile AArch32 EL3 and M-profile secure mode
11876 * to control non-secure access to the FPU. It doesn't have any
11877 * effect if EL3 is AArch64 or if EL3 doesn't exist at all.
11879 if ((arm_feature(env
, ARM_FEATURE_EL3
) && !arm_el_is_aa64(env
, 3) &&
11880 cur_el
<= 2 && !arm_is_secure_below_el3(env
))) {
11881 if (!extract32(env
->cp15
.nsacr
, 10, 1)) {
11882 /* FP insns act as UNDEF */
11883 return cur_el
== 2 ? 2 : 1;
11888 * CPTR_EL2 is present in v7VE or v8, and changes format
11889 * with HCR_EL2.E2H (regardless of TGE).
11892 if (hcr_el2
& HCR_E2H
) {
11893 switch (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, FPEN
)) {
11895 if (cur_el
!= 0 || !(hcr_el2
& HCR_TGE
)) {
11903 } else if (arm_is_el2_enabled(env
)) {
11904 if (FIELD_EX64(env
->cp15
.cptr_el
[2], CPTR_EL2
, TFP
)) {
11910 /* CPTR_EL3 : present in v8 */
11911 if (FIELD_EX64(env
->cp15
.cptr_el
[3], CPTR_EL3
, TFP
)) {
11912 /* Trap all FP ops to EL3 */
11919 /* Return the exception level we're running at if this is our mmu_idx */
11920 int arm_mmu_idx_to_el(ARMMMUIdx mmu_idx
)
11922 if (mmu_idx
& ARM_MMU_IDX_M
) {
11923 return mmu_idx
& ARM_MMU_IDX_M_PRIV
;
11927 case ARMMMUIdx_E10_0
:
11928 case ARMMMUIdx_E20_0
:
11930 case ARMMMUIdx_E10_1
:
11931 case ARMMMUIdx_E10_1_PAN
:
11934 case ARMMMUIdx_E20_2
:
11935 case ARMMMUIdx_E20_2_PAN
:
11940 g_assert_not_reached();
11945 ARMMMUIdx
arm_v7m_mmu_idx_for_secstate(CPUARMState
*env
, bool secstate
)
11947 g_assert_not_reached();
11951 static bool arm_pan_enabled(CPUARMState
*env
)
11954 return env
->pstate
& PSTATE_PAN
;
11956 return env
->uncached_cpsr
& CPSR_PAN
;
11960 ARMMMUIdx
arm_mmu_idx_el(CPUARMState
*env
, int el
)
11965 if (arm_feature(env
, ARM_FEATURE_M
)) {
11966 return arm_v7m_mmu_idx_for_secstate(env
, env
->v7m
.secure
);
11969 /* See ARM pseudo-function ELIsInHost. */
11972 hcr
= arm_hcr_el2_eff(env
);
11973 if ((hcr
& (HCR_E2H
| HCR_TGE
)) == (HCR_E2H
| HCR_TGE
)) {
11974 idx
= ARMMMUIdx_E20_0
;
11976 idx
= ARMMMUIdx_E10_0
;
11980 if (arm_pan_enabled(env
)) {
11981 idx
= ARMMMUIdx_E10_1_PAN
;
11983 idx
= ARMMMUIdx_E10_1
;
11987 /* Note that TGE does not apply at EL2. */
11988 if (arm_hcr_el2_eff(env
) & HCR_E2H
) {
11989 if (arm_pan_enabled(env
)) {
11990 idx
= ARMMMUIdx_E20_2_PAN
;
11992 idx
= ARMMMUIdx_E20_2
;
11995 idx
= ARMMMUIdx_E2
;
11999 return ARMMMUIdx_E3
;
12001 g_assert_not_reached();
12007 ARMMMUIdx
arm_mmu_idx(CPUARMState
*env
)
12009 return arm_mmu_idx_el(env
, arm_current_el(env
));
12012 static bool mve_no_pred(CPUARMState
*env
)
12015 * Return true if there is definitely no predication of MVE
12016 * instructions by VPR or LTPSIZE. (Returning false even if there
12017 * isn't any predication is OK; generated code will just be
12019 * If the CPU does not implement MVE then this TB flag is always 0.
12021 * NOTE: if you change this logic, the "recalculate s->mve_no_pred"
12022 * logic in gen_update_fp_context() needs to be updated to match.
12024 * We do not include the effect of the ECI bits here -- they are
12025 * tracked in other TB flags. This simplifies the logic for
12026 * "when did we emit code that changes the MVE_NO_PRED TB flag
12027 * and thus need to end the TB?".
12029 if (cpu_isar_feature(aa32_mve
, env_archcpu(env
))) {
12032 if (env
->v7m
.vpr
) {
12035 if (env
->v7m
.ltpsize
< 4) {
12041 void cpu_get_tb_cpu_state(CPUARMState
*env
, vaddr
*pc
,
12042 uint64_t *cs_base
, uint32_t *pflags
)
12044 CPUARMTBFlags flags
;
12046 assert_hflags_rebuild_correctly(env
);
12047 flags
= env
->hflags
;
12049 if (EX_TBFLAG_ANY(flags
, AARCH64_STATE
)) {
12051 if (cpu_isar_feature(aa64_bti
, env_archcpu(env
))) {
12052 DP_TBFLAG_A64(flags
, BTYPE
, env
->btype
);
12055 *pc
= env
->regs
[15];
12057 if (arm_feature(env
, ARM_FEATURE_M
)) {
12058 if (arm_feature(env
, ARM_FEATURE_M_SECURITY
) &&
12059 FIELD_EX32(env
->v7m
.fpccr
[M_REG_S
], V7M_FPCCR
, S
)
12060 != env
->v7m
.secure
) {
12061 DP_TBFLAG_M32(flags
, FPCCR_S_WRONG
, 1);
12064 if ((env
->v7m
.fpccr
[env
->v7m
.secure
] & R_V7M_FPCCR_ASPEN_MASK
) &&
12065 (!(env
->v7m
.control
[M_REG_S
] & R_V7M_CONTROL_FPCA_MASK
) ||
12066 (env
->v7m
.secure
&&
12067 !(env
->v7m
.control
[M_REG_S
] & R_V7M_CONTROL_SFPA_MASK
)))) {
12069 * ASPEN is set, but FPCA/SFPA indicate that there is no
12070 * active FP context; we must create a new FP context before
12071 * executing any FP insn.
12073 DP_TBFLAG_M32(flags
, NEW_FP_CTXT_NEEDED
, 1);
12076 bool is_secure
= env
->v7m
.fpccr
[M_REG_S
] & R_V7M_FPCCR_S_MASK
;
12077 if (env
->v7m
.fpccr
[is_secure
] & R_V7M_FPCCR_LSPACT_MASK
) {
12078 DP_TBFLAG_M32(flags
, LSPACT
, 1);
12081 if (mve_no_pred(env
)) {
12082 DP_TBFLAG_M32(flags
, MVE_NO_PRED
, 1);
12086 * Note that XSCALE_CPAR shares bits with VECSTRIDE.
12087 * Note that VECLEN+VECSTRIDE are RES0 for M-profile.
12089 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
12090 DP_TBFLAG_A32(flags
, XSCALE_CPAR
, env
->cp15
.c15_cpar
);
12092 DP_TBFLAG_A32(flags
, VECLEN
, env
->vfp
.vec_len
);
12093 DP_TBFLAG_A32(flags
, VECSTRIDE
, env
->vfp
.vec_stride
);
12095 if (env
->vfp
.xregs
[ARM_VFP_FPEXC
] & (1 << 30)) {
12096 DP_TBFLAG_A32(flags
, VFPEN
, 1);
12100 DP_TBFLAG_AM32(flags
, THUMB
, env
->thumb
);
12101 DP_TBFLAG_AM32(flags
, CONDEXEC
, env
->condexec_bits
);
12105 * The SS_ACTIVE and PSTATE_SS bits correspond to the state machine
12106 * states defined in the ARM ARM for software singlestep:
12107 * SS_ACTIVE PSTATE.SS State
12108 * 0 x Inactive (the TB flag for SS is always 0)
12109 * 1 0 Active-pending
12110 * 1 1 Active-not-pending
12111 * SS_ACTIVE is set in hflags; PSTATE__SS is computed every TB.
12113 if (EX_TBFLAG_ANY(flags
, SS_ACTIVE
) && (env
->pstate
& PSTATE_SS
)) {
12114 DP_TBFLAG_ANY(flags
, PSTATE__SS
, 1);
12117 *pflags
= flags
.flags
;
12118 *cs_base
= flags
.flags2
;
12121 #ifdef TARGET_AARCH64
12123 * The manual says that when SVE is enabled and VQ is widened the
12124 * implementation is allowed to zero the previously inaccessible
12125 * portion of the registers. The corollary to that is that when
12126 * SVE is enabled and VQ is narrowed we are also allowed to zero
12127 * the now inaccessible portion of the registers.
12129 * The intent of this is that no predicate bit beyond VQ is ever set.
12130 * Which means that some operations on predicate registers themselves
12131 * may operate on full uint64_t or even unrolled across the maximum
12132 * uint64_t[4]. Performing 4 bits of host arithmetic unconditionally
12133 * may well be cheaper than conditionals to restrict the operation
12134 * to the relevant portion of a uint16_t[16].
12136 void aarch64_sve_narrow_vq(CPUARMState
*env
, unsigned vq
)
12141 assert(vq
>= 1 && vq
<= ARM_MAX_VQ
);
12142 assert(vq
<= env_archcpu(env
)->sve_max_vq
);
12144 /* Zap the high bits of the zregs. */
12145 for (i
= 0; i
< 32; i
++) {
12146 memset(&env
->vfp
.zregs
[i
].d
[2 * vq
], 0, 16 * (ARM_MAX_VQ
- vq
));
12149 /* Zap the high bits of the pregs and ffr. */
12152 pmask
= ~(-1ULL << (16 * (vq
& 3)));
12154 for (j
= vq
/ 4; j
< ARM_MAX_VQ
/ 4; j
++) {
12155 for (i
= 0; i
< 17; ++i
) {
12156 env
->vfp
.pregs
[i
].p
[j
] &= pmask
;
12162 static uint32_t sve_vqm1_for_el_sm_ena(CPUARMState
*env
, int el
, bool sm
)
12167 exc_el
= sme_exception_el(env
, el
);
12169 exc_el
= sve_exception_el(env
, el
);
12172 return 0; /* disabled */
12174 return sve_vqm1_for_el_sm(env
, el
, sm
);
12178 * Notice a change in SVE vector size when changing EL.
12180 void aarch64_sve_change_el(CPUARMState
*env
, int old_el
,
12181 int new_el
, bool el0_a64
)
12183 ARMCPU
*cpu
= env_archcpu(env
);
12184 int old_len
, new_len
;
12185 bool old_a64
, new_a64
, sm
;
12187 /* Nothing to do if no SVE. */
12188 if (!cpu_isar_feature(aa64_sve
, cpu
)) {
12192 /* Nothing to do if FP is disabled in either EL. */
12193 if (fp_exception_el(env
, old_el
) || fp_exception_el(env
, new_el
)) {
12197 old_a64
= old_el
? arm_el_is_aa64(env
, old_el
) : el0_a64
;
12198 new_a64
= new_el
? arm_el_is_aa64(env
, new_el
) : el0_a64
;
12201 * Both AArch64.TakeException and AArch64.ExceptionReturn
12202 * invoke ResetSVEState when taking an exception from, or
12203 * returning to, AArch32 state when PSTATE.SM is enabled.
12205 sm
= FIELD_EX64(env
->svcr
, SVCR
, SM
);
12206 if (old_a64
!= new_a64
&& sm
) {
12207 arm_reset_sve_state(env
);
12212 * DDI0584A.d sec 3.2: "If SVE instructions are disabled or trapped
12213 * at ELx, or not available because the EL is in AArch32 state, then
12214 * for all purposes other than a direct read, the ZCR_ELx.LEN field
12215 * has an effective value of 0".
12217 * Consider EL2 (aa64, vq=4) -> EL0 (aa32) -> EL1 (aa64, vq=0).
12218 * If we ignore aa32 state, we would fail to see the vq4->vq0 transition
12219 * from EL2->EL1. Thus we go ahead and narrow when entering aa32 so that
12220 * we already have the correct register contents when encountering the
12221 * vq0->vq0 transition between EL0->EL1.
12223 old_len
= new_len
= 0;
12225 old_len
= sve_vqm1_for_el_sm_ena(env
, old_el
, sm
);
12228 new_len
= sve_vqm1_for_el_sm_ena(env
, new_el
, sm
);
12231 /* When changing vector length, clear inaccessible state. */
12232 if (new_len
< old_len
) {
12233 aarch64_sve_narrow_vq(env
, new_len
+ 1);
12238 #ifndef CONFIG_USER_ONLY
12239 ARMSecuritySpace
arm_security_space(CPUARMState
*env
)
12241 if (arm_feature(env
, ARM_FEATURE_M
)) {
12242 return arm_secure_to_space(env
->v7m
.secure
);
12246 * If EL3 is not supported then the secure state is implementation
12247 * defined, in which case QEMU defaults to non-secure.
12249 if (!arm_feature(env
, ARM_FEATURE_EL3
)) {
12250 return ARMSS_NonSecure
;
12253 /* Check for AArch64 EL3 or AArch32 Mon. */
12255 if (extract32(env
->pstate
, 2, 2) == 3) {
12256 if (cpu_isar_feature(aa64_rme
, env_archcpu(env
))) {
12259 return ARMSS_Secure
;
12263 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
) {
12264 return ARMSS_Secure
;
12268 return arm_security_space_below_el3(env
);
12271 ARMSecuritySpace
arm_security_space_below_el3(CPUARMState
*env
)
12273 assert(!arm_feature(env
, ARM_FEATURE_M
));
12276 * If EL3 is not supported then the secure state is implementation
12277 * defined, in which case QEMU defaults to non-secure.
12279 if (!arm_feature(env
, ARM_FEATURE_EL3
)) {
12280 return ARMSS_NonSecure
;
12284 * Note NSE cannot be set without RME, and NSE & !NS is Reserved.
12285 * Ignoring NSE when !NS retains consistency without having to
12286 * modify other predicates.
12288 if (!(env
->cp15
.scr_el3
& SCR_NS
)) {
12289 return ARMSS_Secure
;
12290 } else if (env
->cp15
.scr_el3
& SCR_NSE
) {
12291 return ARMSS_Realm
;
12293 return ARMSS_NonSecure
;
12296 #endif /* !CONFIG_USER_ONLY */