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