1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-11-10 22:59:13 +00:00

Merge pull request #112 from fastogt/master

Clang + stubs for arm
This commit is contained in:
Veselin Georgiev 2018-05-18 00:13:27 +03:00 committed by GitHub
commit 05c8078d25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 8 deletions

View file

@ -32,7 +32,7 @@ int cpuid_exists_by_eflags(void)
#if defined(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 */
#elif defined(PLATFORM_X86) #elif defined(PLATFORM_X86)
# if defined(COMPILER_GCC) # if defined(COMPILER_GCC) || defined(COMPILER_CLANG)
int result; int result;
__asm __volatile( __asm __volatile(
" pushfl\n" " pushfl\n"
@ -70,6 +70,8 @@ int cpuid_exists_by_eflags(void)
# else # else
return 0; return 0;
# endif /* COMPILER_MICROSOFT */ # endif /* COMPILER_MICROSOFT */
#elif defined(PLATFORM_ARM)
return 0;
#else #else
return 0; return 0;
#endif /* PLATFORM_X86 */ #endif /* PLATFORM_X86 */
@ -82,7 +84,7 @@ int cpuid_exists_by_eflags(void)
*/ */
void exec_cpuid(uint32_t *regs) void exec_cpuid(uint32_t *regs)
{ {
#ifdef COMPILER_GCC # if defined(COMPILER_GCC) || defined(COMPILER_CLANG)
# ifdef PLATFORM_X64 # ifdef PLATFORM_X64
__asm __volatile( __asm __volatile(
" mov %0, %%rdi\n" " mov %0, %%rdi\n"
@ -109,7 +111,7 @@ void exec_cpuid(uint32_t *regs)
:"m"(regs) :"m"(regs)
:"memory", "eax", "rdi" :"memory", "eax", "rdi"
); );
# else # elif defined(PLATFORM_X86)
__asm __volatile( __asm __volatile(
" mov %0, %%edi\n" " mov %0, %%edi\n"
@ -135,6 +137,7 @@ void exec_cpuid(uint32_t *regs)
:"m"(regs) :"m"(regs)
:"memory", "eax", "edi" :"memory", "eax", "edi"
); );
# elif defined(PLATFORM_ARM)
# endif /* COMPILER_GCC */ # endif /* COMPILER_GCC */
#else #else
# ifdef COMPILER_MICROSOFT # ifdef COMPILER_MICROSOFT
@ -173,13 +176,18 @@ void exec_cpuid(uint32_t *regs)
void cpu_rdtsc(uint64_t* result) void cpu_rdtsc(uint64_t* result)
{ {
uint32_t low_part, hi_part; uint32_t low_part, hi_part;
#ifdef COMPILER_GCC #if defined(COMPILER_GCC) || defined(COMPILER_CLANG)
#ifdef PLATFORM_ARM
low_part = 0;
hi_part = 0;
#else
__asm __volatile ( __asm __volatile (
" rdtsc\n" " rdtsc\n"
" mov %%eax, %0\n" " mov %%eax, %0\n"
" mov %%edx, %1\n" " mov %%edx, %1\n"
:"=m"(low_part), "=m"(hi_part)::"memory", "eax", "edx" :"=m"(low_part), "=m"(hi_part)::"memory", "eax", "edx"
); );
#endif
#else #else
# ifdef COMPILER_MICROSOFT # ifdef COMPILER_MICROSOFT
__asm { __asm {
@ -198,12 +206,14 @@ void cpu_rdtsc(uint64_t* result)
#ifdef INLINE_ASM_SUPPORTED #ifdef INLINE_ASM_SUPPORTED
void busy_sse_loop(int cycles) void busy_sse_loop(int cycles)
{ {
#ifdef COMPILER_GCC # if defined(COMPILER_GCC) || defined(COMPILER_CLANG)
#ifndef __APPLE__ #ifndef __APPLE__
# define XALIGN ".balign 16\n" # define XALIGN ".balign 16\n"
#else #else
# define XALIGN ".align 4\n" # define XALIGN ".align 4\n"
#endif #endif
#ifdef PLATFORM_ARM
#else
__asm __volatile ( __asm __volatile (
" xorps %%xmm0, %%xmm0\n" " xorps %%xmm0, %%xmm0\n"
" xorps %%xmm1, %%xmm1\n" " xorps %%xmm1, %%xmm1\n"
@ -510,6 +520,7 @@ void busy_sse_loop(int cycles)
" jnz 1b\n" " jnz 1b\n"
::"a"(cycles) ::"a"(cycles)
); );
#endif
#else #else
# ifdef COMPILER_MICROSOFT # ifdef COMPILER_MICROSOFT
__asm { __asm {
@ -822,4 +833,4 @@ bsLoop:
# endif /* COMPILER_MICROSOFT */ # endif /* COMPILER_MICROSOFT */
#endif /* COMPILER_GCC */ #endif /* COMPILER_GCC */
} }
#endif /* INLINE_ASSEMBLY_SUPPORTED */ #endif /* INLINE_ASSEMBLY_SUPPORTED */

View file

@ -29,20 +29,36 @@
/* Determine Compiler: */ /* Determine Compiler: */
#if defined(_MSC_VER) #if defined(_MSC_VER)
#if !defined(COMPILER_MICROSOFT)
# define COMPILER_MICROSOFT # define COMPILER_MICROSOFT
#endif
#elif defined(__GNUC__) #elif defined(__GNUC__)
#if !defined(COMPILER_GCC)
# define COMPILER_GCC # define COMPILER_GCC
#endif #endif
#elif defined(__clang__)
#if !defined(COMPILER_CLANG)
# define COMPILER_CLANG
#endif
#endif
/* Determine Platform */ /* Determine Platform */
#if defined(__x86_64__) || defined(_M_AMD64) #if defined(__x86_64__) || defined(_M_AMD64)
#if !defined(PLATFORM_X64)
# define PLATFORM_X64 # define PLATFORM_X64
#endif
#elif defined(__i386__) || defined(_M_IX86) #elif defined(__i386__) || defined(_M_IX86)
#if !defined(PLATFORM_X86)
# define PLATFORM_X86 # define PLATFORM_X86
#endif #endif
#elif defined(__ARMEL__)
#if !defined(PLATFORM_ARM)
# define PLATFORM_ARM
#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_X64)) || defined(PLATFORM_X86) #if ((defined(COMPILER_GCC) || defined(COMPILER_CLANG))) && (defined(PLATFORM_X64) || defined(PLATFORM_X86) || defined(PLATFORM_ARM))
# define INLINE_ASM_SUPPORTED # define INLINE_ASM_SUPPORTED
#endif #endif

View file

@ -1141,7 +1141,7 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename);
int cpu_msr_driver_close(struct msr_driver_t* handle); int cpu_msr_driver_close(struct msr_driver_t* handle);
#ifdef __cplusplus #ifdef __cplusplus
}; /* extern "C" */ } /* extern "C" */
#endif #endif