xref: /netbsd-src/external/gpl3/binutils.old/dist/bfd/cpu-arc.c (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos /* BFD support for the ARC processor
2*e992f068Schristos    Copyright (C) 1994-2022 Free Software Foundation, Inc.
375fd0b74Schristos    Contributed by Doug Evans (dje@cygnus.com).
475fd0b74Schristos 
575fd0b74Schristos    This file is part of BFD, the Binary File Descriptor library.
675fd0b74Schristos 
775fd0b74Schristos    This program is free software; you can redistribute it and/or modify
875fd0b74Schristos    it under the terms of the GNU General Public License as published by
975fd0b74Schristos    the Free Software Foundation; either version 3 of the License, or
1075fd0b74Schristos    (at your option) any later version.
1175fd0b74Schristos 
1275fd0b74Schristos    This program is distributed in the hope that it will be useful,
1375fd0b74Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1475fd0b74Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1575fd0b74Schristos    GNU General Public License for more details.
1675fd0b74Schristos 
1775fd0b74Schristos    You should have received a copy of the GNU General Public License
1875fd0b74Schristos    along with this program; if not, write to the Free Software
1975fd0b74Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
2075fd0b74Schristos    MA 02110-1301, USA.  */
2175fd0b74Schristos 
2275fd0b74Schristos #include "sysdep.h"
2375fd0b74Schristos #include "bfd.h"
2475fd0b74Schristos #include "libbfd.h"
2575fd0b74Schristos 
26ede78133Schristos static const bfd_arch_info_type *
27ede78133Schristos arc_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b);
28ede78133Schristos 
2975fd0b74Schristos #define ARC(mach, print_name, default_p, next) \
3075fd0b74Schristos   {					       \
31012573ebSchristos     32,	/* Bits in a word.  */		\
32012573ebSchristos     32,	/* Bits in an address.  */	\
33012573ebSchristos     8,	/* Bits in a byte.  */		\
3475fd0b74Schristos     bfd_arch_arc,			\
3575fd0b74Schristos     mach,				\
3675fd0b74Schristos     "arc",				\
3775fd0b74Schristos     print_name,				\
38012573ebSchristos     4, /* Section alignment power.  */	\
3975fd0b74Schristos     default_p,				\
40ede78133Schristos     arc_compatible,			\
4175fd0b74Schristos     bfd_default_scan,			\
4275fd0b74Schristos     bfd_arch_default_fill,		\
4375fd0b74Schristos     next,				\
44012573ebSchristos     0 /* Maximum offset of a reloc from the start of an insn.  */ \
4575fd0b74Schristos   }
4675fd0b74Schristos 
4775fd0b74Schristos static const bfd_arch_info_type arch_info_struct[] =
4875fd0b74Schristos {
49*e992f068Schristos   ARC (bfd_mach_arc_arc600, "A6"    , false, &arch_info_struct[1]),
50*e992f068Schristos   ARC (bfd_mach_arc_arc601, "ARC601", false, &arch_info_struct[2]),
51*e992f068Schristos   ARC (bfd_mach_arc_arc700, "ARC700", false, &arch_info_struct[3]),
52*e992f068Schristos   ARC (bfd_mach_arc_arc700, "A7",     false, &arch_info_struct[4]),
53*e992f068Schristos   ARC (bfd_mach_arc_arcv2,  "ARCv2",  false, &arch_info_struct[5]),
54*e992f068Schristos   ARC (bfd_mach_arc_arcv2,  "EM",     false, &arch_info_struct[6]),
55*e992f068Schristos   ARC (bfd_mach_arc_arcv2,  "HS",     false, NULL),
5675fd0b74Schristos };
5775fd0b74Schristos 
5875fd0b74Schristos const bfd_arch_info_type bfd_arc_arch =
59*e992f068Schristos   ARC (bfd_mach_arc_arc600, "ARC600", true, &arch_info_struct[0]);
6075fd0b74Schristos 
61ede78133Schristos /* ARC-specific "compatible" function.  The general rule is that if A and B are
62ede78133Schristos    compatible, then this function should return architecture that is more
63ede78133Schristos    "feature-rich", that is, can run both A and B.  ARCv2, EM and HS all has
64ede78133Schristos    same mach number, so bfd_default_compatible assumes they are the same, and
65ede78133Schristos    returns an A.  That causes issues with GDB, because GDB assumes that if
66ede78133Schristos    machines are compatible, then "compatible ()" always returns same machine
67ede78133Schristos    regardless of argument order.  As a result GDB gets confused because, for
68ede78133Schristos    example, compatible (ARCv2, EM) returns ARCv2, but compatible (EM, ARCv2)
69ede78133Schristos    returns EM, hence GDB is not sure if they are compatible and prints a
70ede78133Schristos    warning.  */
7175fd0b74Schristos 
72ede78133Schristos static const bfd_arch_info_type *
arc_compatible(const bfd_arch_info_type * a,const bfd_arch_info_type * b)73ede78133Schristos arc_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b)
7475fd0b74Schristos {
75ede78133Schristos   const bfd_arch_info_type * const em = &arch_info_struct[5];
76ede78133Schristos   const bfd_arch_info_type * const hs = &arch_info_struct[6];
7775fd0b74Schristos 
78ede78133Schristos   /* Trivial case where a and b is the same instance.  Some callers already
79ede78133Schristos      check this condition but some do not and get an invalid result.  */
80ede78133Schristos   if (a == b)
81ede78133Schristos     return a;
82ede78133Schristos 
83ede78133Schristos   /* If a & b are for different architecture we can do nothing.  */
84ede78133Schristos   if (a->arch != b->arch)
85ede78133Schristos     return NULL;
86ede78133Schristos 
87ede78133Schristos   if (a->bits_per_word != b->bits_per_word)
88ede78133Schristos     return NULL;
89ede78133Schristos 
90ede78133Schristos   /* ARCv2|EM and EM.  */
91ede78133Schristos   if ((a->mach == bfd_mach_arc_arcv2 && b == em)
92ede78133Schristos       || (b->mach == bfd_mach_arc_arcv2 && a == em))
93ede78133Schristos     return em;
94ede78133Schristos 
95ede78133Schristos   /* ARCv2|HS and HS.  */
96ede78133Schristos   if ((a->mach == bfd_mach_arc_arcv2 && b == hs)
97ede78133Schristos       || (b->mach == bfd_mach_arc_arcv2 && a == hs))
98ede78133Schristos     return hs;
99ede78133Schristos 
100ede78133Schristos   return bfd_default_compatible (a, b);
10175fd0b74Schristos }
102