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"
24 #include "qemu-common.h"
25 #include "migration/vmstate.h"
26 #include "exec/exec-all.h"
29 static void m68k_cpu_set_pc(CPUState
*cs
, vaddr value
)
31 M68kCPU
*cpu
= M68K_CPU(cs
);
36 static bool m68k_cpu_has_work(CPUState
*cs
)
38 return cs
->interrupt_request
& CPU_INTERRUPT_HARD
;
41 static void m68k_set_feature(CPUM68KState
*env
, int feature
)
43 env
->features
|= (1u << feature
);
46 /* CPUClass::reset() */
47 static void m68k_cpu_reset(CPUState
*s
)
49 M68kCPU
*cpu
= M68K_CPU(s
);
50 M68kCPUClass
*mcc
= M68K_CPU_GET_CLASS(cpu
);
51 CPUM68KState
*env
= &cpu
->env
;
55 memset(env
, 0, offsetof(CPUM68KState
, features
));
56 #if !defined(CONFIG_USER_ONLY)
60 /* ??? FP regs should be initialized to NaN. */
61 cpu_m68k_set_ccr(env
, 0);
62 /* TODO: We should set PC from the interrupt vector. */
67 static void m68k_cpu_disas_set_info(CPUState
*s
, disassemble_info
*info
)
69 M68kCPU
*cpu
= M68K_CPU(s
);
70 CPUM68KState
*env
= &cpu
->env
;
71 info
->print_insn
= print_insn_m68k
;
72 if (m68k_feature(env
, M68K_FEATURE_M68000
)) {
73 info
->mach
= bfd_mach_m68040
;
79 static ObjectClass
*m68k_cpu_class_by_name(const char *cpu_model
)
84 if (cpu_model
== NULL
) {
88 typename
= g_strdup_printf("%s-" TYPE_M68K_CPU
, cpu_model
);
89 oc
= object_class_by_name(typename
);
91 if (oc
!= NULL
&& (object_class_dynamic_cast(oc
, TYPE_M68K_CPU
) == NULL
||
92 object_class_is_abstract(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
);
116 static void m68020_cpu_initfn(Object
*obj
)
118 M68kCPU
*cpu
= M68K_CPU(obj
);
119 CPUM68KState
*env
= &cpu
->env
;
121 m68k_set_feature(env
, M68K_FEATURE_M68000
);
122 m68k_set_feature(env
, M68K_FEATURE_USP
);
123 m68k_set_feature(env
, M68K_FEATURE_WORD_INDEX
);
124 m68k_set_feature(env
, M68K_FEATURE_QUAD_MULDIV
);
125 m68k_set_feature(env
, M68K_FEATURE_BRAL
);
126 m68k_set_feature(env
, M68K_FEATURE_BCCL
);
127 m68k_set_feature(env
, M68K_FEATURE_BITFIELD
);
128 m68k_set_feature(env
, M68K_FEATURE_EXT_FULL
);
129 m68k_set_feature(env
, M68K_FEATURE_SCALED_INDEX
);
130 m68k_set_feature(env
, M68K_FEATURE_LONG_MULDIV
);
131 m68k_set_feature(env
, M68K_FEATURE_FPU
);
132 m68k_set_feature(env
, M68K_FEATURE_CAS
);
133 m68k_set_feature(env
, M68K_FEATURE_BKPT
);
135 #define m68030_cpu_initfn m68020_cpu_initfn
136 #define m68040_cpu_initfn m68020_cpu_initfn
138 static void m68060_cpu_initfn(Object
*obj
)
140 M68kCPU
*cpu
= M68K_CPU(obj
);
141 CPUM68KState
*env
= &cpu
->env
;
143 m68k_set_feature(env
, M68K_FEATURE_M68000
);
144 m68k_set_feature(env
, M68K_FEATURE_USP
);
145 m68k_set_feature(env
, M68K_FEATURE_WORD_INDEX
);
146 m68k_set_feature(env
, M68K_FEATURE_BRAL
);
147 m68k_set_feature(env
, M68K_FEATURE_BCCL
);
148 m68k_set_feature(env
, M68K_FEATURE_BITFIELD
);
149 m68k_set_feature(env
, M68K_FEATURE_EXT_FULL
);
150 m68k_set_feature(env
, M68K_FEATURE_SCALED_INDEX
);
151 m68k_set_feature(env
, M68K_FEATURE_LONG_MULDIV
);
152 m68k_set_feature(env
, M68K_FEATURE_FPU
);
153 m68k_set_feature(env
, M68K_FEATURE_CAS
);
154 m68k_set_feature(env
, M68K_FEATURE_BKPT
);
157 static void m5208_cpu_initfn(Object
*obj
)
159 M68kCPU
*cpu
= M68K_CPU(obj
);
160 CPUM68KState
*env
= &cpu
->env
;
162 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_A
);
163 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_APLUSC
);
164 m68k_set_feature(env
, M68K_FEATURE_BRAL
);
165 m68k_set_feature(env
, M68K_FEATURE_CF_EMAC
);
166 m68k_set_feature(env
, M68K_FEATURE_USP
);
169 static void cfv4e_cpu_initfn(Object
*obj
)
171 M68kCPU
*cpu
= M68K_CPU(obj
);
172 CPUM68KState
*env
= &cpu
->env
;
174 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_A
);
175 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_B
);
176 m68k_set_feature(env
, M68K_FEATURE_BRAL
);
177 m68k_set_feature(env
, M68K_FEATURE_CF_FPU
);
178 m68k_set_feature(env
, M68K_FEATURE_CF_EMAC
);
179 m68k_set_feature(env
, M68K_FEATURE_USP
);
182 static void any_cpu_initfn(Object
*obj
)
184 M68kCPU
*cpu
= M68K_CPU(obj
);
185 CPUM68KState
*env
= &cpu
->env
;
187 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_A
);
188 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_B
);
189 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_APLUSC
);
190 m68k_set_feature(env
, M68K_FEATURE_BRAL
);
191 m68k_set_feature(env
, M68K_FEATURE_CF_FPU
);
192 /* MAC and EMAC are mututally exclusive, so pick EMAC.
193 It's mostly backwards compatible. */
194 m68k_set_feature(env
, M68K_FEATURE_CF_EMAC
);
195 m68k_set_feature(env
, M68K_FEATURE_CF_EMAC_B
);
196 m68k_set_feature(env
, M68K_FEATURE_USP
);
197 m68k_set_feature(env
, M68K_FEATURE_EXT_FULL
);
198 m68k_set_feature(env
, M68K_FEATURE_WORD_INDEX
);
201 typedef struct M68kCPUInfo
{
203 void (*instance_init
)(Object
*obj
);
206 static const M68kCPUInfo m68k_cpus
[] = {
207 { .name
= "m68000", .instance_init
= m68000_cpu_initfn
},
208 { .name
= "m68020", .instance_init
= m68020_cpu_initfn
},
209 { .name
= "m68030", .instance_init
= m68030_cpu_initfn
},
210 { .name
= "m68040", .instance_init
= m68040_cpu_initfn
},
211 { .name
= "m68060", .instance_init
= m68060_cpu_initfn
},
212 { .name
= "m5206", .instance_init
= m5206_cpu_initfn
},
213 { .name
= "m5208", .instance_init
= m5208_cpu_initfn
},
214 { .name
= "cfv4e", .instance_init
= cfv4e_cpu_initfn
},
215 { .name
= "any", .instance_init
= any_cpu_initfn
},
218 static void m68k_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
220 CPUState
*cs
= CPU(dev
);
221 M68kCPU
*cpu
= M68K_CPU(dev
);
222 M68kCPUClass
*mcc
= M68K_CPU_GET_CLASS(dev
);
223 Error
*local_err
= NULL
;
225 cpu_exec_realizefn(cs
, &local_err
);
226 if (local_err
!= NULL
) {
227 error_propagate(errp
, local_err
);
231 m68k_cpu_init_gdb(cpu
);
236 mcc
->parent_realize(dev
, errp
);
239 static void m68k_cpu_initfn(Object
*obj
)
241 CPUState
*cs
= CPU(obj
);
242 M68kCPU
*cpu
= M68K_CPU(obj
);
243 CPUM68KState
*env
= &cpu
->env
;
248 if (tcg_enabled() && !inited
) {
254 static const VMStateDescription vmstate_m68k_cpu
= {
259 static void m68k_cpu_class_init(ObjectClass
*c
, void *data
)
261 M68kCPUClass
*mcc
= M68K_CPU_CLASS(c
);
262 CPUClass
*cc
= CPU_CLASS(c
);
263 DeviceClass
*dc
= DEVICE_CLASS(c
);
265 mcc
->parent_realize
= dc
->realize
;
266 dc
->realize
= m68k_cpu_realizefn
;
268 mcc
->parent_reset
= cc
->reset
;
269 cc
->reset
= m68k_cpu_reset
;
271 cc
->class_by_name
= m68k_cpu_class_by_name
;
272 cc
->has_work
= m68k_cpu_has_work
;
273 cc
->do_interrupt
= m68k_cpu_do_interrupt
;
274 cc
->cpu_exec_interrupt
= m68k_cpu_exec_interrupt
;
275 cc
->dump_state
= m68k_cpu_dump_state
;
276 cc
->set_pc
= m68k_cpu_set_pc
;
277 cc
->gdb_read_register
= m68k_cpu_gdb_read_register
;
278 cc
->gdb_write_register
= m68k_cpu_gdb_write_register
;
279 #ifdef CONFIG_USER_ONLY
280 cc
->handle_mmu_fault
= m68k_cpu_handle_mmu_fault
;
282 cc
->get_phys_page_debug
= m68k_cpu_get_phys_page_debug
;
284 cc
->disas_set_info
= m68k_cpu_disas_set_info
;
286 cc
->gdb_num_core_regs
= 18;
287 cc
->gdb_core_xml_file
= "cf-core.xml";
289 dc
->vmsd
= &vmstate_m68k_cpu
;
292 static void register_cpu_type(const M68kCPUInfo
*info
)
294 TypeInfo type_info
= {
295 .parent
= TYPE_M68K_CPU
,
296 .instance_init
= info
->instance_init
,
299 type_info
.name
= g_strdup_printf("%s-" TYPE_M68K_CPU
, info
->name
);
300 type_register(&type_info
);
301 g_free((void *)type_info
.name
);
304 static const TypeInfo m68k_cpu_type_info
= {
305 .name
= TYPE_M68K_CPU
,
307 .instance_size
= sizeof(M68kCPU
),
308 .instance_init
= m68k_cpu_initfn
,
310 .class_size
= sizeof(M68kCPUClass
),
311 .class_init
= m68k_cpu_class_init
,
314 static void m68k_cpu_register_types(void)
318 type_register_static(&m68k_cpu_type_info
);
319 for (i
= 0; i
< ARRAY_SIZE(m68k_cpus
); i
++) {
320 register_cpu_type(&m68k_cpus
[i
]);
324 type_init(m68k_cpu_register_types
)