summaryrefslogtreecommitdiff
path: root/lib/builtins
diff options
context:
space:
mode:
authorAlina Sbirlea <asbirlea@google.com>2016-07-08 16:18:39 +0000
committerAlina Sbirlea <asbirlea@google.com>2016-07-08 16:18:39 +0000
commit81ba9dae4d6bdc223972f0d1ff9bc5b5be77c312 (patch)
tree364b6ad530d21b44af91abd5955336610d5b8fad /lib/builtins
parent088ae11c9b861dd9d8ad08a50a237897200fedce (diff)
Check cpuid supported for i386.
Summary: Reviewers: Subscribers: git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@274868 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/builtins')
-rw-r--r--lib/builtins/cpu_model.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/builtins/cpu_model.c b/lib/builtins/cpu_model.c
index 7b76f9e39..61574cd98 100644
--- a/lib/builtins/cpu_model.c
+++ b/lib/builtins/cpu_model.c
@@ -119,6 +119,31 @@ enum ProcessorFeatures {
FEATURE_EM64T
};
+static bool isCpuIdSupported() {
+#if defined(i386) || defined(__i386__)
+ int __cpuid_supported;
+ __asm(" pushfl\n"
+ " popl %%eax\n"
+ " movl %%eax,%%ecx\n"
+ " xorl $0x00200000,%%eax\n"
+ " pushl %%eax\n"
+ " popfl\n"
+ " pushfl\n"
+ " popl %%eax\n"
+ " movl $0,%0\n"
+ " cmpl %%eax,%%ecx\n"
+ " je 1f\n"
+ " movl $1,%0\n"
+ "1:"
+ : "=r"(__cpuid_supported)
+ :
+ : "eax", "ecx");
+ if (!__cpuid_supported)
+ return 0;
+#endif
+ return 1;
+}
+
#if defined(i386) || defined(__i386__) || defined(__x86__) || \
defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) || \
defined(_M_X64)
@@ -706,7 +731,7 @@ struct __processor_model {
unsigned int __cpu_type;
unsigned int __cpu_subtype;
unsigned int __cpu_features[1];
-} __cpu_model = { 0, 0, 0, { 0 } };
+} __cpu_model = {0, 0, 0, {0}};
/* A constructor function that is sets __cpu_model and __cpu_features with
the right values. This needs to run only once. This constructor is
@@ -726,6 +751,9 @@ __cpu_indicator_init(void) {
if (__cpu_model.__cpu_vendor)
return 0;
+ if (!isCpuIdSupported())
+ return -1;
+
/* Assume cpuid insn present. Run in level 0 to get vendor id. */
if (getX86CpuIDAndInfo(0, &MaxLeaf, &Vendor, &ECX, &EDX)) {
__cpu_model.__cpu_vendor = VENDOR_OTHER;