Commit | Line | Data |
---|---|---|
7d9884b9 JG |
1 | /* Print instructions for Tahoe target machines, for GDB. |
2 | Copyright 1986, 1989, 1991 Free Software Foundation, Inc. | |
3 | Contributed by the State University of New York at Buffalo, by the | |
4 | Distributed Computer Systems Lab, Department of Computer Science, 1991. | |
cb173f45 | 5 | |
7d9884b9 JG |
6 | This file is part of GDB. |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
cb173f45 | 17 | |
7d9884b9 JG |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
21 | ||
cb173f45 | 22 | #include "defs.h" |
cb173f45 | 23 | #include "symtab.h" |
aab77d5f | 24 | #include "opcode/tahoe.h" |
cb173f45 JK |
25 | |
26 | /* Tahoe instructions are never longer than this. */ | |
27 | #define MAXLEN 62 | |
28 | ||
29 | /* Number of elements in the opcode table. */ | |
30 | #define NOPCODES (sizeof votstrs / sizeof votstrs[0]) | |
31 | ||
32 | extern char *reg_names[]; | |
33 | ||
34 | static unsigned char *print_insn_arg (); | |
35 | ||
36 | /* Print the Tahoe instruction at address MEMADDR in debugged memory, | |
37 | on STREAM. Returns length of the instruction, in bytes. */ | |
38 | ||
39 | int | |
40 | print_insn (memaddr, stream) | |
41 | CORE_ADDR memaddr; | |
42 | FILE *stream; | |
43 | { | |
44 | unsigned char buffer[MAXLEN]; | |
45 | register int i; | |
46 | register unsigned char *p; | |
47 | register char *d; | |
48 | ||
49 | read_memory (memaddr, buffer, MAXLEN); | |
50 | ||
51 | for (i = 0; i < NOPCODES; i++) | |
52 | if (votstrs[i].detail.code == buffer[0] | |
53 | || votstrs[i].detail.code == *(unsigned short *)buffer) | |
54 | break; | |
55 | ||
56 | /* Handle undefined instructions. */ | |
57 | if (i == NOPCODES) | |
58 | { | |
59 | fprintf (stream, "0%o", buffer[0]); | |
60 | return 1; | |
61 | } | |
62 | ||
63 | fprintf (stream, "%s", votstrs[i].name); | |
64 | ||
65 | /* Point at first byte of argument data, | |
66 | and at descriptor for first argument. */ | |
67 | p = buffer + 1 + (votstrs[i].detail.code >= 0x100); | |
68 | d = votstrs[i].detail.args; | |
69 | ||
70 | if (*d) | |
71 | fputc ('\t', stream); | |
72 | ||
73 | while (*d) | |
74 | { | |
75 | p = print_insn_arg (d, p, memaddr + (p - buffer), stream); | |
76 | d += 2; | |
77 | if (*d) | |
78 | fprintf (stream, ","); | |
79 | } | |
80 | return p - buffer; | |
81 | } | |
82 | /*******************************************************************/ | |
83 | static unsigned char * | |
84 | print_insn_arg (d, p, addr, stream) | |
85 | char *d; | |
86 | register char *p; | |
87 | CORE_ADDR addr; | |
88 | FILE *stream; | |
89 | { | |
90 | int temp1 = 0; | |
91 | register int regnum = *p & 0xf; | |
92 | float floatlitbuf; | |
93 | ||
94 | if (*d == 'b') | |
95 | { | |
96 | if (d[1] == 'b') | |
97 | fprintf (stream, "0x%x", addr + *p++ + 1); | |
98 | else | |
99 | { | |
100 | ||
101 | temp1 = *p; | |
102 | temp1 <<= 8; | |
103 | temp1 |= *(p + 1); | |
104 | fprintf (stream, "0x%x", addr + temp1 + 2); | |
105 | p += 2; | |
106 | } | |
107 | } | |
108 | else | |
109 | switch ((*p++ >> 4) & 0xf) | |
110 | { | |
111 | case 0: | |
112 | case 1: | |
113 | case 2: | |
7d9884b9 | 114 | case 3: /* Literal (short immediate byte) mode */ |
cb173f45 JK |
115 | if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h') |
116 | { | |
117 | *(int *)&floatlitbuf = 0x4000 + ((p[-1] & 0x3f) << 4); | |
118 | fprintf (stream, "$%f", floatlitbuf); | |
119 | } | |
120 | else | |
121 | fprintf (stream, "$%d", p[-1] & 0x3f); | |
122 | break; | |
123 | ||
124 | case 4: /* Indexed */ | |
125 | p = (char *) print_insn_arg (d, p, addr + 1, stream); | |
126 | fprintf (stream, "[%s]", reg_names[regnum]); | |
127 | break; | |
128 | ||
129 | case 5: /* Register */ | |
130 | fprintf (stream, reg_names[regnum]); | |
131 | break; | |
132 | ||
133 | case 7: /* Autodecrement */ | |
134 | fputc ('-', stream); | |
135 | case 6: /* Register deferred */ | |
136 | fprintf (stream, "(%s)", reg_names[regnum]); | |
137 | break; | |
138 | ||
139 | case 9: /* Absolute Address & Autoincrement deferred */ | |
140 | fputc ('*', stream); | |
141 | if (regnum == PC_REGNUM) | |
142 | { | |
143 | temp1 = *p; | |
144 | temp1 <<= 8; | |
145 | temp1 |= *(p +1); | |
146 | ||
147 | fputc ('$', stream); | |
148 | print_address (temp1, stream); | |
149 | p += 4; | |
150 | break; | |
151 | } | |
152 | case 8: /*Immediate & Autoincrement SP */ | |
153 | if (regnum == 8) /*88 is Immediate Byte Mode*/ | |
154 | fprintf (stream, "$%d", *p++); | |
155 | ||
156 | else if (regnum == 9) /*89 is Immediate Word Mode*/ | |
157 | { | |
158 | temp1 = *p; | |
159 | temp1 <<= 8; | |
160 | temp1 |= *(p +1); | |
161 | fprintf (stream, "$%d", temp1); | |
162 | p += 2; | |
163 | } | |
164 | ||
165 | else if (regnum == PC_REGNUM) /*8F is Immediate Long Mode*/ | |
166 | { | |
167 | temp1 = *p; | |
168 | temp1 <<=8; | |
169 | temp1 |= *(p +1); | |
170 | temp1 <<=8; | |
171 | temp1 |= *(p +2); | |
172 | temp1 <<= 8; | |
173 | temp1 |= *(p +3); | |
174 | fprintf (stream, "$%d", temp1); | |
175 | p += 4; | |
176 | } | |
177 | ||
178 | else /*8E is Autoincrement SP Mode*/ | |
179 | fprintf (stream, "(%s)+", reg_names[regnum]); | |
180 | break; | |
181 | ||
182 | case 11: /* Register + Byte Displacement Deferred Mode*/ | |
183 | fputc ('*', stream); | |
184 | case 10: /* Register + Byte Displacement Mode*/ | |
185 | if (regnum == PC_REGNUM) | |
186 | print_address (addr + *p + 2, stream); | |
187 | else | |
188 | fprintf (stream, "%d(%s)", *p, reg_names[regnum]); | |
189 | p += 1; | |
190 | break; | |
191 | ||
192 | case 13: /* Register + Word Displacement Deferred Mode*/ | |
193 | fputc ('*', stream); | |
194 | case 12: /* Register + Word Displacement Mode*/ | |
195 | temp1 = *p; | |
196 | temp1 <<= 8; | |
197 | temp1 |= *(p +1); | |
198 | if (regnum == PC_REGNUM) | |
199 | print_address (addr + temp1 + 3, stream); | |
200 | else | |
201 | fprintf (stream, "%d(%s)", temp1, reg_names[regnum]); | |
202 | p += 2; | |
203 | break; | |
204 | ||
205 | case 15: /* Register + Long Displacement Deferred Mode*/ | |
206 | fputc ('*', stream); | |
207 | case 14: /* Register + Long Displacement Mode*/ | |
208 | temp1 = *p; | |
209 | temp1 <<= 8; | |
210 | temp1 |= *(p +1); | |
211 | temp1 <<= 8; | |
212 | temp1 |= *(p +2); | |
213 | temp1 <<= 8; | |
214 | temp1 |= *(p +3); | |
215 | if (regnum == PC_REGNUM) | |
216 | print_address (addr + temp1 + 5, stream); | |
217 | else | |
218 | fprintf (stream, "%d(%s)", temp1, reg_names[regnum]); | |
219 | p += 4; | |
220 | } | |
221 | ||
222 | return (unsigned char *) p; | |
223 | } | |
224 | ||
225 | ||
226 | ||
227 | ||
228 | ||
229 | ||
230 | ||
231 | ||
232 | ||
233 | ||
234 | ||
235 | ||
236 |