опубликован 24-12-2000 23:17 MSK
Вот пример из моей сисинфовой библиотечки:
-------------------------------------------
struct TCPUID {
int cpu_type;
int cpu_family;
int cpu_model;
int cpu_stepping;
int cpu_csize; char Vendor[13];
bool IntelOEM;
bool isFPU;
bool isMMX;
bool isSSE;
bool isSerial;
bool isL2;
};
int isCPUID(void)
{
int is_old486 = 0;
__asm {
pushfd
pop ecx
mov eax,ecx
xor eax,0x200000
push eax
popfd
pushfd
pop eax
xor eax,ecx
jne nocpuid
mov eax,1
mov [is_old486],eax
nocpuid:
}
return !is_old486;
}
void getCPUID(TCPUID *cdat)
{
int cpuid1;
char vendor_id[12];
static char intel_id[] = "GenuineIntel";
unsigned int cpu_sign = 0,
features_ebx,
features_edx,
features_ecx,
cache_eax,
cache_ebx,
cache_ecx,
cache_edx = 0;
__asm {
push ebx
push esi
push edi
// get vendor ID
xor eax,eax
cpuid
mov dword ptr vendor_id, ebx
mov dword ptr [vendor_id+4], edx
mov dword ptr [vendor_id+8], ecx
cmp eax,1
jl no_features
// get cpu features
mov eax,1
cpuid
mov cpu_sign, eax
mov features_ebx, ebx
mov features_edx, edx
mov features_ecx, ecx
// check cache desc
mov eax, 0
cpuid
// get cache info
cmp ax,2
jl no_features
mov eax,2
cpuid
mov cache_eax, eax
mov cache_ebx, ebx
mov cache_ecx, ecx
mov cache_edx, edx
no_features:
pop edi
pop esi
pop ebx
}
cdat->IntelOEM = true;
memcpy(cdat->Vendor,vendor_id,12);
for(int i=0;i < 12;i++)
if (vendor_id[i] != intel_id[i]) {
cdat->IntelOEM = false;
break;
}
// 0 - original OEM
// 1 - OverDrive processor
// 2 - Dual processor
// 3 - Intel reserved
cdat->cpu_type = (cpu_sign >> 12) & 3;
cdat->cpu_family = (cpu_sign >> 8) & 15;
cdat->cpu_model = (cpu_sign >> 4) & 15;
cdat->cpu_stepping = (cpu_sign) & 15;
cdat->isMMX = features_edx && (1<<23);
cdat->isSSE = features_edx && (1<<25);
cdat->isFPU = features_edx && 1;
cdat->isSerial = features_edx && (1<<18);
cdat->isL2 = true;
switch (cache_edx & 0xff) {
case 0x40 : cdat->cpu_csize = 0;
break;
case 0x41 : cdat->cpu_csize = 128;
break;
case 0x42 : cdat->cpu_csize = 256;
break;
case 0x43 : cdat->cpu_csize = 512;
break;
case 0x44 : cdat->cpu_csize = 1024;
break;
case 0x45 : cdat->cpu_csize = 2048;
break;
default:
cdat->cpu_csize = 0;
cdat->isL2 = false;
}
}
int sysGetCPUid(void)
{
TCPUID cpudat;
int result=0; //unknown type
int cpu_m; // Model
int cpu_f; // Family
int cpu_t; // Type
if (isCPUID()) {
getCPUID(&cpudat);
cpu_f = cpudat.cpu_family;
cpu_m = cpudat.cpu_model;
cpu_t = cpudat.cpu_type;
} else {
return 0;
}
if (cpu_f==4) // 80486
{
result=4000000+(cpu_m*1000)+cpu_t; // Unknown 486;
if (cpu_m==4) result=41; // SL
if (cpu_m==2) result=42; // SX
if (cpu_m==5) result=43; // SX2
if (cpu_m<2) result=44; // DX
if (cpu_m==3