Back to index

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

Go to the source code of this file.

Classes

struct  buffer
struct  tab_elt

Defines

#define TXTSIZ   24

Typedefs

typedef int(* func )(struct buffer *, disassemble_info *, char *)

Functions

static int fetch_data (struct buffer *buf, disassemble_info *info, int n)
static int prt (struct buffer *buf, disassemble_info *info, char *txt)
static int prt_e (struct buffer *buf, disassemble_info *info, char *txt)
static int jr_cc (struct buffer *buf, disassemble_info *info, char *txt)
static int prt_nn (struct buffer *buf, disassemble_info *info, char *txt)
static int prt_rr_nn (struct buffer *buf, disassemble_info *info, char *txt)
static int prt_rr (struct buffer *buf, disassemble_info *info, char *txt)
static int prt_n (struct buffer *buf, disassemble_info *info, char *txt)
static int ld_r_n (struct buffer *buf, disassemble_info *info, char *txt)
static int prt_r (struct buffer *buf, disassemble_info *info, char *txt)
static int ld_r_r (struct buffer *buf, disassemble_info *info, char *txt)
static int arit_r (struct buffer *buf, disassemble_info *info, char *txt)
static int prt_cc (struct buffer *buf, disassemble_info *info, char *txt)
static int pop_rr (struct buffer *buf, disassemble_info *info, char *txt)
static int jp_cc_nn (struct buffer *buf, disassemble_info *info, char *txt)
static int arit_n (struct buffer *buf, disassemble_info *info, char *txt)
static int rst (struct buffer *buf, disassemble_info *info, char *txt)
static int cis (struct buffer *buf, disassemble_info *info, char *txt ATTRIBUTE_UNUSED)
static int dump (struct buffer *buf, disassemble_info *info, char *txt)
static int pref_ed (struct buffer *buf, disassemble_info *info, char *txt ATTRIBUTE_UNUSED)
static int pref_cb (struct buffer *buf, disassemble_info *info, char *txt ATTRIBUTE_UNUSED)
static int addvv (struct buffer *buf, disassemble_info *info, char *txt)
static int ld_v_v (struct buffer *buf, disassemble_info *info, char *txt)
static int prt_d (struct buffer *buf, disassemble_info *info, char *txt)
static int prt_d_n (struct buffer *buf, disassemble_info *info, char *txt)
static int arit_d (struct buffer *buf, disassemble_info *info, char *txt)
static int ld_r_d (struct buffer *buf, disassemble_info *info, char *txt)
static int ld_d_r (struct buffer *buf, disassemble_info *info, char *txt)
static int pref_xd_cb (struct buffer *buf, disassemble_info *info, char *txt)
static int pref_ind (struct buffer *buf, disassemble_info *info, char *txt)
int print_insn_z80 (bfd_vma addr, disassemble_info *info)

Variables

static char * rr_str [] = { "bc", "de", "hl", "sp" }
static char * r_str [] = { "b", "c", "d", "e", "h", "l", "(hl)", "a" }
static char * cc_str [] = { "nz", "z", "nc", "c", "po", "pe", "p", "m" }
static char * arit_str []
static char * cb1_str [] = { "", "bit", "res", "set"}
static char * cb2_str []
static struct tab_elt []

Class Documentation

struct buffer

Definition at line 102 of file chew.c.

Class Members
bfd_vma base
signed char data
int n_fetch
int n_used
char * ptr
unsigned long size
unsigned long write_idx
struct tab_elt

Definition at line 34 of file z80-dis.c.

Collaboration diagram for tab_elt:
Class Members
func fp
unsigned char mask
char * text
unsigned char val

Define Documentation

#define TXTSIZ   24

Definition at line 42 of file z80-dis.c.


Typedef Documentation

typedef int(* func)(struct buffer *, disassemble_info *, char *)

Definition at line 32 of file z80-dis.c.


Function Documentation

static int addvv ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 360 of file z80-dis.c.

{
  info->fprintf_func (info->stream, "add %s,%s", txt, txt);

  return buf->n_used = buf->n_fetch;
}
static int arit_d ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 418 of file z80-dis.c.

{
  char mytxt[TXTSIZ];
  signed char c;

  c = buf->data[buf->n_fetch - 1];
  snprintf (mytxt, TXTSIZ, txt, arit_str[(c >> 3) & 7]);
  return prt_d (buf, info, mytxt);
}

Here is the call graph for this function:

static int arit_n ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 233 of file z80-dis.c.

{
  char mytxt[TXTSIZ];

  snprintf (mytxt,TXTSIZ, txt, arit_str[(buf->data[0] >> 3) & 7]);
  return prt_n (buf, info, mytxt);
}

Here is the call graph for this function:

static int arit_r ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 192 of file z80-dis.c.

{
  info->fprintf_func (info->stream, txt,
                    arit_str[(buf->data[buf->n_fetch - 1] >> 3) & 7],
                    r_str[buf->data[buf->n_fetch - 1] & 7]);
  buf->n_used = buf->n_fetch;
  return buf->n_used;
}
static int cis ( struct buffer buf,
disassemble_info info,
char *txt  ATTRIBUTE_UNUSED 
) [static]

Definition at line 251 of file z80-dis.c.

{
  static char * opar[] = { "ld", "cp", "in", "out" };
  char * op;
  char c;

  c = buf->data[1];
  op = ((0x13 & c) == 0x13) ? "ot" : (opar[c & 3]);
  info->fprintf_func (info->stream,
                    "%s%c%s", op,
                    (c & 0x08) ? 'd' : 'i',
                    (c & 0x10) ? "r" : "");
  buf->n_used = 2;
  return buf->n_used;
}
static int dump ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 268 of file z80-dis.c.

{
  int i;

  info->fprintf_func (info->stream, "defb ");
  for (i = 0; txt[i]; ++i)
    info->fprintf_func (info->stream, i ? ", 0x%02x" : "0x%02x",
                     (unsigned char) buf->data[i]);
  buf->n_used = i;
  return buf->n_used;
}
static int fetch_data ( struct buffer buf,
disassemble_info info,
int  n 
) [static]

Definition at line 56 of file z80-dis.c.

{
  int r;

  if (buf->n_fetch + n > 4)
    abort ();

  r = info->read_memory_func (buf->base + buf->n_fetch,
                           (unsigned char*) buf->data + buf->n_fetch,
                           n, info);
  if (r == 0)
    buf->n_fetch += n;
  return !r;
}

Here is the caller graph for this function:

static int jp_cc_nn ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 223 of file z80-dis.c.

{
  char mytxt[TXTSIZ];

  snprintf (mytxt,TXTSIZ,
           "%s%s,0x%%04x", txt, cc_str[(buf->data[0] >> 3) & 7]);
  return prt_nn (buf, info, mytxt);
}

Here is the call graph for this function:

static int jr_cc ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 99 of file z80-dis.c.

{
  char mytxt[TXTSIZ];

  snprintf (mytxt, TXTSIZ, txt, cc_str[(buf->data[0] >> 3) & 3]);
  return prt_e (buf, info, mytxt);
}

Here is the call graph for this function:

static int ld_d_r ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 440 of file z80-dis.c.

{
  char mytxt[TXTSIZ];
  signed char c;

  c = buf->data[buf->n_fetch - 1];
  snprintf (mytxt, TXTSIZ, txt, r_str[c & 7]);
  return prt_d (buf, info, mytxt);
}

Here is the call graph for this function:

static int ld_r_d ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 429 of file z80-dis.c.

{
  char mytxt[TXTSIZ];
  signed char c;

  c = buf->data[buf->n_fetch - 1];
  snprintf (mytxt, TXTSIZ, txt, r_str[(c >> 3) & 7]);
  return prt_d (buf, info, mytxt);
}

Here is the call graph for this function:

static int ld_r_n ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 164 of file z80-dis.c.

{
  char mytxt[TXTSIZ];

  snprintf (mytxt, TXTSIZ, txt, r_str[(buf->data[0] >> 3) & 7]);
  return prt_n (buf, info, mytxt);
}

Here is the call graph for this function:

static int ld_r_r ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 182 of file z80-dis.c.

{
  info->fprintf_func (info->stream, txt,
                    r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7],
                    r_str[buf->data[buf->n_fetch - 1] & 7]);
  buf->n_used = buf->n_fetch;
  return buf->n_used;
}

Here is the caller graph for this function:

static int ld_v_v ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 368 of file z80-dis.c.

{
  char mytxt[TXTSIZ];

  snprintf (mytxt, TXTSIZ, "ld %s%%s,%s%%s", txt, txt);
  return ld_r_r (buf, info, mytxt);
}

Here is the call graph for this function:

static int pop_rr ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 211 of file z80-dis.c.

{
  static char *rr_stack[] = { "bc","de","hl","af"};

  info->fprintf_func (info->stream, "%s %s", txt,
                    rr_stack[(buf->data[0] >> 4) & 3]);
  buf->n_used = buf->n_fetch;
  return buf->n_used;
}
static int pref_cb ( struct buffer buf,
disassemble_info info,
char *txt  ATTRIBUTE_UNUSED 
) [static]

Definition at line 337 of file z80-dis.c.

{
  if (fetch_data (buf, info, 1))
    {
      buf->n_used = 2;
      if ((buf->data[1] & 0xc0) == 0)
       info->fprintf_func (info->stream, "%s %s",
                         cb2_str[(buf->data[1] >> 3) & 7],
                         r_str[buf->data[1] & 7]);
      else
       info->fprintf_func (info->stream, "%s %d,%s",
                         cb1_str[(buf->data[1] >> 6) & 3],
                         (buf->data[1] >> 3) & 7,
                         r_str[buf->data[1] & 7]);
    }
  else
    buf->n_used = -1;

  return buf->n_used;
}

Here is the call graph for this function:

static int pref_ed ( struct buffer buf,
disassemble_info info,
char *txt  ATTRIBUTE_UNUSED 
) [static]

Definition at line 311 of file z80-dis.c.

{
  struct tab_elt *p;

  if (fetch_data(buf, info, 1))
    {
      for (p = opc_ed; p->val != (buf->data[1] & p->mask); ++p)
       ;
      p->fp (buf, info, p->text);
    }
  else
    buf->n_used = -1;

  return buf->n_used;
}

Here is the call graph for this function:

static int pref_ind ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 521 of file z80-dis.c.

{
  if (fetch_data (buf, info, 1))
    {
      char mytxt[TXTSIZ];
      struct tab_elt *p;

      for (p = opc_ind; p->val != (buf->data[1] & p->mask); ++p)
       ;
      snprintf (mytxt, TXTSIZ, p->text, txt);
      p->fp (buf, info, mytxt);
    }
  else
    buf->n_used = -1;

  return buf->n_used;
}

Here is the call graph for this function:

static int pref_xd_cb ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 451 of file z80-dis.c.

{
  if (fetch_data (buf, info, 2))
    {
      int d;
      char arg[TXTSIZ];
      signed char *p;

      buf->n_used = 4;
      p = buf->data;
      d = p[2];

      if (((p[3] & 0xC0) == 0x40) || ((p[3] & 7) == 0x06))
       snprintf (arg, TXTSIZ, "(%s%+d)", txt, d);
      else
       snprintf (arg, TXTSIZ, "(%s%+d),%s", txt, d, r_str[p[3] & 7]);

      if ((p[3] & 0xc0) == 0)
       info->fprintf_func (info->stream, "%s %s",
                         cb2_str[(buf->data[3] >> 3) & 7],
                         arg);
      else
       info->fprintf_func (info->stream, "%s %d,%s",
                         cb1_str[(buf->data[3] >> 6) & 3],
                         (buf->data[3] >> 3) & 7,
                         arg);
    }
  else
    buf->n_used = -1;

  return buf->n_used;
}

Here is the call graph for this function:

int print_insn_z80 ( bfd_vma  addr,
disassemble_info info 
)

Definition at line 603 of file z80-dis.c.

{
  struct buffer buf;
  struct tab_elt *p;

  buf.base = addr;
  buf.n_fetch = 0;
  buf.n_used = 0;

  if (! fetch_data (& buf, info, 1))
    return -1;

  for (p = opc_main; p->val != (buf.data[0] & p->mask); ++p)
    ;
  p->fp (& buf, info, p->text);

  return buf.n_used;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int prt ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

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

{
  info->fprintf_func (info->stream, "%s", txt);
  buf->n_used = buf->n_fetch;
  return 1;
}
static int prt_cc ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 202 of file z80-dis.c.

{
  info->fprintf_func (info->stream, "%s%s", txt,
                    cc_str[(buf->data[0] >> 3) & 7]);
  buf->n_used = buf->n_fetch;
  return buf->n_used;
}
static int prt_d ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 377 of file z80-dis.c.

{
  int d;
  signed char *p;

  p = buf->data + buf->n_fetch;

  if (fetch_data (buf, info, 1))
    {
      d = p[0];
      info->fprintf_func (info->stream, txt, d);
      buf->n_used = buf->n_fetch;
    }
  else
    buf->n_used = -1;

  return buf->n_used;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int prt_d_n ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 397 of file z80-dis.c.

{
  char mytxt[TXTSIZ];
  int d;
  signed char *p;

  p = buf->data + buf->n_fetch;

  if (fetch_data (buf, info, 1))
    {
      d = p[0];
      snprintf (mytxt, TXTSIZ, txt, d);
      return prt_n (buf, info, mytxt);
    }
  else
    buf->n_used = -1;

  return buf->n_used;
}

Here is the call graph for this function:

static int prt_e ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 80 of file z80-dis.c.

{
  char e;
  int target_addr;

  if (fetch_data (buf, info, 1))
    {
      e = buf->data[1];
      target_addr = (buf->base + 2 + e) & 0xffff;
      buf->n_used = buf->n_fetch;
      info->fprintf_func (info->stream, "%s0x%04x", txt, target_addr);
    }
  else
    buf->n_used = -1;

  return buf->n_used;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int prt_n ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 144 of file z80-dis.c.

{
  int n;
  unsigned char *p;

  p = (unsigned char*) buf->data + buf->n_fetch;

  if (fetch_data (buf, info, 1))
    {
      n = p[0];
      info->fprintf_func (info->stream, txt, n);
      buf->n_used = buf->n_fetch;
    }
  else
    buf->n_used = -1;

  return buf->n_used;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int prt_nn ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 108 of file z80-dis.c.

{
  int nn;
  unsigned char *p;

  p = (unsigned char*) buf->data + buf->n_fetch;
  if (fetch_data (buf, info, 2))
    {
      nn = p[0] + (p[1] << 8);
      info->fprintf_func (info->stream, txt, nn);
      buf->n_used = buf->n_fetch;
    }
  else
    buf->n_used = -1;
  return buf->n_used;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int prt_r ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 173 of file z80-dis.c.

{
  info->fprintf_func (info->stream, txt,
                    r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7]);
  buf->n_used = buf->n_fetch;
  return buf->n_used;
}
static int prt_rr ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 135 of file z80-dis.c.

{
  info->fprintf_func (info->stream, "%s%s", txt,
                    rr_str[(buf->data[buf->n_fetch - 1] >> 4) & 3]);
  buf->n_used = buf->n_fetch;
  return buf->n_used;
}
static int prt_rr_nn ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 126 of file z80-dis.c.

{
  char mytxt[TXTSIZ];

  snprintf (mytxt, TXTSIZ, txt, rr_str[(buf->data[0] >> 4) & 3]);
  return prt_nn (buf, info, mytxt);
}

Here is the call graph for this function:

static int rst ( struct buffer buf,
disassemble_info info,
char *  txt 
) [static]

Definition at line 242 of file z80-dis.c.

{
  info->fprintf_func (info->stream, txt, buf->data[0] & 0x38);
  buf->n_used = buf->n_fetch;
  return buf->n_used;
}

Variable Documentation

char* arit_str[] [static]
Initial value:
{
  "add a,", "adc a,", "sub ", "sbc a,", "and ", "xor ", "or ", "cp "
}

Definition at line 50 of file z80-dis.c.

char* cb1_str[] = { "", "bit", "res", "set"} [static]

Definition at line 329 of file z80-dis.c.

char* cb2_str[] [static]
Initial value:
{
  "rlc", "rrc", "rl", "rr", "sla", "sra", "sli", "srl"
}

Definition at line 331 of file z80-dis.c.

char* cc_str[] = { "nz", "z", "nc", "c", "po", "pe", "p", "m" } [static]

Definition at line 48 of file z80-dis.c.

char* r_str[] = { "b", "c", "d", "e", "h", "l", "(hl)", "a" } [static]

Definition at line 46 of file z80-dis.c.

char* rr_str[] = { "bc", "de", "hl", "sp" } [static]

Definition at line 44 of file z80-dis.c.

static struct tab_elt [static]

Definition at line 485 of file z80-dis.c.