ae18c55a9b67d1baef03be6313b47d5f432fa994
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
);
158 (*info
->fprintf_func
) (info
->stream
, "0x%x",num
);
164 dis_long (insn
, memaddr
, info
)
167 struct disassemble_info
*info
;
171 struct d10v_opcode
*op
= (struct d10v_opcode
*)d10v_opcodes
;
172 struct d10v_operand
*oper
;
177 if ((op
->format
& LONG_OPCODE
) && ((op
->mask
& insn
) == op
->opcode
))
179 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
180 for ( i
=0; op
->operands
[i
]; i
++)
182 oper
= (struct d10v_operand
*)&d10v_operands
[op
->operands
[i
]];
183 if (oper
->flags
== OPERAND_ATPAR
)
185 print_operand (oper
, insn
, op
, memaddr
, info
);
186 if (op
->operands
[i
+1] && oper
->bits
&&
187 d10v_operands
[op
->operands
[i
+1]].flags
!= OPERAND_PLUS
&&
188 d10v_operands
[op
->operands
[i
+1]].flags
!= OPERAND_MINUS
)
189 (*info
->fprintf_func
) (info
->stream
, ", ");
196 (*info
->fprintf_func
) (info
->stream
, ")");
200 dis_2_short (insn
, memaddr
, info
, order
)
203 struct disassemble_info
*info
;
209 struct d10v_opcode
*op
;
211 int match
, num_match
=0;
212 struct d10v_operand
*oper
;
215 ins
[0] = (insn
& 0x3FFFFFFF) >> 15;
216 ins
[1] = insn
& 0x00007FFF;
220 op
= (struct d10v_opcode
*)d10v_opcodes
;
224 if ((op
->format
& SHORT_OPCODE
) && ((op
->mask
& ins
[j
]) == op
->opcode
))
226 (*info
->fprintf_func
) (info
->stream
, "%s\t",op
->name
);
227 for (i
=0; op
->operands
[i
]; i
++)
229 oper
= (struct d10v_operand
*)&d10v_operands
[op
->operands
[i
]];
230 if (oper
->flags
== OPERAND_ATPAR
)
232 print_operand (oper
, ins
[j
], op
, memaddr
, info
);
233 if (op
->operands
[i
+1] && oper
->bits
&&
234 d10v_operands
[op
->operands
[i
+1]].flags
!= OPERAND_PLUS
&&
235 d10v_operands
[op
->operands
[i
+1]].flags
!= OPERAND_MINUS
)
236 (*info
->fprintf_func
) (info
->stream
, ", ");
245 (*info
->fprintf_func
) (info
->stream
, "unknown");
250 (*info
->fprintf_func
) (info
->stream
, "\t->\t");
254 (*info
->fprintf_func
) (info
->stream
, "\t<-\t");
258 (*info
->fprintf_func
) (info
->stream
, "\t||\t");
267 (*info
->fprintf_func
) (info
->stream
, ".long\t0x%08x",insn
);
270 (*info
->fprintf_func
) (info
->stream
, ")");
This page took 0.034201 seconds and 4 git commands to generate.