Added zip to java files
[deliverable/binutils-gdb.git] / opcodes / d10v-dis.c
CommitLineData
e3659cbf 1/* Disassemble D10V instructions.
8a974fdc 2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
e3659cbf
MH
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18
19#include <stdio.h>
20
21#include "opcode/d10v.h"
22#include "dis-asm.h"
23
8a974fdc
ILT
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 0x03003FFF
27
687c3cc8
MH
28static void dis_2_short PARAMS ((unsigned long insn, bfd_vma memaddr,
29 struct disassemble_info *info, int order));
30static void dis_long PARAMS ((unsigned long insn, bfd_vma memaddr,
31 struct disassemble_info *info));
e3659cbf
MH
32
33int
34print_insn_d10v (memaddr, info)
35 bfd_vma memaddr;
36 struct disassemble_info *info;
37{
38 int status;
39 bfd_byte buffer[4];
40 unsigned long insn;
e3659cbf
MH
41
42 status = (*info->read_memory_func) (memaddr, buffer, 4, info);
43 if (status != 0)
44 {
45 (*info->memory_error_func) (status, memaddr, info);
46 return -1;
47 }
48 insn = bfd_getb32 (buffer);
49
50 status = insn & FM11;
51 switch (status) {
52 case 0:
687c3cc8 53 dis_2_short (insn, memaddr, info, 2);
e3659cbf
MH
54 break;
55 case FM01:
687c3cc8 56 dis_2_short (insn, memaddr, info, 0);
e3659cbf
MH
57 break;
58 case FM10:
687c3cc8 59 dis_2_short (insn, memaddr, info, 1);
e3659cbf
MH
60 break;
61 case FM11:
687c3cc8 62 dis_long (insn, memaddr, info);
e3659cbf
MH
63 break;
64 }
e3659cbf
MH
65 return 4;
66}
67
68static void
687c3cc8 69print_operand (oper, insn, op, memaddr, info)
e3659cbf
MH
70 struct d10v_operand *oper;
71 unsigned long insn;
72 struct d10v_opcode *op;
687c3cc8
MH
73 bfd_vma memaddr;
74 struct disassemble_info *info;
e3659cbf
MH
75{
76 int num, shift;
77
78 if (oper->flags == OPERAND_ATMINUS)
79 {
687c3cc8 80 (*info->fprintf_func) (info->stream, "@-");
e3659cbf
MH
81 return;
82 }
83 if (oper->flags == OPERAND_MINUS)
84 {
687c3cc8 85 (*info->fprintf_func) (info->stream, "-");
e3659cbf
MH
86 return;
87 }
88 if (oper->flags == OPERAND_PLUS)
89 {
687c3cc8 90 (*info->fprintf_func) (info->stream, "+");
e3659cbf
MH
91 return;
92 }
93 if (oper->flags == OPERAND_ATSIGN)
94 {
687c3cc8 95 (*info->fprintf_func) (info->stream, "@");
e3659cbf
MH
96 return;
97 }
98 if (oper->flags == OPERAND_ATPAR)
99 {
687c3cc8 100 (*info->fprintf_func) (info->stream, "@(");
e3659cbf
MH
101 return;
102 }
103
104 shift = oper->shift;
105
106 /* the LONG_L format shifts registers over by 15 */
107 if (op->format == LONG_L && (oper->flags & OPERAND_REG))
108 shift += 15;
109
110 num = (insn >> shift) & (0x7FFFFFFF >> (31 - oper->bits));
111
95e3e733 112 if (oper->flags & OPERAND_REG)
e3659cbf 113 {
95e3e733
MH
114 int i;
115 int match=0;
116 num += oper->flags & (OPERAND_ACC|OPERAND_FLAG|OPERAND_CONTROL);
117 for (i=0;i<reg_name_cnt();i++)
118 {
119 if (num == pre_defined_registers[i].value)
120 {
121 if (pre_defined_registers[i].pname)
687c3cc8 122 (*info->fprintf_func) (info->stream, "%s",pre_defined_registers[i].pname);
95e3e733 123 else
687c3cc8 124 (*info->fprintf_func) (info->stream, "%s",pre_defined_registers[i].name);
95e3e733
MH
125 match=1;
126 break;
127 }
128 }
129 if (match==0)
130 {
687c3cc8
MH
131 /* this would only get executed if a register was not in the
132 register table */
95e3e733 133 if (oper->flags & OPERAND_ACC)
687c3cc8 134 (*info->fprintf_func) (info->stream, "a");
95e3e733 135 else if (oper->flags & OPERAND_CONTROL)
687c3cc8 136 (*info->fprintf_func) (info->stream, "cr");
95e3e733 137 else if(oper->flags & OPERAND_REG)
687c3cc8
MH
138 (*info->fprintf_func) (info->stream, "r");
139 (*info->fprintf_func) (info->stream, "%d",num);
95e3e733 140 }
e3659cbf 141 }
e3659cbf 142 else
687c3cc8
MH
143 {
144 /* addresses are right-shifted by 2 */
145 if (oper->flags & OPERAND_ADDR)
146 {
147 long max;
148 int neg=0;
149 max = (1 << (oper->bits - 1));
150 if (num & max)
151 {
8a974fdc 152 num = -num & ((1 << oper->bits)-1);
687c3cc8
MH
153 neg = 1;
154 }
155 num = num<<2;
156 if (neg)
8a974fdc 157 (*info->print_address_func) ((memaddr - num) & PC_MASK, info);
687c3cc8 158 else
8a974fdc 159 (*info->print_address_func) ((memaddr + num) & PC_MASK, info);
687c3cc8
MH
160 }
161 else
0be71562
MH
162 {
163 if (oper->flags & OPERAND_SIGNED)
164 {
165 int max = (1 << (oper->bits - 1));
166 if (num & max)
167 {
8a974fdc 168 num = -num & ((1 << oper->bits)-1);
0be71562
MH
169 (*info->fprintf_func) (info->stream, "-");
170 }
171 }
172 (*info->fprintf_func) (info->stream, "0x%x",num);
173 }
687c3cc8 174 }
e3659cbf
MH
175}
176
177
178static void
687c3cc8 179dis_long (insn, memaddr, info)
e3659cbf 180 unsigned long insn;
687c3cc8
MH
181 bfd_vma memaddr;
182 struct disassemble_info *info;
e3659cbf
MH
183{
184 int i;
185 char buf[32];
186 struct d10v_opcode *op = (struct d10v_opcode *)d10v_opcodes;
187 struct d10v_operand *oper;
188 int need_paren = 0;
8a974fdc 189 int match = 0;
e3659cbf
MH
190
191 while (op->name)
192 {
193 if ((op->format & LONG_OPCODE) && ((op->mask & insn) == op->opcode))
194 {
8a974fdc 195 match = 1;
687c3cc8 196 (*info->fprintf_func) (info->stream, "%s\t", op->name);
e3659cbf
MH
197 for ( i=0; op->operands[i]; i++)
198 {
199 oper = (struct d10v_operand *)&d10v_operands[op->operands[i]];
200 if (oper->flags == OPERAND_ATPAR)
201 need_paren = 1;
687c3cc8 202 print_operand (oper, insn, op, memaddr, info);
e3659cbf
MH
203 if (op->operands[i+1] && oper->bits &&
204 d10v_operands[op->operands[i+1]].flags != OPERAND_PLUS &&
205 d10v_operands[op->operands[i+1]].flags != OPERAND_MINUS)
687c3cc8 206 (*info->fprintf_func) (info->stream, ", ");
e3659cbf
MH
207 }
208 break;
209 }
210 op++;
211 }
8a974fdc
ILT
212
213 if (!match)
214 (*info->fprintf_func) (info->stream, ".long\t0x%08x",insn);
215
e3659cbf 216 if (need_paren)
687c3cc8 217 (*info->fprintf_func) (info->stream, ")");
e3659cbf
MH
218}
219
220static void
687c3cc8 221dis_2_short (insn, memaddr, info, order)
e3659cbf 222 unsigned long insn;
687c3cc8
MH
223 bfd_vma memaddr;
224 struct disassemble_info *info;
e3659cbf
MH
225 int order;
226{
227 int i,j;
228 char astr[2][32];
229 unsigned int ins[2];
230 struct d10v_opcode *op;
231 char buf[32];
232 int match, num_match=0;
233 struct d10v_operand *oper;
234 int need_paren = 0;
235
236 ins[0] = (insn & 0x3FFFFFFF) >> 15;
237 ins[1] = insn & 0x00007FFF;
238
e3659cbf
MH
239 for(j=0;j<2;j++)
240 {
241 op = (struct d10v_opcode *)d10v_opcodes;
242 match=0;
243 while (op->name)
244 {
245 if ((op->format & SHORT_OPCODE) && ((op->mask & ins[j]) == op->opcode))
246 {
687c3cc8 247 (*info->fprintf_func) (info->stream, "%s\t",op->name);
e3659cbf
MH
248 for (i=0; op->operands[i]; i++)
249 {
250 oper = (struct d10v_operand *)&d10v_operands[op->operands[i]];
251 if (oper->flags == OPERAND_ATPAR)
252 need_paren = 1;
687c3cc8 253 print_operand (oper, ins[j], op, memaddr, info);
e3659cbf
MH
254 if (op->operands[i+1] && oper->bits &&
255 d10v_operands[op->operands[i+1]].flags != OPERAND_PLUS &&
256 d10v_operands[op->operands[i+1]].flags != OPERAND_MINUS)
687c3cc8 257 (*info->fprintf_func) (info->stream, ", ");
e3659cbf
MH
258 }
259 match = 1;
260 num_match++;
261 break;
262 }
263 op++;
264 }
265 if (!match)
687c3cc8 266 (*info->fprintf_func) (info->stream, "unknown");
e3659cbf
MH
267
268 switch (order)
269 {
270 case 0:
687c3cc8 271 (*info->fprintf_func) (info->stream, "\t->\t");
e3659cbf
MH
272 order = -1;
273 break;
274 case 1:
687c3cc8 275 (*info->fprintf_func) (info->stream, "\t<-\t");
e3659cbf
MH
276 order = -1;
277 break;
278 case 2:
687c3cc8 279 (*info->fprintf_func) (info->stream, "\t||\t");
e3659cbf
MH
280 order = -1;
281 break;
282 default:
283 break;
284 }
285 }
286
287 if (num_match == 0)
687c3cc8 288 (*info->fprintf_func) (info->stream, ".long\t0x%08x",insn);
e3659cbf
MH
289
290 if (need_paren)
687c3cc8 291 (*info->fprintf_func) (info->stream, ")");
e3659cbf 292}
This page took 0.111869 seconds and 4 git commands to generate.