Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/coff-w65.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for WDC 65816 COFF binaries.
    2    Copyright 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
     2   Copyright 1995, 1996, 1997, 1999, 2000, 2001, 2002
     3   Free Software Foundation, Inc.
    34   Written by Steve Chamberlain, <sac@cygnus.com>.
    45
     
    2728#include "libcoff.h"
    2829
     30static int  select_reloc              PARAMS ((reloc_howto_type *));
     31static void rtype2howto               PARAMS ((arelent *, struct internal_reloc *));
     32static void reloc_processing          PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *));
     33static int  w65_reloc16_estimate    PARAMS ((bfd *, asection *, arelent *, unsigned int, struct bfd_link_info *));
     34static void w65_reloc16_extra_cases PARAMS ((bfd *,struct bfd_link_info *, struct bfd_link_order *, arelent *, bfd_byte *, unsigned int *, unsigned int *));
     35
    2936#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
    3037static reloc_howto_type howto_table[] =
    31 {
    32   HOWTO (R_W65_ABS8,    0,  0, 8, false, 0, complain_overflow_bitfield, 0, "abs8", true, 0x000000ff, 0x000000ff, false),
    33   HOWTO (R_W65_ABS16,   1,  0, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false),
    34   HOWTO (R_W65_ABS24,   0,  2, 32, false, 0, complain_overflow_bitfield, 0, "abs24", true, 0x00ffffff, 0x00ffffff, false),
    35   HOWTO (R_W65_ABS8S8,  0,  0, 8, false, 0, complain_overflow_bitfield, 0, ">abs8", true, 0x000000ff, 0x000000ff, false),
    36   HOWTO (R_W65_ABS8S16, 0,  0, 8, false, 0, complain_overflow_bitfield, 0, "^abs8", true, 0x000000ff, 0x000000ff, false),
    37   HOWTO (R_W65_ABS16S8, 1,  0, 16, false, 0, complain_overflow_bitfield, 0, ">abs16", true, 0x0000ffff, 0x0000ffff, false),
    38   HOWTO (R_W65_ABS16S16,1,  0, 16, false, 0, complain_overflow_bitfield, 0, "^abs16", true, 0x0000ffff, 0x0000ffff, false),
    39   HOWTO (R_W65_PCR8,    0,  0, 8, false, 0, complain_overflow_bitfield, 0, "pcrel8", true, 0x000000ff, 0x000000ff, true),
    40   HOWTO (R_W65_PCR16,   1,  0, 16, false, 0, complain_overflow_bitfield, 0, "pcrel16", true, 0x0000ffff, 0x0000ffff, true),
    41   HOWTO (R_W65_DP,    0,  0, 8, false, 0, complain_overflow_bitfield, 0, "dp", true, 0x000000ff, 0x000000ff, false),
    42 
    43 };
    44 
    45 /* Turn a howto into a reloc number */
     38  {
     39    HOWTO (R_W65_ABS8,    0,  0, 8,  FALSE, 0, complain_overflow_bitfield, 0, "abs8", TRUE, 0x000000ff, 0x000000ff, FALSE),
     40    HOWTO (R_W65_ABS16,   1,  0, 16, FALSE, 0, complain_overflow_bitfield, 0, "abs16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
     41    HOWTO (R_W65_ABS24,   0,  2, 32, FALSE, 0, complain_overflow_bitfield, 0, "abs24", TRUE, 0x00ffffff, 0x00ffffff, FALSE),
     42    HOWTO (R_W65_ABS8S8,  0,  0, 8,  FALSE, 0, complain_overflow_bitfield, 0, ">abs8", TRUE, 0x000000ff, 0x000000ff, FALSE),
     43    HOWTO (R_W65_ABS8S16, 0,  0, 8,  FALSE, 0, complain_overflow_bitfield, 0, "^abs8", TRUE, 0x000000ff, 0x000000ff, FALSE),
     44    HOWTO (R_W65_ABS16S8, 1,  0, 16, FALSE, 0, complain_overflow_bitfield, 0, ">abs16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
     45    HOWTO (R_W65_ABS16S16,1,  0, 16, FALSE, 0, complain_overflow_bitfield, 0, "^abs16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
     46    HOWTO (R_W65_PCR8,    0,  0, 8,  FALSE, 0, complain_overflow_bitfield, 0, "pcrel8", TRUE, 0x000000ff, 0x000000ff, TRUE),
     47    HOWTO (R_W65_PCR16,   1,  0, 16, FALSE, 0, complain_overflow_bitfield, 0, "pcrel16", TRUE, 0x0000ffff, 0x0000ffff, TRUE),
     48    HOWTO (R_W65_DP,      0,  0, 8,  FALSE, 0, complain_overflow_bitfield, 0, "dp", TRUE, 0x000000ff, 0x000000ff, FALSE),
     49  };
     50
     51/* Turn a howto into a reloc number.  */
    4652
    4753#define SELECT_RELOC(x,howto) \
     
    5359
    5460/* Code to swap in the reloc */
    55 #define SWAP_IN_RELOC_OFFSET   bfd_h_get_32
    56 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
     61#define SWAP_IN_RELOC_OFFSET    H_GET_32
     62#define SWAP_OUT_RELOC_OFFSET   H_PUT_32
    5763#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
    5864  dst->r_stuff[0] = 'S'; \
     
    6672}
    6773
    68 /* Code to turn a r_type into a howto ptr, uses the above howto table
    69    */
     74/* Code to turn a r_type into a howto ptr, uses the above howto table.  */
    7075
    7176static void
     
    7479     struct internal_reloc *dst;
    7580{
    76       internal->howto = howto_table + dst->r_type - 1;
     81  internal->howto = howto_table + dst->r_type - 1;
    7782}
    7883
    7984#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
    8085
    81 /* Perform any necessary magic to the addend in a reloc entry */
     86/* Perform any necessary magic to the addend in a reloc entry. */
    8287
    8388#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
     
    99104
    100105  if (((int) reloc->r_symndx) > 0)
    101     {
    102       relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
    103     }
     106    relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
    104107  else
    105     {
    106       relent->sym_ptr_ptr = (asymbol **)&(bfd_abs_symbol);
    107     }
     108    relent->sym_ptr_ptr = (asymbol **)&(bfd_abs_symbol);
    108109
    109110  relent->addend = reloc->r_offset;
     
    114115
    115116static int
    116 h8300_reloc16_estimate(abfd, input_section, reloc, shrink, link_info)
     117w65_reloc16_estimate (abfd, input_section, reloc, shrink, link_info)
    117118     bfd *abfd;
    118119     asection *input_section;
     
    128129   the size of the shrink  - but we don't change reloc->address here,
    129130   since we need it to know where the relocation lives in the source
    130    uncooked section */
     131   uncooked section. */
    131132
    132133  /*  reloc->address -= shrink;   conceptual */
     
    141142      break;
    142143
    143       /* Thing is a move one byte */
     144      /* Thing is a move one byte. */
    144145    case R_MOV16B1:
    145       value = bfd_coff_reloc16_get_value(reloc, link_info, input_section);
     146      value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
    146147
    147148      if (value >= 0xff00)
    148149        {
    149 
    150150          /* Change the reloc type from 16bit, possible 8 to 8bit
    151              possible 16 */
     151             possible 16. */
    152152          reloc->howto = reloc->howto + 1;
    153           /* The place to relc moves back by one */
    154           /* This will be two bytes smaller in the long run */
    155           shrink +=2 ;
    156           bfd_perform_slip(abfd, 2, input_section, address);
     153          /* The place to relc moves back by one. */
     154          /* This will be two bytes smaller in the long run. */
     155          shrink += 2;
     156          bfd_perform_slip (abfd, 2, input_section, address);
    157157        }
    158158
    159159      break;
    160160      /* This is the 24 bit branch which could become an 8 bitter,
    161       the relocation points to the first byte of the insn, not the
    162        actual data */
     161        the relocation points to the first byte of the insn, not the
     162         actual data. */
    163163
    164164    case R_JMPL1:
    165       value = bfd_coff_reloc16_get_value(reloc, link_info, input_section);
     165      value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
    166166
    167167      dot = input_section->output_section->vma +
     
    170170      /* See if the address we're looking at within 127 bytes of where
    171171         we are, if so then we can use a small branch rather than the
    172          jump we were going to */
    173 
    174       gap = value - dot ;
    175 
    176       if (-120 < (long)gap && (long)gap < 120 )
     172         jump we were going to.  */
     173      gap = value - dot;
     174
     175      if (-120 < (long) gap && (long) gap < 120)
    177176        {
    178 
    179177          /* Change the reloc type from 24bit, possible 8 to 8bit
    180              possible 32 */
     178             possible 32. */
    181179          reloc->howto = reloc->howto + 1;
    182           /* This will be two bytes smaller in the long run */
    183           shrink +=2 ;
    184           bfd_perform_slip(abfd, 2, input_section, address);
     180          /* This will be two bytes smaller in the long run. */
     181          shrink += 2;
     182          bfd_perform_slip (abfd, 2, input_section, address);
    185183        }
    186184      break;
    187185
    188186    case R_JMP1:
    189 
    190       value = bfd_coff_reloc16_get_value(reloc, link_info, input_section);
     187      value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
    191188
    192189      dot = input_section->output_section->vma +
     
    195192      /* See if the address we're looking at within 127 bytes of where
    196193         we are, if so then we can use a small branch rather than the
    197          jump we were going to */
    198 
     194         jump we were going to.  */
    199195      gap = value - (dot - shrink);
    200196
    201       if (-120 < (long)gap && (long)gap < 120 )
     197      if (-120 < (long) gap && (long) gap < 120)
    202198        {
    203 
    204199          /* Change the reloc type from 16bit, possible 8 to 8bit
    205              possible 16 */
     200             possible 16. */
    206201          reloc->howto = reloc->howto + 1;
    207           /* The place to relc moves back by one */
    208 
    209           /* This will be two bytes smaller in the long run */
    210           shrink +=2 ;
    211           bfd_perform_slip(abfd, 2, input_section, address);
     202          /* The place to relc moves back by one. */
     203
     204          /* This will be two bytes smaller in the long run. */
     205          shrink += 2;
     206          bfd_perform_slip (abfd, 2, input_section, address);
    212207        }
    213208      break;
     
    217212}
    218213
    219 /* First phase of a relaxing link */
     214/* First phase of a relaxing link. */
    220215
    221216/* Reloc types
     
    224219   R_JMP1               R_JMP2          jmp or pcrel branch
    225220   R_JMPL1              R_JMPL_B8       24jmp or pcrel branch
    226    R_MOV24B1            R_MOV24B2       24 or 8 bit reloc for mov.b
    227 
    228 */
     221   R_MOV24B1            R_MOV24B2       24 or 8 bit reloc for mov.b  */
    229222
    230223static void
    231 h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr,
     224w65_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr,
    232225                           dst_ptr)
    233226     bfd *abfd;
     
    271264        unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info,
    272265                                                       input_section);
    273         gap >>=16;
     266        gap >>= 16;
    274267        bfd_put_8 (abfd, gap, data + dst_address);
    275268        dst_address += 1;
     
    283276                                                       input_section);
    284277
    285         bfd_put_16 (abfd, gap, data + dst_address);
     278        bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address);
    286279        dst_address += 2;
    287280        src_address += 2;
     
    293286                                                       input_section);
    294287        gap >>= 8;
    295         bfd_put_16 (abfd, gap, data + dst_address);
     288        bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address);
    296289        dst_address += 2;
    297290        src_address += 2;
     
    303296                                                       input_section);
    304297        gap >>= 16;
    305         bfd_put_16 (abfd, gap, data + dst_address);
     298        bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address);
    306299        dst_address += 2;
    307300        src_address += 2;
     
    313306        unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info,
    314307                                                       input_section);
    315         bfd_put_16 (abfd, gap, data + dst_address);
    316         bfd_put_8 (abfd, gap>>16, data+dst_address+2);
     308        bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address);
     309        bfd_put_8 (abfd, gap >> 16, data+dst_address + 2);
    317310        dst_address += 3;
    318311        src_address += 3;
     
    329322
    330323        gap -= dot + 1;
    331         if (gap < -128 || gap > 127) {
    332           if (! ((*link_info->callbacks->reloc_overflow)
    333                  (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
    334                   reloc->howto->name, reloc->addend, input_section->owner,
    335                   input_section, reloc->address)))
    336             abort ();
    337         }
     324        if (gap < -128 || gap > 127)
     325          {
     326            if (! ((*link_info->callbacks->reloc_overflow)
     327                   (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
     328                    reloc->howto->name, reloc->addend, input_section->owner,
     329                    input_section, reloc->address)))
     330              abort ();
     331          }
    338332        bfd_put_8 (abfd, gap, data + dst_address);
    339333        dst_address += 1;
     
    351345
    352346        /* This wraps within the page, so ignore the relativeness, look at the
    353            high part */
    354         if ((gap & 0xf0000) != (dot & 0xf0000)) {
    355           if (! ((*link_info->callbacks->reloc_overflow)
    356                  (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
    357                   reloc->howto->name, reloc->addend, input_section->owner,
    358                   input_section, reloc->address)))
    359             abort ();
    360         }
     347           high part.  */
     348        if ((gap & 0xf0000) != (dot & 0xf0000))
     349          {
     350            if (! ((*link_info->callbacks->reloc_overflow)
     351                   (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
     352                    reloc->howto->name, reloc->addend, input_section->owner,
     353                    input_section, reloc->address)))
     354              abort ();
     355          }
    361356
    362357        gap -= dot + 2;
     
    373368  *src_ptr = src_address;
    374369  *dst_ptr = dst_address;
    375 
    376 }
    377 
    378 #define coff_reloc16_extra_cases h8300_reloc16_extra_cases
    379 #define coff_reloc16_estimate h8300_reloc16_estimate
     370}
     371
     372#define coff_reloc16_extra_cases w65_reloc16_extra_cases
     373#define coff_reloc16_estimate w65_reloc16_estimate
    380374
    381375#include "coffcode.h"
Note: See TracChangeset for help on using the changeset viewer.