]>
Commit | Line | Data |
---|---|---|
25ebd80f AF |
1 | /* |
2 | * QEMU Alpha CPU | |
3 | * | |
9444006f | 4 | * Copyright (c) 2007 Jocelyn Mayer |
25ebd80f AF |
5 | * Copyright (c) 2012 SUSE LINUX Products GmbH |
6 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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> | |
20 | */ | |
21 | ||
3993c6bd | 22 | #include "cpu.h" |
25ebd80f | 23 | #include "qemu-common.h" |
501a7ce7 | 24 | #include "qapi/error.h" |
25ebd80f AF |
25 | |
26 | ||
0c28246f AF |
27 | static void alpha_cpu_realize(Object *obj, Error **errp) |
28 | { | |
0c28246f AF |
29 | AlphaCPU *cpu = ALPHA_CPU(obj); |
30 | ||
31 | qemu_init_vcpu(&cpu->env); | |
0c28246f AF |
32 | } |
33 | ||
494342b3 AF |
34 | /* Sort alphabetically by type name. */ |
35 | static gint alpha_cpu_list_compare(gconstpointer a, gconstpointer b) | |
36 | { | |
37 | ObjectClass *class_a = (ObjectClass *)a; | |
38 | ObjectClass *class_b = (ObjectClass *)b; | |
39 | const char *name_a, *name_b; | |
40 | ||
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); | |
44 | } | |
45 | ||
46 | static void alpha_cpu_list_entry(gpointer data, gpointer user_data) | |
47 | { | |
48 | ObjectClass *oc = data; | |
92a31361 | 49 | CPUListState *s = user_data; |
494342b3 AF |
50 | |
51 | (*s->cpu_fprintf)(s->file, " %s\n", | |
52 | object_class_get_name(oc)); | |
53 | } | |
54 | ||
55 | void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf) | |
56 | { | |
92a31361 | 57 | CPUListState s = { |
494342b3 AF |
58 | .file = f, |
59 | .cpu_fprintf = cpu_fprintf, | |
60 | }; | |
61 | GSList *list; | |
62 | ||
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); | |
68 | } | |
69 | ||
0c28246f AF |
70 | /* Models */ |
71 | ||
72 | #define TYPE(model) model "-" TYPE_ALPHA_CPU | |
73 | ||
74 | typedef struct AlphaCPUAlias { | |
75 | const char *alias; | |
76 | const char *typename; | |
77 | } AlphaCPUAlias; | |
78 | ||
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") }, | |
86 | }; | |
87 | ||
88 | static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model) | |
89 | { | |
90 | ObjectClass *oc = NULL; | |
91 | char *typename; | |
92 | int i; | |
93 | ||
94 | if (cpu_model == NULL) { | |
95 | return NULL; | |
96 | } | |
97 | ||
98 | oc = object_class_by_name(cpu_model); | |
99 | if (oc != NULL) { | |
100 | return oc; | |
101 | } | |
102 | ||
103 | for (i = 0; i < ARRAY_SIZE(alpha_cpu_aliases); i++) { | |
104 | if (strcmp(cpu_model, alpha_cpu_aliases[i].alias) == 0) { | |
105 | oc = object_class_by_name(alpha_cpu_aliases[i].typename); | |
106 | assert(oc != NULL); | |
107 | return oc; | |
108 | } | |
109 | } | |
110 | ||
111 | typename = g_strdup_printf("%s-" TYPE_ALPHA_CPU, cpu_model); | |
112 | oc = object_class_by_name(typename); | |
113 | g_free(typename); | |
114 | return oc; | |
115 | } | |
116 | ||
117 | AlphaCPU *cpu_alpha_init(const char *cpu_model) | |
118 | { | |
119 | AlphaCPU *cpu; | |
120 | CPUAlphaState *env; | |
121 | ObjectClass *cpu_class; | |
122 | ||
123 | cpu_class = alpha_cpu_class_by_name(cpu_model); | |
124 | if (cpu_class == NULL) { | |
125 | /* Default to ev67; no reason not to emulate insns by default. */ | |
126 | cpu_class = object_class_by_name(TYPE("ev67")); | |
127 | } | |
128 | cpu = ALPHA_CPU(object_new(object_class_get_name(cpu_class))); | |
129 | env = &cpu->env; | |
130 | ||
131 | env->cpu_model_str = cpu_model; | |
132 | ||
133 | alpha_cpu_realize(OBJECT(cpu), NULL); | |
134 | return cpu; | |
135 | } | |
136 | ||
137 | static void ev4_cpu_initfn(Object *obj) | |
138 | { | |
139 | AlphaCPU *cpu = ALPHA_CPU(obj); | |
140 | CPUAlphaState *env = &cpu->env; | |
141 | ||
142 | env->implver = IMPLVER_2106x; | |
143 | } | |
144 | ||
145 | static const TypeInfo ev4_cpu_type_info = { | |
146 | .name = TYPE("ev4"), | |
147 | .parent = TYPE_ALPHA_CPU, | |
148 | .instance_init = ev4_cpu_initfn, | |
149 | }; | |
150 | ||
151 | static void ev5_cpu_initfn(Object *obj) | |
152 | { | |
153 | AlphaCPU *cpu = ALPHA_CPU(obj); | |
154 | CPUAlphaState *env = &cpu->env; | |
155 | ||
156 | env->implver = IMPLVER_21164; | |
157 | } | |
158 | ||
159 | static const TypeInfo ev5_cpu_type_info = { | |
160 | .name = TYPE("ev5"), | |
161 | .parent = TYPE_ALPHA_CPU, | |
162 | .instance_init = ev5_cpu_initfn, | |
163 | }; | |
164 | ||
165 | static void ev56_cpu_initfn(Object *obj) | |
166 | { | |
167 | AlphaCPU *cpu = ALPHA_CPU(obj); | |
168 | CPUAlphaState *env = &cpu->env; | |
169 | ||
170 | env->amask |= AMASK_BWX; | |
171 | } | |
172 | ||
173 | static const TypeInfo ev56_cpu_type_info = { | |
174 | .name = TYPE("ev56"), | |
175 | .parent = TYPE("ev5"), | |
176 | .instance_init = ev56_cpu_initfn, | |
177 | }; | |
178 | ||
179 | static void pca56_cpu_initfn(Object *obj) | |
180 | { | |
181 | AlphaCPU *cpu = ALPHA_CPU(obj); | |
182 | CPUAlphaState *env = &cpu->env; | |
183 | ||
184 | env->amask |= AMASK_MVI; | |
185 | } | |
186 | ||
187 | static const TypeInfo pca56_cpu_type_info = { | |
188 | .name = TYPE("pca56"), | |
189 | .parent = TYPE("ev56"), | |
190 | .instance_init = pca56_cpu_initfn, | |
191 | }; | |
192 | ||
193 | static void ev6_cpu_initfn(Object *obj) | |
194 | { | |
195 | AlphaCPU *cpu = ALPHA_CPU(obj); | |
196 | CPUAlphaState *env = &cpu->env; | |
197 | ||
198 | env->implver = IMPLVER_21264; | |
199 | env->amask = AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP; | |
200 | } | |
201 | ||
202 | static const TypeInfo ev6_cpu_type_info = { | |
203 | .name = TYPE("ev6"), | |
204 | .parent = TYPE_ALPHA_CPU, | |
205 | .instance_init = ev6_cpu_initfn, | |
206 | }; | |
207 | ||
208 | static void ev67_cpu_initfn(Object *obj) | |
209 | { | |
210 | AlphaCPU *cpu = ALPHA_CPU(obj); | |
211 | CPUAlphaState *env = &cpu->env; | |
212 | ||
213 | env->amask |= AMASK_CIX | AMASK_PREFETCH; | |
214 | } | |
215 | ||
216 | static const TypeInfo ev67_cpu_type_info = { | |
217 | .name = TYPE("ev67"), | |
218 | .parent = TYPE("ev6"), | |
219 | .instance_init = ev67_cpu_initfn, | |
220 | }; | |
221 | ||
222 | static const TypeInfo ev68_cpu_type_info = { | |
223 | .name = TYPE("ev68"), | |
224 | .parent = TYPE("ev67"), | |
225 | }; | |
226 | ||
9444006f AF |
227 | static void alpha_cpu_initfn(Object *obj) |
228 | { | |
229 | AlphaCPU *cpu = ALPHA_CPU(obj); | |
230 | CPUAlphaState *env = &cpu->env; | |
231 | ||
232 | cpu_exec_init(env); | |
233 | tlb_flush(env, 1); | |
234 | ||
0c28246f AF |
235 | alpha_translate_init(); |
236 | ||
9444006f AF |
237 | #if defined(CONFIG_USER_ONLY) |
238 | env->ps = PS_USER_MODE; | |
239 | cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD | |
240 | | FPCR_UNFD | FPCR_INED | FPCR_DNOD | |
241 | | FPCR_DYN_NORMAL)); | |
242 | #endif | |
243 | env->lock_addr = -1; | |
244 | env->fen = 1; | |
245 | } | |
246 | ||
25ebd80f AF |
247 | static const TypeInfo alpha_cpu_type_info = { |
248 | .name = TYPE_ALPHA_CPU, | |
249 | .parent = TYPE_CPU, | |
250 | .instance_size = sizeof(AlphaCPU), | |
9444006f | 251 | .instance_init = alpha_cpu_initfn, |
0c28246f | 252 | .abstract = true, |
25ebd80f AF |
253 | .class_size = sizeof(AlphaCPUClass), |
254 | }; | |
255 | ||
256 | static void alpha_cpu_register_types(void) | |
257 | { | |
258 | type_register_static(&alpha_cpu_type_info); | |
0c28246f AF |
259 | type_register_static(&ev4_cpu_type_info); |
260 | type_register_static(&ev5_cpu_type_info); | |
261 | type_register_static(&ev56_cpu_type_info); | |
262 | type_register_static(&pca56_cpu_type_info); | |
263 | type_register_static(&ev6_cpu_type_info); | |
264 | type_register_static(&ev67_cpu_type_info); | |
265 | type_register_static(&ev68_cpu_type_info); | |
25ebd80f AF |
266 | } |
267 | ||
268 | type_init(alpha_cpu_register_types) |