1 /* BFD library support routines for the Hitachi H8/300 architecture.
2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
3 Hacked by Steve Chamberlain of Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "h8300-opcode.h"
30 static struct h8_opcode
* h8_opcodes_sorted
[256][MAXSAME
];
32 /* Run through the opcodes and sort them into order to make them easy
36 DEFUN_VOID(bfd_h8_disassemble_init
)
41 for (p
= h8_opcodes
; p
->name
; p
++) {
47 if ((int)p
->data
.nib
[0] < 16) {
48 n1
=(int) p
->data
.nib
[0] ;
50 if ((int)p
->data
.nib
[1] < 16) {
51 n2
= (int) p
->data
.nib
[1];
54 for (i
= 0; i
< MAXSAME
; i
++) {
56 if (h8_opcodes_sorted
[j
][i
] == (struct h8_opcode
*)NULL
) {
57 h8_opcodes_sorted
[j
][i
] = p
;
62 if (i
==MAXSAME
)abort();
64 /* Just make sure there are an even number of nibbles in it, and
65 that the count is the same s the length */
66 for (i
= 0; p
->data
.nib
[i
] != E
; i
++) ;
68 if (i
/2 != p
->length
) abort();
70 for (i
= 0; i
< 256; i
++)
72 if (h8_opcodes_sorted
[i
][0])
73 p
= h8_opcodes_sorted
[i
][0];
74 else h8_opcodes_sorted
[i
][0] = p
;
79 DEFUN(bfd_h8_disassemble
,(addr
, data
, stream
),
81 CONST bfd_byte
*data AND
84 /* Find the first entry in the table for this opcode */
89 struct h8_opcode
**p
= h8_opcodes_sorted
[(unsigned)(data
[0])];
92 /* Find the exact opcode/arg combo */
99 op_enum_type looking_for
= *nib
;
100 int thisnib
= data
[len
>>1] ;
101 thisnib
= (len
& 1) ? (thisnib
& 0xf) : ((thisnib
>> 4) & 0xf);
102 if ((int)looking_for
& (int)B31
) {
103 if (((int)thisnib
& 0x8) ==0) goto fail
;
104 looking_for
= (op_enum_type
)((int)looking_for
& ~(int)B31
);
106 if ((int)looking_for
& (int)B30
) {
107 if (((int)thisnib
& 0x8) !=0) goto fail
;
108 looking_for
= (op_enum_type
)((int)looking_for
& ~(int)B30
);
110 switch (looking_for
) {
111 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
112 case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
113 if ((int)looking_for
!= thisnib
) goto fail
;
120 abs
= (data
[len
>>1]) * 256 + data
[(len
+2)>>1];
128 abs
= thisnib
== 0x80 ? 2:1;
154 fprintf(stream
, "Dont understand \n");
165 fprintf(stream
, "%02x %02x .word\tH'%x,H'%x\n",
172 for (i
= 0; i
< q
->length
; i
++) {
173 fprintf(stream
, "%02x ", data
[i
]);
176 fprintf(stream
, " ");
179 fprintf(stream
, "%s\t",q
->name
);
180 /* Now print out the args */
182 op_enum_type
*args
= q
->args
.nib
;
186 fprintf(stream
, ",");
187 switch ((int)(*args
) & ~((int)B30
|(int)B31
)) {
191 fprintf(stream
, "#H'%x", (unsigned)abs
); break;
193 fprintf(stream
, "r%d%c", rd
/2, rd
& 1 ? 'l' : 'h'); break;
195 fprintf(stream
, "r%d%c", rs
/2, rs
& 1 ? 'l' : 'h'); break;
197 fprintf(stream
, "r%d", rd
& 0x7); break;
199 fprintf(stream
, "r%d", rs
& 0x7); break;
201 fprintf(stream
, "@r%d+", rs
& 0x7); break;
203 fprintf(stream
, "@-r%d", rd
& 0x7); break;
205 fprintf(stream
, "@r%d", rd
& 0x7); break;
207 fprintf(stream
, "@r%d",rs
& 0x7); break;
212 fprintf(stream
, "@H'%x", (unsigned)abs
); break;
214 fprintf(stream
, "%d", (char)abs
);break;
217 fprintf(stream
, "@(%d,r%d)", abs
, rdisp
& 0x7); break;
219 fprintf(stream
, "ccr"); break;
221 fprintf(stream
, "#%d",abs
); break;
234 unsigned int DEFUN( print_insn_h8300
,(addr
, data
, file
),
236 CONST bfd_byte
*data AND
241 bfd_h8_disassemble_init();
245 return bfd_h8_disassemble(addr
, data
, file
);
249 Relocations for the H8
252 static bfd_reloc_status_enum_type
253 DEFUN(howto16_callback
,(abfd
, reloc_entry
, symbol_in
, data
, ignore_input_section
),
255 arelent
*reloc_entry AND
256 asymbol
*symbol_in AND
257 unsigned char *data AND
258 asection
*ignore_input_section
)
261 bfd_vma addr
= reloc_entry
->address
;
262 long x
= bfd_get_16(abfd
, (bfd_byte
*)data
+ addr
);
264 HOWTO_PREPARE(relocation
, symbol_in
);
266 x
= (x
+ relocation
+ reloc_entry
->addend
);
268 bfd_put_16(abfd
, x
, (bfd_byte
*)data
+ addr
);
273 static bfd_reloc_status_enum_type
274 DEFUN(howto8_callback
,(abfd
, reloc_entry
, symbol_in
, data
, ignore_input_section
),
276 arelent
*reloc_entry AND
277 asymbol
*symbol_in AND
278 unsigned char *data AND
279 asection
*ignore_input_section
)
282 bfd_vma addr
= reloc_entry
->address
;
283 long x
= bfd_get_8(abfd
, (bfd_byte
*)data
+ addr
);
285 HOWTO_PREPARE(relocation
, symbol_in
);
287 x
= (x
+ relocation
+ reloc_entry
->addend
);
289 bfd_put_8(abfd
, x
, (bfd_byte
*)data
+ addr
);
294 static bfd_reloc_status_enum_type
295 DEFUN(howto8_FFnn_callback
,(abfd
, reloc_entry
, symbol_in
, data
, ignore_input_section
),
297 arelent
*reloc_entry AND
298 asymbol
*symbol_in AND
299 unsigned char *data AND
300 asection
*ignore_input_section
)
303 bfd_vma addr
= reloc_entry
->address
;
305 long x
= bfd_get_8(abfd
, (bfd_byte
*)data
+ addr
);
307 HOWTO_PREPARE(relocation
, symbol_in
);
309 x
= (x
+ relocation
+ reloc_entry
->addend
);
311 bfd_put_8(abfd
, x
, (bfd_byte
*)data
+ addr
);
315 static bfd_reloc_status_enum_type
316 DEFUN(howto8_pcrel_callback
,(abfd
, reloc_entry
, symbol_in
, data
, ignore_input_section
),
318 arelent
*reloc_entry AND
319 asymbol
*symbol_in AND
320 unsigned char *data AND
321 asection
*ignore_input_section
)
324 bfd_vma addr
= reloc_entry
->address
;
325 long x
= bfd_get_8(abfd
, (bfd_byte
*)data
+ addr
);
327 HOWTO_PREPARE(relocation
, symbol_in
);
329 x
= (x
+ relocation
+ reloc_entry
->addend
);
331 bfd_put_8(abfd
, x
, (bfd_byte
*)data
+ addr
);
336 static reloc_howto_type howto_16
337 = NEWHOWTO(howto16_callback
,"abs16",1,0);
338 static reloc_howto_type howto_8
339 = NEWHOWTO(howto8_callback
,"abs8",0,0);
341 static reloc_howto_type howto_8_FFnn
342 = NEWHOWTO(howto8_FFnn_callback
,"ff00+abs8",0,0);
344 static reloc_howto_type howto_8_pcrel
345 = NEWHOWTO(howto8_pcrel_callback
,"pcrel8",0,1);
349 static CONST
struct reloc_howto_struct
*DEFUN(local_bfd_reloc_type_lookup
,( code
),
350 bfd_reloc_code_enum_type code
)
355 case BFD_RELOC_8_FFnn
:
356 return &howto_8_FFnn
;
359 case BFD_RELOC_8_PCREL
:
360 return &howto_8_pcrel
;
362 return (reloc_howto_type
*)NULL
;
365 int bfd_default_scan_num_mach();
367 static bfd_arch_info_struct_type arch_info_struct
=
369 16, /* 16 bits in a word */
370 16, /* 16 bits in an address */
371 8, /* 8 bits in a byte */
373 0, /* only 1 machine */
374 "H8/300", /* arch_name */
375 "H8/300", /* printable name */
376 true, /* the default machine */
377 bfd_default_compatible
,
380 local_bfd_reloc_type_lookup
,
387 void DEFUN_VOID(bfd_h8300_arch
)
389 bfd_arch_linkin(&arch_info_struct
);