(int64e_type): Fix definition.
[deliverable/binutils-gdb.git] / bfd / seclet.c
index 4088f0eb9ba482f411535789c99cea9bc6e6baa6..5dcc59ab0ef88f67678be1369dbd188f21b022ba 100644 (file)
@@ -1,3 +1,23 @@
+/* seclet.c
+   Copyright (C) 1992, 1993 Free Software Foundation, Inc.
+   Written by Cygnus Support.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
 /* This module is part of BFD */
 
 
@@ -26,6 +46,9 @@
 #include "libbfd.h"
 #include "seclet.h"
 #include "coff/internal.h"
+
+/* Create a new seclet and attach it to a section.  */
+
 bfd_seclet_type *
 DEFUN(bfd_new_seclet,(abfd, section),
       bfd *abfd AND
@@ -42,329 +65,121 @@ DEFUN(bfd_new_seclet,(abfd, section),
   section->seclets_tail = n;
 
   return n;
-  
 }
 
+/* Given an indirect seclet which points to an input section, relocate
+   the contents of the seclet and put the data in its final
+   destination.  */
 
-
-
-#define MAX_ERRORS_IN_A_ROW 10
-extern bfd_error_vector_type bfd_error_vector;
-bfd_vma 
-DEFUN(get_value,(reloc, seclet),
-      arelent  *reloc AND
-      bfd_seclet_type *seclet)
+static boolean
+DEFUN(rel,(abfd, seclet, output_section, data, relocateable),
+      bfd *abfd AND
+      bfd_seclet_type *seclet AND
+      asection *output_section AND
+      PTR data AND
+      boolean relocateable)
 {
-  bfd_vma value;
-  if (reloc->sym_ptr_ptr) 
+  if ((output_section->flags & SEC_HAS_CONTENTS) != 0
+      && seclet->size)
   {
-    asymbol *symbol = *(reloc->sym_ptr_ptr);
-
-  
-    /* A symbol holds a pointer to a section, and an offset from the
-       base of the section.  To relocate, we find where the section will
-       live in the output and add that in */
-
-    if (symbol->section == (asection *)NULL) 
+    data = (PTR) bfd_get_relocated_section_contents(abfd, seclet, data,
+                                                   relocateable);
+    if(bfd_set_section_contents(abfd,
+                               output_section,
+                               data,
+                               seclet->offset,
+                               seclet->size) == false)
     {
-      /* Ouch, this is an undefined symbol.. */
-      bfd_error_vector.undefined_symbol(reloc, seclet);
-      value = symbol->value;
+      abort();
     }
-    else 
-    {
-      value = symbol->value +
-       symbol->section->output_offset +
-       symbol->section->output_section->vma;
-    }  
   }
-  
-  else 
-  {
-    value = 0;  
-  }
-  
-  /* Add the value contained in the relocation */
-  value += (short)((reloc->addend) & 0xffff);
-  
-  return value;
-  
-
+  return true;
 }
 
-static char *
-DEFUN(foo_bfd_get_relocated_section_contents,(seclet),
-      bfd_seclet_type *seclet)
+/* Put the contents of a seclet in its final destination.  */
 
+static boolean
+DEFUN(seclet_dump_seclet,(abfd, seclet, section, data, relocateable),
+      bfd *abfd AND
+      bfd_seclet_type *seclet AND
+      asection *section AND
+      PTR data AND
+      boolean relocateable)
 {
-  asymbol **symbols = 0;
-  extern bfd *output_bfd;
-  bfd *abfd;    
-
-  /* Get enough memory to hold the stuff */
-  bfd *input_bfd = seclet->u.indirect.section->owner;
-  asection *input_section = seclet->u.indirect.section;
-
-  char *data = malloc(input_section->_raw_size);
-  char *dst = data;
-  char *prev_dst = data;
-  unsigned int gap = 0;
-
-  bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd,
-                                                      input_section);
-  arelent **reloc_vector = (arelent **)ldmalloc(reloc_size);
-  abfd = output_bfd;
-  
-  /* read in the section */
-  bfd_get_section_contents(input_bfd,
-                          input_section,
-                          data,
-                          0,
-                          input_section->_raw_size);
-  
-  
-  if (bfd_canonicalize_reloc(input_bfd, 
-                            input_section,
-                            reloc_vector,
-                            seclet->u.indirect.symbols) )
-  {
-    arelent **parent = reloc_vector;
-    arelent *reloc ;
-    
-
-
-    unsigned int dst_address = 0;
-    unsigned int src_address = 0;
-    unsigned int run;
-    unsigned int idx;
-    
-    /* Find how long a run we can do */
-    while (dst_address < seclet->size) 
+  switch (seclet->type) 
     {
-      
-      reloc = *parent;
-      if (reloc) 
-      {
-       /* Note that the relaxing didn't tie up the addresses in the
-          relocation, so we use the original address to work out the
-          run of non-relocated data */
-       run = reloc->address - src_address;
-       parent++;
-       
-      }
-      else 
-      {
-       run = seclet->size - dst_address;
-      }
-      /* Copy the bytes */
-      for (idx = 0; idx < run; idx++)
-      {
-       data[dst_address++] = data[src_address++];
-      }
-    
-      /* Now do the relocation */
-    
-      if (reloc) 
-      {
-       switch (reloc->howto->type) 
-       {
-       case R_JMP2:
-         /* Speciial relaxed type */
-       {
-         bfd_vma dot = seclet->offset + dst_address + seclet->u.indirect.section->output_section->vma;   
-         int   gap = get_value(reloc,seclet)-dot-1;
-         if ((gap & ~0xff  ) != 0 &&((gap & 0xff00)!= 0xff00)) abort();
-
-         bfd_put_8(abfd,gap,   data+dst_address);
-
-         switch (data[dst_address-1]) 
-         {
-           
-         case 0x5e:
-           /* jsr -> bsr */
-           bfd_put_8(abfd, 0x55, data+dst_address-1);
-           break;
-         case 0x5a:     
-           /* jmp ->bra */
-           bfd_put_8(abfd, 0x40, data+dst_address-1);
-           break;
-         
-         default:
-           abort();
-         
-         }
-       
-       
+    case bfd_indirect_seclet:
+      /* The contents of this section come from another one somewhere
+        else */
+      return rel(abfd, seclet, section, data, relocateable);
 
-            
-         dst_address++;
-         src_address+=3;
-  
-         break;
+    case bfd_fill_seclet:
+      /* Fill in the section with us */
+      {
+       char *d = bfd_xmalloc(seclet->size);
+       unsigned int i;
+       for (i =0;  i < seclet->size; i+=2) {
+         d[i] = seclet->u.fill.value >> 8;
        }
-
-            
-       case R_MOVB2:
-         /* Special relaxed type, there will be a gap between where we
-            get stuff from and where we put stuff to now 
-            
-            for a mov.b @aa:16 -> mov.b @aa:8
-            opcode 0x6a 0x0y offset
-            ->     0x2y off
-            */
-         if (data[dst_address-1] != 0x6a)
-          abort();
-         switch (data[dst_address] & 0xf0) 
-         {
-         case 0x00:
-           /* Src is memory */
-           data[dst_address-1] = (data[src_address] & 0xf) | 0x20;
-           break;
-         case 0x80:
-           /* Src is reg */
-           data[dst_address-1] = (data[src_address] & 0xf) | 0x30;
-           break;
-         default:
-           abort();
-         }
-       
-         /* the offset must fit ! after all, what was all the relaxing
-            about ? */
-
-         bfd_put_8(abfd, get_value(reloc, seclet), data + dst_address);
-
-         /* Note the magic - src goes up by two bytes, but dst by only
-            one */
-         dst_address+=1;
-         src_address+=3;
-       
-         break;
-         /* PCrel 8 bits */
-       case R_PCRBYTE:   
-       {
-         bfd_vma dot = seclet->offset + dst_address + seclet->u.indirect.section->output_section->vma;   
-         int   gap = get_value(reloc,seclet)-dot;
-         if (gap > 127 || gap < -128) 
-         {
-           bfd_error_vector.reloc_value_truncated(reloc, seclet);
-         }
-         
-         bfd_put_8(abfd,gap,   data+dst_address);
-         dst_address++;
-         src_address++;
-  
-         break;
+       for (i = 1; i < seclet->size; i+=2) {
+         d[i] = seclet->u.fill.value ;
        }
-
-       case R_RELBYTE:
-       {
-         unsigned  int gap =get_value(reloc,seclet);
-         if (gap > 256)
+       /* Don't bother to fill in empty sections */
+       if (!(bfd_get_section_flags(abfd, section) & SEC_HAS_CONTENTS))
          {
-           bfd_error_vector.reloc_value_truncated(reloc, seclet);
+           return true;
          }
-         
-         bfd_put_8(abfd, gap, data+dst_address);
-         dst_address+=1;
-         src_address+=1;
-
+       return bfd_set_section_contents(abfd, section, d, seclet->offset,
+                                       seclet->size);
+      }
 
-       }
-         break; 
-       case R_JMP1:
-         /* A relword which would have like to have been a pcrel */
-       case R_MOVB1:   
-         /* A relword which would like to have been modified but
-            didn't make it */
-       case R_RELWORD:
-         bfd_put_16(abfd, get_value(reloc,seclet), data+dst_address);
-         dst_address+=2;
-         src_address+=2;
-         break;
-       
-       default:
-         abort();
-       }
-      }    
+    default:
+      abort();
     }
-  }
-  free((char *)reloc_vector);
-  return data;
-  
-}
-
-void
-DEFUN(rel,(abfd, seclet, output_section),
-      bfd *abfd AND
-      bfd_seclet_type *seclet AND
-      asection *output_section)
-{
-  bfd_byte *data;
-  if (output_section->flags & SEC_HAS_CONTENTS )
-  {
-    
-  data = bfd_get_relocated_section_contents(abfd, seclet);
 
-  if(bfd_set_section_contents(abfd,
-                             output_section,
-                             data,
-                             seclet->offset,
-                             seclet->size) == false)
-  {
-    abort();
-  }
-  
+  return true;
 }
 
-    
+/*
+INTERNAL_FUNCTION
+       bfd_generic_seclet_link
 
-  
+SYNOPSIS
+       boolean bfd_generic_seclet_link
+        (bfd *abfd,
+         PTR data,
+         boolean relocateable);
 
-}
-
-void
-DEFUN(seclet_dump_seclet,(abfd, seclet, section),
-      bfd *abfd AND
-      bfd_seclet_type *seclet AND
-      asection *section)
-{
-  switch (seclet->type) 
-  {
-    
-  case bfd_indirect_seclet:
-    /* The contents of this section come from another one somewhere
-       else */
-    rel(abfd, seclet, section);
-    
-    
-    break;
-    
-  default:
-    abort();
-  }
-  
+DESCRIPTION
 
+       The generic seclet linking routine.  The caller should have
+       set up seclets for all the output sections.  The DATA argument
+       should point to a memory area large enough to hold the largest
+       section.  This function looks through the seclets and moves
+       the contents into the output sections.  If RELOCATEABLE is
+       true, the orelocation fields of the output sections must
+       already be initialized.
 
-}
+*/
 
-void
-DEFUN(seclet_dump,(abfd),
-      bfd *abfd)
+boolean
+DEFUN(bfd_generic_seclet_link,(abfd, data, relocateable),
+      bfd *abfd AND
+      PTR data AND
+      boolean relocateable)
 {
-  /* Write all the seclets on the bfd out, relocate etc according to the
-     rules */
-
   asection *o = abfd->sections;
   while (o != (asection *)NULL) 
   {
     bfd_seclet_type *p = o->seclets_head;
     while (p != (bfd_seclet_type *)NULL) 
     {
-      seclet_dump_seclet(abfd, p, o);
+      if (seclet_dump_seclet(abfd, p, o, data, relocateable) == false)
+       return false;
       p = p ->next;
     }
     o = o->next;
   }
 
+  return true;
 }
This page took 0.031783 seconds and 4 git commands to generate.