From Chirag Shah...
Here are different ways to do the
cpuid
Let the assembler/compiler do the register/memory copy for us
asm("cpuid"
: "=b" (first),
"=c" (third),
"=d" (second)
: "a" (input));
This generates code with this pointless copy via
eax
cpuid
movl %eax, -20(%ebp)
movl %ebx, %eax
movl %eax, -8(%ebp)
movl %ecx, %eax
movl %eax, -16(%ebp)
movl %edx, %eax
movl %eax, -12(%ebp)
Explictly show I want to do MOV operations, and use the =m constraint operator to tell it to copy to memory
asm("mov $0,%%eax;
cpuid;
mov %%ebx,%0;
mov %%edx,%1;
mov %%ecx,%2;"
:"=m"(first), "=m"(second), "=m"(third)
:
:"%eax");
This generates:
mov $0,%eax;
cpuid;
mov %ebx,-8(%ebp);
mov %edx,-12(%ebp);
mov %ecx,-16(%ebp);
int main(void)
{
unsigned int first,second,third;
unsigned int feature;
unsigned int input = 0;
asm("cpuid"
: "=b" (first),
"=c" (third),
"=d" (second)
: "a" (input));
//make sure it's a real Intel processor
if (first == 'uneG')
if (second == 'Ieni')
if (third == 'letn'){
//it's a real Intel, so let's check the feature bit
asm("mov $1,%%eax;
cpuid;
mov %%ecx,%0;"
:"=r"(feature)
:
:"%eax");
if(feature & EST_BIT){
printf("This/these processors support EST.\n");
printf("Returning 1\n");
return 1;
}
}
printf("This/these processors do not support EST.\n");
printf("Returning 0\n");
return 0;
}
--
MattWalsh - 06 Oct 2005