From nobody Fri May 17 06:53:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1681238162; cv=none; d=zohomail.com; s=zohoarc; b=M1RvhBhloUgb7ADl7V6DZQyca5T/RekJMj1vZQzZq+fQt7nZ6UnaHEp2gLp2nqGQTSI5Wq4tREUqThangdlmoAWhTCiM3n7/Ke6TzeCCiTN1BHgp+SuHQAyIRbGTGE+xSd30lSOAE+Q84HQl0CSDSnCP7BCZeKEOvTqC7edltWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681238162; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ywktIeNjmzcDZXTa18vId8DLOUcAih4LapmgltNiEzs=; b=mBLcvchnJmYRuviu8b3Tir6cTZdhGC03BQVXYQsFq7MaX6v5iNvwCiuNhPb1X6NjZg6wHNN35G/JVJxvY2EB+V77J8Wx8F/K7TBb5Qe///mKfaCXw+/vzYFoOYSxXsTXIbpwSvVY34prNxHy4dTjvVrlMrI64UC7GTxe3HBGlvE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1681238162191691.5205876917428; Tue, 11 Apr 2023 11:36:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmIp9-0007pr-1B; Tue, 11 Apr 2023 14:34:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmIp7-0007ou-9Y for qemu-devel@nongnu.org; Tue, 11 Apr 2023 14:34:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmIp5-0007rK-Bu for qemu-devel@nongnu.org; Tue, 11 Apr 2023 14:34:33 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-459-BevZngUFP82HbXt3ZEgVyQ-1; Tue, 11 Apr 2023 14:34:24 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6A1C538221CF; Tue, 11 Apr 2023 18:34:24 +0000 (UTC) Received: from thuth.com (unknown [10.39.192.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1F7640BC797; Tue, 11 Apr 2023 18:34:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681238070; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ywktIeNjmzcDZXTa18vId8DLOUcAih4LapmgltNiEzs=; b=dfmfHEVjIOEKpdSZ3gocaQixuNG6TdwWSRofApKnzGR3ybD90bXPnzDE5L5CsaSH6hKyD5 TxuxNx/6x6D4zXuR9U8oa5YmKjEMaL12PIPTfMbZP27flj2Rn3twu0FSH65hIT2rnjfaLN ZyALNJGR6usY8tGJM9t09D85jSW3SBg= X-MC-Unique: BevZngUFP82HbXt3ZEgVyQ-1 From: Thomas Huth To: Laurent Vivier , qemu-devel@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-ppc@nongnu.org, Paolo Bonzini , Richard Henderson , David Gibson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza Subject: [PATCH 1/3] softmmu/qtest: Move the target-specific pseries RTAS code out of qtest.c Date: Tue, 11 Apr 2023 20:34:16 +0200 Message-Id: <20230411183418.1640500-2-thuth@redhat.com> In-Reply-To: <20230411183418.1640500-1-thuth@redhat.com> References: <20230411183418.1640500-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681238163884100011 Content-Type: text/plain; charset="utf-8" Ideally, qtest.c should be independent from target specific code, so we only have to compile it once for all targets. Thus start improving the situation by moving the pseries related code to hw/ppc/spapr_rtas.c instead and allow target code to register a callback handler for such target specific commands. Signed-off-by: Thomas Huth Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Richard Henderson --- include/sysemu/qtest.h | 4 ++++ hw/ppc/spapr_rtas.c | 29 +++++++++++++++++++++++++++++ softmmu/qtest.c | 39 +++++++++++++-------------------------- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h index 4c53537ef3..85f05b0e46 100644 --- a/include/sysemu/qtest.h +++ b/include/sysemu/qtest.h @@ -14,6 +14,7 @@ #ifndef QTEST_H #define QTEST_H =20 +#include "chardev/char.h" =20 extern bool qtest_allowed; =20 @@ -22,6 +23,9 @@ static inline bool qtest_enabled(void) return qtest_allowed; } =20 +void qtest_send_prefix(CharBackend *chr); +void G_GNUC_PRINTF(2, 3) qtest_sendf(CharBackend *chr, const char *fmt, ..= .); +void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words)); bool qtest_driver(void); =20 void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Er= ror **errp); diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 3f664ea02c..7df21581c2 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -33,6 +33,7 @@ #include "sysemu/cpus.h" #include "sysemu/hw_accel.h" #include "sysemu/runstate.h" +#include "sysemu/qtest.h" #include "kvm_ppc.h" =20 #include "hw/ppc/spapr.h" @@ -548,6 +549,32 @@ uint64_t qtest_rtas_call(char *cmd, uint32_t nargs, ui= nt64_t args, return H_PARAMETER; } =20 +static bool spapr_qtest_callback(CharBackend *chr, gchar **words) +{ + if (strcmp(words[0], "rtas") =3D=3D 0) { + uint64_t res, args, ret; + unsigned long nargs, nret; + int rc; + + rc =3D qemu_strtoul(words[2], NULL, 0, &nargs); + g_assert(rc =3D=3D 0); + rc =3D qemu_strtou64(words[3], NULL, 0, &args); + g_assert(rc =3D=3D 0); + rc =3D qemu_strtoul(words[4], NULL, 0, &nret); + g_assert(rc =3D=3D 0); + rc =3D qemu_strtou64(words[5], NULL, 0, &ret); + g_assert(rc =3D=3D 0); + res =3D qtest_rtas_call(words[1], nargs, args, nret, ret); + + qtest_send_prefix(chr); + qtest_sendf(chr, "OK %"PRIu64"\n", res); + + return true; + } + + return false; +} + void spapr_rtas_register(int token, const char *name, spapr_rtas_fn fn) { assert((token >=3D RTAS_TOKEN_BASE) && (token < RTAS_TOKEN_MAX)); @@ -630,6 +657,8 @@ static void core_rtas_register_types(void) rtas_ibm_nmi_register); spapr_rtas_register(RTAS_IBM_NMI_INTERLOCK, "ibm,nmi-interlock", rtas_ibm_nmi_interlock); + + qtest_set_command_cb(spapr_qtest_callback); } =20 type_init(core_rtas_register_types) diff --git a/softmmu/qtest.c b/softmmu/qtest.c index 34bd2a33a7..76cbb8bcee 100644 --- a/softmmu/qtest.c +++ b/softmmu/qtest.c @@ -29,10 +29,6 @@ #include "qemu/module.h" #include "qemu/cutils.h" #include "qom/object_interfaces.h" -#include CONFIG_DEVICES -#ifdef CONFIG_PSERIES -#include "hw/ppc/spapr_rtas.h" -#endif =20 #define MAX_IRQ 256 =20 @@ -263,7 +259,7 @@ static int hex2nib(char ch) } } =20 -static void qtest_send_prefix(CharBackend *chr) +void qtest_send_prefix(CharBackend *chr) { if (!qtest_log_fp || !qtest_opened) { return; @@ -302,8 +298,7 @@ static void qtest_send(CharBackend *chr, const char *st= r) qtest_server_send(qtest_server_send_opaque, str); } =20 -static void G_GNUC_PRINTF(2, 3) qtest_sendf(CharBackend *chr, - const char *fmt, ...) +void qtest_sendf(CharBackend *chr, const char *fmt, ...) { va_list ap; gchar *buffer; @@ -361,6 +356,15 @@ static void qtest_clock_warp(int64_t dest) qemu_clock_notify(QEMU_CLOCK_VIRTUAL); } =20 +static bool (*process_command_cb)(CharBackend *chr, gchar **words); + +void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words)) +{ + assert(!process_command_cb); /* Switch to a list if we need more than= one */ + + process_command_cb =3D pc_cb; +} + static void qtest_process_command(CharBackend *chr, gchar **words) { const gchar *command; @@ -717,25 +721,6 @@ static void qtest_process_command(CharBackend *chr, gc= har **words) qtest_sendf(chr, "OK big\n"); #else qtest_sendf(chr, "OK little\n"); -#endif -#ifdef CONFIG_PSERIES - } else if (strcmp(words[0], "rtas") =3D=3D 0) { - uint64_t res, args, ret; - unsigned long nargs, nret; - int rc; - - rc =3D qemu_strtoul(words[2], NULL, 0, &nargs); - g_assert(rc =3D=3D 0); - rc =3D qemu_strtou64(words[3], NULL, 0, &args); - g_assert(rc =3D=3D 0); - rc =3D qemu_strtoul(words[4], NULL, 0, &nret); - g_assert(rc =3D=3D 0); - rc =3D qemu_strtou64(words[5], NULL, 0, &ret); - g_assert(rc =3D=3D 0); - res =3D qtest_rtas_call(words[1], nargs, args, nret, ret); - - qtest_send_prefix(chr); - qtest_sendf(chr, "OK %"PRIu64"\n", res); #endif } else if (qtest_enabled() && strcmp(words[0], "clock_step") =3D=3D 0)= { int64_t ns; @@ -777,6 +762,8 @@ static void qtest_process_command(CharBackend *chr, gch= ar **words) qtest_send_prefix(chr); qtest_sendf(chr, "OK %"PRIi64"\n", (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); + } else if (process_command_cb && process_command_cb(chr, words)) { + /* Command got consumed by the callback handler */ } else { qtest_send_prefix(chr); qtest_sendf(chr, "FAIL Unknown command '%s'\n", words[0]); --=20 2.31.1 From nobody Fri May 17 06:53:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1681238116; cv=none; d=zohomail.com; s=zohoarc; b=k1uOXeHIjzihZG4iy631761oo0SnGFEXPZ3gEHr6EFFIhcNLnhnpOk02IWdXGLtbY9KDonJKC/c3lzskyoa7Ql9qgt2TQMr1dZAWpH4xfAGvAiqN4m+4clAuU+o7rQ8eInNmViq3cfHQ+X0FtXExeJqnKRiIX0WhWBqFTqfOvEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681238116; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1WR3JUd4sj5Y/42kNM9HHQB4Ft1XAdsD7YSuJ46rkS8=; b=SA9YmGcQlMf6eypW/b0OPXUPDLGWz+zml7rLChs1UNkwGhgiQ+xXExUqbug6vDymWdy96BJ1sAVrOXuujssy+vjkt6hOBYqyH/r08/VFOJ/Pd0Im2Yk1KY+9svQR+OfZUShXAdQ5sO1ddVHcTOsT85ZDESaZsz4Xa84MP/PKVDc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1681238116395166.10070113604024; Tue, 11 Apr 2023 11:35:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmIp8-0007pp-Ln; Tue, 11 Apr 2023 14:34:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmIp6-0007oh-Jb for qemu-devel@nongnu.org; Tue, 11 Apr 2023 14:34:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmIp4-0007r5-AO for qemu-devel@nongnu.org; Tue, 11 Apr 2023 14:34:31 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-296-Dhyq2IS0OVqgDUMinmql2A-1; Tue, 11 Apr 2023 14:34:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D5AF3800B23; Tue, 11 Apr 2023 18:34:26 +0000 (UTC) Received: from thuth.com (unknown [10.39.192.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id C15D040BC797; Tue, 11 Apr 2023 18:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681238068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1WR3JUd4sj5Y/42kNM9HHQB4Ft1XAdsD7YSuJ46rkS8=; b=J/Ed3EI6yL7KF5irCCRfp5AbtwCCo+/kAeASEPQaS/tpsEjWd6VIYjK4K7OENJvcX48H/r mX/H6q0Rl5V02yA1A9fxMG7c7PowMUfmuepLsp+wn5nJmYISiUXMYBvmPzS4uGxhYkakSq nKWPiHWWmuvjRoFilWJQ0ZnK4NBOcy4= X-MC-Unique: Dhyq2IS0OVqgDUMinmql2A-1 From: Thomas Huth To: Laurent Vivier , qemu-devel@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-ppc@nongnu.org, Paolo Bonzini , Richard Henderson , David Gibson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza Subject: [PATCH 2/3] include/exec: Provide the tswap() functions for target independent code, too Date: Tue, 11 Apr 2023 20:34:17 +0200 Message-Id: <20230411183418.1640500-3-thuth@redhat.com> In-Reply-To: <20230411183418.1640500-1-thuth@redhat.com> References: <20230411183418.1640500-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681238117989100001 Content-Type: text/plain; charset="utf-8" In some cases of target independent code, it would be useful to have access to the functions that swap endianess in case it differs between guest and host. Thus re-implement the tswapXX() functions in a new header that can be included separately. The check whether the swapping is needed continues to be done at compile-time for target specific code, while it is done at run-time in target-independent code. Signed-off-by: Thomas Huth Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Richard Henderson --- include/exec/cpu-all.h | 64 +------------------------------------ include/exec/tswap.h | 72 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 63 deletions(-) create mode 100644 include/exec/tswap.h diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 090922e4a8..ad824fee52 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -21,6 +21,7 @@ =20 #include "exec/cpu-common.h" #include "exec/memory.h" +#include "exec/tswap.h" #include "qemu/thread.h" #include "hw/core/cpu.h" #include "qemu/rcu.h" @@ -44,69 +45,6 @@ #define BSWAP_NEEDED #endif =20 -#ifdef BSWAP_NEEDED - -static inline uint16_t tswap16(uint16_t s) -{ - return bswap16(s); -} - -static inline uint32_t tswap32(uint32_t s) -{ - return bswap32(s); -} - -static inline uint64_t tswap64(uint64_t s) -{ - return bswap64(s); -} - -static inline void tswap16s(uint16_t *s) -{ - *s =3D bswap16(*s); -} - -static inline void tswap32s(uint32_t *s) -{ - *s =3D bswap32(*s); -} - -static inline void tswap64s(uint64_t *s) -{ - *s =3D bswap64(*s); -} - -#else - -static inline uint16_t tswap16(uint16_t s) -{ - return s; -} - -static inline uint32_t tswap32(uint32_t s) -{ - return s; -} - -static inline uint64_t tswap64(uint64_t s) -{ - return s; -} - -static inline void tswap16s(uint16_t *s) -{ -} - -static inline void tswap32s(uint32_t *s) -{ -} - -static inline void tswap64s(uint64_t *s) -{ -} - -#endif - #if TARGET_LONG_SIZE =3D=3D 4 #define tswapl(s) tswap32(s) #define tswapls(s) tswap32s((uint32_t *)(s)) diff --git a/include/exec/tswap.h b/include/exec/tswap.h new file mode 100644 index 0000000000..68944a880b --- /dev/null +++ b/include/exec/tswap.h @@ -0,0 +1,72 @@ +/* + * Macros for swapping a value if the endianness is different + * between the target and the host. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#ifndef TSWAP_H +#define TSWAP_H + +#include "hw/core/cpu.h" +#include "qemu/bswap.h" + +/* + * If we're in target-specific code, we can hard-code the swapping + * condition, otherwise we have to do (slower) run-time checks. + */ +#ifdef NEED_CPU_H +#define target_needs_bswap() (HOST_BIG_ENDIAN !=3D TARGET_BIG_ENDIAN) +#else +#define target_needs_bswap() (target_words_bigendian() !=3D HOST_BIG_ENDI= AN) +#endif + +static inline uint16_t tswap16(uint16_t s) +{ + if (target_needs_bswap()) { + return bswap16(s); + } else { + return s; + } +} + +static inline uint32_t tswap32(uint32_t s) +{ + if (target_needs_bswap()) { + return bswap32(s); + } else { + return s; + } +} + +static inline uint64_t tswap64(uint64_t s) +{ + if (target_needs_bswap()) { + return bswap64(s); + } else { + return s; + } +} + +static inline void tswap16s(uint16_t *s) +{ + if (target_needs_bswap()) { + *s =3D bswap16(*s); + } +} + +static inline void tswap32s(uint32_t *s) +{ + if (target_needs_bswap()) { + *s =3D bswap32(*s); + } +} + +static inline void tswap64s(uint64_t *s) +{ + if (target_needs_bswap()) { + *s =3D bswap64(*s); + } +} + +#endif /* TSWAP_H */ --=20 2.31.1 From nobody Fri May 17 06:53:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1681238116; cv=none; d=zohomail.com; s=zohoarc; b=ayCoDVLAJkl2yzgdT0gL8ommABMm8U0jkHdVZ+71fJwCfPR0/KKcpD9GXpnO3+kE8reVATAtO/JYWZOMs3+iKsE8ztmjgnxCUTVmBHulRLOOnxS1I0Pu42NMqjK9RagDvPJ6LW7/4q680ybKuwnQLf6FbHdR24LA4B3PmhQMJ3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681238116; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7JUIOdBxGT6oGtU6vp8zJtxfRJKtCGtT/nlvEO2fOXw=; b=S6SLB73vsJguHPBKkpzIDUHeOiK8r+M4JiSZat0dFJ+DmJ+L5zuCUNd/7CwXSaJEjATcBHhH2mYGr9DGOgIMefQHueCJRtHzXRBBLRuPaUaYxOvlej3+KD6/XGBZ0dPvH5h7tY8ubYXIBNuGuJHr5T+jB+AdfReq8vanZOYbTPM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1681238116496543.9177799979973; Tue, 11 Apr 2023 11:35:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmIpB-0007s6-Uh; Tue, 11 Apr 2023 14:34:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmIpA-0007rL-Sl for qemu-devel@nongnu.org; Tue, 11 Apr 2023 14:34:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmIp9-0007sz-Cb for qemu-devel@nongnu.org; Tue, 11 Apr 2023 14:34:36 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-282-B2bh-6sHNRKmcF_Y6ZSTjA-1; Tue, 11 Apr 2023 14:34:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0D56D185A78F; Tue, 11 Apr 2023 18:34:29 +0000 (UTC) Received: from thuth.com (unknown [10.39.192.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38B7340BC797; Tue, 11 Apr 2023 18:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681238074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7JUIOdBxGT6oGtU6vp8zJtxfRJKtCGtT/nlvEO2fOXw=; b=A+oF/1c+2Bm3VwviOcwguYyplau0xTWUtZrh1EjqgEslr3ckQQ5YliSm/i8AKvF/IgCuOs eo5oN5v3NMDE1NdZJIFayPFy2exXcz6g7uUv+B5aonltBNU6gGsskgTLsNTwHXklHyr4L5 2ioaTYbvafswmCOHd9jm4WRAR2vkCEY= X-MC-Unique: B2bh-6sHNRKmcF_Y6ZSTjA-1 From: Thomas Huth To: Laurent Vivier , qemu-devel@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-ppc@nongnu.org, Paolo Bonzini , Richard Henderson , David Gibson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza Subject: [PATCH 3/3] softmmu: Make qtest.c target independent Date: Tue, 11 Apr 2023 20:34:18 +0200 Message-Id: <20230411183418.1640500-4-thuth@redhat.com> In-Reply-To: <20230411183418.1640500-1-thuth@redhat.com> References: <20230411183418.1640500-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681238118367100007 Content-Type: text/plain; charset="utf-8" The code in this file is not performance critical, so we can use the target independent endianess functions to only compile this file once for all targets. Signed-off-by: Thomas Huth Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Richard Henderson --- softmmu/qtest.c | 12 ++++++------ softmmu/meson.build | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/softmmu/qtest.c b/softmmu/qtest.c index 76cbb8bcee..9f2197fd6f 100644 --- a/softmmu/qtest.c +++ b/softmmu/qtest.c @@ -13,12 +13,12 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" -#include "cpu.h" #include "sysemu/qtest.h" #include "sysemu/runstate.h" #include "chardev/char-fe.h" #include "exec/ioport.h" #include "exec/memory.h" +#include "exec/tswap.h" #include "hw/qdev-core.h" #include "hw/irq.h" #include "qemu/accel.h" @@ -717,11 +717,11 @@ static void qtest_process_command(CharBackend *chr, g= char **words) qtest_send(chr, "OK\n"); } else if (strcmp(words[0], "endianness") =3D=3D 0) { qtest_send_prefix(chr); -#if TARGET_BIG_ENDIAN - qtest_sendf(chr, "OK big\n"); -#else - qtest_sendf(chr, "OK little\n"); -#endif + if (target_words_bigendian()) { + qtest_sendf(chr, "OK big\n"); + } else { + qtest_sendf(chr, "OK little\n"); + } } else if (qtest_enabled() && strcmp(words[0], "clock_step") =3D=3D 0)= { int64_t ns; =20 diff --git a/softmmu/meson.build b/softmmu/meson.build index 1a7c7ac089..b392f0bd35 100644 --- a/softmmu/meson.build +++ b/softmmu/meson.build @@ -3,7 +3,6 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files( 'ioport.c', 'memory.c', 'physmem.c', - 'qtest.c', 'dirtylimit.c', 'watchpoint.c', )]) @@ -23,6 +22,7 @@ softmmu_ss.add(files( 'globals.c', 'memory_mapping.c', 'qdev-monitor.c', + 'qtest.c', 'rtc.c', 'runstate-action.c', 'runstate-hmp-cmds.c', --=20 2.31.1