daily update
[deliverable/binutils-gdb.git] / gdb / arch-utils.c
CommitLineData
c0e8c252 1/* Dynamic architecture support for GDB, the GNU debugger.
b6ba6518 2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
c0e8c252
AC
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,
19 Boston, MA 02111-1307, USA. */
20
21#include "defs.h"
22
23#if GDB_MULTI_ARCH
fb6ecb0f 24#include "arch-utils.h"
c0e8c252
AC
25#include "gdbcmd.h"
26#include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
27#else
28/* Just include everything in sight so that the every old definition
29 of macro is visible. */
30#include "gdb_string.h"
c0e8c252
AC
31#include "symtab.h"
32#include "frame.h"
33#include "inferior.h"
34#include "breakpoint.h"
35#include "gdb_wait.h"
36#include "gdbcore.h"
37#include "gdbcmd.h"
38#include "target.h"
c0e8c252 39#include "annotate.h"
c0e8c252 40#endif
fbec36e2 41#include "regcache.h"
39d4ef09 42#include "gdb_assert.h"
c0e8c252 43
1ba607ad
AC
44#include "version.h"
45
f0d4cc9e
AC
46#include "floatformat.h"
47
c0e8c252
AC
48/* Use the program counter to determine the contents and size
49 of a breakpoint instruction. If no target-dependent macro
50 BREAKPOINT_FROM_PC has been defined to implement this function,
51 assume that the breakpoint doesn't depend on the PC, and
52 use the values of the BIG_BREAKPOINT and LITTLE_BREAKPOINT macros.
53 Return a pointer to a string of bytes that encode a breakpoint
54 instruction, stores the length of the string to *lenptr,
55 and optionally adjust the pc to point to the correct memory location
56 for inserting the breakpoint. */
57
58unsigned char *
59legacy_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
60{
61 /* {BIG_,LITTLE_}BREAKPOINT is the sequence of bytes we insert for a
62 breakpoint. On some machines, breakpoints are handled by the
63 target environment and we don't have to worry about them here. */
64#ifdef BIG_BREAKPOINT
d7449b42 65 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
c0e8c252
AC
66 {
67 static unsigned char big_break_insn[] = BIG_BREAKPOINT;
68 *lenptr = sizeof (big_break_insn);
69 return big_break_insn;
70 }
71#endif
72#ifdef LITTLE_BREAKPOINT
d7449b42 73 if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
c0e8c252
AC
74 {
75 static unsigned char little_break_insn[] = LITTLE_BREAKPOINT;
76 *lenptr = sizeof (little_break_insn);
77 return little_break_insn;
78 }
79#endif
80#ifdef BREAKPOINT
81 {
82 static unsigned char break_insn[] = BREAKPOINT;
83 *lenptr = sizeof (break_insn);
84 return break_insn;
85 }
86#endif
87 *lenptr = 0;
88 return NULL;
89}
90
91int
92generic_frameless_function_invocation_not (struct frame_info *fi)
93{
94 return 0;
95}
96
71a9f22e
JB
97int
98generic_return_value_on_stack_not (struct type *type)
99{
100 return 0;
101}
102
bdcd319a
CV
103CORE_ADDR
104generic_skip_trampoline_code (CORE_ADDR pc)
105{
106 return 0;
107}
108
68e9cc94
CV
109int
110generic_in_solib_call_trampoline (CORE_ADDR pc, char *name)
111{
112 return 0;
113}
114
c12260ac
CV
115int
116generic_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
117{
118 return 0;
119}
120
c0e8c252
AC
121char *
122legacy_register_name (int i)
123{
124#ifdef REGISTER_NAMES
125 static char *names[] = REGISTER_NAMES;
126 if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
127 return NULL;
128 else
129 return names[i];
130#else
8e65ff28
AC
131 internal_error (__FILE__, __LINE__,
132 "legacy_register_name: called.");
c0e8c252
AC
133 return NULL;
134#endif
135}
136
137#if defined (CALL_DUMMY)
138LONGEST legacy_call_dummy_words[] = CALL_DUMMY;
139#else
140LONGEST legacy_call_dummy_words[1];
141#endif
142int legacy_sizeof_call_dummy_words = sizeof (legacy_call_dummy_words);
143
144void
145generic_remote_translate_xfer_address (CORE_ADDR gdb_addr, int gdb_len,
146 CORE_ADDR * rem_addr, int *rem_len)
147{
148 *rem_addr = gdb_addr;
149 *rem_len = gdb_len;
150}
151
dad41f9a
AC
152int
153generic_prologue_frameless_p (CORE_ADDR ip)
154{
155#ifdef SKIP_PROLOGUE_FRAMELESS_P
156 return ip == SKIP_PROLOGUE_FRAMELESS_P (ip);
157#else
158 return ip == SKIP_PROLOGUE (ip);
159#endif
160}
161
2bf0cb65
EZ
162/* New/multi-arched targets should use the correct gdbarch field
163 instead of using this global pointer. */
164int
165legacy_print_insn (bfd_vma vma, disassemble_info *info)
166{
167 return (*tm_print_insn) (vma, info);
168}
dad41f9a 169
3339cf8b
AC
170/* Helper functions for INNER_THAN */
171
172int
fba45db2 173core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
3339cf8b
AC
174{
175 return (lhs < rhs);
176}
177
178int
fba45db2 179core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
3339cf8b
AC
180{
181 return (lhs > rhs);
182}
183
184
f0d4cc9e
AC
185/* Helper functions for TARGET_{FLOAT,DOUBLE}_FORMAT */
186
187const struct floatformat *
188default_float_format (struct gdbarch *gdbarch)
189{
190#if GDB_MULTI_ARCH
191 int byte_order = gdbarch_byte_order (gdbarch);
192#else
193 int byte_order = TARGET_BYTE_ORDER;
194#endif
195 switch (byte_order)
196 {
d7449b42 197 case BFD_ENDIAN_BIG:
f0d4cc9e 198 return &floatformat_ieee_single_big;
778eb05e 199 case BFD_ENDIAN_LITTLE:
f0d4cc9e
AC
200 return &floatformat_ieee_single_little;
201 default:
8e65ff28
AC
202 internal_error (__FILE__, __LINE__,
203 "default_float_format: bad byte order");
f0d4cc9e
AC
204 }
205}
206
207
208const struct floatformat *
209default_double_format (struct gdbarch *gdbarch)
210{
211#if GDB_MULTI_ARCH
212 int byte_order = gdbarch_byte_order (gdbarch);
213#else
214 int byte_order = TARGET_BYTE_ORDER;
215#endif
216 switch (byte_order)
217 {
d7449b42 218 case BFD_ENDIAN_BIG:
f0d4cc9e 219 return &floatformat_ieee_double_big;
778eb05e 220 case BFD_ENDIAN_LITTLE:
f0d4cc9e
AC
221 return &floatformat_ieee_double_little;
222 default:
8e65ff28
AC
223 internal_error (__FILE__, __LINE__,
224 "default_double_format: bad byte order");
f0d4cc9e
AC
225 }
226}
227
5e74b15c
RE
228void
229default_print_float_info (void)
230{
231#ifdef FLOAT_INFO
232#if GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL
233#error "FLOAT_INFO defined in multi-arch"
234#endif
235 FLOAT_INFO;
236#else
237 printf_filtered ("No floating point info available for this processor.\n");
238#endif
239}
240
193e3b1a
AC
241/* Misc helper functions for targets. */
242
243int
fba45db2 244frame_num_args_unknown (struct frame_info *fi)
193e3b1a
AC
245{
246 return -1;
247}
248
249
250int
fba45db2 251generic_register_convertible_not (int num)
193e3b1a
AC
252{
253 return 0;
254}
255
b4a20239 256
c8f9d51c
JB
257/* Under some ABI's that specify the `struct convention' for returning
258 structures by value, by the time we've returned from the function,
259 the return value is sitting there in the caller's buffer, but GDB
260 has no way to find the address of that buffer.
261
262 On such architectures, use this function as your
263 extract_struct_value_address method. When asked to a struct
264 returned by value in this fashion, GDB will print a nice error
265 message, instead of garbage. */
266CORE_ADDR
267generic_cannot_extract_struct_value_address (char *dummy)
268{
269 return 0;
270}
271
7c7651b2
AC
272int
273default_register_sim_regno (int num)
274{
275 return num;
276}
277
f517ea4e
PS
278
279CORE_ADDR
875e1767 280core_addr_identity (CORE_ADDR addr)
f517ea4e
PS
281{
282 return addr;
283}
284
88c72b7d
AC
285int
286no_op_reg_to_regnum (int reg)
287{
288 return reg;
289}
290
c347ee3e
MS
291/* For use by frame_args_address and frame_locals_address. */
292CORE_ADDR
293default_frame_address (struct frame_info *fi)
294{
295 return fi->frame;
296}
297
e02bc4cc
DS
298/* Default prepare_to_procced(). */
299int
300default_prepare_to_proceed (int select_it)
301{
302 return 0;
303}
304
305/* Generic prepare_to_proceed(). This one should be suitable for most
306 targets that support threads. */
307int
308generic_prepare_to_proceed (int select_it)
309{
39f77062 310 ptid_t wait_ptid;
e02bc4cc
DS
311 struct target_waitstatus wait_status;
312
313 /* Get the last target status returned by target_wait(). */
39f77062 314 get_last_target_status (&wait_ptid, &wait_status);
e02bc4cc 315
8849f47d
JL
316 /* Make sure we were stopped either at a breakpoint, or because
317 of a Ctrl-C. */
e02bc4cc 318 if (wait_status.kind != TARGET_WAITKIND_STOPPED
8849f47d
JL
319 || (wait_status.value.sig != TARGET_SIGNAL_TRAP &&
320 wait_status.value.sig != TARGET_SIGNAL_INT))
e02bc4cc
DS
321 {
322 return 0;
323 }
324
39f77062
KB
325 if (!ptid_equal (wait_ptid, minus_one_ptid)
326 && !ptid_equal (inferior_ptid, wait_ptid))
e02bc4cc
DS
327 {
328 /* Switched over from WAIT_PID. */
39f77062 329 CORE_ADDR wait_pc = read_pc_pid (wait_ptid);
e02bc4cc 330
8849f47d 331 if (wait_pc != read_pc ())
e02bc4cc
DS
332 {
333 if (select_it)
334 {
8849f47d 335 /* Switch back to WAIT_PID thread. */
39f77062 336 inferior_ptid = wait_ptid;
e02bc4cc
DS
337
338 /* FIXME: This stuff came from switch_to_thread() in
339 thread.c (which should probably be a public function). */
340 flush_cached_frames ();
341 registers_changed ();
342 stop_pc = wait_pc;
343 select_frame (get_current_frame (), 0);
344 }
8849f47d
JL
345 /* We return 1 to indicate that there is a breakpoint here,
346 so we need to step over it before continuing to avoid
347 hitting it straight away. */
348 if (breakpoint_here_p (wait_pc))
349 {
350 return 1;
351 }
e02bc4cc
DS
352 }
353 }
354 return 0;
355
356}
357
10312cc4
AC
358void
359init_frame_pc_noop (int fromleaf, struct frame_info *prev)
360{
361 return;
362}
363
7824d2f2
AC
364void
365init_frame_pc_default (int fromleaf, struct frame_info *prev)
366{
367 if (fromleaf)
368 prev->pc = SAVED_PC_AFTER_CALL (prev->next);
369 else if (prev->next != NULL)
370 prev->pc = FRAME_SAVED_PC (prev->next);
371 else
372 prev->pc = read_pc ();
373}
374
a2cf933a
EZ
375void
376default_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
377{
378 return;
379}
380
381void
382default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
383{
384 return;
385}
386
01fb7433
AC
387int
388cannot_register_not (int regnum)
389{
390 return 0;
391}
39d4ef09
AC
392
393/* Legacy version of target_virtual_frame_pointer(). Assumes that
394 there is an FP_REGNUM and that it is the same, cooked or raw. */
395
396void
397legacy_virtual_frame_pointer (CORE_ADDR pc,
398 int *frame_regnum,
399 LONGEST *frame_offset)
400{
401 gdb_assert (FP_REGNUM >= 0);
402 *frame_regnum = FP_REGNUM;
403 *frame_offset = 0;
404}
46cd78fb
AC
405
406/* Assume the world is flat. Every register is large enough to fit a
407 target integer. */
408
409int
410generic_register_raw_size (int regnum)
411{
412 gdb_assert (regnum >= 0 && regnum < NUM_REGS + NUM_PSEUDO_REGS);
413 return TARGET_INT_BIT / HOST_CHAR_BIT;
414}
415
ce29138a
MS
416/* Assume the virtual size corresponds to the virtual type. */
417
418int
419generic_register_virtual_size (int regnum)
420{
ef8570de 421 return TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (regnum));
ce29138a
MS
422}
423
01fb7433 424\f
b4a20239
AC
425/* Functions to manipulate the endianness of the target. */
426
1ba607ad 427/* ``target_byte_order'' is only used when non- multi-arch.
afe64c1a
AC
428 Multi-arch targets obtain the current byte order using the
429 TARGET_BYTE_ORDER gdbarch method.
430
431 The choice of initial value is entirely arbitrary. During startup,
432 the function initialize_current_architecture() updates this value
433 based on default byte-order information extracted from BFD. */
434int target_byte_order = BFD_ENDIAN_BIG;
b4a20239
AC
435int target_byte_order_auto = 1;
436
53904c9e
AC
437static const char endian_big[] = "big";
438static const char endian_little[] = "little";
439static const char endian_auto[] = "auto";
440static const char *endian_enum[] =
b4a20239
AC
441{
442 endian_big,
443 endian_little,
444 endian_auto,
445 NULL,
446};
53904c9e 447static const char *set_endian_string;
b4a20239
AC
448
449/* Called by ``show endian''. */
450
451static void
452show_endian (char *args, int from_tty)
453{
454 if (TARGET_BYTE_ORDER_AUTO)
455 printf_unfiltered ("The target endianness is set automatically (currently %s endian)\n",
d7449b42 456 (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? "big" : "little"));
b4a20239
AC
457 else
458 printf_unfiltered ("The target is assumed to be %s endian\n",
d7449b42 459 (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? "big" : "little"));
b4a20239
AC
460}
461
462static void
463set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c)
464{
3fd3d7d2 465 if (set_endian_string == endian_auto)
b4a20239
AC
466 {
467 target_byte_order_auto = 1;
468 }
469 else if (set_endian_string == endian_little)
470 {
b4a20239
AC
471 target_byte_order_auto = 0;
472 if (GDB_MULTI_ARCH)
473 {
474 struct gdbarch_info info;
fb6ecb0f 475 gdbarch_info_init (&info);
778eb05e 476 info.byte_order = BFD_ENDIAN_LITTLE;
16f33e29
AC
477 if (! gdbarch_update_p (info))
478 {
479 printf_unfiltered ("Little endian target not supported by GDB\n");
480 }
b4a20239 481 }
1ba607ad
AC
482 else
483 {
778eb05e 484 target_byte_order = BFD_ENDIAN_LITTLE;
1ba607ad 485 }
b4a20239
AC
486 }
487 else if (set_endian_string == endian_big)
488 {
b4a20239
AC
489 target_byte_order_auto = 0;
490 if (GDB_MULTI_ARCH)
491 {
492 struct gdbarch_info info;
fb6ecb0f 493 gdbarch_info_init (&info);
d7449b42 494 info.byte_order = BFD_ENDIAN_BIG;
16f33e29
AC
495 if (! gdbarch_update_p (info))
496 {
497 printf_unfiltered ("Big endian target not supported by GDB\n");
498 }
b4a20239 499 }
1ba607ad
AC
500 else
501 {
d7449b42 502 target_byte_order = BFD_ENDIAN_BIG;
1ba607ad 503 }
b4a20239
AC
504 }
505 else
8e65ff28
AC
506 internal_error (__FILE__, __LINE__,
507 "set_endian: bad value");
b4a20239
AC
508 show_endian (NULL, from_tty);
509}
510
511/* Set the endianness from a BFD. */
512
513static void
514set_endian_from_file (bfd *abfd)
515{
3fd3d7d2 516 int want;
1ba607ad 517 if (GDB_MULTI_ARCH)
8e65ff28
AC
518 internal_error (__FILE__, __LINE__,
519 "set_endian_from_file: not for multi-arch");
3fd3d7d2
AC
520 if (bfd_big_endian (abfd))
521 want = BFD_ENDIAN_BIG;
b4a20239 522 else
3fd3d7d2
AC
523 want = BFD_ENDIAN_LITTLE;
524 if (TARGET_BYTE_ORDER_AUTO)
525 target_byte_order = want;
526 else if (TARGET_BYTE_ORDER != want)
527 warning ("%s endian file does not match %s endian target.",
528 want == BFD_ENDIAN_BIG ? "big" : "little",
529 TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? "big" : "little");
b4a20239
AC
530}
531
532
533/* Functions to manipulate the architecture of the target */
534
535enum set_arch { set_arch_auto, set_arch_manual };
536
537int target_architecture_auto = 1;
538
53904c9e 539const char *set_architecture_string;
b4a20239
AC
540
541/* Old way of changing the current architecture. */
542
543extern const struct bfd_arch_info bfd_default_arch_struct;
544const struct bfd_arch_info *target_architecture = &bfd_default_arch_struct;
545int (*target_architecture_hook) (const struct bfd_arch_info *ap);
546
547static int
548arch_ok (const struct bfd_arch_info *arch)
549{
550 if (GDB_MULTI_ARCH)
8e65ff28
AC
551 internal_error (__FILE__, __LINE__,
552 "arch_ok: not multi-arched");
b4a20239
AC
553 /* Should be performing the more basic check that the binary is
554 compatible with GDB. */
555 /* Check with the target that the architecture is valid. */
556 return (target_architecture_hook == NULL
557 || target_architecture_hook (arch));
558}
559
560static void
561set_arch (const struct bfd_arch_info *arch,
562 enum set_arch type)
563{
564 if (GDB_MULTI_ARCH)
8e65ff28
AC
565 internal_error (__FILE__, __LINE__,
566 "set_arch: not multi-arched");
b4a20239
AC
567 switch (type)
568 {
569 case set_arch_auto:
570 if (!arch_ok (arch))
571 warning ("Target may not support %s architecture",
572 arch->printable_name);
573 target_architecture = arch;
574 break;
575 case set_arch_manual:
576 if (!arch_ok (arch))
577 {
578 printf_unfiltered ("Target does not support `%s' architecture.\n",
579 arch->printable_name);
580 }
581 else
582 {
583 target_architecture_auto = 0;
584 target_architecture = arch;
585 }
586 break;
587 }
588 if (gdbarch_debug)
4b9b3959 589 gdbarch_dump (current_gdbarch, gdb_stdlog);
b4a20239
AC
590}
591
592/* Set the architecture from arch/machine (deprecated) */
593
594void
595set_architecture_from_arch_mach (enum bfd_architecture arch,
596 unsigned long mach)
597{
598 const struct bfd_arch_info *wanted = bfd_lookup_arch (arch, mach);
599 if (GDB_MULTI_ARCH)
8e65ff28
AC
600 internal_error (__FILE__, __LINE__,
601 "set_architecture_from_arch_mach: not multi-arched");
b4a20239
AC
602 if (wanted != NULL)
603 set_arch (wanted, set_arch_manual);
604 else
8e65ff28
AC
605 internal_error (__FILE__, __LINE__,
606 "gdbarch: hardwired architecture/machine not recognized");
b4a20239
AC
607}
608
609/* Set the architecture from a BFD (deprecated) */
610
611static void
612set_architecture_from_file (bfd *abfd)
613{
614 const struct bfd_arch_info *wanted = bfd_get_arch_info (abfd);
615 if (GDB_MULTI_ARCH)
8e65ff28
AC
616 internal_error (__FILE__, __LINE__,
617 "set_architecture_from_file: not multi-arched");
b4a20239
AC
618 if (target_architecture_auto)
619 {
620 set_arch (wanted, set_arch_auto);
621 }
622 else if (wanted != target_architecture)
623 {
624 warning ("%s architecture file may be incompatible with %s target.",
625 wanted->printable_name,
626 target_architecture->printable_name);
627 }
628}
629
630
631/* Called if the user enters ``show architecture'' without an
632 argument. */
633
634static void
635show_architecture (char *args, int from_tty)
636{
637 const char *arch;
638 arch = TARGET_ARCHITECTURE->printable_name;
639 if (target_architecture_auto)
640 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch);
641 else
642 printf_filtered ("The target architecture is assumed to be %s\n", arch);
643}
644
645
646/* Called if the user enters ``set architecture'' with or without an
647 argument. */
648
649static void
650set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c)
651{
652 if (strcmp (set_architecture_string, "auto") == 0)
653 {
654 target_architecture_auto = 1;
655 }
656 else if (GDB_MULTI_ARCH)
657 {
658 struct gdbarch_info info;
fb6ecb0f 659 gdbarch_info_init (&info);
b4a20239
AC
660 info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
661 if (info.bfd_arch_info == NULL)
8e65ff28
AC
662 internal_error (__FILE__, __LINE__,
663 "set_architecture: bfd_scan_arch failed");
16f33e29 664 if (gdbarch_update_p (info))
b4a20239
AC
665 target_architecture_auto = 0;
666 else
ec3d358c 667 printf_unfiltered ("Architecture `%s' not recognized.\n",
b4a20239
AC
668 set_architecture_string);
669 }
670 else
671 {
672 const struct bfd_arch_info *arch
673 = bfd_scan_arch (set_architecture_string);
674 if (arch == NULL)
8e65ff28
AC
675 internal_error (__FILE__, __LINE__,
676 "set_architecture: bfd_scan_arch failed");
b4a20239
AC
677 set_arch (arch, set_arch_manual);
678 }
679 show_architecture (NULL, from_tty);
680}
681
b7d6b182 682/* Set the dynamic target-system-dependent parameters (architecture,
b4a20239
AC
683 byte-order) using information found in the BFD */
684
685void
fba45db2 686set_gdbarch_from_file (bfd *abfd)
b4a20239
AC
687{
688 if (GDB_MULTI_ARCH)
689 {
690 struct gdbarch_info info;
fb6ecb0f 691 gdbarch_info_init (&info);
b4a20239 692 info.abfd = abfd;
16f33e29 693 if (! gdbarch_update_p (info))
ec3d358c 694 error ("Architecture of file not recognized.\n");
b4a20239
AC
695 }
696 else
697 {
698 set_architecture_from_file (abfd);
699 set_endian_from_file (abfd);
700 }
701}
702
703/* Initialize the current architecture. Update the ``set
704 architecture'' command so that it specifies a list of valid
705 architectures. */
706
1ba607ad
AC
707#ifdef DEFAULT_BFD_ARCH
708extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
709static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
710#else
4b9b3959 711static const bfd_arch_info_type *default_bfd_arch;
1ba607ad
AC
712#endif
713
714#ifdef DEFAULT_BFD_VEC
715extern const bfd_target DEFAULT_BFD_VEC;
716static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
717#else
718static const bfd_target *default_bfd_vec;
719#endif
720
b4a20239
AC
721void
722initialize_current_architecture (void)
723{
724 const char **arches = gdbarch_printable_names ();
b4a20239 725
1ba607ad
AC
726 /* determine a default architecture and byte order. */
727 struct gdbarch_info info;
fb6ecb0f 728 gdbarch_info_init (&info);
1ba607ad
AC
729
730 /* Find a default architecture. */
731 if (info.bfd_arch_info == NULL
732 && default_bfd_arch != NULL)
733 info.bfd_arch_info = default_bfd_arch;
734 if (info.bfd_arch_info == NULL)
b4a20239 735 {
1ba607ad
AC
736 /* Choose the architecture by taking the first one
737 alphabetically. */
738 const char *chosen = arches[0];
b4a20239 739 const char **arch;
b4a20239
AC
740 for (arch = arches; *arch != NULL; arch++)
741 {
b4a20239
AC
742 if (strcmp (*arch, chosen) < 0)
743 chosen = *arch;
744 }
745 if (chosen == NULL)
8e65ff28
AC
746 internal_error (__FILE__, __LINE__,
747 "initialize_current_architecture: No arch");
b4a20239
AC
748 info.bfd_arch_info = bfd_scan_arch (chosen);
749 if (info.bfd_arch_info == NULL)
8e65ff28
AC
750 internal_error (__FILE__, __LINE__,
751 "initialize_current_architecture: Arch not found");
1ba607ad
AC
752 }
753
afe64c1a 754 /* Take several guesses at a byte order. */
428721aa 755 if (info.byte_order == BFD_ENDIAN_UNKNOWN
1ba607ad
AC
756 && default_bfd_vec != NULL)
757 {
758 /* Extract BFD's default vector's byte order. */
759 switch (default_bfd_vec->byteorder)
760 {
761 case BFD_ENDIAN_BIG:
d7449b42 762 info.byte_order = BFD_ENDIAN_BIG;
1ba607ad
AC
763 break;
764 case BFD_ENDIAN_LITTLE:
778eb05e 765 info.byte_order = BFD_ENDIAN_LITTLE;
1ba607ad
AC
766 break;
767 default:
768 break;
769 }
770 }
428721aa 771 if (info.byte_order == BFD_ENDIAN_UNKNOWN)
1ba607ad
AC
772 {
773 /* look for ``*el-*'' in the target name. */
774 const char *chp;
775 chp = strchr (target_name, '-');
776 if (chp != NULL
777 && chp - 2 >= target_name
778 && strncmp (chp - 2, "el", 2) == 0)
778eb05e 779 info.byte_order = BFD_ENDIAN_LITTLE;
1ba607ad 780 }
428721aa 781 if (info.byte_order == BFD_ENDIAN_UNKNOWN)
1ba607ad
AC
782 {
783 /* Wire it to big-endian!!! */
d7449b42 784 info.byte_order = BFD_ENDIAN_BIG;
1ba607ad
AC
785 }
786
787 if (GDB_MULTI_ARCH)
788 {
16f33e29
AC
789 if (! gdbarch_update_p (info))
790 {
8e65ff28
AC
791 internal_error (__FILE__, __LINE__,
792 "initialize_current_architecture: Selection of initial architecture failed");
16f33e29 793 }
b4a20239 794 }
ceaa8edf 795 else
afe64c1a
AC
796 {
797 /* If the multi-arch logic comes up with a byte-order (from BFD)
798 use it for the non-multi-arch case. */
799 if (info.byte_order != BFD_ENDIAN_UNKNOWN)
800 target_byte_order = info.byte_order;
801 initialize_non_multiarch ();
802 }
b4a20239 803
1ba607ad
AC
804 /* Create the ``set architecture'' command appending ``auto'' to the
805 list of architectures. */
b4a20239
AC
806 {
807 struct cmd_list_element *c;
808 /* Append ``auto''. */
809 int nr;
810 for (nr = 0; arches[nr] != NULL; nr++);
811 arches = xrealloc (arches, sizeof (char*) * (nr + 2));
812 arches[nr + 0] = "auto";
813 arches[nr + 1] = NULL;
814 /* FIXME: add_set_enum_cmd() uses an array of ``char *'' instead
815 of ``const char *''. We just happen to know that the casts are
816 safe. */
817 c = add_set_enum_cmd ("architecture", class_support,
53904c9e 818 arches, &set_architecture_string,
b4a20239
AC
819 "Set architecture of target.",
820 &setlist);
9f60d481 821 set_cmd_sfunc (c, set_architecture);
b4a20239
AC
822 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
823 /* Don't use set_from_show - need to print both auto/manual and
824 current setting. */
825 add_cmd ("architecture", class_support, show_architecture,
826 "Show the current target architecture", &showlist);
b4a20239
AC
827 }
828}
829
830
fb6ecb0f
AC
831/* Initialize a gdbarch info to values that will be automatically
832 overridden. Note: Originally, this ``struct info'' was initialized
833 using memset(0). Unfortunatly, that ran into problems, namely
834 BFD_ENDIAN_BIG is zero. An explicit initialization function that
835 can explicitly set each field to a well defined value is used. */
836
837void
838gdbarch_info_init (struct gdbarch_info *info)
839{
840 memset (info, 0, sizeof (struct gdbarch_info));
428721aa 841 info->byte_order = BFD_ENDIAN_UNKNOWN;
fb6ecb0f
AC
842}
843
c0e8c252
AC
844/* */
845
b4a20239 846extern initialize_file_ftype _initialize_gdbarch_utils;
c0e8c252
AC
847
848void
b4a20239 849_initialize_gdbarch_utils (void)
c0e8c252 850{
b4a20239
AC
851 struct cmd_list_element *c;
852 c = add_set_enum_cmd ("endian", class_support,
853 endian_enum, &set_endian_string,
854 "Set endianness of target.",
855 &setlist);
9f60d481 856 set_cmd_sfunc (c, set_endian);
b4a20239
AC
857 /* Don't use set_from_show - need to print both auto/manual and
858 current setting. */
859 add_cmd ("endian", class_support, show_endian,
860 "Show the current byte-order", &showlist);
c0e8c252 861}
This page took 0.172688 seconds and 4 git commands to generate.