4 * Copyright (c) 2008 AXIS Communications AB
5 * Written by Edgar E. Iglesias.
7 * Copyright (c) 2012 SUSE LINUX Products GmbH
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.
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.
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>
25 #include "qemu-common.h"
29 /* CPUClass::reset() */
30 static void cris_cpu_reset(CPUState
*s
)
32 CRISCPU
*cpu
= CRIS_CPU(s
);
33 CRISCPUClass
*ccc
= CRIS_CPU_GET_CLASS(cpu
);
34 CPUCRISState
*env
= &cpu
->env
;
39 vr
= env
->pregs
[PR_VR
];
40 memset(env
, 0, offsetof(CPUCRISState
, breakpoints
));
41 env
->pregs
[PR_VR
] = vr
;
44 #if defined(CONFIG_USER_ONLY)
45 /* start in user mode with interrupts enabled. */
46 env
->pregs
[PR_CCS
] |= U_FLAG
| I_FLAG
| P_FLAG
;
49 env
->pregs
[PR_CCS
] = 0;
53 static ObjectClass
*cris_cpu_class_by_name(const char *cpu_model
)
58 if (cpu_model
== NULL
) {
62 typename
= g_strdup_printf("%s-" TYPE_CRIS_CPU
, cpu_model
);
63 oc
= object_class_by_name(typename
);
65 if (oc
!= NULL
&& (!object_class_dynamic_cast(oc
, TYPE_CRIS_CPU
) ||
66 object_class_is_abstract(oc
))) {
72 CRISCPU
*cpu_cris_init(const char *cpu_model
)
77 oc
= cris_cpu_class_by_name(cpu_model
);
81 cpu
= CRIS_CPU(object_new(object_class_get_name(oc
)));
83 object_property_set_bool(OBJECT(cpu
), true, "realized", NULL
);
88 /* Sort alphabetically by VR. */
89 static gint
cris_cpu_list_compare(gconstpointer a
, gconstpointer b
)
91 CRISCPUClass
*ccc_a
= CRIS_CPU_CLASS(a
);
92 CRISCPUClass
*ccc_b
= CRIS_CPU_CLASS(b
);
95 if (ccc_a
->vr
> ccc_b
->vr
) {
97 } else if (ccc_a
->vr
< ccc_b
->vr
) {
104 static void cris_cpu_list_entry(gpointer data
, gpointer user_data
)
106 ObjectClass
*oc
= data
;
107 CPUListState
*s
= user_data
;
108 const char *typename
= object_class_get_name(oc
);
111 name
= g_strndup(typename
, strlen(typename
) - strlen("-" TYPE_CRIS_CPU
));
112 (*s
->cpu_fprintf
)(s
->file
, " %s\n", name
);
116 void cris_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
120 .cpu_fprintf
= cpu_fprintf
,
124 list
= object_class_get_list(TYPE_CRIS_CPU
, false);
125 list
= g_slist_sort(list
, cris_cpu_list_compare
);
126 (*cpu_fprintf
)(f
, "Available CPUs:\n");
127 g_slist_foreach(list
, cris_cpu_list_entry
, &s
);
131 static void cris_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
133 CRISCPU
*cpu
= CRIS_CPU(dev
);
134 CRISCPUClass
*ccc
= CRIS_CPU_GET_CLASS(dev
);
138 ccc
->parent_realize(dev
, errp
);
141 static void cris_cpu_initfn(Object
*obj
)
143 CPUState
*cs
= CPU(obj
);
144 CRISCPU
*cpu
= CRIS_CPU(obj
);
145 CRISCPUClass
*ccc
= CRIS_CPU_GET_CLASS(obj
);
146 CPUCRISState
*env
= &cpu
->env
;
147 static bool tcg_initialized
;
152 env
->pregs
[PR_VR
] = ccc
->vr
;
154 if (tcg_enabled() && !tcg_initialized
) {
155 tcg_initialized
= true;
156 if (env
->pregs
[PR_VR
] < 32) {
157 cris_initialize_crisv10_tcg();
159 cris_initialize_tcg();
164 static void crisv8_cpu_class_init(ObjectClass
*oc
, void *data
)
166 CPUClass
*cc
= CPU_CLASS(oc
);
167 CRISCPUClass
*ccc
= CRIS_CPU_CLASS(oc
);
170 cc
->do_interrupt
= crisv10_cpu_do_interrupt
;
173 static void crisv9_cpu_class_init(ObjectClass
*oc
, void *data
)
175 CPUClass
*cc
= CPU_CLASS(oc
);
176 CRISCPUClass
*ccc
= CRIS_CPU_CLASS(oc
);
179 cc
->do_interrupt
= crisv10_cpu_do_interrupt
;
182 static void crisv10_cpu_class_init(ObjectClass
*oc
, void *data
)
184 CPUClass
*cc
= CPU_CLASS(oc
);
185 CRISCPUClass
*ccc
= CRIS_CPU_CLASS(oc
);
188 cc
->do_interrupt
= crisv10_cpu_do_interrupt
;
191 static void crisv11_cpu_class_init(ObjectClass
*oc
, void *data
)
193 CPUClass
*cc
= CPU_CLASS(oc
);
194 CRISCPUClass
*ccc
= CRIS_CPU_CLASS(oc
);
197 cc
->do_interrupt
= crisv10_cpu_do_interrupt
;
200 static void crisv32_cpu_class_init(ObjectClass
*oc
, void *data
)
202 CRISCPUClass
*ccc
= CRIS_CPU_CLASS(oc
);
207 #define TYPE(model) model "-" TYPE_CRIS_CPU
209 static const TypeInfo cris_cpu_model_type_infos
[] = {
211 .name
= TYPE("crisv8"),
212 .parent
= TYPE_CRIS_CPU
,
213 .class_init
= crisv8_cpu_class_init
,
215 .name
= TYPE("crisv9"),
216 .parent
= TYPE_CRIS_CPU
,
217 .class_init
= crisv9_cpu_class_init
,
219 .name
= TYPE("crisv10"),
220 .parent
= TYPE_CRIS_CPU
,
221 .class_init
= crisv10_cpu_class_init
,
223 .name
= TYPE("crisv11"),
224 .parent
= TYPE_CRIS_CPU
,
225 .class_init
= crisv11_cpu_class_init
,
227 .name
= TYPE("crisv32"),
228 .parent
= TYPE_CRIS_CPU
,
229 .class_init
= crisv32_cpu_class_init
,
235 static void cris_cpu_class_init(ObjectClass
*oc
, void *data
)
237 DeviceClass
*dc
= DEVICE_CLASS(oc
);
238 CPUClass
*cc
= CPU_CLASS(oc
);
239 CRISCPUClass
*ccc
= CRIS_CPU_CLASS(oc
);
241 ccc
->parent_realize
= dc
->realize
;
242 dc
->realize
= cris_cpu_realizefn
;
244 ccc
->parent_reset
= cc
->reset
;
245 cc
->reset
= cris_cpu_reset
;
247 cc
->class_by_name
= cris_cpu_class_by_name
;
248 cc
->do_interrupt
= cris_cpu_do_interrupt
;
249 cc
->dump_state
= cris_cpu_dump_state
;
252 static const TypeInfo cris_cpu_type_info
= {
253 .name
= TYPE_CRIS_CPU
,
255 .instance_size
= sizeof(CRISCPU
),
256 .instance_init
= cris_cpu_initfn
,
258 .class_size
= sizeof(CRISCPUClass
),
259 .class_init
= cris_cpu_class_init
,
262 static void cris_cpu_register_types(void)
266 type_register_static(&cris_cpu_type_info
);
267 for (i
= 0; i
< ARRAY_SIZE(cris_cpu_model_type_infos
); i
++) {
268 type_register_static(&cris_cpu_model_type_infos
[i
]);
272 type_init(cris_cpu_register_types
)