1991-10-01 04:43:11 +01:00
|
|
|
/* BFD library support routines for the Hitachi H8/300 architecture.
|
|
|
|
Copyright (C) 1990-1991 Free Software Foundation, Inc.
|
|
|
|
Hacked by Steve Chamberlain of Cygnus Support.
|
|
|
|
|
|
|
|
This file is part of BFD, the Binary File Descriptor library.
|
|
|
|
|
|
|
|
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
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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.
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
|
|
|
#include "bfd.h"
|
1991-11-27 17:56:08 +01:00
|
|
|
#include "sysdep.h"
|
1991-10-01 04:43:11 +01:00
|
|
|
#include "libbfd.h"
|
|
|
|
|
|
|
|
#define DEFINE_TABLE
|
* aout-encap.c, aoutf1.h, aoutx.h, archive.c, bout.c, coff-a29k.c,
coff-h8300.c, coff-i386.c, coff-i960.c, coff-m68k.c, coff-m88k.c,
coff-mips.c, coff-rs6000.c, cpu-h300.c, elf.c, i386aout.c,
newos3.c, stab-syms.c, syms.c: All these files have had their
#includes altered to point to the new places.
1991-12-01 06:24:02 +01:00
|
|
|
#include "opcode/h8300.h"
|
1991-10-01 04:43:11 +01:00
|
|
|
|
|
|
|
#define MAXSAME 14
|
|
|
|
|
|
|
|
static struct h8_opcode * h8_opcodes_sorted[256][MAXSAME];
|
|
|
|
|
|
|
|
/* Run through the opcodes and sort them into order to make them easy
|
|
|
|
to disassemble
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
DEFUN_VOID(bfd_h8_disassemble_init)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct h8_opcode *p;
|
|
|
|
|
|
|
|
for (p = h8_opcodes; p->name; p++) {
|
|
|
|
int where = 0;
|
|
|
|
int n1 = 0;
|
|
|
|
int n2 = 0;
|
|
|
|
int n3 = 0;
|
|
|
|
int n4= 0;
|
|
|
|
if ((int)p->data.nib[0] < 16) {
|
|
|
|
n1 =(int) p->data.nib[0] ;
|
|
|
|
} else n1 = 0;
|
|
|
|
if ((int)p->data.nib[1] < 16) {
|
|
|
|
n2 = (int) p->data.nib[1];
|
|
|
|
}else n2 = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXSAME; i++) {
|
|
|
|
int j = n1 * 16 + n2;
|
|
|
|
if (h8_opcodes_sorted[j][i] == (struct h8_opcode *)NULL) {
|
|
|
|
h8_opcodes_sorted[j][i] = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i==MAXSAME)abort();
|
|
|
|
|
|
|
|
/* Just make sure there are an even number of nibbles in it, and
|
|
|
|
that the count is the same s the length */
|
|
|
|
for (i = 0; p->data.nib[i] != E; i++) ;
|
|
|
|
if (i & 1) abort();
|
|
|
|
if (i/2 != p->length) abort();
|
|
|
|
}
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
if (h8_opcodes_sorted[i][0])
|
|
|
|
p = h8_opcodes_sorted[i][0];
|
|
|
|
else h8_opcodes_sorted[i][0] = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1991-10-05 01:39:21 +01:00
|
|
|
|
1991-10-01 04:43:11 +01:00
|
|
|
unsigned int
|
|
|
|
DEFUN(bfd_h8_disassemble,(addr, data, stream),
|
|
|
|
bfd_vma addr AND
|
|
|
|
CONST bfd_byte *data AND
|
|
|
|
FILE *stream)
|
|
|
|
{
|
|
|
|
/* Find the first entry in the table for this opcode */
|
1991-10-05 01:39:21 +01:00
|
|
|
CONST static char *regnames[] = {
|
|
|
|
"r0h","r1h","r2h","r3h","r4h","r5h","r6h","r7h",
|
|
|
|
"r0l","r1l","r2l","r3l","r4l","r5l","r6l","r7l" };
|
|
|
|
|
1991-10-01 04:43:11 +01:00
|
|
|
int rs = 0;
|
|
|
|
int rd = 0;
|
|
|
|
int rdisp = 0;
|
|
|
|
int abs = 0;
|
|
|
|
struct h8_opcode **p = h8_opcodes_sorted[(unsigned)(data[0])];
|
|
|
|
struct h8_opcode *q;
|
|
|
|
|
|
|
|
/* Find the exact opcode/arg combo */
|
|
|
|
while (*p) {
|
1991-11-27 17:56:08 +01:00
|
|
|
op_type *nib;
|
1991-10-01 04:43:11 +01:00
|
|
|
unsigned int len = 0;
|
|
|
|
q = *p++;
|
|
|
|
nib =q->data.nib;
|
|
|
|
while (*nib != E) {
|
1991-11-27 17:56:08 +01:00
|
|
|
op_type looking_for = *nib;
|
1991-10-01 04:43:11 +01:00
|
|
|
int thisnib = data[len>>1] ;
|
|
|
|
thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib >> 4) & 0xf);
|
|
|
|
if ((int)looking_for & (int)B31) {
|
|
|
|
if (((int)thisnib & 0x8) ==0) goto fail;
|
1991-11-27 17:56:08 +01:00
|
|
|
looking_for = (op_type)((int)looking_for & ~(int)B31);
|
1991-10-01 04:43:11 +01:00
|
|
|
}
|
|
|
|
if ((int)looking_for & (int)B30) {
|
|
|
|
if (((int)thisnib & 0x8) !=0) goto fail;
|
1991-11-27 17:56:08 +01:00
|
|
|
looking_for = (op_type)((int)looking_for & ~(int)B30);
|
1991-10-01 04:43:11 +01:00
|
|
|
}
|
|
|
|
switch (looking_for) {
|
|
|
|
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
|
|
|
|
case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
|
|
|
|
if ((int)looking_for != thisnib) goto fail;
|
|
|
|
break;
|
|
|
|
case ABS16SRC:
|
|
|
|
case ABS16DST:
|
|
|
|
case DISPSRC:
|
|
|
|
case DISPDST:
|
|
|
|
case IMM16:
|
|
|
|
abs = (data[len>>1]) * 256 + data[(len+2)>>1];
|
|
|
|
len+=3;
|
|
|
|
nib+=3;
|
|
|
|
break;
|
|
|
|
case DISPREG:
|
|
|
|
rdisp = thisnib;
|
|
|
|
break;
|
|
|
|
case KBIT:
|
1991-11-27 17:56:08 +01:00
|
|
|
abs = thisnib == 0x8 ? 2:1;
|
1991-10-01 04:43:11 +01:00
|
|
|
break;
|
|
|
|
case IMM8:
|
|
|
|
case ABS8SRC:
|
|
|
|
case ABS8DST:
|
1991-12-01 08:53:50 +01:00
|
|
|
case MEMIND:
|
1991-10-01 04:43:11 +01:00
|
|
|
case DISP8:
|
|
|
|
abs= data[len>>1];
|
|
|
|
len++;
|
|
|
|
nib++;
|
|
|
|
break;
|
|
|
|
case IMM3:
|
|
|
|
abs = thisnib ;
|
|
|
|
break;
|
|
|
|
case RS8:
|
|
|
|
case RS16:
|
|
|
|
case RSINC:
|
|
|
|
case RSIND:
|
|
|
|
rs = thisnib;
|
|
|
|
break;
|
|
|
|
case RD16:
|
|
|
|
case RDDEC:
|
|
|
|
case RD8:
|
|
|
|
case RDIND:
|
|
|
|
rd = thisnib;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stream, "Dont understand \n");
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
len++;
|
|
|
|
nib++;
|
|
|
|
}
|
|
|
|
goto found;
|
|
|
|
fail:
|
|
|
|
;
|
|
|
|
|
|
|
|
}
|
1991-11-27 17:56:08 +01:00
|
|
|
fprintf(stream, "%02x %02x .word\tH'%x,H'%x",
|
1991-10-05 01:39:21 +01:00
|
|
|
data[0], data[1],
|
|
|
|
data[0], data[1]);
|
1991-10-01 04:43:11 +01:00
|
|
|
return 2;
|
|
|
|
found:;
|
|
|
|
{ int i;
|
|
|
|
|
|
|
|
for (i = 0; i < q->length; i++) {
|
|
|
|
fprintf(stream, "%02x ", data[i]);
|
|
|
|
}
|
|
|
|
for (; i < 6; i++) {
|
|
|
|
fprintf(stream, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stream, "%s\t",q->name);
|
|
|
|
/* Now print out the args */
|
|
|
|
{
|
1991-11-27 17:56:08 +01:00
|
|
|
op_type *args = q->args.nib;
|
1991-10-01 04:43:11 +01:00
|
|
|
int hadone = 0;
|
|
|
|
while (*args != E) {
|
|
|
|
if (hadone)
|
|
|
|
fprintf(stream, ",");
|
|
|
|
switch ((int)(*args) & ~((int)B30|(int)B31)) {
|
|
|
|
case IMM16:
|
|
|
|
case IMM8:
|
|
|
|
case IMM3:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "#0x%x", (unsigned)abs);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case RD8:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "%s", regnames[rd]);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case RS8:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "%s",regnames[rs]);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case RD16:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "r%d", rd& 0x7);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case RS16:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "r%d", rs & 0x7);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case RSINC:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "@r%d+", rs & 0x7);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case RDDEC:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "@-r%d", rd & 0x7);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case RDIND:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "@r%d", rd & 0x7);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case RSIND:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "@r%d",rs & 0x7);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case ABS8SRC:
|
|
|
|
case ABS16SRC:
|
|
|
|
case ABS16DST:
|
|
|
|
case ABS8DST:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "@0x%x", (unsigned)abs);
|
|
|
|
break;
|
|
|
|
case MEMIND:
|
|
|
|
fprintf(stream, "@@%d (%x)",abs, abs);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case DISP8:
|
1991-10-05 01:39:21 +01:00
|
|
|
fprintf(stream, ".%s%d (%x)",(char)abs>0 ? "+" :"", (char)abs,
|
|
|
|
addr + (char)abs);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case DISPSRC:
|
|
|
|
case DISPDST:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "@(0x%x,r%d)", abs, rdisp & 0x7);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case CCR:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "ccr");
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
case KBIT:
|
1991-12-01 08:53:50 +01:00
|
|
|
fprintf(stream, "#%d",abs);
|
|
|
|
break;
|
1991-10-01 04:43:11 +01:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
hadone = 1;
|
|
|
|
args++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return q->length;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1991-11-27 17:56:08 +01:00
|
|
|
unsigned int DEFUN(print_insn_h8300,(addr, data, file),
|
1991-10-01 04:43:11 +01:00
|
|
|
bfd_vma addr AND
|
1991-11-27 17:56:08 +01:00
|
|
|
CONST char *data AND
|
1991-10-01 04:43:11 +01:00
|
|
|
PTR file)
|
|
|
|
{
|
|
|
|
static boolean init;
|
|
|
|
if (!init) {
|
|
|
|
bfd_h8_disassemble_init();
|
|
|
|
init= 1;
|
|
|
|
}
|
1991-11-27 17:56:08 +01:00
|
|
|
|
|
|
|
return bfd_h8_disassemble(addr, (bfd_byte *)data, file);
|
1991-10-01 04:43:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Relocations for the H8
|
|
|
|
|
|
|
|
*/
|
1991-11-27 17:56:08 +01:00
|
|
|
static bfd_reloc_status_type
|
1991-10-01 04:43:11 +01:00
|
|
|
DEFUN(howto16_callback,(abfd, reloc_entry, symbol_in, data, ignore_input_section),
|
|
|
|
bfd *abfd AND
|
|
|
|
arelent *reloc_entry AND
|
|
|
|
asymbol *symbol_in AND
|
|
|
|
unsigned char *data AND
|
|
|
|
asection *ignore_input_section)
|
|
|
|
{
|
|
|
|
long relocation = 0;
|
|
|
|
bfd_vma addr = reloc_entry->address;
|
|
|
|
long x = bfd_get_16(abfd, (bfd_byte *)data + addr);
|
|
|
|
|
|
|
|
HOWTO_PREPARE(relocation, symbol_in);
|
|
|
|
|
|
|
|
x = (x + relocation + reloc_entry->addend);
|
|
|
|
|
|
|
|
bfd_put_16(abfd, x, (bfd_byte *)data + addr);
|
|
|
|
return bfd_reloc_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1991-11-27 17:56:08 +01:00
|
|
|
static bfd_reloc_status_type
|
1991-10-01 04:43:11 +01:00
|
|
|
DEFUN(howto8_callback,(abfd, reloc_entry, symbol_in, data, ignore_input_section),
|
|
|
|
bfd *abfd AND
|
|
|
|
arelent *reloc_entry AND
|
|
|
|
asymbol *symbol_in AND
|
|
|
|
unsigned char *data AND
|
|
|
|
asection *ignore_input_section)
|
|
|
|
{
|
|
|
|
long relocation = 0;
|
|
|
|
bfd_vma addr = reloc_entry->address;
|
|
|
|
long x = bfd_get_8(abfd, (bfd_byte *)data + addr);
|
|
|
|
|
|
|
|
HOWTO_PREPARE(relocation, symbol_in);
|
|
|
|
|
|
|
|
x = (x + relocation + reloc_entry->addend);
|
|
|
|
|
|
|
|
bfd_put_8(abfd, x, (bfd_byte *)data + addr);
|
|
|
|
return bfd_reloc_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1991-11-27 17:56:08 +01:00
|
|
|
static bfd_reloc_status_type
|
1991-10-01 04:43:11 +01:00
|
|
|
DEFUN(howto8_FFnn_callback,(abfd, reloc_entry, symbol_in, data, ignore_input_section),
|
|
|
|
bfd *abfd AND
|
|
|
|
arelent *reloc_entry AND
|
|
|
|
asymbol *symbol_in AND
|
|
|
|
unsigned char *data AND
|
|
|
|
asection *ignore_input_section)
|
|
|
|
{
|
|
|
|
long relocation = 0;
|
|
|
|
bfd_vma addr = reloc_entry->address;
|
|
|
|
|
|
|
|
long x = bfd_get_8(abfd, (bfd_byte *)data + addr);
|
|
|
|
abort();
|
|
|
|
HOWTO_PREPARE(relocation, symbol_in);
|
|
|
|
|
|
|
|
x = (x + relocation + reloc_entry->addend);
|
|
|
|
|
|
|
|
bfd_put_8(abfd, x, (bfd_byte *)data + addr);
|
|
|
|
return bfd_reloc_ok;
|
|
|
|
}
|
|
|
|
|
1991-11-27 17:56:08 +01:00
|
|
|
static bfd_reloc_status_type
|
1991-10-01 04:43:11 +01:00
|
|
|
DEFUN(howto8_pcrel_callback,(abfd, reloc_entry, symbol_in, data, ignore_input_section),
|
|
|
|
bfd *abfd AND
|
|
|
|
arelent *reloc_entry AND
|
|
|
|
asymbol *symbol_in AND
|
|
|
|
unsigned char *data AND
|
|
|
|
asection *ignore_input_section)
|
|
|
|
{
|
|
|
|
long relocation = 0;
|
|
|
|
bfd_vma addr = reloc_entry->address;
|
|
|
|
long x = bfd_get_8(abfd, (bfd_byte *)data + addr);
|
|
|
|
abort();
|
|
|
|
HOWTO_PREPARE(relocation, symbol_in);
|
|
|
|
|
|
|
|
x = (x + relocation + reloc_entry->addend);
|
|
|
|
|
|
|
|
bfd_put_8(abfd, x, (bfd_byte *)data + addr);
|
|
|
|
return bfd_reloc_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static reloc_howto_type howto_16
|
1991-10-05 01:39:21 +01:00
|
|
|
= NEWHOWTO(howto16_callback,"abs16",1,0,0);
|
1991-10-01 04:43:11 +01:00
|
|
|
static reloc_howto_type howto_8
|
1991-10-05 01:39:21 +01:00
|
|
|
= NEWHOWTO(howto8_callback,"abs8",0,0,0);
|
1991-10-01 04:43:11 +01:00
|
|
|
|
|
|
|
static reloc_howto_type howto_8_FFnn
|
1991-10-05 01:39:21 +01:00
|
|
|
= NEWHOWTO(howto8_FFnn_callback,"ff00+abs8",0,0,0);
|
1991-10-01 04:43:11 +01:00
|
|
|
|
|
|
|
static reloc_howto_type howto_8_pcrel
|
1991-10-05 01:39:21 +01:00
|
|
|
= NEWHOWTO(howto8_pcrel_callback,"pcrel8",0,1,1);
|
1991-10-01 04:43:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
1991-10-05 01:39:21 +01:00
|
|
|
static CONST struct reloc_howto_struct *
|
|
|
|
DEFUN(local_bfd_reloc_type_lookup,(arch, code),
|
1991-11-27 17:56:08 +01:00
|
|
|
CONST struct bfd_arch_info *arch AND
|
|
|
|
bfd_reloc_code_type code)
|
1991-10-01 04:43:11 +01:00
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case BFD_RELOC_16:
|
|
|
|
return &howto_16;
|
|
|
|
case BFD_RELOC_8_FFnn:
|
|
|
|
return &howto_8_FFnn;
|
|
|
|
case BFD_RELOC_8:
|
|
|
|
return &howto_8;
|
|
|
|
case BFD_RELOC_8_PCREL:
|
|
|
|
return &howto_8_pcrel;
|
|
|
|
}
|
|
|
|
return (reloc_howto_type *)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bfd_default_scan_num_mach();
|
|
|
|
|
1991-10-05 01:39:21 +01:00
|
|
|
static boolean
|
|
|
|
DEFUN(h8300_scan,(info, string),
|
1991-11-27 17:56:08 +01:00
|
|
|
CONST struct bfd_arch_info *info AND
|
1991-10-05 01:39:21 +01:00
|
|
|
CONST char *string)
|
|
|
|
{
|
|
|
|
if (strcmp(string,"h8300") == 0) return true;
|
|
|
|
if (strcmp(string,"H8300") == 0) return true;
|
|
|
|
if (strcmp(string,"h8/300") == 0) return true;
|
|
|
|
if (strcmp(string,"H8/300") == 0) return true;
|
|
|
|
return false;
|
|
|
|
}
|
1991-11-27 17:56:08 +01:00
|
|
|
|
|
|
|
static bfd_arch_info_type arch_info_struct =
|
1991-10-01 04:43:11 +01:00
|
|
|
{
|
|
|
|
16, /* 16 bits in a word */
|
|
|
|
16, /* 16 bits in an address */
|
|
|
|
8, /* 8 bits in a byte */
|
|
|
|
bfd_arch_h8300,
|
|
|
|
0, /* only 1 machine */
|
1991-10-05 01:39:21 +01:00
|
|
|
"H8/300", /* arch_name */
|
1991-10-01 04:43:11 +01:00
|
|
|
"H8/300", /* printable name */
|
|
|
|
true, /* the default machine */
|
|
|
|
bfd_default_compatible,
|
1991-10-05 01:39:21 +01:00
|
|
|
h8300_scan,
|
1991-10-01 04:43:11 +01:00
|
|
|
print_insn_h8300,
|
|
|
|
local_bfd_reloc_type_lookup,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
1991-11-27 17:56:08 +01:00
|
|
|
void
|
|
|
|
DEFUN_VOID(bfd_h8300_arch)
|
1991-10-01 04:43:11 +01:00
|
|
|
{
|
|
|
|
bfd_arch_linkin(&arch_info_struct);
|
|
|
|
}
|