/src/binutils-gdb/opcodes/m68k-dis.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Print Motorola 68k instructions. |
2 | | Copyright (C) 1986-2025 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of the GNU opcodes library. |
5 | | |
6 | | This library is free software; you can redistribute it and/or modify |
7 | | it under the terms of the GNU General Public License as published by |
8 | | the Free Software Foundation; either version 3, or (at your option) |
9 | | any later version. |
10 | | |
11 | | It is distributed in the hope that it will be useful, but WITHOUT |
12 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
13 | | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
14 | | License for more details. |
15 | | |
16 | | You should have received a copy of the GNU General Public License |
17 | | along with this program; if not, write to the Free Software |
18 | | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | | MA 02110-1301, USA. */ |
20 | | |
21 | | #include "sysdep.h" |
22 | | #include "disassemble.h" |
23 | | #include "floatformat.h" |
24 | | #include "libiberty.h" |
25 | | #include "opintl.h" |
26 | | #include "cpu-m68k.h" |
27 | | #include "opcode/m68k.h" |
28 | | |
29 | | /* Local function prototypes. */ |
30 | | |
31 | | const char * const fpcr_names[] = |
32 | | { |
33 | | "", "%fpiar", "%fpsr", "%fpiar/%fpsr", "%fpcr", |
34 | | "%fpiar/%fpcr", "%fpsr/%fpcr", "%fpiar/%fpsr/%fpcr" |
35 | | }; |
36 | | |
37 | | static char *const reg_names[] = |
38 | | { |
39 | | "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7", |
40 | | "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%fp", "%sp", |
41 | | "%ps", "%pc" |
42 | | }; |
43 | | |
44 | | /* Name of register halves for MAC/EMAC. |
45 | | Seperate from reg_names since 'spu', 'fpl' look weird. */ |
46 | | static char *const reg_half_names[] = |
47 | | { |
48 | | "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7", |
49 | | "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6", "%a7", |
50 | | "%ps", "%pc" |
51 | | }; |
52 | | |
53 | | /* Sign-extend an (unsigned char). */ |
54 | | #if __STDC__ == 1 |
55 | 2.41M | #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 | | /* Error code of print_insn_arg's return value. */ |
61 | | |
62 | | enum print_insn_arg_error |
63 | | { |
64 | | /* An invalid operand is found. */ |
65 | | PRINT_INSN_ARG_INVALID_OPERAND = -1, |
66 | | |
67 | | /* An opcode table error. */ |
68 | | PRINT_INSN_ARG_INVALID_OP_TABLE = -2, |
69 | | |
70 | | /* A memory error. */ |
71 | | PRINT_INSN_ARG_MEMORY_ERROR = -3, |
72 | | }; |
73 | | |
74 | | /* Get a 1 byte signed integer. */ |
75 | | #define NEXTBYTE(p, val) \ |
76 | 2.01M | do \ |
77 | 2.01M | { \ |
78 | 2.01M | p += 2; \ |
79 | 2.01M | if (!FETCH_DATA (info, p)) \ |
80 | 2.01M | return PRINT_INSN_ARG_MEMORY_ERROR; \ |
81 | 2.01M | val = COERCE_SIGNED_CHAR (p[-1]); \ |
82 | 2.01M | } \ |
83 | 2.01M | while (0) |
84 | | |
85 | | /* Get a 2 byte signed integer. */ |
86 | 1.32M | #define COERCE16(x) ((int) (((x) ^ 0x8000) - 0x8000)) |
87 | | |
88 | | #define NEXTWORD(p, val, ret_val) \ |
89 | 1.32M | do \ |
90 | 1.32M | { \ |
91 | 1.32M | p += 2; \ |
92 | 1.32M | if (!FETCH_DATA (info, p)) \ |
93 | 1.32M | return ret_val; \ |
94 | 1.32M | val = COERCE16 ((p[-2] << 8) + p[-1]); \ |
95 | 1.32M | } \ |
96 | 1.32M | while (0) |
97 | | |
98 | | /* Get a 4 byte signed integer. */ |
99 | 200k | #define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000) |
100 | | |
101 | | #define NEXTLONG(p, val, ret_val) \ |
102 | 200k | do \ |
103 | 200k | { \ |
104 | 200k | p += 4; \ |
105 | 200k | if (!FETCH_DATA (info, p)) \ |
106 | 200k | return ret_val; \ |
107 | 200k | val = COERCE32 (((((((unsigned) p[-4] << 8) + p[-3]) << 8) \ |
108 | 200k | + p[-2]) << 8) + p[-1]); \ |
109 | 200k | } \ |
110 | 200k | while (0) |
111 | | |
112 | | /* Get a 4 byte unsigned integer. */ |
113 | | #define NEXTULONG(p, val) \ |
114 | 45.4k | do \ |
115 | 45.4k | { \ |
116 | 45.4k | p += 4; \ |
117 | 45.4k | if (!FETCH_DATA (info, p)) \ |
118 | 45.4k | return PRINT_INSN_ARG_MEMORY_ERROR; \ |
119 | 45.4k | val = (((((((unsigned) p[-4] << 8) + p[-3]) << 8) \ |
120 | 45.4k | + p[-2]) << 8) + p[-1]); \ |
121 | 45.4k | } \ |
122 | 45.4k | while (0) |
123 | | |
124 | | /* Get a single precision float. */ |
125 | | #define NEXTSINGLE(val, p) \ |
126 | 565 | do \ |
127 | 565 | { \ |
128 | 565 | p += 4; \ |
129 | 565 | if (!FETCH_DATA (info, p)) \ |
130 | 565 | return PRINT_INSN_ARG_MEMORY_ERROR; \ |
131 | 565 | floatformat_to_double (& floatformat_ieee_single_big, \ |
132 | 564 | (char *) p - 4, & val); \ |
133 | 564 | } \ |
134 | 565 | while (0) |
135 | | |
136 | | /* Get a double precision float. */ |
137 | | #define NEXTDOUBLE(val, p) \ |
138 | 763 | do \ |
139 | 763 | { \ |
140 | 763 | p += 8; \ |
141 | 763 | if (!FETCH_DATA (info, p)) \ |
142 | 763 | return PRINT_INSN_ARG_MEMORY_ERROR; \ |
143 | 763 | floatformat_to_double (& floatformat_ieee_double_big, \ |
144 | 762 | (char *) p - 8, & val); \ |
145 | 762 | } \ |
146 | 763 | while (0) |
147 | | |
148 | | /* Get an extended precision float. */ |
149 | | #define NEXTEXTEND(val, p) \ |
150 | 823 | do \ |
151 | 823 | { \ |
152 | 823 | p += 12; \ |
153 | 823 | if (!FETCH_DATA (info, p)) \ |
154 | 823 | return PRINT_INSN_ARG_MEMORY_ERROR; \ |
155 | 823 | floatformat_to_double (& floatformat_m68881_ext, \ |
156 | 822 | (char *) p - 12, & val); \ |
157 | 822 | } \ |
158 | 823 | while (0) |
159 | | |
160 | | /* Need a function to convert from packed to double |
161 | | precision. Actually, it's easier to print a |
162 | | packed number than a double anyway, so maybe |
163 | | there should be a special case to handle this... */ |
164 | | #define NEXTPACKED(p, val) \ |
165 | 553 | do \ |
166 | 553 | { \ |
167 | 553 | p += 12; \ |
168 | 553 | if (!FETCH_DATA (info, p)) \ |
169 | 553 | return PRINT_INSN_ARG_MEMORY_ERROR; \ |
170 | 553 | val = 0.0; \ |
171 | 550 | } \ |
172 | 553 | while (0) |
173 | | |
174 | | |
175 | | /* Maximum length of an instruction. */ |
176 | | #define MAXLEN 22 |
177 | | |
178 | | struct private |
179 | | { |
180 | | /* Points to first byte not fetched. */ |
181 | | bfd_byte *max_fetched; |
182 | | bfd_byte the_buffer[MAXLEN]; |
183 | | bfd_vma insn_start; |
184 | | }; |
185 | | |
186 | | /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive) |
187 | | to ADDR (exclusive) are valid. Returns 1 for success, 0 on memory |
188 | | error. */ |
189 | | #define FETCH_DATA(info, addr) \ |
190 | 91.4M | ((addr) <= ((struct private *) (info->private_data))->max_fetched \ |
191 | 91.4M | ? 1 : fetch_data ((info), (addr))) |
192 | | |
193 | | static int |
194 | | fetch_data (struct disassemble_info *info, bfd_byte *addr) |
195 | 5.89M | { |
196 | 5.89M | int status; |
197 | 5.89M | struct private *priv = (struct private *)info->private_data; |
198 | 5.89M | bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer); |
199 | | |
200 | 5.89M | status = (*info->read_memory_func) (start, |
201 | 5.89M | priv->max_fetched, |
202 | 5.89M | addr - priv->max_fetched, |
203 | 5.89M | info); |
204 | 5.89M | if (status != 0) |
205 | 26.0k | { |
206 | 26.0k | (*info->memory_error_func) (status, start, info); |
207 | 26.0k | return 0; |
208 | 26.0k | } |
209 | 5.86M | else |
210 | 5.86M | priv->max_fetched = addr; |
211 | 5.86M | return 1; |
212 | 5.89M | } |
213 | | |
214 | | /* This function is used to print to the bit-bucket. */ |
215 | | static int |
216 | | dummy_printer (void *file ATTRIBUTE_UNUSED, |
217 | | enum disassembler_style style ATTRIBUTE_UNUSED, |
218 | | const char *format ATTRIBUTE_UNUSED, |
219 | | ...) |
220 | 9.13M | { |
221 | 9.13M | return 0; |
222 | 9.13M | } |
223 | | |
224 | | static void |
225 | | dummy_print_address (bfd_vma vma ATTRIBUTE_UNUSED, |
226 | | struct disassemble_info *info ATTRIBUTE_UNUSED) |
227 | 299k | { |
228 | 299k | } |
229 | | |
230 | | /* Fetch BITS bits from a position in the instruction specified by CODE. |
231 | | CODE is a "place to put an argument", or 'x' for a destination |
232 | | that is a general address (mode and register). |
233 | | BUFFER contains the instruction. |
234 | | Returns -1 on failure. */ |
235 | | |
236 | | static int |
237 | | fetch_arg (unsigned char *buffer, |
238 | | int code, |
239 | | int bits, |
240 | | disassemble_info *info) |
241 | 10.2M | { |
242 | 10.2M | int val = 0; |
243 | | |
244 | 10.2M | switch (code) |
245 | 10.2M | { |
246 | 33.6k | case '/': /* MAC/EMAC mask bit. */ |
247 | 33.6k | val = buffer[3] >> 5; |
248 | 33.6k | break; |
249 | | |
250 | 1.54k | case 'G': /* EMAC ACC load. */ |
251 | 1.54k | val = ((buffer[3] >> 3) & 0x2) | ((~buffer[1] >> 7) & 0x1); |
252 | 1.54k | break; |
253 | | |
254 | 1.16k | case 'H': /* EMAC ACC !load. */ |
255 | 1.16k | val = ((buffer[3] >> 3) & 0x2) | ((buffer[1] >> 7) & 0x1); |
256 | 1.16k | break; |
257 | | |
258 | 272 | case ']': /* EMAC ACCEXT bit. */ |
259 | 272 | val = buffer[0] >> 2; |
260 | 272 | break; |
261 | | |
262 | 47.2k | case 'I': /* MAC/EMAC scale factor. */ |
263 | 47.2k | val = buffer[2] >> 1; |
264 | 47.2k | break; |
265 | | |
266 | 622 | case 'F': /* EMAC ACCx. */ |
267 | 622 | val = buffer[0] >> 1; |
268 | 622 | break; |
269 | | |
270 | 98 | case 'f': |
271 | 98 | val = buffer[1]; |
272 | 98 | break; |
273 | | |
274 | 6.32M | case 's': |
275 | 6.32M | val = buffer[1]; |
276 | 6.32M | break; |
277 | | |
278 | 2.49M | case 'd': /* Destination, for register or quick. */ |
279 | 2.49M | val = (buffer[0] << 8) + buffer[1]; |
280 | 2.49M | val >>= 9; |
281 | 2.49M | break; |
282 | | |
283 | 798k | case 'x': /* Destination, for general arg. */ |
284 | 798k | val = (buffer[0] << 8) + buffer[1]; |
285 | 798k | val >>= 6; |
286 | 798k | break; |
287 | | |
288 | 148 | case 'k': |
289 | 148 | if (! FETCH_DATA (info, buffer + 3)) |
290 | 0 | return -1; |
291 | 148 | val = (buffer[3] >> 4); |
292 | 148 | break; |
293 | | |
294 | 250 | case 'C': |
295 | 250 | if (! FETCH_DATA (info, buffer + 3)) |
296 | 0 | return -1; |
297 | 250 | val = buffer[3]; |
298 | 250 | break; |
299 | | |
300 | 117k | case '1': |
301 | 117k | if (! FETCH_DATA (info, buffer + 3)) |
302 | 0 | return -1; |
303 | 117k | val = (buffer[2] << 8) + buffer[3]; |
304 | 117k | val >>= 12; |
305 | 117k | break; |
306 | | |
307 | 5.29k | case '2': |
308 | 5.29k | if (! FETCH_DATA (info, buffer + 3)) |
309 | 0 | return -1; |
310 | 5.29k | val = (buffer[2] << 8) + buffer[3]; |
311 | 5.29k | val >>= 6; |
312 | 5.29k | break; |
313 | | |
314 | 99.4k | case '3': |
315 | 101k | case 'j': |
316 | 101k | if (! FETCH_DATA (info, buffer + 3)) |
317 | 0 | return -1; |
318 | 101k | val = (buffer[2] << 8) + buffer[3]; |
319 | 101k | break; |
320 | | |
321 | 330 | case '4': |
322 | 330 | if (! FETCH_DATA (info, buffer + 5)) |
323 | 0 | return -1; |
324 | 330 | val = (buffer[4] << 8) + buffer[5]; |
325 | 330 | val >>= 12; |
326 | 330 | break; |
327 | | |
328 | 330 | case '5': |
329 | 330 | if (! FETCH_DATA (info, buffer + 5)) |
330 | 0 | return -1; |
331 | 330 | val = (buffer[4] << 8) + buffer[5]; |
332 | 330 | val >>= 6; |
333 | 330 | break; |
334 | | |
335 | 330 | case '6': |
336 | 330 | if (! FETCH_DATA (info, buffer + 5)) |
337 | 0 | return -1; |
338 | 330 | val = (buffer[4] << 8) + buffer[5]; |
339 | 330 | break; |
340 | | |
341 | 8.07k | case '7': |
342 | 8.07k | if (! FETCH_DATA (info, buffer + 3)) |
343 | 0 | return -1; |
344 | 8.07k | val = (buffer[2] << 8) + buffer[3]; |
345 | 8.07k | val >>= 7; |
346 | 8.07k | break; |
347 | | |
348 | 14.8k | case '8': |
349 | 14.8k | if (! FETCH_DATA (info, buffer + 3)) |
350 | 0 | return -1; |
351 | 14.8k | val = (buffer[2] << 8) + buffer[3]; |
352 | 14.8k | val >>= 10; |
353 | 14.8k | break; |
354 | | |
355 | 314 | case '9': |
356 | 314 | if (! FETCH_DATA (info, buffer + 3)) |
357 | 0 | return -1; |
358 | 314 | val = (buffer[2] << 8) + buffer[3]; |
359 | 314 | val >>= 5; |
360 | 314 | break; |
361 | | |
362 | 12.0k | case 'e': |
363 | 12.0k | val = (buffer[1] >> 6); |
364 | 12.0k | break; |
365 | | |
366 | 93.3k | case 'E': |
367 | 93.3k | if (! FETCH_DATA (info, buffer + 3)) |
368 | 0 | return -1; |
369 | 93.3k | val = (buffer[2] >> 1); |
370 | 93.3k | break; |
371 | | |
372 | 24.1k | case 'm': |
373 | 24.1k | val = (buffer[1] & 0x40 ? 0x8 : 0) |
374 | 24.1k | | ((buffer[0] >> 1) & 0x7) |
375 | 24.1k | | (buffer[3] & 0x80 ? 0x10 : 0); |
376 | 24.1k | break; |
377 | | |
378 | 33.6k | case 'n': |
379 | 33.6k | val = (buffer[1] & 0x40 ? 0x8 : 0) | ((buffer[0] >> 1) & 0x7); |
380 | 33.6k | break; |
381 | | |
382 | 46.5k | case 'o': |
383 | 46.5k | val = (buffer[2] >> 4) | (buffer[3] & 0x80 ? 0x10 : 0); |
384 | 46.5k | break; |
385 | | |
386 | 24.1k | case 'M': |
387 | 24.1k | val = (buffer[1] & 0xf) | (buffer[3] & 0x40 ? 0x10 : 0); |
388 | 24.1k | break; |
389 | | |
390 | 46.5k | case 'N': |
391 | 46.5k | val = (buffer[3] & 0xf) | (buffer[3] & 0x40 ? 0x10 : 0); |
392 | 46.5k | break; |
393 | | |
394 | 1.87k | case 'h': |
395 | 1.87k | val = buffer[2] >> 2; |
396 | 1.87k | break; |
397 | | |
398 | 0 | default: |
399 | 0 | abort (); |
400 | 10.2M | } |
401 | | |
402 | | /* bits is never too big. */ |
403 | 10.2M | return val & ((1 << bits) - 1); |
404 | 10.2M | } |
405 | | |
406 | | /* Check if an EA is valid for a particular code. This is required |
407 | | for the EMAC instructions since the type of source address determines |
408 | | if it is a EMAC-load instruciton if the EA is mode 2-5, otherwise it |
409 | | is a non-load EMAC instruction and the bits mean register Ry. |
410 | | A similar case exists for the movem instructions where the register |
411 | | mask is interpreted differently for different EAs. */ |
412 | | |
413 | | static bool |
414 | | m68k_valid_ea (char code, int val) |
415 | 6.57M | { |
416 | 6.57M | int mode, mask; |
417 | 6.57M | #define M(n0,n1,n2,n3,n4,n5,n6,n70,n71,n72,n73,n74) \ |
418 | 6.57M | (n0 | n1 << 1 | n2 << 2 | n3 << 3 | n4 << 4 | n5 << 5 | n6 << 6 \ |
419 | 6.57M | | n70 << 7 | n71 << 8 | n72 << 9 | n73 << 10 | n74 << 11) |
420 | | |
421 | 6.57M | switch (code) |
422 | 6.57M | { |
423 | 1.04M | case '*': |
424 | 1.04M | mask = M (1,1,1,1,1,1,1,1,1,1,1,1); |
425 | 1.04M | break; |
426 | 246k | case '~': |
427 | 246k | mask = M (0,0,1,1,1,1,1,1,1,0,0,0); |
428 | 246k | break; |
429 | 939k | case '%': |
430 | 939k | mask = M (1,1,1,1,1,1,1,1,1,0,0,0); |
431 | 939k | break; |
432 | 994k | case ';': |
433 | 994k | mask = M (1,0,1,1,1,1,1,1,1,1,1,1); |
434 | 994k | break; |
435 | 23.1k | case '@': |
436 | 23.1k | mask = M (1,0,1,1,1,1,1,1,1,1,1,0); |
437 | 23.1k | break; |
438 | 39.6k | case '!': |
439 | 39.6k | mask = M (0,0,1,0,0,1,1,1,1,1,1,0); |
440 | 39.6k | break; |
441 | 13.9k | case '&': |
442 | 13.9k | mask = M (0,0,1,0,0,1,1,1,1,0,0,0); |
443 | 13.9k | break; |
444 | 2.83M | case '$': |
445 | 2.83M | mask = M (1,0,1,1,1,1,1,1,1,0,0,0); |
446 | 2.83M | break; |
447 | 3.22k | case '?': |
448 | 3.22k | mask = M (1,0,1,0,0,1,1,1,1,0,0,0); |
449 | 3.22k | break; |
450 | 2.71k | case '/': |
451 | 2.71k | mask = M (1,0,1,0,0,1,1,1,1,1,1,0); |
452 | 2.71k | break; |
453 | 175 | case '|': |
454 | 175 | mask = M (0,0,1,0,0,1,1,1,1,1,1,0); |
455 | 175 | break; |
456 | 11.9k | case '>': |
457 | 11.9k | mask = M (0,0,1,0,1,1,1,1,1,0,0,0); |
458 | 11.9k | break; |
459 | 11.7k | case '<': |
460 | 11.7k | mask = M (0,0,1,1,0,1,1,1,1,1,1,0); |
461 | 11.7k | break; |
462 | 80.4k | case 'm': |
463 | 80.4k | mask = M (1,1,1,1,1,0,0,0,0,0,0,0); |
464 | 80.4k | break; |
465 | 83.4k | case 'n': |
466 | 83.4k | mask = M (0,0,0,0,0,1,0,0,0,1,0,0); |
467 | 83.4k | break; |
468 | 64.1k | case 'o': |
469 | 64.1k | mask = M (0,0,0,0,0,0,1,1,1,0,1,1); |
470 | 64.1k | break; |
471 | 113k | case 'p': |
472 | 113k | mask = M (1,1,1,1,1,1,0,0,0,0,0,0); |
473 | 113k | break; |
474 | 18.1k | case 'q': |
475 | 18.1k | mask = M (1,0,1,1,1,1,0,0,0,0,0,0); |
476 | 18.1k | break; |
477 | 4.14k | case 'v': |
478 | 4.14k | mask = M (1,0,1,1,1,1,0,1,1,0,0,0); |
479 | 4.14k | break; |
480 | 50 | case 'b': |
481 | 50 | mask = M (1,0,1,1,1,1,0,0,0,1,0,0); |
482 | 50 | break; |
483 | 91 | case 'w': |
484 | 91 | mask = M (0,0,1,1,1,1,0,0,0,1,0,0); |
485 | 91 | break; |
486 | 4.76k | case 'y': |
487 | 4.76k | mask = M (0,0,1,0,0,1,0,0,0,0,0,0); |
488 | 4.76k | break; |
489 | 508 | case 'z': |
490 | 508 | mask = M (0,0,1,0,0,1,0,0,0,1,0,0); |
491 | 508 | break; |
492 | 38.6k | case '4': |
493 | 38.6k | mask = M (0,0,1,1,1,1,0,0,0,0,0,0); |
494 | 38.6k | break; |
495 | 0 | default: |
496 | 0 | abort (); |
497 | 6.57M | } |
498 | 6.57M | #undef M |
499 | | |
500 | 6.57M | mode = (val >> 3) & 7; |
501 | 6.57M | if (mode == 7) |
502 | 553k | mode += val & 7; |
503 | 6.57M | return (mask & (1 << mode)) != 0; |
504 | 6.57M | } |
505 | | |
506 | | /* Print a base register REGNO and displacement DISP, on INFO->STREAM. |
507 | | REGNO = -1 for pc, -2 for none (suppressed). */ |
508 | | |
509 | | static void |
510 | | print_base (int regno, bfd_vma disp, disassemble_info *info) |
511 | 410k | { |
512 | 410k | if (regno == -1) |
513 | 17.4k | { |
514 | 17.4k | (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%pc"); |
515 | 17.4k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@("); |
516 | 17.4k | (*info->print_address_func) (disp, info); |
517 | 17.4k | } |
518 | 392k | else |
519 | 392k | { |
520 | 392k | if (regno == -3) |
521 | 4.91k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
522 | 4.91k | "%%zpc"); |
523 | 387k | else if (regno != -2) |
524 | 334k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
525 | 334k | "%s", reg_names[regno]); |
526 | 392k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@("); |
527 | 392k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
528 | 392k | "%" PRIx64, (uint64_t) disp); |
529 | 392k | } |
530 | 410k | } |
531 | | |
532 | | /* Print the index register of an indexed argument, as encoded in the |
533 | | extension word. */ |
534 | | |
535 | | static void |
536 | | print_index_register (int ext, disassemble_info *info) |
537 | 324k | { |
538 | 324k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
539 | 324k | "%s", reg_names[(ext >> 12) & 0xf]); |
540 | 324k | (*info->fprintf_styled_func) (info->stream, dis_style_text, |
541 | 324k | ":%c", ext & 0x800 ? 'l' : 'w'); |
542 | 324k | if ((ext >> 9) & 3) |
543 | 182k | { |
544 | 182k | (*info->fprintf_styled_func) (info->stream, dis_style_text, ":"); |
545 | 182k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
546 | 182k | "%d", 1 << ((ext >> 9) & 3)); |
547 | 182k | } |
548 | 324k | } |
549 | | |
550 | | /* Print an indexed argument. The base register is BASEREG (-1 for pc). |
551 | | P points to extension word, in buffer. |
552 | | ADDR is the nominal core address of that extension word. |
553 | | Returns NULL upon error. */ |
554 | | |
555 | | static unsigned char * |
556 | | print_indexed (int basereg, |
557 | | unsigned char *p, |
558 | | bfd_vma addr, |
559 | | disassemble_info *info) |
560 | 410k | { |
561 | 410k | int word; |
562 | 410k | bfd_vma base_disp; |
563 | 410k | bfd_vma outer_disp; |
564 | 410k | bool print_index = true; |
565 | | |
566 | 410k | NEXTWORD (p, word, NULL); |
567 | | |
568 | | /* Handle the 68000 style of indexing. */ |
569 | | |
570 | 410k | if ((word & 0x100) == 0) |
571 | 241k | { |
572 | 241k | base_disp = word & 0xff; |
573 | 241k | if ((base_disp & 0x80) != 0) |
574 | 68.2k | base_disp -= 0x100; |
575 | 241k | if (basereg == -1) |
576 | 11.3k | base_disp += addr; |
577 | 241k | print_base (basereg, base_disp, info); |
578 | 241k | (*info->fprintf_styled_func) (info->stream, dis_style_text, ","); |
579 | 241k | print_index_register (word, info); |
580 | 241k | (*info->fprintf_styled_func) (info->stream, dis_style_text, ")"); |
581 | 241k | return p; |
582 | 241k | } |
583 | | |
584 | | /* Handle the generalized kind. */ |
585 | | /* First, compute the displacement to add to the base register. */ |
586 | 169k | if (word & 0200) |
587 | 58.3k | { |
588 | 58.3k | if (basereg == -1) |
589 | 4.92k | basereg = -3; |
590 | 53.4k | else |
591 | 53.4k | basereg = -2; |
592 | 58.3k | } |
593 | 169k | if (word & 0100) |
594 | 85.5k | print_index = false; |
595 | 169k | base_disp = 0; |
596 | 169k | switch ((word >> 4) & 3) |
597 | 169k | { |
598 | 43.0k | case 2: |
599 | 43.0k | NEXTWORD (p, base_disp, NULL); |
600 | 43.0k | break; |
601 | 48.7k | case 3: |
602 | 48.7k | NEXTLONG (p, base_disp, NULL); |
603 | 169k | } |
604 | 169k | if (basereg == -1) |
605 | 6.11k | base_disp += addr; |
606 | | |
607 | | /* Handle single-level case (not indirect). */ |
608 | 169k | if ((word & 7) == 0) |
609 | 34.6k | { |
610 | 34.6k | print_base (basereg, base_disp, info); |
611 | 34.6k | if (print_index) |
612 | 24.4k | { |
613 | 24.4k | (*info->fprintf_styled_func) (info->stream, dis_style_text, ","); |
614 | 24.4k | print_index_register (word, info); |
615 | 24.4k | } |
616 | 34.6k | (*info->fprintf_styled_func) (info->stream, dis_style_text, ")"); |
617 | 34.6k | return p; |
618 | 34.6k | } |
619 | | |
620 | | /* Two level. Compute displacement to add after indirection. */ |
621 | 134k | outer_disp = 0; |
622 | 134k | switch (word & 3) |
623 | 134k | { |
624 | 39.5k | case 2: |
625 | 39.5k | NEXTWORD (p, outer_disp, NULL); |
626 | 39.5k | break; |
627 | 39.5k | case 3: |
628 | 35.0k | NEXTLONG (p, outer_disp, NULL); |
629 | 134k | } |
630 | | |
631 | 134k | print_base (basereg, base_disp, info); |
632 | 134k | if ((word & 4) == 0 && print_index) |
633 | 27.8k | { |
634 | 27.8k | (*info->fprintf_styled_func) (info->stream, dis_style_text, ","); |
635 | 27.8k | print_index_register (word, info); |
636 | 27.8k | print_index = false; |
637 | 27.8k | } |
638 | 134k | (*info->fprintf_styled_func) (info->stream, dis_style_text, |
639 | 134k | ")@("); |
640 | 134k | (*info->fprintf_styled_func) (info->stream, dis_style_address_offset, |
641 | 134k | "%" PRIx64, (uint64_t) outer_disp); |
642 | 134k | if (print_index) |
643 | 31.2k | { |
644 | 31.2k | (*info->fprintf_styled_func) (info->stream, dis_style_text, ","); |
645 | 31.2k | print_index_register (word, info); |
646 | 31.2k | } |
647 | 134k | (*info->fprintf_styled_func) (info->stream, dis_style_text, ")"); |
648 | | |
649 | 134k | return p; |
650 | 134k | } |
651 | | |
652 | | #define FETCH_ARG(size, val) \ |
653 | 3.54M | do \ |
654 | 3.54M | { \ |
655 | 3.54M | val = fetch_arg (buffer, place, size, info); \ |
656 | 3.54M | if (val < 0) \ |
657 | 3.54M | return PRINT_INSN_ARG_MEMORY_ERROR; \ |
658 | 3.54M | } \ |
659 | 3.54M | while (0) |
660 | | |
661 | | /* Returns number of bytes "eaten" by the operand, or |
662 | | return enum print_insn_arg_error. ADDR is the pc for this arg to be |
663 | | relative to. */ |
664 | | |
665 | | static int |
666 | | print_insn_arg (const char *d, |
667 | | unsigned char *buffer, |
668 | | unsigned char *p0, |
669 | | bfd_vma addr, |
670 | | disassemble_info *info) |
671 | 12.9M | { |
672 | 12.9M | int val = 0; |
673 | 12.9M | int place = d[1]; |
674 | 12.9M | unsigned char *p = p0; |
675 | 12.9M | int regno; |
676 | 12.9M | const char *regname; |
677 | 12.9M | unsigned char *p1; |
678 | 12.9M | double flval; |
679 | 12.9M | int flt_p; |
680 | 12.9M | bfd_signed_vma disp; |
681 | 12.9M | unsigned int uval; |
682 | | |
683 | 12.9M | switch (*d) |
684 | 12.9M | { |
685 | 12.0k | case 'c': /* Cache identifier. */ |
686 | 12.0k | { |
687 | 12.0k | static char *const cacheFieldName[] = { "nc", "dc", "ic", "bc" }; |
688 | 12.0k | FETCH_ARG (2, val); |
689 | 12.0k | (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic, |
690 | 12.0k | "%s", cacheFieldName[val]); |
691 | 12.0k | break; |
692 | 12.0k | } |
693 | | |
694 | 16.4k | case 'a': /* Address register indirect only. Cf. case '+'. */ |
695 | 16.4k | { |
696 | 16.4k | FETCH_ARG (3, val); |
697 | 16.4k | (*info->fprintf_styled_func) (info->stream, dis_style_register, "%s", |
698 | 16.4k | reg_names[val + 8]); |
699 | 16.4k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@"); |
700 | 16.4k | break; |
701 | 16.4k | } |
702 | | |
703 | 2.26k | case '_': /* 32-bit absolute address for move16. */ |
704 | 2.26k | { |
705 | 2.26k | NEXTULONG (p, uval); |
706 | 2.26k | (*info->print_address_func) (uval, info); |
707 | 2.26k | break; |
708 | 2.26k | } |
709 | | |
710 | 9.60k | case 'C': |
711 | 9.60k | (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%ccr"); |
712 | 9.60k | break; |
713 | | |
714 | 9.56k | case 'S': |
715 | 9.56k | (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%sr"); |
716 | 9.56k | break; |
717 | | |
718 | 864 | case 'U': |
719 | 864 | (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%usp"); |
720 | 864 | break; |
721 | | |
722 | 3.17k | case 'E': |
723 | 3.17k | (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%acc"); |
724 | 3.17k | break; |
725 | | |
726 | 2.44k | case 'G': |
727 | 2.44k | (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%macsr"); |
728 | 2.44k | break; |
729 | | |
730 | 5.64k | case 'H': |
731 | 5.64k | (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%mask"); |
732 | 5.64k | break; |
733 | | |
734 | 2.48k | case 'J': |
735 | 2.48k | { |
736 | | /* FIXME: There's a problem here, different m68k processors call the |
737 | | same address different names. The tables below try to get it right |
738 | | using info->mach, but only for v4e. */ |
739 | 2.48k | struct regname { char * name; int value; }; |
740 | 2.48k | static const struct regname names[] = |
741 | 2.48k | { |
742 | 2.48k | {"%sfc", 0x000}, {"%dfc", 0x001}, {"%cacr", 0x002}, |
743 | 2.48k | {"%tc", 0x003}, {"%itt0",0x004}, {"%itt1", 0x005}, |
744 | 2.48k | {"%dtt0",0x006}, {"%dtt1",0x007}, {"%buscr",0x008}, |
745 | 2.48k | {"%rgpiobar", 0x009}, {"%acr4",0x00c}, |
746 | 2.48k | {"%acr5",0x00d}, {"%acr6",0x00e}, {"%acr7", 0x00f}, |
747 | 2.48k | {"%usp", 0x800}, {"%vbr", 0x801}, {"%caar", 0x802}, |
748 | 2.48k | {"%msp", 0x803}, {"%isp", 0x804}, |
749 | 2.48k | {"%pc", 0x80f}, |
750 | | /* Reg c04 is sometimes called flashbar or rambar. |
751 | | Reg c05 is also sometimes called rambar. */ |
752 | 2.48k | {"%rambar0", 0xc04}, {"%rambar1", 0xc05}, |
753 | | |
754 | | /* reg c0e is sometimes called mbar2 or secmbar. |
755 | | reg c0f is sometimes called mbar. */ |
756 | 2.48k | {"%mbar0", 0xc0e}, {"%mbar1", 0xc0f}, |
757 | | |
758 | | /* Should we be calling this psr like we do in case 'Y'? */ |
759 | 2.48k | {"%mmusr",0x805}, |
760 | | |
761 | 2.48k | {"%urp", 0x806}, {"%srp", 0x807}, {"%pcr", 0x808}, |
762 | | |
763 | | /* Fido added these. */ |
764 | 2.48k | {"%cac", 0xffe}, {"%mbo", 0xfff} |
765 | 2.48k | }; |
766 | | /* Alternate names for v4e (MCF5407/5445x/MCF547x/MCF548x), at least. */ |
767 | 2.48k | static const struct regname names_v4e[] = |
768 | 2.48k | { |
769 | 2.48k | {"%asid",0x003}, {"%acr0",0x004}, {"%acr1",0x005}, |
770 | 2.48k | {"%acr2",0x006}, {"%acr3",0x007}, {"%mmubar",0x008}, |
771 | 2.48k | }; |
772 | 2.48k | unsigned int arch_mask; |
773 | | |
774 | 2.48k | arch_mask = bfd_m68k_mach_to_features (info->mach); |
775 | 2.48k | FETCH_ARG (12, val); |
776 | 2.48k | if (arch_mask & (mcfisa_b | mcfisa_c)) |
777 | 542 | { |
778 | 3.74k | for (regno = ARRAY_SIZE (names_v4e); --regno >= 0;) |
779 | 3.25k | if (names_v4e[regno].value == val) |
780 | 54 | { |
781 | 54 | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
782 | 54 | "%s", names_v4e[regno].name); |
783 | 54 | break; |
784 | 54 | } |
785 | 542 | if (regno >= 0) |
786 | 54 | break; |
787 | 542 | } |
788 | 72.8k | for (regno = ARRAY_SIZE (names) - 1; regno >= 0; regno--) |
789 | 70.9k | if (names[regno].value == val) |
790 | 538 | { |
791 | 538 | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
792 | 538 | "%s", names[regno].name); |
793 | 538 | break; |
794 | 538 | } |
795 | 2.42k | if (regno < 0) |
796 | 1.88k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "0x%x", val); |
797 | 2.42k | } |
798 | 0 | break; |
799 | | |
800 | 548k | case 'Q': |
801 | 548k | FETCH_ARG (3, val); |
802 | | /* 0 means 8, except for the bkpt instruction... */ |
803 | 548k | if (val == 0 && d[1] != 's') |
804 | 36.4k | val = 8; |
805 | 548k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
806 | 548k | "#%d", val); |
807 | 548k | break; |
808 | | |
809 | 15.2k | case 'x': |
810 | 15.2k | FETCH_ARG (3, val); |
811 | | /* 0 means -1. */ |
812 | 15.2k | if (val == 0) |
813 | 3.18k | val = -1; |
814 | 15.2k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
815 | 15.2k | "#%d", val); |
816 | 15.2k | break; |
817 | | |
818 | 93.3k | case 'j': |
819 | 93.3k | FETCH_ARG (3, val); |
820 | 93.3k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
821 | 93.3k | "#%d", val+1); |
822 | 93.3k | break; |
823 | | |
824 | 90.5k | case 'K': |
825 | 90.5k | FETCH_ARG (9, val); |
826 | 90.5k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
827 | 90.5k | "#%d", val); |
828 | 90.5k | break; |
829 | | |
830 | 157k | case 'M': |
831 | 157k | if (place == 'h') |
832 | 1.87k | { |
833 | 1.87k | static char *const scalefactor_name[] = { "<<", ">>" }; |
834 | | |
835 | 1.87k | FETCH_ARG (1, val); |
836 | 1.87k | (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic, |
837 | 1.87k | "%s", scalefactor_name[val]); |
838 | 1.87k | } |
839 | 156k | else |
840 | 156k | { |
841 | 156k | FETCH_ARG (8, val); |
842 | 156k | if (val & 0x80) |
843 | 34.7k | val = val - 0x100; |
844 | 156k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
845 | 156k | "#%d", val); |
846 | 156k | } |
847 | 157k | break; |
848 | | |
849 | 157k | case 'T': |
850 | 3.14k | FETCH_ARG (4, val); |
851 | 3.14k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
852 | 3.14k | "#%d", val); |
853 | 3.14k | break; |
854 | | |
855 | 1.74M | case 'D': |
856 | 1.74M | FETCH_ARG (3, val); |
857 | 1.74M | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
858 | 1.74M | "%s", reg_names[val]); |
859 | 1.74M | break; |
860 | | |
861 | 285k | case 'A': |
862 | 285k | FETCH_ARG (3, val); |
863 | 285k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
864 | 285k | "%s", reg_names[val + 010]); |
865 | 285k | break; |
866 | | |
867 | 226k | case 'R': |
868 | 226k | FETCH_ARG (4, val); |
869 | 226k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
870 | 226k | "%s", reg_names[val]); |
871 | 226k | break; |
872 | | |
873 | 660 | case 'r': |
874 | 660 | FETCH_ARG (4, regno); |
875 | 660 | if (regno > 7) |
876 | 234 | { |
877 | 234 | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
878 | 234 | "%s", reg_names[regno]); |
879 | 234 | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@"); |
880 | 234 | } |
881 | 426 | else |
882 | 426 | { |
883 | 426 | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@("); |
884 | 426 | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
885 | 426 | "%s", reg_names[regno]); |
886 | 426 | (*info->fprintf_styled_func) (info->stream, dis_style_text, ")"); |
887 | 426 | } |
888 | 660 | break; |
889 | | |
890 | 12.3k | case 'F': |
891 | 12.3k | FETCH_ARG (3, val); |
892 | 12.3k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
893 | 12.3k | "%%fp%d", val); |
894 | 12.3k | break; |
895 | | |
896 | 9.01k | case 'O': |
897 | 9.01k | FETCH_ARG (6, val); |
898 | 9.01k | if (val & 0x20) |
899 | 3.58k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
900 | 3.58k | "%s", reg_names[val & 7]); |
901 | 5.43k | else |
902 | 5.43k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
903 | 5.43k | "%d", val); |
904 | 9.01k | break; |
905 | | |
906 | 22.0k | case '+': |
907 | 22.0k | FETCH_ARG (3, val); |
908 | 22.0k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
909 | 22.0k | "%s", reg_names[val + 8]); |
910 | 22.0k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@+"); |
911 | 22.0k | break; |
912 | | |
913 | 94.7k | case '-': |
914 | 94.7k | FETCH_ARG (3, val); |
915 | 94.7k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
916 | 94.7k | "%s", reg_names[val + 8]); |
917 | 94.7k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@-"); |
918 | 94.7k | break; |
919 | | |
920 | 164 | case 'k': |
921 | 164 | if (place == 'k') |
922 | 0 | { |
923 | 0 | FETCH_ARG (3, val); |
924 | 0 | (*info->fprintf_styled_func) (info->stream, dis_style_text, "{"); |
925 | 0 | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
926 | 0 | "%s", reg_names[val]); |
927 | 0 | (*info->fprintf_styled_func) (info->stream, dis_style_text, "}"); |
928 | 0 | } |
929 | 164 | else if (place == 'C') |
930 | 164 | { |
931 | 164 | FETCH_ARG (7, val); |
932 | 164 | if (val > 63) /* This is a signed constant. */ |
933 | 124 | val -= 128; |
934 | 164 | (*info->fprintf_styled_func) (info->stream, dis_style_text, "{"); |
935 | 164 | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
936 | 164 | "#%d", val); |
937 | 164 | (*info->fprintf_styled_func) (info->stream, dis_style_text, "}"); |
938 | 164 | } |
939 | 0 | else |
940 | 0 | return PRINT_INSN_ARG_INVALID_OPERAND; |
941 | 164 | break; |
942 | | |
943 | 2.34M | case '#': |
944 | 2.35M | case '^': |
945 | 2.35M | p1 = buffer + (*d == '#' ? 2 : 4); |
946 | 2.35M | if (place == 's') |
947 | 0 | FETCH_ARG (4, val); |
948 | 2.35M | else if (place == 'C') |
949 | 86 | FETCH_ARG (7, val); |
950 | 2.35M | else if (place == '8') |
951 | 0 | FETCH_ARG (3, val); |
952 | 2.35M | else if (place == '3') |
953 | 498 | FETCH_ARG (8, val); |
954 | 2.35M | else if (place == 'b') |
955 | 2.01M | NEXTBYTE (p1, val); |
956 | 338k | else if (place == 'w' || place == 'W') |
957 | 234k | NEXTWORD (p1, val, PRINT_INSN_ARG_MEMORY_ERROR); |
958 | 104k | else if (place == 'l') |
959 | 104k | NEXTLONG (p1, val, PRINT_INSN_ARG_MEMORY_ERROR); |
960 | 0 | else |
961 | 0 | return PRINT_INSN_ARG_INVALID_OP_TABLE; |
962 | | |
963 | 2.35M | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
964 | 2.35M | "#%d", val); |
965 | 2.35M | break; |
966 | | |
967 | 443k | case 'B': |
968 | 443k | if (place == 'b') |
969 | 0 | NEXTBYTE (p, disp); |
970 | 443k | else if (place == 'B') |
971 | 402k | disp = COERCE_SIGNED_CHAR (buffer[1]); |
972 | 40.9k | else if (place == 'w' || place == 'W') |
973 | 32.9k | NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR); |
974 | 7.97k | else if (place == 'l' || place == 'L' || place == 'C') |
975 | 6.03k | NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR); |
976 | 1.94k | else if (place == 'g') |
977 | 0 | { |
978 | 0 | NEXTBYTE (buffer, disp); |
979 | 0 | if (disp == 0) |
980 | 0 | NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR); |
981 | 0 | else if (disp == -1) |
982 | 0 | NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR); |
983 | 0 | } |
984 | 1.94k | else if (place == 'c') |
985 | 1.94k | { |
986 | 1.94k | if (buffer[1] & 0x40) /* If bit six is one, long offset. */ |
987 | 1.10k | NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR); |
988 | 842 | else |
989 | 842 | NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR); |
990 | 1.94k | } |
991 | 0 | else |
992 | 0 | return PRINT_INSN_ARG_INVALID_OP_TABLE; |
993 | | |
994 | 443k | info->target = addr + disp; |
995 | | |
996 | 443k | (*info->print_address_func) (addr + disp, info); |
997 | 443k | break; |
998 | | |
999 | 36.4k | case 'd': |
1000 | 36.4k | { |
1001 | 36.4k | int val1; |
1002 | | |
1003 | 36.4k | NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR); |
1004 | 36.4k | FETCH_ARG (3, val1); |
1005 | 36.4k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1006 | 36.4k | "%s", reg_names[val1 + 8]); |
1007 | 36.4k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@("); |
1008 | 36.4k | (*info->fprintf_styled_func) (info->stream, dis_style_address_offset, |
1009 | 36.4k | "%d", val); |
1010 | 36.4k | (*info->fprintf_styled_func) (info->stream, dis_style_text, ")"); |
1011 | 36.4k | break; |
1012 | 36.4k | } |
1013 | | |
1014 | 2.01k | case 's': |
1015 | 2.01k | FETCH_ARG (3, val); |
1016 | 2.01k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1017 | 2.01k | "%s", fpcr_names[val]); |
1018 | 2.01k | break; |
1019 | | |
1020 | 3.42k | case 'e': |
1021 | 3.42k | FETCH_ARG (2, val); |
1022 | 3.42k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1023 | 3.42k | "%%acc%d", val); |
1024 | 3.42k | break; |
1025 | | |
1026 | 272 | case 'g': |
1027 | 272 | FETCH_ARG (1, val); |
1028 | 272 | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1029 | 272 | "%%accext%s", val == 0 ? "01" : "23"); |
1030 | 272 | break; |
1031 | | |
1032 | 47.2k | case 'i': |
1033 | 47.2k | FETCH_ARG (2, val); |
1034 | 47.2k | if (val == 1) |
1035 | 13.3k | (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic, |
1036 | 13.3k | "<<"); |
1037 | 33.8k | else if (val == 3) |
1038 | 17.0k | (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic, |
1039 | 17.0k | ">>"); |
1040 | 16.8k | else |
1041 | 16.8k | return PRINT_INSN_ARG_INVALID_OPERAND; |
1042 | 30.4k | break; |
1043 | | |
1044 | 30.4k | case 'I': |
1045 | | /* Get coprocessor ID... */ |
1046 | 21.8k | val = fetch_arg (buffer, 'd', 3, info); |
1047 | 21.8k | if (val < 0) |
1048 | 0 | return PRINT_INSN_ARG_MEMORY_ERROR; |
1049 | 21.8k | if (val != 1) /* Unusual coprocessor ID? */ |
1050 | 0 | (*info->fprintf_styled_func) (info->stream, dis_style_text, |
1051 | 0 | "(cpid=%d) ", val); |
1052 | 21.8k | break; |
1053 | | |
1054 | 38.6k | case '4': |
1055 | 1.08M | case '*': |
1056 | 1.32M | case '~': |
1057 | 2.26M | case '%': |
1058 | 3.26M | case ';': |
1059 | 3.28M | case '@': |
1060 | 3.32M | case '!': |
1061 | 6.15M | case '$': |
1062 | 6.16M | case '?': |
1063 | 6.16M | case '/': |
1064 | 6.17M | case '&': |
1065 | 6.17M | case '|': |
1066 | 6.19M | case '<': |
1067 | 6.20M | case '>': |
1068 | 6.28M | case 'm': |
1069 | 6.36M | case 'n': |
1070 | 6.43M | case 'o': |
1071 | 6.54M | case 'p': |
1072 | 6.56M | case 'q': |
1073 | 6.56M | case 'v': |
1074 | 6.56M | case 'b': |
1075 | 6.56M | case 'w': |
1076 | 6.57M | case 'y': |
1077 | 6.57M | case 'z': |
1078 | 6.57M | if (place == 'd') |
1079 | 798k | { |
1080 | 798k | val = fetch_arg (buffer, 'x', 6, info); |
1081 | 798k | if (val < 0) |
1082 | 0 | return PRINT_INSN_ARG_MEMORY_ERROR; |
1083 | 798k | val = ((val & 7) << 3) + ((val >> 3) & 7); |
1084 | 798k | } |
1085 | 5.77M | else |
1086 | 5.77M | { |
1087 | 5.77M | val = fetch_arg (buffer, 's', 6, info); |
1088 | 5.77M | if (val < 0) |
1089 | 0 | return PRINT_INSN_ARG_MEMORY_ERROR; |
1090 | 5.77M | } |
1091 | | |
1092 | | /* If the <ea> is invalid for *d, then reject this match. */ |
1093 | 6.57M | if (!m68k_valid_ea (*d, val)) |
1094 | 809k | return PRINT_INSN_ARG_INVALID_OPERAND; |
1095 | | |
1096 | | /* Get register number assuming address register. */ |
1097 | 5.76M | regno = (val & 7) + 8; |
1098 | 5.76M | regname = reg_names[regno]; |
1099 | 5.76M | switch (val >> 3) |
1100 | 5.76M | { |
1101 | 3.00M | case 0: |
1102 | 3.00M | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1103 | 3.00M | "%s", reg_names[val]); |
1104 | 3.00M | break; |
1105 | | |
1106 | 122k | case 1: |
1107 | 122k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1108 | 122k | "%s", regname); |
1109 | 122k | break; |
1110 | | |
1111 | 475k | case 2: |
1112 | 475k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1113 | 475k | "%s", regname); |
1114 | 475k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@"); |
1115 | 475k | break; |
1116 | | |
1117 | 581k | case 3: |
1118 | 581k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1119 | 581k | "%s", regname); |
1120 | 581k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@+"); |
1121 | 581k | break; |
1122 | | |
1123 | 601k | case 4: |
1124 | 601k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1125 | 601k | "%s", regname); |
1126 | 601k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@-"); |
1127 | 601k | break; |
1128 | | |
1129 | 402k | case 5: |
1130 | 402k | NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR); |
1131 | 402k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1132 | 402k | "%s", regname); |
1133 | 402k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@("); |
1134 | 402k | (*info->fprintf_styled_func) (info->stream, dis_style_address_offset, |
1135 | 402k | "%d", val); |
1136 | 402k | (*info->fprintf_styled_func) (info->stream, dis_style_text, ")"); |
1137 | 402k | break; |
1138 | | |
1139 | 388k | case 6: |
1140 | 388k | p = print_indexed (regno, p, addr, info); |
1141 | 388k | if (p == NULL) |
1142 | 294 | return PRINT_INSN_ARG_MEMORY_ERROR; |
1143 | 387k | break; |
1144 | | |
1145 | 387k | case 7: |
1146 | 189k | switch (val & 7) |
1147 | 189k | { |
1148 | 61.6k | case 0: |
1149 | 61.6k | NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR); |
1150 | 61.5k | (*info->print_address_func) (val, info); |
1151 | 61.5k | break; |
1152 | | |
1153 | 43.2k | case 1: |
1154 | 43.2k | NEXTULONG (p, uval); |
1155 | 43.2k | (*info->print_address_func) (uval, info); |
1156 | 43.2k | break; |
1157 | | |
1158 | 26.1k | case 2: |
1159 | 26.1k | NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR); |
1160 | 26.1k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1161 | 26.1k | "%%pc"); |
1162 | 26.1k | (*info->fprintf_styled_func) (info->stream, dis_style_text, "@("); |
1163 | 26.1k | (*info->print_address_func) (addr + val, info); |
1164 | 26.1k | (*info->fprintf_styled_func) (info->stream, dis_style_text, ")"); |
1165 | 26.1k | break; |
1166 | | |
1167 | 22.3k | case 3: |
1168 | 22.3k | p = print_indexed (-1, p, addr, info); |
1169 | 22.3k | if (p == NULL) |
1170 | 35 | return PRINT_INSN_ARG_MEMORY_ERROR; |
1171 | 22.3k | break; |
1172 | | |
1173 | 36.4k | case 4: |
1174 | 36.4k | flt_p = 1; /* Assume it's a float... */ |
1175 | 36.4k | switch (place) |
1176 | 36.4k | { |
1177 | 6.10k | case 'b': |
1178 | 6.10k | NEXTBYTE (p, val); |
1179 | 6.10k | flt_p = 0; |
1180 | 6.10k | break; |
1181 | | |
1182 | 22.1k | case 'w': |
1183 | 22.1k | NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR); |
1184 | 22.1k | flt_p = 0; |
1185 | 22.1k | break; |
1186 | | |
1187 | 5.46k | case 'l': |
1188 | 5.46k | NEXTLONG (p, val, PRINT_INSN_ARG_MEMORY_ERROR); |
1189 | 5.45k | flt_p = 0; |
1190 | 5.45k | break; |
1191 | | |
1192 | 565 | case 'f': |
1193 | 565 | NEXTSINGLE (flval, p); |
1194 | 564 | break; |
1195 | | |
1196 | 763 | case 'F': |
1197 | 763 | NEXTDOUBLE (flval, p); |
1198 | 762 | break; |
1199 | | |
1200 | 823 | case 'x': |
1201 | 823 | NEXTEXTEND (flval, p); |
1202 | 822 | break; |
1203 | | |
1204 | 822 | case 'p': |
1205 | 553 | NEXTPACKED (p, flval); |
1206 | 550 | break; |
1207 | | |
1208 | 550 | default: |
1209 | 0 | return PRINT_INSN_ARG_INVALID_OPERAND; |
1210 | 36.4k | } |
1211 | 36.4k | if (flt_p) /* Print a float? */ |
1212 | 2.69k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
1213 | 2.69k | "#0e%g", flval); |
1214 | 33.7k | else |
1215 | 33.7k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
1216 | 33.7k | "#%d", val); |
1217 | 36.4k | break; |
1218 | | |
1219 | 0 | default: |
1220 | 0 | return PRINT_INSN_ARG_INVALID_OPERAND; |
1221 | 189k | } |
1222 | 5.76M | } |
1223 | | |
1224 | | /* If place is '/', then this is the case of the mask bit for |
1225 | | mac/emac loads. Now that the arg has been printed, grab the |
1226 | | mask bit and if set, add a '&' to the arg. */ |
1227 | 5.76M | if (place == '/') |
1228 | 33.6k | { |
1229 | 33.6k | FETCH_ARG (1, val); |
1230 | 33.6k | if (val) |
1231 | 27.4k | info->fprintf_styled_func (info->stream, dis_style_text, "&"); |
1232 | 33.6k | } |
1233 | 5.76M | break; |
1234 | | |
1235 | 5.76M | case 'L': |
1236 | 19.8k | case 'l': |
1237 | 19.8k | if (place == 'w') |
1238 | 17.9k | { |
1239 | 17.9k | char doneany; |
1240 | 17.9k | p1 = buffer + 2; |
1241 | 17.9k | NEXTWORD (p1, val, PRINT_INSN_ARG_MEMORY_ERROR); |
1242 | | /* Move the pointer ahead if this point is farther ahead |
1243 | | than the last. */ |
1244 | 17.9k | p = p1 > p ? p1 : p; |
1245 | 17.9k | if (val == 0) |
1246 | 1.58k | { |
1247 | 1.58k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
1248 | 1.58k | "#0"); |
1249 | 1.58k | break; |
1250 | 1.58k | } |
1251 | 16.3k | if (*d == 'l') |
1252 | 2.87k | { |
1253 | 2.87k | int newval = 0; |
1254 | | |
1255 | 48.8k | for (regno = 0; regno < 16; ++regno) |
1256 | 46.0k | if (val & (0x8000 >> regno)) |
1257 | 11.3k | newval |= 1 << regno; |
1258 | 2.87k | val = newval; |
1259 | 2.87k | } |
1260 | 16.3k | val &= 0xffff; |
1261 | 16.3k | doneany = 0; |
1262 | 225k | for (regno = 0; regno < 16; ++regno) |
1263 | 208k | if (val & (1 << regno)) |
1264 | 51.4k | { |
1265 | 51.4k | int first_regno; |
1266 | | |
1267 | 51.4k | if (doneany) |
1268 | 35.0k | (*info->fprintf_styled_func) (info->stream, dis_style_text, |
1269 | 35.0k | "/"); |
1270 | 51.4k | doneany = 1; |
1271 | 51.4k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1272 | 51.4k | "%s", reg_names[regno]); |
1273 | 51.4k | first_regno = regno; |
1274 | 104k | while (val & (1 << (regno + 1))) |
1275 | 53.0k | ++regno; |
1276 | 51.4k | if (regno > first_regno) |
1277 | 23.6k | { |
1278 | 23.6k | (*info->fprintf_styled_func) (info->stream, |
1279 | 23.6k | dis_style_text, "-"); |
1280 | 23.6k | (*info->fprintf_styled_func) (info->stream, |
1281 | 23.6k | dis_style_register, "%s", |
1282 | 23.6k | reg_names[regno]); |
1283 | 23.6k | } |
1284 | 51.4k | } |
1285 | 16.3k | } |
1286 | 1.93k | else if (place == '3') |
1287 | 608 | { |
1288 | | /* `fmovem' insn. */ |
1289 | 608 | char doneany; |
1290 | | |
1291 | 608 | FETCH_ARG (8, val); |
1292 | 608 | if (val == 0) |
1293 | 132 | { |
1294 | 132 | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
1295 | 132 | "#0"); |
1296 | 132 | break; |
1297 | 132 | } |
1298 | 476 | if (*d == 'l') |
1299 | 370 | { |
1300 | 370 | int newval = 0; |
1301 | | |
1302 | 3.33k | for (regno = 0; regno < 8; ++regno) |
1303 | 2.96k | if (val & (0x80 >> regno)) |
1304 | 1.90k | newval |= 1 << regno; |
1305 | 370 | val = newval; |
1306 | 370 | } |
1307 | 476 | val &= 0xff; |
1308 | 476 | doneany = 0; |
1309 | 2.77k | for (regno = 0; regno < 8; ++regno) |
1310 | 2.29k | if (val & (1 << regno)) |
1311 | 800 | { |
1312 | 800 | int first_regno; |
1313 | 800 | if (doneany) |
1314 | 324 | (*info->fprintf_styled_func) (info->stream, dis_style_text, |
1315 | 324 | "/"); |
1316 | 800 | doneany = 1; |
1317 | 800 | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1318 | 800 | "%%fp%d", regno); |
1319 | 800 | first_regno = regno; |
1320 | 2.31k | while (val & (1 << (regno + 1))) |
1321 | 1.51k | ++regno; |
1322 | 800 | if (regno > first_regno) |
1323 | 336 | { |
1324 | 336 | (*info->fprintf_styled_func) (info->stream, |
1325 | 336 | dis_style_text, "-"); |
1326 | 336 | (*info->fprintf_styled_func) (info->stream, |
1327 | 336 | dis_style_register, |
1328 | 336 | "%%fp%d", regno); |
1329 | 336 | } |
1330 | 800 | } |
1331 | 476 | } |
1332 | 1.32k | else if (place == '8') |
1333 | 1.32k | { |
1334 | 1.32k | FETCH_ARG (3, val); |
1335 | | /* fmoveml for FP status registers. */ |
1336 | 1.32k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1337 | 1.32k | "%s", fpcr_names[val]); |
1338 | 1.32k | } |
1339 | 0 | else |
1340 | 0 | return PRINT_INSN_ARG_INVALID_OP_TABLE; |
1341 | 18.1k | break; |
1342 | | |
1343 | 18.1k | case 'X': |
1344 | 279 | place = '8'; |
1345 | | /* Fall through. */ |
1346 | 742 | case 'Y': |
1347 | 763 | case 'Z': |
1348 | 2.09k | case 'W': |
1349 | 2.18k | case '0': |
1350 | 2.99k | case '1': |
1351 | 4.49k | case '2': |
1352 | 4.72k | case '3': |
1353 | 4.72k | { |
1354 | 4.72k | char *name = 0; |
1355 | | |
1356 | 4.72k | FETCH_ARG (5, val); |
1357 | 4.72k | switch (val) |
1358 | 4.72k | { |
1359 | 101 | case 2: name = "%tt0"; break; |
1360 | 123 | case 3: name = "%tt1"; break; |
1361 | 136 | case 0x10: name = "%tc"; break; |
1362 | 30 | case 0x11: name = "%drp"; break; |
1363 | 46 | case 0x12: name = "%srp"; break; |
1364 | 34 | case 0x13: name = "%crp"; break; |
1365 | 34 | case 0x14: name = "%cal"; break; |
1366 | 1.03k | case 0x15: name = "%val"; break; |
1367 | 17 | case 0x16: name = "%scc"; break; |
1368 | 2.40k | case 0x17: name = "%ac"; break; |
1369 | 496 | case 0x18: name = "%psr"; break; |
1370 | 50 | case 0x19: name = "%pcsr"; break; |
1371 | 67 | case 0x1c: |
1372 | 93 | case 0x1d: |
1373 | 93 | { |
1374 | 93 | int break_reg = ((buffer[3] >> 2) & 7); |
1375 | | |
1376 | 93 | (*info->fprintf_styled_func) |
1377 | 93 | (info->stream, dis_style_register, |
1378 | 93 | val == 0x1c ? "%%bad%d" : "%%bac%d", break_reg); |
1379 | 93 | } |
1380 | 93 | break; |
1381 | 124 | default: |
1382 | 124 | (*info->fprintf_styled_func) (info->stream, dis_style_text, |
1383 | 124 | "<mmu register %d>", val); |
1384 | 4.72k | } |
1385 | 4.72k | if (name) |
1386 | 4.50k | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1387 | 4.50k | "%s", name); |
1388 | 4.72k | } |
1389 | 0 | break; |
1390 | | |
1391 | 188 | case 'f': |
1392 | 188 | { |
1393 | 188 | int fc; |
1394 | | |
1395 | 188 | FETCH_ARG (5, fc); |
1396 | 188 | if (fc == 1) |
1397 | 40 | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1398 | 40 | "%%dfc"); |
1399 | 148 | else if (fc == 0) |
1400 | 148 | (*info->fprintf_styled_func) (info->stream, dis_style_register, |
1401 | 148 | "%%sfc"); |
1402 | 0 | else |
1403 | | /* xgettext:c-format */ |
1404 | 0 | (*info->fprintf_styled_func) (info->stream, dis_style_text, |
1405 | 0 | _("<function code %d>"), fc); |
1406 | 188 | } |
1407 | 0 | break; |
1408 | | |
1409 | 57 | case 'V': |
1410 | 57 | (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%val"); |
1411 | 57 | break; |
1412 | | |
1413 | 2.44k | case 't': |
1414 | 2.44k | { |
1415 | 2.44k | int level; |
1416 | | |
1417 | 2.44k | FETCH_ARG (3, level); |
1418 | 2.44k | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
1419 | 2.44k | "%d", level); |
1420 | 2.44k | } |
1421 | 0 | break; |
1422 | | |
1423 | 75.4k | case 'u': |
1424 | 75.4k | { |
1425 | 75.4k | short is_upper = 0; |
1426 | 75.4k | int reg; |
1427 | | |
1428 | 75.4k | FETCH_ARG (5, reg); |
1429 | 75.4k | if (reg & 0x10) |
1430 | 20.5k | { |
1431 | 20.5k | is_upper = 1; |
1432 | 20.5k | reg &= 0xf; |
1433 | 20.5k | } |
1434 | 75.4k | (*info->fprintf_styled_func) (info->stream, dis_style_register, "%s%s", |
1435 | 75.4k | reg_half_names[reg], |
1436 | 75.4k | is_upper ? "u" : "l"); |
1437 | 75.4k | } |
1438 | 0 | break; |
1439 | | |
1440 | 0 | default: |
1441 | 0 | return PRINT_INSN_ARG_INVALID_OP_TABLE; |
1442 | 12.9M | } |
1443 | | |
1444 | 12.1M | return p - p0; |
1445 | 12.9M | } |
1446 | | |
1447 | | /* Return the insn type determined from the opcode information. */ |
1448 | | |
1449 | | static enum dis_insn_type |
1450 | | m68k_opcode_to_insn_type (const struct m68k_opcode *opc) |
1451 | 2.99M | { |
1452 | | /* All branches have an operand in 'B' format (the 'B' place only comes |
1453 | | with the 'B' format). */ |
1454 | 2.99M | if (strchr (opc->args, 'B') == NULL) |
1455 | 2.77M | return dis_nonbranch; |
1456 | | |
1457 | | /* Most branches are conditional branches, detect the ones that aren't |
1458 | | from the opcode name. */ |
1459 | 221k | if (strncmp (opc->name, "bra", 3) == 0) |
1460 | 8.31k | return dis_branch; |
1461 | | |
1462 | 213k | if (strncmp (opc->name, "bsr", 3) == 0) |
1463 | 16.4k | return dis_jsr; |
1464 | | |
1465 | 196k | return dis_condbranch; |
1466 | 213k | } |
1467 | | |
1468 | | /* Try to match the current instruction to best and if so, return the |
1469 | | number of bytes consumed from the instruction stream, else zero. |
1470 | | Return -1 on memory error. */ |
1471 | | |
1472 | | static int |
1473 | | match_insn_m68k (bfd_vma memaddr, |
1474 | | disassemble_info * info, |
1475 | | const struct m68k_opcode * best) |
1476 | 3.82M | { |
1477 | 3.82M | unsigned char *save_p; |
1478 | 3.82M | unsigned char *p; |
1479 | 3.82M | const char *d; |
1480 | 3.82M | const char *args = best->args; |
1481 | | |
1482 | 3.82M | struct private *priv = (struct private *) info->private_data; |
1483 | 3.82M | bfd_byte *buffer = priv->the_buffer; |
1484 | 3.82M | fprintf_styled_ftype save_printer = info->fprintf_styled_func; |
1485 | 3.82M | void (* save_print_address) (bfd_vma, struct disassemble_info *) |
1486 | 3.82M | = info->print_address_func; |
1487 | | |
1488 | 3.82M | if (*args == '.') |
1489 | 62.6k | args++; |
1490 | | |
1491 | | /* Point at first word of argument data, |
1492 | | and at descriptor for first argument. */ |
1493 | 3.82M | p = buffer + 2; |
1494 | | |
1495 | | /* Figure out how long the fixed-size portion of the instruction is. |
1496 | | The only place this is stored in the opcode table is |
1497 | | in the arguments--look for arguments which specify fields in the 2nd |
1498 | | or 3rd words of the instruction. */ |
1499 | 11.3M | for (d = args; *d; d += 2) |
1500 | 7.55M | { |
1501 | | /* I don't think it is necessary to be checking d[0] here; |
1502 | | I suspect all this could be moved to the case statement below. */ |
1503 | 7.55M | if (d[0] == '#') |
1504 | 1.26M | { |
1505 | 1.26M | if (d[1] == 'l' && p - buffer < 6) |
1506 | 58.0k | p = buffer + 6; |
1507 | 1.20M | else if (p - buffer < 4 && d[1] != 'C' && d[1] != '8') |
1508 | 1.20M | p = buffer + 4; |
1509 | 1.26M | } |
1510 | | |
1511 | 7.55M | if ((d[0] == 'L' || d[0] == 'l') && d[1] == 'w' && p - buffer < 4) |
1512 | 19.3k | p = buffer + 4; |
1513 | | |
1514 | 7.55M | switch (d[1]) |
1515 | 7.55M | { |
1516 | 77.9k | case '1': |
1517 | 82.0k | case '2': |
1518 | 152k | case '3': |
1519 | 156k | case '7': |
1520 | 166k | case '8': |
1521 | 166k | case '9': |
1522 | 177k | case 'i': |
1523 | 177k | if (p - buffer < 4) |
1524 | 95.1k | p = buffer + 4; |
1525 | 177k | break; |
1526 | 165 | case '4': |
1527 | 330 | case '5': |
1528 | 495 | case '6': |
1529 | 495 | if (p - buffer < 6) |
1530 | 165 | p = buffer + 6; |
1531 | 495 | break; |
1532 | 7.37M | default: |
1533 | 7.37M | break; |
1534 | 7.55M | } |
1535 | 7.55M | } |
1536 | | |
1537 | | /* pflusha is an exceptions. It takes no arguments but is two words |
1538 | | long. Recognize it by looking at the lower 16 bits of the mask. */ |
1539 | 3.82M | if (p - buffer < 4 && (best->match & 0xFFFF) != 0) |
1540 | 48.0k | p = buffer + 4; |
1541 | | |
1542 | | /* lpstop is another exception. It takes a one word argument but is |
1543 | | three words long. */ |
1544 | 3.82M | if (p - buffer < 6 |
1545 | 3.82M | && (best->match & 0xffff) == 0xffff |
1546 | 3.82M | && args[0] == '#' |
1547 | 3.82M | && args[1] == 'w') |
1548 | 13 | { |
1549 | | /* Copy the one word argument into the usual location for a one |
1550 | | word argument, to simplify printing it. We can get away with |
1551 | | this because we know exactly what the second word is, and we |
1552 | | aren't going to print anything based on it. */ |
1553 | 13 | p = buffer + 6; |
1554 | 13 | if (!FETCH_DATA (info, p)) |
1555 | 1 | return -1; |
1556 | 12 | buffer[2] = buffer[4]; |
1557 | 12 | buffer[3] = buffer[5]; |
1558 | 12 | } |
1559 | | |
1560 | 3.82M | if (!FETCH_DATA (info, p)) |
1561 | 501 | return -1; |
1562 | | |
1563 | 3.82M | save_p = p; |
1564 | 3.82M | info->print_address_func = dummy_print_address; |
1565 | 3.82M | info->fprintf_styled_func = dummy_printer; |
1566 | | |
1567 | | /* We scan the operands twice. The first time we don't print anything, |
1568 | | but look for errors. */ |
1569 | 10.1M | for (d = args; *d; d += 2) |
1570 | 7.12M | { |
1571 | 7.12M | int eaten = print_insn_arg (d, buffer, p, memaddr + (p - buffer), info); |
1572 | | |
1573 | 7.12M | if (eaten >= 0) |
1574 | 6.29M | p += eaten; |
1575 | 826k | else if (eaten == PRINT_INSN_ARG_INVALID_OPERAND |
1576 | 826k | || eaten == PRINT_INSN_ARG_MEMORY_ERROR) |
1577 | 826k | { |
1578 | 826k | info->fprintf_styled_func = save_printer; |
1579 | 826k | info->print_address_func = save_print_address; |
1580 | 826k | return eaten == PRINT_INSN_ARG_MEMORY_ERROR ? -1 : 0; |
1581 | 826k | } |
1582 | 0 | else |
1583 | 0 | { |
1584 | | /* We must restore the print functions before trying to print the |
1585 | | error message. */ |
1586 | 0 | info->fprintf_styled_func = save_printer; |
1587 | 0 | info->print_address_func = save_print_address; |
1588 | 0 | info->fprintf_styled_func (info->stream, dis_style_text, |
1589 | | /* xgettext:c-format */ |
1590 | 0 | _("<internal error in opcode table: %s %s>\n"), |
1591 | 0 | best->name, best->args); |
1592 | 0 | return 2; |
1593 | 0 | } |
1594 | 7.12M | } |
1595 | | |
1596 | 2.99M | p = save_p; |
1597 | 2.99M | info->fprintf_styled_func = save_printer; |
1598 | 2.99M | info->print_address_func = save_print_address; |
1599 | 2.99M | info->insn_type = m68k_opcode_to_insn_type (best); |
1600 | | |
1601 | 2.99M | d = args; |
1602 | | |
1603 | 2.99M | info->fprintf_styled_func (info->stream, dis_style_mnemonic, "%s", best->name); |
1604 | | |
1605 | 2.99M | if (*d) |
1606 | 2.99M | info->fprintf_styled_func (info->stream, dis_style_text, " "); |
1607 | | |
1608 | 8.82M | while (*d) |
1609 | 5.83M | { |
1610 | 5.83M | p += print_insn_arg (d, buffer, p, memaddr + (p - buffer), info); |
1611 | 5.83M | d += 2; |
1612 | | |
1613 | 5.83M | if (*d && *(d - 2) != 'I' && *d != 'k') |
1614 | 2.82M | info->fprintf_styled_func (info->stream, dis_style_text, ","); |
1615 | 5.83M | } |
1616 | | |
1617 | 2.99M | return p - buffer; |
1618 | 3.82M | } |
1619 | | |
1620 | | /* Try to interpret the instruction at address MEMADDR as one that |
1621 | | can execute on a processor with the features given by ARCH_MASK. |
1622 | | If successful, print the instruction to INFO->STREAM and return |
1623 | | its length in bytes. Return 0 otherwise. Return -1 on memory |
1624 | | error. */ |
1625 | | |
1626 | | static int |
1627 | | m68k_scan_mask (bfd_vma memaddr, disassemble_info *info, |
1628 | | unsigned int arch_mask) |
1629 | 4.63M | { |
1630 | 4.63M | int i; |
1631 | 4.63M | const char *d; |
1632 | 4.63M | static const struct m68k_opcode **opcodes[16]; |
1633 | 4.63M | static int numopcodes[16]; |
1634 | 4.63M | int val; |
1635 | 4.63M | int major_opcode; |
1636 | | |
1637 | 4.63M | struct private *priv = (struct private *) info->private_data; |
1638 | 4.63M | bfd_byte *buffer = priv->the_buffer; |
1639 | | |
1640 | 4.63M | if (!opcodes[0]) |
1641 | 2 | { |
1642 | | /* Speed up the matching by sorting the opcode |
1643 | | table on the upper four bits of the opcode. */ |
1644 | 2 | const struct m68k_opcode **opc_pointer[16]; |
1645 | | |
1646 | | /* First count how many opcodes are in each of the sixteen buckets. */ |
1647 | 3.81k | for (i = 0; i < m68k_numopcodes; i++) |
1648 | 3.81k | numopcodes[(m68k_opcodes[i].opcode >> 28) & 15]++; |
1649 | | |
1650 | | /* Then create a sorted table of pointers |
1651 | | that point into the unsorted table. */ |
1652 | 2 | opc_pointer[0] = xmalloc (sizeof (struct m68k_opcode *) |
1653 | 2 | * m68k_numopcodes); |
1654 | 2 | opcodes[0] = opc_pointer[0]; |
1655 | | |
1656 | 32 | for (i = 1; i < 16; i++) |
1657 | 30 | { |
1658 | 30 | opc_pointer[i] = opc_pointer[i - 1] + numopcodes[i - 1]; |
1659 | 30 | opcodes[i] = opc_pointer[i]; |
1660 | 30 | } |
1661 | | |
1662 | 3.81k | for (i = 0; i < m68k_numopcodes; i++) |
1663 | 3.81k | *opc_pointer[(m68k_opcodes[i].opcode >> 28) & 15]++ = &m68k_opcodes[i]; |
1664 | 2 | } |
1665 | | |
1666 | 4.63M | if (!FETCH_DATA (info, buffer + 2)) |
1667 | 1.28k | return -1; |
1668 | 4.62M | major_opcode = (buffer[0] >> 4) & 15; |
1669 | | |
1670 | 919M | for (i = 0; i < numopcodes[major_opcode]; i++) |
1671 | 918M | { |
1672 | 918M | const struct m68k_opcode *opc = opcodes[major_opcode][i]; |
1673 | 918M | unsigned long opcode = opc->opcode; |
1674 | 918M | unsigned long match = opc->match; |
1675 | 918M | const char *args = opc->args; |
1676 | | |
1677 | 918M | if (*args == '.') |
1678 | 9.41M | args++; |
1679 | | |
1680 | 918M | if (((0xff & buffer[0] & (match >> 24)) == (0xff & (opcode >> 24))) |
1681 | 918M | && ((0xff & buffer[1] & (match >> 16)) == (0xff & (opcode >> 16))) |
1682 | | /* Only fetch the next two bytes if we need to. */ |
1683 | 918M | && (((0xffff & match) == 0) |
1684 | 44.3M | || |
1685 | 44.3M | (FETCH_DATA (info, buffer + 4) |
1686 | 39.5M | && ((0xff & buffer[2] & (match >> 8)) == (0xff & (opcode >> 8))) |
1687 | 39.5M | && ((0xff & buffer[3] & match) == (0xff & opcode))) |
1688 | 44.3M | ) |
1689 | 918M | && (opc->arch & arch_mask) != 0) |
1690 | 3.91M | { |
1691 | | /* Don't use for printout the variants of divul and divsl |
1692 | | that have the same register number in two places. |
1693 | | The more general variants will match instead. */ |
1694 | 11.6M | for (d = args; *d; d += 2) |
1695 | 7.74M | if (d[1] == 'D') |
1696 | 1.01k | break; |
1697 | | |
1698 | | /* Don't use for printout the variants of most floating |
1699 | | point coprocessor instructions which use the same |
1700 | | register number in two places, as above. */ |
1701 | 3.91M | if (*d == '\0') |
1702 | 11.6M | for (d = args; *d; d += 2) |
1703 | 7.74M | if (d[1] == 't') |
1704 | 2.36k | break; |
1705 | | |
1706 | | /* Don't match fmovel with more than one register; |
1707 | | wait for fmoveml. */ |
1708 | 3.91M | if (*d == '\0') |
1709 | 3.90M | { |
1710 | 11.6M | for (d = args; *d; d += 2) |
1711 | 7.73M | { |
1712 | 7.73M | if (d[0] == 's' && d[1] == '8') |
1713 | 2.42k | { |
1714 | 2.42k | val = fetch_arg (buffer, d[1], 3, info); |
1715 | 2.42k | if (val < 0) |
1716 | 0 | return 0; |
1717 | 2.42k | if ((val & (val - 1)) != 0) |
1718 | 345 | break; |
1719 | 2.42k | } |
1720 | 7.73M | } |
1721 | 3.90M | } |
1722 | | |
1723 | | /* Don't match FPU insns with non-default coprocessor ID. */ |
1724 | 3.91M | if (*d == '\0') |
1725 | 3.90M | { |
1726 | 11.4M | for (d = args; *d; d += 2) |
1727 | 7.64M | { |
1728 | 7.64M | if (d[0] == 'I') |
1729 | 97.6k | { |
1730 | 97.6k | val = fetch_arg (buffer, 'd', 3, info); |
1731 | 97.6k | if (val != 1) |
1732 | 83.2k | break; |
1733 | 97.6k | } |
1734 | 7.64M | } |
1735 | 3.90M | } |
1736 | | |
1737 | 3.91M | if (*d == '\0') |
1738 | 3.82M | if ((val = match_insn_m68k (memaddr, info, opc))) |
1739 | 2.99M | return val; |
1740 | 3.91M | } |
1741 | 918M | } |
1742 | 1.63M | return 0; |
1743 | 4.62M | } |
1744 | | |
1745 | | /* Print the m68k instruction at address MEMADDR in debugged memory, |
1746 | | on INFO->STREAM. Returns length of the instruction, in bytes. */ |
1747 | | |
1748 | | int |
1749 | | print_insn_m68k (bfd_vma memaddr, disassemble_info *info) |
1750 | 3.82M | { |
1751 | 3.82M | unsigned int arch_mask; |
1752 | 3.82M | struct private priv; |
1753 | 3.82M | int val; |
1754 | | |
1755 | 3.82M | bfd_byte *buffer = priv.the_buffer; |
1756 | | |
1757 | 3.82M | info->insn_info_valid = 1; |
1758 | 3.82M | info->private_data = & priv; |
1759 | | /* Tell objdump to use two bytes per chunk |
1760 | | and six bytes per line for displaying raw data. */ |
1761 | 3.82M | info->bytes_per_chunk = 2; |
1762 | 3.82M | info->bytes_per_line = 6; |
1763 | 3.82M | info->display_endian = BFD_ENDIAN_BIG; |
1764 | 3.82M | priv.max_fetched = priv.the_buffer; |
1765 | 3.82M | priv.insn_start = memaddr; |
1766 | | |
1767 | 3.82M | arch_mask = bfd_m68k_mach_to_features (info->mach); |
1768 | 3.82M | if (!arch_mask) |
1769 | 3.54M | { |
1770 | | /* First try printing an m680x0 instruction. Try printing a Coldfire |
1771 | | one if that fails. */ |
1772 | 3.54M | val = m68k_scan_mask (memaddr, info, m68k_mask); |
1773 | 3.54M | if (val <= 0) |
1774 | 804k | val = m68k_scan_mask (memaddr, info, mcf_mask); |
1775 | 3.54M | } |
1776 | 282k | else |
1777 | 282k | { |
1778 | 282k | val = m68k_scan_mask (memaddr, info, arch_mask); |
1779 | 282k | } |
1780 | | |
1781 | 3.82M | if (val == 0) |
1782 | 828k | { |
1783 | | /* Handle undefined instructions. */ |
1784 | 828k | info->fprintf_styled_func (info->stream, dis_style_assembler_directive, |
1785 | 828k | ".short"); |
1786 | 828k | info->fprintf_styled_func (info->stream, dis_style_text, " "); |
1787 | 828k | info->fprintf_styled_func (info->stream, dis_style_immediate, |
1788 | 828k | "0x%04x", (buffer[0] << 8) + buffer[1]); |
1789 | | |
1790 | 828k | info->insn_type = dis_noninsn; |
1791 | 828k | } |
1792 | | |
1793 | 3.82M | return val ? val : 2; |
1794 | 3.82M | } |