Assume cpuid is available on x86_64, needs testing on i386 and unavailable on anything else

This commit is contained in:
Anonymous Maarten 2024-06-25 15:09:55 +02:00
parent da4e11fc8b
commit 30b918b30e

View File

@ -1054,6 +1054,7 @@ int MxDeviceEnumerate::SupportsCPUID()
{ {
int has_cpuid; int has_cpuid;
#ifdef _MSC_VER #ifdef _MSC_VER
#if defined(_M_IX86)
__asm { __asm {
xor eax, eax ; Zero EAX register xor eax, eax ; Zero EAX register
pushfd ; Push EFLAGS register value on the stack pushfd ; Push EFLAGS register value on the stack
@ -1065,7 +1066,13 @@ int MxDeviceEnumerate::SupportsCPUID()
popfd ; Push EFLAGS register value on the stack (again, and makes sure the stack remains the same) popfd ; Push EFLAGS register value on the stack (again, and makes sure the stack remains the same)
mov has_cpuid, eax ; Save eax into C variable mov has_cpuid, eax ; Save eax into C variable
} }
#elif defined(_M_X64)
has_cpuid = 1;
#else #else
has_cpuid = 0;
#endif
#else
#if defined(__i386__)
__asm__("xorl %%eax, %%eax\n\t" // Zero EAX register __asm__("xorl %%eax, %%eax\n\t" // Zero EAX register
"pushfl\n\t" // Push EFLAGS register value on the stack "pushfl\n\t" // Push EFLAGS register value on the stack
"orl $0x200000, (%%esp)\n\t" // Set bit 0x200000: Able to use CPUID instruction (Pentium+) "orl $0x200000, (%%esp)\n\t" // Set bit 0x200000: Able to use CPUID instruction (Pentium+)
@ -1076,6 +1083,11 @@ int MxDeviceEnumerate::SupportsCPUID()
"popfl" // Push EFLAGS register value on the stack (again, and makes sure the stack remains the same) "popfl" // Push EFLAGS register value on the stack (again, and makes sure the stack remains the same)
: "=a"(has_cpuid) // has_cpuid == EAX : "=a"(has_cpuid) // has_cpuid == EAX
); );
#elif defined(__x86_64__) || defined(__amd64__)
has_cpuid = 1;
#else
has_cpuid = 0;
#endif
#endif #endif
return has_cpuid; return has_cpuid;
} }