2 Copyright (C) 1988-2020 Free Software Foundation, Inc.
3 Contributed by C-SKY Microsystems and Mentor Graphics.
5 This file is part of the GNU opcodes library.
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)
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.
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. */
25 #include "bfd_stdint.h"
27 #include "disassemble.h"
29 #include "opcode/csky.h"
30 #include "libiberty.h"
32 #include "floatformat.h"
34 #define CSKY_INST_TYPE unsigned long
35 #define HAS_SUB_OPERAND (unsigned int)0xffffffff
36 #define CSKY_DEFAULT_ISA 0xffffffff
46 /* Mem to disassemble. */
48 /* Disassemble info. */
49 disassemble_info
*info
;
50 /* Opcode information. */
51 struct csky_opcode_info
const *opinfo
;
52 BFD_HOST_U_64_BIT isa
;
53 /* The value of operand to show. */
55 /* Whether to look up/print a symbol name. */
56 int need_output_symbol
;
60 enum sym_type last_type
;
62 bfd_vma last_map_addr
= 0;
64 /* Only for objdump tool. */
65 #define INIT_MACH_FLAG 0xffffffff
66 #define BINARY_MACH_FLAG 0x0
68 static unsigned int mach_flag
= INIT_MACH_FLAG
;
71 print_insn_data (bfd_vma pc ATTRIBUTE_UNUSED
,
72 struct disassemble_info
*info
,
75 switch (info
->bytes_per_chunk
)
78 info
->fprintf_func (info
->stream
, ".byte\t0x%02lx", given
);
81 info
->fprintf_func (info
->stream
, ".short\t0x%04lx", given
);
84 info
->fprintf_func (info
->stream
, ".long\t0x%08lx", given
);
92 get_sym_code_type (struct disassemble_info
*info
,
94 enum sym_type
*sym_type
)
97 name
= bfd_asymbol_name (info
->symtab
[n
]);
98 if (name
[0] == '$' && (name
[1] == 't' || name
[1] == 'd')
99 && (name
[2] == 0 || name
[2] == '.'))
101 *sym_type
= ((name
[1] == 't') ? CUR_TEXT
: CUR_DATA
);
108 csky_get_operand_mask (struct operand
const *oprnd
)
111 if (oprnd
->mask
== HAS_SUB_OPERAND
)
113 struct soperand
*sop
= (struct soperand
*)oprnd
;
114 mask
|= csky_get_operand_mask (&sop
->subs
[0]);
115 mask
|= csky_get_operand_mask (&sop
->subs
[1]);
122 csky_get_mask (struct csky_opcode_info
const *pinfo
)
127 if (pinfo
->operand_num
== -1)
128 mask
|= csky_get_operand_mask (&pinfo
->oprnd
.oprnds
[i
]);
130 for (; i
< pinfo
->operand_num
; i
++)
131 mask
|= csky_get_operand_mask (&pinfo
->oprnd
.oprnds
[i
]);
138 csky_chars_to_number (unsigned char * buf
, int n
)
141 unsigned int val
= 0;
143 if (dis_info
.info
->endian
== BFD_ENDIAN_BIG
)
144 for (i
= 0; i
< n
; i
++)
145 val
= val
<< 8 | buf
[i
];
147 for (i
= n
- 1; i
>= 0; i
--)
148 val
= val
<< 8 | buf
[i
];
152 static struct csky_opcode
const *g_opcodeP
;
154 static struct csky_opcode
const *
155 csky_find_inst_info (struct csky_opcode_info
const **pinfo
,
156 CSKY_INST_TYPE inst
, int length
)
160 struct csky_opcode
const *p
;
165 if (!(p
->isa_flag16
& dis_info
.isa
)
166 && !(p
->isa_flag32
& dis_info
.isa
))
172 /* Get the opcode mask. */
173 for (i
= 0; i
< OP_TABLE_NUM
; i
++)
176 mask
= csky_get_mask (&p
->op16
[i
]);
177 if (mask
!= 0 && (inst
& mask
) == p
->op16
[i
].opcode
)
179 *pinfo
= &p
->op16
[i
];
184 else if (length
== 4)
186 mask
= csky_get_mask (&p
->op32
[i
]);
188 && ((unsigned long)(inst
& mask
)
189 == (unsigned long)p
->op32
[i
].opcode
))
191 *pinfo
= &p
->op32
[i
];
203 is_extern_symbol (struct disassemble_info
*info
, int addr
)
205 unsigned int rel_count
= 0;
207 if (info
->section
== NULL
)
209 if ((info
->section
->flags
& SEC_RELOC
) != 0) /* Fit .o file. */
211 struct reloc_cache_entry
*pt
= info
->section
->relocation
;
212 for (; rel_count
< info
->section
->reloc_count
; rel_count
++, pt
++)
213 if ((long unsigned int)addr
== pt
->address
)
221 /* Suppress printing of mapping symbols emitted by the assembler to mark
222 the beginning of code and data sequences. */
225 csky_symbol_is_valid (asymbol
*sym
,
226 struct disassemble_info
*info ATTRIBUTE_UNUSED
)
232 name
= bfd_asymbol_name (sym
);
233 return name
&& *name
!= '$';
237 csky_get_disassembler (bfd
*abfd
)
240 const char *sec_name
= NULL
;
244 mach_flag
= elf_elfheader (abfd
)->e_flags
;
246 sec_name
= get_elf_backend_data (abfd
)->obj_attrs_section
;
247 /* Skip any input that hasn't attribute section.
248 This enables to link object files without attribute section with
250 if (bfd_get_section_by_name (abfd
, sec_name
) != NULL
)
252 attr
= elf_known_obj_attributes_proc (abfd
);
253 dis_info
.isa
= attr
[Tag_CSKY_ISA_EXT_FLAGS
].i
;
255 dis_info
.isa
|= attr
[Tag_CSKY_ISA_FLAGS
].i
;
258 dis_info
.isa
= CSKY_DEFAULT_ISA
;
260 return print_insn_csky
;
264 csky_output_operand (char *str
, struct operand
const *oprnd
,
265 CSKY_INST_TYPE inst
, int reloc ATTRIBUTE_UNUSED
)
271 int mask
= oprnd
->mask
;
275 /* Get operand value with mask. */
277 for (; mask
; mask
>>= 1, value
>>=1)
280 result
|= ((value
& 0x1) << bit
);
286 /* Here is general instructions that have no reloc. */
289 case OPRND_TYPE_CTRLREG
:
290 if (IS_CSKY_V1 (mach_flag
))
292 /* In V1 only cr0-cr12 have alias names. */
294 strcat (str
, csky_ctrl_regs
[value
].name
);
295 /* Others using crn(n > 12). */
296 else if (value
<= 30)
298 sprintf (buf
, "cr%d", (int)value
);
310 sprintf (buf
, "cr<%d, %d>", crx
, sel
);
314 case OPRND_TYPE_DUMMY_REG
:
315 mask
= dis_info
.opinfo
->oprnd
.oprnds
[0].mask
;
317 for (; mask
; mask
>>= 1, value
>>=1)
320 result
|= ((value
& 0x1) << bit
);
324 strcat (str
, csky_general_reg
[value
]);
326 case OPRND_TYPE_GREG0_7
:
327 case OPRND_TYPE_GREG0_15
:
328 case OPRND_TYPE_GREG16_31
:
329 case OPRND_TYPE_REGnsplr
:
330 case OPRND_TYPE_AREG
:
331 if (IS_CSKY_V2 (mach_flag
) && value
== 14)
334 strcat (str
, csky_general_reg
[value
]);
335 dis_info
.value
= value
;
337 case OPRND_TYPE_CPREG
:
338 strcat (str
, csky_cp_reg
[value
]);
340 case OPRND_TYPE_FREG
:
341 sprintf (buf
, "fr%d", (int)value
);
344 case OPRND_TYPE_VREG
:
345 dis_info
.value
= value
;
346 sprintf (buf
, "vr%d", (int)value
);
349 case OPRND_TYPE_CPCREG
:
350 strcat (str
, csky_cp_creg
[value
]);
352 case OPRND_TYPE_CPIDX
:
353 strcat (str
, csky_cp_idx
[value
]);
355 case OPRND_TYPE_IMM2b_JMPIX
:
356 value
= (value
+ 2) << 3;
357 sprintf (buf
, "%d", (int)value
);
360 case OPRND_TYPE_IMM_LDST
:
361 case OPRND_TYPE_IMM_FLDST
:
362 value
<<= oprnd
->shift
;
363 sprintf (buf
, "0x%x", (unsigned int)value
);
366 case OPRND_TYPE_IMM7b_LS2
:
367 case OPRND_TYPE_IMM8b_LS2
:
368 sprintf (buf
, "%d", (int)(value
<< 2));
372 case OPRND_TYPE_IMM5b_BMASKI
:
373 if ((value
!= 0) && (value
> 31 || value
< 8))
378 sprintf (buf
, "%d", (int)value
);
382 case OPRND_TYPE_IMM5b_1_31
:
383 if (value
> 31 || value
< 1)
388 sprintf (buf
, "%d", (int)value
);
392 case OPRND_TYPE_IMM5b_7_31
:
393 if (value
> 31 || value
< 7)
398 sprintf (buf
, "%d", (int)value
);
402 case OPRND_TYPE_MSB2SIZE
:
403 case OPRND_TYPE_LSB2SIZE
:
406 if (oprnd
->type
== OPRND_TYPE_MSB2SIZE
)
410 str
[strlen (str
) - 2] = '\0';
411 sprintf (buf
, "%d, %d", (int)(size
+ value
), (int)value
);
416 case OPRND_TYPE_IMM1b
:
417 case OPRND_TYPE_IMM2b
:
418 case OPRND_TYPE_IMM4b
:
419 case OPRND_TYPE_IMM5b
:
420 case OPRND_TYPE_IMM7b
:
421 case OPRND_TYPE_IMM8b
:
422 case OPRND_TYPE_IMM12b
:
423 case OPRND_TYPE_IMM15b
:
424 case OPRND_TYPE_IMM16b
:
425 case OPRND_TYPE_IMM16b_MOVIH
:
426 case OPRND_TYPE_IMM16b_ORI
:
427 sprintf (buf
, "%d", (int)value
);
431 case OPRND_TYPE_OFF8b
:
432 case OPRND_TYPE_OFF16b
:
434 unsigned char ibytes
[4];
435 int shift
= oprnd
->shift
;
437 unsigned int mem_val
;
439 dis_info
.info
->stop_vma
= 0;
441 value
= ((dis_info
.mem
+ (value
<< shift
)
442 + ((IS_CSKY_V1 (mach_flag
)) ? 2 : 0))
444 status
= dis_info
.info
->read_memory_func (value
, ibytes
, 4,
448 dis_info
.info
->memory_error_func (status
, dis_info
.mem
,
452 mem_val
= csky_chars_to_number (ibytes
, 4);
453 /* Remove [] around literal value to match ABI syntax. */
454 sprintf (buf
, "0x%X", mem_val
);
456 /* For jmpi/jsri, we'll try to get a symbol for the target. */
457 if (dis_info
.info
->print_address_func
&& mem_val
!= 0)
459 dis_info
.value
= mem_val
;
460 dis_info
.need_output_symbol
= 1;
464 sprintf (buf
, "\t// from address pool at 0x%x",
465 (unsigned int)value
);
470 case OPRND_TYPE_BLOOP_OFF4b
:
471 case OPRND_TYPE_BLOOP_OFF12b
:
472 case OPRND_TYPE_OFF11b
:
473 case OPRND_TYPE_OFF16b_LSL1
:
474 case OPRND_TYPE_IMM_OFF18b
:
475 case OPRND_TYPE_OFF26b
:
477 int shift
= oprnd
->shift
;
478 if (value
& ((max
>> 1) + 1))
480 if (is_extern_symbol (dis_info
.info
, dis_info
.mem
))
482 else if (IS_CSKY_V1 (mach_flag
))
483 value
= dis_info
.mem
+ 2 + (value
<< shift
);
485 value
= dis_info
.mem
+ (value
<< shift
);
486 dis_info
.need_output_symbol
= 1;
487 dis_info
.value
= value
;
488 sprintf (buf
, "0x%x", (unsigned int)value
);
492 case OPRND_TYPE_CONSTANT
:
493 case OPRND_TYPE_FCONSTANT
:
495 int shift
= oprnd
->shift
;
501 dis_info
.info
->stop_vma
= 0;
504 if (IS_CSKY_V1 (mach_flag
))
505 addr
= (dis_info
.mem
+ 2 + value
) & 0xfffffffc;
507 addr
= (dis_info
.mem
+ value
) & 0xfffffffc;
509 if (oprnd
->type
== OPRND_TYPE_FCONSTANT
510 && dis_info
.opinfo
->opcode
!= CSKYV2_INST_FLRW
)
515 status
= dis_info
.info
->read_memory_func (addr
, (bfd_byte
*)ibytes
,
516 nbytes
, dis_info
.info
);
518 /* Address out of bounds. -> lrw rx, [pc, 0ffset]. */
519 sprintf (buf
, "[pc, %d]\t// from address pool at %x", (int)value
,
523 dis_info
.value
= addr
;
524 value
= csky_chars_to_number ((unsigned char *)ibytes
, 4);
527 if (oprnd
->type
== OPRND_TYPE_FCONSTANT
)
531 if (dis_info
.opinfo
->opcode
== CSKYV2_INST_FLRW
)
533 floatformat_to_double ((dis_info
.info
->endian
== BFD_ENDIAN_BIG
534 ? &floatformat_ieee_single_big
535 : &floatformat_ieee_single_little
),
538 floatformat_to_double ((dis_info
.info
->endian
== BFD_ENDIAN_BIG
539 ? &floatformat_ieee_double_big
540 : &floatformat_ieee_double_little
),
542 sprintf (buf
, "%f", f
);
546 dis_info
.need_output_symbol
= 1;
547 sprintf (buf
, "0x%x", (unsigned int)value
);
553 case OPRND_TYPE_ELRW_CONSTANT
:
555 int shift
= oprnd
->shift
;
559 dis_info
.info
->stop_vma
= 0;
561 value
= 0x80 + ((~value
) & 0x7f);
563 value
= value
<< shift
;
564 addr
= (dis_info
.mem
+ value
) & 0xfffffffc;
566 status
= dis_info
.info
->read_memory_func (addr
, (bfd_byte
*)ibytes
,
569 /* Address out of bounds. -> lrw rx, [pc, 0ffset]. */
570 sprintf (buf
, "[pc, %d]\t// from address pool at %x", (int) value
,
574 dis_info
.value
= addr
;
575 value
= csky_chars_to_number ((unsigned char *)ibytes
, 4);
576 dis_info
.need_output_symbol
= 1;
577 sprintf (buf
, "0x%x", (unsigned int)value
);
583 case OPRND_TYPE_SFLOAT
:
584 case OPRND_TYPE_DFLOAT
:
586 /* This is for fmovis/fmovid, which have an internal 13-bit
587 encoding that they convert to single/double precision
588 (respectively). We'll convert the 13-bit encoding to an IEEE
589 double and then to host double format to print it.
591 4-bit exponent: bits 19:16, biased by 11.
592 8-bit mantissa: split between 24:21 and 7:4. */
596 unsigned char valbytes
[8];
599 imm4
= ((inst
>> 16) & 0xf);
600 imm4
= (uint64_t)(1023 - (imm4
- 11)) << 52;
602 imm8
= (uint64_t)((inst
>> 4) & 0xf) << 44;
603 imm8
|= (uint64_t)((inst
>> 21) & 0xf) << 48;
605 dbnum
= (uint64_t)((inst
>> 20) & 1) << 63;
606 dbnum
|= imm4
| imm8
;
608 /* Do this a byte at a time so we don't have to
609 worry about the host's endianness. */
610 valbytes
[0] = dbnum
& 0xff;
611 valbytes
[1] = (dbnum
>> 8) & 0xff;
612 valbytes
[2] = (dbnum
>> 16) & 0xff;
613 valbytes
[3] = (dbnum
>> 24) & 0xff;
614 valbytes
[4] = (dbnum
>> 32) & 0xff;
615 valbytes
[5] = (dbnum
>> 40) & 0xff;
616 valbytes
[6] = (dbnum
>> 48) & 0xff;
617 valbytes
[7] = (dbnum
>> 56) & 0xff;
619 floatformat_to_double (&floatformat_ieee_double_little
, valbytes
,
622 sprintf (buf
, "%f", fvalue
);
626 case OPRND_TYPE_HFLOAT_FMOVI
:
627 case OPRND_TYPE_SFLOAT_FMOVI
:
631 imm4
= ((inst
>> 16) & 0xf);
632 imm4
= (138 - imm4
) << 23;
634 imm8
= ((inst
>> 8) & 0x3);
635 imm8
|= (((inst
>> 20) & 0x3f) << 2);
638 value
= ((inst
>> 5) & 1) << 31;
639 value
|= imm4
| imm8
;
641 imm4
= 138 - (imm4
>> 23);
649 memcpy (&f
, &value
, sizeof (float));
650 sprintf (buf
, "%f\t// imm9:%4d, imm4:%2d", f
, imm8
, imm4
);
656 case OPRND_TYPE_DFLOAT_FMOVI
:
661 imm4
= ((inst
>> 16) & 0xf);
662 imm4
= (1034 - imm4
) << 52;
664 imm8
= ((inst
>> 8) & 0x3);
665 imm8
|= (((inst
>> 20) & 0x3f) << 2);
668 dvalue
= (((uint64_t)inst
>> 5) & 1) << 63;
669 dvalue
|= imm4
| imm8
;
671 imm4
= 1034 - (imm4
>> 52);
678 memcpy (&d
, &dvalue
, sizeof (double));
679 sprintf (buf
, "%lf\t// imm9:%4ld, imm4:%2ld", d
, (long) imm8
, (long) imm4
);
684 case OPRND_TYPE_LABEL_WITH_BRACKET
:
685 sprintf (buf
, "[0x%x]", (unsigned int)value
);
687 strcat (str
, "\t// the offset is based on .data");
689 case OPRND_TYPE_OIMM3b
:
690 case OPRND_TYPE_OIMM4b
:
691 case OPRND_TYPE_OIMM5b
:
692 case OPRND_TYPE_OIMM5b_IDLY
:
693 case OPRND_TYPE_OIMM8b
:
694 case OPRND_TYPE_OIMM12b
:
695 case OPRND_TYPE_OIMM16b
:
696 case OPRND_TYPE_OIMM18b
:
698 sprintf (buf
, "%d", (int)value
);
701 case OPRND_TYPE_OIMM5b_BMASKI
:
702 if (value
> 32 || value
< 16)
707 sprintf (buf
, "%d", (int)(value
+ 1));
711 case OPRND_TYPE_FREGLIST_DASH
:
712 if (IS_CSKY_V2 (mach_flag
))
716 if (dis_info
.isa
& CSKY_ISA_FLOAT_7E60
717 && (strstr (str
, "fstm") != NULL
718 || strstr (str
, "fldm") != NULL
))
721 vry
= vrx
+ (value
>> 5);
726 vry
= vrx
+ (value
>> 4);
728 sprintf (buf
, "fr%d-fr%d", vrx
, vry
);
732 case OPRND_TYPE_REGLIST_DASH
:
733 if (IS_CSKY_V1 (mach_flag
))
735 strcat (str
, csky_general_reg
[value
]);
736 strcat (str
, "-r15");
740 strcat (str
, csky_general_reg
[value
>> 5]);
742 strcat (str
, csky_general_reg
[(value
& 0x1f) + (value
>> 5)]);
745 case OPRND_TYPE_PSR_BITS_LIST
:
747 struct psrbit
const *bits
;
748 int first_oprnd
= TRUE
;
750 if (IS_CSKY_V1 (mach_flag
))
757 bits
= cskyv1_psr_bits
;
760 bits
= cskyv2_psr_bits
;
761 while (value
!= 0 && bits
[i
].name
!= NULL
)
763 if (value
& bits
[i
].value
)
767 strcat (str
, bits
[i
].name
);
768 value
&= ~bits
[i
].value
;
775 case OPRND_TYPE_REGbsp
:
776 if (IS_CSKY_V1 (mach_flag
))
777 strcat (str
, "(sp)");
779 strcat (str
, "(sp)");
781 case OPRND_TYPE_REGsp
:
782 if (IS_CSKY_V1 (mach_flag
))
787 case OPRND_TYPE_REGnr4_r7
:
788 case OPRND_TYPE_AREG_WITH_BRACKET
:
789 if (IS_CSKY_V1 (mach_flag
) && (value
< 4 || value
> 7))
792 strcat (str
, csky_general_reg
[value
]);
798 strcat (str
, csky_general_reg
[value
]);
802 case OPRND_TYPE_AREG_WITH_LSHIFT
:
803 strcat (str
, csky_general_reg
[value
>> 5]);
804 strcat (str
, " << ");
805 if ((value
& 0x1f) == 0x1)
807 else if ((value
& 0x1f) == 0x2)
809 else if ((value
& 0x1f) == 0x4)
811 else if ((value
& 0x1f) == 0x8)
814 case OPRND_TYPE_AREG_WITH_LSHIFT_FPU
:
815 strcat (str
, csky_general_reg
[value
>> 2]);
816 strcat (str
, " << ");
817 if ((value
& 0x3) == 0x0)
819 else if ((value
& 0x3) == 0x1)
821 else if ((value
& 0x3) == 0x2)
823 else if ((value
& 0x3) == 0x3)
826 case OPRND_TYPE_FREG_WITH_INDEX
:
828 unsigned freg_val
= value
& 0xf;
829 unsigned index_val
= (value
>> 4) & 0xf;
830 sprintf (buf
, "vr%d[%d]", freg_val
, index_val
);
834 case OPRND_TYPE_REGr4_r7
:
835 if (IS_CSKY_V1 (mach_flag
))
836 strcat (str
, "r4-r7");
838 case OPRND_TYPE_CONST1
:
841 case OPRND_TYPE_REG_r1a
:
842 case OPRND_TYPE_REG_r1b
:
845 case OPRND_TYPE_REG_r28
:
848 case OPRND_TYPE_REGLIST_DASH_COMMA
:
849 /* 16-bit reglist. */
853 if ((value
& 0xf) > 1)
856 strcat (str
, csky_general_reg
[(value
& 0xf) + 3]);
868 if (dis_info
.opinfo
->oprnd
.oprnds
[0].mask
!= OPRND_MASK_0_4
)
870 /* 32bits reglist. */
875 if ((value
& 0x7) > 1)
878 strcat (str
, csky_general_reg
[(value
& 0xf) + 15]);
888 case OPRND_TYPE_UNCOND10b
:
889 case OPRND_TYPE_UNCOND16b
:
890 case OPRND_TYPE_COND10b
:
891 case OPRND_TYPE_COND16b
:
893 int shift
= oprnd
->shift
;
895 if (value
& ((max
>> 1) + 1))
897 if (is_extern_symbol (dis_info
.info
, dis_info
.mem
))
900 value
= dis_info
.mem
+ (value
<< shift
);
901 sprintf (buf
, "0x%x", (unsigned int)value
);
903 dis_info
.need_output_symbol
= 1;
904 dis_info
.value
= value
;
916 csky_print_operand (char *str
, struct operand
const *oprnd
,
917 CSKY_INST_TYPE inst
, int reloc
)
922 if (oprnd
->mask
== HAS_SUB_OPERAND
)
924 struct soperand
*sop
= (struct soperand
*)oprnd
;
925 if (oprnd
->type
== OPRND_TYPE_BRACKET
)
930 else if (oprnd
->type
== OPRND_TYPE_ABRACKET
)
936 ret
= csky_print_operand (str
, &sop
->subs
[0], inst
, reloc
);
940 ret
= csky_print_operand (str
, &sop
->subs
[1], inst
, reloc
);
944 return csky_output_operand (str
, oprnd
, inst
, reloc
);
948 csky_print_operands (char *str
, struct csky_opcode_info
const *pinfo
,
949 struct disassemble_info
*info
, CSKY_INST_TYPE inst
,
954 if (pinfo
->operand_num
)
956 if (pinfo
->operand_num
== -1)
958 ret
= csky_print_operand (str
, &pinfo
->oprnd
.oprnds
[i
], inst
, reloc
);
963 for (; i
< pinfo
->operand_num
; i
++)
967 ret
= csky_print_operand (str
, &pinfo
->oprnd
.oprnds
[i
], inst
, reloc
);
971 info
->fprintf_func (info
->stream
, "%s", str
);
972 if (dis_info
.need_output_symbol
)
974 info
->fprintf_func (info
->stream
, "\t// ");
975 info
->print_address_func (dis_info
.value
, dis_info
.info
);
981 number_to_chars_littleendian (char *buf
, CSKY_INST_TYPE val
, int n
)
992 #define CSKY_READ_DATA() \
994 status = info->read_memory_func (memaddr, buf, 2, info); \
997 info->memory_error_func (status, memaddr, info); \
1000 if (info->endian == BFD_ENDIAN_BIG) \
1001 inst |= (buf[0] << 8) | buf[1]; \
1002 else if (info->endian == BFD_ENDIAN_LITTLE) \
1003 inst |= (buf[1] << 8) | buf[0]; \
1006 info->bytes_per_chunk += 2; \
1011 print_insn_csky (bfd_vma memaddr
, struct disassemble_info
*info
)
1013 unsigned char buf
[4];
1014 CSKY_INST_TYPE inst
= 0;
1017 unsigned long given
;
1018 int is_data
= FALSE
;
1019 void (*printer
) (bfd_vma
, struct disassemble_info
*, long);
1020 unsigned int size
= 4;
1022 memset (str
, 0, sizeof (str
));
1023 info
->bytes_per_chunk
= 0;
1024 info
->bytes_per_chunk
= 0;
1025 dis_info
.mem
= memaddr
;
1026 dis_info
.info
= info
;
1027 dis_info
.need_output_symbol
= 0;
1028 if (mach_flag
!= INIT_MACH_FLAG
&& mach_flag
!= BINARY_MACH_FLAG
)
1029 info
->mach
= mach_flag
;
1030 else if (mach_flag
== INIT_MACH_FLAG
)
1032 mach_flag
= info
->mach
;
1033 dis_info
.isa
= CSKY_DEFAULT_ISA
;
1036 if (mach_flag
== BINARY_MACH_FLAG
&& info
->endian
== BFD_ENDIAN_UNKNOWN
)
1038 info
->endian
= BFD_ENDIAN_LITTLE
;
1039 dis_info
.isa
= CSKY_DEFAULT_ISA
;
1042 /* First check the full symtab for a mapping symbol, even if there
1043 are no usable non-mapping symbols for this address. */
1044 if (info
->symtab_size
!= 0
1045 && bfd_asymbol_flavour (*info
->symtab
) == bfd_target_elf_flavour
)
1050 enum sym_type type
= CUR_TEXT
;
1052 if (memaddr
<= last_map_addr
)
1054 /* Start scanning at the start of the function, or wherever
1055 we finished last time. */
1057 if (n
< last_map_sym
)
1060 /* Scan up to the location being disassembled. */
1061 for (; n
< info
->symtab_size
; n
++)
1063 addr
= bfd_asymbol_value (info
->symtab
[n
]);
1066 if ((info
->section
== NULL
1067 || info
->section
== info
->symtab
[n
]->section
)
1068 && get_sym_code_type (info
, n
, &type
))
1071 last_map_sym
= last_sym
;
1073 is_data
= (last_type
== CUR_DATA
);
1076 size
= 4 - ( memaddr
& 3);
1077 for (n
= last_sym
+ 1; n
< info
->symtab_size
; n
++)
1079 addr
= bfd_asymbol_value (info
->symtab
[n
]);
1082 if (addr
- memaddr
< size
)
1083 size
= addr
- memaddr
;
1087 /* If the next symbol is after three bytes, we need to
1088 print only part of the data, so that we can use either
1091 size
= (memaddr
& 1) ? 1 : 2;
1094 info
->bytes_per_line
= 4;
1100 /* Size was already set above. */
1101 info
->bytes_per_chunk
= size
;
1102 printer
= print_insn_data
;
1104 status
= info
->read_memory_func (memaddr
, (bfd_byte
*) buf
, size
, info
);
1106 if (info
->endian
== BFD_ENDIAN_LITTLE
)
1107 for (i
= size
- 1; i
>= 0; i
--)
1108 given
= buf
[i
] | (given
<< 8);
1110 for (i
= 0; i
< (int) size
; i
++)
1111 given
= buf
[i
] | (given
<< 8);
1113 printer (memaddr
, info
, given
);
1114 return info
->bytes_per_chunk
;
1117 /* Handle instructions. */
1119 if ((inst
& 0xc000) == 0xc000 && IS_CSKY_V2 (mach_flag
))
1121 /* It's a 32-bit instruction. */
1124 if (info
->buffer
&& (info
->endian
== BFD_ENDIAN_LITTLE
))
1126 char* src
= (char *)(info
->buffer
1127 + ((memaddr
- 4 - info
->buffer_vma
)
1128 * info
->octets_per_byte
));
1129 if (info
->endian
== BFD_ENDIAN_LITTLE
)
1130 number_to_chars_littleendian (src
, inst
, 4);
1134 if (IS_CSKY_V1 (mach_flag
))
1135 g_opcodeP
= csky_v1_opcodes
;
1137 g_opcodeP
= csky_v2_opcodes
;
1141 struct csky_opcode
const *op
;
1142 struct csky_opcode_info
const *pinfo
= NULL
;
1145 memset (str
, 0, sizeof (str
));
1146 op
= csky_find_inst_info (&pinfo
, inst
, info
->bytes_per_chunk
);
1149 if (IS_CSKY_V1 (mach_flag
))
1150 info
->fprintf_func (info
->stream
, ".short: 0x%04x",
1151 (unsigned short)inst
);
1153 info
->fprintf_func (info
->stream
, ".long: 0x%08x",
1154 (unsigned int)inst
);
1155 return info
->bytes_per_chunk
;
1158 if (info
->bytes_per_chunk
== 2)
1159 reloc
= op
->reloc16
;
1161 reloc
= op
->reloc32
;
1162 dis_info
.opinfo
= pinfo
;
1163 strcat (str
, op
->mnemonic
);
1165 if (csky_print_operands (str
, pinfo
, info
, inst
, reloc
))
1171 return info
->bytes_per_chunk
;