memory: Use non-bitops ctzl
[qemu/agraf.git] / target-m68k / cpu.c
blobc71f7151743b2ee96ea05c14c047140ac5546356
1 /*
2 * QEMU Motorola 68k CPU
4 * Copyright (c) 2012 SUSE LINUX Products GmbH
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see
18 * <http://www.gnu.org/licenses/lgpl-2.1.html>
21 #include "cpu.h"
22 #include "qemu-common.h"
23 #include "migration/vmstate.h"
26 static void m68k_set_feature(CPUM68KState *env, int feature)
28 env->features |= (1u << feature);
31 /* CPUClass::reset() */
32 static void m68k_cpu_reset(CPUState *s)
34 M68kCPU *cpu = M68K_CPU(s);
35 M68kCPUClass *mcc = M68K_CPU_GET_CLASS(cpu);
36 CPUM68KState *env = &cpu->env;
38 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
39 qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
40 log_cpu_state(env, 0);
43 mcc->parent_reset(s);
45 memset(env, 0, offsetof(CPUM68KState, breakpoints));
46 #if !defined(CONFIG_USER_ONLY)
47 env->sr = 0x2700;
48 #endif
49 m68k_switch_sp(env);
50 /* ??? FP regs should be initialized to NaN. */
51 env->cc_op = CC_OP_FLAGS;
52 /* TODO: We should set PC from the interrupt vector. */
53 env->pc = 0;
54 tlb_flush(env, 1);
57 /* CPU models */
59 static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
61 ObjectClass *oc;
62 char *typename;
64 if (cpu_model == NULL) {
65 return NULL;
68 typename = g_strdup_printf("%s-" TYPE_M68K_CPU, cpu_model);
69 oc = object_class_by_name(typename);
70 g_free(typename);
71 if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL ||
72 object_class_is_abstract(oc))) {
73 return NULL;
75 return oc;
78 static void m5206_cpu_initfn(Object *obj)
80 M68kCPU *cpu = M68K_CPU(obj);
81 CPUM68KState *env = &cpu->env;
83 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
86 static void m5208_cpu_initfn(Object *obj)
88 M68kCPU *cpu = M68K_CPU(obj);
89 CPUM68KState *env = &cpu->env;
91 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
92 m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC);
93 m68k_set_feature(env, M68K_FEATURE_BRAL);
94 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
95 m68k_set_feature(env, M68K_FEATURE_USP);
98 static void cfv4e_cpu_initfn(Object *obj)
100 M68kCPU *cpu = M68K_CPU(obj);
101 CPUM68KState *env = &cpu->env;
103 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
104 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
105 m68k_set_feature(env, M68K_FEATURE_BRAL);
106 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
107 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
108 m68k_set_feature(env, M68K_FEATURE_USP);
111 static void any_cpu_initfn(Object *obj)
113 M68kCPU *cpu = M68K_CPU(obj);
114 CPUM68KState *env = &cpu->env;
116 m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
117 m68k_set_feature(env, M68K_FEATURE_CF_ISA_B);
118 m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC);
119 m68k_set_feature(env, M68K_FEATURE_BRAL);
120 m68k_set_feature(env, M68K_FEATURE_CF_FPU);
121 /* MAC and EMAC are mututally exclusive, so pick EMAC.
122 It's mostly backwards compatible. */
123 m68k_set_feature(env, M68K_FEATURE_CF_EMAC);
124 m68k_set_feature(env, M68K_FEATURE_CF_EMAC_B);
125 m68k_set_feature(env, M68K_FEATURE_USP);
126 m68k_set_feature(env, M68K_FEATURE_EXT_FULL);
127 m68k_set_feature(env, M68K_FEATURE_WORD_INDEX);
130 typedef struct M68kCPUInfo {
131 const char *name;
132 void (*instance_init)(Object *obj);
133 } M68kCPUInfo;
135 static const M68kCPUInfo m68k_cpus[] = {
136 { .name = "m5206", .instance_init = m5206_cpu_initfn },
137 { .name = "m5208", .instance_init = m5208_cpu_initfn },
138 { .name = "cfv4e", .instance_init = cfv4e_cpu_initfn },
139 { .name = "any", .instance_init = any_cpu_initfn },
142 static void m68k_cpu_initfn(Object *obj)
144 M68kCPU *cpu = M68K_CPU(obj);
145 CPUM68KState *env = &cpu->env;
147 cpu_exec_init(env);
150 static const VMStateDescription vmstate_m68k_cpu = {
151 .name = "cpu",
152 .unmigratable = 1,
155 static void m68k_cpu_class_init(ObjectClass *c, void *data)
157 M68kCPUClass *mcc = M68K_CPU_CLASS(c);
158 CPUClass *cc = CPU_CLASS(c);
159 DeviceClass *dc = DEVICE_CLASS(c);
161 mcc->parent_reset = cc->reset;
162 cc->reset = m68k_cpu_reset;
164 cc->class_by_name = m68k_cpu_class_by_name;
165 dc->vmsd = &vmstate_m68k_cpu;
168 static void register_cpu_type(const M68kCPUInfo *info)
170 TypeInfo type_info = {
171 .parent = TYPE_M68K_CPU,
172 .instance_init = info->instance_init,
175 type_info.name = g_strdup_printf("%s-" TYPE_M68K_CPU, info->name);
176 type_register(&type_info);
177 g_free((void *)type_info.name);
180 static const TypeInfo m68k_cpu_type_info = {
181 .name = TYPE_M68K_CPU,
182 .parent = TYPE_CPU,
183 .instance_size = sizeof(M68kCPU),
184 .instance_init = m68k_cpu_initfn,
185 .abstract = true,
186 .class_size = sizeof(M68kCPUClass),
187 .class_init = m68k_cpu_class_init,
190 static void m68k_cpu_register_types(void)
192 int i;
194 type_register_static(&m68k_cpu_type_info);
195 for (i = 0; i < ARRAY_SIZE(m68k_cpus); i++) {
196 register_cpu_type(&m68k_cpus[i]);
200 type_init(m68k_cpu_register_types)