5 #define CUT(x, a, b) (((x)&((1<<((b)+1))-1))>>(a))
14 0x5E, /* POP SI (PC) */
15 0x5D, /* POP BP (Res&) */
24 0x31, 0xDB, /* XOR BX, BX */
25 0x31, 0xD2, /* XOR DX, DX */
27 0x0F, 0xA2, /* CPUID */
29 0x89, 0x45, 0x00, /* MOV AX, 0(BP) */
30 0x89, 0x5d, 0x04, /* MOV BX, 4(BP) */
31 0x89, 0x4d, 0x08, /* MOV CX, 8(BP) */
32 0x89, 0x55, 0x0C, /* MOV DX, 12(BP) */
36 Res (*cpuid)(ulong ax, ulong cx) = (Res(*)(ulong, ulong)) _cpuid;
45 ((ulong *) buf)[0] = r.bx;
46 ((ulong *) buf)[1] = r.dx;
47 ((ulong *) buf)[2] = r.cx;
49 Bprint(out, "vendor %s\n", buf);
53 printbits(char *id, ulong x, char **s)
57 for(i = 0, j = 0; i < 32; i++)
58 if((x & (1<<i)) != 0 && s[i] != nil){
62 Bprint(out, "%s ", id);
64 Bprint(out, "%s ", s[i]);
74 static char *bitsdx[32] = {
75 [0] "fpu", "vme", "de", "pse",
76 [4] "tsc", "msr", "pae", "mce",
77 [8] "cx8", "apic", nil, "sep",
78 [12] "mtrr", "pge", "mca", "cmov",
79 [16] "pat", "pse36", "pn", "clflush",
80 [20] nil, "dts", "acpi", "mmx",
81 [24] "fxsr", "sse", "sse2", "ss",
82 [28] "ht", "tm", "ia64", "pbe",
84 static char *bitscx[32] = {
85 [0] "pni", "pclmulqdq", "dtes64", "monitor",
86 [4] "ds_cpl", "vmx", "smx", "est",
87 [8] "tm2", "ssse3", "cid", nil,
88 [12] "fma", "cx16", "xtpr", "pdcm",
89 [16] nil, "pcid", "dca", "sse4_1",
90 [20] "sse4_2", "x2apic", "movbe", "popcnt",
91 [24] "tscdeadline", "aes", "xsave", "osxsave",
92 [28] "avx", "f16c", "rdrnd", "hypervisor",
96 Bprint(out, "procmodel %.8ulx / %.8ulx\n", r.ax, r.bx);
97 printbits("features", r.dx, bitsdx);
98 printbits("features", r.cx, bitscx);
105 static char *bitsax[32] = {
110 printbits("features", r.ax, bitsax);
117 static char *bitsdx[32] = {
118 [0] "fpu", "vme", "de", "pse",
119 [4] "tsc", "msr", "pae", "mce",
120 [8] "cx8", "apic", nil, "syscall",
121 [12] "mtrr", "pge", "mca", "cmov",
122 [16] "pat", "pse36", nil, "mp",
123 [20] "nx", nil, "mmx+", "mmx",
124 [24] "fxsr", "ffxsr", "pg1g", "tscp",
125 [28] nil, "lm", "3dnow!+", "3dnow!",
127 static char *bitscx[32] = {
128 [0] "ahf64", "cmp", "svm", "eas",
129 [4] "cr8d", "lzcnt", "sse4a", "msse",
130 [8] "3dnow!p", "osvw", "ibs", "xop",
131 [12] "skinit", "wdt", nil, "lwp",
132 [16] "fma4", "tce", nil, "nodeid",
133 [20] nil, "tbm", "topx", "pcx_core",
134 [24] "pcx_nb", nil, nil, nil,
135 [28] nil, nil, nil, nil,
139 Bprint(out, "extmodel %.8ulx / %.8ulx\n", r.ax, r.bx);
140 printbits("extfeatures", r.dx, bitsdx);
141 printbits("extfeatures", r.cx, bitscx);
155 for(i = 0; i < 3; i++){
156 r = cpuid(0x80000002 + i, 0);
157 ((ulong *) buf)[4 * i + 0] = r.ax;
158 ((ulong *) buf)[4 * i + 1] = r.bx;
159 ((ulong *) buf)[4 * i + 2] = r.cx;
160 ((ulong *) buf)[4 * i + 3] = r.dx;
165 Bprint(out, "procname %s\n", p);
174 Bprint(out, "physbits %uld\n", CUT(r.ax, 0, 7));
175 Bprint(out, "virtbits %uld\n", CUT(r.ax, 8, 15));
176 if(CUT(r.ax, 16, 23) != 0)
177 Bprint(out, "guestbits %uld\n", CUT(r.ax, 16, 23));
180 void (*funcs[])(ulong) = {
186 void (*extfuncs[])(ulong) = {
200 Bprint(out, "%.8ulx %.8ulx %.8ulx %.8ulx %.8ulx\n", ax, r.ax, r.bx, r.cx, r.dx);
203 char Egreg[] = "this information is classified";
206 notehand(void *, char *s)
208 if(strncmp(s, "sys:", 4) == 0)
214 main(int argc, char **argv)
223 case 'r': rflag++; break;
224 case 'a': aflag++; break;
227 /* first long in a.out header */
228 w = *(ulong *)(((uintptr)main)&~0xfff);
233 case 0x978a0000: /* amd64 */
234 /* patch out POP BP -> POP AX */
236 case 0xeb010000: /* 386 */
239 Binit(&buf, 1, OWRITE);
242 for(i = 0; i <= r.ax; i++)
243 if(i >= nelem(funcs) || funcs[i] == nil || rflag){
248 r = cpuid(0x80000000, 0);
250 for(i = 0; i <= r.ax; i++)
251 if(i >= nelem(extfuncs) || extfuncs[i] == nil || rflag){
253 stdfunc(0x80000000 | i);
255 extfuncs[i](0x80000000 | i);