Commit 73bd4a19 authored by Ahmed Samy's avatar Ahmed Samy

cpuid: only compile source file if x86 cpu

Suggested-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
Signed-off-by: default avatarAhmed Samy <f.fallen45@gmail.com>
parent 3119b7e0
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
* This file has been written with some help from wikipedia: * This file has been written with some help from wikipedia:
* http://en.wikipedia.org/wiki/CPUID * 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 <stdint.h>
#include <string.h> #include <string.h>
...@@ -248,3 +252,7 @@ void cpuid(cpuid_t info, void *buf) ...@@ -248,3 +252,7 @@ void cpuid(cpuid_t info, void *buf)
} }
} }
#else
#warning "Cannot compile this file on a non-x86 machine"
#endif
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
Test if the CPUID instruction is available. Test if the CPUID instruction is available.
returns 1 if so, 0 otherwise. */ 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 .section .text
.global cpuid_is_supported .global cpuid_is_supported
.type cpuid_is_supported, @function .type cpuid_is_supported, @function
...@@ -26,4 +30,5 @@ cpuid_is_supported: ...@@ -26,4 +30,5 @@ cpuid_is_supported:
ret ret
.size cpuid_is_supported, .-cpuid_is_supported .size cpuid_is_supported, .-cpuid_is_supported
#endif
...@@ -10,16 +10,13 @@ int main() ...@@ -10,16 +10,13 @@ int main()
return 1; return 1;
} }
char buf[128]; printf ("Vendor ID: %s\n", cpuid_get_cpu_type_string (cpuid_get_cpu_type ()));
cpuid(CPU_VENDORID, buf);
printf ("Vendor ID: %s\n", buf);
char buf[48];
cpuid(CPU_PROC_BRAND_STRING, buf); cpuid(CPU_PROC_BRAND_STRING, buf);
printf ("Processor Brand: %s\n", buf); printf ("Processor Brand: %s\n", buf);
int addr; printf ("Highest extended function supported: %#010x\n", cpuid_highest_ext_func_supported());
cpuid(CPU_HIGHEST_EXTENDED_FUNCTION_SUPPORTED, &addr);
printf ("Highest extended function supported: %#010x\n", addr);
union { union {
struct { struct {
...@@ -48,7 +45,7 @@ int main() ...@@ -48,7 +45,7 @@ int main()
} l2c; } l2c;
cpuid(CPU_EXTENDED_L2_CACHE_FEATURES, &l2c.w); 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); l2c.cache_size, l2c.line_size, l2c.assoc);
int invalid; int invalid;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment