agx86nsm.pas 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  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,
  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
  589. AsmWriteLn(#9'ALIGN '+tostr(tai_align(hp).aligntype));
  590. end;
  591. end;
  592. ait_datablock :
  593. begin
  594. if tai_datablock(hp).is_global or SmartAsm then
  595. begin
  596. AsmWrite(#9'GLOBAL ');
  597. AsmWriteLn(tai_datablock(hp).sym.name);
  598. end;
  599. AsmWrite(PadTabs(tai_datablock(hp).sym.name,':'));
  600. if SmartAsm then
  601. AddSymbol(tai_datablock(hp).sym.name,true);
  602. AsmWriteLn('RESB'#9+tostr(tai_datablock(hp).size));
  603. end;
  604. ait_const:
  605. begin
  606. consttype:=tai_const(hp).consttype;
  607. case consttype of
  608. aitconst_64bit,
  609. aitconst_64bit_unaligned:
  610. begin
  611. if assigned(tai_const(hp).sym) then
  612. internalerror(200404292);
  613. AsmWrite(ait_const2str[aitconst_32bit]);
  614. AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  615. AsmWrite(',');
  616. AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  617. AsmLn;
  618. end;
  619. aitconst_uleb128bit,
  620. aitconst_sleb128bit,
  621. aitconst_128bit:
  622. begin
  623. AsmWriteLn(target_asm.comment+'Unsupported const type '+
  624. ait_const2str[consttype]);
  625. end;
  626. {$ifdef i8086}
  627. aitconst_farptr:
  628. begin
  629. AsmWrite(ait_const2str[aitconst_16bit]);
  630. if assigned(tai_const(hp).sym) then
  631. begin
  632. if SmartAsm then
  633. AddSymbol(tai_const(hp).sym.name,false);
  634. AsmWrite(tai_const(hp).sym.name);
  635. if tai_const(hp).value<>0 then
  636. AsmWrite(tostr_with_plus(tai_const(hp).value));
  637. AsmLn;
  638. AsmWrite(ait_const2str[aitconst_16bit]);
  639. AsmWrite('SEG ');
  640. AsmWrite(tai_const(hp).sym.name);
  641. end
  642. else
  643. AsmWrite(tostr(lo(longint(tai_const(hp).value)))+','+
  644. tostr(hi(longint(tai_const(hp).value))));
  645. AsmLn;
  646. end;
  647. {$endif i8086}
  648. aitconst_32bit,
  649. aitconst_16bit,
  650. aitconst_8bit,
  651. aitconst_rva_symbol,
  652. aitconst_secrel32_symbol,
  653. aitconst_16bit_unaligned,
  654. aitconst_32bit_unaligned:
  655. begin
  656. AsmWrite(ait_const2str[tai_const(hp).consttype]);
  657. l:=0;
  658. repeat
  659. if assigned(tai_const(hp).sym) then
  660. begin
  661. if SmartAsm then
  662. begin
  663. AddSymbol(tai_const(hp).sym.name,false);
  664. if assigned(tai_const(hp).endsym) then
  665. AddSymbol(tai_const(hp).endsym.name,false);
  666. end;
  667. if assigned(tai_const(hp).endsym) then
  668. s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
  669. else
  670. s:=tai_const(hp).sym.name;
  671. if tai_const(hp).value<>0 then
  672. s:=s+tostr_with_plus(tai_const(hp).value);
  673. end
  674. else
  675. s:=tostr(tai_const(hp).value);
  676. AsmWrite(s);
  677. inc(l,length(s));
  678. if (l>line_length) or
  679. (hp.next=nil) or
  680. (tai(hp.next).typ<>ait_const) or
  681. (tai_const(hp.next).consttype<>consttype) then
  682. break;
  683. hp:=tai(hp.next);
  684. AsmWrite(',');
  685. until false;
  686. AsmLn;
  687. end;
  688. else
  689. internalerror(200704252);
  690. end;
  691. end;
  692. ait_realconst:
  693. begin
  694. WriteRealConstAsBytes(tai_realconst(hp),#9#9'DB'#9,do_line);
  695. end;
  696. ait_string :
  697. begin
  698. counter := 0;
  699. lines := tai_string(hp).len div line_length;
  700. { separate lines in different parts }
  701. if tai_string(hp).len > 0 then
  702. Begin
  703. for j := 0 to lines-1 do
  704. begin
  705. AsmWrite(#9#9'DB'#9);
  706. quoted:=false;
  707. for i:=counter to counter+line_length-1 do
  708. begin
  709. { it is an ascii character. }
  710. if (ord(tai_string(hp).str[i])>31) and
  711. (ord(tai_string(hp).str[i])<128) and
  712. (tai_string(hp).str[i]<>'"') then
  713. begin
  714. if not(quoted) then
  715. begin
  716. if i>counter then
  717. AsmWrite(',');
  718. AsmWrite('"');
  719. end;
  720. AsmWrite(tai_string(hp).str[i]);
  721. quoted:=true;
  722. end { if > 31 and < 128 and ord('"') }
  723. else
  724. begin
  725. if quoted then
  726. AsmWrite('"');
  727. if i>counter then
  728. AsmWrite(',');
  729. quoted:=false;
  730. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  731. end;
  732. end; { end for i:=0 to... }
  733. if quoted then AsmWrite('"');
  734. AsmWrite(target_info.newline);
  735. inc(counter,line_length);
  736. end; { end for j:=0 ... }
  737. { do last line of lines }
  738. if counter<tai_string(hp).len then
  739. AsmWrite(#9#9'DB'#9);
  740. quoted:=false;
  741. for i:=counter to tai_string(hp).len-1 do
  742. begin
  743. { it is an ascii character. }
  744. if (ord(tai_string(hp).str[i])>31) and
  745. (ord(tai_string(hp).str[i])<128) and
  746. (tai_string(hp).str[i]<>'"') then
  747. begin
  748. if not(quoted) then
  749. begin
  750. if i>counter then
  751. AsmWrite(',');
  752. AsmWrite('"');
  753. end;
  754. AsmWrite(tai_string(hp).str[i]);
  755. quoted:=true;
  756. end { if > 31 and < 128 and " }
  757. else
  758. begin
  759. if quoted then
  760. AsmWrite('"');
  761. if i>counter then
  762. AsmWrite(',');
  763. quoted:=false;
  764. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  765. end;
  766. end; { end for i:=0 to... }
  767. if quoted then
  768. AsmWrite('"');
  769. end;
  770. AsmLn;
  771. end;
  772. ait_label :
  773. begin
  774. if tai_label(hp).labsym.is_used then
  775. begin
  776. if SmartAsm and (tai_label(hp).labsym.bind=AB_GLOBAL) then
  777. begin
  778. AsmWrite(#9'GLOBAL ');
  779. AsmWriteLn(tai_label(hp).labsym.name);
  780. end;
  781. AsmWriteLn(tai_label(hp).labsym.name+':');
  782. end;
  783. if SmartAsm then
  784. AddSymbol(tai_label(hp).labsym.name,true);
  785. end;
  786. ait_symbol :
  787. begin
  788. if tai_symbol(hp).has_value then
  789. internalerror(2009090803);
  790. if tai_symbol(hp).is_global or SmartAsm then
  791. begin
  792. AsmWrite(#9'GLOBAL ');
  793. AsmWriteLn(tai_symbol(hp).sym.name);
  794. end;
  795. AsmWrite(tai_symbol(hp).sym.name);
  796. if SmartAsm then
  797. AddSymbol(tai_symbol(hp).sym.name,true);
  798. if assigned(hp.next) and not(tai(hp.next).typ in
  799. [ait_const,ait_realconst,ait_string]) then
  800. AsmWriteLn(':')
  801. end;
  802. ait_symbol_end : ;
  803. ait_instruction :
  804. begin
  805. fixed_opcode:=taicpu(hp).FixNonCommutativeOpcodes;
  806. { We need intel order, no At&t }
  807. taicpu(hp).SetOperandOrder(op_intel);
  808. { LOCK must be on same line as opcode }
  809. if (taicpu(hp).ops = 0) and
  810. (fixed_opcode = A_LOCK) then
  811. SkipNewLine:=true
  812. else
  813. SkipNewLine:=false;
  814. s:='';
  815. if ((fixed_opcode=A_FADDP) or
  816. (fixed_opcode=A_FMULP))
  817. and (taicpu(hp).ops=0) then
  818. begin
  819. taicpu(hp).allocate_oper(2);
  820. taicpu(hp).oper[0]^.typ:=top_reg;
  821. taicpu(hp).oper[0]^.reg:=NR_ST1;
  822. taicpu(hp).oper[1]^.typ:=top_reg;
  823. taicpu(hp).oper[1]^.reg:=NR_ST;
  824. end;
  825. { NASM only accepts move for loading of
  826. simple symbol address }
  827. if ((taicpu(hp).opcode=A_LEA) and
  828. (taicpu(hp).ops=2) and
  829. (taicpu(hp).oper[0]^.typ=top_reg) and
  830. (reg2opsize(taicpu(hp).oper[0]^.reg) in [S_NO,S_Q]) and
  831. (taicpu(hp).oper[1]^.typ=top_ref) and
  832. (taicpu(hp).oper[1]^.ref^.refaddr<>addr_no) and
  833. assigned(taicpu(hp).oper[1]^.ref^.symbol) and
  834. (taicpu(hp).oper[1]^.ref^.base=NR_NO)) then
  835. begin
  836. AsmWrite(target_asm.comment);
  837. AsmWriteln('Converting LEA to MOV instruction');
  838. taicpu(hp).opcode:=A_MOV;
  839. end;
  840. if fixed_opcode=A_FWAIT then
  841. AsmWriteln(#9#9'DB'#9'09bh')
  842. else
  843. begin
  844. prefix:='';
  845. {$ifdef i8086}
  846. { nickysn note: I don't know if the 187 requires FWAIT before
  847. every instruction like the 8087, so I'm including it just in case }
  848. if (current_settings.cputype<=cpu_186) and
  849. requires_fwait_on_8087(fixed_opcode) then
  850. prefix:='wait '+prefix;
  851. {$endif i8086}
  852. {$ifndef i8086}
  853. { We need to explicitely set
  854. word prefix to get selectors
  855. to be pushed in 2 bytes PM }
  856. if (taicpu(hp).opsize=S_W) and
  857. ((fixed_opcode=A_PUSH) or
  858. (fixed_opcode=A_POP)) and
  859. (taicpu(hp).oper[0]^.typ=top_reg) and
  860. (is_segment_reg(taicpu(hp).oper[0]^.reg)) then
  861. AsmWriteln(#9#9'DB'#9'066h');
  862. {$endif not i8086}
  863. AsmWrite(#9#9+prefix+std_op2str[fixed_opcode]+cond2str[taicpu(hp).condition]);
  864. if taicpu(hp).ops<>0 then
  865. begin
  866. if is_calljmp(fixed_opcode) then
  867. begin
  868. AsmWrite(#9);
  869. WriteOper_jmp(taicpu(hp).oper[0]^,taicpu(hp));
  870. end
  871. else
  872. begin
  873. for i:=0 to taicpu(hp).ops-1 do
  874. begin
  875. if i=0 then
  876. AsmWrite(#9)
  877. else
  878. AsmWrite(',');
  879. WriteOper(taicpu(hp).oper[i]^,taicpu(hp).opsize,fixed_opcode,taicpu(hp).ops,(i=2));
  880. end;
  881. end;
  882. end;
  883. if not SkipNewLine then
  884. AsmLn;
  885. end;
  886. end;
  887. ait_stab,
  888. ait_force_line,
  889. ait_function_name : ;
  890. ait_cutobject :
  891. begin
  892. if SmartAsm then
  893. begin
  894. { only reset buffer if nothing has changed }
  895. if AsmSize=AsmStartSize then
  896. AsmClear
  897. else
  898. begin
  899. if SmartAsm then
  900. begin
  901. WriteSmartExternals;
  902. FreeExternChainList;
  903. end;
  904. AsmClose;
  905. DoAssemble;
  906. AsmCreate(tai_cutobject(hp).place);
  907. WriteHeader;
  908. end;
  909. { avoid empty files }
  910. LastSecType:=sec_none;
  911. LastSecName:='';
  912. LastAlign:=4;
  913. while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
  914. begin
  915. if tai(hp.next).typ=ait_section then
  916. begin
  917. LastSecType:=tai_section(hp.next).sectype;
  918. LastSecName:=tai_section(hp.next).name^;
  919. LastAlign:=tai_section(hp.next).secalign;
  920. end;
  921. hp:=tai(hp.next);
  922. end;
  923. if LastSecType<>sec_none then
  924. WriteSection(LastSecType,LastSecName,LastAlign);
  925. AsmStartSize:=AsmSize;
  926. end;
  927. end;
  928. ait_marker :
  929. if tai_marker(hp).kind=mark_NoLineInfoStart then
  930. inc(InlineLevel)
  931. else if tai_marker(hp).kind=mark_NoLineInfoEnd then
  932. dec(InlineLevel);
  933. ait_directive :
  934. begin
  935. case tai_directive(hp).directive of
  936. asd_nasm_import :
  937. AsmWrite('import ');
  938. asd_extern :
  939. AsmWrite('EXTERN ');
  940. else
  941. internalerror(200509191);
  942. end;
  943. if tai_directive(hp).name<>'' then
  944. begin
  945. if SmartAsm then
  946. AddSymbol(tai_directive(hp).name,false);
  947. AsmWrite(tai_directive(hp).name);
  948. end;
  949. AsmLn;
  950. end;
  951. ait_seh_directive :
  952. { Ignore for now };
  953. ait_varloc:
  954. begin
  955. if tai_varloc(hp).newlocationhi<>NR_NO then
  956. AsmWriteLn(target_asm.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  957. std_regname(tai_varloc(hp).newlocationhi)+':'+std_regname(tai_varloc(hp).newlocation))
  958. else
  959. AsmWriteLn(target_asm.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  960. std_regname(tai_varloc(hp).newlocation));
  961. end;
  962. else
  963. internalerror(10000);
  964. end;
  965. hp:=tai(hp.next);
  966. end;
  967. end;
  968. procedure TX86NasmAssembler.WriteExternals;
  969. var
  970. sym : TAsmSymbol;
  971. i : longint;
  972. begin
  973. for i:=0 to current_asmdata.AsmSymbolDict.Count-1 do
  974. begin
  975. sym:=TAsmSymbol(current_asmdata.AsmSymbolDict[i]);
  976. if sym.bind=AB_EXTERNAL then
  977. AsmWriteln('EXTERN'#9+sym.name);
  978. end;
  979. end;
  980. procedure TX86NasmAssembler.WriteSmartExternals;
  981. var
  982. EC : PExternChain;
  983. begin
  984. EC:=FEC;
  985. while assigned(EC) do
  986. begin
  987. if not EC^.is_defined then
  988. AsmWriteln('EXTERN'#9+EC^.psym^);
  989. EC:=EC^.next;
  990. end;
  991. end;
  992. procedure TX86NasmAssembler.WriteHeader;
  993. begin
  994. {$if defined(i8086)}
  995. AsmWriteLn('BITS 16');
  996. case current_settings.cputype of
  997. cpu_8086: AsmWriteLn('CPU 8086');
  998. cpu_186: AsmWriteLn('CPU 186');
  999. cpu_286: AsmWriteLn('CPU 286');
  1000. cpu_386: AsmWriteLn('CPU 386');
  1001. cpu_Pentium: AsmWriteLn('CPU PENTIUM');
  1002. cpu_Pentium2: AsmWriteLn('CPU P2');
  1003. cpu_Pentium3: AsmWriteLn('CPU P3');
  1004. cpu_Pentium4: AsmWriteLn('CPU P4');
  1005. cpu_PentiumM: AsmWriteLn('CPU P4');
  1006. else
  1007. internalerror(2013050101);
  1008. end;
  1009. if not (cs_huge_code in current_settings.moduleswitches) then
  1010. AsmWriteLn('SECTION ' + CodeSectionName(current_module.modulename^) + ' use16 class=code');
  1011. { NASM complains if you put a missing section in the GROUP directive, so }
  1012. { we add empty declarations to make sure they exist, even if empty }
  1013. AsmWriteLn('SECTION .rodata class=data');
  1014. AsmWriteLn('SECTION .data class=data');
  1015. AsmWriteLn('SECTION .fpc class=data');
  1016. { WLINK requires class=bss in order to leave the BSS section out of the executable }
  1017. AsmWriteLn('SECTION .bss class=bss');
  1018. if (current_settings.x86memorymodel<>mm_tiny) and
  1019. (current_settings.x86memorymodel in x86_near_data_models) then
  1020. AsmWriteLn('SECTION stack stack class=stack align=16');
  1021. if current_settings.x86memorymodel in x86_near_data_models then
  1022. AsmWriteLn('SECTION heap class=heap align=16');
  1023. { group these sections in the same segment }
  1024. if current_settings.x86memorymodel=mm_tiny then
  1025. AsmWriteLn('GROUP dgroup text rodata data fpc bss heap')
  1026. else if current_settings.x86memorymodel in x86_near_data_models then
  1027. AsmWriteLn('GROUP dgroup rodata data fpc bss stack heap')
  1028. else
  1029. AsmWriteLn('GROUP dgroup rodata data fpc bss');
  1030. if paratargetdbg in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4] then
  1031. begin
  1032. AsmWriteLn('SECTION .debug_frame use32 class=DWARF');
  1033. AsmWriteLn('SECTION .debug_info use32 class=DWARF');
  1034. AsmWriteLn('SECTION .debug_line use32 class=DWARF');
  1035. AsmWriteLn('SECTION .debug_abbrev use32 class=DWARF');
  1036. end;
  1037. if not (cs_huge_code in current_settings.moduleswitches) then
  1038. AsmWriteLn('SECTION ' + CodeSectionName(current_module.modulename^));
  1039. {$elseif defined(i386)}
  1040. AsmWriteLn('BITS 32');
  1041. using_relative:=false;
  1042. {$elseif defined(x86_64)}
  1043. AsmWriteLn('BITS 64');
  1044. AsmWriteLn('default rel');
  1045. using_relative:=true;
  1046. {$endif}
  1047. end;
  1048. procedure TX86NasmAssembler.WriteAsmList;
  1049. var
  1050. hal : tasmlisttype;
  1051. begin
  1052. {$ifdef EXTDEBUG}
  1053. if current_module.mainsource<>'' then
  1054. comment(v_info,'Start writing nasm-styled assembler output for '+current_module.mainsource);
  1055. {$endif}
  1056. WriteHeader;
  1057. AsmLn;
  1058. WriteExternals;
  1059. for hal:=low(TasmlistType) to high(TasmlistType) do
  1060. begin
  1061. if not (current_asmdata.asmlists[hal].empty) then
  1062. begin
  1063. AsmWriteLn(target_asm.comment+'Begin asmlist '+AsmListTypeStr[hal]);
  1064. writetree(current_asmdata.asmlists[hal]);
  1065. AsmWriteLn(target_asm.comment+'End asmlist '+AsmListTypeStr[hal]);
  1066. end;
  1067. end;
  1068. AsmLn;
  1069. if SmartAsm then
  1070. begin
  1071. WriteSmartExternals;
  1072. FreeExternChainList;
  1073. end;
  1074. {$ifdef EXTDEBUG}
  1075. if current_module.mainsource<>'' then
  1076. comment(v_info,'Done writing nasm-styled assembler output for '+current_module.mainsource);
  1077. {$endif EXTDEBUG}
  1078. end;
  1079. function TX86NasmAssembler.MakeCmdLine: TCmdStr;
  1080. var
  1081. FormatName : string;
  1082. begin
  1083. result:=Inherited MakeCmdLine;
  1084. {$ifdef i8086}
  1085. case target_info.system of
  1086. system_i8086_msdos:
  1087. FormatName:='obj';
  1088. else
  1089. internalerror(2014082060);
  1090. end;
  1091. {$endif i8086}
  1092. {$ifdef i386}
  1093. case target_info.system of
  1094. system_i386_go32v2:
  1095. FormatName:='coff';
  1096. system_i386_wdosx,
  1097. system_i386_win32:
  1098. FormatName:='win32';
  1099. system_i386_embedded:
  1100. FormatName:='obj';
  1101. system_i386_linux,
  1102. system_i386_beos:
  1103. FormatName:='elf';
  1104. system_i386_darwin:
  1105. FormatName:='macho32';
  1106. else
  1107. FormatName:='elf';
  1108. end;
  1109. {$endif i386}
  1110. {$ifdef x86_64}
  1111. case target_info.system of
  1112. system_x86_64_win64:
  1113. FormatName:='win64';
  1114. system_x86_64_darwin:
  1115. FormatName:='macho64';
  1116. system_x86_64_linux:
  1117. FormatName:='elf64';
  1118. else
  1119. FormatName:='elf64';
  1120. end;
  1121. {$endif x86_64}
  1122. Replace(result,'$FORMAT',FormatName);
  1123. end;
  1124. {*****************************************************************************
  1125. Initialize
  1126. *****************************************************************************}
  1127. {$ifdef i8086}
  1128. const
  1129. as_i8086_nasm_info : tasminfo =
  1130. (
  1131. id : as_i8086_nasm;
  1132. idtxt : 'NASM';
  1133. asmbin : 'nasm';
  1134. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1135. supported_targets : [system_i8086_msdos];
  1136. flags : [af_needar,af_no_debug];
  1137. labelprefix : '..@';
  1138. comment : '; ';
  1139. dollarsign: '$';
  1140. );
  1141. as_i8086_nasmobj_info : tasminfo =
  1142. (
  1143. id : as_i8086_nasmobj;
  1144. idtxt : 'NASMOBJ';
  1145. asmbin : 'nasm';
  1146. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1147. supported_targets : [system_i8086_msdos];
  1148. flags : [af_needar,af_no_debug];
  1149. labelprefix : '..@';
  1150. comment : '; ';
  1151. dollarsign: '$';
  1152. );
  1153. {$endif i8086}
  1154. {$ifdef i386}
  1155. const
  1156. as_i386_nasmcoff_info : tasminfo =
  1157. (
  1158. id : as_i386_nasmcoff;
  1159. idtxt : 'NASMCOFF';
  1160. asmbin : 'nasm';
  1161. asmcmd : '-f coff -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1162. supported_targets : [system_i386_go32v2];
  1163. flags : [af_needar,af_no_debug];
  1164. labelprefix : '..@';
  1165. comment : '; ';
  1166. dollarsign: '$';
  1167. );
  1168. as_i386_nasmwin32_info : tasminfo =
  1169. (
  1170. id : as_i386_nasmwin32;
  1171. idtxt : 'NASMWIN32';
  1172. asmbin : 'nasm';
  1173. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1174. supported_targets : [system_i386_win32];
  1175. flags : [af_needar,af_no_debug,af_smartlink_sections];
  1176. labelprefix : '..@';
  1177. comment : '; ';
  1178. dollarsign: '$';
  1179. );
  1180. as_i386_nasmobj_info : tasminfo =
  1181. (
  1182. id : as_i386_nasmobj;
  1183. idtxt : 'NASMOBJ';
  1184. asmbin : 'nasm';
  1185. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1186. supported_targets : [system_i386_embedded, system_i8086_msdos];
  1187. flags : [af_needar,af_no_debug];
  1188. labelprefix : '..@';
  1189. comment : '; ';
  1190. dollarsign: '$';
  1191. );
  1192. as_i386_nasmwdosx_info : tasminfo =
  1193. (
  1194. id : as_i386_nasmwdosx;
  1195. idtxt : 'NASMWDOSX';
  1196. asmbin : 'nasm';
  1197. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1198. supported_targets : [system_i386_wdosx];
  1199. flags : [af_needar,af_no_debug];
  1200. labelprefix : '..@';
  1201. comment : '; ';
  1202. dollarsign: '$';
  1203. );
  1204. as_i386_nasmelf_info : tasminfo =
  1205. (
  1206. id : as_i386_nasmelf;
  1207. idtxt : 'NASMELF';
  1208. asmbin : 'nasm';
  1209. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1210. supported_targets : [system_i386_linux];
  1211. flags : [af_needar,af_no_debug];
  1212. labelprefix : '..@';
  1213. comment : '; ';
  1214. dollarsign: '$';
  1215. );
  1216. as_i386_nasmdarwin_info : tasminfo =
  1217. (
  1218. id : as_i386_nasmdarwin;
  1219. idtxt : 'NASMDARWIN';
  1220. asmbin : 'nasm';
  1221. asmcmd : '-f macho32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1222. supported_targets : [system_i386_darwin];
  1223. flags : [af_needar,af_no_debug];
  1224. labelprefix : '..@';
  1225. comment : '; ';
  1226. dollarsign: '$';
  1227. );
  1228. as_i386_nasmbeos_info : tasminfo =
  1229. (
  1230. id : as_i386_nasmbeos;
  1231. idtxt : 'NASMELF';
  1232. asmbin : 'nasm';
  1233. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1234. supported_targets : [system_i386_beos];
  1235. flags : [af_needar,af_no_debug];
  1236. labelprefix : '..@';
  1237. comment : '; ';
  1238. dollarsign: '$';
  1239. );
  1240. as_i386_nasmhaiku_info : tasminfo =
  1241. (
  1242. id : as_i386_nasmhaiku;
  1243. idtxt : 'NASMELF';
  1244. asmbin : 'nasm';
  1245. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1246. supported_targets : [system_i386_haiku];
  1247. flags : [af_needar,af_no_debug];
  1248. labelprefix : '..@';
  1249. comment : '; ';
  1250. dollarsign: '$';
  1251. );
  1252. as_i386_nasm_info : tasminfo =
  1253. (
  1254. id : as_i386_nasm;
  1255. idtxt : 'NASM';
  1256. asmbin : 'nasm';
  1257. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1258. supported_targets : [system_any];
  1259. flags : [af_needar,af_no_debug];
  1260. labelprefix : '..@';
  1261. comment : '; ';
  1262. dollarsign: '$';
  1263. );
  1264. {$endif i386}
  1265. {$ifdef x86_64}
  1266. const
  1267. as_x86_64_nasm_info : tasminfo =
  1268. (
  1269. id : as_x86_64_nasm;
  1270. idtxt : 'NASM';
  1271. asmbin : 'nasm';
  1272. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1273. supported_targets : [system_any];
  1274. flags : [af_needar{,af_no_debug}];
  1275. labelprefix : '..@';
  1276. comment : '; ';
  1277. dollarsign: '$';
  1278. );
  1279. as_x86_64_nasmwin64_info : tasminfo =
  1280. (
  1281. id : as_x86_64_nasmwin64;
  1282. idtxt : 'NASMWIN64';
  1283. asmbin : 'nasm';
  1284. asmcmd : '-f win64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1285. supported_targets : [system_x86_64_win64];
  1286. flags : [af_needar,af_no_debug];
  1287. labelprefix : '..@';
  1288. comment : '; ';
  1289. dollarsign: '$';
  1290. );
  1291. as_x86_64_nasmelf_info : tasminfo =
  1292. (
  1293. id : as_x86_64_nasmelf;
  1294. idtxt : 'NASMELF';
  1295. asmbin : 'nasm';
  1296. asmcmd : '-f elf64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1297. supported_targets : [system_x86_64_linux];
  1298. flags : [af_needar,af_no_debug];
  1299. labelprefix : '..@';
  1300. comment : '; ';
  1301. dollarsign: '$';
  1302. );
  1303. as_x86_64_nasmdarwin_info : tasminfo =
  1304. (
  1305. id : as_x86_64_nasmdarwin;
  1306. idtxt : 'NASMDARWIN';
  1307. asmbin : 'nasm';
  1308. asmcmd : '-f macho64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1309. supported_targets : [system_x86_64_darwin];
  1310. flags : [af_needar,af_no_debug];
  1311. labelprefix : '..@';
  1312. comment : '; ';
  1313. dollarsign: '$';
  1314. );
  1315. {$endif x86_64}
  1316. initialization
  1317. {$ifdef i8086}
  1318. RegisterAssembler(as_i8086_nasm_info,TX86NasmAssembler);
  1319. RegisterAssembler(as_i8086_nasmobj_info,TX86NasmAssembler);
  1320. {$endif i8086}
  1321. {$ifdef i386}
  1322. RegisterAssembler(as_i386_nasmcoff_info,TX86NasmAssembler);
  1323. RegisterAssembler(as_i386_nasmwin32_info,TX86NasmAssembler);
  1324. RegisterAssembler(as_i386_nasmwdosx_info,TX86NasmAssembler);
  1325. RegisterAssembler(as_i386_nasmobj_info,TX86NasmAssembler);
  1326. RegisterAssembler(as_i386_nasmbeos_info,TX86NasmAssembler);
  1327. RegisterAssembler(as_i386_nasmhaiku_info,TX86NasmAssembler);
  1328. RegisterAssembler(as_i386_nasmelf_info,TX86NasmAssembler);
  1329. RegisterAssembler(as_i386_nasm_info,TX86NasmAssembler);
  1330. {$endif i386}
  1331. {$ifdef x86_64}
  1332. RegisterAssembler(as_x86_64_nasm_info,TX86NasmAssembler);
  1333. RegisterAssembler(as_x86_64_nasmwin64_info,TX86NasmAssembler);
  1334. RegisterAssembler(as_x86_64_nasmelf_info,TX86NasmAssembler);
  1335. RegisterAssembler(as_x86_64_nasmdarwin_info,TX86NasmAssembler);
  1336. {$endif x86_64}
  1337. end.