lin
2025-08-14 dae8bad597b6607a449b32bf76c523423f7720ed
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
35
/*
 * Copyright (c) 2012-2013 The Chromium OS Authors. All rights reserved.
 *
 * Licensed under the BSD 3-clause.
 */
 
#ifndef __LTP_CPUID_H__
#define __LTP_CPUID_H__
 
static inline void cpuid(unsigned int info, unsigned int *eax, unsigned int *ebx,
                         unsigned int *ecx, unsigned int *edx)
{
#if defined(__i386__) || defined(__x86_64__)
   unsigned int _eax = info, _ebx, _ecx, _edx;
   asm volatile(
# ifdef __i386__
       "xchg %%ebx, %%esi;" /* save ebx (for PIC) */
       "cpuid;"
       "xchg %%esi, %%ebx;" /* restore ebx & pass to caller */
       : "=S" (_ebx),
# else
       "cpuid;"
       : "=b" (_ebx),
# endif
         "+a" (_eax), "=c" (_ecx), "=d" (_edx)
       : /* inputs: eax is handled above */
   );
   if (eax) *eax = _eax;
   if (ebx) *ebx = _ebx;
   if (ecx) *ecx = _ecx;
   if (edx) *edx = _edx;
#endif
}
 
#endif