1 /* BFD backend for RISC-V 2 Copyright 2011-2014 Free Software Foundation, Inc. 3 4 Contributed by Andrew Waterman (waterman@cs.berkeley.edu) at UC Berkeley. 5 Based on MIPS target. 6 7 This file is part of BFD, the Binary File Descriptor library. 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 3 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 22 MA 02110-1301, USA. */ 23 24 #include "sysdep.h" 25 #include "bfd.h" 26 #include "libbfd.h" 27 28 static const bfd_arch_info_type *riscv_compatible 29 (const bfd_arch_info_type *, const bfd_arch_info_type *); 30 31 /* The default routine tests bits_per_word, which is wrong on RISC-V, as 32 RISC-V word size doesn't correlate with reloc size. */ 33 34 static const bfd_arch_info_type * 35 riscv_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b) 36 { 37 if (a->arch != b->arch) 38 return NULL; 39 40 /* Machine compatibility is checked in 41 _bfd_riscv_elf_merge_private_bfd_data. */ 42 43 return a; 44 } 45 46 #define N(BITS_WORD, BITS_ADDR, NUMBER, PRINT, DEFAULT, NEXT) \ 47 { \ 48 BITS_WORD, /* bits in a word */ \ 49 BITS_ADDR, /* bits in an address */ \ 50 8, /* 8 bits in a byte */ \ 51 bfd_arch_riscv, \ 52 NUMBER, \ 53 "riscv", \ 54 PRINT, \ 55 3, \ 56 DEFAULT, \ 57 riscv_compatible, \ 58 bfd_default_scan, \ 59 bfd_arch_default_fill, \ 60 NEXT, \ 61 } 62 63 enum 64 { 65 I_riscv64, 66 I_riscv32 67 }; 68 69 #define NN(index) (&arch_info_struct[(index) + 1]) 70 71 static const bfd_arch_info_type arch_info_struct[] = 72 { 73 N (64, 64, bfd_mach_riscv64, "riscv:rv64", FALSE, NN(I_riscv64)), 74 N (32, 32, bfd_mach_riscv32, "riscv:rv32", FALSE, 0) 75 }; 76 77 /* The default architecture is riscv:rv64. */ 78 79 const bfd_arch_info_type bfd_riscv_arch = 80 N (64, 64, 0, "riscv", TRUE, &arch_info_struct[0]); 81