aboutsummaryrefslogtreecommitdiff
path: root/target/openrisc/cpu.c
diff options
context:
space:
mode:
authorIgor Mammedov <imammedo@redhat.com>2017-10-05 15:50:51 +0200
committerEduardo Habkost <ehabkost@redhat.com>2017-10-27 16:03:54 +0200
commita677273142a6db7dea6c70ea7076a28c10b93cb7 (patch)
tree8e9ce019a4960147080d96c4393e826a9af5b4ae /target/openrisc/cpu.c
parentb2c223571e1a4c0bc4cf559fbc433c0a2b83ae35 (diff)
openrisc: cleanup cpu type name composition
use new OPENRISC_CPU_TYPE_NAME to compose CPU type name and get rid of intermediate OpenRISCCPUInfo/openrisc_cpu_register_types() which is replaced by static TypeInfo array. Signed-off-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <1507211474-188400-18-git-send-email-imammedo@redhat.com> Acked-by: Stafford Horne <shorne@gmail.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Diffstat (limited to 'target/openrisc/cpu.c')
-rw-r--r--target/openrisc/cpu.c69
1 files changed, 23 insertions, 46 deletions
diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c
index a8db869e50..e0394b8b06 100644
--- a/target/openrisc/cpu.c
+++ b/target/openrisc/cpu.c
@@ -101,7 +101,7 @@ static ObjectClass *openrisc_cpu_class_by_name(const char *cpu_model)
ObjectClass *oc;
char *typename;
- typename = g_strdup_printf("%s-" TYPE_OPENRISC_CPU, cpu_model);
+ typename = g_strdup_printf(OPENRISC_CPU_TYPE_NAME("%s"), cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_OPENRISC_CPU) ||
@@ -126,16 +126,6 @@ static void openrisc_any_initfn(Object *obj)
cpu->env.cpucfgr = CPUCFGR_NSGF | CPUCFGR_OB32S | CPUCFGR_EVBARP;
}
-typedef struct OpenRISCCPUInfo {
- const char *name;
- void (*initfn)(Object *obj);
-} OpenRISCCPUInfo;
-
-static const OpenRISCCPUInfo openrisc_cpus[] = {
- { .name = "or1200", .initfn = or1200_initfn },
- { .name = "any", .initfn = openrisc_any_initfn },
-};
-
static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
{
OpenRISCCPUClass *occ = OPENRISC_CPU_CLASS(oc);
@@ -166,40 +156,6 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
cc->tcg_initialize = openrisc_translate_init;
}
-static void cpu_register(const OpenRISCCPUInfo *info)
-{
- TypeInfo type_info = {
- .parent = TYPE_OPENRISC_CPU,
- .instance_size = sizeof(OpenRISCCPU),
- .instance_init = info->initfn,
- .class_size = sizeof(OpenRISCCPUClass),
- };
-
- type_info.name = g_strdup_printf("%s-" TYPE_OPENRISC_CPU, info->name);
- type_register(&type_info);
- g_free((void *)type_info.name);
-}
-
-static const TypeInfo openrisc_cpu_type_info = {
- .name = TYPE_OPENRISC_CPU,
- .parent = TYPE_CPU,
- .instance_size = sizeof(OpenRISCCPU),
- .instance_init = openrisc_cpu_initfn,
- .abstract = true,
- .class_size = sizeof(OpenRISCCPUClass),
- .class_init = openrisc_cpu_class_init,
-};
-
-static void openrisc_cpu_register_types(void)
-{
- int i;
-
- type_register_static(&openrisc_cpu_type_info);
- for (i = 0; i < ARRAY_SIZE(openrisc_cpus); i++) {
- cpu_register(&openrisc_cpus[i]);
- }
-}
-
/* Sort alphabetically by type name, except for "any". */
static gint openrisc_cpu_list_compare(gconstpointer a, gconstpointer b)
{
@@ -248,4 +204,25 @@ void cpu_openrisc_list(FILE *f, fprintf_function cpu_fprintf)
g_slist_free(list);
}
-type_init(openrisc_cpu_register_types)
+#define DEFINE_OPENRISC_CPU_TYPE(cpu_model, initfn) \
+ { \
+ .parent = TYPE_OPENRISC_CPU, \
+ .instance_init = initfn, \
+ .name = OPENRISC_CPU_TYPE_NAME(cpu_model), \
+ }
+
+static const TypeInfo openrisc_cpus_type_infos[] = {
+ { /* base class should be registered first */
+ .name = TYPE_OPENRISC_CPU,
+ .parent = TYPE_CPU,
+ .instance_size = sizeof(OpenRISCCPU),
+ .instance_init = openrisc_cpu_initfn,
+ .abstract = true,
+ .class_size = sizeof(OpenRISCCPUClass),
+ .class_init = openrisc_cpu_class_init,
+ },
+ DEFINE_OPENRISC_CPU_TYPE("or1200", or1200_initfn),
+ DEFINE_OPENRISC_CPU_TYPE("any", openrisc_any_initfn),
+};
+
+DEFINE_TYPES(openrisc_cpus_type_infos)