xref: /netbsd-src/external/gpl3/binutils/dist/bfd/cpu-nios2.c (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
19573673dSchristos /* BFD support for the Altera Nios II processor.
2*cb63e24eSchristos    Copyright (C) 2012-2024 Free Software Foundation, Inc.
39573673dSchristos    Contributed by Nigel Gray (ngray@altera.com).
49573673dSchristos    Contributed by Mentor Graphics, Inc.
59573673dSchristos 
69573673dSchristos    This file is part of BFD, the Binary File Descriptor library.
79573673dSchristos 
89573673dSchristos    This program is free software; you can redistribute it and/or modify
99573673dSchristos    it under the terms of the GNU General Public License as published by
109573673dSchristos    the Free Software Foundation; either version 3 of the License, or
119573673dSchristos    (at your option) any later version.
129573673dSchristos 
139573673dSchristos    This program is distributed in the hope that it will be useful,
149573673dSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
159573673dSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
169573673dSchristos    GNU General Public License for more details.
179573673dSchristos 
189573673dSchristos    You should have received a copy of the GNU General Public License
199573673dSchristos    along with this program; if not, write to the Free Software
209573673dSchristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
219573673dSchristos    MA 02110-1301, USA.  */
229573673dSchristos 
239573673dSchristos #include "sysdep.h"
249573673dSchristos #include "bfd.h"
259573673dSchristos #include "libbfd.h"
269573673dSchristos 
279573673dSchristos static const bfd_arch_info_type *
nios2_compatible(const bfd_arch_info_type * a,const bfd_arch_info_type * b)289573673dSchristos nios2_compatible (const bfd_arch_info_type *a,
299573673dSchristos 		  const bfd_arch_info_type *b)
309573673dSchristos {
319573673dSchristos   if (a->arch != b->arch)
329573673dSchristos     return NULL;
339573673dSchristos 
349573673dSchristos   if (a->bits_per_word != b->bits_per_word)
359573673dSchristos     return NULL;
369573673dSchristos 
379573673dSchristos   if (a->mach == bfd_mach_nios2)
389573673dSchristos     return a;
399573673dSchristos   else if (b->mach == bfd_mach_nios2)
409573673dSchristos     return b;
419573673dSchristos   else if (a->mach != b->mach)
429573673dSchristos     return NULL;
439573673dSchristos 
449573673dSchristos   return a;
459573673dSchristos }
469573673dSchristos 
476f4ced0bSchristos #define N(NUMBER, PRINT, DEFAULT, NEXT)			\
489573673dSchristos   {							\
496f4ced0bSchristos     32, /* Bits in a word.  */				\
506f4ced0bSchristos     32, /* Bits in an address.  */			\
516f4ced0bSchristos     8,	/* Bits in a byte.  */				\
529573673dSchristos     bfd_arch_nios2,					\
539573673dSchristos     NUMBER,						\
549573673dSchristos     "nios2",						\
559573673dSchristos     PRINT,						\
569573673dSchristos     3,							\
579573673dSchristos     DEFAULT,						\
589573673dSchristos     nios2_compatible,					\
599573673dSchristos     bfd_default_scan,					\
609573673dSchristos     bfd_arch_default_fill,				\
616f4ced0bSchristos     NEXT,						\
626f4ced0bSchristos     0 /* Maximum offset of a reloc from the start of an insn.  */ \
639573673dSchristos   }
649573673dSchristos 
659573673dSchristos #define NIOS2R1_NEXT &arch_info_struct[0]
669573673dSchristos #define NIOS2R2_NEXT &arch_info_struct[1]
679573673dSchristos 
686f4ced0bSchristos static const bfd_arch_info_type arch_info_struct[2] =
699573673dSchristos {
704f645668Schristos   N (bfd_mach_nios2r1, "nios2:r1", false, NIOS2R2_NEXT),
714f645668Schristos   N (bfd_mach_nios2r2, "nios2:r2", false, NULL),
729573673dSchristos };
739573673dSchristos 
749573673dSchristos const bfd_arch_info_type bfd_nios2_arch =
754f645668Schristos   N (bfd_mach_nios2, "nios2", true, NIOS2R1_NEXT);
76