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/d10v-dis.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* Disassemble D10V instructions.
    2    Copyright 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
     2   Copyright 1996, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
    33
    44This program is free software; you can redistribute it and/or modify
     
    1616Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    1717
    18 
    1918#include <stdio.h>
    2019
    2120#include "sysdep.h"
    22 #include "opcode/d10v.h" 
     21#include "opcode/d10v.h"
    2322#include "dis-asm.h"
    2423
    25 /* the PC wraps at 18 bits, except for the segment number */
    26 /* so use this mask to keep the parts we want */
     24/* The PC wraps at 18 bits, except for the segment number,
     25   so use this mask to keep the parts we want. */
    2726#define PC_MASK 0x0303FFFF
    2827
    29 static void dis_2_short PARAMS ((unsigned long insn, bfd_vma memaddr, 
     28static void dis_2_short PARAMS ((unsigned long insn, bfd_vma memaddr,
    3029                                 struct disassemble_info *info, int order));
    31 static void dis_long PARAMS ((unsigned long insn, bfd_vma memaddr, 
     30static void dis_long PARAMS ((unsigned long insn, bfd_vma memaddr,
    3231                              struct disassemble_info *info));
    33 
    34 int
     32static void print_operand
     33  PARAMS ((struct d10v_operand *, long unsigned int, struct d10v_opcode *,
     34           bfd_vma, struct disassemble_info *));
     35
     36int
    3537print_insn_d10v (memaddr, info)
    3638     bfd_vma memaddr;
     
    5052
    5153  status = insn & FM11;
    52   switch (status) {
    53   case 0:
    54     dis_2_short (insn, memaddr, info, 2);
    55     break;
    56   case FM01:
    57     dis_2_short (insn, memaddr, info, 0);
    58     break;
    59   case FM10:
    60     dis_2_short (insn, memaddr, info, 1);
    61     break;
    62   case FM11:
    63     dis_long (insn, memaddr, info);
    64     break;
    65   }
     54  switch (status)
     55    {
     56    case 0:
     57      dis_2_short (insn, memaddr, info, 2);
     58      break;
     59    case FM01:
     60      dis_2_short (insn, memaddr, info, 0);
     61      break;
     62    case FM10:
     63      dis_2_short (insn, memaddr, info, 1);
     64      break;
     65    case FM11:
     66      dis_long (insn, memaddr, info);
     67      break;
     68    }
    6669  return 4;
    6770}
     
    7982  if (oper->flags == OPERAND_ATMINUS)
    8083    {
    81       (*info->fprintf_func) (info->stream, "@-");   
     84      (*info->fprintf_func) (info->stream, "@-");
    8285      return;
    8386    }
    8487  if (oper->flags == OPERAND_MINUS)
    8588    {
    86       (*info->fprintf_func) (info->stream, "-");   
     89      (*info->fprintf_func) (info->stream, "-");
    8790      return;
    8891    }
    8992  if (oper->flags == OPERAND_PLUS)
    9093    {
    91       (*info->fprintf_func) (info->stream, "+");   
     94      (*info->fprintf_func) (info->stream, "+");
    9295      return;
    9396    }
    9497  if (oper->flags == OPERAND_ATSIGN)
    9598    {
    96       (*info->fprintf_func) (info->stream, "@");   
     99      (*info->fprintf_func) (info->stream, "@");
    97100      return;
    98101    }
    99102  if (oper->flags == OPERAND_ATPAR)
    100103    {
    101       (*info->fprintf_func) (info->stream, "@(");   
     104      (*info->fprintf_func) (info->stream, "@(");
    102105      return;
    103106    }
     
    105108  shift = oper->shift;
    106109
    107   /* the LONG_L format shifts registers over by 15 */
     110  /* The LONG_L format shifts registers over by 15. */
    108111  if (op->format == LONG_L && (oper->flags & OPERAND_REG))
    109112    shift += 15;
     
    114117    {
    115118      int i;
    116       int match=0;
     119      int match = 0;
    117120      num += (oper->flags
    118               & (OPERAND_GPR|OPERAND_FFLAG|OPERAND_CFLAG|OPERAND_CONTROL));
    119       if (oper->flags & (OPERAND_ACC0|OPERAND_ACC1))
     121              & (OPERAND_GPR | OPERAND_FFLAG | OPERAND_CFLAG | OPERAND_CONTROL));
     122      if (oper->flags & (OPERAND_ACC0 | OPERAND_ACC1))
    120123        num += num ? OPERAND_ACC1 : OPERAND_ACC0;
    121       for (i = 0; i < d10v_reg_name_cnt(); i++)
    122         {
    123           if (num == d10v_predefined_registers[i].value)
     124      for (i = 0; i < d10v_reg_name_cnt (); i++)
     125        {
     126          if (num == (d10v_predefined_registers[i].value & ~ OPERAND_SP))
    124127            {
    125128              if (d10v_predefined_registers[i].pname)
    126                 (*info->fprintf_func) (info->stream, "%s",d10v_predefined_registers[i].pname);
     129                (*info->fprintf_func) (info->stream, "%s",
     130                                       d10v_predefined_registers[i].pname);
    127131              else
    128                 (*info->fprintf_func) (info->stream, "%s",d10v_predefined_registers[i].name);
    129               match=1;
     132                (*info->fprintf_func) (info->stream, "%s",
     133                                       d10v_predefined_registers[i].name);
     134              match = 1;
    130135              break;
    131136            }
     
    133138      if (match == 0)
    134139        {
    135           /* this would only get executed if a register was not in the
    136              register table */
    137           if (oper->flags & (OPERAND_ACC0|OPERAND_ACC1))
     140          /* This would only get executed if a register was not in the
     141             register table. */
     142          if (oper->flags & (OPERAND_ACC0 | OPERAND_ACC1))
    138143            (*info->fprintf_func) (info->stream, "a");
    139144          else if (oper->flags & OPERAND_CONTROL)
    140145            (*info->fprintf_func) (info->stream, "cr");
    141           else if(oper->flags & OPERAND_REG)
     146          else if (oper->flags & OPERAND_REG)
    142147            (*info->fprintf_func) (info->stream, "r");
    143           (*info->fprintf_func) (info->stream, "%d",num);
     148          (*info->fprintf_func) (info->stream, "%d", num & REGISTER_MASK);
    144149        }
    145150    }
    146151  else
    147152    {
    148       /* addresses are right-shifted by 2 */
     153      /* Addresses are right-shifted by 2. */
    149154      if (oper->flags & OPERAND_ADDR)
    150155        {
    151156          long max;
    152           int neg=0;
     157          int neg = 0;
    153158          max = (1 << (oper->bits - 1));
    154159          if (num & max)
    155160            {
    156               num = -num & ((1 << oper->bits)-1);
     161              num = -num & ((1 << oper->bits) - 1);
    157162              neg = 1;
    158163            }
    159           num = num<<2;
     164          num = num << 2;
    160165          if (info->flags & INSN_HAS_RELOC)
    161166            (*info->print_address_func) (num & PC_MASK, info);
     
    175180              if (num & max)
    176181                {
    177                   num = -num & ((1 << oper->bits)-1);
     182                  num = -num & ((1 << oper->bits) - 1);
    178183                  (*info->fprintf_func) (info->stream, "-");
    179184                }
    180185            }
    181           (*info->fprintf_func) (info->stream, "0x%x",num);
     186          (*info->fprintf_func) (info->stream, "0x%x", num);
    182187        }
    183188    }
    184189}
    185 
    186190
    187191static void
     
    192196{
    193197  int i;
    194   char buf[32];
    195   struct d10v_opcode *op = (struct d10v_opcode *)d10v_opcodes;
     198  struct d10v_opcode *op = (struct d10v_opcode *) d10v_opcodes;
    196199  struct d10v_operand *oper;
    197200  int need_paren = 0;
     
    200203  while (op->name)
    201204    {
    202       if ((op->format & LONG_OPCODE) && ((op->mask & insn) == op->opcode))
     205      if ((op->format & LONG_OPCODE) && ((op->mask & insn) == (unsigned long) op->opcode))
    203206        {
    204207          match = 1;
    205           (*info->fprintf_func) (info->stream, "%s\t", op->name);   
    206           for ( i=0; op->operands[i]; i++)
    207             {
    208               oper = (struct d10v_operand *)&d10v_operands[op->operands[i]];
     208          (*info->fprintf_func) (info->stream, "%s\t", op->name);
     209          for (i = 0; op->operands[i]; i++)
     210            {
     211              oper = (struct d10v_operand *) &d10v_operands[op->operands[i]];
    209212              if (oper->flags == OPERAND_ATPAR)
    210213                need_paren = 1;
    211214              print_operand (oper, insn, op, memaddr, info);
    212               if (op->operands[i+1] && oper->bits &&
    213                   d10v_operands[op->operands[i+1]].flags != OPERAND_PLUS &&
    214                   d10v_operands[op->operands[i+1]].flags != OPERAND_MINUS)
    215                 (*info->fprintf_func) (info->stream, ", ");   
     215              if (op->operands[i + 1] && oper->bits
     216                  && d10v_operands[op->operands[i + 1]].flags != OPERAND_PLUS
     217                  && d10v_operands[op->operands[i + 1]].flags != OPERAND_MINUS)
     218                (*info->fprintf_func) (info->stream, ", ");
    216219            }
    217220          break;
     
    221224
    222225  if (!match)
    223     (*info->fprintf_func) (info->stream, ".long\t0x%08x",insn);   
     226    (*info->fprintf_func) (info->stream, ".long\t0x%08x", insn);
    224227
    225228  if (need_paren)
    226     (*info->fprintf_func) (info->stream, ")");   
     229    (*info->fprintf_func) (info->stream, ")");
    227230}
    228231
     
    234237     int order;
    235238{
    236   int i,j;
    237   char astr[2][32];
     239  int i, j;
    238240  unsigned int ins[2];
    239241  struct d10v_opcode *op;
    240   char buf[32];
    241   int match, num_match=0;
     242  int match, num_match = 0;
    242243  struct d10v_operand *oper;
    243244  int need_paren = 0;
     
    246247  ins[1] = insn & 0x00007FFF;
    247248
    248   for(j=0;j<2;j++)
    249     {
    250       op = (struct d10v_opcode *)d10v_opcodes;
    251       match=0;
     249  for (j = 0; j < 2; j++)
     250    {
     251      op = (struct d10v_opcode *) d10v_opcodes;
     252      match = 0;
    252253      while (op->name)
    253254        {
    254           if ((op->format & SHORT_OPCODE) && ((op->mask & ins[j]) == op->opcode))
    255             {
    256               (*info->fprintf_func) (info->stream, "%s\t",op->name);   
    257               for (i=0; op->operands[i]; i++)
     255          if ((op->format & SHORT_OPCODE)
     256              && ((op->mask & ins[j]) == (unsigned long) op->opcode))
     257            {
     258              (*info->fprintf_func) (info->stream, "%s\t", op->name);
     259              for (i = 0; op->operands[i]; i++)
    258260                {
    259                   oper = (struct d10v_operand *)&d10v_operands[op->operands[i]];
     261                  oper = (struct d10v_operand *) &d10v_operands[op->operands[i]];
    260262                  if (oper->flags == OPERAND_ATPAR)
    261263                    need_paren = 1;
    262264                  print_operand (oper, ins[j], op, memaddr, info);
    263                   if (op->operands[i+1] && oper->bits &&
    264                   d10v_operands[op->operands[i+1]].flags != OPERAND_PLUS &&
    265                   d10v_operands[op->operands[i+1]].flags != OPERAND_MINUS)
    266                     (*info->fprintf_func) (info->stream, ", ");   
     265                  if (op->operands[i + 1] && oper->bits
     266                      && d10v_operands[op->operands[i + 1]].flags != OPERAND_PLUS
     267                      && d10v_operands[op->operands[i + 1]].flags != OPERAND_MINUS)
     268                    (*info->fprintf_func) (info->stream, ", ");
    267269                }
    268270              match = 1;
     
    273275        }
    274276      if (!match)
    275         (*info->fprintf_func) (info->stream, "unknown");   
     277        (*info->fprintf_func) (info->stream, "unknown");
    276278
    277279      switch (order)
    278280        {
    279281        case 0:
    280           (*info->fprintf_func) (info->stream, "\t->\t");   
     282          (*info->fprintf_func) (info->stream, "\t->\t");
    281283          order = -1;
    282284          break;
    283285        case 1:
    284           (*info->fprintf_func) (info->stream, "\t<-\t");   
     286          (*info->fprintf_func) (info->stream, "\t<-\t");
    285287          order = -1;
    286288          break;
    287289        case 2:
    288           (*info->fprintf_func) (info->stream, "\t||\t");   
     290          (*info->fprintf_func) (info->stream, "\t||\t");
    289291          order = -1;
    290292          break;
     
    295297
    296298  if (num_match == 0)
    297     (*info->fprintf_func) (info->stream, ".long\t0x%08x",insn);   
     299    (*info->fprintf_func) (info->stream, ".long\t0x%08x", insn);
    298300
    299301  if (need_paren)
    300     (*info->fprintf_func) (info->stream, ")");   
     302    (*info->fprintf_func) (info->stream, ")");
    301303}
Note: See TracChangeset for help on using the changeset viewer.