1 /* Disassemble D10V instructions.
2 Copyright 1996, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #include "opcode/d10v.h"
24 /* The PC wraps at 18 bits, except for the segment number,
25 so use this mask to keep the parts we want. */
26 #define PC_MASK 0x0303FFFF
28 static void dis_2_short
PARAMS ((unsigned long insn
, bfd_vma memaddr
,
29 struct disassemble_info
*info
, int order
));
30 static void dis_long
PARAMS ((unsigned long insn
, bfd_vma memaddr
,
31 struct disassemble_info
*info
));
32 static void print_operand
33 PARAMS ((struct d10v_operand
*, long unsigned int, struct d10v_opcode
*,
34 bfd_vma
, struct disassemble_info
*));
37 print_insn_d10v (memaddr
, info
)
39 struct disassemble_info
*info
;
45 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
48 (*info
->memory_error_func
) (status
, memaddr
, info
);
51 insn
= bfd_getb32 (buffer
);
57 dis_2_short (insn
, memaddr
, info
, 2);
60 dis_2_short (insn
, memaddr
, info
, 0);
63 dis_2_short (insn
, memaddr
, info
, 1);
66 dis_long (insn
, memaddr
, info
);
73 print_operand (oper
, insn
, op
, memaddr
, info
)
74 struct d10v_operand
*oper
;
76 struct d10v_opcode
*op
;
78 struct disassemble_info
*info
;
82 if (oper
->flags
== OPERAND_ATMINUS
)
84 (*info
->fprintf_func
) (info
->stream
, "@-");
87 if (oper
->flags
== OPERAND_MINUS
)
89 (*info
->fprintf_func
) (info
->stream
, "-");
92 if (oper
->flags
== OPERAND_PLUS
)
94 (*info
->fprintf_func
) (info
->stream
, "+");
97 if (oper
->flags
== OPERAND_ATSIGN
)
99 (*info
->fprintf_func
) (info
->stream
, "@");
102 if (oper
->flags
== OPERAND_ATPAR
)
104 (*info
->fprintf_func
) (info
->stream
, "@(");
110 /* The LONG_L format shifts registers over by 15. */
111 if (op
->format
== LONG_L
&& (oper
->flags
& OPERAND_REG
))
114 num
= (insn
>> shift
) & (0x7FFFFFFF >> (31 - oper
->bits
));
116 if (oper
->flags
& OPERAND_REG
)
121 & (OPERAND_GPR
| OPERAND_FFLAG
| OPERAND_CFLAG
| OPERAND_CONTROL
));
122 if (oper
->flags
& (OPERAND_ACC0
| OPERAND_ACC1
))
123 num
+= num
? OPERAND_ACC1
: OPERAND_ACC0
;
124 for (i
= 0; i
< d10v_reg_name_cnt (); i
++)
126 if (num
== (d10v_predefined_registers
[i
].value
& ~ OPERAND_SP
))
128 if (d10v_predefined_registers
[i
].pname
)
129 (*info
->fprintf_func
) (info
->stream
, "%s",
130 d10v_predefined_registers
[i
].pname
);
132 (*info
->fprintf_func
) (info
->stream
, "%s",
133 d10v_predefined_registers
[i
].name
);
140 /* This would only get executed if a register was not in the
142 if (oper
->flags
& (OPERAND_ACC0
| OPERAND_ACC1
))
143 (*info
->fprintf_func
) (info
->stream
, "a");
144 else if (oper
->flags
& OPERAND_CONTROL
)
145 (*info
->fprintf_func
) (info
->stream
, "cr");
146 else if (oper
->flags
& OPERAND_REG
)
147 (*info
->fprintf_func
) (info
->stream
, "r");
148 (*info
->fprintf_func
) (info
->stream
, "%d", num
& REGISTER_MASK
);
153 /* Addresses are right-shifted by 2. */
154 if (oper
->flags
& OPERAND_ADDR
)
158 max
= (1 << (oper
->bits
- 1));
161 num
= -num
& ((1 << oper
->bits
) - 1);
165 if (info
->flags
& INSN_HAS_RELOC
)
166 (*info
->print_address_func
) (num
& PC_MASK
, info
);
170 (*info
->print_address_func
) ((memaddr
- num
) & PC_MASK
, info
);
172 (*info
->print_address_func
) ((memaddr
+ num
) & PC_MASK
, info
);
177 if (oper
->flags
& OPERAND_SIGNED
)
179 int max
= (1 << (oper
->bits
- 1));
182 num
= -num
& ((1 << oper
->bits
) - 1);
183 (*info
->fprintf_func
) (info
->stream
, "-");
186 (*info
->fprintf_func
) (info
->stream
, "0x%x", num
);
192 dis_long (insn
, memaddr
, info
)
195 struct disassemble_info
*info
;
198 struct d10v_opcode
*op
= (struct d10v_opcode
*) d10v_opcodes
;
199 struct d10v_operand
*oper
;
205 if ((op
->format
& LONG_OPCODE
) && ((op
->mask
& insn
) == (unsigned long) op
->opcode
))
208 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
209 for (i
= 0; op
->operands
[i
]; i
++)
211 oper
= (struct d10v_operand
*) &d10v_operands
[op
->operands
[i
]];
212 if (oper
->flags
== OPERAND_ATPAR
)
214 print_operand (oper
, insn
, op
, memaddr
, info
);
215 if (op
->operands
[i
+ 1] && oper
->bits
216 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_PLUS
217 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_MINUS
)
218 (*info
->fprintf_func
) (info
->stream
, ", ");
226 (*info
->fprintf_func
) (info
->stream
, ".long\t0x%08x", insn
);
229 (*info
->fprintf_func
) (info
->stream
, ")");
233 dis_2_short (insn
, memaddr
, info
, order
)
236 struct disassemble_info
*info
;
241 struct d10v_opcode
*op
;
242 int match
, num_match
= 0;
243 struct d10v_operand
*oper
;
246 ins
[0] = (insn
& 0x3FFFFFFF) >> 15;
247 ins
[1] = insn
& 0x00007FFF;
249 for (j
= 0; j
< 2; j
++)
251 op
= (struct d10v_opcode
*) d10v_opcodes
;
255 if ((op
->format
& SHORT_OPCODE
)
256 && ((op
->mask
& ins
[j
]) == (unsigned long) op
->opcode
))
258 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
259 for (i
= 0; op
->operands
[i
]; i
++)
261 oper
= (struct d10v_operand
*) &d10v_operands
[op
->operands
[i
]];
262 if (oper
->flags
== OPERAND_ATPAR
)
264 print_operand (oper
, ins
[j
], op
, memaddr
, info
);
265 if (op
->operands
[i
+ 1] && oper
->bits
266 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_PLUS
267 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_MINUS
)
268 (*info
->fprintf_func
) (info
->stream
, ", ");
277 (*info
->fprintf_func
) (info
->stream
, "unknown");
282 (*info
->fprintf_func
) (info
->stream
, "\t->\t");
286 (*info
->fprintf_func
) (info
->stream
, "\t<-\t");
290 (*info
->fprintf_func
) (info
->stream
, "\t||\t");
299 (*info
->fprintf_func
) (info
->stream
, ".long\t0x%08x", insn
);
302 (*info
->fprintf_func
) (info
->stream
, ")");