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