ppc: do not use get_clock_realtime()
[qemu/rayw.git] / target-m68k / cpu.c
blob4cfb7256c641893d7c0eb404a3bc517135928341
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 /* CPU models */
66 static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
68 ObjectClass *oc;
69 char *typename;
71 if (cpu_model == NULL) {
72 return NULL;
75 typename = g_strdup_printf("%s-" TYPE_M68K_CPU, cpu_model);
76 oc = object_class_by_name(typename);
77 g_free(typename);
78 if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL ||
79 object_class_is_abstract(oc))) {
80 return NULL;
82 return oc;
85 static void m5206_cpu_initfn(Object *obj)
87 M68kCPU *cpu = M68K_CPU(obj);
88 CPUM68KState *env = &cpu->env;
90 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
93 static void m5208_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_APLUSC);
100 m68k_set_feature(env, M68K_FEATURE_BRAL);
101 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
102 m68k_set_feature(env, M68K_FEATURE_USP);
105 static void cfv4e_cpu_initfn(Object *obj)
107 M68kCPU *cpu = M68K_CPU(obj);
108 CPUM68KState *env = &cpu->env;
110 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
111 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
112 m68k_set_feature(env, M68K_FEATURE_BRAL);
113 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
114 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
115 m68k_set_feature(env, M68K_FEATURE_USP);
118 static void any_cpu_initfn(Object *obj)
120 M68kCPU *cpu = M68K_CPU(obj);
121 CPUM68KState *env = &cpu->env;
123 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
124 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
125 m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC);
126 m68k_set_feature(env, M68K_FEATURE_BRAL);
127 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
128 /* MAC and EMAC are mututally exclusive, so pick EMAC.
129 It's mostly backwards compatible. */
130 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
131 m68k_set_feature(env, M68K_FEATURE_CF_EMAC_B);
132 m68k_set_feature(env, M68K_FEATURE_USP);
133 m68k_set_feature(env, M68K_FEATURE_EXT_FULL);
134 m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
137 typedef struct M68kCPUInfo {
138 const char *name;
139 void (*instance_init)(Object *obj);
140 } M68kCPUInfo;
142 static const M68kCPUInfo m68k_cpus[] = {
143 { .name = "m5206", .instance_init = m5206_cpu_initfn },
144 { .name = "m5208", .instance_init = m5208_cpu_initfn },
145 { .name = "cfv4e", .instance_init = cfv4e_cpu_initfn },
146 { .name = "any", .instance_init = any_cpu_initfn },
149 static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
151 CPUState *cs = CPU(dev);
152 M68kCPU *cpu = M68K_CPU(dev);
153 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(dev);
155 m68k_cpu_init_gdb(cpu);
157 cpu_reset(cs);
158 qemu_init_vcpu(cs);
160 mcc->parent_realize(dev, errp);
163 static void m68k_cpu_initfn(Object *obj)
165 CPUState *cs = CPU(obj);
166 M68kCPU *cpu = M68K_CPU(obj);
167 CPUM68KState *env = &cpu->env;
168 static bool inited;
170 cs->env_ptr = env;
171 cpu_exec_init(env);
173 if (tcg_enabled() && !inited) {
174 inited = true;
175 m68k_tcg_init();
179 static const VMStateDescription vmstate_m68k_cpu = {
180 .name = "cpu",
181 .unmigratable = 1,
184 static void m68k_cpu_class_init(ObjectClass *c, void *data)
186 M68kCPUClass *mcc = M68K_CPU_CLASS(c);
187 CPUClass *cc = CPU_CLASS(c);
188 DeviceClass *dc = DEVICE_CLASS(c);
190 mcc->parent_realize = dc->realize;
191 dc->realize = m68k_cpu_realizefn;
193 mcc->parent_reset = cc->reset;
194 cc->reset = m68k_cpu_reset;
196 cc->class_by_name = m68k_cpu_class_by_name;
197 cc->has_work = m68k_cpu_has_work;
198 cc->do_interrupt = m68k_cpu_do_interrupt;
199 cc->cpu_exec_interrupt = m68k_cpu_exec_interrupt;
200 cc->dump_state = m68k_cpu_dump_state;
201 cc->set_pc = m68k_cpu_set_pc;
202 cc->gdb_read_register = m68k_cpu_gdb_read_register;
203 cc->gdb_write_register = m68k_cpu_gdb_write_register;
204 #ifdef CONFIG_USER_ONLY
205 cc->handle_mmu_fault = m68k_cpu_handle_mmu_fault;
206 #else
207 cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug;
208 #endif
209 cc->cpu_exec_enter = m68k_cpu_exec_enter;
210 cc->cpu_exec_exit = m68k_cpu_exec_exit;
212 dc->vmsd = &vmstate_m68k_cpu;
213 cc->gdb_num_core_regs = 18;
214 cc->gdb_core_xml_file = "cf-core.xml";
217 static void register_cpu_type(const M68kCPUInfo *info)
219 TypeInfo type_info = {
220 .parent = TYPE_M68K_CPU,
221 .instance_init = info->instance_init,
224 type_info.name = g_strdup_printf("%s-" TYPE_M68K_CPU, info->name);
225 type_register(&type_info);
226 g_free((void *)type_info.name);
229 static const TypeInfo m68k_cpu_type_info = {
230 .name = TYPE_M68K_CPU,
231 .parent = TYPE_CPU,
232 .instance_size = sizeof(M68kCPU),
233 .instance_init = m68k_cpu_initfn,
234 .abstract = true,
235 .class_size = sizeof(M68kCPUClass),
236 .class_init = m68k_cpu_class_init,
239 static void m68k_cpu_register_types(void)
241 int i;
243 type_register_static(&m68k_cpu_type_info);
244 for (i = 0; i < ARRAY_SIZE(m68k_cpus); i++) {
245 register_cpu_type(&m68k_cpus[i]);
249 type_init(m68k_cpu_register_types)