1 /* Disassemble D10V instructions.
2 Copyright 1996, 1997, 1998, 2000, 2001, 2005, 2007
3 Free Software Foundation, Inc.
5 This file is part of the GNU opcodes library.
7 This library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 It is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
25 #include "opcode/d10v.h"
28 /* The PC wraps at 18 bits, except for the segment number,
29 so use this mask to keep the parts we want. */
30 #define PC_MASK 0x0303FFFF
33 print_operand (struct d10v_operand
*oper
,
35 struct d10v_opcode
*op
,
37 struct disassemble_info
*info
)
41 if (oper
->flags
== OPERAND_ATMINUS
)
43 (*info
->fprintf_func
) (info
->stream
, "@-");
46 if (oper
->flags
== OPERAND_MINUS
)
48 (*info
->fprintf_func
) (info
->stream
, "-");
51 if (oper
->flags
== OPERAND_PLUS
)
53 (*info
->fprintf_func
) (info
->stream
, "+");
56 if (oper
->flags
== OPERAND_ATSIGN
)
58 (*info
->fprintf_func
) (info
->stream
, "@");
61 if (oper
->flags
== OPERAND_ATPAR
)
63 (*info
->fprintf_func
) (info
->stream
, "@(");
69 /* The LONG_L format shifts registers over by 15. */
70 if (op
->format
== LONG_L
&& (oper
->flags
& OPERAND_REG
))
73 num
= (insn
>> shift
) & (0x7FFFFFFF >> (31 - oper
->bits
));
75 if (oper
->flags
& OPERAND_REG
)
81 & (OPERAND_GPR
| OPERAND_FFLAG
| OPERAND_CFLAG
| OPERAND_CONTROL
));
82 if (oper
->flags
& (OPERAND_ACC0
| OPERAND_ACC1
))
83 num
+= num
? OPERAND_ACC1
: OPERAND_ACC0
;
84 for (i
= 0; i
< d10v_reg_name_cnt (); i
++)
86 if (num
== (d10v_predefined_registers
[i
].value
& ~ OPERAND_SP
))
88 if (d10v_predefined_registers
[i
].pname
)
89 (*info
->fprintf_func
) (info
->stream
, "%s",
90 d10v_predefined_registers
[i
].pname
);
92 (*info
->fprintf_func
) (info
->stream
, "%s",
93 d10v_predefined_registers
[i
].name
);
100 /* This would only get executed if a register was not in the
102 if (oper
->flags
& (OPERAND_ACC0
| OPERAND_ACC1
))
103 (*info
->fprintf_func
) (info
->stream
, "a");
104 else if (oper
->flags
& OPERAND_CONTROL
)
105 (*info
->fprintf_func
) (info
->stream
, "cr");
106 else if (oper
->flags
& OPERAND_REG
)
107 (*info
->fprintf_func
) (info
->stream
, "r");
108 (*info
->fprintf_func
) (info
->stream
, "%d", num
& REGISTER_MASK
);
113 /* Addresses are right-shifted by 2. */
114 if (oper
->flags
& OPERAND_ADDR
)
119 max
= (1 << (oper
->bits
- 1));
122 num
= -num
& ((1 << oper
->bits
) - 1);
126 if (info
->flags
& INSN_HAS_RELOC
)
127 (*info
->print_address_func
) (num
& PC_MASK
, info
);
131 (*info
->print_address_func
) ((memaddr
- num
) & PC_MASK
, info
);
133 (*info
->print_address_func
) ((memaddr
+ num
) & PC_MASK
, info
);
138 if (oper
->flags
& OPERAND_SIGNED
)
140 int max
= (1 << (oper
->bits
- 1));
143 num
= -num
& ((1 << oper
->bits
) - 1);
144 (*info
->fprintf_func
) (info
->stream
, "-");
147 (*info
->fprintf_func
) (info
->stream
, "0x%x", num
);
153 dis_long (unsigned long insn
,
155 struct disassemble_info
*info
)
158 struct d10v_opcode
*op
= (struct d10v_opcode
*) d10v_opcodes
;
159 struct d10v_operand
*oper
;
165 if ((op
->format
& LONG_OPCODE
)
166 && ((op
->mask
& insn
) == (unsigned long) op
->opcode
))
169 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
171 for (i
= 0; op
->operands
[i
]; i
++)
173 oper
= (struct d10v_operand
*) &d10v_operands
[op
->operands
[i
]];
174 if (oper
->flags
== OPERAND_ATPAR
)
176 print_operand (oper
, insn
, op
, memaddr
, info
);
177 if (op
->operands
[i
+ 1] && oper
->bits
178 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_PLUS
179 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_MINUS
)
180 (*info
->fprintf_func
) (info
->stream
, ", ");
188 (*info
->fprintf_func
) (info
->stream
, ".long\t0x%08lx", insn
);
191 (*info
->fprintf_func
) (info
->stream
, ")");
195 dis_2_short (unsigned long insn
,
197 struct disassemble_info
*info
,
202 struct d10v_opcode
*op
;
203 int match
, num_match
= 0;
204 struct d10v_operand
*oper
;
207 ins
[0] = (insn
& 0x3FFFFFFF) >> 15;
208 ins
[1] = insn
& 0x00007FFF;
210 for (j
= 0; j
< 2; j
++)
212 op
= (struct d10v_opcode
*) d10v_opcodes
;
216 if ((op
->format
& SHORT_OPCODE
)
217 && ((((unsigned int) op
->mask
) & ins
[j
])
218 == (unsigned int) op
->opcode
))
220 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
221 for (i
= 0; op
->operands
[i
]; i
++)
223 oper
= (struct d10v_operand
*) &d10v_operands
[op
->operands
[i
]];
224 if (oper
->flags
== OPERAND_ATPAR
)
226 print_operand (oper
, ins
[j
], op
, memaddr
, info
);
227 if (op
->operands
[i
+ 1] && oper
->bits
228 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_PLUS
229 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_MINUS
)
230 (*info
->fprintf_func
) (info
->stream
, ", ");
239 (*info
->fprintf_func
) (info
->stream
, "unknown");
244 (*info
->fprintf_func
) (info
->stream
, "\t->\t");
248 (*info
->fprintf_func
) (info
->stream
, "\t<-\t");
252 (*info
->fprintf_func
) (info
->stream
, "\t||\t");
261 (*info
->fprintf_func
) (info
->stream
, ".long\t0x%08lx", insn
);
264 (*info
->fprintf_func
) (info
->stream
, ")");
268 print_insn_d10v (bfd_vma memaddr
, struct disassemble_info
*info
)
274 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
277 (*info
->memory_error_func
) (status
, memaddr
, info
);
280 insn
= bfd_getb32 (buffer
);
282 status
= insn
& FM11
;
286 dis_2_short (insn
, memaddr
, info
, 2);
289 dis_2_short (insn
, memaddr
, info
, 0);
292 dis_2_short (insn
, memaddr
, info
, 1);
295 dis_long (insn
, memaddr
, info
);