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 AlphaCPUClass
*acc
= ALPHA_CPU_GET_CLASS(dev
);
38 acc
->parent_realize(dev
, errp
);
41 /* Sort alphabetically by type name. */
42 static gint
alpha_cpu_list_compare(gconstpointer a
, gconstpointer b
)
44 ObjectClass
*class_a
= (ObjectClass
*)a
;
45 ObjectClass
*class_b
= (ObjectClass
*)b
;
46 const char *name_a
, *name_b
;
48 name_a
= object_class_get_name(class_a
);
49 name_b
= object_class_get_name(class_b
);
50 return strcmp(name_a
, name_b
);
53 static void alpha_cpu_list_entry(gpointer data
, gpointer user_data
)
55 ObjectClass
*oc
= data
;
56 CPUListState
*s
= user_data
;
58 (*s
->cpu_fprintf
)(s
->file
, " %s\n",
59 object_class_get_name(oc
));
62 void alpha_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
66 .cpu_fprintf
= cpu_fprintf
,
70 list
= object_class_get_list(TYPE_ALPHA_CPU
, false);
71 list
= g_slist_sort(list
, alpha_cpu_list_compare
);
72 (*cpu_fprintf
)(f
, "Available CPUs:\n");
73 g_slist_foreach(list
, alpha_cpu_list_entry
, &s
);
79 #define TYPE(model) model "-" TYPE_ALPHA_CPU
81 typedef struct AlphaCPUAlias
{
86 static const AlphaCPUAlias alpha_cpu_aliases
[] = {
87 { "21064", TYPE("ev4") },
88 { "21164", TYPE("ev5") },
89 { "21164a", TYPE("ev56") },
90 { "21164pc", TYPE("pca56") },
91 { "21264", TYPE("ev6") },
92 { "21264a", TYPE("ev67") },
95 static ObjectClass
*alpha_cpu_class_by_name(const char *cpu_model
)
97 ObjectClass
*oc
= NULL
;
101 if (cpu_model
== NULL
) {
105 oc
= object_class_by_name(cpu_model
);
106 if (oc
!= NULL
&& object_class_dynamic_cast(oc
, TYPE_ALPHA_CPU
) != NULL
&&
107 !object_class_is_abstract(oc
)) {
111 for (i
= 0; i
< ARRAY_SIZE(alpha_cpu_aliases
); i
++) {
112 if (strcmp(cpu_model
, alpha_cpu_aliases
[i
].alias
) == 0) {
113 oc
= object_class_by_name(alpha_cpu_aliases
[i
].typename
);
114 assert(oc
!= NULL
&& !object_class_is_abstract(oc
));
119 typename
= g_strdup_printf("%s-" TYPE_ALPHA_CPU
, cpu_model
);
120 oc
= object_class_by_name(typename
);
122 if (oc
!= NULL
&& object_class_is_abstract(oc
)) {
128 AlphaCPU
*cpu_alpha_init(const char *cpu_model
)
132 ObjectClass
*cpu_class
;
134 cpu_class
= alpha_cpu_class_by_name(cpu_model
);
135 if (cpu_class
== NULL
) {
136 /* Default to ev67; no reason not to emulate insns by default. */
137 cpu_class
= object_class_by_name(TYPE("ev67"));
139 cpu
= ALPHA_CPU(object_new(object_class_get_name(cpu_class
)));
142 env
->cpu_model_str
= cpu_model
;
144 object_property_set_bool(OBJECT(cpu
), true, "realized", NULL
);
149 static void ev4_cpu_initfn(Object
*obj
)
151 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
152 CPUAlphaState
*env
= &cpu
->env
;
154 env
->implver
= IMPLVER_2106x
;
157 static const TypeInfo ev4_cpu_type_info
= {
159 .parent
= TYPE_ALPHA_CPU
,
160 .instance_init
= ev4_cpu_initfn
,
163 static void ev5_cpu_initfn(Object
*obj
)
165 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
166 CPUAlphaState
*env
= &cpu
->env
;
168 env
->implver
= IMPLVER_21164
;
171 static const TypeInfo ev5_cpu_type_info
= {
173 .parent
= TYPE_ALPHA_CPU
,
174 .instance_init
= ev5_cpu_initfn
,
177 static void ev56_cpu_initfn(Object
*obj
)
179 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
180 CPUAlphaState
*env
= &cpu
->env
;
182 env
->amask
|= AMASK_BWX
;
185 static const TypeInfo ev56_cpu_type_info
= {
186 .name
= TYPE("ev56"),
187 .parent
= TYPE("ev5"),
188 .instance_init
= ev56_cpu_initfn
,
191 static void pca56_cpu_initfn(Object
*obj
)
193 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
194 CPUAlphaState
*env
= &cpu
->env
;
196 env
->amask
|= AMASK_MVI
;
199 static const TypeInfo pca56_cpu_type_info
= {
200 .name
= TYPE("pca56"),
201 .parent
= TYPE("ev56"),
202 .instance_init
= pca56_cpu_initfn
,
205 static void ev6_cpu_initfn(Object
*obj
)
207 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
208 CPUAlphaState
*env
= &cpu
->env
;
210 env
->implver
= IMPLVER_21264
;
211 env
->amask
= AMASK_BWX
| AMASK_FIX
| AMASK_MVI
| AMASK_TRAP
;
214 static const TypeInfo ev6_cpu_type_info
= {
216 .parent
= TYPE_ALPHA_CPU
,
217 .instance_init
= ev6_cpu_initfn
,
220 static void ev67_cpu_initfn(Object
*obj
)
222 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
223 CPUAlphaState
*env
= &cpu
->env
;
225 env
->amask
|= AMASK_CIX
| AMASK_PREFETCH
;
228 static const TypeInfo ev67_cpu_type_info
= {
229 .name
= TYPE("ev67"),
230 .parent
= TYPE("ev6"),
231 .instance_init
= ev67_cpu_initfn
,
234 static const TypeInfo ev68_cpu_type_info
= {
235 .name
= TYPE("ev68"),
236 .parent
= TYPE("ev67"),
239 static void alpha_cpu_initfn(Object
*obj
)
241 CPUState
*cs
= CPU(obj
);
242 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
243 CPUAlphaState
*env
= &cpu
->env
;
249 alpha_translate_init();
251 #if defined(CONFIG_USER_ONLY)
252 env
->ps
= PS_USER_MODE
;
253 cpu_alpha_store_fpcr(env
, (FPCR_INVD
| FPCR_DZED
| FPCR_OVFD
254 | FPCR_UNFD
| FPCR_INED
| FPCR_DNOD
261 static void alpha_cpu_class_init(ObjectClass
*oc
, void *data
)
263 DeviceClass
*dc
= DEVICE_CLASS(oc
);
264 CPUClass
*cc
= CPU_CLASS(oc
);
265 AlphaCPUClass
*acc
= ALPHA_CPU_CLASS(oc
);
267 acc
->parent_realize
= dc
->realize
;
268 dc
->realize
= alpha_cpu_realizefn
;
270 cc
->class_by_name
= alpha_cpu_class_by_name
;
271 cc
->do_interrupt
= alpha_cpu_do_interrupt
;
272 cc
->dump_state
= alpha_cpu_dump_state
;
273 cc
->set_pc
= alpha_cpu_set_pc
;
274 #ifndef CONFIG_USER_ONLY
275 cc
->do_unassigned_access
= alpha_cpu_unassigned_access
;
276 cc
->get_phys_page_debug
= alpha_cpu_get_phys_page_debug
;
277 dc
->vmsd
= &vmstate_alpha_cpu
;
281 static const TypeInfo alpha_cpu_type_info
= {
282 .name
= TYPE_ALPHA_CPU
,
284 .instance_size
= sizeof(AlphaCPU
),
285 .instance_init
= alpha_cpu_initfn
,
287 .class_size
= sizeof(AlphaCPUClass
),
288 .class_init
= alpha_cpu_class_init
,
291 static void alpha_cpu_register_types(void)
293 type_register_static(&alpha_cpu_type_info
);
294 type_register_static(&ev4_cpu_type_info
);
295 type_register_static(&ev5_cpu_type_info
);
296 type_register_static(&ev56_cpu_type_info
);
297 type_register_static(&pca56_cpu_type_info
);
298 type_register_static(&ev6_cpu_type_info
);
299 type_register_static(&ev67_cpu_type_info
);
300 type_register_static(&ev68_cpu_type_info
);
303 type_init(alpha_cpu_register_types
)