1 #include "qemu/osdep.h"
5 #include "exec/gdbstub.h"
6 #include "exec/helper-proto.h"
7 #include "qemu/host-utils.h"
8 #include "sysemu/arch_init.h"
9 #include "sysemu/sysemu.h"
10 #include "qemu/bitops.h"
11 #include "qemu/crc32c.h"
12 #include "exec/exec-all.h"
13 #include "exec/cpu_ldst.h"
15 #include <zlib.h> /* For crc32 */
16 #include "exec/semihost.h"
17 #include "sysemu/kvm.h"
19 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */
21 #ifndef CONFIG_USER_ONLY
22 static bool get_phys_addr(CPUARMState
*env
, target_ulong address
,
23 int access_type
, ARMMMUIdx mmu_idx
,
24 hwaddr
*phys_ptr
, MemTxAttrs
*attrs
, int *prot
,
25 target_ulong
*page_size
, uint32_t *fsr
,
28 static bool get_phys_addr_lpae(CPUARMState
*env
, target_ulong address
,
29 int access_type
, ARMMMUIdx mmu_idx
,
30 hwaddr
*phys_ptr
, MemTxAttrs
*txattrs
, int *prot
,
31 target_ulong
*page_size_ptr
, uint32_t *fsr
,
34 /* Definitions for the PMCCNTR and PMCR registers */
40 static int vfp_gdb_get_reg(CPUARMState
*env
, uint8_t *buf
, int reg
)
44 /* VFP data registers are always little-endian. */
45 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ? 32 : 16;
47 stfq_le_p(buf
, env
->vfp
.regs
[reg
]);
50 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
51 /* Aliases for Q regs. */
54 stfq_le_p(buf
, env
->vfp
.regs
[(reg
- 32) * 2]);
55 stfq_le_p(buf
+ 8, env
->vfp
.regs
[(reg
- 32) * 2 + 1]);
59 switch (reg
- nregs
) {
60 case 0: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSID
]); return 4;
61 case 1: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSCR
]); return 4;
62 case 2: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPEXC
]); return 4;
67 static int vfp_gdb_set_reg(CPUARMState
*env
, uint8_t *buf
, int reg
)
71 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ? 32 : 16;
73 env
->vfp
.regs
[reg
] = ldfq_le_p(buf
);
76 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
79 env
->vfp
.regs
[(reg
- 32) * 2] = ldfq_le_p(buf
);
80 env
->vfp
.regs
[(reg
- 32) * 2 + 1] = ldfq_le_p(buf
+ 8);
84 switch (reg
- nregs
) {
85 case 0: env
->vfp
.xregs
[ARM_VFP_FPSID
] = ldl_p(buf
); return 4;
86 case 1: env
->vfp
.xregs
[ARM_VFP_FPSCR
] = ldl_p(buf
); return 4;
87 case 2: env
->vfp
.xregs
[ARM_VFP_FPEXC
] = ldl_p(buf
) & (1 << 30); return 4;
92 static int aarch64_fpu_gdb_get_reg(CPUARMState
*env
, uint8_t *buf
, int reg
)
96 /* 128 bit FP register */
97 stfq_le_p(buf
, env
->vfp
.regs
[reg
* 2]);
98 stfq_le_p(buf
+ 8, env
->vfp
.regs
[reg
* 2 + 1]);
102 stl_p(buf
, vfp_get_fpsr(env
));
106 stl_p(buf
, vfp_get_fpcr(env
));
113 static int aarch64_fpu_gdb_set_reg(CPUARMState
*env
, uint8_t *buf
, int reg
)
117 /* 128 bit FP register */
118 env
->vfp
.regs
[reg
* 2] = ldfq_le_p(buf
);
119 env
->vfp
.regs
[reg
* 2 + 1] = ldfq_le_p(buf
+ 8);
123 vfp_set_fpsr(env
, ldl_p(buf
));
127 vfp_set_fpcr(env
, ldl_p(buf
));
134 static uint64_t raw_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
136 assert(ri
->fieldoffset
);
137 if (cpreg_field_is_64bit(ri
)) {
138 return CPREG_FIELD64(env
, ri
);
140 return CPREG_FIELD32(env
, ri
);
144 static void raw_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
147 assert(ri
->fieldoffset
);
148 if (cpreg_field_is_64bit(ri
)) {
149 CPREG_FIELD64(env
, ri
) = value
;
151 CPREG_FIELD32(env
, ri
) = value
;
155 static void *raw_ptr(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
157 return (char *)env
+ ri
->fieldoffset
;
160 uint64_t read_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
162 /* Raw read of a coprocessor register (as needed for migration, etc). */
163 if (ri
->type
& ARM_CP_CONST
) {
164 return ri
->resetvalue
;
165 } else if (ri
->raw_readfn
) {
166 return ri
->raw_readfn(env
, ri
);
167 } else if (ri
->readfn
) {
168 return ri
->readfn(env
, ri
);
170 return raw_read(env
, ri
);
174 static void write_raw_cp_reg(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
177 /* Raw write of a coprocessor register (as needed for migration, etc).
178 * Note that constant registers are treated as write-ignored; the
179 * caller should check for success by whether a readback gives the
182 if (ri
->type
& ARM_CP_CONST
) {
184 } else if (ri
->raw_writefn
) {
185 ri
->raw_writefn(env
, ri
, v
);
186 } else if (ri
->writefn
) {
187 ri
->writefn(env
, ri
, v
);
189 raw_write(env
, ri
, v
);
193 static bool raw_accessors_invalid(const ARMCPRegInfo
*ri
)
195 /* Return true if the regdef would cause an assertion if you called
196 * read_raw_cp_reg() or write_raw_cp_reg() on it (ie if it is a
197 * program bug for it not to have the NO_RAW flag).
198 * NB that returning false here doesn't necessarily mean that calling
199 * read/write_raw_cp_reg() is safe, because we can't distinguish "has
200 * read/write access functions which are safe for raw use" from "has
201 * read/write access functions which have side effects but has forgotten
202 * to provide raw access functions".
203 * The tests here line up with the conditions in read/write_raw_cp_reg()
204 * and assertions in raw_read()/raw_write().
206 if ((ri
->type
& ARM_CP_CONST
) ||
208 ((ri
->raw_writefn
|| ri
->writefn
) && (ri
->raw_readfn
|| ri
->readfn
))) {
214 bool write_cpustate_to_list(ARMCPU
*cpu
)
216 /* Write the coprocessor state from cpu->env to the (index,value) list. */
220 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
221 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
222 const ARMCPRegInfo
*ri
;
224 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
229 if (ri
->type
& ARM_CP_NO_RAW
) {
232 cpu
->cpreg_values
[i
] = read_raw_cp_reg(&cpu
->env
, ri
);
237 bool write_list_to_cpustate(ARMCPU
*cpu
)
242 for (i
= 0; i
< cpu
->cpreg_array_len
; i
++) {
243 uint32_t regidx
= kvm_to_cpreg_id(cpu
->cpreg_indexes
[i
]);
244 uint64_t v
= cpu
->cpreg_values
[i
];
245 const ARMCPRegInfo
*ri
;
247 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
252 if (ri
->type
& ARM_CP_NO_RAW
) {
255 /* Write value and confirm it reads back as written
256 * (to catch read-only registers and partially read-only
257 * registers where the incoming migration value doesn't match)
259 write_raw_cp_reg(&cpu
->env
, ri
, v
);
260 if (read_raw_cp_reg(&cpu
->env
, ri
) != v
) {
267 static void add_cpreg_to_list(gpointer key
, gpointer opaque
)
269 ARMCPU
*cpu
= opaque
;
271 const ARMCPRegInfo
*ri
;
273 regidx
= *(uint32_t *)key
;
274 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
276 if (!(ri
->type
& (ARM_CP_NO_RAW
|ARM_CP_ALIAS
))) {
277 cpu
->cpreg_indexes
[cpu
->cpreg_array_len
] = cpreg_to_kvm_id(regidx
);
278 /* The value array need not be initialized at this point */
279 cpu
->cpreg_array_len
++;
283 static void count_cpreg(gpointer key
, gpointer opaque
)
285 ARMCPU
*cpu
= opaque
;
287 const ARMCPRegInfo
*ri
;
289 regidx
= *(uint32_t *)key
;
290 ri
= get_arm_cp_reginfo(cpu
->cp_regs
, regidx
);
292 if (!(ri
->type
& (ARM_CP_NO_RAW
|ARM_CP_ALIAS
))) {
293 cpu
->cpreg_array_len
++;
297 static gint
cpreg_key_compare(gconstpointer a
, gconstpointer b
)
299 uint64_t aidx
= cpreg_to_kvm_id(*(uint32_t *)a
);
300 uint64_t bidx
= cpreg_to_kvm_id(*(uint32_t *)b
);
311 void init_cpreg_list(ARMCPU
*cpu
)
313 /* Initialise the cpreg_tuples[] array based on the cp_regs hash.
314 * Note that we require cpreg_tuples[] to be sorted by key ID.
319 keys
= g_hash_table_get_keys(cpu
->cp_regs
);
320 keys
= g_list_sort(keys
, cpreg_key_compare
);
322 cpu
->cpreg_array_len
= 0;
324 g_list_foreach(keys
, count_cpreg
, cpu
);
326 arraylen
= cpu
->cpreg_array_len
;
327 cpu
->cpreg_indexes
= g_new(uint64_t, arraylen
);
328 cpu
->cpreg_values
= g_new(uint64_t, arraylen
);
329 cpu
->cpreg_vmstate_indexes
= g_new(uint64_t, arraylen
);
330 cpu
->cpreg_vmstate_values
= g_new(uint64_t, arraylen
);
331 cpu
->cpreg_vmstate_array_len
= cpu
->cpreg_array_len
;
332 cpu
->cpreg_array_len
= 0;
334 g_list_foreach(keys
, add_cpreg_to_list
, cpu
);
336 assert(cpu
->cpreg_array_len
== arraylen
);
342 * Some registers are not accessible if EL3.NS=0 and EL3 is using AArch32 but
343 * they are accessible when EL3 is using AArch64 regardless of EL3.NS.
345 * access_el3_aa32ns: Used to check AArch32 register views.
346 * access_el3_aa32ns_aa64any: Used to check both AArch32/64 register views.
348 static CPAccessResult
access_el3_aa32ns(CPUARMState
*env
,
349 const ARMCPRegInfo
*ri
,
352 bool secure
= arm_is_secure_below_el3(env
);
354 assert(!arm_el_is_aa64(env
, 3));
356 return CP_ACCESS_TRAP_UNCATEGORIZED
;
361 static CPAccessResult
access_el3_aa32ns_aa64any(CPUARMState
*env
,
362 const ARMCPRegInfo
*ri
,
365 if (!arm_el_is_aa64(env
, 3)) {
366 return access_el3_aa32ns(env
, ri
, isread
);
371 /* Some secure-only AArch32 registers trap to EL3 if used from
372 * Secure EL1 (but are just ordinary UNDEF in other non-EL3 contexts).
373 * Note that an access from Secure EL1 can only happen if EL3 is AArch64.
374 * We assume that the .access field is set to PL1_RW.
376 static CPAccessResult
access_trap_aa32s_el1(CPUARMState
*env
,
377 const ARMCPRegInfo
*ri
,
380 if (arm_current_el(env
) == 3) {
383 if (arm_is_secure_below_el3(env
)) {
384 return CP_ACCESS_TRAP_EL3
;
386 /* This will be EL1 NS and EL2 NS, which just UNDEF */
387 return CP_ACCESS_TRAP_UNCATEGORIZED
;
390 /* Check for traps to "powerdown debug" registers, which are controlled
393 static CPAccessResult
access_tdosa(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
396 int el
= arm_current_el(env
);
398 if (el
< 2 && (env
->cp15
.mdcr_el2
& MDCR_TDOSA
)
399 && !arm_is_secure_below_el3(env
)) {
400 return CP_ACCESS_TRAP_EL2
;
402 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDOSA
)) {
403 return CP_ACCESS_TRAP_EL3
;
408 /* Check for traps to "debug ROM" registers, which are controlled
409 * by MDCR_EL2.TDRA for EL2 but by the more general MDCR_EL3.TDA for EL3.
411 static CPAccessResult
access_tdra(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
414 int el
= arm_current_el(env
);
416 if (el
< 2 && (env
->cp15
.mdcr_el2
& MDCR_TDRA
)
417 && !arm_is_secure_below_el3(env
)) {
418 return CP_ACCESS_TRAP_EL2
;
420 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDA
)) {
421 return CP_ACCESS_TRAP_EL3
;
426 /* Check for traps to general debug registers, which are controlled
427 * by MDCR_EL2.TDA for EL2 and MDCR_EL3.TDA for EL3.
429 static CPAccessResult
access_tda(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
432 int el
= arm_current_el(env
);
434 if (el
< 2 && (env
->cp15
.mdcr_el2
& MDCR_TDA
)
435 && !arm_is_secure_below_el3(env
)) {
436 return CP_ACCESS_TRAP_EL2
;
438 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TDA
)) {
439 return CP_ACCESS_TRAP_EL3
;
444 /* Check for traps to performance monitor registers, which are controlled
445 * by MDCR_EL2.TPM for EL2 and MDCR_EL3.TPM for EL3.
447 static CPAccessResult
access_tpm(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
450 int el
= arm_current_el(env
);
452 if (el
< 2 && (env
->cp15
.mdcr_el2
& MDCR_TPM
)
453 && !arm_is_secure_below_el3(env
)) {
454 return CP_ACCESS_TRAP_EL2
;
456 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
457 return CP_ACCESS_TRAP_EL3
;
462 static void dacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
464 ARMCPU
*cpu
= arm_env_get_cpu(env
);
466 raw_write(env
, ri
, value
);
467 tlb_flush(CPU(cpu
), 1); /* Flush TLB as domain not tracked in TLB */
470 static void fcse_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
472 ARMCPU
*cpu
= arm_env_get_cpu(env
);
474 if (raw_read(env
, ri
) != value
) {
475 /* Unlike real hardware the qemu TLB uses virtual addresses,
476 * not modified virtual addresses, so this causes a TLB flush.
478 tlb_flush(CPU(cpu
), 1);
479 raw_write(env
, ri
, value
);
483 static void contextidr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
486 ARMCPU
*cpu
= arm_env_get_cpu(env
);
488 if (raw_read(env
, ri
) != value
&& !arm_feature(env
, ARM_FEATURE_MPU
)
489 && !extended_addresses_enabled(env
)) {
490 /* For VMSA (when not using the LPAE long descriptor page table
491 * format) this register includes the ASID, so do a TLB flush.
492 * For PMSA it is purely a process ID and no action is needed.
494 tlb_flush(CPU(cpu
), 1);
496 raw_write(env
, ri
, value
);
499 static void tlbiall_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
502 /* Invalidate all (TLBIALL) */
503 ARMCPU
*cpu
= arm_env_get_cpu(env
);
505 tlb_flush(CPU(cpu
), 1);
508 static void tlbimva_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
511 /* Invalidate single TLB entry by MVA and ASID (TLBIMVA) */
512 ARMCPU
*cpu
= arm_env_get_cpu(env
);
514 tlb_flush_page(CPU(cpu
), value
& TARGET_PAGE_MASK
);
517 static void tlbiasid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
520 /* Invalidate by ASID (TLBIASID) */
521 ARMCPU
*cpu
= arm_env_get_cpu(env
);
523 tlb_flush(CPU(cpu
), value
== 0);
526 static void tlbimvaa_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
529 /* Invalidate single entry by MVA, all ASIDs (TLBIMVAA) */
530 ARMCPU
*cpu
= arm_env_get_cpu(env
);
532 tlb_flush_page(CPU(cpu
), value
& TARGET_PAGE_MASK
);
535 /* IS variants of TLB operations must affect all cores */
536 static void tlbiall_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
541 CPU_FOREACH(other_cs
) {
542 tlb_flush(other_cs
, 1);
546 static void tlbiasid_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
551 CPU_FOREACH(other_cs
) {
552 tlb_flush(other_cs
, value
== 0);
556 static void tlbimva_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
561 CPU_FOREACH(other_cs
) {
562 tlb_flush_page(other_cs
, value
& TARGET_PAGE_MASK
);
566 static void tlbimvaa_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
571 CPU_FOREACH(other_cs
) {
572 tlb_flush_page(other_cs
, value
& TARGET_PAGE_MASK
);
576 static void tlbiall_nsnh_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
579 CPUState
*cs
= ENV_GET_CPU(env
);
581 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S12NSE1
, ARMMMUIdx_S12NSE0
,
585 static void tlbiall_nsnh_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
590 CPU_FOREACH(other_cs
) {
591 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S12NSE1
,
592 ARMMMUIdx_S12NSE0
, ARMMMUIdx_S2NS
, -1);
596 static void tlbiipas2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
599 /* Invalidate by IPA. This has to invalidate any structures that
600 * contain only stage 2 translation information, but does not need
601 * to apply to structures that contain combined stage 1 and stage 2
602 * translation information.
603 * This must NOP if EL2 isn't implemented or SCR_EL3.NS is zero.
605 CPUState
*cs
= ENV_GET_CPU(env
);
608 if (!arm_feature(env
, ARM_FEATURE_EL2
) || !(env
->cp15
.scr_el3
& SCR_NS
)) {
612 pageaddr
= sextract64(value
<< 12, 0, 40);
614 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S2NS
, -1);
617 static void tlbiipas2_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
623 if (!arm_feature(env
, ARM_FEATURE_EL2
) || !(env
->cp15
.scr_el3
& SCR_NS
)) {
627 pageaddr
= sextract64(value
<< 12, 0, 40);
629 CPU_FOREACH(other_cs
) {
630 tlb_flush_page_by_mmuidx(other_cs
, pageaddr
, ARMMMUIdx_S2NS
, -1);
634 static void tlbiall_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
637 CPUState
*cs
= ENV_GET_CPU(env
);
639 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S1E2
, -1);
642 static void tlbiall_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
647 CPU_FOREACH(other_cs
) {
648 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S1E2
, -1);
652 static void tlbimva_hyp_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
655 CPUState
*cs
= ENV_GET_CPU(env
);
656 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
658 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S1E2
, -1);
661 static void tlbimva_hyp_is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
665 uint64_t pageaddr
= value
& ~MAKE_64BIT_MASK(0, 12);
667 CPU_FOREACH(other_cs
) {
668 tlb_flush_page_by_mmuidx(other_cs
, pageaddr
, ARMMMUIdx_S1E2
, -1);
672 static const ARMCPRegInfo cp_reginfo
[] = {
673 /* Define the secure and non-secure FCSE identifier CP registers
674 * separately because there is no secure bank in V8 (no _EL3). This allows
675 * the secure register to be properly reset and migrated. There is also no
676 * v8 EL1 version of the register so the non-secure instance stands alone.
678 { .name
= "FCSEIDR(NS)",
679 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
680 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_NS
,
681 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_ns
),
682 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
683 { .name
= "FCSEIDR(S)",
684 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 0,
685 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_S
,
686 .fieldoffset
= offsetof(CPUARMState
, cp15
.fcseidr_s
),
687 .resetvalue
= 0, .writefn
= fcse_write
, .raw_writefn
= raw_write
, },
688 /* Define the secure and non-secure context identifier CP registers
689 * separately because there is no secure bank in V8 (no _EL3). This allows
690 * the secure register to be properly reset and migrated. In the
691 * non-secure case, the 32-bit register will have reset and migration
692 * disabled during registration as it is handled by the 64-bit instance.
694 { .name
= "CONTEXTIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
695 .opc0
= 3, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
696 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_NS
,
697 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_el
[1]),
698 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
699 { .name
= "CONTEXTIDR(S)", .state
= ARM_CP_STATE_AA32
,
700 .cp
= 15, .opc1
= 0, .crn
= 13, .crm
= 0, .opc2
= 1,
701 .access
= PL1_RW
, .secure
= ARM_CP_SECSTATE_S
,
702 .fieldoffset
= offsetof(CPUARMState
, cp15
.contextidr_s
),
703 .resetvalue
= 0, .writefn
= contextidr_write
, .raw_writefn
= raw_write
, },
707 static const ARMCPRegInfo not_v8_cp_reginfo
[] = {
708 /* NB: Some of these registers exist in v8 but with more precise
709 * definitions that don't use CP_ANY wildcards (mostly in v8_cp_reginfo[]).
711 /* MMU Domain access control / MPU write buffer control */
713 .cp
= 15, .opc1
= CP_ANY
, .crn
= 3, .crm
= CP_ANY
, .opc2
= CP_ANY
,
714 .access
= PL1_RW
, .resetvalue
= 0,
715 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
716 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
717 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
718 /* ARMv7 allocates a range of implementation defined TLB LOCKDOWN regs.
719 * For v6 and v5, these mappings are overly broad.
721 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 0,
722 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
723 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 1,
724 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
725 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 4,
726 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
727 { .name
= "TLB_LOCKDOWN", .cp
= 15, .crn
= 10, .crm
= 8,
728 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
729 /* Cache maintenance ops; some of this space may be overridden later. */
730 { .name
= "CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
731 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
732 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
},
736 static const ARMCPRegInfo not_v6_cp_reginfo
[] = {
737 /* Not all pre-v6 cores implemented this WFI, so this is slightly
740 { .name
= "WFI_v5", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= 2,
741 .access
= PL1_W
, .type
= ARM_CP_WFI
},
745 static const ARMCPRegInfo not_v7_cp_reginfo
[] = {
746 /* Standard v6 WFI (also used in some pre-v6 cores); not in v7 (which
747 * is UNPREDICTABLE; we choose to NOP as most implementations do).
749 { .name
= "WFI_v6", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
750 .access
= PL1_W
, .type
= ARM_CP_WFI
},
751 /* L1 cache lockdown. Not architectural in v6 and earlier but in practice
752 * implemented in 926, 946, 1026, 1136, 1176 and 11MPCore. StrongARM and
753 * OMAPCP will override this space.
755 { .name
= "DLOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 0,
756 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_data
),
758 { .name
= "ILOCKDOWN", .cp
= 15, .crn
= 9, .crm
= 0, .opc1
= 0, .opc2
= 1,
759 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_insn
),
761 /* v6 doesn't have the cache ID registers but Linux reads them anyway */
762 { .name
= "DUMMY", .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= CP_ANY
,
763 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
765 /* We don't implement pre-v7 debug but most CPUs had at least a DBGDIDR;
766 * implementing it as RAZ means the "debug architecture version" bits
767 * will read as a reserved value, which should cause Linux to not try
768 * to use the debug hardware.
770 { .name
= "DBGDIDR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 0,
771 .access
= PL0_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
772 /* MMU TLB control. Note that the wildcarding means we cover not just
773 * the unified TLB ops but also the dside/iside/inner-shareable variants.
775 { .name
= "TLBIALL", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
776 .opc1
= CP_ANY
, .opc2
= 0, .access
= PL1_W
, .writefn
= tlbiall_write
,
777 .type
= ARM_CP_NO_RAW
},
778 { .name
= "TLBIMVA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
779 .opc1
= CP_ANY
, .opc2
= 1, .access
= PL1_W
, .writefn
= tlbimva_write
,
780 .type
= ARM_CP_NO_RAW
},
781 { .name
= "TLBIASID", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
782 .opc1
= CP_ANY
, .opc2
= 2, .access
= PL1_W
, .writefn
= tlbiasid_write
,
783 .type
= ARM_CP_NO_RAW
},
784 { .name
= "TLBIMVAA", .cp
= 15, .crn
= 8, .crm
= CP_ANY
,
785 .opc1
= CP_ANY
, .opc2
= 3, .access
= PL1_W
, .writefn
= tlbimvaa_write
,
786 .type
= ARM_CP_NO_RAW
},
787 { .name
= "PRRR", .cp
= 15, .crn
= 10, .crm
= 2,
788 .opc1
= 0, .opc2
= 0, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
789 { .name
= "NMRR", .cp
= 15, .crn
= 10, .crm
= 2,
790 .opc1
= 0, .opc2
= 1, .access
= PL1_RW
, .type
= ARM_CP_NOP
},
794 static void cpacr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
799 /* In ARMv8 most bits of CPACR_EL1 are RES0. */
800 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
801 /* ARMv7 defines bits for unimplemented coprocessors as RAZ/WI.
802 * ASEDIS [31] and D32DIS [30] are both UNK/SBZP without VFP.
803 * TRCDIS [28] is RAZ/WI since we do not implement a trace macrocell.
805 if (arm_feature(env
, ARM_FEATURE_VFP
)) {
806 /* VFP coprocessor: cp10 & cp11 [23:20] */
807 mask
|= (1 << 31) | (1 << 30) | (0xf << 20);
809 if (!arm_feature(env
, ARM_FEATURE_NEON
)) {
810 /* ASEDIS [31] bit is RAO/WI */
814 /* VFPv3 and upwards with NEON implement 32 double precision
815 * registers (D0-D31).
817 if (!arm_feature(env
, ARM_FEATURE_NEON
) ||
818 !arm_feature(env
, ARM_FEATURE_VFP3
)) {
819 /* D32DIS [30] is RAO/WI if D16-31 are not implemented. */
825 env
->cp15
.cpacr_el1
= value
;
828 static CPAccessResult
cpacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
831 if (arm_feature(env
, ARM_FEATURE_V8
)) {
832 /* Check if CPACR accesses are to be trapped to EL2 */
833 if (arm_current_el(env
) == 1 &&
834 (env
->cp15
.cptr_el
[2] & CPTR_TCPAC
) && !arm_is_secure(env
)) {
835 return CP_ACCESS_TRAP_EL2
;
836 /* Check if CPACR accesses are to be trapped to EL3 */
837 } else if (arm_current_el(env
) < 3 &&
838 (env
->cp15
.cptr_el
[3] & CPTR_TCPAC
)) {
839 return CP_ACCESS_TRAP_EL3
;
846 static CPAccessResult
cptr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
849 /* Check if CPTR accesses are set to trap to EL3 */
850 if (arm_current_el(env
) == 2 && (env
->cp15
.cptr_el
[3] & CPTR_TCPAC
)) {
851 return CP_ACCESS_TRAP_EL3
;
857 static const ARMCPRegInfo v6_cp_reginfo
[] = {
858 /* prefetch by MVA in v6, NOP in v7 */
859 { .name
= "MVA_prefetch",
860 .cp
= 15, .crn
= 7, .crm
= 13, .opc1
= 0, .opc2
= 1,
861 .access
= PL1_W
, .type
= ARM_CP_NOP
},
862 /* We need to break the TB after ISB to execute self-modifying code
863 * correctly and also to take any pending interrupts immediately.
864 * So use arm_cp_write_ignore() function instead of ARM_CP_NOP flag.
866 { .name
= "ISB", .cp
= 15, .crn
= 7, .crm
= 5, .opc1
= 0, .opc2
= 4,
867 .access
= PL0_W
, .type
= ARM_CP_NO_RAW
, .writefn
= arm_cp_write_ignore
},
868 { .name
= "DSB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 4,
869 .access
= PL0_W
, .type
= ARM_CP_NOP
},
870 { .name
= "DMB", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 5,
871 .access
= PL0_W
, .type
= ARM_CP_NOP
},
872 { .name
= "IFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 2,
874 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ifar_s
),
875 offsetof(CPUARMState
, cp15
.ifar_ns
) },
877 /* Watchpoint Fault Address Register : should actually only be present
878 * for 1136, 1176, 11MPCore.
880 { .name
= "WFAR", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 1,
881 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0, },
882 { .name
= "CPACR", .state
= ARM_CP_STATE_BOTH
, .opc0
= 3,
883 .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 2, .accessfn
= cpacr_access
,
884 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.cpacr_el1
),
885 .resetvalue
= 0, .writefn
= cpacr_write
},
889 static CPAccessResult
pmreg_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
892 /* Performance monitor registers user accessibility is controlled
893 * by PMUSERENR. MDCR_EL2.TPM and MDCR_EL3.TPM allow configurable
894 * trapping to EL2 or EL3 for other accesses.
896 int el
= arm_current_el(env
);
898 if (el
== 0 && !env
->cp15
.c9_pmuserenr
) {
899 return CP_ACCESS_TRAP
;
901 if (el
< 2 && (env
->cp15
.mdcr_el2
& MDCR_TPM
)
902 && !arm_is_secure_below_el3(env
)) {
903 return CP_ACCESS_TRAP_EL2
;
905 if (el
< 3 && (env
->cp15
.mdcr_el3
& MDCR_TPM
)) {
906 return CP_ACCESS_TRAP_EL3
;
912 #ifndef CONFIG_USER_ONLY
914 static inline bool arm_ccnt_enabled(CPUARMState
*env
)
916 /* This does not support checking PMCCFILTR_EL0 register */
918 if (!(env
->cp15
.c9_pmcr
& PMCRE
)) {
925 void pmccntr_sync(CPUARMState
*env
)
929 temp_ticks
= muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
930 ARM_CPU_FREQ
, NANOSECONDS_PER_SECOND
);
932 if (env
->cp15
.c9_pmcr
& PMCRD
) {
933 /* Increment once every 64 processor clock cycles */
937 if (arm_ccnt_enabled(env
)) {
938 env
->cp15
.c15_ccnt
= temp_ticks
- env
->cp15
.c15_ccnt
;
942 static void pmcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
948 /* The counter has been reset */
949 env
->cp15
.c15_ccnt
= 0;
952 /* only the DP, X, D and E bits are writable */
953 env
->cp15
.c9_pmcr
&= ~0x39;
954 env
->cp15
.c9_pmcr
|= (value
& 0x39);
959 static uint64_t pmccntr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
961 uint64_t total_ticks
;
963 if (!arm_ccnt_enabled(env
)) {
964 /* Counter is disabled, do not change value */
965 return env
->cp15
.c15_ccnt
;
968 total_ticks
= muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
969 ARM_CPU_FREQ
, NANOSECONDS_PER_SECOND
);
971 if (env
->cp15
.c9_pmcr
& PMCRD
) {
972 /* Increment once every 64 processor clock cycles */
975 return total_ticks
- env
->cp15
.c15_ccnt
;
978 static void pmccntr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
981 uint64_t total_ticks
;
983 if (!arm_ccnt_enabled(env
)) {
984 /* Counter is disabled, set the absolute value */
985 env
->cp15
.c15_ccnt
= value
;
989 total_ticks
= muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
),
990 ARM_CPU_FREQ
, NANOSECONDS_PER_SECOND
);
992 if (env
->cp15
.c9_pmcr
& PMCRD
) {
993 /* Increment once every 64 processor clock cycles */
996 env
->cp15
.c15_ccnt
= total_ticks
- value
;
999 static void pmccntr_write32(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1002 uint64_t cur_val
= pmccntr_read(env
, NULL
);
1004 pmccntr_write(env
, ri
, deposit64(cur_val
, 0, 32, value
));
1007 #else /* CONFIG_USER_ONLY */
1009 void pmccntr_sync(CPUARMState
*env
)
1015 static void pmccfiltr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1019 env
->cp15
.pmccfiltr_el0
= value
& 0x7E000000;
1023 static void pmcntenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1027 env
->cp15
.c9_pmcnten
|= value
;
1030 static void pmcntenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1034 env
->cp15
.c9_pmcnten
&= ~value
;
1037 static void pmovsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1040 env
->cp15
.c9_pmovsr
&= ~value
;
1043 static void pmxevtyper_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1046 env
->cp15
.c9_pmxevtyper
= value
& 0xff;
1049 static void pmuserenr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1052 env
->cp15
.c9_pmuserenr
= value
& 1;
1055 static void pmintenset_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1058 /* We have no event counters so only the C bit can be changed */
1060 env
->cp15
.c9_pminten
|= value
;
1063 static void pmintenclr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1067 env
->cp15
.c9_pminten
&= ~value
;
1070 static void vbar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1073 /* Note that even though the AArch64 view of this register has bits
1074 * [10:0] all RES0 we can only mask the bottom 5, to comply with the
1075 * architectural requirements for bits which are RES0 only in some
1076 * contexts. (ARMv8 would permit us to do no masking at all, but ARMv7
1077 * requires the bottom five bits to be RAZ/WI because they're UNK/SBZP.)
1079 raw_write(env
, ri
, value
& ~0x1FULL
);
1082 static void scr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
1084 /* We only mask off bits that are RES0 both for AArch64 and AArch32.
1085 * For bits that vary between AArch32/64, code needs to check the
1086 * current execution mode before directly using the feature bit.
1088 uint32_t valid_mask
= SCR_AARCH64_MASK
| SCR_AARCH32_MASK
;
1090 if (!arm_feature(env
, ARM_FEATURE_EL2
)) {
1091 valid_mask
&= ~SCR_HCE
;
1093 /* On ARMv7, SMD (or SCD as it is called in v7) is only
1094 * supported if EL2 exists. The bit is UNK/SBZP when
1095 * EL2 is unavailable. In QEMU ARMv7, we force it to always zero
1096 * when EL2 is unavailable.
1097 * On ARMv8, this bit is always available.
1099 if (arm_feature(env
, ARM_FEATURE_V7
) &&
1100 !arm_feature(env
, ARM_FEATURE_V8
)) {
1101 valid_mask
&= ~SCR_SMD
;
1105 /* Clear all-context RES0 bits. */
1106 value
&= valid_mask
;
1107 raw_write(env
, ri
, value
);
1110 static uint64_t ccsidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1112 ARMCPU
*cpu
= arm_env_get_cpu(env
);
1114 /* Acquire the CSSELR index from the bank corresponding to the CCSIDR
1117 uint32_t index
= A32_BANKED_REG_GET(env
, csselr
,
1118 ri
->secure
& ARM_CP_SECSTATE_S
);
1120 return cpu
->ccsidr
[index
];
1123 static void csselr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1126 raw_write(env
, ri
, value
& 0xf);
1129 static uint64_t isr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1131 CPUState
*cs
= ENV_GET_CPU(env
);
1134 if (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) {
1137 if (cs
->interrupt_request
& CPU_INTERRUPT_FIQ
) {
1140 /* External aborts are not possible in QEMU so A bit is always clear */
1144 static const ARMCPRegInfo v7_cp_reginfo
[] = {
1145 /* the old v6 WFI, UNPREDICTABLE in v7 but we choose to NOP */
1146 { .name
= "NOP", .cp
= 15, .crn
= 7, .crm
= 0, .opc1
= 0, .opc2
= 4,
1147 .access
= PL1_W
, .type
= ARM_CP_NOP
},
1148 /* Performance monitors are implementation defined in v7,
1149 * but with an ARM recommended set of registers, which we
1150 * follow (although we don't actually implement any counters)
1152 * Performance registers fall into three categories:
1153 * (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR)
1154 * (b) RO in PL0 (ie UNDEF on write), RW in PL1 (PMUSERENR)
1155 * (c) UNDEF in PL0 if PMUSERENR.EN==0, otherwise accessible (all others)
1156 * For the cases controlled by PMUSERENR we must set .access to PL0_RW
1157 * or PL0_RO as appropriate and then check PMUSERENR in the helper fn.
1159 { .name
= "PMCNTENSET", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 1,
1160 .access
= PL0_RW
, .type
= ARM_CP_ALIAS
,
1161 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
1162 .writefn
= pmcntenset_write
,
1163 .accessfn
= pmreg_access
,
1164 .raw_writefn
= raw_write
},
1165 { .name
= "PMCNTENSET_EL0", .state
= ARM_CP_STATE_AA64
,
1166 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 1,
1167 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1168 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
), .resetvalue
= 0,
1169 .writefn
= pmcntenset_write
, .raw_writefn
= raw_write
},
1170 { .name
= "PMCNTENCLR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 2,
1172 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcnten
),
1173 .accessfn
= pmreg_access
,
1174 .writefn
= pmcntenclr_write
,
1175 .type
= ARM_CP_ALIAS
},
1176 { .name
= "PMCNTENCLR_EL0", .state
= ARM_CP_STATE_AA64
,
1177 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 2,
1178 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1179 .type
= ARM_CP_ALIAS
,
1180 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcnten
),
1181 .writefn
= pmcntenclr_write
},
1182 { .name
= "PMOVSR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 3,
1183 .access
= PL0_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
1184 .accessfn
= pmreg_access
,
1185 .writefn
= pmovsr_write
,
1186 .raw_writefn
= raw_write
},
1187 { .name
= "PMOVSCLR_EL0", .state
= ARM_CP_STATE_AA64
,
1188 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 3,
1189 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1190 .type
= ARM_CP_ALIAS
,
1191 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmovsr
),
1192 .writefn
= pmovsr_write
,
1193 .raw_writefn
= raw_write
},
1194 /* Unimplemented so WI. */
1195 { .name
= "PMSWINC", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 4,
1196 .access
= PL0_W
, .accessfn
= pmreg_access
, .type
= ARM_CP_NOP
},
1197 /* Since we don't implement any events, writing to PMSELR is UNPREDICTABLE.
1198 * We choose to RAZ/WI.
1200 { .name
= "PMSELR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 5,
1201 .access
= PL0_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0,
1202 .accessfn
= pmreg_access
},
1203 #ifndef CONFIG_USER_ONLY
1204 { .name
= "PMCCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 0,
1205 .access
= PL0_RW
, .resetvalue
= 0, .type
= ARM_CP_IO
,
1206 .readfn
= pmccntr_read
, .writefn
= pmccntr_write32
,
1207 .accessfn
= pmreg_access
},
1208 { .name
= "PMCCNTR_EL0", .state
= ARM_CP_STATE_AA64
,
1209 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 13, .opc2
= 0,
1210 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1212 .readfn
= pmccntr_read
, .writefn
= pmccntr_write
, },
1214 { .name
= "PMCCFILTR_EL0", .state
= ARM_CP_STATE_AA64
,
1215 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 15, .opc2
= 7,
1216 .writefn
= pmccfiltr_write
,
1217 .access
= PL0_RW
, .accessfn
= pmreg_access
,
1219 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmccfiltr_el0
),
1221 { .name
= "PMXEVTYPER", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 1,
1223 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmxevtyper
),
1224 .accessfn
= pmreg_access
, .writefn
= pmxevtyper_write
,
1225 .raw_writefn
= raw_write
},
1226 /* Unimplemented, RAZ/WI. */
1227 { .name
= "PMXEVCNTR", .cp
= 15, .crn
= 9, .crm
= 13, .opc1
= 0, .opc2
= 2,
1228 .access
= PL0_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0,
1229 .accessfn
= pmreg_access
},
1230 { .name
= "PMUSERENR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 0,
1231 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
,
1232 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmuserenr
),
1234 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
1235 { .name
= "PMUSERENR_EL0", .state
= ARM_CP_STATE_AA64
,
1236 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 14, .opc2
= 0,
1237 .access
= PL0_R
| PL1_RW
, .accessfn
= access_tpm
, .type
= ARM_CP_ALIAS
,
1238 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmuserenr
),
1240 .writefn
= pmuserenr_write
, .raw_writefn
= raw_write
},
1241 { .name
= "PMINTENSET", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 1,
1242 .access
= PL1_RW
, .accessfn
= access_tpm
,
1243 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
1245 .writefn
= pmintenset_write
, .raw_writefn
= raw_write
},
1246 { .name
= "PMINTENCLR", .cp
= 15, .crn
= 9, .crm
= 14, .opc1
= 0, .opc2
= 2,
1247 .access
= PL1_RW
, .accessfn
= access_tpm
, .type
= ARM_CP_ALIAS
,
1248 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
1249 .writefn
= pmintenclr_write
, },
1250 { .name
= "PMINTENCLR_EL1", .state
= ARM_CP_STATE_AA64
,
1251 .opc0
= 3, .opc1
= 0, .crn
= 9, .crm
= 14, .opc2
= 2,
1252 .access
= PL1_RW
, .accessfn
= access_tpm
, .type
= ARM_CP_ALIAS
,
1253 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pminten
),
1254 .writefn
= pmintenclr_write
},
1255 { .name
= "VBAR", .state
= ARM_CP_STATE_BOTH
,
1256 .opc0
= 3, .crn
= 12, .crm
= 0, .opc1
= 0, .opc2
= 0,
1257 .access
= PL1_RW
, .writefn
= vbar_write
,
1258 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.vbar_s
),
1259 offsetof(CPUARMState
, cp15
.vbar_ns
) },
1261 { .name
= "CCSIDR", .state
= ARM_CP_STATE_BOTH
,
1262 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 0,
1263 .access
= PL1_R
, .readfn
= ccsidr_read
, .type
= ARM_CP_NO_RAW
},
1264 { .name
= "CSSELR", .state
= ARM_CP_STATE_BOTH
,
1265 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 2, .opc2
= 0,
1266 .access
= PL1_RW
, .writefn
= csselr_write
, .resetvalue
= 0,
1267 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.csselr_s
),
1268 offsetof(CPUARMState
, cp15
.csselr_ns
) } },
1269 /* Auxiliary ID register: this actually has an IMPDEF value but for now
1270 * just RAZ for all cores:
1272 { .name
= "AIDR", .state
= ARM_CP_STATE_BOTH
,
1273 .opc0
= 3, .opc1
= 1, .crn
= 0, .crm
= 0, .opc2
= 7,
1274 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
1275 /* Auxiliary fault status registers: these also are IMPDEF, and we
1276 * choose to RAZ/WI for all cores.
1278 { .name
= "AFSR0_EL1", .state
= ARM_CP_STATE_BOTH
,
1279 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 0,
1280 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
1281 { .name
= "AFSR1_EL1", .state
= ARM_CP_STATE_BOTH
,
1282 .opc0
= 3, .opc1
= 0, .crn
= 5, .crm
= 1, .opc2
= 1,
1283 .access
= PL1_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
1284 /* MAIR can just read-as-written because we don't implement caches
1285 * and so don't need to care about memory attributes.
1287 { .name
= "MAIR_EL1", .state
= ARM_CP_STATE_AA64
,
1288 .opc0
= 3, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0,
1289 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[1]),
1291 { .name
= "MAIR_EL3", .state
= ARM_CP_STATE_AA64
,
1292 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 2, .opc2
= 0,
1293 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[3]),
1295 /* For non-long-descriptor page tables these are PRRR and NMRR;
1296 * regardless they still act as reads-as-written for QEMU.
1298 /* MAIR0/1 are defined separately from their 64-bit counterpart which
1299 * allows them to assign the correct fieldoffset based on the endianness
1300 * handled in the field definitions.
1302 { .name
= "MAIR0", .state
= ARM_CP_STATE_AA32
,
1303 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 0, .access
= PL1_RW
,
1304 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair0_s
),
1305 offsetof(CPUARMState
, cp15
.mair0_ns
) },
1306 .resetfn
= arm_cp_reset_ignore
},
1307 { .name
= "MAIR1", .state
= ARM_CP_STATE_AA32
,
1308 .cp
= 15, .opc1
= 0, .crn
= 10, .crm
= 2, .opc2
= 1, .access
= PL1_RW
,
1309 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.mair1_s
),
1310 offsetof(CPUARMState
, cp15
.mair1_ns
) },
1311 .resetfn
= arm_cp_reset_ignore
},
1312 { .name
= "ISR_EL1", .state
= ARM_CP_STATE_BOTH
,
1313 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 1, .opc2
= 0,
1314 .type
= ARM_CP_NO_RAW
, .access
= PL1_R
, .readfn
= isr_read
},
1315 /* 32 bit ITLB invalidates */
1316 { .name
= "ITLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 0,
1317 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiall_write
},
1318 { .name
= "ITLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 1,
1319 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimva_write
},
1320 { .name
= "ITLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 5, .opc2
= 2,
1321 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiasid_write
},
1322 /* 32 bit DTLB invalidates */
1323 { .name
= "DTLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 0,
1324 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiall_write
},
1325 { .name
= "DTLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 1,
1326 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimva_write
},
1327 { .name
= "DTLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 6, .opc2
= 2,
1328 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiasid_write
},
1329 /* 32 bit TLB invalidates */
1330 { .name
= "TLBIALL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
1331 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiall_write
},
1332 { .name
= "TLBIMVA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
1333 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimva_write
},
1334 { .name
= "TLBIASID", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
1335 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiasid_write
},
1336 { .name
= "TLBIMVAA", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
1337 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimvaa_write
},
1341 static const ARMCPRegInfo v7mp_cp_reginfo
[] = {
1342 /* 32 bit TLB invalidates, Inner Shareable */
1343 { .name
= "TLBIALLIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
1344 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbiall_is_write
},
1345 { .name
= "TLBIMVAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
1346 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimva_is_write
},
1347 { .name
= "TLBIASIDIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
1348 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
,
1349 .writefn
= tlbiasid_is_write
},
1350 { .name
= "TLBIMVAAIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
1351 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
,
1352 .writefn
= tlbimvaa_is_write
},
1356 static void teecr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1363 static CPAccessResult
teehbr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1366 if (arm_current_el(env
) == 0 && (env
->teecr
& 1)) {
1367 return CP_ACCESS_TRAP
;
1369 return CP_ACCESS_OK
;
1372 static const ARMCPRegInfo t2ee_cp_reginfo
[] = {
1373 { .name
= "TEECR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 6, .opc2
= 0,
1374 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, teecr
),
1376 .writefn
= teecr_write
},
1377 { .name
= "TEEHBR", .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 6, .opc2
= 0,
1378 .access
= PL0_RW
, .fieldoffset
= offsetof(CPUARMState
, teehbr
),
1379 .accessfn
= teehbr_access
, .resetvalue
= 0 },
1383 static const ARMCPRegInfo v6k_cp_reginfo
[] = {
1384 { .name
= "TPIDR_EL0", .state
= ARM_CP_STATE_AA64
,
1385 .opc0
= 3, .opc1
= 3, .opc2
= 2, .crn
= 13, .crm
= 0,
1387 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[0]), .resetvalue
= 0 },
1388 { .name
= "TPIDRURW", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 2,
1390 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrurw_s
),
1391 offsetoflow32(CPUARMState
, cp15
.tpidrurw_ns
) },
1392 .resetfn
= arm_cp_reset_ignore
},
1393 { .name
= "TPIDRRO_EL0", .state
= ARM_CP_STATE_AA64
,
1394 .opc0
= 3, .opc1
= 3, .opc2
= 3, .crn
= 13, .crm
= 0,
1395 .access
= PL0_R
|PL1_W
,
1396 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidrro_el
[0]),
1398 { .name
= "TPIDRURO", .cp
= 15, .crn
= 13, .crm
= 0, .opc1
= 0, .opc2
= 3,
1399 .access
= PL0_R
|PL1_W
,
1400 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidruro_s
),
1401 offsetoflow32(CPUARMState
, cp15
.tpidruro_ns
) },
1402 .resetfn
= arm_cp_reset_ignore
},
1403 { .name
= "TPIDR_EL1", .state
= ARM_CP_STATE_AA64
,
1404 .opc0
= 3, .opc1
= 0, .opc2
= 4, .crn
= 13, .crm
= 0,
1406 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[1]), .resetvalue
= 0 },
1407 { .name
= "TPIDRPRW", .opc1
= 0, .cp
= 15, .crn
= 13, .crm
= 0, .opc2
= 4,
1409 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tpidrprw_s
),
1410 offsetoflow32(CPUARMState
, cp15
.tpidrprw_ns
) },
1415 #ifndef CONFIG_USER_ONLY
1417 static CPAccessResult
gt_cntfrq_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1420 /* CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero.
1421 * Writable only at the highest implemented exception level.
1423 int el
= arm_current_el(env
);
1427 if (!extract32(env
->cp15
.c14_cntkctl
, 0, 2)) {
1428 return CP_ACCESS_TRAP
;
1432 if (!isread
&& ri
->state
== ARM_CP_STATE_AA32
&&
1433 arm_is_secure_below_el3(env
)) {
1434 /* Accesses from 32-bit Secure EL1 UNDEF (*not* trap to EL3!) */
1435 return CP_ACCESS_TRAP_UNCATEGORIZED
;
1443 if (!isread
&& el
< arm_highest_el(env
)) {
1444 return CP_ACCESS_TRAP_UNCATEGORIZED
;
1447 return CP_ACCESS_OK
;
1450 static CPAccessResult
gt_counter_access(CPUARMState
*env
, int timeridx
,
1453 unsigned int cur_el
= arm_current_el(env
);
1454 bool secure
= arm_is_secure(env
);
1456 /* CNT[PV]CT: not visible from PL0 if ELO[PV]CTEN is zero */
1458 !extract32(env
->cp15
.c14_cntkctl
, timeridx
, 1)) {
1459 return CP_ACCESS_TRAP
;
1462 if (arm_feature(env
, ARM_FEATURE_EL2
) &&
1463 timeridx
== GTIMER_PHYS
&& !secure
&& cur_el
< 2 &&
1464 !extract32(env
->cp15
.cnthctl_el2
, 0, 1)) {
1465 return CP_ACCESS_TRAP_EL2
;
1467 return CP_ACCESS_OK
;
1470 static CPAccessResult
gt_timer_access(CPUARMState
*env
, int timeridx
,
1473 unsigned int cur_el
= arm_current_el(env
);
1474 bool secure
= arm_is_secure(env
);
1476 /* CNT[PV]_CVAL, CNT[PV]_CTL, CNT[PV]_TVAL: not visible from PL0 if
1477 * EL0[PV]TEN is zero.
1480 !extract32(env
->cp15
.c14_cntkctl
, 9 - timeridx
, 1)) {
1481 return CP_ACCESS_TRAP
;
1484 if (arm_feature(env
, ARM_FEATURE_EL2
) &&
1485 timeridx
== GTIMER_PHYS
&& !secure
&& cur_el
< 2 &&
1486 !extract32(env
->cp15
.cnthctl_el2
, 1, 1)) {
1487 return CP_ACCESS_TRAP_EL2
;
1489 return CP_ACCESS_OK
;
1492 static CPAccessResult
gt_pct_access(CPUARMState
*env
,
1493 const ARMCPRegInfo
*ri
,
1496 return gt_counter_access(env
, GTIMER_PHYS
, isread
);
1499 static CPAccessResult
gt_vct_access(CPUARMState
*env
,
1500 const ARMCPRegInfo
*ri
,
1503 return gt_counter_access(env
, GTIMER_VIRT
, isread
);
1506 static CPAccessResult
gt_ptimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1509 return gt_timer_access(env
, GTIMER_PHYS
, isread
);
1512 static CPAccessResult
gt_vtimer_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1515 return gt_timer_access(env
, GTIMER_VIRT
, isread
);
1518 static CPAccessResult
gt_stimer_access(CPUARMState
*env
,
1519 const ARMCPRegInfo
*ri
,
1522 /* The AArch64 register view of the secure physical timer is
1523 * always accessible from EL3, and configurably accessible from
1526 switch (arm_current_el(env
)) {
1528 if (!arm_is_secure(env
)) {
1529 return CP_ACCESS_TRAP
;
1531 if (!(env
->cp15
.scr_el3
& SCR_ST
)) {
1532 return CP_ACCESS_TRAP_EL3
;
1534 return CP_ACCESS_OK
;
1537 return CP_ACCESS_TRAP
;
1539 return CP_ACCESS_OK
;
1541 g_assert_not_reached();
1545 static uint64_t gt_get_countervalue(CPUARMState
*env
)
1547 return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) / GTIMER_SCALE
;
1550 static void gt_recalc_timer(ARMCPU
*cpu
, int timeridx
)
1552 ARMGenericTimer
*gt
= &cpu
->env
.cp15
.c14_timer
[timeridx
];
1555 /* Timer enabled: calculate and set current ISTATUS, irq, and
1556 * reset timer to when ISTATUS next has to change
1558 uint64_t offset
= timeridx
== GTIMER_VIRT
?
1559 cpu
->env
.cp15
.cntvoff_el2
: 0;
1560 uint64_t count
= gt_get_countervalue(&cpu
->env
);
1561 /* Note that this must be unsigned 64 bit arithmetic: */
1562 int istatus
= count
- offset
>= gt
->cval
;
1566 gt
->ctl
= deposit32(gt
->ctl
, 2, 1, istatus
);
1568 irqstate
= (istatus
&& !(gt
->ctl
& 2));
1569 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], irqstate
);
1572 /* Next transition is when count rolls back over to zero */
1573 nexttick
= UINT64_MAX
;
1575 /* Next transition is when we hit cval */
1576 nexttick
= gt
->cval
+ offset
;
1578 /* Note that the desired next expiry time might be beyond the
1579 * signed-64-bit range of a QEMUTimer -- in this case we just
1580 * set the timer for as far in the future as possible. When the
1581 * timer expires we will reset the timer for any remaining period.
1583 if (nexttick
> INT64_MAX
/ GTIMER_SCALE
) {
1584 nexttick
= INT64_MAX
/ GTIMER_SCALE
;
1586 timer_mod(cpu
->gt_timer
[timeridx
], nexttick
);
1587 trace_arm_gt_recalc(timeridx
, irqstate
, nexttick
);
1589 /* Timer disabled: ISTATUS and timer output always clear */
1591 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], 0);
1592 timer_del(cpu
->gt_timer
[timeridx
]);
1593 trace_arm_gt_recalc_disabled(timeridx
);
1597 static void gt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1600 ARMCPU
*cpu
= arm_env_get_cpu(env
);
1602 timer_del(cpu
->gt_timer
[timeridx
]);
1605 static uint64_t gt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1607 return gt_get_countervalue(env
);
1610 static uint64_t gt_virt_cnt_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1612 return gt_get_countervalue(env
) - env
->cp15
.cntvoff_el2
;
1615 static void gt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1619 trace_arm_gt_cval_write(timeridx
, value
);
1620 env
->cp15
.c14_timer
[timeridx
].cval
= value
;
1621 gt_recalc_timer(arm_env_get_cpu(env
), timeridx
);
1624 static uint64_t gt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1627 uint64_t offset
= timeridx
== GTIMER_VIRT
? env
->cp15
.cntvoff_el2
: 0;
1629 return (uint32_t)(env
->cp15
.c14_timer
[timeridx
].cval
-
1630 (gt_get_countervalue(env
) - offset
));
1633 static void gt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1637 uint64_t offset
= timeridx
== GTIMER_VIRT
? env
->cp15
.cntvoff_el2
: 0;
1639 trace_arm_gt_tval_write(timeridx
, value
);
1640 env
->cp15
.c14_timer
[timeridx
].cval
= gt_get_countervalue(env
) - offset
+
1641 sextract64(value
, 0, 32);
1642 gt_recalc_timer(arm_env_get_cpu(env
), timeridx
);
1645 static void gt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1649 ARMCPU
*cpu
= arm_env_get_cpu(env
);
1650 uint32_t oldval
= env
->cp15
.c14_timer
[timeridx
].ctl
;
1652 trace_arm_gt_ctl_write(timeridx
, value
);
1653 env
->cp15
.c14_timer
[timeridx
].ctl
= deposit64(oldval
, 0, 2, value
);
1654 if ((oldval
^ value
) & 1) {
1655 /* Enable toggled */
1656 gt_recalc_timer(cpu
, timeridx
);
1657 } else if ((oldval
^ value
) & 2) {
1658 /* IMASK toggled: don't need to recalculate,
1659 * just set the interrupt line based on ISTATUS
1661 int irqstate
= (oldval
& 4) && !(value
& 2);
1663 trace_arm_gt_imask_toggle(timeridx
, irqstate
);
1664 qemu_set_irq(cpu
->gt_timer_outputs
[timeridx
], irqstate
);
1668 static void gt_phys_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1670 gt_timer_reset(env
, ri
, GTIMER_PHYS
);
1673 static void gt_phys_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1676 gt_cval_write(env
, ri
, GTIMER_PHYS
, value
);
1679 static uint64_t gt_phys_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1681 return gt_tval_read(env
, ri
, GTIMER_PHYS
);
1684 static void gt_phys_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1687 gt_tval_write(env
, ri
, GTIMER_PHYS
, value
);
1690 static void gt_phys_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1693 gt_ctl_write(env
, ri
, GTIMER_PHYS
, value
);
1696 static void gt_virt_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1698 gt_timer_reset(env
, ri
, GTIMER_VIRT
);
1701 static void gt_virt_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1704 gt_cval_write(env
, ri
, GTIMER_VIRT
, value
);
1707 static uint64_t gt_virt_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1709 return gt_tval_read(env
, ri
, GTIMER_VIRT
);
1712 static void gt_virt_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1715 gt_tval_write(env
, ri
, GTIMER_VIRT
, value
);
1718 static void gt_virt_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1721 gt_ctl_write(env
, ri
, GTIMER_VIRT
, value
);
1724 static void gt_cntvoff_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1727 ARMCPU
*cpu
= arm_env_get_cpu(env
);
1729 trace_arm_gt_cntvoff_write(value
);
1730 raw_write(env
, ri
, value
);
1731 gt_recalc_timer(cpu
, GTIMER_VIRT
);
1734 static void gt_hyp_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1736 gt_timer_reset(env
, ri
, GTIMER_HYP
);
1739 static void gt_hyp_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1742 gt_cval_write(env
, ri
, GTIMER_HYP
, value
);
1745 static uint64_t gt_hyp_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1747 return gt_tval_read(env
, ri
, GTIMER_HYP
);
1750 static void gt_hyp_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1753 gt_tval_write(env
, ri
, GTIMER_HYP
, value
);
1756 static void gt_hyp_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1759 gt_ctl_write(env
, ri
, GTIMER_HYP
, value
);
1762 static void gt_sec_timer_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1764 gt_timer_reset(env
, ri
, GTIMER_SEC
);
1767 static void gt_sec_cval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1770 gt_cval_write(env
, ri
, GTIMER_SEC
, value
);
1773 static uint64_t gt_sec_tval_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
1775 return gt_tval_read(env
, ri
, GTIMER_SEC
);
1778 static void gt_sec_tval_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1781 gt_tval_write(env
, ri
, GTIMER_SEC
, value
);
1784 static void gt_sec_ctl_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
1787 gt_ctl_write(env
, ri
, GTIMER_SEC
, value
);
1790 void arm_gt_ptimer_cb(void *opaque
)
1792 ARMCPU
*cpu
= opaque
;
1794 gt_recalc_timer(cpu
, GTIMER_PHYS
);
1797 void arm_gt_vtimer_cb(void *opaque
)
1799 ARMCPU
*cpu
= opaque
;
1801 gt_recalc_timer(cpu
, GTIMER_VIRT
);
1804 void arm_gt_htimer_cb(void *opaque
)
1806 ARMCPU
*cpu
= opaque
;
1808 gt_recalc_timer(cpu
, GTIMER_HYP
);
1811 void arm_gt_stimer_cb(void *opaque
)
1813 ARMCPU
*cpu
= opaque
;
1815 gt_recalc_timer(cpu
, GTIMER_SEC
);
1818 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
1819 /* Note that CNTFRQ is purely reads-as-written for the benefit
1820 * of software; writing it doesn't actually change the timer frequency.
1821 * Our reset value matches the fixed frequency we implement the timer at.
1823 { .name
= "CNTFRQ", .cp
= 15, .crn
= 14, .crm
= 0, .opc1
= 0, .opc2
= 0,
1824 .type
= ARM_CP_ALIAS
,
1825 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
1826 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c14_cntfrq
),
1828 { .name
= "CNTFRQ_EL0", .state
= ARM_CP_STATE_AA64
,
1829 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 0,
1830 .access
= PL1_RW
| PL0_R
, .accessfn
= gt_cntfrq_access
,
1831 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntfrq
),
1832 .resetvalue
= (1000 * 1000 * 1000) / GTIMER_SCALE
,
1834 /* overall control: mostly access permissions */
1835 { .name
= "CNTKCTL", .state
= ARM_CP_STATE_BOTH
,
1836 .opc0
= 3, .opc1
= 0, .crn
= 14, .crm
= 1, .opc2
= 0,
1838 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_cntkctl
),
1841 /* per-timer control */
1842 { .name
= "CNTP_CTL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
1843 .secure
= ARM_CP_SECSTATE_NS
,
1844 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL1_RW
| PL0_R
,
1845 .accessfn
= gt_ptimer_access
,
1846 .fieldoffset
= offsetoflow32(CPUARMState
,
1847 cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
1848 .writefn
= gt_phys_ctl_write
, .raw_writefn
= raw_write
,
1850 { .name
= "CNTP_CTL(S)",
1851 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 1,
1852 .secure
= ARM_CP_SECSTATE_S
,
1853 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL1_RW
| PL0_R
,
1854 .accessfn
= gt_ptimer_access
,
1855 .fieldoffset
= offsetoflow32(CPUARMState
,
1856 cp15
.c14_timer
[GTIMER_SEC
].ctl
),
1857 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
1859 { .name
= "CNTP_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
1860 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 1,
1861 .type
= ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1862 .accessfn
= gt_ptimer_access
,
1863 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].ctl
),
1865 .writefn
= gt_phys_ctl_write
, .raw_writefn
= raw_write
,
1867 { .name
= "CNTV_CTL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 1,
1868 .type
= ARM_CP_IO
| ARM_CP_ALIAS
, .access
= PL1_RW
| PL0_R
,
1869 .accessfn
= gt_vtimer_access
,
1870 .fieldoffset
= offsetoflow32(CPUARMState
,
1871 cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
1872 .writefn
= gt_virt_ctl_write
, .raw_writefn
= raw_write
,
1874 { .name
= "CNTV_CTL_EL0", .state
= ARM_CP_STATE_AA64
,
1875 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 1,
1876 .type
= ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1877 .accessfn
= gt_vtimer_access
,
1878 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].ctl
),
1880 .writefn
= gt_virt_ctl_write
, .raw_writefn
= raw_write
,
1882 /* TimerValue views: a 32 bit downcounting view of the underlying state */
1883 { .name
= "CNTP_TVAL", .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
1884 .secure
= ARM_CP_SECSTATE_NS
,
1885 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1886 .accessfn
= gt_ptimer_access
,
1887 .readfn
= gt_phys_tval_read
, .writefn
= gt_phys_tval_write
,
1889 { .name
= "CNTP_TVAL(S)",
1890 .cp
= 15, .crn
= 14, .crm
= 2, .opc1
= 0, .opc2
= 0,
1891 .secure
= ARM_CP_SECSTATE_S
,
1892 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1893 .accessfn
= gt_ptimer_access
,
1894 .readfn
= gt_sec_tval_read
, .writefn
= gt_sec_tval_write
,
1896 { .name
= "CNTP_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
1897 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 0,
1898 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1899 .accessfn
= gt_ptimer_access
, .resetfn
= gt_phys_timer_reset
,
1900 .readfn
= gt_phys_tval_read
, .writefn
= gt_phys_tval_write
,
1902 { .name
= "CNTV_TVAL", .cp
= 15, .crn
= 14, .crm
= 3, .opc1
= 0, .opc2
= 0,
1903 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1904 .accessfn
= gt_vtimer_access
,
1905 .readfn
= gt_virt_tval_read
, .writefn
= gt_virt_tval_write
,
1907 { .name
= "CNTV_TVAL_EL0", .state
= ARM_CP_STATE_AA64
,
1908 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 0,
1909 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
| PL0_R
,
1910 .accessfn
= gt_vtimer_access
, .resetfn
= gt_virt_timer_reset
,
1911 .readfn
= gt_virt_tval_read
, .writefn
= gt_virt_tval_write
,
1913 /* The counter itself */
1914 { .name
= "CNTPCT", .cp
= 15, .crm
= 14, .opc1
= 0,
1915 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
1916 .accessfn
= gt_pct_access
,
1917 .readfn
= gt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
1919 { .name
= "CNTPCT_EL0", .state
= ARM_CP_STATE_AA64
,
1920 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 1,
1921 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
1922 .accessfn
= gt_pct_access
, .readfn
= gt_cnt_read
,
1924 { .name
= "CNTVCT", .cp
= 15, .crm
= 14, .opc1
= 1,
1925 .access
= PL0_R
, .type
= ARM_CP_64BIT
| ARM_CP_NO_RAW
| ARM_CP_IO
,
1926 .accessfn
= gt_vct_access
,
1927 .readfn
= gt_virt_cnt_read
, .resetfn
= arm_cp_reset_ignore
,
1929 { .name
= "CNTVCT_EL0", .state
= ARM_CP_STATE_AA64
,
1930 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 0, .opc2
= 2,
1931 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
| ARM_CP_IO
,
1932 .accessfn
= gt_vct_access
, .readfn
= gt_virt_cnt_read
,
1934 /* Comparison value, indicating when the timer goes off */
1935 { .name
= "CNTP_CVAL", .cp
= 15, .crm
= 14, .opc1
= 2,
1936 .secure
= ARM_CP_SECSTATE_NS
,
1937 .access
= PL1_RW
| PL0_R
,
1938 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
1939 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
1940 .accessfn
= gt_ptimer_access
,
1941 .writefn
= gt_phys_cval_write
, .raw_writefn
= raw_write
,
1943 { .name
= "CNTP_CVAL(S)", .cp
= 15, .crm
= 14, .opc1
= 2,
1944 .secure
= ARM_CP_SECSTATE_S
,
1945 .access
= PL1_RW
| PL0_R
,
1946 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
1947 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
1948 .accessfn
= gt_ptimer_access
,
1949 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
1951 { .name
= "CNTP_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
1952 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 2, .opc2
= 2,
1953 .access
= PL1_RW
| PL0_R
,
1955 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_PHYS
].cval
),
1956 .resetvalue
= 0, .accessfn
= gt_ptimer_access
,
1957 .writefn
= gt_phys_cval_write
, .raw_writefn
= raw_write
,
1959 { .name
= "CNTV_CVAL", .cp
= 15, .crm
= 14, .opc1
= 3,
1960 .access
= PL1_RW
| PL0_R
,
1961 .type
= ARM_CP_64BIT
| ARM_CP_IO
| ARM_CP_ALIAS
,
1962 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
1963 .accessfn
= gt_vtimer_access
,
1964 .writefn
= gt_virt_cval_write
, .raw_writefn
= raw_write
,
1966 { .name
= "CNTV_CVAL_EL0", .state
= ARM_CP_STATE_AA64
,
1967 .opc0
= 3, .opc1
= 3, .crn
= 14, .crm
= 3, .opc2
= 2,
1968 .access
= PL1_RW
| PL0_R
,
1970 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_VIRT
].cval
),
1971 .resetvalue
= 0, .accessfn
= gt_vtimer_access
,
1972 .writefn
= gt_virt_cval_write
, .raw_writefn
= raw_write
,
1974 /* Secure timer -- this is actually restricted to only EL3
1975 * and configurably Secure-EL1 via the accessfn.
1977 { .name
= "CNTPS_TVAL_EL1", .state
= ARM_CP_STATE_AA64
,
1978 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 0,
1979 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL1_RW
,
1980 .accessfn
= gt_stimer_access
,
1981 .readfn
= gt_sec_tval_read
,
1982 .writefn
= gt_sec_tval_write
,
1983 .resetfn
= gt_sec_timer_reset
,
1985 { .name
= "CNTPS_CTL_EL1", .state
= ARM_CP_STATE_AA64
,
1986 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 1,
1987 .type
= ARM_CP_IO
, .access
= PL1_RW
,
1988 .accessfn
= gt_stimer_access
,
1989 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].ctl
),
1991 .writefn
= gt_sec_ctl_write
, .raw_writefn
= raw_write
,
1993 { .name
= "CNTPS_CVAL_EL1", .state
= ARM_CP_STATE_AA64
,
1994 .opc0
= 3, .opc1
= 7, .crn
= 14, .crm
= 2, .opc2
= 2,
1995 .type
= ARM_CP_IO
, .access
= PL1_RW
,
1996 .accessfn
= gt_stimer_access
,
1997 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_SEC
].cval
),
1998 .writefn
= gt_sec_cval_write
, .raw_writefn
= raw_write
,
2004 /* In user-mode none of the generic timer registers are accessible,
2005 * and their implementation depends on QEMU_CLOCK_VIRTUAL and qdev gpio outputs,
2006 * so instead just don't register any of them.
2008 static const ARMCPRegInfo generic_timer_cp_reginfo
[] = {
2014 static void par_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
2016 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
2017 raw_write(env
, ri
, value
);
2018 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
2019 raw_write(env
, ri
, value
& 0xfffff6ff);
2021 raw_write(env
, ri
, value
& 0xfffff1ff);
2025 #ifndef CONFIG_USER_ONLY
2026 /* get_phys_addr() isn't present for user-mode-only targets */
2028 static CPAccessResult
ats_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2032 /* The ATS12NSO* operations must trap to EL3 if executed in
2033 * Secure EL1 (which can only happen if EL3 is AArch64).
2034 * They are simply UNDEF if executed from NS EL1.
2035 * They function normally from EL2 or EL3.
2037 if (arm_current_el(env
) == 1) {
2038 if (arm_is_secure_below_el3(env
)) {
2039 return CP_ACCESS_TRAP_UNCATEGORIZED_EL3
;
2041 return CP_ACCESS_TRAP_UNCATEGORIZED
;
2044 return CP_ACCESS_OK
;
2047 static uint64_t do_ats_write(CPUARMState
*env
, uint64_t value
,
2048 int access_type
, ARMMMUIdx mmu_idx
)
2051 target_ulong page_size
;
2056 MemTxAttrs attrs
= {};
2057 ARMMMUFaultInfo fi
= {};
2059 ret
= get_phys_addr(env
, value
, access_type
, mmu_idx
,
2060 &phys_addr
, &attrs
, &prot
, &page_size
, &fsr
, &fi
);
2061 if (extended_addresses_enabled(env
)) {
2062 /* fsr is a DFSR/IFSR value for the long descriptor
2063 * translation table format, but with WnR always clear.
2064 * Convert it to a 64-bit PAR.
2066 par64
= (1 << 11); /* LPAE bit always set */
2068 par64
|= phys_addr
& ~0xfffULL
;
2069 if (!attrs
.secure
) {
2070 par64
|= (1 << 9); /* NS */
2072 /* We don't set the ATTR or SH fields in the PAR. */
2075 par64
|= (fsr
& 0x3f) << 1; /* FS */
2076 /* Note that S2WLK and FSTAGE are always zero, because we don't
2077 * implement virtualization and therefore there can't be a stage 2
2082 /* fsr is a DFSR/IFSR value for the short descriptor
2083 * translation table format (with WnR always clear).
2084 * Convert it to a 32-bit PAR.
2087 /* We do not set any attribute bits in the PAR */
2088 if (page_size
== (1 << 24)
2089 && arm_feature(env
, ARM_FEATURE_V7
)) {
2090 par64
= (phys_addr
& 0xff000000) | (1 << 1);
2092 par64
= phys_addr
& 0xfffff000;
2094 if (!attrs
.secure
) {
2095 par64
|= (1 << 9); /* NS */
2098 par64
= ((fsr
& (1 << 10)) >> 5) | ((fsr
& (1 << 12)) >> 6) |
2099 ((fsr
& 0xf) << 1) | 1;
2105 static void ats_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
2107 int access_type
= ri
->opc2
& 1;
2110 int el
= arm_current_el(env
);
2111 bool secure
= arm_is_secure_below_el3(env
);
2113 switch (ri
->opc2
& 6) {
2115 /* stage 1 current state PL1: ATS1CPR, ATS1CPW */
2118 mmu_idx
= ARMMMUIdx_S1E3
;
2121 mmu_idx
= ARMMMUIdx_S1NSE1
;
2124 mmu_idx
= secure
? ARMMMUIdx_S1SE1
: ARMMMUIdx_S1NSE1
;
2127 g_assert_not_reached();
2131 /* stage 1 current state PL0: ATS1CUR, ATS1CUW */
2134 mmu_idx
= ARMMMUIdx_S1SE0
;
2137 mmu_idx
= ARMMMUIdx_S1NSE0
;
2140 mmu_idx
= secure
? ARMMMUIdx_S1SE0
: ARMMMUIdx_S1NSE0
;
2143 g_assert_not_reached();
2147 /* stage 1+2 NonSecure PL1: ATS12NSOPR, ATS12NSOPW */
2148 mmu_idx
= ARMMMUIdx_S12NSE1
;
2151 /* stage 1+2 NonSecure PL0: ATS12NSOUR, ATS12NSOUW */
2152 mmu_idx
= ARMMMUIdx_S12NSE0
;
2155 g_assert_not_reached();
2158 par64
= do_ats_write(env
, value
, access_type
, mmu_idx
);
2160 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
2163 static void ats1h_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2166 int access_type
= ri
->opc2
& 1;
2169 par64
= do_ats_write(env
, value
, access_type
, ARMMMUIdx_S2NS
);
2171 A32_BANKED_CURRENT_REG_SET(env
, par
, par64
);
2174 static CPAccessResult
at_s1e2_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2177 if (arm_current_el(env
) == 3 && !(env
->cp15
.scr_el3
& SCR_NS
)) {
2178 return CP_ACCESS_TRAP
;
2180 return CP_ACCESS_OK
;
2183 static void ats_write64(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2186 int access_type
= ri
->opc2
& 1;
2188 int secure
= arm_is_secure_below_el3(env
);
2190 switch (ri
->opc2
& 6) {
2193 case 0: /* AT S1E1R, AT S1E1W */
2194 mmu_idx
= secure
? ARMMMUIdx_S1SE1
: ARMMMUIdx_S1NSE1
;
2196 case 4: /* AT S1E2R, AT S1E2W */
2197 mmu_idx
= ARMMMUIdx_S1E2
;
2199 case 6: /* AT S1E3R, AT S1E3W */
2200 mmu_idx
= ARMMMUIdx_S1E3
;
2203 g_assert_not_reached();
2206 case 2: /* AT S1E0R, AT S1E0W */
2207 mmu_idx
= secure
? ARMMMUIdx_S1SE0
: ARMMMUIdx_S1NSE0
;
2209 case 4: /* AT S12E1R, AT S12E1W */
2210 mmu_idx
= secure
? ARMMMUIdx_S1SE1
: ARMMMUIdx_S12NSE1
;
2212 case 6: /* AT S12E0R, AT S12E0W */
2213 mmu_idx
= secure
? ARMMMUIdx_S1SE0
: ARMMMUIdx_S12NSE0
;
2216 g_assert_not_reached();
2219 env
->cp15
.par_el
[1] = do_ats_write(env
, value
, access_type
, mmu_idx
);
2223 static const ARMCPRegInfo vapa_cp_reginfo
[] = {
2224 { .name
= "PAR", .cp
= 15, .crn
= 7, .crm
= 4, .opc1
= 0, .opc2
= 0,
2225 .access
= PL1_RW
, .resetvalue
= 0,
2226 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.par_s
),
2227 offsetoflow32(CPUARMState
, cp15
.par_ns
) },
2228 .writefn
= par_write
},
2229 #ifndef CONFIG_USER_ONLY
2230 /* This underdecoding is safe because the reginfo is NO_RAW. */
2231 { .name
= "ATS", .cp
= 15, .crn
= 7, .crm
= 8, .opc1
= 0, .opc2
= CP_ANY
,
2232 .access
= PL1_W
, .accessfn
= ats_access
,
2233 .writefn
= ats_write
, .type
= ARM_CP_NO_RAW
},
2238 /* Return basic MPU access permission bits. */
2239 static uint32_t simple_mpu_ap_bits(uint32_t val
)
2246 for (i
= 0; i
< 16; i
+= 2) {
2247 ret
|= (val
>> i
) & mask
;
2253 /* Pad basic MPU access permission bits to extended format. */
2254 static uint32_t extended_mpu_ap_bits(uint32_t val
)
2261 for (i
= 0; i
< 16; i
+= 2) {
2262 ret
|= (val
& mask
) << i
;
2268 static void pmsav5_data_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2271 env
->cp15
.pmsav5_data_ap
= extended_mpu_ap_bits(value
);
2274 static uint64_t pmsav5_data_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2276 return simple_mpu_ap_bits(env
->cp15
.pmsav5_data_ap
);
2279 static void pmsav5_insn_ap_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2282 env
->cp15
.pmsav5_insn_ap
= extended_mpu_ap_bits(value
);
2285 static uint64_t pmsav5_insn_ap_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2287 return simple_mpu_ap_bits(env
->cp15
.pmsav5_insn_ap
);
2290 static uint64_t pmsav7_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2292 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
2298 u32p
+= env
->cp15
.c6_rgnr
;
2302 static void pmsav7_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2305 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2306 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
2312 u32p
+= env
->cp15
.c6_rgnr
;
2313 tlb_flush(CPU(cpu
), 1); /* Mappings may have changed - purge! */
2317 static void pmsav7_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2319 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2320 uint32_t *u32p
= *(uint32_t **)raw_ptr(env
, ri
);
2326 memset(u32p
, 0, sizeof(*u32p
) * cpu
->pmsav7_dregion
);
2329 static void pmsav7_rgnr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2332 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2333 uint32_t nrgs
= cpu
->pmsav7_dregion
;
2335 if (value
>= nrgs
) {
2336 qemu_log_mask(LOG_GUEST_ERROR
,
2337 "PMSAv7 RGNR write >= # supported regions, %" PRIu32
2338 " > %" PRIu32
"\n", (uint32_t)value
, nrgs
);
2342 raw_write(env
, ri
, value
);
2345 static const ARMCPRegInfo pmsav7_cp_reginfo
[] = {
2346 { .name
= "DRBAR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 0,
2347 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
2348 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drbar
),
2349 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
, .resetfn
= pmsav7_reset
},
2350 { .name
= "DRSR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 2,
2351 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
2352 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.drsr
),
2353 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
, .resetfn
= pmsav7_reset
},
2354 { .name
= "DRACR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 1, .opc2
= 4,
2355 .access
= PL1_RW
, .type
= ARM_CP_NO_RAW
,
2356 .fieldoffset
= offsetof(CPUARMState
, pmsav7
.dracr
),
2357 .readfn
= pmsav7_read
, .writefn
= pmsav7_write
, .resetfn
= pmsav7_reset
},
2358 { .name
= "RGNR", .cp
= 15, .crn
= 6, .opc1
= 0, .crm
= 2, .opc2
= 0,
2360 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_rgnr
),
2361 .writefn
= pmsav7_rgnr_write
},
2365 static const ARMCPRegInfo pmsav5_cp_reginfo
[] = {
2366 { .name
= "DATA_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
2367 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
2368 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
2369 .readfn
= pmsav5_data_ap_read
, .writefn
= pmsav5_data_ap_write
, },
2370 { .name
= "INSN_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
2371 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
2372 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
2373 .readfn
= pmsav5_insn_ap_read
, .writefn
= pmsav5_insn_ap_write
, },
2374 { .name
= "DATA_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 2,
2376 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_data_ap
),
2378 { .name
= "INSN_EXT_AP", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 3,
2380 .fieldoffset
= offsetof(CPUARMState
, cp15
.pmsav5_insn_ap
),
2382 { .name
= "DCACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 0,
2384 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_data
), .resetvalue
= 0, },
2385 { .name
= "ICACHE_CFG", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 1,
2387 .fieldoffset
= offsetof(CPUARMState
, cp15
.c2_insn
), .resetvalue
= 0, },
2388 /* Protection region base and size registers */
2389 { .name
= "946_PRBS0", .cp
= 15, .crn
= 6, .crm
= 0, .opc1
= 0,
2390 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2391 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[0]) },
2392 { .name
= "946_PRBS1", .cp
= 15, .crn
= 6, .crm
= 1, .opc1
= 0,
2393 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2394 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[1]) },
2395 { .name
= "946_PRBS2", .cp
= 15, .crn
= 6, .crm
= 2, .opc1
= 0,
2396 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2397 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[2]) },
2398 { .name
= "946_PRBS3", .cp
= 15, .crn
= 6, .crm
= 3, .opc1
= 0,
2399 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2400 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[3]) },
2401 { .name
= "946_PRBS4", .cp
= 15, .crn
= 6, .crm
= 4, .opc1
= 0,
2402 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2403 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[4]) },
2404 { .name
= "946_PRBS5", .cp
= 15, .crn
= 6, .crm
= 5, .opc1
= 0,
2405 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2406 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[5]) },
2407 { .name
= "946_PRBS6", .cp
= 15, .crn
= 6, .crm
= 6, .opc1
= 0,
2408 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2409 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[6]) },
2410 { .name
= "946_PRBS7", .cp
= 15, .crn
= 6, .crm
= 7, .opc1
= 0,
2411 .opc2
= CP_ANY
, .access
= PL1_RW
, .resetvalue
= 0,
2412 .fieldoffset
= offsetof(CPUARMState
, cp15
.c6_region
[7]) },
2416 static void vmsa_ttbcr_raw_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2419 TCR
*tcr
= raw_ptr(env
, ri
);
2420 int maskshift
= extract32(value
, 0, 3);
2422 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
2423 if (arm_feature(env
, ARM_FEATURE_LPAE
) && (value
& TTBCR_EAE
)) {
2424 /* Pre ARMv8 bits [21:19], [15:14] and [6:3] are UNK/SBZP when
2425 * using Long-desciptor translation table format */
2426 value
&= ~((7 << 19) | (3 << 14) | (0xf << 3));
2427 } else if (arm_feature(env
, ARM_FEATURE_EL3
)) {
2428 /* In an implementation that includes the Security Extensions
2429 * TTBCR has additional fields PD0 [4] and PD1 [5] for
2430 * Short-descriptor translation table format.
2432 value
&= TTBCR_PD1
| TTBCR_PD0
| TTBCR_N
;
2438 /* Update the masks corresponding to the TCR bank being written
2439 * Note that we always calculate mask and base_mask, but
2440 * they are only used for short-descriptor tables (ie if EAE is 0);
2441 * for long-descriptor tables the TCR fields are used differently
2442 * and the mask and base_mask values are meaningless.
2444 tcr
->raw_tcr
= value
;
2445 tcr
->mask
= ~(((uint32_t)0xffffffffu
) >> maskshift
);
2446 tcr
->base_mask
= ~((uint32_t)0x3fffu
>> maskshift
);
2449 static void vmsa_ttbcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2452 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2454 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
2455 /* With LPAE the TTBCR could result in a change of ASID
2456 * via the TTBCR.A1 bit, so do a TLB flush.
2458 tlb_flush(CPU(cpu
), 1);
2460 vmsa_ttbcr_raw_write(env
, ri
, value
);
2463 static void vmsa_ttbcr_reset(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2465 TCR
*tcr
= raw_ptr(env
, ri
);
2467 /* Reset both the TCR as well as the masks corresponding to the bank of
2468 * the TCR being reset.
2472 tcr
->base_mask
= 0xffffc000u
;
2475 static void vmsa_tcr_el1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2478 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2479 TCR
*tcr
= raw_ptr(env
, ri
);
2481 /* For AArch64 the A1 bit could result in a change of ASID, so TLB flush. */
2482 tlb_flush(CPU(cpu
), 1);
2483 tcr
->raw_tcr
= value
;
2486 static void vmsa_ttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2489 /* 64 bit accesses to the TTBRs can change the ASID and so we
2490 * must flush the TLB.
2492 if (cpreg_field_is_64bit(ri
)) {
2493 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2495 tlb_flush(CPU(cpu
), 1);
2497 raw_write(env
, ri
, value
);
2500 static void vttbr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2503 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2504 CPUState
*cs
= CPU(cpu
);
2506 /* Accesses to VTTBR may change the VMID so we must flush the TLB. */
2507 if (raw_read(env
, ri
) != value
) {
2508 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S12NSE1
, ARMMMUIdx_S12NSE0
,
2509 ARMMMUIdx_S2NS
, -1);
2510 raw_write(env
, ri
, value
);
2514 static const ARMCPRegInfo vmsa_pmsa_cp_reginfo
[] = {
2515 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 0,
2516 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
,
2517 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dfsr_s
),
2518 offsetoflow32(CPUARMState
, cp15
.dfsr_ns
) }, },
2519 { .name
= "IFSR", .cp
= 15, .crn
= 5, .crm
= 0, .opc1
= 0, .opc2
= 1,
2520 .access
= PL1_RW
, .resetvalue
= 0,
2521 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.ifsr_s
),
2522 offsetoflow32(CPUARMState
, cp15
.ifsr_ns
) } },
2523 { .name
= "DFAR", .cp
= 15, .opc1
= 0, .crn
= 6, .crm
= 0, .opc2
= 0,
2524 .access
= PL1_RW
, .resetvalue
= 0,
2525 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.dfar_s
),
2526 offsetof(CPUARMState
, cp15
.dfar_ns
) } },
2527 { .name
= "FAR_EL1", .state
= ARM_CP_STATE_AA64
,
2528 .opc0
= 3, .crn
= 6, .crm
= 0, .opc1
= 0, .opc2
= 0,
2529 .access
= PL1_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[1]),
2534 static const ARMCPRegInfo vmsa_cp_reginfo
[] = {
2535 { .name
= "ESR_EL1", .state
= ARM_CP_STATE_AA64
,
2536 .opc0
= 3, .crn
= 5, .crm
= 2, .opc1
= 0, .opc2
= 0,
2538 .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[1]), .resetvalue
= 0, },
2539 { .name
= "TTBR0_EL1", .state
= ARM_CP_STATE_BOTH
,
2540 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 0,
2541 .access
= PL1_RW
, .writefn
= vmsa_ttbr_write
, .resetvalue
= 0,
2542 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
2543 offsetof(CPUARMState
, cp15
.ttbr0_ns
) } },
2544 { .name
= "TTBR1_EL1", .state
= ARM_CP_STATE_BOTH
,
2545 .opc0
= 3, .opc1
= 0, .crn
= 2, .crm
= 0, .opc2
= 1,
2546 .access
= PL1_RW
, .writefn
= vmsa_ttbr_write
, .resetvalue
= 0,
2547 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
2548 offsetof(CPUARMState
, cp15
.ttbr1_ns
) } },
2549 { .name
= "TCR_EL1", .state
= ARM_CP_STATE_AA64
,
2550 .opc0
= 3, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
2551 .access
= PL1_RW
, .writefn
= vmsa_tcr_el1_write
,
2552 .resetfn
= vmsa_ttbcr_reset
, .raw_writefn
= raw_write
,
2553 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[1]) },
2554 { .name
= "TTBCR", .cp
= 15, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 2,
2555 .access
= PL1_RW
, .type
= ARM_CP_ALIAS
, .writefn
= vmsa_ttbcr_write
,
2556 .raw_writefn
= vmsa_ttbcr_raw_write
,
2557 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.tcr_el
[3]),
2558 offsetoflow32(CPUARMState
, cp15
.tcr_el
[1])} },
2562 static void omap_ticonfig_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2565 env
->cp15
.c15_ticonfig
= value
& 0xe7;
2566 /* The OS_TYPE bit in this register changes the reported CPUID! */
2567 env
->cp15
.c0_cpuid
= (value
& (1 << 5)) ?
2568 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
2571 static void omap_threadid_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2574 env
->cp15
.c15_threadid
= value
& 0xffff;
2577 static void omap_wfi_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2580 /* Wait-for-interrupt (deprecated) */
2581 cpu_interrupt(CPU(arm_env_get_cpu(env
)), CPU_INTERRUPT_HALT
);
2584 static void omap_cachemaint_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2587 /* On OMAP there are registers indicating the max/min index of dcache lines
2588 * containing a dirty line; cache flush operations have to reset these.
2590 env
->cp15
.c15_i_max
= 0x000;
2591 env
->cp15
.c15_i_min
= 0xff0;
2594 static const ARMCPRegInfo omap_cp_reginfo
[] = {
2595 { .name
= "DFSR", .cp
= 15, .crn
= 5, .crm
= CP_ANY
,
2596 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
, .type
= ARM_CP_OVERRIDE
,
2597 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.esr_el
[1]),
2599 { .name
= "", .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 0, .opc2
= 0,
2600 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
2601 { .name
= "TICONFIG", .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0,
2603 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_ticonfig
), .resetvalue
= 0,
2604 .writefn
= omap_ticonfig_write
},
2605 { .name
= "IMAX", .cp
= 15, .crn
= 15, .crm
= 2, .opc1
= 0, .opc2
= 0,
2607 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_max
), .resetvalue
= 0, },
2608 { .name
= "IMIN", .cp
= 15, .crn
= 15, .crm
= 3, .opc1
= 0, .opc2
= 0,
2609 .access
= PL1_RW
, .resetvalue
= 0xff0,
2610 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_i_min
) },
2611 { .name
= "THREADID", .cp
= 15, .crn
= 15, .crm
= 4, .opc1
= 0, .opc2
= 0,
2613 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_threadid
), .resetvalue
= 0,
2614 .writefn
= omap_threadid_write
},
2615 { .name
= "TI925T_STATUS", .cp
= 15, .crn
= 15,
2616 .crm
= 8, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
2617 .type
= ARM_CP_NO_RAW
,
2618 .readfn
= arm_cp_read_zero
, .writefn
= omap_wfi_write
, },
2619 /* TODO: Peripheral port remap register:
2620 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt controller
2621 * base address at $rn & ~0xfff and map size of 0x200 << ($rn & 0xfff),
2624 { .name
= "OMAP_CACHEMAINT", .cp
= 15, .crn
= 7, .crm
= CP_ANY
,
2625 .opc1
= 0, .opc2
= CP_ANY
, .access
= PL1_W
,
2626 .type
= ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
,
2627 .writefn
= omap_cachemaint_write
},
2628 { .name
= "C9", .cp
= 15, .crn
= 9,
2629 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_RW
,
2630 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
, .resetvalue
= 0 },
2634 static void xscale_cpar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2637 env
->cp15
.c15_cpar
= value
& 0x3fff;
2640 static const ARMCPRegInfo xscale_cp_reginfo
[] = {
2641 { .name
= "XSCALE_CPAR",
2642 .cp
= 15, .crn
= 15, .crm
= 1, .opc1
= 0, .opc2
= 0, .access
= PL1_RW
,
2643 .fieldoffset
= offsetof(CPUARMState
, cp15
.c15_cpar
), .resetvalue
= 0,
2644 .writefn
= xscale_cpar_write
, },
2645 { .name
= "XSCALE_AUXCR",
2646 .cp
= 15, .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 1, .access
= PL1_RW
,
2647 .fieldoffset
= offsetof(CPUARMState
, cp15
.c1_xscaleauxcr
),
2649 /* XScale specific cache-lockdown: since we have no cache we NOP these
2650 * and hope the guest does not really rely on cache behaviour.
2652 { .name
= "XSCALE_LOCK_ICACHE_LINE",
2653 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 0,
2654 .access
= PL1_W
, .type
= ARM_CP_NOP
},
2655 { .name
= "XSCALE_UNLOCK_ICACHE",
2656 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 1, .opc2
= 1,
2657 .access
= PL1_W
, .type
= ARM_CP_NOP
},
2658 { .name
= "XSCALE_DCACHE_LOCK",
2659 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 0,
2660 .access
= PL1_RW
, .type
= ARM_CP_NOP
},
2661 { .name
= "XSCALE_UNLOCK_DCACHE",
2662 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 2, .opc2
= 1,
2663 .access
= PL1_W
, .type
= ARM_CP_NOP
},
2667 static const ARMCPRegInfo dummy_c15_cp_reginfo
[] = {
2668 /* RAZ/WI the whole crn=15 space, when we don't have a more specific
2669 * implementation of this implementation-defined space.
2670 * Ideally this should eventually disappear in favour of actually
2671 * implementing the correct behaviour for all cores.
2673 { .name
= "C15_IMPDEF", .cp
= 15, .crn
= 15,
2674 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
2676 .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
| ARM_CP_OVERRIDE
,
2681 static const ARMCPRegInfo cache_dirty_status_cp_reginfo
[] = {
2682 /* Cache status: RAZ because we have no cache so it's always clean */
2683 { .name
= "CDSR", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 6,
2684 .access
= PL1_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
2689 static const ARMCPRegInfo cache_block_ops_cp_reginfo
[] = {
2690 /* We never have a a block transfer operation in progress */
2691 { .name
= "BXSR", .cp
= 15, .crn
= 7, .crm
= 12, .opc1
= 0, .opc2
= 4,
2692 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
2694 /* The cache ops themselves: these all NOP for QEMU */
2695 { .name
= "IICR", .cp
= 15, .crm
= 5, .opc1
= 0,
2696 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2697 { .name
= "IDCR", .cp
= 15, .crm
= 6, .opc1
= 0,
2698 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2699 { .name
= "CDCR", .cp
= 15, .crm
= 12, .opc1
= 0,
2700 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2701 { .name
= "PIR", .cp
= 15, .crm
= 12, .opc1
= 1,
2702 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2703 { .name
= "PDR", .cp
= 15, .crm
= 12, .opc1
= 2,
2704 .access
= PL0_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2705 { .name
= "CIDCR", .cp
= 15, .crm
= 14, .opc1
= 0,
2706 .access
= PL1_W
, .type
= ARM_CP_NOP
|ARM_CP_64BIT
},
2710 static const ARMCPRegInfo cache_test_clean_cp_reginfo
[] = {
2711 /* The cache test-and-clean instructions always return (1 << 30)
2712 * to indicate that there are no dirty cache lines.
2714 { .name
= "TC_DCACHE", .cp
= 15, .crn
= 7, .crm
= 10, .opc1
= 0, .opc2
= 3,
2715 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
2716 .resetvalue
= (1 << 30) },
2717 { .name
= "TCI_DCACHE", .cp
= 15, .crn
= 7, .crm
= 14, .opc1
= 0, .opc2
= 3,
2718 .access
= PL0_R
, .type
= ARM_CP_CONST
| ARM_CP_NO_RAW
,
2719 .resetvalue
= (1 << 30) },
2723 static const ARMCPRegInfo strongarm_cp_reginfo
[] = {
2724 /* Ignore ReadBuffer accesses */
2725 { .name
= "C9_READBUFFER", .cp
= 15, .crn
= 9,
2726 .crm
= CP_ANY
, .opc1
= CP_ANY
, .opc2
= CP_ANY
,
2727 .access
= PL1_RW
, .resetvalue
= 0,
2728 .type
= ARM_CP_CONST
| ARM_CP_OVERRIDE
| ARM_CP_NO_RAW
},
2732 static uint64_t midr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2734 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2735 unsigned int cur_el
= arm_current_el(env
);
2736 bool secure
= arm_is_secure(env
);
2738 if (arm_feature(&cpu
->env
, ARM_FEATURE_EL2
) && !secure
&& cur_el
== 1) {
2739 return env
->cp15
.vpidr_el2
;
2741 return raw_read(env
, ri
);
2744 static uint64_t mpidr_read_val(CPUARMState
*env
)
2746 ARMCPU
*cpu
= ARM_CPU(arm_env_get_cpu(env
));
2747 uint64_t mpidr
= cpu
->mp_affinity
;
2749 if (arm_feature(env
, ARM_FEATURE_V7MP
)) {
2750 mpidr
|= (1U << 31);
2751 /* Cores which are uniprocessor (non-coherent)
2752 * but still implement the MP extensions set
2753 * bit 30. (For instance, Cortex-R5).
2755 if (cpu
->mp_is_up
) {
2756 mpidr
|= (1u << 30);
2762 static uint64_t mpidr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2764 unsigned int cur_el
= arm_current_el(env
);
2765 bool secure
= arm_is_secure(env
);
2767 if (arm_feature(env
, ARM_FEATURE_EL2
) && !secure
&& cur_el
== 1) {
2768 return env
->cp15
.vmpidr_el2
;
2770 return mpidr_read_val(env
);
2773 static const ARMCPRegInfo mpidr_cp_reginfo
[] = {
2774 { .name
= "MPIDR", .state
= ARM_CP_STATE_BOTH
,
2775 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 5,
2776 .access
= PL1_R
, .readfn
= mpidr_read
, .type
= ARM_CP_NO_RAW
},
2780 static const ARMCPRegInfo lpae_cp_reginfo
[] = {
2782 { .name
= "AMAIR0", .state
= ARM_CP_STATE_BOTH
,
2783 .opc0
= 3, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 0,
2784 .access
= PL1_RW
, .type
= ARM_CP_CONST
,
2786 /* AMAIR1 is mapped to AMAIR_EL1[63:32] */
2787 { .name
= "AMAIR1", .cp
= 15, .crn
= 10, .crm
= 3, .opc1
= 0, .opc2
= 1,
2788 .access
= PL1_RW
, .type
= ARM_CP_CONST
,
2790 { .name
= "PAR", .cp
= 15, .crm
= 7, .opc1
= 0,
2791 .access
= PL1_RW
, .type
= ARM_CP_64BIT
, .resetvalue
= 0,
2792 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.par_s
),
2793 offsetof(CPUARMState
, cp15
.par_ns
)} },
2794 { .name
= "TTBR0", .cp
= 15, .crm
= 2, .opc1
= 0,
2795 .access
= PL1_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
2796 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr0_s
),
2797 offsetof(CPUARMState
, cp15
.ttbr0_ns
) },
2798 .writefn
= vmsa_ttbr_write
, },
2799 { .name
= "TTBR1", .cp
= 15, .crm
= 2, .opc1
= 1,
2800 .access
= PL1_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
2801 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.ttbr1_s
),
2802 offsetof(CPUARMState
, cp15
.ttbr1_ns
) },
2803 .writefn
= vmsa_ttbr_write
, },
2807 static uint64_t aa64_fpcr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2809 return vfp_get_fpcr(env
);
2812 static void aa64_fpcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2815 vfp_set_fpcr(env
, value
);
2818 static uint64_t aa64_fpsr_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
2820 return vfp_get_fpsr(env
);
2823 static void aa64_fpsr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2826 vfp_set_fpsr(env
, value
);
2829 static CPAccessResult
aa64_daif_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2832 if (arm_current_el(env
) == 0 && !(env
->cp15
.sctlr_el
[1] & SCTLR_UMA
)) {
2833 return CP_ACCESS_TRAP
;
2835 return CP_ACCESS_OK
;
2838 static void aa64_daif_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2841 env
->daif
= value
& PSTATE_DAIF
;
2844 static CPAccessResult
aa64_cacheop_access(CPUARMState
*env
,
2845 const ARMCPRegInfo
*ri
,
2848 /* Cache invalidate/clean: NOP, but EL0 must UNDEF unless
2849 * SCTLR_EL1.UCI is set.
2851 if (arm_current_el(env
) == 0 && !(env
->cp15
.sctlr_el
[1] & SCTLR_UCI
)) {
2852 return CP_ACCESS_TRAP
;
2854 return CP_ACCESS_OK
;
2857 /* See: D4.7.2 TLB maintenance requirements and the TLB maintenance instructions
2858 * Page D4-1736 (DDI0487A.b)
2861 static void tlbi_aa64_vmalle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2864 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2865 CPUState
*cs
= CPU(cpu
);
2867 if (arm_is_secure_below_el3(env
)) {
2868 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S1SE1
, ARMMMUIdx_S1SE0
, -1);
2870 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S12NSE1
, ARMMMUIdx_S12NSE0
, -1);
2874 static void tlbi_aa64_vmalle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2877 bool sec
= arm_is_secure_below_el3(env
);
2880 CPU_FOREACH(other_cs
) {
2882 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S1SE1
, ARMMMUIdx_S1SE0
, -1);
2884 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S12NSE1
,
2885 ARMMMUIdx_S12NSE0
, -1);
2890 static void tlbi_aa64_alle1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2893 /* Note that the 'ALL' scope must invalidate both stage 1 and
2894 * stage 2 translations, whereas most other scopes only invalidate
2895 * stage 1 translations.
2897 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2898 CPUState
*cs
= CPU(cpu
);
2900 if (arm_is_secure_below_el3(env
)) {
2901 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S1SE1
, ARMMMUIdx_S1SE0
, -1);
2903 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
2904 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S12NSE1
, ARMMMUIdx_S12NSE0
,
2905 ARMMMUIdx_S2NS
, -1);
2907 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S12NSE1
, ARMMMUIdx_S12NSE0
, -1);
2912 static void tlbi_aa64_alle2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2915 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2916 CPUState
*cs
= CPU(cpu
);
2918 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S1E2
, -1);
2921 static void tlbi_aa64_alle3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2924 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2925 CPUState
*cs
= CPU(cpu
);
2927 tlb_flush_by_mmuidx(cs
, ARMMMUIdx_S1E3
, -1);
2930 static void tlbi_aa64_alle1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2933 /* Note that the 'ALL' scope must invalidate both stage 1 and
2934 * stage 2 translations, whereas most other scopes only invalidate
2935 * stage 1 translations.
2937 bool sec
= arm_is_secure_below_el3(env
);
2938 bool has_el2
= arm_feature(env
, ARM_FEATURE_EL2
);
2941 CPU_FOREACH(other_cs
) {
2943 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S1SE1
, ARMMMUIdx_S1SE0
, -1);
2944 } else if (has_el2
) {
2945 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S12NSE1
,
2946 ARMMMUIdx_S12NSE0
, ARMMMUIdx_S2NS
, -1);
2948 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S12NSE1
,
2949 ARMMMUIdx_S12NSE0
, -1);
2954 static void tlbi_aa64_alle2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2959 CPU_FOREACH(other_cs
) {
2960 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S1E2
, -1);
2964 static void tlbi_aa64_alle3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2969 CPU_FOREACH(other_cs
) {
2970 tlb_flush_by_mmuidx(other_cs
, ARMMMUIdx_S1E3
, -1);
2974 static void tlbi_aa64_vae1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2977 /* Invalidate by VA, EL1&0 (AArch64 version).
2978 * Currently handles all of VAE1, VAAE1, VAALE1 and VALE1,
2979 * since we don't support flush-for-specific-ASID-only or
2980 * flush-last-level-only.
2982 ARMCPU
*cpu
= arm_env_get_cpu(env
);
2983 CPUState
*cs
= CPU(cpu
);
2984 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
2986 if (arm_is_secure_below_el3(env
)) {
2987 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S1SE1
,
2988 ARMMMUIdx_S1SE0
, -1);
2990 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S12NSE1
,
2991 ARMMMUIdx_S12NSE0
, -1);
2995 static void tlbi_aa64_vae2_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
2998 /* Invalidate by VA, EL2
2999 * Currently handles both VAE2 and VALE2, since we don't support
3000 * flush-last-level-only.
3002 ARMCPU
*cpu
= arm_env_get_cpu(env
);
3003 CPUState
*cs
= CPU(cpu
);
3004 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
3006 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S1E2
, -1);
3009 static void tlbi_aa64_vae3_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3012 /* Invalidate by VA, EL3
3013 * Currently handles both VAE3 and VALE3, since we don't support
3014 * flush-last-level-only.
3016 ARMCPU
*cpu
= arm_env_get_cpu(env
);
3017 CPUState
*cs
= CPU(cpu
);
3018 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
3020 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S1E3
, -1);
3023 static void tlbi_aa64_vae1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3026 bool sec
= arm_is_secure_below_el3(env
);
3028 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
3030 CPU_FOREACH(other_cs
) {
3032 tlb_flush_page_by_mmuidx(other_cs
, pageaddr
, ARMMMUIdx_S1SE1
,
3033 ARMMMUIdx_S1SE0
, -1);
3035 tlb_flush_page_by_mmuidx(other_cs
, pageaddr
, ARMMMUIdx_S12NSE1
,
3036 ARMMMUIdx_S12NSE0
, -1);
3041 static void tlbi_aa64_vae2is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3045 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
3047 CPU_FOREACH(other_cs
) {
3048 tlb_flush_page_by_mmuidx(other_cs
, pageaddr
, ARMMMUIdx_S1E2
, -1);
3052 static void tlbi_aa64_vae3is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3056 uint64_t pageaddr
= sextract64(value
<< 12, 0, 56);
3058 CPU_FOREACH(other_cs
) {
3059 tlb_flush_page_by_mmuidx(other_cs
, pageaddr
, ARMMMUIdx_S1E3
, -1);
3063 static void tlbi_aa64_ipas2e1_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3066 /* Invalidate by IPA. This has to invalidate any structures that
3067 * contain only stage 2 translation information, but does not need
3068 * to apply to structures that contain combined stage 1 and stage 2
3069 * translation information.
3070 * This must NOP if EL2 isn't implemented or SCR_EL3.NS is zero.
3072 ARMCPU
*cpu
= arm_env_get_cpu(env
);
3073 CPUState
*cs
= CPU(cpu
);
3076 if (!arm_feature(env
, ARM_FEATURE_EL2
) || !(env
->cp15
.scr_el3
& SCR_NS
)) {
3080 pageaddr
= sextract64(value
<< 12, 0, 48);
3082 tlb_flush_page_by_mmuidx(cs
, pageaddr
, ARMMMUIdx_S2NS
, -1);
3085 static void tlbi_aa64_ipas2e1is_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3091 if (!arm_feature(env
, ARM_FEATURE_EL2
) || !(env
->cp15
.scr_el3
& SCR_NS
)) {
3095 pageaddr
= sextract64(value
<< 12, 0, 48);
3097 CPU_FOREACH(other_cs
) {
3098 tlb_flush_page_by_mmuidx(other_cs
, pageaddr
, ARMMMUIdx_S2NS
, -1);
3102 static CPAccessResult
aa64_zva_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3105 /* We don't implement EL2, so the only control on DC ZVA is the
3106 * bit in the SCTLR which can prohibit access for EL0.
3108 if (arm_current_el(env
) == 0 && !(env
->cp15
.sctlr_el
[1] & SCTLR_DZE
)) {
3109 return CP_ACCESS_TRAP
;
3111 return CP_ACCESS_OK
;
3114 static uint64_t aa64_dczid_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3116 ARMCPU
*cpu
= arm_env_get_cpu(env
);
3117 int dzp_bit
= 1 << 4;
3119 /* DZP indicates whether DC ZVA access is allowed */
3120 if (aa64_zva_access(env
, NULL
, false) == CP_ACCESS_OK
) {
3123 return cpu
->dcz_blocksize
| dzp_bit
;
3126 static CPAccessResult
sp_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3129 if (!(env
->pstate
& PSTATE_SP
)) {
3130 /* Access to SP_EL0 is undefined if it's being used as
3131 * the stack pointer.
3133 return CP_ACCESS_TRAP_UNCATEGORIZED
;
3135 return CP_ACCESS_OK
;
3138 static uint64_t spsel_read(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
3140 return env
->pstate
& PSTATE_SP
;
3143 static void spsel_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t val
)
3145 update_spsel(env
, val
);
3148 static void sctlr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3151 ARMCPU
*cpu
= arm_env_get_cpu(env
);
3153 if (raw_read(env
, ri
) == value
) {
3154 /* Skip the TLB flush if nothing actually changed; Linux likes
3155 * to do a lot of pointless SCTLR writes.
3160 raw_write(env
, ri
, value
);
3161 /* ??? Lots of these bits are not implemented. */
3162 /* This may enable/disable the MMU, so do a TLB flush. */
3163 tlb_flush(CPU(cpu
), 1);
3166 static CPAccessResult
fpexc32_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3169 if ((env
->cp15
.cptr_el
[2] & CPTR_TFP
) && arm_current_el(env
) == 2) {
3170 return CP_ACCESS_TRAP_FP_EL2
;
3172 if (env
->cp15
.cptr_el
[3] & CPTR_TFP
) {
3173 return CP_ACCESS_TRAP_FP_EL3
;
3175 return CP_ACCESS_OK
;
3178 static void sdcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3181 env
->cp15
.mdcr_el3
= value
& SDCR_VALID_MASK
;
3184 static const ARMCPRegInfo v8_cp_reginfo
[] = {
3185 /* Minimal set of EL0-visible registers. This will need to be expanded
3186 * significantly for system emulation of AArch64 CPUs.
3188 { .name
= "NZCV", .state
= ARM_CP_STATE_AA64
,
3189 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 2,
3190 .access
= PL0_RW
, .type
= ARM_CP_NZCV
},
3191 { .name
= "DAIF", .state
= ARM_CP_STATE_AA64
,
3192 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 2,
3193 .type
= ARM_CP_NO_RAW
,
3194 .access
= PL0_RW
, .accessfn
= aa64_daif_access
,
3195 .fieldoffset
= offsetof(CPUARMState
, daif
),
3196 .writefn
= aa64_daif_write
, .resetfn
= arm_cp_reset_ignore
},
3197 { .name
= "FPCR", .state
= ARM_CP_STATE_AA64
,
3198 .opc0
= 3, .opc1
= 3, .opc2
= 0, .crn
= 4, .crm
= 4,
3199 .access
= PL0_RW
, .readfn
= aa64_fpcr_read
, .writefn
= aa64_fpcr_write
},
3200 { .name
= "FPSR", .state
= ARM_CP_STATE_AA64
,
3201 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 4, .crm
= 4,
3202 .access
= PL0_RW
, .readfn
= aa64_fpsr_read
, .writefn
= aa64_fpsr_write
},
3203 { .name
= "DCZID_EL0", .state
= ARM_CP_STATE_AA64
,
3204 .opc0
= 3, .opc1
= 3, .opc2
= 7, .crn
= 0, .crm
= 0,
3205 .access
= PL0_R
, .type
= ARM_CP_NO_RAW
,
3206 .readfn
= aa64_dczid_read
},
3207 { .name
= "DC_ZVA", .state
= ARM_CP_STATE_AA64
,
3208 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 4, .opc2
= 1,
3209 .access
= PL0_W
, .type
= ARM_CP_DC_ZVA
,
3210 #ifndef CONFIG_USER_ONLY
3211 /* Avoid overhead of an access check that always passes in user-mode */
3212 .accessfn
= aa64_zva_access
,
3215 { .name
= "CURRENTEL", .state
= ARM_CP_STATE_AA64
,
3216 .opc0
= 3, .opc1
= 0, .opc2
= 2, .crn
= 4, .crm
= 2,
3217 .access
= PL1_R
, .type
= ARM_CP_CURRENTEL
},
3218 /* Cache ops: all NOPs since we don't emulate caches */
3219 { .name
= "IC_IALLUIS", .state
= ARM_CP_STATE_AA64
,
3220 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
3221 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3222 { .name
= "IC_IALLU", .state
= ARM_CP_STATE_AA64
,
3223 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
3224 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3225 { .name
= "IC_IVAU", .state
= ARM_CP_STATE_AA64
,
3226 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 5, .opc2
= 1,
3227 .access
= PL0_W
, .type
= ARM_CP_NOP
,
3228 .accessfn
= aa64_cacheop_access
},
3229 { .name
= "DC_IVAC", .state
= ARM_CP_STATE_AA64
,
3230 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
3231 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3232 { .name
= "DC_ISW", .state
= ARM_CP_STATE_AA64
,
3233 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
3234 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3235 { .name
= "DC_CVAC", .state
= ARM_CP_STATE_AA64
,
3236 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 10, .opc2
= 1,
3237 .access
= PL0_W
, .type
= ARM_CP_NOP
,
3238 .accessfn
= aa64_cacheop_access
},
3239 { .name
= "DC_CSW", .state
= ARM_CP_STATE_AA64
,
3240 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
3241 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3242 { .name
= "DC_CVAU", .state
= ARM_CP_STATE_AA64
,
3243 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 11, .opc2
= 1,
3244 .access
= PL0_W
, .type
= ARM_CP_NOP
,
3245 .accessfn
= aa64_cacheop_access
},
3246 { .name
= "DC_CIVAC", .state
= ARM_CP_STATE_AA64
,
3247 .opc0
= 1, .opc1
= 3, .crn
= 7, .crm
= 14, .opc2
= 1,
3248 .access
= PL0_W
, .type
= ARM_CP_NOP
,
3249 .accessfn
= aa64_cacheop_access
},
3250 { .name
= "DC_CISW", .state
= ARM_CP_STATE_AA64
,
3251 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
3252 .access
= PL1_W
, .type
= ARM_CP_NOP
},
3253 /* TLBI operations */
3254 { .name
= "TLBI_VMALLE1IS", .state
= ARM_CP_STATE_AA64
,
3255 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 0,
3256 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3257 .writefn
= tlbi_aa64_vmalle1is_write
},
3258 { .name
= "TLBI_VAE1IS", .state
= ARM_CP_STATE_AA64
,
3259 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 1,
3260 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3261 .writefn
= tlbi_aa64_vae1is_write
},
3262 { .name
= "TLBI_ASIDE1IS", .state
= ARM_CP_STATE_AA64
,
3263 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 2,
3264 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3265 .writefn
= tlbi_aa64_vmalle1is_write
},
3266 { .name
= "TLBI_VAAE1IS", .state
= ARM_CP_STATE_AA64
,
3267 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 3,
3268 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3269 .writefn
= tlbi_aa64_vae1is_write
},
3270 { .name
= "TLBI_VALE1IS", .state
= ARM_CP_STATE_AA64
,
3271 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
3272 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3273 .writefn
= tlbi_aa64_vae1is_write
},
3274 { .name
= "TLBI_VAALE1IS", .state
= ARM_CP_STATE_AA64
,
3275 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
3276 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3277 .writefn
= tlbi_aa64_vae1is_write
},
3278 { .name
= "TLBI_VMALLE1", .state
= ARM_CP_STATE_AA64
,
3279 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 0,
3280 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3281 .writefn
= tlbi_aa64_vmalle1_write
},
3282 { .name
= "TLBI_VAE1", .state
= ARM_CP_STATE_AA64
,
3283 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 1,
3284 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3285 .writefn
= tlbi_aa64_vae1_write
},
3286 { .name
= "TLBI_ASIDE1", .state
= ARM_CP_STATE_AA64
,
3287 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 2,
3288 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3289 .writefn
= tlbi_aa64_vmalle1_write
},
3290 { .name
= "TLBI_VAAE1", .state
= ARM_CP_STATE_AA64
,
3291 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 3,
3292 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3293 .writefn
= tlbi_aa64_vae1_write
},
3294 { .name
= "TLBI_VALE1", .state
= ARM_CP_STATE_AA64
,
3295 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
3296 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3297 .writefn
= tlbi_aa64_vae1_write
},
3298 { .name
= "TLBI_VAALE1", .state
= ARM_CP_STATE_AA64
,
3299 .opc0
= 1, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
3300 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
3301 .writefn
= tlbi_aa64_vae1_write
},
3302 { .name
= "TLBI_IPAS2E1IS", .state
= ARM_CP_STATE_AA64
,
3303 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
3304 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
3305 .writefn
= tlbi_aa64_ipas2e1is_write
},
3306 { .name
= "TLBI_IPAS2LE1IS", .state
= ARM_CP_STATE_AA64
,
3307 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
3308 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
3309 .writefn
= tlbi_aa64_ipas2e1is_write
},
3310 { .name
= "TLBI_ALLE1IS", .state
= ARM_CP_STATE_AA64
,
3311 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
3312 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
3313 .writefn
= tlbi_aa64_alle1is_write
},
3314 { .name
= "TLBI_VMALLS12E1IS", .state
= ARM_CP_STATE_AA64
,
3315 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 6,
3316 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
3317 .writefn
= tlbi_aa64_alle1is_write
},
3318 { .name
= "TLBI_IPAS2E1", .state
= ARM_CP_STATE_AA64
,
3319 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
3320 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
3321 .writefn
= tlbi_aa64_ipas2e1_write
},
3322 { .name
= "TLBI_IPAS2LE1", .state
= ARM_CP_STATE_AA64
,
3323 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
3324 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
3325 .writefn
= tlbi_aa64_ipas2e1_write
},
3326 { .name
= "TLBI_ALLE1", .state
= ARM_CP_STATE_AA64
,
3327 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
3328 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
3329 .writefn
= tlbi_aa64_alle1_write
},
3330 { .name
= "TLBI_VMALLS12E1", .state
= ARM_CP_STATE_AA64
,
3331 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 6,
3332 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
3333 .writefn
= tlbi_aa64_alle1is_write
},
3334 #ifndef CONFIG_USER_ONLY
3335 /* 64 bit address translation operations */
3336 { .name
= "AT_S1E1R", .state
= ARM_CP_STATE_AA64
,
3337 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 0,
3338 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3339 { .name
= "AT_S1E1W", .state
= ARM_CP_STATE_AA64
,
3340 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 1,
3341 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3342 { .name
= "AT_S1E0R", .state
= ARM_CP_STATE_AA64
,
3343 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 2,
3344 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3345 { .name
= "AT_S1E0W", .state
= ARM_CP_STATE_AA64
,
3346 .opc0
= 1, .opc1
= 0, .crn
= 7, .crm
= 8, .opc2
= 3,
3347 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3348 { .name
= "AT_S12E1R", .state
= ARM_CP_STATE_AA64
,
3349 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 4,
3350 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3351 { .name
= "AT_S12E1W", .state
= ARM_CP_STATE_AA64
,
3352 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 5,
3353 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3354 { .name
= "AT_S12E0R", .state
= ARM_CP_STATE_AA64
,
3355 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 6,
3356 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3357 { .name
= "AT_S12E0W", .state
= ARM_CP_STATE_AA64
,
3358 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 7,
3359 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3360 /* AT S1E2* are elsewhere as they UNDEF from EL3 if EL2 is not present */
3361 { .name
= "AT_S1E3R", .state
= ARM_CP_STATE_AA64
,
3362 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 0,
3363 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3364 { .name
= "AT_S1E3W", .state
= ARM_CP_STATE_AA64
,
3365 .opc0
= 1, .opc1
= 6, .crn
= 7, .crm
= 8, .opc2
= 1,
3366 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3367 { .name
= "PAR_EL1", .state
= ARM_CP_STATE_AA64
,
3368 .type
= ARM_CP_ALIAS
,
3369 .opc0
= 3, .opc1
= 0, .crn
= 7, .crm
= 4, .opc2
= 0,
3370 .access
= PL1_RW
, .resetvalue
= 0,
3371 .fieldoffset
= offsetof(CPUARMState
, cp15
.par_el
[1]),
3372 .writefn
= par_write
},
3374 /* TLB invalidate last level of translation table walk */
3375 { .name
= "TLBIMVALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 5,
3376 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimva_is_write
},
3377 { .name
= "TLBIMVAALIS", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 3, .opc2
= 7,
3378 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
,
3379 .writefn
= tlbimvaa_is_write
},
3380 { .name
= "TLBIMVAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 5,
3381 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimva_write
},
3382 { .name
= "TLBIMVAAL", .cp
= 15, .opc1
= 0, .crn
= 8, .crm
= 7, .opc2
= 7,
3383 .type
= ARM_CP_NO_RAW
, .access
= PL1_W
, .writefn
= tlbimvaa_write
},
3384 { .name
= "TLBIMVALH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
3385 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3386 .writefn
= tlbimva_hyp_write
},
3387 { .name
= "TLBIMVALHIS",
3388 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
3389 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3390 .writefn
= tlbimva_hyp_is_write
},
3391 { .name
= "TLBIIPAS2",
3392 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 1,
3393 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3394 .writefn
= tlbiipas2_write
},
3395 { .name
= "TLBIIPAS2IS",
3396 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 1,
3397 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3398 .writefn
= tlbiipas2_is_write
},
3399 { .name
= "TLBIIPAS2L",
3400 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 4, .opc2
= 5,
3401 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3402 .writefn
= tlbiipas2_write
},
3403 { .name
= "TLBIIPAS2LIS",
3404 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 0, .opc2
= 5,
3405 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3406 .writefn
= tlbiipas2_is_write
},
3407 /* 32 bit cache operations */
3408 { .name
= "ICIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 0,
3409 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3410 { .name
= "BPIALLUIS", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 1, .opc2
= 6,
3411 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3412 { .name
= "ICIALLU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 0,
3413 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3414 { .name
= "ICIMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 1,
3415 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3416 { .name
= "BPIALL", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 6,
3417 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3418 { .name
= "BPIMVA", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 5, .opc2
= 7,
3419 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3420 { .name
= "DCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 1,
3421 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3422 { .name
= "DCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 6, .opc2
= 2,
3423 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3424 { .name
= "DCCMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 1,
3425 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3426 { .name
= "DCCSW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 10, .opc2
= 2,
3427 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3428 { .name
= "DCCMVAU", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 11, .opc2
= 1,
3429 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3430 { .name
= "DCCIMVAC", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 1,
3431 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3432 { .name
= "DCCISW", .cp
= 15, .opc1
= 0, .crn
= 7, .crm
= 14, .opc2
= 2,
3433 .type
= ARM_CP_NOP
, .access
= PL1_W
},
3434 /* MMU Domain access control / MPU write buffer control */
3435 { .name
= "DACR", .cp
= 15, .opc1
= 0, .crn
= 3, .crm
= 0, .opc2
= 0,
3436 .access
= PL1_RW
, .resetvalue
= 0,
3437 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
3438 .bank_fieldoffsets
= { offsetoflow32(CPUARMState
, cp15
.dacr_s
),
3439 offsetoflow32(CPUARMState
, cp15
.dacr_ns
) } },
3440 { .name
= "ELR_EL1", .state
= ARM_CP_STATE_AA64
,
3441 .type
= ARM_CP_ALIAS
,
3442 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 1,
3444 .fieldoffset
= offsetof(CPUARMState
, elr_el
[1]) },
3445 { .name
= "SPSR_EL1", .state
= ARM_CP_STATE_AA64
,
3446 .type
= ARM_CP_ALIAS
,
3447 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 0, .opc2
= 0,
3449 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_SVC
]) },
3450 /* We rely on the access checks not allowing the guest to write to the
3451 * state field when SPSel indicates that it's being used as the stack
3454 { .name
= "SP_EL0", .state
= ARM_CP_STATE_AA64
,
3455 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 1, .opc2
= 0,
3456 .access
= PL1_RW
, .accessfn
= sp_el0_access
,
3457 .type
= ARM_CP_ALIAS
,
3458 .fieldoffset
= offsetof(CPUARMState
, sp_el
[0]) },
3459 { .name
= "SP_EL1", .state
= ARM_CP_STATE_AA64
,
3460 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 1, .opc2
= 0,
3461 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
,
3462 .fieldoffset
= offsetof(CPUARMState
, sp_el
[1]) },
3463 { .name
= "SPSel", .state
= ARM_CP_STATE_AA64
,
3464 .opc0
= 3, .opc1
= 0, .crn
= 4, .crm
= 2, .opc2
= 0,
3465 .type
= ARM_CP_NO_RAW
,
3466 .access
= PL1_RW
, .readfn
= spsel_read
, .writefn
= spsel_write
},
3467 { .name
= "FPEXC32_EL2", .state
= ARM_CP_STATE_AA64
,
3468 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 3, .opc2
= 0,
3469 .type
= ARM_CP_ALIAS
,
3470 .fieldoffset
= offsetof(CPUARMState
, vfp
.xregs
[ARM_VFP_FPEXC
]),
3471 .access
= PL2_RW
, .accessfn
= fpexc32_access
},
3472 { .name
= "DACR32_EL2", .state
= ARM_CP_STATE_AA64
,
3473 .opc0
= 3, .opc1
= 4, .crn
= 3, .crm
= 0, .opc2
= 0,
3474 .access
= PL2_RW
, .resetvalue
= 0,
3475 .writefn
= dacr_write
, .raw_writefn
= raw_write
,
3476 .fieldoffset
= offsetof(CPUARMState
, cp15
.dacr32_el2
) },
3477 { .name
= "IFSR32_EL2", .state
= ARM_CP_STATE_AA64
,
3478 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 0, .opc2
= 1,
3479 .access
= PL2_RW
, .resetvalue
= 0,
3480 .fieldoffset
= offsetof(CPUARMState
, cp15
.ifsr32_el2
) },
3481 { .name
= "SPSR_IRQ", .state
= ARM_CP_STATE_AA64
,
3482 .type
= ARM_CP_ALIAS
,
3483 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 0,
3485 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_IRQ
]) },
3486 { .name
= "SPSR_ABT", .state
= ARM_CP_STATE_AA64
,
3487 .type
= ARM_CP_ALIAS
,
3488 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 1,
3490 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_ABT
]) },
3491 { .name
= "SPSR_UND", .state
= ARM_CP_STATE_AA64
,
3492 .type
= ARM_CP_ALIAS
,
3493 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 2,
3495 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_UND
]) },
3496 { .name
= "SPSR_FIQ", .state
= ARM_CP_STATE_AA64
,
3497 .type
= ARM_CP_ALIAS
,
3498 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 3, .opc2
= 3,
3500 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_FIQ
]) },
3501 { .name
= "MDCR_EL3", .state
= ARM_CP_STATE_AA64
,
3502 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 3, .opc2
= 1,
3504 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el3
) },
3505 { .name
= "SDCR", .type
= ARM_CP_ALIAS
,
3506 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 3, .opc2
= 1,
3507 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
3508 .writefn
= sdcr_write
,
3509 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.mdcr_el3
) },
3513 /* Used to describe the behaviour of EL2 regs when EL2 does not exist. */
3514 static const ARMCPRegInfo el3_no_el2_cp_reginfo
[] = {
3515 { .name
= "VBAR_EL2", .state
= ARM_CP_STATE_AA64
,
3516 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 0,
3518 .readfn
= arm_cp_read_zero
, .writefn
= arm_cp_write_ignore
},
3519 { .name
= "HCR_EL2", .state
= ARM_CP_STATE_AA64
,
3520 .type
= ARM_CP_NO_RAW
,
3521 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
3523 .readfn
= arm_cp_read_zero
, .writefn
= arm_cp_write_ignore
},
3524 { .name
= "CPTR_EL2", .state
= ARM_CP_STATE_BOTH
,
3525 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 2,
3526 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3527 { .name
= "MAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
3528 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 0,
3529 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
3531 { .name
= "HMAIR1", .state
= ARM_CP_STATE_AA32
,
3532 .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 1,
3533 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3534 { .name
= "AMAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
3535 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 0,
3536 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
3538 { .name
= "HMAIR1", .state
= ARM_CP_STATE_AA32
,
3539 .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 1,
3540 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
3542 { .name
= "AFSR0_EL2", .state
= ARM_CP_STATE_BOTH
,
3543 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 0,
3544 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
3546 { .name
= "AFSR1_EL2", .state
= ARM_CP_STATE_BOTH
,
3547 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 1,
3548 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
3550 { .name
= "TCR_EL2", .state
= ARM_CP_STATE_BOTH
,
3551 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 2,
3552 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3553 { .name
= "VTCR_EL2", .state
= ARM_CP_STATE_BOTH
,
3554 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
3555 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns_aa64any
,
3556 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3557 { .name
= "VTTBR", .state
= ARM_CP_STATE_AA32
,
3558 .cp
= 15, .opc1
= 6, .crm
= 2,
3559 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
3560 .type
= ARM_CP_CONST
| ARM_CP_64BIT
, .resetvalue
= 0 },
3561 { .name
= "VTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
3562 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 0,
3563 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3564 { .name
= "SCTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
3565 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 0,
3566 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3567 { .name
= "TPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
3568 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 2,
3569 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3570 { .name
= "TTBR0_EL2", .state
= ARM_CP_STATE_AA64
,
3571 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 0,
3572 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3573 { .name
= "HTTBR", .cp
= 15, .opc1
= 4, .crm
= 2,
3574 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_CONST
,
3576 { .name
= "CNTHCTL_EL2", .state
= ARM_CP_STATE_BOTH
,
3577 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 1, .opc2
= 0,
3578 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3579 { .name
= "CNTVOFF_EL2", .state
= ARM_CP_STATE_AA64
,
3580 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 0, .opc2
= 3,
3581 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3582 { .name
= "CNTVOFF", .cp
= 15, .opc1
= 4, .crm
= 14,
3583 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_CONST
,
3585 { .name
= "CNTHP_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
3586 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 2,
3587 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3588 { .name
= "CNTHP_CVAL", .cp
= 15, .opc1
= 6, .crm
= 14,
3589 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_CONST
,
3591 { .name
= "CNTHP_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
3592 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 0,
3593 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3594 { .name
= "CNTHP_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
3595 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 1,
3596 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3597 { .name
= "MDCR_EL2", .state
= ARM_CP_STATE_BOTH
,
3598 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 1,
3599 .access
= PL2_RW
, .accessfn
= access_tda
,
3600 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3601 { .name
= "HPFAR_EL2", .state
= ARM_CP_STATE_BOTH
,
3602 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
3603 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns_aa64any
,
3604 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3605 { .name
= "HSTR_EL2", .state
= ARM_CP_STATE_BOTH
,
3606 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 3,
3607 .access
= PL2_RW
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
3611 static void hcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
, uint64_t value
)
3613 ARMCPU
*cpu
= arm_env_get_cpu(env
);
3614 uint64_t valid_mask
= HCR_MASK
;
3616 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
3617 valid_mask
&= ~HCR_HCD
;
3619 valid_mask
&= ~HCR_TSC
;
3622 /* Clear RES0 bits. */
3623 value
&= valid_mask
;
3625 /* These bits change the MMU setup:
3626 * HCR_VM enables stage 2 translation
3627 * HCR_PTW forbids certain page-table setups
3628 * HCR_DC Disables stage1 and enables stage2 translation
3630 if ((raw_read(env
, ri
) ^ value
) & (HCR_VM
| HCR_PTW
| HCR_DC
)) {
3631 tlb_flush(CPU(cpu
), 1);
3633 raw_write(env
, ri
, value
);
3636 static const ARMCPRegInfo el2_cp_reginfo
[] = {
3637 { .name
= "HCR_EL2", .state
= ARM_CP_STATE_AA64
,
3638 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 0,
3639 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.hcr_el2
),
3640 .writefn
= hcr_write
},
3641 { .name
= "ELR_EL2", .state
= ARM_CP_STATE_AA64
,
3642 .type
= ARM_CP_ALIAS
,
3643 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 1,
3645 .fieldoffset
= offsetof(CPUARMState
, elr_el
[2]) },
3646 { .name
= "ESR_EL2", .state
= ARM_CP_STATE_AA64
,
3647 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 2, .opc2
= 0,
3648 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[2]) },
3649 { .name
= "FAR_EL2", .state
= ARM_CP_STATE_AA64
,
3650 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 0,
3651 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[2]) },
3652 { .name
= "SPSR_EL2", .state
= ARM_CP_STATE_AA64
,
3653 .type
= ARM_CP_ALIAS
,
3654 .opc0
= 3, .opc1
= 4, .crn
= 4, .crm
= 0, .opc2
= 0,
3656 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_HYP
]) },
3657 { .name
= "VBAR_EL2", .state
= ARM_CP_STATE_AA64
,
3658 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 0,
3659 .access
= PL2_RW
, .writefn
= vbar_write
,
3660 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[2]),
3662 { .name
= "SP_EL2", .state
= ARM_CP_STATE_AA64
,
3663 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 1, .opc2
= 0,
3664 .access
= PL3_RW
, .type
= ARM_CP_ALIAS
,
3665 .fieldoffset
= offsetof(CPUARMState
, sp_el
[2]) },
3666 { .name
= "CPTR_EL2", .state
= ARM_CP_STATE_BOTH
,
3667 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 2,
3668 .access
= PL2_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
3669 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[2]) },
3670 { .name
= "MAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
3671 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 0,
3672 .access
= PL2_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.mair_el
[2]),
3674 { .name
= "HMAIR1", .state
= ARM_CP_STATE_AA32
,
3675 .opc1
= 4, .crn
= 10, .crm
= 2, .opc2
= 1,
3676 .access
= PL2_RW
, .type
= ARM_CP_ALIAS
,
3677 .fieldoffset
= offsetofhigh32(CPUARMState
, cp15
.mair_el
[2]) },
3678 { .name
= "AMAIR_EL2", .state
= ARM_CP_STATE_BOTH
,
3679 .opc0
= 3, .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 0,
3680 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
3682 /* HAMAIR1 is mapped to AMAIR_EL2[63:32] */
3683 { .name
= "HMAIR1", .state
= ARM_CP_STATE_AA32
,
3684 .opc1
= 4, .crn
= 10, .crm
= 3, .opc2
= 1,
3685 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
3687 { .name
= "AFSR0_EL2", .state
= ARM_CP_STATE_BOTH
,
3688 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 0,
3689 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
3691 { .name
= "AFSR1_EL2", .state
= ARM_CP_STATE_BOTH
,
3692 .opc0
= 3, .opc1
= 4, .crn
= 5, .crm
= 1, .opc2
= 1,
3693 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
3695 { .name
= "TCR_EL2", .state
= ARM_CP_STATE_BOTH
,
3696 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 2,
3698 /* no .writefn needed as this can't cause an ASID change;
3699 * no .raw_writefn or .resetfn needed as we never use mask/base_mask
3701 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[2]) },
3702 { .name
= "VTCR", .state
= ARM_CP_STATE_AA32
,
3703 .cp
= 15, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
3704 .type
= ARM_CP_ALIAS
,
3705 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
3706 .fieldoffset
= offsetof(CPUARMState
, cp15
.vtcr_el2
) },
3707 { .name
= "VTCR_EL2", .state
= ARM_CP_STATE_AA64
,
3708 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 2,
3710 /* no .writefn needed as this can't cause an ASID change;
3711 * no .raw_writefn or .resetfn needed as we never use mask/base_mask
3713 .fieldoffset
= offsetof(CPUARMState
, cp15
.vtcr_el2
) },
3714 { .name
= "VTTBR", .state
= ARM_CP_STATE_AA32
,
3715 .cp
= 15, .opc1
= 6, .crm
= 2,
3716 .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
3717 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
3718 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
),
3719 .writefn
= vttbr_write
},
3720 { .name
= "VTTBR_EL2", .state
= ARM_CP_STATE_AA64
,
3721 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 1, .opc2
= 0,
3722 .access
= PL2_RW
, .writefn
= vttbr_write
,
3723 .fieldoffset
= offsetof(CPUARMState
, cp15
.vttbr_el2
) },
3724 { .name
= "SCTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
3725 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 0,
3726 .access
= PL2_RW
, .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
3727 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[2]) },
3728 { .name
= "TPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
3729 .opc0
= 3, .opc1
= 4, .crn
= 13, .crm
= 0, .opc2
= 2,
3730 .access
= PL2_RW
, .resetvalue
= 0,
3731 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[2]) },
3732 { .name
= "TTBR0_EL2", .state
= ARM_CP_STATE_AA64
,
3733 .opc0
= 3, .opc1
= 4, .crn
= 2, .crm
= 0, .opc2
= 0,
3734 .access
= PL2_RW
, .resetvalue
= 0,
3735 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
3736 { .name
= "HTTBR", .cp
= 15, .opc1
= 4, .crm
= 2,
3737 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
,
3738 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[2]) },
3739 { .name
= "TLBIALLNSNH",
3740 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 4,
3741 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3742 .writefn
= tlbiall_nsnh_write
},
3743 { .name
= "TLBIALLNSNHIS",
3744 .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 4,
3745 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3746 .writefn
= tlbiall_nsnh_is_write
},
3747 { .name
= "TLBIALLH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
3748 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3749 .writefn
= tlbiall_hyp_write
},
3750 { .name
= "TLBIALLHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
3751 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3752 .writefn
= tlbiall_hyp_is_write
},
3753 { .name
= "TLBIMVAH", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
3754 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3755 .writefn
= tlbimva_hyp_write
},
3756 { .name
= "TLBIMVAHIS", .cp
= 15, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
3757 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3758 .writefn
= tlbimva_hyp_is_write
},
3759 { .name
= "TLBI_ALLE2", .state
= ARM_CP_STATE_AA64
,
3760 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 0,
3761 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3762 .writefn
= tlbi_aa64_alle2_write
},
3763 { .name
= "TLBI_VAE2", .state
= ARM_CP_STATE_AA64
,
3764 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 1,
3765 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3766 .writefn
= tlbi_aa64_vae2_write
},
3767 { .name
= "TLBI_VALE2", .state
= ARM_CP_STATE_AA64
,
3768 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 7, .opc2
= 5,
3769 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
3770 .writefn
= tlbi_aa64_vae2_write
},
3771 { .name
= "TLBI_ALLE2IS", .state
= ARM_CP_STATE_AA64
,
3772 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 0,
3773 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
3774 .writefn
= tlbi_aa64_alle2is_write
},
3775 { .name
= "TLBI_VAE2IS", .state
= ARM_CP_STATE_AA64
,
3776 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 1,
3777 .type
= ARM_CP_NO_RAW
, .access
= PL2_W
,
3778 .writefn
= tlbi_aa64_vae2is_write
},
3779 { .name
= "TLBI_VALE2IS", .state
= ARM_CP_STATE_AA64
,
3780 .opc0
= 1, .opc1
= 4, .crn
= 8, .crm
= 3, .opc2
= 5,
3781 .access
= PL2_W
, .type
= ARM_CP_NO_RAW
,
3782 .writefn
= tlbi_aa64_vae2is_write
},
3783 #ifndef CONFIG_USER_ONLY
3784 /* Unlike the other EL2-related AT operations, these must
3785 * UNDEF from EL3 if EL2 is not implemented, which is why we
3786 * define them here rather than with the rest of the AT ops.
3788 { .name
= "AT_S1E2R", .state
= ARM_CP_STATE_AA64
,
3789 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
3790 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
3791 .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3792 { .name
= "AT_S1E2W", .state
= ARM_CP_STATE_AA64
,
3793 .opc0
= 1, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
3794 .access
= PL2_W
, .accessfn
= at_s1e2_access
,
3795 .type
= ARM_CP_NO_RAW
, .writefn
= ats_write64
},
3796 /* The AArch32 ATS1H* operations are CONSTRAINED UNPREDICTABLE
3797 * if EL2 is not implemented; we choose to UNDEF. Behaviour at EL3
3798 * with SCR.NS == 0 outside Monitor mode is UNPREDICTABLE; we choose
3799 * to behave as if SCR.NS was 1.
3801 { .name
= "ATS1HR", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 0,
3803 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
},
3804 { .name
= "ATS1HW", .cp
= 15, .opc1
= 4, .crn
= 7, .crm
= 8, .opc2
= 1,
3806 .writefn
= ats1h_write
, .type
= ARM_CP_NO_RAW
},
3807 { .name
= "CNTHCTL_EL2", .state
= ARM_CP_STATE_BOTH
,
3808 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 1, .opc2
= 0,
3809 /* ARMv7 requires bit 0 and 1 to reset to 1. ARMv8 defines the
3810 * reset values as IMPDEF. We choose to reset to 3 to comply with
3811 * both ARMv7 and ARMv8.
3813 .access
= PL2_RW
, .resetvalue
= 3,
3814 .fieldoffset
= offsetof(CPUARMState
, cp15
.cnthctl_el2
) },
3815 { .name
= "CNTVOFF_EL2", .state
= ARM_CP_STATE_AA64
,
3816 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 0, .opc2
= 3,
3817 .access
= PL2_RW
, .type
= ARM_CP_IO
, .resetvalue
= 0,
3818 .writefn
= gt_cntvoff_write
,
3819 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
3820 { .name
= "CNTVOFF", .cp
= 15, .opc1
= 4, .crm
= 14,
3821 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_ALIAS
| ARM_CP_IO
,
3822 .writefn
= gt_cntvoff_write
,
3823 .fieldoffset
= offsetof(CPUARMState
, cp15
.cntvoff_el2
) },
3824 { .name
= "CNTHP_CVAL_EL2", .state
= ARM_CP_STATE_AA64
,
3825 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 2,
3826 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
3827 .type
= ARM_CP_IO
, .access
= PL2_RW
,
3828 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
3829 { .name
= "CNTHP_CVAL", .cp
= 15, .opc1
= 6, .crm
= 14,
3830 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].cval
),
3831 .access
= PL2_RW
, .type
= ARM_CP_64BIT
| ARM_CP_IO
,
3832 .writefn
= gt_hyp_cval_write
, .raw_writefn
= raw_write
},
3833 { .name
= "CNTHP_TVAL_EL2", .state
= ARM_CP_STATE_BOTH
,
3834 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 0,
3835 .type
= ARM_CP_NO_RAW
| ARM_CP_IO
, .access
= PL2_RW
,
3836 .resetfn
= gt_hyp_timer_reset
,
3837 .readfn
= gt_hyp_tval_read
, .writefn
= gt_hyp_tval_write
},
3838 { .name
= "CNTHP_CTL_EL2", .state
= ARM_CP_STATE_BOTH
,
3840 .opc0
= 3, .opc1
= 4, .crn
= 14, .crm
= 2, .opc2
= 1,
3842 .fieldoffset
= offsetof(CPUARMState
, cp15
.c14_timer
[GTIMER_HYP
].ctl
),
3844 .writefn
= gt_hyp_ctl_write
, .raw_writefn
= raw_write
},
3846 /* The only field of MDCR_EL2 that has a defined architectural reset value
3847 * is MDCR_EL2.HPMN which should reset to the value of PMCR_EL0.N; but we
3848 * don't impelment any PMU event counters, so using zero as a reset
3849 * value for MDCR_EL2 is okay
3851 { .name
= "MDCR_EL2", .state
= ARM_CP_STATE_BOTH
,
3852 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 1,
3853 .access
= PL2_RW
, .resetvalue
= 0,
3854 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdcr_el2
), },
3855 { .name
= "HPFAR", .state
= ARM_CP_STATE_AA32
,
3856 .cp
= 15, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
3857 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
3858 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
3859 { .name
= "HPFAR_EL2", .state
= ARM_CP_STATE_AA64
,
3860 .opc0
= 3, .opc1
= 4, .crn
= 6, .crm
= 0, .opc2
= 4,
3862 .fieldoffset
= offsetof(CPUARMState
, cp15
.hpfar_el2
) },
3863 { .name
= "HSTR_EL2", .state
= ARM_CP_STATE_BOTH
,
3864 .cp
= 15, .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 1, .opc2
= 3,
3866 .fieldoffset
= offsetof(CPUARMState
, cp15
.hstr_el2
) },
3870 static CPAccessResult
nsacr_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3873 /* The NSACR is RW at EL3, and RO for NS EL1 and NS EL2.
3874 * At Secure EL1 it traps to EL3.
3876 if (arm_current_el(env
) == 3) {
3877 return CP_ACCESS_OK
;
3879 if (arm_is_secure_below_el3(env
)) {
3880 return CP_ACCESS_TRAP_EL3
;
3882 /* Accesses from EL1 NS and EL2 NS are UNDEF for write but allow reads. */
3884 return CP_ACCESS_OK
;
3886 return CP_ACCESS_TRAP_UNCATEGORIZED
;
3889 static const ARMCPRegInfo el3_cp_reginfo
[] = {
3890 { .name
= "SCR_EL3", .state
= ARM_CP_STATE_AA64
,
3891 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 0,
3892 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.scr_el3
),
3893 .resetvalue
= 0, .writefn
= scr_write
},
3894 { .name
= "SCR", .type
= ARM_CP_ALIAS
,
3895 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 0,
3896 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
3897 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.scr_el3
),
3898 .writefn
= scr_write
},
3899 { .name
= "SDER32_EL3", .state
= ARM_CP_STATE_AA64
,
3900 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 1,
3901 .access
= PL3_RW
, .resetvalue
= 0,
3902 .fieldoffset
= offsetof(CPUARMState
, cp15
.sder
) },
3904 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 1,
3905 .access
= PL3_RW
, .resetvalue
= 0,
3906 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.sder
) },
3907 { .name
= "MVBAR", .cp
= 15, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
3908 .access
= PL1_RW
, .accessfn
= access_trap_aa32s_el1
,
3909 .writefn
= vbar_write
, .resetvalue
= 0,
3910 .fieldoffset
= offsetof(CPUARMState
, cp15
.mvbar
) },
3911 { .name
= "TTBR0_EL3", .state
= ARM_CP_STATE_AA64
,
3912 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 0,
3913 .access
= PL3_RW
, .writefn
= vmsa_ttbr_write
, .resetvalue
= 0,
3914 .fieldoffset
= offsetof(CPUARMState
, cp15
.ttbr0_el
[3]) },
3915 { .name
= "TCR_EL3", .state
= ARM_CP_STATE_AA64
,
3916 .opc0
= 3, .opc1
= 6, .crn
= 2, .crm
= 0, .opc2
= 2,
3918 /* no .writefn needed as this can't cause an ASID change;
3919 * we must provide a .raw_writefn and .resetfn because we handle
3920 * reset and migration for the AArch32 TTBCR(S), which might be
3921 * using mask and base_mask.
3923 .resetfn
= vmsa_ttbcr_reset
, .raw_writefn
= vmsa_ttbcr_raw_write
,
3924 .fieldoffset
= offsetof(CPUARMState
, cp15
.tcr_el
[3]) },
3925 { .name
= "ELR_EL3", .state
= ARM_CP_STATE_AA64
,
3926 .type
= ARM_CP_ALIAS
,
3927 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 1,
3929 .fieldoffset
= offsetof(CPUARMState
, elr_el
[3]) },
3930 { .name
= "ESR_EL3", .state
= ARM_CP_STATE_AA64
,
3931 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 2, .opc2
= 0,
3932 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.esr_el
[3]) },
3933 { .name
= "FAR_EL3", .state
= ARM_CP_STATE_AA64
,
3934 .opc0
= 3, .opc1
= 6, .crn
= 6, .crm
= 0, .opc2
= 0,
3935 .access
= PL3_RW
, .fieldoffset
= offsetof(CPUARMState
, cp15
.far_el
[3]) },
3936 { .name
= "SPSR_EL3", .state
= ARM_CP_STATE_AA64
,
3937 .type
= ARM_CP_ALIAS
,
3938 .opc0
= 3, .opc1
= 6, .crn
= 4, .crm
= 0, .opc2
= 0,
3940 .fieldoffset
= offsetof(CPUARMState
, banked_spsr
[BANK_MON
]) },
3941 { .name
= "VBAR_EL3", .state
= ARM_CP_STATE_AA64
,
3942 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 0,
3943 .access
= PL3_RW
, .writefn
= vbar_write
,
3944 .fieldoffset
= offsetof(CPUARMState
, cp15
.vbar_el
[3]),
3946 { .name
= "CPTR_EL3", .state
= ARM_CP_STATE_AA64
,
3947 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 1, .opc2
= 2,
3948 .access
= PL3_RW
, .accessfn
= cptr_access
, .resetvalue
= 0,
3949 .fieldoffset
= offsetof(CPUARMState
, cp15
.cptr_el
[3]) },
3950 { .name
= "TPIDR_EL3", .state
= ARM_CP_STATE_AA64
,
3951 .opc0
= 3, .opc1
= 6, .crn
= 13, .crm
= 0, .opc2
= 2,
3952 .access
= PL3_RW
, .resetvalue
= 0,
3953 .fieldoffset
= offsetof(CPUARMState
, cp15
.tpidr_el
[3]) },
3954 { .name
= "AMAIR_EL3", .state
= ARM_CP_STATE_AA64
,
3955 .opc0
= 3, .opc1
= 6, .crn
= 10, .crm
= 3, .opc2
= 0,
3956 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
3958 { .name
= "AFSR0_EL3", .state
= ARM_CP_STATE_BOTH
,
3959 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 0,
3960 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
3962 { .name
= "AFSR1_EL3", .state
= ARM_CP_STATE_BOTH
,
3963 .opc0
= 3, .opc1
= 6, .crn
= 5, .crm
= 1, .opc2
= 1,
3964 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
3966 { .name
= "TLBI_ALLE3IS", .state
= ARM_CP_STATE_AA64
,
3967 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 0,
3968 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
3969 .writefn
= tlbi_aa64_alle3is_write
},
3970 { .name
= "TLBI_VAE3IS", .state
= ARM_CP_STATE_AA64
,
3971 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 1,
3972 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
3973 .writefn
= tlbi_aa64_vae3is_write
},
3974 { .name
= "TLBI_VALE3IS", .state
= ARM_CP_STATE_AA64
,
3975 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 3, .opc2
= 5,
3976 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
3977 .writefn
= tlbi_aa64_vae3is_write
},
3978 { .name
= "TLBI_ALLE3", .state
= ARM_CP_STATE_AA64
,
3979 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 0,
3980 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
3981 .writefn
= tlbi_aa64_alle3_write
},
3982 { .name
= "TLBI_VAE3", .state
= ARM_CP_STATE_AA64
,
3983 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 1,
3984 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
3985 .writefn
= tlbi_aa64_vae3_write
},
3986 { .name
= "TLBI_VALE3", .state
= ARM_CP_STATE_AA64
,
3987 .opc0
= 1, .opc1
= 6, .crn
= 8, .crm
= 7, .opc2
= 5,
3988 .access
= PL3_W
, .type
= ARM_CP_NO_RAW
,
3989 .writefn
= tlbi_aa64_vae3_write
},
3993 static CPAccessResult
ctr_el0_access(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
3996 /* Only accessible in EL0 if SCTLR.UCT is set (and only in AArch64,
3997 * but the AArch32 CTR has its own reginfo struct)
3999 if (arm_current_el(env
) == 0 && !(env
->cp15
.sctlr_el
[1] & SCTLR_UCT
)) {
4000 return CP_ACCESS_TRAP
;
4002 return CP_ACCESS_OK
;
4005 static void oslar_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4008 /* Writes to OSLAR_EL1 may update the OS lock status, which can be
4009 * read via a bit in OSLSR_EL1.
4013 if (ri
->state
== ARM_CP_STATE_AA32
) {
4014 oslock
= (value
== 0xC5ACCE55);
4019 env
->cp15
.oslsr_el1
= deposit32(env
->cp15
.oslsr_el1
, 1, 1, oslock
);
4022 static const ARMCPRegInfo debug_cp_reginfo
[] = {
4023 /* DBGDRAR, DBGDSAR: always RAZ since we don't implement memory mapped
4024 * debug components. The AArch64 version of DBGDRAR is named MDRAR_EL1;
4025 * unlike DBGDRAR it is never accessible from EL0.
4026 * DBGDSAR is deprecated and must RAZ from v8 anyway, so it has no AArch64
4029 { .name
= "DBGDRAR", .cp
= 14, .crn
= 1, .crm
= 0, .opc1
= 0, .opc2
= 0,
4030 .access
= PL0_R
, .accessfn
= access_tdra
,
4031 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4032 { .name
= "MDRAR_EL1", .state
= ARM_CP_STATE_AA64
,
4033 .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 0,
4034 .access
= PL1_R
, .accessfn
= access_tdra
,
4035 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4036 { .name
= "DBGDSAR", .cp
= 14, .crn
= 2, .crm
= 0, .opc1
= 0, .opc2
= 0,
4037 .access
= PL0_R
, .accessfn
= access_tdra
,
4038 .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4039 /* Monitor debug system control register; the 32-bit alias is DBGDSCRext. */
4040 { .name
= "MDSCR_EL1", .state
= ARM_CP_STATE_BOTH
,
4041 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 2,
4042 .access
= PL1_RW
, .accessfn
= access_tda
,
4043 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdscr_el1
),
4045 /* MDCCSR_EL0, aka DBGDSCRint. This is a read-only mirror of MDSCR_EL1.
4046 * We don't implement the configurable EL0 access.
4048 { .name
= "MDCCSR_EL0", .state
= ARM_CP_STATE_BOTH
,
4049 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 0,
4050 .type
= ARM_CP_ALIAS
,
4051 .access
= PL1_R
, .accessfn
= access_tda
,
4052 .fieldoffset
= offsetof(CPUARMState
, cp15
.mdscr_el1
), },
4053 { .name
= "OSLAR_EL1", .state
= ARM_CP_STATE_BOTH
,
4054 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 4,
4055 .access
= PL1_W
, .type
= ARM_CP_NO_RAW
,
4056 .accessfn
= access_tdosa
,
4057 .writefn
= oslar_write
},
4058 { .name
= "OSLSR_EL1", .state
= ARM_CP_STATE_BOTH
,
4059 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 4,
4060 .access
= PL1_R
, .resetvalue
= 10,
4061 .accessfn
= access_tdosa
,
4062 .fieldoffset
= offsetof(CPUARMState
, cp15
.oslsr_el1
) },
4063 /* Dummy OSDLR_EL1: 32-bit Linux will read this */
4064 { .name
= "OSDLR_EL1", .state
= ARM_CP_STATE_BOTH
,
4065 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 1, .crm
= 3, .opc2
= 4,
4066 .access
= PL1_RW
, .accessfn
= access_tdosa
,
4067 .type
= ARM_CP_NOP
},
4068 /* Dummy DBGVCR: Linux wants to clear this on startup, but we don't
4069 * implement vector catch debug events yet.
4072 .cp
= 14, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 0,
4073 .access
= PL1_RW
, .accessfn
= access_tda
,
4074 .type
= ARM_CP_NOP
},
4075 /* Dummy MDCCINT_EL1, since we don't implement the Debug Communications
4076 * Channel but Linux may try to access this register. The 32-bit
4077 * alias is DBGDCCINT.
4079 { .name
= "MDCCINT_EL1", .state
= ARM_CP_STATE_BOTH
,
4080 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 0,
4081 .access
= PL1_RW
, .accessfn
= access_tda
,
4082 .type
= ARM_CP_NOP
},
4086 static const ARMCPRegInfo debug_lpae_cp_reginfo
[] = {
4087 /* 64 bit access versions of the (dummy) debug registers */
4088 { .name
= "DBGDRAR", .cp
= 14, .crm
= 1, .opc1
= 0,
4089 .access
= PL0_R
, .type
= ARM_CP_CONST
|ARM_CP_64BIT
, .resetvalue
= 0 },
4090 { .name
= "DBGDSAR", .cp
= 14, .crm
= 2, .opc1
= 0,
4091 .access
= PL0_R
, .type
= ARM_CP_CONST
|ARM_CP_64BIT
, .resetvalue
= 0 },
4095 void hw_watchpoint_update(ARMCPU
*cpu
, int n
)
4097 CPUARMState
*env
= &cpu
->env
;
4099 vaddr wvr
= env
->cp15
.dbgwvr
[n
];
4100 uint64_t wcr
= env
->cp15
.dbgwcr
[n
];
4102 int flags
= BP_CPU
| BP_STOP_BEFORE_ACCESS
;
4104 if (env
->cpu_watchpoint
[n
]) {
4105 cpu_watchpoint_remove_by_ref(CPU(cpu
), env
->cpu_watchpoint
[n
]);
4106 env
->cpu_watchpoint
[n
] = NULL
;
4109 if (!extract64(wcr
, 0, 1)) {
4110 /* E bit clear : watchpoint disabled */
4114 switch (extract64(wcr
, 3, 2)) {
4116 /* LSC 00 is reserved and must behave as if the wp is disabled */
4119 flags
|= BP_MEM_READ
;
4122 flags
|= BP_MEM_WRITE
;
4125 flags
|= BP_MEM_ACCESS
;
4129 /* Attempts to use both MASK and BAS fields simultaneously are
4130 * CONSTRAINED UNPREDICTABLE; we opt to ignore BAS in this case,
4131 * thus generating a watchpoint for every byte in the masked region.
4133 mask
= extract64(wcr
, 24, 4);
4134 if (mask
== 1 || mask
== 2) {
4135 /* Reserved values of MASK; we must act as if the mask value was
4136 * some non-reserved value, or as if the watchpoint were disabled.
4137 * We choose the latter.
4141 /* Watchpoint covers an aligned area up to 2GB in size */
4143 /* If masked bits in WVR are not zero it's CONSTRAINED UNPREDICTABLE
4144 * whether the watchpoint fires when the unmasked bits match; we opt
4145 * to generate the exceptions.
4149 /* Watchpoint covers bytes defined by the byte address select bits */
4150 int bas
= extract64(wcr
, 5, 8);
4154 /* This must act as if the watchpoint is disabled */
4158 if (extract64(wvr
, 2, 1)) {
4159 /* Deprecated case of an only 4-aligned address. BAS[7:4] are
4160 * ignored, and BAS[3:0] define which bytes to watch.
4164 /* The BAS bits are supposed to be programmed to indicate a contiguous
4165 * range of bytes. Otherwise it is CONSTRAINED UNPREDICTABLE whether
4166 * we fire for each byte in the word/doubleword addressed by the WVR.
4167 * We choose to ignore any non-zero bits after the first range of 1s.
4169 basstart
= ctz32(bas
);
4170 len
= cto32(bas
>> basstart
);
4174 cpu_watchpoint_insert(CPU(cpu
), wvr
, len
, flags
,
4175 &env
->cpu_watchpoint
[n
]);
4178 void hw_watchpoint_update_all(ARMCPU
*cpu
)
4181 CPUARMState
*env
= &cpu
->env
;
4183 /* Completely clear out existing QEMU watchpoints and our array, to
4184 * avoid possible stale entries following migration load.
4186 cpu_watchpoint_remove_all(CPU(cpu
), BP_CPU
);
4187 memset(env
->cpu_watchpoint
, 0, sizeof(env
->cpu_watchpoint
));
4189 for (i
= 0; i
< ARRAY_SIZE(cpu
->env
.cpu_watchpoint
); i
++) {
4190 hw_watchpoint_update(cpu
, i
);
4194 static void dbgwvr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4197 ARMCPU
*cpu
= arm_env_get_cpu(env
);
4200 /* Bits [63:49] are hardwired to the value of bit [48]; that is, the
4201 * register reads and behaves as if values written are sign extended.
4202 * Bits [1:0] are RES0.
4204 value
= sextract64(value
, 0, 49) & ~3ULL;
4206 raw_write(env
, ri
, value
);
4207 hw_watchpoint_update(cpu
, i
);
4210 static void dbgwcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4213 ARMCPU
*cpu
= arm_env_get_cpu(env
);
4216 raw_write(env
, ri
, value
);
4217 hw_watchpoint_update(cpu
, i
);
4220 void hw_breakpoint_update(ARMCPU
*cpu
, int n
)
4222 CPUARMState
*env
= &cpu
->env
;
4223 uint64_t bvr
= env
->cp15
.dbgbvr
[n
];
4224 uint64_t bcr
= env
->cp15
.dbgbcr
[n
];
4229 if (env
->cpu_breakpoint
[n
]) {
4230 cpu_breakpoint_remove_by_ref(CPU(cpu
), env
->cpu_breakpoint
[n
]);
4231 env
->cpu_breakpoint
[n
] = NULL
;
4234 if (!extract64(bcr
, 0, 1)) {
4235 /* E bit clear : watchpoint disabled */
4239 bt
= extract64(bcr
, 20, 4);
4242 case 4: /* unlinked address mismatch (reserved if AArch64) */
4243 case 5: /* linked address mismatch (reserved if AArch64) */
4244 qemu_log_mask(LOG_UNIMP
,
4245 "arm: address mismatch breakpoint types not implemented");
4247 case 0: /* unlinked address match */
4248 case 1: /* linked address match */
4250 /* Bits [63:49] are hardwired to the value of bit [48]; that is,
4251 * we behave as if the register was sign extended. Bits [1:0] are
4252 * RES0. The BAS field is used to allow setting breakpoints on 16
4253 * bit wide instructions; it is CONSTRAINED UNPREDICTABLE whether
4254 * a bp will fire if the addresses covered by the bp and the addresses
4255 * covered by the insn overlap but the insn doesn't start at the
4256 * start of the bp address range. We choose to require the insn and
4257 * the bp to have the same address. The constraints on writing to
4258 * BAS enforced in dbgbcr_write mean we have only four cases:
4259 * 0b0000 => no breakpoint
4260 * 0b0011 => breakpoint on addr
4261 * 0b1100 => breakpoint on addr + 2
4262 * 0b1111 => breakpoint on addr
4263 * See also figure D2-3 in the v8 ARM ARM (DDI0487A.c).
4265 int bas
= extract64(bcr
, 5, 4);
4266 addr
= sextract64(bvr
, 0, 49) & ~3ULL;
4275 case 2: /* unlinked context ID match */
4276 case 8: /* unlinked VMID match (reserved if no EL2) */
4277 case 10: /* unlinked context ID and VMID match (reserved if no EL2) */
4278 qemu_log_mask(LOG_UNIMP
,
4279 "arm: unlinked context breakpoint types not implemented");
4281 case 9: /* linked VMID match (reserved if no EL2) */
4282 case 11: /* linked context ID and VMID match (reserved if no EL2) */
4283 case 3: /* linked context ID match */
4285 /* We must generate no events for Linked context matches (unless
4286 * they are linked to by some other bp/wp, which is handled in
4287 * updates for the linking bp/wp). We choose to also generate no events
4288 * for reserved values.
4293 cpu_breakpoint_insert(CPU(cpu
), addr
, flags
, &env
->cpu_breakpoint
[n
]);
4296 void hw_breakpoint_update_all(ARMCPU
*cpu
)
4299 CPUARMState
*env
= &cpu
->env
;
4301 /* Completely clear out existing QEMU breakpoints and our array, to
4302 * avoid possible stale entries following migration load.
4304 cpu_breakpoint_remove_all(CPU(cpu
), BP_CPU
);
4305 memset(env
->cpu_breakpoint
, 0, sizeof(env
->cpu_breakpoint
));
4307 for (i
= 0; i
< ARRAY_SIZE(cpu
->env
.cpu_breakpoint
); i
++) {
4308 hw_breakpoint_update(cpu
, i
);
4312 static void dbgbvr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4315 ARMCPU
*cpu
= arm_env_get_cpu(env
);
4318 raw_write(env
, ri
, value
);
4319 hw_breakpoint_update(cpu
, i
);
4322 static void dbgbcr_write(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
4325 ARMCPU
*cpu
= arm_env_get_cpu(env
);
4328 /* BAS[3] is a read-only copy of BAS[2], and BAS[1] a read-only
4331 value
= deposit64(value
, 6, 1, extract64(value
, 5, 1));
4332 value
= deposit64(value
, 8, 1, extract64(value
, 7, 1));
4334 raw_write(env
, ri
, value
);
4335 hw_breakpoint_update(cpu
, i
);
4338 static void define_debug_regs(ARMCPU
*cpu
)
4340 /* Define v7 and v8 architectural debug registers.
4341 * These are just dummy implementations for now.
4344 int wrps
, brps
, ctx_cmps
;
4345 ARMCPRegInfo dbgdidr
= {
4346 .name
= "DBGDIDR", .cp
= 14, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 0,
4347 .access
= PL0_R
, .accessfn
= access_tda
,
4348 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->dbgdidr
,
4351 /* Note that all these register fields hold "number of Xs minus 1". */
4352 brps
= extract32(cpu
->dbgdidr
, 24, 4);
4353 wrps
= extract32(cpu
->dbgdidr
, 28, 4);
4354 ctx_cmps
= extract32(cpu
->dbgdidr
, 20, 4);
4356 assert(ctx_cmps
<= brps
);
4358 /* The DBGDIDR and ID_AA64DFR0_EL1 define various properties
4359 * of the debug registers such as number of breakpoints;
4360 * check that if they both exist then they agree.
4362 if (arm_feature(&cpu
->env
, ARM_FEATURE_AARCH64
)) {
4363 assert(extract32(cpu
->id_aa64dfr0
, 12, 4) == brps
);
4364 assert(extract32(cpu
->id_aa64dfr0
, 20, 4) == wrps
);
4365 assert(extract32(cpu
->id_aa64dfr0
, 28, 4) == ctx_cmps
);
4368 define_one_arm_cp_reg(cpu
, &dbgdidr
);
4369 define_arm_cp_regs(cpu
, debug_cp_reginfo
);
4371 if (arm_feature(&cpu
->env
, ARM_FEATURE_LPAE
)) {
4372 define_arm_cp_regs(cpu
, debug_lpae_cp_reginfo
);
4375 for (i
= 0; i
< brps
+ 1; i
++) {
4376 ARMCPRegInfo dbgregs
[] = {
4377 { .name
= "DBGBVR", .state
= ARM_CP_STATE_BOTH
,
4378 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 4,
4379 .access
= PL1_RW
, .accessfn
= access_tda
,
4380 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgbvr
[i
]),
4381 .writefn
= dbgbvr_write
, .raw_writefn
= raw_write
4383 { .name
= "DBGBCR", .state
= ARM_CP_STATE_BOTH
,
4384 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 5,
4385 .access
= PL1_RW
, .accessfn
= access_tda
,
4386 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgbcr
[i
]),
4387 .writefn
= dbgbcr_write
, .raw_writefn
= raw_write
4391 define_arm_cp_regs(cpu
, dbgregs
);
4394 for (i
= 0; i
< wrps
+ 1; i
++) {
4395 ARMCPRegInfo dbgregs
[] = {
4396 { .name
= "DBGWVR", .state
= ARM_CP_STATE_BOTH
,
4397 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 6,
4398 .access
= PL1_RW
, .accessfn
= access_tda
,
4399 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgwvr
[i
]),
4400 .writefn
= dbgwvr_write
, .raw_writefn
= raw_write
4402 { .name
= "DBGWCR", .state
= ARM_CP_STATE_BOTH
,
4403 .cp
= 14, .opc0
= 2, .opc1
= 0, .crn
= 0, .crm
= i
, .opc2
= 7,
4404 .access
= PL1_RW
, .accessfn
= access_tda
,
4405 .fieldoffset
= offsetof(CPUARMState
, cp15
.dbgwcr
[i
]),
4406 .writefn
= dbgwcr_write
, .raw_writefn
= raw_write
4410 define_arm_cp_regs(cpu
, dbgregs
);
4414 void register_cp_regs_for_features(ARMCPU
*cpu
)
4416 /* Register all the coprocessor registers based on feature bits */
4417 CPUARMState
*env
= &cpu
->env
;
4418 if (arm_feature(env
, ARM_FEATURE_M
)) {
4419 /* M profile has no coprocessor registers */
4423 define_arm_cp_regs(cpu
, cp_reginfo
);
4424 if (!arm_feature(env
, ARM_FEATURE_V8
)) {
4425 /* Must go early as it is full of wildcards that may be
4426 * overridden by later definitions.
4428 define_arm_cp_regs(cpu
, not_v8_cp_reginfo
);
4431 if (arm_feature(env
, ARM_FEATURE_V6
)) {
4432 /* The ID registers all have impdef reset values */
4433 ARMCPRegInfo v6_idregs
[] = {
4434 { .name
= "ID_PFR0", .state
= ARM_CP_STATE_BOTH
,
4435 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 0,
4436 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4437 .resetvalue
= cpu
->id_pfr0
},
4438 { .name
= "ID_PFR1", .state
= ARM_CP_STATE_BOTH
,
4439 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 1,
4440 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4441 .resetvalue
= cpu
->id_pfr1
},
4442 { .name
= "ID_DFR0", .state
= ARM_CP_STATE_BOTH
,
4443 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 2,
4444 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4445 .resetvalue
= cpu
->id_dfr0
},
4446 { .name
= "ID_AFR0", .state
= ARM_CP_STATE_BOTH
,
4447 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 3,
4448 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4449 .resetvalue
= cpu
->id_afr0
},
4450 { .name
= "ID_MMFR0", .state
= ARM_CP_STATE_BOTH
,
4451 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 4,
4452 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4453 .resetvalue
= cpu
->id_mmfr0
},
4454 { .name
= "ID_MMFR1", .state
= ARM_CP_STATE_BOTH
,
4455 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 5,
4456 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4457 .resetvalue
= cpu
->id_mmfr1
},
4458 { .name
= "ID_MMFR2", .state
= ARM_CP_STATE_BOTH
,
4459 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 6,
4460 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4461 .resetvalue
= cpu
->id_mmfr2
},
4462 { .name
= "ID_MMFR3", .state
= ARM_CP_STATE_BOTH
,
4463 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 1, .opc2
= 7,
4464 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4465 .resetvalue
= cpu
->id_mmfr3
},
4466 { .name
= "ID_ISAR0", .state
= ARM_CP_STATE_BOTH
,
4467 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 0,
4468 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4469 .resetvalue
= cpu
->id_isar0
},
4470 { .name
= "ID_ISAR1", .state
= ARM_CP_STATE_BOTH
,
4471 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 1,
4472 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4473 .resetvalue
= cpu
->id_isar1
},
4474 { .name
= "ID_ISAR2", .state
= ARM_CP_STATE_BOTH
,
4475 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 2,
4476 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4477 .resetvalue
= cpu
->id_isar2
},
4478 { .name
= "ID_ISAR3", .state
= ARM_CP_STATE_BOTH
,
4479 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 3,
4480 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4481 .resetvalue
= cpu
->id_isar3
},
4482 { .name
= "ID_ISAR4", .state
= ARM_CP_STATE_BOTH
,
4483 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 4,
4484 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4485 .resetvalue
= cpu
->id_isar4
},
4486 { .name
= "ID_ISAR5", .state
= ARM_CP_STATE_BOTH
,
4487 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 5,
4488 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4489 .resetvalue
= cpu
->id_isar5
},
4490 { .name
= "ID_MMFR4", .state
= ARM_CP_STATE_BOTH
,
4491 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 6,
4492 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4493 .resetvalue
= cpu
->id_mmfr4
},
4494 /* 7 is as yet unallocated and must RAZ */
4495 { .name
= "ID_ISAR7_RESERVED", .state
= ARM_CP_STATE_BOTH
,
4496 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 2, .opc2
= 7,
4497 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4501 define_arm_cp_regs(cpu
, v6_idregs
);
4502 define_arm_cp_regs(cpu
, v6_cp_reginfo
);
4504 define_arm_cp_regs(cpu
, not_v6_cp_reginfo
);
4506 if (arm_feature(env
, ARM_FEATURE_V6K
)) {
4507 define_arm_cp_regs(cpu
, v6k_cp_reginfo
);
4509 if (arm_feature(env
, ARM_FEATURE_V7MP
) &&
4510 !arm_feature(env
, ARM_FEATURE_MPU
)) {
4511 define_arm_cp_regs(cpu
, v7mp_cp_reginfo
);
4513 if (arm_feature(env
, ARM_FEATURE_V7
)) {
4514 /* v7 performance monitor control register: same implementor
4515 * field as main ID register, and we implement only the cycle
4518 #ifndef CONFIG_USER_ONLY
4519 ARMCPRegInfo pmcr
= {
4520 .name
= "PMCR", .cp
= 15, .crn
= 9, .crm
= 12, .opc1
= 0, .opc2
= 0,
4522 .type
= ARM_CP_IO
| ARM_CP_ALIAS
,
4523 .fieldoffset
= offsetoflow32(CPUARMState
, cp15
.c9_pmcr
),
4524 .accessfn
= pmreg_access
, .writefn
= pmcr_write
,
4525 .raw_writefn
= raw_write
,
4527 ARMCPRegInfo pmcr64
= {
4528 .name
= "PMCR_EL0", .state
= ARM_CP_STATE_AA64
,
4529 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 0,
4530 .access
= PL0_RW
, .accessfn
= pmreg_access
,
4532 .fieldoffset
= offsetof(CPUARMState
, cp15
.c9_pmcr
),
4533 .resetvalue
= cpu
->midr
& 0xff000000,
4534 .writefn
= pmcr_write
, .raw_writefn
= raw_write
,
4536 define_one_arm_cp_reg(cpu
, &pmcr
);
4537 define_one_arm_cp_reg(cpu
, &pmcr64
);
4539 ARMCPRegInfo clidr
= {
4540 .name
= "CLIDR", .state
= ARM_CP_STATE_BOTH
,
4541 .opc0
= 3, .crn
= 0, .crm
= 0, .opc1
= 1, .opc2
= 1,
4542 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= cpu
->clidr
4544 define_one_arm_cp_reg(cpu
, &clidr
);
4545 define_arm_cp_regs(cpu
, v7_cp_reginfo
);
4546 define_debug_regs(cpu
);
4548 define_arm_cp_regs(cpu
, not_v7_cp_reginfo
);
4550 if (arm_feature(env
, ARM_FEATURE_V8
)) {
4551 /* AArch64 ID registers, which all have impdef reset values.
4552 * Note that within the ID register ranges the unused slots
4553 * must all RAZ, not UNDEF; future architecture versions may
4554 * define new registers here.
4556 ARMCPRegInfo v8_idregs
[] = {
4557 { .name
= "ID_AA64PFR0_EL1", .state
= ARM_CP_STATE_AA64
,
4558 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 0,
4559 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4560 .resetvalue
= cpu
->id_aa64pfr0
},
4561 { .name
= "ID_AA64PFR1_EL1", .state
= ARM_CP_STATE_AA64
,
4562 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 1,
4563 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4564 .resetvalue
= cpu
->id_aa64pfr1
},
4565 { .name
= "ID_AA64PFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4566 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 2,
4567 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4569 { .name
= "ID_AA64PFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4570 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 3,
4571 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4573 { .name
= "ID_AA64PFR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4574 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 4,
4575 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4577 { .name
= "ID_AA64PFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4578 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 5,
4579 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4581 { .name
= "ID_AA64PFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4582 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 6,
4583 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4585 { .name
= "ID_AA64PFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4586 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 4, .opc2
= 7,
4587 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4589 { .name
= "ID_AA64DFR0_EL1", .state
= ARM_CP_STATE_AA64
,
4590 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 0,
4591 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4592 /* We mask out the PMUVer field, because we don't currently
4593 * implement the PMU. Not advertising it prevents the guest
4594 * from trying to use it and getting UNDEFs on registers we
4597 .resetvalue
= cpu
->id_aa64dfr0
& ~0xf00 },
4598 { .name
= "ID_AA64DFR1_EL1", .state
= ARM_CP_STATE_AA64
,
4599 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 1,
4600 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4601 .resetvalue
= cpu
->id_aa64dfr1
},
4602 { .name
= "ID_AA64DFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4603 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 2,
4604 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4606 { .name
= "ID_AA64DFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4607 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 3,
4608 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4610 { .name
= "ID_AA64AFR0_EL1", .state
= ARM_CP_STATE_AA64
,
4611 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 4,
4612 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4613 .resetvalue
= cpu
->id_aa64afr0
},
4614 { .name
= "ID_AA64AFR1_EL1", .state
= ARM_CP_STATE_AA64
,
4615 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 5,
4616 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4617 .resetvalue
= cpu
->id_aa64afr1
},
4618 { .name
= "ID_AA64AFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4619 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 6,
4620 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4622 { .name
= "ID_AA64AFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4623 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 5, .opc2
= 7,
4624 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4626 { .name
= "ID_AA64ISAR0_EL1", .state
= ARM_CP_STATE_AA64
,
4627 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 0,
4628 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4629 .resetvalue
= cpu
->id_aa64isar0
},
4630 { .name
= "ID_AA64ISAR1_EL1", .state
= ARM_CP_STATE_AA64
,
4631 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 1,
4632 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4633 .resetvalue
= cpu
->id_aa64isar1
},
4634 { .name
= "ID_AA64ISAR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4635 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 2,
4636 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4638 { .name
= "ID_AA64ISAR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4639 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 3,
4640 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4642 { .name
= "ID_AA64ISAR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4643 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 4,
4644 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4646 { .name
= "ID_AA64ISAR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4647 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 5,
4648 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4650 { .name
= "ID_AA64ISAR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4651 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 6,
4652 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4654 { .name
= "ID_AA64ISAR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4655 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 6, .opc2
= 7,
4656 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4658 { .name
= "ID_AA64MMFR0_EL1", .state
= ARM_CP_STATE_AA64
,
4659 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 0,
4660 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4661 .resetvalue
= cpu
->id_aa64mmfr0
},
4662 { .name
= "ID_AA64MMFR1_EL1", .state
= ARM_CP_STATE_AA64
,
4663 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 1,
4664 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4665 .resetvalue
= cpu
->id_aa64mmfr1
},
4666 { .name
= "ID_AA64MMFR2_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4667 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 2,
4668 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4670 { .name
= "ID_AA64MMFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4671 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 3,
4672 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4674 { .name
= "ID_AA64MMFR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4675 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 4,
4676 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4678 { .name
= "ID_AA64MMFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4679 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 5,
4680 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4682 { .name
= "ID_AA64MMFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4683 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 6,
4684 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4686 { .name
= "ID_AA64MMFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4687 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 7, .opc2
= 7,
4688 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4690 { .name
= "MVFR0_EL1", .state
= ARM_CP_STATE_AA64
,
4691 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 0,
4692 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4693 .resetvalue
= cpu
->mvfr0
},
4694 { .name
= "MVFR1_EL1", .state
= ARM_CP_STATE_AA64
,
4695 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 1,
4696 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4697 .resetvalue
= cpu
->mvfr1
},
4698 { .name
= "MVFR2_EL1", .state
= ARM_CP_STATE_AA64
,
4699 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 2,
4700 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4701 .resetvalue
= cpu
->mvfr2
},
4702 { .name
= "MVFR3_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4703 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 3,
4704 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4706 { .name
= "MVFR4_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4707 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 4,
4708 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4710 { .name
= "MVFR5_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4711 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 5,
4712 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4714 { .name
= "MVFR6_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4715 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 6,
4716 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4718 { .name
= "MVFR7_EL1_RESERVED", .state
= ARM_CP_STATE_AA64
,
4719 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 3, .opc2
= 7,
4720 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4722 { .name
= "PMCEID0", .state
= ARM_CP_STATE_AA32
,
4723 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 6,
4724 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
4725 .resetvalue
= cpu
->pmceid0
},
4726 { .name
= "PMCEID0_EL0", .state
= ARM_CP_STATE_AA64
,
4727 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 6,
4728 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
4729 .resetvalue
= cpu
->pmceid0
},
4730 { .name
= "PMCEID1", .state
= ARM_CP_STATE_AA32
,
4731 .cp
= 15, .opc1
= 0, .crn
= 9, .crm
= 12, .opc2
= 7,
4732 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
4733 .resetvalue
= cpu
->pmceid1
},
4734 { .name
= "PMCEID1_EL0", .state
= ARM_CP_STATE_AA64
,
4735 .opc0
= 3, .opc1
= 3, .crn
= 9, .crm
= 12, .opc2
= 7,
4736 .access
= PL0_R
, .accessfn
= pmreg_access
, .type
= ARM_CP_CONST
,
4737 .resetvalue
= cpu
->pmceid1
},
4740 /* RVBAR_EL1 is only implemented if EL1 is the highest EL */
4741 if (!arm_feature(env
, ARM_FEATURE_EL3
) &&
4742 !arm_feature(env
, ARM_FEATURE_EL2
)) {
4743 ARMCPRegInfo rvbar
= {
4744 .name
= "RVBAR_EL1", .state
= ARM_CP_STATE_AA64
,
4745 .opc0
= 3, .opc1
= 0, .crn
= 12, .crm
= 0, .opc2
= 1,
4746 .type
= ARM_CP_CONST
, .access
= PL1_R
, .resetvalue
= cpu
->rvbar
4748 define_one_arm_cp_reg(cpu
, &rvbar
);
4750 define_arm_cp_regs(cpu
, v8_idregs
);
4751 define_arm_cp_regs(cpu
, v8_cp_reginfo
);
4753 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
4754 uint64_t vmpidr_def
= mpidr_read_val(env
);
4755 ARMCPRegInfo vpidr_regs
[] = {
4756 { .name
= "VPIDR", .state
= ARM_CP_STATE_AA32
,
4757 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
4758 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
4759 .resetvalue
= cpu
->midr
,
4760 .fieldoffset
= offsetof(CPUARMState
, cp15
.vpidr_el2
) },
4761 { .name
= "VPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
4762 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
4763 .access
= PL2_RW
, .resetvalue
= cpu
->midr
,
4764 .fieldoffset
= offsetof(CPUARMState
, cp15
.vpidr_el2
) },
4765 { .name
= "VMPIDR", .state
= ARM_CP_STATE_AA32
,
4766 .cp
= 15, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
4767 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns
,
4768 .resetvalue
= vmpidr_def
,
4769 .fieldoffset
= offsetof(CPUARMState
, cp15
.vmpidr_el2
) },
4770 { .name
= "VMPIDR_EL2", .state
= ARM_CP_STATE_AA64
,
4771 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
4773 .resetvalue
= vmpidr_def
,
4774 .fieldoffset
= offsetof(CPUARMState
, cp15
.vmpidr_el2
) },
4777 define_arm_cp_regs(cpu
, vpidr_regs
);
4778 define_arm_cp_regs(cpu
, el2_cp_reginfo
);
4779 /* RVBAR_EL2 is only implemented if EL2 is the highest EL */
4780 if (!arm_feature(env
, ARM_FEATURE_EL3
)) {
4781 ARMCPRegInfo rvbar
= {
4782 .name
= "RVBAR_EL2", .state
= ARM_CP_STATE_AA64
,
4783 .opc0
= 3, .opc1
= 4, .crn
= 12, .crm
= 0, .opc2
= 1,
4784 .type
= ARM_CP_CONST
, .access
= PL2_R
, .resetvalue
= cpu
->rvbar
4786 define_one_arm_cp_reg(cpu
, &rvbar
);
4789 /* If EL2 is missing but higher ELs are enabled, we need to
4790 * register the no_el2 reginfos.
4792 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
4793 /* When EL3 exists but not EL2, VPIDR and VMPIDR take the value
4794 * of MIDR_EL1 and MPIDR_EL1.
4796 ARMCPRegInfo vpidr_regs
[] = {
4797 { .name
= "VPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
4798 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 0,
4799 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns_aa64any
,
4800 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->midr
,
4801 .fieldoffset
= offsetof(CPUARMState
, cp15
.vpidr_el2
) },
4802 { .name
= "VMPIDR_EL2", .state
= ARM_CP_STATE_BOTH
,
4803 .opc0
= 3, .opc1
= 4, .crn
= 0, .crm
= 0, .opc2
= 5,
4804 .access
= PL2_RW
, .accessfn
= access_el3_aa32ns_aa64any
,
4805 .type
= ARM_CP_NO_RAW
,
4806 .writefn
= arm_cp_write_ignore
, .readfn
= mpidr_read
},
4809 define_arm_cp_regs(cpu
, vpidr_regs
);
4810 define_arm_cp_regs(cpu
, el3_no_el2_cp_reginfo
);
4813 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
4814 define_arm_cp_regs(cpu
, el3_cp_reginfo
);
4815 ARMCPRegInfo el3_regs
[] = {
4816 { .name
= "RVBAR_EL3", .state
= ARM_CP_STATE_AA64
,
4817 .opc0
= 3, .opc1
= 6, .crn
= 12, .crm
= 0, .opc2
= 1,
4818 .type
= ARM_CP_CONST
, .access
= PL3_R
, .resetvalue
= cpu
->rvbar
},
4819 { .name
= "SCTLR_EL3", .state
= ARM_CP_STATE_AA64
,
4820 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 0,
4822 .raw_writefn
= raw_write
, .writefn
= sctlr_write
,
4823 .fieldoffset
= offsetof(CPUARMState
, cp15
.sctlr_el
[3]),
4824 .resetvalue
= cpu
->reset_sctlr
},
4828 define_arm_cp_regs(cpu
, el3_regs
);
4830 /* The behaviour of NSACR is sufficiently various that we don't
4831 * try to describe it in a single reginfo:
4832 * if EL3 is 64 bit, then trap to EL3 from S EL1,
4833 * reads as constant 0xc00 from NS EL1 and NS EL2
4834 * if EL3 is 32 bit, then RW at EL3, RO at NS EL1 and NS EL2
4835 * if v7 without EL3, register doesn't exist
4836 * if v8 without EL3, reads as constant 0xc00 from NS EL1 and NS EL2
4838 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
4839 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
4840 ARMCPRegInfo nsacr
= {
4841 .name
= "NSACR", .type
= ARM_CP_CONST
,
4842 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
4843 .access
= PL1_RW
, .accessfn
= nsacr_access
,
4846 define_one_arm_cp_reg(cpu
, &nsacr
);
4848 ARMCPRegInfo nsacr
= {
4850 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
4851 .access
= PL3_RW
| PL1_R
,
4853 .fieldoffset
= offsetof(CPUARMState
, cp15
.nsacr
)
4855 define_one_arm_cp_reg(cpu
, &nsacr
);
4858 if (arm_feature(env
, ARM_FEATURE_V8
)) {
4859 ARMCPRegInfo nsacr
= {
4860 .name
= "NSACR", .type
= ARM_CP_CONST
,
4861 .cp
= 15, .opc1
= 0, .crn
= 1, .crm
= 1, .opc2
= 2,
4865 define_one_arm_cp_reg(cpu
, &nsacr
);
4869 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
4870 if (arm_feature(env
, ARM_FEATURE_V6
)) {
4871 /* PMSAv6 not implemented */
4872 assert(arm_feature(env
, ARM_FEATURE_V7
));
4873 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
4874 define_arm_cp_regs(cpu
, pmsav7_cp_reginfo
);
4876 define_arm_cp_regs(cpu
, pmsav5_cp_reginfo
);
4879 define_arm_cp_regs(cpu
, vmsa_pmsa_cp_reginfo
);
4880 define_arm_cp_regs(cpu
, vmsa_cp_reginfo
);
4882 if (arm_feature(env
, ARM_FEATURE_THUMB2EE
)) {
4883 define_arm_cp_regs(cpu
, t2ee_cp_reginfo
);
4885 if (arm_feature(env
, ARM_FEATURE_GENERIC_TIMER
)) {
4886 define_arm_cp_regs(cpu
, generic_timer_cp_reginfo
);
4888 if (arm_feature(env
, ARM_FEATURE_VAPA
)) {
4889 define_arm_cp_regs(cpu
, vapa_cp_reginfo
);
4891 if (arm_feature(env
, ARM_FEATURE_CACHE_TEST_CLEAN
)) {
4892 define_arm_cp_regs(cpu
, cache_test_clean_cp_reginfo
);
4894 if (arm_feature(env
, ARM_FEATURE_CACHE_DIRTY_REG
)) {
4895 define_arm_cp_regs(cpu
, cache_dirty_status_cp_reginfo
);
4897 if (arm_feature(env
, ARM_FEATURE_CACHE_BLOCK_OPS
)) {
4898 define_arm_cp_regs(cpu
, cache_block_ops_cp_reginfo
);
4900 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
4901 define_arm_cp_regs(cpu
, omap_cp_reginfo
);
4903 if (arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
4904 define_arm_cp_regs(cpu
, strongarm_cp_reginfo
);
4906 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
4907 define_arm_cp_regs(cpu
, xscale_cp_reginfo
);
4909 if (arm_feature(env
, ARM_FEATURE_DUMMY_C15_REGS
)) {
4910 define_arm_cp_regs(cpu
, dummy_c15_cp_reginfo
);
4912 if (arm_feature(env
, ARM_FEATURE_LPAE
)) {
4913 define_arm_cp_regs(cpu
, lpae_cp_reginfo
);
4915 /* Slightly awkwardly, the OMAP and StrongARM cores need all of
4916 * cp15 crn=0 to be writes-ignored, whereas for other cores they should
4917 * be read-only (ie write causes UNDEF exception).
4920 ARMCPRegInfo id_pre_v8_midr_cp_reginfo
[] = {
4921 /* Pre-v8 MIDR space.
4922 * Note that the MIDR isn't a simple constant register because
4923 * of the TI925 behaviour where writes to another register can
4924 * cause the MIDR value to change.
4926 * Unimplemented registers in the c15 0 0 0 space default to
4927 * MIDR. Define MIDR first as this entire space, then CTR, TCMTR
4928 * and friends override accordingly.
4931 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= CP_ANY
,
4932 .access
= PL1_R
, .resetvalue
= cpu
->midr
,
4933 .writefn
= arm_cp_write_ignore
, .raw_writefn
= raw_write
,
4934 .readfn
= midr_read
,
4935 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
4936 .type
= ARM_CP_OVERRIDE
},
4937 /* crn = 0 op1 = 0 crm = 3..7 : currently unassigned; we RAZ. */
4939 .cp
= 15, .crn
= 0, .crm
= 3, .opc1
= 0, .opc2
= CP_ANY
,
4940 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4942 .cp
= 15, .crn
= 0, .crm
= 4, .opc1
= 0, .opc2
= CP_ANY
,
4943 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4945 .cp
= 15, .crn
= 0, .crm
= 5, .opc1
= 0, .opc2
= CP_ANY
,
4946 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4948 .cp
= 15, .crn
= 0, .crm
= 6, .opc1
= 0, .opc2
= CP_ANY
,
4949 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4951 .cp
= 15, .crn
= 0, .crm
= 7, .opc1
= 0, .opc2
= CP_ANY
,
4952 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4955 ARMCPRegInfo id_v8_midr_cp_reginfo
[] = {
4956 { .name
= "MIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
4957 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 0,
4958 .access
= PL1_R
, .type
= ARM_CP_NO_RAW
, .resetvalue
= cpu
->midr
,
4959 .fieldoffset
= offsetof(CPUARMState
, cp15
.c0_cpuid
),
4960 .readfn
= midr_read
},
4961 /* crn = 0 op1 = 0 crm = 0 op2 = 4,7 : AArch32 aliases of MIDR */
4962 { .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
,
4963 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
4964 .access
= PL1_R
, .resetvalue
= cpu
->midr
},
4965 { .name
= "MIDR", .type
= ARM_CP_ALIAS
| ARM_CP_CONST
,
4966 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 7,
4967 .access
= PL1_R
, .resetvalue
= cpu
->midr
},
4968 { .name
= "REVIDR_EL1", .state
= ARM_CP_STATE_BOTH
,
4969 .opc0
= 3, .opc1
= 0, .crn
= 0, .crm
= 0, .opc2
= 6,
4970 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= cpu
->revidr
},
4973 ARMCPRegInfo id_cp_reginfo
[] = {
4974 /* These are common to v8 and pre-v8 */
4976 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 1,
4977 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
4978 { .name
= "CTR_EL0", .state
= ARM_CP_STATE_AA64
,
4979 .opc0
= 3, .opc1
= 3, .opc2
= 1, .crn
= 0, .crm
= 0,
4980 .access
= PL0_R
, .accessfn
= ctr_el0_access
,
4981 .type
= ARM_CP_CONST
, .resetvalue
= cpu
->ctr
},
4982 /* TCMTR and TLBTR exist in v8 but have no 64-bit versions */
4984 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 2,
4985 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0 },
4988 /* TLBTR is specific to VMSA */
4989 ARMCPRegInfo id_tlbtr_reginfo
= {
4991 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 3,
4992 .access
= PL1_R
, .type
= ARM_CP_CONST
, .resetvalue
= 0,
4994 /* MPUIR is specific to PMSA V6+ */
4995 ARMCPRegInfo id_mpuir_reginfo
= {
4997 .cp
= 15, .crn
= 0, .crm
= 0, .opc1
= 0, .opc2
= 4,
4998 .access
= PL1_R
, .type
= ARM_CP_CONST
,
4999 .resetvalue
= cpu
->pmsav7_dregion
<< 8
5001 ARMCPRegInfo crn0_wi_reginfo
= {
5002 .name
= "CRN0_WI", .cp
= 15, .crn
= 0, .crm
= CP_ANY
,
5003 .opc1
= CP_ANY
, .opc2
= CP_ANY
, .access
= PL1_W
,
5004 .type
= ARM_CP_NOP
| ARM_CP_OVERRIDE
5006 if (arm_feature(env
, ARM_FEATURE_OMAPCP
) ||
5007 arm_feature(env
, ARM_FEATURE_STRONGARM
)) {
5009 /* Register the blanket "writes ignored" value first to cover the
5010 * whole space. Then update the specific ID registers to allow write
5011 * access, so that they ignore writes rather than causing them to
5014 define_one_arm_cp_reg(cpu
, &crn0_wi_reginfo
);
5015 for (r
= id_pre_v8_midr_cp_reginfo
;
5016 r
->type
!= ARM_CP_SENTINEL
; r
++) {
5019 for (r
= id_cp_reginfo
; r
->type
!= ARM_CP_SENTINEL
; r
++) {
5022 id_tlbtr_reginfo
.access
= PL1_RW
;
5023 id_tlbtr_reginfo
.access
= PL1_RW
;
5025 if (arm_feature(env
, ARM_FEATURE_V8
)) {
5026 define_arm_cp_regs(cpu
, id_v8_midr_cp_reginfo
);
5028 define_arm_cp_regs(cpu
, id_pre_v8_midr_cp_reginfo
);
5030 define_arm_cp_regs(cpu
, id_cp_reginfo
);
5031 if (!arm_feature(env
, ARM_FEATURE_MPU
)) {
5032 define_one_arm_cp_reg(cpu
, &id_tlbtr_reginfo
);
5033 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
5034 define_one_arm_cp_reg(cpu
, &id_mpuir_reginfo
);
5038 if (arm_feature(env
, ARM_FEATURE_MPIDR
)) {
5039 define_arm_cp_regs(cpu
, mpidr_cp_reginfo
);
5042 if (arm_feature(env
, ARM_FEATURE_AUXCR
)) {
5043 ARMCPRegInfo auxcr_reginfo
[] = {
5044 { .name
= "ACTLR_EL1", .state
= ARM_CP_STATE_BOTH
,
5045 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 1,
5046 .access
= PL1_RW
, .type
= ARM_CP_CONST
,
5047 .resetvalue
= cpu
->reset_auxcr
},
5048 { .name
= "ACTLR_EL2", .state
= ARM_CP_STATE_BOTH
,
5049 .opc0
= 3, .opc1
= 4, .crn
= 1, .crm
= 0, .opc2
= 1,
5050 .access
= PL2_RW
, .type
= ARM_CP_CONST
,
5052 { .name
= "ACTLR_EL3", .state
= ARM_CP_STATE_AA64
,
5053 .opc0
= 3, .opc1
= 6, .crn
= 1, .crm
= 0, .opc2
= 1,
5054 .access
= PL3_RW
, .type
= ARM_CP_CONST
,
5058 define_arm_cp_regs(cpu
, auxcr_reginfo
);
5061 if (arm_feature(env
, ARM_FEATURE_CBAR
)) {
5062 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
5063 /* 32 bit view is [31:18] 0...0 [43:32]. */
5064 uint32_t cbar32
= (extract64(cpu
->reset_cbar
, 18, 14) << 18)
5065 | extract64(cpu
->reset_cbar
, 32, 12);
5066 ARMCPRegInfo cbar_reginfo
[] = {
5068 .type
= ARM_CP_CONST
,
5069 .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 4, .opc2
= 0,
5070 .access
= PL1_R
, .resetvalue
= cpu
->reset_cbar
},
5071 { .name
= "CBAR_EL1", .state
= ARM_CP_STATE_AA64
,
5072 .type
= ARM_CP_CONST
,
5073 .opc0
= 3, .opc1
= 1, .crn
= 15, .crm
= 3, .opc2
= 0,
5074 .access
= PL1_R
, .resetvalue
= cbar32
},
5077 /* We don't implement a r/w 64 bit CBAR currently */
5078 assert(arm_feature(env
, ARM_FEATURE_CBAR_RO
));
5079 define_arm_cp_regs(cpu
, cbar_reginfo
);
5081 ARMCPRegInfo cbar
= {
5083 .cp
= 15, .crn
= 15, .crm
= 0, .opc1
= 4, .opc2
= 0,
5084 .access
= PL1_R
|PL3_W
, .resetvalue
= cpu
->reset_cbar
,
5085 .fieldoffset
= offsetof(CPUARMState
,
5086 cp15
.c15_config_base_address
)
5088 if (arm_feature(env
, ARM_FEATURE_CBAR_RO
)) {
5089 cbar
.access
= PL1_R
;
5090 cbar
.fieldoffset
= 0;
5091 cbar
.type
= ARM_CP_CONST
;
5093 define_one_arm_cp_reg(cpu
, &cbar
);
5097 /* Generic registers whose values depend on the implementation */
5099 ARMCPRegInfo sctlr
= {
5100 .name
= "SCTLR", .state
= ARM_CP_STATE_BOTH
,
5101 .opc0
= 3, .opc1
= 0, .crn
= 1, .crm
= 0, .opc2
= 0,
5103 .bank_fieldoffsets
= { offsetof(CPUARMState
, cp15
.sctlr_s
),
5104 offsetof(CPUARMState
, cp15
.sctlr_ns
) },
5105 .writefn
= sctlr_write
, .resetvalue
= cpu
->reset_sctlr
,
5106 .raw_writefn
= raw_write
,
5108 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
5109 /* Normally we would always end the TB on an SCTLR write, but Linux
5110 * arch/arm/mach-pxa/sleep.S expects two instructions following
5111 * an MMU enable to execute from cache. Imitate this behaviour.
5113 sctlr
.type
|= ARM_CP_SUPPRESS_TB_END
;
5115 define_one_arm_cp_reg(cpu
, &sctlr
);
5119 ARMCPU
*cpu_arm_init(const char *cpu_model
)
5121 return ARM_CPU(cpu_generic_init(TYPE_ARM_CPU
, cpu_model
));
5124 void arm_cpu_register_gdb_regs_for_features(ARMCPU
*cpu
)
5126 CPUState
*cs
= CPU(cpu
);
5127 CPUARMState
*env
= &cpu
->env
;
5129 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
5130 gdb_register_coprocessor(cs
, aarch64_fpu_gdb_get_reg
,
5131 aarch64_fpu_gdb_set_reg
,
5132 34, "aarch64-fpu.xml", 0);
5133 } else if (arm_feature(env
, ARM_FEATURE_NEON
)) {
5134 gdb_register_coprocessor(cs
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
5135 51, "arm-neon.xml", 0);
5136 } else if (arm_feature(env
, ARM_FEATURE_VFP3
)) {
5137 gdb_register_coprocessor(cs
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
5138 35, "arm-vfp3.xml", 0);
5139 } else if (arm_feature(env
, ARM_FEATURE_VFP
)) {
5140 gdb_register_coprocessor(cs
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
5141 19, "arm-vfp.xml", 0);
5145 /* Sort alphabetically by type name, except for "any". */
5146 static gint
arm_cpu_list_compare(gconstpointer a
, gconstpointer b
)
5148 ObjectClass
*class_a
= (ObjectClass
*)a
;
5149 ObjectClass
*class_b
= (ObjectClass
*)b
;
5150 const char *name_a
, *name_b
;
5152 name_a
= object_class_get_name(class_a
);
5153 name_b
= object_class_get_name(class_b
);
5154 if (strcmp(name_a
, "any-" TYPE_ARM_CPU
) == 0) {
5156 } else if (strcmp(name_b
, "any-" TYPE_ARM_CPU
) == 0) {
5159 return strcmp(name_a
, name_b
);
5163 static void arm_cpu_list_entry(gpointer data
, gpointer user_data
)
5165 ObjectClass
*oc
= data
;
5166 CPUListState
*s
= user_data
;
5167 const char *typename
;
5170 typename
= object_class_get_name(oc
);
5171 name
= g_strndup(typename
, strlen(typename
) - strlen("-" TYPE_ARM_CPU
));
5172 (*s
->cpu_fprintf
)(s
->file
, " %s\n",
5177 void arm_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
5181 .cpu_fprintf
= cpu_fprintf
,
5185 list
= object_class_get_list(TYPE_ARM_CPU
, false);
5186 list
= g_slist_sort(list
, arm_cpu_list_compare
);
5187 (*cpu_fprintf
)(f
, "Available CPUs:\n");
5188 g_slist_foreach(list
, arm_cpu_list_entry
, &s
);
5191 /* The 'host' CPU type is dynamically registered only if KVM is
5192 * enabled, so we have to special-case it here:
5194 (*cpu_fprintf
)(f
, " host (only available in KVM mode)\n");
5198 static void arm_cpu_add_definition(gpointer data
, gpointer user_data
)
5200 ObjectClass
*oc
= data
;
5201 CpuDefinitionInfoList
**cpu_list
= user_data
;
5202 CpuDefinitionInfoList
*entry
;
5203 CpuDefinitionInfo
*info
;
5204 const char *typename
;
5206 typename
= object_class_get_name(oc
);
5207 info
= g_malloc0(sizeof(*info
));
5208 info
->name
= g_strndup(typename
,
5209 strlen(typename
) - strlen("-" TYPE_ARM_CPU
));
5211 entry
= g_malloc0(sizeof(*entry
));
5212 entry
->value
= info
;
5213 entry
->next
= *cpu_list
;
5217 CpuDefinitionInfoList
*arch_query_cpu_definitions(Error
**errp
)
5219 CpuDefinitionInfoList
*cpu_list
= NULL
;
5222 list
= object_class_get_list(TYPE_ARM_CPU
, false);
5223 g_slist_foreach(list
, arm_cpu_add_definition
, &cpu_list
);
5229 static void add_cpreg_to_hashtable(ARMCPU
*cpu
, const ARMCPRegInfo
*r
,
5230 void *opaque
, int state
, int secstate
,
5231 int crm
, int opc1
, int opc2
)
5233 /* Private utility function for define_one_arm_cp_reg_with_opaque():
5234 * add a single reginfo struct to the hash table.
5236 uint32_t *key
= g_new(uint32_t, 1);
5237 ARMCPRegInfo
*r2
= g_memdup(r
, sizeof(ARMCPRegInfo
));
5238 int is64
= (r
->type
& ARM_CP_64BIT
) ? 1 : 0;
5239 int ns
= (secstate
& ARM_CP_SECSTATE_NS
) ? 1 : 0;
5241 /* Reset the secure state to the specific incoming state. This is
5242 * necessary as the register may have been defined with both states.
5244 r2
->secure
= secstate
;
5246 if (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1]) {
5247 /* Register is banked (using both entries in array).
5248 * Overwriting fieldoffset as the array is only used to define
5249 * banked registers but later only fieldoffset is used.
5251 r2
->fieldoffset
= r
->bank_fieldoffsets
[ns
];
5254 if (state
== ARM_CP_STATE_AA32
) {
5255 if (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1]) {
5256 /* If the register is banked then we don't need to migrate or
5257 * reset the 32-bit instance in certain cases:
5259 * 1) If the register has both 32-bit and 64-bit instances then we
5260 * can count on the 64-bit instance taking care of the
5262 * 2) If ARMv8 is enabled then we can count on a 64-bit version
5263 * taking care of the secure bank. This requires that separate
5264 * 32 and 64-bit definitions are provided.
5266 if ((r
->state
== ARM_CP_STATE_BOTH
&& ns
) ||
5267 (arm_feature(&cpu
->env
, ARM_FEATURE_V8
) && !ns
)) {
5268 r2
->type
|= ARM_CP_ALIAS
;
5270 } else if ((secstate
!= r
->secure
) && !ns
) {
5271 /* The register is not banked so we only want to allow migration of
5272 * the non-secure instance.
5274 r2
->type
|= ARM_CP_ALIAS
;
5277 if (r
->state
== ARM_CP_STATE_BOTH
) {
5278 /* We assume it is a cp15 register if the .cp field is left unset.
5284 #ifdef HOST_WORDS_BIGENDIAN
5285 if (r2
->fieldoffset
) {
5286 r2
->fieldoffset
+= sizeof(uint32_t);
5291 if (state
== ARM_CP_STATE_AA64
) {
5292 /* To allow abbreviation of ARMCPRegInfo
5293 * definitions, we treat cp == 0 as equivalent to
5294 * the value for "standard guest-visible sysreg".
5295 * STATE_BOTH definitions are also always "standard
5296 * sysreg" in their AArch64 view (the .cp value may
5297 * be non-zero for the benefit of the AArch32 view).
5299 if (r
->cp
== 0 || r
->state
== ARM_CP_STATE_BOTH
) {
5300 r2
->cp
= CP_REG_ARM64_SYSREG_CP
;
5302 *key
= ENCODE_AA64_CP_REG(r2
->cp
, r2
->crn
, crm
,
5303 r2
->opc0
, opc1
, opc2
);
5305 *key
= ENCODE_CP_REG(r2
->cp
, is64
, ns
, r2
->crn
, crm
, opc1
, opc2
);
5308 r2
->opaque
= opaque
;
5310 /* reginfo passed to helpers is correct for the actual access,
5311 * and is never ARM_CP_STATE_BOTH:
5314 /* Make sure reginfo passed to helpers for wildcarded regs
5315 * has the correct crm/opc1/opc2 for this reg, not CP_ANY:
5320 /* By convention, for wildcarded registers only the first
5321 * entry is used for migration; the others are marked as
5322 * ALIAS so we don't try to transfer the register
5323 * multiple times. Special registers (ie NOP/WFI) are
5324 * never migratable and not even raw-accessible.
5326 if ((r
->type
& ARM_CP_SPECIAL
)) {
5327 r2
->type
|= ARM_CP_NO_RAW
;
5329 if (((r
->crm
== CP_ANY
) && crm
!= 0) ||
5330 ((r
->opc1
== CP_ANY
) && opc1
!= 0) ||
5331 ((r
->opc2
== CP_ANY
) && opc2
!= 0)) {
5332 r2
->type
|= ARM_CP_ALIAS
;
5335 /* Check that raw accesses are either forbidden or handled. Note that
5336 * we can't assert this earlier because the setup of fieldoffset for
5337 * banked registers has to be done first.
5339 if (!(r2
->type
& ARM_CP_NO_RAW
)) {
5340 assert(!raw_accessors_invalid(r2
));
5343 /* Overriding of an existing definition must be explicitly
5346 if (!(r
->type
& ARM_CP_OVERRIDE
)) {
5347 ARMCPRegInfo
*oldreg
;
5348 oldreg
= g_hash_table_lookup(cpu
->cp_regs
, key
);
5349 if (oldreg
&& !(oldreg
->type
& ARM_CP_OVERRIDE
)) {
5350 fprintf(stderr
, "Register redefined: cp=%d %d bit "
5351 "crn=%d crm=%d opc1=%d opc2=%d, "
5352 "was %s, now %s\n", r2
->cp
, 32 + 32 * is64
,
5353 r2
->crn
, r2
->crm
, r2
->opc1
, r2
->opc2
,
5354 oldreg
->name
, r2
->name
);
5355 g_assert_not_reached();
5358 g_hash_table_insert(cpu
->cp_regs
, key
, r2
);
5362 void define_one_arm_cp_reg_with_opaque(ARMCPU
*cpu
,
5363 const ARMCPRegInfo
*r
, void *opaque
)
5365 /* Define implementations of coprocessor registers.
5366 * We store these in a hashtable because typically
5367 * there are less than 150 registers in a space which
5368 * is 16*16*16*8*8 = 262144 in size.
5369 * Wildcarding is supported for the crm, opc1 and opc2 fields.
5370 * If a register is defined twice then the second definition is
5371 * used, so this can be used to define some generic registers and
5372 * then override them with implementation specific variations.
5373 * At least one of the original and the second definition should
5374 * include ARM_CP_OVERRIDE in its type bits -- this is just a guard
5375 * against accidental use.
5377 * The state field defines whether the register is to be
5378 * visible in the AArch32 or AArch64 execution state. If the
5379 * state is set to ARM_CP_STATE_BOTH then we synthesise a
5380 * reginfo structure for the AArch32 view, which sees the lower
5381 * 32 bits of the 64 bit register.
5383 * Only registers visible in AArch64 may set r->opc0; opc0 cannot
5384 * be wildcarded. AArch64 registers are always considered to be 64
5385 * bits; the ARM_CP_64BIT* flag applies only to the AArch32 view of
5386 * the register, if any.
5388 int crm
, opc1
, opc2
, state
;
5389 int crmmin
= (r
->crm
== CP_ANY
) ? 0 : r
->crm
;
5390 int crmmax
= (r
->crm
== CP_ANY
) ? 15 : r
->crm
;
5391 int opc1min
= (r
->opc1
== CP_ANY
) ? 0 : r
->opc1
;
5392 int opc1max
= (r
->opc1
== CP_ANY
) ? 7 : r
->opc1
;
5393 int opc2min
= (r
->opc2
== CP_ANY
) ? 0 : r
->opc2
;
5394 int opc2max
= (r
->opc2
== CP_ANY
) ? 7 : r
->opc2
;
5395 /* 64 bit registers have only CRm and Opc1 fields */
5396 assert(!((r
->type
& ARM_CP_64BIT
) && (r
->opc2
|| r
->crn
)));
5397 /* op0 only exists in the AArch64 encodings */
5398 assert((r
->state
!= ARM_CP_STATE_AA32
) || (r
->opc0
== 0));
5399 /* AArch64 regs are all 64 bit so ARM_CP_64BIT is meaningless */
5400 assert((r
->state
!= ARM_CP_STATE_AA64
) || !(r
->type
& ARM_CP_64BIT
));
5401 /* The AArch64 pseudocode CheckSystemAccess() specifies that op1
5402 * encodes a minimum access level for the register. We roll this
5403 * runtime check into our general permission check code, so check
5404 * here that the reginfo's specified permissions are strict enough
5405 * to encompass the generic architectural permission check.
5407 if (r
->state
!= ARM_CP_STATE_AA32
) {
5410 case 0: case 1: case 2:
5423 /* unallocated encoding, so not possible */
5431 /* min_EL EL1, secure mode only (we don't check the latter) */
5435 /* broken reginfo with out-of-range opc1 */
5439 /* assert our permissions are not too lax (stricter is fine) */
5440 assert((r
->access
& ~mask
) == 0);
5443 /* Check that the register definition has enough info to handle
5444 * reads and writes if they are permitted.
5446 if (!(r
->type
& (ARM_CP_SPECIAL
|ARM_CP_CONST
))) {
5447 if (r
->access
& PL3_R
) {
5448 assert((r
->fieldoffset
||
5449 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
5452 if (r
->access
& PL3_W
) {
5453 assert((r
->fieldoffset
||
5454 (r
->bank_fieldoffsets
[0] && r
->bank_fieldoffsets
[1])) ||
5458 /* Bad type field probably means missing sentinel at end of reg list */
5459 assert(cptype_valid(r
->type
));
5460 for (crm
= crmmin
; crm
<= crmmax
; crm
++) {
5461 for (opc1
= opc1min
; opc1
<= opc1max
; opc1
++) {
5462 for (opc2
= opc2min
; opc2
<= opc2max
; opc2
++) {
5463 for (state
= ARM_CP_STATE_AA32
;
5464 state
<= ARM_CP_STATE_AA64
; state
++) {
5465 if (r
->state
!= state
&& r
->state
!= ARM_CP_STATE_BOTH
) {
5468 if (state
== ARM_CP_STATE_AA32
) {
5469 /* Under AArch32 CP registers can be common
5470 * (same for secure and non-secure world) or banked.
5472 switch (r
->secure
) {
5473 case ARM_CP_SECSTATE_S
:
5474 case ARM_CP_SECSTATE_NS
:
5475 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
5476 r
->secure
, crm
, opc1
, opc2
);
5479 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
5482 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
5488 /* AArch64 registers get mapped to non-secure instance
5490 add_cpreg_to_hashtable(cpu
, r
, opaque
, state
,
5500 void define_arm_cp_regs_with_opaque(ARMCPU
*cpu
,
5501 const ARMCPRegInfo
*regs
, void *opaque
)
5503 /* Define a whole list of registers */
5504 const ARMCPRegInfo
*r
;
5505 for (r
= regs
; r
->type
!= ARM_CP_SENTINEL
; r
++) {
5506 define_one_arm_cp_reg_with_opaque(cpu
, r
, opaque
);
5510 const ARMCPRegInfo
*get_arm_cp_reginfo(GHashTable
*cpregs
, uint32_t encoded_cp
)
5512 return g_hash_table_lookup(cpregs
, &encoded_cp
);
5515 void arm_cp_write_ignore(CPUARMState
*env
, const ARMCPRegInfo
*ri
,
5518 /* Helper coprocessor write function for write-ignore registers */
5521 uint64_t arm_cp_read_zero(CPUARMState
*env
, const ARMCPRegInfo
*ri
)
5523 /* Helper coprocessor write function for read-as-zero registers */
5527 void arm_cp_reset_ignore(CPUARMState
*env
, const ARMCPRegInfo
*opaque
)
5529 /* Helper coprocessor reset function for do-nothing-on-reset registers */
5532 static int bad_mode_switch(CPUARMState
*env
, int mode
, CPSRWriteType write_type
)
5534 /* Return true if it is not valid for us to switch to
5535 * this CPU mode (ie all the UNPREDICTABLE cases in
5536 * the ARM ARM CPSRWriteByInstr pseudocode).
5539 /* Changes to or from Hyp via MSR and CPS are illegal. */
5540 if (write_type
== CPSRWriteByInstr
&&
5541 ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_HYP
||
5542 mode
== ARM_CPU_MODE_HYP
)) {
5547 case ARM_CPU_MODE_USR
:
5549 case ARM_CPU_MODE_SYS
:
5550 case ARM_CPU_MODE_SVC
:
5551 case ARM_CPU_MODE_ABT
:
5552 case ARM_CPU_MODE_UND
:
5553 case ARM_CPU_MODE_IRQ
:
5554 case ARM_CPU_MODE_FIQ
:
5555 /* Note that we don't implement the IMPDEF NSACR.RFR which in v7
5556 * allows FIQ mode to be Secure-only. (In v8 this doesn't exist.)
5558 /* If HCR.TGE is set then changes from Monitor to NS PL1 via MSR
5559 * and CPS are treated as illegal mode changes.
5561 if (write_type
== CPSRWriteByInstr
&&
5562 (env
->cp15
.hcr_el2
& HCR_TGE
) &&
5563 (env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
&&
5564 !arm_is_secure_below_el3(env
)) {
5568 case ARM_CPU_MODE_HYP
:
5569 return !arm_feature(env
, ARM_FEATURE_EL2
)
5570 || arm_current_el(env
) < 2 || arm_is_secure(env
);
5571 case ARM_CPU_MODE_MON
:
5572 return arm_current_el(env
) < 3;
5578 uint32_t cpsr_read(CPUARMState
*env
)
5581 ZF
= (env
->ZF
== 0);
5582 return env
->uncached_cpsr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
5583 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3) | (env
->QF
<< 27)
5584 | (env
->thumb
<< 5) | ((env
->condexec_bits
& 3) << 25)
5585 | ((env
->condexec_bits
& 0xfc) << 8)
5586 | (env
->GE
<< 16) | (env
->daif
& CPSR_AIF
);
5589 void cpsr_write(CPUARMState
*env
, uint32_t val
, uint32_t mask
,
5590 CPSRWriteType write_type
)
5592 uint32_t changed_daif
;
5594 if (mask
& CPSR_NZCV
) {
5595 env
->ZF
= (~val
) & CPSR_Z
;
5597 env
->CF
= (val
>> 29) & 1;
5598 env
->VF
= (val
<< 3) & 0x80000000;
5601 env
->QF
= ((val
& CPSR_Q
) != 0);
5603 env
->thumb
= ((val
& CPSR_T
) != 0);
5604 if (mask
& CPSR_IT_0_1
) {
5605 env
->condexec_bits
&= ~3;
5606 env
->condexec_bits
|= (val
>> 25) & 3;
5608 if (mask
& CPSR_IT_2_7
) {
5609 env
->condexec_bits
&= 3;
5610 env
->condexec_bits
|= (val
>> 8) & 0xfc;
5612 if (mask
& CPSR_GE
) {
5613 env
->GE
= (val
>> 16) & 0xf;
5616 /* In a V7 implementation that includes the security extensions but does
5617 * not include Virtualization Extensions the SCR.FW and SCR.AW bits control
5618 * whether non-secure software is allowed to change the CPSR_F and CPSR_A
5619 * bits respectively.
5621 * In a V8 implementation, it is permitted for privileged software to
5622 * change the CPSR A/F bits regardless of the SCR.AW/FW bits.
5624 if (write_type
!= CPSRWriteRaw
&& !arm_feature(env
, ARM_FEATURE_V8
) &&
5625 arm_feature(env
, ARM_FEATURE_EL3
) &&
5626 !arm_feature(env
, ARM_FEATURE_EL2
) &&
5627 !arm_is_secure(env
)) {
5629 changed_daif
= (env
->daif
^ val
) & mask
;
5631 if (changed_daif
& CPSR_A
) {
5632 /* Check to see if we are allowed to change the masking of async
5633 * abort exceptions from a non-secure state.
5635 if (!(env
->cp15
.scr_el3
& SCR_AW
)) {
5636 qemu_log_mask(LOG_GUEST_ERROR
,
5637 "Ignoring attempt to switch CPSR_A flag from "
5638 "non-secure world with SCR.AW bit clear\n");
5643 if (changed_daif
& CPSR_F
) {
5644 /* Check to see if we are allowed to change the masking of FIQ
5645 * exceptions from a non-secure state.
5647 if (!(env
->cp15
.scr_el3
& SCR_FW
)) {
5648 qemu_log_mask(LOG_GUEST_ERROR
,
5649 "Ignoring attempt to switch CPSR_F flag from "
5650 "non-secure world with SCR.FW bit clear\n");
5654 /* Check whether non-maskable FIQ (NMFI) support is enabled.
5655 * If this bit is set software is not allowed to mask
5656 * FIQs, but is allowed to set CPSR_F to 0.
5658 if ((A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_NMFI
) &&
5660 qemu_log_mask(LOG_GUEST_ERROR
,
5661 "Ignoring attempt to enable CPSR_F flag "
5662 "(non-maskable FIQ [NMFI] support enabled)\n");
5668 env
->daif
&= ~(CPSR_AIF
& mask
);
5669 env
->daif
|= val
& CPSR_AIF
& mask
;
5671 if (write_type
!= CPSRWriteRaw
&&
5672 ((env
->uncached_cpsr
^ val
) & mask
& CPSR_M
)) {
5673 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_USR
) {
5674 /* Note that we can only get here in USR mode if this is a
5675 * gdb stub write; for this case we follow the architectural
5676 * behaviour for guest writes in USR mode of ignoring an attempt
5677 * to switch mode. (Those are caught by translate.c for writes
5678 * triggered by guest instructions.)
5681 } else if (bad_mode_switch(env
, val
& CPSR_M
, write_type
)) {
5682 /* Attempt to switch to an invalid mode: this is UNPREDICTABLE in
5683 * v7, and has defined behaviour in v8:
5684 * + leave CPSR.M untouched
5685 * + allow changes to the other CPSR fields
5687 * For user changes via the GDB stub, we don't set PSTATE.IL,
5688 * as this would be unnecessarily harsh for a user error.
5691 if (write_type
!= CPSRWriteByGDBStub
&&
5692 arm_feature(env
, ARM_FEATURE_V8
)) {
5697 switch_mode(env
, val
& CPSR_M
);
5700 mask
&= ~CACHED_CPSR_BITS
;
5701 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~mask
) | (val
& mask
);
5704 /* Sign/zero extend */
5705 uint32_t HELPER(sxtb16
)(uint32_t x
)
5708 res
= (uint16_t)(int8_t)x
;
5709 res
|= (uint32_t)(int8_t)(x
>> 16) << 16;
5713 uint32_t HELPER(uxtb16
)(uint32_t x
)
5716 res
= (uint16_t)(uint8_t)x
;
5717 res
|= (uint32_t)(uint8_t)(x
>> 16) << 16;
5721 uint32_t HELPER(clz
)(uint32_t x
)
5726 int32_t HELPER(sdiv
)(int32_t num
, int32_t den
)
5730 if (num
== INT_MIN
&& den
== -1)
5735 uint32_t HELPER(udiv
)(uint32_t num
, uint32_t den
)
5742 uint32_t HELPER(rbit
)(uint32_t x
)
5747 #if defined(CONFIG_USER_ONLY)
5749 /* These should probably raise undefined insn exceptions. */
5750 void HELPER(v7m_msr
)(CPUARMState
*env
, uint32_t reg
, uint32_t val
)
5752 ARMCPU
*cpu
= arm_env_get_cpu(env
);
5754 cpu_abort(CPU(cpu
), "v7m_msr %d\n", reg
);
5757 uint32_t HELPER(v7m_mrs
)(CPUARMState
*env
, uint32_t reg
)
5759 ARMCPU
*cpu
= arm_env_get_cpu(env
);
5761 cpu_abort(CPU(cpu
), "v7m_mrs %d\n", reg
);
5765 void switch_mode(CPUARMState
*env
, int mode
)
5767 ARMCPU
*cpu
= arm_env_get_cpu(env
);
5769 if (mode
!= ARM_CPU_MODE_USR
) {
5770 cpu_abort(CPU(cpu
), "Tried to switch out of user mode\n");
5774 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
5775 uint32_t cur_el
, bool secure
)
5780 void aarch64_sync_64_to_32(CPUARMState
*env
)
5782 g_assert_not_reached();
5787 void switch_mode(CPUARMState
*env
, int mode
)
5792 old_mode
= env
->uncached_cpsr
& CPSR_M
;
5793 if (mode
== old_mode
)
5796 if (old_mode
== ARM_CPU_MODE_FIQ
) {
5797 memcpy (env
->fiq_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
5798 memcpy (env
->regs
+ 8, env
->usr_regs
, 5 * sizeof(uint32_t));
5799 } else if (mode
== ARM_CPU_MODE_FIQ
) {
5800 memcpy (env
->usr_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
5801 memcpy (env
->regs
+ 8, env
->fiq_regs
, 5 * sizeof(uint32_t));
5804 i
= bank_number(old_mode
);
5805 env
->banked_r13
[i
] = env
->regs
[13];
5806 env
->banked_r14
[i
] = env
->regs
[14];
5807 env
->banked_spsr
[i
] = env
->spsr
;
5809 i
= bank_number(mode
);
5810 env
->regs
[13] = env
->banked_r13
[i
];
5811 env
->regs
[14] = env
->banked_r14
[i
];
5812 env
->spsr
= env
->banked_spsr
[i
];
5815 /* Physical Interrupt Target EL Lookup Table
5817 * [ From ARM ARM section G1.13.4 (Table G1-15) ]
5819 * The below multi-dimensional table is used for looking up the target
5820 * exception level given numerous condition criteria. Specifically, the
5821 * target EL is based on SCR and HCR routing controls as well as the
5822 * currently executing EL and secure state.
5825 * target_el_table[2][2][2][2][2][4]
5826 * | | | | | +--- Current EL
5827 * | | | | +------ Non-secure(0)/Secure(1)
5828 * | | | +--------- HCR mask override
5829 * | | +------------ SCR exec state control
5830 * | +--------------- SCR mask override
5831 * +------------------ 32-bit(0)/64-bit(1) EL3
5833 * The table values are as such:
5837 * The ARM ARM target EL table includes entries indicating that an "exception
5838 * is not taken". The two cases where this is applicable are:
5839 * 1) An exception is taken from EL3 but the SCR does not have the exception
5841 * 2) An exception is taken from EL2 but the HCR does not have the exception
5843 * In these two cases, the below table contain a target of EL1. This value is
5844 * returned as it is expected that the consumer of the table data will check
5845 * for "target EL >= current EL" to ensure the exception is not taken.
5849 * BIT IRQ IMO Non-secure Secure
5850 * EL3 FIQ RW FMO EL0 EL1 EL2 EL3 EL0 EL1 EL2 EL3
5852 static const int8_t target_el_table
[2][2][2][2][2][4] = {
5853 {{{{/* 0 0 0 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
5854 {/* 0 0 0 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},
5855 {{/* 0 0 1 0 */{ 1, 1, 2, -1 },{ 3, -1, -1, 3 },},
5856 {/* 0 0 1 1 */{ 2, 2, 2, -1 },{ 3, -1, -1, 3 },},},},
5857 {{{/* 0 1 0 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
5858 {/* 0 1 0 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},
5859 {{/* 0 1 1 0 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},
5860 {/* 0 1 1 1 */{ 3, 3, 3, -1 },{ 3, -1, -1, 3 },},},},},
5861 {{{{/* 1 0 0 0 */{ 1, 1, 2, -1 },{ 1, 1, -1, 1 },},
5862 {/* 1 0 0 1 */{ 2, 2, 2, -1 },{ 1, 1, -1, 1 },},},
5863 {{/* 1 0 1 0 */{ 1, 1, 1, -1 },{ 1, 1, -1, 1 },},
5864 {/* 1 0 1 1 */{ 2, 2, 2, -1 },{ 1, 1, -1, 1 },},},},
5865 {{{/* 1 1 0 0 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},
5866 {/* 1 1 0 1 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},},
5867 {{/* 1 1 1 0 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},
5868 {/* 1 1 1 1 */{ 3, 3, 3, -1 },{ 3, 3, -1, 3 },},},},},
5872 * Determine the target EL for physical exceptions
5874 uint32_t arm_phys_excp_target_el(CPUState
*cs
, uint32_t excp_idx
,
5875 uint32_t cur_el
, bool secure
)
5877 CPUARMState
*env
= cs
->env_ptr
;
5882 /* Is the highest EL AArch64? */
5883 int is64
= arm_feature(env
, ARM_FEATURE_AARCH64
);
5885 if (arm_feature(env
, ARM_FEATURE_EL3
)) {
5886 rw
= ((env
->cp15
.scr_el3
& SCR_RW
) == SCR_RW
);
5888 /* Either EL2 is the highest EL (and so the EL2 register width
5889 * is given by is64); or there is no EL2 or EL3, in which case
5890 * the value of 'rw' does not affect the table lookup anyway.
5897 scr
= ((env
->cp15
.scr_el3
& SCR_IRQ
) == SCR_IRQ
);
5898 hcr
= ((env
->cp15
.hcr_el2
& HCR_IMO
) == HCR_IMO
);
5901 scr
= ((env
->cp15
.scr_el3
& SCR_FIQ
) == SCR_FIQ
);
5902 hcr
= ((env
->cp15
.hcr_el2
& HCR_FMO
) == HCR_FMO
);
5905 scr
= ((env
->cp15
.scr_el3
& SCR_EA
) == SCR_EA
);
5906 hcr
= ((env
->cp15
.hcr_el2
& HCR_AMO
) == HCR_AMO
);
5910 /* If HCR.TGE is set then HCR is treated as being 1 */
5911 hcr
|= ((env
->cp15
.hcr_el2
& HCR_TGE
) == HCR_TGE
);
5913 /* Perform a table-lookup for the target EL given the current state */
5914 target_el
= target_el_table
[is64
][scr
][rw
][hcr
][secure
][cur_el
];
5916 assert(target_el
> 0);
5921 static void v7m_push(CPUARMState
*env
, uint32_t val
)
5923 CPUState
*cs
= CPU(arm_env_get_cpu(env
));
5926 stl_phys(cs
->as
, env
->regs
[13], val
);
5929 static uint32_t v7m_pop(CPUARMState
*env
)
5931 CPUState
*cs
= CPU(arm_env_get_cpu(env
));
5934 val
= ldl_phys(cs
->as
, env
->regs
[13]);
5939 /* Switch to V7M main or process stack pointer. */
5940 static void switch_v7m_sp(CPUARMState
*env
, int process
)
5943 if (env
->v7m
.current_sp
!= process
) {
5944 tmp
= env
->v7m
.other_sp
;
5945 env
->v7m
.other_sp
= env
->regs
[13];
5946 env
->regs
[13] = tmp
;
5947 env
->v7m
.current_sp
= process
;
5951 static void do_v7m_exception_exit(CPUARMState
*env
)
5956 type
= env
->regs
[15];
5957 if (env
->v7m
.exception
!= 0)
5958 armv7m_nvic_complete_irq(env
->nvic
, env
->v7m
.exception
);
5960 /* Switch to the target stack. */
5961 switch_v7m_sp(env
, (type
& 4) != 0);
5962 /* Pop registers. */
5963 env
->regs
[0] = v7m_pop(env
);
5964 env
->regs
[1] = v7m_pop(env
);
5965 env
->regs
[2] = v7m_pop(env
);
5966 env
->regs
[3] = v7m_pop(env
);
5967 env
->regs
[12] = v7m_pop(env
);
5968 env
->regs
[14] = v7m_pop(env
);
5969 env
->regs
[15] = v7m_pop(env
);
5970 if (env
->regs
[15] & 1) {
5971 qemu_log_mask(LOG_GUEST_ERROR
,
5972 "M profile return from interrupt with misaligned "
5973 "PC is UNPREDICTABLE\n");
5974 /* Actual hardware seems to ignore the lsbit, and there are several
5975 * RTOSes out there which incorrectly assume the r15 in the stack
5976 * frame should be a Thumb-style "lsbit indicates ARM/Thumb" value.
5978 env
->regs
[15] &= ~1U;
5980 xpsr
= v7m_pop(env
);
5981 xpsr_write(env
, xpsr
, 0xfffffdff);
5982 /* Undo stack alignment. */
5985 /* ??? The exception return type specifies Thread/Handler mode. However
5986 this is also implied by the xPSR value. Not sure what to do
5987 if there is a mismatch. */
5988 /* ??? Likewise for mismatches between the CONTROL register and the stack
5992 static void arm_log_exception(int idx
)
5994 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
5995 const char *exc
= NULL
;
5997 if (idx
>= 0 && idx
< ARRAY_SIZE(excnames
)) {
5998 exc
= excnames
[idx
];
6003 qemu_log_mask(CPU_LOG_INT
, "Taking exception %d [%s]\n", idx
, exc
);
6007 void arm_v7m_cpu_do_interrupt(CPUState
*cs
)
6009 ARMCPU
*cpu
= ARM_CPU(cs
);
6010 CPUARMState
*env
= &cpu
->env
;
6011 uint32_t xpsr
= xpsr_read(env
);
6015 arm_log_exception(cs
->exception_index
);
6018 if (env
->v7m
.current_sp
)
6020 if (env
->v7m
.exception
== 0)
6023 /* For exceptions we just mark as pending on the NVIC, and let that
6025 /* TODO: Need to escalate if the current priority is higher than the
6026 one we're raising. */
6027 switch (cs
->exception_index
) {
6029 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_USAGE
);
6032 /* The PC already points to the next instruction. */
6033 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_SVC
);
6035 case EXCP_PREFETCH_ABORT
:
6036 case EXCP_DATA_ABORT
:
6037 /* TODO: if we implemented the MPU registers, this is where we
6038 * should set the MMFAR, etc from exception.fsr and exception.vaddress.
6040 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_MEM
);
6043 if (semihosting_enabled()) {
6045 nr
= arm_lduw_code(env
, env
->regs
[15], arm_sctlr_b(env
)) & 0xff;
6048 qemu_log_mask(CPU_LOG_INT
,
6049 "...handling as semihosting call 0x%x\n",
6051 env
->regs
[0] = do_arm_semihosting(env
);
6055 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_DEBUG
);
6058 env
->v7m
.exception
= armv7m_nvic_acknowledge_irq(env
->nvic
);
6060 case EXCP_EXCEPTION_EXIT
:
6061 do_v7m_exception_exit(env
);
6064 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
6065 return; /* Never happens. Keep compiler happy. */
6068 /* Align stack pointer. */
6069 /* ??? Should only do this if Configuration Control Register
6070 STACKALIGN bit is set. */
6071 if (env
->regs
[13] & 4) {
6075 /* Switch to the handler mode. */
6076 v7m_push(env
, xpsr
);
6077 v7m_push(env
, env
->regs
[15]);
6078 v7m_push(env
, env
->regs
[14]);
6079 v7m_push(env
, env
->regs
[12]);
6080 v7m_push(env
, env
->regs
[3]);
6081 v7m_push(env
, env
->regs
[2]);
6082 v7m_push(env
, env
->regs
[1]);
6083 v7m_push(env
, env
->regs
[0]);
6084 switch_v7m_sp(env
, 0);
6086 env
->condexec_bits
= 0;
6088 addr
= ldl_phys(cs
->as
, env
->v7m
.vecbase
+ env
->v7m
.exception
* 4);
6089 env
->regs
[15] = addr
& 0xfffffffe;
6090 env
->thumb
= addr
& 1;
6093 /* Function used to synchronize QEMU's AArch64 register set with AArch32
6094 * register set. This is necessary when switching between AArch32 and AArch64
6097 void aarch64_sync_32_to_64(CPUARMState
*env
)
6100 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
6102 /* We can blanket copy R[0:7] to X[0:7] */
6103 for (i
= 0; i
< 8; i
++) {
6104 env
->xregs
[i
] = env
->regs
[i
];
6107 /* Unless we are in FIQ mode, x8-x12 come from the user registers r8-r12.
6108 * Otherwise, they come from the banked user regs.
6110 if (mode
== ARM_CPU_MODE_FIQ
) {
6111 for (i
= 8; i
< 13; i
++) {
6112 env
->xregs
[i
] = env
->usr_regs
[i
- 8];
6115 for (i
= 8; i
< 13; i
++) {
6116 env
->xregs
[i
] = env
->regs
[i
];
6120 /* Registers x13-x23 are the various mode SP and FP registers. Registers
6121 * r13 and r14 are only copied if we are in that mode, otherwise we copy
6122 * from the mode banked register.
6124 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
6125 env
->xregs
[13] = env
->regs
[13];
6126 env
->xregs
[14] = env
->regs
[14];
6128 env
->xregs
[13] = env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)];
6129 /* HYP is an exception in that it is copied from r14 */
6130 if (mode
== ARM_CPU_MODE_HYP
) {
6131 env
->xregs
[14] = env
->regs
[14];
6133 env
->xregs
[14] = env
->banked_r14
[bank_number(ARM_CPU_MODE_USR
)];
6137 if (mode
== ARM_CPU_MODE_HYP
) {
6138 env
->xregs
[15] = env
->regs
[13];
6140 env
->xregs
[15] = env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)];
6143 if (mode
== ARM_CPU_MODE_IRQ
) {
6144 env
->xregs
[16] = env
->regs
[14];
6145 env
->xregs
[17] = env
->regs
[13];
6147 env
->xregs
[16] = env
->banked_r14
[bank_number(ARM_CPU_MODE_IRQ
)];
6148 env
->xregs
[17] = env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)];
6151 if (mode
== ARM_CPU_MODE_SVC
) {
6152 env
->xregs
[18] = env
->regs
[14];
6153 env
->xregs
[19] = env
->regs
[13];
6155 env
->xregs
[18] = env
->banked_r14
[bank_number(ARM_CPU_MODE_SVC
)];
6156 env
->xregs
[19] = env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)];
6159 if (mode
== ARM_CPU_MODE_ABT
) {
6160 env
->xregs
[20] = env
->regs
[14];
6161 env
->xregs
[21] = env
->regs
[13];
6163 env
->xregs
[20] = env
->banked_r14
[bank_number(ARM_CPU_MODE_ABT
)];
6164 env
->xregs
[21] = env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)];
6167 if (mode
== ARM_CPU_MODE_UND
) {
6168 env
->xregs
[22] = env
->regs
[14];
6169 env
->xregs
[23] = env
->regs
[13];
6171 env
->xregs
[22] = env
->banked_r14
[bank_number(ARM_CPU_MODE_UND
)];
6172 env
->xregs
[23] = env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)];
6175 /* Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
6176 * mode, then we can copy from r8-r14. Otherwise, we copy from the
6177 * FIQ bank for r8-r14.
6179 if (mode
== ARM_CPU_MODE_FIQ
) {
6180 for (i
= 24; i
< 31; i
++) {
6181 env
->xregs
[i
] = env
->regs
[i
- 16]; /* X[24:30] <- R[8:14] */
6184 for (i
= 24; i
< 29; i
++) {
6185 env
->xregs
[i
] = env
->fiq_regs
[i
- 24];
6187 env
->xregs
[29] = env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)];
6188 env
->xregs
[30] = env
->banked_r14
[bank_number(ARM_CPU_MODE_FIQ
)];
6191 env
->pc
= env
->regs
[15];
6194 /* Function used to synchronize QEMU's AArch32 register set with AArch64
6195 * register set. This is necessary when switching between AArch32 and AArch64
6198 void aarch64_sync_64_to_32(CPUARMState
*env
)
6201 uint32_t mode
= env
->uncached_cpsr
& CPSR_M
;
6203 /* We can blanket copy X[0:7] to R[0:7] */
6204 for (i
= 0; i
< 8; i
++) {
6205 env
->regs
[i
] = env
->xregs
[i
];
6208 /* Unless we are in FIQ mode, r8-r12 come from the user registers x8-x12.
6209 * Otherwise, we copy x8-x12 into the banked user regs.
6211 if (mode
== ARM_CPU_MODE_FIQ
) {
6212 for (i
= 8; i
< 13; i
++) {
6213 env
->usr_regs
[i
- 8] = env
->xregs
[i
];
6216 for (i
= 8; i
< 13; i
++) {
6217 env
->regs
[i
] = env
->xregs
[i
];
6221 /* Registers r13 & r14 depend on the current mode.
6222 * If we are in a given mode, we copy the corresponding x registers to r13
6223 * and r14. Otherwise, we copy the x register to the banked r13 and r14
6226 if (mode
== ARM_CPU_MODE_USR
|| mode
== ARM_CPU_MODE_SYS
) {
6227 env
->regs
[13] = env
->xregs
[13];
6228 env
->regs
[14] = env
->xregs
[14];
6230 env
->banked_r13
[bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[13];
6232 /* HYP is an exception in that it does not have its own banked r14 but
6233 * shares the USR r14
6235 if (mode
== ARM_CPU_MODE_HYP
) {
6236 env
->regs
[14] = env
->xregs
[14];
6238 env
->banked_r14
[bank_number(ARM_CPU_MODE_USR
)] = env
->xregs
[14];
6242 if (mode
== ARM_CPU_MODE_HYP
) {
6243 env
->regs
[13] = env
->xregs
[15];
6245 env
->banked_r13
[bank_number(ARM_CPU_MODE_HYP
)] = env
->xregs
[15];
6248 if (mode
== ARM_CPU_MODE_IRQ
) {
6249 env
->regs
[14] = env
->xregs
[16];
6250 env
->regs
[13] = env
->xregs
[17];
6252 env
->banked_r14
[bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[16];
6253 env
->banked_r13
[bank_number(ARM_CPU_MODE_IRQ
)] = env
->xregs
[17];
6256 if (mode
== ARM_CPU_MODE_SVC
) {
6257 env
->regs
[14] = env
->xregs
[18];
6258 env
->regs
[13] = env
->xregs
[19];
6260 env
->banked_r14
[bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[18];
6261 env
->banked_r13
[bank_number(ARM_CPU_MODE_SVC
)] = env
->xregs
[19];
6264 if (mode
== ARM_CPU_MODE_ABT
) {
6265 env
->regs
[14] = env
->xregs
[20];
6266 env
->regs
[13] = env
->xregs
[21];
6268 env
->banked_r14
[bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[20];
6269 env
->banked_r13
[bank_number(ARM_CPU_MODE_ABT
)] = env
->xregs
[21];
6272 if (mode
== ARM_CPU_MODE_UND
) {
6273 env
->regs
[14] = env
->xregs
[22];
6274 env
->regs
[13] = env
->xregs
[23];
6276 env
->banked_r14
[bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[22];
6277 env
->banked_r13
[bank_number(ARM_CPU_MODE_UND
)] = env
->xregs
[23];
6280 /* Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
6281 * mode, then we can copy to r8-r14. Otherwise, we copy to the
6282 * FIQ bank for r8-r14.
6284 if (mode
== ARM_CPU_MODE_FIQ
) {
6285 for (i
= 24; i
< 31; i
++) {
6286 env
->regs
[i
- 16] = env
->xregs
[i
]; /* X[24:30] -> R[8:14] */
6289 for (i
= 24; i
< 29; i
++) {
6290 env
->fiq_regs
[i
- 24] = env
->xregs
[i
];
6292 env
->banked_r13
[bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[29];
6293 env
->banked_r14
[bank_number(ARM_CPU_MODE_FIQ
)] = env
->xregs
[30];
6296 env
->regs
[15] = env
->pc
;
6299 static void arm_cpu_do_interrupt_aarch32(CPUState
*cs
)
6301 ARMCPU
*cpu
= ARM_CPU(cs
);
6302 CPUARMState
*env
= &cpu
->env
;
6309 /* If this is a debug exception we must update the DBGDSCR.MOE bits */
6310 switch (env
->exception
.syndrome
>> ARM_EL_EC_SHIFT
) {
6312 case EC_BREAKPOINT_SAME_EL
:
6316 case EC_WATCHPOINT_SAME_EL
:
6322 case EC_VECTORCATCH
:
6331 env
->cp15
.mdscr_el1
= deposit64(env
->cp15
.mdscr_el1
, 2, 4, moe
);
6334 /* TODO: Vectored interrupt controller. */
6335 switch (cs
->exception_index
) {
6337 new_mode
= ARM_CPU_MODE_UND
;
6346 new_mode
= ARM_CPU_MODE_SVC
;
6349 /* The PC already points to the next instruction. */
6353 env
->exception
.fsr
= 2;
6354 /* Fall through to prefetch abort. */
6355 case EXCP_PREFETCH_ABORT
:
6356 A32_BANKED_CURRENT_REG_SET(env
, ifsr
, env
->exception
.fsr
);
6357 A32_BANKED_CURRENT_REG_SET(env
, ifar
, env
->exception
.vaddress
);
6358 qemu_log_mask(CPU_LOG_INT
, "...with IFSR 0x%x IFAR 0x%x\n",
6359 env
->exception
.fsr
, (uint32_t)env
->exception
.vaddress
);
6360 new_mode
= ARM_CPU_MODE_ABT
;
6362 mask
= CPSR_A
| CPSR_I
;
6365 case EXCP_DATA_ABORT
:
6366 A32_BANKED_CURRENT_REG_SET(env
, dfsr
, env
->exception
.fsr
);
6367 A32_BANKED_CURRENT_REG_SET(env
, dfar
, env
->exception
.vaddress
);
6368 qemu_log_mask(CPU_LOG_INT
, "...with DFSR 0x%x DFAR 0x%x\n",
6370 (uint32_t)env
->exception
.vaddress
);
6371 new_mode
= ARM_CPU_MODE_ABT
;
6373 mask
= CPSR_A
| CPSR_I
;
6377 new_mode
= ARM_CPU_MODE_IRQ
;
6379 /* Disable IRQ and imprecise data aborts. */
6380 mask
= CPSR_A
| CPSR_I
;
6382 if (env
->cp15
.scr_el3
& SCR_IRQ
) {
6383 /* IRQ routed to monitor mode */
6384 new_mode
= ARM_CPU_MODE_MON
;
6389 new_mode
= ARM_CPU_MODE_FIQ
;
6391 /* Disable FIQ, IRQ and imprecise data aborts. */
6392 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
6393 if (env
->cp15
.scr_el3
& SCR_FIQ
) {
6394 /* FIQ routed to monitor mode */
6395 new_mode
= ARM_CPU_MODE_MON
;
6400 new_mode
= ARM_CPU_MODE_MON
;
6402 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
6406 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
6407 return; /* Never happens. Keep compiler happy. */
6410 if (new_mode
== ARM_CPU_MODE_MON
) {
6411 addr
+= env
->cp15
.mvbar
;
6412 } else if (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_V
) {
6413 /* High vectors. When enabled, base address cannot be remapped. */
6416 /* ARM v7 architectures provide a vector base address register to remap
6417 * the interrupt vector table.
6418 * This register is only followed in non-monitor mode, and is banked.
6419 * Note: only bits 31:5 are valid.
6421 addr
+= A32_BANKED_CURRENT_REG_GET(env
, vbar
);
6424 if ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_MON
) {
6425 env
->cp15
.scr_el3
&= ~SCR_NS
;
6428 switch_mode (env
, new_mode
);
6429 /* For exceptions taken to AArch32 we must clear the SS bit in both
6430 * PSTATE and in the old-state value we save to SPSR_<mode>, so zero it now.
6432 env
->uncached_cpsr
&= ~PSTATE_SS
;
6433 env
->spsr
= cpsr_read(env
);
6434 /* Clear IT bits. */
6435 env
->condexec_bits
= 0;
6436 /* Switch to the new mode, and to the correct instruction set. */
6437 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~CPSR_M
) | new_mode
;
6438 /* Set new mode endianness */
6439 env
->uncached_cpsr
&= ~CPSR_E
;
6440 if (env
->cp15
.sctlr_el
[arm_current_el(env
)] & SCTLR_EE
) {
6441 env
->uncached_cpsr
|= ~CPSR_E
;
6444 /* this is a lie, as the was no c1_sys on V4T/V5, but who cares
6445 * and we should just guard the thumb mode on V4 */
6446 if (arm_feature(env
, ARM_FEATURE_V4T
)) {
6447 env
->thumb
= (A32_BANKED_CURRENT_REG_GET(env
, sctlr
) & SCTLR_TE
) != 0;
6449 env
->regs
[14] = env
->regs
[15] + offset
;
6450 env
->regs
[15] = addr
;
6453 /* Handle exception entry to a target EL which is using AArch64 */
6454 static void arm_cpu_do_interrupt_aarch64(CPUState
*cs
)
6456 ARMCPU
*cpu
= ARM_CPU(cs
);
6457 CPUARMState
*env
= &cpu
->env
;
6458 unsigned int new_el
= env
->exception
.target_el
;
6459 target_ulong addr
= env
->cp15
.vbar_el
[new_el
];
6460 unsigned int new_mode
= aarch64_pstate_mode(new_el
, true);
6462 if (arm_current_el(env
) < new_el
) {
6463 /* Entry vector offset depends on whether the implemented EL
6464 * immediately lower than the target level is using AArch32 or AArch64
6470 is_aa64
= (env
->cp15
.scr_el3
& SCR_RW
) != 0;
6473 is_aa64
= (env
->cp15
.hcr_el2
& HCR_RW
) != 0;
6476 is_aa64
= is_a64(env
);
6479 g_assert_not_reached();
6487 } else if (pstate_read(env
) & PSTATE_SP
) {
6491 switch (cs
->exception_index
) {
6492 case EXCP_PREFETCH_ABORT
:
6493 case EXCP_DATA_ABORT
:
6494 env
->cp15
.far_el
[new_el
] = env
->exception
.vaddress
;
6495 qemu_log_mask(CPU_LOG_INT
, "...with FAR 0x%" PRIx64
"\n",
6496 env
->cp15
.far_el
[new_el
]);
6504 env
->cp15
.esr_el
[new_el
] = env
->exception
.syndrome
;
6515 qemu_log_mask(CPU_LOG_INT
,
6516 "...handling as semihosting call 0x%" PRIx64
"\n",
6518 env
->xregs
[0] = do_arm_semihosting(env
);
6521 cpu_abort(cs
, "Unhandled exception 0x%x\n", cs
->exception_index
);
6525 env
->banked_spsr
[aarch64_banked_spsr_index(new_el
)] = pstate_read(env
);
6526 aarch64_save_sp(env
, arm_current_el(env
));
6527 env
->elr_el
[new_el
] = env
->pc
;
6529 env
->banked_spsr
[aarch64_banked_spsr_index(new_el
)] = cpsr_read(env
);
6530 env
->elr_el
[new_el
] = env
->regs
[15];
6532 aarch64_sync_32_to_64(env
);
6534 env
->condexec_bits
= 0;
6536 qemu_log_mask(CPU_LOG_INT
, "...with ELR 0x%" PRIx64
"\n",
6537 env
->elr_el
[new_el
]);
6539 pstate_write(env
, PSTATE_DAIF
| new_mode
);
6541 aarch64_restore_sp(env
, new_el
);
6545 qemu_log_mask(CPU_LOG_INT
, "...to EL%d PC 0x%" PRIx64
" PSTATE 0x%x\n",
6546 new_el
, env
->pc
, pstate_read(env
));
6549 static inline bool check_for_semihosting(CPUState
*cs
)
6551 /* Check whether this exception is a semihosting call; if so
6552 * then handle it and return true; otherwise return false.
6554 ARMCPU
*cpu
= ARM_CPU(cs
);
6555 CPUARMState
*env
= &cpu
->env
;
6558 if (cs
->exception_index
== EXCP_SEMIHOST
) {
6559 /* This is always the 64-bit semihosting exception.
6560 * The "is this usermode" and "is semihosting enabled"
6561 * checks have been done at translate time.
6563 qemu_log_mask(CPU_LOG_INT
,
6564 "...handling as semihosting call 0x%" PRIx64
"\n",
6566 env
->xregs
[0] = do_arm_semihosting(env
);
6573 /* Only intercept calls from privileged modes, to provide some
6574 * semblance of security.
6576 if (cs
->exception_index
!= EXCP_SEMIHOST
&&
6577 (!semihosting_enabled() ||
6578 ((env
->uncached_cpsr
& CPSR_M
) == ARM_CPU_MODE_USR
))) {
6582 switch (cs
->exception_index
) {
6584 /* This is always a semihosting call; the "is this usermode"
6585 * and "is semihosting enabled" checks have been done at
6590 /* Check for semihosting interrupt. */
6592 imm
= arm_lduw_code(env
, env
->regs
[15] - 2, arm_sctlr_b(env
))
6598 imm
= arm_ldl_code(env
, env
->regs
[15] - 4, arm_sctlr_b(env
))
6600 if (imm
== 0x123456) {
6606 /* See if this is a semihosting syscall. */
6608 imm
= arm_lduw_code(env
, env
->regs
[15], arm_sctlr_b(env
))
6620 qemu_log_mask(CPU_LOG_INT
,
6621 "...handling as semihosting call 0x%x\n",
6623 env
->regs
[0] = do_arm_semihosting(env
);
6628 /* Handle a CPU exception for A and R profile CPUs.
6629 * Do any appropriate logging, handle PSCI calls, and then hand off
6630 * to the AArch64-entry or AArch32-entry function depending on the
6631 * target exception level's register width.
6633 void arm_cpu_do_interrupt(CPUState
*cs
)
6635 ARMCPU
*cpu
= ARM_CPU(cs
);
6636 CPUARMState
*env
= &cpu
->env
;
6637 unsigned int new_el
= env
->exception
.target_el
;
6641 arm_log_exception(cs
->exception_index
);
6642 qemu_log_mask(CPU_LOG_INT
, "...from EL%d to EL%d\n", arm_current_el(env
),
6644 if (qemu_loglevel_mask(CPU_LOG_INT
)
6645 && !excp_is_internal(cs
->exception_index
)) {
6646 qemu_log_mask(CPU_LOG_INT
, "...with ESR %x/0x%" PRIx32
"\n",
6647 env
->exception
.syndrome
>> ARM_EL_EC_SHIFT
,
6648 env
->exception
.syndrome
);
6651 if (arm_is_psci_call(cpu
, cs
->exception_index
)) {
6652 arm_handle_psci_call(cpu
);
6653 qemu_log_mask(CPU_LOG_INT
, "...handled as PSCI call\n");
6657 /* Semihosting semantics depend on the register width of the
6658 * code that caused the exception, not the target exception level,
6659 * so must be handled here.
6661 if (check_for_semihosting(cs
)) {
6665 assert(!excp_is_internal(cs
->exception_index
));
6666 if (arm_el_is_aa64(env
, new_el
)) {
6667 arm_cpu_do_interrupt_aarch64(cs
);
6669 arm_cpu_do_interrupt_aarch32(cs
);
6672 arm_call_el_change_hook(cpu
);
6674 if (!kvm_enabled()) {
6675 cs
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
6679 /* Return the exception level which controls this address translation regime */
6680 static inline uint32_t regime_el(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
6683 case ARMMMUIdx_S2NS
:
6684 case ARMMMUIdx_S1E2
:
6686 case ARMMMUIdx_S1E3
:
6688 case ARMMMUIdx_S1SE0
:
6689 return arm_el_is_aa64(env
, 3) ? 1 : 3;
6690 case ARMMMUIdx_S1SE1
:
6691 case ARMMMUIdx_S1NSE0
:
6692 case ARMMMUIdx_S1NSE1
:
6695 g_assert_not_reached();
6699 /* Return true if this address translation regime is secure */
6700 static inline bool regime_is_secure(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
6703 case ARMMMUIdx_S12NSE0
:
6704 case ARMMMUIdx_S12NSE1
:
6705 case ARMMMUIdx_S1NSE0
:
6706 case ARMMMUIdx_S1NSE1
:
6707 case ARMMMUIdx_S1E2
:
6708 case ARMMMUIdx_S2NS
:
6710 case ARMMMUIdx_S1E3
:
6711 case ARMMMUIdx_S1SE0
:
6712 case ARMMMUIdx_S1SE1
:
6715 g_assert_not_reached();
6719 /* Return the SCTLR value which controls this address translation regime */
6720 static inline uint32_t regime_sctlr(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
6722 return env
->cp15
.sctlr_el
[regime_el(env
, mmu_idx
)];
6725 /* Return true if the specified stage of address translation is disabled */
6726 static inline bool regime_translation_disabled(CPUARMState
*env
,
6729 if (mmu_idx
== ARMMMUIdx_S2NS
) {
6730 return (env
->cp15
.hcr_el2
& HCR_VM
) == 0;
6732 return (regime_sctlr(env
, mmu_idx
) & SCTLR_M
) == 0;
6735 static inline bool regime_translation_big_endian(CPUARMState
*env
,
6738 return (regime_sctlr(env
, mmu_idx
) & SCTLR_EE
) != 0;
6741 /* Return the TCR controlling this translation regime */
6742 static inline TCR
*regime_tcr(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
6744 if (mmu_idx
== ARMMMUIdx_S2NS
) {
6745 return &env
->cp15
.vtcr_el2
;
6747 return &env
->cp15
.tcr_el
[regime_el(env
, mmu_idx
)];
6750 /* Returns TBI0 value for current regime el */
6751 uint32_t arm_regime_tbi0(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
6756 /* For EL0 and EL1, TBI is controlled by stage 1's TCR, so convert
6757 * a stage 1+2 mmu index into the appropriate stage 1 mmu index.
6759 if (mmu_idx
== ARMMMUIdx_S12NSE0
|| mmu_idx
== ARMMMUIdx_S12NSE1
) {
6760 mmu_idx
+= ARMMMUIdx_S1NSE0
;
6763 tcr
= regime_tcr(env
, mmu_idx
);
6764 el
= regime_el(env
, mmu_idx
);
6767 return extract64(tcr
->raw_tcr
, 20, 1);
6769 return extract64(tcr
->raw_tcr
, 37, 1);
6773 /* Returns TBI1 value for current regime el */
6774 uint32_t arm_regime_tbi1(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
6779 /* For EL0 and EL1, TBI is controlled by stage 1's TCR, so convert
6780 * a stage 1+2 mmu index into the appropriate stage 1 mmu index.
6782 if (mmu_idx
== ARMMMUIdx_S12NSE0
|| mmu_idx
== ARMMMUIdx_S12NSE1
) {
6783 mmu_idx
+= ARMMMUIdx_S1NSE0
;
6786 tcr
= regime_tcr(env
, mmu_idx
);
6787 el
= regime_el(env
, mmu_idx
);
6792 return extract64(tcr
->raw_tcr
, 38, 1);
6796 /* Return the TTBR associated with this translation regime */
6797 static inline uint64_t regime_ttbr(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
6800 if (mmu_idx
== ARMMMUIdx_S2NS
) {
6801 return env
->cp15
.vttbr_el2
;
6804 return env
->cp15
.ttbr0_el
[regime_el(env
, mmu_idx
)];
6806 return env
->cp15
.ttbr1_el
[regime_el(env
, mmu_idx
)];
6810 /* Return true if the translation regime is using LPAE format page tables */
6811 static inline bool regime_using_lpae_format(CPUARMState
*env
,
6814 int el
= regime_el(env
, mmu_idx
);
6815 if (el
== 2 || arm_el_is_aa64(env
, el
)) {
6818 if (arm_feature(env
, ARM_FEATURE_LPAE
)
6819 && (regime_tcr(env
, mmu_idx
)->raw_tcr
& TTBCR_EAE
)) {
6825 /* Returns true if the stage 1 translation regime is using LPAE format page
6826 * tables. Used when raising alignment exceptions, whose FSR changes depending
6827 * on whether the long or short descriptor format is in use. */
6828 bool arm_s1_regime_using_lpae_format(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
6830 if (mmu_idx
== ARMMMUIdx_S12NSE0
|| mmu_idx
== ARMMMUIdx_S12NSE1
) {
6831 mmu_idx
+= ARMMMUIdx_S1NSE0
;
6834 return regime_using_lpae_format(env
, mmu_idx
);
6837 static inline bool regime_is_user(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
6840 case ARMMMUIdx_S1SE0
:
6841 case ARMMMUIdx_S1NSE0
:
6845 case ARMMMUIdx_S12NSE0
:
6846 case ARMMMUIdx_S12NSE1
:
6847 g_assert_not_reached();
6851 /* Translate section/page access permissions to page
6852 * R/W protection flags
6855 * @mmu_idx: MMU index indicating required translation regime
6856 * @ap: The 3-bit access permissions (AP[2:0])
6857 * @domain_prot: The 2-bit domain access permissions
6859 static inline int ap_to_rw_prot(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
6860 int ap
, int domain_prot
)
6862 bool is_user
= regime_is_user(env
, mmu_idx
);
6864 if (domain_prot
== 3) {
6865 return PAGE_READ
| PAGE_WRITE
;
6870 if (arm_feature(env
, ARM_FEATURE_V7
)) {
6873 switch (regime_sctlr(env
, mmu_idx
) & (SCTLR_S
| SCTLR_R
)) {
6875 return is_user
? 0 : PAGE_READ
;
6882 return is_user
? 0 : PAGE_READ
| PAGE_WRITE
;
6887 return PAGE_READ
| PAGE_WRITE
;
6890 return PAGE_READ
| PAGE_WRITE
;
6891 case 4: /* Reserved. */
6894 return is_user
? 0 : PAGE_READ
;
6898 if (!arm_feature(env
, ARM_FEATURE_V6K
)) {
6903 g_assert_not_reached();
6907 /* Translate section/page access permissions to page
6908 * R/W protection flags.
6910 * @ap: The 2-bit simple AP (AP[2:1])
6911 * @is_user: TRUE if accessing from PL0
6913 static inline int simple_ap_to_rw_prot_is_user(int ap
, bool is_user
)
6917 return is_user
? 0 : PAGE_READ
| PAGE_WRITE
;
6919 return PAGE_READ
| PAGE_WRITE
;
6921 return is_user
? 0 : PAGE_READ
;
6925 g_assert_not_reached();
6930 simple_ap_to_rw_prot(CPUARMState
*env
, ARMMMUIdx mmu_idx
, int ap
)
6932 return simple_ap_to_rw_prot_is_user(ap
, regime_is_user(env
, mmu_idx
));
6935 /* Translate S2 section/page access permissions to protection flags
6938 * @s2ap: The 2-bit stage2 access permissions (S2AP)
6939 * @xn: XN (execute-never) bit
6941 static int get_S2prot(CPUARMState
*env
, int s2ap
, int xn
)
6952 if (arm_el_is_aa64(env
, 2) || prot
& PAGE_READ
) {
6959 /* Translate section/page access permissions to protection flags
6962 * @mmu_idx: MMU index indicating required translation regime
6963 * @is_aa64: TRUE if AArch64
6964 * @ap: The 2-bit simple AP (AP[2:1])
6965 * @ns: NS (non-secure) bit
6966 * @xn: XN (execute-never) bit
6967 * @pxn: PXN (privileged execute-never) bit
6969 static int get_S1prot(CPUARMState
*env
, ARMMMUIdx mmu_idx
, bool is_aa64
,
6970 int ap
, int ns
, int xn
, int pxn
)
6972 bool is_user
= regime_is_user(env
, mmu_idx
);
6973 int prot_rw
, user_rw
;
6977 assert(mmu_idx
!= ARMMMUIdx_S2NS
);
6979 user_rw
= simple_ap_to_rw_prot_is_user(ap
, true);
6983 prot_rw
= simple_ap_to_rw_prot_is_user(ap
, false);
6986 if (ns
&& arm_is_secure(env
) && (env
->cp15
.scr_el3
& SCR_SIF
)) {
6990 /* TODO have_wxn should be replaced with
6991 * ARM_FEATURE_V8 || (ARM_FEATURE_V7 && ARM_FEATURE_EL2)
6992 * when ARM_FEATURE_EL2 starts getting set. For now we assume all LPAE
6993 * compatible processors have EL2, which is required for [U]WXN.
6995 have_wxn
= arm_feature(env
, ARM_FEATURE_LPAE
);
6998 wxn
= regime_sctlr(env
, mmu_idx
) & SCTLR_WXN
;
7002 switch (regime_el(env
, mmu_idx
)) {
7005 xn
= pxn
|| (user_rw
& PAGE_WRITE
);
7012 } else if (arm_feature(env
, ARM_FEATURE_V7
)) {
7013 switch (regime_el(env
, mmu_idx
)) {
7017 xn
= xn
|| !(user_rw
& PAGE_READ
);
7021 uwxn
= regime_sctlr(env
, mmu_idx
) & SCTLR_UWXN
;
7023 xn
= xn
|| !(prot_rw
& PAGE_READ
) || pxn
||
7024 (uwxn
&& (user_rw
& PAGE_WRITE
));
7034 if (xn
|| (wxn
&& (prot_rw
& PAGE_WRITE
))) {
7037 return prot_rw
| PAGE_EXEC
;
7040 static bool get_level1_table_address(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
7041 uint32_t *table
, uint32_t address
)
7043 /* Note that we can only get here for an AArch32 PL0/PL1 lookup */
7044 TCR
*tcr
= regime_tcr(env
, mmu_idx
);
7046 if (address
& tcr
->mask
) {
7047 if (tcr
->raw_tcr
& TTBCR_PD1
) {
7048 /* Translation table walk disabled for TTBR1 */
7051 *table
= regime_ttbr(env
, mmu_idx
, 1) & 0xffffc000;
7053 if (tcr
->raw_tcr
& TTBCR_PD0
) {
7054 /* Translation table walk disabled for TTBR0 */
7057 *table
= regime_ttbr(env
, mmu_idx
, 0) & tcr
->base_mask
;
7059 *table
|= (address
>> 18) & 0x3ffc;
7063 /* Translate a S1 pagetable walk through S2 if needed. */
7064 static hwaddr
S1_ptw_translate(CPUARMState
*env
, ARMMMUIdx mmu_idx
,
7065 hwaddr addr
, MemTxAttrs txattrs
,
7067 ARMMMUFaultInfo
*fi
)
7069 if ((mmu_idx
== ARMMMUIdx_S1NSE0
|| mmu_idx
== ARMMMUIdx_S1NSE1
) &&
7070 !regime_translation_disabled(env
, ARMMMUIdx_S2NS
)) {
7071 target_ulong s2size
;
7076 ret
= get_phys_addr_lpae(env
, addr
, 0, ARMMMUIdx_S2NS
, &s2pa
,
7077 &txattrs
, &s2prot
, &s2size
, fsr
, fi
);
7089 /* All loads done in the course of a page table walk go through here.
7090 * TODO: rather than ignoring errors from physical memory reads (which
7091 * are external aborts in ARM terminology) we should propagate this
7092 * error out so that we can turn it into a Data Abort if this walk
7093 * was being done for a CPU load/store or an address translation instruction
7094 * (but not if it was for a debug access).
7096 static uint32_t arm_ldl_ptw(CPUState
*cs
, hwaddr addr
, bool is_secure
,
7097 ARMMMUIdx mmu_idx
, uint32_t *fsr
,
7098 ARMMMUFaultInfo
*fi
)
7100 ARMCPU
*cpu
= ARM_CPU(cs
);
7101 CPUARMState
*env
= &cpu
->env
;
7102 MemTxAttrs attrs
= {};
7105 attrs
.secure
= is_secure
;
7106 as
= arm_addressspace(cs
, attrs
);
7107 addr
= S1_ptw_translate(env
, mmu_idx
, addr
, attrs
, fsr
, fi
);
7111 if (regime_translation_big_endian(env
, mmu_idx
)) {
7112 return address_space_ldl_be(as
, addr
, attrs
, NULL
);
7114 return address_space_ldl_le(as
, addr
, attrs
, NULL
);
7118 static uint64_t arm_ldq_ptw(CPUState
*cs
, hwaddr addr
, bool is_secure
,
7119 ARMMMUIdx mmu_idx
, uint32_t *fsr
,
7120 ARMMMUFaultInfo
*fi
)
7122 ARMCPU
*cpu
= ARM_CPU(cs
);
7123 CPUARMState
*env
= &cpu
->env
;
7124 MemTxAttrs attrs
= {};
7127 attrs
.secure
= is_secure
;
7128 as
= arm_addressspace(cs
, attrs
);
7129 addr
= S1_ptw_translate(env
, mmu_idx
, addr
, attrs
, fsr
, fi
);
7133 if (regime_translation_big_endian(env
, mmu_idx
)) {
7134 return address_space_ldq_be(as
, addr
, attrs
, NULL
);
7136 return address_space_ldq_le(as
, addr
, attrs
, NULL
);
7140 static bool get_phys_addr_v5(CPUARMState
*env
, uint32_t address
,
7141 int access_type
, ARMMMUIdx mmu_idx
,
7142 hwaddr
*phys_ptr
, int *prot
,
7143 target_ulong
*page_size
, uint32_t *fsr
,
7144 ARMMMUFaultInfo
*fi
)
7146 CPUState
*cs
= CPU(arm_env_get_cpu(env
));
7157 /* Pagetable walk. */
7158 /* Lookup l1 descriptor. */
7159 if (!get_level1_table_address(env
, mmu_idx
, &table
, address
)) {
7160 /* Section translation fault if page walk is disabled by PD0 or PD1 */
7164 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
7167 domain
= (desc
>> 5) & 0x0f;
7168 if (regime_el(env
, mmu_idx
) == 1) {
7169 dacr
= env
->cp15
.dacr_ns
;
7171 dacr
= env
->cp15
.dacr_s
;
7173 domain_prot
= (dacr
>> (domain
* 2)) & 3;
7175 /* Section translation fault. */
7179 if (domain_prot
== 0 || domain_prot
== 2) {
7181 code
= 9; /* Section domain fault. */
7183 code
= 11; /* Page domain fault. */
7188 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
7189 ap
= (desc
>> 10) & 3;
7191 *page_size
= 1024 * 1024;
7193 /* Lookup l2 entry. */
7195 /* Coarse pagetable. */
7196 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
7198 /* Fine pagetable. */
7199 table
= (desc
& 0xfffff000) | ((address
>> 8) & 0xffc);
7201 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
7204 case 0: /* Page translation fault. */
7207 case 1: /* 64k page. */
7208 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
7209 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
7210 *page_size
= 0x10000;
7212 case 2: /* 4k page. */
7213 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
7214 ap
= (desc
>> (4 + ((address
>> 9) & 6))) & 3;
7215 *page_size
= 0x1000;
7217 case 3: /* 1k page, or ARMv6/XScale "extended small (4k) page" */
7219 /* ARMv6/XScale extended small page format */
7220 if (arm_feature(env
, ARM_FEATURE_XSCALE
)
7221 || arm_feature(env
, ARM_FEATURE_V6
)) {
7222 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
7223 *page_size
= 0x1000;
7225 /* UNPREDICTABLE in ARMv5; we choose to take a
7226 * page translation fault.
7232 phys_addr
= (desc
& 0xfffffc00) | (address
& 0x3ff);
7235 ap
= (desc
>> 4) & 3;
7238 /* Never happens, but compiler isn't smart enough to tell. */
7243 *prot
= ap_to_rw_prot(env
, mmu_idx
, ap
, domain_prot
);
7244 *prot
|= *prot
? PAGE_EXEC
: 0;
7245 if (!(*prot
& (1 << access_type
))) {
7246 /* Access permission fault. */
7249 *phys_ptr
= phys_addr
;
7252 *fsr
= code
| (domain
<< 4);
7256 static bool get_phys_addr_v6(CPUARMState
*env
, uint32_t address
,
7257 int access_type
, ARMMMUIdx mmu_idx
,
7258 hwaddr
*phys_ptr
, MemTxAttrs
*attrs
, int *prot
,
7259 target_ulong
*page_size
, uint32_t *fsr
,
7260 ARMMMUFaultInfo
*fi
)
7262 CPUState
*cs
= CPU(arm_env_get_cpu(env
));
7276 /* Pagetable walk. */
7277 /* Lookup l1 descriptor. */
7278 if (!get_level1_table_address(env
, mmu_idx
, &table
, address
)) {
7279 /* Section translation fault if page walk is disabled by PD0 or PD1 */
7283 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
7286 if (type
== 0 || (type
== 3 && !arm_feature(env
, ARM_FEATURE_PXN
))) {
7287 /* Section translation fault, or attempt to use the encoding
7288 * which is Reserved on implementations without PXN.
7293 if ((type
== 1) || !(desc
& (1 << 18))) {
7294 /* Page or Section. */
7295 domain
= (desc
>> 5) & 0x0f;
7297 if (regime_el(env
, mmu_idx
) == 1) {
7298 dacr
= env
->cp15
.dacr_ns
;
7300 dacr
= env
->cp15
.dacr_s
;
7302 domain_prot
= (dacr
>> (domain
* 2)) & 3;
7303 if (domain_prot
== 0 || domain_prot
== 2) {
7305 code
= 9; /* Section domain fault. */
7307 code
= 11; /* Page domain fault. */
7312 if (desc
& (1 << 18)) {
7314 phys_addr
= (desc
& 0xff000000) | (address
& 0x00ffffff);
7315 phys_addr
|= (uint64_t)extract32(desc
, 20, 4) << 32;
7316 phys_addr
|= (uint64_t)extract32(desc
, 5, 4) << 36;
7317 *page_size
= 0x1000000;
7320 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
7321 *page_size
= 0x100000;
7323 ap
= ((desc
>> 10) & 3) | ((desc
>> 13) & 4);
7324 xn
= desc
& (1 << 4);
7327 ns
= extract32(desc
, 19, 1);
7329 if (arm_feature(env
, ARM_FEATURE_PXN
)) {
7330 pxn
= (desc
>> 2) & 1;
7332 ns
= extract32(desc
, 3, 1);
7333 /* Lookup l2 entry. */
7334 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
7335 desc
= arm_ldl_ptw(cs
, table
, regime_is_secure(env
, mmu_idx
),
7337 ap
= ((desc
>> 4) & 3) | ((desc
>> 7) & 4);
7339 case 0: /* Page translation fault. */
7342 case 1: /* 64k page. */
7343 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
7344 xn
= desc
& (1 << 15);
7345 *page_size
= 0x10000;
7347 case 2: case 3: /* 4k page. */
7348 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
7350 *page_size
= 0x1000;
7353 /* Never happens, but compiler isn't smart enough to tell. */
7358 if (domain_prot
== 3) {
7359 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
7361 if (pxn
&& !regime_is_user(env
, mmu_idx
)) {
7364 if (xn
&& access_type
== 2)
7367 if (arm_feature(env
, ARM_FEATURE_V6K
) &&
7368 (regime_sctlr(env
, mmu_idx
) & SCTLR_AFE
)) {
7369 /* The simplified model uses AP[0] as an access control bit. */
7370 if ((ap
& 1) == 0) {
7371 /* Access flag fault. */
7372 code
= (code
== 15) ? 6 : 3;
7375 *prot
= simple_ap_to_rw_prot(env
, mmu_idx
, ap
>> 1);
7377 *prot
= ap_to_rw_prot(env
, mmu_idx
, ap
, domain_prot
);
7382 if (!(*prot
& (1 << access_type
))) {
7383 /* Access permission fault. */
7388 /* The NS bit will (as required by the architecture) have no effect if
7389 * the CPU doesn't support TZ or this is a non-secure translation
7390 * regime, because the attribute will already be non-secure.
7392 attrs
->secure
= false;
7394 *phys_ptr
= phys_addr
;
7397 *fsr
= code
| (domain
<< 4);
7401 /* Fault type for long-descriptor MMU fault reporting; this corresponds
7402 * to bits [5..2] in the STATUS field in long-format DFSR/IFSR.
7405 translation_fault
= 1,
7407 permission_fault
= 3,
7411 * check_s2_mmu_setup
7413 * @is_aa64: True if the translation regime is in AArch64 state
7414 * @startlevel: Suggested starting level
7415 * @inputsize: Bitsize of IPAs
7416 * @stride: Page-table stride (See the ARM ARM)
7418 * Returns true if the suggested S2 translation parameters are OK and
7421 static bool check_s2_mmu_setup(ARMCPU
*cpu
, bool is_aa64
, int level
,
7422 int inputsize
, int stride
)
7424 const int grainsize
= stride
+ 3;
7427 /* Negative levels are never allowed. */
7432 startsizecheck
= inputsize
- ((3 - level
) * stride
+ grainsize
);
7433 if (startsizecheck
< 1 || startsizecheck
> stride
+ 4) {
7438 CPUARMState
*env
= &cpu
->env
;
7439 unsigned int pamax
= arm_pamax(cpu
);
7442 case 13: /* 64KB Pages. */
7443 if (level
== 0 || (level
== 1 && pamax
<= 42)) {
7447 case 11: /* 16KB Pages. */
7448 if (level
== 0 || (level
== 1 && pamax
<= 40)) {
7452 case 9: /* 4KB Pages. */
7453 if (level
== 0 && pamax
<= 42) {
7458 g_assert_not_reached();
7461 /* Inputsize checks. */
7462 if (inputsize
> pamax
&&
7463 (arm_el_is_aa64(env
, 1) || inputsize
> 40)) {
7464 /* This is CONSTRAINED UNPREDICTABLE and we choose to fault. */
7468 /* AArch32 only supports 4KB pages. Assert on that. */
7469 assert(stride
== 9);
7478 static bool get_phys_addr_lpae(CPUARMState
*env
, target_ulong address
,
7479 int access_type
, ARMMMUIdx mmu_idx
,
7480 hwaddr
*phys_ptr
, MemTxAttrs
*txattrs
, int *prot
,
7481 target_ulong
*page_size_ptr
, uint32_t *fsr
,
7482 ARMMMUFaultInfo
*fi
)
7484 ARMCPU
*cpu
= arm_env_get_cpu(env
);
7485 CPUState
*cs
= CPU(cpu
);
7486 /* Read an LPAE long-descriptor translation table. */
7487 MMUFaultType fault_type
= translation_fault
;
7494 hwaddr descaddr
, indexmask
, indexmask_grainsize
;
7495 uint32_t tableattrs
;
7496 target_ulong page_size
;
7502 TCR
*tcr
= regime_tcr(env
, mmu_idx
);
7503 int ap
, ns
, xn
, pxn
;
7504 uint32_t el
= regime_el(env
, mmu_idx
);
7505 bool ttbr1_valid
= true;
7506 uint64_t descaddrmask
;
7507 bool aarch64
= arm_el_is_aa64(env
, el
);
7510 * This code does not handle the different format TCR for VTCR_EL2.
7511 * This code also does not support shareability levels.
7512 * Attribute and permission bit handling should also be checked when adding
7513 * support for those page table walks.
7519 if (mmu_idx
!= ARMMMUIdx_S2NS
) {
7520 tbi
= extract64(tcr
->raw_tcr
, 20, 1);
7523 if (extract64(address
, 55, 1)) {
7524 tbi
= extract64(tcr
->raw_tcr
, 38, 1);
7526 tbi
= extract64(tcr
->raw_tcr
, 37, 1);
7531 /* If we are in 64-bit EL2 or EL3 then there is no TTBR1, so mark it
7535 ttbr1_valid
= false;
7540 /* There is no TTBR1 for EL2 */
7542 ttbr1_valid
= false;
7546 /* Determine whether this address is in the region controlled by
7547 * TTBR0 or TTBR1 (or if it is in neither region and should fault).
7548 * This is a Non-secure PL0/1 stage 1 translation, so controlled by
7549 * TTBCR/TTBR0/TTBR1 in accordance with ARM ARM DDI0406C table B-32:
7552 /* AArch64 translation. */
7553 t0sz
= extract32(tcr
->raw_tcr
, 0, 6);
7554 t0sz
= MIN(t0sz
, 39);
7555 t0sz
= MAX(t0sz
, 16);
7556 } else if (mmu_idx
!= ARMMMUIdx_S2NS
) {
7557 /* AArch32 stage 1 translation. */
7558 t0sz
= extract32(tcr
->raw_tcr
, 0, 3);
7560 /* AArch32 stage 2 translation. */
7561 bool sext
= extract32(tcr
->raw_tcr
, 4, 1);
7562 bool sign
= extract32(tcr
->raw_tcr
, 3, 1);
7563 /* Address size is 40-bit for a stage 2 translation,
7564 * and t0sz can be negative (from -8 to 7),
7565 * so we need to adjust it to use the TTBR selecting logic below.
7568 t0sz
= sextract32(tcr
->raw_tcr
, 0, 4) + 8;
7570 /* If the sign-extend bit is not the same as t0sz[3], the result
7571 * is unpredictable. Flag this as a guest error. */
7573 qemu_log_mask(LOG_GUEST_ERROR
,
7574 "AArch32: VTCR.S / VTCR.T0SZ[3] mismatch\n");
7577 t1sz
= extract32(tcr
->raw_tcr
, 16, 6);
7579 t1sz
= MIN(t1sz
, 39);
7580 t1sz
= MAX(t1sz
, 16);
7582 if (t0sz
&& !extract64(address
, addrsize
- t0sz
, t0sz
- tbi
)) {
7583 /* there is a ttbr0 region and we are in it (high bits all zero) */
7585 } else if (ttbr1_valid
&& t1sz
&&
7586 !extract64(~address
, addrsize
- t1sz
, t1sz
- tbi
)) {
7587 /* there is a ttbr1 region and we are in it (high bits all one) */
7590 /* ttbr0 region is "everything not in the ttbr1 region" */
7592 } else if (!t1sz
&& ttbr1_valid
) {
7593 /* ttbr1 region is "everything not in the ttbr0 region" */
7596 /* in the gap between the two regions, this is a Translation fault */
7597 fault_type
= translation_fault
;
7601 /* Note that QEMU ignores shareability and cacheability attributes,
7602 * so we don't need to do anything with the SH, ORGN, IRGN fields
7603 * in the TTBCR. Similarly, TTBCR:A1 selects whether we get the
7604 * ASID from TTBR0 or TTBR1, but QEMU's TLB doesn't currently
7605 * implement any ASID-like capability so we can ignore it (instead
7606 * we will always flush the TLB any time the ASID is changed).
7608 if (ttbr_select
== 0) {
7609 ttbr
= regime_ttbr(env
, mmu_idx
, 0);
7611 epd
= extract32(tcr
->raw_tcr
, 7, 1);
7613 inputsize
= addrsize
- t0sz
;
7615 tg
= extract32(tcr
->raw_tcr
, 14, 2);
7616 if (tg
== 1) { /* 64KB pages */
7619 if (tg
== 2) { /* 16KB pages */
7623 /* We should only be here if TTBR1 is valid */
7624 assert(ttbr1_valid
);
7626 ttbr
= regime_ttbr(env
, mmu_idx
, 1);
7627 epd
= extract32(tcr
->raw_tcr
, 23, 1);
7628 inputsize
= addrsize
- t1sz
;
7630 tg
= extract32(tcr
->raw_tcr
, 30, 2);
7631 if (tg
== 3) { /* 64KB pages */
7634 if (tg
== 1) { /* 16KB pages */
7639 /* Here we should have set up all the parameters for the translation:
7640 * inputsize, ttbr, epd, stride, tbi
7644 /* Translation table walk disabled => Translation fault on TLB miss
7645 * Note: This is always 0 on 64-bit EL2 and EL3.
7650 if (mmu_idx
!= ARMMMUIdx_S2NS
) {
7651 /* The starting level depends on the virtual address size (which can
7652 * be up to 48 bits) and the translation granule size. It indicates
7653 * the number of strides (stride bits at a time) needed to
7654 * consume the bits of the input address. In the pseudocode this is:
7655 * level = 4 - RoundUp((inputsize - grainsize) / stride)
7656 * where their 'inputsize' is our 'inputsize', 'grainsize' is
7657 * our 'stride + 3' and 'stride' is our 'stride'.
7658 * Applying the usual "rounded up m/n is (m+n-1)/n" and simplifying:
7659 * = 4 - (inputsize - stride - 3 + stride - 1) / stride
7660 * = 4 - (inputsize - 4) / stride;
7662 level
= 4 - (inputsize
- 4) / stride
;
7664 /* For stage 2 translations the starting level is specified by the
7665 * VTCR_EL2.SL0 field (whose interpretation depends on the page size)
7667 uint32_t sl0
= extract32(tcr
->raw_tcr
, 6, 2);
7668 uint32_t startlevel
;
7671 if (!aarch64
|| stride
== 9) {
7672 /* AArch32 or 4KB pages */
7673 startlevel
= 2 - sl0
;
7675 /* 16KB or 64KB pages */
7676 startlevel
= 3 - sl0
;
7679 /* Check that the starting level is valid. */
7680 ok
= check_s2_mmu_setup(cpu
, aarch64
, startlevel
,
7683 fault_type
= translation_fault
;
7689 indexmask_grainsize
= (1ULL << (stride
+ 3)) - 1;
7690 indexmask
= (1ULL << (inputsize
- (stride
* (4 - level
)))) - 1;
7692 /* Now we can extract the actual base address from the TTBR */
7693 descaddr
= extract64(ttbr
, 0, 48);
7694 descaddr
&= ~indexmask
;
7696 /* The address field in the descriptor goes up to bit 39 for ARMv7
7697 * but up to bit 47 for ARMv8, but we use the descaddrmask
7698 * up to bit 39 for AArch32, because we don't need other bits in that case
7699 * to construct next descriptor address (anyway they should be all zeroes).
7701 descaddrmask
= ((1ull << (aarch64
? 48 : 40)) - 1) &
7702 ~indexmask_grainsize
;
7704 /* Secure accesses start with the page table in secure memory and
7705 * can be downgraded to non-secure at any step. Non-secure accesses
7706 * remain non-secure. We implement this by just ORing in the NSTable/NS
7707 * bits at each step.
7709 tableattrs
= regime_is_secure(env
, mmu_idx
) ? 0 : (1 << 4);
7711 uint64_t descriptor
;
7714 descaddr
|= (address
>> (stride
* (4 - level
))) & indexmask
;
7716 nstable
= extract32(tableattrs
, 4, 1);
7717 descriptor
= arm_ldq_ptw(cs
, descaddr
, !nstable
, mmu_idx
, fsr
, fi
);
7722 if (!(descriptor
& 1) ||
7723 (!(descriptor
& 2) && (level
== 3))) {
7724 /* Invalid, or the Reserved level 3 encoding */
7727 descaddr
= descriptor
& descaddrmask
;
7729 if ((descriptor
& 2) && (level
< 3)) {
7730 /* Table entry. The top five bits are attributes which may
7731 * propagate down through lower levels of the table (and
7732 * which are all arranged so that 0 means "no effect", so
7733 * we can gather them up by ORing in the bits at each level).
7735 tableattrs
|= extract64(descriptor
, 59, 5);
7737 indexmask
= indexmask_grainsize
;
7740 /* Block entry at level 1 or 2, or page entry at level 3.
7741 * These are basically the same thing, although the number
7742 * of bits we pull in from the vaddr varies.
7744 page_size
= (1ULL << ((stride
* (4 - level
)) + 3));
7745 descaddr
|= (address
& (page_size
- 1));
7746 /* Extract attributes from the descriptor */
7747 attrs
= extract64(descriptor
, 2, 10)
7748 | (extract64(descriptor
, 52, 12) << 10);
7750 if (mmu_idx
== ARMMMUIdx_S2NS
) {
7751 /* Stage 2 table descriptors do not include any attribute fields */
7754 /* Merge in attributes from table descriptors */
7755 attrs
|= extract32(tableattrs
, 0, 2) << 11; /* XN, PXN */
7756 attrs
|= extract32(tableattrs
, 3, 1) << 5; /* APTable[1] => AP[2] */
7757 /* The sense of AP[1] vs APTable[0] is reversed, as APTable[0] == 1
7758 * means "force PL1 access only", which means forcing AP[1] to 0.
7760 if (extract32(tableattrs
, 2, 1)) {
7763 attrs
|= nstable
<< 3; /* NS */
7766 /* Here descaddr is the final physical address, and attributes
7769 fault_type
= access_fault
;
7770 if ((attrs
& (1 << 8)) == 0) {
7775 ap
= extract32(attrs
, 4, 2);
7776 xn
= extract32(attrs
, 12, 1);
7778 if (mmu_idx
== ARMMMUIdx_S2NS
) {
7780 *prot
= get_S2prot(env
, ap
, xn
);
7782 ns
= extract32(attrs
, 3, 1);
7783 pxn
= extract32(attrs
, 11, 1);
7784 *prot
= get_S1prot(env
, mmu_idx
, aarch64
, ap
, ns
, xn
, pxn
);
7787 fault_type
= permission_fault
;
7788 if (!(*prot
& (1 << access_type
))) {
7793 /* The NS bit will (as required by the architecture) have no effect if
7794 * the CPU doesn't support TZ or this is a non-secure translation
7795 * regime, because the attribute will already be non-secure.
7797 txattrs
->secure
= false;
7799 *phys_ptr
= descaddr
;
7800 *page_size_ptr
= page_size
;
7804 /* Long-descriptor format IFSR/DFSR value */
7805 *fsr
= (1 << 9) | (fault_type
<< 2) | level
;
7806 /* Tag the error as S2 for failed S1 PTW at S2 or ordinary S2. */
7807 fi
->stage2
= fi
->s1ptw
|| (mmu_idx
== ARMMMUIdx_S2NS
);
7811 static inline void get_phys_addr_pmsav7_default(CPUARMState
*env
,
7813 int32_t address
, int *prot
)
7815 *prot
= PAGE_READ
| PAGE_WRITE
;
7817 case 0xF0000000 ... 0xFFFFFFFF:
7818 if (regime_sctlr(env
, mmu_idx
) & SCTLR_V
) { /* hivecs execing is ok */
7822 case 0x00000000 ... 0x7FFFFFFF:
7829 static bool get_phys_addr_pmsav7(CPUARMState
*env
, uint32_t address
,
7830 int access_type
, ARMMMUIdx mmu_idx
,
7831 hwaddr
*phys_ptr
, int *prot
, uint32_t *fsr
)
7833 ARMCPU
*cpu
= arm_env_get_cpu(env
);
7835 bool is_user
= regime_is_user(env
, mmu_idx
);
7837 *phys_ptr
= address
;
7840 if (regime_translation_disabled(env
, mmu_idx
)) { /* MPU disabled */
7841 get_phys_addr_pmsav7_default(env
, mmu_idx
, address
, prot
);
7842 } else { /* MPU enabled */
7843 for (n
= (int)cpu
->pmsav7_dregion
- 1; n
>= 0; n
--) {
7845 uint32_t base
= env
->pmsav7
.drbar
[n
];
7846 uint32_t rsize
= extract32(env
->pmsav7
.drsr
[n
], 1, 5);
7850 if (!(env
->pmsav7
.drsr
[n
] & 0x1)) {
7855 qemu_log_mask(LOG_GUEST_ERROR
, "DRSR.Rsize field can not be 0");
7859 rmask
= (1ull << rsize
) - 1;
7862 qemu_log_mask(LOG_GUEST_ERROR
, "DRBAR %" PRIx32
" misaligned "
7863 "to DRSR region size, mask = %" PRIx32
,
7868 if (address
< base
|| address
> base
+ rmask
) {
7872 /* Region matched */
7874 if (rsize
>= 8) { /* no subregions for regions < 256 bytes */
7876 uint32_t srdis_mask
;
7878 rsize
-= 3; /* sub region size (power of 2) */
7879 snd
= ((address
- base
) >> rsize
) & 0x7;
7880 srdis
= extract32(env
->pmsav7
.drsr
[n
], snd
+ 8, 1);
7882 srdis_mask
= srdis
? 0x3 : 0x0;
7883 for (i
= 2; i
<= 8 && rsize
< TARGET_PAGE_BITS
; i
*= 2) {
7884 /* This will check in groups of 2, 4 and then 8, whether
7885 * the subregion bits are consistent. rsize is incremented
7886 * back up to give the region size, considering consistent
7887 * adjacent subregions as one region. Stop testing if rsize
7888 * is already big enough for an entire QEMU page.
7890 int snd_rounded
= snd
& ~(i
- 1);
7891 uint32_t srdis_multi
= extract32(env
->pmsav7
.drsr
[n
],
7892 snd_rounded
+ 8, i
);
7893 if (srdis_mask
^ srdis_multi
) {
7896 srdis_mask
= (srdis_mask
<< i
) | srdis_mask
;
7900 if (rsize
< TARGET_PAGE_BITS
) {
7901 qemu_log_mask(LOG_UNIMP
, "No support for MPU (sub)region"
7902 "alignment of %" PRIu32
" bits. Minimum is %d\n",
7903 rsize
, TARGET_PAGE_BITS
);
7912 if (n
== -1) { /* no hits */
7913 if (cpu
->pmsav7_dregion
&&
7914 (is_user
|| !(regime_sctlr(env
, mmu_idx
) & SCTLR_BR
))) {
7915 /* background fault */
7919 get_phys_addr_pmsav7_default(env
, mmu_idx
, address
, prot
);
7920 } else { /* a MPU hit! */
7921 uint32_t ap
= extract32(env
->pmsav7
.dracr
[n
], 8, 3);
7923 if (is_user
) { /* User mode AP bit decoding */
7928 break; /* no access */
7930 *prot
|= PAGE_WRITE
;
7934 *prot
|= PAGE_READ
| PAGE_EXEC
;
7937 qemu_log_mask(LOG_GUEST_ERROR
,
7938 "Bad value for AP bits in DRACR %"
7941 } else { /* Priv. mode AP bits decoding */
7944 break; /* no access */
7948 *prot
|= PAGE_WRITE
;
7952 *prot
|= PAGE_READ
| PAGE_EXEC
;
7955 qemu_log_mask(LOG_GUEST_ERROR
,
7956 "Bad value for AP bits in DRACR %"
7962 if (env
->pmsav7
.dracr
[n
] & (1 << 12)) {
7963 *prot
&= ~PAGE_EXEC
;
7968 *fsr
= 0x00d; /* Permission fault */
7969 return !(*prot
& (1 << access_type
));
7972 static bool get_phys_addr_pmsav5(CPUARMState
*env
, uint32_t address
,
7973 int access_type
, ARMMMUIdx mmu_idx
,
7974 hwaddr
*phys_ptr
, int *prot
, uint32_t *fsr
)
7979 bool is_user
= regime_is_user(env
, mmu_idx
);
7981 *phys_ptr
= address
;
7982 for (n
= 7; n
>= 0; n
--) {
7983 base
= env
->cp15
.c6_region
[n
];
7984 if ((base
& 1) == 0) {
7987 mask
= 1 << ((base
>> 1) & 0x1f);
7988 /* Keep this shift separate from the above to avoid an
7989 (undefined) << 32. */
7990 mask
= (mask
<< 1) - 1;
7991 if (((base
^ address
) & ~mask
) == 0) {
8000 if (access_type
== 2) {
8001 mask
= env
->cp15
.pmsav5_insn_ap
;
8003 mask
= env
->cp15
.pmsav5_data_ap
;
8005 mask
= (mask
>> (n
* 4)) & 0xf;
8015 *prot
= PAGE_READ
| PAGE_WRITE
;
8020 *prot
|= PAGE_WRITE
;
8024 *prot
= PAGE_READ
| PAGE_WRITE
;
8037 /* Bad permission. */
8045 /* get_phys_addr - get the physical address for this virtual address
8047 * Find the physical address corresponding to the given virtual address,
8048 * by doing a translation table walk on MMU based systems or using the
8049 * MPU state on MPU based systems.
8051 * Returns false if the translation was successful. Otherwise, phys_ptr, attrs,
8052 * prot and page_size may not be filled in, and the populated fsr value provides
8053 * information on why the translation aborted, in the format of a
8054 * DFSR/IFSR fault register, with the following caveats:
8055 * * we honour the short vs long DFSR format differences.
8056 * * the WnR bit is never set (the caller must do this).
8057 * * for PSMAv5 based systems we don't bother to return a full FSR format
8061 * @address: virtual address to get physical address for
8062 * @access_type: 0 for read, 1 for write, 2 for execute
8063 * @mmu_idx: MMU index indicating required translation regime
8064 * @phys_ptr: set to the physical address corresponding to the virtual address
8065 * @attrs: set to the memory transaction attributes to use
8066 * @prot: set to the permissions for the page containing phys_ptr
8067 * @page_size: set to the size of the page containing phys_ptr
8068 * @fsr: set to the DFSR/IFSR value on failure
8070 static bool get_phys_addr(CPUARMState
*env
, target_ulong address
,
8071 int access_type
, ARMMMUIdx mmu_idx
,
8072 hwaddr
*phys_ptr
, MemTxAttrs
*attrs
, int *prot
,
8073 target_ulong
*page_size
, uint32_t *fsr
,
8074 ARMMMUFaultInfo
*fi
)
8076 if (mmu_idx
== ARMMMUIdx_S12NSE0
|| mmu_idx
== ARMMMUIdx_S12NSE1
) {
8077 /* Call ourselves recursively to do the stage 1 and then stage 2
8080 if (arm_feature(env
, ARM_FEATURE_EL2
)) {
8085 ret
= get_phys_addr(env
, address
, access_type
,
8086 mmu_idx
+ ARMMMUIdx_S1NSE0
, &ipa
, attrs
,
8087 prot
, page_size
, fsr
, fi
);
8089 /* If S1 fails or S2 is disabled, return early. */
8090 if (ret
|| regime_translation_disabled(env
, ARMMMUIdx_S2NS
)) {
8095 /* S1 is done. Now do S2 translation. */
8096 ret
= get_phys_addr_lpae(env
, ipa
, access_type
, ARMMMUIdx_S2NS
,
8097 phys_ptr
, attrs
, &s2_prot
,
8098 page_size
, fsr
, fi
);
8100 /* Combine the S1 and S2 perms. */
8105 * For non-EL2 CPUs a stage1+stage2 translation is just stage 1.
8107 mmu_idx
+= ARMMMUIdx_S1NSE0
;
8111 /* The page table entries may downgrade secure to non-secure, but
8112 * cannot upgrade an non-secure translation regime's attributes
8115 attrs
->secure
= regime_is_secure(env
, mmu_idx
);
8116 attrs
->user
= regime_is_user(env
, mmu_idx
);
8118 /* Fast Context Switch Extension. This doesn't exist at all in v8.
8119 * In v7 and earlier it affects all stage 1 translations.
8121 if (address
< 0x02000000 && mmu_idx
!= ARMMMUIdx_S2NS
8122 && !arm_feature(env
, ARM_FEATURE_V8
)) {
8123 if (regime_el(env
, mmu_idx
) == 3) {
8124 address
+= env
->cp15
.fcseidr_s
;
8126 address
+= env
->cp15
.fcseidr_ns
;
8130 /* pmsav7 has special handling for when MPU is disabled so call it before
8131 * the common MMU/MPU disabled check below.
8133 if (arm_feature(env
, ARM_FEATURE_MPU
) &&
8134 arm_feature(env
, ARM_FEATURE_V7
)) {
8135 *page_size
= TARGET_PAGE_SIZE
;
8136 return get_phys_addr_pmsav7(env
, address
, access_type
, mmu_idx
,
8137 phys_ptr
, prot
, fsr
);
8140 if (regime_translation_disabled(env
, mmu_idx
)) {
8141 /* MMU/MPU disabled. */
8142 *phys_ptr
= address
;
8143 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
8144 *page_size
= TARGET_PAGE_SIZE
;
8148 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
8150 *page_size
= TARGET_PAGE_SIZE
;
8151 return get_phys_addr_pmsav5(env
, address
, access_type
, mmu_idx
,
8152 phys_ptr
, prot
, fsr
);
8155 if (regime_using_lpae_format(env
, mmu_idx
)) {
8156 return get_phys_addr_lpae(env
, address
, access_type
, mmu_idx
, phys_ptr
,
8157 attrs
, prot
, page_size
, fsr
, fi
);
8158 } else if (regime_sctlr(env
, mmu_idx
) & SCTLR_XP
) {
8159 return get_phys_addr_v6(env
, address
, access_type
, mmu_idx
, phys_ptr
,
8160 attrs
, prot
, page_size
, fsr
, fi
);
8162 return get_phys_addr_v5(env
, address
, access_type
, mmu_idx
, phys_ptr
,
8163 prot
, page_size
, fsr
, fi
);
8167 /* Walk the page table and (if the mapping exists) add the page
8168 * to the TLB. Return false on success, or true on failure. Populate
8169 * fsr with ARM DFSR/IFSR fault register format value on failure.
8171 bool arm_tlb_fill(CPUState
*cs
, vaddr address
,
8172 int access_type
, int mmu_idx
, uint32_t *fsr
,
8173 ARMMMUFaultInfo
*fi
)
8175 ARMCPU
*cpu
= ARM_CPU(cs
);
8176 CPUARMState
*env
= &cpu
->env
;
8178 target_ulong page_size
;
8181 MemTxAttrs attrs
= {};
8183 ret
= get_phys_addr(env
, address
, access_type
, mmu_idx
, &phys_addr
,
8184 &attrs
, &prot
, &page_size
, fsr
, fi
);
8186 /* Map a single [sub]page. */
8187 phys_addr
&= TARGET_PAGE_MASK
;
8188 address
&= TARGET_PAGE_MASK
;
8189 tlb_set_page_with_attrs(cs
, address
, phys_addr
, attrs
,
8190 prot
, mmu_idx
, page_size
);
8197 hwaddr
arm_cpu_get_phys_page_attrs_debug(CPUState
*cs
, vaddr addr
,
8200 ARMCPU
*cpu
= ARM_CPU(cs
);
8201 CPUARMState
*env
= &cpu
->env
;
8203 target_ulong page_size
;
8207 ARMMMUFaultInfo fi
= {};
8209 *attrs
= (MemTxAttrs
) {};
8211 ret
= get_phys_addr(env
, addr
, 0, cpu_mmu_index(env
, false), &phys_addr
,
8212 attrs
, &prot
, &page_size
, &fsr
, &fi
);
8220 uint32_t HELPER(v7m_mrs
)(CPUARMState
*env
, uint32_t reg
)
8222 ARMCPU
*cpu
= arm_env_get_cpu(env
);
8226 return xpsr_read(env
) & 0xf8000000;
8228 return xpsr_read(env
) & 0xf80001ff;
8230 return xpsr_read(env
) & 0xff00fc00;
8232 return xpsr_read(env
) & 0xff00fdff;
8234 return xpsr_read(env
) & 0x000001ff;
8236 return xpsr_read(env
) & 0x0700fc00;
8238 return xpsr_read(env
) & 0x0700edff;
8240 return env
->v7m
.current_sp
? env
->v7m
.other_sp
: env
->regs
[13];
8242 return env
->v7m
.current_sp
? env
->regs
[13] : env
->v7m
.other_sp
;
8243 case 16: /* PRIMASK */
8244 return (env
->daif
& PSTATE_I
) != 0;
8245 case 17: /* BASEPRI */
8246 case 18: /* BASEPRI_MAX */
8247 return env
->v7m
.basepri
;
8248 case 19: /* FAULTMASK */
8249 return (env
->daif
& PSTATE_F
) != 0;
8250 case 20: /* CONTROL */
8251 return env
->v7m
.control
;
8253 /* ??? For debugging only. */
8254 cpu_abort(CPU(cpu
), "Unimplemented system register read (%d)\n", reg
);
8259 void HELPER(v7m_msr
)(CPUARMState
*env
, uint32_t reg
, uint32_t val
)
8261 ARMCPU
*cpu
= arm_env_get_cpu(env
);
8265 xpsr_write(env
, val
, 0xf8000000);
8268 xpsr_write(env
, val
, 0xf8000000);
8271 xpsr_write(env
, val
, 0xfe00fc00);
8274 xpsr_write(env
, val
, 0xfe00fc00);
8277 /* IPSR bits are readonly. */
8280 xpsr_write(env
, val
, 0x0600fc00);
8283 xpsr_write(env
, val
, 0x0600fc00);
8286 if (env
->v7m
.current_sp
)
8287 env
->v7m
.other_sp
= val
;
8289 env
->regs
[13] = val
;
8292 if (env
->v7m
.current_sp
)
8293 env
->regs
[13] = val
;
8295 env
->v7m
.other_sp
= val
;
8297 case 16: /* PRIMASK */
8299 env
->daif
|= PSTATE_I
;
8301 env
->daif
&= ~PSTATE_I
;
8304 case 17: /* BASEPRI */
8305 env
->v7m
.basepri
= val
& 0xff;
8307 case 18: /* BASEPRI_MAX */
8309 if (val
!= 0 && (val
< env
->v7m
.basepri
|| env
->v7m
.basepri
== 0))
8310 env
->v7m
.basepri
= val
;
8312 case 19: /* FAULTMASK */
8314 env
->daif
|= PSTATE_F
;
8316 env
->daif
&= ~PSTATE_F
;
8319 case 20: /* CONTROL */
8320 env
->v7m
.control
= val
& 3;
8321 switch_v7m_sp(env
, (val
& 2) != 0);
8324 /* ??? For debugging only. */
8325 cpu_abort(CPU(cpu
), "Unimplemented system register write (%d)\n", reg
);
8332 void HELPER(dc_zva
)(CPUARMState
*env
, uint64_t vaddr_in
)
8334 /* Implement DC ZVA, which zeroes a fixed-length block of memory.
8335 * Note that we do not implement the (architecturally mandated)
8336 * alignment fault for attempts to use this on Device memory
8337 * (which matches the usual QEMU behaviour of not implementing either
8338 * alignment faults or any memory attribute handling).
8341 ARMCPU
*cpu
= arm_env_get_cpu(env
);
8342 uint64_t blocklen
= 4 << cpu
->dcz_blocksize
;
8343 uint64_t vaddr
= vaddr_in
& ~(blocklen
- 1);
8345 #ifndef CONFIG_USER_ONLY
8347 /* Slightly awkwardly, QEMU's TARGET_PAGE_SIZE may be less than
8348 * the block size so we might have to do more than one TLB lookup.
8349 * We know that in fact for any v8 CPU the page size is at least 4K
8350 * and the block size must be 2K or less, but TARGET_PAGE_SIZE is only
8351 * 1K as an artefact of legacy v5 subpage support being present in the
8352 * same QEMU executable.
8354 int maxidx
= DIV_ROUND_UP(blocklen
, TARGET_PAGE_SIZE
);
8355 void *hostaddr
[maxidx
];
8357 unsigned mmu_idx
= cpu_mmu_index(env
, false);
8358 TCGMemOpIdx oi
= make_memop_idx(MO_UB
, mmu_idx
);
8360 for (try = 0; try < 2; try++) {
8362 for (i
= 0; i
< maxidx
; i
++) {
8363 hostaddr
[i
] = tlb_vaddr_to_host(env
,
8364 vaddr
+ TARGET_PAGE_SIZE
* i
,
8371 /* If it's all in the TLB it's fair game for just writing to;
8372 * we know we don't need to update dirty status, etc.
8374 for (i
= 0; i
< maxidx
- 1; i
++) {
8375 memset(hostaddr
[i
], 0, TARGET_PAGE_SIZE
);
8377 memset(hostaddr
[i
], 0, blocklen
- (i
* TARGET_PAGE_SIZE
));
8380 /* OK, try a store and see if we can populate the tlb. This
8381 * might cause an exception if the memory isn't writable,
8382 * in which case we will longjmp out of here. We must for
8383 * this purpose use the actual register value passed to us
8384 * so that we get the fault address right.
8386 helper_ret_stb_mmu(env
, vaddr_in
, 0, oi
, GETPC());
8387 /* Now we can populate the other TLB entries, if any */
8388 for (i
= 0; i
< maxidx
; i
++) {
8389 uint64_t va
= vaddr
+ TARGET_PAGE_SIZE
* i
;
8390 if (va
!= (vaddr_in
& TARGET_PAGE_MASK
)) {
8391 helper_ret_stb_mmu(env
, va
, 0, oi
, GETPC());
8396 /* Slow path (probably attempt to do this to an I/O device or
8397 * similar, or clearing of a block of code we have translations
8398 * cached for). Just do a series of byte writes as the architecture
8399 * demands. It's not worth trying to use a cpu_physical_memory_map(),
8400 * memset(), unmap() sequence here because:
8401 * + we'd need to account for the blocksize being larger than a page
8402 * + the direct-RAM access case is almost always going to be dealt
8403 * with in the fastpath code above, so there's no speed benefit
8404 * + we would have to deal with the map returning NULL because the
8405 * bounce buffer was in use
8407 for (i
= 0; i
< blocklen
; i
++) {
8408 helper_ret_stb_mmu(env
, vaddr
+ i
, 0, oi
, GETPC());
8412 memset(g2h(vaddr
), 0, blocklen
);
8416 /* Note that signed overflow is undefined in C. The following routines are
8417 careful to use unsigned types where modulo arithmetic is required.
8418 Failure to do so _will_ break on newer gcc. */
8420 /* Signed saturating arithmetic. */
8422 /* Perform 16-bit signed saturating addition. */
8423 static inline uint16_t add16_sat(uint16_t a
, uint16_t b
)
8428 if (((res
^ a
) & 0x8000) && !((a
^ b
) & 0x8000)) {
8437 /* Perform 8-bit signed saturating addition. */
8438 static inline uint8_t add8_sat(uint8_t a
, uint8_t b
)
8443 if (((res
^ a
) & 0x80) && !((a
^ b
) & 0x80)) {
8452 /* Perform 16-bit signed saturating subtraction. */
8453 static inline uint16_t sub16_sat(uint16_t a
, uint16_t b
)
8458 if (((res
^ a
) & 0x8000) && ((a
^ b
) & 0x8000)) {
8467 /* Perform 8-bit signed saturating subtraction. */
8468 static inline uint8_t sub8_sat(uint8_t a
, uint8_t b
)
8473 if (((res
^ a
) & 0x80) && ((a
^ b
) & 0x80)) {
8482 #define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
8483 #define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
8484 #define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
8485 #define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
8488 #include "op_addsub.h"
8490 /* Unsigned saturating arithmetic. */
8491 static inline uint16_t add16_usat(uint16_t a
, uint16_t b
)
8500 static inline uint16_t sub16_usat(uint16_t a
, uint16_t b
)
8508 static inline uint8_t add8_usat(uint8_t a
, uint8_t b
)
8517 static inline uint8_t sub8_usat(uint8_t a
, uint8_t b
)
8525 #define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
8526 #define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
8527 #define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
8528 #define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
8531 #include "op_addsub.h"
8533 /* Signed modulo arithmetic. */
8534 #define SARITH16(a, b, n, op) do { \
8536 sum = (int32_t)(int16_t)(a) op (int32_t)(int16_t)(b); \
8537 RESULT(sum, n, 16); \
8539 ge |= 3 << (n * 2); \
8542 #define SARITH8(a, b, n, op) do { \
8544 sum = (int32_t)(int8_t)(a) op (int32_t)(int8_t)(b); \
8545 RESULT(sum, n, 8); \
8551 #define ADD16(a, b, n) SARITH16(a, b, n, +)
8552 #define SUB16(a, b, n) SARITH16(a, b, n, -)
8553 #define ADD8(a, b, n) SARITH8(a, b, n, +)
8554 #define SUB8(a, b, n) SARITH8(a, b, n, -)
8558 #include "op_addsub.h"
8560 /* Unsigned modulo arithmetic. */
8561 #define ADD16(a, b, n) do { \
8563 sum = (uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b); \
8564 RESULT(sum, n, 16); \
8565 if ((sum >> 16) == 1) \
8566 ge |= 3 << (n * 2); \
8569 #define ADD8(a, b, n) do { \
8571 sum = (uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b); \
8572 RESULT(sum, n, 8); \
8573 if ((sum >> 8) == 1) \
8577 #define SUB16(a, b, n) do { \
8579 sum = (uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b); \
8580 RESULT(sum, n, 16); \
8581 if ((sum >> 16) == 0) \
8582 ge |= 3 << (n * 2); \
8585 #define SUB8(a, b, n) do { \
8587 sum = (uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b); \
8588 RESULT(sum, n, 8); \
8589 if ((sum >> 8) == 0) \
8596 #include "op_addsub.h"
8598 /* Halved signed arithmetic. */
8599 #define ADD16(a, b, n) \
8600 RESULT(((int32_t)(int16_t)(a) + (int32_t)(int16_t)(b)) >> 1, n, 16)
8601 #define SUB16(a, b, n) \
8602 RESULT(((int32_t)(int16_t)(a) - (int32_t)(int16_t)(b)) >> 1, n, 16)
8603 #define ADD8(a, b, n) \
8604 RESULT(((int32_t)(int8_t)(a) + (int32_t)(int8_t)(b)) >> 1, n, 8)
8605 #define SUB8(a, b, n) \
8606 RESULT(((int32_t)(int8_t)(a) - (int32_t)(int8_t)(b)) >> 1, n, 8)
8609 #include "op_addsub.h"
8611 /* Halved unsigned arithmetic. */
8612 #define ADD16(a, b, n) \
8613 RESULT(((uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b)) >> 1, n, 16)
8614 #define SUB16(a, b, n) \
8615 RESULT(((uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b)) >> 1, n, 16)
8616 #define ADD8(a, b, n) \
8617 RESULT(((uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b)) >> 1, n, 8)
8618 #define SUB8(a, b, n) \
8619 RESULT(((uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b)) >> 1, n, 8)
8622 #include "op_addsub.h"
8624 static inline uint8_t do_usad(uint8_t a
, uint8_t b
)
8632 /* Unsigned sum of absolute byte differences. */
8633 uint32_t HELPER(usad8
)(uint32_t a
, uint32_t b
)
8636 sum
= do_usad(a
, b
);
8637 sum
+= do_usad(a
>> 8, b
>> 8);
8638 sum
+= do_usad(a
>> 16, b
>>16);
8639 sum
+= do_usad(a
>> 24, b
>> 24);
8643 /* For ARMv6 SEL instruction. */
8644 uint32_t HELPER(sel_flags
)(uint32_t flags
, uint32_t a
, uint32_t b
)
8657 return (a
& mask
) | (b
& ~mask
);
8660 /* VFP support. We follow the convention used for VFP instructions:
8661 Single precision routines have a "s" suffix, double precision a
8664 /* Convert host exception flags to vfp form. */
8665 static inline int vfp_exceptbits_from_host(int host_bits
)
8667 int target_bits
= 0;
8669 if (host_bits
& float_flag_invalid
)
8671 if (host_bits
& float_flag_divbyzero
)
8673 if (host_bits
& float_flag_overflow
)
8675 if (host_bits
& (float_flag_underflow
| float_flag_output_denormal
))
8677 if (host_bits
& float_flag_inexact
)
8678 target_bits
|= 0x10;
8679 if (host_bits
& float_flag_input_denormal
)
8680 target_bits
|= 0x80;
8684 uint32_t HELPER(vfp_get_fpscr
)(CPUARMState
*env
)
8689 fpscr
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & 0xffc8ffff)
8690 | (env
->vfp
.vec_len
<< 16)
8691 | (env
->vfp
.vec_stride
<< 20);
8692 i
= get_float_exception_flags(&env
->vfp
.fp_status
);
8693 i
|= get_float_exception_flags(&env
->vfp
.standard_fp_status
);
8694 fpscr
|= vfp_exceptbits_from_host(i
);
8698 uint32_t vfp_get_fpscr(CPUARMState
*env
)
8700 return HELPER(vfp_get_fpscr
)(env
);
8703 /* Convert vfp exception flags to target form. */
8704 static inline int vfp_exceptbits_to_host(int target_bits
)
8708 if (target_bits
& 1)
8709 host_bits
|= float_flag_invalid
;
8710 if (target_bits
& 2)
8711 host_bits
|= float_flag_divbyzero
;
8712 if (target_bits
& 4)
8713 host_bits
|= float_flag_overflow
;
8714 if (target_bits
& 8)
8715 host_bits
|= float_flag_underflow
;
8716 if (target_bits
& 0x10)
8717 host_bits
|= float_flag_inexact
;
8718 if (target_bits
& 0x80)
8719 host_bits
|= float_flag_input_denormal
;
8723 void HELPER(vfp_set_fpscr
)(CPUARMState
*env
, uint32_t val
)
8728 changed
= env
->vfp
.xregs
[ARM_VFP_FPSCR
];
8729 env
->vfp
.xregs
[ARM_VFP_FPSCR
] = (val
& 0xffc8ffff);
8730 env
->vfp
.vec_len
= (val
>> 16) & 7;
8731 env
->vfp
.vec_stride
= (val
>> 20) & 3;
8734 if (changed
& (3 << 22)) {
8735 i
= (val
>> 22) & 3;
8737 case FPROUNDING_TIEEVEN
:
8738 i
= float_round_nearest_even
;
8740 case FPROUNDING_POSINF
:
8743 case FPROUNDING_NEGINF
:
8744 i
= float_round_down
;
8746 case FPROUNDING_ZERO
:
8747 i
= float_round_to_zero
;
8750 set_float_rounding_mode(i
, &env
->vfp
.fp_status
);
8752 if (changed
& (1 << 24)) {
8753 set_flush_to_zero((val
& (1 << 24)) != 0, &env
->vfp
.fp_status
);
8754 set_flush_inputs_to_zero((val
& (1 << 24)) != 0, &env
->vfp
.fp_status
);
8756 if (changed
& (1 << 25))
8757 set_default_nan_mode((val
& (1 << 25)) != 0, &env
->vfp
.fp_status
);
8759 i
= vfp_exceptbits_to_host(val
);
8760 set_float_exception_flags(i
, &env
->vfp
.fp_status
);
8761 set_float_exception_flags(0, &env
->vfp
.standard_fp_status
);
8764 void vfp_set_fpscr(CPUARMState
*env
, uint32_t val
)
8766 HELPER(vfp_set_fpscr
)(env
, val
);
8769 #define VFP_HELPER(name, p) HELPER(glue(glue(vfp_,name),p))
8771 #define VFP_BINOP(name) \
8772 float32 VFP_HELPER(name, s)(float32 a, float32 b, void *fpstp) \
8774 float_status *fpst = fpstp; \
8775 return float32_ ## name(a, b, fpst); \
8777 float64 VFP_HELPER(name, d)(float64 a, float64 b, void *fpstp) \
8779 float_status *fpst = fpstp; \
8780 return float64_ ## name(a, b, fpst); \
8792 float32
VFP_HELPER(neg
, s
)(float32 a
)
8794 return float32_chs(a
);
8797 float64
VFP_HELPER(neg
, d
)(float64 a
)
8799 return float64_chs(a
);
8802 float32
VFP_HELPER(abs
, s
)(float32 a
)
8804 return float32_abs(a
);
8807 float64
VFP_HELPER(abs
, d
)(float64 a
)
8809 return float64_abs(a
);
8812 float32
VFP_HELPER(sqrt
, s
)(float32 a
, CPUARMState
*env
)
8814 return float32_sqrt(a
, &env
->vfp
.fp_status
);
8817 float64
VFP_HELPER(sqrt
, d
)(float64 a
, CPUARMState
*env
)
8819 return float64_sqrt(a
, &env
->vfp
.fp_status
);
8822 /* XXX: check quiet/signaling case */
8823 #define DO_VFP_cmp(p, type) \
8824 void VFP_HELPER(cmp, p)(type a, type b, CPUARMState *env) \
8827 switch(type ## _compare_quiet(a, b, &env->vfp.fp_status)) { \
8828 case 0: flags = 0x6; break; \
8829 case -1: flags = 0x8; break; \
8830 case 1: flags = 0x2; break; \
8831 default: case 2: flags = 0x3; break; \
8833 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
8834 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
8836 void VFP_HELPER(cmpe, p)(type a, type b, CPUARMState *env) \
8839 switch(type ## _compare(a, b, &env->vfp.fp_status)) { \
8840 case 0: flags = 0x6; break; \
8841 case -1: flags = 0x8; break; \
8842 case 1: flags = 0x2; break; \
8843 default: case 2: flags = 0x3; break; \
8845 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
8846 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
8848 DO_VFP_cmp(s
, float32
)
8849 DO_VFP_cmp(d
, float64
)
8852 /* Integer to float and float to integer conversions */
8854 #define CONV_ITOF(name, fsz, sign) \
8855 float##fsz HELPER(name)(uint32_t x, void *fpstp) \
8857 float_status *fpst = fpstp; \
8858 return sign##int32_to_##float##fsz((sign##int32_t)x, fpst); \
8861 #define CONV_FTOI(name, fsz, sign, round) \
8862 uint32_t HELPER(name)(float##fsz x, void *fpstp) \
8864 float_status *fpst = fpstp; \
8865 if (float##fsz##_is_any_nan(x)) { \
8866 float_raise(float_flag_invalid, fpst); \
8869 return float##fsz##_to_##sign##int32##round(x, fpst); \
8872 #define FLOAT_CONVS(name, p, fsz, sign) \
8873 CONV_ITOF(vfp_##name##to##p, fsz, sign) \
8874 CONV_FTOI(vfp_to##name##p, fsz, sign, ) \
8875 CONV_FTOI(vfp_to##name##z##p, fsz, sign, _round_to_zero)
8877 FLOAT_CONVS(si
, s
, 32, )
8878 FLOAT_CONVS(si
, d
, 64, )
8879 FLOAT_CONVS(ui
, s
, 32, u
)
8880 FLOAT_CONVS(ui
, d
, 64, u
)
8886 /* floating point conversion */
8887 float64
VFP_HELPER(fcvtd
, s
)(float32 x
, CPUARMState
*env
)
8889 float64 r
= float32_to_float64(x
, &env
->vfp
.fp_status
);
8890 /* ARM requires that S<->D conversion of any kind of NaN generates
8891 * a quiet NaN by forcing the most significant frac bit to 1.
8893 return float64_maybe_silence_nan(r
, &env
->vfp
.fp_status
);
8896 float32
VFP_HELPER(fcvts
, d
)(float64 x
, CPUARMState
*env
)
8898 float32 r
= float64_to_float32(x
, &env
->vfp
.fp_status
);
8899 /* ARM requires that S<->D conversion of any kind of NaN generates
8900 * a quiet NaN by forcing the most significant frac bit to 1.
8902 return float32_maybe_silence_nan(r
, &env
->vfp
.fp_status
);
8905 /* VFP3 fixed point conversion. */
8906 #define VFP_CONV_FIX_FLOAT(name, p, fsz, isz, itype) \
8907 float##fsz HELPER(vfp_##name##to##p)(uint##isz##_t x, uint32_t shift, \
8910 float_status *fpst = fpstp; \
8912 tmp = itype##_to_##float##fsz(x, fpst); \
8913 return float##fsz##_scalbn(tmp, -(int)shift, fpst); \
8916 /* Notice that we want only input-denormal exception flags from the
8917 * scalbn operation: the other possible flags (overflow+inexact if
8918 * we overflow to infinity, output-denormal) aren't correct for the
8919 * complete scale-and-convert operation.
8921 #define VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, isz, itype, round) \
8922 uint##isz##_t HELPER(vfp_to##name##p##round)(float##fsz x, \
8926 float_status *fpst = fpstp; \
8927 int old_exc_flags = get_float_exception_flags(fpst); \
8929 if (float##fsz##_is_any_nan(x)) { \
8930 float_raise(float_flag_invalid, fpst); \
8933 tmp = float##fsz##_scalbn(x, shift, fpst); \
8934 old_exc_flags |= get_float_exception_flags(fpst) \
8935 & float_flag_input_denormal; \
8936 set_float_exception_flags(old_exc_flags, fpst); \
8937 return float##fsz##_to_##itype##round(tmp, fpst); \
8940 #define VFP_CONV_FIX(name, p, fsz, isz, itype) \
8941 VFP_CONV_FIX_FLOAT(name, p, fsz, isz, itype) \
8942 VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, isz, itype, _round_to_zero) \
8943 VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, isz, itype, )
8945 #define VFP_CONV_FIX_A64(name, p, fsz, isz, itype) \
8946 VFP_CONV_FIX_FLOAT(name, p, fsz, isz, itype) \
8947 VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, isz, itype, )
8949 VFP_CONV_FIX(sh
, d
, 64, 64, int16
)
8950 VFP_CONV_FIX(sl
, d
, 64, 64, int32
)
8951 VFP_CONV_FIX_A64(sq
, d
, 64, 64, int64
)
8952 VFP_CONV_FIX(uh
, d
, 64, 64, uint16
)
8953 VFP_CONV_FIX(ul
, d
, 64, 64, uint32
)
8954 VFP_CONV_FIX_A64(uq
, d
, 64, 64, uint64
)
8955 VFP_CONV_FIX(sh
, s
, 32, 32, int16
)
8956 VFP_CONV_FIX(sl
, s
, 32, 32, int32
)
8957 VFP_CONV_FIX_A64(sq
, s
, 32, 64, int64
)
8958 VFP_CONV_FIX(uh
, s
, 32, 32, uint16
)
8959 VFP_CONV_FIX(ul
, s
, 32, 32, uint32
)
8960 VFP_CONV_FIX_A64(uq
, s
, 32, 64, uint64
)
8962 #undef VFP_CONV_FIX_FLOAT
8963 #undef VFP_CONV_FLOAT_FIX_ROUND
8965 /* Set the current fp rounding mode and return the old one.
8966 * The argument is a softfloat float_round_ value.
8968 uint32_t HELPER(set_rmode
)(uint32_t rmode
, CPUARMState
*env
)
8970 float_status
*fp_status
= &env
->vfp
.fp_status
;
8972 uint32_t prev_rmode
= get_float_rounding_mode(fp_status
);
8973 set_float_rounding_mode(rmode
, fp_status
);
8978 /* Set the current fp rounding mode in the standard fp status and return
8979 * the old one. This is for NEON instructions that need to change the
8980 * rounding mode but wish to use the standard FPSCR values for everything
8981 * else. Always set the rounding mode back to the correct value after
8983 * The argument is a softfloat float_round_ value.
8985 uint32_t HELPER(set_neon_rmode
)(uint32_t rmode
, CPUARMState
*env
)
8987 float_status
*fp_status
= &env
->vfp
.standard_fp_status
;
8989 uint32_t prev_rmode
= get_float_rounding_mode(fp_status
);
8990 set_float_rounding_mode(rmode
, fp_status
);
8995 /* Half precision conversions. */
8996 static float32
do_fcvt_f16_to_f32(uint32_t a
, CPUARMState
*env
, float_status
*s
)
8998 int ieee
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & (1 << 26)) == 0;
8999 float32 r
= float16_to_float32(make_float16(a
), ieee
, s
);
9001 return float32_maybe_silence_nan(r
, s
);
9006 static uint32_t do_fcvt_f32_to_f16(float32 a
, CPUARMState
*env
, float_status
*s
)
9008 int ieee
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & (1 << 26)) == 0;
9009 float16 r
= float32_to_float16(a
, ieee
, s
);
9011 r
= float16_maybe_silence_nan(r
, s
);
9013 return float16_val(r
);
9016 float32
HELPER(neon_fcvt_f16_to_f32
)(uint32_t a
, CPUARMState
*env
)
9018 return do_fcvt_f16_to_f32(a
, env
, &env
->vfp
.standard_fp_status
);
9021 uint32_t HELPER(neon_fcvt_f32_to_f16
)(float32 a
, CPUARMState
*env
)
9023 return do_fcvt_f32_to_f16(a
, env
, &env
->vfp
.standard_fp_status
);
9026 float32
HELPER(vfp_fcvt_f16_to_f32
)(uint32_t a
, CPUARMState
*env
)
9028 return do_fcvt_f16_to_f32(a
, env
, &env
->vfp
.fp_status
);
9031 uint32_t HELPER(vfp_fcvt_f32_to_f16
)(float32 a
, CPUARMState
*env
)
9033 return do_fcvt_f32_to_f16(a
, env
, &env
->vfp
.fp_status
);
9036 float64
HELPER(vfp_fcvt_f16_to_f64
)(uint32_t a
, CPUARMState
*env
)
9038 int ieee
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & (1 << 26)) == 0;
9039 float64 r
= float16_to_float64(make_float16(a
), ieee
, &env
->vfp
.fp_status
);
9041 return float64_maybe_silence_nan(r
, &env
->vfp
.fp_status
);
9046 uint32_t HELPER(vfp_fcvt_f64_to_f16
)(float64 a
, CPUARMState
*env
)
9048 int ieee
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & (1 << 26)) == 0;
9049 float16 r
= float64_to_float16(a
, ieee
, &env
->vfp
.fp_status
);
9051 r
= float16_maybe_silence_nan(r
, &env
->vfp
.fp_status
);
9053 return float16_val(r
);
9056 #define float32_two make_float32(0x40000000)
9057 #define float32_three make_float32(0x40400000)
9058 #define float32_one_point_five make_float32(0x3fc00000)
9060 float32
HELPER(recps_f32
)(float32 a
, float32 b
, CPUARMState
*env
)
9062 float_status
*s
= &env
->vfp
.standard_fp_status
;
9063 if ((float32_is_infinity(a
) && float32_is_zero_or_denormal(b
)) ||
9064 (float32_is_infinity(b
) && float32_is_zero_or_denormal(a
))) {
9065 if (!(float32_is_zero(a
) || float32_is_zero(b
))) {
9066 float_raise(float_flag_input_denormal
, s
);
9070 return float32_sub(float32_two
, float32_mul(a
, b
, s
), s
);
9073 float32
HELPER(rsqrts_f32
)(float32 a
, float32 b
, CPUARMState
*env
)
9075 float_status
*s
= &env
->vfp
.standard_fp_status
;
9077 if ((float32_is_infinity(a
) && float32_is_zero_or_denormal(b
)) ||
9078 (float32_is_infinity(b
) && float32_is_zero_or_denormal(a
))) {
9079 if (!(float32_is_zero(a
) || float32_is_zero(b
))) {
9080 float_raise(float_flag_input_denormal
, s
);
9082 return float32_one_point_five
;
9084 product
= float32_mul(a
, b
, s
);
9085 return float32_div(float32_sub(float32_three
, product
, s
), float32_two
, s
);
9090 /* Constants 256 and 512 are used in some helpers; we avoid relying on
9091 * int->float conversions at run-time. */
9092 #define float64_256 make_float64(0x4070000000000000LL)
9093 #define float64_512 make_float64(0x4080000000000000LL)
9094 #define float32_maxnorm make_float32(0x7f7fffff)
9095 #define float64_maxnorm make_float64(0x7fefffffffffffffLL)
9097 /* Reciprocal functions
9099 * The algorithm that must be used to calculate the estimate
9100 * is specified by the ARM ARM, see FPRecipEstimate()
9103 static float64
recip_estimate(float64 a
, float_status
*real_fp_status
)
9105 /* These calculations mustn't set any fp exception flags,
9106 * so we use a local copy of the fp_status.
9108 float_status dummy_status
= *real_fp_status
;
9109 float_status
*s
= &dummy_status
;
9110 /* q = (int)(a * 512.0) */
9111 float64 q
= float64_mul(float64_512
, a
, s
);
9112 int64_t q_int
= float64_to_int64_round_to_zero(q
, s
);
9114 /* r = 1.0 / (((double)q + 0.5) / 512.0) */
9115 q
= int64_to_float64(q_int
, s
);
9116 q
= float64_add(q
, float64_half
, s
);
9117 q
= float64_div(q
, float64_512
, s
);
9118 q
= float64_div(float64_one
, q
, s
);
9120 /* s = (int)(256.0 * r + 0.5) */
9121 q
= float64_mul(q
, float64_256
, s
);
9122 q
= float64_add(q
, float64_half
, s
);
9123 q_int
= float64_to_int64_round_to_zero(q
, s
);
9125 /* return (double)s / 256.0 */
9126 return float64_div(int64_to_float64(q_int
, s
), float64_256
, s
);
9129 /* Common wrapper to call recip_estimate */
9130 static float64
call_recip_estimate(float64 num
, int off
, float_status
*fpst
)
9132 uint64_t val64
= float64_val(num
);
9133 uint64_t frac
= extract64(val64
, 0, 52);
9134 int64_t exp
= extract64(val64
, 52, 11);
9136 float64 scaled
, estimate
;
9138 /* Generate the scaled number for the estimate function */
9140 if (extract64(frac
, 51, 1) == 0) {
9142 frac
= extract64(frac
, 0, 50) << 2;
9144 frac
= extract64(frac
, 0, 51) << 1;
9148 /* scaled = '0' : '01111111110' : fraction<51:44> : Zeros(44); */
9149 scaled
= make_float64((0x3feULL
<< 52)
9150 | extract64(frac
, 44, 8) << 44);
9152 estimate
= recip_estimate(scaled
, fpst
);
9154 /* Build new result */
9155 val64
= float64_val(estimate
);
9156 sbit
= 0x8000000000000000ULL
& val64
;
9158 frac
= extract64(val64
, 0, 52);
9161 frac
= 1ULL << 51 | extract64(frac
, 1, 51);
9162 } else if (exp
== -1) {
9163 frac
= 1ULL << 50 | extract64(frac
, 2, 50);
9167 return make_float64(sbit
| (exp
<< 52) | frac
);
9170 static bool round_to_inf(float_status
*fpst
, bool sign_bit
)
9172 switch (fpst
->float_rounding_mode
) {
9173 case float_round_nearest_even
: /* Round to Nearest */
9175 case float_round_up
: /* Round to +Inf */
9177 case float_round_down
: /* Round to -Inf */
9179 case float_round_to_zero
: /* Round to Zero */
9183 g_assert_not_reached();
9186 float32
HELPER(recpe_f32
)(float32 input
, void *fpstp
)
9188 float_status
*fpst
= fpstp
;
9189 float32 f32
= float32_squash_input_denormal(input
, fpst
);
9190 uint32_t f32_val
= float32_val(f32
);
9191 uint32_t f32_sbit
= 0x80000000ULL
& f32_val
;
9192 int32_t f32_exp
= extract32(f32_val
, 23, 8);
9193 uint32_t f32_frac
= extract32(f32_val
, 0, 23);
9199 if (float32_is_any_nan(f32
)) {
9201 if (float32_is_signaling_nan(f32
, fpst
)) {
9202 float_raise(float_flag_invalid
, fpst
);
9203 nan
= float32_maybe_silence_nan(f32
, fpst
);
9205 if (fpst
->default_nan_mode
) {
9206 nan
= float32_default_nan(fpst
);
9209 } else if (float32_is_infinity(f32
)) {
9210 return float32_set_sign(float32_zero
, float32_is_neg(f32
));
9211 } else if (float32_is_zero(f32
)) {
9212 float_raise(float_flag_divbyzero
, fpst
);
9213 return float32_set_sign(float32_infinity
, float32_is_neg(f32
));
9214 } else if ((f32_val
& ~(1ULL << 31)) < (1ULL << 21)) {
9215 /* Abs(value) < 2.0^-128 */
9216 float_raise(float_flag_overflow
| float_flag_inexact
, fpst
);
9217 if (round_to_inf(fpst
, f32_sbit
)) {
9218 return float32_set_sign(float32_infinity
, float32_is_neg(f32
));
9220 return float32_set_sign(float32_maxnorm
, float32_is_neg(f32
));
9222 } else if (f32_exp
>= 253 && fpst
->flush_to_zero
) {
9223 float_raise(float_flag_underflow
, fpst
);
9224 return float32_set_sign(float32_zero
, float32_is_neg(f32
));
9228 f64
= make_float64(((int64_t)(f32_exp
) << 52) | (int64_t)(f32_frac
) << 29);
9229 r64
= call_recip_estimate(f64
, 253, fpst
);
9230 r64_val
= float64_val(r64
);
9231 r64_exp
= extract64(r64_val
, 52, 11);
9232 r64_frac
= extract64(r64_val
, 0, 52);
9234 /* result = sign : result_exp<7:0> : fraction<51:29>; */
9235 return make_float32(f32_sbit
|
9236 (r64_exp
& 0xff) << 23 |
9237 extract64(r64_frac
, 29, 24));
9240 float64
HELPER(recpe_f64
)(float64 input
, void *fpstp
)
9242 float_status
*fpst
= fpstp
;
9243 float64 f64
= float64_squash_input_denormal(input
, fpst
);
9244 uint64_t f64_val
= float64_val(f64
);
9245 uint64_t f64_sbit
= 0x8000000000000000ULL
& f64_val
;
9246 int64_t f64_exp
= extract64(f64_val
, 52, 11);
9252 /* Deal with any special cases */
9253 if (float64_is_any_nan(f64
)) {
9255 if (float64_is_signaling_nan(f64
, fpst
)) {
9256 float_raise(float_flag_invalid
, fpst
);
9257 nan
= float64_maybe_silence_nan(f64
, fpst
);
9259 if (fpst
->default_nan_mode
) {
9260 nan
= float64_default_nan(fpst
);
9263 } else if (float64_is_infinity(f64
)) {
9264 return float64_set_sign(float64_zero
, float64_is_neg(f64
));
9265 } else if (float64_is_zero(f64
)) {
9266 float_raise(float_flag_divbyzero
, fpst
);
9267 return float64_set_sign(float64_infinity
, float64_is_neg(f64
));
9268 } else if ((f64_val
& ~(1ULL << 63)) < (1ULL << 50)) {
9269 /* Abs(value) < 2.0^-1024 */
9270 float_raise(float_flag_overflow
| float_flag_inexact
, fpst
);
9271 if (round_to_inf(fpst
, f64_sbit
)) {
9272 return float64_set_sign(float64_infinity
, float64_is_neg(f64
));
9274 return float64_set_sign(float64_maxnorm
, float64_is_neg(f64
));
9276 } else if (f64_exp
>= 2045 && fpst
->flush_to_zero
) {
9277 float_raise(float_flag_underflow
, fpst
);
9278 return float64_set_sign(float64_zero
, float64_is_neg(f64
));
9281 r64
= call_recip_estimate(f64
, 2045, fpst
);
9282 r64_val
= float64_val(r64
);
9283 r64_exp
= extract64(r64_val
, 52, 11);
9284 r64_frac
= extract64(r64_val
, 0, 52);
9286 /* result = sign : result_exp<10:0> : fraction<51:0> */
9287 return make_float64(f64_sbit
|
9288 ((r64_exp
& 0x7ff) << 52) |
9292 /* The algorithm that must be used to calculate the estimate
9293 * is specified by the ARM ARM.
9295 static float64
recip_sqrt_estimate(float64 a
, float_status
*real_fp_status
)
9297 /* These calculations mustn't set any fp exception flags,
9298 * so we use a local copy of the fp_status.
9300 float_status dummy_status
= *real_fp_status
;
9301 float_status
*s
= &dummy_status
;
9305 if (float64_lt(a
, float64_half
, s
)) {
9306 /* range 0.25 <= a < 0.5 */
9308 /* a in units of 1/512 rounded down */
9309 /* q0 = (int)(a * 512.0); */
9310 q
= float64_mul(float64_512
, a
, s
);
9311 q_int
= float64_to_int64_round_to_zero(q
, s
);
9313 /* reciprocal root r */
9314 /* r = 1.0 / sqrt(((double)q0 + 0.5) / 512.0); */
9315 q
= int64_to_float64(q_int
, s
);
9316 q
= float64_add(q
, float64_half
, s
);
9317 q
= float64_div(q
, float64_512
, s
);
9318 q
= float64_sqrt(q
, s
);
9319 q
= float64_div(float64_one
, q
, s
);
9321 /* range 0.5 <= a < 1.0 */
9323 /* a in units of 1/256 rounded down */
9324 /* q1 = (int)(a * 256.0); */
9325 q
= float64_mul(float64_256
, a
, s
);
9326 int64_t q_int
= float64_to_int64_round_to_zero(q
, s
);
9328 /* reciprocal root r */
9329 /* r = 1.0 /sqrt(((double)q1 + 0.5) / 256); */
9330 q
= int64_to_float64(q_int
, s
);
9331 q
= float64_add(q
, float64_half
, s
);
9332 q
= float64_div(q
, float64_256
, s
);
9333 q
= float64_sqrt(q
, s
);
9334 q
= float64_div(float64_one
, q
, s
);
9336 /* r in units of 1/256 rounded to nearest */
9337 /* s = (int)(256.0 * r + 0.5); */
9339 q
= float64_mul(q
, float64_256
,s
);
9340 q
= float64_add(q
, float64_half
, s
);
9341 q_int
= float64_to_int64_round_to_zero(q
, s
);
9343 /* return (double)s / 256.0;*/
9344 return float64_div(int64_to_float64(q_int
, s
), float64_256
, s
);
9347 float32
HELPER(rsqrte_f32
)(float32 input
, void *fpstp
)
9349 float_status
*s
= fpstp
;
9350 float32 f32
= float32_squash_input_denormal(input
, s
);
9351 uint32_t val
= float32_val(f32
);
9352 uint32_t f32_sbit
= 0x80000000 & val
;
9353 int32_t f32_exp
= extract32(val
, 23, 8);
9354 uint32_t f32_frac
= extract32(val
, 0, 23);
9360 if (float32_is_any_nan(f32
)) {
9362 if (float32_is_signaling_nan(f32
, s
)) {
9363 float_raise(float_flag_invalid
, s
);
9364 nan
= float32_maybe_silence_nan(f32
, s
);
9366 if (s
->default_nan_mode
) {
9367 nan
= float32_default_nan(s
);
9370 } else if (float32_is_zero(f32
)) {
9371 float_raise(float_flag_divbyzero
, s
);
9372 return float32_set_sign(float32_infinity
, float32_is_neg(f32
));
9373 } else if (float32_is_neg(f32
)) {
9374 float_raise(float_flag_invalid
, s
);
9375 return float32_default_nan(s
);
9376 } else if (float32_is_infinity(f32
)) {
9377 return float32_zero
;
9380 /* Scale and normalize to a double-precision value between 0.25 and 1.0,
9381 * preserving the parity of the exponent. */
9383 f64_frac
= ((uint64_t) f32_frac
) << 29;
9385 while (extract64(f64_frac
, 51, 1) == 0) {
9386 f64_frac
= f64_frac
<< 1;
9387 f32_exp
= f32_exp
-1;
9389 f64_frac
= extract64(f64_frac
, 0, 51) << 1;
9392 if (extract64(f32_exp
, 0, 1) == 0) {
9393 f64
= make_float64(((uint64_t) f32_sbit
) << 32
9397 f64
= make_float64(((uint64_t) f32_sbit
) << 32
9402 result_exp
= (380 - f32_exp
) / 2;
9404 f64
= recip_sqrt_estimate(f64
, s
);
9406 val64
= float64_val(f64
);
9408 val
= ((result_exp
& 0xff) << 23)
9409 | ((val64
>> 29) & 0x7fffff);
9410 return make_float32(val
);
9413 float64
HELPER(rsqrte_f64
)(float64 input
, void *fpstp
)
9415 float_status
*s
= fpstp
;
9416 float64 f64
= float64_squash_input_denormal(input
, s
);
9417 uint64_t val
= float64_val(f64
);
9418 uint64_t f64_sbit
= 0x8000000000000000ULL
& val
;
9419 int64_t f64_exp
= extract64(val
, 52, 11);
9420 uint64_t f64_frac
= extract64(val
, 0, 52);
9422 uint64_t result_frac
;
9424 if (float64_is_any_nan(f64
)) {
9426 if (float64_is_signaling_nan(f64
, s
)) {
9427 float_raise(float_flag_invalid
, s
);
9428 nan
= float64_maybe_silence_nan(f64
, s
);
9430 if (s
->default_nan_mode
) {
9431 nan
= float64_default_nan(s
);
9434 } else if (float64_is_zero(f64
)) {
9435 float_raise(float_flag_divbyzero
, s
);
9436 return float64_set_sign(float64_infinity
, float64_is_neg(f64
));
9437 } else if (float64_is_neg(f64
)) {
9438 float_raise(float_flag_invalid
, s
);
9439 return float64_default_nan(s
);
9440 } else if (float64_is_infinity(f64
)) {
9441 return float64_zero
;
9444 /* Scale and normalize to a double-precision value between 0.25 and 1.0,
9445 * preserving the parity of the exponent. */
9448 while (extract64(f64_frac
, 51, 1) == 0) {
9449 f64_frac
= f64_frac
<< 1;
9450 f64_exp
= f64_exp
- 1;
9452 f64_frac
= extract64(f64_frac
, 0, 51) << 1;
9455 if (extract64(f64_exp
, 0, 1) == 0) {
9456 f64
= make_float64(f64_sbit
9460 f64
= make_float64(f64_sbit
9465 result_exp
= (3068 - f64_exp
) / 2;
9467 f64
= recip_sqrt_estimate(f64
, s
);
9469 result_frac
= extract64(float64_val(f64
), 0, 52);
9471 return make_float64(f64_sbit
|
9472 ((result_exp
& 0x7ff) << 52) |
9476 uint32_t HELPER(recpe_u32
)(uint32_t a
, void *fpstp
)
9478 float_status
*s
= fpstp
;
9481 if ((a
& 0x80000000) == 0) {
9485 f64
= make_float64((0x3feULL
<< 52)
9486 | ((int64_t)(a
& 0x7fffffff) << 21));
9488 f64
= recip_estimate(f64
, s
);
9490 return 0x80000000 | ((float64_val(f64
) >> 21) & 0x7fffffff);
9493 uint32_t HELPER(rsqrte_u32
)(uint32_t a
, void *fpstp
)
9495 float_status
*fpst
= fpstp
;
9498 if ((a
& 0xc0000000) == 0) {
9502 if (a
& 0x80000000) {
9503 f64
= make_float64((0x3feULL
<< 52)
9504 | ((uint64_t)(a
& 0x7fffffff) << 21));
9505 } else { /* bits 31-30 == '01' */
9506 f64
= make_float64((0x3fdULL
<< 52)
9507 | ((uint64_t)(a
& 0x3fffffff) << 22));
9510 f64
= recip_sqrt_estimate(f64
, fpst
);
9512 return 0x80000000 | ((float64_val(f64
) >> 21) & 0x7fffffff);
9515 /* VFPv4 fused multiply-accumulate */
9516 float32
VFP_HELPER(muladd
, s
)(float32 a
, float32 b
, float32 c
, void *fpstp
)
9518 float_status
*fpst
= fpstp
;
9519 return float32_muladd(a
, b
, c
, 0, fpst
);
9522 float64
VFP_HELPER(muladd
, d
)(float64 a
, float64 b
, float64 c
, void *fpstp
)
9524 float_status
*fpst
= fpstp
;
9525 return float64_muladd(a
, b
, c
, 0, fpst
);
9528 /* ARMv8 round to integral */
9529 float32
HELPER(rints_exact
)(float32 x
, void *fp_status
)
9531 return float32_round_to_int(x
, fp_status
);
9534 float64
HELPER(rintd_exact
)(float64 x
, void *fp_status
)
9536 return float64_round_to_int(x
, fp_status
);
9539 float32
HELPER(rints
)(float32 x
, void *fp_status
)
9541 int old_flags
= get_float_exception_flags(fp_status
), new_flags
;
9544 ret
= float32_round_to_int(x
, fp_status
);
9546 /* Suppress any inexact exceptions the conversion produced */
9547 if (!(old_flags
& float_flag_inexact
)) {
9548 new_flags
= get_float_exception_flags(fp_status
);
9549 set_float_exception_flags(new_flags
& ~float_flag_inexact
, fp_status
);
9555 float64
HELPER(rintd
)(float64 x
, void *fp_status
)
9557 int old_flags
= get_float_exception_flags(fp_status
), new_flags
;
9560 ret
= float64_round_to_int(x
, fp_status
);
9562 new_flags
= get_float_exception_flags(fp_status
);
9564 /* Suppress any inexact exceptions the conversion produced */
9565 if (!(old_flags
& float_flag_inexact
)) {
9566 new_flags
= get_float_exception_flags(fp_status
);
9567 set_float_exception_flags(new_flags
& ~float_flag_inexact
, fp_status
);
9573 /* Convert ARM rounding mode to softfloat */
9574 int arm_rmode_to_sf(int rmode
)
9577 case FPROUNDING_TIEAWAY
:
9578 rmode
= float_round_ties_away
;
9580 case FPROUNDING_ODD
:
9581 /* FIXME: add support for TIEAWAY and ODD */
9582 qemu_log_mask(LOG_UNIMP
, "arm: unimplemented rounding mode: %d\n",
9584 case FPROUNDING_TIEEVEN
:
9586 rmode
= float_round_nearest_even
;
9588 case FPROUNDING_POSINF
:
9589 rmode
= float_round_up
;
9591 case FPROUNDING_NEGINF
:
9592 rmode
= float_round_down
;
9594 case FPROUNDING_ZERO
:
9595 rmode
= float_round_to_zero
;
9602 * The upper bytes of val (above the number specified by 'bytes') must have
9603 * been zeroed out by the caller.
9605 uint32_t HELPER(crc32
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
9611 /* zlib crc32 converts the accumulator and output to one's complement. */
9612 return crc32(acc
^ 0xffffffff, buf
, bytes
) ^ 0xffffffff;
9615 uint32_t HELPER(crc32c
)(uint32_t acc
, uint32_t val
, uint32_t bytes
)
9621 /* Linux crc32c converts the output to one's complement. */
9622 return crc32c(acc
, buf
, bytes
) ^ 0xffffffff;