Use target_big_endian() for the platform name, uname machine,
/proc/cpuinfo suffix and vDSO selection.

Preserve the behavior of the existing fixed-endian targets.

Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
 linux-user/arm/target_proc.h    | 18 +++++------------
 linux-user/arm/target_syscall.h |  6 +-----
 linux-user/arm/elfload.c        | 36 +++++++++++----------------------
 linux-user/uname.c              | 13 +++---------
 linux-user/arm/meson.build      |  4 ----
 5 files changed, 21 insertions(+), 56 deletions(-)

diff --git a/linux-user/arm/target_proc.h b/linux-user/arm/target_proc.h
index d3186ca655cf..d9e00371a4c7 100644
--- a/linux-user/arm/target_proc.h
+++ b/linux-user/arm/target_proc.h
@@ -18,12 +18,6 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)
     const char *elf_name;
     int num_cpus, len_part, len_var;
 
-#if TARGET_BIG_ENDIAN
-# define END_SUFFIX "b"
-#else
-# define END_SUFFIX "l"
-#endif
-
     arch = 8;
     elf_name = target_big_endian() ? "v8b" : "v8l";
     midr_rev = FIELD_EX32(midr, MIDR_EL1, REVISION);
@@ -41,29 +35,27 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)
             midr_var = (midr >> 16) & 0x7f;
             len_var = 2;
             if (arm_feature(&cpu->env, ARM_FEATURE_M)) {
-                elf_name = "armv7m" END_SUFFIX;
+                elf_name = target_big_endian() ? "armv7mb" : "armv7ml";
             } else {
-                elf_name = "armv7" END_SUFFIX;
+                elf_name = target_big_endian() ? "armv7b" : "armv7l";
             }
         } else {
             midr_part = midr >> 4;
             len_part = 7;
             if (arm_feature(&cpu->env, ARM_FEATURE_V6)) {
                 arch = 6;
-                elf_name = "armv6" END_SUFFIX;
+                elf_name = target_big_endian() ? "armv6b" : "armv6l";
             } else if (arm_feature(&cpu->env, ARM_FEATURE_V5)) {
                 arch = 5;
-                elf_name = "armv5t" END_SUFFIX;
+                elf_name = target_big_endian() ? "armv5tb" : "armv5tl";
             } else {
                 arch = 4;
-                elf_name = "armv4" END_SUFFIX;
+                elf_name = target_big_endian() ? "armv4b" : "armv4l";
             }
         }
     }
 #endif
 
-#undef END_SUFFIX
-
     num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
     for (int i = 0; i < num_cpus; i++) {
         dprintf(fd,
diff --git a/linux-user/arm/target_syscall.h b/linux-user/arm/target_syscall.h
index 8c4ddba71773..d344f614954c 100644
--- a/linux-user/arm/target_syscall.h
+++ b/linux-user/arm/target_syscall.h
@@ -10,11 +10,7 @@
 #define ARM_NR_set_tls   (ARM_NR_BASE + 5)
 #define ARM_NR_get_tls    (ARM_NR_BASE + 6)
 
-#if TARGET_BIG_ENDIAN
-#define UNAME_MACHINE "armv5teb"
-#else
-#define UNAME_MACHINE "armv5tel"
-#endif
+#define UNAME_MACHINE (target_big_endian() ? "armv5teb" : "armv5tel")
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_CLONE_BACKWARDS
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index ce69bf054273..baa04851caf2 100644
--- a/linux-user/arm/elfload.c
+++ b/linux-user/arm/elfload.c
@@ -179,29 +179,21 @@ const char *get_elf_platform(CPUState *cs)
 {
     CPUARMState *env = cpu_env(cs);
 
-#if TARGET_BIG_ENDIAN
-# define END  "b"
-#else
-# define END  "l"
-#endif
-
     if (arm_feature(env, ARM_FEATURE_V8)) {
-        return "v8" END;
+        return target_big_endian() ? "v8b" : "v8l";
     } else if (arm_feature(env, ARM_FEATURE_V7)) {
         if (arm_feature(env, ARM_FEATURE_M)) {
-            return "v7m" END;
+            return target_big_endian() ? "v7mb" : "v7ml";
         } else {
-            return "v7" END;
+            return target_big_endian() ? "v7b" : "v7l";
         }
     } else if (arm_feature(env, ARM_FEATURE_V6)) {
-        return "v6" END;
+        return target_big_endian() ? "v6b" : "v6l";
     } else if (arm_feature(env, ARM_FEATURE_V5)) {
-        return "v5" END;
+        return target_big_endian() ? "v5b" : "v5l";
     } else {
-        return "v4" END;
+        return target_big_endian() ? "v4b" : "v4l";
     }
-
-#undef END
 }
 
 bool init_guest_commpage(void)
@@ -257,21 +249,17 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const 
CPUARMState *env)
     r->pt.orig_r0 = tswapal(env->regs[0]); /* FIXME */
 }
 
-#if TARGET_BIG_ENDIAN
 # include "vdso-be8.c.inc"
 # include "vdso-be32.c.inc"
-#else
 # include "vdso-le.c.inc"
-#endif
 
 const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags)
 {
-#if TARGET_BIG_ENDIAN
-    return (EF_ARM_EABI_VERSION(elf_flags) >= EF_ARM_EABI_VER4
-            && (elf_flags & EF_ARM_BE8)
-            ? &vdso_be8_image_info
-            : &vdso_be32_image_info);
-#else
+    if (target_big_endian()) {
+        return (EF_ARM_EABI_VERSION(elf_flags) >= EF_ARM_EABI_VER4
+                && (elf_flags & EF_ARM_BE8)
+                ? &vdso_be8_image_info
+                : &vdso_be32_image_info);
+    }
     return &vdso_image_info;
-#endif
 }
diff --git a/linux-user/uname.c b/linux-user/uname.c
index 32f71f24920d..0f4658bff151 100644
--- a/linux-user/uname.c
+++ b/linux-user/uname.c
@@ -38,20 +38,13 @@ const char *cpu_to_uname_machine(CPUArchState *cpu_env)
      * see arch/arm/kernel/setup.c: setup_processor()
      */
 
-    /* in theory, endianness is configurable on some ARM CPUs, but this isn't
-     * used in user mode emulation */
-#if TARGET_BIG_ENDIAN
-#define utsname_suffix "b"
-#else
-#define utsname_suffix "l"
-#endif
     if (arm_feature(cpu_env, ARM_FEATURE_V7))
-        return "armv7" utsname_suffix;
+        return target_big_endian() ? "armv7b" : "armv7l";
     if (arm_feature(cpu_env, ARM_FEATURE_V6))
-        return "armv6" utsname_suffix;
+        return target_big_endian() ? "armv6b" : "armv6l";
     /* earliest emulated CPU is ARMv5TE; qemu can emulate the 1026, but not its
      * Jazelle support */
-    return "armv5te" utsname_suffix;
+    return target_big_endian() ? "armv5teb" : "armv5tel";
 #elif defined(TARGET_I386) && !defined(TARGET_X86_64)
     /* see arch/x86/kernel/cpu/bugs.c: check_bugs(), 386, 486, 586, 686 */
     CPUState *cpu = env_cpu(cpu_env);
diff --git a/linux-user/arm/meson.build b/linux-user/arm/meson.build
index 348ffb810d7f..47faf42eef6c 100644
--- a/linux-user/arm/meson.build
+++ b/linux-user/arm/meson.build
@@ -6,10 +6,6 @@ syscall_nr_generators += {
                    output: '@BASENAME@_nr.h')
 }
 
-# TARGET_BIG_ENDIAN is defined to 'n' for little-endian; which means it
-# is always true as far as source_set.apply() is concerned.  Always build
-# both header files and include the right one via #if.
-
 vdso_be8_inc = gen_vdso.process('vdso-be8.so',
                                extra_args: ['-s', 'sigreturn_codes',
                                             '-p', 'vdso_be8'])
-- 
2.55.0

Reply via email to