15796c8dcSSimon Schubert /* Target description support for GDB. 25796c8dcSSimon Schubert 3*cf7f2e2dSJohn Marino Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 45796c8dcSSimon Schubert 55796c8dcSSimon Schubert Contributed by CodeSourcery. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This file is part of GDB. 85796c8dcSSimon Schubert 95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 125796c8dcSSimon Schubert (at your option) any later version. 135796c8dcSSimon Schubert 145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 175796c8dcSSimon Schubert GNU General Public License for more details. 185796c8dcSSimon Schubert 195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 205796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert #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; 315796c8dcSSimon Schubert 325796c8dcSSimon Schubert /* Fetch the current target's description, and switch the current 335796c8dcSSimon Schubert architecture to one which incorporates that description. */ 345796c8dcSSimon Schubert 355796c8dcSSimon Schubert void target_find_description (void); 365796c8dcSSimon Schubert 375796c8dcSSimon Schubert /* Discard any description fetched from the current target, and switch 385796c8dcSSimon Schubert the current architecture to one with no target description. */ 395796c8dcSSimon Schubert 405796c8dcSSimon Schubert void target_clear_description (void); 415796c8dcSSimon Schubert 425796c8dcSSimon Schubert /* Return the global current target description. This should only be 435796c8dcSSimon Schubert used by gdbarch initialization code; most access should be through 445796c8dcSSimon Schubert an existing gdbarch. */ 455796c8dcSSimon Schubert 465796c8dcSSimon Schubert const struct target_desc *target_current_description (void); 475796c8dcSSimon Schubert 485796c8dcSSimon Schubert /* Record architecture-specific functions to call for pseudo-register 495796c8dcSSimon Schubert support. If tdesc_use_registers is called and gdbarch_num_pseudo_regs 505796c8dcSSimon Schubert is greater than zero, then these should be called as well. 515796c8dcSSimon Schubert They are equivalent to the gdbarch methods with similar names, 525796c8dcSSimon Schubert except that they will only be called for pseudo registers. */ 535796c8dcSSimon Schubert 545796c8dcSSimon Schubert void set_tdesc_pseudo_register_name 555796c8dcSSimon Schubert (struct gdbarch *gdbarch, gdbarch_register_name_ftype *pseudo_name); 565796c8dcSSimon Schubert 575796c8dcSSimon Schubert void set_tdesc_pseudo_register_type 585796c8dcSSimon Schubert (struct gdbarch *gdbarch, gdbarch_register_type_ftype *pseudo_type); 595796c8dcSSimon Schubert 605796c8dcSSimon Schubert void set_tdesc_pseudo_register_reggroup_p 615796c8dcSSimon Schubert (struct gdbarch *gdbarch, 625796c8dcSSimon Schubert gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p); 635796c8dcSSimon Schubert 645796c8dcSSimon Schubert /* Update GDBARCH to use the TARGET_DESC for registers. TARGET_DESC 655796c8dcSSimon Schubert may be GDBARCH's target description or (if GDBARCH does not have 665796c8dcSSimon Schubert one which describes registers) another target description 675796c8dcSSimon Schubert constructed by the gdbarch initialization routine. 685796c8dcSSimon Schubert 695796c8dcSSimon Schubert Fixed register assignments are taken from EARLY_DATA, which is freed. 705796c8dcSSimon Schubert All registers which have not been assigned fixed numbers are given 715796c8dcSSimon Schubert numbers above the current value of gdbarch_num_regs. 725796c8dcSSimon Schubert gdbarch_num_regs and various register-related predicates are updated to 735796c8dcSSimon Schubert refer to the target description. This function should only be called from 745796c8dcSSimon Schubert the architecture's gdbarch initialization routine, and only after 755796c8dcSSimon Schubert successfully validating the required registers. */ 765796c8dcSSimon Schubert 775796c8dcSSimon Schubert void tdesc_use_registers (struct gdbarch *gdbarch, 785796c8dcSSimon Schubert const struct target_desc *target_desc, 795796c8dcSSimon Schubert struct tdesc_arch_data *early_data); 805796c8dcSSimon Schubert 815796c8dcSSimon Schubert /* Allocate initial data for validation of a target description during 825796c8dcSSimon Schubert gdbarch initialization. */ 835796c8dcSSimon Schubert 845796c8dcSSimon Schubert struct tdesc_arch_data *tdesc_data_alloc (void); 855796c8dcSSimon Schubert 865796c8dcSSimon Schubert /* Clean up data allocated by tdesc_data_alloc. This should only 875796c8dcSSimon Schubert be called to discard the data; tdesc_use_registers takes ownership 885796c8dcSSimon Schubert of its EARLY_DATA argument. */ 895796c8dcSSimon Schubert 905796c8dcSSimon Schubert void tdesc_data_cleanup (void *data_untyped); 915796c8dcSSimon Schubert 925796c8dcSSimon Schubert /* Search FEATURE for a register named NAME. Record REGNO and the 935796c8dcSSimon Schubert register in DATA; when tdesc_use_registers is called, REGNO will be 945796c8dcSSimon Schubert assigned to the register. 1 is returned if the register was found, 955796c8dcSSimon Schubert 0 if it was not. */ 965796c8dcSSimon Schubert 975796c8dcSSimon Schubert int tdesc_numbered_register (const struct tdesc_feature *feature, 985796c8dcSSimon Schubert struct tdesc_arch_data *data, 995796c8dcSSimon Schubert int regno, const char *name); 1005796c8dcSSimon Schubert 1015796c8dcSSimon Schubert /* Search FEATURE for a register named NAME, but do not assign a fixed 1025796c8dcSSimon Schubert register number to it. */ 1035796c8dcSSimon Schubert 1045796c8dcSSimon Schubert int tdesc_unnumbered_register (const struct tdesc_feature *feature, 1055796c8dcSSimon Schubert const char *name); 1065796c8dcSSimon Schubert 1075796c8dcSSimon Schubert /* Search FEATURE for a register named NAME, and return its size in 1085796c8dcSSimon Schubert bits. The register must exist. */ 1095796c8dcSSimon Schubert 1105796c8dcSSimon Schubert int tdesc_register_size (const struct tdesc_feature *feature, 1115796c8dcSSimon Schubert const char *name); 1125796c8dcSSimon Schubert 1135796c8dcSSimon Schubert /* Search FEATURE for a register with any of the names from NAMES 1145796c8dcSSimon Schubert (NULL-terminated). Record REGNO and the register in DATA; when 1155796c8dcSSimon Schubert tdesc_use_registers is called, REGNO will be assigned to the 1165796c8dcSSimon Schubert register. 1 is returned if the register was found, 0 if it was 1175796c8dcSSimon Schubert not. */ 1185796c8dcSSimon Schubert 1195796c8dcSSimon Schubert int tdesc_numbered_register_choices (const struct tdesc_feature *feature, 1205796c8dcSSimon Schubert struct tdesc_arch_data *data, 1215796c8dcSSimon Schubert int regno, const char *const names[]); 1225796c8dcSSimon Schubert 1235796c8dcSSimon Schubert 1245796c8dcSSimon Schubert /* Accessors for target descriptions. */ 1255796c8dcSSimon Schubert 1265796c8dcSSimon Schubert /* Return the BFD architecture associated with this target 1275796c8dcSSimon Schubert description, or NULL if no architecture was specified. */ 1285796c8dcSSimon Schubert 1295796c8dcSSimon Schubert const struct bfd_arch_info *tdesc_architecture 1305796c8dcSSimon Schubert (const struct target_desc *); 1315796c8dcSSimon Schubert 1325796c8dcSSimon Schubert /* Return the OSABI associated with this target description, or 1335796c8dcSSimon Schubert GDB_OSABI_UNKNOWN if no osabi was specified. */ 1345796c8dcSSimon Schubert 1355796c8dcSSimon Schubert enum gdb_osabi tdesc_osabi (const struct target_desc *); 1365796c8dcSSimon Schubert 1375796c8dcSSimon Schubert /* Return non-zero if this target description is compatible 1385796c8dcSSimon Schubert with the given BFD architecture. */ 1395796c8dcSSimon Schubert 1405796c8dcSSimon Schubert int tdesc_compatible_p (const struct target_desc *, 1415796c8dcSSimon Schubert const struct bfd_arch_info *); 1425796c8dcSSimon Schubert 1435796c8dcSSimon Schubert /* Return the string value of a property named KEY, or NULL if the 1445796c8dcSSimon Schubert property was not specified. */ 1455796c8dcSSimon Schubert 1465796c8dcSSimon Schubert const char *tdesc_property (const struct target_desc *, 1475796c8dcSSimon Schubert const char *key); 1485796c8dcSSimon Schubert 1495796c8dcSSimon Schubert /* Return 1 if this target description describes any registers. */ 1505796c8dcSSimon Schubert 1515796c8dcSSimon Schubert int tdesc_has_registers (const struct target_desc *); 1525796c8dcSSimon Schubert 1535796c8dcSSimon Schubert /* Return the feature with the given name, if present, or NULL if 1545796c8dcSSimon Schubert the named feature is not found. */ 1555796c8dcSSimon Schubert 1565796c8dcSSimon Schubert const struct tdesc_feature *tdesc_find_feature (const struct target_desc *, 1575796c8dcSSimon Schubert const char *name); 1585796c8dcSSimon Schubert 1595796c8dcSSimon Schubert /* Return the name of FEATURE. */ 1605796c8dcSSimon Schubert 1615796c8dcSSimon Schubert const char *tdesc_feature_name (const struct tdesc_feature *feature); 1625796c8dcSSimon Schubert 1635796c8dcSSimon Schubert /* Return the type associated with ID in the context of FEATURE, or 1645796c8dcSSimon Schubert NULL if none. */ 1655796c8dcSSimon Schubert 1665796c8dcSSimon Schubert struct tdesc_type *tdesc_named_type (const struct tdesc_feature *feature, 1675796c8dcSSimon Schubert const char *id); 1685796c8dcSSimon Schubert 1695796c8dcSSimon Schubert /* Return the name of register REGNO, from the target description or 1705796c8dcSSimon Schubert from an architecture-provided pseudo_register_name method. */ 1715796c8dcSSimon Schubert 1725796c8dcSSimon Schubert const char *tdesc_register_name (struct gdbarch *gdbarch, int regno); 1735796c8dcSSimon Schubert 1745796c8dcSSimon Schubert /* Return the type of register REGNO, from the target description or 1755796c8dcSSimon Schubert from an architecture-provided pseudo_register_type method. */ 1765796c8dcSSimon Schubert 1775796c8dcSSimon Schubert struct type *tdesc_register_type (struct gdbarch *gdbarch, int regno); 1785796c8dcSSimon Schubert 179*cf7f2e2dSJohn Marino /* Return the type associated with ID, from the target description. */ 180*cf7f2e2dSJohn Marino 181*cf7f2e2dSJohn Marino struct type *tdesc_find_type (struct gdbarch *gdbarch, const char *id); 182*cf7f2e2dSJohn Marino 1835796c8dcSSimon Schubert /* Check whether REGNUM is a member of REGGROUP using the target 1845796c8dcSSimon Schubert description. Return -1 if the target description does not 1855796c8dcSSimon Schubert specify a group. */ 1865796c8dcSSimon Schubert 1875796c8dcSSimon Schubert int tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno, 1885796c8dcSSimon Schubert struct reggroup *reggroup); 1895796c8dcSSimon Schubert 1905796c8dcSSimon Schubert /* Methods for constructing a target description. */ 1915796c8dcSSimon Schubert 1925796c8dcSSimon Schubert struct target_desc *allocate_target_description (void); 1935796c8dcSSimon Schubert struct cleanup *make_cleanup_free_target_description (struct target_desc *); 1945796c8dcSSimon Schubert void set_tdesc_architecture (struct target_desc *, 1955796c8dcSSimon Schubert const struct bfd_arch_info *); 1965796c8dcSSimon Schubert void set_tdesc_osabi (struct target_desc *, enum gdb_osabi osabi); 1975796c8dcSSimon Schubert void set_tdesc_property (struct target_desc *, 1985796c8dcSSimon Schubert const char *key, const char *value); 1995796c8dcSSimon Schubert void tdesc_add_compatible (struct target_desc *, 2005796c8dcSSimon Schubert const struct bfd_arch_info *); 2015796c8dcSSimon Schubert 2025796c8dcSSimon Schubert struct tdesc_feature *tdesc_create_feature (struct target_desc *tdesc, 2035796c8dcSSimon Schubert const char *name); 2045796c8dcSSimon Schubert struct tdesc_type *tdesc_create_vector (struct tdesc_feature *feature, 2055796c8dcSSimon Schubert const char *name, 2065796c8dcSSimon Schubert struct tdesc_type *field_type, 2075796c8dcSSimon Schubert int count); 208*cf7f2e2dSJohn Marino struct tdesc_type *tdesc_create_struct (struct tdesc_feature *feature, 209*cf7f2e2dSJohn Marino const char *name); 210*cf7f2e2dSJohn Marino void tdesc_set_struct_size (struct tdesc_type *type, LONGEST size); 2115796c8dcSSimon Schubert struct tdesc_type *tdesc_create_union (struct tdesc_feature *feature, 2125796c8dcSSimon Schubert const char *name); 213*cf7f2e2dSJohn Marino struct tdesc_type *tdesc_create_flags (struct tdesc_feature *feature, 214*cf7f2e2dSJohn Marino const char *name, 215*cf7f2e2dSJohn Marino LONGEST size); 2165796c8dcSSimon Schubert void tdesc_add_field (struct tdesc_type *type, const char *field_name, 2175796c8dcSSimon Schubert struct tdesc_type *field_type); 218*cf7f2e2dSJohn Marino void tdesc_add_bitfield (struct tdesc_type *type, const char *field_name, 219*cf7f2e2dSJohn Marino int start, int end); 220*cf7f2e2dSJohn Marino void tdesc_add_flag (struct tdesc_type *type, int start, 221*cf7f2e2dSJohn Marino const char *flag_name); 2225796c8dcSSimon Schubert void tdesc_create_reg (struct tdesc_feature *feature, const char *name, 2235796c8dcSSimon Schubert int regnum, int save_restore, const char *group, 2245796c8dcSSimon Schubert int bitsize, const char *type); 2255796c8dcSSimon Schubert 2265796c8dcSSimon Schubert #endif /* TARGET_DESCRIPTIONS_H */ 227