[PATCH v6 20/30] qemu/target_info: Add target_base_arm() helper

Philippe Mathieu-Daudé posted 30 patches 3 weeks, 3 days ago
Maintainers: Pierrick Bouvier <pierrick.bouvier@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Cédric Le Goater" <clg@kaod.org>, Peter Maydell <peter.maydell@linaro.org>, Steven Lee <steven_lee@aspeedtech.com>, Troy Lee <leetroy@gmail.com>, Jamin Lin <jamin_lin@aspeedtech.com>, Andrew Jeffery <andrew@codeconstruct.com.au>, Joel Stanley <joel@jms.id.au>, Samuel Tardieu <sam@rfc1149.net>, Beniamino Galvani <b.galvani@gmail.com>, Strahinja Jankovic <strahinja.p.jankovic@gmail.com>, Antony Pavlov <antonynpavlov@gmail.com>, Igor Mitsyanko <i.mitsyanko@gmail.com>, Rob Herring <robh@kernel.org>, Jean-Christophe Dubois <jcd@tribudubois.net>, Bernhard Beschow <shentey@gmail.com>, Andrey Smirnov <andrew.smirnov@gmail.com>, Subbaraya Sundeep <sundeep.lkml@gmail.com>, Jan Kiszka <jan.kiszka@web.de>, Alistair Francis <alistair@alistair23.me>, Tyrone Ting <kfting@nuvoton.com>, Hao Wu <wuhaotsh@google.com>, Felipe Balbi <balbi@kernel.org>, Niek Linnenbank <nieklinnenbank@gmail.com>, Radoslaw Biernacki <rad@semihalf.com>, Leif Lindholm <leif.lindholm@oss.qualcomm.com>, Alexandre Iooss <erdnaxe@crans.org>, "Michael S. Tsirkin" <mst@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, Shannon Zhao <shannon.zhaosl@gmail.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>
There is a newer version of this series
[PATCH v6 20/30] qemu/target_info: Add target_base_arm() helper
Posted by Philippe Mathieu-Daudé 3 weeks, 3 days ago
Add a helper to check whether the target base architecture
is ARM (either 32-bit or 64-bit).

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 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;
-- 
2.51.0


Re: [PATCH v6 20/30] qemu/target_info: Add target_base_arm() helper
Posted by Pierrick Bouvier 3 weeks, 3 days ago
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é <philmd@linaro.org>
> ---
>   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 <pierrick.bouvier@linaro.org>