m68k-dis.c 41 KB

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