15796c8dcSSimon Schubert /* Target description support for GDB. 25796c8dcSSimon Schubert 3*ef5ccd6cSJohn Marino Copyright (C) 2006-2013 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 #ifndef TARGET_DESCRIPTIONS_H 235796c8dcSSimon Schubert #define TARGET_DESCRIPTIONS_H 1 245796c8dcSSimon Schubert 255796c8dcSSimon Schubert struct tdesc_feature; 265796c8dcSSimon Schubert struct tdesc_arch_data; 275796c8dcSSimon Schubert struct tdesc_type; 285796c8dcSSimon Schubert struct tdesc_reg; 295796c8dcSSimon Schubert struct target_desc; 305796c8dcSSimon Schubert struct target_ops; 31*ef5ccd6cSJohn Marino struct target_desc; 32*ef5ccd6cSJohn Marino /* An inferior's target description info is stored in this opaque 33*ef5ccd6cSJohn Marino object. There's one such object per inferior. */ 34*ef5ccd6cSJohn Marino struct target_desc_info; 35*ef5ccd6cSJohn Marino struct inferior; 365796c8dcSSimon Schubert 37*ef5ccd6cSJohn Marino /* Fetch the current inferior's description, and switch its current 385796c8dcSSimon Schubert architecture to one which incorporates that description. */ 395796c8dcSSimon Schubert 405796c8dcSSimon Schubert void target_find_description (void); 415796c8dcSSimon Schubert 42*ef5ccd6cSJohn Marino /* Discard any description fetched from the target for the current 43*ef5ccd6cSJohn Marino inferior, and switch the current architecture to one with no target 44*ef5ccd6cSJohn Marino description. */ 455796c8dcSSimon Schubert 465796c8dcSSimon Schubert void target_clear_description (void); 475796c8dcSSimon Schubert 48*ef5ccd6cSJohn Marino /* Return the current inferior's target description. This should only 49*ef5ccd6cSJohn Marino be used by gdbarch initialization code; most access should be 50*ef5ccd6cSJohn Marino through an existing gdbarch. */ 515796c8dcSSimon Schubert 525796c8dcSSimon Schubert const struct target_desc *target_current_description (void); 535796c8dcSSimon Schubert 54*ef5ccd6cSJohn Marino /* Copy inferior target description data. Used for example when 55*ef5ccd6cSJohn Marino handling (v)forks, where child's description is the same as the 56*ef5ccd6cSJohn Marino parent's, since the child really is a copy of the parent. */ 57*ef5ccd6cSJohn Marino 58*ef5ccd6cSJohn Marino void copy_inferior_target_desc_info (struct inferior *destinf, 59*ef5ccd6cSJohn Marino struct inferior *srcinf); 60*ef5ccd6cSJohn Marino 61*ef5ccd6cSJohn Marino /* Free a target_desc_info object. */ 62*ef5ccd6cSJohn Marino 63*ef5ccd6cSJohn Marino void target_desc_info_free (struct target_desc_info *tdesc_info); 64*ef5ccd6cSJohn Marino 65*ef5ccd6cSJohn Marino /* Returns true if INFO indicates the target description had been 66*ef5ccd6cSJohn Marino supplied by the user. */ 67*ef5ccd6cSJohn Marino 68*ef5ccd6cSJohn Marino int target_desc_info_from_user_p (struct target_desc_info *info); 69*ef5ccd6cSJohn Marino 705796c8dcSSimon Schubert /* Record architecture-specific functions to call for pseudo-register 715796c8dcSSimon Schubert support. If tdesc_use_registers is called and gdbarch_num_pseudo_regs 725796c8dcSSimon Schubert is greater than zero, then these should be called as well. 735796c8dcSSimon Schubert They are equivalent to the gdbarch methods with similar names, 745796c8dcSSimon Schubert except that they will only be called for pseudo registers. */ 755796c8dcSSimon Schubert 765796c8dcSSimon Schubert void set_tdesc_pseudo_register_name 775796c8dcSSimon Schubert (struct gdbarch *gdbarch, gdbarch_register_name_ftype *pseudo_name); 785796c8dcSSimon Schubert 795796c8dcSSimon Schubert void set_tdesc_pseudo_register_type 805796c8dcSSimon Schubert (struct gdbarch *gdbarch, gdbarch_register_type_ftype *pseudo_type); 815796c8dcSSimon Schubert 825796c8dcSSimon Schubert void set_tdesc_pseudo_register_reggroup_p 835796c8dcSSimon Schubert (struct gdbarch *gdbarch, 845796c8dcSSimon Schubert gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p); 855796c8dcSSimon Schubert 865796c8dcSSimon Schubert /* Update GDBARCH to use the TARGET_DESC for registers. TARGET_DESC 875796c8dcSSimon Schubert may be GDBARCH's target description or (if GDBARCH does not have 885796c8dcSSimon Schubert one which describes registers) another target description 895796c8dcSSimon Schubert constructed by the gdbarch initialization routine. 905796c8dcSSimon Schubert 915796c8dcSSimon Schubert Fixed register assignments are taken from EARLY_DATA, which is freed. 925796c8dcSSimon Schubert All registers which have not been assigned fixed numbers are given 935796c8dcSSimon Schubert numbers above the current value of gdbarch_num_regs. 945796c8dcSSimon Schubert gdbarch_num_regs and various register-related predicates are updated to 955796c8dcSSimon Schubert refer to the target description. This function should only be called from 965796c8dcSSimon Schubert the architecture's gdbarch initialization routine, and only after 975796c8dcSSimon Schubert successfully validating the required registers. */ 985796c8dcSSimon Schubert 995796c8dcSSimon Schubert void tdesc_use_registers (struct gdbarch *gdbarch, 1005796c8dcSSimon Schubert const struct target_desc *target_desc, 1015796c8dcSSimon Schubert struct tdesc_arch_data *early_data); 1025796c8dcSSimon Schubert 1035796c8dcSSimon Schubert /* Allocate initial data for validation of a target description during 1045796c8dcSSimon Schubert gdbarch initialization. */ 1055796c8dcSSimon Schubert 1065796c8dcSSimon Schubert struct tdesc_arch_data *tdesc_data_alloc (void); 1075796c8dcSSimon Schubert 1085796c8dcSSimon Schubert /* Clean up data allocated by tdesc_data_alloc. This should only 1095796c8dcSSimon Schubert be called to discard the data; tdesc_use_registers takes ownership 1105796c8dcSSimon Schubert of its EARLY_DATA argument. */ 1115796c8dcSSimon Schubert 1125796c8dcSSimon Schubert void tdesc_data_cleanup (void *data_untyped); 1135796c8dcSSimon Schubert 1145796c8dcSSimon Schubert /* Search FEATURE for a register named NAME. Record REGNO and the 1155796c8dcSSimon Schubert register in DATA; when tdesc_use_registers is called, REGNO will be 1165796c8dcSSimon Schubert assigned to the register. 1 is returned if the register was found, 1175796c8dcSSimon Schubert 0 if it was not. */ 1185796c8dcSSimon Schubert 1195796c8dcSSimon Schubert int tdesc_numbered_register (const struct tdesc_feature *feature, 1205796c8dcSSimon Schubert struct tdesc_arch_data *data, 1215796c8dcSSimon Schubert int regno, const char *name); 1225796c8dcSSimon Schubert 1235796c8dcSSimon Schubert /* Search FEATURE for a register named NAME, but do not assign a fixed 1245796c8dcSSimon Schubert register number to it. */ 1255796c8dcSSimon Schubert 1265796c8dcSSimon Schubert int tdesc_unnumbered_register (const struct tdesc_feature *feature, 1275796c8dcSSimon Schubert const char *name); 1285796c8dcSSimon Schubert 1295796c8dcSSimon Schubert /* Search FEATURE for a register named NAME, and return its size in 1305796c8dcSSimon Schubert bits. The register must exist. */ 1315796c8dcSSimon Schubert 1325796c8dcSSimon Schubert int tdesc_register_size (const struct tdesc_feature *feature, 1335796c8dcSSimon Schubert const char *name); 1345796c8dcSSimon Schubert 1355796c8dcSSimon Schubert /* Search FEATURE for a register with any of the names from NAMES 1365796c8dcSSimon Schubert (NULL-terminated). Record REGNO and the register in DATA; when 1375796c8dcSSimon Schubert tdesc_use_registers is called, REGNO will be assigned to the 1385796c8dcSSimon Schubert register. 1 is returned if the register was found, 0 if it was 1395796c8dcSSimon Schubert not. */ 1405796c8dcSSimon Schubert 1415796c8dcSSimon Schubert int tdesc_numbered_register_choices (const struct tdesc_feature *feature, 1425796c8dcSSimon Schubert struct tdesc_arch_data *data, 1435796c8dcSSimon Schubert int regno, const char *const names[]); 1445796c8dcSSimon Schubert 1455796c8dcSSimon Schubert 1465796c8dcSSimon Schubert /* Accessors for target descriptions. */ 1475796c8dcSSimon Schubert 1485796c8dcSSimon Schubert /* Return the BFD architecture associated with this target 1495796c8dcSSimon Schubert description, or NULL if no architecture was specified. */ 1505796c8dcSSimon Schubert 1515796c8dcSSimon Schubert const struct bfd_arch_info *tdesc_architecture 1525796c8dcSSimon Schubert (const struct target_desc *); 1535796c8dcSSimon Schubert 1545796c8dcSSimon Schubert /* Return the OSABI associated with this target description, or 1555796c8dcSSimon Schubert GDB_OSABI_UNKNOWN if no osabi was specified. */ 1565796c8dcSSimon Schubert 1575796c8dcSSimon Schubert enum gdb_osabi tdesc_osabi (const struct target_desc *); 1585796c8dcSSimon Schubert 1595796c8dcSSimon Schubert /* Return non-zero if this target description is compatible 1605796c8dcSSimon Schubert with the given BFD architecture. */ 1615796c8dcSSimon Schubert 1625796c8dcSSimon Schubert int tdesc_compatible_p (const struct target_desc *, 1635796c8dcSSimon Schubert const struct bfd_arch_info *); 1645796c8dcSSimon Schubert 1655796c8dcSSimon Schubert /* Return the string value of a property named KEY, or NULL if the 1665796c8dcSSimon Schubert property was not specified. */ 1675796c8dcSSimon Schubert 1685796c8dcSSimon Schubert const char *tdesc_property (const struct target_desc *, 1695796c8dcSSimon Schubert const char *key); 1705796c8dcSSimon Schubert 1715796c8dcSSimon Schubert /* Return 1 if this target description describes any registers. */ 1725796c8dcSSimon Schubert 1735796c8dcSSimon Schubert int tdesc_has_registers (const struct target_desc *); 1745796c8dcSSimon Schubert 1755796c8dcSSimon Schubert /* Return the feature with the given name, if present, or NULL if 1765796c8dcSSimon Schubert the named feature is not found. */ 1775796c8dcSSimon Schubert 1785796c8dcSSimon Schubert const struct tdesc_feature *tdesc_find_feature (const struct target_desc *, 1795796c8dcSSimon Schubert const char *name); 1805796c8dcSSimon Schubert 1815796c8dcSSimon Schubert /* Return the name of FEATURE. */ 1825796c8dcSSimon Schubert 1835796c8dcSSimon Schubert const char *tdesc_feature_name (const struct tdesc_feature *feature); 1845796c8dcSSimon Schubert 1855796c8dcSSimon Schubert /* Return the type associated with ID in the context of FEATURE, or 1865796c8dcSSimon Schubert NULL if none. */ 1875796c8dcSSimon Schubert 1885796c8dcSSimon Schubert struct tdesc_type *tdesc_named_type (const struct tdesc_feature *feature, 1895796c8dcSSimon Schubert const char *id); 1905796c8dcSSimon Schubert 1915796c8dcSSimon Schubert /* Return the name of register REGNO, from the target description or 1925796c8dcSSimon Schubert from an architecture-provided pseudo_register_name method. */ 1935796c8dcSSimon Schubert 1945796c8dcSSimon Schubert const char *tdesc_register_name (struct gdbarch *gdbarch, int regno); 1955796c8dcSSimon Schubert 1965796c8dcSSimon Schubert /* Return the type of register REGNO, from the target description or 1975796c8dcSSimon Schubert from an architecture-provided pseudo_register_type method. */ 1985796c8dcSSimon Schubert 1995796c8dcSSimon Schubert struct type *tdesc_register_type (struct gdbarch *gdbarch, int regno); 2005796c8dcSSimon Schubert 201cf7f2e2dSJohn Marino /* Return the type associated with ID, from the target description. */ 202cf7f2e2dSJohn Marino 203cf7f2e2dSJohn Marino struct type *tdesc_find_type (struct gdbarch *gdbarch, const char *id); 204cf7f2e2dSJohn Marino 2055796c8dcSSimon Schubert /* Check whether REGNUM is a member of REGGROUP using the target 2065796c8dcSSimon Schubert description. Return -1 if the target description does not 2075796c8dcSSimon Schubert specify a group. */ 2085796c8dcSSimon Schubert 2095796c8dcSSimon Schubert int tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno, 2105796c8dcSSimon Schubert struct reggroup *reggroup); 2115796c8dcSSimon Schubert 2125796c8dcSSimon Schubert /* Methods for constructing a target description. */ 2135796c8dcSSimon Schubert 2145796c8dcSSimon Schubert struct target_desc *allocate_target_description (void); 2155796c8dcSSimon Schubert struct cleanup *make_cleanup_free_target_description (struct target_desc *); 2165796c8dcSSimon Schubert void set_tdesc_architecture (struct target_desc *, 2175796c8dcSSimon Schubert const struct bfd_arch_info *); 2185796c8dcSSimon Schubert void set_tdesc_osabi (struct target_desc *, enum gdb_osabi osabi); 2195796c8dcSSimon Schubert void set_tdesc_property (struct target_desc *, 2205796c8dcSSimon Schubert const char *key, const char *value); 2215796c8dcSSimon Schubert void tdesc_add_compatible (struct target_desc *, 2225796c8dcSSimon Schubert const struct bfd_arch_info *); 2235796c8dcSSimon Schubert 2245796c8dcSSimon Schubert struct tdesc_feature *tdesc_create_feature (struct target_desc *tdesc, 2255796c8dcSSimon Schubert const char *name); 2265796c8dcSSimon Schubert struct tdesc_type *tdesc_create_vector (struct tdesc_feature *feature, 2275796c8dcSSimon Schubert const char *name, 2285796c8dcSSimon Schubert struct tdesc_type *field_type, 2295796c8dcSSimon Schubert int count); 230cf7f2e2dSJohn Marino struct tdesc_type *tdesc_create_struct (struct tdesc_feature *feature, 231cf7f2e2dSJohn Marino const char *name); 232cf7f2e2dSJohn Marino void tdesc_set_struct_size (struct tdesc_type *type, LONGEST size); 2335796c8dcSSimon Schubert struct tdesc_type *tdesc_create_union (struct tdesc_feature *feature, 2345796c8dcSSimon Schubert const char *name); 235cf7f2e2dSJohn Marino struct tdesc_type *tdesc_create_flags (struct tdesc_feature *feature, 236cf7f2e2dSJohn Marino const char *name, 237cf7f2e2dSJohn Marino LONGEST size); 2385796c8dcSSimon Schubert void tdesc_add_field (struct tdesc_type *type, const char *field_name, 2395796c8dcSSimon Schubert struct tdesc_type *field_type); 240cf7f2e2dSJohn Marino void tdesc_add_bitfield (struct tdesc_type *type, const char *field_name, 241cf7f2e2dSJohn Marino int start, int end); 242cf7f2e2dSJohn Marino void tdesc_add_flag (struct tdesc_type *type, int start, 243cf7f2e2dSJohn Marino const char *flag_name); 2445796c8dcSSimon Schubert void tdesc_create_reg (struct tdesc_feature *feature, const char *name, 2455796c8dcSSimon Schubert int regnum, int save_restore, const char *group, 2465796c8dcSSimon Schubert int bitsize, const char *type); 2475796c8dcSSimon Schubert 2485796c8dcSSimon Schubert #endif /* TARGET_DESCRIPTIONS_H */ 249