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 (or a shrd) and its dual bit is set,
143 if (((insn
& 0xfc000000) == 0x48000000
144 || (insn
& 0xfc000000) == 0xb0000000)
146 (*info
->fprintf_func
) (info
->stream
, "d.%s\t", opcode
->name
);
148 (*info
->fprintf_func
) (info
->stream
, "%s\t", opcode
->name
);
150 for (s
= opcode
->args
; *s
; s
++)
154 /* Integer register (src1). */
156 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
157 grnames
[(insn
>> 11) & 0x1f]);
160 /* Integer register (src2). */
162 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
163 grnames
[(insn
>> 21) & 0x1f]);
166 /* Integer destination register. */
168 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
169 grnames
[(insn
>> 16) & 0x1f]);
172 /* Floating-point register (src1). */
174 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
175 frnames
[(insn
>> 11) & 0x1f]);
178 /* Floating-point register (src2). */
180 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
181 frnames
[(insn
>> 21) & 0x1f]);
184 /* Floating-point destination register. */
186 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
187 frnames
[(insn
>> 16) & 0x1f]);
190 /* Control register. */
192 (*info
->fprintf_func
) (info
->stream
, "%s%s", I860_REG_PREFIX
,
193 crnames
[(insn
>> 21) & 0x7]);
196 /* 16-bit immediate (sign extend, except for bitwise ops). */
198 if (BITWISE_OP ((insn
& 0xfc000000) >> 26))
199 (*info
->fprintf_func
) (info
->stream
, "0x%04x",
200 (unsigned int) (insn
& 0xffff));
202 (*info
->fprintf_func
) (info
->stream
, "%d",
203 sign_ext ((insn
& 0xffff), 16));
206 /* 16-bit immediate, aligned (2^0, ld.b). */
208 (*info
->fprintf_func
) (info
->stream
, "%d",
209 sign_ext ((insn
& 0xffff), 16));
212 /* 16-bit immediate, aligned (2^1, ld.s). */
214 (*info
->fprintf_func
) (info
->stream
, "%d",
215 sign_ext ((insn
& 0xfffe), 16));
218 /* 16-bit immediate, aligned (2^2, ld.l, {p}fld.l, fst.l). */
220 (*info
->fprintf_func
) (info
->stream
, "%d",
221 sign_ext ((insn
& 0xfffc), 16));
224 /* 16-bit immediate, aligned (2^3, {p}fld.d, fst.d). */
226 (*info
->fprintf_func
) (info
->stream
, "%d",
227 sign_ext ((insn
& 0xfff8), 16));
230 /* 16-bit immediate, aligned (2^4, {p}fld.q, fst.q). */
232 (*info
->fprintf_func
) (info
->stream
, "%d",
233 sign_ext ((insn
& 0xfff0), 16));
236 /* 5-bit immediate (zero extend). */
238 (*info
->fprintf_func
) (info
->stream
, "%d",
239 ((insn
>> 11) & 0x1f));
242 /* Split 16 bit immediate (20..16:10..0). */
244 val
= ((insn
>> 5) & 0xf800) | (insn
& 0x07ff);
245 (*info
->fprintf_func
) (info
->stream
, "%d",
249 /* Split 16 bit immediate, aligned. (2^0, st.b). */
251 val
= ((insn
>> 5) & 0xf800) | (insn
& 0x07ff);
252 (*info
->fprintf_func
) (info
->stream
, "%d",
256 /* Split 16 bit immediate, aligned. (2^1, st.s). */
258 val
= ((insn
>> 5) & 0xf800) | (insn
& 0x07fe);
259 (*info
->fprintf_func
) (info
->stream
, "%d",
263 /* Split 16 bit immediate, aligned. (2^2, st.l). */
265 val
= ((insn
>> 5) & 0xf800) | (insn
& 0x07fc);
266 (*info
->fprintf_func
) (info
->stream
, "%d",
270 /* 26-bit PC relative immediate (lbroff). */
272 val
= sign_ext ((insn
& 0x03ffffff), 26);
273 print_br_address (info
, memaddr
, val
);
276 /* 16-bit PC relative immediate (sbroff). */
278 val
= sign_ext ((((insn
>> 5) & 0xf800) | (insn
& 0x07ff)), 16);
279 print_br_address (info
, memaddr
, val
);
283 (*info
->fprintf_func
) (info
->stream
, "%c", *s
);
289 return sizeof (insn
);
This page took 0.036329 seconds and 4 git commands to generate.