@@ -21,6 +21,7 @@
#define QEMU_SUPERH_CPU_QOM_H
#include "qemu/cpu.h"
+#include "error.h"
#define TYPE_SUPERH_CPU "superh-cpu"
@@ -66,5 +67,7 @@ static inline SuperHCPU *sh_env_get_cpu(CPUSH4State *env)
#define ENV_GET_CPU(e) CPU(sh_env_get_cpu(e))
+void superh_cpu_realize(Object *obj, Error **errp);
+
#endif
@@ -53,6 +53,14 @@ static void superh_cpu_reset(CPUState *s)
set_default_nan_mode(1, &env->fp_status);
}
+void superh_cpu_realize(Object *obj, Error **errp)
+{
+ SuperHCPU *cpu = SUPERH_CPU(obj);
+
+ cpu_reset(CPU(cpu));
+ qemu_init_vcpu(&cpu->env);
+}
+
static void superh_cpu_initfn(Object *obj)
{
SuperHCPU *cpu = SUPERH_CPU(obj);
@@ -261,9 +261,8 @@ CPUSH4State *cpu_sh4_init(const char *cpu_model)
env->features = def->features;
sh4_translate_init();
env->cpu_model_str = cpu_model;
- cpu_reset(CPU(cpu));
cpu_register(env, def);
- qemu_init_vcpu(env);
+ superh_cpu_realize(OBJECT(cpu), NULL);
return env;
}
To avoid moving cpu_reset() into an initfn for some targets, prepare a realizefn with the designated signature but leave it non-static and call it explicitly. Do not declare a local env variable to avoid an unused variable warning for *-user: qemu_init_vcpu() is a no-op macro there. It is safe to reorder cpu_reset() and cpu_register() since there is no overlap in the fields they touch. Signed-off-by: Andreas Färber <afaerber@suse.de> --- target-sh4/cpu-qom.h | 3 +++ target-sh4/cpu.c | 8 ++++++++ target-sh4/translate.c | 3 +-- 3 files changed, 12 insertions(+), 2 deletions(-)