* [PATCH for-8.1 0/3] Make softmmu/qtest.c target independent
@ 2023-04-11 18:34 Thomas Huth
2023-04-11 18:34 ` [PATCH 1/3] softmmu/qtest: Move the target-specific pseries RTAS code out of qtest.c Thomas Huth
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Thomas Huth @ 2023-04-11 18:34 UTC (permalink / raw)
To: Laurent Vivier, qemu-devel, Philippe Mathieu-Daudé
Cc: qemu-ppc, Paolo Bonzini, Richard Henderson, David Gibson,
Cédric Le Goater, Daniel Henrique Barboza
For being able to build universal binaries one day, we need certain
files to be independent from the emulated target. qtest.c is one of
these files. Rework the target specific code in there so we can
finally move it from "specific_ss" to "softmmu_ss".
Thomas Huth (3):
softmmu/qtest: Move the target-specific pseries RTAS code out of
qtest.c
include/exec: Provide the tswap() functions for target independent
code, too
softmmu: Make qtest.c target independent
include/exec/cpu-all.h | 64 +------------------------------------
include/exec/tswap.h | 72 ++++++++++++++++++++++++++++++++++++++++++
include/sysemu/qtest.h | 4 +++
hw/ppc/spapr_rtas.c | 29 +++++++++++++++++
softmmu/qtest.c | 51 +++++++++++-------------------
softmmu/meson.build | 2 +-
6 files changed, 126 insertions(+), 96 deletions(-)
create mode 100644 include/exec/tswap.h
--
2.31.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] softmmu/qtest: Move the target-specific pseries RTAS code out of qtest.c
2023-04-11 18:34 [PATCH for-8.1 0/3] Make softmmu/qtest.c target independent Thomas Huth
@ 2023-04-11 18:34 ` Thomas Huth
2023-04-12 10:44 ` Cédric Le Goater
2023-04-11 18:34 ` [PATCH 2/3] include/exec: Provide the tswap() functions for target independent code, too Thomas Huth
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Thomas Huth @ 2023-04-11 18:34 UTC (permalink / raw)
To: Laurent Vivier, qemu-devel, Philippe Mathieu-Daudé
Cc: qemu-ppc, Paolo Bonzini, Richard Henderson, David Gibson,
Cédric Le Goater, Daniel Henrique Barboza
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 <thuth@redhat.com>
---
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
+#include "chardev/char.h"
extern bool qtest_allowed;
@@ -22,6 +23,9 @@ static inline bool qtest_enabled(void)
return qtest_allowed;
}
+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);
void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error **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"
#include "hw/ppc/spapr.h"
@@ -548,6 +549,32 @@ uint64_t qtest_rtas_call(char *cmd, uint32_t nargs, uint64_t args,
return H_PARAMETER;
}
+static bool spapr_qtest_callback(CharBackend *chr, gchar **words)
+{
+ if (strcmp(words[0], "rtas") == 0) {
+ uint64_t res, args, ret;
+ unsigned long nargs, nret;
+ int rc;
+
+ rc = qemu_strtoul(words[2], NULL, 0, &nargs);
+ g_assert(rc == 0);
+ rc = qemu_strtou64(words[3], NULL, 0, &args);
+ g_assert(rc == 0);
+ rc = qemu_strtoul(words[4], NULL, 0, &nret);
+ g_assert(rc == 0);
+ rc = qemu_strtou64(words[5], NULL, 0, &ret);
+ g_assert(rc == 0);
+ res = 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 >= 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);
}
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
#define MAX_IRQ 256
@@ -263,7 +259,7 @@ static int hex2nib(char ch)
}
}
-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 *str)
qtest_server_send(qtest_server_send_opaque, str);
}
-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);
}
+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 = 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, gchar **words)
qtest_sendf(chr, "OK big\n");
#else
qtest_sendf(chr, "OK little\n");
-#endif
-#ifdef CONFIG_PSERIES
- } else if (strcmp(words[0], "rtas") == 0) {
- uint64_t res, args, ret;
- unsigned long nargs, nret;
- int rc;
-
- rc = qemu_strtoul(words[2], NULL, 0, &nargs);
- g_assert(rc == 0);
- rc = qemu_strtou64(words[3], NULL, 0, &args);
- g_assert(rc == 0);
- rc = qemu_strtoul(words[4], NULL, 0, &nret);
- g_assert(rc == 0);
- rc = qemu_strtou64(words[5], NULL, 0, &ret);
- g_assert(rc == 0);
- res = 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") == 0) {
int64_t ns;
@@ -777,6 +762,8 @@ static void qtest_process_command(CharBackend *chr, gchar **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]);
--
2.31.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] include/exec: Provide the tswap() functions for target independent code, too
2023-04-11 18:34 [PATCH for-8.1 0/3] Make softmmu/qtest.c target independent Thomas Huth
2023-04-11 18:34 ` [PATCH 1/3] softmmu/qtest: Move the target-specific pseries RTAS code out of qtest.c Thomas Huth
@ 2023-04-11 18:34 ` Thomas Huth
2023-04-12 11:01 ` Cédric Le Goater
2023-04-11 18:34 ` [PATCH 3/3] softmmu: Make qtest.c target independent Thomas Huth
2023-04-12 10:13 ` [PATCH for-8.1 0/3] Make softmmu/qtest.c " Richard Henderson
3 siblings, 1 reply; 8+ messages in thread
From: Thomas Huth @ 2023-04-11 18:34 UTC (permalink / raw)
To: Laurent Vivier, qemu-devel, Philippe Mathieu-Daudé
Cc: qemu-ppc, Paolo Bonzini, Richard Henderson, David Gibson,
Cédric Le Goater, Daniel Henrique Barboza
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 <thuth@redhat.com>
---
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 @@
#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
-#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 = bswap16(*s);
-}
-
-static inline void tswap32s(uint32_t *s)
-{
- *s = bswap32(*s);
-}
-
-static inline void tswap64s(uint64_t *s)
-{
- *s = 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 == 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 != TARGET_BIG_ENDIAN)
+#else
+#define target_needs_bswap() (target_words_bigendian() != HOST_BIG_ENDIAN)
+#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 = bswap16(*s);
+ }
+}
+
+static inline void tswap32s(uint32_t *s)
+{
+ if (target_needs_bswap()) {
+ *s = bswap32(*s);
+ }
+}
+
+static inline void tswap64s(uint64_t *s)
+{
+ if (target_needs_bswap()) {
+ *s = bswap64(*s);
+ }
+}
+
+#endif /* TSWAP_H */
--
2.31.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] softmmu: Make qtest.c target independent
2023-04-11 18:34 [PATCH for-8.1 0/3] Make softmmu/qtest.c target independent Thomas Huth
2023-04-11 18:34 ` [PATCH 1/3] softmmu/qtest: Move the target-specific pseries RTAS code out of qtest.c Thomas Huth
2023-04-11 18:34 ` [PATCH 2/3] include/exec: Provide the tswap() functions for target independent code, too Thomas Huth
@ 2023-04-11 18:34 ` Thomas Huth
2023-04-12 10:53 ` Cédric Le Goater
2023-04-12 10:13 ` [PATCH for-8.1 0/3] Make softmmu/qtest.c " Richard Henderson
3 siblings, 1 reply; 8+ messages in thread
From: Thomas Huth @ 2023-04-11 18:34 UTC (permalink / raw)
To: Laurent Vivier, qemu-devel, Philippe Mathieu-Daudé
Cc: qemu-ppc, Paolo Bonzini, Richard Henderson, David Gibson,
Cédric Le Goater, Daniel Henrique Barboza
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 <thuth@redhat.com>
---
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 @@
#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, gchar **words)
qtest_send(chr, "OK\n");
} else if (strcmp(words[0], "endianness") == 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") == 0) {
int64_t ns;
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',
--
2.31.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH for-8.1 0/3] Make softmmu/qtest.c target independent
2023-04-11 18:34 [PATCH for-8.1 0/3] Make softmmu/qtest.c target independent Thomas Huth
` (2 preceding siblings ...)
2023-04-11 18:34 ` [PATCH 3/3] softmmu: Make qtest.c target independent Thomas Huth
@ 2023-04-12 10:13 ` Richard Henderson
3 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2023-04-12 10:13 UTC (permalink / raw)
To: Thomas Huth, Laurent Vivier, qemu-devel,
Philippe Mathieu-Daudé
Cc: qemu-ppc, Paolo Bonzini, David Gibson, Cédric Le Goater,
Daniel Henrique Barboza
On 4/11/23 20:34, Thomas Huth wrote:
> For being able to build universal binaries one day, we need certain
> files to be independent from the emulated target. qtest.c is one of
> these files. Rework the target specific code in there so we can
> finally move it from "specific_ss" to "softmmu_ss".
>
> Thomas Huth (3):
> softmmu/qtest: Move the target-specific pseries RTAS code out of
> qtest.c
> include/exec: Provide the tswap() functions for target independent
> code, too
> softmmu: Make qtest.c target independent
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] softmmu/qtest: Move the target-specific pseries RTAS code out of qtest.c
2023-04-11 18:34 ` [PATCH 1/3] softmmu/qtest: Move the target-specific pseries RTAS code out of qtest.c Thomas Huth
@ 2023-04-12 10:44 ` Cédric Le Goater
0 siblings, 0 replies; 8+ messages in thread
From: Cédric Le Goater @ 2023-04-12 10:44 UTC (permalink / raw)
To: Thomas Huth, Laurent Vivier, qemu-devel,
Philippe Mathieu-Daudé
Cc: qemu-ppc, Paolo Bonzini, Richard Henderson, David Gibson,
Daniel Henrique Barboza
On 4/11/23 20:34, Thomas Huth wrote:
> 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 <thuth@redhat.com>
That #ifdef CONFIG_PSERIES was really ugly.
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Thanks,
C.
> ---
> 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
>
> +#include "chardev/char.h"
>
> extern bool qtest_allowed;
>
> @@ -22,6 +23,9 @@ static inline bool qtest_enabled(void)
> return qtest_allowed;
> }
>
> +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);
>
> void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error **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"
>
> #include "hw/ppc/spapr.h"
> @@ -548,6 +549,32 @@ uint64_t qtest_rtas_call(char *cmd, uint32_t nargs, uint64_t args,
> return H_PARAMETER;
> }
>
> +static bool spapr_qtest_callback(CharBackend *chr, gchar **words)
> +{
> + if (strcmp(words[0], "rtas") == 0) {
> + uint64_t res, args, ret;
> + unsigned long nargs, nret;
> + int rc;
> +
> + rc = qemu_strtoul(words[2], NULL, 0, &nargs);
> + g_assert(rc == 0);
> + rc = qemu_strtou64(words[3], NULL, 0, &args);
> + g_assert(rc == 0);
> + rc = qemu_strtoul(words[4], NULL, 0, &nret);
> + g_assert(rc == 0);
> + rc = qemu_strtou64(words[5], NULL, 0, &ret);
> + g_assert(rc == 0);
> + res = 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 >= 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);
> }
>
> 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
>
> #define MAX_IRQ 256
>
> @@ -263,7 +259,7 @@ static int hex2nib(char ch)
> }
> }
>
> -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 *str)
> qtest_server_send(qtest_server_send_opaque, str);
> }
>
> -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);
> }
>
> +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 = 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, gchar **words)
> qtest_sendf(chr, "OK big\n");
> #else
> qtest_sendf(chr, "OK little\n");
> -#endif
> -#ifdef CONFIG_PSERIES
> - } else if (strcmp(words[0], "rtas") == 0) {
> - uint64_t res, args, ret;
> - unsigned long nargs, nret;
> - int rc;
> -
> - rc = qemu_strtoul(words[2], NULL, 0, &nargs);
> - g_assert(rc == 0);
> - rc = qemu_strtou64(words[3], NULL, 0, &args);
> - g_assert(rc == 0);
> - rc = qemu_strtoul(words[4], NULL, 0, &nret);
> - g_assert(rc == 0);
> - rc = qemu_strtou64(words[5], NULL, 0, &ret);
> - g_assert(rc == 0);
> - res = 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") == 0) {
> int64_t ns;
> @@ -777,6 +762,8 @@ static void qtest_process_command(CharBackend *chr, gchar **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]);
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] softmmu: Make qtest.c target independent
2023-04-11 18:34 ` [PATCH 3/3] softmmu: Make qtest.c target independent Thomas Huth
@ 2023-04-12 10:53 ` Cédric Le Goater
0 siblings, 0 replies; 8+ messages in thread
From: Cédric Le Goater @ 2023-04-12 10:53 UTC (permalink / raw)
To: Thomas Huth, Laurent Vivier, qemu-devel,
Philippe Mathieu-Daudé
Cc: qemu-ppc, Paolo Bonzini, Richard Henderson, David Gibson,
Daniel Henrique Barboza
On 4/11/23 20:34, Thomas Huth wrote:
> 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 <thuth@redhat.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Thanks,
C.
> ---
> 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 @@
>
> #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, gchar **words)
> qtest_send(chr, "OK\n");
> } else if (strcmp(words[0], "endianness") == 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") == 0) {
> int64_t ns;
>
> 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',
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] include/exec: Provide the tswap() functions for target independent code, too
2023-04-11 18:34 ` [PATCH 2/3] include/exec: Provide the tswap() functions for target independent code, too Thomas Huth
@ 2023-04-12 11:01 ` Cédric Le Goater
0 siblings, 0 replies; 8+ messages in thread
From: Cédric Le Goater @ 2023-04-12 11:01 UTC (permalink / raw)
To: Thomas Huth, Laurent Vivier, qemu-devel,
Philippe Mathieu-Daudé
Cc: qemu-ppc, Paolo Bonzini, Richard Henderson, David Gibson,
Daniel Henrique Barboza
On 4/11/23 20:34, Thomas Huth wrote:
> 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.
Reviewed-by: Cédric Le Goater <clg@kaod.org>
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> 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 @@
>
> #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
I wonder if we could get rid of the BSWAP_NEEDED define also.
(used load_aout() and ELF loaders)
Thanks,
C.
> #endif
>
> -#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 = bswap16(*s);
> -}
> -
> -static inline void tswap32s(uint32_t *s)
> -{
> - *s = bswap32(*s);
> -}
> -
> -static inline void tswap64s(uint64_t *s)
> -{
> - *s = 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 == 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 != TARGET_BIG_ENDIAN)
> +#else
> +#define target_needs_bswap() (target_words_bigendian() != HOST_BIG_ENDIAN)
> +#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 = bswap16(*s);
> + }
> +}
> +
> +static inline void tswap32s(uint32_t *s)
> +{
> + if (target_needs_bswap()) {
> + *s = bswap32(*s);
> + }
> +}
> +
> +static inline void tswap64s(uint64_t *s)
> +{
> + if (target_needs_bswap()) {
> + *s = bswap64(*s);
> + }
> +}
> +
> +#endif /* TSWAP_H */
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-04-12 11:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-11 18:34 [PATCH for-8.1 0/3] Make softmmu/qtest.c target independent Thomas Huth
2023-04-11 18:34 ` [PATCH 1/3] softmmu/qtest: Move the target-specific pseries RTAS code out of qtest.c Thomas Huth
2023-04-12 10:44 ` Cédric Le Goater
2023-04-11 18:34 ` [PATCH 2/3] include/exec: Provide the tswap() functions for target independent code, too Thomas Huth
2023-04-12 11:01 ` Cédric Le Goater
2023-04-11 18:34 ` [PATCH 3/3] softmmu: Make qtest.c target independent Thomas Huth
2023-04-12 10:53 ` Cédric Le Goater
2023-04-12 10:13 ` [PATCH for-8.1 0/3] Make softmmu/qtest.c " Richard Henderson
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).