aasmcpu.pas 85 KB

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