• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2012-2013 The Chromium OS Authors. All rights reserved.
3  *
4  * Licensed under the BSD 3-clause.
5  */
6 
7 #ifndef __LTP_CPUID_H__
8 #define __LTP_CPUID_H__
9 
cpuid(unsigned int info,unsigned int * eax,unsigned int * ebx,unsigned int * ecx,unsigned int * edx)10 static inline void cpuid(unsigned int info, unsigned int *eax, unsigned int *ebx,
11                          unsigned int *ecx, unsigned int *edx)
12 {
13 #if defined(__i386__) || defined(__x86_64__)
14 	unsigned int _eax = info, _ebx, _ecx, _edx;
15 	asm volatile(
16 # ifdef __i386__
17 		"xchg %%ebx, %%esi;" /* save ebx (for PIC) */
18 		"cpuid;"
19 		"xchg %%esi, %%ebx;" /* restore ebx & pass to caller */
20 		: "=S" (_ebx),
21 # else
22 		"cpuid;"
23 		: "=b" (_ebx),
24 # endif
25 		  "+a" (_eax), "=c" (_ecx), "=d" (_edx)
26 		: /* inputs: eax is handled above */
27 	);
28 	if (eax) *eax = _eax;
29 	if (ebx) *ebx = _ebx;
30 	if (ecx) *ecx = _ecx;
31 	if (edx) *edx = _edx;
32 #endif
33 }
34 
35 #endif
36