1 /* Disassemble D10V instructions.
2 Copyright (C) 1996-2019 Free Software Foundation, Inc.
4 This file is part of the GNU opcodes library.
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 It is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
23 #include "opcode/d10v.h"
24 #include "disassemble.h"
26 /* The PC wraps at 18 bits, except for the segment number,
27 so use this mask to keep the parts we want. */
28 #define PC_MASK 0x0303FFFF
31 print_operand (struct d10v_operand
*oper
,
33 struct d10v_opcode
*op
,
35 struct disassemble_info
*info
)
39 if (oper
->flags
== OPERAND_ATMINUS
)
41 (*info
->fprintf_func
) (info
->stream
, "@-");
44 if (oper
->flags
== OPERAND_MINUS
)
46 (*info
->fprintf_func
) (info
->stream
, "-");
49 if (oper
->flags
== OPERAND_PLUS
)
51 (*info
->fprintf_func
) (info
->stream
, "+");
54 if (oper
->flags
== OPERAND_ATSIGN
)
56 (*info
->fprintf_func
) (info
->stream
, "@");
59 if (oper
->flags
== OPERAND_ATPAR
)
61 (*info
->fprintf_func
) (info
->stream
, "@(");
67 /* The LONG_L format shifts registers over by 15. */
68 if (op
->format
== LONG_L
&& (oper
->flags
& OPERAND_REG
))
71 num
= (insn
>> shift
) & (0x7FFFFFFF >> (31 - oper
->bits
));
73 if (oper
->flags
& OPERAND_REG
)
79 & (OPERAND_GPR
| OPERAND_FFLAG
| OPERAND_CFLAG
| OPERAND_CONTROL
));
80 if (oper
->flags
& (OPERAND_ACC0
| OPERAND_ACC1
))
81 num
+= num
? OPERAND_ACC1
: OPERAND_ACC0
;
82 for (i
= 0; i
< d10v_reg_name_cnt (); i
++)
84 if (num
== (d10v_predefined_registers
[i
].value
& ~ OPERAND_SP
))
86 if (d10v_predefined_registers
[i
].pname
)
87 (*info
->fprintf_func
) (info
->stream
, "%s",
88 d10v_predefined_registers
[i
].pname
);
90 (*info
->fprintf_func
) (info
->stream
, "%s",
91 d10v_predefined_registers
[i
].name
);
98 /* This would only get executed if a register was not in the
100 if (oper
->flags
& (OPERAND_ACC0
| OPERAND_ACC1
))
101 (*info
->fprintf_func
) (info
->stream
, "a");
102 else if (oper
->flags
& OPERAND_CONTROL
)
103 (*info
->fprintf_func
) (info
->stream
, "cr");
104 else if (oper
->flags
& OPERAND_REG
)
105 (*info
->fprintf_func
) (info
->stream
, "r");
106 (*info
->fprintf_func
) (info
->stream
, "%d", num
& REGISTER_MASK
);
111 /* Addresses are right-shifted by 2. */
112 if (oper
->flags
& OPERAND_ADDR
)
117 max
= (1 << (oper
->bits
- 1));
120 num
= -num
& ((1 << oper
->bits
) - 1);
124 if (info
->flags
& INSN_HAS_RELOC
)
125 (*info
->print_address_func
) (num
& PC_MASK
, info
);
129 (*info
->print_address_func
) ((memaddr
- num
) & PC_MASK
, info
);
131 (*info
->print_address_func
) ((memaddr
+ num
) & PC_MASK
, info
);
136 if (oper
->flags
& OPERAND_SIGNED
)
138 int max
= (1 << (oper
->bits
- 1));
141 num
= -num
& ((1 << oper
->bits
) - 1);
142 (*info
->fprintf_func
) (info
->stream
, "-");
145 (*info
->fprintf_func
) (info
->stream
, "0x%x", num
);
151 dis_long (unsigned long insn
,
153 struct disassemble_info
*info
)
156 struct d10v_opcode
*op
= (struct d10v_opcode
*) d10v_opcodes
;
157 struct d10v_operand
*oper
;
163 if ((op
->format
& LONG_OPCODE
)
164 && ((op
->mask
& insn
) == (unsigned long) op
->opcode
))
167 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
169 for (i
= 0; op
->operands
[i
]; i
++)
171 oper
= (struct d10v_operand
*) &d10v_operands
[op
->operands
[i
]];
172 if (oper
->flags
== OPERAND_ATPAR
)
174 print_operand (oper
, insn
, op
, memaddr
, info
);
175 if (op
->operands
[i
+ 1] && oper
->bits
176 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_PLUS
177 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_MINUS
)
178 (*info
->fprintf_func
) (info
->stream
, ", ");
186 (*info
->fprintf_func
) (info
->stream
, ".long\t0x%08lx", insn
);
189 (*info
->fprintf_func
) (info
->stream
, ")");
193 dis_2_short (unsigned long insn
,
195 struct disassemble_info
*info
,
200 struct d10v_opcode
*op
;
201 int match
, num_match
= 0;
202 struct d10v_operand
*oper
;
205 ins
[0] = (insn
& 0x3FFFFFFF) >> 15;
206 ins
[1] = insn
& 0x00007FFF;
208 for (j
= 0; j
< 2; j
++)
210 op
= (struct d10v_opcode
*) d10v_opcodes
;
214 if ((op
->format
& SHORT_OPCODE
)
215 && ((((unsigned int) op
->mask
) & ins
[j
])
216 == (unsigned int) op
->opcode
))
218 (*info
->fprintf_func
) (info
->stream
, "%s\t", op
->name
);
219 for (i
= 0; op
->operands
[i
]; i
++)
221 oper
= (struct d10v_operand
*) &d10v_operands
[op
->operands
[i
]];
222 if (oper
->flags
== OPERAND_ATPAR
)
224 print_operand (oper
, ins
[j
], op
, memaddr
, info
);
225 if (op
->operands
[i
+ 1] && oper
->bits
226 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_PLUS
227 && d10v_operands
[op
->operands
[i
+ 1]].flags
!= OPERAND_MINUS
)
228 (*info
->fprintf_func
) (info
->stream
, ", ");
237 (*info
->fprintf_func
) (info
->stream
, "unknown");
242 (*info
->fprintf_func
) (info
->stream
, "\t->\t");
246 (*info
->fprintf_func
) (info
->stream
, "\t<-\t");
250 (*info
->fprintf_func
) (info
->stream
, "\t||\t");
259 (*info
->fprintf_func
) (info
->stream
, ".long\t0x%08lx", insn
);
262 (*info
->fprintf_func
) (info
->stream
, ")");
266 print_insn_d10v (bfd_vma memaddr
, struct disassemble_info
*info
)
272 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
275 (*info
->memory_error_func
) (status
, memaddr
, info
);
278 insn
= bfd_getb32 (buffer
);
280 status
= insn
& FM11
;
284 dis_2_short (insn
, memaddr
, info
, 2);
287 dis_2_short (insn
, memaddr
, info
, 0);
290 dis_2_short (insn
, memaddr
, info
, 1);
293 dis_long (insn
, memaddr
, info
);