1 /* Disassembler for the i860.
2 Copyright 2000 Free Software Foundation, Inc.
4 Contributed by Jason Eckhardt <jle@cygnus.com>.
6 This program 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 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #include "opcode/i860.h"
23 /* Later we should probably choose the prefix based on which OS flavor. */
24 #define I860_REG_PREFIX "%"
26 /* Integer register names (encoded as 0..31 in the instruction). */
27 static const char *const grnames
[] =
28 {"r0", "r1", "sp", "fp", "r4", "r5", "r6", "r7",
29 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
30 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
31 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"};
33 /* FP register names (encoded as 0..31 in the instruction). */
34 static const char *const frnames
[] =
35 {"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
36 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
37 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
38 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"};
40 /* Control/status register names (encoded as 0..5 in the instruction). */
41 static const char *const crnames
[] =
42 {"fir", "psr", "dirbase", "db", "fsr", "epsr", "", ""};
46 static int sign_ext
PARAMS((unsigned int, int));
47 static void print_br_address
PARAMS((disassemble_info
*, bfd_vma
, long));
50 /* True if opcode is xor, xorh, and, andh, or, orh, andnot, andnoth. */
51 #define BITWISE_OP(op) ((op) == 0x30 || (op) == 0x31 \
52 || (op) == 0x34 || (op) == 0x35 \
53 || (op) == 0x38 || (op) == 0x39 \
54 || (op) == 0x3c || (op) == 0x3d \
55 || (op) == 0x33 || (op) == 0x37 \
56 || (op) == 0x3b || (op) == 0x3f)
59 /* Sign extend N-bit number. */
72 /* Print a PC-relative branch offset. VAL is the sign extended value
73 from the branch instruction. */
75 print_br_address (info
, memaddr
, val
)
76 disassemble_info
*info
;
81 long adj
= (long)memaddr
+ 4 + (val
<< 2);
83 (*info
->fprintf_func
) (info
->stream
, "0x%08x", adj
);
85 /* Attempt to obtain a symbol for the target address. */
87 if (info
->print_address_func
&& adj
!= 0)
89 (*info
->fprintf_func
) (info
->stream
, "\t// ");
90 (*info
->print_address_func
) (adj
, info
);
95 /* Print one instruction. */
97 print_insn_i860 (memaddr
, info
)
99 disassemble_info
*info
;
102 unsigned int insn
, i
;
104 const struct i860_opcode
*opcode
= 0;
106 status
= (*info
->read_memory_func
) (memaddr
, buff
, sizeof (buff
), info
);
109 (*info
->memory_error_func
) (status
, memaddr
, info
);
113 /* Note that i860 instructions are always accessed as little endian
114 data, regardless of the endian mode of the i860. */
115 insn
= bfd_getl32 (buff
);
119 while (i860_opcodes
[i
].name
!= NULL
)
121 opcode
= &i860_opcodes
[i
];
122 if ((insn
& opcode
->match
) == opcode
->match
123 && (insn
& opcode
->lose
) == 0)
133 /* Instruction not in opcode table. */
134 (*info
->fprintf_func
) (info
->stream
, ".long %#08x", insn
);
141 /* If this a flop and its dual bit is set, prefix with 'd.'. */
142 if ((insn
& 0xfc000000) == 0x48000000 && (insn
& 0x200))
143 (*info
->fprintf_func
) (info
->stream
, "d.%s\t", opcode
->name
);
145 (*info
->fprintf_func
) (info
->stream
, "%s\t", opcode
->name
);
147 for (s
= opcode
->args
; *s
; s
++)
151 /* Integer register (src1). */
153 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
154 grnames
[(insn
>> 11) & 0x1f]);
157 /* Integer register (src2). */
159 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
160 grnames
[(insn
>> 21) & 0x1f]);
163 /* Integer destination register. */
165 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
166 grnames
[(insn
>> 16) & 0x1f]);
169 /* Floating-point register (src1). */
171 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
172 frnames
[(insn
>> 11) & 0x1f]);
175 /* Floating-point register (src2). */
177 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
178 frnames
[(insn
>> 21) & 0x1f]);
181 /* Floating-point destination register. */
183 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
184 frnames
[(insn
>> 16) & 0x1f]);
187 /* Control register. */
189 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
190 crnames
[(insn
>> 21) & 0x7]);
193 /* 16-bit immediate (sign extend, except for bitwise ops). */
195 if (BITWISE_OP ((insn
& 0xfc000000) >> 26))
196 (*info
->fprintf_func
) (info
->stream
, "0x%04x",
197 (unsigned int) (insn
& 0xffff));
199 (*info
->fprintf_func
) (info
->stream
, "%d",
200 sign_ext ((insn
& 0xffff), 16));
203 /* 16-bit immediate, aligned (2^0, ld.b). */
205 (*info
->fprintf_func
) (info
->stream
, "%d",
206 sign_ext ((insn
& 0xffff), 16));
209 /* 16-bit immediate, aligned (2^1, ld.s). */
211 (*info
->fprintf_func
) (info
->stream
, "%d",
212 sign_ext ((insn
& 0xfffe), 16));
215 /* 16-bit immediate, aligned (2^2, ld.l, {p}fld.l, fst.l). */
217 (*info
->fprintf_func
) (info
->stream
, "%d",
218 sign_ext ((insn
& 0xfffc), 16));
221 /* 16-bit immediate, aligned (2^3, {p}fld.d, fst.d). */
223 (*info
->fprintf_func
) (info
->stream
, "%d",
224 sign_ext ((insn
& 0xfff8), 16));
227 /* 16-bit immediate, aligned (2^4, {p}fld.q, fst.q). */
229 (*info
->fprintf_func
) (info
->stream
, "%d",
230 sign_ext ((insn
& 0xfff0), 16));
233 /* 5-bit immediate (zero extend). */
235 (*info
->fprintf_func
) (info
->stream
, "%d",
236 ((insn
>> 11) & 0x1f));
239 /* Split 16 bit immediate (20..16:10..0). */
241 val
= ((insn
>> 5) & 0xf800) | (insn
& 0x07ff);
242 (*info
->fprintf_func
) (info
->stream
, "%d",
246 /* Split 16 bit immediate, aligned. (2^0, st.b). */
248 val
= ((insn
>> 5) & 0xf800) | (insn
& 0x07ff);
249 (*info
->fprintf_func
) (info
->stream
, "%d",
253 /* Split 16 bit immediate, aligned. (2^1, st.s). */
255 val
= ((insn
>> 5) & 0xf800) | (insn
& 0x07fe);
256 (*info
->fprintf_func
) (info
->stream
, "%d",
260 /* Split 16 bit immediate, aligned. (2^2, st.l). */
262 val
= ((insn
>> 5) & 0xf800) | (insn
& 0x07fc);
263 (*info
->fprintf_func
) (info
->stream
, "%d",
267 /* 26-bit PC relative immediate (lbroff). */
269 val
= sign_ext ((insn
& 0x03ffffff), 26);
270 print_br_address (info
, memaddr
, val
);
273 /* 16-bit PC relative immediate (sbroff). */
275 val
= sign_ext ((((insn
>> 5) & 0xf800) | (insn
& 0x07ff)), 16);
276 print_br_address (info
, memaddr
, val
);
280 (*info
->fprintf_func
) (info
->stream
, "%c", *s
);
286 return sizeof (insn
);
This page took 0.045346 seconds and 4 git commands to generate.