aasmcpu.pas 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  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. symppu,
  28. aasmbase,aasmtai;
  29. const
  30. { Operand types }
  31. OT_NONE = $00000000;
  32. OT_BITS8 = $00000001; { size, and other attributes, of the operand }
  33. OT_BITS16 = $00000002;
  34. OT_BITS32 = $00000004;
  35. OT_BITS64 = $00000008; { FPU only }
  36. OT_BITS80 = $00000010;
  37. OT_FAR = $00000020; { this means 16:16 or 16:32, like in CALL/JMP }
  38. OT_NEAR = $00000040;
  39. OT_SHORT = $00000080;
  40. OT_SIZE_MASK = $000000FF; { all the size attributes }
  41. OT_NON_SIZE = longint(not OT_SIZE_MASK);
  42. OT_SIGNED = $00000100; { the operand need to be signed -128-127 }
  43. OT_TO = $00000200; { operand is followed by a colon }
  44. { reverse effect in FADD, FSUB &c }
  45. OT_COLON = $00000400;
  46. OT_REGISTER = $00001000;
  47. OT_IMMEDIATE = $00002000;
  48. OT_IMM8 = $00002001;
  49. OT_IMM16 = $00002002;
  50. OT_IMM32 = $00002004;
  51. OT_IMM64 = $00002008;
  52. OT_IMM80 = $00002010;
  53. OT_REGMEM = $00200000; { for r/m, ie EA, operands }
  54. OT_REGNORM = $00201000; { 'normal' reg, qualifies as EA }
  55. OT_REG8 = $00201001;
  56. OT_REG16 = $00201002;
  57. OT_REG32 = $00201004;
  58. OT_MMXREG = $00201008; { MMX registers }
  59. OT_XMMREG = $00201010; { Katmai registers }
  60. OT_MEMORY = $00204000; { register number in 'basereg' }
  61. OT_MEM8 = $00204001;
  62. OT_MEM16 = $00204002;
  63. OT_MEM32 = $00204004;
  64. OT_MEM64 = $00204008;
  65. OT_MEM80 = $00204010;
  66. OT_FPUREG = $01000000; { floating point stack registers }
  67. OT_FPU0 = $01000800; { FPU stack register zero }
  68. OT_REG_SMASK = $00070000; { special register operands: these may be treated differently }
  69. { a mask for the following }
  70. OT_REG_ACCUM = $00211000; { accumulator: AL, AX or EAX }
  71. OT_REG_AL = $00211001; { REG_ACCUM | BITSxx }
  72. OT_REG_AX = $00211002; { ditto }
  73. OT_REG_EAX = $00211004; { and again }
  74. OT_REG_COUNT = $00221000; { counter: CL, CX or ECX }
  75. OT_REG_CL = $00221001; { REG_COUNT | BITSxx }
  76. OT_REG_CX = $00221002; { ditto }
  77. OT_REG_ECX = $00221004; { another one }
  78. OT_REG_DX = $00241002;
  79. OT_REG_SREG = $00081002; { any segment register }
  80. OT_REG_CS = $01081002; { CS }
  81. OT_REG_DESS = $02081002; { DS, ES, SS (non-CS 86 registers) }
  82. OT_REG_FSGS = $04081002; { FS, GS (386 extended registers) }
  83. OT_REG_CDT = $00101004; { CRn, DRn and TRn }
  84. OT_REG_CREG = $08101004; { CRn }
  85. OT_REG_CR4 = $08101404; { CR4 (Pentium only) }
  86. OT_REG_DREG = $10101004; { DRn }
  87. OT_REG_TREG = $20101004; { TRn }
  88. OT_MEM_OFFS = $00604000; { special type of EA }
  89. { simple [address] offset }
  90. OT_ONENESS = $00800000; { special type of immediate operand }
  91. { so UNITY == IMMEDIATE | ONENESS }
  92. OT_UNITY = $00802000; { for shift/rotate instructions }
  93. { Size of the instruction table converted by nasmconv.pas }
  94. instabentries = {$i i386nop.inc}
  95. maxinfolen = 8;
  96. type
  97. TOperandOrder = (op_intel,op_att);
  98. tinsentry=packed record
  99. opcode : tasmop;
  100. ops : byte;
  101. optypes : array[0..2] of longint;
  102. code : array[0..maxinfolen] of char;
  103. flags : longint;
  104. end;
  105. pinsentry=^tinsentry;
  106. { alignment for operator }
  107. tai_align = class(tai_align_abstract)
  108. reg : tregister;
  109. constructor create(b:byte);
  110. constructor create_op(b: byte; _op: byte);
  111. function calculatefillbuf(var buf : tfillbuffer):pchar;override;
  112. end;
  113. taicpu = class(taicpu_abstract)
  114. opsize : topsize;
  115. constructor op_none(op : tasmop;_size : topsize);
  116. constructor op_reg(op : tasmop;_size : topsize;_op1 : tregister);
  117. constructor op_const(op : tasmop;_size : topsize;_op1 : aword);
  118. constructor op_ref(op : tasmop;_size : topsize;const _op1 : treference);
  119. constructor op_reg_reg(op : tasmop;_size : topsize;_op1,_op2 : tregister);
  120. constructor op_reg_ref(op : tasmop;_size : topsize;_op1 : tregister;const _op2 : treference);
  121. constructor op_reg_const(op:tasmop; _size: topsize; _op1: tregister; _op2: aword);
  122. constructor op_const_reg(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister);
  123. constructor op_const_const(op : tasmop;_size : topsize;_op1,_op2 : aword);
  124. constructor op_const_ref(op : tasmop;_size : topsize;_op1 : aword;const _op2 : treference);
  125. constructor op_ref_reg(op : tasmop;_size : topsize;const _op1 : treference;_op2 : tregister);
  126. constructor op_reg_reg_reg(op : tasmop;_size : topsize;_op1,_op2,_op3 : tregister);
  127. constructor op_const_reg_reg(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister;_op3 : tregister);
  128. constructor op_const_ref_reg(op : tasmop;_size : topsize;_op1 : aword;const _op2 : treference;_op3 : tregister);
  129. constructor op_reg_reg_ref(op : tasmop;_size : topsize;_op1,_op2 : tregister; const _op3 : treference);
  130. constructor op_const_reg_ref(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister;const _op3 : treference);
  131. { this is for Jmp instructions }
  132. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_size : topsize;_op1 : tasmsymbol);
  133. constructor op_sym(op : tasmop;_size : topsize;_op1 : tasmsymbol);
  134. constructor op_sym_ofs(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint);
  135. constructor op_sym_ofs_reg(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;_op2 : tregister);
  136. constructor op_sym_ofs_ref(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  137. procedure changeopsize(siz:topsize);
  138. function GetString:string;
  139. procedure CheckNonCommutativeOpcodes;
  140. private
  141. FOperandOrder : TOperandOrder;
  142. procedure init(_size : topsize); { this need to be called by all constructor }
  143. {$ifndef NOAG386BIN}
  144. public
  145. { the next will reset all instructions that can change in pass 2 }
  146. procedure ResetPass1;
  147. procedure ResetPass2;
  148. function CheckIfValid:boolean;
  149. function Pass1(offset:longint):longint;virtual;
  150. procedure Pass2(sec:TAsmObjectdata);virtual;
  151. procedure SetOperandOrder(order:TOperandOrder);
  152. protected
  153. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);override;
  154. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);override;
  155. procedure ppuderefoper(var o:toper);override;
  156. private
  157. { next fields are filled in pass1, so pass2 is faster }
  158. insentry : PInsEntry;
  159. insoffset,
  160. inssize : longint;
  161. LastInsOffset : longint; { need to be public to be reset }
  162. function InsEnd:longint;
  163. procedure create_ot;
  164. function Matches(p:PInsEntry):longint;
  165. function calcsize(p:PInsEntry):longint;
  166. procedure gencode(sec:TAsmObjectData);
  167. function NeedAddrPrefix(opidx:byte):boolean;
  168. procedure Swapoperands;
  169. {$endif NOAG386BIN}
  170. end;
  171. procedure InitAsm;
  172. procedure DoneAsm;
  173. implementation
  174. uses
  175. cutils,
  176. ag386att;
  177. {*****************************************************************************
  178. Instruction table
  179. *****************************************************************************}
  180. const
  181. {Instruction flags }
  182. IF_NONE = $00000000;
  183. IF_SM = $00000001; { size match first two operands }
  184. IF_SM2 = $00000002;
  185. IF_SB = $00000004; { unsized operands can't be non-byte }
  186. IF_SW = $00000008; { unsized operands can't be non-word }
  187. IF_SD = $00000010; { unsized operands can't be nondword }
  188. IF_AR0 = $00000020; { SB, SW, SD applies to argument 0 }
  189. IF_AR1 = $00000040; { SB, SW, SD applies to argument 1 }
  190. IF_AR2 = $00000060; { SB, SW, SD applies to argument 2 }
  191. IF_ARMASK = $00000060; { mask for unsized argument spec }
  192. IF_PRIV = $00000100; { it's a privileged instruction }
  193. IF_SMM = $00000200; { it's only valid in SMM }
  194. IF_PROT = $00000400; { it's protected mode only }
  195. IF_UNDOC = $00001000; { it's an undocumented instruction }
  196. IF_FPU = $00002000; { it's an FPU instruction }
  197. IF_MMX = $00004000; { it's an MMX instruction }
  198. { it's a 3DNow! instruction }
  199. IF_3DNOW = $00008000;
  200. { it's a SSE (KNI, MMX2) instruction }
  201. IF_SSE = $00010000;
  202. { SSE2 instructions }
  203. IF_SSE2 = $00020000;
  204. { the mask for processor types }
  205. IF_PMASK = longint($FF000000);
  206. { the mask for disassembly "prefer" }
  207. IF_PFMASK = longint($F001FF00);
  208. IF_8086 = $00000000; { 8086 instruction }
  209. IF_186 = $01000000; { 186+ instruction }
  210. IF_286 = $02000000; { 286+ instruction }
  211. IF_386 = $03000000; { 386+ instruction }
  212. IF_486 = $04000000; { 486+ instruction }
  213. IF_PENT = $05000000; { Pentium instruction }
  214. IF_P6 = $06000000; { P6 instruction }
  215. IF_KATMAI = $07000000; { Katmai instructions }
  216. { Willamette instructions }
  217. IF_WILLAMETTE = $08000000;
  218. IF_CYRIX = $10000000; { Cyrix-specific instruction }
  219. IF_AMD = $20000000; { AMD-specific instruction }
  220. { added flags }
  221. IF_PRE = $40000000; { it's a prefix instruction }
  222. IF_PASS2 = longint($80000000); { if the instruction can change in a second pass }
  223. type
  224. TInsTabCache=array[TasmOp] of longint;
  225. PInsTabCache=^TInsTabCache;
  226. const
  227. InsTab:array[0..instabentries-1] of TInsEntry={$i i386tab.inc}
  228. var
  229. InsTabCache : PInsTabCache;
  230. const
  231. { Intel style operands ! }
  232. opsize_2_type:array[0..2,topsize] of longint=(
  233. (OT_NONE,
  234. OT_BITS8,OT_BITS16,OT_BITS32,OT_BITS16,OT_BITS32,OT_BITS32,
  235. OT_BITS16,OT_BITS32,OT_BITS64,
  236. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,OT_NONE,
  237. OT_NEAR,OT_FAR,OT_SHORT
  238. ),
  239. (OT_NONE,
  240. OT_BITS8,OT_BITS16,OT_BITS32,OT_BITS8,OT_BITS8,OT_BITS16,
  241. OT_BITS16,OT_BITS32,OT_BITS64,
  242. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,OT_NONE,
  243. OT_NEAR,OT_FAR,OT_SHORT
  244. ),
  245. (OT_NONE,
  246. OT_BITS8,OT_BITS16,OT_BITS32,OT_NONE,OT_NONE,OT_NONE,
  247. OT_BITS16,OT_BITS32,OT_BITS64,
  248. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,OT_NONE,
  249. OT_NEAR,OT_FAR,OT_SHORT
  250. )
  251. );
  252. { Convert reg to operand type }
  253. reg2type : array[firstreg..lastreg] of longint = (OT_NONE,
  254. OT_REG_EAX,OT_REG_ECX,OT_REG32,OT_REG32,OT_REG32,OT_REG32,OT_REG32,OT_REG32,
  255. OT_REG_AX,OT_REG_CX,OT_REG_DX,OT_REG16,OT_REG16,OT_REG16,OT_REG16,OT_REG16,
  256. OT_REG_AL,OT_REG_CL,OT_REG8,OT_REG8,OT_REG8,OT_REG8,OT_REG8,OT_REG8,
  257. OT_REG_CS,OT_REG_DESS,OT_REG_DESS,OT_REG_DESS,OT_REG_FSGS,OT_REG_FSGS,
  258. OT_FPU0,OT_FPU0,OT_FPUREG,OT_FPUREG,OT_FPUREG,OT_FPUREG,OT_FPUREG,OT_FPUREG,OT_FPUREG,
  259. OT_REG_DREG,OT_REG_DREG,OT_REG_DREG,OT_REG_DREG,OT_REG_DREG,OT_REG_DREG,
  260. OT_REG_CREG,OT_REG_CREG,OT_REG_CREG,OT_REG_CR4,
  261. OT_REG_TREG,OT_REG_TREG,OT_REG_TREG,OT_REG_TREG,OT_REG_TREG,
  262. OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,
  263. OT_XMMREG,OT_XMMREG,OT_XMMREG,OT_XMMREG,OT_XMMREG,OT_XMMREG,OT_XMMREG,OT_XMMREG
  264. );
  265. {****************************************************************************
  266. TAI_ALIGN
  267. ****************************************************************************}
  268. constructor tai_align.create(b: byte);
  269. begin
  270. inherited create(b);
  271. reg := R_ECX;
  272. end;
  273. constructor tai_align.create_op(b: byte; _op: byte);
  274. begin
  275. inherited create_op(b,_op);
  276. reg := R_NO;
  277. end;
  278. function tai_align.calculatefillbuf(var buf : tfillbuffer):pchar;
  279. const
  280. alignarray:array[0..5] of string[8]=(
  281. #$8D#$B4#$26#$00#$00#$00#$00,
  282. #$8D#$B6#$00#$00#$00#$00,
  283. #$8D#$74#$26#$00,
  284. #$8D#$76#$00,
  285. #$89#$F6,
  286. #$90
  287. );
  288. var
  289. bufptr : pchar;
  290. j : longint;
  291. begin
  292. inherited calculatefillbuf(buf);
  293. if not use_op then
  294. begin
  295. bufptr:=pchar(@buf);
  296. while (fillsize>0) do
  297. begin
  298. for j:=0 to 5 do
  299. if (fillsize>=length(alignarray[j])) then
  300. break;
  301. move(alignarray[j][1],bufptr^,length(alignarray[j]));
  302. inc(bufptr,length(alignarray[j]));
  303. dec(fillsize,length(alignarray[j]));
  304. end;
  305. end;
  306. calculatefillbuf:=pchar(@buf);
  307. end;
  308. {*****************************************************************************
  309. Taicpu Constructors
  310. *****************************************************************************}
  311. procedure taicpu.changeopsize(siz:topsize);
  312. begin
  313. opsize:=siz;
  314. end;
  315. procedure taicpu.init(_size : topsize);
  316. begin
  317. { default order is att }
  318. FOperandOrder:=op_att;
  319. segprefix:=R_NO;
  320. opsize:=_size;
  321. {$ifndef NOAG386BIN}
  322. insentry:=nil;
  323. LastInsOffset:=-1;
  324. InsOffset:=0;
  325. InsSize:=0;
  326. {$endif}
  327. end;
  328. constructor taicpu.op_none(op : tasmop;_size : topsize);
  329. begin
  330. inherited create(op);
  331. init(_size);
  332. end;
  333. constructor taicpu.op_reg(op : tasmop;_size : topsize;_op1 : tregister);
  334. begin
  335. inherited create(op);
  336. init(_size);
  337. ops:=1;
  338. loadreg(0,_op1);
  339. end;
  340. constructor taicpu.op_const(op : tasmop;_size : topsize;_op1 : aword);
  341. begin
  342. inherited create(op);
  343. init(_size);
  344. ops:=1;
  345. loadconst(0,_op1);
  346. end;
  347. constructor taicpu.op_ref(op : tasmop;_size : topsize;const _op1 : treference);
  348. begin
  349. inherited create(op);
  350. init(_size);
  351. ops:=1;
  352. loadref(0,_op1);
  353. end;
  354. constructor taicpu.op_reg_reg(op : tasmop;_size : topsize;_op1,_op2 : tregister);
  355. begin
  356. inherited create(op);
  357. init(_size);
  358. ops:=2;
  359. loadreg(0,_op1);
  360. loadreg(1,_op2);
  361. end;
  362. constructor taicpu.op_reg_const(op:tasmop; _size: topsize; _op1: tregister; _op2: aword);
  363. begin
  364. inherited create(op);
  365. init(_size);
  366. ops:=2;
  367. loadreg(0,_op1);
  368. loadconst(1,_op2);
  369. end;
  370. constructor taicpu.op_reg_ref(op : tasmop;_size : topsize;_op1 : tregister;const _op2 : treference);
  371. begin
  372. inherited create(op);
  373. init(_size);
  374. ops:=2;
  375. loadreg(0,_op1);
  376. loadref(1,_op2);
  377. end;
  378. constructor taicpu.op_const_reg(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister);
  379. begin
  380. inherited create(op);
  381. init(_size);
  382. ops:=2;
  383. loadconst(0,_op1);
  384. loadreg(1,_op2);
  385. end;
  386. constructor taicpu.op_const_const(op : tasmop;_size : topsize;_op1,_op2 : aword);
  387. begin
  388. inherited create(op);
  389. init(_size);
  390. ops:=2;
  391. loadconst(0,_op1);
  392. loadconst(1,_op2);
  393. end;
  394. constructor taicpu.op_const_ref(op : tasmop;_size : topsize;_op1 : aword;const _op2 : treference);
  395. begin
  396. inherited create(op);
  397. init(_size);
  398. ops:=2;
  399. loadconst(0,_op1);
  400. loadref(1,_op2);
  401. end;
  402. constructor taicpu.op_ref_reg(op : tasmop;_size : topsize;const _op1 : treference;_op2 : tregister);
  403. begin
  404. inherited create(op);
  405. init(_size);
  406. ops:=2;
  407. loadref(0,_op1);
  408. loadreg(1,_op2);
  409. end;
  410. constructor taicpu.op_reg_reg_reg(op : tasmop;_size : topsize;_op1,_op2,_op3 : tregister);
  411. begin
  412. inherited create(op);
  413. init(_size);
  414. ops:=3;
  415. loadreg(0,_op1);
  416. loadreg(1,_op2);
  417. loadreg(2,_op3);
  418. end;
  419. constructor taicpu.op_const_reg_reg(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister;_op3 : tregister);
  420. begin
  421. inherited create(op);
  422. init(_size);
  423. ops:=3;
  424. loadconst(0,_op1);
  425. loadreg(1,_op2);
  426. loadreg(2,_op3);
  427. end;
  428. constructor taicpu.op_reg_reg_ref(op : tasmop;_size : topsize;_op1,_op2 : tregister;const _op3 : treference);
  429. begin
  430. inherited create(op);
  431. init(_size);
  432. ops:=3;
  433. loadreg(0,_op1);
  434. loadreg(1,_op2);
  435. loadref(2,_op3);
  436. end;
  437. constructor taicpu.op_const_ref_reg(op : tasmop;_size : topsize;_op1 : aword;const _op2 : treference;_op3 : tregister);
  438. begin
  439. inherited create(op);
  440. init(_size);
  441. ops:=3;
  442. loadconst(0,_op1);
  443. loadref(1,_op2);
  444. loadreg(2,_op3);
  445. end;
  446. constructor taicpu.op_const_reg_ref(op : tasmop;_size : topsize;_op1 : aword;_op2 : tregister;const _op3 : treference);
  447. begin
  448. inherited create(op);
  449. init(_size);
  450. ops:=3;
  451. loadconst(0,_op1);
  452. loadreg(1,_op2);
  453. loadref(2,_op3);
  454. end;
  455. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_size : topsize;_op1 : tasmsymbol);
  456. begin
  457. inherited create(op);
  458. init(_size);
  459. condition:=cond;
  460. ops:=1;
  461. loadsymbol(0,_op1,0);
  462. end;
  463. constructor taicpu.op_sym(op : tasmop;_size : topsize;_op1 : tasmsymbol);
  464. begin
  465. inherited create(op);
  466. init(_size);
  467. ops:=1;
  468. loadsymbol(0,_op1,0);
  469. end;
  470. constructor taicpu.op_sym_ofs(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint);
  471. begin
  472. inherited create(op);
  473. init(_size);
  474. ops:=1;
  475. loadsymbol(0,_op1,_op1ofs);
  476. end;
  477. constructor taicpu.op_sym_ofs_reg(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;_op2 : tregister);
  478. begin
  479. inherited create(op);
  480. init(_size);
  481. ops:=2;
  482. loadsymbol(0,_op1,_op1ofs);
  483. loadreg(1,_op2);
  484. end;
  485. constructor taicpu.op_sym_ofs_ref(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  486. begin
  487. inherited create(op);
  488. init(_size);
  489. ops:=2;
  490. loadsymbol(0,_op1,_op1ofs);
  491. loadref(1,_op2);
  492. end;
  493. function taicpu.GetString:string;
  494. var
  495. i : longint;
  496. s : string;
  497. addsize : boolean;
  498. begin
  499. s:='['+std_op2str[opcode];
  500. for i:=1to ops do
  501. begin
  502. if i=1 then
  503. s:=s+' '
  504. else
  505. s:=s+',';
  506. { type }
  507. addsize:=false;
  508. if (oper[i-1].ot and OT_XMMREG)=OT_XMMREG then
  509. s:=s+'xmmreg'
  510. else
  511. if (oper[i-1].ot and OT_MMXREG)=OT_MMXREG then
  512. s:=s+'mmxreg'
  513. else
  514. if (oper[i-1].ot and OT_FPUREG)=OT_FPUREG then
  515. s:=s+'fpureg'
  516. else
  517. if (oper[i-1].ot and OT_REGISTER)=OT_REGISTER then
  518. begin
  519. s:=s+'reg';
  520. addsize:=true;
  521. end
  522. else
  523. if (oper[i-1].ot and OT_IMMEDIATE)=OT_IMMEDIATE then
  524. begin
  525. s:=s+'imm';
  526. addsize:=true;
  527. end
  528. else
  529. if (oper[i-1].ot and OT_MEMORY)=OT_MEMORY then
  530. begin
  531. s:=s+'mem';
  532. addsize:=true;
  533. end
  534. else
  535. s:=s+'???';
  536. { size }
  537. if addsize then
  538. begin
  539. if (oper[i-1].ot and OT_BITS8)<>0 then
  540. s:=s+'8'
  541. else
  542. if (oper[i-1].ot and OT_BITS16)<>0 then
  543. s:=s+'16'
  544. else
  545. if (oper[i-1].ot and OT_BITS32)<>0 then
  546. s:=s+'32'
  547. else
  548. s:=s+'??';
  549. { signed }
  550. if (oper[i-1].ot and OT_SIGNED)<>0 then
  551. s:=s+'s';
  552. end;
  553. end;
  554. GetString:=s+']';
  555. end;
  556. procedure taicpu.Swapoperands;
  557. var
  558. p : TOper;
  559. begin
  560. { Fix the operands which are in AT&T style and we need them in Intel style }
  561. case ops of
  562. 2 : begin
  563. { 0,1 -> 1,0 }
  564. p:=oper[0];
  565. oper[0]:=oper[1];
  566. oper[1]:=p;
  567. end;
  568. 3 : begin
  569. { 0,1,2 -> 2,1,0 }
  570. p:=oper[0];
  571. oper[0]:=oper[2];
  572. oper[2]:=p;
  573. end;
  574. end;
  575. end;
  576. procedure taicpu.SetOperandOrder(order:TOperandOrder);
  577. begin
  578. if FOperandOrder<>order then
  579. begin
  580. Swapoperands;
  581. FOperandOrder:=order;
  582. end;
  583. end;
  584. procedure taicpu.ppuloadoper(ppufile:tcompilerppufile;var o:toper);
  585. begin
  586. o.typ:=toptype(ppufile.getbyte);
  587. o.ot:=ppufile.getlongint;
  588. case o.typ of
  589. top_reg :
  590. o.reg:=tregister(ppufile.getbyte);
  591. top_ref :
  592. begin
  593. new(o.ref);
  594. o.ref^.segment:=tregister(ppufile.getbyte);
  595. o.ref^.base:=tregister(ppufile.getbyte);
  596. o.ref^.index:=tregister(ppufile.getbyte);
  597. o.ref^.scalefactor:=ppufile.getbyte;
  598. o.ref^.offset:=ppufile.getlongint;
  599. o.ref^.symbol:=ppufile.getasmsymbol;
  600. o.ref^.offsetfixup:=ppufile.getlongint;
  601. o.ref^.options:=trefoptions(ppufile.getbyte);
  602. end;
  603. top_const :
  604. o.val:=aword(ppufile.getlongint);
  605. top_symbol :
  606. begin
  607. o.sym:=ppufile.getasmsymbol;
  608. o.symofs:=ppufile.getlongint;
  609. end;
  610. end;
  611. end;
  612. procedure taicpu.ppuwriteoper(ppufile:tcompilerppufile;const o:toper);
  613. begin
  614. ppufile.putbyte(byte(o.typ));
  615. ppufile.putlongint(o.ot);
  616. case o.typ of
  617. top_reg :
  618. ppufile.putbyte(byte(o.reg));
  619. top_ref :
  620. begin
  621. ppufile.putbyte(byte(o.ref^.segment));
  622. ppufile.putbyte(byte(o.ref^.base));
  623. ppufile.putbyte(byte(o.ref^.index));
  624. ppufile.putbyte(o.ref^.scalefactor);
  625. ppufile.putlongint(o.ref^.offset);
  626. ppufile.putasmsymbol(o.ref^.symbol);
  627. ppufile.putlongint(o.ref^.offsetfixup);
  628. ppufile.putbyte(byte(o.ref^.options));
  629. end;
  630. top_const :
  631. ppufile.putlongint(longint(o.val));
  632. top_symbol :
  633. begin
  634. ppufile.putasmsymbol(o.sym);
  635. ppufile.putlongint(longint(o.symofs));
  636. end;
  637. end;
  638. end;
  639. procedure taicpu.ppuderefoper(var o:toper);
  640. begin
  641. case o.typ of
  642. top_ref :
  643. begin
  644. if assigned(o.ref^.symbol) then
  645. objectlibrary.derefasmsymbol(o.ref^.symbol);
  646. end;
  647. top_symbol :
  648. objectlibrary.derefasmsymbol(o.sym);
  649. end;
  650. end;
  651. procedure taicpu.CheckNonCommutativeOpcodes;
  652. begin
  653. { we need ATT order }
  654. SetOperandOrder(op_att);
  655. if ((ops=2) and
  656. (oper[0].typ=top_reg) and
  657. (oper[1].typ=top_reg) and
  658. { if the first is ST and the second is also a register
  659. it is necessarily ST1 .. ST7 }
  660. (oper[0].reg in [R_ST..R_ST0])) or
  661. { ((ops=1) and
  662. (oper[0].typ=top_reg) and
  663. (oper[0].reg in [R_ST1..R_ST7])) or}
  664. (ops=0) then
  665. if opcode=A_FSUBR then
  666. opcode:=A_FSUB
  667. else if opcode=A_FSUB then
  668. opcode:=A_FSUBR
  669. else if opcode=A_FDIVR then
  670. opcode:=A_FDIV
  671. else if opcode=A_FDIV then
  672. opcode:=A_FDIVR
  673. else if opcode=A_FSUBRP then
  674. opcode:=A_FSUBP
  675. else if opcode=A_FSUBP then
  676. opcode:=A_FSUBRP
  677. else if opcode=A_FDIVRP then
  678. opcode:=A_FDIVP
  679. else if opcode=A_FDIVP then
  680. opcode:=A_FDIVRP;
  681. if ((ops=1) and
  682. (oper[0].typ=top_reg) and
  683. (oper[0].reg in [R_ST1..R_ST7])) then
  684. if opcode=A_FSUBRP then
  685. opcode:=A_FSUBP
  686. else if opcode=A_FSUBP then
  687. opcode:=A_FSUBRP
  688. else if opcode=A_FDIVRP then
  689. opcode:=A_FDIVP
  690. else if opcode=A_FDIVP then
  691. opcode:=A_FDIVRP;
  692. end;
  693. {*****************************************************************************
  694. Assembler
  695. *****************************************************************************}
  696. {$ifndef NOAG386BIN}
  697. type
  698. ea=packed record
  699. sib_present : boolean;
  700. bytes : byte;
  701. size : byte;
  702. modrm : byte;
  703. sib : byte;
  704. end;
  705. procedure taicpu.create_ot;
  706. {
  707. this function will also fix some other fields which only needs to be once
  708. }
  709. var
  710. i,l,relsize : longint;
  711. begin
  712. if ops=0 then
  713. exit;
  714. { update oper[].ot field }
  715. for i:=0 to ops-1 do
  716. with oper[i] do
  717. begin
  718. case typ of
  719. top_reg :
  720. ot:=reg2type[reg];
  721. top_ref :
  722. begin
  723. { create ot field }
  724. if (ot and OT_SIZE_MASK)=0 then
  725. ot:=OT_MEMORY or opsize_2_type[i,opsize]
  726. else
  727. ot:=OT_MEMORY or (ot and OT_SIZE_MASK);
  728. if (ref^.base=R_NO) and (ref^.index=R_NO) then
  729. ot:=ot or OT_MEM_OFFS;
  730. { fix scalefactor }
  731. if (ref^.index=R_NO) then
  732. ref^.scalefactor:=0
  733. else
  734. if (ref^.scalefactor=0) then
  735. ref^.scalefactor:=1;
  736. end;
  737. top_const :
  738. begin
  739. if (opsize<>S_W) and (longint(val)>=-128) and (val<=127) then
  740. ot:=OT_IMM8 or OT_SIGNED
  741. else
  742. ot:=OT_IMMEDIATE or opsize_2_type[i,opsize];
  743. end;
  744. top_symbol :
  745. begin
  746. if LastInsOffset=-1 then
  747. l:=0
  748. else
  749. l:=InsOffset-LastInsOffset;
  750. inc(l,symofs);
  751. if assigned(sym) then
  752. inc(l,sym.address);
  753. { instruction size will then always become 2 (PFV) }
  754. relsize:=(InsOffset+2)-l;
  755. if (not assigned(sym) or
  756. ((sym.currbind<>AB_EXTERNAL) and (sym.address<>0))) and
  757. (relsize>=-128) and (relsize<=127) then
  758. ot:=OT_IMM32 or OT_SHORT
  759. else
  760. ot:=OT_IMM32 or OT_NEAR;
  761. end;
  762. end;
  763. end;
  764. end;
  765. function taicpu.InsEnd:longint;
  766. begin
  767. InsEnd:=InsOffset+InsSize;
  768. end;
  769. function taicpu.Matches(p:PInsEntry):longint;
  770. { * IF_SM stands for Size Match: any operand whose size is not
  771. * explicitly specified by the template is `really' intended to be
  772. * the same size as the first size-specified operand.
  773. * Non-specification is tolerated in the input instruction, but
  774. * _wrong_ specification is not.
  775. *
  776. * IF_SM2 invokes Size Match on only the first _two_ operands, for
  777. * three-operand instructions such as SHLD: it implies that the
  778. * first two operands must match in size, but that the third is
  779. * required to be _unspecified_.
  780. *
  781. * IF_SB invokes Size Byte: operands with unspecified size in the
  782. * template are really bytes, and so no non-byte specification in
  783. * the input instruction will be tolerated. IF_SW similarly invokes
  784. * Size Word, and IF_SD invokes Size Doubleword.
  785. *
  786. * (The default state if neither IF_SM nor IF_SM2 is specified is
  787. * that any operand with unspecified size in the template is
  788. * required to have unspecified size in the instruction too...)
  789. }
  790. var
  791. i,j,asize,oprs : longint;
  792. siz : array[0..2] of longint;
  793. begin
  794. Matches:=100;
  795. { Check the opcode and operands }
  796. if (p^.opcode<>opcode) or (p^.ops<>ops) then
  797. begin
  798. Matches:=0;
  799. exit;
  800. end;
  801. { Check that no spurious colons or TOs are present }
  802. for i:=0 to p^.ops-1 do
  803. if (oper[i].ot and (not p^.optypes[i]) and (OT_COLON or OT_TO))<>0 then
  804. begin
  805. Matches:=0;
  806. exit;
  807. end;
  808. { Check that the operand flags all match up }
  809. for i:=0 to p^.ops-1 do
  810. begin
  811. if ((p^.optypes[i] and (not oper[i].ot)) or
  812. ((p^.optypes[i] and OT_SIZE_MASK) and
  813. ((p^.optypes[i] xor oper[i].ot) and OT_SIZE_MASK)))<>0 then
  814. begin
  815. if ((p^.optypes[i] and (not oper[i].ot) and OT_NON_SIZE) or
  816. (oper[i].ot and OT_SIZE_MASK))<>0 then
  817. begin
  818. Matches:=0;
  819. exit;
  820. end
  821. else
  822. Matches:=1;
  823. end;
  824. end;
  825. { Check operand sizes }
  826. { as default an untyped size can get all the sizes, this is different
  827. from nasm, but else we need to do a lot checking which opcodes want
  828. size or not with the automatic size generation }
  829. asize:=longint($ffffffff);
  830. if (p^.flags and IF_SB)<>0 then
  831. asize:=OT_BITS8
  832. else if (p^.flags and IF_SW)<>0 then
  833. asize:=OT_BITS16
  834. else if (p^.flags and IF_SD)<>0 then
  835. asize:=OT_BITS32;
  836. if (p^.flags and IF_ARMASK)<>0 then
  837. begin
  838. siz[0]:=0;
  839. siz[1]:=0;
  840. siz[2]:=0;
  841. if (p^.flags and IF_AR0)<>0 then
  842. siz[0]:=asize
  843. else if (p^.flags and IF_AR1)<>0 then
  844. siz[1]:=asize
  845. else if (p^.flags and IF_AR2)<>0 then
  846. siz[2]:=asize;
  847. end
  848. else
  849. begin
  850. { we can leave because the size for all operands is forced to be
  851. the same
  852. but not if IF_SB IF_SW or IF_SD is set PM }
  853. if asize=-1 then
  854. exit;
  855. siz[0]:=asize;
  856. siz[1]:=asize;
  857. siz[2]:=asize;
  858. end;
  859. if (p^.flags and (IF_SM or IF_SM2))<>0 then
  860. begin
  861. if (p^.flags and IF_SM2)<>0 then
  862. oprs:=2
  863. else
  864. oprs:=p^.ops;
  865. for i:=0 to oprs-1 do
  866. if ((p^.optypes[i] and OT_SIZE_MASK) <> 0) then
  867. begin
  868. for j:=0 to oprs-1 do
  869. siz[j]:=p^.optypes[i] and OT_SIZE_MASK;
  870. break;
  871. end;
  872. end
  873. else
  874. oprs:=2;
  875. { Check operand sizes }
  876. for i:=0 to p^.ops-1 do
  877. begin
  878. if ((p^.optypes[i] and OT_SIZE_MASK)=0) and
  879. ((oper[i].ot and OT_SIZE_MASK and (not siz[i]))<>0) and
  880. { Immediates can always include smaller size }
  881. ((oper[i].ot and OT_IMMEDIATE)=0) and
  882. (((p^.optypes[i] and OT_SIZE_MASK) or siz[i])<(oper[i].ot and OT_SIZE_MASK)) then
  883. Matches:=2;
  884. end;
  885. end;
  886. procedure taicpu.ResetPass1;
  887. begin
  888. { we need to reset everything here, because the choosen insentry
  889. can be invalid for a new situation where the previously optimized
  890. insentry is not correct }
  891. InsEntry:=nil;
  892. InsSize:=0;
  893. LastInsOffset:=-1;
  894. end;
  895. procedure taicpu.ResetPass2;
  896. begin
  897. { we are here in a second pass, check if the instruction can be optimized }
  898. if assigned(InsEntry) and
  899. ((InsEntry^.flags and IF_PASS2)<>0) then
  900. begin
  901. InsEntry:=nil;
  902. InsSize:=0;
  903. end;
  904. LastInsOffset:=-1;
  905. end;
  906. function taicpu.CheckIfValid:boolean;
  907. var
  908. m,i : longint;
  909. begin
  910. CheckIfValid:=false;
  911. { Things which may only be done once, not when a second pass is done to
  912. optimize }
  913. if (Insentry=nil) or ((InsEntry^.flags and IF_PASS2)<>0) then
  914. begin
  915. { We need intel style operands }
  916. SetOperandOrder(op_intel);
  917. { create the .ot fields }
  918. create_ot;
  919. { set the file postion }
  920. aktfilepos:=fileinfo;
  921. end
  922. else
  923. begin
  924. { we've already an insentry so it's valid }
  925. CheckIfValid:=true;
  926. exit;
  927. end;
  928. { Lookup opcode in the table }
  929. InsSize:=-1;
  930. i:=instabcache^[opcode];
  931. if i=-1 then
  932. begin
  933. Message1(asmw_e_opcode_not_in_table,gas_op2str[opcode]);
  934. exit;
  935. end;
  936. insentry:=@instab[i];
  937. while (insentry^.opcode=opcode) do
  938. begin
  939. m:=matches(insentry);
  940. if m=100 then
  941. begin
  942. InsSize:=calcsize(insentry);
  943. if (segprefix<>R_NO) then
  944. inc(InsSize);
  945. { For opsize if size if forced }
  946. if (insentry^.flags and (IF_SB or IF_SW or IF_SD))<>0 then
  947. begin
  948. if (insentry^.flags and IF_ARMASK)=0 then
  949. begin
  950. if (insentry^.flags and IF_SB)<>0 then
  951. begin
  952. if opsize=S_NO then
  953. opsize:=S_B;
  954. end
  955. else if (insentry^.flags and IF_SW)<>0 then
  956. begin
  957. if opsize=S_NO then
  958. opsize:=S_W;
  959. end
  960. else if (insentry^.flags and IF_SD)<>0 then
  961. begin
  962. if opsize=S_NO then
  963. opsize:=S_L;
  964. end;
  965. end;
  966. end;
  967. CheckIfValid:=true;
  968. exit;
  969. end;
  970. inc(i);
  971. insentry:=@instab[i];
  972. end;
  973. if insentry^.opcode<>opcode then
  974. Message1(asmw_e_invalid_opcode_and_operands,GetString);
  975. { No instruction found, set insentry to nil and inssize to -1 }
  976. insentry:=nil;
  977. inssize:=-1;
  978. end;
  979. function taicpu.Pass1(offset:longint):longint;
  980. begin
  981. Pass1:=0;
  982. { Save the old offset and set the new offset }
  983. InsOffset:=Offset;
  984. { Things which may only be done once, not when a second pass is done to
  985. optimize }
  986. if Insentry=nil then
  987. begin
  988. { Check if error last time then InsSize=-1 }
  989. if InsSize=-1 then
  990. exit;
  991. { set the file postion }
  992. aktfilepos:=fileinfo;
  993. end
  994. else
  995. begin
  996. {$ifdef PASS2FLAG}
  997. { we are here in a second pass, check if the instruction can be optimized }
  998. if (InsEntry^.flags and IF_PASS2)=0 then
  999. begin
  1000. Pass1:=InsSize;
  1001. exit;
  1002. end;
  1003. { update the .ot fields, some top_const can be updated }
  1004. create_ot;
  1005. {$endif PASS2FLAG}
  1006. end;
  1007. { Check if it's a valid instruction }
  1008. if CheckIfValid then
  1009. begin
  1010. LastInsOffset:=InsOffset;
  1011. Pass1:=InsSize;
  1012. exit;
  1013. end;
  1014. LastInsOffset:=-1;
  1015. end;
  1016. procedure taicpu.Pass2(sec:TAsmObjectData);
  1017. var
  1018. c : longint;
  1019. begin
  1020. { error in pass1 ? }
  1021. if insentry=nil then
  1022. exit;
  1023. aktfilepos:=fileinfo;
  1024. { Segment override }
  1025. if (segprefix<>R_NO) then
  1026. begin
  1027. case segprefix of
  1028. R_CS : c:=$2e;
  1029. R_DS : c:=$3e;
  1030. R_ES : c:=$26;
  1031. R_FS : c:=$64;
  1032. R_GS : c:=$65;
  1033. R_SS : c:=$36;
  1034. end;
  1035. sec.writebytes(c,1);
  1036. { fix the offset for GenNode }
  1037. inc(InsOffset);
  1038. end;
  1039. { Generate the instruction }
  1040. GenCode(sec);
  1041. end;
  1042. function taicpu.NeedAddrPrefix(opidx:byte):boolean;
  1043. var
  1044. i,b : tregister;
  1045. begin
  1046. if (OT_MEMORY and (not oper[opidx].ot))=0 then
  1047. begin
  1048. i:=oper[opidx].ref^.index;
  1049. b:=oper[opidx].ref^.base;
  1050. if not(i in [R_NO,R_EAX,R_EBX,R_ECX,R_EDX,R_EBP,R_ESP,R_ESI,R_EDI]) or
  1051. not(b in [R_NO,R_EAX,R_EBX,R_ECX,R_EDX,R_EBP,R_ESP,R_ESI,R_EDI]) then
  1052. begin
  1053. NeedAddrPrefix:=true;
  1054. exit;
  1055. end;
  1056. end;
  1057. NeedAddrPrefix:=false;
  1058. end;
  1059. function regval(r:tregister):byte;
  1060. begin
  1061. case r of
  1062. R_EAX,R_AX,R_AL,R_ES,R_CR0,R_DR0,R_ST,R_ST0,R_MM0,R_XMM0 :
  1063. regval:=0;
  1064. R_ECX,R_CX,R_CL,R_CS,R_DR1,R_ST1,R_MM1,R_XMM1 :
  1065. regval:=1;
  1066. R_EDX,R_DX,R_DL,R_SS,R_CR2,R_DR2,R_ST2,R_MM2,R_XMM2 :
  1067. regval:=2;
  1068. R_EBX,R_BX,R_BL,R_DS,R_CR3,R_DR3,R_TR3,R_ST3,R_MM3,R_XMM3 :
  1069. regval:=3;
  1070. R_ESP,R_SP,R_AH,R_FS,R_CR4,R_TR4,R_ST4,R_MM4,R_XMM4 :
  1071. regval:=4;
  1072. R_EBP,R_BP,R_CH,R_GS,R_TR5,R_ST5,R_MM5,R_XMM5 :
  1073. regval:=5;
  1074. R_ESI,R_SI,R_DH,R_DR6,R_TR6,R_ST6,R_MM6,R_XMM6 :
  1075. regval:=6;
  1076. R_EDI,R_DI,R_BH,R_DR7,R_TR7,R_ST7,R_MM7,R_XMM7 :
  1077. regval:=7;
  1078. else
  1079. begin
  1080. internalerror(777001);
  1081. regval:=0;
  1082. end;
  1083. end;
  1084. end;
  1085. function process_ea(const input:toper;var output:ea;rfield:longint):boolean;
  1086. const
  1087. regs : array[0..63] of tregister=(
  1088. R_MM0, R_EAX, R_AX, R_AL, R_XMM0, R_NO, R_NO, R_NO,
  1089. R_MM1, R_ECX, R_CX, R_CL, R_XMM1, R_NO, R_NO, R_NO,
  1090. R_MM2, R_EDX, R_DX, R_DL, R_XMM2, R_NO, R_NO, R_NO,
  1091. R_MM3, R_EBX, R_BX, R_BL, R_XMM3, R_NO, R_NO, R_NO,
  1092. R_MM4, R_ESP, R_SP, R_AH, R_XMM4, R_NO, R_NO, R_NO,
  1093. R_MM5, R_EBP, R_BP, R_CH, R_XMM5, R_NO, R_NO, R_NO,
  1094. R_MM6, R_ESI, R_SI, R_DH, R_XMM6, R_NO, R_NO, R_NO,
  1095. R_MM7, R_EDI, R_DI, R_BH, R_XMM7, R_NO, R_NO, R_NO
  1096. );
  1097. var
  1098. j : longint;
  1099. i,b : tregister;
  1100. sym : tasmsymbol;
  1101. md,s : byte;
  1102. base,index,scalefactor,
  1103. o : longint;
  1104. begin
  1105. process_ea:=false;
  1106. { register ? }
  1107. if (input.typ=top_reg) then
  1108. begin
  1109. j:=0;
  1110. while (j<=high(regs)) do
  1111. begin
  1112. if input.reg=regs[j] then
  1113. break;
  1114. inc(j);
  1115. end;
  1116. if j<=high(regs) then
  1117. begin
  1118. output.sib_present:=false;
  1119. output.bytes:=0;
  1120. output.modrm:=$c0 or (rfield shl 3) or (j shr 3);
  1121. output.size:=1;
  1122. process_ea:=true;
  1123. end;
  1124. exit;
  1125. end;
  1126. { memory reference }
  1127. i:=input.ref^.index;
  1128. b:=input.ref^.base;
  1129. s:=input.ref^.scalefactor;
  1130. o:=input.ref^.offset+input.ref^.offsetfixup;
  1131. sym:=input.ref^.symbol;
  1132. { it's direct address }
  1133. if (b=R_NO) and (i=R_NO) then
  1134. begin
  1135. { it's a pure offset }
  1136. output.sib_present:=false;
  1137. output.bytes:=4;
  1138. output.modrm:=5 or (rfield shl 3);
  1139. end
  1140. else
  1141. { it's an indirection }
  1142. begin
  1143. { 16 bit address? }
  1144. if not((i in [R_NO,R_EAX,R_EBX,R_ECX,R_EDX,R_EBP,R_ESP,R_ESI,R_EDI]) and
  1145. (b in [R_NO,R_EAX,R_EBX,R_ECX,R_EDX,R_EBP,R_ESP,R_ESI,R_EDI])) then
  1146. Message(asmw_e_16bit_not_supported);
  1147. {$ifdef OPTEA}
  1148. { make single reg base }
  1149. if (b=R_NO) and (s=1) then
  1150. begin
  1151. b:=i;
  1152. i:=R_NO;
  1153. end;
  1154. { convert [3,5,9]*EAX to EAX+[2,4,8]*EAX }
  1155. if (b=R_NO) and
  1156. (((s=2) and (i<>R_ESP)) or
  1157. (s=3) or (s=5) or (s=9)) then
  1158. begin
  1159. b:=i;
  1160. dec(s);
  1161. end;
  1162. { swap ESP into base if scalefactor is 1 }
  1163. if (s=1) and (i=R_ESP) then
  1164. begin
  1165. i:=b;
  1166. b:=R_ESP;
  1167. end;
  1168. {$endif OPTEA}
  1169. { wrong, for various reasons }
  1170. if (i=R_ESP) or ((s<>1) and (s<>2) and (s<>4) and (s<>8) and (i<>R_NO)) then
  1171. exit;
  1172. { base }
  1173. case b of
  1174. R_EAX : base:=0;
  1175. R_ECX : base:=1;
  1176. R_EDX : base:=2;
  1177. R_EBX : base:=3;
  1178. R_ESP : base:=4;
  1179. R_NO,
  1180. R_EBP : base:=5;
  1181. R_ESI : base:=6;
  1182. R_EDI : base:=7;
  1183. else
  1184. exit;
  1185. end;
  1186. { index }
  1187. case i of
  1188. R_EAX : index:=0;
  1189. R_ECX : index:=1;
  1190. R_EDX : index:=2;
  1191. R_EBX : index:=3;
  1192. R_NO : index:=4;
  1193. R_EBP : index:=5;
  1194. R_ESI : index:=6;
  1195. R_EDI : index:=7;
  1196. else
  1197. exit;
  1198. end;
  1199. case s of
  1200. 0,
  1201. 1 : scalefactor:=0;
  1202. 2 : scalefactor:=1;
  1203. 4 : scalefactor:=2;
  1204. 8 : scalefactor:=3;
  1205. else
  1206. exit;
  1207. end;
  1208. if (b=R_NO) or
  1209. ((b<>R_EBP) and (o=0) and (sym=nil)) then
  1210. md:=0
  1211. else
  1212. if ((o>=-128) and (o<=127) and (sym=nil)) then
  1213. md:=1
  1214. else
  1215. md:=2;
  1216. if (b=R_NO) or (md=2) then
  1217. output.bytes:=4
  1218. else
  1219. output.bytes:=md;
  1220. { SIB needed ? }
  1221. if (i=R_NO) and (b<>R_ESP) then
  1222. begin
  1223. output.sib_present:=false;
  1224. output.modrm:=(md shl 6) or (rfield shl 3) or base;
  1225. end
  1226. else
  1227. begin
  1228. output.sib_present:=true;
  1229. output.modrm:=(md shl 6) or (rfield shl 3) or 4;
  1230. output.sib:=(scalefactor shl 6) or (index shl 3) or base;
  1231. end;
  1232. end;
  1233. if output.sib_present then
  1234. output.size:=2+output.bytes
  1235. else
  1236. output.size:=1+output.bytes;
  1237. process_ea:=true;
  1238. end;
  1239. function taicpu.calcsize(p:PInsEntry):longint;
  1240. var
  1241. codes : pchar;
  1242. c : byte;
  1243. len : longint;
  1244. ea_data : ea;
  1245. begin
  1246. len:=0;
  1247. codes:=@p^.code;
  1248. repeat
  1249. c:=ord(codes^);
  1250. inc(codes);
  1251. case c of
  1252. 0 :
  1253. break;
  1254. 1,2,3 :
  1255. begin
  1256. inc(codes,c);
  1257. inc(len,c);
  1258. end;
  1259. 8,9,10 :
  1260. begin
  1261. inc(codes);
  1262. inc(len);
  1263. end;
  1264. 4,5,6,7 :
  1265. begin
  1266. if opsize=S_W then
  1267. inc(len,2)
  1268. else
  1269. inc(len);
  1270. end;
  1271. 15,
  1272. 12,13,14,
  1273. 16,17,18,
  1274. 20,21,22,
  1275. 40,41,42 :
  1276. inc(len);
  1277. 24,25,26,
  1278. 31,
  1279. 48,49,50 :
  1280. inc(len,2);
  1281. 28,29,30, { we don't have 16 bit immediates code }
  1282. 32,33,34,
  1283. 52,53,54,
  1284. 56,57,58 :
  1285. inc(len,4);
  1286. 192,193,194 :
  1287. if NeedAddrPrefix(c-192) then
  1288. inc(len);
  1289. 208 :
  1290. inc(len);
  1291. 200,
  1292. 201,
  1293. 202,
  1294. 209,
  1295. 210,
  1296. 217,218,219 : ;
  1297. 216 :
  1298. begin
  1299. inc(codes);
  1300. inc(len);
  1301. end;
  1302. 224,225,226 :
  1303. begin
  1304. InternalError(777002);
  1305. end;
  1306. else
  1307. begin
  1308. if (c>=64) and (c<=191) then
  1309. begin
  1310. if not process_ea(oper[(c shr 3) and 7], ea_data, 0) then
  1311. Message(asmw_e_invalid_effective_address)
  1312. else
  1313. inc(len,ea_data.size);
  1314. end
  1315. else
  1316. InternalError(777003);
  1317. end;
  1318. end;
  1319. until false;
  1320. calcsize:=len;
  1321. end;
  1322. procedure taicpu.GenCode(sec:TAsmObjectData);
  1323. {
  1324. * the actual codes (C syntax, i.e. octal):
  1325. * \0 - terminates the code. (Unless it's a literal of course.)
  1326. * \1, \2, \3 - that many literal bytes follow in the code stream
  1327. * \4, \6 - the POP/PUSH (respectively) codes for CS, DS, ES, SS
  1328. * (POP is never used for CS) depending on operand 0
  1329. * \5, \7 - the second byte of POP/PUSH codes for FS, GS, depending
  1330. * on operand 0
  1331. * \10, \11, \12 - a literal byte follows in the code stream, to be added
  1332. * to the register value of operand 0, 1 or 2
  1333. * \17 - encodes the literal byte 0. (Some compilers don't take
  1334. * kindly to a zero byte in the _middle_ of a compile time
  1335. * string constant, so I had to put this hack in.)
  1336. * \14, \15, \16 - a signed byte immediate operand, from operand 0, 1 or 2
  1337. * \20, \21, \22 - a byte immediate operand, from operand 0, 1 or 2
  1338. * \24, \25, \26 - an unsigned byte immediate operand, from operand 0, 1 or 2
  1339. * \30, \31, \32 - a word immediate operand, from operand 0, 1 or 2
  1340. * \34, \35, \36 - select between \3[012] and \4[012] depending on 16/32 bit
  1341. * assembly mode or the address-size override on the operand
  1342. * \37 - a word constant, from the _segment_ part of operand 0
  1343. * \40, \41, \42 - a long immediate operand, from operand 0, 1 or 2
  1344. * \50, \51, \52 - a byte relative operand, from operand 0, 1 or 2
  1345. * \60, \61, \62 - a word relative operand, from operand 0, 1 or 2
  1346. * \64, \65, \66 - select between \6[012] and \7[012] depending on 16/32 bit
  1347. * assembly mode or the address-size override on the operand
  1348. * \70, \71, \72 - a long relative operand, from operand 0, 1 or 2
  1349. * \1ab - a ModRM, calculated on EA in operand a, with the spare
  1350. * field the register value of operand b.
  1351. * \2ab - a ModRM, calculated on EA in operand a, with the spare
  1352. * field equal to digit b.
  1353. * \30x - might be an 0x67 byte, depending on the address size of
  1354. * the memory reference in operand x.
  1355. * \310 - indicates fixed 16-bit address size, i.e. optional 0x67.
  1356. * \311 - indicates fixed 32-bit address size, i.e. optional 0x67.
  1357. * \320 - indicates fixed 16-bit operand size, i.e. optional 0x66.
  1358. * \321 - indicates fixed 32-bit operand size, i.e. optional 0x66.
  1359. * \322 - indicates that this instruction is only valid when the
  1360. * operand size is the default (instruction to disassembler,
  1361. * generates no code in the assembler)
  1362. * \330 - a literal byte follows in the code stream, to be added
  1363. * to the condition code value of the instruction.
  1364. * \340 - reserve <operand 0> bytes of uninitialised storage.
  1365. * Operand 0 had better be a segmentless constant.
  1366. }
  1367. var
  1368. currval : longint;
  1369. currsym : tasmsymbol;
  1370. procedure getvalsym(opidx:longint);
  1371. begin
  1372. case oper[opidx].typ of
  1373. top_ref :
  1374. begin
  1375. currval:=oper[opidx].ref^.offset+oper[opidx].ref^.offsetfixup;
  1376. currsym:=oper[opidx].ref^.symbol;
  1377. end;
  1378. top_const :
  1379. begin
  1380. currval:=longint(oper[opidx].val);
  1381. currsym:=nil;
  1382. end;
  1383. top_symbol :
  1384. begin
  1385. currval:=oper[opidx].symofs;
  1386. currsym:=oper[opidx].sym;
  1387. end;
  1388. else
  1389. Message(asmw_e_immediate_or_reference_expected);
  1390. end;
  1391. end;
  1392. const
  1393. CondVal:array[TAsmCond] of byte=($0,
  1394. $7, $3, $2, $6, $2, $4, $F, $D, $C, $E, $6, $2,
  1395. $3, $7, $3, $5, $E, $C, $D, $F, $1, $B, $9, $5,
  1396. $0, $A, $A, $B, $8, $4);
  1397. var
  1398. c : byte;
  1399. pb,
  1400. codes : pchar;
  1401. bytes : array[0..3] of byte;
  1402. rfield,
  1403. data,s,opidx : longint;
  1404. ea_data : ea;
  1405. begin
  1406. {$ifdef EXTDEBUG}
  1407. { safety check }
  1408. if sec.sects[sec.currsec].datasize<>insoffset then
  1409. internalerror(200130121);
  1410. {$endif EXTDEBUG}
  1411. { load data to write }
  1412. codes:=insentry^.code;
  1413. { Force word push/pop for registers }
  1414. if (opsize=S_W) and ((codes[0]=#4) or (codes[0]=#6) or
  1415. ((codes[0]=#1) and ((codes[2]=#5) or (codes[2]=#7)))) then
  1416. begin
  1417. bytes[0]:=$66;
  1418. sec.writebytes(bytes,1);
  1419. end;
  1420. repeat
  1421. c:=ord(codes^);
  1422. inc(codes);
  1423. case c of
  1424. 0 :
  1425. break;
  1426. 1,2,3 :
  1427. begin
  1428. sec.writebytes(codes^,c);
  1429. inc(codes,c);
  1430. end;
  1431. 4,6 :
  1432. begin
  1433. case oper[0].reg of
  1434. R_CS :
  1435. begin
  1436. if c=4 then
  1437. bytes[0]:=$f
  1438. else
  1439. bytes[0]:=$e;
  1440. end;
  1441. R_NO,
  1442. R_DS :
  1443. begin
  1444. if c=4 then
  1445. bytes[0]:=$1f
  1446. else
  1447. bytes[0]:=$1e;
  1448. end;
  1449. R_ES :
  1450. begin
  1451. if c=4 then
  1452. bytes[0]:=$7
  1453. else
  1454. bytes[0]:=$6;
  1455. end;
  1456. R_SS :
  1457. begin
  1458. if c=4 then
  1459. bytes[0]:=$17
  1460. else
  1461. bytes[0]:=$16;
  1462. end;
  1463. else
  1464. InternalError(777004);
  1465. end;
  1466. sec.writebytes(bytes,1);
  1467. end;
  1468. 5,7 :
  1469. begin
  1470. case oper[0].reg of
  1471. R_FS :
  1472. begin
  1473. if c=5 then
  1474. bytes[0]:=$a1
  1475. else
  1476. bytes[0]:=$a0;
  1477. end;
  1478. R_GS :
  1479. begin
  1480. if c=5 then
  1481. bytes[0]:=$a9
  1482. else
  1483. bytes[0]:=$a8;
  1484. end;
  1485. else
  1486. InternalError(777005);
  1487. end;
  1488. sec.writebytes(bytes,1);
  1489. end;
  1490. 8,9,10 :
  1491. begin
  1492. bytes[0]:=ord(codes^)+regval(oper[c-8].reg);
  1493. inc(codes);
  1494. sec.writebytes(bytes,1);
  1495. end;
  1496. 15 :
  1497. begin
  1498. bytes[0]:=0;
  1499. sec.writebytes(bytes,1);
  1500. end;
  1501. 12,13,14 :
  1502. begin
  1503. getvalsym(c-12);
  1504. if (currval<-128) or (currval>127) then
  1505. Message2(asmw_e_value_exceeds_bounds,'signed byte',tostr(currval));
  1506. if assigned(currsym) then
  1507. sec.writereloc(currval,1,currsym,RELOC_ABSOLUTE)
  1508. else
  1509. sec.writebytes(currval,1);
  1510. end;
  1511. 16,17,18 :
  1512. begin
  1513. getvalsym(c-16);
  1514. if (currval<-256) or (currval>255) then
  1515. Message2(asmw_e_value_exceeds_bounds,'byte',tostr(currval));
  1516. if assigned(currsym) then
  1517. sec.writereloc(currval,1,currsym,RELOC_ABSOLUTE)
  1518. else
  1519. sec.writebytes(currval,1);
  1520. end;
  1521. 20,21,22 :
  1522. begin
  1523. getvalsym(c-20);
  1524. if (currval<0) or (currval>255) then
  1525. Message2(asmw_e_value_exceeds_bounds,'unsigned byte',tostr(currval));
  1526. if assigned(currsym) then
  1527. sec.writereloc(currval,1,currsym,RELOC_ABSOLUTE)
  1528. else
  1529. sec.writebytes(currval,1);
  1530. end;
  1531. 24,25,26 :
  1532. begin
  1533. getvalsym(c-24);
  1534. if (currval<-65536) or (currval>65535) then
  1535. Message2(asmw_e_value_exceeds_bounds,'word',tostr(currval));
  1536. if assigned(currsym) then
  1537. sec.writereloc(currval,2,currsym,RELOC_ABSOLUTE)
  1538. else
  1539. sec.writebytes(currval,2);
  1540. end;
  1541. 28,29,30 :
  1542. begin
  1543. getvalsym(c-28);
  1544. if assigned(currsym) then
  1545. sec.writereloc(currval,4,currsym,RELOC_ABSOLUTE)
  1546. else
  1547. sec.writebytes(currval,4);
  1548. end;
  1549. 32,33,34 :
  1550. begin
  1551. getvalsym(c-32);
  1552. if assigned(currsym) then
  1553. sec.writereloc(currval,4,currsym,RELOC_ABSOLUTE)
  1554. else
  1555. sec.writebytes(currval,4);
  1556. end;
  1557. 40,41,42 :
  1558. begin
  1559. getvalsym(c-40);
  1560. data:=currval-insend;
  1561. if assigned(currsym) then
  1562. inc(data,currsym.address);
  1563. if (data>127) or (data<-128) then
  1564. Message1(asmw_e_short_jmp_out_of_range,tostr(data));
  1565. sec.writebytes(data,1);
  1566. end;
  1567. 52,53,54 :
  1568. begin
  1569. getvalsym(c-52);
  1570. if assigned(currsym) then
  1571. sec.writereloc(currval,4,currsym,RELOC_RELATIVE)
  1572. else
  1573. sec.writereloc(currval-insend,4,nil,RELOC_ABSOLUTE)
  1574. end;
  1575. 56,57,58 :
  1576. begin
  1577. getvalsym(c-56);
  1578. if assigned(currsym) then
  1579. sec.writereloc(currval,4,currsym,RELOC_RELATIVE)
  1580. else
  1581. sec.writereloc(currval-insend,4,nil,RELOC_ABSOLUTE)
  1582. end;
  1583. 192,193,194 :
  1584. begin
  1585. if NeedAddrPrefix(c-192) then
  1586. begin
  1587. bytes[0]:=$67;
  1588. sec.writebytes(bytes,1);
  1589. end;
  1590. end;
  1591. 200 :
  1592. begin
  1593. bytes[0]:=$67;
  1594. sec.writebytes(bytes,1);
  1595. end;
  1596. 208 :
  1597. begin
  1598. bytes[0]:=$66;
  1599. sec.writebytes(bytes,1);
  1600. end;
  1601. 216 :
  1602. begin
  1603. bytes[0]:=ord(codes^)+condval[condition];
  1604. inc(codes);
  1605. sec.writebytes(bytes,1);
  1606. end;
  1607. 201,
  1608. 202,
  1609. 209,
  1610. 210,
  1611. 217,218,219 :
  1612. begin
  1613. { these are dissambler hints or 32 bit prefixes which
  1614. are not needed }
  1615. end;
  1616. 31,
  1617. 48,49,50,
  1618. 224,225,226 :
  1619. begin
  1620. InternalError(777006);
  1621. end
  1622. else
  1623. begin
  1624. if (c>=64) and (c<=191) then
  1625. begin
  1626. if (c<127) then
  1627. begin
  1628. if (oper[c and 7].typ=top_reg) then
  1629. rfield:=regval(oper[c and 7].reg)
  1630. else
  1631. rfield:=regval(oper[c and 7].ref^.base);
  1632. end
  1633. else
  1634. rfield:=c and 7;
  1635. opidx:=(c shr 3) and 7;
  1636. if not process_ea(oper[opidx], ea_data, rfield) then
  1637. Message(asmw_e_invalid_effective_address);
  1638. pb:=@bytes;
  1639. pb^:=chr(ea_data.modrm);
  1640. inc(pb);
  1641. if ea_data.sib_present then
  1642. begin
  1643. pb^:=chr(ea_data.sib);
  1644. inc(pb);
  1645. end;
  1646. s:=pb-pchar(@bytes);
  1647. sec.writebytes(bytes,s);
  1648. case ea_data.bytes of
  1649. 0 : ;
  1650. 1 :
  1651. begin
  1652. if (oper[opidx].ot and OT_MEMORY)=OT_MEMORY then
  1653. sec.writereloc(oper[opidx].ref^.offset+oper[opidx].ref^.offsetfixup,1,oper[opidx].ref^.symbol,RELOC_ABSOLUTE)
  1654. else
  1655. begin
  1656. bytes[0]:=oper[opidx].ref^.offset+oper[opidx].ref^.offsetfixup;
  1657. sec.writebytes(bytes,1);
  1658. end;
  1659. inc(s);
  1660. end;
  1661. 2,4 :
  1662. begin
  1663. sec.writereloc(oper[opidx].ref^.offset+oper[opidx].ref^.offsetfixup,ea_data.bytes,
  1664. oper[opidx].ref^.symbol,RELOC_ABSOLUTE);
  1665. inc(s,ea_data.bytes);
  1666. end;
  1667. end;
  1668. end
  1669. else
  1670. InternalError(777007);
  1671. end;
  1672. end;
  1673. until false;
  1674. end;
  1675. {$endif NOAG386BIN}
  1676. {*****************************************************************************
  1677. Instruction table
  1678. *****************************************************************************}
  1679. procedure BuildInsTabCache;
  1680. {$ifndef NOAG386BIN}
  1681. var
  1682. i : longint;
  1683. {$endif}
  1684. begin
  1685. {$ifndef NOAG386BIN}
  1686. new(instabcache);
  1687. FillChar(instabcache^,sizeof(tinstabcache),$ff);
  1688. i:=0;
  1689. while (i<InsTabEntries) do
  1690. begin
  1691. if InsTabCache^[InsTab[i].OPcode]=-1 then
  1692. InsTabCache^[InsTab[i].OPcode]:=i;
  1693. inc(i);
  1694. end;
  1695. {$endif NOAG386BIN}
  1696. end;
  1697. procedure InitAsm;
  1698. begin
  1699. {$ifndef NOAG386BIN}
  1700. if not assigned(instabcache) then
  1701. BuildInsTabCache;
  1702. {$endif NOAG386BIN}
  1703. end;
  1704. procedure DoneAsm;
  1705. begin
  1706. {$ifndef NOAG386BIN}
  1707. if assigned(instabcache) then
  1708. dispose(instabcache);
  1709. {$endif NOAG386BIN}
  1710. end;
  1711. end.
  1712. {
  1713. $Log$
  1714. Revision 1.9 2003-01-05 13:36:53 florian
  1715. * x86-64 compiles
  1716. + very basic support for float128 type (x86-64 only)
  1717. Revision 1.8 2002/11/17 16:31:58 carl
  1718. * memory optimization (3-4%) : cleanup of tai fields,
  1719. cleanup of tdef and tsym fields.
  1720. * make it work for m68k
  1721. Revision 1.7 2002/11/15 01:58:54 peter
  1722. * merged changes from 1.0.7 up to 04-11
  1723. - -V option for generating bug report tracing
  1724. - more tracing for option parsing
  1725. - errors for cdecl and high()
  1726. - win32 import stabs
  1727. - win32 records<=8 are returned in eax:edx (turned off by default)
  1728. - heaptrc update
  1729. - more info for temp management in .s file with EXTDEBUG
  1730. Revision 1.6 2002/10/31 13:28:32 pierre
  1731. * correct last wrong fix for tw2158
  1732. Revision 1.5 2002/10/30 17:10:00 pierre
  1733. * merge of fix for tw2158 bug
  1734. Revision 1.4 2002/08/15 19:10:36 peter
  1735. * first things tai,tnode storing in ppu
  1736. Revision 1.3 2002/08/13 18:01:52 carl
  1737. * rename swatoperands to swapoperands
  1738. + m68k first compilable version (still needs a lot of testing):
  1739. assembler generator, system information , inline
  1740. assembler reader.
  1741. Revision 1.2 2002/07/20 11:57:59 florian
  1742. * types.pas renamed to defbase.pas because D6 contains a types
  1743. unit so this would conflicts if D6 programms are compiled
  1744. + Willamette/SSE2 instructions to assembler added
  1745. Revision 1.1 2002/07/01 18:46:29 peter
  1746. * internal linker
  1747. * reorganized aasm layer
  1748. }