Implement vmstate_cpu_common.
Change-Id: I33a83e9ece5ce1fa4631fb24d7c2ff9661b97346
diff --git a/exec.c b/exec.c
index adca9e0..9e0ca1b 100644
--- a/exec.c
+++ b/exec.c
@@ -120,31 +120,12 @@
#endif
}
-#if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
+#if !defined(CONFIG_USER_ONLY)
-#define CPU_COMMON_SAVE_VERSION 1
-
-static void cpu_common_save(QEMUFile *f, void *opaque)
+static int cpu_common_post_load(void *opaque, int version_id)
{
- CPUOldState *env = opaque;
- CPUState *cpu = ENV_GET_CPU(env);
+ CPUState *cpu = opaque;
- cpu_synchronize_state(cpu, 0);
-
- qemu_put_be32s(f, &cpu->halted);
- qemu_put_be32s(f, &cpu->interrupt_request);
-}
-
-static int cpu_common_load(QEMUFile *f, void *opaque, int version_id)
-{
- CPUOldState *env = opaque;
- CPUState *cpu = ENV_GET_CPU(env);
-
- if (version_id != CPU_COMMON_SAVE_VERSION)
- return -EINVAL;
-
- qemu_get_be32s(f, &cpu->halted);
- qemu_get_be32s(f, &cpu->interrupt_request);
/* 0x01 was CPU_INTERRUPT_EXIT. This line can be removed when the
version_id is increased. */
cpu->interrupt_request &= ~0x01;
@@ -153,16 +134,30 @@
return 0;
}
+
+const VMStateDescription vmstate_cpu_common = {
+ .name = "cpu_common",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .minimum_version_id_old = 1,
+ .post_load = cpu_common_post_load,
+ .fields = (VMStateField []) {
+ VMSTATE_UINT32(halted, CPUState),
+ VMSTATE_UINT32(interrupt_request, CPUState),
+ VMSTATE_END_OF_LIST()
+ }
+};
#endif
-CPUState *qemu_get_cpu(int cpu_index)
+CPUState *qemu_get_cpu(int index)
{
CPUState *cpu;
CPU_FOREACH(cpu) {
- if (cpu->cpu_index == cpu_index)
+ if (cpu->cpu_index == index) {
return cpu;
}
+ }
return NULL;
}
@@ -188,21 +183,10 @@
#if defined(CONFIG_USER_ONLY)
cpu_list_unlock();
#endif
+ vmstate_register(NULL, cpu_index, &vmstate_cpu_common, cpu);
#if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
- register_savevm(NULL,
- "cpu_common",
- cpu_index,
- CPU_COMMON_SAVE_VERSION,
- cpu_common_save,
- cpu_common_load,
- env);
- register_savevm(NULL,
- "cpu",
- cpu_index,
- CPU_SAVE_VERSION,
- cpu_save,
- cpu_load,
- env);
+ register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
+ cpu_save, cpu_load, env);
#endif
}
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index b25d20f..4750de9 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -353,5 +353,18 @@
void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
GCC_FMT_ATTR(2, 3);
+#ifdef CONFIG_SOFTMMU
+extern const struct VMStateDescription vmstate_cpu_common;
+#else
+#define vmstate_cpu_common vmstate_dummy
+#endif
+
+#define VMSTATE_CPU() { \
+ .name = "parent_obj", \
+ .size = sizeof(CPUState), \
+ .vmsd = &vmstate_cpu_common, \
+ .flags = VMS_STRUCT, \
+ .offset = 0, \
+}
#endif