2 * mono-hwcap-arm.c: ARM hardware feature detection
5 * Alex Rønne Petersen (alexrp@xamarin.com)
6 * Elijah Taylor (elijahtaylor@google.com)
7 * Miguel de Icaza (miguel@xamarin.com)
8 * Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com)
9 * Paolo Molaro (lupus@xamarin.com)
10 * Rodrigo Kumpera (kumpera@gmail.com)
11 * Sebastien Pouliot (sebastien@xamarin.com)
12 * Zoltan Varga (vargaz@xamarin.com)
14 * Copyright 2003 Ximian, Inc.
15 * Copyright 2003-2011 Novell, Inc
16 * Copyright 2006 Broadcom
17 * Copyright 2007-2008 Andreas Faerber
18 * Copyright 2011-2013 Xamarin Inc
21 #include "mono/utils/mono-hwcap-arm.h"
23 #if defined(PLATFORM_ANDROID)
25 #elif defined(__linux__)
27 #elif defined(__APPLE__)
28 #include <mach/machine.h>
29 #include <sys/sysctl.h>
30 #include <sys/types.h>
33 gboolean mono_hwcap_arm_is_v5 = FALSE;
34 gboolean mono_hwcap_arm_is_v6 = FALSE;
35 gboolean mono_hwcap_arm_is_v7 = FALSE;
36 gboolean mono_hwcap_arm_is_v7s = FALSE;
37 gboolean mono_hwcap_arm_has_vfp = FALSE;
38 gboolean mono_hwcap_arm_has_thumb = FALSE;
39 gboolean mono_hwcap_arm_has_thumb2 = FALSE;
42 mono_hwcap_init (void)
44 #if defined(PLATFORM_ANDROID)
45 /* We can't use the auxiliary vector on Android due to
46 * permissions, so fall back to /proc/cpuinfo.
52 FILE *file = fopen ("/proc/cpuinfo", "r");
55 while ((line = fgets (buf, 512, file))) {
56 if (!strncmp (line, "Processor", 9)) {
57 char *ver = strstr (line, "(v");
61 mono_hwcap_arm_is_v5 = TRUE;
64 mono_hwcap_arm_is_v6 = TRUE;
67 mono_hwcap_arm_is_v7 = TRUE;
69 /* TODO: Find a way to detect v7s. */
75 if (!strncmp (line, "Features", 8)) {
76 char *thumb = strstr (line, "thumb");
79 mono_hwcap_arm_has_thumb = TRUE;
81 /* TODO: Find a way to detect Thumb 2. */
83 char *vfp = strstr (line, "vfp")
86 mono_hwcap_arm_has_vfp = TRUE;
94 #elif defined(__linux__)
96 unsigned long platform;
98 if ((hwcap = getauxval(AT_HWCAP))) {
100 if (hwcap & 0x00000004)
101 mono_hwcap_arm_has_thumb = TRUE;
104 if (hwcap & 0x00000064)
105 mono_hwcap_arm_has_vfp = TRUE;
107 /* TODO: Find a way to detect Thumb 2. */
110 if ((platform = getauxval(AT_PLATFORM))) {
111 const char *str = (const char *) platform;
114 mono_hwcap_arm_is_v5 = TRUE;
117 mono_hwcap_arm_is_v6 = TRUE;
120 mono_hwcap_arm_is_v7 = TRUE;
122 /* TODO: Find a way to detect v7s. */
124 #elif defined(__APPLE__)
125 cpu_subtype_t sub_type;
126 size_t length = sizeof (sub_type);
128 sysctlbyname ("hw.cpusubtype", &sub_type, &length, NULL, 0);
130 if (sub_type == CPU_SUBTYPE_ARM_V5TEJ || sub_type == CPU_SUBTYPE_ARM_XSCALE) {
131 mono_hwcap_arm_is_v5 = TRUE;
132 } else if (sub_type == CPU_SUBTYPE_ARM_V6) {
133 mono_hwcap_arm_is_v5 = TRUE;
134 mono_hwcap_arm_is_v6 = TRUE;
135 } else if (sub_type == CPU_SUBTYPE_ARM_V7 || sub_type == CPU_SUBTYPE_ARM_V7F || sub_type == CPU_SUBTYPE_ARM_V7K) {
136 mono_hwcap_arm_is_v5 = TRUE;
137 mono_hwcap_arm_is_v6 = TRUE;
138 mono_hwcap_arm_is_v7 = TRUE;
141 /* TODO: Find a way to detect features like Thumb and VFP. */