1999-05-03 09:29:11 +02:00
|
|
|
/* Disassemble z8000 code.
|
2020-01-01 08:57:01 +01:00
|
|
|
Copyright (C) 1992-2020 Free Software Foundation, Inc.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-07-05 11:49:03 +02:00
|
|
|
This file is part of the GNU opcodes library.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-07-05 11:49:03 +02:00
|
|
|
This library is free software; you can redistribute it and/or modify
|
2002-04-25 12:59:24 +02:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-05 11:49:03 +02:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
any later version.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-07-05 11:49:03 +02:00
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
License for more details.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2002-04-25 12:59:24 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
2007-07-05 11:49:03 +02:00
|
|
|
along with this file; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
#include "sysdep.h"
|
Move print_insn_XXX to an opcodes internal header
With the changes done in previous patches, print_insn_XXX functions
don't have to be external visible out of opcodes, because both gdb
and objdump select disassemblers through a single interface.
This patch moves these print_insn_XXX declarations from
include/dis-asm.h to opcodes/disassemble.h, which is a new header
added by this patch.
include:
2017-05-24 Yao Qi <yao.qi@linaro.org>
* dis-asm.h: Move some function declarations to
opcodes/disassemble.h.
opcodes:
2017-05-24 Yao Qi <yao.qi@linaro.org>
* alpha-dis.c: Include disassemble.h, don't include
dis-asm.h.
* avr-dis.c, bfin-dis.c, cr16-dis.c: Likewise.
* crx-dis.c, d10v-dis.c, d30v-dis.c: Likewise.
* disassemble.c, dlx-dis.c, epiphany-dis.c: Likewise.
* fr30-dis.c, ft32-dis.c, h8300-dis.c, h8500-dis.c: Likewise.
* hppa-dis.c, i370-dis.c, i386-dis.c: Likewise.
* i860-dis.c, i960-dis.c, ip2k-dis.c: Likewise.
* iq2000-dis.c, lm32-dis.c, m10200-dis.c: Likewise.
* m10300-dis.c, m32r-dis.c, m68hc11-dis.c: Likewise.
* m68k-dis.c, m88k-dis.c, mcore-dis.c: Likewise.
* metag-dis.c, microblaze-dis.c, mmix-dis.c: Likewise.
* moxie-dis.c, msp430-dis.c, mt-dis.c:
* nds32-dis.c, nios2-dis.c, ns32k-dis.c: Likewise.
* or1k-dis.c, pdp11-dis.c, pj-dis.c: Likewise.
* ppc-dis.c, pru-dis.c, riscv-dis.c: Likewise.
* rl78-dis.c, s390-dis.c, score-dis.c: Likewise.
* sh-dis.c, sh64-dis.c, tic30-dis.c: Likewise.
* tic4x-dis.c, tic54x-dis.c, tic6x-dis.c: Likewise.
* tic80-dis.c, tilegx-dis.c, tilepro-dis.c: Likewise.
* v850-dis.c, vax-dis.c, visium-dis.c: Likewise.
* w65-dis.c, wasm32-dis.c, xc16x-dis.c: Likewise.
* xgate-dis.c, xstormy16-dis.c, xtensa-dis.c: Likewise.
* z80-dis.c, z8k-dis.c: Likewise.
* disassemble.h: New file.
2017-05-24 18:23:52 +02:00
|
|
|
#include "disassemble.h"
|
2020-01-08 02:12:36 +01:00
|
|
|
#include "libiberty.h"
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
#define DEFINE_TABLE
|
|
|
|
#include "z8k-opc.h"
|
2003-11-28 21:12:17 +01:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
#include <setjmp.h>
|
2003-12-15 23:01:43 +01:00
|
|
|
|
2002-04-25 12:59:24 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
1999-05-03 09:29:11 +02:00
|
|
|
/* 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 char bytes[24];
|
|
|
|
unsigned short words[24];
|
|
|
|
|
|
|
|
/* Nibble number of first word not yet fetched. */
|
2020-01-08 02:12:36 +01:00
|
|
|
unsigned int max_fetched;
|
1999-05-03 09:29:11 +02:00
|
|
|
bfd_vma insn_start;
|
2014-05-02 17:27:16 +02:00
|
|
|
OPCODES_SIGJMP_BUF bailout;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2003-06-19 15:46:37 +02:00
|
|
|
int tabl_index;
|
1999-05-03 09:29:11 +02:00
|
|
|
char instr_asmsrc[80];
|
|
|
|
unsigned long arg_reg[0x0f];
|
|
|
|
unsigned long immediate;
|
|
|
|
unsigned long displacement;
|
|
|
|
unsigned long address;
|
|
|
|
unsigned long cond_code;
|
|
|
|
unsigned long ctrl_code;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long interrupts;
|
2002-04-25 12:59:24 +02:00
|
|
|
}
|
|
|
|
instr_data_s;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
/* 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) \
|
2001-07-24 02:48:04 +02:00
|
|
|
((nibble) < ((instr_data_s *) (info->private_data))->max_fetched \
|
1999-05-03 09:29:11 +02:00
|
|
|
? 1 : fetch_data ((info), (nibble)))
|
|
|
|
|
|
|
|
static int
|
2003-11-28 21:12:17 +01:00
|
|
|
fetch_data (struct disassemble_info *info, int nibble)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
unsigned char mybuf[20];
|
|
|
|
int status;
|
2000-08-24 19:20:18 +02:00
|
|
|
instr_data_s *priv = (instr_data_s *) info->private_data;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
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);
|
2014-05-02 17:27:16 +02:00
|
|
|
OPCODES_SIGLONGJMP (priv->bailout, 1);
|
1999-05-03 09:29:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int i;
|
2000-08-24 19:20:18 +02:00
|
|
|
unsigned char *p = mybuf;
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
for (i = 0; i < nibble;)
|
|
|
|
{
|
|
|
|
priv->words[i] = (p[0] << 8) | p[1];
|
2000-08-24 19:20:18 +02:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
priv->bytes[i] = *p;
|
|
|
|
priv->nibbles[i++] = *p >> 4;
|
2000-08-24 19:20:18 +02:00
|
|
|
priv->nibbles[i++] = *p & 0xf;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
++p;
|
|
|
|
priv->bytes[i] = *p;
|
|
|
|
priv->nibbles[i++] = *p >> 4;
|
|
|
|
priv->nibbles[i++] = *p & 0xf;
|
|
|
|
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
priv->max_fetched = nibble;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-04-25 12:59:24 +02:00
|
|
|
static char *codes[16] =
|
|
|
|
{
|
|
|
|
"f",
|
|
|
|
"lt",
|
|
|
|
"le",
|
|
|
|
"ule",
|
|
|
|
"ov/pe",
|
|
|
|
"mi",
|
|
|
|
"eq",
|
|
|
|
"c/ult",
|
|
|
|
"t",
|
|
|
|
"ge",
|
|
|
|
"gt",
|
|
|
|
"ugt",
|
|
|
|
"nov/po",
|
|
|
|
"pl",
|
|
|
|
"ne",
|
|
|
|
"nc/uge"
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *ctrl_names[8] =
|
|
|
|
{
|
|
|
|
"<invld>",
|
|
|
|
"flags",
|
|
|
|
"fcw",
|
|
|
|
"refresh",
|
|
|
|
"psapseg",
|
|
|
|
"psapoff",
|
|
|
|
"nspseg",
|
|
|
|
"nspoff"
|
|
|
|
};
|
2001-04-24 17:22:25 +02:00
|
|
|
|
|
|
|
static int seg_length;
|
2003-11-28 21:12:17 +01:00
|
|
|
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);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
static int
|
2003-11-28 21:12:17 +01:00
|
|
|
print_insn_z8k (bfd_vma addr, disassemble_info *info, int is_segmented)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
instr_data_s instr_data;
|
|
|
|
|
|
|
|
info->private_data = (PTR) &instr_data;
|
|
|
|
instr_data.max_fetched = 0;
|
|
|
|
instr_data.insn_start = addr;
|
2014-05-02 17:27:16 +02:00
|
|
|
if (OPCODES_SIGSETJMP (instr_data.bailout) != 0)
|
1999-05-03 09:29:11 +02:00
|
|
|
/* Error return. */
|
|
|
|
return -1;
|
|
|
|
|
2002-04-25 12:59:24 +02:00
|
|
|
info->bytes_per_chunk = 2;
|
|
|
|
info->bytes_per_line = 6;
|
|
|
|
info->display_endian = BFD_ENDIAN_BIG;
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
instr_data.tabl_index = z8k_lookup_instr (instr_data.nibbles, info);
|
2003-06-19 15:46:37 +02:00
|
|
|
if (instr_data.tabl_index >= 0)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
unpack_instr (&instr_data, is_segmented, info);
|
2001-04-24 17:22:25 +02:00
|
|
|
unparse_instr (&instr_data, is_segmented);
|
1999-05-03 09:29:11 +02:00
|
|
|
output_instr (&instr_data, addr, info);
|
2001-04-24 17:22:25 +02:00
|
|
|
return z8k_table[instr_data.tabl_index].length + seg_length;
|
1999-05-03 09:29:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FETCH_DATA (info, 4);
|
|
|
|
(*info->fprintf_func) (info->stream, ".word %02x%02x",
|
|
|
|
instr_data.bytes[0], instr_data.bytes[2]);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-11-28 21:12:17 +01:00
|
|
|
print_insn_z8001 (bfd_vma addr, disassemble_info *info)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
return print_insn_z8k (addr, info, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-11-28 21:12:17 +01:00
|
|
|
print_insn_z8002 (bfd_vma addr, disassemble_info *info)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
return print_insn_z8k (addr, info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-11-28 21:12:17 +01:00
|
|
|
z8k_lookup_instr (unsigned char *nibbles, disassemble_info *info)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2020-01-08 02:12:36 +01:00
|
|
|
unsigned int nibl_index, tabl_index;
|
1999-05-03 09:29:11 +02:00
|
|
|
int nibl_matched;
|
2003-05-01 21:59:33 +02:00
|
|
|
int need_fetch = 0;
|
1999-05-03 09:29:11 +02:00
|
|
|
unsigned short instr_nibl;
|
|
|
|
unsigned short tabl_datum, datum_class, datum_value;
|
|
|
|
|
|
|
|
nibl_matched = 0;
|
|
|
|
tabl_index = 0;
|
2003-05-01 21:59:33 +02:00
|
|
|
FETCH_DATA (info, 4);
|
1999-05-03 09:29:11 +02:00
|
|
|
while (!nibl_matched && z8k_table[tabl_index].name)
|
|
|
|
{
|
|
|
|
nibl_matched = 1;
|
2000-08-24 19:20:18 +02:00
|
|
|
for (nibl_index = 0;
|
2020-01-08 02:12:36 +01:00
|
|
|
nibl_matched
|
|
|
|
&& nibl_index < ARRAY_SIZE (z8k_table[0].byte_info)
|
|
|
|
&& nibl_index < z8k_table[tabl_index].length * 2;
|
2000-08-24 19:20:18 +02:00
|
|
|
nibl_index++)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
if ((nibl_index % 4) == 0)
|
2003-05-01 21:59:33 +02:00
|
|
|
{
|
|
|
|
/* 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;
|
|
|
|
}
|
1999-05-03 09:29:11 +02:00
|
|
|
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;
|
2002-04-25 12:59:24 +02:00
|
|
|
case CLASS_IGNORE:
|
|
|
|
break;
|
1999-05-03 09:29:11 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2002-04-25 12:59:24 +02:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
if (nibl_matched)
|
2002-04-25 12:59:24 +02:00
|
|
|
return tabl_index;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
tabl_index++;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-28 21:12:17 +01:00
|
|
|
output_instr (instr_data_s *instr_data,
|
|
|
|
unsigned long addr ATTRIBUTE_UNUSED,
|
|
|
|
disassemble_info *info)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2020-01-08 02:12:36 +01:00
|
|
|
unsigned int num_bytes;
|
1999-05-03 09:29:11 +02:00
|
|
|
char out_str[100];
|
|
|
|
|
2002-04-25 12:59:24 +02:00
|
|
|
out_str[0] = 0;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2002-04-25 12:59:24 +02:00
|
|
|
num_bytes = (z8k_table[instr_data->tabl_index].length + seg_length) * 2;
|
|
|
|
FETCH_DATA (info, num_bytes);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
strcat (out_str, instr_data->instr_asmsrc);
|
|
|
|
|
|
|
|
(*info->fprintf_func) (info->stream, "%s", out_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-28 21:12:17 +01:00
|
|
|
unpack_instr (instr_data_s *instr_data, int is_segmented, disassemble_info *info)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2020-01-08 02:12:36 +01:00
|
|
|
unsigned int nibl_count, loop;
|
1999-05-03 09:29:11 +02:00
|
|
|
unsigned short instr_nibl, instr_byte, instr_word;
|
|
|
|
long instr_long;
|
2001-04-24 17:22:25 +02:00
|
|
|
unsigned int tabl_datum, datum_class;
|
|
|
|
unsigned short datum_value;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
nibl_count = 0;
|
|
|
|
loop = 0;
|
2001-04-24 17:22:25 +02:00
|
|
|
seg_length = 0;
|
2002-04-25 12:59:24 +02:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
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];
|
2001-07-24 02:48:04 +02:00
|
|
|
instr_byte = instr_data->bytes[nibl_count & ~1];
|
|
|
|
instr_word = instr_data->words[nibl_count & ~3];
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
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:
|
2001-08-13 10:09:58 +02:00
|
|
|
instr_data->displacement = instr_data->insn_start + 4
|
|
|
|
+ (signed short) (instr_word & 0xffff);
|
1999-05-03 09:29:11 +02:00
|
|
|
nibl_count += 3;
|
|
|
|
break;
|
|
|
|
case ARG_DISP12:
|
2001-08-13 10:09:58 +02:00
|
|
|
if (instr_word & 0x800)
|
2002-04-25 12:59:24 +02:00
|
|
|
/* Negative 12 bit displacement. */
|
|
|
|
instr_data->displacement = instr_data->insn_start + 2
|
|
|
|
- (signed short) ((instr_word & 0xfff) | 0xf000) * 2;
|
2001-08-13 10:09:58 +02:00
|
|
|
else
|
2002-04-25 12:59:24 +02:00
|
|
|
instr_data->displacement = instr_data->insn_start + 2
|
|
|
|
- (instr_word & 0x0fff) * 2;
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
nibl_count += 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CLASS_IMM:
|
|
|
|
switch (datum_value)
|
|
|
|
{
|
|
|
|
case ARG_IMM4:
|
|
|
|
instr_data->immediate = instr_nibl;
|
|
|
|
break;
|
2002-04-25 12:59:24 +02:00
|
|
|
case ARG_NIM4:
|
|
|
|
instr_data->immediate = (- instr_nibl) & 0xf;
|
|
|
|
break;
|
1999-05-03 09:29:11 +02:00
|
|
|
case ARG_NIM8:
|
2002-04-25 12:59:24 +02:00
|
|
|
instr_data->immediate = (- instr_byte) & 0xff;
|
1999-05-03 09:29:11 +02:00
|
|
|
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]);
|
2003-05-01 21:59:33 +02:00
|
|
|
instr_data->address = ((instr_word & 0x7f00) << 16)
|
2001-08-13 10:09:58 +02:00
|
|
|
+ (instr_long & 0xffff);
|
1999-05-03 09:29:11 +02:00
|
|
|
nibl_count += 7;
|
2001-08-13 10:09:58 +02:00
|
|
|
seg_length = 2;
|
1999-05-03 09:29:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-05-01 21:59:33 +02:00
|
|
|
instr_data->address = ((instr_word & 0x7f00) << 16)
|
2001-08-13 10:09:58 +02:00
|
|
|
+ (instr_word & 0x00ff);
|
1999-05-03 09:29:11 +02:00
|
|
|
nibl_count += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
instr_data->address = instr_word;
|
|
|
|
nibl_count += 3;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CLASS_0CCC:
|
|
|
|
case CLASS_1CCC:
|
2001-04-24 17:22:25 +02:00
|
|
|
instr_data->ctrl_code = instr_nibl & 0x7;
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
case CLASS_0DISP7:
|
2001-08-13 10:09:58 +02:00
|
|
|
instr_data->displacement =
|
|
|
|
instr_data->insn_start + 2 - (instr_byte & 0x7f) * 2;
|
1999-05-03 09:29:11 +02:00
|
|
|
nibl_count += 1;
|
|
|
|
break;
|
|
|
|
case CLASS_1DISP7:
|
2001-08-13 10:09:58 +02:00
|
|
|
instr_data->displacement =
|
|
|
|
instr_data->insn_start + 2 - (instr_byte & 0x7f) * 2;
|
1999-05-03 09:29:11 +02:00
|
|
|
nibl_count += 1;
|
|
|
|
break;
|
|
|
|
case CLASS_01II:
|
|
|
|
instr_data->interrupts = instr_nibl & 0x3;
|
|
|
|
break;
|
|
|
|
case CLASS_00II:
|
|
|
|
instr_data->interrupts = instr_nibl & 0x3;
|
|
|
|
break;
|
2002-04-25 12:59:24 +02:00
|
|
|
case CLASS_IGNORE:
|
1999-05-03 09:29:11 +02:00
|
|
|
case CLASS_BIT:
|
2001-04-24 17:22:25 +02:00
|
|
|
instr_data->ctrl_code = instr_nibl & 0x7;
|
1999-05-03 09:29:11 +02:00
|
|
|
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;
|
2001-08-13 10:09:58 +02:00
|
|
|
case CLASS_DISP8:
|
|
|
|
instr_data->displacement =
|
|
|
|
instr_data->insn_start + 2 + (signed char) instr_byte * 2;
|
2001-04-24 17:22:25 +02:00
|
|
|
nibl_count += 1;
|
2001-08-13 10:09:58 +02:00
|
|
|
break;
|
2002-04-25 12:59:24 +02:00
|
|
|
case CLASS_BIT_1OR2:
|
|
|
|
instr_data->immediate = ((instr_nibl >> 1) & 0x1) + 1;
|
|
|
|
nibl_count += 1;
|
|
|
|
break;
|
1999-05-03 09:29:11 +02:00
|
|
|
default:
|
2001-08-13 10:09:58 +02:00
|
|
|
abort ();
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
loop += 1;
|
|
|
|
nibl_count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-15 23:01:43 +01:00
|
|
|
static void
|
|
|
|
print_intr(char *tmp_str, unsigned long interrupts)
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_flags(char *tmp_str, unsigned long flags)
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2003-05-01 21:59:33 +02:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
static void
|
2003-11-28 21:12:17 +01:00
|
|
|
unparse_instr (instr_data_s *instr_data, int is_segmented)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2001-04-24 17:22:25 +02:00
|
|
|
unsigned short datum_value;
|
|
|
|
unsigned int tabl_datum, datum_class;
|
1999-05-03 09:29:11 +02:00
|
|
|
int loop, loop_limit;
|
|
|
|
char out_str[80], tmp_str[25];
|
|
|
|
|
2002-04-25 12:59:24 +02:00
|
|
|
sprintf (out_str, "%s\t", z8k_table[instr_data->tabl_index].name);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
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:
|
2002-04-25 12:59:24 +02:00
|
|
|
sprintf (tmp_str, "0x%0lx(r%ld)", instr_data->address,
|
|
|
|
instr_data->arg_reg[datum_value]);
|
1999-05-03 09:29:11 +02:00
|
|
|
strcat (out_str, tmp_str);
|
|
|
|
break;
|
|
|
|
case CLASS_BA:
|
2002-04-25 12:59:24 +02:00
|
|
|
if (is_segmented)
|
2002-08-22 21:22:35 +02:00
|
|
|
sprintf (tmp_str, "rr%ld(#0x%lx)", instr_data->arg_reg[datum_value],
|
2002-04-25 12:59:24 +02:00
|
|
|
instr_data->immediate);
|
|
|
|
else
|
2002-08-22 21:22:35 +02:00
|
|
|
sprintf (tmp_str, "r%ld(#0x%lx)", instr_data->arg_reg[datum_value],
|
2002-04-25 12:59:24 +02:00
|
|
|
instr_data->immediate);
|
1999-05-03 09:29:11 +02:00
|
|
|
strcat (out_str, tmp_str);
|
|
|
|
break;
|
|
|
|
case CLASS_BX:
|
2002-04-25 12:59:24 +02:00
|
|
|
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]);
|
1999-05-03 09:29:11 +02:00
|
|
|
strcat (out_str, tmp_str);
|
|
|
|
break;
|
|
|
|
case CLASS_DISP:
|
2001-04-24 17:22:25 +02:00
|
|
|
sprintf (tmp_str, "0x%0lx", instr_data->displacement);
|
1999-05-03 09:29:11 +02:00
|
|
|
strcat (out_str, tmp_str);
|
|
|
|
break;
|
|
|
|
case CLASS_IMM:
|
2003-12-15 23:01:43 +01:00
|
|
|
if (datum_value == ARG_IMM2) /* True with EI/DI instructions only. */
|
|
|
|
{
|
|
|
|
print_intr (tmp_str, instr_data->interrupts);
|
|
|
|
strcat (out_str, tmp_str);
|
|
|
|
break;
|
|
|
|
}
|
1999-05-03 09:29:11 +02:00
|
|
|
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:
|
2001-04-24 17:22:25 +02:00
|
|
|
sprintf (tmp_str, "%s", ctrl_names[instr_data->ctrl_code]);
|
1999-05-03 09:29:11 +02:00
|
|
|
strcat (out_str, tmp_str);
|
|
|
|
break;
|
|
|
|
case CLASS_DA:
|
|
|
|
case CLASS_ADDRESS:
|
2001-04-24 17:22:25 +02:00
|
|
|
sprintf (tmp_str, "0x%0lx", instr_data->address);
|
1999-05-03 09:29:11 +02:00
|
|
|
strcat (out_str, tmp_str);
|
|
|
|
break;
|
|
|
|
case CLASS_IR:
|
2001-10-09 19:25:58 +02:00
|
|
|
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]);
|
1999-05-03 09:29:11 +02:00
|
|
|
strcat (out_str, tmp_str);
|
|
|
|
break;
|
2003-06-19 15:46:37 +02:00
|
|
|
case CLASS_IRO:
|
|
|
|
sprintf (tmp_str, "@r%ld", instr_data->arg_reg[datum_value]);
|
|
|
|
strcat (out_str, tmp_str);
|
|
|
|
break;
|
1999-05-03 09:29:11 +02:00
|
|
|
case CLASS_FLAGS:
|
2003-12-15 23:01:43 +01:00
|
|
|
print_flags(tmp_str, instr_data->flags);
|
1999-05-03 09:29:11 +02:00
|
|
|
strcat (out_str, tmp_str);
|
|
|
|
break;
|
|
|
|
case CLASS_REG_BYTE:
|
|
|
|
if (instr_data->arg_reg[datum_value] >= 0x8)
|
2001-10-09 19:25:58 +02:00
|
|
|
sprintf (tmp_str, "rl%ld",
|
|
|
|
instr_data->arg_reg[datum_value] - 0x8);
|
1999-05-03 09:29:11 +02:00
|
|
|
else
|
2001-10-09 19:25:58 +02:00
|
|
|
sprintf (tmp_str, "rh%ld", instr_data->arg_reg[datum_value]);
|
1999-05-03 09:29:11 +02:00
|
|
|
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;
|
2001-04-24 17:22:25 +02:00
|
|
|
case CLASS_PR:
|
2001-08-13 10:09:58 +02:00
|
|
|
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]);
|
2001-04-24 17:22:25 +02:00
|
|
|
strcat (out_str, tmp_str);
|
|
|
|
break;
|
1999-05-03 09:29:11 +02:00
|
|
|
default:
|
2001-08-13 10:09:58 +02:00
|
|
|
abort ();
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy (instr_data->instr_asmsrc, out_str);
|
|
|
|
}
|