Commit 1bfbe1fc5a for qemu.org

commit 1bfbe1fc5a6741fdddc64e762c20bb9b38133673
Author: Philippe Mathieu-Daudé <philmd@linaro.org>
Date:   Fri Feb 13 15:14:33 2026 +0100

    system: Make qemu_arch_available() common code

    Remove the need of per-target QEMU_ARCH. Define the
    QEMU_ARCH_* constants based on SYS_EMU_TARGET_* ones,
    themselves already exposed via target_arch(), allowing
    to check the current target is included in @arch_bitmask.

    Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
    Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
    Reviewed-by: Thomas Huth <thuth@redhat.com>
    Message-Id: <20260213175032.32121-5-philmd@linaro.org>

diff --git a/include/system/arch_init.h b/include/system/arch_init.h
index 92d50ba8d6..bb17d18a2b 100644
--- a/include/system/arch_init.h
+++ b/include/system/arch_init.h
@@ -1,30 +1,44 @@
 #ifndef QEMU_ARCH_INIT_H
 #define QEMU_ARCH_INIT_H

+#include "qapi/qapi-types-machine.h"

 enum {
-    QEMU_ARCH_ALL = -1,
-    QEMU_ARCH_ALPHA = (1 << 0),
-    QEMU_ARCH_ARM = (1 << 1),
-    QEMU_ARCH_I386 = (1 << 3),
-    QEMU_ARCH_M68K = (1 << 4),
-    QEMU_ARCH_MICROBLAZE = (1 << 6),
-    QEMU_ARCH_MIPS = (1 << 7),
-    QEMU_ARCH_PPC = (1 << 8),
-    QEMU_ARCH_S390X = (1 << 9),
-    QEMU_ARCH_SH4 = (1 << 10),
-    QEMU_ARCH_SPARC = (1 << 11),
-    QEMU_ARCH_XTENSA = (1 << 12),
-    QEMU_ARCH_OR1K = (1 << 13),
-    QEMU_ARCH_TRICORE = (1 << 16),
-    QEMU_ARCH_HPPA = (1 << 18),
-    QEMU_ARCH_RISCV = (1 << 19),
-    QEMU_ARCH_RX = (1 << 20),
-    QEMU_ARCH_AVR = (1 << 21),
-    QEMU_ARCH_HEXAGON = (1 << 22),
-    QEMU_ARCH_LOONGARCH = (1 << 23),
+    QEMU_ARCH_ALPHA =       (1UL << SYS_EMU_TARGET_ALPHA),
+    QEMU_ARCH_ARM =         (1UL << SYS_EMU_TARGET_ARM) |
+                            (1UL << SYS_EMU_TARGET_AARCH64),
+    QEMU_ARCH_I386 =        (1UL << SYS_EMU_TARGET_I386) |
+                            (1UL << SYS_EMU_TARGET_X86_64),
+    QEMU_ARCH_M68K =        (1UL << SYS_EMU_TARGET_M68K),
+    QEMU_ARCH_MICROBLAZE =  (1UL << SYS_EMU_TARGET_MICROBLAZE) |
+                            (1UL << SYS_EMU_TARGET_MICROBLAZEEL),
+    QEMU_ARCH_MIPS =        (1UL << SYS_EMU_TARGET_MIPS) |
+                            (1UL << SYS_EMU_TARGET_MIPSEL) |
+                            (1UL << SYS_EMU_TARGET_MIPS64) |
+                            (1UL << SYS_EMU_TARGET_MIPS64EL),
+    QEMU_ARCH_PPC =         (1UL << SYS_EMU_TARGET_PPC) |
+                            (1UL << SYS_EMU_TARGET_PPC64),
+    QEMU_ARCH_S390X =       (1UL << SYS_EMU_TARGET_S390X),
+    QEMU_ARCH_SH4 =         (1UL << SYS_EMU_TARGET_SH4) |
+                            (1UL << SYS_EMU_TARGET_SH4EB),
+    QEMU_ARCH_SPARC =       (1UL << SYS_EMU_TARGET_SPARC) |
+                            (1UL << SYS_EMU_TARGET_SPARC64),
+    QEMU_ARCH_XTENSA =      (1UL << SYS_EMU_TARGET_XTENSA) |
+                            (1UL << SYS_EMU_TARGET_XTENSAEB),
+    QEMU_ARCH_OR1K =        (1UL << SYS_EMU_TARGET_OR1K),
+    QEMU_ARCH_TRICORE =     (1UL << SYS_EMU_TARGET_TRICORE),
+    QEMU_ARCH_HPPA =        (1UL << SYS_EMU_TARGET_HPPA),
+    QEMU_ARCH_RISCV =       (1UL << SYS_EMU_TARGET_RISCV32) |
+                            (1UL << SYS_EMU_TARGET_RISCV64),
+    QEMU_ARCH_RX =          (1UL << SYS_EMU_TARGET_RX),
+    QEMU_ARCH_AVR =         (1UL << SYS_EMU_TARGET_AVR),
+    QEMU_ARCH_HEXAGON =     (1UL << SYS_EMU_TARGET_HEXAGON),
+    QEMU_ARCH_LOONGARCH =   (1UL << SYS_EMU_TARGET_LOONGARCH64),
+    QEMU_ARCH_ALL =         UINT32_MAX,
 };

+QEMU_BUILD_BUG_ON(SYS_EMU_TARGET__MAX > 32);
+
 /**
  * qemu_arch_available:
  * @arch_bitmask: bitmask of QEMU_ARCH_* constants
diff --git a/meson.build b/meson.build
index 59c8204d88..4eeef55274 100644
--- a/meson.build
+++ b/meson.build
@@ -3375,8 +3375,6 @@ foreach target : target_dirs
       config_target_data.set(k, v)
     endif
   endforeach
-  config_target_data.set('QEMU_ARCH',
-                         'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
   config_target_h += {target: configure_file(output: target + '-config-target.h',
                                                configuration: config_target_data)}

diff --git a/system/arch_init.c b/system/arch_init.c
index ec9e45a1a8..604d5909ed 100644
--- a/system/arch_init.c
+++ b/system/arch_init.c
@@ -23,8 +23,10 @@
  */
 #include "qemu/osdep.h"
 #include "system/arch_init.h"
+#include "qemu/bitops.h"
+#include "qemu/target-info-qapi.h"

 bool qemu_arch_available(uint32_t arch_bitmask)
 {
-    return arch_bitmask & QEMU_ARCH;
+    return extract32(arch_bitmask, target_arch(), 1);
 }
diff --git a/system/meson.build b/system/meson.build
index 035f0ae7de..579e8353d5 100644
--- a/system/meson.build
+++ b/system/meson.build
@@ -1,12 +1,9 @@
-specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
-  'arch_init.c',
-)])
-
 system_ss.add(files(
   'vl.c',
 ), sdl, libpmem, libdaxctl)

 system_ss.add(files(
+  'arch_init.c',
   'balloon.c',
   'bootdevice.c',
   'cpus.c',