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"
27 #include "fpu/softfloat.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
;
52 floatx80 nan
= floatx80_default_nan(NULL
);
57 memset(env
, 0, offsetof(CPUM68KState
, end_reset_fields
));
59 cpu_m68k_set_sr(env
, SR_S
| SR_I
);
61 cpu_m68k_set_sr(env
, 0);
63 for (i
= 0; i
< 8; i
++) {
64 env
->fregs
[i
].d
= nan
;
66 cpu_m68k_set_fpcr(env
, 0);
69 /* TODO: We should set PC from the interrupt vector. */
73 static void m68k_cpu_disas_set_info(CPUState
*s
, disassemble_info
*info
)
75 M68kCPU
*cpu
= M68K_CPU(s
);
76 CPUM68KState
*env
= &cpu
->env
;
77 info
->print_insn
= print_insn_m68k
;
78 if (m68k_feature(env
, M68K_FEATURE_M68000
)) {
79 info
->mach
= bfd_mach_m68040
;
85 static ObjectClass
*m68k_cpu_class_by_name(const char *cpu_model
)
90 typename
= g_strdup_printf(M68K_CPU_TYPE_NAME("%s"), cpu_model
);
91 oc
= object_class_by_name(typename
);
93 if (oc
!= NULL
&& (object_class_dynamic_cast(oc
, TYPE_M68K_CPU
) == NULL
||
94 object_class_is_abstract(oc
))) {
100 static void m5206_cpu_initfn(Object
*obj
)
102 M68kCPU
*cpu
= M68K_CPU(obj
);
103 CPUM68KState
*env
= &cpu
->env
;
105 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_A
);
108 static void m68000_cpu_initfn(Object
*obj
)
110 M68kCPU
*cpu
= M68K_CPU(obj
);
111 CPUM68KState
*env
= &cpu
->env
;
113 m68k_set_feature(env
, M68K_FEATURE_M68000
);
114 m68k_set_feature(env
, M68K_FEATURE_USP
);
115 m68k_set_feature(env
, M68K_FEATURE_WORD_INDEX
);
116 m68k_set_feature(env
, M68K_FEATURE_MOVEP
);
119 static void m68020_cpu_initfn(Object
*obj
)
121 M68kCPU
*cpu
= M68K_CPU(obj
);
122 CPUM68KState
*env
= &cpu
->env
;
124 m68k_set_feature(env
, M68K_FEATURE_M68000
);
125 m68k_set_feature(env
, M68K_FEATURE_USP
);
126 m68k_set_feature(env
, M68K_FEATURE_WORD_INDEX
);
127 m68k_set_feature(env
, M68K_FEATURE_QUAD_MULDIV
);
128 m68k_set_feature(env
, M68K_FEATURE_BRAL
);
129 m68k_set_feature(env
, M68K_FEATURE_BCCL
);
130 m68k_set_feature(env
, M68K_FEATURE_BITFIELD
);
131 m68k_set_feature(env
, M68K_FEATURE_EXT_FULL
);
132 m68k_set_feature(env
, M68K_FEATURE_SCALED_INDEX
);
133 m68k_set_feature(env
, M68K_FEATURE_LONG_MULDIV
);
134 m68k_set_feature(env
, M68K_FEATURE_FPU
);
135 m68k_set_feature(env
, M68K_FEATURE_CAS
);
136 m68k_set_feature(env
, M68K_FEATURE_BKPT
);
137 m68k_set_feature(env
, M68K_FEATURE_RTD
);
138 m68k_set_feature(env
, M68K_FEATURE_CHK2
);
139 m68k_set_feature(env
, M68K_FEATURE_MOVEP
);
141 #define m68030_cpu_initfn m68020_cpu_initfn
143 static void m68040_cpu_initfn(Object
*obj
)
145 M68kCPU
*cpu
= M68K_CPU(obj
);
146 CPUM68KState
*env
= &cpu
->env
;
148 m68020_cpu_initfn(obj
);
149 m68k_set_feature(env
, M68K_FEATURE_M68040
);
152 static void m68060_cpu_initfn(Object
*obj
)
154 M68kCPU
*cpu
= M68K_CPU(obj
);
155 CPUM68KState
*env
= &cpu
->env
;
157 m68k_set_feature(env
, M68K_FEATURE_M68000
);
158 m68k_set_feature(env
, M68K_FEATURE_USP
);
159 m68k_set_feature(env
, M68K_FEATURE_WORD_INDEX
);
160 m68k_set_feature(env
, M68K_FEATURE_BRAL
);
161 m68k_set_feature(env
, M68K_FEATURE_BCCL
);
162 m68k_set_feature(env
, M68K_FEATURE_BITFIELD
);
163 m68k_set_feature(env
, M68K_FEATURE_EXT_FULL
);
164 m68k_set_feature(env
, M68K_FEATURE_SCALED_INDEX
);
165 m68k_set_feature(env
, M68K_FEATURE_LONG_MULDIV
);
166 m68k_set_feature(env
, M68K_FEATURE_FPU
);
167 m68k_set_feature(env
, M68K_FEATURE_CAS
);
168 m68k_set_feature(env
, M68K_FEATURE_BKPT
);
169 m68k_set_feature(env
, M68K_FEATURE_RTD
);
170 m68k_set_feature(env
, M68K_FEATURE_CHK2
);
173 static void m5208_cpu_initfn(Object
*obj
)
175 M68kCPU
*cpu
= M68K_CPU(obj
);
176 CPUM68KState
*env
= &cpu
->env
;
178 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_A
);
179 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_APLUSC
);
180 m68k_set_feature(env
, M68K_FEATURE_BRAL
);
181 m68k_set_feature(env
, M68K_FEATURE_CF_EMAC
);
182 m68k_set_feature(env
, M68K_FEATURE_USP
);
185 static void cfv4e_cpu_initfn(Object
*obj
)
187 M68kCPU
*cpu
= M68K_CPU(obj
);
188 CPUM68KState
*env
= &cpu
->env
;
190 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_A
);
191 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_B
);
192 m68k_set_feature(env
, M68K_FEATURE_BRAL
);
193 m68k_set_feature(env
, M68K_FEATURE_CF_FPU
);
194 m68k_set_feature(env
, M68K_FEATURE_CF_EMAC
);
195 m68k_set_feature(env
, M68K_FEATURE_USP
);
198 static void any_cpu_initfn(Object
*obj
)
200 M68kCPU
*cpu
= M68K_CPU(obj
);
201 CPUM68KState
*env
= &cpu
->env
;
203 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_A
);
204 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_B
);
205 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_APLUSC
);
206 m68k_set_feature(env
, M68K_FEATURE_BRAL
);
207 m68k_set_feature(env
, M68K_FEATURE_CF_FPU
);
208 /* MAC and EMAC are mututally exclusive, so pick EMAC.
209 It's mostly backwards compatible. */
210 m68k_set_feature(env
, M68K_FEATURE_CF_EMAC
);
211 m68k_set_feature(env
, M68K_FEATURE_CF_EMAC_B
);
212 m68k_set_feature(env
, M68K_FEATURE_USP
);
213 m68k_set_feature(env
, M68K_FEATURE_EXT_FULL
);
214 m68k_set_feature(env
, M68K_FEATURE_WORD_INDEX
);
217 static void m68k_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
219 CPUState
*cs
= CPU(dev
);
220 M68kCPU
*cpu
= M68K_CPU(dev
);
221 M68kCPUClass
*mcc
= M68K_CPU_GET_CLASS(dev
);
222 Error
*local_err
= NULL
;
224 register_m68k_insns(&cpu
->env
);
226 cpu_exec_realizefn(cs
, &local_err
);
227 if (local_err
!= NULL
) {
228 error_propagate(errp
, local_err
);
232 m68k_cpu_init_gdb(cpu
);
237 mcc
->parent_realize(dev
, errp
);
240 static void m68k_cpu_initfn(Object
*obj
)
242 CPUState
*cs
= CPU(obj
);
243 M68kCPU
*cpu
= M68K_CPU(obj
);
244 CPUM68KState
*env
= &cpu
->env
;
249 static const VMStateDescription vmstate_m68k_cpu
= {
254 static void m68k_cpu_class_init(ObjectClass
*c
, void *data
)
256 M68kCPUClass
*mcc
= M68K_CPU_CLASS(c
);
257 CPUClass
*cc
= CPU_CLASS(c
);
258 DeviceClass
*dc
= DEVICE_CLASS(c
);
260 device_class_set_parent_realize(dc
, m68k_cpu_realizefn
,
261 &mcc
->parent_realize
);
262 mcc
->parent_reset
= cc
->reset
;
263 cc
->reset
= m68k_cpu_reset
;
265 cc
->class_by_name
= m68k_cpu_class_by_name
;
266 cc
->has_work
= m68k_cpu_has_work
;
267 cc
->do_interrupt
= m68k_cpu_do_interrupt
;
268 cc
->cpu_exec_interrupt
= m68k_cpu_exec_interrupt
;
269 cc
->dump_state
= m68k_cpu_dump_state
;
270 cc
->set_pc
= m68k_cpu_set_pc
;
271 cc
->gdb_read_register
= m68k_cpu_gdb_read_register
;
272 cc
->gdb_write_register
= m68k_cpu_gdb_write_register
;
273 cc
->handle_mmu_fault
= m68k_cpu_handle_mmu_fault
;
274 #if defined(CONFIG_SOFTMMU)
275 cc
->do_unassigned_access
= m68k_cpu_unassigned_access
;
276 cc
->get_phys_page_debug
= m68k_cpu_get_phys_page_debug
;
278 cc
->disas_set_info
= m68k_cpu_disas_set_info
;
279 cc
->tcg_initialize
= m68k_tcg_init
;
281 cc
->gdb_num_core_regs
= 18;
282 cc
->gdb_core_xml_file
= "cf-core.xml";
284 dc
->vmsd
= &vmstate_m68k_cpu
;
287 #define DEFINE_M68K_CPU_TYPE(cpu_model, initfn) \
289 .name = M68K_CPU_TYPE_NAME(cpu_model), \
290 .instance_init = initfn, \
291 .parent = TYPE_M68K_CPU, \
294 static const TypeInfo m68k_cpus_type_infos
[] = {
295 { /* base class should be registered first */
296 .name
= TYPE_M68K_CPU
,
298 .instance_size
= sizeof(M68kCPU
),
299 .instance_init
= m68k_cpu_initfn
,
301 .class_size
= sizeof(M68kCPUClass
),
302 .class_init
= m68k_cpu_class_init
,
304 DEFINE_M68K_CPU_TYPE("m68000", m68000_cpu_initfn
),
305 DEFINE_M68K_CPU_TYPE("m68020", m68020_cpu_initfn
),
306 DEFINE_M68K_CPU_TYPE("m68030", m68030_cpu_initfn
),
307 DEFINE_M68K_CPU_TYPE("m68040", m68040_cpu_initfn
),
308 DEFINE_M68K_CPU_TYPE("m68060", m68060_cpu_initfn
),
309 DEFINE_M68K_CPU_TYPE("m5206", m5206_cpu_initfn
),
310 DEFINE_M68K_CPU_TYPE("m5208", m5208_cpu_initfn
),
311 DEFINE_M68K_CPU_TYPE("cfv4e", cfv4e_cpu_initfn
),
312 DEFINE_M68K_CPU_TYPE("any", any_cpu_initfn
),
315 DEFINE_TYPES(m68k_cpus_type_infos
)