Home | History | Annotate | Download | only in cpu
      1 /* XC16X opcode support.  -*- C -*-
      2 
      3    Copyright 2006, 2007, 2009 Free Software Foundation, Inc.
      4 
      5    Contributed by KPIT Cummins Infosystems Ltd.; developed under contract
      6    from Infineon Systems, GMBH , Germany.
      7 
      8    This file is part of the GNU Binutils.
      9 
     10    This program is free software; you can redistribute it and/or modify
     11    it under the terms of the GNU General Public License as published by
     12    the Free Software Foundation; either version 3 of the License, or
     13    (at your option) any later version.
     14 
     15    This program is distributed in the hope that it will be useful,
     16    but WITHOUT ANY WARRANTY; without even the implied warranty of
     17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18    GNU General Public License for more details.
     19 
     20    You should have received a copy of the GNU General Public License
     21    along with this program; if not, write to the Free Software
     22    Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
     23    02110-1301, USA.  */
     24 
     25 
     26 /* This file is an addendum to xc16x.cpu.  Heavy use of C code isn't
     27    appropriate in .cpu files, so it resides here.  This especially applies
     28    to assembly/disassembly where parsing/printing can be quite involved.
     29    Such things aren't really part of the specification of the cpu, per se,
     30    so .cpu files provide the general framework and .opc files handle the
     31    nitty-gritty details as necessary.
     32 
     33    Each section is delimited with start and end markers.
     34 
     35    <arch>-opc.h additions use: "-- opc.h"
     36    <arch>-opc.c additions use: "-- opc.c"
     37    <arch>-asm.c additions use: "-- asm.c"
     38    <arch>-dis.c additions use: "-- dis.c"
     39    <arch>-ibd.h additions use: "-- ibd.h"  */
     40 
     41 /* -- opc.h */
     43 
     44 #define CGEN_DIS_HASH_SIZE 8
     45 #define CGEN_DIS_HASH(buf,value) (((* (unsigned char*) (buf)) >> 3) % CGEN_DIS_HASH_SIZE)
     46 
     47 /* -- */
     48 
     49 /* -- opc.c */
     51 
     52 /* -- */
     53 
     54 /* -- asm.c */
     56 /* Handle '#' prefixes (i.e. skip over them).  */
     57 
     58 static const char *
     59 parse_hash (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
     60 	    const char **strp,
     61 	    int opindex ATTRIBUTE_UNUSED,
     62 	    long *valuep ATTRIBUTE_UNUSED)
     63 {
     64   if (**strp == '#')
     65     {
     66       ++*strp;
     67       return NULL;
     68     }
     69   return _("Missing '#' prefix");
     70 }
     71 
     72 /* Handle '.' prefixes (i.e. skip over them).  */
     73 
     74 static const char *
     75 parse_dot (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
     76 	   const char **strp,
     77 	   int opindex ATTRIBUTE_UNUSED,
     78 	   long *valuep ATTRIBUTE_UNUSED)
     79 {
     80   if (**strp == '.')
     81     {
     82       ++*strp;
     83       return NULL;
     84     }
     85   return _("Missing '.' prefix");
     86 }
     87 
     88 /* Handle 'pof:' prefixes (i.e. skip over them).  */
     89 
     90 static const char *
     91 parse_pof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
     92 	   const char **strp,
     93 	   int opindex ATTRIBUTE_UNUSED,
     94 	   long *valuep ATTRIBUTE_UNUSED)
     95 {
     96   if (strncasecmp (*strp, "pof:", 4) == 0)
     97     {
     98       *strp += 4;
     99       return NULL;
    100     }
    101   return _("Missing 'pof:' prefix");
    102 }
    103 
    104 /* Handle 'pag:' prefixes (i.e. skip over them).  */
    105 
    106 static const char *
    107 parse_pag (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    108 	   const char **strp,
    109 	   int opindex ATTRIBUTE_UNUSED,
    110 	   long *valuep ATTRIBUTE_UNUSED)
    111 {
    112   if (strncasecmp (*strp, "pag:", 4) == 0)
    113     {
    114       *strp += 4;
    115       return NULL;
    116     }
    117   return _("Missing 'pag:' prefix");
    118 }
    119 
    120 /* Handle 'sof' prefixes (i.e. skip over them).  */
    121 
    122 static const char *
    123 parse_sof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    124 	   const char **strp,
    125 	   int opindex ATTRIBUTE_UNUSED,
    126 	   long *valuep ATTRIBUTE_UNUSED)
    127 {
    128   if (strncasecmp (*strp, "sof:", 4) == 0)
    129     {
    130       *strp += 4;
    131       return NULL;
    132     }
    133   return _("Missing 'sof:' prefix");
    134 }
    135 
    136 /* Handle 'seg' prefixes (i.e. skip over them).  */
    137 
    138 static const char *
    139 parse_seg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    140 	   const char **strp,
    141 	   int opindex ATTRIBUTE_UNUSED,
    142 	   long *valuep ATTRIBUTE_UNUSED)
    143 {
    144   if (strncasecmp (*strp, "seg:", 4) == 0)
    145     {
    146       *strp += 4;
    147       return NULL;
    148     }
    149   return _("Missing 'seg:' prefix");
    150 }
    151 /* -- */
    152 
    153 /* -- dis.c */
    155 
    156 /* Print an operand with a "." prefix.
    157    NOTE: This prints the operand in hex.
    158    ??? This exists to maintain disassembler compatibility with previous
    159    versions.  Ideally we'd print the "." in print_dot.  */
    160 
    161 static void
    162 print_with_dot_prefix (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    163 		       void * dis_info,
    164 		       long value,
    165 		       unsigned attrs ATTRIBUTE_UNUSED,
    166 		       bfd_vma pc ATTRIBUTE_UNUSED,
    167 		       int length ATTRIBUTE_UNUSED)
    168 {
    169   disassemble_info *info = (disassemble_info *) dis_info;
    170 
    171   info->fprintf_func (info->stream, ".");
    172   info->fprintf_func (info->stream, "0x%lx", value);
    173 }
    174 
    175 /* Print an operand with a "#pof:" prefix.
    176    NOTE: This prints the operand as an address.
    177    ??? This exists to maintain disassembler compatibility with previous
    178    versions.  Ideally we'd print "#pof:" in print_pof.  */
    179 
    180 static void
    181 print_with_pof_prefix (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    182 		       void * dis_info,
    183 		       bfd_vma value,
    184 		       unsigned attrs ATTRIBUTE_UNUSED,
    185 		       bfd_vma pc ATTRIBUTE_UNUSED,
    186 		       int length ATTRIBUTE_UNUSED)
    187 {
    188   disassemble_info *info = (disassemble_info *) dis_info;
    189 
    190   info->fprintf_func (info->stream, "#pof:");
    191   info->fprintf_func (info->stream, "0x%lx", (long) value);
    192 }
    193 
    194 /* Print an operand with a "#pag:" prefix.
    195    NOTE: This prints the operand in hex.
    196    ??? This exists to maintain disassembler compatibility with previous
    197    versions.  Ideally we'd print "#pag:" in print_pag.  */
    198 
    199 static void
    200 print_with_pag_prefix (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    201 		       void * dis_info,
    202 		       long value,
    203 		       unsigned attrs ATTRIBUTE_UNUSED,
    204 		       bfd_vma pc ATTRIBUTE_UNUSED,
    205 		       int length ATTRIBUTE_UNUSED)
    206 {
    207   disassemble_info *info = (disassemble_info *) dis_info;
    208 
    209   info->fprintf_func (info->stream, "#pag:");
    210   info->fprintf_func (info->stream, "0x%lx", value);
    211 }
    212 
    213 /* Print a 'pof:' prefix to an operand.  */
    214 
    215 static void
    216 print_pof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    217 	   void * dis_info ATTRIBUTE_UNUSED,
    218 	   long value ATTRIBUTE_UNUSED,
    219 	   unsigned int attrs ATTRIBUTE_UNUSED,
    220 	   bfd_vma pc ATTRIBUTE_UNUSED,
    221 	   int length ATTRIBUTE_UNUSED)
    222 {
    223 }
    224 
    225 /* Print a 'pag:' prefix to an operand.  */
    226 
    227 static void
    228 print_pag (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    229 	   void * dis_info ATTRIBUTE_UNUSED,
    230 	   long value ATTRIBUTE_UNUSED,
    231 	   unsigned int attrs ATTRIBUTE_UNUSED,
    232 	   bfd_vma pc ATTRIBUTE_UNUSED,
    233 	   int length ATTRIBUTE_UNUSED)
    234 {
    235 }
    236 
    237 /* Print a 'sof:' prefix to an operand.  */
    238 
    239 static void
    240 print_sof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    241 	   void * dis_info,
    242 	   long value ATTRIBUTE_UNUSED,
    243 	   unsigned int attrs ATTRIBUTE_UNUSED,
    244 	   bfd_vma pc ATTRIBUTE_UNUSED,
    245 	   int length ATTRIBUTE_UNUSED)
    246 {
    247   disassemble_info *info = (disassemble_info *) dis_info;
    248 
    249   info->fprintf_func (info->stream, "sof:");
    250 }
    251 
    252 /* Print a 'seg:' prefix to an operand.  */
    253 
    254 static void
    255 print_seg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    256 	   void * dis_info,
    257 	   long value ATTRIBUTE_UNUSED,
    258 	   unsigned int attrs ATTRIBUTE_UNUSED,
    259 	   bfd_vma pc ATTRIBUTE_UNUSED,
    260 	   int length ATTRIBUTE_UNUSED)
    261 {
    262   disassemble_info *info = (disassemble_info *) dis_info;
    263 
    264   info->fprintf_func (info->stream, "seg:");
    265 }
    266 
    267 /* Print a '#' prefix to an operand.  */
    268 
    269 static void
    270 print_hash (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    271 	    void * dis_info,
    272 	    long value ATTRIBUTE_UNUSED,
    273 	    unsigned int attrs ATTRIBUTE_UNUSED,
    274 	    bfd_vma pc ATTRIBUTE_UNUSED,
    275 	    int length ATTRIBUTE_UNUSED)
    276 {
    277   disassemble_info *info = (disassemble_info *) dis_info;
    278 
    279   info->fprintf_func (info->stream, "#");
    280 }
    281 
    282 /* Print a '.' prefix to an operand.  */
    283 
    284 static void
    285 print_dot (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    286 	   void * dis_info ATTRIBUTE_UNUSED,
    287 	   long value ATTRIBUTE_UNUSED,
    288 	   unsigned int attrs ATTRIBUTE_UNUSED,
    289 	   bfd_vma pc ATTRIBUTE_UNUSED,
    290 	   int length ATTRIBUTE_UNUSED)
    291 {
    292 }
    293 
    294 /* -- */
    295