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