rax86.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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. end;
  38. Tx86Instruction=class(TInstruction)
  39. OpOrder : TOperandOrder;
  40. opsize : topsize;
  41. constructor Create(optype : tcoperand);override;
  42. { Operand sizes }
  43. procedure AddReferenceSizes;
  44. procedure SetInstructionOpsize;
  45. procedure CheckOperandSizes;
  46. procedure CheckNonCommutativeOpcodes;
  47. procedure SwapOperands;
  48. { opcode adding }
  49. function ConcatInstruction(p : TAsmList) : tai;override;
  50. end;
  51. const
  52. AsmPrefixes = 6;
  53. AsmPrefix : array[0..AsmPrefixes-1] of TasmOP =(
  54. A_LOCK,A_REP,A_REPE,A_REPNE,A_REPNZ,A_REPZ
  55. );
  56. AsmOverrides = 6;
  57. AsmOverride : array[0..AsmOverrides-1] of TasmOP =(
  58. A_SEGCS,A_SEGES,A_SEGDS,A_SEGFS,A_SEGGS,A_SEGSS
  59. );
  60. CondAsmOps=3;
  61. CondAsmOp:array[0..CondAsmOps-1] of TasmOp=(
  62. A_CMOVcc, A_Jcc, A_SETcc
  63. );
  64. CondAsmOpStr:array[0..CondAsmOps-1] of string[4]=(
  65. 'CMOV','J','SET'
  66. );
  67. implementation
  68. uses
  69. globtype,globals,systems,verbose,
  70. cpuinfo,cgbase,cgutils,
  71. itcpugas,cgx86;
  72. {*****************************************************************************
  73. Parser Helpers
  74. *****************************************************************************}
  75. function is_prefix(t:tasmop):boolean;
  76. var
  77. i : longint;
  78. Begin
  79. is_prefix:=false;
  80. for i:=1 to AsmPrefixes do
  81. if t=AsmPrefix[i-1] then
  82. begin
  83. is_prefix:=true;
  84. exit;
  85. end;
  86. end;
  87. function is_override(t:tasmop):boolean;
  88. var
  89. i : longint;
  90. Begin
  91. is_override:=false;
  92. for i:=1 to AsmOverrides do
  93. if t=AsmOverride[i-1] then
  94. begin
  95. is_override:=true;
  96. exit;
  97. end;
  98. end;
  99. Function CheckPrefix(prefixop,op:tasmop): Boolean;
  100. { Checks if the prefix is valid with the following opcode }
  101. { return false if not, otherwise true }
  102. Begin
  103. CheckPrefix := TRUE;
  104. (* Case prefix of
  105. A_REP,A_REPNE,A_REPE:
  106. Case opcode Of
  107. A_SCASB,A_SCASW,A_SCASD,
  108. A_INS,A_OUTS,A_MOVS,A_CMPS,A_LODS,A_STOS:;
  109. Else
  110. Begin
  111. CheckPrefix := FALSE;
  112. exit;
  113. end;
  114. end; { case }
  115. A_LOCK:
  116. Case opcode Of
  117. A_BT,A_BTS,A_BTR,A_BTC,A_XCHG,A_ADD,A_OR,A_ADC,A_SBB,A_AND,A_SUB,
  118. A_XOR,A_NOT,A_NEG,A_INC,A_DEC:;
  119. Else
  120. Begin
  121. CheckPrefix := FALSE;
  122. Exit;
  123. end;
  124. end; { case }
  125. A_NONE: exit; { no prefix here }
  126. else
  127. CheckPrefix := FALSE;
  128. end; { end case } *)
  129. end;
  130. Function CheckOverride(overrideop,op:tasmop): Boolean;
  131. { Check if the override is valid, and if so then }
  132. { update the instr variable accordingly. }
  133. Begin
  134. CheckOverride := true;
  135. { Case instr.getinstruction of
  136. A_MOVS,A_XLAT,A_CMPS:
  137. Begin
  138. CheckOverride := TRUE;
  139. Message(assem_e_segment_override_not_supported);
  140. end
  141. end }
  142. end;
  143. Procedure FWaitWarning;
  144. begin
  145. if (target_info.system=system_i386_GO32V2) and (cs_fp_emulation in aktmoduleswitches) then
  146. Message(asmr_w_fwait_emu_prob);
  147. end;
  148. {*****************************************************************************
  149. TX86Operand
  150. *****************************************************************************}
  151. Procedure Tx86Operand.SetSize(_size:longint;force:boolean);
  152. begin
  153. inherited SetSize(_size,force);
  154. { OS_64 will be set to S_L and be fixed later
  155. in SetCorrectSize }
  156. opsize:=TCGSize2Opsize[size];
  157. end;
  158. Procedure Tx86Operand.SetCorrectSize(opcode:tasmop);
  159. begin
  160. if gas_needsuffix[opcode]=attsufFPU then
  161. begin
  162. case size of
  163. OS_32 : opsize:=S_FS;
  164. OS_64 : opsize:=S_FL;
  165. end;
  166. end
  167. else if gas_needsuffix[opcode]=attsufFPUint then
  168. begin
  169. case size of
  170. OS_16 : opsize:=S_IS;
  171. OS_32 : opsize:=S_IL;
  172. OS_64 : opsize:=S_IQ;
  173. end;
  174. end;
  175. end;
  176. {*****************************************************************************
  177. T386Instruction
  178. *****************************************************************************}
  179. constructor Tx86Instruction.Create(optype : tcoperand);
  180. begin
  181. inherited Create(optype);
  182. Opsize:=S_NO;
  183. end;
  184. procedure Tx86Instruction.SwapOperands;
  185. begin
  186. Inherited SwapOperands;
  187. { mark the correct order }
  188. if OpOrder=op_intel then
  189. OpOrder:=op_att
  190. else
  191. OpOrder:=op_intel;
  192. end;
  193. procedure Tx86Instruction.AddReferenceSizes;
  194. { this will add the sizes for references like [esi] which do not
  195. have the size set yet, it will take only the size if the other
  196. operand is a register }
  197. var
  198. operand2,i : longint;
  199. s : tasmsymbol;
  200. so : aint;
  201. begin
  202. for i:=1 to ops do
  203. begin
  204. operands[i].SetCorrectSize(opcode);
  205. if tx86operand(operands[i]).opsize=S_NO then
  206. begin
  207. {$ifdef x86_64}
  208. if (opcode=A_MOVQ) and
  209. (ops=2) and
  210. (operands[1].opr.typ=OPR_CONSTANT) then
  211. opsize:=S_Q
  212. else
  213. {$endif x86_64}
  214. case operands[i].Opr.Typ of
  215. OPR_LOCAL,
  216. OPR_REFERENCE :
  217. begin
  218. if i=2 then
  219. operand2:=1
  220. else
  221. operand2:=2;
  222. if operand2<ops then
  223. begin
  224. { Only allow register as operand to take the size from }
  225. if operands[operand2].opr.typ=OPR_REGISTER then
  226. begin
  227. if ((opcode<>A_MOVD) and
  228. (opcode<>A_CVTSI2SS)) then
  229. tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize;
  230. end
  231. else
  232. begin
  233. { if no register then take the opsize (which is available with ATT),
  234. if not availble then give an error }
  235. if opsize<>S_NO then
  236. tx86operand(operands[i]).opsize:=opsize
  237. else
  238. begin
  239. if (m_delphi in aktmodeswitches) then
  240. Message(asmr_w_unable_to_determine_reference_size_using_dword)
  241. else
  242. Message(asmr_e_unable_to_determine_reference_size);
  243. { recovery }
  244. tx86operand(operands[i]).opsize:=S_L;
  245. end;
  246. end;
  247. end
  248. else
  249. begin
  250. if opsize<>S_NO then
  251. tx86operand(operands[i]).opsize:=opsize
  252. end;
  253. end;
  254. OPR_SYMBOL :
  255. begin
  256. { Fix lea which need a reference }
  257. if opcode=A_LEA then
  258. begin
  259. s:=operands[i].opr.symbol;
  260. so:=operands[i].opr.symofs;
  261. operands[i].opr.typ:=OPR_REFERENCE;
  262. Fillchar(operands[i].opr.ref,sizeof(treference),0);
  263. operands[i].opr.ref.symbol:=s;
  264. operands[i].opr.ref.offset:=so;
  265. end;
  266. {$ifdef x86_64}
  267. tx86operand(operands[i]).opsize:=S_Q;
  268. {$else x86_64}
  269. tx86operand(operands[i]).opsize:=S_L;
  270. {$endif x86_64}
  271. end;
  272. end;
  273. end;
  274. end;
  275. end;
  276. procedure Tx86Instruction.SetInstructionOpsize;
  277. begin
  278. if opsize<>S_NO then
  279. exit;
  280. if (OpOrder=op_intel) then
  281. SwapOperands;
  282. case ops of
  283. 0 : ;
  284. 1 :
  285. begin
  286. { "push es" must be stored as a long PM }
  287. if ((opcode=A_PUSH) or
  288. (opcode=A_POP)) and
  289. (operands[1].opr.typ=OPR_REGISTER) and
  290. is_segment_reg(operands[1].opr.reg) then
  291. opsize:=S_L
  292. else
  293. opsize:=tx86operand(operands[1]).opsize;
  294. end;
  295. 2 :
  296. begin
  297. case opcode of
  298. A_MOVZX,A_MOVSX :
  299. begin
  300. case tx86operand(operands[1]).opsize of
  301. S_W :
  302. case tx86operand(operands[2]).opsize of
  303. S_L :
  304. opsize:=S_WL;
  305. end;
  306. S_B :
  307. case tx86operand(operands[2]).opsize of
  308. S_W :
  309. opsize:=S_BW;
  310. S_L :
  311. opsize:=S_BL;
  312. end;
  313. end;
  314. end;
  315. A_MOVD : { movd is a move from a mmx register to a
  316. 32 bit register or memory, so no opsize is correct here PM }
  317. exit;
  318. A_OUT :
  319. opsize:=tx86operand(operands[1]).opsize;
  320. else
  321. opsize:=tx86operand(operands[2]).opsize;
  322. end;
  323. end;
  324. 3 :
  325. opsize:=tx86operand(operands[3]).opsize;
  326. end;
  327. end;
  328. procedure Tx86Instruction.CheckOperandSizes;
  329. var
  330. sizeerr : boolean;
  331. i : longint;
  332. begin
  333. { Check only the most common opcodes here, the others are done in
  334. the assembler pass }
  335. case opcode of
  336. A_PUSH,A_POP,A_DEC,A_INC,A_NOT,A_NEG,
  337. A_CMP,A_MOV,
  338. A_ADD,A_SUB,A_ADC,A_SBB,
  339. A_AND,A_OR,A_TEST,A_XOR: ;
  340. else
  341. exit;
  342. end;
  343. { Handle the BW,BL,WL separatly }
  344. sizeerr:=false;
  345. { special push/pop selector case }
  346. if ((opcode=A_PUSH) or
  347. (opcode=A_POP)) and
  348. (operands[1].opr.typ=OPR_REGISTER) and
  349. is_segment_reg(operands[1].opr.reg) then
  350. exit;
  351. if opsize in [S_BW,S_BL,S_WL] then
  352. begin
  353. if ops<>2 then
  354. sizeerr:=true
  355. else
  356. begin
  357. case opsize of
  358. S_BW :
  359. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_W);
  360. S_BL :
  361. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_L);
  362. S_WL :
  363. sizeerr:=(tx86operand(operands[1]).opsize<>S_W) or (tx86operand(operands[2]).opsize<>S_L);
  364. end;
  365. end;
  366. end
  367. else
  368. begin
  369. for i:=1 to ops do
  370. begin
  371. if (operands[i].opr.typ<>OPR_CONSTANT) and
  372. (tx86operand(operands[i]).opsize in [S_B,S_W,S_L]) and
  373. (tx86operand(operands[i]).opsize<>opsize) then
  374. sizeerr:=true;
  375. end;
  376. end;
  377. if sizeerr then
  378. begin
  379. { if range checks are on then generate an error }
  380. if (cs_compilesystem in aktmoduleswitches) or
  381. not (cs_check_range in aktlocalswitches) then
  382. Message(asmr_w_size_suffix_and_dest_dont_match)
  383. else
  384. Message(asmr_e_size_suffix_and_dest_dont_match);
  385. end;
  386. end;
  387. { This check must be done with the operand in ATT order
  388. i.e.after swapping in the intel reader
  389. but before swapping in the NASM and TASM writers PM }
  390. procedure Tx86Instruction.CheckNonCommutativeOpcodes;
  391. begin
  392. if (OpOrder=op_intel) then
  393. SwapOperands;
  394. if (
  395. (ops=2) and
  396. (operands[1].opr.typ=OPR_REGISTER) and
  397. (operands[2].opr.typ=OPR_REGISTER) and
  398. { if the first is ST and the second is also a register
  399. it is necessarily ST1 .. ST7 }
  400. ((operands[1].opr.reg=NR_ST) or
  401. (operands[1].opr.reg=NR_ST0))
  402. ) or
  403. (ops=0) then
  404. if opcode=A_FSUBR then
  405. opcode:=A_FSUB
  406. else if opcode=A_FSUB then
  407. opcode:=A_FSUBR
  408. else if opcode=A_FDIVR then
  409. opcode:=A_FDIV
  410. else if opcode=A_FDIV then
  411. opcode:=A_FDIVR
  412. else if opcode=A_FSUBRP then
  413. opcode:=A_FSUBP
  414. else if opcode=A_FSUBP then
  415. opcode:=A_FSUBRP
  416. else if opcode=A_FDIVRP then
  417. opcode:=A_FDIVP
  418. else if opcode=A_FDIVP then
  419. opcode:=A_FDIVRP;
  420. if (
  421. (ops=1) and
  422. (operands[1].opr.typ=OPR_REGISTER) and
  423. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  424. (operands[1].opr.reg<>NR_ST) and
  425. (operands[1].opr.reg<>NR_ST0)
  426. ) then
  427. if opcode=A_FSUBRP then
  428. opcode:=A_FSUBP
  429. else if opcode=A_FSUBP then
  430. opcode:=A_FSUBRP
  431. else if opcode=A_FDIVRP then
  432. opcode:=A_FDIVP
  433. else if opcode=A_FDIVP then
  434. opcode:=A_FDIVRP;
  435. end;
  436. {*****************************************************************************
  437. opcode Adding
  438. *****************************************************************************}
  439. function Tx86Instruction.ConcatInstruction(p : TAsmList) : tai;
  440. var
  441. siz : topsize;
  442. i,asize : longint;
  443. ai : taicpu;
  444. begin
  445. if (OpOrder=op_intel) then
  446. SwapOperands;
  447. { Get Opsize }
  448. if (opsize<>S_NO) or (Ops=0) then
  449. siz:=opsize
  450. else
  451. begin
  452. if (Ops=2) and (operands[1].opr.typ=OPR_REGISTER) then
  453. siz:=tx86operand(operands[1]).opsize
  454. else
  455. siz:=tx86operand(operands[Ops]).opsize;
  456. { MOVD should be of size S_LQ or S_QL, but these do not exist PM }
  457. if (ops=2) and
  458. (tx86operand(operands[1]).opsize<>S_NO) and
  459. (tx86operand(operands[2]).opsize<>S_NO) and
  460. (tx86operand(operands[1]).opsize<>tx86operand(operands[2]).opsize) then
  461. siz:=S_NO;
  462. end;
  463. if ((opcode=A_MOVD)or
  464. (opcode=A_CVTSI2SS)) and
  465. ((tx86operand(operands[1]).opsize=S_NO) or
  466. (tx86operand(operands[2]).opsize=S_NO)) then
  467. siz:=S_NO;
  468. { NASM does not support FADD without args
  469. as alias of FADDP
  470. and GNU AS interprets FADD without operand differently
  471. for version 2.9.1 and 2.9.5 !! }
  472. if (ops=0) and
  473. ((opcode=A_FADD) or
  474. (opcode=A_FMUL) or
  475. (opcode=A_FSUB) or
  476. (opcode=A_FSUBR) or
  477. (opcode=A_FDIV) or
  478. (opcode=A_FDIVR)) then
  479. begin
  480. if opcode=A_FADD then
  481. opcode:=A_FADDP
  482. else if opcode=A_FMUL then
  483. opcode:=A_FMULP
  484. else if opcode=A_FSUB then
  485. opcode:=A_FSUBP
  486. else if opcode=A_FSUBR then
  487. opcode:=A_FSUBRP
  488. else if opcode=A_FDIV then
  489. opcode:=A_FDIVP
  490. else if opcode=A_FDIVR then
  491. opcode:=A_FDIVRP;
  492. message1(asmr_w_fadd_to_faddp,std_op2str[opcode]);
  493. end;
  494. {It is valid to specify some instructions without operand size.}
  495. if siz=S_NO then
  496. begin
  497. if (ops=1) and (opcode=A_INT) then
  498. siz:=S_B;
  499. if (ops=1) and (opcode=A_RET) or (opcode=A_RETN) or (opcode=A_RETF) then
  500. siz:=S_W;
  501. if (ops=1) and (opcode=A_PUSH) then
  502. begin
  503. {We are a 32 compiler, assume 32-bit by default. This is Delphi
  504. compatible but bad coding practise.}
  505. siz:=S_L;
  506. message(asmr_w_unable_to_determine_reference_size_using_dword);
  507. end;
  508. if (opcode=A_JMP) or (opcode=A_JCC) or (opcode=A_CALL) then
  509. if ops=1 then
  510. siz:=S_NEAR
  511. else
  512. siz:=S_FAR;
  513. end;
  514. {$ifdef x86_64}
  515. { Convert movq with at least one general registers or constant to a mov instruction }
  516. if (opcode=A_MOVQ) and
  517. (ops=2) and
  518. (
  519. (operands[1].opr.typ=OPR_REGISTER) or
  520. (operands[2].opr.typ=OPR_REGISTER) or
  521. (operands[1].opr.typ=OPR_CONSTANT)
  522. ) then
  523. opcode:=A_MOV;
  524. {$endif x86_64}
  525. { GNU AS interprets FDIV without operand differently
  526. for version 2.9.1 and 2.10
  527. we add explicit args to it !! }
  528. if (ops=0) and
  529. ((opcode=A_FSUBP) or
  530. (opcode=A_FSUBRP) or
  531. (opcode=A_FDIVP) or
  532. (opcode=A_FDIVRP) or
  533. (opcode=A_FSUB) or
  534. (opcode=A_FSUBR) or
  535. (opcode=A_FADD) or
  536. (opcode=A_FADDP) or
  537. (opcode=A_FDIV) or
  538. (opcode=A_FDIVR)) then
  539. begin
  540. message1(asmr_w_adding_explicit_args_fXX,std_op2str[opcode]);
  541. ops:=2;
  542. operands[1].opr.typ:=OPR_REGISTER;
  543. operands[2].opr.typ:=OPR_REGISTER;
  544. operands[1].opr.reg:=NR_ST0;
  545. operands[2].opr.reg:=NR_ST1;
  546. end;
  547. if (ops=1) and
  548. (
  549. (operands[1].opr.typ=OPR_REGISTER) and
  550. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  551. (operands[1].opr.reg<>NR_ST) and
  552. (operands[1].opr.reg<>NR_ST0)
  553. ) and
  554. (
  555. (opcode=A_FSUBP) or
  556. (opcode=A_FSUBRP) or
  557. (opcode=A_FDIVP) or
  558. (opcode=A_FDIVRP) or
  559. (opcode=A_FADDP) or
  560. (opcode=A_FMULP)
  561. ) then
  562. begin
  563. message1(asmr_w_adding_explicit_first_arg_fXX,std_op2str[opcode]);
  564. ops:=2;
  565. operands[2].opr.typ:=OPR_REGISTER;
  566. operands[2].opr.reg:=operands[1].opr.reg;
  567. operands[1].opr.reg:=NR_ST0;
  568. end;
  569. if (ops=1) and
  570. (
  571. (operands[1].opr.typ=OPR_REGISTER) and
  572. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  573. (operands[1].opr.reg<>NR_ST) and
  574. (operands[1].opr.reg<>NR_ST0)
  575. ) and
  576. (
  577. (opcode=A_FSUB) or
  578. (opcode=A_FSUBR) or
  579. (opcode=A_FDIV) or
  580. (opcode=A_FDIVR) or
  581. (opcode=A_FADD) or
  582. (opcode=A_FMUL)
  583. ) then
  584. begin
  585. message1(asmr_w_adding_explicit_second_arg_fXX,std_op2str[opcode]);
  586. ops:=2;
  587. operands[2].opr.typ:=OPR_REGISTER;
  588. operands[2].opr.reg:=NR_ST0;
  589. end;
  590. { I tried to convince Linus Torvalds to add
  591. code to support ENTER instruction
  592. (when raising a stack page fault)
  593. but he replied that ENTER is a bad instruction and
  594. Linux does not need to support it
  595. So I think its at least a good idea to add a warning
  596. if someone uses this in assembler code
  597. FPC itself does not use it at all PM }
  598. if (opcode=A_ENTER) and
  599. (target_info.system in [system_i386_linux,system_i386_FreeBSD]) then
  600. Message(asmr_w_enter_not_supported_by_linux);
  601. ai:=taicpu.op_none(opcode,siz);
  602. ai.SetOperandOrder(OpOrder);
  603. ai.Ops:=Ops;
  604. ai.Allocate_oper(Ops);
  605. for i:=1 to Ops do
  606. case operands[i].opr.typ of
  607. OPR_CONSTANT :
  608. ai.loadconst(i-1,operands[i].opr.val);
  609. OPR_REGISTER:
  610. ai.loadreg(i-1,operands[i].opr.reg);
  611. OPR_SYMBOL:
  612. ai.loadsymbol(i-1,operands[i].opr.symbol,operands[i].opr.symofs);
  613. OPR_LOCAL :
  614. with operands[i].opr do
  615. ai.loadlocal(i-1,localsym,localsymofs,localindexreg,
  616. localscale,localgetoffset,localforceref);
  617. OPR_REFERENCE:
  618. begin
  619. ai.loadref(i-1,operands[i].opr.ref);
  620. if operands[i].size<>OS_NO then
  621. begin
  622. asize:=0;
  623. case operands[i].size of
  624. OS_8,OS_S8 :
  625. asize:=OT_BITS8;
  626. OS_16,OS_S16 :
  627. asize:=OT_BITS16;
  628. OS_32,OS_S32,OS_F32 :
  629. asize:=OT_BITS32;
  630. OS_64,OS_S64:
  631. begin
  632. { Only FPU operations know about 64bit values, for all
  633. integer operations it is seen as 32bit }
  634. if gas_needsuffix[opcode] in [attsufFPU,attsufFPUint] then
  635. asize:=OT_BITS64
  636. else
  637. asize:=OT_BITS32;
  638. end;
  639. OS_F64,OS_C64 :
  640. asize:=OT_BITS64;
  641. OS_F80 :
  642. asize:=OT_BITS80;
  643. end;
  644. if asize<>0 then
  645. ai.oper[i-1]^.ot:=(ai.oper[i-1]^.ot and not OT_SIZE_MASK) or asize;
  646. end;
  647. end;
  648. end;
  649. { Condition ? }
  650. if condition<>C_None then
  651. ai.SetCondition(condition);
  652. { Concat the opcode or give an error }
  653. if assigned(ai) then
  654. begin
  655. { Check the instruction if it's valid }
  656. ai.CheckIfValid;
  657. p.concat(ai);
  658. end
  659. else
  660. Message(asmr_e_invalid_opcode_and_operand);
  661. result:=ai;
  662. end;
  663. end.