Re: [RFC PATCH v2 08/11] config/target: Implement per-binary TargetInfo structure (ARM)

2025-04-18 Thread Philippe Mathieu-Daudé

On 18/4/25 06:02, Pierrick Bouvier wrote:

On 4/17/25 17:50, Philippe Mathieu-Daudé wrote:

If a file defining the binary TargetInfo structure is available,
link with it. Otherwise keep using the stub. Implement such
structure for arm-softmmu.

Signed-off-by: Philippe Mathieu-Daudé 
---
  meson.build   |  7 ++-
  configs/targets/arm-softmmu.c | 22 ++
  2 files changed, 28 insertions(+), 1 deletion(-)
  create mode 100644 configs/targets/arm-softmmu.c

diff --git a/meson.build b/meson.build
index 168b07b5887..da24cc2ba41 100644
--- a/meson.build
+++ b/meson.build
@@ -3809,7 +3809,6 @@ specific_ss.add(files('page-target.c', 'page- 
vary-target.c'))

  common_ss.add(files('target_info.c'))
  system_ss.add(files('target_info-qom.c'))
-specific_ss.add(files('target_info-stub.c'))
  subdir('backends')
  subdir('disas')
@@ -4272,6 +4271,12 @@ foreach target : target_dirs
  arch_srcs += gdbstub_xml
    endif
+  target_info_c = meson.project_source_root() / 'configs' / 
'targets' / target + '.c'

+  if not fs.exists(target_info_c)
+    target_info_c = meson.project_source_root() / 'target_info-stub.c'
+  endif
+  arch_srcs += target_info_c
+
    t = target_arch[target_base_arch].apply(config_target, strict: false)
    arch_srcs += t.sources()
    arch_deps += t.dependencies()


While this works, it would be better with a dictionary, so it follows 
the style of existing meson.build.


As well, two advantages:
- we can move configs somewhere else in case we decide to split them in 
every folder later
- We avoid calling fs.exists for every target, but it should not really 
change anything to configure step time.


---

diff --git a/meson.build b/meson.build
index 81afa63853e..7fca3c5c4dc 100644
--- a/meson.build
+++ b/meson.build
@@ -3228,6 +3228,7 @@ config_devices_mak_list = []
  config_devices_h = {}
  config_target_h = {}
  config_target_mak = {}
+target_info = {}

  disassemblers = {
    'alpha' : ['CONFIG_ALPHA_DIS'],
@@ -3823,9 +3824,9 @@ specific_ss.add(files('page-target.c', 'page-vary- 
target.c'))


  common_ss.add(files('target_info.c'))
  system_ss.add(files('target_info-qom.c'))
-specific_ss.add(files('target_info-stub.c'))

  subdir('backends')
+subdir('configs/targets')
  subdir('disas')
  subdir('migration')
  subdir('monitor')
@@ -4286,6 +4287,12 @@ foreach target : target_dirs
  arch_srcs += gdbstub_xml
    endif

+  if target in target_info
+    arch_srcs += target_info[target]
+  else
+    arch_srcs += files('target_info-stub.c')
+  endif
+
    t = target_arch[target_base_arch].apply(config_target, strict: false)
    arch_srcs += t.sources()
    arch_deps += t.dependencies()

diff --git a/configs/targets/meson.build b/configs/targets/meson.build
new file mode 100644
index 000..140386e932c
--- /dev/null
+++ b/configs/targets/meson.build
@@ -0,0 +1,3 @@
+foreach target : ['arm-softmmu', 'aarch64-softmmu']
+  target_info += {target : files(target + '.c')}
+endforeach



Thanks for showing the dictionary variant!



Re: [RFC PATCH v2 08/11] config/target: Implement per-binary TargetInfo structure (ARM)

2025-04-17 Thread Pierrick Bouvier

On 4/17/25 17:50, Philippe Mathieu-Daudé wrote:

If a file defining the binary TargetInfo structure is available,
link with it. Otherwise keep using the stub. Implement such
structure for arm-softmmu.

Signed-off-by: Philippe Mathieu-Daudé 
---
  meson.build   |  7 ++-
  configs/targets/arm-softmmu.c | 22 ++
  2 files changed, 28 insertions(+), 1 deletion(-)
  create mode 100644 configs/targets/arm-softmmu.c

diff --git a/meson.build b/meson.build
index 168b07b5887..da24cc2ba41 100644
--- a/meson.build
+++ b/meson.build
@@ -3809,7 +3809,6 @@ specific_ss.add(files('page-target.c', 
'page-vary-target.c'))
  
  common_ss.add(files('target_info.c'))

  system_ss.add(files('target_info-qom.c'))
-specific_ss.add(files('target_info-stub.c'))
  
  subdir('backends')

  subdir('disas')
@@ -4272,6 +4271,12 @@ foreach target : target_dirs
  arch_srcs += gdbstub_xml
endif
  
+  target_info_c = meson.project_source_root() / 'configs' / 'targets' / target + '.c'

+  if not fs.exists(target_info_c)
+target_info_c = meson.project_source_root() / 'target_info-stub.c'
+  endif
+  arch_srcs += target_info_c
+
t = target_arch[target_base_arch].apply(config_target, strict: false)
arch_srcs += t.sources()
arch_deps += t.dependencies()
diff --git a/configs/targets/arm-softmmu.c b/configs/targets/arm-softmmu.c
new file mode 100644
index 000..6263d604f19
--- /dev/null
+++ b/configs/targets/arm-softmmu.c
@@ -0,0 +1,22 @@
+/*
+ * QEMU binary/target API (qemu-system-arm)
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/target_info-impl.h"
+#include "qemu/target_info-qom.h"
+#include "cpu-qom.h"
+
+static const TargetInfo target_info_arm_system = {
+.name = "arm",
+.machine_typename = TYPE_TARGET_ARM_MACHINE,
+};
+
+const TargetInfo *target_info(void)
+{
+return &target_info_arm_system;
+}


You can extract this from this commit, and squash with aarch64 target.
I think it's a good idea to store this in configs/targets.


Re: [RFC PATCH v2 08/11] config/target: Implement per-binary TargetInfo structure (ARM)

2025-04-17 Thread Pierrick Bouvier

On 4/17/25 17:50, Philippe Mathieu-Daudé wrote:

If a file defining the binary TargetInfo structure is available,
link with it. Otherwise keep using the stub. Implement such
structure for arm-softmmu.

Signed-off-by: Philippe Mathieu-Daudé 
---
  meson.build   |  7 ++-
  configs/targets/arm-softmmu.c | 22 ++
  2 files changed, 28 insertions(+), 1 deletion(-)
  create mode 100644 configs/targets/arm-softmmu.c

diff --git a/meson.build b/meson.build
index 168b07b5887..da24cc2ba41 100644
--- a/meson.build
+++ b/meson.build
@@ -3809,7 +3809,6 @@ specific_ss.add(files('page-target.c', 
'page-vary-target.c'))
  
  common_ss.add(files('target_info.c'))

  system_ss.add(files('target_info-qom.c'))
-specific_ss.add(files('target_info-stub.c'))
  
  subdir('backends')

  subdir('disas')
@@ -4272,6 +4271,12 @@ foreach target : target_dirs
  arch_srcs += gdbstub_xml
endif
  
+  target_info_c = meson.project_source_root() / 'configs' / 'targets' / target + '.c'

+  if not fs.exists(target_info_c)
+target_info_c = meson.project_source_root() / 'target_info-stub.c'
+  endif
+  arch_srcs += target_info_c
+
t = target_arch[target_base_arch].apply(config_target, strict: false)
arch_srcs += t.sources()
arch_deps += t.dependencies()


While this works, it would be better with a dictionary, so it follows 
the style of existing meson.build.


As well, two advantages:
- we can move configs somewhere else in case we decide to split them in 
every folder later
- We avoid calling fs.exists for every target, but it should not really 
change anything to configure step time.


---

diff --git a/meson.build b/meson.build
index 81afa63853e..7fca3c5c4dc 100644
--- a/meson.build
+++ b/meson.build
@@ -3228,6 +3228,7 @@ config_devices_mak_list = []
 config_devices_h = {}
 config_target_h = {}
 config_target_mak = {}
+target_info = {}

 disassemblers = {
   'alpha' : ['CONFIG_ALPHA_DIS'],
@@ -3823,9 +3824,9 @@ specific_ss.add(files('page-target.c', 
'page-vary-target.c'))


 common_ss.add(files('target_info.c'))
 system_ss.add(files('target_info-qom.c'))
-specific_ss.add(files('target_info-stub.c'))

 subdir('backends')
+subdir('configs/targets')
 subdir('disas')
 subdir('migration')
 subdir('monitor')
@@ -4286,6 +4287,12 @@ foreach target : target_dirs
 arch_srcs += gdbstub_xml
   endif

+  if target in target_info
+arch_srcs += target_info[target]
+  else
+arch_srcs += files('target_info-stub.c')
+  endif
+
   t = target_arch[target_base_arch].apply(config_target, strict: false)
   arch_srcs += t.sources()
   arch_deps += t.dependencies()

diff --git a/configs/targets/meson.build b/configs/targets/meson.build
new file mode 100644
index 000..140386e932c
--- /dev/null
+++ b/configs/targets/meson.build
@@ -0,0 +1,3 @@
+foreach target : ['arm-softmmu', 'aarch64-softmmu']
+  target_info += {target : files(target + '.c')}
+endforeach