m68k.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366
  1. /* m68k.c All the m68020 specific stuff in one convenient, huge,
  2. slow to compile, easy to find file.
  3. Copyright (C) 1987 Free Software Foundation, Inc.
  4. This file is part of GAS, the GNU Assembler.
  5. GAS 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 1, or (at your option)
  8. any later version.
  9. GAS is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GAS; see the file COPYING. If not, write to
  15. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  16. #include <stdio.h>
  17. #include <ctype.h>
  18. #include "m68k-opcode.h"
  19. #include "as.h"
  20. #include "obstack.h"
  21. #include "frags.h"
  22. #include "struc-symbol.h"
  23. #include "flonum.h"
  24. #include "expr.h"
  25. #include "hash.h"
  26. #include "md.h"
  27. #include "m68k.h"
  28. #ifdef M_SUN
  29. /* This variable contains the value to write out at the beginning of
  30. the a.out file. The 2<<16 means that this is a 68020 file instead
  31. of an old-style 68000 file */
  32. long omagic = 2<<16|OMAGIC; /* Magic byte for header file */
  33. #else
  34. long omagic = OMAGIC;
  35. #endif
  36. /* This array holds the chars that always start a comment. If the
  37. pre-processor is disabled, these aren't very useful */
  38. char comment_chars[] = "|";
  39. /* This array holds the chars that only start a comment at the beginning of
  40. a line. If the line seems to have the form '# 123 filename'
  41. .line and .file directives will appear in the pre-processed output */
  42. /* Note that input_file.c hand checks for '#' at the beginning of the
  43. first line of the input file. This is because the compiler outputs
  44. #NO_APP at the beginning of its output. */
  45. /* Also note that '/*' will always start a comment */
  46. char line_comment_chars[] = "#";
  47. /* Chars that can be used to separate mant from exp in floating point nums */
  48. char EXP_CHARS[] = "eE";
  49. /* Chars that mean this number is a floating point constant */
  50. /* As in 0f12.456 */
  51. /* or 0d1.2345e12 */
  52. char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  53. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  54. changed in read.c . Ideally it shouldn't have to know about it at all,
  55. but nothing is ideal around here.
  56. */
  57. void fix_new();
  58. void install_operand();
  59. void install_gen_operand();
  60. /* Its an arbitrary name: This means I don't approve of it */
  61. /* See flames below */
  62. struct obstack robyn;
  63. #define TAB(x,y) (((x)<<2)+(y))
  64. #define TABTYPE(xy) ((xy) >> 2)
  65. #define BYTE 0
  66. #define SHORT 1
  67. #define LONG 2
  68. #define SZ_UNDEF 3
  69. #define BRANCH 1
  70. #define FBRANCH 2
  71. #define PCREL 3
  72. #define BCC68000 4
  73. #define DBCC 5
  74. /* BCC68000 is for patching in an extra jmp instruction for long offsets
  75. on the 68000. The 68000 doesn't support long branches with branchs */
  76. /* This table desribes how you change sizes for the various types of variable
  77. size expressions. This version only supports two kinds. */
  78. /* Note that calls to frag_var need to specify the maximum expansion needed */
  79. /* This is currently 10 bytes for DBCC */
  80. /* The fields are:
  81. How far Forward this mode will reach:
  82. How far Backward this mode will reach:
  83. How many bytes this mode will add to the size of the frag
  84. Which mode to go to if the offset won't fit in this one
  85. */
  86. relax_typeS
  87. md_relax_table[] = {
  88. { 1, 1, 0, 0 }, /* First entries aren't used */
  89. { 1, 1, 0, 0 }, /* For no good reason except */
  90. { 1, 1, 0, 0 }, /* that the VAX doesn't either */
  91. { 1, 1, 0, 0 },
  92. { (127), (-128), 0, TAB(BRANCH,SHORT)},
  93. { (2+32767), (2+-32768), 2, TAB(BRANCH,LONG) },
  94. { 0, 0, 4, 0 },
  95. { 1, 1, 0, 0 },
  96. { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE */
  97. { (2+32767), (2+-32768), 2, TAB(FBRANCH,LONG)},
  98. { 0, 0, 4, 0 },
  99. { 1, 1, 0, 0 },
  100. { 1, 1, 0, 0 }, /* PCREL doesn't come BYTE */
  101. { (2+32767), (2+-32768), 2, TAB(PCREL,LONG)},
  102. { 0, 0, 4, 0 },
  103. { 1, 1, 0, 0 },
  104. { (127), (-128), 0, TAB(BCC68000,SHORT)},
  105. { (2+32767), (2+-32768), 2, TAB(BCC68000,LONG) },
  106. { 0, 0, 6, 0 }, /* jmp long space */
  107. { 1, 1, 0, 0 },
  108. { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE */
  109. { (2+32767), (2+-32768), 2, TAB(DBCC,LONG) },
  110. { 0, 0, 10, 0 }, /* bra/jmp long space */
  111. { 1, 1, 0, 0 },
  112. };
  113. void s_data1(), s_data2(), s_even(), s_space();
  114. void float_cons();
  115. /* These are the machine dependent pseudo-ops. These are included so
  116. the assembler can work on the output from the SUN C compiler, which
  117. generates these.
  118. */
  119. /* This table describes all the machine specific pseudo-ops the assembler
  120. has to support. The fields are:
  121. pseudo-op name without dot
  122. function to call to execute this pseudo-op
  123. Integer arg to pass to the function
  124. */
  125. pseudo_typeS md_pseudo_table[] = {
  126. { "data1", s_data1, 0 },
  127. { "data2", s_data2, 0 },
  128. { "even", s_even, 0 },
  129. { "skip", s_space, 0 },
  130. { 0, 0, 0 }
  131. };
  132. /* #define isbyte(x) ((x)>=-128 && (x)<=127) */
  133. /* #define isword(x) ((x)>=-32768 && (x)<=32767) */
  134. #define issbyte(x) ((x)>=-128 && (x)<=127)
  135. #define isubyte(x) ((x)>=0 && (x)<=255)
  136. #define issword(x) ((x)>=-32768 && (x)<=32767)
  137. #define isuword(x) ((x)>=0 && (x)<=65535)
  138. #define isbyte(x) ((x)>=-128 && (x)<=255)
  139. #define isword(x) ((x)>=-32768 && (x)<=65535)
  140. #define islong(x) (1)
  141. char *input_line_pointer;
  142. /* Operands we can parse: (And associated modes)
  143. numb: 8 bit num
  144. numw: 16 bit num
  145. numl: 32 bit num
  146. dreg: data reg 0-7
  147. reg: address or data register
  148. areg: address register
  149. apc: address register, PC, ZPC or empty string
  150. num: 16 or 32 bit num
  151. num2: like num
  152. sz: w or l if omitted, l assumed
  153. scale: 1 2 4 or 8 if omitted, 1 assumed
  154. 7.4 IMMED #num --> NUM
  155. 0.? DREG dreg --> dreg
  156. 1.? AREG areg --> areg
  157. 2.? AINDR areg@ --> *(areg)
  158. 3.? AINC areg@+ --> *(areg++)
  159. 4.? ADEC areg@- --> *(--areg)
  160. 5.? AOFF apc@(numw) --> *(apc+numw) -- empty string and ZPC not allowed here
  161. 6.? AINDX apc@(num,reg:sz:scale) --> *(apc+num+reg*scale)
  162. 6.? AINDX apc@(reg:sz:scale) --> same, with num=0
  163. 6.? APODX apc@(num)@(num2,reg:sz:scale) --> *(*(apc+num)+num2+reg*scale)
  164. 6.? APODX apc@(num)@(reg:sz:scale) --> same, with num2=0
  165. 6.? AMIND apc@(num)@(num2) --> *(*(apc+num)+num2) (previous mode without an index reg)
  166. 6.? APRDX apc@(num,reg:sz:scale)@(num2) --> *(*(apc+num+reg*scale)+num2)
  167. 6.? APRDX apc@(reg:sz:scale)@(num2) --> same, with num=0
  168. 7.0 ABSL num:sz --> *(num)
  169. num --> *(num) (sz L assumed)
  170. *** MSCR otherreg --> Magic
  171. With -l option
  172. 5.? AOFF apc@(num) --> *(apc+num) -- empty string and ZPC not allowed here still
  173. examples:
  174. #foo #0x35 #12
  175. d2
  176. a4
  177. a3@
  178. a5@+
  179. a6@-
  180. a2@(12) pc@(14)
  181. a1@(5,d2:w:1) @(45,d6:l:4)
  182. pc@(a2) @(d4)
  183. etc . . .
  184. #name@(numw) -->turn into PC rel mode
  185. apc@(num8,reg:sz:scale) --> *(apc+num8+reg*scale)
  186. */
  187. #define IMMED 1
  188. #define DREG 2
  189. #define AREG 3
  190. #define AINDR 4
  191. #define ADEC 5
  192. #define AINC 6
  193. #define AOFF 7
  194. #define AINDX 8
  195. #define APODX 9
  196. #define AMIND 10
  197. #define APRDX 11
  198. #define ABSL 12
  199. #define MSCR 13
  200. #define REGLST 14
  201. #define FAIL 0
  202. #define OK 1
  203. /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
  204. 8-15==addr reg for operands that take both types */
  205. #define DATA 1 /* 1- 8 == data registers 0-7 */
  206. #define ADDR (DATA+8) /* 9-16 == address regs 0-7 */
  207. #define FPREG (ADDR+8) /* 17-24 Eight FP registers */
  208. #define COPNUM (FPREG+8) /* 25-32 Co-processor #1-#8 */
  209. #define PC (COPNUM+8) /* 33 Program counter */
  210. #define ZPC (PC+1) /* 34 Hack for Program space, but 0 addressing */
  211. #define SR (ZPC+1) /* 35 Status Reg */
  212. #define CCR (SR+1) /* 36 Condition code Reg */
  213. /* These have to be in order for the movec instruction to work. */
  214. #define USP (CCR+1) /* 37 User Stack Pointer */
  215. #define ISP (USP+1) /* 38 Interrupt stack pointer */
  216. #define SFC (ISP+1) /* 39 */
  217. #define DFC (SFC+1) /* 40 */
  218. #define CACR (DFC+1) /* 41 */
  219. #define VBR (CACR+1) /* 42 */
  220. #define CAAR (VBR+1) /* 43 */
  221. #define MSP (CAAR+1) /* 44 */
  222. #define FPI (MSP+1) /* 45 */
  223. #define FPS (FPI+1) /* 46 */
  224. #define FPC (FPS+1) /* 47 */
  225. /*
  226. * these defines should be in m68k.c but
  227. * i put them here to keep all the m68851 stuff
  228. * together -rab
  229. * JF--Make sure these #s don't clash with the ones in m68k.c
  230. * That would be BAD.
  231. */
  232. #define TC (FPC+1) /* 48 */
  233. #define DRP (TC+1) /* 49 */
  234. #define SRP (DRP+1) /* 50 */
  235. #define CRP (SRP+1) /* 51 */
  236. #define CAL (CRP+1) /* 52 */
  237. #define VAL (CAL+1) /* 53 */
  238. #define SCC (VAL+1) /* 54 */
  239. #define AC (SCC+1) /* 55 */
  240. #define BAD (AC+1) /* 56,57,58,59, 60,61,62,63 */
  241. #define BAC (BAD+8) /* 64,65,66,67, 68,69,70,71 */
  242. #define PSR (BAC+8) /* 72 */
  243. #define PCSR (PSR+1) /* 73 */
  244. /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
  245. /* I think. . . */
  246. #define SP ADDR+7
  247. /* JF these tables here are for speed at the expense of size */
  248. /* You can replace them with the #if 0 versions if you really
  249. need space and don't mind it running a bit slower */
  250. static char mklower_table[256];
  251. #define mklower(c) (mklower_table[(unsigned char)(c)])
  252. static char notend_table[256];
  253. static char alt_notend_table[256];
  254. #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
  255. alt_notend_table[(unsigned char)(s[1])])))
  256. #if 0
  257. #define mklower(c) (isupper(c) ? tolower(c) : c)
  258. #endif
  259. struct m68k_exp {
  260. char *e_beg;
  261. char *e_end;
  262. expressionS e_exp;
  263. short e_siz; /* 0== default 1==short/byte 2==word 3==long */
  264. };
  265. /* Internal form of an operand. */
  266. struct m68k_op {
  267. char *error; /* Couldn't parse it */
  268. int mode; /* What mode this instruction is in. */
  269. unsigned long int reg; /* Base register */
  270. struct m68k_exp *con1;
  271. int ireg; /* Index register */
  272. int isiz; /* 0==unspec 1==byte(?) 2==short 3==long */
  273. int imul; /* Multipy ireg by this (1,2,4,or 8) */
  274. struct m68k_exp *con2;
  275. };
  276. /* internal form of a 68020 instruction */
  277. struct m68_it {
  278. char *error;
  279. char *args; /* list of opcode info */
  280. int numargs;
  281. int numo; /* Number of shorts in opcode */
  282. short opcode[11];
  283. struct m68k_op operands[6];
  284. int nexp; /* number of exprs in use */
  285. struct m68k_exp exprs[4];
  286. int nfrag; /* Number of frags we have to produce */
  287. struct {
  288. int fragoff; /* Where in the current opcode[] the frag ends */
  289. symbolS *fadd;
  290. long int foff;
  291. int fragty;
  292. } fragb[4];
  293. int nrel; /* Num of reloc strucs in use */
  294. struct {
  295. int n;
  296. symbolS *add,
  297. *sub;
  298. long int off;
  299. char wid;
  300. char pcrel;
  301. } reloc[5]; /* Five is enough??? */
  302. };
  303. struct m68_it the_ins; /* the instruction being assembled */
  304. /* Macros for adding things to the m68_it struct */
  305. #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
  306. /* Like addword, but goes BEFORE general operands */
  307. #define insop(w) {int z;\
  308. for(z=the_ins.numo;z>opcode->m_codenum;--z)\
  309. the_ins.opcode[z]=the_ins.opcode[z-1];\
  310. for(z=0;z<the_ins.nrel;z++)\
  311. the_ins.reloc[z].n+=2;\
  312. the_ins.opcode[opcode->m_codenum]=w;\
  313. the_ins.numo++;\
  314. }
  315. #define add_exp(beg,end) (\
  316. the_ins.exprs[the_ins.nexp].e_beg=beg,\
  317. the_ins.exprs[the_ins.nexp].e_end=end,\
  318. &the_ins.exprs[the_ins.nexp++]\
  319. )
  320. /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
  321. #define add_fix(width,exp,pc_rel) {\
  322. the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
  323. (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
  324. the_ins.reloc[the_ins.nrel].add=adds((exp));\
  325. the_ins.reloc[the_ins.nrel].sub=subs((exp));\
  326. the_ins.reloc[the_ins.nrel].off=offs((exp));\
  327. the_ins.reloc[the_ins.nrel].wid=width;\
  328. the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
  329. }
  330. #define add_frag(add,off,type) {\
  331. the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
  332. the_ins.fragb[the_ins.nfrag].fadd=add;\
  333. the_ins.fragb[the_ins.nfrag].foff=off;\
  334. the_ins.fragb[the_ins.nfrag++].fragty=type;\
  335. }
  336. #define isvar(exp) ((exp) && (adds(exp) || subs(exp)))
  337. #define seg(exp) ((exp)->e_exp.X_seg)
  338. #define adds(exp) ((exp)->e_exp.X_add_symbol)
  339. #define subs(exp) ((exp)->e_exp.X_subtract_symbol)
  340. #define offs(exp) ((exp)->e_exp.X_add_number)
  341. struct m68_incant {
  342. char *m_operands;
  343. unsigned long m_opcode;
  344. short m_opnum;
  345. short m_codenum;
  346. struct m68_incant *m_next;
  347. };
  348. #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
  349. #define gettwo(x) (((x)->m_opcode)&0xffff)
  350. /* JF modified this to handle cases where the first part of a symbol name
  351. looks like a register */
  352. int
  353. m68k_reg_parse(ccp)
  354. register char **ccp;
  355. {
  356. register char c1,
  357. c2,
  358. c3,
  359. c4;
  360. register int n = 0,
  361. ret;
  362. c1=mklower(ccp[0][0]);
  363. c2=mklower(ccp[0][1]);
  364. c3=mklower(ccp[0][2]);
  365. c4=mklower(ccp[0][3]);
  366. switch(c1) {
  367. case 'a':
  368. if(c2>='0' && c2<='7') {
  369. n=2;
  370. ret=ADDR+c2-'0';
  371. }
  372. #ifdef m68851
  373. else if (c2 == 'c') {
  374. n = 2;
  375. ret = AC;
  376. }
  377. #endif
  378. break;
  379. #ifdef m68851
  380. case 'b':
  381. if (c2 == 'a') {
  382. if (c3 == 'd') {
  383. if (c4 >= '0' && c4 <= '7') {
  384. n = 4;
  385. ret = BAD + c4 - '0';
  386. }
  387. }
  388. if (c3 == 'c') {
  389. if (c4 >= '0' && c4 <= '7') {
  390. n = 4;
  391. ret = BAC + c4 - '0';
  392. }
  393. }
  394. }
  395. break;
  396. #endif
  397. case 'c':
  398. #ifdef m68851
  399. if (c2 == 'a' && c3 == 'l') {
  400. n = 3;
  401. ret = CAL;
  402. } else
  403. #endif
  404. /* This supports both CCR and CC as the ccr reg. */
  405. if(c2=='c' && c3=='r') {
  406. n=3;
  407. ret = CCR;
  408. } else if(c2=='c') {
  409. n=2;
  410. ret = CCR;
  411. } else if(c2=='a' && (c3=='a' || c3=='c') && c4=='r') {
  412. n=4;
  413. ret = c3=='a' ? CAAR : CACR;
  414. }
  415. #ifdef m68851
  416. else if (c2 == 'r' && c3 == 'p') {
  417. n = 3;
  418. ret = (CRP);
  419. }
  420. #endif
  421. break;
  422. case 'd':
  423. if(c2>='0' && c2<='7') {
  424. n=2;
  425. ret = DATA+c2-'0';
  426. } else if(c2=='f' && c3=='c') {
  427. n=3;
  428. ret = DFC;
  429. }
  430. #ifdef m68851
  431. else if (c2 == 'r' && c3 == 'p') {
  432. n = 3;
  433. ret = (DRP);
  434. }
  435. #endif
  436. break;
  437. case 'f':
  438. if(c2=='p') {
  439. if(c3>='0' && c3<='7') {
  440. n=3;
  441. ret = FPREG+c3-'0';
  442. } else if(c3=='i') {
  443. n=3;
  444. ret = FPI;
  445. } else if(c3=='s') {
  446. n= (c4 == 'r' ? 4 : 3);
  447. ret = FPS;
  448. } else if(c3=='c') {
  449. n= (c4 == 'r' ? 4 : 3);
  450. ret = FPC;
  451. }
  452. }
  453. break;
  454. case 'i':
  455. if(c2=='s' && c3=='p') {
  456. n=3;
  457. ret = ISP;
  458. }
  459. break;
  460. case 'm':
  461. if(c2=='s' && c3=='p') {
  462. n=3;
  463. ret = MSP;
  464. }
  465. break;
  466. case 'p':
  467. if(c2=='c') {
  468. #ifdef m68851
  469. if(c3 == 's' && c4=='r') {
  470. n=4;
  471. ret = (PCSR);
  472. } else
  473. #endif
  474. {
  475. n=2;
  476. ret = PC;
  477. }
  478. }
  479. #ifdef m68851
  480. else if (c2 == 's' && c3 == 'r') {
  481. n = 3;
  482. ret = (PSR);
  483. }
  484. #endif
  485. break;
  486. case 's':
  487. #ifdef m68851
  488. if (c2 == 'c' && c3 == 'c') {
  489. n = 3;
  490. ret = (SCC);
  491. } else if (c2 == 'r' && c3 == 'p') {
  492. n = 3;
  493. ret = (SRP);
  494. } else
  495. #endif
  496. if(c2=='r') {
  497. n=2;
  498. ret = SR;
  499. } else if(c2=='p') {
  500. n=2;
  501. ret = ADDR+7;
  502. } else if(c2=='f' && c3=='c') {
  503. n=3;
  504. ret = SFC;
  505. }
  506. break;
  507. #ifdef m68851
  508. case 't':
  509. if(c2 == 'c') {
  510. n=2;
  511. ret=TC;
  512. }
  513. break;
  514. #endif
  515. case 'u':
  516. if(c2=='s' && c3=='p') {
  517. n=3;
  518. ret = USP;
  519. }
  520. break;
  521. case 'v':
  522. #ifdef m68851
  523. if (c2 == 'a' && c3 == 'l') {
  524. n = 3;
  525. ret = (VAL);
  526. } else
  527. #endif
  528. if(c2=='b' && c3=='r') {
  529. n=3;
  530. ret = VBR;
  531. }
  532. break;
  533. case 'z':
  534. if(c2=='p' && c3=='c') {
  535. n=3;
  536. ret = ZPC;
  537. }
  538. break;
  539. default:
  540. break;
  541. }
  542. if(n) {
  543. if(isalnum(ccp[0][n]) || ccp[0][n]=='_')
  544. ret=FAIL;
  545. else
  546. ccp[0]+=n;
  547. } else
  548. ret = FAIL;
  549. return ret;
  550. }
  551. #define SKIP_WHITE() { str++; if(*str==' ') str++;}
  552. int
  553. m68k_ip_op(str,opP)
  554. char *str;
  555. register struct m68k_op *opP;
  556. {
  557. char *strend;
  558. long i;
  559. char *parse_index();
  560. if(*str==' ')
  561. str++;
  562. /* Find the end of the string */
  563. if(!*str) {
  564. /* Out of gas */
  565. opP->error="Missing operand";
  566. return FAIL;
  567. }
  568. for(strend=str;*strend;strend++)
  569. ;
  570. --strend;
  571. /* Guess what: A constant. Shar and enjoy */
  572. if(*str=='#') {
  573. str++;
  574. opP->con1=add_exp(str,strend);
  575. opP->mode=IMMED;
  576. return OK;
  577. }
  578. i=m68k_reg_parse(&str);
  579. if((i==FAIL || *str!='\0') && *str!='@') {
  580. char *stmp;
  581. char *index();
  582. if(i!=FAIL && (*str=='/' || *str=='-')) {
  583. opP->mode=REGLST;
  584. return get_regs(i,str,opP);
  585. }
  586. if(stmp=index(str,'@')) {
  587. opP->con1=add_exp(str,stmp-1);
  588. if(stmp==strend) {
  589. opP->mode=AINDX;
  590. return OK;
  591. }
  592. stmp++;
  593. if(*stmp++!='(' || *strend--!=')') {
  594. opP->error="Malformed operand";
  595. return FAIL;
  596. }
  597. i=try_index(&stmp,opP);
  598. opP->con2=add_exp(stmp,strend);
  599. if(i==FAIL) opP->mode=AMIND;
  600. else opP->mode=APODX;
  601. return OK;
  602. }
  603. opP->mode=ABSL;
  604. if(strend[-1]==':') { /* mode ==foo:[wl] */
  605. switch(*strend) {
  606. case 'w':
  607. case 'W':
  608. opP->isiz=2;
  609. break;
  610. case 'l':
  611. case 'L':
  612. opP->isiz=3;
  613. break;
  614. default:
  615. opP->error="size spec not :w or :l";
  616. return FAIL;
  617. }
  618. strend-=2;
  619. } else {
  620. opP->isiz=0;
  621. }
  622. opP->con1=add_exp(str,strend);
  623. return OK;
  624. }
  625. opP->reg=i;
  626. if(*str=='\0') {
  627. if(i>=DATA+0 && i<=DATA+7)
  628. opP->mode=DREG;
  629. else if(i>=ADDR+0 && i<=ADDR+7)
  630. opP->mode=AREG;
  631. else
  632. opP->mode=MSCR;
  633. return OK;
  634. }
  635. if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC && i!=FAIL) { /* Can't indirect off non address regs */
  636. opP->error="Invalid indirect register";
  637. return FAIL;
  638. }
  639. if(*str!='@')
  640. abort();
  641. str++;
  642. switch(*str) {
  643. case '\0':
  644. opP->mode=AINDR;
  645. return OK;
  646. case '-':
  647. opP->mode=ADEC;
  648. return OK;
  649. case '+':
  650. opP->mode=AINC;
  651. return OK;
  652. case '(':
  653. str++;
  654. break;
  655. default:
  656. opP->error="Junk after indirect";
  657. return FAIL;
  658. }
  659. /* Some kind of indexing involved. Lets find out how bad it is */
  660. i=try_index(&str,opP);
  661. /* Didn't start with an index reg, maybe its offset or offset,reg */
  662. if(i==FAIL) {
  663. char *beg_str;
  664. beg_str=str;
  665. for(i=1;i;) {
  666. switch(*str++) {
  667. case '\0':
  668. opP->error="Missing )";
  669. return FAIL;
  670. case ',': i=0; break;
  671. case '(': i++; break;
  672. case ')': --i; break;
  673. }
  674. }
  675. opP->con1=add_exp(beg_str,str-2);
  676. /* Should be offset,reg */
  677. if(str[-1]==',') {
  678. i=try_index(&str,opP);
  679. if(i==FAIL) {
  680. opP->error="Malformed index reg";
  681. return FAIL;
  682. }
  683. }
  684. }
  685. /* We've now got offset) offset,reg) or reg) */
  686. if(*str=='\0') {
  687. /* Th-the-thats all folks */
  688. if(opP->reg==FAIL) opP->mode=AINDX; /* Other form of indirect */
  689. else if(opP->ireg==FAIL) opP->mode=AOFF;
  690. else opP->mode=AINDX;
  691. return OK;
  692. }
  693. /* Next thing had better be another @ */
  694. if(*str!='@' || str[1]!='(') {
  695. opP->error="junk after indirect";
  696. return FAIL;
  697. }
  698. str+=2;
  699. if(opP->ireg!=FAIL) {
  700. opP->mode=APRDX;
  701. i=try_index(&str,opP);
  702. if(i!=FAIL) {
  703. opP->error="Two index registers! not allowed!";
  704. return FAIL;
  705. }
  706. } else
  707. i=try_index(&str,opP);
  708. if(i==FAIL) {
  709. char *beg_str;
  710. beg_str=str;
  711. for(i=1;i;) {
  712. switch(*str++) {
  713. case '\0':
  714. opP->error="Missing )";
  715. return FAIL;
  716. case ',': i=0; break;
  717. case '(': i++; break;
  718. case ')': --i; break;
  719. }
  720. }
  721. opP->con2=add_exp(beg_str,str-2);
  722. if(str[-1]==',') {
  723. if(opP->ireg!=FAIL) {
  724. opP->error="Can't have two index regs";
  725. return FAIL;
  726. }
  727. i=try_index(&str,opP);
  728. if(i==FAIL) {
  729. opP->error="malformed index reg";
  730. return FAIL;
  731. }
  732. opP->mode=APODX;
  733. } else if(opP->ireg!=FAIL)
  734. opP->mode=APRDX;
  735. else
  736. opP->mode=AMIND;
  737. } else
  738. opP->mode=APODX;
  739. if(*str!='\0') {
  740. opP->error="Junk after indirect";
  741. return FAIL;
  742. }
  743. return OK;
  744. }
  745. int
  746. try_index(s,opP)
  747. char **s;
  748. struct m68k_op *opP;
  749. {
  750. register int i;
  751. char *ss;
  752. #define SKIP_W() { ss++; if(*ss==' ') ss++;}
  753. ss= *s;
  754. /* SKIP_W(); */
  755. i=m68k_reg_parse(&ss);
  756. if(!(i>=DATA+0 && i<=ADDR+7)) { /* if i is not DATA or ADDR reg */
  757. *s=ss;
  758. return FAIL;
  759. }
  760. opP->ireg=i;
  761. /* SKIP_W(); */
  762. if(*ss==')') {
  763. opP->isiz=0;
  764. opP->imul=1;
  765. SKIP_W();
  766. *s=ss;
  767. return OK;
  768. }
  769. if(*ss!=':') {
  770. opP->error="Missing : in index register";
  771. *s=ss;
  772. return FAIL;
  773. }
  774. SKIP_W();
  775. if(mklower(*ss)=='w') opP->isiz=2;
  776. else if(mklower(*ss)=='l') opP->isiz=3;
  777. else {
  778. opP->error="Size spec not :w or :l";
  779. *s=ss;
  780. return FAIL;
  781. }
  782. SKIP_W();
  783. if(*ss==':') {
  784. SKIP_W();
  785. switch(*ss) {
  786. case '1':
  787. case '2':
  788. case '4':
  789. case '8':
  790. opP->imul= *ss-'0';
  791. break;
  792. default:
  793. opP->error="index multiplier not 1, 2, 4 or 8";
  794. *s=ss;
  795. return FAIL;
  796. }
  797. SKIP_W();
  798. } else opP->imul=1;
  799. if(*ss!=')') {
  800. opP->error="Missing )";
  801. *s=ss;
  802. return FAIL;
  803. }
  804. SKIP_W();
  805. *s=ss;
  806. return OK;
  807. }
  808. #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
  809. main()
  810. {
  811. char buf[128];
  812. struct m68k_op thark;
  813. for(;;) {
  814. if(!gets(buf))
  815. break;
  816. bzero(&thark,sizeof(thark));
  817. if(!m68k_ip_op(buf,&thark)) printf("FAIL:");
  818. if(thark.error)
  819. printf("op1 error %s in %s\n",thark.error,buf);
  820. printf("mode %d, reg %d, ",thark.mode,thark.reg);
  821. if(thark.b_const)
  822. printf("Constant: '%.*s',",1+thark.e_const-thark.b_const,thark.b_const);
  823. printf("ireg %d, isiz %d, imul %d ",thark.ireg,thark.isiz,thark.imul);
  824. if(thark.b_iadd)
  825. printf("Iadd: '%.*s'",1+thark.e_iadd-thark.b_iadd,thark.b_iadd);
  826. printf("\n");
  827. }
  828. exit(0);
  829. }
  830. #endif
  831. static struct hash_control* op_hash = NULL; /* handle of the OPCODE hash table
  832. NULL means any use before m68_ip_begin()
  833. will crash */
  834. /*
  835. * m 6 8 _ i p ( )
  836. *
  837. * This converts a string into a 68k instruction.
  838. * The string must be a bare single instruction in sun format
  839. * with RMS-style 68020 indirects
  840. * (example: )
  841. *
  842. * It provides some error messages: at most one fatal error message (which
  843. * stops the scan) and at most one warning message for each operand.
  844. * The 68k instruction is returned in exploded form, since we have no
  845. * knowledge of how you parse (or evaluate) your expressions.
  846. * We do however strip off and decode addressing modes and operation
  847. * mnemonic.
  848. *
  849. * This function's value is a string. If it is not "" then an internal
  850. * logic error was found: read this code to assign meaning to the string.
  851. * No argument string should generate such an error string:
  852. * it means a bug in our code, not in the user's text.
  853. *
  854. * You MUST have called m86_ip_begin() once and m86_ip_end() never before using
  855. * this function.
  856. */
  857. /* JF this function no longer returns a useful value. Sorry */
  858. void
  859. m68_ip (instring)
  860. char *instring;
  861. {
  862. register char *p;
  863. register struct m68k_op *opP;
  864. register struct m68_incant *opcode;
  865. register char *s;
  866. register int tmpreg,
  867. baseo,
  868. outro,
  869. nextword;
  870. int siz1,
  871. siz2;
  872. char c;
  873. int losing;
  874. int opsfound;
  875. char *crack_operand();
  876. char *atof_m68k();
  877. LITTLENUM_TYPE words[6];
  878. LITTLENUM_TYPE *wordp;
  879. if (*instring == ' ')
  880. instring++; /* skip leading whitespace */
  881. /* Scan up to end of operation-code, which MUST end in end-of-string
  882. or exactly 1 space. */
  883. for (p = instring; *p != '\0'; p++)
  884. if (*p == ' ')
  885. break;
  886. if (p == instring) {
  887. the_ins.error = "No operator";
  888. the_ins.opcode[0] = NULL;
  889. /* the_ins.numo=1; */
  890. return;
  891. }
  892. /* p now points to the end of the opcode name, probably whitespace.
  893. make sure the name is null terminated by clobbering the whitespace,
  894. look it up in the hash table, then fix it back. */
  895. c = *p;
  896. *p = '\0';
  897. opcode = (struct m68_incant *)hash_find (op_hash, instring);
  898. *p = c;
  899. if (opcode == NULL) {
  900. the_ins.error = "Unknown operator";
  901. the_ins.opcode[0] = NULL;
  902. /* the_ins.numo=1; */
  903. return;
  904. }
  905. /* found a legitimate opcode, start matching operands */
  906. for(opP= &the_ins.operands[0];*p;opP++) {
  907. p = crack_operand (p, opP);
  908. if(opP->error) {
  909. the_ins.error=opP->error;
  910. return;
  911. }
  912. }
  913. opsfound=opP- &the_ins.operands[0];
  914. /* This ugly hack is to support the floating pt opcodes in their standard form */
  915. /* Essentially, we fake a first enty of type COP#1 */
  916. if(opcode->m_operands[0]=='I') {
  917. int n;
  918. for(n=opsfound;n>0;--n)
  919. the_ins.operands[n]=the_ins.operands[n-1];
  920. /* bcopy((char *)(&the_ins.operands[0]),(char *)(&the_ins.operands[1]),opsfound*sizeof(the_ins.operands[0])); */
  921. bzero((char *)(&the_ins.operands[0]),sizeof(the_ins.operands[0]));
  922. the_ins.operands[0].mode=MSCR;
  923. the_ins.operands[0].reg=COPNUM; /* COP #1 */
  924. opsfound++;
  925. }
  926. /* We've got the operands. Find an opcode that'll
  927. accept them */
  928. for(losing=0;;) {
  929. if(opsfound!=opcode->m_opnum)
  930. losing++;
  931. else for(s=opcode->m_operands,opP= &the_ins.operands[0];*s && !losing;s+=2,opP++) {
  932. /* Warning: this switch is huge! */
  933. /* I've tried to organize the cases into this order:
  934. non-alpha first, then alpha by letter. lower-case goes directly
  935. before uppercase counterpart. */
  936. /* Code with multiple case ...: gets sorted by the lowest case ...
  937. it belongs to. I hope this makes sense. */
  938. switch(*s) {
  939. case '!':
  940. if(opP->mode==MSCR || opP->mode==IMMED ||
  941. opP->mode==DREG || opP->mode==AREG || opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  942. losing++;
  943. break;
  944. case '#':
  945. if(opP->mode!=IMMED)
  946. losing++;
  947. else {
  948. long t;
  949. t=get_num(opP->con1,80);
  950. if(s[1]=='b' && !isbyte(t))
  951. losing++;
  952. else if(s[1]=='w' && !isword(t))
  953. losing++;
  954. }
  955. break;
  956. case '^':
  957. case 'T':
  958. if(opP->mode!=IMMED)
  959. losing++;
  960. break;
  961. case '$':
  962. if(opP->mode==MSCR || opP->mode==AREG ||
  963. opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  964. losing++;
  965. break;
  966. case '%':
  967. if(opP->mode==MSCR || opP->reg==PC ||
  968. opP->reg==ZPC || opP->mode==REGLST)
  969. losing++;
  970. break;
  971. case '&':
  972. if(opP->mode==MSCR || opP->mode==DREG ||
  973. opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC ||
  974. opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  975. losing++;
  976. break;
  977. case '*':
  978. if(opP->mode==MSCR || opP->mode==REGLST)
  979. losing++;
  980. break;
  981. case '+':
  982. if(opP->mode!=AINC)
  983. losing++;
  984. break;
  985. case '-':
  986. if(opP->mode!=ADEC)
  987. losing++;
  988. break;
  989. case '/':
  990. if(opP->mode==MSCR || opP->mode==AREG ||
  991. opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->mode==REGLST)
  992. losing++;
  993. break;
  994. case ';':
  995. if(opP->mode==MSCR || opP->mode==AREG || opP->mode==REGLST)
  996. losing++;
  997. break;
  998. case '?':
  999. if(opP->mode==MSCR || opP->mode==AREG ||
  1000. opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->reg==PC ||
  1001. opP->reg==ZPC || opP->mode==REGLST)
  1002. losing++;
  1003. break;
  1004. case '@':
  1005. if(opP->mode==MSCR || opP->mode==AREG ||
  1006. opP->mode==IMMED || opP->mode==REGLST)
  1007. losing++;
  1008. break;
  1009. case '~': /* For now! (JF FOO is this right?) */
  1010. if(opP->mode==MSCR || opP->mode==DREG ||
  1011. opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1012. losing++;
  1013. break;
  1014. case 'A':
  1015. if(opP->mode!=AREG)
  1016. losing++;
  1017. break;
  1018. case 'B': /* FOO */
  1019. if(opP->mode!=ABSL)
  1020. losing++;
  1021. break;
  1022. case 'C':
  1023. if(opP->mode!=MSCR || opP->reg!=CCR)
  1024. losing++;
  1025. break;
  1026. case 'd': /* FOO This mode is a KLUDGE!! */
  1027. if(opP->mode!=AOFF && (opP->mode!=ABSL ||
  1028. opP->con1->e_beg[0]!='(' || opP->con1->e_end[0]!=')'))
  1029. losing++;
  1030. break;
  1031. case 'D':
  1032. if(opP->mode!=DREG)
  1033. losing++;
  1034. break;
  1035. case 'F':
  1036. if(opP->mode!=MSCR || opP->reg<(FPREG+0) || opP->reg>(FPREG+7))
  1037. losing++;
  1038. break;
  1039. case 'I':
  1040. if(opP->mode!=MSCR || opP->reg<COPNUM ||
  1041. opP->reg>=COPNUM+7)
  1042. losing++;
  1043. break;
  1044. case 'J':
  1045. if(opP->mode!=MSCR || opP->reg<USP || opP->reg>MSP)
  1046. losing++;
  1047. break;
  1048. case 'k':
  1049. if(opP->mode!=IMMED)
  1050. losing++;
  1051. break;
  1052. case 'l':
  1053. case 'L':
  1054. if(opP->mode==DREG || opP->mode==AREG || opP->mode==FPREG) {
  1055. if(s[1]=='8')
  1056. losing++;
  1057. else {
  1058. opP->mode=REGLST;
  1059. opP->reg=1<<(opP->reg-DATA);
  1060. }
  1061. } else if(opP->mode!=REGLST) {
  1062. losing++;
  1063. } else if(s[1]=='8' && opP->reg&0x0FFffFF)
  1064. losing++;
  1065. else if(s[1]=='3' && opP->reg&0x7000000)
  1066. losing++;
  1067. break;
  1068. case 'M':
  1069. if(opP->mode!=IMMED)
  1070. losing++;
  1071. else {
  1072. long t;
  1073. t=get_num(opP->con1,80);
  1074. if(!issbyte(t) || isvar(opP->con1))
  1075. losing++;
  1076. }
  1077. break;
  1078. case 'O':
  1079. if(opP->mode!=DREG && opP->mode!=IMMED)
  1080. losing++;
  1081. break;
  1082. case 'Q':
  1083. if(opP->mode!=IMMED)
  1084. losing++;
  1085. else {
  1086. long t;
  1087. t=get_num(opP->con1,80);
  1088. if(t<1 || t>8 || isvar(opP->con1))
  1089. losing++;
  1090. }
  1091. break;
  1092. case 'R':
  1093. if(opP->mode!=DREG && opP->mode!=AREG)
  1094. losing++;
  1095. break;
  1096. case 's':
  1097. if(opP->mode!=MSCR || !(opP->reg==FPI || opP->reg==FPS || opP->reg==FPC))
  1098. losing++;
  1099. break;
  1100. case 'S':
  1101. if(opP->mode!=MSCR || opP->reg!=SR)
  1102. losing++;
  1103. break;
  1104. case 'U':
  1105. if(opP->mode!=MSCR || opP->reg!=USP)
  1106. losing++;
  1107. break;
  1108. /* JF these are out of order. We could put them
  1109. in order if we were willing to put up with
  1110. bunches of #ifdef m68851s in the code */
  1111. #ifdef m68851
  1112. /* Memory addressing mode used by pflushr */
  1113. case '|':
  1114. if(opP->mode==MSCR || opP->mode==DREG ||
  1115. opP->mode==AREG || opP->mode==REGLST)
  1116. losing++;
  1117. break;
  1118. case 'f':
  1119. if (opP->mode != MSCR || (opP->reg != SFC && opP->reg != DFC))
  1120. losing++;
  1121. break;
  1122. case 'P':
  1123. if (opP->mode != MSCR || (opP->reg != TC && opP->reg != CAL &&
  1124. opP->reg != VAL && opP->reg != SCC && opP->reg != AC))
  1125. losing++;
  1126. break;
  1127. case 'V':
  1128. if (opP->reg != VAL)
  1129. losing++;
  1130. break;
  1131. case 'W':
  1132. if (opP->mode != MSCR || (opP->reg != DRP && opP->reg != SRP &&
  1133. opP->reg != CRP))
  1134. losing++;
  1135. break;
  1136. case 'X':
  1137. if (opP->mode != MSCR ||
  1138. (!(opP->reg >= BAD && opP->reg <= BAD+7) &&
  1139. !(opP->reg >= BAC && opP->reg <= BAC+7)))
  1140. losing++;
  1141. break;
  1142. case 'Y':
  1143. if (opP->reg != PSR)
  1144. losing++;
  1145. break;
  1146. case 'Z':
  1147. if (opP->reg != PCSR)
  1148. losing++;
  1149. break;
  1150. #endif
  1151. default:
  1152. as_fatal("Internal error: Operand mode %c unknown",*s);
  1153. }
  1154. }
  1155. if(!losing)
  1156. break;
  1157. opcode=opcode->m_next;
  1158. if(!opcode) { /* Fell off the end */
  1159. the_ins.error="instruction/operands mismatch";
  1160. return;
  1161. }
  1162. losing=0;
  1163. }
  1164. the_ins.args=opcode->m_operands;
  1165. the_ins.numargs=opcode->m_opnum;
  1166. the_ins.numo=opcode->m_codenum;
  1167. the_ins.opcode[0]=getone(opcode);
  1168. the_ins.opcode[1]=gettwo(opcode);
  1169. for(s=the_ins.args,opP= &the_ins.operands[0];*s;s+=2,opP++) {
  1170. /* This switch is a doozy.
  1171. What the first step; its a big one! */
  1172. switch(s[0]) {
  1173. case '*':
  1174. case '~':
  1175. case '%':
  1176. case ';':
  1177. case '@':
  1178. case '!':
  1179. case '&':
  1180. case '$':
  1181. case '?':
  1182. case '/':
  1183. #ifdef m68851
  1184. case '|':
  1185. #endif
  1186. switch(opP->mode) {
  1187. case IMMED:
  1188. tmpreg=0x3c; /* 7.4 */
  1189. if(index("bwl",s[1])) nextword=get_num(opP->con1,80);
  1190. else nextword=nextword=get_num(opP->con1,0);
  1191. if(isvar(opP->con1))
  1192. add_fix(s[1],opP->con1,0);
  1193. switch(s[1]) {
  1194. case 'b':
  1195. if(!isbyte(nextword))
  1196. opP->error="operand out of range";
  1197. addword(nextword);
  1198. baseo=0;
  1199. break;
  1200. case 'w':
  1201. if(!isword(nextword))
  1202. opP->error="operand out of range";
  1203. addword(nextword);
  1204. baseo=0;
  1205. break;
  1206. case 'l':
  1207. addword(nextword>>16);
  1208. addword(nextword);
  1209. baseo=0;
  1210. break;
  1211. case 'f':
  1212. baseo=2;
  1213. outro=8;
  1214. break;
  1215. case 'F':
  1216. baseo=4;
  1217. outro=11;
  1218. break;
  1219. case 'x':
  1220. baseo=6;
  1221. outro=15;
  1222. break;
  1223. case 'p':
  1224. baseo=6;
  1225. outro= -1;
  1226. break;
  1227. default:
  1228. as_fatal("Internal error: Can't decode %c%c",*s,s[1]);
  1229. }
  1230. if(!baseo)
  1231. break;
  1232. /* We gotta put out some float */
  1233. if(seg(opP->con1)!=SEG_BIG) {
  1234. int_to_gen(nextword);
  1235. gen_to_words(words,baseo,(long int)outro);
  1236. for(wordp=words;baseo--;wordp++)
  1237. addword(*wordp);
  1238. break;
  1239. } /* Its BIG */
  1240. if(offs(opP->con1)>0) {
  1241. as_warn("Bignum assumed to be binary bit-pattern");
  1242. if(offs(opP->con1)>baseo) {
  1243. as_warn("Bignum too big for %c format; truncated",s[1]);
  1244. offs(opP->con1)=baseo;
  1245. }
  1246. baseo-=offs(opP->con1);
  1247. for(wordp=generic_bignum+offs(opP->con1)-1;offs(opP->con1)--;--wordp)
  1248. addword(*wordp);
  1249. while(baseo--)
  1250. addword(0);
  1251. break;
  1252. }
  1253. gen_to_words(words,baseo,(long int)outro);
  1254. for(wordp=words;baseo--;wordp++)
  1255. addword(*wordp);
  1256. break;
  1257. case DREG:
  1258. tmpreg=opP->reg-DATA; /* 0.dreg */
  1259. break;
  1260. case AREG:
  1261. tmpreg=0x08+opP->reg-ADDR; /* 1.areg */
  1262. break;
  1263. case AINDR:
  1264. tmpreg=0x10+opP->reg-ADDR; /* 2.areg */
  1265. break;
  1266. case ADEC:
  1267. tmpreg=0x20+opP->reg-ADDR; /* 4.areg */
  1268. break;
  1269. case AINC:
  1270. tmpreg=0x18+opP->reg-ADDR; /* 3.areg */
  1271. break;
  1272. case AOFF:
  1273. if(opP->reg==PC)
  1274. tmpreg=0x3A; /* 7.2 */
  1275. else
  1276. tmpreg=0x28+opP->reg-ADDR; /* 5.areg */
  1277. nextword=get_num(opP->con1,80);
  1278. /* Force into index mode. Hope this works */
  1279. if(!issword(nextword)) {
  1280. if(opP->reg==PC)
  1281. tmpreg=0x3B; /* 7.3 */
  1282. else
  1283. tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
  1284. /* addword(0x0171); */
  1285. /* 171 seems to be wrong, and I can't find the 68020 manual, so we'll try 170
  1286. (which is what the Sun asm seems to generate */
  1287. addword(0x0170);
  1288. if(isvar(opP->con1))
  1289. add_fix('l',opP->con1,0);
  1290. addword(nextword>>16);
  1291. /* addword(nextword); */
  1292. } else if(isvar(opP->con1)) {
  1293. if(!flagseen['l']) {
  1294. add_fix('w',opP->con1,0);
  1295. } else {
  1296. tmpreg=0x30+opP->reg-ADDR;
  1297. addword(0x0170);
  1298. add_fix('l',opP->con1,0);
  1299. addword(nextword>>16);
  1300. }
  1301. }
  1302. addword(nextword);
  1303. break;
  1304. case AINDX:
  1305. case APODX:
  1306. case AMIND:
  1307. case APRDX:
  1308. nextword=0;
  1309. baseo=get_num(opP->con1,80);
  1310. outro=get_num(opP->con2,80);
  1311. /* Figure out the 'addressing mode' */
  1312. /* Also turn on the BASE_DISABLE bit, if needed */
  1313. if(opP->reg==PC || opP->reg==ZPC) {
  1314. tmpreg=0x3b; /* 7.3 */
  1315. if(opP->reg==ZPC)
  1316. nextword|=0x80;
  1317. } else if(opP->reg==FAIL) {
  1318. nextword|=0x80;
  1319. tmpreg=0x30; /* 6.garbage */
  1320. } else tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
  1321. siz1= (opP->con1) ? opP->con1->e_siz : 0;
  1322. siz2= (opP->con2) ? opP->con2->e_siz : 0;
  1323. /* Index register stuff */
  1324. if(opP->ireg>=DATA+0 && opP->ireg<=ADDR+7) {
  1325. nextword|=(opP->ireg-DATA)<<12;
  1326. if(opP->isiz==0 || opP->isiz==3)
  1327. nextword|=0x800;
  1328. switch(opP->imul) {
  1329. case 1: break;
  1330. case 2: nextword|=0x200; break;
  1331. case 4: nextword|=0x400; break;
  1332. case 8: nextword|=0x600; break;
  1333. default: abort();
  1334. }
  1335. /* IF its simple, GET US OUT OF HERE! */
  1336. /* Must be INDEX, with an index register. Address register
  1337. cannot be ZERO-PC, and either :b was forced, or we know it'll fit */
  1338. if(opP->mode==AINDX &&
  1339. opP->reg!=FAIL && opP->reg!=ZPC && (siz1==1 || (issbyte(baseo) &&
  1340. !isvar(opP->con1)))) {
  1341. nextword +=baseo&0xff;
  1342. addword(nextword);
  1343. if(isvar(opP->con1))
  1344. add_fix('B',opP->con1,0);
  1345. break;
  1346. }
  1347. } else
  1348. nextword|=0x40; /* No index reg */
  1349. /* It aint simple */
  1350. nextword|=0x100;
  1351. /* If the guy specified a width, we assume that
  1352. it is wide enough. Maybe it isn't. Ifso, we lose
  1353. */
  1354. switch(siz1) {
  1355. case 0:
  1356. if(isvar(opP->con1) || !issword(baseo)) {
  1357. siz1=3;
  1358. nextword|=0x30;
  1359. } else if(baseo==0)
  1360. nextword|=0x10;
  1361. else {
  1362. nextword|=0x20;
  1363. siz1=2;
  1364. }
  1365. break;
  1366. case 1:
  1367. as_warn("Byte dispacement won't work. Defaulting to :w");
  1368. case 2:
  1369. nextword|=0x20;
  1370. break;
  1371. case 3:
  1372. nextword|=0x30;
  1373. break;
  1374. }
  1375. /* Figure out innner displacement stuff */
  1376. if(opP->mode!=AINDX) {
  1377. switch(siz2) {
  1378. case 0:
  1379. if(isvar(opP->con2) || !issword(outro)) {
  1380. siz2=3;
  1381. nextword|=0x3;
  1382. } else if(outro==0)
  1383. nextword|=0x1;
  1384. else {
  1385. nextword|=0x2;
  1386. siz2=2;
  1387. }
  1388. break;
  1389. case 1:
  1390. as_warn("Byte dispacement won't work. Defaulting to :w");
  1391. case 2:
  1392. nextword|=0x2;
  1393. break;
  1394. case 3:
  1395. nextword|=0x3;
  1396. break;
  1397. }
  1398. if(opP->mode==APODX) nextword|=0x04;
  1399. else if(opP->mode==AMIND) nextword|=0x40;
  1400. }
  1401. addword(nextword);
  1402. if(isvar(opP->con1))
  1403. add_fix(siz1==3 ? 'l' : 'w',opP->con1,0);
  1404. if(siz1==3)
  1405. addword(baseo>>16);
  1406. if(siz1)
  1407. addword(baseo);
  1408. if(isvar(opP->con2))
  1409. add_fix(siz2==3 ? 'l' : 'w',opP->con2,0);
  1410. if(siz2==3)
  1411. addword(outro>>16);
  1412. if(siz2)
  1413. addword(outro);
  1414. break;
  1415. case ABSL:
  1416. nextword=get_num(opP->con1,80);
  1417. switch(opP->isiz) {
  1418. case 0:
  1419. if(!isvar(opP->con1) && issword(offs(opP->con1))) {
  1420. tmpreg=0x38; /* 7.0 */
  1421. addword(nextword);
  1422. break;
  1423. }
  1424. /* Don't generate pc relative code
  1425. on 68010 and 68000 */
  1426. if(isvar(opP->con1) &&
  1427. !subs(opP->con1) &&
  1428. seg(opP->con1)==SEG_TEXT &&
  1429. now_seg==SEG_TEXT &&
  1430. flagseen['m']==0 &&
  1431. !index("~%&$?", s[0])) {
  1432. tmpreg=0x3A; /* 7.2 */
  1433. add_frag(adds(opP->con1),
  1434. offs(opP->con1),
  1435. TAB(PCREL,SZ_UNDEF));
  1436. break;
  1437. }
  1438. case 3: /* Fall through into long */
  1439. if(isvar(opP->con1))
  1440. add_fix('l',opP->con1,0);
  1441. tmpreg=0x39; /* 7.1 mode */
  1442. addword(nextword>>16);
  1443. addword(nextword);
  1444. break;
  1445. case 2: /* Word */
  1446. if(isvar(opP->con1))
  1447. add_fix('w',opP->con1,0);
  1448. tmpreg=0x38; /* 7.0 mode */
  1449. addword(nextword);
  1450. break;
  1451. }
  1452. break;
  1453. case MSCR:
  1454. default:
  1455. as_warn("unknown/incorrect operand");
  1456. /* abort(); */
  1457. }
  1458. install_gen_operand(s[1],tmpreg);
  1459. break;
  1460. case '#':
  1461. case '^':
  1462. switch(s[1]) { /* JF: I hate floating point! */
  1463. case 'j':
  1464. tmpreg=70;
  1465. break;
  1466. case '8':
  1467. tmpreg=20;
  1468. break;
  1469. case 'C':
  1470. tmpreg=50;
  1471. break;
  1472. case '3':
  1473. default:
  1474. tmpreg=80;
  1475. break;
  1476. }
  1477. tmpreg=get_num(opP->con1,tmpreg);
  1478. if(isvar(opP->con1))
  1479. add_fix(s[1],opP->con1,0);
  1480. switch(s[1]) {
  1481. case 'b': /* Danger: These do no check for
  1482. certain types of overflow.
  1483. user beware! */
  1484. if(!isbyte(tmpreg))
  1485. opP->error="out of range";
  1486. insop(tmpreg);
  1487. if(isvar(opP->con1))
  1488. the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1489. break;
  1490. case 'w':
  1491. if(!isword(tmpreg))
  1492. opP->error="out of range";
  1493. insop(tmpreg);
  1494. if(isvar(opP->con1))
  1495. the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1496. break;
  1497. case 'l':
  1498. insop(tmpreg); /* Because of the way insop works, we put these two out backwards */
  1499. insop(tmpreg>>16);
  1500. if(isvar(opP->con1))
  1501. the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1502. break;
  1503. case '3':
  1504. tmpreg&=0xFF;
  1505. case '8':
  1506. case 'C':
  1507. install_operand(s[1],tmpreg);
  1508. break;
  1509. default:
  1510. as_fatal("Internal error: Unknown mode #%c",s[1]);
  1511. }
  1512. break;
  1513. case '+':
  1514. case '-':
  1515. case 'A':
  1516. install_operand(s[1],opP->reg-ADDR);
  1517. break;
  1518. case 'B':
  1519. tmpreg=get_num(opP->con1,80);
  1520. switch(s[1]) {
  1521. case 'g':
  1522. if(opP->con1->e_siz) { /* Deal with fixed size stuff by hand */
  1523. switch(opP->con1->e_siz) {
  1524. case 1:
  1525. add_fix('b',opP->con1,1);
  1526. break;
  1527. case 2:
  1528. add_fix('w',opP->con1,1);
  1529. addword(0);
  1530. break;
  1531. case 3:
  1532. add_fix('l',opP->con1,1);
  1533. addword(0);
  1534. addword(0);
  1535. break;
  1536. default:
  1537. as_fatal("Bad size for expression %d",opP->con1->e_siz);
  1538. }
  1539. } else if(subs(opP->con1)) {
  1540. /* We can't relax it */
  1541. the_ins.opcode[the_ins.numo-1]|=0xff;
  1542. add_fix('l',opP->con1,1);
  1543. addword(0);
  1544. addword(0);
  1545. } else if(adds(opP->con1)) {
  1546. if (flagseen['m'] &&
  1547. (the_ins.opcode[0] >= 0x6200) &&
  1548. (the_ins.opcode[0] <= 0x6f00)) {
  1549. add_frag(adds(opP->con1),offs(opP->con1),TAB(BCC68000,SZ_UNDEF));
  1550. } else {
  1551. add_frag(adds(opP->con1),offs(opP->con1),TAB(BRANCH,SZ_UNDEF));
  1552. }
  1553. } else {
  1554. /* JF: This is the WRONG thing to do
  1555. add_frag((symbolS *)0,offs(opP->con1),TAB(BRANCH,BYTE)); */
  1556. the_ins.opcode[the_ins.numo-1]|=0xff;
  1557. add_fix('l',opP->con1,1);
  1558. addword(0);
  1559. addword(4);
  1560. }
  1561. break;
  1562. case 'w':
  1563. if(isvar(opP->con1)) {
  1564. /* check for DBcc instruction */
  1565. if ((the_ins.opcode[0] & 0xf0f8) ==0x50c8){
  1566. /* size varies if patch */
  1567. /* needed for long form */
  1568. add_frag(adds(opP->con1),offs(opP->con1),TAB(DBCC,SZ_UNDEF));
  1569. break;
  1570. }
  1571. /* Don't ask! */
  1572. opP->con1->e_exp.X_add_number+=2;
  1573. add_fix('w',opP->con1,1);
  1574. }
  1575. addword(0);
  1576. break;
  1577. case 'c':
  1578. if(opP->con1->e_siz) {
  1579. switch(opP->con1->e_siz) {
  1580. case 2:
  1581. add_fix('w',opP->con1,1)
  1582. addword(0);
  1583. break;
  1584. case 3:
  1585. the_ins.opcode[the_ins.numo-1]|=0x40;
  1586. add_fix('l',opP->con1,1);
  1587. addword(0);
  1588. addword(0);
  1589. break;
  1590. default:
  1591. as_warn("Bad size for offset, must be word or long");
  1592. break;
  1593. }
  1594. } else if(subs(opP->con1)) {
  1595. add_fix('l',opP->con1,1);
  1596. add_frag((symbolS *)0,(long)0,TAB(FBRANCH,LONG));
  1597. } else if(adds(opP->con1)) {
  1598. add_frag(adds(opP->con1),offs(opP->con1),TAB(FBRANCH,SZ_UNDEF));
  1599. } else {
  1600. /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
  1601. the_ins.opcode[the_ins.numo-1]|=0x40;
  1602. add_fix('l',opP->con1,1);
  1603. addword(0);
  1604. addword(4);
  1605. }
  1606. break;
  1607. default:
  1608. as_fatal("Internal error: operand type B%c unknown",s[1]);
  1609. }
  1610. break;
  1611. case 'C': /* Ignore it */
  1612. break;
  1613. case 'd': /* JF this is a kludge */
  1614. if(opP->mode==AOFF) {
  1615. install_operand('s',opP->reg-ADDR);
  1616. } else {
  1617. char *tmpP;
  1618. tmpP=opP->con1->e_end-2;
  1619. opP->con1->e_beg++;
  1620. opP->con1->e_end-=4; /* point to the , */
  1621. baseo=m68k_reg_parse(&tmpP);
  1622. if(baseo<ADDR+0 || baseo>ADDR+7) {
  1623. as_warn("Unknown address reg, using A0");
  1624. baseo=0;
  1625. } else baseo-=ADDR;
  1626. install_operand('s',baseo);
  1627. }
  1628. tmpreg=get_num(opP->con1,80);
  1629. if(!issword(tmpreg)) {
  1630. as_warn("Expression out of range, using 0");
  1631. tmpreg=0;
  1632. }
  1633. addword(tmpreg);
  1634. break;
  1635. case 'D':
  1636. install_operand(s[1],opP->reg-DATA);
  1637. break;
  1638. case 'F':
  1639. install_operand(s[1],opP->reg-FPREG);
  1640. break;
  1641. case 'I':
  1642. tmpreg=1+opP->reg-COPNUM;
  1643. if(tmpreg==8)
  1644. tmpreg=0;
  1645. install_operand(s[1],tmpreg);
  1646. break;
  1647. case 'J': /* JF foo */
  1648. switch(opP->reg) {
  1649. case SFC:
  1650. tmpreg=0;
  1651. break;
  1652. case DFC:
  1653. tmpreg=0x001;
  1654. break;
  1655. case CACR:
  1656. tmpreg=0x002;
  1657. break;
  1658. case USP:
  1659. tmpreg=0x800;
  1660. break;
  1661. case VBR:
  1662. tmpreg=0x801;
  1663. break;
  1664. case CAAR:
  1665. tmpreg=0x802;
  1666. break;
  1667. case MSP:
  1668. tmpreg=0x803;
  1669. break;
  1670. case ISP:
  1671. tmpreg=0x804;
  1672. break;
  1673. default:
  1674. abort();
  1675. }
  1676. install_operand(s[1],tmpreg);
  1677. break;
  1678. case 'k':
  1679. tmpreg=get_num(opP->con1,55);
  1680. install_operand(s[1],tmpreg&0x7f);
  1681. break;
  1682. case 'l':
  1683. tmpreg=opP->reg;
  1684. if(s[1]=='w') {
  1685. if(tmpreg&0x7FF0000)
  1686. as_warn("Floating point register in register list");
  1687. insop(reverse_16_bits(tmpreg));
  1688. } else {
  1689. if(tmpreg&0x700FFFF)
  1690. as_warn("Wrong register in floating-point reglist");
  1691. install_operand(s[1],reverse_8_bits(tmpreg>>16));
  1692. }
  1693. break;
  1694. case 'L':
  1695. tmpreg=opP->reg;
  1696. if(s[1]=='w') {
  1697. if(tmpreg&0x7FF0000)
  1698. as_warn("Floating point register in register list");
  1699. insop(tmpreg);
  1700. } else if(s[1]=='8') {
  1701. if(tmpreg&0x0FFFFFF)
  1702. as_warn("incorrect register in reglist");
  1703. install_operand(s[1],tmpreg>>24);
  1704. } else {
  1705. if(tmpreg&0x700FFFF)
  1706. as_warn("wrong register in floating-point reglist");
  1707. else
  1708. install_operand(s[1],tmpreg>>16);
  1709. }
  1710. break;
  1711. case 'M':
  1712. install_operand(s[1],get_num(opP->con1,60));
  1713. break;
  1714. case 'O':
  1715. tmpreg= (opP->mode==DREG)
  1716. ? 0x20+opP->reg-DATA
  1717. : (get_num(opP->con1,40)&0x1F);
  1718. install_operand(s[1],tmpreg);
  1719. break;
  1720. case 'Q':
  1721. tmpreg=get_num(opP->con1,10);
  1722. if(tmpreg==8)
  1723. tmpreg=0;
  1724. install_operand(s[1],tmpreg);
  1725. break;
  1726. case 'R':
  1727. /* This depends on the fact that ADDR registers are
  1728. eight more than their corresponding DATA regs, so
  1729. the result will have the ADDR_REG bit set */
  1730. install_operand(s[1],opP->reg-DATA);
  1731. break;
  1732. case 's':
  1733. if(opP->reg==FPI) tmpreg=0x1;
  1734. else if(opP->reg==FPS) tmpreg=0x2;
  1735. else if(opP->reg==FPC) tmpreg=0x4;
  1736. else abort();
  1737. install_operand(s[1],tmpreg);
  1738. break;
  1739. case 'S': /* Ignore it */
  1740. break;
  1741. case 'T':
  1742. install_operand(s[1],get_num(opP->con1,30));
  1743. break;
  1744. case 'U': /* Ignore it */
  1745. break;
  1746. #ifdef m68851
  1747. /* JF: These are out of order, I fear. */
  1748. case 'f':
  1749. switch (opP->reg) {
  1750. case SFC:
  1751. tmpreg=0;
  1752. break;
  1753. case DFC:
  1754. tmpreg=1;
  1755. break;
  1756. default:
  1757. abort();
  1758. }
  1759. install_operand(s[1],tmpreg);
  1760. break;
  1761. case 'P':
  1762. switch(opP->reg) {
  1763. case TC:
  1764. tmpreg=0;
  1765. break;
  1766. case CAL:
  1767. tmpreg=4;
  1768. break;
  1769. case VAL:
  1770. tmpreg=5;
  1771. break;
  1772. case SCC:
  1773. tmpreg=6;
  1774. break;
  1775. case AC:
  1776. tmpreg=7;
  1777. break;
  1778. default:
  1779. abort();
  1780. }
  1781. install_operand(s[1],tmpreg);
  1782. break;
  1783. case 'V':
  1784. if (opP->reg == VAL)
  1785. break;
  1786. abort();
  1787. case 'W':
  1788. switch(opP->reg) {
  1789. case DRP:
  1790. tmpreg=1;
  1791. break;
  1792. case SRP:
  1793. tmpreg=2;
  1794. break;
  1795. case CRP:
  1796. tmpreg=3;
  1797. break;
  1798. default:
  1799. abort();
  1800. }
  1801. install_operand(s[1],tmpreg);
  1802. break;
  1803. case 'X':
  1804. switch (opP->reg) {
  1805. case BAD: case BAD+1: case BAD+2: case BAD+3:
  1806. case BAD+4: case BAD+5: case BAD+6: case BAD+7:
  1807. tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
  1808. break;
  1809. case BAC: case BAC+1: case BAC+2: case BAC+3:
  1810. case BAC+4: case BAC+5: case BAC+6: case BAC+7:
  1811. tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
  1812. break;
  1813. default:
  1814. abort();
  1815. }
  1816. install_operand(s[1], tmpreg);
  1817. break;
  1818. case 'Y':
  1819. if (opP->reg == PSR)
  1820. break;
  1821. abort();
  1822. case 'Z':
  1823. if (opP->reg == PCSR)
  1824. break;
  1825. abort;
  1826. #endif /* m68851 */
  1827. default:
  1828. as_fatal("Internal error: Operand type %c unknown",s[0]);
  1829. }
  1830. }
  1831. /* By the time whe get here (FINALLY) the_ins contains the complete
  1832. instruction, ready to be emitted. . . */
  1833. }
  1834. int
  1835. get_regs(i,str,opP)
  1836. struct m68k_op *opP;
  1837. char *str;
  1838. {
  1839. /* 26, 25, 24, 23-16, 15-8, 0-7 */
  1840. /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
  1841. unsigned long int cur_regs = 0;
  1842. int reg1,
  1843. reg2;
  1844. #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
  1845. else if(x==FPS) cur_regs|=(1<<25);\
  1846. else if(x==FPC) cur_regs|=(1<<26);\
  1847. else cur_regs|=(1<<(x-1)); }
  1848. reg1=i;
  1849. for(;;) {
  1850. if(*str=='/') {
  1851. ADD_REG(reg1);
  1852. str++;
  1853. } else if(*str=='-') {
  1854. str++;
  1855. reg2=m68k_reg_parse(&str);
  1856. if(reg2<DATA || reg2>=FPREG+8 || reg1==FPI || reg1==FPS || reg1==FPC) {
  1857. opP->error="unknown register in register list";
  1858. return FAIL;
  1859. }
  1860. while(reg1<=reg2) {
  1861. ADD_REG(reg1);
  1862. reg1++;
  1863. }
  1864. if(*str=='\0')
  1865. break;
  1866. } else if(*str=='\0') {
  1867. ADD_REG(reg1);
  1868. break;
  1869. } else {
  1870. opP->error="unknow character in register list";
  1871. return FAIL;
  1872. }
  1873. /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
  1874. if (*str=='/')
  1875. str ++;
  1876. reg1=m68k_reg_parse(&str);
  1877. if((reg1<DATA || reg1>=FPREG+8) && !(reg1==FPI || reg1==FPS || reg1==FPC)) {
  1878. opP->error="unknown register in register list";
  1879. return FAIL;
  1880. }
  1881. }
  1882. opP->reg=cur_regs;
  1883. return OK;
  1884. }
  1885. int
  1886. reverse_16_bits(in)
  1887. int in;
  1888. {
  1889. int out=0;
  1890. int n;
  1891. static int mask[16] = {
  1892. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  1893. 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
  1894. };
  1895. for(n=0;n<16;n++) {
  1896. if(in&mask[n])
  1897. out|=mask[15-n];
  1898. }
  1899. return out;
  1900. }
  1901. int
  1902. reverse_8_bits(in)
  1903. int in;
  1904. {
  1905. int out=0;
  1906. int n;
  1907. static int mask[8] = {
  1908. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  1909. };
  1910. for(n=0;n<8;n++) {
  1911. if(in&mask[n])
  1912. out|=mask[7-n];
  1913. }
  1914. return out;
  1915. }
  1916. void
  1917. install_operand(mode,val)
  1918. int mode;
  1919. int val;
  1920. {
  1921. switch(mode) {
  1922. case 's':
  1923. the_ins.opcode[0]|=val & 0xFF; /* JF FF is for M kludge */
  1924. break;
  1925. case 'd':
  1926. the_ins.opcode[0]|=val<<9;
  1927. break;
  1928. case '1':
  1929. the_ins.opcode[1]|=val<<12;
  1930. break;
  1931. case '2':
  1932. the_ins.opcode[1]|=val<<6;
  1933. break;
  1934. case '3':
  1935. the_ins.opcode[1]|=val;
  1936. break;
  1937. case '4':
  1938. the_ins.opcode[2]|=val<<12;
  1939. break;
  1940. case '5':
  1941. the_ins.opcode[2]|=val<<6;
  1942. break;
  1943. case '6':
  1944. /* DANGER! This is a hack to force cas2l and cas2w cmds
  1945. to be three words long! */
  1946. the_ins.numo++;
  1947. the_ins.opcode[2]|=val;
  1948. break;
  1949. case '7':
  1950. the_ins.opcode[1]|=val<<7;
  1951. break;
  1952. case '8':
  1953. the_ins.opcode[1]|=val<<10;
  1954. break;
  1955. #ifdef m68851
  1956. case '9':
  1957. the_ins.opcode[1]|=val<<5;
  1958. break;
  1959. #endif
  1960. case 't':
  1961. the_ins.opcode[1]|=(val<<10)|(val<<7);
  1962. break;
  1963. case 'D':
  1964. the_ins.opcode[1]|=(val<<12)|val;
  1965. break;
  1966. case 'g':
  1967. the_ins.opcode[0]|=val=0xff;
  1968. break;
  1969. case 'i':
  1970. the_ins.opcode[0]|=val<<9;
  1971. break;
  1972. case 'C':
  1973. the_ins.opcode[1]|=val;
  1974. break;
  1975. case 'j':
  1976. the_ins.opcode[1]|=val;
  1977. the_ins.numo++; /* What a hack */
  1978. break;
  1979. case 'k':
  1980. the_ins.opcode[1]|=val<<4;
  1981. break;
  1982. case 'b':
  1983. case 'w':
  1984. case 'l':
  1985. break;
  1986. case 'c':
  1987. default:
  1988. abort();
  1989. }
  1990. }
  1991. void
  1992. install_gen_operand(mode,val)
  1993. int mode;
  1994. int val;
  1995. {
  1996. switch(mode) {
  1997. case 's':
  1998. the_ins.opcode[0]|=val;
  1999. break;
  2000. case 'd':
  2001. /* This is a kludge!!! */
  2002. the_ins.opcode[0]|=(val&0x07)<<9|(val&0x38)<<3;
  2003. break;
  2004. case 'b':
  2005. case 'w':
  2006. case 'l':
  2007. case 'f':
  2008. case 'F':
  2009. case 'x':
  2010. case 'p':
  2011. the_ins.opcode[0]|=val;
  2012. break;
  2013. /* more stuff goes here */
  2014. default:
  2015. abort();
  2016. }
  2017. }
  2018. char *
  2019. crack_operand(str,opP)
  2020. register char *str;
  2021. register struct m68k_op *opP;
  2022. {
  2023. register int parens;
  2024. register int c;
  2025. register char *beg_str;
  2026. if(!str) {
  2027. return str;
  2028. }
  2029. beg_str=str;
  2030. for(parens=0;*str && (parens>0 || notend(str));str++) {
  2031. if(*str=='(') parens++;
  2032. else if(*str==')') {
  2033. if(!parens) { /* ERROR */
  2034. opP->error="Extra )";
  2035. return str;
  2036. }
  2037. --parens;
  2038. }
  2039. }
  2040. if(!*str && parens) { /* ERROR */
  2041. opP->error="Missing )";
  2042. return str;
  2043. }
  2044. c= *str;
  2045. *str='\0';
  2046. if(m68k_ip_op(beg_str,opP)==FAIL) {
  2047. *str=c;
  2048. return str;
  2049. }
  2050. *str=c;
  2051. if(c=='}')
  2052. c= *++str; /* JF bitfield hack */
  2053. if(c) {
  2054. c= *++str;
  2055. if(!c)
  2056. as_warn("Missing operand");
  2057. }
  2058. return str;
  2059. }
  2060. /* See the comment up above where the #define notend(... is */
  2061. #if 0
  2062. notend(s)
  2063. char *s;
  2064. {
  2065. if(*s==',') return 0;
  2066. if(*s=='{' || *s=='}')
  2067. return 0;
  2068. if(*s!=':') return 1;
  2069. /* This kludge here is for the division cmd, which is a kludge */
  2070. if(index("aAdD#",s[1])) return 0;
  2071. return 1;
  2072. }
  2073. #endif
  2074. /* This is the guts of the machine-dependent assembler. STR points to a
  2075. machine dependent instruction. This funciton is supposed to emit
  2076. the frags/bytes it assembles to.
  2077. */
  2078. void
  2079. md_assemble(str)
  2080. char *str;
  2081. {
  2082. char *er;
  2083. short *fromP;
  2084. char *toP;
  2085. int m,n;
  2086. char *to_beg_P;
  2087. int shorts_this_frag;
  2088. bzero((char *)(&the_ins),sizeof(the_ins)); /* JF for paranoia sake */
  2089. m68_ip(str);
  2090. er=the_ins.error;
  2091. if(!er) {
  2092. for(n=the_ins.numargs;n;--n)
  2093. if(the_ins.operands[n].error) {
  2094. er=the_ins.operands[n].error;
  2095. break;
  2096. }
  2097. }
  2098. if(er) {
  2099. as_warn("\"%s\" -- Statement '%s' ignored",er,str);
  2100. return;
  2101. }
  2102. if(the_ins.nfrag==0) { /* No frag hacking involved; just put it out */
  2103. toP=frag_more(2*the_ins.numo);
  2104. fromP= &the_ins.opcode[0];
  2105. for(m=the_ins.numo;m;--m) {
  2106. md_number_to_chars(toP,(long)(*fromP),2);
  2107. toP+=2;
  2108. fromP++;
  2109. }
  2110. /* put out symbol-dependent info */
  2111. for(m=0;m<the_ins.nrel;m++) {
  2112. switch(the_ins.reloc[m].wid) {
  2113. case 'B':
  2114. n=1;
  2115. break;
  2116. case 'b':
  2117. n=1;
  2118. break;
  2119. case 'w':
  2120. n=2;
  2121. break;
  2122. case 'l':
  2123. n=4;
  2124. break;
  2125. default:
  2126. as_fatal("confusing width %c",the_ins.reloc[m].wid);
  2127. }
  2128. fix_new(frag_now,
  2129. (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2130. n,
  2131. the_ins.reloc[m].add,
  2132. the_ins.reloc[m].sub,
  2133. the_ins.reloc[m].off,
  2134. the_ins.reloc[m].pcrel);
  2135. }
  2136. return;
  2137. }
  2138. /* There's some frag hacking */
  2139. for(n=0,fromP= &the_ins.opcode[0];n<the_ins.nfrag;n++) {
  2140. int wid;
  2141. if(n==0) wid=2*the_ins.fragb[n].fragoff;
  2142. else wid=2*(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2143. toP=frag_more(wid);
  2144. to_beg_P=toP;
  2145. shorts_this_frag=0;
  2146. for(m=wid/2;m;--m) {
  2147. md_number_to_chars(toP,(long)(*fromP),2);
  2148. toP+=2;
  2149. fromP++;
  2150. shorts_this_frag++;
  2151. }
  2152. for(m=0;m<the_ins.nrel;m++) {
  2153. if((the_ins.reloc[m].n)>= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */) {
  2154. the_ins.reloc[m].n-= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */;
  2155. break;
  2156. }
  2157. wid=the_ins.reloc[m].wid;
  2158. if(wid==0)
  2159. continue;
  2160. the_ins.reloc[m].wid=0;
  2161. wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2162. fix_new(frag_now,
  2163. (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2164. wid,
  2165. the_ins.reloc[m].add,
  2166. the_ins.reloc[m].sub,
  2167. the_ins.reloc[m].off,
  2168. the_ins.reloc[m].pcrel);
  2169. }
  2170. know(the_ins.fragb[n].fadd);
  2171. (void)frag_var(rs_machine_dependent,10,0,(relax_substateT)(the_ins.fragb[n].fragty),
  2172. the_ins.fragb[n].fadd,the_ins.fragb[n].foff,to_beg_P);
  2173. }
  2174. n=(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2175. shorts_this_frag=0;
  2176. if(n) {
  2177. toP=frag_more(n*sizeof(short));
  2178. while(n--) {
  2179. md_number_to_chars(toP,(long)(*fromP),2);
  2180. toP+=2;
  2181. fromP++;
  2182. shorts_this_frag++;
  2183. }
  2184. }
  2185. for(m=0;m<the_ins.nrel;m++) {
  2186. int wid;
  2187. wid=the_ins.reloc[m].wid;
  2188. if(wid==0)
  2189. continue;
  2190. the_ins.reloc[m].wid=0;
  2191. wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2192. fix_new(frag_now,
  2193. (the_ins.reloc[m].n + toP-frag_now->fr_literal)-/* the_ins.numo */ shorts_this_frag*2,
  2194. wid,
  2195. the_ins.reloc[m].add,
  2196. the_ins.reloc[m].sub,
  2197. the_ins.reloc[m].off,
  2198. the_ins.reloc[m].pcrel);
  2199. }
  2200. }
  2201. /* This function is called once, at assembler startup time. This should
  2202. set up all the tables, etc that the MD part of the assembler needs
  2203. */
  2204. void
  2205. md_begin()
  2206. {
  2207. /*
  2208. * md_begin -- set up hash tables with 68000 instructions.
  2209. * similar to what the vax assembler does. ---phr
  2210. */
  2211. /* RMS claims the thing to do is take the m68k-opcode.h table, and make
  2212. a copy of it at runtime, adding in the information we want but isn't
  2213. there. I think it'd be better to have an awk script hack the table
  2214. at compile time. Or even just xstr the table and use it as-is. But
  2215. my lord ghod hath spoken, so we do it this way. Excuse the ugly var
  2216. names. */
  2217. register struct m68k_opcode *ins;
  2218. register struct m68_incant *hack,
  2219. *slak;
  2220. register char *retval = 0; /* empty string, or error msg text */
  2221. register int i;
  2222. register char c;
  2223. if ((op_hash = hash_new()) == NULL)
  2224. as_fatal("Virtual memory exhausted");
  2225. obstack_begin(&robyn,4000);
  2226. for (ins = m68k_opcodes; ins < endop; ins++) {
  2227. hack=slak=(struct m68_incant *)obstack_alloc(&robyn,sizeof(struct m68_incant));
  2228. do {
  2229. slak->m_operands=ins->args;
  2230. slak->m_opnum=strlen(slak->m_operands)/2;
  2231. slak->m_opcode=ins->opcode;
  2232. /* This is kludgey */
  2233. slak->m_codenum=((ins->match)&0xffffL) ? 2 : 1;
  2234. if((ins+1)!=endop && !strcmp(ins->name,(ins+1)->name)) {
  2235. slak->m_next=(struct m68_incant *)
  2236. obstack_alloc(&robyn,sizeof(struct m68_incant));
  2237. ins++;
  2238. } else
  2239. slak->m_next=0;
  2240. slak=slak->m_next;
  2241. } while(slak);
  2242. retval = hash_insert (op_hash, ins->name,(char *)hack);
  2243. /* Didn't his mommy tell him about null pointers? */
  2244. if(retval && *retval)
  2245. as_fatal("Internal Error: Can't hash %s: %s",ins->name,retval);
  2246. }
  2247. for (i = 0; i < sizeof(mklower_table) ; i++)
  2248. mklower_table[i] = (isupper(c = (char) i)) ? tolower(c) : c;
  2249. for (i = 0 ; i < sizeof(notend_table) ; i++) {
  2250. notend_table[i] = 0;
  2251. alt_notend_table[i] = 0;
  2252. }
  2253. notend_table[','] = 1;
  2254. notend_table['{'] = 1;
  2255. notend_table['}'] = 1;
  2256. alt_notend_table['a'] = 1;
  2257. alt_notend_table['A'] = 1;
  2258. alt_notend_table['d'] = 1;
  2259. alt_notend_table['D'] = 1;
  2260. alt_notend_table['#'] = 1;
  2261. }
  2262. #if 0
  2263. #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
  2264. || (*s == ':' && index("aAdD#", s[1]))) \
  2265. ? 0 : 1)
  2266. #endif
  2267. /* This funciton is called once, before the assembler exits. It is
  2268. supposed to do any final cleanup for this part of the assembler.
  2269. */
  2270. void
  2271. md_end()
  2272. {
  2273. }
  2274. #define MAX_LITTLENUMS 6
  2275. /* Turn a string in input_line_pointer into a floating point constant of type
  2276. type, and store the appropriate bytes in *litP. The number of LITTLENUMS
  2277. emitted is stored in *sizeP . An error message is returned, or NULL on OK.
  2278. */
  2279. char *
  2280. md_atof(type,litP,sizeP)
  2281. char type;
  2282. char *litP;
  2283. int *sizeP;
  2284. {
  2285. int prec;
  2286. LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2287. LITTLENUM_TYPE *wordP;
  2288. char *t;
  2289. char *atof_m68k();
  2290. switch(type) {
  2291. case 'f':
  2292. case 'F':
  2293. case 's':
  2294. case 'S':
  2295. prec = 2;
  2296. break;
  2297. case 'd':
  2298. case 'D':
  2299. case 'r':
  2300. case 'R':
  2301. prec = 4;
  2302. break;
  2303. case 'x':
  2304. case 'X':
  2305. prec = 6;
  2306. break;
  2307. case 'p':
  2308. case 'P':
  2309. prec = 6;
  2310. break;
  2311. default:
  2312. *sizeP=0;
  2313. return "Bad call to MD_ATOF()";
  2314. }
  2315. t=atof_m68k(input_line_pointer,type,words);
  2316. if(t)
  2317. input_line_pointer=t;
  2318. *sizeP=prec * sizeof(LITTLENUM_TYPE);
  2319. for(wordP=words;prec--;) {
  2320. md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
  2321. litP+=sizeof(LITTLENUM_TYPE);
  2322. }
  2323. return ""; /* Someone should teach Dean about null pointers */
  2324. }
  2325. /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
  2326. for use in the a.out file, and stores them in the array pointed to by buf.
  2327. This knows about the endian-ness of the target machine and does
  2328. THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
  2329. 2 (short) and 4 (long) Floating numbers are put out as a series of
  2330. LITTLENUMS (shorts, here at least)
  2331. */
  2332. void
  2333. md_number_to_chars(buf,val,n)
  2334. char *buf;
  2335. long val;
  2336. int n;
  2337. {
  2338. switch(n) {
  2339. case 1:
  2340. *buf++=val;
  2341. break;
  2342. case 2:
  2343. *buf++=(val>>8);
  2344. *buf++=val;
  2345. break;
  2346. case 4:
  2347. *buf++=(val>>24);
  2348. *buf++=(val>>16);
  2349. *buf++=(val>>8);
  2350. *buf++=val;
  2351. break;
  2352. default:
  2353. abort();
  2354. }
  2355. }
  2356. void
  2357. md_number_to_imm(buf,val,n)
  2358. char *buf;
  2359. long val;
  2360. int n;
  2361. {
  2362. switch(n) {
  2363. case 1:
  2364. *buf++=val;
  2365. break;
  2366. case 2:
  2367. *buf++=(val>>8);
  2368. *buf++=val;
  2369. break;
  2370. case 4:
  2371. *buf++=(val>>24);
  2372. *buf++=(val>>16);
  2373. *buf++=(val>>8);
  2374. *buf++=val;
  2375. break;
  2376. default:
  2377. abort();
  2378. }
  2379. }
  2380. void
  2381. md_number_to_disp(buf,val,n)
  2382. char *buf;
  2383. long val;
  2384. int n;
  2385. {
  2386. abort();
  2387. }
  2388. void
  2389. md_number_to_field(buf,val,fix)
  2390. char *buf;
  2391. long val;
  2392. void *fix;
  2393. {
  2394. abort();
  2395. }
  2396. /* *fragP has been relaxed to its final size, and now needs to have
  2397. the bytes inside it modified to conform to the new size There is UGLY
  2398. MAGIC here. ..
  2399. */
  2400. void
  2401. md_convert_frag(fragP)
  2402. register fragS *fragP;
  2403. {
  2404. long disp;
  2405. long ext;
  2406. /* Address in gas core of the place to store the displacement. */
  2407. register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  2408. /* Address in object code of the displacement. */
  2409. register int object_address = fragP -> fr_fix + fragP -> fr_address;
  2410. know(fragP->fr_symbol);
  2411. /* The displacement of the address, from current location. */
  2412. disp = (fragP->fr_symbol->sy_value + fragP->fr_offset) - object_address;
  2413. switch(fragP->fr_subtype) {
  2414. case TAB(BCC68000,BYTE):
  2415. case TAB(BRANCH,BYTE):
  2416. know(issbyte(disp));
  2417. if(disp==0)
  2418. as_warn("short branch with zero offset: use :w");
  2419. fragP->fr_opcode[1]=disp;
  2420. ext=0;
  2421. break;
  2422. case TAB(DBCC,SHORT):
  2423. know(issword(disp));
  2424. ext=2;
  2425. break;
  2426. case TAB(BCC68000,SHORT):
  2427. case TAB(BRANCH,SHORT):
  2428. know(issword(disp));
  2429. fragP->fr_opcode[1]=0x00;
  2430. ext=2;
  2431. break;
  2432. case TAB(BRANCH,LONG):
  2433. if(flagseen['m']) {
  2434. if(fragP->fr_opcode[0]==0x61) {
  2435. fragP->fr_opcode[0]= 0x4E;
  2436. fragP->fr_opcode[1]= 0xB9; /* JBSR with ABSL LONG offset */
  2437. subseg_change(SEG_TEXT, 0);
  2438. fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2439. fragP->fr_fix+=4;
  2440. ext=0;
  2441. } else if(fragP->fr_opcode[0]==0x60) {
  2442. fragP->fr_opcode[0]= 0x4E;
  2443. fragP->fr_opcode[1]= 0xF9; /* JMP with ABSL LONG offset */
  2444. subseg_change(SEG_TEXT, 0);
  2445. fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset,0);
  2446. fragP->fr_fix+=4;
  2447. ext=0;
  2448. }else {
  2449. as_warn("Long branch offset not supported.");
  2450. }
  2451. } else {
  2452. fragP->fr_opcode[1]=0xff;
  2453. ext=4;
  2454. }
  2455. break;
  2456. case TAB(BCC68000,LONG):
  2457. {
  2458. /* only Bcc 68000 instructions can come here */
  2459. /* change bcc into b!cc/jmp absl long */
  2460. fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  2461. fragP->fr_opcode[1] = 0x6; /* branch offset = 6 */
  2462. fragP->fr_opcode[2] = 0x4e; /* put in jmp long (0x4ef9) */
  2463. fragP->fr_opcode[3] = 0xf9;
  2464. fragP->fr_fix += 2; /* account for jmp instruction */
  2465. subseg_change(SEG_TEXT,0);
  2466. fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
  2467. fragP->fr_offset,0);
  2468. fragP->fr_fix += 4;
  2469. ext=0;
  2470. }
  2471. break;
  2472. case TAB(DBCC,LONG):
  2473. {
  2474. /* only DBcc 68000 instructions can come here */
  2475. /* change dbcc into dbcc/jmp absl long */
  2476. fragP->fr_opcode[2] = 0x00; /* branch offset = 4 */
  2477. fragP->fr_opcode[3] = 0x04;
  2478. fragP->fr_opcode[4] = 0x60; /* put in bra pc+6 */
  2479. fragP->fr_opcode[5] = 0x06;
  2480. fragP->fr_opcode[6] = 0x4e; /* put in jmp long (0x4ef9) */
  2481. fragP->fr_opcode[7] = 0xf9;
  2482. fragP->fr_fix += 6; /* account for bra/jmp instructions */
  2483. subseg_change(SEG_TEXT,0);
  2484. fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
  2485. fragP->fr_offset,0);
  2486. fragP->fr_fix += 4;
  2487. ext=0;
  2488. }
  2489. break;
  2490. case TAB(FBRANCH,SHORT):
  2491. know((fragP->fr_opcode[1]&0x40)==0);
  2492. ext=2;
  2493. break;
  2494. case TAB(FBRANCH,LONG):
  2495. fragP->fr_opcode[1]|=0x40; /* Turn on LONG bit */
  2496. ext=4;
  2497. break;
  2498. case TAB(PCREL,SHORT):
  2499. ext=2;
  2500. break;
  2501. case TAB(PCREL,LONG):
  2502. /* The thing to do here is force it to ABSOLUTE LONG, since
  2503. PCREL is really trying to shorten an ABSOLUTE address anyway */
  2504. /* JF FOO This code has not been tested */
  2505. subseg_change(SEG_TEXT,0);
  2506. fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2507. if((fragP->fr_opcode[1] & 0x3F) != 0x3A)
  2508. as_warn("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
  2509. fragP->fr_opcode[0],fragP->fr_address);
  2510. fragP->fr_opcode[1]&= ~0x3F;
  2511. fragP->fr_opcode[1]|=0x39; /* Mode 7.1 */
  2512. fragP->fr_fix+=4;
  2513. /* md_number_to_chars(buffer_address,
  2514. (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
  2515. 4); */
  2516. ext=0;
  2517. }
  2518. if(ext) {
  2519. md_number_to_chars(buffer_address,(long)disp,(int)ext);
  2520. fragP->fr_fix+=ext;
  2521. }
  2522. }
  2523. /* Force truly undefined symbols to their maximum size, and generally set up
  2524. the frag list to be relaxed
  2525. */
  2526. int
  2527. md_estimate_size_before_relax(fragP,segtype)
  2528. register fragS *fragP;
  2529. int segtype;
  2530. {
  2531. int old_fix;
  2532. old_fix=fragP->fr_fix;
  2533. /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  2534. switch(fragP->fr_subtype) {
  2535. case TAB(DBCC,SZ_UNDEF):
  2536. if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2537. fragP->fr_subtype=TAB(DBCC,SHORT);
  2538. fragP->fr_var+=2;
  2539. break;
  2540. }
  2541. /* only DBcc 68000 instructions can come here */
  2542. /* change dbcc into dbcc/jmp absl long */
  2543. fragP->fr_opcode[2] = 0x00; /* branch offset = 4 */
  2544. fragP->fr_opcode[3] = 0x04;
  2545. fragP->fr_opcode[4] = 0x60; /* put in bra pc+6 */
  2546. fragP->fr_opcode[5] = 0x06;
  2547. fragP->fr_opcode[6] = 0x4e; /* put in jmp long (0x4ef9) */
  2548. fragP->fr_opcode[7] = 0xf9;
  2549. fragP->fr_fix += 6; /* account for bra/jmp instruction */
  2550. subseg_change(SEG_TEXT,0);
  2551. fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
  2552. fragP->fr_offset,0);
  2553. fragP->fr_fix += 4;
  2554. frag_wane(fragP);
  2555. break;
  2556. case TAB(BCC68000,SZ_UNDEF):
  2557. if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2558. fragP->fr_subtype=TAB(BCC68000,BYTE);
  2559. break;
  2560. }
  2561. /* only Bcc 68000 instructions can come here */
  2562. /* change bcc into b!cc/jmp absl long */
  2563. fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  2564. fragP->fr_opcode[1] = 0x6; /* branch offset = 6 */
  2565. fragP->fr_opcode[2] = 0x4e; /* put in jmp long (0x4ef9) */
  2566. fragP->fr_opcode[3] = 0xf9;
  2567. fragP->fr_fix += 2; /* account for jmp instruction */
  2568. subseg_change(SEG_TEXT,0);
  2569. fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
  2570. fragP->fr_offset,0);
  2571. fragP->fr_fix += 4;
  2572. frag_wane(fragP);
  2573. break;
  2574. case TAB(BRANCH,SZ_UNDEF):
  2575. if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2576. fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
  2577. break;
  2578. } else if(flagseen['m']) {
  2579. if(fragP->fr_opcode[0]==0x61) {
  2580. fragP->fr_opcode[0]= 0x4E;
  2581. fragP->fr_opcode[1]= 0xB9; /* JBSR with ABSL LONG offset */
  2582. subseg_change(SEG_TEXT, 0);
  2583. fix_new(fragP, fragP->fr_fix, 4,
  2584. fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2585. fragP->fr_fix+=4;
  2586. frag_wane(fragP);
  2587. } else if(fragP->fr_opcode[0]==0x60) {
  2588. fragP->fr_opcode[0]= 0x4E;
  2589. fragP->fr_opcode[1]= 0xF9; /* JMP with ABSL LONG offset */
  2590. subseg_change(SEG_TEXT, 0);
  2591. fix_new(fragP, fragP->fr_fix, 4,
  2592. fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2593. fragP->fr_fix+=4;
  2594. frag_wane(fragP);
  2595. } else {
  2596. as_warn("Long branch offset to extern symbol not supported.");
  2597. }
  2598. } else { /* Symbol is still undefined. Make it simple */
  2599. fix_new(fragP,(int)(fragP->fr_fix),4,fragP->fr_symbol,
  2600. (symbolS *)0,fragP->fr_offset+4,1);
  2601. fragP->fr_fix+=4;
  2602. fragP->fr_opcode[1]=0xff;
  2603. frag_wane(fragP);
  2604. break;
  2605. }
  2606. default:
  2607. break;
  2608. }
  2609. /* now that SZ_UNDEF are taken care of, check others */
  2610. switch(fragP->fr_subtype) {
  2611. case TAB(BCC68000,BYTE):
  2612. case TAB(BRANCH,BYTE):
  2613. /* We can't do a short jump to the next instruction,
  2614. so we force word mode. */
  2615. if(fragP->fr_symbol && fragP->fr_symbol->sy_value==0 &&
  2616. fragP->fr_symbol->sy_frag==fragP->fr_next) {
  2617. fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),SHORT);
  2618. fragP->fr_var+=2;
  2619. }
  2620. break;
  2621. case TAB(FBRANCH,SZ_UNDEF):
  2622. if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2623. fragP->fr_subtype=TAB(FBRANCH,SHORT);
  2624. fragP->fr_var+=2;
  2625. } else {
  2626. fragP->fr_subtype=TAB(FBRANCH,LONG);
  2627. fragP->fr_var+=4;
  2628. }
  2629. break;
  2630. case TAB(PCREL,SZ_UNDEF):
  2631. if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2632. fragP->fr_subtype=TAB(PCREL,SHORT);
  2633. fragP->fr_var+=2;
  2634. } else {
  2635. fragP->fr_subtype=TAB(PCREL,LONG);
  2636. fragP->fr_var+=4;
  2637. }
  2638. break;
  2639. default:
  2640. break;
  2641. }
  2642. return fragP->fr_var + fragP->fr_fix - old_fix;
  2643. }
  2644. /* the bit-field entries in the relocation_info struct plays hell
  2645. with the byte-order problems of cross-assembly. So as a hack,
  2646. I added this mach. dependent ri twiddler. Ugly, but it gets
  2647. you there. -KWK */
  2648. /* on m68k: first 4 bytes are normal unsigned long, next three bytes
  2649. are symbolnum, most sig. byte first. Last byte is broken up with
  2650. bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
  2651. nibble as nuthin. (on Sun 3 at least) */
  2652. void
  2653. md_ri_to_chars(ri_p, ri)
  2654. struct relocation_info *ri_p, ri;
  2655. {
  2656. unsigned char the_bytes[8];
  2657. /* this is easy */
  2658. md_number_to_chars(the_bytes, ri.r_address, sizeof(ri.r_address));
  2659. /* now the fun stuff */
  2660. the_bytes[4] = (ri.r_symbolnum >> 16) & 0x0ff;
  2661. the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
  2662. the_bytes[6] = ri.r_symbolnum & 0x0ff;
  2663. the_bytes[7] = (((ri.r_pcrel << 7) & 0x80) | ((ri.r_length << 5) & 0x60) |
  2664. ((ri.r_extern << 4) & 0x10));
  2665. /* now put it back where you found it */
  2666. bcopy (the_bytes, (char *)ri_p, sizeof(struct relocation_info));
  2667. }
  2668. #ifndef WORKING_DOT_WORD
  2669. int md_short_jump_size = 4;
  2670. int md_long_jump_size = 6;
  2671. void
  2672. md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)
  2673. char *ptr;
  2674. long from_addr,
  2675. to_addr;
  2676. fragS *frag;
  2677. symbolS *to_symbol;
  2678. {
  2679. long offset;
  2680. offset = to_addr - (from_addr+2);
  2681. md_number_to_chars(ptr ,(long)0x6000,2);
  2682. md_number_to_chars(ptr+2,(long)offset,2);
  2683. }
  2684. void
  2685. md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
  2686. char *ptr;
  2687. long from_addr,
  2688. to_addr;
  2689. fragS *frag;
  2690. symbolS *to_symbol;
  2691. {
  2692. long offset;
  2693. if(flagseen['m']) {
  2694. offset=to_addr-to_symbol->sy_value;
  2695. md_number_to_chars(ptr ,(long)0x4EF9,2);
  2696. md_number_to_chars(ptr+2,(long)offset,4);
  2697. fix_new(frag,(ptr+2)-frag->fr_literal,4,to_symbol,(symbolS *)0,(long int)0,0);
  2698. } else {
  2699. offset=to_addr - (from_addr+2);
  2700. md_number_to_chars(ptr ,(long)0x60ff,2);
  2701. md_number_to_chars(ptr+2,(long)offset,4);
  2702. }
  2703. }
  2704. #endif
  2705. /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
  2706. 0: Everything is OK
  2707. 10: Absolute 1:8 only
  2708. 20: Absolute 0:7 only
  2709. 30: absolute 0:15 only
  2710. 40: Absolute 0:31 only
  2711. 50: absolute 0:127 only
  2712. 55: absolute -64:63 only
  2713. 60: absolute -128:127 only
  2714. 70: absolute 0:4095 only
  2715. 80: No bignums
  2716. */
  2717. int
  2718. get_num(exp,ok)
  2719. struct m68k_exp *exp;
  2720. int ok;
  2721. {
  2722. #ifdef TEST2
  2723. long l = 0;
  2724. if(!exp->e_beg)
  2725. return 0;
  2726. if(*exp->e_beg=='0') {
  2727. if(exp->e_beg[1]=='x')
  2728. sscanf(exp->e_beg+2,"%x",&l);
  2729. else
  2730. sscanf(exp->e_beg+1,"%O",&l);
  2731. return l;
  2732. }
  2733. return atol(exp->e_beg);
  2734. #else
  2735. char *save_in;
  2736. char c_save;
  2737. if(!exp) {
  2738. /* Can't do anything */
  2739. return 0;
  2740. }
  2741. if(!exp->e_beg || !exp->e_end) {
  2742. seg(exp)=SEG_ABSOLUTE;
  2743. adds(exp)=0;
  2744. subs(exp)=0;
  2745. offs(exp)= (ok==10) ? 1 : 0;
  2746. as_warn("Null expression defaults to %ld",offs(exp));
  2747. return 0;
  2748. }
  2749. exp->e_siz=0;
  2750. if(/* ok!=80 && */exp->e_end[-1]==':' && (exp->e_end-exp->e_beg)>2) {
  2751. switch(exp->e_end[0]) {
  2752. case 's':
  2753. case 'b':
  2754. exp->e_siz=1;
  2755. break;
  2756. case 'w':
  2757. exp->e_siz=2;
  2758. break;
  2759. case 'l':
  2760. exp->e_siz=3;
  2761. break;
  2762. default:
  2763. as_warn("Unknown size for expression \"%c\"",exp->e_end[0]);
  2764. }
  2765. exp->e_end-=2;
  2766. }
  2767. c_save=exp->e_end[1];
  2768. exp->e_end[1]='\0';
  2769. save_in=input_line_pointer;
  2770. input_line_pointer=exp->e_beg;
  2771. switch(expression(&(exp->e_exp))) {
  2772. case SEG_NONE:
  2773. /* Do the same thing the VAX asm does */
  2774. seg(exp)=SEG_ABSOLUTE;
  2775. adds(exp)=0;
  2776. subs(exp)=0;
  2777. offs(exp)=0;
  2778. if(ok==10) {
  2779. as_warn("expression out of range: defaulting to 1");
  2780. offs(exp)=1;
  2781. }
  2782. break;
  2783. case SEG_ABSOLUTE:
  2784. switch(ok) {
  2785. case 10:
  2786. if(offs(exp)<1 || offs(exp)>8) {
  2787. as_warn("expression out of range: defaulting to 1");
  2788. offs(exp)=1;
  2789. }
  2790. break;
  2791. case 20:
  2792. if(offs(exp)<0 || offs(exp)>7)
  2793. goto outrange;
  2794. break;
  2795. case 30:
  2796. if(offs(exp)<0 || offs(exp)>15)
  2797. goto outrange;
  2798. break;
  2799. case 40:
  2800. if(offs(exp)<0 || offs(exp)>32)
  2801. goto outrange;
  2802. break;
  2803. case 50:
  2804. if(offs(exp)<0 || offs(exp)>127)
  2805. goto outrange;
  2806. break;
  2807. case 55:
  2808. if(offs(exp)<-64 || offs(exp)>63)
  2809. goto outrange;
  2810. break;
  2811. case 60:
  2812. if(offs(exp)<-128 || offs(exp)>127)
  2813. goto outrange;
  2814. break;
  2815. case 70:
  2816. if(offs(exp)<0 || offs(exp)>4095) {
  2817. outrange:
  2818. as_warn("expression out of range: defaulting to 0");
  2819. offs(exp)=0;
  2820. }
  2821. break;
  2822. default:
  2823. break;
  2824. }
  2825. break;
  2826. case SEG_TEXT:
  2827. case SEG_DATA:
  2828. case SEG_BSS:
  2829. case SEG_UNKNOWN:
  2830. case SEG_DIFFERENCE:
  2831. if(ok>=10 && ok<=70) {
  2832. seg(exp)=SEG_ABSOLUTE;
  2833. adds(exp)=0;
  2834. subs(exp)=0;
  2835. offs(exp)= (ok==10) ? 1 : 0;
  2836. as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  2837. }
  2838. break;
  2839. case SEG_BIG:
  2840. if(ok==80 && offs(exp)<0) { /* HACK! Turn it into a long */
  2841. LITTLENUM_TYPE words[6];
  2842. gen_to_words(words,2,8L);/* These numbers are magic! */
  2843. seg(exp)=SEG_ABSOLUTE;
  2844. adds(exp)=0;
  2845. subs(exp)=0;
  2846. offs(exp)=words[1]|(words[0]<<16);
  2847. } else if(ok!=0) {
  2848. seg(exp)=SEG_ABSOLUTE;
  2849. adds(exp)=0;
  2850. subs(exp)=0;
  2851. offs(exp)= (ok==10) ? 1 : 0;
  2852. as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  2853. }
  2854. break;
  2855. default:
  2856. abort();
  2857. }
  2858. if(input_line_pointer!=exp->e_end+1)
  2859. as_warn("Ignoring junk after expression");
  2860. exp->e_end[1]=c_save;
  2861. input_line_pointer=save_in;
  2862. if(exp->e_siz) {
  2863. switch(exp->e_siz) {
  2864. case 1:
  2865. if(!isbyte(offs(exp)))
  2866. as_warn("expression doesn't fit in BYTE");
  2867. break;
  2868. case 2:
  2869. if(!isword(offs(exp)))
  2870. as_warn("expression doesn't fit in WORD");
  2871. break;
  2872. }
  2873. }
  2874. return offs(exp);
  2875. #endif
  2876. }
  2877. /* These are the back-ends for the various machine dependent pseudo-ops. */
  2878. void demand_empty_rest_of_line(); /* Hate those extra verbose names */
  2879. void
  2880. s_data1()
  2881. {
  2882. subseg_new(SEG_DATA,1);
  2883. demand_empty_rest_of_line();
  2884. }
  2885. void
  2886. s_data2()
  2887. {
  2888. subseg_new(SEG_DATA,2);
  2889. demand_empty_rest_of_line();
  2890. }
  2891. void
  2892. s_even()
  2893. {
  2894. register int temp;
  2895. register long int temp_fill;
  2896. temp = 1; /* JF should be 2? */
  2897. temp_fill = get_absolute_expression ();
  2898. if ( ! need_pass_2 ) /* Never make frag if expect extra pass. */
  2899. frag_align (temp, (int)temp_fill);
  2900. demand_empty_rest_of_line();
  2901. }
  2902. /* s_space is defined in read.c .skip is simply an alias to it. */
  2903. int
  2904. md_parse_option(argP,cntP,vecP)
  2905. char **argP;
  2906. int *cntP;
  2907. char ***vecP;
  2908. {
  2909. switch(**argP) {
  2910. case 'l': /* -l means keep external to 2 bit offset
  2911. rather than 16 bit one */
  2912. break;
  2913. case 'm':
  2914. /* Gas simply ignores this option! */
  2915. (*argP)++;
  2916. if(**argP=='c')
  2917. (*argP)++;
  2918. if(!strcmp(*argP,"68000"))
  2919. flagseen['m']=2;
  2920. else if(!strcmp(*argP,"68010")) {
  2921. #ifdef M_SUN
  2922. omagic= 1<<16|OMAGIC;
  2923. #endif
  2924. flagseen['m']=1;
  2925. } else if(!strcmp(*argP,"68020"))
  2926. flagseen['m']=0;
  2927. else
  2928. as_warn("Unknown -m option ignored");
  2929. while(**argP)
  2930. (*argP)++;
  2931. break;
  2932. default:
  2933. return 0;
  2934. }
  2935. return 1;
  2936. }
  2937. #ifdef TEST2
  2938. /* TEST2: Test md_assemble() */
  2939. /* Warning, this routine probably doesn't work anymore */
  2940. main()
  2941. {
  2942. struct m68_it the_ins;
  2943. char buf[120];
  2944. char *cp;
  2945. int n;
  2946. m68_ip_begin();
  2947. for(;;) {
  2948. if(!gets(buf) || !*buf)
  2949. break;
  2950. if(buf[0]=='|' || buf[1]=='.')
  2951. continue;
  2952. for(cp=buf;*cp;cp++)
  2953. if(*cp=='\t')
  2954. *cp=' ';
  2955. if(is_label(buf))
  2956. continue;
  2957. bzero(&the_ins,sizeof(the_ins));
  2958. m68_ip(&the_ins,buf);
  2959. if(the_ins.error) {
  2960. printf("Error %s in %s\n",the_ins.error,buf);
  2961. } else {
  2962. printf("Opcode(%d.%s): ",the_ins.numo,the_ins.args);
  2963. for(n=0;n<the_ins.numo;n++)
  2964. printf(" 0x%x",the_ins.opcode[n]&0xffff);
  2965. printf(" ");
  2966. print_the_insn(&the_ins.opcode[0],stdout);
  2967. (void)putchar('\n');
  2968. }
  2969. for(n=0;n<strlen(the_ins.args)/2;n++) {
  2970. if(the_ins.operands[n].error) {
  2971. printf("op%d Error %s in %s\n",n,the_ins.operands[n].error,buf);
  2972. continue;
  2973. }
  2974. printf("mode %d, reg %d, ",the_ins.operands[n].mode,the_ins.operands[n].reg);
  2975. if(the_ins.operands[n].b_const)
  2976. printf("Constant: '%.*s', ",1+the_ins.operands[n].e_const-the_ins.operands[n].b_const,the_ins.operands[n].b_const);
  2977. printf("ireg %d, isiz %d, imul %d, ",the_ins.operands[n].ireg,the_ins.operands[n].isiz,the_ins.operands[n].imul);
  2978. if(the_ins.operands[n].b_iadd)
  2979. printf("Iadd: '%.*s',",1+the_ins.operands[n].e_iadd-the_ins.operands[n].b_iadd,the_ins.operands[n].b_iadd);
  2980. (void)putchar('\n');
  2981. }
  2982. }
  2983. m68_ip_end();
  2984. return 0;
  2985. }
  2986. is_label(str)
  2987. char *str;
  2988. {
  2989. while(*str==' ')
  2990. str++;
  2991. while(*str && *str!=' ')
  2992. str++;
  2993. if(str[-1]==':' || str[1]=='=')
  2994. return 1;
  2995. return 0;
  2996. }
  2997. print_address(add,fp)
  2998. FILE *fp;
  2999. {
  3000. fprintf(fp,"%#X",add);
  3001. }
  3002. #endif
  3003. /* Possible states for relaxation:
  3004. 0 0 branch offset byte (bra, etc)
  3005. 0 1 word
  3006. 0 2 long
  3007. 1 0 indexed offsets byte a0@(32,d4:w:1) etc
  3008. 1 1 word
  3009. 1 2 long
  3010. 2 0 two-offset index word-word a0@(32,d4)@(45) etc
  3011. 2 1 word-long
  3012. 2 2 long-word
  3013. 2 3 long-long
  3014. */
  3015. #ifdef DONTDEF
  3016. abort()
  3017. {
  3018. printf("ABORT!\n");
  3019. exit(12);
  3020. }
  3021. char *index(s,c)
  3022. char *s;
  3023. {
  3024. while(*s!=c) {
  3025. if(!*s) return 0;
  3026. s++;
  3027. }
  3028. return s;
  3029. }
  3030. bzero(s,n)
  3031. char *s;
  3032. {
  3033. while(n--)
  3034. *s++=0;
  3035. }
  3036. print_frags()
  3037. {
  3038. fragS *fragP;
  3039. extern fragS *text_frag_root;
  3040. for(fragP=text_frag_root;fragP;fragP=fragP->fr_next) {
  3041. printf("addr %lu next 0x%x fix %ld var %ld symbol 0x%x offset %ld\n",
  3042. fragP->fr_address,fragP->fr_next,fragP->fr_fix,fragP->fr_var,fragP->fr_symbol,fragP->fr_offset);
  3043. printf("opcode 0x%x type %d subtype %d\n\n",fragP->fr_opcode,fragP->fr_type,fragP->fr_subtype);
  3044. }
  3045. fflush(stdout);
  3046. return 0;
  3047. }
  3048. #endif
  3049. #ifdef DONTDEF
  3050. /*VARARGS1*/
  3051. panic(format,args)
  3052. char *format;
  3053. {
  3054. fputs("Internal error:",stderr);
  3055. _doprnt(format,&args,stderr);
  3056. (void)putc('\n',stderr);
  3057. as_where();
  3058. abort();
  3059. }
  3060. #endif