Commonise tdesc_feature and makes use of it in gdbserver tdesc
[deliverable/binutils-gdb.git] / gdb / common / tdesc.h
CommitLineData
e2882c85 1/* Copyright (C) 2006-2018 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
18#ifndef ARCH_TDESC_H
19#define ARCH_TDESC_H 1
20
21struct tdesc_feature;
22struct tdesc_type;
d4a0e8b5
SM
23struct tdesc_type_builtin;
24struct tdesc_type_vector;
25struct tdesc_type_with_fields;
f49ff000
YQ
26struct tdesc_reg;
27struct target_desc;
28
ea3e7d71
AH
29/* The interface to visit different elements of target description. */
30
31class tdesc_element_visitor
32{
33public:
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
59class tdesc_element
60{
61public:
62 virtual void accept (tdesc_element_visitor &v) const = 0;
63};
64
65/* An individual register from a target description. */
66
67struct 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
132typedef std::unique_ptr<tdesc_reg> tdesc_reg_up;
133
82ec9bc7
AH
134enum tdesc_type_kind
135{
136 /* Predefined types. */
137 TDESC_TYPE_BOOL,
138 TDESC_TYPE_INT8,
139 TDESC_TYPE_INT16,
140 TDESC_TYPE_INT32,
141 TDESC_TYPE_INT64,
142 TDESC_TYPE_INT128,
143 TDESC_TYPE_UINT8,
144 TDESC_TYPE_UINT16,
145 TDESC_TYPE_UINT32,
146 TDESC_TYPE_UINT64,
147 TDESC_TYPE_UINT128,
148 TDESC_TYPE_CODE_PTR,
149 TDESC_TYPE_DATA_PTR,
150 TDESC_TYPE_IEEE_SINGLE,
151 TDESC_TYPE_IEEE_DOUBLE,
152 TDESC_TYPE_ARM_FPA_EXT,
153 TDESC_TYPE_I387_EXT,
154
155 /* Types defined by a target feature. */
156 TDESC_TYPE_VECTOR,
157 TDESC_TYPE_STRUCT,
158 TDESC_TYPE_UNION,
159 TDESC_TYPE_FLAGS,
160 TDESC_TYPE_ENUM
161};
162
163struct tdesc_type : tdesc_element
164{
165 tdesc_type (const std::string &name_, enum tdesc_type_kind kind_)
166 : name (name_), kind (kind_)
167 {}
168
169 virtual ~tdesc_type () = default;
170
171 DISABLE_COPY_AND_ASSIGN (tdesc_type);
172
173 /* The name of this type. */
174 std::string name;
175
176 /* Identify the kind of this type. */
177 enum tdesc_type_kind kind;
178
179 bool operator== (const tdesc_type &other) const
180 {
181 return name == other.name && kind == other.kind;
182 }
183
184 bool operator!= (const tdesc_type &other) const
185 {
186 return !(*this == other);
187 }
188};
189
190typedef std::unique_ptr<tdesc_type> tdesc_type_up;
191
192/* A feature from a target description. Each feature is a collection
193 of other elements, e.g. registers and types. */
194
195struct tdesc_feature : tdesc_element
196{
197 tdesc_feature (const std::string &name_)
198 : name (name_)
199 {}
200
201 virtual ~tdesc_feature () = default;
202
203 DISABLE_COPY_AND_ASSIGN (tdesc_feature);
204
205 /* The name of this feature. It may be recognized by the architecture
206 support code. */
207 std::string name;
208
209 /* The registers associated with this feature. */
210 std::vector<tdesc_reg_up> registers;
211
212 /* The types associated with this feature. */
213 std::vector<tdesc_type_up> types;
214
215 void accept (tdesc_element_visitor &v) const override;
216
217 bool operator== (const tdesc_feature &other) const;
218
219 bool operator!= (const tdesc_feature &other) const
220 {
221 return !(*this == other);
222 }
223};
224
225typedef std::unique_ptr<tdesc_feature> tdesc_feature_up;
226
5f035c07
YQ
227/* Allocate a new target_desc. */
228target_desc *allocate_target_description (void);
229
230/* Set TARGET_DESC's architecture by NAME. */
231void set_tdesc_architecture (target_desc *target_desc,
232 const char *name);
233
234/* Set TARGET_DESC's osabi by NAME. */
235void set_tdesc_osabi (target_desc *target_desc, const char *name);
236
f49ff000
YQ
237/* Return the type associated with ID in the context of FEATURE, or
238 NULL if none. */
239struct tdesc_type *tdesc_named_type (const struct tdesc_feature *feature,
240 const char *id);
241
242/* Return the created feature named NAME in target description TDESC. */
243struct tdesc_feature *tdesc_create_feature (struct target_desc *tdesc,
0abe8a89
YQ
244 const char *name,
245 const char *xml = nullptr);
246
f49ff000
YQ
247
248/* Return the created vector tdesc_type named NAME in FEATURE. */
249struct tdesc_type *tdesc_create_vector (struct tdesc_feature *feature,
250 const char *name,
251 struct tdesc_type *field_type,
252 int count);
253
254/* Return the created struct tdesc_type named NAME in FEATURE. */
d4a0e8b5
SM
255tdesc_type_with_fields *tdesc_create_struct (struct tdesc_feature *feature,
256 const char *name);
f49ff000
YQ
257
258/* Return the created union tdesc_type named NAME in FEATURE. */
d4a0e8b5
SM
259tdesc_type_with_fields *tdesc_create_union (struct tdesc_feature *feature,
260 const char *name);
f49ff000
YQ
261
262/* Return the created flags tdesc_type named NAME in FEATURE. */
d4a0e8b5
SM
263tdesc_type_with_fields *tdesc_create_flags (struct tdesc_feature *feature,
264 const char *name,
265 int size);
f49ff000
YQ
266
267/* Add a new field to TYPE. FIELD_NAME is its name, and FIELD_TYPE is
268 its type. */
d4a0e8b5 269void tdesc_add_field (tdesc_type_with_fields *type, const char *field_name,
f49ff000
YQ
270 struct tdesc_type *field_type);
271
272/* Set the total length of TYPE. Structs which contain bitfields may
273 omit the reserved bits, so the end of the last field may not
274 suffice. */
d4a0e8b5 275void tdesc_set_struct_size (tdesc_type_with_fields *type, int size);
f49ff000
YQ
276
277/* Add a new untyped bitfield to TYPE.
278 Untyped bitfields become either uint32 or uint64 depending on the size
279 of the underlying type. */
d4a0e8b5 280void tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name,
f49ff000
YQ
281 int start, int end);
282
283/* A flag is just a typed(bool) single-bit bitfield.
284 This function is kept to minimize changes in generated files. */
d4a0e8b5 285void tdesc_add_flag (tdesc_type_with_fields *type, int start,
f49ff000
YQ
286 const char *flag_name);
287
288/* Create a register in feature FEATURE. */
289void tdesc_create_reg (struct tdesc_feature *feature, const char *name,
290 int regnum, int save_restore, const char *group,
291 int bitsize, const char *type);
292
293#endif /* ARCH_TDESC_H */
This page took 0.079979 seconds and 4 git commands to generate.