]> Git Repo - qemu.git/blob - target-cris/cpu.c
target-cris: Introduce CRISCPU subclasses
[qemu.git] / target-cris / cpu.c
1 /*
2  * QEMU CRIS CPU
3  *
4  * Copyright (c) 2008 AXIS Communications AB
5  * Written by Edgar E. Iglesias.
6  *
7  * Copyright (c) 2012 SUSE LINUX Products GmbH
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, see
21  * <http://www.gnu.org/licenses/lgpl-2.1.html>
22  */
23
24 #include "cpu.h"
25 #include "qemu-common.h"
26 #include "mmu.h"
27
28
29 /* CPUClass::reset() */
30 static void cris_cpu_reset(CPUState *s)
31 {
32     CRISCPU *cpu = CRIS_CPU(s);
33     CRISCPUClass *ccc = CRIS_CPU_GET_CLASS(cpu);
34     CPUCRISState *env = &cpu->env;
35     uint32_t vr;
36
37     if (qemu_loglevel_mask(CPU_LOG_RESET)) {
38         qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
39         log_cpu_state(env, 0);
40     }
41
42     ccc->parent_reset(s);
43
44     vr = env->pregs[PR_VR];
45     memset(env, 0, offsetof(CPUCRISState, breakpoints));
46     env->pregs[PR_VR] = vr;
47     tlb_flush(env, 1);
48
49 #if defined(CONFIG_USER_ONLY)
50     /* start in user mode with interrupts enabled.  */
51     env->pregs[PR_CCS] |= U_FLAG | I_FLAG | P_FLAG;
52 #else
53     cris_mmu_init(env);
54     env->pregs[PR_CCS] = 0;
55 #endif
56 }
57
58 static ObjectClass *cris_cpu_class_by_name(const char *cpu_model)
59 {
60     ObjectClass *oc;
61     char *typename;
62
63     if (cpu_model == NULL) {
64         return NULL;
65     }
66
67     typename = g_strdup_printf("%s-" TYPE_CRIS_CPU, cpu_model);
68     oc = object_class_by_name(typename);
69     g_free(typename);
70     if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_CRIS_CPU) ||
71                        object_class_is_abstract(oc))) {
72         oc = NULL;
73     }
74     return oc;
75 }
76
77 CRISCPU *cpu_cris_init(const char *cpu_model)
78 {
79     CRISCPU *cpu;
80     ObjectClass *oc;
81
82     oc = cris_cpu_class_by_name(cpu_model);
83     if (oc == NULL) {
84         return NULL;
85     }
86     cpu = CRIS_CPU(object_new(object_class_get_name(oc)));
87
88     object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
89
90     return cpu;
91 }
92
93 /* Sort alphabetically by VR. */
94 static gint cris_cpu_list_compare(gconstpointer a, gconstpointer b)
95 {
96     CRISCPUClass *ccc_a = CRIS_CPU_CLASS(a);
97     CRISCPUClass *ccc_b = CRIS_CPU_CLASS(b);
98
99     /*  */
100     if (ccc_a->vr > ccc_b->vr) {
101         return 1;
102     } else if (ccc_a->vr < ccc_b->vr) {
103         return -1;
104     } else {
105         return 0;
106     }
107 }
108
109 static void cris_cpu_list_entry(gpointer data, gpointer user_data)
110 {
111     ObjectClass *oc = data;
112     CPUListState *s = user_data;
113     const char *typename = object_class_get_name(oc);
114     char *name;
115
116     name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_CRIS_CPU));
117     (*s->cpu_fprintf)(s->file, "  %s\n", name);
118     g_free(name);
119 }
120
121 void cris_cpu_list(FILE *f, fprintf_function cpu_fprintf)
122 {
123     CPUListState s = {
124         .file = f,
125         .cpu_fprintf = cpu_fprintf,
126     };
127     GSList *list;
128
129     list = object_class_get_list(TYPE_CRIS_CPU, false);
130     list = g_slist_sort(list, cris_cpu_list_compare);
131     (*cpu_fprintf)(f, "Available CPUs:\n");
132     g_slist_foreach(list, cris_cpu_list_entry, &s);
133     g_slist_free(list);
134 }
135
136 static void cris_cpu_realizefn(DeviceState *dev, Error **errp)
137 {
138     CRISCPU *cpu = CRIS_CPU(dev);
139     CRISCPUClass *ccc = CRIS_CPU_GET_CLASS(dev);
140
141     cpu_reset(CPU(cpu));
142     qemu_init_vcpu(&cpu->env);
143
144     ccc->parent_realize(dev, errp);
145 }
146
147 static void cris_cpu_initfn(Object *obj)
148 {
149     CRISCPU *cpu = CRIS_CPU(obj);
150     CRISCPUClass *ccc = CRIS_CPU_GET_CLASS(obj);
151     CPUCRISState *env = &cpu->env;
152     static bool tcg_initialized;
153
154     cpu_exec_init(env);
155
156     env->pregs[PR_VR] = ccc->vr;
157
158     if (tcg_enabled() && !tcg_initialized) {
159         tcg_initialized = true;
160         if (env->pregs[PR_VR] < 32) {
161             cris_initialize_crisv10_tcg();
162         } else {
163             cris_initialize_tcg();
164         }
165     }
166 }
167
168 static void crisv8_cpu_class_init(ObjectClass *oc, void *data)
169 {
170     CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);
171
172     ccc->vr = 8;
173 }
174
175 static void crisv9_cpu_class_init(ObjectClass *oc, void *data)
176 {
177     CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);
178
179     ccc->vr = 9;
180 }
181
182 static void crisv10_cpu_class_init(ObjectClass *oc, void *data)
183 {
184     CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);
185
186     ccc->vr = 10;
187 }
188
189 static void crisv11_cpu_class_init(ObjectClass *oc, void *data)
190 {
191     CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);
192
193     ccc->vr = 11;
194 }
195
196 static void crisv32_cpu_class_init(ObjectClass *oc, void *data)
197 {
198     CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);
199
200     ccc->vr = 32;
201 }
202
203 #define TYPE(model) model "-" TYPE_CRIS_CPU
204
205 static const TypeInfo cris_cpu_model_type_infos[] = {
206     {
207         .name = TYPE("crisv8"),
208         .parent = TYPE_CRIS_CPU,
209         .class_init = crisv8_cpu_class_init,
210     }, {
211         .name = TYPE("crisv9"),
212         .parent = TYPE_CRIS_CPU,
213         .class_init = crisv9_cpu_class_init,
214     }, {
215         .name = TYPE("crisv10"),
216         .parent = TYPE_CRIS_CPU,
217         .class_init = crisv10_cpu_class_init,
218     }, {
219         .name = TYPE("crisv11"),
220         .parent = TYPE_CRIS_CPU,
221         .class_init = crisv11_cpu_class_init,
222     }, {
223         .name = TYPE("crisv32"),
224         .parent = TYPE_CRIS_CPU,
225         .class_init = crisv32_cpu_class_init,
226     }
227 };
228
229 #undef TYPE
230
231 static void cris_cpu_class_init(ObjectClass *oc, void *data)
232 {
233     DeviceClass *dc = DEVICE_CLASS(oc);
234     CPUClass *cc = CPU_CLASS(oc);
235     CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);
236
237     ccc->parent_realize = dc->realize;
238     dc->realize = cris_cpu_realizefn;
239
240     ccc->parent_reset = cc->reset;
241     cc->reset = cris_cpu_reset;
242
243     cc->class_by_name = cris_cpu_class_by_name;
244 }
245
246 static const TypeInfo cris_cpu_type_info = {
247     .name = TYPE_CRIS_CPU,
248     .parent = TYPE_CPU,
249     .instance_size = sizeof(CRISCPU),
250     .instance_init = cris_cpu_initfn,
251     .abstract = true,
252     .class_size = sizeof(CRISCPUClass),
253     .class_init = cris_cpu_class_init,
254 };
255
256 static void cris_cpu_register_types(void)
257 {
258     int i;
259
260     type_register_static(&cris_cpu_type_info);
261     for (i = 0; i < ARRAY_SIZE(cris_cpu_model_type_infos); i++) {
262         type_register_static(&cris_cpu_model_type_infos[i]);
263     }
264 }
265
266 type_init(cris_cpu_register_types)
This page took 0.040765 seconds and 4 git commands to generate.