rax86.pas 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. {
  2. Copyright (c) 1998-2002 by Carl Eric Codere and Peter Vreman
  3. Handles the common x86 assembler reader routines
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. {
  18. Contains the common x86 (i386 and x86-64) assembler reader routines.
  19. }
  20. unit rax86;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. aasmbase,aasmtai,aasmdata,aasmcpu,
  25. cpubase,rautils,cclasses;
  26. { Parser helpers }
  27. function is_prefix(t:tasmop):boolean;
  28. function is_override(t:tasmop):boolean;
  29. Function CheckPrefix(prefixop,op:tasmop): Boolean;
  30. Function CheckOverride(overrideop,op:tasmop): Boolean;
  31. Procedure FWaitWarning;
  32. type
  33. Tx86Operand=class(TOperand)
  34. opsize : topsize;
  35. Procedure SetSize(_size:longint;force:boolean);override;
  36. Procedure SetCorrectSize(opcode:tasmop);override;
  37. Function CheckOperand: boolean; override;
  38. { handles the @Code symbol }
  39. Procedure SetupCode;
  40. { handles the @Data symbol }
  41. Procedure SetupData;
  42. end;
  43. { Operands are always in AT&T order.
  44. Intel reader attaches them right-to-left, then shifts to start with 1 }
  45. Tx86Instruction=class(TInstruction)
  46. opsize : topsize;
  47. constructor Create(optype : tcoperand);override;
  48. { Operand sizes }
  49. procedure AddReferenceSizes; virtual;
  50. procedure SetInstructionOpsize;
  51. procedure CheckOperandSizes;
  52. procedure CheckNonCommutativeOpcodes;
  53. { Additional actions required by specific reader }
  54. procedure FixupOpcode;virtual;
  55. { opcode adding }
  56. function ConcatInstruction(p : TAsmList) : tai;override;
  57. end;
  58. const
  59. AsmPrefixes = 8{$ifdef i8086}+2{$endif i8086};
  60. AsmPrefix : array[0..AsmPrefixes-1] of TasmOP =(
  61. A_LOCK,A_REP,A_REPE,A_REPNE,A_REPNZ,A_REPZ,A_XACQUIRE,A_XRELEASE{$ifdef i8086},A_REPC,A_REPNC{$endif i8086}
  62. );
  63. AsmOverrides = 6;
  64. AsmOverride : array[0..AsmOverrides-1] of TasmOP =(
  65. A_SEGCS,A_SEGES,A_SEGDS,A_SEGFS,A_SEGGS,A_SEGSS
  66. );
  67. CondAsmOps=3;
  68. CondAsmOp:array[0..CondAsmOps-1] of TasmOp=(
  69. A_CMOVcc, A_Jcc, A_SETcc
  70. );
  71. CondAsmOpStr:array[0..CondAsmOps-1] of string[4]=(
  72. 'CMOV','J','SET'
  73. );
  74. implementation
  75. uses
  76. globtype,globals,systems,verbose,
  77. procinfo,
  78. cgbase,cgutils,
  79. itcpugas,cgx86, cutils;
  80. {*****************************************************************************
  81. Parser Helpers
  82. *****************************************************************************}
  83. function is_prefix(t:tasmop):boolean;
  84. var
  85. i : longint;
  86. Begin
  87. is_prefix:=false;
  88. for i:=1 to AsmPrefixes do
  89. if t=AsmPrefix[i-1] then
  90. begin
  91. is_prefix:=true;
  92. exit;
  93. end;
  94. end;
  95. function is_override(t:tasmop):boolean;
  96. var
  97. i : longint;
  98. Begin
  99. is_override:=false;
  100. for i:=1 to AsmOverrides do
  101. if t=AsmOverride[i-1] then
  102. begin
  103. is_override:=true;
  104. exit;
  105. end;
  106. end;
  107. Function CheckPrefix(prefixop,op:tasmop): Boolean;
  108. { Checks if the prefix is valid with the following opcode }
  109. { return false if not, otherwise true }
  110. Begin
  111. CheckPrefix := TRUE;
  112. (* Case prefix of
  113. A_REP,A_REPNE,A_REPE:
  114. Case opcode Of
  115. A_SCASB,A_SCASW,A_SCASD,
  116. A_INS,A_OUTS,A_MOVS,A_CMPS,A_LODS,A_STOS:;
  117. Else
  118. Begin
  119. CheckPrefix := FALSE;
  120. exit;
  121. end;
  122. end; { case }
  123. A_LOCK:
  124. Case opcode Of
  125. A_BT,A_BTS,A_BTR,A_BTC,A_XCHG,A_ADD,A_OR,A_ADC,A_SBB,A_AND,A_SUB,
  126. A_XOR,A_NOT,A_NEG,A_INC,A_DEC:;
  127. Else
  128. Begin
  129. CheckPrefix := FALSE;
  130. Exit;
  131. end;
  132. end; { case }
  133. A_NONE: exit; { no prefix here }
  134. else
  135. CheckPrefix := FALSE;
  136. end; { end case } *)
  137. end;
  138. Function CheckOverride(overrideop,op:tasmop): Boolean;
  139. { Check if the override is valid, and if so then }
  140. { update the instr variable accordingly. }
  141. Begin
  142. CheckOverride := true;
  143. { Case instr.getinstruction of
  144. A_MOVS,A_XLAT,A_CMPS:
  145. Begin
  146. CheckOverride := TRUE;
  147. Message(assem_e_segment_override_not_supported);
  148. end
  149. end }
  150. end;
  151. Procedure FWaitWarning;
  152. begin
  153. if (target_info.system=system_i386_GO32V2) and (cs_fp_emulation in current_settings.moduleswitches) then
  154. Message(asmr_w_fwait_emu_prob);
  155. end;
  156. {*****************************************************************************
  157. TX86Operand
  158. *****************************************************************************}
  159. Procedure Tx86Operand.SetSize(_size:longint;force:boolean);
  160. begin
  161. inherited SetSize(_size,force);
  162. { OS_64 will be set to S_L and be fixed later
  163. in SetCorrectSize }
  164. // multimedia register
  165. case _size of
  166. 16: size := OS_M128;
  167. 32: size := OS_M256;
  168. end;
  169. {$ifdef i8086}
  170. { allows e.g. using 32-bit registers in i8086 inline asm }
  171. if size in [OS_32,OS_S32] then
  172. opsize:=S_L
  173. else
  174. {$endif i8086}
  175. opsize:=TCGSize2Opsize[size];
  176. end;
  177. Procedure Tx86Operand.SetCorrectSize(opcode:tasmop);
  178. begin
  179. if gas_needsuffix[opcode]=attsufFPU then
  180. begin
  181. case size of
  182. OS_32 : opsize:=S_FS;
  183. OS_64 : opsize:=S_FL;
  184. end;
  185. end
  186. else if gas_needsuffix[opcode]=attsufFPUint then
  187. begin
  188. case size of
  189. OS_16 : opsize:=S_IS;
  190. OS_32 : opsize:=S_IL;
  191. OS_64 : opsize:=S_IQ;
  192. end;
  193. end
  194. else if gas_needsuffix[opcode]=AttSufMM then
  195. begin
  196. if (opr.typ=OPR_Reference) then
  197. begin
  198. case size of
  199. OS_32 : size := OS_M32;
  200. OS_64 : size := OS_M64;
  201. end;
  202. end;
  203. end
  204. else
  205. begin
  206. if size=OS_64 then
  207. opsize:=S_Q;
  208. end;
  209. end;
  210. Function Tx86Operand.CheckOperand: boolean;
  211. begin
  212. result:=true;
  213. if (opr.typ=OPR_Reference) then
  214. begin
  215. if not hasvar then
  216. begin
  217. if (getsupreg(opr.ref.base)=RS_EBP) and (opr.ref.offset>0) then
  218. begin
  219. if current_procinfo.procdef.proccalloption=pocall_register then
  220. message(asmr_w_no_direct_ebp_for_parameter)
  221. else
  222. message(asmr_w_direct_ebp_for_parameter_regcall);
  223. end
  224. else if (getsupreg(opr.ref.base)=RS_EBP) and (opr.ref.offset<0) then
  225. message(asmr_w_direct_ebp_neg_offset)
  226. else if (getsupreg(opr.ref.base)=RS_ESP) and (opr.ref.offset<0) then
  227. message(asmr_w_direct_esp_neg_offset);
  228. end;
  229. if (cs_create_pic in current_settings.moduleswitches) and
  230. assigned(opr.ref.symbol) and
  231. not assigned(opr.ref.relsymbol) then
  232. begin
  233. if not(opr.ref.refaddr in [addr_pic,addr_pic_no_got]) then
  234. begin
  235. if (opr.ref.symbol.name <> '_GLOBAL_OFFSET_TABLE_') then
  236. begin
  237. message(asmr_e_need_pic_ref);
  238. result:=false;
  239. end
  240. else
  241. opr.ref.refaddr:=addr_pic;
  242. end
  243. else
  244. begin
  245. {$ifdef x86_64}
  246. { should probably be extended to i386, but there the situation
  247. is more complex and ELF-style PIC still need to be
  248. tested/debugged }
  249. if (opr.ref.symbol.bind in [AB_LOCAL,AB_PRIVATE_EXTERN]) and
  250. (opr.ref.refaddr=addr_pic) then
  251. message(asmr_w_useless_got_for_local)
  252. else if (opr.ref.symbol.bind in [AB_GLOBAL,AB_EXTERNAL,AB_COMMON,AB_WEAK_EXTERNAL]) and
  253. (opr.ref.refaddr=addr_pic_no_got) then
  254. message(asmr_w_global_access_without_got);
  255. {$endif x86_64}
  256. end;
  257. end;
  258. end;
  259. end;
  260. procedure Tx86Operand.SetupCode;
  261. begin
  262. {$ifdef i8086}
  263. opr.typ:=OPR_SYMBOL;
  264. opr.symofs:=0;
  265. opr.symbol:=current_asmdata.RefAsmSymbol(current_procinfo.procdef.mangledname,AT_FUNCTION);
  266. opr.symseg:=true;
  267. opr.sym_farproc_entry:=false;
  268. {$else i8086}
  269. Message(asmr_w_CODE_and_DATA_not_supported);
  270. {$endif i8086}
  271. end;
  272. procedure Tx86Operand.SetupData;
  273. begin
  274. {$ifdef i8086}
  275. InitRef;
  276. if current_settings.x86memorymodel=mm_huge then
  277. opr.ref.refaddr:=addr_fardataseg
  278. else
  279. opr.ref.refaddr:=addr_dgroup;
  280. {$else i8086}
  281. Message(asmr_w_CODE_and_DATA_not_supported);
  282. {$endif i8086}
  283. end;
  284. {*****************************************************************************
  285. T386Instruction
  286. *****************************************************************************}
  287. constructor Tx86Instruction.Create(optype : tcoperand);
  288. begin
  289. inherited Create(optype);
  290. Opsize:=S_NO;
  291. end;
  292. procedure Tx86Instruction.AddReferenceSizes;
  293. { this will add the sizes for references like [esi] which do not
  294. have the size set yet, it will take only the size if the other
  295. operand is a register }
  296. var
  297. operand2,i,j : longint;
  298. s : tasmsymbol;
  299. so : aint;
  300. ExistsMemRefNoSize: boolean;
  301. ExistsMemRef: boolean;
  302. ExistsConstNoSize: boolean;
  303. ExistsLocalSymSize: boolean;
  304. memrefsize: integer;
  305. memopsize: integer;
  306. memoffset: asizeint;
  307. begin
  308. ExistsMemRefNoSize := false;
  309. ExistsMemRef := false;
  310. ExistsConstNoSize := false;
  311. ExistsLocalSymSize := false;
  312. // EXIST A MEMORY- OR CONSTANT-OPERAND WITHOUT SIZE ?
  313. for i := 1 to ops do
  314. begin
  315. if operands[i].Opr.Typ in [OPR_REFERENCE, OPR_LOCAL] then
  316. begin
  317. ExistsMemRef := true;
  318. if (tx86operand(operands[i]).opsize = S_NO) then
  319. begin
  320. ExistsMemRefNoSize := true;
  321. case operands[i].opr.Typ of
  322. OPR_LOCAL: ExistsLocalSymSize := tx86operand(operands[i]).opr.localsym.getsize > 0;
  323. OPR_REFERENCE: ExistsLocalSymSize := true;
  324. end;
  325. end;
  326. end
  327. else if operands[i].Opr.Typ in [OPR_CONSTANT] then
  328. begin
  329. ExistsConstNoSize := tx86operand(operands[i]).opsize = S_NO;
  330. end;
  331. end;
  332. // ONLY SUPPORTED OPCODES WITH SSE- OR AVX-REGISTERS
  333. if (ExistsMemRef) and
  334. (MemRefInfo(opcode).ExistsSSEAVX) then
  335. begin
  336. // 1. WE HAVE AN SSE- OR AVX-OPCODE WITH MEMORY OPERAND
  337. if (not(ExistsMemRefNoSize)) or
  338. (ExistsLocalSymSize) then
  339. begin
  340. // 2. WE KNOWN THE MEMORYSIZE OF THE MEMORY-OPERAND OR WE CAN
  341. // CALC THE MEMORYSIZE
  342. // 3. CALC THE SIZE OF THE MEMORYOPERAND BY OPCODE-DEFINITION
  343. // 4. COMPARE THE SIZE FROM OPCODE-DEFINITION AND THE REAL MEMORY-OPERAND-SIZE
  344. // - validate memory-reference-size
  345. for i := 1 to ops do
  346. begin
  347. if (operands[i].Opr.Typ in [OPR_REFERENCE, OPR_LOCAL]) then
  348. begin
  349. memrefsize := -1;
  350. case MemRefInfo(opcode).MemRefSize of
  351. msiMem8: memrefsize := 8;
  352. msiMem16: memrefsize := 16;
  353. msiMem32: memrefsize := 32;
  354. msiMem64: memrefsize := 64;
  355. msiMem128: memrefsize := 128;
  356. msiMem256: memrefsize := 256;
  357. msiMemRegSize
  358. : for j := 1 to ops do
  359. begin
  360. if operands[j].Opr.Typ = OPR_REGISTER then
  361. begin
  362. if (tx86operand(operands[j]).opsize <> S_NO) and
  363. (tx86operand(operands[j]).size <> OS_NO) then
  364. begin
  365. case tx86operand(operands[j]).opsize of
  366. S_B : memrefsize := 8;
  367. S_W : memrefsize := 16;
  368. S_L : memrefsize := 32;
  369. S_Q : memrefsize := 64;
  370. S_XMM : memrefsize := 128;
  371. S_YMM : memrefsize := 256;
  372. else Internalerror(777200);
  373. end;
  374. break;
  375. end;
  376. end;
  377. end;
  378. end;
  379. if memrefsize > -1 then
  380. begin
  381. // CALC REAL-MEMORY-OPERAND-SIZE AND A POSSIBLE OFFSET
  382. // OFFSET:
  383. // e.g. PAND XMM0, [RAX + 16] =>> OFFSET = 16 BYTES
  384. // PAND XMM0, [RAX + a.b + 10] =>> OFFSET = 10 BYTES (a = record-variable)
  385. memopsize := 0;
  386. case operands[i].opr.typ of
  387. OPR_LOCAL: memopsize := operands[i].opr.localvarsize * 8;
  388. OPR_REFERENCE:
  389. if operands[i].opr.ref.refaddr = addr_pic then
  390. memopsize := sizeof(pint) * 8
  391. else
  392. memopsize := operands[i].opr.varsize * 8;
  393. end;
  394. if memopsize = 0 then memopsize := topsize2memsize[tx86operand(operands[i]).opsize];
  395. if (memopsize > 0) and
  396. (memrefsize > 0) then
  397. begin
  398. memoffset := 0;
  399. case operands[i].opr.typ of
  400. OPR_LOCAL:
  401. memoffset := operands[i].opr.localconstoffset;
  402. OPR_REFERENCE:
  403. memoffset := operands[i].opr.constoffset;
  404. end;
  405. if memoffset < 0 then
  406. begin
  407. Message2(asmr_w_check_mem_operand_negative_offset,
  408. std_op2str[opcode],
  409. ToStr(memoffset));
  410. end
  411. else if (memopsize < (memrefsize + memoffset * 8)) then
  412. begin
  413. if memoffset = 0 then
  414. begin
  415. Message3(asmr_w_check_mem_operand_size3,
  416. std_op2str[opcode],
  417. ToStr(memopsize),
  418. ToStr(memrefsize)
  419. );
  420. end
  421. else
  422. begin
  423. Message4(asmr_w_check_mem_operand_size_offset,
  424. std_op2str[opcode],
  425. ToStr(memopsize),
  426. ToStr(memrefsize),
  427. ToStr(memoffset)
  428. );
  429. end;
  430. end;
  431. end;
  432. end;
  433. end;
  434. end;
  435. end;
  436. end;
  437. if (ExistsMemRefNoSize or ExistsConstNoSize) and
  438. (MemRefInfo(opcode).ExistsSSEAVX) then
  439. begin
  440. for i := 1 to ops do
  441. begin
  442. if (tx86operand(operands[i]).opsize = S_NO) then
  443. begin
  444. case operands[i].Opr.Typ of
  445. OPR_REFERENCE:
  446. case MemRefInfo(opcode).MemRefSize of
  447. msiMem8:
  448. begin
  449. tx86operand(operands[i]).opsize := S_B;
  450. tx86operand(operands[i]).size := OS_8;
  451. end;
  452. msiMultiple8:
  453. begin
  454. tx86operand(operands[i]).opsize := S_B;
  455. tx86operand(operands[i]).size := OS_8;
  456. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"8 bit memory operand"');
  457. end;
  458. msiMem16:
  459. begin
  460. tx86operand(operands[i]).opsize := S_W;
  461. tx86operand(operands[i]).size := OS_16;
  462. end;
  463. msiMultiple16:
  464. begin
  465. tx86operand(operands[i]).opsize := S_W;
  466. tx86operand(operands[i]).size := OS_16;
  467. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"16 bit memory operand"');
  468. end;
  469. msiMem32:
  470. begin
  471. tx86operand(operands[i]).opsize := S_L;
  472. tx86operand(operands[i]).size := OS_32;
  473. end;
  474. msiMultiple32:
  475. begin
  476. tx86operand(operands[i]).opsize := S_L;
  477. tx86operand(operands[i]).size := OS_32;
  478. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"32 bit memory operand"');
  479. end;
  480. msiMem64:
  481. begin
  482. tx86operand(operands[i]).opsize := S_Q;
  483. tx86operand(operands[i]).size := OS_M64;
  484. end;
  485. msiMultiple64:
  486. begin
  487. tx86operand(operands[i]).opsize := S_Q;
  488. tx86operand(operands[i]).size := OS_M64;
  489. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"64 bit memory operand"');
  490. end;
  491. msiMem128:
  492. begin
  493. tx86operand(operands[i]).opsize := S_XMM;
  494. tx86operand(operands[i]).size := OS_M128;
  495. end;
  496. msiMultiple128:
  497. begin
  498. tx86operand(operands[i]).opsize := S_XMM;
  499. tx86operand(operands[i]).size := OS_M128;
  500. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"128 bit memory operand"');
  501. end;
  502. msiMem256:
  503. begin
  504. tx86operand(operands[i]).opsize := S_YMM;
  505. tx86operand(operands[i]).size := OS_M256;
  506. opsize := S_YMM;
  507. end;
  508. msiMultiple256:
  509. begin
  510. tx86operand(operands[i]).opsize := S_YMM;
  511. tx86operand(operands[i]).size := OS_M256;
  512. opsize := S_YMM;
  513. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"256 bit memory operand"');
  514. end;
  515. msiMemRegSize:
  516. begin
  517. // mem-ref-size = register size
  518. for j := 1 to ops do
  519. begin
  520. if operands[j].Opr.Typ = OPR_REGISTER then
  521. begin
  522. if (tx86operand(operands[j]).opsize <> S_NO) and
  523. (tx86operand(operands[j]).size <> OS_NO) then
  524. begin
  525. tx86operand(operands[i]).opsize := tx86operand(operands[j]).opsize;
  526. tx86operand(operands[i]).size := tx86operand(operands[j]).size;
  527. break;
  528. end
  529. else Message(asmr_e_unable_to_determine_reference_size);
  530. end;
  531. end;
  532. end;
  533. msiMemRegx16y32:
  534. begin
  535. for j := 1 to ops do
  536. begin
  537. if operands[j].Opr.Typ = OPR_REGISTER then
  538. begin
  539. case getsubreg(operands[j].opr.reg) of
  540. R_SUBMMX: begin
  541. tx86operand(operands[i]).opsize := S_L;
  542. tx86operand(operands[i]).size := OS_M16;
  543. break;
  544. end;
  545. R_SUBMMY: begin
  546. tx86operand(operands[i]).opsize := S_Q;
  547. tx86operand(operands[i]).size := OS_M32;
  548. break;
  549. end;
  550. else Message(asmr_e_unable_to_determine_reference_size);
  551. end;
  552. end;
  553. end;
  554. end;
  555. msiMemRegx32y64:
  556. begin
  557. for j := 1 to ops do
  558. begin
  559. if operands[j].Opr.Typ = OPR_REGISTER then
  560. begin
  561. case getsubreg(operands[j].opr.reg) of
  562. R_SUBMMX: begin
  563. tx86operand(operands[i]).opsize := S_L;
  564. tx86operand(operands[i]).size := OS_M32;
  565. break;
  566. end;
  567. R_SUBMMY: begin
  568. tx86operand(operands[i]).opsize := S_Q;
  569. tx86operand(operands[i]).size := OS_M64;
  570. break;
  571. end;
  572. else Message(asmr_e_unable_to_determine_reference_size);
  573. end;
  574. end;
  575. end;
  576. end;
  577. msiMemRegx64y128:
  578. begin
  579. for j := 1 to ops do
  580. begin
  581. if operands[j].Opr.Typ = OPR_REGISTER then
  582. begin
  583. case getsubreg(operands[j].opr.reg) of
  584. R_SUBMMX: begin
  585. tx86operand(operands[i]).opsize := S_Q;
  586. tx86operand(operands[i]).size := OS_M64;
  587. break;
  588. end;
  589. R_SUBMMY: begin
  590. tx86operand(operands[i]).opsize := S_XMM;
  591. tx86operand(operands[i]).size := OS_M128;
  592. break;
  593. end;
  594. else Message(asmr_e_unable_to_determine_reference_size);
  595. end;
  596. end;
  597. end;
  598. end;
  599. msiMemRegx64y256:
  600. begin
  601. for j := 1 to ops do
  602. begin
  603. if operands[j].Opr.Typ = OPR_REGISTER then
  604. begin
  605. case getsubreg(operands[j].opr.reg) of
  606. R_SUBMMX: begin
  607. tx86operand(operands[i]).opsize := S_Q;
  608. tx86operand(operands[i]).size := OS_M64;
  609. break;
  610. end;
  611. R_SUBMMY: begin
  612. tx86operand(operands[i]).opsize := S_YMM;
  613. tx86operand(operands[i]).size := OS_M256;
  614. break;
  615. end;
  616. else Message(asmr_e_unable_to_determine_reference_size);
  617. end;
  618. end;
  619. end;
  620. end;
  621. msiNoSize: ; // all memory-sizes are ok
  622. msiMultiple: Message(asmr_e_unable_to_determine_reference_size); // TODO individual message
  623. end;
  624. OPR_CONSTANT:
  625. case MemRefInfo(opcode).ConstSize of
  626. csiMem8: begin
  627. tx86operand(operands[i]).opsize := S_B;
  628. tx86operand(operands[i]).size := OS_8;
  629. end;
  630. csiMem16: begin
  631. tx86operand(operands[i]).opsize := S_W;
  632. tx86operand(operands[i]).size := OS_16;
  633. end;
  634. csiMem32: begin
  635. tx86operand(operands[i]).opsize := S_L;
  636. tx86operand(operands[i]).size := OS_32;
  637. end;
  638. end;
  639. end;
  640. end;
  641. end;
  642. end;
  643. for i:=1 to ops do
  644. begin
  645. operands[i].SetCorrectSize(opcode);
  646. if tx86operand(operands[i]).opsize=S_NO then
  647. begin
  648. {$ifdef x86_64}
  649. if (opcode=A_MOVQ) and
  650. (ops=2) and
  651. (operands[1].opr.typ=OPR_CONSTANT) then
  652. opsize:=S_Q
  653. else
  654. {$endif x86_64}
  655. case operands[i].Opr.Typ of
  656. OPR_LOCAL,
  657. OPR_REFERENCE :
  658. begin
  659. { for 3-operand opcodes, operand #1 (in ATT order) is always an immediate,
  660. don't consider it. }
  661. if i=ops then
  662. operand2:=i-1
  663. else
  664. operand2:=i+1;
  665. if operand2>0 then
  666. begin
  667. { Only allow register as operand to take the size from }
  668. if operands[operand2].opr.typ=OPR_REGISTER then
  669. begin
  670. if ((opcode<>A_MOVD) and
  671. (opcode<>A_CVTSI2SS)) then
  672. begin
  673. //tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize;
  674. // torsten - 31.01.2012
  675. // old: xmm/ymm-register operands have a opsize = "S_NO"
  676. // new: xmm/ymm-register operands have a opsize = "S_XMM/S_YMM"
  677. // any SSE- and AVX-opcodes have mixed operand sizes (e.g. cvtsd2ss xmmreg, xmmreg/m32)
  678. // in this case is we need the old handling ("S_NO")
  679. // =>> ignore
  680. if (tx86operand(operands[operand2]).opsize <> S_XMM) and
  681. (tx86operand(operands[operand2]).opsize <> S_YMM) then
  682. tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize
  683. else tx86operand(operands[operand2]).opsize := S_NO;
  684. end;
  685. end
  686. else
  687. begin
  688. { if no register then take the opsize (which is available with ATT),
  689. if not availble then give an error }
  690. if opsize<>S_NO then
  691. tx86operand(operands[i]).opsize:=opsize
  692. else
  693. begin
  694. if (m_delphi in current_settings.modeswitches) then
  695. Message(asmr_w_unable_to_determine_reference_size_using_dword)
  696. else
  697. Message(asmr_e_unable_to_determine_reference_size);
  698. { recovery }
  699. tx86operand(operands[i]).opsize:=S_L;
  700. end;
  701. end;
  702. end
  703. else
  704. begin
  705. if opsize<>S_NO then
  706. tx86operand(operands[i]).opsize:=opsize
  707. end;
  708. end;
  709. OPR_SYMBOL :
  710. begin
  711. { Fix lea which need a reference }
  712. if opcode=A_LEA then
  713. begin
  714. s:=operands[i].opr.symbol;
  715. so:=operands[i].opr.symofs;
  716. operands[i].opr.typ:=OPR_REFERENCE;
  717. Fillchar(operands[i].opr.ref,sizeof(treference),0);
  718. operands[i].opr.ref.symbol:=s;
  719. operands[i].opr.ref.offset:=so;
  720. end;
  721. {$if defined(x86_64)}
  722. tx86operand(operands[i]).opsize:=S_Q;
  723. {$elseif defined(i386)}
  724. tx86operand(operands[i]).opsize:=S_L;
  725. {$elseif defined(i8086)}
  726. tx86operand(operands[i]).opsize:=S_W;
  727. {$endif}
  728. end;
  729. end;
  730. end;
  731. end;
  732. end;
  733. procedure Tx86Instruction.SetInstructionOpsize;
  734. begin
  735. if opsize<>S_NO then
  736. exit;
  737. case ops of
  738. 0 : ;
  739. 1 :
  740. begin
  741. { "push es" must be stored as a long PM }
  742. if ((opcode=A_PUSH) or
  743. (opcode=A_POP)) and
  744. (operands[1].opr.typ=OPR_REGISTER) and
  745. is_segment_reg(operands[1].opr.reg) then
  746. {$ifdef i8086}
  747. opsize:=S_W
  748. {$else i8086}
  749. opsize:=S_L
  750. {$endif i8086}
  751. else
  752. opsize:=tx86operand(operands[1]).opsize;
  753. end;
  754. 2 :
  755. begin
  756. case opcode of
  757. A_MOVZX,A_MOVSX :
  758. begin
  759. if tx86operand(operands[1]).opsize=S_NO then
  760. begin
  761. tx86operand(operands[1]).opsize:=S_B;
  762. if (m_delphi in current_settings.modeswitches) then
  763. Message(asmr_w_unable_to_determine_reference_size_using_byte)
  764. else
  765. Message(asmr_e_unable_to_determine_reference_size);
  766. end;
  767. case tx86operand(operands[1]).opsize of
  768. S_W :
  769. case tx86operand(operands[2]).opsize of
  770. S_L :
  771. opsize:=S_WL;
  772. {$ifdef x86_64}
  773. S_Q :
  774. opsize:=S_WQ;
  775. {$endif}
  776. end;
  777. S_B :
  778. begin
  779. case tx86operand(operands[2]).opsize of
  780. S_W :
  781. opsize:=S_BW;
  782. S_L :
  783. opsize:=S_BL;
  784. {$ifdef x86_64}
  785. S_Q :
  786. opsize:=S_BQ;
  787. {$endif}
  788. end;
  789. end;
  790. end;
  791. end;
  792. A_MOVSS,
  793. A_VMOVSS,
  794. A_MOVD : { movd is a move from a mmx register to a
  795. 32 bit register or memory, so no opsize is correct here PM }
  796. exit;
  797. A_MOVQ :
  798. opsize:=S_IQ;
  799. A_CVTSI2SS,
  800. A_CVTSI2SD,
  801. A_OUT :
  802. opsize:=tx86operand(operands[1]).opsize;
  803. else
  804. opsize:=tx86operand(operands[2]).opsize;
  805. end;
  806. end;
  807. 3 :
  808. begin
  809. case opcode of
  810. A_VCVTSI2SS,
  811. A_VCVTSI2SD:
  812. opsize:=tx86operand(operands[1]).opsize;
  813. else
  814. opsize:=tx86operand(operands[ops]).opsize;
  815. end;
  816. end;
  817. 4 :
  818. opsize:=tx86operand(operands[ops]).opsize;
  819. end;
  820. end;
  821. procedure Tx86Instruction.CheckOperandSizes;
  822. var
  823. sizeerr : boolean;
  824. i : longint;
  825. begin
  826. { Check only the most common opcodes here, the others are done in
  827. the assembler pass }
  828. case opcode of
  829. A_PUSH,A_POP,A_DEC,A_INC,A_NOT,A_NEG,
  830. A_CMP,A_MOV,
  831. A_ADD,A_SUB,A_ADC,A_SBB,
  832. A_AND,A_OR,A_TEST,A_XOR: ;
  833. else
  834. exit;
  835. end;
  836. { Handle the BW,BL,WL separatly }
  837. sizeerr:=false;
  838. { special push/pop selector case }
  839. if ((opcode=A_PUSH) or
  840. (opcode=A_POP)) and
  841. (operands[1].opr.typ=OPR_REGISTER) and
  842. is_segment_reg(operands[1].opr.reg) then
  843. exit;
  844. if opsize in [S_BW,S_BL,S_WL] then
  845. begin
  846. if ops<>2 then
  847. sizeerr:=true
  848. else
  849. begin
  850. case opsize of
  851. S_BW :
  852. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_W);
  853. S_BL :
  854. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_L);
  855. S_WL :
  856. sizeerr:=(tx86operand(operands[1]).opsize<>S_W) or (tx86operand(operands[2]).opsize<>S_L);
  857. end;
  858. end;
  859. end
  860. else
  861. begin
  862. for i:=1 to ops do
  863. begin
  864. if (operands[i].opr.typ<>OPR_CONSTANT) and
  865. (tx86operand(operands[i]).opsize in [S_B,S_W,S_L]) and
  866. (tx86operand(operands[i]).opsize<>opsize) then
  867. sizeerr:=true;
  868. end;
  869. end;
  870. if sizeerr then
  871. begin
  872. { if range checks are on then generate an error }
  873. if (cs_compilesystem in current_settings.moduleswitches) or
  874. not (cs_check_range in current_settings.localswitches) then
  875. Message(asmr_w_size_suffix_and_dest_dont_match)
  876. else
  877. Message(asmr_e_size_suffix_and_dest_dont_match);
  878. end;
  879. end;
  880. { This check must be done with the operand in ATT order
  881. i.e.after swapping in the intel reader
  882. but before swapping in the NASM and TASM writers PM }
  883. procedure Tx86Instruction.CheckNonCommutativeOpcodes;
  884. begin
  885. if (
  886. (ops=2) and
  887. (operands[1].opr.typ=OPR_REGISTER) and
  888. (operands[2].opr.typ=OPR_REGISTER) and
  889. { if the first is ST and the second is also a register
  890. it is necessarily ST1 .. ST7 }
  891. ((operands[1].opr.reg=NR_ST) or
  892. (operands[1].opr.reg=NR_ST0))
  893. ) or
  894. (ops=0) then
  895. if opcode=A_FSUBR then
  896. opcode:=A_FSUB
  897. else if opcode=A_FSUB then
  898. opcode:=A_FSUBR
  899. else if opcode=A_FDIVR then
  900. opcode:=A_FDIV
  901. else if opcode=A_FDIV then
  902. opcode:=A_FDIVR
  903. else if opcode=A_FSUBRP then
  904. opcode:=A_FSUBP
  905. else if opcode=A_FSUBP then
  906. opcode:=A_FSUBRP
  907. else if opcode=A_FDIVRP then
  908. opcode:=A_FDIVP
  909. else if opcode=A_FDIVP then
  910. opcode:=A_FDIVRP;
  911. if (
  912. (ops=1) and
  913. (operands[1].opr.typ=OPR_REGISTER) and
  914. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  915. (operands[1].opr.reg<>NR_ST) and
  916. (operands[1].opr.reg<>NR_ST0)
  917. ) then
  918. if opcode=A_FSUBRP then
  919. opcode:=A_FSUBP
  920. else if opcode=A_FSUBP then
  921. opcode:=A_FSUBRP
  922. else if opcode=A_FDIVRP then
  923. opcode:=A_FDIVP
  924. else if opcode=A_FDIVP then
  925. opcode:=A_FDIVRP;
  926. end;
  927. procedure Tx86Instruction.FixupOpcode;
  928. begin
  929. { does nothing by default }
  930. end;
  931. {*****************************************************************************
  932. opcode Adding
  933. *****************************************************************************}
  934. function Tx86Instruction.ConcatInstruction(p : TAsmList) : tai;
  935. var
  936. siz : topsize;
  937. i,asize : longint;
  938. ai : taicpu;
  939. begin
  940. ConcatInstruction:=nil;
  941. ai:=nil;
  942. for i:=1 to Ops do
  943. if not operands[i].CheckOperand then
  944. exit;
  945. { Get Opsize }
  946. if (opsize<>S_NO) or (Ops=0) then
  947. siz:=opsize
  948. else
  949. begin
  950. if (Ops=2) and (operands[1].opr.typ=OPR_REGISTER) then
  951. siz:=tx86operand(operands[1]).opsize
  952. else
  953. siz:=tx86operand(operands[Ops]).opsize;
  954. { MOVD should be of size S_LQ or S_QL, but these do not exist PM }
  955. if (ops=2) and
  956. (tx86operand(operands[1]).opsize<>S_NO) and
  957. (tx86operand(operands[2]).opsize<>S_NO) and
  958. (tx86operand(operands[1]).opsize<>tx86operand(operands[2]).opsize) then
  959. siz:=S_NO;
  960. end;
  961. if ((opcode=A_MOVD)or
  962. (opcode=A_CVTSI2SS)) and
  963. ((tx86operand(operands[1]).opsize=S_NO) or
  964. (tx86operand(operands[2]).opsize=S_NO)) then
  965. siz:=S_NO;
  966. { NASM does not support FADD without args
  967. as alias of FADDP
  968. and GNU AS interprets FADD without operand differently
  969. for version 2.9.1 and 2.9.5 !! }
  970. if (ops=0) and
  971. ((opcode=A_FADD) or
  972. (opcode=A_FMUL) or
  973. (opcode=A_FSUB) or
  974. (opcode=A_FSUBR) or
  975. (opcode=A_FDIV) or
  976. (opcode=A_FDIVR)) then
  977. begin
  978. if opcode=A_FADD then
  979. opcode:=A_FADDP
  980. else if opcode=A_FMUL then
  981. opcode:=A_FMULP
  982. else if opcode=A_FSUB then
  983. opcode:=A_FSUBP
  984. else if opcode=A_FSUBR then
  985. opcode:=A_FSUBRP
  986. else if opcode=A_FDIV then
  987. opcode:=A_FDIVP
  988. else if opcode=A_FDIVR then
  989. opcode:=A_FDIVRP;
  990. message1(asmr_w_fadd_to_faddp,std_op2str[opcode]);
  991. end;
  992. {It is valid to specify some instructions without operand size.}
  993. if siz=S_NO then
  994. begin
  995. if (ops=1) and (opcode=A_INT) then
  996. siz:=S_B;
  997. if (ops=1) and (opcode=A_XABORT) then
  998. siz:=S_B;
  999. {$ifdef i8086}
  1000. if (ops=1) and (opcode=A_BRKEM) then
  1001. siz:=S_B;
  1002. {$endif i8086}
  1003. if (ops=1) and (opcode=A_RET) or (opcode=A_RETN) or (opcode=A_RETF) or
  1004. (opcode=A_RETW) or (opcode=A_RETNW) or (opcode=A_RETFW) or
  1005. {$ifndef x86_64}
  1006. (opcode=A_RETD) or (opcode=A_RETND) or
  1007. {$endif x86_64}
  1008. (opcode=A_RETFD)
  1009. {$ifdef x86_64}
  1010. or (opcode=A_RETQ) or (opcode=A_RETNQ) or (opcode=A_RETFQ)
  1011. {$endif x86_64}
  1012. then
  1013. siz:=S_W;
  1014. if (ops=1) and (opcode=A_PUSH) then
  1015. begin
  1016. {$ifdef i8086}
  1017. if (tx86operand(operands[1]).opr.val>=-128) and (tx86operand(operands[1]).opr.val<=127) then
  1018. begin
  1019. siz:=S_B;
  1020. message(asmr_w_unable_to_determine_constant_size_using_byte);
  1021. end
  1022. else
  1023. begin
  1024. siz:=S_W;
  1025. message(asmr_w_unable_to_determine_constant_size_using_word);
  1026. end;
  1027. {$else i8086}
  1028. { We are a 32 compiler, assume 32-bit by default. This is Delphi
  1029. compatible but bad coding practise.}
  1030. siz:=S_L;
  1031. message(asmr_w_unable_to_determine_reference_size_using_dword);
  1032. {$endif i8086}
  1033. end;
  1034. if (opcode=A_JMP) or (opcode=A_JCC) or (opcode=A_CALL) then
  1035. if ops=1 then
  1036. siz:=S_NEAR
  1037. else
  1038. siz:=S_FAR;
  1039. end;
  1040. { GNU AS interprets FDIV without operand differently
  1041. for version 2.9.1 and 2.10
  1042. we add explicit args to it !! }
  1043. if (ops=0) and
  1044. ((opcode=A_FSUBP) or
  1045. (opcode=A_FSUBRP) or
  1046. (opcode=A_FDIVP) or
  1047. (opcode=A_FDIVRP) or
  1048. (opcode=A_FSUB) or
  1049. (opcode=A_FSUBR) or
  1050. (opcode=A_FADD) or
  1051. (opcode=A_FADDP) or
  1052. (opcode=A_FDIV) or
  1053. (opcode=A_FDIVR)) then
  1054. begin
  1055. message1(asmr_w_adding_explicit_args_fXX,std_op2str[opcode]);
  1056. ops:=2;
  1057. operands[1].opr.typ:=OPR_REGISTER;
  1058. operands[2].opr.typ:=OPR_REGISTER;
  1059. operands[1].opr.reg:=NR_ST0;
  1060. operands[2].opr.reg:=NR_ST1;
  1061. end;
  1062. if (ops=1) and
  1063. (
  1064. (operands[1].opr.typ=OPR_REGISTER) and
  1065. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1066. (operands[1].opr.reg<>NR_ST) and
  1067. (operands[1].opr.reg<>NR_ST0)
  1068. ) and
  1069. (
  1070. (opcode=A_FSUBP) or
  1071. (opcode=A_FSUBRP) or
  1072. (opcode=A_FDIVP) or
  1073. (opcode=A_FDIVRP) or
  1074. (opcode=A_FADDP) or
  1075. (opcode=A_FMULP)
  1076. ) then
  1077. begin
  1078. message1(asmr_w_adding_explicit_first_arg_fXX,std_op2str[opcode]);
  1079. ops:=2;
  1080. operands[2].opr.typ:=OPR_REGISTER;
  1081. operands[2].opr.reg:=operands[1].opr.reg;
  1082. operands[1].opr.reg:=NR_ST0;
  1083. end;
  1084. if (ops=1) and
  1085. (
  1086. (operands[1].opr.typ=OPR_REGISTER) and
  1087. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1088. (operands[1].opr.reg<>NR_ST) and
  1089. (operands[1].opr.reg<>NR_ST0)
  1090. ) and
  1091. (
  1092. (opcode=A_FSUB) or
  1093. (opcode=A_FSUBR) or
  1094. (opcode=A_FDIV) or
  1095. (opcode=A_FDIVR) or
  1096. (opcode=A_FADD) or
  1097. (opcode=A_FMUL)
  1098. ) then
  1099. begin
  1100. message1(asmr_w_adding_explicit_second_arg_fXX,std_op2str[opcode]);
  1101. ops:=2;
  1102. operands[2].opr.typ:=OPR_REGISTER;
  1103. operands[2].opr.reg:=NR_ST0;
  1104. end;
  1105. { Check for 'POP CS' }
  1106. if (opcode=A_POP) and (ops=1) and (operands[1].opr.typ=OPR_REGISTER) and
  1107. (operands[1].opr.reg=NR_CS) then
  1108. {$ifdef i8086}
  1109. { On i8086 we print only a warning, because 'POP CS' works on 8086 and 8088
  1110. CPUs, but isn't supported on any later CPU }
  1111. Message(asmr_w_pop_cs_not_portable);
  1112. {$else i8086}
  1113. { On the i386 and x86_64 targets, we print out an error, because no CPU,
  1114. supported by these targets support 'POP CS' }
  1115. Message(asmr_e_pop_cs_not_valid);
  1116. {$endif i8086}
  1117. { I tried to convince Linus Torvalds to add
  1118. code to support ENTER instruction
  1119. (when raising a stack page fault)
  1120. but he replied that ENTER is a bad instruction and
  1121. Linux does not need to support it
  1122. So I think its at least a good idea to add a warning
  1123. if someone uses this in assembler code
  1124. FPC itself does not use it at all PM }
  1125. if (opcode=A_ENTER) and
  1126. (target_info.system in [system_i386_linux,system_i386_FreeBSD,system_i386_android]) then
  1127. Message(asmr_w_enter_not_supported_by_linux);
  1128. ai:=taicpu.op_none(opcode,siz);
  1129. ai.fileinfo:=filepos;
  1130. ai.SetOperandOrder(op_att);
  1131. ai.Ops:=Ops;
  1132. ai.Allocate_oper(Ops);
  1133. for i:=1 to Ops do
  1134. case operands[i].opr.typ of
  1135. OPR_CONSTANT :
  1136. ai.loadconst(i-1,operands[i].opr.val);
  1137. OPR_REGISTER:
  1138. ai.loadreg(i-1,operands[i].opr.reg);
  1139. OPR_SYMBOL:
  1140. {$ifdef i8086}
  1141. if operands[i].opr.symseg then
  1142. taicpu(ai).loadsegsymbol(i-1,operands[i].opr.symbol)
  1143. else
  1144. {$endif i8086}
  1145. ai.loadsymbol(i-1,operands[i].opr.symbol,operands[i].opr.symofs);
  1146. OPR_LOCAL :
  1147. with operands[i].opr do
  1148. begin
  1149. ai.loadlocal(i-1,localsym,localsymofs,localindexreg,
  1150. localscale,localgetoffset,localforceref);
  1151. ai.oper[i-1]^.localoper^.localsegment:=localsegment;
  1152. end;
  1153. OPR_REFERENCE:
  1154. begin
  1155. if (opcode<>A_XLAT) and not is_x86_string_op(opcode) then
  1156. optimize_ref(operands[i].opr.ref,true);
  1157. ai.loadref(i-1,operands[i].opr.ref);
  1158. if operands[i].size<>OS_NO then
  1159. begin
  1160. asize:=0;
  1161. case operands[i].size of
  1162. OS_8,OS_S8 :
  1163. asize:=OT_BITS8;
  1164. OS_16,OS_S16, OS_M16:
  1165. asize:=OT_BITS16;
  1166. OS_32,OS_S32 :
  1167. {$ifdef i8086}
  1168. if siz=S_FAR then
  1169. asize:=OT_FAR
  1170. else
  1171. asize:=OT_BITS32;
  1172. {$else i8086}
  1173. asize:=OT_BITS32;
  1174. {$endif i8086}
  1175. OS_F32,OS_M32 :
  1176. asize:=OT_BITS32;
  1177. OS_64,OS_S64:
  1178. begin
  1179. { Only FPU operations know about 64bit values, for all
  1180. integer operations it is seen as 32bit
  1181. this applies only to i386, see tw16622}
  1182. if gas_needsuffix[opcode] in [attsufFPU,attsufFPUint] then
  1183. asize:=OT_BITS64
  1184. {$ifdef i386}
  1185. else
  1186. asize:=OT_BITS32
  1187. {$endif i386}
  1188. ;
  1189. end;
  1190. OS_F64,OS_C64, OS_M64 :
  1191. asize:=OT_BITS64;
  1192. OS_F80 :
  1193. asize:=OT_BITS80;
  1194. OS_128,OS_M128:
  1195. asize := OT_BITS128;
  1196. OS_M256:
  1197. asize := OT_BITS256;
  1198. OS_M512:
  1199. asize := OT_BITS512;
  1200. end;
  1201. if asize<>0 then
  1202. ai.oper[i-1]^.ot:=(ai.oper[i-1]^.ot and not OT_SIZE_MASK) or asize;
  1203. end;
  1204. end;
  1205. end;
  1206. { Condition ? }
  1207. if condition<>C_None then
  1208. ai.SetCondition(condition);
  1209. { Set is_jmp, it enables asmwriter to emit short jumps if appropriate }
  1210. if (opcode=A_JMP) or (opcode=A_JCC) then
  1211. ai.is_jmp := True;
  1212. { Concat the opcode or give an error }
  1213. if assigned(ai) then
  1214. p.concat(ai)
  1215. else
  1216. Message(asmr_e_invalid_opcode_and_operand);
  1217. result:=ai;
  1218. end;
  1219. end.