rax86.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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,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 : taasmoutput) : 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. case operands[i].Opr.Typ of
  208. OPR_LOCAL,
  209. OPR_REFERENCE :
  210. begin
  211. if i=2 then
  212. operand2:=1
  213. else
  214. operand2:=2;
  215. if operand2<ops then
  216. begin
  217. { Only allow register as operand to take the size from }
  218. if operands[operand2].opr.typ=OPR_REGISTER then
  219. begin
  220. if ((opcode<>A_MOVD) and
  221. (opcode<>A_CVTSI2SS)) then
  222. tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize;
  223. end
  224. else
  225. begin
  226. { if no register then take the opsize (which is available with ATT),
  227. if not availble then give an error }
  228. if opsize<>S_NO then
  229. tx86operand(operands[i]).opsize:=opsize
  230. else
  231. begin
  232. if (m_delphi in aktmodeswitches) then
  233. Message(asmr_w_unable_to_determine_reference_size_using_dword)
  234. else
  235. Message(asmr_e_unable_to_determine_reference_size);
  236. { recovery }
  237. tx86operand(operands[i]).opsize:=S_L;
  238. end;
  239. end;
  240. end
  241. else
  242. begin
  243. if opsize<>S_NO then
  244. tx86operand(operands[i]).opsize:=opsize
  245. end;
  246. end;
  247. OPR_SYMBOL :
  248. begin
  249. { Fix lea which need a reference }
  250. if opcode=A_LEA then
  251. begin
  252. s:=operands[i].opr.symbol;
  253. so:=operands[i].opr.symofs;
  254. operands[i].opr.typ:=OPR_REFERENCE;
  255. Fillchar(operands[i].opr.ref,sizeof(treference),0);
  256. operands[i].opr.ref.symbol:=s;
  257. operands[i].opr.ref.offset:=so;
  258. end;
  259. {$ifdef x86_64}
  260. tx86operand(operands[i]).opsize:=S_Q;
  261. {$else x86_64}
  262. tx86operand(operands[i]).opsize:=S_L;
  263. {$endif x86_64}
  264. end;
  265. end;
  266. end;
  267. end;
  268. end;
  269. procedure Tx86Instruction.SetInstructionOpsize;
  270. begin
  271. if opsize<>S_NO then
  272. exit;
  273. if (OpOrder=op_intel) then
  274. SwapOperands;
  275. case ops of
  276. 0 : ;
  277. 1 :
  278. begin
  279. { "push es" must be stored as a long PM }
  280. if ((opcode=A_PUSH) or
  281. (opcode=A_POP)) and
  282. (operands[1].opr.typ=OPR_REGISTER) and
  283. is_segment_reg(operands[1].opr.reg) then
  284. opsize:=S_L
  285. else
  286. opsize:=tx86operand(operands[1]).opsize;
  287. end;
  288. 2 :
  289. begin
  290. case opcode of
  291. A_MOVZX,A_MOVSX :
  292. begin
  293. case tx86operand(operands[1]).opsize of
  294. S_W :
  295. case tx86operand(operands[2]).opsize of
  296. S_L :
  297. opsize:=S_WL;
  298. end;
  299. S_B :
  300. case tx86operand(operands[2]).opsize of
  301. S_W :
  302. opsize:=S_BW;
  303. S_L :
  304. opsize:=S_BL;
  305. end;
  306. end;
  307. end;
  308. A_MOVD : { movd is a move from a mmx register to a
  309. 32 bit register or memory, so no opsize is correct here PM }
  310. exit;
  311. A_OUT :
  312. opsize:=tx86operand(operands[1]).opsize;
  313. else
  314. opsize:=tx86operand(operands[2]).opsize;
  315. end;
  316. end;
  317. 3 :
  318. opsize:=tx86operand(operands[3]).opsize;
  319. end;
  320. end;
  321. procedure Tx86Instruction.CheckOperandSizes;
  322. var
  323. sizeerr : boolean;
  324. i : longint;
  325. begin
  326. { Check only the most common opcodes here, the others are done in
  327. the assembler pass }
  328. case opcode of
  329. A_PUSH,A_POP,A_DEC,A_INC,A_NOT,A_NEG,
  330. A_CMP,A_MOV,
  331. A_ADD,A_SUB,A_ADC,A_SBB,
  332. A_AND,A_OR,A_TEST,A_XOR: ;
  333. else
  334. exit;
  335. end;
  336. { Handle the BW,BL,WL separatly }
  337. sizeerr:=false;
  338. { special push/pop selector case }
  339. if ((opcode=A_PUSH) or
  340. (opcode=A_POP)) and
  341. (operands[1].opr.typ=OPR_REGISTER) and
  342. is_segment_reg(operands[1].opr.reg) then
  343. exit;
  344. if opsize in [S_BW,S_BL,S_WL] then
  345. begin
  346. if ops<>2 then
  347. sizeerr:=true
  348. else
  349. begin
  350. case opsize of
  351. S_BW :
  352. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_W);
  353. S_BL :
  354. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_L);
  355. S_WL :
  356. sizeerr:=(tx86operand(operands[1]).opsize<>S_W) or (tx86operand(operands[2]).opsize<>S_L);
  357. end;
  358. end;
  359. end
  360. else
  361. begin
  362. for i:=1 to ops do
  363. begin
  364. if (operands[i].opr.typ<>OPR_CONSTANT) and
  365. (tx86operand(operands[i]).opsize in [S_B,S_W,S_L]) and
  366. (tx86operand(operands[i]).opsize<>opsize) then
  367. sizeerr:=true;
  368. end;
  369. end;
  370. if sizeerr then
  371. begin
  372. { if range checks are on then generate an error }
  373. if (cs_compilesystem in aktmoduleswitches) or
  374. not (cs_check_range in aktlocalswitches) then
  375. Message(asmr_w_size_suffix_and_dest_dont_match)
  376. else
  377. Message(asmr_e_size_suffix_and_dest_dont_match);
  378. end;
  379. end;
  380. { This check must be done with the operand in ATT order
  381. i.e.after swapping in the intel reader
  382. but before swapping in the NASM and TASM writers PM }
  383. procedure Tx86Instruction.CheckNonCommutativeOpcodes;
  384. begin
  385. if (OpOrder=op_intel) then
  386. SwapOperands;
  387. if (
  388. (ops=2) and
  389. (operands[1].opr.typ=OPR_REGISTER) and
  390. (operands[2].opr.typ=OPR_REGISTER) and
  391. { if the first is ST and the second is also a register
  392. it is necessarily ST1 .. ST7 }
  393. ((operands[1].opr.reg=NR_ST) or
  394. (operands[1].opr.reg=NR_ST0))
  395. ) or
  396. (ops=0) then
  397. if opcode=A_FSUBR then
  398. opcode:=A_FSUB
  399. else if opcode=A_FSUB then
  400. opcode:=A_FSUBR
  401. else if opcode=A_FDIVR then
  402. opcode:=A_FDIV
  403. else if opcode=A_FDIV then
  404. opcode:=A_FDIVR
  405. else if opcode=A_FSUBRP then
  406. opcode:=A_FSUBP
  407. else if opcode=A_FSUBP then
  408. opcode:=A_FSUBRP
  409. else if opcode=A_FDIVRP then
  410. opcode:=A_FDIVP
  411. else if opcode=A_FDIVP then
  412. opcode:=A_FDIVRP;
  413. if (
  414. (ops=1) and
  415. (operands[1].opr.typ=OPR_REGISTER) and
  416. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  417. (operands[1].opr.reg<>NR_ST) and
  418. (operands[1].opr.reg<>NR_ST0)
  419. ) then
  420. if opcode=A_FSUBRP then
  421. opcode:=A_FSUBP
  422. else if opcode=A_FSUBP then
  423. opcode:=A_FSUBRP
  424. else if opcode=A_FDIVRP then
  425. opcode:=A_FDIVP
  426. else if opcode=A_FDIVP then
  427. opcode:=A_FDIVRP;
  428. end;
  429. {*****************************************************************************
  430. opcode Adding
  431. *****************************************************************************}
  432. function Tx86Instruction.ConcatInstruction(p : taasmoutput) : tai;
  433. var
  434. siz : topsize;
  435. i,asize : longint;
  436. ai : taicpu;
  437. begin
  438. if (OpOrder=op_intel) then
  439. SwapOperands;
  440. { Get Opsize }
  441. if (opsize<>S_NO) or (Ops=0) then
  442. siz:=opsize
  443. else
  444. begin
  445. if (Ops=2) and (operands[1].opr.typ=OPR_REGISTER) then
  446. siz:=tx86operand(operands[1]).opsize
  447. else
  448. siz:=tx86operand(operands[Ops]).opsize;
  449. { MOVD should be of size S_LQ or S_QL, but these do not exist PM }
  450. if (ops=2) and
  451. (tx86operand(operands[1]).opsize<>S_NO) and
  452. (tx86operand(operands[2]).opsize<>S_NO) and
  453. (tx86operand(operands[1]).opsize<>tx86operand(operands[2]).opsize) then
  454. siz:=S_NO;
  455. end;
  456. if ((opcode=A_MOVD)or
  457. (opcode=A_CVTSI2SS)) and
  458. ((tx86operand(operands[1]).opsize=S_NO) or
  459. (tx86operand(operands[2]).opsize=S_NO)) then
  460. siz:=S_NO;
  461. { NASM does not support FADD without args
  462. as alias of FADDP
  463. and GNU AS interprets FADD without operand differently
  464. for version 2.9.1 and 2.9.5 !! }
  465. if (ops=0) and
  466. ((opcode=A_FADD) or
  467. (opcode=A_FMUL) or
  468. (opcode=A_FSUB) or
  469. (opcode=A_FSUBR) or
  470. (opcode=A_FDIV) or
  471. (opcode=A_FDIVR)) then
  472. begin
  473. if opcode=A_FADD then
  474. opcode:=A_FADDP
  475. else if opcode=A_FMUL then
  476. opcode:=A_FMULP
  477. else if opcode=A_FSUB then
  478. opcode:=A_FSUBP
  479. else if opcode=A_FSUBR then
  480. opcode:=A_FSUBRP
  481. else if opcode=A_FDIV then
  482. opcode:=A_FDIVP
  483. else if opcode=A_FDIVR then
  484. opcode:=A_FDIVRP;
  485. message1(asmr_w_fadd_to_faddp,std_op2str[opcode]);
  486. end;
  487. {It is valid to specify some instructions without operand size.}
  488. if siz=S_NO then
  489. begin
  490. if (ops=1) and (opcode=A_INT) then
  491. siz:=S_B;
  492. if (ops=1) and (opcode=A_RET) or (opcode=A_RETN) or (opcode=A_RETF) then
  493. siz:=S_W;
  494. if (ops=1) and (opcode=A_PUSH) then
  495. begin
  496. {We are a 32 compiler, assume 32-bit by default. This is Delphi
  497. compatible but bad coding practise.}
  498. siz:=S_L;
  499. message(asmr_w_unable_to_determine_reference_size_using_dword);
  500. end;
  501. if (opcode=A_JMP) or (opcode=A_JCC) or (opcode=A_CALL) then
  502. if ops=1 then
  503. siz:=S_NEAR
  504. else
  505. siz:=S_FAR;
  506. end;
  507. {$ifdef x86_64}
  508. { Convert movq with at least one general registers to mov instruction }
  509. if (opcode=A_MOVQ) and
  510. (ops=2) and
  511. (
  512. (operands[1].opr.typ=OPR_REGISTER) or
  513. (operands[2].opr.typ=OPR_REGISTER)
  514. ) then
  515. opcode:=A_MOV;
  516. {$endif x86_64}
  517. { GNU AS interprets FDIV without operand differently
  518. for version 2.9.1 and 2.10
  519. we add explicit args to it !! }
  520. if (ops=0) and
  521. ((opcode=A_FSUBP) or
  522. (opcode=A_FSUBRP) or
  523. (opcode=A_FDIVP) or
  524. (opcode=A_FDIVRP) or
  525. (opcode=A_FSUB) or
  526. (opcode=A_FSUBR) or
  527. (opcode=A_FADD) or
  528. (opcode=A_FADDP) or
  529. (opcode=A_FDIV) or
  530. (opcode=A_FDIVR)) then
  531. begin
  532. message1(asmr_w_adding_explicit_args_fXX,std_op2str[opcode]);
  533. ops:=2;
  534. operands[1].opr.typ:=OPR_REGISTER;
  535. operands[2].opr.typ:=OPR_REGISTER;
  536. operands[1].opr.reg:=NR_ST0;
  537. operands[2].opr.reg:=NR_ST1;
  538. end;
  539. if (ops=1) and
  540. (
  541. (operands[1].opr.typ=OPR_REGISTER) and
  542. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  543. (operands[1].opr.reg<>NR_ST) and
  544. (operands[1].opr.reg<>NR_ST0)
  545. ) and
  546. (
  547. (opcode=A_FSUBP) or
  548. (opcode=A_FSUBRP) or
  549. (opcode=A_FDIVP) or
  550. (opcode=A_FDIVRP) or
  551. (opcode=A_FADDP) or
  552. (opcode=A_FMULP)
  553. ) then
  554. begin
  555. message1(asmr_w_adding_explicit_first_arg_fXX,std_op2str[opcode]);
  556. ops:=2;
  557. operands[2].opr.typ:=OPR_REGISTER;
  558. operands[2].opr.reg:=operands[1].opr.reg;
  559. operands[1].opr.reg:=NR_ST0;
  560. end;
  561. if (ops=1) and
  562. (
  563. (operands[1].opr.typ=OPR_REGISTER) and
  564. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  565. (operands[1].opr.reg<>NR_ST) and
  566. (operands[1].opr.reg<>NR_ST0)
  567. ) and
  568. (
  569. (opcode=A_FSUB) or
  570. (opcode=A_FSUBR) or
  571. (opcode=A_FDIV) or
  572. (opcode=A_FDIVR) or
  573. (opcode=A_FADD) or
  574. (opcode=A_FMUL)
  575. ) then
  576. begin
  577. message1(asmr_w_adding_explicit_second_arg_fXX,std_op2str[opcode]);
  578. ops:=2;
  579. operands[2].opr.typ:=OPR_REGISTER;
  580. operands[2].opr.reg:=NR_ST0;
  581. end;
  582. { I tried to convince Linus Torvalds to add
  583. code to support ENTER instruction
  584. (when raising a stack page fault)
  585. but he replied that ENTER is a bad instruction and
  586. Linux does not need to support it
  587. So I think its at least a good idea to add a warning
  588. if someone uses this in assembler code
  589. FPC itself does not use it at all PM }
  590. if (opcode=A_ENTER) and
  591. (target_info.system in [system_i386_linux,system_i386_FreeBSD]) then
  592. Message(asmr_w_enter_not_supported_by_linux);
  593. ai:=taicpu.op_none(opcode,siz);
  594. ai.SetOperandOrder(OpOrder);
  595. ai.Ops:=Ops;
  596. ai.Allocate_oper(Ops);
  597. for i:=1 to Ops do
  598. case operands[i].opr.typ of
  599. OPR_CONSTANT :
  600. ai.loadconst(i-1,operands[i].opr.val);
  601. OPR_REGISTER:
  602. ai.loadreg(i-1,operands[i].opr.reg);
  603. OPR_SYMBOL:
  604. ai.loadsymbol(i-1,operands[i].opr.symbol,operands[i].opr.symofs);
  605. OPR_LOCAL :
  606. with operands[i].opr do
  607. ai.loadlocal(i-1,localsym,localsymofs,localindexreg,
  608. localscale,localgetoffset,localforceref);
  609. OPR_REFERENCE:
  610. begin
  611. ai.loadref(i-1,operands[i].opr.ref);
  612. if operands[i].size<>OS_NO then
  613. begin
  614. asize:=0;
  615. case operands[i].size of
  616. OS_8,OS_S8 :
  617. asize:=OT_BITS8;
  618. OS_16,OS_S16 :
  619. asize:=OT_BITS16;
  620. OS_32,OS_S32,OS_F32 :
  621. asize:=OT_BITS32;
  622. OS_64,OS_S64:
  623. begin
  624. { Only FPU operations know about 64bit values, for all
  625. integer operations it is seen as 32bit }
  626. if gas_needsuffix[opcode] in [attsufFPU,attsufFPUint] then
  627. asize:=OT_BITS64
  628. else
  629. asize:=OT_BITS32;
  630. end;
  631. OS_F64,OS_C64 :
  632. asize:=OT_BITS64;
  633. OS_F80 :
  634. asize:=OT_BITS80;
  635. end;
  636. if asize<>0 then
  637. ai.oper[i-1]^.ot:=(ai.oper[i-1]^.ot and not OT_SIZE_MASK) or asize;
  638. end;
  639. end;
  640. end;
  641. { Condition ? }
  642. if condition<>C_None then
  643. ai.SetCondition(condition);
  644. { Concat the opcode or give an error }
  645. if assigned(ai) then
  646. begin
  647. { Check the instruction if it's valid }
  648. ai.CheckIfValid;
  649. p.concat(ai);
  650. end
  651. else
  652. Message(asmr_e_invalid_opcode_and_operand);
  653. result:=ai;
  654. end;
  655. end.