File: cpuid.h

package info (click to toggle)
linux 6.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,488,076 kB
  • sloc: ansic: 23,401,844; asm: 266,744; sh: 108,976; makefile: 49,705; python: 36,927; perl: 36,810; cpp: 6,044; yacc: 4,904; lex: 2,722; awk: 1,440; ruby: 25; sed: 5
file content (34 lines) | stat: -rw-r--r-- 833 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef PERF_CPUID_H
#define PERF_CPUID_H 1


static inline void
cpuid(unsigned int op, unsigned int op2, unsigned int *a, unsigned int *b,
	unsigned int *c, unsigned int *d)
{
	/*
	 * Preserve %ebx/%rbx register by either placing it in %rdi or saving it
	 * on the stack - x86-64 needs to avoid the stack red zone. In PIC
	 * compilations %ebx contains the address of the global offset
	 * table. %rbx is occasionally used to address stack variables in
	 * presence of dynamic allocas.
	 */
	asm(
#if defined(__x86_64__)
		"mov %%rbx, %%rdi\n"
		"cpuid\n"
		"xchg %%rdi, %%rbx\n"
#else
		"pushl %%ebx\n"
		"cpuid\n"
		"movl %%ebx, %%edi\n"
		"popl %%ebx\n"
#endif
		: "=a"(*a), "=D"(*b), "=c"(*c), "=d"(*d)
		: "a"(op), "2"(op2));
}

void get_cpuid_0(char *vendor, unsigned int *lvl);

#endif