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