Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef PERF_CPUID_H
0003 #define PERF_CPUID_H 1
0004 
0005 
0006 static inline void
0007 cpuid(unsigned int op, unsigned int op2, unsigned int *a, unsigned int *b,
0008     unsigned int *c, unsigned int *d)
0009 {
0010     /*
0011      * Preserve %ebx/%rbx register by either placing it in %rdi or saving it
0012      * on the stack - x86-64 needs to avoid the stack red zone. In PIC
0013      * compilations %ebx contains the address of the global offset
0014      * table. %rbx is occasionally used to address stack variables in
0015      * presence of dynamic allocas.
0016      */
0017     asm(
0018 #if defined(__x86_64__)
0019         "mov %%rbx, %%rdi\n"
0020         "cpuid\n"
0021         "xchg %%rdi, %%rbx\n"
0022 #else
0023         "pushl %%ebx\n"
0024         "cpuid\n"
0025         "movl %%ebx, %%edi\n"
0026         "popl %%ebx\n"
0027 #endif
0028         : "=a"(*a), "=D"(*b), "=c"(*c), "=d"(*d)
0029         : "a"(op), "2"(op2));
0030 }
0031 
0032 void get_cpuid_0(char *vendor, unsigned int *lvl);
0033 
0034 #endif