1 /* Print mips instructions for GDB, the GNU debugger, or for objdump.
2 Copyright (c) 1989, 91-97, 1998 Free Software Foundation, Inc.
3 Contributed by Nobuyuki Hikichi(hikichi@sra.co.jp).
5 This file is part of GDB, GAS, and the GNU binutils.
7 This program 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 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "opcode/mips.h"
27 /* FIXME: These are needed to figure out if the code is mips16 or
28 not. The low bit of the address is often a good indicator. No
29 symbol table is available when this code runs out in an embedded
30 system as when it is used for disassembler support in a monitor. */
32 #if !defined(EMBEDDED_ENV)
33 #define SYMTAB_AVAILABLE 1
38 static int print_insn_mips16
PARAMS ((bfd_vma
, struct disassemble_info
*));
39 static void print_mips16_insn_arg
40 PARAMS ((int, const struct mips_opcode
*, int, boolean
, int, bfd_vma
,
41 struct disassemble_info
*));
43 /* Mips instructions are never longer than this many bytes. */
46 static void print_insn_arg
PARAMS ((const char *, unsigned long, bfd_vma
,
47 struct disassemble_info
*));
48 static int _print_insn_mips
PARAMS ((bfd_vma
, unsigned long int,
49 struct disassemble_info
*));
52 /* FIXME: This should be shared with gdb somehow. */
53 #define REGISTER_NAMES \
54 { "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", \
55 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", \
56 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", \
57 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", \
58 "sr", "lo", "hi", "bad", "cause","pc", \
59 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
60 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
61 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",\
62 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",\
63 "fsr", "fir", "fp", "inx", "rand", "tlblo","ctxt", "tlbhi",\
67 static CONST
char * CONST reg_names
[] = REGISTER_NAMES
;
69 /* The mips16 register names. */
70 static const char * const mips16_reg_names
[] =
72 "s0", "s1", "v0", "v1", "a0", "a1", "a2", "a3"
77 print_insn_arg (d
, l
, pc
, info
)
79 register unsigned long int l
;
81 struct disassemble_info
*info
;
90 /* start-sanitize-vr5400 */
93 /* end-sanitize-vr5400 */
94 /* start-sanitize-r5900 */
97 /* end-sanitize-r5900 */
98 (*info
->fprintf_func
) (info
->stream
, "%c", *d
);
105 (*info
->fprintf_func
) (info
->stream
, "$%s",
106 reg_names
[(l
>> OP_SH_RS
) & OP_MASK_RS
]);
111 (*info
->fprintf_func
) (info
->stream
, "$%s",
112 reg_names
[(l
>> OP_SH_RT
) & OP_MASK_RT
]);
117 (*info
->fprintf_func
) (info
->stream
, "0x%x",
118 (l
>> OP_SH_IMMEDIATE
) & OP_MASK_IMMEDIATE
);
121 case 'j': /* same as i, but sign-extended */
123 delta
= (l
>> OP_SH_DELTA
) & OP_MASK_DELTA
;
126 (*info
->fprintf_func
) (info
->stream
, "%d",
131 (*info
->fprintf_func
) (info
->stream
, "0x%x",
132 (unsigned int) ((l
>> OP_SH_PREFX
)
137 (*info
->fprintf_func
) (info
->stream
, "0x%x",
138 (unsigned int) ((l
>> OP_SH_CACHE
)
143 (*info
->print_address_func
)
144 (((pc
& 0xF0000000) | (((l
>> OP_SH_TARGET
) & OP_MASK_TARGET
) << 2)),
149 /* sign extend the displacement */
150 delta
= (l
>> OP_SH_DELTA
) & OP_MASK_DELTA
;
153 (*info
->print_address_func
)
154 ((delta
<< 2) + pc
+ 4,
159 (*info
->fprintf_func
) (info
->stream
, "$%s",
160 reg_names
[(l
>> OP_SH_RD
) & OP_MASK_RD
]);
164 (*info
->fprintf_func
) (info
->stream
, "$%s", reg_names
[0]);
168 (*info
->fprintf_func
) (info
->stream
, "0x%x",
169 (l
>> OP_SH_SHAMT
) & OP_MASK_SHAMT
);
173 (*info
->fprintf_func
) (info
->stream
, "0x%x",
174 (l
>> OP_SH_CODE
) & OP_MASK_CODE
);
179 (*info
->fprintf_func
) (info
->stream
, "0x%x",
180 (l
>> OP_SH_CODE2
) & OP_MASK_CODE2
);
184 (*info
->fprintf_func
) (info
->stream
, "0x%x",
185 (l
>> OP_SH_COPZ
) & OP_MASK_COPZ
);
189 (*info
->fprintf_func
) (info
->stream
, "0x%x",
190 (l
>> OP_SH_SYSCALL
) & OP_MASK_SYSCALL
);
195 (*info
->fprintf_func
) (info
->stream
, "$f%d",
196 (l
>> OP_SH_FS
) & OP_MASK_FS
);
199 /* start-sanitize-r5900 */
201 (*info
->fprintf_func
) (info
->stream
, "0x%x",
206 (*info
->fprintf_func
) (info
->stream
, "vi27");
210 (*info
->fprintf_func
) (info
->stream
, "vf%d",
211 (l
>> OP_SH_FT
) & OP_MASK_FT
);
214 (*info
->fprintf_func
) (info
->stream
, "vf%d",
215 (l
>> OP_SH_FS
) & OP_MASK_FS
);
218 (*info
->fprintf_func
) (info
->stream
, "vf%d",
219 (l
>> OP_SH_FD
) & OP_MASK_FD
);
223 (*info
->fprintf_func
) (info
->stream
, "vi%d",
224 (l
>> OP_SH_FT
) & OP_MASK_FT
);
227 (*info
->fprintf_func
) (info
->stream
, "vi%d",
228 (l
>> OP_SH_FS
) & OP_MASK_FS
);
231 (*info
->fprintf_func
) (info
->stream
, "vi%d",
232 (l
>> OP_SH_FD
) & OP_MASK_FD
);
236 (*info
->fprintf_func
) (info
->stream
, "vf%d",
237 (l
>> OP_SH_FT
) & OP_MASK_FT
);
238 switch ((l
>> 23) & 0x3)
241 (*info
->fprintf_func
) (info
->stream
, "x");
244 (*info
->fprintf_func
) (info
->stream
, "y");
247 (*info
->fprintf_func
) (info
->stream
, "z");
250 (*info
->fprintf_func
) (info
->stream
, "w");
258 (*info
->fprintf_func
) (info
->stream
, ".xyz\t");
262 (*info
->fprintf_func
) (info
->stream
, ".");
264 (*info
->fprintf_func
) (info
->stream
, "w");
266 (*info
->fprintf_func
) (info
->stream
, "x");
268 (*info
->fprintf_func
) (info
->stream
, "y");
270 (*info
->fprintf_func
) (info
->stream
, "z");
271 (*info
->fprintf_func
) (info
->stream
, "\t");
275 (*info
->fprintf_func
) (info
->stream
, "vf%d",
276 (l
>> OP_SH_FS
) & OP_MASK_FS
);
277 switch ((l
>> 21) & 0x3)
280 (*info
->fprintf_func
) (info
->stream
, "x");
283 (*info
->fprintf_func
) (info
->stream
, "y");
286 (*info
->fprintf_func
) (info
->stream
, "z");
289 (*info
->fprintf_func
) (info
->stream
, "w");
294 (*info
->fprintf_func
) (info
->stream
, "I");
298 (*info
->fprintf_func
) (info
->stream
, "Q");
302 (*info
->fprintf_func
) (info
->stream
, "R");
306 (*info
->fprintf_func
) (info
->stream
, "ACC");
310 delta
= (l
>> 6) & 0x7fff;
312 (*info
->print_address_func
) (delta
, info
);
315 /* end-sanitize-r5900 */
319 (*info
->fprintf_func
) (info
->stream
, "$f%d",
320 (l
>> OP_SH_FT
) & OP_MASK_FT
);
324 (*info
->fprintf_func
) (info
->stream
, "$f%d",
325 (l
>> OP_SH_FD
) & OP_MASK_FD
);
329 (*info
->fprintf_func
) (info
->stream
, "$f%d",
330 (l
>> OP_SH_FR
) & OP_MASK_FR
);
334 (*info
->fprintf_func
) (info
->stream
, "$%d",
335 (l
>> OP_SH_RT
) & OP_MASK_RT
);
339 (*info
->fprintf_func
) (info
->stream
, "$%d",
340 (l
>> OP_SH_RD
) & OP_MASK_RD
);
344 (*info
->fprintf_func
) (info
->stream
, "$fcc%d",
345 (l
>> OP_SH_BCC
) & OP_MASK_BCC
);
349 (*info
->fprintf_func
) (info
->stream
, "$fcc%d",
350 (l
>> OP_SH_CCC
) & OP_MASK_CCC
);
354 (*info
->fprintf_func
) (info
->stream
, "%d",
355 (l
>> OP_SH_PERFREG
) & OP_MASK_PERFREG
);
358 /* start-sanitize-vr5400 */
360 (*info
->fprintf_func
) (info
->stream
, "%d",
361 (l
>> OP_SH_VECBYTE
) & OP_MASK_VECBYTE
);
365 (*info
->fprintf_func
) (info
->stream
, "%d",
366 (l
>> OP_SH_VECALIGN
) & OP_MASK_VECALIGN
);
368 /* end-sanitize-vr5400 */
371 /* xgettext:c-format */
372 (*info
->fprintf_func
) (info
->stream
,
373 _("# internal error, undefined modifier(%c)"),
381 /* Figure out the MIPS ISA and CPU based on the machine number.
382 FIXME: What does this have to do with SYMTAB_AVAILABLE? */
385 set_mips_isa_type (mach
, isa
, cputype
)
390 int target_processor
= 0;
395 /* start-sanitize-tx19 */
396 case bfd_mach_mips1900
:
397 target_processor
= 1900;
400 /* end-sanitize-tx19 */
401 case bfd_mach_mips3000
:
402 target_processor
= 3000;
405 case bfd_mach_mips3900
:
406 target_processor
= 3900;
409 case bfd_mach_mips4000
:
410 target_processor
= 4000;
413 case bfd_mach_mips4010
:
414 target_processor
= 4010;
417 case bfd_mach_mips4100
:
418 target_processor
= 4100;
421 case bfd_mach_mips4300
:
422 target_processor
= 4300;
425 /* start-sanitize-vr4320 */
426 case bfd_mach_mips4320
:
427 target_processor
= 4320;
430 /* end-sanitize-vr4320 */
431 case bfd_mach_mips4400
:
432 target_processor
= 4400;
435 case bfd_mach_mips4600
:
436 target_processor
= 4600;
439 case bfd_mach_mips4650
:
440 target_processor
= 4650;
443 /* start-sanitize-tx49 */
444 case bfd_mach_mips4900
:
445 target_processor
= 4900;
448 /* end-sanitize-tx49 */
449 case bfd_mach_mips5000
:
450 target_processor
= 5000;
453 /* start-sanitize-vr5400 */
454 case bfd_mach_mips5400
:
455 target_processor
= 5400;
458 /* end-sanitize-vr5400 */
459 /* start-sanitize-r5900 */
460 case bfd_mach_mips5900
:
461 target_processor
= 5900;
464 /* end-sanitize-r5900 */
465 case bfd_mach_mips6000
:
466 target_processor
= 6000;
469 case bfd_mach_mips8000
:
470 target_processor
= 8000;
473 case bfd_mach_mips10000
:
474 target_processor
= 10000;
477 case bfd_mach_mips16
:
478 target_processor
= 16;
482 target_processor
= 3000;
489 *cputype
= target_processor
;
492 #endif /* SYMTAB_AVAILABLE */
494 /* Print the mips instruction at address MEMADDR in debugged memory,
495 on using INFO. Returns length of the instruction, in bytes, which is
496 always 4. BIGENDIAN must be 1 if this is big-endian code, 0 if
497 this is little-endian code. */
500 _print_insn_mips (memaddr
, word
, info
)
502 unsigned long int word
;
503 struct disassemble_info
*info
;
505 register const struct mips_opcode
*op
;
506 int target_processor
, mips_isa
;
507 static boolean init
= 0;
508 static const struct mips_opcode
*mips_hash
[OP_MASK_OP
+ 1];
510 /* Build a hash table to shorten the search time. */
515 for (i
= 0; i
<= OP_MASK_OP
; i
++)
517 for (op
= mips_opcodes
; op
< &mips_opcodes
[NUMOPCODES
]; op
++)
519 if (op
->pinfo
== INSN_MACRO
)
521 if (i
== ((op
->match
>> OP_SH_OP
) & OP_MASK_OP
))
532 #if ! SYMTAB_AVAILABLE
533 /* This is running out on a target machine, not in a host tool.
534 FIXME: Where does mips_target_info come from? */
535 target_processor
= mips_target_info
.processor
;
536 mips_isa
= mips_target_info
.isa
;
538 set_mips_isa_type (info
->mach
, &target_processor
, &mips_isa
);
541 info
->bytes_per_chunk
= 4;
542 info
->display_endian
= info
->endian
;
544 op
= mips_hash
[(word
>> OP_SH_OP
) & OP_MASK_OP
];
547 for (; op
< &mips_opcodes
[NUMOPCODES
]; op
++)
549 if (op
->pinfo
!= INSN_MACRO
&& (word
& op
->mask
) == op
->match
)
551 register const char *d
;
554 if ((op
->membership
& INSN_ISA
) == INSN_ISA1
)
556 else if ((op
->membership
& INSN_ISA
) == INSN_ISA2
)
558 else if ((op
->membership
& INSN_ISA
) == INSN_ISA3
)
560 else if ((op
->membership
& INSN_ISA
) == INSN_ISA4
)
565 if (insn_isa
> mips_isa
566 && (target_processor
== 4650
567 && op
->membership
& INSN_4650
) == 0
568 && (target_processor
== 4010
569 && op
->membership
& INSN_4010
) == 0
570 && (target_processor
== 4100
571 && op
->membership
& INSN_4100
) == 0
572 /* start-sanitize-vr4320 */
573 && (target_processor
== 4320
574 && op
->membership
& INSN_4320
) == 0
575 /* end-sanitize-vr4320 */
576 /* start-sanitize-vr5400 */
577 && (target_processor
== 5400
578 && op
->membership
& INSN_5400
) == 0
579 /* end-sanitize-vr5400 */
580 /* start-sanitize-r5900 */
581 && (target_processor
== 5900
582 && op
->membership
& INSN_5900
) == 0
583 /* end-sanitize-r5900 */
584 /* start-sanitize-tx49 */
585 && (target_processor
== 4900
586 && op
->membership
& INSN_4900
) == 0
587 /* end-sanitize-tx49 */
588 && (target_processor
== 3900
589 && op
->membership
& INSN_3900
) == 0)
592 (*info
->fprintf_func
) (info
->stream
, "%s", op
->name
);
595 if (d
!= NULL
&& *d
!= '\0')
597 /* start-sanitize-r5900 */
598 /* If this is an opcode completer, then do not emit
599 a tab after the opcode. */
600 if (*d
!= '&' && *d
!= ';')
601 /* end-sanitize-r5900 */
602 (*info
->fprintf_func
) (info
->stream
, "\t");
603 for (; *d
!= '\0'; d
++)
604 /* start-sanitize-r5900 */
605 /* If this is an escape character, go ahead and print the
606 next character in the arg string verbatim. */
610 (*info
->fprintf_func
) (info
->stream
, "%c", *d
);
613 /* end-sanitize-r5900 */
614 print_insn_arg (d
, word
, memaddr
, info
);
622 /* Handle undefined instructions. */
623 (*info
->fprintf_func
) (info
->stream
, "0x%x", word
);
628 /* In an environment where we do not know the symbol type of the
629 instruction we are forced to assume that the low order bit of the
630 instructions' address may mark it as a mips16 instruction. If we
631 are single stepping, or the pc is within the disassembled function,
632 this works. Otherwise, we need a clue. Sometimes. */
635 print_insn_big_mips (memaddr
, info
)
637 struct disassemble_info
*info
;
643 /* FIXME: If odd address, this is CLEARLY a mips 16 instruction. */
644 /* Only a few tools will work this way. */
646 return print_insn_mips16 (memaddr
, info
);
651 || (info
->flavour
== bfd_target_elf_flavour
652 && info
->symbols
!= NULL
653 && ((*(elf_symbol_type
**) info
->symbols
)->internal_elf_sym
.st_other
655 return print_insn_mips16 (memaddr
, info
);
658 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
660 return _print_insn_mips (memaddr
, (unsigned long) bfd_getb32 (buffer
),
664 (*info
->memory_error_func
) (status
, memaddr
, info
);
670 print_insn_little_mips (memaddr
, info
)
672 struct disassemble_info
*info
;
677 /* start-sanitize-sky */
680 /* bfd_mach_dvp_p is a macro which may evaluate its arguments more than
681 once. Since dvp_mach_type is a function, ensure it's only called
683 int mach
= dvp_info_mach_type (info
);
685 if (bfd_mach_dvp_p (info
->mach
)
686 || bfd_mach_dvp_p (mach
))
687 return print_insn_dvp (memaddr
, info
);
690 /* end-sanitize-sky */
694 return print_insn_mips16 (memaddr
, info
);
699 || (info
->flavour
== bfd_target_elf_flavour
700 && info
->symbols
!= NULL
701 && ((*(elf_symbol_type
**) info
->symbols
)->internal_elf_sym
.st_other
703 return print_insn_mips16 (memaddr
, info
);
706 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
708 return _print_insn_mips (memaddr
, (unsigned long) bfd_getl32 (buffer
),
712 (*info
->memory_error_func
) (status
, memaddr
, info
);
717 /* Disassemble mips16 instructions. */
720 print_insn_mips16 (memaddr
, info
)
722 struct disassemble_info
*info
;
730 const struct mips_opcode
*op
, *opend
;
732 info
->bytes_per_chunk
= 2;
733 info
->display_endian
= info
->endian
;
735 info
->insn_info_valid
= 1;
736 info
->branch_delay_insns
= 0;
738 info
->insn_type
= dis_nonbranch
;
742 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
745 (*info
->memory_error_func
) (status
, memaddr
, info
);
751 if (info
->endian
== BFD_ENDIAN_BIG
)
752 insn
= bfd_getb16 (buffer
);
754 insn
= bfd_getl16 (buffer
);
756 /* Handle the extend opcode specially. */
758 if ((insn
& 0xf800) == 0xf000)
761 extend
= insn
& 0x7ff;
765 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
768 (*info
->fprintf_func
) (info
->stream
, "extend 0x%x",
769 (unsigned int) extend
);
770 (*info
->memory_error_func
) (status
, memaddr
, info
);
774 if (info
->endian
== BFD_ENDIAN_BIG
)
775 insn
= bfd_getb16 (buffer
);
777 insn
= bfd_getl16 (buffer
);
779 /* Check for an extend opcode followed by an extend opcode. */
780 if ((insn
& 0xf800) == 0xf000)
782 (*info
->fprintf_func
) (info
->stream
, "extend 0x%x",
783 (unsigned int) extend
);
784 info
->insn_type
= dis_noninsn
;
791 /* FIXME: Should probably use a hash table on the major opcode here. */
793 opend
= mips16_opcodes
+ bfd_mips16_num_opcodes
;
794 for (op
= mips16_opcodes
; op
< opend
; op
++)
796 if (op
->pinfo
!= INSN_MACRO
&& (insn
& op
->mask
) == op
->match
)
800 if (strchr (op
->args
, 'a') != NULL
)
804 (*info
->fprintf_func
) (info
->stream
, "extend 0x%x",
805 (unsigned int) extend
);
806 info
->insn_type
= dis_noninsn
;
814 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2,
819 if (info
->endian
== BFD_ENDIAN_BIG
)
820 extend
= bfd_getb16 (buffer
);
822 extend
= bfd_getl16 (buffer
);
827 (*info
->fprintf_func
) (info
->stream
, "%s", op
->name
);
828 if (op
->args
[0] != '\0')
829 (*info
->fprintf_func
) (info
->stream
, "\t");
831 for (s
= op
->args
; *s
!= '\0'; s
++)
835 && (((insn
>> MIPS16OP_SH_RX
) & MIPS16OP_MASK_RX
)
836 == ((insn
>> MIPS16OP_SH_RY
) & MIPS16OP_MASK_RY
)))
838 /* Skip the register and the comma. */
844 && (((insn
>> MIPS16OP_SH_RZ
) & MIPS16OP_MASK_RZ
)
845 == ((insn
>> MIPS16OP_SH_RX
) & MIPS16OP_MASK_RX
)))
847 /* Skip the register and the comma. */
851 print_mips16_insn_arg (*s
, op
, insn
, use_extend
, extend
, memaddr
,
855 if ((op
->pinfo
& INSN_UNCOND_BRANCH_DELAY
) != 0)
857 info
->branch_delay_insns
= 1;
858 if (info
->insn_type
!= dis_jsr
)
859 info
->insn_type
= dis_branch
;
867 (*info
->fprintf_func
) (info
->stream
, "0x%x", extend
| 0xf000);
868 (*info
->fprintf_func
) (info
->stream
, "0x%x", insn
);
869 info
->insn_type
= dis_noninsn
;
874 /* Disassemble an operand for a mips16 instruction. */
877 print_mips16_insn_arg (type
, op
, l
, use_extend
, extend
, memaddr
, info
)
879 const struct mips_opcode
*op
;
884 struct disassemble_info
*info
;
891 (*info
->fprintf_func
) (info
->stream
, "%c", type
);
896 (*info
->fprintf_func
) (info
->stream
, "$%s",
897 mips16_reg_names
[((l
>> MIPS16OP_SH_RY
)
898 & MIPS16OP_MASK_RY
)]);
903 (*info
->fprintf_func
) (info
->stream
, "$%s",
904 mips16_reg_names
[((l
>> MIPS16OP_SH_RX
)
905 & MIPS16OP_MASK_RX
)]);
909 (*info
->fprintf_func
) (info
->stream
, "$%s",
910 mips16_reg_names
[((l
>> MIPS16OP_SH_RZ
)
911 & MIPS16OP_MASK_RZ
)]);
915 (*info
->fprintf_func
) (info
->stream
, "$%s",
916 mips16_reg_names
[((l
>> MIPS16OP_SH_MOVE32Z
)
917 & MIPS16OP_MASK_MOVE32Z
)]);
921 (*info
->fprintf_func
) (info
->stream
, "$%s", reg_names
[0]);
925 (*info
->fprintf_func
) (info
->stream
, "$%s", reg_names
[29]);
929 (*info
->fprintf_func
) (info
->stream
, "$pc");
933 (*info
->fprintf_func
) (info
->stream
, "$%s", reg_names
[31]);
937 (*info
->fprintf_func
) (info
->stream
, "$%s",
938 reg_names
[((l
>> MIPS16OP_SH_REGR32
)
939 & MIPS16OP_MASK_REGR32
)]);
943 (*info
->fprintf_func
) (info
->stream
, "$%s",
944 reg_names
[MIPS16OP_EXTRACT_REG32R (l
)]);
970 int immed
, nbits
, shift
, signedp
, extbits
, pcrel
, extu
, branch
;
982 immed
= (l
>> MIPS16OP_SH_RZ
) & MIPS16OP_MASK_RZ
;
988 immed
= (l
>> MIPS16OP_SH_RX
) & MIPS16OP_MASK_RX
;
994 immed
= (l
>> MIPS16OP_SH_RZ
) & MIPS16OP_MASK_RZ
;
1000 immed
= (l
>> MIPS16OP_SH_RX
) & MIPS16OP_MASK_RX
;
1006 immed
= (l
>> MIPS16OP_SH_IMM4
) & MIPS16OP_MASK_IMM4
;
1012 immed
= (l
>> MIPS16OP_SH_IMM5
) & MIPS16OP_MASK_IMM5
;
1013 info
->insn_type
= dis_dref
;
1014 info
->data_size
= 1;
1019 immed
= (l
>> MIPS16OP_SH_IMM5
) & MIPS16OP_MASK_IMM5
;
1020 info
->insn_type
= dis_dref
;
1021 info
->data_size
= 2;
1026 immed
= (l
>> MIPS16OP_SH_IMM5
) & MIPS16OP_MASK_IMM5
;
1027 if ((op
->pinfo
& MIPS16_INSN_READ_PC
) == 0
1028 && (op
->pinfo
& MIPS16_INSN_READ_SP
) == 0)
1030 info
->insn_type
= dis_dref
;
1031 info
->data_size
= 4;
1037 immed
= (l
>> MIPS16OP_SH_IMM5
) & MIPS16OP_MASK_IMM5
;
1038 info
->insn_type
= dis_dref
;
1039 info
->data_size
= 8;
1043 immed
= (l
>> MIPS16OP_SH_IMM5
) & MIPS16OP_MASK_IMM5
;
1048 immed
= (l
>> MIPS16OP_SH_IMM6
) & MIPS16OP_MASK_IMM6
;
1052 immed
= (l
>> MIPS16OP_SH_IMM8
) & MIPS16OP_MASK_IMM8
;
1057 immed
= (l
>> MIPS16OP_SH_IMM8
) & MIPS16OP_MASK_IMM8
;
1058 /* FIXME: This might be lw, or it might be addiu to $sp or
1059 $pc. We assume it's load. */
1060 info
->insn_type
= dis_dref
;
1061 info
->data_size
= 4;
1066 immed
= (l
>> MIPS16OP_SH_IMM8
) & MIPS16OP_MASK_IMM8
;
1067 info
->insn_type
= dis_dref
;
1068 info
->data_size
= 8;
1072 immed
= (l
>> MIPS16OP_SH_IMM8
) & MIPS16OP_MASK_IMM8
;
1077 immed
= (l
>> MIPS16OP_SH_IMM8
) & MIPS16OP_MASK_IMM8
;
1083 immed
= (l
>> MIPS16OP_SH_IMM8
) & MIPS16OP_MASK_IMM8
;
1088 immed
= (l
>> MIPS16OP_SH_IMM8
) & MIPS16OP_MASK_IMM8
;
1092 info
->insn_type
= dis_condbranch
;
1096 immed
= (l
>> MIPS16OP_SH_IMM11
) & MIPS16OP_MASK_IMM11
;
1100 info
->insn_type
= dis_branch
;
1105 immed
= (l
>> MIPS16OP_SH_IMM8
) & MIPS16OP_MASK_IMM8
;
1107 /* FIXME: This can be lw or la. We assume it is lw. */
1108 info
->insn_type
= dis_dref
;
1109 info
->data_size
= 4;
1114 immed
= (l
>> MIPS16OP_SH_IMM5
) & MIPS16OP_MASK_IMM5
;
1116 info
->insn_type
= dis_dref
;
1117 info
->data_size
= 8;
1122 immed
= (l
>> MIPS16OP_SH_IMM5
) & MIPS16OP_MASK_IMM5
;
1131 if (signedp
&& immed
>= (1 << (nbits
- 1)))
1132 immed
-= 1 << nbits
;
1134 if ((type
== '<' || type
== '>' || type
== '[' || type
== ']')
1141 immed
|= ((extend
& 0x1f) << 11) | (extend
& 0x7e0);
1142 else if (extbits
== 15)
1143 immed
|= ((extend
& 0xf) << 11) | (extend
& 0x7f0);
1145 immed
= ((extend
>> 6) & 0x1f) | (extend
& 0x20);
1146 immed
&= (1 << extbits
) - 1;
1147 if (! extu
&& immed
>= (1 << (extbits
- 1)))
1148 immed
-= 1 << extbits
;
1152 (*info
->fprintf_func
) (info
->stream
, "%d", immed
);
1161 baseaddr
= memaddr
+ 2;
1163 else if (use_extend
)
1164 baseaddr
= memaddr
- 2;
1172 /* If this instruction is in the delay slot of a jr
1173 instruction, the base address is the address of the
1174 jr instruction. If it is in the delay slot of jalr
1175 instruction, the base address is the address of the
1176 jalr instruction. This test is unreliable: we have
1177 no way of knowing whether the previous word is
1178 instruction or data. */
1179 status
= (*info
->read_memory_func
) (memaddr
- 4, buffer
, 2,
1182 && (((info
->endian
== BFD_ENDIAN_BIG
1183 ? bfd_getb16 (buffer
)
1184 : bfd_getl16 (buffer
))
1185 & 0xf800) == 0x1800))
1186 baseaddr
= memaddr
- 4;
1189 status
= (*info
->read_memory_func
) (memaddr
- 2, buffer
,
1192 && (((info
->endian
== BFD_ENDIAN_BIG
1193 ? bfd_getb16 (buffer
)
1194 : bfd_getl16 (buffer
))
1195 & 0xf81f) == 0xe800))
1196 baseaddr
= memaddr
- 2;
1199 val
= (baseaddr
& ~ ((1 << shift
) - 1)) + immed
;
1200 (*info
->print_address_func
) (val
, info
);
1209 l
= ((l
& 0x1f) << 23) | ((l
& 0x3e0) << 13) | (extend
<< 2);
1210 (*info
->print_address_func
) ((memaddr
& 0xf0000000) | l
, info
);
1211 info
->insn_type
= dis_jsr
;
1212 info
->target
= (memaddr
& 0xf0000000) | l
;
1213 info
->branch_delay_insns
= 1;
1219 int need_comma
, amask
, smask
;
1223 l
= (l
>> MIPS16OP_SH_IMM6
) & MIPS16OP_MASK_IMM6
;
1225 amask
= (l
>> 3) & 7;
1227 if (amask
> 0 && amask
< 5)
1229 (*info
->fprintf_func
) (info
->stream
, "$%s", reg_names
[4]);
1231 (*info
->fprintf_func
) (info
->stream
, "-$%s",
1232 reg_names
[amask
+ 3]);
1236 smask
= (l
>> 1) & 3;
1239 (*info
->fprintf_func
) (info
->stream
, "%s??",
1240 need_comma
? "," : "");
1245 (*info
->fprintf_func
) (info
->stream
, "%s$%s",
1246 need_comma
? "," : "",
1249 (*info
->fprintf_func
) (info
->stream
, "-$%s",
1250 reg_names
[smask
+ 15]);
1256 (*info
->fprintf_func
) (info
->stream
, "%s$%s",
1257 need_comma
? "," : "",
1262 if (amask
== 5 || amask
== 6)
1264 (*info
->fprintf_func
) (info
->stream
, "%s$f0",
1265 need_comma
? "," : "");
1267 (*info
->fprintf_func
) (info
->stream
, "-$f1");