Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | /* Copyright (C) 2006-2020 Free Software Foundation, Inc. |
f49ff000 YQ |
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 | ||
1a5c2598 TT |
18 | #ifndef COMMON_TDESC_H |
19 | #define COMMON_TDESC_H | |
f49ff000 YQ |
20 | |
21 | struct tdesc_feature; | |
22 | struct tdesc_type; | |
d4a0e8b5 SM |
23 | struct tdesc_type_builtin; |
24 | struct tdesc_type_vector; | |
25 | struct tdesc_type_with_fields; | |
f49ff000 YQ |
26 | struct tdesc_reg; |
27 | struct target_desc; | |
28 | ||
ea3e7d71 AH |
29 | /* The interface to visit different elements of target description. */ |
30 | ||
31 | class tdesc_element_visitor | |
32 | { | |
33 | public: | |
34 | virtual void visit_pre (const target_desc *e) | |
35 | {} | |
36 | ||
37 | virtual void visit_post (const target_desc *e) | |
38 | {} | |
39 | ||
40 | virtual void visit_pre (const tdesc_feature *e) | |
41 | {} | |
42 | ||
43 | virtual void visit_post (const tdesc_feature *e) | |
44 | {} | |
45 | ||
46 | virtual void visit (const tdesc_type_builtin *e) | |
47 | {} | |
48 | ||
49 | virtual void visit (const tdesc_type_vector *e) | |
50 | {} | |
51 | ||
52 | virtual void visit (const tdesc_type_with_fields *e) | |
53 | {} | |
54 | ||
55 | virtual void visit (const tdesc_reg *e) | |
56 | {} | |
57 | }; | |
58 | ||
59 | class tdesc_element | |
60 | { | |
61 | public: | |
62 | virtual void accept (tdesc_element_visitor &v) const = 0; | |
63 | }; | |
64 | ||
65 | /* An individual register from a target description. */ | |
66 | ||
67 | struct tdesc_reg : tdesc_element | |
68 | { | |
69 | tdesc_reg (struct tdesc_feature *feature, const std::string &name_, | |
70 | int regnum, int save_restore_, const char *group_, | |
71 | int bitsize_, const char *type_); | |
72 | ||
73 | virtual ~tdesc_reg () = default; | |
74 | ||
75 | DISABLE_COPY_AND_ASSIGN (tdesc_reg); | |
76 | ||
77 | /* The name of this register. In standard features, it may be | |
78 | recognized by the architecture support code, or it may be purely | |
79 | for the user. */ | |
80 | std::string name; | |
81 | ||
82 | /* The register number used by this target to refer to this | |
83 | register. This is used for remote p/P packets and to determine | |
84 | the ordering of registers in the remote g/G packets. */ | |
85 | long target_regnum; | |
86 | ||
87 | /* If this flag is set, GDB should save and restore this register | |
88 | around calls to an inferior function. */ | |
89 | int save_restore; | |
90 | ||
91 | /* The name of the register group containing this register, or empty | |
92 | if the group should be automatically determined from the | |
93 | register's type. If this is "general", "float", or "vector", the | |
94 | corresponding "info" command should display this register's | |
95 | value. It can be an arbitrary string, but should be limited to | |
96 | alphanumeric characters and internal hyphens. Currently other | |
97 | strings are ignored (treated as empty). */ | |
98 | std::string group; | |
99 | ||
100 | /* The size of the register, in bits. */ | |
101 | int bitsize; | |
102 | ||
103 | /* The type of the register. This string corresponds to either | |
104 | a named type from the target description or a predefined | |
105 | type from GDB. */ | |
106 | std::string type; | |
107 | ||
108 | /* The target-described type corresponding to TYPE, if found. */ | |
109 | struct tdesc_type *tdesc_type; | |
110 | ||
111 | void accept (tdesc_element_visitor &v) const override | |
112 | { | |
113 | v.visit (this); | |
114 | } | |
115 | ||
116 | bool operator== (const tdesc_reg &other) const | |
117 | { | |
118 | return (name == other.name | |
119 | && target_regnum == other.target_regnum | |
120 | && save_restore == other.save_restore | |
121 | && bitsize == other.bitsize | |
122 | && group == other.group | |
123 | && type == other.type); | |
124 | } | |
125 | ||
126 | bool operator!= (const tdesc_reg &other) const | |
127 | { | |
128 | return !(*this == other); | |
129 | } | |
130 | }; | |
131 | ||
132 | typedef std::unique_ptr<tdesc_reg> tdesc_reg_up; | |
133 | ||
fbf42f4e AB |
134 | /* Declaration of a structure that holds information about one |
135 | "compatibility" entry within a target description. */ | |
136 | ||
137 | struct tdesc_compatible_info; | |
138 | ||
139 | /* A pointer to a single piece of compatibility information. */ | |
140 | ||
141 | typedef std::unique_ptr<tdesc_compatible_info> tdesc_compatible_info_up; | |
142 | ||
143 | /* Return a vector of compatibility information pointers from the target | |
144 | description TARGET_DESC. */ | |
145 | ||
146 | const std::vector<tdesc_compatible_info_up> &tdesc_compatible_info_list | |
147 | (const target_desc *target_desc); | |
148 | ||
149 | /* Return the architecture name from a compatibility information | |
150 | COMPATIBLE. */ | |
151 | ||
152 | const char *tdesc_compatible_info_arch_name | |
153 | (const tdesc_compatible_info_up &compatible); | |
154 | ||
82ec9bc7 AH |
155 | enum tdesc_type_kind |
156 | { | |
157 | /* Predefined types. */ | |
158 | TDESC_TYPE_BOOL, | |
159 | TDESC_TYPE_INT8, | |
160 | TDESC_TYPE_INT16, | |
161 | TDESC_TYPE_INT32, | |
162 | TDESC_TYPE_INT64, | |
163 | TDESC_TYPE_INT128, | |
164 | TDESC_TYPE_UINT8, | |
165 | TDESC_TYPE_UINT16, | |
166 | TDESC_TYPE_UINT32, | |
167 | TDESC_TYPE_UINT64, | |
168 | TDESC_TYPE_UINT128, | |
169 | TDESC_TYPE_CODE_PTR, | |
170 | TDESC_TYPE_DATA_PTR, | |
a6d0f249 | 171 | TDESC_TYPE_IEEE_HALF, |
82ec9bc7 AH |
172 | TDESC_TYPE_IEEE_SINGLE, |
173 | TDESC_TYPE_IEEE_DOUBLE, | |
174 | TDESC_TYPE_ARM_FPA_EXT, | |
175 | TDESC_TYPE_I387_EXT, | |
176 | ||
177 | /* Types defined by a target feature. */ | |
178 | TDESC_TYPE_VECTOR, | |
179 | TDESC_TYPE_STRUCT, | |
180 | TDESC_TYPE_UNION, | |
181 | TDESC_TYPE_FLAGS, | |
182 | TDESC_TYPE_ENUM | |
183 | }; | |
184 | ||
185 | struct tdesc_type : tdesc_element | |
186 | { | |
187 | tdesc_type (const std::string &name_, enum tdesc_type_kind kind_) | |
188 | : name (name_), kind (kind_) | |
189 | {} | |
190 | ||
191 | virtual ~tdesc_type () = default; | |
192 | ||
193 | DISABLE_COPY_AND_ASSIGN (tdesc_type); | |
194 | ||
195 | /* The name of this type. */ | |
196 | std::string name; | |
197 | ||
198 | /* Identify the kind of this type. */ | |
199 | enum tdesc_type_kind kind; | |
200 | ||
201 | bool operator== (const tdesc_type &other) const | |
202 | { | |
203 | return name == other.name && kind == other.kind; | |
204 | } | |
205 | ||
206 | bool operator!= (const tdesc_type &other) const | |
207 | { | |
208 | return !(*this == other); | |
209 | } | |
210 | }; | |
211 | ||
212 | typedef std::unique_ptr<tdesc_type> tdesc_type_up; | |
213 | ||
eee8a18d AH |
214 | struct tdesc_type_builtin : tdesc_type |
215 | { | |
216 | tdesc_type_builtin (const std::string &name, enum tdesc_type_kind kind) | |
217 | : tdesc_type (name, kind) | |
218 | {} | |
219 | ||
220 | void accept (tdesc_element_visitor &v) const override | |
221 | { | |
222 | v.visit (this); | |
223 | } | |
224 | }; | |
225 | ||
226 | /* tdesc_type for vector types. */ | |
227 | ||
228 | struct tdesc_type_vector : tdesc_type | |
229 | { | |
230 | tdesc_type_vector (const std::string &name, tdesc_type *element_type_, | |
231 | int count_) | |
232 | : tdesc_type (name, TDESC_TYPE_VECTOR), | |
233 | element_type (element_type_), count (count_) | |
234 | {} | |
235 | ||
236 | void accept (tdesc_element_visitor &v) const override | |
237 | { | |
238 | v.visit (this); | |
239 | } | |
240 | ||
241 | struct tdesc_type *element_type; | |
242 | int count; | |
243 | }; | |
244 | ||
245 | /* A named type from a target description. */ | |
246 | ||
247 | struct tdesc_type_field | |
248 | { | |
249 | tdesc_type_field (const std::string &name_, tdesc_type *type_, | |
250 | int start_, int end_) | |
251 | : name (name_), type (type_), start (start_), end (end_) | |
252 | {} | |
253 | ||
254 | std::string name; | |
255 | struct tdesc_type *type; | |
256 | /* For non-enum-values, either both are -1 (non-bitfield), or both are | |
257 | not -1 (bitfield). For enum values, start is the value (which could be | |
258 | -1), end is -1. */ | |
259 | int start, end; | |
260 | }; | |
261 | ||
262 | /* tdesc_type for struct, union, flags, and enum types. */ | |
263 | ||
264 | struct tdesc_type_with_fields : tdesc_type | |
265 | { | |
266 | tdesc_type_with_fields (const std::string &name, tdesc_type_kind kind, | |
267 | int size_ = 0) | |
268 | : tdesc_type (name, kind), size (size_) | |
269 | {} | |
270 | ||
271 | void accept (tdesc_element_visitor &v) const override | |
272 | { | |
273 | v.visit (this); | |
274 | } | |
275 | ||
276 | std::vector<tdesc_type_field> fields; | |
277 | int size; | |
278 | }; | |
279 | ||
82ec9bc7 AH |
280 | /* A feature from a target description. Each feature is a collection |
281 | of other elements, e.g. registers and types. */ | |
282 | ||
283 | struct tdesc_feature : tdesc_element | |
284 | { | |
285 | tdesc_feature (const std::string &name_) | |
286 | : name (name_) | |
287 | {} | |
288 | ||
289 | virtual ~tdesc_feature () = default; | |
290 | ||
291 | DISABLE_COPY_AND_ASSIGN (tdesc_feature); | |
292 | ||
293 | /* The name of this feature. It may be recognized by the architecture | |
294 | support code. */ | |
295 | std::string name; | |
296 | ||
297 | /* The registers associated with this feature. */ | |
298 | std::vector<tdesc_reg_up> registers; | |
299 | ||
300 | /* The types associated with this feature. */ | |
301 | std::vector<tdesc_type_up> types; | |
302 | ||
303 | void accept (tdesc_element_visitor &v) const override; | |
304 | ||
305 | bool operator== (const tdesc_feature &other) const; | |
306 | ||
307 | bool operator!= (const tdesc_feature &other) const | |
308 | { | |
309 | return !(*this == other); | |
310 | } | |
311 | }; | |
312 | ||
313 | typedef std::unique_ptr<tdesc_feature> tdesc_feature_up; | |
314 | ||
5f035c07 YQ |
315 | /* Allocate a new target_desc. */ |
316 | target_desc *allocate_target_description (void); | |
317 | ||
318 | /* Set TARGET_DESC's architecture by NAME. */ | |
319 | void set_tdesc_architecture (target_desc *target_desc, | |
320 | const char *name); | |
321 | ||
d278f585 AH |
322 | /* Return the architecture associated with this target description as a string, |
323 | or NULL if no architecture was specified. */ | |
324 | const char *tdesc_architecture_name (const struct target_desc *target_desc); | |
325 | ||
5f035c07 YQ |
326 | /* Set TARGET_DESC's osabi by NAME. */ |
327 | void set_tdesc_osabi (target_desc *target_desc, const char *name); | |
328 | ||
d278f585 AH |
329 | /* Return the osabi associated with this target description as a string, |
330 | or NULL if no osabi was specified. */ | |
331 | const char *tdesc_osabi_name (const struct target_desc *target_desc); | |
332 | ||
f49ff000 YQ |
333 | /* Return the type associated with ID in the context of FEATURE, or |
334 | NULL if none. */ | |
335 | struct tdesc_type *tdesc_named_type (const struct tdesc_feature *feature, | |
336 | const char *id); | |
337 | ||
338 | /* Return the created feature named NAME in target description TDESC. */ | |
339 | struct tdesc_feature *tdesc_create_feature (struct target_desc *tdesc, | |
3b74854b | 340 | const char *name); |
f49ff000 YQ |
341 | |
342 | /* Return the created vector tdesc_type named NAME in FEATURE. */ | |
343 | struct tdesc_type *tdesc_create_vector (struct tdesc_feature *feature, | |
344 | const char *name, | |
345 | struct tdesc_type *field_type, | |
346 | int count); | |
347 | ||
348 | /* Return the created struct tdesc_type named NAME in FEATURE. */ | |
d4a0e8b5 SM |
349 | tdesc_type_with_fields *tdesc_create_struct (struct tdesc_feature *feature, |
350 | const char *name); | |
f49ff000 YQ |
351 | |
352 | /* Return the created union tdesc_type named NAME in FEATURE. */ | |
d4a0e8b5 SM |
353 | tdesc_type_with_fields *tdesc_create_union (struct tdesc_feature *feature, |
354 | const char *name); | |
f49ff000 YQ |
355 | |
356 | /* Return the created flags tdesc_type named NAME in FEATURE. */ | |
d4a0e8b5 SM |
357 | tdesc_type_with_fields *tdesc_create_flags (struct tdesc_feature *feature, |
358 | const char *name, | |
359 | int size); | |
f49ff000 | 360 | |
eee8a18d AH |
361 | /* Return the created enum tdesc_type named NAME in FEATURE. */ |
362 | tdesc_type_with_fields *tdesc_create_enum (struct tdesc_feature *feature, | |
363 | const char *name, | |
364 | int size); | |
365 | ||
f49ff000 YQ |
366 | /* Add a new field to TYPE. FIELD_NAME is its name, and FIELD_TYPE is |
367 | its type. */ | |
d4a0e8b5 | 368 | void tdesc_add_field (tdesc_type_with_fields *type, const char *field_name, |
f49ff000 YQ |
369 | struct tdesc_type *field_type); |
370 | ||
eee8a18d AH |
371 | /* Add a new bitfield to TYPE, with range START to END. FIELD_NAME is its name, |
372 | and FIELD_TYPE is its type. */ | |
373 | void tdesc_add_typed_bitfield (tdesc_type_with_fields *type, | |
374 | const char *field_name, | |
375 | int start, int end, | |
376 | struct tdesc_type *field_type); | |
377 | ||
f49ff000 YQ |
378 | /* Set the total length of TYPE. Structs which contain bitfields may |
379 | omit the reserved bits, so the end of the last field may not | |
380 | suffice. */ | |
d4a0e8b5 | 381 | void tdesc_set_struct_size (tdesc_type_with_fields *type, int size); |
f49ff000 YQ |
382 | |
383 | /* Add a new untyped bitfield to TYPE. | |
384 | Untyped bitfields become either uint32 or uint64 depending on the size | |
385 | of the underlying type. */ | |
d4a0e8b5 | 386 | void tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name, |
f49ff000 YQ |
387 | int start, int end); |
388 | ||
389 | /* A flag is just a typed(bool) single-bit bitfield. | |
390 | This function is kept to minimize changes in generated files. */ | |
d4a0e8b5 | 391 | void tdesc_add_flag (tdesc_type_with_fields *type, int start, |
f49ff000 YQ |
392 | const char *flag_name); |
393 | ||
eee8a18d AH |
394 | /* Add field with VALUE and NAME to the enum TYPE. */ |
395 | void tdesc_add_enum_value (tdesc_type_with_fields *type, int value, | |
396 | const char *name); | |
397 | ||
f49ff000 YQ |
398 | /* Create a register in feature FEATURE. */ |
399 | void tdesc_create_reg (struct tdesc_feature *feature, const char *name, | |
400 | int regnum, int save_restore, const char *group, | |
401 | int bitsize, const char *type); | |
402 | ||
e98577a9 AH |
403 | /* Return the tdesc in string XML format. */ |
404 | ||
405 | const char *tdesc_get_features_xml (const target_desc *tdesc); | |
406 | ||
407 | /* Print target description as xml. */ | |
408 | ||
409 | class print_xml_feature : public tdesc_element_visitor | |
410 | { | |
411 | public: | |
412 | print_xml_feature (std::string *buffer_) | |
caa7fd04 AB |
413 | : m_buffer (buffer_), |
414 | m_depth (0) | |
e98577a9 AH |
415 | {} |
416 | ||
417 | void visit_pre (const target_desc *e) override; | |
418 | void visit_post (const target_desc *e) override; | |
419 | void visit_pre (const tdesc_feature *e) override; | |
420 | void visit_post (const tdesc_feature *e) override; | |
421 | void visit (const tdesc_type_builtin *type) override; | |
422 | void visit (const tdesc_type_vector *type) override; | |
423 | void visit (const tdesc_type_with_fields *type) override; | |
424 | void visit (const tdesc_reg *reg) override; | |
425 | ||
426 | private: | |
caa7fd04 AB |
427 | |
428 | /* Called with a positive value of ADJUST when we move inside an element, | |
429 | for example inside <target>, and with a negative value when we leave | |
430 | the element. In this class this function does nothing, but a | |
431 | sub-class can override this to track the current level of nesting. */ | |
432 | void indent (int adjust) | |
433 | { | |
434 | m_depth += (adjust * 2); | |
435 | } | |
436 | ||
437 | /* Functions to add lines to the output buffer M_BUFFER. Each of these | |
438 | functions appends a newline, so don't include one in the strings being | |
439 | passed. */ | |
440 | void add_line (const std::string &str); | |
441 | void add_line (const char *fmt, ...); | |
442 | ||
443 | /* The buffer we are writing too. */ | |
e98577a9 | 444 | std::string *m_buffer; |
caa7fd04 AB |
445 | |
446 | /* The current indentation depth. */ | |
447 | int m_depth; | |
e98577a9 AH |
448 | }; |
449 | ||
1a5c2598 | 450 | #endif /* COMMON_TDESC_H */ |