This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH BFD octets per byte support


 This patch adds support to BFD for targets on which a byte is not an
8-bit quantity.

* archures.c: add new functions to determine a target's byte size.
* bfd-in2.h: regenerated
* coffgen.c: indicate that the offset parameter is in bytes, not octets
* cofflink.c: use bfd_octets_per_byte where appropriate to get the octet
offset when calling bfd_set_section_contents.
* linker.c: ditto
* reloc.c (bfd_perform_relocation, bfd_install_relocation) distinguish
between octets and bytes.  Use octets when indexing into octet data; use
bytes when calculating target addresses.
* section.c: Distinguish between octets and bytes for usage of
_cooked_size,  _raw_size, and output_offset.  Clarify description of
bfd_set_section_contents.
* srec.c (srec_write_section): distinguish between octets and bytes.
Target addresses are in bytes, offsets into octet data are in octets.


Index: archures.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/archures.c,v
retrieving revision 1.6
diff -c -3 -p -r1.6 archures.c
*** archures.c	1999/12/01 10:14:02	1.6
--- archures.c	2000/01/13 19:25:49
*************** bfd_printable_arch_mach (arch, machine)
*** 903,905 ****
--- 903,954 ----
        return ap->printable_name;
      return "UNKNOWN!";
  }
+ 
+ /*
+ FUNCTION
+ 	bfd_octets_per_byte
+ 
+ SYNOPSIS
+ 	int bfd_octets_per_byte(bfd *abfd);
+ 
+ DESCRIPTION
+ 	Return the number of octets (8-bit quantities) per target byte
+         (minimum addressable unit).  In most cases, this will be one, but some
+         DSP targets have 16, 32, or even 48 bits per byte.
+ 
+ */
+ 
+ int
+ bfd_octets_per_byte (abfd)
+      bfd *abfd;
+ {
+     return bfd_arch_mach_octets_per_byte (bfd_get_arch (abfd), 
+                                           bfd_get_mach (abfd));
+ }
+ 
+ /*
+ FUNCTION
+ 	bfd_arch_mach_octets_per_byte
+ 
+ SYNOPSIS
+ 	int bfd_arch_mach_octets_per_byte(enum bfd_architecture arch,
+                                           unsigned long machine);
+ 
+ DESCRIPTION
+ 	See bfd_octets_per_byte.
+         
+         This routine is provided for those cases where a bfd * is not
+         available
+ */
+ 
+ int
+ bfd_arch_mach_octets_per_byte (arch, mach)
+     enum bfd_architecture arch;
+     unsigned long mach;
+ {
+     const bfd_arch_info_type *ap = bfd_lookup_arch (arch, mach);
+     if (ap)
+       return ap->bits_per_byte / 8;
+     return 1;
+ }
+ 
Index: bfd-in2.h
===================================================================
RCS file: /cvs/binutils/binutils/bfd/bfd-in2.h,v
retrieving revision 1.27
diff -c -3 -p -r1.27 bfd-in2.h
*** bfd-in2.h	1999/12/10 18:51:34	1.27
--- bfd-in2.h	2000/01/13 19:25:52
*************** typedef struct sec
*** 1066,1087 ****
  
     bfd_vma lma;
  
!          /* The size of the section in bytes, as it will be output.
             contains a value even if the section has no contents (e.g., the
             size of <<.bss>>). This will be filled in after relocation */
  
     bfd_size_type _cooked_size;
  
!          /* The original size on disk of the section, in bytes.  Normally this
             value is the same as the size, but if some relaxing has
             been done, then this value will be bigger.  */
  
     bfd_size_type _raw_size;
  
           /* If this section is going to be output, then this value is the
!            offset into the output section of the first byte in the input
!            section. E.g., if this was going to start at the 100th byte in
!            the output section, this value would be 100. */
  
     bfd_vma output_offset;
  
--- 1066,1090 ----
  
     bfd_vma lma;
  
!          /* The size of the section in octets, as it will be output.
             contains a value even if the section has no contents (e.g., the
             size of <<.bss>>). This will be filled in after relocation */
  
     bfd_size_type _cooked_size;
  
!          /* The original size on disk of the section, in octets.  Normally this
             value is the same as the size, but if some relaxing has
             been done, then this value will be bigger.  */
  
     bfd_size_type _raw_size;
  
           /* If this section is going to be output, then this value is the
!             offset in *bytes* into the output section of the first byte in the
!             input section (byte ==> smallest addressable unit on the
!             target).  In most cases, if this was going to start at the
!             100th octet (8-bit quantity) in the output section, this value
!             would be 100.  However, if the target byte size were 16 bits
!             (bfd_octets_per_byte were "2"), this value would be 50. */ 
  
     bfd_vma output_offset;
  
*************** bfd_lookup_arch
*** 1445,1450 ****
--- 1448,1460 ----
  const char *
  bfd_printable_arch_mach
   PARAMS ((enum bfd_architecture arch, unsigned long machine));
+ 
+ int 
+ bfd_octets_per_byte PARAMS ((bfd *abfd));
+ 
+ int 
+ bfd_arch_mach_octets_per_byte PARAMS ((enum bfd_architecture arch,
+                                        unsigned long machine));
  
  typedef enum bfd_reloc_status
  {
Index: coffgen.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/coffgen.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 coffgen.c
*** coffgen.c	1999/09/11 15:16:14	1.9
--- coffgen.c	2000/01/13 19:25:53
*************** _bfd_coff_is_local_label_name (abfd, nam
*** 2136,2145 ****
    return name[0] == '.' && name[1] == 'L';
  }
  
! /* Provided a BFD, a section and an offset into the section, calculate
!    and return the name of the source file and the line nearest to the
!    wanted location.  */
! 
  /*ARGSUSED*/
  boolean
  coff_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
--- 2136,2144 ----
    return name[0] == '.' && name[1] == 'L';
  }
  
! /* Provided a BFD, a section and an offset (in bytes, not octets) into the
!    section, calculate and return the name of the source file and the line
!    nearest to the wanted location.  */
  /*ARGSUSED*/
  boolean
  coff_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
Index: cofflink.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/cofflink.c,v
retrieving revision 1.13
diff -c -3 -p -r1.13 cofflink.c
*** cofflink.c	1999/09/12 16:28:20	1.13
--- cofflink.c	2000/01/13 19:25:55
*************** _bfd_coff_link_input_bfd (finfo, input_b
*** 2425,2431 ****
        if (secdata == NULL || secdata->stab_info == NULL)
  	{
  	  if (! bfd_set_section_contents (output_bfd, o->output_section,
! 					  contents, o->output_offset,
  					  (o->_cooked_size != 0
  					   ? o->_cooked_size
  					   : o->_raw_size)))
--- 2425,2434 ----
        if (secdata == NULL || secdata->stab_info == NULL)
  	{
  	  if (! bfd_set_section_contents (output_bfd, o->output_section,
! 					  contents, 
!                                           (file_ptr) 
!                                           (o->output_offset * 
!                                            bfd_octets_per_byte (output_bfd)),
  					  (o->_cooked_size != 0
  					   ? o->_cooked_size
  					   : o->_raw_size)))
*************** _bfd_coff_reloc_link_order (output_bfd, 
*** 2737,2743 ****
  	  break;
  	}
        ok = bfd_set_section_contents (output_bfd, output_section, (PTR) buf,
! 				     (file_ptr) link_order->offset, size);
        free (buf);
        if (! ok)
  	return false;
--- 2740,2748 ----
  	  break;
  	}
        ok = bfd_set_section_contents (output_bfd, output_section, (PTR) buf,
! 				     (file_ptr) 
!                                      (link_order->offset *
!                                       bfd_octets_per_byte (output_bfd)), size);
        free (buf);
        if (! ok)
  	return false;
Index: linker.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/linker.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 linker.c
*** linker.c	1999/07/11 19:49:41	1.3
--- linker.c	2000/01/13 19:25:57
*************** _bfd_generic_reloc_link_order (abfd, inf
*** 2524,2530 ****
  	  break;
  	}
        ok = bfd_set_section_contents (abfd, sec, (PTR) buf,
! 				     (file_ptr) link_order->offset, size);
        free (buf);
        if (! ok)
  	return false;
--- 2524,2532 ----
  	  break;
  	}
        ok = bfd_set_section_contents (abfd, sec, (PTR) buf,
! 				     (file_ptr) 
!                                      (link_order->offset *
!                                       bfd_octets_per_byte (abfd)), size);
        free (buf);
        if (! ok)
  	return false;
*************** _bfd_default_link_order (abfd, info, sec
*** 2592,2598 ****
      case bfd_data_link_order:
        return bfd_set_section_contents (abfd, sec,
  				       (PTR) link_order->u.data.contents,
! 				       (file_ptr) link_order->offset,
  				       link_order->size);
      }
  }
--- 2594,2602 ----
      case bfd_data_link_order:
        return bfd_set_section_contents (abfd, sec,
  				       (PTR) link_order->u.data.contents,
! 				       (file_ptr) 
!                                        (link_order->offset *
!                                         bfd_octets_per_byte (abfd)),
  				       link_order->size);
      }
  }
*************** default_fill_link_order (abfd, info, sec
*** 2626,2632 ****
    for (i = 1; i < size; i += 2)
      space[i] = fill;
    result = bfd_set_section_contents (abfd, sec, space,
! 				     (file_ptr) link_order->offset,
  				     link_order->size);
    free (space);
    return result;
--- 2630,2638 ----
    for (i = 1; i < size; i += 2)
      space[i] = fill;
    result = bfd_set_section_contents (abfd, sec, space,
! 				     (file_ptr) 
!                                      (link_order->offset * 
!                                       bfd_octets_per_byte (abfd)),
  				     link_order->size);
    free (space);
    return result;
*************** default_indirect_link_order (output_bfd,
*** 2743,2749 ****
    /* Output the section contents.  */
    if (! bfd_set_section_contents (output_bfd, output_section,
  				  (PTR) new_contents,
! 				  link_order->offset, link_order->size))
      goto error_return;
  
    if (contents != NULL)
--- 2749,2758 ----
    /* Output the section contents.  */
    if (! bfd_set_section_contents (output_bfd, output_section,
  				  (PTR) new_contents,
! 				  (file_ptr)
!                                   (link_order->offset * 
!                                    bfd_octets_per_byte (output_bfd)), 
!                                   link_order->size))
      goto error_return;
  
    if (contents != NULL)
Index: reloc.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/reloc.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 reloc.c
*** reloc.c	1999/11/28 03:26:42	1.9
--- reloc.c	2000/01/13 19:25:58
*************** bfd_perform_relocation (abfd, reloc_entr
*** 592,598 ****
  {
    bfd_vma relocation;
    bfd_reloc_status_type flag = bfd_reloc_ok;
!   bfd_size_type addr = reloc_entry->address;
    bfd_vma output_base = 0;
    reloc_howto_type *howto = reloc_entry->howto;
    asection *reloc_target_output_section;
--- 592,598 ----
  {
    bfd_vma relocation;
    bfd_reloc_status_type flag = bfd_reloc_ok;
!   bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
    bfd_vma output_base = 0;
    reloc_howto_type *howto = reloc_entry->howto;
    asection *reloc_target_output_section;
*************** bfd_perform_relocation (abfd, reloc_entr
*** 628,634 ****
      }
  
    /* Is the address of the relocation really within the section?  */
!   if (reloc_entry->address > input_section->_cooked_size)
      return bfd_reloc_outofrange;
  
    /* Work out which section the relocation is targetted at and the
--- 628,635 ----
      }
  
    /* Is the address of the relocation really within the section?  */
!   if (reloc_entry->address > input_section->_cooked_size /
!       bfd_octets_per_byte (abfd))
      return bfd_reloc_outofrange;
  
    /* Work out which section the relocation is targetted at and the
*************** space consuming.  For each target:
*** 897,937 ****
      {
      case 0:
        {
! 	char x = bfd_get_8 (abfd, (char *) data + addr);
  	DOIT (x);
! 	bfd_put_8 (abfd, x, (unsigned char *) data + addr);
        }
        break;
  
      case 1:
        {
! 	short x = bfd_get_16 (abfd, (bfd_byte *) data + addr);
  	DOIT (x);
! 	bfd_put_16 (abfd, x, (unsigned char *) data + addr);
        }
        break;
      case 2:
        {
! 	long x = bfd_get_32 (abfd, (bfd_byte *) data + addr);
  	DOIT (x);
! 	bfd_put_32 (abfd, x, (bfd_byte *) data + addr);
        }
        break;
      case -2:
        {
! 	long x = bfd_get_32 (abfd, (bfd_byte *) data + addr);
  	relocation = -relocation;
  	DOIT (x);
! 	bfd_put_32 (abfd, x, (bfd_byte *) data + addr);
        }
        break;
  
      case -1:
        {
! 	long x = bfd_get_16 (abfd, (bfd_byte *) data + addr);
  	relocation = -relocation;
  	DOIT (x);
! 	bfd_put_16 (abfd, x, (bfd_byte *) data + addr);
        }
        break;
  
--- 898,938 ----
      {
      case 0:
        {
! 	char x = bfd_get_8 (abfd, (char *) data + octets);
  	DOIT (x);
! 	bfd_put_8 (abfd, x, (unsigned char *) data + octets);
        }
        break;
  
      case 1:
        {
! 	short x = bfd_get_16 (abfd, (bfd_byte *) data + octets);
  	DOIT (x);
! 	bfd_put_16 (abfd, x, (unsigned char *) data + octets);
        }
        break;
      case 2:
        {
! 	long x = bfd_get_32 (abfd, (bfd_byte *) data + octets);
  	DOIT (x);
! 	bfd_put_32 (abfd, x, (bfd_byte *) data + octets);
        }
        break;
      case -2:
        {
! 	long x = bfd_get_32 (abfd, (bfd_byte *) data + octets);
  	relocation = -relocation;
  	DOIT (x);
! 	bfd_put_32 (abfd, x, (bfd_byte *) data + octets);
        }
        break;
  
      case -1:
        {
! 	long x = bfd_get_16 (abfd, (bfd_byte *) data + octets);
  	relocation = -relocation;
  	DOIT (x);
! 	bfd_put_16 (abfd, x, (bfd_byte *) data + octets);
        }
        break;
  
*************** space consuming.  For each target:
*** 942,950 ****
      case 4:
  #ifdef BFD64
        {
! 	bfd_vma x = bfd_get_64 (abfd, (bfd_byte *) data + addr);
  	DOIT (x);
! 	bfd_put_64 (abfd, x, (bfd_byte *) data + addr);
        }
  #else
        abort ();
--- 943,951 ----
      case 4:
  #ifdef BFD64
        {
! 	bfd_vma x = bfd_get_64 (abfd, (bfd_byte *) data + octets);
  	DOIT (x);
! 	bfd_put_64 (abfd, x, (bfd_byte *) data + octets);
        }
  #else
        abort ();
*************** bfd_install_relocation (abfd, reloc_entr
*** 994,1000 ****
  {
    bfd_vma relocation;
    bfd_reloc_status_type flag = bfd_reloc_ok;
!   bfd_size_type addr = reloc_entry->address;
    bfd_vma output_base = 0;
    reloc_howto_type *howto = reloc_entry->howto;
    asection *reloc_target_output_section;
--- 995,1001 ----
  {
    bfd_vma relocation;
    bfd_reloc_status_type flag = bfd_reloc_ok;
!   bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
    bfd_vma output_base = 0;
    reloc_howto_type *howto = reloc_entry->howto;
    asection *reloc_target_output_section;
*************** space consuming.  For each target:
*** 1283,1289 ****
  #define DOIT(x) \
    x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) +  relocation) & howto->dst_mask))
  
!   data = (bfd_byte *) data_start + (addr - data_start_offset);
  
    switch (howto->size)
      {
--- 1284,1290 ----
  #define DOIT(x) \
    x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) +  relocation) & howto->dst_mask))
  
!   data = (bfd_byte *) data_start + (octets - data_start_offset); 
  
    switch (howto->size)
      {
Index: section.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/section.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 section.c
*** section.c	1999/09/06 18:34:29	1.9
--- section.c	2000/01/13 19:25:59
*************** CODE_FRAGMENT
*** 369,390 ****
  .
  .   bfd_vma lma;
  .
! .        {* The size of the section in bytes, as it will be output.
  .           contains a value even if the section has no contents (e.g., the
  .           size of <<.bss>>). This will be filled in after relocation *}
  .
  .   bfd_size_type _cooked_size;
  .
! .        {* The original size on disk of the section, in bytes.  Normally this
  .	    value is the same as the size, but if some relaxing has
  .	    been done, then this value will be bigger.  *}
  .
  .   bfd_size_type _raw_size;
  .
  .        {* If this section is going to be output, then this value is the
! .           offset into the output section of the first byte in the input
! .           section. E.g., if this was going to start at the 100th byte in
! .           the output section, this value would be 100. *}
  .
  .   bfd_vma output_offset;
  .
--- 369,393 ----
  .
  .   bfd_vma lma;
  .
! .        {* The size of the section in octets, as it will be output.
  .           contains a value even if the section has no contents (e.g., the
  .           size of <<.bss>>). This will be filled in after relocation *}
  .
  .   bfd_size_type _cooked_size;
  .
! .        {* The original size on disk of the section, in octets.  Normally this
  .	    value is the same as the size, but if some relaxing has
  .	    been done, then this value will be bigger.  *}
  .
  .   bfd_size_type _raw_size;
  .
  .        {* If this section is going to be output, then this value is the
! .           offset in *bytes* into the output section of the first byte in the
! .           input section (byte ==> smallest addressable unit on the
! .           target).  In most cases, if this was going to start at the
! .           100th octet (8-bit quantity) in the output section, this value
! .           would be 100.  However, if the target byte size were 16 bits
! .           (bfd_octets_per_byte were "2"), this value would be 50. *}
  .
  .   bfd_vma output_offset;
  .
*************** DESCRIPTION
*** 920,926 ****
  	Sets the contents of the section @var{section} in BFD
  	@var{abfd} to the data starting in memory at @var{data}. The
  	data is written to the output section starting at offset
! 	@var{offset} for @var{count} bytes.
  
  
  
--- 923,929 ----
  	Sets the contents of the section @var{section} in BFD
  	@var{abfd} to the data starting in memory at @var{data}. The
  	data is written to the output section starting at offset
! 	@var{offset} for @var{count} octets.
  
  
  
Index: srec.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/srec.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 srec.c
*** srec.c	1999/07/19 14:55:16	1.3
--- srec.c	2000/01/13 19:26:00
*************** srec_write_section (abfd, tdata, list)
*** 1000,1030 ****
       tdata_type *tdata;
       srec_data_list_type *list;
  {
!   unsigned int bytes_written = 0;
    bfd_byte *location = list->data;
  
!   while (bytes_written < list->size)
      {
        bfd_vma address;
  
!       unsigned int bytes_this_chunk = list->size - bytes_written;
  
!       if (bytes_this_chunk > CHUNK)
  	{
! 	  bytes_this_chunk = CHUNK;
  	}
  
!       address = list->where + bytes_written;
  
        if (! srec_write_record (abfd,
  			       tdata->type,
  			       address,
  			       location,
! 			       location + bytes_this_chunk))
  	return false;
  
!       bytes_written += bytes_this_chunk;
!       location += bytes_this_chunk;
      }
  
    return true;
--- 1000,1030 ----
       tdata_type *tdata;
       srec_data_list_type *list;
  {
!   unsigned int octets_written = 0;
    bfd_byte *location = list->data;
  
!   while (octets_written < list->size)
      {
        bfd_vma address;
  
!       unsigned int octets_this_chunk = list->size - octets_written;
  
!       if (octets_this_chunk > CHUNK)
  	{
! 	  octets_this_chunk = CHUNK;
  	}
  
!       address = list->where + octets_written / bfd_octets_per_byte (abfd);
  
        if (! srec_write_record (abfd,
  			       tdata->type,
  			       address,
  			       location,
! 			       location + octets_this_chunk))
  	return false;
  
!       octets_written += octets_this_chunk;
!       location += octets_this_chunk;
      }
  
    return true;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]