rax86.pas 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  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. const
  293. {$ifdef x86_64}
  294. topsize2memsize: array[topsize] of integer =
  295. (0, 8,16,32,64,8,8,16,8,16,32,
  296. 16,32,64,
  297. 16,32,64,0,0,
  298. 64,
  299. 0,0,0,
  300. 80,
  301. 128,
  302. 256,
  303. 512
  304. );
  305. {$else}
  306. topsize2memsize: array[topsize] of integer =
  307. (0, 8,16,32,64,8,8,16,
  308. 16,32,64,
  309. 16,32,64,0,0,
  310. 64,
  311. 0,0,0,
  312. 80,
  313. 128,
  314. 256,
  315. 512
  316. );
  317. {$endif}
  318. procedure Tx86Instruction.AddReferenceSizes;
  319. { this will add the sizes for references like [esi] which do not
  320. have the size set yet, it will take only the size if the other
  321. operand is a register }
  322. var
  323. operand2,i,j : longint;
  324. s : tasmsymbol;
  325. so : aint;
  326. ExistsMemRefNoSize: boolean;
  327. ExistsMemRef: boolean;
  328. ExistsConstNoSize: boolean;
  329. ExistsLocalSymSize: boolean;
  330. memrefsize: integer;
  331. memopsize: integer;
  332. memoffset: asizeint;
  333. begin
  334. ExistsMemRefNoSize := false;
  335. ExistsMemRef := false;
  336. ExistsConstNoSize := false;
  337. ExistsLocalSymSize := false;
  338. // EXIST A MEMORY- OR CONSTANT-OPERAND WITHOUT SIZE ?
  339. for i := 1 to ops do
  340. begin
  341. if operands[i].Opr.Typ in [OPR_REFERENCE, OPR_LOCAL] then
  342. begin
  343. ExistsMemRef := true;
  344. if (tx86operand(operands[i]).opsize = S_NO) then
  345. begin
  346. ExistsMemRefNoSize := true;
  347. case operands[i].opr.Typ of
  348. OPR_LOCAL: ExistsLocalSymSize := tx86operand(operands[i]).opr.localsym.getsize > 0;
  349. OPR_REFERENCE: ExistsLocalSymSize := true;
  350. end;
  351. end;
  352. end
  353. else if operands[i].Opr.Typ in [OPR_CONSTANT] then
  354. begin
  355. ExistsConstNoSize := tx86operand(operands[i]).opsize = S_NO;
  356. end;
  357. end;
  358. // ONLY SUPPORTED OPCODES WITH SSE- OR AVX-REGISTERS
  359. if (ExistsMemRef) and
  360. (MemRefInfo(opcode).ExistsSSEAVX) then
  361. begin
  362. // 1. WE HAVE AN SSE- OR AVX-OPCODE WITH MEMORY OPERAND
  363. if (not(ExistsMemRefNoSize)) or
  364. (ExistsLocalSymSize) then
  365. begin
  366. // 2. WE KNOWN THE MEMORYSIZE OF THE MEMORY-OPERAND OR WE CAN
  367. // CALC THE MEMORYSIZE
  368. // 3. CALC THE SIZE OF THE MEMORYOPERAND BY OPCODE-DEFINITION
  369. // 4. COMPARE THE SIZE FROM OPCODE-DEFINITION AND THE REAL MEMORY-OPERAND-SIZE
  370. // - validate memory-reference-size
  371. for i := 1 to ops do
  372. begin
  373. if (operands[i].Opr.Typ in [OPR_REFERENCE, OPR_LOCAL]) then
  374. begin
  375. memrefsize := -1;
  376. case MemRefInfo(opcode).MemRefSize of
  377. msiMem8: memrefsize := 8;
  378. msiMem16: memrefsize := 16;
  379. msiMem32: memrefsize := 32;
  380. msiMem64: memrefsize := 64;
  381. msiMem128: memrefsize := 128;
  382. msiMem256: memrefsize := 256;
  383. msiMemRegSize
  384. : for j := 1 to ops do
  385. begin
  386. if operands[j].Opr.Typ = OPR_REGISTER then
  387. begin
  388. if (tx86operand(operands[j]).opsize <> S_NO) and
  389. (tx86operand(operands[j]).size <> OS_NO) then
  390. begin
  391. case tx86operand(operands[j]).opsize of
  392. S_B : memrefsize := 8;
  393. S_W : memrefsize := 16;
  394. S_L : memrefsize := 32;
  395. S_Q : memrefsize := 64;
  396. S_XMM : memrefsize := 128;
  397. S_YMM : memrefsize := 256;
  398. else Internalerror(777200);
  399. end;
  400. break;
  401. end;
  402. end;
  403. end;
  404. end;
  405. if memrefsize > -1 then
  406. begin
  407. // CALC REAL-MEMORY-OPERAND-SIZE AND A POSSIBLE OFFSET
  408. // OFFSET:
  409. // e.g. PAND XMM0, [RAX + 16] =>> OFFSET = 16 BYTES
  410. // PAND XMM0, [RAX + a.b + 10] =>> OFFSET = 10 BYTES (a = record-variable)
  411. memopsize := 0;
  412. case operands[i].opr.typ of
  413. OPR_LOCAL: memopsize := operands[i].opr.localvarsize * 8;
  414. OPR_REFERENCE:
  415. if operands[i].opr.ref.refaddr = addr_pic then
  416. memopsize := sizeof(pint) * 8
  417. else
  418. memopsize := operands[i].opr.varsize * 8;
  419. end;
  420. if memopsize = 0 then memopsize := topsize2memsize[tx86operand(operands[i]).opsize];
  421. if (memopsize > 0) and
  422. (memrefsize > 0) then
  423. begin
  424. memoffset := 0;
  425. case operands[i].opr.typ of
  426. OPR_LOCAL:
  427. memoffset := operands[i].opr.localconstoffset;
  428. OPR_REFERENCE:
  429. memoffset := operands[i].opr.constoffset;
  430. end;
  431. if memoffset < 0 then
  432. begin
  433. Message2(asmr_w_check_mem_operand_negative_offset,
  434. std_op2str[opcode],
  435. ToStr(memoffset));
  436. end
  437. else if (memopsize < (memrefsize + memoffset * 8)) then
  438. begin
  439. if memoffset = 0 then
  440. begin
  441. Message3(asmr_w_check_mem_operand_size3,
  442. std_op2str[opcode],
  443. ToStr(memopsize),
  444. ToStr(memrefsize)
  445. );
  446. end
  447. else
  448. begin
  449. Message4(asmr_w_check_mem_operand_size_offset,
  450. std_op2str[opcode],
  451. ToStr(memopsize),
  452. ToStr(memrefsize),
  453. ToStr(memoffset)
  454. );
  455. end;
  456. end;
  457. end;
  458. end;
  459. end;
  460. end;
  461. end;
  462. end;
  463. if (ExistsMemRefNoSize or ExistsConstNoSize) and
  464. (MemRefInfo(opcode).ExistsSSEAVX) then
  465. begin
  466. for i := 1 to ops do
  467. begin
  468. if (tx86operand(operands[i]).opsize = S_NO) then
  469. begin
  470. case operands[i].Opr.Typ of
  471. OPR_REFERENCE:
  472. case MemRefInfo(opcode).MemRefSize of
  473. msiMem8:
  474. begin
  475. tx86operand(operands[i]).opsize := S_B;
  476. tx86operand(operands[i]).size := OS_8;
  477. end;
  478. msiMultiple8:
  479. begin
  480. tx86operand(operands[i]).opsize := S_B;
  481. tx86operand(operands[i]).size := OS_8;
  482. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"8 bit memory operand"');
  483. end;
  484. msiMem16:
  485. begin
  486. tx86operand(operands[i]).opsize := S_W;
  487. tx86operand(operands[i]).size := OS_16;
  488. end;
  489. msiMultiple16:
  490. begin
  491. tx86operand(operands[i]).opsize := S_W;
  492. tx86operand(operands[i]).size := OS_16;
  493. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"16 bit memory operand"');
  494. end;
  495. msiMem32:
  496. begin
  497. tx86operand(operands[i]).opsize := S_L;
  498. tx86operand(operands[i]).size := OS_32;
  499. end;
  500. msiMultiple32:
  501. begin
  502. tx86operand(operands[i]).opsize := S_L;
  503. tx86operand(operands[i]).size := OS_32;
  504. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"32 bit memory operand"');
  505. end;
  506. msiMem64:
  507. begin
  508. tx86operand(operands[i]).opsize := S_Q;
  509. tx86operand(operands[i]).size := OS_M64;
  510. end;
  511. msiMultiple64:
  512. begin
  513. tx86operand(operands[i]).opsize := S_Q;
  514. tx86operand(operands[i]).size := OS_M64;
  515. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"64 bit memory operand"');
  516. end;
  517. msiMem128:
  518. begin
  519. tx86operand(operands[i]).opsize := S_XMM;
  520. tx86operand(operands[i]).size := OS_M128;
  521. end;
  522. msiMultiple128:
  523. begin
  524. tx86operand(operands[i]).opsize := S_XMM;
  525. tx86operand(operands[i]).size := OS_M128;
  526. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"128 bit memory operand"');
  527. end;
  528. msiMem256:
  529. begin
  530. tx86operand(operands[i]).opsize := S_YMM;
  531. tx86operand(operands[i]).size := OS_M256;
  532. opsize := S_YMM;
  533. end;
  534. msiMultiple256:
  535. begin
  536. tx86operand(operands[i]).opsize := S_YMM;
  537. tx86operand(operands[i]).size := OS_M256;
  538. opsize := S_YMM;
  539. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"256 bit memory operand"');
  540. end;
  541. msiMemRegSize:
  542. begin
  543. // mem-ref-size = register size
  544. for j := 1 to ops do
  545. begin
  546. if operands[j].Opr.Typ = OPR_REGISTER then
  547. begin
  548. if (tx86operand(operands[j]).opsize <> S_NO) and
  549. (tx86operand(operands[j]).size <> OS_NO) then
  550. begin
  551. tx86operand(operands[i]).opsize := tx86operand(operands[j]).opsize;
  552. tx86operand(operands[i]).size := tx86operand(operands[j]).size;
  553. break;
  554. end
  555. else Message(asmr_e_unable_to_determine_reference_size);
  556. end;
  557. end;
  558. end;
  559. msiMemRegx16y32:
  560. begin
  561. for j := 1 to ops do
  562. begin
  563. if operands[j].Opr.Typ = OPR_REGISTER then
  564. begin
  565. case getsubreg(operands[j].opr.reg) of
  566. R_SUBMMX: begin
  567. tx86operand(operands[i]).opsize := S_L;
  568. tx86operand(operands[i]).size := OS_M16;
  569. break;
  570. end;
  571. R_SUBMMY: begin
  572. tx86operand(operands[i]).opsize := S_Q;
  573. tx86operand(operands[i]).size := OS_M32;
  574. break;
  575. end;
  576. else Message(asmr_e_unable_to_determine_reference_size);
  577. end;
  578. end;
  579. end;
  580. end;
  581. msiMemRegx32y64:
  582. begin
  583. for j := 1 to ops do
  584. begin
  585. if operands[j].Opr.Typ = OPR_REGISTER then
  586. begin
  587. case getsubreg(operands[j].opr.reg) of
  588. R_SUBMMX: begin
  589. tx86operand(operands[i]).opsize := S_L;
  590. tx86operand(operands[i]).size := OS_M32;
  591. break;
  592. end;
  593. R_SUBMMY: begin
  594. tx86operand(operands[i]).opsize := S_Q;
  595. tx86operand(operands[i]).size := OS_M64;
  596. break;
  597. end;
  598. else Message(asmr_e_unable_to_determine_reference_size);
  599. end;
  600. end;
  601. end;
  602. end;
  603. msiMemRegx64y128:
  604. begin
  605. for j := 1 to ops do
  606. begin
  607. if operands[j].Opr.Typ = OPR_REGISTER then
  608. begin
  609. case getsubreg(operands[j].opr.reg) of
  610. R_SUBMMX: begin
  611. tx86operand(operands[i]).opsize := S_Q;
  612. tx86operand(operands[i]).size := OS_M64;
  613. break;
  614. end;
  615. R_SUBMMY: begin
  616. tx86operand(operands[i]).opsize := S_XMM;
  617. tx86operand(operands[i]).size := OS_M128;
  618. break;
  619. end;
  620. else Message(asmr_e_unable_to_determine_reference_size);
  621. end;
  622. end;
  623. end;
  624. end;
  625. msiMemRegx64y256:
  626. begin
  627. for j := 1 to ops do
  628. begin
  629. if operands[j].Opr.Typ = OPR_REGISTER then
  630. begin
  631. case getsubreg(operands[j].opr.reg) of
  632. R_SUBMMX: begin
  633. tx86operand(operands[i]).opsize := S_Q;
  634. tx86operand(operands[i]).size := OS_M64;
  635. break;
  636. end;
  637. R_SUBMMY: begin
  638. tx86operand(operands[i]).opsize := S_YMM;
  639. tx86operand(operands[i]).size := OS_M256;
  640. break;
  641. end;
  642. else Message(asmr_e_unable_to_determine_reference_size);
  643. end;
  644. end;
  645. end;
  646. end;
  647. msiNoSize: ; // all memory-sizes are ok
  648. msiMultiple: Message(asmr_e_unable_to_determine_reference_size); // TODO individual message
  649. end;
  650. OPR_CONSTANT:
  651. case MemRefInfo(opcode).ConstSize of
  652. csiMem8: begin
  653. tx86operand(operands[i]).opsize := S_B;
  654. tx86operand(operands[i]).size := OS_8;
  655. end;
  656. csiMem16: begin
  657. tx86operand(operands[i]).opsize := S_W;
  658. tx86operand(operands[i]).size := OS_16;
  659. end;
  660. csiMem32: begin
  661. tx86operand(operands[i]).opsize := S_L;
  662. tx86operand(operands[i]).size := OS_32;
  663. end;
  664. end;
  665. end;
  666. end;
  667. end;
  668. end;
  669. for i:=1 to ops do
  670. begin
  671. operands[i].SetCorrectSize(opcode);
  672. if tx86operand(operands[i]).opsize=S_NO then
  673. begin
  674. {$ifdef x86_64}
  675. if (opcode=A_MOVQ) and
  676. (ops=2) and
  677. (operands[1].opr.typ=OPR_CONSTANT) then
  678. opsize:=S_Q
  679. else
  680. {$endif x86_64}
  681. case operands[i].Opr.Typ of
  682. OPR_LOCAL,
  683. OPR_REFERENCE :
  684. begin
  685. { for 3-operand opcodes, operand #1 (in ATT order) is always an immediate,
  686. don't consider it. }
  687. if i=ops then
  688. operand2:=i-1
  689. else
  690. operand2:=i+1;
  691. if operand2>0 then
  692. begin
  693. { Only allow register as operand to take the size from }
  694. if operands[operand2].opr.typ=OPR_REGISTER then
  695. begin
  696. if ((opcode<>A_MOVD) and
  697. (opcode<>A_CVTSI2SS)) then
  698. begin
  699. //tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize;
  700. // torsten - 31.01.2012
  701. // old: xmm/ymm-register operands have a opsize = "S_NO"
  702. // new: xmm/ymm-register operands have a opsize = "S_XMM/S_YMM"
  703. // any SSE- and AVX-opcodes have mixed operand sizes (e.g. cvtsd2ss xmmreg, xmmreg/m32)
  704. // in this case is we need the old handling ("S_NO")
  705. // =>> ignore
  706. if (tx86operand(operands[operand2]).opsize <> S_XMM) and
  707. (tx86operand(operands[operand2]).opsize <> S_YMM) then
  708. tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize
  709. else tx86operand(operands[operand2]).opsize := S_NO;
  710. end;
  711. end
  712. else
  713. begin
  714. { if no register then take the opsize (which is available with ATT),
  715. if not availble then give an error }
  716. if opsize<>S_NO then
  717. tx86operand(operands[i]).opsize:=opsize
  718. else
  719. begin
  720. if (m_delphi in current_settings.modeswitches) then
  721. Message(asmr_w_unable_to_determine_reference_size_using_dword)
  722. else
  723. Message(asmr_e_unable_to_determine_reference_size);
  724. { recovery }
  725. tx86operand(operands[i]).opsize:=S_L;
  726. end;
  727. end;
  728. end
  729. else
  730. begin
  731. if opsize<>S_NO then
  732. tx86operand(operands[i]).opsize:=opsize
  733. end;
  734. end;
  735. OPR_SYMBOL :
  736. begin
  737. { Fix lea which need a reference }
  738. if opcode=A_LEA then
  739. begin
  740. s:=operands[i].opr.symbol;
  741. so:=operands[i].opr.symofs;
  742. operands[i].opr.typ:=OPR_REFERENCE;
  743. Fillchar(operands[i].opr.ref,sizeof(treference),0);
  744. operands[i].opr.ref.symbol:=s;
  745. operands[i].opr.ref.offset:=so;
  746. end;
  747. {$if defined(x86_64)}
  748. tx86operand(operands[i]).opsize:=S_Q;
  749. {$elseif defined(i386)}
  750. tx86operand(operands[i]).opsize:=S_L;
  751. {$elseif defined(i8086)}
  752. tx86operand(operands[i]).opsize:=S_W;
  753. {$endif}
  754. end;
  755. end;
  756. end;
  757. end;
  758. end;
  759. procedure Tx86Instruction.SetInstructionOpsize;
  760. begin
  761. if opsize<>S_NO then
  762. exit;
  763. case ops of
  764. 0 : ;
  765. 1 :
  766. begin
  767. { "push es" must be stored as a long PM }
  768. if ((opcode=A_PUSH) or
  769. (opcode=A_POP)) and
  770. (operands[1].opr.typ=OPR_REGISTER) and
  771. is_segment_reg(operands[1].opr.reg) then
  772. {$ifdef i8086}
  773. opsize:=S_W
  774. {$else i8086}
  775. opsize:=S_L
  776. {$endif i8086}
  777. else
  778. opsize:=tx86operand(operands[1]).opsize;
  779. end;
  780. 2 :
  781. begin
  782. case opcode of
  783. A_MOVZX,A_MOVSX :
  784. begin
  785. if tx86operand(operands[1]).opsize=S_NO then
  786. begin
  787. tx86operand(operands[1]).opsize:=S_B;
  788. if (m_delphi in current_settings.modeswitches) then
  789. Message(asmr_w_unable_to_determine_reference_size_using_byte)
  790. else
  791. Message(asmr_e_unable_to_determine_reference_size);
  792. end;
  793. case tx86operand(operands[1]).opsize of
  794. S_W :
  795. case tx86operand(operands[2]).opsize of
  796. S_L :
  797. opsize:=S_WL;
  798. {$ifdef x86_64}
  799. S_Q :
  800. opsize:=S_WQ;
  801. {$endif}
  802. end;
  803. S_B :
  804. begin
  805. case tx86operand(operands[2]).opsize of
  806. S_W :
  807. opsize:=S_BW;
  808. S_L :
  809. opsize:=S_BL;
  810. {$ifdef x86_64}
  811. S_Q :
  812. opsize:=S_BQ;
  813. {$endif}
  814. end;
  815. end;
  816. end;
  817. end;
  818. A_MOVSS,
  819. A_VMOVSS,
  820. A_MOVD : { movd is a move from a mmx register to a
  821. 32 bit register or memory, so no opsize is correct here PM }
  822. exit;
  823. A_MOVQ :
  824. opsize:=S_IQ;
  825. A_CVTSI2SS,
  826. A_CVTSI2SD,
  827. A_OUT :
  828. opsize:=tx86operand(operands[1]).opsize;
  829. else
  830. opsize:=tx86operand(operands[2]).opsize;
  831. end;
  832. end;
  833. 3 :
  834. begin
  835. case opcode of
  836. A_VCVTSI2SS,
  837. A_VCVTSI2SD:
  838. opsize:=tx86operand(operands[1]).opsize;
  839. else
  840. opsize:=tx86operand(operands[ops]).opsize;
  841. end;
  842. end;
  843. 4 :
  844. opsize:=tx86operand(operands[ops]).opsize;
  845. end;
  846. end;
  847. procedure Tx86Instruction.CheckOperandSizes;
  848. var
  849. sizeerr : boolean;
  850. i : longint;
  851. begin
  852. { Check only the most common opcodes here, the others are done in
  853. the assembler pass }
  854. case opcode of
  855. A_PUSH,A_POP,A_DEC,A_INC,A_NOT,A_NEG,
  856. A_CMP,A_MOV,
  857. A_ADD,A_SUB,A_ADC,A_SBB,
  858. A_AND,A_OR,A_TEST,A_XOR: ;
  859. else
  860. exit;
  861. end;
  862. { Handle the BW,BL,WL separatly }
  863. sizeerr:=false;
  864. { special push/pop selector case }
  865. if ((opcode=A_PUSH) or
  866. (opcode=A_POP)) and
  867. (operands[1].opr.typ=OPR_REGISTER) and
  868. is_segment_reg(operands[1].opr.reg) then
  869. exit;
  870. if opsize in [S_BW,S_BL,S_WL] then
  871. begin
  872. if ops<>2 then
  873. sizeerr:=true
  874. else
  875. begin
  876. case opsize of
  877. S_BW :
  878. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_W);
  879. S_BL :
  880. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_L);
  881. S_WL :
  882. sizeerr:=(tx86operand(operands[1]).opsize<>S_W) or (tx86operand(operands[2]).opsize<>S_L);
  883. end;
  884. end;
  885. end
  886. else
  887. begin
  888. for i:=1 to ops do
  889. begin
  890. if (operands[i].opr.typ<>OPR_CONSTANT) and
  891. (tx86operand(operands[i]).opsize in [S_B,S_W,S_L]) and
  892. (tx86operand(operands[i]).opsize<>opsize) then
  893. sizeerr:=true;
  894. end;
  895. end;
  896. if sizeerr then
  897. begin
  898. { if range checks are on then generate an error }
  899. if (cs_compilesystem in current_settings.moduleswitches) or
  900. not (cs_check_range in current_settings.localswitches) then
  901. Message(asmr_w_size_suffix_and_dest_dont_match)
  902. else
  903. Message(asmr_e_size_suffix_and_dest_dont_match);
  904. end;
  905. end;
  906. { This check must be done with the operand in ATT order
  907. i.e.after swapping in the intel reader
  908. but before swapping in the NASM and TASM writers PM }
  909. procedure Tx86Instruction.CheckNonCommutativeOpcodes;
  910. begin
  911. if (
  912. (ops=2) and
  913. (operands[1].opr.typ=OPR_REGISTER) and
  914. (operands[2].opr.typ=OPR_REGISTER) and
  915. { if the first is ST and the second is also a register
  916. it is necessarily ST1 .. ST7 }
  917. ((operands[1].opr.reg=NR_ST) or
  918. (operands[1].opr.reg=NR_ST0))
  919. ) or
  920. (ops=0) then
  921. if opcode=A_FSUBR then
  922. opcode:=A_FSUB
  923. else if opcode=A_FSUB then
  924. opcode:=A_FSUBR
  925. else if opcode=A_FDIVR then
  926. opcode:=A_FDIV
  927. else if opcode=A_FDIV then
  928. opcode:=A_FDIVR
  929. else if opcode=A_FSUBRP then
  930. opcode:=A_FSUBP
  931. else if opcode=A_FSUBP then
  932. opcode:=A_FSUBRP
  933. else if opcode=A_FDIVRP then
  934. opcode:=A_FDIVP
  935. else if opcode=A_FDIVP then
  936. opcode:=A_FDIVRP;
  937. if (
  938. (ops=1) and
  939. (operands[1].opr.typ=OPR_REGISTER) and
  940. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  941. (operands[1].opr.reg<>NR_ST) and
  942. (operands[1].opr.reg<>NR_ST0)
  943. ) then
  944. if opcode=A_FSUBRP then
  945. opcode:=A_FSUBP
  946. else if opcode=A_FSUBP then
  947. opcode:=A_FSUBRP
  948. else if opcode=A_FDIVRP then
  949. opcode:=A_FDIVP
  950. else if opcode=A_FDIVP then
  951. opcode:=A_FDIVRP;
  952. end;
  953. procedure Tx86Instruction.FixupOpcode;
  954. begin
  955. { does nothing by default }
  956. end;
  957. {*****************************************************************************
  958. opcode Adding
  959. *****************************************************************************}
  960. function Tx86Instruction.ConcatInstruction(p : TAsmList) : tai;
  961. var
  962. siz : topsize;
  963. i,asize : longint;
  964. ai : taicpu;
  965. begin
  966. ConcatInstruction:=nil;
  967. ai:=nil;
  968. for i:=1 to Ops do
  969. if not operands[i].CheckOperand then
  970. exit;
  971. { Get Opsize }
  972. if (opsize<>S_NO) or (Ops=0) then
  973. siz:=opsize
  974. else
  975. begin
  976. if (Ops=2) and (operands[1].opr.typ=OPR_REGISTER) then
  977. siz:=tx86operand(operands[1]).opsize
  978. else
  979. siz:=tx86operand(operands[Ops]).opsize;
  980. { MOVD should be of size S_LQ or S_QL, but these do not exist PM }
  981. if (ops=2) and
  982. (tx86operand(operands[1]).opsize<>S_NO) and
  983. (tx86operand(operands[2]).opsize<>S_NO) and
  984. (tx86operand(operands[1]).opsize<>tx86operand(operands[2]).opsize) then
  985. siz:=S_NO;
  986. end;
  987. if ((opcode=A_MOVD)or
  988. (opcode=A_CVTSI2SS)) and
  989. ((tx86operand(operands[1]).opsize=S_NO) or
  990. (tx86operand(operands[2]).opsize=S_NO)) then
  991. siz:=S_NO;
  992. { NASM does not support FADD without args
  993. as alias of FADDP
  994. and GNU AS interprets FADD without operand differently
  995. for version 2.9.1 and 2.9.5 !! }
  996. if (ops=0) and
  997. ((opcode=A_FADD) or
  998. (opcode=A_FMUL) or
  999. (opcode=A_FSUB) or
  1000. (opcode=A_FSUBR) or
  1001. (opcode=A_FDIV) or
  1002. (opcode=A_FDIVR)) then
  1003. begin
  1004. if opcode=A_FADD then
  1005. opcode:=A_FADDP
  1006. else if opcode=A_FMUL then
  1007. opcode:=A_FMULP
  1008. else if opcode=A_FSUB then
  1009. opcode:=A_FSUBP
  1010. else if opcode=A_FSUBR then
  1011. opcode:=A_FSUBRP
  1012. else if opcode=A_FDIV then
  1013. opcode:=A_FDIVP
  1014. else if opcode=A_FDIVR then
  1015. opcode:=A_FDIVRP;
  1016. message1(asmr_w_fadd_to_faddp,std_op2str[opcode]);
  1017. end;
  1018. {It is valid to specify some instructions without operand size.}
  1019. if siz=S_NO then
  1020. begin
  1021. if (ops=1) and (opcode=A_INT) then
  1022. siz:=S_B;
  1023. if (ops=1) and (opcode=A_XABORT) then
  1024. siz:=S_B;
  1025. {$ifdef i8086}
  1026. if (ops=1) and (opcode=A_BRKEM) then
  1027. siz:=S_B;
  1028. {$endif i8086}
  1029. if (ops=1) and (opcode=A_RET) or (opcode=A_RETN) or (opcode=A_RETF) or
  1030. (opcode=A_RETW) or (opcode=A_RETNW) or (opcode=A_RETFW) or
  1031. {$ifndef x86_64}
  1032. (opcode=A_RETD) or (opcode=A_RETND) or
  1033. {$endif x86_64}
  1034. (opcode=A_RETFD)
  1035. {$ifdef x86_64}
  1036. or (opcode=A_RETQ) or (opcode=A_RETNQ) or (opcode=A_RETFQ)
  1037. {$endif x86_64}
  1038. then
  1039. siz:=S_W;
  1040. if (ops=1) and (opcode=A_PUSH) then
  1041. begin
  1042. {$ifdef i8086}
  1043. if (tx86operand(operands[1]).opr.val>=-128) and (tx86operand(operands[1]).opr.val<=127) then
  1044. begin
  1045. siz:=S_B;
  1046. message(asmr_w_unable_to_determine_constant_size_using_byte);
  1047. end
  1048. else
  1049. begin
  1050. siz:=S_W;
  1051. message(asmr_w_unable_to_determine_constant_size_using_word);
  1052. end;
  1053. {$else i8086}
  1054. { We are a 32 compiler, assume 32-bit by default. This is Delphi
  1055. compatible but bad coding practise.}
  1056. siz:=S_L;
  1057. message(asmr_w_unable_to_determine_reference_size_using_dword);
  1058. {$endif i8086}
  1059. end;
  1060. if (opcode=A_JMP) or (opcode=A_JCC) or (opcode=A_CALL) then
  1061. if ops=1 then
  1062. siz:=S_NEAR
  1063. else
  1064. siz:=S_FAR;
  1065. end;
  1066. { GNU AS interprets FDIV without operand differently
  1067. for version 2.9.1 and 2.10
  1068. we add explicit args to it !! }
  1069. if (ops=0) and
  1070. ((opcode=A_FSUBP) or
  1071. (opcode=A_FSUBRP) or
  1072. (opcode=A_FDIVP) or
  1073. (opcode=A_FDIVRP) or
  1074. (opcode=A_FSUB) or
  1075. (opcode=A_FSUBR) or
  1076. (opcode=A_FADD) or
  1077. (opcode=A_FADDP) or
  1078. (opcode=A_FDIV) or
  1079. (opcode=A_FDIVR)) then
  1080. begin
  1081. message1(asmr_w_adding_explicit_args_fXX,std_op2str[opcode]);
  1082. ops:=2;
  1083. operands[1].opr.typ:=OPR_REGISTER;
  1084. operands[2].opr.typ:=OPR_REGISTER;
  1085. operands[1].opr.reg:=NR_ST0;
  1086. operands[2].opr.reg:=NR_ST1;
  1087. end;
  1088. if (ops=1) and
  1089. (
  1090. (operands[1].opr.typ=OPR_REGISTER) and
  1091. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1092. (operands[1].opr.reg<>NR_ST) and
  1093. (operands[1].opr.reg<>NR_ST0)
  1094. ) and
  1095. (
  1096. (opcode=A_FSUBP) or
  1097. (opcode=A_FSUBRP) or
  1098. (opcode=A_FDIVP) or
  1099. (opcode=A_FDIVRP) or
  1100. (opcode=A_FADDP) or
  1101. (opcode=A_FMULP)
  1102. ) then
  1103. begin
  1104. message1(asmr_w_adding_explicit_first_arg_fXX,std_op2str[opcode]);
  1105. ops:=2;
  1106. operands[2].opr.typ:=OPR_REGISTER;
  1107. operands[2].opr.reg:=operands[1].opr.reg;
  1108. operands[1].opr.reg:=NR_ST0;
  1109. end;
  1110. if (ops=1) and
  1111. (
  1112. (operands[1].opr.typ=OPR_REGISTER) and
  1113. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1114. (operands[1].opr.reg<>NR_ST) and
  1115. (operands[1].opr.reg<>NR_ST0)
  1116. ) and
  1117. (
  1118. (opcode=A_FSUB) or
  1119. (opcode=A_FSUBR) or
  1120. (opcode=A_FDIV) or
  1121. (opcode=A_FDIVR) or
  1122. (opcode=A_FADD) or
  1123. (opcode=A_FMUL)
  1124. ) then
  1125. begin
  1126. message1(asmr_w_adding_explicit_second_arg_fXX,std_op2str[opcode]);
  1127. ops:=2;
  1128. operands[2].opr.typ:=OPR_REGISTER;
  1129. operands[2].opr.reg:=NR_ST0;
  1130. end;
  1131. { Check for 'POP CS' }
  1132. if (opcode=A_POP) and (ops=1) and (operands[1].opr.typ=OPR_REGISTER) and
  1133. (operands[1].opr.reg=NR_CS) then
  1134. {$ifdef i8086}
  1135. { On i8086 we print only a warning, because 'POP CS' works on 8086 and 8088
  1136. CPUs, but isn't supported on any later CPU }
  1137. Message(asmr_w_pop_cs_not_portable);
  1138. {$else i8086}
  1139. { On the i386 and x86_64 targets, we print out an error, because no CPU,
  1140. supported by these targets support 'POP CS' }
  1141. Message(asmr_e_pop_cs_not_valid);
  1142. {$endif i8086}
  1143. { I tried to convince Linus Torvalds to add
  1144. code to support ENTER instruction
  1145. (when raising a stack page fault)
  1146. but he replied that ENTER is a bad instruction and
  1147. Linux does not need to support it
  1148. So I think its at least a good idea to add a warning
  1149. if someone uses this in assembler code
  1150. FPC itself does not use it at all PM }
  1151. if (opcode=A_ENTER) and
  1152. (target_info.system in [system_i386_linux,system_i386_FreeBSD,system_i386_android]) then
  1153. Message(asmr_w_enter_not_supported_by_linux);
  1154. ai:=taicpu.op_none(opcode,siz);
  1155. ai.fileinfo:=filepos;
  1156. ai.SetOperandOrder(op_att);
  1157. ai.Ops:=Ops;
  1158. ai.Allocate_oper(Ops);
  1159. for i:=1 to Ops do
  1160. case operands[i].opr.typ of
  1161. OPR_CONSTANT :
  1162. ai.loadconst(i-1,operands[i].opr.val);
  1163. OPR_REGISTER:
  1164. ai.loadreg(i-1,operands[i].opr.reg);
  1165. OPR_SYMBOL:
  1166. {$ifdef i8086}
  1167. if operands[i].opr.symseg then
  1168. taicpu(ai).loadsegsymbol(i-1,operands[i].opr.symbol)
  1169. else
  1170. {$endif i8086}
  1171. ai.loadsymbol(i-1,operands[i].opr.symbol,operands[i].opr.symofs);
  1172. OPR_LOCAL :
  1173. with operands[i].opr do
  1174. ai.loadlocal(i-1,localsym,localsymofs,localindexreg,
  1175. localscale,localgetoffset,localforceref);
  1176. OPR_REFERENCE:
  1177. begin
  1178. if (opcode<>A_XLAT) and not is_x86_string_op(opcode) then
  1179. optimize_ref(operands[i].opr.ref,true);
  1180. ai.loadref(i-1,operands[i].opr.ref);
  1181. if operands[i].size<>OS_NO then
  1182. begin
  1183. asize:=0;
  1184. case operands[i].size of
  1185. OS_8,OS_S8 :
  1186. asize:=OT_BITS8;
  1187. OS_16,OS_S16, OS_M16:
  1188. asize:=OT_BITS16;
  1189. OS_32,OS_S32 :
  1190. {$ifdef i8086}
  1191. if siz=S_FAR then
  1192. asize:=OT_FAR
  1193. else
  1194. asize:=OT_BITS32;
  1195. {$else i8086}
  1196. asize:=OT_BITS32;
  1197. {$endif i8086}
  1198. OS_F32,OS_M32 :
  1199. asize:=OT_BITS32;
  1200. OS_64,OS_S64:
  1201. begin
  1202. { Only FPU operations know about 64bit values, for all
  1203. integer operations it is seen as 32bit
  1204. this applies only to i386, see tw16622}
  1205. if gas_needsuffix[opcode] in [attsufFPU,attsufFPUint] then
  1206. asize:=OT_BITS64
  1207. {$ifdef i386}
  1208. else
  1209. asize:=OT_BITS32
  1210. {$endif i386}
  1211. ;
  1212. end;
  1213. OS_F64,OS_C64, OS_M64 :
  1214. asize:=OT_BITS64;
  1215. OS_F80 :
  1216. asize:=OT_BITS80;
  1217. OS_128,OS_M128,OS_MS128:
  1218. asize := OT_BITS128;
  1219. OS_M256,OS_MS256:
  1220. asize := OT_BITS256;
  1221. end;
  1222. if asize<>0 then
  1223. ai.oper[i-1]^.ot:=(ai.oper[i-1]^.ot and not OT_SIZE_MASK) or asize;
  1224. end;
  1225. end;
  1226. end;
  1227. { Condition ? }
  1228. if condition<>C_None then
  1229. ai.SetCondition(condition);
  1230. { Set is_jmp, it enables asmwriter to emit short jumps if appropriate }
  1231. if (opcode=A_JMP) or (opcode=A_JCC) then
  1232. ai.is_jmp := True;
  1233. { Concat the opcode or give an error }
  1234. if assigned(ai) then
  1235. p.concat(ai)
  1236. else
  1237. Message(asmr_e_invalid_opcode_and_operand);
  1238. result:=ai;
  1239. end;
  1240. end.