aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--target/moxie/cpu.c56
-rw-r--r--target/moxie/cpu.h3
2 files changed, 20 insertions, 39 deletions
diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c
index 44441b2..f1389e5 100644
--- a/target/moxie/cpu.c
+++ b/target/moxie/cpu.c
@@ -86,7 +86,7 @@ static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
ObjectClass *oc;
char *typename;
- typename = g_strdup_printf("%s-" TYPE_MOXIE_CPU, cpu_model);
+ typename = g_strdup_printf(MOXIE_CPU_TYPE_NAME("%s"), cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
@@ -134,46 +134,24 @@ static void moxie_any_initfn(Object *obj)
/* Set cpu feature flags */
}
-typedef struct MoxieCPUInfo {
- const char *name;
- void (*initfn)(Object *obj);
-} MoxieCPUInfo;
-
-static const MoxieCPUInfo moxie_cpus[] = {
- { .name = "MoxieLite", .initfn = moxielite_initfn },
- { .name = "any", .initfn = moxie_any_initfn },
-};
+#define DEFINE_MOXIE_CPU_TYPE(cpu_model, initfn) \
+ { \
+ .parent = TYPE_MOXIE_CPU, \
+ .instance_init = initfn, \
+ .name = MOXIE_CPU_TYPE_NAME(cpu_model), \
+ }
-static void cpu_register(const MoxieCPUInfo *info)
-{
- TypeInfo type_info = {
- .parent = TYPE_MOXIE_CPU,
+static const TypeInfo moxie_cpus_type_infos[] = {
+ { /* base class should be registered first */
+ .name = TYPE_MOXIE_CPU,
+ .parent = TYPE_CPU,
.instance_size = sizeof(MoxieCPU),
- .instance_init = info->initfn,
+ .instance_init = moxie_cpu_initfn,
.class_size = sizeof(MoxieCPUClass),
- };
-
- type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name);
- type_register(&type_info);
- g_free((void *)type_info.name);
-}
-
-static const TypeInfo moxie_cpu_type_info = {
- .name = TYPE_MOXIE_CPU,
- .parent = TYPE_CPU,
- .instance_size = sizeof(MoxieCPU),
- .instance_init = moxie_cpu_initfn,
- .class_size = sizeof(MoxieCPUClass),
- .class_init = moxie_cpu_class_init,
+ .class_init = moxie_cpu_class_init,
+ },
+ DEFINE_MOXIE_CPU_TYPE("MoxieLite", moxielite_initfn),
+ DEFINE_MOXIE_CPU_TYPE("any", moxie_any_initfn),
};
-static void moxie_cpu_register_types(void)
-{
- int i;
- type_register_static(&moxie_cpu_type_info);
- for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) {
- cpu_register(&moxie_cpus[i]);
- }
-}
-
-type_init(moxie_cpu_register_types)
+DEFINE_TYPES(moxie_cpus_type_infos)
diff --git a/target/moxie/cpu.h b/target/moxie/cpu.h
index 75decaa..d37e6a5 100644
--- a/target/moxie/cpu.h
+++ b/target/moxie/cpu.h
@@ -122,6 +122,9 @@ int cpu_moxie_signal_handler(int host_signum, void *pinfo,
#define cpu_init(cpu_model) cpu_generic_init(TYPE_MOXIE_CPU, cpu_model)
+#define MOXIE_CPU_TYPE_SUFFIX "-" TYPE_MOXIE_CPU
+#define MOXIE_CPU_TYPE_NAME(model) model MOXIE_CPU_TYPE_SUFFIX
+
#define cpu_signal_handler cpu_moxie_signal_handler
static inline int cpu_mmu_index(CPUMoxieState *env, bool ifetch)