* configure.in: Add cygmon for x86-coff and x86-elf. Configure
[deliverable/binutils-gdb.git] / gdb / gdbarch.c
CommitLineData
f7e85b1b
AC
1/* Semi-dynamic architecture support for GDB, the GNU debugger.
2 Copyright 1998, Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "defs.h"
21#include "bfd.h"
22#include "gdbcmd.h"
23
24
25/* Functions to manipulate the endianness of the target. */
26
27#ifdef TARGET_BYTE_ORDER_SELECTABLE
28/* compat - Catch old targets that expect a selectable byte-order to
29 default to BIG_ENDIAN */
30#ifndef TARGET_BYTE_ORDER_DEFAULT
31#define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
32#endif
33#endif
34#ifndef TARGET_BYTE_ORDER_DEFAULT
35/* compat - Catch old non byte-order selectable targets that do not
36 define TARGET_BYTE_ORDER_DEFAULT and instead expect
37 TARGET_BYTE_ORDER to be used as the default. For targets that
38 defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
39 below will get a strange compiler warning. */
40#define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
41#endif
42int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
43int target_byte_order_auto = 1;
44
45/* Chain containing the \"set endian\" commands. */
46static struct cmd_list_element *endianlist = NULL;
47
48/* Called by ``show endian''. */
49static void show_endian PARAMS ((char *, int));
50static void
51show_endian (args, from_tty)
52 char *args;
53 int from_tty;
54{
55 char *msg =
56 (TARGET_BYTE_ORDER_AUTO
57 ? "The target endianness is set automatically (currently %s endian)\n"
58 : "The target is assumed to be %s endian\n");
59 printf_unfiltered (msg, (TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little"));
60}
61
62/* Called if the user enters ``set endian'' without an argument. */
63static void set_endian PARAMS ((char *, int));
64static void
65set_endian (args, from_tty)
66 char *args;
67 int from_tty;
68{
69 printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
70 show_endian (args, from_tty);
71}
72
73/* Called by ``set endian big''. */
74static void set_endian_big PARAMS ((char *, int));
75static void
76set_endian_big (args, from_tty)
77 char *args;
78 int from_tty;
79{
80 if (TARGET_BYTE_ORDER_SELECTABLE_P)
81 {
82 target_byte_order = BIG_ENDIAN;
83 target_byte_order_auto = 0;
84 }
85 else
86 {
87 printf_unfiltered ("Byte order is not selectable.");
88 show_endian (args, from_tty);
89 }
90}
91
92/* Called by ``set endian little''. */
93static void set_endian_little PARAMS ((char *, int));
94static void
95set_endian_little (args, from_tty)
96 char *args;
97 int from_tty;
98{
99 if (TARGET_BYTE_ORDER_SELECTABLE_P)
100 {
101 target_byte_order = LITTLE_ENDIAN;
102 target_byte_order_auto = 0;
103 }
104 else
105 {
106 printf_unfiltered ("Byte order is not selectable.");
107 show_endian (args, from_tty);
108 }
109}
110
111/* Called by ``set endian auto''. */
112static void set_endian_auto PARAMS ((char *, int));
113static void
114set_endian_auto (args, from_tty)
115 char *args;
116 int from_tty;
117{
118 if (TARGET_BYTE_ORDER_SELECTABLE_P)
119 {
120 target_byte_order_auto = 1;
121 }
122 else
123 {
124 printf_unfiltered ("Byte order is not selectable.");
125 show_endian (args, from_tty);
126 }
127}
128
129/* Set the endianness from a BFD. */
130static void set_endian_from_file PARAMS ((bfd *));
131static void
132set_endian_from_file (abfd)
133 bfd *abfd;
134{
135 if (TARGET_BYTE_ORDER_SELECTABLE_P)
136 {
137 int want;
138
139 if (bfd_big_endian (abfd))
140 want = BIG_ENDIAN;
141 else
142 want = LITTLE_ENDIAN;
143 if (TARGET_BYTE_ORDER_AUTO)
144 target_byte_order = want;
145 else if (TARGET_BYTE_ORDER != want)
146 warning ("%s endian file does not match %s endian target.",
147 want == BIG_ENDIAN ? "big" : "little",
148 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
149 }
150 else
151 {
152 if (bfd_big_endian (abfd)
153 ? TARGET_BYTE_ORDER != BIG_ENDIAN
154 : TARGET_BYTE_ORDER == BIG_ENDIAN)
155 warning ("%s endian file does not match %s endian target.",
156 bfd_big_endian (abfd) ? "big" : "little",
157 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
158 }
159}
160
161
162
163/* Functions to manipulate the architecture of the target */
164
165int target_architecture_auto = 1;
166extern const bfd_arch_info_type bfd_default_arch_struct;
167const bfd_arch_info_type *target_architecture = &bfd_default_arch_struct;
168int (*target_architecture_hook) PARAMS ((const bfd_arch_info_type *ap));
169
170/* Do the real work of changing the current architecture */
171static void
172set_arch (arch)
173 const bfd_arch_info_type *arch;
174{
175 /* FIXME: Is it compatible with gdb? */
176 /* Check with the target on the setting */
177 if (target_architecture_hook != NULL
178 && !target_architecture_hook (arch))
179 printf_unfiltered ("Target does not support `%s' architecture.\n",
180 arch->printable_name);
181 else
182 {
183 target_architecture_auto = 0;
184 target_architecture = arch;
185 }
186}
187
188/* Called if the user enters ``show architecture'' without an argument. */
189static void show_architecture PARAMS ((char *, int));
190static void
191show_architecture (args, from_tty)
192 char *args;
193 int from_tty;
194{
195 const char *arch;
196 arch = target_architecture->printable_name;
197 if (target_architecture_auto)
198 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch);
199 else
200 printf_filtered ("The target architecture is assumed to be %s\n", arch);
201}
202
203/* Called if the user enters ``set architecture'' with or without an
204 argument. */
205static void set_architecture PARAMS ((char *, int));
206static void
207set_architecture (args, from_tty)
208 char *args;
209 int from_tty;
210{
211 if (args == NULL)
212 {
213 printf_unfiltered ("\"set architecture\" must be followed by \"auto\" or an architecture name.\n");
214 }
215 else if (strcmp (args, "auto") == 0)
216 {
217 target_architecture_auto = 1;
218 }
219 else
220 {
221 const bfd_arch_info_type *arch = bfd_scan_arch (args);
222 if (arch != NULL)
223 set_arch (arch);
224 else
225 printf_unfiltered ("Architecture `%s' not reconized.\n", args);
226 }
227}
228
229/* Called if the user enters ``info architecture'' without an argument. */
230static void info_architecture PARAMS ((char *, int));
231static void
232info_architecture (args, from_tty)
233 char *args;
234 int from_tty;
235{
236 enum bfd_architecture a;
237 printf_filtered ("Available architectures are:\n");
238 for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++)
239 {
240 const bfd_arch_info_type *ap = bfd_lookup_arch (a, 0);
241 if (ap != NULL)
242 {
243 do
244 {
245 printf_filtered (" %s", ap->printable_name);
246 ap = ap->next;
247 }
248 while (ap != NULL);
249 printf_filtered ("\n");
250 }
251 }
252}
253
254/* Set the architecture from arch/machine */
255void
256set_architecture_from_arch_mach (arch, mach)
257 enum bfd_architecture arch;
258 unsigned long mach;
259{
260 const bfd_arch_info_type *wanted = bfd_lookup_arch (arch, mach);
261 if (wanted != NULL)
262 set_arch (wanted);
263 else
264 fatal ("hardwired architecture/machine not reconized");
265}
266
267/* Set the architecture from a BFD */
268static void set_architecture_from_file PARAMS ((bfd *));
269static void
270set_architecture_from_file (abfd)
271 bfd *abfd;
272{
273 const bfd_arch_info_type *wanted = bfd_get_arch_info (abfd);
274 if (target_architecture_auto)
275 {
276 if (target_architecture_hook != NULL
277 && !target_architecture_hook (wanted))
278 warning ("Target may not support %s architecture",
279 wanted->printable_name);
280 target_architecture = wanted;
281 }
282 else if (wanted != target_architecture)
283 {
284 warning ("%s architecture file may be incompatible with %s target.",
285 wanted->printable_name,
286 target_architecture->printable_name);
287 }
288}
289
290
291
292/* Disassembler */
293
294/* Pointer to the target-dependent disassembly function. */
295int (*tm_print_insn) PARAMS ((bfd_vma, disassemble_info *));
296disassemble_info tm_print_insn_info;
297
298
299
300/* Set the dynamic target-system-dependant parameters (architecture,
301 byte-order) using information found in the BFD */
302
303void
304set_gdbarch_from_file (abfd)
305 bfd *abfd;
306{
307 set_architecture_from_file (abfd);
308 set_endian_from_file (abfd);
309}
310
311
312extern void _initialize_gdbarch PARAMS ((void));
313void
314_initialize_gdbarch ()
315{
316 add_prefix_cmd ("endian", class_support, set_endian,
317 "Set endianness of target.",
318 &endianlist, "set endian ", 0, &setlist);
319 add_cmd ("big", class_support, set_endian_big,
320 "Set target as being big endian.", &endianlist);
321 add_cmd ("little", class_support, set_endian_little,
322 "Set target as being little endian.", &endianlist);
323 add_cmd ("auto", class_support, set_endian_auto,
324 "Select target endianness automatically.", &endianlist);
325 add_cmd ("endian", class_support, show_endian,
326 "Show endianness of target.", &showlist);
327
328 add_cmd ("architecture", class_support, set_architecture,
329 "Set architecture of target.", &setlist);
330 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
331 add_cmd ("architecture", class_support, show_architecture,
332 "Show architecture of target.", &showlist);
333 add_cmd ("architecture", class_support, info_architecture,
334 "List supported target architectures", &infolist);
335
336 INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info, gdb_stdout, (fprintf_ftype)fprintf_filtered);
337 tm_print_insn_info.flavour = bfd_target_unknown_flavour;
338 tm_print_insn_info.read_memory_func = dis_asm_read_memory;
339 tm_print_insn_info.memory_error_func = dis_asm_memory_error;
340 tm_print_insn_info.print_address_func = dis_asm_print_address;
341}
This page took 0.035203 seconds and 4 git commands to generate.