1 /* Print DEC PDP-11 instructions.
2 Copyright 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file 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., 51 Franklin Street - Fifth Floor, Boston,
17 MA 02110-1301, USA. */
21 #include "opcode/pdp11.h"
23 #define AFTER_INSTRUCTION "\t"
24 #define OPERAND_SEPARATOR ", "
26 #define JUMP 0x1000 /* Flag that this operand is used in a jump. */
28 #define FPRINTF (*info->fprintf_func)
29 #define F info->stream
31 /* Sign-extend a 16-bit number in an int. */
32 #define SIGN_BITS (8 * sizeof (int) - 16)
33 #define sign_extend(x) (((x) << SIGN_BITS) >> SIGN_BITS)
36 read_word (bfd_vma memaddr, int *word, disassemble_info *info)
41 status = (*info->read_memory_func) (memaddr, x, 2, info);
45 *word = x[1] << 8 | x[0];
50 print_signed_octal (int n, disassemble_info *info)
53 FPRINTF (F, "-%o", -n);
59 print_reg (int reg, disassemble_info *info)
61 /* Mask off the addressing mode, if any. */
66 case 0: case 1: case 2: case 3: case 4: case 5:
67 FPRINTF (F, "r%d", reg); break;
68 case 6: FPRINTF (F, "sp"); break;
69 case 7: FPRINTF (F, "pc"); break;
70 default: ; /* error */
75 print_freg (int freg, disassemble_info *info)
77 FPRINTF (F, "fr%d", freg);
81 print_operand (bfd_vma *memaddr, int code, disassemble_info *info)
83 int mode = (code >> 3) & 7;
90 print_reg (reg, info);
94 print_reg (reg, info);
102 if (read_word (*memaddr, &data, info) < 0)
105 print_signed_octal (sign_extend (data), info);
111 print_reg (reg, info);
120 if (read_word (*memaddr, &address, info) < 0)
122 FPRINTF (F, "*$%o", address);
128 print_reg (reg, info);
134 print_reg (reg, info);
139 print_reg (reg, info);
144 if (read_word (*memaddr, &disp, info) < 0)
149 bfd_vma address = *memaddr + sign_extend (disp);
155 (*info->print_address_func) (address, info);
161 print_signed_octal (sign_extend (disp), info);
163 print_reg (reg, info);
173 print_foperand (bfd_vma *memaddr, int code, disassemble_info *info)
175 int mode = (code >> 3) & 7;
179 print_freg (reg, info);
181 return print_operand (memaddr, code, info);
186 /* Print the PDP-11 instruction at address MEMADDR in debugged memory,
187 on INFO->STREAM. Returns length of the instruction, in bytes. */
190 print_insn_pdp11 (bfd_vma memaddr, disassemble_info *info)
192 bfd_vma start_memaddr = memaddr;
197 info->bytes_per_line = 6;
198 info->bytes_per_chunk = 2;
199 info->display_endian = BFD_ENDIAN_LITTLE;
201 if (read_word (memaddr, &opcode, info) != 0)
205 src = (opcode >> 6) & 0x3f;
208 for (i = 0; i < pdp11_num_opcodes; i++)
210 #define OP pdp11_opcodes[i]
211 if ((opcode & OP.mask) == OP.opcode)
214 case PDP11_OPCODE_NO_OPS:
215 FPRINTF (F, OP.name);
217 case PDP11_OPCODE_REG:
218 FPRINTF (F, OP.name);
219 FPRINTF (F, AFTER_INSTRUCTION);
220 print_reg (dst, info);
222 case PDP11_OPCODE_OP:
223 FPRINTF (F, OP.name);
224 FPRINTF (F, AFTER_INSTRUCTION);
225 if (strcmp (OP.name, "jmp") == 0)
227 if (print_operand (&memaddr, dst, info) < 0)
230 case PDP11_OPCODE_FOP:
231 FPRINTF (F, OP.name);
232 FPRINTF (F, AFTER_INSTRUCTION);
233 if (strcmp (OP.name, "jmp") == 0)
235 if (print_foperand (&memaddr, dst, info) < 0)
238 case PDP11_OPCODE_REG_OP:
239 FPRINTF (F, OP.name);
240 FPRINTF (F, AFTER_INSTRUCTION);
241 print_reg (src, info);
242 FPRINTF (F, OPERAND_SEPARATOR);
243 if (strcmp (OP.name, "jsr") == 0)
245 if (print_operand (&memaddr, dst, info) < 0)
248 case PDP11_OPCODE_REG_OP_REV:
249 FPRINTF (F, OP.name);
250 FPRINTF (F, AFTER_INSTRUCTION);
251 if (print_operand (&memaddr, dst, info) < 0)
253 FPRINTF (F, OPERAND_SEPARATOR);
254 print_reg (src, info);
256 case PDP11_OPCODE_AC_FOP:
258 int ac = (opcode & 0xe0) >> 6;
259 FPRINTF (F, OP.name);
260 FPRINTF (F, AFTER_INSTRUCTION);
261 print_freg (ac, info);
262 FPRINTF (F, OPERAND_SEPARATOR);
263 if (print_foperand (&memaddr, dst, info) < 0)
267 case PDP11_OPCODE_FOP_AC:
269 int ac = (opcode & 0xe0) >> 6;
270 FPRINTF (F, OP.name);
271 FPRINTF (F, AFTER_INSTRUCTION);
272 if (print_foperand (&memaddr, dst, info) < 0)
274 FPRINTF (F, OPERAND_SEPARATOR);
275 print_freg (ac, info);
278 case PDP11_OPCODE_AC_OP:
280 int ac = (opcode & 0xe0) >> 6;
281 FPRINTF (F, OP.name);
282 FPRINTF (F, AFTER_INSTRUCTION);
283 print_freg (ac, info);
284 FPRINTF (F, OPERAND_SEPARATOR);
285 if (print_operand (&memaddr, dst, info) < 0)
289 case PDP11_OPCODE_OP_AC:
291 int ac = (opcode & 0xe0) >> 6;
292 FPRINTF (F, OP.name);
293 FPRINTF (F, AFTER_INSTRUCTION);
294 if (print_operand (&memaddr, dst, info) < 0)
296 FPRINTF (F, OPERAND_SEPARATOR);
297 print_freg (ac, info);
300 case PDP11_OPCODE_OP_OP:
301 FPRINTF (F, OP.name);
302 FPRINTF (F, AFTER_INSTRUCTION);
303 if (print_operand (&memaddr, src, info) < 0)
305 FPRINTF (F, OPERAND_SEPARATOR);
306 if (print_operand (&memaddr, dst, info) < 0)
309 case PDP11_OPCODE_DISPL:
311 int displ = (opcode & 0xff) << 8;
312 bfd_vma address = memaddr + (sign_extend (displ) >> 7);
313 FPRINTF (F, OP.name);
314 FPRINTF (F, AFTER_INSTRUCTION);
315 (*info->print_address_func) (address, info);
318 case PDP11_OPCODE_REG_DISPL:
320 int displ = (opcode & 0x3f) << 10;
321 bfd_vma address = memaddr - (displ >> 9);
323 FPRINTF (F, OP.name);
324 FPRINTF (F, AFTER_INSTRUCTION);
325 print_reg (src, info);
326 FPRINTF (F, OPERAND_SEPARATOR);
327 (*info->print_address_func) (address, info);
330 case PDP11_OPCODE_IMM8:
332 int code = opcode & 0xff;
333 FPRINTF (F, OP.name);
334 FPRINTF (F, AFTER_INSTRUCTION);
335 FPRINTF (F, "%o", code);
338 case PDP11_OPCODE_IMM6:
340 int code = opcode & 0x3f;
341 FPRINTF (F, OP.name);
342 FPRINTF (F, AFTER_INSTRUCTION);
343 FPRINTF (F, "%o", code);
346 case PDP11_OPCODE_IMM3:
348 int code = opcode & 7;
349 FPRINTF (F, OP.name);
350 FPRINTF (F, AFTER_INSTRUCTION);
351 FPRINTF (F, "%o", code);
354 case PDP11_OPCODE_ILLEGAL:
356 FPRINTF (F, ".word");
357 FPRINTF (F, AFTER_INSTRUCTION);
358 FPRINTF (F, "%o", opcode);
362 /* TODO: is this a proper way of signalling an error? */
363 FPRINTF (F, "<internal error: unrecognized instruction type>");
370 return memaddr - start_memaddr;