Merge remote-tracking branch 'bonzini/migration-writev' into staging
[qemu/ar7.git] / target-arm / cpu.c
blob496a59f5c0936d14c2875e6430c06ef5a3c4103a
1 /*
2 * QEMU ARM CPU
4 * Copyright (c) 2012 SUSE LINUX Products GmbH
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see
18 * <http://www.gnu.org/licenses/gpl-2.0.html>
21 #include "cpu.h"
22 #include "qemu-common.h"
23 #if !defined(CONFIG_USER_ONLY)
24 #include "hw/loader.h"
25 #endif
26 #include "sysemu/sysemu.h"
28 static void cp_reg_reset(gpointer key, gpointer value, gpointer opaque)
30 /* Reset a single ARMCPRegInfo register */
31 ARMCPRegInfo *ri = value;
32 ARMCPU *cpu = opaque;
34 if (ri->type & ARM_CP_SPECIAL) {
35 return;
38 if (ri->resetfn) {
39 ri->resetfn(&cpu->env, ri);
40 return;
43 /* A zero offset is never possible as it would be regs[0]
44 * so we use it to indicate that reset is being handled elsewhere.
45 * This is basically only used for fields in non-core coprocessors
46 * (like the pxa2xx ones).
48 if (!ri->fieldoffset) {
49 return;
52 if (ri->type & ARM_CP_64BIT) {
53 CPREG_FIELD64(&cpu->env, ri) = ri->resetvalue;
54 } else {
55 CPREG_FIELD32(&cpu->env, ri) = ri->resetvalue;
59 /* CPUClass::reset() */
60 static void arm_cpu_reset(CPUState *s)
62 ARMCPU *cpu = ARM_CPU(s);
63 ARMCPUClass *acc = ARM_CPU_GET_CLASS(cpu);
64 CPUARMState *env = &cpu->env;
66 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
67 qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
68 log_cpu_state(env, 0);
71 acc->parent_reset(s);
73 memset(env, 0, offsetof(CPUARMState, breakpoints));
74 g_hash_table_foreach(cpu->cp_regs, cp_reg_reset, cpu);
75 env->vfp.xregs[ARM_VFP_FPSID] = cpu->reset_fpsid;
76 env->vfp.xregs[ARM_VFP_MVFR0] = cpu->mvfr0;
77 env->vfp.xregs[ARM_VFP_MVFR1] = cpu->mvfr1;
79 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
80 env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
83 #if defined(CONFIG_USER_ONLY)
84 env->uncached_cpsr = ARM_CPU_MODE_USR;
85 /* For user mode we must enable access to coprocessors */
86 env->vfp.xregs[ARM_VFP_FPEXC] = 1 << 30;
87 if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
88 env->cp15.c15_cpar = 3;
89 } else if (arm_feature(env, ARM_FEATURE_XSCALE)) {
90 env->cp15.c15_cpar = 1;
92 #else
93 /* SVC mode with interrupts disabled. */
94 env->uncached_cpsr = ARM_CPU_MODE_SVC | CPSR_A | CPSR_F | CPSR_I;
95 /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
96 clear at reset. Initial SP and PC are loaded from ROM. */
97 if (IS_M(env)) {
98 uint32_t pc;
99 uint8_t *rom;
100 env->uncached_cpsr &= ~CPSR_I;
101 rom = rom_ptr(0);
102 if (rom) {
103 /* We should really use ldl_phys here, in case the guest
104 modified flash and reset itself. However images
105 loaded via -kernel have not been copied yet, so load the
106 values directly from there. */
107 env->regs[13] = ldl_p(rom);
108 pc = ldl_p(rom + 4);
109 env->thumb = pc & 1;
110 env->regs[15] = pc & ~1;
113 env->vfp.xregs[ARM_VFP_FPEXC] = 0;
114 #endif
115 set_flush_to_zero(1, &env->vfp.standard_fp_status);
116 set_flush_inputs_to_zero(1, &env->vfp.standard_fp_status);
117 set_default_nan_mode(1, &env->vfp.standard_fp_status);
118 set_float_detect_tininess(float_tininess_before_rounding,
119 &env->vfp.fp_status);
120 set_float_detect_tininess(float_tininess_before_rounding,
121 &env->vfp.standard_fp_status);
122 tlb_flush(env, 1);
123 /* Reset is a state change for some CPUARMState fields which we
124 * bake assumptions about into translated code, so we need to
125 * tb_flush().
127 tb_flush(env);
130 static inline void set_feature(CPUARMState *env, int feature)
132 env->features |= 1ULL << feature;
135 static void arm_cpu_initfn(Object *obj)
137 CPUState *cs = CPU(obj);
138 ARMCPU *cpu = ARM_CPU(obj);
139 static bool inited;
141 cs->env_ptr = &cpu->env;
142 cpu_exec_init(&cpu->env);
143 cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal,
144 g_free, g_free);
146 if (tcg_enabled() && !inited) {
147 inited = true;
148 arm_translate_init();
152 static void arm_cpu_finalizefn(Object *obj)
154 ARMCPU *cpu = ARM_CPU(obj);
155 g_hash_table_destroy(cpu->cp_regs);
158 static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
160 ARMCPU *cpu = ARM_CPU(dev);
161 ARMCPUClass *acc = ARM_CPU_GET_CLASS(dev);
162 CPUARMState *env = &cpu->env;
164 /* Some features automatically imply others: */
165 if (arm_feature(env, ARM_FEATURE_V7)) {
166 set_feature(env, ARM_FEATURE_VAPA);
167 set_feature(env, ARM_FEATURE_THUMB2);
168 set_feature(env, ARM_FEATURE_MPIDR);
169 if (!arm_feature(env, ARM_FEATURE_M)) {
170 set_feature(env, ARM_FEATURE_V6K);
171 } else {
172 set_feature(env, ARM_FEATURE_V6);
175 if (arm_feature(env, ARM_FEATURE_V6K)) {
176 set_feature(env, ARM_FEATURE_V6);
177 set_feature(env, ARM_FEATURE_MVFR);
179 if (arm_feature(env, ARM_FEATURE_V6)) {
180 set_feature(env, ARM_FEATURE_V5);
181 if (!arm_feature(env, ARM_FEATURE_M)) {
182 set_feature(env, ARM_FEATURE_AUXCR);
185 if (arm_feature(env, ARM_FEATURE_V5)) {
186 set_feature(env, ARM_FEATURE_V4T);
188 if (arm_feature(env, ARM_FEATURE_M)) {
189 set_feature(env, ARM_FEATURE_THUMB_DIV);
191 if (arm_feature(env, ARM_FEATURE_ARM_DIV)) {
192 set_feature(env, ARM_FEATURE_THUMB_DIV);
194 if (arm_feature(env, ARM_FEATURE_VFP4)) {
195 set_feature(env, ARM_FEATURE_VFP3);
197 if (arm_feature(env, ARM_FEATURE_VFP3)) {
198 set_feature(env, ARM_FEATURE_VFP);
200 if (arm_feature(env, ARM_FEATURE_LPAE)) {
201 set_feature(env, ARM_FEATURE_PXN);
204 register_cp_regs_for_features(cpu);
205 arm_cpu_register_gdb_regs_for_features(cpu);
207 cpu_reset(CPU(cpu));
208 qemu_init_vcpu(env);
210 acc->parent_realize(dev, errp);
213 /* CPU models */
215 static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
217 ObjectClass *oc;
218 char *typename;
220 if (!cpu_model) {
221 return NULL;
224 typename = g_strdup_printf("%s-" TYPE_ARM_CPU, cpu_model);
225 oc = object_class_by_name(typename);
226 g_free(typename);
227 if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
228 object_class_is_abstract(oc)) {
229 return NULL;
231 return oc;
234 static void arm926_initfn(Object *obj)
236 ARMCPU *cpu = ARM_CPU(obj);
237 set_feature(&cpu->env, ARM_FEATURE_V5);
238 set_feature(&cpu->env, ARM_FEATURE_VFP);
239 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
240 set_feature(&cpu->env, ARM_FEATURE_CACHE_TEST_CLEAN);
241 cpu->midr = 0x41069265;
242 cpu->reset_fpsid = 0x41011090;
243 cpu->ctr = 0x1dd20d2;
244 cpu->reset_sctlr = 0x00090078;
247 static void arm946_initfn(Object *obj)
249 ARMCPU *cpu = ARM_CPU(obj);
250 set_feature(&cpu->env, ARM_FEATURE_V5);
251 set_feature(&cpu->env, ARM_FEATURE_MPU);
252 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
253 cpu->midr = 0x41059461;
254 cpu->ctr = 0x0f004006;
255 cpu->reset_sctlr = 0x00000078;
258 static void arm1026_initfn(Object *obj)
260 ARMCPU *cpu = ARM_CPU(obj);
261 set_feature(&cpu->env, ARM_FEATURE_V5);
262 set_feature(&cpu->env, ARM_FEATURE_VFP);
263 set_feature(&cpu->env, ARM_FEATURE_AUXCR);
264 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
265 set_feature(&cpu->env, ARM_FEATURE_CACHE_TEST_CLEAN);
266 cpu->midr = 0x4106a262;
267 cpu->reset_fpsid = 0x410110a0;
268 cpu->ctr = 0x1dd20d2;
269 cpu->reset_sctlr = 0x00090078;
270 cpu->reset_auxcr = 1;
272 /* The 1026 had an IFAR at c6,c0,0,1 rather than the ARMv6 c6,c0,0,2 */
273 ARMCPRegInfo ifar = {
274 .name = "IFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 1,
275 .access = PL1_RW,
276 .fieldoffset = offsetof(CPUARMState, cp15.c6_insn),
277 .resetvalue = 0
279 define_one_arm_cp_reg(cpu, &ifar);
283 static void arm1136_r2_initfn(Object *obj)
285 ARMCPU *cpu = ARM_CPU(obj);
286 /* What qemu calls "arm1136_r2" is actually the 1136 r0p2, ie an
287 * older core than plain "arm1136". In particular this does not
288 * have the v6K features.
289 * These ID register values are correct for 1136 but may be wrong
290 * for 1136_r2 (in particular r0p2 does not actually implement most
291 * of the ID registers).
293 set_feature(&cpu->env, ARM_FEATURE_V6);
294 set_feature(&cpu->env, ARM_FEATURE_VFP);
295 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
296 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
297 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
298 cpu->midr = 0x4107b362;
299 cpu->reset_fpsid = 0x410120b4;
300 cpu->mvfr0 = 0x11111111;
301 cpu->mvfr1 = 0x00000000;
302 cpu->ctr = 0x1dd20d2;
303 cpu->reset_sctlr = 0x00050078;
304 cpu->id_pfr0 = 0x111;
305 cpu->id_pfr1 = 0x1;
306 cpu->id_dfr0 = 0x2;
307 cpu->id_afr0 = 0x3;
308 cpu->id_mmfr0 = 0x01130003;
309 cpu->id_mmfr1 = 0x10030302;
310 cpu->id_mmfr2 = 0x01222110;
311 cpu->id_isar0 = 0x00140011;
312 cpu->id_isar1 = 0x12002111;
313 cpu->id_isar2 = 0x11231111;
314 cpu->id_isar3 = 0x01102131;
315 cpu->id_isar4 = 0x141;
316 cpu->reset_auxcr = 7;
319 static void arm1136_initfn(Object *obj)
321 ARMCPU *cpu = ARM_CPU(obj);
322 set_feature(&cpu->env, ARM_FEATURE_V6K);
323 set_feature(&cpu->env, ARM_FEATURE_V6);
324 set_feature(&cpu->env, ARM_FEATURE_VFP);
325 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
326 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
327 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
328 cpu->midr = 0x4117b363;
329 cpu->reset_fpsid = 0x410120b4;
330 cpu->mvfr0 = 0x11111111;
331 cpu->mvfr1 = 0x00000000;
332 cpu->ctr = 0x1dd20d2;
333 cpu->reset_sctlr = 0x00050078;
334 cpu->id_pfr0 = 0x111;
335 cpu->id_pfr1 = 0x1;
336 cpu->id_dfr0 = 0x2;
337 cpu->id_afr0 = 0x3;
338 cpu->id_mmfr0 = 0x01130003;
339 cpu->id_mmfr1 = 0x10030302;
340 cpu->id_mmfr2 = 0x01222110;
341 cpu->id_isar0 = 0x00140011;
342 cpu->id_isar1 = 0x12002111;
343 cpu->id_isar2 = 0x11231111;
344 cpu->id_isar3 = 0x01102131;
345 cpu->id_isar4 = 0x141;
346 cpu->reset_auxcr = 7;
349 static void arm1176_initfn(Object *obj)
351 ARMCPU *cpu = ARM_CPU(obj);
352 set_feature(&cpu->env, ARM_FEATURE_V6K);
353 set_feature(&cpu->env, ARM_FEATURE_VFP);
354 set_feature(&cpu->env, ARM_FEATURE_VAPA);
355 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
356 set_feature(&cpu->env, ARM_FEATURE_CACHE_DIRTY_REG);
357 set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS);
358 cpu->midr = 0x410fb767;
359 cpu->reset_fpsid = 0x410120b5;
360 cpu->mvfr0 = 0x11111111;
361 cpu->mvfr1 = 0x00000000;
362 cpu->ctr = 0x1dd20d2;
363 cpu->reset_sctlr = 0x00050078;
364 cpu->id_pfr0 = 0x111;
365 cpu->id_pfr1 = 0x11;
366 cpu->id_dfr0 = 0x33;
367 cpu->id_afr0 = 0;
368 cpu->id_mmfr0 = 0x01130003;
369 cpu->id_mmfr1 = 0x10030302;
370 cpu->id_mmfr2 = 0x01222100;
371 cpu->id_isar0 = 0x0140011;
372 cpu->id_isar1 = 0x12002111;
373 cpu->id_isar2 = 0x11231121;
374 cpu->id_isar3 = 0x01102131;
375 cpu->id_isar4 = 0x01141;
376 cpu->reset_auxcr = 7;
379 static void arm11mpcore_initfn(Object *obj)
381 ARMCPU *cpu = ARM_CPU(obj);
382 set_feature(&cpu->env, ARM_FEATURE_V6K);
383 set_feature(&cpu->env, ARM_FEATURE_VFP);
384 set_feature(&cpu->env, ARM_FEATURE_VAPA);
385 set_feature(&cpu->env, ARM_FEATURE_MPIDR);
386 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
387 cpu->midr = 0x410fb022;
388 cpu->reset_fpsid = 0x410120b4;
389 cpu->mvfr0 = 0x11111111;
390 cpu->mvfr1 = 0x00000000;
391 cpu->ctr = 0x1d192992; /* 32K icache 32K dcache */
392 cpu->id_pfr0 = 0x111;
393 cpu->id_pfr1 = 0x1;
394 cpu->id_dfr0 = 0;
395 cpu->id_afr0 = 0x2;
396 cpu->id_mmfr0 = 0x01100103;
397 cpu->id_mmfr1 = 0x10020302;
398 cpu->id_mmfr2 = 0x01222000;
399 cpu->id_isar0 = 0x00100011;
400 cpu->id_isar1 = 0x12002111;
401 cpu->id_isar2 = 0x11221011;
402 cpu->id_isar3 = 0x01102131;
403 cpu->id_isar4 = 0x141;
404 cpu->reset_auxcr = 1;
407 static void cortex_m3_initfn(Object *obj)
409 ARMCPU *cpu = ARM_CPU(obj);
410 set_feature(&cpu->env, ARM_FEATURE_V7);
411 set_feature(&cpu->env, ARM_FEATURE_M);
412 cpu->midr = 0x410fc231;
415 static void arm_v7m_class_init(ObjectClass *oc, void *data)
417 #ifndef CONFIG_USER_ONLY
418 CPUClass *cc = CPU_CLASS(oc);
420 cc->do_interrupt = arm_v7m_cpu_do_interrupt;
421 #endif
424 static const ARMCPRegInfo cortexa8_cp_reginfo[] = {
425 { .name = "L2LOCKDOWN", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 0,
426 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
427 { .name = "L2AUXCR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 2,
428 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
429 REGINFO_SENTINEL
432 static void cortex_a8_initfn(Object *obj)
434 ARMCPU *cpu = ARM_CPU(obj);
435 set_feature(&cpu->env, ARM_FEATURE_V7);
436 set_feature(&cpu->env, ARM_FEATURE_VFP3);
437 set_feature(&cpu->env, ARM_FEATURE_NEON);
438 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
439 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
440 cpu->midr = 0x410fc080;
441 cpu->reset_fpsid = 0x410330c0;
442 cpu->mvfr0 = 0x11110222;
443 cpu->mvfr1 = 0x00011100;
444 cpu->ctr = 0x82048004;
445 cpu->reset_sctlr = 0x00c50078;
446 cpu->id_pfr0 = 0x1031;
447 cpu->id_pfr1 = 0x11;
448 cpu->id_dfr0 = 0x400;
449 cpu->id_afr0 = 0;
450 cpu->id_mmfr0 = 0x31100003;
451 cpu->id_mmfr1 = 0x20000000;
452 cpu->id_mmfr2 = 0x01202000;
453 cpu->id_mmfr3 = 0x11;
454 cpu->id_isar0 = 0x00101111;
455 cpu->id_isar1 = 0x12112111;
456 cpu->id_isar2 = 0x21232031;
457 cpu->id_isar3 = 0x11112131;
458 cpu->id_isar4 = 0x00111142;
459 cpu->clidr = (1 << 27) | (2 << 24) | 3;
460 cpu->ccsidr[0] = 0xe007e01a; /* 16k L1 dcache. */
461 cpu->ccsidr[1] = 0x2007e01a; /* 16k L1 icache. */
462 cpu->ccsidr[2] = 0xf0000000; /* No L2 icache. */
463 cpu->reset_auxcr = 2;
464 define_arm_cp_regs(cpu, cortexa8_cp_reginfo);
467 static const ARMCPRegInfo cortexa9_cp_reginfo[] = {
468 /* power_control should be set to maximum latency. Again,
469 * default to 0 and set by private hook
471 { .name = "A9_PWRCTL", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 0,
472 .access = PL1_RW, .resetvalue = 0,
473 .fieldoffset = offsetof(CPUARMState, cp15.c15_power_control) },
474 { .name = "A9_DIAG", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 1,
475 .access = PL1_RW, .resetvalue = 0,
476 .fieldoffset = offsetof(CPUARMState, cp15.c15_diagnostic) },
477 { .name = "A9_PWRDIAG", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 2,
478 .access = PL1_RW, .resetvalue = 0,
479 .fieldoffset = offsetof(CPUARMState, cp15.c15_power_diagnostic) },
480 { .name = "NEONBUSY", .cp = 15, .crn = 15, .crm = 1, .opc1 = 0, .opc2 = 0,
481 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
482 /* TLB lockdown control */
483 { .name = "TLB_LOCKR", .cp = 15, .crn = 15, .crm = 4, .opc1 = 5, .opc2 = 2,
484 .access = PL1_W, .resetvalue = 0, .type = ARM_CP_NOP },
485 { .name = "TLB_LOCKW", .cp = 15, .crn = 15, .crm = 4, .opc1 = 5, .opc2 = 4,
486 .access = PL1_W, .resetvalue = 0, .type = ARM_CP_NOP },
487 { .name = "TLB_VA", .cp = 15, .crn = 15, .crm = 5, .opc1 = 5, .opc2 = 2,
488 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
489 { .name = "TLB_PA", .cp = 15, .crn = 15, .crm = 6, .opc1 = 5, .opc2 = 2,
490 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
491 { .name = "TLB_ATTR", .cp = 15, .crn = 15, .crm = 7, .opc1 = 5, .opc2 = 2,
492 .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST },
493 REGINFO_SENTINEL
496 static void cortex_a9_initfn(Object *obj)
498 ARMCPU *cpu = ARM_CPU(obj);
499 set_feature(&cpu->env, ARM_FEATURE_V7);
500 set_feature(&cpu->env, ARM_FEATURE_VFP3);
501 set_feature(&cpu->env, ARM_FEATURE_VFP_FP16);
502 set_feature(&cpu->env, ARM_FEATURE_NEON);
503 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
504 /* Note that A9 supports the MP extensions even for
505 * A9UP and single-core A9MP (which are both different
506 * and valid configurations; we don't model A9UP).
508 set_feature(&cpu->env, ARM_FEATURE_V7MP);
509 cpu->midr = 0x410fc090;
510 cpu->reset_fpsid = 0x41033090;
511 cpu->mvfr0 = 0x11110222;
512 cpu->mvfr1 = 0x01111111;
513 cpu->ctr = 0x80038003;
514 cpu->reset_sctlr = 0x00c50078;
515 cpu->id_pfr0 = 0x1031;
516 cpu->id_pfr1 = 0x11;
517 cpu->id_dfr0 = 0x000;
518 cpu->id_afr0 = 0;
519 cpu->id_mmfr0 = 0x00100103;
520 cpu->id_mmfr1 = 0x20000000;
521 cpu->id_mmfr2 = 0x01230000;
522 cpu->id_mmfr3 = 0x00002111;
523 cpu->id_isar0 = 0x00101111;
524 cpu->id_isar1 = 0x13112111;
525 cpu->id_isar2 = 0x21232041;
526 cpu->id_isar3 = 0x11112131;
527 cpu->id_isar4 = 0x00111142;
528 cpu->clidr = (1 << 27) | (1 << 24) | 3;
529 cpu->ccsidr[0] = 0xe00fe015; /* 16k L1 dcache. */
530 cpu->ccsidr[1] = 0x200fe015; /* 16k L1 icache. */
532 ARMCPRegInfo cbar = {
533 .name = "CBAR", .cp = 15, .crn = 15, .crm = 0, .opc1 = 4,
534 .opc2 = 0, .access = PL1_R|PL3_W, .resetvalue = cpu->reset_cbar,
535 .fieldoffset = offsetof(CPUARMState, cp15.c15_config_base_address)
537 define_one_arm_cp_reg(cpu, &cbar);
538 define_arm_cp_regs(cpu, cortexa9_cp_reginfo);
542 #ifndef CONFIG_USER_ONLY
543 static int a15_l2ctlr_read(CPUARMState *env, const ARMCPRegInfo *ri,
544 uint64_t *value)
546 /* Linux wants the number of processors from here.
547 * Might as well set the interrupt-controller bit too.
549 *value = ((smp_cpus - 1) << 24) | (1 << 23);
550 return 0;
552 #endif
554 static const ARMCPRegInfo cortexa15_cp_reginfo[] = {
555 #ifndef CONFIG_USER_ONLY
556 { .name = "L2CTLR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 2,
557 .access = PL1_RW, .resetvalue = 0, .readfn = a15_l2ctlr_read,
558 .writefn = arm_cp_write_ignore, },
559 #endif
560 { .name = "L2ECTLR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 3,
561 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
562 REGINFO_SENTINEL
565 static void cortex_a15_initfn(Object *obj)
567 ARMCPU *cpu = ARM_CPU(obj);
568 set_feature(&cpu->env, ARM_FEATURE_V7);
569 set_feature(&cpu->env, ARM_FEATURE_VFP4);
570 set_feature(&cpu->env, ARM_FEATURE_VFP_FP16);
571 set_feature(&cpu->env, ARM_FEATURE_NEON);
572 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
573 set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);
574 set_feature(&cpu->env, ARM_FEATURE_V7MP);
575 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
576 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
577 set_feature(&cpu->env, ARM_FEATURE_LPAE);
578 cpu->midr = 0x412fc0f1;
579 cpu->reset_fpsid = 0x410430f0;
580 cpu->mvfr0 = 0x10110222;
581 cpu->mvfr1 = 0x11111111;
582 cpu->ctr = 0x8444c004;
583 cpu->reset_sctlr = 0x00c50078;
584 cpu->id_pfr0 = 0x00001131;
585 cpu->id_pfr1 = 0x00011011;
586 cpu->id_dfr0 = 0x02010555;
587 cpu->id_afr0 = 0x00000000;
588 cpu->id_mmfr0 = 0x10201105;
589 cpu->id_mmfr1 = 0x20000000;
590 cpu->id_mmfr2 = 0x01240000;
591 cpu->id_mmfr3 = 0x02102211;
592 cpu->id_isar0 = 0x02101110;
593 cpu->id_isar1 = 0x13112111;
594 cpu->id_isar2 = 0x21232041;
595 cpu->id_isar3 = 0x11112131;
596 cpu->id_isar4 = 0x10011142;
597 cpu->clidr = 0x0a200023;
598 cpu->ccsidr[0] = 0x701fe00a; /* 32K L1 dcache */
599 cpu->ccsidr[1] = 0x201fe00a; /* 32K L1 icache */
600 cpu->ccsidr[2] = 0x711fe07a; /* 4096K L2 unified cache */
601 define_arm_cp_regs(cpu, cortexa15_cp_reginfo);
604 static void ti925t_initfn(Object *obj)
606 ARMCPU *cpu = ARM_CPU(obj);
607 set_feature(&cpu->env, ARM_FEATURE_V4T);
608 set_feature(&cpu->env, ARM_FEATURE_OMAPCP);
609 cpu->midr = ARM_CPUID_TI925T;
610 cpu->ctr = 0x5109149;
611 cpu->reset_sctlr = 0x00000070;
614 static void sa1100_initfn(Object *obj)
616 ARMCPU *cpu = ARM_CPU(obj);
617 set_feature(&cpu->env, ARM_FEATURE_STRONGARM);
618 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
619 cpu->midr = 0x4401A11B;
620 cpu->reset_sctlr = 0x00000070;
623 static void sa1110_initfn(Object *obj)
625 ARMCPU *cpu = ARM_CPU(obj);
626 set_feature(&cpu->env, ARM_FEATURE_STRONGARM);
627 set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
628 cpu->midr = 0x6901B119;
629 cpu->reset_sctlr = 0x00000070;
632 static void pxa250_initfn(Object *obj)
634 ARMCPU *cpu = ARM_CPU(obj);
635 set_feature(&cpu->env, ARM_FEATURE_V5);
636 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
637 cpu->midr = 0x69052100;
638 cpu->ctr = 0xd172172;
639 cpu->reset_sctlr = 0x00000078;
642 static void pxa255_initfn(Object *obj)
644 ARMCPU *cpu = ARM_CPU(obj);
645 set_feature(&cpu->env, ARM_FEATURE_V5);
646 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
647 cpu->midr = 0x69052d00;
648 cpu->ctr = 0xd172172;
649 cpu->reset_sctlr = 0x00000078;
652 static void pxa260_initfn(Object *obj)
654 ARMCPU *cpu = ARM_CPU(obj);
655 set_feature(&cpu->env, ARM_FEATURE_V5);
656 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
657 cpu->midr = 0x69052903;
658 cpu->ctr = 0xd172172;
659 cpu->reset_sctlr = 0x00000078;
662 static void pxa261_initfn(Object *obj)
664 ARMCPU *cpu = ARM_CPU(obj);
665 set_feature(&cpu->env, ARM_FEATURE_V5);
666 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
667 cpu->midr = 0x69052d05;
668 cpu->ctr = 0xd172172;
669 cpu->reset_sctlr = 0x00000078;
672 static void pxa262_initfn(Object *obj)
674 ARMCPU *cpu = ARM_CPU(obj);
675 set_feature(&cpu->env, ARM_FEATURE_V5);
676 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
677 cpu->midr = 0x69052d06;
678 cpu->ctr = 0xd172172;
679 cpu->reset_sctlr = 0x00000078;
682 static void pxa270a0_initfn(Object *obj)
684 ARMCPU *cpu = ARM_CPU(obj);
685 set_feature(&cpu->env, ARM_FEATURE_V5);
686 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
687 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
688 cpu->midr = 0x69054110;
689 cpu->ctr = 0xd172172;
690 cpu->reset_sctlr = 0x00000078;
693 static void pxa270a1_initfn(Object *obj)
695 ARMCPU *cpu = ARM_CPU(obj);
696 set_feature(&cpu->env, ARM_FEATURE_V5);
697 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
698 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
699 cpu->midr = 0x69054111;
700 cpu->ctr = 0xd172172;
701 cpu->reset_sctlr = 0x00000078;
704 static void pxa270b0_initfn(Object *obj)
706 ARMCPU *cpu = ARM_CPU(obj);
707 set_feature(&cpu->env, ARM_FEATURE_V5);
708 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
709 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
710 cpu->midr = 0x69054112;
711 cpu->ctr = 0xd172172;
712 cpu->reset_sctlr = 0x00000078;
715 static void pxa270b1_initfn(Object *obj)
717 ARMCPU *cpu = ARM_CPU(obj);
718 set_feature(&cpu->env, ARM_FEATURE_V5);
719 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
720 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
721 cpu->midr = 0x69054113;
722 cpu->ctr = 0xd172172;
723 cpu->reset_sctlr = 0x00000078;
726 static void pxa270c0_initfn(Object *obj)
728 ARMCPU *cpu = ARM_CPU(obj);
729 set_feature(&cpu->env, ARM_FEATURE_V5);
730 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
731 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
732 cpu->midr = 0x69054114;
733 cpu->ctr = 0xd172172;
734 cpu->reset_sctlr = 0x00000078;
737 static void pxa270c5_initfn(Object *obj)
739 ARMCPU *cpu = ARM_CPU(obj);
740 set_feature(&cpu->env, ARM_FEATURE_V5);
741 set_feature(&cpu->env, ARM_FEATURE_XSCALE);
742 set_feature(&cpu->env, ARM_FEATURE_IWMMXT);
743 cpu->midr = 0x69054117;
744 cpu->ctr = 0xd172172;
745 cpu->reset_sctlr = 0x00000078;
748 static void arm_any_initfn(Object *obj)
750 ARMCPU *cpu = ARM_CPU(obj);
751 set_feature(&cpu->env, ARM_FEATURE_V7);
752 set_feature(&cpu->env, ARM_FEATURE_VFP4);
753 set_feature(&cpu->env, ARM_FEATURE_VFP_FP16);
754 set_feature(&cpu->env, ARM_FEATURE_NEON);
755 set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
756 set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);
757 set_feature(&cpu->env, ARM_FEATURE_V7MP);
758 cpu->midr = 0xffffffff;
761 typedef struct ARMCPUInfo {
762 const char *name;
763 void (*initfn)(Object *obj);
764 void (*class_init)(ObjectClass *oc, void *data);
765 } ARMCPUInfo;
767 static const ARMCPUInfo arm_cpus[] = {
768 { .name = "arm926", .initfn = arm926_initfn },
769 { .name = "arm946", .initfn = arm946_initfn },
770 { .name = "arm1026", .initfn = arm1026_initfn },
771 /* What QEMU calls "arm1136-r2" is actually the 1136 r0p2, i.e. an
772 * older core than plain "arm1136". In particular this does not
773 * have the v6K features.
775 { .name = "arm1136-r2", .initfn = arm1136_r2_initfn },
776 { .name = "arm1136", .initfn = arm1136_initfn },
777 { .name = "arm1176", .initfn = arm1176_initfn },
778 { .name = "arm11mpcore", .initfn = arm11mpcore_initfn },
779 { .name = "cortex-m3", .initfn = cortex_m3_initfn,
780 .class_init = arm_v7m_class_init },
781 { .name = "cortex-a8", .initfn = cortex_a8_initfn },
782 { .name = "cortex-a9", .initfn = cortex_a9_initfn },
783 { .name = "cortex-a15", .initfn = cortex_a15_initfn },
784 { .name = "ti925t", .initfn = ti925t_initfn },
785 { .name = "sa1100", .initfn = sa1100_initfn },
786 { .name = "sa1110", .initfn = sa1110_initfn },
787 { .name = "pxa250", .initfn = pxa250_initfn },
788 { .name = "pxa255", .initfn = pxa255_initfn },
789 { .name = "pxa260", .initfn = pxa260_initfn },
790 { .name = "pxa261", .initfn = pxa261_initfn },
791 { .name = "pxa262", .initfn = pxa262_initfn },
792 /* "pxa270" is an alias for "pxa270-a0" */
793 { .name = "pxa270", .initfn = pxa270a0_initfn },
794 { .name = "pxa270-a0", .initfn = pxa270a0_initfn },
795 { .name = "pxa270-a1", .initfn = pxa270a1_initfn },
796 { .name = "pxa270-b0", .initfn = pxa270b0_initfn },
797 { .name = "pxa270-b1", .initfn = pxa270b1_initfn },
798 { .name = "pxa270-c0", .initfn = pxa270c0_initfn },
799 { .name = "pxa270-c5", .initfn = pxa270c5_initfn },
800 { .name = "any", .initfn = arm_any_initfn },
803 static void arm_cpu_class_init(ObjectClass *oc, void *data)
805 ARMCPUClass *acc = ARM_CPU_CLASS(oc);
806 CPUClass *cc = CPU_CLASS(acc);
807 DeviceClass *dc = DEVICE_CLASS(oc);
809 acc->parent_realize = dc->realize;
810 dc->realize = arm_cpu_realizefn;
812 acc->parent_reset = cc->reset;
813 cc->reset = arm_cpu_reset;
815 cc->class_by_name = arm_cpu_class_by_name;
816 cc->do_interrupt = arm_cpu_do_interrupt;
817 cpu_class_set_vmsd(cc, &vmstate_arm_cpu);
820 static void cpu_register(const ARMCPUInfo *info)
822 TypeInfo type_info = {
823 .parent = TYPE_ARM_CPU,
824 .instance_size = sizeof(ARMCPU),
825 .instance_init = info->initfn,
826 .class_size = sizeof(ARMCPUClass),
827 .class_init = info->class_init,
830 type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
831 type_register(&type_info);
832 g_free((void *)type_info.name);
835 static const TypeInfo arm_cpu_type_info = {
836 .name = TYPE_ARM_CPU,
837 .parent = TYPE_CPU,
838 .instance_size = sizeof(ARMCPU),
839 .instance_init = arm_cpu_initfn,
840 .instance_finalize = arm_cpu_finalizefn,
841 .abstract = true,
842 .class_size = sizeof(ARMCPUClass),
843 .class_init = arm_cpu_class_init,
846 static void arm_cpu_register_types(void)
848 int i;
850 type_register_static(&arm_cpu_type_info);
851 for (i = 0; i < ARRAY_SIZE(arm_cpus); i++) {
852 cpu_register(&arm_cpus[i]);
856 type_init(arm_cpu_register_types)