1 /* Print DEC PDP-11 instructions.
2 Copyright (C) 2001-2019 Free Software Foundation, Inc.
4 This file is part of the GNU opcodes library.
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 It is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 #include "disassemble.h"
23 #include "opcode/pdp11.h"
25 #define AFTER_INSTRUCTION "\t"
26 #define OPERAND_SEPARATOR ", "
28 #define JUMP 0x1000 /* Flag that this operand is used in a jump. */
30 #define FPRINTF (*info->fprintf_func)
31 #define F info->stream
33 /* Sign-extend a 16-bit number in an int. */
34 #define SIGN_BITS (8 * sizeof (int) - 16)
35 #define sign_extend(x) (((x) << SIGN_BITS) >> SIGN_BITS)
38 read_word (bfd_vma memaddr
, int *word
, disassemble_info
*info
)
43 status
= (*info
->read_memory_func
) (memaddr
, x
, 2, info
);
47 *word
= x
[1] << 8 | x
[0];
52 print_signed_octal (int n
, disassemble_info
*info
)
55 FPRINTF (F
, "-%o", -n
);
61 print_reg (int reg
, disassemble_info
*info
)
63 /* Mask off the addressing mode, if any. */
68 case 0: case 1: case 2: case 3: case 4: case 5:
69 FPRINTF (F
, "r%d", reg
); break;
70 case 6: FPRINTF (F
, "sp"); break;
71 case 7: FPRINTF (F
, "pc"); break;
72 default: ; /* error */
77 print_freg (int freg
, disassemble_info
*info
)
79 FPRINTF (F
, "fr%d", freg
);
83 print_operand (bfd_vma
*memaddr
, int code
, disassemble_info
*info
)
85 int mode
= (code
>> 3) & 7;
92 print_reg (reg
, info
);
96 print_reg (reg
, info
);
104 if (read_word (*memaddr
, &data
, info
) < 0)
107 print_signed_octal (sign_extend (data
), info
);
113 print_reg (reg
, info
);
122 if (read_word (*memaddr
, &address
, info
) < 0)
124 FPRINTF (F
, "*$%o", address
);
130 print_reg (reg
, info
);
136 print_reg (reg
, info
);
141 print_reg (reg
, info
);
146 if (read_word (*memaddr
, &disp
, info
) < 0)
151 bfd_vma address
= *memaddr
+ sign_extend (disp
);
157 (*info
->print_address_func
) (address
, info
);
163 print_signed_octal (sign_extend (disp
), info
);
165 print_reg (reg
, info
);
175 print_foperand (bfd_vma
*memaddr
, int code
, disassemble_info
*info
)
177 int mode
= (code
>> 3) & 7;
181 print_freg (reg
, info
);
183 return print_operand (memaddr
, code
, info
);
188 /* Print the PDP-11 instruction at address MEMADDR in debugged memory,
189 on INFO->STREAM. Returns length of the instruction, in bytes. */
192 print_insn_pdp11 (bfd_vma memaddr
, disassemble_info
*info
)
194 bfd_vma start_memaddr
= memaddr
;
199 info
->bytes_per_line
= 6;
200 info
->bytes_per_chunk
= 2;
201 info
->display_endian
= BFD_ENDIAN_LITTLE
;
203 if (read_word (memaddr
, &opcode
, info
) != 0)
207 src
= (opcode
>> 6) & 0x3f;
210 for (i
= 0; i
< pdp11_num_opcodes
; i
++)
212 #define OP pdp11_opcodes[i]
213 if ((opcode
& OP
.mask
) == OP
.opcode
)
216 case PDP11_OPCODE_NO_OPS
:
217 FPRINTF (F
, "%s", OP
.name
);
219 case PDP11_OPCODE_REG
:
220 FPRINTF (F
, "%s", OP
.name
);
221 FPRINTF (F
, AFTER_INSTRUCTION
);
222 print_reg (dst
, info
);
224 case PDP11_OPCODE_OP
:
225 FPRINTF (F
, "%s", OP
.name
);
226 FPRINTF (F
, AFTER_INSTRUCTION
);
227 if (strcmp (OP
.name
, "jmp") == 0)
229 if (print_operand (&memaddr
, dst
, info
) < 0)
232 case PDP11_OPCODE_FOP
:
233 FPRINTF (F
, "%s", OP
.name
);
234 FPRINTF (F
, AFTER_INSTRUCTION
);
235 if (strcmp (OP
.name
, "jmp") == 0)
237 if (print_foperand (&memaddr
, dst
, info
) < 0)
240 case PDP11_OPCODE_REG_OP
:
241 FPRINTF (F
, "%s", OP
.name
);
242 FPRINTF (F
, AFTER_INSTRUCTION
);
243 print_reg (src
, info
);
244 FPRINTF (F
, OPERAND_SEPARATOR
);
245 if (strcmp (OP
.name
, "jsr") == 0)
247 if (print_operand (&memaddr
, dst
, info
) < 0)
250 case PDP11_OPCODE_REG_OP_REV
:
251 FPRINTF (F
, "%s", OP
.name
);
252 FPRINTF (F
, AFTER_INSTRUCTION
);
253 if (print_operand (&memaddr
, dst
, info
) < 0)
255 FPRINTF (F
, OPERAND_SEPARATOR
);
256 print_reg (src
, info
);
258 case PDP11_OPCODE_AC_FOP
:
260 int ac
= (opcode
& 0xe0) >> 6;
261 FPRINTF (F
, "%s", OP
.name
);
262 FPRINTF (F
, AFTER_INSTRUCTION
);
263 print_freg (ac
, info
);
264 FPRINTF (F
, OPERAND_SEPARATOR
);
265 if (print_foperand (&memaddr
, dst
, info
) < 0)
269 case PDP11_OPCODE_FOP_AC
:
271 int ac
= (opcode
& 0xe0) >> 6;
272 FPRINTF (F
, "%s", OP
.name
);
273 FPRINTF (F
, AFTER_INSTRUCTION
);
274 if (print_foperand (&memaddr
, dst
, info
) < 0)
276 FPRINTF (F
, OPERAND_SEPARATOR
);
277 print_freg (ac
, info
);
280 case PDP11_OPCODE_AC_OP
:
282 int ac
= (opcode
& 0xe0) >> 6;
283 FPRINTF (F
, "%s", OP
.name
);
284 FPRINTF (F
, AFTER_INSTRUCTION
);
285 print_freg (ac
, info
);
286 FPRINTF (F
, OPERAND_SEPARATOR
);
287 if (print_operand (&memaddr
, dst
, info
) < 0)
291 case PDP11_OPCODE_OP_AC
:
293 int ac
= (opcode
& 0xe0) >> 6;
294 FPRINTF (F
, "%s", OP
.name
);
295 FPRINTF (F
, AFTER_INSTRUCTION
);
296 if (print_operand (&memaddr
, dst
, info
) < 0)
298 FPRINTF (F
, OPERAND_SEPARATOR
);
299 print_freg (ac
, info
);
302 case PDP11_OPCODE_OP_OP
:
303 FPRINTF (F
, "%s", OP
.name
);
304 FPRINTF (F
, AFTER_INSTRUCTION
);
305 if (print_operand (&memaddr
, src
, info
) < 0)
307 FPRINTF (F
, OPERAND_SEPARATOR
);
308 if (print_operand (&memaddr
, dst
, info
) < 0)
311 case PDP11_OPCODE_DISPL
:
313 int displ
= (opcode
& 0xff) << 8;
314 bfd_vma address
= memaddr
+ (sign_extend (displ
) >> 7);
315 FPRINTF (F
, "%s", OP
.name
);
316 FPRINTF (F
, AFTER_INSTRUCTION
);
317 (*info
->print_address_func
) (address
, info
);
320 case PDP11_OPCODE_REG_DISPL
:
322 int displ
= (opcode
& 0x3f) << 10;
323 bfd_vma address
= memaddr
- (displ
>> 9);
325 FPRINTF (F
, "%s", OP
.name
);
326 FPRINTF (F
, AFTER_INSTRUCTION
);
327 print_reg (src
, info
);
328 FPRINTF (F
, OPERAND_SEPARATOR
);
329 (*info
->print_address_func
) (address
, info
);
332 case PDP11_OPCODE_IMM8
:
334 int code
= opcode
& 0xff;
335 FPRINTF (F
, "%s", OP
.name
);
336 FPRINTF (F
, AFTER_INSTRUCTION
);
337 FPRINTF (F
, "%o", code
);
340 case PDP11_OPCODE_IMM6
:
342 int code
= opcode
& 0x3f;
343 FPRINTF (F
, "%s", OP
.name
);
344 FPRINTF (F
, AFTER_INSTRUCTION
);
345 FPRINTF (F
, "%o", code
);
348 case PDP11_OPCODE_IMM3
:
350 int code
= opcode
& 7;
351 FPRINTF (F
, "%s", OP
.name
);
352 FPRINTF (F
, AFTER_INSTRUCTION
);
353 FPRINTF (F
, "%o", code
);
356 case PDP11_OPCODE_ILLEGAL
:
358 FPRINTF (F
, ".word");
359 FPRINTF (F
, AFTER_INSTRUCTION
);
360 FPRINTF (F
, "%o", opcode
);
364 /* TODO: is this a proper way of signalling an error? */
365 FPRINTF (F
, "<internal error: unrecognized instruction type>");
372 return memaddr
- start_memaddr
;