* command.c (shell_escape, make_command, _initialze_command):
[deliverable/binutils-gdb.git] / gdb / mips-pinsn.c
CommitLineData
dd3b648e 1/* Print mips instructions for GDB, the GNU debugger.
2d62e807 2 Copyright 1989, 1991, 1992 Free Software Foundation, Inc.
609f87d4 3 Contributed by Nobuyuki Hikichi(hikichi@sra.co.jp).
dd3b648e
RP
4
5This file is part of GDB.
6
99a7de40 7This program is free software; you can redistribute it and/or modify
dd3b648e 8it under the terms of the GNU General Public License as published by
99a7de40
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
dd3b648e 11
99a7de40 12This program is distributed in the hope that it will be useful,
dd3b648e
RP
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
99a7de40
JG
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
dd3b648e 20
dd3b648e 21#include "defs.h"
dd3b648e 22#include "symtab.h"
7e258d18 23#include "opcode/mips.h"
dd3b648e
RP
24
25/* Mips instructions are never longer than this many bytes. */
26#define MAXLEN 4
27
28/* Number of elements in the opcode table. */
29#define NOPCODES (sizeof mips_opcodes / sizeof mips_opcodes[0])
30
31#define MKLONG(p) *(unsigned long*)p
dd3b648e
RP
32\f
33/* subroutine */
34static unsigned char *
35print_insn_arg (d, l, stream, pc)
36 char *d;
37 register unsigned long int *l;
38 FILE *stream;
39 CORE_ADDR pc;
40{
41 switch (*d)
42 {
43 case ',':
44 case '(':
45 case ')':
46 fputc (*d, stream);
47 break;
48
49 case 's':
50 fprintf (stream, "$%s", reg_names[((struct op_i_fmt *) l)->rs]);
51 break;
52
53 case 't':
54 fprintf (stream, "$%s", reg_names[((struct op_i_fmt *) l)->rt]);
55 break;
56
57 case 'i':
58 fprintf (stream, "%d", ((struct op_i_fmt *) l)->immediate);
59 break;
60
61 case 'j': /* same as i, but sign-extended */
62 fprintf (stream, "%d", ((struct op_b_fmt *) l)->delta);
63 break;
64
65 case 'a':
66 print_address ((pc & 0xF0000000) | (((struct op_j_fmt *)l)->target << 2),
67 stream);
68 break;
69
70 case 'b':
71 print_address ((((struct op_b_fmt *) l)->delta << 2) + pc + 4, stream);
72 break;
73
74 case 'd':
b8c50f09 75 fprintf (stream, "$%s", reg_names[((struct op_r_fmt *) l)->rd]);
dd3b648e
RP
76 break;
77
78 case 'h':
79 fprintf (stream, "0x%x", ((struct op_r_fmt *) l)->shamt);
80 break;
81
ebeccdf0
JG
82 case 'B':
83 fprintf (stream, "0x%x", ((struct op_brk_fmt *) l)->code);
84 break;
85
dd3b648e
RP
86 case 'S':
87 fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->fs);
88 break;
89
90 case 'T':
91 fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->ft);
92 break;
93
94 case 'D':
95 fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->fd);
96 break;
97
98 default:
99 fprintf (stream, "# internal error, undefined modifier(%c)", *d);
100 break;
101 }
102}
103\f
104/* Print the mips instruction at address MEMADDR in debugged memory,
105 on STREAM. Returns length of the instruction, in bytes, which
106 is always 4. */
107
108int
109print_insn (memaddr, stream)
110 CORE_ADDR memaddr;
111 FILE *stream;
112{
113 unsigned char buffer[MAXLEN];
114 register int i;
115 register char *d;
116 unsigned long int l;
117
118 read_memory (memaddr, buffer, MAXLEN);
2d62e807 119 SWAP_TARGET_AND_HOST (buffer, MAXLEN);
dd3b648e
RP
120
121 for (i = 0; i < NOPCODES; i++)
122 {
123 register unsigned int opcode = mips_opcodes[i].opcode;
124 register unsigned int match = mips_opcodes[i].match;
125 if ((*(unsigned int*)buffer & match) == opcode)
126 break;
127 }
128
129 l = MKLONG (buffer);
130 /* Handle undefined instructions. */
131 if (i == NOPCODES)
132 {
133 fprintf (stream, "0x%x",l);
134 return 4;
135 }
136
137 fprintf (stream, "%s", mips_opcodes[i].name);
138
139 if (!(d = mips_opcodes[i].args))
140 return 4;
141
142 fputc (' ', stream);
143
144 while (*d)
145 print_insn_arg (d++, &l, stream, memaddr);
146
147 return 4;
148}
This page took 0.080484 seconds and 4 git commands to generate.