1 |
227 |
jeremybenn |
/* Target description support for GDB.
|
2 |
|
|
|
3 |
|
|
Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
4 |
|
|
|
5 |
|
|
Contributed by CodeSourcery.
|
6 |
|
|
|
7 |
|
|
This file is part of GDB.
|
8 |
|
|
|
9 |
|
|
This program is free software; you can redistribute it and/or modify
|
10 |
|
|
it under the terms of the GNU General Public License as published by
|
11 |
|
|
the Free Software Foundation; either version 3 of the License, or
|
12 |
|
|
(at your option) any later version.
|
13 |
|
|
|
14 |
|
|
This program is distributed in the hope that it will be useful,
|
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
|
|
GNU General Public License for more details.
|
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU General Public License
|
20 |
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
21 |
|
|
|
22 |
|
|
#include "defs.h"
|
23 |
|
|
#include "arch-utils.h"
|
24 |
|
|
#include "gdbcmd.h"
|
25 |
|
|
#include "gdbtypes.h"
|
26 |
|
|
#include "reggroups.h"
|
27 |
|
|
#include "target.h"
|
28 |
|
|
#include "target-descriptions.h"
|
29 |
|
|
#include "vec.h"
|
30 |
|
|
#include "xml-support.h"
|
31 |
|
|
#include "xml-tdesc.h"
|
32 |
|
|
#include "osabi.h"
|
33 |
|
|
|
34 |
|
|
#include "gdb_assert.h"
|
35 |
|
|
#include "gdb_obstack.h"
|
36 |
|
|
#include "hashtab.h"
|
37 |
|
|
|
38 |
|
|
/* Types. */
|
39 |
|
|
|
40 |
|
|
typedef struct property
|
41 |
|
|
{
|
42 |
|
|
char *key;
|
43 |
|
|
char *value;
|
44 |
|
|
} property_s;
|
45 |
|
|
DEF_VEC_O(property_s);
|
46 |
|
|
|
47 |
|
|
/* An individual register from a target description. */
|
48 |
|
|
|
49 |
|
|
typedef struct tdesc_reg
|
50 |
|
|
{
|
51 |
|
|
/* The name of this register. In standard features, it may be
|
52 |
|
|
recognized by the architecture support code, or it may be purely
|
53 |
|
|
for the user. */
|
54 |
|
|
char *name;
|
55 |
|
|
|
56 |
|
|
/* The register number used by this target to refer to this
|
57 |
|
|
register. This is used for remote p/P packets and to determine
|
58 |
|
|
the ordering of registers in the remote g/G packets. */
|
59 |
|
|
long target_regnum;
|
60 |
|
|
|
61 |
|
|
/* If this flag is set, GDB should save and restore this register
|
62 |
|
|
around calls to an inferior function. */
|
63 |
|
|
int save_restore;
|
64 |
|
|
|
65 |
|
|
/* The name of the register group containing this register, or NULL
|
66 |
|
|
if the group should be automatically determined from the
|
67 |
|
|
register's type. If this is "general", "float", or "vector", the
|
68 |
|
|
corresponding "info" command should display this register's
|
69 |
|
|
value. It can be an arbitrary string, but should be limited to
|
70 |
|
|
alphanumeric characters and internal hyphens. Currently other
|
71 |
|
|
strings are ignored (treated as NULL). */
|
72 |
|
|
char *group;
|
73 |
|
|
|
74 |
|
|
/* The size of the register, in bits. */
|
75 |
|
|
int bitsize;
|
76 |
|
|
|
77 |
|
|
/* The type of the register. This string corresponds to either
|
78 |
|
|
a named type from the target description or a predefined
|
79 |
|
|
type from GDB. */
|
80 |
|
|
char *type;
|
81 |
|
|
|
82 |
|
|
/* The target-described type corresponding to TYPE, if found. */
|
83 |
|
|
struct tdesc_type *tdesc_type;
|
84 |
|
|
} *tdesc_reg_p;
|
85 |
|
|
DEF_VEC_P(tdesc_reg_p);
|
86 |
|
|
|
87 |
|
|
/* A named type from a target description. */
|
88 |
|
|
|
89 |
|
|
typedef struct tdesc_type_field
|
90 |
|
|
{
|
91 |
|
|
char *name;
|
92 |
|
|
struct tdesc_type *type;
|
93 |
|
|
} tdesc_type_field;
|
94 |
|
|
DEF_VEC_O(tdesc_type_field);
|
95 |
|
|
|
96 |
|
|
typedef struct tdesc_type
|
97 |
|
|
{
|
98 |
|
|
/* The name of this type. */
|
99 |
|
|
char *name;
|
100 |
|
|
|
101 |
|
|
/* Identify the kind of this type. */
|
102 |
|
|
enum
|
103 |
|
|
{
|
104 |
|
|
/* Predefined types. */
|
105 |
|
|
TDESC_TYPE_INT8,
|
106 |
|
|
TDESC_TYPE_INT16,
|
107 |
|
|
TDESC_TYPE_INT32,
|
108 |
|
|
TDESC_TYPE_INT64,
|
109 |
|
|
TDESC_TYPE_INT128,
|
110 |
|
|
TDESC_TYPE_UINT8,
|
111 |
|
|
TDESC_TYPE_UINT16,
|
112 |
|
|
TDESC_TYPE_UINT32,
|
113 |
|
|
TDESC_TYPE_UINT64,
|
114 |
|
|
TDESC_TYPE_UINT128,
|
115 |
|
|
TDESC_TYPE_CODE_PTR,
|
116 |
|
|
TDESC_TYPE_DATA_PTR,
|
117 |
|
|
TDESC_TYPE_IEEE_SINGLE,
|
118 |
|
|
TDESC_TYPE_IEEE_DOUBLE,
|
119 |
|
|
TDESC_TYPE_ARM_FPA_EXT,
|
120 |
|
|
TDESC_TYPE_I387_EXT,
|
121 |
|
|
TDESC_TYPE_I386_EFLAGS,
|
122 |
|
|
TDESC_TYPE_I386_MXCSR,
|
123 |
|
|
|
124 |
|
|
/* Types defined by a target feature. */
|
125 |
|
|
TDESC_TYPE_VECTOR,
|
126 |
|
|
TDESC_TYPE_UNION
|
127 |
|
|
} kind;
|
128 |
|
|
|
129 |
|
|
/* Kind-specific data. */
|
130 |
|
|
union
|
131 |
|
|
{
|
132 |
|
|
/* Vector type. */
|
133 |
|
|
struct
|
134 |
|
|
{
|
135 |
|
|
struct tdesc_type *type;
|
136 |
|
|
int count;
|
137 |
|
|
} v;
|
138 |
|
|
|
139 |
|
|
/* Union type. */
|
140 |
|
|
struct
|
141 |
|
|
{
|
142 |
|
|
VEC(tdesc_type_field) *fields;
|
143 |
|
|
} u;
|
144 |
|
|
} u;
|
145 |
|
|
} *tdesc_type_p;
|
146 |
|
|
DEF_VEC_P(tdesc_type_p);
|
147 |
|
|
|
148 |
|
|
/* A feature from a target description. Each feature is a collection
|
149 |
|
|
of other elements, e.g. registers and types. */
|
150 |
|
|
|
151 |
|
|
typedef struct tdesc_feature
|
152 |
|
|
{
|
153 |
|
|
/* The name of this feature. It may be recognized by the architecture
|
154 |
|
|
support code. */
|
155 |
|
|
char *name;
|
156 |
|
|
|
157 |
|
|
/* The registers associated with this feature. */
|
158 |
|
|
VEC(tdesc_reg_p) *registers;
|
159 |
|
|
|
160 |
|
|
/* The types associated with this feature. */
|
161 |
|
|
VEC(tdesc_type_p) *types;
|
162 |
|
|
} *tdesc_feature_p;
|
163 |
|
|
DEF_VEC_P(tdesc_feature_p);
|
164 |
|
|
|
165 |
|
|
/* A compatible architecture from a target description. */
|
166 |
|
|
typedef const struct bfd_arch_info *arch_p;
|
167 |
|
|
DEF_VEC_P(arch_p);
|
168 |
|
|
|
169 |
|
|
/* A target description. */
|
170 |
|
|
|
171 |
|
|
struct target_desc
|
172 |
|
|
{
|
173 |
|
|
/* The architecture reported by the target, if any. */
|
174 |
|
|
const struct bfd_arch_info *arch;
|
175 |
|
|
|
176 |
|
|
/* The osabi reported by the target, if any; GDB_OSABI_UNKNOWN
|
177 |
|
|
otherwise. */
|
178 |
|
|
enum gdb_osabi osabi;
|
179 |
|
|
|
180 |
|
|
/* The list of compatible architectures reported by the target. */
|
181 |
|
|
VEC(arch_p) *compatible;
|
182 |
|
|
|
183 |
|
|
/* Any architecture-specific properties specified by the target. */
|
184 |
|
|
VEC(property_s) *properties;
|
185 |
|
|
|
186 |
|
|
/* The features associated with this target. */
|
187 |
|
|
VEC(tdesc_feature_p) *features;
|
188 |
|
|
};
|
189 |
|
|
|
190 |
|
|
/* Per-architecture data associated with a target description. The
|
191 |
|
|
target description may be shared by multiple architectures, but
|
192 |
|
|
this data is private to one gdbarch. */
|
193 |
|
|
|
194 |
|
|
typedef struct tdesc_arch_reg
|
195 |
|
|
{
|
196 |
|
|
struct tdesc_reg *reg;
|
197 |
|
|
struct type *type;
|
198 |
|
|
} tdesc_arch_reg;
|
199 |
|
|
DEF_VEC_O(tdesc_arch_reg);
|
200 |
|
|
|
201 |
|
|
struct tdesc_arch_data
|
202 |
|
|
{
|
203 |
|
|
/* A list of register/type pairs, indexed by GDB's internal register number.
|
204 |
|
|
During initialization of the gdbarch this list is used to store
|
205 |
|
|
registers which the architecture assigns a fixed register number.
|
206 |
|
|
Registers which are NULL in this array, or off the end, are
|
207 |
|
|
treated as zero-sized and nameless (i.e. placeholders in the
|
208 |
|
|
numbering). */
|
209 |
|
|
VEC(tdesc_arch_reg) *arch_regs;
|
210 |
|
|
|
211 |
|
|
/* Functions which report the register name, type, and reggroups for
|
212 |
|
|
pseudo-registers. */
|
213 |
|
|
gdbarch_register_name_ftype *pseudo_register_name;
|
214 |
|
|
gdbarch_register_type_ftype *pseudo_register_type;
|
215 |
|
|
gdbarch_register_reggroup_p_ftype *pseudo_register_reggroup_p;
|
216 |
|
|
};
|
217 |
|
|
|
218 |
|
|
/* Global state. These variables are associated with the current
|
219 |
|
|
target; if GDB adds support for multiple simultaneous targets, then
|
220 |
|
|
these variables should become target-specific data. */
|
221 |
|
|
|
222 |
|
|
/* A flag indicating that a description has already been fetched from
|
223 |
|
|
the current target, so it should not be queried again. */
|
224 |
|
|
|
225 |
|
|
static int target_desc_fetched;
|
226 |
|
|
|
227 |
|
|
/* The description fetched from the current target, or NULL if the
|
228 |
|
|
current target did not supply any description. Only valid when
|
229 |
|
|
target_desc_fetched is set. Only the description initialization
|
230 |
|
|
code should access this; normally, the description should be
|
231 |
|
|
accessed through the gdbarch object. */
|
232 |
|
|
|
233 |
|
|
static const struct target_desc *current_target_desc;
|
234 |
|
|
|
235 |
|
|
/* Other global variables. */
|
236 |
|
|
|
237 |
|
|
/* The filename to read a target description from. */
|
238 |
|
|
|
239 |
|
|
static char *target_description_filename;
|
240 |
|
|
|
241 |
|
|
/* A handle for architecture-specific data associated with the
|
242 |
|
|
target description (see struct tdesc_arch_data). */
|
243 |
|
|
|
244 |
|
|
static struct gdbarch_data *tdesc_data;
|
245 |
|
|
|
246 |
|
|
/* Fetch the current target's description, and switch the current
|
247 |
|
|
architecture to one which incorporates that description. */
|
248 |
|
|
|
249 |
|
|
void
|
250 |
|
|
target_find_description (void)
|
251 |
|
|
{
|
252 |
|
|
/* If we've already fetched a description from the target, don't do
|
253 |
|
|
it again. This allows a target to fetch the description early,
|
254 |
|
|
during its to_open or to_create_inferior, if it needs extra
|
255 |
|
|
information about the target to initialize. */
|
256 |
|
|
if (target_desc_fetched)
|
257 |
|
|
return;
|
258 |
|
|
|
259 |
|
|
/* The current architecture should not have any target description
|
260 |
|
|
specified. It should have been cleared, e.g. when we
|
261 |
|
|
disconnected from the previous target. */
|
262 |
|
|
gdb_assert (gdbarch_target_desc (target_gdbarch) == NULL);
|
263 |
|
|
|
264 |
|
|
/* First try to fetch an XML description from the user-specified
|
265 |
|
|
file. */
|
266 |
|
|
current_target_desc = NULL;
|
267 |
|
|
if (target_description_filename != NULL
|
268 |
|
|
&& *target_description_filename != '\0')
|
269 |
|
|
current_target_desc
|
270 |
|
|
= file_read_description_xml (target_description_filename);
|
271 |
|
|
|
272 |
|
|
/* Next try to read the description from the current target using
|
273 |
|
|
target objects. */
|
274 |
|
|
if (current_target_desc == NULL)
|
275 |
|
|
current_target_desc = target_read_description_xml (¤t_target);
|
276 |
|
|
|
277 |
|
|
/* If that failed try a target-specific hook. */
|
278 |
|
|
if (current_target_desc == NULL)
|
279 |
|
|
current_target_desc = target_read_description (¤t_target);
|
280 |
|
|
|
281 |
|
|
/* If a non-NULL description was returned, then update the current
|
282 |
|
|
architecture. */
|
283 |
|
|
if (current_target_desc)
|
284 |
|
|
{
|
285 |
|
|
struct gdbarch_info info;
|
286 |
|
|
|
287 |
|
|
gdbarch_info_init (&info);
|
288 |
|
|
info.target_desc = current_target_desc;
|
289 |
|
|
if (!gdbarch_update_p (info))
|
290 |
|
|
warning (_("Architecture rejected target-supplied description"));
|
291 |
|
|
else
|
292 |
|
|
{
|
293 |
|
|
struct tdesc_arch_data *data;
|
294 |
|
|
|
295 |
|
|
data = gdbarch_data (target_gdbarch, tdesc_data);
|
296 |
|
|
if (tdesc_has_registers (current_target_desc)
|
297 |
|
|
&& data->arch_regs == NULL)
|
298 |
|
|
warning (_("Target-supplied registers are not supported "
|
299 |
|
|
"by the current architecture"));
|
300 |
|
|
}
|
301 |
|
|
}
|
302 |
|
|
|
303 |
|
|
/* Now that we know this description is usable, record that we
|
304 |
|
|
fetched it. */
|
305 |
|
|
target_desc_fetched = 1;
|
306 |
|
|
}
|
307 |
|
|
|
308 |
|
|
/* Discard any description fetched from the current target, and switch
|
309 |
|
|
the current architecture to one with no target description. */
|
310 |
|
|
|
311 |
|
|
void
|
312 |
|
|
target_clear_description (void)
|
313 |
|
|
{
|
314 |
|
|
struct gdbarch_info info;
|
315 |
|
|
|
316 |
|
|
if (!target_desc_fetched)
|
317 |
|
|
return;
|
318 |
|
|
|
319 |
|
|
target_desc_fetched = 0;
|
320 |
|
|
current_target_desc = NULL;
|
321 |
|
|
|
322 |
|
|
gdbarch_info_init (&info);
|
323 |
|
|
if (!gdbarch_update_p (info))
|
324 |
|
|
internal_error (__FILE__, __LINE__,
|
325 |
|
|
_("Could not remove target-supplied description"));
|
326 |
|
|
}
|
327 |
|
|
|
328 |
|
|
/* Return the global current target description. This should only be
|
329 |
|
|
used by gdbarch initialization code; most access should be through
|
330 |
|
|
an existing gdbarch. */
|
331 |
|
|
|
332 |
|
|
const struct target_desc *
|
333 |
|
|
target_current_description (void)
|
334 |
|
|
{
|
335 |
|
|
if (target_desc_fetched)
|
336 |
|
|
return current_target_desc;
|
337 |
|
|
|
338 |
|
|
return NULL;
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
/* Return non-zero if this target description is compatible
|
342 |
|
|
with the given BFD architecture. */
|
343 |
|
|
|
344 |
|
|
int
|
345 |
|
|
tdesc_compatible_p (const struct target_desc *target_desc,
|
346 |
|
|
const struct bfd_arch_info *arch)
|
347 |
|
|
{
|
348 |
|
|
const struct bfd_arch_info *compat;
|
349 |
|
|
int ix;
|
350 |
|
|
|
351 |
|
|
for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
|
352 |
|
|
ix++)
|
353 |
|
|
{
|
354 |
|
|
if (compat == arch
|
355 |
|
|
|| arch->compatible (arch, compat)
|
356 |
|
|
|| compat->compatible (compat, arch))
|
357 |
|
|
return 1;
|
358 |
|
|
}
|
359 |
|
|
|
360 |
|
|
return 0;
|
361 |
|
|
}
|
362 |
|
|
|
363 |
|
|
|
364 |
|
|
/* Direct accessors for target descriptions. */
|
365 |
|
|
|
366 |
|
|
/* Return the string value of a property named KEY, or NULL if the
|
367 |
|
|
property was not specified. */
|
368 |
|
|
|
369 |
|
|
const char *
|
370 |
|
|
tdesc_property (const struct target_desc *target_desc, const char *key)
|
371 |
|
|
{
|
372 |
|
|
struct property *prop;
|
373 |
|
|
int ix;
|
374 |
|
|
|
375 |
|
|
for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
|
376 |
|
|
ix++)
|
377 |
|
|
if (strcmp (prop->key, key) == 0)
|
378 |
|
|
return prop->value;
|
379 |
|
|
|
380 |
|
|
return NULL;
|
381 |
|
|
}
|
382 |
|
|
|
383 |
|
|
/* Return the BFD architecture associated with this target
|
384 |
|
|
description, or NULL if no architecture was specified. */
|
385 |
|
|
|
386 |
|
|
const struct bfd_arch_info *
|
387 |
|
|
tdesc_architecture (const struct target_desc *target_desc)
|
388 |
|
|
{
|
389 |
|
|
return target_desc->arch;
|
390 |
|
|
}
|
391 |
|
|
|
392 |
|
|
/* Return the OSABI associated with this target description, or
|
393 |
|
|
GDB_OSABI_UNKNOWN if no osabi was specified. */
|
394 |
|
|
|
395 |
|
|
enum gdb_osabi
|
396 |
|
|
tdesc_osabi (const struct target_desc *target_desc)
|
397 |
|
|
{
|
398 |
|
|
return target_desc->osabi;
|
399 |
|
|
}
|
400 |
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
|
|
/* Return 1 if this target description includes any registers. */
|
404 |
|
|
|
405 |
|
|
int
|
406 |
|
|
tdesc_has_registers (const struct target_desc *target_desc)
|
407 |
|
|
{
|
408 |
|
|
int ix;
|
409 |
|
|
struct tdesc_feature *feature;
|
410 |
|
|
|
411 |
|
|
if (target_desc == NULL)
|
412 |
|
|
return 0;
|
413 |
|
|
|
414 |
|
|
for (ix = 0;
|
415 |
|
|
VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
|
416 |
|
|
ix++)
|
417 |
|
|
if (! VEC_empty (tdesc_reg_p, feature->registers))
|
418 |
|
|
return 1;
|
419 |
|
|
|
420 |
|
|
return 0;
|
421 |
|
|
}
|
422 |
|
|
|
423 |
|
|
/* Return the feature with the given name, if present, or NULL if
|
424 |
|
|
the named feature is not found. */
|
425 |
|
|
|
426 |
|
|
const struct tdesc_feature *
|
427 |
|
|
tdesc_find_feature (const struct target_desc *target_desc,
|
428 |
|
|
const char *name)
|
429 |
|
|
{
|
430 |
|
|
int ix;
|
431 |
|
|
struct tdesc_feature *feature;
|
432 |
|
|
|
433 |
|
|
for (ix = 0;
|
434 |
|
|
VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
|
435 |
|
|
ix++)
|
436 |
|
|
if (strcmp (feature->name, name) == 0)
|
437 |
|
|
return feature;
|
438 |
|
|
|
439 |
|
|
return NULL;
|
440 |
|
|
}
|
441 |
|
|
|
442 |
|
|
/* Return the name of FEATURE. */
|
443 |
|
|
|
444 |
|
|
const char *
|
445 |
|
|
tdesc_feature_name (const struct tdesc_feature *feature)
|
446 |
|
|
{
|
447 |
|
|
return feature->name;
|
448 |
|
|
}
|
449 |
|
|
|
450 |
|
|
/* Predefined types. */
|
451 |
|
|
static struct tdesc_type tdesc_predefined_types[] =
|
452 |
|
|
{
|
453 |
|
|
{ "int8", TDESC_TYPE_INT8 },
|
454 |
|
|
{ "int16", TDESC_TYPE_INT16 },
|
455 |
|
|
{ "int32", TDESC_TYPE_INT32 },
|
456 |
|
|
{ "int64", TDESC_TYPE_INT64 },
|
457 |
|
|
{ "int128", TDESC_TYPE_INT128 },
|
458 |
|
|
{ "uint8", TDESC_TYPE_UINT8 },
|
459 |
|
|
{ "uint16", TDESC_TYPE_UINT16 },
|
460 |
|
|
{ "uint32", TDESC_TYPE_UINT32 },
|
461 |
|
|
{ "uint64", TDESC_TYPE_UINT64 },
|
462 |
|
|
{ "uint128", TDESC_TYPE_UINT128 },
|
463 |
|
|
{ "code_ptr", TDESC_TYPE_CODE_PTR },
|
464 |
|
|
{ "data_ptr", TDESC_TYPE_DATA_PTR },
|
465 |
|
|
{ "ieee_single", TDESC_TYPE_IEEE_SINGLE },
|
466 |
|
|
{ "ieee_double", TDESC_TYPE_IEEE_DOUBLE },
|
467 |
|
|
{ "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT },
|
468 |
|
|
{ "i387_ext", TDESC_TYPE_I387_EXT },
|
469 |
|
|
{ "i386_eflags", TDESC_TYPE_I386_EFLAGS },
|
470 |
|
|
{ "i386_mxcsr", TDESC_TYPE_I386_MXCSR }
|
471 |
|
|
};
|
472 |
|
|
|
473 |
|
|
/* Return the type associated with ID in the context of FEATURE, or
|
474 |
|
|
NULL if none. */
|
475 |
|
|
|
476 |
|
|
struct tdesc_type *
|
477 |
|
|
tdesc_named_type (const struct tdesc_feature *feature, const char *id)
|
478 |
|
|
{
|
479 |
|
|
int ix;
|
480 |
|
|
struct tdesc_type *type;
|
481 |
|
|
|
482 |
|
|
/* First try target-defined types. */
|
483 |
|
|
for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
|
484 |
|
|
if (strcmp (type->name, id) == 0)
|
485 |
|
|
return type;
|
486 |
|
|
|
487 |
|
|
/* Next try the predefined types. */
|
488 |
|
|
for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
|
489 |
|
|
if (strcmp (tdesc_predefined_types[ix].name, id) == 0)
|
490 |
|
|
return &tdesc_predefined_types[ix];
|
491 |
|
|
|
492 |
|
|
return NULL;
|
493 |
|
|
}
|
494 |
|
|
|
495 |
|
|
/* Lookup type associated with ID. */
|
496 |
|
|
|
497 |
|
|
struct type *
|
498 |
|
|
tdesc_find_type (struct gdbarch *gdbarch, const char *id)
|
499 |
|
|
{
|
500 |
|
|
struct tdesc_arch_reg *reg;
|
501 |
|
|
struct tdesc_arch_data *data;
|
502 |
|
|
int i, num_regs;
|
503 |
|
|
|
504 |
|
|
data = gdbarch_data (gdbarch, tdesc_data);
|
505 |
|
|
num_regs = VEC_length (tdesc_arch_reg, data->arch_regs);
|
506 |
|
|
for (i = 0; i < num_regs; i++)
|
507 |
|
|
{
|
508 |
|
|
reg = VEC_index (tdesc_arch_reg, data->arch_regs, i);
|
509 |
|
|
if (reg->reg
|
510 |
|
|
&& reg->reg->tdesc_type
|
511 |
|
|
&& reg->type
|
512 |
|
|
&& strcmp (id, reg->reg->tdesc_type->name) == 0)
|
513 |
|
|
return reg->type;
|
514 |
|
|
}
|
515 |
|
|
|
516 |
|
|
return NULL;
|
517 |
|
|
}
|
518 |
|
|
|
519 |
|
|
/* Construct, if necessary, and return the GDB type implementing target
|
520 |
|
|
type TDESC_TYPE for architecture GDBARCH. */
|
521 |
|
|
|
522 |
|
|
static struct type *
|
523 |
|
|
tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
|
524 |
|
|
{
|
525 |
|
|
struct type *type;
|
526 |
|
|
|
527 |
|
|
switch (tdesc_type->kind)
|
528 |
|
|
{
|
529 |
|
|
/* Predefined types. */
|
530 |
|
|
case TDESC_TYPE_INT8:
|
531 |
|
|
return builtin_type (gdbarch)->builtin_int8;
|
532 |
|
|
|
533 |
|
|
case TDESC_TYPE_INT16:
|
534 |
|
|
return builtin_type (gdbarch)->builtin_int16;
|
535 |
|
|
|
536 |
|
|
case TDESC_TYPE_INT32:
|
537 |
|
|
return builtin_type (gdbarch)->builtin_int32;
|
538 |
|
|
|
539 |
|
|
case TDESC_TYPE_INT64:
|
540 |
|
|
return builtin_type (gdbarch)->builtin_int64;
|
541 |
|
|
|
542 |
|
|
case TDESC_TYPE_INT128:
|
543 |
|
|
return builtin_type (gdbarch)->builtin_int128;
|
544 |
|
|
|
545 |
|
|
case TDESC_TYPE_UINT8:
|
546 |
|
|
return builtin_type (gdbarch)->builtin_uint8;
|
547 |
|
|
|
548 |
|
|
case TDESC_TYPE_UINT16:
|
549 |
|
|
return builtin_type (gdbarch)->builtin_uint16;
|
550 |
|
|
|
551 |
|
|
case TDESC_TYPE_UINT32:
|
552 |
|
|
return builtin_type (gdbarch)->builtin_uint32;
|
553 |
|
|
|
554 |
|
|
case TDESC_TYPE_UINT64:
|
555 |
|
|
return builtin_type (gdbarch)->builtin_uint64;
|
556 |
|
|
|
557 |
|
|
case TDESC_TYPE_UINT128:
|
558 |
|
|
return builtin_type (gdbarch)->builtin_uint128;
|
559 |
|
|
|
560 |
|
|
case TDESC_TYPE_CODE_PTR:
|
561 |
|
|
return builtin_type (gdbarch)->builtin_func_ptr;
|
562 |
|
|
|
563 |
|
|
case TDESC_TYPE_DATA_PTR:
|
564 |
|
|
return builtin_type (gdbarch)->builtin_data_ptr;
|
565 |
|
|
|
566 |
|
|
default:
|
567 |
|
|
break;
|
568 |
|
|
}
|
569 |
|
|
|
570 |
|
|
type = tdesc_find_type (gdbarch, tdesc_type->name);
|
571 |
|
|
if (type)
|
572 |
|
|
return type;
|
573 |
|
|
|
574 |
|
|
switch (tdesc_type->kind)
|
575 |
|
|
{
|
576 |
|
|
case TDESC_TYPE_IEEE_SINGLE:
|
577 |
|
|
return arch_float_type (gdbarch, -1, "builtin_type_ieee_single",
|
578 |
|
|
floatformats_ieee_single);
|
579 |
|
|
|
580 |
|
|
case TDESC_TYPE_IEEE_DOUBLE:
|
581 |
|
|
return arch_float_type (gdbarch, -1, "builtin_type_ieee_double",
|
582 |
|
|
floatformats_ieee_double);
|
583 |
|
|
|
584 |
|
|
case TDESC_TYPE_ARM_FPA_EXT:
|
585 |
|
|
return arch_float_type (gdbarch, -1, "builtin_type_arm_ext",
|
586 |
|
|
floatformats_arm_ext);
|
587 |
|
|
|
588 |
|
|
case TDESC_TYPE_I387_EXT:
|
589 |
|
|
return arch_float_type (gdbarch, -1, "builtin_type_i387_ext",
|
590 |
|
|
floatformats_i387_ext);
|
591 |
|
|
|
592 |
|
|
case TDESC_TYPE_I386_EFLAGS:
|
593 |
|
|
{
|
594 |
|
|
struct type *type;
|
595 |
|
|
|
596 |
|
|
type = arch_flags_type (gdbarch, "builtin_type_i386_eflags", 4);
|
597 |
|
|
append_flags_type_flag (type, 0, "CF");
|
598 |
|
|
append_flags_type_flag (type, 1, NULL);
|
599 |
|
|
append_flags_type_flag (type, 2, "PF");
|
600 |
|
|
append_flags_type_flag (type, 4, "AF");
|
601 |
|
|
append_flags_type_flag (type, 6, "ZF");
|
602 |
|
|
append_flags_type_flag (type, 7, "SF");
|
603 |
|
|
append_flags_type_flag (type, 8, "TF");
|
604 |
|
|
append_flags_type_flag (type, 9, "IF");
|
605 |
|
|
append_flags_type_flag (type, 10, "DF");
|
606 |
|
|
append_flags_type_flag (type, 11, "OF");
|
607 |
|
|
append_flags_type_flag (type, 14, "NT");
|
608 |
|
|
append_flags_type_flag (type, 16, "RF");
|
609 |
|
|
append_flags_type_flag (type, 17, "VM");
|
610 |
|
|
append_flags_type_flag (type, 18, "AC");
|
611 |
|
|
append_flags_type_flag (type, 19, "VIF");
|
612 |
|
|
append_flags_type_flag (type, 20, "VIP");
|
613 |
|
|
append_flags_type_flag (type, 21, "ID");
|
614 |
|
|
|
615 |
|
|
return type;
|
616 |
|
|
}
|
617 |
|
|
break;
|
618 |
|
|
|
619 |
|
|
case TDESC_TYPE_I386_MXCSR:
|
620 |
|
|
{
|
621 |
|
|
struct type *type;
|
622 |
|
|
|
623 |
|
|
type = arch_flags_type (gdbarch, "builtin_type_i386_mxcsr", 4);
|
624 |
|
|
append_flags_type_flag (type, 0, "IE");
|
625 |
|
|
append_flags_type_flag (type, 1, "DE");
|
626 |
|
|
append_flags_type_flag (type, 2, "ZE");
|
627 |
|
|
append_flags_type_flag (type, 3, "OE");
|
628 |
|
|
append_flags_type_flag (type, 4, "UE");
|
629 |
|
|
append_flags_type_flag (type, 5, "PE");
|
630 |
|
|
append_flags_type_flag (type, 6, "DAZ");
|
631 |
|
|
append_flags_type_flag (type, 7, "IM");
|
632 |
|
|
append_flags_type_flag (type, 8, "DM");
|
633 |
|
|
append_flags_type_flag (type, 9, "ZM");
|
634 |
|
|
append_flags_type_flag (type, 10, "OM");
|
635 |
|
|
append_flags_type_flag (type, 11, "UM");
|
636 |
|
|
append_flags_type_flag (type, 12, "PM");
|
637 |
|
|
append_flags_type_flag (type, 15, "FZ");
|
638 |
|
|
|
639 |
|
|
return type;
|
640 |
|
|
}
|
641 |
|
|
break;
|
642 |
|
|
|
643 |
|
|
/* Types defined by a target feature. */
|
644 |
|
|
case TDESC_TYPE_VECTOR:
|
645 |
|
|
{
|
646 |
|
|
struct type *type, *field_type;
|
647 |
|
|
|
648 |
|
|
field_type = tdesc_gdb_type (gdbarch, tdesc_type->u.v.type);
|
649 |
|
|
type = init_vector_type (field_type, tdesc_type->u.v.count);
|
650 |
|
|
TYPE_NAME (type) = xstrdup (tdesc_type->name);
|
651 |
|
|
|
652 |
|
|
return type;
|
653 |
|
|
}
|
654 |
|
|
|
655 |
|
|
case TDESC_TYPE_UNION:
|
656 |
|
|
{
|
657 |
|
|
struct type *type, *field_type;
|
658 |
|
|
struct tdesc_type_field *f;
|
659 |
|
|
int ix;
|
660 |
|
|
|
661 |
|
|
type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
|
662 |
|
|
TYPE_NAME (type) = xstrdup (tdesc_type->name);
|
663 |
|
|
|
664 |
|
|
for (ix = 0;
|
665 |
|
|
VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
|
666 |
|
|
ix++)
|
667 |
|
|
{
|
668 |
|
|
field_type = tdesc_gdb_type (gdbarch, f->type);
|
669 |
|
|
append_composite_type_field (type, xstrdup (f->name), field_type);
|
670 |
|
|
|
671 |
|
|
/* If any of the children of this union are vectors, flag the
|
672 |
|
|
union as a vector also. This allows e.g. a union of two
|
673 |
|
|
vector types to show up automatically in "info vector". */
|
674 |
|
|
if (TYPE_VECTOR (field_type))
|
675 |
|
|
TYPE_VECTOR (type) = 1;
|
676 |
|
|
}
|
677 |
|
|
|
678 |
|
|
return type;
|
679 |
|
|
}
|
680 |
|
|
}
|
681 |
|
|
|
682 |
|
|
internal_error (__FILE__, __LINE__,
|
683 |
|
|
"Type \"%s\" has an unknown kind %d",
|
684 |
|
|
tdesc_type->name, tdesc_type->kind);
|
685 |
|
|
}
|
686 |
|
|
|
687 |
|
|
|
688 |
|
|
/* Support for registers from target descriptions. */
|
689 |
|
|
|
690 |
|
|
/* Construct the per-gdbarch data. */
|
691 |
|
|
|
692 |
|
|
static void *
|
693 |
|
|
tdesc_data_init (struct obstack *obstack)
|
694 |
|
|
{
|
695 |
|
|
struct tdesc_arch_data *data;
|
696 |
|
|
|
697 |
|
|
data = OBSTACK_ZALLOC (obstack, struct tdesc_arch_data);
|
698 |
|
|
return data;
|
699 |
|
|
}
|
700 |
|
|
|
701 |
|
|
/* Similar, but for the temporary copy used during architecture
|
702 |
|
|
initialization. */
|
703 |
|
|
|
704 |
|
|
struct tdesc_arch_data *
|
705 |
|
|
tdesc_data_alloc (void)
|
706 |
|
|
{
|
707 |
|
|
return XZALLOC (struct tdesc_arch_data);
|
708 |
|
|
}
|
709 |
|
|
|
710 |
|
|
/* Free something allocated by tdesc_data_alloc, if it is not going
|
711 |
|
|
to be used (for instance if it was unsuitable for the
|
712 |
|
|
architecture). */
|
713 |
|
|
|
714 |
|
|
void
|
715 |
|
|
tdesc_data_cleanup (void *data_untyped)
|
716 |
|
|
{
|
717 |
|
|
struct tdesc_arch_data *data = data_untyped;
|
718 |
|
|
|
719 |
|
|
VEC_free (tdesc_arch_reg, data->arch_regs);
|
720 |
|
|
xfree (data);
|
721 |
|
|
}
|
722 |
|
|
|
723 |
|
|
/* Search FEATURE for a register named NAME. */
|
724 |
|
|
|
725 |
|
|
static struct tdesc_reg *
|
726 |
|
|
tdesc_find_register_early (const struct tdesc_feature *feature,
|
727 |
|
|
const char *name)
|
728 |
|
|
{
|
729 |
|
|
int ixr;
|
730 |
|
|
struct tdesc_reg *reg;
|
731 |
|
|
|
732 |
|
|
for (ixr = 0;
|
733 |
|
|
VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
|
734 |
|
|
ixr++)
|
735 |
|
|
if (strcasecmp (reg->name, name) == 0)
|
736 |
|
|
return reg;
|
737 |
|
|
|
738 |
|
|
return NULL;
|
739 |
|
|
}
|
740 |
|
|
|
741 |
|
|
/* Search FEATURE for a register named NAME. Assign REGNO to it. */
|
742 |
|
|
|
743 |
|
|
int
|
744 |
|
|
tdesc_numbered_register (const struct tdesc_feature *feature,
|
745 |
|
|
struct tdesc_arch_data *data,
|
746 |
|
|
int regno, const char *name)
|
747 |
|
|
{
|
748 |
|
|
struct tdesc_arch_reg arch_reg = { 0 };
|
749 |
|
|
struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
|
750 |
|
|
|
751 |
|
|
if (reg == NULL)
|
752 |
|
|
return 0;
|
753 |
|
|
|
754 |
|
|
/* Make sure the vector includes a REGNO'th element. */
|
755 |
|
|
while (regno >= VEC_length (tdesc_arch_reg, data->arch_regs))
|
756 |
|
|
VEC_safe_push (tdesc_arch_reg, data->arch_regs, &arch_reg);
|
757 |
|
|
|
758 |
|
|
arch_reg.reg = reg;
|
759 |
|
|
VEC_replace (tdesc_arch_reg, data->arch_regs, regno, &arch_reg);
|
760 |
|
|
return 1;
|
761 |
|
|
}
|
762 |
|
|
|
763 |
|
|
/* Search FEATURE for a register named NAME, but do not assign a fixed
|
764 |
|
|
register number to it. */
|
765 |
|
|
|
766 |
|
|
int
|
767 |
|
|
tdesc_unnumbered_register (const struct tdesc_feature *feature,
|
768 |
|
|
const char *name)
|
769 |
|
|
{
|
770 |
|
|
struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
|
771 |
|
|
|
772 |
|
|
if (reg == NULL)
|
773 |
|
|
return 0;
|
774 |
|
|
|
775 |
|
|
return 1;
|
776 |
|
|
}
|
777 |
|
|
|
778 |
|
|
/* Search FEATURE for a register whose name is in NAMES and assign
|
779 |
|
|
REGNO to it. */
|
780 |
|
|
|
781 |
|
|
int
|
782 |
|
|
tdesc_numbered_register_choices (const struct tdesc_feature *feature,
|
783 |
|
|
struct tdesc_arch_data *data,
|
784 |
|
|
int regno, const char *const names[])
|
785 |
|
|
{
|
786 |
|
|
int i;
|
787 |
|
|
|
788 |
|
|
for (i = 0; names[i] != NULL; i++)
|
789 |
|
|
if (tdesc_numbered_register (feature, data, regno, names[i]))
|
790 |
|
|
return 1;
|
791 |
|
|
|
792 |
|
|
return 0;
|
793 |
|
|
}
|
794 |
|
|
|
795 |
|
|
/* Search FEATURE for a register named NAME, and return its size in
|
796 |
|
|
bits. The register must exist. */
|
797 |
|
|
|
798 |
|
|
int
|
799 |
|
|
tdesc_register_size (const struct tdesc_feature *feature,
|
800 |
|
|
const char *name)
|
801 |
|
|
{
|
802 |
|
|
struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
|
803 |
|
|
|
804 |
|
|
gdb_assert (reg != NULL);
|
805 |
|
|
return reg->bitsize;
|
806 |
|
|
}
|
807 |
|
|
|
808 |
|
|
/* Look up a register by its GDB internal register number. */
|
809 |
|
|
|
810 |
|
|
static struct tdesc_arch_reg *
|
811 |
|
|
tdesc_find_arch_register (struct gdbarch *gdbarch, int regno)
|
812 |
|
|
{
|
813 |
|
|
struct tdesc_arch_reg *reg;
|
814 |
|
|
struct tdesc_arch_data *data;
|
815 |
|
|
|
816 |
|
|
data = gdbarch_data (gdbarch, tdesc_data);
|
817 |
|
|
if (regno < VEC_length (tdesc_arch_reg, data->arch_regs))
|
818 |
|
|
return VEC_index (tdesc_arch_reg, data->arch_regs, regno);
|
819 |
|
|
else
|
820 |
|
|
return NULL;
|
821 |
|
|
}
|
822 |
|
|
|
823 |
|
|
static struct tdesc_reg *
|
824 |
|
|
tdesc_find_register (struct gdbarch *gdbarch, int regno)
|
825 |
|
|
{
|
826 |
|
|
struct tdesc_arch_reg *reg = tdesc_find_arch_register (gdbarch, regno);
|
827 |
|
|
return reg? reg->reg : NULL;
|
828 |
|
|
}
|
829 |
|
|
|
830 |
|
|
/* Return the name of register REGNO, from the target description or
|
831 |
|
|
from an architecture-provided pseudo_register_name method. */
|
832 |
|
|
|
833 |
|
|
const char *
|
834 |
|
|
tdesc_register_name (struct gdbarch *gdbarch, int regno)
|
835 |
|
|
{
|
836 |
|
|
struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
|
837 |
|
|
int num_regs = gdbarch_num_regs (gdbarch);
|
838 |
|
|
int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
|
839 |
|
|
|
840 |
|
|
if (reg != NULL)
|
841 |
|
|
return reg->name;
|
842 |
|
|
|
843 |
|
|
if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
|
844 |
|
|
{
|
845 |
|
|
struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
|
846 |
|
|
gdb_assert (data->pseudo_register_name != NULL);
|
847 |
|
|
return data->pseudo_register_name (gdbarch, regno);
|
848 |
|
|
}
|
849 |
|
|
|
850 |
|
|
return "";
|
851 |
|
|
}
|
852 |
|
|
|
853 |
|
|
struct type *
|
854 |
|
|
tdesc_register_type (struct gdbarch *gdbarch, int regno)
|
855 |
|
|
{
|
856 |
|
|
struct tdesc_arch_reg *arch_reg = tdesc_find_arch_register (gdbarch, regno);
|
857 |
|
|
struct tdesc_reg *reg = arch_reg? arch_reg->reg : NULL;
|
858 |
|
|
int num_regs = gdbarch_num_regs (gdbarch);
|
859 |
|
|
int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
|
860 |
|
|
|
861 |
|
|
if (reg == NULL && regno >= num_regs && regno < num_regs + num_pseudo_regs)
|
862 |
|
|
{
|
863 |
|
|
struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
|
864 |
|
|
gdb_assert (data->pseudo_register_type != NULL);
|
865 |
|
|
return data->pseudo_register_type (gdbarch, regno);
|
866 |
|
|
}
|
867 |
|
|
|
868 |
|
|
if (reg == NULL)
|
869 |
|
|
/* Return "int0_t", since "void" has a misleading size of one. */
|
870 |
|
|
return builtin_type (gdbarch)->builtin_int0;
|
871 |
|
|
|
872 |
|
|
if (arch_reg->type == NULL)
|
873 |
|
|
{
|
874 |
|
|
/* First check for a predefined or target defined type. */
|
875 |
|
|
if (reg->tdesc_type)
|
876 |
|
|
arch_reg->type = tdesc_gdb_type (gdbarch, reg->tdesc_type);
|
877 |
|
|
|
878 |
|
|
/* Next try size-sensitive type shortcuts. */
|
879 |
|
|
else if (strcmp (reg->type, "float") == 0)
|
880 |
|
|
{
|
881 |
|
|
if (reg->bitsize == gdbarch_float_bit (gdbarch))
|
882 |
|
|
arch_reg->type = builtin_type (gdbarch)->builtin_float;
|
883 |
|
|
else if (reg->bitsize == gdbarch_double_bit (gdbarch))
|
884 |
|
|
arch_reg->type = builtin_type (gdbarch)->builtin_double;
|
885 |
|
|
else if (reg->bitsize == gdbarch_long_double_bit (gdbarch))
|
886 |
|
|
arch_reg->type = builtin_type (gdbarch)->builtin_long_double;
|
887 |
|
|
else
|
888 |
|
|
{
|
889 |
|
|
warning (_("Register \"%s\" has an unsupported size (%d bits)"),
|
890 |
|
|
reg->name, reg->bitsize);
|
891 |
|
|
arch_reg->type = builtin_type (gdbarch)->builtin_double;
|
892 |
|
|
}
|
893 |
|
|
}
|
894 |
|
|
else if (strcmp (reg->type, "int") == 0)
|
895 |
|
|
{
|
896 |
|
|
if (reg->bitsize == gdbarch_long_bit (gdbarch))
|
897 |
|
|
arch_reg->type = builtin_type (gdbarch)->builtin_long;
|
898 |
|
|
else if (reg->bitsize == TARGET_CHAR_BIT)
|
899 |
|
|
arch_reg->type = builtin_type (gdbarch)->builtin_char;
|
900 |
|
|
else if (reg->bitsize == gdbarch_short_bit (gdbarch))
|
901 |
|
|
arch_reg->type = builtin_type (gdbarch)->builtin_short;
|
902 |
|
|
else if (reg->bitsize == gdbarch_int_bit (gdbarch))
|
903 |
|
|
arch_reg->type = builtin_type (gdbarch)->builtin_int;
|
904 |
|
|
else if (reg->bitsize == gdbarch_long_long_bit (gdbarch))
|
905 |
|
|
arch_reg->type = builtin_type (gdbarch)->builtin_long_long;
|
906 |
|
|
else if (reg->bitsize == gdbarch_ptr_bit (gdbarch))
|
907 |
|
|
/* A bit desperate by this point... */
|
908 |
|
|
arch_reg->type = builtin_type (gdbarch)->builtin_data_ptr;
|
909 |
|
|
else
|
910 |
|
|
{
|
911 |
|
|
warning (_("Register \"%s\" has an unsupported size (%d bits)"),
|
912 |
|
|
reg->name, reg->bitsize);
|
913 |
|
|
arch_reg->type = builtin_type (gdbarch)->builtin_long;
|
914 |
|
|
}
|
915 |
|
|
}
|
916 |
|
|
|
917 |
|
|
if (arch_reg->type == NULL)
|
918 |
|
|
internal_error (__FILE__, __LINE__,
|
919 |
|
|
"Register \"%s\" has an unknown type \"%s\"",
|
920 |
|
|
reg->name, reg->type);
|
921 |
|
|
}
|
922 |
|
|
|
923 |
|
|
return arch_reg->type;
|
924 |
|
|
}
|
925 |
|
|
|
926 |
|
|
static int
|
927 |
|
|
tdesc_remote_register_number (struct gdbarch *gdbarch, int regno)
|
928 |
|
|
{
|
929 |
|
|
struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
|
930 |
|
|
|
931 |
|
|
if (reg != NULL)
|
932 |
|
|
return reg->target_regnum;
|
933 |
|
|
else
|
934 |
|
|
return -1;
|
935 |
|
|
}
|
936 |
|
|
|
937 |
|
|
/* Check whether REGNUM is a member of REGGROUP. Registers from the
|
938 |
|
|
target description may be classified as general, float, or vector.
|
939 |
|
|
Unlike a gdbarch register_reggroup_p method, this function will
|
940 |
|
|
return -1 if it does not know; the caller should handle registers
|
941 |
|
|
with no specified group.
|
942 |
|
|
|
943 |
|
|
Arbitrary strings (other than "general", "float", and "vector")
|
944 |
|
|
from the description are not used; they cause the register to be
|
945 |
|
|
displayed in "info all-registers" but excluded from "info
|
946 |
|
|
registers" et al. The names of containing features are also not
|
947 |
|
|
used. This might be extended to display registers in some more
|
948 |
|
|
useful groupings.
|
949 |
|
|
|
950 |
|
|
The save-restore flag is also implemented here. */
|
951 |
|
|
|
952 |
|
|
int
|
953 |
|
|
tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
|
954 |
|
|
struct reggroup *reggroup)
|
955 |
|
|
{
|
956 |
|
|
struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
|
957 |
|
|
|
958 |
|
|
if (reg != NULL && reg->group != NULL)
|
959 |
|
|
{
|
960 |
|
|
int general_p = 0, float_p = 0, vector_p = 0;
|
961 |
|
|
|
962 |
|
|
if (strcmp (reg->group, "general") == 0)
|
963 |
|
|
general_p = 1;
|
964 |
|
|
else if (strcmp (reg->group, "float") == 0)
|
965 |
|
|
float_p = 1;
|
966 |
|
|
else if (strcmp (reg->group, "vector") == 0)
|
967 |
|
|
vector_p = 1;
|
968 |
|
|
|
969 |
|
|
if (reggroup == float_reggroup)
|
970 |
|
|
return float_p;
|
971 |
|
|
|
972 |
|
|
if (reggroup == vector_reggroup)
|
973 |
|
|
return vector_p;
|
974 |
|
|
|
975 |
|
|
if (reggroup == general_reggroup)
|
976 |
|
|
return general_p;
|
977 |
|
|
}
|
978 |
|
|
|
979 |
|
|
if (reg != NULL
|
980 |
|
|
&& (reggroup == save_reggroup || reggroup == restore_reggroup))
|
981 |
|
|
return reg->save_restore;
|
982 |
|
|
|
983 |
|
|
return -1;
|
984 |
|
|
}
|
985 |
|
|
|
986 |
|
|
/* Check whether REGNUM is a member of REGGROUP. Registers with no
|
987 |
|
|
group specified go to the default reggroup function and are handled
|
988 |
|
|
by type. */
|
989 |
|
|
|
990 |
|
|
static int
|
991 |
|
|
tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regno,
|
992 |
|
|
struct reggroup *reggroup)
|
993 |
|
|
{
|
994 |
|
|
int num_regs = gdbarch_num_regs (gdbarch);
|
995 |
|
|
int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
|
996 |
|
|
int ret;
|
997 |
|
|
|
998 |
|
|
if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
|
999 |
|
|
{
|
1000 |
|
|
struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
|
1001 |
|
|
if (data->pseudo_register_reggroup_p != NULL)
|
1002 |
|
|
return data->pseudo_register_reggroup_p (gdbarch, regno, reggroup);
|
1003 |
|
|
/* Otherwise fall through to the default reggroup_p. */
|
1004 |
|
|
}
|
1005 |
|
|
|
1006 |
|
|
ret = tdesc_register_in_reggroup_p (gdbarch, regno, reggroup);
|
1007 |
|
|
if (ret != -1)
|
1008 |
|
|
return ret;
|
1009 |
|
|
|
1010 |
|
|
return default_register_reggroup_p (gdbarch, regno, reggroup);
|
1011 |
|
|
}
|
1012 |
|
|
|
1013 |
|
|
/* Record architecture-specific functions to call for pseudo-register
|
1014 |
|
|
support. */
|
1015 |
|
|
|
1016 |
|
|
void
|
1017 |
|
|
set_tdesc_pseudo_register_name (struct gdbarch *gdbarch,
|
1018 |
|
|
gdbarch_register_name_ftype *pseudo_name)
|
1019 |
|
|
{
|
1020 |
|
|
struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
|
1021 |
|
|
|
1022 |
|
|
data->pseudo_register_name = pseudo_name;
|
1023 |
|
|
}
|
1024 |
|
|
|
1025 |
|
|
void
|
1026 |
|
|
set_tdesc_pseudo_register_type (struct gdbarch *gdbarch,
|
1027 |
|
|
gdbarch_register_type_ftype *pseudo_type)
|
1028 |
|
|
{
|
1029 |
|
|
struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
|
1030 |
|
|
|
1031 |
|
|
data->pseudo_register_type = pseudo_type;
|
1032 |
|
|
}
|
1033 |
|
|
|
1034 |
|
|
void
|
1035 |
|
|
set_tdesc_pseudo_register_reggroup_p
|
1036 |
|
|
(struct gdbarch *gdbarch,
|
1037 |
|
|
gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p)
|
1038 |
|
|
{
|
1039 |
|
|
struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
|
1040 |
|
|
|
1041 |
|
|
data->pseudo_register_reggroup_p = pseudo_reggroup_p;
|
1042 |
|
|
}
|
1043 |
|
|
|
1044 |
|
|
/* Update GDBARCH to use the target description for registers. */
|
1045 |
|
|
|
1046 |
|
|
void
|
1047 |
|
|
tdesc_use_registers (struct gdbarch *gdbarch,
|
1048 |
|
|
const struct target_desc *target_desc,
|
1049 |
|
|
struct tdesc_arch_data *early_data)
|
1050 |
|
|
{
|
1051 |
|
|
int num_regs = gdbarch_num_regs (gdbarch);
|
1052 |
|
|
int i, ixf, ixr;
|
1053 |
|
|
struct tdesc_feature *feature;
|
1054 |
|
|
struct tdesc_reg *reg;
|
1055 |
|
|
struct tdesc_arch_data *data;
|
1056 |
|
|
struct tdesc_arch_reg *arch_reg, new_arch_reg = { 0 };
|
1057 |
|
|
htab_t reg_hash;
|
1058 |
|
|
|
1059 |
|
|
/* We can't use the description for registers if it doesn't describe
|
1060 |
|
|
any. This function should only be called after validating
|
1061 |
|
|
registers, so the caller should know that registers are
|
1062 |
|
|
included. */
|
1063 |
|
|
gdb_assert (tdesc_has_registers (target_desc));
|
1064 |
|
|
|
1065 |
|
|
data = gdbarch_data (gdbarch, tdesc_data);
|
1066 |
|
|
data->arch_regs = early_data->arch_regs;
|
1067 |
|
|
xfree (early_data);
|
1068 |
|
|
|
1069 |
|
|
/* Build up a set of all registers, so that we can assign register
|
1070 |
|
|
numbers where needed. The hash table expands as necessary, so
|
1071 |
|
|
the initial size is arbitrary. */
|
1072 |
|
|
reg_hash = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
|
1073 |
|
|
for (ixf = 0;
|
1074 |
|
|
VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
|
1075 |
|
|
ixf++)
|
1076 |
|
|
for (ixr = 0;
|
1077 |
|
|
VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
|
1078 |
|
|
ixr++)
|
1079 |
|
|
{
|
1080 |
|
|
void **slot = htab_find_slot (reg_hash, reg, INSERT);
|
1081 |
|
|
|
1082 |
|
|
*slot = reg;
|
1083 |
|
|
}
|
1084 |
|
|
|
1085 |
|
|
/* Remove any registers which were assigned numbers by the
|
1086 |
|
|
architecture. */
|
1087 |
|
|
for (ixr = 0;
|
1088 |
|
|
VEC_iterate (tdesc_arch_reg, data->arch_regs, ixr, arch_reg);
|
1089 |
|
|
ixr++)
|
1090 |
|
|
if (arch_reg->reg)
|
1091 |
|
|
htab_remove_elt (reg_hash, arch_reg->reg);
|
1092 |
|
|
|
1093 |
|
|
/* Assign numbers to the remaining registers and add them to the
|
1094 |
|
|
list of registers. The new numbers are always above gdbarch_num_regs.
|
1095 |
|
|
Iterate over the features, not the hash table, so that the order
|
1096 |
|
|
matches that in the target description. */
|
1097 |
|
|
|
1098 |
|
|
gdb_assert (VEC_length (tdesc_arch_reg, data->arch_regs) <= num_regs);
|
1099 |
|
|
while (VEC_length (tdesc_arch_reg, data->arch_regs) < num_regs)
|
1100 |
|
|
VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
|
1101 |
|
|
for (ixf = 0;
|
1102 |
|
|
VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
|
1103 |
|
|
ixf++)
|
1104 |
|
|
for (ixr = 0;
|
1105 |
|
|
VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
|
1106 |
|
|
ixr++)
|
1107 |
|
|
if (htab_find (reg_hash, reg) != NULL)
|
1108 |
|
|
{
|
1109 |
|
|
new_arch_reg.reg = reg;
|
1110 |
|
|
VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
|
1111 |
|
|
num_regs++;
|
1112 |
|
|
}
|
1113 |
|
|
|
1114 |
|
|
htab_delete (reg_hash);
|
1115 |
|
|
|
1116 |
|
|
/* Update the architecture. */
|
1117 |
|
|
set_gdbarch_num_regs (gdbarch, num_regs);
|
1118 |
|
|
set_gdbarch_register_name (gdbarch, tdesc_register_name);
|
1119 |
|
|
set_gdbarch_register_type (gdbarch, tdesc_register_type);
|
1120 |
|
|
set_gdbarch_remote_register_number (gdbarch,
|
1121 |
|
|
tdesc_remote_register_number);
|
1122 |
|
|
set_gdbarch_register_reggroup_p (gdbarch, tdesc_register_reggroup_p);
|
1123 |
|
|
}
|
1124 |
|
|
|
1125 |
|
|
|
1126 |
|
|
/* Methods for constructing a target description. */
|
1127 |
|
|
|
1128 |
|
|
static void
|
1129 |
|
|
tdesc_free_reg (struct tdesc_reg *reg)
|
1130 |
|
|
{
|
1131 |
|
|
xfree (reg->name);
|
1132 |
|
|
xfree (reg->type);
|
1133 |
|
|
xfree (reg->group);
|
1134 |
|
|
xfree (reg);
|
1135 |
|
|
}
|
1136 |
|
|
|
1137 |
|
|
void
|
1138 |
|
|
tdesc_create_reg (struct tdesc_feature *feature, const char *name,
|
1139 |
|
|
int regnum, int save_restore, const char *group,
|
1140 |
|
|
int bitsize, const char *type)
|
1141 |
|
|
{
|
1142 |
|
|
struct tdesc_reg *reg = XZALLOC (struct tdesc_reg);
|
1143 |
|
|
|
1144 |
|
|
reg->name = xstrdup (name);
|
1145 |
|
|
reg->target_regnum = regnum;
|
1146 |
|
|
reg->save_restore = save_restore;
|
1147 |
|
|
reg->group = group ? xstrdup (group) : NULL;
|
1148 |
|
|
reg->bitsize = bitsize;
|
1149 |
|
|
reg->type = type ? xstrdup (type) : xstrdup ("<unknown>");
|
1150 |
|
|
|
1151 |
|
|
/* If the register's type is target-defined, look it up now. We may not
|
1152 |
|
|
have easy access to the containing feature when we want it later. */
|
1153 |
|
|
reg->tdesc_type = tdesc_named_type (feature, reg->type);
|
1154 |
|
|
|
1155 |
|
|
VEC_safe_push (tdesc_reg_p, feature->registers, reg);
|
1156 |
|
|
}
|
1157 |
|
|
|
1158 |
|
|
static void
|
1159 |
|
|
tdesc_free_type (struct tdesc_type *type)
|
1160 |
|
|
{
|
1161 |
|
|
|
1162 |
|
|
switch (type->kind)
|
1163 |
|
|
{
|
1164 |
|
|
case TDESC_TYPE_UNION:
|
1165 |
|
|
{
|
1166 |
|
|
struct tdesc_type_field *f;
|
1167 |
|
|
int ix;
|
1168 |
|
|
|
1169 |
|
|
for (ix = 0;
|
1170 |
|
|
VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f);
|
1171 |
|
|
ix++)
|
1172 |
|
|
xfree (f->name);
|
1173 |
|
|
|
1174 |
|
|
VEC_free (tdesc_type_field, type->u.u.fields);
|
1175 |
|
|
}
|
1176 |
|
|
break;
|
1177 |
|
|
|
1178 |
|
|
default:
|
1179 |
|
|
break;
|
1180 |
|
|
}
|
1181 |
|
|
|
1182 |
|
|
xfree (type->name);
|
1183 |
|
|
xfree (type);
|
1184 |
|
|
}
|
1185 |
|
|
|
1186 |
|
|
struct tdesc_type *
|
1187 |
|
|
tdesc_create_vector (struct tdesc_feature *feature, const char *name,
|
1188 |
|
|
struct tdesc_type *field_type, int count)
|
1189 |
|
|
{
|
1190 |
|
|
struct tdesc_type *type = XZALLOC (struct tdesc_type);
|
1191 |
|
|
|
1192 |
|
|
type->name = xstrdup (name);
|
1193 |
|
|
type->kind = TDESC_TYPE_VECTOR;
|
1194 |
|
|
type->u.v.type = field_type;
|
1195 |
|
|
type->u.v.count = count;
|
1196 |
|
|
|
1197 |
|
|
VEC_safe_push (tdesc_type_p, feature->types, type);
|
1198 |
|
|
return type;
|
1199 |
|
|
}
|
1200 |
|
|
|
1201 |
|
|
struct tdesc_type *
|
1202 |
|
|
tdesc_create_union (struct tdesc_feature *feature, const char *name)
|
1203 |
|
|
{
|
1204 |
|
|
struct tdesc_type *type = XZALLOC (struct tdesc_type);
|
1205 |
|
|
|
1206 |
|
|
type->name = xstrdup (name);
|
1207 |
|
|
type->kind = TDESC_TYPE_UNION;
|
1208 |
|
|
|
1209 |
|
|
VEC_safe_push (tdesc_type_p, feature->types, type);
|
1210 |
|
|
return type;
|
1211 |
|
|
}
|
1212 |
|
|
|
1213 |
|
|
void
|
1214 |
|
|
tdesc_add_field (struct tdesc_type *type, const char *field_name,
|
1215 |
|
|
struct tdesc_type *field_type)
|
1216 |
|
|
{
|
1217 |
|
|
struct tdesc_type_field f = { 0 };
|
1218 |
|
|
|
1219 |
|
|
gdb_assert (type->kind == TDESC_TYPE_UNION);
|
1220 |
|
|
|
1221 |
|
|
f.name = xstrdup (field_name);
|
1222 |
|
|
f.type = field_type;
|
1223 |
|
|
|
1224 |
|
|
VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
|
1225 |
|
|
}
|
1226 |
|
|
|
1227 |
|
|
static void
|
1228 |
|
|
tdesc_free_feature (struct tdesc_feature *feature)
|
1229 |
|
|
{
|
1230 |
|
|
struct tdesc_reg *reg;
|
1231 |
|
|
struct tdesc_type *type;
|
1232 |
|
|
int ix;
|
1233 |
|
|
|
1234 |
|
|
for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++)
|
1235 |
|
|
tdesc_free_reg (reg);
|
1236 |
|
|
VEC_free (tdesc_reg_p, feature->registers);
|
1237 |
|
|
|
1238 |
|
|
for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
|
1239 |
|
|
tdesc_free_type (type);
|
1240 |
|
|
VEC_free (tdesc_type_p, feature->types);
|
1241 |
|
|
|
1242 |
|
|
xfree (feature->name);
|
1243 |
|
|
xfree (feature);
|
1244 |
|
|
}
|
1245 |
|
|
|
1246 |
|
|
struct tdesc_feature *
|
1247 |
|
|
tdesc_create_feature (struct target_desc *tdesc, const char *name)
|
1248 |
|
|
{
|
1249 |
|
|
struct tdesc_feature *new_feature = XZALLOC (struct tdesc_feature);
|
1250 |
|
|
|
1251 |
|
|
new_feature->name = xstrdup (name);
|
1252 |
|
|
|
1253 |
|
|
VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature);
|
1254 |
|
|
return new_feature;
|
1255 |
|
|
}
|
1256 |
|
|
|
1257 |
|
|
struct target_desc *
|
1258 |
|
|
allocate_target_description (void)
|
1259 |
|
|
{
|
1260 |
|
|
return XZALLOC (struct target_desc);
|
1261 |
|
|
}
|
1262 |
|
|
|
1263 |
|
|
static void
|
1264 |
|
|
free_target_description (void *arg)
|
1265 |
|
|
{
|
1266 |
|
|
struct target_desc *target_desc = arg;
|
1267 |
|
|
struct tdesc_feature *feature;
|
1268 |
|
|
struct property *prop;
|
1269 |
|
|
int ix;
|
1270 |
|
|
|
1271 |
|
|
for (ix = 0;
|
1272 |
|
|
VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
|
1273 |
|
|
ix++)
|
1274 |
|
|
tdesc_free_feature (feature);
|
1275 |
|
|
VEC_free (tdesc_feature_p, target_desc->features);
|
1276 |
|
|
|
1277 |
|
|
for (ix = 0;
|
1278 |
|
|
VEC_iterate (property_s, target_desc->properties, ix, prop);
|
1279 |
|
|
ix++)
|
1280 |
|
|
{
|
1281 |
|
|
xfree (prop->key);
|
1282 |
|
|
xfree (prop->value);
|
1283 |
|
|
}
|
1284 |
|
|
VEC_free (property_s, target_desc->properties);
|
1285 |
|
|
|
1286 |
|
|
VEC_free (arch_p, target_desc->compatible);
|
1287 |
|
|
|
1288 |
|
|
xfree (target_desc);
|
1289 |
|
|
}
|
1290 |
|
|
|
1291 |
|
|
struct cleanup *
|
1292 |
|
|
make_cleanup_free_target_description (struct target_desc *target_desc)
|
1293 |
|
|
{
|
1294 |
|
|
return make_cleanup (free_target_description, target_desc);
|
1295 |
|
|
}
|
1296 |
|
|
|
1297 |
|
|
void
|
1298 |
|
|
tdesc_add_compatible (struct target_desc *target_desc,
|
1299 |
|
|
const struct bfd_arch_info *compatible)
|
1300 |
|
|
{
|
1301 |
|
|
const struct bfd_arch_info *compat;
|
1302 |
|
|
int ix;
|
1303 |
|
|
|
1304 |
|
|
/* If this instance of GDB is compiled without BFD support for the
|
1305 |
|
|
compatible architecture, simply ignore it -- we would not be able
|
1306 |
|
|
to handle it anyway. */
|
1307 |
|
|
if (compatible == NULL)
|
1308 |
|
|
return;
|
1309 |
|
|
|
1310 |
|
|
for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
|
1311 |
|
|
ix++)
|
1312 |
|
|
if (compat == compatible)
|
1313 |
|
|
internal_error (__FILE__, __LINE__,
|
1314 |
|
|
_("Attempted to add duplicate "
|
1315 |
|
|
"compatible architecture \"%s\""),
|
1316 |
|
|
compatible->printable_name);
|
1317 |
|
|
|
1318 |
|
|
VEC_safe_push (arch_p, target_desc->compatible, compatible);
|
1319 |
|
|
}
|
1320 |
|
|
|
1321 |
|
|
void
|
1322 |
|
|
set_tdesc_property (struct target_desc *target_desc,
|
1323 |
|
|
const char *key, const char *value)
|
1324 |
|
|
{
|
1325 |
|
|
struct property *prop, new_prop;
|
1326 |
|
|
int ix;
|
1327 |
|
|
|
1328 |
|
|
gdb_assert (key != NULL && value != NULL);
|
1329 |
|
|
|
1330 |
|
|
for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
|
1331 |
|
|
ix++)
|
1332 |
|
|
if (strcmp (prop->key, key) == 0)
|
1333 |
|
|
internal_error (__FILE__, __LINE__,
|
1334 |
|
|
_("Attempted to add duplicate property \"%s\""), key);
|
1335 |
|
|
|
1336 |
|
|
new_prop.key = xstrdup (key);
|
1337 |
|
|
new_prop.value = xstrdup (value);
|
1338 |
|
|
VEC_safe_push (property_s, target_desc->properties, &new_prop);
|
1339 |
|
|
}
|
1340 |
|
|
|
1341 |
|
|
void
|
1342 |
|
|
set_tdesc_architecture (struct target_desc *target_desc,
|
1343 |
|
|
const struct bfd_arch_info *arch)
|
1344 |
|
|
{
|
1345 |
|
|
target_desc->arch = arch;
|
1346 |
|
|
}
|
1347 |
|
|
|
1348 |
|
|
void
|
1349 |
|
|
set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
|
1350 |
|
|
{
|
1351 |
|
|
target_desc->osabi = osabi;
|
1352 |
|
|
}
|
1353 |
|
|
|
1354 |
|
|
|
1355 |
|
|
static struct cmd_list_element *tdesc_set_cmdlist, *tdesc_show_cmdlist;
|
1356 |
|
|
static struct cmd_list_element *tdesc_unset_cmdlist;
|
1357 |
|
|
|
1358 |
|
|
/* Helper functions for the CLI commands. */
|
1359 |
|
|
|
1360 |
|
|
static void
|
1361 |
|
|
set_tdesc_cmd (char *args, int from_tty)
|
1362 |
|
|
{
|
1363 |
|
|
help_list (tdesc_set_cmdlist, "set tdesc ", -1, gdb_stdout);
|
1364 |
|
|
}
|
1365 |
|
|
|
1366 |
|
|
static void
|
1367 |
|
|
show_tdesc_cmd (char *args, int from_tty)
|
1368 |
|
|
{
|
1369 |
|
|
cmd_show_list (tdesc_show_cmdlist, from_tty, "");
|
1370 |
|
|
}
|
1371 |
|
|
|
1372 |
|
|
static void
|
1373 |
|
|
unset_tdesc_cmd (char *args, int from_tty)
|
1374 |
|
|
{
|
1375 |
|
|
help_list (tdesc_unset_cmdlist, "unset tdesc ", -1, gdb_stdout);
|
1376 |
|
|
}
|
1377 |
|
|
|
1378 |
|
|
static void
|
1379 |
|
|
set_tdesc_filename_cmd (char *args, int from_tty,
|
1380 |
|
|
struct cmd_list_element *c)
|
1381 |
|
|
{
|
1382 |
|
|
target_clear_description ();
|
1383 |
|
|
target_find_description ();
|
1384 |
|
|
}
|
1385 |
|
|
|
1386 |
|
|
static void
|
1387 |
|
|
show_tdesc_filename_cmd (struct ui_file *file, int from_tty,
|
1388 |
|
|
struct cmd_list_element *c,
|
1389 |
|
|
const char *value)
|
1390 |
|
|
{
|
1391 |
|
|
if (value != NULL && *value != '\0')
|
1392 |
|
|
printf_filtered (_("\
|
1393 |
|
|
The target description will be read from \"%s\".\n"),
|
1394 |
|
|
value);
|
1395 |
|
|
else
|
1396 |
|
|
printf_filtered (_("\
|
1397 |
|
|
The target description will be read from the target.\n"));
|
1398 |
|
|
}
|
1399 |
|
|
|
1400 |
|
|
static void
|
1401 |
|
|
unset_tdesc_filename_cmd (char *args, int from_tty)
|
1402 |
|
|
{
|
1403 |
|
|
xfree (target_description_filename);
|
1404 |
|
|
target_description_filename = NULL;
|
1405 |
|
|
target_clear_description ();
|
1406 |
|
|
target_find_description ();
|
1407 |
|
|
}
|
1408 |
|
|
|
1409 |
|
|
static void
|
1410 |
|
|
maint_print_c_tdesc_cmd (char *args, int from_tty)
|
1411 |
|
|
{
|
1412 |
|
|
const struct target_desc *tdesc;
|
1413 |
|
|
const struct bfd_arch_info *compatible;
|
1414 |
|
|
const char *filename, *inp;
|
1415 |
|
|
char *function, *outp;
|
1416 |
|
|
struct property *prop;
|
1417 |
|
|
struct tdesc_feature *feature;
|
1418 |
|
|
struct tdesc_reg *reg;
|
1419 |
|
|
struct tdesc_type *type;
|
1420 |
|
|
struct tdesc_type_field *f;
|
1421 |
|
|
int ix, ix2, ix3;
|
1422 |
|
|
|
1423 |
|
|
/* Use the global target-supplied description, not the current
|
1424 |
|
|
architecture's. This lets a GDB for one architecture generate C
|
1425 |
|
|
for another architecture's description, even though the gdbarch
|
1426 |
|
|
initialization code will reject the new description. */
|
1427 |
|
|
tdesc = current_target_desc;
|
1428 |
|
|
if (tdesc == NULL)
|
1429 |
|
|
error (_("There is no target description to print."));
|
1430 |
|
|
|
1431 |
|
|
if (target_description_filename == NULL)
|
1432 |
|
|
error (_("The current target description did not come from an XML file."));
|
1433 |
|
|
|
1434 |
|
|
filename = lbasename (target_description_filename);
|
1435 |
|
|
function = alloca (strlen (filename) + 1);
|
1436 |
|
|
for (inp = filename, outp = function; *inp != '\0'; inp++)
|
1437 |
|
|
if (*inp == '.')
|
1438 |
|
|
break;
|
1439 |
|
|
else if (*inp == '-')
|
1440 |
|
|
*outp++ = '_';
|
1441 |
|
|
else
|
1442 |
|
|
*outp++ = *inp;
|
1443 |
|
|
*outp = '\0';
|
1444 |
|
|
|
1445 |
|
|
/* Standard boilerplate. */
|
1446 |
|
|
printf_unfiltered ("/* THIS FILE IS GENERATED. Original: %s */\n\n",
|
1447 |
|
|
filename);
|
1448 |
|
|
printf_unfiltered ("#include \"defs.h\"\n");
|
1449 |
|
|
printf_unfiltered ("#include \"osabi.h\"\n");
|
1450 |
|
|
printf_unfiltered ("#include \"target-descriptions.h\"\n");
|
1451 |
|
|
printf_unfiltered ("\n");
|
1452 |
|
|
|
1453 |
|
|
printf_unfiltered ("struct target_desc *tdesc_%s;\n", function);
|
1454 |
|
|
printf_unfiltered ("static void\n");
|
1455 |
|
|
printf_unfiltered ("initialize_tdesc_%s (void)\n", function);
|
1456 |
|
|
printf_unfiltered ("{\n");
|
1457 |
|
|
printf_unfiltered
|
1458 |
|
|
(" struct target_desc *result = allocate_target_description ();\n");
|
1459 |
|
|
printf_unfiltered (" struct tdesc_feature *feature;\n");
|
1460 |
|
|
printf_unfiltered (" struct tdesc_type *field_type, *type;\n");
|
1461 |
|
|
printf_unfiltered ("\n");
|
1462 |
|
|
|
1463 |
|
|
if (tdesc_architecture (tdesc) != NULL)
|
1464 |
|
|
{
|
1465 |
|
|
printf_unfiltered
|
1466 |
|
|
(" set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
|
1467 |
|
|
tdesc_architecture (tdesc)->printable_name);
|
1468 |
|
|
printf_unfiltered ("\n");
|
1469 |
|
|
}
|
1470 |
|
|
|
1471 |
|
|
if (tdesc_osabi (tdesc) > GDB_OSABI_UNKNOWN
|
1472 |
|
|
&& tdesc_osabi (tdesc) < GDB_OSABI_INVALID)
|
1473 |
|
|
{
|
1474 |
|
|
printf_unfiltered
|
1475 |
|
|
(" set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
|
1476 |
|
|
gdbarch_osabi_name (tdesc_osabi (tdesc)));
|
1477 |
|
|
printf_unfiltered ("\n");
|
1478 |
|
|
}
|
1479 |
|
|
|
1480 |
|
|
for (ix = 0; VEC_iterate (arch_p, tdesc->compatible, ix, compatible);
|
1481 |
|
|
ix++)
|
1482 |
|
|
{
|
1483 |
|
|
printf_unfiltered
|
1484 |
|
|
(" tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
|
1485 |
|
|
compatible->printable_name);
|
1486 |
|
|
}
|
1487 |
|
|
if (ix)
|
1488 |
|
|
printf_unfiltered ("\n");
|
1489 |
|
|
|
1490 |
|
|
for (ix = 0; VEC_iterate (property_s, tdesc->properties, ix, prop);
|
1491 |
|
|
ix++)
|
1492 |
|
|
{
|
1493 |
|
|
printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n",
|
1494 |
|
|
prop->key, prop->value);
|
1495 |
|
|
}
|
1496 |
|
|
|
1497 |
|
|
for (ix = 0;
|
1498 |
|
|
VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
|
1499 |
|
|
ix++)
|
1500 |
|
|
{
|
1501 |
|
|
printf_unfiltered (" feature = tdesc_create_feature (result, \"%s\");\n",
|
1502 |
|
|
feature->name);
|
1503 |
|
|
|
1504 |
|
|
for (ix2 = 0;
|
1505 |
|
|
VEC_iterate (tdesc_type_p, feature->types, ix2, type);
|
1506 |
|
|
ix2++)
|
1507 |
|
|
{
|
1508 |
|
|
switch (type->kind)
|
1509 |
|
|
{
|
1510 |
|
|
case TDESC_TYPE_VECTOR:
|
1511 |
|
|
printf_unfiltered
|
1512 |
|
|
(" field_type = tdesc_named_type (feature, \"%s\");\n",
|
1513 |
|
|
type->u.v.type->name);
|
1514 |
|
|
printf_unfiltered
|
1515 |
|
|
(" tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
|
1516 |
|
|
type->name, type->u.v.count);
|
1517 |
|
|
break;
|
1518 |
|
|
case TDESC_TYPE_UNION:
|
1519 |
|
|
printf_unfiltered
|
1520 |
|
|
(" type = tdesc_create_union (feature, \"%s\");\n",
|
1521 |
|
|
type->name);
|
1522 |
|
|
for (ix3 = 0;
|
1523 |
|
|
VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
|
1524 |
|
|
ix3++)
|
1525 |
|
|
{
|
1526 |
|
|
printf_unfiltered
|
1527 |
|
|
(" field_type = tdesc_named_type (feature, \"%s\");\n",
|
1528 |
|
|
f->type->name);
|
1529 |
|
|
printf_unfiltered
|
1530 |
|
|
(" tdesc_add_field (type, \"%s\", field_type);\n",
|
1531 |
|
|
f->name);
|
1532 |
|
|
}
|
1533 |
|
|
break;
|
1534 |
|
|
default:
|
1535 |
|
|
error (_("C output is not supported type \"%s\"."), type->name);
|
1536 |
|
|
}
|
1537 |
|
|
printf_unfiltered ("\n");
|
1538 |
|
|
}
|
1539 |
|
|
|
1540 |
|
|
for (ix2 = 0;
|
1541 |
|
|
VEC_iterate (tdesc_reg_p, feature->registers, ix2, reg);
|
1542 |
|
|
ix2++)
|
1543 |
|
|
{
|
1544 |
|
|
printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
|
1545 |
|
|
reg->name, reg->target_regnum, reg->save_restore);
|
1546 |
|
|
if (reg->group)
|
1547 |
|
|
printf_unfiltered ("\"%s\", ", reg->group);
|
1548 |
|
|
else
|
1549 |
|
|
printf_unfiltered ("NULL, ");
|
1550 |
|
|
printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
|
1551 |
|
|
}
|
1552 |
|
|
|
1553 |
|
|
printf_unfiltered ("\n");
|
1554 |
|
|
}
|
1555 |
|
|
|
1556 |
|
|
printf_unfiltered (" tdesc_%s = result;\n", function);
|
1557 |
|
|
printf_unfiltered ("}\n");
|
1558 |
|
|
}
|
1559 |
|
|
|
1560 |
|
|
/* Provide a prototype to silence -Wmissing-prototypes. */
|
1561 |
|
|
extern initialize_file_ftype _initialize_target_descriptions;
|
1562 |
|
|
|
1563 |
|
|
void
|
1564 |
|
|
_initialize_target_descriptions (void)
|
1565 |
|
|
{
|
1566 |
|
|
tdesc_data = gdbarch_data_register_pre_init (tdesc_data_init);
|
1567 |
|
|
|
1568 |
|
|
add_prefix_cmd ("tdesc", class_maintenance, set_tdesc_cmd, _("\
|
1569 |
|
|
Set target description specific variables."),
|
1570 |
|
|
&tdesc_set_cmdlist, "set tdesc ",
|
1571 |
|
|
|
1572 |
|
|
add_prefix_cmd ("tdesc", class_maintenance, show_tdesc_cmd, _("\
|
1573 |
|
|
Show target description specific variables."),
|
1574 |
|
|
&tdesc_show_cmdlist, "show tdesc ",
|
1575 |
|
|
|
1576 |
|
|
add_prefix_cmd ("tdesc", class_maintenance, unset_tdesc_cmd, _("\
|
1577 |
|
|
Unset target description specific variables."),
|
1578 |
|
|
&tdesc_unset_cmdlist, "unset tdesc ",
|
1579 |
|
|
|
1580 |
|
|
|
1581 |
|
|
add_setshow_filename_cmd ("filename", class_obscure,
|
1582 |
|
|
&target_description_filename,
|
1583 |
|
|
_("\
|
1584 |
|
|
Set the file to read for an XML target description"), _("\
|
1585 |
|
|
Show the file to read for an XML target description"), _("\
|
1586 |
|
|
When set, GDB will read the target description from a local\n\
|
1587 |
|
|
file instead of querying the remote target."),
|
1588 |
|
|
set_tdesc_filename_cmd,
|
1589 |
|
|
show_tdesc_filename_cmd,
|
1590 |
|
|
&tdesc_set_cmdlist, &tdesc_show_cmdlist);
|
1591 |
|
|
|
1592 |
|
|
add_cmd ("filename", class_obscure, unset_tdesc_filename_cmd, _("\
|
1593 |
|
|
Unset the file to read for an XML target description. When unset,\n\
|
1594 |
|
|
GDB will read the description from the target."),
|
1595 |
|
|
&tdesc_unset_cmdlist);
|
1596 |
|
|
|
1597 |
|
|
add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\
|
1598 |
|
|
Print the current target description as a C source file."),
|
1599 |
|
|
&maintenanceprintlist);
|
1600 |
|
|
}
|