Coverage Report

Created: 2026-05-11 07:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/crx-dis.c
Line
Count
Source
1
/* Disassembler code for CRX.
2
   Copyright (C) 2004-2026 Free Software Foundation, Inc.
3
   Contributed by Tomer Levi, NSC, Israel.
4
   Written by Tomer Levi.
5
6
   This file is part of the GNU opcodes library.
7
8
   This library is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3, or (at your option)
11
   any later version.
12
13
   It is distributed in the hope that it will be useful, but WITHOUT
14
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16
   License for more details.
17
18
   You should have received a copy of the GNU General Public License
19
   along with this program; if not, write to the Free Software
20
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21
   MA 02110-1301, USA.  */
22
23
#include "sysdep.h"
24
#include "disassemble.h"
25
#include "opcode/crx.h"
26
27
/* String to print when opcode was not matched.  */
28
59.4k
#define ILLEGAL "illegal"
29
  /* Escape to 16-bit immediate.  */
30
642
#define ESCAPE_16_BIT  0xE
31
32
/* Extract 'n_bits' from 'a' starting from offset 'offs'.  */
33
#define EXTRACT(a, offs, n_bits)      \
34
452k
  (((a) >> (offs)) & ((2ull << (n_bits - 1)) - 1))
35
36
/* Set Bit Mask - a mask to set all bits starting from offset 'offs'.  */
37
74.5M
#define SBM(offs)  ((-1u << (offs)) & 0xffffffff)
38
39
typedef unsigned long dwordU;
40
typedef unsigned short wordU;
41
42
typedef struct
43
{
44
  dwordU val;
45
  int nbits;
46
} parameter;
47
48
/* Structure to hold valid 'cinv' instruction options.  */
49
50
typedef struct
51
  {
52
    /* Cinv printed string.  */
53
    char *str;
54
    /* Value corresponding to the string.  */
55
    unsigned int value;
56
  }
57
cinv_entry;
58
59
/* CRX 'cinv' options.  */
60
static const cinv_entry crx_cinvs[] =
61
{
62
  {"[i]", 2}, {"[i,u]", 3}, {"[d]", 4}, {"[d,u]", 5},
63
  {"[d,i]", 6}, {"[d,i,u]", 7}, {"[b]", 8},
64
  {"[b,i]", 10}, {"[b,i,u]", 11}, {"[b,d]", 12},
65
  {"[b,d,u]", 13}, {"[b,d,i]", 14}, {"[b,d,i,u]", 15}
66
};
67
68
/* Enum to distinguish different registers argument types.  */
69
typedef enum REG_ARG_TYPE
70
  {
71
    /* General purpose register (r<N>).  */
72
    REG_ARG = 0,
73
    /* User register (u<N>).  */
74
    USER_REG_ARG,
75
    /* CO-Processor register (c<N>).  */
76
    COP_ARG,
77
    /* CO-Processor special register (cs<N>).  */
78
    COPS_ARG
79
  }
80
REG_ARG_TYPE;
81
82
/* Number of valid 'cinv' instruction options.  */
83
static int NUMCINVS = ((sizeof crx_cinvs)/(sizeof crx_cinvs[0]));
84
/* Current opcode table entry we're disassembling.  */
85
static const inst *instruction;
86
/* Current instruction we're disassembling.  */
87
static ins currInsn;
88
/* The current instruction is read into 3 consecutive words.  */
89
static wordU words[3];
90
/* Contains all words in appropriate order.  */
91
static ULONGLONG allWords;
92
/* Holds the current processed argument number.  */
93
static int processing_argument_number;
94
/* Nonzero means a CST4 instruction.  */
95
static int cst4flag;
96
/* Nonzero means the instruction's original size is
97
   incremented (escape sequence is used).  */
98
static int size_changed;
99
100
101
/* Retrieve the number of operands for the current assembled instruction.  */
102
103
static int
104
get_number_of_operands (void)
105
213k
{
106
213k
  int i;
107
108
608k
  for (i = 0; i < MAX_OPERANDS && instruction->operands[i].op_type; i++)
109
395k
    ;
110
111
213k
  return i;
112
213k
}
113
114
/* Return the bit size for a given operand.  */
115
116
static int
117
getbits (operand_type op)
118
395k
{
119
395k
  if (op < MAX_OPRD)
120
395k
    return crx_optab[op].bit_size;
121
0
  else
122
0
    return 0;
123
395k
}
124
125
/* Return the argument type of a given operand.  */
126
127
static argtype
128
getargtype (operand_type op)
129
395k
{
130
395k
  if (op < MAX_OPRD)
131
395k
    return crx_optab[op].arg_type;
132
0
  else
133
0
    return nullargs;
134
395k
}
135
136
/* Given the trap index in dispatch table, return its name.
137
   This routine is used when disassembling the 'excp' instruction.  */
138
139
static char *
140
gettrapstring (unsigned int trap_index)
141
20.8k
{
142
20.8k
  const trap_entry *trap;
143
144
184k
  for (trap = crx_traps; trap < crx_traps + NUMTRAPS; trap++)
145
164k
    if (trap->entry == trap_index)
146
490
      return trap->name;
147
148
20.3k
  return ILLEGAL;
149
20.8k
}
150
151
/* Given a 'cinv' instruction constant operand, return its corresponding string.
152
   This routine is used when disassembling the 'cinv' instruction.  */
153
154
static char *
155
getcinvstring (unsigned int num)
156
110
{
157
110
  const cinv_entry *cinv;
158
159
737
  for (cinv = crx_cinvs; cinv < (crx_cinvs + NUMCINVS); cinv++)
160
711
    if (cinv->value == num)
161
84
      return cinv->str;
162
163
26
  return ILLEGAL;
164
110
}
165
166
/* Given a register enum value, retrieve its name.  */
167
168
static char *
169
getregname (reg r)
170
262k
{
171
262k
  const reg_entry * regentry = &crx_regtab[r];
172
173
262k
  if (regentry->type != CRX_R_REGTYPE)
174
0
    return ILLEGAL;
175
262k
  else
176
262k
    return regentry->name;
177
262k
}
178
179
/* Given a coprocessor register enum value, retrieve its name.  */
180
181
static char *
182
getcopregname (copreg r, reg_type type)
183
84
{
184
84
  const reg_entry * regentry;
185
186
84
  if (type == CRX_C_REGTYPE)
187
57
    regentry = &crx_copregtab[r];
188
27
  else if (type == CRX_CS_REGTYPE)
189
27
    regentry = &crx_copregtab[r+(cs0-c0)];
190
0
  else
191
0
    return ILLEGAL;
192
193
84
  return regentry->name;
194
84
}
195
196
197
/* Getting a processor register name.  */
198
199
static char *
200
getprocregname (int reg_index)
201
728
{
202
728
  const reg_entry *r;
203
204
5.10k
  for (r = crx_regtab; r < crx_regtab + NUMREGS; r++)
205
5.02k
    if (r->image == reg_index)
206
647
      return r->name;
207
208
81
  return "ILLEGAL REGISTER";
209
728
}
210
211
/* Get the power of two for a given integer.  */
212
213
static int
214
powerof2 (int x)
215
1.55k
{
216
1.55k
  int product, i;
217
218
2.90k
  for (i = 0, product = 1; i < x; i++)
219
1.34k
    product *= 2;
220
221
1.55k
  return product;
222
1.55k
}
223
224
/* Transform a register bit mask to a register list.  */
225
226
static void
227
getregliststring (int mask, char *string, enum REG_ARG_TYPE core_cop)
228
1.15k
{
229
1.15k
  char temp_string[16];
230
1.15k
  int i;
231
232
1.15k
  string[0] = '{';
233
1.15k
  string[1] = '\0';
234
235
236
  /* A zero mask means HI/LO registers.  */
237
1.15k
  if (mask == 0)
238
145
    {
239
145
      if (core_cop == USER_REG_ARG)
240
71
  strcat (string, "ulo,uhi");
241
74
      else
242
74
  strcat (string, "lo,hi");
243
145
    }
244
1.00k
  else
245
1.00k
    {
246
17.0k
      for (i = 0; i < 16; i++)
247
16.0k
  {
248
16.0k
    if (mask & 0x1)
249
6.26k
      {
250
6.26k
        switch (core_cop)
251
6.26k
        {
252
5.39k
        case REG_ARG:
253
5.39k
    sprintf (temp_string, "r%d", i);
254
5.39k
    break;
255
219
        case USER_REG_ARG:
256
219
    sprintf (temp_string, "u%d", i);
257
219
    break;
258
384
        case COP_ARG:
259
384
    sprintf (temp_string, "c%d", i);
260
384
    break;
261
264
        case COPS_ARG:
262
264
    sprintf (temp_string, "cs%d", i);
263
264
    break;
264
0
        default:
265
0
    break;
266
6.26k
        }
267
6.26k
        strcat (string, temp_string);
268
6.26k
        if (mask & 0xfffe)
269
5.25k
    strcat (string, ",");
270
6.26k
      }
271
16.0k
    mask >>= 1;
272
16.0k
  }
273
1.00k
    }
274
275
1.15k
  strcat (string, "}");
276
1.15k
}
277
278
/* START and END are relating 'allWords' struct, which is 48 bits size.
279
280
        START|--------|END
281
      +---------+---------+---------+---------+
282
      |       |    V    |     A   |   L     |
283
      +---------+---------+---------+---------+
284
              0   16    32      48
285
    words     [0]     [1]       [2] */
286
287
static parameter
288
makelongparameter (ULONGLONG val, int start, int end)
289
452k
{
290
452k
  parameter p;
291
292
452k
  p.val = (dwordU) EXTRACT(val, 48 - end, end - start);
293
452k
  p.nbits = end - start;
294
452k
  return p;
295
452k
}
296
297
/* Build a mask of the instruction's 'constant' opcode,
298
   based on the instruction's printing flags.  */
299
300
static unsigned int
301
build_mask (void)
302
99.6M
{
303
99.6M
  unsigned int print_flags;
304
99.6M
  unsigned int mask;
305
306
99.6M
  print_flags = instruction->flags & FMT_CRX;
307
99.6M
  switch (print_flags)
308
99.6M
    {
309
2.28M
      case FMT_1:
310
2.28M
  mask = 0xF0F00000;
311
2.28M
  break;
312
1.83M
      case FMT_2:
313
1.83M
  mask = 0xFFF0FF00;
314
1.83M
  break;
315
19.1M
      case FMT_3:
316
19.1M
  mask = 0xFFF00F00;
317
19.1M
  break;
318
919k
      case FMT_4:
319
919k
  mask = 0xFFF0F000;
320
919k
  break;
321
919k
      case FMT_5:
322
919k
  mask = 0xFFF0FFF0;
323
919k
  break;
324
74.5M
      default:
325
74.5M
  mask = SBM(instruction->match_bits);
326
74.5M
  break;
327
99.6M
    }
328
329
99.6M
  return mask;
330
99.6M
}
331
332
/* Search for a matching opcode. Return 1 for success, 0 for failure.  */
333
334
static int
335
match_opcode (void)
336
252k
{
337
252k
  unsigned int mask;
338
339
  /* The instruction 'constant' opcode doewsn't exceed 32 bits.  */
340
252k
  unsigned int doubleWord = words[1] + ((unsigned) words[0] << 16);
341
342
  /* Start searching from end of instruction table.  */
343
252k
  instruction = &crx_instruction[NUMOPCODES - 2];
344
345
  /* Loop over instruction table until a full match is found.  */
346
99.6M
  while (instruction >= crx_instruction)
347
99.6M
    {
348
99.6M
      mask = build_mask ();
349
99.6M
      if ((doubleWord & mask) == BIN(instruction->match, instruction->match_bits))
350
228k
  return 1;
351
99.4M
      else
352
99.4M
  instruction--;
353
99.6M
    }
354
24.4k
  return 0;
355
252k
}
356
357
/* Set the proper parameter value for different type of arguments.  */
358
359
static void
360
make_argument (argument * a, int start_bits)
361
395k
{
362
395k
  int inst_bit_size, total_size;
363
395k
  parameter p;
364
365
395k
  if ((instruction->size == 3) && a->size >= 16)
366
6.65k
    inst_bit_size = 48;
367
388k
  else
368
388k
    inst_bit_size = 32;
369
370
395k
  switch (a->type)
371
395k
    {
372
57
    case arg_copr:
373
84
    case arg_copsr:
374
84
      p = makelongparameter (allWords, inst_bit_size - (start_bits + a->size),
375
84
           inst_bit_size - start_bits);
376
84
      a->cr = p.val;
377
84
      break;
378
379
199k
    case arg_r:
380
199k
      p = makelongparameter (allWords, inst_bit_size - (start_bits + a->size),
381
199k
           inst_bit_size - start_bits);
382
199k
      a->r = p.val;
383
199k
      break;
384
385
112k
    case arg_ic:
386
112k
      p = makelongparameter (allWords, inst_bit_size - (start_bits + a->size),
387
112k
           inst_bit_size - start_bits);
388
389
112k
      if ((p.nbits == 4) && cst4flag)
390
62.9k
  {
391
62.9k
    if (IS_INSN_TYPE (CMPBR_INS) && (p.val == ESCAPE_16_BIT))
392
339
      {
393
        /* A special case, where the value is actually stored
394
     in the last 4 bits.  */
395
339
        p = makelongparameter (allWords, 44, 48);
396
        /* The size of the instruction should be incremented.  */
397
339
        size_changed = 1;
398
339
      }
399
400
62.9k
    if (p.val == 6)
401
2.59k
      p.val = -1;
402
60.3k
    else if (p.val == 13)
403
1.16k
      p.val = 48;
404
59.1k
    else if (p.val == 5)
405
2.29k
      p.val = -4;
406
56.8k
    else if (p.val == 10)
407
1.01k
      p.val = 32;
408
55.8k
    else if (p.val == 11)
409
1.38k
      p.val = 20;
410
54.4k
    else if (p.val == 9)
411
2.00k
      p.val = 16;
412
62.9k
  }
413
414
112k
      a->constant = p.val;
415
112k
      break;
416
417
1.55k
    case arg_idxr:
418
1.55k
      a->scale = 0;
419
1.55k
      total_size = a->size + 10;  /* sizeof(rbase + ridx + scl2) = 10.  */
420
1.55k
      p = makelongparameter (allWords, inst_bit_size - total_size,
421
1.55k
           inst_bit_size - (total_size - 4));
422
1.55k
      a->r = p.val;
423
1.55k
      p = makelongparameter (allWords, inst_bit_size - (total_size - 4),
424
1.55k
           inst_bit_size - (total_size - 8));
425
1.55k
      a->i_r = p.val;
426
1.55k
      p = makelongparameter (allWords, inst_bit_size - (total_size - 8),
427
1.55k
           inst_bit_size - (total_size - 10));
428
1.55k
      a->scale = p.val;
429
1.55k
      p = makelongparameter (allWords, inst_bit_size - (total_size - 10),
430
1.55k
           inst_bit_size);
431
1.55k
      a->constant = p.val;
432
1.55k
      break;
433
434
9.58k
    case arg_rbase:
435
9.58k
      p = makelongparameter (allWords, inst_bit_size - (start_bits + 4),
436
9.58k
           inst_bit_size - start_bits);
437
9.58k
      a->r = p.val;
438
9.58k
      break;
439
440
51.7k
    case arg_cr:
441
51.7k
      if (a->size <= 8)
442
43.4k
  {
443
43.4k
    p = makelongparameter (allWords, inst_bit_size - (start_bits + 4),
444
43.4k
         inst_bit_size - start_bits);
445
43.4k
    a->r = p.val;
446
    /* Case for opc4 r dispu rbase.  */
447
43.4k
    p = makelongparameter (allWords, inst_bit_size - (start_bits + 8),
448
43.4k
         inst_bit_size - (start_bits + 4));
449
43.4k
  }
450
8.31k
      else
451
8.31k
  {
452
    /* The 'rbase' start_bits is always relative to a 32-bit data type.  */
453
8.31k
    p = makelongparameter (allWords, 32 - (start_bits + 4),
454
8.31k
         32 - start_bits);
455
8.31k
    a->r = p.val;
456
8.31k
    p = makelongparameter (allWords, 32 - start_bits,
457
8.31k
         inst_bit_size);
458
8.31k
  }
459
51.7k
      if ((p.nbits == 4) && cst4flag)
460
43.4k
  {
461
43.4k
    if (instruction->flags & DISPUW4)
462
14.2k
      p.val *= 2;
463
29.2k
    else if (instruction->flags & DISPUD4)
464
14.2k
      p.val *= 4;
465
43.4k
  }
466
51.7k
      a->constant = p.val;
467
51.7k
      break;
468
469
20.8k
    case arg_c:
470
20.8k
      p = makelongparameter (allWords, inst_bit_size - (start_bits + a->size),
471
20.8k
           inst_bit_size - start_bits);
472
20.8k
      a->constant = p.val;
473
20.8k
      break;
474
0
    default:
475
0
      break;
476
395k
    }
477
395k
}
478
479
/*  Print a single argument.  */
480
481
static void
482
print_arg (argument *a, bfd_vma memaddr, struct disassemble_info *info)
483
395k
{
484
395k
  ULONGLONG longdisp, mask;
485
395k
  int sign_flag = 0;
486
395k
  int relative = 0;
487
395k
  bfd_vma number;
488
395k
  int op_index = 0;
489
395k
  char string[200];
490
395k
  void *stream = info->stream;
491
395k
  fprintf_ftype func = info->fprintf_func;
492
493
395k
  switch (a->type)
494
395k
    {
495
57
    case arg_copr:
496
57
      func (stream, "%s", getcopregname (a->cr, CRX_C_REGTYPE));
497
57
      break;
498
499
27
    case arg_copsr:
500
27
      func (stream, "%s", getcopregname (a->cr, CRX_CS_REGTYPE));
501
27
      break;
502
503
199k
    case arg_r:
504
199k
      if (IS_INSN_MNEMONIC ("mtpr") || IS_INSN_MNEMONIC ("mfpr"))
505
728
  func (stream, "%s", getprocregname (a->r));
506
198k
      else
507
198k
  func (stream, "%s", getregname (a->r));
508
199k
      break;
509
510
112k
    case arg_ic:
511
112k
      if (IS_INSN_MNEMONIC ("excp"))
512
20.8k
  func (stream, "%s", gettrapstring (a->constant));
513
514
91.4k
      else if (IS_INSN_MNEMONIC ("cinv"))
515
110
  func (stream, "%s", getcinvstring (a->constant));
516
517
91.3k
      else if (INST_HAS_REG_LIST)
518
1.38k
  {
519
1.38k
    REG_ARG_TYPE reg_arg_type = IS_INSN_TYPE (COP_REG_INS) ?
520
1.00k
      COP_ARG : IS_INSN_TYPE (COPS_REG_INS) ?
521
913
      COPS_ARG : (instruction->flags & USER_REG) ?
522
795
      USER_REG_ARG : REG_ARG;
523
524
1.38k
    if ((reg_arg_type == COP_ARG) || (reg_arg_type == COPS_ARG))
525
474
      {
526
        /*  Check for proper argument number.  */
527
474
        if (processing_argument_number == 2)
528
237
    {
529
237
      getregliststring (a->constant, string, reg_arg_type);
530
237
      func (stream, "%s", string);
531
237
    }
532
237
        else
533
237
    func (stream, "$0x%lx", a->constant & 0xffffffff);
534
474
      }
535
913
    else
536
913
      {
537
913
        getregliststring (a->constant, string, reg_arg_type);
538
913
        func (stream, "%s", string);
539
913
      }
540
1.38k
  }
541
90.0k
      else
542
90.0k
  func (stream, "$0x%lx", a->constant & 0xffffffff);
543
112k
      break;
544
545
1.55k
    case arg_idxr:
546
1.55k
      func (stream, "0x%lx(%s,%s,%d)", a->constant & 0xffffffff,
547
1.55k
      getregname (a->r), getregname (a->i_r), powerof2 (a->scale));
548
1.55k
      break;
549
550
9.58k
    case arg_rbase:
551
9.58k
      func (stream, "(%s)", getregname (a->r));
552
9.58k
      break;
553
554
51.7k
    case arg_cr:
555
51.7k
      func (stream, "0x%lx(%s)", a->constant & 0xffffffff, getregname (a->r));
556
557
51.7k
      if (IS_INSN_TYPE (LD_STOR_INS_INC))
558
708
  func (stream, "+");
559
51.7k
      break;
560
561
20.8k
    case arg_c:
562
      /* Removed the *2 part as because implicit zeros are no more required.
563
   Have to fix this as this needs a bit of extension in terms of branchins.
564
   Have to add support for cmp and branch instructions.  */
565
20.8k
      if (IS_INSN_TYPE (BRANCH_INS) || IS_INSN_MNEMONIC ("bal")
566
8.82k
    || IS_INSN_TYPE (CMPBR_INS) || IS_INSN_TYPE (DCR_BRANCH_INS)
567
7.53k
    || IS_INSN_TYPE (COP_BRANCH_INS))
568
13.4k
  {
569
13.4k
    relative = 1;
570
13.4k
    longdisp = a->constant;
571
13.4k
    longdisp <<= 1;
572
573
13.4k
    switch (a->size)
574
13.4k
      {
575
12.0k
      case 8:
576
12.9k
      case 16:
577
13.2k
      case 24:
578
13.4k
      case 32:
579
13.4k
        mask = ((LONGLONG) 1 << a->size) - 1;
580
13.4k
        if (longdisp & ((ULONGLONG) 1 << a->size))
581
2.70k
    {
582
2.70k
      sign_flag = 1;
583
2.70k
      longdisp = ~(longdisp) + 1;
584
2.70k
    }
585
13.4k
        a->constant = (unsigned long int) (longdisp & mask);
586
13.4k
        break;
587
0
      default:
588
0
        func (stream,
589
0
        "Wrong offset used in branch/bal instruction");
590
0
        break;
591
13.4k
      }
592
593
13.4k
  }
594
      /* For branch Neq instruction it is 2*offset + 2.  */
595
7.42k
      else if (IS_INSN_TYPE (BRANCH_NEQ_INS))
596
3.96k
  a->constant = 2 * a->constant + 2;
597
3.45k
      else if (IS_INSN_TYPE (LD_STOR_INS_INC)
598
3.45k
         || IS_INSN_TYPE (LD_STOR_INS)
599
2.62k
         || IS_INSN_TYPE (STOR_IMM_INS)
600
2.41k
         || IS_INSN_TYPE (CSTBIT_INS))
601
3.45k
  {
602
3.45k
    op_index = instruction->flags & REVERSE_MATCH ? 0 : 1;
603
3.45k
    if (instruction->operands[op_index].op_type == abs16)
604
2.31k
      a->constant |= 0xFFFF0000;
605
3.45k
  }
606
20.8k
      func (stream, "%s", "0x");
607
20.8k
      number = (relative ? memaddr : 0)
608
20.8k
  + (sign_flag ? -a->constant : a->constant);
609
20.8k
      (*info->print_address_func) (number, info);
610
20.8k
      break;
611
0
    default:
612
0
      break;
613
395k
    }
614
395k
}
615
616
/* Print all the arguments of CURRINSN instruction.  */
617
618
static void
619
print_arguments (ins *currentInsn, bfd_vma memaddr, struct disassemble_info *info)
620
213k
{
621
213k
  int i;
622
623
608k
  for (i = 0; i < currentInsn->nargs; i++)
624
395k
    {
625
395k
      processing_argument_number = i;
626
627
395k
      print_arg (&currentInsn->arg[i], memaddr, info);
628
629
395k
      if (i != currentInsn->nargs - 1)
630
182k
  info->fprintf_func (info->stream, ", ");
631
395k
    }
632
213k
}
633
634
/* Build the instruction's arguments.  */
635
636
static void
637
make_instruction (void)
638
213k
{
639
213k
  int i;
640
213k
  unsigned int shift;
641
642
608k
  for (i = 0; i < currInsn.nargs; i++)
643
395k
    {
644
395k
      argument a;
645
646
395k
      memset (&a, 0, sizeof (a));
647
395k
      a.type = getargtype (instruction->operands[i].op_type);
648
395k
      if (instruction->operands[i].op_type == cst4
649
332k
    || instruction->operands[i].op_type == rbase_dispu4)
650
106k
  cst4flag = 1;
651
395k
      a.size = getbits (instruction->operands[i].op_type);
652
395k
      shift = instruction->operands[i].shift;
653
654
395k
      make_argument (&a, shift);
655
395k
      currInsn.arg[i] = a;
656
395k
    }
657
658
  /* Calculate instruction size (in bytes).  */
659
213k
  currInsn.size = instruction->size + (size_changed ? 1 : 0);
660
  /* Now in bits.  */
661
213k
  currInsn.size *= 2;
662
213k
}
663
664
/* Retrieve a single word from a given memory address.  */
665
666
static wordU
667
get_word_at_PC (bfd_vma memaddr, struct disassemble_info *info)
668
757k
{
669
757k
  bfd_byte buffer[4];
670
757k
  int status;
671
757k
  wordU insn = 0;
672
673
757k
  status = info->read_memory_func (memaddr, buffer, 2, info);
674
675
757k
  if (status == 0)
676
756k
    insn = (wordU) bfd_getl16 (buffer);
677
678
757k
  return insn;
679
757k
}
680
681
/* Retrieve multiple words (3) from a given memory address.  */
682
683
static void
684
get_words_at_PC (bfd_vma memaddr, struct disassemble_info *info)
685
252k
{
686
252k
  int i;
687
252k
  bfd_vma mem;
688
689
1.01M
  for (i = 0, mem = memaddr; i < 3; i++, mem += 2)
690
757k
    words[i] = get_word_at_PC (mem, info);
691
692
252k
  allWords =
693
252k
    ((ULONGLONG) words[0] << 32) + ((unsigned long) words[1] << 16) + words[2];
694
252k
}
695
696
/* Prints the instruction by calling print_arguments after proper matching.  */
697
698
int
699
print_insn_crx (bfd_vma memaddr, struct disassemble_info *info)
700
252k
{
701
252k
  int is_decoded;     /* Nonzero means instruction has a match.  */
702
703
  /* Initialize global variables.  */
704
252k
  cst4flag = 0;
705
252k
  size_changed = 0;
706
707
  /* Retrieve the encoding from current memory location.  */
708
252k
  get_words_at_PC (memaddr, info);
709
  /* Find a matching opcode in table.  */
710
252k
  is_decoded = match_opcode ();
711
  /* If found, print the instruction's mnemonic and arguments.  */
712
252k
  if (is_decoded > 0 && (words[0] != 0 || words[1] != 0))
713
213k
    {
714
213k
      info->fprintf_func (info->stream, "%s", instruction->mnemonic);
715
213k
      if ((currInsn.nargs = get_number_of_operands ()) != 0)
716
213k
  info->fprintf_func (info->stream, "\t");
717
213k
      make_instruction ();
718
213k
      print_arguments (&currInsn, memaddr, info);
719
213k
      return currInsn.size;
720
213k
    }
721
722
  /* No match found.  */
723
39.0k
  info->fprintf_func (info->stream,"%s ",ILLEGAL);
724
39.0k
  return 2;
725
252k
}