1 /* Semi-dynamic architecture support for GDB, the GNU debugger.
2 Copyright 1998, Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 /* Non-zero if we want to trace architecture code. */
28 #define GDBARCH_DEBUG 1
30 int gdbarch_debug = GDBARCH_DEBUG;
33 /* Functions to manipulate the endianness of the target. */
35 #ifdef TARGET_BYTE_ORDER_SELECTABLE
36 /* compat - Catch old targets that expect a selectable byte-order to
37 default to BIG_ENDIAN */
38 #ifndef TARGET_BYTE_ORDER_DEFAULT
39 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
42 #ifndef TARGET_BYTE_ORDER_DEFAULT
43 /* compat - Catch old non byte-order selectable targets that do not
44 define TARGET_BYTE_ORDER_DEFAULT and instead expect
45 TARGET_BYTE_ORDER to be used as the default. For targets that
46 defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
47 below will get a strange compiler warning. */
48 #define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
50 int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
51 int target_byte_order_auto = 1;
53 /* Chain containing the \"set endian\" commands. */
54 static struct cmd_list_element *endianlist = NULL;
56 /* Called by ``show endian''. */
57 static void show_endian PARAMS ((char *, int));
59 show_endian (args, from_tty)
64 (TARGET_BYTE_ORDER_AUTO
65 ? "The target endianness is set automatically (currently %s endian)\n"
66 : "The target is assumed to be %s endian\n");
67 printf_unfiltered (msg, (TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little"));
70 /* Called if the user enters ``set endian'' without an argument. */
71 static void set_endian PARAMS ((char *, int));
73 set_endian (args, from_tty)
77 printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
78 show_endian (args, from_tty);
81 /* Called by ``set endian big''. */
82 static void set_endian_big PARAMS ((char *, int));
84 set_endian_big (args, from_tty)
88 if (TARGET_BYTE_ORDER_SELECTABLE_P)
90 target_byte_order = BIG_ENDIAN;
91 target_byte_order_auto = 0;
95 printf_unfiltered ("Byte order is not selectable.");
96 show_endian (args, from_tty);
100 /* Called by ``set endian little''. */
101 static void set_endian_little PARAMS ((char *, int));
103 set_endian_little (args, from_tty)
107 if (TARGET_BYTE_ORDER_SELECTABLE_P)
109 target_byte_order = LITTLE_ENDIAN;
110 target_byte_order_auto = 0;
114 printf_unfiltered ("Byte order is not selectable.");
115 show_endian (args, from_tty);
119 /* Called by ``set endian auto''. */
120 static void set_endian_auto PARAMS ((char *, int));
122 set_endian_auto (args, from_tty)
126 if (TARGET_BYTE_ORDER_SELECTABLE_P)
128 target_byte_order_auto = 1;
132 printf_unfiltered ("Byte order is not selectable.");
133 show_endian (args, from_tty);
137 /* Set the endianness from a BFD. */
138 static void set_endian_from_file PARAMS ((bfd *));
140 set_endian_from_file (abfd)
143 if (TARGET_BYTE_ORDER_SELECTABLE_P)
147 if (bfd_big_endian (abfd))
150 want = LITTLE_ENDIAN;
151 if (TARGET_BYTE_ORDER_AUTO)
152 target_byte_order = want;
153 else if (TARGET_BYTE_ORDER != want)
154 warning ("%s endian file does not match %s endian target.",
155 want == BIG_ENDIAN ? "big" : "little",
156 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
160 if (bfd_big_endian (abfd)
161 ? TARGET_BYTE_ORDER != BIG_ENDIAN
162 : TARGET_BYTE_ORDER == BIG_ENDIAN)
163 warning ("%s endian file does not match %s endian target.",
164 bfd_big_endian (abfd) ? "big" : "little",
165 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
171 /* Functions to manipulate the architecture of the target */
173 int target_architecture_auto = 1;
174 extern const struct bfd_arch_info bfd_default_arch_struct;
175 const struct bfd_arch_info *target_architecture = &bfd_default_arch_struct;
176 int (*target_architecture_hook) PARAMS ((const struct bfd_arch_info *ap));
178 /* Do the real work of changing the current architecture */
181 const struct bfd_arch_info *arch;
183 /* FIXME: Is it compatible with gdb? */
184 /* Check with the target on the setting */
185 if (target_architecture_hook != NULL
186 && !target_architecture_hook (arch))
187 printf_unfiltered ("Target does not support `%s' architecture.\n",
188 arch->printable_name);
191 target_architecture_auto = 0;
192 target_architecture = arch;
196 /* Called if the user enters ``show architecture'' without an argument. */
197 static void show_architecture PARAMS ((char *, int));
199 show_architecture (args, from_tty)
204 arch = TARGET_ARCHITECTURE->printable_name;
205 if (target_architecture_auto)
206 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch);
208 printf_filtered ("The target architecture is assumed to be %s\n", arch);
211 /* Called if the user enters ``set architecture'' with or without an
213 static void set_architecture PARAMS ((char *, int));
215 set_architecture (args, from_tty)
221 printf_unfiltered ("\"set architecture\" must be followed by \"auto\" or an architecture name.\n");
223 else if (strcmp (args, "auto") == 0)
225 target_architecture_auto = 1;
229 const struct bfd_arch_info *arch = bfd_scan_arch (args);
233 printf_unfiltered ("Architecture `%s' not reconized.\n", args);
237 /* Called if the user enters ``info architecture'' without an argument. */
238 static void info_architecture PARAMS ((char *, int));
240 info_architecture (args, from_tty)
244 enum bfd_architecture a;
245 printf_filtered ("Available architectures are:\n");
246 for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++)
248 const struct bfd_arch_info *ap = bfd_lookup_arch (a, 0);
253 printf_filtered (" %s", ap->printable_name);
257 printf_filtered ("\n");
262 /* Set the architecture from arch/machine */
264 set_architecture_from_arch_mach (arch, mach)
265 enum bfd_architecture arch;
268 const struct bfd_arch_info *wanted = bfd_lookup_arch (arch, mach);
272 fatal ("hardwired architecture/machine not reconized");
275 /* Set the architecture from a BFD */
276 static void set_architecture_from_file PARAMS ((bfd *));
278 set_architecture_from_file (abfd)
281 const struct bfd_arch_info *wanted = bfd_get_arch_info (abfd);
282 if (target_architecture_auto)
284 if (target_architecture_hook != NULL
285 && !target_architecture_hook (wanted))
286 warning ("Target may not support %s architecture",
287 wanted->printable_name);
288 target_architecture = wanted;
290 else if (wanted != target_architecture)
292 warning ("%s architecture file may be incompatible with %s target.",
293 wanted->printable_name,
294 target_architecture->printable_name);
302 /* Pointer to the target-dependent disassembly function. */
303 int (*tm_print_insn) PARAMS ((bfd_vma, disassemble_info *));
304 disassemble_info tm_print_insn_info;
308 /* Set the dynamic target-system-dependant parameters (architecture,
309 byte-order) using information found in the BFD */
312 set_gdbarch_from_file (abfd)
315 set_architecture_from_file (abfd);
316 set_endian_from_file (abfd);
320 extern void _initialize_gdbarch PARAMS ((void));
322 _initialize_gdbarch ()
324 add_prefix_cmd ("endian", class_support, set_endian,
325 "Set endianness of target.",
326 &endianlist, "set endian ", 0, &setlist);
327 add_cmd ("big", class_support, set_endian_big,
328 "Set target as being big endian.", &endianlist);
329 add_cmd ("little", class_support, set_endian_little,
330 "Set target as being little endian.", &endianlist);
331 add_cmd ("auto", class_support, set_endian_auto,
332 "Select target endianness automatically.", &endianlist);
333 add_cmd ("endian", class_support, show_endian,
334 "Show endianness of target.", &showlist);
336 add_cmd ("architecture", class_support, set_architecture,
337 "Set architecture of target.", &setlist);
338 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
339 add_cmd ("architecture", class_support, show_architecture,
340 "Show architecture of target.", &showlist);
341 add_cmd ("architecture", class_support, info_architecture,
342 "List supported target architectures", &infolist);
344 INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info, gdb_stdout, (fprintf_ftype)fprintf_filtered);
345 tm_print_insn_info.flavour = bfd_target_unknown_flavour;
346 tm_print_insn_info.read_memory_func = dis_asm_read_memory;
347 tm_print_insn_info.memory_error_func = dis_asm_memory_error;
348 tm_print_insn_info.print_address_func = dis_asm_print_address;
350 #ifdef MAINTENANCE_CMDS
351 add_show_from_set (add_set_cmd ("archdebug",
354 (char *)&gdbarch_debug,
355 "Set architecture debugging.\n\
356 When non-zero, architecture debugging is enabled.", &setlist),