agx86nsm.pas 48 KB

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