Patchwork [RFC,16/20] target-m68k: move final steps of cpu_m68k_init() to realize function

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

Comments

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

Patch

diff --git a/target-m68k/cpu.c b/target-m68k/cpu.c
index 3e70bb0..2e8d60e 100644
--- a/target-m68k/cpu.c
+++ b/target-m68k/cpu.c
@@ -20,7 +20,7 @@ 
 
 #include "cpu.h"
 #include "qemu-common.h"
-
+#include "gdbstub.h"
 
 static void m68k_set_feature(CPUM68KState *env, int feature)
 {
@@ -127,6 +127,55 @@  static void m68k_cpu_initfn(Object *obj)
     cpu_exec_init(env);
 }
 
+static int fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n)
+{
+    if (n < 8) {
+        stfq_p(mem_buf, env->fregs[n]);
+        return 8;
+    }
+    if (n < 11) {
+        /* FP control registers (not implemented)  */
+        memset(mem_buf, 0, 4);
+        return 4;
+    }
+    return 0;
+}
+
+static int fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n)
+{
+    if (n < 8) {
+        env->fregs[n] = ldfq_p(mem_buf);
+        return 8;
+    }
+    if (n < 11) {
+        /* FP control registers (not implemented)  */
+        return 4;
+    }
+    return 0;
+}
+
+static void cpu_m68k_realize(CPUState *cobj, Error **errp)
+{
+    M68kCPU *cpu = M68K_CPU(cobj);
+    CPUM68KState *env = &cpu->env;
+    static int inited;
+
+    if (!inited) {
+        inited = 1;
+        m68k_tcg_init();
+    }
+
+    register_m68k_insns(env);
+    if (m68k_feature(env, M68K_FEATURE_CF_FPU)) {
+        gdb_register_coprocessor(env, fpu_gdb_get_reg, fpu_gdb_set_reg,
+                                 11, "cf-fp.xml", 18);
+    }
+    /* TODO: Add [E]MAC registers.  */
+
+    cpu_reset(cobj);
+    qemu_init_vcpu(env);
+}
+
 static void m68k_cpu_class_init(ObjectClass *c, void *data)
 {
     M68kCPUClass *mcc = M68K_CPU_CLASS(c);
@@ -134,6 +183,7 @@  static void m68k_cpu_class_init(ObjectClass *c, void *data)
 
     mcc->parent_reset = cc->reset;
     cc->reset = m68k_cpu_reset;
+    cc->realize = cpu_m68k_realize;
 }
 
 static void register_cpu_type(const M68kCPUInfo *info)
diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index 4d88bb0..f122706 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -19,7 +19,6 @@ 
  */
 
 #include "cpu.h"
-#include "gdbstub.h"
 
 #include "helpers.h"
 
@@ -71,61 +70,17 @@  void m68k_cpu_list(FILE *f, fprintf_function cpu_fprintf)
     g_slist_free(list);
 }
 
-static int fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n)
-{
-    if (n < 8) {
-        stfq_p(mem_buf, env->fregs[n]);
-        return 8;
-    }
-    if (n < 11) {
-        /* FP control registers (not implemented)  */
-        memset(mem_buf, 0, 4);
-        return 4;
-    }
-    return 0;
-}
-
-static int fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n)
-{
-    if (n < 8) {
-        env->fregs[n] = ldfq_p(mem_buf);
-        return 8;
-    }
-    if (n < 11) {
-        /* FP control registers (not implemented)  */
-        return 4;
-    }
-    return 0;
-}
-
 CPUState *cpu_m68k_init(const char *cpu_model)
 {
     M68kCPU *cpu;
-    CPUM68KState *env;
-    static int inited;
 
     if (object_class_by_name(cpu_model) == NULL) {
         return NULL;
     }
     cpu = M68K_CPU(object_new(cpu_model));
-    env = &cpu->env;
-
-    if (!inited) {
-        inited = 1;
-        m68k_tcg_init();
-    }
-
     CPU(cpu)->cpu_model_str = cpu_model;
+    cpu_realize(CPU(cpu), NULL);
 
-    register_m68k_insns(env);
-    if (m68k_feature(env, M68K_FEATURE_CF_FPU)) {
-        gdb_register_coprocessor(env, fpu_gdb_get_reg, fpu_gdb_set_reg,
-                                 11, "cf-fp.xml", 18);
-    }
-    /* TODO: Add [E]MAC registers.  */
-
-    cpu_reset(ENV_GET_CPU(env));
-    qemu_init_vcpu(env);
     return CPU(cpu);
 }