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