1 /* Semi-dynamic architecture support for GDB, the GNU debugger.
2 Copyright 1998, Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 /* start-sanitize-carp start-sanitize-vr4xxx */
26 /* Convenience macro for allocting memory. */
29 #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
32 /* end-sanitize-carp end-sanitize-vr4xxx */
34 /* Non-zero if we want to trace architecture code. */
37 #define GDBARCH_DEBUG 0
39 int gdbarch_debug
= GDBARCH_DEBUG
;
41 /* start-sanitize-carp start-sanitize-vr4xxx */
43 /* Maintain the struct gdbarch object */
47 /* basic architectural information */
48 const struct bfd_arch_info
*bfd_arch_info
;
51 /* target specific vector. */
52 struct gdbarch_tdep
*tdep
;
54 /* per-architecture data-pointers */
58 /* per-architecture swap-regions */
59 struct gdbarch_swap
*swap
;
63 When adding to the below you must also: declare/define set/get
64 value functions; override the corresponding macro in gdbarch.h;
65 initialize the value in gdbarch_alloc() (if zero is an unsuitable
66 default); confirm that the target updated the value correctly in
67 verify_gdbarch(); add a fprintf_unfiltered call to
68 gdbarch_update() so that the new field is dumped out; append an
69 initial value to the static variable DEFAULT_GDBARCH (base values
70 on the host's c-type system). */
80 gdbarch_tdep (gdbarch
)
81 struct gdbarch
*gdbarch
;
86 const struct bfd_arch_info
*
87 gdbarch_bfd_arch_info (gdbarch
)
88 struct gdbarch
*gdbarch
;
90 return gdbarch
->bfd_arch_info
;
94 gdbarch_byte_order (gdbarch
)
95 struct gdbarch
*gdbarch
;
97 return gdbarch
->byte_order
;
101 gdbarch_long_bit (gdbarch
)
102 struct gdbarch
*gdbarch
;
104 return gdbarch
->long_bit
;
108 set_gdbarch_long_bit (gdbarch
, long_bit
)
109 struct gdbarch
*gdbarch
;
112 gdbarch
->long_bit
= long_bit
;
116 gdbarch_long_long_bit (gdbarch
)
117 struct gdbarch
*gdbarch
;
119 return gdbarch
->long_long_bit
;
123 set_gdbarch_long_long_bit (gdbarch
, long_long_bit
)
124 struct gdbarch
*gdbarch
;
127 gdbarch
->long_long_bit
= long_long_bit
;
131 gdbarch_ptr_bit (gdbarch
)
132 struct gdbarch
*gdbarch
;
134 return gdbarch
->ptr_bit
;
138 set_gdbarch_ptr_bit (gdbarch
, ptr_bit
)
139 struct gdbarch
*gdbarch
;
142 gdbarch
->ptr_bit
= ptr_bit
;
146 /* Ensure that all values in a GDBARCH are reasonable. XXX - should
147 this instead return a success/fail indication? */
150 verify_gdbarch (gdbarch
)
151 struct gdbarch
*gdbarch
;
154 if (gdbarch
->byte_order
== 0)
155 fatal ("verify_gdbarch: byte-order unset");
156 if (gdbarch
->bfd_arch_info
== NULL
)
157 fatal ("verify_gdbarch: bfd_arch_info unset");
159 if (gdbarch
->long_bit
== 0)
160 fatal ("verify_gdbarch: long_bit invalid");
161 if (gdbarch
->long_long_bit
== 0)
162 fatal ("verify_gdbarch: long_long_bit invalid");
163 if (gdbarch
->ptr_bit
== 0)
164 fatal ("verify_gdbarch: ptr_bit invalid");
168 /* Keep a registrary of per-architecture data-pointers required by GDB
176 struct gdbarch_data_registration
178 gdbarch_data_ftype
*init
;
179 struct gdbarch_data
*data
;
180 struct gdbarch_data_registration
*next
;
183 struct gdbarch_data_registrary
186 struct gdbarch_data_registration
*registrations
;
189 struct gdbarch_data_registrary gdbarch_data_registrary
=
194 struct gdbarch_data
*
195 register_gdbarch_data (init
)
196 gdbarch_data_ftype
*init
;
198 struct gdbarch_data_registration
**curr
;
199 for (curr
= &gdbarch_data_registrary
.registrations
;
201 curr
= &(*curr
)->next
);
202 (*curr
) = XMALLOC (struct gdbarch_data_registration
);
203 (*curr
)->next
= NULL
;
204 (*curr
)->init
= init
;
205 (*curr
)->data
= XMALLOC (struct gdbarch_data
);
206 (*curr
)->data
->index
= gdbarch_data_registrary
.nr
++;
207 return (*curr
)->data
;
211 /* Walk through all the registered users initializing each in turn. */
213 static void init_gdbarch_data
PARAMS ((struct gdbarch
*));
215 init_gdbarch_data (gdbarch
)
216 struct gdbarch
*gdbarch
;
218 struct gdbarch_data_registration
*rego
;
219 gdbarch
->nr_data
= gdbarch_data_registrary
.nr
+ 1;
220 gdbarch
->data
= xmalloc (sizeof (void*) * gdbarch
->nr_data
);
221 for (rego
= gdbarch_data_registrary
.registrations
;
225 if (rego
->data
->index
< gdbarch
->nr_data
)
226 gdbarch
->data
[rego
->data
->index
] = rego
->init ();
231 /* Return the current value of the specified per-architecture
236 struct gdbarch_data
*data
;
238 if (data
->index
>= current_gdbarch
->nr_data
)
239 fatal ("gdbarch_data: request for non-existant data.");
240 return current_gdbarch
->data
[data
->index
];
245 /* Keep a registrary of swaped data required by GDB modules. */
250 struct gdbarch_swap_registration
*source
;
251 struct gdbarch_swap
*next
;
254 struct gdbarch_swap_registration
257 unsigned long sizeof_data
;
258 gdbarch_swap_ftype
*init
;
259 struct gdbarch_swap_registration
*next
;
262 struct gdbarch_swap_registrary
265 struct gdbarch_swap_registration
*registrations
;
268 struct gdbarch_swap_registrary gdbarch_swap_registrary
=
274 register_gdbarch_swap (data
, sizeof_data
, init
)
276 unsigned long sizeof_data
;
277 gdbarch_swap_ftype
*init
;
279 struct gdbarch_swap_registration
**rego
;
280 for (rego
= &gdbarch_swap_registrary
.registrations
;
282 rego
= &(*rego
)->next
);
283 (*rego
) = XMALLOC (struct gdbarch_swap_registration
);
284 (*rego
)->next
= NULL
;
285 (*rego
)->init
= init
;
286 (*rego
)->data
= data
;
287 (*rego
)->sizeof_data
= sizeof_data
;
291 static void init_gdbarch_swap
PARAMS ((struct gdbarch
*));
293 init_gdbarch_swap (gdbarch
)
294 struct gdbarch
*gdbarch
;
296 struct gdbarch_swap_registration
*rego
;
297 struct gdbarch_swap
**curr
= &gdbarch
->swap
;
298 for (rego
= gdbarch_swap_registrary
.registrations
;
302 if (rego
->data
!= NULL
)
304 (*curr
) = XMALLOC (struct gdbarch_swap
);
305 (*curr
)->source
= rego
;
306 (*curr
)->swap
= xmalloc (rego
->sizeof_data
);
307 (*curr
)->next
= NULL
;
308 memset (rego
->data
, 0, rego
->sizeof_data
);
309 curr
= &(*curr
)->next
;
311 if (rego
->init
!= NULL
)
316 static void swapout_gdbarch_swap
PARAMS ((struct gdbarch
*));
318 swapout_gdbarch_swap (gdbarch
)
319 struct gdbarch
*gdbarch
;
321 struct gdbarch_swap
*curr
;
322 for (curr
= gdbarch
->swap
;
325 memcpy (curr
->swap
, curr
->source
->data
, curr
->source
->sizeof_data
);
328 static void swapin_gdbarch_swap
PARAMS ((struct gdbarch
*));
330 swapin_gdbarch_swap (gdbarch
)
331 struct gdbarch
*gdbarch
;
333 struct gdbarch_swap
*curr
;
334 for (curr
= gdbarch
->swap
;
337 memcpy (curr
->source
->data
, curr
->swap
, curr
->source
->sizeof_data
);
341 /* Keep a registrary of the architectures known by GDB. */
343 struct gdbarch_init_registration
345 enum bfd_architecture bfd_architecture
;
346 gdbarch_init_ftype
*init
;
347 struct gdbarch_list
*arches
;
348 struct gdbarch_init_registration
*next
;
351 static struct gdbarch_init_registration
*gdbarch_init_registrary
= NULL
;
354 register_gdbarch_init (bfd_architecture
, init
)
355 enum bfd_architecture bfd_architecture
;
356 gdbarch_init_ftype
*init
;
358 struct gdbarch_init_registration
**curr
;
359 const struct bfd_arch_info
*bfd_arch_info
;
360 /* Check that BFD reconizes this architecture */
361 bfd_arch_info
= bfd_lookup_arch (bfd_architecture
, 0);
362 if (bfd_arch_info
== NULL
)
364 fatal ("Attempt to register unknown architecture (%d)", bfd_architecture
);
366 /* Check that we haven't seen this architecture before */
367 for (curr
= &gdbarch_init_registrary
;
369 curr
= &(*curr
)->next
)
371 if (bfd_architecture
== (*curr
)->bfd_architecture
)
372 fatal ("Duplicate registraration of architecture (%s)",
373 bfd_arch_info
->printable_name
);
377 fprintf_unfiltered (stderr
, "register_gdbarch_init (%s, 0x%08lx)\n",
378 bfd_arch_info
->printable_name
,
381 (*curr
) = XMALLOC (struct gdbarch_init_registration
);
382 (*curr
)->bfd_architecture
= bfd_architecture
;
383 (*curr
)->init
= init
;
384 (*curr
)->arches
= NULL
;
385 (*curr
)->next
= NULL
;
390 /* Look for an architecture using gdbarch_info. Base search on only
391 BFD_ARCH_INFO and BYTE_ORDER. */
393 struct gdbarch_list
*
394 gdbarch_list_lookup_by_info (arches
, info
)
395 struct gdbarch_list
*arches
;
396 const struct gdbarch_info
*info
;
398 for (; arches
!= NULL
; arches
= arches
->next
)
400 if (info
->bfd_arch_info
!= arches
->gdbarch
->bfd_arch_info
)
402 if (info
->byte_order
!= arches
->gdbarch
->byte_order
)
410 /* Create a new ``struct gdbarch'' based in information provied by
411 ``struct gdbarch_info'' */
414 gdbarch_alloc (info
, tdep
)
415 const struct gdbarch_info
*info
;
416 struct gdbarch_tdep
*tdep
;
418 struct gdbarch
*gdbarch
= XMALLOC (struct gdbarch
);
419 memset (gdbarch
, 0, sizeof (*gdbarch
));
421 gdbarch
->tdep
= tdep
;
423 gdbarch
->bfd_arch_info
= info
->bfd_arch_info
;
424 gdbarch
->byte_order
= info
->byte_order
;
429 /* Update the current architecture. Return ZERO if the update request
433 gdbarch_update (info
)
434 struct gdbarch_info info
;
436 struct gdbarch
*new_gdbarch
;
437 struct gdbarch_list
**list
;
438 struct gdbarch_init_registration
*rego
;
440 /* Fill in any missing bits. Most important is the bfd_architecture
441 which is used to select the target architecture. */
442 if (info
.bfd_architecture
== bfd_arch_unknown
)
444 if (info
.bfd_arch_info
!= NULL
)
445 info
.bfd_architecture
= info
.bfd_arch_info
->arch
;
446 else if (info
.abfd
!= NULL
)
447 info
.bfd_architecture
= bfd_get_arch (info
.abfd
);
448 /* FIXME - should query BFD for its default architecture. */
450 info
.bfd_architecture
= current_gdbarch
->bfd_arch_info
->arch
;
452 if (info
.bfd_arch_info
== NULL
)
454 if (target_architecture_auto
&& info
.abfd
!= NULL
)
455 info
.bfd_arch_info
= bfd_get_arch_info (info
.abfd
);
457 info
.bfd_arch_info
= current_gdbarch
->bfd_arch_info
;
459 if (info
.byte_order
== 0)
461 if (target_byte_order_auto
&& info
.abfd
!= NULL
)
462 info
.byte_order
= (bfd_big_endian (info
.abfd
) ? BIG_ENDIAN
463 : bfd_little_endian (info
.abfd
) ? LITTLE_ENDIAN
466 info
.byte_order
= current_gdbarch
->byte_order
;
468 /* A default for abfd? */
470 /* Find the target that knows about this architecture. */
471 for (rego
= gdbarch_init_registrary
;
472 rego
!= NULL
&& rego
->bfd_architecture
!= info
.bfd_architecture
;
477 fprintf_unfiltered (stderr
, "gdbarch_update: No matching architecture\n");
481 /* Ask the target for a replacement architecture. */
482 new_gdbarch
= rego
->init (&info
, rego
->arches
);
484 /* Did the target like it? No. Reject the change. */
485 if (new_gdbarch
== NULL
)
488 fprintf_unfiltered (stderr
, "gdbarch_update: Target rejected architecture\n");
492 /* Did the architecture change? No. Do nothing. */
493 if (current_gdbarch
== new_gdbarch
)
496 fprintf_unfiltered (stderr
, "gdbarch_update: Architecture 0x%08lx (%s) unchanged\n",
498 new_gdbarch
->bfd_arch_info
->printable_name
);
502 /* Swap all data belonging to the old target out */
503 swapout_gdbarch_swap (current_gdbarch
);
505 /* Is this a pre-existing architecture? Yes. Swap it in. */
506 for (list
= ®o
->arches
;
508 list
= &(*list
)->next
)
510 if ((*list
)->gdbarch
== new_gdbarch
)
513 fprintf_unfiltered (stderr
, "gdbarch_update: Previous architecture 0x%08lx (%s) selected\n",
515 new_gdbarch
->bfd_arch_info
->printable_name
);
516 current_gdbarch
= new_gdbarch
;
517 swapin_gdbarch_swap (new_gdbarch
);
522 /* Append this new architecture to this targets list. */
523 (*list
) = XMALLOC (struct gdbarch_list
);
524 (*list
)->next
= NULL
;
525 (*list
)->gdbarch
= new_gdbarch
;
527 /* Switch to this new architecture. Dump it out. */
528 current_gdbarch
= new_gdbarch
;
531 fprintf_unfiltered (stderr
, "gdbarch_update: New architecture 0x%08lx (%s) selected\n",
533 new_gdbarch
->bfd_arch_info
->printable_name
);
534 fprintf_unfiltered (stderr
, "TARGET_BYTE_ORDER = %d\n", TARGET_BYTE_ORDER
);
535 fprintf_unfiltered (stderr
, "TARGET_LONG_BIT = %d\n", TARGET_LONG_BIT
);
536 fprintf_unfiltered (stderr
, "TARGET_LONG_LONG_BIT = %d\n", TARGET_LONG_LONG_BIT
);
537 fprintf_unfiltered (stderr
, "TARGET_PTR_BIT = %d\n", TARGET_PTR_BIT
);
540 /* Check that the newly installed architecture is valid. */
541 verify_gdbarch (new_gdbarch
);
543 /* Initialize the per-architecture memory (swap) areas.
544 CURRENT_GDBARCH must be update before these modules are
546 init_gdbarch_swap (new_gdbarch
);
548 /* Initialize the per-architecture data-pointer of all parties that
549 registered an interest in this architecture. CURRENT_GDBARCH
550 must be updated before these modules are called. */
551 init_gdbarch_data (new_gdbarch
);
557 /* end-sanitize-carp end-sanitize-vr4xxx */
559 /* Functions to manipulate the endianness of the target. */
561 #ifdef TARGET_BYTE_ORDER_SELECTABLE
562 /* compat - Catch old targets that expect a selectable byte-order to
563 default to BIG_ENDIAN */
564 #ifndef TARGET_BYTE_ORDER_DEFAULT
565 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
568 #ifndef TARGET_BYTE_ORDER_DEFAULT
569 /* compat - Catch old non byte-order selectable targets that do not
570 define TARGET_BYTE_ORDER_DEFAULT and instead expect
571 TARGET_BYTE_ORDER to be used as the default. For targets that
572 defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
573 below will get a strange compiler warning. */
574 #define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
576 int target_byte_order
= TARGET_BYTE_ORDER_DEFAULT
;
577 int target_byte_order_auto
= 1;
579 /* Chain containing the \"set endian\" commands. */
580 static struct cmd_list_element
*endianlist
= NULL
;
582 /* Called by ``show endian''. */
583 static void show_endian
PARAMS ((char *, int));
585 show_endian (args
, from_tty
)
590 (TARGET_BYTE_ORDER_AUTO
591 ? "The target endianness is set automatically (currently %s endian)\n"
592 : "The target is assumed to be %s endian\n");
593 printf_unfiltered (msg
, (TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little"));
596 /* Called if the user enters ``set endian'' without an argument. */
597 static void set_endian
PARAMS ((char *, int));
599 set_endian (args
, from_tty
)
603 printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
604 show_endian (args
, from_tty
);
607 /* Called by ``set endian big''. */
608 static void set_endian_big
PARAMS ((char *, int));
610 set_endian_big (args
, from_tty
)
614 if (TARGET_BYTE_ORDER_SELECTABLE_P
)
616 target_byte_order
= BIG_ENDIAN
;
617 target_byte_order_auto
= 0;
618 /* start-sanitize-carp start-sanitize-vr4xxx */
621 struct gdbarch_info info
;
622 memset (&info
, 0, sizeof info
);
623 info
.byte_order
= BIG_ENDIAN
;
624 gdbarch_update (info
);
626 /* end-sanitize-carp end-sanitize-vr4xxx */
630 printf_unfiltered ("Byte order is not selectable.");
631 show_endian (args
, from_tty
);
635 /* Called by ``set endian little''. */
636 static void set_endian_little
PARAMS ((char *, int));
638 set_endian_little (args
, from_tty
)
642 if (TARGET_BYTE_ORDER_SELECTABLE_P
)
644 target_byte_order
= LITTLE_ENDIAN
;
645 target_byte_order_auto
= 0;
646 /* start-sanitize-carp start-sanitize-vr4xxx */
649 struct gdbarch_info info
;
650 memset (&info
, 0, sizeof info
);
651 info
.byte_order
= LITTLE_ENDIAN
;
652 gdbarch_update (info
);
654 /* end-sanitize-carp end-sanitize-vr4xxx */
658 printf_unfiltered ("Byte order is not selectable.");
659 show_endian (args
, from_tty
);
663 /* Called by ``set endian auto''. */
664 static void set_endian_auto
PARAMS ((char *, int));
666 set_endian_auto (args
, from_tty
)
670 if (TARGET_BYTE_ORDER_SELECTABLE_P
)
672 target_byte_order_auto
= 1;
676 printf_unfiltered ("Byte order is not selectable.");
677 show_endian (args
, from_tty
);
681 /* Set the endianness from a BFD. */
682 static void set_endian_from_file
PARAMS ((bfd
*));
684 set_endian_from_file (abfd
)
687 if (TARGET_BYTE_ORDER_SELECTABLE_P
)
691 if (bfd_big_endian (abfd
))
694 want
= LITTLE_ENDIAN
;
695 if (TARGET_BYTE_ORDER_AUTO
)
696 target_byte_order
= want
;
697 else if (TARGET_BYTE_ORDER
!= want
)
698 warning ("%s endian file does not match %s endian target.",
699 want
== BIG_ENDIAN
? "big" : "little",
700 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
704 if (bfd_big_endian (abfd
)
705 ? TARGET_BYTE_ORDER
!= BIG_ENDIAN
706 : TARGET_BYTE_ORDER
== BIG_ENDIAN
)
707 warning ("%s endian file does not match %s endian target.",
708 bfd_big_endian (abfd
) ? "big" : "little",
709 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
715 /* Functions to manipulate the architecture of the target */
717 int target_architecture_auto
= 1;
718 extern const struct bfd_arch_info bfd_default_arch_struct
;
719 const struct bfd_arch_info
*target_architecture
= &bfd_default_arch_struct
;
720 int (*target_architecture_hook
) PARAMS ((const struct bfd_arch_info
*ap
));
722 /* Do the real work of changing the current architecture */
725 const struct bfd_arch_info
*arch
;
727 /* FIXME: Is it compatible with gdb? */
728 /* Check with the target on the setting */
729 if (target_architecture_hook
!= NULL
730 && !target_architecture_hook (arch
))
731 printf_unfiltered ("Target does not support `%s' architecture.\n",
732 arch
->printable_name
);
735 target_architecture_auto
= 0;
736 target_architecture
= arch
;
740 /* Called if the user enters ``show architecture'' without an argument. */
741 static void show_architecture
PARAMS ((char *, int));
743 show_architecture (args
, from_tty
)
748 arch
= TARGET_ARCHITECTURE
->printable_name
;
749 if (target_architecture_auto
)
750 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch
);
752 printf_filtered ("The target architecture is assumed to be %s\n", arch
);
755 /* Called if the user enters ``set architecture'' with or without an
757 static void set_architecture
PARAMS ((char *, int));
759 set_architecture (args
, from_tty
)
765 printf_unfiltered ("\"set architecture\" must be followed by \"auto\" or an architecture name.\n");
767 else if (strcmp (args
, "auto") == 0)
769 target_architecture_auto
= 1;
771 /* start-sanitize-carp start-sanitize-vr4xxx */
772 else if (GDB_MULTI_ARCH
)
774 const struct bfd_arch_info
*arch
= bfd_scan_arch (args
);
776 printf_unfiltered ("Architecture `%s' not reconized.\n", args
);
779 struct gdbarch_info info
;
780 memset (&info
, 0, sizeof info
);
781 info
.bfd_arch_info
= arch
;
782 if (gdbarch_update (info
))
783 target_architecture_auto
= 0;
785 printf_unfiltered ("Architecture `%s' not reconized.\n", args
);
788 /* end-sanitize-carp end-sanitize-vr4xxx */
791 const struct bfd_arch_info
*arch
= bfd_scan_arch (args
);
795 printf_unfiltered ("Architecture `%s' not reconized.\n", args
);
799 /* Called if the user enters ``info architecture'' without an argument. */
800 static void info_architecture
PARAMS ((char *, int));
802 info_architecture (args
, from_tty
)
806 enum bfd_architecture a
;
807 /* start-sanitize-carp start-sanitize-vr4xxx */
810 if (gdbarch_init_registrary
!= NULL
)
812 struct gdbarch_init_registration
*rego
;
813 printf_filtered ("Available architectures are:\n");
814 for (rego
= gdbarch_init_registrary
;
818 const struct bfd_arch_info
*ap
;
819 ap
= bfd_lookup_arch (rego
->bfd_architecture
, 0);
824 printf_filtered (" %s", ap
->printable_name
);
828 printf_filtered ("\n");
834 printf_filtered ("There are no available architectures.\n");
838 /* end-sanitize-carp end-sanitize-vr4xxx */
839 printf_filtered ("Available architectures are:\n");
840 for (a
= bfd_arch_obscure
+ 1; a
< bfd_arch_last
; a
++)
842 const struct bfd_arch_info
*ap
= bfd_lookup_arch (a
, 0);
847 printf_filtered (" %s", ap
->printable_name
);
851 printf_filtered ("\n");
856 /* Set the architecture from arch/machine */
858 set_architecture_from_arch_mach (arch
, mach
)
859 enum bfd_architecture arch
;
862 const struct bfd_arch_info
*wanted
= bfd_lookup_arch (arch
, mach
);
866 fatal ("hardwired architecture/machine not reconized");
869 /* Set the architecture from a BFD */
870 static void set_architecture_from_file
PARAMS ((bfd
*));
872 set_architecture_from_file (abfd
)
875 const struct bfd_arch_info
*wanted
= bfd_get_arch_info (abfd
);
876 if (target_architecture_auto
)
878 if (target_architecture_hook
!= NULL
879 && !target_architecture_hook (wanted
))
880 warning ("Target may not support %s architecture",
881 wanted
->printable_name
);
882 target_architecture
= wanted
;
884 else if (wanted
!= target_architecture
)
886 warning ("%s architecture file may be incompatible with %s target.",
887 wanted
->printable_name
,
888 target_architecture
->printable_name
);
896 /* Pointer to the target-dependent disassembly function. */
897 int (*tm_print_insn
) PARAMS ((bfd_vma
, disassemble_info
*));
898 disassemble_info tm_print_insn_info
;
902 /* Set the dynamic target-system-dependant parameters (architecture,
903 byte-order) using information found in the BFD */
906 set_gdbarch_from_file (abfd
)
909 /* start-sanitize-carp start-sanitize-vr4xxx */
912 struct gdbarch_info info
;
913 memset (&info
, 0, sizeof info
);
915 gdbarch_update (info
);
918 /* end-sanitize-carp end-sanitize-vr4xxx */
919 set_architecture_from_file (abfd
);
920 set_endian_from_file (abfd
);
923 /* start-sanitize-carp start-sanitize-vr4xxx */
925 /* The default architecture uses host values (for want of a better
928 struct gdbarch default_gdbarch
= {
929 /* basic architecture information */
930 &bfd_default_arch_struct
,
931 TARGET_BYTE_ORDER_DEFAULT
,
932 /* target specific vector */
934 /*per-architecture data-pointers and swap regions */
936 /* Multi-arch values */
937 8 * sizeof (long), /* long */
938 8 * sizeof (LONGEST
), /* long long */
939 8 * sizeof (void*), /* ptr */
941 struct gdbarch
*current_gdbarch
= &default_gdbarch
;
943 /* end-sanitize-carp end-sanitize-vr4xxx */
945 extern void _initialize_gdbarch
PARAMS ((void));
947 _initialize_gdbarch ()
949 add_prefix_cmd ("endian", class_support
, set_endian
,
950 "Set endianness of target.",
951 &endianlist
, "set endian ", 0, &setlist
);
952 add_cmd ("big", class_support
, set_endian_big
,
953 "Set target as being big endian.", &endianlist
);
954 add_cmd ("little", class_support
, set_endian_little
,
955 "Set target as being little endian.", &endianlist
);
956 add_cmd ("auto", class_support
, set_endian_auto
,
957 "Select target endianness automatically.", &endianlist
);
958 add_cmd ("endian", class_support
, show_endian
,
959 "Show endianness of target.", &showlist
);
961 add_cmd ("architecture", class_support
, set_architecture
,
962 "Set architecture of target.", &setlist
);
963 add_alias_cmd ("processor", "architecture", class_support
, 1, &setlist
);
964 add_cmd ("architecture", class_support
, show_architecture
,
965 "Show architecture of target.", &showlist
);
966 add_cmd ("architecture", class_support
, info_architecture
,
967 "List supported target architectures", &infolist
);
969 INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info
, gdb_stdout
, (fprintf_ftype
)fprintf_filtered
);
970 tm_print_insn_info
.flavour
= bfd_target_unknown_flavour
;
971 tm_print_insn_info
.read_memory_func
= dis_asm_read_memory
;
972 tm_print_insn_info
.memory_error_func
= dis_asm_memory_error
;
973 tm_print_insn_info
.print_address_func
= dis_asm_print_address
;
975 #ifdef MAINTENANCE_CMDS
976 add_show_from_set (add_set_cmd ("archdebug",
979 (char *)&gdbarch_debug
,
980 "Set architecture debugging.\n\
981 When non-zero, architecture debugging is enabled.", &setlist
),