1 /* Target description support for GDB.
3 Copyright (C) 2006-2018 Free Software Foundation, Inc.
5 Contributed by CodeSourcery.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #ifndef TARGET_DESCRIPTIONS_H
23 #define TARGET_DESCRIPTIONS_H 1
24 #include "common/tdesc.h"
26 struct tdesc_arch_data;
28 /* An inferior's target description info is stored in this opaque
29 object. There's one such object per inferior. */
30 struct target_desc_info;
33 /* Fetch the current inferior's description, and switch its current
34 architecture to one which incorporates that description. */
36 void target_find_description (void);
38 /* Discard any description fetched from the target for the current
39 inferior, and switch the current architecture to one with no target
42 void target_clear_description (void);
44 /* Return the current inferior's target description. This should only
45 be used by gdbarch initialization code; most access should be
46 through an existing gdbarch. */
48 const struct target_desc *target_current_description (void);
50 /* Copy inferior target description data. Used for example when
51 handling (v)forks, where child's description is the same as the
52 parent's, since the child really is a copy of the parent. */
54 void copy_inferior_target_desc_info (struct inferior *destinf,
55 struct inferior *srcinf);
57 /* Free a target_desc_info object. */
59 void target_desc_info_free (struct target_desc_info *tdesc_info);
61 /* Returns true if INFO indicates the target description had been
62 supplied by the user. */
64 int target_desc_info_from_user_p (struct target_desc_info *info);
66 /* Record architecture-specific functions to call for pseudo-register
67 support. If tdesc_use_registers is called and gdbarch_num_pseudo_regs
68 is greater than zero, then these should be called as well.
69 They are equivalent to the gdbarch methods with similar names,
70 except that they will only be called for pseudo registers. */
72 void set_tdesc_pseudo_register_name
73 (struct gdbarch *gdbarch, gdbarch_register_name_ftype *pseudo_name);
75 void set_tdesc_pseudo_register_type
76 (struct gdbarch *gdbarch, gdbarch_register_type_ftype *pseudo_type);
78 void set_tdesc_pseudo_register_reggroup_p
79 (struct gdbarch *gdbarch,
80 gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p);
82 /* Update GDBARCH to use the TARGET_DESC for registers. TARGET_DESC
83 may be GDBARCH's target description or (if GDBARCH does not have
84 one which describes registers) another target description
85 constructed by the gdbarch initialization routine.
87 Fixed register assignments are taken from EARLY_DATA, which is freed.
88 All registers which have not been assigned fixed numbers are given
89 numbers above the current value of gdbarch_num_regs.
90 gdbarch_num_regs and various register-related predicates are updated to
91 refer to the target description. This function should only be called from
92 the architecture's gdbarch initialization routine, and only after
93 successfully validating the required registers. */
95 void tdesc_use_registers (struct gdbarch *gdbarch,
96 const struct target_desc *target_desc,
97 struct tdesc_arch_data *early_data);
99 /* Allocate initial data for validation of a target description during
100 gdbarch initialization. */
102 struct tdesc_arch_data *tdesc_data_alloc (void);
104 /* Clean up data allocated by tdesc_data_alloc. This should only
105 be called to discard the data; tdesc_use_registers takes ownership
106 of its EARLY_DATA argument. */
108 void tdesc_data_cleanup (void *data_untyped);
110 /* Search FEATURE for a register named NAME. Record REGNO and the
111 register in DATA; when tdesc_use_registers is called, REGNO will be
112 assigned to the register. 1 is returned if the register was found,
115 int tdesc_numbered_register (const struct tdesc_feature *feature,
116 struct tdesc_arch_data *data,
117 int regno, const char *name);
119 /* Search FEATURE for a register named NAME, but do not assign a fixed
120 register number to it. */
122 int tdesc_unnumbered_register (const struct tdesc_feature *feature,
125 /* Search FEATURE for a register named NAME, and return its size in
126 bits. The register must exist. */
128 int tdesc_register_size (const struct tdesc_feature *feature,
131 /* Search FEATURE for a register with any of the names from NAMES
132 (NULL-terminated). Record REGNO and the register in DATA; when
133 tdesc_use_registers is called, REGNO will be assigned to the
134 register. 1 is returned if the register was found, 0 if it was
137 int tdesc_numbered_register_choices (const struct tdesc_feature *feature,
138 struct tdesc_arch_data *data,
139 int regno, const char *const names[]);
142 /* Accessors for target descriptions. */
144 /* Return the BFD architecture associated with this target
145 description, or NULL if no architecture was specified. */
147 const struct bfd_arch_info *tdesc_architecture
148 (const struct target_desc *);
150 /* Return the OSABI associated with this target description, or
151 GDB_OSABI_UNKNOWN if no osabi was specified. */
153 enum gdb_osabi tdesc_osabi (const struct target_desc *);
155 /* Return non-zero if this target description is compatible
156 with the given BFD architecture. */
158 int tdesc_compatible_p (const struct target_desc *,
159 const struct bfd_arch_info *);
161 /* Return the string value of a property named KEY, or NULL if the
162 property was not specified. */
164 const char *tdesc_property (const struct target_desc *,
167 /* Return 1 if this target description describes any registers. */
169 int tdesc_has_registers (const struct target_desc *);
171 /* Return the feature with the given name, if present, or NULL if
172 the named feature is not found. */
174 const struct tdesc_feature *tdesc_find_feature (const struct target_desc *,
177 /* Return the name of FEATURE. */
179 const char *tdesc_feature_name (const struct tdesc_feature *feature);
181 /* Return the name of register REGNO, from the target description or
182 from an architecture-provided pseudo_register_name method. */
184 const char *tdesc_register_name (struct gdbarch *gdbarch, int regno);
186 /* Return the type of register REGNO, from the target description or
187 from an architecture-provided pseudo_register_type method. */
189 struct type *tdesc_register_type (struct gdbarch *gdbarch, int regno);
191 /* Return the type associated with ID, from the target description. */
193 struct type *tdesc_find_type (struct gdbarch *gdbarch, const char *id);
195 /* Check whether REGNUM is a member of REGGROUP using the target
196 description. Return -1 if the target description does not
199 int tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
200 struct reggroup *reggroup);
202 /* Methods for constructing a target description. */
204 struct cleanup *make_cleanup_free_target_description (struct target_desc *);
205 void set_tdesc_architecture (struct target_desc *,
206 const struct bfd_arch_info *);
207 void set_tdesc_osabi (struct target_desc *, enum gdb_osabi osabi);
208 void set_tdesc_property (struct target_desc *,
209 const char *key, const char *value);
210 void tdesc_add_compatible (struct target_desc *,
211 const struct bfd_arch_info *);
212 tdesc_type_with_fields *tdesc_create_enum (struct tdesc_feature *feature,
215 void tdesc_add_typed_bitfield (tdesc_type_with_fields *type, const char *field_name,
217 struct tdesc_type *field_type);
218 void tdesc_add_enum_value (tdesc_type_with_fields *type, int value,
222 namespace selftests {
224 /* Record that XML_FILE should generate a target description that equals
225 TDESC, to be verified by the "maintenance check xml-descriptions"
228 void record_xml_tdesc (const char *xml_file,
229 const struct target_desc *tdesc);
233 #endif /* TARGET_DESCRIPTIONS_H */