Patchwork [RFC,20/20] cpu: convert cpu_copy() to QOM

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

Comments

Eduardo Habkost - Dec. 18, 2012, 8:04 p.m.
Instead of using CPUArchState for parameters and return value,
get/return CPUState objects.

It is still an ugly hack that should die, but at least it's an ugly hack
that can use the QOM CPU object if necessary, and allows the calling
code to be converted to QOM as well.

This also keeps the cpu_copy() hack that we need to eventually kill.

The result of this series is:

  $ g grep class_by_name target-*/cpu.c
  $

That means all architectures that used CPU class lookup on its cpu_init()
implementation were converted to use generic_cpu_init().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 cpu-all.h            | 1 -
 exec.c               | 9 +++++----
 include/qemu/cpu.h   | 4 ++++
 linux-user/syscall.c | 2 +-
 4 files changed, 10 insertions(+), 6 deletions(-)

Patch

diff --git a/cpu-all.h b/cpu-all.h
index d6b2b19..24662ce 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -352,7 +352,6 @@  void page_set_flags(target_ulong start, target_ulong end, int flags);
 int page_check_range(target_ulong start, target_ulong len, int flags);
 #endif
 
-CPUArchState *cpu_copy(CPUArchState *env);
 CPUArchState *qemu_get_cpu(int cpu);
 
 #define CPU_DUMP_CODE 0x00010000
diff --git a/exec.c b/exec.c
index 3919145..5af5652 100644
--- a/exec.c
+++ b/exec.c
@@ -524,10 +524,11 @@  void cpu_abort(CPUArchState *env, const char *fmt, ...)
     abort();
 }
 
-CPUArchState *cpu_copy(CPUArchState *env)
+CPUState *cpu_copy(CPUState *old_cpu)
 {
-    CPUState *old_cpu = ENV_GET_CPU(env);
-    CPUArchState *new_env = CPU_GET_ENV(cpu_init(old_cpu->cpu_model_str));
+    CPUArchState *env = CPU_GET_ENV(old_cpu);
+    CPUState *new_cpu = cpu_init(old_cpu->cpu_model_str);
+    CPUArchState *new_env = CPU_GET_ENV(new_cpu);
     CPUArchState *next_cpu = new_env->next_cpu;
     int cpu_index = new_env->cpu_index;
 #if defined(TARGET_HAS_ICE)
@@ -556,7 +557,7 @@  CPUArchState *cpu_copy(CPUArchState *env)
     }
 #endif
 
-    return new_env;
+    return new_cpu;
 }
 
 #if !defined(CONFIG_USER_ONLY)
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index 7461319..9cfbc94 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -174,5 +174,9 @@  CPUState *generic_cpu_create(const char *base_class_name,
  */
 CPUState *generic_cpu_init(const char *base_class_name, const char *cpu_model);
 
+/* Legacy hacks that should eventually die: */
+
+/* CPU clone/copy hack, that does a memcpy of the ->env field */
+CPUState *cpu_copy(CPUState *cpu);
 
 #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 31d5276..400cf47 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4362,7 +4362,7 @@  static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
         ts = g_malloc0(sizeof(TaskState));
         init_task_state(ts);
         /* we create a new CPU instance. */
-        new_env = cpu_copy(env);
+        new_env = CPU_GET_ENV(cpu_copy(ENV_GET_CPU(env)));
 #if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC)
         cpu_reset(ENV_GET_CPU(new_env));
 #endif