diff mbox

[4/5] vmstate: refactor and move VMSTATE_UINTTL* macro

Message ID 1329905754-11873-5-git-send-email-i.mitsyanko@samsung.com
State New
Headers show

Commit Message

Mitsyanko Igor Feb. 22, 2012, 10:15 a.m. UTC
Instead of defining VMSTATE_UINTTL* based on TARGET_LONG_BITS value, we can
use qemu_put_betls/qemu_get_betls functions. These two functions depend on
TARGET_LONG_BITS as well, and this new approach for VMSTATE_UINTTL* will result
in the same thing as before (will call qemu_get_be32s/qemu_put_be32s for 32-bit
target or qemu_put_be64s/qemu_get_be64s for 64-bit target).
Move VMSTATE_UINTTL* definitions to vmstate.h where they belong.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
---
 hw/hw.h   |   19 -------------------
 savevm.c  |   21 +++++++++++++++++++++
 vmstate.h |   11 +++++++++++
 3 files changed, 32 insertions(+), 19 deletions(-)

Comments

Juan Quintela Feb. 22, 2012, 2 p.m. UTC | #1
Igor Mitsyanko <i.mitsyanko@samsung.com> wrote:
> Instead of defining VMSTATE_UINTTL* based on TARGET_LONG_BITS value, we can
> use qemu_put_betls/qemu_get_betls functions. These two functions depend on
> TARGET_LONG_BITS as well, and this new approach for VMSTATE_UINTTL* will result
> in the same thing as before (will call qemu_get_be32s/qemu_put_be32s for 32-bit
> target or qemu_put_be64s/qemu_get_be64s for 64-bit target).
> Move VMSTATE_UINTTL* definitions to vmstate.h where they belong.

The idea was to removed the other functions.  Notice that the cases are
equivalent.  i.e. this just bring us a new type that we have to
represent, maintain.  The other makes use to use a define, take your poison.

Later, Juan.
diff mbox

Patch

diff --git a/hw/hw.h b/hw/hw.h
index e5cb9bf..fb66156 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -46,23 +46,4 @@  typedef int QEMUBootSetHandler(void *opaque, const char *boot_devices);
 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque);
 int qemu_boot_set(const char *boot_devices);
 
-#ifdef NEED_CPU_H
-#if TARGET_LONG_BITS == 64
-#define VMSTATE_UINTTL_V(_f, _s, _v)                                  \
-    VMSTATE_UINT64_V(_f, _s, _v)
-#define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)                        \
-    VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
-#else
-#define VMSTATE_UINTTL_V(_f, _s, _v)                                  \
-    VMSTATE_UINT32_V(_f, _s, _v)
-#define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)                        \
-    VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
-#endif
-#define VMSTATE_UINTTL(_f, _s)                                        \
-    VMSTATE_UINTTL_V(_f, _s, 0)
-#define VMSTATE_UINTTL_ARRAY(_f, _s, _n)                              \
-    VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
-
-#endif
-
 #endif
diff --git a/savevm.c b/savevm.c
index 80be1ff..af33157 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1081,6 +1081,27 @@  const VMStateInfo vmstate_info_uint16_equal = {
     .put  = put_uint16,
 };
 
+/* target unsigned long */
+
+static int get_target_ul(QEMUFile *f, void *pv, size_t size)
+{
+    target_ulong *v = pv;
+    qemu_get_betls(f, v);
+    return 0;
+}
+
+static void put_target_ul(QEMUFile *f, void *pv, size_t size)
+{
+    target_ulong *v = pv;
+    qemu_put_betls(f, v);
+}
+
+const VMStateInfo vmstate_info_target_ul = {
+    .name = "target ulong",
+    .get  = get_target_ul,
+    .put  = put_target_ul,
+};
+
 /* timers  */
 
 static int get_timer(QEMUFile *f, void *pv, size_t size)
diff --git a/vmstate.h b/vmstate.h
index 9d3c49c..218c303 100644
--- a/vmstate.h
+++ b/vmstate.h
@@ -130,6 +130,7 @@  extern const VMStateInfo vmstate_info_uint8;
 extern const VMStateInfo vmstate_info_uint16;
 extern const VMStateInfo vmstate_info_uint32;
 extern const VMStateInfo vmstate_info_uint64;
+extern const VMStateInfo vmstate_info_target_ul;
 
 extern const VMStateInfo vmstate_info_timer;
 extern const VMStateInfo vmstate_info_buffer;
@@ -446,6 +447,8 @@  extern const VMStateInfo vmstate_info_unused_buffer;
     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
 #define VMSTATE_UINT64_V(_f, _s, _v)                                  \
     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
+#define VMSTATE_UINTTL_V(_f, _s, _v)                                  \
+    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_target_ul, target_ulong)
 
 #define VMSTATE_BOOL(_f, _s)                                          \
     VMSTATE_BOOL_V(_f, _s, 0)
@@ -467,6 +470,8 @@  extern const VMStateInfo vmstate_info_unused_buffer;
     VMSTATE_UINT32_V(_f, _s, 0)
 #define VMSTATE_UINT64(_f, _s)                                        \
     VMSTATE_UINT64_V(_f, _s, 0)
+#define VMSTATE_UINTTL(_f, _s)                                        \
+    VMSTATE_UINTTL_V(_f, _s, 0)
 
 #define VMSTATE_UINT8_EQUAL(_f, _s)                                   \
     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
@@ -558,6 +563,12 @@  extern const VMStateInfo vmstate_info_unused_buffer;
 #define VMSTATE_INT64_ARRAY(_f, _s, _n)                               \
     VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
 
+#define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)                        \
+    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_target_ul, target_ulong)
+
+#define VMSTATE_UINTTL_ARRAY(_f, _s, _n)                              \
+        VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
+
 #define VMSTATE_BUFFER_V(_f, _s, _v)                                  \
     VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))