agx86nsm.pas 47 KB

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