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/aout-ns32k.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for ns32k a.out-ish binaries.
    2    Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1998, 2000
     2   Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1998, 2000, 2001, 2002, 2003
    33   Free Software Foundation, Inc.
    44   Contributed by Ian Dall (idall@eleceng.adelaide.edu.au).
    55
    6 This file is part of BFD, the Binary File Descriptor library.
    7 
    8 This program is free software; you can redistribute it and/or modify
    9 it under the terms of the GNU General Public License as published by
    10 the Free Software Foundation; either version 2 of the License, or
    11 (at your option) any later version.
    12 
    13 This program is distributed in the hope that it will be useful,
    14 but WITHOUT ANY WARRANTY; without even the implied warranty of
    15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16 GNU General Public License for more details.
    17 
    18 You should have received a copy of the GNU General Public License
    19 along with this program; if not, write to the Free Software
    20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    21 
    22 #define BYTES_IN_WORD 4
     6   This file is part of BFD, the Binary File Descriptor library.
     7
     8   This program is free software; you can redistribute it and/or modify
     9   it under the terms of the GNU General Public License as published by
     10   the Free Software Foundation; either version 2 of the License, or
     11   (at your option) any later version.
     12
     13   This program is distributed in the hope that it will be useful,
     14   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16   GNU General Public License for more details.
     17
     18   You should have received a copy of the GNU General Public License
     19   along with this program; if not, write to the Free Software
     20   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    2321
    2422#include "bfd.h"
     
    2624#include "ns32k.h"
    2725
    28 #define MYNS(OP) CAT(ns32kaout_,OP)
     26/* Do not "beautify" the CONCAT* macro args.  Traditional C will not
     27   remove whitespace added here, and thus will fail to concatenate
     28   the tokens.  */
     29#define MYNS(OP) CONCAT2 (ns32kaout_,OP)
     30
    2931reloc_howto_type *
    3032MYNS(bfd_reloc_type_lookup)
     
    3234          bfd_reloc_code_real_type code));
    3335
    34 boolean
     36bfd_boolean
    3537MYNS(write_object_contents)
    3638  PARAMS((bfd *abfd));
    3739
    38 /* Avoid multiple definitions from aoutx if supporting standard a.out format(s)
    39  * as well as this one
    40  */
    41 #define NAME(x,y) CAT3(ns32kaout,_32_,y)
     40/* Avoid multiple definitions from aoutx if supporting
     41   standard a.out format(s) as well as this one.  */
     42#define NAME(x,y) CONCAT3 (ns32kaout,_32_,y)
    4243
    4344void bfd_ns32k_arch PARAMS ((void));
     
    4748#define MY(OP) MYNS(OP)
    4849
    49 #define MY_swap_std_reloc_in MY(swap_std_reloc_in)
     50#define MY_swap_std_reloc_in  MY(swap_std_reloc_in)
    5051#define MY_swap_std_reloc_out MY(swap_std_reloc_out)
    5152
    5253static void
    53 MY_swap_std_reloc_in PARAMS ((bfd *abfd, struct reloc_std_external *bytes,
    54                               arelent *cache_ptr, asymbol **symbols,
    55                               bfd_size_type symcount));
    56 
     54MY_swap_std_reloc_in PARAMS ((bfd *, struct reloc_std_external *,
     55                              arelent *, asymbol **,
     56                              bfd_size_type));
    5757static void
    58 MY_swap_std_reloc_out PARAMS ((bfd *abfd, arelent *g,
    59                                struct reloc_std_external *natptr));
     58MY_swap_std_reloc_out PARAMS ((bfd *, arelent *,
     59                               struct reloc_std_external *));
     60reloc_howto_type *
     61MY(reloc_howto) PARAMS ((bfd *, struct reloc_std_external *,
     62                         int *, int *, int *));
     63void
     64MY(put_reloc) PARAMS ((bfd *, int, int, bfd_vma, reloc_howto_type *,
     65                       struct reloc_std_external *));
    6066
    6167/* The ns32k series is ah, unusual, when it comes to relocation.
    62  * There are three storage methods for relocateable objects.  There
    63  * are displacements, immediate operands and ordinary twos complement
    64  * data. Of these, only the last fits into the standard relocation
    65  * scheme.  Immediate operands are stored huffman encoded and
    66  * immediate operands are stored big endian (where as the natural byte
    67  * order is little endian for this achitecture).
    68 
    69  * Note that the ns32k displacement storage method is orthogonal to
    70  * whether the relocation is pc relative or not. The "displacement"
    71  * storage scheme is used for essentially all address constants. The
    72  * displacement can be relative to zero (absolute displacement),
    73  * relative to the pc (pc relative), the stack pointer, the frame
    74  * pointer, the static base register and general purpose register etc.
    75 
    76  * For example:
    77  *
    78  *  sym1: .long .       # pc relative 2's complement
    79  *  sym1: .long foo     # 2's complement not pc relative
    80  *
    81  *  self:  movd @self, r0 # pc relative displacement
    82  *         movd foo, r0 # non pc relative displacement
    83  *
    84  *  self:  movd self, r0 # pc relative immediate
    85  *         movd foo, r0 # non pc relative immediate
    86  *
    87  * In addition, for historical reasons the encoding of the relocation types
    88  * in the a.out format relocation entries is such that even the relocation
    89  * methods which are standard are not encoded the standard way.
    90  *
    91  */
     68   There are three storage methods for relocateable objects.  There
     69   are displacements, immediate operands and ordinary twos complement
     70   data. Of these, only the last fits into the standard relocation
     71   scheme.  Immediate operands are stored huffman encoded and
     72   immediate operands are stored big endian (where as the natural byte
     73   order is little endian for this achitecture).
     74
     75   Note that the ns32k displacement storage method is orthogonal to
     76   whether the relocation is pc relative or not. The "displacement"
     77   storage scheme is used for essentially all address constants. The
     78   displacement can be relative to zero (absolute displacement),
     79   relative to the pc (pc relative), the stack pointer, the frame
     80   pointer, the static base register and general purpose register etc.
     81
     82   For example:
     83
     84   sym1: .long .         # pc relative 2's complement
     85   sym1: .long foo       # 2's complement not pc relative
     86
     87   self:  movd @self, r0 # pc relative displacement
     88          movd foo, r0   # non pc relative displacement
     89
     90   self:  movd self, r0  # pc relative immediate
     91          movd foo, r0   # non pc relative immediate
     92
     93   In addition, for historical reasons the encoding of the relocation types
     94   in the a.out format relocation entries is such that even the relocation
     95   methods which are standard are not encoded the standard way.  */
    9296
    9397reloc_howto_type MY(howto_table)[] =
    94 {
    95   /* ns32k immediate operands */
    96   HOWTO (BFD_RELOC_NS32K_IMM_8, 0, 0, 8, false, 0, true,
    97          _bfd_ns32k_reloc_imm, "NS32K_IMM_8",
    98          true, 0x000000ff,0x000000ff, false),
    99   HOWTO (BFD_RELOC_NS32K_IMM_16, 0, 1, 16, false, 0, true,
    100          _bfd_ns32k_reloc_imm,  "NS32K_IMM_16",
    101          true, 0x0000ffff,0x0000ffff, false),
    102   HOWTO (BFD_RELOC_NS32K_IMM_32, 0, 2, 32, false, 0, true,
    103          _bfd_ns32k_reloc_imm, "NS32K_IMM_32",
    104          true, 0xffffffff,0xffffffff, false),
    105   HOWTO (BFD_RELOC_NS32K_IMM_8_PCREL, 0, 0, 8, true, 0, false,
    106          _bfd_ns32k_reloc_imm, "PCREL_NS32K_IMM_8",
    107          true, 0x000000ff, 0x000000ff, false),
    108   HOWTO (BFD_RELOC_NS32K_IMM_16_PCREL, 0, 1, 16, true, 0, false,
    109          _bfd_ns32k_reloc_imm, "PCREL_NS32K_IMM_16",
    110          true, 0x0000ffff,0x0000ffff, false),
    111   HOWTO (BFD_RELOC_NS32K_IMM_32_PCREL, 0, 2, 32, true, 0, false,
    112          _bfd_ns32k_reloc_imm, "PCREL_NS32K_IMM_32",
    113          true, 0xffffffff,0xffffffff, false),
    114 
    115   /* ns32k displacements */
    116   HOWTO (BFD_RELOC_NS32K_DISP_8, 0, 0, 8, false, 0, true,
    117          _bfd_ns32k_reloc_disp, "NS32K_DISP_8",
    118          true, 0x000000ff,0x000000ff, false),
    119   HOWTO (BFD_RELOC_NS32K_DISP_16, 0, 1, 16, false, 0, true,
    120          _bfd_ns32k_reloc_disp, "NS32K_DISP_16",
    121          true, 0x0000ffff, 0x0000ffff, false),
    122   HOWTO (BFD_RELOC_NS32K_DISP_32, 0, 2, 32, false, 0, true,
    123          _bfd_ns32k_reloc_disp, "NS32K_DISP_32",
    124          true, 0xffffffff, 0xffffffff, false),
    125   HOWTO (BFD_RELOC_NS32K_DISP_8_PCREL, 0, 0, 8, true, 0, false,
    126          _bfd_ns32k_reloc_disp, "PCREL_NS32K_DISP_8",
    127          true, 0x000000ff,0x000000ff, false),
    128   HOWTO (BFD_RELOC_NS32K_DISP_16_PCREL, 0, 1, 16, true, 0, false,
    129          _bfd_ns32k_reloc_disp, "PCREL_NS32K_DISP_16",
    130          true, 0x0000ffff,0x0000ffff, false),
    131   HOWTO (BFD_RELOC_NS32K_DISP_32_PCREL, 0, 2, 32, true, 0, false,
    132          _bfd_ns32k_reloc_disp, "PCREL_NS32K_DISP_32",
    133          true, 0xffffffff,0xffffffff, false),
    134 
    135   /* Normal 2's complement */
    136   HOWTO (BFD_RELOC_8, 0, 0, 8, false, 0, complain_overflow_bitfield,0,
    137          "8", true, 0x000000ff,0x000000ff, false),
    138   HOWTO (BFD_RELOC_16, 0, 1, 16, false, 0, complain_overflow_bitfield,0,
    139          "16", true, 0x0000ffff,0x0000ffff, false),
    140   HOWTO (BFD_RELOC_32, 0, 2, 32, false, 0, complain_overflow_bitfield,0,
    141          "32", true, 0xffffffff,0xffffffff, false),
    142   HOWTO (BFD_RELOC_8_PCREL, 0, 0, 8, true, 0, complain_overflow_signed, 0,
    143          "PCREL_8", true, 0x000000ff,0x000000ff, false),
    144   HOWTO (BFD_RELOC_16_PCREL, 0, 1, 16, true, 0, complain_overflow_signed, 0,
    145          "PCREL_16", true, 0x0000ffff,0x0000ffff, false),
    146   HOWTO (BFD_RELOC_32_PCREL, 0, 2, 32, true, 0, complain_overflow_signed, 0,
    147          "PCREL_32", true, 0xffffffff,0xffffffff, false),
    148 };
     98  {
     99    /* type           rs   size bsz  pcrel bitpos ovrf                  sf name          part_inpl readmask setmask pcdone */
     100    /* ns32k immediate operands.  */
     101    HOWTO (BFD_RELOC_NS32K_IMM_8, 0, 0, 8, FALSE, 0, complain_overflow_signed,
     102           _bfd_ns32k_reloc_imm, "NS32K_IMM_8",
     103           TRUE, 0x000000ff,0x000000ff, FALSE),
     104    HOWTO (BFD_RELOC_NS32K_IMM_16, 0, 1, 16, FALSE, 0, complain_overflow_signed,
     105           _bfd_ns32k_reloc_imm,  "NS32K_IMM_16",
     106           TRUE, 0x0000ffff,0x0000ffff, FALSE),
     107    HOWTO (BFD_RELOC_NS32K_IMM_32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
     108           _bfd_ns32k_reloc_imm, "NS32K_IMM_32",
     109           TRUE, 0xffffffff,0xffffffff, FALSE),
     110    HOWTO (BFD_RELOC_NS32K_IMM_8_PCREL, 0, 0, 8, TRUE, 0, complain_overflow_signed,
     111           _bfd_ns32k_reloc_imm, "PCREL_NS32K_IMM_8",
     112           TRUE, 0x000000ff, 0x000000ff, FALSE),
     113    HOWTO (BFD_RELOC_NS32K_IMM_16_PCREL, 0, 1, 16, TRUE, 0, complain_overflow_signed,
     114           _bfd_ns32k_reloc_imm, "PCREL_NS32K_IMM_16",
     115           TRUE, 0x0000ffff,0x0000ffff, FALSE),
     116    HOWTO (BFD_RELOC_NS32K_IMM_32_PCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed,
     117           _bfd_ns32k_reloc_imm, "PCREL_NS32K_IMM_32",
     118           TRUE, 0xffffffff,0xffffffff, FALSE),
     119
     120    /* ns32k displacements.  */
     121    HOWTO (BFD_RELOC_NS32K_DISP_8, 0, 0, 7, FALSE, 0, complain_overflow_signed,
     122           _bfd_ns32k_reloc_disp, "NS32K_DISP_8",
     123           TRUE, 0x000000ff,0x000000ff, FALSE),
     124    HOWTO (BFD_RELOC_NS32K_DISP_16, 0, 1, 14, FALSE, 0, complain_overflow_signed,
     125           _bfd_ns32k_reloc_disp, "NS32K_DISP_16",
     126           TRUE, 0x0000ffff, 0x0000ffff, FALSE),
     127    HOWTO (BFD_RELOC_NS32K_DISP_32, 0, 2, 30, FALSE, 0, complain_overflow_signed,
     128           _bfd_ns32k_reloc_disp, "NS32K_DISP_32",
     129           TRUE, 0xffffffff, 0xffffffff, FALSE),
     130    HOWTO (BFD_RELOC_NS32K_DISP_8_PCREL, 0, 0, 7, TRUE, 0, complain_overflow_signed,
     131           _bfd_ns32k_reloc_disp, "PCREL_NS32K_DISP_8",
     132           TRUE, 0x000000ff,0x000000ff, FALSE),
     133    HOWTO (BFD_RELOC_NS32K_DISP_16_PCREL, 0, 1, 14, TRUE, 0, complain_overflow_signed,
     134           _bfd_ns32k_reloc_disp, "PCREL_NS32K_DISP_16",
     135           TRUE, 0x0000ffff,0x0000ffff, FALSE),
     136    HOWTO (BFD_RELOC_NS32K_DISP_32_PCREL, 0, 2, 30, TRUE, 0, complain_overflow_signed,
     137           _bfd_ns32k_reloc_disp, "PCREL_NS32K_DISP_32",
     138           TRUE, 0xffffffff,0xffffffff, FALSE),
     139
     140    /* Normal 2's complement.  */
     141    HOWTO (BFD_RELOC_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,0,
     142           "8", TRUE, 0x000000ff,0x000000ff, FALSE),
     143    HOWTO (BFD_RELOC_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,0,
     144           "16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
     145    HOWTO (BFD_RELOC_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,
     146           "32", TRUE, 0xffffffff,0xffffffff, FALSE),
     147    HOWTO (BFD_RELOC_8_PCREL, 0, 0, 8, TRUE, 0, complain_overflow_signed, 0,
     148           "PCREL_8", TRUE, 0x000000ff,0x000000ff, FALSE),
     149    HOWTO (BFD_RELOC_16_PCREL, 0, 1, 16, TRUE, 0, complain_overflow_signed, 0,
     150           "PCREL_16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
     151    HOWTO (BFD_RELOC_32_PCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed, 0,
     152           "PCREL_32", TRUE, 0xffffffff,0xffffffff, FALSE),
     153  };
    149154
    150155#define CTOR_TABLE_RELOC_HOWTO(BFD) (MY(howto_table) + 14)
     
    165170  unsigned int r_length;
    166171  int r_ns32k_type;
    167 /*  BFD_ASSERT(bfd_header_little_endian (abfd)); */
     172
     173  /*  BFD_ASSERT(bfd_header_little_endian (abfd)); */
    168174  *r_index =  ((rel->r_index[2] << 16)
    169175               | (rel->r_index[1] << 8)
     
    178184}
    179185
    180 #define MY_reloc_howto(BFD,REL,IN,EX,PC) MY(reloc_howto) (BFD, REL, &IN, &EX, &PC)
     186#define MY_reloc_howto(BFD, REL, IN, EX, PC) \
     187  MY(reloc_howto) (BFD, REL, &IN, &EX, &PC)
    181188
    182189void
     
    185192     int r_extern;
    186193     int r_index;
    187      long value;
     194     bfd_vma value;
    188195     reloc_howto_type *howto;
    189196     struct reloc_std_external *reloc;
     
    192199  int r_pcrel;
    193200  int r_ns32k_type;
     201
    194202  PUT_WORD (abfd, value, reloc->r_address);
    195   r_length = howto->size ;      /* Size as a power of two */
    196   r_pcrel  = (int) howto->pc_relative; /* Relative to PC? */
     203  r_length = howto->size ;      /* Size as a power of two. */
     204  r_pcrel  = (int) howto->pc_relative; /* Relative to PC?  */
    197205  r_ns32k_type = (howto - MY(howto_table) )/6;
    198 /*  BFD_ASSERT (bfd_header_little_endian (abfd)); */
     206
     207  /*  BFD_ASSERT (bfd_header_little_endian (abfd)); */
    199208  reloc->r_index[2] = r_index >> 16;
    200209  reloc->r_index[1] = r_index >> 8;
     
    215224#define MY_relocate_contents _bfd_ns32k_relocate_contents
    216225
    217 #include <aoutx.h>
     226#include "aoutx.h"
    218227
    219228reloc_howto_type *
     
    233242      case 32:
    234243        code = BFD_RELOC_32;
     244        break;
     245      default:
    235246        break;
    236247      }
     
    255266      ENTRY(BFD_RELOC_16_PCREL, 16);
    256267      ENTRY(BFD_RELOC_32_PCREL, 17);
    257     default: return (reloc_howto_type *) NULL;
     268    default:
     269      return (reloc_howto_type *) NULL;
    258270    }
    259271#undef ENTRY
     
    273285  struct aoutdata  *su = &(abfd->tdata.aout_data->a);
    274286
    275   cache_ptr->address = bfd_h_get_32 (abfd, bytes->r_address);
    276 
    277   /* now the fun stuff */
    278 
     287  cache_ptr->address = H_GET_32 (abfd, bytes->r_address);
     288
     289  /* Now the fun stuff.  */
    279290  cache_ptr->howto = MY_reloc_howto(abfd, bytes, r_index, r_extern, r_pcrel);
    280291
    281   MOVE_ADDRESS(0);
     292  MOVE_ADDRESS (0);
    282293}
    283294
     
    296307  r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
    297308
    298   /* name was clobbered by aout_write_syms to be symbol index */
     309  /* Name was clobbered by aout_write_syms to be symbol index. */
    299310
    300311  /* If this relocation is relative to a symbol then set the
     
    304315     from the abs section, or as a symbol which has an abs value.
    305316     Check for that here.  */
    306 
    307317  if (bfd_is_com_section (output_section)
    308318      || output_section == &bfd_abs_section
     
    312322        {
    313323          /* Whoops, looked like an abs symbol, but is really an offset
    314              from the abs section */
     324             from the abs section. */
    315325          r_index = 0;
    316326          r_extern = 0;
     
    318328      else
    319329        {
    320           /* Fill in symbol */
     330          /* Fill in symbol. */
    321331          r_extern = 1;
    322332#undef KEEPIT
     
    328338  else
    329339    {
    330       /* Just an ordinary section */
     340      /* Just an ordinary section. */
    331341      r_extern = 0;
    332342      r_index  = output_section->target_index;
     
    344354{
    345355  int r_ns32k_type = (howto - MY(howto_table)) / 6;
    346   long (*get_data) PARAMS ((bfd_byte *, long, long));
    347   int (*put_data) PARAMS ((long, bfd_byte *, long, long));
     356  bfd_vma (*get_data) PARAMS ((bfd_byte *, int));
     357  void (*put_data) PARAMS ((bfd_vma, bfd_byte *, int));
    348358
    349359  switch (r_ns32k_type)
Note: See TracChangeset for help on using the changeset viewer.