aasmcpu.pas 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl and Peter Vreman
  4. Contains the abstract assembler implementation for the i386
  5. * Portions of this code was inspired by the NASM sources
  6. The Netwide Assembler is Copyright (c) 1996 Simon Tatham and
  7. Julian Hall. All rights reserved.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. ****************************************************************************
  20. }
  21. unit aasmcpu;
  22. {$i fpcdefs.inc}
  23. interface
  24. uses
  25. cclasses,globals,verbose,
  26. cginfo,cpuinfo,cpubase,
  27. symppu,symtype,symsym,
  28. aasmbase,aasmtai;
  29. const
  30. { "mov reg,reg" source operand number }
  31. O_MOV_SOURCE = 0;
  32. { "mov reg,reg" destination operand number }
  33. O_MOV_DEST = 1;
  34. { Operand types }
  35. OT_NONE = $00000000;
  36. OT_BITS8 = $00000001; { size, and other attributes, of the operand }
  37. OT_BITS16 = $00000002;
  38. OT_BITS32 = $00000004;
  39. OT_BITS64 = $00000008; { FPU only }
  40. OT_BITS80 = $00000010;
  41. OT_FAR = $00000020; { this means 16:16 or 16:32, like in CALL/JMP }
  42. OT_NEAR = $00000040;
  43. OT_SHORT = $00000080;
  44. OT_SIZE_MASK = $000000FF; { all the size attributes }
  45. OT_NON_SIZE = longint(not OT_SIZE_MASK);
  46. OT_SIGNED = $00000100; { the operand need to be signed -128-127 }
  47. OT_TO = $00000200; { operand is followed by a colon }
  48. { reverse effect in FADD, FSUB &c }
  49. OT_COLON = $00000400;
  50. OT_REGISTER = $00001000;
  51. OT_IMMEDIATE = $00002000;
  52. OT_IMM8 = $00002001;
  53. OT_IMM16 = $00002002;
  54. OT_IMM32 = $00002004;
  55. OT_IMM64 = $00002008;
  56. OT_IMM80 = $00002010;
  57. OT_REGMEM = $00200000; { for r/m, ie EA, operands }
  58. OT_REGNORM = $00201000; { 'normal' reg, qualifies as EA }
  59. OT_REG8 = $00201001;
  60. OT_REG16 = $00201002;
  61. OT_REG32 = $00201004;
  62. OT_REG64 = $00201008;
  63. OT_MMXREG = $00201008; { MMX registers }
  64. OT_XMMREG = $00201010; { Katmai registers }
  65. OT_MEMORY = $00204000; { register number in 'basereg' }
  66. OT_MEM8 = $00204001;
  67. OT_MEM16 = $00204002;
  68. OT_MEM32 = $00204004;
  69. OT_MEM64 = $00204008;
  70. OT_MEM80 = $00204010;
  71. OT_FPUREG = $01000000; { floating point stack registers }
  72. OT_FPU0 = $01000800; { FPU stack register zero }
  73. OT_REG_SMASK = $00070000; { special register operands: these may be treated differently }
  74. { a mask for the following }
  75. OT_REG_ACCUM = $00211000; { FUNCTION_RETURN_REG: AL, AX or EAX }
  76. OT_REG_AL = $00211001; { REG_ACCUM | BITSxx }
  77. OT_REG_AX = $00211002; { ditto }
  78. OT_REG_EAX = $00211004; { and again }
  79. {$ifdef x86_64}
  80. OT_REG_RAX = $00211008;
  81. {$endif x86_64}
  82. OT_REG_COUNT = $00221000; { counter: CL, CX or ECX }
  83. OT_REG_CL = $00221001; { REG_COUNT | BITSxx }
  84. OT_REG_CX = $00221002; { ditto }
  85. OT_REG_ECX = $00221004; { another one }
  86. {$ifdef x86_64}
  87. OT_REG_RCX = $00221008;
  88. {$endif x86_64}
  89. OT_REG_DX = $00241002;
  90. OT_REG_EDX = $00241004;
  91. OT_REG_SREG = $00081002; { any segment register }
  92. OT_REG_CS = $01081002; { CS }
  93. OT_REG_DESS = $02081002; { DS, ES, SS (non-CS 86 registers) }
  94. OT_REG_FSGS = $04081002; { FS, GS (386 extended registers) }
  95. OT_REG_CDT = $00101004; { CRn, DRn and TRn }
  96. OT_REG_CREG = $08101004; { CRn }
  97. OT_REG_CR4 = $08101404; { CR4 (Pentium only) }
  98. OT_REG_DREG = $10101004; { DRn }
  99. OT_REG_TREG = $20101004; { TRn }
  100. OT_MEM_OFFS = $00604000; { special type of EA }
  101. { simple [address] offset }
  102. OT_ONENESS = $00800000; { special type of immediate operand }
  103. { so UNITY == IMMEDIATE | ONENESS }
  104. OT_UNITY = $00802000; { for shift/rotate instructions }
  105. { Size of the instruction table converted by nasmconv.pas }
  106. {$ifdef x86_64}
  107. instabentries = {$i x86_64no.inc}
  108. {$else x86_64}
  109. instabentries = {$i i386nop.inc}
  110. {$endif x86_64}
  111. maxinfolen = 8;
  112. type
  113. TOperandOrder = (op_intel,op_att);
  114. tinsentry=packed record
  115. opcode : tasmop;
  116. ops : byte;
  117. optypes : array[0..2] of longint;
  118. code : array[0..maxinfolen] of char;
  119. flags : longint;
  120. end;
  121. pinsentry=^tinsentry;
  122. { alignment for operator }
  123. tai_align = class(tai_align_abstract)
  124. reg : tregister;
  125. constructor create(b:byte);
  126. constructor create_op(b: byte; _op: byte);
  127. function calculatefillbuf(var buf : tfillbuffer):pchar;override;
  128. end;
  129. taicpu = class(taicpu_abstract)
  130. opsize : topsize;
  131. constructor op_none(op : tasmop;_size : topsize);
  132. constructor op_reg(op : tasmop;_size : topsize;_op1 : tregister);
  133. constructor op_const(op : tasmop;_size : topsize;_op1 : aword);
  134. constructor op_ref(op : tasmop;_size : topsize;const _op1 : treference);
  135. constructor op_reg_reg(op : tasmop;_size : topsize;_op1,_op2 : tregister);
  136. constructor op_reg_ref(op : tasmop;_size : topsize;_op1 : tregister;const _op2 : treference);
  137. constructor op_reg_const(op:tasmop; _size: topsize; _op1: tregister; _op2: aword);
  138. constructor op_const_reg(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister);
  139. constructor op_const_const(op : tasmop;_size : topsize;_op1,_op2 : aword);
  140. constructor op_const_ref(op : tasmop;_size : topsize;_op1 : aword;const _op2 : treference);
  141. constructor op_ref_reg(op : tasmop;_size : topsize;const _op1 : treference;_op2 : tregister);
  142. constructor op_reg_reg_reg(op : tasmop;_size : topsize;_op1,_op2,_op3 : tregister);
  143. constructor op_const_reg_reg(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister;_op3 : tregister);
  144. constructor op_const_ref_reg(op : tasmop;_size : topsize;_op1 : aword;const _op2 : treference;_op3 : tregister);
  145. constructor op_reg_reg_ref(op : tasmop;_size : topsize;_op1,_op2 : tregister; const _op3 : treference);
  146. constructor op_const_reg_ref(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister;const _op3 : treference);
  147. { this is for Jmp instructions }
  148. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_size : topsize;_op1 : tasmsymbol);
  149. constructor op_sym(op : tasmop;_size : topsize;_op1 : tasmsymbol);
  150. constructor op_sym_ofs(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint);
  151. constructor op_sym_ofs_reg(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;_op2 : tregister);
  152. constructor op_sym_ofs_ref(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  153. procedure changeopsize(siz:topsize);
  154. function GetString:string;
  155. procedure CheckNonCommutativeOpcodes;
  156. private
  157. FOperandOrder : TOperandOrder;
  158. procedure init(_size : topsize); { this need to be called by all constructor }
  159. {$ifndef NOAG386BIN}
  160. public
  161. { the next will reset all instructions that can change in pass 2 }
  162. procedure ResetPass1;
  163. procedure ResetPass2;
  164. function CheckIfValid:boolean;
  165. function Pass1(offset:longint):longint;virtual;
  166. procedure Pass2(sec:TAsmObjectdata);virtual;
  167. procedure SetOperandOrder(order:TOperandOrder);
  168. function is_nop:boolean;override;
  169. function is_move:boolean;override;
  170. function spill_registers(list:Taasmoutput;
  171. rgget:Trggetproc;
  172. rgunget:Trgungetproc;
  173. r:Tsuperregisterset;
  174. var unusedregsint:Tsuperregisterset;
  175. const spilltemplist:Tspill_temp_list):boolean;override;
  176. protected
  177. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);override;
  178. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);override;
  179. procedure ppuderefoper(var o:toper);override;
  180. private
  181. { next fields are filled in pass1, so pass2 is faster }
  182. insentry : PInsEntry;
  183. insoffset,
  184. inssize : longint;
  185. LastInsOffset : longint; { need to be public to be reset }
  186. function InsEnd:longint;
  187. procedure create_ot;
  188. function Matches(p:PInsEntry):longint;
  189. function calcsize(p:PInsEntry):longint;
  190. procedure gencode(sec:TAsmObjectData);
  191. function NeedAddrPrefix(opidx:byte):boolean;
  192. procedure Swapoperands;
  193. function FindInsentry:boolean;
  194. {$endif NOAG386BIN}
  195. end;
  196. procedure InitAsm;
  197. procedure DoneAsm;
  198. implementation
  199. uses
  200. cutils,
  201. itx86att;
  202. {*****************************************************************************
  203. Instruction table
  204. *****************************************************************************}
  205. const
  206. {Instruction flags }
  207. IF_NONE = $00000000;
  208. IF_SM = $00000001; { size match first two operands }
  209. IF_SM2 = $00000002;
  210. IF_SB = $00000004; { unsized operands can't be non-byte }
  211. IF_SW = $00000008; { unsized operands can't be non-word }
  212. IF_SD = $00000010; { unsized operands can't be nondword }
  213. IF_AR0 = $00000020; { SB, SW, SD applies to argument 0 }
  214. IF_AR1 = $00000040; { SB, SW, SD applies to argument 1 }
  215. IF_AR2 = $00000060; { SB, SW, SD applies to argument 2 }
  216. IF_ARMASK = $00000060; { mask for unsized argument spec }
  217. IF_PRIV = $00000100; { it's a privileged instruction }
  218. IF_SMM = $00000200; { it's only valid in SMM }
  219. IF_PROT = $00000400; { it's protected mode only }
  220. IF_UNDOC = $00001000; { it's an undocumented instruction }
  221. IF_FPU = $00002000; { it's an FPU instruction }
  222. IF_MMX = $00004000; { it's an MMX instruction }
  223. { it's a 3DNow! instruction }
  224. IF_3DNOW = $00008000;
  225. { it's a SSE (KNI, MMX2) instruction }
  226. IF_SSE = $00010000;
  227. { SSE2 instructions }
  228. IF_SSE2 = $00020000;
  229. { SSE3 instructions }
  230. IF_SSE3 = $00040000;
  231. { the mask for processor types }
  232. {IF_PMASK = longint($FF000000);}
  233. { the mask for disassembly "prefer" }
  234. {IF_PFMASK = longint($F001FF00);}
  235. IF_8086 = $00000000; { 8086 instruction }
  236. IF_186 = $01000000; { 186+ instruction }
  237. IF_286 = $02000000; { 286+ instruction }
  238. IF_386 = $03000000; { 386+ instruction }
  239. IF_486 = $04000000; { 486+ instruction }
  240. IF_PENT = $05000000; { Pentium instruction }
  241. IF_P6 = $06000000; { P6 instruction }
  242. IF_KATMAI = $07000000; { Katmai instructions }
  243. { Willamette instructions }
  244. IF_WILLAMETTE = $08000000;
  245. { Prescott instructions }
  246. IF_PRESCOTT = $09000000;
  247. IF_CYRIX = $10000000; { Cyrix-specific instruction }
  248. IF_AMD = $20000000; { AMD-specific instruction }
  249. { added flags }
  250. IF_PRE = $40000000; { it's a prefix instruction }
  251. IF_PASS2 = longint($80000000); { if the instruction can change in a second pass }
  252. type
  253. TInsTabCache=array[TasmOp] of longint;
  254. PInsTabCache=^TInsTabCache;
  255. const
  256. {$ifdef x86_64}
  257. InsTab:array[0..instabentries-1] of TInsEntry={$i x86_64ta.inc}
  258. {$else x86_64}
  259. InsTab:array[0..instabentries-1] of TInsEntry={$i i386tab.inc}
  260. {$endif x86_64}
  261. var
  262. InsTabCache : PInsTabCache;
  263. const
  264. {$ifdef x86_64}
  265. { Intel style operands ! }
  266. opsize_2_type:array[0..2,topsize] of longint=(
  267. (OT_NONE,
  268. OT_BITS8,OT_BITS16,OT_BITS32,OT_BITS16,OT_BITS32,OT_BITS32,OT_BITS64,OT_BITS64,OT_BITS64,
  269. OT_BITS16,OT_BITS32,OT_BITS64,
  270. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,OT_NONE,
  271. OT_NEAR,OT_FAR,OT_SHORT
  272. ),
  273. (OT_NONE,
  274. OT_BITS8,OT_BITS16,OT_BITS32,OT_BITS8,OT_BITS8,OT_BITS16,OT_BITS8,OT_BITS16,OT_BITS32,
  275. OT_BITS16,OT_BITS32,OT_BITS64,
  276. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,OT_NONE,
  277. OT_NEAR,OT_FAR,OT_SHORT
  278. ),
  279. (OT_NONE,
  280. OT_BITS8,OT_BITS16,OT_BITS32,OT_NONE,OT_NONE,OT_NONE,OT_NONE,OT_NONE,OT_NONE,
  281. OT_BITS16,OT_BITS32,OT_BITS64,
  282. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,OT_NONE,
  283. OT_NEAR,OT_FAR,OT_SHORT
  284. )
  285. );
  286. reg_ot_table : array[tregisterindex] of longint = (
  287. {$i r8664ot.inc}
  288. );
  289. {$else x86_64}
  290. { Intel style operands ! }
  291. opsize_2_type:array[0..2,topsize] of longint=(
  292. (OT_NONE,
  293. OT_BITS8,OT_BITS16,OT_BITS32,OT_BITS16,OT_BITS32,OT_BITS32,
  294. OT_BITS16,OT_BITS32,OT_BITS64,
  295. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,OT_NONE,
  296. OT_NEAR,OT_FAR,OT_SHORT
  297. ),
  298. (OT_NONE,
  299. OT_BITS8,OT_BITS16,OT_BITS32,OT_BITS8,OT_BITS8,OT_BITS16,
  300. OT_BITS16,OT_BITS32,OT_BITS64,
  301. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,OT_NONE,
  302. OT_NEAR,OT_FAR,OT_SHORT
  303. ),
  304. (OT_NONE,
  305. OT_BITS8,OT_BITS16,OT_BITS32,OT_NONE,OT_NONE,OT_NONE,
  306. OT_BITS16,OT_BITS32,OT_BITS64,
  307. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,OT_NONE,
  308. OT_NEAR,OT_FAR,OT_SHORT
  309. )
  310. );
  311. reg_ot_table : array[tregisterindex] of longint = (
  312. {$i r386ot.inc}
  313. );
  314. {$endif x86_64}
  315. subreg2type:array[tsubregister] of longint = (
  316. OT_NONE,OT_REG8,OT_REG8,OT_REG16,OT_REG32,OT_REG64
  317. );
  318. {****************************************************************************
  319. TAI_ALIGN
  320. ****************************************************************************}
  321. constructor tai_align.create(b: byte);
  322. begin
  323. inherited create(b);
  324. reg:=NR_ECX;
  325. end;
  326. constructor tai_align.create_op(b: byte; _op: byte);
  327. begin
  328. inherited create_op(b,_op);
  329. reg:=NR_NO;
  330. end;
  331. function tai_align.calculatefillbuf(var buf : tfillbuffer):pchar;
  332. const
  333. alignarray:array[0..5] of string[8]=(
  334. #$8D#$B4#$26#$00#$00#$00#$00,
  335. #$8D#$B6#$00#$00#$00#$00,
  336. #$8D#$74#$26#$00,
  337. #$8D#$76#$00,
  338. #$89#$F6,
  339. #$90
  340. );
  341. var
  342. bufptr : pchar;
  343. j : longint;
  344. begin
  345. inherited calculatefillbuf(buf);
  346. if not use_op then
  347. begin
  348. bufptr:=pchar(@buf);
  349. while (fillsize>0) do
  350. begin
  351. for j:=0 to 5 do
  352. if (fillsize>=length(alignarray[j])) then
  353. break;
  354. move(alignarray[j][1],bufptr^,length(alignarray[j]));
  355. inc(bufptr,length(alignarray[j]));
  356. dec(fillsize,length(alignarray[j]));
  357. end;
  358. end;
  359. calculatefillbuf:=pchar(@buf);
  360. end;
  361. {*****************************************************************************
  362. Taicpu Constructors
  363. *****************************************************************************}
  364. procedure taicpu.changeopsize(siz:topsize);
  365. begin
  366. opsize:=siz;
  367. end;
  368. procedure taicpu.init(_size : topsize);
  369. begin
  370. { default order is att }
  371. FOperandOrder:=op_att;
  372. segprefix:=NR_NO;
  373. opsize:=_size;
  374. {$ifndef NOAG386BIN}
  375. insentry:=nil;
  376. LastInsOffset:=-1;
  377. InsOffset:=0;
  378. InsSize:=0;
  379. {$endif}
  380. end;
  381. constructor taicpu.op_none(op : tasmop;_size : topsize);
  382. begin
  383. inherited create(op);
  384. init(_size);
  385. end;
  386. constructor taicpu.op_reg(op : tasmop;_size : topsize;_op1 : tregister);
  387. begin
  388. inherited create(op);
  389. init(_size);
  390. ops:=1;
  391. loadreg(0,_op1);
  392. end;
  393. constructor taicpu.op_const(op : tasmop;_size : topsize;_op1 : aword);
  394. begin
  395. inherited create(op);
  396. init(_size);
  397. ops:=1;
  398. loadconst(0,_op1);
  399. end;
  400. constructor taicpu.op_ref(op : tasmop;_size : topsize;const _op1 : treference);
  401. begin
  402. inherited create(op);
  403. init(_size);
  404. ops:=1;
  405. loadref(0,_op1);
  406. end;
  407. constructor taicpu.op_reg_reg(op : tasmop;_size : topsize;_op1,_op2 : tregister);
  408. begin
  409. inherited create(op);
  410. init(_size);
  411. ops:=2;
  412. loadreg(0,_op1);
  413. loadreg(1,_op2);
  414. end;
  415. constructor taicpu.op_reg_const(op:tasmop; _size: topsize; _op1: tregister; _op2: aword);
  416. begin
  417. inherited create(op);
  418. init(_size);
  419. ops:=2;
  420. loadreg(0,_op1);
  421. loadconst(1,_op2);
  422. end;
  423. constructor taicpu.op_reg_ref(op : tasmop;_size : topsize;_op1 : tregister;const _op2 : treference);
  424. begin
  425. inherited create(op);
  426. init(_size);
  427. ops:=2;
  428. loadreg(0,_op1);
  429. loadref(1,_op2);
  430. end;
  431. constructor taicpu.op_const_reg(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister);
  432. begin
  433. inherited create(op);
  434. init(_size);
  435. ops:=2;
  436. loadconst(0,_op1);
  437. loadreg(1,_op2);
  438. end;
  439. constructor taicpu.op_const_const(op : tasmop;_size : topsize;_op1,_op2 : aword);
  440. begin
  441. inherited create(op);
  442. init(_size);
  443. ops:=2;
  444. loadconst(0,_op1);
  445. loadconst(1,_op2);
  446. end;
  447. constructor taicpu.op_const_ref(op : tasmop;_size : topsize;_op1 : aword;const _op2 : treference);
  448. begin
  449. inherited create(op);
  450. init(_size);
  451. ops:=2;
  452. loadconst(0,_op1);
  453. loadref(1,_op2);
  454. end;
  455. constructor taicpu.op_ref_reg(op : tasmop;_size : topsize;const _op1 : treference;_op2 : tregister);
  456. begin
  457. inherited create(op);
  458. init(_size);
  459. ops:=2;
  460. loadref(0,_op1);
  461. loadreg(1,_op2);
  462. end;
  463. constructor taicpu.op_reg_reg_reg(op : tasmop;_size : topsize;_op1,_op2,_op3 : tregister);
  464. begin
  465. inherited create(op);
  466. init(_size);
  467. ops:=3;
  468. loadreg(0,_op1);
  469. loadreg(1,_op2);
  470. loadreg(2,_op3);
  471. end;
  472. constructor taicpu.op_const_reg_reg(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister;_op3 : tregister);
  473. begin
  474. inherited create(op);
  475. init(_size);
  476. ops:=3;
  477. loadconst(0,_op1);
  478. loadreg(1,_op2);
  479. loadreg(2,_op3);
  480. end;
  481. constructor taicpu.op_reg_reg_ref(op : tasmop;_size : topsize;_op1,_op2 : tregister;const _op3 : treference);
  482. begin
  483. inherited create(op);
  484. init(_size);
  485. ops:=3;
  486. loadreg(0,_op1);
  487. loadreg(1,_op2);
  488. loadref(2,_op3);
  489. end;
  490. constructor taicpu.op_const_ref_reg(op : tasmop;_size : topsize;_op1 : aword;const _op2 : treference;_op3 : tregister);
  491. begin
  492. inherited create(op);
  493. init(_size);
  494. ops:=3;
  495. loadconst(0,_op1);
  496. loadref(1,_op2);
  497. loadreg(2,_op3);
  498. end;
  499. constructor taicpu.op_const_reg_ref(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister;const _op3 : treference);
  500. begin
  501. inherited create(op);
  502. init(_size);
  503. ops:=3;
  504. loadconst(0,_op1);
  505. loadreg(1,_op2);
  506. loadref(2,_op3);
  507. end;
  508. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_size : topsize;_op1 : tasmsymbol);
  509. begin
  510. inherited create(op);
  511. init(_size);
  512. condition:=cond;
  513. ops:=1;
  514. loadsymbol(0,_op1,0);
  515. end;
  516. constructor taicpu.op_sym(op : tasmop;_size : topsize;_op1 : tasmsymbol);
  517. begin
  518. inherited create(op);
  519. init(_size);
  520. ops:=1;
  521. loadsymbol(0,_op1,0);
  522. end;
  523. constructor taicpu.op_sym_ofs(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint);
  524. begin
  525. inherited create(op);
  526. init(_size);
  527. ops:=1;
  528. loadsymbol(0,_op1,_op1ofs);
  529. end;
  530. constructor taicpu.op_sym_ofs_reg(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;_op2 : tregister);
  531. begin
  532. inherited create(op);
  533. init(_size);
  534. ops:=2;
  535. loadsymbol(0,_op1,_op1ofs);
  536. loadreg(1,_op2);
  537. end;
  538. constructor taicpu.op_sym_ofs_ref(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  539. begin
  540. inherited create(op);
  541. init(_size);
  542. ops:=2;
  543. loadsymbol(0,_op1,_op1ofs);
  544. loadref(1,_op2);
  545. end;
  546. function taicpu.GetString:string;
  547. var
  548. i : longint;
  549. s : string;
  550. addsize : boolean;
  551. begin
  552. s:='['+std_op2str[opcode];
  553. for i:=1to ops do
  554. begin
  555. if i=1 then
  556. s:=s+' '
  557. else
  558. s:=s+',';
  559. { type }
  560. addsize:=false;
  561. if (oper[i-1].ot and OT_XMMREG)=OT_XMMREG then
  562. s:=s+'xmmreg'
  563. else
  564. if (oper[i-1].ot and OT_MMXREG)=OT_MMXREG then
  565. s:=s+'mmxreg'
  566. else
  567. if (oper[i-1].ot and OT_FPUREG)=OT_FPUREG then
  568. s:=s+'fpureg'
  569. else
  570. if (oper[i-1].ot and OT_REGISTER)=OT_REGISTER then
  571. begin
  572. s:=s+'reg';
  573. addsize:=true;
  574. end
  575. else
  576. if (oper[i-1].ot and OT_IMMEDIATE)=OT_IMMEDIATE then
  577. begin
  578. s:=s+'imm';
  579. addsize:=true;
  580. end
  581. else
  582. if (oper[i-1].ot and OT_MEMORY)=OT_MEMORY then
  583. begin
  584. s:=s+'mem';
  585. addsize:=true;
  586. end
  587. else
  588. s:=s+'???';
  589. { size }
  590. if addsize then
  591. begin
  592. if (oper[i-1].ot and OT_BITS8)<>0 then
  593. s:=s+'8'
  594. else
  595. if (oper[i-1].ot and OT_BITS16)<>0 then
  596. s:=s+'16'
  597. else
  598. if (oper[i-1].ot and OT_BITS32)<>0 then
  599. s:=s+'32'
  600. else
  601. s:=s+'??';
  602. { signed }
  603. if (oper[i-1].ot and OT_SIGNED)<>0 then
  604. s:=s+'s';
  605. end;
  606. end;
  607. GetString:=s+']';
  608. end;
  609. procedure taicpu.Swapoperands;
  610. var
  611. p : TOper;
  612. begin
  613. { Fix the operands which are in AT&T style and we need them in Intel style }
  614. case ops of
  615. 2 : begin
  616. { 0,1 -> 1,0 }
  617. p:=oper[0];
  618. oper[0]:=oper[1];
  619. oper[1]:=p;
  620. end;
  621. 3 : begin
  622. { 0,1,2 -> 2,1,0 }
  623. p:=oper[0];
  624. oper[0]:=oper[2];
  625. oper[2]:=p;
  626. end;
  627. end;
  628. end;
  629. procedure taicpu.SetOperandOrder(order:TOperandOrder);
  630. begin
  631. if FOperandOrder<>order then
  632. begin
  633. Swapoperands;
  634. FOperandOrder:=order;
  635. end;
  636. end;
  637. procedure taicpu.ppuloadoper(ppufile:tcompilerppufile;var o:toper);
  638. begin
  639. o.typ:=toptype(ppufile.getbyte);
  640. o.ot:=ppufile.getlongint;
  641. case o.typ of
  642. top_reg :
  643. ppufile.getdata(o.reg,sizeof(Tregister));
  644. top_ref :
  645. begin
  646. new(o.ref);
  647. ppufile.getdata(o.ref^.segment,sizeof(Tregister));
  648. ppufile.getdata(o.ref^.base,sizeof(Tregister));
  649. ppufile.getdata(o.ref^.index,sizeof(Tregister));
  650. o.ref^.scalefactor:=ppufile.getbyte;
  651. o.ref^.offset:=ppufile.getlongint;
  652. o.ref^.symbol:=ppufile.getasmsymbol;
  653. end;
  654. top_const :
  655. o.val:=aword(ppufile.getlongint);
  656. top_symbol :
  657. begin
  658. o.sym:=ppufile.getasmsymbol;
  659. o.symofs:=ppufile.getlongint;
  660. end;
  661. top_local :
  662. begin
  663. ppufile.getderef(o.localsymderef);
  664. o.localsymofs:=ppufile.getlongint;
  665. end;
  666. end;
  667. end;
  668. procedure taicpu.ppuwriteoper(ppufile:tcompilerppufile;const o:toper);
  669. begin
  670. ppufile.putbyte(byte(o.typ));
  671. ppufile.putlongint(o.ot);
  672. case o.typ of
  673. top_reg :
  674. ppufile.putdata(o.reg,sizeof(Tregister));
  675. top_ref :
  676. begin
  677. ppufile.putdata(o.ref^.segment,sizeof(Tregister));
  678. ppufile.putdata(o.ref^.base,sizeof(Tregister));
  679. ppufile.putdata(o.ref^.index,sizeof(Tregister));
  680. ppufile.putbyte(o.ref^.scalefactor);
  681. ppufile.putlongint(o.ref^.offset);
  682. ppufile.putasmsymbol(o.ref^.symbol);
  683. end;
  684. top_const :
  685. ppufile.putlongint(longint(o.val));
  686. top_symbol :
  687. begin
  688. ppufile.putasmsymbol(o.sym);
  689. ppufile.putlongint(longint(o.symofs));
  690. end;
  691. top_local :
  692. begin
  693. ppufile.putderef(tvarsym(o.localsym),o.localsymderef);
  694. ppufile.putlongint(longint(o.localsymofs));
  695. end;
  696. end;
  697. end;
  698. procedure taicpu.ppuderefoper(var o:toper);
  699. begin
  700. case o.typ of
  701. top_ref :
  702. begin
  703. if assigned(o.ref^.symbol) then
  704. objectlibrary.derefasmsymbol(o.ref^.symbol);
  705. end;
  706. top_symbol :
  707. objectlibrary.derefasmsymbol(o.sym);
  708. top_local :
  709. o.localsym:=tvarsym(o.localsymderef.resolve);
  710. end;
  711. end;
  712. procedure taicpu.CheckNonCommutativeOpcodes;
  713. begin
  714. { we need ATT order }
  715. SetOperandOrder(op_att);
  716. if (
  717. (ops=2) and
  718. (oper[0].typ=top_reg) and
  719. (oper[1].typ=top_reg) and
  720. { if the first is ST and the second is also a register
  721. it is necessarily ST1 .. ST7 }
  722. ((oper[0].reg=NR_ST) or
  723. (oper[0].reg=NR_ST0))
  724. ) or
  725. { ((ops=1) and
  726. (oper[0].typ=top_reg) and
  727. (oper[0].reg in [R_ST1..R_ST7])) or}
  728. (ops=0) then
  729. begin
  730. if opcode=A_FSUBR then
  731. opcode:=A_FSUB
  732. else if opcode=A_FSUB then
  733. opcode:=A_FSUBR
  734. else if opcode=A_FDIVR then
  735. opcode:=A_FDIV
  736. else if opcode=A_FDIV then
  737. opcode:=A_FDIVR
  738. else if opcode=A_FSUBRP then
  739. opcode:=A_FSUBP
  740. else if opcode=A_FSUBP then
  741. opcode:=A_FSUBRP
  742. else if opcode=A_FDIVRP then
  743. opcode:=A_FDIVP
  744. else if opcode=A_FDIVP then
  745. opcode:=A_FDIVRP;
  746. end;
  747. if (
  748. (ops=1) and
  749. (oper[0].typ=top_reg) and
  750. (getregtype(oper[0].reg)=R_FPUREGISTER) and
  751. (oper[0].reg<>NR_ST)
  752. ) then
  753. begin
  754. if opcode=A_FSUBRP then
  755. opcode:=A_FSUBP
  756. else if opcode=A_FSUBP then
  757. opcode:=A_FSUBRP
  758. else if opcode=A_FDIVRP then
  759. opcode:=A_FDIVP
  760. else if opcode=A_FDIVP then
  761. opcode:=A_FDIVRP;
  762. end;
  763. end;
  764. {*****************************************************************************
  765. Assembler
  766. *****************************************************************************}
  767. {$ifndef NOAG386BIN}
  768. type
  769. ea=packed record
  770. sib_present : boolean;
  771. bytes : byte;
  772. size : byte;
  773. modrm : byte;
  774. sib : byte;
  775. end;
  776. procedure taicpu.create_ot;
  777. {
  778. this function will also fix some other fields which only needs to be once
  779. }
  780. var
  781. i,l,relsize : longint;
  782. begin
  783. if ops=0 then
  784. exit;
  785. { update oper[].ot field }
  786. for i:=0 to ops-1 do
  787. with oper[i] do
  788. begin
  789. case typ of
  790. top_reg :
  791. begin
  792. ot:=reg_ot_table[findreg_by_number(reg)];
  793. end;
  794. top_ref :
  795. begin
  796. { create ot field }
  797. if (ot and OT_SIZE_MASK)=0 then
  798. ot:=OT_MEMORY or opsize_2_type[i,opsize]
  799. else
  800. ot:=OT_MEMORY or (ot and OT_SIZE_MASK);
  801. if (ref^.base=NR_NO) and (ref^.index=NR_NO) then
  802. ot:=ot or OT_MEM_OFFS;
  803. { fix scalefactor }
  804. if (ref^.index=NR_NO) then
  805. ref^.scalefactor:=0
  806. else
  807. if (ref^.scalefactor=0) then
  808. ref^.scalefactor:=1;
  809. end;
  810. top_local :
  811. begin
  812. if (ot and OT_SIZE_MASK)=0 then
  813. ot:=OT_MEMORY or opsize_2_type[i,opsize]
  814. else
  815. ot:=OT_MEMORY or (ot and OT_SIZE_MASK);
  816. end;
  817. top_const :
  818. begin
  819. if (opsize<>S_W) and (longint(val)>=-128) and (val<=127) then
  820. ot:=OT_IMM8 or OT_SIGNED
  821. else
  822. ot:=OT_IMMEDIATE or opsize_2_type[i,opsize];
  823. end;
  824. top_symbol :
  825. begin
  826. if LastInsOffset=-1 then
  827. l:=0
  828. else
  829. l:=InsOffset-LastInsOffset;
  830. inc(l,symofs);
  831. if assigned(sym) then
  832. inc(l,sym.address);
  833. { instruction size will then always become 2 (PFV) }
  834. relsize:=(InsOffset+2)-l;
  835. if (not assigned(sym) or
  836. ((sym.currbind<>AB_EXTERNAL) and (sym.address<>0))) and
  837. (relsize>=-128) and (relsize<=127) then
  838. ot:=OT_IMM32 or OT_SHORT
  839. else
  840. ot:=OT_IMM32 or OT_NEAR;
  841. end;
  842. end;
  843. end;
  844. end;
  845. function taicpu.InsEnd:longint;
  846. begin
  847. InsEnd:=InsOffset+InsSize;
  848. end;
  849. function taicpu.Matches(p:PInsEntry):longint;
  850. { * IF_SM stands for Size Match: any operand whose size is not
  851. * explicitly specified by the template is `really' intended to be
  852. * the same size as the first size-specified operand.
  853. * Non-specification is tolerated in the input instruction, but
  854. * _wrong_ specification is not.
  855. *
  856. * IF_SM2 invokes Size Match on only the first _two_ operands, for
  857. * three-operand instructions such as SHLD: it implies that the
  858. * first two operands must match in size, but that the third is
  859. * required to be _unspecified_.
  860. *
  861. * IF_SB invokes Size Byte: operands with unspecified size in the
  862. * template are really bytes, and so no non-byte specification in
  863. * the input instruction will be tolerated. IF_SW similarly invokes
  864. * Size Word, and IF_SD invokes Size Doubleword.
  865. *
  866. * (The default state if neither IF_SM nor IF_SM2 is specified is
  867. * that any operand with unspecified size in the template is
  868. * required to have unspecified size in the instruction too...)
  869. }
  870. var
  871. i,j,asize,oprs : longint;
  872. siz : array[0..2] of longint;
  873. begin
  874. Matches:=100;
  875. { Check the opcode and operands }
  876. if (p^.opcode<>opcode) or (p^.ops<>ops) then
  877. begin
  878. Matches:=0;
  879. exit;
  880. end;
  881. { Check that no spurious colons or TOs are present }
  882. for i:=0 to p^.ops-1 do
  883. if (oper[i].ot and (not p^.optypes[i]) and (OT_COLON or OT_TO))<>0 then
  884. begin
  885. Matches:=0;
  886. exit;
  887. end;
  888. { Check that the operand flags all match up }
  889. for i:=0 to p^.ops-1 do
  890. begin
  891. if ((p^.optypes[i] and (not oper[i].ot)) or
  892. ((p^.optypes[i] and OT_SIZE_MASK) and
  893. ((p^.optypes[i] xor oper[i].ot) and OT_SIZE_MASK)))<>0 then
  894. begin
  895. if ((p^.optypes[i] and (not oper[i].ot) and OT_NON_SIZE) or
  896. (oper[i].ot and OT_SIZE_MASK))<>0 then
  897. begin
  898. Matches:=0;
  899. exit;
  900. end
  901. else
  902. Matches:=1;
  903. end;
  904. end;
  905. { Check operand sizes }
  906. { as default an untyped size can get all the sizes, this is different
  907. from nasm, but else we need to do a lot checking which opcodes want
  908. size or not with the automatic size generation }
  909. asize:=longint($ffffffff);
  910. if (p^.flags and IF_SB)<>0 then
  911. asize:=OT_BITS8
  912. else if (p^.flags and IF_SW)<>0 then
  913. asize:=OT_BITS16
  914. else if (p^.flags and IF_SD)<>0 then
  915. asize:=OT_BITS32;
  916. if (p^.flags and IF_ARMASK)<>0 then
  917. begin
  918. siz[0]:=0;
  919. siz[1]:=0;
  920. siz[2]:=0;
  921. if (p^.flags and IF_AR0)<>0 then
  922. siz[0]:=asize
  923. else if (p^.flags and IF_AR1)<>0 then
  924. siz[1]:=asize
  925. else if (p^.flags and IF_AR2)<>0 then
  926. siz[2]:=asize;
  927. end
  928. else
  929. begin
  930. { we can leave because the size for all operands is forced to be
  931. the same
  932. but not if IF_SB IF_SW or IF_SD is set PM }
  933. if asize=-1 then
  934. exit;
  935. siz[0]:=asize;
  936. siz[1]:=asize;
  937. siz[2]:=asize;
  938. end;
  939. if (p^.flags and (IF_SM or IF_SM2))<>0 then
  940. begin
  941. if (p^.flags and IF_SM2)<>0 then
  942. oprs:=2
  943. else
  944. oprs:=p^.ops;
  945. for i:=0 to oprs-1 do
  946. if ((p^.optypes[i] and OT_SIZE_MASK) <> 0) then
  947. begin
  948. for j:=0 to oprs-1 do
  949. siz[j]:=p^.optypes[i] and OT_SIZE_MASK;
  950. break;
  951. end;
  952. end
  953. else
  954. oprs:=2;
  955. { Check operand sizes }
  956. for i:=0 to p^.ops-1 do
  957. begin
  958. if ((p^.optypes[i] and OT_SIZE_MASK)=0) and
  959. ((oper[i].ot and OT_SIZE_MASK and (not siz[i]))<>0) and
  960. { Immediates can always include smaller size }
  961. ((oper[i].ot and OT_IMMEDIATE)=0) and
  962. (((p^.optypes[i] and OT_SIZE_MASK) or siz[i])<(oper[i].ot and OT_SIZE_MASK)) then
  963. Matches:=2;
  964. end;
  965. end;
  966. procedure taicpu.ResetPass1;
  967. begin
  968. { we need to reset everything here, because the choosen insentry
  969. can be invalid for a new situation where the previously optimized
  970. insentry is not correct }
  971. InsEntry:=nil;
  972. InsSize:=0;
  973. LastInsOffset:=-1;
  974. end;
  975. procedure taicpu.ResetPass2;
  976. begin
  977. { we are here in a second pass, check if the instruction can be optimized }
  978. if assigned(InsEntry) and
  979. ((InsEntry^.flags and IF_PASS2)<>0) then
  980. begin
  981. InsEntry:=nil;
  982. InsSize:=0;
  983. end;
  984. LastInsOffset:=-1;
  985. end;
  986. function taicpu.CheckIfValid:boolean;
  987. begin
  988. result:=FindInsEntry;
  989. end;
  990. function taicpu.FindInsentry:boolean;
  991. var
  992. i : longint;
  993. begin
  994. result:=false;
  995. { Things which may only be done once, not when a second pass is done to
  996. optimize }
  997. if (Insentry=nil) or ((InsEntry^.flags and IF_PASS2)<>0) then
  998. begin
  999. { We need intel style operands }
  1000. SetOperandOrder(op_intel);
  1001. { create the .ot fields }
  1002. create_ot;
  1003. { set the file postion }
  1004. aktfilepos:=fileinfo;
  1005. end
  1006. else
  1007. begin
  1008. { we've already an insentry so it's valid }
  1009. result:=true;
  1010. exit;
  1011. end;
  1012. { Lookup opcode in the table }
  1013. InsSize:=-1;
  1014. i:=instabcache^[opcode];
  1015. if i=-1 then
  1016. begin
  1017. Message1(asmw_e_opcode_not_in_table,gas_op2str[opcode]);
  1018. exit;
  1019. end;
  1020. insentry:=@instab[i];
  1021. while (insentry^.opcode=opcode) do
  1022. begin
  1023. if matches(insentry)=100 then
  1024. begin
  1025. result:=true;
  1026. exit;
  1027. end;
  1028. inc(i);
  1029. insentry:=@instab[i];
  1030. end;
  1031. Message1(asmw_e_invalid_opcode_and_operands,GetString);
  1032. { No instruction found, set insentry to nil and inssize to -1 }
  1033. insentry:=nil;
  1034. inssize:=-1;
  1035. end;
  1036. function taicpu.Pass1(offset:longint):longint;
  1037. begin
  1038. Pass1:=0;
  1039. { Save the old offset and set the new offset }
  1040. InsOffset:=Offset;
  1041. { Things which may only be done once, not when a second pass is done to
  1042. optimize }
  1043. if Insentry=nil then
  1044. begin
  1045. { Check if error last time then InsSize=-1 }
  1046. if InsSize=-1 then
  1047. exit;
  1048. { set the file postion }
  1049. aktfilepos:=fileinfo;
  1050. end
  1051. else
  1052. begin
  1053. {$ifdef PASS2FLAG}
  1054. { we are here in a second pass, check if the instruction can be optimized }
  1055. if (InsEntry^.flags and IF_PASS2)=0 then
  1056. begin
  1057. Pass1:=InsSize;
  1058. exit;
  1059. end;
  1060. { update the .ot fields, some top_const can be updated }
  1061. create_ot;
  1062. {$endif PASS2FLAG}
  1063. end;
  1064. { Get InsEntry }
  1065. if FindInsEntry then
  1066. begin
  1067. { Calculate instruction size }
  1068. InsSize:=calcsize(insentry);
  1069. if segprefix<>NR_NO then
  1070. inc(InsSize);
  1071. { Fix opsize if size if forced }
  1072. if (insentry^.flags and (IF_SB or IF_SW or IF_SD))<>0 then
  1073. begin
  1074. if (insentry^.flags and IF_ARMASK)=0 then
  1075. begin
  1076. if (insentry^.flags and IF_SB)<>0 then
  1077. begin
  1078. if opsize=S_NO then
  1079. opsize:=S_B;
  1080. end
  1081. else if (insentry^.flags and IF_SW)<>0 then
  1082. begin
  1083. if opsize=S_NO then
  1084. opsize:=S_W;
  1085. end
  1086. else if (insentry^.flags and IF_SD)<>0 then
  1087. begin
  1088. if opsize=S_NO then
  1089. opsize:=S_L;
  1090. end;
  1091. end;
  1092. end;
  1093. LastInsOffset:=InsOffset;
  1094. Pass1:=InsSize;
  1095. exit;
  1096. end;
  1097. LastInsOffset:=-1;
  1098. end;
  1099. procedure taicpu.Pass2(sec:TAsmObjectData);
  1100. var
  1101. c : longint;
  1102. begin
  1103. { error in pass1 ? }
  1104. if insentry=nil then
  1105. exit;
  1106. aktfilepos:=fileinfo;
  1107. { Segment override }
  1108. if (segprefix<>NR_NO) then
  1109. begin
  1110. case segprefix of
  1111. NR_CS : c:=$2e;
  1112. NR_DS : c:=$3e;
  1113. NR_ES : c:=$26;
  1114. NR_FS : c:=$64;
  1115. NR_GS : c:=$65;
  1116. NR_SS : c:=$36;
  1117. end;
  1118. sec.writebytes(c,1);
  1119. { fix the offset for GenNode }
  1120. inc(InsOffset);
  1121. end;
  1122. { Generate the instruction }
  1123. GenCode(sec);
  1124. end;
  1125. function taicpu.needaddrprefix(opidx:byte):boolean;
  1126. begin
  1127. needaddrprefix:=false;
  1128. if (OT_MEMORY and (not oper[opidx].ot))=0 then
  1129. begin
  1130. if (
  1131. (oper[opidx].ref^.index<>NR_NO) and
  1132. (getsubreg(oper[opidx].ref^.index)<>R_SUBD)
  1133. ) or
  1134. (
  1135. (oper[opidx].ref^.base<>NR_NO) and
  1136. (getsubreg(oper[opidx].ref^.base)<>R_SUBD)
  1137. ) then
  1138. needaddrprefix:=true;
  1139. end;
  1140. end;
  1141. function regval(r:Tregister):byte;
  1142. const
  1143. {$ifdef x86_64}
  1144. opcode_table:array[tregisterindex] of tregisterindex = (
  1145. {$i r8664op.inc}
  1146. );
  1147. {$else x86_64}
  1148. opcode_table:array[tregisterindex] of tregisterindex = (
  1149. {$i r386op.inc}
  1150. );
  1151. {$endif x86_64}
  1152. var
  1153. regidx : tregisterindex;
  1154. begin
  1155. regidx:=findreg_by_number(r);
  1156. if regidx<>0 then
  1157. result:=opcode_table[regidx]
  1158. else
  1159. begin
  1160. Message1(asmw_e_invalid_register,generic_regname(r));
  1161. result:=0;
  1162. end;
  1163. end;
  1164. function process_ea(const input:toper;var output:ea;rfield:longint):boolean;
  1165. var
  1166. sym : tasmsymbol;
  1167. md,s,rv : byte;
  1168. base,index,scalefactor,
  1169. o : longint;
  1170. ir,br : Tregister;
  1171. isub,bsub : tsubregister;
  1172. begin
  1173. process_ea:=false;
  1174. {Register ?}
  1175. if (input.typ=top_reg) then
  1176. begin
  1177. rv:=regval(input.reg);
  1178. output.sib_present:=false;
  1179. output.bytes:=0;
  1180. output.modrm:=$c0 or (rfield shl 3) or rv;
  1181. output.size:=1;
  1182. process_ea:=true;
  1183. exit;
  1184. end;
  1185. {No register, so memory reference.}
  1186. if ((input.ref^.index<>NR_NO) and (getregtype(input.ref^.index)<>R_INTREGISTER)) or
  1187. ((input.ref^.base<>NR_NO) and (getregtype(input.ref^.base)<>R_INTREGISTER)) then
  1188. internalerror(200301081);
  1189. ir:=input.ref^.index;
  1190. br:=input.ref^.base;
  1191. isub:=getsubreg(ir);
  1192. bsub:=getsubreg(br);
  1193. s:=input.ref^.scalefactor;
  1194. o:=input.ref^.offset;
  1195. sym:=input.ref^.symbol;
  1196. { it's direct address }
  1197. if (br=NR_NO) and (ir=NR_NO) then
  1198. begin
  1199. { it's a pure offset }
  1200. output.sib_present:=false;
  1201. output.bytes:=4;
  1202. output.modrm:=5 or (rfield shl 3);
  1203. end
  1204. else
  1205. { it's an indirection }
  1206. begin
  1207. { 16 bit address? }
  1208. if ((ir<>NR_NO) and (isub<>R_SUBD)) or
  1209. ((br<>NR_NO) and (bsub<>R_SUBD)) then
  1210. message(asmw_e_16bit_not_supported);
  1211. {$ifdef OPTEA}
  1212. { make single reg base }
  1213. if (br=NR_NO) and (s=1) then
  1214. begin
  1215. br:=ir;
  1216. ir:=NR_NO;
  1217. end;
  1218. { convert [3,5,9]*EAX to EAX+[2,4,8]*EAX }
  1219. if (br=NR_NO) and
  1220. (((s=2) and (ir<>NR_ESP)) or
  1221. (s=3) or (s=5) or (s=9)) then
  1222. begin
  1223. br:=ir;
  1224. dec(s);
  1225. end;
  1226. { swap ESP into base if scalefactor is 1 }
  1227. if (s=1) and (ir=NR_ESP) then
  1228. begin
  1229. ir:=br;
  1230. br:=NR_ESP;
  1231. end;
  1232. {$endif OPTEA}
  1233. { wrong, for various reasons }
  1234. if (ir=NR_ESP) or ((s<>1) and (s<>2) and (s<>4) and (s<>8) and (ir<>NR_NO)) then
  1235. exit;
  1236. { base }
  1237. case br of
  1238. NR_EAX : base:=0;
  1239. NR_ECX : base:=1;
  1240. NR_EDX : base:=2;
  1241. NR_EBX : base:=3;
  1242. NR_ESP : base:=4;
  1243. NR_NO,
  1244. NR_EBP : base:=5;
  1245. NR_ESI : base:=6;
  1246. NR_EDI : base:=7;
  1247. else
  1248. exit;
  1249. end;
  1250. { index }
  1251. case ir of
  1252. NR_EAX : index:=0;
  1253. NR_ECX : index:=1;
  1254. NR_EDX : index:=2;
  1255. NR_EBX : index:=3;
  1256. NR_NO : index:=4;
  1257. NR_EBP : index:=5;
  1258. NR_ESI : index:=6;
  1259. NR_EDI : index:=7;
  1260. else
  1261. exit;
  1262. end;
  1263. case s of
  1264. 0,
  1265. 1 : scalefactor:=0;
  1266. 2 : scalefactor:=1;
  1267. 4 : scalefactor:=2;
  1268. 8 : scalefactor:=3;
  1269. else
  1270. exit;
  1271. end;
  1272. if (br=NR_NO) or
  1273. ((br<>NR_EBP) and (o=0) and (sym=nil)) then
  1274. md:=0
  1275. else
  1276. if ((o>=-128) and (o<=127) and (sym=nil)) then
  1277. md:=1
  1278. else
  1279. md:=2;
  1280. if (br=NR_NO) or (md=2) then
  1281. output.bytes:=4
  1282. else
  1283. output.bytes:=md;
  1284. { SIB needed ? }
  1285. if (ir=NR_NO) and (br<>NR_ESP) then
  1286. begin
  1287. output.sib_present:=false;
  1288. output.modrm:=(md shl 6) or (rfield shl 3) or base;
  1289. end
  1290. else
  1291. begin
  1292. output.sib_present:=true;
  1293. output.modrm:=(md shl 6) or (rfield shl 3) or 4;
  1294. output.sib:=(scalefactor shl 6) or (index shl 3) or base;
  1295. end;
  1296. end;
  1297. if output.sib_present then
  1298. output.size:=2+output.bytes
  1299. else
  1300. output.size:=1+output.bytes;
  1301. process_ea:=true;
  1302. end;
  1303. function taicpu.calcsize(p:PInsEntry):longint;
  1304. var
  1305. codes : pchar;
  1306. c : byte;
  1307. len : longint;
  1308. ea_data : ea;
  1309. begin
  1310. len:=0;
  1311. codes:=@p^.code;
  1312. repeat
  1313. c:=ord(codes^);
  1314. inc(codes);
  1315. case c of
  1316. 0 :
  1317. break;
  1318. 1,2,3 :
  1319. begin
  1320. inc(codes,c);
  1321. inc(len,c);
  1322. end;
  1323. 8,9,10 :
  1324. begin
  1325. inc(codes);
  1326. inc(len);
  1327. end;
  1328. 4,5,6,7 :
  1329. begin
  1330. if opsize=S_W then
  1331. inc(len,2)
  1332. else
  1333. inc(len);
  1334. end;
  1335. 15,
  1336. 12,13,14,
  1337. 16,17,18,
  1338. 20,21,22,
  1339. 40,41,42 :
  1340. inc(len);
  1341. 24,25,26,
  1342. 31,
  1343. 48,49,50 :
  1344. inc(len,2);
  1345. 28,29,30, { we don't have 16 bit immediates code }
  1346. 32,33,34,
  1347. 52,53,54,
  1348. 56,57,58 :
  1349. inc(len,4);
  1350. 192,193,194 :
  1351. if NeedAddrPrefix(c-192) then
  1352. inc(len);
  1353. 208 :
  1354. inc(len);
  1355. 200,
  1356. 201,
  1357. 202,
  1358. 209,
  1359. 210,
  1360. 217,218,219 : ;
  1361. 216 :
  1362. begin
  1363. inc(codes);
  1364. inc(len);
  1365. end;
  1366. 224,225,226 :
  1367. begin
  1368. InternalError(777002);
  1369. end;
  1370. else
  1371. begin
  1372. if (c>=64) and (c<=191) then
  1373. begin
  1374. if not process_ea(oper[(c shr 3) and 7], ea_data, 0) then
  1375. Message(asmw_e_invalid_effective_address)
  1376. else
  1377. inc(len,ea_data.size);
  1378. end
  1379. else
  1380. InternalError(777003);
  1381. end;
  1382. end;
  1383. until false;
  1384. calcsize:=len;
  1385. end;
  1386. procedure taicpu.GenCode(sec:TAsmObjectData);
  1387. {
  1388. * the actual codes (C syntax, i.e. octal):
  1389. * \0 - terminates the code. (Unless it's a literal of course.)
  1390. * \1, \2, \3 - that many literal bytes follow in the code stream
  1391. * \4, \6 - the POP/PUSH (respectively) codes for CS, DS, ES, SS
  1392. * (POP is never used for CS) depending on operand 0
  1393. * \5, \7 - the second byte of POP/PUSH codes for FS, GS, depending
  1394. * on operand 0
  1395. * \10, \11, \12 - a literal byte follows in the code stream, to be added
  1396. * to the register value of operand 0, 1 or 2
  1397. * \17 - encodes the literal byte 0. (Some compilers don't take
  1398. * kindly to a zero byte in the _middle_ of a compile time
  1399. * string constant, so I had to put this hack in.)
  1400. * \14, \15, \16 - a signed byte immediate operand, from operand 0, 1 or 2
  1401. * \20, \21, \22 - a byte immediate operand, from operand 0, 1 or 2
  1402. * \24, \25, \26 - an unsigned byte immediate operand, from operand 0, 1 or 2
  1403. * \30, \31, \32 - a word immediate operand, from operand 0, 1 or 2
  1404. * \34, \35, \36 - select between \3[012] and \4[012] depending on 16/32 bit
  1405. * assembly mode or the address-size override on the operand
  1406. * \37 - a word constant, from the _segment_ part of operand 0
  1407. * \40, \41, \42 - a long immediate operand, from operand 0, 1 or 2
  1408. * \50, \51, \52 - a byte relative operand, from operand 0, 1 or 2
  1409. * \60, \61, \62 - a word relative operand, from operand 0, 1 or 2
  1410. * \64, \65, \66 - select between \6[012] and \7[012] depending on 16/32 bit
  1411. * assembly mode or the address-size override on the operand
  1412. * \70, \71, \72 - a long relative operand, from operand 0, 1 or 2
  1413. * \1ab - a ModRM, calculated on EA in operand a, with the spare
  1414. * field the register value of operand b.
  1415. * \2ab - a ModRM, calculated on EA in operand a, with the spare
  1416. * field equal to digit b.
  1417. * \30x - might be an 0x67 byte, depending on the address size of
  1418. * the memory reference in operand x.
  1419. * \310 - indicates fixed 16-bit address size, i.e. optional 0x67.
  1420. * \311 - indicates fixed 32-bit address size, i.e. optional 0x67.
  1421. * \320 - indicates fixed 16-bit operand size, i.e. optional 0x66.
  1422. * \321 - indicates fixed 32-bit operand size, i.e. optional 0x66.
  1423. * \322 - indicates that this instruction is only valid when the
  1424. * operand size is the default (instruction to disassembler,
  1425. * generates no code in the assembler)
  1426. * \330 - a literal byte follows in the code stream, to be added
  1427. * to the condition code value of the instruction.
  1428. * \340 - reserve <operand 0> bytes of uninitialised storage.
  1429. * Operand 0 had better be a segmentless constant.
  1430. }
  1431. var
  1432. currval : longint;
  1433. currsym : tasmsymbol;
  1434. procedure getvalsym(opidx:longint);
  1435. begin
  1436. case oper[opidx].typ of
  1437. top_ref :
  1438. begin
  1439. currval:=oper[opidx].ref^.offset;
  1440. currsym:=oper[opidx].ref^.symbol;
  1441. end;
  1442. top_const :
  1443. begin
  1444. currval:=longint(oper[opidx].val);
  1445. currsym:=nil;
  1446. end;
  1447. top_symbol :
  1448. begin
  1449. currval:=oper[opidx].symofs;
  1450. currsym:=oper[opidx].sym;
  1451. end;
  1452. else
  1453. Message(asmw_e_immediate_or_reference_expected);
  1454. end;
  1455. end;
  1456. const
  1457. CondVal:array[TAsmCond] of byte=($0,
  1458. $7, $3, $2, $6, $2, $4, $F, $D, $C, $E, $6, $2,
  1459. $3, $7, $3, $5, $E, $C, $D, $F, $1, $B, $9, $5,
  1460. $0, $A, $A, $B, $8, $4);
  1461. var
  1462. c : byte;
  1463. pb,
  1464. codes : pchar;
  1465. bytes : array[0..3] of byte;
  1466. rfield,
  1467. data,s,opidx : longint;
  1468. ea_data : ea;
  1469. begin
  1470. {$ifdef EXTDEBUG}
  1471. { safety check }
  1472. if sec.sects[sec.currsec].datasize<>insoffset then
  1473. internalerror(200130121);
  1474. {$endif EXTDEBUG}
  1475. { load data to write }
  1476. codes:=insentry^.code;
  1477. { Force word push/pop for registers }
  1478. if (opsize=S_W) and ((codes[0]=#4) or (codes[0]=#6) or
  1479. ((codes[0]=#1) and ((codes[2]=#5) or (codes[2]=#7)))) then
  1480. begin
  1481. bytes[0]:=$66;
  1482. sec.writebytes(bytes,1);
  1483. end;
  1484. repeat
  1485. c:=ord(codes^);
  1486. inc(codes);
  1487. case c of
  1488. 0 :
  1489. break;
  1490. 1,2,3 :
  1491. begin
  1492. sec.writebytes(codes^,c);
  1493. inc(codes,c);
  1494. end;
  1495. 4,6 :
  1496. begin
  1497. case oper[0].reg of
  1498. NR_CS:
  1499. bytes[0]:=$e;
  1500. NR_NO,
  1501. NR_DS:
  1502. bytes[0]:=$1e;
  1503. NR_ES:
  1504. bytes[0]:=$6;
  1505. NR_SS:
  1506. bytes[0]:=$16;
  1507. else
  1508. internalerror(777004);
  1509. end;
  1510. if c=4 then
  1511. inc(bytes[0]);
  1512. sec.writebytes(bytes,1);
  1513. end;
  1514. 5,7 :
  1515. begin
  1516. case oper[0].reg of
  1517. NR_FS:
  1518. bytes[0]:=$a0;
  1519. NR_GS:
  1520. bytes[0]:=$a8;
  1521. else
  1522. internalerror(777005);
  1523. end;
  1524. if c=5 then
  1525. inc(bytes[0]);
  1526. sec.writebytes(bytes,1);
  1527. end;
  1528. 8,9,10 :
  1529. begin
  1530. bytes[0]:=ord(codes^)+regval(oper[c-8].reg);
  1531. inc(codes);
  1532. sec.writebytes(bytes,1);
  1533. end;
  1534. 15 :
  1535. begin
  1536. bytes[0]:=0;
  1537. sec.writebytes(bytes,1);
  1538. end;
  1539. 12,13,14 :
  1540. begin
  1541. getvalsym(c-12);
  1542. if (currval<-128) or (currval>127) then
  1543. Message2(asmw_e_value_exceeds_bounds,'signed byte',tostr(currval));
  1544. if assigned(currsym) then
  1545. sec.writereloc(currval,1,currsym,RELOC_ABSOLUTE)
  1546. else
  1547. sec.writebytes(currval,1);
  1548. end;
  1549. 16,17,18 :
  1550. begin
  1551. getvalsym(c-16);
  1552. if (currval<-256) or (currval>255) then
  1553. Message2(asmw_e_value_exceeds_bounds,'byte',tostr(currval));
  1554. if assigned(currsym) then
  1555. sec.writereloc(currval,1,currsym,RELOC_ABSOLUTE)
  1556. else
  1557. sec.writebytes(currval,1);
  1558. end;
  1559. 20,21,22 :
  1560. begin
  1561. getvalsym(c-20);
  1562. if (currval<0) or (currval>255) then
  1563. Message2(asmw_e_value_exceeds_bounds,'unsigned byte',tostr(currval));
  1564. if assigned(currsym) then
  1565. sec.writereloc(currval,1,currsym,RELOC_ABSOLUTE)
  1566. else
  1567. sec.writebytes(currval,1);
  1568. end;
  1569. 24,25,26 :
  1570. begin
  1571. getvalsym(c-24);
  1572. if (currval<-65536) or (currval>65535) then
  1573. Message2(asmw_e_value_exceeds_bounds,'word',tostr(currval));
  1574. if assigned(currsym) then
  1575. sec.writereloc(currval,2,currsym,RELOC_ABSOLUTE)
  1576. else
  1577. sec.writebytes(currval,2);
  1578. end;
  1579. 28,29,30 :
  1580. begin
  1581. getvalsym(c-28);
  1582. if assigned(currsym) then
  1583. sec.writereloc(currval,4,currsym,RELOC_ABSOLUTE)
  1584. else
  1585. sec.writebytes(currval,4);
  1586. end;
  1587. 32,33,34 :
  1588. begin
  1589. getvalsym(c-32);
  1590. if assigned(currsym) then
  1591. sec.writereloc(currval,4,currsym,RELOC_ABSOLUTE)
  1592. else
  1593. sec.writebytes(currval,4);
  1594. end;
  1595. 40,41,42 :
  1596. begin
  1597. getvalsym(c-40);
  1598. data:=currval-insend;
  1599. if assigned(currsym) then
  1600. inc(data,currsym.address);
  1601. if (data>127) or (data<-128) then
  1602. Message1(asmw_e_short_jmp_out_of_range,tostr(data));
  1603. sec.writebytes(data,1);
  1604. end;
  1605. 52,53,54 :
  1606. begin
  1607. getvalsym(c-52);
  1608. if assigned(currsym) then
  1609. sec.writereloc(currval,4,currsym,RELOC_RELATIVE)
  1610. else
  1611. sec.writereloc(currval-insend,4,nil,RELOC_ABSOLUTE)
  1612. end;
  1613. 56,57,58 :
  1614. begin
  1615. getvalsym(c-56);
  1616. if assigned(currsym) then
  1617. sec.writereloc(currval,4,currsym,RELOC_RELATIVE)
  1618. else
  1619. sec.writereloc(currval-insend,4,nil,RELOC_ABSOLUTE)
  1620. end;
  1621. 192,193,194 :
  1622. begin
  1623. if NeedAddrPrefix(c-192) then
  1624. begin
  1625. bytes[0]:=$67;
  1626. sec.writebytes(bytes,1);
  1627. end;
  1628. end;
  1629. 200 :
  1630. begin
  1631. bytes[0]:=$67;
  1632. sec.writebytes(bytes,1);
  1633. end;
  1634. 208 :
  1635. begin
  1636. bytes[0]:=$66;
  1637. sec.writebytes(bytes,1);
  1638. end;
  1639. 216 :
  1640. begin
  1641. bytes[0]:=ord(codes^)+condval[condition];
  1642. inc(codes);
  1643. sec.writebytes(bytes,1);
  1644. end;
  1645. 201,
  1646. 202,
  1647. 209,
  1648. 210,
  1649. 217,218,219 :
  1650. begin
  1651. { these are dissambler hints or 32 bit prefixes which
  1652. are not needed }
  1653. end;
  1654. 31,
  1655. 48,49,50,
  1656. 224,225,226 :
  1657. begin
  1658. InternalError(777006);
  1659. end
  1660. else
  1661. begin
  1662. if (c>=64) and (c<=191) then
  1663. begin
  1664. if (c<127) then
  1665. begin
  1666. if (oper[c and 7].typ=top_reg) then
  1667. rfield:=regval(oper[c and 7].reg)
  1668. else
  1669. rfield:=regval(oper[c and 7].ref^.base);
  1670. end
  1671. else
  1672. rfield:=c and 7;
  1673. opidx:=(c shr 3) and 7;
  1674. if not process_ea(oper[opidx], ea_data, rfield) then
  1675. Message(asmw_e_invalid_effective_address);
  1676. pb:=@bytes;
  1677. pb^:=chr(ea_data.modrm);
  1678. inc(pb);
  1679. if ea_data.sib_present then
  1680. begin
  1681. pb^:=chr(ea_data.sib);
  1682. inc(pb);
  1683. end;
  1684. s:=pb-pchar(@bytes);
  1685. sec.writebytes(bytes,s);
  1686. case ea_data.bytes of
  1687. 0 : ;
  1688. 1 :
  1689. begin
  1690. if (oper[opidx].ot and OT_MEMORY)=OT_MEMORY then
  1691. sec.writereloc(oper[opidx].ref^.offset,1,oper[opidx].ref^.symbol,RELOC_ABSOLUTE)
  1692. else
  1693. begin
  1694. bytes[0]:=oper[opidx].ref^.offset;
  1695. sec.writebytes(bytes,1);
  1696. end;
  1697. inc(s);
  1698. end;
  1699. 2,4 :
  1700. begin
  1701. sec.writereloc(oper[opidx].ref^.offset,ea_data.bytes,
  1702. oper[opidx].ref^.symbol,RELOC_ABSOLUTE);
  1703. inc(s,ea_data.bytes);
  1704. end;
  1705. end;
  1706. end
  1707. else
  1708. InternalError(777007);
  1709. end;
  1710. end;
  1711. until false;
  1712. end;
  1713. {$endif NOAG386BIN}
  1714. function Taicpu.is_nop:boolean;
  1715. begin
  1716. {We do not check the number of operands; we assume that nobody constructs
  1717. a mov or xchg instruction with less than 2 operands. (DM)}
  1718. is_nop:=(opcode=A_NOP) or
  1719. (opcode=A_MOV) and (oper[0].typ=top_reg) and (oper[1].typ=top_reg) and (oper[0].reg=oper[1].reg) or
  1720. (opcode=A_XCHG) and (oper[0].typ=top_reg) and (oper[1].typ=top_reg) and (oper[0].reg=oper[1].reg);
  1721. end;
  1722. function Taicpu.is_move:boolean;
  1723. begin
  1724. {We do not check the number of operands; we assume that nobody constructs
  1725. a mov, movzx or movsx instruction with less than 2 operands. Note that
  1726. a move between a reference and a register is not a move that is of
  1727. interrest to the register allocation, therefore we only return true
  1728. for a move between two registers. (DM)}
  1729. is_move:=((opcode=A_MOV) or (opcode=A_MOVZX) or (opcode=A_MOVSX)) and
  1730. ((oper[0].typ=top_reg) and (oper[1].typ=top_reg));
  1731. end;
  1732. function Taicpu.spill_registers(list:Taasmoutput;
  1733. rgget:Trggetproc;
  1734. rgunget:Trgungetproc;
  1735. r:Tsuperregisterset;
  1736. var unusedregsint:Tsuperregisterset;
  1737. const spilltemplist:Tspill_temp_list):boolean;
  1738. {Spill the registers in r in this instruction. Returns true if any help
  1739. registers are used. This procedure has become one big hack party, because
  1740. of the huge amount of situations you can have. The irregularity of the i386
  1741. instruction set doesn't help either. (DM)}
  1742. var i:byte;
  1743. supreg:Tsuperregister;
  1744. subreg:Tsubregister;
  1745. helpreg:Tregister;
  1746. helpins:Taicpu;
  1747. op:Tasmop;
  1748. hopsize:Topsize;
  1749. pos:Tai;
  1750. begin
  1751. {Situation examples are in intel notation, so operand order:
  1752. mov eax , ebx
  1753. ^^^ ^^^
  1754. oper[1] oper[0]
  1755. (DM)}
  1756. spill_registers:=false;
  1757. case ops of
  1758. 1:
  1759. begin
  1760. if (oper[0].typ=top_reg) and
  1761. (getregtype(oper[0].reg)=R_INTREGISTER) then
  1762. begin
  1763. supreg:=getsupreg(oper[0].reg);
  1764. if supreg in r then
  1765. begin
  1766. {Situation example:
  1767. push r20d ; r20d must be spilled into [ebp-12]
  1768. Change into:
  1769. push [ebp-12] ; Replace register by reference }
  1770. { hopsize:=reg2opsize(oper[0].reg);}
  1771. oper[0].typ:=top_ref;
  1772. new(oper[0].ref);
  1773. oper[0].ref^:=spilltemplist[supreg];
  1774. { oper[0].ref^.size:=hopsize;}
  1775. end;
  1776. end;
  1777. if oper[0].typ=top_ref then
  1778. begin
  1779. supreg:=getsupreg(oper[0].ref^.base);
  1780. if supreg in r then
  1781. begin
  1782. {Situation example:
  1783. push [r21d+4*r22d] ; r21d must be spilled into [ebp-12]
  1784. Change into:
  1785. mov r23d,[ebp-12] ; Use a help register
  1786. push [r23d+4*r22d] ; Replace register by helpregister }
  1787. subreg:=getsubreg(oper[0].ref^.base);
  1788. if oper[0].ref^.index=NR_NO then
  1789. pos:=Tai(previous)
  1790. else
  1791. pos:=get_insert_pos(Tai(previous),getsupreg(oper[0].ref^.index),RS_INVALID,RS_INVALID,unusedregsint);
  1792. rgget(list,pos,subreg,helpreg);
  1793. spill_registers:=true;
  1794. helpins:=Taicpu.op_ref_reg(A_MOV,reg2opsize(oper[0].ref^.base),spilltemplist[supreg],helpreg);
  1795. if pos=nil then
  1796. list.insertafter(helpins,list.first)
  1797. else
  1798. list.insertafter(helpins,pos.next);
  1799. rgunget(list,helpins,helpreg);
  1800. forward_allocation(Tai(helpins.next),unusedregsint);
  1801. oper[0].ref^.base:=helpreg;
  1802. end;
  1803. supreg:=getsupreg(oper[0].ref^.index);
  1804. if supreg in r then
  1805. begin
  1806. {Situation example:
  1807. push [r21d+4*r22d] ; r22d must be spilled into [ebp-12]
  1808. Change into:
  1809. mov r23d,[ebp-12] ; Use a help register
  1810. push [r21d+4*r23d] ; Replace register by helpregister }
  1811. subreg:=getsubreg(oper[0].ref^.index);
  1812. if oper[0].ref^.base=NR_NO then
  1813. pos:=Tai(previous)
  1814. else
  1815. pos:=get_insert_pos(Tai(previous),getsupreg(oper[0].ref^.base),RS_INVALID,RS_INVALID,unusedregsint);
  1816. rgget(list,pos,subreg,helpreg);
  1817. spill_registers:=true;
  1818. helpins:=Taicpu.op_ref_reg(A_MOV,reg2opsize(oper[0].ref^.index),spilltemplist[supreg],helpreg);
  1819. if pos=nil then
  1820. list.insertafter(helpins,list.first)
  1821. else
  1822. list.insertafter(helpins,pos.next);
  1823. rgunget(list,helpins,helpreg);
  1824. forward_allocation(Tai(helpins.next),unusedregsint);
  1825. oper[0].ref^.index:=helpreg;
  1826. end;
  1827. end;
  1828. end;
  1829. 2:
  1830. begin
  1831. { First spill the registers from the references. This is
  1832. required because the reference can be moved from this instruction
  1833. to a MOV instruction when spilling of the register operand is done }
  1834. for i:=0 to 1 do
  1835. if oper[i].typ=top_ref then
  1836. begin
  1837. supreg:=getsupreg(oper[i].ref^.base);
  1838. if supreg in r then
  1839. begin
  1840. {Situation example:
  1841. add r20d,[r21d+4*r22d] ; r21d must be spilled into [ebp-12]
  1842. Change into:
  1843. mov r23d,[ebp-12] ; Use a help register
  1844. add r20d,[r23d+4*r22d] ; Replace register by helpregister }
  1845. subreg:=getsubreg(oper[i].ref^.base);
  1846. if i=1 then
  1847. pos:=get_insert_pos(Tai(previous),getsupreg(oper[i].ref^.index),getsupreg(oper[0].reg),
  1848. RS_INVALID,unusedregsint)
  1849. else
  1850. pos:=get_insert_pos(Tai(previous),getsupreg(oper[i].ref^.index),RS_INVALID,RS_INVALID,unusedregsint);
  1851. rgget(list,pos,subreg,helpreg);
  1852. spill_registers:=true;
  1853. helpins:=Taicpu.op_ref_reg(A_MOV,reg2opsize(oper[i].ref^.base),spilltemplist[supreg],helpreg);
  1854. if pos=nil then
  1855. list.insertafter(helpins,list.first)
  1856. else
  1857. list.insertafter(helpins,pos.next);
  1858. oper[i].ref^.base:=helpreg;
  1859. rgunget(list,helpins,helpreg);
  1860. forward_allocation(Tai(helpins.next),unusedregsint);
  1861. end;
  1862. supreg:=getsupreg(oper[i].ref^.index);
  1863. if supreg in r then
  1864. begin
  1865. {Situation example:
  1866. add r20d,[r21d+4*r22d] ; r22d must be spilled into [ebp-12]
  1867. Change into:
  1868. mov r23d,[ebp-12] ; Use a help register
  1869. add r20d,[r21d+4*r23d] ; Replace register by helpregister }
  1870. subreg:=getsubreg(oper[i].ref^.index);
  1871. if i=1 then
  1872. pos:=get_insert_pos(Tai(previous),getsupreg(oper[i].ref^.base),getsupreg(oper[0].reg),
  1873. RS_INVALID,unusedregsint)
  1874. else
  1875. pos:=get_insert_pos(Tai(previous),getsupreg(oper[i].ref^.base),RS_INVALID,RS_INVALID,unusedregsint);
  1876. rgget(list,pos,subreg,helpreg);
  1877. spill_registers:=true;
  1878. helpins:=Taicpu.op_ref_reg(A_MOV,reg2opsize(oper[i].ref^.index),spilltemplist[supreg],helpreg);
  1879. if pos=nil then
  1880. list.insertafter(helpins,list.first)
  1881. else
  1882. list.insertafter(helpins,pos.next);
  1883. oper[i].ref^.index:=helpreg;
  1884. rgunget(list,helpins,helpreg);
  1885. forward_allocation(Tai(helpins.next),unusedregsint);
  1886. end;
  1887. end;
  1888. if (oper[0].typ=top_reg) and
  1889. (getregtype(oper[0].reg)=R_INTREGISTER) then
  1890. begin
  1891. supreg:=getsupreg(oper[0].reg);
  1892. subreg:=getsubreg(oper[0].reg);
  1893. if supreg in r then
  1894. if oper[1].typ=top_ref then
  1895. begin
  1896. {Situation example:
  1897. add [r20d],r21d ; r21d must be spilled into [ebp-12]
  1898. Change into:
  1899. mov r22d,[ebp-12] ; Use a help register
  1900. add [r20d],r22d ; Replace register by helpregister }
  1901. pos:=get_insert_pos(Tai(previous),getsupreg(oper[0].reg),
  1902. getsupreg(oper[1].ref^.base),getsupreg(oper[1].ref^.index),
  1903. unusedregsint);
  1904. rgget(list,pos,subreg,helpreg);
  1905. spill_registers:=true;
  1906. helpins:=Taicpu.op_ref_reg(A_MOV,reg2opsize(oper[0].reg),spilltemplist[supreg],helpreg);
  1907. if pos=nil then
  1908. list.insertafter(helpins,list.first)
  1909. else
  1910. list.insertafter(helpins,pos.next);
  1911. oper[0].reg:=helpreg;
  1912. rgunget(list,helpins,helpreg);
  1913. forward_allocation(Tai(helpins.next),unusedregsint);
  1914. end
  1915. else
  1916. begin
  1917. {Situation example:
  1918. add r20d,r21d ; r21d must be spilled into [ebp-12]
  1919. Change into:
  1920. add r20d,[ebp-12] ; Replace register by reference }
  1921. oper[0].typ:=top_ref;
  1922. new(oper[0].ref);
  1923. oper[0].ref^:=spilltemplist[supreg];
  1924. end;
  1925. end;
  1926. if (oper[1].typ=top_reg) and
  1927. (getregtype(oper[1].reg)=R_INTREGISTER) then
  1928. begin
  1929. supreg:=getsupreg(oper[1].reg);
  1930. subreg:=getsubreg(oper[1].reg);
  1931. if supreg in r then
  1932. begin
  1933. if oper[0].typ=top_ref then
  1934. begin
  1935. {Situation example:
  1936. add r20d,[r21d] ; r20d must be spilled into [ebp-12]
  1937. Change into:
  1938. mov r22d,[r21d] ; Use a help register
  1939. add [ebp-12],r22d ; Replace register by helpregister }
  1940. pos:=get_insert_pos(Tai(previous),getsupreg(oper[0].ref^.base),
  1941. getsupreg(oper[0].ref^.index),RS_INVALID,unusedregsint);
  1942. rgget(list,pos,subreg,helpreg);
  1943. spill_registers:=true;
  1944. op:=A_MOV;
  1945. hopsize:=opsize; {Save old value...}
  1946. if (opcode=A_MOVZX) or (opcode=A_MOVSX) or (opcode=A_LEA) then
  1947. begin
  1948. {Because 'movzx memory,register' does not exist...}
  1949. op:=opcode;
  1950. opcode:=A_MOV;
  1951. opsize:=reg2opsize(oper[1].reg);
  1952. end;
  1953. helpins:=Taicpu.op_ref_reg(op,hopsize,oper[0].ref^,helpreg);
  1954. if pos=nil then
  1955. list.insertafter(helpins,list.first)
  1956. else
  1957. list.insertafter(helpins,pos.next);
  1958. dispose(oper[0].ref);
  1959. oper[0].typ:=top_reg;
  1960. oper[0].reg:=helpreg;
  1961. oper[1].typ:=top_ref;
  1962. new(oper[1].ref);
  1963. oper[1].ref^:=spilltemplist[supreg];
  1964. rgunget(list,helpins,helpreg);
  1965. forward_allocation(Tai(helpins.next),unusedregsint);
  1966. end
  1967. else
  1968. begin
  1969. {Situation example:
  1970. add r20d,r21d ; r20d must be spilled into [ebp-12]
  1971. Change into:
  1972. add [ebp-12],r21d ; Replace register by reference }
  1973. if (opcode=A_MOVZX) or (opcode=A_MOVSX) then
  1974. begin
  1975. {Because 'movzx memory,register' does not exist...}
  1976. spill_registers:=true;
  1977. op:=opcode;
  1978. hopsize:=opsize;
  1979. opcode:=A_MOV;
  1980. opsize:=reg2opsize(oper[1].reg);
  1981. pos:=get_insert_pos(Tai(previous),getsupreg(oper[0].reg),RS_INVALID,RS_INVALID,unusedregsint);
  1982. rgget(list,pos,subreg,helpreg);
  1983. helpins:=Taicpu.op_reg_reg(op,hopsize,oper[0].reg,helpreg);
  1984. if pos=nil then
  1985. list.insertafter(helpins,list.first)
  1986. else
  1987. list.insertafter(helpins,pos.next);
  1988. oper[0].reg:=helpreg;
  1989. rgunget(list,helpins,helpreg);
  1990. forward_allocation(Tai(helpins.next),unusedregsint);
  1991. end;
  1992. oper[1].typ:=top_ref;
  1993. new(oper[1].ref);
  1994. oper[1].ref^:=spilltemplist[supreg];
  1995. end;
  1996. end;
  1997. end;
  1998. { The i386 instruction set never gets boring...
  1999. some opcodes do not support a memory location as destination }
  2000. if (oper[1].typ=top_ref) and
  2001. (
  2002. (oper[0].typ=top_const) or
  2003. ((oper[0].typ=top_reg) and
  2004. (getregtype(oper[0].reg)=R_INTREGISTER))
  2005. ) then
  2006. begin
  2007. case opcode of
  2008. A_IMUL :
  2009. begin
  2010. {Yikes! We just changed the destination register into
  2011. a memory location above here.
  2012. Situation examples:
  2013. imul [ebp-12],r21d ; We need a help register
  2014. imul [ebp-12],<const> ; We need a help register
  2015. Change into:
  2016. mov r22d,[ebp-12] ; Use a help instruction (only for IMUL)
  2017. imul r22d,r21d ; Replace reference by helpregister
  2018. mov [ebp-12],r22d ; Use another help instruction}
  2019. rgget(list,Tai(previous),subreg,helpreg);
  2020. spill_registers:=true;
  2021. {First help instruction.}
  2022. helpins:=Taicpu.op_ref_reg(A_MOV,opsize,oper[1].ref^,helpreg);
  2023. if previous=nil then
  2024. list.insert(helpins)
  2025. else
  2026. list.insertafter(helpins,previous);
  2027. {Second help instruction.}
  2028. helpins:=Taicpu.op_reg_ref(A_MOV,opsize,helpreg,oper[1].ref^);
  2029. dispose(oper[1].ref);
  2030. oper[1].typ:=top_reg;
  2031. oper[1].reg:=helpreg;
  2032. list.insertafter(helpins,self);
  2033. rgunget(list,self,helpreg);
  2034. end;
  2035. end;
  2036. end;
  2037. { The i386 instruction set never gets boring...
  2038. some opcodes do not support a memory location as source }
  2039. if (oper[0].typ=top_ref) and
  2040. (oper[1].typ=top_reg) and
  2041. (getregtype(oper[1].reg)=R_INTREGISTER) then
  2042. begin
  2043. case opcode of
  2044. A_BT,A_BTS,
  2045. A_BTC,A_BTR :
  2046. begin
  2047. {Yikes! We just changed the source register into
  2048. a memory location above here.
  2049. Situation example:
  2050. bt r21d,[ebp-12] ; We need a help register
  2051. Change into:
  2052. mov r22d,[ebp-12] ; Use a help instruction (only for IMUL)
  2053. bt r21d,r22d ; Replace reference by helpregister}
  2054. rgget(list,Tai(previous),subreg,helpreg);
  2055. spill_registers:=true;
  2056. {First help instruction.}
  2057. helpins:=Taicpu.op_ref_reg(A_MOV,opsize,oper[0].ref^,helpreg);
  2058. if previous=nil then
  2059. list.insert(helpins)
  2060. else
  2061. list.insertafter(helpins,previous);
  2062. dispose(oper[0].ref);
  2063. oper[0].typ:=top_reg;
  2064. oper[0].reg:=helpreg;
  2065. rgunget(list,helpins,helpreg);
  2066. end;
  2067. end;
  2068. end;
  2069. end;
  2070. 3:
  2071. begin
  2072. {$warning todo!!}
  2073. end;
  2074. end;
  2075. end;
  2076. {*****************************************************************************
  2077. Instruction table
  2078. *****************************************************************************}
  2079. procedure BuildInsTabCache;
  2080. {$ifndef NOAG386BIN}
  2081. var
  2082. i : longint;
  2083. {$endif}
  2084. begin
  2085. {$ifndef NOAG386BIN}
  2086. new(instabcache);
  2087. FillChar(instabcache^,sizeof(tinstabcache),$ff);
  2088. i:=0;
  2089. while (i<InsTabEntries) do
  2090. begin
  2091. if InsTabCache^[InsTab[i].OPcode]=-1 then
  2092. InsTabCache^[InsTab[i].OPcode]:=i;
  2093. inc(i);
  2094. end;
  2095. {$endif NOAG386BIN}
  2096. end;
  2097. procedure InitAsm;
  2098. begin
  2099. {$ifndef NOAG386BIN}
  2100. if not assigned(instabcache) then
  2101. BuildInsTabCache;
  2102. {$endif NOAG386BIN}
  2103. end;
  2104. procedure DoneAsm;
  2105. begin
  2106. {$ifndef NOAG386BIN}
  2107. if assigned(instabcache) then
  2108. begin
  2109. dispose(instabcache);
  2110. instabcache:=nil;
  2111. end;
  2112. {$endif NOAG386BIN}
  2113. end;
  2114. end.
  2115. {
  2116. $Log$
  2117. Revision 1.29 2003-09-29 20:58:56 peter
  2118. * optimized releasing of registers
  2119. Revision 1.28 2003/09/28 21:49:30 peter
  2120. * fixed invalid opcode handling in spill registers
  2121. Revision 1.27 2003/09/28 13:37:07 peter
  2122. * give error for wrong register number
  2123. Revision 1.26 2003/09/24 21:15:49 florian
  2124. * fixed make cycle
  2125. Revision 1.25 2003/09/24 17:12:36 florian
  2126. * x86-64 adaptions
  2127. Revision 1.24 2003/09/23 17:56:06 peter
  2128. * locals and paras are allocated in the code generation
  2129. * tvarsym.localloc contains the location of para/local when
  2130. generating code for the current procedure
  2131. Revision 1.23 2003/09/14 14:22:51 daniel
  2132. * Fixed incorrect movzx spilling
  2133. Revision 1.22 2003/09/12 20:25:17 daniel
  2134. * Add BTR to destination memory location check in spilling
  2135. Revision 1.21 2003/09/10 19:14:31 daniel
  2136. * Failed attempt to restore broken fastspill functionality
  2137. Revision 1.20 2003/09/10 11:23:09 marco
  2138. * fix from peter for bts reg32,mem32 problem
  2139. Revision 1.19 2003/09/09 12:54:45 florian
  2140. * x86 instruction table updated to nasm 0.98.37:
  2141. - sse3 aka prescott support
  2142. - small fixes
  2143. Revision 1.18 2003/09/07 22:09:35 peter
  2144. * preparations for different default calling conventions
  2145. * various RA fixes
  2146. Revision 1.17 2003/09/03 15:55:02 peter
  2147. * NEWRA branch merged
  2148. Revision 1.16.2.4 2003/08/31 15:46:26 peter
  2149. * more updates for tregister
  2150. Revision 1.16.2.3 2003/08/29 17:29:00 peter
  2151. * next batch of updates
  2152. Revision 1.16.2.2 2003/08/28 18:35:08 peter
  2153. * tregister changed to cardinal
  2154. Revision 1.16.2.1 2003/08/27 19:55:54 peter
  2155. * first tregister patch
  2156. Revision 1.16 2003/08/21 17:20:19 peter
  2157. * first spill the registers of top_ref before spilling top_reg
  2158. Revision 1.15 2003/08/21 14:48:36 peter
  2159. * fix reg-supreg range check error
  2160. Revision 1.14 2003/08/20 16:52:01 daniel
  2161. * Some old register convention code removed
  2162. * A few changes to eliminate a few lines of code
  2163. Revision 1.13 2003/08/20 09:07:00 daniel
  2164. * New register coding now mandatory, some more convert_registers calls
  2165. removed.
  2166. Revision 1.12 2003/08/20 07:48:04 daniel
  2167. * Made internal assembler use new register coding
  2168. Revision 1.11 2003/08/19 13:58:33 daniel
  2169. * Corrected a comment.
  2170. Revision 1.10 2003/08/15 14:44:20 daniel
  2171. * Fixed newra compilation
  2172. Revision 1.9 2003/08/11 21:18:20 peter
  2173. * start of sparc support for newra
  2174. Revision 1.8 2003/08/09 18:56:54 daniel
  2175. * cs_regalloc renamed to cs_regvars to avoid confusion with register
  2176. allocator
  2177. * Some preventive changes to i386 spillinh code
  2178. Revision 1.7 2003/07/06 15:31:21 daniel
  2179. * Fixed register allocator. *Lots* of fixes.
  2180. Revision 1.6 2003/06/14 14:53:50 jonas
  2181. * fixed newra cycle for x86
  2182. * added constants for indicating source and destination operands of the
  2183. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  2184. Revision 1.5 2003/06/03 13:01:59 daniel
  2185. * Register allocator finished
  2186. Revision 1.4 2003/05/30 23:57:08 peter
  2187. * more sparc cleanup
  2188. * accumulator removed, splitted in function_return_reg (called) and
  2189. function_result_reg (caller)
  2190. Revision 1.3 2003/05/22 21:33:31 peter
  2191. * removed some unit dependencies
  2192. Revision 1.2 2002/04/25 16:12:09 florian
  2193. * fixed more problems with cpubase and x86-64
  2194. Revision 1.1 2003/04/25 12:43:40 florian
  2195. * merged i386/aasmcpu and x86_64/aasmcpu to x86/aasmcpu
  2196. Revision 1.18 2003/04/25 12:04:31 florian
  2197. * merged agx64att and ag386att to x86/agx86att
  2198. Revision 1.17 2003/04/22 14:33:38 peter
  2199. * removed some notes/hints
  2200. Revision 1.16 2003/04/22 10:09:35 daniel
  2201. + Implemented the actual register allocator
  2202. + Scratch registers unavailable when new register allocator used
  2203. + maybe_save/maybe_restore unavailable when new register allocator used
  2204. Revision 1.15 2003/03/26 12:50:54 armin
  2205. * avoid problems with the ide in init/dome
  2206. Revision 1.14 2003/03/08 08:59:07 daniel
  2207. + $define newra will enable new register allocator
  2208. + getregisterint will return imaginary registers with $newra
  2209. + -sr switch added, will skip register allocation so you can see
  2210. the direct output of the code generator before register allocation
  2211. Revision 1.13 2003/02/25 07:41:54 daniel
  2212. * Properly fixed reversed operands bug
  2213. Revision 1.12 2003/02/19 22:00:15 daniel
  2214. * Code generator converted to new register notation
  2215. - Horribily outdated todo.txt removed
  2216. Revision 1.11 2003/01/09 20:40:59 daniel
  2217. * Converted some code in cgx86.pas to new register numbering
  2218. Revision 1.10 2003/01/08 18:43:57 daniel
  2219. * Tregister changed into a record
  2220. Revision 1.9 2003/01/05 13:36:53 florian
  2221. * x86-64 compiles
  2222. + very basic support for float128 type (x86-64 only)
  2223. Revision 1.8 2002/11/17 16:31:58 carl
  2224. * memory optimization (3-4%) : cleanup of tai fields,
  2225. cleanup of tdef and tsym fields.
  2226. * make it work for m68k
  2227. Revision 1.7 2002/11/15 01:58:54 peter
  2228. * merged changes from 1.0.7 up to 04-11
  2229. - -V option for generating bug report tracing
  2230. - more tracing for option parsing
  2231. - errors for cdecl and high()
  2232. - win32 import stabs
  2233. - win32 records<=8 are returned in eax:edx (turned off by default)
  2234. - heaptrc update
  2235. - more info for temp management in .s file with EXTDEBUG
  2236. Revision 1.6 2002/10/31 13:28:32 pierre
  2237. * correct last wrong fix for tw2158
  2238. Revision 1.5 2002/10/30 17:10:00 pierre
  2239. * merge of fix for tw2158 bug
  2240. Revision 1.4 2002/08/15 19:10:36 peter
  2241. * first things tai,tnode storing in ppu
  2242. Revision 1.3 2002/08/13 18:01:52 carl
  2243. * rename swatoperands to swapoperands
  2244. + m68k first compilable version (still needs a lot of testing):
  2245. assembler generator, system information , inline
  2246. assembler reader.
  2247. Revision 1.2 2002/07/20 11:57:59 florian
  2248. * types.pas renamed to defbase.pas because D6 contains a types
  2249. unit so this would conflicts if D6 programms are compiled
  2250. + Willamette/SSE2 instructions to assembler added
  2251. Revision 1.1 2002/07/01 18:46:29 peter
  2252. * internal linker
  2253. * reorganized aasm layer
  2254. }