Coverage Report

Created: 2025-06-24 06:45

/src/binutils-gdb/opcodes/csky-dis.c
Line
Count
Source (jump to first uncovered line)
1
/* C-SKY disassembler.
2
   Copyright (C) 1988-2025 Free Software Foundation, Inc.
3
   Contributed by C-SKY Microsystems and Mentor Graphics.
4
5
   This file is part of the GNU opcodes library.
6
7
   This library is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3, or (at your option)
10
   any later version.
11
12
   It is distributed in the hope that it will be useful, but WITHOUT
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
   License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include "config.h"
24
#include <stdio.h>
25
#include <stdint.h>
26
#include <elf/csky.h>
27
#include "disassemble.h"
28
#include "elf-bfd.h"
29
#include "opcode/csky.h"
30
#include "libiberty.h"
31
#include "csky-opc.h"
32
#include "floatformat.h"
33
34
898k
#define CSKY_INST_TYPE unsigned long
35
221M
#define HAS_SUB_OPERAND (unsigned int)0xffffffff
36
979
#define CSKY_DEFAULT_ISA 0xffffffff
37
38
enum sym_type
39
{
40
  CUR_TEXT,
41
  CUR_DATA
42
};
43
44
struct csky_dis_info
45
{
46
  /* Mem to disassemble.  */
47
  bfd_vma mem;
48
  /* Disassemble info.  */
49
  disassemble_info *info;
50
  /* Opcode information.  */
51
  struct csky_opcode_info const *opinfo;
52
  uint64_t isa;
53
  /* The value of operand to show.  */
54
  int value;
55
  /* Whether to look up/print a symbol name.  */
56
  int need_output_symbol;
57
} dis_info;
58
59
60
enum sym_type last_type;
61
int last_map_sym = 1;
62
bfd_vma last_map_addr = 0;
63
int using_abi = 0;
64
65
/* Only for objdump tool.  */
66
2.25M
#define INIT_MACH_FLAG  0xffffffff
67
2.69M
#define BINARY_MACH_FLAG 0x0
68
69
static unsigned int mach_flag = INIT_MACH_FLAG;
70
71
static void
72
print_insn_data (bfd_vma pc ATTRIBUTE_UNUSED,
73
     struct disassemble_info *info,
74
     long given)
75
0
{
76
0
  switch (info->bytes_per_chunk)
77
0
    {
78
0
    case 1:
79
0
      info->fprintf_func (info->stream, ".byte\t0x%02lx", given);
80
0
      break;
81
0
    case 2:
82
0
      info->fprintf_func (info->stream, ".short\t0x%04lx", given);
83
0
      break;
84
0
    case 4:
85
0
      info->fprintf_func (info->stream, ".long\t0x%08lx", given);
86
0
      break;
87
0
    default:
88
0
      abort ();
89
0
    }
90
0
}
91
92
static int
93
get_sym_code_type (struct disassemble_info *info,
94
       int n,
95
       enum sym_type *sym_type)
96
0
{
97
0
  const char *name;
98
0
  name = bfd_asymbol_name (info->symtab[n]);
99
0
  if (name[0] == '$' && (name[1] == 't' || name[1] == 'd')
100
0
      && (name[2] == 0 || name[2] == '.'))
101
0
    {
102
0
      *sym_type = ((name[1] == 't') ? CUR_TEXT : CUR_DATA);
103
0
      return true;
104
0
    }
105
0
  return false;
106
0
}
107
108
static int
109
csky_get_operand_mask (struct operand const *oprnd)
110
219M
{
111
219M
  int mask = 0;
112
219M
  if (oprnd->mask == HAS_SUB_OPERAND)
113
10.6M
    {
114
10.6M
      struct soperand *sop = (struct soperand *)oprnd;
115
10.6M
      mask |= csky_get_operand_mask (&sop->subs[0]);
116
10.6M
      mask |= csky_get_operand_mask (&sop->subs[1]);
117
10.6M
      return mask;
118
10.6M
    }
119
208M
  return oprnd->mask;
120
219M
}
121
122
static int
123
csky_get_mask (struct csky_opcode_info const *pinfo)
124
537M
{
125
537M
  int i = 0;
126
537M
  int mask = 0;
127
  /* List type.  */
128
537M
  if (pinfo->operand_num == -1)
129
1.53M
    mask |= csky_get_operand_mask (&pinfo->oprnd.oprnds[i]);
130
536M
  else
131
732M
    for (; i < pinfo->operand_num; i++)
132
196M
      mask |= csky_get_operand_mask (&pinfo->oprnd.oprnds[i]);
133
134
537M
  mask = ~mask;
135
537M
  return mask;
136
537M
}
137
138
static unsigned int
139
csky_chars_to_number (unsigned char * buf, int n)
140
73.7k
{
141
73.7k
  int i;
142
73.7k
  unsigned int val = 0;
143
144
73.7k
  if (dis_info.info->endian == BFD_ENDIAN_BIG)
145
186k
    for (i = 0; i < n; i++)
146
148k
      val = val << 8 | buf[i];
147
36.4k
  else
148
182k
    for (i = n - 1; i >= 0; i--)
149
145k
      val = val << 8 | buf[i];
150
73.7k
  return val;
151
73.7k
}
152
153
static struct csky_opcode const *g_opcodeP;
154
155
static struct csky_opcode const *
156
csky_find_inst_info (struct csky_opcode_info const **pinfo,
157
         CSKY_INST_TYPE inst, int length)
158
898k
{
159
898k
  int i;
160
898k
  unsigned int mask;
161
898k
  struct csky_opcode const *p;
162
163
898k
  p = g_opcodeP;
164
311M
  while (p->mnemonic)
165
311M
    {
166
311M
  if (!(p->isa_flag16 & dis_info.isa)
167
311M
        && !(p->isa_flag32 & dis_info.isa))
168
42.3M
  {
169
42.3M
    p++;
170
42.3M
    continue;
171
42.3M
  }
172
173
      /* Get the opcode mask.  */
174
805M
      for (i = 0; i < OP_TABLE_NUM; i++)
175
537M
  if (length == 2)
176
481M
    {
177
481M
      mask =  csky_get_mask (&p->op16[i]);
178
481M
      if (mask != 0 && (inst & mask) == p->op16[i].opcode)
179
754k
        {
180
754k
    *pinfo = &p->op16[i];
181
754k
    g_opcodeP = p;
182
754k
    return p;
183
754k
        }
184
481M
    }
185
56.1M
  else if (length == 4)
186
56.1M
    {
187
56.1M
      mask =  csky_get_mask (&p->op32[i]);
188
56.1M
      if (mask != 0
189
56.1M
    && ((unsigned long)(inst & mask)
190
56.1M
        == (unsigned long)p->op32[i].opcode))
191
22.4k
        {
192
22.4k
    *pinfo = &p->op32[i];
193
22.4k
    g_opcodeP = p;
194
22.4k
    return p;
195
22.4k
        }
196
56.1M
    }
197
268M
      p++;
198
268M
    }
199
200
121k
  return NULL;
201
898k
}
202
203
static bool
204
is_extern_symbol (struct disassemble_info *info, int addr)
205
69.0k
{
206
69.0k
  unsigned int rel_count = 0;
207
208
69.0k
  if (info->section == NULL)
209
26.4k
    return 0;
210
42.5k
  if ((info->section->flags & SEC_RELOC) != 0)  /* Fit .o file.  */
211
0
    {
212
0
      struct reloc_cache_entry *pt = info->section->relocation;
213
0
      for (; rel_count < info->section->reloc_count; rel_count++, pt++)
214
0
  if ((long unsigned int)addr == pt->address)
215
0
    return true;
216
0
      return false;
217
0
    }
218
42.5k
  return false;
219
42.5k
}
220
221
222
/* Suppress printing of mapping symbols emitted by the assembler to mark
223
   the beginning of code and data sequences.  */
224
225
bool
226
csky_symbol_is_valid (asymbol *sym,
227
          struct disassemble_info *info ATTRIBUTE_UNUSED)
228
0
{
229
0
  const char *name;
230
231
0
  if (sym == NULL)
232
0
    return false;
233
0
  name = bfd_asymbol_name (sym);
234
0
  return name && *name != '$';
235
0
}
236
237
disassembler_ftype
238
csky_get_disassembler (bfd *abfd)
239
977
{
240
977
  obj_attribute *attr;
241
977
  const char *sec_name = NULL;
242
977
  if (!abfd || bfd_get_flavour (abfd) != bfd_target_elf_flavour)
243
885
    dis_info.isa = CSKY_DEFAULT_ISA;
244
92
  else
245
92
    {
246
92
      mach_flag = elf_elfheader (abfd)->e_flags;
247
248
92
      sec_name = get_elf_backend_data (abfd)->obj_attrs_section;
249
      /* Skip any input that hasn't attribute section.
250
         This enables to link object files without attribute section with
251
         any others.  */
252
92
      if (bfd_get_section_by_name (abfd, sec_name) != NULL)
253
0
        {
254
0
          attr = elf_known_obj_attributes_proc (abfd);
255
0
          dis_info.isa = attr[Tag_CSKY_ISA_EXT_FLAGS].i;
256
0
          dis_info.isa <<= 32;
257
0
          dis_info.isa |= attr[Tag_CSKY_ISA_FLAGS].i;
258
0
        }
259
92
      else
260
92
        dis_info.isa = CSKY_DEFAULT_ISA;
261
92
    }
262
263
977
   return print_insn_csky;
264
977
}
265
266
/* Parse the string of disassembler options.  */
267
static void
268
parse_csky_dis_options (const char *opts_in)
269
638
{
270
638
  char *opts = xstrdup (opts_in);
271
638
  char *opt = opts;
272
638
  char *opt_end = opts;
273
274
2.90k
  for (; opt_end != NULL; opt = opt_end + 1)
275
2.27k
    {
276
2.27k
      if ((opt_end = strchr (opt, ',')) != NULL)
277
1.63k
  *opt_end = 0;
278
2.27k
      if (strcmp (opt, "abi-names") == 0)
279
74
  using_abi = 1;
280
2.19k
      else
281
2.19k
  fprintf (stderr,
282
2.19k
     "unrecognized disassembler option: %s", opt);
283
2.27k
    }
284
638
}
285
286
/* Get general register name.  */
287
static const char *
288
get_gr_name (int regno)
289
929k
{
290
929k
  return csky_get_general_reg_name (mach_flag, regno, using_abi);
291
929k
}
292
293
/* Get control register name.  */
294
static const char *
295
get_cr_name (unsigned int regno, int bank)
296
3.10k
{
297
3.10k
  return csky_get_control_reg_name (mach_flag, bank, regno, using_abi);
298
3.10k
}
299
300
static int
301
csky_output_operand (char *str, struct operand const *oprnd,
302
         CSKY_INST_TYPE inst, int reloc ATTRIBUTE_UNUSED)
303
1.46M
{
304
1.46M
  int ret = 0;;
305
1.46M
  int bit = 0;
306
1.46M
  int result = 0;
307
1.46M
  bfd_vma value;
308
1.46M
  int mask = oprnd->mask;
309
1.46M
  int max = 0;
310
1.46M
  char buf[128];
311
312
  /* Get operand value with mask.  */
313
1.46M
  value = inst & mask;
314
13.7M
  for (; mask; mask >>= 1, value >>=1)
315
12.2M
    if (mask & 0x1)
316
6.78M
      {
317
6.78M
  result |= ((value & 0x1) << bit);
318
6.78M
  max |= (1 << bit);
319
6.78M
  bit++;
320
6.78M
      }
321
1.46M
  value = result;
322
323
  /* Here is general instructions that have no reloc.  */
324
1.46M
  switch (oprnd->type)
325
1.46M
    {
326
3.18k
    case OPRND_TYPE_CTRLREG:
327
3.18k
  if (IS_CSKY_V1(mach_flag) && ((value & 0x1f) == 0x1f))
328
81
    return -1;
329
3.10k
  strcat (str, get_cr_name((value & 0x1f), (value >> 5)));
330
3.10k
  break;
331
24.3k
    case OPRND_TYPE_DUMMY_REG:
332
24.3k
      mask = dis_info.opinfo->oprnd.oprnds[0].mask;
333
24.3k
      value = inst & mask;
334
121k
      for (; mask; mask >>= 1, value >>=1)
335
97.3k
  if (mask & 0x1)
336
97.3k
    {
337
97.3k
      result |= ((value & 0x1) << bit);
338
97.3k
      bit++;
339
97.3k
    }
340
24.3k
      value = result;
341
24.3k
      strcat (str, get_gr_name (value));
342
24.3k
      break;
343
482k
    case OPRND_TYPE_GREG0_7:
344
807k
    case OPRND_TYPE_GREG0_15:
345
807k
    case OPRND_TYPE_GREG16_31:
346
814k
    case OPRND_TYPE_REGnsplr:
347
830k
    case OPRND_TYPE_AREG:
348
830k
      strcat (str, get_gr_name (value));
349
830k
      break;
350
5.09k
    case OPRND_TYPE_CPREG:
351
5.09k
      sprintf (buf, "cpr%d", (int)value);
352
5.09k
      strcat (str, buf);
353
5.09k
      break;
354
306
    case OPRND_TYPE_FREG:
355
306
      sprintf (buf, "fr%d", (int)value);
356
306
      strcat (str, buf);
357
306
      break;
358
1.03k
    case OPRND_TYPE_VREG:
359
1.03k
      dis_info.value = value;
360
1.03k
      sprintf (buf, "vr%d", (int)value);
361
1.03k
      strcat (str, buf);
362
1.03k
      break;
363
1.17k
    case OPRND_TYPE_CPCREG:
364
1.17k
      sprintf (buf, "cpcr%d", (int)value);
365
1.17k
      strcat (str, buf);
366
1.17k
      break;
367
1.67k
    case OPRND_TYPE_CPIDX:
368
1.67k
      sprintf (buf, "cp%d", (int)value);
369
1.67k
      strcat (str, buf);
370
1.67k
      break;
371
3.12k
    case OPRND_TYPE_IMM2b_JMPIX:
372
3.12k
      value = (value + 2) << 3;
373
3.12k
      sprintf (buf, "%d", (int)value);
374
3.12k
      strcat (str, buf);
375
3.12k
      break;
376
133k
    case OPRND_TYPE_IMM_LDST:
377
133k
    case OPRND_TYPE_IMM_FLDST:
378
133k
      value <<= oprnd->shift;
379
133k
      sprintf (buf, "0x%x", (unsigned int)value);
380
133k
      strcat (str, buf);
381
133k
      break;
382
6.85k
    case OPRND_TYPE_IMM7b_LS2:
383
21.9k
    case OPRND_TYPE_IMM8b_LS2:
384
21.9k
      sprintf (buf, "%d", (int)(value << 2));
385
21.9k
      strcat (str, buf);
386
21.9k
      ret = 0;
387
21.9k
      break;
388
787
    case OPRND_TYPE_IMM5b_BMASKI:
389
787
      if ((value != 0) && (value > 31 || value < 8))
390
138
  {
391
138
    ret = -1;
392
138
    break;
393
138
  }
394
649
      sprintf (buf, "%d", (int)value);
395
649
      strcat (str, buf);
396
649
      ret = 0;
397
649
      break;
398
2.42k
    case OPRND_TYPE_IMM5b_1_31:
399
2.42k
      if (value > 31 || value < 1)
400
73
  {
401
73
    ret = -1;
402
73
    break;
403
73
  }
404
2.35k
      sprintf (buf, "%d", (int)value);
405
2.35k
      strcat (str, buf);
406
2.35k
      ret = 0;
407
2.35k
      break;
408
1.07k
    case OPRND_TYPE_IMM5b_7_31:
409
1.07k
      if (value > 31 || value < 7)
410
393
  {
411
393
    ret = -1;
412
393
    break;
413
393
  }
414
685
      sprintf (buf, "%d", (int)value);
415
685
      strcat (str, buf);
416
685
      ret = 0;
417
685
      break;
418
7
    case OPRND_TYPE_IMM5b_VSH:
419
7
      {
420
7
  char num[128];
421
7
  value = ((value & 0x1) << 4) | (value >> 1);
422
7
  sprintf (num, "%d", (int)value);
423
7
  strcat (str, num);
424
7
  ret = 0;
425
7
  break;
426
1.07k
      }
427
47
    case OPRND_TYPE_MSB2SIZE:
428
94
    case OPRND_TYPE_LSB2SIZE:
429
94
      {
430
94
  static int size;
431
94
  if (oprnd->type == OPRND_TYPE_MSB2SIZE)
432
47
    size = value;
433
47
  else
434
47
    {
435
47
      str[strlen (str) - 2] = '\0';
436
47
      sprintf (buf, "%d, %d", (int)(size + value), (int)value);
437
47
      strcat (str, buf);
438
47
    }
439
94
  break;
440
47
      }
441
0
    case OPRND_TYPE_IMM1b:
442
712
    case OPRND_TYPE_IMM2b:
443
796
    case OPRND_TYPE_IMM4b:
444
64.4k
    case OPRND_TYPE_IMM5b:
445
64.4k
    case OPRND_TYPE_IMM5b_LS:
446
69.9k
    case OPRND_TYPE_IMM7b:
447
129k
    case OPRND_TYPE_IMM8b:
448
132k
    case OPRND_TYPE_IMM12b:
449
140k
    case OPRND_TYPE_IMM15b:
450
141k
    case OPRND_TYPE_IMM16b:
451
141k
    case OPRND_TYPE_IMM16b_MOVIH:
452
142k
    case OPRND_TYPE_IMM16b_ORI:
453
142k
      sprintf (buf, "%d", (int)value);
454
142k
      strcat (str, buf);
455
142k
      ret = 0;
456
142k
      break;
457
1.31k
    case OPRND_TYPE_OFF8b:
458
1.31k
    case OPRND_TYPE_OFF16b:
459
1.31k
      {
460
1.31k
  unsigned char ibytes[4];
461
1.31k
  int shift = oprnd->shift;
462
1.31k
  int status;
463
1.31k
  unsigned int mem_val;
464
465
1.31k
  dis_info.info->stop_vma = 0;
466
467
1.31k
  value = ((dis_info.mem + (value << shift)
468
1.31k
      + ((IS_CSKY_V1 (mach_flag)) ? 2 : 0))
469
1.31k
     & 0xfffffffc);
470
1.31k
  status = dis_info.info->read_memory_func (value, ibytes, 4,
471
1.31k
              dis_info.info);
472
1.31k
  if (status != 0)
473
95
    {
474
95
      dis_info.info->memory_error_func (status, dis_info.mem,
475
95
                dis_info.info);
476
95
      return -1;
477
95
    }
478
1.21k
  mem_val = csky_chars_to_number (ibytes, 4);
479
  /* Remove [] around literal value to match ABI syntax.  */
480
1.21k
  sprintf (buf, "0x%X", mem_val);
481
1.21k
  strcat (str, buf);
482
  /* For jmpi/jsri, we'll try to get a symbol for the target.  */
483
1.21k
  if (dis_info.info->print_address_func && mem_val != 0)
484
1.08k
    {
485
1.08k
      dis_info.value = mem_val;
486
1.08k
      dis_info.need_output_symbol = 1;
487
1.08k
    }
488
133
  else
489
133
    {
490
133
      sprintf (buf, "\t// from address pool at 0x%x",
491
133
         (unsigned int)value);
492
133
      strcat (str, buf);
493
133
    }
494
1.21k
  break;
495
1.31k
      }
496
86
    case OPRND_TYPE_BLOOP_OFF4b:
497
172
    case OPRND_TYPE_BLOOP_OFF12b:
498
22.3k
    case OPRND_TYPE_OFF11b:
499
23.2k
    case OPRND_TYPE_OFF16b_LSL1:
500
23.6k
    case OPRND_TYPE_IMM_OFF18b:
501
25.5k
    case OPRND_TYPE_OFF26b:
502
25.5k
      {
503
25.5k
  int shift = oprnd->shift;
504
25.5k
  if (value & ((max >> 1) + 1))
505
15.8k
    value |= ~max;
506
25.5k
  if (is_extern_symbol (dis_info.info, dis_info.mem))
507
0
    value = 0;
508
25.5k
  else if (IS_CSKY_V1 (mach_flag))
509
22.1k
    value = dis_info.mem + 2 + (value << shift);
510
3.41k
  else
511
3.41k
    value = dis_info.mem + (value << shift);
512
25.5k
  dis_info.need_output_symbol = 1;
513
25.5k
  dis_info.value= value;
514
25.5k
  sprintf (buf, "0x%x", (unsigned int)value);
515
25.5k
  strcat (str, buf);
516
25.5k
  break;
517
23.6k
      }
518
20.9k
    case OPRND_TYPE_CONSTANT:
519
20.9k
    case OPRND_TYPE_FCONSTANT:
520
20.9k
      {
521
20.9k
  int shift = oprnd->shift;
522
20.9k
  bfd_byte ibytes[8];
523
20.9k
  int status;
524
20.9k
  bfd_vma addr;
525
20.9k
  int nbytes;
526
527
20.9k
  dis_info.info->stop_vma = 0;
528
20.9k
  value <<= shift;
529
530
20.9k
  if (IS_CSKY_V1 (mach_flag))
531
7.09k
    addr = (dis_info.mem + 2 + value) & 0xfffffffc;
532
13.8k
  else
533
13.8k
    addr = (dis_info.mem + value) & 0xfffffffc;
534
535
20.9k
  if (oprnd->type == OPRND_TYPE_FCONSTANT
536
20.9k
      && dis_info.opinfo->opcode != CSKYV2_INST_FLRW)
537
0
    nbytes = 8;
538
20.9k
  else
539
20.9k
    nbytes = 4;
540
541
20.9k
  status = dis_info.info->read_memory_func (addr, ibytes,
542
20.9k
              nbytes, dis_info.info);
543
20.9k
  if (status != 0)
544
    /* Address out of bounds.  -> lrw rx, [pc, 0ffset]. */
545
2.95k
    sprintf (buf, "[pc, %d]\t// from address pool at %x", (int)value,
546
2.95k
       (unsigned int)addr);
547
17.9k
  else if (oprnd->type == OPRND_TYPE_FCONSTANT)
548
0
    {
549
0
      double f;
550
551
0
      if (dis_info.opinfo->opcode == CSKYV2_INST_FLRW)
552
        /* flrws.  */
553
0
        floatformat_to_double ((dis_info.info->endian == BFD_ENDIAN_BIG
554
0
              ? &floatformat_ieee_single_big
555
0
              : &floatformat_ieee_single_little),
556
0
             ibytes, &f);
557
0
      else
558
0
        floatformat_to_double ((dis_info.info->endian == BFD_ENDIAN_BIG
559
0
              ? &floatformat_ieee_double_big
560
0
              : &floatformat_ieee_double_little),
561
0
             ibytes, &f);
562
0
      sprintf (buf, "%.7g", f);
563
0
    }
564
17.9k
  else
565
17.9k
    {
566
17.9k
      dis_info.value = addr;
567
17.9k
      dis_info.need_output_symbol = 1;
568
17.9k
      value = csky_chars_to_number (ibytes, 4);
569
17.9k
      sprintf (buf, "0x%x", (unsigned int) value);
570
17.9k
    }
571
572
20.9k
  strcat (str, buf);
573
20.9k
  break;
574
20.9k
      }
575
68.8k
    case OPRND_TYPE_ELRW_CONSTANT:
576
68.8k
      {
577
68.8k
  int shift = oprnd->shift;
578
68.8k
  char ibytes[4];
579
68.8k
  int status;
580
68.8k
  bfd_vma addr;
581
68.8k
  dis_info.info->stop_vma = 0;
582
583
68.8k
  value = 0x80 + ((~value) & 0x7f);
584
585
68.8k
  value = value << shift;
586
68.8k
  addr = (dis_info.mem + value) & 0xfffffffc;
587
588
68.8k
  status = dis_info.info->read_memory_func (addr, (bfd_byte *)ibytes,
589
68.8k
              4, dis_info.info);
590
68.8k
  if (status != 0)
591
    /* Address out of bounds.  -> lrw rx, [pc, 0ffset]. */
592
14.2k
    sprintf (buf, "[pc, %d]\t// from address pool at %x", (int) value,
593
14.2k
       (unsigned int)addr);
594
54.5k
  else
595
54.5k
    {
596
54.5k
      dis_info.value = addr;
597
54.5k
      value = csky_chars_to_number ((unsigned char *)ibytes, 4);
598
54.5k
      dis_info.need_output_symbol = 1;
599
54.5k
      sprintf (buf, "0x%x", (unsigned int)value);
600
54.5k
    }
601
602
68.8k
  strcat (str, buf);
603
68.8k
  break;
604
20.9k
      }
605
0
    case OPRND_TYPE_SFLOAT:
606
0
    case OPRND_TYPE_DFLOAT:
607
0
      {
608
  /* This is for fmovis/fmovid, which have an internal 13-bit
609
     encoding that they convert to single/double precision
610
     (respectively).  We'll convert the 13-bit encoding to an IEEE
611
     double and then to host double format to print it.
612
     Sign bit: bit 20.
613
     4-bit exponent: bits 19:16, biased by 11.
614
     8-bit mantissa: split between 24:21 and 7:4.  */
615
0
  uint64_t imm4;
616
0
  uint64_t imm8;
617
0
  uint64_t dbnum;
618
0
  unsigned char valbytes[8];
619
0
  double fvalue;
620
621
0
  imm4 = ((inst >> 16) & 0xf);
622
0
  imm4 = (uint64_t)(1023 - (imm4 - 11)) << 52;
623
624
0
  imm8 = (uint64_t)((inst >> 4) & 0xf) << 44;
625
0
  imm8 |= (uint64_t)((inst >> 21) & 0xf) << 48;
626
627
0
  dbnum = (uint64_t)((inst >> 20) & 1) << 63;
628
0
  dbnum |= imm4 | imm8;
629
630
  /* Do this a byte at a time so we don't have to
631
     worry about the host's endianness.  */
632
0
  valbytes[0] = dbnum & 0xff;
633
0
  valbytes[1] = (dbnum >> 8) & 0xff;
634
0
  valbytes[2] = (dbnum >> 16) & 0xff;
635
0
  valbytes[3] = (dbnum >> 24) & 0xff;
636
0
  valbytes[4] = (dbnum >> 32) & 0xff;
637
0
  valbytes[5] = (dbnum >> 40) & 0xff;
638
0
  valbytes[6] = (dbnum >> 48) & 0xff;
639
0
  valbytes[7] = (dbnum >> 56) & 0xff;
640
641
0
  floatformat_to_double (&floatformat_ieee_double_little, valbytes,
642
0
             &fvalue);
643
644
0
  sprintf (buf, "%.7g", fvalue);
645
0
  strcat (str, buf);
646
0
  break;
647
0
      }
648
0
    case OPRND_TYPE_HFLOAT_FMOVI:
649
0
    case OPRND_TYPE_SFLOAT_FMOVI:
650
0
      {
651
0
  int imm4;
652
0
  int imm8;
653
0
  imm4 = ((inst >> 16) & 0xf);
654
0
  imm4 = (138 - imm4) << 23;
655
656
0
  imm8 = ((inst >> 8) & 0x3);
657
0
  imm8 |= (((inst >> 20) & 0x3f) << 2);
658
0
  imm8 <<= 15;
659
660
0
  value = ((inst >> 5) & 1) << 31;
661
0
  value |= imm4 | imm8;
662
663
0
  imm4 = 138 - (imm4 >> 23);
664
0
  imm8 >>= 15;
665
0
  if ((inst >> 5) & 1)
666
0
    {
667
0
      imm8 = 0 - imm8;
668
0
    }
669
670
0
  float f = 0;
671
0
  memcpy (&f, &value, sizeof (float));
672
0
  sprintf (buf, "%.7g\t// imm9:%4d, imm4:%2d", f, imm8, imm4);
673
0
  strcat (str, buf);
674
675
0
  break;
676
0
      }
677
678
0
    case OPRND_TYPE_DFLOAT_FMOVI:
679
0
      {
680
0
  uint64_t imm4;
681
0
  uint64_t imm8;
682
0
  uint64_t dvalue;
683
0
  imm4 = ((inst >> 16) & 0xf);
684
0
  imm4 = (1034 - imm4) << 52;
685
686
0
  imm8 = ((inst >> 8) & 0x3);
687
0
  imm8 |= (((inst >> 20) & 0x3f) << 2);
688
0
  imm8 <<= 44;
689
690
0
  dvalue = (((uint64_t)inst >> 5) & 1) << 63;
691
0
  dvalue |= imm4 | imm8;
692
693
0
  imm4 = 1034 - (imm4 >> 52);
694
0
  imm8 >>= 44;
695
0
  if (inst >> 5)
696
0
    {
697
0
      imm8 = 0 - imm8;
698
0
    }
699
0
  double d = 0;
700
0
  memcpy (&d, &dvalue, sizeof (double));
701
0
  sprintf (buf, "%.7g\t// imm9:%4ld, imm4:%2ld", d, (long) imm8, (long) imm4);
702
0
  strcat (str, buf);
703
704
0
  break;
705
0
      }
706
1.07k
    case OPRND_TYPE_LABEL_WITH_BRACKET:
707
1.07k
      sprintf (buf, "[0x%x]", (unsigned int)value);
708
1.07k
      strcat (str, buf);
709
1.07k
      strcat (str, "\t// the offset is based on .data");
710
1.07k
      break;
711
5.21k
    case OPRND_TYPE_OIMM3b:
712
5.36k
    case OPRND_TYPE_OIMM4b:
713
22.6k
    case OPRND_TYPE_OIMM5b:
714
22.6k
    case OPRND_TYPE_OIMM5b_IDLY:
715
63.6k
    case OPRND_TYPE_OIMM8b:
716
64.0k
    case OPRND_TYPE_OIMM12b:
717
64.3k
    case OPRND_TYPE_OIMM16b:
718
64.5k
    case OPRND_TYPE_OIMM18b:
719
64.5k
      value += 1;
720
64.5k
      sprintf (buf, "%d", (int)value);
721
64.5k
      strcat (str, buf);
722
64.5k
      break;
723
0
    case OPRND_TYPE_OIMM5b_BMASKI:
724
0
      if (value > 32 || value < 16)
725
0
  {
726
0
    ret = -1;
727
0
    break;
728
0
  }
729
0
      sprintf (buf, "%d", (int)(value + 1));
730
0
      strcat (str, buf);
731
0
      ret = 0;
732
0
      break;
733
29
    case OPRND_TYPE_FREGLIST_DASH:
734
29
      if (IS_CSKY_V2 (mach_flag))
735
29
  {
736
29
    int vrx = 0;
737
29
    int vry = 0;
738
29
    if (dis_info.isa & CSKY_ISA_FLOAT_7E60
739
29
        && (strstr (str, "fstm") != NULL
740
0
      || strstr (str, "fldm") != NULL))
741
0
      {
742
0
        vrx = value & 0x1f;
743
0
        vry = vrx + (value >> 5);
744
0
      }
745
29
    else
746
29
      {
747
29
        vrx = value & 0xf;
748
29
        vry = vrx + (value >> 4);
749
29
      }
750
29
    sprintf (buf, "fr%d-fr%d", vrx, vry);
751
29
    strcat (str, buf);
752
29
  }
753
29
      break;
754
1.47k
    case OPRND_TYPE_REGLIST_DASH:
755
1.47k
      if (IS_CSKY_V1 (mach_flag))
756
1.47k
  {
757
1.47k
    sprintf (buf, "%s-r15", get_gr_name (value));
758
1.47k
    strcat (str, buf);
759
1.47k
  }
760
0
      else
761
0
  {
762
0
    if ((value & 0x1f) + (value >> 5) > 31)
763
0
      {
764
0
        ret = -1;
765
0
        break;
766
0
      }
767
0
    strcat (str, get_gr_name ((value >> 5)));
768
0
    strcat (str, "-");
769
0
    strcat (str, get_gr_name ((value & 0x1f) + (value >> 5)));
770
0
  }
771
1.47k
      break;
772
1.47k
    case OPRND_TYPE_PSR_BITS_LIST:
773
78
      {
774
78
  struct psrbit const *bits;
775
78
  int first_oprnd = true;
776
78
  int i = 0;
777
78
  if (IS_CSKY_V1 (mach_flag))
778
78
    {
779
78
      if (value == 0)
780
31
        {
781
31
    strcat (str, "af");
782
31
    break;
783
31
        }
784
47
      bits = cskyv1_psr_bits;
785
47
    }
786
0
  else
787
0
    bits = cskyv2_psr_bits;
788
154
  while (value != 0 && bits[i].name != NULL)
789
107
      {
790
107
        if (value & bits[i].value)
791
91
    {
792
91
      if (!first_oprnd)
793
44
        strcat (str, ", ");
794
91
      strcat (str, bits[i].name);
795
91
      value &= ~bits[i].value;
796
91
      first_oprnd = false;
797
91
    }
798
107
        i++;
799
107
      }
800
47
  break;
801
78
      }
802
1.47k
    case OPRND_TYPE_REGbsp:
803
1.47k
      if (IS_CSKY_V1 (mach_flag))
804
1.47k
  sprintf(buf, "(%s)", get_gr_name (0));
805
0
      else
806
0
  sprintf(buf, "(%s)", get_gr_name (14));
807
1.47k
      strcat (str, buf);
808
1.47k
      break;
809
42.9k
    case OPRND_TYPE_REGsp:
810
42.9k
      if (IS_CSKY_V1 (mach_flag))
811
0
  strcat (str, get_gr_name (0));
812
42.9k
      else
813
42.9k
  strcat (str, get_gr_name (14));
814
42.9k
      break;
815
2.06k
    case OPRND_TYPE_REGnr4_r7:
816
2.09k
    case OPRND_TYPE_AREG_WITH_BRACKET:
817
2.09k
      strcat (str, "(");
818
2.09k
      strcat (str, get_gr_name (value));
819
2.09k
      strcat (str, ")");
820
2.09k
      break;
821
562
    case OPRND_TYPE_AREG_WITH_LSHIFT:
822
562
      strcat (str, get_gr_name (value >> 5));
823
562
      strcat (str, " << ");
824
562
      if ((value & 0x1f) == 0x1)
825
3
  strcat (str, "0");
826
559
      else if ((value & 0x1f) == 0x2)
827
19
  strcat (str, "1");
828
540
      else if ((value & 0x1f) == 0x4)
829
36
  strcat (str, "2");
830
504
      else if ((value & 0x1f) == 0x8)
831
23
  strcat (str, "3");
832
562
      break;
833
98
    case OPRND_TYPE_AREG_WITH_LSHIFT_FPU:
834
98
      strcat (str, get_gr_name (value >> 2));
835
98
      strcat (str, " << ");
836
98
      if ((value & 0x3) == 0x0)
837
10
  strcat (str, "0");
838
88
      else if ((value & 0x3) == 0x1)
839
84
  strcat (str, "1");
840
4
      else if ((value & 0x3) == 0x2)
841
3
  strcat (str, "2");
842
1
      else if ((value & 0x3) == 0x3)
843
1
  strcat (str, "3");
844
98
      break;
845
27
    case OPRND_TYPE_VREG_WITH_INDEX:
846
27
      {
847
27
  unsigned freg_val = value & 0xf;
848
27
  unsigned index_val = (value >> 4) & 0xf;
849
27
  sprintf (buf, "vr%d[%d]", freg_val, index_val);
850
27
  strcat(str, buf);
851
27
  break;
852
2.06k
      }
853
0
    case OPRND_TYPE_FREG_WITH_INDEX:
854
0
      {
855
0
  unsigned freg_val = value & 0xf;
856
0
  unsigned index_val = (value >> 4) & 0xf;
857
0
  sprintf (buf, "fr%d[%d]", freg_val, index_val);
858
0
  strcat(str, buf);
859
0
  break;
860
2.06k
      }
861
2.06k
    case OPRND_TYPE_REGr4_r7:
862
2.06k
      if (IS_CSKY_V1 (mach_flag))
863
2.06k
  {
864
2.06k
    sprintf (buf, "%s-%s", get_gr_name (4), get_gr_name (7));
865
2.06k
    strcat (str, buf);
866
2.06k
  }
867
2.06k
      break;
868
1.87k
    case OPRND_TYPE_CONST1:
869
1.87k
      strcat (str, "1");
870
1.87k
      break;
871
2.16k
    case OPRND_TYPE_REG_r1a:
872
2.19k
    case OPRND_TYPE_REG_r1b:
873
2.19k
      strcat (str, get_gr_name (1));
874
2.19k
      break;
875
196
    case OPRND_TYPE_REG_r28:
876
196
      strcat (str, get_gr_name (28));
877
196
      break;
878
9.00k
    case OPRND_TYPE_REGLIST_DASH_COMMA:
879
      /* 16-bit reglist.  */
880
9.00k
      if (value & 0xf)
881
7.32k
  {
882
7.32k
    strcat (str, get_gr_name (4));
883
7.32k
    if ((value & 0xf) > 1)
884
5.58k
      {
885
5.58k
        strcat (str, "-");
886
5.58k
        strcat (str, get_gr_name ((value & 0xf) + 3));
887
5.58k
      }
888
7.32k
    if (value & ~0xf)
889
5.33k
      strcat (str, ", ");
890
7.32k
  }
891
9.00k
      if (value & 0x10)
892
6.86k
  {
893
    /* r15.  */
894
6.86k
    strcat (str, get_gr_name (15));
895
6.86k
    if (value & ~0x1f)
896
0
      strcat (str, ", ");
897
6.86k
  }
898
9.00k
      if (dis_info.opinfo->oprnd.oprnds[0].mask != OPRND_MASK_0_4)
899
0
  {
900
    /* 32bits reglist.  */
901
0
    value >>= 5;
902
0
    if (value & 0x3)
903
0
      {
904
0
        strcat (str, get_gr_name (16));
905
0
        if ((value & 0x7) > 1)
906
0
    {
907
0
      strcat (str, "-");
908
0
      strcat (str, get_gr_name ((value & 0x7) + 15));
909
0
    }
910
0
        if (value & ~0x7)
911
0
    strcat (str, ", ");
912
0
        }
913
0
    if (value & 0x8)
914
      /* r15.  */
915
0
      strcat (str, get_gr_name (28));
916
0
  }
917
9.00k
      break;
918
14.7k
    case OPRND_TYPE_UNCOND10b:
919
15.1k
    case OPRND_TYPE_UNCOND16b:
920
43.1k
    case OPRND_TYPE_COND10b:
921
43.4k
    case OPRND_TYPE_COND16b:
922
43.4k
      {
923
43.4k
  int shift = oprnd->shift;
924
925
43.4k
  if (value & ((max >> 1) + 1))
926
16.6k
    value |= ~max;
927
43.4k
  if (is_extern_symbol (dis_info.info, dis_info.mem))
928
0
    value = 0;
929
43.4k
  else
930
43.4k
    value = dis_info.mem + (value << shift);
931
43.4k
  sprintf (buf, "0x%x", (unsigned int)value);
932
43.4k
  strcat (str, buf);
933
43.4k
  dis_info.need_output_symbol = 1;
934
43.4k
  dis_info.value = value;
935
43.4k
      }
936
43.4k
      break;
937
938
118
    default:
939
118
      ret = -1;
940
118
      break;
941
1.46M
    }
942
1.46M
  return ret;
943
1.46M
}
944
945
static int
946
csky_print_operand (char *str, struct operand const *oprnd,
947
        CSKY_INST_TYPE inst, int reloc)
948
1.60M
{
949
1.60M
  int ret = -1;
950
1.60M
  char *lc = "";
951
1.60M
  char *rc = "";
952
1.60M
  if (oprnd->mask == HAS_SUB_OPERAND)
953
146k
    {
954
146k
      struct soperand *sop = (struct soperand *)oprnd;
955
146k
      if (oprnd->type == OPRND_TYPE_BRACKET)
956
134k
  {
957
134k
    lc = "(";
958
134k
    rc = ")";
959
134k
  }
960
11.5k
      else if (oprnd->type == OPRND_TYPE_ABRACKET)
961
11.5k
  {
962
11.5k
    lc = "<";
963
11.5k
    rc = ">";
964
11.5k
  }
965
146k
      strcat (str, lc);
966
146k
      ret = csky_print_operand (str, &sop->subs[0], inst, reloc);
967
146k
      if (ret)
968
0
  return ret;
969
146k
      strcat (str, ", ");
970
146k
      ret = csky_print_operand (str, &sop->subs[1], inst, reloc);
971
146k
      strcat (str, rc);
972
146k
      return ret;
973
146k
    }
974
1.46M
  return csky_output_operand (str, oprnd, inst, reloc);
975
1.60M
}
976
977
static int
978
csky_print_operands (char *str, struct csky_opcode_info const *pinfo,
979
         struct disassemble_info *info, CSKY_INST_TYPE inst,
980
         int reloc)
981
777k
{
982
777k
  int i = 0;
983
777k
  int ret = 0;
984
777k
  if (pinfo->operand_num)
985
653k
    strcat (str, "      \t");
986
777k
  if (pinfo->operand_num == -1)
987
9.08k
    {
988
9.08k
      ret = csky_print_operand (str, &pinfo->oprnd.oprnds[i], inst, reloc);
989
9.08k
      if (ret)
990
0
  return ret;
991
9.08k
    }
992
768k
  else
993
2.07M
    for (; i < pinfo->operand_num; i++)
994
1.30M
      {
995
1.30M
  if (i != 0)
996
663k
    strcat (str, ", ");
997
1.30M
  ret = csky_print_operand (str, &pinfo->oprnd.oprnds[i], inst, reloc);
998
1.30M
  if (ret)
999
898
    return ret;
1000
1.30M
      }
1001
776k
  info->fprintf_func (info->stream, "%s", str);
1002
776k
  if (dis_info.need_output_symbol)
1003
142k
    {
1004
142k
      info->fprintf_func (info->stream, "\t// ");
1005
142k
      info->print_address_func (dis_info.value, dis_info.info);
1006
142k
    }
1007
776k
  return 0;
1008
777k
}
1009
1010
static void
1011
number_to_chars_littleendian (char *buf, CSKY_INST_TYPE val, int n)
1012
0
{
1013
0
  if (n <= 0)
1014
0
    abort ();
1015
0
  while (n--)
1016
0
    {
1017
0
      *buf++ = val & 0xff;
1018
0
      val >>= 8;
1019
0
    }
1020
0
}
1021
1022
943k
#define CSKY_READ_DATA()                                        \
1023
943k
{                                                               \
1024
943k
  status = info->read_memory_func (memaddr, buf, 2, info);      \
1025
943k
  if (status)                                                   \
1026
943k
    {                                                           \
1027
379
      info->memory_error_func (status, memaddr, info);          \
1028
379
      return -1;                                                \
1029
379
    }                                                           \
1030
943k
  if (info->endian == BFD_ENDIAN_BIG)                           \
1031
943k
    inst |= (buf[0] << 8) | buf[1];                             \
1032
943k
  else if (info->endian == BFD_ENDIAN_LITTLE)                   \
1033
458k
    inst |= (buf[1] << 8) | buf[0];                             \
1034
458k
  else                                                          \
1035
458k
    abort();                                                    \
1036
943k
  info->bytes_per_chunk += 2;                                   \
1037
943k
  memaddr += 2;                                                 \
1038
943k
}
1039
1040
int
1041
print_insn_csky (bfd_vma memaddr, struct disassemble_info *info)
1042
898k
{
1043
898k
  unsigned char buf[4];
1044
898k
  CSKY_INST_TYPE inst = 0;
1045
898k
  int status;
1046
898k
  char str[256];
1047
898k
  unsigned long given;
1048
898k
  int is_data = false;
1049
898k
  void (*printer) (bfd_vma, struct disassemble_info *, long);
1050
898k
  unsigned int  size = 4;
1051
1052
898k
  memset (str, 0, sizeof (str));
1053
898k
  info->bytes_per_chunk = 0;
1054
898k
  info->bytes_per_chunk = 0;
1055
898k
  dis_info.mem = memaddr;
1056
898k
  dis_info.info = info;
1057
898k
  dis_info.need_output_symbol = 0;
1058
1059
898k
  if (info->disassembler_options)
1060
638
    {
1061
638
      parse_csky_dis_options (info->disassembler_options);
1062
638
      info->disassembler_options = NULL;
1063
638
    }
1064
1065
898k
  if (mach_flag != INIT_MACH_FLAG && mach_flag != BINARY_MACH_FLAG)
1066
439k
    info->mach = mach_flag;
1067
459k
  else if (mach_flag == INIT_MACH_FLAG)
1068
2
    {
1069
2
      mach_flag = info->mach;
1070
2
      dis_info.isa = CSKY_DEFAULT_ISA;
1071
2
    }
1072
1073
898k
  if (mach_flag == BINARY_MACH_FLAG && info->endian == BFD_ENDIAN_UNKNOWN)
1074
0
    {
1075
0
      info->endian = BFD_ENDIAN_LITTLE;
1076
0
      dis_info.isa = CSKY_DEFAULT_ISA;
1077
0
    }
1078
1079
  /* First check the full symtab for a mapping symbol, even if there
1080
     are no usable non-mapping symbols for this address.  */
1081
898k
  if (info->symtab_size != 0
1082
898k
      && bfd_asymbol_flavour (*info->symtab) == bfd_target_elf_flavour)
1083
0
    {
1084
0
      bfd_vma addr;
1085
0
      int n;
1086
0
      int last_sym = -1;
1087
0
      enum sym_type type = CUR_TEXT;
1088
1089
0
      if (memaddr <= last_map_addr)
1090
0
  last_map_sym = -1;
1091
      /* Start scanning at the start of the function, or wherever
1092
   we finished last time.  */
1093
0
      n = 0;
1094
0
      if (n < last_map_sym)
1095
0
  n = last_map_sym;
1096
1097
      /* Scan up to the location being disassembled.  */
1098
0
      for (; n < info->symtab_size; n++)
1099
0
  {
1100
0
    addr = bfd_asymbol_value (info->symtab[n]);
1101
0
    if (addr > memaddr)
1102
0
      break;
1103
0
    if ((info->section == NULL
1104
0
         || info->section == info->symtab[n]->section)
1105
0
        && get_sym_code_type (info, n, &type))
1106
0
      last_sym = n;
1107
0
  }
1108
0
      last_map_sym = last_sym;
1109
0
      last_type = type;
1110
0
      is_data = (last_type == CUR_DATA);
1111
0
      if (is_data)
1112
0
  {
1113
0
    size = 4 - ( memaddr & 3);
1114
0
    for (n = last_sym + 1; n < info->symtab_size; n++)
1115
0
      {
1116
0
        addr = bfd_asymbol_value (info->symtab[n]);
1117
0
        if (addr > memaddr)
1118
0
    {
1119
0
      if (addr - memaddr < size)
1120
0
        size = addr - memaddr;
1121
0
      break;
1122
0
    }
1123
0
      }
1124
    /* If the next symbol is after three bytes, we need to
1125
       print only part of the data, so that we can use either
1126
       .byte or .short.  */
1127
0
    if (size == 3)
1128
0
      size = (memaddr & 1) ? 1 : 2;
1129
0
  }
1130
0
    }
1131
898k
  info->bytes_per_line = 4;
1132
1133
898k
  if (is_data)
1134
0
    {
1135
0
      int i;
1136
1137
      /* Size was already set above.  */
1138
0
      info->bytes_per_chunk = size;
1139
0
      printer = print_insn_data;
1140
1141
0
      status = info->read_memory_func (memaddr, (bfd_byte *) buf, size, info);
1142
0
      given = 0;
1143
0
      if (info->endian == BFD_ENDIAN_LITTLE)
1144
0
  for (i = size - 1; i >= 0; i--)
1145
0
    given = buf[i] | (given << 8);
1146
0
      else
1147
0
  for (i = 0; i < (int) size; i++)
1148
0
    given = buf[i] | (given << 8);
1149
1150
0
      printer (memaddr, info, given);
1151
0
      return info->bytes_per_chunk;
1152
0
    }
1153
1154
  /* Handle instructions.  */
1155
2.69M
  CSKY_READ_DATA();
1156
2.69M
  if ((inst & 0xc000) == 0xc000 && IS_CSKY_V2 (mach_flag))
1157
45.4k
    {
1158
      /* It's a 32-bit instruction.  */
1159
45.4k
      inst <<= 16;
1160
90.9k
      CSKY_READ_DATA();
1161
90.9k
      if (info->buffer && (info->endian == BFD_ENDIAN_LITTLE))
1162
0
  {
1163
0
    char* src = (char *)(info->buffer
1164
0
             + ((memaddr - 4 - info->buffer_vma)
1165
0
          * info->octets_per_byte));
1166
0
    if (info->endian == BFD_ENDIAN_LITTLE)
1167
0
      number_to_chars_littleendian (src, inst, 4);
1168
0
  }
1169
90.9k
    }
1170
1171
897k
  if (IS_CSKY_V1 (mach_flag))
1172
183k
    g_opcodeP = csky_v1_opcodes;
1173
714k
  else
1174
714k
    g_opcodeP = csky_v2_opcodes;
1175
1176
897k
  do
1177
898k
    {
1178
898k
      struct csky_opcode const *op;
1179
898k
      struct csky_opcode_info const *pinfo = NULL;
1180
898k
      int reloc;
1181
1182
898k
      memset (str, 0, sizeof (str));
1183
898k
      op = csky_find_inst_info (&pinfo, inst, info->bytes_per_chunk);
1184
898k
      if (!op)
1185
121k
  {
1186
121k
    if (IS_CSKY_V1 (mach_flag))
1187
326
      info->fprintf_func (info->stream, ".short: 0x%04x",
1188
326
        (unsigned short)inst);
1189
121k
    else
1190
121k
      info->fprintf_func (info->stream, ".long: 0x%08x",
1191
121k
        (unsigned int)inst);
1192
121k
    return info->bytes_per_chunk;
1193
121k
  }
1194
1195
777k
      if (info->bytes_per_chunk == 2)
1196
754k
  reloc = op->reloc16;
1197
22.4k
      else
1198
22.4k
  reloc = op->reloc32;
1199
777k
      dis_info.opinfo = pinfo;
1200
777k
      strcat (str, op->mnemonic);
1201
1202
777k
      if (csky_print_operands (str, pinfo, info, inst, reloc))
1203
898
  g_opcodeP++;
1204
776k
      else
1205
776k
  break;
1206
777k
    } while (1);
1207
1208
776k
  return info->bytes_per_chunk;
1209
897k
}