rax86.pas 20 KB

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