OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [opcodes/] [ns32k-dis.c] - Diff between revs 1181 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 1181 Rev 1765
/* Print National Semiconductor 32000 instructions.
/* Print National Semiconductor 32000 instructions.
   Copyright 1986, 1988, 1991, 1992, 1994, 1998, 2001
   Copyright 1986, 1988, 1991, 1992, 1994, 1998, 2001
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
 
 
This file is part of opcodes library.
This file is part of opcodes library.
 
 
This program is free software; you can redistribute it and/or modify
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
(at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 
 
 
#include "bfd.h"
#include "bfd.h"
#include "sysdep.h"
#include "sysdep.h"
#include "dis-asm.h"
#include "dis-asm.h"
#if !defined(const) && !defined(__STDC__)
#if !defined(const) && !defined(__STDC__)
#define const
#define const
#endif
#endif
#include "opcode/ns32k.h"
#include "opcode/ns32k.h"
#include "opintl.h"
#include "opintl.h"
 
 
static disassemble_info *dis_info;
static disassemble_info *dis_info;
 
 
/*
/*
 * Hacks to get it to compile <= READ THESE AS FIXES NEEDED
 * Hacks to get it to compile <= READ THESE AS FIXES NEEDED
 */
 */
#define INVALID_FLOAT(val, size) invalid_float((char *)val, size)
#define INVALID_FLOAT(val, size) invalid_float((char *)val, size)
 
 
static int print_insn_arg
static int print_insn_arg
  PARAMS ((int, int, int *, char *, bfd_vma, char *, int));
  PARAMS ((int, int, int *, char *, bfd_vma, char *, int));
static int get_displacement PARAMS ((char *, int *));
static int get_displacement PARAMS ((char *, int *));
static int invalid_float PARAMS ((char *, int));
static int invalid_float PARAMS ((char *, int));
static long int read_memory_integer PARAMS ((unsigned char *, int));
static long int read_memory_integer PARAMS ((unsigned char *, int));
static int fetch_data PARAMS ((struct disassemble_info *, bfd_byte *));
static int fetch_data PARAMS ((struct disassemble_info *, bfd_byte *));
struct ns32k_option;
struct ns32k_option;
static void optlist PARAMS ((int, const struct ns32k_option *, char *));
static void optlist PARAMS ((int, const struct ns32k_option *, char *));
static void list_search PARAMS ((int, const struct ns32k_option *, char *));
static void list_search PARAMS ((int, const struct ns32k_option *, char *));
static int bit_extract PARAMS ((bfd_byte *, int, int));
static int bit_extract PARAMS ((bfd_byte *, int, int));
static int bit_extract_simple PARAMS ((bfd_byte *, int, int));
static int bit_extract_simple PARAMS ((bfd_byte *, int, int));
static void bit_copy PARAMS ((char *, int, int, char *));
static void bit_copy PARAMS ((char *, int, int, char *));
static int sign_extend PARAMS ((int, int));
static int sign_extend PARAMS ((int, int));
static void flip_bytes PARAMS ((char *, int));
static void flip_bytes PARAMS ((char *, int));
 
 
static long read_memory_integer(addr, nr)
static long read_memory_integer(addr, nr)
     unsigned char *addr;
     unsigned char *addr;
     int nr;
     int nr;
{
{
  long val;
  long val;
  int i;
  int i;
  for (val = 0, i = nr - 1; i >= 0; i--) {
  for (val = 0, i = nr - 1; i >= 0; i--) {
    val =  (val << 8);
    val =  (val << 8);
    val |= (0xff & *(addr + i));
    val |= (0xff & *(addr + i));
  }
  }
  return val;
  return val;
}
}
 
 
/* 32000 instructions are never longer than this.  */
/* 32000 instructions are never longer than this.  */
#define MAXLEN 62
#define MAXLEN 62
 
 
 
 
#include <setjmp.h>
#include <setjmp.h>
 
 
struct private
struct private
{
{
  /* Points to first byte not fetched.  */
  /* Points to first byte not fetched.  */
  bfd_byte *max_fetched;
  bfd_byte *max_fetched;
  bfd_byte the_buffer[MAXLEN];
  bfd_byte the_buffer[MAXLEN];
  bfd_vma insn_start;
  bfd_vma insn_start;
  jmp_buf bailout;
  jmp_buf bailout;
};
};
 
 
 
 
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
   to ADDR (exclusive) are valid.  Returns 1 for success, longjmps
   to ADDR (exclusive) are valid.  Returns 1 for success, longjmps
   on error.  */
   on error.  */
#define FETCH_DATA(info, addr) \
#define FETCH_DATA(info, addr) \
  ((addr) <= ((struct private *)(info->private_data))->max_fetched \
  ((addr) <= ((struct private *)(info->private_data))->max_fetched \
   ? 1 : fetch_data ((info), (addr)))
   ? 1 : fetch_data ((info), (addr)))
 
 
static int
static int
fetch_data (info, addr)
fetch_data (info, addr)
     struct disassemble_info *info;
     struct disassemble_info *info;
     bfd_byte *addr;
     bfd_byte *addr;
{
{
  int status;
  int status;
  struct private *priv = (struct private *)info->private_data;
  struct private *priv = (struct private *)info->private_data;
  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
 
 
  status = (*info->read_memory_func) (start,
  status = (*info->read_memory_func) (start,
                                      priv->max_fetched,
                                      priv->max_fetched,
                                      addr - priv->max_fetched,
                                      addr - priv->max_fetched,
                                      info);
                                      info);
  if (status != 0)
  if (status != 0)
    {
    {
      (*info->memory_error_func) (status, start, info);
      (*info->memory_error_func) (status, start, info);
      longjmp (priv->bailout, 1);
      longjmp (priv->bailout, 1);
    }
    }
  else
  else
    priv->max_fetched = addr;
    priv->max_fetched = addr;
  return 1;
  return 1;
}
}
/* Number of elements in the opcode table.  */
/* Number of elements in the opcode table.  */
#define NOPCODES (sizeof ns32k_opcodes / sizeof ns32k_opcodes[0])
#define NOPCODES (sizeof ns32k_opcodes / sizeof ns32k_opcodes[0])
 
 
#define NEXT_IS_ADDR    '|'
#define NEXT_IS_ADDR    '|'
 
 


struct ns32k_option {
struct ns32k_option {
  char *pattern;                /* the option itself */
  char *pattern;                /* the option itself */
  unsigned long value;          /* binary value of the option */
  unsigned long value;          /* binary value of the option */
  unsigned long match;          /* these bits must match */
  unsigned long match;          /* these bits must match */
};
};
 
 


static const struct ns32k_option opt_u[]= /* restore, exit */
static const struct ns32k_option opt_u[]= /* restore, exit */
{
{
  { "r0",       0x80,   0x80    },
  { "r0",       0x80,   0x80    },
  { "r1",       0x40,   0x40    },
  { "r1",       0x40,   0x40    },
  { "r2",       0x20,   0x20    },
  { "r2",       0x20,   0x20    },
  { "r3",       0x10,   0x10    },
  { "r3",       0x10,   0x10    },
  { "r4",       0x08,   0x08    },
  { "r4",       0x08,   0x08    },
  { "r5",       0x04,   0x04    },
  { "r5",       0x04,   0x04    },
  { "r6",       0x02,   0x02    },
  { "r6",       0x02,   0x02    },
  { "r7",       0x01,   0x01    },
  { "r7",       0x01,   0x01    },
  {  0 , 0x00,   0x00    }
  {  0 , 0x00,   0x00    }
};
};
 
 
static const struct ns32k_option opt_U[]= /* save, enter */
static const struct ns32k_option opt_U[]= /* save, enter */
{
{
  { "r0",       0x01,   0x01    },
  { "r0",       0x01,   0x01    },
  { "r1",       0x02,   0x02    },
  { "r1",       0x02,   0x02    },
  { "r2",       0x04,   0x04    },
  { "r2",       0x04,   0x04    },
  { "r3",       0x08,   0x08    },
  { "r3",       0x08,   0x08    },
  { "r4",       0x10,   0x10    },
  { "r4",       0x10,   0x10    },
  { "r5",       0x20,   0x20    },
  { "r5",       0x20,   0x20    },
  { "r6",       0x40,   0x40    },
  { "r6",       0x40,   0x40    },
  { "r7",       0x80,   0x80    },
  { "r7",       0x80,   0x80    },
  {  0 , 0x00,   0x00    }
  {  0 , 0x00,   0x00    }
};
};
 
 
static const struct ns32k_option opt_O[]= /* setcfg */
static const struct ns32k_option opt_O[]= /* setcfg */
{
{
  { "c",        0x8,    0x8     },
  { "c",        0x8,    0x8     },
  { "m",        0x4,    0x4     },
  { "m",        0x4,    0x4     },
  { "f",        0x2,    0x2     },
  { "f",        0x2,    0x2     },
  { "i",        0x1,    0x1     },
  { "i",        0x1,    0x1     },
  {  0 , 0x0,    0x0     }
  {  0 , 0x0,    0x0     }
};
};
 
 
static const struct ns32k_option opt_C[]= /* cinv */
static const struct ns32k_option opt_C[]= /* cinv */
{
{
  { "a",        0x4,    0x4     },
  { "a",        0x4,    0x4     },
  { "i",        0x2,    0x2     },
  { "i",        0x2,    0x2     },
  { "d",        0x1,    0x1     },
  { "d",        0x1,    0x1     },
  {  0 , 0x0,    0x0     }
  {  0 , 0x0,    0x0     }
};
};
 
 
static const struct ns32k_option opt_S[]= /* string inst */
static const struct ns32k_option opt_S[]= /* string inst */
{
{
  { "b",        0x1,    0x1     },
  { "b",        0x1,    0x1     },
  { "u",        0x6,    0x6     },
  { "u",        0x6,    0x6     },
  { "w",        0x2,    0x2     },
  { "w",        0x2,    0x2     },
  {  0 , 0x0,    0x0     }
  {  0 , 0x0,    0x0     }
};
};
 
 
static const struct ns32k_option list_P532[]= /* lpr spr */
static const struct ns32k_option list_P532[]= /* lpr spr */
{
{
  { "us",       0x0,    0xf     },
  { "us",       0x0,    0xf     },
  { "dcr",      0x1,    0xf     },
  { "dcr",      0x1,    0xf     },
  { "bpc",      0x2,    0xf     },
  { "bpc",      0x2,    0xf     },
  { "dsr",      0x3,    0xf     },
  { "dsr",      0x3,    0xf     },
  { "car",      0x4,    0xf     },
  { "car",      0x4,    0xf     },
  { "fp",       0x8,    0xf     },
  { "fp",       0x8,    0xf     },
  { "sp",       0x9,    0xf     },
  { "sp",       0x9,    0xf     },
  { "sb",       0xa,    0xf     },
  { "sb",       0xa,    0xf     },
  { "usp",      0xb,    0xf     },
  { "usp",      0xb,    0xf     },
  { "cfg",      0xc,    0xf     },
  { "cfg",      0xc,    0xf     },
  { "psr",      0xd,    0xf     },
  { "psr",      0xd,    0xf     },
  { "intbase",  0xe,    0xf     },
  { "intbase",  0xe,    0xf     },
  { "mod",      0xf,    0xf     },
  { "mod",      0xf,    0xf     },
  {  0 , 0x00,   0xf     }
  {  0 , 0x00,   0xf     }
};
};
 
 
static const struct ns32k_option list_M532[]= /* lmr smr */
static const struct ns32k_option list_M532[]= /* lmr smr */
{
{
  { "mcr",      0x9,    0xf     },
  { "mcr",      0x9,    0xf     },
  { "msr",      0xa,    0xf     },
  { "msr",      0xa,    0xf     },
  { "tear",     0xb,    0xf     },
  { "tear",     0xb,    0xf     },
  { "ptb0",     0xc,    0xf     },
  { "ptb0",     0xc,    0xf     },
  { "ptb1",     0xd,    0xf     },
  { "ptb1",     0xd,    0xf     },
  { "ivar0",    0xe,    0xf     },
  { "ivar0",    0xe,    0xf     },
  { "ivar1",    0xf,    0xf     },
  { "ivar1",    0xf,    0xf     },
  {  0 , 0x0,    0xf     }
  {  0 , 0x0,    0xf     }
};
};
 
 
static const struct ns32k_option list_P032[]= /* lpr spr */
static const struct ns32k_option list_P032[]= /* lpr spr */
{
{
  { "upsr",     0x0,    0xf     },
  { "upsr",     0x0,    0xf     },
  { "fp",       0x8,    0xf     },
  { "fp",       0x8,    0xf     },
  { "sp",       0x9,    0xf     },
  { "sp",       0x9,    0xf     },
  { "sb",       0xa,    0xf     },
  { "sb",       0xa,    0xf     },
  { "psr",      0xb,    0xf     },
  { "psr",      0xb,    0xf     },
  { "intbase",  0xe,    0xf     },
  { "intbase",  0xe,    0xf     },
  { "mod",      0xf,    0xf     },
  { "mod",      0xf,    0xf     },
  {  0 , 0x0,    0xf     }
  {  0 , 0x0,    0xf     }
};
};
 
 
static const struct ns32k_option list_M032[]= /* lmr smr */
static const struct ns32k_option list_M032[]= /* lmr smr */
{
{
  { "bpr0",     0x0,    0xf     },
  { "bpr0",     0x0,    0xf     },
  { "bpr1",     0x1,    0xf     },
  { "bpr1",     0x1,    0xf     },
  { "pf0",      0x4,    0xf     },
  { "pf0",      0x4,    0xf     },
  { "pf1",      0x5,    0xf     },
  { "pf1",      0x5,    0xf     },
  { "sc",       0x8,    0xf     },
  { "sc",       0x8,    0xf     },
  { "msr",      0xa,    0xf     },
  { "msr",      0xa,    0xf     },
  { "bcnt",     0xb,    0xf     },
  { "bcnt",     0xb,    0xf     },
  { "ptb0",     0xc,    0xf     },
  { "ptb0",     0xc,    0xf     },
  { "ptb1",     0xd,    0xf     },
  { "ptb1",     0xd,    0xf     },
  { "eia",      0xf,    0xf     },
  { "eia",      0xf,    0xf     },
  {  0 , 0x0,    0xf     }
  {  0 , 0x0,    0xf     }
};
};
 
 
 
 
/*
/*
 * figure out which options are present
 * figure out which options are present
 */
 */
static void
static void
optlist(options, optionP, result)
optlist(options, optionP, result)
     int options;
     int options;
     const struct ns32k_option *optionP;
     const struct ns32k_option *optionP;
     char *result;
     char *result;
{
{
    if (options == 0) {
    if (options == 0) {
        sprintf(result, "[]");
        sprintf(result, "[]");
        return;
        return;
    }
    }
    sprintf(result, "[");
    sprintf(result, "[");
 
 
    for (; (options != 0) && optionP->pattern; optionP++) {
    for (; (options != 0) && optionP->pattern; optionP++) {
        if ((options & optionP->match) == optionP->value) {
        if ((options & optionP->match) == optionP->value) {
            /* we found a match, update result and options */
            /* we found a match, update result and options */
            strcat(result, optionP->pattern);
            strcat(result, optionP->pattern);
            options &= ~optionP->value;
            options &= ~optionP->value;
            if (options != 0)    /* more options to come */
            if (options != 0)    /* more options to come */
                strcat(result, ",");
                strcat(result, ",");
        }
        }
    }
    }
    if (options != 0)
    if (options != 0)
        strcat(result, "undefined");
        strcat(result, "undefined");
 
 
    strcat(result, "]");
    strcat(result, "]");
}
}
 
 
static void
static void
list_search (reg_value, optionP, result)
list_search (reg_value, optionP, result)
     int reg_value;
     int reg_value;
     const struct ns32k_option *optionP;
     const struct ns32k_option *optionP;
     char *result;
     char *result;
{
{
    for (; optionP->pattern; optionP++) {
    for (; optionP->pattern; optionP++) {
        if ((reg_value & optionP->match) == optionP->value) {
        if ((reg_value & optionP->match) == optionP->value) {
            sprintf(result, "%s", optionP->pattern);
            sprintf(result, "%s", optionP->pattern);
            return;
            return;
        }
        }
    }
    }
    sprintf(result, "undefined");
    sprintf(result, "undefined");
}
}


/*
/*
 * extract "count" bits starting "offset" bits
 * extract "count" bits starting "offset" bits
 * into buffer
 * into buffer
 */
 */
 
 
static int
static int
bit_extract (buffer, offset, count)
bit_extract (buffer, offset, count)
     bfd_byte *buffer;
     bfd_byte *buffer;
     int offset;
     int offset;
     int count;
     int count;
{
{
  int result;
  int result;
  int bit;
  int bit;
 
 
  buffer += offset >> 3;
  buffer += offset >> 3;
  offset &= 7;
  offset &= 7;
  bit = 1;
  bit = 1;
  result = 0;
  result = 0;
  while (count--)
  while (count--)
    {
    {
      FETCH_DATA(dis_info, buffer + 1);
      FETCH_DATA(dis_info, buffer + 1);
      if ((*buffer & (1 << offset)))
      if ((*buffer & (1 << offset)))
        result |= bit;
        result |= bit;
      if (++offset == 8)
      if (++offset == 8)
        {
        {
          offset = 0;
          offset = 0;
          buffer++;
          buffer++;
        }
        }
      bit <<= 1;
      bit <<= 1;
    }
    }
  return result;
  return result;
}
}
 
 
/* Like bit extract but the buffer is valid and doen't need to be
/* Like bit extract but the buffer is valid and doen't need to be
 * fetched
 * fetched
 */
 */
static int
static int
bit_extract_simple (buffer, offset, count)
bit_extract_simple (buffer, offset, count)
     bfd_byte *buffer;
     bfd_byte *buffer;
     int offset;
     int offset;
     int count;
     int count;
{
{
  int result;
  int result;
  int bit;
  int bit;
 
 
  buffer += offset >> 3;
  buffer += offset >> 3;
  offset &= 7;
  offset &= 7;
  bit = 1;
  bit = 1;
  result = 0;
  result = 0;
  while (count--)
  while (count--)
    {
    {
      if ((*buffer & (1 << offset)))
      if ((*buffer & (1 << offset)))
        result |= bit;
        result |= bit;
      if (++offset == 8)
      if (++offset == 8)
        {
        {
          offset = 0;
          offset = 0;
          buffer++;
          buffer++;
        }
        }
      bit <<= 1;
      bit <<= 1;
    }
    }
  return result;
  return result;
}
}
 
 
static void
static void
bit_copy (buffer, offset, count, to)
bit_copy (buffer, offset, count, to)
     char *buffer;
     char *buffer;
     int offset;
     int offset;
     int count;
     int count;
     char *to;
     char *to;
{
{
  for(; count > 8; count -= 8, to++, offset += 8)
  for(; count > 8; count -= 8, to++, offset += 8)
    *to = bit_extract (buffer, offset, 8);
    *to = bit_extract (buffer, offset, 8);
  *to = bit_extract (buffer, offset, count);
  *to = bit_extract (buffer, offset, count);
}
}
 
 
 
 
static int
static int
sign_extend (value, bits)
sign_extend (value, bits)
     int value, bits;
     int value, bits;
{
{
  value = value & ((1 << bits) - 1);
  value = value & ((1 << bits) - 1);
  return (value & (1 << (bits-1))
  return (value & (1 << (bits-1))
          ? value | (~((1 << bits) - 1))
          ? value | (~((1 << bits) - 1))
          : value);
          : value);
}
}
 
 
static void
static void
flip_bytes (ptr, count)
flip_bytes (ptr, count)
     char *ptr;
     char *ptr;
     int count;
     int count;
{
{
  char tmp;
  char tmp;
 
 
  while (count > 0)
  while (count > 0)
    {
    {
      tmp = ptr[0];
      tmp = ptr[0];
      ptr[0] = ptr[count-1];
      ptr[0] = ptr[count-1];
      ptr[count-1] = tmp;
      ptr[count-1] = tmp;
      ptr++;
      ptr++;
      count -= 2;
      count -= 2;
    }
    }
}
}


/* Given a character C, does it represent a general addressing mode?  */
/* Given a character C, does it represent a general addressing mode?  */
#define Is_gen(c) \
#define Is_gen(c) \
  ((c) == 'F' || (c) == 'L' || (c) == 'B' \
  ((c) == 'F' || (c) == 'L' || (c) == 'B' \
   || (c) == 'W' || (c) == 'D' || (c) == 'A' || (c) == 'I' || (c) == 'Z')
   || (c) == 'W' || (c) == 'D' || (c) == 'A' || (c) == 'I' || (c) == 'Z')
 
 
/* Adressing modes.  */
/* Adressing modes.  */
#define Adrmod_index_byte 0x1c
#define Adrmod_index_byte 0x1c
#define Adrmod_index_word 0x1d
#define Adrmod_index_word 0x1d
#define Adrmod_index_doubleword 0x1e
#define Adrmod_index_doubleword 0x1e
#define Adrmod_index_quadword 0x1f
#define Adrmod_index_quadword 0x1f
 
 
/* Is MODE an indexed addressing mode?  */
/* Is MODE an indexed addressing mode?  */
#define Adrmod_is_index(mode) \
#define Adrmod_is_index(mode) \
  (mode == Adrmod_index_byte \
  (mode == Adrmod_index_byte \
   || mode == Adrmod_index_word \
   || mode == Adrmod_index_word \
   || mode == Adrmod_index_doubleword \
   || mode == Adrmod_index_doubleword \
   || mode == Adrmod_index_quadword)
   || mode == Adrmod_index_quadword)
 
 


/* Print the 32000 instruction at address MEMADDR in debugged memory,
/* Print the 32000 instruction at address MEMADDR in debugged memory,
   on STREAM.  Returns length of the instruction, in bytes.  */
   on STREAM.  Returns length of the instruction, in bytes.  */
 
 
int
int
print_insn_ns32k (memaddr, info)
print_insn_ns32k (memaddr, info)
     bfd_vma memaddr;
     bfd_vma memaddr;
     disassemble_info *info;
     disassemble_info *info;
{
{
  register unsigned int i;
  register unsigned int i;
  register char *d;
  register char *d;
  unsigned short first_word;
  unsigned short first_word;
  int ioffset;          /* bits into instruction */
  int ioffset;          /* bits into instruction */
  int aoffset;          /* bits into arguments */
  int aoffset;          /* bits into arguments */
  char arg_bufs[MAX_ARGS+1][ARG_LEN];
  char arg_bufs[MAX_ARGS+1][ARG_LEN];
  int argnum;
  int argnum;
  int maxarg;
  int maxarg;
  struct private priv;
  struct private priv;
  bfd_byte *buffer = priv.the_buffer;
  bfd_byte *buffer = priv.the_buffer;
  dis_info = info;
  dis_info = info;
 
 
  info->private_data = (PTR) &priv;
  info->private_data = (PTR) &priv;
  priv.max_fetched = priv.the_buffer;
  priv.max_fetched = priv.the_buffer;
  priv.insn_start = memaddr;
  priv.insn_start = memaddr;
  if (setjmp (priv.bailout) != 0)
  if (setjmp (priv.bailout) != 0)
    /* Error return.  */
    /* Error return.  */
    return -1;
    return -1;
 
 
  /* Look for 8bit opcodes first. Other wise, fetching two bytes could take
  /* Look for 8bit opcodes first. Other wise, fetching two bytes could take
   * us over the end of accessible data unnecessarilly
   * us over the end of accessible data unnecessarilly
   */
   */
  FETCH_DATA(info, buffer + 1);
  FETCH_DATA(info, buffer + 1);
  for (i = 0; i < NOPCODES; i++)
  for (i = 0; i < NOPCODES; i++)
    if (ns32k_opcodes[i].opcode_id_size <= 8
    if (ns32k_opcodes[i].opcode_id_size <= 8
        && ((buffer[0]
        && ((buffer[0]
             & (((unsigned long) 1 << ns32k_opcodes[i].opcode_id_size) - 1))
             & (((unsigned long) 1 << ns32k_opcodes[i].opcode_id_size) - 1))
            == ns32k_opcodes[i].opcode_seed))
            == ns32k_opcodes[i].opcode_seed))
      break;
      break;
  if (i == NOPCODES) {
  if (i == NOPCODES) {
    /* Maybe it is 9 to 16 bits big */
    /* Maybe it is 9 to 16 bits big */
    FETCH_DATA(info, buffer + 2);
    FETCH_DATA(info, buffer + 2);
    first_word = read_memory_integer(buffer, 2);
    first_word = read_memory_integer(buffer, 2);
 
 
    for (i = 0; i < NOPCODES; i++)
    for (i = 0; i < NOPCODES; i++)
      if ((first_word
      if ((first_word
           & (((unsigned long) 1 << ns32k_opcodes[i].opcode_id_size) - 1))
           & (((unsigned long) 1 << ns32k_opcodes[i].opcode_id_size) - 1))
          == ns32k_opcodes[i].opcode_seed)
          == ns32k_opcodes[i].opcode_seed)
        break;
        break;
 
 
    /* Handle undefined instructions.  */
    /* Handle undefined instructions.  */
    if (i == NOPCODES)
    if (i == NOPCODES)
      {
      {
        (*dis_info->fprintf_func)(dis_info->stream, "0%o", buffer[0]);
        (*dis_info->fprintf_func)(dis_info->stream, "0%o", buffer[0]);
        return 1;
        return 1;
      }
      }
  }
  }
 
 
  (*dis_info->fprintf_func)(dis_info->stream, "%s", ns32k_opcodes[i].name);
  (*dis_info->fprintf_func)(dis_info->stream, "%s", ns32k_opcodes[i].name);
 
 
  ioffset = ns32k_opcodes[i].opcode_size;
  ioffset = ns32k_opcodes[i].opcode_size;
  aoffset = ns32k_opcodes[i].opcode_size;
  aoffset = ns32k_opcodes[i].opcode_size;
  d = ns32k_opcodes[i].operands;
  d = ns32k_opcodes[i].operands;
 
 
  if (*d)
  if (*d)
    {
    {
      /* Offset in bits of the first thing beyond each index byte.
      /* Offset in bits of the first thing beyond each index byte.
         Element 0 is for operand A and element 1 is for operand B.
         Element 0 is for operand A and element 1 is for operand B.
         The rest are irrelevant, but we put them here so we don't
         The rest are irrelevant, but we put them here so we don't
         index outside the array.  */
         index outside the array.  */
      int index_offset[MAX_ARGS];
      int index_offset[MAX_ARGS];
 
 
      /* 0 for operand A, 1 for operand B, greater for other args.  */
      /* 0 for operand A, 1 for operand B, greater for other args.  */
      int whicharg = 0;
      int whicharg = 0;
 
 
      (*dis_info->fprintf_func)(dis_info->stream, "\t");
      (*dis_info->fprintf_func)(dis_info->stream, "\t");
 
 
      maxarg = 0;
      maxarg = 0;
 
 
      /* First we have to find and keep track of the index bytes,
      /* First we have to find and keep track of the index bytes,
         if we are using scaled indexed addressing mode, since the index
         if we are using scaled indexed addressing mode, since the index
         bytes occur right after the basic instruction, not as part
         bytes occur right after the basic instruction, not as part
         of the addressing extension.  */
         of the addressing extension.  */
      if (Is_gen(d[1]))
      if (Is_gen(d[1]))
        {
        {
          int addr_mode = bit_extract (buffer, ioffset - 5, 5);
          int addr_mode = bit_extract (buffer, ioffset - 5, 5);
 
 
          if (Adrmod_is_index (addr_mode))
          if (Adrmod_is_index (addr_mode))
            {
            {
              aoffset += 8;
              aoffset += 8;
              index_offset[0] = aoffset;
              index_offset[0] = aoffset;
            }
            }
        }
        }
      if (d[2] && Is_gen(d[3]))
      if (d[2] && Is_gen(d[3]))
        {
        {
          int addr_mode = bit_extract (buffer, ioffset - 10, 5);
          int addr_mode = bit_extract (buffer, ioffset - 10, 5);
 
 
          if (Adrmod_is_index (addr_mode))
          if (Adrmod_is_index (addr_mode))
            {
            {
              aoffset += 8;
              aoffset += 8;
              index_offset[1] = aoffset;
              index_offset[1] = aoffset;
            }
            }
        }
        }
 
 
      while (*d)
      while (*d)
        {
        {
          argnum = *d - '1';
          argnum = *d - '1';
          d++;
          d++;
          if (argnum > maxarg && argnum < MAX_ARGS)
          if (argnum > maxarg && argnum < MAX_ARGS)
            maxarg = argnum;
            maxarg = argnum;
          ioffset = print_insn_arg (*d, ioffset, &aoffset, buffer,
          ioffset = print_insn_arg (*d, ioffset, &aoffset, buffer,
                                    memaddr, arg_bufs[argnum],
                                    memaddr, arg_bufs[argnum],
                                    index_offset[whicharg]);
                                    index_offset[whicharg]);
          d++;
          d++;
          whicharg++;
          whicharg++;
        }
        }
      for (argnum = 0; argnum <= maxarg; argnum++)
      for (argnum = 0; argnum <= maxarg; argnum++)
        {
        {
          bfd_vma addr;
          bfd_vma addr;
          char *ch;
          char *ch;
          for (ch = arg_bufs[argnum]; *ch;)
          for (ch = arg_bufs[argnum]; *ch;)
            {
            {
              if (*ch == NEXT_IS_ADDR)
              if (*ch == NEXT_IS_ADDR)
                {
                {
                  ++ch;
                  ++ch;
                  addr = bfd_scan_vma (ch, NULL, 16);
                  addr = bfd_scan_vma (ch, NULL, 16);
                  (*dis_info->print_address_func) (addr, dis_info);
                  (*dis_info->print_address_func) (addr, dis_info);
                  while (*ch && *ch != NEXT_IS_ADDR)
                  while (*ch && *ch != NEXT_IS_ADDR)
                    ++ch;
                    ++ch;
                  if (*ch)
                  if (*ch)
                    ++ch;
                    ++ch;
                }
                }
              else
              else
                (*dis_info->fprintf_func)(dis_info->stream, "%c", *ch++);
                (*dis_info->fprintf_func)(dis_info->stream, "%c", *ch++);
            }
            }
          if (argnum < maxarg)
          if (argnum < maxarg)
            (*dis_info->fprintf_func)(dis_info->stream, ", ");
            (*dis_info->fprintf_func)(dis_info->stream, ", ");
        }
        }
    }
    }
  return aoffset / 8;
  return aoffset / 8;
}
}
 
 
/* Print an instruction operand of category given by d.  IOFFSET is
/* Print an instruction operand of category given by d.  IOFFSET is
   the bit position below which small (<1 byte) parts of the operand can
   the bit position below which small (<1 byte) parts of the operand can
   be found (usually in the basic instruction, but for indexed
   be found (usually in the basic instruction, but for indexed
   addressing it can be in the index byte).  AOFFSETP is a pointer to the
   addressing it can be in the index byte).  AOFFSETP is a pointer to the
   bit position of the addressing extension.  BUFFER contains the
   bit position of the addressing extension.  BUFFER contains the
   instruction.  ADDR is where BUFFER was read from.  Put the disassembled
   instruction.  ADDR is where BUFFER was read from.  Put the disassembled
   version of the operand in RESULT.  INDEX_OFFSET is the bit position
   version of the operand in RESULT.  INDEX_OFFSET is the bit position
   of the index byte (it contains garbage if this operand is not a
   of the index byte (it contains garbage if this operand is not a
   general operand using scaled indexed addressing mode).  */
   general operand using scaled indexed addressing mode).  */
 
 
static int
static int
print_insn_arg (d, ioffset, aoffsetp, buffer, addr, result, index_offset)
print_insn_arg (d, ioffset, aoffsetp, buffer, addr, result, index_offset)
     int d;
     int d;
     int ioffset, *aoffsetp;
     int ioffset, *aoffsetp;
     char *buffer;
     char *buffer;
     bfd_vma addr;
     bfd_vma addr;
     char *result;
     char *result;
     int index_offset;
     int index_offset;
{
{
  int addr_mode;
  int addr_mode;
  float Fvalue;
  float Fvalue;
  double Lvalue;
  double Lvalue;
  int Ivalue;
  int Ivalue;
  int disp1, disp2;
  int disp1, disp2;
  int index;
  int index;
  int size;
  int size;
 
 
  switch (d)
  switch (d)
    {
    {
    case 'f':
    case 'f':
      /* a "gen" operand but 5 bits from the end of instruction */
      /* a "gen" operand but 5 bits from the end of instruction */
      ioffset -= 5;
      ioffset -= 5;
    case 'Z':
    case 'Z':
    case 'F':
    case 'F':
    case 'L':
    case 'L':
    case 'I':
    case 'I':
    case 'B':
    case 'B':
    case 'W':
    case 'W':
    case 'D':
    case 'D':
    case 'A':
    case 'A':
      addr_mode = bit_extract (buffer, ioffset-5, 5);
      addr_mode = bit_extract (buffer, ioffset-5, 5);
      ioffset -= 5;
      ioffset -= 5;
      switch (addr_mode)
      switch (addr_mode)
        {
        {
        case 0x0: case 0x1: case 0x2: case 0x3:
        case 0x0: case 0x1: case 0x2: case 0x3:
        case 0x4: case 0x5: case 0x6: case 0x7:
        case 0x4: case 0x5: case 0x6: case 0x7:
          /* register mode R0 -- R7 */
          /* register mode R0 -- R7 */
          switch (d)
          switch (d)
            {
            {
            case 'F':
            case 'F':
            case 'L':
            case 'L':
            case 'Z':
            case 'Z':
              sprintf (result, "f%d", addr_mode);
              sprintf (result, "f%d", addr_mode);
              break;
              break;
            default:
            default:
              sprintf (result, "r%d", addr_mode);
              sprintf (result, "r%d", addr_mode);
            }
            }
          break;
          break;
        case 0x8: case 0x9: case 0xa: case 0xb:
        case 0x8: case 0x9: case 0xa: case 0xb:
        case 0xc: case 0xd: case 0xe: case 0xf:
        case 0xc: case 0xd: case 0xe: case 0xf:
          /* Register relative disp(R0 -- R7) */
          /* Register relative disp(R0 -- R7) */
          disp1 = get_displacement (buffer, aoffsetp);
          disp1 = get_displacement (buffer, aoffsetp);
          sprintf (result, "%d(r%d)", disp1, addr_mode & 7);
          sprintf (result, "%d(r%d)", disp1, addr_mode & 7);
          break;
          break;
        case 0x10:
        case 0x10:
        case 0x11:
        case 0x11:
        case 0x12:
        case 0x12:
          /* Memory relative disp2(disp1(FP, SP, SB)) */
          /* Memory relative disp2(disp1(FP, SP, SB)) */
          disp1 = get_displacement (buffer, aoffsetp);
          disp1 = get_displacement (buffer, aoffsetp);
          disp2 = get_displacement (buffer, aoffsetp);
          disp2 = get_displacement (buffer, aoffsetp);
          sprintf (result, "%d(%d(%s))", disp2, disp1,
          sprintf (result, "%d(%d(%s))", disp2, disp1,
                   addr_mode==0x10?"fp":addr_mode==0x11?"sp":"sb");
                   addr_mode==0x10?"fp":addr_mode==0x11?"sp":"sb");
          break;
          break;
        case 0x13:
        case 0x13:
          /* reserved */
          /* reserved */
          sprintf (result, "reserved");
          sprintf (result, "reserved");
          break;
          break;
        case 0x14:
        case 0x14:
          /* Immediate */
          /* Immediate */
          switch (d)
          switch (d)
            {
            {
            case 'I': case 'Z': case 'A':
            case 'I': case 'Z': case 'A':
              /* I and Z are output operands and can`t be immediate
              /* I and Z are output operands and can`t be immediate
               * A is an address and we can`t have the address of
               * A is an address and we can`t have the address of
               * an immediate either. We don't know how much to increase
               * an immediate either. We don't know how much to increase
               * aoffsetp by since whatever generated this is broken
               * aoffsetp by since whatever generated this is broken
               * anyway!
               * anyway!
               */
               */
              sprintf (result, _("$<undefined>"));
              sprintf (result, _("$<undefined>"));
              break;
              break;
            case 'B':
            case 'B':
              Ivalue = bit_extract (buffer, *aoffsetp, 8);
              Ivalue = bit_extract (buffer, *aoffsetp, 8);
              Ivalue = sign_extend (Ivalue, 8);
              Ivalue = sign_extend (Ivalue, 8);
              *aoffsetp += 8;
              *aoffsetp += 8;
              sprintf (result, "$%d", Ivalue);
              sprintf (result, "$%d", Ivalue);
              break;
              break;
            case 'W':
            case 'W':
              Ivalue = bit_extract (buffer, *aoffsetp, 16);
              Ivalue = bit_extract (buffer, *aoffsetp, 16);
              flip_bytes ((char *) & Ivalue, 2);
              flip_bytes ((char *) & Ivalue, 2);
              *aoffsetp += 16;
              *aoffsetp += 16;
              Ivalue = sign_extend (Ivalue, 16);
              Ivalue = sign_extend (Ivalue, 16);
              sprintf (result, "$%d", Ivalue);
              sprintf (result, "$%d", Ivalue);
              break;
              break;
            case 'D':
            case 'D':
              Ivalue = bit_extract (buffer, *aoffsetp, 32);
              Ivalue = bit_extract (buffer, *aoffsetp, 32);
              flip_bytes ((char *) & Ivalue, 4);
              flip_bytes ((char *) & Ivalue, 4);
              *aoffsetp += 32;
              *aoffsetp += 32;
              sprintf (result, "$%d", Ivalue);
              sprintf (result, "$%d", Ivalue);
              break;
              break;
            case 'F':
            case 'F':
              bit_copy (buffer, *aoffsetp, 32, (char *) &Fvalue);
              bit_copy (buffer, *aoffsetp, 32, (char *) &Fvalue);
              flip_bytes ((char *) & Fvalue, 4);
              flip_bytes ((char *) & Fvalue, 4);
              *aoffsetp += 32;
              *aoffsetp += 32;
              if (INVALID_FLOAT (&Fvalue, 4))
              if (INVALID_FLOAT (&Fvalue, 4))
                sprintf (result, "<<invalid float 0x%.8x>>", *(int *) &Fvalue);
                sprintf (result, "<<invalid float 0x%.8x>>", *(int *) &Fvalue);
              else /* assume host has ieee float */
              else /* assume host has ieee float */
                sprintf (result, "$%g", Fvalue);
                sprintf (result, "$%g", Fvalue);
              break;
              break;
            case 'L':
            case 'L':
              bit_copy (buffer, *aoffsetp, 64, (char *) &Lvalue);
              bit_copy (buffer, *aoffsetp, 64, (char *) &Lvalue);
              flip_bytes ((char *) & Lvalue, 8);
              flip_bytes ((char *) & Lvalue, 8);
              *aoffsetp += 64;
              *aoffsetp += 64;
              if (INVALID_FLOAT (&Lvalue, 8))
              if (INVALID_FLOAT (&Lvalue, 8))
                sprintf (result, "<<invalid long 0x%.8x%.8x>>",
                sprintf (result, "<<invalid long 0x%.8x%.8x>>",
                         *(((int *) &Lvalue) + 1), *(int *) &Lvalue);
                         *(((int *) &Lvalue) + 1), *(int *) &Lvalue);
              else /* assume host has ieee float */
              else /* assume host has ieee float */
                sprintf (result, "$%g", Lvalue);
                sprintf (result, "$%g", Lvalue);
              break;
              break;
            }
            }
          break;
          break;
        case 0x15:
        case 0x15:
          /* Absolute @disp */
          /* Absolute @disp */
          disp1 = get_displacement (buffer, aoffsetp);
          disp1 = get_displacement (buffer, aoffsetp);
          sprintf (result, "@|%d|", disp1);
          sprintf (result, "@|%d|", disp1);
          break;
          break;
        case 0x16:
        case 0x16:
          /* External EXT(disp1) + disp2 (Mod table stuff) */
          /* External EXT(disp1) + disp2 (Mod table stuff) */
          disp1 = get_displacement (buffer, aoffsetp);
          disp1 = get_displacement (buffer, aoffsetp);
          disp2 = get_displacement (buffer, aoffsetp);
          disp2 = get_displacement (buffer, aoffsetp);
          sprintf (result, "EXT(%d) + %d", disp1, disp2);
          sprintf (result, "EXT(%d) + %d", disp1, disp2);
          break;
          break;
        case 0x17:
        case 0x17:
          /* Top of stack tos */
          /* Top of stack tos */
          sprintf (result, "tos");
          sprintf (result, "tos");
          break;
          break;
        case 0x18:
        case 0x18:
          /* Memory space disp(FP) */
          /* Memory space disp(FP) */
          disp1 = get_displacement (buffer, aoffsetp);
          disp1 = get_displacement (buffer, aoffsetp);
          sprintf (result, "%d(fp)", disp1);
          sprintf (result, "%d(fp)", disp1);
          break;
          break;
        case 0x19:
        case 0x19:
          /* Memory space disp(SP) */
          /* Memory space disp(SP) */
          disp1 = get_displacement (buffer, aoffsetp);
          disp1 = get_displacement (buffer, aoffsetp);
          sprintf (result, "%d(sp)", disp1);
          sprintf (result, "%d(sp)", disp1);
          break;
          break;
        case 0x1a:
        case 0x1a:
          /* Memory space disp(SB) */
          /* Memory space disp(SB) */
          disp1 = get_displacement (buffer, aoffsetp);
          disp1 = get_displacement (buffer, aoffsetp);
          sprintf (result, "%d(sb)", disp1);
          sprintf (result, "%d(sb)", disp1);
          break;
          break;
        case 0x1b:
        case 0x1b:
          /* Memory space disp(PC) */
          /* Memory space disp(PC) */
          disp1 = get_displacement (buffer, aoffsetp);
          disp1 = get_displacement (buffer, aoffsetp);
          *result++ = NEXT_IS_ADDR;
          *result++ = NEXT_IS_ADDR;
          sprintf_vma (result, addr + disp1);
          sprintf_vma (result, addr + disp1);
          result += strlen (result);
          result += strlen (result);
          *result++ = NEXT_IS_ADDR;
          *result++ = NEXT_IS_ADDR;
          *result = '\0';
          *result = '\0';
          break;
          break;
        case 0x1c:
        case 0x1c:
        case 0x1d:
        case 0x1d:
        case 0x1e:
        case 0x1e:
        case 0x1f:
        case 0x1f:
          /* Scaled index basemode[R0 -- R7:B,W,D,Q] */
          /* Scaled index basemode[R0 -- R7:B,W,D,Q] */
          index = bit_extract (buffer, index_offset - 8, 3);
          index = bit_extract (buffer, index_offset - 8, 3);
          print_insn_arg (d, index_offset, aoffsetp, buffer, addr,
          print_insn_arg (d, index_offset, aoffsetp, buffer, addr,
                          result, 0);
                          result, 0);
          {
          {
            static const char *ind = "bwdq";
            static const char *ind = "bwdq";
            char *off;
            char *off;
 
 
            off = result + strlen (result);
            off = result + strlen (result);
            sprintf (off, "[r%d:%c]", index,
            sprintf (off, "[r%d:%c]", index,
                     ind[addr_mode & 3]);
                     ind[addr_mode & 3]);
          }
          }
          break;
          break;
        }
        }
      break;
      break;
    case 'H':
    case 'H':
    case 'q':
    case 'q':
      Ivalue = bit_extract (buffer, ioffset-4, 4);
      Ivalue = bit_extract (buffer, ioffset-4, 4);
      Ivalue = sign_extend (Ivalue, 4);
      Ivalue = sign_extend (Ivalue, 4);
      sprintf (result, "%d", Ivalue);
      sprintf (result, "%d", Ivalue);
      ioffset -= 4;
      ioffset -= 4;
      break;
      break;
    case 'r':
    case 'r':
      Ivalue = bit_extract (buffer, ioffset-3, 3);
      Ivalue = bit_extract (buffer, ioffset-3, 3);
      sprintf (result, "r%d", Ivalue&7);
      sprintf (result, "r%d", Ivalue&7);
      ioffset -= 3;
      ioffset -= 3;
      break;
      break;
    case 'd':
    case 'd':
      sprintf (result, "%d", get_displacement (buffer, aoffsetp));
      sprintf (result, "%d", get_displacement (buffer, aoffsetp));
      break;
      break;
    case 'b':
    case 'b':
      Ivalue = get_displacement (buffer, aoffsetp);
      Ivalue = get_displacement (buffer, aoffsetp);
      /*
      /*
       * Warning!!  HACK ALERT!
       * Warning!!  HACK ALERT!
       * Operand type 'b' is only used by the cmp{b,w,d} and
       * Operand type 'b' is only used by the cmp{b,w,d} and
       * movm{b,w,d} instructions; we need to know whether
       * movm{b,w,d} instructions; we need to know whether
       * it's a `b' or `w' or `d' instruction; and for both
       * it's a `b' or `w' or `d' instruction; and for both
       * cmpm and movm it's stored at the same place so we
       * cmpm and movm it's stored at the same place so we
       * just grab two bits of the opcode and look at it...
       * just grab two bits of the opcode and look at it...
       *
       *
       */
       */
      size = bit_extract(buffer, ioffset-6, 2);
      size = bit_extract(buffer, ioffset-6, 2);
      if (size == 0)             /* 00 => b */
      if (size == 0)             /* 00 => b */
        size = 1;
        size = 1;
      else if (size == 1)       /* 01 => w */
      else if (size == 1)       /* 01 => w */
        size = 2;
        size = 2;
      else
      else
        size = 4;               /* 11 => d */
        size = 4;               /* 11 => d */
 
 
      sprintf (result, "%d", (Ivalue / size) + 1);
      sprintf (result, "%d", (Ivalue / size) + 1);
      break;
      break;
    case 'p':
    case 'p':
      *result++ = NEXT_IS_ADDR;
      *result++ = NEXT_IS_ADDR;
      sprintf_vma (result, addr + get_displacement (buffer, aoffsetp));
      sprintf_vma (result, addr + get_displacement (buffer, aoffsetp));
      result += strlen (result);
      result += strlen (result);
      *result++ = NEXT_IS_ADDR;
      *result++ = NEXT_IS_ADDR;
      *result = '\0';
      *result = '\0';
      break;
      break;
    case 'i':
    case 'i':
      Ivalue = bit_extract (buffer, *aoffsetp, 8);
      Ivalue = bit_extract (buffer, *aoffsetp, 8);
      *aoffsetp += 8;
      *aoffsetp += 8;
      sprintf (result, "0x%x", Ivalue);
      sprintf (result, "0x%x", Ivalue);
      break;
      break;
    case 'u':
    case 'u':
      Ivalue = bit_extract (buffer, *aoffsetp, 8);
      Ivalue = bit_extract (buffer, *aoffsetp, 8);
      optlist(Ivalue, opt_u, result);
      optlist(Ivalue, opt_u, result);
      *aoffsetp += 8;
      *aoffsetp += 8;
      break;
      break;
    case 'U':
    case 'U':
      Ivalue = bit_extract(buffer, *aoffsetp, 8);
      Ivalue = bit_extract(buffer, *aoffsetp, 8);
      optlist(Ivalue, opt_U, result);
      optlist(Ivalue, opt_U, result);
      *aoffsetp += 8;
      *aoffsetp += 8;
      break;
      break;
    case 'O':
    case 'O':
      Ivalue = bit_extract(buffer, ioffset-9, 9);
      Ivalue = bit_extract(buffer, ioffset-9, 9);
      optlist(Ivalue, opt_O, result);
      optlist(Ivalue, opt_O, result);
      ioffset -= 9;
      ioffset -= 9;
      break;
      break;
    case 'C':
    case 'C':
      Ivalue = bit_extract(buffer, ioffset-4, 4);
      Ivalue = bit_extract(buffer, ioffset-4, 4);
      optlist(Ivalue, opt_C, result);
      optlist(Ivalue, opt_C, result);
      ioffset -= 4;
      ioffset -= 4;
      break;
      break;
    case 'S':
    case 'S':
      Ivalue = bit_extract(buffer, ioffset - 8, 8);
      Ivalue = bit_extract(buffer, ioffset - 8, 8);
      optlist(Ivalue, opt_S, result);
      optlist(Ivalue, opt_S, result);
      ioffset -= 8;
      ioffset -= 8;
      break;
      break;
    case 'M':
    case 'M':
      Ivalue = bit_extract(buffer, ioffset-4, 4);
      Ivalue = bit_extract(buffer, ioffset-4, 4);
      list_search(Ivalue, 0 ? list_M032 : list_M532, result);
      list_search(Ivalue, 0 ? list_M032 : list_M532, result);
      ioffset -= 4;
      ioffset -= 4;
      break;
      break;
    case 'P':
    case 'P':
      Ivalue = bit_extract(buffer, ioffset-4, 4);
      Ivalue = bit_extract(buffer, ioffset-4, 4);
      list_search(Ivalue, 0 ? list_P032 : list_P532, result);
      list_search(Ivalue, 0 ? list_P032 : list_P532, result);
      ioffset -= 4;
      ioffset -= 4;
      break;
      break;
    case 'g':
    case 'g':
      Ivalue = bit_extract(buffer, *aoffsetp, 3);
      Ivalue = bit_extract(buffer, *aoffsetp, 3);
      sprintf(result, "%d", Ivalue);
      sprintf(result, "%d", Ivalue);
      *aoffsetp += 3;
      *aoffsetp += 3;
      break;
      break;
    case 'G':
    case 'G':
      Ivalue = bit_extract(buffer, *aoffsetp, 5);
      Ivalue = bit_extract(buffer, *aoffsetp, 5);
      sprintf(result, "%d", Ivalue + 1);
      sprintf(result, "%d", Ivalue + 1);
      *aoffsetp += 5;
      *aoffsetp += 5;
      break;
      break;
    }
    }
  return ioffset;
  return ioffset;
}
}
 
 
static int
static int
get_displacement (buffer, aoffsetp)
get_displacement (buffer, aoffsetp)
     char *buffer;
     char *buffer;
     int *aoffsetp;
     int *aoffsetp;
{
{
  int Ivalue;
  int Ivalue;
  short Ivalue2;
  short Ivalue2;
 
 
  Ivalue = bit_extract (buffer, *aoffsetp, 8);
  Ivalue = bit_extract (buffer, *aoffsetp, 8);
  switch (Ivalue & 0xc0)
  switch (Ivalue & 0xc0)
    {
    {
    case 0x00:
    case 0x00:
    case 0x40:
    case 0x40:
      Ivalue = sign_extend (Ivalue, 7);
      Ivalue = sign_extend (Ivalue, 7);
      *aoffsetp += 8;
      *aoffsetp += 8;
      break;
      break;
    case 0x80:
    case 0x80:
      Ivalue2 = bit_extract (buffer, *aoffsetp, 16);
      Ivalue2 = bit_extract (buffer, *aoffsetp, 16);
      flip_bytes ((char *) & Ivalue2, 2);
      flip_bytes ((char *) & Ivalue2, 2);
      Ivalue = sign_extend (Ivalue2, 14);
      Ivalue = sign_extend (Ivalue2, 14);
      *aoffsetp += 16;
      *aoffsetp += 16;
      break;
      break;
    case 0xc0:
    case 0xc0:
      Ivalue = bit_extract (buffer, *aoffsetp, 32);
      Ivalue = bit_extract (buffer, *aoffsetp, 32);
      flip_bytes ((char *) & Ivalue, 4);
      flip_bytes ((char *) & Ivalue, 4);
      Ivalue = sign_extend (Ivalue, 30);
      Ivalue = sign_extend (Ivalue, 30);
      *aoffsetp += 32;
      *aoffsetp += 32;
      break;
      break;
    }
    }
  return Ivalue;
  return Ivalue;
}
}


 
 
#if 1 /* a version that should work on ns32k f's&d's on any machine */
#if 1 /* a version that should work on ns32k f's&d's on any machine */
static int
static int
invalid_float (p, len)
invalid_float (p, len)
     register char *p;
     register char *p;
     register int len;
     register int len;
{
{
  register int val;
  register int val;
 
 
  if ( len == 4 )
  if ( len == 4 )
    val = (bit_extract_simple(p, 23, 8)/*exponent*/ == 0xff
    val = (bit_extract_simple(p, 23, 8)/*exponent*/ == 0xff
           || (bit_extract_simple(p, 23, 8)/*exponent*/ == 0 &&
           || (bit_extract_simple(p, 23, 8)/*exponent*/ == 0 &&
               bit_extract_simple(p, 0, 23)/*mantisa*/ != 0));
               bit_extract_simple(p, 0, 23)/*mantisa*/ != 0));
  else if ( len == 8 )
  else if ( len == 8 )
    val = (bit_extract_simple(p, 52, 11)/*exponent*/ == 0x7ff
    val = (bit_extract_simple(p, 52, 11)/*exponent*/ == 0x7ff
           || (bit_extract_simple(p, 52, 11)/*exponent*/ == 0
           || (bit_extract_simple(p, 52, 11)/*exponent*/ == 0
               && (bit_extract_simple(p, 0, 32)/*low mantisa*/ != 0
               && (bit_extract_simple(p, 0, 32)/*low mantisa*/ != 0
                   || bit_extract_simple(p, 32, 20)/*high mantisa*/ != 0)));
                   || bit_extract_simple(p, 32, 20)/*high mantisa*/ != 0)));
  else
  else
    val = 1;
    val = 1;
  return (val);
  return (val);
}
}
#else
#else
 
 
/* assumes the bytes have been swapped to local order */
/* assumes the bytes have been swapped to local order */
typedef union { double d;
typedef union { double d;
                float f;
                float f;
                struct { unsigned m:23, e:8, :1;} sf;
                struct { unsigned m:23, e:8, :1;} sf;
                struct { unsigned lm; unsigned m:20, e:11, :1;} sd;
                struct { unsigned lm; unsigned m:20, e:11, :1;} sd;
              } float_type_u;
              } float_type_u;
 
 
static int
static int
invalid_float (p, len)
invalid_float (p, len)
     register float_type_u *p;
     register float_type_u *p;
     register int len;
     register int len;
{
{
  register int val;
  register int val;
  if ( len == sizeof (float) )
  if ( len == sizeof (float) )
    val = (p->sf.e == 0xff
    val = (p->sf.e == 0xff
           || (p->sf.e == 0 && p->sf.m != 0));
           || (p->sf.e == 0 && p->sf.m != 0));
  else if ( len == sizeof (double) )
  else if ( len == sizeof (double) )
    val = (p->sd.e == 0x7ff
    val = (p->sd.e == 0x7ff
           || (p->sd.e == 0 && (p->sd.m != 0 || p->sd.lm != 0)));
           || (p->sd.e == 0 && (p->sd.m != 0 || p->sd.lm != 0)));
  else
  else
    val = 1;
    val = 1;
  return (val);
  return (val);
}
}
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.