2 /* i370-dis.c -- Disassemble Instruction 370 (ESA/390) instructions
3 Copyright 1994, 2000 Free Software Foundation, Inc.
4 PowerPC version written by Ian Lance Taylor, Cygnus Support
5 Rewritten for i370 ESA/390 support by Linas Vepstas <linas@linas.org>
7 This file is part of GDB, GAS, and the GNU binutils.
9 GDB, GAS, and the GNU binutils are free software; you can redistribute
10 them and/or modify them under the terms of the GNU General Public
11 License as published by the Free Software Foundation; either version
12 2, or (at your option) any later version.
14 GDB, GAS, and the GNU binutils are distributed in the hope that they
15 will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 the GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this file; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "opcode/i370.h"
29 /* This file provides several disassembler functions, all of which use
30 the disassembler interface defined in dis-asm.h.
34 print_insn_i370 (memaddr, info)
36 struct disassemble_info *info;
41 const struct i370_opcode *opcode;
42 const struct i370_opcode *opcode_end;
44 status = (*info->read_memory_func) (memaddr, buffer, 6, info);
47 (*info->memory_error_func) (status, memaddr, info);
51 /* Cast the bytes into the insn (in a host-endian indep way) */
52 insn.i[0] = (buffer[0] << 24) & 0xff000000;
53 insn.i[0] |= (buffer[1] << 16) & 0xff0000;
54 insn.i[0] |= (buffer[2] << 8) & 0xff00;
55 insn.i[0] |= buffer[3] & 0xff;
56 insn.i[1] = (buffer[4] << 24) & 0xff000000;
57 insn.i[1] |= (buffer[5] << 16) & 0xff0000;
59 /* Find the first match in the opcode table. We could speed this up
60 a bit by doing a binary search on the major opcode. */
61 opcode_end = i370_opcodes + i370_num_opcodes;
62 for (opcode = i370_opcodes; opcode < opcode_end; opcode++)
64 const unsigned char *opindex;
65 const struct i370_operand *operand;
69 /* Mask off operands, and look for a match ... */
74 masked.i[0] &= 0xffff;
76 masked.i[0] &= opcode->mask.i[0];
77 if (masked.i[0] != opcode->opcode.i[0]) continue;
81 masked.i[1] &= opcode->mask.i[1];
82 if (masked.i[1] != opcode->opcode.i[1]) continue;
85 /* Found a match. adjust a tad */
92 /* Make two passes over the operands. First see if any of them
93 have extraction functions, and, if they do, make sure the
94 instruction is valid. */
96 for (opindex = opcode->operands; *opindex != 0; opindex++)
98 operand = i370_operands + *opindex;
100 (*operand->extract) (insn, &invalid);
102 if (invalid) continue;
104 /* The instruction is valid. */
105 (*info->fprintf_func) (info->stream, "%s", opcode->name);
106 if (opcode->operands[0] != 0)
107 (*info->fprintf_func) (info->stream, "\t");
109 /* Now extract and print the operands. */
110 for (opindex = opcode->operands; *opindex != 0; opindex++)
114 operand = i370_operands + *opindex;
116 /* Extract the value from the instruction. */
117 if (operand->extract)
118 value = (*operand->extract) (insn, (int *) NULL);
121 value = (insn.i[0] >> operand->shift) & ((1 << operand->bits) - 1);
124 /* Print the operand as directed by the flags. */
125 if ((operand->flags & I370_OPERAND_OPTIONAL) != 0)
128 (*info->fprintf_func) (info->stream, "(r%ld)", value);
130 else if ((operand->flags & I370_OPERAND_SBASE) != 0)
132 (*info->fprintf_func) (info->stream, "(r%ld)", value);
134 else if ((operand->flags & I370_OPERAND_INDEX) != 0)
137 (*info->fprintf_func) (info->stream, "(r%ld,", value);
139 (*info->fprintf_func) (info->stream, "(,");
141 else if ((operand->flags & I370_OPERAND_LENGTH) != 0)
143 (*info->fprintf_func) (info->stream, "(%ld,", value);
145 else if ((operand->flags & I370_OPERAND_BASE) != 0)
146 (*info->fprintf_func) (info->stream, "r%ld)", value);
147 else if ((operand->flags & I370_OPERAND_GPR) != 0)
148 (*info->fprintf_func) (info->stream, "r%ld,", value);
149 else if ((operand->flags & I370_OPERAND_FPR) != 0)
150 (*info->fprintf_func) (info->stream, "f%ld,", value);
151 else if ((operand->flags & I370_OPERAND_RELATIVE) != 0)
152 (*info->fprintf_func) (info->stream, "%ld", value);
154 (*info->fprintf_func) (info->stream, " %ld, ", value);
163 /* We could not find a match. */
164 (*info->fprintf_func) (info->stream, ".short 0x%02x%02x", buffer[0], buffer[1]);