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. */
22 /* Just include everything in sight so that the every old definition
23 of macro is visible. */
24 #include "gdb_string.h"
29 #include "breakpoint.h"
34 #include "gdbthread.h"
36 #include "symfile.h" /* for overlay functions */
40 /* Non-zero if we want to trace architecture code. */
43 #define GDBARCH_DEBUG 0
45 int gdbarch_debug
= GDBARCH_DEBUG
;
48 /* Functions to manipulate the endianness of the target. */
50 #ifdef TARGET_BYTE_ORDER_SELECTABLE
51 /* compat - Catch old targets that expect a selectable byte-order to
52 default to BIG_ENDIAN */
53 #ifndef TARGET_BYTE_ORDER_DEFAULT
54 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
57 #if !TARGET_BYTE_ORDER_SELECTABLE_P
58 #ifndef TARGET_BYTE_ORDER_DEFAULT
59 /* compat - Catch old non byte-order selectable targets that do not
60 define TARGET_BYTE_ORDER_DEFAULT and instead expect
61 TARGET_BYTE_ORDER to be used as the default. For targets that
62 defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
63 below will get a strange compiler warning. */
64 #define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
67 #ifndef TARGET_BYTE_ORDER_DEFAULT
68 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN /* arbitrary */
70 int target_byte_order
= TARGET_BYTE_ORDER_DEFAULT
;
71 int target_byte_order_auto
= 1;
73 /* Chain containing the \"set endian\" commands. */
74 static struct cmd_list_element
*endianlist
= NULL
;
76 /* Called by ``show endian''. */
77 static void show_endian
PARAMS ((char *, int));
79 show_endian (args
, from_tty
)
84 (TARGET_BYTE_ORDER_AUTO
85 ? "The target endianness is set automatically (currently %s endian)\n"
86 : "The target is assumed to be %s endian\n");
87 printf_unfiltered (msg
, (TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little"));
90 /* Called if the user enters ``set endian'' without an argument. */
91 static void set_endian
PARAMS ((char *, int));
93 set_endian (args
, from_tty
)
97 printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
98 show_endian (args
, from_tty
);
101 /* Called by ``set endian big''. */
102 static void set_endian_big
PARAMS ((char *, int));
104 set_endian_big (args
, from_tty
)
108 if (TARGET_BYTE_ORDER_SELECTABLE_P
)
110 target_byte_order
= BIG_ENDIAN
;
111 target_byte_order_auto
= 0;
115 printf_unfiltered ("Byte order is not selectable.");
116 show_endian (args
, from_tty
);
120 /* Called by ``set endian little''. */
121 static void set_endian_little
PARAMS ((char *, int));
123 set_endian_little (args
, from_tty
)
127 if (TARGET_BYTE_ORDER_SELECTABLE_P
)
129 target_byte_order
= LITTLE_ENDIAN
;
130 target_byte_order_auto
= 0;
134 printf_unfiltered ("Byte order is not selectable.");
135 show_endian (args
, from_tty
);
139 /* Called by ``set endian auto''. */
140 static void set_endian_auto
PARAMS ((char *, int));
142 set_endian_auto (args
, from_tty
)
146 if (TARGET_BYTE_ORDER_SELECTABLE_P
)
148 target_byte_order_auto
= 1;
152 printf_unfiltered ("Byte order is not selectable.");
153 show_endian (args
, from_tty
);
157 /* Set the endianness from a BFD. */
158 static void set_endian_from_file
PARAMS ((bfd
*));
160 set_endian_from_file (abfd
)
163 if (TARGET_BYTE_ORDER_SELECTABLE_P
)
167 if (bfd_big_endian (abfd
))
170 want
= LITTLE_ENDIAN
;
171 if (TARGET_BYTE_ORDER_AUTO
)
172 target_byte_order
= want
;
173 else if (TARGET_BYTE_ORDER
!= want
)
174 warning ("%s endian file does not match %s endian target.",
175 want
== BIG_ENDIAN
? "big" : "little",
176 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
180 if (bfd_big_endian (abfd
)
181 ? TARGET_BYTE_ORDER
!= BIG_ENDIAN
182 : TARGET_BYTE_ORDER
== BIG_ENDIAN
)
183 warning ("%s endian file does not match %s endian target.",
184 bfd_big_endian (abfd
) ? "big" : "little",
185 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
191 /* Functions to manipulate the architecture of the target */
193 int target_architecture_auto
= 1;
194 extern const struct bfd_arch_info bfd_default_arch_struct
;
195 const struct bfd_arch_info
*target_architecture
= &bfd_default_arch_struct
;
196 int (*target_architecture_hook
) PARAMS ((const struct bfd_arch_info
*ap
));
198 /* Do the real work of changing the current architecture */
199 enum set_arch
{ set_arch_auto
, set_arch_manual
};
201 set_arch (arch
, type
)
202 const struct bfd_arch_info
*arch
;
205 /* FIXME: Should be performing the more basic check that the binary
206 is compatible with GDB. */
207 /* Check with the target that the architecture is valid. */
208 int arch_valid
= (target_architecture_hook
!= NULL
209 && !target_architecture_hook (arch
));
214 warning ("Target may not support %s architecture",
215 arch
->printable_name
);
216 target_architecture
= arch
;
218 case set_arch_manual
:
221 printf_unfiltered ("Target does not support `%s' architecture.\n",
222 arch
->printable_name
);
226 target_architecture_auto
= 0;
227 target_architecture
= arch
;
233 /* Called if the user enters ``show architecture'' without an argument. */
234 static void show_architecture
PARAMS ((char *, int));
236 show_architecture (args
, from_tty
)
241 arch
= TARGET_ARCHITECTURE
->printable_name
;
242 if (target_architecture_auto
)
243 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch
);
245 printf_filtered ("The target architecture is assumed to be %s\n", arch
);
248 /* Called if the user enters ``set architecture'' with or without an
250 static void set_architecture
PARAMS ((char *, int));
252 set_architecture (args
, from_tty
)
258 printf_unfiltered ("\"set architecture\" must be followed by \"auto\" or an architecture name.\n");
260 else if (strcmp (args
, "auto") == 0)
262 target_architecture_auto
= 1;
266 const struct bfd_arch_info
*arch
= bfd_scan_arch (args
);
268 set_arch (arch
, set_arch_manual
);
270 printf_unfiltered ("Architecture `%s' not reconized.\n", args
);
274 /* Called if the user enters ``info architecture'' without an argument. */
275 static void info_architecture
PARAMS ((char *, int));
277 info_architecture (args
, from_tty
)
281 enum bfd_architecture a
;
282 printf_filtered ("Available architectures are:\n");
283 for (a
= bfd_arch_obscure
+ 1; a
< bfd_arch_last
; a
++)
285 const struct bfd_arch_info
*ap
= bfd_lookup_arch (a
, 0);
290 printf_filtered (" %s", ap
->printable_name
);
294 printf_filtered ("\n");
299 /* Set the architecture from arch/machine */
301 set_architecture_from_arch_mach (arch
, mach
)
302 enum bfd_architecture arch
;
305 const struct bfd_arch_info
*wanted
= bfd_lookup_arch (arch
, mach
);
307 set_arch (wanted
, set_arch_manual
);
309 fatal ("hardwired architecture/machine not reconized");
312 /* Set the architecture from a BFD */
313 static void set_architecture_from_file
PARAMS ((bfd
*));
315 set_architecture_from_file (abfd
)
318 const struct bfd_arch_info
*wanted
= bfd_get_arch_info (abfd
);
319 if (target_architecture_auto
)
321 set_arch (wanted
, set_arch_auto
);
323 else if (wanted
!= target_architecture
)
325 warning ("%s architecture file may be incompatible with %s target.",
326 wanted
->printable_name
,
327 target_architecture
->printable_name
);
335 /* Pointer to the target-dependent disassembly function. */
336 int (*tm_print_insn
) PARAMS ((bfd_vma
, disassemble_info
*));
337 disassemble_info tm_print_insn_info
;
341 /* Set the dynamic target-system-dependant parameters (architecture,
342 byte-order) using information found in the BFD */
345 set_gdbarch_from_file (abfd
)
348 set_architecture_from_file (abfd
);
349 set_endian_from_file (abfd
);
353 #if defined (CALL_DUMMY)
354 /* FIXME - this should go away */
355 LONGEST call_dummy_words
[] = CALL_DUMMY
;
356 int sizeof_call_dummy_words
= sizeof (call_dummy_words
);
360 extern void _initialize_gdbarch
PARAMS ((void));
362 _initialize_gdbarch ()
364 add_prefix_cmd ("endian", class_support
, set_endian
,
365 "Set endianness of target.",
366 &endianlist
, "set endian ", 0, &setlist
);
367 add_cmd ("big", class_support
, set_endian_big
,
368 "Set target as being big endian.", &endianlist
);
369 add_cmd ("little", class_support
, set_endian_little
,
370 "Set target as being little endian.", &endianlist
);
371 add_cmd ("auto", class_support
, set_endian_auto
,
372 "Select target endianness automatically.", &endianlist
);
373 add_cmd ("endian", class_support
, show_endian
,
374 "Show endianness of target.", &showlist
);
376 add_cmd ("architecture", class_support
, set_architecture
,
377 "Set architecture of target.", &setlist
);
378 add_alias_cmd ("processor", "architecture", class_support
, 1, &setlist
);
379 add_cmd ("architecture", class_support
, show_architecture
,
380 "Show architecture of target.", &showlist
);
381 add_cmd ("architecture", class_support
, info_architecture
,
382 "List supported target architectures", &infolist
);
384 INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info
, gdb_stdout
, (fprintf_ftype
)fprintf_filtered
);
385 tm_print_insn_info
.flavour
= bfd_target_unknown_flavour
;
386 tm_print_insn_info
.read_memory_func
= dis_asm_read_memory
;
387 tm_print_insn_info
.memory_error_func
= dis_asm_memory_error
;
388 tm_print_insn_info
.print_address_func
= dis_asm_print_address
;
390 add_show_from_set (add_set_cmd ("archdebug",
393 (char *)&gdbarch_debug
,
394 "Set architecture debugging.\n\
395 When non-zero, architecture debugging is enabled.", &setlist
),