CPUID: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
No edit summary |
m Bot: Replace deprecated source tag with syntaxhighlight |
||
Line 9: | Line 9: | ||
This assembly routine checks if CPUID is supported: |
This assembly routine checks if CPUID is supported: |
||
< |
<syntaxhighlight lang="asm"> |
||
pushfd ;Save EFLAGS |
pushfd ;Save EFLAGS |
||
pushfd ;Store EFLAGS |
pushfd ;Store EFLAGS |
||
Line 20: | Line 20: | ||
and eax,0x00200000 ;eax = zero if ID bit can't be changed, else non-zero |
and eax,0x00200000 ;eax = zero if ID bit can't be changed, else non-zero |
||
ret |
ret |
||
</syntaxhighlight> |
|||
</source> |
|||
Note 1: There are some old CPUs where CPUID is supported but the ID bit in EFLAGS is not (NexGen). There are also CPUs that support CPUID if and only if it has to be enabled first (Cyrix M1). |
Note 1: There are some old CPUs where CPUID is supported but the ID bit in EFLAGS is not (NexGen). There are also CPUs that support CPUID if and only if it has to be enabled first (Cyrix M1). |
||
Line 29: | Line 29: | ||
The idea of the CPUID instruction is that you can call it with different values in EAX, and it will return different information about the processor. For example, if we want the Vendor ID String (see below), we should code something like that: |
The idea of the CPUID instruction is that you can call it with different values in EAX, and it will return different information about the processor. For example, if we want the Vendor ID String (see below), we should code something like that: |
||
< |
<syntaxhighlight lang="asm"> |
||
mov eax, 0x0 |
mov eax, 0x0 |
||
cpuid |
cpuid |
||
</syntaxhighlight> |
|||
</source> |
|||
There are differences between AMD and Intel. According to the Intel CPUID application note, we should first check the Vendor ID String for "GenuineIntel" before taking out information, such as the Processor Signature, Processor Feature Flags, etc. |
There are differences between AMD and Intel. According to the Intel CPUID application note, we should first check the Vendor ID String for "GenuineIntel" before taking out information, such as the Processor Signature, Processor Feature Flags, etc. |
||
Line 40: | Line 40: | ||
When called with EAX = 0, CPUID returns the vendor ID string in EBX, EDX and ECX. Writing these to memory in this order results in a 12-character string. These can be tested against known Vendor ID strings: |
When called with EAX = 0, CPUID returns the vendor ID string in EBX, EDX and ECX. Writing these to memory in this order results in a 12-character string. These can be tested against known Vendor ID strings: |
||
< |
<syntaxhighlight lang="c"> |
||
// Vendor strings from CPUs. |
// Vendor strings from CPUs. |
||
#define CPUID_VENDOR_AMD "AuthenticAMD" |
#define CPUID_VENDOR_AMD "AuthenticAMD" |
||
Line 73: | Line 73: | ||
#define CPUID_VENDOR_BHYVE "bhyve bhyve " |
#define CPUID_VENDOR_BHYVE "bhyve bhyve " |
||
#define CPUID_VENDOR_QNX " QNXQVMBSQG " |
#define CPUID_VENDOR_QNX " QNXQVMBSQG " |
||
</syntaxhighlight> |
|||
</source> |
|||
You already know that the Vendor ID String is returned in EBX, ECX, EDX. Let us take an Intel processor. It should return "GenuineIntel". Look at the following text to see how the string is placed in the registers: |
You already know that the Vendor ID String is returned in EBX, ECX, EDX. Let us take an Intel processor. It should return "GenuineIntel". Look at the following text to see how the string is placed in the registers: |