4 * Copyright (c) 2005 Samuel Tardieu
5 * Copyright (c) 2012 SUSE LINUX Products GmbH
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.
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.
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>
23 #include "qemu-common.h"
24 #include "migration/vmstate.h"
27 static void superh_cpu_set_pc(CPUState
*cs
, vaddr value
)
29 SuperHCPU
*cpu
= SUPERH_CPU(cs
);
34 static void superh_cpu_synchronize_from_tb(CPUState
*cs
, TranslationBlock
*tb
)
36 SuperHCPU
*cpu
= SUPERH_CPU(cs
);
39 cpu
->env
.flags
= tb
->flags
;
42 /* CPUClass::reset() */
43 static void superh_cpu_reset(CPUState
*s
)
45 SuperHCPU
*cpu
= SUPERH_CPU(s
);
46 SuperHCPUClass
*scc
= SUPERH_CPU_GET_CLASS(cpu
);
47 CPUSH4State
*env
= &cpu
->env
;
51 memset(env
, 0, offsetof(CPUSH4State
, breakpoints
));
55 #if defined(CONFIG_USER_ONLY)
56 env
->fpscr
= FPSCR_PR
; /* value for userspace according to the kernel */
57 set_float_rounding_mode(float_round_nearest_even
, &env
->fp_status
); /* ?! */
59 env
->sr
= SR_MD
| SR_RB
| SR_BL
| SR_I3
| SR_I2
| SR_I1
| SR_I0
;
60 env
->fpscr
= FPSCR_DN
| FPSCR_RM_ZERO
; /* CPU reset value according to SH4 manual */
61 set_float_rounding_mode(float_round_to_zero
, &env
->fp_status
);
62 set_flush_to_zero(1, &env
->fp_status
);
64 set_default_nan_mode(1, &env
->fp_status
);
67 typedef struct SuperHCPUListState
{
68 fprintf_function cpu_fprintf
;
72 /* Sort alphabetically by type name. */
73 static gint
superh_cpu_list_compare(gconstpointer a
, gconstpointer b
)
75 ObjectClass
*class_a
= (ObjectClass
*)a
;
76 ObjectClass
*class_b
= (ObjectClass
*)b
;
77 const char *name_a
, *name_b
;
79 name_a
= object_class_get_name(class_a
);
80 name_b
= object_class_get_name(class_b
);
81 return strcmp(name_a
, name_b
);
84 static void superh_cpu_list_entry(gpointer data
, gpointer user_data
)
86 ObjectClass
*oc
= data
;
87 SuperHCPUClass
*scc
= SUPERH_CPU_CLASS(oc
);
88 SuperHCPUListState
*s
= user_data
;
90 (*s
->cpu_fprintf
)(s
->file
, "%s\n",
94 void sh4_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
96 SuperHCPUListState s
= {
97 .cpu_fprintf
= cpu_fprintf
,
102 list
= object_class_get_list(TYPE_SUPERH_CPU
, false);
103 list
= g_slist_sort(list
, superh_cpu_list_compare
);
104 g_slist_foreach(list
, superh_cpu_list_entry
, &s
);
108 static gint
superh_cpu_name_compare(gconstpointer a
, gconstpointer b
)
110 const SuperHCPUClass
*scc
= SUPERH_CPU_CLASS(a
);
111 const char *name
= b
;
113 return strcasecmp(scc
->name
, name
);
116 static ObjectClass
*superh_cpu_class_by_name(const char *cpu_model
)
121 if (cpu_model
== NULL
) {
124 if (strcasecmp(cpu_model
, "any") == 0) {
125 return object_class_by_name(TYPE_SH7750R_CPU
);
128 oc
= object_class_by_name(cpu_model
);
129 if (oc
!= NULL
&& object_class_dynamic_cast(oc
, TYPE_SUPERH_CPU
) != NULL
130 && !object_class_is_abstract(oc
)) {
135 list
= object_class_get_list(TYPE_SUPERH_CPU
, false);
136 item
= g_slist_find_custom(list
, cpu_model
, superh_cpu_name_compare
);
144 SuperHCPU
*cpu_sh4_init(const char *cpu_model
)
150 oc
= superh_cpu_class_by_name(cpu_model
);
154 cpu
= SUPERH_CPU(object_new(object_class_get_name(oc
)));
156 env
->cpu_model_str
= cpu_model
;
158 object_property_set_bool(OBJECT(cpu
), true, "realized", NULL
);
163 static void sh7750r_cpu_initfn(Object
*obj
)
165 SuperHCPU
*cpu
= SUPERH_CPU(obj
);
166 CPUSH4State
*env
= &cpu
->env
;
168 env
->id
= SH_CPU_SH7750R
;
169 env
->features
= SH_FEATURE_BCR3_AND_BCR4
;
172 static void sh7750r_class_init(ObjectClass
*oc
, void *data
)
174 SuperHCPUClass
*scc
= SUPERH_CPU_CLASS(oc
);
176 scc
->name
= "SH7750R";
177 scc
->pvr
= 0x00050000;
178 scc
->prr
= 0x00000100;
179 scc
->cvr
= 0x00110000;
182 static const TypeInfo sh7750r_type_info
= {
183 .name
= TYPE_SH7750R_CPU
,
184 .parent
= TYPE_SUPERH_CPU
,
185 .class_init
= sh7750r_class_init
,
186 .instance_init
= sh7750r_cpu_initfn
,
189 static void sh7751r_cpu_initfn(Object
*obj
)
191 SuperHCPU
*cpu
= SUPERH_CPU(obj
);
192 CPUSH4State
*env
= &cpu
->env
;
194 env
->id
= SH_CPU_SH7751R
;
195 env
->features
= SH_FEATURE_BCR3_AND_BCR4
;
198 static void sh7751r_class_init(ObjectClass
*oc
, void *data
)
200 SuperHCPUClass
*scc
= SUPERH_CPU_CLASS(oc
);
202 scc
->name
= "SH7751R";
203 scc
->pvr
= 0x04050005;
204 scc
->prr
= 0x00000113;
205 scc
->cvr
= 0x00110000; /* Neutered caches, should be 0x20480000 */
208 static const TypeInfo sh7751r_type_info
= {
209 .name
= TYPE_SH7751R_CPU
,
210 .parent
= TYPE_SUPERH_CPU
,
211 .class_init
= sh7751r_class_init
,
212 .instance_init
= sh7751r_cpu_initfn
,
215 static void sh7785_cpu_initfn(Object
*obj
)
217 SuperHCPU
*cpu
= SUPERH_CPU(obj
);
218 CPUSH4State
*env
= &cpu
->env
;
220 env
->id
= SH_CPU_SH7785
;
221 env
->features
= SH_FEATURE_SH4A
;
224 static void sh7785_class_init(ObjectClass
*oc
, void *data
)
226 SuperHCPUClass
*scc
= SUPERH_CPU_CLASS(oc
);
228 scc
->name
= "SH7785";
229 scc
->pvr
= 0x10300700;
230 scc
->prr
= 0x00000200;
231 scc
->cvr
= 0x71440211;
234 static const TypeInfo sh7785_type_info
= {
235 .name
= TYPE_SH7785_CPU
,
236 .parent
= TYPE_SUPERH_CPU
,
237 .class_init
= sh7785_class_init
,
238 .instance_init
= sh7785_cpu_initfn
,
241 static void superh_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
243 SuperHCPU
*cpu
= SUPERH_CPU(dev
);
244 SuperHCPUClass
*scc
= SUPERH_CPU_GET_CLASS(dev
);
248 scc
->parent_realize(dev
, errp
);
251 static void superh_cpu_initfn(Object
*obj
)
253 CPUState
*cs
= CPU(obj
);
254 SuperHCPU
*cpu
= SUPERH_CPU(obj
);
255 CPUSH4State
*env
= &cpu
->env
;
260 env
->movcal_backup_tail
= &(env
->movcal_backup
);
263 sh4_translate_init();
267 static const VMStateDescription vmstate_sh_cpu
= {
272 static void superh_cpu_class_init(ObjectClass
*oc
, void *data
)
274 DeviceClass
*dc
= DEVICE_CLASS(oc
);
275 CPUClass
*cc
= CPU_CLASS(oc
);
276 SuperHCPUClass
*scc
= SUPERH_CPU_CLASS(oc
);
278 scc
->parent_realize
= dc
->realize
;
279 dc
->realize
= superh_cpu_realizefn
;
281 scc
->parent_reset
= cc
->reset
;
282 cc
->reset
= superh_cpu_reset
;
284 cc
->class_by_name
= superh_cpu_class_by_name
;
285 cc
->do_interrupt
= superh_cpu_do_interrupt
;
286 cc
->dump_state
= superh_cpu_dump_state
;
287 cc
->set_pc
= superh_cpu_set_pc
;
288 cc
->synchronize_from_tb
= superh_cpu_synchronize_from_tb
;
289 #ifndef CONFIG_USER_ONLY
290 cc
->get_phys_page_debug
= superh_cpu_get_phys_page_debug
;
292 dc
->vmsd
= &vmstate_sh_cpu
;
295 static const TypeInfo superh_cpu_type_info
= {
296 .name
= TYPE_SUPERH_CPU
,
298 .instance_size
= sizeof(SuperHCPU
),
299 .instance_init
= superh_cpu_initfn
,
301 .class_size
= sizeof(SuperHCPUClass
),
302 .class_init
= superh_cpu_class_init
,
305 static void superh_cpu_register_types(void)
307 type_register_static(&superh_cpu_type_info
);
308 type_register_static(&sh7750r_type_info
);
309 type_register_static(&sh7751r_type_info
);
310 type_register_static(&sh7785_type_info
);
313 type_init(superh_cpu_register_types
)