1 #include "qemu/osdep.h"
4 #include "exec/gdbstub.h"
5 #include "exec/helper-proto.h"
6 #include "qemu/host-utils.h"
7 #include "sysemu/arch_init.h"
8 #include "sysemu/sysemu.h"
9 #include "qemu/bitops.h"
10 #include "qemu/crc32c.h"
11 #include "exec/exec-all.h"
12 #include "exec/cpu_ldst.h"
14 #include <zlib.h> /* For crc32 */
15 #include "exec/semihost.h"
16 #include "sysemu/kvm.h"
18 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */
20 #ifndef CONFIG_USER_ONLY
21 static bool get_phys_addr(CPUARMState
*env
, target_ulong address
,
22 int access_type
, ARMMMUIdx mmu_idx
,
23 hwaddr
*phys_ptr
, MemTxAttrs
*attrs
, int *prot
,
24 target_ulong
*page_size
, uint32_t *fsr
,
27 static bool get_phys_addr_lpae(CPUARMState
*env
, target_ulong address
,
28 int access_type
, ARMMMUIdx mmu_idx
,
29 hwaddr
*phys_ptr
, MemTxAttrs
*txattrs
, int *prot
,
30 target_ulong
*page_size_ptr
, uint32_t *fsr
,
33 /* Definitions for the PMCCNTR and PMCR registers */
39 static int vfp_gdb_get_reg(CPUARMState
*env
, uint8_t *buf
, int reg
)
43 /* VFP data registers are always little-endian. */
44 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ?
32 : 16;
46 stfq_le_p(buf
, env
->vfp
.regs
[reg
]);
49 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
50 /* Aliases for Q regs. */
53 stfq_le_p(buf
, env
->vfp
.regs
[(reg
- 32) * 2]);
54 stfq_le_p(buf
+ 8, env
->vfp
.regs
[(reg
- 32) * 2 + 1]);
58 switch (reg
- nregs
) {
59 case 0: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSID
]); return 4;
60 case 1: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSCR
]); return 4;
61 case 2: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPEXC
]); return 4;
66 static int vfp_gdb_set_reg(CPUARMState
*env
, uint8_t *buf
, int reg
)
70 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ?
32 : 16;
72 env
->vfp
.regs
[reg
] = ldfq_le_p(buf
);
75 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
78 env
->vfp
.regs
[(reg
- 32) * 2] = ldfq_le_p(buf
);
79 env
->vfp
.regs
[(reg
- 32) * 2 + 1] = ldfq_le_p(buf
+ 8);
83 switch (reg
- nregs
) {
84 case 0: env
->vfp
.xregs
[ARM_VFP_FPSID
] = ldl_p(buf
); return 4;
85 case 1: env
->vfp
.xregs
[ARM_VFP_FPSCR
] = ldl_p(buf
); return 4;
86 case 2: env
->vfp
.xregs
[ARM_VFP_FPEXC
] = ldl_p(buf
) & (1 << 30); return 4;
91 static int aarch64_fpu_gdb_get_reg(CPUARMState
*env
, uint8_t *buf
, int reg
)
95 /* 128 bit FP register */
96 stfq_le_p(buf
, env
->vfp
.regs
[reg
* 2]);
97 stfq_le_p(buf
+ 8, env
->vfp
.regs
[reg
* 2 + 1]);
101 stl_p(buf
, vfp_get_fpsr(env
));
105 stl_p(buf
, vfp_get_fpcr(env
));
112 static int aarch64_fpu_gdb_set_reg(CPUARMState
*env
, uint8_t *buf
, int reg
)
116 /* 128 bit FP register */
117 env
->vfp
.regs
[reg
* 2] = ldfq_le_p(buf
);
118 env
->vfp
.regs
[reg
* 2 + 1] = ldfq_le_p(buf
+ 8);
122 vfp_set_fpsr(env
, ldl_p(buf
));
126 vfp_set_fpcr(env
, ldl_p(buf
));
133 static uint64_t raw_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
135 assert(ri
->fieldoffset
);
136 if (cpreg_field_is_64bit(ri
)) {
137 return CPREG_FIELD64(env
, ri
);
139 return CPREG_FIELD32(env
, ri
);
143 static void raw_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
146 assert(ri
->fieldoffset
);
147 if (cpreg_field_is_64bit(ri
)) {
148 CPREG_FIELD64(env
, ri
) = value
;
150 CPREG_FIELD32(env
, ri
) = value
;
154 static void *raw_ptr(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
156 return (char *)env
+ ri
->fieldoffset
;
159 uint64_t read_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
161 /* Raw read of a coprocessor register (as needed for migration, etc). */
162 if (ri
->type
& ARM_CP_CONST
) {
163 return ri
->resetvalue
;
164 } else if (ri
->raw_readfn
) {
165 return ri
->raw_readfn(env
, ri
);
166 } else if (ri
->readfn
) {
167 return ri
->readfn(env
, ri
);
169 return raw_read(env
, ri
);
173 static void write_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
176 /* Raw write of a coprocessor register (as needed for migration, etc).
177 * Note that constant registers are treated as write-ignored; the
178 * caller should check for success by whether a readback gives the
181 if (ri
->type
& ARM_CP_CONST
) {
183 } else if (ri
->raw_writefn
) {
184 ri
->raw_writefn(env
, ri
, v
);
185 } else if (ri
->writefn
) {
186 ri
->writefn(env
, ri
, v
);
188 raw_write(env
, ri
, v
);
192 static bool raw_accessors_invalid(const ARMCPRegInfo
*ri
)
194 /* Return true if the regdef would cause an assertion if you called
195 * read_raw_cp_reg() or write_raw_cp_reg() on it (ie if it is a
196 * program bug for it not to have the NO_RAW flag).
197 * NB that returning false here doesn't necessarily mean that calling
198 * read/write_raw_cp_reg() is safe, because we can't distinguish "has
199 * read/write access functions which are safe for raw use" from "has
200 * read/write access functions which have side effects but has forgotten
201 * to provide raw access functions".
202 * The tests here line up with the conditions in read/write_raw_cp_reg()
203 * and assertions in raw_read()/raw_write().
205 if ((ri
->type
& ARM_CP_CONST
) ||
207 ((ri
->raw_writefn
|| ri
->writefn
) && (ri
->raw_readfn
|| ri
->readfn
))) {
213 bool write_cpustate_to_list(ARMCPU
*cpu
)
215 /* Write the coprocessor state from cpu->env to the (index,value) list. */
219 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
220 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
221 const ARMCPRegInfo
*ri
;
223 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
228 if (ri
->type
& ARM_CP_NO_RAW
) {
231 cpu
->cpreg_values
[i
] = read_raw_cp_reg(&cpu
->env
, ri
);
236 bool write_list_to_cpustate(ARMCPU
*cpu
)
241 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
242 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
243 uint64_t v
= cpu
->cpreg_values
[i
];
244 const ARMCPRegInfo
*ri
;
246 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
251 if (ri
->type
& ARM_CP_NO_RAW
) {
254 /* Write value and confirm it reads back as written
255 * (to catch read-only registers and partially read-only
256 * registers where the incoming migration value doesn't match)
258 write_raw_cp_reg(&cpu
->env
, ri
, v
);
259 if (read_raw_cp_reg(&cpu
->env
, ri
) != v
) {
266 static void add_cpreg_to_list(gpointer key
, gpointer opaque
)
268 ARMCPU
*cpu
= opaque
;
270 const ARMCPRegInfo
*ri
;
272 regidx
= *(uint32_t *)key
;
273 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
275 if (!(ri
->type
& (ARM_CP_NO_RAW
|ARM_CP_ALIAS
))) {
276 cpu
->cpreg_indexes
[cpu
->cpreg_array_len
] = cpreg_to_kvm_id(regidx
);
277 /* The value array need not be initialized at this point */
278 cpu
->cpreg_array_len
++;
282 static void count_cpreg(gpointer key
, gpointer opaque
)
284 ARMCPU
*cpu
= opaque
;
286 const ARMCPRegInfo
*ri
;
288 regidx
= *(uint32_t *)key
;
289 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
291 if (!(ri
->type
& (ARM_CP_NO_RAW
|ARM_CP_ALIAS
))) {
292 cpu
->cpreg_array_len
++;
296 static gint
cpreg_key_compare(gconstpointer a
, gconstpointer b
)
298 uint64_t aidx
= cpreg_to_kvm_id(*(uint32_t *)a
);
299 uint64_t bidx
= cpreg_to_kvm_id(*(uint32_t *)b
);
310 void init_cpreg_list(ARMCPU
*cpu
)
312 /* Initialise the cpreg_tuples[] array based on the cp_regs hash.
313 * Note that we require cpreg_tuples[] to be sorted by key ID.
318 keys
= g_hash_table_get_keys(cpu
->cp_regs
);
319 keys
= g_list_sort(keys
, cpreg_key_compare
);
321 cpu
->cpreg_array_len
= 0;
323 g_list_foreach(keys
, count_cpreg
, cpu
);
325 arraylen
= cpu
->cpreg_array_len
;
326 cpu
->cpreg_indexes
= g_new(uint64_t, arraylen
);
327 cpu
->cpreg_values
= g_new(uint64_t, arraylen
);
328 cpu
->cpreg_vmstate_indexes
= g_new(uint64_t, arraylen
);
329 cpu
->cpreg_vmstate_values
= g_new(uint64_t, arraylen
);
330 cpu
->cpreg_vmstate_array_len
= cpu
->cpreg_array_len
;
331 cpu
->cpreg_array_len
= 0;
333 g_list_foreach(keys
, add_cpreg_to_list
, cpu
);
335 assert(cpu
->cpreg_array_len
== arraylen
);
341 * Some registers are not accessible if EL3.NS=0 and EL3 is using AArch32 but
342 * they are accessible when EL3 is using AArch64 regardless of EL3.NS.
344 * access_el3_aa32ns: Used to check AArch32 register views.
345 * access_el3_aa32ns_aa64any: Used to check both AArch32/64 register views.
347 static CPAccessResult
access_el3_aa32ns(CPUARMState
*env
,
348 const ARMCPRegInfo
*ri
,
351 bool secure
= arm_is_secure_below_el3(env
);
353 assert(!arm_el_is_aa64(env
, 3));
355 return CP_ACCESS_TRAP_UNCATEGORIZED
;
360 static CPAccessResult
access_el3_aa32ns_aa64any(CPUARMState
*env
,
361 const ARMCPRegInfo
*ri
,
364 if (!arm_el_is_aa64(env
, 3)) {
365 return access_el3_aa32ns(env
, ri
, isread
);
370 /* Some secure-only AArch32 registers trap to EL3 if used from
371 * Secure EL1 (but are just ordinary UNDEF in other non-EL3 contexts).
372 * Note that an access from Secure EL1 can only happen if EL3 is AArch64.
373 * We assume that the .access field is set to PL1_RW.
375 static CPAccessResult
access_trap_aa32s_el1(CPUARMState
*env
,
376 const ARMCPRegInfo
*ri
,
379 if (arm_current_el(env
) == 3) {
382 if (arm_is_secure_below_el3(env
)) {
383 return CP_ACCESS_TRAP_EL3
;
385 /* This will be EL1 NS and EL2 NS, which just UNDEF */
386 return CP_ACCESS_TRAP_UNCATEGORIZED
;
389 /* Check for traps to "powerdown debug" registers, which are controlled
392 static CPAccessResult
access_tdosa(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
395 int el
= arm_current_el(env
);
397 if (el
< 2 && (env
->cp15
.mdcr_el2
& MDCR_TDOSA
)
398 && !arm_is_secure_below_el3(env
)) {
399 return CP_ACCESS_TRAP_EL2
;
401 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDOSA
)) {
402 return CP_ACCESS_TRAP_EL3
;
407 /* Check for traps to "debug ROM" registers, which are controlled
408 * by MDCR_EL2.TDRA for EL2 but by the more general MDCR_EL3.TDA for EL3.
410 static CPAccessResult
access_tdra(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
413 int el
= arm_current_el(env
);
415 if (el
< 2 && (env
->cp15
.mdcr_el2
& MDCR_TDRA
)
416 && !arm_is_secure_below_el3(env
)) {
417 return CP_ACCESS_TRAP_EL2
;
419 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDA
)) {
420 return CP_ACCESS_TRAP_EL3
;
425 /* Check for traps to general debug registers, which are controlled
426 * by MDCR_EL2.TDA for EL2 and MDCR_EL3.TDA for EL3.
428 static CPAccessResult
access_tda(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
431 int el
= arm_current_el(env
);
433 if (el
< 2 && (env
->cp15
.mdcr_el2
& MDCR_TDA
)
434 && !arm_is_secure_below_el3(env
)) {
435 return CP_ACCESS_TRAP_EL2
;
437 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDA
)) {
438 return CP_ACCESS_TRAP_EL3
;
443 /* Check for traps to performance monitor registers, which are controlled
444 * by MDCR_EL2.TPM for EL2 and MDCR_EL3.TPM for EL3.
446 static CPAccessResult
access_tpm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
449 int el
= arm_current_el(env
);
451 if (el
< 2 && (env
->cp15
.mdcr_el2
& MDCR_TPM
)
452 && !arm_is_secure_below_el3(env
)) {
453 return CP_ACCESS_TRAP_EL2
;
455 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
456 return CP_ACCESS_TRAP_EL3
;
461 static void dacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
463 ARMCPU
*cpu
= arm_env_get_cpu(env
);
465 raw_write(env
, ri
, value
);
466 tlb_flush(CPU(cpu
), 1); /* Flush TLB as domain not tracked in TLB */
469 static void fcse_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
471 ARMCPU
*cpu
= arm_env_get_cpu(env
);
473 if (raw_read(env
, ri
) != value
) {
474 /* Unlike real hardware the qemu TLB uses virtual addresses,
475 * not modified virtual addresses, so this causes a TLB flush.
477 tlb_flush(CPU(cpu
), 1);
478 raw_write(env
, ri
, value
);
482 static void contextidr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
485 ARMCPU
*cpu
= arm_env_get_cpu(env
);
487 if (raw_read(env
, ri
) != value
&& !arm_feature(env
, ARM_FEATURE_MPU
)
488 && !extended_addresses_enabled(env
)) {
489 /* For VMSA (when not using the LPAE long descriptor page table
490 * format) this register includes the ASID, so do a TLB flush.
491 * For PMSA it is purely a process ID and no action is needed.
493 tlb_flush(CPU(cpu
), 1);
495 raw_write(env
, ri
, value
);
498 static void tlbiall_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
501 /* Invalidate all (TLBIALL) */
502 ARMCPU
*cpu
= arm_env_get_cpu(env
);
504 tlb_flush(CPU(cpu
), 1);
507 static void tlbimva_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
510 /* Invalidate single TLB entry by MVA and ASID (TLBIMVA) */
511 ARMCPU
*cpu
= arm_env_get_cpu(env
);
513 tlb_flush_page(CPU(cpu
), value
& TARGET_PAGE_MASK
);
516 static void tlbiasid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
519 /* Invalidate by ASID (TLBIASID) */
520 ARMCPU
*cpu
= arm_env_get_cpu(env
);
522 tlb_flush(CPU(cpu
), value
== 0);
525 static void tlbimvaa_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
528 /* Invalidate single entry by MVA, all ASIDs (TLBIMVAA) */
529 ARMCPU
*cpu
= arm_env_get_cpu(env
);
531 tlb_flush_page(CPU(cpu
), value
& TARGET_PAGE_MASK
);
534 /* IS variants of TLB operations must affect all cores */
535 static void tlbiall_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
540 CPU_FOREACH(other_cs
) {
541 tlb_flush(other_cs
, 1);
545 static void tlbiasid_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
550 CPU_FOREACH(other_cs
) {
551 tlb_flush(other_cs
, value
== 0);
555 static void tlbimva_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
560 CPU_FOREACH(other_cs
) {
561 tlb_flush_page(other_cs
, value
& TARGET_PAGE_MASK
);
565 static void tlbimvaa_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
570 CPU_FOREACH(other_cs
) {
571 tlb_flush_page(other_cs
, value
& TARGET_PAGE_MASK
);
575 static const ARMCPRegInfo cp_reginfo
[] = {
576 /* Define the secure and non-secure FCSE identifier CP registers
577 * separately because there is no secure bank in V8 (no _EL3). This allows
578 * the secure register to be properly reset and migrated. There is also no
579 * v8 EL1 version of the register so the non-secure instance stands alone.
581 { .name
= "FCSEIDR(NS)",
582 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
583 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_NS
,
584 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_ns
),
585 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
586 { .name
= "FCSEIDR(S)",
587 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
588 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_S
,
589 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_s
),
590 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
591 /* Define the secure and non-secure context identifier CP registers
592 * separately because there is no secure bank in V8 (no _EL3). This allows
593 * the secure register to be properly reset and migrated. In the
594 * non-secure case, the 32-bit register will have reset and migration
595 * disabled during registration as it is handled by the 64-bit instance.
597 { .name
= "CONTEXTIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
598 .opc0
= 3, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
599 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_NS
,
600 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[1]),
601 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
602 { .name
= "CONTEXTIDR(S)", .state
= ARM_CP_STATE_AA32
,
603 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
604 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_S
,
605 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_s
),
606 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
610 static const ARMCPRegInfo not_v8_cp_reginfo
[] = {
611 /* NB: Some of these registers exist in v8 but with more precise
612 * definitions that don't use CP_ANY wildcards (mostly in v8_cp_reginfo[]).
614 /* MMU Domain access control / MPU write buffer control */
616 .cp
= 15, .opc1
= CP_ANY
, .crn
= 3, .crm
= CP_ANY
, .opc2
= CP_ANY
,
617 .access
= PL1_RW
, .resetvalue
= 0,
618 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
619 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
620 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
621 /* ARMv7 allocates a range of implementation defined TLB LOCKDOWN regs.
622 * For v6 and v5, these mappings are overly broad.
624 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 0,
625 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
626 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 1,
627 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
628 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 4,
629 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
630 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 8,
631 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
632 /* Cache maintenance ops; some of this space may be overridden later. */
633 { .name
= "CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
634 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
635 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
},
639 static const ARMCPRegInfo not_v6_cp_reginfo
[] = {
640 /* Not all pre-v6 cores implemented this WFI, so this is slightly
643 { .name
= "WFI_v5", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= 2,
644 .access
= PL1_W
, .type
= ARM_CP_WFI
},
648 static const ARMCPRegInfo not_v7_cp_reginfo
[] = {
649 /* Standard v6 WFI (also used in some pre-v6 cores); not in v7 (which
650 * is UNPREDICTABLE; we choose to NOP as most implementations do).
652 { .name
= "WFI_v6", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
653 .access
= PL1_W
, .type
= ARM_CP_WFI
},
654 /* L1 cache lockdown. Not architectural in v6 and earlier but in practice
655 * implemented in 926, 946, 1026, 1136, 1176 and 11MPCore. StrongARM and
656 * OMAPCP will override this space.
658 { .name
= "DLOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 0,
659 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_data
),
661 { .name
= "ILOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 1,
662 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_insn
),
664 /* v6 doesn't have the cache ID registers but Linux reads them anyway */
665 { .name
= "DUMMY", .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= CP_ANY
,
666 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
668 /* We don't implement pre-v7 debug but most CPUs had at least a DBGDIDR;
669 * implementing it as RAZ means the "debug architecture version" bits
670 * will read as a reserved value, which should cause Linux to not try
671 * to use the debug hardware.
673 { .name
= "DBGDIDR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 0,
674 .access
= PL0_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
675 /* MMU TLB control. Note that the wildcarding means we cover not just
676 * the unified TLB ops but also the dside/iside/inner-shareable variants.
678 { .name
= "TLBIALL", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
679 .opc1
= CP_ANY
, .opc2
= 0, .access
= PL1_W
, .writefn
= tlbiall_write
,
680 .type
= ARM_CP_NO_RAW
},
681 { .name
= "TLBIMVA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
682 .opc1
= CP_ANY
, .opc2
= 1, .access
= PL1_W
, .writefn
= tlbimva_write
,
683 .type
= ARM_CP_NO_RAW
},
684 { .name
= "TLBIASID", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
685 .opc1
= CP_ANY
, .opc2
= 2, .access
= PL1_W
, .writefn
= tlbiasid_write
,
686 .type
= ARM_CP_NO_RAW
},
687 { .name
= "TLBIMVAA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
688 .opc1
= CP_ANY
, .opc2
= 3, .access
= PL1_W
, .writefn
= tlbimvaa_write
,
689 .type
= ARM_CP_NO_RAW
},
690 { .name
= "PRRR", .cp
= 15, .crn
= 10, .crm
= 2,
691 .opc1
= 0, .opc2
= 0, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
692 { .name
= "NMRR", .cp
= 15, .crn
= 10, .crm
= 2,
693 .opc1
= 0, .opc2
= 1, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
697 static void cpacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
702 /* In ARMv8 most bits of CPACR_EL1 are RES0. */
703 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
704 /* ARMv7 defines bits for unimplemented coprocessors as RAZ/WI.
705 * ASEDIS [31] and D32DIS [30] are both UNK/SBZP without VFP.
706 * TRCDIS [28] is RAZ/WI since we do not implement a trace macrocell.
708 if (arm_feature(env
, ARM_FEATURE_VFP
)) {
709 /* VFP coprocessor: cp10 & cp11 [23:20] */
710 mask
|= (1 << 31) | (1 << 30) | (0xf << 20);
712 if (!arm_feature(env
, ARM_FEATURE_NEON
)) {
713 /* ASEDIS [31] bit is RAO/WI */
717 /* VFPv3 and upwards with NEON implement 32 double precision
718 * registers (D0-D31).
720 if (!arm_feature(env
, ARM_FEATURE_NEON
) ||
721 !arm_feature(env
, ARM_FEATURE_VFP3
)) {
722 /* D32DIS [30] is RAO/WI if D16-31 are not implemented. */
728 env
->cp15
.cpacr_el1
= value
;
731 static CPAccessResult
cpacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
734 if (arm_feature(env
, ARM_FEATURE_V8
)) {
735 /* Check if CPACR accesses are to be trapped to EL2 */
736 if (arm_current_el(env
) == 1 &&
737 (env
->cp15
.cptr_el
[2] & CPTR_TCPAC
) && !arm_is_secure(env
)) {
738 return CP_ACCESS_TRAP_EL2
;
739 /* Check if CPACR accesses are to be trapped to EL3 */
740 } else if (arm_current_el(env
) < 3 &&
741 (env
->cp15
.cptr_el
[3] & CPTR_TCPAC
)) {
742 return CP_ACCESS_TRAP_EL3
;
749 static CPAccessResult
cptr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
752 /* Check if CPTR accesses are set to trap to EL3 */
753 if (arm_current_el(env
) == 2 && (env
->cp15
.cptr_el
[3] & CPTR_TCPAC
)) {
754 return CP_ACCESS_TRAP_EL3
;
760 static const ARMCPRegInfo v6_cp_reginfo
[] = {
761 /* prefetch by MVA in v6, NOP in v7 */
762 { .name
= "MVA_prefetch",
763 .cp
= 15, .crn
= 7, .crm
= 13, .opc1
= 0, .opc2
= 1,
764 .access
= PL1_W
, .type
= ARM_CP_NOP
},
765 /* We need to break the TB after ISB to execute self-modifying code
766 * correctly and also to take any pending interrupts immediately.
767 * So use arm_cp_write_ignore() function instead of ARM_CP_NOP flag.
769 { .name
= "ISB", .cp
= 15, .crn
= 7, .crm
= 5, .opc1
= 0, .opc2
= 4,
770 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
, .writefn
= arm_cp_write_ignore
},
771 { .name
= "DSB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 4,
772 .access
= PL0_W
, .type
= ARM_CP_NOP
},
773 { .name
= "DMB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 5,
774 .access
= PL0_W
, .type
= ARM_CP_NOP
},
775 { .name
= "IFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 2,
777 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ifar_s
),
778 offsetof(CPUARMState
, cp15
.ifar_ns
) },
780 /* Watchpoint Fault Address Register : should actually only be present
781 * for 1136, 1176, 11MPCore.
783 { .name
= "WFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 1,
784 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0, },
785 { .name
= "CPACR", .state
= ARM_CP_STATE_BOTH
, .opc0
= 3,
786 .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 2, .accessfn
= cpacr_access
,
787 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.cpacr_el1
),
788 .resetvalue
= 0, .writefn
= cpacr_write
},
792 static CPAccessResult
pmreg_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
795 /* Performance monitor registers user accessibility is controlled
796 * by PMUSERENR. MDCR_EL2.TPM and MDCR_EL3.TPM allow configurable
797 * trapping to EL2 or EL3 for other accesses.
799 int el
= arm_current_el(env
);
801 if (el
== 0 && !env
->cp15
.c9_pmuserenr
) {
802 return CP_ACCESS_TRAP
;
804 if (el
< 2 && (env
->cp15
.mdcr_el2
& MDCR_TPM
)
805 && !arm_is_secure_below_el3(env
)) {
806 return CP_ACCESS_TRAP_EL2
;
808 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
809 return CP_ACCESS_TRAP_EL3
;
815 #ifndef CONFIG_USER_ONLY
817 static inline bool arm_ccnt_enabled(CPUARMState
*env
)
819 /* This does not support checking PMCCFILTR_EL0 register */
821 if (!(env
->cp15
.c9_pmcr
& PMCRE
)) {
828 void pmccntr_sync(CPUARMState
*env
)
832 temp_ticks
= muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
833 ARM_CPU_FREQ
, NANOSECONDS_PER_SECOND
);
835 if (env
->cp15
.c9_pmcr
& PMCRD
) {
836 /* Increment once every 64 processor clock cycles */
840 if (arm_ccnt_enabled(env
)) {
841 env
->cp15
.c15_ccnt
= temp_ticks
- env
->cp15
.c15_ccnt
;
845 static void pmcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
851 /* The counter has been reset */
852 env
->cp15
.c15_ccnt
= 0;
855 /* only the DP, X, D and E bits are writable */
856 env
->cp15
.c9_pmcr
&= ~0x39;
857 env
->cp15
.c9_pmcr
|= (value
& 0x39);
862 static uint64_t pmccntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
864 uint64_t total_ticks
;
866 if (!arm_ccnt_enabled(env
)) {
867 /* Counter is disabled, do not change value */
868 return env
->cp15
.c15_ccnt
;
871 total_ticks
= muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
872 ARM_CPU_FREQ
, NANOSECONDS_PER_SECOND
);
874 if (env
->cp15
.c9_pmcr
& PMCRD
) {
875 /* Increment once every 64 processor clock cycles */
878 return total_ticks
- env
->cp15
.c15_ccnt
;
881 static void pmccntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
884 uint64_t total_ticks
;
886 if (!arm_ccnt_enabled(env
)) {
887 /* Counter is disabled, set the absolute value */
888 env
->cp15
.c15_ccnt
= value
;
892 total_ticks
= muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
893 ARM_CPU_FREQ
, NANOSECONDS_PER_SECOND
);
895 if (env
->cp15
.c9_pmcr
& PMCRD
) {
896 /* Increment once every 64 processor clock cycles */
899 env
->cp15
.c15_ccnt
= total_ticks
- value
;
902 static void pmccntr_write32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
905 uint64_t cur_val
= pmccntr_read(env
, NULL
);
907 pmccntr_write(env
, ri
, deposit64(cur_val
, 0, 32, value
));
910 #else /* CONFIG_USER_ONLY */
912 void pmccntr_sync(CPUARMState
*env
)
918 static void pmccfiltr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
922 env
->cp15
.pmccfiltr_el0
= value
& 0x7E000000;
926 static void pmcntenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
930 env
->cp15
.c9_pmcnten
|= value
;
933 static void pmcntenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
937 env
->cp15
.c9_pmcnten
&= ~value
;
940 static void pmovsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
943 env
->cp15
.c9_pmovsr
&= ~value
;
946 static void pmxevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
949 env
->cp15
.c9_pmxevtyper
= value
& 0xff;
952 static void pmuserenr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
955 env
->cp15
.c9_pmuserenr
= value
& 1;
958 static void pmintenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
961 /* We have no event counters so only the C bit can be changed */
963 env
->cp15
.c9_pminten
|= value
;
966 static void pmintenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
970 env
->cp15
.c9_pminten
&= ~value
;
973 static void vbar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
976 /* Note that even though the AArch64 view of this register has bits
977 * [10:0] all RES0 we can only mask the bottom 5, to comply with the
978 * architectural requirements for bits which are RES0 only in some
979 * contexts. (ARMv8 would permit us to do no masking at all, but ARMv7
980 * requires the bottom five bits to be RAZ/WI because they're UNK/SBZP.)
982 raw_write(env
, ri
, value
& ~0x1FULL
);
985 static void scr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
987 /* We only mask off bits that are RES0 both for AArch64 and AArch32.
988 * For bits that vary between AArch32/64, code needs to check the
989 * current execution mode before directly using the feature bit.
991 uint32_t valid_mask
= SCR_AARCH64_MASK
| SCR_AARCH32_MASK
;
993 if (!arm_feature(env
, ARM_FEATURE_EL2
)) {
994 valid_mask
&= ~SCR_HCE
;
996 /* On ARMv7, SMD (or SCD as it is called in v7) is only
997 * supported if EL2 exists. The bit is UNK/SBZP when
998 * EL2 is unavailable. In QEMU ARMv7, we force it to always zero
999 * when EL2 is unavailable.
1000 * On ARMv8, this bit is always available.
1002 if (arm_feature(env
, ARM_FEATURE_V7
) &&
1003 !arm_feature(env
, ARM_FEATURE_V8
)) {
1004 valid_mask
&= ~SCR_SMD
;
1008 /* Clear all-context RES0 bits. */
1009 value
&= valid_mask
;
1010 raw_write(env
, ri
, value
);
1013 static uint64_t ccsidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1015 ARMCPU
*cpu
= arm_env_get_cpu(env
);
1017 /* Acquire the CSSELR index from the bank corresponding to the CCSIDR
1020 uint32_t index
= A32_BANKED_REG_GET(env
, csselr
,
1021 ri
->secure
& ARM_CP_SECSTATE_S
);
1023 return cpu
->ccsidr
[index
];
1026 static void csselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1029 raw_write(env
, ri
, value
& 0xf);
1032 static uint64_t isr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1034 CPUState
*cs
= ENV_GET_CPU(env
);
1037 if (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) {
1040 if (cs
->interrupt_request
& CPU_INTERRUPT_FIQ
) {
1043 /* External aborts are not possible in QEMU so A bit is always clear */
1047 static const ARMCPRegInfo v7_cp_reginfo
[] = {
1048 /* the old v6 WFI, UNPREDICTABLE in v7 but we choose to NOP */
1049 { .name
= "NOP", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
1050 .access
= PL1_W
, .type
= ARM_CP_NOP
},
1051 /* Performance monitors are implementation defined in v7,
1052 * but with an ARM recommended set of registers, which we
1053 * follow (although we don't actually implement any counters)
1055 * Performance registers fall into three categories:
1056 * (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR)
1057 * (b) RO in PL0 (ie UNDEF on write), RW in PL1 (PMUSERENR)
1058 * (c) UNDEF in PL0 if PMUSERENR.EN==0, otherwise accessible (all others)
1059 * For the cases controlled by PMUSERENR we must set .access to PL0_RW
1060 * or PL0_RO as appropriate and then check PMUSERENR in the helper fn.
1062 { .name
= "PMCNTENSET", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 1,
1063 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
,
1064 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
1065 .writefn
= pmcntenset_write
,
1066 .accessfn
= pmreg_access
,
1067 .raw_writefn
= raw_write
},
1068 { .name
= "PMCNTENSET_EL0", .state
= ARM_CP_STATE_AA64
,
1069 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 1,
1070 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1071 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
), .resetvalue
= 0,
1072 .writefn
= pmcntenset_write
, .raw_writefn
= raw_write
},
1073 { .name
= "PMCNTENCLR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 2,
1075 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
1076 .accessfn
= pmreg_access
,
1077 .writefn
= pmcntenclr_write
,
1078 .type
= ARM_CP_ALIAS
},
1079 { .name
= "PMCNTENCLR_EL0", .state
= ARM_CP_STATE_AA64
,
1080 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 2,
1081 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1082 .type
= ARM_CP_ALIAS
,
1083 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
),
1084 .writefn
= pmcntenclr_write
},
1085 { .name
= "PMOVSR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 3,
1086 .access
= PL0_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
1087 .accessfn
= pmreg_access
,
1088 .writefn
= pmovsr_write
,
1089 .raw_writefn
= raw_write
},
1090 { .name
= "PMOVSCLR_EL0", .state
= ARM_CP_STATE_AA64
,
1091 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 3,
1092 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1093 .type
= ARM_CP_ALIAS
,
1094 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
1095 .writefn
= pmovsr_write
,
1096 .raw_writefn
= raw_write
},
1097 /* Unimplemented so WI. */
1098 { .name
= "PMSWINC", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 4,
1099 .access
= PL0_W
, .accessfn
= pmreg_access
, .type
= ARM_CP_NOP
},
1100 /* Since we don't implement any events, writing to PMSELR is UNPREDICTABLE.
1101 * We choose to RAZ/WI.
1103 { .name
= "PMSELR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 5,
1104 .access
= PL0_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0,
1105 .accessfn
= pmreg_access
},
1106 #ifndef CONFIG_USER_ONLY
1107 { .name
= "PMCCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 0,
1108 .access
= PL0_RW
, .resetvalue
= 0, .type
= ARM_CP_IO
,
1109 .readfn
= pmccntr_read
, .writefn
= pmccntr_write32
,
1110 .accessfn
= pmreg_access
},
1111 { .name
= "PMCCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
1112 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 0,
1113 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1115 .readfn
= pmccntr_read
, .writefn
= pmccntr_write
, },
1117 { .name
= "PMCCFILTR_EL0", .state
= ARM_CP_STATE_AA64
,
1118 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 15, .opc2
= 7,
1119 .writefn
= pmccfiltr_write
,
1120 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1122 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmccfiltr_el0
),
1124 { .name
= "PMXEVTYPER", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 1,
1126 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmxevtyper
),
1127 .accessfn
= pmreg_access
, .writefn
= pmxevtyper_write
,
1128 .raw_writefn
= raw_write
},
1129 /* Unimplemented, RAZ/WI. */
1130 { .name
= "PMXEVCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 2,
1131 .access
= PL0_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0,
1132 .accessfn
= pmreg_access
},
1133 { .name
= "PMUSERENR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 0,
1134 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
,
1135 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmuserenr
),
1137 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
1138 { .name
= "PMUSERENR_EL0", .state
= ARM_CP_STATE_AA64
,
1139 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 0,
1140 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
, .type
= ARM_CP_ALIAS
,
1141 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmuserenr
),
1143 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
1144 { .name
= "PMINTENSET", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 1,
1145 .access
= PL1_RW
, .accessfn
= access_tpm
,
1146 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
1148 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
},
1149 { .name
= "PMINTENCLR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 2,
1150 .access
= PL1_RW
, .accessfn
= access_tpm
, .type
= ARM_CP_ALIAS
,
1151 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
1152 .writefn
= pmintenclr_write
, },
1153 { .name
= "PMINTENCLR_EL1", .state
= ARM_CP_STATE_AA64
,
1154 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 2,
1155 .access
= PL1_RW
, .accessfn
= access_tpm
, .type
= ARM_CP_ALIAS
,
1156 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
1157 .writefn
= pmintenclr_write
},
1158 { .name
= "VBAR", .state
= ARM_CP_STATE_BOTH
,
1159 .opc0
= 3, .crn
= 12, .crm
= 0, .opc1
= 0, .opc2
= 0,
1160 .access
= PL1_RW
, .writefn
= vbar_write
,
1161 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.vbar_s
),
1162 offsetof(CPUARMState
, cp15
.vbar_ns
) },
1164 { .name
= "CCSIDR", .state
= ARM_CP_STATE_BOTH
,
1165 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 0,
1166 .access
= PL1_R
, .readfn
= ccsidr_read
, .type
= ARM_CP_NO_RAW
},
1167 { .name
= "CSSELR", .state
= ARM_CP_STATE_BOTH
,
1168 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 2, .opc2
= 0,
1169 .access
= PL1_RW
, .writefn
= csselr_write
, .resetvalue
= 0,
1170 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.csselr_s
),
1171 offsetof(CPUARMState
, cp15
.csselr_ns
) } },
1172 /* Auxiliary ID register: this actually has an IMPDEF value but for now
1173 * just RAZ for all cores:
1175 { .name
= "AIDR", .state
= ARM_CP_STATE_BOTH
,
1176 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 7,
1177 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
1178 /* Auxiliary fault status registers: these also are IMPDEF, and we
1179 * choose to RAZ/WI for all cores.
1181 { .name
= "AFSR0_EL1", .state
= ARM_CP_STATE_BOTH
,
1182 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 0,
1183 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
1184 { .name
= "AFSR1_EL1", .state
= ARM_CP_STATE_BOTH
,
1185 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 1,
1186 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
1187 /* MAIR can just read-as-written because we don't implement caches
1188 * and so don't need to care about memory attributes.
1190 { .name
= "MAIR_EL1", .state
= ARM_CP_STATE_AA64
,
1191 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
1192 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[1]),
1194 { .name
= "MAIR_EL3", .state
= ARM_CP_STATE_AA64
,
1195 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 2, .opc2
= 0,
1196 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[3]),
1198 /* For non-long-descriptor page tables these are PRRR and NMRR;
1199 * regardless they still act as reads-as-written for QEMU.
1201 /* MAIR0/1 are defined separately from their 64-bit counterpart which
1202 * allows them to assign the correct fieldoffset based on the endianness
1203 * handled in the field definitions.
1205 { .name
= "MAIR0", .state
= ARM_CP_STATE_AA32
,
1206 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0, .access
= PL1_RW
,
1207 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair0_s
),
1208 offsetof(CPUARMState
, cp15
.mair0_ns
) },
1209 .resetfn
= arm_cp_reset_ignore
},
1210 { .name
= "MAIR1", .state
= ARM_CP_STATE_AA32
,
1211 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 1, .access
= PL1_RW
,
1212 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair1_s
),
1213 offsetof(CPUARMState
, cp15
.mair1_ns
) },
1214 .resetfn
= arm_cp_reset_ignore
},
1215 { .name
= "ISR_EL1", .state
= ARM_CP_STATE_BOTH
,
1216 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 1, .opc2
= 0,
1217 .type
= ARM_CP_NO_RAW
, .access
= PL1_R
, .readfn
= isr_read
},
1218 /* 32 bit ITLB invalidates */
1219 { .name
= "ITLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 0,
1220 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiall_write
},
1221 { .name
= "ITLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
1222 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimva_write
},
1223 { .name
= "ITLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 2,
1224 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiasid_write
},
1225 /* 32 bit DTLB invalidates */
1226 { .name
= "DTLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 0,
1227 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiall_write
},
1228 { .name
= "DTLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
1229 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimva_write
},
1230 { .name
= "DTLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 2,
1231 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiasid_write
},
1232 /* 32 bit TLB invalidates */
1233 { .name
= "TLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
1234 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiall_write
},
1235 { .name
= "TLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
1236 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimva_write
},
1237 { .name
= "TLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
1238 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiasid_write
},
1239 { .name
= "TLBIMVAA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
1240 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimvaa_write
},
1244 static const ARMCPRegInfo v7mp_cp_reginfo
[] = {
1245 /* 32 bit TLB invalidates, Inner Shareable */
1246 { .name
= "TLBIALLIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
1247 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiall_is_write
},
1248 { .name
= "TLBIMVAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
1249 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimva_is_write
},
1250 { .name
= "TLBIASIDIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
1251 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
,
1252 .writefn
= tlbiasid_is_write
},
1253 { .name
= "TLBIMVAAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
1254 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
,
1255 .writefn
= tlbimvaa_is_write
},
1259 static void teecr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1266 static CPAccessResult
teehbr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1269 if (arm_current_el(env
) == 0 && (env
->teecr
& 1)) {
1270 return CP_ACCESS_TRAP
;
1272 return CP_ACCESS_OK
;
1275 static const ARMCPRegInfo t2ee_cp_reginfo
[] = {
1276 { .name
= "TEECR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 6, .opc2
= 0,
1277 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, teecr
),
1279 .writefn
= teecr_write
},
1280 { .name
= "TEEHBR", .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 6, .opc2
= 0,
1281 .access
= PL0_RW
, .fieldoffset
= offsetof(CPUARMState
, teehbr
),
1282 .accessfn
= teehbr_access
, .resetvalue
= 0 },
1286 static const ARMCPRegInfo v6k_cp_reginfo
[] = {
1287 { .name
= "TPIDR_EL0", .state
= ARM_CP_STATE_AA64
,
1288 .opc0
= 3, .opc1
= 3, .opc2
= 2, .crn
= 13, .crm
= 0,
1290 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[0]), .resetvalue
= 0 },
1291 { .name
= "TPIDRURW", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 2,
1293 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrurw_s
),
1294 offsetoflow32(CPUARMState
, cp15
.tpidrurw_ns
) },
1295 .resetfn
= arm_cp_reset_ignore
},
1296 { .name
= "TPIDRRO_EL0", .state
= ARM_CP_STATE_AA64
,
1297 .opc0
= 3, .opc1
= 3, .opc2
= 3, .crn
= 13, .crm
= 0,
1298 .access
= PL0_R
|PL1_W
,
1299 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidrro_el
[0]),
1301 { .name
= "TPIDRURO", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 3,
1302 .access
= PL0_R
|PL1_W
,
1303 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidruro_s
),
1304 offsetoflow32(CPUARMState
, cp15
.tpidruro_ns
) },
1305 .resetfn
= arm_cp_reset_ignore
},
1306 { .name
= "TPIDR_EL1", .state
= ARM_CP_STATE_AA64
,
1307 .opc0
= 3, .opc1
= 0, .opc2
= 4, .crn
= 13, .crm
= 0,
1309 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[1]), .resetvalue
= 0 },
1310 { .name
= "TPIDRPRW", .opc1
= 0, .cp
= 15, .crn
= 13, .crm
= 0, .opc2
= 4,
1312 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrprw_s
),
1313 offsetoflow32(CPUARMState
, cp15
.tpidrprw_ns
) },
1318 #ifndef CONFIG_USER_ONLY
1320 static CPAccessResult
gt_cntfrq_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1323 /* CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero.
1324 * Writable only at the highest implemented exception level.
1326 int el
= arm_current_el(env
);
1330 if (!extract32(env
->cp15
.c14_cntkctl
, 0, 2)) {
1331 return CP_ACCESS_TRAP
;
1335 if (!isread
&& ri
->state
== ARM_CP_STATE_AA32
&&
1336 arm_is_secure_below_el3(env
)) {
1337 /* Accesses from 32-bit Secure EL1 UNDEF (*not* trap to EL3!) */
1338 return CP_ACCESS_TRAP_UNCATEGORIZED
;
1346 if (!isread
&& el
< arm_highest_el(env
)) {
1347 return CP_ACCESS_TRAP_UNCATEGORIZED
;
1350 return CP_ACCESS_OK
;
1353 static CPAccessResult
gt_counter_access(CPUARMState
*env
, int timeridx
,
1356 unsigned int cur_el
= arm_current_el(env
);
1357 bool secure
= arm_is_secure(env
);
1359 /* CNT[PV]CT: not visible from PL0 if ELO[PV]CTEN is zero */
1361 !extract32(env
->cp15
.c14_cntkctl
, timeridx
, 1)) {
1362 return CP_ACCESS_TRAP
;
1365 if (arm_feature(env
, ARM_FEATURE_EL2
) &&
1366 timeridx
== GTIMER_PHYS
&& !secure
&& cur_el
< 2 &&
1367 !extract32(env
->cp15
.cnthctl_el2
, 0, 1)) {
1368 return CP_ACCESS_TRAP_EL2
;
1370 return CP_ACCESS_OK
;
1373 static CPAccessResult
gt_timer_access(CPUARMState
*env
, int timeridx
,
1376 unsigned int cur_el
= arm_current_el(env
);
1377 bool secure
= arm_is_secure(env
);
1379 /* CNT[PV]_CVAL, CNT[PV]_CTL, CNT[PV]_TVAL: not visible from PL0 if
1380 * EL0[PV]TEN is zero.
1383 !extract32(env
->cp15
.c14_cntkctl
, 9 - timeridx
, 1)) {
1384 return CP_ACCESS_TRAP
;
1387 if (arm_feature(env
, ARM_FEATURE_EL2
) &&
1388 timeridx
== GTIMER_PHYS
&& !secure
&& cur_el
< 2 &&
1389 !extract32(env
->cp15
.cnthctl_el2
, 1, 1)) {
1390 return CP_ACCESS_TRAP_EL2
;
1392 return CP_ACCESS_OK
;
1395 static CPAccessResult
gt_pct_access(CPUARMState
*env
,
1396 const ARMCPRegInfo
*ri
,
1399 return gt_counter_access(env
, GTIMER_PHYS
, isread
);
1402 static CPAccessResult
gt_vct_access(CPUARMState
*env
,
1403 const ARMCPRegInfo
*ri
,
1406 return gt_counter_access(env
, GTIMER_VIRT
, isread
);
1409 static CPAccessResult
gt_ptimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1412 return gt_timer_access(env
, GTIMER_PHYS
, isread
);
1415 static CPAccessResult
gt_vtimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1418 return gt_timer_access(env
, GTIMER_VIRT
, isread
);
1421 static CPAccessResult
gt_stimer_access(CPUARMState
*env
,
1422 const ARMCPRegInfo
*ri
,
1425 /* The AArch64 register view of the secure physical timer is
1426 * always accessible from EL3, and configurably accessible from
1429 switch (arm_current_el(env
)) {
1431 if (!arm_is_secure(env
)) {
1432 return CP_ACCESS_TRAP
;
1434 if (!(env
->cp15
.scr_el3
& SCR_ST
)) {
1435 return CP_ACCESS_TRAP_EL3
;
1437 return CP_ACCESS_OK
;
1440 return CP_ACCESS_TRAP
;
1442 return CP_ACCESS_OK
;
1444 g_assert_not_reached();
1448 static uint64_t gt_get_countervalue(CPUARMState
*env
)
1450 return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) / GTIMER_SCALE
;
1453 static void gt_recalc_timer(ARMCPU
*cpu
, int timeridx
)
1455 ARMGenericTimer
*gt
= &cpu
->env
.cp15
.c14_timer
[timeridx
];
1458 /* Timer enabled: calculate and set current ISTATUS, irq, and
1459 * reset timer to when ISTATUS next has to change
1461 uint64_t offset
= timeridx
== GTIMER_VIRT ?
1462 cpu
->env
.cp15
.cntvoff_el2
: 0;
1463 uint64_t count
= gt_get_countervalue(&cpu
->env
);
1464 /* Note that this must be unsigned 64 bit arithmetic: */
1465 int istatus
= count
- offset
>= gt
->cval
;
1468 gt
->ctl
= deposit32(gt
->ctl
, 2, 1, istatus
);
1469 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
],
1470 (istatus
&& !(gt
->ctl
& 2)));
1472 /* Next transition is when count rolls back over to zero */
1473 nexttick
= UINT64_MAX
;
1475 /* Next transition is when we hit cval */
1476 nexttick
= gt
->cval
+ offset
;
1478 /* Note that the desired next expiry time might be beyond the
1479 * signed-64-bit range of a QEMUTimer -- in this case we just
1480 * set the timer for as far in the future as possible. When the
1481 * timer expires we will reset the timer for any remaining period.
1483 if (nexttick
> INT64_MAX
/ GTIMER_SCALE
) {
1484 nexttick
= INT64_MAX
/ GTIMER_SCALE
;
1486 timer_mod(cpu
->gt_timer
[timeridx
], nexttick
);
1488 /* Timer disabled: ISTATUS and timer output always clear */
1490 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], 0);
1491 timer_del(cpu
->gt_timer
[timeridx
]);
1495 static void gt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1498 ARMCPU
*cpu
= arm_env_get_cpu(env
);
1500 timer_del(cpu
->gt_timer
[timeridx
]);
1503 static uint64_t gt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1505 return gt_get_countervalue(env
);
1508 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1510 return gt_get_countervalue(env
) - env
->cp15
.cntvoff_el2
;
1513 static void gt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1517 env
->cp15
.c14_timer
[timeridx
].cval
= value
;
1518 gt_recalc_timer(arm_env_get_cpu(env
), timeridx
);
1521 static uint64_t gt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1524 uint64_t offset
= timeridx
== GTIMER_VIRT ? env
->cp15
.cntvoff_el2
: 0;
1526 return (uint32_t)(env
->cp15
.c14_timer
[timeridx
].cval
-
1527 (gt_get_countervalue(env
) - offset
));
1530 static void gt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1534 uint64_t offset
= timeridx
== GTIMER_VIRT ? env
->cp15
.cntvoff_el2
: 0;
1536 env
->cp15
.c14_timer
[timeridx
].cval
= gt_get_countervalue(env
) - offset
+
1537 sextract64(value
, 0, 32);
1538 gt_recalc_timer(arm_env_get_cpu(env
), timeridx
);
1541 static void gt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1545 ARMCPU
*cpu
= arm_env_get_cpu(env
);
1546 uint32_t oldval
= env
->cp15
.c14_timer
[timeridx
].ctl
;
1548 env
->cp15
.c14_timer
[timeridx
].ctl
= deposit64(oldval
, 0, 2, value
);
1549 if ((oldval
^ value
) & 1) {
1550 /* Enable toggled */
1551 gt_recalc_timer(cpu
, timeridx
);
1552 } else if ((oldval
^ value
) & 2) {
1553 /* IMASK toggled: don't need to recalculate,
1554 * just set the interrupt line based on ISTATUS
1556 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
],
1557 (oldval
& 4) && !(value
& 2));
1561 static void gt_phys_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1563 gt_timer_reset(env
, ri
, GTIMER_PHYS
);
1566 static void gt_phys_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1569 gt_cval_write(env
, ri
, GTIMER_PHYS
, value
);
1572 static uint64_t gt_phys_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1574 return gt_tval_read(env
, ri
, GTIMER_PHYS
);
1577 static void gt_phys_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1580 gt_tval_write(env
, ri
, GTIMER_PHYS
, value
);
1583 static void gt_phys_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1586 gt_ctl_write(env
, ri
, GTIMER_PHYS
, value
);
1589 static void gt_virt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1591 gt_timer_reset(env
, ri
, GTIMER_VIRT
);
1594 static void gt_virt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1597 gt_cval_write(env
, ri
, GTIMER_VIRT
, value
);
1600 static uint64_t gt_virt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1602 return gt_tval_read(env
, ri
, GTIMER_VIRT
);
1605 static void gt_virt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1608 gt_tval_write(env
, ri
, GTIMER_VIRT
, value
);
1611 static void gt_virt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1614 gt_ctl_write(env
, ri
, GTIMER_VIRT
, value
);
1617 static void gt_cntvoff_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1620 ARMCPU
*cpu
= arm_env_get_cpu(env
);
1622 raw_write(env
, ri
, value
);
1623 gt_recalc_timer(cpu
, GTIMER_VIRT
);
1626 static void gt_hyp_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1628 gt_timer_reset(env
, ri
, GTIMER_HYP
);
1631 static void gt_hyp_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1634 gt_cval_write(env
, ri
, GTIMER_HYP
, value
);
1637 static uint64_t gt_hyp_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1639 return gt_tval_read(env
, ri
, GTIMER_HYP
);
1642 static void gt_hyp_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1645 gt_tval_write(env
, ri
, GTIMER_HYP
, value
);
1648 static void gt_hyp_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1651 gt_ctl_write(env
, ri
, GTIMER_HYP
, value
);
1654 static void gt_sec_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1656 gt_timer_reset(env
, ri
, GTIMER_SEC
);
1659 static void gt_sec_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1662 gt_cval_write(env
, ri
, GTIMER_SEC
, value
);
1665 static uint64_t gt_sec_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1667 return gt_tval_read(env
, ri
, GTIMER_SEC
);
1670 static void gt_sec_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1673 gt_tval_write(env
, ri
, GTIMER_SEC
, value
);
1676 static void gt_sec_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1679 gt_ctl_write(env
, ri
, GTIMER_SEC
, value
);
1682 void arm_gt_ptimer_cb(void *opaque
)
1684 ARMCPU
*cpu
= opaque
;
1686 gt_recalc_timer(cpu
, GTIMER_PHYS
);
1689 void arm_gt_vtimer_cb(void *opaque
)
1691 ARMCPU
*cpu
= opaque
;
1693 gt_recalc_timer(cpu
, GTIMER_VIRT
);
1696 void arm_gt_htimer_cb(void *opaque
)
1698 ARMCPU
*cpu
= opaque
;
1700 gt_recalc_timer(cpu
, GTIMER_HYP
);
1703 void arm_gt_stimer_cb(void *opaque
)
1705 ARMCPU
*cpu
= opaque
;
1707 gt_recalc_timer(cpu
, GTIMER_SEC
);
1710 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
1711 /* Note that CNTFRQ is purely reads-as-written for the benefit
1712 * of software; writing it doesn't actually change the timer frequency.
1713 * Our reset value matches the fixed frequency we implement the timer at.
1715 { .name
= "CNTFRQ", .cp
= 15, .crn
= 14, .crm
= 0, .opc1
= 0, .opc2
= 0,
1716 .type
= ARM_CP_ALIAS
,
1717 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
1718 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c14_cntfrq
),
1720 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
1721 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
1722 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
1723 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
1724 .resetvalue
= (1000 * 1000 * 1000) / GTIMER_SCALE
,
1726 /* overall control: mostly access permissions */
1727 { .name
= "CNTKCTL", .state
= ARM_CP_STATE_BOTH
,
1728 .opc0
= 3, .opc1
= 0, .crn
= 14, .crm
= 1, .opc2
= 0,
1730 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntkctl
),
1733 /* per-timer control */
1734 { .name
= "CNTP_CTL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
1735 .secure
= ARM_CP_SECSTATE_NS
,
1736 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL1_RW
| PL0_R
,
1737 .accessfn
= gt_ptimer_access
,
1738 .fieldoffset
= offsetoflow32(CPUARMState
,
1739 cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
1740 .writefn
= gt_phys_ctl_write
, .raw_writefn
= raw_write
,
1742 { .name
= "CNTP_CTL(S)",
1743 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
1744 .secure
= ARM_CP_SECSTATE_S
,
1745 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL1_RW
| PL0_R
,
1746 .accessfn
= gt_ptimer_access
,
1747 .fieldoffset
= offsetoflow32(CPUARMState
,
1748 cp15
.c14_timer
[GTIMER_SEC
].ctl
),
1749 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
1751 { .name
= "CNTP_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
1752 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 1,
1753 .type
= ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1754 .accessfn
= gt_ptimer_access
,
1755 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
1757 .writefn
= gt_phys_ctl_write
, .raw_writefn
= raw_write
,
1759 { .name
= "CNTV_CTL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 1,
1760 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL1_RW
| PL0_R
,
1761 .accessfn
= gt_vtimer_access
,
1762 .fieldoffset
= offsetoflow32(CPUARMState
,
1763 cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
1764 .writefn
= gt_virt_ctl_write
, .raw_writefn
= raw_write
,
1766 { .name
= "CNTV_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
1767 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 1,
1768 .type
= ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1769 .accessfn
= gt_vtimer_access
,
1770 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
1772 .writefn
= gt_virt_ctl_write
, .raw_writefn
= raw_write
,
1774 /* TimerValue views: a 32 bit downcounting view of the underlying state */
1775 { .name
= "CNTP_TVAL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
1776 .secure
= ARM_CP_SECSTATE_NS
,
1777 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1778 .accessfn
= gt_ptimer_access
,
1779 .readfn
= gt_phys_tval_read
, .writefn
= gt_phys_tval_write
,
1781 { .name
= "CNTP_TVAL(S)",
1782 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
1783 .secure
= ARM_CP_SECSTATE_S
,
1784 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1785 .accessfn
= gt_ptimer_access
,
1786 .readfn
= gt_sec_tval_read
, .writefn
= gt_sec_tval_write
,
1788 { .name
= "CNTP_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
1789 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 0,
1790 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1791 .accessfn
= gt_ptimer_access
, .resetfn
= gt_phys_timer_reset
,
1792 .readfn
= gt_phys_tval_read
, .writefn
= gt_phys_tval_write
,
1794 { .name
= "CNTV_TVAL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 0,
1795 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1796 .accessfn
= gt_vtimer_access
,
1797 .readfn
= gt_virt_tval_read
, .writefn
= gt_virt_tval_write
,
1799 { .name
= "CNTV_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
1800 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 0,
1801 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1802 .accessfn
= gt_vtimer_access
, .resetfn
= gt_virt_timer_reset
,
1803 .readfn
= gt_virt_tval_read
, .writefn
= gt_virt_tval_write
,
1805 /* The counter itself */
1806 { .name
= "CNTPCT", .cp
= 15, .crm
= 14, .opc1
= 0,
1807 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
1808 .accessfn
= gt_pct_access
,
1809 .readfn
= gt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
1811 { .name
= "CNTPCT_EL0", .state
= ARM_CP_STATE_AA64
,
1812 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 1,
1813 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
1814 .accessfn
= gt_pct_access
, .readfn
= gt_cnt_read
,
1816 { .name
= "CNTVCT", .cp
= 15, .crm
= 14, .opc1
= 1,
1817 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
1818 .accessfn
= gt_vct_access
,
1819 .readfn
= gt_virt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
1821 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
1822 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
1823 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
1824 .accessfn
= gt_vct_access
, .readfn
= gt_virt_cnt_read
,
1826 /* Comparison value, indicating when the timer goes off */
1827 { .name
= "CNTP_CVAL", .cp
= 15, .crm
= 14, .opc1
= 2,
1828 .secure
= ARM_CP_SECSTATE_NS
,
1829 .access
= PL1_RW
| PL0_R
,
1830 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
1831 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
1832 .accessfn
= gt_ptimer_access
,
1833 .writefn
= gt_phys_cval_write
, .raw_writefn
= raw_write
,
1835 { .name
= "CNTP_CVAL(S)", .cp
= 15, .crm
= 14, .opc1
= 2,
1836 .secure
= ARM_CP_SECSTATE_S
,
1837 .access
= PL1_RW
| PL0_R
,
1838 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
1839 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
1840 .accessfn
= gt_ptimer_access
,
1841 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
1843 { .name
= "CNTP_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
1844 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 2,
1845 .access
= PL1_RW
| PL0_R
,
1847 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
1848 .resetvalue
= 0, .accessfn
= gt_ptimer_access
,
1849 .writefn
= gt_phys_cval_write
, .raw_writefn
= raw_write
,
1851 { .name
= "CNTV_CVAL", .cp
= 15, .crm
= 14, .opc1
= 3,
1852 .access
= PL1_RW
| PL0_R
,
1853 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
1854 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
1855 .accessfn
= gt_vtimer_access
,
1856 .writefn
= gt_virt_cval_write
, .raw_writefn
= raw_write
,
1858 { .name
= "CNTV_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
1859 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 2,
1860 .access
= PL1_RW
| PL0_R
,
1862 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
1863 .resetvalue
= 0, .accessfn
= gt_vtimer_access
,
1864 .writefn
= gt_virt_cval_write
, .raw_writefn
= raw_write
,
1866 /* Secure timer -- this is actually restricted to only EL3
1867 * and configurably Secure-EL1 via the accessfn.
1869 { .name
= "CNTPS_TVAL_EL1", .state
= ARM_CP_STATE_AA64
,
1870 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 0,
1871 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
,
1872 .accessfn
= gt_stimer_access
,
1873 .readfn
= gt_sec_tval_read
,
1874 .writefn
= gt_sec_tval_write
,
1875 .resetfn
= gt_sec_timer_reset
,
1877 { .name
= "CNTPS_CTL_EL1", .state
= ARM_CP_STATE_AA64
,
1878 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 1,
1879 .type
= ARM_CP_IO
, .access
= PL1_RW
,
1880 .accessfn
= gt_stimer_access
,
1881 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].ctl
),
1883 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
1885 { .name
= "CNTPS_CVAL_EL1", .state
= ARM_CP_STATE_AA64
,
1886 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 2,
1887 .type
= ARM_CP_IO
, .access
= PL1_RW
,
1888 .accessfn
= gt_stimer_access
,
1889 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
1890 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
1896 /* In user-mode none of the generic timer registers are accessible,
1897 * and their implementation depends on QEMU_CLOCK_VIRTUAL and qdev gpio outputs,
1898 * so instead just don't register any of them.
1900 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
1906 static void par_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
1908 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
1909 raw_write(env
, ri
, value
);
1910 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
1911 raw_write(env
, ri
, value
& 0xfffff6ff);
1913 raw_write(env
, ri
, value
& 0xfffff1ff);
1917 #ifndef CONFIG_USER_ONLY
1918 /* get_phys_addr() isn't present for user-mode-only targets */
1920 static CPAccessResult
ats_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1924 /* The ATS12NSO* operations must trap to EL3 if executed in
1925 * Secure EL1 (which can only happen if EL3 is AArch64).
1926 * They are simply UNDEF if executed from NS EL1.
1927 * They function normally from EL2 or EL3.
1929 if (arm_current_el(env
) == 1) {
1930 if (arm_is_secure_below_el3(env
)) {
1931 return CP_ACCESS_TRAP_UNCATEGORIZED_EL3
;
1933 return CP_ACCESS_TRAP_UNCATEGORIZED
;
1936 return CP_ACCESS_OK
;
1939 static uint64_t do_ats_write(CPUARMState
*env
, uint64_t value
,
1940 int access_type
, ARMMMUIdx mmu_idx
)
1943 target_ulong page_size
;
1948 MemTxAttrs attrs
= {};
1949 ARMMMUFaultInfo fi
= {};
1951 ret
= get_phys_addr(env
, value
, access_type
, mmu_idx
,
1952 &phys_addr
, &attrs
, &prot
, &page_size
, &fsr
, &fi
);
1953 if (extended_addresses_enabled(env
)) {
1954 /* fsr is a DFSR/IFSR value for the long descriptor
1955 * translation table format, but with WnR always clear.
1956 * Convert it to a 64-bit PAR.
1958 par64
= (1 << 11); /* LPAE bit always set */
1960 par64
|= phys_addr
& ~0xfffULL
;
1961 if (!attrs
.secure
) {
1962 par64
|= (1 << 9); /* NS */
1964 /* We don't set the ATTR or SH fields in the PAR. */
1967 par64
|= (fsr
& 0x3f) << 1; /* FS */
1968 /* Note that S2WLK and FSTAGE are always zero, because we don't
1969 * implement virtualization and therefore there can't be a stage 2
1974 /* fsr is a DFSR/IFSR value for the short descriptor
1975 * translation table format (with WnR always clear).
1976 * Convert it to a 32-bit PAR.
1979 /* We do not set any attribute bits in the PAR */
1980 if (page_size
== (1 << 24)
1981 && arm_feature(env
, ARM_FEATURE_V7
)) {
1982 par64
= (phys_addr
& 0xff000000) | (1 << 1);
1984 par64
= phys_addr
& 0xfffff000;
1986 if (!attrs
.secure
) {
1987 par64
|= (1 << 9); /* NS */
1990 par64
= ((fsr
& (1 << 10)) >> 5) | ((fsr
& (1 << 12)) >> 6) |
1991 ((fsr
& 0xf) << 1) | 1;
1997 static void ats_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
1999 int access_type
= ri
->opc2
& 1;
2002 int el
= arm_current_el(env
);
2003 bool secure
= arm_is_secure_below_el3(env
);
2005 switch (ri
->opc2
& 6) {
2007 /* stage 1 current state PL1: ATS1CPR, ATS1CPW */
2010 mmu_idx
= ARMMMUIdx_S1E3
;
2013 mmu_idx
= ARMMMUIdx_S1NSE1
;
2016 mmu_idx
= secure ? ARMMMUIdx_S1SE1
: ARMMMUIdx_S1NSE1
;
2019 g_assert_not_reached();
2023 /* stage 1 current state PL0: ATS1CUR, ATS1CUW */
2026 mmu_idx
= ARMMMUIdx_S1SE0
;
2029 mmu_idx
= ARMMMUIdx_S1NSE0
;
2032 mmu_idx
= secure ? ARMMMUIdx_S1SE0
: ARMMMUIdx_S1NSE0
;
2035 g_assert_not_reached();
2039 /* stage 1+2 NonSecure PL1: ATS12NSOPR, ATS12NSOPW */
2040 mmu_idx
= ARMMMUIdx_S12NSE1
;
2043 /* stage 1+2 NonSecure PL0: ATS12NSOUR, ATS12NSOUW */
2044 mmu_idx
= ARMMMUIdx_S12NSE0
;
2047 g_assert_not_reached();
2050 par64
= do_ats_write(env
, value
, access_type
, mmu_idx
);
2052 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
2055 static void ats1h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2058 int access_type
= ri
->opc2
& 1;
2061 par64
= do_ats_write(env
, value
, access_type
, ARMMMUIdx_S2NS
);
2063 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
2066 static CPAccessResult
at_s1e2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2069 if (arm_current_el(env
) == 3 && !(env
->cp15
.scr_el3
& SCR_NS
)) {
2070 return CP_ACCESS_TRAP
;
2072 return CP_ACCESS_OK
;
2075 static void ats_write64(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2078 int access_type
= ri
->opc2
& 1;
2080 int secure
= arm_is_secure_below_el3(env
);
2082 switch (ri
->opc2
& 6) {
2085 case 0: /* AT S1E1R, AT S1E1W */
2086 mmu_idx
= secure ? ARMMMUIdx_S1SE1
: ARMMMUIdx_S1NSE1
;
2088 case 4: /* AT S1E2R, AT S1E2W */
2089 mmu_idx
= ARMMMUIdx_S1E2
;
2091 case 6: /* AT S1E3R, AT S1E3W */
2092 mmu_idx
= ARMMMUIdx_S1E3
;
2095 g_assert_not_reached();
2098 case 2: /* AT S1E0R, AT S1E0W */
2099 mmu_idx
= secure ? ARMMMUIdx_S1SE0
: ARMMMUIdx_S1NSE0
;
2101 case 4: /* AT S12E1R, AT S12E1W */
2102 mmu_idx
= secure ? ARMMMUIdx_S1SE1
: ARMMMUIdx_S12NSE1
;
2104 case 6: /* AT S12E0R, AT S12E0W */
2105 mmu_idx
= secure ? ARMMMUIdx_S1SE0
: ARMMMUIdx_S12NSE0
;
2108 g_assert_not_reached();
2111 env
->cp15
.par_el
[1] = do_ats_write(env
, value
, access_type
, mmu_idx
);
2115 static const ARMCPRegInfo vapa_cp_reginfo
[] = {
2116 { .name
= "PAR", .cp
= 15, .crn
= 7, .crm
= 4, .opc1
= 0, .opc2
= 0,
2117 .access
= PL1_RW
, .resetvalue
= 0,
2118 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.par_s
),
2119 offsetoflow32(CPUARMState
, cp15
.par_ns
) },
2120 .writefn
= par_write
},
2121 #ifndef CONFIG_USER_ONLY
2122 /* This underdecoding is safe because the reginfo is NO_RAW. */
2123 { .name
= "ATS", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= CP_ANY
,
2124 .access
= PL1_W
, .accessfn
= ats_access
,
2125 .writefn
= ats_write
, .type
= ARM_CP_NO_RAW
},
2130 /* Return basic MPU access permission bits. */
2131 static uint32_t simple_mpu_ap_bits(uint32_t val
)
2138 for (i
= 0; i
< 16; i
+= 2) {
2139 ret
|= (val
>> i
) & mask
;
2145 /* Pad basic MPU access permission bits to extended format. */
2146 static uint32_t extended_mpu_ap_bits(uint32_t val
)
2153 for (i
= 0; i
< 16; i
+= 2) {
2154 ret
|= (val
& mask
) << i
;
2160 static void pmsav5_data_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2163 env
->cp15
.pmsav5_data_ap
= extended_mpu_ap_bits(value
);
2166 static uint64_t pmsav5_data_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2168 return simple_mpu_ap_bits(env
->cp15
.pmsav5_data_ap
);
2171 static void pmsav5_insn_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2174 env
->cp15
.pmsav5_insn_ap
= extended_mpu_ap_bits(value
);
2177 static uint64_t pmsav5_insn_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2179 return simple_mpu_ap_bits(env
->cp15
.pmsav5_insn_ap
);
2182 static uint64_t pmsav7_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2184 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
2190 u32p
+= env
->cp15
.c6_rgnr
;
2194 static void pmsav7_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2197 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2198 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
2204 u32p
+= env
->cp15
.c6_rgnr
;
2205 tlb_flush(CPU(cpu
), 1); /* Mappings may have changed - purge! */
2209 static void pmsav7_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2211 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2212 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
2218 memset(u32p
, 0, sizeof(*u32p
) * cpu
->pmsav7_dregion
);
2221 static void pmsav7_rgnr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2224 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2225 uint32_t nrgs
= cpu
->pmsav7_dregion
;
2227 if (value
>= nrgs
) {
2228 qemu_log_mask(LOG_GUEST_ERROR
,
2229 "PMSAv7 RGNR write >= # supported regions, %" PRIu32
2230 " > %" PRIu32
"\n", (uint32_t)value
, nrgs
);
2234 raw_write(env
, ri
, value
);
2237 static const ARMCPRegInfo pmsav7_cp_reginfo
[] = {
2238 { .name
= "DRBAR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 0,
2239 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
2240 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drbar
),
2241 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
, .resetfn
= pmsav7_reset
},
2242 { .name
= "DRSR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 2,
2243 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
2244 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drsr
),
2245 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
, .resetfn
= pmsav7_reset
},
2246 { .name
= "DRACR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 4,
2247 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
2248 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.dracr
),
2249 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
, .resetfn
= pmsav7_reset
},
2250 { .name
= "RGNR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 2, .opc2
= 0,
2252 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_rgnr
),
2253 .writefn
= pmsav7_rgnr_write
},
2257 static const ARMCPRegInfo pmsav5_cp_reginfo
[] = {
2258 { .name
= "DATA_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
2259 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
2260 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
2261 .readfn
= pmsav5_data_ap_read
, .writefn
= pmsav5_data_ap_write
, },
2262 { .name
= "INSN_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
2263 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
2264 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
2265 .readfn
= pmsav5_insn_ap_read
, .writefn
= pmsav5_insn_ap_write
, },
2266 { .name
= "DATA_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 2,
2268 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
2270 { .name
= "INSN_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 3,
2272 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
2274 { .name
= "DCACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 0,
2276 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_data
), .resetvalue
= 0, },
2277 { .name
= "ICACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 1,
2279 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_insn
), .resetvalue
= 0, },
2280 /* Protection region base and size registers */
2281 { .name
= "946_PRBS0", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0,
2282 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2283 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[0]) },
2284 { .name
= "946_PRBS1", .cp
= 15, .crn
= 6, .crm
= 1, .opc1
= 0,
2285 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2286 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[1]) },
2287 { .name
= "946_PRBS2", .cp
= 15, .crn
= 6, .crm
= 2, .opc1
= 0,
2288 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2289 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[2]) },
2290 { .name
= "946_PRBS3", .cp
= 15, .crn
= 6, .crm
= 3, .opc1
= 0,
2291 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2292 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[3]) },
2293 { .name
= "946_PRBS4", .cp
= 15, .crn
= 6, .crm
= 4, .opc1
= 0,
2294 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2295 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[4]) },
2296 { .name
= "946_PRBS5", .cp
= 15, .crn
= 6, .crm
= 5, .opc1
= 0,
2297 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2298 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[5]) },
2299 { .name
= "946_PRBS6", .cp
= 15, .crn
= 6, .crm
= 6, .opc1
= 0,
2300 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2301 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[6]) },
2302 { .name
= "946_PRBS7", .cp
= 15, .crn
= 6, .crm
= 7, .opc1
= 0,
2303 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2304 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[7]) },
2308 static void vmsa_ttbcr_raw_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2311 TCR
*tcr
= raw_ptr(env
, ri
);
2312 int maskshift
= extract32(value
, 0, 3);
2314 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
2315 if (arm_feature(env
, ARM_FEATURE_LPAE
) && (value
& TTBCR_EAE
)) {
2316 /* Pre ARMv8 bits [21:19], [15:14] and [6:3] are UNK/SBZP when
2317 * using Long-desciptor translation table format */
2318 value
&= ~((7 << 19) | (3 << 14) | (0xf << 3));
2319 } else if (arm_feature(env
, ARM_FEATURE_EL3
)) {
2320 /* In an implementation that includes the Security Extensions
2321 * TTBCR has additional fields PD0 [4] and PD1 [5] for
2322 * Short-descriptor translation table format.
2324 value
&= TTBCR_PD1
| TTBCR_PD0
| TTBCR_N
;
2330 /* Update the masks corresponding to the TCR bank being written
2331 * Note that we always calculate mask and base_mask, but
2332 * they are only used for short-descriptor tables (ie if EAE is 0);
2333 * for long-descriptor tables the TCR fields are used differently
2334 * and the mask and base_mask values are meaningless.
2336 tcr
->raw_tcr
= value
;
2337 tcr
->mask
= ~(((uint32_t)0xffffffffu
) >> maskshift
);
2338 tcr
->base_mask
= ~((uint32_t)0x3fffu
>> maskshift
);
2341 static void vmsa_ttbcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2344 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2346 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
2347 /* With LPAE the TTBCR could result in a change of ASID
2348 * via the TTBCR.A1 bit, so do a TLB flush.
2350 tlb_flush(CPU(cpu
), 1);
2352 vmsa_ttbcr_raw_write(env
, ri
, value
);
2355 static void vmsa_ttbcr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2357 TCR
*tcr
= raw_ptr(env
, ri
);
2359 /* Reset both the TCR as well as the masks corresponding to the bank of
2360 * the TCR being reset.
2364 tcr
->base_mask
= 0xffffc000u
;
2367 static void vmsa_tcr_el1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2370 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2371 TCR
*tcr
= raw_ptr(env
, ri
);
2373 /* For AArch64 the A1 bit could result in a change of ASID, so TLB flush. */
2374 tlb_flush(CPU(cpu
), 1);
2375 tcr
->raw_tcr
= value
;
2378 static void vmsa_ttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2381 /* 64 bit accesses to the TTBRs can change the ASID and so we
2382 * must flush the TLB.
2384 if (cpreg_field_is_64bit(ri
)) {
2385 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2387 tlb_flush(CPU(cpu
), 1);
2389 raw_write(env
, ri
, value
);
2392 static void vttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2395 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2396 CPUState
*cs
= CPU(cpu
);
2398 /* Accesses to VTTBR may change the VMID so we must flush the TLB. */
2399 if (raw_read(env
, ri
) != value
) {
2400 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S12NSE1
, ARMMMUIdx_S12NSE0
,
2401 ARMMMUIdx_S2NS
, -1);
2402 raw_write(env
, ri
, value
);
2406 static const ARMCPRegInfo vmsa_pmsa_cp_reginfo
[] = {
2407 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
2408 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
2409 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dfsr_s
),
2410 offsetoflow32(CPUARMState
, cp15
.dfsr_ns
) }, },
2411 { .name
= "IFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
2412 .access
= PL1_RW
, .resetvalue
= 0,
2413 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.ifsr_s
),
2414 offsetoflow32(CPUARMState
, cp15
.ifsr_ns
) } },
2415 { .name
= "DFAR", .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 0, .opc2
= 0,
2416 .access
= PL1_RW
, .resetvalue
= 0,
2417 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.dfar_s
),
2418 offsetof(CPUARMState
, cp15
.dfar_ns
) } },
2419 { .name
= "FAR_EL1", .state
= ARM_CP_STATE_AA64
,
2420 .opc0
= 3, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 0,
2421 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[1]),
2426 static const ARMCPRegInfo vmsa_cp_reginfo
[] = {
2427 { .name
= "ESR_EL1", .state
= ARM_CP_STATE_AA64
,
2428 .opc0
= 3, .crn
= 5, .crm
= 2, .opc1
= 0, .opc2
= 0,
2430 .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[1]), .resetvalue
= 0, },
2431 { .name
= "TTBR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2432 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 0,
2433 .access
= PL1_RW
, .writefn
= vmsa_ttbr_write
, .resetvalue
= 0,
2434 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
2435 offsetof(CPUARMState
, cp15
.ttbr0_ns
) } },
2436 { .name
= "TTBR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2437 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 1,
2438 .access
= PL1_RW
, .writefn
= vmsa_ttbr_write
, .resetvalue
= 0,
2439 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
2440 offsetof(CPUARMState
, cp15
.ttbr1_ns
) } },
2441 { .name
= "TCR_EL1", .state
= ARM_CP_STATE_AA64
,
2442 .opc0
= 3, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
2443 .access
= PL1_RW
, .writefn
= vmsa_tcr_el1_write
,
2444 .resetfn
= vmsa_ttbcr_reset
, .raw_writefn
= raw_write
,
2445 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[1]) },
2446 { .name
= "TTBCR", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
2447 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
, .writefn
= vmsa_ttbcr_write
,
2448 .raw_writefn
= vmsa_ttbcr_raw_write
,
2449 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tcr_el
[3]),
2450 offsetoflow32(CPUARMState
, cp15
.tcr_el
[1])} },
2454 static void omap_ticonfig_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2457 env
->cp15
.c15_ticonfig
= value
& 0xe7;
2458 /* The OS_TYPE bit in this register changes the reported CPUID! */
2459 env
->cp15
.c0_cpuid
= (value
& (1 << 5)) ?
2460 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
2463 static void omap_threadid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2466 env
->cp15
.c15_threadid
= value
& 0xffff;
2469 static void omap_wfi_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2472 /* Wait-for-interrupt (deprecated) */
2473 cpu_interrupt(CPU(arm_env_get_cpu(env
)), CPU_INTERRUPT_HALT
);
2476 static void omap_cachemaint_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2479 /* On OMAP there are registers indicating the max/min index of dcache lines
2480 * containing a dirty line; cache flush operations have to reset these.
2482 env
->cp15
.c15_i_max
= 0x000;
2483 env
->cp15
.c15_i_min
= 0xff0;
2486 static const ARMCPRegInfo omap_cp_reginfo
[] = {
2487 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= CP_ANY
,
2488 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_OVERRIDE
,
2489 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.esr_el
[1]),
2491 { .name
= "", .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 0, .opc2
= 0,
2492 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
2493 { .name
= "TICONFIG", .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0,
2495 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ticonfig
), .resetvalue
= 0,
2496 .writefn
= omap_ticonfig_write
},
2497 { .name
= "IMAX", .cp
= 15, .crn
= 15, .crm
= 2, .opc1
= 0, .opc2
= 0,
2499 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_max
), .resetvalue
= 0, },
2500 { .name
= "IMIN", .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 0, .opc2
= 0,
2501 .access
= PL1_RW
, .resetvalue
= 0xff0,
2502 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_min
) },
2503 { .name
= "THREADID", .cp
= 15, .crn
= 15, .crm
= 4, .opc1
= 0, .opc2
= 0,
2505 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_threadid
), .resetvalue
= 0,
2506 .writefn
= omap_threadid_write
},
2507 { .name
= "TI925T_STATUS", .cp
= 15, .crn
= 15,
2508 .crm
= 8, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
2509 .type
= ARM_CP_NO_RAW
,
2510 .readfn
= arm_cp_read_zero
, .writefn
= omap_wfi_write
, },
2511 /* TODO: Peripheral port remap register:
2512 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt controller
2513 * base address at $rn & ~0xfff and map size of 0x200 << ($rn & 0xfff),
2516 { .name
= "OMAP_CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
2517 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
2518 .type
= ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
,
2519 .writefn
= omap_cachemaint_write
},
2520 { .name
= "C9", .cp
= 15, .crn
= 9,
2521 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
,
2522 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
, .resetvalue
= 0 },
2526 static void xscale_cpar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2529 env
->cp15
.c15_cpar
= value
& 0x3fff;
2532 static const ARMCPRegInfo xscale_cp_reginfo
[] = {
2533 { .name
= "XSCALE_CPAR",
2534 .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
2535 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_cpar
), .resetvalue
= 0,
2536 .writefn
= xscale_cpar_write
, },
2537 { .name
= "XSCALE_AUXCR",
2538 .cp
= 15, .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 1, .access
= PL1_RW
,
2539 .fieldoffset
= offsetof(CPUARMState
, cp15
.c1_xscaleauxcr
),
2541 /* XScale specific cache-lockdown: since we have no cache we NOP these
2542 * and hope the guest does not really rely on cache behaviour.
2544 { .name
= "XSCALE_LOCK_ICACHE_LINE",
2545 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 0,
2546 .access
= PL1_W
, .type
= ARM_CP_NOP
},
2547 { .name
= "XSCALE_UNLOCK_ICACHE",
2548 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 1,
2549 .access
= PL1_W
, .type
= ARM_CP_NOP
},
2550 { .name
= "XSCALE_DCACHE_LOCK",
2551 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 0,
2552 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
2553 { .name
= "XSCALE_UNLOCK_DCACHE",
2554 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 1,
2555 .access
= PL1_W
, .type
= ARM_CP_NOP
},
2559 static const ARMCPRegInfo dummy_c15_cp_reginfo
[] = {
2560 /* RAZ/WI the whole crn=15 space, when we don't have a more specific
2561 * implementation of this implementation-defined space.
2562 * Ideally this should eventually disappear in favour of actually
2563 * implementing the correct behaviour for all cores.
2565 { .name
= "C15_IMPDEF", .cp
= 15, .crn
= 15,
2566 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
2568 .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
| ARM_CP_OVERRIDE
,
2573 static const ARMCPRegInfo cache_dirty_status_cp_reginfo
[] = {
2574 /* Cache status: RAZ because we have no cache so it's always clean */
2575 { .name
= "CDSR", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 6,
2576 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
2581 static const ARMCPRegInfo cache_block_ops_cp_reginfo
[] = {
2582 /* We never have a a block transfer operation in progress */
2583 { .name
= "BXSR", .cp
= 15, .crn
= 7, .crm
= 12, .opc1
= 0, .opc2
= 4,
2584 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
2586 /* The cache ops themselves: these all NOP for QEMU */
2587 { .name
= "IICR", .cp
= 15, .crm
= 5, .opc1
= 0,
2588 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2589 { .name
= "IDCR", .cp
= 15, .crm
= 6, .opc1
= 0,
2590 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2591 { .name
= "CDCR", .cp
= 15, .crm
= 12, .opc1
= 0,
2592 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2593 { .name
= "PIR", .cp
= 15, .crm
= 12, .opc1
= 1,
2594 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2595 { .name
= "PDR", .cp
= 15, .crm
= 12, .opc1
= 2,
2596 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2597 { .name
= "CIDCR", .cp
= 15, .crm
= 14, .opc1
= 0,
2598 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2602 static const ARMCPRegInfo cache_test_clean_cp_reginfo
[] = {
2603 /* The cache test-and-clean instructions always return (1 << 30)
2604 * to indicate that there are no dirty cache lines.
2606 { .name
= "TC_DCACHE", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 3,
2607 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
2608 .resetvalue
= (1 << 30) },
2609 { .name
= "TCI_DCACHE", .cp
= 15, .crn
= 7, .crm
= 14, .opc1
= 0, .opc2
= 3,
2610 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
2611 .resetvalue
= (1 << 30) },
2615 static const ARMCPRegInfo strongarm_cp_reginfo
[] = {
2616 /* Ignore ReadBuffer accesses */
2617 { .name
= "C9_READBUFFER", .cp
= 15, .crn
= 9,
2618 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
2619 .access
= PL1_RW
, .resetvalue
= 0,
2620 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
},
2624 static uint64_t midr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2626 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2627 unsigned int cur_el
= arm_current_el(env
);
2628 bool secure
= arm_is_secure(env
);
2630 if (arm_feature(&cpu
->env
, ARM_FEATURE_EL2
) && !secure
&& cur_el
== 1) {
2631 return env
->cp15
.vpidr_el2
;
2633 return raw_read(env
, ri
);
2636 static uint64_t mpidr_read_val(CPUARMState
*env
)
2638 ARMCPU
*cpu
= ARM_CPU(arm_env_get_cpu(env
));
2639 uint64_t mpidr
= cpu
->mp_affinity
;
2641 if (arm_feature(env
, ARM_FEATURE_V7MP
)) {
2642 mpidr
|= (1U << 31);
2643 /* Cores which are uniprocessor (non-coherent)
2644 * but still implement the MP extensions set
2645 * bit 30. (For instance, Cortex-R5).
2647 if (cpu
->mp_is_up
) {
2648 mpidr
|= (1u << 30);
2654 static uint64_t mpidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2656 unsigned int cur_el
= arm_current_el(env
);
2657 bool secure
= arm_is_secure(env
);
2659 if (arm_feature(env
, ARM_FEATURE_EL2
) && !secure
&& cur_el
== 1) {
2660 return env
->cp15
.vmpidr_el2
;
2662 return mpidr_read_val(env
);
2665 static const ARMCPRegInfo mpidr_cp_reginfo
[] = {
2666 { .name
= "MPIDR", .state
= ARM_CP_STATE_BOTH
,
2667 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 5,
2668 .access
= PL1_R
, .readfn
= mpidr_read
, .type
= ARM_CP_NO_RAW
},
2672 static const ARMCPRegInfo lpae_cp_reginfo
[] = {
2674 { .name
= "AMAIR0", .state
= ARM_CP_STATE_BOTH
,
2675 .opc0
= 3, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 0,
2676 .access
= PL1_RW
, .type
= ARM_CP_CONST
,
2678 /* AMAIR1 is mapped to AMAIR_EL1[63:32] */
2679 { .name
= "AMAIR1", .cp
= 15, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 1,
2680 .access
= PL1_RW
, .type
= ARM_CP_CONST
,
2682 { .name
= "PAR", .cp
= 15, .crm
= 7, .opc1
= 0,
2683 .access
= PL1_RW
, .type
= ARM_CP_64BIT
, .resetvalue
= 0,
2684 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.par_s
),
2685 offsetof(CPUARMState
, cp15
.par_ns
)} },
2686 { .name
= "TTBR0", .cp
= 15, .crm
= 2, .opc1
= 0,
2687 .access
= PL1_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
2688 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
2689 offsetof(CPUARMState
, cp15
.ttbr0_ns
) },
2690 .writefn
= vmsa_ttbr_write
, },
2691 { .name
= "TTBR1", .cp
= 15, .crm
= 2, .opc1
= 1,
2692 .access
= PL1_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
2693 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
2694 offsetof(CPUARMState
, cp15
.ttbr1_ns
) },
2695 .writefn
= vmsa_ttbr_write
, },
2699 static uint64_t aa64_fpcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2701 return vfp_get_fpcr(env
);
2704 static void aa64_fpcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2707 vfp_set_fpcr(env
, value
);
2710 static uint64_t aa64_fpsr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2712 return vfp_get_fpsr(env
);
2715 static void aa64_fpsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2718 vfp_set_fpsr(env
, value
);
2721 static CPAccessResult
aa64_daif_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2724 if (arm_current_el(env
) == 0 && !(env
->cp15
.sctlr_el
[1] & SCTLR_UMA
)) {
2725 return CP_ACCESS_TRAP
;
2727 return CP_ACCESS_OK
;
2730 static void aa64_daif_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2733 env
->daif
= value
& PSTATE_DAIF
;
2736 static CPAccessResult
aa64_cacheop_access(CPUARMState
*env
,
2737 const ARMCPRegInfo
*ri
,
2740 /* Cache invalidate/clean: NOP, but EL0 must UNDEF unless
2741 * SCTLR_EL1.UCI is set.
2743 if (arm_current_el(env
) == 0 && !(env
->cp15
.sctlr_el
[1] & SCTLR_UCI
)) {
2744 return CP_ACCESS_TRAP
;
2746 return CP_ACCESS_OK
;
2749 /* See: D4.7.2 TLB maintenance requirements and the TLB maintenance instructions
2750 * Page D4-1736 (DDI0487A.b)
2753 static void tlbi_aa64_vmalle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2756 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2757 CPUState
*cs
= CPU(cpu
);
2759 if (arm_is_secure_below_el3(env
)) {
2760 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S1SE1
, ARMMMUIdx_S1SE0
, -1);
2762 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S12NSE1
, ARMMMUIdx_S12NSE0
, -1);
2766 static void tlbi_aa64_vmalle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2769 bool sec
= arm_is_secure_below_el3(env
);
2772 CPU_FOREACH(other_cs
) {
2774 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S1SE1
, ARMMMUIdx_S1SE0
, -1);
2776 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S12NSE1
,
2777 ARMMMUIdx_S12NSE0
, -1);
2782 static void tlbi_aa64_alle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2785 /* Note that the 'ALL' scope must invalidate both stage 1 and
2786 * stage 2 translations, whereas most other scopes only invalidate
2787 * stage 1 translations.
2789 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2790 CPUState
*cs
= CPU(cpu
);
2792 if (arm_is_secure_below_el3(env
)) {
2793 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S1SE1
, ARMMMUIdx_S1SE0
, -1);
2795 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
2796 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S12NSE1
, ARMMMUIdx_S12NSE0
,
2797 ARMMMUIdx_S2NS
, -1);
2799 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S12NSE1
, ARMMMUIdx_S12NSE0
, -1);
2804 static void tlbi_aa64_alle2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2807 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2808 CPUState
*cs
= CPU(cpu
);
2810 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S1E2
, -1);
2813 static void tlbi_aa64_alle3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2816 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2817 CPUState
*cs
= CPU(cpu
);
2819 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S1E3
, -1);
2822 static void tlbi_aa64_alle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2825 /* Note that the 'ALL' scope must invalidate both stage 1 and
2826 * stage 2 translations, whereas most other scopes only invalidate
2827 * stage 1 translations.
2829 bool sec
= arm_is_secure_below_el3(env
);
2830 bool has_el2
= arm_feature(env
, ARM_FEATURE_EL2
);
2833 CPU_FOREACH(other_cs
) {
2835 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S1SE1
, ARMMMUIdx_S1SE0
, -1);
2836 } else if (has_el2
) {
2837 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S12NSE1
,
2838 ARMMMUIdx_S12NSE0
, ARMMMUIdx_S2NS
, -1);
2840 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S12NSE1
,
2841 ARMMMUIdx_S12NSE0
, -1);
2846 static void tlbi_aa64_alle2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2851 CPU_FOREACH(other_cs
) {
2852 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S1E2
, -1);
2856 static void tlbi_aa64_alle3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2861 CPU_FOREACH(other_cs
) {
2862 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S1E3
, -1);
2866 static void tlbi_aa64_vae1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2869 /* Invalidate by VA, EL1&0 (AArch64 version).
2870 * Currently handles all of VAE1, VAAE1, VAALE1 and VALE1,
2871 * since we don't support flush-for-specific-ASID-only or
2872 * flush-last-level-only.
2874 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2875 CPUState
*cs
= CPU(cpu
);
2876 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
2878 if (arm_is_secure_below_el3(env
)) {
2879 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S1SE1
,
2880 ARMMMUIdx_S1SE0
, -1);
2882 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S12NSE1
,
2883 ARMMMUIdx_S12NSE0
, -1);
2887 static void tlbi_aa64_vae2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2890 /* Invalidate by VA, EL2
2891 * Currently handles both VAE2 and VALE2, since we don't support
2892 * flush-last-level-only.
2894 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2895 CPUState
*cs
= CPU(cpu
);
2896 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
2898 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S1E2
, -1);
2901 static void tlbi_aa64_vae3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2904 /* Invalidate by VA, EL3
2905 * Currently handles both VAE3 and VALE3, since we don't support
2906 * flush-last-level-only.
2908 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2909 CPUState
*cs
= CPU(cpu
);
2910 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
2912 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S1E3
, -1);
2915 static void tlbi_aa64_vae1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2918 bool sec
= arm_is_secure_below_el3(env
);
2920 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
2922 CPU_FOREACH(other_cs
) {
2924 tlb_flush_page_by_mmuidx(other_cs
, pageaddr
, ARMMMUIdx_S1SE1
,
2925 ARMMMUIdx_S1SE0
, -1);
2927 tlb_flush_page_by_mmuidx(other_cs
, pageaddr
, ARMMMUIdx_S12NSE1
,
2928 ARMMMUIdx_S12NSE0
, -1);
2933 static void tlbi_aa64_vae2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2937 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
2939 CPU_FOREACH(other_cs
) {
2940 tlb_flush_page_by_mmuidx(other_cs
, pageaddr
, ARMMMUIdx_S1E2
, -1);
2944 static void tlbi_aa64_vae3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2948 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
2950 CPU_FOREACH(other_cs
) {
2951 tlb_flush_page_by_mmuidx(other_cs
, pageaddr
, ARMMMUIdx_S1E3
, -1);
2955 static void tlbi_aa64_ipas2e1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2958 /* Invalidate by IPA. This has to invalidate any structures that
2959 * contain only stage 2 translation information, but does not need
2960 * to apply to structures that contain combined stage 1 and stage 2
2961 * translation information.
2962 * This must NOP if EL2 isn't implemented or SCR_EL3.NS is zero.
2964 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2965 CPUState
*cs
= CPU(cpu
);
2968 if (!arm_feature(env
, ARM_FEATURE_EL2
) || !(env
->cp15
.scr_el3
& SCR_NS
)) {
2972 pageaddr
= sextract64(value
<< 12, 0, 48);
2974 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S2NS
, -1);
2977 static void tlbi_aa64_ipas2e1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2983 if (!arm_feature(env
, ARM_FEATURE_EL2
) || !(env
->cp15
.scr_el3
& SCR_NS
)) {