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
));
34 print_insn_d10v (memaddr
, info
)
36 struct disassemble_info
*info
;
42 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
45 (*info
->memory_error_func
) (status
, memaddr
, info
);
48 insn
= bfd_getb32 (buffer
);
54 dis_2_short (insn
, memaddr
, info
, 2);
57 dis_2_short (insn
, memaddr
, info
, 0);
60 dis_2_short (insn
, memaddr
, info
, 1);
63 dis_long (insn
, memaddr
, info
);
70 print_operand (oper
, insn
, op
, memaddr
, info
)
71 struct d10v_operand
*oper
;
73 struct d10v_opcode
*op
;
75 struct disassemble_info
*info
;
79 if (oper
->flags
== OPERAND_ATMINUS
)
81 (*info
->fprintf_func
) (info
->stream
, "@-");
84 if (oper
->flags
== OPERAND_MINUS
)
86 (*info
->fprintf_func
) (info
->stream
, "-");
89 if (oper
->flags
== OPERAND_PLUS
)
91 (*info
->fprintf_func
) (info
->stream
, "+");
94 if (oper
->flags
== OPERAND_ATSIGN
)
96 (*info
->fprintf_func
) (info
->stream
, "@");
99 if (oper
->flags
== OPERAND_ATPAR
)
101 (*info
->fprintf_func
) (info
->stream
, "@(");
107 /* The LONG_L format shifts registers over by 15. */
108 if (op
->format
== LONG_L
&& (oper
->flags
& OPERAND_REG
))
111 num
= (insn
>> shift
) & (0x7FFFFFFF >> (31 - oper
->bits
));
113 if (oper
->flags
& OPERAND_REG
)
118 & (OPERAND_GPR
| OPERAND_FFLAG
| OPERAND_CFLAG
| OPERAND_CONTROL
));
119 if (oper
->flags
& (OPERAND_ACC0
| OPERAND_ACC1
))
120 num
+= num
? OPERAND_ACC1
: OPERAND_ACC0
;
121 for (i
= 0; i
< d10v_reg_name_cnt (); i
++)
123 if (num
== d10v_predefined_registers
[i
].value
)
125 if (d10v_predefined_registers
[i
].pname
)
126 (*info
->fprintf_func
) (info
->stream
, "%s",
127 d10v_predefined_registers
[i
].pname
);
129 (*info
->fprintf_func
) (info
->stream
, "%s",
130 d10v_predefined_registers
[i
].name
);
137 /* This would only get executed if a register was not in the
139 if (oper
->flags
& (OPERAND_ACC0
| OPERAND_ACC1
))
140 (*info
->fprintf_func
) (info
->stream
, "a");
141 else if (oper
->flags
& OPERAND_CONTROL
)
142 (*info
->fprintf_func
) (info
->stream
, "cr");
143 else if (oper
->flags
& OPERAND_REG
)
144 (*info
->fprintf_func
) (info
->stream
, "r");
145 (*info
->fprintf_func
) (info
->stream
, "%d", num
);
150 /* Addresses are right-shifted by 2. */
151 if (oper
->flags
& OPERAND_ADDR
)
155 max
= (1 << (oper
->bits
- 1));
158 num
= -num
& ((1 << oper
->bits
) - 1);
162 if (info
->flags
& INSN_HAS_RELOC
)
163 (*info
->print_address_func
) (num
& PC_MASK
, info
);
167 (*info
->print_address_func
) ((memaddr
- num
) & PC_MASK
, info
);
169 (*info
->print_address_func
) ((memaddr
+ num
) & PC_MASK
, info
);
174 if (oper
->flags
& OPERAND_SIGNED
)
176 int max
= (1 << (oper
->bits
- 1));
179 num
= -num
& ((1 << oper
->bits
) - 1);
180 (*info
->fprintf_func
) (info
->stream
, "-");
183 (*info
->fprintf_func
) (info
->stream
, "0x%x", num
);
189 dis_long (insn
, memaddr
, info
)
192 struct disassemble_info
*info
;
196 struct d10v_opcode
*op
= (struct d10v_opcode
*) d10v_opcodes
;
197 struct d10v_operand
*oper
;
203 if ((op
->format
& LONG_OPCODE
) && ((op
->mask
& insn
) == op
->opcode
))
206 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
207 for (i
= 0; op
->operands
[i
]; i
++)
209 oper
= (struct d10v_operand
*) &d10v_operands
[op
->operands
[i
]];
210 if (oper
->flags
== OPERAND_ATPAR
)
212 print_operand (oper
, insn
, op
, memaddr
, info
);
213 if (op
->operands
[i
+ 1] && oper
->bits
214 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_PLUS
215 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_MINUS
)
216 (*info
->fprintf_func
) (info
->stream
, ", ");
224 (*info
->fprintf_func
) (info
->stream
, ".long\t0x%08x", insn
);
227 (*info
->fprintf_func
) (info
->stream
, ")");
231 dis_2_short (insn
, memaddr
, info
, order
)
234 struct disassemble_info
*info
;
240 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
]) == 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
, ")");