Back to index

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

Go to the source code of this file.

Classes

struct  instr_data_s

Defines

#define DEFINE_TABLE
#define FETCH_DATA(info, nibble)

Functions

static int fetch_data (struct disassemble_info *info, int nibble)
int z8k_lookup_instr (unsigned char *, disassemble_info *)
static void output_instr (instr_data_s *, unsigned long, disassemble_info *)
static void unpack_instr (instr_data_s *, int, disassemble_info *)
static void unparse_instr (instr_data_s *, int)
static int print_insn_z8k (bfd_vma addr, disassemble_info *info, int is_segmented)
int print_insn_z8001 (bfd_vma addr, disassemble_info *info)
int print_insn_z8002 (bfd_vma addr, disassemble_info *info)
static void output_instr (instr_data_s *instr_data, unsigned long addr ATTRIBUTE_UNUSED, disassemble_info *info)
static void print_intr (char *tmp_str, unsigned long interrupts)
static void print_flags (char *tmp_str, unsigned long flags)

Variables

static char * codes [16]
static char * ctrl_names [8]
static int seg_length

Class Documentation

struct instr_data_s

Definition at line 30 of file z8k-dis.c.

Class Members
unsigned long address
unsigned long arg_reg
jmp_buf bailout
unsigned char bytes
unsigned long cond_code
unsigned long ctrl_code
unsigned long displacement
unsigned long flags
unsigned long immediate
bfd_vma insn_start
char instr_asmsrc
unsigned long interrupts
int max_fetched
unsigned char nibbles
int tabl_index
unsigned short words

Define Documentation

#define DEFINE_TABLE

Definition at line 25 of file z8k-dis.c.

#define FETCH_DATA (   info,
  nibble 
)
Value:
((nibble) < ((instr_data_s *) (info->private_data))->max_fetched \
   ? 1 : fetch_data ((info), (nibble)))

Definition at line 59 of file z8k-dis.c.


Function Documentation

static int fetch_data ( struct disassemble_info info,
int  nibble 
) [static]

Definition at line 64 of file z8k-dis.c.

{
  unsigned char mybuf[20];
  int status;
  instr_data_s *priv = (instr_data_s *) info->private_data;

  if ((nibble % 4) != 0)
    abort ();

  status = (*info->read_memory_func) (priv->insn_start,
                                  (bfd_byte *) mybuf,
                                  nibble / 2,
                                  info);
  if (status != 0)
    {
      (*info->memory_error_func) (status, priv->insn_start, info);
      longjmp (priv->bailout, 1);
    }

  {
    int i;
    unsigned char *p = mybuf;

    for (i = 0; i < nibble;)
      {
       priv->words[i] = (p[0] << 8) | p[1];

       priv->bytes[i] = *p;
       priv->nibbles[i++] = *p >> 4;
       priv->nibbles[i++] = *p & 0xf;

       ++p;
       priv->bytes[i] = *p;
       priv->nibbles[i++] = *p >> 4;
       priv->nibbles[i++] = *p & 0xf;

       ++p;
      }
  }
  priv->max_fetched = nibble;
  return 1;
}

Here is the call graph for this function:

static void output_instr ( instr_data_s ,
unsigned  long,
disassemble_info  
) [static]

Here is the caller graph for this function:

static void output_instr ( instr_data_s instr_data,
unsigned long addr  ATTRIBUTE_UNUSED,
disassemble_info info 
) [static]

Definition at line 281 of file z8k-dis.c.

{
  int num_bytes;
  char out_str[100];

  out_str[0] = 0;

  num_bytes = (z8k_table[instr_data->tabl_index].length + seg_length) * 2;
  FETCH_DATA (info, num_bytes);

  strcat (out_str, instr_data->instr_asmsrc);

  (*info->fprintf_func) (info->stream, "%s", out_str);
}
static void print_flags ( char *  tmp_str,
unsigned long  flags 
) [static]

Definition at line 494 of file z8k-dis.c.

{
  int comma = 0;

  *tmp_str = 0;
  if (flags & 8)
    {
      strcat (tmp_str, "c");
      comma = 1;
    }
  if (flags & 4)
    {
      if (comma) strcat (tmp_str, ",");
      strcat (tmp_str, "z");
      comma = 1;
    }
  if (flags & 2)
    {
      if (comma) strcat (tmp_str, ",");
      strcat (tmp_str, "s");
      comma = 1;
    }
  if (flags & 1)
    {
      if (comma) strcat (tmp_str, ",");
      strcat (tmp_str, "p");
    }
}

Here is the caller graph for this function:

int print_insn_z8001 ( bfd_vma  addr,
disassemble_info info 
)

Definition at line 179 of file z8k-dis.c.

{
  return print_insn_z8k (addr, info, 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int print_insn_z8002 ( bfd_vma  addr,
disassemble_info info 
)

Definition at line 185 of file z8k-dis.c.

{
  return print_insn_z8k (addr, info, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int print_insn_z8k ( bfd_vma  addr,
disassemble_info info,
int  is_segmented 
) [static]

Definition at line 146 of file z8k-dis.c.

{
  instr_data_s instr_data;

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

  info->bytes_per_chunk = 2;
  info->bytes_per_line = 6;
  info->display_endian = BFD_ENDIAN_BIG;

  instr_data.tabl_index = z8k_lookup_instr (instr_data.nibbles, info);
  if (instr_data.tabl_index >= 0)
    {
      unpack_instr (&instr_data, is_segmented, info);
      unparse_instr (&instr_data, is_segmented);
      output_instr (&instr_data, addr, info);
      return z8k_table[instr_data.tabl_index].length + seg_length;
    }
  else
    {
      FETCH_DATA (info, 4);
      (*info->fprintf_func) (info->stream, ".word %02x%02x",
                          instr_data.bytes[0], instr_data.bytes[2]);
      return 2;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void print_intr ( char *  tmp_str,
unsigned long  interrupts 
) [static]

Definition at line 476 of file z8k-dis.c.

{
  int comma = 0;

  *tmp_str = 0;
  if (! (interrupts & 2))
    {
      strcat (tmp_str, "vi");
      comma = 1;
    }
  if (! (interrupts & 1))
    {
      if (comma) strcat (tmp_str, ",");
      strcat (tmp_str, "nvi");
    }
}

Here is the caller graph for this function:

static void unpack_instr ( instr_data_s instr_data,
int  is_segmented,
disassemble_info info 
) [static]

Definition at line 299 of file z8k-dis.c.

{
  int nibl_count, loop;
  unsigned short instr_nibl, instr_byte, instr_word;
  long instr_long;
  unsigned int tabl_datum, datum_class;
  unsigned short datum_value;

  nibl_count = 0;
  loop = 0;
  seg_length = 0;

  while (z8k_table[instr_data->tabl_index].byte_info[loop] != 0)
    {
      FETCH_DATA (info, nibl_count + 4 - (nibl_count % 4));
      instr_nibl = instr_data->nibbles[nibl_count];
      instr_byte = instr_data->bytes[nibl_count & ~1];
      instr_word = instr_data->words[nibl_count & ~3];

      tabl_datum = z8k_table[instr_data->tabl_index].byte_info[loop];
      datum_class = tabl_datum & CLASS_MASK;
      datum_value = tabl_datum & ~CLASS_MASK;

      switch (datum_class)
       {
       case CLASS_DISP:
         switch (datum_value)
           {
           case ARG_DISP16:
             instr_data->displacement = instr_data->insn_start + 4
              + (signed short) (instr_word & 0xffff);
             nibl_count += 3;
             break;
           case ARG_DISP12:
             if (instr_word & 0x800)
              /* Negative 12 bit displacement.  */
              instr_data->displacement = instr_data->insn_start + 2
                - (signed short) ((instr_word & 0xfff) | 0xf000) * 2;
             else
              instr_data->displacement = instr_data->insn_start + 2
                - (instr_word & 0x0fff) * 2;

             nibl_count += 2;
             break;
           default:
             break;
           }
         break;
       case CLASS_IMM:
         switch (datum_value)
           {
           case ARG_IMM4:
             instr_data->immediate = instr_nibl;
             break;
           case ARG_NIM4:
             instr_data->immediate = (- instr_nibl) & 0xf;
             break;
           case ARG_NIM8:
             instr_data->immediate = (- instr_byte) & 0xff;
             nibl_count += 1;
             break;
           case ARG_IMM8:
             instr_data->immediate = instr_byte;
             nibl_count += 1;
             break;
           case ARG_IMM16:
             instr_data->immediate = instr_word;
             nibl_count += 3;
             break;
           case ARG_IMM32:
             FETCH_DATA (info, nibl_count + 8);
             instr_long = (instr_data->words[nibl_count] << 16)
              | (instr_data->words[nibl_count + 4]);
             instr_data->immediate = instr_long;
             nibl_count += 7;
             break;
           case ARG_IMMN:
             instr_data->immediate = instr_nibl - 1;
             break;
           case ARG_IMM4M1:
             instr_data->immediate = instr_nibl + 1;
             break;
           case ARG_IMM_1:
             instr_data->immediate = 1;
             break;
           case ARG_IMM_2:
             instr_data->immediate = 2;
             break;
           case ARG_IMM2:
             instr_data->immediate = instr_nibl & 0x3;
             break;
           default:
             break;
           }
         break;
       case CLASS_CC:
         instr_data->cond_code = instr_nibl;
         break;
       case CLASS_ADDRESS:
         if (is_segmented)
           {
             if (instr_nibl & 0x8)
              {
                FETCH_DATA (info, nibl_count + 8);
                instr_long = (instr_data->words[nibl_count] << 16)
                  | (instr_data->words[nibl_count + 4]);
                instr_data->address = ((instr_word & 0x7f00) << 16)
                  + (instr_long & 0xffff);
                nibl_count += 7;
                seg_length = 2;
              }
             else
              {
                instr_data->address = ((instr_word & 0x7f00) << 16)
                  + (instr_word & 0x00ff);
                nibl_count += 3;
              }
           }
         else
           {
             instr_data->address = instr_word;
             nibl_count += 3;
           }
         break;
       case CLASS_0CCC:
       case CLASS_1CCC:
         instr_data->ctrl_code = instr_nibl & 0x7;
         break;
       case CLASS_0DISP7:
         instr_data->displacement =
           instr_data->insn_start + 2 - (instr_byte & 0x7f) * 2;
         nibl_count += 1;
         break;
       case CLASS_1DISP7:
         instr_data->displacement =
           instr_data->insn_start + 2 - (instr_byte & 0x7f) * 2;
         nibl_count += 1;
         break;
       case CLASS_01II:
         instr_data->interrupts = instr_nibl & 0x3;
         break;
       case CLASS_00II:
         instr_data->interrupts = instr_nibl & 0x3;
         break;
       case CLASS_IGNORE:
       case CLASS_BIT:
         instr_data->ctrl_code = instr_nibl & 0x7;
         break;
       case CLASS_FLAGS:
         instr_data->flags = instr_nibl;
         break;
       case CLASS_REG:
         instr_data->arg_reg[datum_value] = instr_nibl;
         break;
       case CLASS_REGN0:
         instr_data->arg_reg[datum_value] = instr_nibl;
         break;
       case CLASS_DISP8:
         instr_data->displacement =
           instr_data->insn_start + 2 + (signed char) instr_byte * 2;
         nibl_count += 1;
         break;
        case CLASS_BIT_1OR2:
          instr_data->immediate = ((instr_nibl >> 1) & 0x1) + 1;
          nibl_count += 1;
         break;
       default:
         abort ();
         break;
       }

      loop += 1;
      nibl_count += 1;
    }
}

Here is the caller graph for this function:

static void unparse_instr ( instr_data_s instr_data,
int  is_segmented 
) [static]

Definition at line 524 of file z8k-dis.c.

{
  unsigned short datum_value;
  unsigned int tabl_datum, datum_class;
  int loop, loop_limit;
  char out_str[80], tmp_str[25];

  sprintf (out_str, "%s\t", z8k_table[instr_data->tabl_index].name);

  loop_limit = z8k_table[instr_data->tabl_index].noperands;
  for (loop = 0; loop < loop_limit; loop++)
    {
      if (loop)
       strcat (out_str, ",");

      tabl_datum = z8k_table[instr_data->tabl_index].arg_info[loop];
      datum_class = tabl_datum & CLASS_MASK;
      datum_value = tabl_datum & ~CLASS_MASK;

      switch (datum_class)
       {
       case CLASS_X:
          sprintf (tmp_str, "0x%0lx(r%ld)", instr_data->address,
                   instr_data->arg_reg[datum_value]);
         strcat (out_str, tmp_str);
         break;
       case CLASS_BA:
          if (is_segmented)
            sprintf (tmp_str, "rr%ld(#0x%lx)", instr_data->arg_reg[datum_value],
                     instr_data->immediate);
          else
            sprintf (tmp_str, "r%ld(#0x%lx)", instr_data->arg_reg[datum_value],
                     instr_data->immediate);
         strcat (out_str, tmp_str);
         break;
       case CLASS_BX:
          if (is_segmented)
            sprintf (tmp_str, "rr%ld(r%ld)", instr_data->arg_reg[datum_value],
                     instr_data->arg_reg[ARG_RX]);
          else
            sprintf (tmp_str, "r%ld(r%ld)", instr_data->arg_reg[datum_value],
                     instr_data->arg_reg[ARG_RX]);
         strcat (out_str, tmp_str);
         break;
       case CLASS_DISP:
         sprintf (tmp_str, "0x%0lx", instr_data->displacement);
         strcat (out_str, tmp_str);
         break;
       case CLASS_IMM:
         if (datum_value == ARG_IMM2)     /* True with EI/DI instructions only.  */
           {
             print_intr (tmp_str, instr_data->interrupts);
             strcat (out_str, tmp_str);
             break;
           }
         sprintf (tmp_str, "#0x%0lx", instr_data->immediate);
         strcat (out_str, tmp_str);
         break;
       case CLASS_CC:
         sprintf (tmp_str, "%s", codes[instr_data->cond_code]);
         strcat (out_str, tmp_str);
         break;
       case CLASS_CTRL:
         sprintf (tmp_str, "%s", ctrl_names[instr_data->ctrl_code]);
         strcat (out_str, tmp_str);
         break;
       case CLASS_DA:
       case CLASS_ADDRESS:
         sprintf (tmp_str, "0x%0lx", instr_data->address);
         strcat (out_str, tmp_str);
         break;
       case CLASS_IR:
         if (is_segmented)
           sprintf (tmp_str, "@rr%ld", instr_data->arg_reg[datum_value]);
         else
           sprintf (tmp_str, "@r%ld", instr_data->arg_reg[datum_value]);
         strcat (out_str, tmp_str);
         break;
       case CLASS_IRO:
          sprintf (tmp_str, "@r%ld", instr_data->arg_reg[datum_value]);
         strcat (out_str, tmp_str);
         break;
       case CLASS_FLAGS:
         print_flags(tmp_str, instr_data->flags);
         strcat (out_str, tmp_str);
         break;
       case CLASS_REG_BYTE:
         if (instr_data->arg_reg[datum_value] >= 0x8)
           sprintf (tmp_str, "rl%ld",
                   instr_data->arg_reg[datum_value] - 0x8);
         else
           sprintf (tmp_str, "rh%ld", instr_data->arg_reg[datum_value]);
         strcat (out_str, tmp_str);
         break;
       case CLASS_REG_WORD:
         sprintf (tmp_str, "r%ld", instr_data->arg_reg[datum_value]);
         strcat (out_str, tmp_str);
         break;
       case CLASS_REG_QUAD:
         sprintf (tmp_str, "rq%ld", instr_data->arg_reg[datum_value]);
         strcat (out_str, tmp_str);
         break;
       case CLASS_REG_LONG:
         sprintf (tmp_str, "rr%ld", instr_data->arg_reg[datum_value]);
         strcat (out_str, tmp_str);
         break;
       case CLASS_PR:
         if (is_segmented)
           sprintf (tmp_str, "rr%ld", instr_data->arg_reg[datum_value]);
         else
           sprintf (tmp_str, "r%ld", instr_data->arg_reg[datum_value]);
         strcat (out_str, tmp_str);
         break;
       default:
         abort ();
         break;
       }
    }

  strcpy (instr_data->instr_asmsrc, out_str);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int z8k_lookup_instr ( unsigned char *  nibbles,
disassemble_info info 
)

Definition at line 191 of file z8k-dis.c.

{
  int nibl_index, tabl_index;
  int nibl_matched;
  int need_fetch = 0;
  unsigned short instr_nibl;
  unsigned short tabl_datum, datum_class, datum_value;

  nibl_matched = 0;
  tabl_index = 0;
  FETCH_DATA (info, 4);
  while (!nibl_matched && z8k_table[tabl_index].name)
    {
      nibl_matched = 1;
      for (nibl_index = 0;
          nibl_index < z8k_table[tabl_index].length * 2 && nibl_matched;
          nibl_index++)
       {
         if ((nibl_index % 4) == 0)
            {
              /* Fetch data only if it isn't already there.  */
              if (nibl_index >= 4 || (nibl_index < 4 && need_fetch))
                FETCH_DATA (info, nibl_index + 4);   /* Fetch one word at a time.  */
              if (nibl_index < 4)
                need_fetch = 0;
              else
                need_fetch = 1;
            }
         instr_nibl = nibbles[nibl_index];

         tabl_datum = z8k_table[tabl_index].byte_info[nibl_index];
         datum_class = tabl_datum & CLASS_MASK;
         datum_value = ~CLASS_MASK & tabl_datum;

         switch (datum_class)
           {
           case CLASS_BIT:
             if (datum_value != instr_nibl)
              nibl_matched = 0;
             break;
           case CLASS_IGNORE:
             break;
           case CLASS_00II:
             if (!((~instr_nibl) & 0x4))
              nibl_matched = 0;
             break;
           case CLASS_01II:
             if (!(instr_nibl & 0x4))
              nibl_matched = 0;
             break;
           case CLASS_0CCC:
             if (!((~instr_nibl) & 0x8))
              nibl_matched = 0;
             break;
           case CLASS_1CCC:
             if (!(instr_nibl & 0x8))
              nibl_matched = 0;
             break;
           case CLASS_0DISP7:
             if (!((~instr_nibl) & 0x8))
              nibl_matched = 0;
             nibl_index += 1;
             break;
           case CLASS_1DISP7:
             if (!(instr_nibl & 0x8))
              nibl_matched = 0;
             nibl_index += 1;
             break;
           case CLASS_REGN0:
             if (instr_nibl == 0)
              nibl_matched = 0;
             break;
           case CLASS_BIT_1OR2:
             if ((instr_nibl | 0x2) != (datum_value | 0x2))
              nibl_matched = 0;
             break;
           default:
             break;
           }
       }

      if (nibl_matched)
       return tabl_index;

      tabl_index++;
    }
  return -1;
}

Here is the caller graph for this function:


Variable Documentation

char* codes[16] [static]
Initial value:
  {
    "f",
    "lt",
    "le",
    "ule",
    "ov/pe",
    "mi",
    "eq",
    "c/ult",
    "t",
    "ge",
    "gt",
    "ugt",
    "nov/po",
    "pl",
    "ne",
    "nc/uge"
  }

Definition at line 107 of file z8k-dis.c.

char* ctrl_names[8] [static]
Initial value:
  {
    "<invld>",
    "flags",
    "fcw",
    "refresh",
    "psapseg",
    "psapoff",
    "nspseg",
    "nspoff"
  }

Definition at line 127 of file z8k-dis.c.

int seg_length [static]

Definition at line 139 of file z8k-dis.c.