| 1 | /* Matsushita 10200 specific support for 32-bit ELF |
| 2 | Copyright (C) 1996, 1997 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of BFD, the Binary File Descriptor library. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 19 | |
| 20 | #include "bfd.h" |
| 21 | #include "sysdep.h" |
| 22 | #include "libbfd.h" |
| 23 | #include "elf-bfd.h" |
| 24 | |
| 25 | static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup |
| 26 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); |
| 27 | static void mn10200_info_to_howto |
| 28 | PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *)); |
| 29 | |
| 30 | |
| 31 | /* We have to use RELA instructions since md_apply_fix3 in the assembler |
| 32 | does absolutely nothing. */ |
| 33 | #define USE_RELA |
| 34 | |
| 35 | enum reloc_type |
| 36 | { |
| 37 | R_MN10200_NONE = 0, |
| 38 | R_MN10200_32, |
| 39 | R_MN10200_16, |
| 40 | R_MN10200_8, |
| 41 | R_MN10200_24, |
| 42 | R_MN10200_PCREL8, |
| 43 | R_MN10200_PCREL24, |
| 44 | R_MN10200_MAX |
| 45 | }; |
| 46 | |
| 47 | static reloc_howto_type elf_mn10200_howto_table[] = |
| 48 | { |
| 49 | /* Dummy relocation. Does nothing. */ |
| 50 | HOWTO (R_MN10200_NONE, |
| 51 | 0, |
| 52 | 2, |
| 53 | 16, |
| 54 | false, |
| 55 | 0, |
| 56 | complain_overflow_bitfield, |
| 57 | bfd_elf_generic_reloc, |
| 58 | "R_MN10200_NONE", |
| 59 | false, |
| 60 | 0, |
| 61 | 0, |
| 62 | false), |
| 63 | /* Standard 32 bit reloc. */ |
| 64 | HOWTO (R_MN10200_32, |
| 65 | 0, |
| 66 | 2, |
| 67 | 32, |
| 68 | false, |
| 69 | 0, |
| 70 | complain_overflow_bitfield, |
| 71 | bfd_elf_generic_reloc, |
| 72 | "R_MN10200_32", |
| 73 | false, |
| 74 | 0xffffffff, |
| 75 | 0xffffffff, |
| 76 | false), |
| 77 | /* Standard 16 bit reloc. */ |
| 78 | HOWTO (R_MN10200_16, |
| 79 | 0, |
| 80 | 1, |
| 81 | 16, |
| 82 | false, |
| 83 | 0, |
| 84 | complain_overflow_bitfield, |
| 85 | bfd_elf_generic_reloc, |
| 86 | "R_MN10200_16", |
| 87 | false, |
| 88 | 0xffff, |
| 89 | 0xffff, |
| 90 | false), |
| 91 | /* Standard 8 bit reloc. */ |
| 92 | HOWTO (R_MN10200_8, |
| 93 | 0, |
| 94 | 0, |
| 95 | 8, |
| 96 | false, |
| 97 | 0, |
| 98 | complain_overflow_bitfield, |
| 99 | bfd_elf_generic_reloc, |
| 100 | "R_MN10200_8", |
| 101 | false, |
| 102 | 0xff, |
| 103 | 0xff, |
| 104 | false), |
| 105 | /* Standard 24 bit reloc. */ |
| 106 | HOWTO (R_MN10200_24, |
| 107 | 0, |
| 108 | 2, |
| 109 | 24, |
| 110 | false, |
| 111 | 0, |
| 112 | complain_overflow_bitfield, |
| 113 | bfd_elf_generic_reloc, |
| 114 | "R_MN10200_24", |
| 115 | false, |
| 116 | 0xffffff, |
| 117 | 0xffffff, |
| 118 | false), |
| 119 | /* Simple 8 pc-relative reloc. */ |
| 120 | HOWTO (R_MN10200_PCREL8, |
| 121 | 0, |
| 122 | 0, |
| 123 | 8, |
| 124 | true, |
| 125 | 0, |
| 126 | complain_overflow_bitfield, |
| 127 | bfd_elf_generic_reloc, |
| 128 | "R_MN10200_PCREL8", |
| 129 | false, |
| 130 | 0xff, |
| 131 | 0xff, |
| 132 | true), |
| 133 | /* Simple 32bit pc-relative reloc with a 1 byte adjustment |
| 134 | to get the pc-relative offset correct. */ |
| 135 | HOWTO (R_MN10200_PCREL24, |
| 136 | 0, |
| 137 | 2, |
| 138 | 24, |
| 139 | true, |
| 140 | 0, |
| 141 | complain_overflow_bitfield, |
| 142 | bfd_elf_generic_reloc, |
| 143 | "R_MN10200_PCREL24", |
| 144 | false, |
| 145 | 0xffffff, |
| 146 | 0xffffff, |
| 147 | true), |
| 148 | }; |
| 149 | |
| 150 | struct mn10200_reloc_map |
| 151 | { |
| 152 | unsigned char bfd_reloc_val; |
| 153 | unsigned char elf_reloc_val; |
| 154 | }; |
| 155 | |
| 156 | static const struct mn10200_reloc_map mn10200_reloc_map[] = |
| 157 | { |
| 158 | { BFD_RELOC_NONE, R_MN10200_NONE, }, |
| 159 | { BFD_RELOC_32, R_MN10200_32, }, |
| 160 | { BFD_RELOC_16, R_MN10200_16, }, |
| 161 | { BFD_RELOC_8, R_MN10200_8, }, |
| 162 | { BFD_RELOC_24, R_MN10200_24, }, |
| 163 | { BFD_RELOC_8_PCREL, R_MN10200_PCREL8, }, |
| 164 | { BFD_RELOC_24_PCREL, R_MN10200_PCREL24, }, |
| 165 | }; |
| 166 | |
| 167 | static reloc_howto_type * |
| 168 | bfd_elf32_bfd_reloc_type_lookup (abfd, code) |
| 169 | bfd *abfd; |
| 170 | bfd_reloc_code_real_type code; |
| 171 | { |
| 172 | unsigned int i; |
| 173 | |
| 174 | for (i = 0; |
| 175 | i < sizeof (mn10200_reloc_map) / sizeof (struct mn10200_reloc_map); |
| 176 | i++) |
| 177 | { |
| 178 | if (mn10200_reloc_map[i].bfd_reloc_val == code) |
| 179 | return &elf_mn10200_howto_table[mn10200_reloc_map[i].elf_reloc_val]; |
| 180 | } |
| 181 | |
| 182 | return NULL; |
| 183 | } |
| 184 | |
| 185 | /* Set the howto pointer for an MN10200 ELF reloc. */ |
| 186 | |
| 187 | static void |
| 188 | mn10200_info_to_howto (abfd, cache_ptr, dst) |
| 189 | bfd *abfd; |
| 190 | arelent *cache_ptr; |
| 191 | Elf32_Internal_Rela *dst; |
| 192 | { |
| 193 | unsigned int r_type; |
| 194 | |
| 195 | r_type = ELF32_R_TYPE (dst->r_info); |
| 196 | BFD_ASSERT (r_type < (unsigned int) R_MN10200_MAX); |
| 197 | cache_ptr->howto = &elf_mn10200_howto_table[r_type]; |
| 198 | } |
| 199 | |
| 200 | #define TARGET_LITTLE_SYM bfd_elf32_mn10200_vec |
| 201 | #define TARGET_LITTLE_NAME "elf32-mn10200" |
| 202 | #define ELF_ARCH bfd_arch_mn10200 |
| 203 | #define ELF_MACHINE_CODE EM_CYGNUS_MN10200 |
| 204 | #define ELF_MAXPAGESIZE 0x1000 |
| 205 | |
| 206 | #define elf_info_to_howto mn10200_info_to_howto |
| 207 | #define elf_info_to_howto_rel 0 |
| 208 | |
| 209 | #define elf_symbol_leading_char '_' |
| 210 | |
| 211 | #include "elf32-target.h" |