]>
Commit | Line | Data |
---|---|---|
dd3b648e | 1 | /* Print mips instructions for GDB, the GNU debugger. |
7d9884b9 | 2 | Copyright 1989, 1991 Free Software Foundation, Inc. |
dd3b648e RP |
3 | Contributed by Nobuyuki Hikichi([email protected]) |
4 | ||
5 | This file is part of GDB. | |
6 | ||
99a7de40 | 7 | This program is free software; you can redistribute it and/or modify |
dd3b648e | 8 | it under the terms of the GNU General Public License as published by |
99a7de40 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
dd3b648e | 11 | |
99a7de40 | 12 | This program is distributed in the hope that it will be useful, |
dd3b648e RP |
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
99a7de40 JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
dd3b648e RP |
20 | |
21 | #include <stdio.h> | |
22 | ||
23 | #include "defs.h" | |
dd3b648e | 24 | #include "symtab.h" |
7e258d18 | 25 | #include "opcode/mips.h" |
dd3b648e RP |
26 | |
27 | /* Mips instructions are never longer than this many bytes. */ | |
28 | #define MAXLEN 4 | |
29 | ||
30 | /* Number of elements in the opcode table. */ | |
31 | #define NOPCODES (sizeof mips_opcodes / sizeof mips_opcodes[0]) | |
32 | ||
33 | #define MKLONG(p) *(unsigned long*)p | |
34 | ||
35 | extern char *reg_names[]; | |
36 | ||
37 | \f | |
38 | /* subroutine */ | |
39 | static unsigned char * | |
40 | print_insn_arg (d, l, stream, pc) | |
41 | char *d; | |
42 | register unsigned long int *l; | |
43 | FILE *stream; | |
44 | CORE_ADDR pc; | |
45 | { | |
46 | switch (*d) | |
47 | { | |
48 | case ',': | |
49 | case '(': | |
50 | case ')': | |
51 | fputc (*d, stream); | |
52 | break; | |
53 | ||
54 | case 's': | |
55 | fprintf (stream, "$%s", reg_names[((struct op_i_fmt *) l)->rs]); | |
56 | break; | |
57 | ||
58 | case 't': | |
59 | fprintf (stream, "$%s", reg_names[((struct op_i_fmt *) l)->rt]); | |
60 | break; | |
61 | ||
62 | case 'i': | |
63 | fprintf (stream, "%d", ((struct op_i_fmt *) l)->immediate); | |
64 | break; | |
65 | ||
66 | case 'j': /* same as i, but sign-extended */ | |
67 | fprintf (stream, "%d", ((struct op_b_fmt *) l)->delta); | |
68 | break; | |
69 | ||
70 | case 'a': | |
71 | print_address ((pc & 0xF0000000) | (((struct op_j_fmt *)l)->target << 2), | |
72 | stream); | |
73 | break; | |
74 | ||
75 | case 'b': | |
76 | print_address ((((struct op_b_fmt *) l)->delta << 2) + pc + 4, stream); | |
77 | break; | |
78 | ||
79 | case 'd': | |
b8c50f09 | 80 | fprintf (stream, "$%s", reg_names[((struct op_r_fmt *) l)->rd]); |
dd3b648e RP |
81 | break; |
82 | ||
83 | case 'h': | |
84 | fprintf (stream, "0x%x", ((struct op_r_fmt *) l)->shamt); | |
85 | break; | |
86 | ||
87 | case 'S': | |
88 | fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->fs); | |
89 | break; | |
90 | ||
91 | case 'T': | |
92 | fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->ft); | |
93 | break; | |
94 | ||
95 | case 'D': | |
96 | fprintf (stream, "$f%d", ((struct fop_r_fmt *) l)->fd); | |
97 | break; | |
98 | ||
99 | default: | |
100 | fprintf (stream, "# internal error, undefined modifier(%c)", *d); | |
101 | break; | |
102 | } | |
103 | } | |
104 | \f | |
105 | /* Print the mips instruction at address MEMADDR in debugged memory, | |
106 | on STREAM. Returns length of the instruction, in bytes, which | |
107 | is always 4. */ | |
108 | ||
109 | int | |
110 | print_insn (memaddr, stream) | |
111 | CORE_ADDR memaddr; | |
112 | FILE *stream; | |
113 | { | |
114 | unsigned char buffer[MAXLEN]; | |
115 | register int i; | |
116 | register char *d; | |
117 | unsigned long int l; | |
118 | ||
119 | read_memory (memaddr, buffer, MAXLEN); | |
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 | } |