qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC 04/13] move CPU x86 object creation to cpu.c


From: Eduardo Habkost
Subject: [Qemu-devel] [RFC 04/13] move CPU x86 object creation to cpu.c
Date: Thu, 16 Aug 2012 13:59:03 -0300

Eventually all of the init code will become just a simple object_new()
call, but right now we need to reorder and split some of the steps
invoved in the CPU model string parsing, and it will be easier to do
that inside cpu.c, by now.

Signed-off-by: Eduardo Habkost <address@hidden>
---
 hw/pc.c              |  2 +-
 hw/xen_machine_pv.c  |  2 +-
 target-i386/cpu.c    | 18 ++++++++++++++++++
 target-i386/cpu.h    |  4 ++--
 target-i386/helper.c | 24 ------------------------
 5 files changed, 22 insertions(+), 28 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index 8c639f3..5f93d86 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -911,7 +911,7 @@ static X86CPU *pc_new_cpu(const char *cpu_model)
     X86CPU *cpu;
     CPUX86State *env;
 
-    cpu = cpu_x86_init(cpu_model);
+    cpu = cpu_x86_create(cpu_model);
     if (cpu == NULL) {
         fprintf(stderr, "Unable to find x86 CPU definition\n");
         exit(1);
diff --git a/hw/xen_machine_pv.c b/hw/xen_machine_pv.c
index 4017f43..f966da0 100644
--- a/hw/xen_machine_pv.c
+++ b/hw/xen_machine_pv.c
@@ -49,7 +49,7 @@ static void xen_init_pv(ram_addr_t ram_size,
         cpu_model = "qemu32";
 #endif
     }
-    cpu = cpu_x86_init(cpu_model);
+    cpu = cpu_x86_create(cpu_model);
     qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
     env->halted = 1;
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index d7153f3..5734570 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1503,6 +1503,24 @@ out:
     return 0;
 }
 
+X86CPU *cpu_x86_create(const char *cpu_model)
+{
+    X86CPU *cpu;
+    CPUX86State *env;
+
+    cpu = X86_CPU(object_new(TYPE_X86_CPU));
+    env = &cpu->env;
+    env->cpu_model_str = cpu_model;
+
+    if (cpu_x86_register(cpu, cpu_model) < 0) {
+        object_delete(OBJECT(cpu));
+        return NULL;
+    }
+
+    x86_cpu_realize(OBJECT(cpu), NULL);
+    return cpu;
+}
+
 #if !defined(CONFIG_USER_ONLY)
 /* interpret radix and convert from string to arbitrary scalar,
  * otherwise flag failure
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 3562612..6f48ba8 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -809,7 +809,6 @@ typedef struct CPUX86State {
 
 #include "cpu-qom.h"
 
-X86CPU *cpu_x86_init(const char *cpu_model);
 int cpu_x86_exec(CPUX86State *s);
 void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 void x86_cpudef_setup(void);
@@ -925,6 +924,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo,
 void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
                    uint32_t *eax, uint32_t *ebx,
                    uint32_t *ecx, uint32_t *edx);
+X86CPU *cpu_x86_create(const char *cpu_model);
 int cpu_x86_register(X86CPU *cpu, const char *cpu_model);
 void cpu_clear_apic_feature(CPUX86State *env);
 void host_cpuid(uint32_t function, uint32_t count,
@@ -985,7 +985,7 @@ uint64_t cpu_get_tsc(CPUX86State *env);
 
 static inline CPUX86State *cpu_init(const char *cpu_model)
 {
-    X86CPU *cpu = cpu_x86_init(cpu_model);
+    X86CPU *cpu = cpu_x86_create(cpu_model);
     if (cpu == NULL) {
         return NULL;
     }
diff --git a/target-i386/helper.c b/target-i386/helper.c
index a0e4c89..d51d9eb 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1147,30 +1147,6 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned 
int selector,
     return 1;
 }
 
-X86CPU *cpu_x86_init(const char *cpu_model)
-{
-    X86CPU *cpu;
-    CPUX86State *env;
-    Error *error = NULL;
-
-    cpu = X86_CPU(object_new(TYPE_X86_CPU));
-    env = &cpu->env;
-    env->cpu_model_str = cpu_model;
-
-    if (cpu_x86_register(cpu, cpu_model) < 0) {
-        object_delete(OBJECT(cpu));
-        return NULL;
-    }
-
-    x86_cpu_realize(OBJECT(cpu), &error);
-    if (error_is_set(&error)) {
-        error_free(error);
-        object_delete(OBJECT(cpu));
-        return NULL;
-    }
-    return cpu;
-}
-
 #if !defined(CONFIG_USER_ONLY)
 void do_cpu_init(X86CPU *cpu)
 {
-- 
1.7.11.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]