* [PATCH 0/8] hw/core/cpu: Expose cpu_is_big_endian() method
@ 2024-10-04 16:21 Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 1/8] exec/tswap: Massage target_needs_bswap() definition Philippe Mathieu-Daudé
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-04 16:21 UTC (permalink / raw)
To: qemu-devel
Cc: Aurelien Jarno, Eduardo Habkost, Yanan Wang, Edgar E. Iglesias,
qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Philippe Mathieu-Daudé,
Nicholas Piggin, qemu-arm, Zhao Liu, Peter Maydell, Jiaxun Yang
Introduce CPUClass::is_big_endian() handler and expose
the cpu_is_big_endian() method. This will be useful later
when endianness will be propagated in the slow paths,
allowing removal of various TARGET_BIG_ENDIAN uses.
Philippe Mathieu-Daudé (8):
exec/tswap: Massage target_needs_bswap() definition
hw/core/cpu: Introduce CPUClass::is_big_endian() handler
target/arm: Implement CPUClass::is_big_endian
target/microblaze: Implement CPUClass::is_big_endian
target/mips: Declare mips_env_is_bigendian() in 'internal.h'
target/mips: Implement CPUClass::is_big_endian
target/ppc: Register CPUClass::is_big_endian
hw/core/cpu: Expose cpu_is_big_endian() method
include/exec/tswap.h | 2 +-
include/hw/core/cpu.h | 11 ++++++++++-
target/mips/internal.h | 5 +++++
hw/core/cpu-common.c | 14 ++++++++++++++
target/arm/cpu.c | 6 ++++++
target/microblaze/cpu.c | 8 ++++++++
target/mips/cpu.c | 6 ++++++
target/mips/tcg/ldst_helper.c | 15 +++++----------
target/ppc/cpu_init.c | 5 +++--
9 files changed, 58 insertions(+), 14 deletions(-)
--
2.45.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/8] exec/tswap: Massage target_needs_bswap() definition
2024-10-04 16:21 [PATCH 0/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
@ 2024-10-04 16:21 ` Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 2/8] hw/core/cpu: Introduce CPUClass::is_big_endian() handler Philippe Mathieu-Daudé
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-04 16:21 UTC (permalink / raw)
To: qemu-devel
Cc: Aurelien Jarno, Eduardo Habkost, Yanan Wang, Edgar E. Iglesias,
qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Philippe Mathieu-Daudé,
Nicholas Piggin, qemu-arm, Zhao Liu, Peter Maydell, Jiaxun Yang
Invert target_needs_bswap() comparison to match the
COMPILING_PER_TARGET definition (2 lines upper).
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/exec/tswap.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/exec/tswap.h b/include/exec/tswap.h
index b7a41913475..ecd4faef015 100644
--- a/include/exec/tswap.h
+++ b/include/exec/tswap.h
@@ -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() (target_words_bigendian() != HOST_BIG_ENDIAN)
+#define target_needs_bswap() (HOST_BIG_ENDIAN != target_words_bigendian())
#endif /* COMPILING_PER_TARGET */
static inline uint16_t tswap16(uint16_t s)
--
2.45.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/8] hw/core/cpu: Introduce CPUClass::is_big_endian() handler
2024-10-04 16:21 [PATCH 0/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 1/8] exec/tswap: Massage target_needs_bswap() definition Philippe Mathieu-Daudé
@ 2024-10-04 16:21 ` Philippe Mathieu-Daudé
2024-10-04 16:41 ` Peter Maydell
2024-10-04 16:21 ` [PATCH 3/8] target/arm: Implement CPUClass::is_big_endian Philippe Mathieu-Daudé
` (5 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-04 16:21 UTC (permalink / raw)
To: qemu-devel
Cc: Aurelien Jarno, Eduardo Habkost, Yanan Wang, Edgar E. Iglesias,
qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Philippe Mathieu-Daudé,
Nicholas Piggin, qemu-arm, Zhao Liu, Peter Maydell, Jiaxun Yang
Introduce the CPUClass::is_big_endian() handler and its
common default.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/core/cpu.h | 3 ++-
hw/core/cpu-common.c | 7 +++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 04e9ad49968..22ef7a44e86 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -150,6 +150,7 @@ struct CPUClass {
ObjectClass *(*class_by_name)(const char *cpu_model);
void (*parse_features)(const char *typename, char *str, Error **errp);
+ bool (*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,
@@ -749,7 +750,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:
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 7982ecd39a5..aa5ea9761e4 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -26,6 +26,7 @@
#include "qemu/main-loop.h"
#include "exec/log.h"
#include "exec/gdbstub.h"
+#include "exec/tswap.h"
#include "sysemu/tcg.h"
#include "hw/boards.h"
#include "hw/qdev-properties.h"
@@ -138,6 +139,11 @@ static void cpu_common_reset_hold(Object *obj, ResetType type)
cpu_exec_reset_hold(cpu);
}
+static bool cpu_common_is_big_endian(CPUState *cs)
+{
+ return target_words_bigendian();
+}
+
static bool cpu_common_has_work(CPUState *cs)
{
return false;
@@ -306,6 +312,7 @@ static void cpu_common_class_init(ObjectClass *klass, void *data)
k->parse_features = cpu_common_parse_features;
k->get_arch_id = cpu_common_get_arch_id;
+ k->is_big_endian = cpu_common_is_big_endian;
k->has_work = cpu_common_has_work;
k->gdb_read_register = cpu_common_gdb_read_register;
k->gdb_write_register = cpu_common_gdb_write_register;
--
2.45.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/8] target/arm: Implement CPUClass::is_big_endian
2024-10-04 16:21 [PATCH 0/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 1/8] exec/tswap: Massage target_needs_bswap() definition Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 2/8] hw/core/cpu: Introduce CPUClass::is_big_endian() handler Philippe Mathieu-Daudé
@ 2024-10-04 16:21 ` Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 4/8] target/microblaze: " Philippe Mathieu-Daudé
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-04 16:21 UTC (permalink / raw)
To: qemu-devel
Cc: Aurelien Jarno, Eduardo Habkost, Yanan Wang, Edgar E. Iglesias,
qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Philippe Mathieu-Daudé,
Nicholas Piggin, qemu-arm, Zhao Liu, Peter Maydell, Jiaxun Yang
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/arm/cpu.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 19191c23918..2bb87a9299f 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -122,6 +122,11 @@ void arm_restore_state_to_opc(CPUState *cs,
}
#endif /* CONFIG_TCG */
+static bool arm_cpu_is_big_endian(CPUState *cs)
+{
+ return arm_cpu_data_is_big_endian(cpu_env(cs));
+}
+
/*
* With SCTLR_ELx.NMI == 0, IRQ with Superpriority is masked identically with
* IRQ without Superpriority. Moreover, if the GIC is configured so that
@@ -2692,6 +2697,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
&acc->parent_phases);
cc->class_by_name = arm_cpu_class_by_name;
+ cc->is_big_endian = arm_cpu_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] 12+ messages in thread
* [PATCH 4/8] target/microblaze: Implement CPUClass::is_big_endian
2024-10-04 16:21 [PATCH 0/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2024-10-04 16:21 ` [PATCH 3/8] target/arm: Implement CPUClass::is_big_endian Philippe Mathieu-Daudé
@ 2024-10-04 16:21 ` Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 5/8] target/mips: Declare mips_env_is_bigendian() in 'internal.h' Philippe Mathieu-Daudé
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-04 16:21 UTC (permalink / raw)
To: qemu-devel
Cc: Aurelien Jarno, Eduardo Habkost, Yanan Wang, Edgar E. Iglesias,
qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Philippe Mathieu-Daudé,
Nicholas Piggin, qemu-arm, Zhao Liu, Peter Maydell, Jiaxun Yang
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/microblaze/cpu.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index 135947ee800..93c0c6d36c8 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -119,6 +119,13 @@ static bool mb_cpu_has_work(CPUState *cs)
return cs->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI);
}
+static bool mb_cpu_is_big_endian(CPUState *cs)
+{
+ MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
+
+ return !cpu->cfg.endi;
+}
+
static int mb_cpu_mmu_index(CPUState *cs, bool ifetch)
{
CPUMBState *env = cpu_env(cs);
@@ -433,6 +440,7 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
&mcc->parent_phases);
cc->class_by_name = mb_cpu_class_by_name;
+ cc->is_big_endian = mb_cpu_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] 12+ messages in thread
* [PATCH 5/8] target/mips: Declare mips_env_is_bigendian() in 'internal.h'
2024-10-04 16:21 [PATCH 0/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2024-10-04 16:21 ` [PATCH 4/8] target/microblaze: " Philippe Mathieu-Daudé
@ 2024-10-04 16:21 ` Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 6/8] target/mips: Implement CPUClass::is_big_endian Philippe Mathieu-Daudé
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-04 16:21 UTC (permalink / raw)
To: qemu-devel
Cc: Aurelien Jarno, Eduardo Habkost, Yanan Wang, Edgar E. Iglesias,
qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Philippe Mathieu-Daudé,
Nicholas Piggin, qemu-arm, Zhao Liu, Peter Maydell, Jiaxun Yang
In order to re-use cpu_is_bigendian(), declare it on "internal.h"
after renaming it as mips_env_is_bigendian().
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/mips/internal.h | 5 +++++
target/mips/tcg/ldst_helper.c | 15 +++++----------
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/target/mips/internal.h b/target/mips/internal.h
index a9a22ea00ec..84c8e5e1ae7 100644
--- a/target/mips/internal.h
+++ b/target/mips/internal.h
@@ -225,6 +225,11 @@ static inline void mips_env_set_pc(CPUMIPSState *env, target_ulong value)
}
}
+static inline bool mips_env_is_bigendian(CPUMIPSState *env)
+{
+ return extract32(env->CP0_Config0, CP0C0_BE, 1);
+}
+
static inline void restore_pamask(CPUMIPSState *env)
{
if (env->hflags & MIPS_HFLAG_ELPA) {
diff --git a/target/mips/tcg/ldst_helper.c b/target/mips/tcg/ldst_helper.c
index 97056d00a27..f92a923d7ad 100644
--- a/target/mips/tcg/ldst_helper.c
+++ b/target/mips/tcg/ldst_helper.c
@@ -53,11 +53,6 @@ HELPER_LD_ATOMIC(lld, ldq, 0x7, (target_ulong))
#endif /* !CONFIG_USER_ONLY */
-static inline bool cpu_is_bigendian(CPUMIPSState *env)
-{
- return extract32(env->CP0_Config0, CP0C0_BE, 1);
-}
-
static inline target_ulong get_lmask(CPUMIPSState *env,
target_ulong value, unsigned bits)
{
@@ -65,7 +60,7 @@ static inline target_ulong get_lmask(CPUMIPSState *env,
value &= mask;
- if (!cpu_is_bigendian(env)) {
+ if (!mips_env_is_bigendian(env)) {
value ^= mask;
}
@@ -76,7 +71,7 @@ void helper_swl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
int mem_idx)
{
target_ulong lmask = get_lmask(env, arg2, 32);
- int dir = cpu_is_bigendian(env) ? 1 : -1;
+ int dir = mips_env_is_bigendian(env) ? 1 : -1;
cpu_stb_mmuidx_ra(env, arg2, (uint8_t)(arg1 >> 24), mem_idx, GETPC());
@@ -100,7 +95,7 @@ void helper_swr(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
int mem_idx)
{
target_ulong lmask = get_lmask(env, arg2, 32);
- int dir = cpu_is_bigendian(env) ? 1 : -1;
+ int dir = mips_env_is_bigendian(env) ? 1 : -1;
cpu_stb_mmuidx_ra(env, arg2, (uint8_t)arg1, mem_idx, GETPC());
@@ -130,7 +125,7 @@ void helper_sdl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
int mem_idx)
{
target_ulong lmask = get_lmask(env, arg2, 64);
- int dir = cpu_is_bigendian(env) ? 1 : -1;
+ int dir = mips_env_is_bigendian(env) ? 1 : -1;
cpu_stb_mmuidx_ra(env, arg2, (uint8_t)(arg1 >> 56), mem_idx, GETPC());
@@ -174,7 +169,7 @@ void helper_sdr(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
int mem_idx)
{
target_ulong lmask = get_lmask(env, arg2, 64);
- int dir = cpu_is_bigendian(env) ? 1 : -1;
+ int dir = mips_env_is_bigendian(env) ? 1 : -1;
cpu_stb_mmuidx_ra(env, arg2, (uint8_t)arg1, mem_idx, GETPC());
--
2.45.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 6/8] target/mips: Implement CPUClass::is_big_endian
2024-10-04 16:21 [PATCH 0/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2024-10-04 16:21 ` [PATCH 5/8] target/mips: Declare mips_env_is_bigendian() in 'internal.h' Philippe Mathieu-Daudé
@ 2024-10-04 16:21 ` Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 7/8] target/ppc: Register CPUClass::is_big_endian Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 8/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
7 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-04 16:21 UTC (permalink / raw)
To: qemu-devel
Cc: Aurelien Jarno, Eduardo Habkost, Yanan Wang, Edgar E. Iglesias,
qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Philippe Mathieu-Daudé,
Nicholas Piggin, qemu-arm, Zhao Liu, Peter Maydell, Jiaxun Yang
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/mips/cpu.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index 89655b1900f..ad70ad802a7 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -132,6 +132,11 @@ static vaddr mips_cpu_get_pc(CPUState *cs)
return cpu->env.active_tc.PC;
}
+static bool mips_cpu_is_big_endian(CPUState *cs)
+{
+ return mips_env_is_bigendian(cpu_env(cs));
+}
+
static bool mips_cpu_has_work(CPUState *cs)
{
CPUMIPSState *env = cpu_env(cs);
@@ -577,6 +582,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data)
&mcc->parent_phases);
cc->class_by_name = mips_cpu_class_by_name;
+ cc->is_big_endian = mips_cpu_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] 12+ messages in thread
* [PATCH 7/8] target/ppc: Register CPUClass::is_big_endian
2024-10-04 16:21 [PATCH 0/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2024-10-04 16:21 ` [PATCH 6/8] target/mips: Implement CPUClass::is_big_endian Philippe Mathieu-Daudé
@ 2024-10-04 16:21 ` Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 8/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
7 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-04 16:21 UTC (permalink / raw)
To: qemu-devel
Cc: Aurelien Jarno, Eduardo Habkost, Yanan Wang, Edgar E. Iglesias,
qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Philippe Mathieu-Daudé,
Nicholas Piggin, qemu-arm, Zhao Liu, Peter Maydell, Jiaxun Yang
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/ppc/cpu_init.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index 23881d09e9f..39ec290cdc0 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -7341,8 +7341,6 @@ static void ppc_cpu_reset_hold(Object *obj, ResetType type)
#endif
}
-#ifndef CONFIG_USER_ONLY
-
static bool ppc_cpu_is_big_endian(CPUState *cs)
{
cpu_synchronize_state(cs);
@@ -7350,6 +7348,8 @@ static bool ppc_cpu_is_big_endian(CPUState *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)
{
@@ -7515,6 +7515,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
&pcc->parent_phases);
cc->class_by_name = ppc_cpu_class_by_name;
+ cc->is_big_endian = ppc_cpu_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] 12+ messages in thread
* [PATCH 8/8] hw/core/cpu: Expose cpu_is_big_endian() method
2024-10-04 16:21 [PATCH 0/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2024-10-04 16:21 ` [PATCH 7/8] target/ppc: Register CPUClass::is_big_endian Philippe Mathieu-Daudé
@ 2024-10-04 16:21 ` Philippe Mathieu-Daudé
7 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-04 16:21 UTC (permalink / raw)
To: qemu-devel
Cc: Aurelien Jarno, Eduardo Habkost, Yanan Wang, Edgar E. Iglesias,
qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Philippe Mathieu-Daudé,
Nicholas Piggin, qemu-arm, Zhao Liu, Peter Maydell, Jiaxun Yang
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 22ef7a44e86..2550bc98dee 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -608,6 +608,14 @@ extern __thread CPUState *current_cpu;
extern bool mttcg_enabled;
#define qemu_tcg_mttcg_enabled() (mttcg_enabled)
+/**
+ * cpu_is_big_endian:
+ * @cpu: The CPU whose state is to be inspected.
+ *
+ * Returns: %true if the CPU runs in big endianness, %false otherwise.
+ */
+bool cpu_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 aa5ea9761e4..277c4ee6720 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_is_big_endian(CPUState *cpu)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ return cc->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] 12+ messages in thread
* Re: [PATCH 2/8] hw/core/cpu: Introduce CPUClass::is_big_endian() handler
2024-10-04 16:21 ` [PATCH 2/8] hw/core/cpu: Introduce CPUClass::is_big_endian() handler Philippe Mathieu-Daudé
@ 2024-10-04 16:41 ` Peter Maydell
2024-10-04 16:53 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 12+ messages in thread
From: Peter Maydell @ 2024-10-04 16:41 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Aurelien Jarno, Eduardo Habkost, Yanan Wang,
Edgar E. Iglesias, qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Nicholas Piggin, qemu-arm, Zhao Liu,
Jiaxun Yang
On Fri, 4 Oct 2024 at 17:22, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> Introduce the CPUClass::is_big_endian() handler and its
> common default.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/hw/core/cpu.h | 3 ++-
> hw/core/cpu-common.c | 7 +++++++
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 04e9ad49968..22ef7a44e86 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -150,6 +150,7 @@ struct CPUClass {
> ObjectClass *(*class_by_name)(const char *cpu_model);
> void (*parse_features)(const char *typename, char *str, Error **errp);
>
> + bool (*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,
What does this actually mean, though? Arm for instance
has multiple different kinds of "big-endian" depending
on the CPU: both BE32 and BE8, and data-endianness not
necessarily being the same as instruction-endianness.
This series doesn't introduce any users of this new API.
It's hard to say without seeing what the intended use is,
but I would expect that probably they would want to be testing
something else, depending on what they're trying to do.
It's pretty uncommon for anything out in the system to
want to know what endianness a runtime-configurable CPU
happens to be set to, because in real hardware a device
has no way to tell. (This is why cpu_virtio_is_big_endian()
is named the way it is -- to discourage anybody from trying
to use it outside the virtio devices where we need it for
legacy "the spec wasn't written thinking about endianness
very hard" reasons.)
thanks
-- PMM
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/8] hw/core/cpu: Introduce CPUClass::is_big_endian() handler
2024-10-04 16:41 ` Peter Maydell
@ 2024-10-04 16:53 ` Philippe Mathieu-Daudé
2024-10-04 17:01 ` Peter Maydell
0 siblings, 1 reply; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-10-04 16:53 UTC (permalink / raw)
To: Peter Maydell
Cc: qemu-devel, Aurelien Jarno, Eduardo Habkost, Yanan Wang,
Edgar E. Iglesias, qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Nicholas Piggin, qemu-arm, Zhao Liu,
Jiaxun Yang
On 4/10/24 18:41, Peter Maydell wrote:
> On Fri, 4 Oct 2024 at 17:22, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>>
>> Introduce the CPUClass::is_big_endian() handler and its
>> common default.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> include/hw/core/cpu.h | 3 ++-
>> hw/core/cpu-common.c | 7 +++++++
>> 2 files changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
>> index 04e9ad49968..22ef7a44e86 100644
>> --- a/include/hw/core/cpu.h
>> +++ b/include/hw/core/cpu.h
>> @@ -150,6 +150,7 @@ struct CPUClass {
>> ObjectClass *(*class_by_name)(const char *cpu_model);
>> void (*parse_features)(const char *typename, char *str, Error **errp);
>>
>> + bool (*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,
>
> What does this actually mean, though? Arm for instance
> has multiple different kinds of "big-endian" depending
> on the CPU: both BE32 and BE8, and data-endianness not
> necessarily being the same as instruction-endianness.
This is to be used in the data bus (I was wondering whether using 'data'
in the method name).
> This series doesn't introduce any users of this new API.
> It's hard to say without seeing what the intended use is,
> but I would expect that probably they would want to be testing
> something else, depending on what they're trying to do.
I'm trying to split my branch in "~20 patches series";
I should post example of API consumers in a few days.
First conversion is the cpu_in/out() API in system/ioport.c,
I'll try to post it ASAP so we can discuss there.
> It's pretty uncommon for anything out in the system to
> want to know what endianness a runtime-configurable CPU
> happens to be set to, because in real hardware a device
> has no way to tell. (This is why cpu_virtio_is_big_endian()
> is named the way it is -- to discourage anybody from trying
> to use it outside the virtio devices where we need it for
> legacy "the spec wasn't written thinking about endianness
> very hard" reasons.)
I'm trying to convert implicit knowledge of target endianness
to explicit one, propagated as argument from the machine.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/8] hw/core/cpu: Introduce CPUClass::is_big_endian() handler
2024-10-04 16:53 ` Philippe Mathieu-Daudé
@ 2024-10-04 17:01 ` Peter Maydell
0 siblings, 0 replies; 12+ messages in thread
From: Peter Maydell @ 2024-10-04 17:01 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Aurelien Jarno, Eduardo Habkost, Yanan Wang,
Edgar E. Iglesias, qemu-ppc, Marcel Apfelbaum, Aleksandar Rikalo,
Daniel Henrique Barboza, Nicholas Piggin, qemu-arm, Zhao Liu,
Jiaxun Yang
On Fri, 4 Oct 2024 at 17:54, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> On 4/10/24 18:41, Peter Maydell wrote:
> > On Fri, 4 Oct 2024 at 17:22, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
> >>
> >> Introduce the CPUClass::is_big_endian() handler and its
> >> common default.
> >>
> >> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> >> ---
> >> include/hw/core/cpu.h | 3 ++-
> >> hw/core/cpu-common.c | 7 +++++++
> >> 2 files changed, 9 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> >> index 04e9ad49968..22ef7a44e86 100644
> >> --- a/include/hw/core/cpu.h
> >> +++ b/include/hw/core/cpu.h
> >> @@ -150,6 +150,7 @@ struct CPUClass {
> >> ObjectClass *(*class_by_name)(const char *cpu_model);
> >> void (*parse_features)(const char *typename, char *str, Error **errp);
> >>
> >> + bool (*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,
> >
> > What does this actually mean, though? Arm for instance
> > has multiple different kinds of "big-endian" depending
> > on the CPU: both BE32 and BE8, and data-endianness not
> > necessarily being the same as instruction-endianness.
>
> This is to be used in the data bus (I was wondering whether using 'data'
> in the method name).
That sounds like what you actually want is (a non-compile-time
version of) TARGET_ENDIANNESS, which is not related to the
CPU's dynamic setting.
> > This series doesn't introduce any users of this new API.
> > It's hard to say without seeing what the intended use is,
> > but I would expect that probably they would want to be testing
> > something else, depending on what they're trying to do.
>
> I'm trying to split my branch in "~20 patches series";
> I should post example of API consumers in a few days.
>
> First conversion is the cpu_in/out() API in system/ioport.c,
> I'll try to post it ASAP so we can discuss there.
Yeah, I think we really need to look at the users, because
my current feeling is "we don't want this API at all,
the answer will always be to use something else".
I suspect for cpu_in/out the answer is "this API only
makes sense for x86, and whatever extent it's built
for anything else is accidental". We could probably
define it as always-little-endian.
-- PMM
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-10-04 17:02 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-04 16:21 [PATCH 0/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 1/8] exec/tswap: Massage target_needs_bswap() definition Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 2/8] hw/core/cpu: Introduce CPUClass::is_big_endian() handler Philippe Mathieu-Daudé
2024-10-04 16:41 ` Peter Maydell
2024-10-04 16:53 ` Philippe Mathieu-Daudé
2024-10-04 17:01 ` Peter Maydell
2024-10-04 16:21 ` [PATCH 3/8] target/arm: Implement CPUClass::is_big_endian Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 4/8] target/microblaze: " Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 5/8] target/mips: Declare mips_env_is_bigendian() in 'internal.h' Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 6/8] target/mips: Implement CPUClass::is_big_endian Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 7/8] target/ppc: Register CPUClass::is_big_endian Philippe Mathieu-Daudé
2024-10-04 16:21 ` [PATCH 8/8] hw/core/cpu: Expose cpu_is_big_endian() method Philippe Mathieu-Daudé
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).