target-arm: Avoid g_hash_table_get_keys()
[qemu/ar7.git] / target-alpha / cpu.c
blob26708055d942e20263110263f285e4e1853d16cc
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_realizefn(DeviceState *dev, Error **errp)
29 AlphaCPUClass *acc = ALPHA_CPU_GET_CLASS(dev);
31 acc->parent_realize(dev, errp);
34 /* Sort alphabetically by type name. */
35 static gint alpha_cpu_list_compare(gconstpointer a, gconstpointer b)
37 ObjectClass *class_a = (ObjectClass *)a;
38 ObjectClass *class_b = (ObjectClass *)b;
39 const char *name_a, *name_b;
41 name_a = object_class_get_name(class_a);
42 name_b = object_class_get_name(class_b);
43 return strcmp(name_a, name_b);
46 static void alpha_cpu_list_entry(gpointer data, gpointer user_data)
48 ObjectClass *oc = data;
49 CPUListState *s = user_data;
51 (*s->cpu_fprintf)(s->file, " %s\n",
52 object_class_get_name(oc));
55 void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf)
57 CPUListState s = {
58 .file = f,
59 .cpu_fprintf = cpu_fprintf,
61 GSList *list;
63 list = object_class_get_list(TYPE_ALPHA_CPU, false);
64 list = g_slist_sort(list, alpha_cpu_list_compare);
65 (*cpu_fprintf)(f, "Available CPUs:\n");
66 g_slist_foreach(list, alpha_cpu_list_entry, &s);
67 g_slist_free(list);
70 /* Models */
72 #define TYPE(model) model "-" TYPE_ALPHA_CPU
74 typedef struct AlphaCPUAlias {
75 const char *alias;
76 const char *typename;
77 } AlphaCPUAlias;
79 static const AlphaCPUAlias alpha_cpu_aliases[] = {
80 { "21064", TYPE("ev4") },
81 { "21164", TYPE("ev5") },
82 { "21164a", TYPE("ev56") },
83 { "21164pc", TYPE("pca56") },
84 { "21264", TYPE("ev6") },
85 { "21264a", TYPE("ev67") },
88 static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model)
90 ObjectClass *oc = NULL;
91 char *typename;
92 int i;
94 if (cpu_model == NULL) {
95 return NULL;
98 oc = object_class_by_name(cpu_model);
99 if (oc != NULL && object_class_dynamic_cast(oc, TYPE_ALPHA_CPU) != NULL &&
100 !object_class_is_abstract(oc)) {
101 return oc;
104 for (i = 0; i < ARRAY_SIZE(alpha_cpu_aliases); i++) {
105 if (strcmp(cpu_model, alpha_cpu_aliases[i].alias) == 0) {
106 oc = object_class_by_name(alpha_cpu_aliases[i].typename);
107 assert(oc != NULL && !object_class_is_abstract(oc));
108 return oc;
112 typename = g_strdup_printf("%s-" TYPE_ALPHA_CPU, cpu_model);
113 oc = object_class_by_name(typename);
114 g_free(typename);
115 if (oc != NULL && object_class_is_abstract(oc)) {
116 oc = NULL;
118 return oc;
121 AlphaCPU *cpu_alpha_init(const char *cpu_model)
123 AlphaCPU *cpu;
124 CPUAlphaState *env;
125 ObjectClass *cpu_class;
127 cpu_class = alpha_cpu_class_by_name(cpu_model);
128 if (cpu_class == NULL) {
129 /* Default to ev67; no reason not to emulate insns by default. */
130 cpu_class = object_class_by_name(TYPE("ev67"));
132 cpu = ALPHA_CPU(object_new(object_class_get_name(cpu_class)));
133 env = &cpu->env;
135 env->cpu_model_str = cpu_model;
137 object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
139 return cpu;
142 static void ev4_cpu_initfn(Object *obj)
144 AlphaCPU *cpu = ALPHA_CPU(obj);
145 CPUAlphaState *env = &cpu->env;
147 env->implver = IMPLVER_2106x;
150 static const TypeInfo ev4_cpu_type_info = {
151 .name = TYPE("ev4"),
152 .parent = TYPE_ALPHA_CPU,
153 .instance_init = ev4_cpu_initfn,
156 static void ev5_cpu_initfn(Object *obj)
158 AlphaCPU *cpu = ALPHA_CPU(obj);
159 CPUAlphaState *env = &cpu->env;
161 env->implver = IMPLVER_21164;
164 static const TypeInfo ev5_cpu_type_info = {
165 .name = TYPE("ev5"),
166 .parent = TYPE_ALPHA_CPU,
167 .instance_init = ev5_cpu_initfn,
170 static void ev56_cpu_initfn(Object *obj)
172 AlphaCPU *cpu = ALPHA_CPU(obj);
173 CPUAlphaState *env = &cpu->env;
175 env->amask |= AMASK_BWX;
178 static const TypeInfo ev56_cpu_type_info = {
179 .name = TYPE("ev56"),
180 .parent = TYPE("ev5"),
181 .instance_init = ev56_cpu_initfn,
184 static void pca56_cpu_initfn(Object *obj)
186 AlphaCPU *cpu = ALPHA_CPU(obj);
187 CPUAlphaState *env = &cpu->env;
189 env->amask |= AMASK_MVI;
192 static const TypeInfo pca56_cpu_type_info = {
193 .name = TYPE("pca56"),
194 .parent = TYPE("ev56"),
195 .instance_init = pca56_cpu_initfn,
198 static void ev6_cpu_initfn(Object *obj)
200 AlphaCPU *cpu = ALPHA_CPU(obj);
201 CPUAlphaState *env = &cpu->env;
203 env->implver = IMPLVER_21264;
204 env->amask = AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP;
207 static const TypeInfo ev6_cpu_type_info = {
208 .name = TYPE("ev6"),
209 .parent = TYPE_ALPHA_CPU,
210 .instance_init = ev6_cpu_initfn,
213 static void ev67_cpu_initfn(Object *obj)
215 AlphaCPU *cpu = ALPHA_CPU(obj);
216 CPUAlphaState *env = &cpu->env;
218 env->amask |= AMASK_CIX | AMASK_PREFETCH;
221 static const TypeInfo ev67_cpu_type_info = {
222 .name = TYPE("ev67"),
223 .parent = TYPE("ev6"),
224 .instance_init = ev67_cpu_initfn,
227 static const TypeInfo ev68_cpu_type_info = {
228 .name = TYPE("ev68"),
229 .parent = TYPE("ev67"),
232 static void alpha_cpu_initfn(Object *obj)
234 CPUState *cs = CPU(obj);
235 AlphaCPU *cpu = ALPHA_CPU(obj);
236 CPUAlphaState *env = &cpu->env;
238 cs->env_ptr = env;
239 cpu_exec_init(env);
240 tlb_flush(env, 1);
242 alpha_translate_init();
244 #if defined(CONFIG_USER_ONLY)
245 env->ps = PS_USER_MODE;
246 cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
247 | FPCR_UNFD | FPCR_INED | FPCR_DNOD
248 | FPCR_DYN_NORMAL));
249 #endif
250 env->lock_addr = -1;
251 env->fen = 1;
254 static void alpha_cpu_class_init(ObjectClass *oc, void *data)
256 DeviceClass *dc = DEVICE_CLASS(oc);
257 CPUClass *cc = CPU_CLASS(oc);
258 AlphaCPUClass *acc = ALPHA_CPU_CLASS(oc);
260 acc->parent_realize = dc->realize;
261 dc->realize = alpha_cpu_realizefn;
263 cc->class_by_name = alpha_cpu_class_by_name;
264 cc->do_interrupt = alpha_cpu_do_interrupt;
265 cc->dump_state = alpha_cpu_dump_state;
266 cpu_class_set_do_unassigned_access(cc, alpha_cpu_unassigned_access);
267 device_class_set_vmsd(dc, &vmstate_alpha_cpu);
270 static const TypeInfo alpha_cpu_type_info = {
271 .name = TYPE_ALPHA_CPU,
272 .parent = TYPE_CPU,
273 .instance_size = sizeof(AlphaCPU),
274 .instance_init = alpha_cpu_initfn,
275 .abstract = true,
276 .class_size = sizeof(AlphaCPUClass),
277 .class_init = alpha_cpu_class_init,
280 static void alpha_cpu_register_types(void)
282 type_register_static(&alpha_cpu_type_info);
283 type_register_static(&ev4_cpu_type_info);
284 type_register_static(&ev5_cpu_type_info);
285 type_register_static(&ev56_cpu_type_info);
286 type_register_static(&pca56_cpu_type_info);
287 type_register_static(&ev6_cpu_type_info);
288 type_register_static(&ev67_cpu_type_info);
289 type_register_static(&ev68_cpu_type_info);
292 type_init(alpha_cpu_register_types)