tricore: cleanup cpu type name composition
introduce TRICORE_CPU_TYPE_NAME macro and use it to construct cpu type names. While at it move cpu type_infos into one array and register it directly with type_init_from_array() instead of custom tricore_cpu_register_types()/cpu_register() Signed-off-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <1507211474-188400-30-git-send-email-imammedo@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
parent
1aaa63193b
commit
b9ad9d5b21
@ -116,7 +116,7 @@ static ObjectClass *tricore_cpu_class_by_name(const char *cpu_model)
|
||||
ObjectClass *oc;
|
||||
char *typename;
|
||||
|
||||
typename = g_strdup_printf("%s-" TYPE_TRICORE_CPU, cpu_model);
|
||||
typename = g_strdup_printf(TRICORE_CPU_TYPE_NAME("%s"), cpu_model);
|
||||
oc = object_class_by_name(typename);
|
||||
g_free(typename);
|
||||
if (!oc || !object_class_dynamic_cast(oc, TYPE_TRICORE_CPU) ||
|
||||
@ -147,19 +147,6 @@ static void tc27x_initfn(Object *obj)
|
||||
set_feature(&cpu->env, TRICORE_FEATURE_161);
|
||||
}
|
||||
|
||||
typedef struct TriCoreCPUInfo {
|
||||
const char *name;
|
||||
void (*initfn)(Object *obj);
|
||||
void (*class_init)(ObjectClass *oc, void *data);
|
||||
} TriCoreCPUInfo;
|
||||
|
||||
static const TriCoreCPUInfo tricore_cpus[] = {
|
||||
{ .name = "tc1796", .initfn = tc1796_initfn },
|
||||
{ .name = "tc1797", .initfn = tc1797_initfn },
|
||||
{ .name = "tc27x", .initfn = tc27x_initfn },
|
||||
{ .name = NULL }
|
||||
};
|
||||
|
||||
static void tricore_cpu_class_init(ObjectClass *c, void *data)
|
||||
{
|
||||
TriCoreCPUClass *mcc = TRICORE_CPU_CLASS(c);
|
||||
@ -181,41 +168,26 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data)
|
||||
cc->tcg_initialize = tricore_tcg_init;
|
||||
}
|
||||
|
||||
static void cpu_register(const TriCoreCPUInfo *info)
|
||||
{
|
||||
TypeInfo type_info = {
|
||||
.parent = TYPE_TRICORE_CPU,
|
||||
#define DEFINE_TRICORE_CPU_TYPE(cpu_model, initfn) \
|
||||
{ \
|
||||
.parent = TYPE_TRICORE_CPU, \
|
||||
.instance_init = initfn, \
|
||||
.name = TRICORE_CPU_TYPE_NAME(cpu_model), \
|
||||
}
|
||||
|
||||
static const TypeInfo tricore_cpu_type_infos[] = {
|
||||
{
|
||||
.name = TYPE_TRICORE_CPU,
|
||||
.parent = TYPE_CPU,
|
||||
.instance_size = sizeof(TriCoreCPU),
|
||||
.instance_init = info->initfn,
|
||||
.instance_init = tricore_cpu_initfn,
|
||||
.abstract = true,
|
||||
.class_size = sizeof(TriCoreCPUClass),
|
||||
.class_init = info->class_init,
|
||||
};
|
||||
|
||||
type_info.name = g_strdup_printf("%s-" TYPE_TRICORE_CPU, info->name);
|
||||
type_register(&type_info);
|
||||
g_free((void *)type_info.name);
|
||||
}
|
||||
|
||||
static const TypeInfo tricore_cpu_type_info = {
|
||||
.name = TYPE_TRICORE_CPU,
|
||||
.parent = TYPE_CPU,
|
||||
.instance_size = sizeof(TriCoreCPU),
|
||||
.instance_init = tricore_cpu_initfn,
|
||||
.abstract = true,
|
||||
.class_size = sizeof(TriCoreCPUClass),
|
||||
.class_init = tricore_cpu_class_init,
|
||||
.class_init = tricore_cpu_class_init,
|
||||
},
|
||||
DEFINE_TRICORE_CPU_TYPE("tc1796", tc1796_initfn),
|
||||
DEFINE_TRICORE_CPU_TYPE("tc1797", tc1797_initfn),
|
||||
DEFINE_TRICORE_CPU_TYPE("tc27x", tc27x_initfn),
|
||||
};
|
||||
|
||||
static void tricore_cpu_register_types(void)
|
||||
{
|
||||
const TriCoreCPUInfo *info = tricore_cpus;
|
||||
|
||||
type_register_static(&tricore_cpu_type_info);
|
||||
|
||||
while (info->name) {
|
||||
cpu_register(info);
|
||||
info++;
|
||||
}
|
||||
}
|
||||
|
||||
type_init(tricore_cpu_register_types)
|
||||
DEFINE_TYPES(tricore_cpu_type_infos)
|
||||
|
@ -413,6 +413,8 @@ static inline void cpu_get_tb_cpu_state(CPUTriCoreState *env, target_ulong *pc,
|
||||
|
||||
#define cpu_init(cpu_model) cpu_generic_init(TYPE_TRICORE_CPU, cpu_model)
|
||||
|
||||
#define TRICORE_CPU_TYPE_SUFFIX "-" TYPE_TRICORE_CPU
|
||||
#define TRICORE_CPU_TYPE_NAME(model) model TRICORE_CPU_TYPE_SUFFIX
|
||||
|
||||
/* helpers.c */
|
||||
int cpu_tricore_handle_mmu_fault(CPUState *cpu, target_ulong address,
|
||||
|
Loading…
Reference in New Issue
Block a user