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