vax.c 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193
  1. /* vax.c - vax-specific -
  2. Copyright (C) 1987 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 1, or (at your option)
  7. any later version.
  8. GAS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to
  14. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. /* JF I moved almost all the vax specific stuff into this one file 'cuz RMS
  16. seems to think its a good idea. I hope I managed to get all the VAX-isms */
  17. #include "as.h"
  18. #include "read.h"
  19. #include "flonum.h"
  20. #include "vax-inst.h"
  21. #include "md.h"
  22. #include "obstack.h" /* For FRAG_APPEND_1_CHAR macro in "frags.h" */
  23. #include "frags.h"
  24. #include "struc-symbol.h"
  25. #include "expr.h"
  26. #include "symbols.h"
  27. /* This is the number to put at the beginning of the a.out file */
  28. long omagic = OMAGIC;
  29. /* These chars start a comment anywhere in a source file (except inside
  30. another comment */
  31. char comment_chars[] = "#";
  32. /* These chars only start a comment at the beginning of a line. */
  33. /* Note that for the VAX the are the same ac comment_chars above. */
  34. char line_comment_chars[] = "#";
  35. /* Chars that can be used to separate mant from exp in floating point nums */
  36. char EXP_CHARS[] = "eE";
  37. /* Chars that mean this number is a floating point constant */
  38. /* as in 0f123.456 */
  39. /* or 0H1.234E-12 (see exp chars above) */
  40. char FLT_CHARS[] = "dDfFgGhH";
  41. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  42. changed in read.c . Ideally it shouldn't have to know about it at all,
  43. but nothing is ideal around here.
  44. */
  45. static expressionS /* Hold details of an operand expression */
  46. exp_of_operand [ VIT_MAX_OPERANDS ];
  47. static struct vit
  48. v; /* A vax instruction after decoding. */
  49. LITTLENUM_TYPE big_operand_bits [ VIT_MAX_OPERANDS ] [ SIZE_OF_LARGE_NUMBER ];
  50. /* Hold details of big operands. */
  51. FLONUM_TYPE float_operand [ VIT_MAX_OPERANDS ];
  52. /* Above is made to point into */
  53. /* big_operand_bits by md_begin(). */
  54. /*
  55. * For VAX, relative addresses of "just the right length" are easy.
  56. * The branch displacement is always the last operand, even in
  57. * synthetic instructions.
  58. * For VAX, we encode the relax_substateTs (in e.g. fr_substate) as:
  59. *
  60. * 4 3 2 1 0 bit number
  61. * ---/ /--+-------+-------+-------+-------+-------+
  62. * | what state ? | how long ? |
  63. * ---/ /--+-------+-------+-------+-------+-------+
  64. *
  65. * The "how long" bits are 00=byte, 01=word, 10=long.
  66. * This is a Un*x convention.
  67. * Not all lengths are legit for a given value of (what state).
  68. * The "how long" refers merely to the displacement length.
  69. * The address usually has some constant bytes in it as well.
  70. *
  71. groups for VAX address relaxing.
  72. 1. "foo" pc-relative.
  73. length of byte, word, long
  74. 2a. J<cond> where <cond> is a simple flag test.
  75. length of byte, word, long.
  76. VAX opcodes are: (Hex)
  77. bneq/bnequ 12
  78. beql/beqlu 13
  79. bgtr 14
  80. bleq 15
  81. bgeq 18
  82. blss 19
  83. bgtru 1a
  84. blequ 1b
  85. bvc 1c
  86. bvs 1d
  87. bgequ/bcc 1e
  88. blssu/bcs 1f
  89. Always, you complement 0th bit to reverse condition.
  90. Always, 1-byte opcode, then 1-byte displacement.
  91. 2b. J<cond> where cond tests a memory bit.
  92. length of byte, word, long.
  93. Vax opcodes are: (Hex)
  94. bbs e0
  95. bbc e1
  96. bbss e2
  97. bbcs e3
  98. bbsc e4
  99. bbcc e5
  100. bbssi e6
  101. bbcci e7
  102. Always, you complement 0th bit to reverse condition.
  103. Always, 1-byte opcde, longword-address, byte-address, 1-byte-displacement
  104. 2c. J<cond> where cond tests low-order memory bit
  105. length of byte,word,long.
  106. Vax opcodes are: (Hex)
  107. blbs e8
  108. blbc e9
  109. Always, you complement 0th bit to reverse condition.
  110. Always, 1-byte opcode, longword-address, 1-byte displacement.
  111. 3. Jbs/Jbr.
  112. length of byte,word,long.
  113. Vax opcodes are: (Hex)
  114. bsbb 10
  115. brb 11
  116. These are like (2) but there is no condition to reverse.
  117. Always, 1 byte opcode, then displacement/absolute.
  118. 4a. JacbX
  119. length of word, long.
  120. Vax opcodes are: (Hex)
  121. acbw 3d
  122. acbf 4f
  123. acbd 6f
  124. abcb 9d
  125. acbl f1
  126. acbg 4ffd
  127. acbh 6ffd
  128. Always, we cannot reverse the sense of the branch; we have a word
  129. displacement.
  130. The double-byte op-codes don't hurt: we never want to modify the
  131. opcode, so we don't care how many bytes are between the opcode and
  132. the operand.
  133. 4b. JXobXXX
  134. length of long, long, byte.
  135. Vax opcodes are: (Hex)
  136. aoblss f2
  137. aobleq f3
  138. sobgeq f4
  139. sobgtr f5
  140. Always, we cannot reverse the sense of the branch; we have a byte
  141. displacement.
  142. The only time we need to modify the opcode is for class 2 instructions.
  143. After relax() we may complement the lowest order bit of such instruction
  144. to reverse sense of branch.
  145. For class 2 instructions, we store context of "where is the opcode literal".
  146. We can change an opcode's lowest order bit without breaking anything else.
  147. We sometimes store context in the operand literal. This way we can figure out
  148. after relax() what the original addressing mode was.
  149. */
  150. /* These displacements are relative to */
  151. /* the start address of the displacement. */
  152. /* The first letter is Byte, Word. */
  153. /* 2nd letter is Forward, Backward. */
  154. #define BF (1+ 127)
  155. #define BB (1+-128)
  156. #define WF (2+ 32767)
  157. #define WB (2+-32768)
  158. /* Dont need LF, LB because they always */
  159. /* reach. [They are coded as 0.] */
  160. #define C(a,b) ENCODE_RELAX(a,b)
  161. /* This macro has no side-effects. */
  162. #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
  163. relax_typeS
  164. md_relax_table[] = {
  165. { 1, 1, 0, 0 }, /* error sentinel 0,0 */
  166. { 1, 1, 0, 0 }, /* unused 0,1 */
  167. { 1, 1, 0, 0 }, /* unused 0,2 */
  168. { 1, 1, 0, 0 }, /* unused 0,3 */
  169. { BF+1, BB+1, 2, C(1,1) }, /* B^"foo" 1,0 */
  170. { WF+1, WB+1, 3, C(1,2) }, /* W^"foo" 1,1 */
  171. { 0, 0, 5, 0 }, /* L^"foo" 1,2 */
  172. { 1, 1, 0, 0 }, /* unused 1,3 */
  173. { BF , BB , 1, C(2,1) }, /* b<cond> B^"foo" 2,0 */
  174. { WF+2, WB+2, 4, C(2,2) }, /* br.+? brw X 2,1 */
  175. { 0, 0, 7, 0 }, /* br.+? jmp X 2,2 */
  176. { 1, 1, 0, 0 }, /* unused 2,3 */
  177. { BF , BB , 1, C(3,1) }, /* brb B^foo 3,0 */
  178. { WF , WB , 2, C(3,2) }, /* brw W^foo 3,1 */
  179. { 0, 0, 5, 0 }, /* Jmp L^foo 3,2 */
  180. { 1, 1, 0, 0 }, /* unused 3,3 */
  181. { 1, 1, 0, 0 }, /* unused 4,0 */
  182. { WF , WB , 2, C(4,2) }, /* acb_ ^Wfoo 4,1 */
  183. { 0, 0, 10, 0 }, /* acb_,br,jmp L^foo4,2 */
  184. { 1, 1, 0, 0 }, /* unused 4,3 */
  185. { BF , BB , 1, C(5,1) }, /* Xob___,,foo 5,0 */
  186. { WF+4, WB+4, 6, C(5,2) }, /* Xob.+2,brb.+3,brw5,1 */
  187. { 0, 0, 9, 0 }, /* Xob.+2,brb.+6,jmp5,2 */
  188. };
  189. #undef C
  190. #undef BF
  191. #undef BB
  192. #undef WF
  193. #undef WB
  194. void float_cons();
  195. pseudo_typeS md_pseudo_table[] = {
  196. { "dfloat", float_cons, 'd' },
  197. { "ffloat", float_cons, 'f' },
  198. { "gfloat", float_cons, 'g' },
  199. { "hfloat", float_cons, 'h' },
  200. { 0 }
  201. };
  202. #define STATE_PC_RELATIVE (1)
  203. #define STATE_CONDITIONAL_BRANCH (2)
  204. #define STATE_ALWAYS_BRANCH (3) /* includes BSB... */
  205. #define STATE_COMPLEX_BRANCH (4)
  206. #define STATE_COMPLEX_HOP (5)
  207. #define STATE_BYTE (0)
  208. #define STATE_WORD (1)
  209. #define STATE_LONG (2)
  210. #define STATE_UNDF (3) /* Symbol undefined in pass1 */
  211. #define min(a, b) ((a) < (b) ? (a) : (b))
  212. void
  213. md_begin()
  214. {
  215. char * vip_begin();
  216. char * errtxt;
  217. FLONUM_TYPE * fP;
  218. int i;
  219. if ( * (errtxt = vip_begin(TRUE, "$", "*", "`")) )
  220. {
  221. as_fatal( "VIP_BEGIN error:%s", errtxt );
  222. }
  223. for (i = 0, fP = float_operand;
  224. fP < float_operand + VIT_MAX_OPERANDS;
  225. i++, fP ++)
  226. {
  227. fP -> low = & big_operand_bits [i] [0];
  228. fP -> high = & big_operand_bits [i] [SIZE_OF_LARGE_NUMBER - 1];
  229. }
  230. }
  231. void
  232. md_end()
  233. {
  234. vip_end();
  235. }
  236. void /* Knows about order of bytes in address. */
  237. md_number_to_chars (con, value, nbytes)
  238. char con []; /* Return 'nbytes' of chars here. */
  239. long int value; /* The value of the bits. */
  240. int nbytes; /* Number of bytes in the output. */
  241. {
  242. int n;
  243. long v;
  244. n=nbytes;
  245. v=value;
  246. while (nbytes--)
  247. {
  248. *con++ = value; /* Lint wants & MASK_CHAR. */
  249. value >>= BITS_PER_CHAR;
  250. }
  251. /* XXX line number probably botched for this warning message. */
  252. if (value != 0 && value != -1)
  253. as_warn ("Displacement (%ld) long for instruction field length (%d).",v,n);
  254. }
  255. void /* Knows about order of bytes in address. */
  256. md_number_to_imm (con, value, nbytes)
  257. char con []; /* Return 'nbytes' of chars here. */
  258. long int value; /* The value of the bits. */
  259. int nbytes; /* Number of bytes in the output. */
  260. {
  261. int n;
  262. long v;
  263. n=nbytes;
  264. v=value;
  265. while (nbytes--)
  266. {
  267. *con++ = value; /* Lint wants & MASK_CHAR. */
  268. value >>= BITS_PER_CHAR;
  269. }
  270. /* XXX line number probably botched for this warning message. */
  271. if (value != 0 && value != -1)
  272. as_warn ("Displacement (%ld) too long for instruction field length (%d).",v,n);
  273. }
  274. void /* Knows about order of bytes in address. */
  275. md_number_to_disp (con, value, nbytes)
  276. char con []; /* Return 'nbytes' of chars here. */
  277. long int value; /* The value of the bits. */
  278. int nbytes; /* Number of bytes in the output. */
  279. {
  280. abort();
  281. while (nbytes--)
  282. {
  283. *con++ = value; /* Lint wants & MASK_CHAR. */
  284. value >>= BITS_PER_CHAR;
  285. }
  286. /* XXX line number probably botched for this warning message. */
  287. if (value != 0 && value != -1)
  288. as_warn ("Displacement too long for instruction field length.");
  289. }
  290. void /* Knows about order of bytes in address. */
  291. md_number_to_field (con, value, nbytes)
  292. char con []; /* Return 'nbytes' of chars here. */
  293. long int value; /* The value of the bits. */
  294. int nbytes; /* Number of bytes in the output. */
  295. {
  296. abort();
  297. while (nbytes--)
  298. {
  299. *con++ = value; /* Lint wants & MASK_CHAR. */
  300. value >>= BITS_PER_CHAR;
  301. }
  302. /* XXX line number probably botched for this warning message. */
  303. if (value != 0 && value != -1)
  304. as_warn ("Displacement too long for instruction field length.");
  305. }
  306. long int /* Knows about the byte order in a word. */
  307. md_chars_to_number (con, nbytes)
  308. unsigned char con[]; /* Low order byte 1st. */
  309. int nbytes; /* Number of bytes in the input. */
  310. {
  311. long int retval;
  312. for (retval=0, con+=nbytes-1; nbytes--; con--)
  313. {
  314. retval <<= BITS_PER_CHAR;
  315. retval |= *con;
  316. }
  317. return retval;
  318. }
  319. /* vax:md_assemble() emit frags for 1 instruction */
  320. void
  321. md_assemble (instruction_string)
  322. char * instruction_string; /* A string: assemble 1 instruction. */
  323. {
  324. char * p;
  325. register struct vop * operandP; /* An operand. Scans all operands. */
  326. char * save_input_line_pointer;
  327. char c_save; /* What used to live after an expression. */
  328. struct frag* fragP; /* Fragment of code we just made. */
  329. register int goofed; /* TRUE: instruction_string bad for all passes. */
  330. register struct vop * end_operandP; /* -> slot just after last operand */
  331. /* Limit of the for (each operand). */
  332. register expressionS *expP; /* -> expression values for this operand */
  333. /* These refer to an instruction operand expression. */
  334. segT to_seg; /* Target segment of the address. */
  335. register valueT this_add_number;
  336. register struct symbol * this_add_symbol; /* +ve (minuend) symbol. */
  337. register struct symbol * this_subtract_symbol; /* -ve(subtrahend) symbol. */
  338. long int opcode_as_number; /* As a number. */
  339. char * opcode_as_chars; /* Least significant byte 1st. */
  340. /* As an array of characters. */
  341. char * opcode_low_byteP; /* Least significant byte 1st */
  342. struct details * detP; /* The details of an ADxxx frag. */
  343. int length; /* length (bytes) meant by vop_short. */
  344. int at; /* 0, or 1 if '@' is in addressing mode. */
  345. int nbytes; /* From vop_nbytes: vax_operand_width (in bytes) */
  346. FLONUM_TYPE * floatP;
  347. char * vip();
  348. LITTLENUM_TYPE literal_float [8];
  349. /* Big enough for any floating point literal. */
  350. if ( * ( p = vip (&v, instruction_string) ) )
  351. {
  352. as_fatal("vax_assemble\"%s\" in=\"%s\"", p, instruction_string);
  353. }
  354. /*
  355. * Now we try to find as many as_warn()s as we can. If we do any as_warn()s
  356. * then goofed=TRUE. Notice that we don't make any frags yet.
  357. * Should goofed be TRUE, then this instruction will wedge in any pass,
  358. * and we can safely flush it, without causing interpass symbol phase
  359. * errors. That is, without changing label values in different passes.
  360. */
  361. if ( goofed = ( * v . vit_error ) )
  362. {
  363. as_warn("Ignoring statement due to \"%s\"", v . vit_error);
  364. }
  365. /*
  366. * We need to use expression() and friends, which require us to diddle
  367. * input_line_pointer. So we save it and restore it later.
  368. */
  369. save_input_line_pointer = input_line_pointer;
  370. for (operandP = v.vit_operand,
  371. expP = exp_of_operand,
  372. floatP = float_operand,
  373. end_operandP = v.vit_operand + v.vit_operands;
  374. operandP < end_operandP;
  375. operandP++,
  376. expP++,
  377. floatP ++
  378. ) /* for each operand */
  379. {
  380. if ( * ( operandP -> vop_error ) )
  381. {
  382. as_warn("Ignoring statement because \"%s\"", ( operandP -> vop_error ) );
  383. goofed = TRUE;
  384. }
  385. else
  386. {/* statement has no syntax goofs: lets sniff the expression */
  387. int can_be_short; /* TRUE if a bignum can be reduced to a short literal. */
  388. input_line_pointer = operandP -> vop_expr_begin;
  389. c_save = operandP -> vop_expr_end [1];
  390. operandP -> vop_expr_end [1] = '\0';
  391. /* If to_seg == SEG_PASS1, expression() will have set need_pass_2 = TRUE. */
  392. switch (to_seg = expression( expP ))
  393. {
  394. case SEG_NONE:
  395. /* for BSD4.2 compatibility, missing expression is absolute 0 */
  396. to_seg = expP -> X_seg = SEG_ABSOLUTE;
  397. expP -> X_add_number = 0;
  398. /* for SEG_ABSOLUTE, we shouldnt need to set X_subtract_symbol, X_add_symbol to any particular value. */
  399. /* But, we will program defensively. Since this situation occurs */
  400. /* rarely so it costs us little to do, and stops Dean */
  401. /* worrying about the origin of random bits in expressionS's. */
  402. expP -> X_add_symbol = NULL;
  403. expP -> X_subtract_symbol = NULL;
  404. case SEG_TEXT:
  405. case SEG_DATA:
  406. case SEG_BSS:
  407. case SEG_ABSOLUTE:
  408. case SEG_UNKNOWN:
  409. break;
  410. case SEG_DIFFERENCE:
  411. /*
  412. * Major bug. We can't handle the case of a
  413. * SEG_DIFFERENCE expression in a VIT_OPCODE_SYNTHETIC
  414. * variable-length instruction.
  415. * We don't have a frag type that is smart enough to
  416. * relax a SEG_DIFFERENCE, and so we just force all
  417. * SEG_DIFFERENCEs to behave like SEG_PASS1s.
  418. * Clearly, if there is a demand we can invent a new or
  419. * modified frag type and then coding up a frag for this
  420. * case will be easy. SEG_DIFFERENCE was invented for the
  421. * .words after a CASE opcode, and was never intended for
  422. * instruction operands.
  423. */
  424. need_pass_2 = TRUE;
  425. break;
  426. case SEG_BIG:
  427. /* Preserve the bits. */
  428. if (expP -> X_add_number > 0)
  429. {
  430. bignum_copy (generic_bignum, expP -> X_add_number,
  431. floatP -> low, SIZE_OF_LARGE_NUMBER);
  432. }
  433. else
  434. {
  435. know( expP -> X_add_number < 0 );
  436. flonum_copy (& generic_floating_point_number,
  437. floatP);
  438. if (index ("s i", operandP -> vop_short))
  439. { /* Could possibly become S^# */
  440. flonum_gen2vax (- expP -> X_add_number, floatP, literal_float);
  441. switch ( - expP -> X_add_number)
  442. {
  443. case 'f':
  444. can_be_short =
  445. (literal_float [0] & 0xFC0F) == 0x4000
  446. && literal_float [1] == 0;
  447. break;
  448. case 'd':
  449. can_be_short =
  450. (literal_float [0] & 0xFC0F) == 0x4000
  451. && literal_float[1] == 0
  452. && literal_float [2] == 0
  453. && literal_float [3] == 0;
  454. break;
  455. case 'g':
  456. can_be_short =
  457. (literal_float [0] & 0xFF81) == 0x4000
  458. && literal_float[1] == 0
  459. && literal_float [2] == 0
  460. && literal_float [3] == 0;
  461. break;
  462. case 'h':
  463. can_be_short =
  464. (literal_float [0] & 0xFFF8) == 0x4000
  465. && (literal_float [1] & 0xE000) == 0
  466. && literal_float [2] == 0
  467. && literal_float [3] == 0
  468. && literal_float [4] == 0
  469. && literal_float [5] == 0
  470. && literal_float [6] == 0
  471. && literal_float [7] == 0;
  472. break;
  473. default:
  474. BAD_CASE( - expP -> X_add_number );
  475. break;
  476. } /* switch (float type) */
  477. } /* if (could want to become S^#...) */
  478. } /* bignum or flonum ? */
  479. if ( operandP -> vop_short == 's'
  480. || operandP -> vop_short == 'i'
  481. || ( operandP -> vop_short == ' '
  482. && operandP -> vop_reg == 0xF
  483. && (operandP -> vop_mode & 0xE) == 0x8))
  484. {
  485. /* Saw a '#'. */
  486. if (operandP -> vop_short == ' ')
  487. { /* We must chose S^ or I^. */
  488. if (expP -> X_add_number > 0)
  489. { /* Bignum: Short literal impossible. */
  490. operandP -> vop_short = 'i';
  491. operandP -> vop_mode = 8;
  492. operandP -> vop_reg = 0xF; /* VAX PC. */
  493. }
  494. else
  495. { /* Flonum: Try to do it. */
  496. if (can_be_short)
  497. {
  498. operandP -> vop_short = 's';
  499. operandP -> vop_mode = 0;
  500. operandP -> vop_ndx = -1;
  501. operandP -> vop_reg = -1;
  502. /* JF hope this is the right thing */
  503. expP->X_seg=SEG_ABSOLUTE;
  504. }
  505. else
  506. {
  507. operandP -> vop_short = 'i';
  508. operandP -> vop_mode = 8;
  509. operandP -> vop_reg = 0xF; /* VAX PC */
  510. }
  511. } /* bignum or flonum ? */
  512. } /* if #, but no S^ or I^ seen. */
  513. /* No more ' ' case: either 's' or 'i'. */
  514. if (operandP -> vop_short == 's')
  515. {
  516. /* Wants to be a short literal. */
  517. if (expP -> X_add_number > 0)
  518. {
  519. as_warn( "Bignum not permitted in short literal. Immediate mode assumed." );
  520. operandP -> vop_short = 'i';
  521. operandP -> vop_mode = 8;
  522. operandP -> vop_reg = 0xF; /* VAX PC. */
  523. }
  524. else
  525. {
  526. if ( ! can_be_short)
  527. {
  528. as_warn( "Can't do flonum short literal: immediate mode used." );
  529. operandP -> vop_short = 'i';
  530. operandP -> vop_mode = 8;
  531. operandP -> vop_reg = 0xF; /* VAX PC. */
  532. }
  533. else
  534. { /* Encode short literal now. */
  535. register int temp;
  536. switch ( - expP -> X_add_number )
  537. {
  538. case 'f':
  539. case 'd':
  540. temp = literal_float [0] >> 4;
  541. break;
  542. case 'g':
  543. temp = literal_float [0] >> 1;
  544. break;
  545. case 'h':
  546. temp = ((literal_float [0] << 3) & 070)
  547. | ((literal_float [1] >> 13) & 07);
  548. break;
  549. default:
  550. BAD_CASE( - expP -> X_add_number );
  551. break;
  552. }
  553. floatP -> low [0] = temp & 077;
  554. floatP -> low [1] = 0;
  555. } /* if can be short literal float */
  556. } /* flonum or bignum ? */
  557. }
  558. else
  559. { /* I^# seen: set it up if float. */
  560. if (expP -> X_add_number < 0)
  561. {
  562. bcopy( literal_float, floatP -> low, sizeof(literal_float));
  563. }
  564. } /* if S^# seen. */
  565. }
  566. else
  567. {
  568. as_warn( "A bignum/flonum may not be a displacement: 0x%x used",
  569. expP -> X_add_number = 0x80000000);
  570. /* Chosen so luser gets the most offset bits to patch later. */
  571. }
  572. expP -> X_add_number = floatP -> low [0]
  573. | ((LITTLENUM_MASK & (floatP -> low [1])) << LITTLENUM_NUMBER_OF_BITS);
  574. /*
  575. * For the SEG_BIG case we have:
  576. * If vop_short == 's' then a short floating literal is in the
  577. * lowest 6 bits of floatP -> low [0], which is
  578. * big_operand_bits [---] [0].
  579. * If vop_short == 'i' then the appropriate number of elements
  580. * of big_operand_bits [---] [...] are set up with the correct
  581. * bits.
  582. * Also, just in case width is byte word or long, we copy the lowest
  583. * 32 bits of the number to X_add_number.
  584. */
  585. break;
  586. default:
  587. BAD_CASE( to_seg );
  588. break;
  589. }
  590. if ( input_line_pointer != operandP -> vop_expr_end + 1 )
  591. {
  592. as_warn("Junk at end of expression \"%s\"", input_line_pointer);
  593. goofed = TRUE;
  594. }
  595. operandP -> vop_expr_end [1] = c_save;
  596. }
  597. } /* for(each operand) */
  598. input_line_pointer = save_input_line_pointer;
  599. if ( ! need_pass_2 && ! goofed )
  600. {
  601. /* We saw no errors in any operands - try to make frag(s) */
  602. int is_undefined; /* True if operand expression's */
  603. /* segment not known yet. */
  604. int length_code;
  605. /* Emit op-code. */
  606. /* Remember where it is, in case we want to modify the op-code later. */
  607. opcode_low_byteP = frag_more (v . vit_opcode_nbytes);
  608. bcopy (v . vit_opcode, opcode_low_byteP, v . vit_opcode_nbytes);
  609. opcode_as_number = md_chars_to_number (opcode_as_chars = v . vit_opcode, 4);
  610. for (operandP = v.vit_operand,
  611. expP = exp_of_operand,
  612. floatP = float_operand,
  613. end_operandP = v.vit_operand + v.vit_operands;
  614. operandP < end_operandP;
  615. operandP++,
  616. floatP ++,
  617. expP++
  618. ) /* for each operand */
  619. {
  620. if ( operandP -> vop_ndx >= 0 )
  621. {
  622. /* indexed addressing byte */
  623. /* Legality of indexed mode already checked: it is OK */
  624. FRAG_APPEND_1_CHAR( 0x40 + operandP -> vop_ndx );
  625. } /* if(vop_ndx>=0) */
  626. /* Here to make main operand frag(s). */
  627. this_add_number = expP -> X_add_number;
  628. this_add_symbol = expP -> X_add_symbol;
  629. this_subtract_symbol = expP -> X_subtract_symbol;
  630. to_seg = expP -> X_seg;
  631. is_undefined = (to_seg == SEG_UNKNOWN);
  632. know( to_seg == SEG_UNKNOWN \
  633. || to_seg == SEG_ABSOLUTE \
  634. || to_seg == SEG_DATA \
  635. || to_seg == SEG_TEXT \
  636. || to_seg == SEG_BSS \
  637. || to_seg == SEG_BIG \
  638. );
  639. at = operandP -> vop_mode & 1;
  640. length = operandP->vop_short=='b' ? 1 : operandP->vop_short=='w' ? 2 : operandP->vop_short=='l' ? 4 : 0;
  641. nbytes = operandP -> vop_nbytes;
  642. if ( operandP -> vop_access == 'b' )
  643. {
  644. if (to_seg == now_seg || is_undefined)
  645. { /* If is_undefined, then it might BECOME now_seg. */
  646. if ( nbytes )
  647. {
  648. p = frag_more (nbytes);
  649. fix_new (frag_now, p - frag_now -> fr_literal, nbytes,
  650. this_add_symbol, 0, this_add_number, 1);
  651. }
  652. else
  653. { /* to_seg==now_seg || to_seg == SEG_UNKNOWN */
  654. /* nbytes==0 */
  655. length_code = is_undefined ? STATE_UNDF : STATE_BYTE;
  656. if ( opcode_as_number & VIT_OPCODE_SPECIAL )
  657. {
  658. if ( operandP -> vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP )
  659. {
  660. /* br or jsb */
  661. frag_var (rs_machine_dependent, 5, 1,
  662. ENCODE_RELAX( STATE_ALWAYS_BRANCH, length_code ),
  663. this_add_symbol, this_add_number,
  664. opcode_low_byteP);
  665. }
  666. else
  667. {
  668. if(operandP -> vop_width == VAX_WIDTH_WORD_JUMP)
  669. {
  670. length_code=STATE_WORD; /* JF: There is no state_byte for this one! */
  671. frag_var (rs_machine_dependent, 10, 2,
  672. ENCODE_RELAX( STATE_COMPLEX_BRANCH, length_code ),
  673. this_add_symbol, this_add_number,
  674. opcode_low_byteP);
  675. }
  676. else
  677. {
  678. know( operandP -> vop_width == VAX_WIDTH_BYTE_JUMP );
  679. frag_var (rs_machine_dependent, 9, 1,
  680. ENCODE_RELAX( STATE_COMPLEX_HOP, length_code),
  681. this_add_symbol, this_add_number,
  682. opcode_low_byteP);
  683. }
  684. }
  685. }
  686. else
  687. {
  688. know( operandP -> vop_width == VAX_WIDTH_CONDITIONAL_JUMP );
  689. frag_var (rs_machine_dependent, 7, 1,
  690. ENCODE_RELAX( STATE_CONDITIONAL_BRANCH, length_code ),
  691. this_add_symbol, this_add_number,
  692. opcode_low_byteP);
  693. }
  694. }
  695. }
  696. else
  697. { /* to_seg != now_seg && to_seg != SEG_UNKNOWN */
  698. /*
  699. * --- SEG FLOAT MAY APPEAR HERE ----
  700. */
  701. if ( to_seg == SEG_ABSOLUTE )
  702. {
  703. if ( nbytes )
  704. {
  705. know( ! (opcode_as_number & VIT_OPCODE_SYNTHETIC) );
  706. p = frag_more (nbytes);
  707. /* Conventional relocation. */
  708. fix_new (frag_now, p - frag_now -> fr_literal,
  709. nbytes, & abs_symbol, 0, this_add_number, 1);
  710. }
  711. else
  712. {
  713. know( opcode_as_number & VIT_OPCODE_SYNTHETIC );
  714. if ( opcode_as_number & VIT_OPCODE_SPECIAL )
  715. {
  716. if ( operandP -> vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP )
  717. {
  718. /* br or jsb */
  719. * opcode_low_byteP = opcode_as_chars[0] + VAX_WIDEN_LONG;
  720. know( opcode_as_chars [1] == 0 );
  721. p = frag_more (5);
  722. p [0] = VAX_ABSOLUTE_MODE; /* @#... */
  723. md_number_to_chars (p + 1, this_add_number, 4);
  724. /* Now (eg) JMP @#foo or JSB @#foo. */
  725. }
  726. else
  727. {
  728. if(operandP -> vop_width == VAX_WIDTH_WORD_JUMP)
  729. {
  730. p = frag_more (10);
  731. p[0] = 2;
  732. p[1] = 0;
  733. p[2] = VAX_BRB;
  734. p[3] = 6;
  735. p[4] = VAX_JMP;
  736. p[5] = VAX_ABSOLUTE_MODE; /* @#... */
  737. md_number_to_chars (p+6, this_add_number, 4);
  738. /*
  739. * Now (eg) ACBx 1f
  740. * BRB 2f
  741. * 1: JMP @#foo
  742. * 2:
  743. */
  744. }
  745. else
  746. {
  747. know( operandP -> vop_width == VAX_WIDTH_BYTE_JUMP );
  748. p = frag_more (9);
  749. p [0] = 2;
  750. p [1] = VAX_BRB;
  751. p [2] = 6;
  752. p [3] = VAX_JMP;
  753. p [4] = VAX_PC_RELATIVE_MODE + 1; /* @#... */
  754. md_number_to_chars (p+5, this_add_number, 4);
  755. /*
  756. * Now (eg) xOBxxx 1f
  757. * BRB 2f
  758. * 1: JMP @#foo
  759. * 2:
  760. */
  761. }
  762. }
  763. }
  764. else
  765. {
  766. /* b<cond> */
  767. * opcode_low_byteP ^= 1; /* To reverse the condition in a VAX branch, complement the lowest order bit. */
  768. p = frag_more (7);
  769. p[0] = 6;
  770. p[1] = VAX_JMP;
  771. p[2] = VAX_ABSOLUTE_MODE; /* @#... */
  772. md_number_to_chars( p+3, this_add_number, 4);
  773. /*
  774. * Now (eg) BLEQ 1f
  775. * JMP @#foo
  776. * 1:
  777. */
  778. }
  779. }
  780. }
  781. else
  782. { /* to_seg != now_seg && to_seg != SEG_UNKNOWN && to_Seg != SEG_ABSOLUTE */
  783. if ( nbytes > 0)
  784. {
  785. /* Pc-relative. Conventional relocation. */
  786. know( ! (opcode_as_number & VIT_OPCODE_SYNTHETIC) );
  787. p = frag_more (nbytes);
  788. fix_new (frag_now, p - frag_now -> fr_literal,
  789. nbytes, & abs_symbol, 0, this_add_number, 1);
  790. }
  791. else
  792. {
  793. know( opcode_as_number & VIT_OPCODE_SYNTHETIC );
  794. if ( opcode_as_number & VIT_OPCODE_SPECIAL )
  795. {
  796. if ( operandP -> vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP )
  797. {
  798. /* br or jsb */
  799. know( opcode_as_chars [1] == 0 );
  800. * opcode_low_byteP = opcode_as_chars[0] + VAX_WIDEN_LONG;
  801. p = frag_more (5);
  802. p [0] = VAX_PC_RELATIVE_MODE;
  803. fix_new (frag_now,
  804. p+1 - frag_now -> fr_literal, 4,
  805. this_add_symbol, 0,
  806. this_add_number, 1);
  807. /* Now eg JMP foo or JSB foo. */
  808. }
  809. else
  810. {
  811. if(operandP -> vop_width == VAX_WIDTH_WORD_JUMP)
  812. {
  813. p = frag_more (10);
  814. p[0] = 0;
  815. p[1] = 2;
  816. p[2] = VAX_BRB;
  817. p[3] = 6;
  818. p[4] = VAX_JMP;
  819. p[5] = VAX_PC_RELATIVE_MODE;
  820. fix_new (frag_now,
  821. p+6 - frag_now -> fr_literal, 4,
  822. this_add_symbol, 0,
  823. this_add_number, 1);
  824. /*
  825. * Now (eg) ACBx 1f
  826. * BRB 2f
  827. * 1: JMP foo
  828. * 2:
  829. */
  830. }
  831. else
  832. {
  833. know( operandP -> vop_width == VAX_WIDTH_BYTE_JUMP);
  834. p = frag_more (10);
  835. p [0] = 2;
  836. p [1] = VAX_BRB;
  837. p [2] = 6;
  838. p [3] = VAX_JMP;
  839. p [4] = VAX_PC_RELATIVE_MODE;
  840. fix_new (frag_now,
  841. p+5 - frag_now -> fr_literal,
  842. 4, this_add_symbol, 0,
  843. this_add_number, 1);
  844. /*
  845. * Now (eg) xOBxxx 1f
  846. * BRB 2f
  847. * 1: JMP foo
  848. * 2:
  849. */
  850. }
  851. }
  852. }
  853. else
  854. {
  855. know( operandP -> vop_width == VAX_WIDTH_CONDITIONAL_JUMP );
  856. * opcode_low_byteP ^= 1; /* Reverse branch condition. */
  857. p = frag_more (7);
  858. p[0] = 6;
  859. p[1] = VAX_JMP;
  860. p[2] = VAX_PC_RELATIVE_MODE;
  861. fix_new (frag_now, p+3 - frag_now -> fr_literal,
  862. 4, this_add_symbol, 0,
  863. this_add_number, 1);
  864. }
  865. }
  866. }
  867. }
  868. }
  869. else
  870. {
  871. know( operandP -> vop_access != 'b' ); /* So it is ordinary operand. */
  872. know( operandP -> vop_access != ' ' ); /* ' ' target-independent: elsewhere. */
  873. know( operandP -> vop_access=='a' || operandP -> vop_access=='m' || operandP -> vop_access=='r' || operandP -> vop_access=='v' || operandP -> vop_access=='w' );
  874. if ( operandP -> vop_short == 's' )
  875. {
  876. if ( to_seg == SEG_ABSOLUTE )
  877. {
  878. if ( this_add_number <0 || this_add_number >= 64 )
  879. {
  880. as_warn("Short literal overflow(%d.), immediate mode assumed.",this_add_number);
  881. operandP -> vop_short = 'i';
  882. operandP -> vop_mode = 8;
  883. operandP -> vop_reg = 0xF;
  884. }
  885. }
  886. else
  887. {
  888. as_warn("Forced short literal to immediate mode. now_seg=%s to_seg=%s", seg_name[(int)now_seg], seg_name[(int)to_seg]);
  889. operandP -> vop_short = 'i';
  890. operandP -> vop_mode = 8;
  891. operandP -> vop_reg = 0xF;
  892. }
  893. }
  894. if ( operandP->vop_reg>=0 && (operandP->vop_mode<8 || (operandP->vop_reg!=0xF && operandP->vop_mode<10)) )
  895. { /* One byte operand. */
  896. know( operandP->vop_mode>3 );
  897. FRAG_APPEND_1_CHAR( operandP->vop_mode<<4 | operandP->vop_reg);
  898. /* All 1-bytes except S^# happen here. */
  899. }
  900. else
  901. { /* {@}{q^}foo{(Rn)} or S^#foo */
  902. if (operandP -> vop_reg == -1 && operandP -> vop_short != 's')
  903. { /* "{@}{q^}foo" */
  904. if ( to_seg == now_seg )
  905. {
  906. if (length == 0)
  907. {
  908. know( operandP -> vop_short == ' ' );
  909. p = frag_var (rs_machine_dependent, 10, 2,
  910. ENCODE_RELAX( STATE_PC_RELATIVE, STATE_BYTE ),
  911. this_add_symbol, this_add_number,
  912. opcode_low_byteP);
  913. know( operandP -> vop_mode == 10 + at );
  914. * p = at << 4;
  915. /* At is the only context we need to carry to */
  916. /* other side of relax() process. */
  917. /* Must be in the correct bit position of VAX */
  918. /* operand spec. byte. */
  919. }
  920. else
  921. {
  922. know( length );
  923. know( operandP -> vop_short != ' ' );
  924. p = frag_more (length+1);
  925. /* JF is this array stuff really going to work? */
  926. p[0] = 0xF | ((at + "?\12\14?\16"[length]) << 4);
  927. fix_new (frag_now, p+1 - frag_now -> fr_literal,
  928. length, this_add_symbol, 0,
  929. this_add_number, 1);
  930. }
  931. }
  932. else
  933. { /* to_seg != now_seg */
  934. if (this_add_symbol == NULL)
  935. {
  936. know( to_seg == SEG_ABSOLUTE );
  937. /* Do @#foo: simpler relocation than foo-.(pc) anyway. */
  938. p = frag_more (5);
  939. p [0] = VAX_ABSOLUTE_MODE; /* @#... */
  940. md_number_to_chars (p+1, this_add_number, 4);
  941. if (length && length != 4)
  942. {
  943. as_warn( "Length specification ignored. Address mode 9F used" );
  944. }
  945. }
  946. else
  947. {
  948. /* {@}{q^}other_seg */
  949. know( (length == 0 && operandP->vop_short == ' ') \
  950. || (length > 0 && operandP->vop_short != ' '));
  951. if (is_undefined)
  952. {
  953. /*
  954. * We have a SEG_UNKNOWN symbol. It might
  955. * turn out to be in the same segment as
  956. * the instruction, permitting relaxation.
  957. */
  958. p = frag_var (rs_machine_dependent, 5, 2,
  959. ENCODE_RELAX( STATE_PC_RELATIVE, STATE_UNDF ),
  960. this_add_symbol, this_add_number,
  961. 0);
  962. p [0] = at << 4;
  963. }
  964. else
  965. {
  966. if (length == 0)
  967. {
  968. know( operandP -> vop_short == ' ' );
  969. length = 4; /* Longest possible. */
  970. }
  971. p = frag_more (length+1);
  972. p [0] = 0xF | ((at + "?\12\14?\16"[length]) << 4);
  973. md_number_to_chars (p+1, this_add_number, length);
  974. fix_new (frag_now,
  975. p+1 - frag_now -> fr_literal,
  976. length, this_add_symbol, 0,
  977. this_add_number, 1);
  978. }
  979. }
  980. }
  981. }
  982. else
  983. { /* {@}{q^}foo(Rn) or S^# or I^# or # */
  984. if ( operandP -> vop_mode < 0xA )
  985. { /* # or S^# or I^# */
  986. /* know( (length == 0 && operandP->vop_short == ' ') \
  987. || (length > 0 && operandP->vop_short != ' ')); */
  988. if ( length == 0
  989. && to_seg == SEG_ABSOLUTE
  990. && operandP -> vop_mode == 8 /* No '@'. */
  991. && this_add_number < 64
  992. && this_add_number >= 0)
  993. {
  994. operandP -> vop_short = 's';
  995. }
  996. if ( operandP -> vop_short == 's' )
  997. {
  998. FRAG_APPEND_1_CHAR( this_add_number );
  999. }
  1000. else
  1001. { /* I^#... */
  1002. know( nbytes );
  1003. p = frag_more (nbytes+1);
  1004. know( operandP -> vop_reg == 0xF );
  1005. p [0] = (operandP->vop_mode << 4) | 0xF;
  1006. if (to_seg == SEG_ABSOLUTE)
  1007. {
  1008. /*
  1009. * If nbytes > 4, then we are scrod. We don't know if the
  1010. * high order bytes are to be 0xFF or 0x00.
  1011. * BSD4.2 & RMS say use 0x00. OK --- but this
  1012. * assembler needs ANOTHER rewrite to
  1013. * cope properly with this bug.
  1014. */
  1015. md_number_to_chars (p+1, this_add_number, min( 4, nbytes ));
  1016. if (nbytes > 4)
  1017. {
  1018. bzero (p+5, nbytes - 4);
  1019. }
  1020. }
  1021. else
  1022. {
  1023. if (to_seg == SEG_BIG)
  1024. {
  1025. /*
  1026. * Problem here is to get the bytes in the right order.
  1027. * We stored our constant as LITTLENUMs, not bytes.
  1028. */
  1029. LITTLENUM_TYPE * lP;
  1030. lP = floatP -> low;
  1031. if (nbytes & 1)
  1032. {
  1033. know( nbytes == 1 );
  1034. p [1] = * lP;
  1035. }
  1036. else
  1037. {
  1038. for (p ++; nbytes; nbytes -= 2, p += 2, lP ++)
  1039. {
  1040. md_number_to_chars (p, *lP, 2);
  1041. }
  1042. }
  1043. }
  1044. else
  1045. {
  1046. fix_new (frag_now, p+1 - frag_now->fr_literal,
  1047. nbytes, this_add_symbol, 0,
  1048. this_add_number, 0);
  1049. }
  1050. }
  1051. }
  1052. }
  1053. else
  1054. { /* {@}{q^}foo(Rn) */
  1055. know( (length == 0 && operandP->vop_short == ' ') \
  1056. || (length > 0 && operandP->vop_short != ' '));
  1057. if (length == 0)
  1058. {
  1059. if ( to_seg == SEG_ABSOLUTE )
  1060. {
  1061. register long int test;
  1062. test = this_add_number;
  1063. if(test<0) test = ~ test;
  1064. length = test & 0xffff8000 ? 4
  1065. : test & 0xffffff80 ? 2
  1066. : 1;
  1067. }
  1068. else
  1069. {
  1070. length = 4;
  1071. }
  1072. }
  1073. p = frag_more (1 + length);
  1074. know( operandP -> vop_reg >= 0 );
  1075. p [0] = operandP -> vop_reg
  1076. | ((at | "?\12\14?\16"[length]) << 4);
  1077. if (to_seg == SEG_ABSOLUTE)
  1078. {
  1079. md_number_to_chars( p+1, this_add_number, length );
  1080. }
  1081. else
  1082. {
  1083. fix_new (frag_now, p+1 - frag_now -> fr_literal,
  1084. length, this_add_symbol, 0,
  1085. this_add_number, 0);
  1086. }
  1087. }
  1088. }
  1089. } /* if(single-byte-operand) */
  1090. }
  1091. } /* for(operandP) */
  1092. } /* if(!need_pass_2&&!goofed) */
  1093. } /* vax_assemble() */
  1094. /*
  1095. * md_estimate_size_before_relax()
  1096. *
  1097. * Called just before relax().
  1098. * Any symbol that is now undefined will not become defined.
  1099. * Return the correct fr_subtype in the frag.
  1100. * Return the initial "guess for fr_var" to caller.
  1101. * The guess for fr_var is ACTUALLY the growth beyond fr_fix.
  1102. * Whatever we do to grow fr_fix or fr_var contributes to our returned value.
  1103. * Although it may not be explicit in the frag, pretend fr_var starts with a
  1104. * 0 value.
  1105. */
  1106. int
  1107. md_estimate_size_before_relax (fragP, segment_type)
  1108. register fragS * fragP;
  1109. register int segment_type; /* N_DATA or N_TEXT. */
  1110. {
  1111. register char * p;
  1112. register int old_fr_fix;
  1113. old_fr_fix = fragP -> fr_fix;
  1114. switch (fragP -> fr_subtype)
  1115. {
  1116. case ENCODE_RELAX( STATE_PC_RELATIVE, STATE_UNDF ):
  1117. if ((fragP -> fr_symbol -> sy_type & N_TYPE) == segment_type)
  1118. { /* A relaxable case. */
  1119. fragP -> fr_subtype = ENCODE_RELAX( STATE_PC_RELATIVE, STATE_BYTE );
  1120. }
  1121. else
  1122. {
  1123. p = fragP -> fr_literal + old_fr_fix;
  1124. p [0] |= VAX_PC_RELATIVE_MODE; /* Preserve @ bit. */
  1125. fragP -> fr_fix += 1 + 4;
  1126. fix_new (fragP, old_fr_fix + 1, 4, fragP -> fr_symbol, 0,
  1127. fragP -> fr_offset, 1);
  1128. frag_wane (fragP);
  1129. }
  1130. break;
  1131. case ENCODE_RELAX( STATE_CONDITIONAL_BRANCH, STATE_UNDF ):
  1132. if ((fragP -> fr_symbol -> sy_type & N_TYPE) == segment_type)
  1133. {
  1134. fragP -> fr_subtype = ENCODE_RELAX( STATE_CONDITIONAL_BRANCH, STATE_BYTE );
  1135. }
  1136. else
  1137. {
  1138. p = fragP -> fr_literal + old_fr_fix;
  1139. * fragP -> fr_opcode ^= 1; /* Reverse sense of branch. */
  1140. p [0] = 6;
  1141. p [1] = VAX_JMP;
  1142. p [2] = VAX_PC_RELATIVE_MODE; /* ...(PC) */
  1143. fragP -> fr_fix += 1 + 1+1+4;
  1144. fix_new (fragP, old_fr_fix + 3, 4, fragP -> fr_symbol, 0,
  1145. fragP -> fr_offset, 1);
  1146. frag_wane (fragP);
  1147. }
  1148. break;
  1149. case ENCODE_RELAX( STATE_COMPLEX_BRANCH, STATE_UNDF ):
  1150. if ((fragP -> fr_symbol -> sy_type & N_TYPE) == segment_type)
  1151. {
  1152. fragP -> fr_subtype = ENCODE_RELAX( STATE_COMPLEX_BRANCH, STATE_WORD );
  1153. }
  1154. else
  1155. {
  1156. p = fragP -> fr_literal + old_fr_fix;
  1157. p [0] = 2;
  1158. p [1] = 0;
  1159. p [2] = VAX_BRB;
  1160. p [3] = 6;
  1161. p [4] = VAX_JMP;
  1162. p [5] = VAX_PC_RELATIVE_MODE; /* ...(pc) */
  1163. fragP -> fr_fix += 2 + 2 + 1+1+4;
  1164. fix_new (fragP, old_fr_fix + 6, 4, fragP -> fr_symbol, 0,
  1165. fragP -> fr_offset, 1);
  1166. frag_wane (fragP);
  1167. }
  1168. break;
  1169. case ENCODE_RELAX( STATE_COMPLEX_HOP, STATE_UNDF ):
  1170. if ((fragP -> fr_symbol -> sy_type & N_TYPE) == segment_type)
  1171. {
  1172. fragP -> fr_subtype = ENCODE_RELAX( STATE_COMPLEX_HOP, STATE_BYTE );
  1173. }
  1174. else
  1175. {
  1176. p = fragP -> fr_literal + old_fr_fix;
  1177. p [0] = 2;
  1178. p [1] = VAX_BRB;
  1179. p [2] = 6;
  1180. p [3] = VAX_JMP;
  1181. p [4] = VAX_PC_RELATIVE_MODE; /* ...(pc) */
  1182. fragP -> fr_fix += 1 + 2 + 1+1+4;
  1183. fix_new (fragP, old_fr_fix + 5, 4, fragP -> fr_symbol, 0,
  1184. fragP -> fr_offset, 1);
  1185. frag_wane (fragP);
  1186. }
  1187. break;
  1188. case ENCODE_RELAX( STATE_ALWAYS_BRANCH, STATE_UNDF ):
  1189. if ((fragP -> fr_symbol -> sy_type & N_TYPE) == segment_type)
  1190. {
  1191. fragP -> fr_subtype = ENCODE_RELAX( STATE_ALWAYS_BRANCH, STATE_BYTE );
  1192. }
  1193. else
  1194. {
  1195. p = fragP -> fr_literal + old_fr_fix;
  1196. * fragP -> fr_opcode += VAX_WIDEN_LONG;
  1197. p [0] = VAX_PC_RELATIVE_MODE; /* ...(PC) */
  1198. fragP -> fr_fix += 1+4;
  1199. fix_new (fragP, old_fr_fix + 1, 4, fragP -> fr_symbol, 0,
  1200. fragP -> fr_offset, 1);
  1201. frag_wane (fragP);
  1202. }
  1203. break;
  1204. default:
  1205. break;
  1206. }
  1207. return (fragP -> fr_var + fragP -> fr_fix - old_fr_fix);
  1208. } /* md_estimate_size_before_relax() */
  1209. /*
  1210. * md_convert_frag();
  1211. *
  1212. * Called after relax() is finished.
  1213. * In: Address of frag.
  1214. * fr_type == rs_machine_dependent.
  1215. * fr_subtype is what the address relaxed to.
  1216. *
  1217. * Out: Any fixSs and constants are set up.
  1218. * Caller will turn frag into a ".space 0".
  1219. */
  1220. void
  1221. md_convert_frag (fragP)
  1222. register fragS * fragP;
  1223. {
  1224. register char * addressP; /* -> _var to change. */
  1225. register char * opcodeP; /* -> opcode char(s) to change. */
  1226. register short int length_code; /* 2=long 1=word 0=byte */
  1227. register short int extension; /* Size of relaxed address. */
  1228. /* Added to fr_fix: incl. ALL var chars. */
  1229. register symbolS * symbolP;
  1230. register long int where;
  1231. register long int address_of_var;
  1232. /* Where, in file space, is _var of *fragP? */
  1233. register long int target_address;
  1234. /* Where, in file space, does addr point? */
  1235. know (fragP -> fr_type == rs_machine_dependent );
  1236. length_code = fragP -> fr_subtype & 3; /* depends on ENCODE_RELAX() */
  1237. know( length_code >= 0 && length_code < 3 );
  1238. where = fragP -> fr_fix;
  1239. addressP = fragP -> fr_literal + where;
  1240. opcodeP = fragP -> fr_opcode;
  1241. symbolP = fragP -> fr_symbol;
  1242. know( symbolP );
  1243. target_address = symbolP -> sy_value + fragP -> fr_offset;
  1244. address_of_var = fragP -> fr_address + where;
  1245. switch ( fragP -> fr_subtype )
  1246. {
  1247. case ENCODE_RELAX( STATE_PC_RELATIVE, STATE_BYTE):
  1248. know( *addressP == 0 || *addressP == 0x10 ); /* '@' bit. */
  1249. addressP [0] |= 0xAF; /* Byte displacement. */
  1250. addressP [1] = target_address - (address_of_var + 2);
  1251. extension = 2;
  1252. break;
  1253. case ENCODE_RELAX( STATE_PC_RELATIVE, STATE_WORD):
  1254. know( *addressP == 0 || *addressP == 0x10 ); /* '@' bit. */
  1255. addressP [0] |= 0xCF; /* Word displacement. */
  1256. md_number_to_chars (addressP+1, target_address - (address_of_var + 3), 2);
  1257. extension = 3;
  1258. break;
  1259. case ENCODE_RELAX( STATE_PC_RELATIVE, STATE_LONG):
  1260. know( *addressP == 0 || *addressP == 0x10 ); /* '@' bit. */
  1261. addressP [0] |= 0xEF; /* Long word displacement. */
  1262. md_number_to_chars (addressP+1, target_address - (address_of_var + 5), 4);
  1263. extension = 5;
  1264. break;
  1265. case ENCODE_RELAX( STATE_CONDITIONAL_BRANCH, STATE_BYTE):
  1266. addressP [0] = target_address - (address_of_var + 1);
  1267. extension = 1;
  1268. break;
  1269. case ENCODE_RELAX( STATE_CONDITIONAL_BRANCH, STATE_WORD):
  1270. opcodeP [0] ^= 1; /* Reverse sense of test. */
  1271. addressP [0] = 3;
  1272. addressP [1] = VAX_BRB + VAX_WIDEN_WORD;
  1273. md_number_to_chars (addressP+2, target_address - (address_of_var + 4), 2);
  1274. extension = 4;
  1275. break;
  1276. case ENCODE_RELAX( STATE_CONDITIONAL_BRANCH, STATE_LONG):
  1277. opcodeP [0] ^= 1; /* Reverse sense of test. */
  1278. addressP [0] = 6;
  1279. addressP [1] = VAX_JMP;
  1280. addressP [2] = VAX_PC_RELATIVE_MODE;
  1281. md_number_to_chars (addressP+3, target_address, 4);
  1282. extension = 7;
  1283. break;
  1284. case ENCODE_RELAX( STATE_ALWAYS_BRANCH, STATE_BYTE):
  1285. addressP [0] = target_address - (address_of_var + 1);
  1286. extension = 1;
  1287. break;
  1288. case ENCODE_RELAX( STATE_ALWAYS_BRANCH, STATE_WORD):
  1289. opcodeP [0] += VAX_WIDEN_WORD; /* brb -> brw, bsbb -> bsbw */
  1290. md_number_to_chars (addressP, target_address - (address_of_var + 2), 2);
  1291. extension = 2;
  1292. break;
  1293. case ENCODE_RELAX( STATE_ALWAYS_BRANCH, STATE_LONG):
  1294. opcodeP [0] += VAX_WIDEN_LONG; /* brb -> jmp, bsbb -> jsb */
  1295. addressP [0] = VAX_PC_RELATIVE_MODE;
  1296. md_number_to_chars (addressP+1, target_address - (address_of_var + 5), 4);
  1297. extension = 5;
  1298. break;
  1299. case ENCODE_RELAX( STATE_COMPLEX_BRANCH, STATE_WORD):
  1300. md_number_to_chars (addressP, target_address - (address_of_var + 2), 2);
  1301. extension = 2;
  1302. break;
  1303. case ENCODE_RELAX( STATE_COMPLEX_BRANCH, STATE_LONG):
  1304. addressP [0] = 2;
  1305. addressP [1] = 0;
  1306. addressP [2] = VAX_BRB;
  1307. addressP [3] = 6;
  1308. addressP [4] = VAX_JMP;
  1309. addressP [5] = VAX_PC_RELATIVE_MODE;
  1310. md_number_to_chars (addressP+6, target_address, 4);
  1311. extension = 10;
  1312. break;
  1313. case ENCODE_RELAX( STATE_COMPLEX_HOP, STATE_BYTE):
  1314. addressP [0] = target_address - (address_of_var + 1);
  1315. extension = 1;
  1316. break;
  1317. case ENCODE_RELAX( STATE_COMPLEX_HOP, STATE_WORD):
  1318. addressP [0] = 2;
  1319. addressP [1] = VAX_BRB;
  1320. addressP [2] = 3;
  1321. addressP [3] = VAX_BRW;
  1322. md_number_to_chars (addressP+4, target_address - (address_of_var + 6), 2);
  1323. extension = 6;
  1324. break;
  1325. case ENCODE_RELAX( STATE_COMPLEX_HOP, STATE_LONG):
  1326. addressP [0] = 2;
  1327. addressP [1] = VAX_BRB;
  1328. addressP [2] = 6;
  1329. addressP [3] = VAX_JMP;
  1330. addressP [4] = VAX_PC_RELATIVE_MODE;
  1331. md_number_to_chars (addressP+5, target_address, 4);
  1332. extension = 9;
  1333. break;
  1334. default:
  1335. BAD_CASE( fragP -> fr_subtype );
  1336. break;
  1337. }
  1338. fragP -> fr_fix += extension;
  1339. }
  1340. /* the bit-field entries in the relocation_info struct plays hell
  1341. with the byte-order problems of cross-assembly. So as a hack,
  1342. I added this mach. dependent ri twiddler. Ugly, but it gets
  1343. you there. -KWK */
  1344. /* on vax: first 4 bytes are normal unsigned long, next three bytes
  1345. are symbolnum, least sig. byte first. Last byte is broken up with
  1346. the upper nibble as nuthin, bit 3 as extern, bits 2 & 1 as length, and
  1347. bit 0 as pcrel. */
  1348. void md_ri_to_chars(ri_p, ri)
  1349. struct relocation_info *ri_p, ri;
  1350. {
  1351. unsigned char the_bytes[8];
  1352. /* this is easy */
  1353. md_number_to_chars(the_bytes, ri.r_address, sizeof(ri.r_address));
  1354. /* now the fun stuff */
  1355. the_bytes[6] = (ri.r_symbolnum >> 16) & 0x0ff;
  1356. the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
  1357. the_bytes[4] = ri.r_symbolnum & 0x0ff;
  1358. the_bytes[7] = (((ri.r_extern << 3) & 0x08) | ((ri.r_length << 1) & 0x06) |
  1359. ((ri.r_pcrel << 0) & 0x01)) & 0x0F;
  1360. /* now put it back where you found it */
  1361. bcopy (the_bytes, (char *)ri_p, sizeof(struct relocation_info));
  1362. }
  1363. /* JF this used to be a separate file */
  1364. /* vax_ins_parse.c - a part for a VAX assembler */
  1365. /* Copyright (C) 1987 Free Software Foundtation, Inc */
  1366. /*
  1367. * BUGS, GRIPES, APOLOGIA, etc.
  1368. *
  1369. * The opcode table 'votstrs' needs to be sorted on opcode frequency.
  1370. * That is, AFTER we hash it with hash_...(), we want most-used opcodes
  1371. * to come out of the hash table faster.
  1372. *
  1373. * I am sorry to inflict
  1374. * yet another VAX assembler on the world, but RMS says we must
  1375. * do everything from scratch, to prevent pin-heads restricting
  1376. * this software.
  1377. */
  1378. /*
  1379. * This is a vaguely modular set of routines in C to parse VAX
  1380. * assembly code using DEC mnemonics. It is NOT un*x specific.
  1381. *
  1382. * The idea here is that the assembler has taken care of all:
  1383. * labels
  1384. * macros
  1385. * listing
  1386. * pseudo-ops
  1387. * line continuation
  1388. * comments
  1389. * condensing any whitespace down to exactly one space
  1390. * and all we have to do is parse 1 line into a vax instruction
  1391. * partially formed. We will accept a line, and deliver:
  1392. * an error message (hopefully empty)
  1393. * a skeleton VAX instruction (tree structure)
  1394. * textual pointers to all the operand expressions
  1395. * a warning message that notes a silly operand (hopefully empty)
  1396. */
  1397. /*
  1398. * E D I T H I S T O R Y
  1399. *
  1400. * 17may86 Dean Elsner. Bug if line ends immediately after opcode.
  1401. * 30apr86 Dean Elsner. New vip_op() uses arg block so change call.
  1402. * 6jan86 Dean Elsner. Crock vip_begin() to call vip_op_defaults().
  1403. * 2jan86 Dean Elsner. Invent synthetic opcodes.
  1404. * Widen vax_opcodeT to 32 bits. Use a bit for VIT_OPCODE_SYNTHETIC,
  1405. * which means this is not a real opcode, it is like a macro; it will
  1406. * be relax()ed into 1 or more instructions.
  1407. * Use another bit for VIT_OPCODE_SPECIAL if the op-code is not optimised
  1408. * like a regular branch instruction. Option added to vip_begin():
  1409. * exclude synthetic opcodes. Invent synthetic_votstrs[].
  1410. * 31dec85 Dean Elsner. Invent vit_opcode_nbytes.
  1411. * Also make vit_opcode into a char[]. We now have n-byte vax opcodes,
  1412. * so caller's don't have to know the difference between a 1-byte & a
  1413. * 2-byte op-code. Still need vax_opcodeT concept, so we know how
  1414. * big an object must be to hold an op.code.
  1415. * 30dec85 Dean Elsner. Widen typedef vax_opcodeT in "vax-inst.h"
  1416. * because vax opcodes may be 16 bits. Our crufty C compiler was
  1417. * happily initialising 8-bit vot_codes with 16-bit numbers!
  1418. * (Wouldn't the 'phone company like to compress data so easily!)
  1419. * 29dec85 Dean Elsner. New static table vax_operand_width_size[].
  1420. * Invented so we know hw many bytes a "I^#42" needs in its immediate
  1421. * operand. Revised struct vop in "vax-inst.h": explicitly include
  1422. * byte length of each operand, and it's letter-code datum type.
  1423. * 17nov85 Dean Elsner. Name Change.
  1424. * Due to ar(1) truncating names, we learned the hard way that
  1425. * "vax-inst-parse.c" -> "vax-inst-parse." dropping the "o" off
  1426. * the archived object name. SO... we shortened the name of this
  1427. * source file, and changed the makefile.
  1428. */
  1429. /* #include <stdio.h> JF for one big happy file */
  1430. /* JF #include "vax-inst.h" /* define the tree we parse it into */
  1431. static char * op_hash = NULL; /* handle of the OPCODE hash table */
  1432. /* NULL means any use before vip_begin() */
  1433. /* will crash */
  1434. /*
  1435. * In: 1 character, from "bdfghloqpw" being the data-type of an operand
  1436. * of a vax instruction.
  1437. *
  1438. * Out: the length of an operand of that type, in bytes.
  1439. * Special branch operands types "-?!" have length 0.
  1440. */
  1441. static short int vax_operand_width_size [256] = {
  1442. #define _ 0
  1443. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
  1444. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
  1445. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
  1446. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
  1447. _, _, 1, _, 8, _, 4, 8,16, _, _, _, 4, _, _,16, /* ..b.d.fgh...l..o */
  1448. _, 8, _, _, _, _, _, 2, _, _, _, _, _, _, _, _, /* .q.....w........ */
  1449. _, _, 1, _, 8, _, 4, 8,16, _, _, _, 4, _, _,16, /* ..b.d.fgh...l..o */
  1450. _, 8, _, _, _, _, _, 2, _, _, _, _, _, _, _, _, /* .q.....w........ */
  1451. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
  1452. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
  1453. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
  1454. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
  1455. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
  1456. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
  1457. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
  1458. _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _};
  1459. #undef _
  1460. /*
  1461. * This perversion encodes all the vax opcodes as a bunch of strings.
  1462. * RMS says we should build our hash-table at run-time. Hmm.
  1463. * Please would someone arrange these in decreasing frequency of opcode?
  1464. * Because of the way hash_...() works, the most frequently used opcode
  1465. * should be textually first and so on.
  1466. *
  1467. * Input for this table was 'vax.opcodes', awk(1)ed by 'vax.opcodes.c.awk' .
  1468. * So change 'vax.opcodes', then re-generate this table.
  1469. */
  1470. #include "vax-opcode.h"
  1471. /*
  1472. * This is a table of optional op-codes. All of them represent
  1473. * 'synthetic' instructions that seem popular.
  1474. *
  1475. * Here we make some pseudo op-codes. Every code has a bit set to say
  1476. * it is synthetic. This lets you catch them if you want to
  1477. * ban these opcodes. They are mnemonics for "elastic" instructions
  1478. * that are supposed to assemble into the fewest bytes needed to do a
  1479. * branch, or to do a conditional branch, or whatever.
  1480. *
  1481. * The opcode is in the usual place [low-order n*8 bits]. This means
  1482. * that if you mask off the bucky bits, the usual rules apply about
  1483. * how long the opcode is.
  1484. *
  1485. * All VAX branch displacements come at the end of the instruction.
  1486. * For simple branches (1-byte opcode + 1-byte displacement) the last
  1487. * operand is coded 'b?' where the "data type" '?' is a clue that we
  1488. * may reverse the sense of the branch (complement lowest order bit)
  1489. * and branch around a jump. This is by far the most common case.
  1490. * That is why the VIT_OPCODE_SYNTHETIC bit is set: it says this is
  1491. * a 0-byte op-code followed by 2 or more bytes of operand address.
  1492. *
  1493. * If the op-code has VIT_OPCODE_SPECIAL set, then we have a more unusual
  1494. * case.
  1495. *
  1496. * For JBSB & JBR the treatment is the similar, except (1) we have a 'bw'
  1497. * option before (2) we can directly JSB/JMP because there is no condition.
  1498. * These operands have 'b-' as their access/data type.
  1499. *
  1500. * That leaves a bunch of random opcodes: JACBx, JxOBxxx. In these
  1501. * cases, we do the same idea. JACBxxx are all marked with a 'b!'
  1502. * JAOBxxx & JSOBxxx are marked with a 'b:'.
  1503. *
  1504. */
  1505. #if (VIT_OPCODE_SYNTHETIC != 0x80000000)
  1506. You have just broken the encoding below, which assumes the sign bit
  1507. means 'I am an imaginary instruction'.
  1508. #endif
  1509. #if (VIT_OPCODE_SPECIAL != 0x40000000)
  1510. You have just broken the encoding below, which assumes the 0x40M bit means
  1511. 'I am not to be "optimised" the way normal branches are'.
  1512. #endif
  1513. static struct vot
  1514. synthetic_votstrs[] =
  1515. {
  1516. { "jbsb", {"b-", 0xC0000010 } }, /* BSD 4.2 */
  1517. /* jsb used already */
  1518. { "jbr", {"b-", 0xC0000011 } }, /* BSD 4.2 */
  1519. { "jr", {"b-", 0xC0000011 } }, /* consistent */
  1520. { "jneq", {"b?", 0x80000012 } },
  1521. { "jnequ", {"b?", 0x80000012 } },
  1522. { "jeql", {"b?", 0x80000013 } },
  1523. { "jeqlu", {"b?", 0x80000013 } },
  1524. { "jgtr", {"b?", 0x80000014 } },
  1525. { "jleq", {"b?", 0x80000015 } },
  1526. /* un-used opcodes here */
  1527. { "jgeq", {"b?", 0x80000018 } },
  1528. { "jlss", {"b?", 0x80000019 } },
  1529. { "jgtru", {"b?", 0x8000001a } },
  1530. { "jlequ", {"b?", 0x8000001b } },
  1531. { "jvc", {"b?", 0x8000001c } },
  1532. { "jvs", {"b?", 0x8000001d } },
  1533. { "jgequ", {"b?", 0x8000001e } },
  1534. { "jcc", {"b?", 0x8000001e } },
  1535. { "jlssu", {"b?", 0x8000001f } },
  1536. { "jcs", {"b?", 0x8000001f } },
  1537. { "jacbw", {"rwrwmwb!", 0xC000003d } },
  1538. { "jacbf", {"rfrfmfb!", 0xC000004f } },
  1539. { "jacbd", {"rdrdmdb!", 0xC000006f } },
  1540. { "jacbb", {"rbrbmbb!", 0xC000009d } },
  1541. { "jacbl", {"rlrlmlb!", 0xC00000f1 } },
  1542. { "jacbg", {"rgrgmgb!", 0xC0004ffd } },
  1543. { "jacbh", {"rhrhmhb!", 0xC0006ffd } },
  1544. { "jbs", {"rlvbb?", 0x800000e0 } },
  1545. { "jbc", {"rlvbb?", 0x800000e1 } },
  1546. { "jbss", {"rlvbb?", 0x800000e2 } },
  1547. { "jbcs", {"rlvbb?", 0x800000e3 } },
  1548. { "jbsc", {"rlvbb?", 0x800000e4 } },
  1549. { "jbcc", {"rlvbb?", 0x800000e5 } },
  1550. { "jbssi", {"rlvbb?", 0x800000e6 } },
  1551. { "jbcci", {"rlvbb?", 0x800000e7 } },
  1552. { "jlbs", {"rlb?", 0x800000e8 } }, /* JF changed from rlvbb? */
  1553. { "jlbc", {"rlb?", 0x800000e9 } }, /* JF changed from rlvbb? */
  1554. { "jaoblss", {"rlmlb:", 0xC00000f2 } },
  1555. { "jaobleq", {"rlmlb:", 0xC00000f3 } },
  1556. { "jsobgeq", {"mlb:", 0xC00000f4 } },/* JF was rlmlb: */
  1557. { "jsobgtr", {"mlb:", 0xC00000f5 } },/* JF was rlmlb: */
  1558. /* CASEx has no branch addresses in our conception of it. */
  1559. /* You should use ".word ..." statements after the "case ...". */
  1560. { "" , "" } /* empty is end sentinel */
  1561. }; /* synthetic_votstrs */
  1562. /*
  1563. * v i p _ b e g i n ( )
  1564. *
  1565. * Call me once before you decode any lines.
  1566. * I decode votstrs into a hash table at op_hash (which I create).
  1567. * I return an error text: hopefully "".
  1568. * If you want, I will include the 'synthetic' jXXX instructions in the
  1569. * instruction table.
  1570. * You must nominate metacharacters for eg DEC's "#", "@", "^".
  1571. */
  1572. char *
  1573. vip_begin(synthetic_too, immediate, indirect, displen)
  1574. int synthetic_too; /* TRUE means include jXXX op-codes. */
  1575. char * immediate,
  1576. * indirect,
  1577. * displen;
  1578. {
  1579. register struct vot * vP; /* scan votstrs */
  1580. register char * retval; /* error text */
  1581. char * hash_insert(); /* */
  1582. char * hash_new(); /* lies */
  1583. if ( (op_hash = hash_new()) )
  1584. {
  1585. retval = ""; /* OK so far */
  1586. for (vP=votstrs; *vP->vot_name && !*retval; vP++)
  1587. {
  1588. retval = hash_insert(op_hash, vP->vot_name, &vP->vot_detail);
  1589. }
  1590. if ( synthetic_too )
  1591. {
  1592. for (vP=synthetic_votstrs; *vP->vot_name && !*retval; vP++)
  1593. {
  1594. retval = hash_insert(op_hash, vP->vot_name, &vP->vot_detail);
  1595. }
  1596. }
  1597. }
  1598. else
  1599. {
  1600. retval="virtual memory exceeded";
  1601. }
  1602. vip_op_defaults (immediate, indirect, displen);
  1603. return (retval);
  1604. }
  1605. /*
  1606. * v i p _ e n d ( )
  1607. *
  1608. * Call me once after you have decoded all lines.
  1609. * I do any cleaning-up needed.
  1610. *
  1611. * We don't have to do any cleanup ourselves: all of our operand
  1612. * symbol table is static, and free()ing it is naughty.
  1613. */
  1614. vip_end()
  1615. {
  1616. }
  1617. /*
  1618. * v i p ( )
  1619. *
  1620. * This converts a string into a vax instruction.
  1621. * The string must be a bare single instruction in dec-vax (with BSD4 frobs)
  1622. * format.
  1623. * It provides some error messages: at most one fatal error message (which
  1624. * stops the scan) and at most one warning message for each operand.
  1625. * The vax instruction is returned in exploded form, since we have no
  1626. * knowledge of how you parse (or evaluate) your expressions.
  1627. * We do however strip off and decode addressing modes and operation
  1628. * mnemonic.
  1629. *
  1630. * The exploded instruction is returned to a struct vit of your choice.
  1631. * #include "vax-inst.h" to know what a struct vit is.
  1632. *
  1633. * This function's value is a string. If it is not "" then an internal
  1634. * logic error was found: read this code to assign meaning to the string.
  1635. * No argument string should generate such an error string:
  1636. * it means a bug in our code, not in the user's text.
  1637. *
  1638. * You MUST have called vip_begin() once and vip_end() never before using
  1639. * this function.
  1640. */
  1641. char * /* "" or bug string */
  1642. vip (vitP, instring)
  1643. struct vit * vitP; /* We build an exploded instruction here. */
  1644. char * instring; /* Text of a vax instruction: we modify. */
  1645. {
  1646. register struct vot_wot * vwP; /* How to bit-encode this opcode. */
  1647. register char * p; /* 1/skip whitespace.2/scan vot_how */
  1648. register char * q; /* */
  1649. register char * bug; /* "" or program logic error */
  1650. register unsigned char count; /* counts number of operands seen */
  1651. register struct vop * operandp; /* scan operands in struct vit */
  1652. register char * alloperr; /* error over all operands */
  1653. register char c; /* Remember char, (we clobber it */
  1654. /* with '\0' temporarily). */
  1655. register vax_opcodeT oc; /* Op-code of this instruction. */
  1656. struct vot_wot * hash_find();
  1657. char * vip_op();
  1658. bug = "";
  1659. if (* instring == ' ')
  1660. ++ instring; /* Skip leading whitespace. */
  1661. for ( p=instring; *p && *p!=' '; p++)
  1662. ; /* MUST end in end-of-string or exactly 1 space. */
  1663. /* Scanned up to end of operation-code. */
  1664. /* Operation-code is ended with whitespace. */
  1665. if (p-instring == 0)
  1666. {
  1667. vitP -> vit_error = "No operator";
  1668. count = 0;
  1669. bzero (vitP -> vit_opcode, sizeof(vitP -> vit_opcode) );
  1670. }
  1671. else
  1672. {
  1673. c = *p;
  1674. *p = '\0';
  1675. /*
  1676. * Here with instring pointing to what better be an op-name, and p
  1677. * pointing to character just past that.
  1678. * We trust instring points to an op-name, with no whitespace.
  1679. */
  1680. vwP = hash_find (op_hash, instring);
  1681. * p = c; /* Restore char after op-code. */
  1682. if ( vwP == 0)
  1683. {
  1684. vitP -> vit_error = "Unknown operator";
  1685. count = 0;
  1686. bzero (vitP -> vit_opcode, sizeof(vitP -> vit_opcode) );
  1687. }
  1688. else
  1689. {
  1690. /*
  1691. * We found a match! So lets pick up as many operands as the
  1692. * instruction wants, and even gripe if there are too many.
  1693. * We expect comma to seperate each operand.
  1694. * We let instring track the text, while p tracks a part of the
  1695. * struct vot.
  1696. */
  1697. /*
  1698. * The lines below know about 2-byte opcodes starting FD,FE or FF.
  1699. * They also understand synthetic opcodes. Note:
  1700. * we return 32 bits of opcode, including bucky bits, BUT
  1701. * an opcode length is either 8 or 16 bits for vit_opcode_nbytes.
  1702. */
  1703. oc = vwP -> vot_code; /* The op-code. */
  1704. vitP -> vit_opcode_nbytes = (oc & 0xFF) >= 0xFD ? 2 : 1;
  1705. md_number_to_chars (vitP -> vit_opcode, oc, 4);
  1706. count = 0; /* no operands seen yet */
  1707. instring = p; /* point just past operation code */
  1708. alloperr = "";
  1709. for ( p = vwP -> vot_how, operandp = vitP -> vit_operand;
  1710. !*alloperr && !*bug && *p;
  1711. operandp++, p += 2
  1712. )
  1713. {
  1714. /*
  1715. * Here to parse one operand. Leave instring pointing just
  1716. * past any one ',' that marks the end of this operand.
  1717. */
  1718. if (!p[1])
  1719. bug = "p"; /* ODD(!!) number of bytes in vot_how?? */
  1720. else if (*instring)
  1721. {
  1722. for ( q=instring; (c = *q) && c!=','; q++)
  1723. ;
  1724. /*
  1725. * Q points to ',' or '\0' that ends argument. C is that
  1726. * character.
  1727. */
  1728. *q = 0;
  1729. operandp -> vop_width = p[1];
  1730. operandp -> vop_nbytes = vax_operand_width_size [p [1]];
  1731. operandp -> vop_access = p[0];
  1732. bug = vip_op (instring, operandp);
  1733. *q = c; /* Restore input text. */
  1734. if ( * (operandp->vop_error) )
  1735. alloperr = "Bad operand";
  1736. instring = q + (c?1:0); /* next operand (if any) */
  1737. count++; /* won another argument, may have an operr */
  1738. }
  1739. else
  1740. alloperr = "Not enough operands";
  1741. }
  1742. if (!*alloperr)
  1743. {
  1744. if (* instring == ' ')
  1745. instring++; /* Skip whitespace. */
  1746. if (*instring)
  1747. alloperr = "Too many operands";
  1748. }
  1749. vitP -> vit_error = alloperr;
  1750. }
  1751. }
  1752. vitP -> vit_operands = count;
  1753. return(bug);
  1754. }
  1755. #ifdef test
  1756. /*
  1757. * Test program for above.
  1758. */
  1759. struct vit myvit; /* build an exploded vax instruction here */
  1760. char answer[100]; /* human types a line of vax assembler here */
  1761. char * mybug; /* "" or an internal logic diagnostic */
  1762. int mycount; /* number of operands */
  1763. struct vop * myvop; /* scan operands from myvit */
  1764. int mysynth; /* TRUE means want synthetic opcodes. */
  1765. char my_immediate[200];
  1766. char my_indirect[200];
  1767. char my_displen[200];
  1768. char * vip();
  1769. main()
  1770. {
  1771. char * p;
  1772. char * vip_begin();
  1773. printf("0 means no synthetic instructions. ");
  1774. printf("Value for vip_begin? ");
  1775. gets(answer);
  1776. sscanf(answer,"%d",&mysynth);
  1777. printf("Synthetic opcodes %s be included.\n", mysynth ? "will" : "will not" );
  1778. printf("enter immediate symbols eg enter # ");
  1779. gets(my_immediate);
  1780. printf("enter indirect symbols eg enter @ ");
  1781. gets(my_indirect);
  1782. printf("enter displen symbols eg enter ^ ");
  1783. gets(my_displen);
  1784. if ( * (p = vip_begin (mysynth, my_immediate, my_indirect, my_displen) ) )
  1785. {
  1786. error("vip_begin=%s",p);
  1787. }
  1788. printf("An empty input line will quit you from the vax instruction parser\n");
  1789. for(;;)
  1790. {
  1791. printf ("vax instruction: ");
  1792. fflush (stdout);
  1793. gets (answer);
  1794. if (!*answer)
  1795. {
  1796. break; /* out of for each input text loop */
  1797. }
  1798. mybug = vip (&myvit, answer);
  1799. if (*mybug)
  1800. {
  1801. printf ("BUG:\"%s\"\n",mybug);
  1802. }
  1803. if (*myvit.vit_error)
  1804. {
  1805. printf ("ERR:\"%s\"\n",myvit.vit_error);
  1806. }
  1807. printf ("opcode=");
  1808. for (mycount=myvit . vit_opcode_nbytes, p = myvit . vit_opcode;
  1809. mycount;
  1810. mycount--, p++
  1811. )
  1812. {
  1813. printf ("%02x ", *p&0xFF);
  1814. }
  1815. printf (" operand count=%d.\n", mycount = myvit.vit_operands);
  1816. for (myvop=myvit.vit_operand; mycount; mycount--,myvop++)
  1817. {
  1818. printf ("mode=%xx reg=%xx ndx=%xx len='%c'=%c%c%d. expr=\"",
  1819. myvop->vop_mode, myvop->vop_reg, myvop->vop_ndx,
  1820. myvop->vop_short, myvop->vop_access, myvop-> vop_width,
  1821. myvop->vop_nbytes);
  1822. for (p=myvop->vop_expr_begin; p<=myvop->vop_expr_end; p++)
  1823. {
  1824. putchar(*p);
  1825. }
  1826. printf("\"\n");
  1827. if (*myvop->vop_error)
  1828. {
  1829. printf (" err:\"%s\"\n", myvop->vop_error);
  1830. }
  1831. if (*myvop->vop_warn)
  1832. {
  1833. printf (" wrn:\"%s\"\n", myvop->vop_warn);
  1834. }
  1835. }
  1836. }
  1837. vip_end();
  1838. exit();
  1839. }
  1840. #endif /* #ifdef test */
  1841. /* end of vax_ins_parse.c */
  1842. /* JF this used to be a separate file also */
  1843. /* vax_reg_parse.c - convert a VAX register name to a number */
  1844. /* Copyright (C) 1987 Free Software Foundation, Inc. A part of GNU. */
  1845. /*
  1846. * v a x _ r e g _ p a r s e ( )
  1847. *
  1848. * Take 3 char.s, the last of which may be `\0` (non-existent)
  1849. * and return the VAX register number that they represent.
  1850. *
  1851. * Return -1 if they don't form a register name. Good names return
  1852. * a number from 0:15 inclusive.
  1853. *
  1854. * Case is not important in a name.
  1855. *
  1856. * Register names understood are:
  1857. *
  1858. * R0
  1859. * R1
  1860. * R2
  1861. * R3
  1862. * R4
  1863. * R5
  1864. * R6
  1865. * R7
  1866. * R8
  1867. * R9
  1868. * R10
  1869. * R11
  1870. * R12 AP
  1871. * R13 FP
  1872. * R14 SP
  1873. * R15 PC
  1874. *
  1875. */
  1876. #include <ctype.h>
  1877. #define AP (12)
  1878. #define FP (13)
  1879. #define SP (14)
  1880. #define PC (15)
  1881. int /* return -1 or 0:15 */
  1882. vax_reg_parse(c1, c2, c3) /* 3 chars of register name */
  1883. char c1, c2, c3; /* c3 == 0 if 2-character reg name */
  1884. {
  1885. register int retval; /* return -1:15 */
  1886. retval = -1;
  1887. if (isupper(c1)) c1 = tolower(c1);
  1888. if (isupper(c2)) c2 = tolower(c2);
  1889. if (isdigit(c2) && c1=='r')
  1890. {
  1891. retval = c2 - '0';
  1892. if (isdigit(c3))
  1893. {
  1894. retval = retval*10 + c3 - '0';
  1895. retval = (retval>15) ? -1 : retval;
  1896. /* clamp the register value to 1 hex digit */
  1897. }
  1898. else if (c3)
  1899. retval = -1; /* c3 must be '\0' or a digit */
  1900. }
  1901. else if (c3) /* There are no three letter regs */
  1902. retval = -1;
  1903. else if (c2=='p')
  1904. {
  1905. switch (c1)
  1906. {
  1907. case 's':
  1908. retval = SP;
  1909. break;
  1910. case 'f':
  1911. retval = FP;
  1912. break;
  1913. case 'a':
  1914. retval = AP;
  1915. break;
  1916. default:
  1917. retval = -1;
  1918. }
  1919. }
  1920. else if (c1=='p' && c2=='c')
  1921. retval = PC;
  1922. else
  1923. retval = -1;
  1924. return (retval);
  1925. }
  1926. /* end: vax_reg_parse.c */
  1927. /* JF this was another separate prog */
  1928. /* vip_op.c - parse 1 VAX instr's operand.(C)1986 Free Software Foundation. */
  1929. /* JF #include <ctype.h> */
  1930. /* #include "vax_inst.h" */
  1931. /*
  1932. * v i p _ o p ( )
  1933. *
  1934. * Parse a vax operand in DEC assembler notation.
  1935. * For speed, expect a string of whitespace to be reduced to a single ' '.
  1936. * This is the case for GNU AS, and is easy for other DEC-compatible
  1937. * assemblers.
  1938. *
  1939. * Knowledge about DEC VAX assembler operand notation lives here.
  1940. * This doesn't even know what a register name is, except it believes
  1941. * all register names are 2 or 3 characters, and lets vax_reg_parse() say
  1942. * what number each name represents.
  1943. * It does, however, know that PC, SP etc are special registers so it can
  1944. * detect addressing modes that are silly for those registers.
  1945. *
  1946. * Where possible, it delivers 1 fatal or 1 warning message if the operand
  1947. * is suspect. Exactly what we test for is still evolving.
  1948. */
  1949. /*
  1950. * B u g s
  1951. *
  1952. * Arg block.
  1953. *
  1954. * There were a number of 'mismatched argument type' bugs to vip_op.
  1955. * The most general solution is to typedef each (of many) arguments.
  1956. * We used instead a typedef'd argument block. This is less modular
  1957. * than using seperate return pointers for each result, but runs faster
  1958. * on most engines, and seems to keep programmers happy. It will have
  1959. * to be done properly if we ever want to use vip_op as a general-purpose
  1960. * module (it was designed to be).
  1961. *
  1962. * G^
  1963. *
  1964. * Doesn't support DEC "G^" format operands. These always take 5 bytes
  1965. * to express, and code as modes 8F or 9F. Reason: "G^" deprives you of
  1966. * optimising to (say) a "B^" if you are lucky in the way you link.
  1967. * When someone builds a linker smart enough to convert "G^" to "B^", "W^"
  1968. * whenever possible, then we should implement it.
  1969. * If there is some other use for "G^", feel free to code it in!
  1970. *
  1971. *
  1972. * speed
  1973. *
  1974. * If I nested if()s more, I could avoid testing (*err) which would save
  1975. * time, space and page faults. I didn't nest all those if()s for clarity
  1976. * and because I think the mode testing can be re-arranged 1st to test the
  1977. * commoner constructs 1st. Does anybody have statistics on this?
  1978. *
  1979. *
  1980. *
  1981. * error messages
  1982. *
  1983. * In future, we should be able to 'compose' error messages in a scratch area
  1984. * and give the user MUCH more informative error messages. Although this takes
  1985. * a little more code at run-time, it will make this module much more self-
  1986. * documenting. As an example of what sucks now: most error messages have
  1987. * hardwired into them the DEC VAX metacharacters "#^@" which are nothing like
  1988. * the Un*x characters "$`*", that most users will expect from this AS.
  1989. */
  1990. /*
  1991. * The input is a string, ending with '\0'.
  1992. *
  1993. * We also require a 'hint' of what kind of operand is expected: so
  1994. * we can remind caller not to write into literals for instance.
  1995. *
  1996. * The output is a skeletal instruction.
  1997. *
  1998. * The algorithm has two parts.
  1999. * 1. extract the syntactic features (parse off all the @^#-()+[] mode crud);
  2000. * 2. express the @^#-()+[] as some parameters suited to further analysis.
  2001. *
  2002. * 2nd step is where we detect the googles of possible invalid combinations
  2003. * a human (or compiler) might write. Note that if we do a half-way
  2004. * decent assembler, we don't know how long to make (eg) displacement
  2005. * fields when we first meet them (because they may not have defined values).
  2006. * So we must wait until we know how many bits are needed for each address,
  2007. * then we can know both length and opcodes of instructions.
  2008. * For reason(s) above, we will pass to our caller a 'broken' instruction
  2009. * of these major components, from which our caller can generate instructions:
  2010. * - displacement length I^ S^ L^ B^ W^ unspecified
  2011. * - mode (many)
  2012. * - register R0-R15 or absent
  2013. * - index register R0-R15 or absent
  2014. * - expression text what we don't parse
  2015. * - error text(s) why we couldn't understand the operand
  2016. */
  2017. /*
  2018. * To decode output of this, test errtxt. If errtxt[0] == '\0', then
  2019. * we had no errors that prevented parsing. Also, if we ever report
  2020. * an internal bug, errtxt[0] is set non-zero. So one test tells you
  2021. * if the other outputs are to be taken seriously.
  2022. */
  2023. /* vax registers we need to know */
  2024. /* JF #define SP (14)
  2025. /* JF for one big happy file #define PC (15) */
  2026. /* useful ideas */
  2027. /* #define TRUE (1) */
  2028. /* #define FALSE (0) */
  2029. /*
  2030. * Because this module is useful for both VMS and UN*X style assemblers
  2031. * and because of the variety of UN*X assemblers we must recognise
  2032. * the different conventions for assembler operand notation. For example
  2033. * VMS says "#42" for immediate mode, while most UN*X say "$42".
  2034. * We permit arbitrary sets of (single) characters to represent the
  2035. * 3 concepts that DEC writes '#', '@', '^'.
  2036. */
  2037. /* character tests */
  2038. #define IMMEDIATEP(c) (vip_immediate_metacharacter [c])
  2039. #define INDIRECTP(c) (vip_indirect_metacharacter [c])
  2040. #define DISPLENP(c) (vip_displen_metacharacter [c])
  2041. /* We assume 8 bits per byte. Use vip_op_defaults() to set these up BEFORE we
  2042. * are ever called.
  2043. */
  2044. static char
  2045. vip_immediate_metacharacter [256], /* TRUE if character is like DEC # */
  2046. vip_indirect_metacharacter [256], /* TRUE if character is like DEC @ */
  2047. vip_displen_metacharacter [256]; /* TRUE if character is like DEC ^ */
  2048. static vip_op_1();
  2049. vip_op_defaults(immediate, indirect, displen) /* can be called any time */
  2050. char * immediate, /* Strings of characters for each job. */
  2051. * indirect,
  2052. * displen; /* more arguments may appear in future! */
  2053. {
  2054. vip_op_1 (vip_immediate_metacharacter, immediate);
  2055. vip_op_1 (vip_indirect_metacharacter, indirect );
  2056. vip_op_1 (vip_displen_metacharacter, displen );
  2057. }
  2058. static
  2059. vip_op_1 (table, truths)
  2060. char table[256];
  2061. char * truths;
  2062. {
  2063. bzero (table, sizeof(table));
  2064. for (; *truths; truths++)
  2065. {
  2066. table [*truths] = TRUE;
  2067. }
  2068. }
  2069. /*
  2070. * Dec defines the semantics of address modes (and values)
  2071. * by a two-letter code, explained here.
  2072. *
  2073. * letter 1: access type
  2074. *
  2075. * a address calculation - no data access, registers forbidden
  2076. * b branch displacement
  2077. * m read - let go of bus - write back "modify"
  2078. * r read
  2079. * v bit field address: like 'a' but registers are OK
  2080. * w write
  2081. * space no operator (eg ".long foo") [our convention]
  2082. *
  2083. * letter 2: data type (i.e. width, alignment)
  2084. *
  2085. * b byte
  2086. * d double precision floating point (D format)
  2087. * f single precision floating point (F format)
  2088. * g G format floating
  2089. * h H format floating
  2090. * l longword
  2091. * o octaword
  2092. * q quadword
  2093. * w word
  2094. * ? simple synthetic branch operand
  2095. * - unconditional synthetic JSB/JSR operand
  2096. * ! complex synthetic branch operand
  2097. *
  2098. * The '-?!' letter 2's are not for external consumption. They are used
  2099. * for various assemblers. Generally, all unknown widths are assumed 0.
  2100. * We don't limit your choice of width character.
  2101. *
  2102. * DEC operands are hard work to parse. For example, '@' as the first
  2103. * character means indirect (deferred) mode but elswhere it is a shift
  2104. * operator.
  2105. * The long-winded explanation of how this is supposed to work is
  2106. * cancelled. Read a DEC vax manual.
  2107. * We try hard not to parse anything that MIGHT be part of the expression
  2108. * buried in that syntax. For example if we see @...(Rn) we don't check
  2109. * for '-' before the '(' because mode @-(Rn) does not exist.
  2110. *
  2111. * After parsing we have:
  2112. *
  2113. * at TRUE if leading '@' (or Un*x '*')
  2114. * len takes one value from " bilsw". eg B^ -> 'b'.
  2115. * hash TRUE if leading '#' (or Un*x '$')
  2116. * expr_begin, expr_end the expression we did not parse
  2117. * even though we don't interpret it, we make use
  2118. * of its presence or absence.
  2119. * sign -1: -(Rn) 0: absent +1: (Rn)+
  2120. * paren TRUE if () are around register
  2121. * reg major register number 0:15 -1 means absent
  2122. * ndx index register number 0:15 -1 means absent
  2123. *
  2124. * Again, I dare not explain it: just trace ALL the code!
  2125. */
  2126. char * /* (code here) bug message, "" = OK */
  2127. /* our code bug, NOT bad assembly language */
  2128. vip_op (optext, vopP)
  2129. char * optext; /* user's input string e.g.: */
  2130. /* "@B^foo@bar(AP)[FP]:" */
  2131. struct vop * vopP; /* In: vop_access, vop_width. */
  2132. /* Out: _ndx, _reg, _mode, _short, _warn, */
  2133. /* _error _expr_begin, _expr_end, _nbytes. */
  2134. /* vop_nbytes : number of bytes in a datum. */
  2135. {
  2136. char * p; /* track operand text forward */
  2137. char * q; /* track operand text backward */
  2138. int at; /* TRUE if leading '@'('*') seen */
  2139. char len; /* one of " bilsw" */
  2140. int hash; /* TRUE if leading '#'('$') seen */
  2141. int sign; /* -1, 0 or +1 */
  2142. int paren; /* TRUE if () surround register */
  2143. int reg; /* register number, -1:absent */
  2144. int ndx; /* index register number -1:absent */
  2145. char * bug; /* report any logic error in here, ""==OK */
  2146. char * err; /* report illegal operand, ""==OK */
  2147. /* " " is a FAKE error: means we won */
  2148. /* ANY err that begins with ' ' is a fake. */
  2149. /* " " is converted to "" before return */
  2150. char * wrn; /* warn about weird modes pf address */
  2151. char * oldq; /* preserve q in case we backup */
  2152. int mode; /* build up 4-bit operand mode here */
  2153. /* note: index mode is in ndx, this is */
  2154. /* the major mode of operand address */
  2155. /*
  2156. * Notice how we move wrong-arg-type bugs INSIDE this module: if we
  2157. * get the types wrong below, we lose at compile time rather than at
  2158. * lint or run time.
  2159. */
  2160. char access; /* vop_access. */
  2161. char width; /* vop_width. */
  2162. int vax_reg_parse(); /* returns 0:15 or -1 if not a register */
  2163. access = vopP -> vop_access;
  2164. width = vopP -> vop_width;
  2165. bug = /* none of our code bugs (yet) */
  2166. err = /* no user text errors */
  2167. wrn = ""; /* no warnings even */
  2168. p = optext;
  2169. if (*p == ' ') /* Expect all whitespace reduced to ' '. */
  2170. p++; /* skip over whitespace */
  2171. if ( at = INDIRECTP(*p) ) { /* TRUE if *p=='@'(or '*' for Un*x) */
  2172. p++; /* at is determined */
  2173. if (*p == ' ') /* Expect all whitespace reduced to ' '. */
  2174. p++; /* skip over whitespace */
  2175. }
  2176. /*
  2177. * This code is subtle. It tries to detect all legal (letter)'^'
  2178. * but it doesn't waste time explicitly testing for premature '\0' because
  2179. * this case is rejected as a mismatch against either (letter) or '^'.
  2180. */
  2181. {
  2182. register char c;
  2183. c = *p;
  2184. if (isupper(c)) c = tolower(c);
  2185. if ( DISPLENP(p[1]) && index("bilws", len = c) )
  2186. p += 2; /* skip (letter) '^' */
  2187. else /* no (letter) '^' seen */
  2188. len = ' '; /* len is determined */
  2189. }
  2190. if (*p == ' ') /* Expect all whitespace reduced to ' '. */
  2191. p++; /* skip over whitespace */
  2192. if ( hash = IMMEDIATEP(*p) ) /* TRUE if *p=='#' ('$' for Un*x) */
  2193. p++; /* hash is determined */
  2194. /*
  2195. * p points to what may be the beginning of an expression.
  2196. * We have peeled off the front all that is peelable.
  2197. * We know at, len, hash.
  2198. *
  2199. * Lets point q at the end of the text and parse that (backwards).
  2200. */
  2201. for (q=p; *q; q++)
  2202. ;
  2203. q--; /* now q points at last char of text */
  2204. if ( *q == ' ' && q >= p ) /* Expect all whitespace reduced to ' '. */
  2205. q--;
  2206. /* reverse over whitespace, but don't */
  2207. /* run back over *p */
  2208. /*
  2209. * As a matter of policy here, we look for [Rn], although both Rn and S^#
  2210. * forbid [Rn]. This is because it is easy, and because only a sick
  2211. * cyborg would have [...] trailing an expression in a VAX-like assembler.
  2212. * A meticulous parser would first check for Rn followed by '(' or '['
  2213. * and not parse a trailing ']' if it found another. We just ban expressions
  2214. * ending in ']'.
  2215. */
  2216. if (*q==']')
  2217. {
  2218. while (q>=p && *q!='[')
  2219. q--;
  2220. /* either q<p or we got matching '[' */
  2221. if (q<p)
  2222. err = "no '[' to match ']'";
  2223. else
  2224. {
  2225. /*
  2226. * Confusers like "[]" will eventually lose with a bad register
  2227. * name error. So again we don't need to check for early '\0'.
  2228. */
  2229. if (q[3] == ']')
  2230. ndx = vax_reg_parse(q[1],q[2],0);
  2231. else if (q[4] == ']')
  2232. ndx = vax_reg_parse(q[1],q[2],q[3]);
  2233. else
  2234. ndx = -1;
  2235. /*
  2236. * Since we saw a ']' we will demand a register name in the [].
  2237. * If luser hasn't given us one: be rude.
  2238. */
  2239. if (ndx < 0)
  2240. err = "bad register in []";
  2241. else if (ndx == PC)
  2242. err = "[PC] index banned";
  2243. else
  2244. q--; /* point q just before "[...]" */
  2245. }
  2246. }
  2247. else
  2248. ndx = -1; /* no ']', so no iNDeX register */
  2249. /*
  2250. * If err = "..." then we lost: run away.
  2251. * Otherwise ndx == -1 if there was no "[...]".
  2252. * Otherwise, ndx is index register number, and q points before "[...]".
  2253. */
  2254. if ( *q == ' ' && q >= p ) /* Expect all whitespace reduced to ' '. */
  2255. q--;
  2256. /* reverse over whitespace, but don't */
  2257. /* run back over *p */
  2258. if (!*err)
  2259. {
  2260. sign = 0; /* no ()+ or -() seen yet */
  2261. if ( q>p+3 && *q=='+' && q[-1]==')' )
  2262. {
  2263. sign = 1; /* we saw a ")+" */
  2264. q--; /* q points to ')' */
  2265. }
  2266. if ( *q==')' && q>p+2 )
  2267. {
  2268. paren = TRUE; /* assume we have "(...)" */
  2269. while ( q>=p && *q!='(' )
  2270. q--;
  2271. /* either q<p or we got matching '(' */
  2272. if (q<p)
  2273. err = "no '(' to match ')'";
  2274. else
  2275. {
  2276. /*
  2277. * Confusers like "()" will eventually lose with a bad register
  2278. * name error. So again we don't need to check for early '\0'.
  2279. */
  2280. if ( q[3] == ')' )
  2281. reg = vax_reg_parse(q[1],q[2],0);
  2282. else if ( q[4] == ')' )
  2283. reg = vax_reg_parse(q[1],q[2],q[3]);
  2284. else
  2285. reg = -1;
  2286. /*
  2287. * Since we saw a ')' we will demand a register name in the ')'.
  2288. * This is nasty: why can't our hypothetical assembler permit
  2289. * parenthesised expressions? BECAUSE I AM LAZY! That is why.
  2290. * Abuse luser if we didn't spy a register name.
  2291. */
  2292. if ( reg < 0 ) {
  2293. /* JF allow parenthasized expressions. I hope this works */
  2294. paren = FALSE;
  2295. while(*q!=')')
  2296. q++;
  2297. /* err = "unknown register in ()"; */
  2298. }
  2299. else
  2300. q--; /* point just before '(' of "(...)" */
  2301. /*
  2302. * If err == "..." then we lost. Run away.
  2303. * Otherwise if reg >= 0 then we saw (Rn).
  2304. */
  2305. }
  2306. /*
  2307. * If err == "..." then we lost.
  2308. * Otherwise paren==TRUE and reg = register in "()".
  2309. */
  2310. }
  2311. else
  2312. paren = FALSE;
  2313. /*
  2314. * If err == "..." then we lost.
  2315. * Otherwise, q points just before "(Rn)", if any.
  2316. * If there was a "(...)" then paren==TRUE, and reg is the register.
  2317. */
  2318. /*
  2319. * We should only seek '-' of "-(...)" if:
  2320. * we saw "(...)" paren == TRUE
  2321. * we have no errors so far ! *err
  2322. * we did not see '+' of "(...)+" sign < 1
  2323. * We don't check len. We want a specific error message later if
  2324. * user tries "x^...-(Rn)". This is a feature not a bug.
  2325. */
  2326. if ( !*err )
  2327. {
  2328. if ( paren && sign<1 ) /* !sign is adequate test */
  2329. {
  2330. if ( *q == '-' )
  2331. {
  2332. sign = -1;
  2333. q--;
  2334. }
  2335. }
  2336. /*
  2337. * We have back-tracked over most
  2338. * of the crud at the end of an operand.
  2339. * Unless err, we know: sign, paren. If paren, we know reg.
  2340. * The last case is of an expression "Rn".
  2341. * This is worth hunting for if !err, !paren.
  2342. * We wouldn't be here if err.
  2343. * We remember to save q, in case we didn't want "Rn" anyway.
  2344. */
  2345. if ( !paren )
  2346. {
  2347. if (*q == ' ' && q >= p) /* Expect all whitespace reduced to ' '. */
  2348. q--;
  2349. /* reverse over whitespace, but don't */
  2350. /* run back over *p */
  2351. if ( q>p && q<p+3 ) /* room for Rn or Rnn exactly? */
  2352. reg = vax_reg_parse(p[0],p[1],q<p+2?0:p[2]);
  2353. else
  2354. reg = -1; /* always comes here if no register at all */
  2355. /*
  2356. * Here with a definitive reg value.
  2357. */
  2358. if ( reg >= 0 )
  2359. {
  2360. oldq = q;
  2361. q = p-1;
  2362. }
  2363. }
  2364. }
  2365. }
  2366. /*
  2367. * have reg. -1:absent; else 0:15
  2368. */
  2369. /*
  2370. * We have: err, at, len, hash, ndx, sign, paren, reg.
  2371. * Also, any remaining expression is from *p through *q inclusive.
  2372. * Should there be no expression, q==p-1. So expression length = q-p+1.
  2373. * This completes the first part: parsing the operand text.
  2374. */
  2375. /*
  2376. * We now want to boil the data down, checking consistency on the way.
  2377. * We want: len, mode, reg, ndx, err, p, q, wrn, bug.
  2378. * We will deliver a 4-bit reg, and a 4-bit mode.
  2379. */
  2380. /*
  2381. * Case of branch operand. Different. No L^B^W^I^S^ allowed for instance.
  2382. *
  2383. * in: at ?
  2384. * len ?
  2385. * hash ?
  2386. * p:q ?
  2387. * sign ?
  2388. * paren ?
  2389. * reg ?
  2390. * ndx ?
  2391. *
  2392. * out: mode 0
  2393. * reg -1
  2394. * len ' '
  2395. * p:q whatever was input
  2396. * ndx -1
  2397. * err " " or error message, and other outputs trashed
  2398. */
  2399. if ( ! * err )
  2400. {
  2401. if ( access == 'b' )
  2402. { /* branch operands have restricted forms */
  2403. if(at || hash || sign || paren || ndx >= 0 || reg >= 0 || len != ' ')
  2404. err = "invalid branch operand";
  2405. else
  2406. err = " ";
  2407. }
  2408. }
  2409. /* Since nobody seems to use it: comment this 'feature'(?) out for now. */
  2410. #ifdef NEVER
  2411. /*
  2412. * Case of stand-alone operand. e.g. ".long foo"
  2413. *
  2414. * in: at ?
  2415. * len ?
  2416. * hash ?
  2417. * p:q ?
  2418. * sign ?
  2419. * paren ?
  2420. * reg ?
  2421. * ndx ?
  2422. *
  2423. * out: mode 0
  2424. * reg -1
  2425. * len ' '
  2426. * p:q whatever was input
  2427. * ndx -1
  2428. * err " " or error message, and other outputs trashed
  2429. */
  2430. if ( ! * err )
  2431. {
  2432. if ( access == ' ' )
  2433. { /* addresses have restricted forms */
  2434. if ( at )
  2435. err = "address prohibits @";
  2436. else
  2437. {
  2438. if ( hash )
  2439. err = "address prohibits #";
  2440. else
  2441. {
  2442. if ( sign )
  2443. {
  2444. if ( sign < 0 )
  2445. err = "address prohibits -()";
  2446. else
  2447. err = "address prohibits ()+";
  2448. }
  2449. else
  2450. {
  2451. if ( paren )
  2452. err = "address prohibits ()";
  2453. else
  2454. {
  2455. if ( ndx >= 0 )
  2456. err = "address prohibits []";
  2457. else
  2458. {
  2459. if ( reg >= 0 )
  2460. err = "address prohibits register";
  2461. else
  2462. {
  2463. if ( len != ' ' )
  2464. err = "address prohibits displacement length specifier";
  2465. else
  2466. {
  2467. err = " "; /* succeed */
  2468. mode = 0;
  2469. }
  2470. }
  2471. }
  2472. }
  2473. }
  2474. }
  2475. }
  2476. }
  2477. }
  2478. #endif /*#Ifdef NEVER*/
  2479. /*
  2480. * Case of S^#.
  2481. *
  2482. * in: at FALSE
  2483. * len 's' definition
  2484. * hash TRUE demand
  2485. * p:q demand not empty
  2486. * sign 0 by paren==FALSE
  2487. * paren FALSE by "()" scan logic because "S^" seen
  2488. * reg -1 or nn by mistake
  2489. * ndx -1
  2490. *
  2491. * out: mode 0
  2492. * reg -1
  2493. * len 's'
  2494. * exp
  2495. * ndx -1
  2496. */
  2497. if ( ! * err )
  2498. {
  2499. if ( len == 's' )
  2500. {
  2501. if ( ! hash || paren || at || ndx >= 0)
  2502. err = "invalid operand of S^#";
  2503. else {
  2504. if (reg >= 0)
  2505. {
  2506. /*
  2507. * SHIT! we saw S^#Rnn ! put the Rnn back in
  2508. * expression. KLUDGE! Use oldq so we don't
  2509. * need to know exact length of reg name.
  2510. */
  2511. q = oldq;
  2512. reg = 0;
  2513. }
  2514. /*
  2515. * We have all the expression we will ever get.
  2516. */
  2517. if (p>q)
  2518. err = "S^# needs expression";
  2519. else if ( access == 'r' )
  2520. {
  2521. err = " "; /* WIN! */
  2522. mode = 0;
  2523. }
  2524. else
  2525. err = "S^# may only read-access";
  2526. }
  2527. }
  2528. }
  2529. /*
  2530. * Case of -(Rn), which is weird case.
  2531. *
  2532. * in: at FALSE
  2533. * len '
  2534. * hash FALSE
  2535. * p:q q<p
  2536. * sign -1 by definition
  2537. * paren TRUE by definition
  2538. * reg present by definition
  2539. * ndx optional
  2540. *
  2541. * out: mode 7
  2542. * reg present
  2543. * len ' '
  2544. * exp "" enforce empty expression
  2545. * ndx optional warn if same as reg
  2546. */
  2547. if ( ! * err )
  2548. {
  2549. if ( sign<0 )
  2550. {
  2551. if ( len != ' ' || hash || at || p<=q)
  2552. err = "invalid operand of -()";
  2553. else
  2554. {
  2555. err = " "; /* win */
  2556. mode = 7;
  2557. if ( reg == PC )
  2558. wrn = "-(PC) unprdeictable";
  2559. else if ( reg == ndx )
  2560. wrn = "[]index same as -()register: unpredictable";
  2561. }
  2562. }
  2563. }
  2564. /*
  2565. * We convert "(Rn)" to "@Rn" for our convenience.
  2566. * (I hope this is convenient: has someone got a better way to parse this?)
  2567. * A side-effect of this is that "@Rn" is a valid operand.
  2568. */
  2569. if ( paren && !sign && !hash && !at && len==' ' && p>q )
  2570. {
  2571. at = TRUE;
  2572. paren = FALSE;
  2573. }
  2574. /*
  2575. * Case of (Rn)+, which is slightly different.
  2576. *
  2577. * in: at
  2578. * len ' '
  2579. * hash FALSE
  2580. * p:q q<p
  2581. * sign +1 by definition
  2582. * paren TRUE by definition
  2583. * reg present by definition
  2584. * ndx optional
  2585. *
  2586. * out: mode 8+@
  2587. * reg present
  2588. * len ' '
  2589. * exp "" enforce empty expression
  2590. * ndx optional warn if same as reg
  2591. */
  2592. if ( ! * err )
  2593. {
  2594. if ( sign > 0 )
  2595. {
  2596. if ( len != ' ' || hash || p<=q)
  2597. err = "invalid operand of ()+";
  2598. else
  2599. {
  2600. err = " "; /* win */
  2601. mode = 8 + (at ? 1 : 0);
  2602. if (reg == PC )
  2603. wrn = "(PC)+ unpredictable";
  2604. else if (reg == ndx)
  2605. wrn = "[]index same as ()+register: unpredictable";
  2606. }
  2607. }
  2608. }
  2609. /*
  2610. * Case of #, without S^.
  2611. *
  2612. * in: at
  2613. * len ' ' or 'i'
  2614. * hash TRUE by definition
  2615. * p:q
  2616. * sign 0
  2617. * paren FALSE
  2618. * reg absent
  2619. * ndx optional
  2620. *
  2621. * out: mode 8+@
  2622. * reg PC
  2623. * len ' ' or 'i'
  2624. * exp
  2625. * ndx optional
  2626. */
  2627. if (! * err)
  2628. {
  2629. if (hash)
  2630. {
  2631. if (len!='i' && len!=' ')
  2632. err = "# conflicts length";
  2633. else if (paren)
  2634. err = "# bars register";
  2635. else
  2636. {
  2637. if (reg >= 0)
  2638. {
  2639. /*
  2640. * SHIT! we saw #Rnn! Put the Rnn back into the expression.
  2641. * By using oldq, we don't need to know how long Rnn was.
  2642. * KLUDGE!
  2643. */
  2644. q = oldq;
  2645. reg = -1; /* no register any more */
  2646. }
  2647. err = " "; /* win */
  2648. mode = (at ? 9 : 8);
  2649. reg = PC;
  2650. if ( (access=='m' || access=='w') && !at)
  2651. wrn = "writing or modifying # is unpredictable";
  2652. }
  2653. }
  2654. }
  2655. /*
  2656. * If !*err, then sign == 0
  2657. * hash == FALSE
  2658. */
  2659. /*
  2660. * Case of Rn. We seperate this one because it has a few special
  2661. * errors the remaining modes lack.
  2662. *
  2663. * in: at optional
  2664. * len ' '
  2665. * hash FALSE by program logic
  2666. * p:q empty
  2667. * sign 0 by program logic
  2668. * paren FALSE by definition
  2669. * reg present by definition
  2670. * ndx optional
  2671. *
  2672. * out: mode 5+@
  2673. * reg present
  2674. * len ' ' enforce no length
  2675. * exp "" enforce empty expression
  2676. * ndx optional warn if same as reg
  2677. */
  2678. if (! * err && !paren && reg>=0)
  2679. {
  2680. if (len!=' ')
  2681. err = "length not needed";
  2682. else if (at)
  2683. {
  2684. err = " "; /* win */
  2685. mode = 6; /* @Rn */
  2686. }
  2687. else if (ndx>=0)
  2688. err = "can't []index a register, because it has no address";
  2689. else if (access=='a')
  2690. err = "a register has no address";
  2691. else
  2692. {
  2693. /*
  2694. * Idea here is to detect from length of datum
  2695. * and from register number if we will touch PC.
  2696. * Warn if we do.
  2697. * vop_nbytes is number of bytes in operand.
  2698. * Compute highest byte affected, compare to PC0.
  2699. */
  2700. if ( (vopP->vop_nbytes + reg*4) > 60)
  2701. wrn = "PC part of operand unpredictable";
  2702. err = " "; /* win */
  2703. mode = 5; /* Rn */
  2704. }
  2705. }
  2706. /*
  2707. * If !*err, sign == 0
  2708. * hash == FALSE
  2709. * paren == TRUE OR reg==-1
  2710. */
  2711. /*
  2712. * Rest of cases fit into one bunch.
  2713. *
  2714. * in: at optional
  2715. * len ' ' or 'b' or 'w' or 'l'
  2716. * hash FALSE by program logic
  2717. * p:q expected (empty is not an error)
  2718. * sign 0 by program logic
  2719. * paren optional
  2720. * reg optional
  2721. * ndx optional
  2722. *
  2723. * out: mode 10 + @ + len
  2724. * reg optional
  2725. * len ' ' or 'b' or 'w' or 'l'
  2726. * exp maybe empty
  2727. * ndx optional warn if same as reg
  2728. */
  2729. if (!*err)
  2730. {
  2731. err = " "; /* win (always) */
  2732. mode = 10 + (at ? 1 : 0);
  2733. switch (len)
  2734. {
  2735. case 'l':
  2736. mode += 2;
  2737. case 'w':
  2738. mode += 2;
  2739. case ' ': /* assumed B^ until our caller changes it */
  2740. case 'b':
  2741. break;
  2742. }
  2743. }
  2744. /*
  2745. * here with completely specified mode
  2746. * len
  2747. * reg
  2748. * expression p,q
  2749. * ndx
  2750. */
  2751. if (*err==' ')
  2752. err = ""; /* " " is no longer an error */
  2753. vopP -> vop_mode = mode;
  2754. vopP -> vop_reg = reg;
  2755. vopP -> vop_short = len;
  2756. vopP -> vop_expr_begin = p;
  2757. vopP -> vop_expr_end = q;
  2758. vopP -> vop_ndx = ndx;
  2759. vopP -> vop_error = err;
  2760. vopP -> vop_warn = wrn;
  2761. return(bug);
  2762. } /* vip_op() */
  2763. /*
  2764. Summary of vip_op outputs.
  2765. mode reg len ndx
  2766. (Rn) => @Rn
  2767. {@}Rn 5+@ n ' ' optional
  2768. branch operand 0 -1 ' ' -1
  2769. S^#foo 0 -1 's' -1
  2770. -(Rn) 7 n ' ' optional
  2771. {@}(Rn)+ 8+@ n ' ' optional
  2772. {@}#foo, no S^ 8+@ PC " i" optional
  2773. {@}{q^}{(Rn)} 10+@+q option " bwl" optional
  2774. */
  2775. #ifdef TEST /* #Define to use this testbed. */
  2776. /*
  2777. * Follows a test program for this function.
  2778. * We declare arrays non-local in case some of our tiny-minded machines
  2779. * default to small stacks. Also, helps with some debuggers.
  2780. */
  2781. #include <stdio.h>
  2782. char answer[100]; /* human types into here */
  2783. char * p; /* */
  2784. char * myerr;
  2785. char * mywrn;
  2786. char * mybug;
  2787. char myaccess;
  2788. char mywidth;
  2789. char mymode;
  2790. char myreg;
  2791. char mylen;
  2792. char * myleft;
  2793. char * myright;
  2794. char myndx;
  2795. int my_operand_length;
  2796. char my_immediate[200];
  2797. char my_indirect[200];
  2798. char my_displen[200];
  2799. main()
  2800. {
  2801. char * vip_op(); /* make cc happy */
  2802. printf("enter immediate symbols eg enter # ");
  2803. gets(my_immediate);
  2804. printf("enter indirect symbols eg enter @ ");
  2805. gets(my_indirect);
  2806. printf("enter displen symbols eg enter ^ ");
  2807. gets(my_displen);
  2808. vip_op_defaults (my_immediate, my_indirect, my_displen);
  2809. for (;;)
  2810. {
  2811. printf("access,width (eg 'ab' or 'wh') [empty line to quit] : ");
  2812. fflush(stdout);
  2813. gets(answer);
  2814. if (!answer[0])
  2815. exit(0);
  2816. myaccess = answer[0];
  2817. mywidth = answer[1];
  2818. switch ( mywidth )
  2819. {
  2820. case 'b': my_operand_length = 1; break;
  2821. case 'd': my_operand_length = 8; break;
  2822. case 'f': my_operand_length = 4; break;
  2823. case 'g': my_operand_length = 16; break;
  2824. case 'h': my_operand_length = 32; break;
  2825. case 'l': my_operand_length = 4; break;
  2826. case 'o': my_operand_length = 16; break;
  2827. case 'q': my_operand_length = 8; break;
  2828. case 'w': my_operand_length = 2; break;
  2829. case '!':
  2830. case '?':
  2831. case '-': my_operand_length = 0; break;
  2832. default:
  2833. my_operand_length = 2;
  2834. printf("I dn't understand access width %c\n",mywidth);
  2835. break;
  2836. }
  2837. printf("VAX assembler instruction operand: ");
  2838. fflush(stdout);
  2839. gets(answer);
  2840. mybug = vip_op( answer, myaccess, mywidth, my_operand_length,
  2841. &mymode, &myreg, &mylen, &myleft, &myright, &myndx,
  2842. &myerr, &mywrn);
  2843. if (*myerr)
  2844. {
  2845. printf("error: \"%s\"\n",myerr);
  2846. if (*mybug)
  2847. printf(" bug: \"%s\"\n",mybug);
  2848. }
  2849. else
  2850. {
  2851. if (*mywrn)
  2852. printf("warning: \"%s\"\n",mywrn);
  2853. mumble("mode" ,mymode);
  2854. mumble("register",myreg);
  2855. mumble("index" ,myndx);
  2856. printf("width:'%c' ",mylen);
  2857. printf("expression: \"");
  2858. while (myleft<=myright)
  2859. putchar(*myleft++);
  2860. printf("\"\n");
  2861. }
  2862. }
  2863. }
  2864. mumble(text,value)
  2865. char * text;
  2866. int value;
  2867. {
  2868. printf("%s:",text);
  2869. if (value>=0)
  2870. printf("%xx",value);
  2871. else
  2872. printf("ABSENT");
  2873. printf(" ");
  2874. }
  2875. #endif /* ifdef TEST */
  2876. /* end: vip_op.c */
  2877. /* end: vax.c */
  2878. /* JF: new routines */
  2879. int md_short_jump_size=3;
  2880. int md_long_jump_size=6;
  2881. void
  2882. md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)
  2883. char *ptr;
  2884. long from_addr,
  2885. to_addr;
  2886. fragS *frag;
  2887. symbolS *to_symbol;
  2888. {
  2889. long offset;
  2890. offset=to_addr - (from_addr+1);
  2891. *ptr++= 0x31;
  2892. md_number_to_chars(ptr,offset,2);
  2893. }
  2894. void
  2895. md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
  2896. char *ptr;
  2897. long from_addr,
  2898. to_addr;
  2899. fragS *frag;
  2900. symbolS *to_symbol;
  2901. {
  2902. long offset;
  2903. offset=to_addr-to_symbol->sy_value;
  2904. *ptr++=0x17;
  2905. *ptr++=0x9F;
  2906. md_number_to_chars(ptr,offset,4);
  2907. fix_new(frag,ptr-frag->fr_literal,4,to_symbol,(symbolS *)0,(long int)0,0);
  2908. }
  2909. int
  2910. md_parse_option(argP,cntP,vecP)
  2911. char **argP;
  2912. int *cntP;
  2913. char ***vecP;
  2914. {
  2915. char *temp_file_name; /* file name for -t option */
  2916. switch(**argP) {
  2917. case 'd':
  2918. as_warn("Displacement length %s. ignored! GNU is NOT Un*x!",*argP);
  2919. break;
  2920. case 'J':
  2921. as_warn("I can do better than -J!");
  2922. break;
  2923. case 'S':
  2924. as_warn("SYMBOL TABLE not implemented");
  2925. break; /* SYMBOL TABLE not implemented */
  2926. case 'T':
  2927. as_warn("TOKEN TRACE not implemented");
  2928. break; /* TOKEN TRACE not implemented */
  2929. case 't':
  2930. if (**argP) { /* Rest of argument is filename. */
  2931. temp_file_name = *argP;
  2932. while(**argP)
  2933. (*argP)++;
  2934. } else if (*cntP) {
  2935. while(**argP)
  2936. (*argP)++;
  2937. --(*cntP);
  2938. temp_file_name = *++(*vecP);
  2939. **vecP = NULL; /* Remember this is not a file-name. */
  2940. } else {
  2941. as_warn("I expected a filename after -t.");
  2942. temp_file_name = "{absent}";
  2943. }
  2944. as_warn("I don't need or use temp. file \"%s\".",temp_file_name);
  2945. break;
  2946. case 'V':
  2947. as_warn("I don't use an interpass file! -V ignored");
  2948. break;
  2949. default:
  2950. return 0;
  2951. }
  2952. return 1;
  2953. }