Home | History | Annotate | Line # | Download | only in bfd
cpu-arc.c revision 1.9
      1  1.1  christos /* BFD support for the ARC processor
      2  1.9  christos    Copyright (C) 1994-2020 Free Software Foundation, Inc.
      3  1.1  christos    Contributed by Doug Evans (dje (at) cygnus.com).
      4  1.1  christos 
      5  1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      6  1.1  christos 
      7  1.1  christos    This program is free software; you can redistribute it and/or modify
      8  1.1  christos    it under the terms of the GNU General Public License as published by
      9  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10  1.1  christos    (at your option) any later version.
     11  1.1  christos 
     12  1.1  christos    This program is distributed in the hope that it will be useful,
     13  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  1.1  christos    GNU General Public License for more details.
     16  1.1  christos 
     17  1.1  christos    You should have received a copy of the GNU General Public License
     18  1.1  christos    along with this program; if not, write to the Free Software
     19  1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     20  1.1  christos    MA 02110-1301, USA.  */
     21  1.1  christos 
     22  1.1  christos #include "sysdep.h"
     23  1.1  christos #include "bfd.h"
     24  1.1  christos #include "libbfd.h"
     25  1.1  christos 
     26  1.8  christos static const bfd_arch_info_type *
     27  1.8  christos arc_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b);
     28  1.8  christos 
     29  1.1  christos #define ARC(mach, print_name, default_p, next) \
     30  1.9  christos   {					       \
     31  1.9  christos     32,	/* Bits in a word.  */		\
     32  1.9  christos     32,	/* Bits in an address.  */	\
     33  1.9  christos     8,	/* Bits in a byte.  */		\
     34  1.1  christos     bfd_arch_arc,			\
     35  1.1  christos     mach,				\
     36  1.1  christos     "arc",				\
     37  1.1  christos     print_name,				\
     38  1.9  christos     4, /* Section alignment power.  */	\
     39  1.1  christos     default_p,				\
     40  1.8  christos     arc_compatible,			\
     41  1.1  christos     bfd_default_scan,			\
     42  1.1  christos     bfd_arch_default_fill,		\
     43  1.1  christos     next,				\
     44  1.9  christos     0 /* Maximum offset of a reloc from the start of an insn.  */ \
     45  1.1  christos   }
     46  1.1  christos 
     47  1.1  christos static const bfd_arch_info_type arch_info_struct[] =
     48  1.1  christos {
     49  1.8  christos   ARC (bfd_mach_arc_arc600, "A6"    , FALSE, &arch_info_struct[1]),
     50  1.8  christos   ARC (bfd_mach_arc_arc601, "ARC601", FALSE, &arch_info_struct[2]),
     51  1.8  christos   ARC (bfd_mach_arc_arc700, "ARC700", FALSE, &arch_info_struct[3]),
     52  1.8  christos   ARC (bfd_mach_arc_arc700, "A7",     FALSE, &arch_info_struct[4]),
     53  1.8  christos   ARC (bfd_mach_arc_arcv2,  "ARCv2",  FALSE, &arch_info_struct[5]),
     54  1.8  christos   ARC (bfd_mach_arc_arcv2,  "EM",     FALSE, &arch_info_struct[6]),
     55  1.6  christos   ARC (bfd_mach_arc_arcv2,  "HS",     FALSE, NULL),
     56  1.1  christos };
     57  1.1  christos 
     58  1.1  christos const bfd_arch_info_type bfd_arc_arch =
     59  1.6  christos   ARC (bfd_mach_arc_arc600, "ARC600", TRUE, &arch_info_struct[0]);
     60  1.8  christos 
     61  1.8  christos /* ARC-specific "compatible" function.  The general rule is that if A and B are
     62  1.8  christos    compatible, then this function should return architecture that is more
     63  1.8  christos    "feature-rich", that is, can run both A and B.  ARCv2, EM and HS all has
     64  1.8  christos    same mach number, so bfd_default_compatible assumes they are the same, and
     65  1.8  christos    returns an A.  That causes issues with GDB, because GDB assumes that if
     66  1.8  christos    machines are compatible, then "compatible ()" always returns same machine
     67  1.8  christos    regardless of argument order.  As a result GDB gets confused because, for
     68  1.8  christos    example, compatible (ARCv2, EM) returns ARCv2, but compatible (EM, ARCv2)
     69  1.8  christos    returns EM, hence GDB is not sure if they are compatible and prints a
     70  1.8  christos    warning.  */
     71  1.8  christos 
     72  1.8  christos static const bfd_arch_info_type *
     73  1.8  christos arc_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b)
     74  1.8  christos {
     75  1.8  christos   const bfd_arch_info_type * const em = &arch_info_struct[5];
     76  1.8  christos   const bfd_arch_info_type * const hs = &arch_info_struct[6];
     77  1.8  christos 
     78  1.8  christos   /* Trivial case where a and b is the same instance.  Some callers already
     79  1.8  christos      check this condition but some do not and get an invalid result.  */
     80  1.8  christos   if (a == b)
     81  1.8  christos     return a;
     82  1.8  christos 
     83  1.8  christos   /* If a & b are for different architecture we can do nothing.  */
     84  1.8  christos   if (a->arch != b->arch)
     85  1.8  christos     return NULL;
     86  1.8  christos 
     87  1.8  christos   if (a->bits_per_word != b->bits_per_word)
     88  1.8  christos     return NULL;
     89  1.8  christos 
     90  1.8  christos   /* ARCv2|EM and EM.  */
     91  1.8  christos   if ((a->mach == bfd_mach_arc_arcv2 && b == em)
     92  1.8  christos       || (b->mach == bfd_mach_arc_arcv2 && a == em))
     93  1.8  christos     return em;
     94  1.8  christos 
     95  1.8  christos   /* ARCv2|HS and HS.  */
     96  1.8  christos   if ((a->mach == bfd_mach_arc_arcv2 && b == hs)
     97  1.8  christos       || (b->mach == bfd_mach_arc_arcv2 && a == hs))
     98  1.8  christos     return hs;
     99  1.8  christos 
    100  1.8  christos   return bfd_default_compatible (a, b);
    101  1.8  christos }
    102