From ce46bd1e998231b323b2e95e3b530c204dca6976 Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 25 Apr 2016 00:00:55 +0300 Subject: [PATCH] make cpuid work on x86_64 not that it's used for anything, just for the logs --- Sources/Engine/Base/Types.h | 8 +++++- Sources/Engine/Engine.cpp | 51 +++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/Sources/Engine/Base/Types.h b/Sources/Engine/Base/Types.h index fe1672a..555bc81 100644 --- a/Sources/Engine/Base/Types.h +++ b/Sources/Engine/Base/Types.h @@ -119,9 +119,15 @@ MY_STATIC_ASSERT(size_tSize, sizeof(size_t) == sizeof(void*)); #define __MSVC_INLINE__ #elif defined (__GNUC__) && defined(__i386) #define __GNU_INLINE_X86_32__ + #elif defined (__GNUC__) && defined(__x86_64__) + #define __GNU_INLINE_X86_64__ #endif - #if defined(__GNU_INLINE_X86_32__) + #if defined(__GNU_INLINE_X86_32__) || defined(__GNU_INLINE_X86_64__) + #define __GNU_INLINE_X86__ + #endif + + #if defined(__GNU_INLINE_X86__) #define FPU_REGS "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)" #define MMX_REGS "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7" #endif diff --git a/Sources/Engine/Engine.cpp b/Sources/Engine/Engine.cpp index 4ca653e..452d281 100644 --- a/Sources/Engine/Engine.cpp +++ b/Sources/Engine/Engine.cpp @@ -144,38 +144,39 @@ static void DetectCPU(void) mov dword ptr [ulFeatures], edx } - #elif (defined __GNU_INLINE_X86_32__) + #elif (defined __GNU_INLINE_X86__) + ULONG eax, ebx, ecx, edx; // test MMX presence and update flag __asm__ __volatile__ ( - "pushl %%ebx \n\t" - "xorl %%eax,%%eax \n\t" // request for basic id + #if (defined __GNU_INLINE_X86_64__) "cpuid \n\t" - "movl %%ebx, (%%esi) \n\t" - "movl %%edx, 4(%%esi) \n\t" - "movl %%ecx, 8(%%esi) \n\t" - "popl %%ebx \n\t" - : // no specific outputs. - : "S" (strVendor) - : "eax", "ecx", "edx", "memory" + : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) + #else + "movl %%ebx, %%esi \n\t" + "cpuid \n\t" + "xchgl %%ebx, %%esi \n\t" + : "=a" (eax), "=S" (ebx), "=c" (ecx), "=d" (edx) + #endif + : "a" (0) // request for basic id ); - - // need to break this into a separate asm block, since I'm clobbering - // too many registers. There's something to be said for letting MSVC - // figure out where on the stack your locals are resting, but yeah, - // I know, that's x86-specific anyhow... - // !!! FIXME: can probably do this right with modern GCC. + memcpy(strVendor + 0, &ebx, 4); + memcpy(strVendor + 4, &edx, 4); + memcpy(strVendor + 8, &ecx, 4); __asm__ __volatile__ ( - "pushl %%ebx \n\t" - "movl $1, %%eax \n\t" // request for TFMS feature flags - "cpuid \n\t" - "mov %%eax, (%%esi) \n\t" // remember type, family, model and stepping - "mov %%edx, (%%edi) \n\t" - "popl %%ebx \n\t" - : // no specific outputs. - : "S" (&ulTFMS), "D" (&ulFeatures) - : "eax", "ecx", "edx", "memory" + #if (defined __GNU_INLINE_X86_64__) + "cpuid \n\t" + : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) + #else + "movl %%ebx, %%esi \n\t" + "cpuid \n\t" + "xchgl %%ebx, %%esi \n\t" + : "=a" (eax), "=S" (ebx), "=c" (ecx), "=d" (edx) + #endif + : "a" (1) // request for TFMS feature flags ); + ulTFMS = eax; + ulFeatures = edx; #endif