* dlltool.c (dtab): Remove empty function.
[binutils.git] / opcodes / i370-dis.c
blob0f04f27f6bbcb1e1231b076a72594083ef2b6dd0
1 /* i370-dis.c -- Disassemble Instruction 370 (ESA/390) instructions
2 Copyright 1994, 2000, 2003 Free Software Foundation, Inc.
3 PowerPC version written by Ian Lance Taylor, Cygnus Support
4 Rewritten for i370 ESA/390 support by Linas Vepstas <linas@linas.org>
6 This file is part of GDB, GAS, and the GNU binutils.
8 GDB, GAS, and the GNU binutils are free software; you can redistribute
9 them and/or modify them under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either version
11 2, or (at your option) any later version.
13 GDB, GAS, and the GNU binutils are distributed in the hope that they
14 will be useful, but WITHOUT ANY WARRANTY; without even the implied
15 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
16 the GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this file; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include <stdio.h>
23 #include "sysdep.h"
24 #include "dis-asm.h"
25 #include "opcode/i370.h"
27 /* This file provides several disassembler functions, all of which use
28 the disassembler interface defined in dis-asm.h.
31 int
32 print_insn_i370 (bfd_vma memaddr, struct disassemble_info *info)
34 bfd_byte buffer[8];
35 int status;
36 i370_insn_t insn;
37 const struct i370_opcode *opcode;
38 const struct i370_opcode *opcode_end;
40 status = (*info->read_memory_func) (memaddr, buffer, 6, info);
41 if (status != 0)
43 (*info->memory_error_func) (status, memaddr, info);
44 return -1;
47 /* Cast the bytes into the insn (in a host-endian indep way) */
48 insn.i[0] = (buffer[0] << 24) & 0xff000000;
49 insn.i[0] |= (buffer[1] << 16) & 0xff0000;
50 insn.i[0] |= (buffer[2] << 8) & 0xff00;
51 insn.i[0] |= buffer[3] & 0xff;
52 insn.i[1] = (buffer[4] << 24) & 0xff000000;
53 insn.i[1] |= (buffer[5] << 16) & 0xff0000;
55 /* Find the first match in the opcode table. We could speed this up
56 a bit by doing a binary search on the major opcode. */
57 opcode_end = i370_opcodes + i370_num_opcodes;
58 for (opcode = i370_opcodes; opcode < opcode_end; opcode++)
60 const unsigned char *opindex;
61 const struct i370_operand *operand;
62 i370_insn_t masked;
63 int invalid;
65 /* Mask off operands, and look for a match ... */
66 masked = insn;
67 if (2 == opcode->len)
69 masked.i[0] >>= 16;
70 masked.i[0] &= 0xffff;
72 masked.i[0] &= opcode->mask.i[0];
73 if (masked.i[0] != opcode->opcode.i[0]) continue;
75 if (6 == opcode->len)
77 masked.i[1] &= opcode->mask.i[1];
78 if (masked.i[1] != opcode->opcode.i[1]) continue;
81 /* Found a match. adjust a tad */
82 if (2 == opcode->len)
84 insn.i[0] >>= 16;
85 insn.i[0] &= 0xffff;
88 /* Make two passes over the operands. First see if any of them
89 have extraction functions, and, if they do, make sure the
90 instruction is valid. */
91 invalid = 0;
92 for (opindex = opcode->operands; *opindex != 0; opindex++)
94 operand = i370_operands + *opindex;
95 if (operand->extract)
96 (*operand->extract) (insn, &invalid);
98 if (invalid) continue;
100 /* The instruction is valid. */
101 (*info->fprintf_func) (info->stream, "%s", opcode->name);
102 if (opcode->operands[0] != 0)
103 (*info->fprintf_func) (info->stream, "\t");
105 /* Now extract and print the operands. */
106 for (opindex = opcode->operands; *opindex != 0; opindex++)
108 long value;
110 operand = i370_operands + *opindex;
112 /* Extract the value from the instruction. */
113 if (operand->extract)
114 value = (*operand->extract) (insn, (int *) NULL);
115 else
117 value = (insn.i[0] >> operand->shift) & ((1 << operand->bits) - 1);
120 /* Print the operand as directed by the flags. */
121 if ((operand->flags & I370_OPERAND_OPTIONAL) != 0)
123 if (value)
124 (*info->fprintf_func) (info->stream, "(r%ld)", value);
126 else if ((operand->flags & I370_OPERAND_SBASE) != 0)
128 (*info->fprintf_func) (info->stream, "(r%ld)", value);
130 else if ((operand->flags & I370_OPERAND_INDEX) != 0)
132 if (value)
133 (*info->fprintf_func) (info->stream, "(r%ld,", value);
134 else
135 (*info->fprintf_func) (info->stream, "(,");
137 else if ((operand->flags & I370_OPERAND_LENGTH) != 0)
139 (*info->fprintf_func) (info->stream, "(%ld,", value);
141 else if ((operand->flags & I370_OPERAND_BASE) != 0)
142 (*info->fprintf_func) (info->stream, "r%ld)", value);
143 else if ((operand->flags & I370_OPERAND_GPR) != 0)
144 (*info->fprintf_func) (info->stream, "r%ld,", value);
145 else if ((operand->flags & I370_OPERAND_FPR) != 0)
146 (*info->fprintf_func) (info->stream, "f%ld,", value);
147 else if ((operand->flags & I370_OPERAND_RELATIVE) != 0)
148 (*info->fprintf_func) (info->stream, "%ld", value);
149 else
150 (*info->fprintf_func) (info->stream, " %ld, ", value);
154 return opcode->len;
159 /* We could not find a match. */
160 (*info->fprintf_func) (info->stream, ".short 0x%02x%02x", buffer[0], buffer[1]);
162 return 2;