Commit | Line | Data |
---|---|---|
5d0734a7 JK |
1 | /* Print Motorola 68k instructions. |
2 | Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc. | |
3 | ||
4 | This file is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License as published by | |
6 | the Free Software Foundation; either version 2 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program; if not, write to the Free Software | |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
17 | ||
18 | #include "dis-asm.h" | |
19 | #include "ieee-float.h" | |
20 | ||
21 | extern CONST struct ext_format ext_format_68881; | |
22 | ||
23 | /* Opcode/m68k.h is a massive table. As a kludge, break it up into | |
24 | two pieces. This makes nonportable C -- FIXME -- it assumes that | |
25 | two data items declared near each other will be contiguous in | |
26 | memory. This kludge can be removed, FIXME, when GCC is fixed to not | |
27 | be a hog about initializers. */ | |
28 | ||
29 | #ifdef __GNUC__ | |
30 | #define BREAK_UP_BIG_DECL }; \ | |
31 | struct m68k_opcode m68k_opcodes_2[] = { | |
32 | #define AND_OTHER_PART sizeof (m68k_opcodes_2) | |
33 | #endif | |
34 | ||
35 | #include "opcode/m68k.h" | |
36 | ||
37 | ||
38 | /* Local function prototypes */ | |
39 | ||
40 | static int | |
cbe61cc6 | 41 | fetch_arg PARAMS ((unsigned char *, int, int, disassemble_info *)); |
5d0734a7 JK |
42 | |
43 | static void | |
44 | print_base PARAMS ((int, int, disassemble_info*)); | |
45 | ||
46 | static unsigned char * | |
47 | print_indexed PARAMS ((int, unsigned char *, bfd_vma, disassemble_info *)); | |
48 | ||
49 | static unsigned char * | |
50 | print_insn_arg PARAMS ((char *, unsigned char *, unsigned char *, bfd_vma, | |
51 | disassemble_info *)); | |
52 | ||
53 | /* Sign-extend an (unsigned char). */ | |
54 | #if __STDC__ == 1 | |
55 | #define COERCE_SIGNED_CHAR(ch) ((signed char)(ch)) | |
56 | #else | |
57 | #define COERCE_SIGNED_CHAR(ch) ((int)(((ch) ^ 0x80) & 0xFF) - 128) | |
58 | #endif | |
59 | ||
60 | CONST char * CONST fpcr_names[] = { | |
61 | "", "fpiar", "fpsr", "fpiar/fpsr", "fpcr", | |
62 | "fpiar/fpcr", "fpsr/fpcr", "fpiar/fpsr/fpcr"}; | |
63 | ||
64 | static char *reg_names[] = { | |
65 | "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a0", | |
66 | "a1", "a2", "a3", "a4", "a5", "fp", "sp", "ps", "pc"}; | |
67 | ||
68 | /* Define accessors for 68K's 1, 2, and 4-byte signed quantities. | |
69 | The _SHIFT values move the quantity to the high order end of an | |
70 | `int' value, so it will sign-extend. Probably a few more casts | |
71 | are needed to make it compile without warnings on finicky systems. */ | |
72 | #define BITS_PER_BYTE 8 | |
73 | #define WORD_SHIFT (BITS_PER_BYTE * ((sizeof (int)) - 2)) | |
74 | #define LONG_SHIFT (BITS_PER_BYTE * ((sizeof (int)) - 4)) | |
75 | ||
76 | #define NEXTBYTE(p) (p += 2, FETCH_DATA (info, p), COERCE_SIGNED_CHAR(p[-1])) | |
77 | ||
78 | #define NEXTWORD(p) \ | |
79 | (p += 2, FETCH_DATA (info, p), \ | |
80 | (((int)((p[-2] << 8) + p[-1])) << WORD_SHIFT) >> WORD_SHIFT) | |
81 | ||
82 | #define NEXTLONG(p) \ | |
83 | (p += 4, FETCH_DATA (info, p), \ | |
84 | (((int)((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1])) \ | |
85 | << LONG_SHIFT) >> LONG_SHIFT) | |
86 | ||
87 | /* NEXTSINGLE and NEXTDOUBLE handle alignment problems, but not | |
88 | * byte-swapping or other float format differences. FIXME! */ | |
89 | ||
90 | union number { | |
91 | double d; | |
92 | float f; | |
93 | char c[10]; | |
94 | }; | |
95 | ||
96 | #define NEXTSINGLE(val, p) \ | |
97 | { int i; union number u;\ | |
98 | FETCH_DATA (info, p + sizeof (float));\ | |
99 | for (i = 0; i < sizeof(float); i++) u.c[i] = *p++; \ | |
100 | val = u.f; } | |
101 | ||
102 | #define NEXTDOUBLE(val, p) \ | |
103 | { int i; union number u;\ | |
104 | FETCH_DATA (info, p + sizeof (double));\ | |
105 | for (i = 0; i < sizeof(double); i++) u.c[i] = *p++; \ | |
106 | val = u.d; } | |
107 | ||
108 | /* Need a function to convert from extended to double precision... */ | |
109 | #define NEXTEXTEND(p) \ | |
110 | (p += 12, FETCH_DATA (info, p), 0.0) | |
111 | ||
112 | /* Need a function to convert from packed to double | |
113 | precision. Actually, it's easier to print a | |
114 | packed number than a double anyway, so maybe | |
115 | there should be a special case to handle this... */ | |
116 | #define NEXTPACKED(p) \ | |
117 | (p += 12, FETCH_DATA (info, p), 0.0) | |
118 | ||
119 | \f | |
120 | /* Maximum length of an instruction. */ | |
121 | #define MAXLEN 22 | |
122 | ||
123 | #include <setjmp.h> | |
124 | ||
125 | struct private | |
126 | { | |
127 | /* Points to first byte not fetched. */ | |
128 | bfd_byte *max_fetched; | |
129 | bfd_byte the_buffer[MAXLEN]; | |
130 | bfd_vma insn_start; | |
131 | jmp_buf bailout; | |
132 | }; | |
133 | ||
134 | /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive) | |
135 | to ADDR (exclusive) are valid. Returns 1 for success, longjmps | |
136 | on error. */ | |
137 | #define FETCH_DATA(info, addr) \ | |
138 | ((addr) <= ((struct private *)(info->private_data))->max_fetched \ | |
139 | ? 1 : fetch_data ((info), (addr))) | |
140 | ||
141 | static int | |
142 | fetch_data (info, addr) | |
143 | struct disassemble_info *info; | |
144 | bfd_byte *addr; | |
145 | { | |
146 | int status; | |
147 | struct private *priv = (struct private *)info->private_data; | |
148 | bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer); | |
149 | ||
150 | status = (*info->read_memory_func) (start, | |
151 | priv->max_fetched, | |
152 | addr - priv->max_fetched, | |
153 | info); | |
154 | if (status != 0) | |
155 | { | |
156 | (*info->memory_error_func) (status, start, info); | |
05545edc | 157 | longjmp (priv->bailout, 1); |
5d0734a7 JK |
158 | } |
159 | else | |
160 | priv->max_fetched = addr; | |
161 | return 1; | |
162 | } | |
163 | \f | |
164 | static void | |
165 | m68k_opcode_error(info, code, place) | |
166 | struct disassemble_info *info; | |
167 | int code, place; | |
168 | { | |
169 | (*info->fprintf_func)(info->stream, | |
170 | "<internal error in opcode table: \"%c%c\">", | |
171 | code, place); | |
172 | } | |
173 | ||
174 | /* Print the m68k instruction at address MEMADDR in debugged memory, | |
175 | on STREAM. Returns length of the instruction, in bytes. */ | |
176 | ||
177 | int | |
178 | print_insn_m68k (memaddr, info) | |
179 | bfd_vma memaddr; | |
180 | disassemble_info *info; | |
181 | { | |
182 | register int i; | |
183 | register unsigned char *p; | |
184 | register char *d; | |
185 | register unsigned long bestmask; | |
186 | int best; | |
187 | struct private priv; | |
188 | bfd_byte *buffer = priv.the_buffer; | |
189 | ||
190 | info->private_data = (PTR) &priv; | |
191 | priv.max_fetched = priv.the_buffer; | |
192 | priv.insn_start = memaddr; | |
193 | if (setjmp (priv.bailout) != 0) | |
194 | /* Error return. */ | |
195 | return -1; | |
196 | ||
197 | bestmask = 0; | |
198 | best = -1; | |
199 | FETCH_DATA (info, buffer + 2); | |
200 | for (i = 0; i < numopcodes; i++) | |
201 | { | |
202 | register unsigned long opcode = m68k_opcodes[i].opcode; | |
203 | register unsigned long match = m68k_opcodes[i].match; | |
204 | if (((0xff & buffer[0] & (match >> 24)) == (0xff & (opcode >> 24))) | |
205 | && ((0xff & buffer[1] & (match >> 16)) == (0xff & (opcode >> 16))) | |
206 | /* Only fetch the next two bytes if we need to. */ | |
207 | && (((0xffff & match) == 0) | |
208 | || | |
209 | (FETCH_DATA (info, buffer + 4) | |
210 | && ((0xff & buffer[2] & (match >> 8)) == (0xff & (opcode >> 8))) | |
211 | && ((0xff & buffer[3] & match) == (0xff & opcode))) | |
212 | )) | |
213 | { | |
214 | /* Don't use for printout the variants of divul and divsl | |
215 | that have the same register number in two places. | |
216 | The more general variants will match instead. */ | |
217 | for (d = m68k_opcodes[i].args; *d; d += 2) | |
218 | if (d[1] == 'D') | |
219 | break; | |
220 | ||
221 | /* Don't use for printout the variants of most floating | |
222 | point coprocessor instructions which use the same | |
223 | register number in two places, as above. */ | |
224 | if (*d == 0) | |
225 | for (d = m68k_opcodes[i].args; *d; d += 2) | |
226 | if (d[1] == 't') | |
227 | break; | |
228 | ||
229 | if (*d == 0 && match > bestmask) | |
230 | { | |
231 | best = i; | |
232 | bestmask = match; | |
233 | } | |
234 | } | |
235 | } | |
236 | ||
237 | /* Handle undefined instructions. */ | |
238 | if (best < 0) | |
239 | { | |
240 | (*info->fprintf_func) (info->stream, "0%o", | |
241 | (buffer[0] << 8) + buffer[1]); | |
242 | return 2; | |
243 | } | |
244 | ||
245 | (*info->fprintf_func) (info->stream, "%s", m68k_opcodes[best].name); | |
246 | ||
247 | /* Point at first word of argument data, | |
248 | and at descriptor for first argument. */ | |
249 | p = buffer + 2; | |
250 | ||
e6fb7139 JK |
251 | /* Figure out how long the fixed-size portion of the instruction is. |
252 | The only place this is stored in the opcode table is | |
253 | in the arguments--look for arguments which specify fields in the 2nd | |
254 | or 3rd words of the instruction. */ | |
5d0734a7 JK |
255 | for (d = m68k_opcodes[best].args; *d; d += 2) |
256 | { | |
e6fb7139 JK |
257 | /* I don't think it is necessary to be checking d[0] here; I suspect |
258 | all this could be moved to the case statement below. */ | |
5d0734a7 JK |
259 | if (d[0] == '#') |
260 | { | |
261 | if (d[1] == 'l' && p - buffer < 6) | |
262 | p = buffer + 6; | |
263 | else if (p - buffer < 4 && d[1] != 'C' && d[1] != '8' ) | |
264 | p = buffer + 4; | |
265 | } | |
5d0734a7 JK |
266 | if ((d[0] == 'L' || d[0] == 'l') && d[1] == 'w' && p - buffer < 4) |
267 | p = buffer + 4; | |
e6fb7139 JK |
268 | switch (d[1]) |
269 | { | |
270 | case '1': | |
271 | case '2': | |
272 | case '3': | |
273 | case '7': | |
274 | case '8': | |
275 | case '9': | |
276 | if (p - buffer < 4) | |
277 | p = buffer + 4; | |
278 | break; | |
279 | case '4': | |
280 | case '5': | |
281 | case '6': | |
282 | if (p - buffer < 6) | |
283 | p = buffer + 6; | |
284 | break; | |
285 | default: | |
286 | break; | |
287 | } | |
5d0734a7 | 288 | } |
e6fb7139 JK |
289 | /* pflusha is an exception; it takes no arguments but is two words long. */ |
290 | if (buffer[0] == 0xf0 && buffer[1] == 0 && buffer[2] == 0x24 && | |
291 | buffer[3] == 0) | |
292 | p = buffer + 4; | |
5d0734a7 JK |
293 | |
294 | FETCH_DATA (info, p); | |
295 | ||
296 | d = m68k_opcodes[best].args; | |
297 | ||
298 | if (*d) | |
299 | (*info->fprintf_func) (info->stream, " "); | |
300 | ||
301 | while (*d) | |
302 | { | |
303 | p = print_insn_arg (d, buffer, p, memaddr + p - buffer, info); | |
304 | d += 2; | |
305 | if (*d && *(d - 2) != 'I' && *d != 'k') | |
306 | (*info->fprintf_func) (info->stream, ","); | |
307 | } | |
308 | return p - buffer; | |
309 | } | |
310 | ||
311 | static unsigned char * | |
312 | print_insn_arg (d, buffer, p, addr, info) | |
313 | char *d; | |
314 | unsigned char *buffer; | |
315 | register unsigned char *p; | |
316 | bfd_vma addr; /* PC for this arg to be relative to */ | |
317 | disassemble_info *info; | |
318 | { | |
319 | register int val = 0; | |
320 | register int place = d[1]; | |
321 | int regno; | |
322 | register CONST char *regname; | |
323 | register unsigned char *p1; | |
324 | double flval; | |
325 | int flt_p; | |
326 | ||
327 | switch (*d) | |
328 | { | |
329 | case 'c': /* cache identifier */ | |
330 | { | |
331 | static char *cacheFieldName[] = { "NOP", "dc", "ic", "bc" }; | |
332 | val = fetch_arg (buffer, place, 2, info); | |
333 | (*info->fprintf_func) (info->stream, cacheFieldName[val]); | |
334 | break; | |
335 | } | |
336 | ||
337 | case 'a': /* address register indirect only. Cf. case '+'. */ | |
338 | { | |
339 | (*info->fprintf_func) | |
340 | (info->stream, | |
341 | "%s@", | |
342 | reg_names [fetch_arg (buffer, place, 3, info) + 8]); | |
343 | break; | |
344 | } | |
345 | ||
346 | case '_': /* 32-bit absolute address for move16. */ | |
347 | { | |
348 | val = NEXTLONG (p); | |
349 | (*info->fprintf_func) (info->stream, "@#"); | |
e6fb7139 | 350 | (*info->print_address_func) (val, info); |
5d0734a7 JK |
351 | break; |
352 | } | |
353 | ||
354 | case 'C': | |
355 | (*info->fprintf_func) (info->stream, "ccr"); | |
356 | break; | |
357 | ||
358 | case 'S': | |
359 | (*info->fprintf_func) (info->stream, "sr"); | |
360 | break; | |
361 | ||
362 | case 'U': | |
363 | (*info->fprintf_func) (info->stream, "usp"); | |
364 | break; | |
365 | ||
366 | case 'J': | |
367 | { | |
368 | static struct { char *name; int value; } names[] | |
369 | = {{"sfc", 0x000}, {"dfc", 0x001}, {"cacr", 0x002}, | |
370 | {"tc", 0x003}, {"itt0",0x004}, {"itt1", 0x005}, | |
371 | {"dtt0",0x006}, {"dtt1",0x007}, | |
372 | {"usp", 0x800}, {"vbr", 0x801}, {"caar", 0x802}, | |
e6fb7139 JK |
373 | {"msp", 0x803}, {"isp", 0x804}, |
374 | ||
375 | /* Should we be calling this psr like we do in case 'Y'? */ | |
376 | {"mmusr",0x805}, | |
377 | ||
5d0734a7 JK |
378 | {"urp", 0x806}, {"srp", 0x807}}; |
379 | ||
380 | val = fetch_arg (buffer, place, 12, info); | |
381 | for (regno = sizeof names / sizeof names[0] - 1; regno >= 0; regno--) | |
382 | if (names[regno].value == val) | |
383 | { | |
384 | (*info->fprintf_func) (info->stream, names[regno].name); | |
385 | break; | |
386 | } | |
387 | if (regno < 0) | |
388 | (*info->fprintf_func) (info->stream, "%d", val); | |
389 | } | |
390 | break; | |
391 | ||
392 | case 'Q': | |
393 | val = fetch_arg (buffer, place, 3, info); | |
394 | /* 0 means 8, except for the bkpt instruction... */ | |
395 | if (val == 0 && d[1] != 's') | |
396 | val = 8; | |
397 | (*info->fprintf_func) (info->stream, "#%d", val); | |
398 | break; | |
399 | ||
400 | case 'M': | |
401 | val = fetch_arg (buffer, place, 8, info); | |
402 | if (val & 0x80) | |
403 | val = val - 0x100; | |
404 | (*info->fprintf_func) (info->stream, "#%d", val); | |
405 | break; | |
406 | ||
407 | case 'T': | |
408 | val = fetch_arg (buffer, place, 4, info); | |
409 | (*info->fprintf_func) (info->stream, "#%d", val); | |
410 | break; | |
411 | ||
412 | case 'D': | |
413 | (*info->fprintf_func) (info->stream, "%s", | |
414 | reg_names[fetch_arg (buffer, place, 3, info)]); | |
415 | break; | |
416 | ||
417 | case 'A': | |
418 | (*info->fprintf_func) | |
419 | (info->stream, "%s", | |
420 | reg_names[fetch_arg (buffer, place, 3, info) + 010]); | |
421 | break; | |
422 | ||
423 | case 'R': | |
424 | (*info->fprintf_func) | |
425 | (info->stream, "%s", | |
426 | reg_names[fetch_arg (buffer, place, 4, info)]); | |
427 | break; | |
428 | ||
429 | case 'r': | |
430 | (*info->fprintf_func) | |
431 | (info->stream, "%s@", | |
432 | reg_names[fetch_arg (buffer, place, 4, info)]); | |
433 | break; | |
434 | ||
435 | case 'F': | |
436 | (*info->fprintf_func) | |
437 | (info->stream, "fp%d", | |
438 | fetch_arg (buffer, place, 3, info)); | |
439 | break; | |
440 | ||
441 | case 'O': | |
442 | val = fetch_arg (buffer, place, 6, info); | |
443 | if (val & 0x20) | |
444 | (*info->fprintf_func) (info->stream, "%s", reg_names [val & 7]); | |
445 | else | |
446 | (*info->fprintf_func) (info->stream, "%d", val); | |
447 | break; | |
448 | ||
449 | case '+': | |
450 | (*info->fprintf_func) | |
451 | (info->stream, "%s@+", | |
452 | reg_names[fetch_arg (buffer, place, 3, info) + 8]); | |
453 | break; | |
454 | ||
455 | case '-': | |
456 | (*info->fprintf_func) | |
457 | (info->stream, "%s@-", | |
458 | reg_names[fetch_arg (buffer, place, 3, info) + 8]); | |
459 | break; | |
460 | ||
461 | case 'k': | |
462 | if (place == 'k') | |
463 | (*info->fprintf_func) | |
464 | (info->stream, "{%s}", | |
465 | reg_names[fetch_arg (buffer, place, 3, info)]); | |
466 | else if (place == 'C') | |
467 | { | |
468 | val = fetch_arg (buffer, place, 7, info); | |
469 | if ( val > 63 ) /* This is a signed constant. */ | |
470 | val -= 128; | |
471 | (*info->fprintf_func) (info->stream, "{#%d}", val); | |
472 | } | |
473 | else | |
474 | m68k_opcode_error (info, *d, place); | |
475 | break; | |
476 | ||
477 | case '#': | |
478 | case '^': | |
479 | p1 = buffer + (*d == '#' ? 2 : 4); | |
480 | if (place == 's') | |
481 | val = fetch_arg (buffer, place, 4, info); | |
482 | else if (place == 'C') | |
483 | val = fetch_arg (buffer, place, 7, info); | |
484 | else if (place == '8') | |
485 | val = fetch_arg (buffer, place, 3, info); | |
486 | else if (place == '3') | |
487 | val = fetch_arg (buffer, place, 8, info); | |
488 | else if (place == 'b') | |
489 | val = NEXTBYTE (p1); | |
490 | else if (place == 'w') | |
491 | val = NEXTWORD (p1); | |
492 | else if (place == 'l') | |
493 | val = NEXTLONG (p1); | |
494 | else | |
495 | m68k_opcode_error (info, *d, place); | |
496 | (*info->fprintf_func) (info->stream, "#%d", val); | |
497 | break; | |
498 | ||
499 | case 'B': | |
500 | if (place == 'b') | |
501 | val = NEXTBYTE (p); | |
502 | else if (place == 'B') | |
503 | val = COERCE_SIGNED_CHAR(buffer[1]); | |
504 | else if (place == 'w' || place == 'W') | |
505 | val = NEXTWORD (p); | |
506 | else if (place == 'l' || place == 'L') | |
507 | val = NEXTLONG (p); | |
508 | else if (place == 'g') | |
509 | { | |
510 | val = NEXTBYTE (buffer); | |
511 | if (val == 0) | |
512 | val = NEXTWORD (p); | |
513 | else if (val == -1) | |
514 | val = NEXTLONG (p); | |
515 | } | |
516 | else if (place == 'c') | |
517 | { | |
518 | if (buffer[1] & 0x40) /* If bit six is one, long offset */ | |
519 | val = NEXTLONG (p); | |
520 | else | |
521 | val = NEXTWORD (p); | |
522 | } | |
523 | else | |
524 | m68k_opcode_error (info, *d, place); | |
525 | ||
e6fb7139 | 526 | (*info->print_address_func) (addr + val, info); |
5d0734a7 JK |
527 | break; |
528 | ||
529 | case 'd': | |
530 | val = NEXTWORD (p); | |
531 | (*info->fprintf_func) | |
532 | (info->stream, "%s@(%d)", | |
533 | reg_names[fetch_arg (buffer, place, 3, info)], val); | |
534 | break; | |
535 | ||
536 | case 's': | |
537 | (*info->fprintf_func) (info->stream, "%s", | |
538 | fpcr_names[fetch_arg (buffer, place, 3, info)]); | |
539 | break; | |
540 | ||
541 | case 'I': | |
542 | /* Get coprocessor ID... */ | |
543 | val = fetch_arg (buffer, 'd', 3, info); | |
544 | ||
545 | if (val != 1) /* Unusual coprocessor ID? */ | |
546 | (*info->fprintf_func) (info->stream, "(cpid=%d) ", val); | |
547 | if (place == 'i') | |
548 | p += 2; /* Skip coprocessor extended operands */ | |
549 | break; | |
550 | ||
551 | case '*': | |
552 | case '~': | |
553 | case '%': | |
554 | case ';': | |
555 | case '@': | |
556 | case '!': | |
557 | case '$': | |
558 | case '?': | |
559 | case '/': | |
560 | case '&': | |
561 | case '`': | |
e6fb7139 | 562 | case '|': |
5d0734a7 JK |
563 | |
564 | if (place == 'd') | |
565 | { | |
566 | val = fetch_arg (buffer, 'x', 6, info); | |
567 | val = ((val & 7) << 3) + ((val >> 3) & 7); | |
568 | } | |
569 | else | |
570 | val = fetch_arg (buffer, 's', 6, info); | |
571 | ||
572 | /* Get register number assuming address register. */ | |
573 | regno = (val & 7) + 8; | |
574 | regname = reg_names[regno]; | |
575 | switch (val >> 3) | |
576 | { | |
577 | case 0: | |
578 | (*info->fprintf_func) (info->stream, "%s", reg_names[val]); | |
579 | break; | |
580 | ||
581 | case 1: | |
582 | (*info->fprintf_func) (info->stream, "%s", regname); | |
583 | break; | |
584 | ||
585 | case 2: | |
586 | (*info->fprintf_func) (info->stream, "%s@", regname); | |
587 | break; | |
588 | ||
589 | case 3: | |
590 | (*info->fprintf_func) (info->stream, "%s@+", regname); | |
591 | break; | |
592 | ||
593 | case 4: | |
594 | (*info->fprintf_func) (info->stream, "%s@-", regname); | |
595 | break; | |
596 | ||
597 | case 5: | |
598 | val = NEXTWORD (p); | |
599 | (*info->fprintf_func) (info->stream, "%s@(%d)", regname, val); | |
600 | break; | |
601 | ||
602 | case 6: | |
603 | p = print_indexed (regno, p, addr, info); | |
604 | break; | |
605 | ||
606 | case 7: | |
607 | switch (val & 7) | |
608 | { | |
609 | case 0: | |
610 | val = NEXTWORD (p); | |
611 | (*info->fprintf_func) (info->stream, "@#"); | |
e6fb7139 | 612 | (*info->print_address_func) (val, info); |
5d0734a7 JK |
613 | break; |
614 | ||
615 | case 1: | |
616 | val = NEXTLONG (p); | |
617 | (*info->fprintf_func) (info->stream, "@#"); | |
e6fb7139 | 618 | (*info->print_address_func) (val, info); |
5d0734a7 JK |
619 | break; |
620 | ||
621 | case 2: | |
622 | val = NEXTWORD (p); | |
e6fb7139 | 623 | (*info->print_address_func) (addr + val, info); |
5d0734a7 JK |
624 | break; |
625 | ||
626 | case 3: | |
627 | p = print_indexed (-1, p, addr, info); | |
628 | break; | |
629 | ||
630 | case 4: | |
631 | flt_p = 1; /* Assume it's a float... */ | |
632 | switch( place ) | |
633 | { | |
634 | case 'b': | |
635 | val = NEXTBYTE (p); | |
636 | flt_p = 0; | |
637 | break; | |
638 | ||
639 | case 'w': | |
640 | val = NEXTWORD (p); | |
641 | flt_p = 0; | |
642 | break; | |
643 | ||
644 | case 'l': | |
645 | val = NEXTLONG (p); | |
646 | flt_p = 0; | |
647 | break; | |
648 | ||
649 | case 'f': | |
650 | NEXTSINGLE(flval, p); | |
651 | break; | |
652 | ||
653 | case 'F': | |
654 | NEXTDOUBLE(flval, p); | |
655 | break; | |
656 | ||
657 | case 'x': | |
658 | ieee_extended_to_double (&ext_format_68881, | |
659 | (char *)p, &flval); | |
660 | p += 12; | |
661 | break; | |
662 | ||
663 | case 'p': | |
664 | flval = NEXTPACKED(p); | |
665 | break; | |
666 | ||
667 | default: | |
668 | m68k_opcode_error (info, *d, place); | |
669 | } | |
670 | if ( flt_p ) /* Print a float? */ | |
671 | (*info->fprintf_func) (info->stream, "#%g", flval); | |
672 | else | |
673 | (*info->fprintf_func) (info->stream, "#%d", val); | |
674 | break; | |
675 | ||
676 | default: | |
677 | (*info->fprintf_func) (info->stream, | |
678 | "<invalid address mode 0%o>", | |
679 | (unsigned) val); | |
680 | } | |
681 | } | |
682 | break; | |
683 | ||
684 | case 'L': | |
685 | case 'l': | |
686 | if (place == 'w') | |
687 | { | |
688 | char doneany; | |
689 | p1 = buffer + 2; | |
690 | val = NEXTWORD (p1); | |
691 | /* Move the pointer ahead if this point is farther ahead | |
692 | than the last. */ | |
693 | p = p1 > p ? p1 : p; | |
694 | if (val == 0) | |
695 | { | |
696 | (*info->fprintf_func) (info->stream, "#0"); | |
697 | break; | |
698 | } | |
699 | if (*d == 'l') | |
700 | { | |
701 | register int newval = 0; | |
702 | for (regno = 0; regno < 16; ++regno) | |
703 | if (val & (0x8000 >> regno)) | |
704 | newval |= 1 << regno; | |
705 | val = newval; | |
706 | } | |
707 | val &= 0xffff; | |
708 | doneany = 0; | |
709 | for (regno = 0; regno < 16; ++regno) | |
710 | if (val & (1 << regno)) | |
711 | { | |
712 | int first_regno; | |
713 | if (doneany) | |
714 | (*info->fprintf_func) (info->stream, "/"); | |
715 | doneany = 1; | |
716 | (*info->fprintf_func) (info->stream, "%s", reg_names[regno]); | |
717 | first_regno = regno; | |
718 | while (val & (1 << (regno + 1))) | |
719 | ++regno; | |
720 | if (regno > first_regno) | |
721 | (*info->fprintf_func) (info->stream, "-%s", | |
722 | reg_names[regno]); | |
723 | } | |
724 | } | |
725 | else if (place == '3') | |
726 | { | |
727 | /* `fmovem' insn. */ | |
728 | char doneany; | |
729 | val = fetch_arg (buffer, place, 8, info); | |
730 | if (val == 0) | |
731 | { | |
732 | (*info->fprintf_func) (info->stream, "#0"); | |
733 | break; | |
734 | } | |
735 | if (*d == 'l') | |
736 | { | |
737 | register int newval = 0; | |
738 | for (regno = 0; regno < 8; ++regno) | |
739 | if (val & (0x80 >> regno)) | |
740 | newval |= 1 << regno; | |
741 | val = newval; | |
742 | } | |
743 | val &= 0xff; | |
744 | doneany = 0; | |
745 | for (regno = 0; regno < 8; ++regno) | |
746 | if (val & (1 << regno)) | |
747 | { | |
748 | int first_regno; | |
749 | if (doneany) | |
750 | (*info->fprintf_func) (info->stream, "/"); | |
751 | doneany = 1; | |
752 | (*info->fprintf_func) (info->stream, "fp%d", regno); | |
753 | first_regno = regno; | |
754 | while (val & (1 << (regno + 1))) | |
755 | ++regno; | |
756 | if (regno > first_regno) | |
757 | (*info->fprintf_func) (info->stream, "-fp%d", regno); | |
758 | } | |
759 | } | |
760 | else | |
761 | goto de_fault; | |
762 | break; | |
763 | ||
e6fb7139 JK |
764 | case 'X': |
765 | place = '8'; | |
766 | case 'Y': | |
767 | case 'Z': | |
768 | case 'W': | |
769 | case '3': | |
770 | case 'P': | |
771 | { | |
772 | int val = fetch_arg (buffer, place, 5, info); | |
773 | char *name = 0; | |
774 | switch (val) | |
775 | { | |
776 | case 2: name = "tt0"; break; | |
777 | case 3: name = "tt1"; break; | |
778 | case 0x10: name = "tc"; break; | |
779 | case 0x11: name = "drp"; break; | |
780 | case 0x12: name = "srp"; break; | |
781 | case 0x13: name = "crp"; break; | |
782 | case 0x14: name = "cal"; break; | |
783 | case 0x15: name = "val"; break; | |
784 | case 0x16: name = "scc"; break; | |
785 | case 0x17: name = "ac"; break; | |
786 | case 0x18: name = "psr"; break; | |
787 | case 0x19: name = "pcsr"; break; | |
788 | case 0x1c: | |
789 | case 0x1d: | |
790 | { | |
791 | int break_reg = ((buffer[3] >> 2) & 7); | |
792 | (*info->fprintf_func) | |
793 | (info->stream, val == 0x1c ? "bad%d" : "bac%d", | |
794 | break_reg); | |
795 | } | |
796 | break; | |
797 | default: | |
798 | (*info->fprintf_func) (info->stream, "<mmu register %d>", val); | |
799 | } | |
800 | if (name) | |
801 | (*info->fprintf_func) (info->stream, name); | |
802 | } | |
803 | break; | |
804 | ||
805 | case 'f': | |
806 | { | |
807 | int fc = fetch_arg (buffer, place, 5, info); | |
808 | if (fc == 1) | |
809 | (*info->fprintf_func) (info->stream, "dfc"); | |
810 | else if (fc == 0) | |
811 | (*info->fprintf_func) (info->stream, "sfc"); | |
812 | else | |
813 | (*info->fprintf_func) (info->stream, "<function code %d>", fc); | |
814 | } | |
815 | break; | |
816 | ||
817 | case 'V': | |
818 | (*info->fprintf_func) (info->stream, "val"); | |
819 | break; | |
820 | ||
821 | case 't': | |
822 | { | |
823 | int level = fetch_arg (buffer, place, 3, info); | |
824 | (*info->fprintf_func) (info->stream, "%d", level); | |
825 | } | |
826 | break; | |
827 | ||
5d0734a7 JK |
828 | default: de_fault: |
829 | m68k_opcode_error (info, *d, ' '); | |
830 | } | |
831 | ||
832 | return (unsigned char *) p; | |
833 | } | |
834 | ||
835 | /* Fetch BITS bits from a position in the instruction specified by CODE. | |
836 | CODE is a "place to put an argument", or 'x' for a destination | |
837 | that is a general address (mode and register). | |
838 | BUFFER contains the instruction. */ | |
839 | ||
840 | static int | |
841 | fetch_arg (buffer, code, bits, info) | |
842 | unsigned char *buffer; | |
843 | int code; | |
844 | int bits; | |
845 | disassemble_info *info; | |
846 | { | |
847 | register int val = 0; | |
848 | switch (code) | |
849 | { | |
850 | case 's': | |
851 | val = buffer[1]; | |
852 | break; | |
853 | ||
854 | case 'd': /* Destination, for register or quick. */ | |
855 | val = (buffer[0] << 8) + buffer[1]; | |
856 | val >>= 9; | |
857 | break; | |
858 | ||
859 | case 'x': /* Destination, for general arg */ | |
860 | val = (buffer[0] << 8) + buffer[1]; | |
861 | val >>= 6; | |
862 | break; | |
863 | ||
864 | case 'k': | |
865 | FETCH_DATA (info, buffer + 3); | |
866 | val = (buffer[3] >> 4); | |
867 | break; | |
868 | ||
869 | case 'C': | |
870 | FETCH_DATA (info, buffer + 3); | |
871 | val = buffer[3]; | |
872 | break; | |
873 | ||
874 | case '1': | |
875 | FETCH_DATA (info, buffer + 3); | |
876 | val = (buffer[2] << 8) + buffer[3]; | |
877 | val >>= 12; | |
878 | break; | |
879 | ||
880 | case '2': | |
881 | FETCH_DATA (info, buffer + 3); | |
882 | val = (buffer[2] << 8) + buffer[3]; | |
883 | val >>= 6; | |
884 | break; | |
885 | ||
886 | case '3': | |
887 | case 'j': | |
888 | FETCH_DATA (info, buffer + 3); | |
889 | val = (buffer[2] << 8) + buffer[3]; | |
890 | break; | |
891 | ||
892 | case '4': | |
893 | FETCH_DATA (info, buffer + 5); | |
894 | val = (buffer[4] << 8) + buffer[5]; | |
895 | val >>= 12; | |
896 | break; | |
897 | ||
898 | case '5': | |
899 | FETCH_DATA (info, buffer + 5); | |
900 | val = (buffer[4] << 8) + buffer[5]; | |
901 | val >>= 6; | |
902 | break; | |
903 | ||
904 | case '6': | |
905 | FETCH_DATA (info, buffer + 5); | |
906 | val = (buffer[4] << 8) + buffer[5]; | |
907 | break; | |
908 | ||
909 | case '7': | |
910 | FETCH_DATA (info, buffer + 3); | |
911 | val = (buffer[2] << 8) + buffer[3]; | |
912 | val >>= 7; | |
913 | break; | |
914 | ||
915 | case '8': | |
916 | FETCH_DATA (info, buffer + 3); | |
917 | val = (buffer[2] << 8) + buffer[3]; | |
918 | val >>= 10; | |
919 | break; | |
920 | ||
921 | case '9': | |
922 | FETCH_DATA (info, buffer + 3); | |
923 | val = (buffer[2] << 8) + buffer[3]; | |
924 | val >>= 5; | |
925 | break; | |
926 | ||
927 | case 'e': | |
928 | val = (buffer[1] >> 6); | |
929 | break; | |
930 | ||
931 | default: | |
932 | abort (); | |
933 | } | |
934 | ||
935 | switch (bits) | |
936 | { | |
937 | case 2: | |
938 | return val & 3; | |
939 | case 3: | |
940 | return val & 7; | |
941 | case 4: | |
942 | return val & 017; | |
943 | case 5: | |
944 | return val & 037; | |
945 | case 6: | |
946 | return val & 077; | |
947 | case 7: | |
948 | return val & 0177; | |
949 | case 8: | |
950 | return val & 0377; | |
951 | case 12: | |
952 | return val & 07777; | |
953 | default: | |
954 | abort (); | |
955 | } | |
956 | } | |
957 | ||
958 | /* Print an indexed argument. The base register is BASEREG (-1 for pc). | |
959 | P points to extension word, in buffer. | |
960 | ADDR is the nominal core address of that extension word. */ | |
961 | ||
962 | static unsigned char * | |
963 | print_indexed (basereg, p, addr, info) | |
964 | int basereg; | |
965 | unsigned char *p; | |
966 | bfd_vma addr; | |
967 | disassemble_info *info; | |
968 | { | |
969 | register int word; | |
970 | static char *scales[] = {"", "*2", "*4", "*8"}; | |
971 | register int base_disp; | |
972 | register int outer_disp; | |
973 | char buf[40]; | |
974 | ||
975 | word = NEXTWORD (p); | |
976 | ||
977 | /* Generate the text for the index register. | |
978 | Where this will be output is not yet determined. */ | |
979 | sprintf (buf, "[%s.%c%s]", | |
980 | reg_names[(word >> 12) & 0xf], | |
981 | (word & 0x800) ? 'l' : 'w', | |
982 | scales[(word >> 9) & 3]); | |
983 | ||
984 | /* Handle the 68000 style of indexing. */ | |
985 | ||
986 | if ((word & 0x100) == 0) | |
987 | { | |
988 | print_base (basereg, | |
989 | ((word & 0x80) ? word | 0xff00 : word & 0xff) | |
990 | + ((basereg == -1) ? addr : 0), | |
991 | info); | |
992 | (*info->fprintf_func) (info->stream, "%s", buf); | |
993 | return p; | |
994 | } | |
995 | ||
996 | /* Handle the generalized kind. */ | |
997 | /* First, compute the displacement to add to the base register. */ | |
998 | ||
999 | if (word & 0200) | |
1000 | basereg = -2; | |
1001 | if (word & 0100) | |
1002 | buf[0] = 0; | |
1003 | base_disp = 0; | |
1004 | switch ((word >> 4) & 3) | |
1005 | { | |
1006 | case 2: | |
1007 | base_disp = NEXTWORD (p); | |
1008 | break; | |
1009 | case 3: | |
1010 | base_disp = NEXTLONG (p); | |
1011 | } | |
1012 | if (basereg == -1) | |
1013 | base_disp += addr; | |
1014 | ||
1015 | /* Handle single-level case (not indirect) */ | |
1016 | ||
1017 | if ((word & 7) == 0) | |
1018 | { | |
1019 | print_base (basereg, base_disp, info); | |
1020 | (*info->fprintf_func) (info->stream, "%s", buf); | |
1021 | return p; | |
1022 | } | |
1023 | ||
1024 | /* Two level. Compute displacement to add after indirection. */ | |
1025 | ||
1026 | outer_disp = 0; | |
1027 | switch (word & 3) | |
1028 | { | |
1029 | case 2: | |
1030 | outer_disp = NEXTWORD (p); | |
1031 | break; | |
1032 | case 3: | |
1033 | outer_disp = NEXTLONG (p); | |
1034 | } | |
1035 | ||
1036 | (*info->fprintf_func) (info->stream, "%d(", outer_disp); | |
1037 | print_base (basereg, base_disp, info); | |
1038 | ||
1039 | /* If postindexed, print the closeparen before the index. */ | |
1040 | if (word & 4) | |
1041 | (*info->fprintf_func) (info->stream, ")%s", buf); | |
1042 | /* If preindexed, print the closeparen after the index. */ | |
1043 | else | |
1044 | (*info->fprintf_func) (info->stream, "%s)", buf); | |
1045 | ||
1046 | return p; | |
1047 | } | |
1048 | ||
1049 | /* Print a base register REGNO and displacement DISP, on INFO->STREAM. | |
1050 | REGNO = -1 for pc, -2 for none (suppressed). */ | |
1051 | ||
1052 | static void | |
1053 | print_base (regno, disp, info) | |
1054 | int regno; | |
1055 | int disp; | |
1056 | disassemble_info *info; | |
1057 | { | |
1058 | if (regno == -2) | |
1059 | (*info->fprintf_func) (info->stream, "%d", disp); | |
1060 | else if (regno == -1) | |
1061 | (*info->fprintf_func) (info->stream, "0x%x", (unsigned) disp); | |
1062 | else | |
1063 | (*info->fprintf_func) (info->stream, "%d(%s)", disp, reg_names[regno]); | |
1064 | } |