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