1 /* Print mips instructions for GDB, the GNU debugger.
2 Copyright (C) 1989 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. */
26 #include "mips-opcode.h"
28 /* Mips instructions are never longer than this many bytes. */
31 /* Number of elements in the opcode table. */
32 #define NOPCODES (sizeof mips_opcodes / sizeof mips_opcodes[0])
34 #define MKLONG(p) *(unsigned long*)p
36 extern char *reg_names[];
40 static unsigned char *
41 print_insn_arg (d, l, stream, pc)
43 register unsigned long int *l;
56 fprintf (stream, "$%s", reg_names[((struct op_i_fmt *) l)->rs]);
60 fprintf (stream, "$%s", reg_names[((struct op_i_fmt *) l)->rt]);
64 fprintf (stream, "%d", ((struct op_i_fmt *) l)->immediate);
67 case 'j': /* same as i, but sign-extended */
68 fprintf (stream, "%d", ((struct op_b_fmt *) l)->delta);
72 print_address ((pc & 0xF0000000) | (((struct op_j_fmt *)l)->target << 2),
77 print_address ((((struct op_b_fmt *) l)->delta << 2) + pc + 4, stream);
81 fprintf (stream, "%s", reg_names[((struct op_r_fmt *) l)->rd]);
85 fprintf (stream, "0x%x", ((struct op_r_fmt *) l)->shamt);
89 fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->fs);
93 fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->ft);
97 fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->fd);
101 fprintf (stream, "# internal error, undefined modifier(%c)", *d);
106 /* Print the mips instruction at address MEMADDR in debugged memory,
107 on STREAM. Returns length of the instruction, in bytes, which
111 print_insn (memaddr, stream)
115 unsigned char buffer[MAXLEN];
120 read_memory (memaddr, buffer, MAXLEN);
122 for (i = 0; i < NOPCODES; i++)
124 register unsigned int opcode = mips_opcodes[i].opcode;
125 register unsigned int match = mips_opcodes[i].match;
126 if ((*(unsigned int*)buffer & match) == opcode)
131 /* Handle undefined instructions. */
134 fprintf (stream, "0x%x",l);
138 fprintf (stream, "%s", mips_opcodes[i].name);
140 if (!(d = mips_opcodes[i].args))
146 print_insn_arg (d++, &l, stream, memaddr);