diff options
Diffstat (limited to 'target/unicore32/cpu.c')
-rw-r--r-- | target/unicore32/cpu.c | 61 |
1 files changed, 20 insertions, 41 deletions
diff --git a/target/unicore32/cpu.c b/target/unicore32/cpu.c index 526604ff78..17dc1504d7 100644 --- a/target/unicore32/cpu.c +++ b/target/unicore32/cpu.c @@ -44,7 +44,7 @@ static ObjectClass *uc32_cpu_class_by_name(const char *cpu_model) ObjectClass *oc; char *typename; - typename = g_strdup_printf("%s-" TYPE_UNICORE32_CPU, cpu_model); + typename = g_strdup_printf(UNICORE32_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_UNICORE32_CPU) || @@ -54,11 +54,6 @@ static ObjectClass *uc32_cpu_class_by_name(const char *cpu_model) return oc; } -typedef struct UniCore32CPUInfo { - const char *name; - void (*instance_init)(Object *obj); -} UniCore32CPUInfo; - static void unicore_ii_cpu_initfn(Object *obj) { UniCore32CPU *cpu = UNICORE32_CPU(obj); @@ -90,11 +85,6 @@ static void uc32_any_cpu_initfn(Object *obj) set_snan_bit_is_one(1, &env->ucf64.fp_status); } -static const UniCore32CPUInfo uc32_cpus[] = { - { .name = "UniCore-II", .instance_init = unicore_ii_cpu_initfn }, - { .name = "any", .instance_init = uc32_any_cpu_initfn }, -}; - static void uc32_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); @@ -160,36 +150,25 @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data) dc->vmsd = &vmstate_uc32_cpu; } -static void uc32_register_cpu_type(const UniCore32CPUInfo *info) -{ - TypeInfo type_info = { - .parent = TYPE_UNICORE32_CPU, - .instance_init = info->instance_init, - }; - - type_info.name = g_strdup_printf("%s-" TYPE_UNICORE32_CPU, info->name); - type_register(&type_info); - g_free((void *)type_info.name); -} +#define DEFINE_UNICORE32_CPU_TYPE(cpu_model, initfn) \ + { \ + .parent = TYPE_UNICORE32_CPU, \ + .instance_init = initfn, \ + .name = UNICORE32_CPU_TYPE_NAME(cpu_model), \ + } -static const TypeInfo uc32_cpu_type_info = { - .name = TYPE_UNICORE32_CPU, - .parent = TYPE_CPU, - .instance_size = sizeof(UniCore32CPU), - .instance_init = uc32_cpu_initfn, - .abstract = true, - .class_size = sizeof(UniCore32CPUClass), - .class_init = uc32_cpu_class_init, +static const TypeInfo uc32_cpu_type_infos[] = { + { + .name = TYPE_UNICORE32_CPU, + .parent = TYPE_CPU, + .instance_size = sizeof(UniCore32CPU), + .instance_init = uc32_cpu_initfn, + .abstract = true, + .class_size = sizeof(UniCore32CPUClass), + .class_init = uc32_cpu_class_init, + }, + DEFINE_UNICORE32_CPU_TYPE("UniCore-II", unicore_ii_cpu_initfn), + DEFINE_UNICORE32_CPU_TYPE("any", uc32_any_cpu_initfn), }; -static void uc32_cpu_register_types(void) -{ - int i; - - type_register_static(&uc32_cpu_type_info); - for (i = 0; i < ARRAY_SIZE(uc32_cpus); i++) { - uc32_register_cpu_type(&uc32_cpus[i]); - } -} - -type_init(uc32_cpu_register_types) +DEFINE_TYPES(uc32_cpu_type_infos) |