I dug this code up from a project that I worked on a long time ago. Unfortunately,
it is woefully out of date, especially with any of the latest P4 processors.
Also unfortunately, I don't have a large suite of machines on which to test this,
however, I have verified a large number of these, but not all.
Also missing from the list are any AMD processors since my old companies didn't
explicitly support AMD. Oh, well. As always, this code is to be used at your own
expense, and I guess with this particular set of code, that means a little more.
Anyway, I hope someone finds this interesting, and if you have any questions,
feel free to ask.
-BossHogg
#include "windows.h"
bool QueryCPUID();
bool QueryMMX();
bool QueryHyperThreading();
void QueryVendorString(char* string);
bool QuerySerialNumber(char* string);
void GetCPUInfoString(char* string);
unsigned long QueryCacheSize();
unsigned long QueryCPUCount();
unsigned char QueryCPUModel();
unsigned char QueryCPUFamily();
unsigned char QueryCPUStepping();
unsigned char QueryCPUType();
bool Is8086()
{
int is8086=0;
__asm {
pushf
pop ax
mov cx, ax
and ax, 0fffh
push ax
popf
pushf
pop ax
and ax, 0f000h
cmp ax, 0f000h
mov is8086, 0
jne DONE_8086_CHECK
mov is8086, 1
DONE_8086_CHECK:
};
return !!is8086;
}
bool Is80286()
{
int is80286=0;
__asm {
smsw ax
and ax, 1
or cx, 0f000h
push cx
popf
pushf
pop ax
and ax, 0f000h
mov is80286, 1
jz DONE_80286_CHECK
mov is80286, 0
DONE_80286_CHECK:
};
return !!is80286;
}
bool Is80386()
{
int is80386=0;
__asm {
pushfd
pop eax
mov ecx, eax
xor eax, 40000h
push eax
popfd
pushfd
pop eax
xor eax, ecx
mov is80386, 1
jz DONE_80386_CHECK
mov is80386, 0
DONE_80386_CHECK:
};
return !!is80386;
}
bool QueryCPUID()
{
int hasCPUID=0;
__asm
{
pushfd
pop eax
mov ecx, eax
and ecx, 0x00200000
xor eax, 0x00200000
push eax
popfd
pushfd
pop eax
and eax, 0x00200000
xor eax, ecx
mov hasCPUID, eax
};
return !!hasCPUID;
}
bool QueryMMX()
{
bool canDoMMX=false;
__asm
{
mov eax, 1 ; request for feature flags
_emit 0x0F ; CPUID on Pentiums is 0f,a2
_emit 0xA2
test edx, 0x00800000 ; is MMX technology Bit(bit 23)in feature
jz DONE_MMX_CHECK ; flags equal to 1
mov canDoMMX,1
DONE_MMX_CHECK:
};
return canDoMMX;
}
bool QueryHyperThreading()
{
unsigned int regEdx = 0;
unsigned int regEax = 0;
unsigned int vendorId[3] = {0, 0, 0};
if (!QueryCPUID())
return false;
__asm
{
xor eax, eax // call cpuid with eax = 0
cpuid // Get vendor id string
mov vendorId, ebx
mov vendorId + 4, edx
mov vendorId + 8, ecx
mov eax, 1 // call cpuid with eax = 1
cpuid
mov regEax, eax // eax contains family processor type
mov regEdx, edx // edx has info about the availability of hyper-Threading
}
if (((regEax & 0x0F00) == 0x0F00) || (regEax & 0x0F00000))
{
if (vendorId[0] == 'uneG' && vendorId[1] == 'Ieni' && vendorId[2] == 'letn')
{
return !!(regEdx & 0x10000000);
}
}
return false;
}
void QueryVendorString(char* string)
{
char vendorId[12];
__asm{
|
|