mips-dis.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821
  1. /* Print mips instructions for GDB, the GNU debugger, or for objdump.
  2. Copyright (C) 1989-2022 Free Software Foundation, Inc.
  3. Contributed by Nobuyuki Hikichi(hikichi@sra.co.jp).
  4. This file is part of the GNU opcodes library.
  5. This library is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. It is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  12. License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "disassemble.h"
  19. #include "libiberty.h"
  20. #include "opcode/mips.h"
  21. #include "opintl.h"
  22. #include "elf-bfd.h"
  23. #include "elf/mips.h"
  24. #include "elfxx-mips.h"
  25. /* FIXME: These are needed to figure out if the code is mips16 or
  26. not. The low bit of the address is often a good indicator. No
  27. symbol table is available when this code runs out in an embedded
  28. system as when it is used for disassembler support in a monitor. */
  29. #if !defined(EMBEDDED_ENV)
  30. #define SYMTAB_AVAILABLE 1
  31. #endif
  32. /* Mips instructions are at maximum this many bytes long. */
  33. #define INSNLEN 4
  34. /* FIXME: These should be shared with gdb somehow. */
  35. struct mips_cp0sel_name
  36. {
  37. unsigned int cp0reg;
  38. unsigned int sel;
  39. const char * const name;
  40. };
  41. static const char * const mips_gpr_names_numeric[32] =
  42. {
  43. "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
  44. "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
  45. "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
  46. "$24", "$25", "$26", "$27", "$28", "$29", "$30", "$31"
  47. };
  48. static const char * const mips_gpr_names_oldabi[32] =
  49. {
  50. "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
  51. "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
  52. "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
  53. "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
  54. };
  55. static const char * const mips_gpr_names_newabi[32] =
  56. {
  57. "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
  58. "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
  59. "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
  60. "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
  61. };
  62. static const char * const mips_fpr_names_numeric[32] =
  63. {
  64. "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
  65. "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
  66. "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
  67. "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31"
  68. };
  69. static const char * const mips_fpr_names_32[32] =
  70. {
  71. "fv0", "fv0f", "fv1", "fv1f", "ft0", "ft0f", "ft1", "ft1f",
  72. "ft2", "ft2f", "ft3", "ft3f", "fa0", "fa0f", "fa1", "fa1f",
  73. "ft4", "ft4f", "ft5", "ft5f", "fs0", "fs0f", "fs1", "fs1f",
  74. "fs2", "fs2f", "fs3", "fs3f", "fs4", "fs4f", "fs5", "fs5f"
  75. };
  76. static const char * const mips_fpr_names_n32[32] =
  77. {
  78. "fv0", "ft14", "fv1", "ft15", "ft0", "ft1", "ft2", "ft3",
  79. "ft4", "ft5", "ft6", "ft7", "fa0", "fa1", "fa2", "fa3",
  80. "fa4", "fa5", "fa6", "fa7", "fs0", "ft8", "fs1", "ft9",
  81. "fs2", "ft10", "fs3", "ft11", "fs4", "ft12", "fs5", "ft13"
  82. };
  83. static const char * const mips_fpr_names_64[32] =
  84. {
  85. "fv0", "ft12", "fv1", "ft13", "ft0", "ft1", "ft2", "ft3",
  86. "ft4", "ft5", "ft6", "ft7", "fa0", "fa1", "fa2", "fa3",
  87. "fa4", "fa5", "fa6", "fa7", "ft8", "ft9", "ft10", "ft11",
  88. "fs0", "fs1", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7"
  89. };
  90. static const char * const mips_cp0_names_numeric[32] =
  91. {
  92. "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
  93. "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
  94. "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
  95. "$24", "$25", "$26", "$27", "$28", "$29", "$30", "$31"
  96. };
  97. static const char * const mips_cp1_names_numeric[32] =
  98. {
  99. "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
  100. "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
  101. "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
  102. "$24", "$25", "$26", "$27", "$28", "$29", "$30", "$31"
  103. };
  104. static const char * const mips_cp0_names_r3900[32] =
  105. {
  106. "$0", "$1", "$2", "c0_config",
  107. "$4", "$5", "$6", "c0_cache",
  108. "c0_badvaddr", "$9", "$10", "$11",
  109. "c0_sr", "c0_cause", "c0_epc", "c0_prid",
  110. "c0_debug", "c0_depc", "$18", "$19",
  111. "$20", "$21", "$22", "$23",
  112. "$24", "$25", "$26", "$27",
  113. "$28", "$29", "$30", "$31",
  114. };
  115. static const char * const mips_cp0_names_r3000[32] =
  116. {
  117. "c0_index", "c0_random", "c0_entrylo", "$3",
  118. "c0_context", "$5", "$6", "$7",
  119. "c0_badvaddr", "$9", "c0_entryhi", "$11",
  120. "c0_sr", "c0_cause", "c0_epc", "c0_prid",
  121. "$16", "$17", "$18", "$19",
  122. "$20", "$21", "$22", "$23",
  123. "$24", "$25", "$26", "$27",
  124. "$28", "$29", "$30", "$31",
  125. };
  126. static const char * const mips_cp0_names_r4000[32] =
  127. {
  128. "c0_index", "c0_random", "c0_entrylo0", "c0_entrylo1",
  129. "c0_context", "c0_pagemask", "c0_wired", "$7",
  130. "c0_badvaddr", "c0_count", "c0_entryhi", "c0_compare",
  131. "c0_sr", "c0_cause", "c0_epc", "c0_prid",
  132. "c0_config", "c0_lladdr", "c0_watchlo", "c0_watchhi",
  133. "c0_xcontext", "$21", "$22", "$23",
  134. "$24", "$25", "c0_ecc", "c0_cacheerr",
  135. "c0_taglo", "c0_taghi", "c0_errorepc", "$31",
  136. };
  137. static const char * const mips_cp0_names_r5900[32] =
  138. {
  139. "c0_index", "c0_random", "c0_entrylo0", "c0_entrylo1",
  140. "c0_context", "c0_pagemask", "c0_wired", "$7",
  141. "c0_badvaddr", "c0_count", "c0_entryhi", "c0_compare",
  142. "c0_sr", "c0_cause", "c0_epc", "c0_prid",
  143. "c0_config", "$17", "$18", "$19",
  144. "$20", "$21", "$22", "c0_badpaddr",
  145. "c0_depc", "c0_perfcnt", "$26", "$27",
  146. "c0_taglo", "c0_taghi", "c0_errorepc", "$31"
  147. };
  148. static const char * const mips_cp0_names_mips3264[32] =
  149. {
  150. "c0_index", "c0_random", "c0_entrylo0", "c0_entrylo1",
  151. "c0_context", "c0_pagemask", "c0_wired", "$7",
  152. "c0_badvaddr", "c0_count", "c0_entryhi", "c0_compare",
  153. "c0_status", "c0_cause", "c0_epc", "c0_prid",
  154. "c0_config", "c0_lladdr", "c0_watchlo", "c0_watchhi",
  155. "c0_xcontext", "$21", "$22", "c0_debug",
  156. "c0_depc", "c0_perfcnt", "c0_errctl", "c0_cacheerr",
  157. "c0_taglo", "c0_taghi", "c0_errorepc", "c0_desave",
  158. };
  159. static const char * const mips_cp1_names_mips[32] =
  160. {
  161. "c1_fir", "$1", "$2", "$3",
  162. "$4", "$5", "$6", "$7",
  163. "$8", "$9", "$10", "$11",
  164. "$12", "$13", "$14", "$15",
  165. "$16", "$17", "$18", "$19",
  166. "$20", "$21", "$22", "$23",
  167. "$24", "$25", "$26", "$27",
  168. "$28", "$29", "$30", "c1_fcsr"
  169. };
  170. static const char * const mips_cp1_names_mips3264[32] =
  171. {
  172. "c1_fir", "c1_ufr", "$2", "$3",
  173. "c1_unfr", "$5", "$6", "$7",
  174. "$8", "$9", "$10", "$11",
  175. "$12", "$13", "$14", "$15",
  176. "$16", "$17", "$18", "$19",
  177. "$20", "$21", "$22", "$23",
  178. "$24", "c1_fccr", "c1_fexr", "$27",
  179. "c1_fenr", "$29", "$30", "c1_fcsr"
  180. };
  181. static const struct mips_cp0sel_name mips_cp0sel_names_mips3264[] =
  182. {
  183. { 16, 1, "c0_config1" },
  184. { 16, 2, "c0_config2" },
  185. { 16, 3, "c0_config3" },
  186. { 18, 1, "c0_watchlo,1" },
  187. { 18, 2, "c0_watchlo,2" },
  188. { 18, 3, "c0_watchlo,3" },
  189. { 18, 4, "c0_watchlo,4" },
  190. { 18, 5, "c0_watchlo,5" },
  191. { 18, 6, "c0_watchlo,6" },
  192. { 18, 7, "c0_watchlo,7" },
  193. { 19, 1, "c0_watchhi,1" },
  194. { 19, 2, "c0_watchhi,2" },
  195. { 19, 3, "c0_watchhi,3" },
  196. { 19, 4, "c0_watchhi,4" },
  197. { 19, 5, "c0_watchhi,5" },
  198. { 19, 6, "c0_watchhi,6" },
  199. { 19, 7, "c0_watchhi,7" },
  200. { 25, 1, "c0_perfcnt,1" },
  201. { 25, 2, "c0_perfcnt,2" },
  202. { 25, 3, "c0_perfcnt,3" },
  203. { 25, 4, "c0_perfcnt,4" },
  204. { 25, 5, "c0_perfcnt,5" },
  205. { 25, 6, "c0_perfcnt,6" },
  206. { 25, 7, "c0_perfcnt,7" },
  207. { 27, 1, "c0_cacheerr,1" },
  208. { 27, 2, "c0_cacheerr,2" },
  209. { 27, 3, "c0_cacheerr,3" },
  210. { 28, 1, "c0_datalo" },
  211. { 29, 1, "c0_datahi" }
  212. };
  213. static const char * const mips_cp0_names_mips3264r2[32] =
  214. {
  215. "c0_index", "c0_random", "c0_entrylo0", "c0_entrylo1",
  216. "c0_context", "c0_pagemask", "c0_wired", "c0_hwrena",
  217. "c0_badvaddr", "c0_count", "c0_entryhi", "c0_compare",
  218. "c0_status", "c0_cause", "c0_epc", "c0_prid",
  219. "c0_config", "c0_lladdr", "c0_watchlo", "c0_watchhi",
  220. "c0_xcontext", "$21", "$22", "c0_debug",
  221. "c0_depc", "c0_perfcnt", "c0_errctl", "c0_cacheerr",
  222. "c0_taglo", "c0_taghi", "c0_errorepc", "c0_desave",
  223. };
  224. static const struct mips_cp0sel_name mips_cp0sel_names_mips3264r2[] =
  225. {
  226. { 4, 1, "c0_contextconfig" },
  227. { 0, 1, "c0_mvpcontrol" },
  228. { 0, 2, "c0_mvpconf0" },
  229. { 0, 3, "c0_mvpconf1" },
  230. { 1, 1, "c0_vpecontrol" },
  231. { 1, 2, "c0_vpeconf0" },
  232. { 1, 3, "c0_vpeconf1" },
  233. { 1, 4, "c0_yqmask" },
  234. { 1, 5, "c0_vpeschedule" },
  235. { 1, 6, "c0_vpeschefback" },
  236. { 2, 1, "c0_tcstatus" },
  237. { 2, 2, "c0_tcbind" },
  238. { 2, 3, "c0_tcrestart" },
  239. { 2, 4, "c0_tchalt" },
  240. { 2, 5, "c0_tccontext" },
  241. { 2, 6, "c0_tcschedule" },
  242. { 2, 7, "c0_tcschefback" },
  243. { 5, 1, "c0_pagegrain" },
  244. { 6, 1, "c0_srsconf0" },
  245. { 6, 2, "c0_srsconf1" },
  246. { 6, 3, "c0_srsconf2" },
  247. { 6, 4, "c0_srsconf3" },
  248. { 6, 5, "c0_srsconf4" },
  249. { 12, 1, "c0_intctl" },
  250. { 12, 2, "c0_srsctl" },
  251. { 12, 3, "c0_srsmap" },
  252. { 15, 1, "c0_ebase" },
  253. { 16, 1, "c0_config1" },
  254. { 16, 2, "c0_config2" },
  255. { 16, 3, "c0_config3" },
  256. { 18, 1, "c0_watchlo,1" },
  257. { 18, 2, "c0_watchlo,2" },
  258. { 18, 3, "c0_watchlo,3" },
  259. { 18, 4, "c0_watchlo,4" },
  260. { 18, 5, "c0_watchlo,5" },
  261. { 18, 6, "c0_watchlo,6" },
  262. { 18, 7, "c0_watchlo,7" },
  263. { 19, 1, "c0_watchhi,1" },
  264. { 19, 2, "c0_watchhi,2" },
  265. { 19, 3, "c0_watchhi,3" },
  266. { 19, 4, "c0_watchhi,4" },
  267. { 19, 5, "c0_watchhi,5" },
  268. { 19, 6, "c0_watchhi,6" },
  269. { 19, 7, "c0_watchhi,7" },
  270. { 23, 1, "c0_tracecontrol" },
  271. { 23, 2, "c0_tracecontrol2" },
  272. { 23, 3, "c0_usertracedata" },
  273. { 23, 4, "c0_tracebpc" },
  274. { 25, 1, "c0_perfcnt,1" },
  275. { 25, 2, "c0_perfcnt,2" },
  276. { 25, 3, "c0_perfcnt,3" },
  277. { 25, 4, "c0_perfcnt,4" },
  278. { 25, 5, "c0_perfcnt,5" },
  279. { 25, 6, "c0_perfcnt,6" },
  280. { 25, 7, "c0_perfcnt,7" },
  281. { 27, 1, "c0_cacheerr,1" },
  282. { 27, 2, "c0_cacheerr,2" },
  283. { 27, 3, "c0_cacheerr,3" },
  284. { 28, 1, "c0_datalo" },
  285. { 28, 2, "c0_taglo1" },
  286. { 28, 3, "c0_datalo1" },
  287. { 28, 4, "c0_taglo2" },
  288. { 28, 5, "c0_datalo2" },
  289. { 28, 6, "c0_taglo3" },
  290. { 28, 7, "c0_datalo3" },
  291. { 29, 1, "c0_datahi" },
  292. { 29, 2, "c0_taghi1" },
  293. { 29, 3, "c0_datahi1" },
  294. { 29, 4, "c0_taghi2" },
  295. { 29, 5, "c0_datahi2" },
  296. { 29, 6, "c0_taghi3" },
  297. { 29, 7, "c0_datahi3" },
  298. };
  299. /* SB-1: MIPS64 (mips_cp0_names_mips3264) with minor mods. */
  300. static const char * const mips_cp0_names_sb1[32] =
  301. {
  302. "c0_index", "c0_random", "c0_entrylo0", "c0_entrylo1",
  303. "c0_context", "c0_pagemask", "c0_wired", "$7",
  304. "c0_badvaddr", "c0_count", "c0_entryhi", "c0_compare",
  305. "c0_status", "c0_cause", "c0_epc", "c0_prid",
  306. "c0_config", "c0_lladdr", "c0_watchlo", "c0_watchhi",
  307. "c0_xcontext", "$21", "$22", "c0_debug",
  308. "c0_depc", "c0_perfcnt", "c0_errctl", "c0_cacheerr_i",
  309. "c0_taglo_i", "c0_taghi_i", "c0_errorepc", "c0_desave",
  310. };
  311. static const struct mips_cp0sel_name mips_cp0sel_names_sb1[] =
  312. {
  313. { 16, 1, "c0_config1" },
  314. { 18, 1, "c0_watchlo,1" },
  315. { 19, 1, "c0_watchhi,1" },
  316. { 22, 0, "c0_perftrace" },
  317. { 23, 3, "c0_edebug" },
  318. { 25, 1, "c0_perfcnt,1" },
  319. { 25, 2, "c0_perfcnt,2" },
  320. { 25, 3, "c0_perfcnt,3" },
  321. { 25, 4, "c0_perfcnt,4" },
  322. { 25, 5, "c0_perfcnt,5" },
  323. { 25, 6, "c0_perfcnt,6" },
  324. { 25, 7, "c0_perfcnt,7" },
  325. { 26, 1, "c0_buserr_pa" },
  326. { 27, 1, "c0_cacheerr_d" },
  327. { 27, 3, "c0_cacheerr_d_pa" },
  328. { 28, 1, "c0_datalo_i" },
  329. { 28, 2, "c0_taglo_d" },
  330. { 28, 3, "c0_datalo_d" },
  331. { 29, 1, "c0_datahi_i" },
  332. { 29, 2, "c0_taghi_d" },
  333. { 29, 3, "c0_datahi_d" },
  334. };
  335. /* Xlr cop0 register names. */
  336. static const char * const mips_cp0_names_xlr[32] = {
  337. "c0_index", "c0_random", "c0_entrylo0", "c0_entrylo1",
  338. "c0_context", "c0_pagemask", "c0_wired", "$7",
  339. "c0_badvaddr", "c0_count", "c0_entryhi", "c0_compare",
  340. "c0_status", "c0_cause", "c0_epc", "c0_prid",
  341. "c0_config", "c0_lladdr", "c0_watchlo", "c0_watchhi",
  342. "c0_xcontext", "$21", "$22", "c0_debug",
  343. "c0_depc", "c0_perfcnt", "c0_errctl", "c0_cacheerr_i",
  344. "c0_taglo_i", "c0_taghi_i", "c0_errorepc", "c0_desave",
  345. };
  346. /* XLR's CP0 Select Registers. */
  347. static const struct mips_cp0sel_name mips_cp0sel_names_xlr[] = {
  348. { 9, 6, "c0_extintreq" },
  349. { 9, 7, "c0_extintmask" },
  350. { 15, 1, "c0_ebase" },
  351. { 16, 1, "c0_config1" },
  352. { 16, 2, "c0_config2" },
  353. { 16, 3, "c0_config3" },
  354. { 16, 7, "c0_procid2" },
  355. { 18, 1, "c0_watchlo,1" },
  356. { 18, 2, "c0_watchlo,2" },
  357. { 18, 3, "c0_watchlo,3" },
  358. { 18, 4, "c0_watchlo,4" },
  359. { 18, 5, "c0_watchlo,5" },
  360. { 18, 6, "c0_watchlo,6" },
  361. { 18, 7, "c0_watchlo,7" },
  362. { 19, 1, "c0_watchhi,1" },
  363. { 19, 2, "c0_watchhi,2" },
  364. { 19, 3, "c0_watchhi,3" },
  365. { 19, 4, "c0_watchhi,4" },
  366. { 19, 5, "c0_watchhi,5" },
  367. { 19, 6, "c0_watchhi,6" },
  368. { 19, 7, "c0_watchhi,7" },
  369. { 25, 1, "c0_perfcnt,1" },
  370. { 25, 2, "c0_perfcnt,2" },
  371. { 25, 3, "c0_perfcnt,3" },
  372. { 25, 4, "c0_perfcnt,4" },
  373. { 25, 5, "c0_perfcnt,5" },
  374. { 25, 6, "c0_perfcnt,6" },
  375. { 25, 7, "c0_perfcnt,7" },
  376. { 27, 1, "c0_cacheerr,1" },
  377. { 27, 2, "c0_cacheerr,2" },
  378. { 27, 3, "c0_cacheerr,3" },
  379. { 28, 1, "c0_datalo" },
  380. { 29, 1, "c0_datahi" }
  381. };
  382. static const char * const mips_hwr_names_numeric[32] =
  383. {
  384. "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
  385. "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
  386. "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
  387. "$24", "$25", "$26", "$27", "$28", "$29", "$30", "$31"
  388. };
  389. static const char * const mips_hwr_names_mips3264r2[32] =
  390. {
  391. "hwr_cpunum", "hwr_synci_step", "hwr_cc", "hwr_ccres",
  392. "$4", "$5", "$6", "$7",
  393. "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
  394. "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
  395. "$24", "$25", "$26", "$27", "$28", "$29", "$30", "$31"
  396. };
  397. static const char * const msa_control_names[32] =
  398. {
  399. "msa_ir", "msa_csr", "msa_access", "msa_save",
  400. "msa_modify", "msa_request", "msa_map", "msa_unmap",
  401. "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
  402. "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
  403. "$24", "$25", "$26", "$27", "$28", "$29", "$30", "$31"
  404. };
  405. struct mips_abi_choice
  406. {
  407. const char * name;
  408. const char * const *gpr_names;
  409. const char * const *fpr_names;
  410. };
  411. struct mips_abi_choice mips_abi_choices[] =
  412. {
  413. { "numeric", mips_gpr_names_numeric, mips_fpr_names_numeric },
  414. { "32", mips_gpr_names_oldabi, mips_fpr_names_32 },
  415. { "n32", mips_gpr_names_newabi, mips_fpr_names_n32 },
  416. { "64", mips_gpr_names_newabi, mips_fpr_names_64 },
  417. };
  418. struct mips_arch_choice
  419. {
  420. const char *name;
  421. int bfd_mach_valid;
  422. unsigned long bfd_mach;
  423. int processor;
  424. int isa;
  425. int ase;
  426. const char * const *cp0_names;
  427. const struct mips_cp0sel_name *cp0sel_names;
  428. unsigned int cp0sel_names_len;
  429. const char * const *cp1_names;
  430. const char * const *hwr_names;
  431. };
  432. const struct mips_arch_choice mips_arch_choices[] =
  433. {
  434. { "numeric", 0, 0, 0, 0, 0,
  435. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_numeric,
  436. mips_hwr_names_numeric },
  437. { "r3000", 1, bfd_mach_mips3000, CPU_R3000, ISA_MIPS1, 0,
  438. mips_cp0_names_r3000, NULL, 0, mips_cp1_names_mips,
  439. mips_hwr_names_numeric },
  440. { "r3900", 1, bfd_mach_mips3900, CPU_R3900, ISA_MIPS1, 0,
  441. mips_cp0_names_r3900, NULL, 0, mips_cp1_names_numeric,
  442. mips_hwr_names_numeric },
  443. { "r4000", 1, bfd_mach_mips4000, CPU_R4000, ISA_MIPS3, 0,
  444. mips_cp0_names_r4000, NULL, 0, mips_cp1_names_mips,
  445. mips_hwr_names_numeric },
  446. { "r4010", 1, bfd_mach_mips4010, CPU_R4010, ISA_MIPS2, 0,
  447. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  448. mips_hwr_names_numeric },
  449. { "vr4100", 1, bfd_mach_mips4100, CPU_VR4100, ISA_MIPS3, 0,
  450. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  451. mips_hwr_names_numeric },
  452. { "vr4111", 1, bfd_mach_mips4111, CPU_R4111, ISA_MIPS3, 0,
  453. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  454. mips_hwr_names_numeric },
  455. { "vr4120", 1, bfd_mach_mips4120, CPU_VR4120, ISA_MIPS3, 0,
  456. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  457. mips_hwr_names_numeric },
  458. { "r4300", 1, bfd_mach_mips4300, CPU_R4300, ISA_MIPS3, 0,
  459. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  460. mips_hwr_names_numeric },
  461. { "r4400", 1, bfd_mach_mips4400, CPU_R4400, ISA_MIPS3, 0,
  462. mips_cp0_names_r4000, NULL, 0, mips_cp1_names_mips,
  463. mips_hwr_names_numeric },
  464. { "r4600", 1, bfd_mach_mips4600, CPU_R4600, ISA_MIPS3, 0,
  465. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  466. mips_hwr_names_numeric },
  467. { "r4650", 1, bfd_mach_mips4650, CPU_R4650, ISA_MIPS3, 0,
  468. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  469. mips_hwr_names_numeric },
  470. { "r5000", 1, bfd_mach_mips5000, CPU_R5000, ISA_MIPS4, 0,
  471. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  472. mips_hwr_names_numeric },
  473. { "vr5400", 1, bfd_mach_mips5400, CPU_VR5400, ISA_MIPS4, 0,
  474. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  475. mips_hwr_names_numeric },
  476. { "vr5500", 1, bfd_mach_mips5500, CPU_VR5500, ISA_MIPS4, 0,
  477. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  478. mips_hwr_names_numeric },
  479. { "r5900", 1, bfd_mach_mips5900, CPU_R5900, ISA_MIPS3, 0,
  480. mips_cp0_names_r5900, NULL, 0, mips_cp1_names_mips,
  481. mips_hwr_names_numeric },
  482. { "r6000", 1, bfd_mach_mips6000, CPU_R6000, ISA_MIPS2, 0,
  483. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  484. mips_hwr_names_numeric },
  485. { "rm7000", 1, bfd_mach_mips7000, CPU_RM7000, ISA_MIPS4, 0,
  486. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  487. mips_hwr_names_numeric },
  488. { "rm9000", 1, bfd_mach_mips7000, CPU_RM7000, ISA_MIPS4, 0,
  489. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  490. mips_hwr_names_numeric },
  491. { "r8000", 1, bfd_mach_mips8000, CPU_R8000, ISA_MIPS4, 0,
  492. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  493. mips_hwr_names_numeric },
  494. { "r10000", 1, bfd_mach_mips10000, CPU_R10000, ISA_MIPS4, 0,
  495. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  496. mips_hwr_names_numeric },
  497. { "r12000", 1, bfd_mach_mips12000, CPU_R12000, ISA_MIPS4, 0,
  498. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  499. mips_hwr_names_numeric },
  500. { "r14000", 1, bfd_mach_mips14000, CPU_R14000, ISA_MIPS4, 0,
  501. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  502. mips_hwr_names_numeric },
  503. { "r16000", 1, bfd_mach_mips16000, CPU_R16000, ISA_MIPS4, 0,
  504. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  505. mips_hwr_names_numeric },
  506. { "mips5", 1, bfd_mach_mips5, CPU_MIPS5, ISA_MIPS5, 0,
  507. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips,
  508. mips_hwr_names_numeric },
  509. /* For stock MIPS32, disassemble all applicable MIPS-specified ASEs.
  510. Note that MIPS-3D and MDMX are not applicable to MIPS32. (See
  511. _MIPS32 Architecture For Programmers Volume I: Introduction to the
  512. MIPS32 Architecture_ (MIPS Document Number MD00082, Revision 0.95),
  513. page 1. */
  514. { "mips32", 1, bfd_mach_mipsisa32, CPU_MIPS32,
  515. ISA_MIPS32, ASE_SMARTMIPS,
  516. mips_cp0_names_mips3264,
  517. mips_cp0sel_names_mips3264, ARRAY_SIZE (mips_cp0sel_names_mips3264),
  518. mips_cp1_names_mips3264, mips_hwr_names_numeric },
  519. { "mips32r2", 1, bfd_mach_mipsisa32r2, CPU_MIPS32R2,
  520. ISA_MIPS32R2,
  521. (ASE_SMARTMIPS | ASE_DSP | ASE_DSPR2 | ASE_EVA | ASE_MIPS3D
  522. | ASE_MT | ASE_MCU | ASE_VIRT | ASE_MSA | ASE_XPA),
  523. mips_cp0_names_mips3264r2,
  524. mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
  525. mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
  526. { "mips32r3", 1, bfd_mach_mipsisa32r3, CPU_MIPS32R3,
  527. ISA_MIPS32R3,
  528. (ASE_SMARTMIPS | ASE_DSP | ASE_DSPR2 | ASE_EVA | ASE_MIPS3D
  529. | ASE_MT | ASE_MCU | ASE_VIRT | ASE_MSA | ASE_XPA),
  530. mips_cp0_names_mips3264r2,
  531. mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
  532. mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
  533. { "mips32r5", 1, bfd_mach_mipsisa32r5, CPU_MIPS32R5,
  534. ISA_MIPS32R5,
  535. (ASE_SMARTMIPS | ASE_DSP | ASE_DSPR2 | ASE_EVA | ASE_MIPS3D
  536. | ASE_MT | ASE_MCU | ASE_VIRT | ASE_MSA | ASE_XPA),
  537. mips_cp0_names_mips3264r2,
  538. mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
  539. mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
  540. { "mips32r6", 1, bfd_mach_mipsisa32r6, CPU_MIPS32R6,
  541. ISA_MIPS32R6,
  542. (ASE_EVA | ASE_MSA | ASE_VIRT | ASE_XPA | ASE_MCU | ASE_MT | ASE_DSP
  543. | ASE_DSPR2 | ASE_DSPR3 | ASE_CRC | ASE_GINV),
  544. mips_cp0_names_mips3264r2,
  545. mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
  546. mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
  547. /* For stock MIPS64, disassemble all applicable MIPS-specified ASEs. */
  548. { "mips64", 1, bfd_mach_mipsisa64, CPU_MIPS64,
  549. ISA_MIPS64, ASE_MIPS3D | ASE_MDMX,
  550. mips_cp0_names_mips3264,
  551. mips_cp0sel_names_mips3264, ARRAY_SIZE (mips_cp0sel_names_mips3264),
  552. mips_cp1_names_mips3264, mips_hwr_names_numeric },
  553. { "mips64r2", 1, bfd_mach_mipsisa64r2, CPU_MIPS64R2,
  554. ISA_MIPS64R2,
  555. (ASE_MIPS3D | ASE_DSP | ASE_DSPR2 | ASE_DSP64 | ASE_EVA | ASE_MT
  556. | ASE_MCU | ASE_VIRT | ASE_VIRT64 | ASE_MSA | ASE_MSA64 | ASE_XPA),
  557. mips_cp0_names_mips3264r2,
  558. mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
  559. mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
  560. { "mips64r3", 1, bfd_mach_mipsisa64r3, CPU_MIPS64R3,
  561. ISA_MIPS64R3,
  562. (ASE_MIPS3D | ASE_DSP | ASE_DSPR2 | ASE_DSP64 | ASE_EVA | ASE_MT
  563. | ASE_MCU | ASE_VIRT | ASE_VIRT64 | ASE_MSA | ASE_MSA64 | ASE_XPA),
  564. mips_cp0_names_mips3264r2,
  565. mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
  566. mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
  567. { "mips64r5", 1, bfd_mach_mipsisa64r5, CPU_MIPS64R5,
  568. ISA_MIPS64R5,
  569. (ASE_MIPS3D | ASE_DSP | ASE_DSPR2 | ASE_DSP64 | ASE_EVA | ASE_MT
  570. | ASE_MCU | ASE_VIRT | ASE_VIRT64 | ASE_MSA | ASE_MSA64 | ASE_XPA),
  571. mips_cp0_names_mips3264r2,
  572. mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
  573. mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
  574. { "mips64r6", 1, bfd_mach_mipsisa64r6, CPU_MIPS64R6,
  575. ISA_MIPS64R6,
  576. (ASE_EVA | ASE_MSA | ASE_MSA64 | ASE_XPA | ASE_VIRT | ASE_VIRT64
  577. | ASE_MCU | ASE_MT | ASE_DSP | ASE_DSPR2 | ASE_DSPR3 | ASE_CRC
  578. | ASE_CRC64 | ASE_GINV),
  579. mips_cp0_names_mips3264r2,
  580. mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
  581. mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
  582. { "interaptiv-mr2", 1, bfd_mach_mips_interaptiv_mr2, CPU_INTERAPTIV_MR2,
  583. ISA_MIPS32R3,
  584. ASE_MT | ASE_EVA | ASE_DSP | ASE_DSPR2 | ASE_MIPS16E2 | ASE_MIPS16E2_MT,
  585. mips_cp0_names_mips3264r2,
  586. mips_cp0sel_names_mips3264r2, ARRAY_SIZE (mips_cp0sel_names_mips3264r2),
  587. mips_cp1_names_mips3264, mips_hwr_names_mips3264r2 },
  588. { "sb1", 1, bfd_mach_mips_sb1, CPU_SB1,
  589. ISA_MIPS64 | INSN_SB1, ASE_MIPS3D,
  590. mips_cp0_names_sb1,
  591. mips_cp0sel_names_sb1, ARRAY_SIZE (mips_cp0sel_names_sb1),
  592. mips_cp1_names_mips3264, mips_hwr_names_numeric },
  593. { "loongson2e", 1, bfd_mach_mips_loongson_2e, CPU_LOONGSON_2E,
  594. ISA_MIPS3 | INSN_LOONGSON_2E, 0, mips_cp0_names_numeric,
  595. NULL, 0, mips_cp1_names_mips, mips_hwr_names_numeric },
  596. { "loongson2f", 1, bfd_mach_mips_loongson_2f, CPU_LOONGSON_2F,
  597. ISA_MIPS3 | INSN_LOONGSON_2F, ASE_LOONGSON_MMI, mips_cp0_names_numeric,
  598. NULL, 0, mips_cp1_names_mips, mips_hwr_names_numeric },
  599. /* The loongson3a is an alias of gs464 for compatibility */
  600. { "loongson3a", 1, bfd_mach_mips_gs464, CPU_GS464,
  601. ISA_MIPS64R2, ASE_LOONGSON_MMI | ASE_LOONGSON_CAM | ASE_LOONGSON_EXT,
  602. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips3264,
  603. mips_hwr_names_numeric },
  604. { "gs464", 1, bfd_mach_mips_gs464, CPU_GS464,
  605. ISA_MIPS64R2, ASE_LOONGSON_MMI | ASE_LOONGSON_CAM | ASE_LOONGSON_EXT,
  606. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips3264,
  607. mips_hwr_names_numeric },
  608. { "gs464e", 1, bfd_mach_mips_gs464e, CPU_GS464E,
  609. ISA_MIPS64R2, ASE_LOONGSON_MMI | ASE_LOONGSON_CAM | ASE_LOONGSON_EXT
  610. | ASE_LOONGSON_EXT2, mips_cp0_names_numeric, NULL, 0, mips_cp1_names_mips3264,
  611. mips_hwr_names_numeric },
  612. { "gs264e", 1, bfd_mach_mips_gs264e, CPU_GS264E,
  613. ISA_MIPS64R2, ASE_LOONGSON_MMI | ASE_LOONGSON_CAM | ASE_LOONGSON_EXT
  614. | ASE_LOONGSON_EXT2 | ASE_MSA | ASE_MSA64, mips_cp0_names_numeric, NULL,
  615. 0, mips_cp1_names_mips3264, mips_hwr_names_numeric },
  616. { "octeon", 1, bfd_mach_mips_octeon, CPU_OCTEON,
  617. ISA_MIPS64R2 | INSN_OCTEON, 0, mips_cp0_names_numeric, NULL, 0,
  618. mips_cp1_names_mips3264, mips_hwr_names_numeric },
  619. { "octeon+", 1, bfd_mach_mips_octeonp, CPU_OCTEONP,
  620. ISA_MIPS64R2 | INSN_OCTEONP, 0, mips_cp0_names_numeric,
  621. NULL, 0, mips_cp1_names_mips3264, mips_hwr_names_numeric },
  622. { "octeon2", 1, bfd_mach_mips_octeon2, CPU_OCTEON2,
  623. ISA_MIPS64R2 | INSN_OCTEON2, 0, mips_cp0_names_numeric,
  624. NULL, 0, mips_cp1_names_mips3264, mips_hwr_names_numeric },
  625. { "octeon3", 1, bfd_mach_mips_octeon3, CPU_OCTEON3,
  626. ISA_MIPS64R5 | INSN_OCTEON3, ASE_VIRT | ASE_VIRT64,
  627. mips_cp0_names_numeric,
  628. NULL, 0, mips_cp1_names_mips3264, mips_hwr_names_numeric },
  629. { "xlr", 1, bfd_mach_mips_xlr, CPU_XLR,
  630. ISA_MIPS64 | INSN_XLR, 0,
  631. mips_cp0_names_xlr,
  632. mips_cp0sel_names_xlr, ARRAY_SIZE (mips_cp0sel_names_xlr),
  633. mips_cp1_names_mips3264, mips_hwr_names_numeric },
  634. /* XLP is mostly like XLR, with the prominent exception it is being
  635. MIPS64R2. */
  636. { "xlp", 1, bfd_mach_mips_xlr, CPU_XLR,
  637. ISA_MIPS64R2 | INSN_XLR, 0,
  638. mips_cp0_names_xlr,
  639. mips_cp0sel_names_xlr, ARRAY_SIZE (mips_cp0sel_names_xlr),
  640. mips_cp1_names_mips3264, mips_hwr_names_numeric },
  641. /* This entry, mips16, is here only for ISA/processor selection; do
  642. not print its name. */
  643. { "", 1, bfd_mach_mips16, CPU_MIPS16, ISA_MIPS64,
  644. ASE_MIPS16E2 | ASE_MIPS16E2_MT,
  645. mips_cp0_names_numeric, NULL, 0, mips_cp1_names_numeric,
  646. mips_hwr_names_numeric },
  647. };
  648. /* ISA and processor type to disassemble for, and register names to use.
  649. set_default_mips_dis_options and parse_mips_dis_options fill in these
  650. values. */
  651. static int mips_processor;
  652. static int mips_isa;
  653. static int mips_ase;
  654. static int micromips_ase;
  655. static const char * const *mips_gpr_names;
  656. static const char * const *mips_fpr_names;
  657. static const char * const *mips_cp0_names;
  658. static const struct mips_cp0sel_name *mips_cp0sel_names;
  659. static int mips_cp0sel_names_len;
  660. static const char * const *mips_cp1_names;
  661. static const char * const *mips_hwr_names;
  662. /* Other options */
  663. static int no_aliases; /* If set disassemble as most general inst. */
  664. static const struct mips_abi_choice *
  665. choose_abi_by_name (const char *name, unsigned int namelen)
  666. {
  667. const struct mips_abi_choice *c;
  668. unsigned int i;
  669. for (i = 0, c = NULL; i < ARRAY_SIZE (mips_abi_choices) && c == NULL; i++)
  670. if (strncmp (mips_abi_choices[i].name, name, namelen) == 0
  671. && strlen (mips_abi_choices[i].name) == namelen)
  672. c = &mips_abi_choices[i];
  673. return c;
  674. }
  675. static const struct mips_arch_choice *
  676. choose_arch_by_name (const char *name, unsigned int namelen)
  677. {
  678. const struct mips_arch_choice *c = NULL;
  679. unsigned int i;
  680. for (i = 0, c = NULL; i < ARRAY_SIZE (mips_arch_choices) && c == NULL; i++)
  681. if (strncmp (mips_arch_choices[i].name, name, namelen) == 0
  682. && strlen (mips_arch_choices[i].name) == namelen)
  683. c = &mips_arch_choices[i];
  684. return c;
  685. }
  686. static const struct mips_arch_choice *
  687. choose_arch_by_number (unsigned long mach)
  688. {
  689. static unsigned long hint_bfd_mach;
  690. static const struct mips_arch_choice *hint_arch_choice;
  691. const struct mips_arch_choice *c;
  692. unsigned int i;
  693. /* We optimize this because even if the user specifies no
  694. flags, this will be done for every instruction! */
  695. if (hint_bfd_mach == mach
  696. && hint_arch_choice != NULL
  697. && hint_arch_choice->bfd_mach == hint_bfd_mach)
  698. return hint_arch_choice;
  699. for (i = 0, c = NULL; i < ARRAY_SIZE (mips_arch_choices) && c == NULL; i++)
  700. {
  701. if (mips_arch_choices[i].bfd_mach_valid
  702. && mips_arch_choices[i].bfd_mach == mach)
  703. {
  704. c = &mips_arch_choices[i];
  705. hint_bfd_mach = mach;
  706. hint_arch_choice = c;
  707. }
  708. }
  709. return c;
  710. }
  711. /* Check if the object uses NewABI conventions. */
  712. static int
  713. is_newabi (Elf_Internal_Ehdr *header)
  714. {
  715. /* There are no old-style ABIs which use 64-bit ELF. */
  716. if (header->e_ident[EI_CLASS] == ELFCLASS64)
  717. return 1;
  718. /* If a 32-bit ELF file, n32 is a new-style ABI. */
  719. if ((header->e_flags & EF_MIPS_ABI2) != 0)
  720. return 1;
  721. return 0;
  722. }
  723. /* Check if the object has microMIPS ASE code. */
  724. static int
  725. is_micromips (Elf_Internal_Ehdr *header)
  726. {
  727. if ((header->e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) != 0)
  728. return 1;
  729. return 0;
  730. }
  731. /* Convert ASE flags from .MIPS.abiflags to internal values. */
  732. static unsigned long
  733. mips_convert_abiflags_ases (unsigned long afl_ases)
  734. {
  735. unsigned long opcode_ases = 0;
  736. if (afl_ases & AFL_ASE_DSP)
  737. opcode_ases |= ASE_DSP;
  738. if (afl_ases & AFL_ASE_DSPR2)
  739. opcode_ases |= ASE_DSPR2;
  740. if (afl_ases & AFL_ASE_EVA)
  741. opcode_ases |= ASE_EVA;
  742. if (afl_ases & AFL_ASE_MCU)
  743. opcode_ases |= ASE_MCU;
  744. if (afl_ases & AFL_ASE_MDMX)
  745. opcode_ases |= ASE_MDMX;
  746. if (afl_ases & AFL_ASE_MIPS3D)
  747. opcode_ases |= ASE_MIPS3D;
  748. if (afl_ases & AFL_ASE_MT)
  749. opcode_ases |= ASE_MT;
  750. if (afl_ases & AFL_ASE_SMARTMIPS)
  751. opcode_ases |= ASE_SMARTMIPS;
  752. if (afl_ases & AFL_ASE_VIRT)
  753. opcode_ases |= ASE_VIRT;
  754. if (afl_ases & AFL_ASE_MSA)
  755. opcode_ases |= ASE_MSA;
  756. if (afl_ases & AFL_ASE_XPA)
  757. opcode_ases |= ASE_XPA;
  758. if (afl_ases & AFL_ASE_DSPR3)
  759. opcode_ases |= ASE_DSPR3;
  760. if (afl_ases & AFL_ASE_MIPS16E2)
  761. opcode_ases |= ASE_MIPS16E2;
  762. return opcode_ases;
  763. }
  764. /* Calculate combination ASE flags from regular ASE flags. */
  765. static unsigned long
  766. mips_calculate_combination_ases (int opcode_isa, unsigned long opcode_ases)
  767. {
  768. unsigned long combination_ases = 0;
  769. if ((opcode_ases & (ASE_XPA | ASE_VIRT)) == (ASE_XPA | ASE_VIRT))
  770. combination_ases |= ASE_XPA_VIRT;
  771. if ((opcode_ases & (ASE_MIPS16E2 | ASE_MT)) == (ASE_MIPS16E2 | ASE_MT))
  772. combination_ases |= ASE_MIPS16E2_MT;
  773. if ((opcode_ases & ASE_EVA)
  774. && ((opcode_isa & INSN_ISA_MASK) == ISA_MIPS64R6
  775. || (opcode_isa & INSN_ISA_MASK) == ISA_MIPS32R6))
  776. combination_ases |= ASE_EVA_R6;
  777. return combination_ases;
  778. }
  779. static void
  780. set_default_mips_dis_options (struct disassemble_info *info)
  781. {
  782. const struct mips_arch_choice *chosen_arch;
  783. /* Defaults: mipsIII/r3000 (?!), no microMIPS ASE (any compressed code
  784. is MIPS16 ASE) (o)32-style ("oldabi") GPR names, and numeric FPR,
  785. CP0 register, and HWR names. */
  786. mips_isa = ISA_MIPS3;
  787. mips_processor = CPU_R3000;
  788. micromips_ase = 0;
  789. mips_ase = 0;
  790. mips_gpr_names = mips_gpr_names_oldabi;
  791. mips_fpr_names = mips_fpr_names_numeric;
  792. mips_cp0_names = mips_cp0_names_numeric;
  793. mips_cp0sel_names = NULL;
  794. mips_cp0sel_names_len = 0;
  795. mips_cp1_names = mips_cp1_names_numeric;
  796. mips_hwr_names = mips_hwr_names_numeric;
  797. no_aliases = 0;
  798. /* Set ISA, architecture, and cp0 register names as best we can. */
  799. #if ! SYMTAB_AVAILABLE
  800. /* This is running out on a target machine, not in a host tool.
  801. FIXME: Where does mips_target_info come from? */
  802. target_processor = mips_target_info.processor;
  803. mips_isa = mips_target_info.isa;
  804. mips_ase = mips_target_info.ase;
  805. #else
  806. chosen_arch = choose_arch_by_number (info->mach);
  807. if (chosen_arch != NULL)
  808. {
  809. mips_processor = chosen_arch->processor;
  810. mips_isa = chosen_arch->isa;
  811. mips_ase = chosen_arch->ase;
  812. mips_cp0_names = chosen_arch->cp0_names;
  813. mips_cp0sel_names = chosen_arch->cp0sel_names;
  814. mips_cp0sel_names_len = chosen_arch->cp0sel_names_len;
  815. mips_cp1_names = chosen_arch->cp1_names;
  816. mips_hwr_names = chosen_arch->hwr_names;
  817. }
  818. /* Update settings according to the ELF file header flags. */
  819. if (info->flavour == bfd_target_elf_flavour && info->section != NULL)
  820. {
  821. struct bfd *abfd = info->section->owner;
  822. Elf_Internal_Ehdr *header = elf_elfheader (abfd);
  823. Elf_Internal_ABIFlags_v0 *abiflags = NULL;
  824. /* We won't ever get here if !HAVE_BFD_MIPS_ELF_GET_ABIFLAGS,
  825. because we won't then have a MIPS/ELF BFD, however we need
  826. to guard against a link error in a `--enable-targets=...'
  827. configuration with a 32-bit host where the MIPS target is
  828. a secondary, or with MIPS/ECOFF configurations. */
  829. #ifdef HAVE_BFD_MIPS_ELF_GET_ABIFLAGS
  830. abiflags = bfd_mips_elf_get_abiflags (abfd);
  831. #endif
  832. /* If an ELF "newabi" binary, use the n32/(n)64 GPR names. */
  833. if (is_newabi (header))
  834. mips_gpr_names = mips_gpr_names_newabi;
  835. /* If a microMIPS binary, then don't use MIPS16 bindings. */
  836. micromips_ase = is_micromips (header);
  837. /* OR in any extra ASE flags set in ELF file structures. */
  838. if (abiflags)
  839. mips_ase |= mips_convert_abiflags_ases (abiflags->ases);
  840. else if (header->e_flags & EF_MIPS_ARCH_ASE_MDMX)
  841. mips_ase |= ASE_MDMX;
  842. }
  843. #endif
  844. mips_ase |= mips_calculate_combination_ases (mips_isa, mips_ase);
  845. }
  846. /* Parse an ASE disassembler option and set the corresponding global
  847. ASE flag(s). Return TRUE if successful, FALSE otherwise. */
  848. static bool
  849. parse_mips_ase_option (const char *option)
  850. {
  851. if (startswith (option, "msa"))
  852. {
  853. mips_ase |= ASE_MSA;
  854. if ((mips_isa & INSN_ISA_MASK) == ISA_MIPS64R2
  855. || (mips_isa & INSN_ISA_MASK) == ISA_MIPS64R3
  856. || (mips_isa & INSN_ISA_MASK) == ISA_MIPS64R5
  857. || (mips_isa & INSN_ISA_MASK) == ISA_MIPS64R6)
  858. mips_ase |= ASE_MSA64;
  859. return true;
  860. }
  861. if (startswith (option, "virt"))
  862. {
  863. mips_ase |= ASE_VIRT;
  864. if (mips_isa & ISA_MIPS64R2
  865. || mips_isa & ISA_MIPS64R3
  866. || mips_isa & ISA_MIPS64R5
  867. || mips_isa & ISA_MIPS64R6)
  868. mips_ase |= ASE_VIRT64;
  869. return true;
  870. }
  871. if (startswith (option, "xpa"))
  872. {
  873. mips_ase |= ASE_XPA;
  874. return true;
  875. }
  876. if (startswith (option, "ginv"))
  877. {
  878. mips_ase |= ASE_GINV;
  879. return true;
  880. }
  881. if (startswith (option, "loongson-mmi"))
  882. {
  883. mips_ase |= ASE_LOONGSON_MMI;
  884. return true;
  885. }
  886. if (startswith (option, "loongson-cam"))
  887. {
  888. mips_ase |= ASE_LOONGSON_CAM;
  889. return true;
  890. }
  891. /* Put here for match ext2 frist */
  892. if (startswith (option, "loongson-ext2"))
  893. {
  894. mips_ase |= ASE_LOONGSON_EXT2;
  895. return true;
  896. }
  897. if (startswith (option, "loongson-ext"))
  898. {
  899. mips_ase |= ASE_LOONGSON_EXT;
  900. return true;
  901. }
  902. return false;
  903. }
  904. static void
  905. parse_mips_dis_option (const char *option, unsigned int len)
  906. {
  907. unsigned int i, optionlen, vallen;
  908. const char *val;
  909. const struct mips_abi_choice *chosen_abi;
  910. const struct mips_arch_choice *chosen_arch;
  911. /* Try to match options that are simple flags */
  912. if (startswith (option, "no-aliases"))
  913. {
  914. no_aliases = 1;
  915. return;
  916. }
  917. if (parse_mips_ase_option (option))
  918. {
  919. mips_ase |= mips_calculate_combination_ases (mips_isa, mips_ase);
  920. return;
  921. }
  922. /* Look for the = that delimits the end of the option name. */
  923. for (i = 0; i < len; i++)
  924. if (option[i] == '=')
  925. break;
  926. if (i == 0) /* Invalid option: no name before '='. */
  927. return;
  928. if (i == len) /* Invalid option: no '='. */
  929. return;
  930. if (i == (len - 1)) /* Invalid option: no value after '='. */
  931. return;
  932. optionlen = i;
  933. val = option + (optionlen + 1);
  934. vallen = len - (optionlen + 1);
  935. if (strncmp ("gpr-names", option, optionlen) == 0
  936. && strlen ("gpr-names") == optionlen)
  937. {
  938. chosen_abi = choose_abi_by_name (val, vallen);
  939. if (chosen_abi != NULL)
  940. mips_gpr_names = chosen_abi->gpr_names;
  941. return;
  942. }
  943. if (strncmp ("fpr-names", option, optionlen) == 0
  944. && strlen ("fpr-names") == optionlen)
  945. {
  946. chosen_abi = choose_abi_by_name (val, vallen);
  947. if (chosen_abi != NULL)
  948. mips_fpr_names = chosen_abi->fpr_names;
  949. return;
  950. }
  951. if (strncmp ("cp0-names", option, optionlen) == 0
  952. && strlen ("cp0-names") == optionlen)
  953. {
  954. chosen_arch = choose_arch_by_name (val, vallen);
  955. if (chosen_arch != NULL)
  956. {
  957. mips_cp0_names = chosen_arch->cp0_names;
  958. mips_cp0sel_names = chosen_arch->cp0sel_names;
  959. mips_cp0sel_names_len = chosen_arch->cp0sel_names_len;
  960. }
  961. return;
  962. }
  963. if (strncmp ("cp1-names", option, optionlen) == 0
  964. && strlen ("cp1-names") == optionlen)
  965. {
  966. chosen_arch = choose_arch_by_name (val, vallen);
  967. if (chosen_arch != NULL)
  968. mips_cp1_names = chosen_arch->cp1_names;
  969. return;
  970. }
  971. if (strncmp ("hwr-names", option, optionlen) == 0
  972. && strlen ("hwr-names") == optionlen)
  973. {
  974. chosen_arch = choose_arch_by_name (val, vallen);
  975. if (chosen_arch != NULL)
  976. mips_hwr_names = chosen_arch->hwr_names;
  977. return;
  978. }
  979. if (strncmp ("reg-names", option, optionlen) == 0
  980. && strlen ("reg-names") == optionlen)
  981. {
  982. /* We check both ABI and ARCH here unconditionally, so
  983. that "numeric" will do the desirable thing: select
  984. numeric register names for all registers. Other than
  985. that, a given name probably won't match both. */
  986. chosen_abi = choose_abi_by_name (val, vallen);
  987. if (chosen_abi != NULL)
  988. {
  989. mips_gpr_names = chosen_abi->gpr_names;
  990. mips_fpr_names = chosen_abi->fpr_names;
  991. }
  992. chosen_arch = choose_arch_by_name (val, vallen);
  993. if (chosen_arch != NULL)
  994. {
  995. mips_cp0_names = chosen_arch->cp0_names;
  996. mips_cp0sel_names = chosen_arch->cp0sel_names;
  997. mips_cp0sel_names_len = chosen_arch->cp0sel_names_len;
  998. mips_cp1_names = chosen_arch->cp1_names;
  999. mips_hwr_names = chosen_arch->hwr_names;
  1000. }
  1001. return;
  1002. }
  1003. /* Invalid option. */
  1004. }
  1005. static void
  1006. parse_mips_dis_options (const char *options)
  1007. {
  1008. const char *option_end;
  1009. if (options == NULL)
  1010. return;
  1011. while (*options != '\0')
  1012. {
  1013. /* Skip empty options. */
  1014. if (*options == ',')
  1015. {
  1016. options++;
  1017. continue;
  1018. }
  1019. /* We know that *options is neither NUL or a comma. */
  1020. option_end = options + 1;
  1021. while (*option_end != ',' && *option_end != '\0')
  1022. option_end++;
  1023. parse_mips_dis_option (options, option_end - options);
  1024. /* Go on to the next one. If option_end points to a comma, it
  1025. will be skipped above. */
  1026. options = option_end;
  1027. }
  1028. }
  1029. static const struct mips_cp0sel_name *
  1030. lookup_mips_cp0sel_name (const struct mips_cp0sel_name *names,
  1031. unsigned int len,
  1032. unsigned int cp0reg,
  1033. unsigned int sel)
  1034. {
  1035. unsigned int i;
  1036. for (i = 0; i < len; i++)
  1037. if (names[i].cp0reg == cp0reg && names[i].sel == sel)
  1038. return &names[i];
  1039. return NULL;
  1040. }
  1041. /* Print register REGNO, of type TYPE, for instruction OPCODE. */
  1042. static void
  1043. print_reg (struct disassemble_info *info, const struct mips_opcode *opcode,
  1044. enum mips_reg_operand_type type, int regno)
  1045. {
  1046. switch (type)
  1047. {
  1048. case OP_REG_GP:
  1049. info->fprintf_func (info->stream, "%s", mips_gpr_names[regno]);
  1050. break;
  1051. case OP_REG_FP:
  1052. info->fprintf_func (info->stream, "%s", mips_fpr_names[regno]);
  1053. break;
  1054. case OP_REG_CCC:
  1055. if (opcode->pinfo & (FP_D | FP_S))
  1056. info->fprintf_func (info->stream, "$fcc%d", regno);
  1057. else
  1058. info->fprintf_func (info->stream, "$cc%d", regno);
  1059. break;
  1060. case OP_REG_VEC:
  1061. if (opcode->membership & INSN_5400)
  1062. info->fprintf_func (info->stream, "$f%d", regno);
  1063. else
  1064. info->fprintf_func (info->stream, "$v%d", regno);
  1065. break;
  1066. case OP_REG_ACC:
  1067. info->fprintf_func (info->stream, "$ac%d", regno);
  1068. break;
  1069. case OP_REG_COPRO:
  1070. if (opcode->name[strlen (opcode->name) - 1] == '0')
  1071. info->fprintf_func (info->stream, "%s", mips_cp0_names[regno]);
  1072. else
  1073. info->fprintf_func (info->stream, "$%d", regno);
  1074. break;
  1075. case OP_REG_CONTROL:
  1076. if (opcode->name[strlen (opcode->name) - 1] == '1')
  1077. info->fprintf_func (info->stream, "%s", mips_cp1_names[regno]);
  1078. else
  1079. info->fprintf_func (info->stream, "$%d", regno);
  1080. break;
  1081. case OP_REG_HW:
  1082. info->fprintf_func (info->stream, "%s", mips_hwr_names[regno]);
  1083. break;
  1084. case OP_REG_VF:
  1085. info->fprintf_func (info->stream, "$vf%d", regno);
  1086. break;
  1087. case OP_REG_VI:
  1088. info->fprintf_func (info->stream, "$vi%d", regno);
  1089. break;
  1090. case OP_REG_R5900_I:
  1091. info->fprintf_func (info->stream, "$I");
  1092. break;
  1093. case OP_REG_R5900_Q:
  1094. info->fprintf_func (info->stream, "$Q");
  1095. break;
  1096. case OP_REG_R5900_R:
  1097. info->fprintf_func (info->stream, "$R");
  1098. break;
  1099. case OP_REG_R5900_ACC:
  1100. info->fprintf_func (info->stream, "$ACC");
  1101. break;
  1102. case OP_REG_MSA:
  1103. info->fprintf_func (info->stream, "$w%d", regno);
  1104. break;
  1105. case OP_REG_MSA_CTRL:
  1106. info->fprintf_func (info->stream, "%s", msa_control_names[regno]);
  1107. break;
  1108. }
  1109. }
  1110. /* Used to track the state carried over from previous operands in
  1111. an instruction. */
  1112. struct mips_print_arg_state {
  1113. /* The value of the last OP_INT seen. We only use this for OP_MSB,
  1114. where the value is known to be unsigned and small. */
  1115. unsigned int last_int;
  1116. /* The type and number of the last OP_REG seen. We only use this for
  1117. OP_REPEAT_DEST_REG and OP_REPEAT_PREV_REG. */
  1118. enum mips_reg_operand_type last_reg_type;
  1119. unsigned int last_regno;
  1120. unsigned int dest_regno;
  1121. unsigned int seen_dest;
  1122. };
  1123. /* Initialize STATE for the start of an instruction. */
  1124. static inline void
  1125. init_print_arg_state (struct mips_print_arg_state *state)
  1126. {
  1127. memset (state, 0, sizeof (*state));
  1128. }
  1129. /* Print OP_VU0_SUFFIX or OP_VU0_MATCH_SUFFIX operand OPERAND,
  1130. whose value is given by UVAL. */
  1131. static void
  1132. print_vu0_channel (struct disassemble_info *info,
  1133. const struct mips_operand *operand, unsigned int uval)
  1134. {
  1135. if (operand->size == 4)
  1136. info->fprintf_func (info->stream, "%s%s%s%s",
  1137. uval & 8 ? "x" : "",
  1138. uval & 4 ? "y" : "",
  1139. uval & 2 ? "z" : "",
  1140. uval & 1 ? "w" : "");
  1141. else if (operand->size == 2)
  1142. info->fprintf_func (info->stream, "%c", "xyzw"[uval]);
  1143. else
  1144. abort ();
  1145. }
  1146. /* Record information about a register operand. */
  1147. static void
  1148. mips_seen_register (struct mips_print_arg_state *state,
  1149. unsigned int regno,
  1150. enum mips_reg_operand_type reg_type)
  1151. {
  1152. state->last_reg_type = reg_type;
  1153. state->last_regno = regno;
  1154. if (!state->seen_dest)
  1155. {
  1156. state->seen_dest = 1;
  1157. state->dest_regno = regno;
  1158. }
  1159. }
  1160. /* Print SAVE/RESTORE instruction operands according to the argument
  1161. register mask AMASK, the number of static registers saved NSREG,
  1162. the $ra, $s0 and $s1 register specifiers RA, S0 and S1 respectively,
  1163. and the frame size FRAME_SIZE. */
  1164. static void
  1165. mips_print_save_restore (struct disassemble_info *info, unsigned int amask,
  1166. unsigned int nsreg, unsigned int ra,
  1167. unsigned int s0, unsigned int s1,
  1168. unsigned int frame_size)
  1169. {
  1170. const fprintf_ftype infprintf = info->fprintf_func;
  1171. unsigned int nargs, nstatics, smask, i, j;
  1172. void *is = info->stream;
  1173. const char *sep;
  1174. if (amask == MIPS_SVRS_ALL_ARGS)
  1175. {
  1176. nargs = 4;
  1177. nstatics = 0;
  1178. }
  1179. else if (amask == MIPS_SVRS_ALL_STATICS)
  1180. {
  1181. nargs = 0;
  1182. nstatics = 4;
  1183. }
  1184. else
  1185. {
  1186. nargs = amask >> 2;
  1187. nstatics = amask & 3;
  1188. }
  1189. sep = "";
  1190. if (nargs > 0)
  1191. {
  1192. infprintf (is, "%s", mips_gpr_names[4]);
  1193. if (nargs > 1)
  1194. infprintf (is, "-%s", mips_gpr_names[4 + nargs - 1]);
  1195. sep = ",";
  1196. }
  1197. infprintf (is, "%s%d", sep, frame_size);
  1198. if (ra) /* $ra */
  1199. infprintf (is, ",%s", mips_gpr_names[31]);
  1200. smask = 0;
  1201. if (s0) /* $s0 */
  1202. smask |= 1 << 0;
  1203. if (s1) /* $s1 */
  1204. smask |= 1 << 1;
  1205. if (nsreg > 0) /* $s2-$s8 */
  1206. smask |= ((1 << nsreg) - 1) << 2;
  1207. for (i = 0; i < 9; i++)
  1208. if (smask & (1 << i))
  1209. {
  1210. infprintf (is, ",%s", mips_gpr_names[i == 8 ? 30 : (16 + i)]);
  1211. /* Skip over string of set bits. */
  1212. for (j = i; smask & (2 << j); j++)
  1213. continue;
  1214. if (j > i)
  1215. infprintf (is, "-%s", mips_gpr_names[j == 8 ? 30 : (16 + j)]);
  1216. i = j + 1;
  1217. }
  1218. /* Statics $ax - $a3. */
  1219. if (nstatics == 1)
  1220. infprintf (is, ",%s", mips_gpr_names[7]);
  1221. else if (nstatics > 0)
  1222. infprintf (is, ",%s-%s",
  1223. mips_gpr_names[7 - nstatics + 1],
  1224. mips_gpr_names[7]);
  1225. }
  1226. /* Print operand OPERAND of OPCODE, using STATE to track inter-operand state.
  1227. UVAL is the encoding of the operand (shifted into bit 0) and BASE_PC is
  1228. the base address for OP_PCREL operands. */
  1229. static void
  1230. print_insn_arg (struct disassemble_info *info,
  1231. struct mips_print_arg_state *state,
  1232. const struct mips_opcode *opcode,
  1233. const struct mips_operand *operand,
  1234. bfd_vma base_pc,
  1235. unsigned int uval)
  1236. {
  1237. const fprintf_ftype infprintf = info->fprintf_func;
  1238. void *is = info->stream;
  1239. switch (operand->type)
  1240. {
  1241. case OP_INT:
  1242. {
  1243. const struct mips_int_operand *int_op;
  1244. int_op = (const struct mips_int_operand *) operand;
  1245. uval = mips_decode_int_operand (int_op, uval);
  1246. state->last_int = uval;
  1247. if (int_op->print_hex)
  1248. infprintf (is, "0x%x", uval);
  1249. else
  1250. infprintf (is, "%d", uval);
  1251. }
  1252. break;
  1253. case OP_MAPPED_INT:
  1254. {
  1255. const struct mips_mapped_int_operand *mint_op;
  1256. mint_op = (const struct mips_mapped_int_operand *) operand;
  1257. uval = mint_op->int_map[uval];
  1258. state->last_int = uval;
  1259. if (mint_op->print_hex)
  1260. infprintf (is, "0x%x", uval);
  1261. else
  1262. infprintf (is, "%d", uval);
  1263. }
  1264. break;
  1265. case OP_MSB:
  1266. {
  1267. const struct mips_msb_operand *msb_op;
  1268. msb_op = (const struct mips_msb_operand *) operand;
  1269. uval += msb_op->bias;
  1270. if (msb_op->add_lsb)
  1271. uval -= state->last_int;
  1272. infprintf (is, "0x%x", uval);
  1273. }
  1274. break;
  1275. case OP_REG:
  1276. case OP_OPTIONAL_REG:
  1277. {
  1278. const struct mips_reg_operand *reg_op;
  1279. reg_op = (const struct mips_reg_operand *) operand;
  1280. uval = mips_decode_reg_operand (reg_op, uval);
  1281. print_reg (info, opcode, reg_op->reg_type, uval);
  1282. mips_seen_register (state, uval, reg_op->reg_type);
  1283. }
  1284. break;
  1285. case OP_REG_PAIR:
  1286. {
  1287. const struct mips_reg_pair_operand *pair_op;
  1288. pair_op = (const struct mips_reg_pair_operand *) operand;
  1289. print_reg (info, opcode, pair_op->reg_type,
  1290. pair_op->reg1_map[uval]);
  1291. infprintf (is, ",");
  1292. print_reg (info, opcode, pair_op->reg_type,
  1293. pair_op->reg2_map[uval]);
  1294. }
  1295. break;
  1296. case OP_PCREL:
  1297. {
  1298. const struct mips_pcrel_operand *pcrel_op;
  1299. pcrel_op = (const struct mips_pcrel_operand *) operand;
  1300. info->target = mips_decode_pcrel_operand (pcrel_op, base_pc, uval);
  1301. /* For jumps and branches clear the ISA bit except for
  1302. the GDB disassembler. */
  1303. if (pcrel_op->include_isa_bit
  1304. && info->flavour != bfd_target_unknown_flavour)
  1305. info->target &= -2;
  1306. (*info->print_address_func) (info->target, info);
  1307. }
  1308. break;
  1309. case OP_PERF_REG:
  1310. infprintf (is, "%d", uval);
  1311. break;
  1312. case OP_ADDIUSP_INT:
  1313. {
  1314. int sval;
  1315. sval = mips_signed_operand (operand, uval) * 4;
  1316. if (sval >= -8 && sval < 8)
  1317. sval ^= 0x400;
  1318. infprintf (is, "%d", sval);
  1319. break;
  1320. }
  1321. case OP_CLO_CLZ_DEST:
  1322. {
  1323. unsigned int reg1, reg2;
  1324. reg1 = uval & 31;
  1325. reg2 = uval >> 5;
  1326. /* If one is zero use the other. */
  1327. if (reg1 == reg2 || reg2 == 0)
  1328. infprintf (is, "%s", mips_gpr_names[reg1]);
  1329. else if (reg1 == 0)
  1330. infprintf (is, "%s", mips_gpr_names[reg2]);
  1331. else
  1332. /* Bogus, result depends on processor. */
  1333. infprintf (is, "%s or %s", mips_gpr_names[reg1],
  1334. mips_gpr_names[reg2]);
  1335. }
  1336. break;
  1337. case OP_SAME_RS_RT:
  1338. case OP_CHECK_PREV:
  1339. case OP_NON_ZERO_REG:
  1340. {
  1341. print_reg (info, opcode, OP_REG_GP, uval & 31);
  1342. mips_seen_register (state, uval, OP_REG_GP);
  1343. }
  1344. break;
  1345. case OP_LWM_SWM_LIST:
  1346. if (operand->size == 2)
  1347. {
  1348. if (uval == 0)
  1349. infprintf (is, "%s,%s",
  1350. mips_gpr_names[16],
  1351. mips_gpr_names[31]);
  1352. else
  1353. infprintf (is, "%s-%s,%s",
  1354. mips_gpr_names[16],
  1355. mips_gpr_names[16 + uval],
  1356. mips_gpr_names[31]);
  1357. }
  1358. else
  1359. {
  1360. int s_reg_encode;
  1361. s_reg_encode = uval & 0xf;
  1362. if (s_reg_encode != 0)
  1363. {
  1364. if (s_reg_encode == 1)
  1365. infprintf (is, "%s", mips_gpr_names[16]);
  1366. else if (s_reg_encode < 9)
  1367. infprintf (is, "%s-%s",
  1368. mips_gpr_names[16],
  1369. mips_gpr_names[15 + s_reg_encode]);
  1370. else if (s_reg_encode == 9)
  1371. infprintf (is, "%s-%s,%s",
  1372. mips_gpr_names[16],
  1373. mips_gpr_names[23],
  1374. mips_gpr_names[30]);
  1375. else
  1376. infprintf (is, "UNKNOWN");
  1377. }
  1378. if (uval & 0x10) /* For ra. */
  1379. {
  1380. if (s_reg_encode == 0)
  1381. infprintf (is, "%s", mips_gpr_names[31]);
  1382. else
  1383. infprintf (is, ",%s", mips_gpr_names[31]);
  1384. }
  1385. }
  1386. break;
  1387. case OP_ENTRY_EXIT_LIST:
  1388. {
  1389. const char *sep;
  1390. unsigned int amask, smask;
  1391. sep = "";
  1392. amask = (uval >> 3) & 7;
  1393. if (amask > 0 && amask < 5)
  1394. {
  1395. infprintf (is, "%s", mips_gpr_names[4]);
  1396. if (amask > 1)
  1397. infprintf (is, "-%s", mips_gpr_names[amask + 3]);
  1398. sep = ",";
  1399. }
  1400. smask = (uval >> 1) & 3;
  1401. if (smask == 3)
  1402. {
  1403. infprintf (is, "%s??", sep);
  1404. sep = ",";
  1405. }
  1406. else if (smask > 0)
  1407. {
  1408. infprintf (is, "%s%s", sep, mips_gpr_names[16]);
  1409. if (smask > 1)
  1410. infprintf (is, "-%s", mips_gpr_names[smask + 15]);
  1411. sep = ",";
  1412. }
  1413. if (uval & 1)
  1414. {
  1415. infprintf (is, "%s%s", sep, mips_gpr_names[31]);
  1416. sep = ",";
  1417. }
  1418. if (amask == 5 || amask == 6)
  1419. {
  1420. infprintf (is, "%s%s", sep, mips_fpr_names[0]);
  1421. if (amask == 6)
  1422. infprintf (is, "-%s", mips_fpr_names[1]);
  1423. }
  1424. }
  1425. break;
  1426. case OP_SAVE_RESTORE_LIST:
  1427. /* Should be handled by the caller due to complex behavior. */
  1428. abort ();
  1429. case OP_MDMX_IMM_REG:
  1430. {
  1431. unsigned int vsel;
  1432. vsel = uval >> 5;
  1433. uval &= 31;
  1434. if ((vsel & 0x10) == 0)
  1435. {
  1436. int fmt;
  1437. vsel &= 0x0f;
  1438. for (fmt = 0; fmt < 3; fmt++, vsel >>= 1)
  1439. if ((vsel & 1) == 0)
  1440. break;
  1441. print_reg (info, opcode, OP_REG_VEC, uval);
  1442. infprintf (is, "[%d]", vsel >> 1);
  1443. }
  1444. else if ((vsel & 0x08) == 0)
  1445. print_reg (info, opcode, OP_REG_VEC, uval);
  1446. else
  1447. infprintf (is, "0x%x", uval);
  1448. }
  1449. break;
  1450. case OP_REPEAT_PREV_REG:
  1451. print_reg (info, opcode, state->last_reg_type, state->last_regno);
  1452. break;
  1453. case OP_REPEAT_DEST_REG:
  1454. print_reg (info, opcode, state->last_reg_type, state->dest_regno);
  1455. break;
  1456. case OP_PC:
  1457. infprintf (is, "$pc");
  1458. break;
  1459. case OP_REG28:
  1460. print_reg (info, opcode, OP_REG_GP, 28);
  1461. break;
  1462. case OP_VU0_SUFFIX:
  1463. case OP_VU0_MATCH_SUFFIX:
  1464. print_vu0_channel (info, operand, uval);
  1465. break;
  1466. case OP_IMM_INDEX:
  1467. infprintf (is, "[%d]", uval);
  1468. break;
  1469. case OP_REG_INDEX:
  1470. infprintf (is, "[");
  1471. print_reg (info, opcode, OP_REG_GP, uval);
  1472. infprintf (is, "]");
  1473. break;
  1474. }
  1475. }
  1476. /* Validate the arguments for INSN, which is described by OPCODE.
  1477. Use DECODE_OPERAND to get the encoding of each operand. */
  1478. static bool
  1479. validate_insn_args (const struct mips_opcode *opcode,
  1480. const struct mips_operand *(*decode_operand) (const char *),
  1481. unsigned int insn)
  1482. {
  1483. struct mips_print_arg_state state;
  1484. const struct mips_operand *operand;
  1485. const char *s;
  1486. unsigned int uval;
  1487. init_print_arg_state (&state);
  1488. for (s = opcode->args; *s; ++s)
  1489. {
  1490. switch (*s)
  1491. {
  1492. case ',':
  1493. case '(':
  1494. case ')':
  1495. break;
  1496. case '#':
  1497. ++s;
  1498. break;
  1499. default:
  1500. operand = decode_operand (s);
  1501. if (operand)
  1502. {
  1503. uval = mips_extract_operand (operand, insn);
  1504. switch (operand->type)
  1505. {
  1506. case OP_REG:
  1507. case OP_OPTIONAL_REG:
  1508. {
  1509. const struct mips_reg_operand *reg_op;
  1510. reg_op = (const struct mips_reg_operand *) operand;
  1511. uval = mips_decode_reg_operand (reg_op, uval);
  1512. mips_seen_register (&state, uval, reg_op->reg_type);
  1513. }
  1514. break;
  1515. case OP_SAME_RS_RT:
  1516. {
  1517. unsigned int reg1, reg2;
  1518. reg1 = uval & 31;
  1519. reg2 = uval >> 5;
  1520. if (reg1 != reg2 || reg1 == 0)
  1521. return false;
  1522. }
  1523. break;
  1524. case OP_CHECK_PREV:
  1525. {
  1526. const struct mips_check_prev_operand *prev_op;
  1527. prev_op = (const struct mips_check_prev_operand *) operand;
  1528. if (!prev_op->zero_ok && uval == 0)
  1529. return false;
  1530. if (((prev_op->less_than_ok && uval < state.last_regno)
  1531. || (prev_op->greater_than_ok && uval > state.last_regno)
  1532. || (prev_op->equal_ok && uval == state.last_regno)))
  1533. break;
  1534. return false;
  1535. }
  1536. case OP_NON_ZERO_REG:
  1537. {
  1538. if (uval == 0)
  1539. return false;
  1540. }
  1541. break;
  1542. case OP_INT:
  1543. case OP_MAPPED_INT:
  1544. case OP_MSB:
  1545. case OP_REG_PAIR:
  1546. case OP_PCREL:
  1547. case OP_PERF_REG:
  1548. case OP_ADDIUSP_INT:
  1549. case OP_CLO_CLZ_DEST:
  1550. case OP_LWM_SWM_LIST:
  1551. case OP_ENTRY_EXIT_LIST:
  1552. case OP_MDMX_IMM_REG:
  1553. case OP_REPEAT_PREV_REG:
  1554. case OP_REPEAT_DEST_REG:
  1555. case OP_PC:
  1556. case OP_REG28:
  1557. case OP_VU0_SUFFIX:
  1558. case OP_VU0_MATCH_SUFFIX:
  1559. case OP_IMM_INDEX:
  1560. case OP_REG_INDEX:
  1561. case OP_SAVE_RESTORE_LIST:
  1562. break;
  1563. }
  1564. }
  1565. if (*s == 'm' || *s == '+' || *s == '-')
  1566. ++s;
  1567. }
  1568. }
  1569. return true;
  1570. }
  1571. /* Print the arguments for INSN, which is described by OPCODE.
  1572. Use DECODE_OPERAND to get the encoding of each operand. Use BASE_PC
  1573. as the base of OP_PCREL operands, adjusting by LENGTH if the OP_PCREL
  1574. operand is for a branch or jump. */
  1575. static void
  1576. print_insn_args (struct disassemble_info *info,
  1577. const struct mips_opcode *opcode,
  1578. const struct mips_operand *(*decode_operand) (const char *),
  1579. unsigned int insn, bfd_vma insn_pc, unsigned int length)
  1580. {
  1581. const fprintf_ftype infprintf = info->fprintf_func;
  1582. void *is = info->stream;
  1583. struct mips_print_arg_state state;
  1584. const struct mips_operand *operand;
  1585. const char *s;
  1586. init_print_arg_state (&state);
  1587. for (s = opcode->args; *s; ++s)
  1588. {
  1589. switch (*s)
  1590. {
  1591. case ',':
  1592. case '(':
  1593. case ')':
  1594. infprintf (is, "%c", *s);
  1595. break;
  1596. case '#':
  1597. ++s;
  1598. infprintf (is, "%c%c", *s, *s);
  1599. break;
  1600. default:
  1601. operand = decode_operand (s);
  1602. if (!operand)
  1603. {
  1604. /* xgettext:c-format */
  1605. infprintf (is,
  1606. _("# internal error, undefined operand in `%s %s'"),
  1607. opcode->name, opcode->args);
  1608. return;
  1609. }
  1610. if (operand->type == OP_SAVE_RESTORE_LIST)
  1611. {
  1612. /* Handle this case here because of the complex behavior. */
  1613. unsigned int amask = (insn >> 15) & 0xf;
  1614. unsigned int nsreg = (insn >> 23) & 0x7;
  1615. unsigned int ra = insn & 0x1000; /* $ra */
  1616. unsigned int s0 = insn & 0x800; /* $s0 */
  1617. unsigned int s1 = insn & 0x400; /* $s1 */
  1618. unsigned int frame_size = (((insn >> 15) & 0xf0)
  1619. | ((insn >> 6) & 0x0f)) * 8;
  1620. mips_print_save_restore (info, amask, nsreg, ra, s0, s1,
  1621. frame_size);
  1622. }
  1623. else if (operand->type == OP_REG
  1624. && s[1] == ','
  1625. && s[2] == 'H'
  1626. && opcode->name[strlen (opcode->name) - 1] == '0')
  1627. {
  1628. /* Coprocessor register 0 with sel field. */
  1629. const struct mips_cp0sel_name *n;
  1630. unsigned int reg, sel;
  1631. reg = mips_extract_operand (operand, insn);
  1632. s += 2;
  1633. operand = decode_operand (s);
  1634. sel = mips_extract_operand (operand, insn);
  1635. /* CP0 register including 'sel' code for mftc0, to be
  1636. printed textually if known. If not known, print both
  1637. CP0 register name and sel numerically since CP0 register
  1638. with sel 0 may have a name unrelated to register being
  1639. printed. */
  1640. n = lookup_mips_cp0sel_name (mips_cp0sel_names,
  1641. mips_cp0sel_names_len,
  1642. reg, sel);
  1643. if (n != NULL)
  1644. infprintf (is, "%s", n->name);
  1645. else
  1646. infprintf (is, "$%d,%d", reg, sel);
  1647. }
  1648. else
  1649. {
  1650. bfd_vma base_pc = insn_pc;
  1651. /* Adjust the PC relative base so that branch/jump insns use
  1652. the following PC as the base but genuinely PC relative
  1653. operands use the current PC. */
  1654. if (operand->type == OP_PCREL)
  1655. {
  1656. const struct mips_pcrel_operand *pcrel_op;
  1657. pcrel_op = (const struct mips_pcrel_operand *) operand;
  1658. /* The include_isa_bit flag is sufficient to distinguish
  1659. branch/jump from other PC relative operands. */
  1660. if (pcrel_op->include_isa_bit)
  1661. base_pc += length;
  1662. }
  1663. print_insn_arg (info, &state, opcode, operand, base_pc,
  1664. mips_extract_operand (operand, insn));
  1665. }
  1666. if (*s == 'm' || *s == '+' || *s == '-')
  1667. ++s;
  1668. break;
  1669. }
  1670. }
  1671. }
  1672. /* Print the mips instruction at address MEMADDR in debugged memory,
  1673. on using INFO. Returns length of the instruction, in bytes, which is
  1674. always INSNLEN. BIGENDIAN must be 1 if this is big-endian code, 0 if
  1675. this is little-endian code. */
  1676. static int
  1677. print_insn_mips (bfd_vma memaddr,
  1678. int word,
  1679. struct disassemble_info *info)
  1680. {
  1681. #define GET_OP(insn, field) \
  1682. (((insn) >> OP_SH_##field) & OP_MASK_##field)
  1683. static const struct mips_opcode *mips_hash[OP_MASK_OP + 1];
  1684. const fprintf_ftype infprintf = info->fprintf_func;
  1685. const struct mips_opcode *op;
  1686. static bool init = 0;
  1687. void *is = info->stream;
  1688. /* Build a hash table to shorten the search time. */
  1689. if (! init)
  1690. {
  1691. unsigned int i;
  1692. for (i = 0; i <= OP_MASK_OP; i++)
  1693. {
  1694. for (op = mips_opcodes; op < &mips_opcodes[NUMOPCODES]; op++)
  1695. {
  1696. if (op->pinfo == INSN_MACRO
  1697. || (no_aliases && (op->pinfo2 & INSN2_ALIAS)))
  1698. continue;
  1699. if (i == GET_OP (op->match, OP))
  1700. {
  1701. mips_hash[i] = op;
  1702. break;
  1703. }
  1704. }
  1705. }
  1706. init = 1;
  1707. }
  1708. info->bytes_per_chunk = INSNLEN;
  1709. info->display_endian = info->endian;
  1710. info->insn_info_valid = 1;
  1711. info->branch_delay_insns = 0;
  1712. info->data_size = 0;
  1713. info->insn_type = dis_nonbranch;
  1714. info->target = 0;
  1715. info->target2 = 0;
  1716. op = mips_hash[GET_OP (word, OP)];
  1717. if (op != NULL)
  1718. {
  1719. for (; op < &mips_opcodes[NUMOPCODES]; op++)
  1720. {
  1721. if (op->pinfo != INSN_MACRO
  1722. && !(no_aliases && (op->pinfo2 & INSN2_ALIAS))
  1723. && (word & op->mask) == op->match)
  1724. {
  1725. /* We always disassemble the jalx instruction, except for MIPS r6. */
  1726. if (!opcode_is_member (op, mips_isa, mips_ase, mips_processor)
  1727. && (strcmp (op->name, "jalx")
  1728. || (mips_isa & INSN_ISA_MASK) == ISA_MIPS32R6
  1729. || (mips_isa & INSN_ISA_MASK) == ISA_MIPS64R6))
  1730. continue;
  1731. /* Figure out instruction type and branch delay information. */
  1732. if ((op->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
  1733. {
  1734. if ((op->pinfo & (INSN_WRITE_GPR_31 | INSN_WRITE_1)) != 0)
  1735. info->insn_type = dis_jsr;
  1736. else
  1737. info->insn_type = dis_branch;
  1738. info->branch_delay_insns = 1;
  1739. }
  1740. else if ((op->pinfo & (INSN_COND_BRANCH_DELAY
  1741. | INSN_COND_BRANCH_LIKELY)) != 0)
  1742. {
  1743. if ((op->pinfo & INSN_WRITE_GPR_31) != 0)
  1744. info->insn_type = dis_condjsr;
  1745. else
  1746. info->insn_type = dis_condbranch;
  1747. info->branch_delay_insns = 1;
  1748. }
  1749. else if ((op->pinfo & (INSN_STORE_MEMORY
  1750. | INSN_LOAD_MEMORY)) != 0)
  1751. info->insn_type = dis_dref;
  1752. if (!validate_insn_args (op, decode_mips_operand, word))
  1753. continue;
  1754. infprintf (is, "%s", op->name);
  1755. if (op->pinfo2 & INSN2_VU0_CHANNEL_SUFFIX)
  1756. {
  1757. unsigned int uval;
  1758. infprintf (is, ".");
  1759. uval = mips_extract_operand (&mips_vu0_channel_mask, word);
  1760. print_vu0_channel (info, &mips_vu0_channel_mask, uval);
  1761. }
  1762. if (op->args[0])
  1763. {
  1764. infprintf (is, "\t");
  1765. print_insn_args (info, op, decode_mips_operand, word,
  1766. memaddr, 4);
  1767. }
  1768. return INSNLEN;
  1769. }
  1770. }
  1771. }
  1772. #undef GET_OP
  1773. /* Handle undefined instructions. */
  1774. info->insn_type = dis_noninsn;
  1775. infprintf (is, "0x%x", word);
  1776. return INSNLEN;
  1777. }
  1778. /* Disassemble an operand for a mips16 instruction. */
  1779. static void
  1780. print_mips16_insn_arg (struct disassemble_info *info,
  1781. struct mips_print_arg_state *state,
  1782. const struct mips_opcode *opcode,
  1783. char type, bfd_vma memaddr,
  1784. unsigned insn, bool use_extend,
  1785. unsigned extend, bool is_offset)
  1786. {
  1787. const fprintf_ftype infprintf = info->fprintf_func;
  1788. void *is = info->stream;
  1789. const struct mips_operand *operand, *ext_operand;
  1790. unsigned short ext_size;
  1791. unsigned int uval;
  1792. bfd_vma baseaddr;
  1793. if (!use_extend)
  1794. extend = 0;
  1795. switch (type)
  1796. {
  1797. case ',':
  1798. case '(':
  1799. case ')':
  1800. infprintf (is, "%c", type);
  1801. break;
  1802. default:
  1803. operand = decode_mips16_operand (type, false);
  1804. if (!operand)
  1805. {
  1806. /* xgettext:c-format */
  1807. infprintf (is, _("# internal error, undefined operand in `%s %s'"),
  1808. opcode->name, opcode->args);
  1809. return;
  1810. }
  1811. if (operand->type == OP_SAVE_RESTORE_LIST)
  1812. {
  1813. /* Handle this case here because of the complex interaction
  1814. with the EXTEND opcode. */
  1815. unsigned int amask = extend & 0xf;
  1816. unsigned int nsreg = (extend >> 8) & 0x7;
  1817. unsigned int ra = insn & 0x40; /* $ra */
  1818. unsigned int s0 = insn & 0x20; /* $s0 */
  1819. unsigned int s1 = insn & 0x10; /* $s1 */
  1820. unsigned int frame_size = ((extend & 0xf0) | (insn & 0x0f)) * 8;
  1821. if (frame_size == 0 && !use_extend)
  1822. frame_size = 128;
  1823. mips_print_save_restore (info, amask, nsreg, ra, s0, s1, frame_size);
  1824. break;
  1825. }
  1826. if (is_offset && operand->type == OP_INT)
  1827. {
  1828. const struct mips_int_operand *int_op;
  1829. int_op = (const struct mips_int_operand *) operand;
  1830. info->insn_type = dis_dref;
  1831. info->data_size = 1 << int_op->shift;
  1832. }
  1833. ext_size = 0;
  1834. if (use_extend)
  1835. {
  1836. ext_operand = decode_mips16_operand (type, true);
  1837. if (ext_operand != operand
  1838. || (operand->type == OP_INT && operand->lsb == 0
  1839. && mips_opcode_32bit_p (opcode)))
  1840. {
  1841. ext_size = ext_operand->size;
  1842. operand = ext_operand;
  1843. }
  1844. }
  1845. if (operand->size == 26)
  1846. uval = ((extend & 0x1f) << 21) | ((extend & 0x3e0) << 11) | insn;
  1847. else if (ext_size == 16 || ext_size == 9)
  1848. uval = ((extend & 0x1f) << 11) | (extend & 0x7e0) | (insn & 0x1f);
  1849. else if (ext_size == 15)
  1850. uval = ((extend & 0xf) << 11) | (extend & 0x7f0) | (insn & 0xf);
  1851. else if (ext_size == 6)
  1852. uval = ((extend >> 6) & 0x1f) | (extend & 0x20);
  1853. else
  1854. uval = mips_extract_operand (operand, (extend << 16) | insn);
  1855. if (ext_size == 9)
  1856. uval &= (1U << ext_size) - 1;
  1857. baseaddr = memaddr + 2;
  1858. if (operand->type == OP_PCREL)
  1859. {
  1860. const struct mips_pcrel_operand *pcrel_op;
  1861. pcrel_op = (const struct mips_pcrel_operand *) operand;
  1862. if (!pcrel_op->include_isa_bit && use_extend)
  1863. baseaddr = memaddr - 2;
  1864. else if (!pcrel_op->include_isa_bit)
  1865. {
  1866. bfd_byte buffer[2];
  1867. /* If this instruction is in the delay slot of a JAL/JALX
  1868. instruction, the base address is the address of the
  1869. JAL/JALX instruction. If it is in the delay slot of
  1870. a JR/JALR instruction, the base address is the address
  1871. of the JR/JALR instruction. This test is unreliable:
  1872. we have no way of knowing whether the previous word is
  1873. instruction or data. */
  1874. if (info->read_memory_func (memaddr - 4, buffer, 2, info) == 0
  1875. && (((info->endian == BFD_ENDIAN_BIG
  1876. ? bfd_getb16 (buffer)
  1877. : bfd_getl16 (buffer))
  1878. & 0xf800) == 0x1800))
  1879. baseaddr = memaddr - 4;
  1880. else if (info->read_memory_func (memaddr - 2, buffer, 2,
  1881. info) == 0
  1882. && (((info->endian == BFD_ENDIAN_BIG
  1883. ? bfd_getb16 (buffer)
  1884. : bfd_getl16 (buffer))
  1885. & 0xf89f) == 0xe800)
  1886. && (((info->endian == BFD_ENDIAN_BIG
  1887. ? bfd_getb16 (buffer)
  1888. : bfd_getl16 (buffer))
  1889. & 0x0060) != 0x0060))
  1890. baseaddr = memaddr - 2;
  1891. else
  1892. baseaddr = memaddr;
  1893. }
  1894. }
  1895. print_insn_arg (info, state, opcode, operand, baseaddr + 1, uval);
  1896. break;
  1897. }
  1898. }
  1899. /* Check if the given address is the last word of a MIPS16 PLT entry.
  1900. This word is data and depending on the value it may interfere with
  1901. disassembly of further PLT entries. We make use of the fact PLT
  1902. symbols are marked BSF_SYNTHETIC. */
  1903. static bool
  1904. is_mips16_plt_tail (struct disassemble_info *info, bfd_vma addr)
  1905. {
  1906. if (info->symbols
  1907. && info->symbols[0]
  1908. && (info->symbols[0]->flags & BSF_SYNTHETIC)
  1909. && addr == bfd_asymbol_value (info->symbols[0]) + 12)
  1910. return true;
  1911. return false;
  1912. }
  1913. /* Whether none, a 32-bit or a 16-bit instruction match has been done. */
  1914. enum match_kind
  1915. {
  1916. MATCH_NONE,
  1917. MATCH_FULL,
  1918. MATCH_SHORT
  1919. };
  1920. /* Disassemble mips16 instructions. */
  1921. static int
  1922. print_insn_mips16 (bfd_vma memaddr, struct disassemble_info *info)
  1923. {
  1924. const fprintf_ftype infprintf = info->fprintf_func;
  1925. int status;
  1926. bfd_byte buffer[4];
  1927. const struct mips_opcode *op, *opend;
  1928. struct mips_print_arg_state state;
  1929. void *is = info->stream;
  1930. bool have_second;
  1931. bool extend_only;
  1932. unsigned int second;
  1933. unsigned int first;
  1934. unsigned int full;
  1935. info->bytes_per_chunk = 2;
  1936. info->display_endian = info->endian;
  1937. info->insn_info_valid = 1;
  1938. info->branch_delay_insns = 0;
  1939. info->data_size = 0;
  1940. info->target = 0;
  1941. info->target2 = 0;
  1942. #define GET_OP(insn, field) \
  1943. (((insn) >> MIPS16OP_SH_##field) & MIPS16OP_MASK_##field)
  1944. /* Decode PLT entry's GOT slot address word. */
  1945. if (is_mips16_plt_tail (info, memaddr))
  1946. {
  1947. info->insn_type = dis_noninsn;
  1948. status = (*info->read_memory_func) (memaddr, buffer, 4, info);
  1949. if (status == 0)
  1950. {
  1951. unsigned int gotslot;
  1952. if (info->endian == BFD_ENDIAN_BIG)
  1953. gotslot = bfd_getb32 (buffer);
  1954. else
  1955. gotslot = bfd_getl32 (buffer);
  1956. infprintf (is, ".word\t0x%x", gotslot);
  1957. return 4;
  1958. }
  1959. }
  1960. else
  1961. {
  1962. info->insn_type = dis_nonbranch;
  1963. status = (*info->read_memory_func) (memaddr, buffer, 2, info);
  1964. }
  1965. if (status != 0)
  1966. {
  1967. (*info->memory_error_func) (status, memaddr, info);
  1968. return -1;
  1969. }
  1970. extend_only = false;
  1971. if (info->endian == BFD_ENDIAN_BIG)
  1972. first = bfd_getb16 (buffer);
  1973. else
  1974. first = bfd_getl16 (buffer);
  1975. status = (*info->read_memory_func) (memaddr + 2, buffer, 2, info);
  1976. if (status == 0)
  1977. {
  1978. have_second = true;
  1979. if (info->endian == BFD_ENDIAN_BIG)
  1980. second = bfd_getb16 (buffer);
  1981. else
  1982. second = bfd_getl16 (buffer);
  1983. full = (first << 16) | second;
  1984. }
  1985. else
  1986. {
  1987. have_second = false;
  1988. second = 0;
  1989. full = first;
  1990. }
  1991. /* FIXME: Should probably use a hash table on the major opcode here. */
  1992. opend = mips16_opcodes + bfd_mips16_num_opcodes;
  1993. for (op = mips16_opcodes; op < opend; op++)
  1994. {
  1995. enum match_kind match;
  1996. if (!opcode_is_member (op, mips_isa, mips_ase, mips_processor))
  1997. continue;
  1998. if (op->pinfo == INSN_MACRO
  1999. || (no_aliases && (op->pinfo2 & INSN2_ALIAS)))
  2000. match = MATCH_NONE;
  2001. else if (mips_opcode_32bit_p (op))
  2002. {
  2003. if (have_second
  2004. && (full & op->mask) == op->match)
  2005. match = MATCH_FULL;
  2006. else
  2007. match = MATCH_NONE;
  2008. }
  2009. else if ((first & op->mask) == op->match)
  2010. {
  2011. match = MATCH_SHORT;
  2012. second = 0;
  2013. full = first;
  2014. }
  2015. else if ((first & 0xf800) == 0xf000
  2016. && have_second
  2017. && !extend_only
  2018. && (second & op->mask) == op->match)
  2019. {
  2020. if (op->pinfo2 & INSN2_SHORT_ONLY)
  2021. {
  2022. match = MATCH_NONE;
  2023. extend_only = true;
  2024. }
  2025. else
  2026. match = MATCH_FULL;
  2027. }
  2028. else
  2029. match = MATCH_NONE;
  2030. if (match != MATCH_NONE)
  2031. {
  2032. const char *s;
  2033. infprintf (is, "%s", op->name);
  2034. if (op->args[0] != '\0')
  2035. infprintf (is, "\t");
  2036. init_print_arg_state (&state);
  2037. for (s = op->args; *s != '\0'; s++)
  2038. {
  2039. if (*s == ','
  2040. && s[1] == 'w'
  2041. && GET_OP (full, RX) == GET_OP (full, RY))
  2042. {
  2043. /* Skip the register and the comma. */
  2044. ++s;
  2045. continue;
  2046. }
  2047. if (*s == ','
  2048. && s[1] == 'v'
  2049. && GET_OP (full, RZ) == GET_OP (full, RX))
  2050. {
  2051. /* Skip the register and the comma. */
  2052. ++s;
  2053. continue;
  2054. }
  2055. if (s[0] == 'N'
  2056. && s[1] == ','
  2057. && s[2] == 'O'
  2058. && op->name[strlen (op->name) - 1] == '0')
  2059. {
  2060. /* Coprocessor register 0 with sel field. */
  2061. const struct mips_cp0sel_name *n;
  2062. const struct mips_operand *operand;
  2063. unsigned int reg, sel;
  2064. operand = decode_mips16_operand (*s, true);
  2065. reg = mips_extract_operand (operand, (first << 16) | second);
  2066. s += 2;
  2067. operand = decode_mips16_operand (*s, true);
  2068. sel = mips_extract_operand (operand, (first << 16) | second);
  2069. /* CP0 register including 'sel' code for mftc0, to be
  2070. printed textually if known. If not known, print both
  2071. CP0 register name and sel numerically since CP0 register
  2072. with sel 0 may have a name unrelated to register being
  2073. printed. */
  2074. n = lookup_mips_cp0sel_name (mips_cp0sel_names,
  2075. mips_cp0sel_names_len,
  2076. reg, sel);
  2077. if (n != NULL)
  2078. infprintf (is, "%s", n->name);
  2079. else
  2080. infprintf (is, "$%d,%d", reg, sel);
  2081. }
  2082. else
  2083. switch (match)
  2084. {
  2085. case MATCH_FULL:
  2086. print_mips16_insn_arg (info, &state, op, *s, memaddr + 2,
  2087. second, true, first, s[1] == '(');
  2088. break;
  2089. case MATCH_SHORT:
  2090. print_mips16_insn_arg (info, &state, op, *s, memaddr,
  2091. first, false, 0, s[1] == '(');
  2092. break;
  2093. case MATCH_NONE: /* Stop the compiler complaining. */
  2094. break;
  2095. }
  2096. }
  2097. /* Figure out branch instruction type and delay slot information. */
  2098. if ((op->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0)
  2099. info->branch_delay_insns = 1;
  2100. if ((op->pinfo & INSN_UNCOND_BRANCH_DELAY) != 0
  2101. || (op->pinfo2 & INSN2_UNCOND_BRANCH) != 0)
  2102. {
  2103. if ((op->pinfo & INSN_WRITE_GPR_31) != 0)
  2104. info->insn_type = dis_jsr;
  2105. else
  2106. info->insn_type = dis_branch;
  2107. }
  2108. else if ((op->pinfo2 & INSN2_COND_BRANCH) != 0)
  2109. info->insn_type = dis_condbranch;
  2110. return match == MATCH_FULL ? 4 : 2;
  2111. }
  2112. }
  2113. #undef GET_OP
  2114. infprintf (is, "0x%x", first);
  2115. info->insn_type = dis_noninsn;
  2116. return 2;
  2117. }
  2118. /* Disassemble microMIPS instructions. */
  2119. static int
  2120. print_insn_micromips (bfd_vma memaddr, struct disassemble_info *info)
  2121. {
  2122. const fprintf_ftype infprintf = info->fprintf_func;
  2123. const struct mips_opcode *op, *opend;
  2124. void *is = info->stream;
  2125. bfd_byte buffer[2];
  2126. unsigned int higher;
  2127. unsigned int length;
  2128. int status;
  2129. unsigned int insn;
  2130. info->bytes_per_chunk = 2;
  2131. info->display_endian = info->endian;
  2132. info->insn_info_valid = 1;
  2133. info->branch_delay_insns = 0;
  2134. info->data_size = 0;
  2135. info->insn_type = dis_nonbranch;
  2136. info->target = 0;
  2137. info->target2 = 0;
  2138. status = (*info->read_memory_func) (memaddr, buffer, 2, info);
  2139. if (status != 0)
  2140. {
  2141. (*info->memory_error_func) (status, memaddr, info);
  2142. return -1;
  2143. }
  2144. length = 2;
  2145. if (info->endian == BFD_ENDIAN_BIG)
  2146. insn = bfd_getb16 (buffer);
  2147. else
  2148. insn = bfd_getl16 (buffer);
  2149. if ((insn & 0x1c00) == 0x0000 || (insn & 0x1000) == 0x1000)
  2150. {
  2151. /* This is a 32-bit microMIPS instruction. */
  2152. higher = insn;
  2153. status = (*info->read_memory_func) (memaddr + 2, buffer, 2, info);
  2154. if (status != 0)
  2155. {
  2156. infprintf (is, "micromips 0x%x", higher);
  2157. (*info->memory_error_func) (status, memaddr + 2, info);
  2158. return -1;
  2159. }
  2160. if (info->endian == BFD_ENDIAN_BIG)
  2161. insn = bfd_getb16 (buffer);
  2162. else
  2163. insn = bfd_getl16 (buffer);
  2164. insn = insn | (higher << 16);
  2165. length += 2;
  2166. }
  2167. /* FIXME: Should probably use a hash table on the major opcode here. */
  2168. opend = micromips_opcodes + bfd_micromips_num_opcodes;
  2169. for (op = micromips_opcodes; op < opend; op++)
  2170. {
  2171. if (op->pinfo != INSN_MACRO
  2172. && !(no_aliases && (op->pinfo2 & INSN2_ALIAS))
  2173. && (insn & op->mask) == op->match
  2174. && ((length == 2 && (op->mask & 0xffff0000) == 0)
  2175. || (length == 4 && (op->mask & 0xffff0000) != 0)))
  2176. {
  2177. if (!validate_insn_args (op, decode_micromips_operand, insn))
  2178. continue;
  2179. infprintf (is, "%s", op->name);
  2180. if (op->args[0])
  2181. {
  2182. infprintf (is, "\t");
  2183. print_insn_args (info, op, decode_micromips_operand, insn,
  2184. memaddr + 1, length);
  2185. }
  2186. /* Figure out instruction type and branch delay information. */
  2187. if ((op->pinfo
  2188. & (INSN_UNCOND_BRANCH_DELAY | INSN_COND_BRANCH_DELAY)) != 0)
  2189. info->branch_delay_insns = 1;
  2190. if (((op->pinfo & INSN_UNCOND_BRANCH_DELAY)
  2191. | (op->pinfo2 & INSN2_UNCOND_BRANCH)) != 0)
  2192. {
  2193. if ((op->pinfo & (INSN_WRITE_GPR_31 | INSN_WRITE_1)) != 0)
  2194. info->insn_type = dis_jsr;
  2195. else
  2196. info->insn_type = dis_branch;
  2197. }
  2198. else if (((op->pinfo & INSN_COND_BRANCH_DELAY)
  2199. | (op->pinfo2 & INSN2_COND_BRANCH)) != 0)
  2200. {
  2201. if ((op->pinfo & INSN_WRITE_GPR_31) != 0)
  2202. info->insn_type = dis_condjsr;
  2203. else
  2204. info->insn_type = dis_condbranch;
  2205. }
  2206. else if ((op->pinfo
  2207. & (INSN_STORE_MEMORY | INSN_LOAD_MEMORY)) != 0)
  2208. info->insn_type = dis_dref;
  2209. return length;
  2210. }
  2211. }
  2212. infprintf (is, "0x%x", insn);
  2213. info->insn_type = dis_noninsn;
  2214. return length;
  2215. }
  2216. /* Return 1 if a symbol associated with the location being disassembled
  2217. indicates a compressed mode, either MIPS16 or microMIPS, according to
  2218. MICROMIPS_P. We iterate over all the symbols at the address being
  2219. considered assuming if at least one of them indicates code compression,
  2220. then such code has been genuinely produced here (other symbols could
  2221. have been derived from function symbols defined elsewhere or could
  2222. define data). Otherwise, return 0. */
  2223. static bool
  2224. is_compressed_mode_p (struct disassemble_info *info, bool micromips_p)
  2225. {
  2226. int i;
  2227. int l;
  2228. for (i = info->symtab_pos, l = i + info->num_symbols; i < l; i++)
  2229. if (((info->symtab[i])->flags & BSF_SYNTHETIC) != 0
  2230. && ((!micromips_p
  2231. && ELF_ST_IS_MIPS16 ((*info->symbols)->udata.i))
  2232. || (micromips_p
  2233. && ELF_ST_IS_MICROMIPS ((*info->symbols)->udata.i))))
  2234. return 1;
  2235. else if (bfd_asymbol_flavour (info->symtab[i]) == bfd_target_elf_flavour
  2236. && info->symtab[i]->section == info->section)
  2237. {
  2238. elf_symbol_type *symbol = (elf_symbol_type *) info->symtab[i];
  2239. if ((!micromips_p
  2240. && ELF_ST_IS_MIPS16 (symbol->internal_elf_sym.st_other))
  2241. || (micromips_p
  2242. && ELF_ST_IS_MICROMIPS (symbol->internal_elf_sym.st_other)))
  2243. return 1;
  2244. }
  2245. return 0;
  2246. }
  2247. /* In an environment where we do not know the symbol type of the
  2248. instruction we are forced to assume that the low order bit of the
  2249. instructions' address may mark it as a mips16 instruction. If we
  2250. are single stepping, or the pc is within the disassembled function,
  2251. this works. Otherwise, we need a clue. Sometimes. */
  2252. static int
  2253. _print_insn_mips (bfd_vma memaddr,
  2254. struct disassemble_info *info,
  2255. enum bfd_endian endianness)
  2256. {
  2257. bfd_byte buffer[INSNLEN];
  2258. int status;
  2259. set_default_mips_dis_options (info);
  2260. parse_mips_dis_options (info->disassembler_options);
  2261. if (info->mach == bfd_mach_mips16)
  2262. return print_insn_mips16 (memaddr, info);
  2263. if (info->mach == bfd_mach_mips_micromips)
  2264. return print_insn_micromips (memaddr, info);
  2265. #if 1
  2266. /* FIXME: If odd address, this is CLEARLY a compressed instruction. */
  2267. /* Only a few tools will work this way. */
  2268. if (memaddr & 0x01)
  2269. {
  2270. if (micromips_ase)
  2271. return print_insn_micromips (memaddr, info);
  2272. else
  2273. return print_insn_mips16 (memaddr, info);
  2274. }
  2275. #endif
  2276. #if SYMTAB_AVAILABLE
  2277. if (is_compressed_mode_p (info, true))
  2278. return print_insn_micromips (memaddr, info);
  2279. if (is_compressed_mode_p (info, false))
  2280. return print_insn_mips16 (memaddr, info);
  2281. #endif
  2282. status = (*info->read_memory_func) (memaddr, buffer, INSNLEN, info);
  2283. if (status == 0)
  2284. {
  2285. int insn;
  2286. if (endianness == BFD_ENDIAN_BIG)
  2287. insn = bfd_getb32 (buffer);
  2288. else
  2289. insn = bfd_getl32 (buffer);
  2290. return print_insn_mips (memaddr, insn, info);
  2291. }
  2292. else
  2293. {
  2294. (*info->memory_error_func) (status, memaddr, info);
  2295. return -1;
  2296. }
  2297. }
  2298. int
  2299. print_insn_big_mips (bfd_vma memaddr, struct disassemble_info *info)
  2300. {
  2301. return _print_insn_mips (memaddr, info, BFD_ENDIAN_BIG);
  2302. }
  2303. int
  2304. print_insn_little_mips (bfd_vma memaddr, struct disassemble_info *info)
  2305. {
  2306. return _print_insn_mips (memaddr, info, BFD_ENDIAN_LITTLE);
  2307. }
  2308. /* Indices into option argument vector for options accepting an argument.
  2309. Use MIPS_OPTION_ARG_NONE for options accepting no argument. */
  2310. typedef enum
  2311. {
  2312. MIPS_OPTION_ARG_NONE = -1,
  2313. MIPS_OPTION_ARG_ABI,
  2314. MIPS_OPTION_ARG_ARCH,
  2315. MIPS_OPTION_ARG_SIZE
  2316. } mips_option_arg_t;
  2317. /* Valid MIPS disassembler options. */
  2318. static struct
  2319. {
  2320. const char *name;
  2321. const char *description;
  2322. mips_option_arg_t arg;
  2323. } mips_options[] =
  2324. {
  2325. { "no-aliases", N_("Use canonical instruction forms.\n"),
  2326. MIPS_OPTION_ARG_NONE },
  2327. { "msa", N_("Recognize MSA instructions.\n"),
  2328. MIPS_OPTION_ARG_NONE },
  2329. { "virt", N_("Recognize the virtualization ASE instructions.\n"),
  2330. MIPS_OPTION_ARG_NONE },
  2331. { "xpa", N_("Recognize the eXtended Physical Address (XPA) ASE\n\
  2332. instructions.\n"),
  2333. MIPS_OPTION_ARG_NONE },
  2334. { "ginv", N_("Recognize the Global INValidate (GINV) ASE "
  2335. "instructions.\n"),
  2336. MIPS_OPTION_ARG_NONE },
  2337. { "loongson-mmi",
  2338. N_("Recognize the Loongson MultiMedia extensions "
  2339. "Instructions (MMI) ASE instructions.\n"),
  2340. MIPS_OPTION_ARG_NONE },
  2341. { "loongson-cam",
  2342. N_("Recognize the Loongson Content Address Memory (CAM) "
  2343. " instructions.\n"),
  2344. MIPS_OPTION_ARG_NONE },
  2345. { "loongson-ext",
  2346. N_("Recognize the Loongson EXTensions (EXT) "
  2347. " instructions.\n"),
  2348. MIPS_OPTION_ARG_NONE },
  2349. { "loongson-ext2",
  2350. N_("Recognize the Loongson EXTensions R2 (EXT2) "
  2351. " instructions.\n"),
  2352. MIPS_OPTION_ARG_NONE },
  2353. { "gpr-names=", N_("Print GPR names according to specified ABI.\n\
  2354. Default: based on binary being disassembled.\n"),
  2355. MIPS_OPTION_ARG_ABI },
  2356. { "fpr-names=", N_("Print FPR names according to specified ABI.\n\
  2357. Default: numeric.\n"),
  2358. MIPS_OPTION_ARG_ABI },
  2359. { "cp0-names=", N_("Print CP0 register names according to specified "
  2360. "architecture.\n\
  2361. Default: based on binary being disassembled.\n"),
  2362. MIPS_OPTION_ARG_ARCH },
  2363. { "hwr-names=", N_("Print HWR names according to specified architecture.\n\
  2364. Default: based on binary being disassembled.\n"),
  2365. MIPS_OPTION_ARG_ARCH },
  2366. { "reg-names=", N_("Print GPR and FPR names according to specified ABI.\n"),
  2367. MIPS_OPTION_ARG_ABI },
  2368. { "reg-names=", N_("Print CP0 register and HWR names according to "
  2369. "specified\n\
  2370. architecture."),
  2371. MIPS_OPTION_ARG_ARCH }
  2372. };
  2373. /* Build the structure representing valid MIPS disassembler options.
  2374. This is done dynamically for maintenance ease purpose; a static
  2375. initializer would be unreadable. */
  2376. const disasm_options_and_args_t *
  2377. disassembler_options_mips (void)
  2378. {
  2379. static disasm_options_and_args_t *opts_and_args;
  2380. if (opts_and_args == NULL)
  2381. {
  2382. size_t num_options = ARRAY_SIZE (mips_options);
  2383. size_t num_args = MIPS_OPTION_ARG_SIZE;
  2384. disasm_option_arg_t *args;
  2385. disasm_options_t *opts;
  2386. size_t i;
  2387. size_t j;
  2388. args = XNEWVEC (disasm_option_arg_t, num_args + 1);
  2389. args[MIPS_OPTION_ARG_ABI].name = "ABI";
  2390. args[MIPS_OPTION_ARG_ABI].values
  2391. = XNEWVEC (const char *, ARRAY_SIZE (mips_abi_choices) + 1);
  2392. for (i = 0; i < ARRAY_SIZE (mips_abi_choices); i++)
  2393. args[MIPS_OPTION_ARG_ABI].values[i] = mips_abi_choices[i].name;
  2394. /* The array we return must be NULL terminated. */
  2395. args[MIPS_OPTION_ARG_ABI].values[i] = NULL;
  2396. args[MIPS_OPTION_ARG_ARCH].name = "ARCH";
  2397. args[MIPS_OPTION_ARG_ARCH].values
  2398. = XNEWVEC (const char *, ARRAY_SIZE (mips_arch_choices) + 1);
  2399. for (i = 0, j = 0; i < ARRAY_SIZE (mips_arch_choices); i++)
  2400. if (*mips_arch_choices[i].name != '\0')
  2401. args[MIPS_OPTION_ARG_ARCH].values[j++] = mips_arch_choices[i].name;
  2402. /* The array we return must be NULL terminated. */
  2403. args[MIPS_OPTION_ARG_ARCH].values[j] = NULL;
  2404. /* The array we return must be NULL terminated. */
  2405. args[MIPS_OPTION_ARG_SIZE].name = NULL;
  2406. args[MIPS_OPTION_ARG_SIZE].values = NULL;
  2407. opts_and_args = XNEW (disasm_options_and_args_t);
  2408. opts_and_args->args = args;
  2409. opts = &opts_and_args->options;
  2410. opts->name = XNEWVEC (const char *, num_options + 1);
  2411. opts->description = XNEWVEC (const char *, num_options + 1);
  2412. opts->arg = XNEWVEC (const disasm_option_arg_t *, num_options + 1);
  2413. for (i = 0; i < num_options; i++)
  2414. {
  2415. opts->name[i] = mips_options[i].name;
  2416. opts->description[i] = _(mips_options[i].description);
  2417. if (mips_options[i].arg != MIPS_OPTION_ARG_NONE)
  2418. opts->arg[i] = &args[mips_options[i].arg];
  2419. else
  2420. opts->arg[i] = NULL;
  2421. }
  2422. /* The array we return must be NULL terminated. */
  2423. opts->name[i] = NULL;
  2424. opts->description[i] = NULL;
  2425. opts->arg[i] = NULL;
  2426. }
  2427. return opts_and_args;
  2428. }
  2429. void
  2430. print_mips_disassembler_options (FILE *stream)
  2431. {
  2432. const disasm_options_and_args_t *opts_and_args;
  2433. const disasm_option_arg_t *args;
  2434. const disasm_options_t *opts;
  2435. size_t max_len = 0;
  2436. size_t i;
  2437. size_t j;
  2438. opts_and_args = disassembler_options_mips ();
  2439. opts = &opts_and_args->options;
  2440. args = opts_and_args->args;
  2441. fprintf (stream, _("\n\
  2442. The following MIPS specific disassembler options are supported for use\n\
  2443. with the -M switch (multiple options should be separated by commas):\n\n"));
  2444. /* Compute the length of the longest option name. */
  2445. for (i = 0; opts->name[i] != NULL; i++)
  2446. {
  2447. size_t len = strlen (opts->name[i]);
  2448. if (opts->arg[i] != NULL)
  2449. len += strlen (opts->arg[i]->name);
  2450. if (max_len < len)
  2451. max_len = len;
  2452. }
  2453. for (i = 0, max_len++; opts->name[i] != NULL; i++)
  2454. {
  2455. fprintf (stream, " %s", opts->name[i]);
  2456. if (opts->arg[i] != NULL)
  2457. fprintf (stream, "%s", opts->arg[i]->name);
  2458. if (opts->description[i] != NULL)
  2459. {
  2460. size_t len = strlen (opts->name[i]);
  2461. if (opts->arg[i] != NULL)
  2462. len += strlen (opts->arg[i]->name);
  2463. fprintf (stream,
  2464. "%*c %s", (int) (max_len - len), ' ', opts->description[i]);
  2465. }
  2466. fprintf (stream, _("\n"));
  2467. }
  2468. for (i = 0; args[i].name != NULL; i++)
  2469. {
  2470. fprintf (stream, _("\n\
  2471. For the options above, the following values are supported for \"%s\":\n "),
  2472. args[i].name);
  2473. for (j = 0; args[i].values[j] != NULL; j++)
  2474. fprintf (stream, " %s", args[i].values[j]);
  2475. fprintf (stream, _("\n"));
  2476. }
  2477. fprintf (stream, _("\n"));
  2478. }