Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Functions | Variables
h8500-dis.c File Reference
#include <stdio.h>
#include "sysdep.h"
#include "h8500-opc.h"
#include "dis-asm.h"
#include "opintl.h"
#include <setjmp.h>

Go to the source code of this file.

Classes

struct  private

Defines

#define DISASSEMBLER_TABLE
#define DEFINE_TABLE
#define MAXLEN   8
#define FETCH_DATA(info, addr)

Functions

static int fetch_data (struct disassemble_info *info, bfd_byte *addr)
int print_insn_h8500 (bfd_vma addr, disassemble_info *info)

Variables

static char * crname [] = { "sr", "ccr", "*", "br", "ep", "dp", "*", "tp" }

Class Documentation

struct private

Definition at line 35 of file h8500-dis.c.

Class Members
jmp_buf bailout
bfd_vma insn_start
bfd_byte * max_fetched
bfd_byte the_buffer

Define Documentation

#define DEFINE_TABLE

Definition at line 23 of file h8500-dis.c.

Definition at line 22 of file h8500-dis.c.

#define FETCH_DATA (   info,
  addr 
)
Value:
((addr) <= ((struct private *)(info->private_data))->max_fetched \
   ? 1 : fetch_data ((info), (addr)))

Definition at line 47 of file h8500-dis.c.

#define MAXLEN   8

Definition at line 31 of file h8500-dis.c.


Function Documentation

static int fetch_data ( struct disassemble_info info,
bfd_byte addr 
) [static]

Definition at line 52 of file h8500-dis.c.

{
  int status;
  struct private *priv = (struct private *) info->private_data;
  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);

  status = (*info->read_memory_func) (start,
                                  priv->max_fetched,
                                  addr - priv->max_fetched,
                                  info);
  if (status != 0)
    {
      (*info->memory_error_func) (status, start, info);
      longjmp (priv->bailout, 1);
    }
  else
    priv->max_fetched = addr;
  return 1;
}
int print_insn_h8500 ( bfd_vma  addr,
disassemble_info info 
)

Definition at line 75 of file h8500-dis.c.

{
  const h8500_opcode_info *opcode;
  void *stream = info->stream;
  fprintf_ftype func = info->fprintf_func;
  struct private priv;
  bfd_byte *buffer = priv.the_buffer;

  info->private_data = (PTR) & priv;
  priv.max_fetched = priv.the_buffer;
  priv.insn_start = addr;
  if (setjmp (priv.bailout) != 0)
    /* Error return.  */
    return -1;

  /* Run down the table to find the one which matches.  */
  for (opcode = h8500_table; opcode->name; opcode++)
    {
      int byte;
      int rn = 0;
      int rd = 0;
      int rs = 0;
      int disp = 0;
      int abs = 0;
      int imm = 0;
      int pcrel = 0;
      int qim = 0;
      int i;
      int cr = 0;

      for (byte = 0; byte < opcode->length; byte++)
       {
         FETCH_DATA (info, buffer + byte + 1);
         if ((buffer[byte] & opcode->bytes[byte].mask)
             != (opcode->bytes[byte].contents))
           goto next;

         else
           {
             /* Extract any info parts.  */
             switch (opcode->bytes[byte].insert)
              {
              case 0:
              case FP:
                break;
              default:
                /* xgettext:c-format */
                func (stream, _("can't cope with insert %d\n"),
                     opcode->bytes[byte].insert);
                break;
              case RN:
                rn = buffer[byte] & 0x7;
                break;
              case RS:
                rs = buffer[byte] & 0x7;
                break;
              case CRB:
                cr = buffer[byte] & 0x7;
                if (cr == 0)
                  goto next;
                break;
              case CRW:
                cr = buffer[byte] & 0x7;
                if (cr != 0)
                  goto next;
                break;
              case DISP16:
                FETCH_DATA (info, buffer + byte + 2);
                disp = (buffer[byte] << 8) | (buffer[byte + 1]);
                break;
              case FPIND_D8:
              case DISP8:
                disp = ((char) (buffer[byte]));
                break;
              case RD:
              case RDIND:
                rd = buffer[byte] & 0x7;
                break;
              case ABS24:
                FETCH_DATA (info, buffer + byte + 3);
                abs =
                  (buffer[byte] << 16)
                  | (buffer[byte + 1] << 8)
                  | (buffer[byte + 2]);
                break;
              case ABS16:
                FETCH_DATA (info, buffer + byte + 2);
                abs = (buffer[byte] << 8) | (buffer[byte + 1]);
                break;
              case ABS8:
                abs = (buffer[byte]);
                break;
              case IMM16:
                FETCH_DATA (info, buffer + byte + 2);
                imm = (buffer[byte] << 8) | (buffer[byte + 1]);
                break;
              case IMM4:
                imm = (buffer[byte]) & 0xf;
                break;
              case IMM8:
              case RLIST:
                imm = (buffer[byte]);
                break;
              case PCREL16:
                FETCH_DATA (info, buffer + byte + 2);
                pcrel = (buffer[byte] << 8) | (buffer[byte + 1]);
                break;
              case PCREL8:
                pcrel = (buffer[byte]);
                break;
              case QIM:
                switch (buffer[byte] & 0x7)
                  {
                  case 0:
                    qim = 1;
                    break;
                  case 1:
                    qim = 2;
                    break;
                  case 4:
                    qim = -1;
                    break;
                  case 5:
                    qim = -2;
                    break;
                  }
                break;

              }
           }
       }
      /* We get here when all the masks have passed so we can output
        the operands.  */
      FETCH_DATA (info, buffer + opcode->length);
      (func) (stream, "%s\t", opcode->name);
      for (i = 0; i < opcode->nargs; i++)
       {
         if (i)
           (func) (stream, ",");
         switch (opcode->arg_type[i])
           {
           case FP:
             func (stream, "fp");
             break;
           case RNIND_D16:
             func (stream, "@(0x%x:16,r%d)", disp, rn);
             break;
           case RNIND_D8:
             func (stream, "@(0x%x:8 (%d),r%d)", disp & 0xff, disp, rn);
             break;
           case RDIND_D16:
             func (stream, "@(0x%x:16,r%d)", disp, rd);
             break;
           case RDIND_D8:
             func (stream, "@(0x%x:8 (%d), r%d)", disp & 0xff, disp, rd);
             break;
           case FPIND_D8:
             func (stream, "@(0x%x:8 (%d), fp)", disp & 0xff, disp);
             break;
           case CRB:
           case CRW:
             func (stream, "%s", crname[cr]);
             break;
           case RN:
             func (stream, "r%d", rn);
             break;
           case RD:
             func (stream, "r%d", rd);
             break;
           case RS:
             func (stream, "r%d", rs);
             break;
           case RNDEC:
             func (stream, "@-r%d", rn);
             break;
           case RNINC:
             func (stream, "@r%d+", rn);
             break;
           case RNIND:
             func (stream, "@r%d", rn);
             break;
           case RDIND:
             func (stream, "@r%d", rd);
             break;
           case SPINC:
             func (stream, "@sp+");
             break;
           case SPDEC:
             func (stream, "@-sp");
             break;
           case ABS24:
             func (stream, "@0x%0x:24", abs);
             break;
           case ABS16:
             func (stream, "@0x%0x:16", abs & 0xffff);
             break;
           case ABS8:
             func (stream, "@0x%0x:8", abs & 0xff);
             break;
           case IMM16:
             func (stream, "#0x%0x:16", imm & 0xffff);
             break;
           case RLIST:
             {
              int i;
              int nc = 0;

              func (stream, "(");
              for (i = 0; i < 8; i++)
                {
                  if (imm & (1 << i))
                    {
                     func (stream, "r%d", i);
                     if (nc)
                       func (stream, ",");
                     nc = 1;
                    }
                }
              func (stream, ")");
             }
             break;
           case IMM8:
             func (stream, "#0x%0x:8", imm & 0xff);
             break;
           case PCREL16:
             func (stream, "0x%0x:16",
                  (int)(pcrel + addr + opcode->length) & 0xffff);
             break;
           case PCREL8:
             func (stream, "#0x%0x:8",
                  (int)((char) pcrel + addr + opcode->length) & 0xffff);
             break;
           case QIM:
             func (stream, "#%d:q", qim);
             break;
           case IMM4:
             func (stream, "#%d:4", imm);
             break;
           }
       }
      return opcode->length;
    next:
      ;
    }

  /* Couldn't understand anything.  */
  /* xgettext:c-format */
  func (stream, _("%02x\t\t*unknown*"), buffer[0]);
  return 1;
}

Here is the caller graph for this function:


Variable Documentation

char* crname[] = { "sr", "ccr", "*", "br", "ep", "dp", "*", "tp" } [static]

Definition at line 72 of file h8500-dis.c.