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...
In your inline the "jl dont_bother" may not be supported. I always use something like
"jmp 0f\n\t"
.
.
.
"0:\n\t"
Also, your lines
"mov %%ebx, %0\n\t"
"mov %%ecx, %1\n\t"
"mov %%edx, %2\n\t"
each of these lines are moving 4 bytes into the character array but you only increment it by one byte as seen below
:"=r"(vendor[0]), "=r"(vendor[1]), "=r"(vendor[2]) shouldn't this be
:"=r"(vendor[0]), "=r"(vendor[4]), "=r"(vendor[8])
Actually I think you have your variables mixed up, the line above should be
:"=r"(vstring[0]), "=r"(vstring[4]), "=r"(vstring[8]) gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387