Andreas Färber | 25ebd80 | 2012-04-06 19:46:48 +0200 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Alpha CPU |
| 3 | * |
Andreas Färber | 9444006 | 2012-04-07 01:19:45 +0200 | [diff] [blame] | 4 | * Copyright (c) 2007 Jocelyn Mayer |
Andreas Färber | 25ebd80 | 2012-04-06 19:46:48 +0200 | [diff] [blame] | 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 | |
Andreas Färber | 3993c6b | 2012-05-03 06:43:49 +0200 | [diff] [blame] | 22 | #include "cpu.h" |
Andreas Färber | 25ebd80 | 2012-04-06 19:46:48 +0200 | [diff] [blame] | 23 | #include "qemu-common.h" |
Andreas Färber | fe31e73 | 2013-01-21 00:27:16 +0100 | [diff] [blame] | 24 | #include "migration/vmstate.h" |
Andreas Färber | 25ebd80 | 2012-04-06 19:46:48 +0200 | [diff] [blame] | 25 | |
| 26 | |
Andreas Färber | f45748f | 2013-06-21 19:09:18 +0200 | [diff] [blame] | 27 | static void alpha_cpu_set_pc(CPUState *cs, vaddr value) |
| 28 | { |
| 29 | AlphaCPU *cpu = ALPHA_CPU(cs); |
| 30 | |
| 31 | cpu->env.pc = value; |
| 32 | } |
| 33 | |
Andreas Färber | bd1b282 | 2013-01-05 14:01:30 +0100 | [diff] [blame] | 34 | static void alpha_cpu_realizefn(DeviceState *dev, Error **errp) |
Andreas Färber | 0c28246 | 2012-10-15 17:33:32 +0200 | [diff] [blame] | 35 | { |
Andreas Färber | 14a10fc | 2013-07-27 02:53:25 +0200 | [diff] [blame] | 36 | CPUState *cs = CPU(dev); |
Andreas Färber | bd1b282 | 2013-01-05 14:01:30 +0100 | [diff] [blame] | 37 | AlphaCPUClass *acc = ALPHA_CPU_GET_CLASS(dev); |
Andreas Färber | 0c28246 | 2012-10-15 17:33:32 +0200 | [diff] [blame] | 38 | |
Andreas Färber | 14a10fc | 2013-07-27 02:53:25 +0200 | [diff] [blame] | 39 | qemu_init_vcpu(cs); |
| 40 | |
Andreas Färber | bd1b282 | 2013-01-05 14:01:30 +0100 | [diff] [blame] | 41 | acc->parent_realize(dev, errp); |
Andreas Färber | 0c28246 | 2012-10-15 17:33:32 +0200 | [diff] [blame] | 42 | } |
| 43 | |
Andreas Färber | 494342b | 2012-10-15 17:44:21 +0200 | [diff] [blame] | 44 | /* Sort alphabetically by type name. */ |
| 45 | static gint alpha_cpu_list_compare(gconstpointer a, gconstpointer b) |
| 46 | { |
| 47 | ObjectClass *class_a = (ObjectClass *)a; |
| 48 | ObjectClass *class_b = (ObjectClass *)b; |
| 49 | const char *name_a, *name_b; |
| 50 | |
| 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); |
| 54 | } |
| 55 | |
| 56 | static void alpha_cpu_list_entry(gpointer data, gpointer user_data) |
| 57 | { |
| 58 | ObjectClass *oc = data; |
Andreas Färber | 92a3136 | 2012-12-16 02:17:02 +0100 | [diff] [blame] | 59 | CPUListState *s = user_data; |
Andreas Färber | 494342b | 2012-10-15 17:44:21 +0200 | [diff] [blame] | 60 | |
| 61 | (*s->cpu_fprintf)(s->file, " %s\n", |
| 62 | object_class_get_name(oc)); |
| 63 | } |
| 64 | |
| 65 | void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf) |
| 66 | { |
Andreas Färber | 92a3136 | 2012-12-16 02:17:02 +0100 | [diff] [blame] | 67 | CPUListState s = { |
Andreas Färber | 494342b | 2012-10-15 17:44:21 +0200 | [diff] [blame] | 68 | .file = f, |
| 69 | .cpu_fprintf = cpu_fprintf, |
| 70 | }; |
| 71 | GSList *list; |
| 72 | |
| 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); |
| 77 | g_slist_free(list); |
| 78 | } |
| 79 | |
Andreas Färber | 0c28246 | 2012-10-15 17:33:32 +0200 | [diff] [blame] | 80 | /* Models */ |
| 81 | |
| 82 | #define TYPE(model) model "-" TYPE_ALPHA_CPU |
| 83 | |
| 84 | typedef struct AlphaCPUAlias { |
| 85 | const char *alias; |
| 86 | const char *typename; |
| 87 | } AlphaCPUAlias; |
| 88 | |
| 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") }, |
| 96 | }; |
| 97 | |
| 98 | static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model) |
| 99 | { |
| 100 | ObjectClass *oc = NULL; |
| 101 | char *typename; |
| 102 | int i; |
| 103 | |
| 104 | if (cpu_model == NULL) { |
| 105 | return NULL; |
| 106 | } |
| 107 | |
| 108 | oc = object_class_by_name(cpu_model); |
Andreas Färber | a120c28 | 2013-01-23 12:28:22 +0100 | [diff] [blame] | 109 | if (oc != NULL && object_class_dynamic_cast(oc, TYPE_ALPHA_CPU) != NULL && |
| 110 | !object_class_is_abstract(oc)) { |
Andreas Färber | 0c28246 | 2012-10-15 17:33:32 +0200 | [diff] [blame] | 111 | return oc; |
| 112 | } |
| 113 | |
| 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); |
Andreas Färber | a120c28 | 2013-01-23 12:28:22 +0100 | [diff] [blame] | 117 | assert(oc != NULL && !object_class_is_abstract(oc)); |
Andreas Färber | 0c28246 | 2012-10-15 17:33:32 +0200 | [diff] [blame] | 118 | return oc; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | typename = g_strdup_printf("%s-" TYPE_ALPHA_CPU, cpu_model); |
| 123 | oc = object_class_by_name(typename); |
| 124 | g_free(typename); |
Andreas Färber | a120c28 | 2013-01-23 12:28:22 +0100 | [diff] [blame] | 125 | if (oc != NULL && object_class_is_abstract(oc)) { |
| 126 | oc = NULL; |
| 127 | } |
Andreas Färber | 0c28246 | 2012-10-15 17:33:32 +0200 | [diff] [blame] | 128 | return oc; |
| 129 | } |
| 130 | |
| 131 | AlphaCPU *cpu_alpha_init(const char *cpu_model) |
| 132 | { |
| 133 | AlphaCPU *cpu; |
| 134 | CPUAlphaState *env; |
| 135 | ObjectClass *cpu_class; |
| 136 | |
| 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")); |
| 141 | } |
| 142 | cpu = ALPHA_CPU(object_new(object_class_get_name(cpu_class))); |
| 143 | env = &cpu->env; |
| 144 | |
| 145 | env->cpu_model_str = cpu_model; |
| 146 | |
Andreas Färber | bd1b282 | 2013-01-05 14:01:30 +0100 | [diff] [blame] | 147 | object_property_set_bool(OBJECT(cpu), true, "realized", NULL); |
| 148 | |
Andreas Färber | 0c28246 | 2012-10-15 17:33:32 +0200 | [diff] [blame] | 149 | return cpu; |
| 150 | } |
| 151 | |
| 152 | static void ev4_cpu_initfn(Object *obj) |
| 153 | { |
| 154 | AlphaCPU *cpu = ALPHA_CPU(obj); |
| 155 | CPUAlphaState *env = &cpu->env; |
| 156 | |
| 157 | env->implver = IMPLVER_2106x; |
| 158 | } |
| 159 | |
| 160 | static const TypeInfo ev4_cpu_type_info = { |
| 161 | .name = TYPE("ev4"), |
| 162 | .parent = TYPE_ALPHA_CPU, |
| 163 | .instance_init = ev4_cpu_initfn, |
| 164 | }; |
| 165 | |
| 166 | static void ev5_cpu_initfn(Object *obj) |
| 167 | { |
| 168 | AlphaCPU *cpu = ALPHA_CPU(obj); |
| 169 | CPUAlphaState *env = &cpu->env; |
| 170 | |
| 171 | env->implver = IMPLVER_21164; |
| 172 | } |
| 173 | |
| 174 | static const TypeInfo ev5_cpu_type_info = { |
| 175 | .name = TYPE("ev5"), |
| 176 | .parent = TYPE_ALPHA_CPU, |
| 177 | .instance_init = ev5_cpu_initfn, |
| 178 | }; |
| 179 | |
| 180 | static void ev56_cpu_initfn(Object *obj) |
| 181 | { |
| 182 | AlphaCPU *cpu = ALPHA_CPU(obj); |
| 183 | CPUAlphaState *env = &cpu->env; |
| 184 | |
| 185 | env->amask |= AMASK_BWX; |
| 186 | } |
| 187 | |
| 188 | static const TypeInfo ev56_cpu_type_info = { |
| 189 | .name = TYPE("ev56"), |
| 190 | .parent = TYPE("ev5"), |
| 191 | .instance_init = ev56_cpu_initfn, |
| 192 | }; |
| 193 | |
| 194 | static void pca56_cpu_initfn(Object *obj) |
| 195 | { |
| 196 | AlphaCPU *cpu = ALPHA_CPU(obj); |
| 197 | CPUAlphaState *env = &cpu->env; |
| 198 | |
| 199 | env->amask |= AMASK_MVI; |
| 200 | } |
| 201 | |
| 202 | static const TypeInfo pca56_cpu_type_info = { |
| 203 | .name = TYPE("pca56"), |
| 204 | .parent = TYPE("ev56"), |
| 205 | .instance_init = pca56_cpu_initfn, |
| 206 | }; |
| 207 | |
| 208 | static void ev6_cpu_initfn(Object *obj) |
| 209 | { |
| 210 | AlphaCPU *cpu = ALPHA_CPU(obj); |
| 211 | CPUAlphaState *env = &cpu->env; |
| 212 | |
| 213 | env->implver = IMPLVER_21264; |
| 214 | env->amask = AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP; |
| 215 | } |
| 216 | |
| 217 | static const TypeInfo ev6_cpu_type_info = { |
| 218 | .name = TYPE("ev6"), |
| 219 | .parent = TYPE_ALPHA_CPU, |
| 220 | .instance_init = ev6_cpu_initfn, |
| 221 | }; |
| 222 | |
| 223 | static void ev67_cpu_initfn(Object *obj) |
| 224 | { |
| 225 | AlphaCPU *cpu = ALPHA_CPU(obj); |
| 226 | CPUAlphaState *env = &cpu->env; |
| 227 | |
| 228 | env->amask |= AMASK_CIX | AMASK_PREFETCH; |
| 229 | } |
| 230 | |
| 231 | static const TypeInfo ev67_cpu_type_info = { |
| 232 | .name = TYPE("ev67"), |
| 233 | .parent = TYPE("ev6"), |
| 234 | .instance_init = ev67_cpu_initfn, |
| 235 | }; |
| 236 | |
| 237 | static const TypeInfo ev68_cpu_type_info = { |
| 238 | .name = TYPE("ev68"), |
| 239 | .parent = TYPE("ev67"), |
| 240 | }; |
| 241 | |
Andreas Färber | 9444006 | 2012-04-07 01:19:45 +0200 | [diff] [blame] | 242 | static void alpha_cpu_initfn(Object *obj) |
| 243 | { |
Andreas Färber | c05efcb | 2013-01-17 12:13:41 +0100 | [diff] [blame] | 244 | CPUState *cs = CPU(obj); |
Andreas Färber | 9444006 | 2012-04-07 01:19:45 +0200 | [diff] [blame] | 245 | AlphaCPU *cpu = ALPHA_CPU(obj); |
| 246 | CPUAlphaState *env = &cpu->env; |
| 247 | |
Andreas Färber | c05efcb | 2013-01-17 12:13:41 +0100 | [diff] [blame] | 248 | cs->env_ptr = env; |
Andreas Färber | 9444006 | 2012-04-07 01:19:45 +0200 | [diff] [blame] | 249 | cpu_exec_init(env); |
| 250 | tlb_flush(env, 1); |
| 251 | |
Andreas Färber | 0c28246 | 2012-10-15 17:33:32 +0200 | [diff] [blame] | 252 | alpha_translate_init(); |
| 253 | |
Andreas Färber | 9444006 | 2012-04-07 01:19:45 +0200 | [diff] [blame] | 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 |
| 258 | | FPCR_DYN_NORMAL)); |
| 259 | #endif |
| 260 | env->lock_addr = -1; |
| 261 | env->fen = 1; |
| 262 | } |
| 263 | |
Andreas Färber | 2b8c275 | 2013-01-21 18:26:21 +0100 | [diff] [blame] | 264 | static void alpha_cpu_class_init(ObjectClass *oc, void *data) |
| 265 | { |
Andreas Färber | bd1b282 | 2013-01-05 14:01:30 +0100 | [diff] [blame] | 266 | DeviceClass *dc = DEVICE_CLASS(oc); |
Andreas Färber | 2b8c275 | 2013-01-21 18:26:21 +0100 | [diff] [blame] | 267 | CPUClass *cc = CPU_CLASS(oc); |
Andreas Färber | bd1b282 | 2013-01-05 14:01:30 +0100 | [diff] [blame] | 268 | AlphaCPUClass *acc = ALPHA_CPU_CLASS(oc); |
| 269 | |
| 270 | acc->parent_realize = dc->realize; |
| 271 | dc->realize = alpha_cpu_realizefn; |
Andreas Färber | 2b8c275 | 2013-01-21 18:26:21 +0100 | [diff] [blame] | 272 | |
| 273 | cc->class_by_name = alpha_cpu_class_by_name; |
Andreas Färber | 97a8ea5 | 2013-02-02 10:57:51 +0100 | [diff] [blame] | 274 | cc->do_interrupt = alpha_cpu_do_interrupt; |
Andreas Färber | 878096e | 2013-05-27 01:33:50 +0200 | [diff] [blame] | 275 | cc->dump_state = alpha_cpu_dump_state; |
Andreas Färber | f45748f | 2013-06-21 19:09:18 +0200 | [diff] [blame] | 276 | cc->set_pc = alpha_cpu_set_pc; |
Andreas Färber | 5b50e79 | 2013-06-29 04:18:45 +0200 | [diff] [blame] | 277 | cc->gdb_read_register = alpha_cpu_gdb_read_register; |
| 278 | cc->gdb_write_register = alpha_cpu_gdb_write_register; |
Andreas Färber | 00b941e | 2013-06-29 18:55:54 +0200 | [diff] [blame] | 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; |
| 283 | #endif |
Andreas Färber | a0e372f | 2013-06-28 23:18:47 +0200 | [diff] [blame] | 284 | cc->gdb_num_core_regs = 67; |
Andreas Färber | 2b8c275 | 2013-01-21 18:26:21 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Andreas Färber | 25ebd80 | 2012-04-06 19:46:48 +0200 | [diff] [blame] | 287 | static const TypeInfo alpha_cpu_type_info = { |
| 288 | .name = TYPE_ALPHA_CPU, |
| 289 | .parent = TYPE_CPU, |
| 290 | .instance_size = sizeof(AlphaCPU), |
Andreas Färber | 9444006 | 2012-04-07 01:19:45 +0200 | [diff] [blame] | 291 | .instance_init = alpha_cpu_initfn, |
Andreas Färber | 0c28246 | 2012-10-15 17:33:32 +0200 | [diff] [blame] | 292 | .abstract = true, |
Andreas Färber | 25ebd80 | 2012-04-06 19:46:48 +0200 | [diff] [blame] | 293 | .class_size = sizeof(AlphaCPUClass), |
Andreas Färber | 2b8c275 | 2013-01-21 18:26:21 +0100 | [diff] [blame] | 294 | .class_init = alpha_cpu_class_init, |
Andreas Färber | 25ebd80 | 2012-04-06 19:46:48 +0200 | [diff] [blame] | 295 | }; |
| 296 | |
| 297 | static void alpha_cpu_register_types(void) |
| 298 | { |
| 299 | type_register_static(&alpha_cpu_type_info); |
Andreas Färber | 0c28246 | 2012-10-15 17:33:32 +0200 | [diff] [blame] | 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); |
Andreas Färber | 25ebd80 | 2012-04-06 19:46:48 +0200 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | type_init(alpha_cpu_register_types) |