make cpuid work on x86_64

not that it's used for anything, just for the logs
This commit is contained in:
notaz 2016-04-25 00:00:55 +03:00
parent ff57a29e0f
commit ce46bd1e99
2 changed files with 33 additions and 26 deletions

View File

@ -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

View File

@ -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