m68k-dis.c 39 KB

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