5 #define CUT(x, a, b) (((x)&((1<<((b)+1))-1))>>(a))
14 0x8B, 0x44, 0x24, 0x08, /* MOV 8(SP), AX */
15 0x31, 0xDB, /* XOR BX, BX */
16 0x8B, 0x4C, 0x24, 0x0C, /* MOV 12(SP), CX */
17 0x31, 0xD2, /* XOR DX, DX */
18 0x0F, 0xA2, /* CPUID */
19 0x8B, 0x7C, 0x24, 0x04, /* MOV 4(SP), DI */
20 0x89, 0x07, /* MOV AX, (DI) */
21 0x89, 0x5F, 0x04, /* MOV BX, 4(DI) */
22 0x89, 0x4F, 0x08, /* MOV CX, 8(DI) */
23 0x89, 0x57, 0x0C, /* MOV DX, 12(DI) */
27 Res (*cpuid)(ulong ax, ulong cx) = (Res(*)(ulong, ulong)) _cpuid;
36 ((ulong *) buf)[0] = r.bx;
37 ((ulong *) buf)[1] = r.dx;
38 ((ulong *) buf)[2] = r.cx;
40 Bprint(out, "vendor %s\n", buf);
44 printbits(char *id, ulong x, char **s)
48 for(i = 0, j = 0; i < 32; i++)
49 if((x & (1<<i)) != 0 && s[i] != nil){
53 Bprint(out, "%s ", id);
55 Bprint(out, "%s ", s[i]);
65 static char *bitsdx[32] = {
66 "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce", "cx8", "apic",
67 nil, "sep", "mtrr", "pge", "mca", "cmov", "pat", "pse36", "pn", "clflush",
68 nil, "dts", "acpi", "mmx", "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", "pbe",
70 static char *bitscx[32] = {
71 "pni", "pclmulqdq", "dtes64", "monitor", "ds_cpl", "vmx", "smx", "est", "tm2", "ssse3",
72 "cid", nil, "fma", "cx16", "xtpr", "pdcm", nil, "pcid", "dca", "sse4_1", "sse4_2", "x2apic",
73 "movbe", "popcnt", "tscdeadline", "aes", "xsave", "osxsave", "avx",
74 "f16c", "rdrnd", "hypervisor"
78 Bprint(out, "procmodel %.8ulx / %.8ulx\n", r.ax, r.bx);
79 printbits("features", r.dx, bitsdx);
80 printbits("features", r.cx, bitscx);
87 static char *bitsdx[32] = {
88 "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce", "cx8", "apic",
89 nil, "syscall", "mtrr", "pge", "mca", "cmov", "pat", "pse36", nil, "mp",
90 "nx", nil, "mmx+", "mmx", "fxsr", "ffxsr", "pg1g", "tscp", nil, "lm", "3dnow!+", "3dnow!"
92 static char *bitscx[32] = {
93 "ahf64", "cmp", "svm", "eas", "cr8d", "lzcnt", "sse4a", "msse", "3dnow!p", "osvw", "ibs",
94 "xop", "skinit", "wdt", nil, "lwp", "fma4", "tce", nil, "nodeid", nil, "tbm", "topx",
99 Bprint(out, "extmodel %.8ulx / %.8ulx\n", r.ax, r.bx);
100 printbits("extfeatures", r.dx, bitsdx);
101 printbits("extfeatures", r.cx, bitscx);
115 for(i = 0; i < 3; i++){
116 r = cpuid(0x80000002 + i, 0);
117 ((ulong *) buf)[4 * i + 0] = r.ax;
118 ((ulong *) buf)[4 * i + 1] = r.bx;
119 ((ulong *) buf)[4 * i + 2] = r.cx;
120 ((ulong *) buf)[4 * i + 3] = r.dx;
125 Bprint(out, "procname %s\n", p);
134 Bprint(out, "physbits %uld\n", CUT(r.ax, 0, 7));
135 Bprint(out, "virtbits %uld\n", CUT(r.ax, 8, 15));
136 if(CUT(r.ax, 16, 23) != 0)
137 Bprint(out, "guestbits %uld\n", CUT(r.ax, 16, 23));
140 void (*funcs[])(ulong) = {
145 void (*extfuncs[])(ulong) = {
159 Bprint(out, "%.8ulx %.8ulx %.8ulx %.8ulx %.8ulx\n", ax, r.ax, r.bx, r.cx, r.dx);
162 char Egreg[] = "this information is classified";
165 notehand(void *, char *s)
167 if(strncmp(s, "sys:", 4) == 0)
173 main(int argc, char **argv)
182 case 'r': rflag++; break;
183 case 'a': aflag++; break;
186 w = *(ulong *)0x1000;
190 Binit(&buf, 1, OWRITE);
193 for(i = 0; i <= r.ax; i++)
194 if(i >= nelem(funcs) || funcs[i] == nil || rflag){
199 r = cpuid(0x80000000, 0);
201 for(i = 0; i <= r.ax; i++)
202 if(i >= nelem(extfuncs) || extfuncs[i] == nil || rflag){
204 stdfunc(0x80000000 | i);
206 extfuncs[i](0x80000000 | i);