Merge remote-tracking branch 'remotes/awilliam/tags/vfio-update-20150706.0' into...
[qemu/ar7.git] / target-alpha / cpu.c
bloba98b7d8d7269aa17416ff80d34a1fdf627ab8f61
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 bool alpha_cpu_has_work(CPUState *cs)
36 /* Here we are checking to see if the CPU should wake up from HALT.
37 We will have gotten into this state only for WTINT from PALmode. */
38 /* ??? I'm not sure how the IPL state works with WTINT to keep a CPU
39 asleep even if (some) interrupts have been asserted. For now,
40 assume that if a CPU really wants to stay asleep, it will mask
41 interrupts at the chipset level, which will prevent these bits
42 from being set in the first place. */
43 return cs->interrupt_request & (CPU_INTERRUPT_HARD
44 | CPU_INTERRUPT_TIMER
45 | CPU_INTERRUPT_SMP
46 | CPU_INTERRUPT_MCHK);
49 static void alpha_cpu_realizefn(DeviceState *dev, Error **errp)
51 CPUState *cs = CPU(dev);
52 AlphaCPUClass *acc = ALPHA_CPU_GET_CLASS(dev);
54 qemu_init_vcpu(cs);
56 acc->parent_realize(dev, errp);
59 /* Sort alphabetically by type name. */
60 static gint alpha_cpu_list_compare(gconstpointer a, gconstpointer b)
62 ObjectClass *class_a = (ObjectClass *)a;
63 ObjectClass *class_b = (ObjectClass *)b;
64 const char *name_a, *name_b;
66 name_a = object_class_get_name(class_a);
67 name_b = object_class_get_name(class_b);
68 return strcmp(name_a, name_b);
71 static void alpha_cpu_list_entry(gpointer data, gpointer user_data)
73 ObjectClass *oc = data;
74 CPUListState *s = user_data;
76 (*s->cpu_fprintf)(s->file, " %s\n",
77 object_class_get_name(oc));
80 void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf)
82 CPUListState s = {
83 .file = f,
84 .cpu_fprintf = cpu_fprintf,
86 GSList *list;
88 list = object_class_get_list(TYPE_ALPHA_CPU, false);
89 list = g_slist_sort(list, alpha_cpu_list_compare);
90 (*cpu_fprintf)(f, "Available CPUs:\n");
91 g_slist_foreach(list, alpha_cpu_list_entry, &s);
92 g_slist_free(list);
95 /* Models */
97 #define TYPE(model) model "-" TYPE_ALPHA_CPU
99 typedef struct AlphaCPUAlias {
100 const char *alias;
101 const char *typename;
102 } AlphaCPUAlias;
104 static const AlphaCPUAlias alpha_cpu_aliases[] = {
105 { "21064", TYPE("ev4") },
106 { "21164", TYPE("ev5") },
107 { "21164a", TYPE("ev56") },
108 { "21164pc", TYPE("pca56") },
109 { "21264", TYPE("ev6") },
110 { "21264a", TYPE("ev67") },
113 static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model)
115 ObjectClass *oc = NULL;
116 char *typename;
117 int i;
119 if (cpu_model == NULL) {
120 return NULL;
123 oc = object_class_by_name(cpu_model);
124 if (oc != NULL && object_class_dynamic_cast(oc, TYPE_ALPHA_CPU) != NULL &&
125 !object_class_is_abstract(oc)) {
126 return oc;
129 for (i = 0; i < ARRAY_SIZE(alpha_cpu_aliases); i++) {
130 if (strcmp(cpu_model, alpha_cpu_aliases[i].alias) == 0) {
131 oc = object_class_by_name(alpha_cpu_aliases[i].typename);
132 assert(oc != NULL && !object_class_is_abstract(oc));
133 return oc;
137 typename = g_strdup_printf("%s-" TYPE_ALPHA_CPU, cpu_model);
138 oc = object_class_by_name(typename);
139 g_free(typename);
140 if (oc != NULL && object_class_is_abstract(oc)) {
141 oc = NULL;
143 return oc;
146 AlphaCPU *cpu_alpha_init(const char *cpu_model)
148 AlphaCPU *cpu;
149 ObjectClass *cpu_class;
151 cpu_class = alpha_cpu_class_by_name(cpu_model);
152 if (cpu_class == NULL) {
153 /* Default to ev67; no reason not to emulate insns by default. */
154 cpu_class = object_class_by_name(TYPE("ev67"));
156 cpu = ALPHA_CPU(object_new(object_class_get_name(cpu_class)));
158 object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
160 return cpu;
163 static void ev4_cpu_initfn(Object *obj)
165 AlphaCPU *cpu = ALPHA_CPU(obj);
166 CPUAlphaState *env = &cpu->env;
168 env->implver = IMPLVER_2106x;
171 static const TypeInfo ev4_cpu_type_info = {
172 .name = TYPE("ev4"),
173 .parent = TYPE_ALPHA_CPU,
174 .instance_init = ev4_cpu_initfn,
177 static void ev5_cpu_initfn(Object *obj)
179 AlphaCPU *cpu = ALPHA_CPU(obj);
180 CPUAlphaState *env = &cpu->env;
182 env->implver = IMPLVER_21164;
185 static const TypeInfo ev5_cpu_type_info = {
186 .name = TYPE("ev5"),
187 .parent = TYPE_ALPHA_CPU,
188 .instance_init = ev5_cpu_initfn,
191 static void ev56_cpu_initfn(Object *obj)
193 AlphaCPU *cpu = ALPHA_CPU(obj);
194 CPUAlphaState *env = &cpu->env;
196 env->amask |= AMASK_BWX;
199 static const TypeInfo ev56_cpu_type_info = {
200 .name = TYPE("ev56"),
201 .parent = TYPE("ev5"),
202 .instance_init = ev56_cpu_initfn,
205 static void pca56_cpu_initfn(Object *obj)
207 AlphaCPU *cpu = ALPHA_CPU(obj);
208 CPUAlphaState *env = &cpu->env;
210 env->amask |= AMASK_MVI;
213 static const TypeInfo pca56_cpu_type_info = {
214 .name = TYPE("pca56"),
215 .parent = TYPE("ev56"),
216 .instance_init = pca56_cpu_initfn,
219 static void ev6_cpu_initfn(Object *obj)
221 AlphaCPU *cpu = ALPHA_CPU(obj);
222 CPUAlphaState *env = &cpu->env;
224 env->implver = IMPLVER_21264;
225 env->amask = AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP;
228 static const TypeInfo ev6_cpu_type_info = {
229 .name = TYPE("ev6"),
230 .parent = TYPE_ALPHA_CPU,
231 .instance_init = ev6_cpu_initfn,
234 static void ev67_cpu_initfn(Object *obj)
236 AlphaCPU *cpu = ALPHA_CPU(obj);
237 CPUAlphaState *env = &cpu->env;
239 env->amask |= AMASK_CIX | AMASK_PREFETCH;
242 static const TypeInfo ev67_cpu_type_info = {
243 .name = TYPE("ev67"),
244 .parent = TYPE("ev6"),
245 .instance_init = ev67_cpu_initfn,
248 static const TypeInfo ev68_cpu_type_info = {
249 .name = TYPE("ev68"),
250 .parent = TYPE("ev67"),
253 static void alpha_cpu_initfn(Object *obj)
255 CPUState *cs = CPU(obj);
256 AlphaCPU *cpu = ALPHA_CPU(obj);
257 CPUAlphaState *env = &cpu->env;
259 cs->env_ptr = env;
260 cpu_exec_init(env);
261 tlb_flush(cs, 1);
263 alpha_translate_init();
265 #if defined(CONFIG_USER_ONLY)
266 env->ps = PS_USER_MODE;
267 cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
268 | FPCR_UNFD | FPCR_INED | FPCR_DNOD
269 | FPCR_DYN_NORMAL));
270 #endif
271 env->lock_addr = -1;
272 env->fen = 1;
275 static void alpha_cpu_class_init(ObjectClass *oc, void *data)
277 DeviceClass *dc = DEVICE_CLASS(oc);
278 CPUClass *cc = CPU_CLASS(oc);
279 AlphaCPUClass *acc = ALPHA_CPU_CLASS(oc);
281 acc->parent_realize = dc->realize;
282 dc->realize = alpha_cpu_realizefn;
284 cc->class_by_name = alpha_cpu_class_by_name;
285 cc->has_work = alpha_cpu_has_work;
286 cc->do_interrupt = alpha_cpu_do_interrupt;
287 cc->cpu_exec_interrupt = alpha_cpu_exec_interrupt;
288 cc->dump_state = alpha_cpu_dump_state;
289 cc->set_pc = alpha_cpu_set_pc;
290 cc->gdb_read_register = alpha_cpu_gdb_read_register;
291 cc->gdb_write_register = alpha_cpu_gdb_write_register;
292 #ifdef CONFIG_USER_ONLY
293 cc->handle_mmu_fault = alpha_cpu_handle_mmu_fault;
294 #else
295 cc->do_unassigned_access = alpha_cpu_unassigned_access;
296 cc->do_unaligned_access = alpha_cpu_do_unaligned_access;
297 cc->get_phys_page_debug = alpha_cpu_get_phys_page_debug;
298 dc->vmsd = &vmstate_alpha_cpu;
299 #endif
300 cc->gdb_num_core_regs = 67;
303 static const TypeInfo alpha_cpu_type_info = {
304 .name = TYPE_ALPHA_CPU,
305 .parent = TYPE_CPU,
306 .instance_size = sizeof(AlphaCPU),
307 .instance_init = alpha_cpu_initfn,
308 .abstract = true,
309 .class_size = sizeof(AlphaCPUClass),
310 .class_init = alpha_cpu_class_init,
313 static void alpha_cpu_register_types(void)
315 type_register_static(&alpha_cpu_type_info);
316 type_register_static(&ev4_cpu_type_info);
317 type_register_static(&ev5_cpu_type_info);
318 type_register_static(&ev56_cpu_type_info);
319 type_register_static(&pca56_cpu_type_info);
320 type_register_static(&ev6_cpu_type_info);
321 type_register_static(&ev67_cpu_type_info);
322 type_register_static(&ev68_cpu_type_info);
325 type_init(alpha_cpu_register_types)