Some programs rely on specific CPU instructions, with features like MMX, 3DNow!, Hyper Threading, etc. Some of them even rely on the specific CPU version. How would they know for sure that the CPU has what it takes to operate? The documentation for the Win32 API on this matter is scarce, if any. For example, GetSystemInfo returns no more than the CPU vendor, and of course we want to know more.
When Intel released CPU’s with MMX instruction sets, they had to add a special instruction for programmers to know whether this is an MMX machine or not - CPUID. Today, CPUID has become a standard instruction. You can use it on any Intel CPU starting from Intel 486, on any AMD CPUs, and even on some of Cyrix’s CPUs.
The CPUID instruction
This is far from being a complete guide to the CPUID instruction. However, a few pointers will be given as an introduction.
CPUID handles EAX as a parameter for the required information type, and returns the data in the EAX, EBX, ECX, EDX registers. Always call CPUID with EAX first set to 0, and get the highest EAX parameter you can pass to CPUID in EAX, and the vendor string (Yes, string) in EBX, ECX, EDX with total of 12 characters. According to the highest EAX, you will know whether to proceed to the next CPUID call with a different EAX value. For example, calling CPUID with EAX = 0 on an AMD machine would get the string “AuthenticAMD” on EBX, ECX and EDX (4 chars each). If you wanted to call CPUID with EAX = 1, you would make sure you got EAX >= 1 on the first call. As mentioned, beware that not all CPUs support this instruction. As any other unsupported CPU instruction, this will raise a structured exception which can easily be caught, as shown in the following MS specific code:
__try
{
__asm
{
xor eax, eax
cpuid
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
// The cpu does not support CPUID instruction
NotifyTheUserThatHisCpuIsProbablyNotWhatHePayedFor();
}
A complete reference for the Intel’s retrievable features list can be found in Intel’s CPU reference for Pentium II at ftp://download.intel.com/design/PentiumII/manuals/24319102.PDF starting at page 3-116.
A good guide for using the CPUID instruction can be found at
http://www.paradicesoftware.com/specs/cpuid/
Thoroughly detecting Hyper Threading on intel CPUs:
http://www.intel.com/cd/ids/developer/asmo-na/eng/199701.htm?page=3
In 1999, Intel added a serial number feature which can be retrieved by CPUID on Pentium III CPUs. The existence of a retrievable unique serial number for every intel computer world wide has raised the public interest as an invasion of privacy. You can read about it in here:
http://www.cdt.org/privacy/issues/pentium3/990226intelcomplaint.shtml
http://www.cdt.org/privacy/issues/pentium3/990226intelcomplaintsupp.shtml
and about the resolution in here:
http://www.cyber-rights.org/reports/intel-rep.htm
RSS feed for comments on this post. TrackBack URI
Powered by WordPress