]> git.proxmox.com Git - mirror_qemu.git/blob - target-arm/cpu.c
target-arm: Add the Hypervisor timer
[mirror_qemu.git] / target-arm / cpu.c
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
21 #include "cpu.h"
22 #include "internals.h"
23 #include "qemu-common.h"
24 #include "hw/qdev-properties.h"
25 #if !defined(CONFIG_USER_ONLY)
26 #include "hw/loader.h"
27 #endif
28 #include "hw/arm/arm.h"
29 #include "sysemu/sysemu.h"
30 #include "sysemu/kvm.h"
31 #include "kvm_arm.h"
32
33 static void arm_cpu_set_pc(CPUState *cs, vaddr value)
34 {
35 ARMCPU *cpu = ARM_CPU(cs);
36
37 cpu->env.regs[15] = value;
38 }
39
40 static bool arm_cpu_has_work(CPUState *cs)
41 {
42 ARMCPU *cpu = ARM_CPU(cs);
43
44 return !cpu->powered_off
45 && cs->interrupt_request &
46 (CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD
47 | CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ
48 | CPU_INTERRUPT_EXITTB);
49 }
50
51 static void cp_reg_reset(gpointer key, gpointer value, gpointer opaque)
52 {
53 /* Reset a single ARMCPRegInfo register */
54 ARMCPRegInfo *ri = value;
55 ARMCPU *cpu = opaque;
56
57 if (ri->type & (ARM_CP_SPECIAL | ARM_CP_ALIAS)) {
58 return;
59 }
60
61 if (ri->resetfn) {
62 ri->resetfn(&cpu->env, ri);
63 return;
64 }
65
66 /* A zero offset is never possible as it would be regs[0]
67 * so we use it to indicate that reset is being handled elsewhere.
68 * This is basically only used for fields in non-core coprocessors
69 * (like the pxa2xx ones).
70 */
71 if (!ri->fieldoffset) {
72 return;
73 }
74
75 if (cpreg_field_is_64bit(ri)) {
76 CPREG_FIELD64(&cpu->env, ri) = ri->resetvalue;
77 } else {
78 CPREG_FIELD32(&cpu->env, ri) = ri->resetvalue;
79 }
80 }
81
82 /* CPUClass::reset() */
83 static void arm_cpu_reset(CPUState *s)
84 {
85 ARMCPU *cpu = ARM_CPU(s);
86 ARMCPUClass *acc = ARM_CPU_GET_CLASS(cpu);
87 CPUARMState *env = &cpu->env;
88
89 acc->parent_reset(s);
90
91 memset(env, 0, offsetof(CPUARMState, features));
92 g_hash_table_foreach(cpu->cp_regs, cp_reg_reset, cpu);
93 env->vfp.xregs[ARM_VFP_FPSID] = cpu->reset_fpsid;
94 env->vfp.xregs[ARM_VFP_MVFR0] = cpu->mvfr0;
95 env->vfp.xregs[ARM_VFP_MVFR1] = cpu->mvfr1;
96 env->vfp.xregs[ARM_VFP_MVFR2] = cpu->mvfr2;
97
98 cpu->powered_off = cpu->start_powered_off;
99 s->halted = cpu->start_powered_off;
100
101 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
102 env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
103 }
104
105 if (arm_feature(env, ARM_FEATURE_AARCH64)) {
106 /* 64 bit CPUs always start in 64 bit mode */
107 env->aarch64 = 1;
108 #if defined(CONFIG_USER_ONLY)
109 env->pstate = PSTATE_MODE_EL0t;
110 /* Userspace expects access to DC ZVA, CTL_EL0 and the cache ops */
111 env->cp15.sctlr_el[1] |= SCTLR_UCT | SCTLR_UCI | SCTLR_DZE;
112 /* and to the FP/Neon instructions */
113 env->cp15.cpacr_el1 = deposit64(env->cp15.cpacr_el1, 20, 2, 3);
114 #else
115 /* Reset into the highest available EL */
116 if (arm_feature(env, ARM_FEATURE_EL3)) {
117 env->pstate = PSTATE_MODE_EL3h;
118 } else if (arm_feature(env, ARM_FEATURE_EL2)) {
119 env->pstate = PSTATE_MODE_EL2h;
120 } else {
121 env->pstate = PSTATE_MODE_EL1h;
122 }
123 env->pc = cpu->rvbar;
124 #endif
125 } else {
126 #if defined(CONFIG_USER_ONLY)
127 /* Userspace expects access to cp10 and cp11 for FP/Neon */
128 env->cp15.cpacr_el1 = deposit64(env->cp15.cpacr_el1, 20, 4, 0xf);
129 #endif
130 }
131
132 #if defined(CONFIG_USER_ONLY)
133 env->uncached_cpsr = ARM_CPU_MODE_USR;
134 /* For user mode we must enable access to coprocessors */
135 env->vfp.xregs[ARM_VFP_FPEXC] = 1 << 30;
136 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
137 env->cp15.c15_cpar = 3;
138 } else if (arm_feature(env, ARM_FEATURE_XSCALE)) {
139 env->cp15.c15_cpar = 1;
140 }
141 #else
142 /* SVC mode with interrupts disabled. */
143 env->uncached_cpsr = ARM_CPU_MODE_SVC;
144 env->daif = PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F;
145 /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
146 * clear at reset. Initial SP and PC are loaded from ROM.
147 */
148 if (IS_M(env)) {
149 uint32_t initial_msp; /* Loaded from 0x0 */
150 uint32_t initial_pc; /* Loaded from 0x4 */
151 uint8_t *rom;
152
153 env->daif &= ~PSTATE_I;
154 rom = rom_ptr(0);
155 if (rom) {
156 /* Address zero is covered by ROM which hasn't yet been
157 * copied into physical memory.
158 */
159 initial_msp = ldl_p(rom);
160 initial_pc = ldl_p(rom + 4);
161 } else {
162 /* Address zero not covered by a ROM blob, or the ROM blob
163 * is in non-modifiable memory and this is a second reset after
164 * it got copied into memory. In the latter case, rom_ptr
165 * will return a NULL pointer and we should use ldl_phys instead.
166 */
167 initial_msp = ldl_phys(s->as, 0);
168 initial_pc = ldl_phys(s->as, 4);
169 }
170
171 env->regs[13] = initial_msp & 0xFFFFFFFC;
172 env->regs[15] = initial_pc & ~1;
173 env->thumb = initial_pc & 1;
174 }
175
176 /* AArch32 has a hard highvec setting of 0xFFFF0000. If we are currently
177 * executing as AArch32 then check if highvecs are enabled and
178 * adjust the PC accordingly.
179 */
180 if (A32_BANKED_CURRENT_REG_GET(env, sctlr) & SCTLR_V) {
181 env->regs[15] = 0xFFFF0000;
182 }
183
184 env->vfp.xregs[ARM_VFP_FPEXC] = 0;
185 #endif
186 set_flush_to_zero(1, &env->vfp.standard_fp_status);
187 set_flush_inputs_to_zero(1, &env->vfp.standard_fp_status);
188 set_default_nan_mode(1, &env->vfp.standard_fp_status);
189 set_float_detect_tininess(float_tininess_before_rounding,
190 &env->vfp.fp_status);
191 set_float_detect_tininess(float_tininess_before_rounding,
192 &env->vfp.standard_fp_status);
193 tlb_flush(s, 1);
194
195 #ifndef CONFIG_USER_ONLY
196 if (kvm_enabled()) {
197 kvm_arm_reset_vcpu(cpu);
198 }
199 #endif
200
201 hw_breakpoint_update_all(cpu);
202 hw_watchpoint_update_all(cpu);
203 }
204
205 bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
206 {
207 CPUClass *cc = CPU_GET_CLASS(cs);
208 CPUARMState *env = cs->env_ptr;
209 uint32_t cur_el = arm_current_el(env);
210 bool secure = arm_is_secure(env);
211 uint32_t target_el;
212 uint32_t excp_idx;
213 bool ret = false;
214
215 if (interrupt_request & CPU_INTERRUPT_FIQ) {
216 excp_idx = EXCP_FIQ;
217 target_el = arm_phys_excp_target_el(cs, excp_idx, cur_el, secure);
218 if (arm_excp_unmasked(cs, excp_idx, target_el)) {
219 cs->exception_index = excp_idx;
220 env->exception.target_el = target_el;
221 cc->do_interrupt(cs);
222 ret = true;
223 }
224 }
225 if (interrupt_request & CPU_INTERRUPT_HARD) {
226 excp_idx = EXCP_IRQ;
227 target_el = arm_phys_excp_target_el(cs, excp_idx, cur_el, secure);
228 if (arm_excp_unmasked(cs, excp_idx, target_el)) {
229 cs->exception_index = excp_idx;
230 env->exception.target_el = target_el;
231 cc->do_interrupt(cs);
232 ret = true;
233 }
234 }
235 if (interrupt_request & CPU_INTERRUPT_VIRQ) {
236 excp_idx = EXCP_VIRQ;
237 target_el = 1;
238 if (arm_excp_unmasked(cs, excp_idx, target_el)) {
239 cs->exception_index = excp_idx;
240 env->exception.target_el = target_el;
241 cc->do_interrupt(cs);
242 ret = true;
243 }
244 }
245 if (interrupt_request & CPU_INTERRUPT_VFIQ) {
246 excp_idx = EXCP_VFIQ;
247 target_el = 1;
248 if (arm_excp_unmasked(cs, excp_idx, target_el)) {
249 cs->exception_index = excp_idx;
250 env->exception.target_el = target_el;
251 cc->do_interrupt(cs);
252 ret = true;
253 }
254 }
255
256 return ret;
257 }
258
259 #if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64)
260 static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
261 {
262 CPUClass *cc = CPU_GET_CLASS(cs);
263 ARMCPU *cpu = ARM_CPU(cs);
264 CPUARMState *env = &cpu->env;
265 bool ret = false;
266
267
268 if (interrupt_request & CPU_INTERRUPT_FIQ
269 && !(env->daif & PSTATE_F)) {
270 cs->exception_index = EXCP_FIQ;
271 cc->do_interrupt(cs);
272 ret = true;
273 }
274 /* ARMv7-M interrupt return works by loading a magic value
275 * into the PC. On real hardware the load causes the
276 * return to occur. The qemu implementation performs the
277 * jump normally, then does the exception return when the
278 * CPU tries to execute code at the magic address.
279 * This will cause the magic PC value to be pushed to
280 * the stack if an interrupt occurred at the wrong time.
281 * We avoid this by disabling interrupts when
282 * pc contains a magic address.
283 */
284 if (interrupt_request & CPU_INTERRUPT_HARD
285 && !(env->daif & PSTATE_I)
286 && (env->regs[15] < 0xfffffff0)) {
287 cs->exception_index = EXCP_IRQ;
288 cc->do_interrupt(cs);
289 ret = true;
290 }
291 return ret;
292 }
293 #endif
294
295 #ifndef CONFIG_USER_ONLY
296 static void arm_cpu_set_irq(void *opaque, int irq, int level)
297 {
298 ARMCPU *cpu = opaque;
299 CPUARMState *env = &cpu->env;
300 CPUState *cs = CPU(cpu);
301 static const int mask[] = {
302 [ARM_CPU_IRQ] = CPU_INTERRUPT_HARD,
303 [ARM_CPU_FIQ] = CPU_INTERRUPT_FIQ,
304 [ARM_CPU_VIRQ] = CPU_INTERRUPT_VIRQ,
305 [ARM_CPU_VFIQ] = CPU_INTERRUPT_VFIQ
306 };
307
308 switch (irq) {
309 case ARM_CPU_VIRQ:
310 case ARM_CPU_VFIQ:
311 if (!arm_feature(env, ARM_FEATURE_EL2)) {
312 hw_error("%s: Virtual interrupt line %d with no EL2 support\n",
313 __func__, irq);
314 }
315 /* fall through */
316 case ARM_CPU_IRQ:
317 case ARM_CPU_FIQ:
318 if (level) {
319 cpu_interrupt(cs, mask[irq]);
320 } else {
321 cpu_reset_interrupt(cs, mask[irq]);
322 }
323 break;
324 default:
325 hw_error("arm_cpu_set_irq: Bad interrupt line %d\n", irq);
326 }
327 }
328
329 static void arm_cpu_kvm_set_irq(void *opaque, int irq, int level)
330 {
331 #ifdef CONFIG_KVM
332 ARMCPU *cpu = opaque;
333 CPUState *cs = CPU(cpu);
334 int kvm_irq = KVM_ARM_IRQ_TYPE_CPU << KVM_ARM_IRQ_TYPE_SHIFT;
335
336 switch (irq) {
337 case ARM_CPU_IRQ:
338 kvm_irq |= KVM_ARM_IRQ_CPU_IRQ;
339 break;
340 case ARM_CPU_FIQ:
341 kvm_irq |= KVM_ARM_IRQ_CPU_FIQ;
342 break;
343 default:
344 hw_error("arm_cpu_kvm_set_irq: Bad interrupt line %d\n", irq);
345 }
346 kvm_irq |= cs->cpu_index << KVM_ARM_IRQ_VCPU_SHIFT;
347 kvm_set_irq(kvm_state, kvm_irq, level ? 1 : 0);
348 #endif
349 }
350
351 static bool arm_cpu_is_big_endian(CPUState *cs)
352 {
353 ARMCPU *cpu = ARM_CPU(cs);
354 CPUARMState *env = &cpu->env;
355 int cur_el;
356
357 cpu_synchronize_state(cs);
358
359 /* In 32bit guest endianness is determined by looking at CPSR's E bit */
360 if (!is_a64(env)) {
361 return (env->uncached_cpsr & CPSR_E) ? 1 : 0;
362 }
363
364 cur_el = arm_current_el(env);
365
366 if (cur_el == 0) {
367 return (env->cp15.sctlr_el[1] & SCTLR_E0E) != 0;
368 }
369
370 return (env->cp15.sctlr_el[cur_el] & SCTLR_EE) != 0;
371 }
372
373 #endif
374
375 static inline void set_feature(CPUARMState *env, int feature)
376 {
377 env->features |= 1ULL << feature;
378 }
379
380 static inline void unset_feature(CPUARMState *env, int feature)
381 {
382 env->features &= ~(1ULL << feature);
383 }
384
385 static int
386 print_insn_thumb1(bfd_vma pc, disassemble_info *info)
387 {
388 return print_insn_arm(pc | 1, info);
389 }
390
391 static void arm_disas_set_info(CPUState *cpu, disassemble_info *info)
392 {
393 ARMCPU *ac = ARM_CPU(cpu);
394 CPUARMState *env = &ac->env;
395
396 if (is_a64(env)) {
397 /* We might not be compiled with the A64 disassembler
398 * because it needs a C++ compiler. Leave print_insn
399 * unset in this case to use the caller default behaviour.
400 */
401 #if defined(CONFIG_ARM_A64_DIS)
402 info->print_insn = print_insn_arm_a64;
403 #endif
404 } else if (env->thumb) {
405 info->print_insn = print_insn_thumb1;
406 } else {
407 info->print_insn = print_insn_arm;
408 }
409 if (env->bswap_code) {
410 #ifdef TARGET_WORDS_BIGENDIAN
411 info->endian = BFD_ENDIAN_LITTLE;
412 #else
413 info->endian = BFD_ENDIAN_BIG;
414 #endif
415 }
416 }
417
418 #define ARM_CPUS_PER_CLUSTER 8
419
420 static void arm_cpu_initfn(Object *obj)
421 {
422 CPUState *cs = CPU(obj);
423 ARMCPU *cpu = ARM_CPU(obj);
424 static bool inited;
425 uint32_t Aff1, Aff0;
426
427 cs->env_ptr = &cpu->env;
428 cpu_exec_init(cs, &error_abort);
429 cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal,
430 g_free, g_free);
431
432 /* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it.
433 * We don't support setting cluster ID ([16..23]) (known as Aff2
434 * in later ARM ARM versions), or any of the higher affinity level fields,
435 * so these bits always RAZ.
436 */
437 Aff1 = cs->cpu_index / ARM_CPUS_PER_CLUSTER;
438 Aff0 = cs->cpu_index % ARM_CPUS_PER_CLUSTER;
439 cpu->mp_affinity = (Aff1 << 8) | Aff0;
440
441 #ifndef CONFIG_USER_ONLY
442 /* Our inbound IRQ and FIQ lines */
443 if (kvm_enabled()) {
444 /* VIRQ and VFIQ are unused with KVM but we add them to maintain
445 * the same interface as non-KVM CPUs.
446 */
447 qdev_init_gpio_in(DEVICE(cpu), arm_cpu_kvm_set_irq, 4);
448 } else {
449 qdev_init_gpio_in(DEVICE(cpu), arm_cpu_set_irq, 4);
450 }
451
452 cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
453 arm_gt_ptimer_cb, cpu);
454 cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
455 arm_gt_vtimer_cb, cpu);
456 cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCALE,
457 arm_gt_htimer_cb, cpu);
458 qdev_init_gpio_out(DEVICE(cpu), cpu->gt_timer_outputs,
459 ARRAY_SIZE(cpu->gt_timer_outputs));
460 #endif
461
462 /* DTB consumers generally don't in fact care what the 'compatible'
463 * string is, so always provide some string and trust that a hypothetical
464 * picky DTB consumer will also provide a helpful error message.
465 */
466 cpu->dtb_compatible = "qemu,unknown";
467 cpu->psci_version = 1; /* By default assume PSCI v0.1 */
468 cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
469
470 if (tcg_enabled()) {
471 cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
472 if (!inited) {
473 inited = true;
474 arm_translate_init();
475 }
476 }
477 }
478
479 static Property arm_cpu_reset_cbar_property =
480 DEFINE_PROP_UINT64("reset-cbar", ARMCPU, reset_cbar, 0);
481
482 static Property arm_cpu_reset_hivecs_property =
483 DEFINE_PROP_BOOL("reset-hivecs", ARMCPU, reset_hivecs, false);
484
485 static Property arm_cpu_rvbar_property =
486 DEFINE_PROP_UINT64("rvbar", ARMCPU, rvbar, 0);
487
488 static Property arm_cpu_has_el3_property =
489 DEFINE_PROP_BOOL("has_el3", ARMCPU, has_el3, true);
490
491 static Property arm_cpu_has_mpu_property =
492 DEFINE_PROP_BOOL("has-mpu", ARMCPU, has_mpu, true);
493
494 static Property arm_cpu_pmsav7_dregion_property =
495 DEFINE_PROP_UINT32("pmsav7-dregion", ARMCPU, pmsav7_dregion, 16);
496
497 static void arm_cpu_post_init(Object *obj)
498 {
499 ARMCPU *cpu = ARM_CPU(obj);
500
501 if (arm_feature(&cpu->env, ARM_FEATURE_CBAR) ||
502 arm_feature(&cpu->env, ARM_FEATURE_CBAR_RO)) {
503 qdev_property_add_static(DEVICE(obj), &arm_cpu_reset_cbar_property,
504 &error_abort);
505 }
506
507 if (!arm_feature(&cpu->env, ARM_FEATURE_M)) {
508 qdev_property_add_static(DEVICE(obj), &arm_cpu_reset_hivecs_property,
509 &error_abort);
510 }
511
512 if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
513 qdev_property_add_static(DEVICE(obj), &arm_cpu_rvbar_property,
514 &error_abort);
515 }
516
517 if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) {
518 /* Add the has_el3 state CPU property only if EL3 is allowed. This will
519 * prevent "has_el3" from existing on CPUs which cannot support EL3.
520 */
521 qdev_property_add_static(DEVICE(obj), &arm_cpu_has_el3_property,
522 &error_abort);
523 }
524
525 if (arm_feature(&cpu->env, ARM_FEATURE_MPU)) {
526 qdev_property_add_static(DEVICE(obj), &arm_cpu_has_mpu_property,
527 &error_abort);
528 if (arm_feature(&cpu->env, ARM_FEATURE_V7)) {
529 qdev_property_add_static(DEVICE(obj),
530 &arm_cpu_pmsav7_dregion_property,
531 &error_abort);
532 }
533 }
534
535 }
536
537 static void arm_cpu_finalizefn(Object *obj)
538 {
539 ARMCPU *cpu = ARM_CPU(obj);
540 g_hash_table_destroy(cpu->cp_regs);
541 }
542
543 static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
544 {
545 CPUState *cs = CPU(dev);
546 ARMCPU *cpu = ARM_CPU(dev);
547 ARMCPUClass *acc = ARM_CPU_GET_CLASS(dev);
548 CPUARMState *env = &cpu->env;
549
550 /* Some features automatically imply others: */
551 if (arm_feature(env, ARM_FEATURE_V8)) {
552 set_feature(env, ARM_FEATURE_V7);
553 set_feature(env, ARM_FEATURE_ARM_DIV);
554 set_feature(env, ARM_FEATURE_LPAE);
555 }
556 if (arm_feature(env, ARM_FEATURE_V7)) {
557 set_feature(env, ARM_FEATURE_VAPA);
558 set_feature(env, ARM_FEATURE_THUMB2);
559 set_feature(env, ARM_FEATURE_MPIDR);
560 if (!arm_feature(env, ARM_FEATURE_M)) {
561 set_feature(env, ARM_FEATURE_V6K);
562 } else {
563 set_feature(env, ARM_FEATURE_V6);
564 }
565 }
566 if (arm_feature(env, ARM_FEATURE_V6K)) {
567 set_feature(env, ARM_FEATURE_V6);
568 set_feature(env, ARM_FEATURE_MVFR);
569 }
570 if (arm_feature(env, ARM_FEATURE_V6)) {
571 set_feature(env, ARM_FEATURE_V5);
572 if (!arm_feature(env, ARM_FEATURE_M)) {
573 set_feature(env, ARM_FEATURE_AUXCR);
574 }
575 }
576 if (arm_feature(env, ARM_FEATURE_V5)) {
577 set_feature(env, ARM_FEATURE_V4T);
578 }
579 if (arm_feature(env, ARM_FEATURE_M)) {
580 set_feature(env, ARM_FEATURE_THUMB_DIV);
581 }
582 if (arm_feature(env, ARM_FEATURE_ARM_DIV)) {
583 set_feature(env, ARM_FEATURE_THUMB_DIV);
584 }
585 if (arm_feature(env, ARM_FEATURE_VFP4)) {
586 set_feature(env, ARM_FEATURE_VFP3);
587 set_feature(env, ARM_FEATURE_VFP_FP16);
588 }
589 if (arm_feature(env, ARM_FEATURE_VFP3)) {
590 set_feature(env, ARM_FEATURE_VFP);
591 }
592 if (arm_feature(env, ARM_FEATURE_LPAE)) {
593 set_feature(env, ARM_FEATURE_V7MP);
594 set_feature(env, ARM_FEATURE_PXN);
595 }
596 if (arm_feature(env, ARM_FEATURE_CBAR_RO)) {
597 set_feature(env, ARM_FEATURE_CBAR);
598 }
599 if (arm_feature(env, ARM_FEATURE_THUMB2) &&
600 !arm_feature(env, ARM_FEATURE_M)) {
601 set_feature(env, ARM_FEATURE_THUMB_DSP);
602 }
603
604 if (cpu->reset_hivecs) {
605 cpu->reset_sctlr |= (1 << 13);
606 }
607
608 if (!cpu->has_el3) {
609 /* If the has_el3 CPU property is disabled then we need to disable the
610 * feature.
611 */
612 unset_feature(env, ARM_FEATURE_EL3);
613
614 /* Disable the security extension feature bits in the processor feature
615 * registers as well. These are id_pfr1[7:4] and id_aa64pfr0[15:12].
616 */
617 cpu->id_pfr1 &= ~0xf0;
618 cpu->id_aa64pfr0 &= ~0xf000;
619 }
620
621 if (!cpu->has_mpu) {
622 unset_feature(env, ARM_FEATURE_MPU);
623 }
624
625 if (arm_feature(env, ARM_FEATURE_MPU) &&
626 arm_feature(env, ARM_FEATURE_V7)) {
627 uint32_t nr = cpu->pmsav7_dregion;
628
629 if (nr > 0xff) {
630 error_setg(errp, "PMSAv7 MPU #regions invalid %" PRIu32 "\n", nr);
631 return;
632 }
633
634 if (nr) {
635 env->pmsav7.drbar = g_new0(uint32_t, nr);
636 env->pmsav7.drsr = g_new0(uint32_t, nr);
637 env->pmsav7.dracr = g_new0(uint32_t, nr);
638 }
639 }
640
641 register_cp_regs_for_features(cpu);
642 arm_cpu_register_gdb_regs_for_features(cpu);
643
644 init_cpreg_list(cpu);
645
646 qemu_init_vcpu(cs);
647 cpu_reset(cs);
648
649 acc->parent_realize(dev, errp);
650 }
651
652 static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
653 {
654 ObjectClass *oc;
655 char *typename;
656 char **cpuname;
657
658 if (!cpu_model) {
659 return NULL;
660 }
661
662 cpuname = g_strsplit(cpu_model, ",", 1);
663 typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpuname[0]);
664 oc = object_class_by_name(typename);
665 g_strfreev(cpuname);
666 g_free(typename);
667 if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
668 object_class_is_abstract(oc)) {
669 return NULL;
670 }
671 return oc;
672 }
673
674 /* CPU models. These are not needed for the AArch64 linux-user build. */
675 #if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64)
676
677 static void arm926_initfn(Object *obj)
678 {
679 ARMCPU *cpu = ARM_CPU(obj);
680
681 cpu->dtb_compatible = "arm,arm926";
682 set_feature(&cpu->env, ARM_FEATURE_V5);
683 set_feature(&cpu->env, ARM_FEATURE_VFP);
684 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
685 set_feature(&cpu->env, ARM_FEATURE_CACHE_TEST_CLEAN);
686 cpu->midr = 0x41069265;
687 cpu->reset_fpsid = 0x41011090;
688 cpu->ctr = 0x1dd20d2;
689 cpu->reset_sctlr = 0x00090078;
690 }
691
692 static void arm946_initfn(Object *obj)
693 {
694 ARMCPU *cpu = ARM_CPU(obj);
695
696 cpu->dtb_compatible = "arm,arm946";
697 set_feature(&cpu->env, ARM_FEATURE_V5);
698 set_feature(&cpu->env, ARM_FEATURE_MPU);
699 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
700 cpu->midr = 0x41059461;
701 cpu->ctr = 0x0f004006;
702 cpu->reset_sctlr = 0x00000078;
703 }
704
705 static void arm1026_initfn(Object *obj)
706 {
707 ARMCPU *cpu = ARM_CPU(obj);
708
709 cpu->dtb_compatible = "arm,arm1026";
710 set_feature(&cpu->env, ARM_FEATURE_V5);
711 set_feature(&cpu->env, ARM_FEATURE_VFP);
712 set_feature(&cpu->env, ARM_FEATURE_AUXCR);
713 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
714 set_feature(&cpu->env, ARM_FEATURE_CACHE_TEST_CLEAN);
715 cpu->midr = 0x4106a262;
716 cpu->reset_fpsid = 0x410110a0;
717 cpu->ctr = 0x1dd20d2;
718 cpu->reset_sctlr = 0x00090078;
719 cpu->reset_auxcr = 1;
720 {
721 /* The 1026 had an IFAR at c6,c0,0,1 rather than the ARMv6 c6,c0,0,2 */
722 ARMCPRegInfo ifar = {
723 .name = "IFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 1,
724 .access = PL1_RW,
725 .fieldoffset = offsetof(CPUARMState, cp15.ifar_ns),
726 .resetvalue = 0
727 };
728 define_one_arm_cp_reg(cpu, &ifar);
729 }
730 }
731
732 static void arm1136_r2_initfn(Object *obj)
733 {
734 ARMCPU *cpu = ARM_CPU(obj);
735 /* What qemu calls "arm1136_r2" is actually the 1136 r0p2, ie an
736 * older core than plain "arm1136". In particular this does not
737 * have the v6K features.
738 * These ID register values are correct for 1136 but may be wrong
739 * for 1136_r2 (in particular r0p2 does not actually implement most
740 * of the ID registers).
741 */
742
743 cpu->dtb_compatible = "arm,arm1136";
744 set_feature(&cpu->env, ARM_FEATURE_V6);
745 set_feature(&cpu->env, ARM_FEATURE_VFP);
746 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
747 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
748 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
749 cpu->midr = 0x4107b362;
750 cpu->reset_fpsid = 0x410120b4;
751 cpu->mvfr0 = 0x11111111;
752 cpu->mvfr1 = 0x00000000;
753 cpu->ctr = 0x1dd20d2;
754 cpu->reset_sctlr = 0x00050078;
755 cpu->id_pfr0 = 0x111;
756 cpu->id_pfr1 = 0x1;
757 cpu->id_dfr0 = 0x2;
758 cpu->id_afr0 = 0x3;
759 cpu->id_mmfr0 = 0x01130003;
760 cpu->id_mmfr1 = 0x10030302;
761 cpu->id_mmfr2 = 0x01222110;
762 cpu->id_isar0 = 0x00140011;
763 cpu->id_isar1 = 0x12002111;
764 cpu->id_isar2 = 0x11231111;
765 cpu->id_isar3 = 0x01102131;
766 cpu->id_isar4 = 0x141;
767 cpu->reset_auxcr = 7;
768 }
769
770 static void arm1136_initfn(Object *obj)
771 {
772 ARMCPU *cpu = ARM_CPU(obj);
773
774 cpu->dtb_compatible = "arm,arm1136";
775 set_feature(&cpu->env, ARM_FEATURE_V6K);
776 set_feature(&cpu->env, ARM_FEATURE_V6);
777 set_feature(&cpu->env, ARM_FEATURE_VFP);
778 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
779 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
780 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
781 cpu->midr = 0x4117b363;
782 cpu->reset_fpsid = 0x410120b4;
783 cpu->mvfr0 = 0x11111111;
784 cpu->mvfr1 = 0x00000000;
785 cpu->ctr = 0x1dd20d2;
786 cpu->reset_sctlr = 0x00050078;
787 cpu->id_pfr0 = 0x111;
788 cpu->id_pfr1 = 0x1;
789 cpu->id_dfr0 = 0x2;
790 cpu->id_afr0 = 0x3;
791 cpu->id_mmfr0 = 0x01130003;
792 cpu->id_mmfr1 = 0x10030302;
793 cpu->id_mmfr2 = 0x01222110;
794 cpu->id_isar0 = 0x00140011;
795 cpu->id_isar1 = 0x12002111;
796 cpu->id_isar2 = 0x11231111;
797 cpu->id_isar3 = 0x01102131;
798 cpu->id_isar4 = 0x141;
799 cpu->reset_auxcr = 7;
800 }
801
802 static void arm1176_initfn(Object *obj)
803 {
804 ARMCPU *cpu = ARM_CPU(obj);
805
806 cpu->dtb_compatible = "arm,arm1176";
807 set_feature(&cpu->env, ARM_FEATURE_V6K);
808 set_feature(&cpu->env, ARM_FEATURE_VFP);
809 set_feature(&cpu->env, ARM_FEATURE_VAPA);
810 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
811 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
812 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
813 set_feature(&cpu->env, ARM_FEATURE_EL3);
814 cpu->midr = 0x410fb767;
815 cpu->reset_fpsid = 0x410120b5;
816 cpu->mvfr0 = 0x11111111;
817 cpu->mvfr1 = 0x00000000;
818 cpu->ctr = 0x1dd20d2;
819 cpu->reset_sctlr = 0x00050078;
820 cpu->id_pfr0 = 0x111;
821 cpu->id_pfr1 = 0x11;
822 cpu->id_dfr0 = 0x33;
823 cpu->id_afr0 = 0;
824 cpu->id_mmfr0 = 0x01130003;
825 cpu->id_mmfr1 = 0x10030302;
826 cpu->id_mmfr2 = 0x01222100;
827 cpu->id_isar0 = 0x0140011;
828 cpu->id_isar1 = 0x12002111;
829 cpu->id_isar2 = 0x11231121;
830 cpu->id_isar3 = 0x01102131;
831 cpu->id_isar4 = 0x01141;
832 cpu->reset_auxcr = 7;
833 }
834
835 static void arm11mpcore_initfn(Object *obj)
836 {
837 ARMCPU *cpu = ARM_CPU(obj);
838
839 cpu->dtb_compatible = "arm,arm11mpcore";
840 set_feature(&cpu->env, ARM_FEATURE_V6K);
841 set_feature(&cpu->env, ARM_FEATURE_VFP);
842 set_feature(&cpu->env, ARM_FEATURE_VAPA);
843 set_feature(&cpu->env, ARM_FEATURE_MPIDR);
844 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
845 cpu->midr = 0x410fb022;
846 cpu->reset_fpsid = 0x410120b4;
847 cpu->mvfr0 = 0x11111111;
848 cpu->mvfr1 = 0x00000000;
849 cpu->ctr = 0x1d192992; /* 32K icache 32K dcache */
850 cpu->id_pfr0 = 0x111;
851 cpu->id_pfr1 = 0x1;
852 cpu->id_dfr0 = 0;
853 cpu->id_afr0 = 0x2;
854 cpu->id_mmfr0 = 0x01100103;
855 cpu->id_mmfr1 = 0x10020302;
856 cpu->id_mmfr2 = 0x01222000;
857 cpu->id_isar0 = 0x00100011;
858 cpu->id_isar1 = 0x12002111;
859 cpu->id_isar2 = 0x11221011;
860 cpu->id_isar3 = 0x01102131;
861 cpu->id_isar4 = 0x141;
862 cpu->reset_auxcr = 1;
863 }
864
865 static void cortex_m3_initfn(Object *obj)
866 {
867 ARMCPU *cpu = ARM_CPU(obj);
868 set_feature(&cpu->env, ARM_FEATURE_V7);
869 set_feature(&cpu->env, ARM_FEATURE_M);
870 cpu->midr = 0x410fc231;
871 }
872
873 static void cortex_m4_initfn(Object *obj)
874 {
875 ARMCPU *cpu = ARM_CPU(obj);
876
877 set_feature(&cpu->env, ARM_FEATURE_V7);
878 set_feature(&cpu->env, ARM_FEATURE_M);
879 set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP);
880 cpu->midr = 0x410fc240; /* r0p0 */
881 }
882 static void arm_v7m_class_init(ObjectClass *oc, void *data)
883 {
884 CPUClass *cc = CPU_CLASS(oc);
885
886 #ifndef CONFIG_USER_ONLY
887 cc->do_interrupt = arm_v7m_cpu_do_interrupt;
888 #endif
889
890 cc->cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt;
891 }
892
893 static const ARMCPRegInfo cortexr5_cp_reginfo[] = {
894 /* Dummy the TCM region regs for the moment */
895 { .name = "ATCM", .cp = 15, .opc1 = 0, .crn = 9, .crm = 1, .opc2 = 0,
896 .access = PL1_RW, .type = ARM_CP_CONST },
897 { .name = "BTCM", .cp = 15, .opc1 = 0, .crn = 9, .crm = 1, .opc2 = 1,
898 .access = PL1_RW, .type = ARM_CP_CONST },
899 REGINFO_SENTINEL
900 };
901
902 static void cortex_r5_initfn(Object *obj)
903 {
904 ARMCPU *cpu = ARM_CPU(obj);
905
906 set_feature(&cpu->env, ARM_FEATURE_V7);
907 set_feature(&cpu->env, ARM_FEATURE_THUMB_DIV);
908 set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);
909 set_feature(&cpu->env, ARM_FEATURE_V7MP);
910 set_feature(&cpu->env, ARM_FEATURE_MPU);
911 cpu->midr = 0x411fc153; /* r1p3 */
912 cpu->id_pfr0 = 0x0131;
913 cpu->id_pfr1 = 0x001;
914 cpu->id_dfr0 = 0x010400;
915 cpu->id_afr0 = 0x0;
916 cpu->id_mmfr0 = 0x0210030;
917 cpu->id_mmfr1 = 0x00000000;
918 cpu->id_mmfr2 = 0x01200000;
919 cpu->id_mmfr3 = 0x0211;
920 cpu->id_isar0 = 0x2101111;
921 cpu->id_isar1 = 0x13112111;
922 cpu->id_isar2 = 0x21232141;
923 cpu->id_isar3 = 0x01112131;
924 cpu->id_isar4 = 0x0010142;
925 cpu->id_isar5 = 0x0;
926 cpu->mp_is_up = true;
927 define_arm_cp_regs(cpu, cortexr5_cp_reginfo);
928 }
929
930 static const ARMCPRegInfo cortexa8_cp_reginfo[] = {
931 { .name = "L2LOCKDOWN", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 0,
932 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
933 { .name = "L2AUXCR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 2,
934 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
935 REGINFO_SENTINEL
936 };
937
938 static void cortex_a8_initfn(Object *obj)
939 {
940 ARMCPU *cpu = ARM_CPU(obj);
941
942 cpu->dtb_compatible = "arm,cortex-a8";
943 set_feature(&cpu->env, ARM_FEATURE_V7);
944 set_feature(&cpu->env, ARM_FEATURE_VFP3);
945 set_feature(&cpu->env, ARM_FEATURE_NEON);
946 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
947 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
948 set_feature(&cpu->env, ARM_FEATURE_EL3);
949 cpu->midr = 0x410fc080;
950 cpu->reset_fpsid = 0x410330c0;
951 cpu->mvfr0 = 0x11110222;
952 cpu->mvfr1 = 0x00011100;
953 cpu->ctr = 0x82048004;
954 cpu->reset_sctlr = 0x00c50078;
955 cpu->id_pfr0 = 0x1031;
956 cpu->id_pfr1 = 0x11;
957 cpu->id_dfr0 = 0x400;
958 cpu->id_afr0 = 0;
959 cpu->id_mmfr0 = 0x31100003;
960 cpu->id_mmfr1 = 0x20000000;
961 cpu->id_mmfr2 = 0x01202000;
962 cpu->id_mmfr3 = 0x11;
963 cpu->id_isar0 = 0x00101111;
964 cpu->id_isar1 = 0x12112111;
965 cpu->id_isar2 = 0x21232031;
966 cpu->id_isar3 = 0x11112131;
967 cpu->id_isar4 = 0x00111142;
968 cpu->dbgdidr = 0x15141000;
969 cpu->clidr = (1 << 27) | (2 << 24) | 3;
970 cpu->ccsidr[0] = 0xe007e01a; /* 16k L1 dcache. */
971 cpu->ccsidr[1] = 0x2007e01a; /* 16k L1 icache. */
972 cpu->ccsidr[2] = 0xf0000000; /* No L2 icache. */
973 cpu->reset_auxcr = 2;
974 define_arm_cp_regs(cpu, cortexa8_cp_reginfo);
975 }
976
977 static const ARMCPRegInfo cortexa9_cp_reginfo[] = {
978 /* power_control should be set to maximum latency. Again,
979 * default to 0 and set by private hook
980 */
981 { .name = "A9_PWRCTL", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 0,
982 .access = PL1_RW, .resetvalue = 0,
983 .fieldoffset = offsetof(CPUARMState, cp15.c15_power_control) },
984 { .name = "A9_DIAG", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 1,
985 .access = PL1_RW, .resetvalue = 0,
986 .fieldoffset = offsetof(CPUARMState, cp15.c15_diagnostic) },
987 { .name = "A9_PWRDIAG", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 2,
988 .access = PL1_RW, .resetvalue = 0,
989 .fieldoffset = offsetof(CPUARMState, cp15.c15_power_diagnostic) },
990 { .name = "NEONBUSY", .cp = 15, .crn = 15, .crm = 1, .opc1 = 0, .opc2 = 0,
991 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
992 /* TLB lockdown control */
993 { .name = "TLB_LOCKR", .cp = 15, .crn = 15, .crm = 4, .opc1 = 5, .opc2 = 2,
994 .access = PL1_W, .resetvalue = 0, .type = ARM_CP_NOP },
995 { .name = "TLB_LOCKW", .cp = 15, .crn = 15, .crm = 4, .opc1 = 5, .opc2 = 4,
996 .access = PL1_W, .resetvalue = 0, .type = ARM_CP_NOP },
997 { .name = "TLB_VA", .cp = 15, .crn = 15, .crm = 5, .opc1 = 5, .opc2 = 2,
998 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
999 { .name = "TLB_PA", .cp = 15, .crn = 15, .crm = 6, .opc1 = 5, .opc2 = 2,
1000 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
1001 { .name = "TLB_ATTR", .cp = 15, .crn = 15, .crm = 7, .opc1 = 5, .opc2 = 2,
1002 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
1003 REGINFO_SENTINEL
1004 };
1005
1006 static void cortex_a9_initfn(Object *obj)
1007 {
1008 ARMCPU *cpu = ARM_CPU(obj);
1009
1010 cpu->dtb_compatible = "arm,cortex-a9";
1011 set_feature(&cpu->env, ARM_FEATURE_V7);
1012 set_feature(&cpu->env, ARM_FEATURE_VFP3);
1013 set_feature(&cpu->env, ARM_FEATURE_VFP_FP16);
1014 set_feature(&cpu->env, ARM_FEATURE_NEON);
1015 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
1016 set_feature(&cpu->env, ARM_FEATURE_EL3);
1017 /* Note that A9 supports the MP extensions even for
1018 * A9UP and single-core A9MP (which are both different
1019 * and valid configurations; we don't model A9UP).
1020 */
1021 set_feature(&cpu->env, ARM_FEATURE_V7MP);
1022 set_feature(&cpu->env, ARM_FEATURE_CBAR);
1023 cpu->midr = 0x410fc090;
1024 cpu->reset_fpsid = 0x41033090;
1025 cpu->mvfr0 = 0x11110222;
1026 cpu->mvfr1 = 0x01111111;
1027 cpu->ctr = 0x80038003;
1028 cpu->reset_sctlr = 0x00c50078;
1029 cpu->id_pfr0 = 0x1031;
1030 cpu->id_pfr1 = 0x11;
1031 cpu->id_dfr0 = 0x000;
1032 cpu->id_afr0 = 0;
1033 cpu->id_mmfr0 = 0x00100103;
1034 cpu->id_mmfr1 = 0x20000000;
1035 cpu->id_mmfr2 = 0x01230000;
1036 cpu->id_mmfr3 = 0x00002111;
1037 cpu->id_isar0 = 0x00101111;
1038 cpu->id_isar1 = 0x13112111;
1039 cpu->id_isar2 = 0x21232041;
1040 cpu->id_isar3 = 0x11112131;
1041 cpu->id_isar4 = 0x00111142;
1042 cpu->dbgdidr = 0x35141000;
1043 cpu->clidr = (1 << 27) | (1 << 24) | 3;
1044 cpu->ccsidr[0] = 0xe00fe019; /* 16k L1 dcache. */
1045 cpu->ccsidr[1] = 0x200fe019; /* 16k L1 icache. */
1046 define_arm_cp_regs(cpu, cortexa9_cp_reginfo);
1047 }
1048
1049 #ifndef CONFIG_USER_ONLY
1050 static uint64_t a15_l2ctlr_read(CPUARMState *env, const ARMCPRegInfo *ri)
1051 {
1052 /* Linux wants the number of processors from here.
1053 * Might as well set the interrupt-controller bit too.
1054 */
1055 return ((smp_cpus - 1) << 24) | (1 << 23);
1056 }
1057 #endif
1058
1059 static const ARMCPRegInfo cortexa15_cp_reginfo[] = {
1060 #ifndef CONFIG_USER_ONLY
1061 { .name = "L2CTLR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 2,
1062 .access = PL1_RW, .resetvalue = 0, .readfn = a15_l2ctlr_read,
1063 .writefn = arm_cp_write_ignore, },
1064 #endif
1065 { .name = "L2ECTLR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 3,
1066 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
1067 REGINFO_SENTINEL
1068 };
1069
1070 static void cortex_a15_initfn(Object *obj)
1071 {
1072 ARMCPU *cpu = ARM_CPU(obj);
1073
1074 cpu->dtb_compatible = "arm,cortex-a15";
1075 set_feature(&cpu->env, ARM_FEATURE_V7);
1076 set_feature(&cpu->env, ARM_FEATURE_VFP4);
1077 set_feature(&cpu->env, ARM_FEATURE_NEON);
1078 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
1079 set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);
1080 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
1081 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
1082 set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
1083 set_feature(&cpu->env, ARM_FEATURE_LPAE);
1084 set_feature(&cpu->env, ARM_FEATURE_EL3);
1085 cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A15;
1086 cpu->midr = 0x412fc0f1;
1087 cpu->reset_fpsid = 0x410430f0;
1088 cpu->mvfr0 = 0x10110222;
1089 cpu->mvfr1 = 0x11111111;
1090 cpu->ctr = 0x8444c004;
1091 cpu->reset_sctlr = 0x00c50078;
1092 cpu->id_pfr0 = 0x00001131;
1093 cpu->id_pfr1 = 0x00011011;
1094 cpu->id_dfr0 = 0x02010555;
1095 cpu->id_afr0 = 0x00000000;
1096 cpu->id_mmfr0 = 0x10201105;
1097 cpu->id_mmfr1 = 0x20000000;
1098 cpu->id_mmfr2 = 0x01240000;
1099 cpu->id_mmfr3 = 0x02102211;
1100 cpu->id_isar0 = 0x02101110;
1101 cpu->id_isar1 = 0x13112111;
1102 cpu->id_isar2 = 0x21232041;
1103 cpu->id_isar3 = 0x11112131;
1104 cpu->id_isar4 = 0x10011142;
1105 cpu->dbgdidr = 0x3515f021;
1106 cpu->clidr = 0x0a200023;
1107 cpu->ccsidr[0] = 0x701fe00a; /* 32K L1 dcache */
1108 cpu->ccsidr[1] = 0x201fe00a; /* 32K L1 icache */
1109 cpu->ccsidr[2] = 0x711fe07a; /* 4096K L2 unified cache */
1110 define_arm_cp_regs(cpu, cortexa15_cp_reginfo);
1111 }
1112
1113 static void ti925t_initfn(Object *obj)
1114 {
1115 ARMCPU *cpu = ARM_CPU(obj);
1116 set_feature(&cpu->env, ARM_FEATURE_V4T);
1117 set_feature(&cpu->env, ARM_FEATURE_OMAPCP);
1118 cpu->midr = ARM_CPUID_TI925T;
1119 cpu->ctr = 0x5109149;
1120 cpu->reset_sctlr = 0x00000070;
1121 }
1122
1123 static void sa1100_initfn(Object *obj)
1124 {
1125 ARMCPU *cpu = ARM_CPU(obj);
1126
1127 cpu->dtb_compatible = "intel,sa1100";
1128 set_feature(&cpu->env, ARM_FEATURE_STRONGARM);
1129 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
1130 cpu->midr = 0x4401A11B;
1131 cpu->reset_sctlr = 0x00000070;
1132 }
1133
1134 static void sa1110_initfn(Object *obj)
1135 {
1136 ARMCPU *cpu = ARM_CPU(obj);
1137 set_feature(&cpu->env, ARM_FEATURE_STRONGARM);
1138 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
1139 cpu->midr = 0x6901B119;
1140 cpu->reset_sctlr = 0x00000070;
1141 }
1142
1143 static void pxa250_initfn(Object *obj)
1144 {
1145 ARMCPU *cpu = ARM_CPU(obj);
1146
1147 cpu->dtb_compatible = "marvell,xscale";
1148 set_feature(&cpu->env, ARM_FEATURE_V5);
1149 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1150 cpu->midr = 0x69052100;
1151 cpu->ctr = 0xd172172;
1152 cpu->reset_sctlr = 0x00000078;
1153 }
1154
1155 static void pxa255_initfn(Object *obj)
1156 {
1157 ARMCPU *cpu = ARM_CPU(obj);
1158
1159 cpu->dtb_compatible = "marvell,xscale";
1160 set_feature(&cpu->env, ARM_FEATURE_V5);
1161 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1162 cpu->midr = 0x69052d00;
1163 cpu->ctr = 0xd172172;
1164 cpu->reset_sctlr = 0x00000078;
1165 }
1166
1167 static void pxa260_initfn(Object *obj)
1168 {
1169 ARMCPU *cpu = ARM_CPU(obj);
1170
1171 cpu->dtb_compatible = "marvell,xscale";
1172 set_feature(&cpu->env, ARM_FEATURE_V5);
1173 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1174 cpu->midr = 0x69052903;
1175 cpu->ctr = 0xd172172;
1176 cpu->reset_sctlr = 0x00000078;
1177 }
1178
1179 static void pxa261_initfn(Object *obj)
1180 {
1181 ARMCPU *cpu = ARM_CPU(obj);
1182
1183 cpu->dtb_compatible = "marvell,xscale";
1184 set_feature(&cpu->env, ARM_FEATURE_V5);
1185 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1186 cpu->midr = 0x69052d05;
1187 cpu->ctr = 0xd172172;
1188 cpu->reset_sctlr = 0x00000078;
1189 }
1190
1191 static void pxa262_initfn(Object *obj)
1192 {
1193 ARMCPU *cpu = ARM_CPU(obj);
1194
1195 cpu->dtb_compatible = "marvell,xscale";
1196 set_feature(&cpu->env, ARM_FEATURE_V5);
1197 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1198 cpu->midr = 0x69052d06;
1199 cpu->ctr = 0xd172172;
1200 cpu->reset_sctlr = 0x00000078;
1201 }
1202
1203 static void pxa270a0_initfn(Object *obj)
1204 {
1205 ARMCPU *cpu = ARM_CPU(obj);
1206
1207 cpu->dtb_compatible = "marvell,xscale";
1208 set_feature(&cpu->env, ARM_FEATURE_V5);
1209 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1210 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1211 cpu->midr = 0x69054110;
1212 cpu->ctr = 0xd172172;
1213 cpu->reset_sctlr = 0x00000078;
1214 }
1215
1216 static void pxa270a1_initfn(Object *obj)
1217 {
1218 ARMCPU *cpu = ARM_CPU(obj);
1219
1220 cpu->dtb_compatible = "marvell,xscale";
1221 set_feature(&cpu->env, ARM_FEATURE_V5);
1222 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1223 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1224 cpu->midr = 0x69054111;
1225 cpu->ctr = 0xd172172;
1226 cpu->reset_sctlr = 0x00000078;
1227 }
1228
1229 static void pxa270b0_initfn(Object *obj)
1230 {
1231 ARMCPU *cpu = ARM_CPU(obj);
1232
1233 cpu->dtb_compatible = "marvell,xscale";
1234 set_feature(&cpu->env, ARM_FEATURE_V5);
1235 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1236 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1237 cpu->midr = 0x69054112;
1238 cpu->ctr = 0xd172172;
1239 cpu->reset_sctlr = 0x00000078;
1240 }
1241
1242 static void pxa270b1_initfn(Object *obj)
1243 {
1244 ARMCPU *cpu = ARM_CPU(obj);
1245
1246 cpu->dtb_compatible = "marvell,xscale";
1247 set_feature(&cpu->env, ARM_FEATURE_V5);
1248 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1249 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1250 cpu->midr = 0x69054113;
1251 cpu->ctr = 0xd172172;
1252 cpu->reset_sctlr = 0x00000078;
1253 }
1254
1255 static void pxa270c0_initfn(Object *obj)
1256 {
1257 ARMCPU *cpu = ARM_CPU(obj);
1258
1259 cpu->dtb_compatible = "marvell,xscale";
1260 set_feature(&cpu->env, ARM_FEATURE_V5);
1261 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1262 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1263 cpu->midr = 0x69054114;
1264 cpu->ctr = 0xd172172;
1265 cpu->reset_sctlr = 0x00000078;
1266 }
1267
1268 static void pxa270c5_initfn(Object *obj)
1269 {
1270 ARMCPU *cpu = ARM_CPU(obj);
1271
1272 cpu->dtb_compatible = "marvell,xscale";
1273 set_feature(&cpu->env, ARM_FEATURE_V5);
1274 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
1275 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
1276 cpu->midr = 0x69054117;
1277 cpu->ctr = 0xd172172;
1278 cpu->reset_sctlr = 0x00000078;
1279 }
1280
1281 #ifdef CONFIG_USER_ONLY
1282 static void arm_any_initfn(Object *obj)
1283 {
1284 ARMCPU *cpu = ARM_CPU(obj);
1285 set_feature(&cpu->env, ARM_FEATURE_V8);
1286 set_feature(&cpu->env, ARM_FEATURE_VFP4);
1287 set_feature(&cpu->env, ARM_FEATURE_NEON);
1288 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
1289 set_feature(&cpu->env, ARM_FEATURE_V8_AES);
1290 set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
1291 set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
1292 set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
1293 set_feature(&cpu->env, ARM_FEATURE_CRC);
1294 cpu->midr = 0xffffffff;
1295 }
1296 #endif
1297
1298 #endif /* !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64) */
1299
1300 typedef struct ARMCPUInfo {
1301 const char *name;
1302 void (*initfn)(Object *obj);
1303 void (*class_init)(ObjectClass *oc, void *data);
1304 } ARMCPUInfo;
1305
1306 static const ARMCPUInfo arm_cpus[] = {
1307 #if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64)
1308 { .name = "arm926", .initfn = arm926_initfn },
1309 { .name = "arm946", .initfn = arm946_initfn },
1310 { .name = "arm1026", .initfn = arm1026_initfn },
1311 /* What QEMU calls "arm1136-r2" is actually the 1136 r0p2, i.e. an
1312 * older core than plain "arm1136". In particular this does not
1313 * have the v6K features.
1314 */
1315 { .name = "arm1136-r2", .initfn = arm1136_r2_initfn },
1316 { .name = "arm1136", .initfn = arm1136_initfn },
1317 { .name = "arm1176", .initfn = arm1176_initfn },
1318 { .name = "arm11mpcore", .initfn = arm11mpcore_initfn },
1319 { .name = "cortex-m3", .initfn = cortex_m3_initfn,
1320 .class_init = arm_v7m_class_init },
1321 { .name = "cortex-m4", .initfn = cortex_m4_initfn,
1322 .class_init = arm_v7m_class_init },
1323 { .name = "cortex-r5", .initfn = cortex_r5_initfn },
1324 { .name = "cortex-a8", .initfn = cortex_a8_initfn },
1325 { .name = "cortex-a9", .initfn = cortex_a9_initfn },
1326 { .name = "cortex-a15", .initfn = cortex_a15_initfn },
1327 { .name = "ti925t", .initfn = ti925t_initfn },
1328 { .name = "sa1100", .initfn = sa1100_initfn },
1329 { .name = "sa1110", .initfn = sa1110_initfn },
1330 { .name = "pxa250", .initfn = pxa250_initfn },
1331 { .name = "pxa255", .initfn = pxa255_initfn },
1332 { .name = "pxa260", .initfn = pxa260_initfn },
1333 { .name = "pxa261", .initfn = pxa261_initfn },
1334 { .name = "pxa262", .initfn = pxa262_initfn },
1335 /* "pxa270" is an alias for "pxa270-a0" */
1336 { .name = "pxa270", .initfn = pxa270a0_initfn },
1337 { .name = "pxa270-a0", .initfn = pxa270a0_initfn },
1338 { .name = "pxa270-a1", .initfn = pxa270a1_initfn },
1339 { .name = "pxa270-b0", .initfn = pxa270b0_initfn },
1340 { .name = "pxa270-b1", .initfn = pxa270b1_initfn },
1341 { .name = "pxa270-c0", .initfn = pxa270c0_initfn },
1342 { .name = "pxa270-c5", .initfn = pxa270c5_initfn },
1343 #ifdef CONFIG_USER_ONLY
1344 { .name = "any", .initfn = arm_any_initfn },
1345 #endif
1346 #endif
1347 { .name = NULL }
1348 };
1349
1350 static Property arm_cpu_properties[] = {
1351 DEFINE_PROP_BOOL("start-powered-off", ARMCPU, start_powered_off, false),
1352 DEFINE_PROP_UINT32("psci-conduit", ARMCPU, psci_conduit, 0),
1353 DEFINE_PROP_UINT32("midr", ARMCPU, midr, 0),
1354 DEFINE_PROP_END_OF_LIST()
1355 };
1356
1357 #ifdef CONFIG_USER_ONLY
1358 static int arm_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
1359 int mmu_idx)
1360 {
1361 ARMCPU *cpu = ARM_CPU(cs);
1362 CPUARMState *env = &cpu->env;
1363
1364 env->exception.vaddress = address;
1365 if (rw == 2) {
1366 cs->exception_index = EXCP_PREFETCH_ABORT;
1367 } else {
1368 cs->exception_index = EXCP_DATA_ABORT;
1369 }
1370 return 1;
1371 }
1372 #endif
1373
1374 static void arm_cpu_class_init(ObjectClass *oc, void *data)
1375 {
1376 ARMCPUClass *acc = ARM_CPU_CLASS(oc);
1377 CPUClass *cc = CPU_CLASS(acc);
1378 DeviceClass *dc = DEVICE_CLASS(oc);
1379
1380 acc->parent_realize = dc->realize;
1381 dc->realize = arm_cpu_realizefn;
1382 dc->props = arm_cpu_properties;
1383
1384 acc->parent_reset = cc->reset;
1385 cc->reset = arm_cpu_reset;
1386
1387 cc->class_by_name = arm_cpu_class_by_name;
1388 cc->has_work = arm_cpu_has_work;
1389 cc->cpu_exec_interrupt = arm_cpu_exec_interrupt;
1390 cc->dump_state = arm_cpu_dump_state;
1391 cc->set_pc = arm_cpu_set_pc;
1392 cc->gdb_read_register = arm_cpu_gdb_read_register;
1393 cc->gdb_write_register = arm_cpu_gdb_write_register;
1394 #ifdef CONFIG_USER_ONLY
1395 cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;
1396 #else
1397 cc->do_interrupt = arm_cpu_do_interrupt;
1398 cc->get_phys_page_debug = arm_cpu_get_phys_page_debug;
1399 cc->vmsd = &vmstate_arm_cpu;
1400 cc->virtio_is_big_endian = arm_cpu_is_big_endian;
1401 #endif
1402 cc->gdb_num_core_regs = 26;
1403 cc->gdb_core_xml_file = "arm-core.xml";
1404 cc->gdb_stop_before_watchpoint = true;
1405 cc->debug_excp_handler = arm_debug_excp_handler;
1406
1407 cc->disas_set_info = arm_disas_set_info;
1408 }
1409
1410 static void cpu_register(const ARMCPUInfo *info)
1411 {
1412 TypeInfo type_info = {
1413 .parent = TYPE_ARM_CPU,
1414 .instance_size = sizeof(ARMCPU),
1415 .instance_init = info->initfn,
1416 .class_size = sizeof(ARMCPUClass),
1417 .class_init = info->class_init,
1418 };
1419
1420 type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
1421 type_register(&type_info);
1422 g_free((void *)type_info.name);
1423 }
1424
1425 static const TypeInfo arm_cpu_type_info = {
1426 .name = TYPE_ARM_CPU,
1427 .parent = TYPE_CPU,
1428 .instance_size = sizeof(ARMCPU),
1429 .instance_init = arm_cpu_initfn,
1430 .instance_post_init = arm_cpu_post_init,
1431 .instance_finalize = arm_cpu_finalizefn,
1432 .abstract = true,
1433 .class_size = sizeof(ARMCPUClass),
1434 .class_init = arm_cpu_class_init,
1435 };
1436
1437 static void arm_cpu_register_types(void)
1438 {
1439 const ARMCPUInfo *info = arm_cpus;
1440
1441 type_register_static(&arm_cpu_type_info);
1442
1443 while (info->name) {
1444 cpu_register(info);
1445 info++;
1446 }
1447 }
1448
1449 type_init(arm_cpu_register_types)