Hi :)
I'm trying to get the vendor ID using the CPUID opcode. Again, this is inline ASM with C; but it's the ASM that I need help with. The C is fine AFAIK.
I'm not sure if it's the way I'm trying to do this, or if my CPU simply doesn't support CPUID...
char* getCPUID(void) {
int vendor[3];
char vstring[12 + 1];
/* Get vendor string: */
asm("mov %0, %%eax\n\t"
"cpuid\n\t"
"cmp $3, %%eax\n\t" /* If eax < 3, CPU doesn't support CPUID... */
"jl dont_bother\n\t" /* So we can't CPUID :( */
"mov %%ebx, %0\n\t"
"mov %%ecx, %1\n\t"
"mov %%edx, %2\n\t"
"dont_bother:\n\t"
"mov $-1, %0"
:"=r"(vendor[0]), "=r"(vendor[1]), "=r"(vendor[2])
);
if (vendor[0] == -1) {
return "Error: CPU doesn't support CPUID!";
}
/* Store in vstring; 12 char string results */
memcpy(&(vstring[0]), &(vendor[0]), sizeof(int));
memcpy(&(vstring[4]), &(vendor[1]), sizeof(int));
memcpy(&(vstring[8]), &(vendor[2]), sizeof(int));
/* Make sure string is NULL-terminated */
vstring[12] = '\0';
return getManufacturer(vstring); /* Function simply compares vstring to some
known vendor strings. */
}
... but my error message is printed. Is it my ASM, or the CPU?
I'm hoping it's the ASM...
$ ./a.out
Manufacturer: Error: CPU doesn't support CPUID!