scripts/kvm/kvm_stat: Replaced os.listdir with os.walk
[qemu.git] / target-m68k / cpu.c
blobe8a4eed1f9c50b88810050eeb998df15c69026b3
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_cpu_set_pc(CPUState *cs, vaddr value)
28 M68kCPU *cpu = M68K_CPU(cs);
30 cpu->env.pc = value;
33 static bool m68k_cpu_has_work(CPUState *cs)
35 return cs->interrupt_request & CPU_INTERRUPT_HARD;
38 static void m68k_set_feature(CPUM68KState *env, int feature)
40 env->features |= (1u << feature);
43 /* CPUClass::reset() */
44 static void m68k_cpu_reset(CPUState *s)
46 M68kCPU *cpu = M68K_CPU(s);
47 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(cpu);
48 CPUM68KState *env = &cpu->env;
50 mcc->parent_reset(s);
52 memset(env, 0, offsetof(CPUM68KState, features));
53 #if !defined(CONFIG_USER_ONLY)
54 env->sr = 0x2700;
55 #endif
56 m68k_switch_sp(env);
57 /* ??? FP regs should be initialized to NaN. */
58 env->cc_op = CC_OP_FLAGS;
59 /* TODO: We should set PC from the interrupt vector. */
60 env->pc = 0;
61 tlb_flush(s, 1);
64 static void m68k_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
66 info->print_insn = print_insn_m68k;
69 /* CPU models */
71 static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
73 ObjectClass *oc;
74 char *typename;
76 if (cpu_model == NULL) {
77 return NULL;
80 typename = g_strdup_printf("%s-" TYPE_M68K_CPU, cpu_model);
81 oc = object_class_by_name(typename);
82 g_free(typename);
83 if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL ||
84 object_class_is_abstract(oc))) {
85 return NULL;
87 return oc;
90 static void m5206_cpu_initfn(Object *obj)
92 M68kCPU *cpu = M68K_CPU(obj);
93 CPUM68KState *env = &cpu->env;
95 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
98 static void m5208_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);
104 m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC);
105 m68k_set_feature(env, M68K_FEATURE_BRAL);
106 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
107 m68k_set_feature(env, M68K_FEATURE_USP);
110 static void cfv4e_cpu_initfn(Object *obj)
112 M68kCPU *cpu = M68K_CPU(obj);
113 CPUM68KState *env = &cpu->env;
115 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
116 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
117 m68k_set_feature(env, M68K_FEATURE_BRAL);
118 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
119 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
120 m68k_set_feature(env, M68K_FEATURE_USP);
123 static void any_cpu_initfn(Object *obj)
125 M68kCPU *cpu = M68K_CPU(obj);
126 CPUM68KState *env = &cpu->env;
128 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
129 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
130 m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC);
131 m68k_set_feature(env, M68K_FEATURE_BRAL);
132 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
133 /* MAC and EMAC are mututally exclusive, so pick EMAC.
134 It's mostly backwards compatible. */
135 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
136 m68k_set_feature(env, M68K_FEATURE_CF_EMAC_B);
137 m68k_set_feature(env, M68K_FEATURE_USP);
138 m68k_set_feature(env, M68K_FEATURE_EXT_FULL);
139 m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
142 typedef struct M68kCPUInfo {
143 const char *name;
144 void (*instance_init)(Object *obj);
145 } M68kCPUInfo;
147 static const M68kCPUInfo m68k_cpus[] = {
148 { .name = "m5206", .instance_init = m5206_cpu_initfn },
149 { .name = "m5208", .instance_init = m5208_cpu_initfn },
150 { .name = "cfv4e", .instance_init = cfv4e_cpu_initfn },
151 { .name = "any", .instance_init = any_cpu_initfn },
154 static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
156 CPUState *cs = CPU(dev);
157 M68kCPU *cpu = M68K_CPU(dev);
158 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(dev);
160 m68k_cpu_init_gdb(cpu);
162 cpu_reset(cs);
163 qemu_init_vcpu(cs);
165 mcc->parent_realize(dev, errp);
168 static void m68k_cpu_initfn(Object *obj)
170 CPUState *cs = CPU(obj);
171 M68kCPU *cpu = M68K_CPU(obj);
172 CPUM68KState *env = &cpu->env;
173 static bool inited;
175 cs->env_ptr = env;
176 cpu_exec_init(cs, &error_abort);
178 if (tcg_enabled() && !inited) {
179 inited = true;
180 m68k_tcg_init();
184 static const VMStateDescription vmstate_m68k_cpu = {
185 .name = "cpu",
186 .unmigratable = 1,
189 static void m68k_cpu_class_init(ObjectClass *c, void *data)
191 M68kCPUClass *mcc = M68K_CPU_CLASS(c);
192 CPUClass *cc = CPU_CLASS(c);
193 DeviceClass *dc = DEVICE_CLASS(c);
195 mcc->parent_realize = dc->realize;
196 dc->realize = m68k_cpu_realizefn;
198 mcc->parent_reset = cc->reset;
199 cc->reset = m68k_cpu_reset;
201 cc->class_by_name = m68k_cpu_class_by_name;
202 cc->has_work = m68k_cpu_has_work;
203 cc->do_interrupt = m68k_cpu_do_interrupt;
204 cc->cpu_exec_interrupt = m68k_cpu_exec_interrupt;
205 cc->dump_state = m68k_cpu_dump_state;
206 cc->set_pc = m68k_cpu_set_pc;
207 cc->gdb_read_register = m68k_cpu_gdb_read_register;
208 cc->gdb_write_register = m68k_cpu_gdb_write_register;
209 #ifdef CONFIG_USER_ONLY
210 cc->handle_mmu_fault = m68k_cpu_handle_mmu_fault;
211 #else
212 cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug;
213 #endif
214 cc->cpu_exec_enter = m68k_cpu_exec_enter;
215 cc->cpu_exec_exit = m68k_cpu_exec_exit;
216 cc->disas_set_info = m68k_cpu_disas_set_info;
218 cc->gdb_num_core_regs = 18;
219 cc->gdb_core_xml_file = "cf-core.xml";
221 dc->vmsd = &vmstate_m68k_cpu;
224 * Reason: m68k_cpu_initfn() calls cpu_exec_init(), which saves
225 * the object in cpus -> dangling pointer after final
226 * object_unref().
228 dc->cannot_destroy_with_object_finalize_yet = true;
231 static void register_cpu_type(const M68kCPUInfo *info)
233 TypeInfo type_info = {
234 .parent = TYPE_M68K_CPU,
235 .instance_init = info->instance_init,
238 type_info.name = g_strdup_printf("%s-" TYPE_M68K_CPU, info->name);
239 type_register(&type_info);
240 g_free((void *)type_info.name);
243 static const TypeInfo m68k_cpu_type_info = {
244 .name = TYPE_M68K_CPU,
245 .parent = TYPE_CPU,
246 .instance_size = sizeof(M68kCPU),
247 .instance_init = m68k_cpu_initfn,
248 .abstract = true,
249 .class_size = sizeof(M68kCPUClass),
250 .class_init = m68k_cpu_class_init,
253 static void m68k_cpu_register_types(void)
255 int i;
257 type_register_static(&m68k_cpu_type_info);
258 for (i = 0; i < ARRAY_SIZE(m68k_cpus); i++) {
259 register_cpu_type(&m68k_cpus[i]);
263 type_init(m68k_cpu_register_types)