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