target: Implement CPUClass::datapath_is_big_endian() handlers
cover target: Implement CPUClass::datapath_is_big_endian() handlers
The long term goal is to remove endianness knowledge from QEMU system binaries, allowing them to run vCPU in any endianness. For that target_words_bigendian(), TARGET_BIG_ENDIAN and few other things (like MO_TE) must be removed.
Have each target implement a datapath_is_big_endian() handler to express whether the CPU data is expected to be accessed in big endian or not.
Few targets already provide a such functionality (ARM, PPC); for some the data endianness is exposed via a CPU bit; and for many the data endianness is fixed.
Use this handler in 3 places: disas/, the generic-loader device and the VirtIO core layer.
Note, a similar CPUClass::codepath_is_big_endian() helper could be useful for translator_ld/st_swap() API.
Philippe Mathieu-Daudé (20):
exec/tswap: Rename target_words_bigendian -> qemu_binary_is_bigendian hw/core/cpu: Introduce CPUClass::datapath_is_big_endian() handler target/arm: Implement CPUClass::datapath_is_big_endian target/ppc: Register CPUClass::datapath_is_big_endian target/rx: Implement CPUClass::datapath_is_big_endian target/sparc: Implement CPUClass::datapath_is_big_endian target/riscv: Implement CPUClass::datapath_is_big_endian target/sh4: Expose CPUSH4State::little_endian property target/sh4: Implement CPUClass::datapath_is_big_endian target/microblaze: Implement CPUClass::datapath_is_big_endian target/mips: Implement CPUClass::datapath_is_big_endian target/xtensa: Implement xtensa_isa_is_big_endian() target/xtensa: Implement CPUClass::datapath_is_big_endian
target: Implement CPUClass::datapath_is_big_endian (little-endian)
target: Implement CPUClass::datapath_is_big_endian (big-endian) hw/core/cpu: Expose cpu_datapath_is_big_endian() method
disas: Use cpu_datapath_is_big_endian() hw/core/generic-loader: Use cpu_datapath_is_big_endian() hw/virtio: Use cpu_datapath_is_big_endian()
hw/core/cpu: Remove cpu_virtio_is_big_endian()
include/exec/tswap.h | 18 +++++++++--------- include/hw/core/cpu.h | 22 ++++++++++++---------- include/hw/core/sysemu-cpu-ops.h | 8 -------- include/hw/xtensa/xtensa-isa.h | 1 + target/microblaze/cpu.h | 2 ++ target/sh4/cpu.h | 6 ++++++ cpu-target.c | 2 +- disas/disas-common.c | 3 +-- hw/core/cpu-common.c | 7 +++++++ hw/core/cpu-sysemu.c | 11 ----------- hw/core/generic-loader.c | 7 ++----- hw/display/vga.c | 4 ++-- hw/virtio/virtio.c | 4 ++-- system/qtest.c | 2 +- target/alpha/cpu.c | 6 ++++++ target/arm/cpu.c | 4 ++-- target/avr/cpu.c | 7 ++++++- target/hexagon/cpu.c | 6 ++++++ target/hppa/cpu.c | 6 ++++++ target/i386/cpu.c | 6 ++++++ target/loongarch/cpu.c | 6 ++++++ target/m68k/cpu.c | 6 ++++++ target/microblaze/cpu.c | 11 +++++++++++ target/mips/cpu.c | 9 +++++++++ target/openrisc/cpu.c | 6 ++++++ target/ppc/cpu_init.c | 8 ++++---- target/riscv/cpu.c | 17 +++++++++++++++++ target/rx/cpu.c | 10 ++++++++++ target/s390x/cpu.c | 6 ++++++ target/sh4/cpu.c | 16 ++++++++++++++++ target/sparc/cpu.c | 15 +++++++++++++++ target/tricore/cpu.c | 6 ++++++ target/xtensa/cpu.c | 8 ++++++++ target/xtensa/xtensa-isa.c | 7 +++++++ 34 files changed, 205 insertions(+), 58 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/20 exec/tswap: Rename target_words_bigendian -> qemu_binary_is_bigendian
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)--- 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(-)
include/exec/tswap.h +9 -9
@@ -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)
cpu-target.c +1 -1
@@ -463,7 +463,7 @@ out: }#endif -bool target_words_bigendian (void ) +bool qemu_binary_is_bigendian (void ) {return TARGET_BIG_ENDIAN ; }
disas/disas-common.c +1 -1
@@ -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 ;
hw/core/cpu-sysemu.c +1 -1
@@ -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)
hw/core/generic-loader.c +1 -1
@@ -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 ;
hw/display/vga.c +2 -2
@@ -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);
hw/virtio/virtio.c +1 -1
@@ -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 ;
system/qtest.c +1 -1
@@ -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" );
Signature · 1 line
2.45.2
Re: [PATCH 01/20] exec/tswap: Rename target_words_bigendian -> qemu_binary_is_bigendian
Quoted 9 lines · 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é<[email protected]>
Quoted 10 lines
--- 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(-)
r~
PATCH 2/20 hw/core/cpu: Introduce CPUClass::datapath_is_big_endian() handler
In reply to 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.
--- include/hw/core/cpu.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/hw/core/cpu.h +4 -1
@@ -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:
Signature · 1 line
2.45.2
PATCH 3/20 target/arm: Implement CPUClass::datapath_is_big_endian
In reply to Philippe Mathieu-Daudéarm_cpu_virtio_is_big_endian() already returns whether the data path is in big endian. Re-use that.
--- target/arm/cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/arm/cpu.c +3 -2
@@ -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;
Signature · 1 line
2.45.2
Re: [PATCH 03/20] target/arm: Implement CPUClass::datapath_is_big_endian
Quoted 7 lines · 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é <[email protected]>--- 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~
Quoted 31 lines
target/arm/cpu.c +3
-2@@ -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;
PATCH 4/20 target/ppc: Register CPUClass::datapath_is_big_endian
In reply to 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.
--- target/ppc/cpu_init.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
target/ppc/cpu_init.c +5 -4
@@ -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;
Signature · 1 line
2.45.2
PATCH 5/20 target/rx: Implement CPUClass::datapath_is_big_endian
In reply to Philippe Mathieu-DaudéWhile on RX the endianness can be set at RESET, we do not implement that; only little endianness is used.
--- target/rx/cpu.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
target/rx/cpu.c +10 -0
@@ -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;
Signature · 1 line
2.45.2
PATCH 6/20 target/sparc: Implement CPUClass::datapath_is_big_endian
In reply to Philippe Mathieu-DaudéWhile the SPARC data endianness can be changed at runtime, we do not implement that; only big endianness is used.
--- target/sparc/cpu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
target/sparc/cpu.c +15 -0
@@ -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;
Signature · 1 line
2.45.2
PATCH 7/20 target/riscv: Implement CPUClass::datapath_is_big_endian
In reply to 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").
--- target/riscv/cpu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
target/riscv/cpu.c +17 -0
@@ -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;
Signature · 1 line
2.45.2
PATCH 8/20 target/sh4: Expose CPUSH4State::little_endian property
In reply to Philippe Mathieu-DaudéSH4 CPUs endianness is set with an external pin in a power-on reset.
--- target/sh4/cpu.h | 6 ++++++ target/sh4/cpu.c | 8 ++++++++ 2 files changed, 14 insertions(+)
target/sh4/cpu.h +6 -0
@@ -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;
target/sh4/cpu.c +8 -0
@@ -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);
Signature · 1 line
2.45.2
PATCH 9/20 target/sh4: Implement CPUClass::datapath_is_big_endian
In reply to Philippe Mathieu-DaudéImplement SH4 datapath_is_big_endian() helper, returning the 'little_endian' property set at reset.
--- target/sh4/cpu.c | 8 ++++++++ 1 file changed, 8 insertions(+)
target/sh4/cpu.c +8 -0
@@ -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;
Signature · 1 line
2.45.2
PATCH 10/20 target/microblaze: Implement CPUClass::datapath_is_big_endian
In reply to Philippe Mathieu-DaudéImplement the MicroBlaze datapath_is_big_endian() handler, returning the value of the ENDI bit.
--- target/microblaze/cpu.h | 2 ++ target/microblaze/cpu.c | 11 +++++++++++ 2 files changed, 13 insertions(+)
target/microblaze/cpu.h +2 -0
@@ -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) {
target/microblaze/cpu.c +11 -0
@@ -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;
Signature · 1 line
2.45.2
PATCH 11/20 target/mips: Implement CPUClass::datapath_is_big_endian
In reply to Philippe Mathieu-DaudéImplement MIPS datapath_is_big_endian() handler using the already existing mips_env_is_bigendian() method.
--- target/mips/cpu.c | 9 +++++++++ 1 file changed, 9 insertions(+)
target/mips/cpu.c +9 -0
@@ -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;
Signature · 1 line
2.45.2
PATCH 12/20 target/xtensa: Implement xtensa_isa_is_big_endian()
In reply to 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.
--- include/hw/xtensa/xtensa-isa.h | 1 + target/xtensa/xtensa-isa.c | 7 +++++++ 2 files changed, 8 insertions(+)
include/hw/xtensa/xtensa-isa.h +1 -0
@@ -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 }
target/xtensa/xtensa-isa.c +7 -0
@@ -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; +}
Signature · 1 line
2.45.2
PATCH 13/20 target/xtensa: Implement CPUClass::datapath_is_big_endian
In reply to Philippe Mathieu-DaudéImplement Xtensa datapath_is_big_endian() helper via libisa.
---
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(+)
target/xtensa/cpu.c +8 -0
@@ -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;
Signature · 1 line
2.45.2
PATCH 14/20 target: Implement CPUClass::datapath_is_big_endian (little-endian)
In reply to 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.
--- 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(-)
target/alpha/cpu.c +6 -0
@@ -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;
target/avr/cpu.c +6 -1
@@ -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;
target/i386/cpu.c +6 -0
@@ -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;
target/loongarch/cpu.c +6 -0
@@ -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;
target/tricore/cpu.c +6 -0
@@ -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;
Signature · 1 line
2.45.2
PATCH 15/20 target: Implement CPUClass::datapath_is_big_endian (big-endian)
In reply to 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.
--- 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(+)
target/hexagon/cpu.c +6 -0
@@ -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;
target/hppa/cpu.c +6 -0
@@ -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;
target/m68k/cpu.c +6 -0
@@ -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;
target/openrisc/cpu.c +6 -0
@@ -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;
target/s390x/cpu.c +6 -0
@@ -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;
Signature · 1 line
2.45.2
Re: [PATCH 15/20] target: Implement CPUClass::datapath_is_big_endian (big-endian)
Quoted 30 lines · 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é <[email protected]>--- 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(+)target/hexagon/cpu.c +5
-0@@ -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;
target/hexagon/cpu.c static void hexagon_cpu_class_init(ObjectClass *c, void *data) · line 353
Quoted 7 lines
target/hexagon/cpu.c +1
-0@@ -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:
Quoted 96 lines
target/hppa/cpu.c +6
-0@@ -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;target/m68k/cpu.c +6
-0@@ -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;target/openrisc/cpu.c +6
-0@@ -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;target/s390x/cpu.c +6
-0@@ -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;
PATCH 16/20 hw/core/cpu: Expose cpu_datapath_is_big_endian() method
In reply to Philippe Mathieu-DaudéAll target implement their CPUClass::datapath_is_big_endian() helper, we can expose the generic cpu_datapath_is_big_endian() method.
--- include/hw/core/cpu.h | 8 ++++++++ hw/core/cpu-common.c | 7 +++++++ 2 files changed, 15 insertions(+)
include/hw/core/cpu.h +8 -0
@@ -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.
hw/core/cpu-common.c +7 -0
@@ -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)
Signature · 1 line
2.45.2
PATCH 17/20 disas: Use cpu_datapath_is_big_endian()
In reply to Philippe Mathieu-DaudéRather that using the binary endianness, use the vCPU one.
--- disas/disas-common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
disas/disas-common.c +1 -2
@@ -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 ;
Signature · 1 line
2.45.2
Re: [PATCH 17/20] disas: Use cpu_datapath_is_big_endian()
Quoted 20 lines · Philippe Mathieu-Daudé
Rather that using the binary endianness, use the vCPU one.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- disas/disas-common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)disas/disas-common.c +0
-1@@ -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"
disas/disas-common.c void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu) · line 66
Quoted 8 lines
disas/disas-common.c +1
-1@@ -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~
Re: [PATCH 17/20] disas: Use cpu_datapath_is_big_endian()
In reply to Philippe Mathieu-DaudéQuoted 21 lines · Philippe Mathieu-Daudé
Rather that using the binary endianness, use the vCPU one.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- disas/disas-common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)disas/disas-common.c +0
-1@@ -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"
disas/disas-common.c void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu)
Quoted 9 lines
disas/disas-common.c +1
-2@@ -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
PATCH 18/20 hw/core/generic-loader: Use cpu_datapath_is_big_endian()
In reply to Philippe Mathieu-DaudéRather that using the binary endianness, use the vCPU one.
--- hw/core/generic-loader.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
hw/core/generic-loader.c +2 -5
@@ -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,
Signature · 1 line
2.45.2
Re: [PATCH 18/20] hw/core/generic-loader: Use cpu_datapath_is_big_endian()
Quoted 34 lines · Philippe Mathieu-Daudé
Rather that using the binary endianness, use the vCPU one.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/core/generic-loader.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)hw/core/generic-loader.c +0
-4@@ -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) {
hw/core/generic-loader.c static void generic_loader_realize(DeviceState *dev, Error **errp) · line 144
Quoted 10 lines
hw/core/generic-loader.c +2
-1AddressSpace *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~
RFC PATCH 19/20 hw/virtio: Use cpu_datapath_is_big_endian()
In reply to 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.
--- hw/virtio/virtio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio.c +1 -1
@@ -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 ;
Signature · 1 line
2.45.2
PATCH 20/20 hw/core/cpu: Remove cpu_virtio_is_big_endian()
In reply to 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.
--- 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(-)
include/hw/core/cpu.h +0 -9
@@ -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 */ /**
include/hw/core/sysemu-cpu-ops.h +0 -8
@@ -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.
hw/core/cpu-sysemu.c +0 -11
@@ -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);
target/arm/cpu.c +0 -1
@@ -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
target/ppc/cpu_init.c +0 -1
@@ -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
Signature · 1 line
2.45.2