This is the mail archive of the binutils@sources.redhat.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]
Other format: [Raw text]

Re: Patch for avr port of binutils [adiw, sbiw, ldd with more functionality]


Hi Nick,


Nick Clifton wrote:


Hi Klaus,

* The file bfd-in2.h is an automatically generated file. If you need to patch it, you should also patch the source file(s) that are used to create it. In this particular case the new relocs that you created needed to be added to the bfd/reloc.c file.

OK, thanks for this info. I downloaded the version (041119) via a single file not from cvs. And bfd-in2.h was contained there :-(??
I have removed it from my sources and bring the change into bfd/relocs.c.
But after that I was not longer able to build? What I have to typ for a rebuild of the internal generated header files?



* You used C++ style comments in a few places in the code. Although GCC allows this, other compiler might not, and besides we are trying to get to the state where we can compile all of binutils with the -Wall -Werror flags set.

OK, changed.



* We are now using ISO-C90 style C formatting in binutils, and although there are quite a lot of files that have not yet been converted over, we still ike to encourage any new patches to make use of this standard. Thus for example the PARAMS() macro is now no longer needed when declaring function prototypes, and function declarations can include their arguments inside the parentheses.


Done, but only for my single new function. If you are interested in changing the complete avr-related files I can do this also but please
after this patch. So that I am able to keep track and not through all the things together :-)


* The patch needlessly inserted whitespace in various places and did not always follow the GNU Coding convention.

Ups, yes. I need a bit assistent from you. Is there a tool for checking/auto formatting available? Or have you a .vimrc file where I
can do this with traditional "gg=G" command? I´m a bit confused above the old style in the changed files. I found there tabs also as
normal spaces to shift the raws. Please give me a hint what to do, I will apply this soon as possible.


* It is helpful if you can generate patches using the -c switch to diff. The extra context makes the patch much easier to read.

Done.

* When adding a new feature it is always a good idea to include a new entry in the relevent testsuite to make sure that the feature works, and continues to work in the future.

There is actually no testsuite for avr. Sorry!

* You should always include a set of entries for the relevent ChangeLog files annotating which files you have changed and why. Note - for convenince we ask that these entries just be submitted as plain text, not a diff, as they usually have to be applied by hand.

I add an additional file as attatchment so you have the ability to use the given text. If you need it in an other way please let me know.

Because of the open items: could not build the bfd-in2.h file, and the formatting rules we need another version. So please give
me a detailed information on this to topics so that the next patch is maybe the last one :-)


Regards
  Klaus

diff -cr binutils-041119/bfd/elf32-avr.c binutils-041119_modified_for_patch004/bfd/elf32-avr.c
*** binutils-041119/bfd/elf32-avr.c	2004-10-21 17:28:20.000000000 +0200
--- binutils-041119_modified_for_patch004/bfd/elf32-avr.c	2004-12-20 17:16:15.413077464 +0100
***************
*** 329,335 ****
  	 FALSE,			/* partial_inplace */
  	 0xffffffff,		/* src_mask */
  	 0xffffffff,		/* dst_mask */
! 	 FALSE)			/* pcrel_offset */
  };
  
  /* Map BFD reloc types to AVR ELF reloc types.  */
--- 329,380 ----
  	 FALSE,			/* partial_inplace */
  	 0xffffffff,		/* src_mask */
  	 0xffffffff,		/* dst_mask */
! 	 FALSE),			/* pcrel_offset */
!   /* A 16 bit absolute relocation of 16 bit address.
!      For LDI command.  */
!   HOWTO (R_AVR_LDI,		/* type */
! 	 0,			/* rightshift */
! 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
! 	 16,			/* bitsize */
! 	 FALSE,			/* pc_relative */
! 	 0,			/* bitpos */
! 	 complain_overflow_dont, /* complain_on_overflow */
! 	 bfd_elf_generic_reloc,	/* special_function */
! 	 "R_AVR_LDI",	/* name */
! 	 FALSE,			/* partial_inplace */
! 	 0xffff,		/* src_mask */
! 	 0xffff,		/* dst_mask */
! 	 FALSE),		/* pcrel_offset */
!   /* A 6 bit absolute relocation of 6 bit offset.
!      For ldd/sdd command.  */
!   HOWTO (R_AVR_6,		/* type */
! 	 0,			/* rightshift */
! 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
! 	 6,			/* bitsize */
! 	 FALSE,			/* pc_relative */
! 	 0,			/* bitpos */
! 	 complain_overflow_dont, /* complain_on_overflow */
! 	 bfd_elf_generic_reloc,	/* special_function */
! 	 "R_AVR_6",	/* name */
! 	 FALSE,			/* partial_inplace */
! 	 0xffff,		/* src_mask */
! 	 0xffff,		/* dst_mask */
! 	 FALSE),		/* pcrel_offset */
!   /* A 6 bit absolute relocation of 6 bit offset.
!      For sbiw/adiw command.  */
!   HOWTO (R_AVR_6_ADIW,		/* type */
! 	 0,			/* rightshift */
! 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
! 	 6,			/* bitsize */
! 	 FALSE,			/* pc_relative */
! 	 0,			/* bitpos */
! 	 complain_overflow_dont, /* complain_on_overflow */
! 	 bfd_elf_generic_reloc,	/* special_function */
! 	 "R_AVR_6_ADIW",	/* name */
! 	 FALSE,			/* partial_inplace */
! 	 0xffff,		/* src_mask */
! 	 0xffff,		/* dst_mask */
! 	 FALSE)		/* pcrel_offset */
  };
  
  /* Map BFD reloc types to AVR ELF reloc types.  */
***************
*** 360,366 ****
    { BFD_RELOC_AVR_LO8_LDI_PM_NEG,   R_AVR_LO8_LDI_PM_NEG },
    { BFD_RELOC_AVR_HI8_LDI_PM_NEG,   R_AVR_HI8_LDI_PM_NEG },
    { BFD_RELOC_AVR_HH8_LDI_PM_NEG,   R_AVR_HH8_LDI_PM_NEG },
!   { BFD_RELOC_AVR_CALL,             R_AVR_CALL }
  };
  
  static reloc_howto_type *
--- 405,414 ----
    { BFD_RELOC_AVR_LO8_LDI_PM_NEG,   R_AVR_LO8_LDI_PM_NEG },
    { BFD_RELOC_AVR_HI8_LDI_PM_NEG,   R_AVR_HI8_LDI_PM_NEG },
    { BFD_RELOC_AVR_HH8_LDI_PM_NEG,   R_AVR_HH8_LDI_PM_NEG },
!   { BFD_RELOC_AVR_CALL,             R_AVR_CALL },
!   { BFD_RELOC_AVR_LDI,              R_AVR_LDI  },
!   { BFD_RELOC_AVR_6,                R_AVR_6    },
!   { BFD_RELOC_AVR_6_ADIW,           R_AVR_6_ADIW }
  };
  
  static reloc_howto_type *
***************
*** 561,566 ****
--- 609,647 ----
        bfd_put_16 (input_bfd, x, contents);
        break;
  
+     case R_AVR_LDI:
+       contents += rel->r_offset;
+       srel = (bfd_signed_vma) relocation + rel->r_addend;
+       if ((srel&0xffff)>255) { /*remove offset for data/eeprom section*/
+           return bfd_reloc_overflow;
+       }
+       x = bfd_get_16 (input_bfd, contents);
+       x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00);
+       bfd_put_16 (input_bfd, x, contents);
+       break;
+ 
+     case R_AVR_6:
+       contents += rel->r_offset;
+       srel = (bfd_signed_vma) relocation + rel->r_addend;
+       if (((srel&0xffff)>63 ) || (srel <0 )) { /*remove offset for data/eeprom section*/
+           return bfd_reloc_overflow;
+       }
+       x = bfd_get_16 (input_bfd, contents);
+       x = (x & 0xd3f8) | (( srel  & 7) | (( srel  & (3 << 3)) << 7) | (( srel  & (1 << 5)) << 8) );
+       bfd_put_16 (input_bfd, x, contents);
+       break;
+ 
+     case R_AVR_6_ADIW:
+       contents += rel->r_offset;
+       srel = (bfd_signed_vma) relocation + rel->r_addend;
+       if (((srel&0xffff)>63 ) || (srel <0 )) { /*remove offset for data/eeprom section*/
+           return bfd_reloc_overflow;
+       }
+       x = bfd_get_16 (input_bfd, contents);
+       x = (x & 0xff30) | (srel & 0xf) | ((srel & 0x30)<<2); 
+       bfd_put_16 (input_bfd, x, contents);
+       break;
+ 
      case R_AVR_HI8_LDI:
        contents += rel->r_offset;
        srel = (bfd_signed_vma) relocation + rel->r_addend;
diff -cr binutils-041119/bfd/reloc.c binutils-041119_modified_for_patch004/bfd/reloc.c
*** binutils-041119/bfd/reloc.c	2004-11-04 15:57:44.000000000 +0100
--- binutils-041119_modified_for_patch004/bfd/reloc.c	2004-12-20 18:04:31.487807184 +0100
***************
*** 3362,3367 ****
--- 3362,3382 ----
  ENUMDOC
    This is a 32 bit reloc for the AVR that stores 23 bit value
    into 22 bits.
+ ENUM
+   BFD_RELOC_AVR_LDI
+ ENUMDOC
+   This is a 16 bit reloc for the AVR that stores all needed bits
+   for absolute addressing with ldi with overflow check to linktime
+ ENUM
+   BFD_RELOC_AVR_6
+ ENUMDOC
+   This is a 6 bit reloc for the AVR that stores offset for ldd/std
+   instructions
+ ENUM
+   BFD_RELOC_AVR_6_ADIW
+ ENUMDOC
+   This is a 6 bit reloc for the AVR that stores offset for adiw/sbiw
+   instructions
  
  ENUM
    BFD_RELOC_390_12
diff -cr binutils-041119/gas/config/tc-avr.c binutils-041119_modified_for_patch004/gas/config/tc-avr.c
*** binutils-041119/gas/config/tc-avr.c	2004-09-11 15:15:04.000000000 +0200
--- binutils-041119_modified_for_patch004/gas/config/tc-avr.c	2004-12-20 18:07:47.768967912 +0100
***************
*** 150,155 ****
--- 150,156 ----
  static unsigned int avr_get_constant PARAMS ((char *, int));
  static char *parse_exp PARAMS ((char *, expressionS *));
  static bfd_reloc_code_real_type avr_ldi_expression PARAMS ((expressionS *));
+ static void avr_offset_expression ((expressionS *));
  
  #define EXP_MOD_NAME(i) exp_mod[i].name
  #define EXP_MOD_RELOC(i) exp_mod[i].reloc
***************
*** 689,700 ****
  	  as_bad (_("pointer register (Y or Z) required"));
  	str = skip_space (str);
  	if (*str++ == '+')
! 	  {
! 	    unsigned int x;
! 	    x = avr_get_constant (str, 63);
! 	    str = input_line_pointer;
! 	    op_mask |= (x & 7) | ((x & (3 << 3)) << 7) | ((x & (1 << 5)) << 8);
! 	  }
        }
        break;
  
--- 690,702 ----
  	  as_bad (_("pointer register (Y or Z) required"));
  	str = skip_space (str);
  	if (*str++ == '+')
! 	    {
! 	      input_line_pointer = str;
! 	      avr_offset_expression (&op_expr);
! 	      str = input_line_pointer;
! 	      fix_new_exp (frag_now, where, 3,
! 		  &op_expr, FALSE, BFD_RELOC_AVR_6);
! 	    }
        }
        break;
  
***************
*** 746,756 ****
  
      case 'K':
        {
! 	unsigned int x;
! 
! 	x = avr_get_constant (str, 63);
! 	str = input_line_pointer;
! 	op_mask |= (x & 0xf) | ((x & 0x30) << 2);
        }
        break;
  
--- 748,758 ----
  
      case 'K':
        {
! 	  input_line_pointer = str;
! 	  avr_offset_expression (&op_expr);
! 	  str = input_line_pointer;
! 	  fix_new_exp (frag_now, where, 3,
! 	  &op_expr, FALSE, BFD_RELOC_AVR_6_ADIW);
        }
        break;
  
***************
*** 935,940 ****
--- 937,963 ----
  	  bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value), where);
  	  break;
  
+ 	case BFD_RELOC_AVR_LDI:
+ 	  if (value > 255)
+ 	    as_bad_where (fixP->fx_file, fixP->fx_line,
+ 			  _("operand out of range: %ld"), value);
+ 	  bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value), where);
+ 	  break;
+ 
+     case BFD_RELOC_AVR_6:
+ 	  if ((value > 63) || (value<0) )
+ 	    as_bad_where (fixP->fx_file, fixP->fx_line,
+ 			  _("operand out of range: %ld"), value);
+       bfd_putl16 ((bfd_vma) insn | (( value  & 7) | (( value  & (3 << 3)) << 7) | (( value  & (1 << 5)) << 8) ), where);
+       break;
+ 
+     case BFD_RELOC_AVR_6_ADIW:
+ 	  if ((value > 63) || (value<0) )
+ 	    as_bad_where (fixP->fx_file, fixP->fx_line,
+ 			  _("operand out of range: %ld"), value);
+       bfd_putl16 ((bfd_vma) insn| (value & 0xf) | ((value & 0x30)<<2), where);
+       break;
+ 
  	case -BFD_RELOC_AVR_LO8_LDI:
  	  bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 16), where);
  	  break;
***************
*** 1129,1134 ****
--- 1152,1182 ----
    return input_line_pointer;
  }
  
+ /* Parse for ldd/std offset */
+ 
+ static void
+ avr_offset_expression (expressionS *exp)
+ {
+   char *str = input_line_pointer;
+   char *tmp;
+   char op[8];
+   tmp = str;
+   str = extract_word (str, op, sizeof (op));
+ 
+   input_line_pointer = tmp;
+   expression (exp);
+ 
+   /* Warn about expressions that fail to use lo8 ().  */
+   if (exp->X_op == O_constant)
+     {
+       int x = exp->X_add_number;
+       
+       if (x < -255 || x > 255)
+ 	  as_warn (_("constant out of 8-bit range: %d"), x);
+     }
+ 
+ }
+ 
  /* Parse special expressions (needed for LDI command):
     xx8 (address)
     xx8 (-address)
***************
*** 1145,1151 ****
    char op[8];
    int mod;
    tmp = str;
! 
    str = extract_word (str, op, sizeof (op));
  
    if (op[0])
--- 1193,1199 ----
    char op[8];
    int mod;
    tmp = str;
!   
    str = extract_word (str, op, sizeof (op));
  
    if (op[0])
***************
*** 1222,1231 ****
        if (x < -255 || x > 255)
  	as_warn (_("constant out of 8-bit range: %d"), x);
      }
-   else
-     as_warn (_("expression possibly out of 8-bit range"));
  
!   return BFD_RELOC_AVR_LO8_LDI;
  }
  
  /* Flag to pass `pm' mode between `avr_parse_cons_expression' and
--- 1270,1277 ----
        if (x < -255 || x > 255)
  	as_warn (_("constant out of 8-bit range: %d"), x);
      }
  
!   return BFD_RELOC_AVR_LDI;
  }
  
  /* Flag to pass `pm' mode between `avr_parse_cons_expression' and
diff -cr binutils-041119/include/elf/avr.h binutils-041119_modified_for_patch004/include/elf/avr.h
*** binutils-041119/include/elf/avr.h	2001-03-14 03:27:44.000000000 +0100
--- binutils-041119_modified_for_patch004/include/elf/avr.h	2004-12-20 17:13:48.307440920 +0100
***************
*** 53,58 ****
--- 53,61 ----
       RELOC_NUMBER (R_AVR_HI8_LDI_PM_NEG,       16)
       RELOC_NUMBER (R_AVR_HH8_LDI_PM_NEG,       17)
       RELOC_NUMBER (R_AVR_CALL,		       18)
+      RELOC_NUMBER (R_AVR_LDI,              19)
+      RELOC_NUMBER (R_AVR_6,                20)
+      RELOC_NUMBER (R_AVR_6_ADIW,           21)
  END_RELOC_NUMBERS (R_AVR_max)
  
  #endif /* _ELF_AVR_H */
./bfd
2004-12-20 Klaus Rudolph <lts-rudolph@gmx.de>

    * elf32-avr.c: Change parameter interpretation for LDI,
    ADIW/SBIW and LDD/STD
    * reloc.c: new relocs R_AVR_LDI, R_AVR_6, R_AVR_6_ADIW

./gas
2004-12-20 Klaus Rudolph <lts-rudolph@gmx.de>
    
    * config/tc-avr.h: New relocs R_AVR_LDI, R_AVR_6, R_AVR_6_ADIW
    for LDI, ADIW/SBIW and LDD/STD

./include/elf
2004-12-20 Klaus Rudolph <lts-rudolph@gmx.de>
    * include/elf/avr.h: New relocs R_AVR_LDI, R_AVR_6, R_AVR_6_ADIW

----------------------------------------
    if longer descriptions are needed:
---------------------------------------


./bfd
2004-12-20 Klaus Rudolph <lts-rudolph@gmx.de>

    * elf32-avr.c: Change parameter interpretation for LDI,
    ADIW/SBIW and LDD/STD
    the ldi instruction check now for correct size of 8 bit 
    parameter. The reloc take full 16 bit size to do relative
    calculation during link time.
    adiw, sbiw now able to use offsets as parameters
    ldd, std are now also able to us offsets as parameters
    * reloc.c: new relocs R_AVR_LDI, R_AVR_6, R_AVR_6_ADIW

./gas
2004-12-20 Klaus Rudolph <lts-rudolph@gmx.de>
    
    * config/tc-avr.h: New relocs R_AVR_LDI, R_AVR_6, R_AVR_6_ADIW
    for LDI, ADIW/SBIW and LDD/STD
    the ldi instruction check now for correct size of 8 bit 
    parameter. The reloc take full 16 bit size to do relative
    calculation during link time.
    adiw, sbiw now able to use offsets as parameters
    ldd, std are now also able to us offsets as parameters
    * reloc.c: new relocs R_AVR_LDI, R_AVR_6, R_AVR_6_ADIW

./include/elf
2004-12-20 Klaus Rudolph <lts-rudolph@gmx.de>
    * include/elf/avr.h: New relocs R_AVR_LDI, R_AVR_6, R_AVR_6_ADIW


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