]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
linux-user: Move get_elf_cpu_model to target/elfload.c
authorRichard Henderson <richard.henderson@linaro.org>
Tue, 29 Jul 2025 20:09:57 +0000 (10:09 -1000)
committerRichard Henderson <richard.henderson@linaro.org>
Wed, 27 Aug 2025 20:39:25 +0000 (06:39 +1000)
Rename from cpu_get_model to emphasize that this is an elf-specific
function.  Declare the function once in loader.h.

This frees up target_elf.h for other uses.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
39 files changed:
linux-user/aarch64/elfload.c
linux-user/aarch64/target_elf.h
linux-user/alpha/elfload.c
linux-user/alpha/target_elf.h
linux-user/arm/elfload.c
linux-user/arm/target_elf.h
linux-user/hexagon/elfload.c
linux-user/hexagon/target_elf.h
linux-user/hppa/elfload.c
linux-user/hppa/target_elf.h
linux-user/i386/elfload.c
linux-user/i386/target_elf.h
linux-user/loader.h
linux-user/loongarch64/elfload.c
linux-user/loongarch64/target_elf.h
linux-user/m68k/elfload.c
linux-user/m68k/target_elf.h
linux-user/main.c
linux-user/microblaze/elfload.c
linux-user/microblaze/target_elf.h
linux-user/mips/elfload.c
linux-user/mips/target_elf.h
linux-user/mips64/target_elf.h
linux-user/openrisc/elfload.c
linux-user/openrisc/target_elf.h
linux-user/ppc/elfload.c
linux-user/ppc/target_elf.h
linux-user/riscv/elfload.c
linux-user/riscv/target_elf.h
linux-user/s390x/elfload.c
linux-user/s390x/target_elf.h
linux-user/sh4/elfload.c
linux-user/sh4/target_elf.h
linux-user/sparc/elfload.c
linux-user/sparc/target_elf.h
linux-user/x86_64/elfload.c
linux-user/x86_64/target_elf.h
linux-user/xtensa/elfload.c
linux-user/xtensa/target_elf.h

index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..b92442dfeb2a8adfac5add6d9036c53c2c88f9f4 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "any";
+}
index a7eb962fba754c1d99a534a21ad3cec8b1473d38..d955b3d07f90123eb79fb0d0c059c54dad03e769 100644 (file)
@@ -7,8 +7,5 @@
 
 #ifndef AARCH64_TARGET_ELF_H
 #define AARCH64_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "any";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..1e44475c47586bb5c624d187e16b9de915e182bc 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "ev67";
+}
index b77d638f6d4a8652344509010d0220945b2968a1..52b68680ad35bf472a515d25d3b6b930b3393c85 100644 (file)
@@ -7,8 +7,5 @@
 
 #ifndef ALPHA_TARGET_ELF_H
 #define ALPHA_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "ev67";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..b92442dfeb2a8adfac5add6d9036c53c2c88f9f4 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "any";
+}
index 58ff6a0986fbe2bad2103b673c969aae58a023f3..2abb27a733775d352aa9913b1f97249a6d45be25 100644 (file)
@@ -7,8 +7,5 @@
 
 #ifndef ARM_TARGET_ELF_H
 #define ARM_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "any";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..d8b545032ab61c9f7c602344db964d521cc0284a 100644 (file)
@@ -1 +1,35 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    static char buf[32];
+    int err;
+
+    /* For now, treat anything newer than v5 as a v73 */
+    /* FIXME - Disable instructions that are newer than the specified arch */
+    if (eflags == 0x04 ||    /* v5  */
+        eflags == 0x05 ||    /* v55 */
+        eflags == 0x60 ||    /* v60 */
+        eflags == 0x61 ||    /* v61 */
+        eflags == 0x62 ||    /* v62 */
+        eflags == 0x65 ||    /* v65 */
+        eflags == 0x66 ||    /* v66 */
+        eflags == 0x67 ||    /* v67 */
+        eflags == 0x8067 ||  /* v67t */
+        eflags == 0x68 ||    /* v68 */
+        eflags == 0x69 ||    /* v69 */
+        eflags == 0x71 ||    /* v71 */
+        eflags == 0x8071 ||  /* v71t */
+        eflags == 0x73       /* v73 */
+       ) {
+        return "v73";
+    }
+
+    err = snprintf(buf, sizeof(buf), "unknown (0x%x)", eflags);
+    return err >= 0 && err < sizeof(buf) ? buf : "unknown";
+}
index 36056fc9f016ee12cbe42de6ccade380134f40cd..eccf207f6b5b21fa94610693701dffcdfb398e34 100644 (file)
 #ifndef HEXAGON_TARGET_ELF_H
 #define HEXAGON_TARGET_ELF_H
 
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    static char buf[32];
-    int err;
-
-    /* For now, treat anything newer than v5 as a v73 */
-    /* FIXME - Disable instructions that are newer than the specified arch */
-    if (eflags == 0x04 ||    /* v5  */
-        eflags == 0x05 ||    /* v55 */
-        eflags == 0x60 ||    /* v60 */
-        eflags == 0x61 ||    /* v61 */
-        eflags == 0x62 ||    /* v62 */
-        eflags == 0x65 ||    /* v65 */
-        eflags == 0x66 ||    /* v66 */
-        eflags == 0x67 ||    /* v67 */
-        eflags == 0x8067 ||  /* v67t */
-        eflags == 0x68 ||    /* v68 */
-        eflags == 0x69 ||    /* v69 */
-        eflags == 0x71 ||    /* v71 */
-        eflags == 0x8071 ||  /* v71t */
-        eflags == 0x73       /* v73 */
-       ) {
-        return "v73";
-    }
-
-    err = snprintf(buf, sizeof(buf), "unknown (0x%x)", eflags);
-    return err >= 0 && err < sizeof(buf) ? buf : "unknown";
-}
-
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..2274fcbde435d6e661ebbb9772604de413fde859 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "hppa";
+}
index 19cae8bd65ddc6326b55c0df277c6ff1c82bcc51..5826ca2cd22f61de4aad886ad950f4930354951c 100644 (file)
@@ -7,8 +7,5 @@
 
 #ifndef HPPA_TARGET_ELF_H
 #define HPPA_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "hppa";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..f92adb73085b9b094e2f7a0132162b4476fdbb17 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "max";
+}
index 238a9aba738a0a855055e4616801365796f82080..e6f0d8fa4e6796eeddfbd3052cd7b40013bc0e04 100644 (file)
@@ -7,8 +7,5 @@
 
 #ifndef I386_TARGET_ELF_H
 #define I386_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "max";
-}
+
 #endif
index e102e6f4108f470c08c6c755d1a8bcf91a8afbb4..75ee9975a08d33f5654f2c55ba5d5076965842a1 100644 (file)
@@ -98,6 +98,9 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
 
 extern unsigned long guest_stack_size;
 
+/* Note that Elf32 and Elf64 use uint32_t for e_flags. */
+const char *get_elf_cpu_model(uint32_t eflags);
+
 #if defined(TARGET_S390X) || defined(TARGET_AARCH64) || defined(TARGET_ARM)
 uint32_t get_elf_hwcap(void);
 const char *elf_hwcap_str(uint32_t bit);
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..874dc4c2304778122a6ac183af33f4173fe101e1 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "la464";
+}
index 95c3f05a46d8728f4e488e77632310356bf8ca80..39a08d35d9ba23869066c52fed838b73916cde6b 100644 (file)
@@ -5,8 +5,5 @@
 
 #ifndef LOONGARCH_TARGET_ELF_H
 #define LOONGARCH_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "la464";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..561ac5b3b3a7d05d988af485a016abcf2285d667 100644 (file)
@@ -1 +1,18 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+#include "elf.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    if (eflags == 0 || (eflags & EF_M68K_M68000)) {
+        /* 680x0 */
+        return "m68040";
+    }
+
+    /* Coldfire */
+    return "any";
+}
index 998fe0fe2f32241f8366cd021fc6b783190da720..62ff9d38d4cdbeb8bb16261e68a52ba6994f176a 100644 (file)
@@ -7,14 +7,5 @@
 
 #ifndef M68K_TARGET_ELF_H
 #define M68K_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    if (eflags == 0 || (eflags & EF_M68K_M68000)) {
-        /* 680x0 */
-        return "m68040";
-    }
 
-    /* Coldfire */
-    return "any";
-}
 #endif
index 68972f00a155a14fd47bb93aa64733bfa332e3c8..ad1a29d1989d4a64936c16c9046ee578378d7e7b 100644 (file)
@@ -49,7 +49,6 @@
 #include "qemu/guest-random.h"
 #include "elf.h"
 #include "trace/control.h"
-#include "target_elf.h"
 #include "user/cpu_loop.h"
 #include "crypto/init.h"
 #include "fd-trans.h"
@@ -809,7 +808,7 @@ int main(int argc, char **argv, char **envp)
     }
 
     if (cpu_model == NULL) {
-        cpu_model = cpu_get_model(get_elf_eflags(execfd));
+        cpu_model = get_elf_cpu_model(get_elf_eflags(execfd));
     }
     cpu_type = parse_cpu_option(cpu_model);
 
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..b92442dfeb2a8adfac5add6d9036c53c2c88f9f4 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "any";
+}
index 8a8f1debff9e7cf78af9ba22bb0b9adc032e4aff..bfe2997fd237c0e3abcf4ec2a4a6d7c4b0e2db6d 100644 (file)
@@ -7,8 +7,5 @@
 
 #ifndef MICROBLAZE_TARGET_ELF_H
 #define MICROBLAZE_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "any";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..04e3b7674010b791adc37460d0abf161934b2a72 100644 (file)
@@ -1 +1,44 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+#include "elf.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+#ifdef TARGET_MIPS64
+    switch (eflags & EF_MIPS_MACH) {
+    case EF_MIPS_MACH_OCTEON:
+    case EF_MIPS_MACH_OCTEON2:
+    case EF_MIPS_MACH_OCTEON3:
+        return "Octeon68XX";
+    case EF_MIPS_MACH_LS2E:
+        return "Loongson-2E";
+    case EF_MIPS_MACH_LS2F:
+        return "Loongson-2F";
+    case EF_MIPS_MACH_LS3A:
+        return "Loongson-3A1000";
+    default:
+        break;
+    }
+    switch (eflags & EF_MIPS_ARCH) {
+    case EF_MIPS_ARCH_64R6:
+        return "I6400";
+    case EF_MIPS_ARCH_64R2:
+        return "MIPS64R2-generic";
+    default:
+        break;
+    }
+    return "5KEf";
+#else
+    if ((eflags & EF_MIPS_ARCH) == EF_MIPS_ARCH_32R6) {
+        return "mips32r6-generic";
+    }
+    if (eflags & EF_MIPS_NAN2008) {
+        return "P5600";
+    }
+    return "24Kf";
+#endif
+}
index 71a32315a858a18a800e4c5f568898289ba28455..febf710c7aeb49dc4ecce028cd9d93f1b552a28f 100644 (file)
@@ -7,14 +7,5 @@
 
 #ifndef MIPS_TARGET_ELF_H
 #define MIPS_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    if ((eflags & EF_MIPS_ARCH) == EF_MIPS_ARCH_32R6) {
-        return "mips32r6-generic";
-    }
-    if (eflags & EF_MIPS_NAN2008) {
-        return "P5600";
-    }
-    return "24Kf";
-}
+
 #endif
index 502af9d2781d57b877290ba63571766297e7607d..02e6d14840aed8686e7325797de17b581895a726 100644 (file)
@@ -7,30 +7,5 @@
 
 #ifndef MIPS64_TARGET_ELF_H
 #define MIPS64_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    switch (eflags & EF_MIPS_MACH) {
-    case EF_MIPS_MACH_OCTEON:
-    case EF_MIPS_MACH_OCTEON2:
-    case EF_MIPS_MACH_OCTEON3:
-        return "Octeon68XX";
-    case EF_MIPS_MACH_LS2E:
-        return "Loongson-2E";
-    case EF_MIPS_MACH_LS2F:
-        return "Loongson-2F";
-    case EF_MIPS_MACH_LS3A:
-        return "Loongson-3A1000";
-    default:
-        break;
-    }
-    switch (eflags & EF_MIPS_ARCH) {
-    case EF_MIPS_ARCH_64R6:
-        return "I6400";
-    case EF_MIPS_ARCH_64R2:
-        return "MIPS64R2-generic";
-    default:
-        break;
-    }
-    return "5KEf";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..b92442dfeb2a8adfac5add6d9036c53c2c88f9f4 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "any";
+}
index 265ecd30794d4901f05db9ccaaaa4b371ad1d1f5..b34f2ff672da7b3735f958dd29cddd03cd1e6324 100644 (file)
@@ -7,8 +7,5 @@
 
 #ifndef OPENRISC_TARGET_ELF_H
 #define OPENRISC_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "any";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..7775dc06fac08badd01601cea807ecb4052fe27f 100644 (file)
@@ -1 +1,15 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+#ifdef TARGET_PPC64
+    return "POWER9";
+#else
+    return "750";
+#endif
+}
index 061661885423f6816f5c048c059956e5ada59f4b..8c0a8ea431268c5956c43fbb4ce9ce87d79140e3 100644 (file)
@@ -7,12 +7,5 @@
 
 #ifndef PPC_TARGET_ELF_H
 #define PPC_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-#ifdef TARGET_PPC64
-    return "POWER9";
-#else
-    return "750";
-#endif
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..f92adb73085b9b094e2f7a0132162b4476fdbb17 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "max";
+}
index dedd5956f3afea58035387910d7ec536d63828a9..bfe86105d0322b1980cf28f588d15091d24c3dfb 100644 (file)
@@ -7,8 +7,5 @@
 
 #ifndef RISCV_TARGET_ELF_H
 #define RISCV_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "max";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..989953a247ed57e07bf469133a1cb0f2dbb54957 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "qemu";
+}
index 8114b59c1d67a78e1f3a9eceb7285e8c508551c2..e51b053339f90314350361ced47b80efbf7d6953 100644 (file)
@@ -7,8 +7,5 @@
 
 #ifndef S390X_TARGET_ELF_H
 #define S390X_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "qemu";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..546034ec07ec890b212d2f96c322a051c4573fc6 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "sh7785";
+}
index f485e0cef279b61ec24e37fa300088402e2b1cc7..d17011bd752efc133fab926ebca76846429e085d 100644 (file)
@@ -7,8 +7,5 @@
 
 #ifndef SH4_TARGET_ELF_H
 #define SH4_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "sh7785";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..243e6f9b66a6e52bbe0205fd6767fb0eb5f8ad14 100644 (file)
@@ -1 +1,15 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+#ifdef TARGET_SPARC64
+    return "TI UltraSparc II";
+#else
+    return "Fujitsu MB86904";
+#endif
+}
index a510ceb6129ce4feb9befc1f51e3e82d89fc36e3..7e46748d261f900a483efeee73361fd94f01ceeb 100644 (file)
@@ -7,12 +7,5 @@
 
 #ifndef SPARC_TARGET_ELF_H
 #define SPARC_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-#ifdef TARGET_SPARC64
-    return "TI UltraSparc II";
-#else
-    return "Fujitsu MB86904";
-#endif
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..f92adb73085b9b094e2f7a0132162b4476fdbb17 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "max";
+}
index 3f628f8d66197faae698cbec4e244ba4e4950f19..5849f96350161335f57e3e34cade1be0d489da08 100644 (file)
@@ -7,8 +7,5 @@
 
 #ifndef X86_64_TARGET_ELF_H
 #define X86_64_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "max";
-}
+
 #endif
index 73fa78ef14ea5ec208df4358dd64d3b7f4b25880..e35ba69a109a3bc8470ae0eedc73221aef3761f0 100644 (file)
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return XTENSA_DEFAULT_CPU_MODEL;
+}
index a9a3fabd89bea8de8e4841a1968977aedd7418cd..2c55c22e14b612a86dca1f370c30947bd13d4e4b 100644 (file)
@@ -8,9 +8,4 @@
 #ifndef XTENSA_TARGET_ELF_H
 #define XTENSA_TARGET_ELF_H
 
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return XTENSA_DEFAULT_CPU_MODEL;
-}
-
 #endif