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 /* FIXME: Skip 860's instruction in other CPUs. It is not suitable.
163 These codes need to be optimized. */
164 if (((CSKY_ARCH_MASK
& mach_flag
) != CSKY_ARCH_860
)
165 && (p
->isa_flag32
& CSKYV2_ISA_10E60
))
171 /* Get the opcode mask. */
172 for (i
= 0; i
< OP_TABLE_NUM
; i
++)
175 mask
= csky_get_mask (&p
->op16
[i
]);
176 if (mask
!= 0 && (inst
& mask
) == p
->op16
[i
].opcode
)
178 *pinfo
= &p
->op16
[i
];
183 else if (length
== 4)
185 mask
= csky_get_mask (&p
->op32
[i
]);
187 && ((unsigned long)(inst
& mask
)
188 == (unsigned long)p
->op32
[i
].opcode
))
190 *pinfo
= &p
->op32
[i
];
202 is_extern_symbol (struct disassemble_info
*info
, int addr
)
204 unsigned int rel_count
= 0;
206 if (info
->section
== NULL
)
208 if ((info
->section
->flags
& SEC_RELOC
) != 0) /* Fit .o file. */
210 struct reloc_cache_entry
*pt
= info
->section
->relocation
;
211 for (; rel_count
< info
->section
->reloc_count
; rel_count
++, pt
++)
212 if ((long unsigned int)addr
== pt
->address
)
220 /* Suppress printing of mapping symbols emitted by the assembler to mark
221 the beginning of code and data sequences. */
224 csky_symbol_is_valid (asymbol
*sym
,
225 struct disassemble_info
*info ATTRIBUTE_UNUSED
)
231 name
= bfd_asymbol_name (sym
);
232 return name
&& *name
!= '$';
236 csky_get_disassembler (bfd
*abfd
)
239 mach_flag
= elf_elfheader (abfd
)->e_flags
;
240 return print_insn_csky
;
244 csky_output_operand (char *str
, struct operand
const *oprnd
,
245 CSKY_INST_TYPE inst
, int reloc ATTRIBUTE_UNUSED
)
251 int mask
= oprnd
->mask
;
255 /* Get operand value with mask. */
257 for (; mask
; mask
>>= 1, value
>>=1)
260 result
|= ((value
& 0x1) << bit
);
266 /* Here is general instructions that have no reloc. */
269 case OPRND_TYPE_CTRLREG
:
270 if (IS_CSKY_V1 (mach_flag
))
272 /* In V1 only cr0-cr12 have alias names. */
274 strcat (str
, csky_ctrl_regs
[value
].name
);
275 /* Others using crn(n > 12). */
276 else if (value
<= 30)
278 sprintf (buf
, "cr%d", (int)value
);
290 sprintf (buf
, "cr<%d, %d>", crx
, sel
);
294 case OPRND_TYPE_DUMMY_REG
:
295 mask
= dis_info
.opinfo
->oprnd
.oprnds
[0].mask
;
297 for (; mask
; mask
>>= 1, value
>>=1)
300 result
|= ((value
& 0x1) << bit
);
304 strcat (str
, csky_general_reg
[value
]);
306 case OPRND_TYPE_GREG0_7
:
307 case OPRND_TYPE_GREG0_15
:
308 case OPRND_TYPE_GREG16_31
:
309 case OPRND_TYPE_REGnsplr
:
310 case OPRND_TYPE_AREG
:
311 if (IS_CSKY_V2 (mach_flag
) && value
== 14)
314 strcat (str
, csky_general_reg
[value
]);
315 dis_info
.value
= value
;
317 case OPRND_TYPE_CPREG
:
318 strcat (str
, csky_cp_reg
[value
]);
320 case OPRND_TYPE_FREG
:
321 sprintf (buf
, "fr%d", (int)value
);
324 case OPRND_TYPE_VREG
:
325 sprintf (buf
, "vr%d", (int)value
);
328 case OPRND_TYPE_CPCREG
:
329 strcat (str
, csky_cp_creg
[value
]);
331 case OPRND_TYPE_CPIDX
:
332 strcat (str
, csky_cp_idx
[value
]);
334 case OPRND_TYPE_IMM2b_JMPIX
:
335 value
= (value
+ 2) << 3;
336 sprintf (buf
, "%d", (int)value
);
339 case OPRND_TYPE_IMM_LDST
:
340 case OPRND_TYPE_IMM_FLDST
:
341 value
<<= oprnd
->shift
;
342 sprintf (buf
, "0x%x", (unsigned int)value
);
345 case OPRND_TYPE_IMM7b_LS2
:
346 case OPRND_TYPE_IMM8b_LS2
:
347 sprintf (buf
, "%d", (int)(value
<< 2));
351 case OPRND_TYPE_IMM5b_BMASKI
:
352 if ((value
!= 0) && (value
> 31 || value
< 8))
357 sprintf (buf
, "%d", (int)value
);
361 case OPRND_TYPE_IMM5b_1_31
:
362 if (value
> 31 || value
< 1)
367 sprintf (buf
, "%d", (int)value
);
371 case OPRND_TYPE_IMM5b_7_31
:
372 if (value
> 31 || value
< 7)
377 sprintf (buf
, "%d", (int)value
);
381 case OPRND_TYPE_MSB2SIZE
:
382 case OPRND_TYPE_LSB2SIZE
:
385 if (oprnd
->type
== OPRND_TYPE_MSB2SIZE
)
389 str
[strlen (str
) - 2] = '\0';
390 sprintf (buf
, "%d, %d", (int)(size
+ value
), (int)value
);
395 case OPRND_TYPE_IMM1b
:
396 case OPRND_TYPE_IMM2b
:
397 case OPRND_TYPE_IMM4b
:
398 case OPRND_TYPE_IMM5b
:
399 case OPRND_TYPE_IMM7b
:
400 case OPRND_TYPE_IMM8b
:
401 case OPRND_TYPE_IMM12b
:
402 case OPRND_TYPE_IMM15b
:
403 case OPRND_TYPE_IMM16b
:
404 case OPRND_TYPE_IMM16b_MOVIH
:
405 case OPRND_TYPE_IMM16b_ORI
:
406 sprintf (buf
, "%d", (int)value
);
410 case OPRND_TYPE_OFF8b
:
411 case OPRND_TYPE_OFF16b
:
413 unsigned char ibytes
[4];
414 int shift
= oprnd
->shift
;
416 unsigned int mem_val
;
418 dis_info
.info
->stop_vma
= 0;
420 value
= ((dis_info
.mem
+ (value
<< shift
)
421 + ((IS_CSKY_V1 (mach_flag
)) ? 2 : 0))
423 status
= dis_info
.info
->read_memory_func (value
, ibytes
, 4,
427 dis_info
.info
->memory_error_func (status
, dis_info
.mem
,
431 mem_val
= csky_chars_to_number (ibytes
, 4);
432 /* Remove [] around literal value to match ABI syntax. */
433 sprintf (buf
, "0x%X", mem_val
);
435 /* For jmpi/jsri, we'll try to get a symbol for the target. */
436 if (dis_info
.info
->print_address_func
&& mem_val
!= 0)
438 dis_info
.value
= mem_val
;
439 dis_info
.need_output_symbol
= 1;
443 sprintf (buf
, "\t// from address pool at 0x%x",
444 (unsigned int)value
);
449 case OPRND_TYPE_BLOOP_OFF4b
:
450 case OPRND_TYPE_BLOOP_OFF12b
:
451 case OPRND_TYPE_OFF11b
:
452 case OPRND_TYPE_OFF16b_LSL1
:
453 case OPRND_TYPE_IMM_OFF18b
:
454 case OPRND_TYPE_OFF26b
:
456 int shift
= oprnd
->shift
;
457 if (value
& ((max
>> 1) + 1))
459 if (is_extern_symbol (dis_info
.info
, dis_info
.mem
))
461 else if (IS_CSKY_V1 (mach_flag
))
462 value
= dis_info
.mem
+ 2 + (value
<< shift
);
464 value
= dis_info
.mem
+ (value
<< shift
);
465 dis_info
.need_output_symbol
= 1;
466 dis_info
.value
= value
;
467 sprintf (buf
, "0x%x", (unsigned int)value
);
471 case OPRND_TYPE_CONSTANT
:
472 case OPRND_TYPE_FCONSTANT
:
474 int shift
= oprnd
->shift
;
480 dis_info
.info
->stop_vma
= 0;
483 if (IS_CSKY_V1 (mach_flag
))
484 addr
= (dis_info
.mem
+ 2 + value
) & 0xfffffffc;
486 addr
= (dis_info
.mem
+ value
) & 0xfffffffc;
488 if (oprnd
->type
== OPRND_TYPE_FCONSTANT
489 && dis_info
.opinfo
->opcode
!= CSKYV2_INST_FLRW
)
494 status
= dis_info
.info
->read_memory_func (addr
, (bfd_byte
*)ibytes
,
495 nbytes
, dis_info
.info
);
497 /* Address out of bounds. -> lrw rx, [pc, 0ffset]. */
498 sprintf (buf
, "[pc, %d]\t// from address pool at %x", (int)value
,
502 dis_info
.value
= addr
;
503 value
= csky_chars_to_number ((unsigned char *)ibytes
, 4);
506 if (oprnd
->type
== OPRND_TYPE_FCONSTANT
)
510 if (dis_info
.opinfo
->opcode
== CSKYV2_INST_FLRW
)
512 floatformat_to_double ((dis_info
.info
->endian
== BFD_ENDIAN_BIG
513 ? &floatformat_ieee_single_big
514 : &floatformat_ieee_single_little
),
517 floatformat_to_double ((dis_info
.info
->endian
== BFD_ENDIAN_BIG
518 ? &floatformat_ieee_double_big
519 : &floatformat_ieee_double_little
),
521 sprintf (buf
, "%f", f
);
525 dis_info
.need_output_symbol
= 1;
526 sprintf (buf
, "0x%x", (unsigned int)value
);
532 case OPRND_TYPE_ELRW_CONSTANT
:
534 int shift
= oprnd
->shift
;
538 dis_info
.info
->stop_vma
= 0;
540 value
= 0x80 + ((~value
) & 0x7f);
542 value
= value
<< shift
;
543 addr
= (dis_info
.mem
+ value
) & 0xfffffffc;
545 status
= dis_info
.info
->read_memory_func (addr
, (bfd_byte
*)ibytes
,
548 /* Address out of bounds. -> lrw rx, [pc, 0ffset]. */
549 sprintf (buf
, "[pc, %d]\t// from address pool at %x", (int) value
,
553 dis_info
.value
= addr
;
554 value
= csky_chars_to_number ((unsigned char *)ibytes
, 4);
555 dis_info
.need_output_symbol
= 1;
556 sprintf (buf
, "0x%x", (unsigned int)value
);
562 case OPRND_TYPE_SFLOAT
:
563 case OPRND_TYPE_DFLOAT
:
565 /* This is for fmovis/fmovid, which have an internal 13-bit
566 encoding that they convert to single/double precision
567 (respectively). We'll convert the 13-bit encoding to an IEEE
568 double and then to host double format to print it.
570 4-bit exponent: bits 19:16, biased by 11.
571 8-bit mantissa: split between 24:21 and 7:4. */
575 unsigned char valbytes
[8];
578 imm4
= ((inst
>> 16) & 0xf);
579 imm4
= (uint64_t)(1023 - (imm4
- 11)) << 52;
581 imm8
= (uint64_t)((inst
>> 4) & 0xf) << 44;
582 imm8
|= (uint64_t)((inst
>> 21) & 0xf) << 48;
584 dbnum
= (uint64_t)((inst
>> 20) & 1) << 63;
585 dbnum
|= imm4
| imm8
;
587 /* Do this a byte at a time so we don't have to
588 worry about the host's endianness. */
589 valbytes
[0] = dbnum
& 0xff;
590 valbytes
[1] = (dbnum
>> 8) & 0xff;
591 valbytes
[2] = (dbnum
>> 16) & 0xff;
592 valbytes
[3] = (dbnum
>> 24) & 0xff;
593 valbytes
[4] = (dbnum
>> 32) & 0xff;
594 valbytes
[5] = (dbnum
>> 40) & 0xff;
595 valbytes
[6] = (dbnum
>> 48) & 0xff;
596 valbytes
[7] = (dbnum
>> 56) & 0xff;
598 floatformat_to_double (&floatformat_ieee_double_little
, valbytes
,
601 sprintf (buf
, "%f", fvalue
);
605 case OPRND_TYPE_LABEL_WITH_BRACKET
:
606 sprintf (buf
, "[0x%x]", (unsigned int)value
);
608 strcat (str
, "\t// the offset is based on .data");
610 case OPRND_TYPE_OIMM3b
:
611 case OPRND_TYPE_OIMM4b
:
612 case OPRND_TYPE_OIMM5b
:
613 case OPRND_TYPE_OIMM5b_IDLY
:
614 case OPRND_TYPE_OIMM8b
:
615 case OPRND_TYPE_OIMM12b
:
616 case OPRND_TYPE_OIMM16b
:
617 case OPRND_TYPE_OIMM18b
:
619 sprintf (buf
, "%d", (int)value
);
622 case OPRND_TYPE_OIMM5b_BMASKI
:
623 if (value
> 32 || value
< 16)
628 sprintf (buf
, "%d", (int)(value
+ 1));
632 case OPRND_TYPE_FREGLIST_DASH
:
633 if (IS_CSKY_V2 (mach_flag
))
635 int vrx
= value
& 0xf;
636 int vry
= vrx
+ (value
>> 4);
637 sprintf (buf
, "fr%d-fr%d", vrx
, vry
);
641 case OPRND_TYPE_REGLIST_DASH
:
642 if (IS_CSKY_V1 (mach_flag
))
644 strcat (str
, csky_general_reg
[value
]);
645 strcat (str
, "-r15");
649 strcat (str
, csky_general_reg
[value
>> 5]);
651 strcat (str
, csky_general_reg
[(value
& 0x1f) + (value
>> 5)]);
654 case OPRND_TYPE_PSR_BITS_LIST
:
656 struct psrbit
const *bits
;
657 int first_oprnd
= TRUE
;
659 if (IS_CSKY_V1 (mach_flag
))
666 bits
= cskyv1_psr_bits
;
669 bits
= cskyv2_psr_bits
;
670 while (value
!= 0 && bits
[i
].name
!= NULL
)
672 if (value
& bits
[i
].value
)
676 strcat (str
, bits
[i
].name
);
677 value
&= ~bits
[i
].value
;
684 case OPRND_TYPE_REGbsp
:
685 if (IS_CSKY_V1 (mach_flag
))
686 strcat (str
, "(sp)");
688 strcat (str
, "(sp)");
690 case OPRND_TYPE_REGsp
:
691 if (IS_CSKY_V1 (mach_flag
))
696 case OPRND_TYPE_REGnr4_r7
:
697 case OPRND_TYPE_AREG_WITH_BRACKET
:
698 if (IS_CSKY_V1 (mach_flag
) && (value
< 4 || value
> 7))
701 strcat (str
, csky_general_reg
[value
]);
707 strcat (str
, csky_general_reg
[value
]);
711 case OPRND_TYPE_AREG_WITH_LSHIFT
:
712 strcat (str
, csky_general_reg
[value
>> 5]);
713 strcat (str
, " << ");
714 if ((value
& 0x1f) == 0x1)
716 else if ((value
& 0x1f) == 0x2)
718 else if ((value
& 0x1f) == 0x4)
720 else if ((value
& 0x1f) == 0x8)
723 case OPRND_TYPE_AREG_WITH_LSHIFT_FPU
:
724 strcat (str
, csky_general_reg
[value
>> 2]);
725 strcat (str
, " << ");
726 if ((value
& 0x3) == 0x0)
728 else if ((value
& 0x3) == 0x1)
730 else if ((value
& 0x3) == 0x2)
732 else if ((value
& 0x3) == 0x3)
735 case OPRND_TYPE_FREG_WITH_INDEX
:
737 unsigned freg_val
= value
& 0xf;
738 unsigned index_val
= (value
>> 4) & 0xf;
739 sprintf (buf
, "vr%d[%d]", freg_val
, index_val
);
743 case OPRND_TYPE_REGr4_r7
:
744 if (IS_CSKY_V1 (mach_flag
))
745 strcat (str
, "r4-r7");
747 case OPRND_TYPE_CONST1
:
750 case OPRND_TYPE_REG_r1a
:
751 case OPRND_TYPE_REG_r1b
:
754 case OPRND_TYPE_REG_r28
:
757 case OPRND_TYPE_REGLIST_DASH_COMMA
:
758 /* 16-bit reglist. */
762 if ((value
& 0xf) > 1)
765 strcat (str
, csky_general_reg
[(value
& 0xf) + 3]);
777 if (dis_info
.opinfo
->oprnd
.oprnds
[0].mask
!= OPRND_MASK_0_4
)
779 /* 32bits reglist. */
784 if ((value
& 0x7) > 1)
787 strcat (str
, csky_general_reg
[(value
& 0xf) + 15]);
797 case OPRND_TYPE_UNCOND10b
:
798 case OPRND_TYPE_UNCOND16b
:
799 case OPRND_TYPE_COND10b
:
800 case OPRND_TYPE_COND16b
:
802 int shift
= oprnd
->shift
;
804 if (value
& ((max
>> 1) + 1))
806 if (is_extern_symbol (dis_info
.info
, dis_info
.mem
))
809 value
= dis_info
.mem
+ (value
<< shift
);
810 sprintf (buf
, "0x%x", (unsigned int)value
);
812 dis_info
.need_output_symbol
= 1;
813 dis_info
.value
= value
;
825 csky_print_operand (char *str
, struct operand
const *oprnd
,
826 CSKY_INST_TYPE inst
, int reloc
)
831 if (oprnd
->mask
== HAS_SUB_OPERAND
)
833 struct soperand
*sop
= (struct soperand
*)oprnd
;
834 if (oprnd
->type
== OPRND_TYPE_BRACKET
)
839 else if (oprnd
->type
== OPRND_TYPE_ABRACKET
)
845 ret
= csky_print_operand (str
, &sop
->subs
[0], inst
, reloc
);
849 ret
= csky_print_operand (str
, &sop
->subs
[1], inst
, reloc
);
853 return csky_output_operand (str
, oprnd
, inst
, reloc
);
857 csky_print_operands (char *str
, struct csky_opcode_info
const *pinfo
,
858 struct disassemble_info
*info
, CSKY_INST_TYPE inst
,
863 if (pinfo
->operand_num
)
865 if (pinfo
->operand_num
== -1)
867 ret
= csky_print_operand (str
, &pinfo
->oprnd
.oprnds
[i
], inst
, reloc
);
872 for (; i
< pinfo
->operand_num
; i
++)
876 ret
= csky_print_operand (str
, &pinfo
->oprnd
.oprnds
[i
], inst
, reloc
);
880 info
->fprintf_func (info
->stream
, "%s", str
);
881 if (dis_info
.need_output_symbol
)
883 info
->fprintf_func (info
->stream
, "\t// ");
884 info
->print_address_func (dis_info
.value
, dis_info
.info
);
890 number_to_chars_littleendian (char *buf
, CSKY_INST_TYPE val
, int n
)
901 #define CSKY_READ_DATA() \
903 status = info->read_memory_func (memaddr, buf, 2, info); \
906 info->memory_error_func (status, memaddr, info); \
909 if (info->endian == BFD_ENDIAN_BIG) \
910 inst |= (buf[0] << 8) | buf[1]; \
911 else if (info->endian == BFD_ENDIAN_LITTLE) \
912 inst |= (buf[1] << 8) | buf[0]; \
915 info->bytes_per_chunk += 2; \
920 print_insn_csky (bfd_vma memaddr
, struct disassemble_info
*info
)
922 unsigned char buf
[4];
923 CSKY_INST_TYPE inst
= 0;
928 void (*printer
) (bfd_vma
, struct disassemble_info
*, long);
929 unsigned int size
= 4;
931 memset (str
, 0, sizeof (str
));
932 info
->bytes_per_chunk
= 0;
933 info
->bytes_per_chunk
= 0;
934 dis_info
.mem
= memaddr
;
935 dis_info
.info
= info
;
936 dis_info
.need_output_symbol
= 0;
937 if (mach_flag
!= INIT_MACH_FLAG
&& mach_flag
!= BINARY_MACH_FLAG
)
938 info
->mach
= mach_flag
;
939 else if (mach_flag
== INIT_MACH_FLAG
)
940 mach_flag
= info
->mach
;
942 if (mach_flag
== BINARY_MACH_FLAG
&& info
->endian
== BFD_ENDIAN_UNKNOWN
)
943 info
->endian
= BFD_ENDIAN_LITTLE
;
945 /* First check the full symtab for a mapping symbol, even if there
946 are no usable non-mapping symbols for this address. */
947 if (info
->symtab_size
!= 0
948 && bfd_asymbol_flavour (*info
->symtab
) == bfd_target_elf_flavour
)
953 enum sym_type type
= CUR_TEXT
;
955 if (memaddr
<= last_map_addr
)
957 /* Start scanning at the start of the function, or wherever
958 we finished last time. */
960 if (n
< last_map_sym
)
963 /* Scan up to the location being disassembled. */
964 for (; n
< info
->symtab_size
; n
++)
966 addr
= bfd_asymbol_value (info
->symtab
[n
]);
969 if ((info
->section
== NULL
970 || info
->section
== info
->symtab
[n
]->section
)
971 && get_sym_code_type (info
, n
, &type
))
974 last_map_sym
= last_sym
;
976 is_data
= (last_type
== CUR_DATA
);
979 size
= 4 - ( memaddr
& 3);
980 for (n
= last_sym
+ 1; n
< info
->symtab_size
; n
++)
982 addr
= bfd_asymbol_value (info
->symtab
[n
]);
985 if (addr
- memaddr
< size
)
986 size
= addr
- memaddr
;
990 /* If the next symbol is after three bytes, we need to
991 print only part of the data, so that we can use either
994 size
= (memaddr
& 1) ? 1 : 2;
997 info
->bytes_per_line
= 4;
1003 /* Size was already set above. */
1004 info
->bytes_per_chunk
= size
;
1005 printer
= print_insn_data
;
1007 status
= info
->read_memory_func (memaddr
, (bfd_byte
*) buf
, size
, info
);
1009 if (info
->endian
== BFD_ENDIAN_LITTLE
)
1010 for (i
= size
- 1; i
>= 0; i
--)
1011 given
= buf
[i
] | (given
<< 8);
1013 for (i
= 0; i
< (int) size
; i
++)
1014 given
= buf
[i
] | (given
<< 8);
1016 printer (memaddr
, info
, given
);
1017 return info
->bytes_per_chunk
;
1020 /* Handle instructions. */
1022 if ((inst
& 0xc000) == 0xc000 && IS_CSKY_V2 (mach_flag
))
1024 /* It's a 32-bit instruction. */
1027 if (info
->buffer
&& (info
->endian
== BFD_ENDIAN_LITTLE
))
1029 char* src
= (char *)(info
->buffer
1030 + ((memaddr
- 4 - info
->buffer_vma
)
1031 * info
->octets_per_byte
));
1032 if (info
->endian
== BFD_ENDIAN_LITTLE
)
1033 number_to_chars_littleendian (src
, inst
, 4);
1037 if (IS_CSKY_V1 (mach_flag
))
1038 g_opcodeP
= csky_v1_opcodes
;
1040 g_opcodeP
= csky_v2_opcodes
;
1044 struct csky_opcode
const *op
;
1045 struct csky_opcode_info
const *pinfo
= NULL
;
1048 memset (str
, 0, sizeof (str
));
1049 op
= csky_find_inst_info (&pinfo
, inst
, info
->bytes_per_chunk
);
1052 if (IS_CSKY_V1 (mach_flag
))
1053 info
->fprintf_func (info
->stream
, ".short: 0x%04x",
1054 (unsigned short)inst
);
1056 info
->fprintf_func (info
->stream
, ".long: 0x%08x",
1057 (unsigned int)inst
);
1058 return info
->bytes_per_chunk
;
1061 if (info
->bytes_per_chunk
== 2)
1062 reloc
= op
->reloc16
;
1064 reloc
= op
->reloc32
;
1065 dis_info
.opinfo
= pinfo
;
1066 strcat (str
, op
->mnemonic
);
1068 if (csky_print_operands (str
, pinfo
, info
, inst
, reloc
))
1074 return info
->bytes_per_chunk
;