| 1 | /* BFD back-end for Texas Instruments TMS320C80 Multimedia Video Processor (MVP). | 
|---|
| 2 | Copyright 1996, 1997, 1999, 2000 Free Software Foundation, Inc. | 
|---|
| 3 |  | 
|---|
| 4 | Written by Fred Fish (fnf@cygnus.com) | 
|---|
| 5 |  | 
|---|
| 6 | There is nothing new under the sun. This file draws a lot on other | 
|---|
| 7 | coff files. | 
|---|
| 8 |  | 
|---|
| 9 | This file is part of BFD, the Binary File Descriptor library. | 
|---|
| 10 |  | 
|---|
| 11 | This program is free software; you can redistribute it and/or modify | 
|---|
| 12 | it under the terms of the GNU General Public License as published by | 
|---|
| 13 | the Free Software Foundation; either version 2 of the License, or | 
|---|
| 14 | (at your option) any later version. | 
|---|
| 15 |  | 
|---|
| 16 | This program is distributed in the hope that it will be useful, | 
|---|
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 19 | GNU General Public License for more details. | 
|---|
| 20 |  | 
|---|
| 21 | You should have received a copy of the GNU General Public License | 
|---|
| 22 | along with this program; if not, write to the Free Software | 
|---|
| 23 | Foundation, 59 Temple Place - Suite 330, | 
|---|
| 24 | Boston, MA 02111-1307, USA.  */ | 
|---|
| 25 |  | 
|---|
| 26 | #include "bfd.h" | 
|---|
| 27 | #include "bfdlink.h" | 
|---|
| 28 | #include "sysdep.h" | 
|---|
| 29 | #include "libbfd.h" | 
|---|
| 30 | #include "coff/tic80.h" | 
|---|
| 31 | #include "coff/internal.h" | 
|---|
| 32 | #include "libcoff.h" | 
|---|
| 33 |  | 
|---|
| 34 | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2) | 
|---|
| 35 | #define COFF_ALIGN_IN_SECTION_HEADER 1 | 
|---|
| 36 | #define COFF_ALIGN_IN_SFLAGS 1 | 
|---|
| 37 |  | 
|---|
| 38 | #define GET_SCNHDR_FLAGS bfd_h_get_16 | 
|---|
| 39 | #define PUT_SCNHDR_FLAGS bfd_h_put_16 | 
|---|
| 40 |  | 
|---|
| 41 | static void rtype2howto | 
|---|
| 42 | PARAMS ((arelent *cache_ptr, struct internal_reloc *dst)); | 
|---|
| 43 | static bfd_reloc_status_type ppbase_reloc | 
|---|
| 44 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | 
|---|
| 45 | static bfd_reloc_status_type glob15_reloc | 
|---|
| 46 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | 
|---|
| 47 | static bfd_reloc_status_type glob16_reloc | 
|---|
| 48 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | 
|---|
| 49 | static bfd_reloc_status_type local16_reloc | 
|---|
| 50 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | 
|---|
| 51 | static boolean coff_tic80_relocate_section | 
|---|
| 52 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | 
|---|
| 53 | struct internal_reloc *, struct internal_syment *, asection **)); | 
|---|
| 54 |  | 
|---|
| 55 | static reloc_howto_type tic80_howto_table[] = | 
|---|
| 56 | { | 
|---|
| 57 |  | 
|---|
| 58 | HOWTO (R_RELLONG,                     /* type */ | 
|---|
| 59 | 0,                             /* rightshift */ | 
|---|
| 60 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 61 | 32,                            /* bitsize */ | 
|---|
| 62 | false,                         /* pc_relative */ | 
|---|
| 63 | 0,                             /* bitpos */ | 
|---|
| 64 | complain_overflow_bitfield,    /* complain_on_overflow */ | 
|---|
| 65 | NULL,                          /* special_function */ | 
|---|
| 66 | "RELLONG",                     /* name */ | 
|---|
| 67 | true,                          /* partial_inplace */ | 
|---|
| 68 | 0xffffffff,                    /* src_mask */ | 
|---|
| 69 | 0xffffffff,                    /* dst_mask */ | 
|---|
| 70 | false),                        /* pcrel_offset */ | 
|---|
| 71 |  | 
|---|
| 72 | HOWTO (R_MPPCR,                       /* type */ | 
|---|
| 73 | 2,                             /* rightshift */ | 
|---|
| 74 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 75 | 32,                            /* bitsize */ | 
|---|
| 76 | true,                          /* pc_relative */ | 
|---|
| 77 | 0,                             /* bitpos */ | 
|---|
| 78 | complain_overflow_signed,      /* complain_on_overflow */ | 
|---|
| 79 | NULL,                          /* special_function */ | 
|---|
| 80 | "MPPCR",                       /* name */ | 
|---|
| 81 | true,                          /* partial_inplace */ | 
|---|
| 82 | 0xffffffff,                    /* src_mask */ | 
|---|
| 83 | 0xffffffff,                    /* dst_mask */ | 
|---|
| 84 | true),                         /* pcrel_offset */ | 
|---|
| 85 |  | 
|---|
| 86 | HOWTO (R_ABS,                         /* type */ | 
|---|
| 87 | 0,                             /* rightshift */ | 
|---|
| 88 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 89 | 32,                            /* bitsize */ | 
|---|
| 90 | false,                         /* pc_relative */ | 
|---|
| 91 | 0,                             /* bitpos */ | 
|---|
| 92 | complain_overflow_bitfield,    /* complain_on_overflow */ | 
|---|
| 93 | NULL,                          /* special_function */ | 
|---|
| 94 | "ABS",                         /* name */ | 
|---|
| 95 | true,                          /* partial_inplace */ | 
|---|
| 96 | 0xffffffff,                    /* src_mask */ | 
|---|
| 97 | 0xffffffff,                    /* dst_mask */ | 
|---|
| 98 | false),                                /* pcrel_offset */ | 
|---|
| 99 |  | 
|---|
| 100 | HOWTO (R_PPBASE,                      /* type */ | 
|---|
| 101 | 0,                             /* rightshift */ | 
|---|
| 102 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 103 | 32,                            /* bitsize */ | 
|---|
| 104 | false,                         /* pc_relative */ | 
|---|
| 105 | 0,                             /* bitpos */ | 
|---|
| 106 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 107 | ppbase_reloc,                  /* special_function */ | 
|---|
| 108 | "PPBASE",                      /* name */ | 
|---|
| 109 | true,                          /* partial_inplace */ | 
|---|
| 110 | 0xffffffff,                    /* src_mask */ | 
|---|
| 111 | 0xffffffff,                    /* dst_mask */ | 
|---|
| 112 | false),                        /* pcrel_offset */ | 
|---|
| 113 |  | 
|---|
| 114 | HOWTO (R_PPLBASE,                     /* type */ | 
|---|
| 115 | 0,                             /* rightshift */ | 
|---|
| 116 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 117 | 32,                            /* bitsize */ | 
|---|
| 118 | false,                         /* pc_relative */ | 
|---|
| 119 | 0,                             /* bitpos */ | 
|---|
| 120 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 121 | ppbase_reloc,                  /* special_function */ | 
|---|
| 122 | "PPLBASE",                     /* name */ | 
|---|
| 123 | true,                          /* partial_inplace */ | 
|---|
| 124 | 0xffffffff,                    /* src_mask */ | 
|---|
| 125 | 0xffffffff,                    /* dst_mask */ | 
|---|
| 126 | false),                        /* pcrel_offset */ | 
|---|
| 127 |  | 
|---|
| 128 | HOWTO (R_PP15,                        /* type */ | 
|---|
| 129 | 0,                             /* rightshift */ | 
|---|
| 130 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 131 | 15,                            /* bitsize */ | 
|---|
| 132 | false,                         /* pc_relative */ | 
|---|
| 133 | 6,                             /* bitpos */ | 
|---|
| 134 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 135 | glob15_reloc,                  /* special_function */ | 
|---|
| 136 | "PP15",                        /* name */ | 
|---|
| 137 | true,                          /* partial_inplace */ | 
|---|
| 138 | 0x1ffc0,                       /* src_mask */ | 
|---|
| 139 | 0x1ffc0,                       /* dst_mask */ | 
|---|
| 140 | false),                        /* pcrel_offset */ | 
|---|
| 141 |  | 
|---|
| 142 | HOWTO (R_PP15W,                       /* type */ | 
|---|
| 143 | 2,                             /* rightshift */ | 
|---|
| 144 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 145 | 15,                            /* bitsize */ | 
|---|
| 146 | false,                         /* pc_relative */ | 
|---|
| 147 | 6,                             /* bitpos */ | 
|---|
| 148 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 149 | glob15_reloc,                  /* special_function */ | 
|---|
| 150 | "PP15W",                       /* name */ | 
|---|
| 151 | true,                          /* partial_inplace */ | 
|---|
| 152 | 0x1ffc0,                       /* src_mask */ | 
|---|
| 153 | 0x1ffc0,                       /* dst_mask */ | 
|---|
| 154 | false),                        /* pcrel_offset */ | 
|---|
| 155 |  | 
|---|
| 156 | HOWTO (R_PP15H,                       /* type */ | 
|---|
| 157 | 1,                             /* rightshift */ | 
|---|
| 158 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 159 | 15,                            /* bitsize */ | 
|---|
| 160 | false,                         /* pc_relative */ | 
|---|
| 161 | 6,                             /* bitpos */ | 
|---|
| 162 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 163 | glob15_reloc,                  /* special_function */ | 
|---|
| 164 | "PP15H",                       /* name */ | 
|---|
| 165 | true,                          /* partial_inplace */ | 
|---|
| 166 | 0x1ffc0,                       /* src_mask */ | 
|---|
| 167 | 0x1ffc0,                       /* dst_mask */ | 
|---|
| 168 | false),                        /* pcrel_offset */ | 
|---|
| 169 |  | 
|---|
| 170 | HOWTO (R_PP16B,                       /* type */ | 
|---|
| 171 | 0,                             /* rightshift */ | 
|---|
| 172 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 173 | 16,                            /* bitsize */ | 
|---|
| 174 | false,                         /* pc_relative */ | 
|---|
| 175 | 6,                             /* bitpos */ | 
|---|
| 176 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 177 | glob16_reloc,                  /* special_function */ | 
|---|
| 178 | "PP16B",                       /* name */ | 
|---|
| 179 | true,                          /* partial_inplace */ | 
|---|
| 180 | 0x3ffc0,                       /* src_mask */ | 
|---|
| 181 | 0x3ffc0,                       /* dst_mask */ | 
|---|
| 182 | false),                        /* pcrel_offset */ | 
|---|
| 183 |  | 
|---|
| 184 | HOWTO (R_PPL15,                       /* type */ | 
|---|
| 185 | 0,                             /* rightshift */ | 
|---|
| 186 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 187 | 15,                            /* bitsize */ | 
|---|
| 188 | false,                         /* pc_relative */ | 
|---|
| 189 | 0,                             /* bitpos */ | 
|---|
| 190 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 191 | NULL,                          /* special_function */ | 
|---|
| 192 | "PPL15",                       /* name */ | 
|---|
| 193 | true,                          /* partial_inplace */ | 
|---|
| 194 | 0x7fff,                        /* src_mask */ | 
|---|
| 195 | 0x7fff,                        /* dst_mask */ | 
|---|
| 196 | false),                        /* pcrel_offset */ | 
|---|
| 197 |  | 
|---|
| 198 | HOWTO (R_PPL15W,                      /* type */ | 
|---|
| 199 | 2,                             /* rightshift */ | 
|---|
| 200 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 201 | 15,                            /* bitsize */ | 
|---|
| 202 | false,                         /* pc_relative */ | 
|---|
| 203 | 0,                             /* bitpos */ | 
|---|
| 204 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 205 | NULL,                          /* special_function */ | 
|---|
| 206 | "PPL15W",                      /* name */ | 
|---|
| 207 | true,                          /* partial_inplace */ | 
|---|
| 208 | 0x7fff,                        /* src_mask */ | 
|---|
| 209 | 0x7fff,                        /* dst_mask */ | 
|---|
| 210 | false),                        /* pcrel_offset */ | 
|---|
| 211 |  | 
|---|
| 212 | HOWTO (R_PPL15H,                      /* type */ | 
|---|
| 213 | 1,                             /* rightshift */ | 
|---|
| 214 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 215 | 15,                            /* bitsize */ | 
|---|
| 216 | false,                         /* pc_relative */ | 
|---|
| 217 | 0,                             /* bitpos */ | 
|---|
| 218 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 219 | NULL,                          /* special_function */ | 
|---|
| 220 | "PPL15H",                      /* name */ | 
|---|
| 221 | true,                          /* partial_inplace */ | 
|---|
| 222 | 0x7fff,                        /* src_mask */ | 
|---|
| 223 | 0x7fff,                        /* dst_mask */ | 
|---|
| 224 | false),                        /* pcrel_offset */ | 
|---|
| 225 |  | 
|---|
| 226 | HOWTO (R_PPL16B,                      /* type */ | 
|---|
| 227 | 0,                             /* rightshift */ | 
|---|
| 228 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 229 | 16,                            /* bitsize */ | 
|---|
| 230 | false,                         /* pc_relative */ | 
|---|
| 231 | 0,                             /* bitpos */ | 
|---|
| 232 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 233 | local16_reloc,                 /* special_function */ | 
|---|
| 234 | "PPL16B",                      /* name */ | 
|---|
| 235 | true,                          /* partial_inplace */ | 
|---|
| 236 | 0xffff,                        /* src_mask */ | 
|---|
| 237 | 0xffff,                        /* dst_mask */ | 
|---|
| 238 | false),                        /* pcrel_offset */ | 
|---|
| 239 |  | 
|---|
| 240 | HOWTO (R_PPN15,                       /* type */ | 
|---|
| 241 | 0,                             /* rightshift */ | 
|---|
| 242 | -2,                            /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 243 | 15,                            /* bitsize */ | 
|---|
| 244 | false,                         /* pc_relative */ | 
|---|
| 245 | 6,                             /* bitpos */ | 
|---|
| 246 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 247 | glob15_reloc,                  /* special_function */ | 
|---|
| 248 | "PPN15",                       /* name */ | 
|---|
| 249 | true,                          /* partial_inplace */ | 
|---|
| 250 | 0x1ffc0,                       /* src_mask */ | 
|---|
| 251 | 0x1ffc0,                       /* dst_mask */ | 
|---|
| 252 | false),                        /* pcrel_offset */ | 
|---|
| 253 |  | 
|---|
| 254 | HOWTO (R_PPN15W,                      /* type */ | 
|---|
| 255 | 2,                             /* rightshift */ | 
|---|
| 256 | -2,                            /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 257 | 15,                            /* bitsize */ | 
|---|
| 258 | false,                         /* pc_relative */ | 
|---|
| 259 | 6,                             /* bitpos */ | 
|---|
| 260 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 261 | glob15_reloc,                  /* special_function */ | 
|---|
| 262 | "PPN15W",                      /* name */ | 
|---|
| 263 | true,                          /* partial_inplace */ | 
|---|
| 264 | 0x1ffc0,                       /* src_mask */ | 
|---|
| 265 | 0x1ffc0,                       /* dst_mask */ | 
|---|
| 266 | false),                        /* pcrel_offset */ | 
|---|
| 267 |  | 
|---|
| 268 | HOWTO (R_PPN15H,                      /* type */ | 
|---|
| 269 | 1,                             /* rightshift */ | 
|---|
| 270 | -2,                            /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 271 | 15,                            /* bitsize */ | 
|---|
| 272 | false,                         /* pc_relative */ | 
|---|
| 273 | 6,                             /* bitpos */ | 
|---|
| 274 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 275 | glob15_reloc,                  /* special_function */ | 
|---|
| 276 | "PPN15H",                      /* name */ | 
|---|
| 277 | true,                          /* partial_inplace */ | 
|---|
| 278 | 0x1ffc0,                       /* src_mask */ | 
|---|
| 279 | 0x1ffc0,                       /* dst_mask */ | 
|---|
| 280 | false),                        /* pcrel_offset */ | 
|---|
| 281 |  | 
|---|
| 282 | HOWTO (R_PPN16B,                      /* type */ | 
|---|
| 283 | 0,                             /* rightshift */ | 
|---|
| 284 | -2,                            /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 285 | 16,                            /* bitsize */ | 
|---|
| 286 | false,                         /* pc_relative */ | 
|---|
| 287 | 6,                             /* bitpos */ | 
|---|
| 288 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 289 | glob16_reloc,                  /* special_function */ | 
|---|
| 290 | "PPN16B",                      /* name */ | 
|---|
| 291 | true,                          /* partial_inplace */ | 
|---|
| 292 | 0x3ffc0,                       /* src_mask */ | 
|---|
| 293 | 0x3ffc0,                       /* dst_mask */ | 
|---|
| 294 | false),                        /* pcrel_offset */ | 
|---|
| 295 |  | 
|---|
| 296 | HOWTO (R_PPLN15,                      /* type */ | 
|---|
| 297 | 0,                             /* rightshift */ | 
|---|
| 298 | -2,                            /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 299 | 15,                            /* bitsize */ | 
|---|
| 300 | false,                         /* pc_relative */ | 
|---|
| 301 | 0,                             /* bitpos */ | 
|---|
| 302 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 303 | NULL,                          /* special_function */ | 
|---|
| 304 | "PPLN15",                      /* name */ | 
|---|
| 305 | true,                          /* partial_inplace */ | 
|---|
| 306 | 0x7fff,                        /* src_mask */ | 
|---|
| 307 | 0x7fff,                        /* dst_mask */ | 
|---|
| 308 | false),                        /* pcrel_offset */ | 
|---|
| 309 |  | 
|---|
| 310 | HOWTO (R_PPLN15W,                     /* type */ | 
|---|
| 311 | 2,                             /* rightshift */ | 
|---|
| 312 | -2,                            /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 313 | 15,                            /* bitsize */ | 
|---|
| 314 | false,                         /* pc_relative */ | 
|---|
| 315 | 0,                             /* bitpos */ | 
|---|
| 316 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 317 | NULL,                          /* special_function */ | 
|---|
| 318 | "PPLN15W",                     /* name */ | 
|---|
| 319 | true,                          /* partial_inplace */ | 
|---|
| 320 | 0x7fff,                        /* src_mask */ | 
|---|
| 321 | 0x7fff,                        /* dst_mask */ | 
|---|
| 322 | false),                        /* pcrel_offset */ | 
|---|
| 323 |  | 
|---|
| 324 | HOWTO (R_PPLN15H,                     /* type */ | 
|---|
| 325 | 1,                             /* rightshift */ | 
|---|
| 326 | -2,                            /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 327 | 15,                            /* bitsize */ | 
|---|
| 328 | false,                         /* pc_relative */ | 
|---|
| 329 | 0,                             /* bitpos */ | 
|---|
| 330 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 331 | NULL,                          /* special_function */ | 
|---|
| 332 | "PPLN15H",                     /* name */ | 
|---|
| 333 | true,                          /* partial_inplace */ | 
|---|
| 334 | 0x7fff,                        /* src_mask */ | 
|---|
| 335 | 0x7fff,                        /* dst_mask */ | 
|---|
| 336 | false),                        /* pcrel_offset */ | 
|---|
| 337 |  | 
|---|
| 338 | HOWTO (R_PPLN16B,                     /* type */ | 
|---|
| 339 | 0,                             /* rightshift */ | 
|---|
| 340 | -2,                            /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 341 | 15,                            /* bitsize */ | 
|---|
| 342 | false,                         /* pc_relative */ | 
|---|
| 343 | 0,                             /* bitpos */ | 
|---|
| 344 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 345 | local16_reloc,                 /* special_function */ | 
|---|
| 346 | "PPLN16B",                     /* name */ | 
|---|
| 347 | true,                          /* partial_inplace */ | 
|---|
| 348 | 0xffff,                        /* src_mask */ | 
|---|
| 349 | 0xffff,                        /* dst_mask */ | 
|---|
| 350 | false)                         /* pcrel_offset */ | 
|---|
| 351 | }; | 
|---|
| 352 |  | 
|---|
| 353 |  | 
|---|
| 354 | /* Special relocation functions, used when the output file is not | 
|---|
| 355 | itself a COFF TIc80 file.  */ | 
|---|
| 356 |  | 
|---|
| 357 | /* This special function is used for the base address type | 
|---|
| 358 | relocations.  */ | 
|---|
| 359 |  | 
|---|
| 360 | static bfd_reloc_status_type | 
|---|
| 361 | ppbase_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | 
|---|
| 362 | error_message) | 
|---|
| 363 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 364 | arelent *reloc_entry ATTRIBUTE_UNUSED; | 
|---|
| 365 | asymbol *symbol_in ATTRIBUTE_UNUSED; | 
|---|
| 366 | PTR data ATTRIBUTE_UNUSED; | 
|---|
| 367 | asection *input_section ATTRIBUTE_UNUSED; | 
|---|
| 368 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 369 | char **error_message ATTRIBUTE_UNUSED; | 
|---|
| 370 | { | 
|---|
| 371 | /* FIXME.  */ | 
|---|
| 372 | abort (); | 
|---|
| 373 | } | 
|---|
| 374 |  | 
|---|
| 375 | /* This special function is used for the global 15 bit relocations.  */ | 
|---|
| 376 |  | 
|---|
| 377 | static bfd_reloc_status_type | 
|---|
| 378 | glob15_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | 
|---|
| 379 | error_message) | 
|---|
| 380 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 381 | arelent *reloc_entry ATTRIBUTE_UNUSED; | 
|---|
| 382 | asymbol *symbol_in ATTRIBUTE_UNUSED; | 
|---|
| 383 | PTR data ATTRIBUTE_UNUSED; | 
|---|
| 384 | asection *input_section ATTRIBUTE_UNUSED; | 
|---|
| 385 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 386 | char **error_message ATTRIBUTE_UNUSED; | 
|---|
| 387 | { | 
|---|
| 388 | /* FIXME.  */ | 
|---|
| 389 | abort (); | 
|---|
| 390 | } | 
|---|
| 391 |  | 
|---|
| 392 | /* This special function is used for the global 16 bit relocations.  */ | 
|---|
| 393 |  | 
|---|
| 394 | static bfd_reloc_status_type | 
|---|
| 395 | glob16_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | 
|---|
| 396 | error_message) | 
|---|
| 397 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 398 | arelent *reloc_entry ATTRIBUTE_UNUSED; | 
|---|
| 399 | asymbol *symbol_in ATTRIBUTE_UNUSED; | 
|---|
| 400 | PTR data ATTRIBUTE_UNUSED; | 
|---|
| 401 | asection *input_section ATTRIBUTE_UNUSED; | 
|---|
| 402 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 403 | char **error_message ATTRIBUTE_UNUSED; | 
|---|
| 404 | { | 
|---|
| 405 | /* FIXME.  */ | 
|---|
| 406 | abort (); | 
|---|
| 407 | } | 
|---|
| 408 |  | 
|---|
| 409 | /* This special function is used for the local 16 bit relocations.  */ | 
|---|
| 410 |  | 
|---|
| 411 | static bfd_reloc_status_type | 
|---|
| 412 | local16_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | 
|---|
| 413 | error_message) | 
|---|
| 414 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 415 | arelent *reloc_entry ATTRIBUTE_UNUSED; | 
|---|
| 416 | asymbol *symbol_in ATTRIBUTE_UNUSED; | 
|---|
| 417 | PTR data ATTRIBUTE_UNUSED; | 
|---|
| 418 | asection *input_section ATTRIBUTE_UNUSED; | 
|---|
| 419 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 420 | char **error_message ATTRIBUTE_UNUSED; | 
|---|
| 421 | { | 
|---|
| 422 | /* FIXME.  */ | 
|---|
| 423 | abort (); | 
|---|
| 424 | } | 
|---|
| 425 |  | 
|---|
| 426 |  | 
|---|
| 427 | /* Code to turn an external r_type into a pointer to an entry in the howto_table. | 
|---|
| 428 | If passed an r_type we don't recognize the abort rather than silently failing | 
|---|
| 429 | to generate an output file.  */ | 
|---|
| 430 |  | 
|---|
| 431 | static void | 
|---|
| 432 | rtype2howto (cache_ptr, dst) | 
|---|
| 433 | arelent *cache_ptr; | 
|---|
| 434 | struct internal_reloc *dst; | 
|---|
| 435 | { | 
|---|
| 436 | unsigned int i; | 
|---|
| 437 |  | 
|---|
| 438 | for (i = 0; i < sizeof tic80_howto_table / sizeof tic80_howto_table[0]; i++) | 
|---|
| 439 | { | 
|---|
| 440 | if (tic80_howto_table[i].type == dst->r_type) | 
|---|
| 441 | { | 
|---|
| 442 | cache_ptr->howto = tic80_howto_table + i; | 
|---|
| 443 | return; | 
|---|
| 444 | } | 
|---|
| 445 | } | 
|---|
| 446 |  | 
|---|
| 447 | (*_bfd_error_handler) (_("Unrecognized reloc type 0x%x"), | 
|---|
| 448 | (unsigned int) dst->r_type); | 
|---|
| 449 | cache_ptr->howto = tic80_howto_table + 0; | 
|---|
| 450 | } | 
|---|
| 451 |  | 
|---|
| 452 | #define RTYPE2HOWTO(cache_ptr, dst) rtype2howto (cache_ptr, dst) | 
|---|
| 453 | #define coff_rtype_to_howto coff_tic80_rtype_to_howto | 
|---|
| 454 |  | 
|---|
| 455 | static reloc_howto_type * | 
|---|
| 456 | coff_tic80_rtype_to_howto (abfd, sec, rel, h, sym, addendp) | 
|---|
| 457 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 458 | asection *sec; | 
|---|
| 459 | struct internal_reloc *rel; | 
|---|
| 460 | struct coff_link_hash_entry *h ATTRIBUTE_UNUSED; | 
|---|
| 461 | struct internal_syment *sym ATTRIBUTE_UNUSED; | 
|---|
| 462 | bfd_vma *addendp; | 
|---|
| 463 | { | 
|---|
| 464 | arelent genrel; | 
|---|
| 465 |  | 
|---|
| 466 | if (rel -> r_symndx == -1 && addendp != NULL) | 
|---|
| 467 | { | 
|---|
| 468 | /* This is a TI "internal relocation", which means that the relocation | 
|---|
| 469 | amount is the amount by which the current section is being relocated | 
|---|
| 470 | in the output section.  */ | 
|---|
| 471 | *addendp = (sec -> output_section -> vma + sec -> output_offset) - sec -> vma; | 
|---|
| 472 | } | 
|---|
| 473 | RTYPE2HOWTO (&genrel, rel); | 
|---|
| 474 | return genrel.howto; | 
|---|
| 475 | } | 
|---|
| 476 |  | 
|---|
| 477 | #ifndef BADMAG | 
|---|
| 478 | #define BADMAG(x) TIC80BADMAG(x) | 
|---|
| 479 | #endif | 
|---|
| 480 |  | 
|---|
| 481 |  | 
|---|
| 482 | #define coff_relocate_section coff_tic80_relocate_section | 
|---|
| 483 |  | 
|---|
| 484 | /* We need a special relocation routine to handle the PP relocs.  Most | 
|---|
| 485 | of this is a copy of _bfd_coff_generic_relocate_section.  */ | 
|---|
| 486 |  | 
|---|
| 487 | static boolean | 
|---|
| 488 | coff_tic80_relocate_section (output_bfd, info, input_bfd, | 
|---|
| 489 | input_section, contents, relocs, syms, | 
|---|
| 490 | sections) | 
|---|
| 491 | bfd *output_bfd; | 
|---|
| 492 | struct bfd_link_info *info; | 
|---|
| 493 | bfd *input_bfd; | 
|---|
| 494 | asection *input_section; | 
|---|
| 495 | bfd_byte *contents; | 
|---|
| 496 | struct internal_reloc *relocs; | 
|---|
| 497 | struct internal_syment *syms; | 
|---|
| 498 | asection **sections; | 
|---|
| 499 | { | 
|---|
| 500 | struct internal_reloc *rel; | 
|---|
| 501 | struct internal_reloc *relend; | 
|---|
| 502 |  | 
|---|
| 503 | rel = relocs; | 
|---|
| 504 | relend = rel + input_section->reloc_count; | 
|---|
| 505 | for (; rel < relend; rel++) | 
|---|
| 506 | { | 
|---|
| 507 | long symndx; | 
|---|
| 508 | struct coff_link_hash_entry *h; | 
|---|
| 509 | struct internal_syment *sym; | 
|---|
| 510 | bfd_vma addend; | 
|---|
| 511 | bfd_vma val; | 
|---|
| 512 | reloc_howto_type *howto; | 
|---|
| 513 | bfd_reloc_status_type rstat; | 
|---|
| 514 | bfd_vma addr; | 
|---|
| 515 |  | 
|---|
| 516 | symndx = rel->r_symndx; | 
|---|
| 517 |  | 
|---|
| 518 | if (symndx == -1) | 
|---|
| 519 | { | 
|---|
| 520 | h = NULL; | 
|---|
| 521 | sym = NULL; | 
|---|
| 522 | } | 
|---|
| 523 | else | 
|---|
| 524 | { | 
|---|
| 525 | h = obj_coff_sym_hashes (input_bfd)[symndx]; | 
|---|
| 526 | sym = syms + symndx; | 
|---|
| 527 | } | 
|---|
| 528 |  | 
|---|
| 529 | /* COFF treats common symbols in one of two ways.  Either the | 
|---|
| 530 | size of the symbol is included in the section contents, or it | 
|---|
| 531 | is not.  We assume that the size is not included, and force | 
|---|
| 532 | the rtype_to_howto function to adjust the addend as needed.  */ | 
|---|
| 533 |  | 
|---|
| 534 | if (sym != NULL && sym->n_scnum != 0) | 
|---|
| 535 | addend = - sym->n_value; | 
|---|
| 536 | else | 
|---|
| 537 | addend = 0; | 
|---|
| 538 |  | 
|---|
| 539 | howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h, | 
|---|
| 540 | sym, &addend); | 
|---|
| 541 | if (howto == NULL) | 
|---|
| 542 | return false; | 
|---|
| 543 |  | 
|---|
| 544 | val = 0; | 
|---|
| 545 |  | 
|---|
| 546 | if (h == NULL) | 
|---|
| 547 | { | 
|---|
| 548 | asection *sec; | 
|---|
| 549 |  | 
|---|
| 550 | if (symndx == -1) | 
|---|
| 551 | { | 
|---|
| 552 | sec = bfd_abs_section_ptr; | 
|---|
| 553 | val = 0; | 
|---|
| 554 | } | 
|---|
| 555 | else | 
|---|
| 556 | { | 
|---|
| 557 | sec = sections[symndx]; | 
|---|
| 558 | val = (sec->output_section->vma | 
|---|
| 559 | + sec->output_offset | 
|---|
| 560 | + sym->n_value); | 
|---|
| 561 | if (! obj_pe (output_bfd)) | 
|---|
| 562 | val -= sec->vma; | 
|---|
| 563 | } | 
|---|
| 564 | } | 
|---|
| 565 | else | 
|---|
| 566 | { | 
|---|
| 567 | if (h->root.type == bfd_link_hash_defined | 
|---|
| 568 | || h->root.type == bfd_link_hash_defweak) | 
|---|
| 569 | { | 
|---|
| 570 | asection *sec; | 
|---|
| 571 |  | 
|---|
| 572 | sec = h->root.u.def.section; | 
|---|
| 573 | val = (h->root.u.def.value | 
|---|
| 574 | + sec->output_section->vma | 
|---|
| 575 | + sec->output_offset); | 
|---|
| 576 | } | 
|---|
| 577 |  | 
|---|
| 578 | else if (! info->relocateable) | 
|---|
| 579 | { | 
|---|
| 580 | if (! ((*info->callbacks->undefined_symbol) | 
|---|
| 581 | (info, h->root.root.string, input_bfd, input_section, | 
|---|
| 582 | rel->r_vaddr - input_section->vma, true))) | 
|---|
| 583 | return false; | 
|---|
| 584 | } | 
|---|
| 585 | } | 
|---|
| 586 |  | 
|---|
| 587 | addr = rel->r_vaddr - input_section->vma; | 
|---|
| 588 |  | 
|---|
| 589 | /* FIXME: This code assumes little endian, but the PP can | 
|---|
| 590 | apparently be bi-endian.  I don't know if the bi-endianness | 
|---|
| 591 | applies to the instruction set or just to the data.  */ | 
|---|
| 592 | switch (howto->type) | 
|---|
| 593 | { | 
|---|
| 594 | default: | 
|---|
| 595 | case R_ABS: | 
|---|
| 596 | case R_RELLONGX: | 
|---|
| 597 | case R_PPL15: | 
|---|
| 598 | case R_PPL15W: | 
|---|
| 599 | case R_PPL15H: | 
|---|
| 600 | case R_PPLN15: | 
|---|
| 601 | case R_PPLN15W: | 
|---|
| 602 | case R_PPLN15H: | 
|---|
| 603 | rstat = _bfd_final_link_relocate (howto, input_bfd, input_section, | 
|---|
| 604 | contents, addr, val, addend); | 
|---|
| 605 | break; | 
|---|
| 606 |  | 
|---|
| 607 | case R_PP15: | 
|---|
| 608 | case R_PP15W: | 
|---|
| 609 | case R_PP15H: | 
|---|
| 610 | case R_PPN15: | 
|---|
| 611 | case R_PPN15W: | 
|---|
| 612 | case R_PPN15H: | 
|---|
| 613 | /* Offset the address so that we can use 4 byte relocations.  */ | 
|---|
| 614 | rstat = _bfd_final_link_relocate (howto, input_bfd, input_section, | 
|---|
| 615 | contents + 2, addr, val, addend); | 
|---|
| 616 | break; | 
|---|
| 617 |  | 
|---|
| 618 | case R_PP16B: | 
|---|
| 619 | case R_PPN16B: | 
|---|
| 620 | { | 
|---|
| 621 | /* The most significant bit is stored in bit 6.  */ | 
|---|
| 622 | bfd_byte hold; | 
|---|
| 623 |  | 
|---|
| 624 | hold = contents[addr + 4]; | 
|---|
| 625 | contents[addr + 4] &=~ 0x20; | 
|---|
| 626 | contents[addr + 4] |= (contents[addr] >> 1) & 0x20; | 
|---|
| 627 | rstat = _bfd_final_link_relocate (howto, input_bfd, input_section, | 
|---|
| 628 | contents + 2, addr, | 
|---|
| 629 | val, addend); | 
|---|
| 630 | contents[addr] &=~ 0x40; | 
|---|
| 631 | contents[addr] |= (contents[addr + 4] << 1) & 0x40; | 
|---|
| 632 | contents[addr + 4] &=~ 0x20; | 
|---|
| 633 | contents[addr + 4] |= hold & 0x20; | 
|---|
| 634 | break; | 
|---|
| 635 | } | 
|---|
| 636 |  | 
|---|
| 637 | case R_PPL16B: | 
|---|
| 638 | case R_PPLN16B: | 
|---|
| 639 | { | 
|---|
| 640 | /* The most significant bit is stored in bit 28.  */ | 
|---|
| 641 | bfd_byte hold; | 
|---|
| 642 |  | 
|---|
| 643 | hold = contents[addr + 1]; | 
|---|
| 644 | contents[addr + 1] &=~ 0x80; | 
|---|
| 645 | contents[addr + 1] |= (contents[addr + 3] << 3) & 0x80; | 
|---|
| 646 | rstat = _bfd_final_link_relocate (howto, input_bfd, input_section, | 
|---|
| 647 | contents, addr, | 
|---|
| 648 | val, addend); | 
|---|
| 649 | contents[addr + 3] &= ~0x10; | 
|---|
| 650 | contents[addr + 3] |= (contents[addr + 1] >> 3) & 0x10; | 
|---|
| 651 | contents[addr + 1] &=~ 0x80; | 
|---|
| 652 | contents[addr + 1] |= hold & 0x80; | 
|---|
| 653 | break; | 
|---|
| 654 | } | 
|---|
| 655 |  | 
|---|
| 656 | case R_PPBASE: | 
|---|
| 657 | /* Parameter RAM is from 0x1000000 to 0x1000800.  */ | 
|---|
| 658 | contents[addr] &=~ 0x3; | 
|---|
| 659 | if (val >= 0x1000000 && val < 0x1000800) | 
|---|
| 660 | contents[addr] |= 0x3; | 
|---|
| 661 | else | 
|---|
| 662 | contents[addr] |= 0x2; | 
|---|
| 663 | rstat = bfd_reloc_ok; | 
|---|
| 664 | break; | 
|---|
| 665 |  | 
|---|
| 666 | case R_PPLBASE: | 
|---|
| 667 | /* Parameter RAM is from 0x1000000 to 0x1000800.  */ | 
|---|
| 668 | contents[addr + 2] &= ~0xc0; | 
|---|
| 669 | if (val >= 0x1000000 && val < 0x1000800) | 
|---|
| 670 | contents[addr + 2] |= 0xc0; | 
|---|
| 671 | else | 
|---|
| 672 | contents[addr + 2] |= 0x80; | 
|---|
| 673 | rstat = bfd_reloc_ok; | 
|---|
| 674 | break; | 
|---|
| 675 | } | 
|---|
| 676 |  | 
|---|
| 677 | switch (rstat) | 
|---|
| 678 | { | 
|---|
| 679 | default: | 
|---|
| 680 | abort (); | 
|---|
| 681 | case bfd_reloc_ok: | 
|---|
| 682 | break; | 
|---|
| 683 | case bfd_reloc_outofrange: | 
|---|
| 684 | (*_bfd_error_handler) | 
|---|
| 685 | (_("%s: bad reloc address 0x%lx in section `%s'"), | 
|---|
| 686 | bfd_get_filename (input_bfd), | 
|---|
| 687 | (unsigned long) rel->r_vaddr, | 
|---|
| 688 | bfd_get_section_name (input_bfd, input_section)); | 
|---|
| 689 | return false; | 
|---|
| 690 | case bfd_reloc_overflow: | 
|---|
| 691 | { | 
|---|
| 692 | const char *name; | 
|---|
| 693 | char buf[SYMNMLEN + 1]; | 
|---|
| 694 |  | 
|---|
| 695 | if (symndx == -1) | 
|---|
| 696 | name = "*ABS*"; | 
|---|
| 697 | else if (h != NULL) | 
|---|
| 698 | name = h->root.root.string; | 
|---|
| 699 | else | 
|---|
| 700 | { | 
|---|
| 701 | name = _bfd_coff_internal_syment_name (input_bfd, sym, buf); | 
|---|
| 702 | if (name == NULL) | 
|---|
| 703 | return false; | 
|---|
| 704 | } | 
|---|
| 705 |  | 
|---|
| 706 | if (! ((*info->callbacks->reloc_overflow) | 
|---|
| 707 | (info, name, howto->name, (bfd_vma) 0, input_bfd, | 
|---|
| 708 | input_section, rel->r_vaddr - input_section->vma))) | 
|---|
| 709 | return false; | 
|---|
| 710 | } | 
|---|
| 711 | } | 
|---|
| 712 | } | 
|---|
| 713 | return true; | 
|---|
| 714 | } | 
|---|
| 715 |  | 
|---|
| 716 |  | 
|---|
| 717 | #define TIC80COFF 1             /* Customize coffcode.h */ | 
|---|
| 718 | #undef C_AUTOARG                /* Clashes with TIc80's C_UEXT */ | 
|---|
| 719 | #undef C_LASTENT                /* Clashes with TIc80's C_STATLAB */ | 
|---|
| 720 | #include "coffcode.h" | 
|---|
| 721 |  | 
|---|
| 722 | CREATE_LITTLE_COFF_TARGET_VEC (tic80coff_vec, "coff-tic80", D_PAGED, 0, '_', NULL) | 
|---|