s390-ccw.img: Get queue config from host.
[qemu/agraf.git] / target-m68k / cpu.c
blob3c65b4e44f4fedf36dbdca8fcb18a0d0118df23b
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_set_feature(CPUM68KState *env, int feature)
28 env->features |= (1u << feature);
31 /* CPUClass::reset() */
32 static void m68k_cpu_reset(CPUState *s)
34 M68kCPU *cpu = M68K_CPU(s);
35 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(cpu);
36 CPUM68KState *env = &cpu->env;
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);
43 mcc->parent_reset(s);
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 /* ??? FP regs should be initialized to NaN. */
51 env->cc_op = CC_OP_FLAGS;
52 /* TODO: We should set PC from the interrupt vector. */
53 env->pc = 0;
54 tlb_flush(env, 1);
57 /* CPU models */
59 static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
61 ObjectClass *oc;
62 char *typename;
64 if (cpu_model == NULL) {
65 return NULL;
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;
75 return oc;
78 static void m5206_cpu_initfn(Object *obj)
80 M68kCPU *cpu = M68K_CPU(obj);
81 CPUM68KState *env = &cpu->env;
83 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
86 static void m5208_cpu_initfn(Object *obj)
88 M68kCPU *cpu = M68K_CPU(obj);
89 CPUM68KState *env = &cpu->env;
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);
98 static void cfv4e_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_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);
111 static void any_cpu_initfn(Object *obj)
113 M68kCPU *cpu = M68K_CPU(obj);
114 CPUM68KState *env = &cpu->env;
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 /* MAC and EMAC are mututally exclusive, so pick EMAC.
122 It's mostly backwards compatible. */
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);
130 typedef struct M68kCPUInfo {
131 const char *name;
132 void (*instance_init)(Object *obj);
133 } M68kCPUInfo;
135 static 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 },
142 static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
144 M68kCPU *cpu = M68K_CPU(dev);
145 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(dev);
147 m68k_cpu_init_gdb(cpu);
149 cpu_reset(CPU(cpu));
150 qemu_init_vcpu(&cpu->env);
152 mcc->parent_realize(dev, errp);
155 static void m68k_cpu_initfn(Object *obj)
157 CPUState *cs = CPU(obj);
158 M68kCPU *cpu = M68K_CPU(obj);
159 CPUM68KState *env = &cpu->env;
160 static bool inited;
162 cs->env_ptr = env;
163 cpu_exec_init(env);
165 if (tcg_enabled() && !inited) {
166 inited = true;
167 m68k_tcg_init();
171 static const VMStateDescription vmstate_m68k_cpu = {
172 .name = "cpu",
173 .unmigratable = 1,
176 static void m68k_cpu_class_init(ObjectClass *c, void *data)
178 M68kCPUClass *mcc = M68K_CPU_CLASS(c);
179 CPUClass *cc = CPU_CLASS(c);
180 DeviceClass *dc = DEVICE_CLASS(c);
182 mcc->parent_realize = dc->realize;
183 dc->realize = m68k_cpu_realizefn;
185 mcc->parent_reset = cc->reset;
186 cc->reset = m68k_cpu_reset;
188 cc->class_by_name = m68k_cpu_class_by_name;
189 cc->do_interrupt = m68k_cpu_do_interrupt;
190 dc->vmsd = &vmstate_m68k_cpu;
193 static void register_cpu_type(const M68kCPUInfo *info)
195 TypeInfo type_info = {
196 .parent = TYPE_M68K_CPU,
197 .instance_init = info->instance_init,
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);
205 static 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,
215 static void m68k_cpu_register_types(void)
217 int i;
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]);
225 type_init(m68k_cpu_register_types)