rax86.pas 21 KB

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