On 2025-10-20 15:14, Philippe Mathieu-Daudé wrote:
Add a helper to check whether the target base architecture
is ARM (either 32-bit or 64-bit).

Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
  include/qemu/target-info.h |  7 +++++++
  target-info.c              | 11 +++++++++++
  2 files changed, 18 insertions(+)

diff --git a/include/qemu/target-info.h b/include/qemu/target-info.h
index e8fbdf19d53..62359622232 100644
--- a/include/qemu/target-info.h
+++ b/include/qemu/target-info.h
@@ -50,6 +50,13 @@ const char *target_cpu_type(void);
   */
  bool target_big_endian(void);
+/**
+ * target_base_arm:
+ *
+ * Returns whether the target architecture is ARM or Aarch64.
+ */
+bool target_base_arm(void);
+
  /**
   * target_arm:
   *
diff --git a/target-info.c b/target-info.c
index 332198e40a2..f661b1af289 100644
--- a/target-info.c
+++ b/target-info.c
@@ -63,6 +63,17 @@ bool target_big_endian(void)
      return target_endian_mode() == ENDIAN_MODE_BIG;
  }
+bool target_base_arm(void)
+{
+    switch (target_arch()) {
+    case SYS_EMU_TARGET_ARM:
+    case SYS_EMU_TARGET_AARCH64:
+        return true;
+    default:
+        return false;
+    }
+}
+
  bool target_arm(void)
  {
      return target_arch() == SYS_EMU_TARGET_ARM;

That's good, and we can extend that to all other base arch accordingly. It's a small amount of boilerplate for something that is safe by design and can't be misused.

Reviewed-by: Pierrick Bouvier <[email protected]>


Reply via email to