Patchwork [RFC,18/20] target-unicore32: move final steps of uc32_cpu_init() to realize function

login
register
mail settings
Submitter Eduardo Habkost
Date Dec. 18, 2012, 8:04 p.m.
Message ID <1355861053-11460-19-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/207208/
State New
Headers show

Comments

Eduardo Habkost - Dec. 18, 2012, 8:04 p.m.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-unicore32/cpu.c    | 21 +++++++++++++++++++++
 target-unicore32/helper.c | 11 +----------
 2 files changed, 22 insertions(+), 10 deletions(-)

Patch

diff --git a/target-unicore32/cpu.c b/target-unicore32/cpu.c
index 76750da..5467127 100644
--- a/target-unicore32/cpu.c
+++ b/target-unicore32/cpu.c
@@ -80,12 +80,33 @@  static void uc32_cpu_initfn(Object *obj)
     tlb_flush(env, 1);
 }
 
+static void uc32_cpu_realize(CPUState *cobj, Error **errp)
+{
+    UniCore32CPU *cpu = UNICORE32_CPU(cobj);
+    CPUUniCore32State *env = &cpu->env;
+    static int inited;
+
+    if (!inited) {
+        inited = 1;
+        uc32_translate_init();
+    }
+
+    qemu_init_vcpu(env);
+}
+
+static void uc32_class_init(ObjectClass *oc, void *data)
+{
+    CPUClass *cc = CPU_CLASS(oc);
+    cc->realize = uc32_cpu_realize;
+}
+
 static void uc32_register_cpu_type(const UniCore32CPUInfo *info)
 {
     TypeInfo type_info = {
         .name = info->name,
         .parent = TYPE_UNICORE32_CPU,
         .instance_init = info->instance_init,
+        .class_init = uc32_class_init,
     };
 
     type_register_static(&type_info);
diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c
index dc7b0b3..927e591 100644
--- a/target-unicore32/helper.c
+++ b/target-unicore32/helper.c
@@ -26,21 +26,12 @@ 
 CPUState *uc32_cpu_init(const char *cpu_model)
 {
     UniCore32CPU *cpu;
-    CPUUniCore32State *env;
-    static int inited = 1;
 
     if (object_class_by_name(cpu_model) == NULL) {
         return NULL;
     }
     cpu = UNICORE32_CPU(object_new(cpu_model));
-    env = &cpu->env;
-
-    if (inited) {
-        inited = 0;
-        uc32_translate_init();
-    }
-
-    qemu_init_vcpu(env);
+    cpu_realize(CPU(cpu), NULL);
     return CPU(cpu);
 }