GDBserver

linux-x86-tdesc-selftest.c
Go to the documentation of this file.
1 /* Copyright (C) 2017-2018 Free Software Foundation, Inc.
2
3 This file is part of GDB.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18 #include "server.h"
19 #include "linux-x86-tdesc.h"
20 #include "tdesc.h"
21 #include "common/selftest.h"
22 #include "x86-xstate.h"
23
24 /* Defined in auto-generated file i386-linux.c. */
25 void init_registers_i386_linux (void);
26 extern const struct target_desc *tdesc_i386_linux;
27
28 /* Defined in auto-generated file i386-mmx-linux.c. */
29 void init_registers_i386_mmx_linux (void);
30 extern const struct target_desc *tdesc_i386_mmx_linux;
31
32 /* Defined in auto-generated file i386-avx-linux.c. */
33 void init_registers_i386_avx_linux (void);
34 extern const struct target_desc *tdesc_i386_avx_linux;
35
36 /* Defined in auto-generated file i386-avx-mpx-linux.c. */
37 void init_registers_i386_avx_mpx_linux (void);
38 extern const struct target_desc *tdesc_i386_avx_mpx_linux;
39
40 /* Defined in auto-generated file i386-avx-avx512-linux.c. */
41 void init_registers_i386_avx_avx512_linux (void);
42 extern const struct target_desc *tdesc_i386_avx_avx512_linux;
43
44 /* Defined in auto-generated file i386-avx-mpx-avx512-linux.c. */
45 void init_registers_i386_avx_mpx_avx512_pku_linux (void);
46 extern const struct target_desc *tdesc_i386_avx_mpx_avx512_pku_linux;
47
48 /* Defined in auto-generated file i386-mpx-linux.c. */
49 void init_registers_i386_mpx_linux (void);
50 extern const struct target_desc *tdesc_i386_mpx_linux;
51
52 #ifdef __x86_64__
53
54 /* Defined in auto-generated file amd64-linux.c. */
55 void init_registers_amd64_linux (void);
56 extern const struct target_desc *tdesc_amd64_linux;
57
58 /* Defined in auto-generated file amd64-avx-linux.c. */
59 void init_registers_amd64_avx_linux (void);
60 extern const struct target_desc *tdesc_amd64_avx_linux;
61
62 /* Defined in auto-generated file amd64-avx-avx512-linux.c. */
63 void init_registers_amd64_avx_avx512_linux (void);
64 extern const struct target_desc *tdesc_amd64_avx_avx512_linux;
65
66 /* Defined in auto-generated file amd64-avx-mpx-avx512-pku-linux.c. */
67 void init_registers_amd64_avx_mpx_avx512_pku_linux (void);
68 extern const struct target_desc *tdesc_amd64_avx_mpx_avx512_pku_linux;
69
70 /* Defined in auto-generated file amd64-avx-mpx-linux.c. */
71 void init_registers_amd64_avx_mpx_linux (void);
72 extern const struct target_desc *tdesc_amd64_avx_mpx_linux;
73
74 /* Defined in auto-generated file amd64-mpx-linux.c. */
75 void init_registers_amd64_mpx_linux (void);
76 extern const struct target_desc *tdesc_amd64_mpx_linux;
77
78 /* Defined in auto-generated file x32-linux.c. */
79 void init_registers_x32_linux (void);
80 extern const struct target_desc *tdesc_x32_linux;
81
82 /* Defined in auto-generated file x32-avx-linux.c. */
83 void init_registers_x32_avx_linux (void);
84 extern const struct target_desc *tdesc_x32_avx_linux;
85
86 /* Defined in auto-generated file x32-avx-avx512-linux.c. */
87 void init_registers_x32_avx_avx512_linux (void);
88 extern const struct target_desc *tdesc_x32_avx_avx512_linux;
89
90 #endif
91
92 namespace selftests {
93 namespace tdesc {
94 static void
95 i386_tdesc_test ()
96 {
97 struct
98 {
99 unsigned int mask;
100 const target_desc *tdesc;
101 } tdesc_tests[] = {
102 { X86_XSTATE_X87, tdesc_i386_mmx_linux },
103 { X86_XSTATE_SSE_MASK, tdesc_i386_linux },
104 { X86_XSTATE_AVX_MASK, tdesc_i386_avx_linux },
105 { X86_XSTATE_MPX_MASK, tdesc_i386_mpx_linux },
106 { X86_XSTATE_AVX_MPX_MASK, tdesc_i386_avx_mpx_linux },
107 { X86_XSTATE_AVX_AVX512_MASK, tdesc_i386_avx_avx512_linux },
108 { X86_XSTATE_AVX_MPX_AVX512_PKU_MASK, tdesc_i386_avx_mpx_avx512_pku_linux }
109 };
110
111 for (auto &elem : tdesc_tests)
112 {
113 const target_desc *tdesc = i386_linux_read_description (elem.mask);
114
115 SELF_CHECK (*tdesc == *elem.tdesc);
116 }
117 }
118
119 #ifdef __x86_64__
120
121 static void
122 amd64_tdesc_test ()
123 {
124 struct
125 {
126 unsigned int mask;
127 const target_desc *tdesc[2];
128 } tdesc_tests[] = {
129 { X86_XSTATE_SSE_MASK, { tdesc_amd64_linux, tdesc_x32_linux } },
130 { X86_XSTATE_AVX_MASK, { tdesc_amd64_avx_linux, tdesc_x32_avx_linux } },
131 { X86_XSTATE_MPX_MASK, { tdesc_amd64_mpx_linux, tdesc_x32_avx_linux } },
132 { X86_XSTATE_AVX_MPX_MASK, { tdesc_amd64_avx_mpx_linux,
133 tdesc_x32_avx_linux } },
134 { X86_XSTATE_AVX_AVX512_MASK, { tdesc_amd64_avx_avx512_linux,
135 tdesc_x32_avx_avx512_linux } },
136 { X86_XSTATE_AVX_MPX_AVX512_PKU_MASK,
137 { tdesc_amd64_avx_mpx_avx512_pku_linux, tdesc_x32_avx_avx512_linux } },
138 };
139
140 for (auto &elem : tdesc_tests)
141 {
142 for (int i = 0; i < 2; i++)
143 {
144 const target_desc *tdesc = amd64_linux_read_description (elem.mask,
145 i);
146
147 SELF_CHECK (*tdesc == *elem.tdesc[i]);
148 }
149 }
150 }
151
152 #endif
153 }
154 } // namespace selftests
155
156 void
157 initialize_low_tdesc ()
158 {
159 init_registers_i386_linux ();
160 init_registers_i386_mmx_linux ();
161 init_registers_i386_avx_linux ();
162 init_registers_i386_mpx_linux ();
163 init_registers_i386_avx_mpx_linux ();
164 init_registers_i386_avx_avx512_linux ();
165 init_registers_i386_avx_mpx_avx512_pku_linux ();
166
167 selftests::register_test ("i386-tdesc", selftests::tdesc::i386_tdesc_test);
168
169 #ifdef __x86_64__
170 init_registers_x32_linux ();
171 init_registers_x32_avx_linux ();
172 init_registers_x32_avx_avx512_linux ();
173
174 init_registers_amd64_linux ();
175 init_registers_amd64_avx_linux ();
176 init_registers_amd64_mpx_linux ();
177 init_registers_amd64_avx_mpx_linux ();
178 init_registers_amd64_avx_avx512_linux ();
179 init_registers_amd64_avx_mpx_avx512_pku_linux ();
180
181 selftests::register_test ("amd64-tdesc", selftests::tdesc::amd64_tdesc_test);
182 #endif
183 }
X86_XSTATE_AVX_MASK
#define X86_XSTATE_AVX_MASK
Definition: x86-xstate.h:43
init_registers_i386_avx_mpx_linux
void init_registers_i386_avx_mpx_linux(void)
X86_XSTATE_SSE_MASK
#define X86_XSTATE_SSE_MASK
Definition: x86-xstate.h:42
tdesc_i386_avx_mpx_linux
const struct target_desc * tdesc_i386_avx_mpx_linux
i386_linux_read_description
const struct target_desc * i386_linux_read_description(uint64_t xcr0)
Definition: linux-x86-tdesc.c:78
X86_XSTATE_MPX_MASK
#define X86_XSTATE_MPX_MASK
Definition: x86-xstate.h:44
init_registers_i386_mmx_linux
void init_registers_i386_mmx_linux(void)
initialize_low_tdesc
void initialize_low_tdesc()
Definition: linux-x86-tdesc-selftest.c:157
init_registers_i386_linux
void init_registers_i386_linux(void)
tdesc_i386_mmx_linux
const struct target_desc * tdesc_i386_mmx_linux
selftests::tdesc::i386_tdesc_test
static void i386_tdesc_test()
Definition: linux-x86-tdesc-selftest.c:95
x86-xstate.h
selftests
Definition: linux-aarch64-tdesc-selftest.c:27
init_registers_i386_avx_mpx_avx512_pku_linux
void init_registers_i386_avx_mpx_avx512_pku_linux(void)
linux-x86-tdesc.h
X86_XSTATE_AVX_AVX512_MASK
#define X86_XSTATE_AVX_AVX512_MASK
Definition: x86-xstate.h:46
tdesc_i386_linux
const struct target_desc * tdesc_i386_linux
server.h
init_registers_amd64_linux
void init_registers_amd64_linux(void)
tdesc_amd64_linux
const struct target_desc * tdesc_amd64_linux
init_registers_i386_avx_linux
void init_registers_i386_avx_linux(void)
tdesc_i386_avx_linux
const struct target_desc * tdesc_i386_avx_linux
init_registers_i386_mpx_linux
void init_registers_i386_mpx_linux(void)
target_desc
Definition: tdesc.h:33
init_registers_i386_avx_avx512_linux
void init_registers_i386_avx_avx512_linux(void)
X86_XSTATE_X87
#define X86_XSTATE_X87
Definition: x86-xstate.h:24
tdesc_i386_avx_avx512_linux
const struct target_desc * tdesc_i386_avx_avx512_linux
selftest.h
X86_XSTATE_AVX_MPX_MASK
#define X86_XSTATE_AVX_MPX_MASK
Definition: x86-xstate.h:45
tdesc_i386_avx_mpx_avx512_pku_linux
const struct target_desc * tdesc_i386_avx_mpx_avx512_pku_linux
selftests::register_test
void register_test(const std::string &name, selftest *test)
Definition: selftest.c:52
X86_XSTATE_AVX_MPX_AVX512_PKU_MASK
#define X86_XSTATE_AVX_MPX_AVX512_PKU_MASK
Definition: x86-xstate.h:47
tdesc.h
SELF_CHECK
#define SELF_CHECK(VALUE)
Definition: selftest.h:67
tdesc_i386_mpx_linux
const struct target_desc * tdesc_i386_mpx_linux