CPUID

From OSDev.wiki
Revision as of 09:42, 13 December 2006 by osdev>Jhawthorn
Jump to navigation Jump to search
CPUID
CPU Identification
 
Usage:{{{Usage}}}
Usage:{{{Usage2}}}
Modifies Flags:None
Availability:Pentium


The CPUID instruction can be used to retrieve various amount of information about your cpu, like its vendor string and model number, the size of internal caches and (more interesting), the list of CPU features supported.

How to use CPUID

Note that prior to use the CPUID instruction, you should also make sure the processor support it by testing the 'ID' bit in eflags (this is 0x200000 and is modifiable only when CPUID instruction is supported. For systems that doesn't support CPUID, writing a '1' at that place will have no effect)

CPU Brand

When called with EAX = 0, CPUID returns the brand name in EBX, EDX and ECX. Writing these to memory in this order results in a 12-character string. These can be tested against known brands:

Template:Code

Also, EAX is set to the maximum EAX value supported for CPUID calls, as not all queries are supported on all processors

CPU Features

When called with EAX = 1 (CPUID_GETFEATURES), CPUID returns a bit field in EDX containing the following values. Note that different brands of CPUs may have given different meanings to these. Recent processors also use ECX for features (which form a different set), with which you should be very careful as some old CPUs return bogus information in this register.

Template:Code

Using CPUID from GCC

CPUID can be invoked with various request codes (in eax) and will return values in general registers (much as a built-in service interrupt). The following code is made Public Domain out of Clicker's x86/cpu.h

Template:Code

Links