1 /* Print DEC PDP-11 instructions.
2 Copyright 2001 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #include "opcode/pdp11.h"
22 #define AFTER_INSTRUCTION "\t"
23 #define OPERAND_SEPARATOR ", "
25 #define JUMP 0x1000 /* flag that this operand is used in a jump */
27 #define FPRINTF (*info->fprintf_func)
28 #define F info->stream
30 /* sign-extend a 16-bit number in an int */
31 #define SIGN_BITS (8 * sizeof (int) - 16)
32 #define sign_extend(x) (((x) << SIGN_BITS) >> SIGN_BITS)
34 static int read_word PARAMS ((bfd_vma memaddr, int *word,
35 disassemble_info *info));
36 static void print_signed_octal PARAMS ((int n, disassemble_info *info));
37 static void print_reg PARAMS ((int reg, disassemble_info *info));
38 static void print_freg PARAMS ((int freg, disassemble_info *info));
39 static int print_operand PARAMS ((bfd_vma *memaddr, int code,
40 disassemble_info *info));
41 int print_insn_pdp11 PARAMS ((bfd_vma memaddr, disassemble_info *info));
44 read_word (memaddr, word, info)
47 disassemble_info *info;
52 status = (*info->read_memory_func) (memaddr, x, 2, info);
56 *word = x[1] << 8 | x[0];
61 print_signed_octal (n, info)
63 disassemble_info *info;
66 FPRINTF (F, "-%o", -n);
74 disassemble_info *info;
76 /* mask off the addressing mode, if any */
81 case 0: case 1: case 2: case 3: case 4: case 5:
82 FPRINTF (F, "r%d", reg); break;
83 case 6: FPRINTF (F, "sp"); break;
84 case 7: FPRINTF (F, "pc"); break;
90 print_freg (freg, info)
92 disassemble_info *info;
94 FPRINTF (F, "fr%d", freg);
98 print_operand (memaddr, code, info)
101 disassemble_info *info;
103 int mode = (code >> 3) & 7;
110 print_reg (reg, info);
114 print_reg (reg, info);
121 if (read_word (*memaddr, &data, info) < 0)
124 print_signed_octal (sign_extend (data), info);
130 print_reg (reg, info);
138 if (read_word (*memaddr, &address, info) < 0)
140 FPRINTF (F, "*$%o", address);
146 print_reg (reg, info);
152 print_reg (reg, info);
157 print_reg (reg, info);
162 if (read_word (*memaddr, &disp, info) < 0)
167 bfd_vma address = *memaddr + sign_extend (disp);
170 (*info->print_address_func) (address, info);
176 print_signed_octal (sign_extend (disp), info);
178 print_reg (reg, 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 (memaddr, info)
193 disassemble_info *info;
195 bfd_vma start_memaddr = memaddr;
200 info->bytes_per_line = 6;
201 info->bytes_per_chunk = 2;
202 info->display_endian = BFD_ENDIAN_LITTLE;
204 if (read_word (memaddr, &opcode, info) != 0)
208 src = (opcode >> 6) & 0x3f;
211 for (i = 0; i < pdp11_num_opcodes; i++)
213 #define OP pdp11_opcodes[i]
214 if ((opcode & OP.mask) == OP.opcode)
217 case PDP11_OPCODE_NO_OPS:
218 FPRINTF (F, OP.name);
220 case PDP11_OPCODE_REG:
221 FPRINTF (F, OP.name);
222 FPRINTF (F, AFTER_INSTRUCTION);
223 print_reg (dst, info);
225 case PDP11_OPCODE_OP:
226 FPRINTF (F, OP.name);
227 FPRINTF (F, AFTER_INSTRUCTION);
228 if (strcmp (OP.name, "jmp") == 0)
230 if (print_operand (&memaddr, dst, info) < 0)
233 case PDP11_OPCODE_REG_OP:
234 FPRINTF (F, OP.name);
235 FPRINTF (F, AFTER_INSTRUCTION);
236 print_reg (src, info);
237 FPRINTF (F, OPERAND_SEPARATOR);
238 if (strcmp (OP.name, "jsr") == 0)
240 if (print_operand (&memaddr, dst, info) < 0)
243 case PDP11_OPCODE_REG_OP_REV:
244 FPRINTF (F, OP.name);
245 FPRINTF (F, AFTER_INSTRUCTION);
246 if (print_operand (&memaddr, dst, info) < 0)
248 FPRINTF (F, OPERAND_SEPARATOR);
249 print_reg (src, info);
251 case PDP11_OPCODE_AC_OP:
253 int ac = (opcode & 0xe0) >> 6;
254 FPRINTF (F, OP.name);
255 FPRINTF (F, AFTER_INSTRUCTION);
256 print_freg (ac, info);
257 FPRINTF (F, OPERAND_SEPARATOR);
258 if (print_operand (&memaddr, dst, info) < 0)
262 case PDP11_OPCODE_OP_OP:
263 FPRINTF (F, OP.name);
264 FPRINTF (F, AFTER_INSTRUCTION);
265 if (print_operand (&memaddr, src, info) < 0)
267 FPRINTF (F, OPERAND_SEPARATOR);
268 if (print_operand (&memaddr, dst, info) < 0)
271 case PDP11_OPCODE_DISPL:
273 int displ = (opcode & 0xff) << 8;
274 bfd_vma address = memaddr + (sign_extend (displ) >> 7);
275 FPRINTF (F, OP.name);
276 FPRINTF (F, AFTER_INSTRUCTION);
277 (*info->print_address_func) (address, info);
280 case PDP11_OPCODE_REG_DISPL:
282 int displ = (opcode & 0x3f) << 10;
283 bfd_vma address = memaddr + (sign_extend (displ) >> 9);
284 FPRINTF (F, OP.name);
285 FPRINTF (F, AFTER_INSTRUCTION);
286 print_reg (src, info);
287 FPRINTF (F, OPERAND_SEPARATOR);
288 (*info->print_address_func) (address, info);
291 case PDP11_OPCODE_IMM8:
293 int code = opcode & 0xff;
294 FPRINTF (F, OP.name);
295 FPRINTF (F, AFTER_INSTRUCTION);
296 FPRINTF (F, "%o", code);
299 case PDP11_OPCODE_IMM6:
301 int code = opcode & 0x3f;
302 FPRINTF (F, OP.name);
303 FPRINTF (F, AFTER_INSTRUCTION);
304 FPRINTF (F, "%o", code);
307 case PDP11_OPCODE_IMM3:
309 int code = opcode & 7;
310 FPRINTF (F, OP.name);
311 FPRINTF (F, AFTER_INSTRUCTION);
312 FPRINTF (F, "%o", code);
316 /* TODO: is this a proper way of signalling an error? */
317 FPRINTF (F, "<internal error: unrecognized instruction type>");
323 return memaddr - start_memaddr;