CPUID: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
→Checking CPUID availability: increase comment quality |
m Reverted edits by Kb (talk) to last revision by Silverfox1955 |
||
Line 10: | Line 10: | ||
<source lang="asm"> |
<source lang="asm"> |
||
pushfd ;Save EFLAGS |
|||
⚫ | |||
xor dword [esp],0x00200000 ;Invert the ID bit in stored EFLAGS |
|||
popfd ;Load stored EFLAGS (with ID bit 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 |
|||
popfd ;Restore original EFLAGS |
|||
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 |
|||
⚫ | |||
</source> |
</source> |
||
Line 28: | Line 25: | ||
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 === |