[PATCH 03/10] target-info: Add functions for querying whether the target is i386 or x86_64

Thomas Huth posted 10 patches 1 week, 2 days ago
Maintainers: Pierrick Bouvier <pierrick.bouvier@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Zhao Liu <zhao1.liu@intel.com>
[PATCH 03/10] target-info: Add functions for querying whether the target is i386 or x86_64
Posted by Thomas Huth 1 week, 2 days ago
From: Thomas Huth <thuth@redhat.com>

As we already have functions for querying whether the target architecture
is one of the various ppc, arm or s390x flavours, add now some functions
for x86, too, which will come in handy to decide during runtime whether
we are running in 32 or 64-bit mode in the x86 targets.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 include/qemu/target-info.h | 21 +++++++++++++++++++++
 target-info.c              | 21 +++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/include/qemu/target-info.h b/include/qemu/target-info.h
index 23c997de541..0713ab4bb16 100644
--- a/include/qemu/target-info.h
+++ b/include/qemu/target-info.h
@@ -99,4 +99,25 @@ bool target_ppc64(void);
  */
 bool target_s390x(void);
 
+/**
+ * target_base_x86:
+ *
+ * Returns whether the target architecture is x86 (32-bit or 64-bit).
+ */
+bool target_base_x86(void);
+
+/**
+ * target_i386:
+ *
+ * Returns whether the target architecture is x86 32-bit.
+ */
+bool target_i386(void);
+
+/**
+ * target_x86_64:
+ *
+ * Returns whether the target architecture is x86 64-bit.
+ */
+bool target_x86_64(void);
+
 #endif
diff --git a/target-info.c b/target-info.c
index 28c458fc7a7..dea73b5fbca 100644
--- a/target-info.c
+++ b/target-info.c
@@ -93,3 +93,24 @@ bool target_s390x(void)
 {
     return target_arch() == SYS_EMU_TARGET_S390X;
 }
+
+bool target_base_x86(void)
+{
+    switch (target_arch()) {
+    case SYS_EMU_TARGET_I386:
+    case SYS_EMU_TARGET_X86_64:
+        return true;
+    default:
+        return false;
+    }
+}
+
+bool target_i386(void)
+{
+    return target_arch() == SYS_EMU_TARGET_I386;
+}
+
+bool target_x86_64(void)
+{
+    return target_arch() == SYS_EMU_TARGET_X86_64;
+}
-- 
2.53.0