Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/perf/arch/x86/util/cpuid.h
26295 views
1
/* SPDX-License-Identifier: GPL-2.0 */
2
#ifndef PERF_CPUID_H
3
#define PERF_CPUID_H 1
4
5
6
static inline void
7
cpuid(unsigned int op, unsigned int op2, unsigned int *a, unsigned int *b,
8
unsigned int *c, unsigned int *d)
9
{
10
/*
11
* Preserve %ebx/%rbx register by either placing it in %rdi or saving it
12
* on the stack - x86-64 needs to avoid the stack red zone. In PIC
13
* compilations %ebx contains the address of the global offset
14
* table. %rbx is occasionally used to address stack variables in
15
* presence of dynamic allocas.
16
*/
17
asm(
18
#if defined(__x86_64__)
19
"mov %%rbx, %%rdi\n"
20
"cpuid\n"
21
"xchg %%rdi, %%rbx\n"
22
#else
23
"pushl %%ebx\n"
24
"cpuid\n"
25
"movl %%ebx, %%edi\n"
26
"popl %%ebx\n"
27
#endif
28
: "=a"(*a), "=D"(*b), "=c"(*c), "=d"(*d)
29
: "a"(op), "2"(op2));
30
}
31
32
void get_cpuid_0(char *vendor, unsigned int *lvl);
33
34
#endif
35
36