]> Git Repo - qemu.git/blob - target-m68k/cpu.c
Merge remote-tracking branch 'afaerber/qom-cpu' into staging
[qemu.git] / target-m68k / cpu.c
1 /*
2  * QEMU Motorola 68k CPU
3  *
4  * Copyright (c) 2012 SUSE LINUX Products GmbH
5  *
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.
10  *
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.
15  *
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>
19  */
20
21 #include "cpu.h"
22 #include "qemu-common.h"
23 #include "migration/vmstate.h"
24
25
26 static void m68k_set_feature(CPUM68KState *env, int feature)
27 {
28     env->features |= (1u << feature);
29 }
30
31 /* CPUClass::reset() */
32 static void m68k_cpu_reset(CPUState *s)
33 {
34     M68kCPU *cpu = M68K_CPU(s);
35     M68kCPUClass *mcc = M68K_CPU_GET_CLASS(cpu);
36     CPUM68KState *env = &cpu->env;
37
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);
41     }
42
43     mcc->parent_reset(s);
44
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);
55 }
56
57 /* CPU models */
58
59 static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
60 {
61     ObjectClass *oc;
62     char *typename;
63
64     if (cpu_model == NULL) {
65         return NULL;
66     }
67
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;
74     }
75     return oc;
76 }
77
78 static void m5206_cpu_initfn(Object *obj)
79 {
80     M68kCPU *cpu = M68K_CPU(obj);
81     CPUM68KState *env = &cpu->env;
82
83     m68k_set_feature(env, M68K_FEATURE_CF_ISA_A);
84 }
85
86 static void m5208_cpu_initfn(Object *obj)
87 {
88     M68kCPU *cpu = M68K_CPU(obj);
89     CPUM68KState *env = &cpu->env;
90
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);
96 }
97
98 static void cfv4e_cpu_initfn(Object *obj)
99 {
100     M68kCPU *cpu = M68K_CPU(obj);
101     CPUM68KState *env = &cpu->env;
102
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);
109 }
110
111 static void any_cpu_initfn(Object *obj)
112 {
113     M68kCPU *cpu = M68K_CPU(obj);
114     CPUM68KState *env = &cpu->env;
115
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);
128 }
129
130 typedef struct M68kCPUInfo {
131     const char *name;
132     void (*instance_init)(Object *obj);
133 } M68kCPUInfo;
134
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 },
140 };
141
142 static void m68k_cpu_initfn(Object *obj)
143 {
144     M68kCPU *cpu = M68K_CPU(obj);
145     CPUM68KState *env = &cpu->env;
146
147     cpu_exec_init(env);
148 }
149
150 static const VMStateDescription vmstate_m68k_cpu = {
151     .name = "cpu",
152     .unmigratable = 1,
153 };
154
155 static void m68k_cpu_class_init(ObjectClass *c, void *data)
156 {
157     M68kCPUClass *mcc = M68K_CPU_CLASS(c);
158     CPUClass *cc = CPU_CLASS(c);
159     DeviceClass *dc = DEVICE_CLASS(c);
160
161     mcc->parent_reset = cc->reset;
162     cc->reset = m68k_cpu_reset;
163
164     cc->class_by_name = m68k_cpu_class_by_name;
165     dc->vmsd = &vmstate_m68k_cpu;
166 }
167
168 static void register_cpu_type(const M68kCPUInfo *info)
169 {
170     TypeInfo type_info = {
171         .parent = TYPE_M68K_CPU,
172         .instance_init = info->instance_init,
173     };
174
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);
178 }
179
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,
188 };
189
190 static void m68k_cpu_register_types(void)
191 {
192     int i;
193
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]);
197     }
198 }
199
200 type_init(m68k_cpu_register_types)
This page took 0.039414 seconds and 4 git commands to generate.