CPUID: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
m Reverted edits by Markhobley (Talk); changed back to last version by Steve23 |
→How to use CPUID: simplify asm, and use ecx rather than ebx because cdecl requires us to preserve ebx |
||
Line 4: | Line 4: | ||
Note that prior to use the CPUID instruction, you should also make sure the processor supports it by testing the 'ID' bit (0x200000) in eflags (modifiable only when the CPUID instruction is supported. For systems that don't support CPUID, writing a '1' at that place will have no effect). |
Note that prior to use the CPUID instruction, you should also make sure the processor supports it by testing the 'ID' bit (0x200000) in eflags (modifiable only when the CPUID instruction is supported. For systems that don't support CPUID, writing a '1' at that place will have no effect). |
||
Here is an assembly routine that checks if CPUID is supported: |
|||
<source lang="asm"> |
<source lang="asm"> |
||
; returns |
; returns 1 if CPUID is supported, 0 otherwise (ZF is also set accordingly) |
||
pushfd |
pushfd ; get |
||
pop eax |
pop eax |
||
mov |
mov ecx, eax ; save |
||
xor eax, 0x200000 |
xor eax, 0x200000 ; flip |
||
⚫ | |||
and ebx, 0x200000 |
|||
⚫ | |||
popfd |
popfd |
||
pushfd |
pushfd ; and test |
||
pop eax |
pop eax |
||
xor eax, ecx ; mask changed bits |
|||
and eax, 0x200000 |
|||
shr eax, 21 ; move bit 21 to bit 0 |
|||
xor eax, ebx |
|||
and eax, 1 ; and mask others |
|||
ret |
ret |
||
</source> |
</source> |