]>
Commit | Line | Data |
---|---|---|
7da1e27d | 1 | /* Disassembler for the PA-RISC. Somewhat derived from sparc-pinsn.c. |
5140562f | 2 | Copyright 1989, 1990, 1992 Free Software Foundation, Inc. |
7da1e27d SG |
3 | |
4 | Contributed by the Center for Software Science at the | |
5 | University of Utah ([email protected]). | |
6 | ||
5140562f | 7 | This file is part of GDB. |
7da1e27d | 8 | |
5140562f | 9 | This program is free software; you can redistribute it and/or modify |
7da1e27d | 10 | it under the terms of the GNU General Public License as published by |
5140562f JG |
11 | the Free Software Foundation; either version 2 of the License, or |
12 | (at your option) any later version. | |
7da1e27d | 13 | |
5140562f | 14 | This program is distributed in the hope that it will be useful, |
7da1e27d SG |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
5140562f JG |
20 | along with this program; if not, write to the Free Software |
21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
7da1e27d SG |
22 | |
23 | #include "defs.h" | |
24 | #include "symtab.h" | |
25 | #include "opcode/hppa.h" | |
26 | ||
27 | char *control_reg[] = {"rctr", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
28 | "pidr1", "pidr2", "ccr", "sar", "pidr3", "pidr4", | |
29 | "iva", "eiem", "itmr", "pcsq", "pcoq", "iir", "isr", | |
30 | "ior", "ipsw", "eirr", "tr0", "tr1", "tr2", "tr3", | |
31 | "tr4", "tr5", "tr6", "tr7" | |
32 | }; | |
33 | ||
34 | char *compare_cond_names[] = {"", ",=", ",<", ",<=", ",<<", ",<<=", ",sv", | |
35 | ",od", ",tr", ",<>", ",>=", ",>", ",>>=", | |
36 | ",>>", ",nsv", ",ev" | |
37 | }; | |
38 | char *add_cond_names[] = {"", ",=", ",<", ",<=", ",nuv", ",znv", ",sv", | |
39 | ",od", ",tr", ",<>", ",>=", ",>", ",uv", | |
40 | ",vnz", ",nsv", ",ev" | |
41 | }; | |
42 | char *logical_cond_names[] = {"", ",=", ",<", ",<=", 0, 0, 0, ",od", | |
43 | ",tr", ",<>", ",>=", ",>", 0, 0, 0, ",ev"}; | |
44 | char *unit_cond_names[] = {"", 0, ",sbz", ",shz", ",sdc", 0, ",sbc", ",shc", | |
45 | ",tr", 0, ",nbz", ",nhz", ",ndc", 0, ",nbc", ",nhc" | |
46 | }; | |
47 | char *shift_cond_names[] = {"", ",=", ",<", ",od", ",tr", ",<>", ",>=", ",ev"}; | |
48 | ||
49 | char *index_compl_names[] = {"", ",m", ",s", ",sm"}; | |
50 | char *short_ldst_compl_names[] = {"", ",ma", "", ",mb"}; | |
51 | char *short_bytes_compl_names[] = {"", ",b,m", ",e", ",e,m"}; | |
52 | char *float_format_names[] = {",sgl", ",dbl", ",quad"}; | |
53 | char *float_comp_names[] = | |
54 | {",false?", ",false", ",?", ",!<=>", ",=", ",=t", ",?=", ",!<>", | |
55 | ",!?>=", ",<", ",?<", ",!>=", ",!?>", ",<=", ",?<=", ",!>", | |
56 | ",!?<=", ",>", ",?>", ",!<=", ",!?<", ",>=", ",?>=", ",!<", | |
57 | ",!?=", ",<>", ",!=", ",!=t", ",!?", ",<=>", ",true?", ",true" | |
58 | }; | |
59 | ||
60 | /* For a bunch of different instructions form an index into a | |
61 | completer name table. */ | |
62 | #define GET_COMPL(insn) (GET_FIELD (insn, 26, 26) | \ | |
63 | GET_FIELD (insn, 18, 18) << 1) | |
64 | ||
65 | #define GET_COND(insn) (GET_FIELD ((insn), 16, 18) + \ | |
66 | (GET_FIELD ((insn), 19, 19) ? 8 : 0)) | |
67 | ||
68 | void fput_reg (), fput_const (); | |
69 | ||
70 | /* Print one instruction from MEMADDR on STREAM. */ | |
71 | int | |
72 | print_insn (memaddr, stream) | |
73 | CORE_ADDR memaddr; | |
74 | FILE *stream; | |
75 | { | |
76 | unsigned int insn, i, op; | |
77 | ||
78 | read_memory (memaddr, &insn, sizeof (insn)); | |
79 | ||
80 | for (i = 0; i < NUMOPCODES; ++i) | |
81 | { | |
82 | const struct pa_opcode *opcode = &pa_opcodes[i]; | |
83 | if ((insn & opcode->mask) == opcode->match) | |
84 | { | |
85 | register const char *s; | |
86 | ||
87 | fputs_filtered (opcode->name, stream); | |
88 | ||
89 | if (!index ("cCY<?!@-+&U>~nZFM", opcode->args[0])) | |
90 | fputs_filtered (" ", stream); | |
91 | for (s = opcode->args; *s != '\0'; ++s) | |
92 | { | |
93 | switch (*s) | |
94 | { | |
95 | case 'x': | |
96 | fput_reg (GET_FIELD (insn, 11, 15), stream); | |
97 | break; | |
98 | case 'X': | |
99 | if (GET_FIELD (insn, 25, 25)) | |
100 | fput_reg_r (GET_FIELD (insn, 11, 15), stream); | |
101 | else | |
102 | fput_reg (GET_FIELD (insn, 11, 15), stream); | |
103 | break; | |
104 | case 'b': | |
105 | fput_reg (GET_FIELD (insn, 6, 10), stream); | |
106 | break; | |
107 | case '^': | |
108 | fput_creg (GET_FIELD (insn, 6, 10), stream); | |
109 | break; | |
110 | case 'E': | |
111 | if (GET_FIELD (insn, 25, 25)) | |
112 | fput_reg_r (GET_FIELD (insn, 6, 10), stream); | |
113 | else | |
114 | fput_reg (GET_FIELD (insn, 6, 10), stream); | |
115 | break; | |
116 | case 't': | |
117 | fput_reg (GET_FIELD (insn, 27, 31), stream); | |
118 | break; | |
119 | case 'v': | |
120 | if (GET_FIELD (insn, 25, 25)) | |
121 | fput_reg_r (GET_FIELD (insn, 27, 31), stream); | |
122 | else | |
123 | fput_reg (GET_FIELD (insn, 27, 31), stream); | |
124 | break; | |
125 | case '4': | |
126 | fput_creg (GET_FIELD (insn, 6, 10), stream); | |
127 | break; | |
128 | case '6': | |
129 | fput_reg (GET_FIELD (insn, 11, 15), stream); | |
130 | break; | |
131 | case '7': | |
132 | fput_reg (GET_FIELD (insn, 27, 31), stream); | |
133 | break; | |
134 | case '8': | |
135 | fput_reg (GET_FIELD (insn, 16, 20), stream); | |
136 | break; | |
137 | case '9': | |
138 | fput_reg (GET_FIELD (insn, 21, 25), stream); | |
139 | break; | |
140 | case '5': | |
141 | fput_const (extract_5_load (insn), stream); | |
142 | break; | |
143 | /* case 's': */ | |
144 | case 'S': | |
145 | fprintf_filtered (stream, "sr%d", extract_3 (insn)); | |
146 | break; | |
147 | case 'c': | |
148 | fprintf_filtered (stream, "%s ", | |
149 | index_compl_names[GET_COMPL (insn)]); | |
150 | break; | |
151 | case 'C': | |
152 | fprintf_filtered (stream, "%s ", | |
153 | short_ldst_compl_names[GET_COMPL (insn)]); | |
154 | break; | |
155 | case 'Y': | |
156 | fprintf_filtered (stream, "%s ", | |
157 | short_bytes_compl_names[GET_COMPL (insn)]); | |
158 | break; | |
159 | /* these four conditions are for the set of instructions | |
160 | which distinguish true/false conditions by opcode rather | |
161 | than by the 'f' bit (sigh): comb, comib, addb, addib */ | |
162 | case '<': | |
163 | fputs_filtered (compare_cond_names[GET_FIELD (insn, 16, 18)], | |
164 | stream); | |
165 | break; | |
166 | case '?': | |
167 | fputs_filtered (compare_cond_names[GET_FIELD (insn, 16, 18) + 8], | |
168 | stream); | |
169 | break; | |
170 | case '!': | |
171 | fputs_filtered (add_cond_names[GET_FIELD (insn, 16, 18)], | |
172 | stream); | |
173 | break; | |
174 | case '@': | |
175 | fputs_filtered (add_cond_names[GET_FIELD (insn, 16, 18) + 8], | |
176 | stream); | |
177 | break; | |
178 | case '-': | |
179 | fprintf_filtered (stream, "%s ", | |
180 | compare_cond_names[GET_COND (insn)]); | |
181 | break; | |
182 | case '+': | |
183 | fprintf_filtered (stream, "%s ", | |
184 | add_cond_names[GET_FIELD (insn, 16, 18)]); | |
185 | break; | |
186 | ||
187 | case '&': | |
188 | fprintf_filtered (stream, "%s ", | |
189 | logical_cond_names[GET_COND (insn)]); | |
190 | break; | |
191 | case 'U': | |
192 | fprintf_filtered (stream, "%s ", | |
193 | unit_cond_names[GET_COND (insn)]); | |
194 | break; | |
195 | case '>': | |
196 | case '~': | |
197 | fprintf_filtered (stream, "%s ", | |
198 | shift_cond_names[GET_FIELD (insn, 16, 18)]); | |
199 | break; | |
200 | case 'V': | |
201 | fput_const (extract_5_store (insn), stream); | |
202 | break; | |
203 | case 'i': | |
204 | fput_const (extract_11 (insn), stream); | |
205 | break; | |
206 | case 'j': | |
207 | fput_const (extract_14 (insn), stream); | |
208 | break; | |
209 | case 'k': | |
210 | fput_const (extract_21 (insn), stream); | |
211 | break; | |
212 | case 'n': | |
213 | if (insn & 0x2) | |
214 | fprintf_filtered (stream, ",n "); | |
215 | else | |
216 | fprintf_filtered (stream, " "); | |
217 | break; | |
218 | case 'w': | |
219 | print_address (memaddr + 8 + extract_12 (insn), stream); | |
220 | break; | |
221 | case 'W': | |
222 | /* don't interpret an address if it's an external branch | |
223 | instruction. */ | |
224 | op = GET_FIELD (insn, 0, 5); | |
225 | if (op != 0x38 /* be */ && op != 0x39 /* ble */) | |
226 | print_address (memaddr + 8 + extract_17 (insn), stream); | |
227 | else | |
228 | fput_const (extract_17 (insn), stream); | |
229 | break; | |
230 | case 'B': | |
231 | { | |
232 | int space; | |
233 | if (space = GET_FIELD (insn, 16, 17)) | |
234 | fprintf_filtered (stream, "sr%d,", space); | |
235 | fput_reg (GET_FIELD (insn, 6, 10), stream); | |
236 | break; | |
237 | } | |
238 | case 'p': | |
239 | fprintf_filtered (stream, "%d", | |
240 | 31 - GET_FIELD (insn, 22, 26)); | |
241 | break; | |
242 | case 'P': | |
243 | fprintf_filtered (stream, "%d", | |
244 | GET_FIELD (insn, 22, 26)); | |
245 | break; | |
246 | case 'T': | |
247 | fprintf_filtered (stream, "%d", | |
248 | 32 - GET_FIELD (insn, 27, 31)); | |
249 | break; | |
250 | case 'A': | |
251 | fput_const (GET_FIELD (insn, 6, 18), stream); | |
252 | break; | |
253 | case 'Z': | |
254 | if (GET_FIELD (insn, 26, 26)) | |
255 | fprintf_filtered (stream, ",m "); | |
256 | else | |
257 | fprintf_filtered (stream, " "); | |
258 | break; | |
259 | case 'D': | |
260 | fput_const (GET_FIELD (insn, 6, 31), stream); | |
261 | break; | |
262 | case 'f': | |
263 | fprintf_filtered (stream, ",%d", GET_FIELD (insn, 23, 25)); | |
264 | break; | |
265 | case 'O': | |
266 | fput_const ((GET_FIELD (insn, 6,20) << 5 | | |
267 | GET_FIELD (insn, 27, 31)), stream); | |
268 | break; | |
269 | case 'o': | |
270 | fput_const (GET_FIELD (insn, 6, 20), stream); | |
271 | break; | |
272 | case '2': | |
273 | fput_const ((GET_FIELD (insn, 6, 22) << 5 | | |
274 | GET_FIELD (insn, 27, 31)), stream); | |
275 | break; | |
276 | case '1': | |
277 | fput_const ((GET_FIELD (insn, 11, 20) << 5 | | |
278 | GET_FIELD (insn, 27, 31)), stream); | |
279 | break; | |
280 | case '0': | |
281 | fput_const ((GET_FIELD (insn, 16, 20) << 5 | | |
282 | GET_FIELD (insn, 27, 31)), stream); | |
283 | break; | |
284 | case 'u': | |
285 | fprintf_filtered (stream, "%d", GET_FIELD (insn, 23, 25)); | |
286 | break; | |
287 | case 'F': | |
288 | /* if no destination completer, need a space here */ | |
289 | if (GET_FIELD (insn, 21, 22) == 1) | |
290 | fputs_filtered (float_format_names[GET_FIELD (insn, 19, 20)], | |
291 | stream); | |
292 | else | |
293 | fprintf_filtered (stream, "%s ", | |
294 | float_format_names[GET_FIELD | |
295 | (insn, 19, 20)]); | |
296 | break; | |
297 | case 'G': | |
298 | fprintf_filtered (stream, "%s ", | |
299 | float_format_names[GET_FIELD (insn, | |
300 | 17, 18)]); | |
301 | break; | |
302 | case 'H': | |
303 | fputs_filtered (float_format_names[GET_FIELD | |
304 | (insn, 26, 26)], stream); | |
305 | break; | |
306 | case 'M': | |
307 | fputs_filtered (float_comp_names[GET_FIELD (insn, 27, 31)], | |
308 | stream); | |
309 | break; | |
310 | case '}': | |
311 | fprintf_filtered (stream, "fp%d", GET_FIELD (insn, 6, 10)); | |
312 | break; | |
313 | case '|': | |
314 | fprintf_filtered (stream, "fp%d", GET_FIELD (insn, 11, 15)); | |
315 | break; | |
316 | case '{': | |
317 | if (GET_FIELD (insn, 23, 25) == 0) | |
318 | fprintf_filtered (stream, "fp%d", | |
319 | GET_FIELD (insn, 27, 31)); | |
320 | else | |
321 | fprintf_filtered (stream, "cp%d", | |
322 | GET_FIELD (insn, 27, 31)); | |
323 | break; | |
324 | default: | |
325 | fprintf_filtered (stream, "%c", *s); | |
326 | break; | |
327 | } | |
328 | } | |
329 | return sizeof(insn); | |
330 | } | |
331 | } | |
332 | fprintf_filtered (stream, "%#8x", insn); | |
333 | return sizeof(insn); | |
334 | } | |
335 | ||
336 | /* Utility function to print registers */ | |
337 | ||
338 | void | |
339 | fput_reg (reg, stream) | |
340 | unsigned reg; | |
341 | FILE *stream; | |
342 | { | |
343 | if (reg) | |
344 | fputs_filtered (reg_names[reg], stream); | |
345 | else | |
346 | fputs_filtered ("r0", stream); | |
347 | } | |
348 | ||
349 | void | |
350 | fput_reg_r (reg, stream) | |
351 | unsigned reg; | |
352 | FILE *stream; | |
353 | { | |
354 | if (reg) | |
355 | fputs_filtered (reg_names[reg], stream); | |
356 | else | |
357 | fputs_filtered ("r0", stream); | |
358 | fputs_filtered ("R", stream); | |
359 | } | |
360 | ||
361 | void | |
362 | fput_creg (reg, stream) | |
363 | unsigned reg; | |
364 | FILE *stream; | |
365 | { | |
366 | fputs_filtered (control_reg[reg], stream); | |
367 | } | |
368 | ||
369 | /* print constants with sign */ | |
370 | ||
371 | void | |
372 | fput_const (num, stream) | |
373 | unsigned num; | |
374 | FILE *stream; | |
375 | { | |
376 | if ((int)num < 0) | |
377 | fprintf_filtered (stream, "-%x", -(int)num); | |
378 | else | |
379 | fprintf_filtered (stream, "%x", num); | |
380 | } |