CPUID: Difference between revisions
[unchecked revision] | [unchecked revision] |
Ported CPUID page, reorganized it |
updated to use code templates |
||
Line 9:
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:
<pre>
/* Vendor-strings. */
#define CPUID_VENDOR_INTEL "GenuineIntel"▼
#define CPUID_VENDOR_VIA "CentaurHauls"
#define CPUID_VENDOR_CENTAUR "CentaurHauls"
#define CPUID_VENDOR_UMC "UMC UMC UMC " /* FIXME - Is the space right? */▼
▲
#define CPUID_VENDOR_RISE "RiseRiseRise"▼
#define CPUID_VENDOR_NSC "Geode by NSC"
</pre>
}}
Also, EAX is set to the maximum EAX value supported for CPUID calls, as not all queries are supported on all processors
Line 29 ⟶ 33:
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.
{{code|CPUID flags|
/* Flags. */▼
<pre>
#define CPUID_FLAG_DE
#define CPUID_FLAG_PAE
#define CPUID_FLAG_MCE
#define CPUID_FLAG_CMOV
#define CPUID_FLAG_PSN
#define CPUID_FLAG_SS
#define CPUID_FLAG_IA64 0x40000000 /* IA-64 (64-bit Intel CPU) */
#define CPUID_FLAG_PBE 0x80000000 /* Pending Break Event. */
</pre>
}}
== Using CPUID from GCC ==
Line 66 ⟶ 74:
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
{{code|CPUID in GCC|
enum cpuid_requests {▼
<pre>
CPUID_GETVENDORSTRING,▼
CPUID_GETFEATURES,▼
CPUID_GETTLB,▼
CPUID_GETSERIAL,▼
};
/** issue a single request to CPUID. Fits 'intel features', for instance
▲ CPUID_INTELEXTENDED=0x80000000,
▲ CPUID_INTELFEATURES,
▲ CPUID_INTELBRANDSTRING,
*/
▲ CPUID_INTELBRANDSTRINGMORE,
▲ CPUID_INTELBRANDSTRINGEND,
}
*/
▲ * note that even if only "eax" and "edx" are of interrest, other registers
▲ * will be modified by the operation, so we need to tell the compiler about it.
int
▲ static inline void cpuid(int code, dword *a, dword *d) {
}
</pre>
}}
▲ static inline int cpuid_string(int code, dword where[4]) {
▲ asm volatile("cpuid":"=a"(*where),"=b"(*(where+1)),
▲ "=c"(*(where+2)),"=d"(*(where+3)):"0"(code));
▲ return highest;
== Links ==
|
Revision as of 06:17, 1 December 2006
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:
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.
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
Links
- You can check out SandPile.org for an exhaustive list of functions available through CPUID instruction.
- CPUID For OS Developers, an implementation written by Brynet-Inc.
- Forum topic about issues with CPUID