2 Copyright (C) 1988-2018 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. */
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
)
142 if (dis_info
.info
->endian
== BFD_ENDIAN_BIG
)
144 val
|= buf
[n
] << (n
*8);
146 for (i
= 0; i
< n
; i
++)
147 val
|= buf
[i
] << (i
*8);
151 static struct csky_opcode
const *g_opcodeP
;
153 static struct csky_opcode
const *
154 csky_find_inst_info (struct csky_opcode_info
const **pinfo
,
155 CSKY_INST_TYPE inst
, int length
)
159 struct csky_opcode
const *p
;
164 /* Get the opcode mask. */
165 for (i
= 0; i
< OP_TABLE_NUM
; i
++)
168 mask
= csky_get_mask (&p
->op16
[i
]);
169 if (mask
!= 0 && (inst
& mask
) == p
->op16
[i
].opcode
)
171 *pinfo
= &p
->op16
[i
];
176 else if (length
== 4)
178 mask
= csky_get_mask (&p
->op32
[i
]);
180 && ((unsigned long)(inst
& mask
)
181 == (unsigned long)p
->op32
[i
].opcode
))
183 *pinfo
= &p
->op32
[i
];
195 is_extern_symbol (struct disassemble_info
*info
, int addr
)
197 unsigned int rel_count
= 0;
199 if (info
->section
== NULL
)
201 if ((info
->section
->flags
& SEC_RELOC
) != 0) /* Fit .o file. */
203 struct reloc_cache_entry
*pt
= info
->section
->relocation
;
204 for (; rel_count
< info
->section
->reloc_count
; rel_count
++, pt
++)
205 if ((long unsigned int)addr
== pt
->address
)
213 /* Suppress printing of mapping symbols emitted by the assembler to mark
214 the beginning of code and data sequences. */
217 csky_symbol_is_valid (asymbol
*sym
,
218 struct disassemble_info
*info ATTRIBUTE_UNUSED
)
224 name
= bfd_asymbol_name (sym
);
225 return name
&& *name
!= '$';
229 csky_get_disassembler (bfd
*abfd
)
232 mach_flag
= elf_elfheader (abfd
)->e_flags
;
233 return print_insn_csky
;
237 csky_output_operand (char *str
, struct operand
const *oprnd
,
238 CSKY_INST_TYPE inst
, int reloc ATTRIBUTE_UNUSED
)
244 int mask
= oprnd
->mask
;
248 /* Get operand value with mask. */
250 for (; mask
; mask
>>= 1, value
>>=1)
253 result
|= ((value
& 0x1) << bit
);
259 /* Here is general instructions that have no reloc. */
262 case OPRND_TYPE_CTRLREG
:
263 if (IS_CSKY_V1 (mach_flag
))
265 /* In V1 only cr0-cr12 have alias names. */
267 strcat (str
, csky_ctrl_regs
[value
].name
);
268 /* Others using crn(n > 12). */
269 else if (value
<= 30)
271 sprintf (buf
, "cr%d", (int)value
);
283 sprintf (buf
, "cr<%d, %d>", crx
, sel
);
287 case OPRND_TYPE_DUMMY_REG
:
288 mask
= dis_info
.opinfo
->oprnd
.oprnds
[0].mask
;
290 for (; mask
; mask
>>= 1, value
>>=1)
293 result
|= ((value
& 0x1) << bit
);
297 strcat (str
, csky_general_reg
[value
]);
299 case OPRND_TYPE_GREG0_7
:
300 case OPRND_TYPE_GREG0_15
:
301 case OPRND_TYPE_GREG16_31
:
302 case OPRND_TYPE_REGnsplr
:
303 case OPRND_TYPE_AREG
:
304 if (IS_CSKY_V2 (mach_flag
) && value
== 14)
307 strcat (str
, csky_general_reg
[value
]);
308 dis_info
.value
= value
;
310 case OPRND_TYPE_CPREG
:
311 strcat (str
, csky_cp_reg
[value
]);
313 case OPRND_TYPE_FREG
:
314 sprintf (buf
, "fr%d", (int)value
);
317 case OPRND_TYPE_VREG
:
318 sprintf (buf
, "vr%d", (int)value
);
321 case OPRND_TYPE_CPCREG
:
322 strcat (str
, csky_cp_creg
[value
]);
324 case OPRND_TYPE_CPIDX
:
325 strcat (str
, csky_cp_idx
[value
]);
327 case OPRND_TYPE_IMM2b_JMPIX
:
328 value
= (value
+ 2) << 3;
329 sprintf (buf
, "%d", (int)value
);
332 case OPRND_TYPE_IMM_LDST
:
333 case OPRND_TYPE_IMM_FLDST
:
334 value
<<= oprnd
->shift
;
335 sprintf (buf
, "0x%x", (unsigned int)value
);
338 case OPRND_TYPE_IMM7b_LS2
:
339 case OPRND_TYPE_IMM8b_LS2
:
340 sprintf (buf
, "%d", (int)(value
<< 2));
344 case OPRND_TYPE_IMM5b_BMASKI
:
345 if ((value
!= 0) && (value
> 31 || value
< 8))
350 sprintf (buf
, "%d", (int)value
);
354 case OPRND_TYPE_IMM5b_1_31
:
355 if (value
> 31 || value
< 1)
360 sprintf (buf
, "%d", (int)value
);
364 case OPRND_TYPE_IMM5b_7_31
:
365 if (value
> 31 || value
< 7)
370 sprintf (buf
, "%d", (int)value
);
374 case OPRND_TYPE_MSB2SIZE
:
375 case OPRND_TYPE_LSB2SIZE
:
378 if (oprnd
->type
== OPRND_TYPE_MSB2SIZE
)
382 str
[strlen (str
) - 2] = '\0';
383 sprintf (buf
, "%d, %d", (int)(size
+ value
), (int)value
);
388 case OPRND_TYPE_IMM1b
:
389 case OPRND_TYPE_IMM2b
:
390 case OPRND_TYPE_IMM4b
:
391 case OPRND_TYPE_IMM5b
:
392 case OPRND_TYPE_IMM7b
:
393 case OPRND_TYPE_IMM8b
:
394 case OPRND_TYPE_IMM12b
:
395 case OPRND_TYPE_IMM15b
:
396 case OPRND_TYPE_IMM16b
:
397 case OPRND_TYPE_IMM16b_MOVIH
:
398 case OPRND_TYPE_IMM16b_ORI
:
399 sprintf (buf
, "%d", (int)value
);
403 case OPRND_TYPE_OFF8b
:
404 case OPRND_TYPE_OFF16b
:
406 unsigned char ibytes
[4];
407 int shift
= oprnd
->shift
;
409 unsigned int mem_val
;
411 dis_info
.info
->stop_vma
= 0;
413 value
= ((dis_info
.mem
+ (value
<< shift
)
414 + ((IS_CSKY_V1 (mach_flag
)) ? 2 : 0))
416 status
= dis_info
.info
->read_memory_func (value
, ibytes
, 4,
420 dis_info
.info
->memory_error_func (status
, dis_info
.mem
,
424 mem_val
= csky_chars_to_number (ibytes
, 4);
425 /* Remove [] around literal value to match ABI syntax. */
426 sprintf (buf
, "0x%X", mem_val
);
428 /* For jmpi/jsri, we'll try to get a symbol for the target. */
429 if (dis_info
.info
->print_address_func
&& mem_val
!= 0)
431 dis_info
.value
= mem_val
;
432 dis_info
.need_output_symbol
= 1;
436 sprintf (buf
, "\t// from address pool at 0x%x",
437 (unsigned int)value
);
442 case OPRND_TYPE_BLOOP_OFF4b
:
443 case OPRND_TYPE_BLOOP_OFF12b
:
444 case OPRND_TYPE_OFF11b
:
445 case OPRND_TYPE_OFF16b_LSL1
:
446 case OPRND_TYPE_IMM_OFF18b
:
447 case OPRND_TYPE_OFF26b
:
449 int shift
= oprnd
->shift
;
450 if (value
& ((max
>> 1) + 1))
452 if (is_extern_symbol (dis_info
.info
, dis_info
.mem
))
454 else if (IS_CSKY_V1 (mach_flag
))
455 value
= dis_info
.mem
+ 2 + (value
<< shift
);
457 value
= dis_info
.mem
+ (value
<< shift
);
458 dis_info
.need_output_symbol
= 1;
459 dis_info
.value
= value
;
460 sprintf (buf
, "0x%x", (unsigned int)value
);
464 case OPRND_TYPE_CONSTANT
:
465 case OPRND_TYPE_FCONSTANT
:
467 int shift
= oprnd
->shift
;
473 dis_info
.info
->stop_vma
= 0;
476 if (IS_CSKY_V1 (mach_flag
))
477 addr
= (dis_info
.mem
+ 2 + value
) & 0xfffffffc;
479 addr
= (dis_info
.mem
+ value
) & 0xfffffffc;
481 if (oprnd
->type
== OPRND_TYPE_FCONSTANT
482 && dis_info
.opinfo
->opcode
!= CSKYV2_INST_FLRW
)
487 status
= dis_info
.info
->read_memory_func (addr
, (bfd_byte
*)ibytes
,
488 nbytes
, dis_info
.info
);
490 /* Address out of bounds. -> lrw rx, [pc, 0ffset]. */
491 sprintf (buf
, "[pc, %d]\t// from address pool at %x", (int)value
,
495 dis_info
.value
= addr
;
496 value
= csky_chars_to_number ((unsigned char *)ibytes
, 4);
499 if (oprnd
->type
== OPRND_TYPE_FCONSTANT
)
503 if (dis_info
.opinfo
->opcode
== CSKYV2_INST_FLRW
)
505 floatformat_to_double ((dis_info
.info
->endian
== BFD_ENDIAN_BIG
506 ? &floatformat_ieee_single_big
507 : &floatformat_ieee_single_little
),
510 floatformat_to_double ((dis_info
.info
->endian
== BFD_ENDIAN_BIG
511 ? &floatformat_ieee_double_big
512 : &floatformat_ieee_double_little
),
514 sprintf (buf
, "%f", f
);
518 dis_info
.need_output_symbol
= 1;
519 sprintf (buf
, "0x%x", (unsigned int)value
);
525 case OPRND_TYPE_ELRW_CONSTANT
:
527 int shift
= oprnd
->shift
;
531 dis_info
.info
->stop_vma
= 0;
533 value
= 0x80 + ((~value
) & 0x7f);
535 value
= value
<< shift
;
536 addr
= (dis_info
.mem
+ value
) & 0xfffffffc;
538 status
= dis_info
.info
->read_memory_func (addr
, (bfd_byte
*)ibytes
,
541 /* Address out of bounds. -> lrw rx, [pc, 0ffset]. */
542 sprintf (buf
, "[pc, %d]\t// from address pool at %x", (int) value
,
546 dis_info
.value
= addr
;
547 value
= csky_chars_to_number ((unsigned char *)ibytes
, 4);
548 dis_info
.need_output_symbol
= 1;
549 sprintf (buf
, "0x%x", (unsigned int)value
);
555 case OPRND_TYPE_SFLOAT
:
556 case OPRND_TYPE_DFLOAT
:
558 /* This is for fmovis/fmovid, which have an internal 13-bit
559 encoding that they convert to single/double precision
560 (respectively). We'll convert the 13-bit encoding to an IEEE
561 double and then to host double format to print it.
563 4-bit exponent: bits 19:16, biased by 11.
564 8-bit mantissa: split between 24:21 and 7:4. */
568 unsigned char valbytes
[8];
571 imm4
= ((inst
>> 16) & 0xf);
572 imm4
= (uint64_t)(1023 - (imm4
- 11)) << 52;
574 imm8
= (uint64_t)((inst
>> 4) & 0xf) << 44;
575 imm8
|= (uint64_t)((inst
>> 21) & 0xf) << 48;
577 dbnum
= (uint64_t)((inst
>> 20) & 1) << 63;
578 dbnum
|= imm4
| imm8
;
580 /* Do this a byte at a time so we don't have to
581 worry about the host's endianness. */
582 valbytes
[0] = dbnum
& 0xff;
583 valbytes
[1] = (dbnum
>> 8) & 0xff;
584 valbytes
[2] = (dbnum
>> 16) & 0xff;
585 valbytes
[3] = (dbnum
>> 24) & 0xff;
586 valbytes
[4] = (dbnum
>> 32) & 0xff;
587 valbytes
[5] = (dbnum
>> 40) & 0xff;
588 valbytes
[6] = (dbnum
>> 48) & 0xff;
589 valbytes
[7] = (dbnum
>> 56) & 0xff;
591 floatformat_to_double (&floatformat_ieee_double_little
, valbytes
,
594 sprintf (buf
, "%f", fvalue
);
598 case OPRND_TYPE_LABEL_WITH_BRACKET
:
599 sprintf (buf
, "[0x%x]", (unsigned int)value
);
601 strcat (str
, "\t// the offset is based on .data");
603 case OPRND_TYPE_OIMM3b
:
604 case OPRND_TYPE_OIMM4b
:
605 case OPRND_TYPE_OIMM5b
:
606 case OPRND_TYPE_OIMM5b_IDLY
:
607 case OPRND_TYPE_OIMM8b
:
608 case OPRND_TYPE_OIMM12b
:
609 case OPRND_TYPE_OIMM16b
:
610 case OPRND_TYPE_OIMM18b
:
612 sprintf (buf
, "%d", (int)value
);
615 case OPRND_TYPE_OIMM5b_BMASKI
:
616 if (value
> 32 || value
< 16)
621 sprintf (buf
, "%d", (int)(value
+ 1));
625 case OPRND_TYPE_FREGLIST_DASH
:
626 if (IS_CSKY_V2 (mach_flag
))
628 int vrx
= value
& 0xf;
629 int vry
= vrx
+ (value
>> 4);
630 sprintf (buf
, "fr%d-fr%d", vrx
, vry
);
634 case OPRND_TYPE_REGLIST_DASH
:
635 if (IS_CSKY_V1 (mach_flag
))
637 strcat (str
, csky_general_reg
[value
]);
638 strcat (str
, "-r15");
642 strcat (str
, csky_general_reg
[value
>> 5]);
644 strcat (str
, csky_general_reg
[(value
& 0x1f) + (value
>> 5)]);
647 case OPRND_TYPE_PSR_BITS_LIST
:
649 struct psrbit
const *bits
;
650 int first_oprnd
= TRUE
;
652 if (IS_CSKY_V1 (mach_flag
))
659 bits
= cskyv1_psr_bits
;
662 bits
= cskyv2_psr_bits
;
663 while (value
!= 0 && bits
[i
].name
!= NULL
)
665 if (value
& bits
[i
].value
)
669 strcat (str
, bits
[i
].name
);
670 value
&= ~bits
[i
].value
;
677 case OPRND_TYPE_REGbsp
:
678 if (IS_CSKY_V1 (mach_flag
))
679 strcat (str
, "(sp)");
681 strcat (str
, "(sp)");
683 case OPRND_TYPE_REGsp
:
684 if (IS_CSKY_V1 (mach_flag
))
689 case OPRND_TYPE_REGnr4_r7
:
690 case OPRND_TYPE_AREG_WITH_BRACKET
:
691 if (IS_CSKY_V1 (mach_flag
) && (value
< 4 || value
> 7))
694 strcat (str
, csky_general_reg
[value
]);
700 strcat (str
, csky_general_reg
[value
]);
704 case OPRND_TYPE_AREG_WITH_LSHIFT
:
705 strcat (str
, csky_general_reg
[value
>> 5]);
706 strcat (str
, " << ");
707 if ((value
& 0x1f) == 0x1)
709 else if ((value
& 0x1f) == 0x2)
711 else if ((value
& 0x1f) == 0x4)
713 else if ((value
& 0x1f) == 0x8)
716 case OPRND_TYPE_AREG_WITH_LSHIFT_FPU
:
717 strcat (str
, csky_general_reg
[value
>> 2]);
718 strcat (str
, " << ");
719 if ((value
& 0x3) == 0x0)
721 else if ((value
& 0x3) == 0x1)
723 else if ((value
& 0x3) == 0x2)
725 else if ((value
& 0x3) == 0x3)
728 case OPRND_TYPE_FREG_WITH_INDEX
:
730 unsigned freg_val
= value
& 0xf;
731 unsigned index_val
= (value
>> 4) & 0xf;
732 sprintf (buf
, "vr%d[%d]", freg_val
, index_val
);
736 case OPRND_TYPE_REGr4_r7
:
737 if (IS_CSKY_V1 (mach_flag
))
738 strcat (str
, "r4-r7");
740 case OPRND_TYPE_CONST1
:
743 case OPRND_TYPE_REG_r1a
:
744 case OPRND_TYPE_REG_r1b
:
747 case OPRND_TYPE_REG_r28
:
750 case OPRND_TYPE_REGLIST_DASH_COMMA
:
751 /* 16-bit reglist. */
755 if ((value
& 0xf) > 1)
758 strcat (str
, csky_general_reg
[(value
& 0xf) + 3]);
770 if (dis_info
.opinfo
->oprnd
.oprnds
[0].mask
!= OPRND_MASK_0_4
)
772 /* 32bits reglist. */
777 if ((value
& 0x7) > 1)
780 strcat (str
, csky_general_reg
[(value
& 0xf) + 15]);
790 case OPRND_TYPE_UNCOND10b
:
791 case OPRND_TYPE_UNCOND16b
:
792 case OPRND_TYPE_COND10b
:
793 case OPRND_TYPE_COND16b
:
795 int shift
= oprnd
->shift
;
797 if (value
& ((max
>> 1) + 1))
799 if (is_extern_symbol (dis_info
.info
, dis_info
.mem
))
802 value
= dis_info
.mem
+ (value
<< shift
);
803 sprintf (buf
, "0x%x", (unsigned int)value
);
805 dis_info
.need_output_symbol
= 1;
806 dis_info
.value
= value
;
818 csky_print_operand (char *str
, struct operand
const *oprnd
,
819 CSKY_INST_TYPE inst
, int reloc
)
824 if (oprnd
->mask
== HAS_SUB_OPERAND
)
826 struct soperand
*sop
= (struct soperand
*)oprnd
;
827 if (oprnd
->type
== OPRND_TYPE_BRACKET
)
832 else if (oprnd
->type
== OPRND_TYPE_ABRACKET
)
838 ret
= csky_print_operand (str
, &sop
->subs
[0], inst
, reloc
);
842 ret
= csky_print_operand (str
, &sop
->subs
[1], inst
, reloc
);
846 return csky_output_operand (str
, oprnd
, inst
, reloc
);
850 csky_print_operands (char *str
, struct csky_opcode_info
const *pinfo
,
851 struct disassemble_info
*info
, CSKY_INST_TYPE inst
,
856 if (pinfo
->operand_num
)
858 if (pinfo
->operand_num
== -1)
860 ret
= csky_print_operand (str
, &pinfo
->oprnd
.oprnds
[i
], inst
, reloc
);
865 for (; i
< pinfo
->operand_num
; i
++)
869 ret
= csky_print_operand (str
, &pinfo
->oprnd
.oprnds
[i
], inst
, reloc
);
873 info
->fprintf_func (info
->stream
, "%s", str
);
874 if (dis_info
.need_output_symbol
)
876 info
->fprintf_func (info
->stream
, "\t// ");
877 info
->print_address_func (dis_info
.value
, dis_info
.info
);
883 number_to_chars_littleendian (char *buf
, CSKY_INST_TYPE val
, int n
)
894 #define CSKY_READ_DATA() \
896 status = info->read_memory_func (memaddr, buf, 2, info); \
899 info->memory_error_func (status, memaddr, info); \
902 if (info->endian == BFD_ENDIAN_BIG) \
903 inst |= (buf[0] << 8) | buf[1]; \
904 else if (info->endian == BFD_ENDIAN_LITTLE) \
905 inst |= (buf[1] << 8) | buf[0]; \
908 info->bytes_per_chunk += 2; \
913 print_insn_csky (bfd_vma memaddr
, struct disassemble_info
*info
)
915 unsigned char buf
[4];
916 CSKY_INST_TYPE inst
= 0;
921 void (*printer
) (bfd_vma
, struct disassemble_info
*, long);
922 unsigned int size
= 4;
924 memset (str
, 0, sizeof (str
));
925 info
->bytes_per_chunk
= 0;
926 info
->bytes_per_chunk
= 0;
927 dis_info
.mem
= memaddr
;
928 dis_info
.info
= info
;
929 dis_info
.need_output_symbol
= 0;
930 if (mach_flag
!= INIT_MACH_FLAG
&& mach_flag
!= BINARY_MACH_FLAG
)
931 info
->mach
= mach_flag
;
932 else if (mach_flag
== INIT_MACH_FLAG
)
933 mach_flag
= info
->mach
;
935 if (mach_flag
== BINARY_MACH_FLAG
&& info
->endian
== BFD_ENDIAN_UNKNOWN
)
936 info
->endian
= BFD_ENDIAN_LITTLE
;
938 /* First check the full symtab for a mapping symbol, even if there
939 are no usable non-mapping symbols for this address. */
940 if (info
->symtab_size
!= 0
941 && bfd_asymbol_flavour (*info
->symtab
) == bfd_target_elf_flavour
)
946 enum sym_type type
= CUR_TEXT
;
948 if (memaddr
<= last_map_addr
)
950 /* Start scanning at the start of the function, or wherever
951 we finished last time. */
953 if (n
< last_map_sym
)
956 /* Scan up to the location being disassembled. */
957 for (; n
< info
->symtab_size
; n
++)
959 addr
= bfd_asymbol_value (info
->symtab
[n
]);
962 if ((info
->section
== NULL
963 || info
->section
== info
->symtab
[n
]->section
)
964 && get_sym_code_type (info
, n
, &type
))
967 last_map_sym
= last_sym
;
969 is_data
= (last_type
== CUR_DATA
);
972 size
= 4 - ( memaddr
& 3);
973 for (n
= last_sym
+ 1; n
< info
->symtab_size
; n
++)
975 addr
= bfd_asymbol_value (info
->symtab
[n
]);
978 if (addr
- memaddr
< size
)
979 size
= addr
- memaddr
;
983 /* If the next symbol is after three bytes, we need to
984 print only part of the data, so that we can use either
987 size
= (memaddr
& 1) ? 1 : 2;
990 info
->bytes_per_line
= 4;
996 /* Size was already set above. */
997 info
->bytes_per_chunk
= size
;
998 printer
= print_insn_data
;
1000 status
= info
->read_memory_func (memaddr
, (bfd_byte
*) buf
, size
, info
);
1002 if (info
->endian
== BFD_ENDIAN_LITTLE
)
1003 for (i
= size
- 1; i
>= 0; i
--)
1004 given
= buf
[i
] | (given
<< 8);
1006 for (i
= 0; i
< (int) size
; i
++)
1007 given
= buf
[i
] | (given
<< 8);
1009 printer (memaddr
, info
, given
);
1010 return info
->bytes_per_chunk
;
1013 /* Handle instructions. */
1015 if ((inst
& 0xc000) == 0xc000 && IS_CSKY_V2 (mach_flag
))
1017 /* It's a 32-bit instruction. */
1020 if (info
->buffer
&& (info
->endian
== BFD_ENDIAN_LITTLE
))
1022 char* src
= (char *)(info
->buffer
1023 + ((memaddr
- 4 - info
->buffer_vma
)
1024 * info
->octets_per_byte
));
1025 if (info
->endian
== BFD_ENDIAN_LITTLE
)
1026 number_to_chars_littleendian (src
, inst
, 4);
1030 if (IS_CSKY_V1 (mach_flag
))
1031 g_opcodeP
= csky_v1_opcodes
;
1033 g_opcodeP
= csky_v2_opcodes
;
1037 struct csky_opcode
const *op
;
1038 struct csky_opcode_info
const *pinfo
= NULL
;
1041 memset (str
, 0, sizeof (str
));
1042 op
= csky_find_inst_info (&pinfo
, inst
, info
->bytes_per_chunk
);
1045 if (IS_CSKY_V1 (mach_flag
))
1046 info
->fprintf_func (info
->stream
, ".short: 0x%04x",
1047 (unsigned short)inst
);
1049 info
->fprintf_func (info
->stream
, ".long: 0x%08x",
1050 (unsigned int)inst
);
1051 return info
->bytes_per_chunk
;
1054 if (info
->bytes_per_chunk
== 2)
1055 reloc
= op
->reloc16
;
1057 reloc
= op
->reloc32
;
1058 dis_info
.opinfo
= pinfo
;
1059 strcat (str
, op
->mnemonic
);
1061 if (csky_print_operands (str
, pinfo
, info
, inst
, reloc
))
1067 return info
->bytes_per_chunk
;