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