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_extend(x) ((((x) & 0xffff) ^ 0x8000) - 0x8000)
37 read_word (bfd_vma memaddr
, int *word
, disassemble_info
*info
)
42 status
= (*info
->read_memory_func
) (memaddr
, x
, 2, info
);
46 *word
= x
[1] << 8 | x
[0];
51 print_signed_octal (int n
, disassemble_info
*info
)
54 FPRINTF (F
, "-%o", -n
);
60 print_reg (int reg
, disassemble_info
*info
)
62 /* Mask off the addressing mode, if any. */
67 case 0: case 1: case 2: case 3: case 4: case 5:
68 FPRINTF (F
, "r%d", reg
); break;
69 case 6: FPRINTF (F
, "sp"); break;
70 case 7: FPRINTF (F
, "pc"); break;
71 default: ; /* error */
76 print_freg (int freg
, disassemble_info
*info
)
78 FPRINTF (F
, "fr%d", freg
);
82 print_operand (bfd_vma
*memaddr
, int code
, disassemble_info
*info
)
84 int mode
= (code
>> 3) & 7;
91 print_reg (reg
, info
);
95 print_reg (reg
, info
);
103 if (read_word (*memaddr
, &data
, info
) < 0)
106 print_signed_octal (sign_extend (data
), info
);
112 print_reg (reg
, info
);
121 if (read_word (*memaddr
, &address
, info
) < 0)
123 FPRINTF (F
, "*$%o", address
);
129 print_reg (reg
, info
);
135 print_reg (reg
, info
);
140 print_reg (reg
, info
);
145 if (read_word (*memaddr
, &disp
, info
) < 0)
150 bfd_vma address
= *memaddr
+ sign_extend (disp
);
156 (*info
->print_address_func
) (address
, info
);
162 print_signed_octal (sign_extend (disp
), info
);
164 print_reg (reg
, info
);
174 print_foperand (bfd_vma
*memaddr
, int code
, disassemble_info
*info
)
176 int mode
= (code
>> 3) & 7;
180 print_freg (reg
, info
);
182 return print_operand (memaddr
, code
, info
);
187 /* Print the PDP-11 instruction at address MEMADDR in debugged memory,
188 on INFO->STREAM. Returns length of the instruction, in bytes. */
191 print_insn_pdp11 (bfd_vma memaddr
, disassemble_info
*info
)
193 bfd_vma start_memaddr
= memaddr
;
198 info
->bytes_per_line
= 6;
199 info
->bytes_per_chunk
= 2;
200 info
->display_endian
= BFD_ENDIAN_LITTLE
;
202 if (read_word (memaddr
, &opcode
, info
) != 0)
206 src
= (opcode
>> 6) & 0x3f;
209 for (i
= 0; i
< pdp11_num_opcodes
; i
++)
211 #define OP pdp11_opcodes[i]
212 if ((opcode
& OP
.mask
) == OP
.opcode
)
215 case PDP11_OPCODE_NO_OPS
:
216 FPRINTF (F
, "%s", OP
.name
);
218 case PDP11_OPCODE_REG
:
219 FPRINTF (F
, "%s", OP
.name
);
220 FPRINTF (F
, AFTER_INSTRUCTION
);
221 print_reg (dst
, info
);
223 case PDP11_OPCODE_OP
:
224 FPRINTF (F
, "%s", OP
.name
);
225 FPRINTF (F
, AFTER_INSTRUCTION
);
226 if (strcmp (OP
.name
, "jmp") == 0)
228 if (print_operand (&memaddr
, dst
, info
) < 0)
231 case PDP11_OPCODE_FOP
:
232 FPRINTF (F
, "%s", OP
.name
);
233 FPRINTF (F
, AFTER_INSTRUCTION
);
234 if (strcmp (OP
.name
, "jmp") == 0)
236 if (print_foperand (&memaddr
, dst
, info
) < 0)
239 case PDP11_OPCODE_REG_OP
:
240 FPRINTF (F
, "%s", OP
.name
);
241 FPRINTF (F
, AFTER_INSTRUCTION
);
242 print_reg (src
, info
);
243 FPRINTF (F
, OPERAND_SEPARATOR
);
244 if (strcmp (OP
.name
, "jsr") == 0)
246 if (print_operand (&memaddr
, dst
, info
) < 0)
249 case PDP11_OPCODE_REG_OP_REV
:
250 FPRINTF (F
, "%s", OP
.name
);
251 FPRINTF (F
, AFTER_INSTRUCTION
);
252 if (print_operand (&memaddr
, dst
, info
) < 0)
254 FPRINTF (F
, OPERAND_SEPARATOR
);
255 print_reg (src
, info
);
257 case PDP11_OPCODE_AC_FOP
:
259 int ac
= (opcode
& 0xe0) >> 6;
260 FPRINTF (F
, "%s", OP
.name
);
261 FPRINTF (F
, AFTER_INSTRUCTION
);
262 print_freg (ac
, info
);
263 FPRINTF (F
, OPERAND_SEPARATOR
);
264 if (print_foperand (&memaddr
, dst
, info
) < 0)
268 case PDP11_OPCODE_FOP_AC
:
270 int ac
= (opcode
& 0xe0) >> 6;
271 FPRINTF (F
, "%s", OP
.name
);
272 FPRINTF (F
, AFTER_INSTRUCTION
);
273 if (print_foperand (&memaddr
, dst
, info
) < 0)
275 FPRINTF (F
, OPERAND_SEPARATOR
);
276 print_freg (ac
, info
);
279 case PDP11_OPCODE_AC_OP
:
281 int ac
= (opcode
& 0xe0) >> 6;
282 FPRINTF (F
, "%s", OP
.name
);
283 FPRINTF (F
, AFTER_INSTRUCTION
);
284 print_freg (ac
, info
);
285 FPRINTF (F
, OPERAND_SEPARATOR
);
286 if (print_operand (&memaddr
, dst
, info
) < 0)
290 case PDP11_OPCODE_OP_AC
:
292 int ac
= (opcode
& 0xe0) >> 6;
293 FPRINTF (F
, "%s", OP
.name
);
294 FPRINTF (F
, AFTER_INSTRUCTION
);
295 if (print_operand (&memaddr
, dst
, info
) < 0)
297 FPRINTF (F
, OPERAND_SEPARATOR
);
298 print_freg (ac
, info
);
301 case PDP11_OPCODE_OP_OP
:
302 FPRINTF (F
, "%s", OP
.name
);
303 FPRINTF (F
, AFTER_INSTRUCTION
);
304 if (print_operand (&memaddr
, src
, info
) < 0)
306 FPRINTF (F
, OPERAND_SEPARATOR
);
307 if (print_operand (&memaddr
, dst
, info
) < 0)
310 case PDP11_OPCODE_DISPL
:
312 int displ
= (opcode
& 0xff) << 8;
313 bfd_vma address
= memaddr
+ (sign_extend (displ
) >> 7);
314 FPRINTF (F
, "%s", OP
.name
);
315 FPRINTF (F
, AFTER_INSTRUCTION
);
316 (*info
->print_address_func
) (address
, info
);
319 case PDP11_OPCODE_REG_DISPL
:
321 int displ
= (opcode
& 0x3f) << 10;
322 bfd_vma address
= memaddr
- (displ
>> 9);
324 FPRINTF (F
, "%s", OP
.name
);
325 FPRINTF (F
, AFTER_INSTRUCTION
);
326 print_reg (src
, info
);
327 FPRINTF (F
, OPERAND_SEPARATOR
);
328 (*info
->print_address_func
) (address
, info
);
331 case PDP11_OPCODE_IMM8
:
333 int code
= opcode
& 0xff;
334 FPRINTF (F
, "%s", OP
.name
);
335 FPRINTF (F
, AFTER_INSTRUCTION
);
336 FPRINTF (F
, "%o", code
);
339 case PDP11_OPCODE_IMM6
:
341 int code
= opcode
& 0x3f;
342 FPRINTF (F
, "%s", OP
.name
);
343 FPRINTF (F
, AFTER_INSTRUCTION
);
344 FPRINTF (F
, "%o", code
);
347 case PDP11_OPCODE_IMM3
:
349 int code
= opcode
& 7;
350 FPRINTF (F
, "%s", OP
.name
);
351 FPRINTF (F
, AFTER_INSTRUCTION
);
352 FPRINTF (F
, "%o", code
);
355 case PDP11_OPCODE_ILLEGAL
:
357 FPRINTF (F
, ".word");
358 FPRINTF (F
, AFTER_INSTRUCTION
);
359 FPRINTF (F
, "%o", opcode
);
363 /* TODO: is this a proper way of signalling an error? */
364 FPRINTF (F
, "<internal error: unrecognized instruction type>");
371 return memaddr
- start_memaddr
;
This page took 0.037226 seconds and 4 git commands to generate.