cd8c0ba3d98e3b214f1b2d14b8f4ac5ff79890d9
1 /* Instruction printing code for the ARM
2 Copyright (C) 1994, 95, 96, 97, 1998 Free Software Foundation, Inc.
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modification by James G. Smith (jsmith@cygnus.co.uk)
6 This file is part of libopcodes.
8 This program is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your option)
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "coff/internal.h"
29 /* start-sanitize-armelf */
30 /* FIXME: This shouldn't be done here */
32 #include "elf/internal.h"
33 /* end-sanitize-armelf */
35 static char *arm_conditional
[] =
36 {"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
37 "hi", "ls", "ge", "lt", "gt", "le", "", "nv"};
39 static char *arm_regnames
[] =
40 {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
41 "r8", "r9", "sl", "fp", "ip", "sp", "lr", "pc"};
43 static char *arm_fp_const
[] =
44 {"0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0"};
46 static char *arm_shift
[] =
47 {"lsl", "lsr", "asr", "ror"};
49 static int print_insn_arm
PARAMS ((bfd_vma
, struct disassemble_info
*,
53 arm_decode_shift (given
, func
, stream
)
58 func (stream
, "%s", arm_regnames
[given
& 0xf]);
59 if ((given
& 0xff0) != 0)
61 if ((given
& 0x10) == 0)
63 int amount
= (given
& 0xf80) >> 7;
64 int shift
= (given
& 0x60) >> 5;
69 func (stream
, ", rrx");
74 func (stream
, ", %s #%d", arm_shift
[shift
], amount
);
77 func (stream
, ", %s %s", arm_shift
[(given
& 0x60) >> 5],
78 arm_regnames
[(given
& 0xf00) >> 8]);
82 /* Print one instruction from PC on INFO->STREAM.
83 Return the size of the instruction (always 4 on ARM). */
86 print_insn_arm (pc
, info
, given
)
88 struct disassemble_info
*info
;
91 struct arm_opcode
*insn
;
92 void *stream
= info
->stream
;
93 fprintf_ftype func
= info
->fprintf_func
;
95 for (insn
= arm_opcodes
; insn
->assembler
; insn
++)
97 if ((given
& insn
->mask
) == insn
->value
)
100 for (c
= insn
->assembler
; *c
; c
++)
111 if (((given
& 0x000f0000) == 0x000f0000)
112 && ((given
& 0x02000000) == 0))
114 int offset
= given
& 0xfff;
115 if ((given
& 0x00800000) == 0)
117 (*info
->print_address_func
)
118 (offset
+ pc
+ 8, info
);
123 arm_regnames
[(given
>> 16) & 0xf]);
124 if ((given
& 0x01000000) != 0)
126 if ((given
& 0x02000000) == 0)
128 int offset
= given
& 0xfff;
130 func (stream
, ", %s#%d",
131 (((given
& 0x00800000) == 0)
132 ? "-" : ""), offset
);
136 func (stream
, ", %s",
137 (((given
& 0x00800000) == 0)
139 arm_decode_shift (given
, func
, stream
);
143 ((given
& 0x00200000) != 0) ? "!" : "");
147 if ((given
& 0x02000000) == 0)
149 int offset
= given
& 0xfff;
151 func (stream
, "], %s#%d",
152 (((given
& 0x00800000) == 0)
153 ? "-" : ""), offset
);
159 func (stream
, "], %s",
160 (((given
& 0x00800000) == 0)
162 arm_decode_shift (given
, func
, stream
);
169 if ((given
& 0x004f0000) == 0x004f0000)
171 /* PC relative with immediate offset */
172 int offset
= ((given
& 0xf00) >> 4) | (given
& 0xf);
173 if ((given
& 0x00800000) == 0)
175 (*info
->print_address_func
)
176 (offset
+ pc
+ 8, info
);
181 arm_regnames
[(given
>> 16) & 0xf]);
182 if ((given
& 0x01000000) != 0)
185 if ((given
& 0x00400000) == 0x00400000)
188 int offset
= ((given
& 0xf00) >> 4) | (given
& 0xf);
190 func (stream
, ", %s#%d",
191 (((given
& 0x00800000) == 0)
192 ? "-" : ""), offset
);
197 func (stream
, ", %s%s",
198 (((given
& 0x00800000) == 0)
200 arm_regnames
[given
& 0xf]);
204 ((given
& 0x00200000) != 0) ? "!" : "");
209 if ((given
& 0x00400000) == 0x00400000)
212 int offset
= ((given
& 0xf00) >> 4) | (given
& 0xf);
214 func (stream
, "], %s#%d",
215 (((given
& 0x00800000) == 0)
216 ? "-" : ""), offset
);
223 func (stream
, "], %s%s",
224 (((given
& 0x00800000) == 0)
226 arm_regnames
[given
& 0xf]);
233 (*info
->print_address_func
)
234 (BDISP (given
) * 4 + pc
+ 8, info
);
239 arm_conditional
[(given
>> 28) & 0xf]);
248 for (reg
= 0; reg
< 16; reg
++)
249 if ((given
& (1 << reg
)) != 0)
254 func (stream
, "%s", arm_regnames
[reg
]);
261 if ((given
& 0x02000000) != 0)
263 int rotate
= (given
& 0xf00) >> 7;
264 int immed
= (given
& 0xff);
266 ((immed
<< (32 - rotate
))
267 | (immed
>> rotate
)) & 0xffffffff);
270 arm_decode_shift (given
, func
, stream
);
274 if ((given
& 0x0000f000) == 0x0000f000)
279 if ((given
& 0x01200000) == 0x00200000)
284 if ((given
& 0x00000020) == 0x00000020)
291 func (stream
, "[%s", arm_regnames
[(given
>> 16) & 0xf]);
292 if ((given
& 0x01000000) != 0)
294 int offset
= given
& 0xff;
296 func (stream
, ", %s#%d]%s",
297 ((given
& 0x00800000) == 0 ? "-" : ""),
299 ((given
& 0x00200000) != 0 ? "!" : ""));
305 int offset
= given
& 0xff;
307 func (stream
, "], %s#%d",
308 ((given
& 0x00800000) == 0 ? "-" : ""),
316 switch (given
& 0x00090000)
319 func (stream
, "_???");
322 func (stream
, "_all");
325 func (stream
, "_ctl");
328 func (stream
, "_flg");
334 switch (given
& 0x00408000)
351 switch (given
& 0x00080080)
363 func (stream
, _("<illegal precision>"));
368 switch (given
& 0x00408000)
385 switch (given
& 0x60)
401 case '0': case '1': case '2': case '3': case '4':
402 case '5': case '6': case '7': case '8': case '9':
404 int bitstart
= *c
++ - '0';
406 while (*c
>= '0' && *c
<= '9')
407 bitstart
= (bitstart
* 10) + *c
++ - '0';
413 while (*c
>= '0' && *c
<= '9')
414 bitend
= (bitend
* 10) + *c
++ - '0';
422 reg
= given
>> bitstart
;
423 reg
&= (2 << (bitend
- bitstart
)) - 1;
424 func (stream
, "%s", arm_regnames
[reg
]);
430 reg
= given
>> bitstart
;
431 reg
&= (2 << (bitend
- bitstart
)) - 1;
432 func (stream
, "%d", reg
);
438 reg
= given
>> bitstart
;
439 reg
&= (2 << (bitend
- bitstart
)) - 1;
440 func (stream
, "0x%08x", reg
);
446 reg
= given
>> bitstart
;
447 reg
&= (2 << (bitend
- bitstart
)) - 1;
450 arm_fp_const
[reg
& 7]);
452 func (stream
, "f%d", reg
);
461 if ((given
& (1 << bitstart
)) == 0)
462 func (stream
, "%c", *c
);
466 if ((given
& (1 << bitstart
)) != 0)
467 func (stream
, "%c", *c
);
471 if ((given
& (1 << bitstart
)) != 0)
472 func (stream
, "%c", *c
++);
474 func (stream
, "%c", *++c
);
487 func (stream
, "%c", *c
);
495 /* Print one instruction from PC on INFO->STREAM.
496 Return the size of the instruction. */
499 print_insn_thumb (pc
, info
, given
)
501 struct disassemble_info
*info
;
504 struct thumb_opcode
*insn
;
505 void *stream
= info
->stream
;
506 fprintf_ftype func
= info
->fprintf_func
;
508 for (insn
= thumb_opcodes
; insn
->assembler
; insn
++)
510 if ((given
& insn
->mask
) == insn
->value
)
512 char *c
= insn
->assembler
;
514 /* Special processing for Thumb 2 instruction BL sequence: */
515 if (!*c
) /* check for empty (not NULL) assembler string */
517 info
->bytes_per_chunk
= 4;
518 info
->bytes_per_line
= 4;
520 func (stream
, "%04x\tbl\t", given
& 0xffff);
521 (*info
->print_address_func
)
522 (BDISP23 (given
) * 2 + pc
+ 4, info
);
527 info
->bytes_per_chunk
= 2;
528 info
->bytes_per_line
= 4;
531 func (stream
, "%04x\t", given
);
547 reg
= (given
>> 3) & 0x7;
548 if (given
& (1 << 6))
550 func (stream
, "%s", arm_regnames
[reg
]);
558 if (given
& (1 << 7))
560 func (stream
, "%s", arm_regnames
[reg
]);
566 arm_conditional
[(given
>> 8) & 0xf]);
570 if (given
& (1 << 8))
574 if (*c
== 'O' && (given
& (1 << 8)))
582 /* It would be nice if we could spot
583 ranges, and generate the rS-rE format: */
584 for (reg
= 0; (reg
< 8); reg
++)
585 if ((given
& (1 << reg
)) != 0)
590 func (stream
, "%s", arm_regnames
[reg
]);
613 case '0': case '1': case '2': case '3': case '4':
614 case '5': case '6': case '7': case '8': case '9':
616 int bitstart
= *c
++ - '0';
618 while (*c
>= '0' && *c
<= '9')
619 bitstart
= (bitstart
* 10) + *c
++ - '0';
627 while (*c
>= '0' && *c
<= '9')
628 bitend
= (bitend
* 10) + *c
++ - '0';
631 reg
= given
>> bitstart
;
632 reg
&= (2 << (bitend
- bitstart
)) - 1;
636 func (stream
, "%s", arm_regnames
[reg
]);
640 func (stream
, "%d", reg
);
644 func (stream
, "%d", reg
<< 1);
648 func (stream
, "%d", reg
<< 2);
652 /* PC-relative address -- the bottom two
653 bits of the address are dropped before
655 info
->print_address_func
656 (((pc
+ 4) & ~3) + (reg
<< 2), info
);
660 func (stream
, "0x%04x", reg
);
664 reg
= ((reg
^ (1 << bitend
)) - (1 << bitend
));
665 func (stream
, "%d", reg
);
669 reg
= ((reg
^ (1 << bitend
)) - (1 << bitend
));
670 (*info
->print_address_func
)
671 (reg
* 2 + pc
+ 4, info
);
682 if ((given
& (1 << bitstart
)) != 0)
683 func (stream
, "%c", *c
);
688 if ((given
& (1 << bitstart
)) != 0)
689 func (stream
, "%c", *c
++);
691 func (stream
, "%c", *++c
);
705 func (stream
, "%c", *c
);
716 /* NOTE: There are no checks in these routines that the relevant number of data bytes exist */
719 print_insn_big_arm (pc
, info
)
721 struct disassemble_info
*info
;
726 coff_symbol_type
*cs
;
727 /* start-sanitize-armelf */
729 /* end-sanitize-armelf */
733 if (info
->symbols
!= NULL
)
735 if (bfd_asymbol_flavour (*info
->symbols
) == bfd_target_coff_flavour
)
737 cs
= coffsymbol (*info
->symbols
);
738 is_thumb
= (cs
->native
->u
.syment
.n_sclass
== C_THUMBEXT
739 || cs
->native
->u
.syment
.n_sclass
== C_THUMBSTAT
740 || cs
->native
->u
.syment
.n_sclass
== C_THUMBLABEL
741 || cs
->native
->u
.syment
.n_sclass
== C_THUMBEXTFUNC
742 || cs
->native
->u
.syment
.n_sclass
== C_THUMBSTATFUNC
);
745 /* start-sanitize-armelf */
746 else if (bfd_asymbol_flavour (*info
->symbols
) == bfd_target_elf_flavour
)
748 es
= *(elf_symbol_type
**)(info
->symbols
);
749 is_thumb
= (es
->internal_elf_sym
.st_other
== C_THUMBEXT
750 || es
->internal_elf_sym
.st_other
== C_THUMBSTAT
751 || es
->internal_elf_sym
.st_other
== C_THUMBLABEL
752 || es
->internal_elf_sym
.st_other
== C_THUMBEXTFUNC
753 || es
->internal_elf_sym
.st_other
== C_THUMBSTATFUNC
);
755 /* end-sanitize-armelf */
758 info
->bytes_per_chunk
= 4;
759 info
->display_endian
= BFD_ENDIAN_BIG
;
761 /* Always fetch word aligned values. */
763 status
= (*info
->read_memory_func
) (pc
& ~ 0x3, (bfd_byte
*) &b
[0], 4, info
);
766 (*info
->memory_error_func
) (status
, pc
, info
);
774 given
= (b
[2] << 8) | b
[3];
776 status
= info
->read_memory_func ((pc
+ 4) & ~ 0x3, (bfd_byte
*) b
, 4, info
);
779 info
->memory_error_func (status
, pc
+ 4, info
);
783 given
|= (b
[0] << 24) | (b
[1] << 16);
787 given
= (b
[0] << 8) | b
[1] | (b
[2] << 24) | (b
[3] << 16);
792 given
= (b
[0] << 24) | (b
[1] << 16) | (b
[2] << 8) | (b
[3]);
797 status
= print_insn_thumb (pc
, info
, given
);
801 status
= print_insn_arm (pc
, info
, given
);
808 print_insn_little_arm (pc
, info
)
810 struct disassemble_info
* info
;
815 coff_symbol_type
*cs
;
816 /* start-sanitize-armelf */
818 /* end-sanitize-armelf */
822 if (info
->symbols
!= NULL
)
824 if (bfd_asymbol_flavour (*info
->symbols
) == bfd_target_coff_flavour
)
826 cs
= coffsymbol (*info
->symbols
);
827 is_thumb
= (cs
->native
->u
.syment
.n_sclass
== C_THUMBEXT
828 || cs
->native
->u
.syment
.n_sclass
== C_THUMBSTAT
829 || cs
->native
->u
.syment
.n_sclass
== C_THUMBLABEL
830 || cs
->native
->u
.syment
.n_sclass
== C_THUMBEXTFUNC
831 || cs
->native
->u
.syment
.n_sclass
== C_THUMBSTATFUNC
);
834 /* start-sanitize-armelf */
835 else if (bfd_asymbol_flavour (*info
->symbols
) == bfd_target_elf_flavour
)
837 es
= *(elf_symbol_type
**)(info
->symbols
);
838 is_thumb
= (es
->internal_elf_sym
.st_other
== C_THUMBEXT
839 || es
->internal_elf_sym
.st_other
== C_THUMBSTAT
840 || es
->internal_elf_sym
.st_other
== C_THUMBLABEL
841 || es
->internal_elf_sym
.st_other
== C_THUMBEXTFUNC
842 || es
->internal_elf_sym
.st_other
== C_THUMBSTATFUNC
);
844 /* end-sanitize-armelf */
848 info
->bytes_per_chunk
= 4;
849 info
->display_endian
= BFD_ENDIAN_LITTLE
;
851 status
= (*info
->read_memory_func
) (pc
, (bfd_byte
*) &b
[0], 4, info
);
852 if (status
!= 0 && is_thumb
)
854 info
->bytes_per_chunk
= 2;
856 status
= info
->read_memory_func (pc
, (bfd_byte
*) b
, 2, info
);
861 (*info
->memory_error_func
) (status
, pc
, info
);
865 given
= (b
[0]) | (b
[1] << 8) | (b
[2] << 16) | (b
[3] << 24);
869 status
= print_insn_thumb (pc
, info
, given
);
873 status
= print_insn_arm (pc
, info
, given
);
This page took 0.047712 seconds and 3 git commands to generate.