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