spapr, pnv, xive: Add a "xive-fabric" link to the XIVE router
[qemu/ar7.git] / target / m68k / cpu.c
blobf276335faf9e0f308708d180eeb0255cf8e72bc4
1 /*
2 * QEMU Motorola 68k CPU
4 * Copyright (c) 2012 SUSE LINUX Products GmbH
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see
18 * <http://www.gnu.org/licenses/lgpl-2.1.html>
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
23 #include "cpu.h"
24 #include "migration/vmstate.h"
25 #include "fpu/softfloat.h"
27 static void m68k_cpu_set_pc(CPUState *cs, vaddr value)
29 M68kCPU *cpu = M68K_CPU(cs);
31 cpu->env.pc = value;
34 static bool m68k_cpu_has_work(CPUState *cs)
36 return cs->interrupt_request & CPU_INTERRUPT_HARD;
39 static void m68k_set_feature(CPUM68KState *env, int feature)
41 env->features |= (1u << feature);
44 /* CPUClass::reset() */
45 static void m68k_cpu_reset(CPUState *s)
47 M68kCPU *cpu = M68K_CPU(s);
48 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(cpu);
49 CPUM68KState *env = &cpu->env;
50 floatx80 nan = floatx80_default_nan(NULL);
51 int i;
53 mcc->parent_reset(s);
55 memset(env, 0, offsetof(CPUM68KState, end_reset_fields));
56 #ifdef CONFIG_SOFTMMU
57 cpu_m68k_set_sr(env, SR_S | SR_I);
58 #else
59 cpu_m68k_set_sr(env, 0);
60 #endif
61 for (i = 0; i < 8; i++) {
62 env->fregs[i].d = nan;
64 cpu_m68k_set_fpcr(env, 0);
65 env->fpsr = 0;
67 /* TODO: We should set PC from the interrupt vector. */
68 env->pc = 0;
71 static void m68k_cpu_disas_set_info(CPUState *s, disassemble_info *info)
73 M68kCPU *cpu = M68K_CPU(s);
74 CPUM68KState *env = &cpu->env;
75 info->print_insn = print_insn_m68k;
76 if (m68k_feature(env, M68K_FEATURE_M68000)) {
77 info->mach = bfd_mach_m68040;
81 /* CPU models */
83 static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
85 ObjectClass *oc;
86 char *typename;
88 typename = g_strdup_printf(M68K_CPU_TYPE_NAME("%s"), cpu_model);
89 oc = object_class_by_name(typename);
90 g_free(typename);
91 if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL ||
92 object_class_is_abstract(oc))) {
93 return NULL;
95 return oc;
98 static void m5206_cpu_initfn(Object *obj)
100 M68kCPU *cpu = M68K_CPU(obj);
101 CPUM68KState *env = &cpu->env;
103 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
106 static void m68000_cpu_initfn(Object *obj)
108 M68kCPU *cpu = M68K_CPU(obj);
109 CPUM68KState *env = &cpu->env;
111 m68k_set_feature(env, M68K_FEATURE_M68000);
112 m68k_set_feature(env, M68K_FEATURE_USP);
113 m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
114 m68k_set_feature(env, M68K_FEATURE_MOVEP);
117 /* common features for 68020, 68030 and 68040 */
118 static void m680x0_cpu_common(CPUM68KState *env)
120 m68k_set_feature(env, M68K_FEATURE_M68000);
121 m68k_set_feature(env, M68K_FEATURE_USP);
122 m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
123 m68k_set_feature(env, M68K_FEATURE_QUAD_MULDIV);
124 m68k_set_feature(env, M68K_FEATURE_BRAL);
125 m68k_set_feature(env, M68K_FEATURE_BCCL);
126 m68k_set_feature(env, M68K_FEATURE_BITFIELD);
127 m68k_set_feature(env, M68K_FEATURE_EXT_FULL);
128 m68k_set_feature(env, M68K_FEATURE_SCALED_INDEX);
129 m68k_set_feature(env, M68K_FEATURE_LONG_MULDIV);
130 m68k_set_feature(env, M68K_FEATURE_FPU);
131 m68k_set_feature(env, M68K_FEATURE_CAS);
132 m68k_set_feature(env, M68K_FEATURE_BKPT);
133 m68k_set_feature(env, M68K_FEATURE_RTD);
134 m68k_set_feature(env, M68K_FEATURE_CHK2);
135 m68k_set_feature(env, M68K_FEATURE_MOVEP);
138 static void m68020_cpu_initfn(Object *obj)
140 M68kCPU *cpu = M68K_CPU(obj);
141 CPUM68KState *env = &cpu->env;
143 m680x0_cpu_common(env);
144 m68k_set_feature(env, M68K_FEATURE_M68020);
147 static void m68030_cpu_initfn(Object *obj)
149 M68kCPU *cpu = M68K_CPU(obj);
150 CPUM68KState *env = &cpu->env;
152 m680x0_cpu_common(env);
153 m68k_set_feature(env, M68K_FEATURE_M68030);
156 static void m68040_cpu_initfn(Object *obj)
158 M68kCPU *cpu = M68K_CPU(obj);
159 CPUM68KState *env = &cpu->env;
161 m680x0_cpu_common(env);
162 m68k_set_feature(env, M68K_FEATURE_M68040);
165 static void m68060_cpu_initfn(Object *obj)
167 M68kCPU *cpu = M68K_CPU(obj);
168 CPUM68KState *env = &cpu->env;
170 m68k_set_feature(env, M68K_FEATURE_M68000);
171 m68k_set_feature(env, M68K_FEATURE_USP);
172 m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
173 m68k_set_feature(env, M68K_FEATURE_BRAL);
174 m68k_set_feature(env, M68K_FEATURE_BCCL);
175 m68k_set_feature(env, M68K_FEATURE_BITFIELD);
176 m68k_set_feature(env, M68K_FEATURE_EXT_FULL);
177 m68k_set_feature(env, M68K_FEATURE_SCALED_INDEX);
178 m68k_set_feature(env, M68K_FEATURE_LONG_MULDIV);
179 m68k_set_feature(env, M68K_FEATURE_FPU);
180 m68k_set_feature(env, M68K_FEATURE_CAS);
181 m68k_set_feature(env, M68K_FEATURE_BKPT);
182 m68k_set_feature(env, M68K_FEATURE_RTD);
183 m68k_set_feature(env, M68K_FEATURE_CHK2);
184 m68k_set_feature(env, M68K_FEATURE_M68060);
187 static void m5208_cpu_initfn(Object *obj)
189 M68kCPU *cpu = M68K_CPU(obj);
190 CPUM68KState *env = &cpu->env;
192 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
193 m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC);
194 m68k_set_feature(env, M68K_FEATURE_BRAL);
195 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
196 m68k_set_feature(env, M68K_FEATURE_USP);
199 static void cfv4e_cpu_initfn(Object *obj)
201 M68kCPU *cpu = M68K_CPU(obj);
202 CPUM68KState *env = &cpu->env;
204 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
205 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
206 m68k_set_feature(env, M68K_FEATURE_BRAL);
207 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
208 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
209 m68k_set_feature(env, M68K_FEATURE_USP);
212 static void any_cpu_initfn(Object *obj)
214 M68kCPU *cpu = M68K_CPU(obj);
215 CPUM68KState *env = &cpu->env;
217 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
218 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
219 m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC);
220 m68k_set_feature(env, M68K_FEATURE_BRAL);
221 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
223 * MAC and EMAC are mututally exclusive, so pick EMAC.
224 * It's mostly backwards compatible.
226 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
227 m68k_set_feature(env, M68K_FEATURE_CF_EMAC_B);
228 m68k_set_feature(env, M68K_FEATURE_USP);
229 m68k_set_feature(env, M68K_FEATURE_EXT_FULL);
230 m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
233 static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
235 CPUState *cs = CPU(dev);
236 M68kCPU *cpu = M68K_CPU(dev);
237 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(dev);
238 Error *local_err = NULL;
240 register_m68k_insns(&cpu->env);
242 cpu_exec_realizefn(cs, &local_err);
243 if (local_err != NULL) {
244 error_propagate(errp, local_err);
245 return;
248 m68k_cpu_init_gdb(cpu);
250 cpu_reset(cs);
251 qemu_init_vcpu(cs);
253 mcc->parent_realize(dev, errp);
256 static void m68k_cpu_initfn(Object *obj)
258 M68kCPU *cpu = M68K_CPU(obj);
260 cpu_set_cpustate_pointers(cpu);
263 static const VMStateDescription vmstate_m68k_cpu = {
264 .name = "cpu",
265 .unmigratable = 1,
268 static void m68k_cpu_class_init(ObjectClass *c, void *data)
270 M68kCPUClass *mcc = M68K_CPU_CLASS(c);
271 CPUClass *cc = CPU_CLASS(c);
272 DeviceClass *dc = DEVICE_CLASS(c);
274 device_class_set_parent_realize(dc, m68k_cpu_realizefn,
275 &mcc->parent_realize);
276 mcc->parent_reset = cc->reset;
277 cc->reset = m68k_cpu_reset;
279 cc->class_by_name = m68k_cpu_class_by_name;
280 cc->has_work = m68k_cpu_has_work;
281 cc->do_interrupt = m68k_cpu_do_interrupt;
282 cc->cpu_exec_interrupt = m68k_cpu_exec_interrupt;
283 cc->dump_state = m68k_cpu_dump_state;
284 cc->set_pc = m68k_cpu_set_pc;
285 cc->gdb_read_register = m68k_cpu_gdb_read_register;
286 cc->gdb_write_register = m68k_cpu_gdb_write_register;
287 cc->tlb_fill = m68k_cpu_tlb_fill;
288 #if defined(CONFIG_SOFTMMU)
289 cc->do_transaction_failed = m68k_cpu_transaction_failed;
290 cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug;
291 #endif
292 cc->disas_set_info = m68k_cpu_disas_set_info;
293 cc->tcg_initialize = m68k_tcg_init;
295 cc->gdb_num_core_regs = 18;
296 cc->gdb_core_xml_file = "cf-core.xml";
298 dc->vmsd = &vmstate_m68k_cpu;
301 #define DEFINE_M68K_CPU_TYPE(cpu_model, initfn) \
303 .name = M68K_CPU_TYPE_NAME(cpu_model), \
304 .instance_init = initfn, \
305 .parent = TYPE_M68K_CPU, \
308 static const TypeInfo m68k_cpus_type_infos[] = {
309 { /* base class should be registered first */
310 .name = TYPE_M68K_CPU,
311 .parent = TYPE_CPU,
312 .instance_size = sizeof(M68kCPU),
313 .instance_init = m68k_cpu_initfn,
314 .abstract = true,
315 .class_size = sizeof(M68kCPUClass),
316 .class_init = m68k_cpu_class_init,
318 DEFINE_M68K_CPU_TYPE("m68000", m68000_cpu_initfn),
319 DEFINE_M68K_CPU_TYPE("m68020", m68020_cpu_initfn),
320 DEFINE_M68K_CPU_TYPE("m68030", m68030_cpu_initfn),
321 DEFINE_M68K_CPU_TYPE("m68040", m68040_cpu_initfn),
322 DEFINE_M68K_CPU_TYPE("m68060", m68060_cpu_initfn),
323 DEFINE_M68K_CPU_TYPE("m5206", m5206_cpu_initfn),
324 DEFINE_M68K_CPU_TYPE("m5208", m5208_cpu_initfn),
325 DEFINE_M68K_CPU_TYPE("cfv4e", cfv4e_cpu_initfn),
326 DEFINE_M68K_CPU_TYPE("any", any_cpu_initfn),
329 DEFINE_TYPES(m68k_cpus_type_infos)