[ARC] Add checking for LP_COUNT reg usage, improve error reporting.
[deliverable/binutils-gdb.git] / gdb / target-descriptions.c
CommitLineData
424163ea
DJ
1/* Target description support for GDB.
2
618f726f 3 Copyright (C) 2006-2016 Free Software Foundation, Inc.
424163ea
DJ
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
424163ea
DJ
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
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
424163ea
DJ
21
22#include "defs.h"
23#include "arch-utils.h"
23181151 24#include "gdbcmd.h"
123dc839
DJ
25#include "gdbtypes.h"
26#include "reggroups.h"
424163ea
DJ
27#include "target.h"
28#include "target-descriptions.h"
29709017 29#include "vec.h"
123dc839 30#include "xml-support.h"
23181151 31#include "xml-tdesc.h"
c3f08eb7 32#include "osabi.h"
424163ea 33
123dc839
DJ
34#include "gdb_obstack.h"
35#include "hashtab.h"
6ecd4729 36#include "inferior.h"
424163ea
DJ
37
38/* Types. */
39
29709017
DJ
40typedef struct property
41{
23181151
DJ
42 char *key;
43 char *value;
29709017
DJ
44} property_s;
45DEF_VEC_O(property_s);
46
123dc839
DJ
47/* An individual register from a target description. */
48
49typedef 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. */
ad068eab 83 struct tdesc_type *tdesc_type;
123dc839
DJ
84} *tdesc_reg_p;
85DEF_VEC_P(tdesc_reg_p);
86
87/* A named type from a target description. */
ad068eab
UW
88
89typedef struct tdesc_type_field
90{
91 char *name;
92 struct tdesc_type *type;
81516450
DE
93 /* For non-enum-values, either both are -1 (non-bitfield), or both are
94 not -1 (bitfield). For enum values, start is the value (which could be
95 -1), end is -1. */
f5dff777 96 int start, end;
ad068eab
UW
97} tdesc_type_field;
98DEF_VEC_O(tdesc_type_field);
99
52059ffd
TT
100enum tdesc_type_kind
101{
102 /* Predefined types. */
81516450 103 TDESC_TYPE_BOOL,
52059ffd
TT
104 TDESC_TYPE_INT8,
105 TDESC_TYPE_INT16,
106 TDESC_TYPE_INT32,
107 TDESC_TYPE_INT64,
108 TDESC_TYPE_INT128,
109 TDESC_TYPE_UINT8,
110 TDESC_TYPE_UINT16,
111 TDESC_TYPE_UINT32,
112 TDESC_TYPE_UINT64,
113 TDESC_TYPE_UINT128,
114 TDESC_TYPE_CODE_PTR,
115 TDESC_TYPE_DATA_PTR,
116 TDESC_TYPE_IEEE_SINGLE,
117 TDESC_TYPE_IEEE_DOUBLE,
118 TDESC_TYPE_ARM_FPA_EXT,
119 TDESC_TYPE_I387_EXT,
120
121 /* Types defined by a target feature. */
122 TDESC_TYPE_VECTOR,
123 TDESC_TYPE_STRUCT,
124 TDESC_TYPE_UNION,
81516450
DE
125 TDESC_TYPE_FLAGS,
126 TDESC_TYPE_ENUM
52059ffd
TT
127};
128
ad068eab
UW
129typedef struct tdesc_type
130{
131 /* The name of this type. */
132 char *name;
133
134 /* Identify the kind of this type. */
52059ffd 135 enum tdesc_type_kind kind;
ad068eab
UW
136
137 /* Kind-specific data. */
138 union
139 {
140 /* Vector type. */
141 struct
142 {
143 struct tdesc_type *type;
144 int count;
145 } v;
146
81516450 147 /* Struct, union, flags, or enum type. */
ad068eab
UW
148 struct
149 {
150 VEC(tdesc_type_field) *fields;
54157a25 151 int size;
ad068eab
UW
152 } u;
153 } u;
154} *tdesc_type_p;
155DEF_VEC_P(tdesc_type_p);
123dc839
DJ
156
157/* A feature from a target description. Each feature is a collection
158 of other elements, e.g. registers and types. */
159
160typedef struct tdesc_feature
161{
162 /* The name of this feature. It may be recognized by the architecture
163 support code. */
164 char *name;
165
166 /* The registers associated with this feature. */
167 VEC(tdesc_reg_p) *registers;
168
169 /* The types associated with this feature. */
ad068eab 170 VEC(tdesc_type_p) *types;
123dc839
DJ
171} *tdesc_feature_p;
172DEF_VEC_P(tdesc_feature_p);
173
e35359c5
UW
174/* A compatible architecture from a target description. */
175typedef const struct bfd_arch_info *arch_p;
176DEF_VEC_P(arch_p);
177
123dc839
DJ
178/* A target description. */
179
424163ea
DJ
180struct target_desc
181{
23181151
DJ
182 /* The architecture reported by the target, if any. */
183 const struct bfd_arch_info *arch;
184
08d16641
PA
185 /* The osabi reported by the target, if any; GDB_OSABI_UNKNOWN
186 otherwise. */
187 enum gdb_osabi osabi;
188
e35359c5
UW
189 /* The list of compatible architectures reported by the target. */
190 VEC(arch_p) *compatible;
191
29709017
DJ
192 /* Any architecture-specific properties specified by the target. */
193 VEC(property_s) *properties;
123dc839
DJ
194
195 /* The features associated with this target. */
196 VEC(tdesc_feature_p) *features;
197};
198
199/* Per-architecture data associated with a target description. The
200 target description may be shared by multiple architectures, but
201 this data is private to one gdbarch. */
202
ad068eab
UW
203typedef struct tdesc_arch_reg
204{
205 struct tdesc_reg *reg;
206 struct type *type;
207} tdesc_arch_reg;
208DEF_VEC_O(tdesc_arch_reg);
209
123dc839
DJ
210struct tdesc_arch_data
211{
ad068eab 212 /* A list of register/type pairs, indexed by GDB's internal register number.
123dc839
DJ
213 During initialization of the gdbarch this list is used to store
214 registers which the architecture assigns a fixed register number.
215 Registers which are NULL in this array, or off the end, are
216 treated as zero-sized and nameless (i.e. placeholders in the
217 numbering). */
ad068eab 218 VEC(tdesc_arch_reg) *arch_regs;
123dc839
DJ
219
220 /* Functions which report the register name, type, and reggroups for
221 pseudo-registers. */
222 gdbarch_register_name_ftype *pseudo_register_name;
223 gdbarch_register_type_ftype *pseudo_register_type;
224 gdbarch_register_reggroup_p_ftype *pseudo_register_reggroup_p;
424163ea
DJ
225};
226
6ecd4729
PA
227/* Info about an inferior's target description. There's one of these
228 for each inferior. */
424163ea 229
6ecd4729
PA
230struct target_desc_info
231{
232 /* A flag indicating that a description has already been fetched
233 from the target, so it should not be queried again. */
234
235 int fetched;
424163ea 236
6ecd4729
PA
237 /* The description fetched from the target, or NULL if the target
238 did not supply any description. Only valid when
239 target_desc_fetched is set. Only the description initialization
240 code should access this; normally, the description should be
241 accessed through the gdbarch object. */
424163ea 242
6ecd4729 243 const struct target_desc *tdesc;
424163ea 244
6ecd4729
PA
245 /* The filename to read a target description from, as set by "set
246 tdesc filename ..." */
424163ea 247
6ecd4729
PA
248 char *filename;
249};
23181151 250
6ecd4729
PA
251/* Get the inferior INF's target description info, allocating one on
252 the stop if necessary. */
23181151 253
6ecd4729
PA
254static struct target_desc_info *
255get_tdesc_info (struct inferior *inf)
256{
257 if (inf->tdesc_info == NULL)
258 inf->tdesc_info = XCNEW (struct target_desc_info);
259 return inf->tdesc_info;
260}
23181151 261
123dc839
DJ
262/* A handle for architecture-specific data associated with the
263 target description (see struct tdesc_arch_data). */
264
265static struct gdbarch_data *tdesc_data;
266
6ecd4729
PA
267/* See target-descriptions.h. */
268
269int
270target_desc_info_from_user_p (struct target_desc_info *info)
271{
272 return info != NULL && info->filename != NULL;
273}
274
275/* See target-descriptions.h. */
276
277void
278copy_inferior_target_desc_info (struct inferior *destinf, struct inferior *srcinf)
279{
280 struct target_desc_info *src = get_tdesc_info (srcinf);
281 struct target_desc_info *dest = get_tdesc_info (destinf);
282
283 dest->fetched = src->fetched;
284 dest->tdesc = src->tdesc;
285 dest->filename = src->filename != NULL ? xstrdup (src->filename) : NULL;
286}
287
288/* See target-descriptions.h. */
289
290void
291target_desc_info_free (struct target_desc_info *tdesc_info)
292{
293 if (tdesc_info != NULL)
294 {
295 xfree (tdesc_info->filename);
296 xfree (tdesc_info);
297 }
298}
299
300/* Convenience helper macros. */
301
302#define target_desc_fetched \
303 get_tdesc_info (current_inferior ())->fetched
304#define current_target_desc \
305 get_tdesc_info (current_inferior ())->tdesc
306#define target_description_filename \
307 get_tdesc_info (current_inferior ())->filename
308
309/* The string manipulated by the "set tdesc filename ..." command. */
310
311static char *tdesc_filename_cmd_string;
312
424163ea
DJ
313/* Fetch the current target's description, and switch the current
314 architecture to one which incorporates that description. */
315
316void
317target_find_description (void)
318{
319 /* If we've already fetched a description from the target, don't do
320 it again. This allows a target to fetch the description early,
321 during its to_open or to_create_inferior, if it needs extra
322 information about the target to initialize. */
323 if (target_desc_fetched)
324 return;
325
326 /* The current architecture should not have any target description
327 specified. It should have been cleared, e.g. when we
328 disconnected from the previous target. */
f5656ead 329 gdb_assert (gdbarch_target_desc (target_gdbarch ()) == NULL);
424163ea 330
23181151
DJ
331 /* First try to fetch an XML description from the user-specified
332 file. */
333 current_target_desc = NULL;
334 if (target_description_filename != NULL
335 && *target_description_filename != '\0')
336 current_target_desc
337 = file_read_description_xml (target_description_filename);
338
339 /* Next try to read the description from the current target using
340 target objects. */
341 if (current_target_desc == NULL)
342 current_target_desc = target_read_description_xml (&current_target);
343
344 /* If that failed try a target-specific hook. */
345 if (current_target_desc == NULL)
346 current_target_desc = target_read_description (&current_target);
424163ea
DJ
347
348 /* If a non-NULL description was returned, then update the current
349 architecture. */
350 if (current_target_desc)
351 {
352 struct gdbarch_info info;
353
354 gdbarch_info_init (&info);
355 info.target_desc = current_target_desc;
356 if (!gdbarch_update_p (info))
123dc839
DJ
357 warning (_("Architecture rejected target-supplied description"));
358 else
359 {
360 struct tdesc_arch_data *data;
361
19ba03f4
SM
362 data = ((struct tdesc_arch_data *)
363 gdbarch_data (target_gdbarch (), tdesc_data));
123dc839 364 if (tdesc_has_registers (current_target_desc)
ad068eab 365 && data->arch_regs == NULL)
123dc839
DJ
366 warning (_("Target-supplied registers are not supported "
367 "by the current architecture"));
368 }
424163ea
DJ
369 }
370
371 /* Now that we know this description is usable, record that we
372 fetched it. */
373 target_desc_fetched = 1;
374}
375
376/* Discard any description fetched from the current target, and switch
377 the current architecture to one with no target description. */
378
379void
380target_clear_description (void)
381{
382 struct gdbarch_info info;
383
384 if (!target_desc_fetched)
385 return;
386
387 target_desc_fetched = 0;
388 current_target_desc = NULL;
389
390 gdbarch_info_init (&info);
391 if (!gdbarch_update_p (info))
392 internal_error (__FILE__, __LINE__,
393 _("Could not remove target-supplied description"));
394}
395
396/* Return the global current target description. This should only be
397 used by gdbarch initialization code; most access should be through
398 an existing gdbarch. */
399
400const struct target_desc *
401target_current_description (void)
402{
403 if (target_desc_fetched)
404 return current_target_desc;
405
406 return NULL;
407}
e35359c5
UW
408
409/* Return non-zero if this target description is compatible
410 with the given BFD architecture. */
411
412int
413tdesc_compatible_p (const struct target_desc *target_desc,
414 const struct bfd_arch_info *arch)
415{
416 const struct bfd_arch_info *compat;
417 int ix;
418
419 for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
420 ix++)
421 {
422 if (compat == arch
423 || arch->compatible (arch, compat)
424 || compat->compatible (compat, arch))
425 return 1;
426 }
427
428 return 0;
429}
23181151
DJ
430\f
431
123dc839 432/* Direct accessors for target descriptions. */
424163ea 433
29709017
DJ
434/* Return the string value of a property named KEY, or NULL if the
435 property was not specified. */
436
437const char *
438tdesc_property (const struct target_desc *target_desc, const char *key)
439{
440 struct property *prop;
441 int ix;
442
443 for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
444 ix++)
445 if (strcmp (prop->key, key) == 0)
446 return prop->value;
447
448 return NULL;
449}
450
23181151
DJ
451/* Return the BFD architecture associated with this target
452 description, or NULL if no architecture was specified. */
453
454const struct bfd_arch_info *
455tdesc_architecture (const struct target_desc *target_desc)
456{
457 return target_desc->arch;
458}
08d16641
PA
459
460/* Return the OSABI associated with this target description, or
461 GDB_OSABI_UNKNOWN if no osabi was specified. */
462
463enum gdb_osabi
464tdesc_osabi (const struct target_desc *target_desc)
465{
466 return target_desc->osabi;
467}
468
23181151
DJ
469\f
470
123dc839
DJ
471/* Return 1 if this target description includes any registers. */
472
473int
474tdesc_has_registers (const struct target_desc *target_desc)
475{
476 int ix;
477 struct tdesc_feature *feature;
478
479 if (target_desc == NULL)
480 return 0;
481
482 for (ix = 0;
483 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
484 ix++)
485 if (! VEC_empty (tdesc_reg_p, feature->registers))
486 return 1;
487
488 return 0;
489}
490
491/* Return the feature with the given name, if present, or NULL if
492 the named feature is not found. */
493
494const struct tdesc_feature *
495tdesc_find_feature (const struct target_desc *target_desc,
496 const char *name)
497{
498 int ix;
499 struct tdesc_feature *feature;
500
501 for (ix = 0;
502 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
503 ix++)
504 if (strcmp (feature->name, name) == 0)
505 return feature;
506
507 return NULL;
508}
509
510/* Return the name of FEATURE. */
511
512const char *
513tdesc_feature_name (const struct tdesc_feature *feature)
514{
515 return feature->name;
516}
517
ad068eab
UW
518/* Predefined types. */
519static struct tdesc_type tdesc_predefined_types[] =
81adfced 520{
81516450 521 { "bool", TDESC_TYPE_BOOL },
ad068eab
UW
522 { "int8", TDESC_TYPE_INT8 },
523 { "int16", TDESC_TYPE_INT16 },
524 { "int32", TDESC_TYPE_INT32 },
525 { "int64", TDESC_TYPE_INT64 },
526 { "int128", TDESC_TYPE_INT128 },
527 { "uint8", TDESC_TYPE_UINT8 },
528 { "uint16", TDESC_TYPE_UINT16 },
529 { "uint32", TDESC_TYPE_UINT32 },
530 { "uint64", TDESC_TYPE_UINT64 },
531 { "uint128", TDESC_TYPE_UINT128 },
532 { "code_ptr", TDESC_TYPE_CODE_PTR },
533 { "data_ptr", TDESC_TYPE_DATA_PTR },
534 { "ieee_single", TDESC_TYPE_IEEE_SINGLE },
535 { "ieee_double", TDESC_TYPE_IEEE_DOUBLE },
9fd3625f 536 { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT },
a6f5ef51 537 { "i387_ext", TDESC_TYPE_I387_EXT }
ad068eab 538};
81adfced 539
81516450
DE
540/* Lookup a predefined type. */
541
542static struct tdesc_type *
543tdesc_predefined_type (enum tdesc_type_kind kind)
544{
545 int ix;
546 struct tdesc_type *type;
547
548 for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
549 if (tdesc_predefined_types[ix].kind == kind)
550 return &tdesc_predefined_types[ix];
551
552 gdb_assert_not_reached ("bad predefined tdesc type");
553}
554
123dc839
DJ
555/* Return the type associated with ID in the context of FEATURE, or
556 NULL if none. */
557
ad068eab 558struct tdesc_type *
123dc839
DJ
559tdesc_named_type (const struct tdesc_feature *feature, const char *id)
560{
561 int ix;
ad068eab 562 struct tdesc_type *type;
123dc839
DJ
563
564 /* First try target-defined types. */
ad068eab
UW
565 for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
566 if (strcmp (type->name, id) == 0)
567 return type;
123dc839 568
81adfced
DJ
569 /* Next try the predefined types. */
570 for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
571 if (strcmp (tdesc_predefined_types[ix].name, id) == 0)
ad068eab 572 return &tdesc_predefined_types[ix];
123dc839
DJ
573
574 return NULL;
575}
ad068eab 576
9fd3625f
L
577/* Lookup type associated with ID. */
578
579struct type *
580tdesc_find_type (struct gdbarch *gdbarch, const char *id)
581{
582 struct tdesc_arch_reg *reg;
583 struct tdesc_arch_data *data;
584 int i, num_regs;
585
19ba03f4 586 data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
9fd3625f
L
587 num_regs = VEC_length (tdesc_arch_reg, data->arch_regs);
588 for (i = 0; i < num_regs; i++)
589 {
590 reg = VEC_index (tdesc_arch_reg, data->arch_regs, i);
591 if (reg->reg
592 && reg->reg->tdesc_type
593 && reg->type
594 && strcmp (id, reg->reg->tdesc_type->name) == 0)
595 return reg->type;
596 }
597
598 return NULL;
599}
600
ad068eab
UW
601/* Construct, if necessary, and return the GDB type implementing target
602 type TDESC_TYPE for architecture GDBARCH. */
603
604static struct type *
605tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
606{
9fd3625f
L
607 struct type *type;
608
ad068eab
UW
609 switch (tdesc_type->kind)
610 {
611 /* Predefined types. */
81516450
DE
612 case TDESC_TYPE_BOOL:
613 return builtin_type (gdbarch)->builtin_bool;
614
ad068eab 615 case TDESC_TYPE_INT8:
df4df182 616 return builtin_type (gdbarch)->builtin_int8;
ad068eab
UW
617
618 case TDESC_TYPE_INT16:
df4df182 619 return builtin_type (gdbarch)->builtin_int16;
ad068eab
UW
620
621 case TDESC_TYPE_INT32:
df4df182 622 return builtin_type (gdbarch)->builtin_int32;
ad068eab
UW
623
624 case TDESC_TYPE_INT64:
df4df182 625 return builtin_type (gdbarch)->builtin_int64;
ad068eab
UW
626
627 case TDESC_TYPE_INT128:
df4df182 628 return builtin_type (gdbarch)->builtin_int128;
ad068eab
UW
629
630 case TDESC_TYPE_UINT8:
df4df182 631 return builtin_type (gdbarch)->builtin_uint8;
ad068eab
UW
632
633 case TDESC_TYPE_UINT16:
df4df182 634 return builtin_type (gdbarch)->builtin_uint16;
ad068eab
UW
635
636 case TDESC_TYPE_UINT32:
df4df182 637 return builtin_type (gdbarch)->builtin_uint32;
ad068eab
UW
638
639 case TDESC_TYPE_UINT64:
df4df182 640 return builtin_type (gdbarch)->builtin_uint64;
ad068eab
UW
641
642 case TDESC_TYPE_UINT128:
df4df182 643 return builtin_type (gdbarch)->builtin_uint128;
ad068eab
UW
644
645 case TDESC_TYPE_CODE_PTR:
646 return builtin_type (gdbarch)->builtin_func_ptr;
647
648 case TDESC_TYPE_DATA_PTR:
649 return builtin_type (gdbarch)->builtin_data_ptr;
650
9fd3625f
L
651 default:
652 break;
653 }
654
655 type = tdesc_find_type (gdbarch, tdesc_type->name);
656 if (type)
657 return type;
658
659 switch (tdesc_type->kind)
660 {
ad068eab 661 case TDESC_TYPE_IEEE_SINGLE:
e9bb382b 662 return arch_float_type (gdbarch, -1, "builtin_type_ieee_single",
27067745 663 floatformats_ieee_single);
ad068eab
UW
664
665 case TDESC_TYPE_IEEE_DOUBLE:
e9bb382b 666 return arch_float_type (gdbarch, -1, "builtin_type_ieee_double",
27067745 667 floatformats_ieee_double);
ad068eab
UW
668
669 case TDESC_TYPE_ARM_FPA_EXT:
e9bb382b 670 return arch_float_type (gdbarch, -1, "builtin_type_arm_ext",
27067745 671 floatformats_arm_ext);
ad068eab 672
9fd3625f
L
673 case TDESC_TYPE_I387_EXT:
674 return arch_float_type (gdbarch, -1, "builtin_type_i387_ext",
675 floatformats_i387_ext);
676
ad068eab
UW
677 /* Types defined by a target feature. */
678 case TDESC_TYPE_VECTOR:
679 {
680 struct type *type, *field_type;
681
682 field_type = tdesc_gdb_type (gdbarch, tdesc_type->u.v.type);
683 type = init_vector_type (field_type, tdesc_type->u.v.count);
684 TYPE_NAME (type) = xstrdup (tdesc_type->name);
685
686 return type;
687 }
688
f5dff777
DJ
689 case TDESC_TYPE_STRUCT:
690 {
691 struct type *type, *field_type;
692 struct tdesc_type_field *f;
693 int ix;
694
695 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
696 TYPE_NAME (type) = xstrdup (tdesc_type->name);
697 TYPE_TAG_NAME (type) = TYPE_NAME (type);
698
699 for (ix = 0;
700 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
701 ix++)
702 {
81516450 703 if (f->start != -1 && f->end != -1)
f5dff777
DJ
704 {
705 /* Bitfield. */
706 struct field *fld;
707 struct type *field_type;
708 int bitsize, total_size;
709
81516450 710 /* This invariant should be preserved while creating types. */
f5dff777 711 gdb_assert (tdesc_type->u.u.size != 0);
81516450
DE
712 if (f->type != NULL)
713 field_type = tdesc_gdb_type (gdbarch, f->type);
714 else if (tdesc_type->u.u.size > 4)
f5dff777
DJ
715 field_type = builtin_type (gdbarch)->builtin_uint64;
716 else
717 field_type = builtin_type (gdbarch)->builtin_uint32;
718
719 fld = append_composite_type_field_raw (type, xstrdup (f->name),
720 field_type);
721
722 /* For little-endian, BITPOS counts from the LSB of
723 the structure and marks the LSB of the field. For
724 big-endian, BITPOS counts from the MSB of the
725 structure and marks the MSB of the field. Either
726 way, it is the number of bits to the "left" of the
727 field. To calculate this in big-endian, we need
728 the total size of the structure. */
729 bitsize = f->end - f->start + 1;
730 total_size = tdesc_type->u.u.size * TARGET_CHAR_BIT;
731 if (gdbarch_bits_big_endian (gdbarch))
f41f5e61 732 SET_FIELD_BITPOS (fld[0], total_size - f->start - bitsize);
f5dff777 733 else
f41f5e61 734 SET_FIELD_BITPOS (fld[0], f->start);
f5dff777
DJ
735 FIELD_BITSIZE (fld[0]) = bitsize;
736 }
737 else
738 {
81516450 739 gdb_assert (f->start == -1 && f->end == -1);
f5dff777
DJ
740 field_type = tdesc_gdb_type (gdbarch, f->type);
741 append_composite_type_field (type, xstrdup (f->name),
742 field_type);
743 }
744 }
745
746 if (tdesc_type->u.u.size != 0)
747 TYPE_LENGTH (type) = tdesc_type->u.u.size;
748 return type;
749 }
750
ad068eab
UW
751 case TDESC_TYPE_UNION:
752 {
753 struct type *type, *field_type;
754 struct tdesc_type_field *f;
755 int ix;
756
e9bb382b 757 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
ad068eab
UW
758 TYPE_NAME (type) = xstrdup (tdesc_type->name);
759
760 for (ix = 0;
761 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
762 ix++)
763 {
764 field_type = tdesc_gdb_type (gdbarch, f->type);
765 append_composite_type_field (type, xstrdup (f->name), field_type);
766
f5dff777 767 /* If any of the children of a union are vectors, flag the
ad068eab
UW
768 union as a vector also. This allows e.g. a union of two
769 vector types to show up automatically in "info vector". */
770 if (TYPE_VECTOR (field_type))
771 TYPE_VECTOR (type) = 1;
772 }
f5dff777
DJ
773 return type;
774 }
775
776 case TDESC_TYPE_FLAGS:
777 {
81516450 778 struct tdesc_type_field *f;
f5dff777
DJ
779 int ix;
780
3494b66d 781 type = arch_flags_type (gdbarch, tdesc_type->name,
81516450
DE
782 tdesc_type->u.u.size);
783 for (ix = 0;
784 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
785 ix++)
786 {
787 struct type *field_type;
788 int bitsize = f->end - f->start + 1;
789
790 gdb_assert (f->type != NULL);
791 field_type = tdesc_gdb_type (gdbarch, f->type);
792 append_flags_type_field (type, f->start, bitsize,
793 field_type, f->name);
794 }
795
796 return type;
797 }
798
799 case TDESC_TYPE_ENUM:
800 {
801 struct tdesc_type_field *f;
802 int ix;
803
804 type = arch_type (gdbarch, TYPE_CODE_ENUM,
805 tdesc_type->u.u.size, tdesc_type->name);
806 TYPE_UNSIGNED (type) = 1;
f5dff777 807 for (ix = 0;
81516450 808 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
f5dff777 809 ix++)
81516450
DE
810 {
811 struct field *fld
812 = append_composite_type_field_raw (type, xstrdup (f->name),
813 NULL);
814
815 SET_FIELD_BITPOS (fld[0], f->start);
816 }
ad068eab
UW
817
818 return type;
819 }
820 }
821
822 internal_error (__FILE__, __LINE__,
823 "Type \"%s\" has an unknown kind %d",
824 tdesc_type->name, tdesc_type->kind);
825}
123dc839
DJ
826\f
827
828/* Support for registers from target descriptions. */
829
830/* Construct the per-gdbarch data. */
831
832static void *
833tdesc_data_init (struct obstack *obstack)
834{
835 struct tdesc_arch_data *data;
836
837 data = OBSTACK_ZALLOC (obstack, struct tdesc_arch_data);
838 return data;
839}
840
841/* Similar, but for the temporary copy used during architecture
842 initialization. */
843
844struct tdesc_arch_data *
845tdesc_data_alloc (void)
846{
41bf6aca 847 return XCNEW (struct tdesc_arch_data);
123dc839
DJ
848}
849
850/* Free something allocated by tdesc_data_alloc, if it is not going
851 to be used (for instance if it was unsuitable for the
852 architecture). */
853
854void
855tdesc_data_cleanup (void *data_untyped)
856{
19ba03f4 857 struct tdesc_arch_data *data = (struct tdesc_arch_data *) data_untyped;
123dc839 858
ad068eab 859 VEC_free (tdesc_arch_reg, data->arch_regs);
123dc839
DJ
860 xfree (data);
861}
862
863/* Search FEATURE for a register named NAME. */
864
7cc46491
DJ
865static struct tdesc_reg *
866tdesc_find_register_early (const struct tdesc_feature *feature,
867 const char *name)
123dc839
DJ
868{
869 int ixr;
870 struct tdesc_reg *reg;
871
872 for (ixr = 0;
873 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
874 ixr++)
875 if (strcasecmp (reg->name, name) == 0)
7cc46491 876 return reg;
123dc839 877
7cc46491
DJ
878 return NULL;
879}
880
881/* Search FEATURE for a register named NAME. Assign REGNO to it. */
882
883int
884tdesc_numbered_register (const struct tdesc_feature *feature,
885 struct tdesc_arch_data *data,
886 int regno, const char *name)
887{
ad068eab 888 struct tdesc_arch_reg arch_reg = { 0 };
7cc46491
DJ
889 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
890
891 if (reg == NULL)
892 return 0;
893
894 /* Make sure the vector includes a REGNO'th element. */
ad068eab
UW
895 while (regno >= VEC_length (tdesc_arch_reg, data->arch_regs))
896 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &arch_reg);
897
898 arch_reg.reg = reg;
899 VEC_replace (tdesc_arch_reg, data->arch_regs, regno, &arch_reg);
7cc46491 900 return 1;
123dc839
DJ
901}
902
58d6951d
DJ
903/* Search FEATURE for a register named NAME, but do not assign a fixed
904 register number to it. */
905
906int
907tdesc_unnumbered_register (const struct tdesc_feature *feature,
908 const char *name)
909{
910 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
911
912 if (reg == NULL)
913 return 0;
914
915 return 1;
916}
917
7cc46491
DJ
918/* Search FEATURE for a register whose name is in NAMES and assign
919 REGNO to it. */
123dc839
DJ
920
921int
922tdesc_numbered_register_choices (const struct tdesc_feature *feature,
923 struct tdesc_arch_data *data,
924 int regno, const char *const names[])
925{
926 int i;
927
928 for (i = 0; names[i] != NULL; i++)
929 if (tdesc_numbered_register (feature, data, regno, names[i]))
930 return 1;
931
932 return 0;
933}
934
7cc46491
DJ
935/* Search FEATURE for a register named NAME, and return its size in
936 bits. The register must exist. */
937
938int
939tdesc_register_size (const struct tdesc_feature *feature,
940 const char *name)
941{
942 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
943
944 gdb_assert (reg != NULL);
945 return reg->bitsize;
946}
947
123dc839
DJ
948/* Look up a register by its GDB internal register number. */
949
ad068eab
UW
950static struct tdesc_arch_reg *
951tdesc_find_arch_register (struct gdbarch *gdbarch, int regno)
123dc839 952{
123dc839
DJ
953 struct tdesc_arch_data *data;
954
19ba03f4 955 data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
ad068eab
UW
956 if (regno < VEC_length (tdesc_arch_reg, data->arch_regs))
957 return VEC_index (tdesc_arch_reg, data->arch_regs, regno);
123dc839
DJ
958 else
959 return NULL;
960}
961
ad068eab
UW
962static struct tdesc_reg *
963tdesc_find_register (struct gdbarch *gdbarch, int regno)
964{
965 struct tdesc_arch_reg *reg = tdesc_find_arch_register (gdbarch, regno);
5d502164 966
ad068eab
UW
967 return reg? reg->reg : NULL;
968}
969
f8b73d13
DJ
970/* Return the name of register REGNO, from the target description or
971 from an architecture-provided pseudo_register_name method. */
972
973const char *
d93859e2 974tdesc_register_name (struct gdbarch *gdbarch, int regno)
123dc839 975{
d93859e2
UW
976 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
977 int num_regs = gdbarch_num_regs (gdbarch);
978 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
123dc839
DJ
979
980 if (reg != NULL)
981 return reg->name;
982
983 if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
984 {
19ba03f4
SM
985 struct tdesc_arch_data *data
986 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
5d502164 987
123dc839 988 gdb_assert (data->pseudo_register_name != NULL);
d93859e2 989 return data->pseudo_register_name (gdbarch, regno);
123dc839
DJ
990 }
991
992 return "";
993}
994
58d6951d 995struct type *
123dc839
DJ
996tdesc_register_type (struct gdbarch *gdbarch, int regno)
997{
ad068eab
UW
998 struct tdesc_arch_reg *arch_reg = tdesc_find_arch_register (gdbarch, regno);
999 struct tdesc_reg *reg = arch_reg? arch_reg->reg : NULL;
123dc839
DJ
1000 int num_regs = gdbarch_num_regs (gdbarch);
1001 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
1002
1003 if (reg == NULL && regno >= num_regs && regno < num_regs + num_pseudo_regs)
1004 {
19ba03f4
SM
1005 struct tdesc_arch_data *data
1006 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
5d502164 1007
123dc839
DJ
1008 gdb_assert (data->pseudo_register_type != NULL);
1009 return data->pseudo_register_type (gdbarch, regno);
1010 }
1011
1012 if (reg == NULL)
1013 /* Return "int0_t", since "void" has a misleading size of one. */
df4df182 1014 return builtin_type (gdbarch)->builtin_int0;
123dc839 1015
ad068eab 1016 if (arch_reg->type == NULL)
123dc839 1017 {
ad068eab
UW
1018 /* First check for a predefined or target defined type. */
1019 if (reg->tdesc_type)
1020 arch_reg->type = tdesc_gdb_type (gdbarch, reg->tdesc_type);
1021
1022 /* Next try size-sensitive type shortcuts. */
1023 else if (strcmp (reg->type, "float") == 0)
1024 {
1025 if (reg->bitsize == gdbarch_float_bit (gdbarch))
1026 arch_reg->type = builtin_type (gdbarch)->builtin_float;
1027 else if (reg->bitsize == gdbarch_double_bit (gdbarch))
1028 arch_reg->type = builtin_type (gdbarch)->builtin_double;
1029 else if (reg->bitsize == gdbarch_long_double_bit (gdbarch))
1030 arch_reg->type = builtin_type (gdbarch)->builtin_long_double;
1031 else
1032 {
1033 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
1034 reg->name, reg->bitsize);
1035 arch_reg->type = builtin_type (gdbarch)->builtin_double;
1036 }
1037 }
1038 else if (strcmp (reg->type, "int") == 0)
1039 {
1040 if (reg->bitsize == gdbarch_long_bit (gdbarch))
1041 arch_reg->type = builtin_type (gdbarch)->builtin_long;
1042 else if (reg->bitsize == TARGET_CHAR_BIT)
1043 arch_reg->type = builtin_type (gdbarch)->builtin_char;
1044 else if (reg->bitsize == gdbarch_short_bit (gdbarch))
1045 arch_reg->type = builtin_type (gdbarch)->builtin_short;
1046 else if (reg->bitsize == gdbarch_int_bit (gdbarch))
1047 arch_reg->type = builtin_type (gdbarch)->builtin_int;
1048 else if (reg->bitsize == gdbarch_long_long_bit (gdbarch))
1049 arch_reg->type = builtin_type (gdbarch)->builtin_long_long;
1050 else if (reg->bitsize == gdbarch_ptr_bit (gdbarch))
c378eb4e 1051 /* A bit desperate by this point... */
ad068eab
UW
1052 arch_reg->type = builtin_type (gdbarch)->builtin_data_ptr;
1053 else
1054 {
1055 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
1056 reg->name, reg->bitsize);
1057 arch_reg->type = builtin_type (gdbarch)->builtin_long;
1058 }
1059 }
1060
1061 if (arch_reg->type == NULL)
1062 internal_error (__FILE__, __LINE__,
1063 "Register \"%s\" has an unknown type \"%s\"",
1064 reg->name, reg->type);
123dc839 1065 }
123dc839 1066
ad068eab 1067 return arch_reg->type;
123dc839
DJ
1068}
1069
1070static int
1071tdesc_remote_register_number (struct gdbarch *gdbarch, int regno)
1072{
1073 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
1074
1075 if (reg != NULL)
1076 return reg->target_regnum;
1077 else
1078 return -1;
1079}
1080
1081/* Check whether REGNUM is a member of REGGROUP. Registers from the
1082 target description may be classified as general, float, or vector.
f8b73d13
DJ
1083 Unlike a gdbarch register_reggroup_p method, this function will
1084 return -1 if it does not know; the caller should handle registers
1085 with no specified group.
123dc839
DJ
1086
1087 Arbitrary strings (other than "general", "float", and "vector")
1088 from the description are not used; they cause the register to be
1089 displayed in "info all-registers" but excluded from "info
1090 registers" et al. The names of containing features are also not
1091 used. This might be extended to display registers in some more
1092 useful groupings.
1093
1094 The save-restore flag is also implemented here. */
1095
f8b73d13
DJ
1096int
1097tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
1098 struct reggroup *reggroup)
123dc839 1099{
123dc839
DJ
1100 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
1101
123dc839
DJ
1102 if (reg != NULL && reg->group != NULL)
1103 {
1104 int general_p = 0, float_p = 0, vector_p = 0;
1105
1106 if (strcmp (reg->group, "general") == 0)
1107 general_p = 1;
1108 else if (strcmp (reg->group, "float") == 0)
1109 float_p = 1;
1110 else if (strcmp (reg->group, "vector") == 0)
1111 vector_p = 1;
1112
1113 if (reggroup == float_reggroup)
1114 return float_p;
1115
1116 if (reggroup == vector_reggroup)
1117 return vector_p;
1118
1119 if (reggroup == general_reggroup)
1120 return general_p;
1121 }
1122
1123 if (reg != NULL
1124 && (reggroup == save_reggroup || reggroup == restore_reggroup))
1125 return reg->save_restore;
1126
f8b73d13
DJ
1127 return -1;
1128}
1129
1130/* Check whether REGNUM is a member of REGGROUP. Registers with no
1131 group specified go to the default reggroup function and are handled
1132 by type. */
1133
1134static int
1135tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regno,
1136 struct reggroup *reggroup)
1137{
1138 int num_regs = gdbarch_num_regs (gdbarch);
1139 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
1140 int ret;
1141
1142 if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
1143 {
19ba03f4
SM
1144 struct tdesc_arch_data *data
1145 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
5d502164 1146
58d6951d
DJ
1147 if (data->pseudo_register_reggroup_p != NULL)
1148 return data->pseudo_register_reggroup_p (gdbarch, regno, reggroup);
1149 /* Otherwise fall through to the default reggroup_p. */
f8b73d13
DJ
1150 }
1151
1152 ret = tdesc_register_in_reggroup_p (gdbarch, regno, reggroup);
1153 if (ret != -1)
1154 return ret;
1155
123dc839
DJ
1156 return default_register_reggroup_p (gdbarch, regno, reggroup);
1157}
1158
1159/* Record architecture-specific functions to call for pseudo-register
1160 support. */
1161
1162void
1163set_tdesc_pseudo_register_name (struct gdbarch *gdbarch,
1164 gdbarch_register_name_ftype *pseudo_name)
1165{
19ba03f4
SM
1166 struct tdesc_arch_data *data
1167 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
123dc839
DJ
1168
1169 data->pseudo_register_name = pseudo_name;
1170}
1171
1172void
1173set_tdesc_pseudo_register_type (struct gdbarch *gdbarch,
1174 gdbarch_register_type_ftype *pseudo_type)
1175{
19ba03f4
SM
1176 struct tdesc_arch_data *data
1177 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
123dc839
DJ
1178
1179 data->pseudo_register_type = pseudo_type;
1180}
1181
1182void
1183set_tdesc_pseudo_register_reggroup_p
1184 (struct gdbarch *gdbarch,
1185 gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p)
1186{
19ba03f4
SM
1187 struct tdesc_arch_data *data
1188 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
123dc839
DJ
1189
1190 data->pseudo_register_reggroup_p = pseudo_reggroup_p;
1191}
1192
1193/* Update GDBARCH to use the target description for registers. */
1194
1195void
1196tdesc_use_registers (struct gdbarch *gdbarch,
7cc46491 1197 const struct target_desc *target_desc,
123dc839
DJ
1198 struct tdesc_arch_data *early_data)
1199{
1200 int num_regs = gdbarch_num_regs (gdbarch);
c6913b7d 1201 int ixf, ixr;
123dc839
DJ
1202 struct tdesc_feature *feature;
1203 struct tdesc_reg *reg;
1204 struct tdesc_arch_data *data;
ad068eab 1205 struct tdesc_arch_reg *arch_reg, new_arch_reg = { 0 };
123dc839
DJ
1206 htab_t reg_hash;
1207
123dc839
DJ
1208 /* We can't use the description for registers if it doesn't describe
1209 any. This function should only be called after validating
1210 registers, so the caller should know that registers are
1211 included. */
1212 gdb_assert (tdesc_has_registers (target_desc));
1213
19ba03f4 1214 data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
ad068eab 1215 data->arch_regs = early_data->arch_regs;
123dc839
DJ
1216 xfree (early_data);
1217
1218 /* Build up a set of all registers, so that we can assign register
1219 numbers where needed. The hash table expands as necessary, so
1220 the initial size is arbitrary. */
1221 reg_hash = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1222 for (ixf = 0;
1223 VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
1224 ixf++)
1225 for (ixr = 0;
1226 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
1227 ixr++)
1228 {
1229 void **slot = htab_find_slot (reg_hash, reg, INSERT);
1230
1231 *slot = reg;
1232 }
1233
1234 /* Remove any registers which were assigned numbers by the
1235 architecture. */
ad068eab
UW
1236 for (ixr = 0;
1237 VEC_iterate (tdesc_arch_reg, data->arch_regs, ixr, arch_reg);
1238 ixr++)
1239 if (arch_reg->reg)
1240 htab_remove_elt (reg_hash, arch_reg->reg);
123dc839
DJ
1241
1242 /* Assign numbers to the remaining registers and add them to the
f57d151a 1243 list of registers. The new numbers are always above gdbarch_num_regs.
123dc839
DJ
1244 Iterate over the features, not the hash table, so that the order
1245 matches that in the target description. */
1246
ad068eab
UW
1247 gdb_assert (VEC_length (tdesc_arch_reg, data->arch_regs) <= num_regs);
1248 while (VEC_length (tdesc_arch_reg, data->arch_regs) < num_regs)
1249 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
123dc839
DJ
1250 for (ixf = 0;
1251 VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
1252 ixf++)
1253 for (ixr = 0;
1254 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
1255 ixr++)
1256 if (htab_find (reg_hash, reg) != NULL)
1257 {
ad068eab
UW
1258 new_arch_reg.reg = reg;
1259 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
123dc839
DJ
1260 num_regs++;
1261 }
1262
1263 htab_delete (reg_hash);
1264
1265 /* Update the architecture. */
1266 set_gdbarch_num_regs (gdbarch, num_regs);
1267 set_gdbarch_register_name (gdbarch, tdesc_register_name);
1268 set_gdbarch_register_type (gdbarch, tdesc_register_type);
1269 set_gdbarch_remote_register_number (gdbarch,
1270 tdesc_remote_register_number);
1271 set_gdbarch_register_reggroup_p (gdbarch, tdesc_register_reggroup_p);
1272}
1273\f
1274
424163ea
DJ
1275/* Methods for constructing a target description. */
1276
123dc839
DJ
1277static void
1278tdesc_free_reg (struct tdesc_reg *reg)
1279{
1280 xfree (reg->name);
1281 xfree (reg->type);
1282 xfree (reg->group);
1283 xfree (reg);
1284}
1285
1286void
1287tdesc_create_reg (struct tdesc_feature *feature, const char *name,
1288 int regnum, int save_restore, const char *group,
1289 int bitsize, const char *type)
1290{
41bf6aca 1291 struct tdesc_reg *reg = XCNEW (struct tdesc_reg);
123dc839
DJ
1292
1293 reg->name = xstrdup (name);
1294 reg->target_regnum = regnum;
1295 reg->save_restore = save_restore;
1296 reg->group = group ? xstrdup (group) : NULL;
1297 reg->bitsize = bitsize;
c8c12293 1298 reg->type = type ? xstrdup (type) : xstrdup ("<unknown>");
123dc839
DJ
1299
1300 /* If the register's type is target-defined, look it up now. We may not
1301 have easy access to the containing feature when we want it later. */
ad068eab 1302 reg->tdesc_type = tdesc_named_type (feature, reg->type);
123dc839
DJ
1303
1304 VEC_safe_push (tdesc_reg_p, feature->registers, reg);
1305}
1306
81516450
DE
1307/* Subroutine of tdesc_free_feature to simplify it.
1308 Note: We do not want to free any referenced types here (e.g., types of
1309 fields of a struct). All types of a feature are recorded in
1310 feature->types and are freed that way. */
1311
ad068eab
UW
1312static void
1313tdesc_free_type (struct tdesc_type *type)
1314{
ad068eab
UW
1315 switch (type->kind)
1316 {
f5dff777 1317 case TDESC_TYPE_STRUCT:
ad068eab 1318 case TDESC_TYPE_UNION:
81516450
DE
1319 case TDESC_TYPE_FLAGS:
1320 case TDESC_TYPE_ENUM:
ad068eab
UW
1321 {
1322 struct tdesc_type_field *f;
1323 int ix;
1324
1325 for (ix = 0;
1326 VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f);
1327 ix++)
1328 xfree (f->name);
1329
1330 VEC_free (tdesc_type_field, type->u.u.fields);
1331 }
1332 break;
1333
1334 default:
1335 break;
1336 }
1337
1338 xfree (type->name);
1339 xfree (type);
1340}
1341
1342struct tdesc_type *
1343tdesc_create_vector (struct tdesc_feature *feature, const char *name,
1344 struct tdesc_type *field_type, int count)
1345{
41bf6aca 1346 struct tdesc_type *type = XCNEW (struct tdesc_type);
ad068eab
UW
1347
1348 type->name = xstrdup (name);
1349 type->kind = TDESC_TYPE_VECTOR;
1350 type->u.v.type = field_type;
1351 type->u.v.count = count;
1352
1353 VEC_safe_push (tdesc_type_p, feature->types, type);
1354 return type;
1355}
1356
f5dff777
DJ
1357struct tdesc_type *
1358tdesc_create_struct (struct tdesc_feature *feature, const char *name)
1359{
41bf6aca 1360 struct tdesc_type *type = XCNEW (struct tdesc_type);
f5dff777
DJ
1361
1362 type->name = xstrdup (name);
1363 type->kind = TDESC_TYPE_STRUCT;
1364
1365 VEC_safe_push (tdesc_type_p, feature->types, type);
1366 return type;
1367}
1368
1369/* Set the total length of TYPE. Structs which contain bitfields may
1370 omit the reserved bits, so the end of the last field may not
1371 suffice. */
1372
1373void
54157a25 1374tdesc_set_struct_size (struct tdesc_type *type, int size)
f5dff777
DJ
1375{
1376 gdb_assert (type->kind == TDESC_TYPE_STRUCT);
54157a25 1377 gdb_assert (size > 0);
f5dff777
DJ
1378 type->u.u.size = size;
1379}
1380
ad068eab
UW
1381struct tdesc_type *
1382tdesc_create_union (struct tdesc_feature *feature, const char *name)
1383{
41bf6aca 1384 struct tdesc_type *type = XCNEW (struct tdesc_type);
ad068eab
UW
1385
1386 type->name = xstrdup (name);
1387 type->kind = TDESC_TYPE_UNION;
1388
1389 VEC_safe_push (tdesc_type_p, feature->types, type);
1390 return type;
1391}
1392
f5dff777
DJ
1393struct tdesc_type *
1394tdesc_create_flags (struct tdesc_feature *feature, const char *name,
54157a25 1395 int size)
f5dff777 1396{
41bf6aca 1397 struct tdesc_type *type = XCNEW (struct tdesc_type);
f5dff777 1398
54157a25
DE
1399 gdb_assert (size > 0);
1400
f5dff777
DJ
1401 type->name = xstrdup (name);
1402 type->kind = TDESC_TYPE_FLAGS;
81516450 1403 type->u.u.size = size;
f5dff777
DJ
1404
1405 VEC_safe_push (tdesc_type_p, feature->types, type);
1406 return type;
1407}
1408
81516450
DE
1409struct tdesc_type *
1410tdesc_create_enum (struct tdesc_feature *feature, const char *name,
1411 int size)
1412{
1413 struct tdesc_type *type = XCNEW (struct tdesc_type);
1414
1415 gdb_assert (size > 0);
1416
1417 type->name = xstrdup (name);
1418 type->kind = TDESC_TYPE_ENUM;
1419 type->u.u.size = size;
1420
1421 VEC_safe_push (tdesc_type_p, feature->types, type);
1422 return type;
1423}
1424
1425/* Add a new field to TYPE. */
f5dff777 1426
ad068eab
UW
1427void
1428tdesc_add_field (struct tdesc_type *type, const char *field_name,
1429 struct tdesc_type *field_type)
1430{
1431 struct tdesc_type_field f = { 0 };
1432
f5dff777
DJ
1433 gdb_assert (type->kind == TDESC_TYPE_UNION
1434 || type->kind == TDESC_TYPE_STRUCT);
ad068eab
UW
1435
1436 f.name = xstrdup (field_name);
1437 f.type = field_type;
81516450
DE
1438 /* Initialize these values so we know this is not a bit-field
1439 when we print-c-tdesc. */
1440 f.start = -1;
1441 f.end = -1;
ad068eab
UW
1442
1443 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1444}
1445
81516450 1446/* Add a new typed bitfield to TYPE. */
f5dff777
DJ
1447
1448void
81516450
DE
1449tdesc_add_typed_bitfield (struct tdesc_type *type, const char *field_name,
1450 int start, int end, struct tdesc_type *field_type)
f5dff777
DJ
1451{
1452 struct tdesc_type_field f = { 0 };
1453
81516450
DE
1454 gdb_assert (type->kind == TDESC_TYPE_STRUCT
1455 || type->kind == TDESC_TYPE_FLAGS);
1456 gdb_assert (start >= 0 && end >= start);
f5dff777
DJ
1457
1458 f.name = xstrdup (field_name);
1459 f.start = start;
1460 f.end = end;
81516450 1461 f.type = field_type;
f5dff777
DJ
1462
1463 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1464}
1465
81516450
DE
1466/* Add a new untyped bitfield to TYPE.
1467 Untyped bitfields become either uint32 or uint64 depending on the size
1468 of the underlying type. */
1469
1470void
1471tdesc_add_bitfield (struct tdesc_type *type, const char *field_name,
1472 int start, int end)
1473{
1474 struct tdesc_type *field_type;
1475
1476 gdb_assert (start >= 0 && end >= start);
1477
1478 if (type->u.u.size > 4)
1479 field_type = tdesc_predefined_type (TDESC_TYPE_UINT64);
1480 else
1481 field_type = tdesc_predefined_type (TDESC_TYPE_UINT32);
1482
1483 tdesc_add_typed_bitfield (type, field_name, start, end, field_type);
1484}
1485
1486/* A flag is just a typed(bool) single-bit bitfield.
1487 This function is kept to minimize changes in generated files. */
1488
f5dff777
DJ
1489void
1490tdesc_add_flag (struct tdesc_type *type, int start,
1491 const char *flag_name)
1492{
81516450 1493 struct tdesc_type_field f = { 0 };
f5dff777 1494
81516450
DE
1495 gdb_assert (type->kind == TDESC_TYPE_FLAGS
1496 || type->kind == TDESC_TYPE_STRUCT);
f5dff777
DJ
1497
1498 f.name = xstrdup (flag_name);
1499 f.start = start;
81516450
DE
1500 f.end = start;
1501 f.type = tdesc_predefined_type (TDESC_TYPE_BOOL);
f5dff777 1502
81516450
DE
1503 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1504}
1505
1506void
1507tdesc_add_enum_value (struct tdesc_type *type, int value,
1508 const char *name)
1509{
1510 struct tdesc_type_field f = { 0 };
1511
1512 gdb_assert (type->kind == TDESC_TYPE_ENUM);
1513
1514 f.name = xstrdup (name);
1515 f.start = value;
1516 f.end = -1;
1517 f.type = tdesc_predefined_type (TDESC_TYPE_INT32);
1518
1519 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
f5dff777
DJ
1520}
1521
123dc839
DJ
1522static void
1523tdesc_free_feature (struct tdesc_feature *feature)
1524{
1525 struct tdesc_reg *reg;
ad068eab 1526 struct tdesc_type *type;
123dc839
DJ
1527 int ix;
1528
1529 for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++)
1530 tdesc_free_reg (reg);
1531 VEC_free (tdesc_reg_p, feature->registers);
1532
ad068eab
UW
1533 for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
1534 tdesc_free_type (type);
1535 VEC_free (tdesc_type_p, feature->types);
123dc839
DJ
1536
1537 xfree (feature->name);
1538 xfree (feature);
1539}
1540
1541struct tdesc_feature *
1542tdesc_create_feature (struct target_desc *tdesc, const char *name)
1543{
41bf6aca 1544 struct tdesc_feature *new_feature = XCNEW (struct tdesc_feature);
123dc839
DJ
1545
1546 new_feature->name = xstrdup (name);
1547
1548 VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature);
1549 return new_feature;
1550}
1551
424163ea
DJ
1552struct target_desc *
1553allocate_target_description (void)
1554{
41bf6aca 1555 return XCNEW (struct target_desc);
424163ea 1556}
29709017 1557
23181151
DJ
1558static void
1559free_target_description (void *arg)
1560{
19ba03f4 1561 struct target_desc *target_desc = (struct target_desc *) arg;
123dc839 1562 struct tdesc_feature *feature;
23181151
DJ
1563 struct property *prop;
1564 int ix;
1565
123dc839
DJ
1566 for (ix = 0;
1567 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
1568 ix++)
1569 tdesc_free_feature (feature);
1570 VEC_free (tdesc_feature_p, target_desc->features);
1571
23181151
DJ
1572 for (ix = 0;
1573 VEC_iterate (property_s, target_desc->properties, ix, prop);
1574 ix++)
1575 {
1576 xfree (prop->key);
1577 xfree (prop->value);
1578 }
1579 VEC_free (property_s, target_desc->properties);
1580
e35359c5
UW
1581 VEC_free (arch_p, target_desc->compatible);
1582
23181151
DJ
1583 xfree (target_desc);
1584}
1585
1586struct cleanup *
1587make_cleanup_free_target_description (struct target_desc *target_desc)
1588{
1589 return make_cleanup (free_target_description, target_desc);
1590}
1591
e35359c5
UW
1592void
1593tdesc_add_compatible (struct target_desc *target_desc,
1594 const struct bfd_arch_info *compatible)
1595{
1596 const struct bfd_arch_info *compat;
1597 int ix;
1598
1599 /* If this instance of GDB is compiled without BFD support for the
1600 compatible architecture, simply ignore it -- we would not be able
1601 to handle it anyway. */
1602 if (compatible == NULL)
1603 return;
1604
1605 for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
1606 ix++)
1607 if (compat == compatible)
1608 internal_error (__FILE__, __LINE__,
1609 _("Attempted to add duplicate "
1610 "compatible architecture \"%s\""),
1611 compatible->printable_name);
1612
1613 VEC_safe_push (arch_p, target_desc->compatible, compatible);
1614}
1615
29709017
DJ
1616void
1617set_tdesc_property (struct target_desc *target_desc,
1618 const char *key, const char *value)
1619{
1620 struct property *prop, new_prop;
1621 int ix;
1622
1623 gdb_assert (key != NULL && value != NULL);
1624
1625 for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
1626 ix++)
1627 if (strcmp (prop->key, key) == 0)
1628 internal_error (__FILE__, __LINE__,
1629 _("Attempted to add duplicate property \"%s\""), key);
1630
23181151
DJ
1631 new_prop.key = xstrdup (key);
1632 new_prop.value = xstrdup (value);
29709017
DJ
1633 VEC_safe_push (property_s, target_desc->properties, &new_prop);
1634}
23181151
DJ
1635
1636void
1637set_tdesc_architecture (struct target_desc *target_desc,
1638 const struct bfd_arch_info *arch)
1639{
1640 target_desc->arch = arch;
1641}
08d16641
PA
1642
1643void
1644set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
1645{
1646 target_desc->osabi = osabi;
1647}
23181151
DJ
1648\f
1649
1650static struct cmd_list_element *tdesc_set_cmdlist, *tdesc_show_cmdlist;
1651static struct cmd_list_element *tdesc_unset_cmdlist;
1652
1653/* Helper functions for the CLI commands. */
1654
1655static void
1656set_tdesc_cmd (char *args, int from_tty)
1657{
635c7e8a 1658 help_list (tdesc_set_cmdlist, "set tdesc ", all_commands, gdb_stdout);
23181151
DJ
1659}
1660
1661static void
1662show_tdesc_cmd (char *args, int from_tty)
1663{
1664 cmd_show_list (tdesc_show_cmdlist, from_tty, "");
1665}
1666
1667static void
1668unset_tdesc_cmd (char *args, int from_tty)
1669{
635c7e8a 1670 help_list (tdesc_unset_cmdlist, "unset tdesc ", all_commands, gdb_stdout);
23181151
DJ
1671}
1672
1673static void
1674set_tdesc_filename_cmd (char *args, int from_tty,
1675 struct cmd_list_element *c)
1676{
6ecd4729
PA
1677 xfree (target_description_filename);
1678 target_description_filename = xstrdup (tdesc_filename_cmd_string);
1679
23181151
DJ
1680 target_clear_description ();
1681 target_find_description ();
1682}
1683
1684static void
1685show_tdesc_filename_cmd (struct ui_file *file, int from_tty,
1686 struct cmd_list_element *c,
1687 const char *value)
1688{
6ecd4729
PA
1689 value = target_description_filename;
1690
23181151 1691 if (value != NULL && *value != '\0')
3e43a32a 1692 printf_filtered (_("The target description will be read from \"%s\".\n"),
23181151
DJ
1693 value);
1694 else
3e43a32a
MS
1695 printf_filtered (_("The target description will be "
1696 "read from the target.\n"));
23181151
DJ
1697}
1698
1699static void
1700unset_tdesc_filename_cmd (char *args, int from_tty)
1701{
1702 xfree (target_description_filename);
1703 target_description_filename = NULL;
1704 target_clear_description ();
1705 target_find_description ();
1706}
1707
81adfced
DJ
1708static void
1709maint_print_c_tdesc_cmd (char *args, int from_tty)
1710{
1711 const struct target_desc *tdesc;
e35359c5 1712 const struct bfd_arch_info *compatible;
81adfced
DJ
1713 const char *filename, *inp;
1714 char *function, *outp;
1715 struct property *prop;
1716 struct tdesc_feature *feature;
1717 struct tdesc_reg *reg;
ad068eab
UW
1718 struct tdesc_type *type;
1719 struct tdesc_type_field *f;
81adfced 1720 int ix, ix2, ix3;
4e2f8df6 1721 int printed_field_type = 0;
81adfced
DJ
1722
1723 /* Use the global target-supplied description, not the current
1724 architecture's. This lets a GDB for one architecture generate C
1725 for another architecture's description, even though the gdbarch
1726 initialization code will reject the new description. */
1727 tdesc = current_target_desc;
1728 if (tdesc == NULL)
1729 error (_("There is no target description to print."));
1730
1731 if (target_description_filename == NULL)
1732 error (_("The current target description did not come from an XML file."));
1733
1734 filename = lbasename (target_description_filename);
224c3ddb 1735 function = (char *) alloca (strlen (filename) + 1);
81adfced
DJ
1736 for (inp = filename, outp = function; *inp != '\0'; inp++)
1737 if (*inp == '.')
1738 break;
1739 else if (*inp == '-')
1740 *outp++ = '_';
1741 else
1742 *outp++ = *inp;
1743 *outp = '\0';
1744
1745 /* Standard boilerplate. */
c4bfde41
JK
1746 printf_unfiltered ("/* THIS FILE IS GENERATED. "
1747 "-*- buffer-read-only: t -*- vi"
1748 ":set ro:\n");
1749 printf_unfiltered (" Original: %s */\n\n", filename);
81adfced 1750 printf_unfiltered ("#include \"defs.h\"\n");
c3f08eb7 1751 printf_unfiltered ("#include \"osabi.h\"\n");
81adfced
DJ
1752 printf_unfiltered ("#include \"target-descriptions.h\"\n");
1753 printf_unfiltered ("\n");
1754
1755 printf_unfiltered ("struct target_desc *tdesc_%s;\n", function);
1756 printf_unfiltered ("static void\n");
1757 printf_unfiltered ("initialize_tdesc_%s (void)\n", function);
1758 printf_unfiltered ("{\n");
1759 printf_unfiltered
1760 (" struct target_desc *result = allocate_target_description ();\n");
1761 printf_unfiltered (" struct tdesc_feature *feature;\n");
4e2f8df6
SDJ
1762
1763 /* Now we do some "filtering" in order to know which variables to
1764 declare. This is needed because otherwise we would declare unused
1765 variables `field_type' and `type'. */
1766 for (ix = 0;
1767 VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
1768 ix++)
1769 {
1770 int printed_desc_type = 0;
1771
1772 for (ix2 = 0;
1773 VEC_iterate (tdesc_type_p, feature->types, ix2, type);
1774 ix2++)
1775 {
1776 if (!printed_field_type)
1777 {
1778 printf_unfiltered (" struct tdesc_type *field_type;\n");
1779 printed_field_type = 1;
1780 }
1781
81516450
DE
1782 if ((type->kind == TDESC_TYPE_UNION
1783 || type->kind == TDESC_TYPE_STRUCT
1784 || type->kind == TDESC_TYPE_FLAGS
1785 || type->kind == TDESC_TYPE_ENUM)
1786 && VEC_length (tdesc_type_field, type->u.u.fields) > 0)
4e2f8df6
SDJ
1787 {
1788 printf_unfiltered (" struct tdesc_type *type;\n");
1789 printed_desc_type = 1;
1790 break;
1791 }
1792 }
1793
1794 if (printed_desc_type)
1795 break;
1796 }
1797
81adfced
DJ
1798 printf_unfiltered ("\n");
1799
1800 if (tdesc_architecture (tdesc) != NULL)
1801 {
1802 printf_unfiltered
1803 (" set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
1804 tdesc_architecture (tdesc)->printable_name);
1805 printf_unfiltered ("\n");
1806 }
1807
c3f08eb7
L
1808 if (tdesc_osabi (tdesc) > GDB_OSABI_UNKNOWN
1809 && tdesc_osabi (tdesc) < GDB_OSABI_INVALID)
1810 {
1811 printf_unfiltered
1812 (" set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
1813 gdbarch_osabi_name (tdesc_osabi (tdesc)));
1814 printf_unfiltered ("\n");
1815 }
1816
e35359c5
UW
1817 for (ix = 0; VEC_iterate (arch_p, tdesc->compatible, ix, compatible);
1818 ix++)
1819 {
1820 printf_unfiltered
1821 (" tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
1822 compatible->printable_name);
1823 }
1824 if (ix)
1825 printf_unfiltered ("\n");
1826
81adfced
DJ
1827 for (ix = 0; VEC_iterate (property_s, tdesc->properties, ix, prop);
1828 ix++)
1829 {
1830 printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n",
1831 prop->key, prop->value);
1832 }
1833
1834 for (ix = 0;
1835 VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
1836 ix++)
1837 {
3e43a32a
MS
1838 printf_unfiltered (" \
1839feature = tdesc_create_feature (result, \"%s\");\n",
81adfced
DJ
1840 feature->name);
1841
1842 for (ix2 = 0;
ad068eab 1843 VEC_iterate (tdesc_type_p, feature->types, ix2, type);
81adfced
DJ
1844 ix2++)
1845 {
ad068eab 1846 switch (type->kind)
81adfced 1847 {
ad068eab 1848 case TDESC_TYPE_VECTOR:
81adfced
DJ
1849 printf_unfiltered
1850 (" field_type = tdesc_named_type (feature, \"%s\");\n",
ad068eab 1851 type->u.v.type->name);
81adfced 1852 printf_unfiltered
ad068eab
UW
1853 (" tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
1854 type->name, type->u.v.count);
81adfced 1855 break;
f92b06da 1856 case TDESC_TYPE_STRUCT:
81516450
DE
1857 case TDESC_TYPE_FLAGS:
1858 if (type->kind == TDESC_TYPE_STRUCT)
1859 {
1860 printf_unfiltered
1861 (" type = tdesc_create_struct (feature, \"%s\");\n",
1862 type->name);
1863 if (type->u.u.size != 0)
1864 printf_unfiltered
1865 (" tdesc_set_struct_size (type, %d);\n",
1866 type->u.u.size);
1867 }
1868 else
1869 {
1870 printf_unfiltered
1871 (" type = tdesc_create_flags (feature, \"%s\", %d);\n",
1872 type->name, type->u.u.size);
1873 }
f92b06da
WT
1874 for (ix3 = 0;
1875 VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1876 ix3++)
1877 {
81516450
DE
1878 const char *type_name;
1879
1880 gdb_assert (f->type != NULL);
1881 type_name = f->type->name;
1882
1883 /* To minimize changes to generated files, don't emit type
1884 info for fields that have defaulted types. */
1885 if (f->start != -1)
1886 {
1887 gdb_assert (f->end != -1);
1888 if (f->type->kind == TDESC_TYPE_BOOL)
1889 {
1890 gdb_assert (f->start == f->end);
1891 printf_unfiltered
1892 (" tdesc_add_flag (type, %d, \"%s\");\n",
1893 f->start, f->name);
1894 }
1895 else if ((type->u.u.size == 4
1896 && f->type->kind == TDESC_TYPE_UINT32)
1897 || (type->u.u.size == 8
1898 && f->type->kind == TDESC_TYPE_UINT64))
1899 {
1900 printf_unfiltered
1901 (" tdesc_add_bitfield (type, \"%s\", %d, %d);\n",
1902 f->name, f->start, f->end);
1903 }
1904 else
1905 {
1906 printf_unfiltered
1907 (" field_type = tdesc_named_type (feature,"
1908 " \"%s\");\n",
1909 type_name);
1910 printf_unfiltered
1911 (" tdesc_add_typed_bitfield (type, \"%s\","
1912 " %d, %d, field_type);\n",
1913 f->name, f->start, f->end);
1914 }
1915 }
1916 else /* Not a bitfield. */
f92b06da 1917 {
81516450
DE
1918 gdb_assert (f->end == -1);
1919 gdb_assert (type->kind == TDESC_TYPE_STRUCT);
f92b06da 1920 printf_unfiltered
81516450
DE
1921 (" field_type = tdesc_named_type (feature,"
1922 " \"%s\");\n",
1923 type_name);
f92b06da
WT
1924 printf_unfiltered
1925 (" tdesc_add_field (type, \"%s\", field_type);\n",
1926 f->name);
1927 }
f92b06da
WT
1928 }
1929 break;
ad068eab 1930 case TDESC_TYPE_UNION:
81adfced 1931 printf_unfiltered
ad068eab
UW
1932 (" type = tdesc_create_union (feature, \"%s\");\n",
1933 type->name);
1934 for (ix3 = 0;
1935 VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1936 ix3++)
81adfced
DJ
1937 {
1938 printf_unfiltered
1939 (" field_type = tdesc_named_type (feature, \"%s\");\n",
ad068eab 1940 f->type->name);
81adfced 1941 printf_unfiltered
ad068eab
UW
1942 (" tdesc_add_field (type, \"%s\", field_type);\n",
1943 f->name);
81adfced 1944 }
81adfced 1945 break;
81516450 1946 case TDESC_TYPE_ENUM:
a6f5ef51 1947 printf_unfiltered
81516450
DE
1948 (" type = tdesc_create_enum (feature, \"%s\", %d);\n",
1949 type->name, type->u.u.size);
a6f5ef51 1950 for (ix3 = 0;
81516450 1951 VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
a6f5ef51
L
1952 ix3++)
1953 printf_unfiltered
81516450
DE
1954 (" tdesc_add_enum_value (type, %d, \"%s\");\n",
1955 f->start, f->name);
a6f5ef51 1956 break;
81adfced 1957 default:
ad068eab 1958 error (_("C output is not supported type \"%s\"."), type->name);
81adfced 1959 }
81adfced
DJ
1960 printf_unfiltered ("\n");
1961 }
1962
1963 for (ix2 = 0;
1964 VEC_iterate (tdesc_reg_p, feature->registers, ix2, reg);
1965 ix2++)
1966 {
1967 printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
1968 reg->name, reg->target_regnum, reg->save_restore);
1969 if (reg->group)
1970 printf_unfiltered ("\"%s\", ", reg->group);
1971 else
1972 printf_unfiltered ("NULL, ");
1973 printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
1974 }
1975
1976 printf_unfiltered ("\n");
1977 }
1978
1979 printf_unfiltered (" tdesc_%s = result;\n", function);
1980 printf_unfiltered ("}\n");
1981}
1982
2c0b251b
PA
1983/* Provide a prototype to silence -Wmissing-prototypes. */
1984extern initialize_file_ftype _initialize_target_descriptions;
1985
23181151
DJ
1986void
1987_initialize_target_descriptions (void)
1988{
123dc839
DJ
1989 tdesc_data = gdbarch_data_register_pre_init (tdesc_data_init);
1990
23181151
DJ
1991 add_prefix_cmd ("tdesc", class_maintenance, set_tdesc_cmd, _("\
1992Set target description specific variables."),
1993 &tdesc_set_cmdlist, "set tdesc ",
1994 0 /* allow-unknown */, &setlist);
1995 add_prefix_cmd ("tdesc", class_maintenance, show_tdesc_cmd, _("\
1996Show target description specific variables."),
1997 &tdesc_show_cmdlist, "show tdesc ",
1998 0 /* allow-unknown */, &showlist);
1999 add_prefix_cmd ("tdesc", class_maintenance, unset_tdesc_cmd, _("\
2000Unset target description specific variables."),
2001 &tdesc_unset_cmdlist, "unset tdesc ",
2002 0 /* allow-unknown */, &unsetlist);
2003
2004 add_setshow_filename_cmd ("filename", class_obscure,
6ecd4729 2005 &tdesc_filename_cmd_string,
23181151
DJ
2006 _("\
2007Set the file to read for an XML target description"), _("\
2008Show the file to read for an XML target description"), _("\
2009When set, GDB will read the target description from a local\n\
2010file instead of querying the remote target."),
2011 set_tdesc_filename_cmd,
2012 show_tdesc_filename_cmd,
2013 &tdesc_set_cmdlist, &tdesc_show_cmdlist);
2014
2015 add_cmd ("filename", class_obscure, unset_tdesc_filename_cmd, _("\
2016Unset the file to read for an XML target description. When unset,\n\
2017GDB will read the description from the target."),
2018 &tdesc_unset_cmdlist);
81adfced
DJ
2019
2020 add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\
2021Print the current target description as a C source file."),
2022 &maintenanceprintlist);
23181151 2023}
This page took 1.146102 seconds and 4 git commands to generate.