CPUID: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
→Checking CPUID availability: increase comment quality |
|||
Line 10: | Line 10: | ||
<source lang="asm"> |
<source lang="asm"> |
||
pushfd ; preserve EFLAGS to restore at the end of routine |
|||
⚫ | |||
pushfd ; store EFLAGS (working copy) |
|||
xor dword [esp], 0x00200000 ; invert ID bit in our copy of EFLAGS |
|||
popfd ; attempt storing _altered_ EFLAGS |
|||
pop eax ;eax = modified EFLAGS (ID bit may or may not be inverted) |
|||
pushfd ; Store EFLAGS again (ID bit may or may not be inverted) |
|||
pop eax ; eax = modified EFLAGS (ID bit may or may not be inverted) |
|||
xor eax, [esp] ; eax = whichever bits were changed |
|||
⚫ | |||
⚫ | |||
and eax, 0x00200000 ; eax = zero if ID bit can't be changed, else non-zero |
|||
⚫ | |||
</source> |
</source> |
||
Line 25: | Line 28: | ||
Note 2: You can simply attempt to execute the CPUID instruction and see if you get an invalid opcode exception. This avoids problems with CPUs that do support CPUID but don't support the ID bit in EFLAGS; and is likely to be faster for CPUs that do support CPUID (and slower for CPUs that don't). |
Note 2: You can simply attempt to execute the CPUID instruction and see if you get an invalid opcode exception. This avoids problems with CPUs that do support CPUID but don't support the ID bit in EFLAGS; and is likely to be faster for CPUs that do support CPUID (and slower for CPUs that don't). |
||
=== Basic usage === |
=== Basic usage === |