agx86nsm.pas 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  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);
  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. (opcode = A_LES) or (opcode = A_LDS) or
  320. // (opcode = A_SHR) or (opcode = A_SHL) or
  321. // (opcode = A_SAR) or (opcode = A_SAL) or
  322. (opcode = A_OUT) or (opcode = A_IN)) then
  323. AsmWrite(sizestr(s,dest));
  324. WriteReference(o.ref^);
  325. end
  326. {$ifdef i8086}
  327. else if o.ref^.refaddr=addr_dgroup then
  328. begin
  329. AsmWrite('dgroup');
  330. end
  331. {$endif i8086}
  332. else
  333. begin
  334. {$ifdef x86_64}
  335. if s=S_L then
  336. asmwrite('dword ')
  337. else
  338. asmwrite('qword ');
  339. {$endif}
  340. {$ifdef i386}
  341. asmwrite('dword ');
  342. {$endif i386}
  343. {$ifdef i8086}
  344. if o.ref^.refaddr=addr_seg then
  345. asmwrite('SEG ')
  346. else
  347. asmwrite('word ');
  348. {$endif i8086}
  349. if assigned(o.ref^.symbol) then
  350. begin
  351. if SmartAsm then
  352. AddSymbol(o.ref^.symbol.name,false);
  353. asmwrite(o.ref^.symbol.name);
  354. if o.ref^.offset=0 then
  355. exit;
  356. end;
  357. if o.ref^.offset>0 then
  358. asmwrite('+');
  359. asmwrite(tostr(o.ref^.offset));
  360. end;
  361. end;
  362. else
  363. internalerror(10001);
  364. end;
  365. end;
  366. procedure TX86NasmAssembler.WriteOper_jmp(const o:toper; ai : taicpu);
  367. begin
  368. case o.typ of
  369. top_reg :
  370. AsmWrite(nasm_regname(o.reg));
  371. top_ref :
  372. if o.ref^.refaddr=addr_no then
  373. begin
  374. if ai.opsize=S_FAR then
  375. AsmWrite('far ');
  376. WriteReference(o.ref^);
  377. end
  378. else
  379. begin
  380. if ai.opsize=S_FAR then
  381. AsmWrite('far ')
  382. else
  383. begin
  384. { NEAR forces NASM to emit near jumps, which are 386+ }
  385. {$ifndef i8086}
  386. if not(
  387. (ai.opcode=A_JCXZ) or (ai.opcode=A_JECXZ) or
  388. {$ifdef x86_64}
  389. (ai.opcode=A_JRCXZ) or
  390. {$endif x86_64}
  391. (ai.opcode=A_LOOP) or (ai.opcode=A_LOOPE) or
  392. (ai.opcode=A_LOOPNE) or (ai.opcode=A_LOOPNZ) or
  393. (ai.opcode=A_LOOPZ)
  394. ) then
  395. AsmWrite('NEAR ');
  396. {$endif i8086}
  397. end;
  398. AsmWrite(o.ref^.symbol.name);
  399. if SmartAsm then
  400. AddSymbol(o.ref^.symbol.name,false);
  401. if o.ref^.offset>0 then
  402. AsmWrite('+'+tostr(o.ref^.offset))
  403. else
  404. if o.ref^.offset<0 then
  405. AsmWrite(tostr(o.ref^.offset));
  406. end;
  407. top_const :
  408. AsmWrite(tostr(aint(o.val)));
  409. else
  410. internalerror(10001);
  411. end;
  412. end;
  413. const
  414. ait_const2str : array[aitconst_128bit..aitconst_64bit_unaligned] of string[30]=(
  415. #9'FIXME_128BIT'#9,#9'DQ'#9,#9'DD'#9,#9'DW'#9,#9'DB'#9,
  416. #9'FIXME_SLEB128BIT'#9,#9'FIXME_ULEB128BIT'#9,
  417. #9'RVA'#9,#9'SECREL32'#9,#9'FIXME_darwin_dwarf_delta64'#9,
  418. #9'FIXME_darwin_dwarf_delta32'#9,#9'FIXME_half16bit'#9,
  419. #9'DW'#9,#9'DD'#9,#9'FIXME_64BIT_UNALIGNED'#9
  420. );
  421. procedure TX86NasmAssembler.WriteSection(atype:TAsmSectiontype;const aname:string);
  422. const
  423. secnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
  424. '.text',
  425. '.data',
  426. '.data',
  427. '.rodata',
  428. '.bss',
  429. '.tbss',
  430. '.pdata',
  431. '.text','.data','.data','.data','.data',
  432. '.stab',
  433. '.stabstr',
  434. '.idata2','.idata4','.idata5','.idata6','.idata7','.edata',
  435. '.eh_frame',
  436. '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
  437. '.fpc',
  438. '',
  439. '.init',
  440. '.fini',
  441. '.objc_class',
  442. '.objc_meta_class',
  443. '.objc_cat_cls_meth',
  444. '.objc_cat_inst_meth',
  445. '.objc_protocol',
  446. '.objc_string_object',
  447. '.objc_cls_meth',
  448. '.objc_inst_meth',
  449. '.objc_cls_refs',
  450. '.objc_message_refs',
  451. '.objc_symbols',
  452. '.objc_category',
  453. '.objc_class_vars',
  454. '.objc_instance_vars',
  455. '.objc_module_info',
  456. '.objc_class_names',
  457. '.objc_meth_var_types',
  458. '.objc_meth_var_names',
  459. '.objc_selector_strs',
  460. '.objc_protocol_ext',
  461. '.objc_class_ext',
  462. '.objc_property',
  463. '.objc_image_info',
  464. '.objc_cstring_object',
  465. '.objc_sel_fixup',
  466. '__DATA,__objc_data',
  467. '__DATA,__objc_const',
  468. '.objc_superrefs',
  469. '__DATA, __datacoal_nt,coalesced',
  470. '.objc_classlist',
  471. '.objc_nlclasslist',
  472. '.objc_catlist',
  473. '.obcj_nlcatlist',
  474. '.objc_protolist'
  475. );
  476. begin
  477. AsmLn;
  478. AsmWrite('SECTION ');
  479. { go32v2 stub only loads .text and .data sections, and allocates space for .bss.
  480. Thus, data which normally goes into .rodata and .rodata_norel sections must
  481. end up in .data section }
  482. if (atype in [sec_rodata,sec_rodata_norel]) and
  483. (target_info.system=system_i386_go32v2) then
  484. AsmWrite('.data')
  485. else if (atype=sec_user) then
  486. AsmWrite(aname)
  487. else if (atype=sec_threadvar) and
  488. (target_info.system in (systems_windows+systems_wince)) then
  489. AsmWrite('.tls'#9'bss')
  490. else if secnames[atype]='.text' then
  491. AsmWrite(CodeSectionName(aname))
  492. else
  493. AsmWrite(secnames[atype]);
  494. if create_smartlink_sections and
  495. (atype<>sec_bss) and
  496. (aname<>'') then
  497. begin
  498. AsmWrite('.');
  499. AsmWrite(aname);
  500. end;
  501. AsmLn;
  502. LastSecType:=atype;
  503. end;
  504. procedure TX86NasmAssembler.WriteTree(p:TAsmList);
  505. {$ifdef cpuextended}
  506. type
  507. t80bitarray = array[0..9] of byte;
  508. {$endif cpuextended}
  509. var
  510. s : string;
  511. hp : tai;
  512. counter,
  513. lines,
  514. i,j,l : longint;
  515. InlineLevel : longint;
  516. consttype : taiconst_type;
  517. do_line, SkipNewLine,
  518. quoted : boolean;
  519. co : comp;
  520. sin : single;
  521. d : double;
  522. {$ifdef cpuextended}
  523. e : extended;
  524. {$endif cpuextended}
  525. fixed_opcode: TAsmOp;
  526. prefix, LastSecName : string;
  527. begin
  528. if not assigned(p) then
  529. exit;
  530. InlineLevel:=0;
  531. { lineinfo is only needed for al_procedures (PFV) }
  532. do_line:=(cs_asm_source in current_settings.globalswitches) or
  533. ((cs_lineinfo in current_settings.moduleswitches)
  534. and (p=current_asmdata.asmlists[al_procedures]));
  535. hp:=tai(p.first);
  536. while assigned(hp) do
  537. begin
  538. prefetch(pointer(hp.next)^);
  539. if not(hp.typ in SkipLineInfo) then
  540. begin
  541. current_filepos:=tailineinfo(hp).fileinfo;
  542. { no line info for inlined code }
  543. if do_line and (inlinelevel=0) then
  544. WriteSourceLine(hp as tailineinfo);
  545. end;
  546. case hp.typ of
  547. ait_comment :
  548. Begin
  549. AsmWrite(target_asm.comment);
  550. AsmWritePChar(tai_comment(hp).str);
  551. AsmLn;
  552. End;
  553. ait_regalloc :
  554. begin
  555. if (cs_asm_regalloc in current_settings.globalswitches) then
  556. AsmWriteLn(#9#9+target_asm.comment+'Register '+nasm_regname(tai_regalloc(hp).reg)+' '+
  557. regallocstr[tai_regalloc(hp).ratype]);
  558. end;
  559. ait_tempalloc :
  560. begin
  561. if (cs_asm_tempalloc in current_settings.globalswitches) then
  562. WriteTempalloc(tai_tempalloc(hp));
  563. end;
  564. ait_section :
  565. begin
  566. if tai_section(hp).sectype<>sec_none then
  567. WriteSection(tai_section(hp).sectype,tai_section(hp).name^);
  568. LastSecType:=tai_section(hp).sectype;
  569. end;
  570. ait_align :
  571. begin
  572. if (tai_align(hp).aligntype>1) then
  573. begin
  574. if (LastSecType=sec_bss) or (
  575. (LastSecType=sec_threadvar) and
  576. (target_info.system in (systems_windows+systems_wince))
  577. ) then
  578. AsmWriteLn(#9'ALIGNB '+tostr(tai_align(hp).aligntype))
  579. else
  580. AsmWriteLn(#9'ALIGN '+tostr(tai_align(hp).aligntype));
  581. end;
  582. end;
  583. ait_datablock :
  584. begin
  585. if tai_datablock(hp).is_global or SmartAsm then
  586. begin
  587. AsmWrite(#9'GLOBAL ');
  588. AsmWriteLn(tai_datablock(hp).sym.name);
  589. end;
  590. AsmWrite(PadTabs(tai_datablock(hp).sym.name,':'));
  591. if SmartAsm then
  592. AddSymbol(tai_datablock(hp).sym.name,true);
  593. AsmWriteLn('RESB'#9+tostr(tai_datablock(hp).size));
  594. end;
  595. ait_const:
  596. begin
  597. consttype:=tai_const(hp).consttype;
  598. case consttype of
  599. aitconst_64bit,
  600. aitconst_64bit_unaligned:
  601. begin
  602. if assigned(tai_const(hp).sym) then
  603. internalerror(200404292);
  604. AsmWrite(ait_const2str[aitconst_32bit]);
  605. AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  606. AsmWrite(',');
  607. AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  608. AsmLn;
  609. end;
  610. aitconst_uleb128bit,
  611. aitconst_sleb128bit,
  612. aitconst_128bit:
  613. begin
  614. AsmWriteLn(target_asm.comment+'Unsupported const type '+
  615. ait_const2str[consttype]);
  616. end;
  617. {$ifdef i8086}
  618. aitconst_farptr:
  619. begin
  620. AsmWrite(ait_const2str[aitconst_16bit]);
  621. if assigned(tai_const(hp).sym) then
  622. begin
  623. if SmartAsm then
  624. AddSymbol(tai_const(hp).sym.name,false);
  625. AsmWrite(tai_const(hp).sym.name);
  626. if tai_const(hp).value<>0 then
  627. AsmWrite(tostr_with_plus(tai_const(hp).value));
  628. AsmLn;
  629. AsmWrite(ait_const2str[aitconst_16bit]);
  630. AsmWrite('SEG ');
  631. AsmWrite(tai_const(hp).sym.name);
  632. end
  633. else
  634. AsmWrite(tostr(lo(longint(tai_const(hp).value)))+','+
  635. tostr(hi(longint(tai_const(hp).value))));
  636. AsmLn;
  637. end;
  638. {$endif i8086}
  639. aitconst_32bit,
  640. aitconst_16bit,
  641. aitconst_8bit,
  642. aitconst_rva_symbol,
  643. aitconst_secrel32_symbol,
  644. aitconst_16bit_unaligned,
  645. aitconst_32bit_unaligned:
  646. begin
  647. AsmWrite(ait_const2str[tai_const(hp).consttype]);
  648. l:=0;
  649. repeat
  650. if assigned(tai_const(hp).sym) then
  651. begin
  652. if SmartAsm then
  653. begin
  654. AddSymbol(tai_const(hp).sym.name,false);
  655. if assigned(tai_const(hp).endsym) then
  656. AddSymbol(tai_const(hp).endsym.name,false);
  657. end;
  658. if assigned(tai_const(hp).endsym) then
  659. s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
  660. else
  661. s:=tai_const(hp).sym.name;
  662. if tai_const(hp).value<>0 then
  663. s:=s+tostr_with_plus(tai_const(hp).value);
  664. end
  665. else
  666. s:=tostr(tai_const(hp).value);
  667. AsmWrite(s);
  668. inc(l,length(s));
  669. if (l>line_length) or
  670. (hp.next=nil) or
  671. (tai(hp.next).typ<>ait_const) or
  672. (tai_const(hp.next).consttype<>consttype) then
  673. break;
  674. hp:=tai(hp.next);
  675. AsmWrite(',');
  676. until false;
  677. AsmLn;
  678. end;
  679. else
  680. internalerror(200704252);
  681. end;
  682. end;
  683. ait_realconst:
  684. begin
  685. WriteRealConstAsBytes(tai_realconst(hp),#9#9'DB'#9,do_line);
  686. end;
  687. ait_string :
  688. begin
  689. counter := 0;
  690. lines := tai_string(hp).len div line_length;
  691. { separate lines in different parts }
  692. if tai_string(hp).len > 0 then
  693. Begin
  694. for j := 0 to lines-1 do
  695. begin
  696. AsmWrite(#9#9'DB'#9);
  697. quoted:=false;
  698. for i:=counter to counter+line_length-1 do
  699. begin
  700. { it is an ascii character. }
  701. if (ord(tai_string(hp).str[i])>31) and
  702. (ord(tai_string(hp).str[i])<128) and
  703. (tai_string(hp).str[i]<>'"') then
  704. begin
  705. if not(quoted) then
  706. begin
  707. if i>counter then
  708. AsmWrite(',');
  709. AsmWrite('"');
  710. end;
  711. AsmWrite(tai_string(hp).str[i]);
  712. quoted:=true;
  713. end { if > 31 and < 128 and ord('"') }
  714. else
  715. begin
  716. if quoted then
  717. AsmWrite('"');
  718. if i>counter then
  719. AsmWrite(',');
  720. quoted:=false;
  721. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  722. end;
  723. end; { end for i:=0 to... }
  724. if quoted then AsmWrite('"');
  725. AsmWrite(target_info.newline);
  726. inc(counter,line_length);
  727. end; { end for j:=0 ... }
  728. { do last line of lines }
  729. if counter<tai_string(hp).len then
  730. AsmWrite(#9#9'DB'#9);
  731. quoted:=false;
  732. for i:=counter to tai_string(hp).len-1 do
  733. begin
  734. { it is an ascii character. }
  735. if (ord(tai_string(hp).str[i])>31) and
  736. (ord(tai_string(hp).str[i])<128) and
  737. (tai_string(hp).str[i]<>'"') then
  738. begin
  739. if not(quoted) then
  740. begin
  741. if i>counter then
  742. AsmWrite(',');
  743. AsmWrite('"');
  744. end;
  745. AsmWrite(tai_string(hp).str[i]);
  746. quoted:=true;
  747. end { if > 31 and < 128 and " }
  748. else
  749. begin
  750. if quoted then
  751. AsmWrite('"');
  752. if i>counter then
  753. AsmWrite(',');
  754. quoted:=false;
  755. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  756. end;
  757. end; { end for i:=0 to... }
  758. if quoted then
  759. AsmWrite('"');
  760. end;
  761. AsmLn;
  762. end;
  763. ait_label :
  764. begin
  765. if tai_label(hp).labsym.is_used then
  766. begin
  767. if SmartAsm and (tai_label(hp).labsym.bind=AB_GLOBAL) then
  768. begin
  769. AsmWrite(#9'GLOBAL ');
  770. AsmWriteLn(tai_label(hp).labsym.name);
  771. end;
  772. AsmWriteLn(tai_label(hp).labsym.name+':');
  773. end;
  774. if SmartAsm then
  775. AddSymbol(tai_label(hp).labsym.name,true);
  776. end;
  777. ait_symbol :
  778. begin
  779. if tai_symbol(hp).has_value then
  780. internalerror(2009090803);
  781. if tai_symbol(hp).is_global or SmartAsm then
  782. begin
  783. AsmWrite(#9'GLOBAL ');
  784. AsmWriteLn(tai_symbol(hp).sym.name);
  785. end;
  786. AsmWrite(tai_symbol(hp).sym.name);
  787. if SmartAsm then
  788. AddSymbol(tai_symbol(hp).sym.name,true);
  789. if assigned(hp.next) and not(tai(hp.next).typ in
  790. [ait_const,ait_realconst,ait_string]) then
  791. AsmWriteLn(':')
  792. end;
  793. ait_symbol_end : ;
  794. ait_instruction :
  795. begin
  796. fixed_opcode:=taicpu(hp).FixNonCommutativeOpcodes;
  797. { We need intel order, no At&t }
  798. taicpu(hp).SetOperandOrder(op_intel);
  799. { LOCK must be on same line as opcode }
  800. if (taicpu(hp).ops = 0) and
  801. (fixed_opcode = A_LOCK) then
  802. SkipNewLine:=true
  803. else
  804. SkipNewLine:=false;
  805. s:='';
  806. if ((fixed_opcode=A_FADDP) or
  807. (fixed_opcode=A_FMULP))
  808. and (taicpu(hp).ops=0) then
  809. begin
  810. taicpu(hp).allocate_oper(2);
  811. taicpu(hp).oper[0]^.typ:=top_reg;
  812. taicpu(hp).oper[0]^.reg:=NR_ST1;
  813. taicpu(hp).oper[1]^.typ:=top_reg;
  814. taicpu(hp).oper[1]^.reg:=NR_ST;
  815. end;
  816. { NASM only accepts move for loading of
  817. simple symbol address }
  818. if ((taicpu(hp).opcode=A_LEA) and
  819. (taicpu(hp).ops=2) and
  820. (taicpu(hp).oper[0]^.typ=top_reg) and
  821. (reg2opsize(taicpu(hp).oper[0]^.reg) in [S_NO,S_Q]) and
  822. (taicpu(hp).oper[1]^.typ=top_ref) and
  823. (taicpu(hp).oper[1]^.ref^.refaddr<>addr_no) and
  824. assigned(taicpu(hp).oper[1]^.ref^.symbol) and
  825. (taicpu(hp).oper[1]^.ref^.base=NR_NO)) then
  826. begin
  827. AsmWrite(target_asm.comment);
  828. AsmWriteln('Converting LEA to MOV instruction');
  829. taicpu(hp).opcode:=A_MOV;
  830. end;
  831. if fixed_opcode=A_FWAIT then
  832. AsmWriteln(#9#9'DB'#9'09bh')
  833. else
  834. begin
  835. prefix:='';
  836. {$ifdef i8086}
  837. { nickysn note: I don't know if the 187 requires FWAIT before
  838. every instruction like the 8087, so I'm including it just in case }
  839. if (current_settings.cputype<=cpu_186) and
  840. requires_fwait_on_8087(fixed_opcode) then
  841. prefix:='wait '+prefix;
  842. {$endif i8086}
  843. {$ifndef i8086}
  844. { We need to explicitely set
  845. word prefix to get selectors
  846. to be pushed in 2 bytes PM }
  847. if (taicpu(hp).opsize=S_W) and
  848. ((fixed_opcode=A_PUSH) or
  849. (fixed_opcode=A_POP)) and
  850. (taicpu(hp).oper[0]^.typ=top_reg) and
  851. (is_segment_reg(taicpu(hp).oper[0]^.reg)) then
  852. AsmWriteln(#9#9'DB'#9'066h');
  853. {$endif not i8086}
  854. AsmWrite(#9#9+prefix+std_op2str[fixed_opcode]+cond2str[taicpu(hp).condition]);
  855. if taicpu(hp).ops<>0 then
  856. begin
  857. if is_calljmp(fixed_opcode) then
  858. begin
  859. AsmWrite(#9);
  860. WriteOper_jmp(taicpu(hp).oper[0]^,taicpu(hp));
  861. end
  862. else
  863. begin
  864. for i:=0 to taicpu(hp).ops-1 do
  865. begin
  866. if i=0 then
  867. AsmWrite(#9)
  868. else
  869. AsmWrite(',');
  870. WriteOper(taicpu(hp).oper[i]^,taicpu(hp).opsize,fixed_opcode,taicpu(hp).ops,(i=2));
  871. end;
  872. end;
  873. end;
  874. if not SkipNewLine then
  875. AsmLn;
  876. end;
  877. end;
  878. ait_stab,
  879. ait_force_line,
  880. ait_function_name : ;
  881. ait_cutobject :
  882. begin
  883. if SmartAsm then
  884. begin
  885. { only reset buffer if nothing has changed }
  886. if AsmSize=AsmStartSize then
  887. AsmClear
  888. else
  889. begin
  890. if SmartAsm then
  891. begin
  892. WriteSmartExternals;
  893. FreeExternChainList;
  894. end;
  895. AsmClose;
  896. DoAssemble;
  897. AsmCreate(tai_cutobject(hp).place);
  898. WriteHeader;
  899. end;
  900. { avoid empty files }
  901. LastSecType:=sec_none;
  902. LastSecName:='';
  903. while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
  904. begin
  905. if tai(hp.next).typ=ait_section then
  906. begin
  907. LastSecType:=tai_section(hp.next).sectype;
  908. LastSecName:=tai_section(hp.next).name^;
  909. end;
  910. hp:=tai(hp.next);
  911. end;
  912. if LastSecType<>sec_none then
  913. WriteSection(LastSecType,LastSecName);
  914. AsmStartSize:=AsmSize;
  915. end;
  916. end;
  917. ait_marker :
  918. if tai_marker(hp).kind=mark_NoLineInfoStart then
  919. inc(InlineLevel)
  920. else if tai_marker(hp).kind=mark_NoLineInfoEnd then
  921. dec(InlineLevel);
  922. ait_directive :
  923. begin
  924. case tai_directive(hp).directive of
  925. asd_nasm_import :
  926. AsmWrite('import ');
  927. asd_extern :
  928. AsmWrite('EXTERN ');
  929. else
  930. internalerror(200509191);
  931. end;
  932. if tai_directive(hp).name<>'' then
  933. begin
  934. if SmartAsm then
  935. AddSymbol(tai_directive(hp).name,false);
  936. AsmWrite(tai_directive(hp).name);
  937. end;
  938. AsmLn;
  939. end;
  940. ait_seh_directive :
  941. { Ignore for now };
  942. ait_varloc:
  943. begin
  944. if tai_varloc(hp).newlocationhi<>NR_NO then
  945. AsmWriteLn(target_asm.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  946. std_regname(tai_varloc(hp).newlocationhi)+':'+std_regname(tai_varloc(hp).newlocation))
  947. else
  948. AsmWriteLn(target_asm.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  949. std_regname(tai_varloc(hp).newlocation));
  950. end;
  951. else
  952. internalerror(10000);
  953. end;
  954. hp:=tai(hp.next);
  955. end;
  956. end;
  957. procedure TX86NasmAssembler.WriteExternals;
  958. var
  959. sym : TAsmSymbol;
  960. i : longint;
  961. begin
  962. for i:=0 to current_asmdata.AsmSymbolDict.Count-1 do
  963. begin
  964. sym:=TAsmSymbol(current_asmdata.AsmSymbolDict[i]);
  965. if sym.bind=AB_EXTERNAL then
  966. AsmWriteln('EXTERN'#9+sym.name);
  967. end;
  968. end;
  969. procedure TX86NasmAssembler.WriteSmartExternals;
  970. var
  971. EC : PExternChain;
  972. begin
  973. EC:=FEC;
  974. while assigned(EC) do
  975. begin
  976. if not EC^.is_defined then
  977. AsmWriteln('EXTERN'#9+EC^.psym^);
  978. EC:=EC^.next;
  979. end;
  980. end;
  981. procedure TX86NasmAssembler.WriteHeader;
  982. begin
  983. {$ifdef i8086}
  984. AsmWriteLn('BITS 16');
  985. case current_settings.cputype of
  986. cpu_8086: AsmWriteLn('CPU 8086');
  987. cpu_186: AsmWriteLn('CPU 186');
  988. cpu_286: AsmWriteLn('CPU 286');
  989. cpu_386: AsmWriteLn('CPU 386');
  990. cpu_Pentium: AsmWriteLn('CPU PENTIUM');
  991. cpu_Pentium2: AsmWriteLn('CPU P2');
  992. cpu_Pentium3: AsmWriteLn('CPU P3');
  993. cpu_Pentium4: AsmWriteLn('CPU P4');
  994. cpu_PentiumM: AsmWriteLn('CPU P4');
  995. else
  996. internalerror(2013050101);
  997. end;
  998. if not (cs_huge_code in current_settings.moduleswitches) then
  999. AsmWriteLn('SECTION ' + CodeSectionName(current_module.modulename^) + ' use16 class=code');
  1000. { NASM complains if you put a missing section in the GROUP directive, so }
  1001. { we add empty declarations to make sure they exist, even if empty }
  1002. AsmWriteLn('SECTION .rodata');
  1003. AsmWriteLn('SECTION .data');
  1004. AsmWriteLn('SECTION .fpc');
  1005. { WLINK requires class=bss in order to leave the BSS section out of the executable }
  1006. AsmWriteLn('SECTION .bss class=bss');
  1007. { group these sections in the same segment }
  1008. if current_settings.x86memorymodel=mm_tiny then
  1009. AsmWriteLn('GROUP dgroup text rodata data fpc bss')
  1010. else
  1011. AsmWriteLn('GROUP dgroup rodata data fpc bss');
  1012. if paratargetdbg in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4] then
  1013. begin
  1014. AsmWriteLn('SECTION .debug_frame use32 class=DWARF');
  1015. AsmWriteLn('SECTION .debug_info use32 class=DWARF');
  1016. AsmWriteLn('SECTION .debug_line use32 class=DWARF');
  1017. AsmWriteLn('SECTION .debug_abbrev use32 class=DWARF');
  1018. end;
  1019. if not (cs_huge_code in current_settings.moduleswitches) then
  1020. AsmWriteLn('SECTION ' + CodeSectionName(current_module.modulename^));
  1021. {$else i8086}
  1022. {$ifdef i386}
  1023. AsmWriteLn('BITS 32');
  1024. using_relative:=false;
  1025. {$else not i386}
  1026. AsmWriteLn('BITS 64');
  1027. AsmWriteLn('default rel');
  1028. using_relative:=true;
  1029. {$endif not i386}
  1030. {$endif i8086}
  1031. end;
  1032. procedure TX86NasmAssembler.WriteAsmList;
  1033. var
  1034. hal : tasmlisttype;
  1035. begin
  1036. {$ifdef EXTDEBUG}
  1037. if current_module.mainsource<>'' then
  1038. comment(v_info,'Start writing nasm-styled assembler output for '+current_module.mainsource);
  1039. {$endif}
  1040. WriteHeader;
  1041. AsmLn;
  1042. WriteExternals;
  1043. for hal:=low(TasmlistType) to high(TasmlistType) do
  1044. begin
  1045. if not (current_asmdata.asmlists[hal].empty) then
  1046. begin
  1047. AsmWriteLn(target_asm.comment+'Begin asmlist '+AsmListTypeStr[hal]);
  1048. writetree(current_asmdata.asmlists[hal]);
  1049. AsmWriteLn(target_asm.comment+'End asmlist '+AsmListTypeStr[hal]);
  1050. end;
  1051. end;
  1052. AsmLn;
  1053. if SmartAsm then
  1054. begin
  1055. WriteSmartExternals;
  1056. FreeExternChainList;
  1057. end;
  1058. {$ifdef EXTDEBUG}
  1059. if current_module.mainsource<>'' then
  1060. comment(v_info,'Done writing nasm-styled assembler output for '+current_module.mainsource);
  1061. {$endif EXTDEBUG}
  1062. end;
  1063. function TX86NasmAssembler.MakeCmdLine: TCmdStr;
  1064. var
  1065. FormatName : string;
  1066. begin
  1067. result:=Inherited MakeCmdLine;
  1068. {$ifdef i8086}
  1069. case target_info.system of
  1070. system_i8086_msdos:
  1071. FormatName:='obj';
  1072. end;
  1073. {$endif i8086}
  1074. {$ifdef i386}
  1075. case target_info.system of
  1076. system_i386_go32v2:
  1077. FormatName:='coff';
  1078. system_i386_wdosx,
  1079. system_i386_win32:
  1080. FormatName:='win32';
  1081. system_i386_embedded:
  1082. FormatName:='obj';
  1083. system_i386_linux,
  1084. system_i386_beos:
  1085. FormatName:='elf';
  1086. system_i386_darwin:
  1087. FormatName:='macho32';
  1088. else
  1089. FormatName:='elf';
  1090. end;
  1091. {$endif i386}
  1092. {$ifdef x86_64}
  1093. case target_info.system of
  1094. system_x86_64_win64:
  1095. FormatName:='win64';
  1096. system_x86_64_darwin:
  1097. FormatName:='macho64';
  1098. system_x86_64_linux:
  1099. FormatName:='elf64';
  1100. else
  1101. FormatName:='elf64';
  1102. end;
  1103. {$endif x86_64}
  1104. Replace(result,'$FORMAT',FormatName);
  1105. end;
  1106. {*****************************************************************************
  1107. Initialize
  1108. *****************************************************************************}
  1109. {$ifdef i8086}
  1110. const
  1111. as_i8086_nasm_info : tasminfo =
  1112. (
  1113. id : as_i8086_nasm;
  1114. idtxt : 'NASM';
  1115. asmbin : 'nasm';
  1116. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1117. supported_targets : [system_i8086_msdos];
  1118. flags : [af_needar,af_no_debug];
  1119. labelprefix : '..@';
  1120. comment : '; ';
  1121. dollarsign: '$';
  1122. );
  1123. as_i8086_nasmobj_info : tasminfo =
  1124. (
  1125. id : as_i8086_nasmobj;
  1126. idtxt : 'NASMOBJ';
  1127. asmbin : 'nasm';
  1128. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1129. supported_targets : [system_i8086_msdos];
  1130. flags : [af_needar,af_no_debug];
  1131. labelprefix : '..@';
  1132. comment : '; ';
  1133. dollarsign: '$';
  1134. );
  1135. {$endif i8086}
  1136. {$ifdef i386}
  1137. const
  1138. as_i386_nasmcoff_info : tasminfo =
  1139. (
  1140. id : as_i386_nasmcoff;
  1141. idtxt : 'NASMCOFF';
  1142. asmbin : 'nasm';
  1143. asmcmd : '-f coff -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1144. supported_targets : [system_i386_go32v2];
  1145. flags : [af_needar,af_no_debug];
  1146. labelprefix : '..@';
  1147. comment : '; ';
  1148. dollarsign: '$';
  1149. );
  1150. as_i386_nasmwin32_info : tasminfo =
  1151. (
  1152. id : as_i386_nasmwin32;
  1153. idtxt : 'NASMWIN32';
  1154. asmbin : 'nasm';
  1155. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1156. supported_targets : [system_i386_win32];
  1157. flags : [af_needar,af_no_debug];
  1158. labelprefix : '..@';
  1159. comment : '; ';
  1160. dollarsign: '$';
  1161. );
  1162. as_i386_nasmobj_info : tasminfo =
  1163. (
  1164. id : as_i386_nasmobj;
  1165. idtxt : 'NASMOBJ';
  1166. asmbin : 'nasm';
  1167. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1168. supported_targets : [system_i386_embedded, system_i8086_msdos];
  1169. flags : [af_needar,af_no_debug];
  1170. labelprefix : '..@';
  1171. comment : '; ';
  1172. dollarsign: '$';
  1173. );
  1174. as_i386_nasmwdosx_info : tasminfo =
  1175. (
  1176. id : as_i386_nasmwdosx;
  1177. idtxt : 'NASMWDOSX';
  1178. asmbin : 'nasm';
  1179. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1180. supported_targets : [system_i386_wdosx];
  1181. flags : [af_needar,af_no_debug];
  1182. labelprefix : '..@';
  1183. comment : '; ';
  1184. dollarsign: '$';
  1185. );
  1186. as_i386_nasmelf_info : tasminfo =
  1187. (
  1188. id : as_i386_nasmelf;
  1189. idtxt : 'NASMELF';
  1190. asmbin : 'nasm';
  1191. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1192. supported_targets : [system_i386_linux];
  1193. flags : [af_needar,af_no_debug];
  1194. labelprefix : '..@';
  1195. comment : '; ';
  1196. dollarsign: '$';
  1197. );
  1198. as_i386_nasmdarwin_info : tasminfo =
  1199. (
  1200. id : as_i386_nasmdarwin;
  1201. idtxt : 'NASMDARWIN';
  1202. asmbin : 'nasm';
  1203. asmcmd : '-f macho32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1204. supported_targets : [system_i386_darwin];
  1205. flags : [af_needar,af_no_debug];
  1206. labelprefix : '..@';
  1207. comment : '; ';
  1208. dollarsign: '$';
  1209. );
  1210. as_i386_nasmbeos_info : tasminfo =
  1211. (
  1212. id : as_i386_nasmbeos;
  1213. idtxt : 'NASMELF';
  1214. asmbin : 'nasm';
  1215. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1216. supported_targets : [system_i386_beos];
  1217. flags : [af_needar,af_no_debug];
  1218. labelprefix : '..@';
  1219. comment : '; ';
  1220. dollarsign: '$';
  1221. );
  1222. as_i386_nasmhaiku_info : tasminfo =
  1223. (
  1224. id : as_i386_nasmhaiku;
  1225. idtxt : 'NASMELF';
  1226. asmbin : 'nasm';
  1227. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1228. supported_targets : [system_i386_haiku];
  1229. flags : [af_needar,af_no_debug];
  1230. labelprefix : '..@';
  1231. comment : '; ';
  1232. dollarsign: '$';
  1233. );
  1234. as_i386_nasm_info : tasminfo =
  1235. (
  1236. id : as_i386_nasm;
  1237. idtxt : 'NASM';
  1238. asmbin : 'nasm';
  1239. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1240. supported_targets : [system_any];
  1241. flags : [af_needar,af_no_debug];
  1242. labelprefix : '..@';
  1243. comment : '; ';
  1244. dollarsign: '$';
  1245. );
  1246. {$endif i386}
  1247. {$ifdef x86_64}
  1248. const
  1249. as_x86_64_nasm_info : tasminfo =
  1250. (
  1251. id : as_x86_64_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. as_x86_64_nasmwin64_info : tasminfo =
  1262. (
  1263. id : as_x86_64_nasmwin64;
  1264. idtxt : 'NASMWIN64';
  1265. asmbin : 'nasm';
  1266. asmcmd : '-f win64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1267. supported_targets : [system_x86_64_win64];
  1268. flags : [af_needar,af_no_debug];
  1269. labelprefix : '..@';
  1270. comment : '; ';
  1271. dollarsign: '$';
  1272. );
  1273. as_x86_64_nasmelf_info : tasminfo =
  1274. (
  1275. id : as_x86_64_nasmelf;
  1276. idtxt : 'NASMELF';
  1277. asmbin : 'nasm';
  1278. asmcmd : '-f elf64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1279. supported_targets : [system_x86_64_linux];
  1280. flags : [af_needar,af_no_debug];
  1281. labelprefix : '..@';
  1282. comment : '; ';
  1283. dollarsign: '$';
  1284. );
  1285. as_x86_64_nasmdarwin_info : tasminfo =
  1286. (
  1287. id : as_x86_64_nasmdarwin;
  1288. idtxt : 'NASMDARWIN';
  1289. asmbin : 'nasm';
  1290. asmcmd : '-f macho64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1291. supported_targets : [system_x86_64_darwin];
  1292. flags : [af_needar,af_no_debug];
  1293. labelprefix : '..@';
  1294. comment : '; ';
  1295. dollarsign: '$';
  1296. );
  1297. {$endif x86_64}
  1298. initialization
  1299. {$ifdef i8086}
  1300. RegisterAssembler(as_i8086_nasm_info,TX86NasmAssembler);
  1301. RegisterAssembler(as_i8086_nasmobj_info,TX86NasmAssembler);
  1302. {$endif i8086}
  1303. {$ifdef i386}
  1304. RegisterAssembler(as_i386_nasmcoff_info,TX86NasmAssembler);
  1305. RegisterAssembler(as_i386_nasmwin32_info,TX86NasmAssembler);
  1306. RegisterAssembler(as_i386_nasmwdosx_info,TX86NasmAssembler);
  1307. RegisterAssembler(as_i386_nasmobj_info,TX86NasmAssembler);
  1308. RegisterAssembler(as_i386_nasmbeos_info,TX86NasmAssembler);
  1309. RegisterAssembler(as_i386_nasmhaiku_info,TX86NasmAssembler);
  1310. RegisterAssembler(as_i386_nasmelf_info,TX86NasmAssembler);
  1311. RegisterAssembler(as_i386_nasm_info,TX86NasmAssembler);
  1312. {$endif i386}
  1313. {$ifdef x86_64}
  1314. RegisterAssembler(as_x86_64_nasm_info,TX86NasmAssembler);
  1315. RegisterAssembler(as_x86_64_nasmwin64_info,TX86NasmAssembler);
  1316. RegisterAssembler(as_x86_64_nasmelf_info,TX86NasmAssembler);
  1317. RegisterAssembler(as_x86_64_nasmdarwin_info,TX86NasmAssembler);
  1318. {$endif x86_64}
  1319. end.