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