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>
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
);
34 static void alpha_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
36 CPUState
*cs
= CPU(dev
);
37 AlphaCPUClass
*acc
= ALPHA_CPU_GET_CLASS(dev
);
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
)
69 .cpu_fprintf
= cpu_fprintf
,
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
);
82 #define TYPE(model) model "-" TYPE_ALPHA_CPU
84 typedef struct 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
;
104 if (cpu_model
== 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
)) {
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
));
122 typename
= g_strdup_printf("%s-" TYPE_ALPHA_CPU
, cpu_model
);
123 oc
= object_class_by_name(typename
);
125 if (oc
!= NULL
&& object_class_is_abstract(oc
)) {
131 AlphaCPU
*cpu_alpha_init(const char *cpu_model
)
135 ObjectClass
*cpu_class
;
137 cpu_class
= alpha_cpu_class_by_name(cpu_model
);
138 if (cpu_class
== NULL
) {
139 /* Default to ev67; no reason not to emulate insns by default. */
140 cpu_class
= object_class_by_name(TYPE("ev67"));
142 cpu
= ALPHA_CPU(object_new(object_class_get_name(cpu_class
)));
145 env
->cpu_model_str
= cpu_model
;
147 object_property_set_bool(OBJECT(cpu
), true, "realized", NULL
);
152 static void ev4_cpu_initfn(Object
*obj
)
154 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
155 CPUAlphaState
*env
= &cpu
->env
;
157 env
->implver
= IMPLVER_2106x
;
160 static const TypeInfo ev4_cpu_type_info
= {
162 .parent
= TYPE_ALPHA_CPU
,
163 .instance_init
= ev4_cpu_initfn
,
166 static void ev5_cpu_initfn(Object
*obj
)
168 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
169 CPUAlphaState
*env
= &cpu
->env
;
171 env
->implver
= IMPLVER_21164
;
174 static const TypeInfo ev5_cpu_type_info
= {
176 .parent
= TYPE_ALPHA_CPU
,
177 .instance_init
= ev5_cpu_initfn
,
180 static void ev56_cpu_initfn(Object
*obj
)
182 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
183 CPUAlphaState
*env
= &cpu
->env
;
185 env
->amask
|= AMASK_BWX
;
188 static const TypeInfo ev56_cpu_type_info
= {
189 .name
= TYPE("ev56"),
190 .parent
= TYPE("ev5"),
191 .instance_init
= ev56_cpu_initfn
,
194 static void pca56_cpu_initfn(Object
*obj
)
196 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
197 CPUAlphaState
*env
= &cpu
->env
;
199 env
->amask
|= AMASK_MVI
;
202 static const TypeInfo pca56_cpu_type_info
= {
203 .name
= TYPE("pca56"),
204 .parent
= TYPE("ev56"),
205 .instance_init
= pca56_cpu_initfn
,
208 static void ev6_cpu_initfn(Object
*obj
)
210 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
211 CPUAlphaState
*env
= &cpu
->env
;
213 env
->implver
= IMPLVER_21264
;
214 env
->amask
= AMASK_BWX
| AMASK_FIX
| AMASK_MVI
| AMASK_TRAP
;
217 static const TypeInfo ev6_cpu_type_info
= {
219 .parent
= TYPE_ALPHA_CPU
,
220 .instance_init
= ev6_cpu_initfn
,
223 static void ev67_cpu_initfn(Object
*obj
)
225 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
226 CPUAlphaState
*env
= &cpu
->env
;
228 env
->amask
|= AMASK_CIX
| AMASK_PREFETCH
;
231 static const TypeInfo ev67_cpu_type_info
= {
232 .name
= TYPE("ev67"),
233 .parent
= TYPE("ev6"),
234 .instance_init
= ev67_cpu_initfn
,
237 static const TypeInfo ev68_cpu_type_info
= {
238 .name
= TYPE("ev68"),
239 .parent
= TYPE("ev67"),
242 static void alpha_cpu_initfn(Object
*obj
)
244 CPUState
*cs
= CPU(obj
);
245 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
246 CPUAlphaState
*env
= &cpu
->env
;
252 alpha_translate_init();
254 #if defined(CONFIG_USER_ONLY)
255 env
->ps
= PS_USER_MODE
;
256 cpu_alpha_store_fpcr(env
, (FPCR_INVD
| FPCR_DZED
| FPCR_OVFD
257 | FPCR_UNFD
| FPCR_INED
| FPCR_DNOD
264 static void alpha_cpu_class_init(ObjectClass
*oc
, void *data
)
266 DeviceClass
*dc
= DEVICE_CLASS(oc
);
267 CPUClass
*cc
= CPU_CLASS(oc
);
268 AlphaCPUClass
*acc
= ALPHA_CPU_CLASS(oc
);
270 acc
->parent_realize
= dc
->realize
;
271 dc
->realize
= alpha_cpu_realizefn
;
273 cc
->class_by_name
= alpha_cpu_class_by_name
;
274 cc
->do_interrupt
= alpha_cpu_do_interrupt
;
275 cc
->dump_state
= alpha_cpu_dump_state
;
276 cc
->set_pc
= alpha_cpu_set_pc
;
277 cc
->gdb_read_register
= alpha_cpu_gdb_read_register
;
278 cc
->gdb_write_register
= alpha_cpu_gdb_write_register
;
279 #ifndef CONFIG_USER_ONLY
280 cc
->do_unassigned_access
= alpha_cpu_unassigned_access
;
281 cc
->get_phys_page_debug
= alpha_cpu_get_phys_page_debug
;
282 dc
->vmsd
= &vmstate_alpha_cpu
;
284 cc
->gdb_num_core_regs
= 67;
287 static const TypeInfo alpha_cpu_type_info
= {
288 .name
= TYPE_ALPHA_CPU
,
290 .instance_size
= sizeof(AlphaCPU
),
291 .instance_init
= alpha_cpu_initfn
,
293 .class_size
= sizeof(AlphaCPUClass
),
294 .class_init
= alpha_cpu_class_init
,
297 static void alpha_cpu_register_types(void)
299 type_register_static(&alpha_cpu_type_info
);
300 type_register_static(&ev4_cpu_type_info
);
301 type_register_static(&ev5_cpu_type_info
);
302 type_register_static(&ev56_cpu_type_info
);
303 type_register_static(&pca56_cpu_type_info
);
304 type_register_static(&ev6_cpu_type_info
);
305 type_register_static(&ev67_cpu_type_info
);
306 type_register_static(&ev68_cpu_type_info
);
309 type_init(alpha_cpu_register_types
)