Patchwork [44/49] x86: factor out cpu_pre/post_load()

login
register
mail settings
Submitter Juan Quintela
Date Sept. 29, 2009, 8:49 p.m.
Message ID <fd03e93278879ee3c39ce089d86962f08eaa3187.1254255997.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/34496/
State Superseded
Headers show

Comments

Juan Quintela - Sept. 29, 2009, 8:49 p.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 target-i386/machine.c |   61 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 41 insertions(+), 20 deletions(-)

Patch

diff --git a/target-i386/machine.c b/target-i386/machine.c
index 5694a5c..454ea14 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -204,12 +204,51 @@  static void fp64_to_fp80(union x86_longdouble *p, uint64_t temp)
 }
 #endif

+static int cpu_pre_load(void *opaque)
+{
+    CPUState *env = opaque;
+
+    cpu_synchronize_state(env);
+    return 0;
+}
+
+static int cpu_post_load(void *opaque, int version_id)
+{
+    CPUState *env = opaque;
+    int i;
+
+    /* XXX: restore FPU round state */
+    env->fpstt = (env->fpus_vmstate >> 11) & 7;
+    env->fpus = env->fpus_vmstate & ~0x3800;
+    env->fptag_vmstate ^= 0xff;
+    for(i = 0; i < 8; i++) {
+        env->fptags[i] = (env->fptag_vmstate >> i) & 1;
+    }
+
+    cpu_breakpoint_remove_all(env, BP_CPU);
+    cpu_watchpoint_remove_all(env, BP_CPU);
+    for (i = 0; i < 4; i++)
+        hw_breakpoint_insert(env, i);
+
+    if (version_id >= 9) {
+        memset(&env->interrupt_bitmap, 0, sizeof(env->interrupt_bitmap));
+        if (env->pending_irq_vmstate >= 0) {
+            env->interrupt_bitmap[env->pending_irq_vmstate / 64] |=
+                (uint64_t)1 << (env->pending_irq_vmstate % 64);
+        }
+    }
+
+    tlb_flush(env, 1);
+    return 0;
+}
+
 int cpu_load(QEMUFile *f, void *opaque, int version_id)
 {
     CPUState *env = opaque;
     int i, guess_mmx;

-    cpu_synchronize_state(env);
+    cpu_pre_load(env);
+
     if (version_id < 3 || version_id > CPU_SAVE_VERSION)
         return -EINVAL;
     for(i = 0; i < CPU_NB_REGS; i++)
@@ -268,14 +307,6 @@  int cpu_load(QEMUFile *f, void *opaque, int version_id)
         }
     }

-    /* XXX: restore FPU round state */
-    env->fpstt = (env->fpus_vmstate >> 11) & 7;
-    env->fpus = env->fpus_vmstate & ~0x3800;
-    env->fptag_vmstate ^= 0xff;
-    for(i = 0; i < 8; i++) {
-        env->fptags[i] = (env->fptag_vmstate >> i) & 1;
-    }
-
     for(i = 0; i < 6; i++)
         cpu_get_seg(f, &env->segs[i]);
     cpu_get_seg(f, &env->ldt);
@@ -299,10 +330,6 @@  int cpu_load(QEMUFile *f, void *opaque, int version_id)

     for(i = 0; i < 8; i++)
         qemu_get_betls(f, &env->dr[i]);
-    cpu_breakpoint_remove_all(env, BP_CPU);
-    cpu_watchpoint_remove_all(env, BP_CPU);
-    for (i = 0; i < 4; i++)
-        hw_breakpoint_insert(env, i);

     qemu_get_sbe32s(f, &env->a20_mask);

@@ -354,11 +381,6 @@  int cpu_load(QEMUFile *f, void *opaque, int version_id)

     if (version_id >= 9) {
         qemu_get_sbe32s(f, &env->pending_irq_vmstate);
-        memset(&env->interrupt_bitmap, 0, sizeof(env->interrupt_bitmap));
-        if (env->pending_irq_vmstate >= 0) {
-            env->interrupt_bitmap[env->pending_irq_vmstate / 64] |=
-                (uint64_t)1 << (env->pending_irq_vmstate % 64);
-        }
         qemu_get_be32s(f, &env->mp_state);
         qemu_get_be64s(f, &env->tsc);
     }
@@ -372,6 +394,5 @@  int cpu_load(QEMUFile *f, void *opaque, int version_id)
         }
     }

-    tlb_flush(env, 1);
-    return 0;
+    return cpu_post_load(env, version_id);
 }