]> git.ozlabs.org Git - ccan/commitdiff
cpuid: only compile source file if x86 cpu
authorAhmed Samy <f.fallen45@gmail.com>
Mon, 23 Sep 2013 22:40:41 +0000 (22:40 +0000)
committerAhmed Samy <f.fallen45@gmail.com>
Mon, 23 Sep 2013 22:41:28 +0000 (22:41 +0000)
Suggested-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Ahmed Samy <f.fallen45@gmail.com>
ccan/cpuid/cpuid.c
ccan/cpuid/issupprted.S
ccan/cpuid/test/run.c

index 6ab0e50f4256fa30e8678667336f89313ace5677..6a45116d710f08410d9bad56d0afdafd1c912fd2 100644 (file)
  * This file has been written with some help from wikipedia:
  *     http://en.wikipedia.org/wiki/CPUID
  */
+
+/* Only compile this file if we're on a x86 machine.  */
+#if defined(__i386__) || defined(__i386) || defined(__x86_64) \
+       || defined(_M_AMD64) || defined(__M_X64)
 #include <stdint.h>
 #include <string.h>
 
@@ -248,3 +252,7 @@ void cpuid(cpuid_t info, void *buf)
        }
 }
 
+#else
+#warning "Cannot compile this file on a non-x86 machine"
+#endif
+
index 8fe859633c7050155ace309aa32b3abdf409781d..80ed0fd0113fe797e010598cc67d1fe86b123fd2 100644 (file)
@@ -2,6 +2,10 @@
   Test if the CPUID instruction is available.
   returns 1 if so, 0 otherwise.  */
 
+/* Only compile this file if we're on a x86 machine.  */
+#if defined(__i386__) || defined(__i386) || defined(__x86_64) \
+       || defined(_M_AMD64) || defined(__M_X64)
+
 .section .text
 .global cpuid_is_supported
 .type cpuid_is_supported, @function
@@ -26,4 +30,5 @@ cpuid_is_supported:
        ret
 
        .size cpuid_is_supported, .-cpuid_is_supported
+#endif
 
index 1f523e4aa207e4db7290961a48f996cc85984c99..21e9aa60d38d2eae7be25f999f9de322a91e53a9 100644 (file)
@@ -10,16 +10,13 @@ int main()
                return 1;
        }
 
-       char buf[128];
-       cpuid(CPU_VENDORID, buf);
-       printf ("Vendor ID: %s\n", buf);
+       printf ("Vendor ID: %s\n", cpuid_get_cpu_type_string (cpuid_get_cpu_type ()));
 
+       char buf[48];
        cpuid(CPU_PROC_BRAND_STRING, buf);
        printf ("Processor Brand: %s\n", buf);
 
-       int addr;
-       cpuid(CPU_HIGHEST_EXTENDED_FUNCTION_SUPPORTED, &addr);
-       printf ("Highest extended function supported: %#010x\n", addr);
+       printf ("Highest extended function supported: %#010x\n", cpuid_highest_ext_func_supported());
 
        union {
                struct {
@@ -48,7 +45,7 @@ int main()
        } l2c;
 
        cpuid(CPU_EXTENDED_L2_CACHE_FEATURES, &l2c.w);
-       printf ("L2 Cache Size: %u KB\tLine Size: %u bytes\tAssociativity: %02xh\n",
+       printf ("L2 Cache Size: %ld KB\tLine Size: %ld bytes\tAssociativity: %02xh\n",
                        l2c.cache_size, l2c.line_size, l2c.assoc);
 
        int invalid;