summaryrefslogtreecommitdiff
path: root/nacl/cpuid/cpuid.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/cpuid/cpuid.c')
-rw-r--r--nacl/cpuid/cpuid.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/nacl/cpuid/cpuid.c b/nacl/cpuid/cpuid.c
new file mode 100644
index 00000000..1a5c6b8e
--- /dev/null
+++ b/nacl/cpuid/cpuid.c
@@ -0,0 +1,41 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <signal.h>
4#include <unistd.h>
5
6void nope()
7{
8 exit(1);
9}
10
11int main()
12{
13 unsigned long x[4];
14 unsigned long y[4];
15 int i;
16 int j;
17 char c;
18
19 signal(SIGILL,nope);
20
21 x[0] = 0;
22 x[1] = 0;
23 x[2] = 0;
24 x[3] = 0;
25
26 asm volatile(".byte 15;.byte 162" : "=a"(x[0]),"=b"(x[1]),"=c"(x[3]),"=d"(x[2]) : "0"(0) );
27 if (!x[0]) return 0;
28 asm volatile(".byte 15;.byte 162" : "=a"(y[0]),"=b"(y[1]),"=c"(y[2]),"=d"(y[3]) : "0"(1) );
29
30 for (i = 1;i < 4;++i)
31 for (j = 0;j < 4;++j) {
32 c = x[i] >> (8 * j);
33 if (c < 32) c = 32;
34 if (c > 126) c = 126;
35 putchar(c);
36 }
37
38 printf("-%08x-%08x\n",y[0],y[3]);
39
40 return 0;
41}