Skip to contentSkip to conversation

qemu: Remove TARGET_NAME definition

RFC PATCH In review Philippe Mathieu-Daudé 6 participants 33 messages Mar 5, 2025 – Mar 11, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover qemu: Remove TARGET_NAME definition

Replace all TARGET_NAME uses by target_name() runtime, then remove the definition and poison it.

While is looks like another cleanup, it is a small step required for the single binary project.

Alex Bennée (1):
plugins/loader: populate target_name with target_name()

Philippe Mathieu-Daudé (10):
system: Extract target-specific globals to their own compilation unit
system: Open-code qemu_init_arch_modules() using target_name()
system: Introduce QemuArchBit enum
system: Replace arch_type global by qemu_arch_available() helper
include: Expose QemuArchBit enum to user emulation
include: Declare target_name() in common "qemu/arch_info.h" tests/qtest: Replace TARGET_NAME -> target_name()
user: Replace TARGET_NAME -> target_name()
qemu: Introduce qemu_arch_name() helper
qemu: Remove C definitions of TARGET_NAME

 meson.build                     | 10 +++--
 include/exec/poison.h           |  1 -
 include/hw/core/cpu.h           |  2 -
 include/qemu/arch_info.h        | 55 +++++++++++++++++++++++++++
 include/qemu/osdep.h            |  2 +
 include/system/arch_init.h      | 32 ----------------
 arch_info-target.c              | 67 +++++++++++++++++++++++++++++++++
 bsd-user/main.c                 |  9 +++--
 cpu-target.c                    |  5 ---
 hw/core/machine-qmp-cmds.c      |  1 +
 hw/scsi/scsi-disk.c             |  4 +-
 linux-user/main.c               | 12 +++---
 plugins/loader.c                |  3 +-
 system/arch_init.c              | 50 ------------------------
 system/globals-target.c         | 24 ++++++++++++
 system/qdev-monitor.c           |  6 +--
 system/vl.c                     | 14 ++++---
 tests/qtest/fuzz/fuzz.c         |  5 +--
 tests/qtest/fuzz/generic_fuzz.c |  4 +-
 tests/qtest/fuzz/i440fx_fuzz.c  |  5 ++-
 tests/qtest/fuzz/qos_fuzz.c     |  5 ++-
 system/meson.build              |  2 +-
 22 files changed, 195 insertions(+), 123 deletions(-)
 create mode 100644 include/qemu/arch_info.h
 delete mode 100644 include/system/arch_init.h
 create mode 100644 arch_info-target.c
 delete mode 100644 system/arch_init.c
 create mode 100644 system/globals-target.c
Signature · 1 line
2.47.1
#1 lore raw

RFC PATCH 1/11 system: Extract target-specific globals to their own compilation unit

We shouldn't use target specific globals for machine properties. These ones could be desugarized, as explained in [*]. While certainly doable, not trivial nor my priority for now. Just move them to a different file to clarify they are *globals*, like the generic globals residing in system/globals.c.

[*] https://lore.kernel.org/qemu-devel/[email protected]/

---
 system/arch_init.c      | 14 --------------
 system/globals-target.c | 24 ++++++++++++++++++++++++
 system/meson.build      |  1 +
 3 files changed, 25 insertions(+), 14 deletions(-)
 create mode 100644 system/globals-target.c
system/arch_init.c +0 -14
index d2c32f84887..ea0842b7410 100644
@@ -25,20 +25,6 @@
 #include "qemu/module.h"
 #include "system/arch_init.h"
 
-#ifdef TARGET_SPARC
-int graphic_width = 1024;
-int graphic_height = 768;
-int graphic_depth = 8;
-#elif defined(TARGET_M68K)
-int graphic_width = 800;
-int graphic_height = 600;
-int graphic_depth = 8;
-#else
-int graphic_width = 800;
-int graphic_height = 600;
-int graphic_depth = 32;
-#endif
-
 const uint32_t arch_type = QEMU_ARCH;
 
 void qemu_init_arch_modules(void)
system/globals-target.c new file +24 -0
new file mode 100644
index 00000000000..989720591e7
@@ -0,0 +1,24 @@
+/*
+ * Global variables that should not exist (target specific)
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "qemu/osdep.h"
+#include "system/system.h"
+
+#ifdef TARGET_SPARC
+int graphic_width = 1024;
+int graphic_height = 768;
+int graphic_depth = 8;
+#elif defined(TARGET_M68K)
+int graphic_width = 800;
+int graphic_height = 600;
+int graphic_depth = 8;
+#else
+int graphic_width = 800;
+int graphic_height = 600;
+int graphic_depth = 32;
+#endif
system/meson.build +1 -0
index 4952f4b2c7d..181195410fb 100644
@@ -1,6 +1,7 @@
 specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
   'arch_init.c',
   'ioport.c',
+  'globals-target.c',
   'memory.c',
   'physmem.c',
   'watchpoint.c',
Signature · 1 line
2.47.1
#2 lore raw

Re: [RFC PATCH 01/11] system: Extract target-specific globals to their own compilation unit

Quoted 6 lines · Philippe Mathieu-Daudé

We shouldn't use target specific globals for machine properties. These ones could be desugarized, as explained in [*]. While certainly doable, not trivial nor my priority for now. Just move them to a different file to clarify they are *globals*, like the generic globals residing in system/globals.c.

Maybe those could be set globally to the default:
int graphic_width = 800;
int graphic_height = 600;
int graphic_depth = 32;

And override them for sparc and m68k in qemu_init_arch_modules function, using qemu_arch_name(). This way, no need to have a new file to hold them.

Quoted 77 lines

[*] https://lore.kernel.org/qemu-devel/[email protected]/

---
  system/arch_init.c      | 14 --------------
  system/globals-target.c | 24 ++++++++++++++++++++++++
  system/meson.build      |  1 +
  3 files changed, 25 insertions(+), 14 deletions(-)

create mode 100644 system/globals-target.c

system/arch_init.c +0 -14
index d2c32f84887..ea0842b7410 100644
@@ -25,20 +25,6 @@
  #include "qemu/module.h"
  #include "system/arch_init.h"
 
-#ifdef TARGET_SPARC
-int graphic_width = 1024;
-int graphic_height = 768;
-int graphic_depth = 8;
-#elif defined(TARGET_M68K)
-int graphic_width = 800;
-int graphic_height = 600;
-int graphic_depth = 8;
-#else
-int graphic_width = 800;
-int graphic_height = 600;
-int graphic_depth = 32;
-#endif
-
  const uint32_t arch_type = QEMU_ARCH;
 
  void qemu_init_arch_modules(void)
system/globals-target.c new file +24 -0
new file mode 100644
index 00000000000..989720591e7
@@ -0,0 +1,24 @@
+/*
+ * Global variables that should not exist (target specific)
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "qemu/osdep.h"
+#include "system/system.h"
+
+#ifdef TARGET_SPARC
+int graphic_width = 1024;
+int graphic_height = 768;
+int graphic_depth = 8;
+#elif defined(TARGET_M68K)
+int graphic_width = 800;
+int graphic_height = 600;
+int graphic_depth = 8;
+#else
+int graphic_width = 800;
+int graphic_height = 600;
+int graphic_depth = 32;
+#endif
system/meson.build +1 -0
index 4952f4b2c7d..181195410fb 100644
@@ -1,6 +1,7 @@
  specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
    'arch_init.c',
    'ioport.c',
+  'globals-target.c',
    'memory.c',
    'physmem.c',
    'watchpoint.c',
#3 lore raw

Re: [RFC PATCH 01/11] system: Extract target-specific globals to their own compilation unit

Quoted 8 lines · Pierrick Bouvier
Quoted 6 lines · Philippe Mathieu-Daudé

We shouldn't use target specific globals for machine properties. These ones could be desugarized, as explained in [*]. While certainly doable, not trivial nor my priority for now. Just move them to a different file to clarify they are *globals*, like the generic globals residing in system/globals.c.

Quoted 7 lines

Maybe those could be set globally to the default:
int graphic_width = 800;
int graphic_height = 600;
int graphic_depth = 32;

And override them for sparc and m68k in qemu_init_arch_modules function, using qemu_arch_name(). This way, no need to have a new file to hold them.

This is not what Paolo explained ...

Quoted 2 lines
Quoted 2 lines

[*] https://lore.kernel.org/qemu-devel/e514d6db-781d-4afe- [email protected]/

... here ^, but maybe I misunderstood him.

Doing the '-g' CLI change is not my priority, and I welcome any developer willing to help :) Here I'm just trying to make sense of that arch_init.c file.

Quoted 74 lines
Quoted 73 lines

---
  system/arch_init.c      | 14 -------------- system/globals-target.c | 24 ++++++++++++++++++++++++ system/meson.build      |  1 +

  3 files changed, 25 insertions(+), 14 deletions(-)

  create mode 100644 system/globals-target.c

system/arch_init.c +0 -14
index d2c32f84887..ea0842b7410 100644
@@ -25,20 +25,6 @@
   #include "qemu/module.h"
   #include "system/arch_init.h"
-#ifdef TARGET_SPARC
-int graphic_width = 1024;
-int graphic_height = 768;
-int graphic_depth = 8;
-#elif defined(TARGET_M68K)
-int graphic_width = 800;
-int graphic_height = 600;
-int graphic_depth = 8;
-#else
-int graphic_width = 800;
-int graphic_height = 600;
-int graphic_depth = 32;
-#endif
-
   const uint32_t arch_type = QEMU_ARCH;
   void qemu_init_arch_modules(void)
system/globals-target.c new file +24 -0
new file mode 100644
index 00000000000..989720591e7
@@ -0,0 +1,24 @@
+/*
+ * Global variables that should not exist (target specific)
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "qemu/osdep.h"
+#include "system/system.h"
+
+#ifdef TARGET_SPARC
+int graphic_width = 1024;
+int graphic_height = 768;
+int graphic_depth = 8;
+#elif defined(TARGET_M68K)
+int graphic_width = 800;
+int graphic_height = 600;
+int graphic_depth = 8;
+#else
+int graphic_width = 800;
+int graphic_height = 600;
+int graphic_depth = 32;
+#endif
system/meson.build +0 -0
index 4952f4b2c7d..181195410fb 100644
@@ -1,6 +1,7 @@

  specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files( 'arch_init.c',
    'ioport.c',
+  'globals-target.c',
    'memory.c',
    'physmem.c',
    'watchpoint.c',

#4 lore raw

Re: [RFC PATCH 01/11] system: Extract target-specific globals to their own compilation unit

Quoted 21 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Pierrick Bouvier
Quoted 6 lines · Philippe Mathieu-Daudé

We shouldn't use target specific globals for machine properties. These ones could be desugarized, as explained in [*]. While certainly doable, not trivial nor my priority for now. Just move them to a different file to clarify they are *globals*, like the generic globals residing in system/globals.c.

Quoted 8 lines

Maybe those could be set globally to the default:
int graphic_width = 800;
int graphic_height = 600;
int graphic_depth = 32;

And override them for sparc and m68k in qemu_init_arch_modules function, using qemu_arch_name().
This way, no need to have a new file to hold them.

This is not what Paolo explained ...

Quoted 1 line
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines

[*] https://lore.kernel.org/qemu-devel/e514d6db-781d-4afe-
[email protected]/

... here ^, but maybe I misunderstood him.

Doing the '-g' CLI change is not my priority, and I welcome any developer willing to help :) Here I'm just trying to make sense of that arch_init.c file.

It's not what I suggested, and the final state (globals are set with a value), should be the same.

It's just
Eventually, the
if (sparc) {
graphic_* = ...'
} else if (m86k) {
graphic_* = ...'
}

Can be moved somewhere else (sooner) if needed.
It's just to get rid of TARGET_SPARC and TARGET_M68K on the way, not to change anything else.

Quoted 75 lines
Quoted 74 lines
Quoted 73 lines
---
   system/arch_init.c      | 14 --------------
   system/globals-target.c | 24 ++++++++++++++++++++++++
   system/meson.build      |  1 +
   3 files changed, 25 insertions(+), 14 deletions(-)

  create mode 100644 system/globals-target.c

system/arch_init.c +0 -14
index d2c32f84887..ea0842b7410 100644
@@ -25,20 +25,6 @@
   #include "qemu/module.h"
   #include "system/arch_init.h"
-#ifdef TARGET_SPARC
-int graphic_width = 1024;
-int graphic_height = 768;
-int graphic_depth = 8;
-#elif defined(TARGET_M68K)
-int graphic_width = 800;
-int graphic_height = 600;
-int graphic_depth = 8;
-#else
-int graphic_width = 800;
-int graphic_height = 600;
-int graphic_depth = 32;
-#endif
-
   const uint32_t arch_type = QEMU_ARCH;
   void qemu_init_arch_modules(void)
system/globals-target.c new file +24 -0
new file mode 100644
index 00000000000..989720591e7
@@ -0,0 +1,24 @@
+/*
+ * Global variables that should not exist (target specific)
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "qemu/osdep.h"
+#include "system/system.h"
+
+#ifdef TARGET_SPARC
+int graphic_width = 1024;
+int graphic_height = 768;
+int graphic_depth = 8;
+#elif defined(TARGET_M68K)
+int graphic_width = 800;
+int graphic_height = 600;
+int graphic_depth = 8;
+#else
+int graphic_width = 800;
+int graphic_height = 600;
+int graphic_depth = 32;
+#endif
system/meson.build +1 -0
index 4952f4b2c7d..181195410fb 100644
@@ -1,6 +1,7 @@
   specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
     'arch_init.c',
     'ioport.c',
+  'globals-target.c',
     'memory.c',
     'physmem.c',
     'watchpoint.c',
Reviewed-by on v1 1/11
#5 lore raw

Re: [RFC PATCH 01/11] system: Extract target-specific globals to their own compilation unit

In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

We shouldn't use target specific globals for machine properties. These ones could be desugarized, as explained in [*]. While certainly doable, not trivial nor my priority for now. Just move them to a different file to clarify they are *globals*, like the generic globals residing in system/globals.c.

[*] https://lore.kernel.org/qemu-devel/[email protected]/

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#6 lore raw

RFC PATCH 2/11 system: Open-code qemu_init_arch_modules() using target_name()

In reply to Philippe Mathieu-Daudé

Mostly revert commit c80cafa0c73 ("system: Add qemu_init_arch_modules") but using target_name() instead of the target specific 'TARGET_NAME' definition.

---
 include/system/arch_init.h | 2 --
 system/arch_init.c         | 9 ---------
 system/vl.c                | 7 ++++++-
 3 files changed, 6 insertions(+), 12 deletions(-)
include/system/arch_init.h +0 -2
index 5b1c1026f3a..d8b77440487 100644
@@ -27,6 +27,4 @@ enum {
 
 extern const uint32_t arch_type;
 
-void qemu_init_arch_modules(void);
-
 #endif
system/arch_init.c +0 -9
index ea0842b7410..b9147af93cb 100644
@@ -22,15 +22,6 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
-#include "qemu/module.h"
 #include "system/arch_init.h"
 
 const uint32_t arch_type = QEMU_ARCH;
-
-void qemu_init_arch_modules(void)
-{
-#ifdef CONFIG_MODULES
-    module_init_info(qemu_modinfo);
-    module_allow_arch(TARGET_NAME);
-#endif
-}
system/vl.c +6 -1
index 8f776684ec8..04f78466c41 100644
@@ -26,6 +26,7 @@
 #include "qemu/help-texts.h"
 #include "qemu/datadir.h"
 #include "qemu/units.h"
+#include "qemu/module.h"
 #include "exec/cpu-common.h"
 #include "exec/page-vary.h"
 #include "hw/qdev-properties.h"
@@ -78,6 +79,7 @@
 #include "hw/block/block.h"
 #include "hw/i386/x86.h"
 #include "hw/i386/pc.h"
+#include "hw/core/cpu.h"
 #include "migration/cpr.h"
 #include "migration/misc.h"
 #include "migration/snapshot.h"
@@ -2885,7 +2887,10 @@ void qemu_init(int argc, char **argv)
 
     os_setup_limits();
 
-    qemu_init_arch_modules();
+#ifdef CONFIG_MODULES
+    module_init_info(qemu_modinfo);
+    module_allow_arch(target_name());
+#endif
 
     qemu_init_subsystems();
 
Signature · 1 line
2.47.1
Reviewed-by on v1 2/11
#7 lore raw

Re: [RFC PATCH 02/11] system: Open-code qemu_init_arch_modules() using target_name()

Quoted 10 lines · Philippe Mathieu-Daudé

Mostly revert commit c80cafa0c73 ("system: Add qemu_init_arch_modules") but using target_name() instead of the target specific 'TARGET_NAME' definition.

---
  include/system/arch_init.h | 2 --
  system/arch_init.c         | 9 ---------
  system/vl.c                | 7 ++++++-
  3 files changed, 6 insertions(+), 12 deletions(-)

r~

#8 lore raw

RFC PATCH 3/11 system: Introduce QemuArchBit enum

In reply to Philippe Mathieu-Daudé

Declare QEMU_ARCH_BIT_$target as QemuArchBit enum. Use them to declare QEMU_ARCH_$target bitmasks.

---
 meson.build                |  4 +--
 include/system/arch_init.h | 65 +++++++++++++++++++++++++-------------
 system/arch_init.c         |  2 +-
 3 files changed, 46 insertions(+), 25 deletions(-)
meson.build +2 -2
index 0a2c61d2bfa..1ab02a5d48d 100644
@@ -3357,8 +3357,8 @@ 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_data.set('QEMU_ARCH_BIT',
+                         'QEMU_ARCH_BIT_' + config_target['TARGET_BASE_ARCH'].to_upper())
   config_target_h += {target: configure_file(output: target + '-config-target.h',
                                                configuration: config_target_data)}
 
include/system/arch_init.h +43 -22

72 lines not on this page · raw message

system/arch_init.c +1 -1
index b9147af93cb..fedbb18e2cc 100644
@@ -24,4 +24,4 @@
 #include "qemu/osdep.h"
 #include "system/arch_init.h"
 
-const uint32_t arch_type = QEMU_ARCH;
+const uint32_t arch_type = BIT(QEMU_ARCH_BIT);
Signature · 1 line
2.47.1
#9 lore raw

Re: [RFC PATCH 03/11] system: Introduce QemuArchBit enum

Quoted 92 lines · Philippe Mathieu-Daudé

Declare QEMU_ARCH_BIT_$target as QemuArchBit enum. Use them to declare QEMU_ARCH_$target bitmasks.

---
  meson.build                |  4 +--
  include/system/arch_init.h | 65 +++++++++++++++++++++++++-------------
  system/arch_init.c         |  2 +-
  3 files changed, 46 insertions(+), 25 deletions(-)
meson.build +2 -2
index 0a2c61d2bfa..1ab02a5d48d 100644
@@ -3357,8 +3357,8 @@ 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_data.set('QEMU_ARCH_BIT',
+                         'QEMU_ARCH_BIT_' + config_target['TARGET_BASE_ARCH'].to_upper())
    config_target_h += {target: configure_file(output: target + '-config-target.h',
                                                 configuration: config_target_data)}
 
include/system/arch_init.h +36 -22
index d8b77440487..06e5527ec88 100644
@@ -1,29 +1,50 @@
  #ifndef QEMU_ARCH_INIT_H
  #define QEMU_ARCH_INIT_H
 
+#include "qemu/bitops.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_OPENRISC = (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),
-};
+typedef enum QemuArchBit {
+    QEMU_ARCH_BIT_ALPHA         = 0,
+    QEMU_ARCH_BIT_ARM           = 1,
+    QEMU_ARCH_BIT_I386          = 3,
+    QEMU_ARCH_BIT_M68K          = 4,
+    QEMU_ARCH_BIT_MICROBLAZE    = 6,
+    QEMU_ARCH_BIT_MIPS          = 7,
+    QEMU_ARCH_BIT_PPC           = 8,
+    QEMU_ARCH_BIT_S390X         = 9,
+    QEMU_ARCH_BIT_SH4           = 10,
+    QEMU_ARCH_BIT_SPARC         = 11,
+    QEMU_ARCH_BIT_XTENSA        = 12,
+    QEMU_ARCH_BIT_OPENRISC      = 13,
+    QEMU_ARCH_BIT_TRICORE       = 16,
+    QEMU_ARCH_BIT_HPPA          = 18,
+    QEMU_ARCH_BIT_RISCV         = 19,
+    QEMU_ARCH_BIT_RX            = 20,
+    QEMU_ARCH_BIT_AVR           = 21,
+    QEMU_ARCH_BIT_HEXAGON       = 22,
+    QEMU_ARCH_BIT_LOONGARCH     = 23,
+} QemuArchBit;
+
+#define QEMU_ARCH_ALPHA         BIT(QEMU_ARCH_BIT_ALPHA)
+#define QEMU_ARCH_ARM           BIT(QEMU_ARCH_BIT_ARM)
+#define QEMU_ARCH_I386          BIT(QEMU_ARCH_BIT_I386)
+#define QEMU_ARCH_M68K          BIT(QEMU_ARCH_BIT_M68K)
+#define QEMU_ARCH_MICROBLAZE    BIT(QEMU_ARCH_BIT_MICROBLAZE)
+#define QEMU_ARCH_MIPS          BIT(QEMU_ARCH_BIT_MIPS)
+#define QEMU_ARCH_PPC           BIT(QEMU_ARCH_BIT_PPC)
+#define QEMU_ARCH_S390X         BIT(QEMU_ARCH_BIT_S390X)
+#define QEMU_ARCH_SH4           BIT(QEMU_ARCH_BIT_SH4)
+#define QEMU_ARCH_SPARC         BIT(QEMU_ARCH_BIT_SPARC)
+#define QEMU_ARCH_XTENSA        BIT(QEMU_ARCH_BIT_XTENSA)
+#define QEMU_ARCH_OPENRISC      BIT(QEMU_ARCH_BIT_OPENRISC)
+#define QEMU_ARCH_TRICORE       BIT(QEMU_ARCH_BIT_TRICORE)

include/system/arch_init.h line 50

Quoted 10 lines
include/system/arch_init.h +7 -0
+#define QEMU_ARCH_HPPA          BIT(QEMU_ARCH_BIT_HPPA)
+#define QEMU_ARCH_RISCV         BIT(QEMU_ARCH_BIT_RISCV)
+#define QEMU_ARCH_RX            BIT(QEMU_ARCH_BIT_RX)
+#define QEMU_ARCH_AVR           BIT(QEMU_ARCH_BIT_AVR)
+#define QEMU_ARCH_HEXAGON       BIT(QEMU_ARCH_BIT_HEXAGON)
+#define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
+#define QEMU_ARCH_ALL           -1
 
  extern const uint32_t arch_type;
 

What are we gaining by having a "bit" oriented enum, vs simple values that can be compared too?
As well, it would make sense to add subvariants (aarch64, x86_64, little and big endian variants for some arch), so all of them are present and can be queried easily.

Quoted 10 lines
system/arch_init.c +1 -1
index b9147af93cb..fedbb18e2cc 100644
@@ -24,4 +24,4 @@
  #include "qemu/osdep.h"
  #include "system/arch_init.h"
 
-const uint32_t arch_type = QEMU_ARCH;
+const uint32_t arch_type = BIT(QEMU_ARCH_BIT);
#10 lore raw

Re: [RFC PATCH 03/11] system: Introduce QemuArchBit enum

Quoted 94 lines · Pierrick Bouvier
Quoted 93 lines · Philippe Mathieu-Daudé

Declare QEMU_ARCH_BIT_$target as QemuArchBit enum. Use them to declare QEMU_ARCH_$target bitmasks.

---
  meson.build                |  4 +-- include/system/arch_init.h | 65 +++++++++++++++++++++++++------------- system/arch_init.c         |  2 +-

  3 files changed, 46 insertions(+), 25 deletions(-)
meson.build +0 -0
index 0a2c61d2bfa..1ab02a5d48d 100644
@@ -3357,8 +3357,8 @@ 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_data.set('QEMU_ARCH_BIT',
+                         'QEMU_ARCH_BIT_' + config_target['TARGET_BASE_ARCH'].to_upper())
    config_target_h += {target: configure_file(output: target + '- config-target.h',
                                                 configuration: config_target_data)}

include/system/arch_init.h +38 -22
index d8b77440487..06e5527ec88 100644
@@ -1,29 +1,50 @@
   #ifndef QEMU_ARCH_INIT_H
   #define QEMU_ARCH_INIT_H
+#include "qemu/bitops.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_OPENRISC = (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),
-};
+typedef enum QemuArchBit {
+    QEMU_ARCH_BIT_ALPHA         = 0,
+    QEMU_ARCH_BIT_ARM           = 1,
+    QEMU_ARCH_BIT_I386          = 3,
+    QEMU_ARCH_BIT_M68K          = 4,
+    QEMU_ARCH_BIT_MICROBLAZE    = 6,
+    QEMU_ARCH_BIT_MIPS          = 7,
+    QEMU_ARCH_BIT_PPC           = 8,
+    QEMU_ARCH_BIT_S390X         = 9,
+    QEMU_ARCH_BIT_SH4           = 10,
+    QEMU_ARCH_BIT_SPARC         = 11,
+    QEMU_ARCH_BIT_XTENSA        = 12,
+    QEMU_ARCH_BIT_OPENRISC      = 13,
+    QEMU_ARCH_BIT_TRICORE       = 16,
+    QEMU_ARCH_BIT_HPPA          = 18,
+    QEMU_ARCH_BIT_RISCV         = 19,
+    QEMU_ARCH_BIT_RX            = 20,
+    QEMU_ARCH_BIT_AVR           = 21,
+    QEMU_ARCH_BIT_HEXAGON       = 22,
+    QEMU_ARCH_BIT_LOONGARCH     = 23,
+} QemuArchBit;
+
+#define QEMU_ARCH_ALPHA         BIT(QEMU_ARCH_BIT_ALPHA)
+#define QEMU_ARCH_ARM           BIT(QEMU_ARCH_BIT_ARM)
+#define QEMU_ARCH_I386          BIT(QEMU_ARCH_BIT_I386)
+#define QEMU_ARCH_M68K          BIT(QEMU_ARCH_BIT_M68K)
+#define QEMU_ARCH_MICROBLAZE    BIT(QEMU_ARCH_BIT_MICROBLAZE)
+#define QEMU_ARCH_MIPS          BIT(QEMU_ARCH_BIT_MIPS)
+#define QEMU_ARCH_PPC           BIT(QEMU_ARCH_BIT_PPC)
+#define QEMU_ARCH_S390X         BIT(QEMU_ARCH_BIT_S390X)
+#define QEMU_ARCH_SH4           BIT(QEMU_ARCH_BIT_SH4)
+#define QEMU_ARCH_SPARC         BIT(QEMU_ARCH_BIT_SPARC)
+#define QEMU_ARCH_XTENSA        BIT(QEMU_ARCH_BIT_XTENSA)
+#define QEMU_ARCH_OPENRISC      BIT(QEMU_ARCH_BIT_OPENRISC)
+#define QEMU_ARCH_TRICORE       BIT(QEMU_ARCH_BIT_TRICORE)
+#define QEMU_ARCH_HPPA          BIT(QEMU_ARCH_BIT_HPPA)
+#define QEMU_ARCH_RISCV         BIT(QEMU_ARCH_BIT_RISCV)
Quoted 8 lines

include/system/arch_init.h line 49

Quoted 6 lines
include/system/arch_init.h +5 -0
+#define QEMU_ARCH_RX            BIT(QEMU_ARCH_BIT_RX)
+#define QEMU_ARCH_AVR           BIT(QEMU_ARCH_BIT_AVR)
+#define QEMU_ARCH_HEXAGON       BIT(QEMU_ARCH_BIT_HEXAGON)
+#define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
+#define QEMU_ARCH_ALL           -1
   extern const uint32_t arch_type;

What are we gaining by having a "bit" oriented enum, vs simple values that can be compared too?

I'm not sure what you are asking here, these definitions are heavily used in qemu-options.hx, and I don't plan to change them anytime soon.

For the single binary I'll try to keep the command line interface with no change. For heterogeneous binary I plan to start with no CLI so I'm not really considering them.

Quoted 1 line

As well, it would make sense to add subvariants (aarch64, x86_64, little and big endian variants for some arch), so all of them are present and can be queried easily.

IIUC what you are referring, this is planned for another interface, but not this series which is focused on introducing qemu_arch_name() and removing TARGET_NAME. While you don't see any improvement in duplicated target files as of this series, some reduction should happen in the next step which remove TARGET_BIG_ENDIAN uses in hw/.

Quoted 10 lines
Quoted 9 lines
system/arch_init.c +1 -1
index b9147af93cb..fedbb18e2cc 100644
@@ -24,4 +24,4 @@
   #include "qemu/osdep.h"
   #include "system/arch_init.h"
-const uint32_t arch_type = QEMU_ARCH;
+const uint32_t arch_type = BIT(QEMU_ARCH_BIT);
#11 lore raw

Re: [RFC PATCH 03/11] system: Introduce QemuArchBit enum

Quoted 107 lines · Philippe Mathieu-Daudé
Quoted 97 lines · Pierrick Bouvier
Quoted 96 lines · Philippe Mathieu-Daudé

Declare QEMU_ARCH_BIT_$target as QemuArchBit enum. Use them to declare QEMU_ARCH_$target bitmasks.

---
   meson.build                |  4 +--
   include/system/arch_init.h | 65 +++++++++++++++++++++++++-------------
   system/arch_init.c         |  2 +-
   3 files changed, 46 insertions(+), 25 deletions(-)
meson.build +2 -2
index 0a2c61d2bfa..1ab02a5d48d 100644
@@ -3357,8 +3357,8 @@ 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_data.set('QEMU_ARCH_BIT',
+                         'QEMU_ARCH_BIT_' +
 config_target['TARGET_BASE_ARCH'].to_upper())
     config_target_h += {target: configure_file(output: target + '-

config-target.h',
                                                 configuration:
config_target_data)}

include/system/arch_init.h +39 -22
index d8b77440487..06e5527ec88 100644
@@ -1,29 +1,50 @@
   #ifndef QEMU_ARCH_INIT_H
   #define QEMU_ARCH_INIT_H
+#include "qemu/bitops.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_OPENRISC = (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),
-};
+typedef enum QemuArchBit {
+    QEMU_ARCH_BIT_ALPHA         = 0,
+    QEMU_ARCH_BIT_ARM           = 1,
+    QEMU_ARCH_BIT_I386          = 3,
+    QEMU_ARCH_BIT_M68K          = 4,
+    QEMU_ARCH_BIT_MICROBLAZE    = 6,
+    QEMU_ARCH_BIT_MIPS          = 7,
+    QEMU_ARCH_BIT_PPC           = 8,
+    QEMU_ARCH_BIT_S390X         = 9,
+    QEMU_ARCH_BIT_SH4           = 10,
+    QEMU_ARCH_BIT_SPARC         = 11,
+    QEMU_ARCH_BIT_XTENSA        = 12,
+    QEMU_ARCH_BIT_OPENRISC      = 13,
+    QEMU_ARCH_BIT_TRICORE       = 16,
+    QEMU_ARCH_BIT_HPPA          = 18,
+    QEMU_ARCH_BIT_RISCV         = 19,
+    QEMU_ARCH_BIT_RX            = 20,
+    QEMU_ARCH_BIT_AVR           = 21,
+    QEMU_ARCH_BIT_HEXAGON       = 22,
+    QEMU_ARCH_BIT_LOONGARCH     = 23,
+} QemuArchBit;
+
+#define QEMU_ARCH_ALPHA         BIT(QEMU_ARCH_BIT_ALPHA)
+#define QEMU_ARCH_ARM           BIT(QEMU_ARCH_BIT_ARM)
+#define QEMU_ARCH_I386          BIT(QEMU_ARCH_BIT_I386)
+#define QEMU_ARCH_M68K          BIT(QEMU_ARCH_BIT_M68K)
+#define QEMU_ARCH_MICROBLAZE    BIT(QEMU_ARCH_BIT_MICROBLAZE)
+#define QEMU_ARCH_MIPS          BIT(QEMU_ARCH_BIT_MIPS)
+#define QEMU_ARCH_PPC           BIT(QEMU_ARCH_BIT_PPC)
+#define QEMU_ARCH_S390X         BIT(QEMU_ARCH_BIT_S390X)
+#define QEMU_ARCH_SH4           BIT(QEMU_ARCH_BIT_SH4)
+#define QEMU_ARCH_SPARC         BIT(QEMU_ARCH_BIT_SPARC)
+#define QEMU_ARCH_XTENSA        BIT(QEMU_ARCH_BIT_XTENSA)
+#define QEMU_ARCH_OPENRISC      BIT(QEMU_ARCH_BIT_OPENRISC)
+#define QEMU_ARCH_TRICORE       BIT(QEMU_ARCH_BIT_TRICORE)
+#define QEMU_ARCH_HPPA          BIT(QEMU_ARCH_BIT_HPPA)
+#define QEMU_ARCH_RISCV         BIT(QEMU_ARCH_BIT_RISCV)
+#define QEMU_ARCH_RX            BIT(QEMU_ARCH_BIT_RX)
Quoted 8 lines

include/system/arch_init.h line 49

Quoted 5 lines
include/system/arch_init.h +4 -0
+#define QEMU_ARCH_AVR           BIT(QEMU_ARCH_BIT_AVR)
+#define QEMU_ARCH_HEXAGON       BIT(QEMU_ARCH_BIT_HEXAGON)
+#define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
+#define QEMU_ARCH_ALL           -1
   extern const uint32_t arch_type;

What are we gaining by having a "bit" oriented enum, vs simple values that can be compared too?

Quoted 7 lines

I'm not sure what you are asking here, these definitions are heavily used in qemu-options.hx, and I don't plan to change them anytime soon.

For the single binary I'll try to keep the command line interface with no change. For heterogeneous binary I plan to start with no CLI so I'm not really considering them.

My bad, I thought we were introducing something new here. Yes, let's stick to a minimal change.

Quoted 10 lines
Quoted 3 lines

As well, it would make sense to add subvariants (aarch64, x86_64, little and big endian variants for some arch), so all of them are present and can be queried easily.

IIUC what you are referring, this is planned for another interface, but not this series which is focused on introducing qemu_arch_name() and removing TARGET_NAME. While you don't see any improvement in duplicated target files as of this series, some reduction should happen in the next step which remove TARGET_BIG_ENDIAN uses in hw/.

Yes, sounds good. It's just a bit hard to track the changes between the cleanup of existing files, and introducing a new API to query this information at run time.

Quoted 11 lines
Quoted 10 lines
Quoted 9 lines
system/arch_init.c +1 -1
index b9147af93cb..fedbb18e2cc 100644
@@ -24,4 +24,4 @@
   #include "qemu/osdep.h"
   #include "system/arch_init.h"
-const uint32_t arch_type = QEMU_ARCH;
+const uint32_t arch_type = BIT(QEMU_ARCH_BIT);
#12 lore raw

Re: [RFC PATCH 03/11] system: Introduce QemuArchBit enum

Quoted 124 lines · Pierrick Bouvier
Quoted 108 lines · Philippe Mathieu-Daudé
Quoted 98 lines · Pierrick Bouvier
Quoted 97 lines · Philippe Mathieu-Daudé

Declare QEMU_ARCH_BIT_$target as QemuArchBit enum. Use them to declare QEMU_ARCH_$target bitmasks.

---
   meson.build                |  4 +-- include/system/arch_init.h | 65 ++++++++++++++++++++++++

+-------------
   system/arch_init.c         |  2 +-
   3 files changed, 46 insertions(+), 25 deletions(-)
meson.build +0 -0
index 0a2c61d2bfa..1ab02a5d48d 100644
@@ -3357,8 +3357,8 @@ 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_data.set('QEMU_ARCH_BIT',
+                         'QEMU_ARCH_BIT_' + config_target['TARGET_BASE_ARCH'].to_upper()) config_target_h += {target: configure_file(output: target + '- config-target.h',
                                                  configuration:
config_target_data)}

include/system/arch_init.h +39 -22
index d8b77440487..06e5527ec88 100644
@@ -1,29 +1,50 @@
    #ifndef QEMU_ARCH_INIT_H
    #define QEMU_ARCH_INIT_H
+#include "qemu/bitops.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_OPENRISC = (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),
-};
+typedef enum QemuArchBit {
+    QEMU_ARCH_BIT_ALPHA         = 0,
+    QEMU_ARCH_BIT_ARM           = 1,
+    QEMU_ARCH_BIT_I386          = 3,
+    QEMU_ARCH_BIT_M68K          = 4,
+    QEMU_ARCH_BIT_MICROBLAZE    = 6,
+    QEMU_ARCH_BIT_MIPS          = 7,
+    QEMU_ARCH_BIT_PPC           = 8,
+    QEMU_ARCH_BIT_S390X         = 9,
+    QEMU_ARCH_BIT_SH4           = 10,
+    QEMU_ARCH_BIT_SPARC         = 11,
+    QEMU_ARCH_BIT_XTENSA        = 12,
+    QEMU_ARCH_BIT_OPENRISC      = 13,
+    QEMU_ARCH_BIT_TRICORE       = 16,
+    QEMU_ARCH_BIT_HPPA          = 18,
+    QEMU_ARCH_BIT_RISCV         = 19,
+    QEMU_ARCH_BIT_RX            = 20,
+    QEMU_ARCH_BIT_AVR           = 21,
+    QEMU_ARCH_BIT_HEXAGON       = 22,
+    QEMU_ARCH_BIT_LOONGARCH     = 23,
+} QemuArchBit;
+
+#define QEMU_ARCH_ALPHA         BIT(QEMU_ARCH_BIT_ALPHA)
+#define QEMU_ARCH_ARM           BIT(QEMU_ARCH_BIT_ARM)
+#define QEMU_ARCH_I386          BIT(QEMU_ARCH_BIT_I386)
+#define QEMU_ARCH_M68K          BIT(QEMU_ARCH_BIT_M68K)
+#define QEMU_ARCH_MICROBLAZE    BIT(QEMU_ARCH_BIT_MICROBLAZE)
+#define QEMU_ARCH_MIPS          BIT(QEMU_ARCH_BIT_MIPS)
+#define QEMU_ARCH_PPC           BIT(QEMU_ARCH_BIT_PPC)
+#define QEMU_ARCH_S390X         BIT(QEMU_ARCH_BIT_S390X)
+#define QEMU_ARCH_SH4           BIT(QEMU_ARCH_BIT_SH4)
+#define QEMU_ARCH_SPARC         BIT(QEMU_ARCH_BIT_SPARC)
+#define QEMU_ARCH_XTENSA        BIT(QEMU_ARCH_BIT_XTENSA)
+#define QEMU_ARCH_OPENRISC      BIT(QEMU_ARCH_BIT_OPENRISC)
+#define QEMU_ARCH_TRICORE       BIT(QEMU_ARCH_BIT_TRICORE)
+#define QEMU_ARCH_HPPA          BIT(QEMU_ARCH_BIT_HPPA)
+#define QEMU_ARCH_RISCV         BIT(QEMU_ARCH_BIT_RISCV)
+#define QEMU_ARCH_RX            BIT(QEMU_ARCH_BIT_RX)
Quoted 8 lines

include/system/arch_init.h line 49

Quoted 5 lines
include/system/arch_init.h +4 -0
+#define QEMU_ARCH_AVR           BIT(QEMU_ARCH_BIT_AVR)
+#define QEMU_ARCH_HEXAGON       BIT(QEMU_ARCH_BIT_HEXAGON)
+#define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
+#define QEMU_ARCH_ALL           -1
    extern const uint32_t arch_type;

What are we gaining by having a "bit" oriented enum, vs simple values that can be compared too?

Quoted 7 lines

I'm not sure what you are asking here, these definitions are heavily used in qemu-options.hx, and I don't plan to change them anytime soon.

For the single binary I'll try to keep the command line interface with no change. For heterogeneous binary I plan to start with no CLI so I'm not really considering them.

My bad, I thought we were introducing something new here. Yes, let's stick to a minimal change.

Quoted 4 lines
Quoted 3 lines

As well, it would make sense to add subvariants (aarch64, x86_64, little and big endian variants for some arch), so all of them are present and can be queried easily.

Quoted 8 lines
Quoted 6 lines

IIUC what you are referring, this is planned for another interface, but not this series which is focused on introducing qemu_arch_name() and removing TARGET_NAME. While you don't see any improvement in duplicated target files as of this series, some reduction should happen in the next step which remove TARGET_BIG_ENDIAN uses in hw/.

Yes, sounds good. It's just a bit hard to track the changes between the cleanup of existing files, and introducing a new API to query this information at run time.

OK, in the next version I'll try to better explain where this series is going in the patch description.

#13 lore raw

Re: [RFC PATCH 03/11] system: Introduce QemuArchBit enum

In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Declare QEMU_ARCH_BIT_$target as QemuArchBit enum. Use them to declare QEMU_ARCH_$target bitmasks.

---
  meson.build                |  4 +--
  include/system/arch_init.h | 65 +++++++++++++++++++++++++-------------
  system/arch_init.c         |  2 +-
  3 files changed, 46 insertions(+), 25 deletions(-)

If we ignore the array index in patch 10, is there any other reason for this?

r~

#14 lore raw

Re: [RFC PATCH 03/11] system: Introduce QemuArchBit enum

In reply to Philippe Mathieu-Daudé
Quoted 68 lines · Philippe Mathieu-Daudé

Declare QEMU_ARCH_BIT_$target as QemuArchBit enum. Use them to declare QEMU_ARCH_$target bitmasks.

---
 meson.build                |  4 +--
 include/system/arch_init.h | 65 +++++++++++++++++++++++++-------------
 system/arch_init.c         |  2 +-
 3 files changed, 46 insertions(+), 25 deletions(-)
meson.build +2 -2
index 0a2c61d2bfa..1ab02a5d48d 100644
@@ -3357,8 +3357,8 @@ 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_data.set('QEMU_ARCH_BIT',
+                         'QEMU_ARCH_BIT_' + config_target['TARGET_BASE_ARCH'].to_upper())
   config_target_h += {target: configure_file(output: target + '-config-target.h',
                                                configuration: config_target_data)}
 
include/system/arch_init.h +12 -22
index d8b77440487..06e5527ec88 100644
@@ -1,29 +1,50 @@
 #ifndef QEMU_ARCH_INIT_H
 #define QEMU_ARCH_INIT_H
 
+#include "qemu/bitops.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_OPENRISC = (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),
-};
+typedef enum QemuArchBit {
+    QEMU_ARCH_BIT_ALPHA         = 0,
+    QEMU_ARCH_BIT_ARM           = 1,
+    QEMU_ARCH_BIT_I386          = 3,
+    QEMU_ARCH_BIT_M68K          = 4,
+    QEMU_ARCH_BIT_MICROBLAZE    = 6,
+    QEMU_ARCH_BIT_MIPS          = 7,
+    QEMU_ARCH_BIT_PPC           = 8,
+    QEMU_ARCH_BIT_S390X         = 9,
+    QEMU_ARCH_BIT_SH4           = 10,
+    QEMU_ARCH_BIT_SPARC         = 11,

include/system/arch_init.h line 26

Quoted 10 lines
include/system/arch_init.h +10 -0
+    QEMU_ARCH_BIT_XTENSA        = 12,
+    QEMU_ARCH_BIT_OPENRISC      = 13,
+    QEMU_ARCH_BIT_TRICORE       = 16,
+    QEMU_ARCH_BIT_HPPA          = 18,
+    QEMU_ARCH_BIT_RISCV         = 19,
+    QEMU_ARCH_BIT_RX            = 20,
+    QEMU_ARCH_BIT_AVR           = 21,
+    QEMU_ARCH_BIT_HEXAGON       = 22,
+    QEMU_ARCH_BIT_LOONGARCH     = 23,
+} QemuArchBit;

I'm somewhat inclined to say we should be defining this as a QemuArch enum in QAPI, especially because that gives us the string <> int conversion that you hand-code in a latter patch.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#15 lore raw

Re: [RFC PATCH 03/11] system: Introduce QemuArchBit enum

Quoted 75 lines · Daniel P. Berrangé
Quoted 74 lines · Philippe Mathieu-Daudé

Declare QEMU_ARCH_BIT_$target as QemuArchBit enum. Use them to declare QEMU_ARCH_$target bitmasks.

---
 meson.build                |  4 +--
 include/system/arch_init.h | 65 +++++++++++++++++++++++++-------------
 system/arch_init.c         |  2 +-
 3 files changed, 46 insertions(+), 25 deletions(-)
meson.build +2 -2
index 0a2c61d2bfa..1ab02a5d48d 100644
@@ -3357,8 +3357,8 @@ 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_data.set('QEMU_ARCH_BIT',
+                         'QEMU_ARCH_BIT_' + config_target['TARGET_BASE_ARCH'].to_upper())
   config_target_h += {target: configure_file(output: target + '-config-target.h',
                                                configuration: config_target_data)}
 
include/system/arch_init.h +18 -22
index d8b77440487..06e5527ec88 100644
@@ -1,29 +1,50 @@
 #ifndef QEMU_ARCH_INIT_H
 #define QEMU_ARCH_INIT_H
 
+#include "qemu/bitops.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_OPENRISC = (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),
-};
+typedef enum QemuArchBit {
+    QEMU_ARCH_BIT_ALPHA         = 0,
+    QEMU_ARCH_BIT_ARM           = 1,
+    QEMU_ARCH_BIT_I386          = 3,
+    QEMU_ARCH_BIT_M68K          = 4,
+    QEMU_ARCH_BIT_MICROBLAZE    = 6,
+    QEMU_ARCH_BIT_MIPS          = 7,
+    QEMU_ARCH_BIT_PPC           = 8,
+    QEMU_ARCH_BIT_S390X         = 9,
+    QEMU_ARCH_BIT_SH4           = 10,
+    QEMU_ARCH_BIT_SPARC         = 11,
+    QEMU_ARCH_BIT_XTENSA        = 12,
+    QEMU_ARCH_BIT_OPENRISC      = 13,
+    QEMU_ARCH_BIT_TRICORE       = 16,
+    QEMU_ARCH_BIT_HPPA          = 18,
+    QEMU_ARCH_BIT_RISCV         = 19,
+    QEMU_ARCH_BIT_RX            = 20,
Quoted 8 lines

include/system/arch_init.h line 26

Quoted 4 lines
include/system/arch_init.h +4 -0
+    QEMU_ARCH_BIT_AVR           = 21,
+    QEMU_ARCH_BIT_HEXAGON       = 22,
+    QEMU_ARCH_BIT_LOONGARCH     = 23,
+} QemuArchBit;

I'm somewhat inclined to say we should be defining this as a QemuArch enum in QAPI, especially because that gives us the string <> int conversion that you hand-code in a latter patch.

Having said that, the auto-generated string/int conversion won't work if we have differing name mappings based on endian/target bits size. So scratch that idea.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#16 lore raw

RFC PATCH 4/11 system: Replace arch_type global by qemu_arch_available() helper

In reply to Philippe Mathieu-Daudé

qemu_arch_available() is a bit simpler to understand while reviewing than the undocumented arch_type variable.

---
 include/system/arch_init.h | 2 +-
 hw/scsi/scsi-disk.c        | 2 +-
 system/arch_init.c         | 5 ++++-
 system/qdev-monitor.c      | 4 ++--
 system/vl.c                | 6 +++---
 5 files changed, 11 insertions(+), 8 deletions(-)
include/system/arch_init.h +1 -1
index 06e5527ec88..023d27d5bd7 100644
@@ -46,6 +46,6 @@ typedef enum QemuArchBit {
 #define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
 #define QEMU_ARCH_ALL           -1
 
-extern const uint32_t arch_type;
+bool qemu_arch_available(unsigned qemu_arch_mask);
 
 #endif
hw/scsi/scsi-disk.c +1 -1
index e7f738b4841..7c87b20e694 100644
@@ -3165,7 +3165,7 @@ static void scsi_property_add_specifics(DeviceClass *dc)
     ObjectClass *oc = OBJECT_CLASS(dc);
 
     /* The loadparm property is only supported on s390x */
-    if (arch_type & QEMU_ARCH_S390X) {
+    if (qemu_arch_available(QEMU_ARCH_S390X)) {
         object_class_property_add_str(oc, "loadparm",
                                       scsi_property_get_loadparm,
                                       scsi_property_set_loadparm);
system/arch_init.c +4 -1
index fedbb18e2cc..0fec0cd416b 100644
@@ -24,4 +24,7 @@
 #include "qemu/osdep.h"
 #include "system/arch_init.h"
 
-const uint32_t arch_type = BIT(QEMU_ARCH_BIT);
+bool qemu_arch_available(unsigned qemu_arch_mask)
+{
+    return qemu_arch_mask & BIT(QEMU_ARCH_BIT);
+}
system/qdev-monitor.c +2 -2
index 856c9e8c32e..5588ed2047d 100644
@@ -132,7 +132,7 @@ static const char *qdev_class_get_alias(DeviceClass *dc)
 
     for (i = 0; qdev_alias_table[i].typename; i++) {
         if (qdev_alias_table[i].arch_mask &&
-            !(qdev_alias_table[i].arch_mask & arch_type)) {
+            !qemu_arch_available(qdev_alias_table[i].arch_mask)) {
             continue;
         }
 
@@ -218,7 +218,7 @@ static const char *find_typename_by_alias(const char *alias)
 
     for (i = 0; qdev_alias_table[i].alias; i++) {
         if (qdev_alias_table[i].arch_mask &&
-            !(qdev_alias_table[i].arch_mask & arch_type)) {
+            !qemu_arch_available(qdev_alias_table[i].arch_mask)) {
             continue;
         }
 
system/vl.c +3 -3
index 04f78466c41..ec93988a03a 100644
@@ -878,11 +878,11 @@ static void help(int exitcode)
             g_get_prgname());
 
 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask)    \
-    if ((arch_mask) & arch_type)                               \
+    if (qemu_arch_available(arch_mask)) \
         fputs(opt_help, stdout);
 
 #define ARCHHEADING(text, arch_mask) \
-    if ((arch_mask) & arch_type)    \
+    if (qemu_arch_available(arch_mask)) \
         puts(stringify(text));
 
 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
@@ -2929,7 +2929,7 @@ void qemu_init(int argc, char **argv)
             const QEMUOption *popt;
 
             popt = lookup_opt(argc, argv, &optarg, &optind);
-            if (!(popt->arch_mask & arch_type)) {
+            if (!qemu_arch_available(popt->arch_mask)) {
                 error_report("Option not supported for this target");
                 exit(1);
             }
Signature · 1 line
2.47.1
Reviewed-by on v1 4/11
#17 lore raw

Re: [RFC PATCH 04/11] system: Replace arch_type global by qemu_arch_available() helper

Quoted 11 lines · Philippe Mathieu-Daudé

qemu_arch_available() is a bit simpler to understand while reviewing than the undocumented arch_type variable.

---
  include/system/arch_init.h | 2 +-
  hw/scsi/scsi-disk.c        | 2 +-
  system/arch_init.c         | 5 ++++-
  system/qdev-monitor.c      | 4 ++--
  system/vl.c                | 6 +++---
  5 files changed, 11 insertions(+), 8 deletions(-)

r~

#18 lore raw

RFC PATCH 5/11 include: Expose QemuArchBit enum to user emulation

In reply to Philippe Mathieu-Daudé

QemuArchBit isn't really specific to system emulation, move the "system/arch_init.h" header to "qemu/arch_info.h", a more generic include path.

---
 meson.build                                      | 2 +-
 include/{system/arch_init.h => qemu/arch_info.h} | 4 ++--
 system/arch_init.c => arch_info-target.c         | 2 +-
 hw/scsi/scsi-disk.c                              | 2 +-
 system/qdev-monitor.c                            | 2 +-
 system/vl.c                                      | 2 +-
 system/meson.build                               | 1 -
 7 files changed, 7 insertions(+), 8 deletions(-)
 rename include/{system/arch_init.h => qemu/arch_info.h} (97%)
 rename system/arch_init.c => arch_info-target.c (97%)
meson.build +1 -1
index 1ab02a5d48d..04d8c477644 100644
@@ -3766,7 +3766,7 @@ if have_block
 endif
 
 common_ss.add(files('cpu-common.c'))
-specific_ss.add(files('cpu-target.c'))
+specific_ss.add(files('cpu-target.c', 'arch_info-target.c'))
 
 subdir('system')
 
include/qemu/arch_info.h renamed from include/system/arch_init.h +2 -2
similarity index 97%
rename from include/system/arch_init.h
rename to include/qemu/arch_info.h
index 023d27d5bd7..3cb95926e27 100644
@@ -1,5 +1,5 @@
-#ifndef QEMU_ARCH_INIT_H
-#define QEMU_ARCH_INIT_H
+#ifndef QEMU_ARCH_INFO_H
+#define QEMU_ARCH_INFO_H
 
 #include "qemu/bitops.h"
 
arch_info-target.c renamed from system/arch_init.c +1 -1
similarity index 97%
rename from system/arch_init.c
rename to arch_info-target.c
index 0fec0cd416b..6c11c73feb9 100644
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
-#include "system/arch_init.h"
+#include "qemu/arch_info.h"
 
 bool qemu_arch_available(unsigned qemu_arch_mask)
 {
hw/scsi/scsi-disk.c +1 -1
index 7c87b20e694..bafa9f39497 100644
@@ -27,12 +27,12 @@
 #include "qemu/module.h"
 #include "qemu/hw-version.h"
 #include "qemu/memalign.h"
+#include "qemu/arch_info.h"
 #include "hw/scsi/scsi.h"
 #include "migration/qemu-file-types.h"
 #include "migration/vmstate.h"
 #include "hw/scsi/emulation.h"
 #include "scsi/constants.h"
-#include "system/arch_init.h"
 #include "system/block-backend.h"
 #include "system/blockdev.h"
 #include "hw/block/block.h"
system/qdev-monitor.c +1 -1
index 5588ed2047d..b88e6e83512 100644
@@ -22,7 +22,6 @@
 #include "monitor/hmp.h"
 #include "monitor/monitor.h"
 #include "monitor/qdev.h"
-#include "system/arch_init.h"
 #include "system/runstate.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-qdev.h"
@@ -37,6 +36,7 @@
 #include "qemu/option.h"
 #include "qemu/qemu-print.h"
 #include "qemu/option_int.h"
+#include "qemu/arch_info.h"
 #include "system/block-backend.h"
 #include "migration/misc.h"
 #include "qemu/cutils.h"
system/vl.c +1 -1
index ec93988a03a..e96c72e5400 100644
@@ -27,6 +27,7 @@
 #include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "qemu/module.h"
+#include "qemu/arch_info.h"
 #include "exec/cpu-common.h"
 #include "exec/page-vary.h"
 #include "hw/qdev-properties.h"
@@ -110,7 +111,6 @@
 #include "trace/control.h"
 #include "qemu/plugin.h"
 #include "qemu/queue.h"
-#include "system/arch_init.h"
 #include "system/confidential-guest-support.h"
 
 #include "ui/qemu-spice.h"
system/meson.build +0 -1
index 181195410fb..900c5d52ee4 100644
@@ -1,5 +1,4 @@
 specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
-  'arch_init.c',
   'ioport.c',
   'globals-target.c',
   'memory.c',
Signature · 1 line
2.47.1
Acked-by on v1 5/11
#19 lore raw

Re: [RFC PATCH 05/11] include: Expose QemuArchBit enum to user emulation

Quoted 14 lines · Philippe Mathieu-Daudé

QemuArchBit isn't really specific to system emulation, move the "system/arch_init.h" header to "qemu/arch_info.h", a more generic include path.

---
  meson.build                                      | 2 +-
  include/{system/arch_init.h => qemu/arch_info.h} | 4 ++--
  system/arch_init.c => arch_info-target.c         | 2 +-
  hw/scsi/scsi-disk.c                              | 2 +-
  system/qdev-monitor.c                            | 2 +-
  system/vl.c                                      | 2 +-
  system/meson.build                               | 1 -
  7 files changed, 7 insertions(+), 8 deletions(-)
Quoted 2 lines

rename include/{system/arch_init.h => qemu/arch_info.h} (97%) rename system/arch_init.c => arch_info-target.c (97%)

I can't think of a reason to use QemuArch(Bit) in user-mode. But I can't really justify splitting the header either. It's certainly not "init" related anyway.

r~

#20 lore raw

RFC PATCH 6/11 include: Declare target_name() in common "qemu/arch_info.h"

In reply to Philippe Mathieu-Daudé

No need to include the huge "hw/core/cpu.h" header to get a simple prototype declaration such target_name().

---
 include/hw/core/cpu.h      | 2 --
 include/qemu/arch_info.h   | 2 ++
 arch_info-target.c         | 5 +++++
 cpu-target.c               | 5 -----
 hw/core/machine-qmp-cmds.c | 1 +
 system/vl.c                | 1 -
 6 files changed, 8 insertions(+), 8 deletions(-)
include/hw/core/cpu.h +0 -2
index 5d11d26556a..4f538a8f96d 100644
@@ -1162,8 +1162,6 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp);
 void cpu_exec_unrealizefn(CPUState *cpu);
 void cpu_exec_reset_hold(CPUState *cpu);
 
-const char *target_name(void);
-
 #ifdef COMPILING_PER_TARGET
 
 #ifndef CONFIG_USER_ONLY
include/qemu/arch_info.h +2 -0
index 3cb95926e27..613dc2037db 100644
@@ -46,6 +46,8 @@ typedef enum QemuArchBit {
 #define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
 #define QEMU_ARCH_ALL           -1
 
+const char *target_name(void);
+
 bool qemu_arch_available(unsigned qemu_arch_mask);
 
 #endif
arch_info-target.c +5 -0
index 6c11c73feb9..61007415b30 100644
@@ -24,6 +24,11 @@
 #include "qemu/osdep.h"
 #include "qemu/arch_info.h"
 
+const char *target_name(void)
+{
+    return TARGET_NAME;
+}
+
 bool qemu_arch_available(unsigned qemu_arch_mask)
 {
     return qemu_arch_mask & BIT(QEMU_ARCH_BIT);
cpu-target.c +0 -5
index f7e17a650c0..1177e93c444 100644
@@ -158,8 +158,3 @@ bool target_words_bigendian(void)
 {
     return TARGET_BIG_ENDIAN;
 }
-
-const char *target_name(void)
-{
-    return TARGET_NAME;
-}
hw/core/machine-qmp-cmds.c +1 -0
index 3130c5cd456..3bf280cef16 100644
@@ -19,6 +19,7 @@
 #include "qapi/qobject-input-visitor.h"
 #include "qapi/type-helpers.h"
 #include "qemu/uuid.h"
+#include "qemu/arch_info.h"
 #include "qom/qom-qobject.h"
 #include "system/hostmem.h"
 #include "system/hw_accel.h"
system/vl.c +0 -1
index e96c72e5400..a41ba4a2d5f 100644
@@ -80,7 +80,6 @@
 #include "hw/block/block.h"
 #include "hw/i386/x86.h"
 #include "hw/i386/pc.h"
-#include "hw/core/cpu.h"
 #include "migration/cpr.h"
 #include "migration/misc.h"
 #include "migration/snapshot.h"
Signature · 1 line
2.47.1
Reviewed-by on v1 6/11
#21 lore raw

Re: [RFC PATCH 06/11] include: Declare target_name() in common "qemu/arch_info.h"

Quoted 4 lines · Philippe Mathieu-Daudé

No need to include the huge "hw/core/cpu.h" header to get a simple prototype declaration such target_name().

Quoted 8 lines
---
  include/hw/core/cpu.h      | 2 --
  include/qemu/arch_info.h   | 2 ++
  arch_info-target.c         | 5 +++++
  cpu-target.c               | 5 -----
  hw/core/machine-qmp-cmds.c | 1 +
  system/vl.c                | 1 -
  6 files changed, 8 insertions(+), 8 deletions(-)

You should mention moving the function as well. Otherwise,

r~

#22 lore raw

RFC PATCH 7/11 plugins/loader: populate target_name with target_name()

In reply to Philippe Mathieu-Daudé

From: Alex Bennée <[email protected]>

We have a function we can call for this, lets not rely on macros that stop us building once.

---
 plugins/loader.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
plugins/loader.c +2 -1
index 99686b54666..e56c1003c27 100644
@@ -29,6 +29,7 @@
 #include "qemu/xxhash.h"
 #include "qemu/plugin.h"
 #include "qemu/memalign.h"
+#include "qemu/arch_info.h"
 #include "hw/core/cpu.h"
 #include "exec/tb-flush.h"
 #ifndef CONFIG_USER_ONLY
@@ -297,7 +298,7 @@ int qemu_plugin_load_list(QemuPluginList *head, Error **errp)
     struct qemu_plugin_desc *desc, *next;
     g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1);
 
-    info->target_name = TARGET_NAME;
+    info->target_name = target_name();
     info->version.min = QEMU_PLUGIN_MIN_VERSION;
     info->version.cur = QEMU_PLUGIN_VERSION;
 #ifndef CONFIG_USER_ONLY
Signature · 1 line
2.47.1
#23 lore raw

RFC PATCH 8/11 tests/qtest: Replace TARGET_NAME -> target_name()

In reply to Philippe Mathieu-Daudé

In order to avoid the target-specific TARGET_NAME definition, replace it by the generic target_name() helper.

---
 tests/qtest/fuzz/fuzz.c         | 5 ++---
 tests/qtest/fuzz/generic_fuzz.c | 4 ++--
 tests/qtest/fuzz/i440fx_fuzz.c  | 5 +++--
 tests/qtest/fuzz/qos_fuzz.c     | 5 +++--
 4 files changed, 10 insertions(+), 9 deletions(-)
tests/qtest/fuzz/fuzz.c +2 -3
index ca248a51a6c..84cef4907f9 100644
@@ -17,6 +17,7 @@
 
 #include "qemu/cutils.h"
 #include "qemu/datadir.h"
+#include "qemu/arch_info.h"
 #include "system/system.h"
 #include "system/qtest.h"
 #include "system/runstate.h"
@@ -35,8 +36,6 @@ typedef struct FuzzTargetState {
 
 typedef QSLIST_HEAD(, FuzzTargetState) FuzzTargetList;
 
-static const char *fuzz_arch = TARGET_NAME;
-
 static FuzzTargetList *fuzz_target_list;
 static FuzzTarget *fuzz_target;
 static QTestState *fuzz_qts;
@@ -61,7 +60,7 @@ void fuzz_reset(QTestState *s)
 static QTestState *qtest_setup(void)
 {
     qtest_server_set_send_handler(&qtest_client_inproc_recv, &fuzz_qts);
-    return qtest_inproc_init(&fuzz_qts, false, fuzz_arch,
+    return qtest_inproc_init(&fuzz_qts, false, target_name(),
             &qtest_server_inproc_recv);
 }
 
tests/qtest/fuzz/generic_fuzz.c +2 -2
index d107a496da6..89a9c16ce1f 100644
@@ -12,10 +12,10 @@
 
 #include "qemu/osdep.h"
 #include "qemu/range.h"
+#include "qemu/arch_info.h"
 
 #include <wordexp.h>
 
-#include "hw/core/cpu.h"
 #include "tests/qtest/libqtest.h"
 #include "tests/qtest/libqos/pci-pc.h"
 #include "fuzz.h"
@@ -914,7 +914,7 @@ static size_t generic_fuzz_crossover(const uint8_t *data1, size_t size1, const
 
 static GString *generic_fuzz_cmdline(FuzzTarget *t)
 {
-    GString *cmd_line = g_string_new(TARGET_NAME);
+    GString *cmd_line = g_string_new(target_name());
     if (!getenv("QEMU_FUZZ_ARGS")) {
         usage();
     }
tests/qtest/fuzz/i440fx_fuzz.c +3 -2
index 155fe018f80..7b39a2ad085 100644
@@ -13,6 +13,7 @@
 #include "qemu/osdep.h"
 
 #include "qemu/main-loop.h"
+#include "qemu/arch_info.h"
 #include "tests/qtest/libqtest.h"
 #include "tests/qtest/libqos/pci.h"
 #include "tests/qtest/libqos/pci-pc.h"
@@ -145,11 +146,11 @@ static void i440fx_fuzz_qos(QTestState *s,
     pciconfig_fuzz_qos(s, bus, Data, Size);
 }
 
-static const char *i440fx_qtest_argv = TARGET_NAME " -machine accel=qtest"
+static const char *i440fx_qtest_argv = " -machine accel=qtest"
                                        " -m 0 -display none";
 static GString *i440fx_argv(FuzzTarget *t)
 {
-    return g_string_new(i440fx_qtest_argv);
+    return g_string_append(g_string_new(target_name()), i440fx_qtest_argv);
 }
 
 
tests/qtest/fuzz/qos_fuzz.c +3 -2
index d3839bf9994..fd93c405f2f 100644
@@ -18,6 +18,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/units.h"
+#include "qemu/arch_info.h"
 #include "qapi/error.h"
 #include "exec/memory.h"
 #include "qemu/main-loop.h"
@@ -83,8 +84,8 @@ static GString *qos_build_main_args(void)
         test_arg = test_node->u.test.before(cmd_line, test_arg);
     }
     /* Prepend the arguments that we need */
-    g_string_prepend(cmd_line,
-            TARGET_NAME " -display none -machine accel=qtest -m 64 ");
+    g_string_prepend(cmd_line, target_name());
+    g_string_prepend(cmd_line, " -display none -machine accel=qtest -m 64 ");
     return cmd_line;
 }
 
Signature · 1 line
2.47.1
#24 lore raw

Re: [RFC PATCH 08/11] tests/qtest: Replace TARGET_NAME -> target_name()

Quoted 10 lines · Philippe Mathieu-Daudé

+++ b/tests/qtest/fuzz/qos_fuzz.c

tests/qtest/fuzz/qos_fuzz.c +1 -0
@@ -18,6 +18,7 @@
 
  #include "qemu/osdep.h"
  #include "qemu/units.h"
+#include "qemu/arch_info.h"
  #include "qapi/error.h"
  #include "exec/memory.h"
  #include "qemu/main-loop.h"

tests/qtest/fuzz/qos_fuzz.c static GString *qos_build_main_args(void) · line 90

Quoted 9 lines
tests/qtest/fuzz/qos_fuzz.c +2 -2
@@ -83,8 +84,8 @@ static GString *qos_build_main_args(void)
          test_arg = test_node->u.test.before(cmd_line, test_arg);
      }
      /* Prepend the arguments that we need */
-    g_string_prepend(cmd_line,
-            TARGET_NAME " -display none -machine accel=qtest -m 64 ");
+    g_string_prepend(cmd_line, target_name());
+    g_string_prepend(cmd_line, " -display none -machine accel=qtest -m 64 ");
      return cmd_line;
  }

You're not constructing in the same order.
Swap the two lines with prepend.

r~

#25 lore raw

RFC PATCH 9/11 user: Replace TARGET_NAME -> target_name()

In reply to Philippe Mathieu-Daudé

In order to avoid the target-specific TARGET_NAME definition, replace it by the generic target_name() helper.

---
 bsd-user/main.c   |  9 ++++++---
 linux-user/main.c | 12 +++++++-----
 2 files changed, 13 insertions(+), 8 deletions(-)
bsd-user/main.c +6 -3
index fdb160bed0f..683003c2d52 100644
@@ -25,6 +25,7 @@
 #include "qemu/help-texts.h"
 #include "qemu/units.h"
 #include "qemu/accel.h"
+#include "qemu/arch_info.h"
 #include "qemu-version.h"
 #include <machine/trap.h>
 
@@ -150,9 +151,11 @@ void cpu_loop(CPUArchState *env)
 
 static void usage(void)
 {
-    printf("qemu-" TARGET_NAME " version " QEMU_FULL_VERSION
+    const char *target = target_name();
+
+    printf("qemu-%s version " QEMU_FULL_VERSION
            "\n" QEMU_COPYRIGHT "\n"
-           "usage: qemu-" TARGET_NAME " [options] program [arguments...]\n"
+           "usage: qemu-%s [options] program [arguments...]\n"
            "BSD CPU emulator (compiled for %s emulation)\n"
            "\n"
            "Standard options:\n"
@@ -188,7 +191,7 @@ static void usage(void)
            "\n"
            QEMU_HELP_BOTTOM "\n"
            ,
-           TARGET_NAME,
+           target, target, target,
            interp_prefix,
            target_dflssiz);
     exit(1);
linux-user/main.c +7 -5
index 5c74c52cc52..0e4722ea273 100644
@@ -21,6 +21,7 @@
 #include "qemu/help-texts.h"
 #include "qemu/units.h"
 #include "qemu/accel.h"
+#include "qemu/arch_info.h"
 #include "qemu-version.h"
 #include <sys/syscall.h>
 #include <sys/resource.h>
@@ -432,8 +433,8 @@ static void handle_arg_strace(const char *arg)
 
 static void handle_arg_version(const char *arg)
 {
-    printf("qemu-" TARGET_NAME " version " QEMU_FULL_VERSION
-           "\n" QEMU_COPYRIGHT "\n");
+    printf("qemu-%s version " QEMU_FULL_VERSION
+           "\n" QEMU_COPYRIGHT "\n", target_name());
     exit(EXIT_SUCCESS);
 }
 
@@ -543,14 +544,15 @@ static const struct qemu_argument arg_table[] = {
 static void usage(int exitcode)
 {
     const struct qemu_argument *arginfo;
+    const char *target = target_name();
     int maxarglen;
     int maxenvlen;
 
-    printf("usage: qemu-" TARGET_NAME " [options] program [arguments...]\n"
-           "Linux CPU emulator (compiled for " TARGET_NAME " emulation)\n"
+    printf("usage: qemu-%s [options] program [arguments...]\n"
+           "Linux CPU emulator (compiled for %s emulation)\n"
            "\n"
            "Options and associated environment variables:\n"
-           "\n");
+           "\n", target, target);
 
     /* Calculate column widths. We must always have at least enough space
      * for the column header.
Signature · 1 line
2.47.1
#26 lore raw

RFC PATCH 10/11 qemu: Introduce qemu_arch_name() helper

In reply to Philippe Mathieu-Daudé

Introduce a generic helper to get the target name of a QemuArchBit. (This will be used for single / heterogeneous binaries). Use it in target_name(), removing the last use of the TARGET_NAME definition.

---
 include/qemu/arch_info.h |  2 ++
 arch_info-target.c       | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)
include/qemu/arch_info.h +2 -0
index 613dc2037db..7e3192f590f 100644
@@ -46,6 +46,8 @@ typedef enum QemuArchBit {
 #define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
 #define QEMU_ARCH_ALL           -1
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit);
+
 const char *target_name(void);
 
 bool qemu_arch_available(unsigned qemu_arch_mask);
arch_info-target.c +33 -1
index 61007415b30..9b19fe8d56d 100644
@@ -24,9 +24,41 @@
 #include "qemu/osdep.h"
 #include "qemu/arch_info.h"
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit)
+{
+    static const char *legacy_target_names[] = {
+        [QEMU_ARCH_ALPHA] = "alpha",
+        [QEMU_ARCH_BIT_ARM] = TARGET_LONG_BITS == 32 ? "arm" : "aarch64",
+        [QEMU_ARCH_BIT_AVR] = "avr",
+        [QEMU_ARCH_BIT_HEXAGON] = "hexagon",
+        [QEMU_ARCH_BIT_HPPA] = "hppa",
+        [QEMU_ARCH_BIT_I386] = TARGET_LONG_BITS == 32 ? "i386" : "x86_64",
+        [QEMU_ARCH_BIT_LOONGARCH] = "loongarch64",
+        [QEMU_ARCH_BIT_M68K] = "m68k",
+        [QEMU_ARCH_BIT_MICROBLAZE] = TARGET_BIG_ENDIAN ? "microblaze"
+                                                       : "microblazeel",
+        [QEMU_ARCH_BIT_MIPS] = TARGET_BIG_ENDIAN
+                             ? (TARGET_LONG_BITS == 32 ? "mips" : "mips64")
+                             : (TARGET_LONG_BITS == 32 ? "mipsel" : "mips64el"),
+        [QEMU_ARCH_BIT_OPENRISC] = "or1k",
+        [QEMU_ARCH_BIT_PPC] = TARGET_LONG_BITS == 32 ? "ppc" : "ppc64",
+        [QEMU_ARCH_BIT_RISCV] = TARGET_LONG_BITS == 32 ? "riscv32" : "riscv64",
+        [QEMU_ARCH_BIT_RX] = "rx",
+        [QEMU_ARCH_BIT_S390X] = "s390x",
+        [QEMU_ARCH_BIT_SH4] = TARGET_BIG_ENDIAN ? "sh4eb" : "sh4",
+        [QEMU_ARCH_BIT_SPARC] = TARGET_LONG_BITS == 32 ? "sparc" : "sparc64",
+        [QEMU_ARCH_BIT_TRICORE] = "tricore",
+        [QEMU_ARCH_BIT_XTENSA] = TARGET_BIG_ENDIAN ? "xtensaeb" : "xtensa",
+    };
+
+    assert(qemu_arch_bit < ARRAY_SIZE(legacy_target_names));
+    assert(legacy_target_names[qemu_arch_bit]);
+    return legacy_target_names[qemu_arch_bit];
+}
+
 const char *target_name(void)
 {
-    return TARGET_NAME;
+    return qemu_arch_name(QEMU_ARCH_BIT);
 }
 
 bool qemu_arch_available(unsigned qemu_arch_mask)
Signature · 1 line
2.47.1
#27 lore raw

Re: [RFC PATCH 10/11] qemu: Introduce qemu_arch_name() helper

Quoted 59 lines · Philippe Mathieu-Daudé

Introduce a generic helper to get the target name of a QemuArchBit. (This will be used for single / heterogeneous binaries). Use it in target_name(), removing the last use of the TARGET_NAME definition.

---
include/qemu/arch_info.h | 2 ++
arch_info-target.c | 34 +++++++++++++++++++++++++++++++++-

2 files changed, 35 insertions(+), 1 deletion(-)
include/qemu/arch_info.h +2 -0
index 613dc2037db..7e3192f590f 100644
@@ -46,6 +46,8 @@ typedef enum QemuArchBit {
 #define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
 #define QEMU_ARCH_ALL           -1
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit);
+
 const char *target_name(void);
 
 bool qemu_arch_available(unsigned qemu_arch_mask);
arch_info-target.c +27 -0
index 61007415b30..9b19fe8d56d 100644
@@ -24,9 +24,41 @@
 #include "qemu/osdep.h"
 #include "qemu/arch_info.h"
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit)
+{
+    static const char *legacy_target_names[] = {
+        [QEMU_ARCH_ALPHA] = "alpha",
+        [QEMU_ARCH_BIT_ARM] = TARGET_LONG_BITS == 32 ? "arm" : "aarch64",
+        [QEMU_ARCH_BIT_AVR] = "avr",
+        [QEMU_ARCH_BIT_HEXAGON] = "hexagon",
+        [QEMU_ARCH_BIT_HPPA] = "hppa",
+        [QEMU_ARCH_BIT_I386] = TARGET_LONG_BITS == 32 ? "i386" : "x86_64",
+        [QEMU_ARCH_BIT_LOONGARCH] = "loongarch64",
+        [QEMU_ARCH_BIT_M68K] = "m68k",
+        [QEMU_ARCH_BIT_MICROBLAZE] = TARGET_BIG_ENDIAN ? "microblaze"
+                                                       : "microblazeel",
+        [QEMU_ARCH_BIT_MIPS] = TARGET_BIG_ENDIAN
+                             ? (TARGET_LONG_BITS == 32 ? "mips" : "mips64")
+                             : (TARGET_LONG_BITS == 32 ? "mipsel" : "mips64el"),
+        [QEMU_ARCH_BIT_OPENRISC] = "or1k",
+        [QEMU_ARCH_BIT_PPC] = TARGET_LONG_BITS == 32 ? "ppc" : "ppc64",
+        [QEMU_ARCH_BIT_RISCV] = TARGET_LONG_BITS == 32 ? "riscv32" : "riscv64",
+        [QEMU_ARCH_BIT_RX] = "rx",
+        [QEMU_ARCH_BIT_S390X] = "s390x",
+        [QEMU_ARCH_BIT_SH4] = TARGET_BIG_ENDIAN ? "sh4eb" : "sh4",
+        [QEMU_ARCH_BIT_SPARC] = TARGET_LONG_BITS == 32 ? "sparc" : "sparc64",
+        [QEMU_ARCH_BIT_TRICORE] = "tricore",
+        [QEMU_ARCH_BIT_XTENSA] = TARGET_BIG_ENDIAN ? "xtensaeb" : "xtensa",
+    };
+

arch_info-target.c line 62

Quoted 10 lines
arch_info-target.c +6 -1
+    assert(qemu_arch_bit < ARRAY_SIZE(legacy_target_names));
+    assert(legacy_target_names[qemu_arch_bit]);
+    return legacy_target_names[qemu_arch_bit];
+}
+
 const char *target_name(void)
 {
-    return TARGET_NAME;
+    return qemu_arch_name(QEMU_ARCH_BIT);
 }

Why two functions that do the same? Do you plan to remove target_name later or it should just do what the new function does?

Regards,
BALATON Zoltan

Quoted 2 lines
arch_info-target.c +0 -0
 bool qemu_arch_available(unsigned qemu_arch_mask)
 
#28 lore raw

Re: [RFC PATCH 10/11] qemu: Introduce qemu_arch_name() helper

Quoted 71 lines · BALATON Zoltan
Quoted 70 lines · Philippe Mathieu-Daudé

Introduce a generic helper to get the target name of a QemuArchBit. (This will be used for single / heterogeneous binaries). Use it in target_name(), removing the last use of the TARGET_NAME definition.

---
include/qemu/arch_info.h |  2 ++
arch_info-target.c       | 34 +++++++++++++++++++++++++++++++++-

2 files changed, 35 insertions(+), 1 deletion(-)
include/qemu/arch_info.h +2 -0
index 613dc2037db..7e3192f590f 100644
@@ -46,6 +46,8 @@ typedef enum QemuArchBit {
 #define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
 #define QEMU_ARCH_ALL           -1
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit);
+
 const char *target_name(void);
 
 bool qemu_arch_available(unsigned qemu_arch_mask);
arch_info-target.c +25 -0
index 61007415b30..9b19fe8d56d 100644
@@ -24,9 +24,41 @@
 #include "qemu/osdep.h"
 #include "qemu/arch_info.h"
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit)
+{
+    static const char *legacy_target_names[] = {
+        [QEMU_ARCH_ALPHA] = "alpha",
+        [QEMU_ARCH_BIT_ARM] = TARGET_LONG_BITS == 32 ? "arm" : 
 "aarch64",
+        [QEMU_ARCH_BIT_AVR] = "avr",
+        [QEMU_ARCH_BIT_HEXAGON] = "hexagon",
+        [QEMU_ARCH_BIT_HPPA] = "hppa",
+        [QEMU_ARCH_BIT_I386] = TARGET_LONG_BITS == 32 ? "i386" : 
 "x86_64",
+        [QEMU_ARCH_BIT_LOONGARCH] = "loongarch64",
+        [QEMU_ARCH_BIT_M68K] = "m68k",
+        [QEMU_ARCH_BIT_MICROBLAZE] = TARGET_BIG_ENDIAN ? "microblaze"
+                                                       : "microblazeel",
+        [QEMU_ARCH_BIT_MIPS] = TARGET_BIG_ENDIAN
+                             ? (TARGET_LONG_BITS == 32 ? "mips" : 
 "mips64")
+                             : (TARGET_LONG_BITS == 32 ? "mipsel" : 
 "mips64el"),
+        [QEMU_ARCH_BIT_OPENRISC] = "or1k",
+        [QEMU_ARCH_BIT_PPC] = TARGET_LONG_BITS == 32 ? "ppc" : "ppc64",
+        [QEMU_ARCH_BIT_RISCV] = TARGET_LONG_BITS == 32 ? "riscv32" : 
 "riscv64",
+        [QEMU_ARCH_BIT_RX] = "rx",
+        [QEMU_ARCH_BIT_S390X] = "s390x",
+        [QEMU_ARCH_BIT_SH4] = TARGET_BIG_ENDIAN ? "sh4eb" : "sh4",
+        [QEMU_ARCH_BIT_SPARC] = TARGET_LONG_BITS == 32 ? "sparc" : 
 "sparc64",
+        [QEMU_ARCH_BIT_TRICORE] = "tricore",
+        [QEMU_ARCH_BIT_XTENSA] = TARGET_BIG_ENDIAN ? "xtensaeb" : 

"xtensa",
+    };

arch_info-target.c +5 -0
+
+    assert(qemu_arch_bit < ARRAY_SIZE(legacy_target_names));
+    assert(legacy_target_names[qemu_arch_bit]);
+    return legacy_target_names[qemu_arch_bit];
+}
Quoted 8 lines
Quoted 6 lines

+
const char *target_name(void)
{
-    return TARGET_NAME;
+    return qemu_arch_name(QEMU_ARCH_BIT);
}

Why two functions that do the same? Do you plan to remove target_name later or it should just do what the new function does?

target_name() is a no-op for current binaries, where one binary include a single target.

The "single binary" will include multiple targets. We plan to symlink it to the previous binaries and use argv[0] to mimic previous behavior.

#29 lore raw

Re: [RFC PATCH 10/11] qemu: Introduce qemu_arch_name() helper

Quoted 80 lines · Philippe Mathieu-Daudé
Quoted 70 lines · BALATON Zoltan
Quoted 69 lines · Philippe Mathieu-Daudé

Introduce a generic helper to get the target name of a QemuArchBit. (This will be used for single / heterogeneous binaries). Use it in target_name(), removing the last use of the TARGET_NAME definition.

---
include/qemu/arch_info.h |  2 ++
arch_info-target.c       | 34 +++++++++++++++++++++++++++++++++-

2 files changed, 35 insertions(+), 1 deletion(-)
include/qemu/arch_info.h +2 -0
index 613dc2037db..7e3192f590f 100644
@@ -46,6 +46,8 @@ typedef enum QemuArchBit {
 #define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
 #define QEMU_ARCH_ALL           -1
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit);
+
 const char *target_name(void);
 
 bool qemu_arch_available(unsigned qemu_arch_mask);
arch_info-target.c +31 -0
index 61007415b30..9b19fe8d56d 100644
@@ -24,9 +24,41 @@
 #include "qemu/osdep.h"
 #include "qemu/arch_info.h"
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit)
+{
+    static const char *legacy_target_names[] = {
+        [QEMU_ARCH_ALPHA] = "alpha",
+        [QEMU_ARCH_BIT_ARM] = TARGET_LONG_BITS == 32 ? "arm" : "aarch64",
+        [QEMU_ARCH_BIT_AVR] = "avr",
+        [QEMU_ARCH_BIT_HEXAGON] = "hexagon",
+        [QEMU_ARCH_BIT_HPPA] = "hppa",
+        [QEMU_ARCH_BIT_I386] = TARGET_LONG_BITS == 32 ? "i386" : 
 "x86_64",
+        [QEMU_ARCH_BIT_LOONGARCH] = "loongarch64",
+        [QEMU_ARCH_BIT_M68K] = "m68k",
+        [QEMU_ARCH_BIT_MICROBLAZE] = TARGET_BIG_ENDIAN ? "microblaze"
+                                                       : "microblazeel",
+        [QEMU_ARCH_BIT_MIPS] = TARGET_BIG_ENDIAN
+                             ? (TARGET_LONG_BITS == 32 ? "mips" : 
 "mips64")
+                             : (TARGET_LONG_BITS == 32 ? "mipsel" : 
 "mips64el"),
+        [QEMU_ARCH_BIT_OPENRISC] = "or1k",
+        [QEMU_ARCH_BIT_PPC] = TARGET_LONG_BITS == 32 ? "ppc" : "ppc64",
+        [QEMU_ARCH_BIT_RISCV] = TARGET_LONG_BITS == 32 ? "riscv32" : 
 "riscv64",
+        [QEMU_ARCH_BIT_RX] = "rx",
+        [QEMU_ARCH_BIT_S390X] = "s390x",
+        [QEMU_ARCH_BIT_SH4] = TARGET_BIG_ENDIAN ? "sh4eb" : "sh4",
+        [QEMU_ARCH_BIT_SPARC] = TARGET_LONG_BITS == 32 ? "sparc" : 
 "sparc64",
+        [QEMU_ARCH_BIT_TRICORE] = "tricore",
+        [QEMU_ARCH_BIT_XTENSA] = TARGET_BIG_ENDIAN ? "xtensaeb" : 
 "xtensa",
+    };
+
+    assert(qemu_arch_bit < ARRAY_SIZE(legacy_target_names));
+    assert(legacy_target_names[qemu_arch_bit]);
+    return legacy_target_names[qemu_arch_bit];
+}
Quoted 8 lines
Quoted 6 lines
arch_info-target.c +1 -0
+

const char *target_name(void)
{
-    return TARGET_NAME;
+    return qemu_arch_name(QEMU_ARCH_BIT);
}

Why two functions that do the same? Do you plan to remove target_name later or it should just do what the new function does?

Quoted 5 lines

target_name() is a no-op for current binaries, where one binary include a single target.

The "single binary" will include multiple targets. We plan to symlink it to the previous binaries and use argv[0] to mimic previous behavior.

This didn't answer the question for me why this would need target_name() and qemu_arch_name() which are the same function with two names. If these do the same why not only have one of them?

Regards,
BALATON Zoltan

#30 lore raw

Re: [RFC PATCH 10/11] qemu: Introduce qemu_arch_name() helper

In reply to Philippe Mathieu-Daudé
Quoted 53 lines · Philippe Mathieu-Daudé

Introduce a generic helper to get the target name of a QemuArchBit. (This will be used for single / heterogeneous binaries). Use it in target_name(), removing the last use of the TARGET_NAME definition.

---
  include/qemu/arch_info.h |  2 ++
  arch_info-target.c       | 34 +++++++++++++++++++++++++++++++++-
  2 files changed, 35 insertions(+), 1 deletion(-)
include/qemu/arch_info.h +2 -0
index 613dc2037db..7e3192f590f 100644
@@ -46,6 +46,8 @@ typedef enum QemuArchBit {
  #define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
  #define QEMU_ARCH_ALL           -1
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit);
+
  const char *target_name(void);
 
  bool qemu_arch_available(unsigned qemu_arch_mask);
arch_info-target.c +21 -0
index 61007415b30..9b19fe8d56d 100644
@@ -24,9 +24,41 @@
  #include "qemu/osdep.h"
  #include "qemu/arch_info.h"
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit)
+{
+    static const char *legacy_target_names[] = {
+        [QEMU_ARCH_ALPHA] = "alpha",
+        [QEMU_ARCH_BIT_ARM] = TARGET_LONG_BITS == 32 ? "arm" : "aarch64",
+        [QEMU_ARCH_BIT_AVR] = "avr",
+        [QEMU_ARCH_BIT_HEXAGON] = "hexagon",
+        [QEMU_ARCH_BIT_HPPA] = "hppa",
+        [QEMU_ARCH_BIT_I386] = TARGET_LONG_BITS == 32 ? "i386" : "x86_64",
+        [QEMU_ARCH_BIT_LOONGARCH] = "loongarch64",
+        [QEMU_ARCH_BIT_M68K] = "m68k",
+        [QEMU_ARCH_BIT_MICROBLAZE] = TARGET_BIG_ENDIAN ? "microblaze"
+                                                       : "microblazeel",
+        [QEMU_ARCH_BIT_MIPS] = TARGET_BIG_ENDIAN
+                             ? (TARGET_LONG_BITS == 32 ? "mips" : "mips64")
+                             : (TARGET_LONG_BITS == 32 ? "mipsel" : "mips64el"),
+        [QEMU_ARCH_BIT_OPENRISC] = "or1k",
+        [QEMU_ARCH_BIT_PPC] = TARGET_LONG_BITS == 32 ? "ppc" : "ppc64",
+        [QEMU_ARCH_BIT_RISCV] = TARGET_LONG_BITS == 32 ? "riscv32" : "riscv64",
+        [QEMU_ARCH_BIT_RX] = "rx",
+        [QEMU_ARCH_BIT_S390X] = "s390x",

arch_info-target.c line 57

Quoted 10 lines
arch_info-target.c +10 -0
+        [QEMU_ARCH_BIT_SH4] = TARGET_BIG_ENDIAN ? "sh4eb" : "sh4",
+        [QEMU_ARCH_BIT_SPARC] = TARGET_LONG_BITS == 32 ? "sparc" : "sparc64",
+        [QEMU_ARCH_BIT_TRICORE] = "tricore",
+        [QEMU_ARCH_BIT_XTENSA] = TARGET_BIG_ENDIAN ? "xtensaeb" : "xtensa",
+    };
+
+    assert(qemu_arch_bit < ARRAY_SIZE(legacy_target_names));
+    assert(legacy_target_names[qemu_arch_bit]);
+    return legacy_target_names[qemu_arch_bit];
+}

Given all of the other #defines checked in this function, I don't think it's helpful at all.

I think you should drop this patch for now.

r~

#31 lore raw

Re: [RFC PATCH 10/11] qemu: Introduce qemu_arch_name() helper

In reply to Philippe Mathieu-Daudé
Quoted 29 lines · Philippe Mathieu-Daudé

Introduce a generic helper to get the target name of a QemuArchBit. (This will be used for single / heterogeneous binaries). Use it in target_name(), removing the last use of the TARGET_NAME definition.

---
 include/qemu/arch_info.h |  2 ++
 arch_info-target.c       | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)
include/qemu/arch_info.h +2 -0
index 613dc2037db..7e3192f590f 100644
@@ -46,6 +46,8 @@ typedef enum QemuArchBit {
 #define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
 #define QEMU_ARCH_ALL           -1
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit);
+
 const char *target_name(void);
 
 bool qemu_arch_available(unsigned qemu_arch_mask);
arch_info-target.c +0 -0
index 61007415b30..9b19fe8d56d 100644

arch_info-target.c line 30

Quoted 7 lines
arch_info-target.c +4 -0
@@ -24,9 +24,41 @@
 #include "qemu/osdep.h"
 #include "qemu/arch_info.h"
 
+const char *qemu_arch_name(QemuArchBit qemu_arch_bit)
+{
+    static const char *legacy_target_names[] = {
+        [QEMU_ARCH_ALPHA] = "alpha",

All the others you've used QEMU_ARCH_BIT except for this. Yes, it happens to have the same value either way, but it still looks wrong.

Quoted 11 lines
arch_info-target.c +11 -0
+        [QEMU_ARCH_BIT_ARM] = TARGET_LONG_BITS == 32 ? "arm" : "aarch64",
+        [QEMU_ARCH_BIT_AVR] = "avr",
+        [QEMU_ARCH_BIT_HEXAGON] = "hexagon",
+        [QEMU_ARCH_BIT_HPPA] = "hppa",
+        [QEMU_ARCH_BIT_I386] = TARGET_LONG_BITS == 32 ? "i386" : "x86_64",
+        [QEMU_ARCH_BIT_LOONGARCH] = "loongarch64",
+        [QEMU_ARCH_BIT_M68K] = "m68k",
+        [QEMU_ARCH_BIT_MICROBLAZE] = TARGET_BIG_ENDIAN ? "microblaze"
+                                                       : "microblazeel",
+        [QEMU_ARCH_BIT_MIPS] = TARGET_BIG_ENDIAN
+                             ? (TARGET_LONG_BITS == 32 ? "mips" : "mips64")

arch_info-target.c line 51

Quoted 10 lines
arch_info-target.c +10 -0
+                             : (TARGET_LONG_BITS == 32 ? "mipsel" : "mips64el"),
+        [QEMU_ARCH_BIT_OPENRISC] = "or1k",
+        [QEMU_ARCH_BIT_PPC] = TARGET_LONG_BITS == 32 ? "ppc" : "ppc64",
+        [QEMU_ARCH_BIT_RISCV] = TARGET_LONG_BITS == 32 ? "riscv32" : "riscv64",
+        [QEMU_ARCH_BIT_RX] = "rx",
+        [QEMU_ARCH_BIT_S390X] = "s390x",
+        [QEMU_ARCH_BIT_SH4] = TARGET_BIG_ENDIAN ? "sh4eb" : "sh4",
+        [QEMU_ARCH_BIT_SPARC] = TARGET_LONG_BITS == 32 ? "sparc" : "sparc64",
+        [QEMU_ARCH_BIT_TRICORE] = "tricore",
+        [QEMU_ARCH_BIT_XTENSA] = TARGET_BIG_ENDIAN ? "xtensaeb" : "xtensa",

Why do we need to give arches different names based on endian/bits, as opposed to a fixed int -> name mapping. What's the intended usage of this ?

Since you're calling this a legacy_target_names, should the method also be call qemu_legacy_arch_name() rather than qemu_arch_name - I would have naively expected qemu_arch_name to be a plain mapping.

Quoted 17 lines
arch_info-target.c +8 -1
+    };
+
+    assert(qemu_arch_bit < ARRAY_SIZE(legacy_target_names));
+    assert(legacy_target_names[qemu_arch_bit]);
+    return legacy_target_names[qemu_arch_bit];
+}
+
 const char *target_name(void)
 {
-    return TARGET_NAME;
+    return qemu_arch_name(QEMU_ARCH_BIT);
 }
 
 bool qemu_arch_available(unsigned qemu_arch_mask)
Signature · 1 line
2.47.1

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#32 lore raw

RFC PATCH 11/11 qemu: Remove C definitions of TARGET_NAME

In reply to Philippe Mathieu-Daudé

We don't use TARGET_NAME anymore, remove and poison it globally.

The symbol is still defined in Makefiles by the configure script (it is required by tests/tcg/).

---
 meson.build           | 4 +++-
 include/exec/poison.h | 1 -
 include/qemu/osdep.h  | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
meson.build +3 -1
index 04d8c477644..eaae1da2e92 100644
@@ -3347,7 +3347,9 @@ foreach target : target_dirs
       # Note that TARGET_BASE_ARCH ends up in config-target.h but it is
       # not used to select files from sourcesets.
       config_target_data.set('TARGET_' + v.to_upper(), 1)
-    elif k == 'TARGET_NAME' or k == 'CONFIG_QEMU_INTERP_PREFIX'
+    elif k == 'TARGET_NAME'
+      # do nothing
+    elif k == 'CONFIG_QEMU_INTERP_PREFIX'
       config_target_data.set_quoted(k, v)
     elif v == 'y'
       config_target_data.set(k, 1)
include/exec/poison.h +0 -1
index f4283f693af..0c4ad04eb97 100644
@@ -34,7 +34,6 @@
 #pragma GCC poison TARGET_XTENSA
 
 #pragma GCC poison TARGET_HAS_BFLT
-#pragma GCC poison TARGET_NAME
 #pragma GCC poison TARGET_SUPPORTS_MTTCG
 #pragma GCC poison TARGET_BIG_ENDIAN
 #pragma GCC poison BSWAP_NEEDED
include/qemu/osdep.h +2 -0
index 4397a906807..3167fda68e4 100644
@@ -50,6 +50,8 @@
  */
 #pragma GCC poison TARGET_WORDS_BIGENDIAN
 
+#pragma GCC poison TARGET_NAME
+
 #include "qemu/compiler.h"
 
 /* Older versions of C++ don't get definitions of various macros from
Signature · 1 line
2.47.1