From: Laurent Vivier <lvivier@redhat.com>
To: qemu-devel@nongnu.org
Cc: dgibson@redhat.com, thuth@redhat.com, qemu-ppc@nongnu.org,
Gerd Hoffmann <kraxel@redhat.com>, Greg Kurz <groug@kaod.org>,
Laurent Vivier <lvivier@redhat.com>
Subject: [Qemu-devel] [PATCH v3 5/6] qtest: define target cpu endianness conversion functions
Date: Wed, 28 Sep 2016 20:51:32 +0200 [thread overview]
Message-ID: <1475088693-29091-6-git-send-email-lvivier@redhat.com> (raw)
In-Reply-To: <1475088693-29091-1-git-send-email-lvivier@redhat.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
tests/libqtest.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 4be1f77..b3ac7d8 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -17,6 +17,7 @@
#ifndef LIBQTEST_H
#define LIBQTEST_H
+#include "qemu/bswap.h"
#include "qapi/qmp/qdict.h"
typedef struct QTestState QTestState;
@@ -891,6 +892,62 @@ static inline bool target_big_endian(void)
return qtest_big_endian(global_qtest);
}
+/* Endianness conversion function between target cpu and specified endianess
+ *
+ * uint16_t target_le16_to_cpu(uint16_t v);
+ * uint32_t target_le32_to_cpu(uint32_t v);
+ * uint64_t target_le64_to_cpu(uint64_t v);
+ * uint16_t target_be16_to_cpu(uint16_t v);
+ * uint32_t target_be32_to_cpu(uint32_t v);
+ * uint64_t target_be64_to_cpu(uint64_t v);
+ *
+ * Convert the value @v from the specified format to the native
+ * endianness of the target CPU by byteswapping if necessary, and
+ * return the converted value.
+ *
+ * uint16_t target_cpu_to_le16(uint16_t v);
+ * uint32_t target_cpu_to_le32(uint32_t v);
+ * uint64_t target_cpu_to_le64(uint64_t v);
+ * uint16_t target_cpu_to_be16(uint16_t v);
+ * uint32_t target_cpu_to_be32(uint32_t v);
+ * uint64_t target_cpu_to_be64(uint64_t v);
+ *
+ * Convert the value @v from the native endianness of the target CPU to
+ * the specified format by byteswapping if necessary, and return
+ * the converted value.
+ *
+ * Both target_X_to_cpu() and target_cpu_to_X() perform the same operation; you
+ * should use whichever one is better documenting of the function your
+ * code is performing.
+ *
+ */
+
+#define le_bswap(s, v, size) (qtest_big_endian(s) ? bswap ## size(v) : (v))
+#define be_bswap(s, v, size) (qtest_big_endian(s) ? (v) : bswap ## size(v))
+
+#define TARGET_CPU_CONVERT(endian, size, type)\
+static inline type target_ ## endian ## size ## _to_cpu(type v)\
+{\
+ return glue(endian, _bswap)(global_qtest, v, size);\
+} \
+\
+static inline type target_cpu_to_ ## endian ## size(type v)\
+{\
+ return glue(endian, _bswap)(global_qtest, v, size);\
+}
+
+TARGET_CPU_CONVERT(be, 16, uint16_t)
+TARGET_CPU_CONVERT(be, 32, uint32_t)
+TARGET_CPU_CONVERT(be, 64, uint64_t)
+
+TARGET_CPU_CONVERT(le, 16, uint16_t)
+TARGET_CPU_CONVERT(le, 32, uint32_t)
+TARGET_CPU_CONVERT(le, 64, uint64_t)
+
+#undef TARGET_CPU_CONVERT
+#undef be_bswap
+#undef le_bswap
+
QDict *qmp_fd_receive(int fd);
void qmp_fd_sendv(int fd, const char *fmt, va_list ap);
void qmp_fd_send(int fd, const char *fmt, ...);
--
2.5.5
next prev parent reply other threads:[~2016-09-28 18:51 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-28 18:51 [Qemu-devel] [PATCH v3 0/6] tests: enable ohci/uhci/xhci tests on PPC64 Laurent Vivier
2016-09-28 18:51 ` [Qemu-devel] [PATCH v3 1/6] libqos: add PPC64 PCI support Laurent Vivier
2016-09-29 5:27 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-10-03 11:23 ` Cédric Le Goater
2016-10-03 11:37 ` Laurent Vivier
2016-10-03 14:03 ` Greg Kurz
2016-10-03 14:14 ` Cédric Le Goater
2016-10-03 17:30 ` Cédric Le Goater
2016-10-04 0:24 ` David Gibson
2016-10-04 6:58 ` Greg Kurz
2016-10-04 7:36 ` Greg Kurz
2016-10-05 1:15 ` David Gibson
2016-10-05 1:14 ` David Gibson
2016-10-05 7:34 ` Greg Kurz
2016-10-05 19:33 ` Greg Kurz
2016-10-06 3:53 ` David Gibson
2016-10-04 0:22 ` David Gibson
2016-10-04 6:44 ` Greg Kurz
2016-10-04 6:45 ` Cédric Le Goater
2016-09-28 18:51 ` [Qemu-devel] [PATCH v3 2/6] libqos: add PCI management in qtest_vboot()/qtest_shutdown() Laurent Vivier
2016-09-29 5:30 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-09-28 18:51 ` [Qemu-devel] [PATCH v3 3/6] libqos: use generic qtest_shutdown() Laurent Vivier
2016-09-29 5:31 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-09-28 18:51 ` [Qemu-devel] [PATCH v3 4/6] qtest: evaluate endianness of the target in qtest_init() Laurent Vivier
2016-09-29 5:31 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-09-28 18:51 ` Laurent Vivier [this message]
2016-09-29 5:33 ` [Qemu-devel] [Qemu-ppc] [PATCH v3 5/6] qtest: define target cpu endianness conversion functions David Gibson
2016-09-29 7:23 ` Laurent Vivier
2016-09-29 7:27 ` David Gibson
2016-09-28 18:51 ` [Qemu-devel] [PATCH v3 6/6] tests: enable ohci/uhci/xhci tests on PPC64 Laurent Vivier
2016-10-04 13:20 ` [Qemu-devel] [Qemu-ppc] " Thomas Huth
2016-10-04 13:36 ` Laurent Vivier
2016-09-28 19:24 ` [Qemu-devel] [PATCH v3 0/6] " no-reply
2016-09-29 5:35 ` [Qemu-devel] [Qemu-ppc] " David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1475088693-29091-6-git-send-email-lvivier@redhat.com \
--to=lvivier@redhat.com \
--cc=dgibson@redhat.com \
--cc=groug@kaod.org \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).