1 /* Disassemble h8500 instructions.
2 Copyright (C) 1993, 94, 95, 1998 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #define DISASSEMBLER_TABLE
23 #include "h8500-opc.h"
27 /* Maximum length of an instruction. */
34 /* Points to first byte not fetched. */
35 bfd_byte
*max_fetched
;
36 bfd_byte the_buffer
[MAXLEN
];
41 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
42 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
44 #define FETCH_DATA(info, addr) \
45 ((addr) <= ((struct private *)(info->private_data))->max_fetched \
46 ? 1 : fetch_data ((info), (addr)))
49 fetch_data (info
, addr
)
50 struct disassemble_info
*info
;
54 struct private *priv
= (struct private *) info
->private_data
;
55 bfd_vma start
= priv
->insn_start
+ (priv
->max_fetched
- priv
->the_buffer
);
57 status
= (*info
->read_memory_func
) (start
,
59 addr
- priv
->max_fetched
,
63 (*info
->memory_error_func
) (status
, start
, info
);
64 longjmp (priv
->bailout
, 1);
67 priv
->max_fetched
= addr
;
71 static char *crname
[] =
72 {"sr", "ccr", "*", "br", "ep", "dp", "*", "tp"};
75 print_insn_h8500 (addr
, info
)
77 disassemble_info
*info
;
79 h8500_opcode_info
*opcode
;
80 void *stream
= info
->stream
;
81 fprintf_ftype func
= info
->fprintf_func
;
84 bfd_byte
*buffer
= priv
.the_buffer
;
86 info
->private_data
= (PTR
) & priv
;
87 priv
.max_fetched
= priv
.the_buffer
;
88 priv
.insn_start
= addr
;
89 if (setjmp (priv
.bailout
) != 0)
98 for (opcode
= h8500_table
; opcode
->name
; opcode
++)
100 if ((opcode
->bytes
[0].contents
& 0x8) == 0)
101 printf("%s\n", opcode
->name
);
107 /* Run down the table to find the one which matches */
108 for (opcode
= h8500_table
; opcode
->name
; opcode
++)
121 for (byte
= 0; byte
< opcode
->length
; byte
++)
123 FETCH_DATA (info
, buffer
+ byte
+ 1);
124 if ((buffer
[byte
] & opcode
->bytes
[byte
].mask
)
125 != (opcode
->bytes
[byte
].contents
))
131 /* extract any info parts */
132 switch (opcode
->bytes
[byte
].insert
)
138 /* xgettext:c-format */
139 func (stream
, _("can't cope with insert %d\n"),
140 opcode
->bytes
[byte
].insert
);
143 rn
= buffer
[byte
] & 0x7;
146 rs
= buffer
[byte
] & 0x7;
149 cr
= buffer
[byte
] & 0x7;
154 cr
= buffer
[byte
] & 0x7;
159 FETCH_DATA (info
, buffer
+ byte
+ 2);
160 disp
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
164 disp
= ((char) (buffer
[byte
]));
168 rd
= buffer
[byte
] & 0x7;
171 FETCH_DATA (info
, buffer
+ byte
+ 3);
174 | (buffer
[byte
+ 1] << 8)
175 | (buffer
[byte
+ 2]);
178 FETCH_DATA (info
, buffer
+ byte
+ 2);
179 abs
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
182 abs
= (buffer
[byte
]);
185 FETCH_DATA (info
, buffer
+ byte
+ 2);
186 imm
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
189 imm
= (buffer
[byte
]) & 0xf;
193 imm
= (buffer
[byte
]);
196 FETCH_DATA (info
, buffer
+ byte
+ 2);
197 pcrel
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
200 pcrel
= (buffer
[byte
]);
203 switch (buffer
[byte
] & 0x7)
223 /* We get here when all the masks have passed so we can output the
225 FETCH_DATA (info
, buffer
+ opcode
->length
);
226 for (i
= 0; i
< opcode
->length
; i
++)
228 (func
) (stream
, "%02x ", buffer
[i
]);
232 (func
) (stream
, " ");
234 (func
) (stream
, "%s\t", opcode
->name
);
235 for (i
= 0; i
< opcode
->nargs
; i
++)
238 (func
) (stream
, ",");
239 switch (opcode
->arg_type
[i
])
245 func (stream
, "@(0x%x:16,r%d)", disp
, rn
);
248 func (stream
, "@(0x%x:8 (%d),r%d)", disp
& 0xff, disp
, rn
);
251 func (stream
, "@(0x%x:16,r%d)", disp
, rd
);
254 func (stream
, "@(0x%x:8 (%d), r%d)", disp
& 0xff, disp
, rd
);
257 func (stream
, "@(0x%x:8 (%d), fp)", disp
& 0xff, disp
, rn
);
261 func (stream
, "%s", crname
[cr
]);
264 func (stream
, "r%d", rn
);
267 func (stream
, "r%d", rd
);
270 func (stream
, "r%d", rs
);
273 func (stream
, "@-r%d", rn
);
276 func (stream
, "@r%d+", rn
);
279 func (stream
, "@r%d", rn
);
282 func (stream
, "@r%d", rd
);
285 func (stream
, "@sp+");
288 func (stream
, "@-sp");
291 func (stream
, "@0x%0x:24", abs
);
294 func (stream
, "@0x%0x:16", abs
& 0xffff);
297 func (stream
, "@0x%0x:8", abs
& 0xff);
300 func (stream
, "#0x%0x:16", imm
& 0xffff);
307 for (i
= 0; i
< 8; i
++)
311 func (stream
, "r%d", i
);
321 func (stream
, "#0x%0x:8", imm
& 0xff);
324 func (stream
, "0x%0x:16", (pcrel
+ addr
+ opcode
->length
) & 0xffff);
327 func (stream
, "#0x%0x:8",
328 ((char) pcrel
+ addr
+ opcode
->length
) & 0xffff);
331 func (stream
, "#%d:q", qim
);
334 func (stream
, "#%d:4", imm
);
338 return opcode
->length
;
342 /* Couldn't understand anything */
343 /* xgettext:c-format */
344 func (stream
, _("%02x\t\t*unknown*"), buffer
[0]);