ra386att.pas 144 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889
  1. {
  2. $Id$
  3. Copyright (c) 1997-98 by Carl Eric Codere
  4. Does the parsing for the AT&T styled inline assembler.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. Unit Ra386att;
  19. {$ifdef TP}
  20. {$N+,E+}
  21. {$endif TP}
  22. {**********************************************************************}
  23. { WARNING }
  24. {**********************************************************************}
  25. { Any modification in the order or removal of terms in the tables }
  26. { in i386.pas and intasmi3.pas will BREAK the code in this unit, }
  27. { unless the appropriate changes are made to this unit. Addition }
  28. { of terms though, will not change the code herein. }
  29. {**********************************************************************}
  30. {--------------------------------------------------------------------}
  31. { LEFT TO DO: }
  32. {--------------------------------------------------------------------}
  33. { o Handle record offsets }
  34. { o Add support imul,shld and shrd. }
  35. { o Add support for nor operators. }
  36. { o Bugfix of ao_imm8s for IMUL. (Currently the 3 operand imul will }
  37. { be considered as invalid because I use ao_imm8 and the table }
  38. { uses ao_imm8s). }
  39. { o In ConcatOpCode add more checking regarding suffixes and }
  40. { destination registers. (started but unfinished). }
  41. {--------------------------------------------------------------------}
  42. Interface
  43. uses
  44. globtype,i386,tree;
  45. function assemble: ptree;
  46. const
  47. { this variable is TRUE if the lookup tables have already been setup }
  48. { for fast access. On the first call to assemble the tables are setup }
  49. { and stay set up. }
  50. _asmsorted: boolean = FALSE;
  51. firstreg = R_EAX;
  52. lastreg = R_ST7;
  53. type
  54. tiasmops = array[firstop..lastop] of string[7];
  55. piasmops = ^tiasmops;
  56. var
  57. previous_was_id : boolean;
  58. { sorted tables of opcodes }
  59. iasmops: piasmops;
  60. { uppercased tables of registers }
  61. iasmregs: array[firstreg..lastreg] of string[6];
  62. Implementation
  63. Uses
  64. strings,cobjects,systems,verbose,globals,
  65. files,aasm,types,symtable,scanner,hcodegen,
  66. rautils;
  67. type
  68. tinteltoken = (
  69. AS_NONE,AS_LABEL,AS_LLABEL,AS_STRING,AS_HEXNUM,AS_OCTALNUM,
  70. AS_BINNUM,AS_REALNUM,AS_COMMA,AS_LPAREN,
  71. AS_RPAREN,AS_COLON,AS_DOT,AS_PLUS,AS_MINUS,AS_STAR,AS_INTNUM,
  72. AS_SEPARATOR,AS_ID,AS_REGISTER,AS_OPCODE,AS_SLASH,AS_DOLLAR,
  73. {------------------ Assembler directives --------------------}
  74. AS_DB,AS_DW,AS_DD,AS_DQ,AS_GLOBAL,AS_ALIGN,AS_ASCII,
  75. AS_ASCIIZ,AS_LCOMM,AS_COMM,AS_SINGLE,AS_DOUBLE,AS_EXTENDED,
  76. AS_DATA,AS_TEXT,AS_END,
  77. {------------------ Assembler Operators --------------------}
  78. AS_MOD,AS_SHL,AS_SHR,AS_NOT,AS_AND,AS_OR,AS_XOR,AS_NOR);
  79. tasmkeyword = string[8];
  80. const
  81. { These tokens should be modified accordingly to the modifications }
  82. { in the different enumerations. }
  83. firstdirective = AS_DB;
  84. lastdirective = AS_END;
  85. firstsreg = R_CS;
  86. lastsreg = R_SS;
  87. _count_asmdirectives = longint(lastdirective)-longint(firstdirective);
  88. _count_asmprefixes = 5;
  89. _count_asmspecialops = 25;
  90. _count_asmoverrides = 3;
  91. _asmdirectives : array[0.._count_asmdirectives] of tasmkeyword =
  92. ('.byte','.word','.long','.quad','.globl','.align','.ascii',
  93. '.asciz','.lcomm','.comm','.single','.double','.tfloat',
  94. '.data','.text','END');
  95. {------------------ Missing opcodes from std list ----------------}
  96. _asmprefixes: array[0.._count_asmprefixes] of tasmkeyword = (
  97. 'REPNE','REPE','REP','REPZ','REPNZ','LOCK');
  98. _prefixtokens: array[0.._count_asmprefixes] of tasmop = (
  99. A_REPNE,A_REPE,A_REP,A_REPE,A_REPNE,A_LOCK);
  100. _specialops: array[0.._count_asmspecialops] of tasmkeyword = (
  101. 'CMPSB','CMPSW','CMPSL','INSB','INSW','INSL','OUTSB','OUTSW','OUTSL',
  102. 'SCASB','SCASW','SCASL','STOSB','STOSW','STOSL','MOVSB','MOVSW','MOVSL',
  103. 'LODSB','LODSW','LODSL','LOCK','SEGCS','SEGDS','SEGES','SEGSS');
  104. _specialopstokens: array[0.._count_asmspecialops] of tasmop = (
  105. A_CMPS,A_CMPS,A_CMPS,A_INS,A_INS,A_INS,A_OUTS,A_OUTS,A_OUTS,
  106. A_SCAS,A_SCAS,A_SCAS,A_STOS,A_STOS,A_STOS,A_MOVS,A_MOVS,A_MOVS,
  107. A_LODS,A_LODS,A_LODS,A_LOCK,A_NONE,A_NONE,A_NONE,A_NONE);
  108. {------------------------------------------------------------------}
  109. { converts from AT&T style to non-specific style... }
  110. _fpusizes:array[A_FILDQ..A_FIDIVRS] of topsize = (
  111. {'fildq','filds',}
  112. S_IQ,S_IS,
  113. {'fildl','fldl','fldt','fistq','fists','fistl','fstl','fsts',}
  114. S_IL,S_FL,S_FX,S_IQ,S_IS,S_IL,S_FL,S_FS,
  115. {'fstps','fistpl','fstpl','fistps','fistpq','fstpt','fcomps',}
  116. S_FS,S_IL,S_FL,S_IS,S_IQ,S_FX,S_FS,
  117. {'ficompl','fcompl','ficomps','fcoms','ficoml','fcoml','ficoms',}
  118. S_IL,S_FL,S_IS,S_FS,S_IL,S_FL,S_IS,
  119. {'fiaddl','faddl','fiadds','fisubl','fsubl','fisubs','fsubs',}
  120. S_IL,S_FL,S_IS,S_IL,S_FL,S_FS,S_IS,S_FS,
  121. {'fsubr','fsubrs','fisubrl','fsubrl','fisubrs','fmuls','fimull',}
  122. S_NO,S_FS,S_IL,S_FL,S_IS,S_FS,S_IL,
  123. {'fmull','fimuls','fdivs','fidivl','fdivl','fidivs','fdivrs',}
  124. S_FL,S_IL,S_FS,S_IL,S_FL,S_IS,S_FS,
  125. {'fidivrl','fdivrl',}
  126. S_IL,S_FL);
  127. _fpuopcodes:array[A_FILDQ..A_FIDIVRS] of tasmop = (
  128. A_FILD,A_FILD,A_FILD,A_FLD,A_FLD,A_FIST,A_FIST,A_FIST,A_FST,A_FST,
  129. A_FSTP,A_FISTP,A_FSTP,A_FISTP,A_FISTP,A_FSTP,
  130. A_FCOMP,A_FICOMP,A_FCOMP,A_FICOMP,
  131. A_FCOM,A_FICOM,A_FCOM,A_FICOM,A_FIADD,A_FADD,A_FIADD,
  132. A_FISUB,A_FSUB,A_FISUB,A_FSUB,A_FSUB,A_FSUBR,A_FISUBR,
  133. A_FSUBR,A_FISUBR,A_FMUL,A_FIMUL,A_FMUL,A_FIMUL,A_FDIV,A_FIDIV,
  134. A_FDIV,A_FIDIV,A_FDIVR,A_FIDIVR,A_FDIVR,A_FIDIVR);
  135. const
  136. newline = #10;
  137. firsttoken : boolean = TRUE;
  138. operandnum : byte = 0;
  139. charcount: byte = 0;
  140. var
  141. inexpression : boolean;
  142. p : paasmoutput;
  143. actasmtoken : tinteltoken;
  144. actasmpattern : string;
  145. c : char;
  146. Instr : TInstruction;
  147. labellist : TAsmLabelList;
  148. Procedure SetupTables;
  149. { creates uppercased symbol tables. }
  150. var
  151. i: tasmop;
  152. j: tregister;
  153. Begin
  154. Message(assem_d_creating_lookup_tables);
  155. { opcodes }
  156. new(iasmops);
  157. for i:=firstop to lastop do
  158. iasmops^[i] := upper(att_op2str[i]);
  159. { opcodes }
  160. for j:=firstreg to lastreg do
  161. iasmregs[j] := upper(att_reg2str[j]);
  162. end;
  163. {---------------------------------------------------------------------}
  164. { Routines for the tokenizing }
  165. {---------------------------------------------------------------------}
  166. function is_asmopcode(const s: string):Boolean;
  167. {*********************************************************************}
  168. { FUNCTION is_asmopcode(s: string):Boolean }
  169. { Description: Determines if the s string is a valid opcode }
  170. { if so returns TRUE otherwise returns FALSE. }
  171. {*********************************************************************}
  172. var
  173. i: tasmop;
  174. j: byte;
  175. hs: topsize;
  176. hid: string;
  177. Begin
  178. is_asmopcode := FALSE;
  179. { first search for extended opcodes }
  180. for j:=0 to _count_asmspecialops do
  181. Begin
  182. if s = _specialops[j] then
  183. Begin
  184. is_asmopcode:=TRUE;
  185. exit;
  186. end;
  187. end;
  188. for i:=firstop to lastop do
  189. Begin
  190. if s=iasmops^[i] then
  191. begin
  192. is_asmopcode := TRUE;
  193. exit
  194. end;
  195. end;
  196. { not found yet ... }
  197. { search for all possible suffixes }
  198. for hs:=S_WL downto S_B do
  199. if copy(s,length(s)-length(att_opsize2str[hs])+1,
  200. length(att_opsize2str[hs]))=upper(att_opsize2str[hs]) then
  201. begin
  202. { here we search the entire table... }
  203. hid:=copy(s,1,length(s)-length(att_opsize2str[hs]));
  204. for i:=firstop to lastop do
  205. if (length(hid) > 0) and (hid=iasmops^[i]) then
  206. begin
  207. is_asmopcode := TRUE;
  208. exit;
  209. end;
  210. end;
  211. end;
  212. Procedure is_asmdirective(const s: string; var token: tinteltoken);
  213. {*********************************************************************}
  214. { FUNCTION is_asmdirective(s: string; var token: tinteltoken):Boolean }
  215. { Description: Determines if the s string is a valid directive }
  216. { (an operator can occur in operand fields, while a directive cannot) }
  217. { if so returns the directive token, otherwise does not change token.}
  218. {*********************************************************************}
  219. var
  220. i:byte;
  221. Begin
  222. for i:=0 to _count_asmdirectives do
  223. begin
  224. if s=_asmdirectives[i] then
  225. begin
  226. token := tinteltoken(longint(firstdirective)+i);
  227. exit;
  228. end;
  229. end;
  230. end;
  231. Procedure is_register(const s: string; var token: tinteltoken);
  232. {*********************************************************************}
  233. { PROCEDURE is_register(s: string; var token: tinteltoken); }
  234. { Description: Determines if the s string is a valid register, if }
  235. { so return token equal to A_REGISTER, otherwise does not change token}
  236. {*********************************************************************}
  237. Var
  238. i: tregister;
  239. Begin
  240. for i:=firstreg to lastreg do
  241. begin
  242. if s=iasmregs[i] then
  243. begin
  244. token := AS_REGISTER;
  245. exit;
  246. end;
  247. end;
  248. end;
  249. Function GetToken: tinteltoken;
  250. {*********************************************************************}
  251. { FUNCTION GetToken: tinteltoken; }
  252. { Description: This routine returns intel assembler tokens and }
  253. { does some minor syntax error checking. }
  254. {*********************************************************************}
  255. var
  256. token: tinteltoken;
  257. forcelabel: boolean;
  258. errorflag : boolean;
  259. temp: string;
  260. code: integer;
  261. value: byte;
  262. begin
  263. errorflag := FALSE;
  264. forcelabel := FALSE;
  265. actasmpattern :='';
  266. {* INIT TOKEN TO NOTHING *}
  267. token := AS_NONE;
  268. { while space and tab , continue scan... }
  269. while c in [' ',#9] do
  270. c:=current_scanner^.asmgetchar;
  271. { Possiblities for first token in a statement: }
  272. { Local Label, Label, Directive, Prefix or Opcode.... }
  273. if firsttoken and not (c in [newline,#13,'{',';']) then
  274. begin
  275. current_scanner^.gettokenpos;
  276. firsttoken := FALSE;
  277. { directive or local labe }
  278. if c = '.' then
  279. begin
  280. actasmpattern := c;
  281. { Let us point to the next character }
  282. c := current_scanner^.asmgetchar;
  283. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  284. begin
  285. actasmpattern := actasmpattern + c;
  286. c := current_scanner^.asmgetchar;
  287. end;
  288. { this is a local label... }
  289. if (actasmpattern[2] = 'L') and (c = ':') then
  290. Begin
  291. { local variables are case sensitive }
  292. gettoken := AS_LLABEL;
  293. { delete .L }
  294. delete(actasmpattern,1,2);
  295. { point to next character ... }
  296. c := current_scanner^.asmgetchar;
  297. exit;
  298. end
  299. { must be a directive }
  300. else
  301. Begin
  302. { directives are case sensitive!! }
  303. is_asmdirective(actasmpattern, token);
  304. if (token <> AS_NONE) then
  305. Begin
  306. gettoken := token;
  307. exit;
  308. end
  309. else
  310. Message1(assem_e_not_directive_or_local_symbol,actasmpattern);
  311. end;
  312. end; { endif }
  313. { only opcodes and global labels are allowed now. }
  314. while c in ['A'..'Z','a'..'z','0'..'9','_'] do
  315. begin
  316. actasmpattern := actasmpattern + c;
  317. c := current_scanner^.asmgetchar;
  318. end;
  319. if c = ':' then
  320. begin
  321. { uppervar(actasmpattern);
  322. Carl, you cannot change the label to upper
  323. if you want to be able to read in system unit
  324. don't forget that ATT syntax is case sensitive
  325. for labels !! (PM) }
  326. token := AS_LABEL;
  327. { let us point to the next character }
  328. c := current_scanner^.asmgetchar;
  329. gettoken := token;
  330. exit;
  331. end;
  332. If is_asmopcode(upper(actasmpattern)) then
  333. Begin
  334. uppervar(actasmpattern);
  335. gettoken := AS_OPCODE;
  336. exit;
  337. end
  338. else
  339. if upper(actasmpattern) = 'END' then
  340. begin
  341. gettoken := AS_END;
  342. exit;
  343. end
  344. else
  345. begin
  346. gettoken := AS_NONE;
  347. Message(assem_e_invalid_operand);
  348. end;
  349. end
  350. else { else firsttoken }
  351. { Here we must handle all possible cases }
  352. begin
  353. case c of
  354. '.': { possiblities : - local label reference , such as in jmp @local1 }
  355. { - field of object/record }
  356. { - directive. }
  357. begin
  358. if previous_was_id then
  359. begin
  360. c:=current_scanner^.asmgetchar;
  361. gettoken:=AS_DOT;
  362. exit;
  363. end;
  364. actasmpattern := c;
  365. c:= current_scanner^.asmgetchar;
  366. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  367. begin
  368. actasmpattern := actasmpattern + c;
  369. c := current_scanner^.asmgetchar;
  370. end;
  371. is_asmdirective(actasmpattern,token);
  372. { if directive }
  373. if (token <> AS_NONE) then
  374. begin
  375. gettoken := token;
  376. exit;
  377. end;
  378. { local label references and directives }
  379. { are case sensitive }
  380. gettoken := AS_ID;
  381. exit;
  382. end;
  383. { identifier, register, opcode, prefix or directive }
  384. '_','A'..'Z','a'..'z': begin
  385. actasmpattern := c;
  386. c:= current_scanner^.asmgetchar;
  387. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  388. begin
  389. actasmpattern := actasmpattern + c;
  390. c := current_scanner^.asmgetchar;
  391. end;
  392. { pascal is not case sensitive! }
  393. { therefore variables which are }
  394. { outside the scope of the asm }
  395. { block, should not be made case }
  396. { sensitive... !!!!! }
  397. uppervar(actasmpattern);
  398. If is_asmopcode(actasmpattern) then
  399. Begin
  400. gettoken := AS_OPCODE;
  401. exit;
  402. end;
  403. { we handle this directive separately from }
  404. { others. }
  405. if actasmpattern = 'END' then
  406. Begin
  407. gettoken := AS_END;
  408. exit;
  409. end;
  410. { if found }
  411. if (token <> AS_NONE) then
  412. begin
  413. gettoken := token;
  414. exit;
  415. end
  416. { this is surely an identifier }
  417. else
  418. token := AS_ID;
  419. gettoken := token;
  420. exit;
  421. end;
  422. '&': begin
  423. c:=current_scanner^.asmgetchar;
  424. gettoken := AS_AND;
  425. end;
  426. { character }
  427. '''' : begin
  428. c:=current_scanner^.asmgetchar;
  429. if c = '\' then
  430. Begin
  431. { escape sequence }
  432. c:=current_scanner^.asmgetchar;
  433. case c of
  434. newline: Message(scan_f_string_exceeds_line);
  435. 't': actasmpattern:=#09;
  436. 'b': actasmpattern:=#08;
  437. '\': actasmpattern:='\';
  438. 'f': actasmpattern:=#12;
  439. 'n': actasmpattern:=#10;
  440. 'r': actasmpattern:=#13;
  441. '"': actasmpattern:='"';
  442. { octal number }
  443. '0'..'7':
  444. begin
  445. temp:=c;
  446. temp:=temp+current_scanner^.asmgetchar;
  447. temp:=temp+current_scanner^.asmgetchar;
  448. val(octaltodec(temp),value,code);
  449. if (code <> 0) then
  450. Message1(assem_e_error_in_octal_const,temp);
  451. actasmpattern:=chr(value);
  452. end;
  453. { hexadecimal number }
  454. 'x':
  455. begin
  456. temp:=current_scanner^.asmgetchar;
  457. temp:=temp+current_scanner^.asmgetchar;
  458. val(hextodec(temp),value,code);
  459. if (code <> 0) then
  460. Message1(assem_e_error_in_hex_const,temp);
  461. actasmpattern:=chr(value);
  462. end;
  463. else
  464. Begin
  465. Message(assem_e_escape_seq_ignored);
  466. actasmpattern:=c;
  467. end
  468. end; { end case }
  469. end
  470. else
  471. actasmpattern:=c;
  472. gettoken := AS_STRING;
  473. c:=current_scanner^.asmgetchar;
  474. exit;
  475. end;
  476. { string }
  477. '"' :
  478. begin
  479. actasmpattern:='';
  480. while true do
  481. Begin
  482. c:=current_scanner^.asmgetchar;
  483. case c of
  484. '\': Begin
  485. { escape sequences }
  486. c:=current_scanner^.asmgetchar;
  487. case c of
  488. newline: Message(scan_f_string_exceeds_line);
  489. 't': actasmpattern:=actasmpattern+#09;
  490. 'b': actasmpattern:=actasmpattern+#08;
  491. '\': actasmpattern:=actasmpattern+'\';
  492. 'f': actasmpattern:=actasmpattern+#12;
  493. 'n': actasmpattern:=actasmpattern+#10;
  494. 'r': actasmpattern:=actasmpattern+#13;
  495. '"': actasmpattern:=actasmpattern+'"';
  496. { octal number }
  497. '0'..'7':
  498. begin
  499. temp:=c;
  500. temp:=temp+current_scanner^.asmgetchar;
  501. temp:=temp+current_scanner^.asmgetchar;
  502. val(octaltodec(temp),value,code);
  503. if (code <> 0) then
  504. Message1(assem_e_error_in_octal_const,temp);
  505. actasmpattern:=actasmpattern+chr(value);
  506. end;
  507. { hexadecimal number }
  508. 'x':
  509. begin
  510. temp:=current_scanner^.asmgetchar;
  511. temp:=temp+current_scanner^.asmgetchar;
  512. val(hextodec(temp),value,code);
  513. if (code <> 0) then
  514. Message1(assem_e_error_in_hex_const,temp);
  515. actasmpattern:=actasmpattern+chr(value);
  516. end;
  517. else
  518. Begin
  519. Message(assem_e_escape_seq_ignored);
  520. actasmpattern:=actasmpattern+c;
  521. end
  522. end; { end case }
  523. end;
  524. '"': begin
  525. c:=current_scanner^.asmgetchar;
  526. break;
  527. end;
  528. newline: Message(scan_f_string_exceeds_line);
  529. else
  530. actasmpattern:=actasmpattern+c;
  531. end;
  532. end; { end case }
  533. token := AS_STRING;
  534. gettoken := token;
  535. exit;
  536. end;
  537. '$' : begin
  538. gettoken := AS_DOLLAR;
  539. c:=current_scanner^.asmgetchar;
  540. exit;
  541. end;
  542. ',' : begin
  543. gettoken := AS_COMMA;
  544. c:=current_scanner^.asmgetchar;
  545. exit;
  546. end;
  547. '<' : begin
  548. gettoken := AS_SHL;
  549. c := current_scanner^.asmgetchar;
  550. if c = '<' then
  551. c := current_scanner^.asmgetchar;
  552. exit;
  553. end;
  554. '>' : begin
  555. gettoken := AS_SHL;
  556. c := current_scanner^.asmgetchar;
  557. if c = '>' then
  558. c := current_scanner^.asmgetchar;
  559. exit;
  560. end;
  561. '|' : begin
  562. gettoken := AS_OR;
  563. c := current_scanner^.asmgetchar;
  564. exit;
  565. end;
  566. '^' : begin
  567. gettoken := AS_XOR;
  568. c := current_scanner^.asmgetchar;
  569. exit;
  570. end;
  571. '!' : begin
  572. Message(assem_e_nor_not_supported);
  573. c := current_scanner^.asmgetchar;
  574. gettoken := AS_NONE;
  575. exit;
  576. end;
  577. '(' : begin
  578. gettoken := AS_LPAREN;
  579. c:=current_scanner^.asmgetchar;
  580. exit;
  581. end;
  582. ')' : begin
  583. gettoken := AS_RPAREN;
  584. c:=current_scanner^.asmgetchar;
  585. exit;
  586. end;
  587. ':' : begin
  588. gettoken := AS_COLON;
  589. c:=current_scanner^.asmgetchar;
  590. exit;
  591. end;
  592. '+' : begin
  593. gettoken := AS_PLUS;
  594. c:=current_scanner^.asmgetchar;
  595. exit;
  596. end;
  597. '-' : begin
  598. gettoken := AS_MINUS;
  599. c:=current_scanner^.asmgetchar;
  600. exit;
  601. end;
  602. '*' : begin
  603. gettoken := AS_STAR;
  604. c:=current_scanner^.asmgetchar;
  605. exit;
  606. end;
  607. '/' : begin
  608. c:=current_scanner^.asmgetchar;
  609. { att styled comment }
  610. if c='/' then
  611. begin
  612. repeat
  613. c:=current_scanner^.asmgetchar;
  614. until c=newline;
  615. firsttoken := TRUE;
  616. gettoken:=AS_SEPARATOR;
  617. c:=current_scanner^.asmgetchar;
  618. exit;
  619. end
  620. else
  621. begin
  622. gettoken := AS_SLASH;
  623. c:=current_scanner^.asmgetchar;
  624. exit;
  625. end;
  626. end;
  627. { register or modulo }
  628. { only register supported }
  629. { for the moment. }
  630. '%' : begin
  631. actasmpattern := c;
  632. c:=current_scanner^.asmgetchar;
  633. while c in ['a'..'z','A'..'Z','0'..'9'] do
  634. Begin
  635. actasmpattern := actasmpattern + c;
  636. c:=current_scanner^.asmgetchar;
  637. end;
  638. token := AS_NONE;
  639. uppervar(actasmpattern);
  640. if (actasmpattern = '%ST') and (c='(') then
  641. Begin
  642. actasmpattern:=actasmpattern+c;
  643. c:=current_scanner^.asmgetchar;
  644. if c in ['0'..'9'] then
  645. actasmpattern := actasmpattern + c
  646. else
  647. Message(assem_e_invalid_fpu_register);
  648. c:=current_scanner^.asmgetchar;
  649. if c <> ')' then
  650. Message(assem_e_invalid_fpu_register)
  651. else
  652. Begin
  653. actasmpattern := actasmpattern + c;
  654. c:=current_scanner^.asmgetchar; { let us point to next character. }
  655. end;
  656. end;
  657. is_register(actasmpattern, token);
  658. { if found }
  659. if (token <> AS_NONE) then
  660. begin
  661. gettoken := token;
  662. exit;
  663. end
  664. else
  665. begin
  666. Message(assem_w_modulo_not_supported);
  667. gettoken := AS_NONE;
  668. end;
  669. end;
  670. { integer number }
  671. '1'..'9': begin
  672. actasmpattern := c;
  673. c := current_scanner^.asmgetchar;
  674. while c in ['0'..'9'] do
  675. Begin
  676. actasmpattern := actasmpattern + c;
  677. c:= current_scanner^.asmgetchar;
  678. end;
  679. gettoken := AS_INTNUM;
  680. exit;
  681. end;
  682. '0': begin
  683. { octal,hexa,real or binary number. }
  684. actasmpattern := c;
  685. c:=current_scanner^.asmgetchar;
  686. case upcase(c) of
  687. { binary }
  688. 'B': Begin
  689. c:=current_scanner^.asmgetchar;
  690. while c in ['0','1'] do
  691. Begin
  692. actasmpattern := actasmpattern + c;
  693. c := current_scanner^.asmgetchar;
  694. end;
  695. gettoken := AS_BINNUM;
  696. exit;
  697. end;
  698. { real }
  699. 'D': Begin
  700. c:=current_scanner^.asmgetchar;
  701. { get ridd of the 0d }
  702. if (c='+') or (c='-') then
  703. begin
  704. actasmpattern:=c;
  705. c:=current_scanner^.asmgetchar;
  706. end
  707. else
  708. actasmpattern:='';
  709. while c in ['0'..'9'] do
  710. Begin
  711. actasmpattern := actasmpattern + c;
  712. c:= current_scanner^.asmgetchar;
  713. end;
  714. if c='.' then
  715. begin
  716. actasmpattern := actasmpattern + c;
  717. c:=current_scanner^.asmgetchar;
  718. while c in ['0'..'9'] do
  719. Begin
  720. actasmpattern := actasmpattern + c;
  721. c:= current_scanner^.asmgetchar;
  722. end;
  723. if upcase(c) = 'E' then
  724. begin
  725. actasmpattern := actasmpattern + c;
  726. c:=current_scanner^.asmgetchar;
  727. if (c = '+') or (c = '-') then
  728. begin
  729. actasmpattern := actasmpattern + c;
  730. c:=current_scanner^.asmgetchar;
  731. end;
  732. while c in ['0'..'9'] do
  733. Begin
  734. actasmpattern := actasmpattern + c;
  735. c:= current_scanner^.asmgetchar;
  736. end;
  737. end;
  738. gettoken := AS_REALNUM;
  739. exit;
  740. end
  741. else
  742. begin
  743. Message1(assem_e_invalid_float_const,actasmpattern+c);
  744. gettoken:=AS_NONE;
  745. end;
  746. end;
  747. { hexadecimal }
  748. 'X': Begin
  749. c:=current_scanner^.asmgetchar;
  750. while c in ['0'..'9','a'..'f','A'..'F'] do
  751. Begin
  752. actasmpattern := actasmpattern + c;
  753. c := current_scanner^.asmgetchar;
  754. end;
  755. gettoken := AS_HEXNUM;
  756. exit;
  757. end;
  758. { octal }
  759. '1'..'7': begin
  760. actasmpattern := actasmpattern + c;
  761. while c in ['0'..'7'] do
  762. Begin
  763. actasmpattern := actasmpattern + c;
  764. c := current_scanner^.asmgetchar;
  765. end;
  766. gettoken := AS_OCTALNUM;
  767. exit;
  768. end;
  769. else { octal number zero value...}
  770. Begin
  771. gettoken := AS_OCTALNUM;
  772. exit;
  773. end;
  774. end; { end case }
  775. end;
  776. '{',#13,newline,';' : begin
  777. { the comment is read by asmgetchar }
  778. c:=current_scanner^.asmgetchar;
  779. firsttoken := TRUE;
  780. gettoken:=AS_SEPARATOR;
  781. end;
  782. else
  783. Begin
  784. Message(scan_f_illegal_char);
  785. end;
  786. end; { end case }
  787. end; { end else if }
  788. end;
  789. {---------------------------------------------------------------------}
  790. { Routines for the output }
  791. {---------------------------------------------------------------------}
  792. { looks for internal names of variables and routines }
  793. Function SearchDirectVar(var Instr: TInstruction; const hs:string;operandnum:byte): Boolean;
  794. var
  795. p : pai_external;
  796. Begin
  797. SearchDirectVar:=false;
  798. { search in the list of internals }
  799. p:=search_assembler_symbol(internals,hs,EXT_ANY);
  800. if p=nil then
  801. p:=search_assembler_symbol(externals,hs,EXT_ANY);
  802. if p<>nil then
  803. begin
  804. { get symbol name }
  805. { free the memory before changing the symbol name. }
  806. instr.operands[operandnum].ref.symbol:=newasmsymbol(p^.sym^.name);
  807. case p^.exttyp of
  808. EXT_BYTE : instr.operands[operandnum].size := S_B;
  809. EXT_WORD : instr.operands[operandnum].size := S_W;
  810. EXT_NEAR,EXT_FAR,EXT_PROC,EXT_DWORD,EXT_CODEPTR,EXT_DATAPTR:
  811. instr.operands[operandnum].size := S_L;
  812. EXT_QWORD : instr.operands[operandnum].size := S_FL;
  813. EXT_TBYTE : instr.operands[operandnum].size := S_FX;
  814. else
  815. { this is in the case where the instruction is LEA }
  816. { or something like that, in that case size is not }
  817. { important. }
  818. instr.operands[operandnum].size := S_NO;
  819. end;
  820. SearchDirectVar := TRUE;
  821. Exit;
  822. end;
  823. end;
  824. { returns an appropriate ao_xxxx flag indicating the type }
  825. { of operand. }
  826. function findtype(Var Opr: TOperand): longint;
  827. Begin
  828. With Opr do
  829. Begin
  830. case operandtype of
  831. OPR_REFERENCE: Begin
  832. if assigned(ref.symbol) then
  833. { check if in local label list }
  834. { if so then it is considered }
  835. { as a displacement. }
  836. Begin
  837. if labellist.search(ref.symbol^.name) <> nil then
  838. findtype := ao_disp
  839. else
  840. findtype := ao_mem; { probably a mem ref. }
  841. end
  842. else
  843. findtype := ao_mem;
  844. end;
  845. OPR_CONSTANT: Begin
  846. { check if there is not already a default size }
  847. if opr.size <> S_NO then
  848. Begin
  849. findtype := const_2_type[opr.size];
  850. exit;
  851. end;
  852. if val < $ff then
  853. Begin
  854. findtype := ao_imm8;
  855. opr.size := S_B;
  856. end
  857. else if val < $ffff then
  858. Begin
  859. findtype := ao_imm16;
  860. opr.size := S_W;
  861. end
  862. else
  863. Begin
  864. findtype := ao_imm32;
  865. opr.size := S_L;
  866. end
  867. end;
  868. OPR_REGISTER: Begin
  869. findtype := reg_2_type[reg];
  870. exit;
  871. end;
  872. OPR_SYMBOL: Begin
  873. findtype := ao_jumpabsolute;
  874. end;
  875. OPR_NONE: Begin
  876. findtype := 0;
  877. end;
  878. else
  879. Begin
  880. Message(assem_f_internal_error_in_findtype);
  881. end;
  882. end;
  883. end;
  884. end;
  885. Procedure HandleExtend(var instr: TInstruction);
  886. { Handles MOVZX, MOVSX ... }
  887. var
  888. instruc: tasmop;
  889. opsize : topsize;
  890. Begin
  891. instruc:=instr.getinstruction;
  892. { if we have A_MOVZX/A_MOVSX here, there is a big problem }
  893. { it should never happen, because it is already replaced }
  894. { by ConcatOpcode! }
  895. Case instruc of
  896. A_MOVZX,A_MOVSX: Message(assem_f_internal_error_in_handleextend);
  897. A_MOVSB, A_MOVSBL:
  898. Begin
  899. instruc := A_MOVSX;
  900. { Indirect memory reference with register }
  901. { no size determined, therefore we determine it }
  902. { with the suffix. }
  903. if instr.operands[1].size = S_NO then
  904. instr.operands[1].size := S_B;
  905. end;
  906. A_MOVSBW:
  907. Begin
  908. instruc := A_MOVSX;
  909. { Indirect memory reference with register }
  910. { no size determined, therefore we determine it }
  911. { with the suffix. }
  912. if instr.operands[1].size = S_NO then
  913. instr.operands[1].size := S_B;
  914. end;
  915. A_MOVSWL:
  916. Begin
  917. instruc := A_MOVSX;
  918. { Indirect memory reference with register }
  919. { no size determined, therefore we determine it }
  920. { with the suffix. }
  921. if instr.operands[1].size = S_NO then
  922. instr.operands[1].size := S_W;
  923. end;
  924. A_MOVZB:
  925. Begin
  926. instruc := A_MOVZX;
  927. { Indirect memory reference with register }
  928. { no size determined, therefore we determine it }
  929. { with the suffix. }
  930. if instr.operands[1].size = S_NO then
  931. instr.operands[1].size := S_B;
  932. end;
  933. A_MOVZWL:
  934. Begin
  935. instruc := A_MOVZX;
  936. { Indirect memory reference with register }
  937. { no size determined, therefore we determine it }
  938. { with the suffix. }
  939. if instr.operands[1].size = S_NO then
  940. instr.operands[1].size := S_W;
  941. end;
  942. End;
  943. With instr do
  944. Begin
  945. if operands[1].size = S_B then
  946. Begin
  947. if operands[2].size = S_L then
  948. opsize := S_BL
  949. else
  950. if operands[2].size = S_W then
  951. opsize := S_BW
  952. else
  953. begin
  954. Message(assem_e_invalid_size_movzx);
  955. exit;
  956. end;
  957. end
  958. else
  959. if operands[1].size = S_W then
  960. Begin
  961. if operands[2].size = S_L then
  962. opsize := S_WL
  963. else
  964. begin
  965. Message(assem_e_invalid_size_movzx);
  966. exit;
  967. end;
  968. end
  969. else
  970. begin
  971. Message(assem_e_invalid_size_movzx);
  972. exit;
  973. end;
  974. if operands[1].operandtype = OPR_REGISTER then
  975. Begin
  976. if operands[2].operandtype <> OPR_REGISTER then
  977. Message(assem_e_invalid_opcode) { exit...}
  978. else
  979. p^.concat(new(pai386,op_reg_reg(instruc,opsize,
  980. operands[1].reg,operands[2].reg)));
  981. end
  982. else
  983. if operands[1].operandtype = OPR_REFERENCE then
  984. Begin
  985. if operands[2].operandtype <> OPR_REGISTER then
  986. Message(assem_e_invalid_opcode) {exit...}
  987. else
  988. p^.concat(new(pai386,op_ref_reg(instruc,opsize,
  989. newreference(operands[1].ref),operands[2].reg)));
  990. end
  991. end; { end with }
  992. end;
  993. Function CheckAndSetOpsize(var op : toperand;size : topsize) : boolean;
  994. Begin
  995. CheckAndSetOpsize:=true;
  996. { operandtype for constant get a default value for size }
  997. { only claim for op.size in S_B, S_W or S_L :
  998. if the var is a float it will be accessed as 2 longs !! }
  999. if (op.operandtype<>OPR_CONSTANT) and (op.size in [S_B,S_W,S_L]) and
  1000. (op.size<>size) then
  1001. begin
  1002. if (cs_compilesystem in aktmoduleswitches) or
  1003. not (cs_check_range in aktlocalswitches) then
  1004. Message(assem_w_size_suffix_and_dest_dont_match)
  1005. else
  1006. Begin
  1007. Message(assem_e_size_suffix_and_dest_dont_match);
  1008. CheckAndSetOpsize:=false;
  1009. End;
  1010. end;
  1011. op.size:=size;
  1012. End;
  1013. Procedure ConcatOpCode(var instr: TInstruction);
  1014. {*********************************************************************}
  1015. { First Pass: }
  1016. { - If this is a three operand opcode: }
  1017. { imul,shld,and shrd -> check them manually. }
  1018. {*********************************************************************}
  1019. var
  1020. fits : boolean;
  1021. i: longint;
  1022. opsize: topsize;
  1023. optyp1, optyp2, optyp3: longint;
  1024. instruc: tasmop;
  1025. href : treference;
  1026. Begin
  1027. fits := FALSE;
  1028. for i:=1 to instr.numops do
  1029. Begin
  1030. case instr.operands[i].operandtype of
  1031. OPR_REGISTER: instr.operands[i].size :=
  1032. reg_2_size[instr.operands[i].reg];
  1033. end; { end case }
  1034. end; { endif }
  1035. { setup specific instructions for first pass }
  1036. instruc := instr.getinstruction;
  1037. Case instruc Of
  1038. A_LEA,A_LDS,A_LSS,A_LES,A_LFS,A_LGS:
  1039. Begin
  1040. if instr.operands[2].size <> S_L then
  1041. Begin
  1042. Message(assem_e_16bit_base_in_32bit_segment);
  1043. exit;
  1044. end; { endif }
  1045. end;
  1046. End;
  1047. With instr do
  1048. Begin
  1049. for i:=1 to numops do
  1050. Begin
  1051. With operands[i] do
  1052. Begin
  1053. { check for 16-bit bases/indexes and emit an error. }
  1054. { we cannot only emit a warning since gas does not }
  1055. { accept 16-bit indexes and bases. }
  1056. if (operandtype = OPR_REFERENCE) and
  1057. ((ref.base <> R_NO) or
  1058. (ref.index <> R_NO)) then
  1059. Begin
  1060. { index or base defined. }
  1061. if (ref.base <> R_NO) then
  1062. Begin
  1063. if not (ref.base in
  1064. [R_EAX,R_EBX,R_ECX,R_EDX,R_EBP,R_ESI,R_EDI,R_ESP]) then
  1065. Message(assem_e_16bit_base_in_32bit_segment);
  1066. end;
  1067. { index or base defined. }
  1068. if (ref.index <> R_NO) then
  1069. Begin
  1070. if not (ref.index in
  1071. [R_EAX,R_EBX,R_ECX,R_EDX,R_EBP,R_ESI,R_EDI,R_ESP]) then
  1072. Message(assem_e_16bit_index_in_32bit_segment);
  1073. end;
  1074. end;
  1075. { Check for constants without bases/indexes in memory }
  1076. { references. }
  1077. { Update: allow constant references under Go32v2, to }
  1078. { access data in the bios data segmement (JM) }
  1079. if (target_info.target<>target_i386_Go32v2) and
  1080. ((operandtype = OPR_REFERENCE) and
  1081. (ref.base = R_NO) and
  1082. (ref.index = R_NO) and
  1083. (ref.symbol = nil) and
  1084. (ref.offset <> 0)) then
  1085. Begin
  1086. ref.is_immediate := TRUE;
  1087. Message(assem_e_const_ref_not_allowed);
  1088. end;
  1089. opinfo := findtype(operands[i]);
  1090. end; { end with }
  1091. end; {endfor}
  1092. { TAKE CARE OF SPECIAL OPCODES, TAKE CARE OF THEM INDIVUALLY. }
  1093. { ALL THE REST ARE TAKEN CARE BY OPCODE TABLE AND THIRD PASS. }
  1094. { is this right for ratti386 ? (PM) }
  1095. { almost... here we check for the size of registers and references }
  1096. { to determine the correct gas opcode to use, because if the token }
  1097. { is A_MOVSX or A_MOVZX then that means that the person forgot to }
  1098. { specify the size.. }
  1099. { if memory size is not specified, will of course give out an error}
  1100. Case instruc Of
  1101. A_MOVSX:
  1102. Begin
  1103. if numops = 2 then
  1104. begin
  1105. if stropsize = S_BL then
  1106. begin
  1107. CheckAndSetOpsize(operands[1],S_B);
  1108. stropsize := S_NO;
  1109. CheckAndSetOpsize(operands[2],S_L);
  1110. addinstr(A_MOVSBL)
  1111. end
  1112. else
  1113. if stropsize = S_WL then
  1114. begin
  1115. CheckAndSetOpsize(operands[1],S_W);
  1116. stropsize := S_NO;
  1117. CheckAndSetOpsize(operands[2],S_L);
  1118. addinstr(A_MOVSWL)
  1119. end
  1120. else
  1121. if stropsize = S_BW then
  1122. begin
  1123. CheckAndSetOpsize(operands[1],S_B);
  1124. stropsize := S_NO;
  1125. CheckAndSetOpsize(operands[2],S_W);
  1126. addinstr(A_MOVSBW)
  1127. end
  1128. else
  1129. if (operands[1].size = S_B) and
  1130. (operands[2].size = S_W) then
  1131. addinstr(A_MOVSBW)
  1132. else
  1133. if (operands[1].size = S_B) and
  1134. (operands[2].size = S_L) then
  1135. addinstr(A_MOVSBL)
  1136. else
  1137. if (operands[1].size = S_W) and
  1138. (operands[2].size = S_L) then
  1139. addinstr(A_MOVSWL)
  1140. else
  1141. begin
  1142. Message(assem_e_invalid_size_movzx);
  1143. exit;
  1144. end;
  1145. instruc := getinstruction; { reload instruction }
  1146. end
  1147. else
  1148. begin
  1149. Message(assem_e_too_many_operands);
  1150. exit;
  1151. end;
  1152. end;
  1153. A_MOVZX:
  1154. Begin
  1155. if numops = 2 then
  1156. Begin
  1157. if stropsize = S_BW then
  1158. begin
  1159. CheckAndSetOpsize(operands[1],S_B);
  1160. stropsize := S_NO;
  1161. CheckAndSetOpsize(operands[2],S_W);
  1162. addinstr(A_MOVZB)
  1163. end
  1164. else
  1165. if stropsize = S_BL then
  1166. begin
  1167. CheckAndSetOpsize(operands[1],S_B);
  1168. stropsize := S_NO;
  1169. CheckAndSetOpsize(operands[2],S_L);
  1170. addinstr(A_MOVZB)
  1171. end
  1172. else
  1173. if stropsize = S_WL then
  1174. begin
  1175. CheckAndSetOpsize(operands[1],S_W);
  1176. stropsize := S_NO;
  1177. CheckAndSetOpsize(operands[2],S_L);
  1178. addinstr(A_MOVZWL)
  1179. end
  1180. else
  1181. { change the instruction to conform to GAS }
  1182. if (operands[1].size = S_B) and
  1183. (operands[2].size in [S_W,S_L]) then
  1184. addinstr(A_MOVZB)
  1185. else
  1186. if (operands[1].size = S_W) and
  1187. (operands[2].size = S_L) then
  1188. addinstr(A_MOVZWL)
  1189. else
  1190. begin
  1191. Message(assem_e_invalid_size_movzx);
  1192. exit;
  1193. end;
  1194. instruc := getinstruction; { reload instruction }
  1195. end
  1196. else
  1197. Begin
  1198. Message(assem_e_too_many_operands);
  1199. exit;
  1200. end;
  1201. end;
  1202. A_FWAIT: FWaitWarning;
  1203. A_BT,A_BTC,A_BTR,A_BTS:
  1204. Begin
  1205. if numops = 2 then
  1206. Begin
  1207. if (operands[1].operandtype = OPR_CONSTANT)
  1208. and (operands[1].val <= $ff) then
  1209. Begin
  1210. operands[1].opinfo := ao_imm8;
  1211. { no operand size if using constant. }
  1212. operands[1].size := S_NO;
  1213. fits := TRUE;
  1214. end
  1215. end
  1216. else
  1217. Begin
  1218. Message(assem_e_invalid_opcode_and_operand);
  1219. exit;
  1220. end;
  1221. end;
  1222. A_ENTER:
  1223. Begin
  1224. if numops =2 then
  1225. Begin
  1226. if (operands[1].operandtype = OPR_CONSTANT) and
  1227. (operands[1].val <= $ffff) then
  1228. Begin
  1229. operands[1].opinfo := ao_imm16;
  1230. end { endif }
  1231. end { endif }
  1232. else
  1233. Begin
  1234. Message(assem_e_invalid_opcode_and_operand);
  1235. exit;
  1236. end
  1237. end;
  1238. { Handle special opcodes for the opcode }
  1239. { table. Set them up correctly. }
  1240. A_INS,A_IN:
  1241. Begin
  1242. if numops =2 then
  1243. Begin
  1244. if (operands[1].operandtype = OPR_REGISTER) and
  1245. (operands[1].reg = R_DX) then
  1246. Begin
  1247. operands[1].opinfo := ao_inoutportreg;
  1248. if (operands[2].operandtype = OPR_REGISTER) and
  1249. (operands[2].reg in [R_EAX,R_AX,R_AL]) and
  1250. (instruc = A_IN) then
  1251. Begin
  1252. operands[2].opinfo := ao_acc;
  1253. case operands[2].reg of
  1254. R_EAX: operands[2].size := S_L;
  1255. R_AX: operands[2].size := S_W;
  1256. R_AL: operands[2].size := S_B;
  1257. end;
  1258. end
  1259. end
  1260. else
  1261. if (operands[1].operandtype = OPR_CONSTANT) and
  1262. (operands[1].val <= $ff) And
  1263. (instruc = A_IN) then
  1264. Begin
  1265. operands[1].opinfo := ao_imm8;
  1266. operands[1].size := S_B;
  1267. if (operands[2].operandtype = OPR_REGISTER) and
  1268. (operands[2].reg in [R_EAX,R_AX,R_AL]) and
  1269. (instruc = A_IN) then
  1270. Begin
  1271. operands[2].opinfo := ao_acc;
  1272. end
  1273. end;
  1274. end
  1275. else
  1276. Begin
  1277. Message(assem_e_invalid_opcode_and_operand);
  1278. exit;
  1279. end;
  1280. end;
  1281. A_OUTS,A_OUT:
  1282. Begin
  1283. if numops =2 then
  1284. Begin
  1285. if (operands[2].operandtype = OPR_REGISTER) and
  1286. (operands[2].reg = R_DX) then
  1287. Begin
  1288. operands[2].opinfo := ao_inoutportreg;
  1289. if (operands[1].operandtype = OPR_REGISTER) and
  1290. (operands[1].reg in [R_EAX,R_AX,R_AL]) and
  1291. (instruc = A_OUT) then
  1292. Begin
  1293. operands[1].opinfo := ao_acc;
  1294. fits := TRUE;
  1295. end
  1296. end
  1297. else
  1298. if (operands[2].operandtype = OPR_CONSTANT) and
  1299. (operands[2].val <= $ff) and
  1300. (instruc = A_OUT) then
  1301. Begin
  1302. operands[2].opinfo := ao_imm8;
  1303. operands[2].size := S_B;
  1304. if (operands[1].operandtype = OPR_REGISTER) and
  1305. (operands[1].reg in [R_EAX,R_AX,R_AL]) and
  1306. (instruc = A_OUT) then
  1307. Begin
  1308. operands[1].opinfo := ao_acc;
  1309. fits := TRUE;
  1310. end
  1311. end;
  1312. end
  1313. else
  1314. Begin
  1315. Message(assem_e_invalid_opcode_and_operand);
  1316. exit;
  1317. end;
  1318. end;
  1319. A_RCL,A_RCR,A_ROL,A_ROR,A_SAL,A_SAR,A_SHL,A_SHR:
  1320. Begin
  1321. if numops =2 then
  1322. Begin
  1323. if (operands[1].operandtype = OPR_REGISTER) and
  1324. (operands[1].reg = R_CL) then
  1325. Begin
  1326. operands[1].opinfo := ao_shiftcount
  1327. end
  1328. else
  1329. if (operands[1].operandtype = OPR_CONSTANT) and
  1330. (operands[1].val <= $ff) then
  1331. Begin
  1332. operands[1].opinfo := ao_imm8;
  1333. operands[1].size := S_B;
  1334. end;
  1335. end
  1336. else { if numops = 2 }
  1337. Begin
  1338. Message(assem_e_invalid_opcode_and_operand);
  1339. exit;
  1340. end;
  1341. end;
  1342. { this did not work (PM) }
  1343. A_DIV, A_IDIV:
  1344. Begin
  1345. if (operands[2].operandtype = OPR_REGISTER) and
  1346. (operands[2].reg in [R_AL,R_AX,R_EAX]) then
  1347. operands[2].opinfo := ao_acc;
  1348. end;
  1349. A_FNSTSW, A_FSTSW:
  1350. Begin
  1351. { %ax can be omitted in ATT syntax }
  1352. if numops = 0 then
  1353. Begin
  1354. numops:=1;
  1355. operands[1].operandtype:=OPR_REGISTER;
  1356. operands[1].reg:=R_AX;
  1357. operands[1].opinfo := ao_acc;
  1358. end
  1359. else
  1360. if numops = 1 then
  1361. Begin
  1362. if (operands[1].operandtype = OPR_REGISTER) and
  1363. (operands[1].reg = R_AX) then
  1364. operands[1].opinfo := ao_acc;
  1365. end
  1366. else
  1367. Begin
  1368. Message(assem_e_invalid_opcode_and_operand);
  1369. exit;
  1370. end;
  1371. end;
  1372. A_SHLD,A_SHRD:
  1373. { these instruction are fully parsed individually on pass three }
  1374. { so we just do a summary checking here. }
  1375. Begin
  1376. if numops = 3 then
  1377. Begin
  1378. if (operands[1].operandtype = OPR_CONSTANT) and
  1379. (operands[1].val <= $ff) then
  1380. Begin
  1381. operands[1].opinfo := ao_imm8;
  1382. operands[1].size := S_B;
  1383. end;
  1384. end
  1385. else
  1386. Begin
  1387. Message(assem_e_invalid_opcode_and_operand);
  1388. exit;
  1389. end;
  1390. end;
  1391. A_INT:
  1392. Begin
  1393. if numops = 1 then
  1394. Begin
  1395. if (operands[1].operandtype = OPR_CONSTANT) and
  1396. (operands[1].val <= $ff) then
  1397. operands[1].opinfo := ao_imm8;
  1398. end
  1399. end;
  1400. A_RET:
  1401. Begin
  1402. if numops =1 then
  1403. Begin
  1404. if (operands[1].operandtype = OPR_CONSTANT) and
  1405. (operands[1].val <= $ffff) then
  1406. operands[1].opinfo := ao_imm16;
  1407. end
  1408. end;
  1409. { all string instructions have default memory }
  1410. { location which are ignored. Take care of }
  1411. { those. }
  1412. { Here could be added the code for segment }
  1413. { overrides. }
  1414. A_SCAS,A_CMPS,A_STOS,A_LODS:
  1415. Begin
  1416. if numops =1 then
  1417. Begin
  1418. operands[1].operandtype := OPR_NONE;
  1419. numops := 0;
  1420. end;
  1421. end;
  1422. A_XLAT:
  1423. Begin
  1424. { handle special TP syntax case for XLAT }
  1425. { here we accept XLAT, XLATB and XLAT m8 }
  1426. if (numops = 1) or (numops = 0) then
  1427. Begin
  1428. operands[1].operandtype := OPR_NONE;
  1429. numops := 0;
  1430. { always a byte for XLAT }
  1431. instr.stropsize := S_B;
  1432. end;
  1433. end;
  1434. { ------------------------------------------------------------------- }
  1435. { ------------------------- SIZE CHECK ------------------------------ }
  1436. { ------------- presently done only for most used opcodes ---------- }
  1437. { Checks if the suffix concords with the destination size , if }
  1438. { not gives out an error. (This check is stricter then gas but is }
  1439. { REQUIRED for intasmi3) }
  1440. A_MOV,A_ADD,A_SUB,A_ADC,A_SBB,A_CMP,A_AND,A_OR,A_TEST,A_XOR:
  1441. begin
  1442. if (instr.stropsize <> S_NO) then
  1443. Begin
  1444. if not CheckAndSetOpsize(operands[1],instr.stropsize) or
  1445. not CheckAndSetOpsize(operands[2],instr.stropsize) then
  1446. End;
  1447. end;
  1448. A_DEC,A_INC,A_NOT,A_NEG:
  1449. begin
  1450. if (instr.stropsize <> S_NO) and
  1451. (instr.operands[1].size <> S_NO) then
  1452. if (instr.stropsize <> instr.operands[1].size) then
  1453. begin
  1454. Message(assem_e_size_suffix_and_dest_reg_dont_match);
  1455. exit;
  1456. end;
  1457. end;
  1458. A_PUSH:
  1459. Begin
  1460. if (instr.operands[1].operandtype = OPR_CONSTANT) and
  1461. (instr.stropsize = S_NO) then
  1462. Message(assem_e_size_suffix_and_dest_reg_dont_match);
  1463. end;
  1464. End; { case }
  1465. {we have to start a new case because A_INS etc are already handled before
  1466. as well... (JM)}
  1467. Case instruc of
  1468. A_INS,A_MOVS,A_OUTS:
  1469. Begin
  1470. if numops =2 then
  1471. Begin
  1472. operands[2].operandtype := OPR_NONE;
  1473. operands[1].operandtype := OPR_NONE;
  1474. numops := 0;
  1475. end;
  1476. end;
  1477. { handle parameter for segment overrides }
  1478. end; { case }
  1479. { ------------------------------------------------------------------- }
  1480. { copy them to local variables }
  1481. { for faster access }
  1482. optyp1:=operands[1].opinfo;
  1483. optyp2:=operands[2].opinfo;
  1484. optyp3:=operands[3].opinfo;
  1485. end; { end with }
  1486. { after reading the operands }
  1487. { search the instruction }
  1488. { setup startvalue from cache }
  1489. if itcache^[instruc]<>-1 then
  1490. i:=itcache^[instruc]
  1491. else
  1492. i:=0;
  1493. { I think this is too dangerous for me therefore i decided that for }
  1494. { the att version only if the processor > i386 or we are compiling }
  1495. { the system unit then this will be allowed... }
  1496. if (instruc > lastop_ittable) then
  1497. begin
  1498. Message1(assem_w_opcode_not_in_table,upper(att_op2str[instruc]));
  1499. fits:=true;
  1500. end
  1501. else while not(fits) do
  1502. begin
  1503. { set the instruction cache, if the instruction }
  1504. { occurs the first time }
  1505. if (it[i].i=instruc) and (itcache^[instruc]=-1) then
  1506. itcache^[instruc]:=i;
  1507. if (it[i].i=instruc) and (instr.numops=it[i].ops) then
  1508. begin
  1509. { first fit }
  1510. case instr.numops of
  1511. 0 : begin
  1512. fits:=true;
  1513. break;
  1514. end;
  1515. 1 :
  1516. Begin
  1517. if (optyp1 and it[i].o1)<>0 then
  1518. Begin
  1519. fits:=true;
  1520. break;
  1521. end;
  1522. { I consider sign-extended 8bit value to }
  1523. { be equal to immediate 8bit therefore }
  1524. { convert... }
  1525. if (optyp1 = ao_imm8) then
  1526. Begin
  1527. { check if this is a simple sign extend. }
  1528. if (it[i].o1<>ao_imm8s) then
  1529. Begin
  1530. fits:=true;
  1531. break;
  1532. end;
  1533. end;
  1534. end;
  1535. 2 : if ((optyp1 and it[i].o1)<>0) and
  1536. ((optyp2 and it[i].o2)<>0) then
  1537. Begin
  1538. fits:=true;
  1539. break;
  1540. end
  1541. { if the operands can be swaped }
  1542. { then swap them }
  1543. else if ((it[i].m and af_d)<>0) and
  1544. ((optyp1 and it[i].o2)<>0) and
  1545. ((optyp2 and it[i].o1)<>0) then
  1546. begin
  1547. fits:=true;
  1548. break;
  1549. end;
  1550. 3 : if ((optyp1 and it[i].o1)<>0) and
  1551. ((optyp2 and it[i].o2)<>0) and
  1552. ((optyp3 and it[i].o3)<>0) then
  1553. Begin
  1554. fits:=true;
  1555. break;
  1556. end;
  1557. end; { end case }
  1558. end; { endif }
  1559. if it[i].i=A_NONE then
  1560. begin
  1561. { NO MATCH! }
  1562. Message(assem_e_invalid_opcode_and_operand);
  1563. exit;
  1564. end;
  1565. inc(i);
  1566. end; { end while }
  1567. { We add the opcode to the opcode linked list }
  1568. if fits then
  1569. Begin
  1570. if instr.getprefix <> A_NONE then
  1571. Begin
  1572. p^.concat(new(pai386,op_none(instr.getprefix,S_NO)));
  1573. end;
  1574. { change from AT&T styled floating point to }
  1575. { intel styled floating point with valid size }
  1576. { we use these instructions so it does not }
  1577. { mess up intasmi3 }
  1578. if (instruc >= A_FILDQ) and (instruc <= A_FIDIVRS) then
  1579. Begin
  1580. instr.stropsize := _fpusizes[instruc];
  1581. instr.addinstr(_fpuopcodes[instruc]);
  1582. instruc := instr.getinstruction;
  1583. end;
  1584. case instr.numops of
  1585. 0:
  1586. if instr.stropsize <> S_NO then
  1587. { is this a string operation opcode or xlat then check }
  1588. { the size of the operation. }
  1589. p^.concat(new(pai386,op_none(instruc,instr.stropsize)))
  1590. else
  1591. p^.concat(new(pai386,op_none(instruc,S_NO)));
  1592. 1: Begin
  1593. case instr.operands[1].operandtype of
  1594. { GAS requires that the size be set in the case of a push }
  1595. { constant value, }
  1596. OPR_CONSTANT:
  1597. Begin
  1598. if instruc = A_PUSH then
  1599. Begin
  1600. if instr.stropsize <> S_NO then
  1601. p^.concat(new(pai386,op_const(instruc,
  1602. instr.stropsize, instr.operands[1].val)))
  1603. else
  1604. Message(assem_e_invalid_opcode_and_operand);
  1605. end
  1606. else
  1607. p^.concat(new(pai386,op_const(instruc,
  1608. S_NO, instr.operands[1].val)));
  1609. end;
  1610. OPR_REGISTER:
  1611. Begin
  1612. if (instr.stropsize<>S_NO) then
  1613. opsize:=instr.stropsize
  1614. else
  1615. opsize:=instr.operands[1].size;
  1616. p^.concat(new(pai386,op_reg(instruc,opsize,instr.operands[1].reg)));
  1617. End;
  1618. OPR_SYMBOL:
  1619. Begin
  1620. p^.concat(new(pai386,op_sym(instruc,
  1621. instr.stropsize,instr.operands[1].symbol)));
  1622. End;
  1623. OPR_REFERENCE:
  1624. { now first check suffix ... }
  1625. if instr.stropsize <> S_NO then
  1626. Begin
  1627. p^.concat(new(pai386,op_ref(instruc,
  1628. instr.stropsize,newreference(instr.operands[1].ref))));
  1629. end
  1630. { no suffix... therefore resort using intel styled checking .. }
  1631. else if (instr.operands[1].size <> S_NO) and
  1632. Not ((instruc = A_CALL) or (instruc = A_JMP)) then
  1633. Begin
  1634. p^.concat(new(pai386,op_ref(instruc,
  1635. instr.operands[1].size,newreference(instr.operands[1].ref))));
  1636. end
  1637. else
  1638. Begin
  1639. { special jmp and call case with }
  1640. { symbolic references. }
  1641. Case instruc of
  1642. A_CALL,A_JMP,A_FNSTCW,A_FSTCW,A_FLDCW,A_FNSTSW,
  1643. A_FSTSW,A_FLDENV,A_FSTENV,A_FNSAVE,A_FSAVE:
  1644. Begin
  1645. p^.concat(new(pai386,op_ref(instruc,
  1646. S_NO,newreference(instr.operands[1].ref))));
  1647. end
  1648. else
  1649. Message(assem_e_invalid_opcode_and_operand);
  1650. End
  1651. end;
  1652. { This either crashed the compiler or the symbol would always be nil! }
  1653. { The problem is here is I didn't see any way of adding the labeled }
  1654. { symbol in the internal list, since i think from what i see in aasm }
  1655. { that these will automatically be declared as external ?? }
  1656. { note: has to be changed to a case if ever activated again to avoid }
  1657. { range problems (JM) }
  1658. { if (instruc in [A_JO,A_JNO,A_JB,A_JC,A_JNAE,
  1659. A_JNB,A_JNC,A_JAE,A_JE,A_JZ,A_JNE,A_JNZ,A_JBE,A_JNA,A_JNBE,
  1660. A_JA,A_JS,A_JNS,A_JP,A_JPE,A_JNP,A_JPO,A_JL,A_JNGE,A_JNL,A_JGE,
  1661. A_JLE,A_JNG,A_JNLE,A_JG,A_JCXZ,A_JECXZ,A_LOOP,A_LOOPZ,A_LOOPE,
  1662. A_LOOPNZ,A_LOOPNE,A_JMP,A_CALL]) then
  1663. Begin
  1664. if assigned(instr.operands[1].ref.symbol) then
  1665. p^.concat(new(pai386,op_csymbol(instruc,
  1666. S_NO,newcsymbol(instr.operands[1].ref.symbol^,instr.operands[1].ref.offset))))
  1667. else
  1668. Message(assem_e_invalid_opcode_and_operand);
  1669. end
  1670. else
  1671. else
  1672. Message(assem_e_invalid_opcode_and_operand);
  1673. end;}
  1674. OPR_NONE: Begin
  1675. Message(assem_f_internal_error_in_concatopcode);
  1676. end;
  1677. else
  1678. Begin
  1679. Message(assem_f_internal_error_in_concatopcode);
  1680. end;
  1681. end;
  1682. end;
  1683. 2:
  1684. Begin
  1685. Case instruc Of
  1686. A_MOVSX,A_MOVZX,A_MOVSB,A_MOVSBL,A_MOVSBW,A_MOVSWL,
  1687. A_MOVZB,A_MOVZWL:
  1688. { movzx and movsx }
  1689. HandleExtend(instr);
  1690. else
  1691. { other instructions }
  1692. Begin
  1693. With instr do
  1694. Begin
  1695. { source }
  1696. opsize := operands[1].size;
  1697. case operands[1].operandtype of
  1698. { reg,reg }
  1699. { reg,ref }
  1700. { const,reg -- IN/OUT }
  1701. OPR_REGISTER:
  1702. Begin
  1703. case operands[2].operandtype of
  1704. OPR_REGISTER:
  1705. { correction: according to the DJGPP FAQ, gas }
  1706. { doesn't even check correctly the size of }
  1707. { operands, therefore let us specify a size! }
  1708. { as in the GAS docs... destination tells us }
  1709. { the size! This might give out invalid output }
  1710. { in some very rare cases (because the size }
  1711. { checking is still not perfect). }
  1712. if (opsize = operands[2].size) then
  1713. begin
  1714. p^.concat(new(pai386,op_reg_reg(instruc,
  1715. opsize,operands[1].reg,operands[2].reg)));
  1716. end
  1717. else
  1718. Case instruc of
  1719. A_IN:
  1720. p^.concat(new(pai386,op_reg_reg(instruc,
  1721. operands[2].size,operands[1].reg,operands[2].reg)));
  1722. A_OUT:
  1723. p^.concat(new(pai386,op_reg_reg(instruc,
  1724. operands[1].size,operands[1].reg,operands[2].reg)));
  1725. { these do not require any size specification. }
  1726. A_SAL,A_SAR,A_SHL,A_SHR,A_ROL,A_ROR,A_RCR,
  1727. A_RCL:
  1728. { outs and ins are already taken care by }
  1729. { the first pass. }
  1730. p^.concat(new(pai386,op_reg_reg(instruc,
  1731. S_NO,operands[1].reg,operands[2].reg)))
  1732. else
  1733. if stropsize <> S_NO then
  1734. Begin
  1735. p^.concat(new(pai386,op_reg_reg(instruc,
  1736. stropsize,operands[1].reg,operands[2].reg)))
  1737. end
  1738. else
  1739. Begin
  1740. Message(assem_e_invalid_opcode_and_operand);
  1741. end;
  1742. end; {case instruc of}
  1743. OPR_REFERENCE:
  1744. { variable name. }
  1745. { here we must check the instruction type }
  1746. { before deciding if to use and compare }
  1747. { any sizes. }
  1748. if assigned(operands[2].ref.symbol) then
  1749. Begin
  1750. if stropsize <> S_NO then
  1751. Begin
  1752. p^.concat(new(pai386,op_reg_ref(instruc,
  1753. stropsize,operands[1].reg,newreference(operands[2].ref))))
  1754. end
  1755. else
  1756. if (opsize = operands[2].size) Then
  1757. p^.concat(new(pai386,op_reg_ref(instruc,
  1758. opsize,operands[1].reg,newreference(operands[2].ref))))
  1759. else
  1760. Case instruc of
  1761. A_RCL,A_RCR,A_ROL,A_ROR,A_SAL,A_SAR,
  1762. A_SHR,A_SHL:
  1763. p^.concat(new(pai386,op_reg_ref(instruc,
  1764. opsize,operands[1].reg,newreference(operands[2].ref))))
  1765. else
  1766. Message(assem_e_invalid_size_in_ref);
  1767. end
  1768. end
  1769. else
  1770. Begin
  1771. { register reference }
  1772. if stropsize <> S_NO then
  1773. Begin
  1774. p^.concat(new(pai386,op_reg_ref(instruc,
  1775. stropsize,operands[1].reg,newreference(operands[2].ref))))
  1776. end
  1777. else
  1778. if (opsize = operands[2].size) or
  1779. (operands[2].size = S_NO) then
  1780. p^.concat(new(pai386,op_reg_ref(instruc,
  1781. opsize,operands[1].reg,newreference(operands[2].ref))))
  1782. else
  1783. Message(assem_e_invalid_size_in_ref);
  1784. end;
  1785. OPR_CONSTANT: { OUT }
  1786. begin
  1787. { determine first with suffix }
  1788. if instruc = A_OUT then
  1789. begin
  1790. if instr.stropsize <> S_NO then
  1791. p^.concat(new(pai386,op_reg_const(instruc,stropsize,
  1792. instr.operands[1].reg, instr.operands[2].val)))
  1793. else
  1794. p^.concat(new(pai386,op_reg_const(instruc,S_NO,
  1795. instr.operands[1].reg, instr.operands[2].val)));
  1796. end
  1797. else
  1798. Message(assem_e_invalid_opcode);
  1799. end;
  1800. else { else case }
  1801. Begin
  1802. Message(assem_f_internal_error_in_concatopcode);
  1803. end;
  1804. end; { end inner case }
  1805. end;
  1806. { const,reg }
  1807. { const,const }
  1808. { const,ref }
  1809. OPR_CONSTANT:
  1810. case instr.operands[2].operandtype of
  1811. { constant, constant does not have a specific size. }
  1812. OPR_CONSTANT:
  1813. p^.concat(new(pai386,op_const_const(instruc,
  1814. S_NO,operands[1].val,operands[2].val)));
  1815. OPR_REFERENCE:
  1816. Begin
  1817. { check for suffix first ... }
  1818. if (instr.stropsize <> S_NO) then
  1819. Begin
  1820. p^.concat(new(pai386,op_const_ref(instruc,
  1821. stropsize,operands[1].val,
  1822. newreference(operands[2].ref))))
  1823. end
  1824. else
  1825. { resort to intel styled checking ... }
  1826. if (operands[1].val <= $ff) and
  1827. (operands[2].size in [S_B,S_W,S_L]) then
  1828. p^.concat(new(pai386,op_const_ref(instruc,
  1829. operands[2].size,operands[1].val,
  1830. newreference(operands[2].ref))))
  1831. else
  1832. if (operands[1].val <= $ffff) and
  1833. (operands[2].size in [S_W,S_L]) then
  1834. p^.concat(new(pai386,op_const_ref(instruc,
  1835. operands[2].size,operands[1].val,
  1836. newreference(operands[2].ref))))
  1837. else
  1838. if (operands[1].val <= $7fffffff) and
  1839. (operands[2].size in [S_L]) then
  1840. p^.concat(new(pai386,op_const_ref(instruc,
  1841. operands[2].size,operands[1].val,
  1842. newreference(operands[2].ref))))
  1843. else
  1844. Message(assem_e_invalid_size_in_ref);
  1845. end;
  1846. OPR_REGISTER:
  1847. Begin
  1848. { size of opcode determined by register }
  1849. if (operands[1].val <= $ff) and
  1850. (operands[2].size in [S_B,S_W,S_L]) then
  1851. p^.concat(new(pai386,op_const_reg(instruc,
  1852. operands[2].size,operands[1].val,
  1853. operands[2].reg)))
  1854. else
  1855. if (operands[1].val <= $ffff) and
  1856. (operands[2].size in [S_W,S_L]) then
  1857. p^.concat(new(pai386,op_const_reg(instruc,
  1858. operands[2].size,operands[1].val,
  1859. operands[2].reg)))
  1860. else
  1861. if (operands[1].val <= $7fffffff) and
  1862. (operands[2].size in [S_L]) then
  1863. p^.concat(new(pai386,op_const_reg(instruc,
  1864. operands[2].size,operands[1].val,
  1865. operands[2].reg)))
  1866. else
  1867. Message(assem_e_invalid_opcode_size);
  1868. end;
  1869. else
  1870. Begin
  1871. Message(assem_f_internal_error_in_concatopcode);
  1872. end;
  1873. end; { end case }
  1874. { sym,reg }
  1875. OPR_SYMBOL:
  1876. case instr.operands[2].operandtype of
  1877. OPR_REGISTER:
  1878. Begin
  1879. Case instruc of
  1880. A_LDS,A_LES,A_LFS,A_LGS,A_LSS:
  1881. opsize:=S_NO
  1882. else
  1883. if stropsize<>S_NO then
  1884. opsize:=stropsize
  1885. else
  1886. if (opsize<>operands[2].size) then
  1887. Message(assem_e_invalid_opcode_and_operand);
  1888. { create an temporary reference }
  1889. End; {case}
  1890. reset_reference(href);
  1891. href.symbol:=instr.operands[1].symbol;
  1892. p^.concat(new(pai386,op_ref_reg(instruc,opsize,
  1893. newreference(href),operands[2].reg)));
  1894. clear_reference(href);
  1895. end;
  1896. else
  1897. Begin
  1898. Message(assem_f_internal_error_in_concatopcode);
  1899. end;
  1900. end; { end inner case }
  1901. { ref,reg }
  1902. { ref,ref }
  1903. OPR_REFERENCE:
  1904. case instr.operands[2].operandtype of
  1905. OPR_REGISTER:
  1906. if assigned(operands[1].ref.symbol) then
  1907. { global variable }
  1908. Begin
  1909. Case instruc Of
  1910. A_LDS,A_LES,A_LFS,A_LGS,A_LSS:
  1911. opsize:=S_NO
  1912. else
  1913. if stropsize<>S_NO then
  1914. opsize:=stropsize
  1915. else
  1916. if (opsize<>operands[2].size) then
  1917. Message(assem_e_invalid_opcode_and_operand);
  1918. end; { case }
  1919. p^.concat(new(pai386,op_ref_reg(instruc,
  1920. opsize,newreference(operands[1].ref),operands[2].reg)));
  1921. end
  1922. else
  1923. Begin
  1924. { register reference }
  1925. { possiblities:1) local variable which }
  1926. { has been replaced by bp and offset }
  1927. { in this case size should be valid }
  1928. { 2) Indirect register }
  1929. { adressing, 2nd operand determines }
  1930. { size. }
  1931. if (stropsize <> S_NO) then
  1932. Begin
  1933. p^.concat(new(pai386,op_ref_reg(instruc,
  1934. stropsize,newreference(operands[1].ref),
  1935. operands[2].reg)))
  1936. end
  1937. else
  1938. if (opsize = operands[2].size) or
  1939. (opsize = S_NO) then
  1940. Begin
  1941. p^.concat(new(pai386,op_ref_reg(instruc,
  1942. operands[2].size,newreference(operands[1].ref),
  1943. operands[2].reg)));
  1944. end
  1945. else
  1946. Message(assem_e_invalid_size_in_ref);
  1947. end;
  1948. OPR_REFERENCE: { special opcodes }
  1949. p^.concat(new(pai386,op_ref_ref(instruc,
  1950. opsize,newreference(operands[1].ref),
  1951. newreference(operands[2].ref))));
  1952. else
  1953. Begin
  1954. Message(assem_f_internal_error_in_concatopcode);
  1955. end;
  1956. end; { end inner case }
  1957. end; { end case }
  1958. end; { end with }
  1959. end; {end else of case instruc of movsx ... }
  1960. end; { end case movsx ...}
  1961. end;
  1962. 3: Begin
  1963. { only imul, shld and shrd }
  1964. { middle must be a register }
  1965. if (instruc = A_SHLD) Or (instruc = A_SHRD) and
  1966. (instr.operands[2].operandtype = OPR_REGISTER) then
  1967. Begin
  1968. case instr.operands[2].size of
  1969. S_W: if instr.operands[1].operandtype = OPR_CONSTANT then
  1970. Begin
  1971. if instr.operands[1].val <= $ff then
  1972. Begin
  1973. if instr.operands[3].size in [S_W] then
  1974. Begin
  1975. case instr.operands[3].operandtype of
  1976. OPR_REFERENCE: { MISSING !!!! } ;
  1977. OPR_REGISTER: p^.concat(new(pai386,
  1978. op_const_reg_reg(instruc, S_W,
  1979. instr.operands[1].val, instr.operands[2].reg,
  1980. instr.operands[3].reg)));
  1981. else
  1982. Message(assem_e_invalid_opcode_and_operand);
  1983. end;
  1984. end
  1985. else
  1986. Message(assem_e_invalid_opcode_and_operand);
  1987. end;
  1988. end
  1989. else
  1990. Message(assem_e_invalid_opcode_and_operand);
  1991. S_L: if instr.operands[1].operandtype = OPR_CONSTANT then
  1992. Begin
  1993. if instr.operands[1].val <= $ff then
  1994. Begin
  1995. if instr.operands[3].size in [S_L] then
  1996. Begin
  1997. case instr.operands[3].operandtype of
  1998. OPR_REFERENCE: { MISSING !!!! } ;
  1999. OPR_REGISTER: p^.concat(new(pai386,
  2000. op_const_reg_reg(instruc, S_L,
  2001. instr.operands[1].val, instr.operands[2].reg,
  2002. instr.operands[3].reg)));
  2003. else
  2004. Message(assem_e_invalid_opcode_and_operand);
  2005. end;
  2006. end
  2007. else
  2008. Message(assem_e_invalid_opcode_and_operand);
  2009. end;
  2010. end
  2011. else
  2012. Message(assem_e_invalid_opcode_and_operand);
  2013. else
  2014. Message(assem_e_invalid_opcode_and_operand);
  2015. end; { end case }
  2016. end
  2017. else
  2018. if (instruc = A_IMUL) and (instr.operands[3].operandtype
  2019. = OPR_REGISTER) then
  2020. Begin
  2021. case instr.operands[3].size of
  2022. S_W: if instr.operands[1].operandtype = OPR_CONSTANT then
  2023. Begin
  2024. if instr.operands[1].val <= $ffff then
  2025. Begin
  2026. if instr.operands[2].size in [S_W] then
  2027. Begin
  2028. case instr.operands[2].operandtype of
  2029. OPR_REFERENCE: { MISSING !!!! } ;
  2030. OPR_REGISTER: p^.concat(new(pai386,
  2031. op_const_reg_reg(instruc, S_W,
  2032. instr.operands[1].val, instr.operands[2].reg,
  2033. instr.operands[3].reg)));
  2034. else
  2035. Message(assem_e_invalid_opcode_and_operand);
  2036. end; { end case }
  2037. end
  2038. else
  2039. Message(assem_e_invalid_opcode_and_operand);
  2040. end;
  2041. end
  2042. else
  2043. Message(assem_e_invalid_opcode_and_operand);
  2044. S_L: if instr.operands[1].operandtype = OPR_CONSTANT then
  2045. Begin
  2046. if instr.operands[1].val <= $7fffffff then
  2047. Begin
  2048. if instr.operands[2].size in [S_L] then
  2049. Begin
  2050. case instr.operands[2].operandtype of
  2051. OPR_REFERENCE: { MISSING !!!! } ;
  2052. OPR_REGISTER: p^.concat(new(pai386,
  2053. op_const_reg_reg(instruc, S_L,
  2054. instr.operands[1].val, instr.operands[2].reg,
  2055. instr.operands[3].reg)));
  2056. else
  2057. Message(assem_e_invalid_opcode_and_operand);
  2058. end; { end case }
  2059. end
  2060. else
  2061. Message(assem_e_invalid_opcode_and_operand);
  2062. end;
  2063. end
  2064. else
  2065. Message(assem_e_invalid_opcode_and_operand);
  2066. else
  2067. Message(assem_e_invalid_middle_sized_operand);
  2068. end; { end case }
  2069. end { endif }
  2070. else
  2071. Message(assem_e_invalid_three_operand_opcode);
  2072. end;
  2073. end; { end case }
  2074. end;
  2075. end;
  2076. Procedure ConcatLabeledInstr(var instr: TInstruction);
  2077. Var instruct : tasmop;
  2078. i : longint;
  2079. Begin
  2080. instruct:=instr.getinstruction;
  2081. Case instruct Of
  2082. A_JO,A_JNO,A_JB,A_JC,A_JNAE,
  2083. A_JNB,A_JNC,A_JAE,A_JE,A_JZ,A_JNE,A_JNZ,A_JBE,A_JNA,A_JNBE,
  2084. A_JA,A_JS,A_JNS,A_JP,A_JPE,A_JNP,A_JPO,A_JL,A_JNGE,A_JNL,A_JGE,
  2085. A_JLE,A_JNG,A_JNLE,A_JG,A_JCXZ,A_JECXZ,A_LOOP,A_LOOPZ,A_LOOPE,
  2086. A_LOOPNZ,A_LOOPNE,A_JMP,A_CALL:
  2087. Begin
  2088. if (instr.numops <> 1) then
  2089. Message(assem_e_invalid_labeled_opcode)
  2090. else if instr.operands[1].operandtype <> OPR_LABINSTR then
  2091. Message(assem_e_invalid_labeled_opcode)
  2092. else if assigned(instr.operands[1].hl) then
  2093. p^.concat(new(pai386_labeled,op_lab(instruct, instr.operands[1].hl)))
  2094. else
  2095. Begin
  2096. Message(assem_f_internal_error_in_concatlabeledinstr);
  2097. end;
  2098. end;
  2099. A_MOV: { move from/to rel8 };
  2100. else
  2101. if (cs_compilesystem in aktmoduleswitches) then
  2102. begin
  2103. for i:=1 to instr.numops do
  2104. if instr.operands[i].operandtype=OPR_LABINSTR then
  2105. begin
  2106. instr.operands[i].operandtype:=OPR_REFERENCE;
  2107. instr.operands[i].ref.symbol:=newpasstr(lab2str(instr.operands[i].hl) );
  2108. instr.operands[i].opinfo:=ao_mem;
  2109. instr.operands[i].ref.base:=R_NO;
  2110. instr.operands[i].ref.index:=R_NO;
  2111. instr.operands[i].ref.segment:=R_DEFAULT_SEG;
  2112. instr.operands[i].ref.offset:=0;
  2113. end;
  2114. { handle now as an ordinary opcode }
  2115. concatopcode(instr);
  2116. end
  2117. else
  2118. Message1(assem_e_invalid_operand,'');
  2119. end; { case }
  2120. end;
  2121. {---------------------------------------------------------------------}
  2122. { Routines for the parsing }
  2123. {---------------------------------------------------------------------}
  2124. procedure consume(t : tinteltoken);
  2125. begin
  2126. if t<>actasmtoken then
  2127. Message(assem_e_syntax_error);
  2128. actasmtoken:=gettoken;
  2129. { set the previous id flag }
  2130. previous_was_id:=(actasmtoken=AS_ID);
  2131. { if the token must be ignored, then }
  2132. { get another token to parse. }
  2133. if actasmtoken = AS_NONE then
  2134. actasmtoken := gettoken;
  2135. end;
  2136. function findregister(const s : string): tregister;
  2137. {*********************************************************************}
  2138. { FUNCTION findregister(s: string):tasmop; }
  2139. { Description: Determines if the s string is a valid register, }
  2140. { if so returns correct tregister token, or R_NO if not found. }
  2141. {*********************************************************************}
  2142. var
  2143. i: tregister;
  2144. begin
  2145. findregister := R_NO;
  2146. for i:=firstreg to lastreg do
  2147. if s = iasmregs[i] then
  2148. Begin
  2149. findregister := i;
  2150. exit;
  2151. end;
  2152. end;
  2153. function findprefix(const s: string; var token: tasmop): boolean;
  2154. var i: byte;
  2155. Begin
  2156. findprefix := FALSE;
  2157. for i:=0 to _count_asmprefixes do
  2158. Begin
  2159. if s = _asmprefixes[i] then
  2160. begin
  2161. token := _prefixtokens[i];
  2162. findprefix := TRUE;
  2163. exit;
  2164. end;
  2165. end;
  2166. end;
  2167. function findsegment(const s:string): tregister;
  2168. {*********************************************************************}
  2169. { FUNCTION findsegment(s: string):tasmop; }
  2170. { Description: Determines if the s string is a valid segment register}
  2171. { if so returns correct tregister token, or R_NO if not found. }
  2172. {*********************************************************************}
  2173. var
  2174. i: tregister;
  2175. Begin
  2176. findsegment := R_DEFAULT_SEG;
  2177. for i:=firstsreg to lastsreg do
  2178. if s = iasmregs[i] then
  2179. Begin
  2180. findsegment := i;
  2181. exit;
  2182. end;
  2183. end;
  2184. function findopcode(const s: string): tasmop;
  2185. {*********************************************************************}
  2186. { FUNCTION findopcode(s: string): tasmop; }
  2187. { Description: Determines if the s string is a valid opcode }
  2188. { if so returns correct tasmop token. }
  2189. {*********************************************************************}
  2190. var
  2191. i: tasmop;
  2192. j: byte;
  2193. hs: topsize;
  2194. hid: string;
  2195. Begin
  2196. findopcode := A_NONE;
  2197. { first search for extended opcodes }
  2198. { now, in this case, we must use the suffix }
  2199. { to determine the size of the instruction }
  2200. for j:=0 to _count_asmspecialops do
  2201. Begin
  2202. if s = _specialops[j] then
  2203. Begin
  2204. findopcode := _specialopstokens[j];
  2205. { set the size }
  2206. case s[length(s)] of
  2207. 'B': instr.stropsize := S_B;
  2208. 'L': instr.stropsize := S_L;
  2209. 'W': instr.stropsize := S_W;
  2210. end;
  2211. exit;
  2212. end;
  2213. end;
  2214. for i:=firstop to lastop do
  2215. Begin
  2216. if s=iasmops^[i] then
  2217. begin
  2218. findopcode := i;
  2219. instr.stropsize := S_NO;
  2220. exit;
  2221. end;
  2222. end;
  2223. { not found yet ... }
  2224. { search for all possible suffixes }
  2225. for hs:=S_WL downto S_B do
  2226. if copy(s,length(s)-length(att_opsize2str[hs])+1,
  2227. length(att_opsize2str[hs]))=upper(att_opsize2str[hs]) then
  2228. begin
  2229. hid:=copy(s,1,length(s)-length(att_opsize2str[hs]));
  2230. for i:=firstop to lastop do
  2231. if (length(hid) > 0) and (hid=iasmops^[i]) then
  2232. begin
  2233. findopcode := i;
  2234. instr.stropsize := hs;
  2235. exit;
  2236. end;
  2237. end;
  2238. end;
  2239. Function CheckPrefix(prefix: tasmop; opcode:tasmop): Boolean;
  2240. { Checks if the prefix is valid with the following instruction }
  2241. { return false if not, otherwise true }
  2242. Begin
  2243. CheckPrefix := TRUE;
  2244. Case prefix of
  2245. A_REP,A_REPNE,A_REPE:
  2246. Case opcode Of
  2247. A_SCAS,A_INS,A_OUTS,A_MOVS,
  2248. A_CMPS,A_LODS,A_STOS:;
  2249. Else
  2250. Begin
  2251. CheckPrefix := FALSE;
  2252. exit;
  2253. end;
  2254. End;
  2255. A_LOCK:
  2256. Case opcode Of
  2257. A_BT,A_BTS,A_BTR,A_BTC,A_XCHG,A_ADD,A_OR,
  2258. A_ADC,A_SBB,A_AND,A_SUB,A_XOR,A_NOT,A_NEG,A_INC,A_DEC:;
  2259. Else
  2260. Begin
  2261. CheckPrefix := FALSE;
  2262. Exit;
  2263. end;
  2264. End;
  2265. A_NONE: exit; { no prefix here }
  2266. else
  2267. CheckPrefix := FALSE;
  2268. end; { end case }
  2269. end;
  2270. Procedure InitAsmRef(var instr: TInstruction);
  2271. {*********************************************************************}
  2272. { Description: This routine first check if the instruction is of }
  2273. { type OPR_NONE, or OPR_REFERENCE , if not it gives out an error. }
  2274. { If the operandtype = OPR_NONE or <> OPR_REFERENCE then it sets up }
  2275. { the operand type to OPR_REFERENCE, as well as setting up the ref }
  2276. { to point to the default segment. }
  2277. {*********************************************************************}
  2278. Begin
  2279. With instr do
  2280. Begin
  2281. case operands[operandnum].operandtype of
  2282. OPR_REFERENCE: exit;
  2283. OPR_NONE: ;
  2284. else
  2285. Message(assem_e_invalid_operand_type);
  2286. end;
  2287. operands[operandnum].operandtype := OPR_REFERENCE;
  2288. operands[operandnum].ref.segment := R_DEFAULT_SEG;
  2289. end;
  2290. end;
  2291. Function CheckOverride(segreg: tregister; var instr: TInstruction): Boolean;
  2292. { Check if the override is valid, and if so then }
  2293. { update the instr variable accordingly. }
  2294. Begin
  2295. CheckOverride := FALSE;
  2296. Case instr.getinstruction of
  2297. A_MOVS,A_XLAT,A_CMPS:
  2298. Begin
  2299. CheckOverride := TRUE;
  2300. Message(assem_e_segment_override_not_supported);
  2301. end
  2302. end
  2303. end;
  2304. Procedure GetRecordOffsetSize(const expr: string;var offset:longint;var size:longint);
  2305. {*********************************************************************}
  2306. { PROCEDURE GetRecordOffsetSize }
  2307. { Description: This routine builds up a record offset after a AS_DOT }
  2308. { token is encountered. }
  2309. { On entry actasmtoken should be equal to AS_DOT }
  2310. {*********************************************************************}
  2311. { EXIT CONDITION: On exit the routine should point to either the }
  2312. { ERROR RECOVER: read until AS_COMMA or AS_SEPARATOR token. }
  2313. { Warning: This is called recursively. }
  2314. {*********************************************************************}
  2315. var
  2316. toffset,tsize : longint;
  2317. Begin
  2318. offset:=0;
  2319. size:=0;
  2320. Consume(AS_DOT);
  2321. if actasmtoken = AS_ID then
  2322. Begin
  2323. if not GetTypeOffsetSize(expr,actasmpattern,toffset,tsize) and
  2324. not GetVarOffsetSize(expr,actasmpattern,toffset,tsize) then
  2325. begin
  2326. Message(assem_e_syntax_error);
  2327. toffset:=0;
  2328. tsize:=0;
  2329. end;
  2330. inc(offset,toffset);
  2331. size:=tsize;
  2332. Consume(AS_ID);
  2333. if actasmtoken=AS_DOT then
  2334. begin
  2335. GetRecordOffsetSize(expr,toffset,tsize);
  2336. inc(offset,toffset);
  2337. size:=tsize;
  2338. end;
  2339. end
  2340. else
  2341. Begin
  2342. Message(assem_e_syntax_error);
  2343. repeat
  2344. consume(actasmtoken)
  2345. until (actasmtoken = AS_SEPARATOR) or (actasmtoken = AS_COMMA);
  2346. end;
  2347. end;
  2348. Function BuildConstExpression(allowref,betweenbracket:boolean): longint;
  2349. {*********************************************************************}
  2350. { FUNCTION BuildConstExpression: longint }
  2351. { Description: This routine calculates a constant expression to }
  2352. { a given value. The return value is the value calculated from }
  2353. { the expression. }
  2354. { The following tokens (not strings) are recognized: }
  2355. { (,),SHL,SHR,/,*,NOT,OR,XOR,AND,MOD,+/-,numbers,ID to constants. }
  2356. {*********************************************************************}
  2357. { ENTRY: On entry the token should be any valid expression token. }
  2358. { EXIT: On Exit the token points to any token after the closing }
  2359. { RBRACKET }
  2360. { ERROR RECOVERY: Tries to find COMMA or SEPARATOR token by consuming }
  2361. { invalid tokens. }
  2362. {*********************************************************************}
  2363. var
  2364. tempstr,expr : string;
  2365. parenlevel,l,k : longint;
  2366. errorflag : boolean;
  2367. prevtoken : tinteltoken;
  2368. Begin
  2369. errorflag := FALSE;
  2370. tempstr := '';
  2371. expr := '';
  2372. inexpression := TRUE;
  2373. prevtoken := AS_NONE;
  2374. parenlevel := 0;
  2375. Repeat
  2376. if actasmtoken<>AS_LPAREN then
  2377. prevtoken:=actasmtoken;
  2378. Case actasmtoken of
  2379. AS_LPAREN:
  2380. Begin
  2381. { Exit if ref? }
  2382. if allowref and (prevtoken in [AS_INTNUM,AS_BINNUM,AS_OCTALNUM,AS_ID,AS_HEXNUM]) then
  2383. break;
  2384. Consume(AS_LPAREN);
  2385. expr := expr + '(';
  2386. inc(parenlevel);
  2387. end;
  2388. AS_RPAREN:
  2389. Begin
  2390. { end of ref ? }
  2391. if (parenlevel=0) and betweenbracket then
  2392. break;
  2393. Consume(AS_RPAREN);
  2394. expr := expr + ')';
  2395. dec(parenlevel);
  2396. end;
  2397. AS_SHL:
  2398. Begin
  2399. Consume(AS_SHL);
  2400. expr := expr + '<';
  2401. end;
  2402. AS_SHR:
  2403. Begin
  2404. Consume(AS_SHR);
  2405. expr := expr + '>';
  2406. end;
  2407. AS_SLASH:
  2408. Begin
  2409. Consume(AS_SLASH);
  2410. expr := expr + '/';
  2411. end;
  2412. AS_MOD:
  2413. Begin
  2414. Consume(AS_MOD);
  2415. expr := expr + '%';
  2416. end;
  2417. AS_STAR:
  2418. Begin
  2419. Consume(AS_STAR);
  2420. expr := expr + '*';
  2421. end;
  2422. AS_PLUS:
  2423. Begin
  2424. Consume(AS_PLUS);
  2425. expr := expr + '+';
  2426. end;
  2427. AS_MINUS:
  2428. Begin
  2429. Consume(AS_MINUS);
  2430. expr := expr + '-';
  2431. end;
  2432. AS_AND:
  2433. Begin
  2434. Consume(AS_AND);
  2435. expr := expr + '&';
  2436. end;
  2437. AS_NOT:
  2438. Begin
  2439. Consume(AS_NOT);
  2440. expr := expr + '~';
  2441. end;
  2442. AS_XOR:
  2443. Begin
  2444. Consume(AS_XOR);
  2445. expr := expr + '^';
  2446. end;
  2447. AS_OR:
  2448. Begin
  2449. Consume(AS_OR);
  2450. expr := expr + '|';
  2451. end;
  2452. AS_INTNUM:
  2453. Begin
  2454. expr := expr + actasmpattern;
  2455. Consume(AS_INTNUM);
  2456. end;
  2457. AS_BINNUM:
  2458. Begin
  2459. expr:=expr+BinaryToDec(actasmpattern);
  2460. Consume(AS_BINNUM);
  2461. end;
  2462. AS_HEXNUM:
  2463. Begin
  2464. expr:=expr+HexToDec(actasmpattern);
  2465. Consume(AS_HEXNUM);
  2466. end;
  2467. AS_OCTALNUM:
  2468. Begin
  2469. expr:=expr+OctalToDec(actasmpattern);
  2470. Consume(AS_OCTALNUM);
  2471. end;
  2472. AS_ID:
  2473. Begin
  2474. tempstr:=actasmpattern;
  2475. consume(AS_ID);
  2476. if actasmtoken=AS_DOT then
  2477. begin
  2478. GetRecordOffsetSize(tempstr,l,k);
  2479. str(l, tempstr);
  2480. expr := expr + tempstr;
  2481. end
  2482. else
  2483. begin
  2484. if SearchIConstant(tempstr,l) then
  2485. begin
  2486. str(l, tempstr);
  2487. expr := expr + tempstr;
  2488. end
  2489. else
  2490. Message1(assem_e_invalid_const_symbol,tempstr);
  2491. end;
  2492. end;
  2493. AS_SEPARATOR,
  2494. AS_COMMA:
  2495. Begin
  2496. break;
  2497. end;
  2498. else
  2499. Begin
  2500. { write error only once. }
  2501. if not errorflag then
  2502. Message(assem_e_invalid_constant_expression);
  2503. BuildConstExpression := 0;
  2504. if actasmtoken in [AS_COMMA,AS_SEPARATOR] then
  2505. exit;
  2506. { consume tokens until we find COMMA or SEPARATOR }
  2507. Consume(actasmtoken);
  2508. errorflag := TRUE;
  2509. end;
  2510. end;
  2511. Until false;
  2512. { calculate expression }
  2513. if not ErrorFlag then
  2514. BuildConstExpression := CalculateExpression(expr)
  2515. else
  2516. BuildConstExpression := 0;
  2517. { no longer in an expression }
  2518. inexpression := FALSE;
  2519. end;
  2520. Procedure BuildRealConstant(typ : tfloattype);
  2521. {*********************************************************************}
  2522. { PROCEDURE BuilRealConst }
  2523. { Description: This routine calculates a constant expression to }
  2524. { a given value. The return value is the value calculated from }
  2525. { the expression. }
  2526. { The following tokens (not strings) are recognized: }
  2527. { +/-,numbers and real numbers }
  2528. {*********************************************************************}
  2529. { ENTRY: On entry the token should be any valid expression token. }
  2530. { EXIT: On Exit the token points to either COMMA or SEPARATOR }
  2531. { ERROR RECOVERY: Tries to find COMMA or SEPARATOR token by consuming }
  2532. { invalid tokens. }
  2533. {*********************************************************************}
  2534. var expr: string;
  2535. tempstr: string;
  2536. r : bestreal;
  2537. code : word;
  2538. negativ : boolean;
  2539. errorflag: boolean;
  2540. Begin
  2541. errorflag := FALSE;
  2542. Repeat
  2543. negativ:=false;
  2544. expr := '';
  2545. tempstr := '';
  2546. if actasmtoken=AS_PLUS then Consume(AS_PLUS)
  2547. else if actasmtoken=AS_MINUS then
  2548. begin
  2549. negativ:=true;
  2550. consume(AS_MINUS);
  2551. end;
  2552. Case actasmtoken of
  2553. AS_INTNUM: Begin
  2554. expr := actasmpattern;
  2555. Consume(AS_INTNUM);
  2556. end;
  2557. AS_REALNUM: Begin
  2558. expr := actasmpattern;
  2559. { in ATT syntax you have 0d in front of the real }
  2560. { should this be forced ? yes i think so, as to }
  2561. { conform to gas as much as possible. }
  2562. if (expr[1]='0') and (upper(expr[2])='D') then
  2563. expr:=copy(expr,3,255);
  2564. Consume(AS_REALNUM);
  2565. end;
  2566. AS_BINNUM: Begin
  2567. { checking for real constants with this should use }
  2568. { real DECODING otherwise the compiler will crash! }
  2569. Message(assem_w_float_bin_ignored);
  2570. Consume(AS_BINNUM);
  2571. end;
  2572. AS_HEXNUM: Begin
  2573. { checking for real constants with this should use }
  2574. { real DECODING otherwise the compiler will crash! }
  2575. Message(assem_w_float_hex_ignored);
  2576. Consume(AS_HEXNUM);
  2577. end;
  2578. AS_OCTALNUM: Begin
  2579. { checking for real constants with this should use }
  2580. { real DECODING otherwise the compiler will crash! }
  2581. { xxxToDec using reals could be a solution, but the }
  2582. { problem is that these will crash the m68k compiler }
  2583. { when compiling -- because of lack of good fpu }
  2584. { support. }
  2585. Message(assem_w_float_octal_ignored);
  2586. Consume(AS_OCTALNUM);
  2587. end;
  2588. else
  2589. Begin
  2590. { only write error once. }
  2591. if not errorflag then
  2592. Message(assem_e_invalid_real_const);
  2593. { consume tokens until we find COMMA or SEPARATOR }
  2594. Consume(actasmtoken);
  2595. errorflag := TRUE;
  2596. End;
  2597. end;
  2598. { go to next term }
  2599. if (actasmtoken=AS_COMMA) or (actasmtoken=AS_SEPARATOR) then
  2600. Begin
  2601. if negativ then expr:='-'+expr;
  2602. val(expr,r,code);
  2603. if code<>0 then
  2604. Begin
  2605. r:=0;
  2606. Message(assem_e_invalid_real_const);
  2607. ConcatRealConstant(p,r,typ);
  2608. End
  2609. else
  2610. Begin
  2611. ConcatRealConstant(p,r,typ);
  2612. End;
  2613. end
  2614. else
  2615. Message(assem_e_invalid_real_const);
  2616. Until actasmtoken=AS_SEPARATOR;
  2617. end;
  2618. Procedure BuildReference(var Instr: TInstruction);
  2619. {*********************************************************************}
  2620. { PROCEDURE BuildReference }
  2621. { Description: This routine builds up an expression after a LPAREN }
  2622. { token is encountered. }
  2623. { On entry actasmtoken should be equal to AS_LPAREN }
  2624. {*********************************************************************}
  2625. { EXIT CONDITION: On exit the routine should point to either the }
  2626. { AS_COMMA or AS_SEPARATOR token. }
  2627. {*********************************************************************}
  2628. procedure Consume_RParen;
  2629. begin
  2630. if actasmtoken <> AS_RPAREN then
  2631. Begin
  2632. Message(assem_e_invalid_reference);
  2633. while actasmtoken <> AS_SEPARATOR do
  2634. Consume(actasmtoken);
  2635. end
  2636. else
  2637. begin
  2638. Consume(AS_RPAREN);
  2639. if not (actasmtoken in [AS_COMMA,AS_SEPARATOR]) then
  2640. Begin
  2641. Message(assem_e_invalid_reference);
  2642. { error recovery ... }
  2643. while actasmtoken <> AS_SEPARATOR do
  2644. Consume(actasmtoken);
  2645. end;
  2646. end;
  2647. end;
  2648. var
  2649. l:longint;
  2650. Begin
  2651. Consume(AS_LPAREN);
  2652. initAsmRef(instr);
  2653. Case actasmtoken of
  2654. AS_HEXNUM,
  2655. AS_INTNUM,
  2656. AS_BINNUM,
  2657. AS_OCTALNUM,
  2658. AS_MINUS,
  2659. AS_PLUS: { absolute offset, such as fs:(0x046c) }
  2660. Begin
  2661. { offset(offset) is invalid }
  2662. If Instr.Operands[OperandNum].Ref.Offset <> 0 Then
  2663. Begin
  2664. Message(assem_e_invalid_reference);
  2665. while actasmtoken <> AS_SEPARATOR do
  2666. Consume(actasmtoken);
  2667. End
  2668. Else
  2669. Begin
  2670. Instr.Operands[OperandNum].Ref.Offset := BuildConstExpression(false,true);
  2671. Consume_RParen;
  2672. end;
  2673. exit;
  2674. End;
  2675. AS_REGISTER: { (reg ... }
  2676. Begin
  2677. { Check if there is already a base (mostly ebp,esp) than this is
  2678. not allowed,becuase it will give crashing code }
  2679. if instr.operands[operandnum].ref.base<>R_NO then
  2680. Message(assem_e_cannot_index_relative_var);
  2681. instr.operands[operandnum].ref.base := findregister(actasmpattern);
  2682. Consume(AS_REGISTER);
  2683. { can either be a register or a right parenthesis }
  2684. { (reg) }
  2685. if actasmtoken=AS_RPAREN then
  2686. Begin
  2687. Consume_RParen;
  2688. exit;
  2689. end;
  2690. { (reg,reg .. }
  2691. Consume(AS_COMMA);
  2692. if actasmtoken=AS_REGISTER then
  2693. Begin
  2694. instr.operands[operandnum].ref.index := findregister(actasmpattern);
  2695. Consume(AS_REGISTER);
  2696. { check for scaling ... }
  2697. case actasmtoken of
  2698. AS_RPAREN:
  2699. Begin
  2700. Consume_RParen;
  2701. exit;
  2702. end;
  2703. AS_COMMA:
  2704. Begin
  2705. Consume(AS_COMMA);
  2706. { we have to process the scaling }
  2707. l:=BuildConstExpression(false,true);
  2708. if ((l = 2) or (l = 4) or (l = 8) or (l = 1)) then
  2709. instr.operands[operandnum].ref.scalefactor := l
  2710. else
  2711. Begin
  2712. Message(assem_e_invalid_scaling_value);
  2713. instr.operands[operandnum].ref.scalefactor := 0;
  2714. end;
  2715. Consume_RParen;
  2716. end;
  2717. else
  2718. Begin
  2719. Message(assem_e_invalid_reference_syntax);
  2720. while (actasmtoken <> AS_SEPARATOR) do
  2721. Consume(actasmtoken);
  2722. end;
  2723. end; { end case }
  2724. end
  2725. else
  2726. Begin
  2727. Message(assem_e_invalid_reference_syntax);
  2728. while (actasmtoken <> AS_SEPARATOR) do
  2729. Consume(actasmtoken);
  2730. end;
  2731. end; {end case }
  2732. AS_COMMA: { (, ... can either be scaling, or index }
  2733. Begin
  2734. Consume(AS_COMMA);
  2735. { Index }
  2736. if (actasmtoken=AS_REGISTER) then
  2737. Begin
  2738. instr.operands[operandnum].ref.index := findregister(actasmpattern);
  2739. Consume(AS_REGISTER);
  2740. { check for scaling ... }
  2741. case actasmtoken of
  2742. AS_RPAREN:
  2743. Begin
  2744. Consume_RParen;
  2745. exit;
  2746. end;
  2747. AS_COMMA:
  2748. Begin
  2749. Consume(AS_COMMA);
  2750. { we have to process the scaling }
  2751. l:=BuildConstExpression(false,true);
  2752. if ((l = 2) or (l = 4) or (l = 8) or (l = 1)) then
  2753. instr.operands[operandnum].ref.scalefactor := l
  2754. else
  2755. Begin
  2756. Message(assem_e_invalid_scaling_value);
  2757. instr.operands[operandnum].ref.scalefactor := 0;
  2758. end;
  2759. Consume_RParen;
  2760. end;
  2761. else
  2762. Begin
  2763. Message(assem_e_invalid_reference_syntax);
  2764. while (actasmtoken <> AS_SEPARATOR) do
  2765. Consume(actasmtoken);
  2766. end;
  2767. end; {end case }
  2768. end
  2769. { Scaling }
  2770. else
  2771. Begin
  2772. l:=BuildConstExpression(false,true);
  2773. if ((l = 2) or (l = 4) or (l = 8) or (l = 1)) then
  2774. instr.operands[operandnum].ref.scalefactor := l
  2775. else
  2776. Begin
  2777. Message(assem_e_invalid_scaling_value);
  2778. instr.operands[operandnum].ref.scalefactor := 0;
  2779. end;
  2780. Consume_RParen;
  2781. exit;
  2782. end;
  2783. end;
  2784. else
  2785. Begin
  2786. Message(assem_e_invalid_reference_syntax);
  2787. while (actasmtoken <> AS_SEPARATOR) do
  2788. Consume(actasmtoken);
  2789. end;
  2790. end; { end case }
  2791. end;
  2792. Procedure BuildOperand(var instr: TInstruction);
  2793. {*********************************************************************}
  2794. { EXIT CONDITION: On exit the routine should point to either the }
  2795. { AS_COMMA or AS_SEPARATOR token. }
  2796. {*********************************************************************}
  2797. var
  2798. tempstr: string;
  2799. expr: string;
  2800. lab: Pasmlabel;
  2801. hl: plabel;
  2802. tsize,l,
  2803. toffset : longint;
  2804. Begin
  2805. tempstr := '';
  2806. expr := '';
  2807. case actasmtoken of
  2808. AS_LPAREN: { Memory reference or constant expression }
  2809. Begin
  2810. initAsmRef(instr);
  2811. BuildReference(instr);
  2812. end;
  2813. AS_DOLLAR: { Constant expression }
  2814. Begin
  2815. Consume(AS_DOLLAR);
  2816. if not (instr.operands[operandnum].operandtype in [OPR_NONE,OPR_CONSTANT]) then
  2817. Message(assem_e_invalid_operand_type);
  2818. { identifiers are handled by BuildExpression }
  2819. instr.operands[operandnum].operandtype := OPR_CONSTANT;
  2820. instr.operands[operandnum].val :=BuildConstExpression(False,False);
  2821. end;
  2822. AS_HEXNUM,AS_INTNUM,AS_MINUS,
  2823. AS_BINNUM,AS_OCTALNUM,AS_PLUS:
  2824. Begin
  2825. { Constant memory offset }
  2826. { This must absolutely be followed by ( }
  2827. InitAsmRef(instr);
  2828. instr.operands[operandnum].ref.offset:=BuildConstExpression(True,False);
  2829. if actasmtoken<>AS_LPAREN then
  2830. Message(assem_e_invalid_reference_syntax)
  2831. else
  2832. BuildReference(instr);
  2833. end;
  2834. AS_STAR: { Call from memory address }
  2835. Begin
  2836. Consume(AS_STAR);
  2837. InitAsmRef(instr);
  2838. if not CreateVarInstr(instr,actasmpattern,operandnum) then
  2839. Message(assem_e_syn_opcode_operand);
  2840. end;
  2841. AS_ID: { A constant expression, or a Variable ref. }
  2842. Begin
  2843. { Local label ? }
  2844. if (actasmpattern[1] ='.') and (actasmpattern[2] = 'L') then
  2845. Begin
  2846. delete(actasmpattern,1,2);
  2847. if actasmpattern = '' then
  2848. Message(assem_e_null_label_ref_not_allowed);
  2849. lab := labellist.search(actasmpattern);
  2850. { check if the label is already defined }
  2851. { if so, we then check if the plabel is }
  2852. { non-nil, if so we add it to instruction }
  2853. if assigned(lab) then
  2854. Begin
  2855. if assigned(lab^.lab) then
  2856. Begin
  2857. instr.operands[operandnum].operandtype := OPR_LABINSTR;
  2858. instr.operands[operandnum].hl := lab^.lab;
  2859. instr.labeled := TRUE;
  2860. end;
  2861. end
  2862. else
  2863. Begin
  2864. { the label does not exist, create it }
  2865. { emit the opcode, but set that the }
  2866. { label has not been emitted }
  2867. getlabel(hl);
  2868. labellist.insert(actasmpattern,hl,FALSE);
  2869. instr.operands[operandnum].operandtype := OPR_LABINSTR;
  2870. instr.operands[operandnum].hl := hl;
  2871. instr.labeled := TRUE;
  2872. end;
  2873. Consume(AS_ID);
  2874. if not (actasmtoken in [AS_SEPARATOR,AS_COMMA]) then
  2875. Begin
  2876. Message(assem_e_syntax_error);
  2877. end;
  2878. end
  2879. else
  2880. { probably a variable or normal expression }
  2881. { or a procedure (such as in CALL ID) }
  2882. Begin
  2883. { check if this is a label, if so then }
  2884. { emit it as a label. }
  2885. if SearchLabel(actasmpattern,hl) then
  2886. Begin
  2887. instr.operands[operandnum].operandtype := OPR_LABINSTR;
  2888. instr.operands[operandnum].hl := hl;
  2889. instr.labeled := TRUE;
  2890. Consume(AS_ID);
  2891. if not (actasmtoken in [AS_SEPARATOR,AS_COMMA]) then
  2892. Message(assem_e_syntax_error);
  2893. end
  2894. else
  2895. { is it a normal variable ? }
  2896. Begin
  2897. { context for scanner }
  2898. initAsmRef(instr);
  2899. if not CreateVarInstr(instr,actasmpattern,operandnum) then
  2900. Begin
  2901. { look for special symbols ... }
  2902. if actasmpattern = '__RESULT' then
  2903. SetUpResult(instr,operandnum)
  2904. else
  2905. if actasmpattern = '__SELF' then
  2906. Begin
  2907. if assigned(procinfo._class) then
  2908. Begin
  2909. instr.operands[operandnum].operandtype := OPR_REFERENCE;
  2910. instr.operands[operandnum].ref.offset := procinfo.ESI_offset;
  2911. instr.operands[operandnum].ref.base := procinfo.framepointer;
  2912. end
  2913. else
  2914. Message(assem_e_cannot_use___SELF_outside_methode);
  2915. end
  2916. else
  2917. if actasmpattern = '__OLDEBP' then
  2918. Begin
  2919. if lexlevel>normal_function_level then
  2920. Begin
  2921. instr.operands[operandnum].operandtype := OPR_REFERENCE;
  2922. instr.operands[operandnum].ref.offset := procinfo.framepointer_offset;
  2923. instr.operands[operandnum].ref.base := procinfo.framepointer;
  2924. end
  2925. else
  2926. Message(assem_e_cannot_use___OLDEBP_outside_nested_procedure);
  2927. end
  2928. else
  2929. { check for direct symbolic names }
  2930. { only if compiling the system unit }
  2931. if (cs_compilesystem in aktmoduleswitches) then
  2932. begin
  2933. if not SearchDirectVar(instr,actasmpattern,operandnum) then
  2934. Begin
  2935. { not found, finally ... add it anyways ... }
  2936. Message1(assem_w_id_supposed_external,actasmpattern);
  2937. instr.operands[operandnum].ref.symbol := newpasstr(actasmpattern);
  2938. end;
  2939. end
  2940. else
  2941. Message1(assem_e_unknown_id,actasmpattern);
  2942. end;
  2943. { constant expression? }
  2944. if (instr.operands[operandnum].operandtype=OPR_CONSTANT) then
  2945. begin
  2946. l:=BuildConstExpression(true,false);
  2947. { indexing? }
  2948. if actasmtoken=AS_LPAREN then
  2949. begin
  2950. instr.operands[operandnum].operandtype:=OPR_REFERENCE;
  2951. reset_reference(Instr.Operands[OperandNum].Ref);
  2952. Instr.Operands[OperandNum].Ref.Offset:=l;
  2953. BuildReference(instr);
  2954. end
  2955. else
  2956. Instr.Operands[OperandNum].Val:=l;
  2957. end
  2958. else
  2959. begin
  2960. expr := actasmpattern;
  2961. Consume(AS_ID);
  2962. if actasmtoken=AS_DOT then
  2963. begin
  2964. GetRecordOffsetSize(expr,toffset,tsize);
  2965. inc(instr.operands[operandnum].ref.offset,toffset);
  2966. SetOperandSize(instr,operandnum,tsize);
  2967. end;
  2968. if actasmtoken=AS_LPAREN then
  2969. BuildReference(instr);
  2970. end;
  2971. end; { end if }
  2972. end; { end if }
  2973. end;
  2974. AS_REGISTER: { Register, a variable reference or a constant reference }
  2975. Begin
  2976. { save the type of register used. }
  2977. tempstr := actasmpattern;
  2978. Consume(AS_REGISTER);
  2979. if actasmtoken = AS_COLON then
  2980. Begin
  2981. Consume(AS_COLON);
  2982. initAsmRef(instr);
  2983. instr.operands[operandnum].ref.segment := findsegment(tempstr);
  2984. { here we can have either an identifier }
  2985. { or a constant, where either can be }
  2986. { followed by a parenthesis... }
  2987. { Constant memory offset . }
  2988. { This must absolutely be followed by ( }
  2989. case actasmtoken of
  2990. AS_HEXNUM,AS_INTNUM,AS_MINUS,
  2991. AS_BINNUM,AS_OCTALNUM,AS_PLUS:
  2992. Begin
  2993. instr.operands[operandnum].ref.offset:=BuildConstExpression(True,False);
  2994. if actasmtoken<>AS_LPAREN then
  2995. Message(assem_e_invalid_reference_syntax)
  2996. else
  2997. BuildReference(instr);
  2998. end;
  2999. AS_LPAREN:
  3000. BuildReference(instr);
  3001. AS_ID: { only a variable is allowed ... }
  3002. Begin
  3003. { is it a normal variable ? }
  3004. if not CreateVarInstr(instr,actasmpattern,operandnum) then
  3005. begin
  3006. { check for direct symbolic names }
  3007. { only if compiling the system unit }
  3008. if (cs_compilesystem in aktmoduleswitches) then
  3009. begin
  3010. if not SearchDirectVar(instr,actasmpattern,operandnum) then
  3011. Message(assem_e_invalid_seg_override);
  3012. end
  3013. else
  3014. Message(assem_e_invalid_seg_override);
  3015. end;
  3016. Consume(actasmtoken);
  3017. case actasmtoken of
  3018. AS_SEPARATOR,
  3019. AS_COMMA: ;
  3020. AS_LPAREN: BuildReference(instr);
  3021. else
  3022. Begin
  3023. Message(assem_e_invalid_seg_override);
  3024. Consume(actasmtoken);
  3025. end;
  3026. end; {end case }
  3027. end;
  3028. else
  3029. Begin
  3030. Message(assem_e_invalid_seg_override);
  3031. Consume(actasmtoken);
  3032. end;
  3033. end; { end case }
  3034. end
  3035. { Simple register }
  3036. else if (actasmtoken in [AS_SEPARATOR,AS_COMMA]) then
  3037. Begin
  3038. if not (instr.operands[operandnum].operandtype in [OPR_NONE,OPR_REGISTER]) then
  3039. Message(assem_e_invalid_operand_type);
  3040. instr.operands[operandnum].operandtype := OPR_REGISTER;
  3041. instr.operands[operandnum].reg := findregister(tempstr);
  3042. end
  3043. else
  3044. Message1(assem_e_syn_register,tempstr);
  3045. end;
  3046. AS_SEPARATOR,
  3047. AS_COMMA: ;
  3048. else
  3049. Begin
  3050. Message(assem_e_syn_opcode_operand);
  3051. Consume(actasmtoken);
  3052. end;
  3053. end; { end case }
  3054. end;
  3055. Procedure BuildConstant(maxvalue: longint);
  3056. {*********************************************************************}
  3057. { PROCEDURE BuildConstant }
  3058. { Description: This routine takes care of parsing a DB,DD,or DW }
  3059. { line and adding those to the assembler node. Expressions, range- }
  3060. { checking are fullly taken care of. }
  3061. { maxvalue: $ff -> indicates that this is a DB node. }
  3062. { $ffff -> indicates that this is a DW node. }
  3063. { $ffffffff -> indicates that this is a DD node. }
  3064. {*********************************************************************}
  3065. { EXIT CONDITION: On exit the routine should point to AS_SEPARATOR. }
  3066. {*********************************************************************}
  3067. var
  3068. strlength: byte;
  3069. expr: string;
  3070. value : longint;
  3071. Begin
  3072. Repeat
  3073. Case actasmtoken of
  3074. AS_STRING:
  3075. Begin
  3076. if maxvalue = $ff then
  3077. strlength := 1
  3078. else
  3079. Message(assem_e_string_not_allowed_as_const);
  3080. expr := actasmpattern;
  3081. if length(expr) > 1 then
  3082. Message(assem_e_string_not_allowed_as_const);
  3083. Consume(AS_STRING);
  3084. Case actasmtoken of
  3085. AS_COMMA: Consume(AS_COMMA);
  3086. AS_SEPARATOR: ;
  3087. else
  3088. Message(assem_e_invalid_string_expression);
  3089. end; { end case }
  3090. ConcatString(p,expr);
  3091. end;
  3092. AS_INTNUM,
  3093. AS_BINNUM,
  3094. AS_OCTALNUM,
  3095. AS_HEXNUM,
  3096. AS_PLUS,
  3097. AS_MINUS,
  3098. AS_LPAREN,
  3099. AS_NOT:
  3100. Begin
  3101. value:=BuildConstExpression(false,false);
  3102. ConcatConstant(p,value,maxvalue);
  3103. end;
  3104. AS_COMMA:
  3105. Begin
  3106. Consume(AS_COMMA);
  3107. end;
  3108. AS_SEPARATOR:
  3109. begin
  3110. break;
  3111. end;
  3112. else
  3113. Begin
  3114. Message(assem_f_internal_error_in_buildconstant);
  3115. end;
  3116. end; { end case }
  3117. Until false;
  3118. end;
  3119. Procedure BuildStringConstant(asciiz: boolean);
  3120. {*********************************************************************}
  3121. { PROCEDURE BuildStringConstant }
  3122. { Description: Takes care of a ASCII, or ASCIIZ directive. }
  3123. { asciiz: boolean -> if true then string will be null terminated. }
  3124. {*********************************************************************}
  3125. { EXIT CONDITION: On exit the routine should point to AS_SEPARATOR. }
  3126. { On ENTRY: Token should point to AS_STRING }
  3127. {*********************************************************************}
  3128. var
  3129. expr: string;
  3130. errorflag : boolean;
  3131. Begin
  3132. errorflag := FALSE;
  3133. Repeat
  3134. Case actasmtoken of
  3135. AS_STRING:
  3136. Begin
  3137. expr:=actasmpattern;
  3138. if asciiz then
  3139. expr:=expr+#0;
  3140. ConcatPasString(p,expr);
  3141. Consume(AS_STRING);
  3142. end;
  3143. AS_COMMA:
  3144. begin
  3145. Consume(AS_COMMA);
  3146. end;
  3147. AS_SEPARATOR:
  3148. begin
  3149. break;
  3150. end;
  3151. else
  3152. Begin
  3153. Consume(actasmtoken);
  3154. if not errorflag then
  3155. Message(assem_e_invalid_string_expression);
  3156. errorflag := TRUE;
  3157. end;
  3158. end;
  3159. Until false;
  3160. end;
  3161. Procedure BuildOpCode;
  3162. {*********************************************************************}
  3163. { PROCEDURE BuildOpcode; }
  3164. { Description: Parses the intel opcode and operands, and writes it }
  3165. { in the TInstruction object. }
  3166. {*********************************************************************}
  3167. { EXIT CONDITION: On exit the routine should point to AS_SEPARATOR. }
  3168. { On ENTRY: Token should point to AS_OPCODE }
  3169. {*********************************************************************}
  3170. var
  3171. asmtok: tasmop;
  3172. op: tasmop;
  3173. expr: string;
  3174. segreg: tregister;
  3175. Begin
  3176. expr := '';
  3177. asmtok := A_NONE; { assmume no prefix }
  3178. segreg := R_NO; { assume no segment override }
  3179. { prefix seg opcode }
  3180. { prefix opcode }
  3181. if findprefix(actasmpattern,asmtok) then
  3182. Begin
  3183. { standard opcode prefix }
  3184. if asmtok <> A_NONE then
  3185. instr.addprefix(asmtok);
  3186. Consume(AS_OPCODE);
  3187. end;
  3188. { allow for newline as in gas styled syntax }
  3189. { under DOS you get two AS_SEPARATOR !! }
  3190. while actasmtoken=AS_SEPARATOR do
  3191. Consume(AS_SEPARATOR);
  3192. if (actasmtoken <> AS_OPCODE) then
  3193. Begin
  3194. Message(assem_e_invalid_or_missing_opcode);
  3195. { error recovery }
  3196. While not (actasmtoken in [AS_SEPARATOR,AS_COMMA,AS_END]) do
  3197. Consume(actasmtoken);
  3198. exit;
  3199. end
  3200. else
  3201. Begin
  3202. op := findopcode(actasmpattern);
  3203. instr.addinstr(op);
  3204. { Valid combination of prefix and instruction ? }
  3205. if (asmtok <> A_NONE) and (NOT CheckPrefix(asmtok,op)) then
  3206. Message1(assem_e_invalid_prefix_and_opcode,actasmpattern);
  3207. Consume(AS_OPCODE);
  3208. { Zero operand opcode ? }
  3209. if actasmtoken in [AS_SEPARATOR,AS_END] then
  3210. exit
  3211. else
  3212. operandnum := 1;
  3213. end;
  3214. repeat
  3215. case actasmtoken of
  3216. AS_COMMA: { Operand delimiter }
  3217. Begin
  3218. if operandnum > MaxOperands then
  3219. Message(assem_e_too_many_operands)
  3220. else
  3221. Inc(operandnum);
  3222. Consume(AS_COMMA);
  3223. end;
  3224. AS_SEPARATOR,
  3225. AS_END : { End of asm operands for this opcode }
  3226. begin
  3227. break;
  3228. end;
  3229. else
  3230. BuildOperand(instr);
  3231. end; { end case }
  3232. until false;
  3233. end;
  3234. Function Assemble: Ptree;
  3235. {*********************************************************************}
  3236. { PROCEDURE Assemble; }
  3237. { Description: Parses the att assembler syntax, parsing is done }
  3238. { according to GAs rules. }
  3239. {*********************************************************************}
  3240. Var
  3241. hl: plabel;
  3242. labelptr,nextlabel : pasmlabel;
  3243. commname : string;
  3244. store_p : paasmoutput;
  3245. Begin
  3246. Message(assem_d_start_att);
  3247. firsttoken := TRUE;
  3248. operandnum := 0;
  3249. previous_was_id := FALSE;
  3250. if assigned(procinfo.retdef) and
  3251. (is_fpu(procinfo.retdef) or
  3252. ret_in_acc(procinfo.retdef)) then
  3253. procinfo.funcret_is_valid:=true;
  3254. { sets up all opcode and register tables in uppercase }
  3255. if not _asmsorted then
  3256. Begin
  3257. SetupTables;
  3258. _asmsorted := TRUE;
  3259. end;
  3260. p:=new(paasmoutput,init);
  3261. { save pointer code section }
  3262. store_p:=p;
  3263. { setup label linked list }
  3264. labellist.init;
  3265. c:=current_scanner^.asmgetchar;
  3266. actasmtoken:=gettoken;
  3267. repeat
  3268. case actasmtoken of
  3269. AS_LLABEL:
  3270. Begin
  3271. labelptr := labellist.search(actasmpattern);
  3272. if not assigned(labelptr) then
  3273. Begin
  3274. getlabel(hl);
  3275. labellist.insert(actasmpattern,hl,TRUE);
  3276. ConcatLabel(p,hl);
  3277. end
  3278. else
  3279. Begin
  3280. { the label has already been inserted into the }
  3281. { label list, either as an instruction label (in}
  3282. { this case it has not been emitted), or as a }
  3283. { duplicate local symbol (in this case it has }
  3284. { already been emitted). }
  3285. if labelptr^.emitted then
  3286. Message1(assem_e_dup_local_sym,'.L'+labelptr^.name^)
  3287. else
  3288. Begin
  3289. if assigned(labelptr^.lab) then
  3290. ConcatLabel(p,labelptr^.lab);
  3291. labelptr^.emitted := TRUE;
  3292. end;
  3293. end;
  3294. Consume(AS_LLABEL);
  3295. end;
  3296. AS_LABEL:
  3297. Begin
  3298. { when looking for Pascal labels, these must }
  3299. { be in uppercase. }
  3300. if SearchLabel(upper(actasmpattern),hl) then
  3301. ConcatLabel(p,hl)
  3302. else
  3303. Begin
  3304. if (cs_compilesystem in aktmoduleswitches) then
  3305. begin
  3306. Message1(assem_e_unknown_label_identifer,actasmpattern);
  3307. { once again we don't know what it represents }
  3308. { so we simply concatenate it }
  3309. ConcatLocal(p,actasmpattern);
  3310. end
  3311. else
  3312. Message1(assem_e_unknown_label_identifer,actasmpattern);
  3313. end;
  3314. Consume(AS_LABEL);
  3315. end;
  3316. AS_DW:
  3317. Begin
  3318. Consume(AS_DW);
  3319. BuildConstant($ffff);
  3320. end;
  3321. AS_DATA:
  3322. Begin
  3323. { -- this should only be allowed for system development -- }
  3324. { i think this should be fixed in the dos unit, and }
  3325. { not here. }
  3326. if (cs_compilesystem in aktmoduleswitches) then
  3327. p:=datasegment
  3328. else
  3329. Message(assem_e_switching_sections_not_allowed);
  3330. Consume(AS_DATA);
  3331. end;
  3332. AS_TEXT:
  3333. Begin
  3334. { -- this should only be allowed for system development -- }
  3335. { i think this should be fixed in the dos unit, and }
  3336. { not here. }
  3337. if (cs_compilesystem in aktmoduleswitches) then
  3338. p:=store_p
  3339. else
  3340. Message(assem_e_switching_sections_not_allowed);
  3341. Consume(AS_TEXT);
  3342. end;
  3343. AS_DB:
  3344. Begin
  3345. Consume(AS_DB);
  3346. BuildConstant($ff);
  3347. end;
  3348. AS_DD:
  3349. Begin
  3350. Consume(AS_DD);
  3351. BuildConstant($ffffffff);
  3352. end;
  3353. AS_DQ:
  3354. Begin
  3355. Consume(AS_DQ);
  3356. BuildRealConstant(s64bit);
  3357. end;
  3358. AS_SINGLE:
  3359. Begin
  3360. Consume(AS_SINGLE);
  3361. BuildRealConstant(s32real);
  3362. end;
  3363. AS_DOUBLE:
  3364. Begin
  3365. Consume(AS_DOUBLE);
  3366. BuildRealConstant(s64real);
  3367. end;
  3368. AS_EXTENDED:
  3369. Begin
  3370. Consume(AS_EXTENDED);
  3371. BuildRealConstant(s80real);
  3372. end;
  3373. AS_GLOBAL:
  3374. Begin
  3375. { normal units should not be able to declare }
  3376. { direct label names like this... anyhow }
  3377. { procedural calls in asm blocks are }
  3378. { supposedely replaced automatically }
  3379. if (cs_compilesystem in aktmoduleswitches) then
  3380. begin
  3381. Consume(AS_GLOBAL);
  3382. if actasmtoken <> AS_ID then
  3383. Message(assem_e_invalid_global_def)
  3384. else
  3385. ConcatPublic(p,actasmpattern);
  3386. Consume(actasmtoken);
  3387. if actasmtoken <> AS_SEPARATOR then
  3388. Begin
  3389. Message(assem_e_line_separator_expected);
  3390. while actasmtoken <> AS_SEPARATOR do
  3391. Consume(actasmtoken);
  3392. end;
  3393. end
  3394. else
  3395. begin
  3396. Message(assem_w_globl_not_supported);
  3397. while actasmtoken <> AS_SEPARATOR do
  3398. Consume(actasmtoken);
  3399. end;
  3400. end;
  3401. AS_ALIGN:
  3402. Begin
  3403. Message(assem_w_align_not_supported);
  3404. while actasmtoken <> AS_SEPARATOR do
  3405. Consume(actasmtoken);
  3406. end;
  3407. AS_ASCIIZ:
  3408. Begin
  3409. Consume(AS_ASCIIZ);
  3410. BuildStringConstant(TRUE);
  3411. end;
  3412. AS_ASCII:
  3413. Begin
  3414. Consume(AS_ASCII);
  3415. BuildStringConstant(FALSE);
  3416. end;
  3417. AS_LCOMM:
  3418. Begin
  3419. { -- this should only be allowed for system development -- }
  3420. { -- otherwise may mess up future enhancements we might -- }
  3421. { -- add. -- }
  3422. if (cs_compilesystem in aktmoduleswitches) then
  3423. begin
  3424. Consume(AS_LCOMM);
  3425. if actasmtoken <> AS_ID then
  3426. begin
  3427. Message(assem_e_invalid_lcomm_def);
  3428. { error recovery }
  3429. while actasmtoken <> AS_SEPARATOR do
  3430. Consume(actasmtoken);
  3431. end
  3432. else
  3433. begin
  3434. commname:=actasmpattern;
  3435. Consume(AS_COMMA);
  3436. ConcatLocalBss(actasmpattern,BuildConstExpression(false,false));
  3437. if actasmtoken <> AS_SEPARATOR then
  3438. Begin
  3439. Message(assem_e_line_separator_expected);
  3440. while actasmtoken <> AS_SEPARATOR do
  3441. Consume(actasmtoken);
  3442. end;
  3443. end;
  3444. end
  3445. else
  3446. begin
  3447. Message(assem_w_lcomm_not_supported);
  3448. while actasmtoken <> AS_SEPARATOR do
  3449. Consume(actasmtoken);
  3450. end;
  3451. end;
  3452. AS_COMM:
  3453. Begin
  3454. { -- this should only be allowed for system development -- }
  3455. { -- otherwise may mess up future enhancements we might -- }
  3456. { -- add. -- }
  3457. if (cs_compilesystem in aktmoduleswitches) then
  3458. begin
  3459. Consume(AS_COMM);
  3460. if actasmtoken <> AS_ID then
  3461. begin
  3462. Message(assem_e_invalid_comm_def);
  3463. { error recovery }
  3464. while actasmtoken <> AS_SEPARATOR do
  3465. Consume(actasmtoken);
  3466. end
  3467. else
  3468. begin
  3469. commname:=actasmpattern;
  3470. Consume(AS_COMMA);
  3471. ConcatGlobalBss(actasmpattern,BuildConstExpression(false,false));
  3472. if actasmtoken <> AS_SEPARATOR then
  3473. Begin
  3474. Message(assem_e_line_separator_expected);
  3475. while actasmtoken <> AS_SEPARATOR do
  3476. Consume(actasmtoken);
  3477. end;
  3478. end;
  3479. end
  3480. else
  3481. begin
  3482. Message(assem_w_comm_not_supported);
  3483. while actasmtoken <> AS_SEPARATOR do
  3484. Consume(actasmtoken);
  3485. end;
  3486. end;
  3487. AS_OPCODE:
  3488. Begin
  3489. instr.init;
  3490. BuildOpcode;
  3491. instr.numops := operandnum;
  3492. if instr.labeled then
  3493. ConcatLabeledInstr(instr)
  3494. else
  3495. ConcatOpCode(instr);
  3496. instr.done;
  3497. end;
  3498. AS_SEPARATOR:
  3499. Begin
  3500. Consume(AS_SEPARATOR);
  3501. { let us go back to the first operand }
  3502. operandnum := 0;
  3503. end;
  3504. AS_END:
  3505. begin
  3506. break; { end assembly block }
  3507. end;
  3508. else
  3509. Begin
  3510. Message(assem_e_assemble_node_syntax_error);
  3511. { error recovery }
  3512. Consume(actasmtoken);
  3513. end;
  3514. end; { end case }
  3515. until false;
  3516. { check if there were undefined symbols. }
  3517. { if so, then list each of those undefined }
  3518. { labels. }
  3519. if assigned(labellist.First) then
  3520. Begin
  3521. labelptr := labellist.First;
  3522. While labelptr <> nil do
  3523. Begin
  3524. nextlabel:=labelptr^.next;
  3525. if not labelptr^.emitted then
  3526. Message1(assem_e_local_sym_not_found_in_asm_statement,'.L'+labelptr^.name^);
  3527. labelptr:=nextlabel;
  3528. end;
  3529. end;
  3530. if p<>store_p then
  3531. begin
  3532. Message(assem_e_assembler_code_not_returned_to_text);
  3533. p:=store_p;
  3534. end;
  3535. assemble := genasmnode(p);
  3536. labellist.done;
  3537. Message(assem_d_finish_att);
  3538. end;
  3539. var
  3540. old_exit: pointer;
  3541. procedure ra386att_exit;{$ifndef FPC}far;{$endif}
  3542. begin
  3543. if assigned(iasmops) then
  3544. dispose(iasmops);
  3545. exitproc:=old_exit;
  3546. end;
  3547. Begin
  3548. old_exit := exitproc;
  3549. exitproc := @ra386att_exit;
  3550. end.
  3551. {
  3552. $Log$
  3553. Revision 1.33 1999-02-25 21:02:47 peter
  3554. * ag386bin updates
  3555. + coff writer
  3556. Revision 1.32 1999/02/22 02:15:34 peter
  3557. * updates for ag386bin
  3558. Revision 1.31 1999/01/29 11:24:02 pierre
  3559. * incompatible size warning or error suppressed for sizes > 4
  3560. Revision 1.30 1999/01/28 14:12:59 pierre
  3561. * bug0175 solved give error on $R+ and warning otherwise
  3562. Revision 1.29 1999/01/10 15:37:54 peter
  3563. * moved some tables from ra386*.pas -> i386.pas
  3564. + start of coff writer
  3565. * renamed asmutils unit to rautils
  3566. Revision 1.28 1998/12/28 15:47:09 peter
  3567. * general constant solution. Constant expressions are now almost
  3568. everywhere allowed and correctly parsed
  3569. Revision 1.27 1998/12/23 22:55:56 peter
  3570. + rec.field(%esi) support
  3571. + [esi+rec.field] support
  3572. Revision 1.26 1998/12/11 00:03:42 peter
  3573. + globtype,tokens,version unit splitted from globals
  3574. Revision 1.25 1998/12/09 13:23:40 jonas
  3575. * replaced two "in [A_...]" constructs I had missed before
  3576. * for shrd/shld: "if operands[1].operandtype = OPR_CONSTANT" instead of
  3577. "if operands[3].operandtype ..."
  3578. Revision 1.24 1998/12/08 23:03:48 jonas
  3579. * allow constant offsets for go32v2 in assembler blocks
  3580. Revision 1.23 1998/12/02 16:23:33 jonas
  3581. * changed "if longintvar in set" to case or "if () or () .." statements
  3582. * tree.pas: changed inlinenumber (and associated constructor/vars) to a byte
  3583. Revision 1.22 1998/11/29 12:47:21 peter
  3584. * fixes for 'asm sti end;'
  3585. Revision 1.21 1998/11/16 15:38:54 peter
  3586. * fixed instruct not in table msg
  3587. Revision 1.20 1998/11/13 15:40:27 pierre
  3588. + added -Se in Makefile cvstest target
  3589. + lexlevel cleanup
  3590. normal_function_level main_program_level and unit_init_level defined
  3591. * tins_cache grown to A_EMMS (gave range check error in asm readers)
  3592. (test added in code !)
  3593. * -Un option was wrong
  3594. * _FAIL and _SELF only keyword inside
  3595. constructors and methods respectively
  3596. Revision 1.19 1998/11/13 10:12:16 peter
  3597. * constant fixes
  3598. Revision 1.18 1998/11/05 23:48:26 peter
  3599. * recordtype.field support in constant expressions
  3600. * fixed imul for oa_imm8 which was not allowed
  3601. * fixed reading of local typed constants
  3602. * fixed comment reading which is not any longer a separator
  3603. Revision 1.17 1998/10/28 21:34:39 peter
  3604. * fixed some opsize
  3605. Revision 1.16 1998/10/28 00:08:48 peter
  3606. + leal procsym,eax is now allowed
  3607. + constants are now handled also when starting an expression
  3608. + call *pointer is now allowed
  3609. Revision 1.15 1998/10/13 16:50:16 pierre
  3610. * undid some changes of Peter that made the compiler wrong
  3611. for m68k (I had to reinsert some ifdefs)
  3612. * removed several memory leaks under m68k
  3613. * removed the meory leaks for assembler readers
  3614. * cross compiling shoud work again better
  3615. ( crosscompiling sysamiga works
  3616. but as68k still complain about some code !)
  3617. Revision 1.14 1998/10/07 04:28:52 carl
  3618. * bugfix of in/out with gas (ins/outs still left though)
  3619. * bugfix of wrong error output with concatlabel
  3620. * gettoken always returns something valid now
  3621. Revision 1.13 1998/09/24 17:52:31 carl
  3622. * bugfix from fix branch
  3623. Revision 1.12.2.1 1998/09/24 17:47:16 carl
  3624. * bugfix with objects/records access
  3625. Revision 1.12 1998/09/03 17:08:46 pierre
  3626. * better lines for stabs
  3627. (no scroll back to if before else part
  3628. no return to case line at jump outside case)
  3629. + source lines also if not in order
  3630. Revision 1.11 1998/09/02 15:16:44 carl
  3631. * indirect register refs with movsx/movzx fixed
  3632. Revision 1.10 1998/09/02 01:24:09 carl
  3633. * bugfix of PUSH opcode with constants
  3634. Revision 1.9 1998/08/21 08:45:49 pierre
  3635. * better line info for asm statements
  3636. Revision 1.8 1998/08/19 16:07:54 jonas
  3637. * changed optimizer switches + cleanup of DestroyRefs in daopt386.pas
  3638. Revision 1.7 1998/08/10 23:57:23 peter
  3639. * use bestreal instead of extended
  3640. Revision 1.6 1998/08/10 14:50:21 peter
  3641. + localswitches, moduleswitches, globalswitches splitting
  3642. Revision 1.5 1998/07/14 14:46:58 peter
  3643. * released NEWINPUT
  3644. Revision 1.4 1998/07/08 15:06:41 daniel
  3645. + $N+,E+ added for TP.
  3646. Revision 1.3 1998/07/07 11:20:07 peter
  3647. + NEWINPUT for a better inputfile and scanner object
  3648. Revision 1.2 1998/06/24 14:06:36 peter
  3649. * fixed the name changes
  3650. Revision 1.1 1998/06/23 14:00:17 peter
  3651. * renamed RA* units
  3652. Revision 1.13 1998/06/16 08:56:29 peter
  3653. + targetcpu
  3654. * cleaner pmodules for newppu
  3655. Revision 1.12 1998/06/12 10:32:35 pierre
  3656. * column problem hopefully solved
  3657. + C vars declaration changed
  3658. Revision 1.11 1998/05/31 14:13:35 peter
  3659. * fixed call bugs with assembler readers
  3660. + OPR_SYMBOL to hold a symbol in the asm parser
  3661. * fixed staticsymtable vars which were acessed through %ebp instead of
  3662. name
  3663. Revision 1.10 1998/05/30 14:31:08 peter
  3664. + $ASMMODE
  3665. Revision 1.9 1998/05/29 09:58:16 pierre
  3666. * OPR_REGISTER for 1 arg was missing in ratti386.pas
  3667. (probably a merging problem)
  3668. * errors at start of line were lost
  3669. Revision 1.8 1998/05/28 16:34:36 carl
  3670. * call bugfix
  3671. * operand with regs bugfix (manual patch in both cases)
  3672. Revision 1.7 1998/05/23 01:21:27 peter
  3673. + aktasmmode, aktoptprocessor, aktoutputformat
  3674. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  3675. + $LIBNAME to set the library name where the unit will be put in
  3676. * splitted cgi386 a bit (codeseg to large for bp7)
  3677. * nasm, tasm works again. nasm moved to ag386nsm.pas
  3678. Revision 1.6 1998/05/20 09:42:37 pierre
  3679. + UseTokenInfo now default
  3680. * unit in interface uses and implementation uses gives error now
  3681. * only one error for unknown symbol (uses lastsymknown boolean)
  3682. the problem came from the label code !
  3683. + first inlined procedures and function work
  3684. (warning there might be allowed cases were the result is still wrong !!)
  3685. * UseBrower updated gives a global list of all position of all used symbols
  3686. with switch -gb
  3687. Revision 1.5 1998/04/29 13:52:23 peter
  3688. * small optimize fix
  3689. Revision 1.4 1998/04/29 10:34:04 pierre
  3690. + added some code for ansistring (not complete nor working yet)
  3691. * corrected operator overloading
  3692. * corrected nasm output
  3693. + started inline procedures
  3694. + added starstarn : use ** for exponentiation (^ gave problems)
  3695. + started UseTokenInfo cond to get accurate positions
  3696. Revision 1.3 1998/04/08 16:58:07 pierre
  3697. * several bugfixes
  3698. ADD ADC and AND are also sign extended
  3699. nasm output OK (program still crashes at end
  3700. and creates wrong assembler files !!)
  3701. procsym types sym in tdef removed !!
  3702. }