agx86nsm.pas 48 KB

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