00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021
00022 #include "sysdep.h"
00023 #include "opcode/v850.h"
00024 #include "dis-asm.h"
00025 #include "opintl.h"
00026
00027 static const char *const v850_reg_names[] =
00028 { "r0", "r1", "r2", "sp", "gp", "r5", "r6", "r7",
00029 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00030 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
00031 "r24", "r25", "r26", "r27", "r28", "r29", "ep", "lp" };
00032
00033 static const char *const v850_sreg_names[] =
00034 { "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "sr6", "sr7",
00035 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15",
00036 "ctpc", "ctpsw", "dbpc", "dbpsw", "ctbp", "sr21", "sr22", "sr23",
00037 "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31",
00038 "sr16", "sr17", "sr18", "sr19", "sr20", "sr21", "sr22", "sr23",
00039 "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31" };
00040
00041 static const char *const v850_cc_names[] =
00042 { "v", "c/l", "z", "nh", "s/n", "t", "lt", "le",
00043 "nv", "nc/nl", "nz", "h", "ns/p", "sa", "ge", "gt" };
00044
00045 static int disassemble
00046 PARAMS ((bfd_vma, struct disassemble_info *, unsigned long));
00047
00048 static int
00049 disassemble (memaddr, info, insn)
00050 bfd_vma memaddr;
00051 struct disassemble_info *info;
00052 unsigned long insn;
00053 {
00054 struct v850_opcode *op = (struct v850_opcode *)v850_opcodes;
00055 const struct v850_operand *operand;
00056 int match = 0;
00057 int short_op = ((insn & 0x0600) != 0x0600);
00058 int bytes_read;
00059 int target_processor;
00060
00061
00062 if ((insn & 0xffe0) == 0x0620)
00063 short_op = 1;
00064
00065 bytes_read = short_op ? 2 : 4;
00066
00067
00068 if (short_op)
00069 insn &= 0xffff;
00070
00071 switch (info->mach)
00072 {
00073 case 0:
00074 default:
00075 target_processor = PROCESSOR_V850;
00076 break;
00077
00078 case bfd_mach_v850e:
00079 target_processor = PROCESSOR_V850E;
00080 break;
00081
00082 case bfd_mach_v850e1:
00083 target_processor = PROCESSOR_V850E1;
00084 break;
00085 }
00086
00087
00088 while (op->name)
00089 {
00090 if ((op->mask & insn) == op->opcode
00091 && (op->processors & target_processor))
00092 {
00093 const unsigned char *opindex_ptr;
00094 unsigned int opnum;
00095 unsigned int memop;
00096
00097 match = 1;
00098 (*info->fprintf_func) (info->stream, "%s\t", op->name);
00099
00100
00101 memop = op->memop;
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 for (opindex_ptr = op->operands, opnum = 1;
00116 *opindex_ptr != 0;
00117 opindex_ptr++, opnum++)
00118 {
00119 long value;
00120 int flag;
00121 int status;
00122 bfd_byte buffer[4];
00123
00124 operand = &v850_operands[*opindex_ptr];
00125
00126 if (operand->extract)
00127 value = (operand->extract) (insn, 0);
00128 else
00129 {
00130 if (operand->bits == -1)
00131 value = (insn & operand->shift);
00132 else
00133 value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
00134
00135 if (operand->flags & V850_OPERAND_SIGNED)
00136 value = ((long)(value << (32 - operand->bits))
00137 >> (32 - operand->bits));
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 if (memop && opnum == memop + 1) info->fprintf_func (info->stream, "[");
00163 else if (memop && opnum == memop + 2) info->fprintf_func (info->stream, "],");
00164 else if (memop == 1 && opnum == 1
00165 && (operand->flags & V850_OPERAND_REG))
00166 info->fprintf_func (info->stream, "[");
00167 else if (opnum > 1) info->fprintf_func (info->stream, ", ");
00168
00169
00170 flag = operand->flags;
00171 flag &= ~ V850_OPERAND_SIGNED;
00172 flag &= ~ V850_OPERAND_RELAX;
00173 flag &= - flag;
00174
00175 switch (flag)
00176 {
00177 case V850_OPERAND_REG: info->fprintf_func (info->stream, "%s", v850_reg_names[value]); break;
00178 case V850_OPERAND_SRG: info->fprintf_func (info->stream, "%s", v850_sreg_names[value]); break;
00179 case V850_OPERAND_CC: info->fprintf_func (info->stream, "%s", v850_cc_names[value]); break;
00180 case V850_OPERAND_EP: info->fprintf_func (info->stream, "ep"); break;
00181 default: info->fprintf_func (info->stream, "%d", value); break;
00182 case V850_OPERAND_DISP:
00183 {
00184 bfd_vma addr = value + memaddr;
00185
00186
00187
00188
00189
00190
00191
00192
00193 if (operand->bits == 22)
00194 {
00195 if ( ! info->symbol_at_address_func (addr, info)
00196 && ((addr & 0xFF000000) != 0)
00197 && info->symbol_at_address_func (addr & 0x00FFFFFF, info))
00198 {
00199 addr &= 0x00FFFFFF;
00200 }
00201 }
00202 info->print_address_func (addr, info);
00203 break;
00204 }
00205
00206 case V850E_PUSH_POP:
00207 {
00208 static int list12_regs[32] = { 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
00209 static int list18_h_regs[32] = { 19, 18, 17, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 30, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
00210 static int list18_l_regs[32] = { 3, 2, 1, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 14, 15, 13, 12, 7, 6, 5, 4, 11, 10, 9, 8 };
00211 int *regs;
00212 int i;
00213 unsigned long int mask = 0;
00214 int pc = 0;
00215 int sr = 0;
00216
00217
00218 switch (operand->shift)
00219 {
00220 case 0xffe00001: regs = list12_regs; break;
00221 case 0xfff8000f: regs = list18_h_regs; break;
00222 case 0xfff8001f: regs = list18_l_regs; value &= ~0x10; break;
00223 default:
00224
00225 fprintf (stderr, _("unknown operand shift: %x\n"), operand->shift );
00226 abort();
00227 }
00228
00229 for (i = 0; i < 32; i++)
00230 {
00231 if (value & (1 << i))
00232 {
00233 switch (regs[ i ])
00234 {
00235 default: mask |= (1 << regs[ i ]); break;
00236
00237 case 0: fprintf (stderr, _("unknown pop reg: %d\n"), i ); abort();
00238 case -1: pc = 1; break;
00239 case -2: sr = 1; break;
00240 }
00241 }
00242 }
00243
00244 info->fprintf_func (info->stream, "{");
00245
00246 if (mask || pc || sr)
00247 {
00248 if (mask)
00249 {
00250 unsigned int bit;
00251 int shown_one = 0;
00252
00253 for (bit = 0; bit < 32; bit++)
00254 if (mask & (1 << bit))
00255 {
00256 unsigned long int first = bit;
00257 unsigned long int last;
00258
00259 if (shown_one)
00260 info->fprintf_func (info->stream, ", ");
00261 else
00262 shown_one = 1;
00263
00264 info->fprintf_func (info->stream, v850_reg_names[first]);
00265
00266 for (bit++; bit < 32; bit++)
00267 if ((mask & (1 << bit)) == 0)
00268 break;
00269
00270 last = bit;
00271
00272 if (last > first + 1)
00273 {
00274 info->fprintf_func (info->stream, " - %s", v850_reg_names[ last - 1 ]);
00275 }
00276 }
00277 }
00278
00279 if (pc)
00280 info->fprintf_func (info->stream, "%sPC", mask ? ", " : "");
00281 if (sr)
00282 info->fprintf_func (info->stream, "%sSR", (mask || pc) ? ", " : "");
00283 }
00284
00285 info->fprintf_func (info->stream, "}");
00286 }
00287 break;
00288
00289 case V850E_IMMEDIATE16:
00290 status = info->read_memory_func (memaddr + bytes_read, buffer, 2, info);
00291 if (status == 0)
00292 {
00293 bytes_read += 2;
00294 value = bfd_getl16 (buffer);
00295
00296
00297 if ((insn & 0x001fffc0) == 0x00130780)
00298 value <<= 16;
00299
00300 info->fprintf_func (info->stream, "0x%x", value);
00301 }
00302 else
00303 {
00304 info->memory_error_func (status, memaddr + bytes_read, info);
00305 }
00306 break;
00307
00308 case V850E_IMMEDIATE32:
00309 status = info->read_memory_func (memaddr + bytes_read, buffer, 4, info);
00310 if (status == 0)
00311 {
00312 bytes_read += 4;
00313 value = bfd_getl32 (buffer);
00314 info->fprintf_func (info->stream, "0x%lx", value);
00315 }
00316 else
00317 {
00318 info->memory_error_func (status, memaddr + bytes_read, info);
00319 }
00320 break;
00321 }
00322
00323
00324 if (memop == 1 && opnum == 1
00325 && ((operand->flags & V850_OPERAND_REG) != 0))
00326 (*info->fprintf_func) (info->stream, "]");
00327 }
00328
00329
00330 if (memop && opnum == memop + 2)
00331 (*info->fprintf_func) (info->stream, "]");
00332
00333
00334 break;
00335 }
00336 op++;
00337 }
00338
00339 if (!match)
00340 {
00341 if (short_op)
00342 info->fprintf_func (info->stream, ".short\t0x%04x", insn);
00343 else
00344 info->fprintf_func (info->stream, ".long\t0x%08x", insn);
00345 }
00346
00347 return bytes_read;
00348 }
00349
00350 int
00351 print_insn_v850 (memaddr, info)
00352 bfd_vma memaddr;
00353 struct disassemble_info * info;
00354 {
00355 int status;
00356 bfd_byte buffer[4];
00357 unsigned long insn = 0;
00358
00359
00360
00361 status = info->read_memory_func (memaddr, buffer, 2, info);
00362 if (status == 0)
00363 {
00364 insn = bfd_getl16 (buffer);
00365
00366 if ( (insn & 0x0600) == 0x0600
00367 && (insn & 0xffe0) != 0x0620)
00368 {
00369
00370 status = info->read_memory_func (memaddr, buffer, 4, info);
00371
00372 if (status == 0)
00373 insn = bfd_getl32 (buffer);
00374 }
00375 }
00376
00377 if (status != 0)
00378 {
00379 info->memory_error_func (status, memaddr, info);
00380 return -1;
00381 }
00382
00383
00384 return disassemble (memaddr, info, insn);
00385 }