Back to index

cell-binutils  2.17cvs20070401
ip2k-ibld.c
Go to the documentation of this file.
00001 /* Instruction building/extraction support for ip2k. -*- C -*-
00002 
00003    THIS FILE IS MACHINE GENERATED WITH CGEN: Cpu tools GENerator.
00004    - the resultant file is machine generated, cgen-ibld.in isn't
00005 
00006    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2005, 2006
00007    Free Software Foundation, Inc.
00008 
00009    This file is part of the GNU Binutils and GDB, the GNU debugger.
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; either version 2, or (at your option)
00014    any later version.
00015 
00016    This program is distributed in the hope that it will be useful,
00017    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019    GNU General Public License for more details.
00020 
00021    You should have received a copy of the GNU General Public License
00022    along with this program; if not, write to the Free Software Foundation, Inc.,
00023    51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00024 
00025 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
00026    Keep that in mind.  */
00027 
00028 #include "sysdep.h"
00029 #include <stdio.h>
00030 #include "ansidecl.h"
00031 #include "dis-asm.h"
00032 #include "bfd.h"
00033 #include "symcat.h"
00034 #include "ip2k-desc.h"
00035 #include "ip2k-opc.h"
00036 #include "opintl.h"
00037 #include "safe-ctype.h"
00038 
00039 #undef  min
00040 #define min(a,b) ((a) < (b) ? (a) : (b))
00041 #undef  max
00042 #define max(a,b) ((a) > (b) ? (a) : (b))
00043 
00044 /* Used by the ifield rtx function.  */
00045 #define FLD(f) (fields->f)
00046 
00047 static const char * insert_normal
00048   (CGEN_CPU_DESC, long, unsigned int, unsigned int, unsigned int,
00049    unsigned int, unsigned int, unsigned int, CGEN_INSN_BYTES_PTR);
00050 static const char * insert_insn_normal
00051   (CGEN_CPU_DESC, const CGEN_INSN *,
00052    CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
00053 static int extract_normal
00054   (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
00055    unsigned int, unsigned int, unsigned int, unsigned int,
00056    unsigned int, unsigned int, bfd_vma, long *);
00057 static int extract_insn_normal
00058   (CGEN_CPU_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *,
00059    CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
00060 #if CGEN_INT_INSN_P
00061 static void put_insn_int_value
00062   (CGEN_CPU_DESC, CGEN_INSN_BYTES_PTR, int, int, CGEN_INSN_INT);
00063 #endif
00064 #if ! CGEN_INT_INSN_P
00065 static CGEN_INLINE void insert_1
00066   (CGEN_CPU_DESC, unsigned long, int, int, int, unsigned char *);
00067 static CGEN_INLINE int fill_cache
00068   (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *,  int, int, bfd_vma);
00069 static CGEN_INLINE long extract_1
00070   (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, int, unsigned char *, bfd_vma);
00071 #endif
00072 
00073 /* Operand insertion.  */
00074 
00075 #if ! CGEN_INT_INSN_P
00076 
00077 /* Subroutine of insert_normal.  */
00078 
00079 static CGEN_INLINE void
00080 insert_1 (CGEN_CPU_DESC cd,
00081          unsigned long value,
00082          int start,
00083          int length,
00084          int word_length,
00085          unsigned char *bufp)
00086 {
00087   unsigned long x,mask;
00088   int shift;
00089 
00090   x = cgen_get_insn_value (cd, bufp, word_length);
00091 
00092   /* Written this way to avoid undefined behaviour.  */
00093   mask = (((1L << (length - 1)) - 1) << 1) | 1;
00094   if (CGEN_INSN_LSB0_P)
00095     shift = (start + 1) - length;
00096   else
00097     shift = (word_length - (start + length));
00098   x = (x & ~(mask << shift)) | ((value & mask) << shift);
00099 
00100   cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x);
00101 }
00102 
00103 #endif /* ! CGEN_INT_INSN_P */
00104 
00105 /* Default insertion routine.
00106 
00107    ATTRS is a mask of the boolean attributes.
00108    WORD_OFFSET is the offset in bits from the start of the insn of the value.
00109    WORD_LENGTH is the length of the word in bits in which the value resides.
00110    START is the starting bit number in the word, architecture origin.
00111    LENGTH is the length of VALUE in bits.
00112    TOTAL_LENGTH is the total length of the insn in bits.
00113 
00114    The result is an error message or NULL if success.  */
00115 
00116 /* ??? This duplicates functionality with bfd's howto table and
00117    bfd_install_relocation.  */
00118 /* ??? This doesn't handle bfd_vma's.  Create another function when
00119    necessary.  */
00120 
00121 static const char *
00122 insert_normal (CGEN_CPU_DESC cd,
00123               long value,
00124               unsigned int attrs,
00125               unsigned int word_offset,
00126               unsigned int start,
00127               unsigned int length,
00128               unsigned int word_length,
00129               unsigned int total_length,
00130               CGEN_INSN_BYTES_PTR buffer)
00131 {
00132   static char errbuf[100];
00133   /* Written this way to avoid undefined behaviour.  */
00134   unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1;
00135 
00136   /* If LENGTH is zero, this operand doesn't contribute to the value.  */
00137   if (length == 0)
00138     return NULL;
00139 
00140   if (word_length > 32)
00141     abort ();
00142 
00143   /* For architectures with insns smaller than the base-insn-bitsize,
00144      word_length may be too big.  */
00145   if (cd->min_insn_bitsize < cd->base_insn_bitsize)
00146     {
00147       if (word_offset == 0
00148          && word_length > total_length)
00149        word_length = total_length;
00150     }
00151 
00152   /* Ensure VALUE will fit.  */
00153   if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT))
00154     {
00155       long minval = - (1L << (length - 1));
00156       unsigned long maxval = mask;
00157       
00158       if ((value > 0 && (unsigned long) value > maxval)
00159          || value < minval)
00160        {
00161          /* xgettext:c-format */
00162          sprintf (errbuf,
00163                  _("operand out of range (%ld not between %ld and %lu)"),
00164                  value, minval, maxval);
00165          return errbuf;
00166        }
00167     }
00168   else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED))
00169     {
00170       unsigned long maxval = mask;
00171       unsigned long val = (unsigned long) value;
00172 
00173       /* For hosts with a word size > 32 check to see if value has been sign
00174         extended beyond 32 bits.  If so then ignore these higher sign bits
00175         as the user is attempting to store a 32-bit signed value into an
00176         unsigned 32-bit field which is allowed.  */
00177       if (sizeof (unsigned long) > 4 && ((value >> 32) == -1))
00178        val &= 0xFFFFFFFF;
00179 
00180       if (val > maxval)
00181        {
00182          /* xgettext:c-format */
00183          sprintf (errbuf,
00184                  _("operand out of range (0x%lx not between 0 and 0x%lx)"),
00185                  val, maxval);
00186          return errbuf;
00187        }
00188     }
00189   else
00190     {
00191       if (! cgen_signed_overflow_ok_p (cd))
00192        {
00193          long minval = - (1L << (length - 1));
00194          long maxval =   (1L << (length - 1)) - 1;
00195          
00196          if (value < minval || value > maxval)
00197            {
00198              sprintf
00199               /* xgettext:c-format */
00200               (errbuf, _("operand out of range (%ld not between %ld and %ld)"),
00201                value, minval, maxval);
00202              return errbuf;
00203            }
00204        }
00205     }
00206 
00207 #if CGEN_INT_INSN_P
00208 
00209   {
00210     int shift;
00211 
00212     if (CGEN_INSN_LSB0_P)
00213       shift = (word_offset + start + 1) - length;
00214     else
00215       shift = total_length - (word_offset + start + length);
00216     *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
00217   }
00218 
00219 #else /* ! CGEN_INT_INSN_P */
00220 
00221   {
00222     unsigned char *bufp = (unsigned char *) buffer + word_offset / 8;
00223 
00224     insert_1 (cd, value, start, length, word_length, bufp);
00225   }
00226 
00227 #endif /* ! CGEN_INT_INSN_P */
00228 
00229   return NULL;
00230 }
00231 
00232 /* Default insn builder (insert handler).
00233    The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
00234    that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
00235    recorded in host byte order, otherwise BUFFER is an array of bytes
00236    and the value is recorded in target byte order).
00237    The result is an error message or NULL if success.  */
00238 
00239 static const char *
00240 insert_insn_normal (CGEN_CPU_DESC cd,
00241                   const CGEN_INSN * insn,
00242                   CGEN_FIELDS * fields,
00243                   CGEN_INSN_BYTES_PTR buffer,
00244                   bfd_vma pc)
00245 {
00246   const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
00247   unsigned long value;
00248   const CGEN_SYNTAX_CHAR_TYPE * syn;
00249 
00250   CGEN_INIT_INSERT (cd);
00251   value = CGEN_INSN_BASE_VALUE (insn);
00252 
00253   /* If we're recording insns as numbers (rather than a string of bytes),
00254      target byte order handling is deferred until later.  */
00255 
00256 #if CGEN_INT_INSN_P
00257 
00258   put_insn_int_value (cd, buffer, cd->base_insn_bitsize,
00259                     CGEN_FIELDS_BITSIZE (fields), value);
00260 
00261 #else
00262 
00263   cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize,
00264                                    (unsigned) CGEN_FIELDS_BITSIZE (fields)),
00265                      value);
00266 
00267 #endif /* ! CGEN_INT_INSN_P */
00268 
00269   /* ??? It would be better to scan the format's fields.
00270      Still need to be able to insert a value based on the operand though;
00271      e.g. storing a branch displacement that got resolved later.
00272      Needs more thought first.  */
00273 
00274   for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn)
00275     {
00276       const char *errmsg;
00277 
00278       if (CGEN_SYNTAX_CHAR_P (* syn))
00279        continue;
00280 
00281       errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
00282                                    fields, buffer, pc);
00283       if (errmsg)
00284        return errmsg;
00285     }
00286 
00287   return NULL;
00288 }
00289 
00290 #if CGEN_INT_INSN_P
00291 /* Cover function to store an insn value into an integral insn.  Must go here
00292    because it needs <prefix>-desc.h for CGEN_INT_INSN_P.  */
00293 
00294 static void
00295 put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
00296                   CGEN_INSN_BYTES_PTR buf,
00297                   int length,
00298                   int insn_length,
00299                   CGEN_INSN_INT value)
00300 {
00301   /* For architectures with insns smaller than the base-insn-bitsize,
00302      length may be too big.  */
00303   if (length > insn_length)
00304     *buf = value;
00305   else
00306     {
00307       int shift = insn_length - length;
00308       /* Written this way to avoid undefined behaviour.  */
00309       CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1;
00310 
00311       *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift);
00312     }
00313 }
00314 #endif
00315 
00316 /* Operand extraction.  */
00317 
00318 #if ! CGEN_INT_INSN_P
00319 
00320 /* Subroutine of extract_normal.
00321    Ensure sufficient bytes are cached in EX_INFO.
00322    OFFSET is the offset in bytes from the start of the insn of the value.
00323    BYTES is the length of the needed value.
00324    Returns 1 for success, 0 for failure.  */
00325 
00326 static CGEN_INLINE int
00327 fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
00328            CGEN_EXTRACT_INFO *ex_info,
00329            int offset,
00330            int bytes,
00331            bfd_vma pc)
00332 {
00333   /* It's doubtful that the middle part has already been fetched so
00334      we don't optimize that case.  kiss.  */
00335   unsigned int mask;
00336   disassemble_info *info = (disassemble_info *) ex_info->dis_info;
00337 
00338   /* First do a quick check.  */
00339   mask = (1 << bytes) - 1;
00340   if (((ex_info->valid >> offset) & mask) == mask)
00341     return 1;
00342 
00343   /* Search for the first byte we need to read.  */
00344   for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1)
00345     if (! (mask & ex_info->valid))
00346       break;
00347 
00348   if (bytes)
00349     {
00350       int status;
00351 
00352       pc += offset;
00353       status = (*info->read_memory_func)
00354        (pc, ex_info->insn_bytes + offset, bytes, info);
00355 
00356       if (status != 0)
00357        {
00358          (*info->memory_error_func) (status, pc, info);
00359          return 0;
00360        }
00361 
00362       ex_info->valid |= ((1 << bytes) - 1) << offset;
00363     }
00364 
00365   return 1;
00366 }
00367 
00368 /* Subroutine of extract_normal.  */
00369 
00370 static CGEN_INLINE long
00371 extract_1 (CGEN_CPU_DESC cd,
00372           CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
00373           int start,
00374           int length,
00375           int word_length,
00376           unsigned char *bufp,
00377           bfd_vma pc ATTRIBUTE_UNUSED)
00378 {
00379   unsigned long x;
00380   int shift;
00381 
00382   x = cgen_get_insn_value (cd, bufp, word_length);
00383 
00384   if (CGEN_INSN_LSB0_P)
00385     shift = (start + 1) - length;
00386   else
00387     shift = (word_length - (start + length));
00388   return x >> shift;
00389 }
00390 
00391 #endif /* ! CGEN_INT_INSN_P */
00392 
00393 /* Default extraction routine.
00394 
00395    INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
00396    or sometimes less for cases like the m32r where the base insn size is 32
00397    but some insns are 16 bits.
00398    ATTRS is a mask of the boolean attributes.  We only need `SIGNED',
00399    but for generality we take a bitmask of all of them.
00400    WORD_OFFSET is the offset in bits from the start of the insn of the value.
00401    WORD_LENGTH is the length of the word in bits in which the value resides.
00402    START is the starting bit number in the word, architecture origin.
00403    LENGTH is the length of VALUE in bits.
00404    TOTAL_LENGTH is the total length of the insn in bits.
00405 
00406    Returns 1 for success, 0 for failure.  */
00407 
00408 /* ??? The return code isn't properly used.  wip.  */
00409 
00410 /* ??? This doesn't handle bfd_vma's.  Create another function when
00411    necessary.  */
00412 
00413 static int
00414 extract_normal (CGEN_CPU_DESC cd,
00415 #if ! CGEN_INT_INSN_P
00416               CGEN_EXTRACT_INFO *ex_info,
00417 #else
00418               CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
00419 #endif
00420               CGEN_INSN_INT insn_value,
00421               unsigned int attrs,
00422               unsigned int word_offset,
00423               unsigned int start,
00424               unsigned int length,
00425               unsigned int word_length,
00426               unsigned int total_length,
00427 #if ! CGEN_INT_INSN_P
00428               bfd_vma pc,
00429 #else
00430               bfd_vma pc ATTRIBUTE_UNUSED,
00431 #endif
00432               long *valuep)
00433 {
00434   long value, mask;
00435 
00436   /* If LENGTH is zero, this operand doesn't contribute to the value
00437      so give it a standard value of zero.  */
00438   if (length == 0)
00439     {
00440       *valuep = 0;
00441       return 1;
00442     }
00443 
00444   if (word_length > 32)
00445     abort ();
00446 
00447   /* For architectures with insns smaller than the insn-base-bitsize,
00448      word_length may be too big.  */
00449   if (cd->min_insn_bitsize < cd->base_insn_bitsize)
00450     {
00451       if (word_offset + word_length > total_length)
00452        word_length = total_length - word_offset;
00453     }
00454 
00455   /* Does the value reside in INSN_VALUE, and at the right alignment?  */
00456 
00457   if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length))
00458     {
00459       if (CGEN_INSN_LSB0_P)
00460        value = insn_value >> ((word_offset + start + 1) - length);
00461       else
00462        value = insn_value >> (total_length - ( word_offset + start + length));
00463     }
00464 
00465 #if ! CGEN_INT_INSN_P
00466 
00467   else
00468     {
00469       unsigned char *bufp = ex_info->insn_bytes + word_offset / 8;
00470 
00471       if (word_length > 32)
00472        abort ();
00473 
00474       if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0)
00475        return 0;
00476 
00477       value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc);
00478     }
00479 
00480 #endif /* ! CGEN_INT_INSN_P */
00481 
00482   /* Written this way to avoid undefined behaviour.  */
00483   mask = (((1L << (length - 1)) - 1) << 1) | 1;
00484 
00485   value &= mask;
00486   /* sign extend? */
00487   if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
00488       && (value & (1L << (length - 1))))
00489     value |= ~mask;
00490 
00491   *valuep = value;
00492 
00493   return 1;
00494 }
00495 
00496 /* Default insn extractor.
00497 
00498    INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
00499    The extracted fields are stored in FIELDS.
00500    EX_INFO is used to handle reading variable length insns.
00501    Return the length of the insn in bits, or 0 if no match,
00502    or -1 if an error occurs fetching data (memory_error_func will have
00503    been called).  */
00504 
00505 static int
00506 extract_insn_normal (CGEN_CPU_DESC cd,
00507                    const CGEN_INSN *insn,
00508                    CGEN_EXTRACT_INFO *ex_info,
00509                    CGEN_INSN_INT insn_value,
00510                    CGEN_FIELDS *fields,
00511                    bfd_vma pc)
00512 {
00513   const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
00514   const CGEN_SYNTAX_CHAR_TYPE *syn;
00515 
00516   CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
00517 
00518   CGEN_INIT_EXTRACT (cd);
00519 
00520   for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
00521     {
00522       int length;
00523 
00524       if (CGEN_SYNTAX_CHAR_P (*syn))
00525        continue;
00526 
00527       length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
00528                                    ex_info, insn_value, fields, pc);
00529       if (length <= 0)
00530        return length;
00531     }
00532 
00533   /* We recognized and successfully extracted this insn.  */
00534   return CGEN_INSN_BITSIZE (insn);
00535 }
00536 
00537 /* Machine generated code added here.  */
00538 
00539 const char * ip2k_cgen_insert_operand
00540   (CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
00541 
00542 /* Main entry point for operand insertion.
00543 
00544    This function is basically just a big switch statement.  Earlier versions
00545    used tables to look up the function to use, but
00546    - if the table contains both assembler and disassembler functions then
00547      the disassembler contains much of the assembler and vice-versa,
00548    - there's a lot of inlining possibilities as things grow,
00549    - using a switch statement avoids the function call overhead.
00550 
00551    This function could be moved into `parse_insn_normal', but keeping it
00552    separate makes clear the interface between `parse_insn_normal' and each of
00553    the handlers.  It's also needed by GAS to insert operands that couldn't be
00554    resolved during parsing.  */
00555 
00556 const char *
00557 ip2k_cgen_insert_operand (CGEN_CPU_DESC cd,
00558                           int opindex,
00559                           CGEN_FIELDS * fields,
00560                           CGEN_INSN_BYTES_PTR buffer,
00561                           bfd_vma pc ATTRIBUTE_UNUSED)
00562 {
00563   const char * errmsg = NULL;
00564   unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
00565 
00566   switch (opindex)
00567     {
00568     case IP2K_OPERAND_ADDR16CJP :
00569       errmsg = insert_normal (cd, fields->f_addr16cjp, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 12, 13, 16, total_length, buffer);
00570       break;
00571     case IP2K_OPERAND_ADDR16H :
00572       errmsg = insert_normal (cd, fields->f_imm8, 0, 0, 7, 8, 16, total_length, buffer);
00573       break;
00574     case IP2K_OPERAND_ADDR16L :
00575       errmsg = insert_normal (cd, fields->f_imm8, 0, 0, 7, 8, 16, total_length, buffer);
00576       break;
00577     case IP2K_OPERAND_ADDR16P :
00578       errmsg = insert_normal (cd, fields->f_page3, 0, 0, 2, 3, 16, total_length, buffer);
00579       break;
00580     case IP2K_OPERAND_BITNO :
00581       errmsg = insert_normal (cd, fields->f_bitno, 0, 0, 11, 3, 16, total_length, buffer);
00582       break;
00583     case IP2K_OPERAND_CBIT :
00584       break;
00585     case IP2K_OPERAND_DCBIT :
00586       break;
00587     case IP2K_OPERAND_FR :
00588       errmsg = insert_normal (cd, fields->f_reg, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 8, 9, 16, total_length, buffer);
00589       break;
00590     case IP2K_OPERAND_LIT8 :
00591       errmsg = insert_normal (cd, fields->f_imm8, 0, 0, 7, 8, 16, total_length, buffer);
00592       break;
00593     case IP2K_OPERAND_PABITS :
00594       break;
00595     case IP2K_OPERAND_RETI3 :
00596       errmsg = insert_normal (cd, fields->f_reti3, 0, 0, 2, 3, 16, total_length, buffer);
00597       break;
00598     case IP2K_OPERAND_ZBIT :
00599       break;
00600 
00601     default :
00602       /* xgettext:c-format */
00603       fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
00604               opindex);
00605       abort ();
00606   }
00607 
00608   return errmsg;
00609 }
00610 
00611 int ip2k_cgen_extract_operand
00612   (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
00613 
00614 /* Main entry point for operand extraction.
00615    The result is <= 0 for error, >0 for success.
00616    ??? Actual values aren't well defined right now.
00617 
00618    This function is basically just a big switch statement.  Earlier versions
00619    used tables to look up the function to use, but
00620    - if the table contains both assembler and disassembler functions then
00621      the disassembler contains much of the assembler and vice-versa,
00622    - there's a lot of inlining possibilities as things grow,
00623    - using a switch statement avoids the function call overhead.
00624 
00625    This function could be moved into `print_insn_normal', but keeping it
00626    separate makes clear the interface between `print_insn_normal' and each of
00627    the handlers.  */
00628 
00629 int
00630 ip2k_cgen_extract_operand (CGEN_CPU_DESC cd,
00631                           int opindex,
00632                           CGEN_EXTRACT_INFO *ex_info,
00633                           CGEN_INSN_INT insn_value,
00634                           CGEN_FIELDS * fields,
00635                           bfd_vma pc)
00636 {
00637   /* Assume success (for those operands that are nops).  */
00638   int length = 1;
00639   unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
00640 
00641   switch (opindex)
00642     {
00643     case IP2K_OPERAND_ADDR16CJP :
00644       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 12, 13, 16, total_length, pc, & fields->f_addr16cjp);
00645       break;
00646     case IP2K_OPERAND_ADDR16H :
00647       length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 8, 16, total_length, pc, & fields->f_imm8);
00648       break;
00649     case IP2K_OPERAND_ADDR16L :
00650       length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 8, 16, total_length, pc, & fields->f_imm8);
00651       break;
00652     case IP2K_OPERAND_ADDR16P :
00653       length = extract_normal (cd, ex_info, insn_value, 0, 0, 2, 3, 16, total_length, pc, & fields->f_page3);
00654       break;
00655     case IP2K_OPERAND_BITNO :
00656       length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 3, 16, total_length, pc, & fields->f_bitno);
00657       break;
00658     case IP2K_OPERAND_CBIT :
00659       break;
00660     case IP2K_OPERAND_DCBIT :
00661       break;
00662     case IP2K_OPERAND_FR :
00663       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 8, 9, 16, total_length, pc, & fields->f_reg);
00664       break;
00665     case IP2K_OPERAND_LIT8 :
00666       length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 8, 16, total_length, pc, & fields->f_imm8);
00667       break;
00668     case IP2K_OPERAND_PABITS :
00669       break;
00670     case IP2K_OPERAND_RETI3 :
00671       length = extract_normal (cd, ex_info, insn_value, 0, 0, 2, 3, 16, total_length, pc, & fields->f_reti3);
00672       break;
00673     case IP2K_OPERAND_ZBIT :
00674       break;
00675 
00676     default :
00677       /* xgettext:c-format */
00678       fprintf (stderr, _("Unrecognized field %d while decoding insn.\n"),
00679               opindex);
00680       abort ();
00681     }
00682 
00683   return length;
00684 }
00685 
00686 cgen_insert_fn * const ip2k_cgen_insert_handlers[] = 
00687 {
00688   insert_insn_normal,
00689 };
00690 
00691 cgen_extract_fn * const ip2k_cgen_extract_handlers[] = 
00692 {
00693   extract_insn_normal,
00694 };
00695 
00696 int ip2k_cgen_get_int_operand     (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
00697 bfd_vma ip2k_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
00698 
00699 /* Getting values from cgen_fields is handled by a collection of functions.
00700    They are distinguished by the type of the VALUE argument they return.
00701    TODO: floating point, inlining support, remove cases where result type
00702    not appropriate.  */
00703 
00704 int
00705 ip2k_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
00706                           int opindex,
00707                           const CGEN_FIELDS * fields)
00708 {
00709   int value;
00710 
00711   switch (opindex)
00712     {
00713     case IP2K_OPERAND_ADDR16CJP :
00714       value = fields->f_addr16cjp;
00715       break;
00716     case IP2K_OPERAND_ADDR16H :
00717       value = fields->f_imm8;
00718       break;
00719     case IP2K_OPERAND_ADDR16L :
00720       value = fields->f_imm8;
00721       break;
00722     case IP2K_OPERAND_ADDR16P :
00723       value = fields->f_page3;
00724       break;
00725     case IP2K_OPERAND_BITNO :
00726       value = fields->f_bitno;
00727       break;
00728     case IP2K_OPERAND_CBIT :
00729       value = 0;
00730       break;
00731     case IP2K_OPERAND_DCBIT :
00732       value = 0;
00733       break;
00734     case IP2K_OPERAND_FR :
00735       value = fields->f_reg;
00736       break;
00737     case IP2K_OPERAND_LIT8 :
00738       value = fields->f_imm8;
00739       break;
00740     case IP2K_OPERAND_PABITS :
00741       value = 0;
00742       break;
00743     case IP2K_OPERAND_RETI3 :
00744       value = fields->f_reti3;
00745       break;
00746     case IP2K_OPERAND_ZBIT :
00747       value = 0;
00748       break;
00749 
00750     default :
00751       /* xgettext:c-format */
00752       fprintf (stderr, _("Unrecognized field %d while getting int operand.\n"),
00753                      opindex);
00754       abort ();
00755   }
00756 
00757   return value;
00758 }
00759 
00760 bfd_vma
00761 ip2k_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
00762                           int opindex,
00763                           const CGEN_FIELDS * fields)
00764 {
00765   bfd_vma value;
00766 
00767   switch (opindex)
00768     {
00769     case IP2K_OPERAND_ADDR16CJP :
00770       value = fields->f_addr16cjp;
00771       break;
00772     case IP2K_OPERAND_ADDR16H :
00773       value = fields->f_imm8;
00774       break;
00775     case IP2K_OPERAND_ADDR16L :
00776       value = fields->f_imm8;
00777       break;
00778     case IP2K_OPERAND_ADDR16P :
00779       value = fields->f_page3;
00780       break;
00781     case IP2K_OPERAND_BITNO :
00782       value = fields->f_bitno;
00783       break;
00784     case IP2K_OPERAND_CBIT :
00785       value = 0;
00786       break;
00787     case IP2K_OPERAND_DCBIT :
00788       value = 0;
00789       break;
00790     case IP2K_OPERAND_FR :
00791       value = fields->f_reg;
00792       break;
00793     case IP2K_OPERAND_LIT8 :
00794       value = fields->f_imm8;
00795       break;
00796     case IP2K_OPERAND_PABITS :
00797       value = 0;
00798       break;
00799     case IP2K_OPERAND_RETI3 :
00800       value = fields->f_reti3;
00801       break;
00802     case IP2K_OPERAND_ZBIT :
00803       value = 0;
00804       break;
00805 
00806     default :
00807       /* xgettext:c-format */
00808       fprintf (stderr, _("Unrecognized field %d while getting vma operand.\n"),
00809                      opindex);
00810       abort ();
00811   }
00812 
00813   return value;
00814 }
00815 
00816 void ip2k_cgen_set_int_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, int);
00817 void ip2k_cgen_set_vma_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma);
00818 
00819 /* Stuffing values in cgen_fields is handled by a collection of functions.
00820    They are distinguished by the type of the VALUE argument they accept.
00821    TODO: floating point, inlining support, remove cases where argument type
00822    not appropriate.  */
00823 
00824 void
00825 ip2k_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
00826                           int opindex,
00827                           CGEN_FIELDS * fields,
00828                           int value)
00829 {
00830   switch (opindex)
00831     {
00832     case IP2K_OPERAND_ADDR16CJP :
00833       fields->f_addr16cjp = value;
00834       break;
00835     case IP2K_OPERAND_ADDR16H :
00836       fields->f_imm8 = value;
00837       break;
00838     case IP2K_OPERAND_ADDR16L :
00839       fields->f_imm8 = value;
00840       break;
00841     case IP2K_OPERAND_ADDR16P :
00842       fields->f_page3 = value;
00843       break;
00844     case IP2K_OPERAND_BITNO :
00845       fields->f_bitno = value;
00846       break;
00847     case IP2K_OPERAND_CBIT :
00848       break;
00849     case IP2K_OPERAND_DCBIT :
00850       break;
00851     case IP2K_OPERAND_FR :
00852       fields->f_reg = value;
00853       break;
00854     case IP2K_OPERAND_LIT8 :
00855       fields->f_imm8 = value;
00856       break;
00857     case IP2K_OPERAND_PABITS :
00858       break;
00859     case IP2K_OPERAND_RETI3 :
00860       fields->f_reti3 = value;
00861       break;
00862     case IP2K_OPERAND_ZBIT :
00863       break;
00864 
00865     default :
00866       /* xgettext:c-format */
00867       fprintf (stderr, _("Unrecognized field %d while setting int operand.\n"),
00868                      opindex);
00869       abort ();
00870   }
00871 }
00872 
00873 void
00874 ip2k_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
00875                           int opindex,
00876                           CGEN_FIELDS * fields,
00877                           bfd_vma value)
00878 {
00879   switch (opindex)
00880     {
00881     case IP2K_OPERAND_ADDR16CJP :
00882       fields->f_addr16cjp = value;
00883       break;
00884     case IP2K_OPERAND_ADDR16H :
00885       fields->f_imm8 = value;
00886       break;
00887     case IP2K_OPERAND_ADDR16L :
00888       fields->f_imm8 = value;
00889       break;
00890     case IP2K_OPERAND_ADDR16P :
00891       fields->f_page3 = value;
00892       break;
00893     case IP2K_OPERAND_BITNO :
00894       fields->f_bitno = value;
00895       break;
00896     case IP2K_OPERAND_CBIT :
00897       break;
00898     case IP2K_OPERAND_DCBIT :
00899       break;
00900     case IP2K_OPERAND_FR :
00901       fields->f_reg = value;
00902       break;
00903     case IP2K_OPERAND_LIT8 :
00904       fields->f_imm8 = value;
00905       break;
00906     case IP2K_OPERAND_PABITS :
00907       break;
00908     case IP2K_OPERAND_RETI3 :
00909       fields->f_reti3 = value;
00910       break;
00911     case IP2K_OPERAND_ZBIT :
00912       break;
00913 
00914     default :
00915       /* xgettext:c-format */
00916       fprintf (stderr, _("Unrecognized field %d while setting vma operand.\n"),
00917                      opindex);
00918       abort ();
00919   }
00920 }
00921 
00922 /* Function to call before using the instruction builder tables.  */
00923 
00924 void
00925 ip2k_cgen_init_ibld_table (CGEN_CPU_DESC cd)
00926 {
00927   cd->insert_handlers = & ip2k_cgen_insert_handlers[0];
00928   cd->extract_handlers = & ip2k_cgen_extract_handlers[0];
00929 
00930   cd->insert_operand = ip2k_cgen_insert_operand;
00931   cd->extract_operand = ip2k_cgen_extract_operand;
00932 
00933   cd->get_int_operand = ip2k_cgen_get_int_operand;
00934   cd->set_int_operand = ip2k_cgen_set_int_operand;
00935   cd->get_vma_operand = ip2k_cgen_get_vma_operand;
00936   cd->set_vma_operand = ip2k_cgen_set_vma_operand;
00937 }