1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "cpu.h"
22#include "qemu-common.h"
23#include "migration/vmstate.h"
24
25
26static void m68k_set_feature(CPUM68KState *env, int feature)
27{
28 env->features |= (1u << feature);
29}
30
31
32static void m68k_cpu_reset(CPUState *s)
33{
34 M68kCPU *cpu = M68K_CPU(s);
35 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(cpu);
36 CPUM68KState *env = &cpu->env;
37
38 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
39 qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
40 log_cpu_state(env, 0);
41 }
42
43 mcc->parent_reset(s);
44
45 memset(env, 0, offsetof(CPUM68KState, breakpoints));
46#if !defined(CONFIG_USER_ONLY)
47 env->sr = 0x2700;
48#endif
49 m68k_switch_sp(env);
50
51 env->cc_op = CC_OP_FLAGS;
52
53 env->pc = 0;
54 tlb_flush(env, 1);
55}
56
57
58
59static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
60{
61 ObjectClass *oc;
62 char *typename;
63
64 if (cpu_model == NULL) {
65 return NULL;
66 }
67
68 typename = g_strdup_printf("%s-" TYPE_M68K_CPU, cpu_model);
69 oc = object_class_by_name(typename);
70 g_free(typename);
71 if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL ||
72 object_class_is_abstract(oc))) {
73 return NULL;
74 }
75 return oc;
76}
77
78static void m5206_cpu_initfn(Object *obj)
79{
80 M68kCPU *cpu = M68K_CPU(obj);
81 CPUM68KState *env = &cpu->env;
82
83 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
84}
85
86static void m5208_cpu_initfn(Object *obj)
87{
88 M68kCPU *cpu = M68K_CPU(obj);
89 CPUM68KState *env = &cpu->env;
90
91 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
92 m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC);
93 m68k_set_feature(env, M68K_FEATURE_BRAL);
94 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
95 m68k_set_feature(env, M68K_FEATURE_USP);
96}
97
98static void cfv4e_cpu_initfn(Object *obj)
99{
100 M68kCPU *cpu = M68K_CPU(obj);
101 CPUM68KState *env = &cpu->env;
102
103 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
104 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
105 m68k_set_feature(env, M68K_FEATURE_BRAL);
106 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
107 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
108 m68k_set_feature(env, M68K_FEATURE_USP);
109}
110
111static void any_cpu_initfn(Object *obj)
112{
113 M68kCPU *cpu = M68K_CPU(obj);
114 CPUM68KState *env = &cpu->env;
115
116 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
117 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
118 m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC);
119 m68k_set_feature(env, M68K_FEATURE_BRAL);
120 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
121
122
123 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
124 m68k_set_feature(env, M68K_FEATURE_CF_EMAC_B);
125 m68k_set_feature(env, M68K_FEATURE_USP);
126 m68k_set_feature(env, M68K_FEATURE_EXT_FULL);
127 m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
128}
129
130typedef struct M68kCPUInfo {
131 const char *name;
132 void (*instance_init)(Object *obj);
133} M68kCPUInfo;
134
135static const M68kCPUInfo m68k_cpus[] = {
136 { .name = "m5206", .instance_init = m5206_cpu_initfn },
137 { .name = "m5208", .instance_init = m5208_cpu_initfn },
138 { .name = "cfv4e", .instance_init = cfv4e_cpu_initfn },
139 { .name = "any", .instance_init = any_cpu_initfn },
140};
141
142static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
143{
144 M68kCPU *cpu = M68K_CPU(dev);
145 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(dev);
146
147 m68k_cpu_init_gdb(cpu);
148
149 cpu_reset(CPU(cpu));
150 qemu_init_vcpu(&cpu->env);
151
152 mcc->parent_realize(dev, errp);
153}
154
155static void m68k_cpu_initfn(Object *obj)
156{
157 CPUState *cs = CPU(obj);
158 M68kCPU *cpu = M68K_CPU(obj);
159 CPUM68KState *env = &cpu->env;
160 static bool inited;
161
162 cs->env_ptr = env;
163 cpu_exec_init(env);
164
165 if (tcg_enabled() && !inited) {
166 inited = true;
167 m68k_tcg_init();
168 }
169}
170
171static const VMStateDescription vmstate_m68k_cpu = {
172 .name = "cpu",
173 .unmigratable = 1,
174};
175
176static void m68k_cpu_class_init(ObjectClass *c, void *data)
177{
178 M68kCPUClass *mcc = M68K_CPU_CLASS(c);
179 CPUClass *cc = CPU_CLASS(c);
180 DeviceClass *dc = DEVICE_CLASS(c);
181
182 mcc->parent_realize = dc->realize;
183 dc->realize = m68k_cpu_realizefn;
184
185 mcc->parent_reset = cc->reset;
186 cc->reset = m68k_cpu_reset;
187
188 cc->class_by_name = m68k_cpu_class_by_name;
189 cc->do_interrupt = m68k_cpu_do_interrupt;
190 dc->vmsd = &vmstate_m68k_cpu;
191}
192
193static void register_cpu_type(const M68kCPUInfo *info)
194{
195 TypeInfo type_info = {
196 .parent = TYPE_M68K_CPU,
197 .instance_init = info->instance_init,
198 };
199
200 type_info.name = g_strdup_printf("%s-" TYPE_M68K_CPU, info->name);
201 type_register(&type_info);
202 g_free((void *)type_info.name);
203}
204
205static const TypeInfo m68k_cpu_type_info = {
206 .name = TYPE_M68K_CPU,
207 .parent = TYPE_CPU,
208 .instance_size = sizeof(M68kCPU),
209 .instance_init = m68k_cpu_initfn,
210 .abstract = true,
211 .class_size = sizeof(M68kCPUClass),
212 .class_init = m68k_cpu_class_init,
213};
214
215static void m68k_cpu_register_types(void)
216{
217 int i;
218
219 type_register_static(&m68k_cpu_type_info);
220 for (i = 0; i < ARRAY_SIZE(m68k_cpus); i++) {
221 register_cpu_type(&m68k_cpus[i]);
222 }
223}
224
225type_init(m68k_cpu_register_types)
226