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 [0] "fpu", "vme", "de", "pse",
67 [4] "tsc", "msr", "pae", "mce",
68 [8] "cx8", "apic", nil, "sep",
69 [12] "mtrr", "pge", "mca", "cmov",
70 [16] "pat", "pse36", "pn", "clflush",
71 [20] nil, "dts", "acpi", "mmx",
72 [24] "fxsr", "sse", "sse2", "ss",
73 [28] "ht", "tm", "ia64", "pbe",
75 static char *bitscx[32] = {
76 [0] "pni", "pclmulqdq", "dtes64", "monitor",
77 [4] "ds_cpl", "vmx", "smx", "est",
78 [8] "tm2", "ssse3", "cid", nil,
79 [12] "fma", "cx16", "xtpr", "pdcm",
80 [16] nil, "pcid", "dca", "sse4_1",
81 [20] "sse4_2", "x2apic", "movbe", "popcnt",
82 [24] "tscdeadline", "aes", "xsave", "osxsave",
83 [28] "avx", "f16c", "rdrnd", "hypervisor",
87 Bprint(out, "procmodel %.8ulx / %.8ulx\n", r.ax, r.bx);
88 printbits("features", r.dx, bitsdx);
89 printbits("features", r.cx, bitscx);
96 static char *bitsdx[32] = {
97 [0] "fpu", "vme", "de", "pse",
98 [4] "tsc", "msr", "pae", "mce",
99 [8] "cx8", "apic", nil, "syscall",
100 [12] "mtrr", "pge", "mca", "cmov",
101 [16] "pat", "pse36", nil, "mp",
102 [20] "nx", nil, "mmx+", "mmx",
103 [24] "fxsr", "ffxsr", "pg1g", "tscp",
104 [28] nil, "lm", "3dnow!+", "3dnow!",
106 static char *bitscx[32] = {
107 [0] "ahf64", "cmp", "svm", "eas",
108 [4] "cr8d", "lzcnt", "sse4a", "msse",
109 [8] "3dnow!p", "osvw", "ibs", "xop",
110 [12] "skinit", "wdt", nil, "lwp",
111 [16] "fma4", "tce", nil, "nodeid",
112 [20] nil, "tbm", "topx", "pcx_core",
113 [24] "pcx_nb", nil, nil, nil,
114 [28] nil, nil, nil, nil,
118 Bprint(out, "extmodel %.8ulx / %.8ulx\n", r.ax, r.bx);
119 printbits("extfeatures", r.dx, bitsdx);
120 printbits("extfeatures", r.cx, bitscx);
134 for(i = 0; i < 3; i++){
135 r = cpuid(0x80000002 + i, 0);
136 ((ulong *) buf)[4 * i + 0] = r.ax;
137 ((ulong *) buf)[4 * i + 1] = r.bx;
138 ((ulong *) buf)[4 * i + 2] = r.cx;
139 ((ulong *) buf)[4 * i + 3] = r.dx;
144 Bprint(out, "procname %s\n", p);
153 Bprint(out, "physbits %uld\n", CUT(r.ax, 0, 7));
154 Bprint(out, "virtbits %uld\n", CUT(r.ax, 8, 15));
155 if(CUT(r.ax, 16, 23) != 0)
156 Bprint(out, "guestbits %uld\n", CUT(r.ax, 16, 23));
159 void (*funcs[])(ulong) = {
164 void (*extfuncs[])(ulong) = {
178 Bprint(out, "%.8ulx %.8ulx %.8ulx %.8ulx %.8ulx\n", ax, r.ax, r.bx, r.cx, r.dx);
181 char Egreg[] = "this information is classified";
184 notehand(void *, char *s)
186 if(strncmp(s, "sys:", 4) == 0)
192 main(int argc, char **argv)
201 case 'r': rflag++; break;
202 case 'a': aflag++; break;
205 w = *(ulong *)0x1000;
209 Binit(&buf, 1, OWRITE);
212 for(i = 0; i <= r.ax; i++)
213 if(i >= nelem(funcs) || funcs[i] == nil || rflag){
218 r = cpuid(0x80000000, 0);
220 for(i = 0; i <= r.ax; i++)
221 if(i >= nelem(extfuncs) || extfuncs[i] == nil || rflag){
223 stdfunc(0x80000000 | i);
225 extfuncs[i](0x80000000 | i);