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-z8k.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for Zilog Z800n COFF binaries.
    2    Copyright 1992, 1993, 1994, 1995, 1997, 1999, 2000, 2001
     2   Copyright 1992, 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002
    33   Free Software Foundation, Inc.
    44   Contributed by Cygnus Support.
     
    2929#include "libcoff.h"
    3030
     31static void extra_case PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *, bfd_byte *, unsigned int *, unsigned int *));
     32static void reloc_processing PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *));
     33static void rtype2howto PARAMS ((arelent *, struct internal_reloc *));
     34static int coff_z8k_select_reloc PARAMS ((reloc_howto_type *));
     35
    3136#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
    3237
    3338static reloc_howto_type r_imm32 =
    34 HOWTO (R_IMM32, 0, 1, 32, false, 0,
    35        complain_overflow_bitfield, 0, "r_imm32", true, 0xffffffff,
    36        0xffffffff, false);
     39HOWTO (R_IMM32, 0, 2, 32, FALSE, 0,
     40       complain_overflow_bitfield, 0, "r_imm32", TRUE, 0xffffffff,
     41       0xffffffff, FALSE);
    3742
    3843static reloc_howto_type r_imm4l =
    39 HOWTO (R_IMM4L, 0, 1, 4, false, 0,
    40        complain_overflow_bitfield, 0, "r_imm4l", true, 0xf, 0xf, false);
     44HOWTO (R_IMM4L, 0, 0, 4, FALSE, 0,
     45       complain_overflow_bitfield, 0, "r_imm4l", TRUE, 0xf, 0xf, FALSE);
    4146
    4247static reloc_howto_type r_da =
    43 HOWTO (R_IMM16, 0, 1, 16, false, 0,
    44        complain_overflow_bitfield, 0, "r_da", true, 0x0000ffff, 0x0000ffff,
    45        false);
     48HOWTO (R_IMM16, 0, 1, 16, FALSE, 0,
     49       complain_overflow_bitfield, 0, "r_da", TRUE, 0x0000ffff, 0x0000ffff,
     50       FALSE);
    4651
    4752static reloc_howto_type r_imm8 =
    48 HOWTO (R_IMM8, 0, 1, 8, false, 0,
    49        complain_overflow_bitfield, 0, "r_imm8", true, 0x000000ff, 0x000000ff,
    50        false);
     53HOWTO (R_IMM8, 0, 0, 8, FALSE, 0,
     54       complain_overflow_bitfield, 0, "r_imm8", TRUE, 0x000000ff, 0x000000ff,
     55       FALSE);
     56
     57static reloc_howto_type r_rel16 =
     58HOWTO (R_REL16, 0, 1, 16, FALSE, 0,
     59       complain_overflow_bitfield, 0, "r_rel16", TRUE, 0x0000ffff, 0x0000ffff,
     60       TRUE);
    5161
    5262static reloc_howto_type r_jr =
    53 HOWTO (R_JR, 0, 1, 8, true, 0, complain_overflow_signed, 0,
    54        "r_jr", true, 0, 0, true);
     63HOWTO (R_JR, 0, 0, 8, TRUE, 0, complain_overflow_signed, 0,
     64       "r_jr", TRUE, 0, 0, TRUE);
     65
     66static reloc_howto_type r_disp7 =
     67HOWTO (R_DISP7, 0, 0, 7, TRUE, 0, complain_overflow_bitfield, 0,
     68       "r_disp7", TRUE, 0, 0, TRUE);
     69
     70static reloc_howto_type r_callr =
     71HOWTO (R_CALLR, 0, 1, 12, TRUE, 0, complain_overflow_signed, 0,
     72       "r_callr", TRUE, 0xfff, 0xfff, TRUE);
    5573
    5674/* Turn a howto into a reloc number */
     
    6987#define __A_MAGIC_SET__
    7088
    71 /* Code to swap in the reloc */
    72 #define SWAP_IN_RELOC_OFFSET   bfd_h_get_32
    73 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
     89/* Code to swap in the reloc. */
     90#define SWAP_IN_RELOC_OFFSET    H_GET_32
     91#define SWAP_OUT_RELOC_OFFSET   H_PUT_32
    7492#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
    7593  dst->r_stuff[0] = 'S'; \
    7694  dst->r_stuff[1] = 'C';
    7795
    78 /* Code to turn a r_type into a howto ptr, uses the above howto table
    79    */
     96/* Code to turn a r_type into a howto ptr, uses the above howto table.  */
    8097
    8198static void
     
    98115      internal->howto = &r_jr;
    99116      break;
     117    case R_DISP7:
     118      internal->howto = &r_disp7;
     119      break;
     120    case R_CALLR:
     121      internal->howto = &r_callr;
     122      break;
     123    case R_REL16:
     124      internal->howto = &r_rel16;
     125      break;
    100126    case R_IMM32:
    101127      internal->howto = &r_imm32;
     
    107133}
    108134
    109 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
    110 
    111 /* Perform any necessary magic to the addend in a reloc entry */
     135#define RTYPE2HOWTO(internal, relocentry) rtype2howto (internal, relocentry)
     136
     137/* Perform any necessary magic to the addend in a reloc entry. */
    112138
    113139#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
     
    120146reloc_processing (relent, reloc, symbols, abfd, section)
    121147     arelent * relent;
    122      struct internal_reloc *reloc;
     148     struct internal_reloc * reloc;
    123149     asymbol ** symbols;
    124150     bfd * abfd;
     
    129155
    130156  if (reloc->r_symndx > 0)
    131     {
    132       relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
    133     }
     157    relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
    134158  else
    135     {
    136       relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
    137     }
     159    relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
    138160
    139161  relent->addend = reloc->r_offset;
     
    143165static void
    144166extra_case (in_abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)
    145      bfd *in_abfd;
    146      struct bfd_link_info *link_info;
    147      struct bfd_link_order *link_order;
    148      arelent *reloc;
    149      bfd_byte *data;
    150      unsigned int *src_ptr;
    151      unsigned int *dst_ptr;
     167     bfd * in_abfd;
     168     struct bfd_link_info * link_info;
     169     struct bfd_link_order * link_order;
     170     arelent * reloc;
     171     bfd_byte * data;
     172     unsigned int * src_ptr;
     173     unsigned int * dst_ptr;
    152174{
    153   asection *input_section = link_order->u.indirect.section;
     175  asection * input_section = link_order->u.indirect.section;
    154176
    155177  switch (reloc->howto->type)
     
    164186
    165187    case R_IMM32:
    166       bfd_put_32 (in_abfd,
    167                   bfd_coff_reloc16_get_value (reloc, link_info, input_section),
    168                   data + *dst_ptr);
     188      /* If no flags are set, assume immediate value.  */
     189      if (! (*reloc->sym_ptr_ptr)->section->flags)
     190        {
     191          bfd_put_32 (in_abfd,
     192                      bfd_coff_reloc16_get_value (reloc, link_info,
     193                                                  input_section),
     194                      data + *dst_ptr);
     195        }
     196      else
     197        {
     198          bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
     199                                                    input_section);
     200          /* Adresses are 23 bit, and the layout of those in a 32-bit
     201             value is as follows:
     202               1AAAAAAA xxxxxxxx AAAAAAAA AAAAAAAA
     203             (A - address bits,  x - ignore).  */
     204          dst = (dst & 0xffff) | ((dst & 0xff0000) << 8) | 0x80000000;
     205          bfd_put_32 (in_abfd, dst, data + *dst_ptr);
     206        }
    169207      (*dst_ptr) += 4;
    170208      (*src_ptr) += 4;
     
    197235                       + *dst_ptr
    198236                       + input_section->output_section->vma);
    199         int gap = dst - dot - 1;/* -1 since were in the odd byte of the
    200                                     word and the pc's been incremented */
     237        int gap = dst - dot - 1;  /* -1, since we're in the odd byte of the
     238                                     word and the pc's been incremented. */
    201239
    202240        if (gap & 1)
     
    216254        break;
    217255      }
     256
     257    case R_DISP7:
     258      {
     259        bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
     260                                                  input_section);
     261        bfd_vma dot = (link_order->offset
     262                       + *dst_ptr
     263                       + input_section->output_section->vma);
     264        int gap = dst - dot - 1;  /* -1, since we're in the odd byte of the
     265                                     word and the pc's been incremented.  */
     266
     267        if (gap & 1)
     268          abort ();
     269        gap /= 2;
     270
     271        if (gap > 0 || gap < -128)
     272          {
     273            if (! ((*link_info->callbacks->reloc_overflow)
     274                   (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
     275                    reloc->howto->name, reloc->addend, input_section->owner,
     276                    input_section, reloc->address)))
     277              abort ();
     278          }
     279        bfd_put_8 (in_abfd,
     280                   (bfd_get_8 ( in_abfd, data + *dst_ptr) & 0x80) + (-gap & 0x7f),
     281                   data + *dst_ptr);
     282        (*dst_ptr)++;
     283        (*src_ptr)++;
     284        break;
     285      }
     286
     287    case R_CALLR:
     288      {
     289        bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
     290                                                  input_section);
     291        bfd_vma dot = (link_order->offset
     292                       + *dst_ptr
     293                       + input_section->output_section->vma);
     294        int gap = dst - dot - 2;
     295
     296        if (gap & 1)
     297          abort ();
     298        gap /= 2;
     299        if (gap > 8191 || gap < -8192)
     300          {
     301            if (! ((*link_info->callbacks->reloc_overflow)
     302                   (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
     303                    reloc->howto->name, reloc->addend, input_section->owner,
     304                    input_section, reloc->address)))
     305              abort ();
     306          }
     307        bfd_put_16 (in_abfd,
     308                    (bfd_get_16 ( in_abfd, data + *dst_ptr) & 0xf000) | (-gap & 0x0fff),
     309                    data + *dst_ptr);
     310        (*dst_ptr) += 2;
     311        (*src_ptr) += 2;
     312        break;
     313      }
     314
     315    case R_REL16:
     316      {
     317        bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
     318                                                  input_section);
     319        bfd_vma dot = (link_order->offset
     320                       + *dst_ptr
     321                       + input_section->output_section->vma);
     322        int gap = dst - dot - 2;
     323
     324        if (gap > 32767 || gap < -32768)
     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          }
     332        bfd_put_16 (in_abfd, (bfd_vma) gap, data + *dst_ptr);
     333        (*dst_ptr) += 2;
     334        (*src_ptr) += 2;
     335        break;
     336      }
     337
    218338    default:
    219339      abort ();
Note: See TracChangeset for help on using the changeset viewer.