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