From patchwork Wed Sep 28 18:51:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 676396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sknK43YCBz9s36 for ; Thu, 29 Sep 2016 05:07:52 +1000 (AEST) Received: from localhost ([::1]:60783 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpKCr-00046s-8i for incoming@patchwork.ozlabs.org; Wed, 28 Sep 2016 15:07:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34241) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpJxU-0006AG-Rv for qemu-devel@nongnu.org; Wed, 28 Sep 2016 14:51:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpJxT-0000XO-G5 for qemu-devel@nongnu.org; Wed, 28 Sep 2016 14:51:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpJxT-0000XF-9Y; Wed, 28 Sep 2016 14:51:55 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B83D5624A8; Wed, 28 Sep 2016 18:51:54 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8SIpYue005222; Wed, 28 Sep 2016 14:51:51 -0400 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 28 Sep 2016 20:51:32 +0200 Message-Id: <1475088693-29091-6-git-send-email-lvivier@redhat.com> In-Reply-To: <1475088693-29091-1-git-send-email-lvivier@redhat.com> References: <1475088693-29091-1-git-send-email-lvivier@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 28 Sep 2016 18:51:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 5/6] qtest: define target cpu endianness conversion functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , thuth@redhat.com, Greg Kurz , qemu-ppc@nongnu.org, Gerd Hoffmann , dgibson@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Laurent Vivier --- 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, ...);