Merge remote-tracking branch 'luiz/queue/qmp' into staging
[qemu/ar7.git] / target-m68k / cpu.c
blob1b6ef664f598ea7fd4cd58471ea9c0c56b824eaa
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 "cpu.h"
22 #include "qemu-common.h"
23 #include "migration/vmstate.h"
26 static void m68k_set_feature(CPUM68KState *env, int feature)
28 env->features |= (1u << feature);
31 /* CPUClass::reset() */
32 static void m68k_cpu_reset(CPUState *s)
34 M68kCPU *cpu = M68K_CPU(s);
35 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(cpu);
36 CPUM68KState *env = &cpu->env;
38 mcc->parent_reset(s);
40 memset(env, 0, offsetof(CPUM68KState, breakpoints));
41 #if !defined(CONFIG_USER_ONLY)
42 env->sr = 0x2700;
43 #endif
44 m68k_switch_sp(env);
45 /* ??? FP regs should be initialized to NaN. */
46 env->cc_op = CC_OP_FLAGS;
47 /* TODO: We should set PC from the interrupt vector. */
48 env->pc = 0;
49 tlb_flush(env, 1);
52 /* CPU models */
54 static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
56 ObjectClass *oc;
57 char *typename;
59 if (cpu_model == NULL) {
60 return NULL;
63 typename = g_strdup_printf("%s-" TYPE_M68K_CPU, cpu_model);
64 oc = object_class_by_name(typename);
65 g_free(typename);
66 if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL ||
67 object_class_is_abstract(oc))) {
68 return NULL;
70 return oc;
73 static void m5206_cpu_initfn(Object *obj)
75 M68kCPU *cpu = M68K_CPU(obj);
76 CPUM68KState *env = &cpu->env;
78 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
81 static void m5208_cpu_initfn(Object *obj)
83 M68kCPU *cpu = M68K_CPU(obj);
84 CPUM68KState *env = &cpu->env;
86 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
87 m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC);
88 m68k_set_feature(env, M68K_FEATURE_BRAL);
89 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
90 m68k_set_feature(env, M68K_FEATURE_USP);
93 static void cfv4e_cpu_initfn(Object *obj)
95 M68kCPU *cpu = M68K_CPU(obj);
96 CPUM68KState *env = &cpu->env;
98 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
99 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
100 m68k_set_feature(env, M68K_FEATURE_BRAL);
101 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
102 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
103 m68k_set_feature(env, M68K_FEATURE_USP);
106 static void any_cpu_initfn(Object *obj)
108 M68kCPU *cpu = M68K_CPU(obj);
109 CPUM68KState *env = &cpu->env;
111 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
112 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
113 m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC);
114 m68k_set_feature(env, M68K_FEATURE_BRAL);
115 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
116 /* MAC and EMAC are mututally exclusive, so pick EMAC.
117 It's mostly backwards compatible. */
118 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
119 m68k_set_feature(env, M68K_FEATURE_CF_EMAC_B);
120 m68k_set_feature(env, M68K_FEATURE_USP);
121 m68k_set_feature(env, M68K_FEATURE_EXT_FULL);
122 m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
125 typedef struct M68kCPUInfo {
126 const char *name;
127 void (*instance_init)(Object *obj);
128 } M68kCPUInfo;
130 static const M68kCPUInfo m68k_cpus[] = {
131 { .name = "m5206", .instance_init = m5206_cpu_initfn },
132 { .name = "m5208", .instance_init = m5208_cpu_initfn },
133 { .name = "cfv4e", .instance_init = cfv4e_cpu_initfn },
134 { .name = "any", .instance_init = any_cpu_initfn },
137 static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
139 M68kCPU *cpu = M68K_CPU(dev);
140 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(dev);
142 m68k_cpu_init_gdb(cpu);
144 cpu_reset(CPU(cpu));
146 mcc->parent_realize(dev, errp);
149 static void m68k_cpu_initfn(Object *obj)
151 CPUState *cs = CPU(obj);
152 M68kCPU *cpu = M68K_CPU(obj);
153 CPUM68KState *env = &cpu->env;
154 static bool inited;
156 cs->env_ptr = env;
157 cpu_exec_init(env);
159 if (tcg_enabled() && !inited) {
160 inited = true;
161 m68k_tcg_init();
165 static const VMStateDescription vmstate_m68k_cpu = {
166 .name = "cpu",
167 .unmigratable = 1,
170 static void m68k_cpu_class_init(ObjectClass *c, void *data)
172 M68kCPUClass *mcc = M68K_CPU_CLASS(c);
173 CPUClass *cc = CPU_CLASS(c);
174 DeviceClass *dc = DEVICE_CLASS(c);
176 mcc->parent_realize = dc->realize;
177 dc->realize = m68k_cpu_realizefn;
179 mcc->parent_reset = cc->reset;
180 cc->reset = m68k_cpu_reset;
182 cc->class_by_name = m68k_cpu_class_by_name;
183 cc->do_interrupt = m68k_cpu_do_interrupt;
184 cc->dump_state = m68k_cpu_dump_state;
185 dc->vmsd = &vmstate_m68k_cpu;
188 static void register_cpu_type(const M68kCPUInfo *info)
190 TypeInfo type_info = {
191 .parent = TYPE_M68K_CPU,
192 .instance_init = info->instance_init,
195 type_info.name = g_strdup_printf("%s-" TYPE_M68K_CPU, info->name);
196 type_register(&type_info);
197 g_free((void *)type_info.name);
200 static const TypeInfo m68k_cpu_type_info = {
201 .name = TYPE_M68K_CPU,
202 .parent = TYPE_CPU,
203 .instance_size = sizeof(M68kCPU),
204 .instance_init = m68k_cpu_initfn,
205 .abstract = true,
206 .class_size = sizeof(M68kCPUClass),
207 .class_init = m68k_cpu_class_init,
210 static void m68k_cpu_register_types(void)
212 int i;
214 type_register_static(&m68k_cpu_type_info);
215 for (i = 0; i < ARRAY_SIZE(m68k_cpus); i++) {
216 register_cpu_type(&m68k_cpus[i]);
220 type_init(m68k_cpu_register_types)