Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed CPU feature detection on x86_64 platform
Browse files Browse the repository at this point in the history
(registers were being corrupted, causing crashes)
  • Loading branch information
slouken committed Dec 24, 2008
1 parent 7fbc3f8 commit f8225c8
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/cpuinfo/SDL_cpuinfo.c
Expand Up @@ -152,7 +152,7 @@ CPU_getCPUIDFeatures(void)
{
int features = 0;
/* *INDENT-OFF* */
#if defined(__GNUC__) && ( defined(i386) || defined(__x86_64__) )
#if defined(__GNUC__) && defined(i386)
__asm__ (
" movl %%ebx,%%edi\n"
" xorl %%eax,%%eax # Set up for CPUID instruction \n"
Expand All @@ -169,6 +169,23 @@ CPU_getCPUIDFeatures(void)
:
: "%eax", "%ecx", "%edx", "%edi"
);
#elif defined(__GNUC__) && defined(__x86_64__)
__asm__ (
" movq %%rbx,%%rdi\n"
" xorl %%eax,%%eax # Set up for CPUID instruction \n"
" cpuid # Get and save vendor ID \n"
" cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
" jl 1f # We dont have the CPUID instruction\n"
" xorl %%eax,%%eax \n"
" incl %%eax \n"
" cpuid # Get family/model/stepping/features\n"
" movl %%edx,%0 \n"
"1: \n"
" movq %%rdi,%%rbx\n"
: "=m" (features)
:
: "%rax", "%rcx", "%rdx", "%rdi"
);
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
__asm {
xor eax, eax ; Set up for CPUID instruction
Expand Down Expand Up @@ -208,7 +225,7 @@ CPU_getCPUIDFeaturesExt(void)
{
int features = 0;
/* *INDENT-OFF* */
#if defined(__GNUC__) && (defined(i386) || defined (__x86_64__) )
#if defined(__GNUC__) && defined(i386)
__asm__ (
" movl %%ebx,%%edi\n"
" movl $0x80000000,%%eax # Query for extended functions \n"
Expand All @@ -224,6 +241,22 @@ CPU_getCPUIDFeaturesExt(void)
:
: "%eax", "%ecx", "%edx", "%edi"
);
#elif defined(__GNUC__) && defined (__x86_64__)
__asm__ (
" movq %%rbx,%%rdi\n"
" movl $0x80000000,%%eax # Query for extended functions \n"
" cpuid # Get extended function limit \n"
" cmpl $0x80000001,%%eax \n"
" jl 1f # Nope, we dont have function 800000001h\n"
" movl $0x80000001,%%eax # Setup extended function 800000001h\n"
" cpuid # and get the information \n"
" movl %%edx,%0 \n"
"1: \n"
" movq %%rdi,%%rbx\n"
: "=m" (features)
:
: "%rax", "%rcx", "%rdx", "%rdi"
);
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
__asm {
mov eax,80000000h ; Query for extended functions
Expand Down

0 comments on commit f8225c8

Please sign in to comment.