Mercurial > mplayer.hg
annotate TOOLS/cpuinfo.c @ 22372:915194317cb7
10l to me, typo. it should have read clflush
author | ivo |
---|---|
date | Thu, 01 Mar 2007 11:00:31 +0000 |
parents | 45d4cffd5180 |
children |
rev | line source |
---|---|
12960 | 1 /* small utility to extract CPU information |
17041 | 2 Used by configure to set CPU optimization levels on some operating |
3 systems where /proc/cpuinfo is non-existent or unreliable. */ | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
4 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
5 #include <stdio.h> |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
6 #include <sys/time.h> |
17040
0bfb87188015
correct k6_mtrr detection, add a great deal of infos about newer processors
gpoirier
parents:
13612
diff
changeset
|
7 #include <stdlib.h> |
0bfb87188015
correct k6_mtrr detection, add a great deal of infos about newer processors
gpoirier
parents:
13612
diff
changeset
|
8 #include <string.h> |
18511
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
9 #include <unistd.h> |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
10 |
18910 | 11 #if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION <= 3) && (__MINGW32_MINOR_VERSION < 10) |
9764 | 12 #include <sys/timeb.h> |
17041 | 13 void gettimeofday(struct timeval* t,void* timezone) { |
14 struct timeb timebuffer; | |
15 ftime( &timebuffer ); | |
16 t->tv_sec=timebuffer.time; | |
17 t->tv_usec=1000*timebuffer.millitm; | |
9764 | 18 } |
18926
a163f6de7bdc
usleep is still missing in MinGW, so leave it out of the MinGW version check.
diego
parents:
18910
diff
changeset
|
19 #endif |
a163f6de7bdc
usleep is still missing in MinGW, so leave it out of the MinGW version check.
diego
parents:
18910
diff
changeset
|
20 #ifdef __MINGW32__ |
9764 | 21 #define MISSING_USLEEP |
21555
ababf115f90d
Avoid deprecated _sleep, instead include windows.h and use Sleep just like
reimar
parents:
20009
diff
changeset
|
22 #include <windows.h> |
ababf115f90d
Avoid deprecated _sleep, instead include windows.h and use Sleep just like
reimar
parents:
20009
diff
changeset
|
23 #define sleep(t) Sleep(1000*t); |
9764 | 24 #endif |
25 | |
13612 | 26 #ifdef __BEOS__ |
27 #define usleep(t) snooze(t) | |
28 #endif | |
29 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
30 #ifdef M_UNIX |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
31 typedef long long int64_t; |
17041 | 32 #define MISSING_USLEEP |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
33 #else |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
34 #include <inttypes.h> |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
35 #endif |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
36 |
19999
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
37 #define CPUID_FEATURE_DEF(bit, desc, description) \ |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
38 { bit, desc } |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
39 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
40 typedef struct cpuid_regs { |
17041 | 41 unsigned int eax; |
42 unsigned int ebx; | |
43 unsigned int ecx; | |
44 unsigned int edx; | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
45 } cpuid_regs_t; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
46 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
47 static cpuid_regs_t |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
48 cpuid(int func) { |
17041 | 49 cpuid_regs_t regs; |
50 #define CPUID ".byte 0x0f, 0xa2; " | |
18534
cbcea803efa1
x86_64 only saves ebx, not rbx. Fix some potential compilation problem on amd64.
gpoirier
parents:
18517
diff
changeset
|
51 #ifdef __x86_64__ |
cbcea803efa1
x86_64 only saves ebx, not rbx. Fix some potential compilation problem on amd64.
gpoirier
parents:
18517
diff
changeset
|
52 asm("mov %%rbx, %%rsi\n\t" |
cbcea803efa1
x86_64 only saves ebx, not rbx. Fix some potential compilation problem on amd64.
gpoirier
parents:
18517
diff
changeset
|
53 #else |
18517 | 54 asm("mov %%ebx, %%esi\n\t" |
18534
cbcea803efa1
x86_64 only saves ebx, not rbx. Fix some potential compilation problem on amd64.
gpoirier
parents:
18517
diff
changeset
|
55 #endif |
18517 | 56 CPUID"\n\t" |
18534
cbcea803efa1
x86_64 only saves ebx, not rbx. Fix some potential compilation problem on amd64.
gpoirier
parents:
18517
diff
changeset
|
57 #ifdef __x86_64__ |
cbcea803efa1
x86_64 only saves ebx, not rbx. Fix some potential compilation problem on amd64.
gpoirier
parents:
18517
diff
changeset
|
58 "xchg %%rsi, %%rbx\n\t" |
cbcea803efa1
x86_64 only saves ebx, not rbx. Fix some potential compilation problem on amd64.
gpoirier
parents:
18517
diff
changeset
|
59 #else |
cbcea803efa1
x86_64 only saves ebx, not rbx. Fix some potential compilation problem on amd64.
gpoirier
parents:
18517
diff
changeset
|
60 "xchg %%esi, %%ebx\n\t" |
cbcea803efa1
x86_64 only saves ebx, not rbx. Fix some potential compilation problem on amd64.
gpoirier
parents:
18517
diff
changeset
|
61 #endif |
18517 | 62 : "=a" (regs.eax), "=S" (regs.ebx), "=c" (regs.ecx), "=d" (regs.edx) |
18511
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
63 : "0" (func)); |
17041 | 64 return regs; |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
65 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
66 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
67 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
68 static int64_t |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
69 rdtsc(void) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
70 { |
18847
0e2d54a7cb61
merges two asm constraints to one, patch by Zuxy Meng zuxy PP meng AHH gmail PP com
gpoirier
parents:
18552
diff
changeset
|
71 uint64_t i; |
17041 | 72 #define RDTSC ".byte 0x0f, 0x31; " |
18847
0e2d54a7cb61
merges two asm constraints to one, patch by Zuxy Meng zuxy PP meng AHH gmail PP com
gpoirier
parents:
18552
diff
changeset
|
73 asm volatile (RDTSC : "=A"(i) : ); |
0e2d54a7cb61
merges two asm constraints to one, patch by Zuxy Meng zuxy PP meng AHH gmail PP com
gpoirier
parents:
18552
diff
changeset
|
74 return i; |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
75 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
76 |
18511
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
77 static const char* |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
78 brandname(int i) |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
79 { |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
80 const static char* brandmap[] = { |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
81 NULL, |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
82 "Intel(R) Celeron(R) processor", |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
83 "Intel(R) Pentium(R) III processor", |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
84 "Intel(R) Pentium(R) III Xeon(tm) processor", |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
85 "Intel(R) Pentium(R) III processor", |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
86 NULL, |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
87 "Mobile Intel(R) Pentium(R) III processor-M", |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
88 "Mobile Intel(R) Celeron(R) processor" |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
89 }; |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
90 |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
91 if (i >= sizeof(brandmap)) |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
92 return NULL; |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
93 else |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
94 return brandmap[i]; |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
95 } |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
96 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
97 static void |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
98 store32(char *d, unsigned int v) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
99 { |
17041 | 100 d[0] = v & 0xff; |
101 d[1] = (v >> 8) & 0xff; | |
102 d[2] = (v >> 16) & 0xff; | |
103 d[3] = (v >> 24) & 0xff; | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
104 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
105 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
106 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
107 int |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
108 main(int argc, char **argv) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
109 { |
17041 | 110 cpuid_regs_t regs, regs_ext; |
111 char idstr[13]; | |
112 unsigned max_cpuid; | |
113 unsigned max_ext_cpuid; | |
114 unsigned int amd_flags; | |
115 unsigned int amd_flags2; | |
18511
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
116 const char *model_name = NULL; |
17041 | 117 int i; |
118 char processor_name[49]; | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
119 |
17041 | 120 regs = cpuid(0); |
121 max_cpuid = regs.eax; | |
122 /* printf("%d CPUID function codes\n", max_cpuid+1); */ | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
123 |
17041 | 124 store32(idstr+0, regs.ebx); |
125 store32(idstr+4, regs.edx); | |
126 store32(idstr+8, regs.ecx); | |
127 idstr[12] = 0; | |
128 printf("vendor_id\t: %s\n", idstr); | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
129 |
17041 | 130 regs_ext = cpuid((1<<31) + 0); |
131 max_ext_cpuid = regs_ext.eax; | |
132 if (max_ext_cpuid >= (1<<31) + 1) { | |
133 regs_ext = cpuid((1<<31) + 1); | |
134 amd_flags = regs_ext.edx; | |
135 amd_flags2 = regs_ext.ecx; | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
136 |
17041 | 137 if (max_ext_cpuid >= (1<<31) + 4) { |
138 for (i = 2; i <= 4; i++) { | |
139 regs_ext = cpuid((1<<31) + i); | |
140 store32(processor_name + (i-2)*16, regs_ext.eax); | |
141 store32(processor_name + (i-2)*16 + 4, regs_ext.ebx); | |
142 store32(processor_name + (i-2)*16 + 8, regs_ext.ecx); | |
143 store32(processor_name + (i-2)*16 + 12, regs_ext.edx); | |
144 } | |
145 processor_name[48] = 0; | |
146 model_name = processor_name; | |
22195 | 147 while (*model_name == ' ') { |
148 model_name++; | |
149 } | |
17041 | 150 } |
151 } else { | |
152 amd_flags = 0; | |
153 amd_flags2 = 0; | |
154 } | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
155 |
17041 | 156 if (max_cpuid >= 1) { |
157 static struct { | |
158 int bit; | |
20001 | 159 char *desc; |
17041 | 160 } cap[] = { |
19999
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
161 CPUID_FEATURE_DEF(0, "fpu", "Floating-point unit on-chip"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
162 CPUID_FEATURE_DEF(1, "vme", "Virtual Mode Enhancements"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
163 CPUID_FEATURE_DEF(2, "de", "Debugging Extension"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
164 CPUID_FEATURE_DEF(3, "pse", "Page Size Extension"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
165 CPUID_FEATURE_DEF(4, "tsc", "Time Stamp Counter"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
166 CPUID_FEATURE_DEF(5, "msr", "Pentium Processor MSR"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
167 CPUID_FEATURE_DEF(6, "pae", "Physical Address Extension"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
168 CPUID_FEATURE_DEF(7, "mce", "Machine Check Exception"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
169 CPUID_FEATURE_DEF(8, "cx8", "CMPXCHG8B Instruction Supported"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
170 CPUID_FEATURE_DEF(9, "apic", "On-chip APIC Hardware Enabled"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
171 CPUID_FEATURE_DEF(11, "sep", "SYSENTER and SYSEXIT"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
172 CPUID_FEATURE_DEF(12, "mtrr", "Memory Type Range Registers"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
173 CPUID_FEATURE_DEF(13, "pge", "PTE Global Bit"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
174 CPUID_FEATURE_DEF(14, "mca", "Machine Check Architecture"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
175 CPUID_FEATURE_DEF(15, "cmov", "Conditional Move/Compare Instruction"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
176 CPUID_FEATURE_DEF(16, "pat", "Page Attribute Table"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
177 CPUID_FEATURE_DEF(17, "pse36", "Page Size Extension 36-bit"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
178 CPUID_FEATURE_DEF(18, "pn", "Processor Serial Number"), |
22372 | 179 CPUID_FEATURE_DEF(19, "clflush", "CFLUSH instruction"), |
19999
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
180 CPUID_FEATURE_DEF(21, "dts", "Debug Store"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
181 CPUID_FEATURE_DEF(22, "acpi", "Thermal Monitor and Clock Ctrl"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
182 CPUID_FEATURE_DEF(23, "mmx", "MMX Technology"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
183 CPUID_FEATURE_DEF(24, "fxsr", "FXSAVE/FXRSTOR"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
184 CPUID_FEATURE_DEF(25, "sse", "SSE Extensions"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
185 CPUID_FEATURE_DEF(26, "sse2", "SSE2 Extensions"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
186 CPUID_FEATURE_DEF(27, "ss", "Self Snoop"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
187 CPUID_FEATURE_DEF(28, "ht", "Multi-threading"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
188 CPUID_FEATURE_DEF(29, "tm", "Therm. Monitor"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
189 CPUID_FEATURE_DEF(30, "ia64", "IA-64 Processor"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
190 CPUID_FEATURE_DEF(31, "pbe", "Pend. Brk. EN."), |
17041 | 191 { -1 } |
192 }; | |
193 static struct { | |
194 int bit; | |
195 char *desc; | |
196 } cap2[] = { | |
19999
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
197 CPUID_FEATURE_DEF(0, "pni", "SSE3 Extensions"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
198 CPUID_FEATURE_DEF(3, "monitor", "MONITOR/MWAIT"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
199 CPUID_FEATURE_DEF(4, "ds_cpl", "CPL Qualified Debug Store"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
200 CPUID_FEATURE_DEF(5, "vmx", "Virtual Machine Extensions"), |
20009
2d5790e4ee8f
Add support for "Safer Mode Extensions", "Supplemental SSE3", "Direct Cache Access"
gpoirier
parents:
20001
diff
changeset
|
201 CPUID_FEATURE_DEF(6, "smx", "Safer Mode Extensions"), |
19999
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
202 CPUID_FEATURE_DEF(7, "est", "Enhanced Intel SpeedStep Technology"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
203 CPUID_FEATURE_DEF(8, "tm2", "Thermal Monitor 2"), |
20009
2d5790e4ee8f
Add support for "Safer Mode Extensions", "Supplemental SSE3", "Direct Cache Access"
gpoirier
parents:
20001
diff
changeset
|
204 CPUID_FEATURE_DEF(9, "ssse3", "Supplemental SSE3"), |
19999
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
205 CPUID_FEATURE_DEF(10, "cid", "L1 Context ID"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
206 CPUID_FEATURE_DEF(13, "cx16", "CMPXCHG16B Available"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
207 CPUID_FEATURE_DEF(14, "xtpr", "xTPR Disable"), |
20009
2d5790e4ee8f
Add support for "Safer Mode Extensions", "Supplemental SSE3", "Direct Cache Access"
gpoirier
parents:
20001
diff
changeset
|
208 CPUID_FEATURE_DEF(18, "dca", "Direct Cache Access"), |
17041 | 209 { -1 } |
210 }; | |
211 static struct { | |
212 int bit; | |
20000 | 213 char *desc; |
17041 | 214 } cap_amd[] = { |
19999
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
215 CPUID_FEATURE_DEF(11, "syscall", "SYSCALL and SYSRET"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
216 CPUID_FEATURE_DEF(19, "mp", "MP Capable"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
217 CPUID_FEATURE_DEF(20, "nx", "No-Execute Page Protection"), |
22371 | 218 CPUID_FEATURE_DEF(22, "mmxext", "MMX Technology (AMD Extensions)"), |
19999
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
219 CPUID_FEATURE_DEF(25, "fxsr_opt", "Fast FXSAVE/FXRSTOR"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
220 CPUID_FEATURE_DEF(27, "rdtscp", "RDTSCP Instruction"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
221 CPUID_FEATURE_DEF(29, "lm", "Long Mode Capable"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
222 CPUID_FEATURE_DEF(30, "3dnowext", "3DNow! Extensions"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
223 CPUID_FEATURE_DEF(31, "3dnow", "3DNow!"), |
17041 | 224 { -1 } |
225 }; | |
226 static struct { | |
227 int bit; | |
228 char *desc; | |
229 } cap_amd2[] = { | |
19999
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
230 CPUID_FEATURE_DEF(0, "lahf_lm", "LAHF/SAHF Supported in 64-bit Mode"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
231 CPUID_FEATURE_DEF(1, "cmp_legacy", "Chip Multi-Core"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
232 CPUID_FEATURE_DEF(2, "svm", "Secure Virtual Machine"), |
1ffb54bae960
Convert strings to comments since they're never used,
gpoirier
parents:
18926
diff
changeset
|
233 CPUID_FEATURE_DEF(4, "cr8legacy", "CR8 Available in Legacy Mode"), |
17041 | 234 { -1 } |
235 }; | |
236 unsigned int family, model, stepping; | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
237 |
17041 | 238 regs = cpuid(1); |
18511
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
239 family = (regs.eax >> 8) & 0xf; |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
240 model = (regs.eax >> 4) & 0xf; |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
241 stepping = regs.eax & 0xf; |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
242 |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
243 if (family == 0xf) |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
244 { |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
245 family += (regs.eax >> 20) & 0xff; |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
246 model += ((regs.eax >> 16) & 0xf) << 4; |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
247 } |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
248 |
17041 | 249 printf("cpu family\t: %d\n" |
250 "model\t\t: %d\n" | |
251 "stepping\t: %d\n" , | |
18511
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
252 family, |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
253 model, |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
254 stepping); |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
255 |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
256 if (strstr(idstr, "Intel") && !model_name) { |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
257 if (family == 6 && model == 0xb && stepping == 1) |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
258 model_name = "Intel (R) Celeron (R) processor"; |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
259 else |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
260 model_name = brandname(regs.ebx & 0xf); |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
261 } |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
262 |
17041 | 263 printf("flags\t\t:"); |
264 for (i = 0; cap[i].bit >= 0; i++) { | |
265 if (regs.edx & (1 << cap[i].bit)) { | |
266 printf(" %s", cap[i].desc); | |
267 } | |
268 } | |
269 for (i = 0; cap2[i].bit >= 0; i++) { | |
18511
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
270 if (regs.ecx & (1 << cap2[i].bit)) { |
17041 | 271 printf(" %s", cap2[i].desc); |
272 } | |
273 } | |
274 /* k6_mtrr is supported by some AMD K6-2/K6-III CPUs but | |
275 it is not indicated by a CPUID feature bit, so we | |
276 have to check the family, model and stepping instead. */ | |
277 if (strstr(idstr, "AMD") && | |
278 family == 5 && | |
279 (model >= 9 || model == 8 && stepping >= 8)) | |
280 printf(" %s", "k6_mtrr"); | |
18511
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
281 /* similar for cyrix_arr. */ |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
282 if (strstr(idstr, "Cyrix") && |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
283 (family == 5 && model < 4 || family == 6)) |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
284 printf(" %s", "cyrix_arr"); |
18552
2d996eb065d4
On old WinChips Linux kernel use this to emulate MTRR, patch by Zuxy Meng < zuxy P meng A gmail P com>
poirierg
parents:
18534
diff
changeset
|
285 /* as well as centaur_mcr. */ |
2d996eb065d4
On old WinChips Linux kernel use this to emulate MTRR, patch by Zuxy Meng < zuxy P meng A gmail P com>
poirierg
parents:
18534
diff
changeset
|
286 if (strstr(idstr, "Centaur") && |
2d996eb065d4
On old WinChips Linux kernel use this to emulate MTRR, patch by Zuxy Meng < zuxy P meng A gmail P com>
poirierg
parents:
18534
diff
changeset
|
287 family == 5) |
2d996eb065d4
On old WinChips Linux kernel use this to emulate MTRR, patch by Zuxy Meng < zuxy P meng A gmail P com>
poirierg
parents:
18534
diff
changeset
|
288 printf(" %s", "centaur_mcr"); |
18511
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
289 |
17041 | 290 for (i = 0; cap_amd[i].bit >= 0; i++) { |
291 if (amd_flags & (1 << cap_amd[i].bit)) { | |
292 printf(" %s", cap_amd[i].desc); | |
293 } | |
294 } | |
295 for (i = 0; cap_amd2[i].bit >= 0; i++) { | |
296 if (amd_flags2 & (1 << cap_amd2[i].bit)) { | |
297 printf(" %s", cap_amd2[i].desc); | |
298 } | |
299 } | |
300 printf("\n"); | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
301 |
17041 | 302 if (regs.edx & (1 << 4)) { |
303 int64_t tsc_start, tsc_end; | |
304 struct timeval tv_start, tv_end; | |
305 int usec_delay; | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
306 |
17041 | 307 tsc_start = rdtsc(); |
308 gettimeofday(&tv_start, NULL); | |
309 #ifdef MISSING_USLEEP | |
310 sleep(1); | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
311 #else |
17041 | 312 usleep(100000); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
313 #endif |
17041 | 314 tsc_end = rdtsc(); |
315 gettimeofday(&tv_end, NULL); | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
316 |
17041 | 317 usec_delay = 1000000 * (tv_end.tv_sec - tv_start.tv_sec) |
318 + (tv_end.tv_usec - tv_start.tv_usec); | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
319 |
17041 | 320 printf("cpu MHz\t\t: %.3f\n", |
321 (double)(tsc_end-tsc_start) / usec_delay); | |
322 } | |
323 } | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
324 |
18511
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
325 printf("model name\t: "); |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
326 if (model_name) |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
327 printf("%s\n", model_name); |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
328 else |
744aa553e4a1
Various improvement, fix build on AMD-64 and icc
gpoirier
parents:
17041
diff
changeset
|
329 printf("Unknown %s CPU\n", idstr); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
diff
changeset
|
330 } |