* [PATCH 01/20] exec/tswap: Rename target_words_bigendian -> qemu_binary_is_bigendian
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 23:33 ` Richard Henderson
2024-12-04 20:25 ` [PATCH 02/20] hw/core/cpu: Introduce CPUClass::datapath_is_big_endian() handler Philippe Mathieu-Daudé
` (18 subsequent siblings)
19 siblings, 1 reply; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
target_words_bigendian() doesn't return whether a target vCPU
expects data in big-endian order, but whether the *binary* has
been compiled with big-endian flavor by default. Rename it
appropriately to reduce confusion. Mechanical change doing:
$ sed -i -e s/target_words_bigendian/qemu_binary_is_bigendian/ \
$(git grep -l target_words_bigendian)
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/exec/tswap.h | 18 +++++++++---------
cpu-target.c | 2 +-
disas/disas-common.c | 2 +-
hw/core/cpu-sysemu.c | 2 +-
hw/core/generic-loader.c | 2 +-
hw/display/vga.c | 4 ++--
hw/virtio/virtio.c | 2 +-
system/qtest.c | 2 +-
8 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/include/exec/tswap.h b/include/exec/tswap.h
index ecd4faef015..0113ff88fcc 100644
--- a/include/exec/tswap.h
+++ b/include/exec/tswap.h
@@ -11,15 +11,15 @@
#include "qemu/bswap.h"
/**
- * target_words_bigendian:
- * Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Note that in target-specific code, you can use
- * TARGET_BIG_ENDIAN directly instead. On the other hand, common
- * code should normally never need to know about the endianness of the
- * target, so please do *not* use this function unless you know very well
- * what you are doing!
+ * qemu_binary_is_bigendian: Returns QEMU binary default endianness
+ *
+ * Returns whether the QEMU binary is built for big endianness flavor
+ * by default.
+ * vCPUs use this flavor by default when their endianness is not specified.
+ *
+ * This is not a clear API so please do *not* use this function.
*/
-bool target_words_bigendian(void);
+bool qemu_binary_is_bigendian(void);
/*
* If we're in target-specific code, we can hard-code the swapping
@@ -28,7 +28,7 @@ bool target_words_bigendian(void);
#ifdef COMPILING_PER_TARGET
#define target_needs_bswap() (HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN)
#else
-#define target_needs_bswap() (HOST_BIG_ENDIAN != target_words_bigendian())
+#define target_needs_bswap() (HOST_BIG_ENDIAN != qemu_binary_is_bigendian())
#endif /* COMPILING_PER_TARGET */
static inline uint16_t tswap16(uint16_t s)
diff --git a/cpu-target.c b/cpu-target.c
index 499facf7747..ff8c55a810a 100644
--- a/cpu-target.c
+++ b/cpu-target.c
@@ -463,7 +463,7 @@ out:
}
#endif
-bool target_words_bigendian(void)
+bool qemu_binary_is_bigendian(void)
{
return TARGET_BIG_ENDIAN;
}
diff --git a/disas/disas-common.c b/disas/disas-common.c
index de61f6d8a12..7377de0715c 100644
--- a/disas/disas-common.c
+++ b/disas/disas-common.c
@@ -61,7 +61,7 @@ void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu)
s->cpu = cpu;
s->info.print_address_func = print_address;
- if (target_words_bigendian()) {
+ if (qemu_binary_is_bigendian()) {
s->info.endian = BFD_ENDIAN_BIG;
} else {
s->info.endian = BFD_ENDIAN_LITTLE;
diff --git a/hw/core/cpu-sysemu.c b/hw/core/cpu-sysemu.c
index 2a9a2a4eb54..4b85face02b 100644
--- a/hw/core/cpu-sysemu.c
+++ b/hw/core/cpu-sysemu.c
@@ -129,7 +129,7 @@ bool cpu_virtio_is_big_endian(CPUState *cpu)
if (cc->sysemu_ops->virtio_is_big_endian) {
return cc->sysemu_ops->virtio_is_big_endian(cpu);
}
- return target_words_bigendian();
+ return qemu_binary_is_bigendian();
}
GuestPanicInformation *cpu_get_crash_info(CPUState *cpu)
diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
index ea8628b8926..abdd4c08a38 100644
--- a/hw/core/generic-loader.c
+++ b/hw/core/generic-loader.c
@@ -134,7 +134,7 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
s->cpu = first_cpu;
}
- big_endian = target_words_bigendian();
+ big_endian = qemu_binary_is_bigendian();
if (s->file) {
AddressSpace *as = s->cpu ? s->cpu->as : NULL;
diff --git a/hw/display/vga.c b/hw/display/vga.c
index 6dbbbf49073..6be02006000 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -2116,7 +2116,7 @@ static bool vga_endian_state_needed(void *opaque)
* default one, thus ensuring backward compatibility for
* migration of the common case
*/
- return s->big_endian_fb != target_words_bigendian();
+ return s->big_endian_fb != qemu_binary_is_bigendian();
}
static const VMStateDescription vmstate_vga_endian = {
@@ -2264,7 +2264,7 @@ bool vga_common_init(VGACommonState *s, Object *obj, Error **errp)
* into a device attribute set by the machine/platform to remove
* all target endian dependencies from this file.
*/
- s->big_endian_fb = target_words_bigendian();
+ s->big_endian_fb = qemu_binary_is_bigendian();
vga_dirty_log_start(s);
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index f12c4aa81eb..b3dede476ed 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2248,7 +2248,7 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val)
static enum virtio_device_endian virtio_default_endian(void)
{
- if (target_words_bigendian()) {
+ if (qemu_binary_is_bigendian()) {
return VIRTIO_DEVICE_ENDIAN_BIG;
} else {
return VIRTIO_DEVICE_ENDIAN_LITTLE;
diff --git a/system/qtest.c b/system/qtest.c
index 12703a20455..8675a0bd316 100644
--- a/system/qtest.c
+++ b/system/qtest.c
@@ -704,7 +704,7 @@ 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_words_bigendian()) {
+ if (qemu_binary_is_bigendian()) {
qtest_sendf(chr, "OK big\n");
} else {
qtest_sendf(chr, "OK little\n");
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 01/20] exec/tswap: Rename target_words_bigendian -> qemu_binary_is_bigendian
2024-12-04 20:25 ` [PATCH 01/20] exec/tswap: Rename target_words_bigendian -> qemu_binary_is_bigendian Philippe Mathieu-Daudé
@ 2024-12-04 23:33 ` Richard Henderson
0 siblings, 0 replies; 27+ messages in thread
From: Richard Henderson @ 2024-12-04 23:33 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
On 12/4/24 14:25, Philippe Mathieu-Daudé wrote:
> target_words_bigendian() doesn't return whether a target vCPU
> expects data in big-endian order, but whether the*binary* has
> been compiled with big-endian flavor by default. Rename it
> appropriately to reduce confusion. Mechanical change doing:
>
> $ sed -i -e s/target_words_bigendian/qemu_binary_is_bigendian/ \
> $(git grep -l target_words_bigendian)
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> include/exec/tswap.h | 18 +++++++++---------
> cpu-target.c | 2 +-
> disas/disas-common.c | 2 +-
> hw/core/cpu-sysemu.c | 2 +-
> hw/core/generic-loader.c | 2 +-
> hw/display/vga.c | 4 ++--
> hw/virtio/virtio.c | 2 +-
> system/qtest.c | 2 +-
> 8 files changed, 17 insertions(+), 17 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 02/20] hw/core/cpu: Introduce CPUClass::datapath_is_big_endian() handler
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 01/20] exec/tswap: Rename target_words_bigendian -> qemu_binary_is_bigendian Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 03/20] target/arm: Implement CPUClass::datapath_is_big_endian Philippe Mathieu-Daudé
` (17 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
Introduce the CPUClass::datapath_is_big_endian() handler,
which returns whether a vCPU expects data in memory to be
in big endian order or not.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/core/cpu.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index c3ca0babcb3..91c6581f814 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -105,6 +105,8 @@ struct SysemuCPUOps;
* @parse_features: Callback to parse command line arguments.
* @reset_dump_flags: #CPUDumpFlags to use for reset logging.
* @has_work: Callback for checking if there is work to do.
+ * @datapath_is_big_endian: Callback returning whether the vCPU expects
+ * memory data in big endian order.
* @mmu_index: Callback for choosing softmmu mmu index;
* may be used internally by memory_rw_debug without TCG.
* @memory_rw_debug: Callback for GDB memory access.
@@ -151,6 +153,7 @@ struct CPUClass {
ObjectClass *(*class_by_name)(const char *cpu_model);
void (*parse_features)(const char *typename, char *str, Error **errp);
+ bool (*datapath_is_big_endian)(CPUState *cpu);
bool (*has_work)(CPUState *cpu);
int (*mmu_index)(CPUState *cpu, bool ifetch);
int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
@@ -750,7 +753,7 @@ int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs);
*/
bool cpu_virtio_is_big_endian(CPUState *cpu);
-#endif /* CONFIG_USER_ONLY */
+#endif /* !CONFIG_USER_ONLY */
/**
* cpu_list_add:
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 03/20] target/arm: Implement CPUClass::datapath_is_big_endian
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 01/20] exec/tswap: Rename target_words_bigendian -> qemu_binary_is_bigendian Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 02/20] hw/core/cpu: Introduce CPUClass::datapath_is_big_endian() handler Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 23:37 ` Richard Henderson
2024-12-04 20:25 ` [PATCH 04/20] target/ppc: Register CPUClass::datapath_is_big_endian Philippe Mathieu-Daudé
` (16 subsequent siblings)
19 siblings, 1 reply; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
arm_cpu_virtio_is_big_endian() already returns whether
the data path is in big endian. Re-use that.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/arm/cpu.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 6938161b954..3061b2ac18c 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1132,7 +1132,7 @@ static void arm_cpu_kvm_set_irq(void *opaque, int irq, int level)
#endif
}
-static bool arm_cpu_virtio_is_big_endian(CPUState *cs)
+static bool arm_cpu_datapath_is_big_endian(CPUState *cs)
{
ARMCPU *cpu = ARM_CPU(cs);
CPUARMState *env = &cpu->env;
@@ -2664,7 +2664,7 @@ static const struct SysemuCPUOps arm_sysemu_ops = {
.asidx_from_attrs = arm_asidx_from_attrs,
.write_elf32_note = arm_cpu_write_elf32_note,
.write_elf64_note = arm_cpu_write_elf64_note,
- .virtio_is_big_endian = arm_cpu_virtio_is_big_endian,
+ .virtio_is_big_endian = arm_cpu_datapath_is_big_endian,
.legacy_vmsd = &vmstate_arm_cpu,
};
#endif
@@ -2709,6 +2709,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
&acc->parent_phases);
cc->class_by_name = arm_cpu_class_by_name;
+ cc->datapath_is_big_endian = arm_cpu_datapath_is_big_endian;
cc->has_work = arm_cpu_has_work;
cc->mmu_index = arm_cpu_mmu_index;
cc->dump_state = arm_cpu_dump_state;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 03/20] target/arm: Implement CPUClass::datapath_is_big_endian
2024-12-04 20:25 ` [PATCH 03/20] target/arm: Implement CPUClass::datapath_is_big_endian Philippe Mathieu-Daudé
@ 2024-12-04 23:37 ` Richard Henderson
0 siblings, 0 replies; 27+ messages in thread
From: Richard Henderson @ 2024-12-04 23:37 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc
On 12/4/24 14:25, Philippe Mathieu-Daudé wrote:
> arm_cpu_virtio_is_big_endian() already returns whether
> the data path is in big endian. Re-use that.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/arm/cpu.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
No, this is wrong.
(1) arm_cpu_virtio_is_big_endian really *is* specific to virtio,
and legacy virtio at that. It changes based on the state of the cpu.
(2) The board-level stuff for which you appear to be intending to
replace qemu_binary_is_bigendian(), for arm, is *always* little-endian,
and has no relation to the state of the cpu.
(3) I thought you were on a better track plumbing endianness through
properties on machine state.
r~
>
> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
> index 6938161b954..3061b2ac18c 100644
> --- a/target/arm/cpu.c
> +++ b/target/arm/cpu.c
> @@ -1132,7 +1132,7 @@ static void arm_cpu_kvm_set_irq(void *opaque, int irq, int level)
> #endif
> }
>
> -static bool arm_cpu_virtio_is_big_endian(CPUState *cs)
> +static bool arm_cpu_datapath_is_big_endian(CPUState *cs)
> {
> ARMCPU *cpu = ARM_CPU(cs);
> CPUARMState *env = &cpu->env;
> @@ -2664,7 +2664,7 @@ static const struct SysemuCPUOps arm_sysemu_ops = {
> .asidx_from_attrs = arm_asidx_from_attrs,
> .write_elf32_note = arm_cpu_write_elf32_note,
> .write_elf64_note = arm_cpu_write_elf64_note,
> - .virtio_is_big_endian = arm_cpu_virtio_is_big_endian,
> + .virtio_is_big_endian = arm_cpu_datapath_is_big_endian,
> .legacy_vmsd = &vmstate_arm_cpu,
> };
> #endif
> @@ -2709,6 +2709,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
> &acc->parent_phases);
>
> cc->class_by_name = arm_cpu_class_by_name;
> + cc->datapath_is_big_endian = arm_cpu_datapath_is_big_endian;
> cc->has_work = arm_cpu_has_work;
> cc->mmu_index = arm_cpu_mmu_index;
> cc->dump_state = arm_cpu_dump_state;
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 04/20] target/ppc: Register CPUClass::datapath_is_big_endian
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 03/20] target/arm: Implement CPUClass::datapath_is_big_endian Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 05/20] target/rx: Implement CPUClass::datapath_is_big_endian Philippe Mathieu-Daudé
` (15 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
ppc_cpu_is_big_endian() already returns whether
the data path is in big endian. Re-use that,
exposing this helper for user emulation.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/ppc/cpu_init.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index efcb80d1c25..9650acb4850 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -7285,15 +7285,15 @@ static void ppc_cpu_reset_hold(Object *obj, ResetType type)
#endif
}
-#ifndef CONFIG_USER_ONLY
-
-static bool ppc_cpu_is_big_endian(CPUState *cs)
+static bool ppc_cpu_datapath_is_big_endian(CPUState *cs)
{
cpu_synchronize_state(cs);
return !FIELD_EX64(cpu_env(cs)->msr, MSR, LE);
}
+#ifndef CONFIG_USER_ONLY
+
static bool ppc_get_irq_stats(InterruptStatsProvider *obj,
uint64_t **irq_counts, unsigned int *nb_irqs)
{
@@ -7407,7 +7407,7 @@ static const struct SysemuCPUOps ppc_sysemu_ops = {
.get_phys_page_debug = ppc_cpu_get_phys_page_debug,
.write_elf32_note = ppc32_cpu_write_elf32_note,
.write_elf64_note = ppc64_cpu_write_elf64_note,
- .virtio_is_big_endian = ppc_cpu_is_big_endian,
+ .virtio_is_big_endian = ppc_cpu_datapath_is_big_endian,
.legacy_vmsd = &vmstate_ppc_cpu,
};
#endif
@@ -7455,6 +7455,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
&pcc->parent_phases);
cc->class_by_name = ppc_cpu_class_by_name;
+ cc->datapath_is_big_endian = ppc_cpu_datapath_is_big_endian;
cc->has_work = ppc_cpu_has_work;
cc->mmu_index = ppc_cpu_mmu_index;
cc->dump_state = ppc_cpu_dump_state;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 05/20] target/rx: Implement CPUClass::datapath_is_big_endian
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 04/20] target/ppc: Register CPUClass::datapath_is_big_endian Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 06/20] target/sparc: " Philippe Mathieu-Daudé
` (14 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
While on RX the endianness can be set at RESET, we
do not implement that; only little endianness is used.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/rx/cpu.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/target/rx/cpu.c b/target/rx/cpu.c
index 65a74ce720f..391f3214168 100644
--- a/target/rx/cpu.c
+++ b/target/rx/cpu.c
@@ -27,6 +27,15 @@
#include "fpu/softfloat.h"
#include "tcg/debug-assert.h"
+static bool rx_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ /*
+ * Endianness is sampled via a pin at reset,
+ * but we don't implement that yet.
+ */
+ return false;
+}
+
static void rx_cpu_set_pc(CPUState *cs, vaddr value)
{
RXCPU *cpu = RX_CPU(cs);
@@ -217,6 +226,7 @@ static void rx_cpu_class_init(ObjectClass *klass, void *data)
&rcc->parent_phases);
cc->class_by_name = rx_cpu_class_by_name;
+ cc->datapath_is_big_endian = rx_cpu_datapath_is_big_endian;
cc->has_work = rx_cpu_has_work;
cc->mmu_index = riscv_cpu_mmu_index;
cc->dump_state = rx_cpu_dump_state;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 06/20] target/sparc: Implement CPUClass::datapath_is_big_endian
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 05/20] target/rx: Implement CPUClass::datapath_is_big_endian Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 07/20] target/riscv: " Philippe Mathieu-Daudé
` (13 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
While the SPARC data endianness can be changed at runtime,
we do not implement that; only big endianness is used.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/sparc/cpu.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index dd7af86de73..de0386dbf64 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -688,6 +688,20 @@ static void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
qemu_fprintf(f, "\n");
}
+static bool sparc_cpu_datapath_is_big_endian(CPUState *cs)
+{
+#if defined(TARGET_SPARC64)
+ /*
+ * SPARCv9 has a couple of PSTATE bits that set the endianness:
+ * Current Little Endian (PS_CLE) and Trap Little Endian (PS_TLE).
+ * We don't implement that yet.
+ */
+ return true;
+#else
+ return true;
+#endif
+}
+
static void sparc_cpu_set_pc(CPUState *cs, vaddr value)
{
SPARCCPU *cpu = SPARC_CPU(cs);
@@ -958,6 +972,7 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data)
cc->class_by_name = sparc_cpu_class_by_name;
cc->parse_features = sparc_cpu_parse_features;
+ cc->datapath_is_big_endian = sparc_cpu_datapath_is_big_endian;
cc->has_work = sparc_cpu_has_work;
cc->mmu_index = sparc_cpu_mmu_index;
cc->dump_state = sparc_cpu_dump_state;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 07/20] target/riscv: Implement CPUClass::datapath_is_big_endian
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 06/20] target/sparc: " Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 08/20] target/sh4: Expose CPUSH4State::little_endian property Philippe Mathieu-Daudé
` (12 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
While the RISC-V data endianness can be changed at runtime,
we do not implement that. The current translation code assumes
little-endian memory accesses (See commit a2f827ff4f4 "target/riscv:
accessors to registers upper part and 128-bit load/store").
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/riscv/cpu.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index f219f0c3b52..b31b9b3471d 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -60,6 +60,22 @@ bool riscv_cpu_is_32bit(RISCVCPU *cpu)
return riscv_cpu_mxl(&cpu->env) == MXL_RV32;
}
+static bool riscv_cpu_datapath_is_big_endian(CPUState *cs)
+{
+#ifndef CONFIG_USER_ONLY
+ /*
+ * A couple of bits in MSTATUS set the endianness:
+ * - MSTATUS_UBE (User-mode),
+ * - MSTATUS_SBE (Supervisor-mode),
+ * - MSTATUS_MBE (Machine-mode)
+ * but we don't implement that yet.
+ */
+ return false;
+#else
+ return false;
+#endif
+}
+
/* Hash that stores general user set numeric options */
static GHashTable *general_user_opts;
@@ -2764,6 +2780,7 @@ static void riscv_cpu_common_class_init(ObjectClass *c, void *data)
&mcc->parent_phases);
cc->class_by_name = riscv_cpu_class_by_name;
+ cc->datapath_is_big_endian = riscv_cpu_datapath_is_big_endian;
cc->has_work = riscv_cpu_has_work;
cc->mmu_index = riscv_cpu_mmu_index;
cc->dump_state = riscv_cpu_dump_state;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 08/20] target/sh4: Expose CPUSH4State::little_endian property
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 07/20] target/riscv: " Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 09/20] target/sh4: Implement CPUClass::datapath_is_big_endian Philippe Mathieu-Daudé
` (11 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
SH4 CPUs endianness is set with an external pin in a power-on reset.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/sh4/cpu.h | 6 ++++++
target/sh4/cpu.c | 8 ++++++++
2 files changed, 14 insertions(+)
diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h
index d928bcf0067..2502ddba102 100644
--- a/target/sh4/cpu.h
+++ b/target/sh4/cpu.h
@@ -198,6 +198,12 @@ typedef struct CPUArchState {
/* Fields from here on are preserved over CPU reset. */
int id; /* CPU model */
+ /*
+ * The endian is set with an external pin in a power-on reset.
+ * The endian cannot be changed dynamically.
+ */
+ bool little_endian;
+
/* The features that we should emulate. See sh_features above. */
uint32_t features;
diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index 8f07261dcfd..f54005644c9 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -23,6 +23,7 @@
#include "qapi/error.h"
#include "qemu/qemu-print.h"
#include "cpu.h"
+#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
#include "exec/exec-all.h"
#include "fpu/softfloat-helpers.h"
@@ -231,6 +232,12 @@ static void superh_cpu_initfn(Object *obj)
env->movcal_backup_tail = &(env->movcal_backup);
}
+static Property superh_cpu_properties[] = {
+ DEFINE_PROP_BOOL("little-endian", SuperHCPU,
+ env.little_endian, !TARGET_BIG_ENDIAN),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
#ifndef CONFIG_USER_ONLY
static const VMStateDescription vmstate_sh_cpu = {
.name = "cpu",
@@ -270,6 +277,7 @@ static void superh_cpu_class_init(ObjectClass *oc, void *data)
device_class_set_parent_realize(dc, superh_cpu_realizefn,
&scc->parent_realize);
+ device_class_set_props(dc, superh_cpu_properties);
resettable_class_set_parent_phases(rc, NULL, superh_cpu_reset_hold, NULL,
&scc->parent_phases);
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 09/20] target/sh4: Implement CPUClass::datapath_is_big_endian
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (7 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 08/20] target/sh4: Expose CPUSH4State::little_endian property Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 10/20] target/microblaze: " Philippe Mathieu-Daudé
` (10 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
Implement SH4 datapath_is_big_endian() helper, returning
the 'little_endian' property set at reset.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/sh4/cpu.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index f54005644c9..69108c1676e 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -29,6 +29,13 @@
#include "fpu/softfloat-helpers.h"
#include "tcg/tcg.h"
+static bool superh_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ SuperHCPU *cpu = SUPERH_CPU(cs);
+
+ return !cpu->env.little_endian;
+}
+
static void superh_cpu_set_pc(CPUState *cs, vaddr value)
{
SuperHCPU *cpu = SUPERH_CPU(cs);
@@ -283,6 +290,7 @@ static void superh_cpu_class_init(ObjectClass *oc, void *data)
&scc->parent_phases);
cc->class_by_name = superh_cpu_class_by_name;
+ cc->datapath_is_big_endian = superh_cpu_datapath_is_big_endian;
cc->has_work = superh_cpu_has_work;
cc->mmu_index = sh4_cpu_mmu_index;
cc->dump_state = superh_cpu_dump_state;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 10/20] target/microblaze: Implement CPUClass::datapath_is_big_endian
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (8 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 09/20] target/sh4: Implement CPUClass::datapath_is_big_endian Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 11/20] target/mips: " Philippe Mathieu-Daudé
` (9 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
Implement the MicroBlaze datapath_is_big_endian() handler,
returning the value of the ENDI bit.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/microblaze/cpu.h | 2 ++
target/microblaze/cpu.c | 11 +++++++++++
2 files changed, 13 insertions(+)
diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h
index 3e5a3e5c605..dd6b61b34ba 100644
--- a/target/microblaze/cpu.h
+++ b/target/microblaze/cpu.h
@@ -412,6 +412,8 @@ void mb_tcg_init(void);
/* Ensure there is no overlap between the two masks. */
QEMU_BUILD_BUG_ON(MSR_TB_MASK & IFLAGS_TB_MASK);
+bool mb_cpu_datapath_is_big_endian(CPUState *cs);
+
static inline void cpu_get_tb_cpu_state(CPUMBState *env, vaddr *pc,
uint64_t *cs_base, uint32_t *flags)
{
diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index 710eb1146c1..3a0e5713415 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -26,6 +26,7 @@
#include "qapi/error.h"
#include "cpu.h"
#include "qemu/module.h"
+#include "sysemu/hw_accel.h"
#include "hw/qdev-properties.h"
#include "exec/exec-all.h"
#include "exec/cpu_ldst.h"
@@ -119,6 +120,15 @@ static bool mb_cpu_has_work(CPUState *cs)
return cs->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI);
}
+bool mb_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
+
+ cpu_synchronize_state(cs);
+
+ return !cpu->cfg.endi;
+}
+
static int mb_cpu_mmu_index(CPUState *cs, bool ifetch)
{
CPUMBState *env = cpu_env(cs);
@@ -447,6 +457,7 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
&mcc->parent_phases);
cc->class_by_name = mb_cpu_class_by_name;
+ cc->datapath_is_big_endian = mb_cpu_datapath_is_big_endian;
cc->has_work = mb_cpu_has_work;
cc->mmu_index = mb_cpu_mmu_index;
cc->dump_state = mb_cpu_dump_state;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 11/20] target/mips: Implement CPUClass::datapath_is_big_endian
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (9 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 10/20] target/microblaze: " Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 12/20] target/xtensa: Implement xtensa_isa_is_big_endian() Philippe Mathieu-Daudé
` (8 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
Implement MIPS datapath_is_big_endian() handler using
the already existing mips_env_is_bigendian() method.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/mips/cpu.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index d0a43b6d5c7..13d0ceaa8af 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -27,6 +27,7 @@
#include "internal.h"
#include "kvm_mips.h"
#include "qemu/module.h"
+#include "sysemu/hw_accel.h"
#include "sysemu/kvm.h"
#include "sysemu/qtest.h"
#include "exec/exec-all.h"
@@ -132,6 +133,13 @@ static vaddr mips_cpu_get_pc(CPUState *cs)
return cpu->env.active_tc.PC;
}
+static bool mips_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ cpu_synchronize_state(cs);
+
+ return mips_env_is_bigendian(cpu_env(cs));
+}
+
static bool mips_cpu_has_work(CPUState *cs)
{
CPUMIPSState *env = cpu_env(cs);
@@ -581,6 +589,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data)
&mcc->parent_phases);
cc->class_by_name = mips_cpu_class_by_name;
+ cc->datapath_is_big_endian = mips_cpu_datapath_is_big_endian;
cc->has_work = mips_cpu_has_work;
cc->mmu_index = mips_cpu_mmu_index;
cc->dump_state = mips_cpu_dump_state;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 12/20] target/xtensa: Implement xtensa_isa_is_big_endian()
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (10 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 11/20] target/mips: " Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 13/20] target/xtensa: Implement CPUClass::datapath_is_big_endian Philippe Mathieu-Daudé
` (7 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
Xtensa internal fields are opaque, only accessible by
the Xtensa libisa. Implement xtensa_isa_is_big_endian()
to get vCPU endianness. This should be implemented in
libisa, not QEMU, but I couldn't figure out where to
contribute this.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/xtensa/xtensa-isa.h | 1 +
target/xtensa/xtensa-isa.c | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/include/hw/xtensa/xtensa-isa.h b/include/hw/xtensa/xtensa-isa.h
index a289531bdc8..1cb8e6ccb66 100644
--- a/include/hw/xtensa/xtensa-isa.h
+++ b/include/hw/xtensa/xtensa-isa.h
@@ -829,6 +829,7 @@ const char *xtensa_funcUnit_name(xtensa_isa isa, xtensa_funcUnit fun);
int xtensa_funcUnit_num_copies(xtensa_isa isa, xtensa_funcUnit fun);
+bool xtensa_isa_is_big_endian(xtensa_isa isa);
#ifdef __cplusplus
}
diff --git a/target/xtensa/xtensa-isa.c b/target/xtensa/xtensa-isa.c
index 630b4f9da1b..36eb4bcf3d4 100644
--- a/target/xtensa/xtensa-isa.c
+++ b/target/xtensa/xtensa-isa.c
@@ -1741,3 +1741,10 @@ int xtensa_funcUnit_num_copies(xtensa_isa isa, xtensa_funcUnit fun)
CHECK_FUNCUNIT(intisa, fun, XTENSA_UNDEFINED);
return intisa->funcUnits[fun].num_copies;
}
+
+bool xtensa_isa_is_big_endian(xtensa_isa isa)
+{
+ xtensa_isa_internal *intisa = (xtensa_isa_internal *)isa;
+
+ return intisa->is_big_endian;
+}
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 13/20] target/xtensa: Implement CPUClass::datapath_is_big_endian
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (11 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 12/20] target/xtensa: Implement xtensa_isa_is_big_endian() Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 14/20] target: Implement CPUClass::datapath_is_big_endian (little-endian) Philippe Mathieu-Daudé
` (6 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
Implement Xtensa datapath_is_big_endian() helper via libisa.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
Other accesses to xtensa_isa_internal fields don't
call cpu_synchronize_state(), and the libisa doesn't
provide a way to switch endianness from translation
code. Should we add a sync just in case?
---
target/xtensa/cpu.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
index 6f9039abaee..7bf792fd0f4 100644
--- a/target/xtensa/cpu.c
+++ b/target/xtensa/cpu.c
@@ -40,6 +40,13 @@
#endif
+static bool xtensa_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ CPUXtensaState *env = cpu_env(cs);
+
+ return xtensa_isa_is_big_endian(env->config->isa);
+}
+
static void xtensa_cpu_set_pc(CPUState *cs, vaddr value)
{
XtensaCPU *cpu = XTENSA_CPU(cs);
@@ -256,6 +263,7 @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data)
&xcc->parent_phases);
cc->class_by_name = xtensa_cpu_class_by_name;
+ cc->datapath_is_big_endian = xtensa_cpu_datapath_is_big_endian;
cc->has_work = xtensa_cpu_has_work;
cc->mmu_index = xtensa_cpu_mmu_index;
cc->dump_state = xtensa_cpu_dump_state;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 14/20] target: Implement CPUClass::datapath_is_big_endian (little-endian)
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (12 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 13/20] target/xtensa: Implement CPUClass::datapath_is_big_endian Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 15/20] target: Implement CPUClass::datapath_is_big_endian (big-endian) Philippe Mathieu-Daudé
` (5 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
For all targets which have endianness architecturally
predefined as little endian (built using TARGET_BIG_ENDIAN=n),
their datapath_is_big_endian() handler simply returns %false.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/alpha/cpu.c | 6 ++++++
target/avr/cpu.c | 7 ++++++-
target/i386/cpu.c | 6 ++++++
target/loongarch/cpu.c | 6 ++++++
target/tricore/cpu.c | 6 ++++++
5 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
index 5d75c941f7a..ee844a4c455 100644
--- a/target/alpha/cpu.c
+++ b/target/alpha/cpu.c
@@ -27,6 +27,11 @@
#include "fpu/softfloat.h"
+static bool alpha_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ return false;
+}
+
static void alpha_cpu_set_pc(CPUState *cs, vaddr value)
{
CPUAlphaState *env = cpu_env(cs);
@@ -247,6 +252,7 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data)
&acc->parent_realize);
cc->class_by_name = alpha_cpu_class_by_name;
+ cc->datapath_is_big_endian = alpha_cpu_datapath_is_big_endian;
cc->has_work = alpha_cpu_has_work;
cc->mmu_index = alpha_cpu_mmu_index;
cc->dump_state = alpha_cpu_dump_state;
diff --git a/target/avr/cpu.c b/target/avr/cpu.c
index 3132842d565..f32f1bee61f 100644
--- a/target/avr/cpu.c
+++ b/target/avr/cpu.c
@@ -159,6 +159,11 @@ static ObjectClass *avr_cpu_class_by_name(const char *cpu_model)
return object_class_by_name(cpu_model);
}
+static bool avr_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ return false;
+}
+
static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags)
{
CPUAVRState *env = cpu_env(cs);
@@ -230,7 +235,7 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
&mcc->parent_phases);
cc->class_by_name = avr_cpu_class_by_name;
-
+ cc->datapath_is_big_endian = avr_cpu_datapath_is_big_endian;
cc->has_work = avr_cpu_has_work;
cc->mmu_index = avr_cpu_mmu_index;
cc->dump_state = avr_cpu_dump_state;
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 3725dbbc4b3..f783d311579 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -2008,6 +2008,11 @@ static char *x86_cpu_class_get_model_name(X86CPUClass *cc)
return cpu_model_from_type(class_name);
}
+static bool x86_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ return false;
+}
+
typedef struct X86CPUVersionDefinition {
X86CPUVersion version;
const char *alias;
@@ -8588,6 +8593,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
cc->class_by_name = x86_cpu_class_by_name;
cc->parse_features = x86_cpu_parse_featurestr;
+ cc->datapath_is_big_endian = x86_cpu_datapath_is_big_endian;
cc->has_work = x86_cpu_has_work;
cc->mmu_index = x86_cpu_mmu_index;
cc->dump_state = x86_cpu_dump_state;
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 57cc4f314bf..b9cf0091546 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -742,6 +742,11 @@ static ObjectClass *loongarch_cpu_class_by_name(const char *cpu_model)
return oc;
}
+static bool loongarch_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ return false;
+}
+
void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags)
{
CPULoongArchState *env = cpu_env(cs);
@@ -836,6 +841,7 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)
&lacc->parent_phases);
cc->class_by_name = loongarch_cpu_class_by_name;
+ cc->datapath_is_big_endian = loongarch_cpu_datapath_is_big_endian;
cc->has_work = loongarch_cpu_has_work;
cc->mmu_index = loongarch_cpu_mmu_index;
cc->dump_state = loongarch_cpu_dump_state;
diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index 1a261715907..ba53d83f662 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -29,6 +29,11 @@ static inline void set_feature(CPUTriCoreState *env, int feature)
env->features |= 1ULL << feature;
}
+static bool tricore_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ return false;
+}
+
static const gchar *tricore_gdb_arch_name(CPUState *cs)
{
return "tricore";
@@ -191,6 +196,7 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data)
resettable_class_set_parent_phases(rc, NULL, tricore_cpu_reset_hold, NULL,
&mcc->parent_phases);
cc->class_by_name = tricore_cpu_class_by_name;
+ cc->datapath_is_big_endian = tricore_cpu_datapath_is_big_endian;
cc->has_work = tricore_cpu_has_work;
cc->mmu_index = tricore_cpu_mmu_index;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 15/20] target: Implement CPUClass::datapath_is_big_endian (big-endian)
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (13 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 14/20] target: Implement CPUClass::datapath_is_big_endian (little-endian) Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-09 20:21 ` Brian Cain
2024-12-04 20:25 ` [PATCH 16/20] hw/core/cpu: Expose cpu_datapath_is_big_endian() method Philippe Mathieu-Daudé
` (4 subsequent siblings)
19 siblings, 1 reply; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
For all targets which have endianness architecturally
predefined as big endian (built using TARGET_BIG_ENDIAN=y),
their datapath_is_big_endian() handler simply returns %true.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/hexagon/cpu.c | 6 ++++++
target/hppa/cpu.c | 6 ++++++
target/m68k/cpu.c | 6 ++++++
target/openrisc/cpu.c | 6 ++++++
target/s390x/cpu.c | 6 ++++++
5 files changed, 30 insertions(+)
diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 020038fc490..6407ed80c59 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -245,6 +245,11 @@ void hexagon_debug(CPUHexagonState *env)
hexagon_dump(env, stdout, CPU_DUMP_FPU);
}
+static bool hexagon_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ return true;
+}
+
static void hexagon_cpu_set_pc(CPUState *cs, vaddr value)
{
cpu_env(cs)->gpr[HEX_REG_PC] = value;
@@ -342,6 +347,7 @@ static void hexagon_cpu_class_init(ObjectClass *c, void *data)
&mcc->parent_phases);
cc->class_by_name = hexagon_cpu_class_by_name;
+ cc->datapath_is_big_endian = hexagon_cpu_datapath_is_big_endian;
cc->has_work = hexagon_cpu_has_work;
cc->dump_state = hexagon_dump_state;
cc->set_pc = hexagon_cpu_set_pc;
diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c
index c38439c1800..8ccd224f2a4 100644
--- a/target/hppa/cpu.c
+++ b/target/hppa/cpu.c
@@ -203,6 +203,11 @@ static void hppa_cpu_initfn(Object *obj)
cpu_hppa_put_psw(env, PSW_W);
}
+static bool hppa_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ return true;
+}
+
static ObjectClass *hppa_cpu_class_by_name(const char *cpu_model)
{
g_autofree char *typename = g_strconcat(cpu_model, "-cpu", NULL);
@@ -245,6 +250,7 @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data)
&acc->parent_realize);
cc->class_by_name = hppa_cpu_class_by_name;
+ cc->datapath_is_big_endian = hppa_cpu_datapath_is_big_endian;
cc->has_work = hppa_cpu_has_work;
cc->mmu_index = hppa_cpu_mmu_index;
cc->dump_state = hppa_cpu_dump_state;
diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index 5fe335558aa..52f8db41d5a 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -24,6 +24,11 @@
#include "migration/vmstate.h"
#include "fpu/softfloat.h"
+static bool m68k_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ return true;
+}
+
static void m68k_cpu_set_pc(CPUState *cs, vaddr value)
{
M68kCPU *cpu = M68K_CPU(cs);
@@ -571,6 +576,7 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
&mcc->parent_phases);
cc->class_by_name = m68k_cpu_class_by_name;
+ cc->datapath_is_big_endian = m68k_cpu_datapath_is_big_endian;
cc->has_work = m68k_cpu_has_work;
cc->mmu_index = m68k_cpu_mmu_index;
cc->dump_state = m68k_cpu_dump_state;
diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c
index b96561d1f26..16e39b43ec4 100644
--- a/target/openrisc/cpu.c
+++ b/target/openrisc/cpu.c
@@ -25,6 +25,11 @@
#include "fpu/softfloat-helpers.h"
#include "tcg/tcg.h"
+static bool openrisc_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ return true;
+}
+
static void openrisc_cpu_set_pc(CPUState *cs, vaddr value)
{
OpenRISCCPU *cpu = OPENRISC_CPU(cs);
@@ -257,6 +262,7 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
&occ->parent_phases);
cc->class_by_name = openrisc_cpu_class_by_name;
+ cc->datapath_is_big_endian = openrisc_cpu_datapath_is_big_endian;
cc->has_work = openrisc_cpu_has_work;
cc->mmu_index = openrisc_cpu_mmu_index;
cc->dump_state = openrisc_cpu_dump_state;
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 514c70f3010..eda1e3b286f 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -44,6 +44,11 @@
#define CR0_RESET 0xE0UL
#define CR14_RESET 0xC2000000UL;
+static bool s390_cpu_datapath_is_big_endian(CPUState *cs)
+{
+ return true;
+}
+
#ifndef CONFIG_USER_ONLY
static bool is_early_exception_psw(uint64_t mask, uint64_t addr)
{
@@ -390,6 +395,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
&scc->parent_phases);
cc->class_by_name = s390_cpu_class_by_name,
+ cc->datapath_is_big_endian = s390_cpu_datapath_is_big_endian;
cc->has_work = s390_cpu_has_work;
cc->mmu_index = s390x_cpu_mmu_index;
cc->dump_state = s390_cpu_dump_state;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 15/20] target: Implement CPUClass::datapath_is_big_endian (big-endian)
2024-12-04 20:25 ` [PATCH 15/20] target: Implement CPUClass::datapath_is_big_endian (big-endian) Philippe Mathieu-Daudé
@ 2024-12-09 20:21 ` Brian Cain
0 siblings, 0 replies; 27+ messages in thread
From: Brian Cain @ 2024-12-09 20:21 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson
On 12/4/2024 2:25 PM, Philippe Mathieu-Daudé wrote:
> For all targets which have endianness architecturally
> predefined as big endian (built using TARGET_BIG_ENDIAN=y),
> their datapath_is_big_endian() handler simply returns %true.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/hexagon/cpu.c | 6 ++++++
> target/hppa/cpu.c | 6 ++++++
> target/m68k/cpu.c | 6 ++++++
> target/openrisc/cpu.c | 6 ++++++
> target/s390x/cpu.c | 6 ++++++
> 5 files changed, 30 insertions(+)
>
> diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
> index 020038fc490..6407ed80c59 100644
> --- a/target/hexagon/cpu.c
> +++ b/target/hexagon/cpu.c
> @@ -245,6 +245,11 @@ void hexagon_debug(CPUHexagonState *env)
> hexagon_dump(env, stdout, CPU_DUMP_FPU);
> }
>
> +static bool hexagon_cpu_datapath_is_big_endian(CPUState *cs)
> +{
> + return true;
> +}
> +
> static void hexagon_cpu_set_pc(CPUState *cs, vaddr value)
> {
> cpu_env(cs)->gpr[HEX_REG_PC] = value;
> @@ -342,6 +347,7 @@ static void hexagon_cpu_class_init(ObjectClass *c, void *data)
> &mcc->parent_phases);
>
> cc->class_by_name = hexagon_cpu_class_by_name;
> + cc->datapath_is_big_endian = hexagon_cpu_datapath_is_big_endian;
> cc->has_work = hexagon_cpu_has_work;
> cc->dump_state = hexagon_dump_state;
> cc->set_pc = hexagon_cpu_set_pc;
For hexagon:
Reviewed-by: Brian Cain <brian.cain@oss.qualcomm.com>
> diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c
> index c38439c1800..8ccd224f2a4 100644
> --- a/target/hppa/cpu.c
> +++ b/target/hppa/cpu.c
> @@ -203,6 +203,11 @@ static void hppa_cpu_initfn(Object *obj)
> cpu_hppa_put_psw(env, PSW_W);
> }
>
> +static bool hppa_cpu_datapath_is_big_endian(CPUState *cs)
> +{
> + return true;
> +}
> +
> static ObjectClass *hppa_cpu_class_by_name(const char *cpu_model)
> {
> g_autofree char *typename = g_strconcat(cpu_model, "-cpu", NULL);
> @@ -245,6 +250,7 @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data)
> &acc->parent_realize);
>
> cc->class_by_name = hppa_cpu_class_by_name;
> + cc->datapath_is_big_endian = hppa_cpu_datapath_is_big_endian;
> cc->has_work = hppa_cpu_has_work;
> cc->mmu_index = hppa_cpu_mmu_index;
> cc->dump_state = hppa_cpu_dump_state;
> diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
> index 5fe335558aa..52f8db41d5a 100644
> --- a/target/m68k/cpu.c
> +++ b/target/m68k/cpu.c
> @@ -24,6 +24,11 @@
> #include "migration/vmstate.h"
> #include "fpu/softfloat.h"
>
> +static bool m68k_cpu_datapath_is_big_endian(CPUState *cs)
> +{
> + return true;
> +}
> +
> static void m68k_cpu_set_pc(CPUState *cs, vaddr value)
> {
> M68kCPU *cpu = M68K_CPU(cs);
> @@ -571,6 +576,7 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
> &mcc->parent_phases);
>
> cc->class_by_name = m68k_cpu_class_by_name;
> + cc->datapath_is_big_endian = m68k_cpu_datapath_is_big_endian;
> cc->has_work = m68k_cpu_has_work;
> cc->mmu_index = m68k_cpu_mmu_index;
> cc->dump_state = m68k_cpu_dump_state;
> diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c
> index b96561d1f26..16e39b43ec4 100644
> --- a/target/openrisc/cpu.c
> +++ b/target/openrisc/cpu.c
> @@ -25,6 +25,11 @@
> #include "fpu/softfloat-helpers.h"
> #include "tcg/tcg.h"
>
> +static bool openrisc_cpu_datapath_is_big_endian(CPUState *cs)
> +{
> + return true;
> +}
> +
> static void openrisc_cpu_set_pc(CPUState *cs, vaddr value)
> {
> OpenRISCCPU *cpu = OPENRISC_CPU(cs);
> @@ -257,6 +262,7 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
> &occ->parent_phases);
>
> cc->class_by_name = openrisc_cpu_class_by_name;
> + cc->datapath_is_big_endian = openrisc_cpu_datapath_is_big_endian;
> cc->has_work = openrisc_cpu_has_work;
> cc->mmu_index = openrisc_cpu_mmu_index;
> cc->dump_state = openrisc_cpu_dump_state;
> diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
> index 514c70f3010..eda1e3b286f 100644
> --- a/target/s390x/cpu.c
> +++ b/target/s390x/cpu.c
> @@ -44,6 +44,11 @@
> #define CR0_RESET 0xE0UL
> #define CR14_RESET 0xC2000000UL;
>
> +static bool s390_cpu_datapath_is_big_endian(CPUState *cs)
> +{
> + return true;
> +}
> +
> #ifndef CONFIG_USER_ONLY
> static bool is_early_exception_psw(uint64_t mask, uint64_t addr)
> {
> @@ -390,6 +395,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
> &scc->parent_phases);
>
> cc->class_by_name = s390_cpu_class_by_name,
> + cc->datapath_is_big_endian = s390_cpu_datapath_is_big_endian;
> cc->has_work = s390_cpu_has_work;
> cc->mmu_index = s390x_cpu_mmu_index;
> cc->dump_state = s390_cpu_dump_state;
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 16/20] hw/core/cpu: Expose cpu_datapath_is_big_endian() method
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (14 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 15/20] target: Implement CPUClass::datapath_is_big_endian (big-endian) Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 20:25 ` [PATCH 17/20] disas: Use cpu_datapath_is_big_endian() Philippe Mathieu-Daudé
` (3 subsequent siblings)
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
All target implement their CPUClass::datapath_is_big_endian()
helper, we can expose the generic cpu_datapath_is_big_endian()
method.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/core/cpu.h | 8 ++++++++
hw/core/cpu-common.c | 7 +++++++
2 files changed, 15 insertions(+)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 91c6581f814..5c75fe3a842 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -611,6 +611,14 @@ extern __thread CPUState *current_cpu;
extern bool mttcg_enabled;
#define qemu_tcg_mttcg_enabled() (mttcg_enabled)
+/**
+ * cpu_datapath_is_big_endian:
+ * @cpu: The CPU whose state is to be inspected.
+ *
+ * Returns: %true if the CPU access data in big endian order, %false otherwise.
+ */
+bool cpu_datapath_is_big_endian(CPUState *cpu);
+
/**
* cpu_paging_enabled:
* @cpu: The CPU whose state is to be inspected.
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 09c79035949..92c0c4c6125 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -66,6 +66,13 @@ CPUState *cpu_create(const char *typename)
return cpu;
}
+bool cpu_datapath_is_big_endian(CPUState *cpu)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ return cc->datapath_is_big_endian(cpu);
+}
+
/* Resetting the IRQ comes from across the code base so we take the
* BQL here if we need to. cpu_interrupt assumes it is held.*/
void cpu_reset_interrupt(CPUState *cpu, int mask)
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 17/20] disas: Use cpu_datapath_is_big_endian()
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (15 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 16/20] hw/core/cpu: Expose cpu_datapath_is_big_endian() method Philippe Mathieu-Daudé
@ 2024-12-04 20:25 ` Philippe Mathieu-Daudé
2024-12-04 23:40 ` Richard Henderson
2024-12-05 10:47 ` Peter Maydell
2024-12-04 20:26 ` [PATCH 18/20] hw/core/generic-loader: " Philippe Mathieu-Daudé
` (2 subsequent siblings)
19 siblings, 2 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:25 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
Rather that using the binary endianness, use the vCPU one.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
disas/disas-common.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/disas/disas-common.c b/disas/disas-common.c
index 7377de0715c..ef91c43449e 100644
--- a/disas/disas-common.c
+++ b/disas/disas-common.c
@@ -7,7 +7,6 @@
#include "disas/disas.h"
#include "disas/capstone.h"
#include "hw/core/cpu.h"
-#include "exec/tswap.h"
#include "disas-internal.h"
@@ -61,7 +60,7 @@ void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu)
s->cpu = cpu;
s->info.print_address_func = print_address;
- if (qemu_binary_is_bigendian()) {
+ if (cpu_datapath_is_big_endian(cpu)) {
s->info.endian = BFD_ENDIAN_BIG;
} else {
s->info.endian = BFD_ENDIAN_LITTLE;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 17/20] disas: Use cpu_datapath_is_big_endian()
2024-12-04 20:25 ` [PATCH 17/20] disas: Use cpu_datapath_is_big_endian() Philippe Mathieu-Daudé
@ 2024-12-04 23:40 ` Richard Henderson
2024-12-05 10:47 ` Peter Maydell
1 sibling, 0 replies; 27+ messages in thread
From: Richard Henderson @ 2024-12-04 23:40 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc
On 12/4/24 14:25, Philippe Mathieu-Daudé wrote:
> Rather that using the binary endianness, use the vCPU one.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> disas/disas-common.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/disas/disas-common.c b/disas/disas-common.c
> index 7377de0715c..ef91c43449e 100644
> --- a/disas/disas-common.c
> +++ b/disas/disas-common.c
> @@ -7,7 +7,6 @@
> #include "disas/disas.h"
> #include "disas/capstone.h"
> #include "hw/core/cpu.h"
> -#include "exec/tswap.h"
> #include "disas-internal.h"
>
>
> @@ -61,7 +60,7 @@ void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu)
>
> s->cpu = cpu;
> s->info.print_address_func = print_address;
> - if (qemu_binary_is_bigendian()) {
> + if (cpu_datapath_is_big_endian(cpu)) {
> s->info.endian = BFD_ENDIAN_BIG;
> } else {
> s->info.endian = BFD_ENDIAN_LITTLE;
I would much rather remove this if statement and force cc->disas_set_info to set this value.
r~
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 17/20] disas: Use cpu_datapath_is_big_endian()
2024-12-04 20:25 ` [PATCH 17/20] disas: Use cpu_datapath_is_big_endian() Philippe Mathieu-Daudé
2024-12-04 23:40 ` Richard Henderson
@ 2024-12-05 10:47 ` Peter Maydell
1 sibling, 0 replies; 27+ messages in thread
From: Peter Maydell @ 2024-12-05 10:47 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Daniel Henrique Barboza, Michael S. Tsirkin,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson
On Wed, 4 Dec 2024 at 20:28, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> Rather that using the binary endianness, use the vCPU one.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> disas/disas-common.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/disas/disas-common.c b/disas/disas-common.c
> index 7377de0715c..ef91c43449e 100644
> --- a/disas/disas-common.c
> +++ b/disas/disas-common.c
> @@ -7,7 +7,6 @@
> #include "disas/disas.h"
> #include "disas/capstone.h"
> #include "hw/core/cpu.h"
> -#include "exec/tswap.h"
> #include "disas-internal.h"
>
>
> @@ -61,7 +60,7 @@ void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu)
>
> s->cpu = cpu;
> s->info.print_address_func = print_address;
> - if (qemu_binary_is_bigendian()) {
> + if (cpu_datapath_is_big_endian(cpu)) {
> s->info.endian = BFD_ENDIAN_BIG;
> } else {
> s->info.endian = BFD_ENDIAN_LITTLE;
> --
This looks weird, but maybe that's just the function naming?
Instruction disassembly is instructions, not data, and the
endianness isn't necessarily the same (e.g. on Armv7 and later
instructions are always little-endian even when data is
big-endian.)
-- PMM
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 18/20] hw/core/generic-loader: Use cpu_datapath_is_big_endian()
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (16 preceding siblings ...)
2024-12-04 20:25 ` [PATCH 17/20] disas: Use cpu_datapath_is_big_endian() Philippe Mathieu-Daudé
@ 2024-12-04 20:26 ` Philippe Mathieu-Daudé
2024-12-05 0:05 ` Richard Henderson
2024-12-04 20:26 ` [RFC PATCH 19/20] hw/virtio: " Philippe Mathieu-Daudé
2024-12-04 20:26 ` [PATCH 20/20] hw/core/cpu: Remove cpu_virtio_is_big_endian() Philippe Mathieu-Daudé
19 siblings, 1 reply; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:26 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
Rather that using the binary endianness, use the vCPU one.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/core/generic-loader.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
index abdd4c08a38..7b3b5f06565 100644
--- a/hw/core/generic-loader.c
+++ b/hw/core/generic-loader.c
@@ -31,7 +31,6 @@
*/
#include "qemu/osdep.h"
-#include "exec/tswap.h"
#include "sysemu/dma.h"
#include "sysemu/reset.h"
#include "hw/boards.h"
@@ -66,7 +65,6 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
{
GenericLoaderState *s = GENERIC_LOADER(dev);
hwaddr entry;
- int big_endian;
ssize_t size = 0;
s->set_pc = false;
@@ -134,14 +132,13 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
s->cpu = first_cpu;
}
- big_endian = qemu_binary_is_bigendian();
-
if (s->file) {
AddressSpace *as = s->cpu ? s->cpu->as : NULL;
if (!s->force_raw) {
size = load_elf_as(s->file, NULL, NULL, NULL, &entry, NULL, NULL,
- NULL, big_endian, 0, 0, 0, as);
+ NULL, cpu_datapath_is_big_endian(s->cpu),
+ 0, 0, 0, as);
if (size < 0) {
size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL,
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 18/20] hw/core/generic-loader: Use cpu_datapath_is_big_endian()
2024-12-04 20:26 ` [PATCH 18/20] hw/core/generic-loader: " Philippe Mathieu-Daudé
@ 2024-12-05 0:05 ` Richard Henderson
0 siblings, 0 replies; 27+ messages in thread
From: Richard Henderson @ 2024-12-05 0:05 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc
On 12/4/24 14:26, Philippe Mathieu-Daudé wrote:
> Rather that using the binary endianness, use the vCPU one.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> hw/core/generic-loader.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
> index abdd4c08a38..7b3b5f06565 100644
> --- a/hw/core/generic-loader.c
> +++ b/hw/core/generic-loader.c
> @@ -31,7 +31,6 @@
> */
>
> #include "qemu/osdep.h"
> -#include "exec/tswap.h"
> #include "sysemu/dma.h"
> #include "sysemu/reset.h"
> #include "hw/boards.h"
> @@ -66,7 +65,6 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
> {
> GenericLoaderState *s = GENERIC_LOADER(dev);
> hwaddr entry;
> - int big_endian;
> ssize_t size = 0;
>
> s->set_pc = false;
> @@ -134,14 +132,13 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
> s->cpu = first_cpu;
> }
>
> - big_endian = qemu_binary_is_bigendian();
> -
> if (s->file) {
> AddressSpace *as = s->cpu ? s->cpu->as : NULL;
>
> if (!s->force_raw) {
> size = load_elf_as(s->file, NULL, NULL, NULL, &entry, NULL, NULL,
> - NULL, big_endian, 0, 0, 0, as);
> + NULL, cpu_datapath_is_big_endian(s->cpu),
> + 0, 0, 0, as);
>
> if (size < 0) {
> size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL,
Given that we're not verifying ehdr.e_machine from the file via the generic-loader, I see
no point in verifying ehdr.e_ident[EI_DATA] either.
I suggest changing load_elf* big_endian parameter to elf_data, then use ELFCLASSNONE to
skip the EI_DATA test. This more or less mirrors the elf_machine parameter -- we use
EM_NONE (0) to skip the e_machine test.
r~
^ permalink raw reply [flat|nested] 27+ messages in thread
* [RFC PATCH 19/20] hw/virtio: Use cpu_datapath_is_big_endian()
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (17 preceding siblings ...)
2024-12-04 20:26 ` [PATCH 18/20] hw/core/generic-loader: " Philippe Mathieu-Daudé
@ 2024-12-04 20:26 ` Philippe Mathieu-Daudé
2024-12-04 20:26 ` [PATCH 20/20] hw/core/cpu: Remove cpu_virtio_is_big_endian() Philippe Mathieu-Daudé
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:26 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
Rather that using the binary endianness, use the vCPU one.
The target affected by this change are MIPS, MicroBlaze, SH-4
and Xtensa. SPARC, RISC-V and RX could be affected later if
their CPUClass::datapath_is_big_endian() handler is fully
implemented.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/virtio/virtio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index b3dede476ed..c57845a16db 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2257,7 +2257,7 @@ static enum virtio_device_endian virtio_default_endian(void)
static enum virtio_device_endian virtio_current_cpu_endian(void)
{
- if (cpu_virtio_is_big_endian(current_cpu)) {
+ if (cpu_datapath_is_big_endian(current_cpu)) {
return VIRTIO_DEVICE_ENDIAN_BIG;
} else {
return VIRTIO_DEVICE_ENDIAN_LITTLE;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 20/20] hw/core/cpu: Remove cpu_virtio_is_big_endian()
2024-12-04 20:25 [PATCH 00/20] target: Implement CPUClass::datapath_is_big_endian() handlers Philippe Mathieu-Daudé
` (18 preceding siblings ...)
2024-12-04 20:26 ` [RFC PATCH 19/20] hw/virtio: " Philippe Mathieu-Daudé
@ 2024-12-04 20:26 ` Philippe Mathieu-Daudé
19 siblings, 0 replies; 27+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-12-04 20:26 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel Henrique Barboza, Michael S. Tsirkin, Peter Maydell,
Laurent Vivier, Mark Cave-Ayland, Alistair Francis,
Anton Johansson, Zhao Liu, Edgar E. Iglesias, David Hildenbrand,
qemu-s390x, Max Filippov, Paolo Bonzini, Nicholas Piggin,
qemu-arm, Thomas Huth, qemu-riscv, Alistair Francis, qemu-ppc,
Richard Henderson, Philippe Mathieu-Daudé
There are no more calls to cpu_virtio_is_big_endian().
Remove the method and the SysemuCPUOps::virtio_is_big_endian
helpers altogether.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/core/cpu.h | 9 ---------
include/hw/core/sysemu-cpu-ops.h | 8 --------
hw/core/cpu-sysemu.c | 11 -----------
target/arm/cpu.c | 1 -
target/ppc/cpu_init.c | 1 -
5 files changed, 30 deletions(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 5c75fe3a842..21b49800f52 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -752,15 +752,6 @@ hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
*/
int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs);
-/**
- * cpu_virtio_is_big_endian:
- * @cpu: CPU
-
- * Returns %true if a CPU which supports runtime configurable endianness
- * is currently big-endian.
- */
-bool cpu_virtio_is_big_endian(CPUState *cpu);
-
#endif /* !CONFIG_USER_ONLY */
/**
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
index 24d003fe041..9806a2b7ecb 100644
--- a/include/hw/core/sysemu-cpu-ops.h
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -72,14 +72,6 @@ typedef struct SysemuCPUOps {
*/
int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
DumpState *s);
- /**
- * @virtio_is_big_endian: Callback to return %true if a CPU which supports
- * runtime configurable endianness is currently big-endian.
- * Non-configurable CPUs can use the default implementation of this method.
- * This method should not be used by any callers other than the pre-1.0
- * virtio devices.
- */
- bool (*virtio_is_big_endian)(CPUState *cpu);
/**
* @legacy_vmsd: Legacy state for migration.
diff --git a/hw/core/cpu-sysemu.c b/hw/core/cpu-sysemu.c
index 4b85face02b..458dde692ec 100644
--- a/hw/core/cpu-sysemu.c
+++ b/hw/core/cpu-sysemu.c
@@ -20,7 +20,6 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
-#include "exec/tswap.h"
#include "hw/core/sysemu-cpu-ops.h"
bool cpu_paging_enabled(const CPUState *cpu)
@@ -122,16 +121,6 @@ int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
return (*cc->sysemu_ops->write_elf64_note)(f, cpu, cpuid, opaque);
}
-bool cpu_virtio_is_big_endian(CPUState *cpu)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- if (cc->sysemu_ops->virtio_is_big_endian) {
- return cc->sysemu_ops->virtio_is_big_endian(cpu);
- }
- return qemu_binary_is_bigendian();
-}
-
GuestPanicInformation *cpu_get_crash_info(CPUState *cpu)
{
CPUClass *cc = CPU_GET_CLASS(cpu);
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 3061b2ac18c..0df6408ee73 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -2664,7 +2664,6 @@ static const struct SysemuCPUOps arm_sysemu_ops = {
.asidx_from_attrs = arm_asidx_from_attrs,
.write_elf32_note = arm_cpu_write_elf32_note,
.write_elf64_note = arm_cpu_write_elf64_note,
- .virtio_is_big_endian = arm_cpu_datapath_is_big_endian,
.legacy_vmsd = &vmstate_arm_cpu,
};
#endif
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index 9650acb4850..be0eea2ff2e 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -7407,7 +7407,6 @@ static const struct SysemuCPUOps ppc_sysemu_ops = {
.get_phys_page_debug = ppc_cpu_get_phys_page_debug,
.write_elf32_note = ppc32_cpu_write_elf32_note,
.write_elf64_note = ppc64_cpu_write_elf64_note,
- .virtio_is_big_endian = ppc_cpu_datapath_is_big_endian,
.legacy_vmsd = &vmstate_ppc_cpu,
};
#endif
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread