hw/core: Introduce QEMU machine as QOM object
[qemu.git] / target-alpha / cpu.c
bloba0d5d5bd9399d391eea357aa0669d36d5adc57e1
1 /*
2 * QEMU Alpha CPU
4 * Copyright (c) 2007 Jocelyn Mayer
5 * Copyright (c) 2012 SUSE LINUX Products GmbH
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see
19 * <http://www.gnu.org/licenses/lgpl-2.1.html>
22 #include "cpu.h"
23 #include "qemu-common.h"
24 #include "migration/vmstate.h"
27 static void alpha_cpu_set_pc(CPUState *cs, vaddr value)
29 AlphaCPU *cpu = ALPHA_CPU(cs);
31 cpu->env.pc = value;
34 static void alpha_cpu_realizefn(DeviceState *dev, Error **errp)
36 CPUState *cs = CPU(dev);
37 AlphaCPUClass *acc = ALPHA_CPU_GET_CLASS(dev);
39 qemu_init_vcpu(cs);
41 acc->parent_realize(dev, errp);
44 /* Sort alphabetically by type name. */
45 static gint alpha_cpu_list_compare(gconstpointer a, gconstpointer b)
47 ObjectClass *class_a = (ObjectClass *)a;
48 ObjectClass *class_b = (ObjectClass *)b;
49 const char *name_a, *name_b;
51 name_a = object_class_get_name(class_a);
52 name_b = object_class_get_name(class_b);
53 return strcmp(name_a, name_b);
56 static void alpha_cpu_list_entry(gpointer data, gpointer user_data)
58 ObjectClass *oc = data;
59 CPUListState *s = user_data;
61 (*s->cpu_fprintf)(s->file, " %s\n",
62 object_class_get_name(oc));
65 void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf)
67 CPUListState s = {
68 .file = f,
69 .cpu_fprintf = cpu_fprintf,
71 GSList *list;
73 list = object_class_get_list(TYPE_ALPHA_CPU, false);
74 list = g_slist_sort(list, alpha_cpu_list_compare);
75 (*cpu_fprintf)(f, "Available CPUs:\n");
76 g_slist_foreach(list, alpha_cpu_list_entry, &s);
77 g_slist_free(list);
80 /* Models */
82 #define TYPE(model) model "-" TYPE_ALPHA_CPU
84 typedef struct AlphaCPUAlias {
85 const char *alias;
86 const char *typename;
87 } AlphaCPUAlias;
89 static const AlphaCPUAlias alpha_cpu_aliases[] = {
90 { "21064", TYPE("ev4") },
91 { "21164", TYPE("ev5") },
92 { "21164a", TYPE("ev56") },
93 { "21164pc", TYPE("pca56") },
94 { "21264", TYPE("ev6") },
95 { "21264a", TYPE("ev67") },
98 static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model)
100 ObjectClass *oc = NULL;
101 char *typename;
102 int i;
104 if (cpu_model == NULL) {
105 return NULL;
108 oc = object_class_by_name(cpu_model);
109 if (oc != NULL && object_class_dynamic_cast(oc, TYPE_ALPHA_CPU) != NULL &&
110 !object_class_is_abstract(oc)) {
111 return oc;
114 for (i = 0; i < ARRAY_SIZE(alpha_cpu_aliases); i++) {
115 if (strcmp(cpu_model, alpha_cpu_aliases[i].alias) == 0) {
116 oc = object_class_by_name(alpha_cpu_aliases[i].typename);
117 assert(oc != NULL && !object_class_is_abstract(oc));
118 return oc;
122 typename = g_strdup_printf("%s-" TYPE_ALPHA_CPU, cpu_model);
123 oc = object_class_by_name(typename);
124 g_free(typename);
125 if (oc != NULL && object_class_is_abstract(oc)) {
126 oc = NULL;
128 return oc;
131 AlphaCPU *cpu_alpha_init(const char *cpu_model)
133 AlphaCPU *cpu;
134 ObjectClass *cpu_class;
136 cpu_class = alpha_cpu_class_by_name(cpu_model);
137 if (cpu_class == NULL) {
138 /* Default to ev67; no reason not to emulate insns by default. */
139 cpu_class = object_class_by_name(TYPE("ev67"));
141 cpu = ALPHA_CPU(object_new(object_class_get_name(cpu_class)));
143 object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
145 return cpu;
148 static void ev4_cpu_initfn(Object *obj)
150 AlphaCPU *cpu = ALPHA_CPU(obj);
151 CPUAlphaState *env = &cpu->env;
153 env->implver = IMPLVER_2106x;
156 static const TypeInfo ev4_cpu_type_info = {
157 .name = TYPE("ev4"),
158 .parent = TYPE_ALPHA_CPU,
159 .instance_init = ev4_cpu_initfn,
162 static void ev5_cpu_initfn(Object *obj)
164 AlphaCPU *cpu = ALPHA_CPU(obj);
165 CPUAlphaState *env = &cpu->env;
167 env->implver = IMPLVER_21164;
170 static const TypeInfo ev5_cpu_type_info = {
171 .name = TYPE("ev5"),
172 .parent = TYPE_ALPHA_CPU,
173 .instance_init = ev5_cpu_initfn,
176 static void ev56_cpu_initfn(Object *obj)
178 AlphaCPU *cpu = ALPHA_CPU(obj);
179 CPUAlphaState *env = &cpu->env;
181 env->amask |= AMASK_BWX;
184 static const TypeInfo ev56_cpu_type_info = {
185 .name = TYPE("ev56"),
186 .parent = TYPE("ev5"),
187 .instance_init = ev56_cpu_initfn,
190 static void pca56_cpu_initfn(Object *obj)
192 AlphaCPU *cpu = ALPHA_CPU(obj);
193 CPUAlphaState *env = &cpu->env;
195 env->amask |= AMASK_MVI;
198 static const TypeInfo pca56_cpu_type_info = {
199 .name = TYPE("pca56"),
200 .parent = TYPE("ev56"),
201 .instance_init = pca56_cpu_initfn,
204 static void ev6_cpu_initfn(Object *obj)
206 AlphaCPU *cpu = ALPHA_CPU(obj);
207 CPUAlphaState *env = &cpu->env;
209 env->implver = IMPLVER_21264;
210 env->amask = AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP;
213 static const TypeInfo ev6_cpu_type_info = {
214 .name = TYPE("ev6"),
215 .parent = TYPE_ALPHA_CPU,
216 .instance_init = ev6_cpu_initfn,
219 static void ev67_cpu_initfn(Object *obj)
221 AlphaCPU *cpu = ALPHA_CPU(obj);
222 CPUAlphaState *env = &cpu->env;
224 env->amask |= AMASK_CIX | AMASK_PREFETCH;
227 static const TypeInfo ev67_cpu_type_info = {
228 .name = TYPE("ev67"),
229 .parent = TYPE("ev6"),
230 .instance_init = ev67_cpu_initfn,
233 static const TypeInfo ev68_cpu_type_info = {
234 .name = TYPE("ev68"),
235 .parent = TYPE("ev67"),
238 static void alpha_cpu_initfn(Object *obj)
240 CPUState *cs = CPU(obj);
241 AlphaCPU *cpu = ALPHA_CPU(obj);
242 CPUAlphaState *env = &cpu->env;
244 cs->env_ptr = env;
245 cpu_exec_init(env);
246 tlb_flush(env, 1);
248 alpha_translate_init();
250 #if defined(CONFIG_USER_ONLY)
251 env->ps = PS_USER_MODE;
252 cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
253 | FPCR_UNFD | FPCR_INED | FPCR_DNOD
254 | FPCR_DYN_NORMAL));
255 #endif
256 env->lock_addr = -1;
257 env->fen = 1;
260 static void alpha_cpu_class_init(ObjectClass *oc, void *data)
262 DeviceClass *dc = DEVICE_CLASS(oc);
263 CPUClass *cc = CPU_CLASS(oc);
264 AlphaCPUClass *acc = ALPHA_CPU_CLASS(oc);
266 acc->parent_realize = dc->realize;
267 dc->realize = alpha_cpu_realizefn;
269 cc->class_by_name = alpha_cpu_class_by_name;
270 cc->do_interrupt = alpha_cpu_do_interrupt;
271 cc->dump_state = alpha_cpu_dump_state;
272 cc->set_pc = alpha_cpu_set_pc;
273 cc->gdb_read_register = alpha_cpu_gdb_read_register;
274 cc->gdb_write_register = alpha_cpu_gdb_write_register;
275 #ifndef CONFIG_USER_ONLY
276 cc->do_unassigned_access = alpha_cpu_unassigned_access;
277 cc->get_phys_page_debug = alpha_cpu_get_phys_page_debug;
278 dc->vmsd = &vmstate_alpha_cpu;
279 #endif
280 cc->gdb_num_core_regs = 67;
283 static const TypeInfo alpha_cpu_type_info = {
284 .name = TYPE_ALPHA_CPU,
285 .parent = TYPE_CPU,
286 .instance_size = sizeof(AlphaCPU),
287 .instance_init = alpha_cpu_initfn,
288 .abstract = true,
289 .class_size = sizeof(AlphaCPUClass),
290 .class_init = alpha_cpu_class_init,
293 static void alpha_cpu_register_types(void)
295 type_register_static(&alpha_cpu_type_info);
296 type_register_static(&ev4_cpu_type_info);
297 type_register_static(&ev5_cpu_type_info);
298 type_register_static(&ev56_cpu_type_info);
299 type_register_static(&pca56_cpu_type_info);
300 type_register_static(&ev6_cpu_type_info);
301 type_register_static(&ev67_cpu_type_info);
302 type_register_static(&ev68_cpu_type_info);
305 type_init(alpha_cpu_register_types)