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"
26 static void alpha_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
28 AlphaCPU
*cpu
= ALPHA_CPU(dev
);
29 AlphaCPUClass
*acc
= ALPHA_CPU_GET_CLASS(dev
);
31 qemu_init_vcpu(&cpu
->env
);
33 acc
->parent_realize(dev
, errp
);
36 /* Sort alphabetically by type name. */
37 static gint
alpha_cpu_list_compare(gconstpointer a
, gconstpointer b
)
39 ObjectClass
*class_a
= (ObjectClass
*)a
;
40 ObjectClass
*class_b
= (ObjectClass
*)b
;
41 const char *name_a
, *name_b
;
43 name_a
= object_class_get_name(class_a
);
44 name_b
= object_class_get_name(class_b
);
45 return strcmp(name_a
, name_b
);
48 static void alpha_cpu_list_entry(gpointer data
, gpointer user_data
)
50 ObjectClass
*oc
= data
;
51 CPUListState
*s
= user_data
;
53 (*s
->cpu_fprintf
)(s
->file
, " %s\n",
54 object_class_get_name(oc
));
57 void alpha_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
61 .cpu_fprintf
= cpu_fprintf
,
65 list
= object_class_get_list(TYPE_ALPHA_CPU
, false);
66 list
= g_slist_sort(list
, alpha_cpu_list_compare
);
67 (*cpu_fprintf
)(f
, "Available CPUs:\n");
68 g_slist_foreach(list
, alpha_cpu_list_entry
, &s
);
74 #define TYPE(model) model "-" TYPE_ALPHA_CPU
76 typedef struct AlphaCPUAlias
{
81 static const AlphaCPUAlias alpha_cpu_aliases
[] = {
82 { "21064", TYPE("ev4") },
83 { "21164", TYPE("ev5") },
84 { "21164a", TYPE("ev56") },
85 { "21164pc", TYPE("pca56") },
86 { "21264", TYPE("ev6") },
87 { "21264a", TYPE("ev67") },
90 static ObjectClass
*alpha_cpu_class_by_name(const char *cpu_model
)
92 ObjectClass
*oc
= NULL
;
96 if (cpu_model
== NULL
) {
100 oc
= object_class_by_name(cpu_model
);
101 if (oc
!= NULL
&& object_class_dynamic_cast(oc
, TYPE_ALPHA_CPU
) != NULL
&&
102 !object_class_is_abstract(oc
)) {
106 for (i
= 0; i
< ARRAY_SIZE(alpha_cpu_aliases
); i
++) {
107 if (strcmp(cpu_model
, alpha_cpu_aliases
[i
].alias
) == 0) {
108 oc
= object_class_by_name(alpha_cpu_aliases
[i
].typename
);
109 assert(oc
!= NULL
&& !object_class_is_abstract(oc
));
114 typename
= g_strdup_printf("%s-" TYPE_ALPHA_CPU
, cpu_model
);
115 oc
= object_class_by_name(typename
);
117 if (oc
!= NULL
&& object_class_is_abstract(oc
)) {
123 AlphaCPU
*cpu_alpha_init(const char *cpu_model
)
127 ObjectClass
*cpu_class
;
129 cpu_class
= alpha_cpu_class_by_name(cpu_model
);
130 if (cpu_class
== NULL
) {
131 /* Default to ev67; no reason not to emulate insns by default. */
132 cpu_class
= object_class_by_name(TYPE("ev67"));
134 cpu
= ALPHA_CPU(object_new(object_class_get_name(cpu_class
)));
137 env
->cpu_model_str
= cpu_model
;
139 object_property_set_bool(OBJECT(cpu
), true, "realized", NULL
);
144 static void ev4_cpu_initfn(Object
*obj
)
146 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
147 CPUAlphaState
*env
= &cpu
->env
;
149 env
->implver
= IMPLVER_2106x
;
152 static const TypeInfo ev4_cpu_type_info
= {
154 .parent
= TYPE_ALPHA_CPU
,
155 .instance_init
= ev4_cpu_initfn
,
158 static void ev5_cpu_initfn(Object
*obj
)
160 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
161 CPUAlphaState
*env
= &cpu
->env
;
163 env
->implver
= IMPLVER_21164
;
166 static const TypeInfo ev5_cpu_type_info
= {
168 .parent
= TYPE_ALPHA_CPU
,
169 .instance_init
= ev5_cpu_initfn
,
172 static void ev56_cpu_initfn(Object
*obj
)
174 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
175 CPUAlphaState
*env
= &cpu
->env
;
177 env
->amask
|= AMASK_BWX
;
180 static const TypeInfo ev56_cpu_type_info
= {
181 .name
= TYPE("ev56"),
182 .parent
= TYPE("ev5"),
183 .instance_init
= ev56_cpu_initfn
,
186 static void pca56_cpu_initfn(Object
*obj
)
188 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
189 CPUAlphaState
*env
= &cpu
->env
;
191 env
->amask
|= AMASK_MVI
;
194 static const TypeInfo pca56_cpu_type_info
= {
195 .name
= TYPE("pca56"),
196 .parent
= TYPE("ev56"),
197 .instance_init
= pca56_cpu_initfn
,
200 static void ev6_cpu_initfn(Object
*obj
)
202 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
203 CPUAlphaState
*env
= &cpu
->env
;
205 env
->implver
= IMPLVER_21264
;
206 env
->amask
= AMASK_BWX
| AMASK_FIX
| AMASK_MVI
| AMASK_TRAP
;
209 static const TypeInfo ev6_cpu_type_info
= {
211 .parent
= TYPE_ALPHA_CPU
,
212 .instance_init
= ev6_cpu_initfn
,
215 static void ev67_cpu_initfn(Object
*obj
)
217 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
218 CPUAlphaState
*env
= &cpu
->env
;
220 env
->amask
|= AMASK_CIX
| AMASK_PREFETCH
;
223 static const TypeInfo ev67_cpu_type_info
= {
224 .name
= TYPE("ev67"),
225 .parent
= TYPE("ev6"),
226 .instance_init
= ev67_cpu_initfn
,
229 static const TypeInfo ev68_cpu_type_info
= {
230 .name
= TYPE("ev68"),
231 .parent
= TYPE("ev67"),
234 static void alpha_cpu_initfn(Object
*obj
)
236 CPUState
*cs
= CPU(obj
);
237 AlphaCPU
*cpu
= ALPHA_CPU(obj
);
238 CPUAlphaState
*env
= &cpu
->env
;
244 alpha_translate_init();
246 #if defined(CONFIG_USER_ONLY)
247 env
->ps
= PS_USER_MODE
;
248 cpu_alpha_store_fpcr(env
, (FPCR_INVD
| FPCR_DZED
| FPCR_OVFD
249 | FPCR_UNFD
| FPCR_INED
| FPCR_DNOD
256 static void alpha_cpu_class_init(ObjectClass
*oc
, void *data
)
258 DeviceClass
*dc
= DEVICE_CLASS(oc
);
259 CPUClass
*cc
= CPU_CLASS(oc
);
260 AlphaCPUClass
*acc
= ALPHA_CPU_CLASS(oc
);
262 acc
->parent_realize
= dc
->realize
;
263 dc
->realize
= alpha_cpu_realizefn
;
265 cc
->class_by_name
= alpha_cpu_class_by_name
;
266 cc
->do_interrupt
= alpha_cpu_do_interrupt
;
269 static const TypeInfo alpha_cpu_type_info
= {
270 .name
= TYPE_ALPHA_CPU
,
272 .instance_size
= sizeof(AlphaCPU
),
273 .instance_init
= alpha_cpu_initfn
,
275 .class_size
= sizeof(AlphaCPUClass
),
276 .class_init
= alpha_cpu_class_init
,
279 static void alpha_cpu_register_types(void)
281 type_register_static(&alpha_cpu_type_info
);
282 type_register_static(&ev4_cpu_type_info
);
283 type_register_static(&ev5_cpu_type_info
);
284 type_register_static(&ev56_cpu_type_info
);
285 type_register_static(&pca56_cpu_type_info
);
286 type_register_static(&ev6_cpu_type_info
);
287 type_register_static(&ev67_cpu_type_info
);
288 type_register_static(&ev68_cpu_type_info
);
291 type_init(alpha_cpu_register_types
)