xref: /netbsd/external/gpl3/gdb/dist/bfd/cpu-nios2.c (revision 1424dfb3)
148596154Schristos /* BFD support for the Altera Nios II processor.
2*1424dfb3Schristos    Copyright (C) 2012-2020 Free Software Foundation, Inc.
348596154Schristos    Contributed by Nigel Gray (ngray@altera.com).
448596154Schristos    Contributed by Mentor Graphics, Inc.
548596154Schristos 
648596154Schristos    This file is part of BFD, the Binary File Descriptor library.
748596154Schristos 
848596154Schristos    This program is free software; you can redistribute it and/or modify
948596154Schristos    it under the terms of the GNU General Public License as published by
1048596154Schristos    the Free Software Foundation; either version 3 of the License, or
1148596154Schristos    (at your option) any later version.
1248596154Schristos 
1348596154Schristos    This program is distributed in the hope that it will be useful,
1448596154Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1548596154Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1648596154Schristos    GNU General Public License for more details.
1748596154Schristos 
1848596154Schristos    You should have received a copy of the GNU General Public License
1948596154Schristos    along with this program; if not, write to the Free Software
2048596154Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
2148596154Schristos    MA 02110-1301, USA.  */
2248596154Schristos 
2348596154Schristos #include "sysdep.h"
2448596154Schristos #include "bfd.h"
2548596154Schristos #include "libbfd.h"
2648596154Schristos 
27ed6a76a9Schristos static const bfd_arch_info_type *
nios2_compatible(const bfd_arch_info_type * a,const bfd_arch_info_type * b)28ed6a76a9Schristos nios2_compatible (const bfd_arch_info_type *a,
29ed6a76a9Schristos 		  const bfd_arch_info_type *b)
30ed6a76a9Schristos {
31ed6a76a9Schristos   if (a->arch != b->arch)
32ed6a76a9Schristos     return NULL;
33ed6a76a9Schristos 
34ed6a76a9Schristos   if (a->bits_per_word != b->bits_per_word)
35ed6a76a9Schristos     return NULL;
36ed6a76a9Schristos 
37ed6a76a9Schristos   if (a->mach == bfd_mach_nios2)
38ed6a76a9Schristos     return a;
39ed6a76a9Schristos   else if (b->mach == bfd_mach_nios2)
40ed6a76a9Schristos     return b;
41ed6a76a9Schristos   else if (a->mach != b->mach)
42ed6a76a9Schristos     return NULL;
43ed6a76a9Schristos 
44ed6a76a9Schristos   return a;
45ed6a76a9Schristos }
46ed6a76a9Schristos 
47*1424dfb3Schristos #define N(NUMBER, PRINT, DEFAULT, NEXT)			\
4848596154Schristos   {							\
49*1424dfb3Schristos     32, /* Bits in a word.  */				\
50*1424dfb3Schristos     32, /* Bits in an address.  */			\
51*1424dfb3Schristos     8,	/* Bits in a byte.  */				\
5248596154Schristos     bfd_arch_nios2,					\
5348596154Schristos     NUMBER,						\
5448596154Schristos     "nios2",						\
5548596154Schristos     PRINT,						\
5648596154Schristos     3,							\
5748596154Schristos     DEFAULT,						\
58ed6a76a9Schristos     nios2_compatible,					\
5948596154Schristos     bfd_default_scan,					\
6048596154Schristos     bfd_arch_default_fill,				\
61*1424dfb3Schristos     NEXT,						\
62*1424dfb3Schristos     0 /* Maximum offset of a reloc from the start of an insn.  */ \
6348596154Schristos   }
6448596154Schristos 
65ed6a76a9Schristos #define NIOS2R1_NEXT &arch_info_struct[0]
66ed6a76a9Schristos #define NIOS2R2_NEXT &arch_info_struct[1]
67ed6a76a9Schristos 
68*1424dfb3Schristos static const bfd_arch_info_type arch_info_struct[2] =
69ed6a76a9Schristos {
70*1424dfb3Schristos   N (bfd_mach_nios2r1, "nios2:r1", FALSE, NIOS2R2_NEXT),
71*1424dfb3Schristos   N (bfd_mach_nios2r2, "nios2:r2", FALSE, NULL),
72ed6a76a9Schristos };
73ed6a76a9Schristos 
74ed6a76a9Schristos const bfd_arch_info_type bfd_nios2_arch =
75*1424dfb3Schristos   N (bfd_mach_nios2, "nios2", TRUE, NIOS2R1_NEXT);
76