I've added a routine to the article that checks that the CPUID instruction is supported.
I am fairly confident that it is correct, but if someone could take a look and double check, I'd
appreciate it.
Wiki: CPUID
Re: Wiki: CPUID
I believe this is the code in question:Hangin10 wrote:I've added a routine to the article that checks that the CPUID instruction is supported.
I am fairly confident that it is correct, but if someone could take a look and double check, I'd
appreciate it.
Code: Select all
; returns 1 if CPUID is supported, 0 otherwise (ZF is also set accordingly)
pushfd ; get
pop eax
mov ecx, eax ; save
xor eax, 0x200000 ; flip
push eax ; set
popfd
pushfd ; and test
pop eax
xor eax, ecx ; mask changed bits
shr eax, 21 ; move bit 21 to bit 0
and eax, 1 ; and mask others
push ecx
popfd ; restore original flags
ret
I don't see much reference to it in the forums or general googling, so I'm guessing that people just assume their CPU is CPUID capable.
Thank you.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Wiki: CPUID
This code follows the i386 system V ABI. That means you just give it a name and declare it as (extern "C") int isCPUIDsupported(); like you would for any function call in a different object file.How is this called from C?
More likely, they're not using it in the first place.people just assume their CPU is CPUID capable.
Considering the last two instructions are POPFD; RET; I call all flags preserved instead.ZF is also set accordingly
Re: Wiki: CPUID
But isn't the POPFD restoring the flags as pushed earlier in the routine (by PUSH ECX), not as originally set?Combuster wrote:Considering the last two instructions are POPFD; RET; I call all flags preserved instead.ZF is also set accordingly
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Wiki: CPUID
Find the only assignment to ECX
Meanwhile, Brendan demonstrated a much shorter version.
Meanwhile, Brendan demonstrated a much shorter version.