Coverage Report

Created: 2026-11-21 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/v850-dis.c
Line
Count
Source
1
/* Disassemble V850 instructions.
2
   Copyright (C) 1996-2026 Free Software Foundation, Inc.
3
4
   This file is part of the GNU opcodes library.
5
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)
9
   any later version.
10
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.
15
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.  */
20
21
22
#include "sysdep.h"
23
#include <stdio.h>
24
#include <string.h>
25
#include "opcode/v850.h"
26
#include "disassemble.h"
27
#include "opintl.h"
28
#include "libiberty.h"
29
30
static const int v850_cacheop_codes[] =
31
{
32
  0x00, 0x20, 0x40, 0x60, 0x61, 0x04, 0x06,
33
  0x07, 0x24, 0x26, 0x27, 0x44, 0x64, 0x65, -1
34
};
35
36
static const int v850_prefop_codes[] =
37
{ 0x00, 0x04, -1};
38
39
static void
40
print_value (int flags,
41
       bfd_vma memaddr,
42
       struct disassemble_info *info,
43
       long value)
44
323k
{
45
323k
  if (flags & V850_PCREL)
46
28.6k
    {
47
28.6k
      bfd_vma addr = value + memaddr;
48
49
28.6k
      if (flags & V850_INVERSE_PCREL)
50
278
  addr = memaddr - value;
51
28.6k
      info->print_address_func (addr, info);
52
28.6k
    }
53
294k
  else if (flags & V850_OPERAND_DISP)
54
197k
    {
55
197k
      if (flags & V850_OPERAND_SIGNED)
56
74.9k
        {
57
74.9k
          info->fprintf_func (info->stream, "%ld", value);
58
74.9k
        }
59
122k
      else
60
122k
        {
61
122k
          info->fprintf_func (info->stream, "%lu", value);
62
122k
        }
63
197k
    }
64
96.5k
  else if ((flags & V850E_IMMEDIATE32)
65
95.5k
     || (flags & V850E_IMMEDIATE16HI))
66
1.11k
    {
67
1.11k
      info->fprintf_func (info->stream, "0x%lx", value);
68
1.11k
    }
69
95.4k
  else
70
95.4k
    {
71
95.4k
      if (flags & V850_OPERAND_SIGNED)
72
56.0k
  {
73
56.0k
    info->fprintf_func (info->stream, "%ld", value);
74
56.0k
  }
75
39.3k
      else
76
39.3k
  {
77
39.3k
    info->fprintf_func (info->stream, "%lu", value);
78
39.3k
  }
79
95.4k
    }
80
323k
}
81
82
static long
83
get_operand_value (const struct v850_operand *operand,
84
       unsigned long insn,
85
       int bytes_read,
86
       bfd_vma memaddr,
87
       struct disassemble_info * info,
88
       bool noerror,
89
       int *invalid)
90
2.46M
{
91
2.46M
  unsigned long value;
92
2.46M
  bfd_byte buffer[4];
93
94
2.46M
  if ((operand->flags & V850E_IMMEDIATE16)
95
2.46M
      || (operand->flags & V850E_IMMEDIATE16HI))
96
794
    {
97
794
      int status = info->read_memory_func (memaddr + bytes_read, buffer, 2, info);
98
99
794
      if (status == 0)
100
794
  {
101
794
    value = bfd_getl16 (buffer);
102
103
794
    if (operand->flags & V850E_IMMEDIATE16HI)
104
344
      value <<= 16;
105
450
    else if (value & 0x8000)
106
220
      value |= (-1UL << 16);
107
108
794
    return value;
109
794
  }
110
111
0
      if (!noerror)
112
0
  info->memory_error_func (status, memaddr + bytes_read, info);
113
114
0
      return 0;
115
794
    }
116
117
2.46M
  if (operand->flags & V850E_IMMEDIATE23)
118
6.94k
    {
119
6.94k
      int status = info->read_memory_func (memaddr + 2, buffer, 4, info);
120
121
6.94k
      if (status == 0)
122
6.94k
  {
123
6.94k
    value = bfd_getl32 (buffer);
124
125
6.94k
    value = (operand->extract) (value, invalid);
126
127
6.94k
    return value;
128
6.94k
  }
129
130
0
      if (!noerror)
131
0
  info->memory_error_func (status, memaddr + bytes_read, info);
132
133
0
      return 0;
134
6.94k
    }
135
136
2.46M
  if (operand->flags & V850E_IMMEDIATE32)
137
6.03k
    {
138
6.03k
      int status = info->read_memory_func (memaddr + bytes_read, buffer, 4, info);
139
140
6.03k
      if (status == 0)
141
6.03k
  {
142
6.03k
    bytes_read += 4;
143
6.03k
    value = bfd_getl32 (buffer);
144
145
6.03k
    return value;
146
6.03k
  }
147
148
6
      if (!noerror)
149
3
  info->memory_error_func (status, memaddr + bytes_read, info);
150
151
6
      return 0;
152
6.03k
    }
153
154
2.45M
  if (operand->extract)
155
316k
    value = (operand->extract) (insn, invalid);
156
2.13M
  else
157
2.13M
    {
158
2.13M
      if (operand->bits == -1)
159
7.97k
  value = (insn & operand->shift);
160
2.13M
      else
161
2.13M
  value = (insn >> operand->shift) & ((1ul << operand->bits) - 1);
162
163
2.13M
      if (operand->flags & V850_OPERAND_SIGNED)
164
164k
  {
165
164k
    unsigned long sign = 1ul << (operand->bits - 1);
166
164k
    value = (value ^ sign) - sign;
167
164k
  }
168
2.13M
    }
169
170
2.45M
  return value;
171
2.46M
}
172
173
static const char *
174
get_v850_sreg_name (unsigned int reg)
175
915
{
176
915
  static const char *const v850_sreg_names[] =
177
915
    {
178
915
     "eipc/vip/mpm", "eipsw/mpc", "fepc/tid", "fepsw/ppa", "ecr/vmecr", "psw/vmtid",
179
915
     "sr6/fpsr/vmadr/dcc", "sr7/fpepc/dc0",
180
915
     "sr8/fpst/vpecr/dcv1", "sr9/fpcc/vptid", "sr10/fpcfg/vpadr/spal", "sr11/spau",
181
915
     "sr12/vdecr/ipa0l", "eiic/vdtid/ipa0u", "feic/ipa1l", "dbic/ipa1u",
182
915
     "ctpc/ipa2l", "ctpsw/ipa2u", "dbpc/ipa3l", "dbpsw/ipa3u", "ctbp/dpa0l",
183
915
     "dir/dpa0u", "bpc/dpa0u", "asid/dpa1l",
184
915
     "bpav/dpa1u", "bpam/dpa2l", "bpdv/dpa2u", "bpdm/dpa3l", "eiwr/dpa3u",
185
915
     "fewr", "dbwr", "bsel"
186
915
    };
187
188
915
  if (reg < ARRAY_SIZE (v850_sreg_names))
189
416
    return v850_sreg_names[reg];
190
499
  return _("<invalid s-reg number>");
191
915
}
192
193
static const char *
194
get_v850_reg_name (unsigned int reg)
195
679k
{
196
679k
  static const char *const v850_reg_names[] =
197
679k
    {
198
679k
     "r0", "r1", "r2", "sp", "gp", "r5", "r6", "r7",
199
679k
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
200
679k
     "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
201
679k
     "r24", "r25", "r26", "r27", "r28", "r29", "ep", "lp"
202
679k
    };
203
204
679k
  if (reg < ARRAY_SIZE (v850_reg_names))
205
679k
    return v850_reg_names[reg];
206
0
  return _("<invalid reg number>");
207
679k
}
208
209
static const char *
210
get_v850_vreg_name (unsigned int reg)
211
224
{
212
224
  static const char *const v850_vreg_names[] =
213
224
    {
214
224
     "vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7", "vr8", "vr9",
215
224
     "vr10", "vr11", "vr12", "vr13", "vr14", "vr15", "vr16", "vr17", "vr18",
216
224
     "vr19", "vr20", "vr21", "vr22", "vr23", "vr24", "vr25", "vr26", "vr27",
217
224
     "vr28", "vr29", "vr30", "vr31"
218
224
    };
219
220
224
  if (reg < ARRAY_SIZE (v850_vreg_names))
221
224
    return v850_vreg_names[reg];
222
0
  return _("<invalid v-reg number>");
223
224
}
224
225
static const char *
226
get_v850_cc_name (unsigned int reg)
227
686
{
228
686
  static const char *const v850_cc_names[] =
229
686
    {
230
686
     "v", "c/l", "z", "nh", "s/n", "t", "lt", "le",
231
686
     "nv", "nc/nl", "nz", "h", "ns/p", "sa", "ge", "gt"
232
686
    };
233
234
686
  if (reg < ARRAY_SIZE (v850_cc_names))
235
686
    return v850_cc_names[reg];
236
0
  return _("<invalid CC-reg number>");
237
686
}
238
239
static const char *
240
get_v850_float_cc_name (unsigned int reg)
241
279
{
242
279
  static const char *const v850_float_cc_names[] =
243
279
    {
244
279
     "f/t", "un/or", "eq/neq", "ueq/ogl", "olt/uge", "ult/oge", "ole/ugt", "ule/ogt",
245
279
     "sf/st", "ngle/gle", "seq/sne", "ngl/gl", "lt/nlt", "nge/ge", "le/nle", "ngt/gt"
246
279
    };
247
248
279
  if (reg < ARRAY_SIZE (v850_float_cc_names))
249
279
    return v850_float_cc_names[reg];
250
0
  return _("<invalid float-CC-reg number>");
251
279
}
252
253
static const char *
254
get_v850_cacheop_name (unsigned int reg)
255
169
{
256
169
  static const char *const v850_cacheop_names[] =
257
169
    {
258
169
     "chbii", "cibii", "cfali", "cisti", "cildi", "chbid", "chbiwbd",
259
169
     "chbwbd", "cibid", "cibiwbd", "cibwbd", "cfald", "cistd", "cildd"
260
169
    };
261
262
169
  if (reg < ARRAY_SIZE (v850_cacheop_names))
263
169
    return v850_cacheop_names[reg];
264
0
  return _("<invalid cacheop number>");
265
169
}
266
267
static const char *
268
get_v850_prefop_name (unsigned int reg)
269
79
{
270
79
  static const char *const v850_prefop_names[] =
271
79
    { "prefi", "prefd" };
272
273
79
  if (reg < ARRAY_SIZE (v850_prefop_names))
274
79
    return v850_prefop_names[reg];
275
0
  return _("<invalid prefop number>");
276
79
}
277
278
static int
279
disassemble (bfd_vma memaddr,
280
       struct disassemble_info *info,
281
       int bytes_read,
282
       unsigned long insn)
283
559k
{
284
559k
  struct v850_opcode *op = (struct v850_opcode *) v850_opcodes;
285
559k
  const struct v850_operand *operand;
286
559k
  int match = 0;
287
559k
  int target_processor;
288
289
559k
  switch (info->mach)
290
559k
    {
291
3.76k
    case 0:
292
18.9k
    default:
293
18.9k
      target_processor = PROCESSOR_V850;
294
18.9k
      break;
295
296
6.36k
    case bfd_mach_v850e:
297
6.36k
      target_processor = PROCESSOR_V850E;
298
6.36k
      break;
299
300
25.3k
    case bfd_mach_v850e1:
301
25.3k
      target_processor = PROCESSOR_V850E;
302
25.3k
      break;
303
304
810
    case bfd_mach_v850e2:
305
810
      target_processor = PROCESSOR_V850E2;
306
810
      break;
307
308
120k
    case bfd_mach_v850e2v3:
309
120k
      target_processor = PROCESSOR_V850E2V3;
310
120k
      break;
311
312
387k
    case bfd_mach_v850e3v5:
313
387k
      target_processor = PROCESSOR_V850E3V5;
314
387k
      break;
315
559k
    }
316
317
  /* If this is a two byte insn, then mask off the high bits.  */
318
559k
  if (bytes_read == 2)
319
425k
    insn &= 0xffff;
320
321
  /* Find the opcode.  */
322
116M
  while (op->name)
323
116M
    {
324
116M
      if ((op->mask & insn) == op->opcode
325
660k
    && (op->processors & target_processor)
326
655k
    && !(op->processors & PROCESSOR_OPTION_ALIAS))
327
653k
  {
328
    /* Code check start.  */
329
653k
    const unsigned char *opindex_ptr;
330
653k
    unsigned int opnum;
331
653k
    unsigned int memop;
332
333
653k
    for (opindex_ptr = op->operands, opnum = 1;
334
1.88M
         *opindex_ptr != 0;
335
1.23M
         opindex_ptr++, opnum++)
336
1.35M
      {
337
1.35M
        int invalid = 0;
338
1.35M
        long value;
339
340
1.35M
        operand = &v850_operands[*opindex_ptr];
341
342
1.35M
        value = get_operand_value (operand, insn, bytes_read, memaddr,
343
1.35M
           info, 1, &invalid);
344
345
1.35M
        if (invalid)
346
272
    goto next_opcode;
347
348
1.35M
              if ((operand->flags & V850_NOT_R0) && value == 0 && (op->memop) <=2)
349
114k
    goto next_opcode;
350
351
1.23M
        if ((operand->flags & V850_NOT_SA) && value == 0xd)
352
123
    goto next_opcode;
353
354
1.23M
        if ((operand->flags & V850_NOT_IMM0) && value == 0)
355
983
    goto next_opcode;
356
1.23M
      }
357
358
    /* Code check end.  */
359
360
537k
    match = 1;
361
537k
    (*info->fprintf_func) (info->stream, "%s\t", op->name);
362
#if 0
363
    fprintf (stderr, "match: insn: %lx, mask: %lx, opcode: %lx, name: %s\n",
364
       insn, op->mask, op->opcode, op->name );
365
#endif
366
367
537k
    memop = op->memop;
368
    /* Now print the operands.
369
370
       MEMOP is the operand number at which a memory
371
       address specification starts, or zero if this
372
       instruction has no memory addresses.
373
374
       A memory address is always two arguments.
375
376
       This information allows us to determine when to
377
       insert commas into the output stream as well as
378
       when to insert disp[reg] expressions onto the
379
       output stream.  */
380
381
537k
    for (opindex_ptr = op->operands, opnum = 1;
382
1.65M
         *opindex_ptr != 0;
383
1.11M
         opindex_ptr++, opnum++)
384
1.11M
      {
385
1.11M
        bool square = false;
386
1.11M
        long value;
387
1.11M
        int flag;
388
1.11M
        char *prefix;
389
390
1.11M
        operand = &v850_operands[*opindex_ptr];
391
392
1.11M
        value = get_operand_value (operand, insn, bytes_read, memaddr,
393
1.11M
           info, 0, 0);
394
395
        /* The first operand is always output without any
396
     special handling.
397
398
     For the following arguments:
399
400
       If memop && opnum == memop + 1, then we need '[' since
401
       we're about to output the register used in a memory
402
       reference.
403
404
       If memop && opnum == memop + 2, then we need ']' since
405
       we just finished the register in a memory reference.  We
406
       also need a ',' before this operand.
407
408
       Else we just need a comma.
409
410
       We may need to output a trailing ']' if the last operand
411
       in an instruction is the register for a memory address.
412
413
       The exception (and there's always an exception) are the
414
       "jmp" insn which needs square brackets around it's only
415
       register argument, and the clr1/not1/set1/tst1 insns
416
       which [...] around their second register argument.  */
417
418
1.11M
        prefix = "";
419
1.11M
        if (operand->flags & V850_OPERAND_BANG)
420
0
    {
421
0
      prefix = "!";
422
0
    }
423
1.11M
        else if (operand->flags & V850_OPERAND_PERCENT)
424
0
    {
425
0
      prefix = "%";
426
0
    }
427
428
1.11M
        if (opnum == 1 && opnum == memop)
429
5.04k
    {
430
5.04k
      info->fprintf_func (info->stream, "%s[", prefix);
431
5.04k
      square = true;
432
5.04k
    }
433
1.11M
        else if (   (strcmp ("stc.w", op->name) == 0
434
1.11M
      || strcmp ("cache", op->name) == 0
435
1.11M
      || strcmp ("pref",  op->name) == 0)
436
1.43k
           && opnum == 2 && opnum == memop)
437
716
    {
438
716
      info->fprintf_func (info->stream, ", [");
439
716
      square = true;
440
716
    }
441
1.11M
        else if (   (strcmp (op->name, "pushsp") == 0
442
1.11M
      || strcmp (op->name, "popsp") == 0
443
1.11M
      || strcmp (op->name, "dbpush" ) == 0)
444
346
           && opnum == 2)
445
173
    {
446
173
      info->fprintf_func (info->stream, "-");
447
173
    }
448
1.11M
        else if (opnum > 1
449
656k
           && (v850_operands[*(opindex_ptr - 1)].flags
450
656k
         & V850_OPERAND_DISP) != 0
451
202k
           && opnum == memop)
452
197k
    {
453
197k
      info->fprintf_func (info->stream, "%s[", prefix);
454
197k
      square = true;
455
197k
    }
456
914k
        else if (opnum == 2
457
277k
           && (   op->opcode == 0x00e407e0 /* clr1 */
458
277k
         || op->opcode == 0x00e207e0 /* not1 */
459
277k
         || op->opcode == 0x00e007e0 /* set1 */
460
277k
         || op->opcode == 0x00e607e0 /* tst1 */
461
277k
         ))
462
264
    {
463
264
      info->fprintf_func (info->stream, ", %s[", prefix);
464
264
      square = true;
465
264
    }
466
914k
        else if (opnum > 1)
467
458k
    info->fprintf_func (info->stream, ", %s", prefix);
468
469
        /* Extract the flags, ignoring ones which do not
470
     effect disassembly output.  */
471
1.11M
        flag = operand->flags & (V850_OPERAND_REG
472
1.11M
               | V850_REG_EVEN
473
1.11M
               | V850_OPERAND_EP
474
1.11M
               | V850_OPERAND_SRG
475
1.11M
               | V850E_OPERAND_REG_LIST
476
1.11M
               | V850_OPERAND_CC
477
1.11M
               | V850_OPERAND_VREG
478
1.11M
               | V850_OPERAND_CACHEOP
479
1.11M
               | V850_OPERAND_PREFOP
480
1.11M
               | V850_OPERAND_FLOAT_CC);
481
482
1.11M
        switch (flag)
483
1.11M
    {
484
665k
    case V850_OPERAND_REG:
485
665k
      info->fprintf_func (info->stream, "%s", get_v850_reg_name (value));
486
665k
      break;
487
536
    case (V850_OPERAND_REG|V850_REG_EVEN):
488
536
      info->fprintf_func (info->stream, "%s", get_v850_reg_name (value * 2));
489
536
      break;
490
122k
    case V850_OPERAND_EP:
491
122k
      info->fprintf_func (info->stream, "ep");
492
122k
      break;
493
915
    case V850_OPERAND_SRG:
494
915
      info->fprintf_func (info->stream, "%s", get_v850_sreg_name (value));
495
915
      break;
496
3.98k
    case V850E_OPERAND_REG_LIST:
497
3.98k
      {
498
3.98k
        static int list12_regs[32]   = { 30, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
499
3.98k
                 0,  0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
500
3.98k
        int *regs;
501
3.98k
        int i;
502
3.98k
        unsigned int mask = 0;
503
3.98k
        int pc = 0;
504
505
3.98k
        switch (operand->shift)
506
3.98k
          {
507
3.98k
          case 0xffe00001: regs = list12_regs; break;
508
0
          default:
509
      /* xgettext:c-format */
510
0
      opcodes_error_handler (_("unknown operand shift: %x"),
511
0
                 operand->shift);
512
0
      abort ();
513
3.98k
          }
514
515
131k
        for (i = 0; i < 32; i++)
516
127k
          {
517
127k
      if (value & (1u << i))
518
18.3k
        {
519
18.3k
          switch (regs[ i ])
520
18.3k
            {
521
18.3k
            default:
522
18.3k
        mask |= (1u << regs[ i ]);
523
18.3k
        break;
524
0
            case 0:
525
        /* xgettext:c-format */
526
0
        opcodes_error_handler (_("unknown reg: %d"), i);
527
0
        abort ();
528
0
        break;
529
0
            case -1:
530
0
        pc = 1;
531
0
        break;
532
18.3k
            }
533
18.3k
        }
534
127k
          }
535
536
3.98k
        info->fprintf_func (info->stream, "{");
537
538
3.98k
        if (mask || pc)
539
3.20k
          {
540
3.20k
      if (mask)
541
3.20k
        {
542
3.20k
          unsigned int bit;
543
3.20k
          int shown_one = 0;
544
545
88.9k
          for (bit = 0; bit < 32; bit++)
546
85.7k
            if (mask & (1u << bit))
547
9.73k
        {
548
9.73k
          unsigned int first = bit;
549
9.73k
          unsigned int last;
550
551
9.73k
          if (shown_one)
552
6.52k
            info->fprintf_func (info->stream, ", ");
553
3.20k
          else
554
3.20k
            shown_one = 1;
555
556
9.73k
          info->fprintf_func (info->stream, "%s", get_v850_reg_name (first));
557
558
18.3k
          for (bit++; bit < 32; bit++)
559
16.8k
            if ((mask & (1u << bit)) == 0)
560
8.19k
              break;
561
562
9.73k
          last = bit;
563
564
9.73k
          if (last > first + 1)
565
4.27k
            {
566
4.27k
              info->fprintf_func (info->stream, " - %s", get_v850_reg_name (last - 1));
567
4.27k
            }
568
9.73k
        }
569
3.20k
        }
570
571
3.20k
      if (pc)
572
0
        info->fprintf_func (info->stream, "%sPC", mask ? ", " : "");
573
3.20k
          }
574
575
3.98k
        info->fprintf_func (info->stream, "}");
576
3.98k
      }
577
0
      break;
578
579
686
    case V850_OPERAND_CC:
580
686
      info->fprintf_func (info->stream, "%s", get_v850_cc_name (value));
581
686
      break;
582
583
279
    case V850_OPERAND_FLOAT_CC:
584
279
      info->fprintf_func (info->stream, "%s", get_v850_float_cc_name (value));
585
279
      break;
586
587
334
    case V850_OPERAND_CACHEOP:
588
334
      {
589
334
        int idx;
590
591
4.15k
        for (idx = 0; v850_cacheop_codes[idx] != -1; idx++)
592
3.99k
          {
593
3.99k
      if (value == v850_cacheop_codes[idx])
594
169
        {
595
169
          info->fprintf_func (info->stream, "%s",
596
169
            get_v850_cacheop_name (idx));
597
169
          goto MATCH_CACHEOP_CODE;
598
169
        }
599
3.99k
          }
600
165
        info->fprintf_func (info->stream, "%d", (int) value);
601
165
      }
602
334
    MATCH_CACHEOP_CODE:
603
334
      break;
604
605
346
    case V850_OPERAND_PREFOP:
606
346
      {
607
346
        int idx;
608
609
880
        for (idx = 0; v850_prefop_codes[idx] != -1; idx++)
610
613
          {
611
613
      if (value == v850_prefop_codes[idx])
612
79
        {
613
79
          info->fprintf_func (info->stream, "%s",
614
79
            get_v850_prefop_name (idx));
615
79
          goto MATCH_PREFOP_CODE;
616
79
        }
617
613
          }
618
267
        info->fprintf_func (info->stream, "%d", (int) value);
619
267
      }
620
346
    MATCH_PREFOP_CODE:
621
346
      break;
622
623
224
    case V850_OPERAND_VREG:
624
224
      info->fprintf_func (info->stream, "%s", get_v850_vreg_name (value));
625
224
      break;
626
627
323k
    default:
628
323k
      print_value (operand->flags, memaddr, info, value);
629
323k
      break;
630
1.11M
    }
631
632
1.11M
        if (square)
633
204k
    (*info->fprintf_func) (info->stream, "]");
634
1.11M
      }
635
636
    /* All done. */
637
537k
    break;
638
537k
  }
639
116M
    next_opcode:
640
116M
      op++;
641
116M
    }
642
643
559k
  return match;
644
559k
}
645
646
int
647
print_insn_v850 (bfd_vma memaddr, struct disassemble_info * info)
648
559k
{
649
559k
  int status, status2, match;
650
559k
  bfd_byte buffer[8];
651
559k
  int length = 0, code_length = 0;
652
559k
  unsigned long insn = 0, insn2 = 0;
653
559k
  int target_processor;
654
655
559k
  switch (info->mach)
656
559k
    {
657
3.79k
    case 0:
658
19.0k
    default:
659
19.0k
      target_processor = PROCESSOR_V850;
660
19.0k
      break;
661
662
6.37k
    case bfd_mach_v850e:
663
6.37k
      target_processor = PROCESSOR_V850E;
664
6.37k
      break;
665
666
25.3k
    case bfd_mach_v850e1:
667
25.3k
      target_processor = PROCESSOR_V850E;
668
25.3k
      break;
669
670
828
    case bfd_mach_v850e2:
671
828
      target_processor = PROCESSOR_V850E2;
672
828
      break;
673
674
120k
    case bfd_mach_v850e2v3:
675
120k
      target_processor = PROCESSOR_V850E2V3;
676
120k
      break;
677
678
387k
    case bfd_mach_v850e3v5:
679
387k
      target_processor = PROCESSOR_V850E3V5;
680
387k
      break;
681
559k
    }
682
683
559k
  status = info->read_memory_func (memaddr, buffer, 2, info);
684
685
559k
  if (status)
686
271
    {
687
271
      info->memory_error_func (status, memaddr, info);
688
271
      return -1;
689
271
    }
690
691
559k
  insn = bfd_getl16 (buffer);
692
693
559k
  status2 = info->read_memory_func (memaddr+2, buffer, 2 , info);
694
695
559k
  if (!status2)
696
558k
    {
697
558k
      insn2 = bfd_getl16 (buffer);
698
      /* fprintf (stderr, "insn2 0x%08lx\n", insn2); */
699
558k
    }
700
701
  /* Special case.  */
702
559k
  if (length == 0
703
559k
      && ((target_processor & PROCESSOR_V850E2_UP) != 0))
704
508k
    {
705
508k
      if ((insn & 0xffff) == 0x02e0    /* jr 32bit */
706
131
    && !status2 && (insn2 & 0x1) == 0)
707
105
  {
708
105
    length = 2;
709
105
    code_length = 6;
710
105
  }
711
508k
      else if ((insn & 0xffe0) == 0x02e0  /* jarl 32bit */
712
1.22k
         && !status2 && (insn2 & 0x1) == 0)
713
1.09k
  {
714
1.09k
    length = 2;
715
1.09k
    code_length = 6;
716
1.09k
  }
717
507k
      else if ((insn & 0xffe0) == 0x06e0  /* jmp 32bit */
718
953
         && !status2 && (insn2 & 0x1) == 0)
719
672
  {
720
672
    length = 2;
721
672
    code_length = 6;
722
672
  }
723
508k
    }
724
725
559k
  if (length == 0
726
557k
      && ((target_processor & PROCESSOR_V850E3V5_UP) != 0))
727
385k
    {
728
385k
      if (   ((insn & 0xffe0) == 0x07a0    /* ld.dw 23bit (v850e3v5) */
729
3.72k
        && !status2 && (insn2 & 0x000f) == 0x0009)
730
385k
    || ((insn & 0xffe0) == 0x07a0    /* st.dw 23bit (v850e3v5) */
731
3.62k
        && !status2 && (insn2 & 0x000f) == 0x000f))
732
524
  {
733
524
    length = 4;
734
524
    code_length = 6;
735
524
  }
736
385k
    }
737
738
559k
  if (length == 0
739
557k
      && ((target_processor & PROCESSOR_V850E2V3_UP) != 0))
740
505k
    {
741
505k
      if (((insn & 0xffe0) == 0x0780    /* ld.b 23bit */
742
1.75k
     && !status2 && (insn2 & 0x000f) == 0x0005)
743
505k
    || ((insn & 0xffe0) == 0x07a0    /* ld.bu 23bit */
744
3.25k
        && !status2 && (insn2 & 0x000f) == 0x0005)
745
505k
    || ((insn & 0xffe0) == 0x0780    /* ld.h 23bit */
746
1.72k
        && !status2 && (insn2 & 0x000f) == 0x0007)
747
504k
    || ((insn & 0xffe0) == 0x07a0    /* ld.hu 23bit */
748
3.10k
        && !status2 && (insn2 & 0x000f) == 0x0007)
749
504k
    || ((insn & 0xffe0) == 0x0780    /* ld.w 23bit */
750
1.18k
        && !status2 && (insn2 & 0x000f) == 0x0009))
751
1.72k
  {
752
1.72k
    length = 4;
753
1.72k
    code_length = 6;
754
1.72k
  }
755
503k
      else if (((insn & 0xffe0) == 0x0780  /* st.b 23bit */
756
825
         && !status2 && (insn2 & 0x000f) == 0x000d)
757
503k
        || ((insn & 0xffe0) == 0x07a0  /* st.h 23bit */
758
2.46k
      && !status2 && (insn2 & 0x000f) == 0x000d)
759
502k
        || ((insn & 0xffe0) == 0x0780  /* st.w 23bit */
760
695
      && !status2 && (insn2 & 0x000f) == 0x000f))
761
1.70k
  {
762
1.70k
    length = 4;
763
1.70k
    code_length = 6;
764
1.70k
  }
765
505k
    }
766
767
559k
  if (length == 0
768
553k
      && target_processor != PROCESSOR_V850)
769
534k
    {
770
534k
      if ((insn & 0xffe0) == 0x0620)    /* 32 bit MOV */
771
487
  {
772
487
    length = 2;
773
487
    code_length = 6;
774
487
  }
775
534k
      else if ((insn & 0xffc0) == 0x0780  /* prepare {list}, imm5, imm16<<16 */
776
2.04k
         && !status2 && (insn2 & 0x001f) == 0x0013)
777
172
  {
778
172
    length = 4;
779
172
    code_length = 6;
780
172
  }
781
534k
      else if ((insn & 0xffc0) == 0x0780  /* prepare {list}, imm5, imm16 */
782
1.87k
         && !status2 && (insn2 & 0x001f) == 0x000b)
783
225
  {
784
225
    length = 4;
785
225
    code_length = 6;
786
225
  }
787
533k
      else if ((insn & 0xffc0) == 0x0780  /* prepare {list}, imm5, imm32 */
788
1.64k
         && !status2 && (insn2 & 0x001f) == 0x001b)
789
463
  {
790
463
    length = 4;
791
463
    code_length = 8;
792
463
  }
793
534k
    }
794
795
559k
  if (length == 4
796
554k
      || (length == 0
797
552k
    && (insn & 0x0600) == 0x0600))
798
134k
    {
799
      /* This is a 4 byte insn.  */
800
134k
      status = info->read_memory_func (memaddr, buffer, 4, info);
801
134k
      if (!status)
802
134k
  {
803
134k
    insn = bfd_getl32 (buffer);
804
805
134k
    if (!length)
806
129k
      length = code_length = 4;
807
134k
  }
808
134k
    }
809
810
559k
  if (code_length > length)
811
7.17k
    {
812
7.17k
      status = info->read_memory_func (memaddr + length, buffer, code_length - length, info);
813
7.17k
      if (status)
814
4
  length = 0;
815
7.17k
    }
816
817
559k
  if (length == 0 && !status)
818
422k
    length = code_length = 2;
819
820
559k
  if (length == 2)
821
425k
    insn &= 0xffff;
822
823
  /* when the last 2 bytes of section is 0xffff, length will be 0 and cause infinitive loop */
824
559k
  if (length == 0)
825
96
    return -1;
826
827
559k
  match = disassemble (memaddr, info, length, insn);
828
829
559k
  if (!match)
830
21.7k
    {
831
21.7k
      int l = 0;
832
833
21.7k
      status = info->read_memory_func (memaddr, buffer, code_length, info);
834
835
44.0k
      while (l < code_length)
836
22.2k
  {
837
22.2k
    if (code_length - l == 2)
838
15.0k
      {
839
15.0k
        insn = bfd_getl16 (buffer + l) & 0xffff;
840
15.0k
        info->fprintf_func (info->stream, ".short\t0x%04lx", insn);
841
15.0k
        l += 2;
842
15.0k
      }
843
7.19k
    else
844
7.19k
      {
845
7.19k
        insn = bfd_getl32 (buffer + l);
846
7.19k
        info->fprintf_func (info->stream, ".long\t0x%08lx", insn);
847
7.19k
        l += 4;
848
7.19k
      }
849
22.2k
  }
850
21.7k
    }
851
852
559k
  return code_length;
853
559k
}