Route Borland/Embarcadero into MS inline ASM code for CPUID

The inline ASM code now uses local variables to save the EAX-EDX registers, and then copies the locals into the function parameters. It side steps problems with calling conventions
pull/507/head
Jeffrey Walton 2017-09-16 18:03:24 -04:00
parent 7464cbba51
commit da0dc66952
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 13 additions and 6 deletions

19
cpu.cpp
View File

@ -123,24 +123,31 @@ extern "C"
} }
#endif #endif
// Embarcadero and Issue 498 // Borland/Embarcadero and Issue 498
// cpu.cpp (131): E2211 Inline assembly not allowed in inline and template functions // cpu.cpp (131): E2211 Inline assembly not allowed in inline and template functions
bool CpuId(word32 func, word32 subfunc, word32 output[4]) bool CpuId(word32 func, word32 subfunc, word32 output[4])
{ {
#if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY) #if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY) || defined(__BORLANDC__)
__try __try
{ {
// Borland/Embarcadero and Issue 500
// Local variables for cpuid output
word32 a, b, c, d;
__asm __asm
{ {
mov eax, func mov eax, func
mov ecx, subfunc mov ecx, subfunc
cpuid cpuid
mov edi, output mov edi, output
mov [edi], eax mov [a], eax
mov [edi+4], ebx mov [b], ebx
mov [edi+8], ecx mov [c], ecx
mov [edi+12], edx mov [d], edx
} }
output[0] = a;
output[1] = b;
output[2] = c;
output[3] = d;
} }
// GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION // GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION
__except (EXCEPTION_EXECUTE_HANDLER) __except (EXCEPTION_EXECUTE_HANDLER)