* doc/gdb.texinfo (appendix "Installing GDB"): changes in configure.
[deliverable/binutils-gdb.git] / gdb / mips-pinsn.c
CommitLineData
dd3b648e
RP
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)
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
RP
20
21#include <stdio.h>
22
23#include "defs.h"
24#include "param.h"
25#include "symtab.h"
26#include "mips-opcode.h"
27
28/* Mips instructions are never longer than this many bytes. */
29#define MAXLEN 4
30
31/* Number of elements in the opcode table. */
32#define NOPCODES (sizeof mips_opcodes / sizeof mips_opcodes[0])
33
34#define MKLONG(p) *(unsigned long*)p
35
36extern char *reg_names[];
37
38\f
39/* subroutine */
40static unsigned char *
41print_insn_arg (d, l, stream, pc)
42 char *d;
43 register unsigned long int *l;
44 FILE *stream;
45 CORE_ADDR pc;
46{
47 switch (*d)
48 {
49 case ',':
50 case '(':
51 case ')':
52 fputc (*d, stream);
53 break;
54
55 case 's':
56 fprintf (stream, "$%s", reg_names[((struct op_i_fmt *) l)->rs]);
57 break;
58
59 case 't':
60 fprintf (stream, "$%s", reg_names[((struct op_i_fmt *) l)->rt]);
61 break;
62
63 case 'i':
64 fprintf (stream, "%d", ((struct op_i_fmt *) l)->immediate);
65 break;
66
67 case 'j': /* same as i, but sign-extended */
68 fprintf (stream, "%d", ((struct op_b_fmt *) l)->delta);
69 break;
70
71 case 'a':
72 print_address ((pc & 0xF0000000) | (((struct op_j_fmt *)l)->target << 2),
73 stream);
74 break;
75
76 case 'b':
77 print_address ((((struct op_b_fmt *) l)->delta << 2) + pc + 4, stream);
78 break;
79
80 case 'd':
b8c50f09 81 fprintf (stream, "$%s", reg_names[((struct op_r_fmt *) l)->rd]);
dd3b648e
RP
82 break;
83
84 case 'h':
85 fprintf (stream, "0x%x", ((struct op_r_fmt *) l)->shamt);
86 break;
87
88 case 'S':
89 fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->fs);
90 break;
91
92 case 'T':
93 fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->ft);
94 break;
95
96 case 'D':
97 fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->fd);
98 break;
99
100 default:
101 fprintf (stream, "# internal error, undefined modifier(%c)", *d);
102 break;
103 }
104}
105\f
106/* Print the mips instruction at address MEMADDR in debugged memory,
107 on STREAM. Returns length of the instruction, in bytes, which
108 is always 4. */
109
110int
111print_insn (memaddr, stream)
112 CORE_ADDR memaddr;
113 FILE *stream;
114{
115 unsigned char buffer[MAXLEN];
116 register int i;
117 register char *d;
118 unsigned long int l;
119
120 read_memory (memaddr, buffer, MAXLEN);
121
122 for (i = 0; i < NOPCODES; i++)
123 {
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)
127 break;
128 }
129
130 l = MKLONG (buffer);
131 /* Handle undefined instructions. */
132 if (i == NOPCODES)
133 {
134 fprintf (stream, "0x%x",l);
135 return 4;
136 }
137
138 fprintf (stream, "%s", mips_opcodes[i].name);
139
140 if (!(d = mips_opcodes[i].args))
141 return 4;
142
143 fputc (' ', stream);
144
145 while (*d)
146 print_insn_arg (d++, &l, stream, memaddr);
147
148 return 4;
149}
This page took 0.042224 seconds and 4 git commands to generate.