* solist.h (target_so_ops.find_and_open_solib): Clarify usage of
[deliverable/binutils-gdb.git] / opcodes / i370-dis.c
CommitLineData
5b93d8bb 1/* i370-dis.c -- Disassemble Instruction 370 (ESA/390) instructions
df7b86aa
NC
2 Copyright 1994, 2000, 2003, 2005, 2007, 2012
3 Free Software Foundation, Inc.
5b93d8bb
AM
4 PowerPC version written by Ian Lance Taylor, Cygnus Support
5 Rewritten for i370 ESA/390 support by Linas Vepstas <linas@linas.org>
6
9b201bb5 7 This file is part of the GNU opcodes library.
5b93d8bb 8
9b201bb5
NC
9 This library is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
5b93d8bb 13
9b201bb5
NC
14 It is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 License for more details.
5b93d8bb 18
47b0e7ad
NC
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, 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
5b93d8bb 23
5b93d8bb 24#include "sysdep.h"
df7b86aa 25#include <stdio.h>
5b93d8bb
AM
26#include "dis-asm.h"
27#include "opcode/i370.h"
28
29/* This file provides several disassembler functions, all of which use
47b0e7ad 30 the disassembler interface defined in dis-asm.h. */
5b93d8bb
AM
31
32int
26ca5450 33print_insn_i370 (bfd_vma memaddr, struct disassemble_info *info)
5b93d8bb
AM
34{
35 bfd_byte buffer[8];
36 int status;
37 i370_insn_t insn;
38 const struct i370_opcode *opcode;
39 const struct i370_opcode *opcode_end;
40
41 status = (*info->read_memory_func) (memaddr, buffer, 6, info);
42 if (status != 0)
43 {
44 (*info->memory_error_func) (status, memaddr, info);
45 return -1;
46 }
47
47b0e7ad 48 /* Cast the bytes into the insn (in a host-endian indep way). */
5b93d8bb
AM
49 insn.i[0] = (buffer[0] << 24) & 0xff000000;
50 insn.i[0] |= (buffer[1] << 16) & 0xff0000;
51 insn.i[0] |= (buffer[2] << 8) & 0xff00;
52 insn.i[0] |= buffer[3] & 0xff;
53 insn.i[1] = (buffer[4] << 24) & 0xff000000;
54 insn.i[1] |= (buffer[5] << 16) & 0xff0000;
55
56 /* Find the first match in the opcode table. We could speed this up
57 a bit by doing a binary search on the major opcode. */
58 opcode_end = i370_opcodes + i370_num_opcodes;
59 for (opcode = i370_opcodes; opcode < opcode_end; opcode++)
60 {
61 const unsigned char *opindex;
62 const struct i370_operand *operand;
63 i370_insn_t masked;
64 int invalid;
65
66 /* Mask off operands, and look for a match ... */
67 masked = insn;
68 if (2 == opcode->len)
69 {
70 masked.i[0] >>= 16;
71 masked.i[0] &= 0xffff;
72 }
73 masked.i[0] &= opcode->mask.i[0];
47b0e7ad
NC
74 if (masked.i[0] != opcode->opcode.i[0])
75 continue;
5b93d8bb
AM
76
77 if (6 == opcode->len)
78 {
79 masked.i[1] &= opcode->mask.i[1];
47b0e7ad
NC
80 if (masked.i[1] != opcode->opcode.i[1])
81 continue;
5b93d8bb
AM
82 }
83
47b0e7ad 84 /* Found a match. adjust a tad. */
5b93d8bb
AM
85 if (2 == opcode->len)
86 {
87 insn.i[0] >>= 16;
88 insn.i[0] &= 0xffff;
89 }
90
91 /* Make two passes over the operands. First see if any of them
92 have extraction functions, and, if they do, make sure the
93 instruction is valid. */
94 invalid = 0;
95 for (opindex = opcode->operands; *opindex != 0; opindex++)
96 {
97 operand = i370_operands + *opindex;
98 if (operand->extract)
99 (*operand->extract) (insn, &invalid);
100 }
47b0e7ad
NC
101 if (invalid)
102 continue;
5b93d8bb
AM
103
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");
108
109 /* Now extract and print the operands. */
110 for (opindex = opcode->operands; *opindex != 0; opindex++)
111 {
112 long value;
113
114 operand = i370_operands + *opindex;
115
116 /* Extract the value from the instruction. */
117 if (operand->extract)
118 value = (*operand->extract) (insn, (int *) NULL);
119 else
47b0e7ad 120 value = (insn.i[0] >> operand->shift) & ((1 << operand->bits) - 1);
5b93d8bb
AM
121
122 /* Print the operand as directed by the flags. */
123 if ((operand->flags & I370_OPERAND_OPTIONAL) != 0)
124 {
125 if (value)
126 (*info->fprintf_func) (info->stream, "(r%ld)", value);
127 }
128 else if ((operand->flags & I370_OPERAND_SBASE) != 0)
129 {
130 (*info->fprintf_func) (info->stream, "(r%ld)", value);
131 }
132 else if ((operand->flags & I370_OPERAND_INDEX) != 0)
133 {
134 if (value)
135 (*info->fprintf_func) (info->stream, "(r%ld,", value);
136 else
137 (*info->fprintf_func) (info->stream, "(,");
138 }
139 else if ((operand->flags & I370_OPERAND_LENGTH) != 0)
140 {
141 (*info->fprintf_func) (info->stream, "(%ld,", value);
142 }
143 else if ((operand->flags & I370_OPERAND_BASE) != 0)
144 (*info->fprintf_func) (info->stream, "r%ld)", value);
145 else if ((operand->flags & I370_OPERAND_GPR) != 0)
146 (*info->fprintf_func) (info->stream, "r%ld,", value);
147 else if ((operand->flags & I370_OPERAND_FPR) != 0)
148 (*info->fprintf_func) (info->stream, "f%ld,", value);
149 else if ((operand->flags & I370_OPERAND_RELATIVE) != 0)
150 (*info->fprintf_func) (info->stream, "%ld", value);
151 else
152 (*info->fprintf_func) (info->stream, " %ld, ", value);
5b93d8bb
AM
153 }
154
155 return opcode->len;
5b93d8bb
AM
156 }
157
5b93d8bb
AM
158 /* We could not find a match. */
159 (*info->fprintf_func) (info->stream, ".short 0x%02x%02x", buffer[0], buffer[1]);
160
161 return 2;
162}
This page took 0.564445 seconds and 4 git commands to generate.