1 /* Print mips instructions for GDB, the GNU debugger, or for objdump.
2 Copyright 1989, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by Nobuyuki Hikichi(hikichi@sra.co.jp).
5 This file is part of GDB.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "opcode/mips.h"
26 /* FIXME: we need direct access to the swapping functions. */
29 /* Mips instructions are never longer than this many bytes. */
32 /* FIXME: This should be shared with gdb somehow. */
33 #define REGISTER_NAMES \
34 { "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", \
35 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", \
36 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", \
37 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", \
38 "sr", "lo", "hi", "bad", "cause","pc", \
39 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
40 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
41 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",\
42 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",\
43 "fsr", "fir", "fp", "inx", "rand", "tlblo","ctxt", "tlbhi",\
47 static CONST
char * CONST reg_names
[] = REGISTER_NAMES
;
51 print_insn_arg (d
, l
, pc
, info
)
53 register unsigned long int l
;
55 struct disassemble_info
*info
;
64 (*info
->fprintf_func
) (info
->stream
, "%c", *d
);
71 (*info
->fprintf_func
) (info
->stream
, "$%s",
72 reg_names
[(l
>> OP_SH_RS
) & OP_MASK_RS
]);
77 (*info
->fprintf_func
) (info
->stream
, "$%s",
78 reg_names
[(l
>> OP_SH_RT
) & OP_MASK_RT
]);
83 (*info
->fprintf_func
) (info
->stream
, "%d",
84 (l
>> OP_SH_IMMEDIATE
) & OP_MASK_IMMEDIATE
);
87 case 'j': /* same as i, but sign-extended */
89 delta
= (l
>> OP_SH_DELTA
) & OP_MASK_DELTA
;
92 (*info
->fprintf_func
) (info
->stream
, "%d",
97 (*info
->print_address_func
)
98 (((pc
& 0xF0000000) | (((l
>> OP_SH_TARGET
) & OP_MASK_TARGET
) << 2)),
103 /* sign extend the displacement */
104 delta
= (l
>> OP_SH_DELTA
) & OP_MASK_DELTA
;
107 (*info
->print_address_func
)
108 ((delta
<< 2) + pc
+ 4,
113 (*info
->fprintf_func
) (info
->stream
, "$%s",
114 reg_names
[(l
>> OP_SH_RD
) & OP_MASK_RD
]);
118 (*info
->fprintf_func
) (info
->stream
, "0x%x",
119 (l
>> OP_SH_SHAMT
) & OP_MASK_SHAMT
);
123 (*info
->fprintf_func
) (info
->stream
, "0x%x",
124 (l
>> OP_SH_CODE
) & OP_MASK_CODE
);
128 (*info
->fprintf_func
) (info
->stream
, "0x%x",
129 (l
>> OP_SH_COPZ
) & OP_MASK_COPZ
);
133 (*info
->fprintf_func
) (info
->stream
, "0x%x",
134 (l
>> OP_SH_SYSCALL
) & OP_MASK_SYSCALL
);
139 (*info
->fprintf_func
) (info
->stream
, "$f%d",
140 (l
>> OP_SH_FS
) & OP_MASK_FS
);
145 (*info
->fprintf_func
) (info
->stream
, "$f%d",
146 (l
>> OP_SH_FT
) & OP_MASK_FT
);
150 (*info
->fprintf_func
) (info
->stream
, "$f%d",
151 (l
>> OP_SH_FD
) & OP_MASK_FD
);
155 (*info
->fprintf_func
) (info
->stream
, "$%d",
156 (l
>> OP_SH_RT
) & OP_MASK_RT
);
160 (*info
->fprintf_func
) (info
->stream
, "$%d",
161 (l
>> OP_SH_RD
) & OP_MASK_RD
);
165 (*info
->fprintf_func
) (info
->stream
,
166 "# internal error, undefined modifier(%c)", *d
);
171 /* Print the mips instruction at address MEMADDR in debugged memory,
172 on using INFO. Returns length of the instruction, in bytes, which is
173 always 4. BIGENDIAN must be 1 if this is big-endian code, 0 if
174 this is little-endian code. */
177 _print_insn_mips (memaddr
, word
, info
)
179 struct disassemble_info
*info
;
180 unsigned long int word
;
185 for (i
= 0; i
< NUMOPCODES
; i
++)
187 if (mips_opcodes
[i
].pinfo
!= INSN_MACRO
)
189 register unsigned int match
= mips_opcodes
[i
].match
;
190 register unsigned int mask
= mips_opcodes
[i
].mask
;
191 if ((word
& mask
) == match
)
196 /* Handle undefined instructions. */
199 (*info
->fprintf_func
) (info
->stream
, "0x%x", word
);
203 (*info
->fprintf_func
) (info
->stream
, "%s", mips_opcodes
[i
].name
);
205 if (!(d
= mips_opcodes
[i
].args
))
208 (*info
->fprintf_func
) (info
->stream
, " ");
211 print_insn_arg (d
++, word
, memaddr
, info
);
217 print_insn_big_mips (memaddr
, info
)
219 struct disassemble_info
*info
;
222 int status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
224 return _print_insn_mips (memaddr
, _do_getb32 (buffer
), info
);
227 (*info
->memory_error_func
) (status
, memaddr
, info
);
233 print_insn_little_mips (memaddr
, info
)
235 struct disassemble_info
*info
;
238 int status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
240 return _print_insn_mips (memaddr
, _do_getl32 (buffer
), info
);
243 (*info
->memory_error_func
) (status
, memaddr
, info
);