* readelf.c (display_debug_frames): Fix warnings: Remove unused
[deliverable/binutils-gdb.git] / bfd / coff-z8k.c
index 21f29a82969050495e69482bf6737ae3a236f428..2e5da488806d574cdbe4aacdcb59195ae8e587ba 100644 (file)
@@ -1,5 +1,6 @@
 /* BFD back-end for Zilog Z800n COFF binaries.
-   Copyright 1992, 93, 94, 95, 1997 Free Software Foundation, Inc.
+   Copyright 1992, 1993, 1994, 1995, 1997, 1999, 2000
+   Free Software Foundation, Inc.
    Contributed by Cygnus Support.
    Written by Steve Chamberlain, <sac@cygnus.com>.
 
@@ -48,13 +49,26 @@ HOWTO (R_IMM8, 0, 1, 8, false, 0,
        complain_overflow_bitfield, 0, "r_imm8", true, 0x000000ff, 0x000000ff,
        false);
 
+static reloc_howto_type r_rel16 =
+HOWTO (R_REL16, 0, 1, 16, false, 0,
+       complain_overflow_bitfield, 0, "r_rel16", true, 0x0000ffff, 0x0000ffff,
+       true);
+
 static reloc_howto_type r_jr =
 HOWTO (R_JR, 0, 1, 8, true, 0, complain_overflow_signed, 0,
        "r_jr", true, 0, 0, true);
 
+static reloc_howto_type r_disp7 =
+HOWTO (R_DISP7, 0, 1, 7, true, 0, complain_overflow_bitfield, 0,
+       "r_disp7", true, 0, 0, true);
+
+static reloc_howto_type r_callr =
+HOWTO (R_CALLR, 0, 1, 12, true, 0, complain_overflow_signed, 0,
+       "r_callr", true, 0xfff, 0xfff, true);
+
 /* Turn a howto into a reloc number */
 
-static int 
+static int
 coff_z8k_select_reloc (howto)
      reloc_howto_type *howto;
 {
@@ -63,13 +77,10 @@ coff_z8k_select_reloc (howto)
 
 #define SELECT_RELOC(x,howto) x.r_type = coff_z8k_select_reloc(howto)
 
-
 #define BADMAG(x) Z8KBADMAG(x)
 #define Z8K 1                  /* Customize coffcode.h */
 #define __A_MAGIC_SET__
 
-
-
 /* Code to swap in the reloc */
 #define SWAP_IN_RELOC_OFFSET   bfd_h_get_32
 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
@@ -99,6 +110,15 @@ rtype2howto (internal, dst)
     case R_JR:
       internal->howto = &r_jr;
       break;
+    case R_DISP7:
+      internal->howto = &r_disp7;
+      break;
+    case R_CALLR:
+      internal->howto = &r_callr;
+      break;
+    case R_REL16:
+      internal->howto = &r_rel16;
+      break;
     case R_IMM32:
       internal->howto = &r_imm32;
       break;
@@ -110,18 +130,15 @@ rtype2howto (internal, dst)
 
 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
 
-
 /* Perform any necessary magic to the addend in a reloc entry */
 
-
 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
  cache_ptr->addend =  ext_reloc.r_offset;
 
-
 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
  reloc_processing(relent, reloc, symbols, abfd, section)
 
-static void 
+static void
 reloc_processing (relent, reloc, symbols, abfd, section)
      arelent * relent;
      struct internal_reloc *reloc;
@@ -141,7 +158,6 @@ reloc_processing (relent, reloc, symbols, abfd, section)
       relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
     }
 
-
   relent->addend = reloc->r_offset;
   relent->address -= section->vma;
 }
@@ -178,7 +194,7 @@ extra_case (in_abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)
 
     case R_IMM4L:
       bfd_put_8 (in_abfd,
-                ((bfd_get_8 (in_abfd, data + *dst_ptr) & 0xf0) 
+                ((bfd_get_8 (in_abfd, data + *dst_ptr) & 0xf0)
                  | (0x0f
                     & bfd_coff_reloc16_get_value (reloc, link_info,
                                                   input_section))),
@@ -221,6 +237,87 @@ extra_case (in_abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)
        (*src_ptr)++;
        break;
       }
+
+    case R_DISP7:
+      {
+       bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
+                                                 input_section);
+       bfd_vma dot = (link_order->offset
+                      + *dst_ptr
+                      + input_section->output_section->vma);
+       int gap = dst - dot - 1;/* -1 since were in the odd byte of the
+                                   word and the pc's been incremented */
+
+       if (gap & 1)
+         abort ();
+       gap /= 2;
+
+       if (gap > 0 || gap < -128)
+         {
+           if (! ((*link_info->callbacks->reloc_overflow)
+                  (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
+                   reloc->howto->name, reloc->addend, input_section->owner,
+                   input_section, reloc->address)))
+             abort ();
+         }
+       bfd_put_8 (in_abfd,
+                   (bfd_get_8 ( in_abfd, data + *dst_ptr) & 0x80) + (-gap & 0x7f),
+                   data + *dst_ptr);
+       (*dst_ptr)++;
+       (*src_ptr)++;
+       break;
+      }
+
+    case R_CALLR:
+      {
+       bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
+                                                 input_section);
+       bfd_vma dot = (link_order->offset
+                      + *dst_ptr
+                      + input_section->output_section->vma);
+       int gap = dst - dot - 2;
+
+       if (gap & 1)
+         abort ();
+       gap /= 2;
+       if (gap > 8191 || gap < -8192)
+         {
+           if (! ((*link_info->callbacks->reloc_overflow)
+                  (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
+                   reloc->howto->name, reloc->addend, input_section->owner,
+                   input_section, reloc->address)))
+             abort ();
+         }
+       bfd_put_16 (in_abfd,
+                    (bfd_get_16 ( in_abfd, data + *dst_ptr) & 0xf000) | (-gap & 0x0fff),
+                    data + *dst_ptr);
+       (*dst_ptr) += 2;
+       (*src_ptr) += 2;
+       break;
+      }
+
+    case R_REL16:
+      {
+       bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
+                                                 input_section);
+       bfd_vma dot = (link_order->offset
+                      + *dst_ptr
+                      + input_section->output_section->vma);
+       int gap = dst - dot - 2;
+
+       if (gap > 32767 || gap < -32768)
+         {
+           if (! ((*link_info->callbacks->reloc_overflow)
+                  (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
+                   reloc->howto->name, reloc->addend, input_section->owner,
+                   input_section, reloc->address)))
+             abort ();
+         }
+       bfd_put_16 (in_abfd,gap,data + *dst_ptr);
+       (*dst_ptr) += 2;
+       (*src_ptr) += 2;
+       break;
+      }
     default:
       abort ();
     }
@@ -230,7 +327,6 @@ extra_case (in_abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)
 
 #include "coffcode.h"
 
-
 #undef  coff_bfd_get_relocated_section_contents
 #undef coff_bfd_relax_section
 #define coff_bfd_get_relocated_section_contents \
This page took 0.026172 seconds and 4 git commands to generate.