misc: Prefer evaluating TARGET_BIG_ENDIAN in C
cover misc: Prefer evaluating TARGET_BIG_ENDIAN in C
Few single-binary cleanups before switching to the TargetInfo API. Sending as a preliminary cleanup because can be reviewed out of context.
Philippe Mathieu-Daudé (8):
linux-user/elfload: Use target_needs_bswap()
accel/kvm: Use target_needs_bswap()
target/mips: Check CPU endianness at runtime using env_is_bigendian() target/ppc: Evaluate TARGET_BIG_ENDIAN at compile time target/xtensa: Evaluate TARGET_BIG_ENDIAN at compile time hw/mips: Evaluate TARGET_BIG_ENDIAN at compile time hw/microblaze: Evaluate TARGET_BIG_ENDIAN at compile time gdbstub/helpers: Evaluate TARGET_BIG_ENDIAN at compile time
include/gdbstub/helpers.h | 11 +---- accel/kvm/kvm-all.c | 29 ++++++------- hw/microblaze/petalogix_ml605_mmu.c | 12 +++--- hw/microblaze/xlnx-zynqmp-pmu.c | 12 +++--- hw/mips/jazz.c | 10 ++--- hw/mips/malta.c | 21 +++------- hw/mips/mipssim.c | 10 ++--- linux-user/elfload.c | 63 ++++++++++++++++++----------- target/mips/tcg/msa_helper.c | 34 ++++++++-------- target/ppc/cpu_init.c | 12 +++--- target/ppc/mem_helper.c | 6 +-- target/ppc/translate.c | 6 +-- target/xtensa/translate.c | 10 ++--- 13 files changed, 109 insertions(+), 127 deletions(-)
Signature · 1 line
2.47.1
PATCH 1/8 linux-user/elfload: Use target_needs_bswap()
Check whether we need to swap at runtime usingtarget_needs_bswap().
--- linux-user/elfload.c | 63 +++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 24 deletions(-)
linux-user/elfload.c +39 -24
@@ -12,6 +12,7 @@#include "exec/page-protection.h" #include "exec/mmap-lock.h" #include "exec/translation-block.h" +#include "exec/tswap.h" #include "user/guest-base.h" #include "user-internals.h" #include "signal-common.h"
@@ -2122,9 +2123,12 @@ static inline void memcpy_fromfs(void * to, const void * from, unsigned long n)memcpy (to, from, n); } -#if HOST_BIG_ENDIAN !=TARGET_BIG_ENDIAN static void bswap_ehdr (struct elfhdr *ehdr) { +if (!target_needs_bswap ()) { +return ; + } +bswap16s (&ehdr->e_type);/* Object file type */ bswap16s (&ehdr->e_machine);/* Architecture */ bswap32s (&ehdr->e_version);/* Object file version */
@@ -2142,8 +2146,11 @@ static void bswap_ehdr(struct elfhdr *ehdr)static void bswap_phdr (struct elf_phdr *phdr,int phnum) { -int i; -for (i =0 ; i < phnum; ++i, ++phdr) { +if (!target_needs_bswap ()) { +return ; + } + +for (int i =0 ; i < phnum; ++i, ++phdr) {bswap32s (&phdr->p_type);/* Segment type */ bswap32s (&phdr->p_flags);/* Segment flags */ bswaptls (&phdr->p_offset);/* Segment file offset */
@@ -2157,8 +2164,11 @@ static void bswap_phdr(struct elf_phdr *phdr, int phnum)static void bswap_shdr (struct elf_shdr *shdr,int shnum) { -int i; -for (i =0 ; i < shnum; ++i, ++shdr) { +if (!target_needs_bswap ()) { +return ; + } + +for (int i =0 ; i < shnum; ++i, ++shdr) {bswap32s (&shdr->sh_name);bswap32s (&shdr->sh_type);bswaptls (&shdr->sh_flags);
@@ -2174,6 +2184,10 @@ static void bswap_shdr(struct elf_shdr *shdr, int shnum)static void bswap_sym (struct elf_sym *sym) { +if (!target_needs_bswap ()) { +return ; + } +bswap32s (&sym->st_name);bswaptls (&sym->st_value);bswaptls (&sym->st_size);
@@ -2183,6 +2197,10 @@ static void bswap_sym(struct elf_sym *sym)#ifdef TARGET_MIPS static void bswap_mips_abiflags (Mips_elf_abiflags_v0 *abiflags) { +if (!target_needs_bswap ()) { +return ; + } +bswap16s (&abiflags->version);bswap32s (&abiflags->ases);bswap32s (&abiflags->isa_ext);
@@ -2190,15 +2208,6 @@ static void bswap_mips_abiflags(Mips_elf_abiflags_v0 *abiflags) bswap32s(&abiflags->flags2); }#endif -#else -static inline void bswap_ehdr (struct elfhdr *ehdr) { } -static inline void bswap_phdr (struct elf_phdr *phdr,int phnum) { } -static inline void bswap_shdr (struct elf_shdr *shdr,int shnum) { } -static inline void bswap_sym (struct elf_sym *sym) { } -#ifdef TARGET_MIPS -static inline void bswap_mips_abiflags (Mips_elf_abiflags_v0 *abiflags) { } -#endif -#endif #ifdef USE_ELF_CORE_DUMP static int elf_core_dump (int ,const CPUArchState *);
@@ -3144,11 +3153,11 @@ static bool parse_elf_properties(const ImageSource *src,* The contents of a valid PT_GNU_PROPERTY is a sequence of uint32_t. * Swap most of them now, beyond the header and namesz. */ -#if HOST_BIG_ENDIAN !=TARGET_BIG_ENDIAN -for (int i =4 ; i < n /4 ; i++) { -bswap32s (note.data + i); +if (target_needs_bswap ()) { +for (int i =4 ; i < n /4 ; i++) { +bswap32s (note.data + i); + } } -#endif /* * Note that nhdr is 3 words, and that the "name" described by namesz
@@ -4000,9 +4009,12 @@ struct target_elf_prpsinfo {char pr_psargs[ELF_PRARGSZ ];/* initial part of arg list */ }; -#if HOST_BIG_ENDIAN !=TARGET_BIG_ENDIAN static void bswap_prstatus (struct target_elf_prstatus *prstatus) { +if (!target_needs_bswap ()) { +return ; + } + prstatus->pr_info.si_signo =tswap32 (prstatus->pr_info.si_signo); prstatus->pr_info.si_code =tswap32 (prstatus->pr_info.si_code); prstatus->pr_info.si_errno =tswap32 (prstatus->pr_info.si_errno);
@@ -4020,6 +4032,10 @@ static void bswap_prstatus(struct target_elf_prstatus *prstatus)static void bswap_psinfo (struct target_elf_prpsinfo *psinfo) { +if (!target_needs_bswap ()) { +return ; + } + psinfo->pr_flag =tswapal (psinfo->pr_flag); psinfo->pr_uid =tswap16 (psinfo->pr_uid); psinfo->pr_gid =tswap16 (psinfo->pr_gid);
@@ -4031,15 +4047,14 @@ static void bswap_psinfo(struct target_elf_prpsinfo *psinfo)static void bswap_note (struct elf_note *en) { +if (!target_needs_bswap ()) { +return ; + } +bswap32s (&en->n_namesz);bswap32s (&en->n_descsz);bswap32s (&en->n_type); } -#else -static inline void bswap_prstatus (struct target_elf_prstatus *p) { } -static inline void bswap_psinfo (struct target_elf_prpsinfo *p) {} -static inline void bswap_note (struct elf_note *en) { } -#endif /* HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN */ /* * Calculate file (dump) size of given memory region.
Signature · 1 line
2.47.1
Re: [PATCH 1/8] linux-user/elfload: Use target_needs_bswap()
Quoted 7 lines · Philippe Mathieu-Daudé
Check whether we need to swap at runtime using
target_needs_bswap().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- linux-user/elfload.c | 63 +++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 24 deletions(-)
r~
PATCH 2/8 accel/kvm: Use target_needs_bswap()
In reply to Philippe Mathieu-DaudéCheck whether we need to swap at runtime usingtarget_needs_bswap().
--- accel/kvm/kvm-all.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
accel/kvm/kvm-all.c +15 -14
@@ -33,6 +33,7 @@#include "system/cpus.h" #include "system/accel-blocker.h" #include "qemu/bswap.h" +#include "exec/tswap.h" #include "system/memory.h" #include "system/ram_addr.h" #include "qemu/event_notifier.h"
@@ -1319,21 +1320,21 @@ bool kvm_hwpoisoned_mem(void)static uint32_t adjust_ioeventfd_endianness (uint32_t val,uint32_t size) { -#if HOST_BIG_ENDIAN !=TARGET_BIG_ENDIAN -/* The kernel expects ioeventfd values in HOST_BIG_ENDIAN -* endianness, but the memory core hands them in target endianness. -* For example, PPC is always treated as big-endian even if running -* on KVM and on PPC64LE. Correct here. -*/ -switch (size) { -case 2 : - val =bswap16 (val); -break ; -case 4 : - val =bswap32 (val); -break ; +if (target_needs_bswap ()) { +/* The kernel expects ioeventfd values in HOST_BIG_ENDIAN +* endianness, but the memory core hands them in target endianness. +* For example, PPC is always treated as big-endian even if running +* on KVM and on PPC64LE. Correct here, swapping back. +*/ +switch (size) { +case 2 : + val =bswap16 (val); +break ; +case 4 : + val =bswap32 (val); +break ; + } } -#endif return val; }
Signature · 1 line
2.47.1
Re: [PATCH 2/8] accel/kvm: Use target_needs_bswap()
Quoted 7 lines · Philippe Mathieu-Daudé
Check whether we need to swap at runtime using
target_needs_bswap().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- accel/kvm/kvm-all.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
r~
PATCH 3/8 target/mips: Check CPU endianness at runtime using env_is_bigendian()
In reply to Philippe Mathieu-DaudéSince CPU endianness can be toggled at runtime before resetting, checking the endianness at build time preprocessing the TARGET_BIG_ENDIAN definition isn't correct. We have to call mips_env_is_bigendian() to get the CPU endianness at runtime.
--- target/mips/tcg/msa_helper.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-)
target/mips/tcg/msa_helper.c +16 -18
@@ -8212,7 +8212,6 @@ void helper_msa_ffint_u_df(CPUMIPSState *env, uint32_t df, uint32_t wd,/* Element-by-element access macros */ #define DF_ELEMENTS (df) (MSA_WRLEN / DF_BITS(df)) -#if TARGET_BIG_ENDIAN static inline uint64_t bswap16x4 (uint64_t x) {uint64_t m =0x00ff00ff00ff00ffull ;
@@ -8223,7 +8222,6 @@ static inline uint64_t bswap32x2(uint64_t x) {return ror64 (bswap64 (x),32 ); } -#endif void helper_msa_ld_b (CPUMIPSState *env,uint32_t wd,target_ulong addr)
@@ -8252,10 +8250,10 @@ void helper_msa_ld_h(CPUMIPSState *env, uint32_t wd,*/ d0 =cpu_ldq_le_data_ra (env, addr +0 , ra); d1 =cpu_ldq_le_data_ra (env, addr +8 , ra); -#if TARGET_BIG_ENDIAN - d0 =bswap16x4 (d0); - d1 =bswap16x4 (d1); -#endif +if (mips_env_is_bigendian (env)) { + d0 =bswap16x4 (d0); + d1 =bswap16x4 (d1); + } pwd->d[0 ] = d0; pwd->d[1 ] = d1; }
@@ -8273,10 +8271,10 @@ void helper_msa_ld_w(CPUMIPSState *env, uint32_t wd,*/ d0 =cpu_ldq_le_data_ra (env, addr +0 , ra); d1 =cpu_ldq_le_data_ra (env, addr +8 , ra); -#if TARGET_BIG_ENDIAN - d0 =bswap32x2 (d0); - d1 =bswap32x2 (d1); -#endif +if (mips_env_is_bigendian (env)) { + d0 =bswap32x2 (d0); + d1 =bswap32x2 (d1); + } pwd->d[0 ] = d0; pwd->d[1 ] = d1; }
@@ -8339,10 +8337,10 @@ void helper_msa_st_h(CPUMIPSState *env, uint32_t wd,/* Store 8 bytes at a time. See helper_msa_ld_h. */ d0 = pwd->d[0 ]; d1 = pwd->d[1 ]; -#if TARGET_BIG_ENDIAN - d0 =bswap16x4 (d0); - d1 =bswap16x4 (d1); -#endif +if (mips_env_is_bigendian (env)) { + d0 =bswap16x4 (d0); + d1 =bswap16x4 (d1); + }cpu_stq_le_data_ra (env, addr +0 , d0, ra);cpu_stq_le_data_ra (env, addr +8 , d1, ra); }
@@ -8360,10 +8358,10 @@ void helper_msa_st_w(CPUMIPSState *env, uint32_t wd,/* Store 8 bytes at a time. See helper_msa_ld_w. */ d0 = pwd->d[0 ]; d1 = pwd->d[1 ]; -#if TARGET_BIG_ENDIAN - d0 =bswap32x2 (d0); - d1 =bswap32x2 (d1); -#endif +if (mips_env_is_bigendian (env)) { + d0 =bswap32x2 (d0); + d1 =bswap32x2 (d1); + }cpu_stq_le_data_ra (env, addr +0 , d0, ra);cpu_stq_le_data_ra (env, addr +8 , d1, ra); }
Signature · 1 line
2.47.1
Re: [PATCH 3/8] target/mips: Check CPU endianness at runtime using env_is_bigendian()
Quoted 9 lines · Philippe Mathieu-Daudé
Since CPU endianness can be toggled at runtime before resetting, checking the endianness at build time preprocessing the
TARGET_BIG_ENDIANdefinition isn't correct. We have to callmips_env_is_bigendian()to get the CPU endianness at runtime.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/mips/tcg/msa_helper.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-)
r~
PATCH 4/8 target/ppc: Evaluate TARGET_BIG_ENDIAN at compile time
In reply to Philippe Mathieu-DaudéRather than evaluating TARGET_BIG_ENDIAN at preprocessing time via #ifdef'ry, do it in C at compile time
--- target/ppc/cpu_init.c | 12 ++++++------ target/ppc/mem_helper.c | 6 +----- target/ppc/translate.c | 6 +----- 3 files changed, 8 insertions(+), 16 deletions(-)
target/ppc/cpu_init.c +6 -6
@@ -7262,14 +7262,14 @@ static void ppc_cpu_reset_hold(Object *obj, ResetType type)#if defined(TARGET_PPC64 ) msr |= (target_ulong )1 <<MSR_TM ;/* Transactional memory */ #endif -#if !TARGET_BIG_ENDIAN - msr |= (target_ulong )1 <<MSR_LE ;/* Little-endian user mode */ -if (!((env->msr_mask >>MSR_LE ) &1 )) { -fprintf (stderr,"Selected CPU does not support little-endian.\n" ); -exit (1 ); +if (!TARGET_BIG_ENDIAN ) { + msr |= (target_ulong )1 <<MSR_LE ;/* Little-endian user mode */ +if (!((env->msr_mask >>MSR_LE ) &1 )) { +fprintf (stderr,"Selected CPU does not support little-endian.\n" ); +exit (1 ); + } }#endif -#endif #if defined(TARGET_PPC64 )if (mmu_is_64bit (env->mmu_model)) {
target/ppc/mem_helper.c +1 -5
@@ -32,11 +32,7 @@static inline bool needs_byteswap (const CPUPPCState *env) { -#if TARGET_BIG_ENDIAN -return FIELD_EX64 (env->msr,MSR ,LE ); -#else -return !FIELD_EX64 (env->msr,MSR ,LE ); -#endif +return TARGET_BIG_ENDIAN ^FIELD_EX64 (env->msr,MSR ,LE ); }/*****************************************************************************/
target/ppc/translate.c +1 -5
@@ -213,11 +213,7 @@ struct DisasContext {/* Return true iff byteswap is needed in a scalar memop */ static inline bool need_byteswap (const DisasContext *ctx) { -#if TARGET_BIG_ENDIAN -return ctx->le_mode; -#else -return !ctx->le_mode; -#endif +return TARGET_BIG_ENDIAN ^ ctx->le_mode; }/* True when active word size < size of target_long. */
Signature · 1 line
2.47.1
Re: [PATCH 4/8] target/ppc: Evaluate TARGET_BIG_ENDIAN at compile time
Quoted 57 lines · Philippe Mathieu-Daudé
Rather than evaluating
TARGET_BIG_ENDIANat preprocessing time via #ifdef'ry, do it in C at compile timeSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- target/ppc/cpu_init.c | 12 ++++++------ target/ppc/mem_helper.c | 6 +----- target/ppc/translate.c | 6 +----- 3 files changed, 8 insertions(+), 16 deletions(-)target/ppc/cpu_init.c +6
-6@@ -7262,14 +7262,14 @@ static void ppc_cpu_reset_hold(Object *obj, ResetType type)#if defined(TARGET_PPC64 ) msr |= (target_ulong )1 <<MSR_TM ;/* Transactional memory */ #endif -#if !TARGET_BIG_ENDIAN - msr |= (target_ulong )1 <<MSR_LE ;/* Little-endian user mode */ -if (!((env->msr_mask >>MSR_LE ) &1 )) { -fprintf (stderr,"Selected CPU does not support little-endian.\n" ); -exit (1 ); +if (!TARGET_BIG_ENDIAN ) { + msr |= (target_ulong )1 <<MSR_LE ;/* Little-endian user mode */ +if (!((env->msr_mask >>MSR_LE ) &1 )) { +fprintf (stderr,"Selected CPU does not support little-endian.\n" ); +exit (1 ); + } }#endif -#endif #if defined(TARGET_PPC64 )if (mmu_is_64bit (env->mmu_model)) {target/ppc/mem_helper.c +1
-5@@ -32,11 +32,7 @@static inline bool needs_byteswap (const CPUPPCState *env) { -#if TARGET_BIG_ENDIAN -return FIELD_EX64 (env->msr,MSR ,LE ); -#else -return !FIELD_EX64 (env->msr,MSR ,LE ); -#endif +return TARGET_BIG_ENDIAN ^FIELD_EX64 (env->msr,MSR ,LE ); }/*****************************************************************************/ target/ppc/translate.c +0
-0
target/ppc/translate.c struct DisasContext { · line 216
Quoted 9 lines
target/ppc/translate.c +1
-5@@ -213,11 +213,7 @@ struct DisasContext {/* Return true iff byteswap is needed in a scalar memop */ static inline bool need_byteswap (const DisasContext *ctx) { -#if TARGET_BIG_ENDIAN -return ctx->le_mode; -#else -return !ctx->le_mode; -#endif +return TARGET_BIG_ENDIAN ^ ctx->le_mode;
Maybe I'm missing something, but with {TARGET_BIG_ENDIAN: 1, ctx->le_mode: 1}, it would return 0, while it should be 1 instead.
It would be more readable to use a if or a ternary expression. Same for previous function needs_byteswap.
Quoted 3 lines
target/ppc/translate.c +0
-0}/* True when active word size < size of target_long. */
Re: [PATCH 4/8] target/ppc: Evaluate TARGET_BIG_ENDIAN at compile time
In reply to Philippe Mathieu-Daudétarget/ppc/mem_helper.c line 36
Quoted 9 lines · Philippe Mathieu-Daudé
static inline bool needs_byteswap(const CPUPPCState *env) {target/ppc/mem_helper.c +1
-5-#if TARGET_BIG_ENDIAN -return FIELD_EX64 (env->msr,MSR ,LE ); -#else -return !FIELD_EX64 (env->msr,MSR ,LE ); -#endif +return TARGET_BIG_ENDIAN ^FIELD_EX64 (env->msr,MSR ,LE ); }
This is wrong. You wanted
!TARGET_BIG_ENDIAN ^ ...
Likewise in the other instance in translate.c.
r~
PATCH 5/8 target/xtensa: Evaluate TARGET_BIG_ENDIAN at compile time
In reply to Philippe Mathieu-DaudéRather than evaluating TARGET_BIG_ENDIAN at preprocessing time via #ifdef'ry, do it in C at compile time
--- target/xtensa/translate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
target/xtensa/translate.c +5 -5
@@ -1395,11 +1395,11 @@ static void translate_bbi(DisasContext *dc, const OpcodeArg arg[], const uint32_t par[]) {TCGv_i32 tmp =tcg_temp_new_i32 (); -#if TARGET_BIG_ENDIAN -tcg_gen_andi_i32 (tmp, arg[0 ].in,0x80000000u >> arg[1 ].imm); -#else -tcg_gen_andi_i32 (tmp, arg[0 ].in,0x00000001u << arg[1 ].imm); -#endif +if (TARGET_BIG_ENDIAN ) { +tcg_gen_andi_i32 (tmp, arg[0 ].in,0x80000000u >> arg[1 ].imm); + }else { +tcg_gen_andi_i32 (tmp, arg[0 ].in,0x00000001u << arg[1 ].imm); + }gen_brcondi (dc, par[0 ], tmp,0 , arg[2 ].imm); }
Signature · 1 line
2.47.1
Re: [PATCH 5/8] target/xtensa: Evaluate TARGET_BIG_ENDIAN at compile time
Quoted 7 lines · Philippe Mathieu-Daudé
Rather than evaluating
TARGET_BIG_ENDIANat preprocessing time via #ifdef'ry, do it in C at compile timeSigned-off-by Philippe Mathieu-Daudé<[email protected]>--- target/xtensa/translate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
r~
PATCH 6/8 hw/mips: Evaluate TARGET_BIG_ENDIAN at compile time
In reply to Philippe Mathieu-DaudéRather than evaluating TARGET_BIG_ENDIAN at preprocessing time via #ifdef'ry, do it in C at compile time
--- hw/mips/jazz.c | 10 +++------- hw/mips/malta.c | 21 ++++++--------------- hw/mips/mipssim.c | 10 +++------- 3 files changed, 12 insertions(+), 29 deletions(-)
hw/mips/jazz.c +3 -7
@@ -59,12 +59,6 @@ enum jazz_model_e { JAZZ_PICA61, }; -#if TARGET_BIG_ENDIAN -#define BIOS_FILENAME "mips_bios.bin" -#else -#define BIOS_FILENAME "mipsel_bios.bin" -#endif -static void main_cpu_reset (void *opaque) {MIPSCPU *cpu = opaque;
@@ -168,6 +162,8 @@ static void mips_jazz_init_net(IOMMUMemoryRegion *rc4030_dma_mr,static void mips_jazz_init (MachineState *machine,enum jazz_model_e jazz_model) { +const char *bios_name =TARGET_BIG_ENDIAN ?"mips_bios.bin" + :"mipsel_bios.bin" ;MemoryRegion *address_space =get_system_memory ();char *filename;int bios_size, n;
@@ -245,7 +241,7 @@ static void mips_jazz_init(MachineState *machine,memory_region_add_subregion (address_space,0xfff00000LL , bios2);/* load the BIOS image. */ - filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , machine->firmware ?:BIOS_FILENAME ); + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , machine->firmware ?: bios_name);if (filename) { bios_size =load_image_targphys (filename,0xfff00000LL ,MAGNUM_BIOS_SIZE );
hw/mips/malta.c +6 -15
@@ -94,12 +94,6 @@ typedef struct {bool display_inited; } MaltaFPGAState; -#if TARGET_BIG_ENDIAN -#define BIOS_FILENAME "mips_bios.bin" -#else -#define BIOS_FILENAME "mipsel_bios.bin" -#endif -#define TYPE_MIPS_MALTA "mips-malta"OBJECT_DECLARE_SIMPLE_TYPE (MaltaState,MIPS_MALTA )
@@ -383,11 +377,7 @@ static uint64_t malta_fpga_read(void *opaque, hwaddr addr,/* STATUS Register */ case 0x00208 : -#if TARGET_BIG_ENDIAN - val =0x00000012 ; -#else - val =0x00000010 ; -#endif + val =TARGET_BIG_ENDIAN ?0x00000012 :0x00000010 ;break ;/* JMPRS Register */
@@ -1177,9 +1167,12 @@ void mips_malta_init(MachineState *machine)target_long bios_size =FLASH_SIZE ;/* Load firmware from flash. */ if (!dinfo) { +const char *bios_name =TARGET_BIG_ENDIAN ?"mips_bios.bin" + :"mipsel_bios.bin" ; +/* Load a BIOS image. */ filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , - machine->firmware ?:BIOS_FILENAME ); + machine->firmware ?: bios_name);if (filename) { bios_size =load_image_targphys (filename,FLASH_ADDRESS ,BIOS_SIZE );
@@ -1197,8 +1190,7 @@ void mips_malta_init(MachineState *machine)* In little endian mode the 32bit words in the bios are swapped, * a neat trick which allows bi-endian firmware. */ -#if !TARGET_BIG_ENDIAN - { +if (!TARGET_BIG_ENDIAN ) {uint32_t *end, *addr;const size_t swapsize =MIN (bios_size,0x3e0000 ); addr =rom_ptr (FLASH_ADDRESS , swapsize);
@@ -1211,7 +1203,6 @@ void mips_malta_init(MachineState *machine) addr++; } } -#endif }/*
hw/mips/mipssim.c +3 -7
@@ -46,12 +46,6 @@#define BIOS_SIZE (4 * MiB) -#if TARGET_BIG_ENDIAN -#define BIOS_FILENAME "mips_bios.bin" -#else -#define BIOS_FILENAME "mipsel_bios.bin" -#endif - static struct _loaderparams { int ram_size; const char *kernel_filename;
@@ -143,6 +137,8 @@ mips_mipssim_init(MachineState *machine)const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename; +const char *bios_name =TARGET_BIG_ENDIAN ?"mips_bios.bin" + :"mipsel_bios.bin" ;char *filename;MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *isa =g_new (MemoryRegion,1 );
@@ -179,7 +175,7 @@ mips_mipssim_init(MachineState *machine)/* Map the BIOS / boot exception handler. */ memory_region_add_subregion (address_space_mem,0x1fc00000LL , bios);/* Load a BIOS / boot exception handler image. */ - filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , machine->firmware ?:BIOS_FILENAME ); + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , machine->firmware ?: bios_name);if (filename) { bios_size =load_image_targphys (filename,0x1fc00000LL ,BIOS_SIZE );g_free (filename);
Signature · 1 line
2.47.1
Re: [PATCH 6/8] hw/mips: Evaluate TARGET_BIG_ENDIAN at compile time
Quoted 9 lines · Philippe Mathieu-Daudé
Rather than evaluating
TARGET_BIG_ENDIANat preprocessing time via #ifdef'ry, do it in C at compile timeSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/mips/jazz.c | 10 +++------- hw/mips/malta.c | 21 ++++++--------------- hw/mips/mipssim.c | 10 +++------- 3 files changed, 12 insertions(+), 29 deletions(-)
r~
PATCH 7/8 hw/microblaze: Evaluate TARGET_BIG_ENDIAN at compile time
In reply to Philippe Mathieu-DaudéRather than evaluating TARGET_BIG_ENDIAN at preprocessing time via #ifdef'ry, do it in C at compile time
--- hw/microblaze/petalogix_ml605_mmu.c | 12 ++++++------ hw/microblaze/xlnx-zynqmp-pmu.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-)
hw/microblaze/petalogix_ml605_mmu.c +6 -6
@@ -218,12 +218,12 @@ petalogix_ml605_init(MachineState *machine)static void petalogix_ml605_machine_init (MachineClass *mc) { -#if TARGET_BIG_ENDIAN - mc->desc ="PetaLogix linux refdesign for xilinx ml605 (big endian)" ; - mc->deprecation_reason ="big endian support is not tested" ; -#else - mc->desc ="PetaLogix linux refdesign for xilinx ml605 (little endian)" ; -#endif +if (TARGET_BIG_ENDIAN ) { + mc->desc ="PetaLogix linux refdesign for xilinx ml605 (big endian)" ; + mc->deprecation_reason ="big endian support is not tested" ; + }else { + mc->desc ="PetaLogix linux refdesign for xilinx ml605 (little endian)" ; + } mc->init = petalogix_ml605_init; }
hw/microblaze/xlnx-zynqmp-pmu.c +6 -6
@@ -181,12 +181,12 @@ static void xlnx_zynqmp_pmu_init(MachineState *machine)static void xlnx_zynqmp_pmu_machine_init (MachineClass *mc) { -#if TARGET_BIG_ENDIAN - mc->desc ="Xilinx ZynqMP PMU machine (big endian)" ; - mc->deprecation_reason ="big endian support is not tested" ; -#else - mc->desc ="Xilinx ZynqMP PMU machine (little endian)" ; -#endif +if (TARGET_BIG_ENDIAN ) { + mc->desc ="Xilinx ZynqMP PMU machine (big endian)" ; + mc->deprecation_reason ="big endian support is not tested" ; + }else { + mc->desc ="Xilinx ZynqMP PMU machine (little endian)" ; + } mc->init = xlnx_zynqmp_pmu_init; }
Signature · 1 line
2.47.1
Re: [PATCH 7/8] hw/microblaze: Evaluate TARGET_BIG_ENDIAN at compile time
Quoted 8 lines · Philippe Mathieu-Daudé
Rather than evaluating
TARGET_BIG_ENDIANat preprocessing time via #ifdef'ry, do it in C at compile timeSigned-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/microblaze/petalogix_ml605_mmu.c | 12 ++++++------ hw/microblaze/xlnx-zynqmp-pmu.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-)
r~
PATCH 8/8 gdbstub/helpers: Evaluate TARGET_BIG_ENDIAN at compile time
In reply to Philippe Mathieu-DaudéRather than evaluating TARGET_BIG_ENDIAN at preprocessing time via #ifdef'ry, do it in C at compile time
--- include/gdbstub/helpers.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
include/gdbstub/helpers.h +2 -9
@@ -56,17 +56,10 @@ static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi, uint64_t val_lo) {uint64_t to_quad; -#if TARGET_BIG_ENDIAN - to_quad =tswap64 (val_hi); + to_quad =tswap64 (TARGET_BIG_ENDIAN ? val_hi : val_lo);g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); - to_quad =tswap64 (val_lo); + to_quad =tswap64 (TARGET_BIG_ENDIAN ? val_lo : val_hi);g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); -#else - to_quad =tswap64 (val_lo); -g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); - to_quad =tswap64 (val_hi); -g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); -#endif return 16 ; }
Signature · 1 line
2.47.1
Re: [PATCH 8/8] gdbstub/helpers: Evaluate TARGET_BIG_ENDIAN at compile time
Quoted 4 lines · Philippe Mathieu-Daudé
Rather than evaluating
TARGET_BIG_ENDIANat preprocessing time via #ifdef'ry, do it in C at compile timeSigned-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH 8/8] gdbstub/helpers: Evaluate TARGET_BIG_ENDIAN at compile time
In reply to Philippe Mathieu-DaudéQuoted 22 lines · Philippe Mathieu-Daudé
Rather than evaluating
TARGET_BIG_ENDIANat preprocessing time via #ifdef'ry, do it in C at compile timeSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- include/gdbstub/helpers.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)include/gdbstub/helpers.h +2
-3@@ -56,17 +56,10 @@ static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi, uint64_t val_lo) {uint64_t to_quad; -#if TARGET_BIG_ENDIAN - to_quad =tswap64 (val_hi); + to_quad =tswap64 (TARGET_BIG_ENDIAN ? val_hi : val_lo);g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); - to_quad =tswap64 (val_lo); + to_quad =tswap64 (TARGET_BIG_ENDIAN ? val_lo : val_hi);
include/gdbstub/helpers.h static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi, · line 65
Quoted 10 lines
include/gdbstub/helpers.h +0
-6g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); -#else - to_quad =tswap64 (val_lo); -g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); - to_quad =tswap64 (val_hi); -g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); -#endif return 16 ; }
I'm not keen on using both TARGET_BIG_ENDIAN and tswap. I think this ought to be
uint64_t v0, v1;
if (TARGET_BIG_ENDIAN) {
v0 = cpu_to_be64(val_hi);
v1 = cpu_to_be64(val_lo);
} else {
v0 = cpu_to_le64(val_lo);
v1 = cpu_to_le64(val_hi);
}
g_byte_array_append(buf, (uint8_t *)&v0, 8);
g_byte_array_append(buf, (uint8_t *)&v1, 8);r~
Quoted 8 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (8):
linux-user/elfload: Usetarget_needs_bswap()
accel/kvm: Usetarget_needs_bswap()
target/mips: Check CPU endianness at runtime usingenv_is_bigendian()target/xtensa: Evaluate
TARGET_BIG_ENDIANat compile time hw/mips: EvaluateTARGET_BIG_ENDIANat compile time hw/microblaze: EvaluateTARGET_BIG_ENDIANat compile time
Reviewed patches queued, thanks.