#include #include #include #define CUT(x, a, b) (((x)&((1<<((b)+1))-1))>>(a)) typedef struct Res { ulong ax, bx, cx, dx; } Res; Biobuf *out; uchar _cpuid[] = { 0x5E, /* POP SI (PC) */ 0x5D, /* POP BP (Res&) */ 0x58, /* POP AX */ 0x59, /* POP CX */ 0x51, /* PUSH CX */ 0x50, /* PUSH AX */ 0x55, /* PUSH BP */ 0x56, /* PUSH SI */ 0x31, 0xDB, /* XOR BX, BX */ 0x31, 0xD2, /* XOR DX, DX */ 0x0F, 0xA2, /* CPUID */ 0x89, 0x45, 0x00, /* MOV AX, 0(BP) */ 0x89, 0x5d, 0x04, /* MOV BX, 4(BP) */ 0x89, 0x4d, 0x08, /* MOV CX, 8(BP) */ 0x89, 0x55, 0x0C, /* MOV DX, 12(BP) */ 0xC3, /* RET */ }; Res (*cpuid)(ulong ax, ulong cx) = (Res(*)(ulong, ulong)) _cpuid; void func0(ulong) { Res r; char buf[13]; r = cpuid(0, 0); ((ulong *) buf)[0] = r.bx; ((ulong *) buf)[1] = r.dx; ((ulong *) buf)[2] = r.cx; buf[13] = 0; Bprint(out, "vendor %s\n", buf); } void printbits(char *id, ulong x, char **s) { int i, j; for(i = 0, j = 0; i < 32; i++) if((x & (1< POP AX */ _cpuid[1] = 0x58; case 0xeb010000: /* 386 */ break; } Binit(&buf, 1, OWRITE); out = &buf; r = cpuid(0, 0); for(i = 0; i <= r.ax; i++) if(i >= nelem(funcs) || funcs[i] == nil || rflag){ if(rflag || aflag) stdfunc(i); }else funcs[i](i); r = cpuid(0x80000000, 0); r.ax -= 0x80000000; for(i = 0; i <= r.ax; i++) if(i >= nelem(extfuncs) || extfuncs[i] == nil || rflag){ if(rflag || aflag) stdfunc(0x80000000 | i); }else extfuncs[i](0x80000000 | i); Bterm(out); }