x86: AVX512 VPERM{D,Q,PS,PD} insns need to honor EVEX.L'L
[deliverable/binutils-gdb.git] / gdbserver / tdesc.cc
1 /* Copyright (C) 2012-2020 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 "tdesc.h"
20 #include "regdef.h"
21
22 #ifndef IN_PROCESS_AGENT
23
24 target_desc::~target_desc ()
25 {
26 xfree ((char *) arch);
27 xfree ((char *) osabi);
28 }
29
30 bool target_desc::operator== (const target_desc &other) const
31 {
32 if (reg_defs != other.reg_defs)
33 return false;
34
35 /* Compare expedite_regs. */
36 int i = 0;
37 for (; expedite_regs[i] != NULL; i++)
38 {
39 if (strcmp (expedite_regs[i], other.expedite_regs[i]) != 0)
40 return false;
41 }
42 if (other.expedite_regs[i] != NULL)
43 return false;
44
45 return true;
46 }
47
48 #endif
49
50 void target_desc::accept (tdesc_element_visitor &v) const
51 {
52 #ifndef IN_PROCESS_AGENT
53 v.visit_pre (this);
54
55 for (const tdesc_feature_up &feature : features)
56 feature->accept (v);
57
58 v.visit_post (this);
59 #endif
60 }
61
62 void
63 init_target_desc (struct target_desc *tdesc,
64 const char **expedite_regs)
65 {
66 int offset = 0;
67
68 /* Go through all the features and populate reg_defs. */
69 for (const tdesc_feature_up &feature : tdesc->features)
70 for (const tdesc_reg_up &treg : feature->registers)
71 {
72 int regnum = treg->target_regnum;
73
74 /* Register number will increase (possibly with gaps) or be zero. */
75 gdb_assert (regnum == 0 || regnum >= tdesc->reg_defs.size ());
76
77 if (regnum != 0)
78 tdesc->reg_defs.resize (regnum, gdb::reg (offset));
79
80 tdesc->reg_defs.emplace_back (treg->name.c_str (), offset,
81 treg->bitsize);
82 offset += treg->bitsize;
83 }
84
85 tdesc->registers_size = offset / 8;
86
87 /* Make sure PBUFSIZ is large enough to hold a full register
88 packet. */
89 gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ);
90
91 #ifndef IN_PROCESS_AGENT
92 tdesc->expedite_regs = expedite_regs;
93 #endif
94 }
95
96 struct target_desc *
97 allocate_target_description (void)
98 {
99 return new target_desc ();
100 }
101
102 #ifndef IN_PROCESS_AGENT
103
104 static const struct target_desc default_description {};
105
106 void
107 copy_target_description (struct target_desc *dest,
108 const struct target_desc *src)
109 {
110 dest->reg_defs = src->reg_defs;
111 dest->expedite_regs = src->expedite_regs;
112 dest->registers_size = src->registers_size;
113 dest->xmltarget = src->xmltarget;
114 }
115
116 const struct target_desc *
117 current_target_desc (void)
118 {
119 if (current_thread == NULL)
120 return &default_description;
121
122 return current_process ()->tdesc;
123 }
124
125 /* An empty structure. */
126
127 struct tdesc_compatible_info { };
128
129 /* See gdbsupport/tdesc.h. */
130
131 const std::vector<tdesc_compatible_info_up> &
132 tdesc_compatible_info_list (const target_desc *target_desc)
133 {
134 static std::vector<tdesc_compatible_info_up> empty;
135 return empty;
136 }
137
138 /* See gdbsupport/tdesc.h. */
139
140 const char *
141 tdesc_compatible_info_arch_name (const tdesc_compatible_info_up &c_info)
142 {
143 return nullptr;
144 }
145
146 /* See gdbsupport/tdesc.h. */
147
148 const char *
149 tdesc_architecture_name (const struct target_desc *target_desc)
150 {
151 return target_desc->arch;
152 }
153
154 /* See gdbsupport/tdesc.h. */
155
156 void
157 set_tdesc_architecture (struct target_desc *target_desc,
158 const char *name)
159 {
160 target_desc->arch = xstrdup (name);
161 }
162
163 /* See gdbsupport/tdesc.h. */
164
165 const char *
166 tdesc_osabi_name (const struct target_desc *target_desc)
167 {
168 return target_desc->osabi;
169 }
170
171 /* See gdbsupport/tdesc.h. */
172
173 void
174 set_tdesc_osabi (struct target_desc *target_desc, const char *name)
175 {
176 target_desc->osabi = xstrdup (name);
177 }
178
179 /* See gdbsupport/tdesc.h. */
180
181 const char *
182 tdesc_get_features_xml (const target_desc *tdesc)
183 {
184 /* Either .xmltarget or .features is not NULL. */
185 gdb_assert (tdesc->xmltarget != NULL
186 || (!tdesc->features.empty ()
187 && tdesc->arch != NULL));
188
189 if (tdesc->xmltarget == NULL)
190 {
191 std::string buffer ("@");
192 print_xml_feature v (&buffer);
193 tdesc->accept (v);
194 tdesc->xmltarget = xstrdup (buffer.c_str ());
195 }
196
197 return tdesc->xmltarget;
198 }
199 #endif
200
201 /* See gdbsupport/tdesc.h. */
202
203 struct tdesc_feature *
204 tdesc_create_feature (struct target_desc *tdesc, const char *name)
205 {
206 struct tdesc_feature *new_feature = new tdesc_feature (name);
207 tdesc->features.emplace_back (new_feature);
208 return new_feature;
209 }
210
211 /* See gdbsupport/tdesc.h. */
212
213 bool
214 tdesc_contains_feature (const target_desc *tdesc, const std::string &feature)
215 {
216 gdb_assert (tdesc != nullptr);
217
218 for (const tdesc_feature_up &f : tdesc->features)
219 {
220 if (f->name == feature)
221 return true;
222 }
223
224 return false;
225 }
This page took 0.033409 seconds and 4 git commands to generate.