-/*
+/* Disassemble z8000 code.
+ Copyright 1992, 1993, 1998, 2000, 2001
+ Free Software Foundation, Inc.
+
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-#include <ansidecl.h>
#include "sysdep.h"
#include "dis-asm.h"
#define DEFINE_TABLE
#include "z8k-opc.h"
-
\f
#include <setjmp.h>
-
\f
-typedef struct
-{
+typedef struct {
/* These are all indexed by nibble number (i.e only every other entry
of bytes is used, and every 4th entry of words). */
unsigned char nibbles[24];
unsigned long ctrl_code;
unsigned long flags;
unsigned long interrupts;
-}
-instr_data_s;
+} instr_data_s;
+
+static int fetch_data PARAMS ((struct disassemble_info *, int));
+
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
to ADDR (exclusive) are valid. Returns 1 for success, longjmps
on error. */
#define FETCH_DATA(info, nibble) \
- ((nibble) <= ((instr_data_s *)(info->private_data))->max_fetched \
+ ((nibble) < ((instr_data_s *) (info->private_data))->max_fetched \
? 1 : fetch_data ((info), (nibble)))
static int
{
unsigned char mybuf[20];
int status;
- instr_data_s *priv = (instr_data_s *)info->private_data;
- bfd_vma start = priv->insn_start + priv->max_fetched / 2;
+ instr_data_s *priv = (instr_data_s *) info->private_data;
if ((nibble % 4) != 0)
abort ();
- status = (*info->read_memory_func) (start,
+
+ status = (*info->read_memory_func) (priv->insn_start,
(bfd_byte *) mybuf,
- (nibble - priv->max_fetched) / 2,
+ nibble / 2,
info);
if (status != 0)
{
- (*info->memory_error_func) (status, start, info);
+ (*info->memory_error_func) (status, priv->insn_start, info);
longjmp (priv->bailout, 1);
}
{
int i;
- char *p = mybuf + priv->max_fetched / 2;
-
- for (i = priv->max_fetched; i < nibble;)
+ 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;
+ priv->nibbles[i++] = *p & 0xf;
++p;
priv->bytes[i] = *p;
return 1;
}
-static char *codes[16] =
-{
+static char *codes[16] = {
"f",
"lt",
"le",
"nc/uge"
};
-int z8k_lookup_instr PARAMS ((unsigned char*, disassemble_info *));
+static char *ctrl_names[8] = {
+ "<invld>",
+ "flags",
+ "fcw",
+ "refresh",
+ "psapseg",
+ "psapoff",
+ "nspseg",
+ "nspoff"
+};
+
+static int seg_length;
+static int print_insn_z8k PARAMS ((bfd_vma, disassemble_info *, int));
+int z8k_lookup_instr PARAMS ((unsigned char *, disassemble_info *));
static void output_instr
PARAMS ((instr_data_s *, unsigned long, disassemble_info *));
static void unpack_instr PARAMS ((instr_data_s *, int, disassemble_info *));
-static void unparse_instr PARAMS ((instr_data_s *));
+static void unparse_instr PARAMS ((instr_data_s *, int));
static int
print_insn_z8k (addr, info, is_segmented)
- unsigned long addr;
+ bfd_vma addr;
disassemble_info *info;
int is_segmented;
{
if (instr_data.tabl_index > 0)
{
unpack_instr (&instr_data, is_segmented, info);
- unparse_instr (&instr_data);
+ unparse_instr (&instr_data, is_segmented);
output_instr (&instr_data, addr, info);
- return z8k_table[instr_data.tabl_index].length;
+ return z8k_table[instr_data.tabl_index].length + seg_length;
}
else
{
}
}
+int
print_insn_z8001 (addr, info)
- unsigned long addr;
+ bfd_vma addr;
disassemble_info *info;
{
return print_insn_z8k (addr, info, 1);
}
+int
print_insn_z8002 (addr, info)
- unsigned long addr;
+ bfd_vma addr;
disassemble_info *info;
{
return print_insn_z8k (addr, info, 0);
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++)
+ for (nibl_index = 0;
+ nibl_index < z8k_table[tabl_index].length * 2 && nibl_matched;
+ nibl_index++)
{
if ((nibl_index % 4) == 0)
/* Fetch one word at a time. */
tabl_index++;
}
return -1;
-
}
static void
output_instr (instr_data, addr, info)
instr_data_s *instr_data;
- unsigned long addr;
+ unsigned long addr ATTRIBUTE_UNUSED;
disassemble_info *info;
{
int loop, loop_limit;
strcpy (out_str, "\t");
- loop_limit = z8k_table[instr_data->tabl_index].length * 2;
+ loop_limit = (z8k_table[instr_data->tabl_index].length + seg_length) * 2;
FETCH_DATA (info, loop_limit);
for (loop = 0; loop < loop_limit; loop++)
{
int nibl_count, loop;
unsigned short instr_nibl, instr_byte, instr_word;
long instr_long;
- unsigned short tabl_datum, datum_class, datum_value;
+ 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];
- instr_word = instr_data->words[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;
switch (datum_class)
{
- case CLASS_X:
- instr_data->address = instr_nibl;
- break;
- case CLASS_BA:
- instr_data->displacement = instr_nibl;
- break;
- case CLASS_BX:
- instr_data->arg_reg[datum_value] = instr_nibl;
- break;
case CLASS_DISP:
switch (datum_value)
{
case ARG_DISP16:
- instr_data->displacement = instr_word;
+ instr_data->displacement = instr_data->insn_start + 4
+ + (signed short) (instr_word & 0xffff);
nibl_count += 3;
break;
case ARG_DISP12:
- instr_data->displacement = instr_word & 0x0fff;
+ if (instr_word & 0x800)
+ {
+ /* neg. 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:
case ARG_IMMN:
instr_data->immediate = instr_nibl - 1;
break;
- /* ????? */
- /* missing ARG_IMMNMINUS1 */
+ case ARG_IMM4M1:
+ instr_data->immediate = instr_nibl + 1;
+ break;
case ARG_IMM_1:
instr_data->immediate = 1;
break;
case CLASS_CC:
instr_data->cond_code = instr_nibl;
break;
- case CLASS_CTRL:
- instr_data->ctrl_code = instr_nibl;
- break;
- case CLASS_DA:
case CLASS_ADDRESS:
if (is_segmented)
{
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) << 8) +
- (instr_long & 0xffff);
+ instr_data->address = ((instr_word & 0x7f00) << 8)
+ + (instr_long & 0xffff);
nibl_count += 7;
+ seg_length = 2;
}
else
{
- instr_data->address = ((instr_word & 0x7f00) << 8) +
- (instr_word & 0x00ff);
+ instr_data->address = ((instr_word & 0x7f00) << 8)
+ + (instr_word & 0x00ff);
nibl_count += 3;
}
}
}
break;
case CLASS_0CCC:
- instr_data->cond_code = instr_nibl & 0x7;
- break;
case CLASS_1CCC:
- instr_data->cond_code = instr_nibl & 0x7;
+ instr_data->ctrl_code = instr_nibl & 0x7;
break;
case CLASS_0DISP7:
- instr_data->displacement = instr_byte & 0x7f;
+ instr_data->displacement =
+ instr_data->insn_start + 2 - (instr_byte & 0x7f) * 2;
nibl_count += 1;
break;
case CLASS_1DISP7:
- instr_data->displacement = instr_byte & 0x7f;
+ 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_BIT:
- /* do nothing */
- break;
- case CLASS_IR:
- instr_data->arg_reg[datum_value] = instr_nibl;
+ instr_data->ctrl_code = instr_nibl & 0x7;
break;
case CLASS_FLAGS:
instr_data->flags = instr_nibl;
case CLASS_REG:
instr_data->arg_reg[datum_value] = instr_nibl;
break;
- case CLASS_REG_BYTE:
- instr_data->arg_reg[datum_value] = instr_nibl;
- break;
- case CLASS_REG_WORD:
- instr_data->arg_reg[datum_value] = instr_nibl;
- break;
- case CLASS_REG_QUAD:
- instr_data->arg_reg[datum_value] = instr_nibl;
- break;
- case CLASS_REG_LONG:
- 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;
default:
+ abort ();
break;
}
}
static void
-unparse_instr (instr_data)
+unparse_instr (instr_data, is_segmented)
instr_data_s *instr_data;
+ int is_segmented;
{
- unsigned short tabl_datum, datum_class, datum_value;
+ unsigned short datum_value;
+ unsigned int tabl_datum, datum_class;
int loop, loop_limit;
char out_str[80], tmp_str[25];
switch (datum_class)
{
case CLASS_X:
- sprintf (tmp_str, "0x%0x(R%d)", instr_data->address,
+ 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:
- sprintf (tmp_str, "r%d(#%x)", instr_data->arg_reg[datum_value],
+ sprintf (tmp_str, "r%ld(#%lx)", instr_data->arg_reg[datum_value],
instr_data->immediate);
strcat (out_str, tmp_str);
break;
case CLASS_BX:
- sprintf (tmp_str, "r%d(R%d)", instr_data->arg_reg[datum_value],
+ 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%0x", instr_data->displacement);
+ sprintf (tmp_str, "0x%0lx", instr_data->displacement);
strcat (out_str, tmp_str);
break;
case CLASS_IMM:
- sprintf (tmp_str, "#0x%0x", instr_data->immediate);
+ sprintf (tmp_str, "#0x%0lx", instr_data->immediate);
strcat (out_str, tmp_str);
break;
case CLASS_CC:
strcat (out_str, tmp_str);
break;
case CLASS_CTRL:
- sprintf (tmp_str, "0x%0x", instr_data->ctrl_code);
+ 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%0x", instr_data->address);
+ sprintf (tmp_str, "0x%0lx", instr_data->address);
strcat (out_str, tmp_str);
break;
case CLASS_IR:
- sprintf (tmp_str, "@R%d", instr_data->arg_reg[datum_value]);
+ sprintf (tmp_str, "@R%ld", instr_data->arg_reg[datum_value]);
strcat (out_str, tmp_str);
break;
case CLASS_FLAGS:
- sprintf (tmp_str, "0x%0x", instr_data->flags);
+ sprintf (tmp_str, "0x%0lx", 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%d",
+ sprintf (tmp_str, "rl%ld",
instr_data->arg_reg[datum_value] - 0x8);
}
else
{
- sprintf (tmp_str, "rh%d", instr_data->arg_reg[datum_value]);
+ 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%d", instr_data->arg_reg[datum_value]);
+ 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%d", instr_data->arg_reg[datum_value]);
+ 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%d", instr_data->arg_reg[datum_value]);
+ 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;
}
}