#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[] = { 0x8B, 0x44, 0x24, 0x08, /* MOV 8(SP), AX */ 0x31, 0xDB, /* XOR BX, BX */ 0x8B, 0x4C, 0x24, 0x0C, /* MOV 12(SP), CX */ 0x31, 0xD2, /* XOR DX, DX */ 0x0F, 0xA2, /* CPUID */ 0x8B, 0x7C, 0x24, 0x04, /* MOV 4(SP), DI */ 0x89, 0x07, /* MOV AX, (DI) */ 0x89, 0x5F, 0x04, /* MOV BX, 4(DI) */ 0x89, 0x4F, 0x08, /* MOV CX, 8(DI) */ 0x89, 0x57, 0x0C, /* MOV DX, 12(DI) */ 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<= 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); }