agx86nsm.pas 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements an asmoutput class for the Nasm assembler with
  4. Intel syntax for the i386+
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit agx86nsm;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cpubase,globtype,
  23. aasmbase,aasmtai,aasmdata,aasmcpu,assemble,cgutils;
  24. type
  25. { T386NasmAssembler }
  26. TX86NasmAssembler = class(texternalassembler)
  27. private
  28. using_relative : boolean;
  29. function CodeSectionName: string;
  30. procedure WriteReference(var ref : treference);
  31. procedure WriteOper(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean);
  32. procedure WriteOper_jmp(const o:toper; op : tasmop);
  33. procedure WriteSection(atype:TAsmSectiontype;const aname:string);
  34. public
  35. procedure WriteTree(p:TAsmList);override;
  36. procedure WriteAsmList;override;
  37. procedure WriteExternals;
  38. procedure WriteSmartExternals;
  39. procedure WriteHeader;
  40. function MakeCmdLine: TCmdStr;override;
  41. end;
  42. implementation
  43. uses
  44. cutils,globals,systems,cclasses,
  45. fmodule,finput,verbose,cpuinfo,cgbase
  46. ;
  47. type
  48. {$ifdef cpuextended}
  49. t80bitarray = array[0..9] of byte;
  50. {$endif cpuextended}
  51. t64bitarray = array[0..7] of byte;
  52. t32bitarray = array[0..3] of byte;
  53. const
  54. line_length = 64;
  55. nasm_regname_table : array[tregisterindex] of string[7] = (
  56. {r386nasm.inc contains the Nasm name of each register.}
  57. {$if defined(x86_64)}
  58. {$i r8664nasm.inc}
  59. {$elseif defined(i386)}
  60. {$i r386nasm.inc}
  61. {$elseif defined(i8086)}
  62. {$i r8086nasm.inc}
  63. {$endif}
  64. );
  65. function nasm_regname(r:Tregister):string;
  66. var
  67. p : tregisterindex;
  68. begin
  69. p:=findreg_by_number(r);
  70. if p<>0 then
  71. result:=nasm_regname_table[p]
  72. else
  73. result:=generic_regname(r);
  74. end;
  75. function single2str(d : single) : string;
  76. var
  77. hs : string;
  78. p : longint;
  79. begin
  80. str(d,hs);
  81. { nasm expects a lowercase e }
  82. p:=pos('E',hs);
  83. if p>0 then
  84. hs[p]:='e';
  85. p:=pos('+',hs);
  86. if p>0 then
  87. delete(hs,p,1);
  88. single2str:=lower(hs);
  89. end;
  90. function double2str(d : double) : string;
  91. var
  92. hs : string;
  93. p : longint;
  94. begin
  95. str(d,hs);
  96. { nasm expects a lowercase e }
  97. p:=pos('E',hs);
  98. if p>0 then
  99. hs[p]:='e';
  100. p:=pos('+',hs);
  101. if p>0 then
  102. delete(hs,p,1);
  103. double2str:=lower(hs);
  104. end;
  105. function extended2str(e : extended) : string;
  106. var
  107. hs : string;
  108. p : longint;
  109. begin
  110. str(e,hs);
  111. { nasm expects a lowercase e }
  112. p:=pos('E',hs);
  113. if p>0 then
  114. hs[p]:='e';
  115. p:=pos('+',hs);
  116. if p>0 then
  117. delete(hs,p,1);
  118. extended2str:=lower(hs);
  119. end;
  120. { convert floating point values }
  121. { to correct endian }
  122. procedure swap64bitarray(var t: t64bitarray);
  123. var
  124. b: byte;
  125. begin
  126. b:= t[7];
  127. t[7] := t[0];
  128. t[0] := b;
  129. b := t[6];
  130. t[6] := t[1];
  131. t[1] := b;
  132. b:= t[5];
  133. t[5] := t[2];
  134. t[2] := b;
  135. b:= t[4];
  136. t[4] := t[3];
  137. t[3] := b;
  138. end;
  139. procedure swap32bitarray(var t: t32bitarray);
  140. var
  141. b: byte;
  142. begin
  143. b:= t[1];
  144. t[1]:= t[2];
  145. t[2]:= b;
  146. b:= t[0];
  147. t[0]:= t[3];
  148. t[3]:= b;
  149. end;
  150. function comp2str(d : bestreal) : string;
  151. type
  152. pdouble = ^double;
  153. var
  154. c : comp;
  155. dd : pdouble;
  156. begin
  157. c:=comp(d);
  158. dd:=pdouble(@c); { this makes a bitwise copy of c into a double }
  159. comp2str:=double2str(dd^);
  160. end;
  161. function sizestr(s:topsize;dest:boolean):string;
  162. begin
  163. case s of
  164. S_B : sizestr:='byte ';
  165. S_W : sizestr:='word ';
  166. S_L : sizestr:='dword ';
  167. S_Q : sizestr:='qword ';
  168. S_IS : sizestr:='word ';
  169. S_IL : sizestr:='dword ';
  170. S_IQ : sizestr:='qword ';
  171. S_FS : sizestr:='dword ';
  172. S_FL : sizestr:='qword ';
  173. S_FX : sizestr:='tword ';
  174. S_BW : if dest then
  175. sizestr:='word '
  176. else
  177. sizestr:='byte ';
  178. S_BL : if dest then
  179. sizestr:='dword '
  180. else
  181. sizestr:='byte ';
  182. S_WL : if dest then
  183. sizestr:='dword '
  184. else
  185. sizestr:='word ';
  186. {$ifdef x86_64}
  187. S_BQ : if dest then
  188. sizestr:='qword '
  189. else
  190. sizestr:='byte ';
  191. S_WQ : if dest then
  192. sizestr:='qword '
  193. else
  194. sizestr:='word ';
  195. S_LQ : if dest then
  196. sizestr:='qword '
  197. else
  198. sizestr:='dword ';
  199. { Nothing needed for XMM registers }
  200. S_XMM: sizestr:='';
  201. {$endif x86_64}
  202. else { S_NO }
  203. sizestr:='';
  204. end;
  205. end;
  206. Function PadTabs(const p:string;addch:char):string;
  207. var
  208. s : string;
  209. i : longint;
  210. begin
  211. i:=length(p);
  212. if addch<>#0 then
  213. begin
  214. inc(i);
  215. s:=p+addch;
  216. end
  217. else
  218. s:=p;
  219. if i<8 then
  220. PadTabs:=s+#9#9
  221. else
  222. PadTabs:=s+#9;
  223. end;
  224. type
  225. PExternChain = ^TExternChain;
  226. TExternChain = Record
  227. psym : pshortstring;
  228. is_defined : boolean;
  229. next : PExternChain;
  230. end;
  231. const
  232. FEC : PExternChain = nil;
  233. procedure AddSymbol(symname : string; defined : boolean);
  234. var
  235. EC : PExternChain;
  236. begin
  237. EC:=FEC;
  238. while assigned(EC) do
  239. begin
  240. if EC^.psym^=symname then
  241. begin
  242. if defined then
  243. EC^.is_defined:=true;
  244. exit;
  245. end;
  246. EC:=EC^.next;
  247. end;
  248. New(EC);
  249. EC^.next:=FEC;
  250. FEC:=EC;
  251. FEC^.psym:=stringdup(symname);
  252. FEC^.is_defined := defined;
  253. end;
  254. procedure FreeExternChainList;
  255. var
  256. EC : PExternChain;
  257. begin
  258. EC:=FEC;
  259. while assigned(EC) do
  260. begin
  261. FEC:=EC^.next;
  262. stringdispose(EC^.psym);
  263. Dispose(EC);
  264. EC:=FEC;
  265. end;
  266. end;
  267. {****************************************************************************
  268. TX86NasmAssembler
  269. ****************************************************************************}
  270. function TX86NasmAssembler.CodeSectionName: string;
  271. begin
  272. {$ifdef i8086}
  273. if current_settings.x86memorymodel in x86_far_code_models then
  274. result:=current_module.modulename^ + '_TEXT'
  275. else
  276. {$endif}
  277. result:='.text';
  278. end;
  279. procedure TX86NasmAssembler.WriteReference(var ref : treference);
  280. var
  281. first : boolean;
  282. base_done : boolean;
  283. begin
  284. with ref do
  285. begin
  286. AsmWrite('[');
  287. first:=true;
  288. base_done:=false;
  289. if (segment<>NR_NO) then
  290. AsmWrite(nasm_regname(segment)+':');
  291. {$ifdef x86_64}
  292. if (base=NR_RIP) then
  293. begin
  294. { nasm RIP is implicit for pic }
  295. if not (ref.refaddr in [addr_pic,addr_pic_no_got]) and not using_relative then
  296. AsmWrite('$ + ');
  297. base_done:=true;
  298. end;
  299. {$endif x86_64}
  300. if assigned(symbol) then
  301. begin
  302. AsmWrite(symbol.name);
  303. if SmartAsm then
  304. AddSymbol(symbol.name,false);
  305. first:=false;
  306. end;
  307. if (base<>NR_NO) and not base_done then
  308. begin
  309. if not(first) then
  310. AsmWrite('+')
  311. else
  312. first:=false;
  313. AsmWrite(nasm_regname(base))
  314. end;
  315. if (index<>NR_NO) then
  316. begin
  317. if not(first) then
  318. AsmWrite('+')
  319. else
  320. first:=false;
  321. AsmWrite(nasm_regname(index));
  322. if scalefactor<>0 then
  323. AsmWrite('*'+tostr(scalefactor));
  324. end;
  325. if offset<0 then
  326. begin
  327. AsmWrite(tostr(offset));
  328. first:=false;
  329. end
  330. else if (offset>0) then
  331. begin
  332. AsmWrite('+'+tostr(offset));
  333. first:=false;
  334. end;
  335. if first then
  336. AsmWrite('0');
  337. AsmWrite(']');
  338. end;
  339. end;
  340. procedure TX86NasmAssembler.WriteOper(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean);
  341. begin
  342. case o.typ of
  343. top_reg :
  344. AsmWrite(nasm_regname(o.reg));
  345. top_const :
  346. begin
  347. if (ops=1) and (opcode<>A_RET) then
  348. AsmWrite(sizestr(s,dest));
  349. AsmWrite(tostr(longint(o.val)));
  350. end;
  351. top_ref :
  352. begin
  353. if o.ref^.refaddr in [addr_no,addr_pic,addr_pic_no_got] then
  354. begin
  355. if not ((opcode = A_LEA) or (opcode = A_LGS) or
  356. (opcode = A_LSS) or (opcode = A_LFS) or
  357. (opcode = A_LES) or (opcode = A_LDS) or
  358. // (opcode = A_SHR) or (opcode = A_SHL) or
  359. // (opcode = A_SAR) or (opcode = A_SAL) or
  360. (opcode = A_OUT) or (opcode = A_IN)) then
  361. AsmWrite(sizestr(s,dest));
  362. WriteReference(o.ref^);
  363. end
  364. {$ifdef i8086}
  365. else if o.ref^.refaddr=addr_dgroup then
  366. begin
  367. AsmWrite('dgroup');
  368. end
  369. {$endif i8086}
  370. else
  371. begin
  372. {$ifdef x86_64}
  373. if s=S_L then
  374. asmwrite('dword ')
  375. else
  376. asmwrite('qword ');
  377. {$endif}
  378. {$ifdef i386}
  379. asmwrite('dword ');
  380. {$endif i386}
  381. {$ifdef i8086}
  382. if o.ref^.refaddr=addr_far then
  383. asmwrite('far ')
  384. else if o.ref^.refaddr=addr_seg then
  385. asmwrite('SEG ')
  386. else
  387. asmwrite('word ');
  388. {$endif i8086}
  389. if assigned(o.ref^.symbol) then
  390. begin
  391. if SmartAsm then
  392. AddSymbol(o.ref^.symbol.name,false);
  393. asmwrite(o.ref^.symbol.name);
  394. if o.ref^.offset=0 then
  395. exit;
  396. end;
  397. if o.ref^.offset>0 then
  398. asmwrite('+');
  399. asmwrite(tostr(o.ref^.offset));
  400. end;
  401. end;
  402. else
  403. internalerror(10001);
  404. end;
  405. end;
  406. procedure TX86NasmAssembler.WriteOper_jmp(const o:toper; op : tasmop);
  407. begin
  408. case o.typ of
  409. top_reg :
  410. AsmWrite(nasm_regname(o.reg));
  411. top_ref :
  412. if o.ref^.refaddr in [addr_no{$ifdef i8086},addr_far_ref{$endif}] then
  413. begin
  414. {$ifdef i8086}
  415. if o.ref^.refaddr=addr_far_ref then
  416. AsmWrite('far ');
  417. {$endif i8086}
  418. WriteReference(o.ref^);
  419. end
  420. else
  421. begin
  422. { NEAR forces NASM to emit near jumps, which are 386+ }
  423. {$ifndef i8086}
  424. if not(
  425. (op=A_JCXZ) or (op=A_JECXZ) or
  426. {$ifdef x86_64}
  427. (op=A_JRCXZ) or
  428. {$endif x86_64}
  429. (op=A_LOOP) or (op=A_LOOPE) or
  430. (op=A_LOOPNE) or (op=A_LOOPNZ) or
  431. (op=A_LOOPZ)
  432. ) then
  433. AsmWrite('NEAR ');
  434. {$endif i8086}
  435. {$ifdef i8086}
  436. if o.ref^.refaddr=addr_far then
  437. AsmWrite('far ');
  438. {$endif i8086}
  439. AsmWrite(o.ref^.symbol.name);
  440. if SmartAsm then
  441. AddSymbol(o.ref^.symbol.name,false);
  442. if o.ref^.offset>0 then
  443. AsmWrite('+'+tostr(o.ref^.offset))
  444. else
  445. if o.ref^.offset<0 then
  446. AsmWrite(tostr(o.ref^.offset));
  447. end;
  448. top_const :
  449. AsmWrite(tostr(aint(o.val)));
  450. else
  451. internalerror(10001);
  452. end;
  453. end;
  454. const
  455. ait_const2str : array[aitconst_128bit..aitconst_64bit_unaligned] of string[30]=(
  456. #9'FIXME_128BIT'#9,#9'DQ'#9,#9'DD'#9,#9'DW'#9,#9'DB'#9,
  457. #9'FIXME_SLEB128BIT'#9,#9'FIXME_ULEB128BIT'#9,
  458. #9'RVA'#9,#9'SECREL32'#9,#9'FIXME_darwin_dwarf_delta64'#9,
  459. #9'FIXME_darwin_dwarf_delta32'#9,#9'FIXME_half16bit'#9,
  460. #9'DW'#9,#9'DD'#9,#9'FIXME_64BIT_UNALIGNED'#9
  461. );
  462. procedure TX86NasmAssembler.WriteSection(atype:TAsmSectiontype;const aname:string);
  463. const
  464. secnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
  465. '.text',
  466. '.data',
  467. '.data',
  468. '.rodata',
  469. '.bss',
  470. '.tbss',
  471. '.pdata',
  472. '.text','.data','.data','.data','.data',
  473. '.stab',
  474. '.stabstr',
  475. '.idata2','.idata4','.idata5','.idata6','.idata7','.edata',
  476. '.eh_frame',
  477. '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
  478. '.fpc',
  479. '',
  480. '.init',
  481. '.fini',
  482. '.objc_class',
  483. '.objc_meta_class',
  484. '.objc_cat_cls_meth',
  485. '.objc_cat_inst_meth',
  486. '.objc_protocol',
  487. '.objc_string_object',
  488. '.objc_cls_meth',
  489. '.objc_inst_meth',
  490. '.objc_cls_refs',
  491. '.objc_message_refs',
  492. '.objc_symbols',
  493. '.objc_category',
  494. '.objc_class_vars',
  495. '.objc_instance_vars',
  496. '.objc_module_info',
  497. '.objc_class_names',
  498. '.objc_meth_var_types',
  499. '.objc_meth_var_names',
  500. '.objc_selector_strs',
  501. '.objc_protocol_ext',
  502. '.objc_class_ext',
  503. '.objc_property',
  504. '.objc_image_info',
  505. '.objc_cstring_object',
  506. '.objc_sel_fixup',
  507. '__DATA,__objc_data',
  508. '__DATA,__objc_const',
  509. '.objc_superrefs',
  510. '__DATA, __datacoal_nt,coalesced',
  511. '.objc_classlist',
  512. '.objc_nlclasslist',
  513. '.objc_catlist',
  514. '.obcj_nlcatlist',
  515. '.objc_protolist'
  516. );
  517. begin
  518. AsmLn;
  519. AsmWrite('SECTION ');
  520. { go32v2 stub only loads .text and .data sections, and allocates space for .bss.
  521. Thus, data which normally goes into .rodata and .rodata_norel sections must
  522. end up in .data section }
  523. if (atype in [sec_rodata,sec_rodata_norel]) and
  524. (target_info.system=system_i386_go32v2) then
  525. AsmWrite('.data')
  526. else if (atype=sec_user) then
  527. AsmWrite(aname)
  528. else if (atype=sec_threadvar) and
  529. (target_info.system in (systems_windows+systems_wince)) then
  530. AsmWrite('.tls'#9'bss')
  531. else if secnames[atype]='.text' then
  532. AsmWrite(CodeSectionName)
  533. else
  534. AsmWrite(secnames[atype]);
  535. if create_smartlink_sections and
  536. (atype<>sec_bss) and
  537. (aname<>'') then
  538. begin
  539. AsmWrite('.');
  540. AsmWrite(aname);
  541. end;
  542. AsmLn;
  543. LasTSecType:=atype;
  544. end;
  545. procedure TX86NasmAssembler.WriteTree(p:TAsmList);
  546. {$ifdef cpuextended}
  547. type
  548. t80bitarray = array[0..9] of byte;
  549. {$endif cpuextended}
  550. var
  551. s : string;
  552. hp : tai;
  553. counter,
  554. lines,
  555. i,j,l : longint;
  556. InlineLevel : longint;
  557. consttype : taiconst_type;
  558. do_line,
  559. quoted : boolean;
  560. co : comp;
  561. sin : single;
  562. d : double;
  563. {$ifdef cpuextended}
  564. e : extended;
  565. {$endif cpuextended}
  566. fixed_opcode: TAsmOp;
  567. prefix : string;
  568. begin
  569. if not assigned(p) then
  570. exit;
  571. InlineLevel:=0;
  572. { lineinfo is only needed for al_procedures (PFV) }
  573. do_line:=(cs_asm_source in current_settings.globalswitches) or
  574. ((cs_lineinfo in current_settings.moduleswitches)
  575. and (p=current_asmdata.asmlists[al_procedures]));
  576. hp:=tai(p.first);
  577. while assigned(hp) do
  578. begin
  579. prefetch(pointer(hp.next)^);
  580. if not(hp.typ in SkipLineInfo) then
  581. begin
  582. current_filepos:=tailineinfo(hp).fileinfo;
  583. { no line info for inlined code }
  584. if do_line and (inlinelevel=0) then
  585. WriteSourceLine(hp as tailineinfo);
  586. end;
  587. case hp.typ of
  588. ait_comment :
  589. Begin
  590. AsmWrite(target_asm.comment);
  591. AsmWritePChar(tai_comment(hp).str);
  592. AsmLn;
  593. End;
  594. ait_regalloc :
  595. begin
  596. if (cs_asm_regalloc in current_settings.globalswitches) then
  597. AsmWriteLn(#9#9+target_asm.comment+'Register '+nasm_regname(tai_regalloc(hp).reg)+' '+
  598. regallocstr[tai_regalloc(hp).ratype]);
  599. end;
  600. ait_tempalloc :
  601. begin
  602. if (cs_asm_tempalloc in current_settings.globalswitches) then
  603. WriteTempalloc(tai_tempalloc(hp));
  604. end;
  605. ait_section :
  606. begin
  607. if tai_section(hp).sectype<>sec_none then
  608. WriteSection(tai_section(hp).sectype,tai_section(hp).name^);
  609. LasTSecType:=tai_section(hp).sectype;
  610. end;
  611. ait_align :
  612. begin
  613. if (tai_align(hp).aligntype>1) then
  614. begin
  615. if (lastsectype=sec_bss) or (
  616. (lastsectype=sec_threadvar) and
  617. (target_info.system in (systems_windows+systems_wince))
  618. ) then
  619. AsmWriteLn(#9'ALIGNB '+tostr(tai_align(hp).aligntype))
  620. else
  621. AsmWriteLn(#9'ALIGN '+tostr(tai_align(hp).aligntype));
  622. end;
  623. end;
  624. ait_datablock :
  625. begin
  626. if tai_datablock(hp).is_global or SmartAsm then
  627. begin
  628. AsmWrite(#9'GLOBAL ');
  629. AsmWriteLn(tai_datablock(hp).sym.name);
  630. end;
  631. AsmWrite(PadTabs(tai_datablock(hp).sym.name,':'));
  632. if SmartAsm then
  633. AddSymbol(tai_datablock(hp).sym.name,true);
  634. AsmWriteLn('RESB'#9+tostr(tai_datablock(hp).size));
  635. end;
  636. ait_const:
  637. begin
  638. consttype:=tai_const(hp).consttype;
  639. case consttype of
  640. aitconst_64bit,
  641. aitconst_64bit_unaligned:
  642. begin
  643. if assigned(tai_const(hp).sym) then
  644. internalerror(200404292);
  645. AsmWrite(ait_const2str[aitconst_32bit]);
  646. AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  647. AsmWrite(',');
  648. AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  649. AsmLn;
  650. end;
  651. aitconst_uleb128bit,
  652. aitconst_sleb128bit,
  653. aitconst_128bit:
  654. begin
  655. AsmWriteLn(target_asm.comment+'Unsupported const type '+
  656. ait_const2str[consttype]);
  657. end;
  658. {$ifdef i8086}
  659. aitconst_farptr:
  660. begin
  661. AsmWrite(ait_const2str[aitconst_16bit]);
  662. if assigned(tai_const(hp).sym) then
  663. begin
  664. if SmartAsm then
  665. AddSymbol(tai_const(hp).sym.name,false);
  666. AsmWrite(tai_const(hp).sym.name);
  667. if tai_const(hp).value<>0 then
  668. AsmWrite(tostr_with_plus(tai_const(hp).value));
  669. AsmLn;
  670. AsmWrite(ait_const2str[aitconst_16bit]);
  671. AsmWrite('SEG ');
  672. AsmWrite(tai_const(hp).sym.name);
  673. end
  674. else
  675. AsmWrite(tostr(lo(longint(tai_const(hp).value)))+','+
  676. tostr(hi(longint(tai_const(hp).value))));
  677. AsmLn;
  678. end;
  679. {$endif i8086}
  680. aitconst_32bit,
  681. aitconst_16bit,
  682. aitconst_8bit,
  683. aitconst_rva_symbol,
  684. aitconst_secrel32_symbol,
  685. aitconst_16bit_unaligned,
  686. aitconst_32bit_unaligned:
  687. begin
  688. AsmWrite(ait_const2str[tai_const(hp).consttype]);
  689. l:=0;
  690. repeat
  691. if assigned(tai_const(hp).sym) then
  692. begin
  693. if SmartAsm then
  694. begin
  695. AddSymbol(tai_const(hp).sym.name,false);
  696. if assigned(tai_const(hp).endsym) then
  697. AddSymbol(tai_const(hp).endsym.name,false);
  698. end;
  699. if assigned(tai_const(hp).endsym) then
  700. s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
  701. else
  702. s:=tai_const(hp).sym.name;
  703. if tai_const(hp).value<>0 then
  704. s:=s+tostr_with_plus(tai_const(hp).value);
  705. end
  706. else
  707. s:=tostr(tai_const(hp).value);
  708. AsmWrite(s);
  709. inc(l,length(s));
  710. if (l>line_length) or
  711. (hp.next=nil) or
  712. (tai(hp.next).typ<>ait_const) or
  713. (tai_const(hp.next).consttype<>consttype) then
  714. break;
  715. hp:=tai(hp.next);
  716. AsmWrite(',');
  717. until false;
  718. AsmLn;
  719. end;
  720. else
  721. internalerror(200704252);
  722. end;
  723. end;
  724. {$if defined(cpuextended) and defined(FPC_HAS_TYPE_EXTENDED)}
  725. ait_real_80bit :
  726. begin
  727. if do_line then
  728. AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_real_80bit(hp).value));
  729. { Make sure e is a extended type, bestreal could be
  730. a different type (bestreal) !! (PFV) }
  731. e:=tai_real_80bit(hp).value;
  732. AsmWrite(#9#9'DB'#9);
  733. for i:=0 to 9 do
  734. begin
  735. if i<>0 then
  736. AsmWrite(',');
  737. AsmWrite(tostr(t80bitarray(e)[i]));
  738. end;
  739. for i:=11 to tai_real_80bit(hp).savesize do
  740. AsmWrite(',0');
  741. AsmLn;
  742. end;
  743. {$else cpuextended}
  744. ait_real_80bit :
  745. AsmWriteLn(#9#9'DT'#9+extended2str(tai_real_80bit(hp).value));
  746. {$endif cpuextended}
  747. // ait_real_64bit :
  748. // AsmWriteLn(#9#9'DQ'#9+double2str(tai_real_64bit(hp).value));
  749. ait_real_64bit :
  750. begin
  751. if do_line then
  752. AsmWriteLn(target_asm.comment+'value: '+double2str(tai_real_64bit(hp).value));
  753. d:=tai_real_64bit(hp).value;
  754. { swap the values to correct endian if required }
  755. if source_info.endian <> target_info.endian then
  756. swap64bitarray(t64bitarray(d));
  757. AsmWrite(#9#9'DB'#9);
  758. {$ifdef arm}
  759. if tai_real_64bit(hp).formatoptions=fo_hiloswapped then
  760. begin
  761. for i:=4 to 7 do
  762. begin
  763. if i<>4 then
  764. AsmWrite(',');
  765. AsmWrite(tostr(t64bitarray(d)[i]));
  766. end;
  767. for i:=0 to 3 do
  768. begin
  769. AsmWrite(',');
  770. AsmWrite(tostr(t64bitarray(d)[i]));
  771. end;
  772. end
  773. else
  774. {$endif arm}
  775. begin
  776. for i:=0 to 7 do
  777. begin
  778. if i<>0 then
  779. AsmWrite(',');
  780. AsmWrite(tostr(t64bitarray(d)[i]));
  781. end;
  782. end;
  783. AsmLn;
  784. end;
  785. // ait_real_32bit :
  786. // AsmWriteLn(#9#9'DD'#9+single2str(tai_real_32bit(hp).value));
  787. ait_real_32bit :
  788. begin
  789. if do_line then
  790. AsmWriteLn(target_asm.comment+'value: '+single2str(tai_real_32bit(hp).value));
  791. sin:=tai_real_32bit(hp).value;
  792. { swap the values to correct endian if required }
  793. if source_info.endian <> target_info.endian then
  794. swap32bitarray(t32bitarray(sin));
  795. AsmWrite(#9#9'DB'#9);
  796. for i:=0 to 3 do
  797. begin
  798. if i<>0 then
  799. AsmWrite(',');
  800. AsmWrite(tostr(t32bitarray(sin)[i]));
  801. end;
  802. AsmLn;
  803. end;
  804. // ait_comp_64bit :
  805. // AsmWriteLn(#9#9'DQ'#9+comp2str(tai_real_80bit(hp).value));
  806. ait_comp_64bit :
  807. begin
  808. if do_line then
  809. AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_comp_64bit(hp).value));
  810. AsmWrite(#9#9'DB'#9);
  811. co:=comp(tai_comp_64bit(hp).value);
  812. { swap the values to correct endian if required }
  813. if source_info.endian <> target_info.endian then
  814. swap64bitarray(t64bitarray(co));
  815. for i:=0 to 7 do
  816. begin
  817. if i<>0 then
  818. AsmWrite(',');
  819. AsmWrite(tostr(t64bitarray(co)[i]));
  820. end;
  821. AsmLn;
  822. end;
  823. ait_string :
  824. begin
  825. counter := 0;
  826. lines := tai_string(hp).len div line_length;
  827. { separate lines in different parts }
  828. if tai_string(hp).len > 0 then
  829. Begin
  830. for j := 0 to lines-1 do
  831. begin
  832. AsmWrite(#9#9'DB'#9);
  833. quoted:=false;
  834. for i:=counter to counter+line_length-1 do
  835. begin
  836. { it is an ascii character. }
  837. if (ord(tai_string(hp).str[i])>31) and
  838. (ord(tai_string(hp).str[i])<128) and
  839. (tai_string(hp).str[i]<>'"') then
  840. begin
  841. if not(quoted) then
  842. begin
  843. if i>counter then
  844. AsmWrite(',');
  845. AsmWrite('"');
  846. end;
  847. AsmWrite(tai_string(hp).str[i]);
  848. quoted:=true;
  849. end { if > 31 and < 128 and ord('"') }
  850. else
  851. begin
  852. if quoted then
  853. AsmWrite('"');
  854. if i>counter then
  855. AsmWrite(',');
  856. quoted:=false;
  857. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  858. end;
  859. end; { end for i:=0 to... }
  860. if quoted then AsmWrite('"');
  861. AsmWrite(target_info.newline);
  862. inc(counter,line_length);
  863. end; { end for j:=0 ... }
  864. { do last line of lines }
  865. if counter<tai_string(hp).len then
  866. AsmWrite(#9#9'DB'#9);
  867. quoted:=false;
  868. for i:=counter to tai_string(hp).len-1 do
  869. begin
  870. { it is an ascii character. }
  871. if (ord(tai_string(hp).str[i])>31) and
  872. (ord(tai_string(hp).str[i])<128) and
  873. (tai_string(hp).str[i]<>'"') then
  874. begin
  875. if not(quoted) then
  876. begin
  877. if i>counter then
  878. AsmWrite(',');
  879. AsmWrite('"');
  880. end;
  881. AsmWrite(tai_string(hp).str[i]);
  882. quoted:=true;
  883. end { if > 31 and < 128 and " }
  884. else
  885. begin
  886. if quoted then
  887. AsmWrite('"');
  888. if i>counter then
  889. AsmWrite(',');
  890. quoted:=false;
  891. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  892. end;
  893. end; { end for i:=0 to... }
  894. if quoted then
  895. AsmWrite('"');
  896. end;
  897. AsmLn;
  898. end;
  899. ait_label :
  900. begin
  901. if tai_label(hp).labsym.is_used then
  902. begin
  903. if SmartAsm and (tai_label(hp).labsym.bind=AB_GLOBAL) then
  904. begin
  905. AsmWrite(#9'GLOBAL ');
  906. AsmWriteLn(tai_label(hp).labsym.name);
  907. end;
  908. AsmWriteLn(tai_label(hp).labsym.name+':');
  909. end;
  910. if SmartAsm then
  911. AddSymbol(tai_label(hp).labsym.name,true);
  912. end;
  913. ait_symbol :
  914. begin
  915. if tai_symbol(hp).has_value then
  916. internalerror(2009090803);
  917. if tai_symbol(hp).is_global or SmartAsm then
  918. begin
  919. AsmWrite(#9'GLOBAL ');
  920. AsmWriteLn(tai_symbol(hp).sym.name);
  921. end;
  922. AsmWrite(tai_symbol(hp).sym.name);
  923. if SmartAsm then
  924. AddSymbol(tai_symbol(hp).sym.name,true);
  925. if assigned(hp.next) and not(tai(hp.next).typ in
  926. [ait_const,
  927. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
  928. AsmWriteLn(':')
  929. end;
  930. ait_symbol_end : ;
  931. ait_instruction :
  932. begin
  933. fixed_opcode:=taicpu(hp).FixNonCommutativeOpcodes;
  934. { We need intel order, no At&t }
  935. taicpu(hp).SetOperandOrder(op_intel);
  936. s:='';
  937. if ((fixed_opcode=A_FADDP) or
  938. (fixed_opcode=A_FMULP))
  939. and (taicpu(hp).ops=0) then
  940. begin
  941. taicpu(hp).allocate_oper(2);
  942. taicpu(hp).oper[0]^.typ:=top_reg;
  943. taicpu(hp).oper[0]^.reg:=NR_ST1;
  944. taicpu(hp).oper[1]^.typ:=top_reg;
  945. taicpu(hp).oper[1]^.reg:=NR_ST;
  946. end;
  947. { NASM only accepts move for loading of
  948. simple symbol address }
  949. if ((taicpu(hp).opcode=A_LEA) and
  950. (taicpu(hp).ops=2) and
  951. (taicpu(hp).oper[0]^.typ=top_reg) and
  952. (reg2opsize(taicpu(hp).oper[0]^.reg) in [S_NO,S_Q]) and
  953. (taicpu(hp).oper[1]^.typ=top_ref) and
  954. (taicpu(hp).oper[1]^.ref^.refaddr<>addr_no) and
  955. assigned(taicpu(hp).oper[1]^.ref^.symbol) and
  956. (taicpu(hp).oper[1]^.ref^.base=NR_NO)) then
  957. begin
  958. AsmWrite(target_asm.comment);
  959. AsmWriteln('Converting LEA to MOV instruction');
  960. taicpu(hp).opcode:=A_MOV;
  961. end;
  962. if fixed_opcode=A_FWAIT then
  963. AsmWriteln(#9#9'DB'#9'09bh')
  964. else
  965. begin
  966. prefix:='';
  967. {$ifdef i8086}
  968. { nickysn note: I don't know if the 187 requires FWAIT before
  969. every instruction like the 8087, so I'm including it just in case }
  970. if (current_settings.cputype<=cpu_186) and
  971. requires_fwait_on_8087(fixed_opcode) then
  972. prefix:='wait '+prefix;
  973. {$endif i8086}
  974. {$ifndef i8086}
  975. { We need to explicitely set
  976. word prefix to get selectors
  977. to be pushed in 2 bytes PM }
  978. if (taicpu(hp).opsize=S_W) and
  979. ((fixed_opcode=A_PUSH) or
  980. (fixed_opcode=A_POP)) and
  981. (taicpu(hp).oper[0]^.typ=top_reg) and
  982. (is_segment_reg(taicpu(hp).oper[0]^.reg)) then
  983. AsmWriteln(#9#9'DB'#9'066h');
  984. {$endif not i8086}
  985. AsmWrite(#9#9+prefix+std_op2str[fixed_opcode]+cond2str[taicpu(hp).condition]);
  986. if taicpu(hp).ops<>0 then
  987. begin
  988. if is_calljmp(fixed_opcode) then
  989. begin
  990. AsmWrite(#9);
  991. WriteOper_jmp(taicpu(hp).oper[0]^,fixed_opcode);
  992. end
  993. else
  994. begin
  995. for i:=0 to taicpu(hp).ops-1 do
  996. begin
  997. if i=0 then
  998. AsmWrite(#9)
  999. else
  1000. AsmWrite(',');
  1001. WriteOper(taicpu(hp).oper[i]^,taicpu(hp).opsize,fixed_opcode,taicpu(hp).ops,(i=2));
  1002. end;
  1003. end;
  1004. end;
  1005. AsmLn;
  1006. end;
  1007. end;
  1008. ait_stab,
  1009. ait_force_line,
  1010. ait_function_name : ;
  1011. ait_cutobject :
  1012. begin
  1013. if SmartAsm then
  1014. begin
  1015. { only reset buffer if nothing has changed }
  1016. if AsmSize=AsmStartSize then
  1017. AsmClear
  1018. else
  1019. begin
  1020. if SmartAsm then
  1021. begin
  1022. WriteSmartExternals;
  1023. FreeExternChainList;
  1024. end;
  1025. AsmClose;
  1026. DoAssemble;
  1027. AsmCreate(tai_cutobject(hp).place);
  1028. WriteHeader;
  1029. end;
  1030. { avoid empty files }
  1031. while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
  1032. begin
  1033. if tai(hp.next).typ=ait_section then
  1034. lasTSectype:=tai_section(hp.next).sectype;
  1035. hp:=tai(hp.next);
  1036. end;
  1037. if lasTSectype<>sec_none then
  1038. WriteSection(lasTSectype,'');
  1039. AsmStartSize:=AsmSize;
  1040. end;
  1041. end;
  1042. ait_marker :
  1043. if tai_marker(hp).kind=mark_NoLineInfoStart then
  1044. inc(InlineLevel)
  1045. else if tai_marker(hp).kind=mark_NoLineInfoEnd then
  1046. dec(InlineLevel);
  1047. ait_directive :
  1048. begin
  1049. case tai_directive(hp).directive of
  1050. asd_nasm_import :
  1051. AsmWrite('import ');
  1052. asd_extern :
  1053. AsmWrite('EXTERN ');
  1054. else
  1055. internalerror(200509191);
  1056. end;
  1057. if tai_directive(hp).name<>'' then
  1058. begin
  1059. if SmartAsm then
  1060. AddSymbol(tai_directive(hp).name,false);
  1061. AsmWrite(tai_directive(hp).name);
  1062. end;
  1063. AsmLn;
  1064. end;
  1065. ait_seh_directive :
  1066. { Ignore for now };
  1067. ait_varloc:
  1068. begin
  1069. if tai_varloc(hp).newlocationhi<>NR_NO then
  1070. AsmWriteLn(target_asm.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1071. std_regname(tai_varloc(hp).newlocationhi)+':'+std_regname(tai_varloc(hp).newlocation))
  1072. else
  1073. AsmWriteLn(target_asm.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1074. std_regname(tai_varloc(hp).newlocation));
  1075. end;
  1076. else
  1077. internalerror(10000);
  1078. end;
  1079. hp:=tai(hp.next);
  1080. end;
  1081. end;
  1082. procedure TX86NasmAssembler.WriteExternals;
  1083. var
  1084. sym : TAsmSymbol;
  1085. i : longint;
  1086. begin
  1087. for i:=0 to current_asmdata.AsmSymbolDict.Count-1 do
  1088. begin
  1089. sym:=TAsmSymbol(current_asmdata.AsmSymbolDict[i]);
  1090. if sym.bind=AB_EXTERNAL then
  1091. AsmWriteln('EXTERN'#9+sym.name);
  1092. end;
  1093. end;
  1094. procedure TX86NasmAssembler.WriteSmartExternals;
  1095. var
  1096. EC : PExternChain;
  1097. begin
  1098. EC:=FEC;
  1099. while assigned(EC) do
  1100. begin
  1101. if not EC^.is_defined then
  1102. AsmWriteln('EXTERN'#9+EC^.psym^);
  1103. EC:=EC^.next;
  1104. end;
  1105. end;
  1106. procedure TX86NasmAssembler.WriteHeader;
  1107. begin
  1108. {$ifdef i8086}
  1109. AsmWriteLn('BITS 16');
  1110. case current_settings.cputype of
  1111. cpu_8086: AsmWriteLn('CPU 8086');
  1112. cpu_186: AsmWriteLn('CPU 186');
  1113. cpu_286: AsmWriteLn('CPU 286');
  1114. cpu_386: AsmWriteLn('CPU 386');
  1115. cpu_Pentium: AsmWriteLn('CPU PENTIUM');
  1116. cpu_Pentium2: AsmWriteLn('CPU P2');
  1117. cpu_Pentium3: AsmWriteLn('CPU P3');
  1118. cpu_Pentium4: AsmWriteLn('CPU P4');
  1119. cpu_PentiumM: AsmWriteLn('CPU P4');
  1120. else
  1121. internalerror(2013050101);
  1122. end;
  1123. AsmWriteLn('SECTION ' + CodeSectionName + ' use16 class=code');
  1124. if current_settings.x86memorymodel in x86_near_data_models then
  1125. begin
  1126. { NASM complains if you put a missing section in the GROUP directive, so }
  1127. { we add empty declarations to make sure they exist, even if empty }
  1128. AsmWriteLn('SECTION .rodata');
  1129. AsmWriteLn('SECTION .data');
  1130. AsmWriteLn('SECTION .fpc');
  1131. { WLINK requires class=bss in order to leave the BSS section out of the executable }
  1132. AsmWriteLn('SECTION .bss class=bss');
  1133. { group these sections in the same segment }
  1134. if current_settings.x86memorymodel=mm_tiny then
  1135. AsmWriteLn('GROUP dgroup text rodata data fpc bss')
  1136. else
  1137. AsmWriteLn('GROUP dgroup rodata data fpc bss');
  1138. end;
  1139. if paratargetdbg in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4] then
  1140. begin
  1141. AsmWriteLn('SECTION .debug_frame use32 class=DWARF');
  1142. AsmWriteLn('SECTION .debug_info use32 class=DWARF');
  1143. AsmWriteLn('SECTION .debug_line use32 class=DWARF');
  1144. AsmWriteLn('SECTION .debug_abbrev use32 class=DWARF');
  1145. end;
  1146. AsmWriteLn('SECTION ' + CodeSectionName);
  1147. {$else i8086}
  1148. {$ifdef i386}
  1149. AsmWriteLn('BITS 32');
  1150. using_relative:=false;
  1151. {$else not i386}
  1152. AsmWriteLn('BITS 64');
  1153. AsmWriteLn('default rel');
  1154. using_relative:=true;
  1155. {$endif not i386}
  1156. {$endif i8086}
  1157. end;
  1158. procedure TX86NasmAssembler.WriteAsmList;
  1159. var
  1160. hal : tasmlisttype;
  1161. begin
  1162. {$ifdef EXTDEBUG}
  1163. if current_module.mainsource<>'' then
  1164. comment(v_info,'Start writing nasm-styled assembler output for '+current_module.mainsource);
  1165. {$endif}
  1166. WriteHeader;
  1167. AsmLn;
  1168. WriteExternals;
  1169. for hal:=low(TasmlistType) to high(TasmlistType) do
  1170. begin
  1171. if not (current_asmdata.asmlists[hal].empty) then
  1172. begin
  1173. AsmWriteLn(target_asm.comment+'Begin asmlist '+AsmListTypeStr[hal]);
  1174. writetree(current_asmdata.asmlists[hal]);
  1175. AsmWriteLn(target_asm.comment+'End asmlist '+AsmListTypeStr[hal]);
  1176. end;
  1177. end;
  1178. AsmLn;
  1179. if SmartAsm then
  1180. begin
  1181. WriteSmartExternals;
  1182. FreeExternChainList;
  1183. end;
  1184. {$ifdef EXTDEBUG}
  1185. if current_module.mainsource<>'' then
  1186. comment(v_info,'Done writing nasm-styled assembler output for '+current_module.mainsource);
  1187. {$endif EXTDEBUG}
  1188. end;
  1189. function TX86NasmAssembler.MakeCmdLine: TCmdStr;
  1190. var
  1191. FormatName : string;
  1192. begin
  1193. result:=Inherited MakeCmdLine;
  1194. {$ifdef i8086}
  1195. case target_info.system of
  1196. system_i8086_msdos:
  1197. FormatName:='obj';
  1198. end;
  1199. {$endif i8086}
  1200. {$ifdef i386}
  1201. case target_info.system of
  1202. system_i386_go32v2:
  1203. FormatName:='coff';
  1204. system_i386_wdosx,
  1205. system_i386_win32:
  1206. FormatName:='win32';
  1207. system_i386_embedded:
  1208. FormatName:='obj';
  1209. system_i386_linux,
  1210. system_i386_beos:
  1211. FormatName:='elf';
  1212. system_i386_darwin:
  1213. FormatName:='macho32';
  1214. else
  1215. FormatName:='elf';
  1216. end;
  1217. {$endif i386}
  1218. {$ifdef x86_64}
  1219. case target_info.system of
  1220. system_x86_64_win64:
  1221. FormatName:='win64';
  1222. system_x86_64_darwin:
  1223. FormatName:='macho64';
  1224. system_x86_64_linux:
  1225. FormatName:='elf64';
  1226. else
  1227. FormatName:='elf64';
  1228. end;
  1229. {$endif x86_64}
  1230. Replace(result,'$FORMAT',FormatName);
  1231. end;
  1232. {*****************************************************************************
  1233. Initialize
  1234. *****************************************************************************}
  1235. {$ifdef i8086}
  1236. const
  1237. as_i8086_nasm_info : tasminfo =
  1238. (
  1239. id : as_i8086_nasm;
  1240. idtxt : 'NASM';
  1241. asmbin : 'nasm';
  1242. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1243. supported_targets : [system_i8086_msdos];
  1244. flags : [af_needar,af_no_debug];
  1245. labelprefix : '..@';
  1246. comment : '; ';
  1247. dollarsign: '$';
  1248. );
  1249. as_i8086_nasmobj_info : tasminfo =
  1250. (
  1251. id : as_i8086_nasmobj;
  1252. idtxt : 'NASMOBJ';
  1253. asmbin : 'nasm';
  1254. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1255. supported_targets : [system_i8086_msdos];
  1256. flags : [af_needar,af_no_debug];
  1257. labelprefix : '..@';
  1258. comment : '; ';
  1259. dollarsign: '$';
  1260. );
  1261. {$endif i8086}
  1262. {$ifdef i386}
  1263. const
  1264. as_i386_nasmcoff_info : tasminfo =
  1265. (
  1266. id : as_i386_nasmcoff;
  1267. idtxt : 'NASMCOFF';
  1268. asmbin : 'nasm';
  1269. asmcmd : '-f coff -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1270. supported_targets : [system_i386_go32v2];
  1271. flags : [af_needar,af_no_debug];
  1272. labelprefix : '..@';
  1273. comment : '; ';
  1274. dollarsign: '$';
  1275. );
  1276. as_i386_nasmwin32_info : tasminfo =
  1277. (
  1278. id : as_i386_nasmwin32;
  1279. idtxt : 'NASMWIN32';
  1280. asmbin : 'nasm';
  1281. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1282. supported_targets : [system_i386_win32];
  1283. flags : [af_needar,af_no_debug];
  1284. labelprefix : '..@';
  1285. comment : '; ';
  1286. dollarsign: '$';
  1287. );
  1288. as_i386_nasmobj_info : tasminfo =
  1289. (
  1290. id : as_i386_nasmobj;
  1291. idtxt : 'NASMOBJ';
  1292. asmbin : 'nasm';
  1293. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1294. supported_targets : [system_i386_embedded, system_i8086_msdos];
  1295. flags : [af_needar,af_no_debug];
  1296. labelprefix : '..@';
  1297. comment : '; ';
  1298. dollarsign: '$';
  1299. );
  1300. as_i386_nasmwdosx_info : tasminfo =
  1301. (
  1302. id : as_i386_nasmwdosx;
  1303. idtxt : 'NASMWDOSX';
  1304. asmbin : 'nasm';
  1305. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1306. supported_targets : [system_i386_wdosx];
  1307. flags : [af_needar,af_no_debug];
  1308. labelprefix : '..@';
  1309. comment : '; ';
  1310. dollarsign: '$';
  1311. );
  1312. as_i386_nasmelf_info : tasminfo =
  1313. (
  1314. id : as_i386_nasmelf;
  1315. idtxt : 'NASMELF';
  1316. asmbin : 'nasm';
  1317. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1318. supported_targets : [system_i386_linux];
  1319. flags : [af_needar,af_no_debug];
  1320. labelprefix : '..@';
  1321. comment : '; ';
  1322. dollarsign: '$';
  1323. );
  1324. as_i386_nasmdarwin_info : tasminfo =
  1325. (
  1326. id : as_i386_nasmdarwin;
  1327. idtxt : 'NASMDARWIN';
  1328. asmbin : 'nasm';
  1329. asmcmd : '-f macho32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1330. supported_targets : [system_i386_darwin];
  1331. flags : [af_needar,af_no_debug];
  1332. labelprefix : '..@';
  1333. comment : '; ';
  1334. );
  1335. as_i386_nasmbeos_info : tasminfo =
  1336. (
  1337. id : as_i386_nasmbeos;
  1338. idtxt : 'NASMELF';
  1339. asmbin : 'nasm';
  1340. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1341. supported_targets : [system_i386_beos];
  1342. flags : [af_needar,af_no_debug];
  1343. labelprefix : '..@';
  1344. comment : '; ';
  1345. dollarsign: '$';
  1346. );
  1347. as_i386_nasmhaiku_info : tasminfo =
  1348. (
  1349. id : as_i386_nasmhaiku;
  1350. idtxt : 'NASMELF';
  1351. asmbin : 'nasm';
  1352. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1353. supported_targets : [system_i386_haiku];
  1354. flags : [af_needar,af_no_debug];
  1355. labelprefix : '..@';
  1356. comment : '; ';
  1357. dollarsign: '$';
  1358. );
  1359. as_i386_nasm_info : tasminfo =
  1360. (
  1361. id : as_i386_nasm;
  1362. idtxt : 'NASM';
  1363. asmbin : 'nasm';
  1364. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1365. supported_targets : [system_any];
  1366. flags : [af_needar,af_no_debug];
  1367. labelprefix : '..@';
  1368. comment : '; ';
  1369. dollarsign: '$';
  1370. );
  1371. {$endif i386}
  1372. {$ifdef x86_64}
  1373. const
  1374. as_x86_64_nasm_info : tasminfo =
  1375. (
  1376. id : as_x86_64_nasm;
  1377. idtxt : 'NASM';
  1378. asmbin : 'nasm';
  1379. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1380. supported_targets : [system_any];
  1381. flags : [af_needar{,af_no_debug}];
  1382. labelprefix : '..@';
  1383. comment : '; ';
  1384. dollarsign: '$';
  1385. );
  1386. as_x86_64_nasmwin64_info : tasminfo =
  1387. (
  1388. id : as_x86_64_nasmwin64;
  1389. idtxt : 'NASMWIN64';
  1390. asmbin : 'nasm';
  1391. asmcmd : '-f win64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1392. supported_targets : [system_x86_64_win64];
  1393. flags : [af_needar,af_no_debug];
  1394. labelprefix : '..@';
  1395. comment : '; ';
  1396. dollarsign: '$';
  1397. );
  1398. as_x86_64_nasmelf_info : tasminfo =
  1399. (
  1400. id : as_x86_64_nasmelf;
  1401. idtxt : 'NASMELF';
  1402. asmbin : 'nasm';
  1403. asmcmd : '-f elf64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1404. supported_targets : [system_x86_64_linux];
  1405. flags : [af_needar,af_no_debug];
  1406. labelprefix : '..@';
  1407. comment : '; ';
  1408. dollarsign: '$';
  1409. );
  1410. as_x86_64_nasmdarwin_info : tasminfo =
  1411. (
  1412. id : as_x86_64_nasmdarwin;
  1413. idtxt : 'NASMDARWIN';
  1414. asmbin : 'nasm';
  1415. asmcmd : '-f macho64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1416. supported_targets : [system_x86_64_darwin];
  1417. flags : [af_needar,af_no_debug];
  1418. labelprefix : '..@';
  1419. comment : '; ';
  1420. dollarsign: '$';
  1421. );
  1422. {$endif x86_64}
  1423. initialization
  1424. {$ifdef i8086}
  1425. RegisterAssembler(as_i8086_nasm_info,TX86NasmAssembler);
  1426. RegisterAssembler(as_i8086_nasmobj_info,TX86NasmAssembler);
  1427. {$endif i8086}
  1428. {$ifdef i386}
  1429. RegisterAssembler(as_i386_nasmcoff_info,TX86NasmAssembler);
  1430. RegisterAssembler(as_i386_nasmwin32_info,TX86NasmAssembler);
  1431. RegisterAssembler(as_i386_nasmwdosx_info,TX86NasmAssembler);
  1432. RegisterAssembler(as_i386_nasmobj_info,TX86NasmAssembler);
  1433. RegisterAssembler(as_i386_nasmbeos_info,TX86NasmAssembler);
  1434. RegisterAssembler(as_i386_nasmhaiku_info,TX86NasmAssembler);
  1435. RegisterAssembler(as_i386_nasmelf_info,TX86NasmAssembler);
  1436. RegisterAssembler(as_i386_nasm_info,TX86NasmAssembler);
  1437. {$endif i386}
  1438. {$ifdef x86_64}
  1439. RegisterAssembler(as_x86_64_nasm_info,TX86NasmAssembler);
  1440. RegisterAssembler(as_x86_64_nasmwin64_info,TX86NasmAssembler);
  1441. RegisterAssembler(as_x86_64_nasmelf_info,TX86NasmAssembler);
  1442. RegisterAssembler(as_x86_64_nasmdarwin_info,TX86NasmAssembler);
  1443. {$endif x86_64}
  1444. end.