4 * Copyright (c) 2012 SUSE LINUX Products GmbH
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see
18 * <http://www.gnu.org/licenses/gpl-2.0.html>
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
24 #include "internals.h"
25 #include "qemu-common.h"
26 #include "exec/exec-all.h"
27 #include "hw/qdev-properties.h"
28 #if !defined(CONFIG_USER_ONLY)
29 #include "hw/loader.h"
31 #include "hw/arm/arm.h"
32 #include "sysemu/sysemu.h"
33 #include "sysemu/kvm.h"
36 static void arm_cpu_set_pc(CPUState *cs, vaddr value)
38 ARMCPU *cpu = ARM_CPU(cs);
40 cpu->env.regs[15] = value;
43 static bool arm_cpu_has_work(CPUState *cs)
45 ARMCPU *cpu = ARM_CPU(cs);
47 return !cpu->powered_off
48 && cs->interrupt_request &
49 (CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD
50 | CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ
51 | CPU_INTERRUPT_EXITTB);
54 void arm_register_el_change_hook(ARMCPU *cpu, ARMELChangeHook *hook,
57 /* We currently only support registering a single hook function */
58 assert(!cpu->el_change_hook);
59 cpu->el_change_hook = hook;
60 cpu->el_change_hook_opaque = opaque;
63 static void cp_reg_reset(gpointer key, gpointer value, gpointer opaque)
65 /* Reset a single ARMCPRegInfo register */
66 ARMCPRegInfo *ri = value;
69 if (ri->type & (ARM_CP_SPECIAL | ARM_CP_ALIAS)) {
74 ri->resetfn(&cpu->env, ri);
78 /* A zero offset is never possible as it would be regs[0]
79 * so we use it to indicate that reset is being handled elsewhere.
80 * This is basically only used for fields in non-core coprocessors
81 * (like the pxa2xx ones).
83 if (!ri->fieldoffset) {
87 if (cpreg_field_is_64bit(ri)) {
88 CPREG_FIELD64(&cpu->env, ri) = ri->resetvalue;
90 CPREG_FIELD32(&cpu->env, ri) = ri->resetvalue;
94 static void cp_reg_check_reset(gpointer key, gpointer value, gpointer opaque)
96 /* Purely an assertion check: we've already done reset once,
97 * so now check that running the reset for the cpreg doesn't
98 * change its value. This traps bugs where two different cpregs
99 * both try to reset the same state field but to different values.
101 ARMCPRegInfo *ri = value;
102 ARMCPU *cpu = opaque;
103 uint64_t oldvalue, newvalue;
105 if (ri->type & (ARM_CP_SPECIAL | ARM_CP_ALIAS | ARM_CP_NO_RAW)) {
109 oldvalue = read_raw_cp_reg(&cpu->env, ri);
110 cp_reg_reset(key, value, opaque);
111 newvalue = read_raw_cp_reg(&cpu->env, ri);
112 assert(oldvalue == newvalue);
115 /* CPUClass::reset() */
116 static void arm_cpu_reset(CPUState *s)
118 ARMCPU *cpu = ARM_CPU(s);
119 ARMCPUClass *acc = ARM_CPU_GET_CLASS(cpu);
120 CPUARMState *env = &cpu->env;
122 acc->parent_reset(s);
124 memset(env, 0, offsetof(CPUARMState, features));
125 g_hash_table_foreach(cpu->cp_regs, cp_reg_reset, cpu);
126 g_hash_table_foreach(cpu->cp_regs, cp_reg_check_reset, cpu);
128 env->vfp.xregs[ARM_VFP_FPSID] = cpu->reset_fpsid;
129 env->vfp.xregs[ARM_VFP_MVFR0] = cpu->mvfr0;
130 env->vfp.xregs[ARM_VFP_MVFR1] = cpu->mvfr1;
131 env->vfp.xregs[ARM_VFP_MVFR2] = cpu->mvfr2;
133 cpu->powered_off = cpu->start_powered_off;
134 s->halted = cpu->start_powered_off;
136 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
137 env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
140 if (arm_feature(env, ARM_FEATURE_AARCH64)) {
141 /* 64 bit CPUs always start in 64 bit mode */
143 #if defined(CONFIG_USER_ONLY)
144 env->pstate = PSTATE_MODE_EL0t;
145 /* Userspace expects access to DC ZVA, CTL_EL0 and the cache ops */
146 env->cp15.sctlr_el[1] |= SCTLR_UCT | SCTLR_UCI | SCTLR_DZE;
147 /* and to the FP/Neon instructions */
148 env->cp15.cpacr_el1 = deposit64(env->cp15.cpacr_el1, 20, 2, 3);
150 /* Reset into the highest available EL */
151 if (arm_feature(env, ARM_FEATURE_EL3)) {
152 env->pstate = PSTATE_MODE_EL3h;
153 } else if (arm_feature(env, ARM_FEATURE_EL2)) {
154 env->pstate = PSTATE_MODE_EL2h;
156 env->pstate = PSTATE_MODE_EL1h;
158 env->pc = cpu->rvbar;
161 #if defined(CONFIG_USER_ONLY)
162 /* Userspace expects access to cp10 and cp11 for FP/Neon */
163 env->cp15.cpacr_el1 = deposit64(env->cp15.cpacr_el1, 20, 4, 0xf);
167 #if defined(CONFIG_USER_ONLY)
168 env->uncached_cpsr = ARM_CPU_MODE_USR;
169 /* For user mode we must enable access to coprocessors */
170 env->vfp.xregs[ARM_VFP_FPEXC] = 1 << 30;
171 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
172 env->cp15.c15_cpar = 3;
173 } else if (arm_feature(env, ARM_FEATURE_XSCALE)) {
174 env->cp15.c15_cpar = 1;
177 /* SVC mode with interrupts disabled. */
178 env->uncached_cpsr = ARM_CPU_MODE_SVC;
179 env->daif = PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F;
180 /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
181 * clear at reset. Initial SP and PC are loaded from ROM.
184 uint32_t initial_msp; /* Loaded from 0x0 */
185 uint32_t initial_pc; /* Loaded from 0x4 */
188 env->daif &= ~PSTATE_I;
191 /* Address zero is covered by ROM which hasn't yet been
192 * copied into physical memory.
194 initial_msp = ldl_p(rom);
195 initial_pc = ldl_p(rom + 4);
197 /* Address zero not covered by a ROM blob, or the ROM blob
198 * is in non-modifiable memory and this is a second reset after
199 * it got copied into memory. In the latter case, rom_ptr
200 * will return a NULL pointer and we should use ldl_phys instead.
202 initial_msp = ldl_phys(s->as, 0);
203 initial_pc = ldl_phys(s->as, 4);
206 env->regs[13] = initial_msp & 0xFFFFFFFC;
207 env->regs[15] = initial_pc & ~1;
208 env->thumb = initial_pc & 1;
211 /* AArch32 has a hard highvec setting of 0xFFFF0000. If we are currently
212 * executing as AArch32 then check if highvecs are enabled and
213 * adjust the PC accordingly.
215 if (A32_BANKED_CURRENT_REG_GET(env, sctlr) & SCTLR_V) {
216 env->regs[15] = 0xFFFF0000;
219 env->vfp.xregs[ARM_VFP_FPEXC] = 0;
221 set_flush_to_zero(1, &env->vfp.standard_fp_status);
222 set_flush_inputs_to_zero(1, &env->vfp.standard_fp_status);
223 set_default_nan_mode(1, &env->vfp.standard_fp_status);
224 set_float_detect_tininess(float_tininess_before_rounding,
225 &env->vfp.fp_status);
226 set_float_detect_tininess(float_tininess_before_rounding,
227 &env->vfp.standard_fp_status);
230 #ifndef CONFIG_USER_ONLY
232 kvm_arm_reset_vcpu(cpu);
236 hw_breakpoint_update_all(cpu);
237 hw_watchpoint_update_all(cpu);
240 bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
242 CPUClass *cc = CPU_GET_CLASS(cs);
243 CPUARMState *env = cs->env_ptr;
244 uint32_t cur_el = arm_current_el(env);
245 bool secure = arm_is_secure(env);
250 if (interrupt_request & CPU_INTERRUPT_FIQ) {
252 target_el = arm_phys_excp_target_el(cs, excp_idx, cur_el, secure);
253 if (arm_excp_unmasked(cs, excp_idx, target_el)) {
254 cs->exception_index = excp_idx;
255 env->exception.target_el = target_el;
256 cc->do_interrupt(cs);
260 if (interrupt_request & CPU_INTERRUPT_HARD) {
262 target_el = arm_phys_excp_target_el(cs, excp_idx, cur_el, secure);
263 if (arm_excp_unmasked(cs, excp_idx, target_el)) {
264 cs->exception_index = excp_idx;
265 env->exception.target_el = target_el;
266 cc->do_interrupt(cs);
270 if (interrupt_request & CPU_INTERRUPT_VIRQ) {
271 excp_idx = EXCP_VIRQ;
273 if (arm_excp_unmasked(cs, excp_idx, target_el)) {
274 cs->exception_index = excp_idx;
275 env->exception.target_el = target_el;
276 cc->do_interrupt(cs);
280 if (interrupt_request & CPU_INTERRUPT_VFIQ) {
281 excp_idx = EXCP_VFIQ;
283 if (arm_excp_unmasked(cs, excp_idx, target_el)) {
284 cs->exception_index = excp_idx;
285 env->exception.target_el = target_el;
286 cc->do_interrupt(cs);
294 #if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64)
295 static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
297 CPUClass *cc = CPU_GET_CLASS(cs);
298 ARMCPU *cpu = ARM_CPU(cs);
299 CPUARMState *env = &cpu->env;
303 if (interrupt_request & CPU_INTERRUPT_FIQ
304 && !(env->daif & PSTATE_F)) {
305 cs->exception_index = EXCP_FIQ;
306 cc->do_interrupt(cs);
309 /* ARMv7-M interrupt return works by loading a magic value
310 * into the PC. On real hardware the load causes the
311 * return to occur. The qemu implementation performs the
312 * jump normally, then does the exception return when the
313 * CPU tries to execute code at the magic address.
314 * This will cause the magic PC value to be pushed to
315 * the stack if an interrupt occurred at the wrong time.
316 * We avoid this by disabling interrupts when
317 * pc contains a magic address.
319 if (interrupt_request & CPU_INTERRUPT_HARD
320 && !(env->daif & PSTATE_I)
321 && (env->regs[15] < 0xfffffff0)) {
322 cs->exception_index = EXCP_IRQ;
323 cc->do_interrupt(cs);
330 #ifndef CONFIG_USER_ONLY
331 static void arm_cpu_set_irq(void *opaque, int irq, int level)
333 ARMCPU *cpu = opaque;
334 CPUARMState *env = &cpu->env;
335 CPUState *cs = CPU(cpu);
336 static const int mask[] = {
337 [ARM_CPU_IRQ] = CPU_INTERRUPT_HARD,
338 [ARM_CPU_FIQ] = CPU_INTERRUPT_FIQ,
339 [ARM_CPU_VIRQ] = CPU_INTERRUPT_VIRQ,
340 [ARM_CPU_VFIQ] = CPU_INTERRUPT_VFIQ
346 assert(arm_feature(env, ARM_FEATURE_EL2));
351 cpu_interrupt(cs, mask[irq]);
353 cpu_reset_interrupt(cs, mask[irq]);
357 g_assert_not_reached();
361 static void arm_cpu_kvm_set_irq(void *opaque, int irq, int level)
364 ARMCPU *cpu = opaque;
365 CPUState *cs = CPU(cpu);
366 int kvm_irq = KVM_ARM_IRQ_TYPE_CPU << KVM_ARM_IRQ_TYPE_SHIFT;
370 kvm_irq |= KVM_ARM_IRQ_CPU_IRQ;
373 kvm_irq |= KVM_ARM_IRQ_CPU_FIQ;
376 g_assert_not_reached();
378 kvm_irq |= cs->cpu_index << KVM_ARM_IRQ_VCPU_SHIFT;
379 kvm_set_irq(kvm_state, kvm_irq, level ? 1 : 0);
383 static bool arm_cpu_virtio_is_big_endian(CPUState *cs)
385 ARMCPU *cpu = ARM_CPU(cs);
386 CPUARMState *env = &cpu->env;
388 cpu_synchronize_state(cs);
389 return arm_cpu_data_is_big_endian(env);
394 static inline void set_feature(CPUARMState *env, int feature)
396 env->features |= 1ULL << feature;
399 static inline void unset_feature(CPUARMState *env, int feature)
401 env->features &= ~(1ULL << feature);
405 print_insn_thumb1(bfd_vma pc, disassemble_info *info)
407 return print_insn_arm(pc | 1, info);
410 static void arm_disas_set_info(CPUState *cpu, disassemble_info *info)
412 ARMCPU *ac = ARM_CPU(cpu);
413 CPUARMState *env = &ac->env;
416 /* We might not be compiled with the A64 disassembler
417 * because it needs a C++ compiler. Leave print_insn
418 * unset in this case to use the caller default behaviour.
420 #if defined(CONFIG_ARM_A64_DIS)
421 info->print_insn = print_insn_arm_a64;
423 } else if (env->thumb) {
424 info->print_insn = print_insn_thumb1;
426 info->print_insn = print_insn_arm;
428 if (bswap_code(arm_sctlr_b(env))) {
429 #ifdef TARGET_WORDS_BIGENDIAN
430 info->endian = BFD_ENDIAN_LITTLE;
432 info->endian = BFD_ENDIAN_BIG;
437 #define ARM_CPUS_PER_CLUSTER 8
439 static void arm_cpu_initfn(Object *obj)
441 CPUState *cs = CPU(obj);
442 ARMCPU *cpu = ARM_CPU(obj);
446 cs->env_ptr = &cpu->env;
447 cpu_exec_init(cs, &error_abort);
448 cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal,
451 /* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it.
452 * We don't support setting cluster ID ([16..23]) (known as Aff2
453 * in later ARM ARM versions), or any of the higher affinity level fields,
454 * so these bits always RAZ.
456 Aff1 = cs->cpu_index / ARM_CPUS_PER_CLUSTER;
457 Aff0 = cs->cpu_index % ARM_CPUS_PER_CLUSTER;
458 cpu->mp_affinity = (Aff1 << ARM_AFF1_SHIFT) | Aff0;
460 #ifndef CONFIG_USER_ONLY
461 /* Our inbound IRQ and FIQ lines */
463 /* VIRQ and VFIQ are unused with KVM but we add them to maintain
464 * the same interface as non-KVM CPUs.
466 qdev_init_gpio_in(DEVICE(cpu), arm_cpu_kvm_set_irq, 4);
468 qdev_init_gpio_in(DEVICE(cpu), arm_cpu_set_irq, 4);
471 cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
472 arm_gt_ptimer_cb, cpu);
473 cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
474 arm_gt_vtimer_cb, cpu);
475 cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
476 arm_gt_htimer_cb, cpu);
477 cpu->gt_timer[GTIMER_SEC] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
478 arm_gt_stimer_cb, cpu);
479 qdev_init_gpio_out(DEVICE(cpu), cpu->gt_timer_outputs,
480 ARRAY_SIZE(cpu->gt_timer_outputs));
483 /* DTB consumers generally don't in fact care what the 'compatible'
484 * string is, so always provide some string and trust that a hypothetical
485 * picky DTB consumer will also provide a helpful error message.
487 cpu->dtb_compatible = "qemu,unknown";
488 cpu->psci_version = 1; /* By default assume PSCI v0.1 */
489 cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
492 cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
495 arm_translate_init();
500 static Property arm_cpu_reset_cbar_property =
501 DEFINE_PROP_UINT64("reset-cbar", ARMCPU, reset_cbar, 0);
503 static Property arm_cpu_reset_hivecs_property =
504 DEFINE_PROP_BOOL("reset-hivecs", ARMCPU, reset_hivecs, false);
506 static Property arm_cpu_rvbar_property =
507 DEFINE_PROP_UINT64("rvbar", ARMCPU, rvbar, 0);
509 static Property arm_cpu_has_el3_property =
510 DEFINE_PROP_BOOL("has_el3", ARMCPU, has_el3, true);
512 static Property arm_cpu_has_mpu_property =
513 DEFINE_PROP_BOOL("has-mpu", ARMCPU, has_mpu, true);
515 static Property arm_cpu_pmsav7_dregion_property =
516 DEFINE_PROP_UINT32("pmsav7-dregion", ARMCPU, pmsav7_dregion, 16);
518 static void arm_cpu_post_init(Object *obj)
520 ARMCPU *cpu = ARM_CPU(obj);
522 if (arm_feature(&cpu->env, ARM_FEATURE_CBAR) ||
523 arm_feature(&cpu->env, ARM_FEATURE_CBAR_RO)) {
524 qdev_property_add_static(DEVICE(obj), &arm_cpu_reset_cbar_property,
528 if (!arm_feature(&cpu->env, ARM_FEATURE_M)) {
529 qdev_property_add_static(DEVICE(obj), &arm_cpu_reset_hivecs_property,
533 if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
534 qdev_property_add_static(DEVICE(obj), &arm_cpu_rvbar_property,
538 if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) {
539 /* Add the has_el3 state CPU property only if EL3 is allowed. This will
540 * prevent "has_el3" from existing on CPUs which cannot support EL3.
542 qdev_property_add_static(DEVICE(obj), &arm_cpu_has_el3_property,
545 #ifndef CONFIG_USER_ONLY
546 object_property_add_link(obj, "secure-memory",
548 (Object **)&cpu->secure_memory,
549 qdev_prop_allow_set_link_before_realize,
550 OBJ_PROP_LINK_UNREF_ON_RELEASE,
555 if (arm_feature(&cpu->env, ARM_FEATURE_MPU)) {
556 qdev_property_add_static(DEVICE(obj), &arm_cpu_has_mpu_property,
558 if (arm_feature(&cpu->env, ARM_FEATURE_V7)) {
559 qdev_property_add_static(DEVICE(obj),
560 &arm_cpu_pmsav7_dregion_property,
567 static void arm_cpu_finalizefn(Object *obj)
569 ARMCPU *cpu = ARM_CPU(obj);
570 g_hash_table_destroy(cpu->cp_regs);
573 static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
575 CPUState *cs = CPU(dev);
576 ARMCPU *cpu = ARM_CPU(dev);
577 ARMCPUClass *acc = ARM_CPU_GET_CLASS(dev);
578 CPUARMState *env = &cpu->env;
581 /* Some features automatically imply others: */
582 if (arm_feature(env, ARM_FEATURE_V8)) {
583 set_feature(env, ARM_FEATURE_V7);
584 set_feature(env, ARM_FEATURE_ARM_DIV);
585 set_feature(env, ARM_FEATURE_LPAE);
587 if (arm_feature(env, ARM_FEATURE_V7)) {
588 set_feature(env, ARM_FEATURE_VAPA);
589 set_feature(env, ARM_FEATURE_THUMB2);
590 set_feature(env, ARM_FEATURE_MPIDR);
591 if (!arm_feature(env, ARM_FEATURE_M)) {
592 set_feature(env, ARM_FEATURE_V6K);
594 set_feature(env, ARM_FEATURE_V6);
597 if (arm_feature(env, ARM_FEATURE_V6K)) {
598 set_feature(env, ARM_FEATURE_V6);
599 set_feature(env, ARM_FEATURE_MVFR);
601 if (arm_feature(env, ARM_FEATURE_V6)) {
602 set_feature(env, ARM_FEATURE_V5);
603 if (!arm_feature(env, ARM_FEATURE_M)) {
604 set_feature(env, ARM_FEATURE_AUXCR);
607 if (arm_feature(env, ARM_FEATURE_V5)) {
608 set_feature(env, ARM_FEATURE_V4T);
610 if (arm_feature(env, ARM_FEATURE_M)) {
611 set_feature(env, ARM_FEATURE_THUMB_DIV);
613 if (arm_feature(env, ARM_FEATURE_ARM_DIV)) {
614 set_feature(env, ARM_FEATURE_THUMB_DIV);
616 if (arm_feature(env, ARM_FEATURE_VFP4)) {
617 set_feature(env, ARM_FEATURE_VFP3);
618 set_feature(env, ARM_FEATURE_VFP_FP16);
620 if (arm_feature(env, ARM_FEATURE_VFP3)) {
621 set_feature(env, ARM_FEATURE_VFP);
623 if (arm_feature(env, ARM_FEATURE_LPAE)) {
624 set_feature(env, ARM_FEATURE_V7MP);
625 set_feature(env, ARM_FEATURE_PXN);
627 if (arm_feature(env, ARM_FEATURE_CBAR_RO)) {
628 set_feature(env, ARM_FEATURE_CBAR);
630 if (arm_feature(env, ARM_FEATURE_THUMB2) &&
631 !arm_feature(env, ARM_FEATURE_M)) {
632 set_feature(env, ARM_FEATURE_THUMB_DSP);
635 if (arm_feature(env, ARM_FEATURE_V7) &&
636 !arm_feature(env, ARM_FEATURE_M) &&
637 !arm_feature(env, ARM_FEATURE_MPU)) {
638 /* v7VMSA drops support for the old ARMv5 tiny pages, so we
643 /* For CPUs which might have tiny 1K pages, or which have an
644 * MPU and might have small region sizes, stick with 1K pages.
648 if (!set_preferred_target_page_bits(pagebits)) {
649 /* This can only ever happen for hotplugging a CPU, or if
650 * the board code incorrectly creates a CPU which it has
651 * promised via minimum_page_size that it will not.
653 error_setg(errp, "This CPU requires a smaller page size than the "
658 if (cpu->reset_hivecs) {
659 cpu->reset_sctlr |= (1 << 13);
663 /* If the has_el3 CPU property is disabled then we need to disable the
666 unset_feature(env, ARM_FEATURE_EL3);
668 /* Disable the security extension feature bits in the processor feature
669 * registers as well. These are id_pfr1[7:4] and id_aa64pfr0[15:12].
671 cpu->id_pfr1 &= ~0xf0;
672 cpu->id_aa64pfr0 &= ~0xf000;
675 if (!arm_feature(env, ARM_FEATURE_EL2)) {
676 /* Disable the hypervisor feature bits in the processor feature
677 * registers if we don't have EL2. These are id_pfr1[15:12] and
678 * id_aa64pfr0_el1[11:8].
680 cpu->id_aa64pfr0 &= ~0xf00;
681 cpu->id_pfr1 &= ~0xf000;
685 unset_feature(env, ARM_FEATURE_MPU);
688 if (arm_feature(env, ARM_FEATURE_MPU) &&
689 arm_feature(env, ARM_FEATURE_V7)) {
690 uint32_t nr = cpu->pmsav7_dregion;
693 error_setg(errp, "PMSAv7 MPU #regions invalid %" PRIu32, nr);
698 env->pmsav7.drbar = g_new0(uint32_t, nr);
699 env->pmsav7.drsr = g_new0(uint32_t, nr);
700 env->pmsav7.dracr = g_new0(uint32_t, nr);
704 register_cp_regs_for_features(cpu);
705 arm_cpu_register_gdb_regs_for_features(cpu);
707 init_cpreg_list(cpu);
709 #ifndef CONFIG_USER_ONLY
719 if (!cpu->secure_memory) {
720 cpu->secure_memory = cs->memory;
722 as = address_space_init_shareable(cpu->secure_memory,
723 "cpu-secure-memory");
724 cpu_address_space_init(cs, as, ARMASIdx_S);
726 cpu_address_space_init(cs,
727 address_space_init_shareable(cs->memory,
735 acc->parent_realize(dev, errp);
738 static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
748 cpuname = g_strsplit(cpu_model, ",", 1);
749 typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpuname[0]);
750 oc = object_class_by_name(typename);
753 if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
754 object_class_is_abstract(oc)) {
760 /* CPU models. These are not needed for the AArch64 linux-user build. */
761 #if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64)
763 static void arm926_initfn(Object *obj)
765 ARMCPU *cpu = ARM_CPU(obj);
767 cpu->dtb_compatible = "arm,arm926";
768 set_feature(&cpu->env, ARM_FEATURE_V5);
769 set_feature(&cpu->env, ARM_FEATURE_VFP);
770 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
771 set_feature(&cpu->env, ARM_FEATURE_CACHE_TEST_CLEAN);
772 cpu->midr = 0x41069265;
773 cpu->reset_fpsid = 0x41011090;
774 cpu->ctr = 0x1dd20d2;
775 cpu->reset_sctlr = 0x00090078;
778 static void arm946_initfn(Object *obj)
780 ARMCPU *cpu = ARM_CPU(obj);
782 cpu->dtb_compatible = "arm,arm946";
783 set_feature(&cpu->env, ARM_FEATURE_V5);
784 set_feature(&cpu->env, ARM_FEATURE_MPU);
785 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
786 cpu->midr = 0x41059461;
787 cpu->ctr = 0x0f004006;
788 cpu->reset_sctlr = 0x00000078;
791 static void arm1026_initfn(Object *obj)
793 ARMCPU *cpu = ARM_CPU(obj);
795 cpu->dtb_compatible = "arm,arm1026";
796 set_feature(&cpu->env, ARM_FEATURE_V5);
797 set_feature(&cpu->env, ARM_FEATURE_VFP);
798 set_feature(&cpu->env, ARM_FEATURE_AUXCR);
799 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
800 set_feature(&cpu->env, ARM_FEATURE_CACHE_TEST_CLEAN);
801 cpu->midr = 0x4106a262;
802 cpu->reset_fpsid = 0x410110a0;
803 cpu->ctr = 0x1dd20d2;
804 cpu->reset_sctlr = 0x00090078;
805 cpu->reset_auxcr = 1;
807 /* The 1026 had an IFAR at c6,c0,0,1 rather than the ARMv6 c6,c0,0,2 */
808 ARMCPRegInfo ifar = {
809 .name = "IFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 1,
811 .fieldoffset = offsetof(CPUARMState, cp15.ifar_ns),
814 define_one_arm_cp_reg(cpu, &ifar);
818 static void arm1136_r2_initfn(Object *obj)
820 ARMCPU *cpu = ARM_CPU(obj);
821 /* What qemu calls "arm1136_r2" is actually the 1136 r0p2, ie an
822 * older core than plain "arm1136". In particular this does not
823 * have the v6K features.
824 * These ID register values are correct for 1136 but may be wrong
825 * for 1136_r2 (in particular r0p2 does not actually implement most
826 * of the ID registers).
829 cpu->dtb_compatible = "arm,arm1136";
830 set_feature(&cpu->env, ARM_FEATURE_V6);
831 set_feature(&cpu->env, ARM_FEATURE_VFP);
832 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
833 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
834 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
835 cpu->midr = 0x4107b362;
836 cpu->reset_fpsid = 0x410120b4;
837 cpu->mvfr0 = 0x11111111;
838 cpu->mvfr1 = 0x00000000;
839 cpu->ctr = 0x1dd20d2;
840 cpu->reset_sctlr = 0x00050078;
841 cpu->id_pfr0 = 0x111;
845 cpu->id_mmfr0 = 0x01130003;
846 cpu->id_mmfr1 = 0x10030302;
847 cpu->id_mmfr2 = 0x01222110;
848 cpu->id_isar0 = 0x00140011;
849 cpu->id_isar1 = 0x12002111;
850 cpu->id_isar2 = 0x11231111;
851 cpu->id_isar3 = 0x01102131;
852 cpu->id_isar4 = 0x141;
853 cpu->reset_auxcr = 7;
856 static void arm1136_initfn(Object *obj)
858 ARMCPU *cpu = ARM_CPU(obj);
860 cpu->dtb_compatible = "arm,arm1136";
861 set_feature(&cpu->env, ARM_FEATURE_V6K);
862 set_feature(&cpu->env, ARM_FEATURE_V6);
863 set_feature(&cpu->env, ARM_FEATURE_VFP);
864 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
865 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
866 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
867 cpu->midr = 0x4117b363;
868 cpu->reset_fpsid = 0x410120b4;
869 cpu->mvfr0 = 0x11111111;
870 cpu->mvfr1 = 0x00000000;
871 cpu->ctr = 0x1dd20d2;
872 cpu->reset_sctlr = 0x00050078;
873 cpu->id_pfr0 = 0x111;
877 cpu->id_mmfr0 = 0x01130003;
878 cpu->id_mmfr1 = 0x10030302;
879 cpu->id_mmfr2 = 0x01222110;
880 cpu->id_isar0 = 0x00140011;
881 cpu->id_isar1 = 0x12002111;
882 cpu->id_isar2 = 0x11231111;
883 cpu->id_isar3 = 0x01102131;
884 cpu->id_isar4 = 0x141;
885 cpu->reset_auxcr = 7;
888 static void arm1176_initfn(Object *obj)
890 ARMCPU *cpu = ARM_CPU(obj);
892 cpu->dtb_compatible = "arm,arm1176";
893 set_feature(&cpu->env, ARM_FEATURE_V6K);
894 set_feature(&cpu->env, ARM_FEATURE_VFP);
895 set_feature(&cpu->env, ARM_FEATURE_VAPA);
896 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
897 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
898 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
899 set_feature(&cpu->env, ARM_FEATURE_EL3);
900 cpu->midr = 0x410fb767;
901 cpu->reset_fpsid = 0x410120b5;
902 cpu->mvfr0 = 0x11111111;
903 cpu->mvfr1 = 0x00000000;
904 cpu->ctr = 0x1dd20d2;
905 cpu->reset_sctlr = 0x00050078;
906 cpu->id_pfr0 = 0x111;
910 cpu->id_mmfr0 = 0x01130003;
911 cpu->id_mmfr1 = 0x10030302;
912 cpu->id_mmfr2 = 0x01222100;
913 cpu->id_isar0 = 0x0140011;
914 cpu->id_isar1 = 0x12002111;
915 cpu->id_isar2 = 0x11231121;
916 cpu->id_isar3 = 0x01102131;
917 cpu->id_isar4 = 0x01141;
918 cpu->reset_auxcr = 7;
921 static void arm11mpcore_initfn(Object *obj)
923 ARMCPU *cpu = ARM_CPU(obj);
925 cpu->dtb_compatible = "arm,arm11mpcore";
926 set_feature(&cpu->env, ARM_FEATURE_V6K);
927 set_feature(&cpu->env, ARM_FEATURE_VFP);
928 set_feature(&cpu->env, ARM_FEATURE_VAPA);
929 set_feature(&cpu->env, ARM_FEATURE_MPIDR);
930 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
931 cpu->midr = 0x410fb022;
932 cpu->reset_fpsid = 0x410120b4;
933 cpu->mvfr0 = 0x11111111;
934 cpu->mvfr1 = 0x00000000;
935 cpu->ctr = 0x1d192992; /* 32K icache 32K dcache */
936 cpu->id_pfr0 = 0x111;
940 cpu->id_mmfr0 = 0x01100103;
941 cpu->id_mmfr1 = 0x10020302;
942 cpu->id_mmfr2 = 0x01222000;
943 cpu->id_isar0 = 0x00100011;
944 cpu->id_isar1 = 0x12002111;
945 cpu->id_isar2 = 0x11221011;
946 cpu->id_isar3 = 0x01102131;
947 cpu->id_isar4 = 0x141;
948 cpu->reset_auxcr = 1;
951 static void cortex_m3_initfn(Object *obj)
953 ARMCPU *cpu = ARM_CPU(obj);
954 set_feature(&cpu->env, ARM_FEATURE_V7);
955 set_feature(&cpu->env, ARM_FEATURE_M);
956 cpu->midr = 0x410fc231;
959 static void cortex_m4_initfn(Object *obj)
961 ARMCPU *cpu = ARM_CPU(obj);
963 set_feature(&cpu->env, ARM_FEATURE_V7);
964 set_feature(&cpu->env, ARM_FEATURE_M);
965 set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP);
966 cpu->midr = 0x410fc240; /* r0p0 */
968 static void arm_v7m_class_init(ObjectClass *oc, void *data)
970 CPUClass *cc = CPU_CLASS(oc);
972 #ifndef CONFIG_USER_ONLY
973 cc->do_interrupt = arm_v7m_cpu_do_interrupt;
976 cc->cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt;
979 static const ARMCPRegInfo cortexr5_cp_reginfo[] = {
980 /* Dummy the TCM region regs for the moment */
981 { .name = "ATCM", .cp = 15, .opc1 = 0, .crn = 9, .crm = 1, .opc2 = 0,
982 .access = PL1_RW, .type = ARM_CP_CONST },
983 { .name = "BTCM", .cp = 15, .opc1 = 0, .crn = 9, .crm = 1, .opc2 = 1,
984 .access = PL1_RW, .type = ARM_CP_CONST },
988 static void cortex_r5_initfn(Object *obj)
990 ARMCPU *cpu = ARM_CPU(obj);
992 set_feature(&cpu->env, ARM_FEATURE_V7);
993 set_feature(&cpu->env, ARM_FEATURE_THUMB_DIV);
994 set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);
995 set_feature(&cpu->env, ARM_FEATURE_V7MP);
996 set_feature(&cpu->env, ARM_FEATURE_MPU);
997 cpu->midr = 0x411fc153; /* r1p3 */
998 cpu->id_pfr0 = 0x0131;
999 cpu->id_pfr1 = 0x001;
1000 cpu->id_dfr0 = 0x010400;
1002 cpu->id_mmfr0 = 0x0210030;
1003 cpu->id_mmfr1 = 0x00000000;
1004 cpu->id_mmfr2 = 0x01200000;
1005 cpu->id_mmfr3 = 0x0211;
1006 cpu->id_isar0 = 0x2101111;
1007 cpu->id_isar1 = 0x13112111;
1008 cpu->id_isar2 = 0x21232141;
1009 cpu->id_isar3 = 0x01112131;
1010 cpu->id_isar4 = 0x0010142;
1011 cpu->id_isar5 = 0x0;
1012 cpu->mp_is_up = true;
1013 define_arm_cp_regs(cpu, cortexr5_cp_reginfo);
1016 static const ARMCPRegInfo cortexa8_cp_reginfo[] = {
1017 { .name = "L2LOCKDOWN", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 0,
1018 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
1019 { .name = "L2AUXCR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 2,
1020 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
1024 static void cortex_a8_initfn(Object *obj)
1026 ARMCPU *cpu = ARM_CPU(obj);
1028 cpu->dtb_compatible = "arm,cortex-a8";
1029 set_feature(&cpu->env, ARM_FEATURE_V7);
1030 set_feature(&cpu->env, ARM_FEATURE_VFP3);
1031 set_feature(&cpu->env, ARM_FEATURE_NEON);
1032 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
1033 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
1034 set_feature(&cpu->env, ARM_FEATURE_EL3);
1035 cpu->midr = 0x410fc080;
1036 cpu->reset_fpsid = 0x410330c0;
1037 cpu->mvfr0 = 0x11110222;
1038 cpu->mvfr1 = 0x00011100;
1039 cpu->ctr = 0x82048004;
1040 cpu->reset_sctlr = 0x00c50078;
1041 cpu->id_pfr0 = 0x1031;
1042 cpu->id_pfr1 = 0x11;
1043 cpu->id_dfr0 = 0x400;
1045 cpu->id_mmfr0 = 0x31100003;
1046 cpu->id_mmfr1 = 0x20000000;
1047 cpu->id_mmfr2 = 0x01202000;
1048 cpu->id_mmfr3 = 0x11;
1049 cpu->id_isar0 = 0x00101111;
1050 cpu->id_isar1 = 0x12112111;
1051 cpu->id_isar2 = 0x21232031;
1052 cpu->id_isar3 = 0x11112131;
1053 cpu->id_isar4 = 0x00111142;
1054 cpu->dbgdidr = 0x15141000;
1055 cpu->clidr = (1 << 27) | (2 << 24) | 3;
1056 cpu->ccsidr[0] = 0xe007e01a; /* 16k L1 dcache. */
1057 cpu->ccsidr[1] = 0x2007e01a; /* 16k L1 icache. */
1058 cpu->ccsidr[2] = 0xf0000000; /* No L2 icache. */
1059 cpu->reset_auxcr = 2;
1060 define_arm_cp_regs(cpu, cortexa8_cp_reginfo);
1063 static const ARMCPRegInfo cortexa9_cp_reginfo[] = {
1064 /* power_control should be set to maximum latency. Again,
1065 * default to 0 and set by private hook
1067 { .name = "A9_PWRCTL", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 0,
1068 .access = PL1_RW, .resetvalue = 0,
1069 .fieldoffset = offsetof(CPUARMState, cp15.c15_power_control) },
1070 { .name = "A9_DIAG", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 1,
1071 .access = PL1_RW, .resetvalue = 0,
1072 .fieldoffset = offsetof(CPUARMState, cp15.c15_diagnostic) },
1073 { .name = "A9_PWRDIAG", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 2,
1074 .access = PL1_RW, .resetvalue = 0,
1075 .fieldoffset = offsetof(CPUARMState, cp15.c15_power_diagnostic) },
1076 { .name = "NEONBUSY", .cp = 15, .crn = 15, .crm = 1, .opc1 = 0, .opc2 = 0,
1077 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
1078 /* TLB lockdown control */
1079 { .name = "TLB_LOCKR", .cp = 15, .crn = 15, .crm = 4, .opc1 = 5, .opc2 = 2,
1080 .access = PL1_W, .resetvalue = 0, .type = ARM_CP_NOP },
1081 { .name = "TLB_LOCKW", .cp = 15, .crn = 15, .crm = 4, .opc1 = 5, .opc2 = 4,
1082 .access = PL1_W, .resetvalue = 0, .type = ARM_CP_NOP },
1083 { .name = "TLB_VA", .cp = 15, .crn = 15, .crm = 5, .opc1 = 5, .opc2 = 2,
1084 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
1085 { .name = "TLB_PA", .cp = 15, .crn = 15, .crm = 6, .opc1 = 5, .opc2 = 2,
1086 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
1087 { .name = "TLB_ATTR", .cp = 15, .crn = 15, .crm = 7, .opc1 = 5, .opc2 = 2,
1088 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
1092 static void cortex_a9_initfn(Object *obj)
1094 ARMCPU *cpu = ARM_CPU(obj);
1096 cpu->dtb_compatible = "arm,cortex-a9";
1097 set_feature(&cpu->env, ARM_FEATURE_V7);
1098 set_feature(&cpu->env, ARM_FEATURE_VFP3);
1099 set_feature(&cpu->env, ARM_FEATURE_VFP_FP16);
1100 set_feature(&cpu->env, ARM_FEATURE_NEON);
1101 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
1102 set_feature(&cpu->env, ARM_FEATURE_EL3);
1103 /* Note that A9 supports the MP extensions even for
1104 * A9UP and single-core A9MP (which are both different
1105 * and valid configurations; we don't model A9UP).
1107 set_feature(&cpu->env, ARM_FEATURE_V7MP);
1108 set_feature(&cpu->env, ARM_FEATURE_CBAR);
1109 cpu->midr = 0x410fc090;
1110 cpu->reset_fpsid = 0x41033090;
1111 cpu->mvfr0 = 0x11110222;
1112 cpu->mvfr1 = 0x01111111;
1113 cpu->ctr = 0x80038003;
1114 cpu->reset_sctlr = 0x00c50078;
1115 cpu->id_pfr0 = 0x1031;
1116 cpu->id_pfr1 = 0x11;
1117 cpu->id_dfr0 = 0x000;
1119 cpu->id_mmfr0 = 0x00100103;
1120 cpu->id_mmfr1 = 0x20000000;
1121 cpu->id_mmfr2 = 0x01230000;
1122 cpu->id_mmfr3 = 0x00002111;
1123 cpu->id_isar0 = 0x00101111;
1124 cpu->id_isar1 = 0x13112111;
1125 cpu->id_isar2 = 0x21232041;
1126 cpu->id_isar3 = 0x11112131;
1127 cpu->id_isar4 = 0x00111142;
1128 cpu->dbgdidr = 0x35141000;
1129 cpu->clidr = (1 << 27) | (1 << 24) | 3;
1130 cpu->ccsidr[0] = 0xe00fe019; /* 16k L1 dcache. */
1131 cpu->ccsidr[1] = 0x200fe019; /* 16k L1 icache. */
1132 define_arm_cp_regs(cpu, cortexa9_cp_reginfo);
1135 #ifndef CONFIG_USER_ONLY
1136 static uint64_t a15_l2ctlr_read(CPUARMState *env, const ARMCPRegInfo *ri)
1138 /* Linux wants the number of processors from here.
1139 * Might as well set the interrupt-controller bit too.
1141 return ((smp_cpus - 1) << 24) | (1 << 23);
1145 static const ARMCPRegInfo cortexa15_cp_reginfo[] = {
1146 #ifndef CONFIG_USER_ONLY
1147 { .name = "L2CTLR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 2,
1148 .access = PL1_RW, .resetvalue = 0, .readfn = a15_l2ctlr_read,
1149 .writefn = arm_cp_write_ignore, },
1151 { .name = "L2ECTLR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 3,
1152 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
1156 static void cortex_a7_initfn(Object *obj)
1158 ARMCPU *cpu = ARM_CPU(obj);
1160 cpu->dtb_compatible = "arm,cortex-a7";
1161 set_feature(&cpu->env, ARM_FEATURE_V7);
1162 set_feature(&cpu->env, ARM_FEATURE_VFP4);
1163 set_feature(&cpu->env, ARM_FEATURE_NEON);
1164 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
1165 set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);
1166 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
1167 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
1168 set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
1169 set_feature(&cpu->env, ARM_FEATURE_LPAE);
1170 set_feature(&cpu->env, ARM_FEATURE_EL3);
1171 cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A7;
1172 cpu->midr = 0x410fc075;
1173 cpu->reset_fpsid = 0x41023075;
1174 cpu->mvfr0 = 0x10110222;
1175 cpu->mvfr1 = 0x11111111;
1176 cpu->ctr = 0x84448003;
1177 cpu->reset_sctlr = 0x00c50078;
1178 cpu->id_pfr0 = 0x00001131;
1179 cpu->id_pfr1 = 0x00011011;
1180 cpu->id_dfr0 = 0x02010555;
1181 cpu->pmceid0 = 0x00000000;
1182 cpu->pmceid1 = 0x00000000;
1183 cpu->id_afr0 = 0x00000000;
1184 cpu->id_mmfr0 = 0x10101105;
1185 cpu->id_mmfr1 = 0x40000000;
1186 cpu->id_mmfr2 = 0x01240000;
1187 cpu->id_mmfr3 = 0x02102211;
1188 cpu->id_isar0 = 0x01101110;
1189 cpu->id_isar1 = 0x13112111;
1190 cpu->id_isar2 = 0x21232041;
1191 cpu->id_isar3 = 0x11112131;
1192 cpu->id_isar4 = 0x10011142;
1193 cpu->dbgdidr = 0x3515f005;
1194 cpu->clidr = 0x0a200023;
1195 cpu->ccsidr[0] = 0x701fe00a; /* 32K L1 dcache */
1196 cpu->ccsidr[1] = 0x201fe00a; /* 32K L1 icache */
1197 cpu->ccsidr[2] = 0x711fe07a; /* 4096K L2 unified cache */
1198 define_arm_cp_regs(cpu, cortexa15_cp_reginfo); /* Same as A15 */
1201 static void cortex_a15_initfn(Object *obj)
1203 ARMCPU *cpu = ARM_CPU(obj);
1205 cpu->dtb_compatible = "arm,cortex-a15";
1206 set_feature(&cpu->env, ARM_FEATURE_V7);
1207 set_feature(&cpu->env, ARM_FEATURE_VFP4);
1208 set_feature(&cpu->env, ARM_FEATURE_NEON);
1209 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
1210 set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);
1211 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
1212 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
1213 set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
1214 set_feature(&cpu->env, ARM_FEATURE_LPAE);
1215 set_feature(&cpu->env, ARM_FEATURE_EL3);
1216 cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A15;
1217 cpu->midr = 0x412fc0f1;
1218 cpu->reset_fpsid = 0x410430f0;
1219 cpu->mvfr0 = 0x10110222;
1220 cpu->mvfr1 = 0x11111111;
1221 cpu->ctr = 0x8444c004;
1222 cpu->reset_sctlr = 0x00c50078;
1223 cpu->id_pfr0 = 0x00001131;
1224 cpu->id_pfr1 = 0x00011011;
1225 cpu->id_dfr0 = 0x02010555;
1226 cpu->pmceid0 = 0x0000000;
1227 cpu->pmceid1 = 0x00000000;
1228 cpu->id_afr0 = 0x00000000;
1229 cpu->id_mmfr0 = 0x10201105;
1230 cpu->id_mmfr1 = 0x20000000;
1231 cpu->id_mmfr2 = 0x01240000;
1232 cpu->id_mmfr3 = 0x02102211;
1233 cpu->id_isar0 = 0x02101110;
1234 cpu->id_isar1 = 0x13112111;
1235 cpu->id_isar2 = 0x21232041;
1236 cpu->id_isar3 = 0x11112131;
1237 cpu->id_isar4 = 0x10011142;
1238 cpu->dbgdidr = 0x3515f021;
1239 cpu->clidr = 0x0a200023;
1240 cpu->ccsidr[0] = 0x701fe00a; /* 32K L1 dcache */
1241 cpu->ccsidr[1] = 0x201fe00a; /* 32K L1 icache */
1242 cpu->ccsidr[2] = 0x711fe07a; /* 4096K L2 unified cache */
1243 define_arm_cp_regs(cpu, cortexa15_cp_reginfo);
1246 static void ti925t_initfn(Object *obj)
1248 ARMCPU *cpu = ARM_CPU(obj);
1249 set_feature(&cpu->env, ARM_FEATURE_V4T);
1250 set_feature(&cpu->env, ARM_FEATURE_OMAPCP);
1251 cpu->midr = ARM_CPUID_TI925T;
1252 cpu->ctr = 0x5109149;
1253 cpu->reset_sctlr = 0x00000070;
1256 static void sa1100_initfn(Object *obj)
1258 ARMCPU *cpu = ARM_CPU(obj);
1260 cpu->dtb_compatible = "intel,sa1100";
1261 set_feature(&cpu->env, ARM_FEATURE_STRONGARM);
1262 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
1263 cpu->midr = 0x4401A11B;
1264 cpu->reset_sctlr = 0x00000070;
1267 static void sa1110_initfn(Object *obj)
1269 ARMCPU *cpu = ARM_CPU(obj);
1270 set_feature(&cpu->env, ARM_FEATURE_STRONGARM);
1271 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
1272 cpu->midr = 0x6901B119;
1273 cpu->reset_sctlr = 0x00000070;
1276 static void pxa250_initfn(Object *obj)
1278 ARMCPU *cpu = ARM_CPU(obj);
1280 cpu->dtb_compatible = "marvell,xscale";
1281 set_feature(&cpu->env, ARM_FEATURE_V5);
1282 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1283 cpu->midr = 0x69052100;
1284 cpu->ctr = 0xd172172;
1285 cpu->reset_sctlr = 0x00000078;
1288 static void pxa255_initfn(Object *obj)
1290 ARMCPU *cpu = ARM_CPU(obj);
1292 cpu->dtb_compatible = "marvell,xscale";
1293 set_feature(&cpu->env, ARM_FEATURE_V5);
1294 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1295 cpu->midr = 0x69052d00;
1296 cpu->ctr = 0xd172172;
1297 cpu->reset_sctlr = 0x00000078;
1300 static void pxa260_initfn(Object *obj)
1302 ARMCPU *cpu = ARM_CPU(obj);
1304 cpu->dtb_compatible = "marvell,xscale";
1305 set_feature(&cpu->env, ARM_FEATURE_V5);
1306 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1307 cpu->midr = 0x69052903;
1308 cpu->ctr = 0xd172172;
1309 cpu->reset_sctlr = 0x00000078;
1312 static void pxa261_initfn(Object *obj)
1314 ARMCPU *cpu = ARM_CPU(obj);
1316 cpu->dtb_compatible = "marvell,xscale";
1317 set_feature(&cpu->env, ARM_FEATURE_V5);
1318 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1319 cpu->midr = 0x69052d05;
1320 cpu->ctr = 0xd172172;
1321 cpu->reset_sctlr = 0x00000078;
1324 static void pxa262_initfn(Object *obj)
1326 ARMCPU *cpu = ARM_CPU(obj);
1328 cpu->dtb_compatible = "marvell,xscale";
1329 set_feature(&cpu->env, ARM_FEATURE_V5);
1330 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1331 cpu->midr = 0x69052d06;
1332 cpu->ctr = 0xd172172;
1333 cpu->reset_sctlr = 0x00000078;
1336 static void pxa270a0_initfn(Object *obj)
1338 ARMCPU *cpu = ARM_CPU(obj);
1340 cpu->dtb_compatible = "marvell,xscale";
1341 set_feature(&cpu->env, ARM_FEATURE_V5);
1342 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1343 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1344 cpu->midr = 0x69054110;
1345 cpu->ctr = 0xd172172;
1346 cpu->reset_sctlr = 0x00000078;
1349 static void pxa270a1_initfn(Object *obj)
1351 ARMCPU *cpu = ARM_CPU(obj);
1353 cpu->dtb_compatible = "marvell,xscale";
1354 set_feature(&cpu->env, ARM_FEATURE_V5);
1355 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1356 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1357 cpu->midr = 0x69054111;
1358 cpu->ctr = 0xd172172;
1359 cpu->reset_sctlr = 0x00000078;
1362 static void pxa270b0_initfn(Object *obj)
1364 ARMCPU *cpu = ARM_CPU(obj);
1366 cpu->dtb_compatible = "marvell,xscale";
1367 set_feature(&cpu->env, ARM_FEATURE_V5);
1368 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1369 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1370 cpu->midr = 0x69054112;
1371 cpu->ctr = 0xd172172;
1372 cpu->reset_sctlr = 0x00000078;
1375 static void pxa270b1_initfn(Object *obj)
1377 ARMCPU *cpu = ARM_CPU(obj);
1379 cpu->dtb_compatible = "marvell,xscale";
1380 set_feature(&cpu->env, ARM_FEATURE_V5);
1381 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1382 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1383 cpu->midr = 0x69054113;
1384 cpu->ctr = 0xd172172;
1385 cpu->reset_sctlr = 0x00000078;
1388 static void pxa270c0_initfn(Object *obj)
1390 ARMCPU *cpu = ARM_CPU(obj);
1392 cpu->dtb_compatible = "marvell,xscale";
1393 set_feature(&cpu->env, ARM_FEATURE_V5);
1394 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1395 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1396 cpu->midr = 0x69054114;
1397 cpu->ctr = 0xd172172;
1398 cpu->reset_sctlr = 0x00000078;
1401 static void pxa270c5_initfn(Object *obj)
1403 ARMCPU *cpu = ARM_CPU(obj);
1405 cpu->dtb_compatible = "marvell,xscale";
1406 set_feature(&cpu->env, ARM_FEATURE_V5);
1407 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1408 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1409 cpu->midr = 0x69054117;
1410 cpu->ctr = 0xd172172;
1411 cpu->reset_sctlr = 0x00000078;
1414 #ifdef CONFIG_USER_ONLY
1415 static void arm_any_initfn(Object *obj)
1417 ARMCPU *cpu = ARM_CPU(obj);
1418 set_feature(&cpu->env, ARM_FEATURE_V8);
1419 set_feature(&cpu->env, ARM_FEATURE_VFP4);
1420 set_feature(&cpu->env, ARM_FEATURE_NEON);
1421 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
1422 set_feature(&cpu->env, ARM_FEATURE_V8_AES);
1423 set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
1424 set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
1425 set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
1426 set_feature(&cpu->env, ARM_FEATURE_CRC);
1427 cpu->midr = 0xffffffff;
1431 #endif /* !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64) */
1433 typedef struct ARMCPUInfo {
1435 void (*initfn)(Object *obj);
1436 void (*class_init)(ObjectClass *oc, void *data);
1439 static const ARMCPUInfo arm_cpus[] = {
1440 #if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64)
1441 { .name = "arm926", .initfn = arm926_initfn },
1442 { .name = "arm946", .initfn = arm946_initfn },
1443 { .name = "arm1026", .initfn = arm1026_initfn },
1444 /* What QEMU calls "arm1136-r2" is actually the 1136 r0p2, i.e. an
1445 * older core than plain "arm1136". In particular this does not
1446 * have the v6K features.
1448 { .name = "arm1136-r2", .initfn = arm1136_r2_initfn },
1449 { .name = "arm1136", .initfn = arm1136_initfn },
1450 { .name = "arm1176", .initfn = arm1176_initfn },
1451 { .name = "arm11mpcore", .initfn = arm11mpcore_initfn },
1452 { .name = "cortex-m3", .initfn = cortex_m3_initfn,
1453 .class_init = arm_v7m_class_init },
1454 { .name = "cortex-m4", .initfn = cortex_m4_initfn,
1455 .class_init = arm_v7m_class_init },
1456 { .name = "cortex-r5", .initfn = cortex_r5_initfn },
1457 { .name = "cortex-a7", .initfn = cortex_a7_initfn },
1458 { .name = "cortex-a8", .initfn = cortex_a8_initfn },
1459 { .name = "cortex-a9", .initfn = cortex_a9_initfn },
1460 { .name = "cortex-a15", .initfn = cortex_a15_initfn },
1461 { .name = "ti925t", .initfn = ti925t_initfn },
1462 { .name = "sa1100", .initfn = sa1100_initfn },
1463 { .name = "sa1110", .initfn = sa1110_initfn },
1464 { .name = "pxa250", .initfn = pxa250_initfn },
1465 { .name = "pxa255", .initfn = pxa255_initfn },
1466 { .name = "pxa260", .initfn = pxa260_initfn },
1467 { .name = "pxa261", .initfn = pxa261_initfn },
1468 { .name = "pxa262", .initfn = pxa262_initfn },
1469 /* "pxa270" is an alias for "pxa270-a0" */
1470 { .name = "pxa270", .initfn = pxa270a0_initfn },
1471 { .name = "pxa270-a0", .initfn = pxa270a0_initfn },
1472 { .name = "pxa270-a1", .initfn = pxa270a1_initfn },
1473 { .name = "pxa270-b0", .initfn = pxa270b0_initfn },
1474 { .name = "pxa270-b1", .initfn = pxa270b1_initfn },
1475 { .name = "pxa270-c0", .initfn = pxa270c0_initfn },
1476 { .name = "pxa270-c5", .initfn = pxa270c5_initfn },
1477 #ifdef CONFIG_USER_ONLY
1478 { .name = "any", .initfn = arm_any_initfn },
1484 static Property arm_cpu_properties[] = {
1485 DEFINE_PROP_BOOL("start-powered-off", ARMCPU, start_powered_off, false),
1486 DEFINE_PROP_UINT32("psci-conduit", ARMCPU, psci_conduit, 0),
1487 DEFINE_PROP_UINT32("midr", ARMCPU, midr, 0),
1488 DEFINE_PROP_UINT64("mp-affinity", ARMCPU, mp_affinity, 0),
1489 DEFINE_PROP_END_OF_LIST()
1492 #ifdef CONFIG_USER_ONLY
1493 static int arm_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
1496 ARMCPU *cpu = ARM_CPU(cs);
1497 CPUARMState *env = &cpu->env;
1499 env->exception.vaddress = address;
1501 cs->exception_index = EXCP_PREFETCH_ABORT;
1503 cs->exception_index = EXCP_DATA_ABORT;
1509 static gchar *arm_gdb_arch_name(CPUState *cs)
1511 ARMCPU *cpu = ARM_CPU(cs);
1512 CPUARMState *env = &cpu->env;
1514 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
1515 return g_strdup("iwmmxt");
1517 return g_strdup("arm");
1520 static void arm_cpu_class_init(ObjectClass *oc, void *data)
1522 ARMCPUClass *acc = ARM_CPU_CLASS(oc);
1523 CPUClass *cc = CPU_CLASS(acc);
1524 DeviceClass *dc = DEVICE_CLASS(oc);
1526 acc->parent_realize = dc->realize;
1527 dc->realize = arm_cpu_realizefn;
1528 dc->props = arm_cpu_properties;
1530 acc->parent_reset = cc->reset;
1531 cc->reset = arm_cpu_reset;
1533 cc->class_by_name = arm_cpu_class_by_name;
1534 cc->has_work = arm_cpu_has_work;
1535 cc->cpu_exec_interrupt = arm_cpu_exec_interrupt;
1536 cc->dump_state = arm_cpu_dump_state;
1537 cc->set_pc = arm_cpu_set_pc;
1538 cc->gdb_read_register = arm_cpu_gdb_read_register;
1539 cc->gdb_write_register = arm_cpu_gdb_write_register;
1540 #ifdef CONFIG_USER_ONLY
1541 cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;
1543 cc->do_interrupt = arm_cpu_do_interrupt;
1544 cc->do_unaligned_access = arm_cpu_do_unaligned_access;
1545 cc->get_phys_page_attrs_debug = arm_cpu_get_phys_page_attrs_debug;
1546 cc->asidx_from_attrs = arm_asidx_from_attrs;
1547 cc->vmsd = &vmstate_arm_cpu;
1548 cc->virtio_is_big_endian = arm_cpu_virtio_is_big_endian;
1549 cc->write_elf64_note = arm_cpu_write_elf64_note;
1550 cc->write_elf32_note = arm_cpu_write_elf32_note;
1552 cc->gdb_num_core_regs = 26;
1553 cc->gdb_core_xml_file = "arm-core.xml";
1554 cc->gdb_arch_name = arm_gdb_arch_name;
1555 cc->gdb_stop_before_watchpoint = true;
1556 cc->debug_excp_handler = arm_debug_excp_handler;
1557 cc->debug_check_watchpoint = arm_debug_check_watchpoint;
1559 cc->disas_set_info = arm_disas_set_info;
1562 * Reason: arm_cpu_initfn() calls cpu_exec_init(), which saves
1563 * the object in cpus -> dangling pointer after final
1566 * Once this is fixed, the devices that create ARM CPUs should be
1567 * updated not to set cannot_destroy_with_object_finalize_yet,
1568 * unless they still screw up something else.
1570 dc->cannot_destroy_with_object_finalize_yet = true;
1573 static void cpu_register(const ARMCPUInfo *info)
1575 TypeInfo type_info = {
1576 .parent = TYPE_ARM_CPU,
1577 .instance_size = sizeof(ARMCPU),
1578 .instance_init = info->initfn,
1579 .class_size = sizeof(ARMCPUClass),
1580 .class_init = info->class_init,
1583 type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
1584 type_register(&type_info);
1585 g_free((void *)type_info.name);
1588 static const TypeInfo arm_cpu_type_info = {
1589 .name = TYPE_ARM_CPU,
1591 .instance_size = sizeof(ARMCPU),
1592 .instance_init = arm_cpu_initfn,
1593 .instance_post_init = arm_cpu_post_init,
1594 .instance_finalize = arm_cpu_finalizefn,
1596 .class_size = sizeof(ARMCPUClass),
1597 .class_init = arm_cpu_class_init,
1600 static void arm_cpu_register_types(void)
1602 const ARMCPUInfo *info = arm_cpus;
1604 type_register_static(&arm_cpu_type_info);
1606 while (info->name) {
1612 type_init(arm_cpu_register_types)