Merge remote-tracking branch 'afaerber/tags/qom-devices-for-anthony' into staging
[qemu/ar7.git] / target-microblaze / cpu.c
blobdce1c7ea67314fbf4a7f01b0d8a2e851f26f154e
1 /*
2 * QEMU MicroBlaze CPU
4 * Copyright (c) 2009 Edgar E. Iglesias
5 * Copyright (c) 2009-2012 PetaLogix Qld Pty Ltd.
6 * Copyright (c) 2012 SUSE LINUX Products GmbH
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, see
20 * <http://www.gnu.org/licenses/lgpl-2.1.html>
23 #include "cpu.h"
24 #include "qemu-common.h"
25 #include "hw/qdev-properties.h"
26 #include "migration/vmstate.h"
29 /* CPUClass::reset() */
30 static void mb_cpu_reset(CPUState *s)
32 MicroBlazeCPU *cpu = MICROBLAZE_CPU(s);
33 MicroBlazeCPUClass *mcc = MICROBLAZE_CPU_GET_CLASS(cpu);
34 CPUMBState *env = &cpu->env;
36 mcc->parent_reset(s);
38 memset(env, 0, offsetof(CPUMBState, breakpoints));
39 env->res_addr = RES_ADDR_NONE;
40 tlb_flush(env, 1);
42 /* Disable stack protector. */
43 env->shr = ~0;
45 env->pvr.regs[0] = PVR0_PVR_FULL_MASK \
46 | PVR0_USE_BARREL_MASK \
47 | PVR0_USE_DIV_MASK \
48 | PVR0_USE_HW_MUL_MASK \
49 | PVR0_USE_EXC_MASK \
50 | PVR0_USE_ICACHE_MASK \
51 | PVR0_USE_DCACHE_MASK \
52 | PVR0_USE_MMU \
53 | (0xb << 8);
54 env->pvr.regs[2] = PVR2_D_OPB_MASK \
55 | PVR2_D_LMB_MASK \
56 | PVR2_I_OPB_MASK \
57 | PVR2_I_LMB_MASK \
58 | PVR2_USE_MSR_INSTR \
59 | PVR2_USE_PCMP_INSTR \
60 | PVR2_USE_BARREL_MASK \
61 | PVR2_USE_DIV_MASK \
62 | PVR2_USE_HW_MUL_MASK \
63 | PVR2_USE_MUL64_MASK \
64 | PVR2_USE_FPU_MASK \
65 | PVR2_USE_FPU2_MASK \
66 | PVR2_FPU_EXC_MASK \
67 | 0;
68 env->pvr.regs[10] = 0x0c000000; /* Default to spartan 3a dsp family. */
69 env->pvr.regs[11] = PVR11_USE_MMU | (16 << 17);
71 #if defined(CONFIG_USER_ONLY)
72 /* start in user mode with interrupts enabled. */
73 env->sregs[SR_MSR] = MSR_EE | MSR_IE | MSR_VM | MSR_UM;
74 env->pvr.regs[10] = 0x0c000000; /* Spartan 3a dsp. */
75 #else
76 env->sregs[SR_MSR] = 0;
77 mmu_init(&env->mmu);
78 env->mmu.c_mmu = 3;
79 env->mmu.c_mmu_tlb_access = 3;
80 env->mmu.c_mmu_zones = 16;
81 #endif
84 static void mb_cpu_realizefn(DeviceState *dev, Error **errp)
86 MicroBlazeCPU *cpu = MICROBLAZE_CPU(dev);
87 MicroBlazeCPUClass *mcc = MICROBLAZE_CPU_GET_CLASS(dev);
89 cpu_reset(CPU(cpu));
91 mcc->parent_realize(dev, errp);
94 static void mb_cpu_initfn(Object *obj)
96 CPUState *cs = CPU(obj);
97 MicroBlazeCPU *cpu = MICROBLAZE_CPU(obj);
98 CPUMBState *env = &cpu->env;
99 static bool tcg_initialized;
101 cs->env_ptr = env;
102 cpu_exec_init(env);
104 set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
106 if (tcg_enabled() && !tcg_initialized) {
107 tcg_initialized = true;
108 mb_tcg_init();
112 static const VMStateDescription vmstate_mb_cpu = {
113 .name = "cpu",
114 .unmigratable = 1,
117 static Property mb_properties[] = {
118 DEFINE_PROP_UINT32("xlnx.base-vectors", MicroBlazeCPU, base_vectors, 0),
119 DEFINE_PROP_END_OF_LIST(),
122 static void mb_cpu_class_init(ObjectClass *oc, void *data)
124 DeviceClass *dc = DEVICE_CLASS(oc);
125 CPUClass *cc = CPU_CLASS(oc);
126 MicroBlazeCPUClass *mcc = MICROBLAZE_CPU_CLASS(oc);
128 mcc->parent_realize = dc->realize;
129 dc->realize = mb_cpu_realizefn;
131 mcc->parent_reset = cc->reset;
132 cc->reset = mb_cpu_reset;
134 cc->do_interrupt = mb_cpu_do_interrupt;
135 cc->dump_state = mb_cpu_dump_state;
136 cpu_class_set_do_unassigned_access(cc, mb_cpu_unassigned_access);
137 dc->vmsd = &vmstate_mb_cpu;
138 dc->props = mb_properties;
141 static const TypeInfo mb_cpu_type_info = {
142 .name = TYPE_MICROBLAZE_CPU,
143 .parent = TYPE_CPU,
144 .instance_size = sizeof(MicroBlazeCPU),
145 .instance_init = mb_cpu_initfn,
146 .class_size = sizeof(MicroBlazeCPUClass),
147 .class_init = mb_cpu_class_init,
150 static void mb_cpu_register_types(void)
152 type_register_static(&mb_cpu_type_info);
155 type_init(mb_cpu_register_types)