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