mirror of
https://github.com/anrieff/libcpuid
synced 2024-11-10 22:59:13 +00:00
Allow compilation on non-x86 platforms.
This commit is contained in:
parent
72d49bdd6f
commit
400c55dbe3
2 changed files with 16 additions and 16 deletions
|
@ -29,10 +29,10 @@
|
||||||
|
|
||||||
int cpuid_exists_by_eflags(void)
|
int cpuid_exists_by_eflags(void)
|
||||||
{
|
{
|
||||||
#ifdef PLATFORM_X64
|
#if defined(PLATFORM_X64)
|
||||||
return 1; /* CPUID is always present on the x86_64 */
|
return 1; /* CPUID is always present on the x86_64 */
|
||||||
#else
|
#elif defined(PLATFORM_X86)
|
||||||
# ifdef COMPILER_GCC
|
# if defined(COMPILER_GCC)
|
||||||
int result;
|
int result;
|
||||||
__asm __volatile(
|
__asm __volatile(
|
||||||
" pushfl\n"
|
" pushfl\n"
|
||||||
|
@ -50,8 +50,7 @@ int cpuid_exists_by_eflags(void)
|
||||||
: "=m"(result)
|
: "=m"(result)
|
||||||
: :"eax", "ecx", "memory");
|
: :"eax", "ecx", "memory");
|
||||||
return (result != 0);
|
return (result != 0);
|
||||||
# else
|
# elif defined(COMPILER_MICROSOFT)
|
||||||
# ifdef COMPILER_MICROSOFT
|
|
||||||
int result;
|
int result;
|
||||||
__asm {
|
__asm {
|
||||||
pushfd
|
pushfd
|
||||||
|
@ -68,20 +67,21 @@ int cpuid_exists_by_eflags(void)
|
||||||
popfd
|
popfd
|
||||||
};
|
};
|
||||||
return (result != 0);
|
return (result != 0);
|
||||||
# else
|
# else
|
||||||
# error "Unsupported compiler"
|
return 0;
|
||||||
# endif /* COMPILER_MICROSOFT */
|
# endif /* COMPILER_MICROSOFT */
|
||||||
# endif /* COMPILER_GCC */
|
#else
|
||||||
#endif /* PLATFORM_X64 */
|
return 0;
|
||||||
|
#endif /* PLATFORM_X86 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* with MSVC/AMD64, the exec_cpuid() and cpu_rdtsc() functions
|
* with MSVC/AMD64, the exec_cpuid() and cpu_rdtsc() functions
|
||||||
* are implemented in separate .asm files. Otherwise, use inline assembly
|
* are implemented in separate .asm files. Otherwise, use inline assembly
|
||||||
*/
|
*/
|
||||||
#ifdef INLINE_ASM_SUPPORTED
|
|
||||||
void exec_cpuid(uint32_t *regs)
|
void exec_cpuid(uint32_t *regs)
|
||||||
{
|
{
|
||||||
|
#ifdef INLINE_ASM_SUPPORTED
|
||||||
#ifdef COMPILER_GCC
|
#ifdef COMPILER_GCC
|
||||||
# ifdef PLATFORM_X64
|
# ifdef PLATFORM_X64
|
||||||
__asm __volatile(
|
__asm __volatile(
|
||||||
|
@ -166,8 +166,8 @@ void exec_cpuid(uint32_t *regs)
|
||||||
# error "Unsupported compiler"
|
# error "Unsupported compiler"
|
||||||
# endif /* COMPILER_MICROSOFT */
|
# endif /* COMPILER_MICROSOFT */
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
#endif /* INLINE_ASSEMBLY_SUPPORTED */
|
#endif /* INLINE_ASSEMBLY_SUPPORTED */
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef INLINE_ASM_SUPPORTED
|
#ifdef INLINE_ASM_SUPPORTED
|
||||||
void cpu_rdtsc(uint64_t* result)
|
void cpu_rdtsc(uint64_t* result)
|
||||||
|
|
|
@ -28,21 +28,21 @@
|
||||||
#include "libcpuid.h"
|
#include "libcpuid.h"
|
||||||
|
|
||||||
/* Determine Compiler: */
|
/* Determine Compiler: */
|
||||||
#ifdef _MSC_VER
|
#if defined(_MSC_VER)
|
||||||
# define COMPILER_MICROSOFT
|
# define COMPILER_MICROSOFT
|
||||||
#else
|
#elif defined(__GNUC__)
|
||||||
# define COMPILER_GCC
|
# define COMPILER_GCC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Determine Platform */
|
/* Determine Platform */
|
||||||
#if defined(__x86_64__) || defined(_M_AMD64)
|
#if defined(__x86_64__) || defined(_M_AMD64)
|
||||||
# define PLATFORM_X64
|
# define PLATFORM_X64
|
||||||
#else
|
#elif defined(__i386__) || defined(_M_IX86)
|
||||||
# define PLATFORM_X86
|
# define PLATFORM_X86
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Under Windows/AMD64 with MSVC, inline assembly isn't supported */
|
/* Under Windows/AMD64 with MSVC, inline assembly isn't supported */
|
||||||
#if defined(COMPILER_GCC) || defined(PLATFORM_X86)
|
#if (defined(COMPILER_GCC) && defined(PLATFORM_X64)) || defined(PLATFORM_X86)
|
||||||
# define INLINE_ASM_SUPPORTED
|
# define INLINE_ASM_SUPPORTED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue