]> git.proxmox.com Git - mirror_qemu.git/blame - target-arm/cpu.c
migration/savevm.c: migrate non-default page size
[mirror_qemu.git] / target-arm / cpu.c
CommitLineData
dec9c2d4
AF
1/*
2 * QEMU ARM CPU
3 *
4 * Copyright (c) 2012 SUSE LINUX Products GmbH
5 *
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.
10 *
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.
15 *
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>
19 */
20
74c21bd0 21#include "qemu/osdep.h"
da34e65c 22#include "qapi/error.h"
778c3a06 23#include "cpu.h"
ccd38087 24#include "internals.h"
dec9c2d4 25#include "qemu-common.h"
63c91552 26#include "exec/exec-all.h"
5de16430 27#include "hw/qdev-properties.h"
3c30dd5a
PM
28#if !defined(CONFIG_USER_ONLY)
29#include "hw/loader.h"
30#endif
7c1840b6 31#include "hw/arm/arm.h"
9c17d615 32#include "sysemu/sysemu.h"
7c1840b6 33#include "sysemu/kvm.h"
50a2c6e5 34#include "kvm_arm.h"
dec9c2d4 35
f45748f1
AF
36static void arm_cpu_set_pc(CPUState *cs, vaddr value)
37{
38 ARMCPU *cpu = ARM_CPU(cs);
39
40 cpu->env.regs[15] = value;
41}
42
8c2e1b00
AF
43static bool arm_cpu_has_work(CPUState *cs)
44{
543486db
RH
45 ARMCPU *cpu = ARM_CPU(cs);
46
47 return !cpu->powered_off
48 && cs->interrupt_request &
136e67e9
EI
49 (CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD
50 | CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ
51 | CPU_INTERRUPT_EXITTB);
8c2e1b00
AF
52}
53
bd7d00fc
PM
54void arm_register_el_change_hook(ARMCPU *cpu, ARMELChangeHook *hook,
55 void *opaque)
56{
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;
61}
62
4b6a83fb
PM
63static void cp_reg_reset(gpointer key, gpointer value, gpointer opaque)
64{
65 /* Reset a single ARMCPRegInfo register */
66 ARMCPRegInfo *ri = value;
67 ARMCPU *cpu = opaque;
68
b061a82b 69 if (ri->type & (ARM_CP_SPECIAL | ARM_CP_ALIAS)) {
4b6a83fb
PM
70 return;
71 }
72
73 if (ri->resetfn) {
74 ri->resetfn(&cpu->env, ri);
75 return;
76 }
77
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).
82 */
83 if (!ri->fieldoffset) {
84 return;
85 }
86
67ed771d 87 if (cpreg_field_is_64bit(ri)) {
4b6a83fb
PM
88 CPREG_FIELD64(&cpu->env, ri) = ri->resetvalue;
89 } else {
90 CPREG_FIELD32(&cpu->env, ri) = ri->resetvalue;
91 }
92}
93
49a66191
PM
94static void cp_reg_check_reset(gpointer key, gpointer value, gpointer opaque)
95{
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.
100 */
101 ARMCPRegInfo *ri = value;
102 ARMCPU *cpu = opaque;
103 uint64_t oldvalue, newvalue;
104
105 if (ri->type & (ARM_CP_SPECIAL | ARM_CP_ALIAS | ARM_CP_NO_RAW)) {
106 return;
107 }
108
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);
113}
114
dec9c2d4
AF
115/* CPUClass::reset() */
116static void arm_cpu_reset(CPUState *s)
117{
118 ARMCPU *cpu = ARM_CPU(s);
119 ARMCPUClass *acc = ARM_CPU_GET_CLASS(cpu);
3c30dd5a 120 CPUARMState *env = &cpu->env;
3c30dd5a 121
dec9c2d4
AF
122 acc->parent_reset(s);
123
f0c3c505 124 memset(env, 0, offsetof(CPUARMState, features));
4b6a83fb 125 g_hash_table_foreach(cpu->cp_regs, cp_reg_reset, cpu);
49a66191
PM
126 g_hash_table_foreach(cpu->cp_regs, cp_reg_check_reset, cpu);
127
3c30dd5a
PM
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;
a50c0f51 131 env->vfp.xregs[ARM_VFP_MVFR2] = cpu->mvfr2;
3c30dd5a 132
543486db
RH
133 cpu->powered_off = cpu->start_powered_off;
134 s->halted = cpu->start_powered_off;
135
3c30dd5a
PM
136 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
137 env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
138 }
139
3926cc84
AG
140 if (arm_feature(env, ARM_FEATURE_AARCH64)) {
141 /* 64 bit CPUs always start in 64 bit mode */
142 env->aarch64 = 1;
d356312f
PM
143#if defined(CONFIG_USER_ONLY)
144 env->pstate = PSTATE_MODE_EL0t;
14e5f106 145 /* Userspace expects access to DC ZVA, CTL_EL0 and the cache ops */
137feaa9 146 env->cp15.sctlr_el[1] |= SCTLR_UCT | SCTLR_UCI | SCTLR_DZE;
8c6afa6a 147 /* and to the FP/Neon instructions */
7ebd5f2e 148 env->cp15.cpacr_el1 = deposit64(env->cp15.cpacr_el1, 20, 2, 3);
d356312f 149#else
5097227c
GB
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;
155 } else {
156 env->pstate = PSTATE_MODE_EL1h;
157 }
3933443e 158 env->pc = cpu->rvbar;
8c6afa6a
PM
159#endif
160 } else {
161#if defined(CONFIG_USER_ONLY)
162 /* Userspace expects access to cp10 and cp11 for FP/Neon */
7ebd5f2e 163 env->cp15.cpacr_el1 = deposit64(env->cp15.cpacr_el1, 20, 4, 0xf);
d356312f 164#endif
3926cc84
AG
165 }
166
3c30dd5a
PM
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;
175 }
176#else
177 /* SVC mode with interrupts disabled. */
4cc35614
PM
178 env->uncached_cpsr = ARM_CPU_MODE_SVC;
179 env->daif = PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F;
3c30dd5a 180 /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
6e3cf5df
MG
181 * clear at reset. Initial SP and PC are loaded from ROM.
182 */
3c30dd5a 183 if (IS_M(env)) {
6e3cf5df
MG
184 uint32_t initial_msp; /* Loaded from 0x0 */
185 uint32_t initial_pc; /* Loaded from 0x4 */
3c30dd5a 186 uint8_t *rom;
6e3cf5df 187
4cc35614 188 env->daif &= ~PSTATE_I;
3c30dd5a
PM
189 rom = rom_ptr(0);
190 if (rom) {
6e3cf5df
MG
191 /* Address zero is covered by ROM which hasn't yet been
192 * copied into physical memory.
193 */
194 initial_msp = ldl_p(rom);
195 initial_pc = ldl_p(rom + 4);
196 } else {
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.
201 */
202 initial_msp = ldl_phys(s->as, 0);
203 initial_pc = ldl_phys(s->as, 4);
3c30dd5a 204 }
6e3cf5df
MG
205
206 env->regs[13] = initial_msp & 0xFFFFFFFC;
207 env->regs[15] = initial_pc & ~1;
208 env->thumb = initial_pc & 1;
3c30dd5a 209 }
387f9806 210
137feaa9
FA
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.
214 */
215 if (A32_BANKED_CURRENT_REG_GET(env, sctlr) & SCTLR_V) {
34bf7744 216 env->regs[15] = 0xFFFF0000;
387f9806
AP
217 }
218
3c30dd5a 219 env->vfp.xregs[ARM_VFP_FPEXC] = 0;
3c30dd5a
PM
220#endif
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);
00c8cb0a 228 tlb_flush(s, 1);
50a2c6e5
PB
229
230#ifndef CONFIG_USER_ONLY
231 if (kvm_enabled()) {
232 kvm_arm_reset_vcpu(cpu);
233 }
234#endif
9ee98ce8 235
46747d15 236 hw_breakpoint_update_all(cpu);
9ee98ce8 237 hw_watchpoint_update_all(cpu);
dec9c2d4
AF
238}
239
e8925712
RH
240bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
241{
242 CPUClass *cc = CPU_GET_CLASS(cs);
012a906b
GB
243 CPUARMState *env = cs->env_ptr;
244 uint32_t cur_el = arm_current_el(env);
245 bool secure = arm_is_secure(env);
246 uint32_t target_el;
247 uint32_t excp_idx;
e8925712
RH
248 bool ret = false;
249
012a906b
GB
250 if (interrupt_request & CPU_INTERRUPT_FIQ) {
251 excp_idx = EXCP_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);
257 ret = true;
258 }
e8925712 259 }
012a906b
GB
260 if (interrupt_request & CPU_INTERRUPT_HARD) {
261 excp_idx = EXCP_IRQ;
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);
267 ret = true;
268 }
e8925712 269 }
012a906b
GB
270 if (interrupt_request & CPU_INTERRUPT_VIRQ) {
271 excp_idx = EXCP_VIRQ;
272 target_el = 1;
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);
277 ret = true;
278 }
136e67e9 279 }
012a906b
GB
280 if (interrupt_request & CPU_INTERRUPT_VFIQ) {
281 excp_idx = EXCP_VFIQ;
282 target_el = 1;
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);
287 ret = true;
288 }
136e67e9 289 }
e8925712
RH
290
291 return ret;
292}
293
b5c633c5
PM
294#if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64)
295static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
296{
297 CPUClass *cc = CPU_GET_CLASS(cs);
298 ARMCPU *cpu = ARM_CPU(cs);
299 CPUARMState *env = &cpu->env;
300 bool ret = false;
301
302
303 if (interrupt_request & CPU_INTERRUPT_FIQ
304 && !(env->daif & PSTATE_F)) {
305 cs->exception_index = EXCP_FIQ;
306 cc->do_interrupt(cs);
307 ret = true;
308 }
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.
318 */
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);
324 ret = true;
325 }
326 return ret;
327}
328#endif
329
7c1840b6
PM
330#ifndef CONFIG_USER_ONLY
331static void arm_cpu_set_irq(void *opaque, int irq, int level)
332{
333 ARMCPU *cpu = opaque;
136e67e9 334 CPUARMState *env = &cpu->env;
7c1840b6 335 CPUState *cs = CPU(cpu);
136e67e9
EI
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
341 };
7c1840b6
PM
342
343 switch (irq) {
136e67e9
EI
344 case ARM_CPU_VIRQ:
345 case ARM_CPU_VFIQ:
f128bf29 346 assert(arm_feature(env, ARM_FEATURE_EL2));
136e67e9
EI
347 /* fall through */
348 case ARM_CPU_IRQ:
7c1840b6
PM
349 case ARM_CPU_FIQ:
350 if (level) {
136e67e9 351 cpu_interrupt(cs, mask[irq]);
7c1840b6 352 } else {
136e67e9 353 cpu_reset_interrupt(cs, mask[irq]);
7c1840b6
PM
354 }
355 break;
356 default:
8f6fd322 357 g_assert_not_reached();
7c1840b6
PM
358 }
359}
360
361static void arm_cpu_kvm_set_irq(void *opaque, int irq, int level)
362{
363#ifdef CONFIG_KVM
364 ARMCPU *cpu = opaque;
365 CPUState *cs = CPU(cpu);
366 int kvm_irq = KVM_ARM_IRQ_TYPE_CPU << KVM_ARM_IRQ_TYPE_SHIFT;
367
368 switch (irq) {
369 case ARM_CPU_IRQ:
370 kvm_irq |= KVM_ARM_IRQ_CPU_IRQ;
371 break;
372 case ARM_CPU_FIQ:
373 kvm_irq |= KVM_ARM_IRQ_CPU_FIQ;
374 break;
375 default:
8f6fd322 376 g_assert_not_reached();
7c1840b6
PM
377 }
378 kvm_irq |= cs->cpu_index << KVM_ARM_IRQ_VCPU_SHIFT;
379 kvm_set_irq(kvm_state, kvm_irq, level ? 1 : 0);
380#endif
381}
84f2bed3 382
ed50ff78 383static bool arm_cpu_virtio_is_big_endian(CPUState *cs)
84f2bed3
PS
384{
385 ARMCPU *cpu = ARM_CPU(cs);
386 CPUARMState *env = &cpu->env;
84f2bed3
PS
387
388 cpu_synchronize_state(cs);
ed50ff78 389 return arm_cpu_data_is_big_endian(env);
84f2bed3
PS
390}
391
7c1840b6
PM
392#endif
393
581be094
PM
394static inline void set_feature(CPUARMState *env, int feature)
395{
918f5dca 396 env->features |= 1ULL << feature;
581be094
PM
397}
398
08828484
GB
399static inline void unset_feature(CPUARMState *env, int feature)
400{
401 env->features &= ~(1ULL << feature);
402}
403
48440620
PC
404static int
405print_insn_thumb1(bfd_vma pc, disassemble_info *info)
406{
407 return print_insn_arm(pc | 1, info);
408}
409
410static void arm_disas_set_info(CPUState *cpu, disassemble_info *info)
411{
412 ARMCPU *ac = ARM_CPU(cpu);
413 CPUARMState *env = &ac->env;
414
415 if (is_a64(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.
419 */
420#if defined(CONFIG_ARM_A64_DIS)
421 info->print_insn = print_insn_arm_a64;
422#endif
423 } else if (env->thumb) {
424 info->print_insn = print_insn_thumb1;
425 } else {
426 info->print_insn = print_insn_arm;
427 }
f9fd40eb 428 if (bswap_code(arm_sctlr_b(env))) {
48440620
PC
429#ifdef TARGET_WORDS_BIGENDIAN
430 info->endian = BFD_ENDIAN_LITTLE;
431#else
432 info->endian = BFD_ENDIAN_BIG;
433#endif
434 }
435}
436
eb5e1d3c
PF
437#define ARM_CPUS_PER_CLUSTER 8
438
777dc784
PM
439static void arm_cpu_initfn(Object *obj)
440{
c05efcb1 441 CPUState *cs = CPU(obj);
777dc784 442 ARMCPU *cpu = ARM_CPU(obj);
79614b78 443 static bool inited;
eb5e1d3c 444 uint32_t Aff1, Aff0;
777dc784 445
c05efcb1 446 cs->env_ptr = &cpu->env;
4bad9e39 447 cpu_exec_init(cs, &error_abort);
4b6a83fb
PM
448 cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal,
449 g_free, g_free);
79614b78 450
eb5e1d3c
PF
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.
455 */
456 Aff1 = cs->cpu_index / ARM_CPUS_PER_CLUSTER;
457 Aff0 = cs->cpu_index % ARM_CPUS_PER_CLUSTER;
0f4a9e45 458 cpu->mp_affinity = (Aff1 << ARM_AFF1_SHIFT) | Aff0;
eb5e1d3c 459
7c1840b6
PM
460#ifndef CONFIG_USER_ONLY
461 /* Our inbound IRQ and FIQ lines */
462 if (kvm_enabled()) {
136e67e9
EI
463 /* VIRQ and VFIQ are unused with KVM but we add them to maintain
464 * the same interface as non-KVM CPUs.
465 */
466 qdev_init_gpio_in(DEVICE(cpu), arm_cpu_kvm_set_irq, 4);
7c1840b6 467 } else {
136e67e9 468 qdev_init_gpio_in(DEVICE(cpu), arm_cpu_set_irq, 4);
7c1840b6 469 }
55d284af 470
bc72ad67 471 cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
55d284af 472 arm_gt_ptimer_cb, cpu);
bc72ad67 473 cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
55d284af 474 arm_gt_vtimer_cb, cpu);
b0e66d95
EI
475 cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
476 arm_gt_htimer_cb, cpu);
b4d3978c
PM
477 cpu->gt_timer[GTIMER_SEC] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
478 arm_gt_stimer_cb, cpu);
55d284af
PM
479 qdev_init_gpio_out(DEVICE(cpu), cpu->gt_timer_outputs,
480 ARRAY_SIZE(cpu->gt_timer_outputs));
7c1840b6
PM
481#endif
482
54d3e3f5
PM
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.
486 */
487 cpu->dtb_compatible = "qemu,unknown";
dd032e34 488 cpu->psci_version = 1; /* By default assume PSCI v0.1 */
3541addc 489 cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
54d3e3f5 490
98128601
RH
491 if (tcg_enabled()) {
492 cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
493 if (!inited) {
494 inited = true;
495 arm_translate_init();
496 }
79614b78 497 }
4b6a83fb
PM
498}
499
07a5b0d2 500static Property arm_cpu_reset_cbar_property =
f318cec6 501 DEFINE_PROP_UINT64("reset-cbar", ARMCPU, reset_cbar, 0);
07a5b0d2 502
68e0a40a
AP
503static Property arm_cpu_reset_hivecs_property =
504 DEFINE_PROP_BOOL("reset-hivecs", ARMCPU, reset_hivecs, false);
505
3933443e
PM
506static Property arm_cpu_rvbar_property =
507 DEFINE_PROP_UINT64("rvbar", ARMCPU, rvbar, 0);
508
51942aee
GB
509static Property arm_cpu_has_el3_property =
510 DEFINE_PROP_BOOL("has_el3", ARMCPU, has_el3, true);
511
8f325f56
PC
512static Property arm_cpu_has_mpu_property =
513 DEFINE_PROP_BOOL("has-mpu", ARMCPU, has_mpu, true);
514
3281af81
PC
515static Property arm_cpu_pmsav7_dregion_property =
516 DEFINE_PROP_UINT32("pmsav7-dregion", ARMCPU, pmsav7_dregion, 16);
517
07a5b0d2
PC
518static void arm_cpu_post_init(Object *obj)
519{
520 ARMCPU *cpu = ARM_CPU(obj);
07a5b0d2 521
f318cec6
PM
522 if (arm_feature(&cpu->env, ARM_FEATURE_CBAR) ||
523 arm_feature(&cpu->env, ARM_FEATURE_CBAR_RO)) {
07a5b0d2 524 qdev_property_add_static(DEVICE(obj), &arm_cpu_reset_cbar_property,
5433a0a8 525 &error_abort);
07a5b0d2 526 }
68e0a40a
AP
527
528 if (!arm_feature(&cpu->env, ARM_FEATURE_M)) {
529 qdev_property_add_static(DEVICE(obj), &arm_cpu_reset_hivecs_property,
5433a0a8 530 &error_abort);
68e0a40a 531 }
3933443e
PM
532
533 if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
534 qdev_property_add_static(DEVICE(obj), &arm_cpu_rvbar_property,
535 &error_abort);
536 }
51942aee
GB
537
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.
541 */
542 qdev_property_add_static(DEVICE(obj), &arm_cpu_has_el3_property,
543 &error_abort);
9e273ef2
PM
544
545#ifndef CONFIG_USER_ONLY
546 object_property_add_link(obj, "secure-memory",
547 TYPE_MEMORY_REGION,
548 (Object **)&cpu->secure_memory,
549 qdev_prop_allow_set_link_before_realize,
550 OBJ_PROP_LINK_UNREF_ON_RELEASE,
551 &error_abort);
552#endif
51942aee 553 }
8f325f56
PC
554
555 if (arm_feature(&cpu->env, ARM_FEATURE_MPU)) {
556 qdev_property_add_static(DEVICE(obj), &arm_cpu_has_mpu_property,
557 &error_abort);
3281af81
PC
558 if (arm_feature(&cpu->env, ARM_FEATURE_V7)) {
559 qdev_property_add_static(DEVICE(obj),
560 &arm_cpu_pmsav7_dregion_property,
561 &error_abort);
562 }
8f325f56
PC
563 }
564
07a5b0d2
PC
565}
566
4b6a83fb
PM
567static void arm_cpu_finalizefn(Object *obj)
568{
569 ARMCPU *cpu = ARM_CPU(obj);
570 g_hash_table_destroy(cpu->cp_regs);
777dc784
PM
571}
572
14969266 573static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
581be094 574{
14a10fc3 575 CPUState *cs = CPU(dev);
14969266
AF
576 ARMCPU *cpu = ARM_CPU(dev);
577 ARMCPUClass *acc = ARM_CPU_GET_CLASS(dev);
581be094 578 CPUARMState *env = &cpu->env;
14969266 579
581be094 580 /* Some features automatically imply others: */
81e69fb0
MR
581 if (arm_feature(env, ARM_FEATURE_V8)) {
582 set_feature(env, ARM_FEATURE_V7);
583 set_feature(env, ARM_FEATURE_ARM_DIV);
584 set_feature(env, ARM_FEATURE_LPAE);
585 }
581be094
PM
586 if (arm_feature(env, ARM_FEATURE_V7)) {
587 set_feature(env, ARM_FEATURE_VAPA);
588 set_feature(env, ARM_FEATURE_THUMB2);
81bdde9d 589 set_feature(env, ARM_FEATURE_MPIDR);
581be094
PM
590 if (!arm_feature(env, ARM_FEATURE_M)) {
591 set_feature(env, ARM_FEATURE_V6K);
592 } else {
593 set_feature(env, ARM_FEATURE_V6);
594 }
595 }
596 if (arm_feature(env, ARM_FEATURE_V6K)) {
597 set_feature(env, ARM_FEATURE_V6);
598 set_feature(env, ARM_FEATURE_MVFR);
599 }
600 if (arm_feature(env, ARM_FEATURE_V6)) {
601 set_feature(env, ARM_FEATURE_V5);
602 if (!arm_feature(env, ARM_FEATURE_M)) {
603 set_feature(env, ARM_FEATURE_AUXCR);
604 }
605 }
606 if (arm_feature(env, ARM_FEATURE_V5)) {
607 set_feature(env, ARM_FEATURE_V4T);
608 }
609 if (arm_feature(env, ARM_FEATURE_M)) {
610 set_feature(env, ARM_FEATURE_THUMB_DIV);
611 }
612 if (arm_feature(env, ARM_FEATURE_ARM_DIV)) {
613 set_feature(env, ARM_FEATURE_THUMB_DIV);
614 }
615 if (arm_feature(env, ARM_FEATURE_VFP4)) {
616 set_feature(env, ARM_FEATURE_VFP3);
da5141fc 617 set_feature(env, ARM_FEATURE_VFP_FP16);
581be094
PM
618 }
619 if (arm_feature(env, ARM_FEATURE_VFP3)) {
620 set_feature(env, ARM_FEATURE_VFP);
621 }
de9b05b8 622 if (arm_feature(env, ARM_FEATURE_LPAE)) {
bdcc150d 623 set_feature(env, ARM_FEATURE_V7MP);
de9b05b8
PM
624 set_feature(env, ARM_FEATURE_PXN);
625 }
f318cec6
PM
626 if (arm_feature(env, ARM_FEATURE_CBAR_RO)) {
627 set_feature(env, ARM_FEATURE_CBAR);
628 }
62b44f05
AR
629 if (arm_feature(env, ARM_FEATURE_THUMB2) &&
630 !arm_feature(env, ARM_FEATURE_M)) {
631 set_feature(env, ARM_FEATURE_THUMB_DSP);
632 }
2ceb98c0 633
68e0a40a
AP
634 if (cpu->reset_hivecs) {
635 cpu->reset_sctlr |= (1 << 13);
636 }
637
51942aee
GB
638 if (!cpu->has_el3) {
639 /* If the has_el3 CPU property is disabled then we need to disable the
640 * feature.
641 */
642 unset_feature(env, ARM_FEATURE_EL3);
643
644 /* Disable the security extension feature bits in the processor feature
3d5c84ff 645 * registers as well. These are id_pfr1[7:4] and id_aa64pfr0[15:12].
51942aee
GB
646 */
647 cpu->id_pfr1 &= ~0xf0;
3d5c84ff 648 cpu->id_aa64pfr0 &= ~0xf000;
51942aee
GB
649 }
650
3c2f7bb3
PM
651 if (!arm_feature(env, ARM_FEATURE_EL2)) {
652 /* Disable the hypervisor feature bits in the processor feature
653 * registers if we don't have EL2. These are id_pfr1[15:12] and
654 * id_aa64pfr0_el1[11:8].
655 */
656 cpu->id_aa64pfr0 &= ~0xf00;
657 cpu->id_pfr1 &= ~0xf000;
658 }
659
8f325f56
PC
660 if (!cpu->has_mpu) {
661 unset_feature(env, ARM_FEATURE_MPU);
662 }
663
3281af81
PC
664 if (arm_feature(env, ARM_FEATURE_MPU) &&
665 arm_feature(env, ARM_FEATURE_V7)) {
666 uint32_t nr = cpu->pmsav7_dregion;
667
668 if (nr > 0xff) {
9af9e0fe 669 error_setg(errp, "PMSAv7 MPU #regions invalid %" PRIu32, nr);
3281af81
PC
670 return;
671 }
6cb0b013
PC
672
673 if (nr) {
674 env->pmsav7.drbar = g_new0(uint32_t, nr);
675 env->pmsav7.drsr = g_new0(uint32_t, nr);
676 env->pmsav7.dracr = g_new0(uint32_t, nr);
677 }
3281af81
PC
678 }
679
2ceb98c0 680 register_cp_regs_for_features(cpu);
14969266
AF
681 arm_cpu_register_gdb_regs_for_features(cpu);
682
721fae12
PM
683 init_cpreg_list(cpu);
684
9e273ef2
PM
685#ifndef CONFIG_USER_ONLY
686 if (cpu->has_el3) {
687 cs->num_ases = 2;
688 } else {
689 cs->num_ases = 1;
690 }
691
692 if (cpu->has_el3) {
693 AddressSpace *as;
694
695 if (!cpu->secure_memory) {
696 cpu->secure_memory = cs->memory;
697 }
698 as = address_space_init_shareable(cpu->secure_memory,
699 "cpu-secure-memory");
700 cpu_address_space_init(cs, as, ARMASIdx_S);
701 }
702 cpu_address_space_init(cs,
703 address_space_init_shareable(cs->memory,
704 "cpu-memory"),
705 ARMASIdx_NS);
706#endif
707
14a10fc3 708 qemu_init_vcpu(cs);
00d0f7cb 709 cpu_reset(cs);
14969266
AF
710
711 acc->parent_realize(dev, errp);
581be094
PM
712}
713
5900d6b2
AF
714static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
715{
716 ObjectClass *oc;
51492fd1 717 char *typename;
fb8d6c24 718 char **cpuname;
5900d6b2
AF
719
720 if (!cpu_model) {
721 return NULL;
722 }
723
fb8d6c24
GB
724 cpuname = g_strsplit(cpu_model, ",", 1);
725 typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpuname[0]);
51492fd1 726 oc = object_class_by_name(typename);
fb8d6c24 727 g_strfreev(cpuname);
51492fd1 728 g_free(typename);
245fb54d
AF
729 if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
730 object_class_is_abstract(oc)) {
5900d6b2
AF
731 return NULL;
732 }
733 return oc;
734}
735
15ee776b
PM
736/* CPU models. These are not needed for the AArch64 linux-user build. */
737#if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64)
738
777dc784
PM
739static void arm926_initfn(Object *obj)
740{
741 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
742
743 cpu->dtb_compatible = "arm,arm926";
581be094
PM
744 set_feature(&cpu->env, ARM_FEATURE_V5);
745 set_feature(&cpu->env, ARM_FEATURE_VFP);
c4804214
PM
746 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
747 set_feature(&cpu->env, ARM_FEATURE_CACHE_TEST_CLEAN);
b2d06f96 748 cpu->midr = 0x41069265;
325b3cef 749 cpu->reset_fpsid = 0x41011090;
64e1671f 750 cpu->ctr = 0x1dd20d2;
0ca7e01c 751 cpu->reset_sctlr = 0x00090078;
777dc784
PM
752}
753
754static void arm946_initfn(Object *obj)
755{
756 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
757
758 cpu->dtb_compatible = "arm,arm946";
581be094
PM
759 set_feature(&cpu->env, ARM_FEATURE_V5);
760 set_feature(&cpu->env, ARM_FEATURE_MPU);
c4804214 761 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
b2d06f96 762 cpu->midr = 0x41059461;
64e1671f 763 cpu->ctr = 0x0f004006;
0ca7e01c 764 cpu->reset_sctlr = 0x00000078;
777dc784
PM
765}
766
767static void arm1026_initfn(Object *obj)
768{
769 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
770
771 cpu->dtb_compatible = "arm,arm1026";
581be094
PM
772 set_feature(&cpu->env, ARM_FEATURE_V5);
773 set_feature(&cpu->env, ARM_FEATURE_VFP);
774 set_feature(&cpu->env, ARM_FEATURE_AUXCR);
c4804214
PM
775 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
776 set_feature(&cpu->env, ARM_FEATURE_CACHE_TEST_CLEAN);
b2d06f96 777 cpu->midr = 0x4106a262;
325b3cef 778 cpu->reset_fpsid = 0x410110a0;
64e1671f 779 cpu->ctr = 0x1dd20d2;
0ca7e01c 780 cpu->reset_sctlr = 0x00090078;
2771db27 781 cpu->reset_auxcr = 1;
06d76f31
PM
782 {
783 /* The 1026 had an IFAR at c6,c0,0,1 rather than the ARMv6 c6,c0,0,2 */
784 ARMCPRegInfo ifar = {
785 .name = "IFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 1,
786 .access = PL1_RW,
b848ce2b 787 .fieldoffset = offsetof(CPUARMState, cp15.ifar_ns),
06d76f31
PM
788 .resetvalue = 0
789 };
790 define_one_arm_cp_reg(cpu, &ifar);
791 }
777dc784
PM
792}
793
794static void arm1136_r2_initfn(Object *obj)
795{
796 ARMCPU *cpu = ARM_CPU(obj);
2e4d7e3e
PM
797 /* What qemu calls "arm1136_r2" is actually the 1136 r0p2, ie an
798 * older core than plain "arm1136". In particular this does not
799 * have the v6K features.
800 * These ID register values are correct for 1136 but may be wrong
801 * for 1136_r2 (in particular r0p2 does not actually implement most
802 * of the ID registers).
803 */
54d3e3f5
PM
804
805 cpu->dtb_compatible = "arm,arm1136";
581be094
PM
806 set_feature(&cpu->env, ARM_FEATURE_V6);
807 set_feature(&cpu->env, ARM_FEATURE_VFP);
c4804214
PM
808 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
809 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
810 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
b2d06f96 811 cpu->midr = 0x4107b362;
325b3cef 812 cpu->reset_fpsid = 0x410120b4;
bd35c355
PM
813 cpu->mvfr0 = 0x11111111;
814 cpu->mvfr1 = 0x00000000;
64e1671f 815 cpu->ctr = 0x1dd20d2;
0ca7e01c 816 cpu->reset_sctlr = 0x00050078;
2e4d7e3e
PM
817 cpu->id_pfr0 = 0x111;
818 cpu->id_pfr1 = 0x1;
819 cpu->id_dfr0 = 0x2;
820 cpu->id_afr0 = 0x3;
821 cpu->id_mmfr0 = 0x01130003;
822 cpu->id_mmfr1 = 0x10030302;
823 cpu->id_mmfr2 = 0x01222110;
824 cpu->id_isar0 = 0x00140011;
825 cpu->id_isar1 = 0x12002111;
826 cpu->id_isar2 = 0x11231111;
827 cpu->id_isar3 = 0x01102131;
828 cpu->id_isar4 = 0x141;
2771db27 829 cpu->reset_auxcr = 7;
777dc784
PM
830}
831
832static void arm1136_initfn(Object *obj)
833{
834 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
835
836 cpu->dtb_compatible = "arm,arm1136";
581be094
PM
837 set_feature(&cpu->env, ARM_FEATURE_V6K);
838 set_feature(&cpu->env, ARM_FEATURE_V6);
839 set_feature(&cpu->env, ARM_FEATURE_VFP);
c4804214
PM
840 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
841 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
842 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
b2d06f96 843 cpu->midr = 0x4117b363;
325b3cef 844 cpu->reset_fpsid = 0x410120b4;
bd35c355
PM
845 cpu->mvfr0 = 0x11111111;
846 cpu->mvfr1 = 0x00000000;
64e1671f 847 cpu->ctr = 0x1dd20d2;
0ca7e01c 848 cpu->reset_sctlr = 0x00050078;
2e4d7e3e
PM
849 cpu->id_pfr0 = 0x111;
850 cpu->id_pfr1 = 0x1;
851 cpu->id_dfr0 = 0x2;
852 cpu->id_afr0 = 0x3;
853 cpu->id_mmfr0 = 0x01130003;
854 cpu->id_mmfr1 = 0x10030302;
855 cpu->id_mmfr2 = 0x01222110;
856 cpu->id_isar0 = 0x00140011;
857 cpu->id_isar1 = 0x12002111;
858 cpu->id_isar2 = 0x11231111;
859 cpu->id_isar3 = 0x01102131;
860 cpu->id_isar4 = 0x141;
2771db27 861 cpu->reset_auxcr = 7;
777dc784
PM
862}
863
864static void arm1176_initfn(Object *obj)
865{
866 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
867
868 cpu->dtb_compatible = "arm,arm1176";
581be094
PM
869 set_feature(&cpu->env, ARM_FEATURE_V6K);
870 set_feature(&cpu->env, ARM_FEATURE_VFP);
871 set_feature(&cpu->env, ARM_FEATURE_VAPA);
c4804214
PM
872 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
873 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
874 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
c0ccb02d 875 set_feature(&cpu->env, ARM_FEATURE_EL3);
b2d06f96 876 cpu->midr = 0x410fb767;
325b3cef 877 cpu->reset_fpsid = 0x410120b5;
bd35c355
PM
878 cpu->mvfr0 = 0x11111111;
879 cpu->mvfr1 = 0x00000000;
64e1671f 880 cpu->ctr = 0x1dd20d2;
0ca7e01c 881 cpu->reset_sctlr = 0x00050078;
2e4d7e3e
PM
882 cpu->id_pfr0 = 0x111;
883 cpu->id_pfr1 = 0x11;
884 cpu->id_dfr0 = 0x33;
885 cpu->id_afr0 = 0;
886 cpu->id_mmfr0 = 0x01130003;
887 cpu->id_mmfr1 = 0x10030302;
888 cpu->id_mmfr2 = 0x01222100;
889 cpu->id_isar0 = 0x0140011;
890 cpu->id_isar1 = 0x12002111;
891 cpu->id_isar2 = 0x11231121;
892 cpu->id_isar3 = 0x01102131;
893 cpu->id_isar4 = 0x01141;
2771db27 894 cpu->reset_auxcr = 7;
777dc784
PM
895}
896
897static void arm11mpcore_initfn(Object *obj)
898{
899 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
900
901 cpu->dtb_compatible = "arm,arm11mpcore";
581be094
PM
902 set_feature(&cpu->env, ARM_FEATURE_V6K);
903 set_feature(&cpu->env, ARM_FEATURE_VFP);
904 set_feature(&cpu->env, ARM_FEATURE_VAPA);
81bdde9d 905 set_feature(&cpu->env, ARM_FEATURE_MPIDR);
c4804214 906 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
b2d06f96 907 cpu->midr = 0x410fb022;
325b3cef 908 cpu->reset_fpsid = 0x410120b4;
bd35c355
PM
909 cpu->mvfr0 = 0x11111111;
910 cpu->mvfr1 = 0x00000000;
200bf596 911 cpu->ctr = 0x1d192992; /* 32K icache 32K dcache */
2e4d7e3e
PM
912 cpu->id_pfr0 = 0x111;
913 cpu->id_pfr1 = 0x1;
914 cpu->id_dfr0 = 0;
915 cpu->id_afr0 = 0x2;
916 cpu->id_mmfr0 = 0x01100103;
917 cpu->id_mmfr1 = 0x10020302;
918 cpu->id_mmfr2 = 0x01222000;
919 cpu->id_isar0 = 0x00100011;
920 cpu->id_isar1 = 0x12002111;
921 cpu->id_isar2 = 0x11221011;
922 cpu->id_isar3 = 0x01102131;
923 cpu->id_isar4 = 0x141;
2771db27 924 cpu->reset_auxcr = 1;
777dc784
PM
925}
926
927static void cortex_m3_initfn(Object *obj)
928{
929 ARMCPU *cpu = ARM_CPU(obj);
581be094
PM
930 set_feature(&cpu->env, ARM_FEATURE_V7);
931 set_feature(&cpu->env, ARM_FEATURE_M);
b2d06f96 932 cpu->midr = 0x410fc231;
777dc784
PM
933}
934
ba890a9b
AR
935static void cortex_m4_initfn(Object *obj)
936{
937 ARMCPU *cpu = ARM_CPU(obj);
938
939 set_feature(&cpu->env, ARM_FEATURE_V7);
940 set_feature(&cpu->env, ARM_FEATURE_M);
941 set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP);
942 cpu->midr = 0x410fc240; /* r0p0 */
943}
e6f010cc
AF
944static void arm_v7m_class_init(ObjectClass *oc, void *data)
945{
e6f010cc
AF
946 CPUClass *cc = CPU_CLASS(oc);
947
b5c633c5 948#ifndef CONFIG_USER_ONLY
e6f010cc
AF
949 cc->do_interrupt = arm_v7m_cpu_do_interrupt;
950#endif
b5c633c5
PM
951
952 cc->cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt;
e6f010cc
AF
953}
954
d6a6b13e
PC
955static const ARMCPRegInfo cortexr5_cp_reginfo[] = {
956 /* Dummy the TCM region regs for the moment */
957 { .name = "ATCM", .cp = 15, .opc1 = 0, .crn = 9, .crm = 1, .opc2 = 0,
958 .access = PL1_RW, .type = ARM_CP_CONST },
959 { .name = "BTCM", .cp = 15, .opc1 = 0, .crn = 9, .crm = 1, .opc2 = 1,
960 .access = PL1_RW, .type = ARM_CP_CONST },
961 REGINFO_SENTINEL
962};
963
964static void cortex_r5_initfn(Object *obj)
965{
966 ARMCPU *cpu = ARM_CPU(obj);
967
968 set_feature(&cpu->env, ARM_FEATURE_V7);
969 set_feature(&cpu->env, ARM_FEATURE_THUMB_DIV);
970 set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);
971 set_feature(&cpu->env, ARM_FEATURE_V7MP);
972 set_feature(&cpu->env, ARM_FEATURE_MPU);
973 cpu->midr = 0x411fc153; /* r1p3 */
974 cpu->id_pfr0 = 0x0131;
975 cpu->id_pfr1 = 0x001;
976 cpu->id_dfr0 = 0x010400;
977 cpu->id_afr0 = 0x0;
978 cpu->id_mmfr0 = 0x0210030;
979 cpu->id_mmfr1 = 0x00000000;
980 cpu->id_mmfr2 = 0x01200000;
981 cpu->id_mmfr3 = 0x0211;
982 cpu->id_isar0 = 0x2101111;
983 cpu->id_isar1 = 0x13112111;
984 cpu->id_isar2 = 0x21232141;
985 cpu->id_isar3 = 0x01112131;
986 cpu->id_isar4 = 0x0010142;
987 cpu->id_isar5 = 0x0;
988 cpu->mp_is_up = true;
989 define_arm_cp_regs(cpu, cortexr5_cp_reginfo);
990}
991
34f90529
PM
992static const ARMCPRegInfo cortexa8_cp_reginfo[] = {
993 { .name = "L2LOCKDOWN", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 0,
994 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
995 { .name = "L2AUXCR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 2,
996 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
997 REGINFO_SENTINEL
998};
999
777dc784
PM
1000static void cortex_a8_initfn(Object *obj)
1001{
1002 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1003
1004 cpu->dtb_compatible = "arm,cortex-a8";
581be094
PM
1005 set_feature(&cpu->env, ARM_FEATURE_V7);
1006 set_feature(&cpu->env, ARM_FEATURE_VFP3);
1007 set_feature(&cpu->env, ARM_FEATURE_NEON);
1008 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
c4804214 1009 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
c0ccb02d 1010 set_feature(&cpu->env, ARM_FEATURE_EL3);
b2d06f96 1011 cpu->midr = 0x410fc080;
325b3cef 1012 cpu->reset_fpsid = 0x410330c0;
bd35c355
PM
1013 cpu->mvfr0 = 0x11110222;
1014 cpu->mvfr1 = 0x00011100;
64e1671f 1015 cpu->ctr = 0x82048004;
0ca7e01c 1016 cpu->reset_sctlr = 0x00c50078;
2e4d7e3e
PM
1017 cpu->id_pfr0 = 0x1031;
1018 cpu->id_pfr1 = 0x11;
1019 cpu->id_dfr0 = 0x400;
1020 cpu->id_afr0 = 0;
1021 cpu->id_mmfr0 = 0x31100003;
1022 cpu->id_mmfr1 = 0x20000000;
1023 cpu->id_mmfr2 = 0x01202000;
1024 cpu->id_mmfr3 = 0x11;
1025 cpu->id_isar0 = 0x00101111;
1026 cpu->id_isar1 = 0x12112111;
1027 cpu->id_isar2 = 0x21232031;
1028 cpu->id_isar3 = 0x11112131;
1029 cpu->id_isar4 = 0x00111142;
48eb3ae6 1030 cpu->dbgdidr = 0x15141000;
85df3786
PM
1031 cpu->clidr = (1 << 27) | (2 << 24) | 3;
1032 cpu->ccsidr[0] = 0xe007e01a; /* 16k L1 dcache. */
1033 cpu->ccsidr[1] = 0x2007e01a; /* 16k L1 icache. */
1034 cpu->ccsidr[2] = 0xf0000000; /* No L2 icache. */
2771db27 1035 cpu->reset_auxcr = 2;
34f90529 1036 define_arm_cp_regs(cpu, cortexa8_cp_reginfo);
777dc784
PM
1037}
1038
1047b9d7
PM
1039static const ARMCPRegInfo cortexa9_cp_reginfo[] = {
1040 /* power_control should be set to maximum latency. Again,
1041 * default to 0 and set by private hook
1042 */
1043 { .name = "A9_PWRCTL", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 0,
1044 .access = PL1_RW, .resetvalue = 0,
1045 .fieldoffset = offsetof(CPUARMState, cp15.c15_power_control) },
1046 { .name = "A9_DIAG", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 1,
1047 .access = PL1_RW, .resetvalue = 0,
1048 .fieldoffset = offsetof(CPUARMState, cp15.c15_diagnostic) },
1049 { .name = "A9_PWRDIAG", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 2,
1050 .access = PL1_RW, .resetvalue = 0,
1051 .fieldoffset = offsetof(CPUARMState, cp15.c15_power_diagnostic) },
1052 { .name = "NEONBUSY", .cp = 15, .crn = 15, .crm = 1, .opc1 = 0, .opc2 = 0,
1053 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
1054 /* TLB lockdown control */
1055 { .name = "TLB_LOCKR", .cp = 15, .crn = 15, .crm = 4, .opc1 = 5, .opc2 = 2,
1056 .access = PL1_W, .resetvalue = 0, .type = ARM_CP_NOP },
1057 { .name = "TLB_LOCKW", .cp = 15, .crn = 15, .crm = 4, .opc1 = 5, .opc2 = 4,
1058 .access = PL1_W, .resetvalue = 0, .type = ARM_CP_NOP },
1059 { .name = "TLB_VA", .cp = 15, .crn = 15, .crm = 5, .opc1 = 5, .opc2 = 2,
1060 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
1061 { .name = "TLB_PA", .cp = 15, .crn = 15, .crm = 6, .opc1 = 5, .opc2 = 2,
1062 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
1063 { .name = "TLB_ATTR", .cp = 15, .crn = 15, .crm = 7, .opc1 = 5, .opc2 = 2,
1064 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
1065 REGINFO_SENTINEL
1066};
1067
777dc784
PM
1068static void cortex_a9_initfn(Object *obj)
1069{
1070 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1071
1072 cpu->dtb_compatible = "arm,cortex-a9";
581be094
PM
1073 set_feature(&cpu->env, ARM_FEATURE_V7);
1074 set_feature(&cpu->env, ARM_FEATURE_VFP3);
1075 set_feature(&cpu->env, ARM_FEATURE_VFP_FP16);
1076 set_feature(&cpu->env, ARM_FEATURE_NEON);
1077 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
c0ccb02d 1078 set_feature(&cpu->env, ARM_FEATURE_EL3);
581be094
PM
1079 /* Note that A9 supports the MP extensions even for
1080 * A9UP and single-core A9MP (which are both different
1081 * and valid configurations; we don't model A9UP).
1082 */
1083 set_feature(&cpu->env, ARM_FEATURE_V7MP);
d8ba780b 1084 set_feature(&cpu->env, ARM_FEATURE_CBAR);
b2d06f96 1085 cpu->midr = 0x410fc090;
325b3cef 1086 cpu->reset_fpsid = 0x41033090;
bd35c355
PM
1087 cpu->mvfr0 = 0x11110222;
1088 cpu->mvfr1 = 0x01111111;
64e1671f 1089 cpu->ctr = 0x80038003;
0ca7e01c 1090 cpu->reset_sctlr = 0x00c50078;
2e4d7e3e
PM
1091 cpu->id_pfr0 = 0x1031;
1092 cpu->id_pfr1 = 0x11;
1093 cpu->id_dfr0 = 0x000;
1094 cpu->id_afr0 = 0;
1095 cpu->id_mmfr0 = 0x00100103;
1096 cpu->id_mmfr1 = 0x20000000;
1097 cpu->id_mmfr2 = 0x01230000;
1098 cpu->id_mmfr3 = 0x00002111;
1099 cpu->id_isar0 = 0x00101111;
1100 cpu->id_isar1 = 0x13112111;
1101 cpu->id_isar2 = 0x21232041;
1102 cpu->id_isar3 = 0x11112131;
1103 cpu->id_isar4 = 0x00111142;
48eb3ae6 1104 cpu->dbgdidr = 0x35141000;
85df3786 1105 cpu->clidr = (1 << 27) | (1 << 24) | 3;
f7838b52
PC
1106 cpu->ccsidr[0] = 0xe00fe019; /* 16k L1 dcache. */
1107 cpu->ccsidr[1] = 0x200fe019; /* 16k L1 icache. */
d8ba780b 1108 define_arm_cp_regs(cpu, cortexa9_cp_reginfo);
777dc784
PM
1109}
1110
34f90529 1111#ifndef CONFIG_USER_ONLY
c4241c7d 1112static uint64_t a15_l2ctlr_read(CPUARMState *env, const ARMCPRegInfo *ri)
34f90529
PM
1113{
1114 /* Linux wants the number of processors from here.
1115 * Might as well set the interrupt-controller bit too.
1116 */
c4241c7d 1117 return ((smp_cpus - 1) << 24) | (1 << 23);
34f90529
PM
1118}
1119#endif
1120
1121static const ARMCPRegInfo cortexa15_cp_reginfo[] = {
1122#ifndef CONFIG_USER_ONLY
1123 { .name = "L2CTLR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 2,
1124 .access = PL1_RW, .resetvalue = 0, .readfn = a15_l2ctlr_read,
1125 .writefn = arm_cp_write_ignore, },
1126#endif
1127 { .name = "L2ECTLR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 3,
1128 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
1129 REGINFO_SENTINEL
1130};
1131
dcf578ed
AY
1132static void cortex_a7_initfn(Object *obj)
1133{
1134 ARMCPU *cpu = ARM_CPU(obj);
1135
1136 cpu->dtb_compatible = "arm,cortex-a7";
1137 set_feature(&cpu->env, ARM_FEATURE_V7);
1138 set_feature(&cpu->env, ARM_FEATURE_VFP4);
1139 set_feature(&cpu->env, ARM_FEATURE_NEON);
1140 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
1141 set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);
1142 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
1143 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
1144 set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
1145 set_feature(&cpu->env, ARM_FEATURE_LPAE);
1146 set_feature(&cpu->env, ARM_FEATURE_EL3);
1147 cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A7;
1148 cpu->midr = 0x410fc075;
1149 cpu->reset_fpsid = 0x41023075;
1150 cpu->mvfr0 = 0x10110222;
1151 cpu->mvfr1 = 0x11111111;
1152 cpu->ctr = 0x84448003;
1153 cpu->reset_sctlr = 0x00c50078;
1154 cpu->id_pfr0 = 0x00001131;
1155 cpu->id_pfr1 = 0x00011011;
1156 cpu->id_dfr0 = 0x02010555;
1157 cpu->pmceid0 = 0x00000000;
1158 cpu->pmceid1 = 0x00000000;
1159 cpu->id_afr0 = 0x00000000;
1160 cpu->id_mmfr0 = 0x10101105;
1161 cpu->id_mmfr1 = 0x40000000;
1162 cpu->id_mmfr2 = 0x01240000;
1163 cpu->id_mmfr3 = 0x02102211;
1164 cpu->id_isar0 = 0x01101110;
1165 cpu->id_isar1 = 0x13112111;
1166 cpu->id_isar2 = 0x21232041;
1167 cpu->id_isar3 = 0x11112131;
1168 cpu->id_isar4 = 0x10011142;
1169 cpu->dbgdidr = 0x3515f005;
1170 cpu->clidr = 0x0a200023;
1171 cpu->ccsidr[0] = 0x701fe00a; /* 32K L1 dcache */
1172 cpu->ccsidr[1] = 0x201fe00a; /* 32K L1 icache */
1173 cpu->ccsidr[2] = 0x711fe07a; /* 4096K L2 unified cache */
1174 define_arm_cp_regs(cpu, cortexa15_cp_reginfo); /* Same as A15 */
1175}
1176
777dc784
PM
1177static void cortex_a15_initfn(Object *obj)
1178{
1179 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1180
1181 cpu->dtb_compatible = "arm,cortex-a15";
581be094
PM
1182 set_feature(&cpu->env, ARM_FEATURE_V7);
1183 set_feature(&cpu->env, ARM_FEATURE_VFP4);
581be094
PM
1184 set_feature(&cpu->env, ARM_FEATURE_NEON);
1185 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
1186 set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);
581be094 1187 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
c4804214 1188 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
c29f9a0a 1189 set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
de9b05b8 1190 set_feature(&cpu->env, ARM_FEATURE_LPAE);
c0ccb02d 1191 set_feature(&cpu->env, ARM_FEATURE_EL3);
3541addc 1192 cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A15;
b2d06f96 1193 cpu->midr = 0x412fc0f1;
325b3cef 1194 cpu->reset_fpsid = 0x410430f0;
bd35c355
PM
1195 cpu->mvfr0 = 0x10110222;
1196 cpu->mvfr1 = 0x11111111;
64e1671f 1197 cpu->ctr = 0x8444c004;
0ca7e01c 1198 cpu->reset_sctlr = 0x00c50078;
2e4d7e3e
PM
1199 cpu->id_pfr0 = 0x00001131;
1200 cpu->id_pfr1 = 0x00011011;
1201 cpu->id_dfr0 = 0x02010555;
4054bfa9
AF
1202 cpu->pmceid0 = 0x0000000;
1203 cpu->pmceid1 = 0x00000000;
2e4d7e3e
PM
1204 cpu->id_afr0 = 0x00000000;
1205 cpu->id_mmfr0 = 0x10201105;
1206 cpu->id_mmfr1 = 0x20000000;
1207 cpu->id_mmfr2 = 0x01240000;
1208 cpu->id_mmfr3 = 0x02102211;
1209 cpu->id_isar0 = 0x02101110;
1210 cpu->id_isar1 = 0x13112111;
1211 cpu->id_isar2 = 0x21232041;
1212 cpu->id_isar3 = 0x11112131;
1213 cpu->id_isar4 = 0x10011142;
48eb3ae6 1214 cpu->dbgdidr = 0x3515f021;
85df3786
PM
1215 cpu->clidr = 0x0a200023;
1216 cpu->ccsidr[0] = 0x701fe00a; /* 32K L1 dcache */
1217 cpu->ccsidr[1] = 0x201fe00a; /* 32K L1 icache */
1218 cpu->ccsidr[2] = 0x711fe07a; /* 4096K L2 unified cache */
34f90529 1219 define_arm_cp_regs(cpu, cortexa15_cp_reginfo);
777dc784
PM
1220}
1221
1222static void ti925t_initfn(Object *obj)
1223{
1224 ARMCPU *cpu = ARM_CPU(obj);
581be094
PM
1225 set_feature(&cpu->env, ARM_FEATURE_V4T);
1226 set_feature(&cpu->env, ARM_FEATURE_OMAPCP);
777dc784 1227 cpu->midr = ARM_CPUID_TI925T;
64e1671f 1228 cpu->ctr = 0x5109149;
0ca7e01c 1229 cpu->reset_sctlr = 0x00000070;
777dc784
PM
1230}
1231
1232static void sa1100_initfn(Object *obj)
1233{
1234 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1235
1236 cpu->dtb_compatible = "intel,sa1100";
581be094 1237 set_feature(&cpu->env, ARM_FEATURE_STRONGARM);
c4804214 1238 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
b2d06f96 1239 cpu->midr = 0x4401A11B;
0ca7e01c 1240 cpu->reset_sctlr = 0x00000070;
777dc784
PM
1241}
1242
1243static void sa1110_initfn(Object *obj)
1244{
1245 ARMCPU *cpu = ARM_CPU(obj);
581be094 1246 set_feature(&cpu->env, ARM_FEATURE_STRONGARM);
c4804214 1247 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
b2d06f96 1248 cpu->midr = 0x6901B119;
0ca7e01c 1249 cpu->reset_sctlr = 0x00000070;
777dc784
PM
1250}
1251
1252static void pxa250_initfn(Object *obj)
1253{
1254 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1255
1256 cpu->dtb_compatible = "marvell,xscale";
581be094
PM
1257 set_feature(&cpu->env, ARM_FEATURE_V5);
1258 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
b2d06f96 1259 cpu->midr = 0x69052100;
64e1671f 1260 cpu->ctr = 0xd172172;
0ca7e01c 1261 cpu->reset_sctlr = 0x00000078;
777dc784
PM
1262}
1263
1264static void pxa255_initfn(Object *obj)
1265{
1266 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1267
1268 cpu->dtb_compatible = "marvell,xscale";
581be094
PM
1269 set_feature(&cpu->env, ARM_FEATURE_V5);
1270 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
b2d06f96 1271 cpu->midr = 0x69052d00;
64e1671f 1272 cpu->ctr = 0xd172172;
0ca7e01c 1273 cpu->reset_sctlr = 0x00000078;
777dc784
PM
1274}
1275
1276static void pxa260_initfn(Object *obj)
1277{
1278 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1279
1280 cpu->dtb_compatible = "marvell,xscale";
581be094
PM
1281 set_feature(&cpu->env, ARM_FEATURE_V5);
1282 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
b2d06f96 1283 cpu->midr = 0x69052903;
64e1671f 1284 cpu->ctr = 0xd172172;
0ca7e01c 1285 cpu->reset_sctlr = 0x00000078;
777dc784
PM
1286}
1287
1288static void pxa261_initfn(Object *obj)
1289{
1290 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1291
1292 cpu->dtb_compatible = "marvell,xscale";
581be094
PM
1293 set_feature(&cpu->env, ARM_FEATURE_V5);
1294 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
b2d06f96 1295 cpu->midr = 0x69052d05;
64e1671f 1296 cpu->ctr = 0xd172172;
0ca7e01c 1297 cpu->reset_sctlr = 0x00000078;
777dc784
PM
1298}
1299
1300static void pxa262_initfn(Object *obj)
1301{
1302 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1303
1304 cpu->dtb_compatible = "marvell,xscale";
581be094
PM
1305 set_feature(&cpu->env, ARM_FEATURE_V5);
1306 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
b2d06f96 1307 cpu->midr = 0x69052d06;
64e1671f 1308 cpu->ctr = 0xd172172;
0ca7e01c 1309 cpu->reset_sctlr = 0x00000078;
777dc784
PM
1310}
1311
1312static void pxa270a0_initfn(Object *obj)
1313{
1314 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1315
1316 cpu->dtb_compatible = "marvell,xscale";
581be094
PM
1317 set_feature(&cpu->env, ARM_FEATURE_V5);
1318 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1319 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
b2d06f96 1320 cpu->midr = 0x69054110;
64e1671f 1321 cpu->ctr = 0xd172172;
0ca7e01c 1322 cpu->reset_sctlr = 0x00000078;
777dc784
PM
1323}
1324
1325static void pxa270a1_initfn(Object *obj)
1326{
1327 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1328
1329 cpu->dtb_compatible = "marvell,xscale";
581be094
PM
1330 set_feature(&cpu->env, ARM_FEATURE_V5);
1331 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1332 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
b2d06f96 1333 cpu->midr = 0x69054111;
64e1671f 1334 cpu->ctr = 0xd172172;
0ca7e01c 1335 cpu->reset_sctlr = 0x00000078;
777dc784
PM
1336}
1337
1338static void pxa270b0_initfn(Object *obj)
1339{
1340 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1341
1342 cpu->dtb_compatible = "marvell,xscale";
581be094
PM
1343 set_feature(&cpu->env, ARM_FEATURE_V5);
1344 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1345 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
b2d06f96 1346 cpu->midr = 0x69054112;
64e1671f 1347 cpu->ctr = 0xd172172;
0ca7e01c 1348 cpu->reset_sctlr = 0x00000078;
777dc784
PM
1349}
1350
1351static void pxa270b1_initfn(Object *obj)
1352{
1353 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1354
1355 cpu->dtb_compatible = "marvell,xscale";
581be094
PM
1356 set_feature(&cpu->env, ARM_FEATURE_V5);
1357 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1358 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
b2d06f96 1359 cpu->midr = 0x69054113;
64e1671f 1360 cpu->ctr = 0xd172172;
0ca7e01c 1361 cpu->reset_sctlr = 0x00000078;
777dc784
PM
1362}
1363
1364static void pxa270c0_initfn(Object *obj)
1365{
1366 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1367
1368 cpu->dtb_compatible = "marvell,xscale";
581be094
PM
1369 set_feature(&cpu->env, ARM_FEATURE_V5);
1370 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1371 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
b2d06f96 1372 cpu->midr = 0x69054114;
64e1671f 1373 cpu->ctr = 0xd172172;
0ca7e01c 1374 cpu->reset_sctlr = 0x00000078;
777dc784
PM
1375}
1376
1377static void pxa270c5_initfn(Object *obj)
1378{
1379 ARMCPU *cpu = ARM_CPU(obj);
54d3e3f5
PM
1380
1381 cpu->dtb_compatible = "marvell,xscale";
581be094
PM
1382 set_feature(&cpu->env, ARM_FEATURE_V5);
1383 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1384 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
b2d06f96 1385 cpu->midr = 0x69054117;
64e1671f 1386 cpu->ctr = 0xd172172;
0ca7e01c 1387 cpu->reset_sctlr = 0x00000078;
777dc784
PM
1388}
1389
f5f6d38b 1390#ifdef CONFIG_USER_ONLY
777dc784
PM
1391static void arm_any_initfn(Object *obj)
1392{
1393 ARMCPU *cpu = ARM_CPU(obj);
81e69fb0 1394 set_feature(&cpu->env, ARM_FEATURE_V8);
581be094 1395 set_feature(&cpu->env, ARM_FEATURE_VFP4);
581be094
PM
1396 set_feature(&cpu->env, ARM_FEATURE_NEON);
1397 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
25f748e3
PM
1398 set_feature(&cpu->env, ARM_FEATURE_V8_AES);
1399 set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
1400 set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
1401 set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
eb0ecd5a 1402 set_feature(&cpu->env, ARM_FEATURE_CRC);
b2d06f96 1403 cpu->midr = 0xffffffff;
777dc784 1404}
f5f6d38b 1405#endif
777dc784 1406
15ee776b
PM
1407#endif /* !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64) */
1408
777dc784
PM
1409typedef struct ARMCPUInfo {
1410 const char *name;
1411 void (*initfn)(Object *obj);
e6f010cc 1412 void (*class_init)(ObjectClass *oc, void *data);
777dc784
PM
1413} ARMCPUInfo;
1414
1415static const ARMCPUInfo arm_cpus[] = {
15ee776b 1416#if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64)
777dc784
PM
1417 { .name = "arm926", .initfn = arm926_initfn },
1418 { .name = "arm946", .initfn = arm946_initfn },
1419 { .name = "arm1026", .initfn = arm1026_initfn },
1420 /* What QEMU calls "arm1136-r2" is actually the 1136 r0p2, i.e. an
1421 * older core than plain "arm1136". In particular this does not
1422 * have the v6K features.
1423 */
1424 { .name = "arm1136-r2", .initfn = arm1136_r2_initfn },
1425 { .name = "arm1136", .initfn = arm1136_initfn },
1426 { .name = "arm1176", .initfn = arm1176_initfn },
1427 { .name = "arm11mpcore", .initfn = arm11mpcore_initfn },
e6f010cc
AF
1428 { .name = "cortex-m3", .initfn = cortex_m3_initfn,
1429 .class_init = arm_v7m_class_init },
ba890a9b
AR
1430 { .name = "cortex-m4", .initfn = cortex_m4_initfn,
1431 .class_init = arm_v7m_class_init },
d6a6b13e 1432 { .name = "cortex-r5", .initfn = cortex_r5_initfn },
dcf578ed 1433 { .name = "cortex-a7", .initfn = cortex_a7_initfn },
777dc784
PM
1434 { .name = "cortex-a8", .initfn = cortex_a8_initfn },
1435 { .name = "cortex-a9", .initfn = cortex_a9_initfn },
1436 { .name = "cortex-a15", .initfn = cortex_a15_initfn },
1437 { .name = "ti925t", .initfn = ti925t_initfn },
1438 { .name = "sa1100", .initfn = sa1100_initfn },
1439 { .name = "sa1110", .initfn = sa1110_initfn },
1440 { .name = "pxa250", .initfn = pxa250_initfn },
1441 { .name = "pxa255", .initfn = pxa255_initfn },
1442 { .name = "pxa260", .initfn = pxa260_initfn },
1443 { .name = "pxa261", .initfn = pxa261_initfn },
1444 { .name = "pxa262", .initfn = pxa262_initfn },
1445 /* "pxa270" is an alias for "pxa270-a0" */
1446 { .name = "pxa270", .initfn = pxa270a0_initfn },
1447 { .name = "pxa270-a0", .initfn = pxa270a0_initfn },
1448 { .name = "pxa270-a1", .initfn = pxa270a1_initfn },
1449 { .name = "pxa270-b0", .initfn = pxa270b0_initfn },
1450 { .name = "pxa270-b1", .initfn = pxa270b1_initfn },
1451 { .name = "pxa270-c0", .initfn = pxa270c0_initfn },
1452 { .name = "pxa270-c5", .initfn = pxa270c5_initfn },
f5f6d38b 1453#ifdef CONFIG_USER_ONLY
777dc784 1454 { .name = "any", .initfn = arm_any_initfn },
f5f6d38b 1455#endif
15ee776b 1456#endif
83e6813a 1457 { .name = NULL }
777dc784
PM
1458};
1459
5de16430
PM
1460static Property arm_cpu_properties[] = {
1461 DEFINE_PROP_BOOL("start-powered-off", ARMCPU, start_powered_off, false),
98128601 1462 DEFINE_PROP_UINT32("psci-conduit", ARMCPU, psci_conduit, 0),
51a9b04b 1463 DEFINE_PROP_UINT32("midr", ARMCPU, midr, 0),
15a21fe0 1464 DEFINE_PROP_UINT64("mp-affinity", ARMCPU, mp_affinity, 0),
5de16430
PM
1465 DEFINE_PROP_END_OF_LIST()
1466};
1467
8c6084bf
PM
1468#ifdef CONFIG_USER_ONLY
1469static int arm_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
1470 int mmu_idx)
1471{
1472 ARMCPU *cpu = ARM_CPU(cs);
1473 CPUARMState *env = &cpu->env;
1474
1475 env->exception.vaddress = address;
1476 if (rw == 2) {
1477 cs->exception_index = EXCP_PREFETCH_ABORT;
1478 } else {
1479 cs->exception_index = EXCP_DATA_ABORT;
1480 }
1481 return 1;
1482}
1483#endif
1484
b3820e6c
DH
1485static gchar *arm_gdb_arch_name(CPUState *cs)
1486{
1487 ARMCPU *cpu = ARM_CPU(cs);
1488 CPUARMState *env = &cpu->env;
1489
1490 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
1491 return g_strdup("iwmmxt");
1492 }
1493 return g_strdup("arm");
1494}
1495
dec9c2d4
AF
1496static void arm_cpu_class_init(ObjectClass *oc, void *data)
1497{
1498 ARMCPUClass *acc = ARM_CPU_CLASS(oc);
1499 CPUClass *cc = CPU_CLASS(acc);
14969266
AF
1500 DeviceClass *dc = DEVICE_CLASS(oc);
1501
1502 acc->parent_realize = dc->realize;
1503 dc->realize = arm_cpu_realizefn;
5de16430 1504 dc->props = arm_cpu_properties;
dec9c2d4
AF
1505
1506 acc->parent_reset = cc->reset;
1507 cc->reset = arm_cpu_reset;
5900d6b2
AF
1508
1509 cc->class_by_name = arm_cpu_class_by_name;
8c2e1b00 1510 cc->has_work = arm_cpu_has_work;
e8925712 1511 cc->cpu_exec_interrupt = arm_cpu_exec_interrupt;
878096ee 1512 cc->dump_state = arm_cpu_dump_state;
f45748f1 1513 cc->set_pc = arm_cpu_set_pc;
5b50e790
AF
1514 cc->gdb_read_register = arm_cpu_gdb_read_register;
1515 cc->gdb_write_register = arm_cpu_gdb_write_register;
7510454e
AF
1516#ifdef CONFIG_USER_ONLY
1517 cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;
1518#else
0adf7d3c 1519 cc->do_interrupt = arm_cpu_do_interrupt;
30901475 1520 cc->do_unaligned_access = arm_cpu_do_unaligned_access;
0faea0c7 1521 cc->get_phys_page_attrs_debug = arm_cpu_get_phys_page_attrs_debug;
017518c1 1522 cc->asidx_from_attrs = arm_asidx_from_attrs;
00b941e5 1523 cc->vmsd = &vmstate_arm_cpu;
ed50ff78 1524 cc->virtio_is_big_endian = arm_cpu_virtio_is_big_endian;
da2b9140
AJ
1525 cc->write_elf64_note = arm_cpu_write_elf64_note;
1526 cc->write_elf32_note = arm_cpu_write_elf32_note;
00b941e5 1527#endif
a0e372f0 1528 cc->gdb_num_core_regs = 26;
5b24c641 1529 cc->gdb_core_xml_file = "arm-core.xml";
b3820e6c 1530 cc->gdb_arch_name = arm_gdb_arch_name;
2472b6c0 1531 cc->gdb_stop_before_watchpoint = true;
3ff6fc91 1532 cc->debug_excp_handler = arm_debug_excp_handler;
3826121d 1533 cc->debug_check_watchpoint = arm_debug_check_watchpoint;
48440620
PC
1534
1535 cc->disas_set_info = arm_disas_set_info;
4c315c27
MA
1536
1537 /*
1538 * Reason: arm_cpu_initfn() calls cpu_exec_init(), which saves
1539 * the object in cpus -> dangling pointer after final
1540 * object_unref().
1541 *
1542 * Once this is fixed, the devices that create ARM CPUs should be
1543 * updated not to set cannot_destroy_with_object_finalize_yet,
1544 * unless they still screw up something else.
1545 */
1546 dc->cannot_destroy_with_object_finalize_yet = true;
dec9c2d4
AF
1547}
1548
777dc784
PM
1549static void cpu_register(const ARMCPUInfo *info)
1550{
1551 TypeInfo type_info = {
777dc784
PM
1552 .parent = TYPE_ARM_CPU,
1553 .instance_size = sizeof(ARMCPU),
1554 .instance_init = info->initfn,
1555 .class_size = sizeof(ARMCPUClass),
e6f010cc 1556 .class_init = info->class_init,
777dc784
PM
1557 };
1558
51492fd1 1559 type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
918fd083 1560 type_register(&type_info);
51492fd1 1561 g_free((void *)type_info.name);
777dc784
PM
1562}
1563
dec9c2d4
AF
1564static const TypeInfo arm_cpu_type_info = {
1565 .name = TYPE_ARM_CPU,
1566 .parent = TYPE_CPU,
1567 .instance_size = sizeof(ARMCPU),
777dc784 1568 .instance_init = arm_cpu_initfn,
07a5b0d2 1569 .instance_post_init = arm_cpu_post_init,
4b6a83fb 1570 .instance_finalize = arm_cpu_finalizefn,
777dc784 1571 .abstract = true,
dec9c2d4
AF
1572 .class_size = sizeof(ARMCPUClass),
1573 .class_init = arm_cpu_class_init,
1574};
1575
1576static void arm_cpu_register_types(void)
1577{
83e6813a 1578 const ARMCPUInfo *info = arm_cpus;
777dc784 1579
dec9c2d4 1580 type_register_static(&arm_cpu_type_info);
83e6813a
PM
1581
1582 while (info->name) {
1583 cpu_register(info);
1584 info++;
777dc784 1585 }
dec9c2d4
AF
1586}
1587
1588type_init(arm_cpu_register_types)