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/opcodes/m32r-ibld.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    2626
    2727#include "sysdep.h"
    28 #include <ctype.h>
    2928#include <stdio.h>
    3029#include "ansidecl.h"
     
    3534#include "m32r-opc.h"
    3635#include "opintl.h"
     36#include "safe-ctype.h"
    3737
    3838#undef min
     
    5050     PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *,
    5151              CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma));
    52 
    5352static int extract_normal
    5453     PARAMS ((CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
     
    5857     PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *,
    5958              CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma));
     59#if CGEN_INT_INSN_P
    6060static void put_insn_int_value
    6161     PARAMS ((CGEN_CPU_DESC, CGEN_INSN_BYTES_PTR, int, int, CGEN_INSN_INT));
    62 
     62#endif
     63#if ! CGEN_INT_INSN_P
     64static CGEN_INLINE void insert_1
     65     PARAMS ((CGEN_CPU_DESC, unsigned long, int, int, int, unsigned char *));
     66static CGEN_INLINE int fill_cache
     67     PARAMS ((CGEN_CPU_DESC, CGEN_EXTRACT_INFO *,  int, int, bfd_vma));
     68static CGEN_INLINE long extract_1
     69     PARAMS ((CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, int,
     70              unsigned char *, bfd_vma));
     71#endif
    6372
    6473
     
    7887  unsigned long x,mask;
    7988  int shift;
    80   int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG;
    81 
    82   switch (word_length)
    83     {
    84     case 8:
    85       x = *bufp;
    86       break;
    87     case 16:
    88       if (big_p)
    89         x = bfd_getb16 (bufp);
    90       else
    91         x = bfd_getl16 (bufp);
    92       break;
    93     case 24:
    94       /* ??? This may need reworking as these cases don't necessarily
    95          want the first byte and the last two bytes handled like this.  */
    96       if (big_p)
    97         x = (bufp[0] << 16) | bfd_getb16 (bufp + 1);
    98       else
    99         x = bfd_getl16 (bufp) | (bufp[2] << 16);
    100       break;
    101     case 32:
    102       if (big_p)
    103         x = bfd_getb32 (bufp);
    104       else
    105         x = bfd_getl32 (bufp);
    106       break;
    107     default :
    108       abort ();
    109     }
     89
     90  x = cgen_get_insn_value (cd, bufp, word_length);
    11091
    11192  /* Written this way to avoid undefined behaviour.  */
     
    11798  x = (x & ~(mask << shift)) | ((value & mask) << shift);
    11899
    119   switch (word_length)
    120     {
    121     case 8:
    122       *bufp = x;
    123       break;
    124     case 16:
    125       if (big_p)
    126         bfd_putb16 (x, bufp);
    127       else
    128         bfd_putl16 (x, bufp);
    129       break;
    130     case 24:
    131       /* ??? This may need reworking as these cases don't necessarily
    132          want the first byte and the last two bytes handled like this.  */
    133       if (big_p)
    134         {
    135           bufp[0] = x >> 16;
    136           bfd_putb16 (x, bufp + 1);
    137         }
    138       else
    139         {
    140           bfd_putl16 (x, bufp);
    141           bufp[2] = x >> 16;
    142         }
    143       break;
    144     case 32:
    145       if (big_p)
    146         bfd_putb32 (x, bufp);
    147       else
    148         bfd_putl32 (x, bufp);
    149       break;
    150     default :
    151       abort ();
    152     }
     100  cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x);
    153101}
    154102
     
    207155
    208156  /* Ensure VALUE will fit.  */
    209   if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED))
     157  if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT))
     158    {
     159      long minval = - (1L << (length - 1));
     160      unsigned long maxval = mask;
     161     
     162      if ((value > 0 && (unsigned long) value > maxval)
     163          || value < minval)
     164        {
     165          /* xgettext:c-format */
     166          sprintf (errbuf,
     167                   _("operand out of range (%ld not between %ld and %lu)"),
     168                   value, minval, maxval);
     169          return errbuf;
     170        }
     171    }
     172  else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED))
    210173    {
    211174      unsigned long maxval = mask;
     
    264227
    265228/* Default insn builder (insert handler).
    266    The instruction is recorded in CGEN_INT_INSN_P byte order
    267    (meaning that if CGEN_INT_INSN_P BUFFER is an int * and thus the value is
    268    recorded in host byte order, otherwise BUFFER is an array of bytes and the
    269    value is recorded in target byte order).
     229   The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
     230   that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
     231   recorded in host byte order, otherwise BUFFER is an array of bytes
     232   and the value is recorded in target byte order).
    270233   The result is an error message or NULL if success.  */
    271234
     
    280243  const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
    281244  unsigned long value;
    282   const unsigned char * syn;
     245  const CGEN_SYNTAX_CHAR_TYPE * syn;
    283246
    284247  CGEN_INIT_INSERT (cd);
     
    295258#else
    296259
    297   cgen_put_insn_value (cd, buffer, min (cd->base_insn_bitsize,
    298                                         CGEN_FIELDS_BITSIZE (fields)),
     260  cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize,
     261                                        (unsigned) CGEN_FIELDS_BITSIZE (fields)),
    299262                       value);
    300263
     
    306269     Needs more thought first.  */
    307270
    308   for (syn = CGEN_SYNTAX_STRING (syntax); * syn != '\0'; ++ syn)
     271  for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn)
    309272    {
    310273      const char *errmsg;
     
    322285}
    323286
     287#if CGEN_INT_INSN_P
    324288/* Cover function to store an insn value into an integral insn.  Must go here
    325289 because it needs <prefix>-desc.h for CGEN_INT_INSN_P.  */
     
    327291static void
    328292put_insn_int_value (cd, buf, length, insn_length, value)
    329      CGEN_CPU_DESC cd;
     293     CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
    330294     CGEN_INSN_BYTES_PTR buf;
    331295     int length;
     
    345309    }
    346310}
     311#endif
    347312
    348313
     
    359324static CGEN_INLINE int
    360325fill_cache (cd, ex_info, offset, bytes, pc)
    361      CGEN_CPU_DESC cd;
     326     CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
    362327     CGEN_EXTRACT_INFO *ex_info;
    363328     int offset, bytes;
     
    366331  /* It's doubtful that the middle part has already been fetched so
    367332     we don't optimize that case.  kiss.  */
    368   int mask;
     333  unsigned int mask;
    369334  disassemble_info *info = (disassemble_info *) ex_info->dis_info;
    370335
     
    404369extract_1 (cd, ex_info, start, length, word_length, bufp, pc)
    405370     CGEN_CPU_DESC cd;
    406      CGEN_EXTRACT_INFO *ex_info;
     371     CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED;
    407372     int start,length,word_length;
    408373     unsigned char *bufp;
    409      bfd_vma pc;
    410 {
    411   unsigned long x,mask;
     374     bfd_vma pc ATTRIBUTE_UNUSED;
     375{
     376  unsigned long x;
    412377  int shift;
     378#if 0
    413379  int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG;
    414 
    415   switch (word_length)
    416     {
    417     case 8:
    418       x = *bufp;
    419       break;
    420     case 16:
    421       if (big_p)
    422         x = bfd_getb16 (bufp);
    423       else
    424         x = bfd_getl16 (bufp);
    425       break;
    426     case 24:
    427       /* ??? This may need reworking as these cases don't necessarily
    428          want the first byte and the last two bytes handled like this.  */
    429       if (big_p)
    430         x = (bufp[0] << 16) | bfd_getb16 (bufp + 1);
    431       else
    432         x = bfd_getl16 (bufp) | (bufp[2] << 16);
    433       break;
    434     case 32:
    435       if (big_p)
    436         x = bfd_getb32 (bufp);
    437       else
    438         x = bfd_getl32 (bufp);
    439       break;
    440     default :
    441       abort ();
    442     }
    443 
    444   /* Written this way to avoid undefined behaviour.  */
    445   mask = (((1L << (length - 1)) - 1) << 1) | 1;
     380#endif
     381  x = cgen_get_insn_value (cd, bufp, word_length);
     382
    446383  if (CGEN_INSN_LSB0_P)
    447384    shift = (start + 1) - length;
    448385  else
    449386    shift = (word_length - (start + length));
    450   return (x >> shift) & mask;
     387  return x >> shift;
    451388}
    452389
     
    492429     long *valuep;
    493430{
    494   CGEN_INSN_INT value;
     431  long value, mask;
    495432
    496433  /* If LENGTH is zero, this operand doesn't contribute to the value
     
    520457    }
    521458
    522   /* Does the value reside in INSN_VALUE?  */
    523 
    524   if (CGEN_INT_INSN_P || word_offset == 0)
    525     {
    526       /* Written this way to avoid undefined behaviour.  */
    527       CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1;
    528 
     459  /* Does the value reside in INSN_VALUE, and at the right alignment?  */
     460
     461  if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length))
     462    {
    529463      if (CGEN_INSN_LSB0_P)
    530464        value = insn_value >> ((word_offset + start + 1) - length);
    531465      else
    532466        value = insn_value >> (total_length - ( word_offset + start + length));
    533       value &= mask;
    534       /* sign extend? */
    535       if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
    536           && (value & (1L << (length - 1))))
    537         value |= ~mask;
    538467    }
    539468
     
    554483
    555484#endif /* ! CGEN_INT_INSN_P */
     485
     486  /* Written this way to avoid undefined behaviour.  */
     487  mask = (((1L << (length - 1)) - 1) << 1) | 1;
     488
     489  value &= mask;
     490  /* sign extend? */
     491  if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
     492      && (value & (1L << (length - 1))))
     493    value |= ~mask;
    556494
    557495  *valuep = value;
     
    579517{
    580518  const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
    581   const unsigned char *syn;
     519  const CGEN_SYNTAX_CHAR_TYPE *syn;
    582520
    583521  CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
     
    604542
    605543/* machine generated code added here */
     544
     545const char * m32r_cgen_insert_operand
     546  PARAMS ((CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma));
    606547
    607548/* Main entry point for operand insertion.
     
    617558   separate makes clear the interface between `parse_insn_normal' and each of
    618559   the handlers.  It's also needed by GAS to insert operands that couldn't be
    619    resolved during parsing.
    620 */
     560   resolved during parsing.  */
    621561
    622562const char *
     
    626566     CGEN_FIELDS * fields;
    627567     CGEN_INSN_BYTES_PTR buffer;
    628      bfd_vma pc;
     568     bfd_vma pc ATTRIBUTE_UNUSED;
    629569{
    630570  const char * errmsg = NULL;
     
    728668}
    729669
     670int m32r_cgen_extract_operand
     671  PARAMS ((CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
     672           CGEN_FIELDS *, bfd_vma));
     673
    730674/* Main entry point for operand extraction.
    731675   The result is <= 0 for error, >0 for success.
     
    741685   This function could be moved into `print_insn_normal', but keeping it
    742686   separate makes clear the interface between `print_insn_normal' and each of
    743    the handlers.
    744 */
     687   the handlers.  */
    745688
    746689int
     
    868811};
    869812
     813int m32r_cgen_get_int_operand
     814  PARAMS ((CGEN_CPU_DESC, int, const CGEN_FIELDS *));
     815bfd_vma m32r_cgen_get_vma_operand
     816  PARAMS ((CGEN_CPU_DESC, int, const CGEN_FIELDS *));
     817
    870818/* Getting values from cgen_fields is handled by a collection of functions.
    871819   They are distinguished by the type of the VALUE argument they return.
     
    875823int
    876824m32r_cgen_get_int_operand (cd, opindex, fields)
    877      CGEN_CPU_DESC cd;
     825     CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
    878826     int opindex;
    879827     const CGEN_FIELDS * fields;
     
    965913bfd_vma
    966914m32r_cgen_get_vma_operand (cd, opindex, fields)
    967      CGEN_CPU_DESC cd;
     915     CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
    968916     int opindex;
    969917     const CGEN_FIELDS * fields;
     
    10531001}
    10541002
     1003void m32r_cgen_set_int_operand
     1004  PARAMS ((CGEN_CPU_DESC, int, CGEN_FIELDS *, int));
     1005void m32r_cgen_set_vma_operand
     1006  PARAMS ((CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma));
     1007
    10551008/* Stuffing values in cgen_fields is handled by a collection of functions.
    10561009   They are distinguished by the type of the VALUE argument they accept.
     
    10601013void
    10611014m32r_cgen_set_int_operand (cd, opindex, fields, value)
    1062      CGEN_CPU_DESC cd;
     1015     CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
    10631016     int opindex;
    10641017     CGEN_FIELDS * fields;
     
    11461099void
    11471100m32r_cgen_set_vma_operand (cd, opindex, fields, value)
    1148      CGEN_CPU_DESC cd;
     1101     CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
    11491102     int opindex;
    11501103     CGEN_FIELDS * fields;
Note: See TracChangeset for help on using the changeset viewer.