]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Semi-dynamic architecture support for GDB, the GNU debugger. |
b83266a0 | 2 | Copyright 1998-1999, Free Software Foundation, Inc. |
c906108c SS |
3 | |
4 | This file is part of GDB. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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. */ | |
19 | ||
20 | #include "defs.h" | |
c906108c | 21 | |
7a292a7a SS |
22 | /* Just include everything in sight so that the every old definition |
23 | of macro is visible. */ | |
24 | #include "gdb_string.h" | |
25 | #include <ctype.h> | |
26 | #include "symtab.h" | |
27 | #include "frame.h" | |
28 | #include "inferior.h" | |
29 | #include "breakpoint.h" | |
30 | #include "wait.h" | |
31 | #include "gdbcore.h" | |
32 | #include "gdbcmd.h" | |
33 | #include "target.h" | |
34 | #include "gdbthread.h" | |
35 | #include "annotate.h" | |
36 | #include "symfile.h" /* for overlay functions */ | |
37 | #include "symcat.h" | |
c906108c SS |
38 | |
39 | ||
40 | /* Non-zero if we want to trace architecture code. */ | |
41 | ||
42 | #ifndef GDBARCH_DEBUG | |
43 | #define GDBARCH_DEBUG 0 | |
44 | #endif | |
45 | int gdbarch_debug = GDBARCH_DEBUG; | |
46 | ||
47 | ||
48 | /* Functions to manipulate the endianness of the target. */ | |
49 | ||
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 | |
55 | #endif | |
56 | #endif | |
7a292a7a | 57 | #if !TARGET_BYTE_ORDER_SELECTABLE_P |
c906108c SS |
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 | |
65 | #endif | |
7a292a7a SS |
66 | #endif |
67 | #ifndef TARGET_BYTE_ORDER_DEFAULT | |
68 | #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN /* arbitrary */ | |
69 | #endif | |
c906108c SS |
70 | int target_byte_order = TARGET_BYTE_ORDER_DEFAULT; |
71 | int target_byte_order_auto = 1; | |
72 | ||
73 | /* Chain containing the \"set endian\" commands. */ | |
74 | static struct cmd_list_element *endianlist = NULL; | |
75 | ||
76 | /* Called by ``show endian''. */ | |
77 | static void show_endian PARAMS ((char *, int)); | |
78 | static void | |
79 | show_endian (args, from_tty) | |
80 | char *args; | |
81 | int from_tty; | |
82 | { | |
83 | char *msg = | |
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")); | |
88 | } | |
89 | ||
90 | /* Called if the user enters ``set endian'' without an argument. */ | |
91 | static void set_endian PARAMS ((char *, int)); | |
92 | static void | |
93 | set_endian (args, from_tty) | |
94 | char *args; | |
95 | int from_tty; | |
96 | { | |
97 | printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n"); | |
98 | show_endian (args, from_tty); | |
99 | } | |
100 | ||
101 | /* Called by ``set endian big''. */ | |
102 | static void set_endian_big PARAMS ((char *, int)); | |
103 | static void | |
104 | set_endian_big (args, from_tty) | |
105 | char *args; | |
106 | int from_tty; | |
107 | { | |
108 | if (TARGET_BYTE_ORDER_SELECTABLE_P) | |
109 | { | |
110 | target_byte_order = BIG_ENDIAN; | |
111 | target_byte_order_auto = 0; | |
112 | } | |
113 | else | |
114 | { | |
115 | printf_unfiltered ("Byte order is not selectable."); | |
116 | show_endian (args, from_tty); | |
117 | } | |
118 | } | |
119 | ||
120 | /* Called by ``set endian little''. */ | |
121 | static void set_endian_little PARAMS ((char *, int)); | |
122 | static void | |
123 | set_endian_little (args, from_tty) | |
124 | char *args; | |
125 | int from_tty; | |
126 | { | |
127 | if (TARGET_BYTE_ORDER_SELECTABLE_P) | |
128 | { | |
129 | target_byte_order = LITTLE_ENDIAN; | |
130 | target_byte_order_auto = 0; | |
131 | } | |
132 | else | |
133 | { | |
134 | printf_unfiltered ("Byte order is not selectable."); | |
135 | show_endian (args, from_tty); | |
136 | } | |
137 | } | |
138 | ||
139 | /* Called by ``set endian auto''. */ | |
140 | static void set_endian_auto PARAMS ((char *, int)); | |
141 | static void | |
142 | set_endian_auto (args, from_tty) | |
143 | char *args; | |
144 | int from_tty; | |
145 | { | |
146 | if (TARGET_BYTE_ORDER_SELECTABLE_P) | |
147 | { | |
148 | target_byte_order_auto = 1; | |
149 | } | |
150 | else | |
151 | { | |
152 | printf_unfiltered ("Byte order is not selectable."); | |
153 | show_endian (args, from_tty); | |
154 | } | |
155 | } | |
156 | ||
157 | /* Set the endianness from a BFD. */ | |
158 | static void set_endian_from_file PARAMS ((bfd *)); | |
159 | static void | |
160 | set_endian_from_file (abfd) | |
161 | bfd *abfd; | |
162 | { | |
163 | if (TARGET_BYTE_ORDER_SELECTABLE_P) | |
164 | { | |
165 | int want; | |
166 | ||
167 | if (bfd_big_endian (abfd)) | |
168 | want = BIG_ENDIAN; | |
169 | else | |
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"); | |
177 | } | |
178 | else | |
179 | { | |
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"); | |
186 | } | |
187 | } | |
188 | ||
189 | ||
190 | ||
191 | /* Functions to manipulate the architecture of the target */ | |
192 | ||
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)); | |
197 | ||
198 | /* Do the real work of changing the current architecture */ | |
b83266a0 | 199 | |
392a587b | 200 | static int arch_ok PARAMS ((const struct bfd_arch_info *arch)); |
b83266a0 SS |
201 | static int |
202 | arch_ok (arch) | |
203 | const struct bfd_arch_info *arch; | |
204 | { | |
205 | /* Should be performing the more basic check that the binary is | |
206 | compatible with GDB. */ | |
207 | /* Check with the target that the architecture is valid. */ | |
208 | return (target_architecture_hook == NULL | |
209 | || target_architecture_hook (arch)); | |
210 | } | |
211 | ||
7a292a7a | 212 | enum set_arch { set_arch_auto, set_arch_manual }; |
b83266a0 | 213 | |
392a587b | 214 | static void set_arch PARAMS ((const struct bfd_arch_info *arch, enum set_arch type)); |
c906108c | 215 | static void |
7a292a7a | 216 | set_arch (arch, type) |
c906108c | 217 | const struct bfd_arch_info *arch; |
7a292a7a | 218 | enum set_arch type; |
c906108c | 219 | { |
7a292a7a | 220 | switch (type) |
c906108c | 221 | { |
7a292a7a | 222 | case set_arch_auto: |
b83266a0 | 223 | if (!arch_ok (arch)) |
7a292a7a SS |
224 | warning ("Target may not support %s architecture", |
225 | arch->printable_name); | |
c906108c | 226 | target_architecture = arch; |
7a292a7a SS |
227 | break; |
228 | case set_arch_manual: | |
b83266a0 | 229 | if (!arch_ok (arch)) |
7a292a7a SS |
230 | { |
231 | printf_unfiltered ("Target does not support `%s' architecture.\n", | |
232 | arch->printable_name); | |
233 | } | |
234 | else | |
235 | { | |
236 | target_architecture_auto = 0; | |
237 | target_architecture = arch; | |
238 | } | |
239 | break; | |
c906108c SS |
240 | } |
241 | } | |
242 | ||
243 | /* Called if the user enters ``show architecture'' without an argument. */ | |
244 | static void show_architecture PARAMS ((char *, int)); | |
245 | static void | |
246 | show_architecture (args, from_tty) | |
247 | char *args; | |
248 | int from_tty; | |
249 | { | |
250 | const char *arch; | |
251 | arch = TARGET_ARCHITECTURE->printable_name; | |
252 | if (target_architecture_auto) | |
253 | printf_filtered ("The target architecture is set automatically (currently %s)\n", arch); | |
254 | else | |
255 | printf_filtered ("The target architecture is assumed to be %s\n", arch); | |
256 | } | |
257 | ||
258 | /* Called if the user enters ``set architecture'' with or without an | |
259 | argument. */ | |
260 | static void set_architecture PARAMS ((char *, int)); | |
261 | static void | |
262 | set_architecture (args, from_tty) | |
263 | char *args; | |
264 | int from_tty; | |
265 | { | |
266 | if (args == NULL) | |
267 | { | |
268 | printf_unfiltered ("\"set architecture\" must be followed by \"auto\" or an architecture name.\n"); | |
269 | } | |
270 | else if (strcmp (args, "auto") == 0) | |
271 | { | |
272 | target_architecture_auto = 1; | |
273 | } | |
274 | else | |
275 | { | |
276 | const struct bfd_arch_info *arch = bfd_scan_arch (args); | |
277 | if (arch != NULL) | |
7a292a7a | 278 | set_arch (arch, set_arch_manual); |
c906108c SS |
279 | else |
280 | printf_unfiltered ("Architecture `%s' not reconized.\n", args); | |
281 | } | |
282 | } | |
283 | ||
284 | /* Called if the user enters ``info architecture'' without an argument. */ | |
285 | static void info_architecture PARAMS ((char *, int)); | |
286 | static void | |
287 | info_architecture (args, from_tty) | |
288 | char *args; | |
289 | int from_tty; | |
290 | { | |
291 | enum bfd_architecture a; | |
292 | printf_filtered ("Available architectures are:\n"); | |
293 | for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++) | |
294 | { | |
295 | const struct bfd_arch_info *ap = bfd_lookup_arch (a, 0); | |
296 | if (ap != NULL) | |
297 | { | |
298 | do | |
299 | { | |
300 | printf_filtered (" %s", ap->printable_name); | |
301 | ap = ap->next; | |
302 | } | |
303 | while (ap != NULL); | |
304 | printf_filtered ("\n"); | |
305 | } | |
306 | } | |
307 | } | |
308 | ||
309 | /* Set the architecture from arch/machine */ | |
310 | void | |
311 | set_architecture_from_arch_mach (arch, mach) | |
312 | enum bfd_architecture arch; | |
313 | unsigned long mach; | |
314 | { | |
315 | const struct bfd_arch_info *wanted = bfd_lookup_arch (arch, mach); | |
316 | if (wanted != NULL) | |
7a292a7a | 317 | set_arch (wanted, set_arch_manual); |
c906108c SS |
318 | else |
319 | fatal ("hardwired architecture/machine not reconized"); | |
320 | } | |
321 | ||
322 | /* Set the architecture from a BFD */ | |
323 | static void set_architecture_from_file PARAMS ((bfd *)); | |
324 | static void | |
325 | set_architecture_from_file (abfd) | |
326 | bfd *abfd; | |
327 | { | |
328 | const struct bfd_arch_info *wanted = bfd_get_arch_info (abfd); | |
329 | if (target_architecture_auto) | |
330 | { | |
7a292a7a | 331 | set_arch (wanted, set_arch_auto); |
c906108c SS |
332 | } |
333 | else if (wanted != target_architecture) | |
334 | { | |
335 | warning ("%s architecture file may be incompatible with %s target.", | |
336 | wanted->printable_name, | |
337 | target_architecture->printable_name); | |
338 | } | |
339 | } | |
340 | ||
341 | ||
342 | ||
343 | /* Disassembler */ | |
344 | ||
345 | /* Pointer to the target-dependent disassembly function. */ | |
346 | int (*tm_print_insn) PARAMS ((bfd_vma, disassemble_info *)); | |
347 | disassemble_info tm_print_insn_info; | |
348 | ||
349 | ||
350 | ||
351 | /* Set the dynamic target-system-dependant parameters (architecture, | |
352 | byte-order) using information found in the BFD */ | |
353 | ||
354 | void | |
355 | set_gdbarch_from_file (abfd) | |
356 | bfd *abfd; | |
357 | { | |
358 | set_architecture_from_file (abfd); | |
359 | set_endian_from_file (abfd); | |
360 | } | |
361 | ||
362 | ||
7a292a7a SS |
363 | #if defined (CALL_DUMMY) |
364 | /* FIXME - this should go away */ | |
365 | LONGEST call_dummy_words[] = CALL_DUMMY; | |
366 | int sizeof_call_dummy_words = sizeof (call_dummy_words); | |
367 | #endif | |
368 | ||
369 | ||
c906108c SS |
370 | extern void _initialize_gdbarch PARAMS ((void)); |
371 | void | |
372 | _initialize_gdbarch () | |
373 | { | |
374 | add_prefix_cmd ("endian", class_support, set_endian, | |
375 | "Set endianness of target.", | |
376 | &endianlist, "set endian ", 0, &setlist); | |
377 | add_cmd ("big", class_support, set_endian_big, | |
378 | "Set target as being big endian.", &endianlist); | |
379 | add_cmd ("little", class_support, set_endian_little, | |
380 | "Set target as being little endian.", &endianlist); | |
381 | add_cmd ("auto", class_support, set_endian_auto, | |
382 | "Select target endianness automatically.", &endianlist); | |
383 | add_cmd ("endian", class_support, show_endian, | |
384 | "Show endianness of target.", &showlist); | |
385 | ||
386 | add_cmd ("architecture", class_support, set_architecture, | |
387 | "Set architecture of target.", &setlist); | |
388 | add_alias_cmd ("processor", "architecture", class_support, 1, &setlist); | |
389 | add_cmd ("architecture", class_support, show_architecture, | |
390 | "Show architecture of target.", &showlist); | |
391 | add_cmd ("architecture", class_support, info_architecture, | |
392 | "List supported target architectures", &infolist); | |
393 | ||
394 | INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info, gdb_stdout, (fprintf_ftype)fprintf_filtered); | |
395 | tm_print_insn_info.flavour = bfd_target_unknown_flavour; | |
396 | tm_print_insn_info.read_memory_func = dis_asm_read_memory; | |
397 | tm_print_insn_info.memory_error_func = dis_asm_memory_error; | |
398 | tm_print_insn_info.print_address_func = dis_asm_print_address; | |
399 | ||
c906108c SS |
400 | add_show_from_set (add_set_cmd ("archdebug", |
401 | class_maintenance, | |
402 | var_zinteger, | |
403 | (char *)&gdbarch_debug, | |
404 | "Set architecture debugging.\n\ | |
405 | When non-zero, architecture debugging is enabled.", &setlist), | |
406 | &showlist); | |
c906108c | 407 | } |