xref: /netbsd-src/external/gpl3/binutils.old/dist/bfd/cpu-nios2.c (revision e992f068c547fd6e84b3f104dc2340adcc955732)
1 /* BFD support for the Altera Nios II processor.
2    Copyright (C) 2012-2022 Free Software Foundation, Inc.
3    Contributed by Nigel Gray (ngray@altera.com).
4    Contributed by Mentor Graphics, Inc.
5 
6    This file is part of BFD, the Binary File Descriptor library.
7 
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12 
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21    MA 02110-1301, USA.  */
22 
23 #include "sysdep.h"
24 #include "bfd.h"
25 #include "libbfd.h"
26 
27 static const bfd_arch_info_type *
nios2_compatible(const bfd_arch_info_type * a,const bfd_arch_info_type * b)28 nios2_compatible (const bfd_arch_info_type *a,
29 		  const bfd_arch_info_type *b)
30 {
31   if (a->arch != b->arch)
32     return NULL;
33 
34   if (a->bits_per_word != b->bits_per_word)
35     return NULL;
36 
37   if (a->mach == bfd_mach_nios2)
38     return a;
39   else if (b->mach == bfd_mach_nios2)
40     return b;
41   else if (a->mach != b->mach)
42     return NULL;
43 
44   return a;
45 }
46 
47 #define N(NUMBER, PRINT, DEFAULT, NEXT)			\
48   {							\
49     32, /* Bits in a word.  */				\
50     32, /* Bits in an address.  */			\
51     8,	/* Bits in a byte.  */				\
52     bfd_arch_nios2,					\
53     NUMBER,						\
54     "nios2",						\
55     PRINT,						\
56     3,							\
57     DEFAULT,						\
58     nios2_compatible,					\
59     bfd_default_scan,					\
60     bfd_arch_default_fill,				\
61     NEXT,						\
62     0 /* Maximum offset of a reloc from the start of an insn.  */ \
63   }
64 
65 #define NIOS2R1_NEXT &arch_info_struct[0]
66 #define NIOS2R2_NEXT &arch_info_struct[1]
67 
68 static const bfd_arch_info_type arch_info_struct[2] =
69 {
70   N (bfd_mach_nios2r1, "nios2:r1", false, NIOS2R2_NEXT),
71   N (bfd_mach_nios2r2, "nios2:r2", false, NULL),
72 };
73 
74 const bfd_arch_info_type bfd_nios2_arch =
75   N (bfd_mach_nios2, "nios2", true, NIOS2R1_NEXT);
76