i386base.pas 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. {
  2. $Id$
  3. Copyright (c) 1999 by Florian Klaempfl
  4. Contains the base types for the i386
  5. * 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 i386base;
  22. interface
  23. {$ifdef TP}
  24. {$L-,Y-}
  25. {$endif}
  26. uses
  27. strings,cobjects,aasm;
  28. const
  29. { Size of the instruction table converted by nasmconv.pas }
  30. instabentries = 1103;
  31. maxinfolen = 7;
  32. { By default we want everything }
  33. {$define ATTOP}
  34. {$define ATTREG}
  35. {$define INTELOP}
  36. {$define ITTABLE}
  37. { For TP we can't use asmdebug due the table sizes }
  38. {$ifndef TP}
  39. {$define ASMDEBUG}
  40. {$endif}
  41. { We Don't need the intel style opcodes if we don't have a intel
  42. reader or generator }
  43. {$ifndef ASMDEBUG}
  44. {$ifdef NORA386INT}
  45. {$ifdef NOAG386NSM}
  46. {$ifdef NOAG386INT}
  47. {$undef INTELOP}
  48. {$endif}
  49. {$endif}
  50. {$endif}
  51. {$endif}
  52. { We Don't need the AT&T style opcodes if we don't have a AT&T
  53. reader or generator }
  54. {$ifdef NORA386ATT}
  55. {$ifdef NOAG386ATT}
  56. {$undef ATTOP}
  57. {$ifdef NOAG386DIR}
  58. {$undef ATTREG}
  59. {$endif}
  60. {$endif}
  61. {$endif}
  62. const
  63. { Operand types }
  64. OT_NONE = $00000000;
  65. OT_BITS8 = $00000001; { size, and other attributes, of the operand }
  66. OT_BITS16 = $00000002;
  67. OT_BITS32 = $00000004;
  68. OT_BITS64 = $00000008; { FPU only }
  69. OT_BITS80 = $00000010;
  70. OT_FAR = $00000020; { this means 16:16 or 16:32, like in CALL/JMP }
  71. OT_NEAR = $00000040;
  72. OT_SHORT = $00000080;
  73. OT_SIZE_MASK = $000000FF; { all the size attributes }
  74. OT_NON_SIZE = not OT_SIZE_MASK;
  75. OT_SIGNED = $00000100; { the operand need to be signed -128-127 }
  76. OT_TO = $00000200; { operand is followed by a colon }
  77. { reverse effect in FADD, FSUB &c }
  78. OT_COLON = $00000400;
  79. OT_REGISTER = $00001000;
  80. OT_IMMEDIATE = $00002000;
  81. OT_IMM8 = $00002001;
  82. OT_IMM16 = $00002002;
  83. OT_IMM32 = $00002004;
  84. OT_IMM64 = $00002008;
  85. OT_IMM80 = $00002010;
  86. OT_REGMEM = $00200000; { for r/m, ie EA, operands }
  87. OT_REGNORM = $00201000; { 'normal' reg, qualifies as EA }
  88. OT_REG8 = $00201001;
  89. OT_REG16 = $00201002;
  90. OT_REG32 = $00201004;
  91. OT_MMXREG = $00201008; { MMX registers }
  92. OT_MEMORY = $00204000; { register number in 'basereg' }
  93. OT_MEM8 = $00204001;
  94. OT_MEM16 = $00204002;
  95. OT_MEM32 = $00204004;
  96. OT_MEM64 = $00204008;
  97. OT_MEM80 = $00204010;
  98. OT_FPUREG = $01000000; { floating point stack registers }
  99. OT_FPU0 = $01000800; { FPU stack register zero }
  100. OT_REG_SMASK = $00070000; { special register operands: these may be treated differently }
  101. { a mask for the following }
  102. OT_REG_ACCUM = $00211000; { accumulator: AL, AX or EAX }
  103. OT_REG_AL = $00211001; { REG_ACCUM | BITSxx }
  104. OT_REG_AX = $00211002; { ditto }
  105. OT_REG_EAX = $00211004; { and again }
  106. OT_REG_COUNT = $00221000; { counter: CL, CX or ECX }
  107. OT_REG_CL = $00221001; { REG_COUNT | BITSxx }
  108. OT_REG_CX = $00221002; { ditto }
  109. OT_REG_ECX = $00221004; { another one }
  110. OT_REG_DX = $00241002;
  111. OT_REG_SREG = $00081002; { any segment register }
  112. OT_REG_CS = $01081002; { CS }
  113. OT_REG_DESS = $02081002; { DS, ES, SS (non-CS 86 registers) }
  114. OT_REG_FSGS = $04081002; { FS, GS (386 extended registers) }
  115. OT_REG_CDT = $00101004; { CRn, DRn and TRn }
  116. OT_REG_CREG = $08101004; { CRn }
  117. OT_REG_CR4 = $08101404; { CR4 (Pentium only) }
  118. OT_REG_DREG = $10101004; { DRn }
  119. OT_REG_TREG = $20101004; { TRn }
  120. OT_MEM_OFFS = $00604000; { special type of EA }
  121. { simple [address] offset }
  122. OT_ONENESS = $00800000; { special type of immediate operand }
  123. { so UNITY == IMMEDIATE | ONENESS }
  124. OT_UNITY = $00802000; { for shift/rotate instructions }
  125. { Instruction flags }
  126. IF_SM = $0001; { size match first operand }
  127. IF_SM2 = $0002; { size match first two operands }
  128. IF_SB = $0004; { unsized operands can't be non-byte }
  129. IF_SW = $0008; { unsized operands can't be non-word }
  130. IF_SD = $0010; { unsized operands can't be nondword }
  131. IF_8086 = $0000; { 8086 instruction }
  132. IF_186 = $0100; { 186+ instruction }
  133. IF_286 = $0200; { 286+ instruction }
  134. IF_386 = $0300; { 386+ instruction }
  135. IF_486 = $0400; { 486+ instruction }
  136. IF_PENT = $0500; { Pentium instruction }
  137. IF_P6 = $0600; { P6 instruction }
  138. IF_CYRIX = $0800; { Cyrix-specific instruction }
  139. IF_PMASK = $0F00; { the mask for processor types }
  140. IF_PRIV = $1000; { it's a privileged instruction }
  141. IF_UNDOC = $2000; { it's an undocumented instruction }
  142. IF_FPU = $4000; { it's an FPU instruction }
  143. IF_MMX = $8000; { it's an MMX instruction }
  144. { added flags }
  145. IF_PRE = $10000; { it's a prefix instruction }
  146. IF_PASS2 = $20000; { if the instruction can change in a second pass }
  147. type
  148. TAsmOp=(A_None,
  149. { prefixes }
  150. A_LOCK,A_REP,A_REPE,A_REPNE,A_REPNZ,A_REPZ,
  151. A_CS,A_ES,A_DS,A_FS,A_GS,A_SS,
  152. { normal }
  153. A_AAA, A_AAD, A_AAM, A_AAS, A_ADC, A_ADD, A_AND, A_ARPL,
  154. A_BOUND, A_BSF, A_BSR, A_BSWAP, A_BT, A_BTC, A_BTR, A_BTS,
  155. A_CALL, A_CBW, A_CDQ, A_CLC, A_CLD, A_CLI, A_CLTS, A_CMC, A_CMP,
  156. A_CMPSB, A_CMPSD, A_CMPSW, A_CMPXCHG, A_CMPXCHG486, A_CMPXCHG8B,
  157. A_CPUID, A_CWD, A_CWDE, A_DAA, A_DAS, A_DEC, A_DIV,
  158. A_EMMS, A_ENTER, A_EQU, A_F2XM1, A_FABS,
  159. A_FADD, A_FADDP, A_FBLD, A_FBSTP, A_FCHS, A_FCLEX, A_FCMOVB,
  160. A_FCMOVBE, A_FCMOVE, A_FCMOVNB, A_FCMOVNBE, A_FCMOVNE,
  161. A_FCMOVNU, A_FCMOVU, A_FCOM, A_FCOMI, A_FCOMIP, A_FCOMP,
  162. A_FCOMPP, A_FCOS, A_FDECSTP, A_FDISI, A_FDIV, A_FDIVP, A_FDIVR,
  163. A_FDIVRP, A_FEMMS,
  164. A_FENI, A_FFREE, A_FIADD, A_FICOM, A_FICOMP, A_FIDIV,
  165. A_FIDIVR, A_FILD, A_FIMUL, A_FINCSTP, A_FINIT, A_FIST, A_FISTP,
  166. A_FISUB, A_FISUBR, A_FLD, A_FLD1, A_FLDCW, A_FLDENV, A_FLDL2E,
  167. A_FLDL2T, A_FLDLG2, A_FLDLN2, A_FLDPI, A_FLDZ, A_FMUL, A_FMULP,
  168. A_FNCLEX, A_FNDISI, A_FNENI, A_FNINIT, A_FNOP, A_FNSAVE,
  169. A_FNSTCW, A_FNSTENV, A_FNSTSW, A_FPATAN, A_FPREM, A_FPREM1,
  170. A_FPTAN, A_FRNDINT, A_FRSTOR, A_FSAVE, A_FSCALE, A_FSETPM,
  171. A_FSIN, A_FSINCOS, A_FSQRT, A_FST, A_FSTCW, A_FSTENV, A_FSTP,
  172. A_FSTSW, A_FSUB, A_FSUBP, A_FSUBR, A_FSUBRP, A_FTST, A_FUCOM,
  173. A_FUCOMI, A_FUCOMIP, A_FUCOMP, A_FUCOMPP, A_FWAIT,A_FXAM, A_FXCH,
  174. A_FXTRACT, A_FYL2X, A_FYL2XP1, A_HLT, A_IBTS, A_ICEBP, A_IDIV,
  175. A_IMUL, A_IN, A_INC, A_INSB, A_INSD, A_INSW, A_INT,
  176. A_INT01, A_INT1, A_INT3, A_INTO, A_INVD, A_INVLPG, A_IRET,
  177. A_IRETD, A_IRETW, A_JCXZ, A_JECXZ, A_JMP, A_LAHF, A_LAR, A_LDS,
  178. A_LEA, A_LEAVE, A_LES, A_LFS, A_LGDT, A_LGS, A_LIDT, A_LLDT,
  179. A_LMSW, A_LOADALL, A_LOADALL286, A_LODSB, A_LODSD, A_LODSW,
  180. A_LOOP, A_LOOPE, A_LOOPNE, A_LOOPNZ, A_LOOPZ, A_LSL, A_LSS,
  181. A_LTR, A_MOV, A_MOVD, A_MOVQ, A_MOVSB, A_MOVSD, A_MOVSW,
  182. A_MOVSX, A_MOVZX, A_MUL, A_NEG, A_NOP, A_NOT, A_OR, A_OUT,
  183. A_OUTSB, A_OUTSD, A_OUTSW, A_PACKSSDW, A_PACKSSWB, A_PACKUSWB,
  184. A_PADDB, A_PADDD, A_PADDSB, A_PADDSIW, A_PADDSW, A_PADDUSB,
  185. A_PADDUSW, A_PADDW, A_PAND, A_PANDN, A_PAVEB,
  186. A_PAVGUSB, A_PCMPEQB, A_PCMPEQD, A_PCMPEQW, A_PCMPGTB, A_PCMPGTD,
  187. A_PCMPGTW, A_PDISTIB,
  188. A_PF2ID, A_PFACC, A_PFADD, A_PFCMPEQ, A_PFCMPGE, A_PFCMPGT,
  189. A_PFMAX, A_PFMIN, A_PFMUL, A_PFRCP, A_PFRCPIT1, A_PFRCPIT2,
  190. A_PFRSQIT1, A_PFRSQRT, A_PFSUB, A_PFSUBR, A_PI2FD,
  191. A_PMACHRIW, A_PMADDWD, A_PMAGW, A_PMULHRIW, A_PMULHRWA,
  192. A_PMULHRWC, A_PMULHW, A_PMULLW, A_PMVGEZB, A_PMVLZB, A_PMVNZB,
  193. A_PMVZB, A_POP, A_POPA, A_POPAD, A_POPAW, A_POPF, A_POPFD,
  194. A_POPFW, A_POR, A_PREFETCH, A_PREFETCHW,
  195. A_PSLLD, A_PSLLQ, A_PSLLW, A_PSRAD, A_PSRAW,
  196. A_PSRLD, A_PSRLQ, A_PSRLW, A_PSUBB, A_PSUBD, A_PSUBSB,
  197. A_PSUBSIW, A_PSUBSW, A_PSUBUSB, A_PSUBUSW, A_PSUBW, A_PUNPCKHBW,
  198. A_PUNPCKHDQ, A_PUNPCKHWD, A_PUNPCKLBW, A_PUNPCKLDQ, A_PUNPCKLWD,
  199. A_PUSH, A_PUSHA, A_PUSHAD, A_PUSHAW, A_PUSHF, A_PUSHFD,
  200. A_PUSHFW, A_PXOR, A_RCL, A_RCR, A_RDMSR, A_RDPMC, A_RDTSC,
  201. A_RESB, A_RET, A_RETF, A_RETN,
  202. A_ROL, A_ROR, A_RSM, A_SAHF, A_SAL, A_SALC, A_SAR, A_SBB,
  203. A_SCASB, A_SCASD, A_SCASW, A_SGDT, A_SHL, A_SHLD, A_SHR, A_SHRD,
  204. A_SIDT, A_SLDT, A_SMI, A_SMSW, A_STC, A_STD, A_STI, A_STOSB,
  205. A_STOSD, A_STOSW, A_STR, A_SUB, A_TEST, A_UMOV, A_VERR, A_VERW,
  206. A_WAIT, A_WBINVD, A_WRMSR, A_XADD, A_XBTS, A_XCHG, A_XLAT, A_XLATB,
  207. A_XOR, A_CMOVcc, A_Jcc, A_SETcc
  208. );
  209. op2strtable=array[tasmop] of string[10];
  210. const
  211. firstop = low(tasmop);
  212. lastop = high(tasmop);
  213. AsmPrefixes = 6;
  214. AsmPrefix : array[0..AsmPrefixes-1] of TasmOP =(
  215. A_LOCK,A_REP,A_REPE,A_REPNE,A_REPNZ,A_REPZ
  216. );
  217. AsmOverrides = 6;
  218. AsmOverride : array[0..AsmOverrides-1] of TasmOP =(
  219. A_CS,A_ES,A_DS,A_FS,A_GS,A_SS
  220. );
  221. {$ifdef INTELOP}
  222. int_op2str:op2strtable=('<none>',
  223. { prefixes }
  224. 'lock','rep','repe','repne','repnz','repz',
  225. 'segcs','seges','segds','segfs','seggs','segss',
  226. { normal }
  227. 'aaa', 'aad', 'aam', 'aas', 'adc', 'add', 'and', 'arpl',
  228. 'bound', 'bsf', 'bsr', 'bswap', 'bt', 'btc', 'btr', 'bts',
  229. 'call', 'cbw', 'cdq', 'clc', 'cld', 'cli', 'clts', 'cmc', 'cmp',
  230. 'cmpsb', 'cmpsd', 'cmpsw', 'cmpxchg', 'cmpxchg486', 'cmpxchg8b',
  231. 'cpuid', 'cwd', 'cwde', 'daa', 'das', 'dec', 'div', 'emms',
  232. 'enter', 'equ', 'f2xm1', 'fabs',
  233. 'fadd', 'faddp', 'fbld', 'fbstp', 'fchs', 'fclex', 'fcmovb',
  234. 'fcmovbe', 'fcmove', 'fcmovnb', 'fcmovnbe', 'fcmovne',
  235. 'fcmovnu', 'fcmovu', 'fcom', 'fcomi', 'fcomip', 'fcomp',
  236. 'fcompp', 'fcos', 'fdecstp', 'fdisi', 'fdiv', 'fdivp', 'fdivr',
  237. 'fdivrp',
  238. 'femms',
  239. 'feni', 'ffree', 'fiadd', 'ficom', 'ficomp', 'fidiv',
  240. 'fidivr', 'fild', 'fimul', 'fincstp', 'finit', 'fist', 'fistp',
  241. 'fisub', 'fisubr', 'fld', 'fld1', 'fldcw', 'fldenv', 'fldl2e',
  242. 'fldl2t', 'fldlg2', 'fldln2', 'fldpi', 'fldz', 'fmul', 'fmulp',
  243. 'fnclex', 'fndisi', 'fneni', 'fninit', 'fnop', 'fnsave',
  244. 'fnstcw', 'fnstenv', 'fnstsw', 'fpatan', 'fprem', 'fprem1',
  245. 'fptan', 'frndint', 'frstor', 'fsave', 'fscale', 'fsetpm',
  246. 'fsin', 'fsincos', 'fsqrt', 'fst', 'fstcw', 'fstenv', 'fstp',
  247. 'fstsw', 'fsub', 'fsubp', 'fsubr', 'fsubrp', 'ftst', 'fucom',
  248. 'fucomi', 'fucomip', 'fucomp', 'fucompp', 'fwait', 'fxam', 'fxch',
  249. 'fxtract', 'fyl2x', 'fyl2xp1', 'hlt', 'ibts', 'icebp', 'idiv',
  250. 'imul', 'in', 'inc', 'insb', 'insd', 'insw', 'int',
  251. 'int01', 'int1', 'int3', 'into', 'invd', 'invlpg', 'iret',
  252. 'iretd', 'iretw', 'jcxz', 'jecxz', 'jmp', 'lahf', 'lar', 'lds',
  253. 'lea', 'leave', 'les', 'lfs', 'lgdt', 'lgs', 'lidt', 'lldt',
  254. 'lmsw', 'loadall', 'loadall286', 'lodsb', 'lodsd', 'lodsw',
  255. 'loop', 'loope', 'loopne', 'loopnz', 'loopz', 'lsl', 'lss',
  256. 'ltr', 'mov', 'movd', 'movq', 'movsb', 'movsd', 'movsw',
  257. 'movsx', 'movzx', 'mul', 'neg', 'nop', 'not', 'or', 'out',
  258. 'outsb', 'outsd', 'outsw', 'packssdw', 'packsswb', 'packuswb',
  259. 'paddb', 'paddd', 'paddsb', 'paddsiw', 'paddsw', 'paddusb',
  260. 'paddusw', 'paddw', 'pand', 'pandn', 'paveb',
  261. 'pavgusb', 'pcmpeqb',
  262. 'pcmpeqd', 'pcmpeqw', 'pcmpgtb', 'pcmpgtd', 'pcmpgtw',
  263. 'pdistib',
  264. 'pf2id', 'pfacc', 'pfadd', 'pfcmpeq', 'pfcmpge', 'pfcmpgt',
  265. 'pfmax', 'pfmin', 'pfmul', 'pfrcp', 'pfrcpit1', 'pfrcpit2',
  266. 'pfrsqit1', 'pfrsqrt', 'pfsub', 'pfsubr', 'pi2fd',
  267. 'pmachriw', 'pmaddwd', 'pmagw', 'pmulhriw', 'pmulhrwa', 'pmulhrwc',
  268. 'pmulhw', 'pmullw', 'pmvgezb', 'pmvlzb', 'pmvnzb',
  269. 'pmvzb', 'pop', 'popa', 'popad', 'popaw', 'popf', 'popfd',
  270. 'popfw', 'por',
  271. 'prefetch', 'prefetchw', 'pslld', 'psllq', 'psllw', 'psrad', 'psraw',
  272. 'psrld', 'psrlq', 'psrlw', 'psubb', 'psubd', 'psubsb',
  273. 'psubsiw', 'psubsw', 'psubusb', 'psubusw', 'psubw', 'punpckhbw',
  274. 'punpckhdq', 'punpckhwd', 'punpcklbw', 'punpckldq', 'punpcklwd',
  275. 'push', 'pusha', 'pushad', 'pushaw', 'pushf', 'pushfd',
  276. 'pushfw', 'pxor', 'rcl', 'rcr', 'rdmsr', 'rdpmc', 'rdtsc',
  277. 'resb', 'ret', 'retf', 'retn',
  278. 'rol', 'ror', 'rsm', 'sahf', 'sal', 'salc', 'sar', 'sbb',
  279. 'scasb', 'scasd', 'scasw', 'sgdt', 'shl', 'shld', 'shr', 'shrd',
  280. 'sidt', 'sldt', 'smi', 'smsw', 'stc', 'std', 'sti', 'stosb',
  281. 'stosd', 'stosw', 'str', 'sub', 'test', 'umov', 'verr', 'verw',
  282. 'wait', 'wbinvd', 'wrmsr', 'xadd', 'xbts', 'xchg', 'xlat', 'xlatb',
  283. 'xor','cmov','j','set'
  284. );
  285. {$endif INTELOP}
  286. {$ifdef ATTOP}
  287. att_op2str:op2strtable=('<none>',
  288. { prefixes }
  289. 'lock','rep','repe','repne','repnz','repz',
  290. 'cs','es','ds','fs','gs','ss',
  291. { normal }
  292. 'aaa', 'aad', 'aam', 'aas', 'adc', 'add', 'and', 'arpl',
  293. 'bound', 'bsf', 'bsr', 'bswap', 'bt', 'btc', 'btr', 'bts',
  294. 'call', 'cbtw', 'cltd', 'clc', 'cld', 'cli', 'clts', 'cmc', 'cmp',
  295. 'cmpsb', 'cmpsl', 'cmpsw', 'cmpxchg', 'cmpxchg486', 'cmpxchg8b',
  296. 'cpuid', 'cwtd', 'cwtl', 'daa', 'das', 'dec', 'div',
  297. 'emms', 'enter', 'equ', 'f2xm1', 'fabs',
  298. 'fadd', 'faddp', 'fbld', 'fbstp', 'fchs', 'fclex', 'fcmovb',
  299. 'fcmovbe', 'fcmove', 'fcmovnb', 'fcmovnbe', 'fcmovne',
  300. 'fcmovnu', 'fcmovu', 'fcom', 'fcomi', 'fcomip', 'fcomp',
  301. 'fcompp', 'fcos', 'fdecstp', 'fdisi', 'fdiv', 'fdivp', 'fdivr',
  302. 'fdivrp', 'femms',
  303. 'feni', 'ffree', 'fiadd', 'ficom', 'ficomp', 'fidiv',
  304. 'fidivr', 'fild', 'fimul', 'fincstp', 'finit', 'fist', 'fistp',
  305. 'fisub', 'fisubr', 'fld', 'fld1', 'fldcw', 'fldenv', 'fldl2e',
  306. 'fldl2t', 'fldlg2', 'fldln2', 'fldpi', 'fldz', 'fmul', 'fmulp',
  307. 'fnclex', 'fndisi', 'fneni', 'fninit', 'fnop', 'fnsave',
  308. 'fnstcw', 'fnstenv', 'fnstsw', 'fpatan', 'fprem', 'fprem1',
  309. 'fptan', 'frndint', 'frstor', 'fsave', 'fscale', 'fsetpm',
  310. 'fsin', 'fsincos', 'fsqrt', 'fst', 'fstcw', 'fstenv', 'fstp',
  311. 'fstsw', 'fsub', 'fsubp', 'fsubr', 'fsubrp', 'ftst', 'fucom',
  312. 'fucomi', 'fucomip', 'fucomp', 'fucompp', 'fwait', 'fxam', 'fxch',
  313. 'fxtract', 'fyl2x', 'fyl2xp1', 'hlt', 'ibts', 'icebp', 'idiv',
  314. 'imul', 'in', 'inc', 'insb', 'insl', 'insw', 'int',
  315. 'int01', 'int1', 'int3', 'into', 'invd', 'invlpg', 'iret',
  316. 'iretd', 'iretw', 'jcxz', 'jecxz', 'jmp', 'lahf', 'lar', 'lds',
  317. 'lea', 'leave', 'les', 'lfs', 'lgdt', 'lgs', 'lidt', 'lldt',
  318. 'lmsw', 'loadall', 'loadall286', 'lodsb', 'lodsl', 'lodsw',
  319. 'loop', 'loope', 'loopne', 'loopnz', 'loopz', 'lsl', 'lss',
  320. 'ltr', 'mov', 'movd', 'movq', 'movsb', 'movsl', 'movsw',
  321. 'movs', 'movz', 'mul', 'neg', 'nop', 'not', 'or', 'out',
  322. 'outsb', 'outsl', 'outsw', 'packssd', 'packssw', 'packusw',
  323. 'paddb', 'paddd', 'paddsb', 'paddsiw', 'paddsw', 'paddusb',
  324. 'paddusw', 'paddw', 'pand', 'pandn', 'paveb',
  325. 'pavgusb', 'pcmpeqb',
  326. 'pcmpeqd', 'pcmpeqw', 'pcmpgtb', 'pcmpgtd', 'pcmpgtw',
  327. 'pdistib',
  328. 'pf2id', 'pfacc', 'pfadd', 'pfcmpeq', 'pfcmpge', 'pfcmpgt',
  329. 'pfmax', 'pfmin', 'pfmul', 'pfrcp', 'pfrcpit1', 'pfrcpit2',
  330. 'pfrsqit1', 'pfrsqrt', 'pfsub', 'pfsubr', 'pi2fd',
  331. 'pmachriw', 'pmaddwd', 'pmagw', 'pmulhriw', 'pmulhrwa', 'pmulhrwc',
  332. 'pmulhw', 'pmullw', 'pmvgezb', 'pmvlzb', 'pmvnzb',
  333. 'pmvzb', 'pop', 'popa', 'popal', 'popaw', 'popf', 'popfl',
  334. 'popfw', 'por',
  335. 'prefetch', 'prefetchw', 'pslld', 'psllq', 'psllw', 'psrad', 'psraw',
  336. 'psrld', 'psrlq', 'psrlw', 'psubb', 'psubd', 'psubsb',
  337. 'psubsiw', 'psubsw', 'psubusb', 'psubusw', 'psubw', 'punpckhbw',
  338. 'punpckhdq', 'punpckhwd', 'punpcklbw', 'punpckldq', 'punpcklwd',
  339. 'push', 'pusha', 'pushal', 'pushaw', 'pushf', 'pushfl',
  340. 'pushfw', 'pxor', 'rcl', 'rcr', 'rdmsr', 'rdpmc', 'rdtsc',
  341. 'resb', 'ret', 'retf', 'retn',
  342. 'rol', 'ror', 'rsm', 'sahf', 'sal', 'salc', 'sar', 'sbb',
  343. 'scasb', 'scasl', 'scasw', 'sgdt', 'shl', 'shld', 'shr', 'shrd',
  344. 'sidt', 'sldt', 'smi', 'smsw', 'stc', 'std', 'sti', 'stosb',
  345. 'stosl', 'stosw', 'str', 'sub', 'test', 'umov', 'verr', 'verw',
  346. 'wait', 'wbinvd', 'wrmsr', 'xadd', 'xbts', 'xchg', 'xlat', 'xlatb',
  347. 'xor','cmov','j','set'
  348. );
  349. {$endif ATTOP}
  350. {*****************************************************************************
  351. Operand Sizes
  352. *****************************************************************************}
  353. type
  354. topsize = (S_NO,
  355. S_B,S_W,S_L,S_BW,S_BL,S_WL,
  356. S_IS,S_IL,S_IQ,
  357. S_FS,S_FL,S_FX,S_D,S_Q,S_FV
  358. );
  359. const
  360. { Intel style operands ! }
  361. opsize_2_type:array[0..2,topsize] of longint=(
  362. (OT_NONE,
  363. OT_BITS8,OT_BITS16,OT_BITS32,OT_BITS16,OT_BITS32,OT_BITS32,
  364. OT_BITS16,OT_BITS32,OT_BITS64,
  365. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64
  366. ),
  367. (OT_NONE,
  368. OT_BITS8,OT_BITS16,OT_BITS32,OT_BITS8,OT_BITS8,OT_BITS16,
  369. OT_BITS16,OT_BITS32,OT_BITS64,
  370. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64
  371. ),
  372. (OT_NONE,
  373. OT_BITS8,OT_BITS16,OT_BITS32,OT_NONE,OT_NONE,OT_NONE,
  374. OT_BITS16,OT_BITS32,OT_BITS64,
  375. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64
  376. )
  377. );
  378. {$ifdef ATTOP}
  379. att_opsize2str : array[topsize] of string[2] = ('',
  380. 'b','w','l','bw','bl','wl',
  381. 's','l','q',
  382. 's','l','t','d','q','v'
  383. );
  384. {$endif}
  385. {*****************************************************************************
  386. Conditions
  387. *****************************************************************************}
  388. type
  389. TAsmCond=(C_None,
  390. C_A,C_AE,C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_NA,C_NAE,
  391. C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_NO,C_NP,
  392. C_NS,C_NZ,C_O,C_P,C_PE,C_PO,C_S,C_Z
  393. );
  394. const
  395. cond2str:array[TAsmCond] of string[3]=('',
  396. 'a', 'ae', 'b', 'be', 'c', 'e', 'g', 'ge', 'l', 'le', 'na', 'nae',
  397. 'nb', 'nbe', 'nc', 'ne', 'ng', 'nge', 'nl', 'nle', 'no', 'np',
  398. 'ns', 'nz', 'o', 'p', 'pe', 'po', 's', 'z'
  399. );
  400. inverse_cond:array[TAsmCond] of TAsmCond=(C_None,
  401. C_NA,C_NAE,C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_A,C_AE,
  402. C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_O,C_P,
  403. C_S,C_Z,C_NO,C_NP,C_NP,C_P,C_NS,C_NZ
  404. );
  405. const
  406. CondAsmOps=3;
  407. CondAsmOp:array[0..CondAsmOps-1] of TasmOp=(
  408. A_CMOVcc, A_Jcc, A_SETcc
  409. );
  410. CondAsmOpStr:array[0..CondAsmOps-1] of string[4]=(
  411. 'CMOV','J','SET'
  412. );
  413. {*****************************************************************************
  414. Registers
  415. *****************************************************************************}
  416. type
  417. { enumeration for registers, don't change the order }
  418. { it's used by the register size conversions }
  419. tregister = (R_NO,
  420. R_EAX,R_ECX,R_EDX,R_EBX,R_ESP,R_EBP,R_ESI,R_EDI,
  421. R_AX,R_CX,R_DX,R_BX,R_SP,R_BP,R_SI,R_DI,
  422. R_AL,R_CL,R_DL,R_BL,R_AH,R_CH,R_BH,R_DH,
  423. R_CS,R_DS,R_ES,R_SS,R_FS,R_GS,
  424. R_ST,R_ST0,R_ST1,R_ST2,R_ST3,R_ST4,R_ST5,R_ST6,R_ST7,
  425. R_DR0,R_DR1,R_DR2,R_DR3,R_DR6,R_DR7,
  426. R_CR0,R_CR2,R_CR3,R_CR4,
  427. R_TR3,R_TR4,R_TR5,R_TR6,R_TR7,
  428. R_MM0,R_MM1,R_MM2,R_MM3,R_MM4,R_MM5,R_MM6,R_MM7,
  429. R_XMM0,R_XMM1,R_XMM2,R_XMM3,R_XMM4,R_XMM5,R_XMM6,R_XMM7
  430. );
  431. tregisterset = set of tregister;
  432. reg2strtable = array[tregister] of string[6];
  433. const
  434. firstreg = low(tregister);
  435. lastreg = high(tregister);
  436. firstsreg = R_CS;
  437. lastsreg = R_GS;
  438. regset8bit : tregisterset = [R_AL..R_DH];
  439. regset16bit : tregisterset = [R_AX..R_DI,R_CS..R_SS];
  440. regset32bit : tregisterset = [R_EAX..R_EDI];
  441. { Convert reg to opsize }
  442. reg_2_opsize:array[firstreg..lastreg] of topsize = (S_NO,
  443. S_L,S_L,S_L,S_L,S_L,S_L,S_L,S_L,
  444. S_W,S_W,S_W,S_W,S_W,S_W,S_W,S_W,
  445. S_B,S_B,S_B,S_B,S_B,S_B,S_B,S_B,
  446. S_W,S_W,S_W,S_W,S_W,S_W,
  447. S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,
  448. S_L,S_L,S_L,S_L,S_L,S_L,
  449. S_L,S_L,S_L,S_L,
  450. S_L,S_L,S_L,S_L,S_L,
  451. S_D,S_D,S_D,S_D,S_D,S_D,S_D,S_D,
  452. S_D,S_D,S_D,S_D,S_D,S_D,S_D,S_D
  453. );
  454. { Convert reg to operand type }
  455. reg_2_type:array[firstreg..lastreg] of longint = (OT_NONE,
  456. OT_REG_EAX,OT_REG_ECX,OT_REG32,OT_REG32,OT_REG32,OT_REG32,OT_REG32,OT_REG32,
  457. OT_REG_AX,OT_REG_CX,OT_REG_DX,OT_REG16,OT_REG16,OT_REG16,OT_REG16,OT_REG16,
  458. OT_REG_AL,OT_REG_CL,OT_REG8,OT_REG8,OT_REG8,OT_REG8,OT_REG8,OT_REG8,
  459. OT_REG_CS,OT_REG_DESS,OT_REG_DESS,OT_REG_DESS,OT_REG_FSGS,OT_REG_FSGS,
  460. OT_FPU0,OT_FPU0,OT_FPUREG,OT_FPUREG,OT_FPUREG,OT_FPUREG,OT_FPUREG,OT_FPUREG,OT_FPUREG,
  461. OT_REG_DREG,OT_REG_DREG,OT_REG_DREG,OT_REG_DREG,OT_REG_DREG,OT_REG_DREG,
  462. OT_REG_CREG,OT_REG_CREG,OT_REG_CREG,OT_REG_CR4,
  463. OT_REG_TREG,OT_REG_TREG,OT_REG_TREG,OT_REG_TREG,OT_REG_TREG,
  464. OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,
  465. OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG,OT_MMXREG
  466. );
  467. {$ifdef INTELOP}
  468. int_reg2str : reg2strtable = ('',
  469. 'eax','ecx','edx','ebx','esp','ebp','esi','edi',
  470. 'ax','cx','dx','bx','sp','bp','si','di',
  471. 'al','cl','dl','bl','ah','ch','bh','dh',
  472. 'cs','ds','es','ss','fs','gs',
  473. 'st','st(0)','st(1)','st(2)','st(3)','st(4)','st(5)','st(6)','st(7)',
  474. 'dr0','dr1','dr2','dr3','dr6','dr7',
  475. 'cr0','cr2','cr3','cr4',
  476. 'tr3','tr4','tr5','tr6','tr7',
  477. 'mm0','mm1','mm2','mm3','mm4','mm5','mm6','mm7',
  478. 'xmm0','xmm1','xmm2','xmm3','xmm4','xmm5','xmm6','xmm7'
  479. );
  480. int_nasmreg2str : reg2strtable = ('',
  481. 'eax','ecx','edx','ebx','esp','ebp','esi','edi',
  482. 'ax','cx','dx','bx','sp','bp','si','di',
  483. 'al','cl','dl','bl','ah','ch','bh','dh',
  484. 'cs','ds','es','ss','fs','gs',
  485. 'st0','st0','st1','st2','st3','st4','st5','st6','st7',
  486. 'dr0','dr1','dr2','dr3','dr6','dr7',
  487. 'cr0','cr2','cr3','cr4',
  488. 'tr3','tr4','tr5','tr6','tr7',
  489. 'mm0','mm1','mm2','mm3','mm4','mm5','mm6','mm7',
  490. 'xmm0','xmm1','xmm2','xmm3','xmm4','xmm5','xmm6','xmm7'
  491. );
  492. {$endif}
  493. {$ifdef ATTREG}
  494. att_reg2str : reg2strtable = ('',
  495. '%eax','%ecx','%edx','%ebx','%esp','%ebp','%esi','%edi',
  496. '%ax','%cx','%dx','%bx','%sp','%bp','%si','%di',
  497. '%al','%cl','%dl','%bl','%ah','%ch','%bh','%dh',
  498. '%cs','%ds','%es','%ss','%fs','%gs',
  499. '%st','%st(0)','%st(1)','%st(2)','%st(3)','%st(4)','%st(5)','%st(6)','%st(7)',
  500. '%dr0','%dr1','%dr2','%dr3','%dr6','%dr7',
  501. '%cr0','%cr2','%cr3','%cr4',
  502. '%tr3','%tr4','%tr5','%tr6','%tr7',
  503. '%mm0','%mm1','%mm2','%mm3','%mm4','%mm5','%mm6','%mm7',
  504. '%xmm0','%xmm1','%xmm2','%xmm3','%xmm4','%xmm5','%xmm6','%xmm7'
  505. );
  506. {$endif ATTREG}
  507. {*****************************************************************************
  508. Flags
  509. *****************************************************************************}
  510. type
  511. TResFlags = (F_E,F_NE,F_G,F_L,F_GE,F_LE,F_C,F_NC,F_A,F_AE,F_B,F_BE);
  512. const
  513. { arrays for boolean location conversions }
  514. flag_2_cond : array[TResFlags] of TAsmCond =
  515. (C_E,C_NE,C_G,C_L,C_GE,C_LE,C_C,C_NC,C_A,C_AE,C_B,C_BE);
  516. {*****************************************************************************
  517. Reference
  518. *****************************************************************************}
  519. type
  520. trefoptions=(ref_none,ref_parafixup,ref_localfixup);
  521. { immediate/reference record }
  522. preference = ^treference;
  523. treference = packed record
  524. is_immediate : boolean; { is this used as reference or immediate }
  525. segment,
  526. base,
  527. index : tregister;
  528. scalefactor : byte;
  529. offset : longint;
  530. symbol : pasmsymbol;
  531. offsetfixup : longint;
  532. options : trefoptions;
  533. end;
  534. {*****************************************************************************
  535. Operand
  536. *****************************************************************************}
  537. type
  538. toptype=(top_none,top_reg,top_ref,top_const,top_symbol);
  539. toper=record
  540. ot : longint;
  541. case typ : toptype of
  542. top_none : ();
  543. top_reg : (reg:tregister);
  544. top_ref : (ref:preference);
  545. top_const : (val:longint);
  546. top_symbol : (sym:pasmsymbol;symofs:longint);
  547. end;
  548. {*****************************************************************************
  549. Generic Location
  550. *****************************************************************************}
  551. type
  552. TLoc=(
  553. LOC_INVALID, { added for tracking problems}
  554. LOC_FPU, { FPU stack }
  555. LOC_REGISTER, { in a processor register }
  556. LOC_MEM, { in memory }
  557. LOC_REFERENCE, { like LOC_MEM, but lvalue }
  558. LOC_JUMP, { boolean results only, jump to false or true label }
  559. LOC_FLAGS, { boolean results only, flags are set }
  560. LOC_CREGISTER, { Constant register which shouldn't be modified }
  561. LOC_MMXREGISTER, { MMX register }
  562. LOC_CMMXREGISTER { Constant MMX register }
  563. );
  564. plocation = ^tlocation;
  565. tlocation = packed record
  566. case loc : tloc of
  567. LOC_MEM,LOC_REFERENCE : (reference : treference);
  568. LOC_FPU : ();
  569. LOC_JUMP : ();
  570. LOC_FLAGS : (resflags : tresflags);
  571. LOC_INVALID : ();
  572. { it's only for better handling }
  573. LOC_MMXREGISTER : (mmxreg : tregister);
  574. { segment in reference at the same place as in loc_register }
  575. LOC_REGISTER,LOC_CREGISTER : (
  576. case longint of
  577. 1 : (register,segment,registerhigh : tregister);
  578. { overlay a registerlow }
  579. 2 : (registerlow : tregister);
  580. );
  581. end;
  582. {*****************************************************************************
  583. Constants
  584. *****************************************************************************}
  585. type
  586. tcpuflags = (cf_registers64);
  587. const
  588. general_registers = [R_EAX,R_EBX,R_ECX,R_EDX];
  589. registers_saved_on_cdecl = [R_ESI,R_EDI,R_EBX];
  590. { generic register names }
  591. stack_pointer = R_ESP;
  592. frame_pointer = R_EBP;
  593. self_pointer = R_ESI;
  594. accumulator = R_EAX;
  595. cpuflags : set of tcpuflags = [];
  596. { sizes }
  597. pointersize = 4;
  598. extended_size = 10;
  599. sizepostfix_pointer = S_L;
  600. {*****************************************************************************
  601. Instruction table
  602. *****************************************************************************}
  603. {$ifndef NOAG386BIN}
  604. type
  605. tinsentry=packed record
  606. opcode : tasmop;
  607. ops : byte;
  608. optypes : array[0..2] of longint;
  609. code : array[0..maxinfolen] of char;
  610. flags : longint;
  611. end;
  612. pinsentry=^tinsentry;
  613. TInsTabCache=array[TasmOp] of longint;
  614. PInsTabCache=^TInsTabCache;
  615. const
  616. InsTab:array[0..instabentries-1] of TInsEntry=
  617. {$i i386tab.inc}
  618. var
  619. InsTabCache : PInsTabCache;
  620. {$endif NOAG386BIN}
  621. {*****************************************************************************
  622. Helpers
  623. *****************************************************************************}
  624. const
  625. maxvarregs = 4;
  626. varregs : array[1..maxvarregs] of tregister =
  627. (R_EBX,R_EDX,R_ECX,R_EAX);
  628. function imm_2_type(l:longint):longint;
  629. { the following functions allow to convert registers }
  630. { for example reg8toreg32(R_AL) returns R_EAX }
  631. { for example reg16toreg32(R_AL) gives an undefined }
  632. { result }
  633. { these functions expects that the turn of }
  634. { tregister isn't changed }
  635. function reg8toreg16(reg : tregister) : tregister;
  636. function reg8toreg32(reg : tregister) : tregister;
  637. function reg16toreg8(reg : tregister) : tregister;
  638. function reg32toreg8(reg : tregister) : tregister;
  639. function reg32toreg16(reg : tregister) : tregister;
  640. function reg16toreg32(reg : tregister) : tregister;
  641. { these procedures must be defined by all target cpus }
  642. function regtoreg8(reg : tregister) : tregister;
  643. function regtoreg16(reg : tregister) : tregister;
  644. function regtoreg32(reg : tregister) : tregister;
  645. { can be ignored on 32 bit systems }
  646. function regtoreg64(reg : tregister) : tregister;
  647. { returns the operand prefix for a given register }
  648. function regsize(reg : tregister) : topsize;
  649. { resets all values of ref to defaults }
  650. procedure reset_reference(var ref : treference);
  651. { set mostly used values of a new reference }
  652. function new_reference(base : tregister;offset : longint) : preference;
  653. function newreference(const r : treference) : preference;
  654. procedure disposereference(var r : preference);
  655. function reg2str(r : tregister) : string;
  656. function is_calljmp(o:tasmop):boolean;
  657. implementation
  658. {$ifdef heaptrc}
  659. uses
  660. ppheap;
  661. {$endif heaptrc}
  662. {*****************************************************************************
  663. Helpers
  664. *****************************************************************************}
  665. function imm_2_type(l:longint):longint;
  666. begin
  667. if (l>=-128) and (l<=127) then
  668. imm_2_type:=OT_IMM8 or OT_SIGNED
  669. else
  670. if (l>=-255) and (l<=255) then
  671. imm_2_type:=OT_IMM8
  672. else
  673. if (l>=-32768) and (l<=32767) then
  674. imm_2_type:=OT_IMM16 or OT_SIGNED
  675. else
  676. if (l>=-65536) and (l<=65535) then
  677. imm_2_type:=OT_IMM16 or OT_SIGNED
  678. else
  679. imm_2_type:=OT_IMM32;
  680. end;
  681. function reg2str(r : tregister) : string;
  682. const
  683. a : array[R_NO..R_BL] of string[3] =
  684. ('','EAX','ECX','EDX','EBX','ESP','EBP','ESI','EDI',
  685. 'AX','CX','DX','BX','SP','BP','SI','DI',
  686. 'AL','CL','DL','BL');
  687. begin
  688. reg2str:=a[r];
  689. end;
  690. function is_calljmp(o:tasmop):boolean;
  691. begin
  692. case o of
  693. A_CALL,
  694. A_JCXZ,
  695. A_JECXZ,
  696. A_JMP,
  697. A_LOOP,
  698. A_Jcc :
  699. is_calljmp:=true;
  700. else
  701. is_calljmp:=false;
  702. end;
  703. end;
  704. procedure disposereference(var r : preference);
  705. begin
  706. dispose(r);
  707. r:=nil;
  708. end;
  709. function newreference(const r : treference) : preference;
  710. var
  711. p : preference;
  712. begin
  713. new(p);
  714. p^:=r;
  715. newreference:=p;
  716. end;
  717. function reg8toreg16(reg : tregister) : tregister;
  718. begin
  719. reg8toreg16:=reg32toreg16(reg8toreg32(reg));
  720. end;
  721. function reg16toreg8(reg : tregister) : tregister;
  722. begin
  723. reg16toreg8:=reg32toreg8(reg16toreg32(reg));
  724. end;
  725. function reg16toreg32(reg : tregister) : tregister;
  726. begin
  727. reg16toreg32:=tregister(byte(reg)-byte(R_EDI));
  728. end;
  729. function reg32toreg16(reg : tregister) : tregister;
  730. begin
  731. reg32toreg16:=tregister(byte(reg)+byte(R_EDI));
  732. end;
  733. function reg32toreg8(reg : tregister) : tregister;
  734. begin
  735. reg32toreg8:=tregister(byte(reg)+byte(R_DI));
  736. end;
  737. function reg8toreg32(reg : tregister) : tregister;
  738. begin
  739. reg8toreg32:=tregister(byte(reg)-byte(R_DI));
  740. end;
  741. function regtoreg8(reg : tregister) : tregister;
  742. begin
  743. regtoreg8:=reg32toreg8(reg);
  744. end;
  745. function regtoreg16(reg : tregister) : tregister;
  746. begin
  747. regtoreg16:=reg32toreg16(reg);
  748. end;
  749. function regtoreg32(reg : tregister) : tregister;
  750. begin
  751. regtoreg32:=reg;
  752. end;
  753. function regtoreg64(reg : tregister) : tregister;
  754. begin
  755. { to avoid warning }
  756. regtoreg64:=R_NO;
  757. end;
  758. function regsize(reg : tregister) : topsize;
  759. begin
  760. if reg in regset8bit then
  761. regsize:=S_B
  762. else if reg in regset16bit then
  763. regsize:=S_W
  764. else if reg in regset32bit then
  765. regsize:=S_L;
  766. end;
  767. procedure reset_reference(var ref : treference);
  768. begin
  769. FillChar(ref,sizeof(treference),0);
  770. end;
  771. function new_reference(base : tregister;offset : longint) : preference;
  772. var
  773. r : preference;
  774. begin
  775. new(r);
  776. FillChar(r^,sizeof(treference),0);
  777. r^.base:=base;
  778. r^.offset:=offset;
  779. new_reference:=r;
  780. end;
  781. {*****************************************************************************
  782. Instruction table
  783. *****************************************************************************}
  784. var
  785. saveexit : pointer;
  786. procedure FreeInsTabCache;{$ifndef FPC}far;{$endif}
  787. begin
  788. exitproc:=saveexit;
  789. {$ifndef NOAG386BIN}
  790. dispose(instabcache);
  791. {$endif NOAG386BIN}
  792. end;
  793. procedure BuildInsTabCache;
  794. {$ifndef NOAG386BIN}
  795. var
  796. i : longint;
  797. {$endif}
  798. begin
  799. {$ifndef NOAG386BIN}
  800. new(instabcache);
  801. FillChar(instabcache^,sizeof(tinstabcache),$ff);
  802. i:=0;
  803. while (i<InsTabEntries) do
  804. begin
  805. if InsTabCache^[InsTab[i].OPcode]=-1 then
  806. InsTabCache^[InsTab[i].OPcode]:=i;
  807. inc(i);
  808. end;
  809. {$endif NOAG386BIN}
  810. saveexit:=exitproc;
  811. exitproc:=@FreeInsTabCache;
  812. end;
  813. begin
  814. BuildInsTabCache;
  815. end.
  816. {
  817. $Log$
  818. Revision 1.5 1999-05-27 19:44:34 peter
  819. * removed oldasm
  820. * plabel -> pasmlabel
  821. * -a switches to source writing automaticly
  822. * assembler readers OOPed
  823. * asmsymbol automaticly external
  824. * jumptables and other label fixes for asm readers
  825. Revision 1.4 1999/05/17 14:33:50 pierre
  826. uses heaptrc need for extrainfo with heaptrc
  827. Revision 1.3 1999/05/12 00:19:51 peter
  828. * removed R_DEFAULT_SEG
  829. * uniform float names
  830. Revision 1.2 1999/05/11 16:30:00 peter
  831. * more noag386bin defines, so tp7 can compile at least
  832. Revision 1.1 1999/05/01 13:24:23 peter
  833. * merged nasm compiler
  834. * old asm moved to oldasm/
  835. Revision 1.13 1999/04/14 09:07:43 peter
  836. * asm reader improvements
  837. Revision 1.12 1999/04/10 16:14:09 peter
  838. * fixed optimizer
  839. Revision 1.11 1999/03/31 13:55:33 peter
  840. * assembler inlining working for ag386bin
  841. Revision 1.10 1999/03/29 16:05:50 peter
  842. * optimizer working for ag386bin
  843. Revision 1.9 1999/03/26 00:01:14 peter
  844. * first things for optimizer (compiles but cycle crashes)
  845. Revision 1.8 1999/03/06 17:24:21 peter
  846. * rewritten intel parser a lot, especially reference reading
  847. * size checking added for asm parsers
  848. Revision 1.7 1999/03/02 02:56:20 peter
  849. + stabs support for binary writers
  850. * more fixes and missing updates from the previous commit :(
  851. Revision 1.6 1999/03/01 15:46:22 peter
  852. * ag386bin finally make cycles correct
  853. * prefixes are now also normal opcodes
  854. Revision 1.5 1999/02/26 00:48:29 peter
  855. * assembler writers fixed for ag386bin
  856. Revision 1.4 1999/02/25 21:03:04 peter
  857. * ag386bin updates
  858. + coff writer
  859. Revision 1.3 1999/02/22 02:44:18 peter
  860. * ag386bin doesn't use i386.pas anymore
  861. Revision 1.2 1999/02/22 02:16:03 peter
  862. * updates for ag386bin
  863. Revision 1.1 1999/02/16 17:59:38 peter
  864. + initial files
  865. }