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
, "$%s", reg_names
[0]);
122 (*info
->fprintf_func
) (info
->stream
, "0x%x",
123 (l
>> OP_SH_SHAMT
) & OP_MASK_SHAMT
);
127 (*info
->fprintf_func
) (info
->stream
, "0x%x",
128 (l
>> OP_SH_CODE
) & OP_MASK_CODE
);
132 (*info
->fprintf_func
) (info
->stream
, "0x%x",
133 (l
>> OP_SH_COPZ
) & OP_MASK_COPZ
);
137 (*info
->fprintf_func
) (info
->stream
, "0x%x",
138 (l
>> OP_SH_SYSCALL
) & OP_MASK_SYSCALL
);
143 (*info
->fprintf_func
) (info
->stream
, "$f%d",
144 (l
>> OP_SH_FS
) & OP_MASK_FS
);
149 (*info
->fprintf_func
) (info
->stream
, "$f%d",
150 (l
>> OP_SH_FT
) & OP_MASK_FT
);
154 (*info
->fprintf_func
) (info
->stream
, "$f%d",
155 (l
>> OP_SH_FD
) & OP_MASK_FD
);
159 (*info
->fprintf_func
) (info
->stream
, "$%d",
160 (l
>> OP_SH_RT
) & OP_MASK_RT
);
164 (*info
->fprintf_func
) (info
->stream
, "$%d",
165 (l
>> OP_SH_RD
) & OP_MASK_RD
);
169 (*info
->fprintf_func
) (info
->stream
,
170 "# internal error, undefined modifier(%c)", *d
);
175 /* Print the mips instruction at address MEMADDR in debugged memory,
176 on using INFO. Returns length of the instruction, in bytes, which is
177 always 4. BIGENDIAN must be 1 if this is big-endian code, 0 if
178 this is little-endian code. */
181 _print_insn_mips (memaddr
, word
, info
)
183 struct disassemble_info
*info
;
184 unsigned long int word
;
187 register const char *d
;
189 for (i
= 0; i
< NUMOPCODES
; i
++)
191 if (mips_opcodes
[i
].pinfo
!= INSN_MACRO
)
193 register unsigned int match
= mips_opcodes
[i
].match
;
194 register unsigned int mask
= mips_opcodes
[i
].mask
;
195 if ((word
& mask
) == match
)
200 /* Handle undefined instructions. */
203 (*info
->fprintf_func
) (info
->stream
, "0x%x", word
);
207 (*info
->fprintf_func
) (info
->stream
, "%s", mips_opcodes
[i
].name
);
209 if (!(d
= mips_opcodes
[i
].args
))
212 (*info
->fprintf_func
) (info
->stream
, " ");
215 print_insn_arg (d
++, word
, memaddr
, info
);
221 print_insn_big_mips (memaddr
, info
)
223 struct disassemble_info
*info
;
226 int status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
228 return _print_insn_mips (memaddr
, _do_getb32 (buffer
), info
);
231 (*info
->memory_error_func
) (status
, memaddr
, info
);
237 print_insn_little_mips (memaddr
, info
)
239 struct disassemble_info
*info
;
242 int status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
244 return _print_insn_mips (memaddr
, _do_getl32 (buffer
), info
);
247 (*info
->memory_error_func
) (status
, memaddr
, info
);
This page took 0.036895 seconds and 4 git commands to generate.