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"
26 #include "disassemble.h"
28 #include "opcode/csky.h"
29 #include "libiberty.h"
31 #include "floatformat.h"
33 #define CSKY_INST_TYPE unsigned long
34 #define HAS_SUB_OPERAND (unsigned int)0xffffffff
44 /* Mem to disassemble. */
46 /* Disassemble info. */
47 disassemble_info
*info
;
48 /* Opcode information. */
49 struct csky_opcode_info
const *opinfo
;
50 /* The value of operand to show. */
52 /* Whether to look up/print a symbol name. */
53 int need_output_symbol
;
57 enum sym_type last_type
;
59 bfd_vma last_map_addr
= 0;
61 /* Only for objdump tool. */
62 #define INIT_MACH_FLAG 0xffffffff
63 #define BINARY_MACH_FLAG 0x0
65 static unsigned int mach_flag
= INIT_MACH_FLAG
;
68 print_insn_data (bfd_vma pc ATTRIBUTE_UNUSED
,
69 struct disassemble_info
*info
,
72 switch (info
->bytes_per_chunk
)
75 info
->fprintf_func (info
->stream
, ".byte\t0x%02lx", given
);
78 info
->fprintf_func (info
->stream
, ".short\t0x%04lx", given
);
81 info
->fprintf_func (info
->stream
, ".long\t0x%08lx", given
);
89 get_sym_code_type (struct disassemble_info
*info
,
91 enum sym_type
*sym_type
)
94 name
= bfd_asymbol_name (info
->symtab
[n
]);
95 if (name
[0] == '$' && (name
[1] == 't' || name
[1] == 'd')
96 && (name
[2] == 0 || name
[2] == '.'))
98 *sym_type
= ((name
[1] == 't') ? CUR_TEXT
: CUR_DATA
);
105 csky_get_operand_mask (struct operand
const *oprnd
)
108 if (oprnd
->mask
== HAS_SUB_OPERAND
)
110 struct soperand
*sop
= (struct soperand
*)oprnd
;
111 mask
|= csky_get_operand_mask (&sop
->subs
[0]);
112 mask
|= csky_get_operand_mask (&sop
->subs
[1]);
119 csky_get_mask (struct csky_opcode_info
const *pinfo
)
124 if (pinfo
->operand_num
== -1)
125 mask
|= csky_get_operand_mask (&pinfo
->oprnd
.oprnds
[i
]);
127 for (; i
< pinfo
->operand_num
; i
++)
128 mask
|= csky_get_operand_mask (&pinfo
->oprnd
.oprnds
[i
]);
135 csky_chars_to_number (unsigned char * buf
, int n
)
138 unsigned int val
= 0;
140 if (dis_info
.info
->endian
== BFD_ENDIAN_BIG
)
141 for (i
= 0; i
< n
; i
++)
142 val
= val
<< 8 | buf
[i
];
144 for (i
= n
- 1; i
>= 0; i
--)
145 val
= val
<< 8 | buf
[i
];
149 static struct csky_opcode
const *g_opcodeP
;
151 static struct csky_opcode
const *
152 csky_find_inst_info (struct csky_opcode_info
const **pinfo
,
153 CSKY_INST_TYPE inst
, int length
)
157 struct csky_opcode
const *p
;
162 /* Get the opcode mask. */
163 for (i
= 0; i
< OP_TABLE_NUM
; i
++)
166 mask
= csky_get_mask (&p
->op16
[i
]);
167 if (mask
!= 0 && (inst
& mask
) == p
->op16
[i
].opcode
)
169 *pinfo
= &p
->op16
[i
];
174 else if (length
== 4)
176 mask
= csky_get_mask (&p
->op32
[i
]);
178 && ((unsigned long)(inst
& mask
)
179 == (unsigned long)p
->op32
[i
].opcode
))
181 *pinfo
= &p
->op32
[i
];
193 is_extern_symbol (struct disassemble_info
*info
, int addr
)
195 unsigned int rel_count
= 0;
197 if (info
->section
== NULL
)
199 if ((info
->section
->flags
& SEC_RELOC
) != 0) /* Fit .o file. */
201 struct reloc_cache_entry
*pt
= info
->section
->relocation
;
202 for (; rel_count
< info
->section
->reloc_count
; rel_count
++, pt
++)
203 if ((long unsigned int)addr
== pt
->address
)
211 /* Suppress printing of mapping symbols emitted by the assembler to mark
212 the beginning of code and data sequences. */
215 csky_symbol_is_valid (asymbol
*sym
,
216 struct disassemble_info
*info ATTRIBUTE_UNUSED
)
222 name
= bfd_asymbol_name (sym
);
223 return name
&& *name
!= '$';
227 csky_get_disassembler (bfd
*abfd
)
230 mach_flag
= elf_elfheader (abfd
)->e_flags
;
231 return print_insn_csky
;
235 csky_output_operand (char *str
, struct operand
const *oprnd
,
236 CSKY_INST_TYPE inst
, int reloc ATTRIBUTE_UNUSED
)
242 int mask
= oprnd
->mask
;
246 /* Get operand value with mask. */
248 for (; mask
; mask
>>= 1, value
>>=1)
251 result
|= ((value
& 0x1) << bit
);
257 /* Here is general instructions that have no reloc. */
260 case OPRND_TYPE_CTRLREG
:
261 if (IS_CSKY_V1 (mach_flag
))
263 /* In V1 only cr0-cr12 have alias names. */
265 strcat (str
, csky_ctrl_regs
[value
].name
);
266 /* Others using crn(n > 12). */
267 else if (value
<= 30)
269 sprintf (buf
, "cr%d", (int)value
);
281 sprintf (buf
, "cr<%d, %d>", crx
, sel
);
285 case OPRND_TYPE_DUMMY_REG
:
286 mask
= dis_info
.opinfo
->oprnd
.oprnds
[0].mask
;
288 for (; mask
; mask
>>= 1, value
>>=1)
291 result
|= ((value
& 0x1) << bit
);
295 strcat (str
, csky_general_reg
[value
]);
297 case OPRND_TYPE_GREG0_7
:
298 case OPRND_TYPE_GREG0_15
:
299 case OPRND_TYPE_GREG16_31
:
300 case OPRND_TYPE_REGnsplr
:
301 case OPRND_TYPE_AREG
:
302 if (IS_CSKY_V2 (mach_flag
) && value
== 14)
305 strcat (str
, csky_general_reg
[value
]);
306 dis_info
.value
= value
;
308 case OPRND_TYPE_CPREG
:
309 strcat (str
, csky_cp_reg
[value
]);
311 case OPRND_TYPE_FREG
:
312 sprintf (buf
, "fr%d", (int)value
);
315 case OPRND_TYPE_VREG
:
316 sprintf (buf
, "vr%d", (int)value
);
319 case OPRND_TYPE_CPCREG
:
320 strcat (str
, csky_cp_creg
[value
]);
322 case OPRND_TYPE_CPIDX
:
323 strcat (str
, csky_cp_idx
[value
]);
325 case OPRND_TYPE_IMM2b_JMPIX
:
326 value
= (value
+ 2) << 3;
327 sprintf (buf
, "%d", (int)value
);
330 case OPRND_TYPE_IMM_LDST
:
331 case OPRND_TYPE_IMM_FLDST
:
332 value
<<= oprnd
->shift
;
333 sprintf (buf
, "0x%x", (unsigned int)value
);
336 case OPRND_TYPE_IMM7b_LS2
:
337 case OPRND_TYPE_IMM8b_LS2
:
338 sprintf (buf
, "%d", (int)(value
<< 2));
342 case OPRND_TYPE_IMM5b_BMASKI
:
343 if ((value
!= 0) && (value
> 31 || value
< 8))
348 sprintf (buf
, "%d", (int)value
);
352 case OPRND_TYPE_IMM5b_1_31
:
353 if (value
> 31 || value
< 1)
358 sprintf (buf
, "%d", (int)value
);
362 case OPRND_TYPE_IMM5b_7_31
:
363 if (value
> 31 || value
< 7)
368 sprintf (buf
, "%d", (int)value
);
372 case OPRND_TYPE_MSB2SIZE
:
373 case OPRND_TYPE_LSB2SIZE
:
376 if (oprnd
->type
== OPRND_TYPE_MSB2SIZE
)
380 str
[strlen (str
) - 2] = '\0';
381 sprintf (buf
, "%d, %d", (int)(size
+ value
), (int)value
);
386 case OPRND_TYPE_IMM1b
:
387 case OPRND_TYPE_IMM2b
:
388 case OPRND_TYPE_IMM4b
:
389 case OPRND_TYPE_IMM5b
:
390 case OPRND_TYPE_IMM7b
:
391 case OPRND_TYPE_IMM8b
:
392 case OPRND_TYPE_IMM12b
:
393 case OPRND_TYPE_IMM15b
:
394 case OPRND_TYPE_IMM16b
:
395 case OPRND_TYPE_IMM16b_MOVIH
:
396 case OPRND_TYPE_IMM16b_ORI
:
397 sprintf (buf
, "%d", (int)value
);
401 case OPRND_TYPE_OFF8b
:
402 case OPRND_TYPE_OFF16b
:
404 unsigned char ibytes
[4];
405 int shift
= oprnd
->shift
;
407 unsigned int mem_val
;
409 dis_info
.info
->stop_vma
= 0;
411 value
= ((dis_info
.mem
+ (value
<< shift
)
412 + ((IS_CSKY_V1 (mach_flag
)) ? 2 : 0))
414 status
= dis_info
.info
->read_memory_func (value
, ibytes
, 4,
418 dis_info
.info
->memory_error_func (status
, dis_info
.mem
,
422 mem_val
= csky_chars_to_number (ibytes
, 4);
423 /* Remove [] around literal value to match ABI syntax. */
424 sprintf (buf
, "0x%X", mem_val
);
426 /* For jmpi/jsri, we'll try to get a symbol for the target. */
427 if (dis_info
.info
->print_address_func
&& mem_val
!= 0)
429 dis_info
.value
= mem_val
;
430 dis_info
.need_output_symbol
= 1;
434 sprintf (buf
, "\t// from address pool at 0x%x",
435 (unsigned int)value
);
440 case OPRND_TYPE_BLOOP_OFF4b
:
441 case OPRND_TYPE_BLOOP_OFF12b
:
442 case OPRND_TYPE_OFF11b
:
443 case OPRND_TYPE_OFF16b_LSL1
:
444 case OPRND_TYPE_IMM_OFF18b
:
445 case OPRND_TYPE_OFF26b
:
447 int shift
= oprnd
->shift
;
448 if (value
& ((max
>> 1) + 1))
450 if (is_extern_symbol (dis_info
.info
, dis_info
.mem
))
452 else if (IS_CSKY_V1 (mach_flag
))
453 value
= dis_info
.mem
+ 2 + (value
<< shift
);
455 value
= dis_info
.mem
+ (value
<< shift
);
456 dis_info
.need_output_symbol
= 1;
457 dis_info
.value
= value
;
458 sprintf (buf
, "0x%x", (unsigned int)value
);
462 case OPRND_TYPE_CONSTANT
:
463 case OPRND_TYPE_FCONSTANT
:
465 int shift
= oprnd
->shift
;
471 dis_info
.info
->stop_vma
= 0;
474 if (IS_CSKY_V1 (mach_flag
))
475 addr
= (dis_info
.mem
+ 2 + value
) & 0xfffffffc;
477 addr
= (dis_info
.mem
+ value
) & 0xfffffffc;
479 if (oprnd
->type
== OPRND_TYPE_FCONSTANT
480 && dis_info
.opinfo
->opcode
!= CSKYV2_INST_FLRW
)
485 status
= dis_info
.info
->read_memory_func (addr
, (bfd_byte
*)ibytes
,
486 nbytes
, dis_info
.info
);
488 /* Address out of bounds. -> lrw rx, [pc, 0ffset]. */
489 sprintf (buf
, "[pc, %d]\t// from address pool at %x", (int)value
,
493 dis_info
.value
= addr
;
494 value
= csky_chars_to_number ((unsigned char *)ibytes
, 4);
497 if (oprnd
->type
== OPRND_TYPE_FCONSTANT
)
501 if (dis_info
.opinfo
->opcode
== CSKYV2_INST_FLRW
)
503 floatformat_to_double ((dis_info
.info
->endian
== BFD_ENDIAN_BIG
504 ? &floatformat_ieee_single_big
505 : &floatformat_ieee_single_little
),
508 floatformat_to_double ((dis_info
.info
->endian
== BFD_ENDIAN_BIG
509 ? &floatformat_ieee_double_big
510 : &floatformat_ieee_double_little
),
512 sprintf (buf
, "%f", f
);
516 dis_info
.need_output_symbol
= 1;
517 sprintf (buf
, "0x%x", (unsigned int)value
);
523 case OPRND_TYPE_ELRW_CONSTANT
:
525 int shift
= oprnd
->shift
;
529 dis_info
.info
->stop_vma
= 0;
531 value
= 0x80 + ((~value
) & 0x7f);
533 value
= value
<< shift
;
534 addr
= (dis_info
.mem
+ value
) & 0xfffffffc;
536 status
= dis_info
.info
->read_memory_func (addr
, (bfd_byte
*)ibytes
,
539 /* Address out of bounds. -> lrw rx, [pc, 0ffset]. */
540 sprintf (buf
, "[pc, %d]\t// from address pool at %x", (int) value
,
544 dis_info
.value
= addr
;
545 value
= csky_chars_to_number ((unsigned char *)ibytes
, 4);
546 dis_info
.need_output_symbol
= 1;
547 sprintf (buf
, "0x%x", (unsigned int)value
);
553 case OPRND_TYPE_SFLOAT
:
554 case OPRND_TYPE_DFLOAT
:
556 /* This is for fmovis/fmovid, which have an internal 13-bit
557 encoding that they convert to single/double precision
558 (respectively). We'll convert the 13-bit encoding to an IEEE
559 double and then to host double format to print it.
561 4-bit exponent: bits 19:16, biased by 11.
562 8-bit mantissa: split between 24:21 and 7:4. */
566 unsigned char valbytes
[8];
569 imm4
= ((inst
>> 16) & 0xf);
570 imm4
= (uint64_t)(1023 - (imm4
- 11)) << 52;
572 imm8
= (uint64_t)((inst
>> 4) & 0xf) << 44;
573 imm8
|= (uint64_t)((inst
>> 21) & 0xf) << 48;
575 dbnum
= (uint64_t)((inst
>> 20) & 1) << 63;
576 dbnum
|= imm4
| imm8
;
578 /* Do this a byte at a time so we don't have to
579 worry about the host's endianness. */
580 valbytes
[0] = dbnum
& 0xff;
581 valbytes
[1] = (dbnum
>> 8) & 0xff;
582 valbytes
[2] = (dbnum
>> 16) & 0xff;
583 valbytes
[3] = (dbnum
>> 24) & 0xff;
584 valbytes
[4] = (dbnum
>> 32) & 0xff;
585 valbytes
[5] = (dbnum
>> 40) & 0xff;
586 valbytes
[6] = (dbnum
>> 48) & 0xff;
587 valbytes
[7] = (dbnum
>> 56) & 0xff;
589 floatformat_to_double (&floatformat_ieee_double_little
, valbytes
,
592 sprintf (buf
, "%f", fvalue
);
596 case OPRND_TYPE_LABEL_WITH_BRACKET
:
597 sprintf (buf
, "[0x%x]", (unsigned int)value
);
599 strcat (str
, "\t// the offset is based on .data");
601 case OPRND_TYPE_OIMM3b
:
602 case OPRND_TYPE_OIMM4b
:
603 case OPRND_TYPE_OIMM5b
:
604 case OPRND_TYPE_OIMM5b_IDLY
:
605 case OPRND_TYPE_OIMM8b
:
606 case OPRND_TYPE_OIMM12b
:
607 case OPRND_TYPE_OIMM16b
:
608 case OPRND_TYPE_OIMM18b
:
610 sprintf (buf
, "%d", (int)value
);
613 case OPRND_TYPE_OIMM5b_BMASKI
:
614 if (value
> 32 || value
< 16)
619 sprintf (buf
, "%d", (int)(value
+ 1));
623 case OPRND_TYPE_FREGLIST_DASH
:
624 if (IS_CSKY_V2 (mach_flag
))
626 int vrx
= value
& 0xf;
627 int vry
= vrx
+ (value
>> 4);
628 sprintf (buf
, "fr%d-fr%d", vrx
, vry
);
632 case OPRND_TYPE_REGLIST_DASH
:
633 if (IS_CSKY_V1 (mach_flag
))
635 strcat (str
, csky_general_reg
[value
]);
636 strcat (str
, "-r15");
640 strcat (str
, csky_general_reg
[value
>> 5]);
642 strcat (str
, csky_general_reg
[(value
& 0x1f) + (value
>> 5)]);
645 case OPRND_TYPE_PSR_BITS_LIST
:
647 struct psrbit
const *bits
;
648 int first_oprnd
= TRUE
;
650 if (IS_CSKY_V1 (mach_flag
))
657 bits
= cskyv1_psr_bits
;
660 bits
= cskyv2_psr_bits
;
661 while (value
!= 0 && bits
[i
].name
!= NULL
)
663 if (value
& bits
[i
].value
)
667 strcat (str
, bits
[i
].name
);
668 value
&= ~bits
[i
].value
;
675 case OPRND_TYPE_REGbsp
:
676 if (IS_CSKY_V1 (mach_flag
))
677 strcat (str
, "(sp)");
679 strcat (str
, "(sp)");
681 case OPRND_TYPE_REGsp
:
682 if (IS_CSKY_V1 (mach_flag
))
687 case OPRND_TYPE_REGnr4_r7
:
688 case OPRND_TYPE_AREG_WITH_BRACKET
:
689 if (IS_CSKY_V1 (mach_flag
) && (value
< 4 || value
> 7))
692 strcat (str
, csky_general_reg
[value
]);
698 strcat (str
, csky_general_reg
[value
]);
702 case OPRND_TYPE_AREG_WITH_LSHIFT
:
703 strcat (str
, csky_general_reg
[value
>> 5]);
704 strcat (str
, " << ");
705 if ((value
& 0x1f) == 0x1)
707 else if ((value
& 0x1f) == 0x2)
709 else if ((value
& 0x1f) == 0x4)
711 else if ((value
& 0x1f) == 0x8)
714 case OPRND_TYPE_AREG_WITH_LSHIFT_FPU
:
715 strcat (str
, csky_general_reg
[value
>> 2]);
716 strcat (str
, " << ");
717 if ((value
& 0x3) == 0x0)
719 else if ((value
& 0x3) == 0x1)
721 else if ((value
& 0x3) == 0x2)
723 else if ((value
& 0x3) == 0x3)
726 case OPRND_TYPE_FREG_WITH_INDEX
:
728 unsigned freg_val
= value
& 0xf;
729 unsigned index_val
= (value
>> 4) & 0xf;
730 sprintf (buf
, "vr%d[%d]", freg_val
, index_val
);
734 case OPRND_TYPE_REGr4_r7
:
735 if (IS_CSKY_V1 (mach_flag
))
736 strcat (str
, "r4-r7");
738 case OPRND_TYPE_CONST1
:
741 case OPRND_TYPE_REG_r1a
:
742 case OPRND_TYPE_REG_r1b
:
745 case OPRND_TYPE_REG_r28
:
748 case OPRND_TYPE_REGLIST_DASH_COMMA
:
749 /* 16-bit reglist. */
753 if ((value
& 0xf) > 1)
756 strcat (str
, csky_general_reg
[(value
& 0xf) + 3]);
768 if (dis_info
.opinfo
->oprnd
.oprnds
[0].mask
!= OPRND_MASK_0_4
)
770 /* 32bits reglist. */
775 if ((value
& 0x7) > 1)
778 strcat (str
, csky_general_reg
[(value
& 0xf) + 15]);
788 case OPRND_TYPE_UNCOND10b
:
789 case OPRND_TYPE_UNCOND16b
:
790 case OPRND_TYPE_COND10b
:
791 case OPRND_TYPE_COND16b
:
793 int shift
= oprnd
->shift
;
795 if (value
& ((max
>> 1) + 1))
797 if (is_extern_symbol (dis_info
.info
, dis_info
.mem
))
800 value
= dis_info
.mem
+ (value
<< shift
);
801 sprintf (buf
, "0x%x", (unsigned int)value
);
803 dis_info
.need_output_symbol
= 1;
804 dis_info
.value
= value
;
816 csky_print_operand (char *str
, struct operand
const *oprnd
,
817 CSKY_INST_TYPE inst
, int reloc
)
822 if (oprnd
->mask
== HAS_SUB_OPERAND
)
824 struct soperand
*sop
= (struct soperand
*)oprnd
;
825 if (oprnd
->type
== OPRND_TYPE_BRACKET
)
830 else if (oprnd
->type
== OPRND_TYPE_ABRACKET
)
836 ret
= csky_print_operand (str
, &sop
->subs
[0], inst
, reloc
);
840 ret
= csky_print_operand (str
, &sop
->subs
[1], inst
, reloc
);
844 return csky_output_operand (str
, oprnd
, inst
, reloc
);
848 csky_print_operands (char *str
, struct csky_opcode_info
const *pinfo
,
849 struct disassemble_info
*info
, CSKY_INST_TYPE inst
,
854 if (pinfo
->operand_num
)
856 if (pinfo
->operand_num
== -1)
858 ret
= csky_print_operand (str
, &pinfo
->oprnd
.oprnds
[i
], inst
, reloc
);
863 for (; i
< pinfo
->operand_num
; i
++)
867 ret
= csky_print_operand (str
, &pinfo
->oprnd
.oprnds
[i
], inst
, reloc
);
871 info
->fprintf_func (info
->stream
, "%s", str
);
872 if (dis_info
.need_output_symbol
)
874 info
->fprintf_func (info
->stream
, "\t// ");
875 info
->print_address_func (dis_info
.value
, dis_info
.info
);
881 number_to_chars_littleendian (char *buf
, CSKY_INST_TYPE val
, int n
)
892 #define CSKY_READ_DATA() \
894 status = info->read_memory_func (memaddr, buf, 2, info); \
897 info->memory_error_func (status, memaddr, info); \
900 if (info->endian == BFD_ENDIAN_BIG) \
901 inst |= (buf[0] << 8) | buf[1]; \
902 else if (info->endian == BFD_ENDIAN_LITTLE) \
903 inst |= (buf[1] << 8) | buf[0]; \
906 info->bytes_per_chunk += 2; \
911 print_insn_csky (bfd_vma memaddr
, struct disassemble_info
*info
)
913 unsigned char buf
[4];
914 CSKY_INST_TYPE inst
= 0;
919 void (*printer
) (bfd_vma
, struct disassemble_info
*, long);
920 unsigned int size
= 4;
922 memset (str
, 0, sizeof (str
));
923 info
->bytes_per_chunk
= 0;
924 info
->bytes_per_chunk
= 0;
925 dis_info
.mem
= memaddr
;
926 dis_info
.info
= info
;
927 dis_info
.need_output_symbol
= 0;
928 if (mach_flag
!= INIT_MACH_FLAG
&& mach_flag
!= BINARY_MACH_FLAG
)
929 info
->mach
= mach_flag
;
930 else if (mach_flag
== INIT_MACH_FLAG
)
931 mach_flag
= info
->mach
;
933 if (mach_flag
== BINARY_MACH_FLAG
&& info
->endian
== BFD_ENDIAN_UNKNOWN
)
934 info
->endian
= BFD_ENDIAN_LITTLE
;
936 /* First check the full symtab for a mapping symbol, even if there
937 are no usable non-mapping symbols for this address. */
938 if (info
->symtab_size
!= 0
939 && bfd_asymbol_flavour (*info
->symtab
) == bfd_target_elf_flavour
)
944 enum sym_type type
= CUR_TEXT
;
946 if (memaddr
<= last_map_addr
)
948 /* Start scanning at the start of the function, or wherever
949 we finished last time. */
951 if (n
< last_map_sym
)
954 /* Scan up to the location being disassembled. */
955 for (; n
< info
->symtab_size
; n
++)
957 addr
= bfd_asymbol_value (info
->symtab
[n
]);
960 if ((info
->section
== NULL
961 || info
->section
== info
->symtab
[n
]->section
)
962 && get_sym_code_type (info
, n
, &type
))
965 last_map_sym
= last_sym
;
967 is_data
= (last_type
== CUR_DATA
);
970 size
= 4 - ( memaddr
& 3);
971 for (n
= last_sym
+ 1; n
< info
->symtab_size
; n
++)
973 addr
= bfd_asymbol_value (info
->symtab
[n
]);
976 if (addr
- memaddr
< size
)
977 size
= addr
- memaddr
;
981 /* If the next symbol is after three bytes, we need to
982 print only part of the data, so that we can use either
985 size
= (memaddr
& 1) ? 1 : 2;
988 info
->bytes_per_line
= 4;
994 /* Size was already set above. */
995 info
->bytes_per_chunk
= size
;
996 printer
= print_insn_data
;
998 status
= info
->read_memory_func (memaddr
, (bfd_byte
*) buf
, size
, info
);
1000 if (info
->endian
== BFD_ENDIAN_LITTLE
)
1001 for (i
= size
- 1; i
>= 0; i
--)
1002 given
= buf
[i
] | (given
<< 8);
1004 for (i
= 0; i
< (int) size
; i
++)
1005 given
= buf
[i
] | (given
<< 8);
1007 printer (memaddr
, info
, given
);
1008 return info
->bytes_per_chunk
;
1011 /* Handle instructions. */
1013 if ((inst
& 0xc000) == 0xc000 && IS_CSKY_V2 (mach_flag
))
1015 /* It's a 32-bit instruction. */
1018 if (info
->buffer
&& (info
->endian
== BFD_ENDIAN_LITTLE
))
1020 char* src
= (char *)(info
->buffer
1021 + ((memaddr
- 4 - info
->buffer_vma
)
1022 * info
->octets_per_byte
));
1023 if (info
->endian
== BFD_ENDIAN_LITTLE
)
1024 number_to_chars_littleendian (src
, inst
, 4);
1028 if (IS_CSKY_V1 (mach_flag
))
1029 g_opcodeP
= csky_v1_opcodes
;
1031 g_opcodeP
= csky_v2_opcodes
;
1035 struct csky_opcode
const *op
;
1036 struct csky_opcode_info
const *pinfo
= NULL
;
1039 memset (str
, 0, sizeof (str
));
1040 op
= csky_find_inst_info (&pinfo
, inst
, info
->bytes_per_chunk
);
1043 if (IS_CSKY_V1 (mach_flag
))
1044 info
->fprintf_func (info
->stream
, ".short: 0x%04x",
1045 (unsigned short)inst
);
1047 info
->fprintf_func (info
->stream
, ".long: 0x%08x",
1048 (unsigned int)inst
);
1049 return info
->bytes_per_chunk
;
1052 if (info
->bytes_per_chunk
== 2)
1053 reloc
= op
->reloc16
;
1055 reloc
= op
->reloc32
;
1056 dis_info
.opinfo
= pinfo
;
1057 strcat (str
, op
->mnemonic
);
1059 if (csky_print_operands (str
, pinfo
, info
, inst
, reloc
))
1065 return info
->bytes_per_chunk
;