15796c8dcSSimon Schubert /* Target description support for GDB. 25796c8dcSSimon Schubert 3*cf7f2e2dSJohn Marino Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 45796c8dcSSimon Schubert 55796c8dcSSimon Schubert Contributed by CodeSourcery. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This file is part of GDB. 85796c8dcSSimon Schubert 95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 125796c8dcSSimon Schubert (at your option) any later version. 135796c8dcSSimon Schubert 145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 175796c8dcSSimon Schubert GNU General Public License for more details. 185796c8dcSSimon Schubert 195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 205796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert #include "defs.h" 235796c8dcSSimon Schubert #include "arch-utils.h" 245796c8dcSSimon Schubert #include "gdbcmd.h" 255796c8dcSSimon Schubert #include "gdbtypes.h" 265796c8dcSSimon Schubert #include "reggroups.h" 275796c8dcSSimon Schubert #include "target.h" 285796c8dcSSimon Schubert #include "target-descriptions.h" 295796c8dcSSimon Schubert #include "vec.h" 305796c8dcSSimon Schubert #include "xml-support.h" 315796c8dcSSimon Schubert #include "xml-tdesc.h" 32*cf7f2e2dSJohn Marino #include "osabi.h" 335796c8dcSSimon Schubert 345796c8dcSSimon Schubert #include "gdb_assert.h" 355796c8dcSSimon Schubert #include "gdb_obstack.h" 365796c8dcSSimon Schubert #include "hashtab.h" 375796c8dcSSimon Schubert 385796c8dcSSimon Schubert /* Types. */ 395796c8dcSSimon Schubert 405796c8dcSSimon Schubert typedef struct property 415796c8dcSSimon Schubert { 425796c8dcSSimon Schubert char *key; 435796c8dcSSimon Schubert char *value; 445796c8dcSSimon Schubert } property_s; 455796c8dcSSimon Schubert DEF_VEC_O(property_s); 465796c8dcSSimon Schubert 475796c8dcSSimon Schubert /* An individual register from a target description. */ 485796c8dcSSimon Schubert 495796c8dcSSimon Schubert typedef struct tdesc_reg 505796c8dcSSimon Schubert { 515796c8dcSSimon Schubert /* The name of this register. In standard features, it may be 525796c8dcSSimon Schubert recognized by the architecture support code, or it may be purely 535796c8dcSSimon Schubert for the user. */ 545796c8dcSSimon Schubert char *name; 555796c8dcSSimon Schubert 565796c8dcSSimon Schubert /* The register number used by this target to refer to this 575796c8dcSSimon Schubert register. This is used for remote p/P packets and to determine 585796c8dcSSimon Schubert the ordering of registers in the remote g/G packets. */ 595796c8dcSSimon Schubert long target_regnum; 605796c8dcSSimon Schubert 615796c8dcSSimon Schubert /* If this flag is set, GDB should save and restore this register 625796c8dcSSimon Schubert around calls to an inferior function. */ 635796c8dcSSimon Schubert int save_restore; 645796c8dcSSimon Schubert 655796c8dcSSimon Schubert /* The name of the register group containing this register, or NULL 665796c8dcSSimon Schubert if the group should be automatically determined from the 675796c8dcSSimon Schubert register's type. If this is "general", "float", or "vector", the 685796c8dcSSimon Schubert corresponding "info" command should display this register's 695796c8dcSSimon Schubert value. It can be an arbitrary string, but should be limited to 705796c8dcSSimon Schubert alphanumeric characters and internal hyphens. Currently other 715796c8dcSSimon Schubert strings are ignored (treated as NULL). */ 725796c8dcSSimon Schubert char *group; 735796c8dcSSimon Schubert 745796c8dcSSimon Schubert /* The size of the register, in bits. */ 755796c8dcSSimon Schubert int bitsize; 765796c8dcSSimon Schubert 775796c8dcSSimon Schubert /* The type of the register. This string corresponds to either 785796c8dcSSimon Schubert a named type from the target description or a predefined 795796c8dcSSimon Schubert type from GDB. */ 805796c8dcSSimon Schubert char *type; 815796c8dcSSimon Schubert 825796c8dcSSimon Schubert /* The target-described type corresponding to TYPE, if found. */ 835796c8dcSSimon Schubert struct tdesc_type *tdesc_type; 845796c8dcSSimon Schubert } *tdesc_reg_p; 855796c8dcSSimon Schubert DEF_VEC_P(tdesc_reg_p); 865796c8dcSSimon Schubert 875796c8dcSSimon Schubert /* A named type from a target description. */ 885796c8dcSSimon Schubert 895796c8dcSSimon Schubert typedef struct tdesc_type_field 905796c8dcSSimon Schubert { 915796c8dcSSimon Schubert char *name; 925796c8dcSSimon Schubert struct tdesc_type *type; 93*cf7f2e2dSJohn Marino int start, end; 945796c8dcSSimon Schubert } tdesc_type_field; 955796c8dcSSimon Schubert DEF_VEC_O(tdesc_type_field); 965796c8dcSSimon Schubert 97*cf7f2e2dSJohn Marino typedef struct tdesc_type_flag 98*cf7f2e2dSJohn Marino { 99*cf7f2e2dSJohn Marino char *name; 100*cf7f2e2dSJohn Marino int start; 101*cf7f2e2dSJohn Marino } tdesc_type_flag; 102*cf7f2e2dSJohn Marino DEF_VEC_O(tdesc_type_flag); 103*cf7f2e2dSJohn Marino 1045796c8dcSSimon Schubert typedef struct tdesc_type 1055796c8dcSSimon Schubert { 1065796c8dcSSimon Schubert /* The name of this type. */ 1075796c8dcSSimon Schubert char *name; 1085796c8dcSSimon Schubert 1095796c8dcSSimon Schubert /* Identify the kind of this type. */ 1105796c8dcSSimon Schubert enum 1115796c8dcSSimon Schubert { 1125796c8dcSSimon Schubert /* Predefined types. */ 1135796c8dcSSimon Schubert TDESC_TYPE_INT8, 1145796c8dcSSimon Schubert TDESC_TYPE_INT16, 1155796c8dcSSimon Schubert TDESC_TYPE_INT32, 1165796c8dcSSimon Schubert TDESC_TYPE_INT64, 1175796c8dcSSimon Schubert TDESC_TYPE_INT128, 1185796c8dcSSimon Schubert TDESC_TYPE_UINT8, 1195796c8dcSSimon Schubert TDESC_TYPE_UINT16, 1205796c8dcSSimon Schubert TDESC_TYPE_UINT32, 1215796c8dcSSimon Schubert TDESC_TYPE_UINT64, 1225796c8dcSSimon Schubert TDESC_TYPE_UINT128, 1235796c8dcSSimon Schubert TDESC_TYPE_CODE_PTR, 1245796c8dcSSimon Schubert TDESC_TYPE_DATA_PTR, 1255796c8dcSSimon Schubert TDESC_TYPE_IEEE_SINGLE, 1265796c8dcSSimon Schubert TDESC_TYPE_IEEE_DOUBLE, 1275796c8dcSSimon Schubert TDESC_TYPE_ARM_FPA_EXT, 128*cf7f2e2dSJohn Marino TDESC_TYPE_I387_EXT, 1295796c8dcSSimon Schubert 1305796c8dcSSimon Schubert /* Types defined by a target feature. */ 1315796c8dcSSimon Schubert TDESC_TYPE_VECTOR, 132*cf7f2e2dSJohn Marino TDESC_TYPE_STRUCT, 133*cf7f2e2dSJohn Marino TDESC_TYPE_UNION, 134*cf7f2e2dSJohn Marino TDESC_TYPE_FLAGS 1355796c8dcSSimon Schubert } kind; 1365796c8dcSSimon Schubert 1375796c8dcSSimon Schubert /* Kind-specific data. */ 1385796c8dcSSimon Schubert union 1395796c8dcSSimon Schubert { 1405796c8dcSSimon Schubert /* Vector type. */ 1415796c8dcSSimon Schubert struct 1425796c8dcSSimon Schubert { 1435796c8dcSSimon Schubert struct tdesc_type *type; 1445796c8dcSSimon Schubert int count; 1455796c8dcSSimon Schubert } v; 1465796c8dcSSimon Schubert 147*cf7f2e2dSJohn Marino /* Struct or union type. */ 1485796c8dcSSimon Schubert struct 1495796c8dcSSimon Schubert { 1505796c8dcSSimon Schubert VEC(tdesc_type_field) *fields; 151*cf7f2e2dSJohn Marino LONGEST size; 1525796c8dcSSimon Schubert } u; 153*cf7f2e2dSJohn Marino 154*cf7f2e2dSJohn Marino /* Flags type. */ 155*cf7f2e2dSJohn Marino struct 156*cf7f2e2dSJohn Marino { 157*cf7f2e2dSJohn Marino VEC(tdesc_type_flag) *flags; 158*cf7f2e2dSJohn Marino LONGEST size; 159*cf7f2e2dSJohn Marino } f; 1605796c8dcSSimon Schubert } u; 1615796c8dcSSimon Schubert } *tdesc_type_p; 1625796c8dcSSimon Schubert DEF_VEC_P(tdesc_type_p); 1635796c8dcSSimon Schubert 1645796c8dcSSimon Schubert /* A feature from a target description. Each feature is a collection 1655796c8dcSSimon Schubert of other elements, e.g. registers and types. */ 1665796c8dcSSimon Schubert 1675796c8dcSSimon Schubert typedef struct tdesc_feature 1685796c8dcSSimon Schubert { 1695796c8dcSSimon Schubert /* The name of this feature. It may be recognized by the architecture 1705796c8dcSSimon Schubert support code. */ 1715796c8dcSSimon Schubert char *name; 1725796c8dcSSimon Schubert 1735796c8dcSSimon Schubert /* The registers associated with this feature. */ 1745796c8dcSSimon Schubert VEC(tdesc_reg_p) *registers; 1755796c8dcSSimon Schubert 1765796c8dcSSimon Schubert /* The types associated with this feature. */ 1775796c8dcSSimon Schubert VEC(tdesc_type_p) *types; 1785796c8dcSSimon Schubert } *tdesc_feature_p; 1795796c8dcSSimon Schubert DEF_VEC_P(tdesc_feature_p); 1805796c8dcSSimon Schubert 1815796c8dcSSimon Schubert /* A compatible architecture from a target description. */ 1825796c8dcSSimon Schubert typedef const struct bfd_arch_info *arch_p; 1835796c8dcSSimon Schubert DEF_VEC_P(arch_p); 1845796c8dcSSimon Schubert 1855796c8dcSSimon Schubert /* A target description. */ 1865796c8dcSSimon Schubert 1875796c8dcSSimon Schubert struct target_desc 1885796c8dcSSimon Schubert { 1895796c8dcSSimon Schubert /* The architecture reported by the target, if any. */ 1905796c8dcSSimon Schubert const struct bfd_arch_info *arch; 1915796c8dcSSimon Schubert 1925796c8dcSSimon Schubert /* The osabi reported by the target, if any; GDB_OSABI_UNKNOWN 1935796c8dcSSimon Schubert otherwise. */ 1945796c8dcSSimon Schubert enum gdb_osabi osabi; 1955796c8dcSSimon Schubert 1965796c8dcSSimon Schubert /* The list of compatible architectures reported by the target. */ 1975796c8dcSSimon Schubert VEC(arch_p) *compatible; 1985796c8dcSSimon Schubert 1995796c8dcSSimon Schubert /* Any architecture-specific properties specified by the target. */ 2005796c8dcSSimon Schubert VEC(property_s) *properties; 2015796c8dcSSimon Schubert 2025796c8dcSSimon Schubert /* The features associated with this target. */ 2035796c8dcSSimon Schubert VEC(tdesc_feature_p) *features; 2045796c8dcSSimon Schubert }; 2055796c8dcSSimon Schubert 2065796c8dcSSimon Schubert /* Per-architecture data associated with a target description. The 2075796c8dcSSimon Schubert target description may be shared by multiple architectures, but 2085796c8dcSSimon Schubert this data is private to one gdbarch. */ 2095796c8dcSSimon Schubert 2105796c8dcSSimon Schubert typedef struct tdesc_arch_reg 2115796c8dcSSimon Schubert { 2125796c8dcSSimon Schubert struct tdesc_reg *reg; 2135796c8dcSSimon Schubert struct type *type; 2145796c8dcSSimon Schubert } tdesc_arch_reg; 2155796c8dcSSimon Schubert DEF_VEC_O(tdesc_arch_reg); 2165796c8dcSSimon Schubert 2175796c8dcSSimon Schubert struct tdesc_arch_data 2185796c8dcSSimon Schubert { 2195796c8dcSSimon Schubert /* A list of register/type pairs, indexed by GDB's internal register number. 2205796c8dcSSimon Schubert During initialization of the gdbarch this list is used to store 2215796c8dcSSimon Schubert registers which the architecture assigns a fixed register number. 2225796c8dcSSimon Schubert Registers which are NULL in this array, or off the end, are 2235796c8dcSSimon Schubert treated as zero-sized and nameless (i.e. placeholders in the 2245796c8dcSSimon Schubert numbering). */ 2255796c8dcSSimon Schubert VEC(tdesc_arch_reg) *arch_regs; 2265796c8dcSSimon Schubert 2275796c8dcSSimon Schubert /* Functions which report the register name, type, and reggroups for 2285796c8dcSSimon Schubert pseudo-registers. */ 2295796c8dcSSimon Schubert gdbarch_register_name_ftype *pseudo_register_name; 2305796c8dcSSimon Schubert gdbarch_register_type_ftype *pseudo_register_type; 2315796c8dcSSimon Schubert gdbarch_register_reggroup_p_ftype *pseudo_register_reggroup_p; 2325796c8dcSSimon Schubert }; 2335796c8dcSSimon Schubert 2345796c8dcSSimon Schubert /* Global state. These variables are associated with the current 2355796c8dcSSimon Schubert target; if GDB adds support for multiple simultaneous targets, then 2365796c8dcSSimon Schubert these variables should become target-specific data. */ 2375796c8dcSSimon Schubert 2385796c8dcSSimon Schubert /* A flag indicating that a description has already been fetched from 2395796c8dcSSimon Schubert the current target, so it should not be queried again. */ 2405796c8dcSSimon Schubert 2415796c8dcSSimon Schubert static int target_desc_fetched; 2425796c8dcSSimon Schubert 2435796c8dcSSimon Schubert /* The description fetched from the current target, or NULL if the 2445796c8dcSSimon Schubert current target did not supply any description. Only valid when 2455796c8dcSSimon Schubert target_desc_fetched is set. Only the description initialization 2465796c8dcSSimon Schubert code should access this; normally, the description should be 2475796c8dcSSimon Schubert accessed through the gdbarch object. */ 2485796c8dcSSimon Schubert 2495796c8dcSSimon Schubert static const struct target_desc *current_target_desc; 2505796c8dcSSimon Schubert 2515796c8dcSSimon Schubert /* Other global variables. */ 2525796c8dcSSimon Schubert 2535796c8dcSSimon Schubert /* The filename to read a target description from. */ 2545796c8dcSSimon Schubert 2555796c8dcSSimon Schubert static char *target_description_filename; 2565796c8dcSSimon Schubert 2575796c8dcSSimon Schubert /* A handle for architecture-specific data associated with the 2585796c8dcSSimon Schubert target description (see struct tdesc_arch_data). */ 2595796c8dcSSimon Schubert 2605796c8dcSSimon Schubert static struct gdbarch_data *tdesc_data; 2615796c8dcSSimon Schubert 2625796c8dcSSimon Schubert /* Fetch the current target's description, and switch the current 2635796c8dcSSimon Schubert architecture to one which incorporates that description. */ 2645796c8dcSSimon Schubert 2655796c8dcSSimon Schubert void 2665796c8dcSSimon Schubert target_find_description (void) 2675796c8dcSSimon Schubert { 2685796c8dcSSimon Schubert /* If we've already fetched a description from the target, don't do 2695796c8dcSSimon Schubert it again. This allows a target to fetch the description early, 2705796c8dcSSimon Schubert during its to_open or to_create_inferior, if it needs extra 2715796c8dcSSimon Schubert information about the target to initialize. */ 2725796c8dcSSimon Schubert if (target_desc_fetched) 2735796c8dcSSimon Schubert return; 2745796c8dcSSimon Schubert 2755796c8dcSSimon Schubert /* The current architecture should not have any target description 2765796c8dcSSimon Schubert specified. It should have been cleared, e.g. when we 2775796c8dcSSimon Schubert disconnected from the previous target. */ 2785796c8dcSSimon Schubert gdb_assert (gdbarch_target_desc (target_gdbarch) == NULL); 2795796c8dcSSimon Schubert 2805796c8dcSSimon Schubert /* First try to fetch an XML description from the user-specified 2815796c8dcSSimon Schubert file. */ 2825796c8dcSSimon Schubert current_target_desc = NULL; 2835796c8dcSSimon Schubert if (target_description_filename != NULL 2845796c8dcSSimon Schubert && *target_description_filename != '\0') 2855796c8dcSSimon Schubert current_target_desc 2865796c8dcSSimon Schubert = file_read_description_xml (target_description_filename); 2875796c8dcSSimon Schubert 2885796c8dcSSimon Schubert /* Next try to read the description from the current target using 2895796c8dcSSimon Schubert target objects. */ 2905796c8dcSSimon Schubert if (current_target_desc == NULL) 2915796c8dcSSimon Schubert current_target_desc = target_read_description_xml (¤t_target); 2925796c8dcSSimon Schubert 2935796c8dcSSimon Schubert /* If that failed try a target-specific hook. */ 2945796c8dcSSimon Schubert if (current_target_desc == NULL) 2955796c8dcSSimon Schubert current_target_desc = target_read_description (¤t_target); 2965796c8dcSSimon Schubert 2975796c8dcSSimon Schubert /* If a non-NULL description was returned, then update the current 2985796c8dcSSimon Schubert architecture. */ 2995796c8dcSSimon Schubert if (current_target_desc) 3005796c8dcSSimon Schubert { 3015796c8dcSSimon Schubert struct gdbarch_info info; 3025796c8dcSSimon Schubert 3035796c8dcSSimon Schubert gdbarch_info_init (&info); 3045796c8dcSSimon Schubert info.target_desc = current_target_desc; 3055796c8dcSSimon Schubert if (!gdbarch_update_p (info)) 3065796c8dcSSimon Schubert warning (_("Architecture rejected target-supplied description")); 3075796c8dcSSimon Schubert else 3085796c8dcSSimon Schubert { 3095796c8dcSSimon Schubert struct tdesc_arch_data *data; 3105796c8dcSSimon Schubert 3115796c8dcSSimon Schubert data = gdbarch_data (target_gdbarch, tdesc_data); 3125796c8dcSSimon Schubert if (tdesc_has_registers (current_target_desc) 3135796c8dcSSimon Schubert && data->arch_regs == NULL) 3145796c8dcSSimon Schubert warning (_("Target-supplied registers are not supported " 3155796c8dcSSimon Schubert "by the current architecture")); 3165796c8dcSSimon Schubert } 3175796c8dcSSimon Schubert } 3185796c8dcSSimon Schubert 3195796c8dcSSimon Schubert /* Now that we know this description is usable, record that we 3205796c8dcSSimon Schubert fetched it. */ 3215796c8dcSSimon Schubert target_desc_fetched = 1; 3225796c8dcSSimon Schubert } 3235796c8dcSSimon Schubert 3245796c8dcSSimon Schubert /* Discard any description fetched from the current target, and switch 3255796c8dcSSimon Schubert the current architecture to one with no target description. */ 3265796c8dcSSimon Schubert 3275796c8dcSSimon Schubert void 3285796c8dcSSimon Schubert target_clear_description (void) 3295796c8dcSSimon Schubert { 3305796c8dcSSimon Schubert struct gdbarch_info info; 3315796c8dcSSimon Schubert 3325796c8dcSSimon Schubert if (!target_desc_fetched) 3335796c8dcSSimon Schubert return; 3345796c8dcSSimon Schubert 3355796c8dcSSimon Schubert target_desc_fetched = 0; 3365796c8dcSSimon Schubert current_target_desc = NULL; 3375796c8dcSSimon Schubert 3385796c8dcSSimon Schubert gdbarch_info_init (&info); 3395796c8dcSSimon Schubert if (!gdbarch_update_p (info)) 3405796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 3415796c8dcSSimon Schubert _("Could not remove target-supplied description")); 3425796c8dcSSimon Schubert } 3435796c8dcSSimon Schubert 3445796c8dcSSimon Schubert /* Return the global current target description. This should only be 3455796c8dcSSimon Schubert used by gdbarch initialization code; most access should be through 3465796c8dcSSimon Schubert an existing gdbarch. */ 3475796c8dcSSimon Schubert 3485796c8dcSSimon Schubert const struct target_desc * 3495796c8dcSSimon Schubert target_current_description (void) 3505796c8dcSSimon Schubert { 3515796c8dcSSimon Schubert if (target_desc_fetched) 3525796c8dcSSimon Schubert return current_target_desc; 3535796c8dcSSimon Schubert 3545796c8dcSSimon Schubert return NULL; 3555796c8dcSSimon Schubert } 3565796c8dcSSimon Schubert 3575796c8dcSSimon Schubert /* Return non-zero if this target description is compatible 3585796c8dcSSimon Schubert with the given BFD architecture. */ 3595796c8dcSSimon Schubert 3605796c8dcSSimon Schubert int 3615796c8dcSSimon Schubert tdesc_compatible_p (const struct target_desc *target_desc, 3625796c8dcSSimon Schubert const struct bfd_arch_info *arch) 3635796c8dcSSimon Schubert { 3645796c8dcSSimon Schubert const struct bfd_arch_info *compat; 3655796c8dcSSimon Schubert int ix; 3665796c8dcSSimon Schubert 3675796c8dcSSimon Schubert for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat); 3685796c8dcSSimon Schubert ix++) 3695796c8dcSSimon Schubert { 3705796c8dcSSimon Schubert if (compat == arch 3715796c8dcSSimon Schubert || arch->compatible (arch, compat) 3725796c8dcSSimon Schubert || compat->compatible (compat, arch)) 3735796c8dcSSimon Schubert return 1; 3745796c8dcSSimon Schubert } 3755796c8dcSSimon Schubert 3765796c8dcSSimon Schubert return 0; 3775796c8dcSSimon Schubert } 3785796c8dcSSimon Schubert 3795796c8dcSSimon Schubert 3805796c8dcSSimon Schubert /* Direct accessors for target descriptions. */ 3815796c8dcSSimon Schubert 3825796c8dcSSimon Schubert /* Return the string value of a property named KEY, or NULL if the 3835796c8dcSSimon Schubert property was not specified. */ 3845796c8dcSSimon Schubert 3855796c8dcSSimon Schubert const char * 3865796c8dcSSimon Schubert tdesc_property (const struct target_desc *target_desc, const char *key) 3875796c8dcSSimon Schubert { 3885796c8dcSSimon Schubert struct property *prop; 3895796c8dcSSimon Schubert int ix; 3905796c8dcSSimon Schubert 3915796c8dcSSimon Schubert for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop); 3925796c8dcSSimon Schubert ix++) 3935796c8dcSSimon Schubert if (strcmp (prop->key, key) == 0) 3945796c8dcSSimon Schubert return prop->value; 3955796c8dcSSimon Schubert 3965796c8dcSSimon Schubert return NULL; 3975796c8dcSSimon Schubert } 3985796c8dcSSimon Schubert 3995796c8dcSSimon Schubert /* Return the BFD architecture associated with this target 4005796c8dcSSimon Schubert description, or NULL if no architecture was specified. */ 4015796c8dcSSimon Schubert 4025796c8dcSSimon Schubert const struct bfd_arch_info * 4035796c8dcSSimon Schubert tdesc_architecture (const struct target_desc *target_desc) 4045796c8dcSSimon Schubert { 4055796c8dcSSimon Schubert return target_desc->arch; 4065796c8dcSSimon Schubert } 4075796c8dcSSimon Schubert 4085796c8dcSSimon Schubert /* Return the OSABI associated with this target description, or 4095796c8dcSSimon Schubert GDB_OSABI_UNKNOWN if no osabi was specified. */ 4105796c8dcSSimon Schubert 4115796c8dcSSimon Schubert enum gdb_osabi 4125796c8dcSSimon Schubert tdesc_osabi (const struct target_desc *target_desc) 4135796c8dcSSimon Schubert { 4145796c8dcSSimon Schubert return target_desc->osabi; 4155796c8dcSSimon Schubert } 4165796c8dcSSimon Schubert 4175796c8dcSSimon Schubert 4185796c8dcSSimon Schubert 4195796c8dcSSimon Schubert /* Return 1 if this target description includes any registers. */ 4205796c8dcSSimon Schubert 4215796c8dcSSimon Schubert int 4225796c8dcSSimon Schubert tdesc_has_registers (const struct target_desc *target_desc) 4235796c8dcSSimon Schubert { 4245796c8dcSSimon Schubert int ix; 4255796c8dcSSimon Schubert struct tdesc_feature *feature; 4265796c8dcSSimon Schubert 4275796c8dcSSimon Schubert if (target_desc == NULL) 4285796c8dcSSimon Schubert return 0; 4295796c8dcSSimon Schubert 4305796c8dcSSimon Schubert for (ix = 0; 4315796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature); 4325796c8dcSSimon Schubert ix++) 4335796c8dcSSimon Schubert if (! VEC_empty (tdesc_reg_p, feature->registers)) 4345796c8dcSSimon Schubert return 1; 4355796c8dcSSimon Schubert 4365796c8dcSSimon Schubert return 0; 4375796c8dcSSimon Schubert } 4385796c8dcSSimon Schubert 4395796c8dcSSimon Schubert /* Return the feature with the given name, if present, or NULL if 4405796c8dcSSimon Schubert the named feature is not found. */ 4415796c8dcSSimon Schubert 4425796c8dcSSimon Schubert const struct tdesc_feature * 4435796c8dcSSimon Schubert tdesc_find_feature (const struct target_desc *target_desc, 4445796c8dcSSimon Schubert const char *name) 4455796c8dcSSimon Schubert { 4465796c8dcSSimon Schubert int ix; 4475796c8dcSSimon Schubert struct tdesc_feature *feature; 4485796c8dcSSimon Schubert 4495796c8dcSSimon Schubert for (ix = 0; 4505796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature); 4515796c8dcSSimon Schubert ix++) 4525796c8dcSSimon Schubert if (strcmp (feature->name, name) == 0) 4535796c8dcSSimon Schubert return feature; 4545796c8dcSSimon Schubert 4555796c8dcSSimon Schubert return NULL; 4565796c8dcSSimon Schubert } 4575796c8dcSSimon Schubert 4585796c8dcSSimon Schubert /* Return the name of FEATURE. */ 4595796c8dcSSimon Schubert 4605796c8dcSSimon Schubert const char * 4615796c8dcSSimon Schubert tdesc_feature_name (const struct tdesc_feature *feature) 4625796c8dcSSimon Schubert { 4635796c8dcSSimon Schubert return feature->name; 4645796c8dcSSimon Schubert } 4655796c8dcSSimon Schubert 4665796c8dcSSimon Schubert /* Predefined types. */ 4675796c8dcSSimon Schubert static struct tdesc_type tdesc_predefined_types[] = 4685796c8dcSSimon Schubert { 4695796c8dcSSimon Schubert { "int8", TDESC_TYPE_INT8 }, 4705796c8dcSSimon Schubert { "int16", TDESC_TYPE_INT16 }, 4715796c8dcSSimon Schubert { "int32", TDESC_TYPE_INT32 }, 4725796c8dcSSimon Schubert { "int64", TDESC_TYPE_INT64 }, 4735796c8dcSSimon Schubert { "int128", TDESC_TYPE_INT128 }, 4745796c8dcSSimon Schubert { "uint8", TDESC_TYPE_UINT8 }, 4755796c8dcSSimon Schubert { "uint16", TDESC_TYPE_UINT16 }, 4765796c8dcSSimon Schubert { "uint32", TDESC_TYPE_UINT32 }, 4775796c8dcSSimon Schubert { "uint64", TDESC_TYPE_UINT64 }, 4785796c8dcSSimon Schubert { "uint128", TDESC_TYPE_UINT128 }, 4795796c8dcSSimon Schubert { "code_ptr", TDESC_TYPE_CODE_PTR }, 4805796c8dcSSimon Schubert { "data_ptr", TDESC_TYPE_DATA_PTR }, 4815796c8dcSSimon Schubert { "ieee_single", TDESC_TYPE_IEEE_SINGLE }, 4825796c8dcSSimon Schubert { "ieee_double", TDESC_TYPE_IEEE_DOUBLE }, 483*cf7f2e2dSJohn Marino { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT }, 484*cf7f2e2dSJohn Marino { "i387_ext", TDESC_TYPE_I387_EXT } 4855796c8dcSSimon Schubert }; 4865796c8dcSSimon Schubert 4875796c8dcSSimon Schubert /* Return the type associated with ID in the context of FEATURE, or 4885796c8dcSSimon Schubert NULL if none. */ 4895796c8dcSSimon Schubert 4905796c8dcSSimon Schubert struct tdesc_type * 4915796c8dcSSimon Schubert tdesc_named_type (const struct tdesc_feature *feature, const char *id) 4925796c8dcSSimon Schubert { 4935796c8dcSSimon Schubert int ix; 4945796c8dcSSimon Schubert struct tdesc_type *type; 4955796c8dcSSimon Schubert 4965796c8dcSSimon Schubert /* First try target-defined types. */ 4975796c8dcSSimon Schubert for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++) 4985796c8dcSSimon Schubert if (strcmp (type->name, id) == 0) 4995796c8dcSSimon Schubert return type; 5005796c8dcSSimon Schubert 5015796c8dcSSimon Schubert /* Next try the predefined types. */ 5025796c8dcSSimon Schubert for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++) 5035796c8dcSSimon Schubert if (strcmp (tdesc_predefined_types[ix].name, id) == 0) 5045796c8dcSSimon Schubert return &tdesc_predefined_types[ix]; 5055796c8dcSSimon Schubert 5065796c8dcSSimon Schubert return NULL; 5075796c8dcSSimon Schubert } 5085796c8dcSSimon Schubert 509*cf7f2e2dSJohn Marino /* Lookup type associated with ID. */ 510*cf7f2e2dSJohn Marino 511*cf7f2e2dSJohn Marino struct type * 512*cf7f2e2dSJohn Marino tdesc_find_type (struct gdbarch *gdbarch, const char *id) 513*cf7f2e2dSJohn Marino { 514*cf7f2e2dSJohn Marino struct tdesc_arch_reg *reg; 515*cf7f2e2dSJohn Marino struct tdesc_arch_data *data; 516*cf7f2e2dSJohn Marino int i, num_regs; 517*cf7f2e2dSJohn Marino 518*cf7f2e2dSJohn Marino data = gdbarch_data (gdbarch, tdesc_data); 519*cf7f2e2dSJohn Marino num_regs = VEC_length (tdesc_arch_reg, data->arch_regs); 520*cf7f2e2dSJohn Marino for (i = 0; i < num_regs; i++) 521*cf7f2e2dSJohn Marino { 522*cf7f2e2dSJohn Marino reg = VEC_index (tdesc_arch_reg, data->arch_regs, i); 523*cf7f2e2dSJohn Marino if (reg->reg 524*cf7f2e2dSJohn Marino && reg->reg->tdesc_type 525*cf7f2e2dSJohn Marino && reg->type 526*cf7f2e2dSJohn Marino && strcmp (id, reg->reg->tdesc_type->name) == 0) 527*cf7f2e2dSJohn Marino return reg->type; 528*cf7f2e2dSJohn Marino } 529*cf7f2e2dSJohn Marino 530*cf7f2e2dSJohn Marino return NULL; 531*cf7f2e2dSJohn Marino } 532*cf7f2e2dSJohn Marino 5335796c8dcSSimon Schubert /* Construct, if necessary, and return the GDB type implementing target 5345796c8dcSSimon Schubert type TDESC_TYPE for architecture GDBARCH. */ 5355796c8dcSSimon Schubert 5365796c8dcSSimon Schubert static struct type * 5375796c8dcSSimon Schubert tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type) 5385796c8dcSSimon Schubert { 539*cf7f2e2dSJohn Marino struct type *type; 540*cf7f2e2dSJohn Marino 5415796c8dcSSimon Schubert switch (tdesc_type->kind) 5425796c8dcSSimon Schubert { 5435796c8dcSSimon Schubert /* Predefined types. */ 5445796c8dcSSimon Schubert case TDESC_TYPE_INT8: 5455796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int8; 5465796c8dcSSimon Schubert 5475796c8dcSSimon Schubert case TDESC_TYPE_INT16: 5485796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int16; 5495796c8dcSSimon Schubert 5505796c8dcSSimon Schubert case TDESC_TYPE_INT32: 5515796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int32; 5525796c8dcSSimon Schubert 5535796c8dcSSimon Schubert case TDESC_TYPE_INT64: 5545796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int64; 5555796c8dcSSimon Schubert 5565796c8dcSSimon Schubert case TDESC_TYPE_INT128: 5575796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int128; 5585796c8dcSSimon Schubert 5595796c8dcSSimon Schubert case TDESC_TYPE_UINT8: 5605796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_uint8; 5615796c8dcSSimon Schubert 5625796c8dcSSimon Schubert case TDESC_TYPE_UINT16: 5635796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_uint16; 5645796c8dcSSimon Schubert 5655796c8dcSSimon Schubert case TDESC_TYPE_UINT32: 5665796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_uint32; 5675796c8dcSSimon Schubert 5685796c8dcSSimon Schubert case TDESC_TYPE_UINT64: 5695796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_uint64; 5705796c8dcSSimon Schubert 5715796c8dcSSimon Schubert case TDESC_TYPE_UINT128: 5725796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_uint128; 5735796c8dcSSimon Schubert 5745796c8dcSSimon Schubert case TDESC_TYPE_CODE_PTR: 5755796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_func_ptr; 5765796c8dcSSimon Schubert 5775796c8dcSSimon Schubert case TDESC_TYPE_DATA_PTR: 5785796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_data_ptr; 5795796c8dcSSimon Schubert 580*cf7f2e2dSJohn Marino default: 581*cf7f2e2dSJohn Marino break; 582*cf7f2e2dSJohn Marino } 583*cf7f2e2dSJohn Marino 584*cf7f2e2dSJohn Marino type = tdesc_find_type (gdbarch, tdesc_type->name); 585*cf7f2e2dSJohn Marino if (type) 586*cf7f2e2dSJohn Marino return type; 587*cf7f2e2dSJohn Marino 588*cf7f2e2dSJohn Marino switch (tdesc_type->kind) 589*cf7f2e2dSJohn Marino { 5905796c8dcSSimon Schubert case TDESC_TYPE_IEEE_SINGLE: 5915796c8dcSSimon Schubert return arch_float_type (gdbarch, -1, "builtin_type_ieee_single", 5925796c8dcSSimon Schubert floatformats_ieee_single); 5935796c8dcSSimon Schubert 5945796c8dcSSimon Schubert case TDESC_TYPE_IEEE_DOUBLE: 5955796c8dcSSimon Schubert return arch_float_type (gdbarch, -1, "builtin_type_ieee_double", 5965796c8dcSSimon Schubert floatformats_ieee_double); 5975796c8dcSSimon Schubert 5985796c8dcSSimon Schubert case TDESC_TYPE_ARM_FPA_EXT: 5995796c8dcSSimon Schubert return arch_float_type (gdbarch, -1, "builtin_type_arm_ext", 6005796c8dcSSimon Schubert floatformats_arm_ext); 6015796c8dcSSimon Schubert 602*cf7f2e2dSJohn Marino case TDESC_TYPE_I387_EXT: 603*cf7f2e2dSJohn Marino return arch_float_type (gdbarch, -1, "builtin_type_i387_ext", 604*cf7f2e2dSJohn Marino floatformats_i387_ext); 605*cf7f2e2dSJohn Marino 6065796c8dcSSimon Schubert /* Types defined by a target feature. */ 6075796c8dcSSimon Schubert case TDESC_TYPE_VECTOR: 6085796c8dcSSimon Schubert { 6095796c8dcSSimon Schubert struct type *type, *field_type; 6105796c8dcSSimon Schubert 6115796c8dcSSimon Schubert field_type = tdesc_gdb_type (gdbarch, tdesc_type->u.v.type); 6125796c8dcSSimon Schubert type = init_vector_type (field_type, tdesc_type->u.v.count); 6135796c8dcSSimon Schubert TYPE_NAME (type) = xstrdup (tdesc_type->name); 6145796c8dcSSimon Schubert 6155796c8dcSSimon Schubert return type; 6165796c8dcSSimon Schubert } 6175796c8dcSSimon Schubert 618*cf7f2e2dSJohn Marino case TDESC_TYPE_STRUCT: 619*cf7f2e2dSJohn Marino { 620*cf7f2e2dSJohn Marino struct type *type, *field_type; 621*cf7f2e2dSJohn Marino struct tdesc_type_field *f; 622*cf7f2e2dSJohn Marino int ix; 623*cf7f2e2dSJohn Marino 624*cf7f2e2dSJohn Marino type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); 625*cf7f2e2dSJohn Marino TYPE_NAME (type) = xstrdup (tdesc_type->name); 626*cf7f2e2dSJohn Marino TYPE_TAG_NAME (type) = TYPE_NAME (type); 627*cf7f2e2dSJohn Marino 628*cf7f2e2dSJohn Marino for (ix = 0; 629*cf7f2e2dSJohn Marino VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f); 630*cf7f2e2dSJohn Marino ix++) 631*cf7f2e2dSJohn Marino { 632*cf7f2e2dSJohn Marino if (f->type == NULL) 633*cf7f2e2dSJohn Marino { 634*cf7f2e2dSJohn Marino /* Bitfield. */ 635*cf7f2e2dSJohn Marino struct field *fld; 636*cf7f2e2dSJohn Marino struct type *field_type; 637*cf7f2e2dSJohn Marino int bitsize, total_size; 638*cf7f2e2dSJohn Marino 639*cf7f2e2dSJohn Marino /* This invariant should be preserved while creating 640*cf7f2e2dSJohn Marino types. */ 641*cf7f2e2dSJohn Marino gdb_assert (tdesc_type->u.u.size != 0); 642*cf7f2e2dSJohn Marino if (tdesc_type->u.u.size > 4) 643*cf7f2e2dSJohn Marino field_type = builtin_type (gdbarch)->builtin_uint64; 644*cf7f2e2dSJohn Marino else 645*cf7f2e2dSJohn Marino field_type = builtin_type (gdbarch)->builtin_uint32; 646*cf7f2e2dSJohn Marino 647*cf7f2e2dSJohn Marino fld = append_composite_type_field_raw (type, xstrdup (f->name), 648*cf7f2e2dSJohn Marino field_type); 649*cf7f2e2dSJohn Marino 650*cf7f2e2dSJohn Marino /* For little-endian, BITPOS counts from the LSB of 651*cf7f2e2dSJohn Marino the structure and marks the LSB of the field. For 652*cf7f2e2dSJohn Marino big-endian, BITPOS counts from the MSB of the 653*cf7f2e2dSJohn Marino structure and marks the MSB of the field. Either 654*cf7f2e2dSJohn Marino way, it is the number of bits to the "left" of the 655*cf7f2e2dSJohn Marino field. To calculate this in big-endian, we need 656*cf7f2e2dSJohn Marino the total size of the structure. */ 657*cf7f2e2dSJohn Marino bitsize = f->end - f->start + 1; 658*cf7f2e2dSJohn Marino total_size = tdesc_type->u.u.size * TARGET_CHAR_BIT; 659*cf7f2e2dSJohn Marino if (gdbarch_bits_big_endian (gdbarch)) 660*cf7f2e2dSJohn Marino FIELD_BITPOS (fld[0]) = total_size - f->start - bitsize; 661*cf7f2e2dSJohn Marino else 662*cf7f2e2dSJohn Marino FIELD_BITPOS (fld[0]) = f->start; 663*cf7f2e2dSJohn Marino FIELD_BITSIZE (fld[0]) = bitsize; 664*cf7f2e2dSJohn Marino } 665*cf7f2e2dSJohn Marino else 666*cf7f2e2dSJohn Marino { 667*cf7f2e2dSJohn Marino field_type = tdesc_gdb_type (gdbarch, f->type); 668*cf7f2e2dSJohn Marino append_composite_type_field (type, xstrdup (f->name), 669*cf7f2e2dSJohn Marino field_type); 670*cf7f2e2dSJohn Marino } 671*cf7f2e2dSJohn Marino } 672*cf7f2e2dSJohn Marino 673*cf7f2e2dSJohn Marino if (tdesc_type->u.u.size != 0) 674*cf7f2e2dSJohn Marino TYPE_LENGTH (type) = tdesc_type->u.u.size; 675*cf7f2e2dSJohn Marino return type; 676*cf7f2e2dSJohn Marino } 677*cf7f2e2dSJohn Marino 6785796c8dcSSimon Schubert case TDESC_TYPE_UNION: 6795796c8dcSSimon Schubert { 6805796c8dcSSimon Schubert struct type *type, *field_type; 6815796c8dcSSimon Schubert struct tdesc_type_field *f; 6825796c8dcSSimon Schubert int ix; 6835796c8dcSSimon Schubert 6845796c8dcSSimon Schubert type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); 6855796c8dcSSimon Schubert TYPE_NAME (type) = xstrdup (tdesc_type->name); 6865796c8dcSSimon Schubert 6875796c8dcSSimon Schubert for (ix = 0; 6885796c8dcSSimon Schubert VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f); 6895796c8dcSSimon Schubert ix++) 6905796c8dcSSimon Schubert { 6915796c8dcSSimon Schubert field_type = tdesc_gdb_type (gdbarch, f->type); 6925796c8dcSSimon Schubert append_composite_type_field (type, xstrdup (f->name), field_type); 6935796c8dcSSimon Schubert 694*cf7f2e2dSJohn Marino /* If any of the children of a union are vectors, flag the 6955796c8dcSSimon Schubert union as a vector also. This allows e.g. a union of two 6965796c8dcSSimon Schubert vector types to show up automatically in "info vector". */ 6975796c8dcSSimon Schubert if (TYPE_VECTOR (field_type)) 6985796c8dcSSimon Schubert TYPE_VECTOR (type) = 1; 6995796c8dcSSimon Schubert } 700*cf7f2e2dSJohn Marino return type; 701*cf7f2e2dSJohn Marino } 702*cf7f2e2dSJohn Marino 703*cf7f2e2dSJohn Marino case TDESC_TYPE_FLAGS: 704*cf7f2e2dSJohn Marino { 705*cf7f2e2dSJohn Marino struct tdesc_type_flag *f; 706*cf7f2e2dSJohn Marino int ix; 707*cf7f2e2dSJohn Marino 708*cf7f2e2dSJohn Marino type = arch_flags_type (gdbarch, xstrdup (tdesc_type->name), 709*cf7f2e2dSJohn Marino tdesc_type->u.f.size); 710*cf7f2e2dSJohn Marino for (ix = 0; 711*cf7f2e2dSJohn Marino VEC_iterate (tdesc_type_flag, tdesc_type->u.f.flags, ix, f); 712*cf7f2e2dSJohn Marino ix++) 713*cf7f2e2dSJohn Marino /* Note that contrary to the function name, this call will 714*cf7f2e2dSJohn Marino just set the properties of an already-allocated 715*cf7f2e2dSJohn Marino field. */ 716*cf7f2e2dSJohn Marino append_flags_type_flag (type, f->start, 717*cf7f2e2dSJohn Marino *f->name ? f->name : NULL); 7185796c8dcSSimon Schubert 7195796c8dcSSimon Schubert return type; 7205796c8dcSSimon Schubert } 7215796c8dcSSimon Schubert } 7225796c8dcSSimon Schubert 7235796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 7245796c8dcSSimon Schubert "Type \"%s\" has an unknown kind %d", 7255796c8dcSSimon Schubert tdesc_type->name, tdesc_type->kind); 7265796c8dcSSimon Schubert } 7275796c8dcSSimon Schubert 7285796c8dcSSimon Schubert 7295796c8dcSSimon Schubert /* Support for registers from target descriptions. */ 7305796c8dcSSimon Schubert 7315796c8dcSSimon Schubert /* Construct the per-gdbarch data. */ 7325796c8dcSSimon Schubert 7335796c8dcSSimon Schubert static void * 7345796c8dcSSimon Schubert tdesc_data_init (struct obstack *obstack) 7355796c8dcSSimon Schubert { 7365796c8dcSSimon Schubert struct tdesc_arch_data *data; 7375796c8dcSSimon Schubert 7385796c8dcSSimon Schubert data = OBSTACK_ZALLOC (obstack, struct tdesc_arch_data); 7395796c8dcSSimon Schubert return data; 7405796c8dcSSimon Schubert } 7415796c8dcSSimon Schubert 7425796c8dcSSimon Schubert /* Similar, but for the temporary copy used during architecture 7435796c8dcSSimon Schubert initialization. */ 7445796c8dcSSimon Schubert 7455796c8dcSSimon Schubert struct tdesc_arch_data * 7465796c8dcSSimon Schubert tdesc_data_alloc (void) 7475796c8dcSSimon Schubert { 7485796c8dcSSimon Schubert return XZALLOC (struct tdesc_arch_data); 7495796c8dcSSimon Schubert } 7505796c8dcSSimon Schubert 7515796c8dcSSimon Schubert /* Free something allocated by tdesc_data_alloc, if it is not going 7525796c8dcSSimon Schubert to be used (for instance if it was unsuitable for the 7535796c8dcSSimon Schubert architecture). */ 7545796c8dcSSimon Schubert 7555796c8dcSSimon Schubert void 7565796c8dcSSimon Schubert tdesc_data_cleanup (void *data_untyped) 7575796c8dcSSimon Schubert { 7585796c8dcSSimon Schubert struct tdesc_arch_data *data = data_untyped; 7595796c8dcSSimon Schubert 7605796c8dcSSimon Schubert VEC_free (tdesc_arch_reg, data->arch_regs); 7615796c8dcSSimon Schubert xfree (data); 7625796c8dcSSimon Schubert } 7635796c8dcSSimon Schubert 7645796c8dcSSimon Schubert /* Search FEATURE for a register named NAME. */ 7655796c8dcSSimon Schubert 7665796c8dcSSimon Schubert static struct tdesc_reg * 7675796c8dcSSimon Schubert tdesc_find_register_early (const struct tdesc_feature *feature, 7685796c8dcSSimon Schubert const char *name) 7695796c8dcSSimon Schubert { 7705796c8dcSSimon Schubert int ixr; 7715796c8dcSSimon Schubert struct tdesc_reg *reg; 7725796c8dcSSimon Schubert 7735796c8dcSSimon Schubert for (ixr = 0; 7745796c8dcSSimon Schubert VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg); 7755796c8dcSSimon Schubert ixr++) 7765796c8dcSSimon Schubert if (strcasecmp (reg->name, name) == 0) 7775796c8dcSSimon Schubert return reg; 7785796c8dcSSimon Schubert 7795796c8dcSSimon Schubert return NULL; 7805796c8dcSSimon Schubert } 7815796c8dcSSimon Schubert 7825796c8dcSSimon Schubert /* Search FEATURE for a register named NAME. Assign REGNO to it. */ 7835796c8dcSSimon Schubert 7845796c8dcSSimon Schubert int 7855796c8dcSSimon Schubert tdesc_numbered_register (const struct tdesc_feature *feature, 7865796c8dcSSimon Schubert struct tdesc_arch_data *data, 7875796c8dcSSimon Schubert int regno, const char *name) 7885796c8dcSSimon Schubert { 7895796c8dcSSimon Schubert struct tdesc_arch_reg arch_reg = { 0 }; 7905796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register_early (feature, name); 7915796c8dcSSimon Schubert 7925796c8dcSSimon Schubert if (reg == NULL) 7935796c8dcSSimon Schubert return 0; 7945796c8dcSSimon Schubert 7955796c8dcSSimon Schubert /* Make sure the vector includes a REGNO'th element. */ 7965796c8dcSSimon Schubert while (regno >= VEC_length (tdesc_arch_reg, data->arch_regs)) 7975796c8dcSSimon Schubert VEC_safe_push (tdesc_arch_reg, data->arch_regs, &arch_reg); 7985796c8dcSSimon Schubert 7995796c8dcSSimon Schubert arch_reg.reg = reg; 8005796c8dcSSimon Schubert VEC_replace (tdesc_arch_reg, data->arch_regs, regno, &arch_reg); 8015796c8dcSSimon Schubert return 1; 8025796c8dcSSimon Schubert } 8035796c8dcSSimon Schubert 8045796c8dcSSimon Schubert /* Search FEATURE for a register named NAME, but do not assign a fixed 8055796c8dcSSimon Schubert register number to it. */ 8065796c8dcSSimon Schubert 8075796c8dcSSimon Schubert int 8085796c8dcSSimon Schubert tdesc_unnumbered_register (const struct tdesc_feature *feature, 8095796c8dcSSimon Schubert const char *name) 8105796c8dcSSimon Schubert { 8115796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register_early (feature, name); 8125796c8dcSSimon Schubert 8135796c8dcSSimon Schubert if (reg == NULL) 8145796c8dcSSimon Schubert return 0; 8155796c8dcSSimon Schubert 8165796c8dcSSimon Schubert return 1; 8175796c8dcSSimon Schubert } 8185796c8dcSSimon Schubert 8195796c8dcSSimon Schubert /* Search FEATURE for a register whose name is in NAMES and assign 8205796c8dcSSimon Schubert REGNO to it. */ 8215796c8dcSSimon Schubert 8225796c8dcSSimon Schubert int 8235796c8dcSSimon Schubert tdesc_numbered_register_choices (const struct tdesc_feature *feature, 8245796c8dcSSimon Schubert struct tdesc_arch_data *data, 8255796c8dcSSimon Schubert int regno, const char *const names[]) 8265796c8dcSSimon Schubert { 8275796c8dcSSimon Schubert int i; 8285796c8dcSSimon Schubert 8295796c8dcSSimon Schubert for (i = 0; names[i] != NULL; i++) 8305796c8dcSSimon Schubert if (tdesc_numbered_register (feature, data, regno, names[i])) 8315796c8dcSSimon Schubert return 1; 8325796c8dcSSimon Schubert 8335796c8dcSSimon Schubert return 0; 8345796c8dcSSimon Schubert } 8355796c8dcSSimon Schubert 8365796c8dcSSimon Schubert /* Search FEATURE for a register named NAME, and return its size in 8375796c8dcSSimon Schubert bits. The register must exist. */ 8385796c8dcSSimon Schubert 8395796c8dcSSimon Schubert int 8405796c8dcSSimon Schubert tdesc_register_size (const struct tdesc_feature *feature, 8415796c8dcSSimon Schubert const char *name) 8425796c8dcSSimon Schubert { 8435796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register_early (feature, name); 8445796c8dcSSimon Schubert 8455796c8dcSSimon Schubert gdb_assert (reg != NULL); 8465796c8dcSSimon Schubert return reg->bitsize; 8475796c8dcSSimon Schubert } 8485796c8dcSSimon Schubert 8495796c8dcSSimon Schubert /* Look up a register by its GDB internal register number. */ 8505796c8dcSSimon Schubert 8515796c8dcSSimon Schubert static struct tdesc_arch_reg * 8525796c8dcSSimon Schubert tdesc_find_arch_register (struct gdbarch *gdbarch, int regno) 8535796c8dcSSimon Schubert { 8545796c8dcSSimon Schubert struct tdesc_arch_data *data; 8555796c8dcSSimon Schubert 8565796c8dcSSimon Schubert data = gdbarch_data (gdbarch, tdesc_data); 8575796c8dcSSimon Schubert if (regno < VEC_length (tdesc_arch_reg, data->arch_regs)) 8585796c8dcSSimon Schubert return VEC_index (tdesc_arch_reg, data->arch_regs, regno); 8595796c8dcSSimon Schubert else 8605796c8dcSSimon Schubert return NULL; 8615796c8dcSSimon Schubert } 8625796c8dcSSimon Schubert 8635796c8dcSSimon Schubert static struct tdesc_reg * 8645796c8dcSSimon Schubert tdesc_find_register (struct gdbarch *gdbarch, int regno) 8655796c8dcSSimon Schubert { 8665796c8dcSSimon Schubert struct tdesc_arch_reg *reg = tdesc_find_arch_register (gdbarch, regno); 867*cf7f2e2dSJohn Marino 8685796c8dcSSimon Schubert return reg? reg->reg : NULL; 8695796c8dcSSimon Schubert } 8705796c8dcSSimon Schubert 8715796c8dcSSimon Schubert /* Return the name of register REGNO, from the target description or 8725796c8dcSSimon Schubert from an architecture-provided pseudo_register_name method. */ 8735796c8dcSSimon Schubert 8745796c8dcSSimon Schubert const char * 8755796c8dcSSimon Schubert tdesc_register_name (struct gdbarch *gdbarch, int regno) 8765796c8dcSSimon Schubert { 8775796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno); 8785796c8dcSSimon Schubert int num_regs = gdbarch_num_regs (gdbarch); 8795796c8dcSSimon Schubert int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch); 8805796c8dcSSimon Schubert 8815796c8dcSSimon Schubert if (reg != NULL) 8825796c8dcSSimon Schubert return reg->name; 8835796c8dcSSimon Schubert 8845796c8dcSSimon Schubert if (regno >= num_regs && regno < num_regs + num_pseudo_regs) 8855796c8dcSSimon Schubert { 8865796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data); 887*cf7f2e2dSJohn Marino 8885796c8dcSSimon Schubert gdb_assert (data->pseudo_register_name != NULL); 8895796c8dcSSimon Schubert return data->pseudo_register_name (gdbarch, regno); 8905796c8dcSSimon Schubert } 8915796c8dcSSimon Schubert 8925796c8dcSSimon Schubert return ""; 8935796c8dcSSimon Schubert } 8945796c8dcSSimon Schubert 8955796c8dcSSimon Schubert struct type * 8965796c8dcSSimon Schubert tdesc_register_type (struct gdbarch *gdbarch, int regno) 8975796c8dcSSimon Schubert { 8985796c8dcSSimon Schubert struct tdesc_arch_reg *arch_reg = tdesc_find_arch_register (gdbarch, regno); 8995796c8dcSSimon Schubert struct tdesc_reg *reg = arch_reg? arch_reg->reg : NULL; 9005796c8dcSSimon Schubert int num_regs = gdbarch_num_regs (gdbarch); 9015796c8dcSSimon Schubert int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch); 9025796c8dcSSimon Schubert 9035796c8dcSSimon Schubert if (reg == NULL && regno >= num_regs && regno < num_regs + num_pseudo_regs) 9045796c8dcSSimon Schubert { 9055796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data); 906*cf7f2e2dSJohn Marino 9075796c8dcSSimon Schubert gdb_assert (data->pseudo_register_type != NULL); 9085796c8dcSSimon Schubert return data->pseudo_register_type (gdbarch, regno); 9095796c8dcSSimon Schubert } 9105796c8dcSSimon Schubert 9115796c8dcSSimon Schubert if (reg == NULL) 9125796c8dcSSimon Schubert /* Return "int0_t", since "void" has a misleading size of one. */ 9135796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int0; 9145796c8dcSSimon Schubert 9155796c8dcSSimon Schubert if (arch_reg->type == NULL) 9165796c8dcSSimon Schubert { 9175796c8dcSSimon Schubert /* First check for a predefined or target defined type. */ 9185796c8dcSSimon Schubert if (reg->tdesc_type) 9195796c8dcSSimon Schubert arch_reg->type = tdesc_gdb_type (gdbarch, reg->tdesc_type); 9205796c8dcSSimon Schubert 9215796c8dcSSimon Schubert /* Next try size-sensitive type shortcuts. */ 9225796c8dcSSimon Schubert else if (strcmp (reg->type, "float") == 0) 9235796c8dcSSimon Schubert { 9245796c8dcSSimon Schubert if (reg->bitsize == gdbarch_float_bit (gdbarch)) 9255796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_float; 9265796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_double_bit (gdbarch)) 9275796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_double; 9285796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_long_double_bit (gdbarch)) 9295796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_long_double; 9305796c8dcSSimon Schubert else 9315796c8dcSSimon Schubert { 9325796c8dcSSimon Schubert warning (_("Register \"%s\" has an unsupported size (%d bits)"), 9335796c8dcSSimon Schubert reg->name, reg->bitsize); 9345796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_double; 9355796c8dcSSimon Schubert } 9365796c8dcSSimon Schubert } 9375796c8dcSSimon Schubert else if (strcmp (reg->type, "int") == 0) 9385796c8dcSSimon Schubert { 9395796c8dcSSimon Schubert if (reg->bitsize == gdbarch_long_bit (gdbarch)) 9405796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_long; 9415796c8dcSSimon Schubert else if (reg->bitsize == TARGET_CHAR_BIT) 9425796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_char; 9435796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_short_bit (gdbarch)) 9445796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_short; 9455796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_int_bit (gdbarch)) 9465796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_int; 9475796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_long_long_bit (gdbarch)) 9485796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_long_long; 9495796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_ptr_bit (gdbarch)) 9505796c8dcSSimon Schubert /* A bit desperate by this point... */ 9515796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_data_ptr; 9525796c8dcSSimon Schubert else 9535796c8dcSSimon Schubert { 9545796c8dcSSimon Schubert warning (_("Register \"%s\" has an unsupported size (%d bits)"), 9555796c8dcSSimon Schubert reg->name, reg->bitsize); 9565796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_long; 9575796c8dcSSimon Schubert } 9585796c8dcSSimon Schubert } 9595796c8dcSSimon Schubert 9605796c8dcSSimon Schubert if (arch_reg->type == NULL) 9615796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 9625796c8dcSSimon Schubert "Register \"%s\" has an unknown type \"%s\"", 9635796c8dcSSimon Schubert reg->name, reg->type); 9645796c8dcSSimon Schubert } 9655796c8dcSSimon Schubert 9665796c8dcSSimon Schubert return arch_reg->type; 9675796c8dcSSimon Schubert } 9685796c8dcSSimon Schubert 9695796c8dcSSimon Schubert static int 9705796c8dcSSimon Schubert tdesc_remote_register_number (struct gdbarch *gdbarch, int regno) 9715796c8dcSSimon Schubert { 9725796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno); 9735796c8dcSSimon Schubert 9745796c8dcSSimon Schubert if (reg != NULL) 9755796c8dcSSimon Schubert return reg->target_regnum; 9765796c8dcSSimon Schubert else 9775796c8dcSSimon Schubert return -1; 9785796c8dcSSimon Schubert } 9795796c8dcSSimon Schubert 9805796c8dcSSimon Schubert /* Check whether REGNUM is a member of REGGROUP. Registers from the 9815796c8dcSSimon Schubert target description may be classified as general, float, or vector. 9825796c8dcSSimon Schubert Unlike a gdbarch register_reggroup_p method, this function will 9835796c8dcSSimon Schubert return -1 if it does not know; the caller should handle registers 9845796c8dcSSimon Schubert with no specified group. 9855796c8dcSSimon Schubert 9865796c8dcSSimon Schubert Arbitrary strings (other than "general", "float", and "vector") 9875796c8dcSSimon Schubert from the description are not used; they cause the register to be 9885796c8dcSSimon Schubert displayed in "info all-registers" but excluded from "info 9895796c8dcSSimon Schubert registers" et al. The names of containing features are also not 9905796c8dcSSimon Schubert used. This might be extended to display registers in some more 9915796c8dcSSimon Schubert useful groupings. 9925796c8dcSSimon Schubert 9935796c8dcSSimon Schubert The save-restore flag is also implemented here. */ 9945796c8dcSSimon Schubert 9955796c8dcSSimon Schubert int 9965796c8dcSSimon Schubert tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno, 9975796c8dcSSimon Schubert struct reggroup *reggroup) 9985796c8dcSSimon Schubert { 9995796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno); 10005796c8dcSSimon Schubert 10015796c8dcSSimon Schubert if (reg != NULL && reg->group != NULL) 10025796c8dcSSimon Schubert { 10035796c8dcSSimon Schubert int general_p = 0, float_p = 0, vector_p = 0; 10045796c8dcSSimon Schubert 10055796c8dcSSimon Schubert if (strcmp (reg->group, "general") == 0) 10065796c8dcSSimon Schubert general_p = 1; 10075796c8dcSSimon Schubert else if (strcmp (reg->group, "float") == 0) 10085796c8dcSSimon Schubert float_p = 1; 10095796c8dcSSimon Schubert else if (strcmp (reg->group, "vector") == 0) 10105796c8dcSSimon Schubert vector_p = 1; 10115796c8dcSSimon Schubert 10125796c8dcSSimon Schubert if (reggroup == float_reggroup) 10135796c8dcSSimon Schubert return float_p; 10145796c8dcSSimon Schubert 10155796c8dcSSimon Schubert if (reggroup == vector_reggroup) 10165796c8dcSSimon Schubert return vector_p; 10175796c8dcSSimon Schubert 10185796c8dcSSimon Schubert if (reggroup == general_reggroup) 10195796c8dcSSimon Schubert return general_p; 10205796c8dcSSimon Schubert } 10215796c8dcSSimon Schubert 10225796c8dcSSimon Schubert if (reg != NULL 10235796c8dcSSimon Schubert && (reggroup == save_reggroup || reggroup == restore_reggroup)) 10245796c8dcSSimon Schubert return reg->save_restore; 10255796c8dcSSimon Schubert 10265796c8dcSSimon Schubert return -1; 10275796c8dcSSimon Schubert } 10285796c8dcSSimon Schubert 10295796c8dcSSimon Schubert /* Check whether REGNUM is a member of REGGROUP. Registers with no 10305796c8dcSSimon Schubert group specified go to the default reggroup function and are handled 10315796c8dcSSimon Schubert by type. */ 10325796c8dcSSimon Schubert 10335796c8dcSSimon Schubert static int 10345796c8dcSSimon Schubert tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regno, 10355796c8dcSSimon Schubert struct reggroup *reggroup) 10365796c8dcSSimon Schubert { 10375796c8dcSSimon Schubert int num_regs = gdbarch_num_regs (gdbarch); 10385796c8dcSSimon Schubert int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch); 10395796c8dcSSimon Schubert int ret; 10405796c8dcSSimon Schubert 10415796c8dcSSimon Schubert if (regno >= num_regs && regno < num_regs + num_pseudo_regs) 10425796c8dcSSimon Schubert { 10435796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data); 1044*cf7f2e2dSJohn Marino 10455796c8dcSSimon Schubert if (data->pseudo_register_reggroup_p != NULL) 10465796c8dcSSimon Schubert return data->pseudo_register_reggroup_p (gdbarch, regno, reggroup); 10475796c8dcSSimon Schubert /* Otherwise fall through to the default reggroup_p. */ 10485796c8dcSSimon Schubert } 10495796c8dcSSimon Schubert 10505796c8dcSSimon Schubert ret = tdesc_register_in_reggroup_p (gdbarch, regno, reggroup); 10515796c8dcSSimon Schubert if (ret != -1) 10525796c8dcSSimon Schubert return ret; 10535796c8dcSSimon Schubert 10545796c8dcSSimon Schubert return default_register_reggroup_p (gdbarch, regno, reggroup); 10555796c8dcSSimon Schubert } 10565796c8dcSSimon Schubert 10575796c8dcSSimon Schubert /* Record architecture-specific functions to call for pseudo-register 10585796c8dcSSimon Schubert support. */ 10595796c8dcSSimon Schubert 10605796c8dcSSimon Schubert void 10615796c8dcSSimon Schubert set_tdesc_pseudo_register_name (struct gdbarch *gdbarch, 10625796c8dcSSimon Schubert gdbarch_register_name_ftype *pseudo_name) 10635796c8dcSSimon Schubert { 10645796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data); 10655796c8dcSSimon Schubert 10665796c8dcSSimon Schubert data->pseudo_register_name = pseudo_name; 10675796c8dcSSimon Schubert } 10685796c8dcSSimon Schubert 10695796c8dcSSimon Schubert void 10705796c8dcSSimon Schubert set_tdesc_pseudo_register_type (struct gdbarch *gdbarch, 10715796c8dcSSimon Schubert gdbarch_register_type_ftype *pseudo_type) 10725796c8dcSSimon Schubert { 10735796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data); 10745796c8dcSSimon Schubert 10755796c8dcSSimon Schubert data->pseudo_register_type = pseudo_type; 10765796c8dcSSimon Schubert } 10775796c8dcSSimon Schubert 10785796c8dcSSimon Schubert void 10795796c8dcSSimon Schubert set_tdesc_pseudo_register_reggroup_p 10805796c8dcSSimon Schubert (struct gdbarch *gdbarch, 10815796c8dcSSimon Schubert gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p) 10825796c8dcSSimon Schubert { 10835796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data); 10845796c8dcSSimon Schubert 10855796c8dcSSimon Schubert data->pseudo_register_reggroup_p = pseudo_reggroup_p; 10865796c8dcSSimon Schubert } 10875796c8dcSSimon Schubert 10885796c8dcSSimon Schubert /* Update GDBARCH to use the target description for registers. */ 10895796c8dcSSimon Schubert 10905796c8dcSSimon Schubert void 10915796c8dcSSimon Schubert tdesc_use_registers (struct gdbarch *gdbarch, 10925796c8dcSSimon Schubert const struct target_desc *target_desc, 10935796c8dcSSimon Schubert struct tdesc_arch_data *early_data) 10945796c8dcSSimon Schubert { 10955796c8dcSSimon Schubert int num_regs = gdbarch_num_regs (gdbarch); 1096*cf7f2e2dSJohn Marino int ixf, ixr; 10975796c8dcSSimon Schubert struct tdesc_feature *feature; 10985796c8dcSSimon Schubert struct tdesc_reg *reg; 10995796c8dcSSimon Schubert struct tdesc_arch_data *data; 11005796c8dcSSimon Schubert struct tdesc_arch_reg *arch_reg, new_arch_reg = { 0 }; 11015796c8dcSSimon Schubert htab_t reg_hash; 11025796c8dcSSimon Schubert 11035796c8dcSSimon Schubert /* We can't use the description for registers if it doesn't describe 11045796c8dcSSimon Schubert any. This function should only be called after validating 11055796c8dcSSimon Schubert registers, so the caller should know that registers are 11065796c8dcSSimon Schubert included. */ 11075796c8dcSSimon Schubert gdb_assert (tdesc_has_registers (target_desc)); 11085796c8dcSSimon Schubert 11095796c8dcSSimon Schubert data = gdbarch_data (gdbarch, tdesc_data); 11105796c8dcSSimon Schubert data->arch_regs = early_data->arch_regs; 11115796c8dcSSimon Schubert xfree (early_data); 11125796c8dcSSimon Schubert 11135796c8dcSSimon Schubert /* Build up a set of all registers, so that we can assign register 11145796c8dcSSimon Schubert numbers where needed. The hash table expands as necessary, so 11155796c8dcSSimon Schubert the initial size is arbitrary. */ 11165796c8dcSSimon Schubert reg_hash = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL); 11175796c8dcSSimon Schubert for (ixf = 0; 11185796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature); 11195796c8dcSSimon Schubert ixf++) 11205796c8dcSSimon Schubert for (ixr = 0; 11215796c8dcSSimon Schubert VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg); 11225796c8dcSSimon Schubert ixr++) 11235796c8dcSSimon Schubert { 11245796c8dcSSimon Schubert void **slot = htab_find_slot (reg_hash, reg, INSERT); 11255796c8dcSSimon Schubert 11265796c8dcSSimon Schubert *slot = reg; 11275796c8dcSSimon Schubert } 11285796c8dcSSimon Schubert 11295796c8dcSSimon Schubert /* Remove any registers which were assigned numbers by the 11305796c8dcSSimon Schubert architecture. */ 11315796c8dcSSimon Schubert for (ixr = 0; 11325796c8dcSSimon Schubert VEC_iterate (tdesc_arch_reg, data->arch_regs, ixr, arch_reg); 11335796c8dcSSimon Schubert ixr++) 11345796c8dcSSimon Schubert if (arch_reg->reg) 11355796c8dcSSimon Schubert htab_remove_elt (reg_hash, arch_reg->reg); 11365796c8dcSSimon Schubert 11375796c8dcSSimon Schubert /* Assign numbers to the remaining registers and add them to the 11385796c8dcSSimon Schubert list of registers. The new numbers are always above gdbarch_num_regs. 11395796c8dcSSimon Schubert Iterate over the features, not the hash table, so that the order 11405796c8dcSSimon Schubert matches that in the target description. */ 11415796c8dcSSimon Schubert 11425796c8dcSSimon Schubert gdb_assert (VEC_length (tdesc_arch_reg, data->arch_regs) <= num_regs); 11435796c8dcSSimon Schubert while (VEC_length (tdesc_arch_reg, data->arch_regs) < num_regs) 11445796c8dcSSimon Schubert VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg); 11455796c8dcSSimon Schubert for (ixf = 0; 11465796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature); 11475796c8dcSSimon Schubert ixf++) 11485796c8dcSSimon Schubert for (ixr = 0; 11495796c8dcSSimon Schubert VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg); 11505796c8dcSSimon Schubert ixr++) 11515796c8dcSSimon Schubert if (htab_find (reg_hash, reg) != NULL) 11525796c8dcSSimon Schubert { 11535796c8dcSSimon Schubert new_arch_reg.reg = reg; 11545796c8dcSSimon Schubert VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg); 11555796c8dcSSimon Schubert num_regs++; 11565796c8dcSSimon Schubert } 11575796c8dcSSimon Schubert 11585796c8dcSSimon Schubert htab_delete (reg_hash); 11595796c8dcSSimon Schubert 11605796c8dcSSimon Schubert /* Update the architecture. */ 11615796c8dcSSimon Schubert set_gdbarch_num_regs (gdbarch, num_regs); 11625796c8dcSSimon Schubert set_gdbarch_register_name (gdbarch, tdesc_register_name); 11635796c8dcSSimon Schubert set_gdbarch_register_type (gdbarch, tdesc_register_type); 11645796c8dcSSimon Schubert set_gdbarch_remote_register_number (gdbarch, 11655796c8dcSSimon Schubert tdesc_remote_register_number); 11665796c8dcSSimon Schubert set_gdbarch_register_reggroup_p (gdbarch, tdesc_register_reggroup_p); 11675796c8dcSSimon Schubert } 11685796c8dcSSimon Schubert 11695796c8dcSSimon Schubert 11705796c8dcSSimon Schubert /* Methods for constructing a target description. */ 11715796c8dcSSimon Schubert 11725796c8dcSSimon Schubert static void 11735796c8dcSSimon Schubert tdesc_free_reg (struct tdesc_reg *reg) 11745796c8dcSSimon Schubert { 11755796c8dcSSimon Schubert xfree (reg->name); 11765796c8dcSSimon Schubert xfree (reg->type); 11775796c8dcSSimon Schubert xfree (reg->group); 11785796c8dcSSimon Schubert xfree (reg); 11795796c8dcSSimon Schubert } 11805796c8dcSSimon Schubert 11815796c8dcSSimon Schubert void 11825796c8dcSSimon Schubert tdesc_create_reg (struct tdesc_feature *feature, const char *name, 11835796c8dcSSimon Schubert int regnum, int save_restore, const char *group, 11845796c8dcSSimon Schubert int bitsize, const char *type) 11855796c8dcSSimon Schubert { 11865796c8dcSSimon Schubert struct tdesc_reg *reg = XZALLOC (struct tdesc_reg); 11875796c8dcSSimon Schubert 11885796c8dcSSimon Schubert reg->name = xstrdup (name); 11895796c8dcSSimon Schubert reg->target_regnum = regnum; 11905796c8dcSSimon Schubert reg->save_restore = save_restore; 11915796c8dcSSimon Schubert reg->group = group ? xstrdup (group) : NULL; 11925796c8dcSSimon Schubert reg->bitsize = bitsize; 11935796c8dcSSimon Schubert reg->type = type ? xstrdup (type) : xstrdup ("<unknown>"); 11945796c8dcSSimon Schubert 11955796c8dcSSimon Schubert /* If the register's type is target-defined, look it up now. We may not 11965796c8dcSSimon Schubert have easy access to the containing feature when we want it later. */ 11975796c8dcSSimon Schubert reg->tdesc_type = tdesc_named_type (feature, reg->type); 11985796c8dcSSimon Schubert 11995796c8dcSSimon Schubert VEC_safe_push (tdesc_reg_p, feature->registers, reg); 12005796c8dcSSimon Schubert } 12015796c8dcSSimon Schubert 12025796c8dcSSimon Schubert static void 12035796c8dcSSimon Schubert tdesc_free_type (struct tdesc_type *type) 12045796c8dcSSimon Schubert { 12055796c8dcSSimon Schubert switch (type->kind) 12065796c8dcSSimon Schubert { 1207*cf7f2e2dSJohn Marino case TDESC_TYPE_STRUCT: 12085796c8dcSSimon Schubert case TDESC_TYPE_UNION: 12095796c8dcSSimon Schubert { 12105796c8dcSSimon Schubert struct tdesc_type_field *f; 12115796c8dcSSimon Schubert int ix; 12125796c8dcSSimon Schubert 12135796c8dcSSimon Schubert for (ix = 0; 12145796c8dcSSimon Schubert VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f); 12155796c8dcSSimon Schubert ix++) 12165796c8dcSSimon Schubert xfree (f->name); 12175796c8dcSSimon Schubert 12185796c8dcSSimon Schubert VEC_free (tdesc_type_field, type->u.u.fields); 12195796c8dcSSimon Schubert } 12205796c8dcSSimon Schubert break; 12215796c8dcSSimon Schubert 1222*cf7f2e2dSJohn Marino case TDESC_TYPE_FLAGS: 1223*cf7f2e2dSJohn Marino { 1224*cf7f2e2dSJohn Marino struct tdesc_type_flag *f; 1225*cf7f2e2dSJohn Marino int ix; 1226*cf7f2e2dSJohn Marino 1227*cf7f2e2dSJohn Marino for (ix = 0; 1228*cf7f2e2dSJohn Marino VEC_iterate (tdesc_type_flag, type->u.f.flags, ix, f); 1229*cf7f2e2dSJohn Marino ix++) 1230*cf7f2e2dSJohn Marino xfree (f->name); 1231*cf7f2e2dSJohn Marino 1232*cf7f2e2dSJohn Marino VEC_free (tdesc_type_flag, type->u.f.flags); 1233*cf7f2e2dSJohn Marino } 1234*cf7f2e2dSJohn Marino break; 1235*cf7f2e2dSJohn Marino 12365796c8dcSSimon Schubert default: 12375796c8dcSSimon Schubert break; 12385796c8dcSSimon Schubert } 12395796c8dcSSimon Schubert 12405796c8dcSSimon Schubert xfree (type->name); 12415796c8dcSSimon Schubert xfree (type); 12425796c8dcSSimon Schubert } 12435796c8dcSSimon Schubert 12445796c8dcSSimon Schubert struct tdesc_type * 12455796c8dcSSimon Schubert tdesc_create_vector (struct tdesc_feature *feature, const char *name, 12465796c8dcSSimon Schubert struct tdesc_type *field_type, int count) 12475796c8dcSSimon Schubert { 12485796c8dcSSimon Schubert struct tdesc_type *type = XZALLOC (struct tdesc_type); 12495796c8dcSSimon Schubert 12505796c8dcSSimon Schubert type->name = xstrdup (name); 12515796c8dcSSimon Schubert type->kind = TDESC_TYPE_VECTOR; 12525796c8dcSSimon Schubert type->u.v.type = field_type; 12535796c8dcSSimon Schubert type->u.v.count = count; 12545796c8dcSSimon Schubert 12555796c8dcSSimon Schubert VEC_safe_push (tdesc_type_p, feature->types, type); 12565796c8dcSSimon Schubert return type; 12575796c8dcSSimon Schubert } 12585796c8dcSSimon Schubert 12595796c8dcSSimon Schubert struct tdesc_type * 1260*cf7f2e2dSJohn Marino tdesc_create_struct (struct tdesc_feature *feature, const char *name) 1261*cf7f2e2dSJohn Marino { 1262*cf7f2e2dSJohn Marino struct tdesc_type *type = XZALLOC (struct tdesc_type); 1263*cf7f2e2dSJohn Marino 1264*cf7f2e2dSJohn Marino type->name = xstrdup (name); 1265*cf7f2e2dSJohn Marino type->kind = TDESC_TYPE_STRUCT; 1266*cf7f2e2dSJohn Marino 1267*cf7f2e2dSJohn Marino VEC_safe_push (tdesc_type_p, feature->types, type); 1268*cf7f2e2dSJohn Marino return type; 1269*cf7f2e2dSJohn Marino } 1270*cf7f2e2dSJohn Marino 1271*cf7f2e2dSJohn Marino /* Set the total length of TYPE. Structs which contain bitfields may 1272*cf7f2e2dSJohn Marino omit the reserved bits, so the end of the last field may not 1273*cf7f2e2dSJohn Marino suffice. */ 1274*cf7f2e2dSJohn Marino 1275*cf7f2e2dSJohn Marino void 1276*cf7f2e2dSJohn Marino tdesc_set_struct_size (struct tdesc_type *type, LONGEST size) 1277*cf7f2e2dSJohn Marino { 1278*cf7f2e2dSJohn Marino gdb_assert (type->kind == TDESC_TYPE_STRUCT); 1279*cf7f2e2dSJohn Marino type->u.u.size = size; 1280*cf7f2e2dSJohn Marino } 1281*cf7f2e2dSJohn Marino 1282*cf7f2e2dSJohn Marino struct tdesc_type * 12835796c8dcSSimon Schubert tdesc_create_union (struct tdesc_feature *feature, const char *name) 12845796c8dcSSimon Schubert { 12855796c8dcSSimon Schubert struct tdesc_type *type = XZALLOC (struct tdesc_type); 12865796c8dcSSimon Schubert 12875796c8dcSSimon Schubert type->name = xstrdup (name); 12885796c8dcSSimon Schubert type->kind = TDESC_TYPE_UNION; 12895796c8dcSSimon Schubert 12905796c8dcSSimon Schubert VEC_safe_push (tdesc_type_p, feature->types, type); 12915796c8dcSSimon Schubert return type; 12925796c8dcSSimon Schubert } 12935796c8dcSSimon Schubert 1294*cf7f2e2dSJohn Marino struct tdesc_type * 1295*cf7f2e2dSJohn Marino tdesc_create_flags (struct tdesc_feature *feature, const char *name, 1296*cf7f2e2dSJohn Marino LONGEST size) 1297*cf7f2e2dSJohn Marino { 1298*cf7f2e2dSJohn Marino struct tdesc_type *type = XZALLOC (struct tdesc_type); 1299*cf7f2e2dSJohn Marino 1300*cf7f2e2dSJohn Marino type->name = xstrdup (name); 1301*cf7f2e2dSJohn Marino type->kind = TDESC_TYPE_FLAGS; 1302*cf7f2e2dSJohn Marino type->u.f.size = size; 1303*cf7f2e2dSJohn Marino 1304*cf7f2e2dSJohn Marino VEC_safe_push (tdesc_type_p, feature->types, type); 1305*cf7f2e2dSJohn Marino return type; 1306*cf7f2e2dSJohn Marino } 1307*cf7f2e2dSJohn Marino 1308*cf7f2e2dSJohn Marino /* Add a new field. Return a temporary pointer to the field, which 1309*cf7f2e2dSJohn Marino is only valid until the next call to tdesc_add_field (the vector 1310*cf7f2e2dSJohn Marino might be reallocated). */ 1311*cf7f2e2dSJohn Marino 13125796c8dcSSimon Schubert void 13135796c8dcSSimon Schubert tdesc_add_field (struct tdesc_type *type, const char *field_name, 13145796c8dcSSimon Schubert struct tdesc_type *field_type) 13155796c8dcSSimon Schubert { 13165796c8dcSSimon Schubert struct tdesc_type_field f = { 0 }; 13175796c8dcSSimon Schubert 1318*cf7f2e2dSJohn Marino gdb_assert (type->kind == TDESC_TYPE_UNION 1319*cf7f2e2dSJohn Marino || type->kind == TDESC_TYPE_STRUCT); 13205796c8dcSSimon Schubert 13215796c8dcSSimon Schubert f.name = xstrdup (field_name); 13225796c8dcSSimon Schubert f.type = field_type; 13235796c8dcSSimon Schubert 13245796c8dcSSimon Schubert VEC_safe_push (tdesc_type_field, type->u.u.fields, &f); 13255796c8dcSSimon Schubert } 13265796c8dcSSimon Schubert 1327*cf7f2e2dSJohn Marino /* Add a new bitfield. */ 1328*cf7f2e2dSJohn Marino 1329*cf7f2e2dSJohn Marino void 1330*cf7f2e2dSJohn Marino tdesc_add_bitfield (struct tdesc_type *type, const char *field_name, 1331*cf7f2e2dSJohn Marino int start, int end) 1332*cf7f2e2dSJohn Marino { 1333*cf7f2e2dSJohn Marino struct tdesc_type_field f = { 0 }; 1334*cf7f2e2dSJohn Marino 1335*cf7f2e2dSJohn Marino gdb_assert (type->kind == TDESC_TYPE_STRUCT); 1336*cf7f2e2dSJohn Marino 1337*cf7f2e2dSJohn Marino f.name = xstrdup (field_name); 1338*cf7f2e2dSJohn Marino f.start = start; 1339*cf7f2e2dSJohn Marino f.end = end; 1340*cf7f2e2dSJohn Marino 1341*cf7f2e2dSJohn Marino VEC_safe_push (tdesc_type_field, type->u.u.fields, &f); 1342*cf7f2e2dSJohn Marino } 1343*cf7f2e2dSJohn Marino 1344*cf7f2e2dSJohn Marino void 1345*cf7f2e2dSJohn Marino tdesc_add_flag (struct tdesc_type *type, int start, 1346*cf7f2e2dSJohn Marino const char *flag_name) 1347*cf7f2e2dSJohn Marino { 1348*cf7f2e2dSJohn Marino struct tdesc_type_flag f = { 0 }; 1349*cf7f2e2dSJohn Marino 1350*cf7f2e2dSJohn Marino gdb_assert (type->kind == TDESC_TYPE_FLAGS); 1351*cf7f2e2dSJohn Marino 1352*cf7f2e2dSJohn Marino f.name = xstrdup (flag_name); 1353*cf7f2e2dSJohn Marino f.start = start; 1354*cf7f2e2dSJohn Marino 1355*cf7f2e2dSJohn Marino VEC_safe_push (tdesc_type_flag, type->u.f.flags, &f); 1356*cf7f2e2dSJohn Marino } 1357*cf7f2e2dSJohn Marino 13585796c8dcSSimon Schubert static void 13595796c8dcSSimon Schubert tdesc_free_feature (struct tdesc_feature *feature) 13605796c8dcSSimon Schubert { 13615796c8dcSSimon Schubert struct tdesc_reg *reg; 13625796c8dcSSimon Schubert struct tdesc_type *type; 13635796c8dcSSimon Schubert int ix; 13645796c8dcSSimon Schubert 13655796c8dcSSimon Schubert for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++) 13665796c8dcSSimon Schubert tdesc_free_reg (reg); 13675796c8dcSSimon Schubert VEC_free (tdesc_reg_p, feature->registers); 13685796c8dcSSimon Schubert 13695796c8dcSSimon Schubert for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++) 13705796c8dcSSimon Schubert tdesc_free_type (type); 13715796c8dcSSimon Schubert VEC_free (tdesc_type_p, feature->types); 13725796c8dcSSimon Schubert 13735796c8dcSSimon Schubert xfree (feature->name); 13745796c8dcSSimon Schubert xfree (feature); 13755796c8dcSSimon Schubert } 13765796c8dcSSimon Schubert 13775796c8dcSSimon Schubert struct tdesc_feature * 13785796c8dcSSimon Schubert tdesc_create_feature (struct target_desc *tdesc, const char *name) 13795796c8dcSSimon Schubert { 13805796c8dcSSimon Schubert struct tdesc_feature *new_feature = XZALLOC (struct tdesc_feature); 13815796c8dcSSimon Schubert 13825796c8dcSSimon Schubert new_feature->name = xstrdup (name); 13835796c8dcSSimon Schubert 13845796c8dcSSimon Schubert VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature); 13855796c8dcSSimon Schubert return new_feature; 13865796c8dcSSimon Schubert } 13875796c8dcSSimon Schubert 13885796c8dcSSimon Schubert struct target_desc * 13895796c8dcSSimon Schubert allocate_target_description (void) 13905796c8dcSSimon Schubert { 13915796c8dcSSimon Schubert return XZALLOC (struct target_desc); 13925796c8dcSSimon Schubert } 13935796c8dcSSimon Schubert 13945796c8dcSSimon Schubert static void 13955796c8dcSSimon Schubert free_target_description (void *arg) 13965796c8dcSSimon Schubert { 13975796c8dcSSimon Schubert struct target_desc *target_desc = arg; 13985796c8dcSSimon Schubert struct tdesc_feature *feature; 13995796c8dcSSimon Schubert struct property *prop; 14005796c8dcSSimon Schubert int ix; 14015796c8dcSSimon Schubert 14025796c8dcSSimon Schubert for (ix = 0; 14035796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature); 14045796c8dcSSimon Schubert ix++) 14055796c8dcSSimon Schubert tdesc_free_feature (feature); 14065796c8dcSSimon Schubert VEC_free (tdesc_feature_p, target_desc->features); 14075796c8dcSSimon Schubert 14085796c8dcSSimon Schubert for (ix = 0; 14095796c8dcSSimon Schubert VEC_iterate (property_s, target_desc->properties, ix, prop); 14105796c8dcSSimon Schubert ix++) 14115796c8dcSSimon Schubert { 14125796c8dcSSimon Schubert xfree (prop->key); 14135796c8dcSSimon Schubert xfree (prop->value); 14145796c8dcSSimon Schubert } 14155796c8dcSSimon Schubert VEC_free (property_s, target_desc->properties); 14165796c8dcSSimon Schubert 14175796c8dcSSimon Schubert VEC_free (arch_p, target_desc->compatible); 14185796c8dcSSimon Schubert 14195796c8dcSSimon Schubert xfree (target_desc); 14205796c8dcSSimon Schubert } 14215796c8dcSSimon Schubert 14225796c8dcSSimon Schubert struct cleanup * 14235796c8dcSSimon Schubert make_cleanup_free_target_description (struct target_desc *target_desc) 14245796c8dcSSimon Schubert { 14255796c8dcSSimon Schubert return make_cleanup (free_target_description, target_desc); 14265796c8dcSSimon Schubert } 14275796c8dcSSimon Schubert 14285796c8dcSSimon Schubert void 14295796c8dcSSimon Schubert tdesc_add_compatible (struct target_desc *target_desc, 14305796c8dcSSimon Schubert const struct bfd_arch_info *compatible) 14315796c8dcSSimon Schubert { 14325796c8dcSSimon Schubert const struct bfd_arch_info *compat; 14335796c8dcSSimon Schubert int ix; 14345796c8dcSSimon Schubert 14355796c8dcSSimon Schubert /* If this instance of GDB is compiled without BFD support for the 14365796c8dcSSimon Schubert compatible architecture, simply ignore it -- we would not be able 14375796c8dcSSimon Schubert to handle it anyway. */ 14385796c8dcSSimon Schubert if (compatible == NULL) 14395796c8dcSSimon Schubert return; 14405796c8dcSSimon Schubert 14415796c8dcSSimon Schubert for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat); 14425796c8dcSSimon Schubert ix++) 14435796c8dcSSimon Schubert if (compat == compatible) 14445796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 14455796c8dcSSimon Schubert _("Attempted to add duplicate " 14465796c8dcSSimon Schubert "compatible architecture \"%s\""), 14475796c8dcSSimon Schubert compatible->printable_name); 14485796c8dcSSimon Schubert 14495796c8dcSSimon Schubert VEC_safe_push (arch_p, target_desc->compatible, compatible); 14505796c8dcSSimon Schubert } 14515796c8dcSSimon Schubert 14525796c8dcSSimon Schubert void 14535796c8dcSSimon Schubert set_tdesc_property (struct target_desc *target_desc, 14545796c8dcSSimon Schubert const char *key, const char *value) 14555796c8dcSSimon Schubert { 14565796c8dcSSimon Schubert struct property *prop, new_prop; 14575796c8dcSSimon Schubert int ix; 14585796c8dcSSimon Schubert 14595796c8dcSSimon Schubert gdb_assert (key != NULL && value != NULL); 14605796c8dcSSimon Schubert 14615796c8dcSSimon Schubert for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop); 14625796c8dcSSimon Schubert ix++) 14635796c8dcSSimon Schubert if (strcmp (prop->key, key) == 0) 14645796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 14655796c8dcSSimon Schubert _("Attempted to add duplicate property \"%s\""), key); 14665796c8dcSSimon Schubert 14675796c8dcSSimon Schubert new_prop.key = xstrdup (key); 14685796c8dcSSimon Schubert new_prop.value = xstrdup (value); 14695796c8dcSSimon Schubert VEC_safe_push (property_s, target_desc->properties, &new_prop); 14705796c8dcSSimon Schubert } 14715796c8dcSSimon Schubert 14725796c8dcSSimon Schubert void 14735796c8dcSSimon Schubert set_tdesc_architecture (struct target_desc *target_desc, 14745796c8dcSSimon Schubert const struct bfd_arch_info *arch) 14755796c8dcSSimon Schubert { 14765796c8dcSSimon Schubert target_desc->arch = arch; 14775796c8dcSSimon Schubert } 14785796c8dcSSimon Schubert 14795796c8dcSSimon Schubert void 14805796c8dcSSimon Schubert set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi) 14815796c8dcSSimon Schubert { 14825796c8dcSSimon Schubert target_desc->osabi = osabi; 14835796c8dcSSimon Schubert } 14845796c8dcSSimon Schubert 14855796c8dcSSimon Schubert 14865796c8dcSSimon Schubert static struct cmd_list_element *tdesc_set_cmdlist, *tdesc_show_cmdlist; 14875796c8dcSSimon Schubert static struct cmd_list_element *tdesc_unset_cmdlist; 14885796c8dcSSimon Schubert 14895796c8dcSSimon Schubert /* Helper functions for the CLI commands. */ 14905796c8dcSSimon Schubert 14915796c8dcSSimon Schubert static void 14925796c8dcSSimon Schubert set_tdesc_cmd (char *args, int from_tty) 14935796c8dcSSimon Schubert { 14945796c8dcSSimon Schubert help_list (tdesc_set_cmdlist, "set tdesc ", -1, gdb_stdout); 14955796c8dcSSimon Schubert } 14965796c8dcSSimon Schubert 14975796c8dcSSimon Schubert static void 14985796c8dcSSimon Schubert show_tdesc_cmd (char *args, int from_tty) 14995796c8dcSSimon Schubert { 15005796c8dcSSimon Schubert cmd_show_list (tdesc_show_cmdlist, from_tty, ""); 15015796c8dcSSimon Schubert } 15025796c8dcSSimon Schubert 15035796c8dcSSimon Schubert static void 15045796c8dcSSimon Schubert unset_tdesc_cmd (char *args, int from_tty) 15055796c8dcSSimon Schubert { 15065796c8dcSSimon Schubert help_list (tdesc_unset_cmdlist, "unset tdesc ", -1, gdb_stdout); 15075796c8dcSSimon Schubert } 15085796c8dcSSimon Schubert 15095796c8dcSSimon Schubert static void 15105796c8dcSSimon Schubert set_tdesc_filename_cmd (char *args, int from_tty, 15115796c8dcSSimon Schubert struct cmd_list_element *c) 15125796c8dcSSimon Schubert { 15135796c8dcSSimon Schubert target_clear_description (); 15145796c8dcSSimon Schubert target_find_description (); 15155796c8dcSSimon Schubert } 15165796c8dcSSimon Schubert 15175796c8dcSSimon Schubert static void 15185796c8dcSSimon Schubert show_tdesc_filename_cmd (struct ui_file *file, int from_tty, 15195796c8dcSSimon Schubert struct cmd_list_element *c, 15205796c8dcSSimon Schubert const char *value) 15215796c8dcSSimon Schubert { 15225796c8dcSSimon Schubert if (value != NULL && *value != '\0') 15235796c8dcSSimon Schubert printf_filtered (_("\ 15245796c8dcSSimon Schubert The target description will be read from \"%s\".\n"), 15255796c8dcSSimon Schubert value); 15265796c8dcSSimon Schubert else 15275796c8dcSSimon Schubert printf_filtered (_("\ 15285796c8dcSSimon Schubert The target description will be read from the target.\n")); 15295796c8dcSSimon Schubert } 15305796c8dcSSimon Schubert 15315796c8dcSSimon Schubert static void 15325796c8dcSSimon Schubert unset_tdesc_filename_cmd (char *args, int from_tty) 15335796c8dcSSimon Schubert { 15345796c8dcSSimon Schubert xfree (target_description_filename); 15355796c8dcSSimon Schubert target_description_filename = NULL; 15365796c8dcSSimon Schubert target_clear_description (); 15375796c8dcSSimon Schubert target_find_description (); 15385796c8dcSSimon Schubert } 15395796c8dcSSimon Schubert 15405796c8dcSSimon Schubert static void 15415796c8dcSSimon Schubert maint_print_c_tdesc_cmd (char *args, int from_tty) 15425796c8dcSSimon Schubert { 15435796c8dcSSimon Schubert const struct target_desc *tdesc; 15445796c8dcSSimon Schubert const struct bfd_arch_info *compatible; 15455796c8dcSSimon Schubert const char *filename, *inp; 15465796c8dcSSimon Schubert char *function, *outp; 15475796c8dcSSimon Schubert struct property *prop; 15485796c8dcSSimon Schubert struct tdesc_feature *feature; 15495796c8dcSSimon Schubert struct tdesc_reg *reg; 15505796c8dcSSimon Schubert struct tdesc_type *type; 15515796c8dcSSimon Schubert struct tdesc_type_field *f; 1552*cf7f2e2dSJohn Marino struct tdesc_type_flag *flag; 15535796c8dcSSimon Schubert int ix, ix2, ix3; 15545796c8dcSSimon Schubert 15555796c8dcSSimon Schubert /* Use the global target-supplied description, not the current 15565796c8dcSSimon Schubert architecture's. This lets a GDB for one architecture generate C 15575796c8dcSSimon Schubert for another architecture's description, even though the gdbarch 15585796c8dcSSimon Schubert initialization code will reject the new description. */ 15595796c8dcSSimon Schubert tdesc = current_target_desc; 15605796c8dcSSimon Schubert if (tdesc == NULL) 15615796c8dcSSimon Schubert error (_("There is no target description to print.")); 15625796c8dcSSimon Schubert 15635796c8dcSSimon Schubert if (target_description_filename == NULL) 15645796c8dcSSimon Schubert error (_("The current target description did not come from an XML file.")); 15655796c8dcSSimon Schubert 15665796c8dcSSimon Schubert filename = lbasename (target_description_filename); 15675796c8dcSSimon Schubert function = alloca (strlen (filename) + 1); 15685796c8dcSSimon Schubert for (inp = filename, outp = function; *inp != '\0'; inp++) 15695796c8dcSSimon Schubert if (*inp == '.') 15705796c8dcSSimon Schubert break; 15715796c8dcSSimon Schubert else if (*inp == '-') 15725796c8dcSSimon Schubert *outp++ = '_'; 15735796c8dcSSimon Schubert else 15745796c8dcSSimon Schubert *outp++ = *inp; 15755796c8dcSSimon Schubert *outp = '\0'; 15765796c8dcSSimon Schubert 15775796c8dcSSimon Schubert /* Standard boilerplate. */ 15785796c8dcSSimon Schubert printf_unfiltered ("/* THIS FILE IS GENERATED. Original: %s */\n\n", 15795796c8dcSSimon Schubert filename); 15805796c8dcSSimon Schubert printf_unfiltered ("#include \"defs.h\"\n"); 1581*cf7f2e2dSJohn Marino printf_unfiltered ("#include \"osabi.h\"\n"); 15825796c8dcSSimon Schubert printf_unfiltered ("#include \"target-descriptions.h\"\n"); 15835796c8dcSSimon Schubert printf_unfiltered ("\n"); 15845796c8dcSSimon Schubert 15855796c8dcSSimon Schubert printf_unfiltered ("struct target_desc *tdesc_%s;\n", function); 15865796c8dcSSimon Schubert printf_unfiltered ("static void\n"); 15875796c8dcSSimon Schubert printf_unfiltered ("initialize_tdesc_%s (void)\n", function); 15885796c8dcSSimon Schubert printf_unfiltered ("{\n"); 15895796c8dcSSimon Schubert printf_unfiltered 15905796c8dcSSimon Schubert (" struct target_desc *result = allocate_target_description ();\n"); 15915796c8dcSSimon Schubert printf_unfiltered (" struct tdesc_feature *feature;\n"); 15925796c8dcSSimon Schubert printf_unfiltered (" struct tdesc_type *field_type, *type;\n"); 15935796c8dcSSimon Schubert printf_unfiltered ("\n"); 15945796c8dcSSimon Schubert 15955796c8dcSSimon Schubert if (tdesc_architecture (tdesc) != NULL) 15965796c8dcSSimon Schubert { 15975796c8dcSSimon Schubert printf_unfiltered 15985796c8dcSSimon Schubert (" set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n", 15995796c8dcSSimon Schubert tdesc_architecture (tdesc)->printable_name); 16005796c8dcSSimon Schubert printf_unfiltered ("\n"); 16015796c8dcSSimon Schubert } 16025796c8dcSSimon Schubert 1603*cf7f2e2dSJohn Marino if (tdesc_osabi (tdesc) > GDB_OSABI_UNKNOWN 1604*cf7f2e2dSJohn Marino && tdesc_osabi (tdesc) < GDB_OSABI_INVALID) 1605*cf7f2e2dSJohn Marino { 1606*cf7f2e2dSJohn Marino printf_unfiltered 1607*cf7f2e2dSJohn Marino (" set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n", 1608*cf7f2e2dSJohn Marino gdbarch_osabi_name (tdesc_osabi (tdesc))); 1609*cf7f2e2dSJohn Marino printf_unfiltered ("\n"); 1610*cf7f2e2dSJohn Marino } 1611*cf7f2e2dSJohn Marino 16125796c8dcSSimon Schubert for (ix = 0; VEC_iterate (arch_p, tdesc->compatible, ix, compatible); 16135796c8dcSSimon Schubert ix++) 16145796c8dcSSimon Schubert { 16155796c8dcSSimon Schubert printf_unfiltered 16165796c8dcSSimon Schubert (" tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n", 16175796c8dcSSimon Schubert compatible->printable_name); 16185796c8dcSSimon Schubert } 16195796c8dcSSimon Schubert if (ix) 16205796c8dcSSimon Schubert printf_unfiltered ("\n"); 16215796c8dcSSimon Schubert 16225796c8dcSSimon Schubert for (ix = 0; VEC_iterate (property_s, tdesc->properties, ix, prop); 16235796c8dcSSimon Schubert ix++) 16245796c8dcSSimon Schubert { 16255796c8dcSSimon Schubert printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n", 16265796c8dcSSimon Schubert prop->key, prop->value); 16275796c8dcSSimon Schubert } 16285796c8dcSSimon Schubert 16295796c8dcSSimon Schubert for (ix = 0; 16305796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature); 16315796c8dcSSimon Schubert ix++) 16325796c8dcSSimon Schubert { 16335796c8dcSSimon Schubert printf_unfiltered (" feature = tdesc_create_feature (result, \"%s\");\n", 16345796c8dcSSimon Schubert feature->name); 16355796c8dcSSimon Schubert 16365796c8dcSSimon Schubert for (ix2 = 0; 16375796c8dcSSimon Schubert VEC_iterate (tdesc_type_p, feature->types, ix2, type); 16385796c8dcSSimon Schubert ix2++) 16395796c8dcSSimon Schubert { 16405796c8dcSSimon Schubert switch (type->kind) 16415796c8dcSSimon Schubert { 16425796c8dcSSimon Schubert case TDESC_TYPE_VECTOR: 16435796c8dcSSimon Schubert printf_unfiltered 16445796c8dcSSimon Schubert (" field_type = tdesc_named_type (feature, \"%s\");\n", 16455796c8dcSSimon Schubert type->u.v.type->name); 16465796c8dcSSimon Schubert printf_unfiltered 16475796c8dcSSimon Schubert (" tdesc_create_vector (feature, \"%s\", field_type, %d);\n", 16485796c8dcSSimon Schubert type->name, type->u.v.count); 16495796c8dcSSimon Schubert break; 16505796c8dcSSimon Schubert case TDESC_TYPE_UNION: 16515796c8dcSSimon Schubert printf_unfiltered 16525796c8dcSSimon Schubert (" type = tdesc_create_union (feature, \"%s\");\n", 16535796c8dcSSimon Schubert type->name); 16545796c8dcSSimon Schubert for (ix3 = 0; 16555796c8dcSSimon Schubert VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f); 16565796c8dcSSimon Schubert ix3++) 16575796c8dcSSimon Schubert { 16585796c8dcSSimon Schubert printf_unfiltered 16595796c8dcSSimon Schubert (" field_type = tdesc_named_type (feature, \"%s\");\n", 16605796c8dcSSimon Schubert f->type->name); 16615796c8dcSSimon Schubert printf_unfiltered 16625796c8dcSSimon Schubert (" tdesc_add_field (type, \"%s\", field_type);\n", 16635796c8dcSSimon Schubert f->name); 16645796c8dcSSimon Schubert } 16655796c8dcSSimon Schubert break; 1666*cf7f2e2dSJohn Marino case TDESC_TYPE_FLAGS: 1667*cf7f2e2dSJohn Marino printf_unfiltered 1668*cf7f2e2dSJohn Marino (" field_type = tdesc_create_flags (feature, \"%s\", %d);\n", 1669*cf7f2e2dSJohn Marino type->name, (int) type->u.f.size); 1670*cf7f2e2dSJohn Marino for (ix3 = 0; 1671*cf7f2e2dSJohn Marino VEC_iterate (tdesc_type_flag, type->u.f.flags, ix3, 1672*cf7f2e2dSJohn Marino flag); 1673*cf7f2e2dSJohn Marino ix3++) 1674*cf7f2e2dSJohn Marino printf_unfiltered 1675*cf7f2e2dSJohn Marino (" tdesc_add_flag (field_type, %d, \"%s\");\n", 1676*cf7f2e2dSJohn Marino flag->start, flag->name); 1677*cf7f2e2dSJohn Marino break; 16785796c8dcSSimon Schubert default: 16795796c8dcSSimon Schubert error (_("C output is not supported type \"%s\"."), type->name); 16805796c8dcSSimon Schubert } 16815796c8dcSSimon Schubert printf_unfiltered ("\n"); 16825796c8dcSSimon Schubert } 16835796c8dcSSimon Schubert 16845796c8dcSSimon Schubert for (ix2 = 0; 16855796c8dcSSimon Schubert VEC_iterate (tdesc_reg_p, feature->registers, ix2, reg); 16865796c8dcSSimon Schubert ix2++) 16875796c8dcSSimon Schubert { 16885796c8dcSSimon Schubert printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ", 16895796c8dcSSimon Schubert reg->name, reg->target_regnum, reg->save_restore); 16905796c8dcSSimon Schubert if (reg->group) 16915796c8dcSSimon Schubert printf_unfiltered ("\"%s\", ", reg->group); 16925796c8dcSSimon Schubert else 16935796c8dcSSimon Schubert printf_unfiltered ("NULL, "); 16945796c8dcSSimon Schubert printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type); 16955796c8dcSSimon Schubert } 16965796c8dcSSimon Schubert 16975796c8dcSSimon Schubert printf_unfiltered ("\n"); 16985796c8dcSSimon Schubert } 16995796c8dcSSimon Schubert 17005796c8dcSSimon Schubert printf_unfiltered (" tdesc_%s = result;\n", function); 17015796c8dcSSimon Schubert printf_unfiltered ("}\n"); 17025796c8dcSSimon Schubert } 17035796c8dcSSimon Schubert 17045796c8dcSSimon Schubert /* Provide a prototype to silence -Wmissing-prototypes. */ 17055796c8dcSSimon Schubert extern initialize_file_ftype _initialize_target_descriptions; 17065796c8dcSSimon Schubert 17075796c8dcSSimon Schubert void 17085796c8dcSSimon Schubert _initialize_target_descriptions (void) 17095796c8dcSSimon Schubert { 17105796c8dcSSimon Schubert tdesc_data = gdbarch_data_register_pre_init (tdesc_data_init); 17115796c8dcSSimon Schubert 17125796c8dcSSimon Schubert add_prefix_cmd ("tdesc", class_maintenance, set_tdesc_cmd, _("\ 17135796c8dcSSimon Schubert Set target description specific variables."), 17145796c8dcSSimon Schubert &tdesc_set_cmdlist, "set tdesc ", 17155796c8dcSSimon Schubert 0 /* allow-unknown */, &setlist); 17165796c8dcSSimon Schubert add_prefix_cmd ("tdesc", class_maintenance, show_tdesc_cmd, _("\ 17175796c8dcSSimon Schubert Show target description specific variables."), 17185796c8dcSSimon Schubert &tdesc_show_cmdlist, "show tdesc ", 17195796c8dcSSimon Schubert 0 /* allow-unknown */, &showlist); 17205796c8dcSSimon Schubert add_prefix_cmd ("tdesc", class_maintenance, unset_tdesc_cmd, _("\ 17215796c8dcSSimon Schubert Unset target description specific variables."), 17225796c8dcSSimon Schubert &tdesc_unset_cmdlist, "unset tdesc ", 17235796c8dcSSimon Schubert 0 /* allow-unknown */, &unsetlist); 17245796c8dcSSimon Schubert 17255796c8dcSSimon Schubert add_setshow_filename_cmd ("filename", class_obscure, 17265796c8dcSSimon Schubert &target_description_filename, 17275796c8dcSSimon Schubert _("\ 17285796c8dcSSimon Schubert Set the file to read for an XML target description"), _("\ 17295796c8dcSSimon Schubert Show the file to read for an XML target description"), _("\ 17305796c8dcSSimon Schubert When set, GDB will read the target description from a local\n\ 17315796c8dcSSimon Schubert file instead of querying the remote target."), 17325796c8dcSSimon Schubert set_tdesc_filename_cmd, 17335796c8dcSSimon Schubert show_tdesc_filename_cmd, 17345796c8dcSSimon Schubert &tdesc_set_cmdlist, &tdesc_show_cmdlist); 17355796c8dcSSimon Schubert 17365796c8dcSSimon Schubert add_cmd ("filename", class_obscure, unset_tdesc_filename_cmd, _("\ 17375796c8dcSSimon Schubert Unset the file to read for an XML target description. When unset,\n\ 17385796c8dcSSimon Schubert GDB will read the description from the target."), 17395796c8dcSSimon Schubert &tdesc_unset_cmdlist); 17405796c8dcSSimon Schubert 17415796c8dcSSimon Schubert add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\ 17425796c8dcSSimon Schubert Print the current target description as a C source file."), 17435796c8dcSSimon Schubert &maintenanceprintlist); 17445796c8dcSSimon Schubert } 1745