Commit | Line | Data |
---|---|---|
2fa0b342 | 1 | /* Print m68k instructions for objdump |
d8474a9b | 2 | Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc. |
2fa0b342 DHW |
3 | |
4 | ||
5 | This file is part of the binutils. | |
6 | ||
7 | The binutils are free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
d8474a9b | 9 | the Free Software Foundation; either version 2, or (at your option) |
2fa0b342 DHW |
10 | any later version. |
11 | ||
12 | The binutils are distributed in the hope that they will be useful, | |
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 | |
18 | along with the binutils; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* $Id$ | |
22 | $Log$ | |
4aa58a0a SC |
23 | Revision 1.6 1991/12/01 02:58:34 sac |
24 | Updated to point to where the header files are now | |
b27d2046 | 25 | |
4aa58a0a SC |
26 | * Revision 1.5 1991/11/03 22:58:44 bothner |
27 | * * Makefile.in ($(DIST_NAME).tar.Z), TODO: Various fixes. | |
28 | * * ar.c (get_pos_bfd): Fix to handling of before/after | |
29 | * positioning options. | |
30 | * * bucomm.c (fatal): MISSING_VFPRINTF is no longer an issue, | |
31 | * since libiberty contains vfprintf etc if otherwise missing. | |
32 | * * m68k-pinsn.c (print_insn_arg): Support BB/BW/BL | |
33 | * type operands, as used by branch instructions. | |
34 | * * nm.c: Delegate printing of symbols to BFD, | |
35 | * by using bfd_print_symbol to do the formatting. | |
36 | * | |
b27d2046 PB |
37 | * Revision 1.4 1991/10/16 18:56:56 bothner |
38 | * * Makefile.in, ar.c, bucomm.c, copy.c, cplus-dem.c, filemode.c, | |
39 | * i960-pinsn.c, m68k-pinsn.c, nm.c, objdump.c, size.c, sparc-pinsn.c, | |
40 | * * strip.c: Add or update Copyright notice. | |
41 | * * TODO: Add note on 'nm -a'. | |
42 | * * version.c: Update version number to 1.90. | |
43 | * * Makefile.in: Fix making of documentation for dist. | |
44 | * | |
d8474a9b PB |
45 | * Revision 1.3 1991/10/11 11:22:00 gnu |
46 | * Include bfd.h before sysdep.h, so ansidecl and PROTO() get defined first. | |
47 | * | |
2a5f387b JG |
48 | * Revision 1.2 1991/06/14 22:54:44 steve |
49 | * *** empty log message *** | |
50 | * | |
17e6f61f SC |
51 | * Revision 1.1.1.1 1991/03/21 21:26:46 gumby |
52 | * Back from Intel with Steve | |
53 | * | |
c074abee DHW |
54 | * Revision 1.1 1991/03/21 21:26:45 gumby |
55 | * Initial revision | |
56 | * | |
2fa0b342 DHW |
57 | * Revision 1.1 1991/03/13 00:34:06 chrisb |
58 | * Initial revision | |
59 | * | |
60 | * Revision 1.4 1991/03/09 04:36:34 rich | |
61 | * Modified Files: | |
62 | * sparc-pinsn.c ostrip.c objdump.c m68k-pinsn.c i960-pinsn.c | |
63 | * binutils.h | |
64 | * | |
65 | * Pulled sysdep.h out of bfd.h. | |
66 | * | |
67 | * Revision 1.3 1991/03/08 21:54:45 rich | |
68 | * Modified Files: | |
69 | * Makefile ar.c binutils.h bucomm.c copy.c cplus-dem.c getopt.c | |
70 | * i960-pinsn.c m68k-pinsn.c nm.c objdump.c sparc-opcode.h | |
71 | * sparc-pinsn.c strip.c | |
72 | * | |
73 | * Verifying Portland tree with steve's last changes. Also, some partial | |
74 | * porting. | |
75 | * | |
76 | * Revision 1.2 1991/03/08 07:46:24 sac | |
77 | * Added -l option to disassembly - prints line numbers too. | |
78 | * | |
79 | * Revision 1.1 1991/02/22 16:48:02 sac | |
80 | * Initial revision | |
81 | * | |
82 | */ | |
2a5f387b | 83 | #include "bfd.h" |
2fa0b342 | 84 | #include "sysdep.h" |
17e6f61f | 85 | #include <stdio.h> |
4aa58a0a | 86 | #include "opcode/m68k.h" |
2fa0b342 DHW |
87 | |
88 | extern int fputs(); | |
89 | extern void print_address(); | |
90 | ||
91 | /* 68k instructions are never longer than this many bytes. */ | |
92 | #define MAXLEN 22 | |
93 | ||
94 | /* Number of elements in the opcode table. */ | |
95 | #define NOPCODES (sizeof m68k_opcodes / sizeof m68k_opcodes[0]) | |
96 | ||
97 | extern char *reg_names[]; | |
98 | char *fpcr_names[] = { "", "fpiar", "fpsr", "fpiar/fpsr", "fpcr", | |
99 | "fpiar/fpcr", "fpsr/fpcr", "fpiar-fpcr"}; | |
100 | ||
101 | char *reg_names[] = {"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp", "ps", "pc"}; | |
102 | static unsigned char *print_insn_arg (); | |
103 | static unsigned char *print_indexed (); | |
104 | static void print_base (); | |
105 | static int fetch_arg (); | |
106 | ||
107 | #define NEXTBYTE(p) (p += 2, ((char *)p)[-1]) | |
108 | ||
109 | #define NEXTWORD(p) \ | |
110 | (p += 2, ((((char *)p)[-2]) << 8) + p[-1]) | |
111 | ||
112 | #define NEXTLONG(p) \ | |
113 | (p += 4, (((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1]) | |
114 | ||
115 | #define NEXTSINGLE(p) \ | |
116 | (p += 4, *((float *)(p - 4))) | |
117 | ||
118 | #define NEXTDOUBLE(p) \ | |
119 | (p += 8, *((double *)(p - 8))) | |
120 | ||
121 | #define NEXTEXTEND(p) \ | |
122 | (p += 12, 0.0) /* Need a function to convert from extended to double | |
123 | precision... */ | |
124 | ||
125 | #define NEXTPACKED(p) \ | |
126 | (p += 12, 0.0) /* Need a function to convert from packed to double | |
127 | precision. Actually, it's easier to print a | |
128 | packed number than a double anyway, so maybe | |
129 | there should be a special case to handle this... */ | |
130 | \f | |
131 | /* Print the m68k instruction at address MEMADDR in debugged memory, | |
132 | on STREAM. Returns length of the instruction, in bytes. */ | |
133 | ||
134 | int | |
135 | print_insn_m68k(addr, buffer, stream) | |
136 | bfd_vma addr; | |
137 | unsigned char *buffer; | |
138 | FILE *stream; | |
139 | { | |
140 | register unsigned int i; | |
141 | register unsigned char *p; | |
142 | register char *d; | |
143 | register unsigned int bestmask; | |
144 | int best; | |
145 | ||
146 | ||
147 | ||
148 | bestmask = 0; | |
149 | best = -1; | |
150 | for (i = 0; i < NOPCODES; i++) | |
151 | { | |
152 | register unsigned int opcode = m68k_opcodes[i].opcode; | |
153 | register unsigned int match = m68k_opcodes[i].match; | |
154 | if (((0xff & buffer[0] & (match >> 24)) == (0xff & (opcode >> 24))) | |
155 | && ((0xff & buffer[1] & (match >> 16)) == (0xff & (opcode >> 16))) | |
156 | && ((0xff & buffer[2] & (match >> 8)) == (0xff & (opcode >> 8))) | |
157 | && ((0xff & buffer[3] & match) == (0xff & opcode))) | |
158 | { | |
159 | /* Don't use for printout the variants of divul and divsl | |
160 | that have the same register number in two places. | |
161 | The more general variants will match instead. */ | |
162 | for (d = m68k_opcodes[i].args; *d; d += 2) | |
163 | if (d[1] == 'D') | |
164 | break; | |
165 | ||
166 | /* Don't use for printout the variants of most floating | |
167 | point coprocessor instructions which use the same | |
168 | register number in two places, as above. */ | |
169 | if (*d == 0) | |
170 | for (d = m68k_opcodes[i].args; *d; d += 2) | |
171 | if (d[1] == 't') | |
172 | break; | |
173 | ||
174 | if (*d == 0 && match > bestmask) | |
175 | { | |
176 | best = i; | |
177 | bestmask = match; | |
178 | } | |
179 | } | |
180 | } | |
181 | ||
182 | /* Handle undefined instructions. */ | |
183 | if (best < 0) | |
184 | { | |
185 | fprintf (stream, "0%o", (unsigned) (buffer[0] << 8) + buffer[1]); | |
186 | return 2; | |
187 | } | |
188 | ||
189 | fprintf (stream, "%s", m68k_opcodes[best].name); | |
190 | ||
191 | /* Point at first word of argument data, | |
192 | and at descriptor for first argument. */ | |
193 | p = buffer + 2; | |
194 | ||
195 | /* Why do this this way? -MelloN */ | |
196 | for (d = m68k_opcodes[best].args; *d; d += 2) | |
197 | { | |
198 | if (d[0] == '#') | |
199 | { | |
200 | if (d[1] == 'l' && p - buffer < 6) | |
201 | p = buffer + 6; | |
202 | else if (p - buffer < 4 && d[1] != 'C' && d[1] != '8' ) | |
203 | p = buffer + 4; | |
204 | } | |
205 | if (d[1] >= '1' && d[1] <= '3' && p - buffer < 4) | |
206 | p = buffer + 4; | |
207 | if (d[1] >= '4' && d[1] <= '6' && p - buffer < 6) | |
208 | p = buffer + 6; | |
209 | if ((d[0] == 'L' || d[0] == 'l') && d[1] == 'w' && p - buffer < 4) | |
210 | p = buffer + 4; | |
211 | } | |
212 | ||
213 | d = m68k_opcodes[best].args; | |
214 | ||
215 | if (*d) | |
216 | fputs (" ", stream); | |
217 | ||
218 | while (*d) | |
219 | { | |
220 | p = print_insn_arg (d, buffer, p, addr + p - buffer, stream); | |
221 | d += 2; | |
222 | if (*d && *(d - 2) != 'I' && *d != 'k') | |
223 | fputs (",", stream); | |
224 | } | |
225 | return p - buffer; | |
226 | } | |
227 | ||
228 | static unsigned char * | |
229 | print_insn_arg (d, buffer, p, addr, stream) | |
230 | char *d; | |
231 | unsigned char *buffer; | |
232 | register unsigned char *p; | |
233 | bfd_vma addr; /* PC for this arg to be relative to */ | |
234 | FILE *stream; | |
235 | { | |
236 | register int val; | |
237 | register int place = d[1]; | |
238 | int regno; | |
239 | register char *regname; | |
240 | register unsigned char *p1; | |
241 | register double flval; | |
242 | int flt_p; | |
243 | ||
244 | switch (*d) | |
245 | { | |
246 | case 'C': | |
247 | fprintf (stream, "ccr"); | |
248 | break; | |
249 | ||
250 | case 'S': | |
251 | fprintf (stream, "sr"); | |
252 | break; | |
253 | ||
254 | case 'U': | |
255 | fprintf (stream, "usp"); | |
256 | break; | |
257 | ||
258 | case 'J': | |
259 | { | |
260 | static struct { char *name; int value; } names[] | |
261 | = {{"sfc", 0x000}, {"dfc", 0x001}, {"cacr", 0x002}, | |
262 | {"usp", 0x800}, {"vbr", 0x801}, {"caar", 0x802}, | |
263 | {"msp", 0x803}, {"isp", 0x804}}; | |
264 | ||
265 | val = fetch_arg (buffer, place, 12); | |
266 | for (regno = sizeof names / sizeof names[0] - 1; regno >= 0; regno--) | |
267 | if (names[regno].value == val) | |
268 | { | |
269 | fprintf (stream, names[regno].name); | |
270 | break; | |
271 | } | |
272 | if (regno < 0) | |
273 | fprintf (stream, "%d", val); | |
274 | } | |
275 | break; | |
276 | ||
277 | case 'Q': | |
278 | val = fetch_arg (buffer, place, 3); | |
279 | if (val == 0) val = 8; | |
280 | fprintf (stream, "#%d", val); | |
281 | break; | |
282 | ||
283 | case 'M': | |
284 | val = fetch_arg (buffer, place, 8); | |
285 | if (val & 0x80) | |
286 | val = val - 0x100; | |
287 | fprintf (stream, "#%d", val); | |
288 | break; | |
289 | ||
290 | case 'T': | |
291 | val = fetch_arg (buffer, place, 4); | |
292 | fprintf (stream, "#%d", val); | |
293 | break; | |
294 | ||
295 | case 'D': | |
296 | fprintf (stream, "%s", reg_names[fetch_arg (buffer, place, 3)]); | |
297 | break; | |
298 | ||
299 | case 'A': | |
300 | fprintf (stream, "%s", | |
301 | reg_names[fetch_arg (buffer, place, 3) + 010]); | |
302 | break; | |
303 | ||
304 | case 'R': | |
305 | fprintf (stream, "%s", reg_names[fetch_arg (buffer, place, 4)]); | |
306 | break; | |
307 | ||
308 | case 'F': | |
309 | fprintf (stream, "fp%d", fetch_arg (buffer, place, 3)); | |
310 | break; | |
311 | ||
312 | case 'O': | |
313 | val = fetch_arg (buffer, place, 6); | |
314 | if (val & 0x20) | |
315 | fprintf (stream, "%s", reg_names [val & 7]); | |
316 | else | |
317 | fprintf (stream, "%d", val); | |
318 | break; | |
319 | ||
320 | case '+': | |
321 | fprintf (stream, "%s@+", | |
322 | reg_names[fetch_arg (buffer, place, 3) + 8]); | |
323 | break; | |
324 | ||
325 | case '-': | |
326 | fprintf (stream, "%s@-", | |
327 | reg_names[fetch_arg (buffer, place, 3) + 8]); | |
328 | break; | |
329 | ||
330 | case 'k': | |
331 | if (place == 'k') | |
332 | fprintf (stream, "{%s}", reg_names[fetch_arg (buffer, place, 3)]); | |
333 | else if (place == 'C') | |
334 | { | |
335 | val = fetch_arg (buffer, place, 7); | |
336 | if ( val > 63 ) /* This is a signed constant. */ | |
337 | val -= 128; | |
338 | fprintf (stream, "{#%d}", val); | |
339 | } | |
340 | else | |
341 | fprintf(stderr, "Invalid arg format in opcode table: \"%c%c\".", | |
342 | *d, place); | |
343 | break; | |
344 | ||
345 | case '#': | |
346 | case '^': | |
347 | p1 = buffer + (*d == '#' ? 2 : 4); | |
348 | if (place == 's') | |
349 | val = fetch_arg (buffer, place, 4); | |
350 | else if (place == 'C') | |
351 | val = fetch_arg (buffer, place, 7); | |
352 | else if (place == '8') | |
353 | val = fetch_arg (buffer, place, 3); | |
354 | else if (place == '3') | |
355 | val = fetch_arg (buffer, place, 8); | |
356 | else if (place == 'b') | |
357 | val = NEXTBYTE (p1); | |
358 | else if (place == 'w') | |
359 | val = NEXTWORD (p1); | |
360 | else if (place == 'l') | |
361 | val = NEXTLONG (p1); | |
362 | else | |
363 | fprintf(stderr, "Invalid arg format in opcode table: \"%c%c\".", | |
364 | *d, place); | |
365 | fprintf (stream, "#%d", val); | |
366 | break; | |
367 | ||
368 | case 'B': | |
369 | if (place == 'b') | |
370 | val = NEXTBYTE (p); | |
b27d2046 PB |
371 | else if (place == 'B') |
372 | val = buffer[1]; | |
373 | else if (place == 'w' || place == 'W') | |
2fa0b342 | 374 | val = NEXTWORD (p); |
b27d2046 | 375 | else if (place == 'l' || place == 'L') |
2fa0b342 DHW |
376 | val = NEXTLONG (p); |
377 | else if (place == 'g') | |
378 | { | |
379 | val = ((char *)buffer)[1]; | |
380 | if (val == 0) | |
381 | val = NEXTWORD (p); | |
382 | else if (val == -1) | |
383 | val = NEXTLONG (p); | |
384 | } | |
385 | else if (place == 'c') | |
386 | { | |
387 | if (buffer[1] & 0x40) /* If bit six is one, long offset */ | |
388 | val = NEXTLONG (p); | |
389 | else | |
390 | val = NEXTWORD (p); | |
391 | } | |
392 | else | |
393 | fprintf(stderr, "Invalid arg format in opcode table: \"%c%c\".", | |
394 | *d, place); | |
395 | print_address (addr + val, stream); | |
396 | break; | |
397 | ||
398 | case 'd': | |
399 | val = NEXTWORD (p); | |
400 | fprintf (stream, "%s@(%d)", | |
401 | reg_names[fetch_arg (buffer, place, 3)], val); | |
402 | break; | |
403 | ||
404 | case 's': | |
405 | fprintf (stream, "%s", | |
406 | fpcr_names[fetch_arg (buffer, place, 3)]); | |
407 | break; | |
408 | ||
409 | case 'I': | |
410 | val = fetch_arg (buffer, 'd', 3); /* Get coprocessor ID... */ | |
411 | if (val != 1) /* Unusual coprocessor ID? */ | |
412 | fprintf (stream, "(cpid=%d) ", val); | |
413 | if (place == 'i') | |
414 | p += 2; /* Skip coprocessor extended operands */ | |
415 | break; | |
416 | ||
417 | case '*': | |
418 | case '~': | |
419 | case '%': | |
420 | case ';': | |
421 | case '@': | |
422 | case '!': | |
423 | case '$': | |
424 | case '?': | |
425 | case '/': | |
426 | case '&': | |
427 | ||
428 | if (place == 'd') | |
429 | { | |
430 | val = fetch_arg (buffer, 'x', 6); | |
431 | val = ((val & 7) << 3) + ((val >> 3) & 7); | |
432 | } | |
433 | else | |
434 | val = fetch_arg (buffer, 's', 6); | |
435 | ||
436 | /* Get register number assuming address register. */ | |
437 | regno = (val & 7) + 8; | |
438 | regname = reg_names[regno]; | |
439 | switch (val >> 3) | |
440 | { | |
441 | case 0: | |
442 | fprintf (stream, "%s", reg_names[val]); | |
443 | break; | |
444 | ||
445 | case 1: | |
446 | fprintf (stream, "%s", regname); | |
447 | break; | |
448 | ||
449 | case 2: | |
450 | fprintf (stream, "%s@", regname); | |
451 | break; | |
452 | ||
453 | case 3: | |
454 | fprintf (stream, "%s@+", regname); | |
455 | break; | |
456 | ||
457 | case 4: | |
458 | fprintf (stream, "%s@-", regname); | |
459 | break; | |
460 | ||
461 | case 5: | |
462 | val = NEXTWORD (p); | |
463 | fprintf (stream, "%s@(%d)", regname, val); | |
464 | break; | |
465 | ||
466 | case 6: | |
467 | p = print_indexed (regno, p, addr, stream); | |
468 | break; | |
469 | ||
470 | case 7: | |
471 | switch (val & 7) | |
472 | { | |
473 | case 0: | |
474 | val = NEXTWORD (p); | |
475 | fprintf (stream, "@#"); | |
476 | print_address (val, stream); | |
477 | break; | |
478 | ||
479 | case 1: | |
480 | val = NEXTLONG (p); | |
481 | fprintf (stream, "@#"); | |
482 | print_address (val, stream); | |
483 | break; | |
484 | ||
485 | case 2: | |
486 | val = NEXTWORD (p); | |
487 | print_address (addr + val, stream); | |
488 | break; | |
489 | ||
490 | case 3: | |
491 | p = print_indexed (-1, p, addr, stream); | |
492 | break; | |
493 | ||
494 | case 4: | |
495 | flt_p = 1; /* Assume it's a float... */ | |
496 | switch( place ) | |
497 | { | |
498 | case 'b': | |
499 | val = NEXTBYTE (p); | |
500 | flt_p = 0; | |
501 | break; | |
502 | ||
503 | case 'w': | |
504 | val = NEXTWORD (p); | |
505 | flt_p = 0; | |
506 | break; | |
507 | ||
508 | case 'l': | |
509 | val = NEXTLONG (p); | |
510 | flt_p = 0; | |
511 | break; | |
512 | ||
513 | case 'f': | |
514 | flval = NEXTSINGLE(p); | |
515 | break; | |
516 | ||
517 | case 'F': | |
518 | flval = NEXTDOUBLE(p); | |
519 | break; | |
520 | ||
521 | case 'x': | |
522 | flval = NEXTEXTEND(p); | |
523 | break; | |
524 | ||
525 | case 'p': | |
526 | flval = NEXTPACKED(p); | |
527 | break; | |
528 | ||
529 | default: | |
530 | fprintf(stderr, "Invalid arg format in opcode table: \"%c%c\".", | |
531 | *d, place); | |
532 | } | |
533 | if ( flt_p ) /* Print a float? */ | |
534 | fprintf (stream, "#%g", flval); | |
535 | else | |
536 | fprintf (stream, "#%d", val); | |
537 | break; | |
538 | ||
539 | default: | |
540 | fprintf (stream, "<invalid address mode 0%o>", (unsigned) val); | |
541 | } | |
542 | } | |
543 | break; | |
544 | ||
545 | case 'L': | |
546 | case 'l': | |
547 | if (place == 'w') | |
548 | { | |
549 | char doneany; | |
550 | p1 = buffer + 2; | |
551 | val = NEXTWORD (p1); | |
552 | /* Move the pointer ahead if this point is farther ahead | |
553 | than the last. */ | |
554 | p = p1 > p ? p1 : p; | |
555 | if (val == 0) | |
556 | { | |
557 | fputs ("#0", stream); | |
558 | break; | |
559 | } | |
560 | if (*d == 'l') | |
561 | { | |
562 | register int newval = 0; | |
563 | for (regno = 0; regno < 16; ++regno) | |
564 | if (val & (0x8000 >> regno)) | |
565 | newval |= 1 << regno; | |
566 | val = newval; | |
567 | } | |
568 | val &= 0xffff; | |
569 | doneany = 0; | |
570 | for (regno = 0; regno < 16; ++regno) | |
571 | if (val & (1 << regno)) | |
572 | { | |
573 | int first_regno; | |
574 | if (doneany) | |
575 | fputs ("/", stream); | |
576 | doneany = 1; | |
577 | fprintf (stream, "%s", reg_names[regno]); | |
578 | first_regno = regno; | |
579 | while (val & (1 << (regno + 1))) | |
580 | ++regno; | |
581 | if (regno > first_regno) | |
582 | fprintf (stream, "-%s", reg_names[regno]); | |
583 | } | |
584 | } | |
585 | else if (place == '3') | |
586 | { | |
587 | /* `fmovem' insn. */ | |
588 | char doneany; | |
589 | val = fetch_arg (buffer, place, 8); | |
590 | if (val == 0) | |
591 | { | |
592 | fputs ("#0", stream); | |
593 | break; | |
594 | } | |
595 | if (*d == 'l') | |
596 | { | |
597 | register int newval = 0; | |
598 | for (regno = 0; regno < 8; ++regno) | |
599 | if (val & (0x80 >> regno)) | |
600 | newval |= 1 << regno; | |
601 | val = newval; | |
602 | } | |
603 | val &= 0xff; | |
604 | doneany = 0; | |
605 | for (regno = 0; regno < 8; ++regno) | |
606 | if (val & (1 << regno)) | |
607 | { | |
608 | int first_regno; | |
609 | if (doneany) | |
610 | fputs ("/", stream); | |
611 | doneany = 1; | |
612 | fprintf (stream, "fp%d", regno); | |
613 | first_regno = regno; | |
614 | while (val & (1 << (regno + 1))) | |
615 | ++regno; | |
616 | if (regno > first_regno) | |
617 | fprintf (stream, "-fp%d", regno); | |
618 | } | |
619 | } | |
620 | else | |
621 | abort (); | |
622 | break; | |
623 | ||
624 | default: | |
625 | fprintf(stderr, "Invalid arg format in opcode table: \"%c\".", *d); | |
626 | } | |
627 | ||
628 | return (unsigned char *) p; | |
629 | } | |
630 | ||
631 | /* Fetch BITS bits from a position in the instruction specified by CODE. | |
632 | CODE is a "place to put an argument", or 'x' for a destination | |
633 | that is a general address (mode and register). | |
634 | BUFFER contains the instruction. */ | |
635 | ||
636 | static int | |
637 | fetch_arg (buffer, code, bits) | |
638 | unsigned char *buffer; | |
639 | char code; | |
640 | int bits; | |
641 | { | |
642 | register int val; | |
643 | switch (code) | |
644 | { | |
645 | case 's': | |
646 | val = buffer[1]; | |
647 | break; | |
648 | ||
649 | case 'd': /* Destination, for register or quick. */ | |
650 | val = (buffer[0] << 8) + buffer[1]; | |
651 | val >>= 9; | |
652 | break; | |
653 | ||
654 | case 'x': /* Destination, for general arg */ | |
655 | val = (buffer[0] << 8) + buffer[1]; | |
656 | val >>= 6; | |
657 | break; | |
658 | ||
659 | case 'k': | |
660 | val = (buffer[3] >> 4); | |
661 | break; | |
662 | ||
663 | case 'C': | |
664 | val = buffer[3]; | |
665 | break; | |
666 | ||
667 | case '1': | |
668 | val = (buffer[2] << 8) + buffer[3]; | |
669 | val >>= 12; | |
670 | break; | |
671 | ||
672 | case '2': | |
673 | val = (buffer[2] << 8) + buffer[3]; | |
674 | val >>= 6; | |
675 | break; | |
676 | ||
677 | case '3': | |
678 | case 'j': | |
679 | val = (buffer[2] << 8) + buffer[3]; | |
680 | break; | |
681 | ||
682 | case '4': | |
683 | val = (buffer[4] << 8) + buffer[5]; | |
684 | val >>= 12; | |
685 | break; | |
686 | ||
687 | case '5': | |
688 | val = (buffer[4] << 8) + buffer[5]; | |
689 | val >>= 6; | |
690 | break; | |
691 | ||
692 | case '6': | |
693 | val = (buffer[4] << 8) + buffer[5]; | |
694 | break; | |
695 | ||
696 | case '7': | |
697 | val = (buffer[2] << 8) + buffer[3]; | |
698 | val >>= 7; | |
699 | break; | |
700 | ||
701 | case '8': | |
702 | val = (buffer[2] << 8) + buffer[3]; | |
703 | val >>= 10; | |
704 | break; | |
705 | ||
706 | default: | |
707 | abort (); | |
708 | } | |
709 | ||
710 | switch (bits) | |
711 | { | |
712 | case 3: | |
713 | return val & 7; | |
714 | case 4: | |
715 | return val & 017; | |
716 | case 5: | |
717 | return val & 037; | |
718 | case 6: | |
719 | return val & 077; | |
720 | case 7: | |
721 | return val & 0177; | |
722 | case 8: | |
723 | return val & 0377; | |
724 | case 12: | |
725 | return val & 07777; | |
726 | default: | |
727 | abort (); | |
728 | return(0); | |
729 | } | |
730 | } /* fetch_arg() */ | |
731 | ||
732 | /* Print an indexed argument. The base register is BASEREG (-1 for pc). | |
733 | P points to extension word, in buffer. | |
734 | ADDR is the nominal core address of that extension word. */ | |
735 | ||
736 | static unsigned char * | |
737 | print_indexed (basereg, p, addr, stream) | |
738 | int basereg; | |
739 | unsigned char *p; | |
740 | FILE *stream; | |
741 | bfd_vma addr; | |
742 | { | |
743 | register int word; | |
744 | static char *scales[] = {"", "*2", "*4", "*8"}; | |
745 | register int base_disp; | |
746 | register int outer_disp; | |
747 | char buf[40]; | |
748 | ||
749 | word = NEXTWORD (p); | |
750 | ||
751 | /* Generate the text for the index register. | |
752 | Where this will be output is not yet determined. */ | |
753 | sprintf (buf, "[%s.%c%s]", | |
754 | reg_names[(word >> 12) & 0xf], | |
755 | (word & 0x800) ? 'l' : 'w', | |
756 | scales[(word >> 9) & 3]); | |
757 | ||
758 | /* Handle the 68000 style of indexing. */ | |
759 | ||
760 | if ((word & 0x100) == 0) | |
761 | { | |
762 | print_base (basereg, | |
763 | ((word & 0x80) ? word | 0xff00 : word & 0xff) | |
764 | + ((basereg == -1) ? addr : 0), | |
765 | stream); | |
766 | fputs (buf, stream); | |
767 | return p; | |
768 | } | |
769 | ||
770 | /* Handle the generalized kind. */ | |
771 | /* First, compute the displacement to add to the base register. */ | |
772 | ||
773 | if (word & 0200) | |
774 | basereg = -2; | |
775 | if (word & 0100) | |
776 | buf[0] = 0; | |
777 | base_disp = 0; | |
778 | switch ((word >> 4) & 3) | |
779 | { | |
780 | case 2: | |
781 | base_disp = NEXTWORD (p); | |
782 | break; | |
783 | case 3: | |
784 | base_disp = NEXTLONG (p); | |
785 | } | |
786 | if (basereg == -1) | |
787 | base_disp += addr; | |
788 | ||
789 | /* Handle single-level case (not indirect) */ | |
790 | ||
791 | if ((word & 7) == 0) | |
792 | { | |
793 | print_base (basereg, base_disp, stream); | |
794 | fputs (buf, stream); | |
795 | return p; | |
796 | } | |
797 | ||
798 | /* Two level. Compute displacement to add after indirection. */ | |
799 | ||
800 | outer_disp = 0; | |
801 | switch (word & 3) | |
802 | { | |
803 | case 2: | |
804 | outer_disp = NEXTWORD (p); | |
805 | break; | |
806 | case 3: | |
807 | outer_disp = NEXTLONG (p); | |
808 | } | |
809 | ||
810 | fprintf (stream, "%d(", outer_disp); | |
811 | print_base (basereg, base_disp, stream); | |
812 | ||
813 | /* If postindexed, print the closeparen before the index. */ | |
814 | if (word & 4) | |
815 | fprintf (stream, ")%s", buf); | |
816 | /* If preindexed, print the closeparen after the index. */ | |
817 | else | |
818 | fprintf (stream, "%s)", buf); | |
819 | ||
820 | return p; | |
821 | } | |
822 | ||
823 | /* Print a base register REGNO and displacement DISP, on STREAM. | |
824 | REGNO = -1 for pc, -2 for none (suppressed). */ | |
825 | ||
826 | static void | |
827 | print_base (regno, disp, stream) | |
828 | int regno; | |
829 | int disp; | |
830 | FILE *stream; | |
831 | { | |
832 | if (regno == -2) | |
833 | fprintf (stream, "%d", disp); | |
834 | else if (regno == -1) | |
835 | fprintf (stream, "0x%x", (unsigned) disp); | |
836 | else | |
837 | fprintf (stream, "%d(%s)", disp, reg_names[regno]); | |
838 | } |