175fd0b74Schristos /* BFD support for the Altera Nios II processor.
2*e992f068Schristos Copyright (C) 2012-2022 Free Software Foundation, Inc.
375fd0b74Schristos Contributed by Nigel Gray (ngray@altera.com).
475fd0b74Schristos Contributed by Mentor Graphics, Inc.
575fd0b74Schristos
675fd0b74Schristos This file is part of BFD, the Binary File Descriptor library.
775fd0b74Schristos
875fd0b74Schristos This program is free software; you can redistribute it and/or modify
975fd0b74Schristos it under the terms of the GNU General Public License as published by
1075fd0b74Schristos the Free Software Foundation; either version 3 of the License, or
1175fd0b74Schristos (at your option) any later version.
1275fd0b74Schristos
1375fd0b74Schristos This program is distributed in the hope that it will be useful,
1475fd0b74Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
1575fd0b74Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1675fd0b74Schristos GNU General Public License for more details.
1775fd0b74Schristos
1875fd0b74Schristos You should have received a copy of the GNU General Public License
1975fd0b74Schristos along with this program; if not, write to the Free Software
2075fd0b74Schristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
2175fd0b74Schristos MA 02110-1301, USA. */
2275fd0b74Schristos
2375fd0b74Schristos #include "sysdep.h"
2475fd0b74Schristos #include "bfd.h"
2575fd0b74Schristos #include "libbfd.h"
2675fd0b74Schristos
2775fd0b74Schristos static const bfd_arch_info_type *
nios2_compatible(const bfd_arch_info_type * a,const bfd_arch_info_type * b)2875fd0b74Schristos nios2_compatible (const bfd_arch_info_type *a,
2975fd0b74Schristos const bfd_arch_info_type *b)
3075fd0b74Schristos {
3175fd0b74Schristos if (a->arch != b->arch)
3275fd0b74Schristos return NULL;
3375fd0b74Schristos
3475fd0b74Schristos if (a->bits_per_word != b->bits_per_word)
3575fd0b74Schristos return NULL;
3675fd0b74Schristos
3775fd0b74Schristos if (a->mach == bfd_mach_nios2)
3875fd0b74Schristos return a;
3975fd0b74Schristos else if (b->mach == bfd_mach_nios2)
4075fd0b74Schristos return b;
4175fd0b74Schristos else if (a->mach != b->mach)
4275fd0b74Schristos return NULL;
4375fd0b74Schristos
4475fd0b74Schristos return a;
4575fd0b74Schristos }
4675fd0b74Schristos
47012573ebSchristos #define N(NUMBER, PRINT, DEFAULT, NEXT) \
4875fd0b74Schristos { \
49012573ebSchristos 32, /* Bits in a word. */ \
50012573ebSchristos 32, /* Bits in an address. */ \
51012573ebSchristos 8, /* Bits in a byte. */ \
5275fd0b74Schristos bfd_arch_nios2, \
5375fd0b74Schristos NUMBER, \
5475fd0b74Schristos "nios2", \
5575fd0b74Schristos PRINT, \
5675fd0b74Schristos 3, \
5775fd0b74Schristos DEFAULT, \
5875fd0b74Schristos nios2_compatible, \
5975fd0b74Schristos bfd_default_scan, \
6075fd0b74Schristos bfd_arch_default_fill, \
61012573ebSchristos NEXT, \
62012573ebSchristos 0 /* Maximum offset of a reloc from the start of an insn. */ \
6375fd0b74Schristos }
6475fd0b74Schristos
6575fd0b74Schristos #define NIOS2R1_NEXT &arch_info_struct[0]
6675fd0b74Schristos #define NIOS2R2_NEXT &arch_info_struct[1]
6775fd0b74Schristos
68012573ebSchristos static const bfd_arch_info_type arch_info_struct[2] =
6975fd0b74Schristos {
70*e992f068Schristos N (bfd_mach_nios2r1, "nios2:r1", false, NIOS2R2_NEXT),
71*e992f068Schristos N (bfd_mach_nios2r2, "nios2:r2", false, NULL),
7275fd0b74Schristos };
7375fd0b74Schristos
7475fd0b74Schristos const bfd_arch_info_type bfd_nios2_arch =
75*e992f068Schristos N (bfd_mach_nios2, "nios2", true, NIOS2R1_NEXT);
76