GDB (xrefs)
Loading...
Searching...
No Matches
x86-cpuid.h
Go to the documentation of this file.
1/* C API for x86 cpuid insn.
2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This file is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef NAT_X86_CPUID_H
20#define NAT_X86_CPUID_H
21
22/* Always include the header for the cpu bit defines. */
23#include "x86-gcc-cpuid.h"
24
25#ifndef __cplusplus
26/* This header file is also used in C code for some test-cases, so define
27 nullptr in C terms to avoid a compilation error. */
28#define nullptr ((void *) 0)
29#endif
30
31#if defined(__i386__) || defined(__x86_64__)
32
33/* Return cpuid data for requested cpuid level, as found in returned
34 eax, ebx, ecx and edx registers. The function checks if cpuid is
35 supported and returns 1 for valid cpuid information or 0 for
36 unsupported cpuid level. Pointers may be non-null. */
37
38static __inline int
39x86_cpuid (unsigned int __level,
40 unsigned int *__eax, unsigned int *__ebx,
41 unsigned int *__ecx, unsigned int *__edx)
42{
43 unsigned int __scratch;
44
45 if (!__eax)
46 __eax = &__scratch;
47 if (!__ebx)
48 __ebx = &__scratch;
49 if (!__ecx)
50 __ecx = &__scratch;
51 if (!__edx)
52 __edx = &__scratch;
53
54 return __get_cpuid (__level, __eax, __ebx, __ecx, __edx);
55}
56
57/* Return cpuid data for requested cpuid level and sub-level, as found
58 in returned eax, ebx, ecx and edx registers. The function checks
59 if cpuid is supported and returns 1 for valid cpuid information or
60 0 for unsupported cpuid level. Pointers may be non-null. */
61
62static __inline int
63x86_cpuid_count (unsigned int __level, unsigned int __sublevel,
64 unsigned int *__eax, unsigned int *__ebx,
65 unsigned int *__ecx, unsigned int *__edx)
66{
67 unsigned int __scratch;
68
69 if (__eax == nullptr)
70 __eax = &__scratch;
71 if (__ebx == nullptr)
72 __ebx = &__scratch;
73 if (__ecx == nullptr)
74 __ecx = &__scratch;
75 if (__edx == nullptr)
76 __edx = &__scratch;
77
78 return __get_cpuid_count (__level, __sublevel, __eax, __ebx, __ecx, __edx);
79}
80
81#else
82
83static __inline int
84x86_cpuid (unsigned int __level,
85 unsigned int *__eax, unsigned int *__ebx,
86 unsigned int *__ecx, unsigned int *__edx)
87{
88 return 0;
89}
90
91static __inline int
92x86_cpuid_count (unsigned int __level, unsigned int __sublevel,
93 unsigned int *__eax, unsigned int *__ebx,
94 unsigned int *__ecx, unsigned int *__edx)
95{
96 return 0;
97}
98
99#endif /* i386 && x86_64 */
100
101#ifndef __cplusplus
102/* Avoid leaking this local definition beyond the scope of this header
103 file. */
104#undef nullptr
105#endif
106
107#endif /* NAT_X86_CPUID_H */
static __inline int x86_cpuid_count(unsigned int __level, unsigned int __sublevel, unsigned int *__eax, unsigned int *__ebx, unsigned int *__ecx, unsigned int *__edx)
Definition x86-cpuid.h:92
static __inline int x86_cpuid(unsigned int __level, unsigned int *__eax, unsigned int *__ebx, unsigned int *__ecx, unsigned int *__edx)
Definition x86-cpuid.h:84
static __inline int __get_cpuid(unsigned int __leaf, unsigned int *__eax, unsigned int *__ebx, unsigned int *__ecx, unsigned int *__edx)
static __inline int __get_cpuid_count(unsigned int __leaf, unsigned int __subleaf, unsigned int *__eax, unsigned int *__ebx, unsigned int *__ecx, unsigned int *__edx)