Add runtime helpers for target and config queries.

Note: This will be reimplemented later [1] using proper information in
TargetInfo. Meanwhile, just add a simple implementation.

[1] 
https://patchew.org/QEMU/20250424222112.36194-1-phi...@linaro.org/20250424222112.36194-19-phi...@linaro.org/

Signed-off-by: Pierrick Bouvier <pierrick.bouv...@linaro.org>
---
 meson.build                |   2 +-
 include/qemu/target-info.h |  14 +++++
 target-info.c              | 117 +++++++++++++++++++++++++++++++++++++
 3 files changed, 132 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 6b235b291dc..7094832c3e2 100644
--- a/meson.build
+++ b/meson.build
@@ -3822,7 +3822,7 @@ endif
 common_ss.add(pagevary)
 specific_ss.add(files('page-target.c', 'page-vary-target.c'))
 
-common_ss.add(files('target-info.c'))
+specific_ss.add(files('target-info.c'))
 specific_ss.add(files('target-info-stub.c'))
 
 subdir('backends')
diff --git a/include/qemu/target-info.h b/include/qemu/target-info.h
index 850a2958b9c..d9c0df10c53 100644
--- a/include/qemu/target-info.h
+++ b/include/qemu/target-info.h
@@ -38,4 +38,18 @@ const char *target_machine_typename(void);
  */
 const char *target_cpu_type(void);
 
+bool target_i386(void);
+bool target_x86_64(void);
+bool target_arm(void);
+bool target_aarch64(void);
+bool target_s390x(void);
+bool target_mips(void);
+bool target_mips64(void);
+bool target_loongarch64(void);
+bool target_riscv32(void);
+bool target_riscv64(void);
+bool target_ppc(void);
+bool target_ppc64(void);
+bool target_has_kvm(void);
+
 #endif
diff --git a/target-info.c b/target-info.c
index 16fdca7aaaf..f2bdae18f4f 100644
--- a/target-info.c
+++ b/target-info.c
@@ -29,3 +29,120 @@ const char *target_machine_typename(void)
 {
     return target_info()->machine_typename;
 }
+
+bool target_i386(void)
+{
+#ifdef TARGET_I386
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_x86_64(void)
+{
+#ifdef TARGET_X86_64
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_arm(void)
+{
+#ifdef TARGET_ARM
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_aarch64(void)
+{
+#ifdef TARGET_AARCH64
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_s390x(void)
+{
+#ifdef TARGET_S390X
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_mips(void)
+{
+#ifdef TARGET_MIPS
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_mips64(void)
+{
+#ifdef TARGET_MIPS64
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_loongarch64(void)
+{
+#ifdef TARGET_LOONGARCH64
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_riscv32(void)
+{
+#ifdef TARGET_RISCV32
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_riscv64(void)
+{
+#ifdef TARGET_RISCV64
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_ppc(void)
+{
+#ifdef TARGET_PPC
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_ppc64(void)
+{
+#ifdef TARGET_ppc64
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool target_has_kvm(void)
+{
+#ifdef CONFIG_KVM
+    return true;
+#else
+    return false;
+#endif
+}
-- 
2.47.2


Reply via email to