1 /* Disassemble D10V instructions.
2 Copyright (C) 1996 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 static void dis_2_short
PARAMS ((unsigned long insn
, bfd_vma memaddr
,
25 struct disassemble_info
*info
, int order
));
26 static void dis_long
PARAMS ((unsigned long insn
, bfd_vma memaddr
,
27 struct disassemble_info
*info
));
30 print_insn_d10v (memaddr
, info
)
32 struct disassemble_info
*info
;
38 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
41 (*info
->memory_error_func
) (status
, memaddr
, info
);
44 insn
= bfd_getb32 (buffer
);
49 dis_2_short (insn
, memaddr
, info
, 2);
52 dis_2_short (insn
, memaddr
, info
, 0);
55 dis_2_short (insn
, memaddr
, info
, 1);
58 dis_long (insn
, memaddr
, info
);
65 print_operand (oper
, insn
, op
, memaddr
, info
)
66 struct d10v_operand
*oper
;
68 struct d10v_opcode
*op
;
70 struct disassemble_info
*info
;
74 if (oper
->flags
== OPERAND_ATMINUS
)
76 (*info
->fprintf_func
) (info
->stream
, "@-");
79 if (oper
->flags
== OPERAND_MINUS
)
81 (*info
->fprintf_func
) (info
->stream
, "-");
84 if (oper
->flags
== OPERAND_PLUS
)
86 (*info
->fprintf_func
) (info
->stream
, "+");
89 if (oper
->flags
== OPERAND_ATSIGN
)
91 (*info
->fprintf_func
) (info
->stream
, "@");
94 if (oper
->flags
== OPERAND_ATPAR
)
96 (*info
->fprintf_func
) (info
->stream
, "@(");
102 /* the LONG_L format shifts registers over by 15 */
103 if (op
->format
== LONG_L
&& (oper
->flags
& OPERAND_REG
))
106 num
= (insn
>> shift
) & (0x7FFFFFFF >> (31 - oper
->bits
));
108 if (oper
->flags
& OPERAND_REG
)
112 num
+= oper
->flags
& (OPERAND_ACC
|OPERAND_FLAG
|OPERAND_CONTROL
);
113 for (i
=0;i
<reg_name_cnt();i
++)
115 if (num
== pre_defined_registers
[i
].value
)
117 if (pre_defined_registers
[i
].pname
)
118 (*info
->fprintf_func
) (info
->stream
, "%s",pre_defined_registers
[i
].pname
);
120 (*info
->fprintf_func
) (info
->stream
, "%s",pre_defined_registers
[i
].name
);
127 /* this would only get executed if a register was not in the
129 if (oper
->flags
& OPERAND_ACC
)
130 (*info
->fprintf_func
) (info
->stream
, "a");
131 else if (oper
->flags
& OPERAND_CONTROL
)
132 (*info
->fprintf_func
) (info
->stream
, "cr");
133 else if(oper
->flags
& OPERAND_REG
)
134 (*info
->fprintf_func
) (info
->stream
, "r");
135 (*info
->fprintf_func
) (info
->stream
, "%d",num
);
140 /* addresses are right-shifted by 2 */
141 if (oper
->flags
& OPERAND_ADDR
)
145 max
= (1 << (oper
->bits
- 1));
148 num
= -num
& (max
-1);
153 (*info
->print_address_func
) (memaddr
- num
, info
);
155 (*info
->print_address_func
) (memaddr
+ num
, info
);
159 if (oper
->flags
& OPERAND_SIGNED
)
161 int max
= (1 << (oper
->bits
- 1));
166 (*info
->fprintf_func
) (info
->stream
, "-");
169 (*info
->fprintf_func
) (info
->stream
, "0x%x",num
);
176 dis_long (insn
, memaddr
, info
)
179 struct disassemble_info
*info
;
183 struct d10v_opcode
*op
= (struct d10v_opcode
*)d10v_opcodes
;
184 struct d10v_operand
*oper
;
189 if ((op
->format
& LONG_OPCODE
) && ((op
->mask
& insn
) == op
->opcode
))
191 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
192 for ( i
=0; op
->operands
[i
]; i
++)
194 oper
= (struct d10v_operand
*)&d10v_operands
[op
->operands
[i
]];
195 if (oper
->flags
== OPERAND_ATPAR
)
197 print_operand (oper
, insn
, op
, memaddr
, info
);
198 if (op
->operands
[i
+1] && oper
->bits
&&
199 d10v_operands
[op
->operands
[i
+1]].flags
!= OPERAND_PLUS
&&
200 d10v_operands
[op
->operands
[i
+1]].flags
!= OPERAND_MINUS
)
201 (*info
->fprintf_func
) (info
->stream
, ", ");
208 (*info
->fprintf_func
) (info
->stream
, ")");
212 dis_2_short (insn
, memaddr
, info
, order
)
215 struct disassemble_info
*info
;
221 struct d10v_opcode
*op
;
223 int match
, num_match
=0;
224 struct d10v_operand
*oper
;
227 ins
[0] = (insn
& 0x3FFFFFFF) >> 15;
228 ins
[1] = insn
& 0x00007FFF;
232 op
= (struct d10v_opcode
*)d10v_opcodes
;
236 if ((op
->format
& SHORT_OPCODE
) && ((op
->mask
& ins
[j
]) == op
->opcode
))
238 (*info
->fprintf_func
) (info
->stream
, "%s\t",op
->name
);
239 for (i
=0; op
->operands
[i
]; i
++)
241 oper
= (struct d10v_operand
*)&d10v_operands
[op
->operands
[i
]];
242 if (oper
->flags
== OPERAND_ATPAR
)
244 print_operand (oper
, ins
[j
], op
, memaddr
, info
);
245 if (op
->operands
[i
+1] && oper
->bits
&&
246 d10v_operands
[op
->operands
[i
+1]].flags
!= OPERAND_PLUS
&&
247 d10v_operands
[op
->operands
[i
+1]].flags
!= OPERAND_MINUS
)
248 (*info
->fprintf_func
) (info
->stream
, ", ");
257 (*info
->fprintf_func
) (info
->stream
, "unknown");
262 (*info
->fprintf_func
) (info
->stream
, "\t->\t");
266 (*info
->fprintf_func
) (info
->stream
, "\t<-\t");
270 (*info
->fprintf_func
) (info
->stream
, "\t||\t");
279 (*info
->fprintf_func
) (info
->stream
, ".long\t0x%08x",insn
);
282 (*info
->fprintf_func
) (info
->stream
, ")");
This page took 0.036053 seconds and 4 git commands to generate.