agx86nsm.pas 47 KB

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