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 #include "defs.h"
235796c8dcSSimon Schubert #include "arch-utils.h"
245796c8dcSSimon Schubert #include "gdbcmd.h"
255796c8dcSSimon Schubert #include "gdbtypes.h"
265796c8dcSSimon Schubert #include "reggroups.h"
275796c8dcSSimon Schubert #include "target.h"
285796c8dcSSimon Schubert #include "target-descriptions.h"
295796c8dcSSimon Schubert #include "vec.h"
305796c8dcSSimon Schubert #include "xml-support.h"
315796c8dcSSimon Schubert #include "xml-tdesc.h"
32cf7f2e2dSJohn Marino #include "osabi.h"
335796c8dcSSimon Schubert
345796c8dcSSimon Schubert #include "gdb_assert.h"
355796c8dcSSimon Schubert #include "gdb_obstack.h"
365796c8dcSSimon Schubert #include "hashtab.h"
37*ef5ccd6cSJohn Marino #include "inferior.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
235*ef5ccd6cSJohn Marino /* Info about an inferior's target description. There's one of these
236*ef5ccd6cSJohn Marino for each inferior. */
2375796c8dcSSimon Schubert
238*ef5ccd6cSJohn Marino struct target_desc_info
239*ef5ccd6cSJohn Marino {
240*ef5ccd6cSJohn Marino /* A flag indicating that a description has already been fetched
241*ef5ccd6cSJohn Marino from the target, so it should not be queried again. */
2425796c8dcSSimon Schubert
243*ef5ccd6cSJohn Marino int fetched;
2445796c8dcSSimon Schubert
245*ef5ccd6cSJohn Marino /* The description fetched from the target, or NULL if the target
246*ef5ccd6cSJohn Marino did not supply any description. Only valid when
2475796c8dcSSimon Schubert target_desc_fetched is set. Only the description initialization
2485796c8dcSSimon Schubert code should access this; normally, the description should be
2495796c8dcSSimon Schubert accessed through the gdbarch object. */
2505796c8dcSSimon Schubert
251*ef5ccd6cSJohn Marino const struct target_desc *tdesc;
2525796c8dcSSimon Schubert
253*ef5ccd6cSJohn Marino /* The filename to read a target description from, as set by "set
254*ef5ccd6cSJohn Marino tdesc filename ..." */
2555796c8dcSSimon Schubert
256*ef5ccd6cSJohn Marino char *filename;
257*ef5ccd6cSJohn Marino };
2585796c8dcSSimon Schubert
259*ef5ccd6cSJohn Marino /* Get the inferior INF's target description info, allocating one on
260*ef5ccd6cSJohn Marino the stop if necessary. */
261*ef5ccd6cSJohn Marino
262*ef5ccd6cSJohn Marino static struct target_desc_info *
get_tdesc_info(struct inferior * inf)263*ef5ccd6cSJohn Marino get_tdesc_info (struct inferior *inf)
264*ef5ccd6cSJohn Marino {
265*ef5ccd6cSJohn Marino if (inf->tdesc_info == NULL)
266*ef5ccd6cSJohn Marino inf->tdesc_info = XCNEW (struct target_desc_info);
267*ef5ccd6cSJohn Marino return inf->tdesc_info;
268*ef5ccd6cSJohn Marino }
2695796c8dcSSimon Schubert
2705796c8dcSSimon Schubert /* A handle for architecture-specific data associated with the
2715796c8dcSSimon Schubert target description (see struct tdesc_arch_data). */
2725796c8dcSSimon Schubert
2735796c8dcSSimon Schubert static struct gdbarch_data *tdesc_data;
2745796c8dcSSimon Schubert
275*ef5ccd6cSJohn Marino /* See target-descriptions.h. */
276*ef5ccd6cSJohn Marino
277*ef5ccd6cSJohn Marino int
target_desc_info_from_user_p(struct target_desc_info * info)278*ef5ccd6cSJohn Marino target_desc_info_from_user_p (struct target_desc_info *info)
279*ef5ccd6cSJohn Marino {
280*ef5ccd6cSJohn Marino return info != NULL && info->filename != NULL;
281*ef5ccd6cSJohn Marino }
282*ef5ccd6cSJohn Marino
283*ef5ccd6cSJohn Marino /* See target-descriptions.h. */
284*ef5ccd6cSJohn Marino
285*ef5ccd6cSJohn Marino void
copy_inferior_target_desc_info(struct inferior * destinf,struct inferior * srcinf)286*ef5ccd6cSJohn Marino copy_inferior_target_desc_info (struct inferior *destinf, struct inferior *srcinf)
287*ef5ccd6cSJohn Marino {
288*ef5ccd6cSJohn Marino struct target_desc_info *src = get_tdesc_info (srcinf);
289*ef5ccd6cSJohn Marino struct target_desc_info *dest = get_tdesc_info (destinf);
290*ef5ccd6cSJohn Marino
291*ef5ccd6cSJohn Marino dest->fetched = src->fetched;
292*ef5ccd6cSJohn Marino dest->tdesc = src->tdesc;
293*ef5ccd6cSJohn Marino dest->filename = src->filename != NULL ? xstrdup (src->filename) : NULL;
294*ef5ccd6cSJohn Marino }
295*ef5ccd6cSJohn Marino
296*ef5ccd6cSJohn Marino /* See target-descriptions.h. */
297*ef5ccd6cSJohn Marino
298*ef5ccd6cSJohn Marino void
target_desc_info_free(struct target_desc_info * tdesc_info)299*ef5ccd6cSJohn Marino target_desc_info_free (struct target_desc_info *tdesc_info)
300*ef5ccd6cSJohn Marino {
301*ef5ccd6cSJohn Marino if (tdesc_info != NULL)
302*ef5ccd6cSJohn Marino {
303*ef5ccd6cSJohn Marino xfree (tdesc_info->filename);
304*ef5ccd6cSJohn Marino xfree (tdesc_info);
305*ef5ccd6cSJohn Marino }
306*ef5ccd6cSJohn Marino }
307*ef5ccd6cSJohn Marino
308*ef5ccd6cSJohn Marino /* Convenience helper macros. */
309*ef5ccd6cSJohn Marino
310*ef5ccd6cSJohn Marino #define target_desc_fetched \
311*ef5ccd6cSJohn Marino get_tdesc_info (current_inferior ())->fetched
312*ef5ccd6cSJohn Marino #define current_target_desc \
313*ef5ccd6cSJohn Marino get_tdesc_info (current_inferior ())->tdesc
314*ef5ccd6cSJohn Marino #define target_description_filename \
315*ef5ccd6cSJohn Marino get_tdesc_info (current_inferior ())->filename
316*ef5ccd6cSJohn Marino
317*ef5ccd6cSJohn Marino /* The string manipulated by the "set tdesc filename ..." command. */
318*ef5ccd6cSJohn Marino
319*ef5ccd6cSJohn Marino static char *tdesc_filename_cmd_string;
320*ef5ccd6cSJohn Marino
3215796c8dcSSimon Schubert /* Fetch the current target's description, and switch the current
3225796c8dcSSimon Schubert architecture to one which incorporates that description. */
3235796c8dcSSimon Schubert
3245796c8dcSSimon Schubert void
target_find_description(void)3255796c8dcSSimon Schubert target_find_description (void)
3265796c8dcSSimon Schubert {
3275796c8dcSSimon Schubert /* If we've already fetched a description from the target, don't do
3285796c8dcSSimon Schubert it again. This allows a target to fetch the description early,
3295796c8dcSSimon Schubert during its to_open or to_create_inferior, if it needs extra
3305796c8dcSSimon Schubert information about the target to initialize. */
3315796c8dcSSimon Schubert if (target_desc_fetched)
3325796c8dcSSimon Schubert return;
3335796c8dcSSimon Schubert
3345796c8dcSSimon Schubert /* The current architecture should not have any target description
3355796c8dcSSimon Schubert specified. It should have been cleared, e.g. when we
3365796c8dcSSimon Schubert disconnected from the previous target. */
337*ef5ccd6cSJohn Marino gdb_assert (gdbarch_target_desc (target_gdbarch ()) == NULL);
3385796c8dcSSimon Schubert
3395796c8dcSSimon Schubert /* First try to fetch an XML description from the user-specified
3405796c8dcSSimon Schubert file. */
3415796c8dcSSimon Schubert current_target_desc = NULL;
3425796c8dcSSimon Schubert if (target_description_filename != NULL
3435796c8dcSSimon Schubert && *target_description_filename != '\0')
3445796c8dcSSimon Schubert current_target_desc
3455796c8dcSSimon Schubert = file_read_description_xml (target_description_filename);
3465796c8dcSSimon Schubert
3475796c8dcSSimon Schubert /* Next try to read the description from the current target using
3485796c8dcSSimon Schubert target objects. */
3495796c8dcSSimon Schubert if (current_target_desc == NULL)
3505796c8dcSSimon Schubert current_target_desc = target_read_description_xml (¤t_target);
3515796c8dcSSimon Schubert
3525796c8dcSSimon Schubert /* If that failed try a target-specific hook. */
3535796c8dcSSimon Schubert if (current_target_desc == NULL)
3545796c8dcSSimon Schubert current_target_desc = target_read_description (¤t_target);
3555796c8dcSSimon Schubert
3565796c8dcSSimon Schubert /* If a non-NULL description was returned, then update the current
3575796c8dcSSimon Schubert architecture. */
3585796c8dcSSimon Schubert if (current_target_desc)
3595796c8dcSSimon Schubert {
3605796c8dcSSimon Schubert struct gdbarch_info info;
3615796c8dcSSimon Schubert
3625796c8dcSSimon Schubert gdbarch_info_init (&info);
3635796c8dcSSimon Schubert info.target_desc = current_target_desc;
3645796c8dcSSimon Schubert if (!gdbarch_update_p (info))
3655796c8dcSSimon Schubert warning (_("Architecture rejected target-supplied description"));
3665796c8dcSSimon Schubert else
3675796c8dcSSimon Schubert {
3685796c8dcSSimon Schubert struct tdesc_arch_data *data;
3695796c8dcSSimon Schubert
370*ef5ccd6cSJohn Marino data = gdbarch_data (target_gdbarch (), tdesc_data);
3715796c8dcSSimon Schubert if (tdesc_has_registers (current_target_desc)
3725796c8dcSSimon Schubert && data->arch_regs == NULL)
3735796c8dcSSimon Schubert warning (_("Target-supplied registers are not supported "
3745796c8dcSSimon Schubert "by the current architecture"));
3755796c8dcSSimon Schubert }
3765796c8dcSSimon Schubert }
3775796c8dcSSimon Schubert
3785796c8dcSSimon Schubert /* Now that we know this description is usable, record that we
3795796c8dcSSimon Schubert fetched it. */
3805796c8dcSSimon Schubert target_desc_fetched = 1;
3815796c8dcSSimon Schubert }
3825796c8dcSSimon Schubert
3835796c8dcSSimon Schubert /* Discard any description fetched from the current target, and switch
3845796c8dcSSimon Schubert the current architecture to one with no target description. */
3855796c8dcSSimon Schubert
3865796c8dcSSimon Schubert void
target_clear_description(void)3875796c8dcSSimon Schubert target_clear_description (void)
3885796c8dcSSimon Schubert {
3895796c8dcSSimon Schubert struct gdbarch_info info;
3905796c8dcSSimon Schubert
3915796c8dcSSimon Schubert if (!target_desc_fetched)
3925796c8dcSSimon Schubert return;
3935796c8dcSSimon Schubert
3945796c8dcSSimon Schubert target_desc_fetched = 0;
3955796c8dcSSimon Schubert current_target_desc = NULL;
3965796c8dcSSimon Schubert
3975796c8dcSSimon Schubert gdbarch_info_init (&info);
3985796c8dcSSimon Schubert if (!gdbarch_update_p (info))
3995796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
4005796c8dcSSimon Schubert _("Could not remove target-supplied description"));
4015796c8dcSSimon Schubert }
4025796c8dcSSimon Schubert
4035796c8dcSSimon Schubert /* Return the global current target description. This should only be
4045796c8dcSSimon Schubert used by gdbarch initialization code; most access should be through
4055796c8dcSSimon Schubert an existing gdbarch. */
4065796c8dcSSimon Schubert
4075796c8dcSSimon Schubert const struct target_desc *
target_current_description(void)4085796c8dcSSimon Schubert target_current_description (void)
4095796c8dcSSimon Schubert {
4105796c8dcSSimon Schubert if (target_desc_fetched)
4115796c8dcSSimon Schubert return current_target_desc;
4125796c8dcSSimon Schubert
4135796c8dcSSimon Schubert return NULL;
4145796c8dcSSimon Schubert }
4155796c8dcSSimon Schubert
4165796c8dcSSimon Schubert /* Return non-zero if this target description is compatible
4175796c8dcSSimon Schubert with the given BFD architecture. */
4185796c8dcSSimon Schubert
4195796c8dcSSimon Schubert int
tdesc_compatible_p(const struct target_desc * target_desc,const struct bfd_arch_info * arch)4205796c8dcSSimon Schubert tdesc_compatible_p (const struct target_desc *target_desc,
4215796c8dcSSimon Schubert const struct bfd_arch_info *arch)
4225796c8dcSSimon Schubert {
4235796c8dcSSimon Schubert const struct bfd_arch_info *compat;
4245796c8dcSSimon Schubert int ix;
4255796c8dcSSimon Schubert
4265796c8dcSSimon Schubert for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
4275796c8dcSSimon Schubert ix++)
4285796c8dcSSimon Schubert {
4295796c8dcSSimon Schubert if (compat == arch
4305796c8dcSSimon Schubert || arch->compatible (arch, compat)
4315796c8dcSSimon Schubert || compat->compatible (compat, arch))
4325796c8dcSSimon Schubert return 1;
4335796c8dcSSimon Schubert }
4345796c8dcSSimon Schubert
4355796c8dcSSimon Schubert return 0;
4365796c8dcSSimon Schubert }
4375796c8dcSSimon Schubert
4385796c8dcSSimon Schubert
4395796c8dcSSimon Schubert /* Direct accessors for target descriptions. */
4405796c8dcSSimon Schubert
4415796c8dcSSimon Schubert /* Return the string value of a property named KEY, or NULL if the
4425796c8dcSSimon Schubert property was not specified. */
4435796c8dcSSimon Schubert
4445796c8dcSSimon Schubert const char *
tdesc_property(const struct target_desc * target_desc,const char * key)4455796c8dcSSimon Schubert tdesc_property (const struct target_desc *target_desc, const char *key)
4465796c8dcSSimon Schubert {
4475796c8dcSSimon Schubert struct property *prop;
4485796c8dcSSimon Schubert int ix;
4495796c8dcSSimon Schubert
4505796c8dcSSimon Schubert for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
4515796c8dcSSimon Schubert ix++)
4525796c8dcSSimon Schubert if (strcmp (prop->key, key) == 0)
4535796c8dcSSimon Schubert return prop->value;
4545796c8dcSSimon Schubert
4555796c8dcSSimon Schubert return NULL;
4565796c8dcSSimon Schubert }
4575796c8dcSSimon Schubert
4585796c8dcSSimon Schubert /* Return the BFD architecture associated with this target
4595796c8dcSSimon Schubert description, or NULL if no architecture was specified. */
4605796c8dcSSimon Schubert
4615796c8dcSSimon Schubert const struct bfd_arch_info *
tdesc_architecture(const struct target_desc * target_desc)4625796c8dcSSimon Schubert tdesc_architecture (const struct target_desc *target_desc)
4635796c8dcSSimon Schubert {
4645796c8dcSSimon Schubert return target_desc->arch;
4655796c8dcSSimon Schubert }
4665796c8dcSSimon Schubert
4675796c8dcSSimon Schubert /* Return the OSABI associated with this target description, or
4685796c8dcSSimon Schubert GDB_OSABI_UNKNOWN if no osabi was specified. */
4695796c8dcSSimon Schubert
4705796c8dcSSimon Schubert enum gdb_osabi
tdesc_osabi(const struct target_desc * target_desc)4715796c8dcSSimon Schubert tdesc_osabi (const struct target_desc *target_desc)
4725796c8dcSSimon Schubert {
4735796c8dcSSimon Schubert return target_desc->osabi;
4745796c8dcSSimon Schubert }
4755796c8dcSSimon Schubert
4765796c8dcSSimon Schubert
4775796c8dcSSimon Schubert
4785796c8dcSSimon Schubert /* Return 1 if this target description includes any registers. */
4795796c8dcSSimon Schubert
4805796c8dcSSimon Schubert int
tdesc_has_registers(const struct target_desc * target_desc)4815796c8dcSSimon Schubert tdesc_has_registers (const struct target_desc *target_desc)
4825796c8dcSSimon Schubert {
4835796c8dcSSimon Schubert int ix;
4845796c8dcSSimon Schubert struct tdesc_feature *feature;
4855796c8dcSSimon Schubert
4865796c8dcSSimon Schubert if (target_desc == NULL)
4875796c8dcSSimon Schubert return 0;
4885796c8dcSSimon Schubert
4895796c8dcSSimon Schubert for (ix = 0;
4905796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
4915796c8dcSSimon Schubert ix++)
4925796c8dcSSimon Schubert if (! VEC_empty (tdesc_reg_p, feature->registers))
4935796c8dcSSimon Schubert return 1;
4945796c8dcSSimon Schubert
4955796c8dcSSimon Schubert return 0;
4965796c8dcSSimon Schubert }
4975796c8dcSSimon Schubert
4985796c8dcSSimon Schubert /* Return the feature with the given name, if present, or NULL if
4995796c8dcSSimon Schubert the named feature is not found. */
5005796c8dcSSimon Schubert
5015796c8dcSSimon Schubert const struct tdesc_feature *
tdesc_find_feature(const struct target_desc * target_desc,const char * name)5025796c8dcSSimon Schubert tdesc_find_feature (const struct target_desc *target_desc,
5035796c8dcSSimon Schubert const char *name)
5045796c8dcSSimon Schubert {
5055796c8dcSSimon Schubert int ix;
5065796c8dcSSimon Schubert struct tdesc_feature *feature;
5075796c8dcSSimon Schubert
5085796c8dcSSimon Schubert for (ix = 0;
5095796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
5105796c8dcSSimon Schubert ix++)
5115796c8dcSSimon Schubert if (strcmp (feature->name, name) == 0)
5125796c8dcSSimon Schubert return feature;
5135796c8dcSSimon Schubert
5145796c8dcSSimon Schubert return NULL;
5155796c8dcSSimon Schubert }
5165796c8dcSSimon Schubert
5175796c8dcSSimon Schubert /* Return the name of FEATURE. */
5185796c8dcSSimon Schubert
5195796c8dcSSimon Schubert const char *
tdesc_feature_name(const struct tdesc_feature * feature)5205796c8dcSSimon Schubert tdesc_feature_name (const struct tdesc_feature *feature)
5215796c8dcSSimon Schubert {
5225796c8dcSSimon Schubert return feature->name;
5235796c8dcSSimon Schubert }
5245796c8dcSSimon Schubert
5255796c8dcSSimon Schubert /* Predefined types. */
5265796c8dcSSimon Schubert static struct tdesc_type tdesc_predefined_types[] =
5275796c8dcSSimon Schubert {
5285796c8dcSSimon Schubert { "int8", TDESC_TYPE_INT8 },
5295796c8dcSSimon Schubert { "int16", TDESC_TYPE_INT16 },
5305796c8dcSSimon Schubert { "int32", TDESC_TYPE_INT32 },
5315796c8dcSSimon Schubert { "int64", TDESC_TYPE_INT64 },
5325796c8dcSSimon Schubert { "int128", TDESC_TYPE_INT128 },
5335796c8dcSSimon Schubert { "uint8", TDESC_TYPE_UINT8 },
5345796c8dcSSimon Schubert { "uint16", TDESC_TYPE_UINT16 },
5355796c8dcSSimon Schubert { "uint32", TDESC_TYPE_UINT32 },
5365796c8dcSSimon Schubert { "uint64", TDESC_TYPE_UINT64 },
5375796c8dcSSimon Schubert { "uint128", TDESC_TYPE_UINT128 },
5385796c8dcSSimon Schubert { "code_ptr", TDESC_TYPE_CODE_PTR },
5395796c8dcSSimon Schubert { "data_ptr", TDESC_TYPE_DATA_PTR },
5405796c8dcSSimon Schubert { "ieee_single", TDESC_TYPE_IEEE_SINGLE },
5415796c8dcSSimon Schubert { "ieee_double", TDESC_TYPE_IEEE_DOUBLE },
542cf7f2e2dSJohn Marino { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT },
543cf7f2e2dSJohn Marino { "i387_ext", TDESC_TYPE_I387_EXT }
5445796c8dcSSimon Schubert };
5455796c8dcSSimon Schubert
5465796c8dcSSimon Schubert /* Return the type associated with ID in the context of FEATURE, or
5475796c8dcSSimon Schubert NULL if none. */
5485796c8dcSSimon Schubert
5495796c8dcSSimon Schubert struct tdesc_type *
tdesc_named_type(const struct tdesc_feature * feature,const char * id)5505796c8dcSSimon Schubert tdesc_named_type (const struct tdesc_feature *feature, const char *id)
5515796c8dcSSimon Schubert {
5525796c8dcSSimon Schubert int ix;
5535796c8dcSSimon Schubert struct tdesc_type *type;
5545796c8dcSSimon Schubert
5555796c8dcSSimon Schubert /* First try target-defined types. */
5565796c8dcSSimon Schubert for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
5575796c8dcSSimon Schubert if (strcmp (type->name, id) == 0)
5585796c8dcSSimon Schubert return type;
5595796c8dcSSimon Schubert
5605796c8dcSSimon Schubert /* Next try the predefined types. */
5615796c8dcSSimon Schubert for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
5625796c8dcSSimon Schubert if (strcmp (tdesc_predefined_types[ix].name, id) == 0)
5635796c8dcSSimon Schubert return &tdesc_predefined_types[ix];
5645796c8dcSSimon Schubert
5655796c8dcSSimon Schubert return NULL;
5665796c8dcSSimon Schubert }
5675796c8dcSSimon Schubert
568cf7f2e2dSJohn Marino /* Lookup type associated with ID. */
569cf7f2e2dSJohn Marino
570cf7f2e2dSJohn Marino struct type *
tdesc_find_type(struct gdbarch * gdbarch,const char * id)571cf7f2e2dSJohn Marino tdesc_find_type (struct gdbarch *gdbarch, const char *id)
572cf7f2e2dSJohn Marino {
573cf7f2e2dSJohn Marino struct tdesc_arch_reg *reg;
574cf7f2e2dSJohn Marino struct tdesc_arch_data *data;
575cf7f2e2dSJohn Marino int i, num_regs;
576cf7f2e2dSJohn Marino
577cf7f2e2dSJohn Marino data = gdbarch_data (gdbarch, tdesc_data);
578cf7f2e2dSJohn Marino num_regs = VEC_length (tdesc_arch_reg, data->arch_regs);
579cf7f2e2dSJohn Marino for (i = 0; i < num_regs; i++)
580cf7f2e2dSJohn Marino {
581cf7f2e2dSJohn Marino reg = VEC_index (tdesc_arch_reg, data->arch_regs, i);
582cf7f2e2dSJohn Marino if (reg->reg
583cf7f2e2dSJohn Marino && reg->reg->tdesc_type
584cf7f2e2dSJohn Marino && reg->type
585cf7f2e2dSJohn Marino && strcmp (id, reg->reg->tdesc_type->name) == 0)
586cf7f2e2dSJohn Marino return reg->type;
587cf7f2e2dSJohn Marino }
588cf7f2e2dSJohn Marino
589cf7f2e2dSJohn Marino return NULL;
590cf7f2e2dSJohn Marino }
591cf7f2e2dSJohn Marino
5925796c8dcSSimon Schubert /* Construct, if necessary, and return the GDB type implementing target
5935796c8dcSSimon Schubert type TDESC_TYPE for architecture GDBARCH. */
5945796c8dcSSimon Schubert
5955796c8dcSSimon Schubert static struct type *
tdesc_gdb_type(struct gdbarch * gdbarch,struct tdesc_type * tdesc_type)5965796c8dcSSimon Schubert tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
5975796c8dcSSimon Schubert {
598cf7f2e2dSJohn Marino struct type *type;
599cf7f2e2dSJohn Marino
6005796c8dcSSimon Schubert switch (tdesc_type->kind)
6015796c8dcSSimon Schubert {
6025796c8dcSSimon Schubert /* Predefined types. */
6035796c8dcSSimon Schubert case TDESC_TYPE_INT8:
6045796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int8;
6055796c8dcSSimon Schubert
6065796c8dcSSimon Schubert case TDESC_TYPE_INT16:
6075796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int16;
6085796c8dcSSimon Schubert
6095796c8dcSSimon Schubert case TDESC_TYPE_INT32:
6105796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int32;
6115796c8dcSSimon Schubert
6125796c8dcSSimon Schubert case TDESC_TYPE_INT64:
6135796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int64;
6145796c8dcSSimon Schubert
6155796c8dcSSimon Schubert case TDESC_TYPE_INT128:
6165796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int128;
6175796c8dcSSimon Schubert
6185796c8dcSSimon Schubert case TDESC_TYPE_UINT8:
6195796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_uint8;
6205796c8dcSSimon Schubert
6215796c8dcSSimon Schubert case TDESC_TYPE_UINT16:
6225796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_uint16;
6235796c8dcSSimon Schubert
6245796c8dcSSimon Schubert case TDESC_TYPE_UINT32:
6255796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_uint32;
6265796c8dcSSimon Schubert
6275796c8dcSSimon Schubert case TDESC_TYPE_UINT64:
6285796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_uint64;
6295796c8dcSSimon Schubert
6305796c8dcSSimon Schubert case TDESC_TYPE_UINT128:
6315796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_uint128;
6325796c8dcSSimon Schubert
6335796c8dcSSimon Schubert case TDESC_TYPE_CODE_PTR:
6345796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_func_ptr;
6355796c8dcSSimon Schubert
6365796c8dcSSimon Schubert case TDESC_TYPE_DATA_PTR:
6375796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_data_ptr;
6385796c8dcSSimon Schubert
639cf7f2e2dSJohn Marino default:
640cf7f2e2dSJohn Marino break;
641cf7f2e2dSJohn Marino }
642cf7f2e2dSJohn Marino
643cf7f2e2dSJohn Marino type = tdesc_find_type (gdbarch, tdesc_type->name);
644cf7f2e2dSJohn Marino if (type)
645cf7f2e2dSJohn Marino return type;
646cf7f2e2dSJohn Marino
647cf7f2e2dSJohn Marino switch (tdesc_type->kind)
648cf7f2e2dSJohn Marino {
6495796c8dcSSimon Schubert case TDESC_TYPE_IEEE_SINGLE:
6505796c8dcSSimon Schubert return arch_float_type (gdbarch, -1, "builtin_type_ieee_single",
6515796c8dcSSimon Schubert floatformats_ieee_single);
6525796c8dcSSimon Schubert
6535796c8dcSSimon Schubert case TDESC_TYPE_IEEE_DOUBLE:
6545796c8dcSSimon Schubert return arch_float_type (gdbarch, -1, "builtin_type_ieee_double",
6555796c8dcSSimon Schubert floatformats_ieee_double);
6565796c8dcSSimon Schubert
6575796c8dcSSimon Schubert case TDESC_TYPE_ARM_FPA_EXT:
6585796c8dcSSimon Schubert return arch_float_type (gdbarch, -1, "builtin_type_arm_ext",
6595796c8dcSSimon Schubert floatformats_arm_ext);
6605796c8dcSSimon Schubert
661cf7f2e2dSJohn Marino case TDESC_TYPE_I387_EXT:
662cf7f2e2dSJohn Marino return arch_float_type (gdbarch, -1, "builtin_type_i387_ext",
663cf7f2e2dSJohn Marino floatformats_i387_ext);
664cf7f2e2dSJohn Marino
6655796c8dcSSimon Schubert /* Types defined by a target feature. */
6665796c8dcSSimon Schubert case TDESC_TYPE_VECTOR:
6675796c8dcSSimon Schubert {
6685796c8dcSSimon Schubert struct type *type, *field_type;
6695796c8dcSSimon Schubert
6705796c8dcSSimon Schubert field_type = tdesc_gdb_type (gdbarch, tdesc_type->u.v.type);
6715796c8dcSSimon Schubert type = init_vector_type (field_type, tdesc_type->u.v.count);
6725796c8dcSSimon Schubert TYPE_NAME (type) = xstrdup (tdesc_type->name);
6735796c8dcSSimon Schubert
6745796c8dcSSimon Schubert return type;
6755796c8dcSSimon Schubert }
6765796c8dcSSimon Schubert
677cf7f2e2dSJohn Marino case TDESC_TYPE_STRUCT:
678cf7f2e2dSJohn Marino {
679cf7f2e2dSJohn Marino struct type *type, *field_type;
680cf7f2e2dSJohn Marino struct tdesc_type_field *f;
681cf7f2e2dSJohn Marino int ix;
682cf7f2e2dSJohn Marino
683cf7f2e2dSJohn Marino type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
684cf7f2e2dSJohn Marino TYPE_NAME (type) = xstrdup (tdesc_type->name);
685cf7f2e2dSJohn Marino TYPE_TAG_NAME (type) = TYPE_NAME (type);
686cf7f2e2dSJohn Marino
687cf7f2e2dSJohn Marino for (ix = 0;
688cf7f2e2dSJohn Marino VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
689cf7f2e2dSJohn Marino ix++)
690cf7f2e2dSJohn Marino {
691cf7f2e2dSJohn Marino if (f->type == NULL)
692cf7f2e2dSJohn Marino {
693cf7f2e2dSJohn Marino /* Bitfield. */
694cf7f2e2dSJohn Marino struct field *fld;
695cf7f2e2dSJohn Marino struct type *field_type;
696cf7f2e2dSJohn Marino int bitsize, total_size;
697cf7f2e2dSJohn Marino
698cf7f2e2dSJohn Marino /* This invariant should be preserved while creating
699cf7f2e2dSJohn Marino types. */
700cf7f2e2dSJohn Marino gdb_assert (tdesc_type->u.u.size != 0);
701cf7f2e2dSJohn Marino if (tdesc_type->u.u.size > 4)
702cf7f2e2dSJohn Marino field_type = builtin_type (gdbarch)->builtin_uint64;
703cf7f2e2dSJohn Marino else
704cf7f2e2dSJohn Marino field_type = builtin_type (gdbarch)->builtin_uint32;
705cf7f2e2dSJohn Marino
706cf7f2e2dSJohn Marino fld = append_composite_type_field_raw (type, xstrdup (f->name),
707cf7f2e2dSJohn Marino field_type);
708cf7f2e2dSJohn Marino
709cf7f2e2dSJohn Marino /* For little-endian, BITPOS counts from the LSB of
710cf7f2e2dSJohn Marino the structure and marks the LSB of the field. For
711cf7f2e2dSJohn Marino big-endian, BITPOS counts from the MSB of the
712cf7f2e2dSJohn Marino structure and marks the MSB of the field. Either
713cf7f2e2dSJohn Marino way, it is the number of bits to the "left" of the
714cf7f2e2dSJohn Marino field. To calculate this in big-endian, we need
715cf7f2e2dSJohn Marino the total size of the structure. */
716cf7f2e2dSJohn Marino bitsize = f->end - f->start + 1;
717cf7f2e2dSJohn Marino total_size = tdesc_type->u.u.size * TARGET_CHAR_BIT;
718cf7f2e2dSJohn Marino if (gdbarch_bits_big_endian (gdbarch))
719*ef5ccd6cSJohn Marino SET_FIELD_BITPOS (fld[0], total_size - f->start - bitsize);
720cf7f2e2dSJohn Marino else
721*ef5ccd6cSJohn Marino SET_FIELD_BITPOS (fld[0], f->start);
722cf7f2e2dSJohn Marino FIELD_BITSIZE (fld[0]) = bitsize;
723cf7f2e2dSJohn Marino }
724cf7f2e2dSJohn Marino else
725cf7f2e2dSJohn Marino {
726cf7f2e2dSJohn Marino field_type = tdesc_gdb_type (gdbarch, f->type);
727cf7f2e2dSJohn Marino append_composite_type_field (type, xstrdup (f->name),
728cf7f2e2dSJohn Marino field_type);
729cf7f2e2dSJohn Marino }
730cf7f2e2dSJohn Marino }
731cf7f2e2dSJohn Marino
732cf7f2e2dSJohn Marino if (tdesc_type->u.u.size != 0)
733cf7f2e2dSJohn Marino TYPE_LENGTH (type) = tdesc_type->u.u.size;
734cf7f2e2dSJohn Marino return type;
735cf7f2e2dSJohn Marino }
736cf7f2e2dSJohn Marino
7375796c8dcSSimon Schubert case TDESC_TYPE_UNION:
7385796c8dcSSimon Schubert {
7395796c8dcSSimon Schubert struct type *type, *field_type;
7405796c8dcSSimon Schubert struct tdesc_type_field *f;
7415796c8dcSSimon Schubert int ix;
7425796c8dcSSimon Schubert
7435796c8dcSSimon Schubert type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
7445796c8dcSSimon Schubert TYPE_NAME (type) = xstrdup (tdesc_type->name);
7455796c8dcSSimon Schubert
7465796c8dcSSimon Schubert for (ix = 0;
7475796c8dcSSimon Schubert VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
7485796c8dcSSimon Schubert ix++)
7495796c8dcSSimon Schubert {
7505796c8dcSSimon Schubert field_type = tdesc_gdb_type (gdbarch, f->type);
7515796c8dcSSimon Schubert append_composite_type_field (type, xstrdup (f->name), field_type);
7525796c8dcSSimon Schubert
753cf7f2e2dSJohn Marino /* If any of the children of a union are vectors, flag the
7545796c8dcSSimon Schubert union as a vector also. This allows e.g. a union of two
7555796c8dcSSimon Schubert vector types to show up automatically in "info vector". */
7565796c8dcSSimon Schubert if (TYPE_VECTOR (field_type))
7575796c8dcSSimon Schubert TYPE_VECTOR (type) = 1;
7585796c8dcSSimon Schubert }
759cf7f2e2dSJohn Marino return type;
760cf7f2e2dSJohn Marino }
761cf7f2e2dSJohn Marino
762cf7f2e2dSJohn Marino case TDESC_TYPE_FLAGS:
763cf7f2e2dSJohn Marino {
764cf7f2e2dSJohn Marino struct tdesc_type_flag *f;
765cf7f2e2dSJohn Marino int ix;
766cf7f2e2dSJohn Marino
767c50c785cSJohn Marino type = arch_flags_type (gdbarch, tdesc_type->name,
768cf7f2e2dSJohn Marino tdesc_type->u.f.size);
769cf7f2e2dSJohn Marino for (ix = 0;
770cf7f2e2dSJohn Marino VEC_iterate (tdesc_type_flag, tdesc_type->u.f.flags, ix, f);
771cf7f2e2dSJohn Marino ix++)
772cf7f2e2dSJohn Marino /* Note that contrary to the function name, this call will
773cf7f2e2dSJohn Marino just set the properties of an already-allocated
774cf7f2e2dSJohn Marino field. */
775cf7f2e2dSJohn Marino append_flags_type_flag (type, f->start,
776cf7f2e2dSJohn Marino *f->name ? f->name : NULL);
7775796c8dcSSimon Schubert
7785796c8dcSSimon Schubert return type;
7795796c8dcSSimon Schubert }
7805796c8dcSSimon Schubert }
7815796c8dcSSimon Schubert
7825796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
7835796c8dcSSimon Schubert "Type \"%s\" has an unknown kind %d",
7845796c8dcSSimon Schubert tdesc_type->name, tdesc_type->kind);
7855796c8dcSSimon Schubert }
7865796c8dcSSimon Schubert
7875796c8dcSSimon Schubert
7885796c8dcSSimon Schubert /* Support for registers from target descriptions. */
7895796c8dcSSimon Schubert
7905796c8dcSSimon Schubert /* Construct the per-gdbarch data. */
7915796c8dcSSimon Schubert
7925796c8dcSSimon Schubert static void *
tdesc_data_init(struct obstack * obstack)7935796c8dcSSimon Schubert tdesc_data_init (struct obstack *obstack)
7945796c8dcSSimon Schubert {
7955796c8dcSSimon Schubert struct tdesc_arch_data *data;
7965796c8dcSSimon Schubert
7975796c8dcSSimon Schubert data = OBSTACK_ZALLOC (obstack, struct tdesc_arch_data);
7985796c8dcSSimon Schubert return data;
7995796c8dcSSimon Schubert }
8005796c8dcSSimon Schubert
8015796c8dcSSimon Schubert /* Similar, but for the temporary copy used during architecture
8025796c8dcSSimon Schubert initialization. */
8035796c8dcSSimon Schubert
8045796c8dcSSimon Schubert struct tdesc_arch_data *
tdesc_data_alloc(void)8055796c8dcSSimon Schubert tdesc_data_alloc (void)
8065796c8dcSSimon Schubert {
8075796c8dcSSimon Schubert return XZALLOC (struct tdesc_arch_data);
8085796c8dcSSimon Schubert }
8095796c8dcSSimon Schubert
8105796c8dcSSimon Schubert /* Free something allocated by tdesc_data_alloc, if it is not going
8115796c8dcSSimon Schubert to be used (for instance if it was unsuitable for the
8125796c8dcSSimon Schubert architecture). */
8135796c8dcSSimon Schubert
8145796c8dcSSimon Schubert void
tdesc_data_cleanup(void * data_untyped)8155796c8dcSSimon Schubert tdesc_data_cleanup (void *data_untyped)
8165796c8dcSSimon Schubert {
8175796c8dcSSimon Schubert struct tdesc_arch_data *data = data_untyped;
8185796c8dcSSimon Schubert
8195796c8dcSSimon Schubert VEC_free (tdesc_arch_reg, data->arch_regs);
8205796c8dcSSimon Schubert xfree (data);
8215796c8dcSSimon Schubert }
8225796c8dcSSimon Schubert
8235796c8dcSSimon Schubert /* Search FEATURE for a register named NAME. */
8245796c8dcSSimon Schubert
8255796c8dcSSimon Schubert static struct tdesc_reg *
tdesc_find_register_early(const struct tdesc_feature * feature,const char * name)8265796c8dcSSimon Schubert tdesc_find_register_early (const struct tdesc_feature *feature,
8275796c8dcSSimon Schubert const char *name)
8285796c8dcSSimon Schubert {
8295796c8dcSSimon Schubert int ixr;
8305796c8dcSSimon Schubert struct tdesc_reg *reg;
8315796c8dcSSimon Schubert
8325796c8dcSSimon Schubert for (ixr = 0;
8335796c8dcSSimon Schubert VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
8345796c8dcSSimon Schubert ixr++)
8355796c8dcSSimon Schubert if (strcasecmp (reg->name, name) == 0)
8365796c8dcSSimon Schubert return reg;
8375796c8dcSSimon Schubert
8385796c8dcSSimon Schubert return NULL;
8395796c8dcSSimon Schubert }
8405796c8dcSSimon Schubert
8415796c8dcSSimon Schubert /* Search FEATURE for a register named NAME. Assign REGNO to it. */
8425796c8dcSSimon Schubert
8435796c8dcSSimon Schubert int
tdesc_numbered_register(const struct tdesc_feature * feature,struct tdesc_arch_data * data,int regno,const char * name)8445796c8dcSSimon Schubert tdesc_numbered_register (const struct tdesc_feature *feature,
8455796c8dcSSimon Schubert struct tdesc_arch_data *data,
8465796c8dcSSimon Schubert int regno, const char *name)
8475796c8dcSSimon Schubert {
8485796c8dcSSimon Schubert struct tdesc_arch_reg arch_reg = { 0 };
8495796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
8505796c8dcSSimon Schubert
8515796c8dcSSimon Schubert if (reg == NULL)
8525796c8dcSSimon Schubert return 0;
8535796c8dcSSimon Schubert
8545796c8dcSSimon Schubert /* Make sure the vector includes a REGNO'th element. */
8555796c8dcSSimon Schubert while (regno >= VEC_length (tdesc_arch_reg, data->arch_regs))
8565796c8dcSSimon Schubert VEC_safe_push (tdesc_arch_reg, data->arch_regs, &arch_reg);
8575796c8dcSSimon Schubert
8585796c8dcSSimon Schubert arch_reg.reg = reg;
8595796c8dcSSimon Schubert VEC_replace (tdesc_arch_reg, data->arch_regs, regno, &arch_reg);
8605796c8dcSSimon Schubert return 1;
8615796c8dcSSimon Schubert }
8625796c8dcSSimon Schubert
8635796c8dcSSimon Schubert /* Search FEATURE for a register named NAME, but do not assign a fixed
8645796c8dcSSimon Schubert register number to it. */
8655796c8dcSSimon Schubert
8665796c8dcSSimon Schubert int
tdesc_unnumbered_register(const struct tdesc_feature * feature,const char * name)8675796c8dcSSimon Schubert tdesc_unnumbered_register (const struct tdesc_feature *feature,
8685796c8dcSSimon Schubert const char *name)
8695796c8dcSSimon Schubert {
8705796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
8715796c8dcSSimon Schubert
8725796c8dcSSimon Schubert if (reg == NULL)
8735796c8dcSSimon Schubert return 0;
8745796c8dcSSimon Schubert
8755796c8dcSSimon Schubert return 1;
8765796c8dcSSimon Schubert }
8775796c8dcSSimon Schubert
8785796c8dcSSimon Schubert /* Search FEATURE for a register whose name is in NAMES and assign
8795796c8dcSSimon Schubert REGNO to it. */
8805796c8dcSSimon Schubert
8815796c8dcSSimon Schubert int
tdesc_numbered_register_choices(const struct tdesc_feature * feature,struct tdesc_arch_data * data,int regno,const char * const names[])8825796c8dcSSimon Schubert tdesc_numbered_register_choices (const struct tdesc_feature *feature,
8835796c8dcSSimon Schubert struct tdesc_arch_data *data,
8845796c8dcSSimon Schubert int regno, const char *const names[])
8855796c8dcSSimon Schubert {
8865796c8dcSSimon Schubert int i;
8875796c8dcSSimon Schubert
8885796c8dcSSimon Schubert for (i = 0; names[i] != NULL; i++)
8895796c8dcSSimon Schubert if (tdesc_numbered_register (feature, data, regno, names[i]))
8905796c8dcSSimon Schubert return 1;
8915796c8dcSSimon Schubert
8925796c8dcSSimon Schubert return 0;
8935796c8dcSSimon Schubert }
8945796c8dcSSimon Schubert
8955796c8dcSSimon Schubert /* Search FEATURE for a register named NAME, and return its size in
8965796c8dcSSimon Schubert bits. The register must exist. */
8975796c8dcSSimon Schubert
8985796c8dcSSimon Schubert int
tdesc_register_size(const struct tdesc_feature * feature,const char * name)8995796c8dcSSimon Schubert tdesc_register_size (const struct tdesc_feature *feature,
9005796c8dcSSimon Schubert const char *name)
9015796c8dcSSimon Schubert {
9025796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
9035796c8dcSSimon Schubert
9045796c8dcSSimon Schubert gdb_assert (reg != NULL);
9055796c8dcSSimon Schubert return reg->bitsize;
9065796c8dcSSimon Schubert }
9075796c8dcSSimon Schubert
9085796c8dcSSimon Schubert /* Look up a register by its GDB internal register number. */
9095796c8dcSSimon Schubert
9105796c8dcSSimon Schubert static struct tdesc_arch_reg *
tdesc_find_arch_register(struct gdbarch * gdbarch,int regno)9115796c8dcSSimon Schubert tdesc_find_arch_register (struct gdbarch *gdbarch, int regno)
9125796c8dcSSimon Schubert {
9135796c8dcSSimon Schubert struct tdesc_arch_data *data;
9145796c8dcSSimon Schubert
9155796c8dcSSimon Schubert data = gdbarch_data (gdbarch, tdesc_data);
9165796c8dcSSimon Schubert if (regno < VEC_length (tdesc_arch_reg, data->arch_regs))
9175796c8dcSSimon Schubert return VEC_index (tdesc_arch_reg, data->arch_regs, regno);
9185796c8dcSSimon Schubert else
9195796c8dcSSimon Schubert return NULL;
9205796c8dcSSimon Schubert }
9215796c8dcSSimon Schubert
9225796c8dcSSimon Schubert static struct tdesc_reg *
tdesc_find_register(struct gdbarch * gdbarch,int regno)9235796c8dcSSimon Schubert tdesc_find_register (struct gdbarch *gdbarch, int regno)
9245796c8dcSSimon Schubert {
9255796c8dcSSimon Schubert struct tdesc_arch_reg *reg = tdesc_find_arch_register (gdbarch, regno);
926cf7f2e2dSJohn Marino
9275796c8dcSSimon Schubert return reg? reg->reg : NULL;
9285796c8dcSSimon Schubert }
9295796c8dcSSimon Schubert
9305796c8dcSSimon Schubert /* Return the name of register REGNO, from the target description or
9315796c8dcSSimon Schubert from an architecture-provided pseudo_register_name method. */
9325796c8dcSSimon Schubert
9335796c8dcSSimon Schubert const char *
tdesc_register_name(struct gdbarch * gdbarch,int regno)9345796c8dcSSimon Schubert tdesc_register_name (struct gdbarch *gdbarch, int regno)
9355796c8dcSSimon Schubert {
9365796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
9375796c8dcSSimon Schubert int num_regs = gdbarch_num_regs (gdbarch);
9385796c8dcSSimon Schubert int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
9395796c8dcSSimon Schubert
9405796c8dcSSimon Schubert if (reg != NULL)
9415796c8dcSSimon Schubert return reg->name;
9425796c8dcSSimon Schubert
9435796c8dcSSimon Schubert if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
9445796c8dcSSimon Schubert {
9455796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
946cf7f2e2dSJohn Marino
9475796c8dcSSimon Schubert gdb_assert (data->pseudo_register_name != NULL);
9485796c8dcSSimon Schubert return data->pseudo_register_name (gdbarch, regno);
9495796c8dcSSimon Schubert }
9505796c8dcSSimon Schubert
9515796c8dcSSimon Schubert return "";
9525796c8dcSSimon Schubert }
9535796c8dcSSimon Schubert
9545796c8dcSSimon Schubert struct type *
tdesc_register_type(struct gdbarch * gdbarch,int regno)9555796c8dcSSimon Schubert tdesc_register_type (struct gdbarch *gdbarch, int regno)
9565796c8dcSSimon Schubert {
9575796c8dcSSimon Schubert struct tdesc_arch_reg *arch_reg = tdesc_find_arch_register (gdbarch, regno);
9585796c8dcSSimon Schubert struct tdesc_reg *reg = arch_reg? arch_reg->reg : NULL;
9595796c8dcSSimon Schubert int num_regs = gdbarch_num_regs (gdbarch);
9605796c8dcSSimon Schubert int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
9615796c8dcSSimon Schubert
9625796c8dcSSimon Schubert if (reg == NULL && regno >= num_regs && regno < num_regs + num_pseudo_regs)
9635796c8dcSSimon Schubert {
9645796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
965cf7f2e2dSJohn Marino
9665796c8dcSSimon Schubert gdb_assert (data->pseudo_register_type != NULL);
9675796c8dcSSimon Schubert return data->pseudo_register_type (gdbarch, regno);
9685796c8dcSSimon Schubert }
9695796c8dcSSimon Schubert
9705796c8dcSSimon Schubert if (reg == NULL)
9715796c8dcSSimon Schubert /* Return "int0_t", since "void" has a misleading size of one. */
9725796c8dcSSimon Schubert return builtin_type (gdbarch)->builtin_int0;
9735796c8dcSSimon Schubert
9745796c8dcSSimon Schubert if (arch_reg->type == NULL)
9755796c8dcSSimon Schubert {
9765796c8dcSSimon Schubert /* First check for a predefined or target defined type. */
9775796c8dcSSimon Schubert if (reg->tdesc_type)
9785796c8dcSSimon Schubert arch_reg->type = tdesc_gdb_type (gdbarch, reg->tdesc_type);
9795796c8dcSSimon Schubert
9805796c8dcSSimon Schubert /* Next try size-sensitive type shortcuts. */
9815796c8dcSSimon Schubert else if (strcmp (reg->type, "float") == 0)
9825796c8dcSSimon Schubert {
9835796c8dcSSimon Schubert if (reg->bitsize == gdbarch_float_bit (gdbarch))
9845796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_float;
9855796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_double_bit (gdbarch))
9865796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_double;
9875796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_long_double_bit (gdbarch))
9885796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_long_double;
9895796c8dcSSimon Schubert else
9905796c8dcSSimon Schubert {
9915796c8dcSSimon Schubert warning (_("Register \"%s\" has an unsupported size (%d bits)"),
9925796c8dcSSimon Schubert reg->name, reg->bitsize);
9935796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_double;
9945796c8dcSSimon Schubert }
9955796c8dcSSimon Schubert }
9965796c8dcSSimon Schubert else if (strcmp (reg->type, "int") == 0)
9975796c8dcSSimon Schubert {
9985796c8dcSSimon Schubert if (reg->bitsize == gdbarch_long_bit (gdbarch))
9995796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_long;
10005796c8dcSSimon Schubert else if (reg->bitsize == TARGET_CHAR_BIT)
10015796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_char;
10025796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_short_bit (gdbarch))
10035796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_short;
10045796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_int_bit (gdbarch))
10055796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_int;
10065796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_long_long_bit (gdbarch))
10075796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_long_long;
10085796c8dcSSimon Schubert else if (reg->bitsize == gdbarch_ptr_bit (gdbarch))
10095796c8dcSSimon Schubert /* A bit desperate by this point... */
10105796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_data_ptr;
10115796c8dcSSimon Schubert else
10125796c8dcSSimon Schubert {
10135796c8dcSSimon Schubert warning (_("Register \"%s\" has an unsupported size (%d bits)"),
10145796c8dcSSimon Schubert reg->name, reg->bitsize);
10155796c8dcSSimon Schubert arch_reg->type = builtin_type (gdbarch)->builtin_long;
10165796c8dcSSimon Schubert }
10175796c8dcSSimon Schubert }
10185796c8dcSSimon Schubert
10195796c8dcSSimon Schubert if (arch_reg->type == NULL)
10205796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
10215796c8dcSSimon Schubert "Register \"%s\" has an unknown type \"%s\"",
10225796c8dcSSimon Schubert reg->name, reg->type);
10235796c8dcSSimon Schubert }
10245796c8dcSSimon Schubert
10255796c8dcSSimon Schubert return arch_reg->type;
10265796c8dcSSimon Schubert }
10275796c8dcSSimon Schubert
10285796c8dcSSimon Schubert static int
tdesc_remote_register_number(struct gdbarch * gdbarch,int regno)10295796c8dcSSimon Schubert tdesc_remote_register_number (struct gdbarch *gdbarch, int regno)
10305796c8dcSSimon Schubert {
10315796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
10325796c8dcSSimon Schubert
10335796c8dcSSimon Schubert if (reg != NULL)
10345796c8dcSSimon Schubert return reg->target_regnum;
10355796c8dcSSimon Schubert else
10365796c8dcSSimon Schubert return -1;
10375796c8dcSSimon Schubert }
10385796c8dcSSimon Schubert
10395796c8dcSSimon Schubert /* Check whether REGNUM is a member of REGGROUP. Registers from the
10405796c8dcSSimon Schubert target description may be classified as general, float, or vector.
10415796c8dcSSimon Schubert Unlike a gdbarch register_reggroup_p method, this function will
10425796c8dcSSimon Schubert return -1 if it does not know; the caller should handle registers
10435796c8dcSSimon Schubert with no specified group.
10445796c8dcSSimon Schubert
10455796c8dcSSimon Schubert Arbitrary strings (other than "general", "float", and "vector")
10465796c8dcSSimon Schubert from the description are not used; they cause the register to be
10475796c8dcSSimon Schubert displayed in "info all-registers" but excluded from "info
10485796c8dcSSimon Schubert registers" et al. The names of containing features are also not
10495796c8dcSSimon Schubert used. This might be extended to display registers in some more
10505796c8dcSSimon Schubert useful groupings.
10515796c8dcSSimon Schubert
10525796c8dcSSimon Schubert The save-restore flag is also implemented here. */
10535796c8dcSSimon Schubert
10545796c8dcSSimon Schubert int
tdesc_register_in_reggroup_p(struct gdbarch * gdbarch,int regno,struct reggroup * reggroup)10555796c8dcSSimon Schubert tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
10565796c8dcSSimon Schubert struct reggroup *reggroup)
10575796c8dcSSimon Schubert {
10585796c8dcSSimon Schubert struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
10595796c8dcSSimon Schubert
10605796c8dcSSimon Schubert if (reg != NULL && reg->group != NULL)
10615796c8dcSSimon Schubert {
10625796c8dcSSimon Schubert int general_p = 0, float_p = 0, vector_p = 0;
10635796c8dcSSimon Schubert
10645796c8dcSSimon Schubert if (strcmp (reg->group, "general") == 0)
10655796c8dcSSimon Schubert general_p = 1;
10665796c8dcSSimon Schubert else if (strcmp (reg->group, "float") == 0)
10675796c8dcSSimon Schubert float_p = 1;
10685796c8dcSSimon Schubert else if (strcmp (reg->group, "vector") == 0)
10695796c8dcSSimon Schubert vector_p = 1;
10705796c8dcSSimon Schubert
10715796c8dcSSimon Schubert if (reggroup == float_reggroup)
10725796c8dcSSimon Schubert return float_p;
10735796c8dcSSimon Schubert
10745796c8dcSSimon Schubert if (reggroup == vector_reggroup)
10755796c8dcSSimon Schubert return vector_p;
10765796c8dcSSimon Schubert
10775796c8dcSSimon Schubert if (reggroup == general_reggroup)
10785796c8dcSSimon Schubert return general_p;
10795796c8dcSSimon Schubert }
10805796c8dcSSimon Schubert
10815796c8dcSSimon Schubert if (reg != NULL
10825796c8dcSSimon Schubert && (reggroup == save_reggroup || reggroup == restore_reggroup))
10835796c8dcSSimon Schubert return reg->save_restore;
10845796c8dcSSimon Schubert
10855796c8dcSSimon Schubert return -1;
10865796c8dcSSimon Schubert }
10875796c8dcSSimon Schubert
10885796c8dcSSimon Schubert /* Check whether REGNUM is a member of REGGROUP. Registers with no
10895796c8dcSSimon Schubert group specified go to the default reggroup function and are handled
10905796c8dcSSimon Schubert by type. */
10915796c8dcSSimon Schubert
10925796c8dcSSimon Schubert static int
tdesc_register_reggroup_p(struct gdbarch * gdbarch,int regno,struct reggroup * reggroup)10935796c8dcSSimon Schubert tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regno,
10945796c8dcSSimon Schubert struct reggroup *reggroup)
10955796c8dcSSimon Schubert {
10965796c8dcSSimon Schubert int num_regs = gdbarch_num_regs (gdbarch);
10975796c8dcSSimon Schubert int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
10985796c8dcSSimon Schubert int ret;
10995796c8dcSSimon Schubert
11005796c8dcSSimon Schubert if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
11015796c8dcSSimon Schubert {
11025796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
1103cf7f2e2dSJohn Marino
11045796c8dcSSimon Schubert if (data->pseudo_register_reggroup_p != NULL)
11055796c8dcSSimon Schubert return data->pseudo_register_reggroup_p (gdbarch, regno, reggroup);
11065796c8dcSSimon Schubert /* Otherwise fall through to the default reggroup_p. */
11075796c8dcSSimon Schubert }
11085796c8dcSSimon Schubert
11095796c8dcSSimon Schubert ret = tdesc_register_in_reggroup_p (gdbarch, regno, reggroup);
11105796c8dcSSimon Schubert if (ret != -1)
11115796c8dcSSimon Schubert return ret;
11125796c8dcSSimon Schubert
11135796c8dcSSimon Schubert return default_register_reggroup_p (gdbarch, regno, reggroup);
11145796c8dcSSimon Schubert }
11155796c8dcSSimon Schubert
11165796c8dcSSimon Schubert /* Record architecture-specific functions to call for pseudo-register
11175796c8dcSSimon Schubert support. */
11185796c8dcSSimon Schubert
11195796c8dcSSimon Schubert void
set_tdesc_pseudo_register_name(struct gdbarch * gdbarch,gdbarch_register_name_ftype * pseudo_name)11205796c8dcSSimon Schubert set_tdesc_pseudo_register_name (struct gdbarch *gdbarch,
11215796c8dcSSimon Schubert gdbarch_register_name_ftype *pseudo_name)
11225796c8dcSSimon Schubert {
11235796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
11245796c8dcSSimon Schubert
11255796c8dcSSimon Schubert data->pseudo_register_name = pseudo_name;
11265796c8dcSSimon Schubert }
11275796c8dcSSimon Schubert
11285796c8dcSSimon Schubert void
set_tdesc_pseudo_register_type(struct gdbarch * gdbarch,gdbarch_register_type_ftype * pseudo_type)11295796c8dcSSimon Schubert set_tdesc_pseudo_register_type (struct gdbarch *gdbarch,
11305796c8dcSSimon Schubert gdbarch_register_type_ftype *pseudo_type)
11315796c8dcSSimon Schubert {
11325796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
11335796c8dcSSimon Schubert
11345796c8dcSSimon Schubert data->pseudo_register_type = pseudo_type;
11355796c8dcSSimon Schubert }
11365796c8dcSSimon Schubert
11375796c8dcSSimon Schubert void
set_tdesc_pseudo_register_reggroup_p(struct gdbarch * gdbarch,gdbarch_register_reggroup_p_ftype * pseudo_reggroup_p)11385796c8dcSSimon Schubert set_tdesc_pseudo_register_reggroup_p
11395796c8dcSSimon Schubert (struct gdbarch *gdbarch,
11405796c8dcSSimon Schubert gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p)
11415796c8dcSSimon Schubert {
11425796c8dcSSimon Schubert struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
11435796c8dcSSimon Schubert
11445796c8dcSSimon Schubert data->pseudo_register_reggroup_p = pseudo_reggroup_p;
11455796c8dcSSimon Schubert }
11465796c8dcSSimon Schubert
11475796c8dcSSimon Schubert /* Update GDBARCH to use the target description for registers. */
11485796c8dcSSimon Schubert
11495796c8dcSSimon Schubert void
tdesc_use_registers(struct gdbarch * gdbarch,const struct target_desc * target_desc,struct tdesc_arch_data * early_data)11505796c8dcSSimon Schubert tdesc_use_registers (struct gdbarch *gdbarch,
11515796c8dcSSimon Schubert const struct target_desc *target_desc,
11525796c8dcSSimon Schubert struct tdesc_arch_data *early_data)
11535796c8dcSSimon Schubert {
11545796c8dcSSimon Schubert int num_regs = gdbarch_num_regs (gdbarch);
1155cf7f2e2dSJohn Marino int ixf, ixr;
11565796c8dcSSimon Schubert struct tdesc_feature *feature;
11575796c8dcSSimon Schubert struct tdesc_reg *reg;
11585796c8dcSSimon Schubert struct tdesc_arch_data *data;
11595796c8dcSSimon Schubert struct tdesc_arch_reg *arch_reg, new_arch_reg = { 0 };
11605796c8dcSSimon Schubert htab_t reg_hash;
11615796c8dcSSimon Schubert
11625796c8dcSSimon Schubert /* We can't use the description for registers if it doesn't describe
11635796c8dcSSimon Schubert any. This function should only be called after validating
11645796c8dcSSimon Schubert registers, so the caller should know that registers are
11655796c8dcSSimon Schubert included. */
11665796c8dcSSimon Schubert gdb_assert (tdesc_has_registers (target_desc));
11675796c8dcSSimon Schubert
11685796c8dcSSimon Schubert data = gdbarch_data (gdbarch, tdesc_data);
11695796c8dcSSimon Schubert data->arch_regs = early_data->arch_regs;
11705796c8dcSSimon Schubert xfree (early_data);
11715796c8dcSSimon Schubert
11725796c8dcSSimon Schubert /* Build up a set of all registers, so that we can assign register
11735796c8dcSSimon Schubert numbers where needed. The hash table expands as necessary, so
11745796c8dcSSimon Schubert the initial size is arbitrary. */
11755796c8dcSSimon Schubert reg_hash = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
11765796c8dcSSimon Schubert for (ixf = 0;
11775796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
11785796c8dcSSimon Schubert ixf++)
11795796c8dcSSimon Schubert for (ixr = 0;
11805796c8dcSSimon Schubert VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
11815796c8dcSSimon Schubert ixr++)
11825796c8dcSSimon Schubert {
11835796c8dcSSimon Schubert void **slot = htab_find_slot (reg_hash, reg, INSERT);
11845796c8dcSSimon Schubert
11855796c8dcSSimon Schubert *slot = reg;
11865796c8dcSSimon Schubert }
11875796c8dcSSimon Schubert
11885796c8dcSSimon Schubert /* Remove any registers which were assigned numbers by the
11895796c8dcSSimon Schubert architecture. */
11905796c8dcSSimon Schubert for (ixr = 0;
11915796c8dcSSimon Schubert VEC_iterate (tdesc_arch_reg, data->arch_regs, ixr, arch_reg);
11925796c8dcSSimon Schubert ixr++)
11935796c8dcSSimon Schubert if (arch_reg->reg)
11945796c8dcSSimon Schubert htab_remove_elt (reg_hash, arch_reg->reg);
11955796c8dcSSimon Schubert
11965796c8dcSSimon Schubert /* Assign numbers to the remaining registers and add them to the
11975796c8dcSSimon Schubert list of registers. The new numbers are always above gdbarch_num_regs.
11985796c8dcSSimon Schubert Iterate over the features, not the hash table, so that the order
11995796c8dcSSimon Schubert matches that in the target description. */
12005796c8dcSSimon Schubert
12015796c8dcSSimon Schubert gdb_assert (VEC_length (tdesc_arch_reg, data->arch_regs) <= num_regs);
12025796c8dcSSimon Schubert while (VEC_length (tdesc_arch_reg, data->arch_regs) < num_regs)
12035796c8dcSSimon Schubert VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
12045796c8dcSSimon Schubert for (ixf = 0;
12055796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
12065796c8dcSSimon Schubert ixf++)
12075796c8dcSSimon Schubert for (ixr = 0;
12085796c8dcSSimon Schubert VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
12095796c8dcSSimon Schubert ixr++)
12105796c8dcSSimon Schubert if (htab_find (reg_hash, reg) != NULL)
12115796c8dcSSimon Schubert {
12125796c8dcSSimon Schubert new_arch_reg.reg = reg;
12135796c8dcSSimon Schubert VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
12145796c8dcSSimon Schubert num_regs++;
12155796c8dcSSimon Schubert }
12165796c8dcSSimon Schubert
12175796c8dcSSimon Schubert htab_delete (reg_hash);
12185796c8dcSSimon Schubert
12195796c8dcSSimon Schubert /* Update the architecture. */
12205796c8dcSSimon Schubert set_gdbarch_num_regs (gdbarch, num_regs);
12215796c8dcSSimon Schubert set_gdbarch_register_name (gdbarch, tdesc_register_name);
12225796c8dcSSimon Schubert set_gdbarch_register_type (gdbarch, tdesc_register_type);
12235796c8dcSSimon Schubert set_gdbarch_remote_register_number (gdbarch,
12245796c8dcSSimon Schubert tdesc_remote_register_number);
12255796c8dcSSimon Schubert set_gdbarch_register_reggroup_p (gdbarch, tdesc_register_reggroup_p);
12265796c8dcSSimon Schubert }
12275796c8dcSSimon Schubert
12285796c8dcSSimon Schubert
12295796c8dcSSimon Schubert /* Methods for constructing a target description. */
12305796c8dcSSimon Schubert
12315796c8dcSSimon Schubert static void
tdesc_free_reg(struct tdesc_reg * reg)12325796c8dcSSimon Schubert tdesc_free_reg (struct tdesc_reg *reg)
12335796c8dcSSimon Schubert {
12345796c8dcSSimon Schubert xfree (reg->name);
12355796c8dcSSimon Schubert xfree (reg->type);
12365796c8dcSSimon Schubert xfree (reg->group);
12375796c8dcSSimon Schubert xfree (reg);
12385796c8dcSSimon Schubert }
12395796c8dcSSimon Schubert
12405796c8dcSSimon Schubert void
tdesc_create_reg(struct tdesc_feature * feature,const char * name,int regnum,int save_restore,const char * group,int bitsize,const char * type)12415796c8dcSSimon Schubert tdesc_create_reg (struct tdesc_feature *feature, const char *name,
12425796c8dcSSimon Schubert int regnum, int save_restore, const char *group,
12435796c8dcSSimon Schubert int bitsize, const char *type)
12445796c8dcSSimon Schubert {
12455796c8dcSSimon Schubert struct tdesc_reg *reg = XZALLOC (struct tdesc_reg);
12465796c8dcSSimon Schubert
12475796c8dcSSimon Schubert reg->name = xstrdup (name);
12485796c8dcSSimon Schubert reg->target_regnum = regnum;
12495796c8dcSSimon Schubert reg->save_restore = save_restore;
12505796c8dcSSimon Schubert reg->group = group ? xstrdup (group) : NULL;
12515796c8dcSSimon Schubert reg->bitsize = bitsize;
12525796c8dcSSimon Schubert reg->type = type ? xstrdup (type) : xstrdup ("<unknown>");
12535796c8dcSSimon Schubert
12545796c8dcSSimon Schubert /* If the register's type is target-defined, look it up now. We may not
12555796c8dcSSimon Schubert have easy access to the containing feature when we want it later. */
12565796c8dcSSimon Schubert reg->tdesc_type = tdesc_named_type (feature, reg->type);
12575796c8dcSSimon Schubert
12585796c8dcSSimon Schubert VEC_safe_push (tdesc_reg_p, feature->registers, reg);
12595796c8dcSSimon Schubert }
12605796c8dcSSimon Schubert
12615796c8dcSSimon Schubert static void
tdesc_free_type(struct tdesc_type * type)12625796c8dcSSimon Schubert tdesc_free_type (struct tdesc_type *type)
12635796c8dcSSimon Schubert {
12645796c8dcSSimon Schubert switch (type->kind)
12655796c8dcSSimon Schubert {
1266cf7f2e2dSJohn Marino case TDESC_TYPE_STRUCT:
12675796c8dcSSimon Schubert case TDESC_TYPE_UNION:
12685796c8dcSSimon Schubert {
12695796c8dcSSimon Schubert struct tdesc_type_field *f;
12705796c8dcSSimon Schubert int ix;
12715796c8dcSSimon Schubert
12725796c8dcSSimon Schubert for (ix = 0;
12735796c8dcSSimon Schubert VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f);
12745796c8dcSSimon Schubert ix++)
12755796c8dcSSimon Schubert xfree (f->name);
12765796c8dcSSimon Schubert
12775796c8dcSSimon Schubert VEC_free (tdesc_type_field, type->u.u.fields);
12785796c8dcSSimon Schubert }
12795796c8dcSSimon Schubert break;
12805796c8dcSSimon Schubert
1281cf7f2e2dSJohn Marino case TDESC_TYPE_FLAGS:
1282cf7f2e2dSJohn Marino {
1283cf7f2e2dSJohn Marino struct tdesc_type_flag *f;
1284cf7f2e2dSJohn Marino int ix;
1285cf7f2e2dSJohn Marino
1286cf7f2e2dSJohn Marino for (ix = 0;
1287cf7f2e2dSJohn Marino VEC_iterate (tdesc_type_flag, type->u.f.flags, ix, f);
1288cf7f2e2dSJohn Marino ix++)
1289cf7f2e2dSJohn Marino xfree (f->name);
1290cf7f2e2dSJohn Marino
1291cf7f2e2dSJohn Marino VEC_free (tdesc_type_flag, type->u.f.flags);
1292cf7f2e2dSJohn Marino }
1293cf7f2e2dSJohn Marino break;
1294cf7f2e2dSJohn Marino
12955796c8dcSSimon Schubert default:
12965796c8dcSSimon Schubert break;
12975796c8dcSSimon Schubert }
12985796c8dcSSimon Schubert
12995796c8dcSSimon Schubert xfree (type->name);
13005796c8dcSSimon Schubert xfree (type);
13015796c8dcSSimon Schubert }
13025796c8dcSSimon Schubert
13035796c8dcSSimon Schubert struct tdesc_type *
tdesc_create_vector(struct tdesc_feature * feature,const char * name,struct tdesc_type * field_type,int count)13045796c8dcSSimon Schubert tdesc_create_vector (struct tdesc_feature *feature, const char *name,
13055796c8dcSSimon Schubert struct tdesc_type *field_type, int count)
13065796c8dcSSimon Schubert {
13075796c8dcSSimon Schubert struct tdesc_type *type = XZALLOC (struct tdesc_type);
13085796c8dcSSimon Schubert
13095796c8dcSSimon Schubert type->name = xstrdup (name);
13105796c8dcSSimon Schubert type->kind = TDESC_TYPE_VECTOR;
13115796c8dcSSimon Schubert type->u.v.type = field_type;
13125796c8dcSSimon Schubert type->u.v.count = count;
13135796c8dcSSimon Schubert
13145796c8dcSSimon Schubert VEC_safe_push (tdesc_type_p, feature->types, type);
13155796c8dcSSimon Schubert return type;
13165796c8dcSSimon Schubert }
13175796c8dcSSimon Schubert
13185796c8dcSSimon Schubert struct tdesc_type *
tdesc_create_struct(struct tdesc_feature * feature,const char * name)1319cf7f2e2dSJohn Marino tdesc_create_struct (struct tdesc_feature *feature, const char *name)
1320cf7f2e2dSJohn Marino {
1321cf7f2e2dSJohn Marino struct tdesc_type *type = XZALLOC (struct tdesc_type);
1322cf7f2e2dSJohn Marino
1323cf7f2e2dSJohn Marino type->name = xstrdup (name);
1324cf7f2e2dSJohn Marino type->kind = TDESC_TYPE_STRUCT;
1325cf7f2e2dSJohn Marino
1326cf7f2e2dSJohn Marino VEC_safe_push (tdesc_type_p, feature->types, type);
1327cf7f2e2dSJohn Marino return type;
1328cf7f2e2dSJohn Marino }
1329cf7f2e2dSJohn Marino
1330cf7f2e2dSJohn Marino /* Set the total length of TYPE. Structs which contain bitfields may
1331cf7f2e2dSJohn Marino omit the reserved bits, so the end of the last field may not
1332cf7f2e2dSJohn Marino suffice. */
1333cf7f2e2dSJohn Marino
1334cf7f2e2dSJohn Marino void
tdesc_set_struct_size(struct tdesc_type * type,LONGEST size)1335cf7f2e2dSJohn Marino tdesc_set_struct_size (struct tdesc_type *type, LONGEST size)
1336cf7f2e2dSJohn Marino {
1337cf7f2e2dSJohn Marino gdb_assert (type->kind == TDESC_TYPE_STRUCT);
1338cf7f2e2dSJohn Marino type->u.u.size = size;
1339cf7f2e2dSJohn Marino }
1340cf7f2e2dSJohn Marino
1341cf7f2e2dSJohn Marino struct tdesc_type *
tdesc_create_union(struct tdesc_feature * feature,const char * name)13425796c8dcSSimon Schubert tdesc_create_union (struct tdesc_feature *feature, const char *name)
13435796c8dcSSimon Schubert {
13445796c8dcSSimon Schubert struct tdesc_type *type = XZALLOC (struct tdesc_type);
13455796c8dcSSimon Schubert
13465796c8dcSSimon Schubert type->name = xstrdup (name);
13475796c8dcSSimon Schubert type->kind = TDESC_TYPE_UNION;
13485796c8dcSSimon Schubert
13495796c8dcSSimon Schubert VEC_safe_push (tdesc_type_p, feature->types, type);
13505796c8dcSSimon Schubert return type;
13515796c8dcSSimon Schubert }
13525796c8dcSSimon Schubert
1353cf7f2e2dSJohn Marino struct tdesc_type *
tdesc_create_flags(struct tdesc_feature * feature,const char * name,LONGEST size)1354cf7f2e2dSJohn Marino tdesc_create_flags (struct tdesc_feature *feature, const char *name,
1355cf7f2e2dSJohn Marino LONGEST size)
1356cf7f2e2dSJohn Marino {
1357cf7f2e2dSJohn Marino struct tdesc_type *type = XZALLOC (struct tdesc_type);
1358cf7f2e2dSJohn Marino
1359cf7f2e2dSJohn Marino type->name = xstrdup (name);
1360cf7f2e2dSJohn Marino type->kind = TDESC_TYPE_FLAGS;
1361cf7f2e2dSJohn Marino type->u.f.size = size;
1362cf7f2e2dSJohn Marino
1363cf7f2e2dSJohn Marino VEC_safe_push (tdesc_type_p, feature->types, type);
1364cf7f2e2dSJohn Marino return type;
1365cf7f2e2dSJohn Marino }
1366cf7f2e2dSJohn Marino
1367cf7f2e2dSJohn Marino /* Add a new field. Return a temporary pointer to the field, which
1368cf7f2e2dSJohn Marino is only valid until the next call to tdesc_add_field (the vector
1369cf7f2e2dSJohn Marino might be reallocated). */
1370cf7f2e2dSJohn Marino
13715796c8dcSSimon Schubert void
tdesc_add_field(struct tdesc_type * type,const char * field_name,struct tdesc_type * field_type)13725796c8dcSSimon Schubert tdesc_add_field (struct tdesc_type *type, const char *field_name,
13735796c8dcSSimon Schubert struct tdesc_type *field_type)
13745796c8dcSSimon Schubert {
13755796c8dcSSimon Schubert struct tdesc_type_field f = { 0 };
13765796c8dcSSimon Schubert
1377cf7f2e2dSJohn Marino gdb_assert (type->kind == TDESC_TYPE_UNION
1378cf7f2e2dSJohn Marino || type->kind == TDESC_TYPE_STRUCT);
13795796c8dcSSimon Schubert
13805796c8dcSSimon Schubert f.name = xstrdup (field_name);
13815796c8dcSSimon Schubert f.type = field_type;
13825796c8dcSSimon Schubert
13835796c8dcSSimon Schubert VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
13845796c8dcSSimon Schubert }
13855796c8dcSSimon Schubert
1386cf7f2e2dSJohn Marino /* Add a new bitfield. */
1387cf7f2e2dSJohn Marino
1388cf7f2e2dSJohn Marino void
tdesc_add_bitfield(struct tdesc_type * type,const char * field_name,int start,int end)1389cf7f2e2dSJohn Marino tdesc_add_bitfield (struct tdesc_type *type, const char *field_name,
1390cf7f2e2dSJohn Marino int start, int end)
1391cf7f2e2dSJohn Marino {
1392cf7f2e2dSJohn Marino struct tdesc_type_field f = { 0 };
1393cf7f2e2dSJohn Marino
1394cf7f2e2dSJohn Marino gdb_assert (type->kind == TDESC_TYPE_STRUCT);
1395cf7f2e2dSJohn Marino
1396cf7f2e2dSJohn Marino f.name = xstrdup (field_name);
1397cf7f2e2dSJohn Marino f.start = start;
1398cf7f2e2dSJohn Marino f.end = end;
1399cf7f2e2dSJohn Marino
1400cf7f2e2dSJohn Marino VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1401cf7f2e2dSJohn Marino }
1402cf7f2e2dSJohn Marino
1403cf7f2e2dSJohn Marino void
tdesc_add_flag(struct tdesc_type * type,int start,const char * flag_name)1404cf7f2e2dSJohn Marino tdesc_add_flag (struct tdesc_type *type, int start,
1405cf7f2e2dSJohn Marino const char *flag_name)
1406cf7f2e2dSJohn Marino {
1407cf7f2e2dSJohn Marino struct tdesc_type_flag f = { 0 };
1408cf7f2e2dSJohn Marino
1409cf7f2e2dSJohn Marino gdb_assert (type->kind == TDESC_TYPE_FLAGS);
1410cf7f2e2dSJohn Marino
1411cf7f2e2dSJohn Marino f.name = xstrdup (flag_name);
1412cf7f2e2dSJohn Marino f.start = start;
1413cf7f2e2dSJohn Marino
1414cf7f2e2dSJohn Marino VEC_safe_push (tdesc_type_flag, type->u.f.flags, &f);
1415cf7f2e2dSJohn Marino }
1416cf7f2e2dSJohn Marino
14175796c8dcSSimon Schubert static void
tdesc_free_feature(struct tdesc_feature * feature)14185796c8dcSSimon Schubert tdesc_free_feature (struct tdesc_feature *feature)
14195796c8dcSSimon Schubert {
14205796c8dcSSimon Schubert struct tdesc_reg *reg;
14215796c8dcSSimon Schubert struct tdesc_type *type;
14225796c8dcSSimon Schubert int ix;
14235796c8dcSSimon Schubert
14245796c8dcSSimon Schubert for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++)
14255796c8dcSSimon Schubert tdesc_free_reg (reg);
14265796c8dcSSimon Schubert VEC_free (tdesc_reg_p, feature->registers);
14275796c8dcSSimon Schubert
14285796c8dcSSimon Schubert for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
14295796c8dcSSimon Schubert tdesc_free_type (type);
14305796c8dcSSimon Schubert VEC_free (tdesc_type_p, feature->types);
14315796c8dcSSimon Schubert
14325796c8dcSSimon Schubert xfree (feature->name);
14335796c8dcSSimon Schubert xfree (feature);
14345796c8dcSSimon Schubert }
14355796c8dcSSimon Schubert
14365796c8dcSSimon Schubert struct tdesc_feature *
tdesc_create_feature(struct target_desc * tdesc,const char * name)14375796c8dcSSimon Schubert tdesc_create_feature (struct target_desc *tdesc, const char *name)
14385796c8dcSSimon Schubert {
14395796c8dcSSimon Schubert struct tdesc_feature *new_feature = XZALLOC (struct tdesc_feature);
14405796c8dcSSimon Schubert
14415796c8dcSSimon Schubert new_feature->name = xstrdup (name);
14425796c8dcSSimon Schubert
14435796c8dcSSimon Schubert VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature);
14445796c8dcSSimon Schubert return new_feature;
14455796c8dcSSimon Schubert }
14465796c8dcSSimon Schubert
14475796c8dcSSimon Schubert struct target_desc *
allocate_target_description(void)14485796c8dcSSimon Schubert allocate_target_description (void)
14495796c8dcSSimon Schubert {
14505796c8dcSSimon Schubert return XZALLOC (struct target_desc);
14515796c8dcSSimon Schubert }
14525796c8dcSSimon Schubert
14535796c8dcSSimon Schubert static void
free_target_description(void * arg)14545796c8dcSSimon Schubert free_target_description (void *arg)
14555796c8dcSSimon Schubert {
14565796c8dcSSimon Schubert struct target_desc *target_desc = arg;
14575796c8dcSSimon Schubert struct tdesc_feature *feature;
14585796c8dcSSimon Schubert struct property *prop;
14595796c8dcSSimon Schubert int ix;
14605796c8dcSSimon Schubert
14615796c8dcSSimon Schubert for (ix = 0;
14625796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
14635796c8dcSSimon Schubert ix++)
14645796c8dcSSimon Schubert tdesc_free_feature (feature);
14655796c8dcSSimon Schubert VEC_free (tdesc_feature_p, target_desc->features);
14665796c8dcSSimon Schubert
14675796c8dcSSimon Schubert for (ix = 0;
14685796c8dcSSimon Schubert VEC_iterate (property_s, target_desc->properties, ix, prop);
14695796c8dcSSimon Schubert ix++)
14705796c8dcSSimon Schubert {
14715796c8dcSSimon Schubert xfree (prop->key);
14725796c8dcSSimon Schubert xfree (prop->value);
14735796c8dcSSimon Schubert }
14745796c8dcSSimon Schubert VEC_free (property_s, target_desc->properties);
14755796c8dcSSimon Schubert
14765796c8dcSSimon Schubert VEC_free (arch_p, target_desc->compatible);
14775796c8dcSSimon Schubert
14785796c8dcSSimon Schubert xfree (target_desc);
14795796c8dcSSimon Schubert }
14805796c8dcSSimon Schubert
14815796c8dcSSimon Schubert struct cleanup *
make_cleanup_free_target_description(struct target_desc * target_desc)14825796c8dcSSimon Schubert make_cleanup_free_target_description (struct target_desc *target_desc)
14835796c8dcSSimon Schubert {
14845796c8dcSSimon Schubert return make_cleanup (free_target_description, target_desc);
14855796c8dcSSimon Schubert }
14865796c8dcSSimon Schubert
14875796c8dcSSimon Schubert void
tdesc_add_compatible(struct target_desc * target_desc,const struct bfd_arch_info * compatible)14885796c8dcSSimon Schubert tdesc_add_compatible (struct target_desc *target_desc,
14895796c8dcSSimon Schubert const struct bfd_arch_info *compatible)
14905796c8dcSSimon Schubert {
14915796c8dcSSimon Schubert const struct bfd_arch_info *compat;
14925796c8dcSSimon Schubert int ix;
14935796c8dcSSimon Schubert
14945796c8dcSSimon Schubert /* If this instance of GDB is compiled without BFD support for the
14955796c8dcSSimon Schubert compatible architecture, simply ignore it -- we would not be able
14965796c8dcSSimon Schubert to handle it anyway. */
14975796c8dcSSimon Schubert if (compatible == NULL)
14985796c8dcSSimon Schubert return;
14995796c8dcSSimon Schubert
15005796c8dcSSimon Schubert for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
15015796c8dcSSimon Schubert ix++)
15025796c8dcSSimon Schubert if (compat == compatible)
15035796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
15045796c8dcSSimon Schubert _("Attempted to add duplicate "
15055796c8dcSSimon Schubert "compatible architecture \"%s\""),
15065796c8dcSSimon Schubert compatible->printable_name);
15075796c8dcSSimon Schubert
15085796c8dcSSimon Schubert VEC_safe_push (arch_p, target_desc->compatible, compatible);
15095796c8dcSSimon Schubert }
15105796c8dcSSimon Schubert
15115796c8dcSSimon Schubert void
set_tdesc_property(struct target_desc * target_desc,const char * key,const char * value)15125796c8dcSSimon Schubert set_tdesc_property (struct target_desc *target_desc,
15135796c8dcSSimon Schubert const char *key, const char *value)
15145796c8dcSSimon Schubert {
15155796c8dcSSimon Schubert struct property *prop, new_prop;
15165796c8dcSSimon Schubert int ix;
15175796c8dcSSimon Schubert
15185796c8dcSSimon Schubert gdb_assert (key != NULL && value != NULL);
15195796c8dcSSimon Schubert
15205796c8dcSSimon Schubert for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
15215796c8dcSSimon Schubert ix++)
15225796c8dcSSimon Schubert if (strcmp (prop->key, key) == 0)
15235796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
15245796c8dcSSimon Schubert _("Attempted to add duplicate property \"%s\""), key);
15255796c8dcSSimon Schubert
15265796c8dcSSimon Schubert new_prop.key = xstrdup (key);
15275796c8dcSSimon Schubert new_prop.value = xstrdup (value);
15285796c8dcSSimon Schubert VEC_safe_push (property_s, target_desc->properties, &new_prop);
15295796c8dcSSimon Schubert }
15305796c8dcSSimon Schubert
15315796c8dcSSimon Schubert void
set_tdesc_architecture(struct target_desc * target_desc,const struct bfd_arch_info * arch)15325796c8dcSSimon Schubert set_tdesc_architecture (struct target_desc *target_desc,
15335796c8dcSSimon Schubert const struct bfd_arch_info *arch)
15345796c8dcSSimon Schubert {
15355796c8dcSSimon Schubert target_desc->arch = arch;
15365796c8dcSSimon Schubert }
15375796c8dcSSimon Schubert
15385796c8dcSSimon Schubert void
set_tdesc_osabi(struct target_desc * target_desc,enum gdb_osabi osabi)15395796c8dcSSimon Schubert set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
15405796c8dcSSimon Schubert {
15415796c8dcSSimon Schubert target_desc->osabi = osabi;
15425796c8dcSSimon Schubert }
15435796c8dcSSimon Schubert
15445796c8dcSSimon Schubert
15455796c8dcSSimon Schubert static struct cmd_list_element *tdesc_set_cmdlist, *tdesc_show_cmdlist;
15465796c8dcSSimon Schubert static struct cmd_list_element *tdesc_unset_cmdlist;
15475796c8dcSSimon Schubert
15485796c8dcSSimon Schubert /* Helper functions for the CLI commands. */
15495796c8dcSSimon Schubert
15505796c8dcSSimon Schubert static void
set_tdesc_cmd(char * args,int from_tty)15515796c8dcSSimon Schubert set_tdesc_cmd (char *args, int from_tty)
15525796c8dcSSimon Schubert {
15535796c8dcSSimon Schubert help_list (tdesc_set_cmdlist, "set tdesc ", -1, gdb_stdout);
15545796c8dcSSimon Schubert }
15555796c8dcSSimon Schubert
15565796c8dcSSimon Schubert static void
show_tdesc_cmd(char * args,int from_tty)15575796c8dcSSimon Schubert show_tdesc_cmd (char *args, int from_tty)
15585796c8dcSSimon Schubert {
15595796c8dcSSimon Schubert cmd_show_list (tdesc_show_cmdlist, from_tty, "");
15605796c8dcSSimon Schubert }
15615796c8dcSSimon Schubert
15625796c8dcSSimon Schubert static void
unset_tdesc_cmd(char * args,int from_tty)15635796c8dcSSimon Schubert unset_tdesc_cmd (char *args, int from_tty)
15645796c8dcSSimon Schubert {
15655796c8dcSSimon Schubert help_list (tdesc_unset_cmdlist, "unset tdesc ", -1, gdb_stdout);
15665796c8dcSSimon Schubert }
15675796c8dcSSimon Schubert
15685796c8dcSSimon Schubert static void
set_tdesc_filename_cmd(char * args,int from_tty,struct cmd_list_element * c)15695796c8dcSSimon Schubert set_tdesc_filename_cmd (char *args, int from_tty,
15705796c8dcSSimon Schubert struct cmd_list_element *c)
15715796c8dcSSimon Schubert {
1572*ef5ccd6cSJohn Marino xfree (target_description_filename);
1573*ef5ccd6cSJohn Marino target_description_filename = xstrdup (tdesc_filename_cmd_string);
1574*ef5ccd6cSJohn Marino
15755796c8dcSSimon Schubert target_clear_description ();
15765796c8dcSSimon Schubert target_find_description ();
15775796c8dcSSimon Schubert }
15785796c8dcSSimon Schubert
15795796c8dcSSimon Schubert static void
show_tdesc_filename_cmd(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)15805796c8dcSSimon Schubert show_tdesc_filename_cmd (struct ui_file *file, int from_tty,
15815796c8dcSSimon Schubert struct cmd_list_element *c,
15825796c8dcSSimon Schubert const char *value)
15835796c8dcSSimon Schubert {
1584*ef5ccd6cSJohn Marino value = target_description_filename;
1585*ef5ccd6cSJohn Marino
15865796c8dcSSimon Schubert if (value != NULL && *value != '\0')
1587c50c785cSJohn Marino printf_filtered (_("The target description will be read from \"%s\".\n"),
15885796c8dcSSimon Schubert value);
15895796c8dcSSimon Schubert else
1590c50c785cSJohn Marino printf_filtered (_("The target description will be "
1591c50c785cSJohn Marino "read from the target.\n"));
15925796c8dcSSimon Schubert }
15935796c8dcSSimon Schubert
15945796c8dcSSimon Schubert static void
unset_tdesc_filename_cmd(char * args,int from_tty)15955796c8dcSSimon Schubert unset_tdesc_filename_cmd (char *args, int from_tty)
15965796c8dcSSimon Schubert {
15975796c8dcSSimon Schubert xfree (target_description_filename);
15985796c8dcSSimon Schubert target_description_filename = NULL;
15995796c8dcSSimon Schubert target_clear_description ();
16005796c8dcSSimon Schubert target_find_description ();
16015796c8dcSSimon Schubert }
16025796c8dcSSimon Schubert
16035796c8dcSSimon Schubert static void
maint_print_c_tdesc_cmd(char * args,int from_tty)16045796c8dcSSimon Schubert maint_print_c_tdesc_cmd (char *args, int from_tty)
16055796c8dcSSimon Schubert {
16065796c8dcSSimon Schubert const struct target_desc *tdesc;
16075796c8dcSSimon Schubert const struct bfd_arch_info *compatible;
16085796c8dcSSimon Schubert const char *filename, *inp;
16095796c8dcSSimon Schubert char *function, *outp;
16105796c8dcSSimon Schubert struct property *prop;
16115796c8dcSSimon Schubert struct tdesc_feature *feature;
16125796c8dcSSimon Schubert struct tdesc_reg *reg;
16135796c8dcSSimon Schubert struct tdesc_type *type;
16145796c8dcSSimon Schubert struct tdesc_type_field *f;
1615cf7f2e2dSJohn Marino struct tdesc_type_flag *flag;
16165796c8dcSSimon Schubert int ix, ix2, ix3;
1617*ef5ccd6cSJohn Marino int printed_field_type = 0;
16185796c8dcSSimon Schubert
16195796c8dcSSimon Schubert /* Use the global target-supplied description, not the current
16205796c8dcSSimon Schubert architecture's. This lets a GDB for one architecture generate C
16215796c8dcSSimon Schubert for another architecture's description, even though the gdbarch
16225796c8dcSSimon Schubert initialization code will reject the new description. */
16235796c8dcSSimon Schubert tdesc = current_target_desc;
16245796c8dcSSimon Schubert if (tdesc == NULL)
16255796c8dcSSimon Schubert error (_("There is no target description to print."));
16265796c8dcSSimon Schubert
16275796c8dcSSimon Schubert if (target_description_filename == NULL)
16285796c8dcSSimon Schubert error (_("The current target description did not come from an XML file."));
16295796c8dcSSimon Schubert
16305796c8dcSSimon Schubert filename = lbasename (target_description_filename);
16315796c8dcSSimon Schubert function = alloca (strlen (filename) + 1);
16325796c8dcSSimon Schubert for (inp = filename, outp = function; *inp != '\0'; inp++)
16335796c8dcSSimon Schubert if (*inp == '.')
16345796c8dcSSimon Schubert break;
16355796c8dcSSimon Schubert else if (*inp == '-')
16365796c8dcSSimon Schubert *outp++ = '_';
16375796c8dcSSimon Schubert else
16385796c8dcSSimon Schubert *outp++ = *inp;
16395796c8dcSSimon Schubert *outp = '\0';
16405796c8dcSSimon Schubert
16415796c8dcSSimon Schubert /* Standard boilerplate. */
1642*ef5ccd6cSJohn Marino printf_unfiltered ("/* THIS FILE IS GENERATED. "
1643*ef5ccd6cSJohn Marino "-*- buffer-read-only: t -*- vi"
1644*ef5ccd6cSJohn Marino ":set ro:\n");
1645*ef5ccd6cSJohn Marino printf_unfiltered (" Original: %s */\n\n", filename);
16465796c8dcSSimon Schubert printf_unfiltered ("#include \"defs.h\"\n");
1647cf7f2e2dSJohn Marino printf_unfiltered ("#include \"osabi.h\"\n");
16485796c8dcSSimon Schubert printf_unfiltered ("#include \"target-descriptions.h\"\n");
16495796c8dcSSimon Schubert printf_unfiltered ("\n");
16505796c8dcSSimon Schubert
16515796c8dcSSimon Schubert printf_unfiltered ("struct target_desc *tdesc_%s;\n", function);
16525796c8dcSSimon Schubert printf_unfiltered ("static void\n");
16535796c8dcSSimon Schubert printf_unfiltered ("initialize_tdesc_%s (void)\n", function);
16545796c8dcSSimon Schubert printf_unfiltered ("{\n");
16555796c8dcSSimon Schubert printf_unfiltered
16565796c8dcSSimon Schubert (" struct target_desc *result = allocate_target_description ();\n");
16575796c8dcSSimon Schubert printf_unfiltered (" struct tdesc_feature *feature;\n");
1658*ef5ccd6cSJohn Marino
1659*ef5ccd6cSJohn Marino /* Now we do some "filtering" in order to know which variables to
1660*ef5ccd6cSJohn Marino declare. This is needed because otherwise we would declare unused
1661*ef5ccd6cSJohn Marino variables `field_type' and `type'. */
1662*ef5ccd6cSJohn Marino for (ix = 0;
1663*ef5ccd6cSJohn Marino VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
1664*ef5ccd6cSJohn Marino ix++)
1665*ef5ccd6cSJohn Marino {
1666*ef5ccd6cSJohn Marino int printed_desc_type = 0;
1667*ef5ccd6cSJohn Marino
1668*ef5ccd6cSJohn Marino for (ix2 = 0;
1669*ef5ccd6cSJohn Marino VEC_iterate (tdesc_type_p, feature->types, ix2, type);
1670*ef5ccd6cSJohn Marino ix2++)
1671*ef5ccd6cSJohn Marino {
1672*ef5ccd6cSJohn Marino if (!printed_field_type)
1673*ef5ccd6cSJohn Marino {
1674*ef5ccd6cSJohn Marino printf_unfiltered (" struct tdesc_type *field_type;\n");
1675*ef5ccd6cSJohn Marino printed_field_type = 1;
1676*ef5ccd6cSJohn Marino }
1677*ef5ccd6cSJohn Marino
1678*ef5ccd6cSJohn Marino if (type->kind == TDESC_TYPE_UNION
1679*ef5ccd6cSJohn Marino && VEC_length (tdesc_type_field, type->u.u.fields) > 0)
1680*ef5ccd6cSJohn Marino {
1681*ef5ccd6cSJohn Marino printf_unfiltered (" struct tdesc_type *type;\n");
1682*ef5ccd6cSJohn Marino printed_desc_type = 1;
1683*ef5ccd6cSJohn Marino break;
1684*ef5ccd6cSJohn Marino }
1685*ef5ccd6cSJohn Marino }
1686*ef5ccd6cSJohn Marino
1687*ef5ccd6cSJohn Marino if (printed_desc_type)
1688*ef5ccd6cSJohn Marino break;
1689*ef5ccd6cSJohn Marino }
1690*ef5ccd6cSJohn Marino
16915796c8dcSSimon Schubert printf_unfiltered ("\n");
16925796c8dcSSimon Schubert
16935796c8dcSSimon Schubert if (tdesc_architecture (tdesc) != NULL)
16945796c8dcSSimon Schubert {
16955796c8dcSSimon Schubert printf_unfiltered
16965796c8dcSSimon Schubert (" set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
16975796c8dcSSimon Schubert tdesc_architecture (tdesc)->printable_name);
16985796c8dcSSimon Schubert printf_unfiltered ("\n");
16995796c8dcSSimon Schubert }
17005796c8dcSSimon Schubert
1701cf7f2e2dSJohn Marino if (tdesc_osabi (tdesc) > GDB_OSABI_UNKNOWN
1702cf7f2e2dSJohn Marino && tdesc_osabi (tdesc) < GDB_OSABI_INVALID)
1703cf7f2e2dSJohn Marino {
1704cf7f2e2dSJohn Marino printf_unfiltered
1705cf7f2e2dSJohn Marino (" set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
1706cf7f2e2dSJohn Marino gdbarch_osabi_name (tdesc_osabi (tdesc)));
1707cf7f2e2dSJohn Marino printf_unfiltered ("\n");
1708cf7f2e2dSJohn Marino }
1709cf7f2e2dSJohn Marino
17105796c8dcSSimon Schubert for (ix = 0; VEC_iterate (arch_p, tdesc->compatible, ix, compatible);
17115796c8dcSSimon Schubert ix++)
17125796c8dcSSimon Schubert {
17135796c8dcSSimon Schubert printf_unfiltered
17145796c8dcSSimon Schubert (" tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
17155796c8dcSSimon Schubert compatible->printable_name);
17165796c8dcSSimon Schubert }
17175796c8dcSSimon Schubert if (ix)
17185796c8dcSSimon Schubert printf_unfiltered ("\n");
17195796c8dcSSimon Schubert
17205796c8dcSSimon Schubert for (ix = 0; VEC_iterate (property_s, tdesc->properties, ix, prop);
17215796c8dcSSimon Schubert ix++)
17225796c8dcSSimon Schubert {
17235796c8dcSSimon Schubert printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n",
17245796c8dcSSimon Schubert prop->key, prop->value);
17255796c8dcSSimon Schubert }
17265796c8dcSSimon Schubert
17275796c8dcSSimon Schubert for (ix = 0;
17285796c8dcSSimon Schubert VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
17295796c8dcSSimon Schubert ix++)
17305796c8dcSSimon Schubert {
1731c50c785cSJohn Marino printf_unfiltered (" \
1732c50c785cSJohn Marino feature = tdesc_create_feature (result, \"%s\");\n",
17335796c8dcSSimon Schubert feature->name);
17345796c8dcSSimon Schubert
17355796c8dcSSimon Schubert for (ix2 = 0;
17365796c8dcSSimon Schubert VEC_iterate (tdesc_type_p, feature->types, ix2, type);
17375796c8dcSSimon Schubert ix2++)
17385796c8dcSSimon Schubert {
17395796c8dcSSimon Schubert switch (type->kind)
17405796c8dcSSimon Schubert {
17415796c8dcSSimon Schubert case TDESC_TYPE_VECTOR:
17425796c8dcSSimon Schubert printf_unfiltered
17435796c8dcSSimon Schubert (" field_type = tdesc_named_type (feature, \"%s\");\n",
17445796c8dcSSimon Schubert type->u.v.type->name);
17455796c8dcSSimon Schubert printf_unfiltered
17465796c8dcSSimon Schubert (" tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
17475796c8dcSSimon Schubert type->name, type->u.v.count);
17485796c8dcSSimon Schubert break;
17495796c8dcSSimon Schubert case TDESC_TYPE_UNION:
17505796c8dcSSimon Schubert printf_unfiltered
17515796c8dcSSimon Schubert (" type = tdesc_create_union (feature, \"%s\");\n",
17525796c8dcSSimon Schubert type->name);
17535796c8dcSSimon Schubert for (ix3 = 0;
17545796c8dcSSimon Schubert VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
17555796c8dcSSimon Schubert ix3++)
17565796c8dcSSimon Schubert {
17575796c8dcSSimon Schubert printf_unfiltered
17585796c8dcSSimon Schubert (" field_type = tdesc_named_type (feature, \"%s\");\n",
17595796c8dcSSimon Schubert f->type->name);
17605796c8dcSSimon Schubert printf_unfiltered
17615796c8dcSSimon Schubert (" tdesc_add_field (type, \"%s\", field_type);\n",
17625796c8dcSSimon Schubert f->name);
17635796c8dcSSimon Schubert }
17645796c8dcSSimon Schubert break;
1765cf7f2e2dSJohn Marino case TDESC_TYPE_FLAGS:
1766cf7f2e2dSJohn Marino printf_unfiltered
1767cf7f2e2dSJohn Marino (" field_type = tdesc_create_flags (feature, \"%s\", %d);\n",
1768cf7f2e2dSJohn Marino type->name, (int) type->u.f.size);
1769cf7f2e2dSJohn Marino for (ix3 = 0;
1770cf7f2e2dSJohn Marino VEC_iterate (tdesc_type_flag, type->u.f.flags, ix3,
1771cf7f2e2dSJohn Marino flag);
1772cf7f2e2dSJohn Marino ix3++)
1773cf7f2e2dSJohn Marino printf_unfiltered
1774cf7f2e2dSJohn Marino (" tdesc_add_flag (field_type, %d, \"%s\");\n",
1775cf7f2e2dSJohn Marino flag->start, flag->name);
1776cf7f2e2dSJohn Marino break;
17775796c8dcSSimon Schubert default:
17785796c8dcSSimon Schubert error (_("C output is not supported type \"%s\"."), type->name);
17795796c8dcSSimon Schubert }
17805796c8dcSSimon Schubert printf_unfiltered ("\n");
17815796c8dcSSimon Schubert }
17825796c8dcSSimon Schubert
17835796c8dcSSimon Schubert for (ix2 = 0;
17845796c8dcSSimon Schubert VEC_iterate (tdesc_reg_p, feature->registers, ix2, reg);
17855796c8dcSSimon Schubert ix2++)
17865796c8dcSSimon Schubert {
17875796c8dcSSimon Schubert printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
17885796c8dcSSimon Schubert reg->name, reg->target_regnum, reg->save_restore);
17895796c8dcSSimon Schubert if (reg->group)
17905796c8dcSSimon Schubert printf_unfiltered ("\"%s\", ", reg->group);
17915796c8dcSSimon Schubert else
17925796c8dcSSimon Schubert printf_unfiltered ("NULL, ");
17935796c8dcSSimon Schubert printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
17945796c8dcSSimon Schubert }
17955796c8dcSSimon Schubert
17965796c8dcSSimon Schubert printf_unfiltered ("\n");
17975796c8dcSSimon Schubert }
17985796c8dcSSimon Schubert
17995796c8dcSSimon Schubert printf_unfiltered (" tdesc_%s = result;\n", function);
18005796c8dcSSimon Schubert printf_unfiltered ("}\n");
18015796c8dcSSimon Schubert }
18025796c8dcSSimon Schubert
18035796c8dcSSimon Schubert /* Provide a prototype to silence -Wmissing-prototypes. */
18045796c8dcSSimon Schubert extern initialize_file_ftype _initialize_target_descriptions;
18055796c8dcSSimon Schubert
18065796c8dcSSimon Schubert void
_initialize_target_descriptions(void)18075796c8dcSSimon Schubert _initialize_target_descriptions (void)
18085796c8dcSSimon Schubert {
18095796c8dcSSimon Schubert tdesc_data = gdbarch_data_register_pre_init (tdesc_data_init);
18105796c8dcSSimon Schubert
18115796c8dcSSimon Schubert add_prefix_cmd ("tdesc", class_maintenance, set_tdesc_cmd, _("\
18125796c8dcSSimon Schubert Set target description specific variables."),
18135796c8dcSSimon Schubert &tdesc_set_cmdlist, "set tdesc ",
18145796c8dcSSimon Schubert 0 /* allow-unknown */, &setlist);
18155796c8dcSSimon Schubert add_prefix_cmd ("tdesc", class_maintenance, show_tdesc_cmd, _("\
18165796c8dcSSimon Schubert Show target description specific variables."),
18175796c8dcSSimon Schubert &tdesc_show_cmdlist, "show tdesc ",
18185796c8dcSSimon Schubert 0 /* allow-unknown */, &showlist);
18195796c8dcSSimon Schubert add_prefix_cmd ("tdesc", class_maintenance, unset_tdesc_cmd, _("\
18205796c8dcSSimon Schubert Unset target description specific variables."),
18215796c8dcSSimon Schubert &tdesc_unset_cmdlist, "unset tdesc ",
18225796c8dcSSimon Schubert 0 /* allow-unknown */, &unsetlist);
18235796c8dcSSimon Schubert
18245796c8dcSSimon Schubert add_setshow_filename_cmd ("filename", class_obscure,
1825*ef5ccd6cSJohn Marino &tdesc_filename_cmd_string,
18265796c8dcSSimon Schubert _("\
18275796c8dcSSimon Schubert Set the file to read for an XML target description"), _("\
18285796c8dcSSimon Schubert Show the file to read for an XML target description"), _("\
18295796c8dcSSimon Schubert When set, GDB will read the target description from a local\n\
18305796c8dcSSimon Schubert file instead of querying the remote target."),
18315796c8dcSSimon Schubert set_tdesc_filename_cmd,
18325796c8dcSSimon Schubert show_tdesc_filename_cmd,
18335796c8dcSSimon Schubert &tdesc_set_cmdlist, &tdesc_show_cmdlist);
18345796c8dcSSimon Schubert
18355796c8dcSSimon Schubert add_cmd ("filename", class_obscure, unset_tdesc_filename_cmd, _("\
18365796c8dcSSimon Schubert Unset the file to read for an XML target description. When unset,\n\
18375796c8dcSSimon Schubert GDB will read the description from the target."),
18385796c8dcSSimon Schubert &tdesc_unset_cmdlist);
18395796c8dcSSimon Schubert
18405796c8dcSSimon Schubert add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\
18415796c8dcSSimon Schubert Print the current target description as a C source file."),
18425796c8dcSSimon Schubert &maintenanceprintlist);
18435796c8dcSSimon Schubert }
1844