]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/nat/x86-cpuid.h
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / nat / x86-cpuid.h
1 /* C API for x86 cpuid insn.
2 Copyright (C) 2007-2024 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 /* Return cpuid data for requested cpuid level, as found in returned
32 eax, ebx, ecx and edx registers. The function checks if cpuid is
33 supported and returns 1 for valid cpuid information or 0 for
34 unsupported cpuid level. Pointers may be non-null. */
35
36 static __inline int
37 x86_cpuid (unsigned int __level,
38 unsigned int *__eax, unsigned int *__ebx,
39 unsigned int *__ecx, unsigned int *__edx)
40 {
41 unsigned int __scratch;
42
43 if (!__eax)
44 __eax = &__scratch;
45 if (!__ebx)
46 __ebx = &__scratch;
47 if (!__ecx)
48 __ecx = &__scratch;
49 if (!__edx)
50 __edx = &__scratch;
51
52 return __get_cpuid (__level, __eax, __ebx, __ecx, __edx);
53 }
54
55 /* Return cpuid data for requested cpuid level and sub-level, as found
56 in returned eax, ebx, ecx and edx registers. The function checks
57 if cpuid is supported and returns 1 for valid cpuid information or
58 0 for unsupported cpuid level. Pointers may be non-null. */
59
60 static __inline int
61 x86_cpuid_count (unsigned int __level, unsigned int __sublevel,
62 unsigned int *__eax, unsigned int *__ebx,
63 unsigned int *__ecx, unsigned int *__edx)
64 {
65 unsigned int __scratch;
66
67 if (__eax == nullptr)
68 __eax = &__scratch;
69 if (__ebx == nullptr)
70 __ebx = &__scratch;
71 if (__ecx == nullptr)
72 __ecx = &__scratch;
73 if (__edx == nullptr)
74 __edx = &__scratch;
75
76 return __get_cpuid_count (__level, __sublevel, __eax, __ebx, __ecx, __edx);
77 }
78
79 #ifndef __cplusplus
80 /* Avoid leaking this local definition beyond the scope of this header
81 file. */
82 #undef nullptr
83 #endif
84
85 #endif /* NAT_X86_CPUID_H */