agx86nsm.pas 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  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. writer.AsmWrite('[');
  262. first:=true;
  263. base_done:=false;
  264. if (segment<>NR_NO) then
  265. writer.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. writer.AsmWrite('$ + ');
  272. base_done:=true;
  273. end;
  274. {$endif x86_64}
  275. if assigned(symbol) then
  276. begin
  277. writer.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. writer.AsmWrite('+')
  286. else
  287. first:=false;
  288. writer.AsmWrite(nasm_regname(base))
  289. end;
  290. if (index<>NR_NO) then
  291. begin
  292. if not(first) then
  293. writer.AsmWrite('+')
  294. else
  295. first:=false;
  296. writer.AsmWrite(nasm_regname(index));
  297. if scalefactor<>0 then
  298. writer.AsmWrite('*'+tostr(scalefactor));
  299. end;
  300. if offset<0 then
  301. begin
  302. writer.AsmWrite(tostr(offset));
  303. first:=false;
  304. end
  305. else if (offset>0) then
  306. begin
  307. writer.AsmWrite('+'+tostr(offset));
  308. first:=false;
  309. end;
  310. if first then
  311. writer.AsmWrite('0');
  312. writer.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. writer.AsmWrite(nasm_regname(o.reg));
  320. top_const :
  321. begin
  322. if (ops=1) and (opcode<>A_RET) then
  323. writer.AsmWrite(sizestr(s,dest));
  324. writer.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. writer.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. writer.AsmWrite('DGROUP');
  345. end
  346. else if o.ref^.refaddr=addr_fardataseg then
  347. begin
  348. writer.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. writer.AsmWrite('dword ')
  356. else
  357. writer.AsmWrite('qword ');
  358. {$endif}
  359. {$ifdef i386}
  360. writer.AsmWrite('dword ');
  361. {$endif i386}
  362. {$ifdef i8086}
  363. if o.ref^.refaddr=addr_seg then
  364. writer.AsmWrite('SEG ')
  365. else
  366. writer.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. writer.AsmWrite(o.ref^.symbol.name);
  373. if o.ref^.offset=0 then
  374. exit;
  375. end;
  376. if o.ref^.offset>0 then
  377. writer.AsmWrite('+');
  378. writer.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. writer.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. writer.AsmWrite('far ');
  395. WriteReference(o.ref^);
  396. end
  397. else
  398. begin
  399. if ai.opsize=S_FAR then
  400. writer.AsmWrite('far ');
  401. { else
  402. writer.AsmWrite('near ') just disables short branches, increasing code size.
  403. Omitting it does not cause any bad effects, tested with nasm 2.11. }
  404. writer.AsmWrite(o.ref^.symbol.name);
  405. if SmartAsm then
  406. AddSymbol(o.ref^.symbol.name,false);
  407. if o.ref^.offset>0 then
  408. writer.AsmWrite('+'+tostr(o.ref^.offset))
  409. else
  410. if o.ref^.offset<0 then
  411. writer.AsmWrite(tostr(o.ref^.offset));
  412. end;
  413. top_const :
  414. writer.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. writer.AsmLn;
  489. writer.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. writer.AsmWrite('.data')
  496. else if (atype=sec_user) then
  497. writer.AsmWrite(aname)
  498. else if (atype=sec_threadvar) and
  499. (target_info.system in (systems_windows+systems_wince)) then
  500. writer.AsmWrite('.tls'#9'bss')
  501. else if target_info.system in [system_i8086_msdos,system_i8086_win16] 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. writer.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. writer.AsmWrite(' stack');
  516. if atype in [sec_debug_frame,sec_debug_info,sec_debug_line,sec_debug_abbrev] then
  517. writer.AsmWrite(' use32')
  518. else
  519. writer.AsmWrite(' use16');
  520. writer.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. writer.AsmWrite(CodeSectionName(aname))
  529. else
  530. writer.AsmWrite(secnames[atype]);
  531. if create_smartlink_sections and
  532. (atype<>sec_bss) and
  533. (aname<>'') then
  534. begin
  535. writer.AsmWrite('.');
  536. writer.AsmWrite(aname);
  537. if atype in [sec_init, sec_fini, sec_stub, sec_code] then
  538. writer.AsmWrite(' code align='+tostr(alignment))
  539. else if atype in [sec_rodata, sec_rodata_norel] then
  540. writer.AsmWrite(' rdata align='+tostr(alignment))
  541. else
  542. writer.AsmWrite(' data align='+tostr(alignment))
  543. end;
  544. writer.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. {$ifdef i8086}
  556. var
  557. i: Integer;
  558. {$endif i8086}
  559. begin
  560. {$ifdef i8086}
  561. if target_info.system in [system_i8086_msdos,system_i8086_win16] then
  562. begin
  563. if current_settings.x86memorymodel=mm_huge then
  564. WriteSection(sec_data,'',2);
  565. writer.AsmLn;
  566. writer.AsmWrite('GROUP DGROUP');
  567. for i:=0 to FSectionsInDGROUP.Count-1 do
  568. writer.AsmWrite(' '+FSectionsInDGROUP.NameOfIndex(i));
  569. writer.AsmLn;
  570. end;
  571. {$endif i8086}
  572. end;
  573. procedure TX86NasmAssembler.WriteTree(p:TAsmList);
  574. {$ifdef cpuextended}
  575. type
  576. t80bitarray = array[0..9] of byte;
  577. {$endif cpuextended}
  578. var
  579. s : string;
  580. hp : tai;
  581. counter,
  582. lines,
  583. i,j,l : longint;
  584. InlineLevel : longint;
  585. consttype : taiconst_type;
  586. do_line, SkipNewLine,
  587. quoted : boolean;
  588. fixed_opcode: TAsmOp;
  589. prefix, LastSecName : string;
  590. LastAlign : Byte;
  591. begin
  592. if not assigned(p) then
  593. exit;
  594. InlineLevel:=0;
  595. { lineinfo is only needed for al_procedures (PFV) }
  596. do_line:=(cs_asm_source in current_settings.globalswitches) or
  597. ((cs_lineinfo in current_settings.moduleswitches)
  598. and (p=current_asmdata.asmlists[al_procedures]));
  599. hp:=tai(p.first);
  600. while assigned(hp) do
  601. begin
  602. prefetch(pointer(hp.next)^);
  603. if not(hp.typ in SkipLineInfo) then
  604. begin
  605. current_filepos:=tailineinfo(hp).fileinfo;
  606. { no line info for inlined code }
  607. if do_line and (inlinelevel=0) then
  608. WriteSourceLine(hp as tailineinfo);
  609. end;
  610. case hp.typ of
  611. ait_comment :
  612. Begin
  613. writer.AsmWrite(asminfo^.comment);
  614. writer.AsmWritePChar(tai_comment(hp).str);
  615. writer.AsmLn;
  616. End;
  617. ait_regalloc :
  618. begin
  619. if (cs_asm_regalloc in current_settings.globalswitches) then
  620. writer.AsmWriteLn(#9#9+asminfo^.comment+'Register '+nasm_regname(tai_regalloc(hp).reg)+' '+
  621. regallocstr[tai_regalloc(hp).ratype]);
  622. end;
  623. ait_tempalloc :
  624. begin
  625. if (cs_asm_tempalloc in current_settings.globalswitches) then
  626. WriteTempalloc(tai_tempalloc(hp));
  627. end;
  628. ait_section :
  629. begin
  630. if tai_section(hp).sectype<>sec_none then
  631. WriteSection(tai_section(hp).sectype,tai_section(hp).name^,tai_section(hp).secalign);
  632. LastSecType:=tai_section(hp).sectype;
  633. end;
  634. ait_align :
  635. begin
  636. if (tai_align(hp).aligntype>1) then
  637. begin
  638. if (LastSecType=sec_bss) or (
  639. (LastSecType=sec_threadvar) and
  640. (target_info.system in (systems_windows+systems_wince))
  641. ) then
  642. writer.AsmWriteLn(#9'ALIGNB '+tostr(tai_align(hp).aligntype))
  643. else if tai_align_abstract(hp).use_op then
  644. writer.AsmWriteLn(#9'ALIGN '+tostr(tai_align(hp).aligntype)+',DB '+tostr(tai_align_abstract(hp).fillop))
  645. else if LastSecType in [sec_code,sec_stub,sec_init,sec_fini] then
  646. writer.AsmWriteLn(#9'ALIGN '+tostr(tai_align(hp).aligntype))
  647. else
  648. writer.AsmWriteLn(#9'ALIGN '+tostr(tai_align(hp).aligntype)+',DB 0');
  649. end;
  650. end;
  651. ait_datablock :
  652. begin
  653. if tai_datablock(hp).is_global or SmartAsm then
  654. begin
  655. writer.AsmWrite(#9'GLOBAL ');
  656. writer.AsmWriteLn(tai_datablock(hp).sym.name);
  657. end;
  658. writer.AsmWrite(PadTabs(tai_datablock(hp).sym.name,':'));
  659. if SmartAsm then
  660. AddSymbol(tai_datablock(hp).sym.name,true);
  661. writer.AsmWriteLn('RESB'#9+tostr(tai_datablock(hp).size));
  662. end;
  663. ait_const:
  664. begin
  665. consttype:=tai_const(hp).consttype;
  666. case consttype of
  667. aitconst_64bit,
  668. aitconst_64bit_unaligned:
  669. begin
  670. if assigned(tai_const(hp).sym) then
  671. internalerror(200404292);
  672. writer.AsmWrite(ait_const2str[aitconst_32bit]);
  673. writer.AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  674. writer.AsmWrite(',');
  675. writer.AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  676. writer.AsmLn;
  677. end;
  678. aitconst_uleb128bit,
  679. aitconst_sleb128bit,
  680. aitconst_128bit:
  681. begin
  682. writer.AsmWriteLn(asminfo^.comment+'Unsupported const type '+
  683. ait_const2str[consttype]);
  684. end;
  685. {$ifdef i8086}
  686. aitconst_farptr:
  687. begin
  688. writer.AsmWrite(ait_const2str[aitconst_16bit]);
  689. if assigned(tai_const(hp).sym) then
  690. begin
  691. if SmartAsm then
  692. AddSymbol(tai_const(hp).sym.name,false);
  693. writer.AsmWrite(tai_const(hp).sym.name);
  694. if tai_const(hp).value<>0 then
  695. writer.AsmWrite(tostr_with_plus(tai_const(hp).value));
  696. writer.AsmLn;
  697. writer.AsmWrite(ait_const2str[aitconst_16bit]);
  698. writer.AsmWrite('SEG ');
  699. writer.AsmWrite(tai_const(hp).sym.name);
  700. end
  701. else
  702. writer.AsmWrite(tostr(lo(longint(tai_const(hp).value)))+','+
  703. tostr(hi(longint(tai_const(hp).value))));
  704. writer.AsmLn;
  705. end;
  706. aitconst_seg:
  707. begin
  708. writer.AsmWrite(ait_const2str[aitconst_16bit]);
  709. if assigned(tai_const(hp).sym) then
  710. begin
  711. if SmartAsm then
  712. AddSymbol(tai_const(hp).sym.name,false);
  713. writer.AsmWrite('SEG ');
  714. writer.AsmWrite(tai_const(hp).sym.name);
  715. end
  716. else
  717. internalerror(2015110501);
  718. writer.AsmLn;
  719. end;
  720. {$endif i8086}
  721. aitconst_32bit,
  722. aitconst_16bit,
  723. aitconst_8bit,
  724. aitconst_rva_symbol,
  725. aitconst_secrel32_symbol,
  726. aitconst_16bit_unaligned,
  727. aitconst_32bit_unaligned:
  728. begin
  729. writer.AsmWrite(ait_const2str[tai_const(hp).consttype]);
  730. l:=0;
  731. repeat
  732. if assigned(tai_const(hp).sym) then
  733. begin
  734. if SmartAsm then
  735. begin
  736. AddSymbol(tai_const(hp).sym.name,false);
  737. if assigned(tai_const(hp).endsym) then
  738. AddSymbol(tai_const(hp).endsym.name,false);
  739. end;
  740. if assigned(tai_const(hp).endsym) then
  741. s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
  742. else
  743. s:=tai_const(hp).sym.name;
  744. if tai_const(hp).value<>0 then
  745. s:=s+tostr_with_plus(tai_const(hp).value);
  746. end
  747. else
  748. s:=tostr(tai_const(hp).value);
  749. writer.AsmWrite(s);
  750. inc(l,length(s));
  751. if (l>line_length) or
  752. (hp.next=nil) or
  753. (tai(hp.next).typ<>ait_const) or
  754. (tai_const(hp.next).consttype<>consttype) then
  755. break;
  756. hp:=tai(hp.next);
  757. writer.AsmWrite(',');
  758. until false;
  759. writer.AsmLn;
  760. end;
  761. else
  762. internalerror(200704252);
  763. end;
  764. end;
  765. ait_realconst:
  766. begin
  767. WriteRealConstAsBytes(tai_realconst(hp),#9#9'DB'#9,do_line);
  768. end;
  769. ait_string :
  770. begin
  771. counter := 0;
  772. lines := tai_string(hp).len div line_length;
  773. { separate lines in different parts }
  774. if tai_string(hp).len > 0 then
  775. Begin
  776. for j := 0 to lines-1 do
  777. begin
  778. writer.AsmWrite(#9#9'DB'#9);
  779. quoted:=false;
  780. for i:=counter to counter+line_length-1 do
  781. begin
  782. { it is an ascii character. }
  783. if (ord(tai_string(hp).str[i])>31) and
  784. (ord(tai_string(hp).str[i])<128) and
  785. (tai_string(hp).str[i]<>'"') then
  786. begin
  787. if not(quoted) then
  788. begin
  789. if i>counter then
  790. writer.AsmWrite(',');
  791. writer.AsmWrite('"');
  792. end;
  793. writer.AsmWrite(tai_string(hp).str[i]);
  794. quoted:=true;
  795. end { if > 31 and < 128 and ord('"') }
  796. else
  797. begin
  798. if quoted then
  799. writer.AsmWrite('"');
  800. if i>counter then
  801. writer.AsmWrite(',');
  802. quoted:=false;
  803. writer.AsmWrite(tostr(ord(tai_string(hp).str[i])));
  804. end;
  805. end; { end for i:=0 to... }
  806. if quoted then writer.AsmWrite('"');
  807. writer.AsmWrite(target_info.newline);
  808. inc(counter,line_length);
  809. end; { end for j:=0 ... }
  810. { do last line of lines }
  811. if counter<tai_string(hp).len then
  812. writer.AsmWrite(#9#9'DB'#9);
  813. quoted:=false;
  814. for i:=counter to tai_string(hp).len-1 do
  815. begin
  816. { it is an ascii character. }
  817. if (ord(tai_string(hp).str[i])>31) and
  818. (ord(tai_string(hp).str[i])<128) and
  819. (tai_string(hp).str[i]<>'"') then
  820. begin
  821. if not(quoted) then
  822. begin
  823. if i>counter then
  824. writer.AsmWrite(',');
  825. writer.AsmWrite('"');
  826. end;
  827. writer.AsmWrite(tai_string(hp).str[i]);
  828. quoted:=true;
  829. end { if > 31 and < 128 and " }
  830. else
  831. begin
  832. if quoted then
  833. writer.AsmWrite('"');
  834. if i>counter then
  835. writer.AsmWrite(',');
  836. quoted:=false;
  837. writer.AsmWrite(tostr(ord(tai_string(hp).str[i])));
  838. end;
  839. end; { end for i:=0 to... }
  840. if quoted then
  841. writer.AsmWrite('"');
  842. end;
  843. writer.AsmLn;
  844. end;
  845. ait_label :
  846. begin
  847. if tai_label(hp).labsym.is_used then
  848. begin
  849. if SmartAsm and (tai_label(hp).labsym.bind=AB_GLOBAL) then
  850. begin
  851. writer.AsmWrite(#9'GLOBAL ');
  852. writer.AsmWriteLn(tai_label(hp).labsym.name);
  853. end;
  854. writer.AsmWriteLn(tai_label(hp).labsym.name+':');
  855. end;
  856. if SmartAsm then
  857. AddSymbol(tai_label(hp).labsym.name,true);
  858. end;
  859. ait_symbol :
  860. begin
  861. if tai_symbol(hp).has_value then
  862. internalerror(2009090803);
  863. if tai_symbol(hp).is_global or SmartAsm then
  864. begin
  865. writer.AsmWrite(#9'GLOBAL ');
  866. writer.AsmWriteLn(tai_symbol(hp).sym.name);
  867. end;
  868. writer.AsmWrite(tai_symbol(hp).sym.name);
  869. if SmartAsm then
  870. AddSymbol(tai_symbol(hp).sym.name,true);
  871. if assigned(hp.next) and not(tai(hp.next).typ in
  872. [ait_const,ait_realconst,ait_string]) then
  873. writer.AsmWriteLn(':')
  874. end;
  875. ait_symbol_end : ;
  876. ait_instruction :
  877. begin
  878. fixed_opcode:=taicpu(hp).FixNonCommutativeOpcodes;
  879. { We need intel order, no At&t }
  880. taicpu(hp).SetOperandOrder(op_intel);
  881. { LOCK must be on same line as opcode }
  882. if (taicpu(hp).ops = 0) and
  883. (fixed_opcode = A_LOCK) then
  884. SkipNewLine:=true
  885. else
  886. SkipNewLine:=false;
  887. s:='';
  888. if ((fixed_opcode=A_FADDP) or
  889. (fixed_opcode=A_FMULP))
  890. and (taicpu(hp).ops=0) then
  891. begin
  892. taicpu(hp).allocate_oper(2);
  893. taicpu(hp).oper[0]^.typ:=top_reg;
  894. taicpu(hp).oper[0]^.reg:=NR_ST1;
  895. taicpu(hp).oper[1]^.typ:=top_reg;
  896. taicpu(hp).oper[1]^.reg:=NR_ST;
  897. end;
  898. { NASM only accepts move for loading of
  899. simple symbol address }
  900. if ((taicpu(hp).opcode=A_LEA) and
  901. (taicpu(hp).ops=2) and
  902. (taicpu(hp).oper[0]^.typ=top_reg) and
  903. (reg2opsize(taicpu(hp).oper[0]^.reg) in [S_NO,S_Q]) and
  904. (taicpu(hp).oper[1]^.typ=top_ref) and
  905. (taicpu(hp).oper[1]^.ref^.refaddr<>addr_no) and
  906. assigned(taicpu(hp).oper[1]^.ref^.symbol) and
  907. (taicpu(hp).oper[1]^.ref^.base=NR_NO)) then
  908. begin
  909. writer.AsmWrite(asminfo^.comment);
  910. writer.AsmWriteln('Converting LEA to MOV instruction');
  911. taicpu(hp).opcode:=A_MOV;
  912. end;
  913. if fixed_opcode=A_FWAIT then
  914. writer.AsmWriteln(#9#9'DB'#9'09bh')
  915. else
  916. begin
  917. prefix:='';
  918. {$ifndef i8086}
  919. { We need to explicitely set
  920. word prefix to get selectors
  921. to be pushed in 2 bytes PM }
  922. if (taicpu(hp).opsize=S_W) and
  923. ((fixed_opcode=A_PUSH) or
  924. (fixed_opcode=A_POP)) and
  925. (taicpu(hp).oper[0]^.typ=top_reg) and
  926. (is_segment_reg(taicpu(hp).oper[0]^.reg)) then
  927. writer.AsmWriteln(#9#9'DB'#9'066h');
  928. {$endif not i8086}
  929. writer.AsmWrite(#9#9+prefix+std_op2str[fixed_opcode]+cond2str[taicpu(hp).condition]);
  930. if taicpu(hp).ops<>0 then
  931. begin
  932. if is_calljmp(fixed_opcode) then
  933. begin
  934. writer.AsmWrite(#9);
  935. WriteOper_jmp(taicpu(hp).oper[0]^,taicpu(hp));
  936. end
  937. else
  938. begin
  939. for i:=0 to taicpu(hp).ops-1 do
  940. begin
  941. if i=0 then
  942. writer.AsmWrite(#9)
  943. else
  944. writer.AsmWrite(',');
  945. WriteOper(taicpu(hp).oper[i]^,taicpu(hp).opsize,fixed_opcode,taicpu(hp).ops,(i=2));
  946. end;
  947. end;
  948. end;
  949. if not SkipNewLine then
  950. writer.AsmLn;
  951. end;
  952. end;
  953. ait_stab,
  954. ait_force_line,
  955. ait_function_name : ;
  956. ait_cutobject :
  957. begin
  958. if SmartAsm then
  959. begin
  960. { only reset buffer if nothing has changed }
  961. if not writer.ClearIfEmpty then
  962. begin
  963. if SmartAsm then
  964. begin
  965. WriteSmartExternals;
  966. FreeExternChainList;
  967. end;
  968. WriteGroups;
  969. writer.AsmClose;
  970. DoAssemble;
  971. writer.AsmCreate(tai_cutobject(hp).place);
  972. ResetSectionsList;
  973. WriteHeader;
  974. end;
  975. { avoid empty files }
  976. LastSecType:=sec_none;
  977. LastSecName:='';
  978. LastAlign:=4;
  979. while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
  980. begin
  981. if tai(hp.next).typ=ait_section then
  982. begin
  983. LastSecType:=tai_section(hp.next).sectype;
  984. LastSecName:=tai_section(hp.next).name^;
  985. LastAlign:=tai_section(hp.next).secalign;
  986. end;
  987. hp:=tai(hp.next);
  988. end;
  989. if LastSecType<>sec_none then
  990. WriteSection(LastSecType,LastSecName,LastAlign);
  991. writer.MarkEmpty;
  992. end;
  993. end;
  994. ait_marker :
  995. if tai_marker(hp).kind=mark_NoLineInfoStart then
  996. inc(InlineLevel)
  997. else if tai_marker(hp).kind=mark_NoLineInfoEnd then
  998. dec(InlineLevel);
  999. ait_directive :
  1000. begin
  1001. case tai_directive(hp).directive of
  1002. asd_nasm_import :
  1003. writer.AsmWrite('import ');
  1004. asd_extern :
  1005. writer.AsmWrite('EXTERN ');
  1006. else
  1007. internalerror(200509191);
  1008. end;
  1009. if tai_directive(hp).name<>'' then
  1010. begin
  1011. if SmartAsm then
  1012. AddSymbol(tai_directive(hp).name,false);
  1013. writer.AsmWrite(tai_directive(hp).name);
  1014. end;
  1015. writer.AsmLn;
  1016. end;
  1017. ait_seh_directive :
  1018. { Ignore for now };
  1019. ait_varloc:
  1020. begin
  1021. if tai_varloc(hp).newlocationhi<>NR_NO then
  1022. writer.AsmWriteLn(asminfo^.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1023. std_regname(tai_varloc(hp).newlocationhi)+':'+std_regname(tai_varloc(hp).newlocation))
  1024. else
  1025. writer.AsmWriteLn(asminfo^.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1026. std_regname(tai_varloc(hp).newlocation));
  1027. end;
  1028. else
  1029. internalerror(10000);
  1030. end;
  1031. hp:=tai(hp.next);
  1032. end;
  1033. end;
  1034. procedure TX86NasmAssembler.WriteExternals;
  1035. var
  1036. sym : TAsmSymbol;
  1037. i : longint;
  1038. begin
  1039. for i:=0 to current_asmdata.AsmSymbolDict.Count-1 do
  1040. begin
  1041. sym:=TAsmSymbol(current_asmdata.AsmSymbolDict[i]);
  1042. if sym.bind=AB_EXTERNAL then
  1043. writer.AsmWriteln('EXTERN'#9+sym.name);
  1044. end;
  1045. end;
  1046. procedure TX86NasmAssembler.WriteSmartExternals;
  1047. var
  1048. EC : PExternChain;
  1049. begin
  1050. EC:=FEC;
  1051. while assigned(EC) do
  1052. begin
  1053. if not EC^.is_defined then
  1054. writer.AsmWriteln('EXTERN'#9+EC^.psym^);
  1055. EC:=EC^.next;
  1056. end;
  1057. end;
  1058. procedure TX86NasmAssembler.WriteHeader;
  1059. begin
  1060. {$if defined(i8086)}
  1061. writer.AsmWriteLn('BITS 16');
  1062. case current_settings.cputype of
  1063. cpu_8086: writer.AsmWriteLn('CPU 8086');
  1064. cpu_186: writer.AsmWriteLn('CPU 186');
  1065. cpu_286: writer.AsmWriteLn('CPU 286');
  1066. cpu_386: writer.AsmWriteLn('CPU 386');
  1067. cpu_Pentium: writer.AsmWriteLn('CPU PENTIUM');
  1068. cpu_Pentium2: writer.AsmWriteLn('CPU P2');
  1069. cpu_Pentium3: writer.AsmWriteLn('CPU P3');
  1070. cpu_Pentium4: writer.AsmWriteLn('CPU P4');
  1071. cpu_PentiumM: writer.AsmWriteLn('CPU P4');
  1072. else
  1073. internalerror(2013050101);
  1074. end;
  1075. {$elseif defined(i386)}
  1076. writer.AsmWriteLn('BITS 32');
  1077. using_relative:=false;
  1078. {$elseif defined(x86_64)}
  1079. writer.AsmWriteLn('BITS 64');
  1080. writer.AsmWriteLn('default rel');
  1081. using_relative:=true;
  1082. {$endif}
  1083. end;
  1084. procedure TX86NasmAssembler.WriteAsmList;
  1085. var
  1086. hal : tasmlisttype;
  1087. begin
  1088. {$ifdef EXTDEBUG}
  1089. if current_module.mainsource<>'' then
  1090. comment(v_info,'Start writing nasm-styled assembler output for '+current_module.mainsource);
  1091. {$endif}
  1092. ResetSectionsList;
  1093. WriteHeader;
  1094. writer.AsmLn;
  1095. WriteExternals;
  1096. for hal:=low(TasmlistType) to high(TasmlistType) do
  1097. begin
  1098. if not (current_asmdata.asmlists[hal].empty) then
  1099. begin
  1100. writer.AsmWriteLn(asminfo^.comment+'Begin asmlist '+AsmListTypeStr[hal]);
  1101. writetree(current_asmdata.asmlists[hal]);
  1102. writer.AsmWriteLn(asminfo^.comment+'End asmlist '+AsmListTypeStr[hal]);
  1103. end;
  1104. end;
  1105. writer.AsmLn;
  1106. if SmartAsm then
  1107. begin
  1108. WriteSmartExternals;
  1109. FreeExternChainList;
  1110. end;
  1111. WriteGroups;
  1112. {$ifdef EXTDEBUG}
  1113. if current_module.mainsource<>'' then
  1114. comment(v_info,'Done writing nasm-styled assembler output for '+current_module.mainsource);
  1115. {$endif EXTDEBUG}
  1116. end;
  1117. function TX86NasmAssembler.MakeCmdLine: TCmdStr;
  1118. var
  1119. FormatName : string;
  1120. begin
  1121. result:=Inherited MakeCmdLine;
  1122. {$ifdef i8086}
  1123. case target_info.system of
  1124. system_i8086_msdos,
  1125. system_i8086_win16:
  1126. FormatName:='obj';
  1127. else
  1128. internalerror(2014082060);
  1129. end;
  1130. {$endif i8086}
  1131. {$ifdef i386}
  1132. case target_info.system of
  1133. system_i386_go32v2:
  1134. FormatName:='coff';
  1135. system_i386_wdosx,
  1136. system_i386_win32:
  1137. FormatName:='win32';
  1138. system_i386_embedded:
  1139. FormatName:='obj';
  1140. system_i386_linux,
  1141. system_i386_beos:
  1142. FormatName:='elf';
  1143. system_i386_darwin:
  1144. FormatName:='macho32';
  1145. else
  1146. FormatName:='elf';
  1147. end;
  1148. {$endif i386}
  1149. {$ifdef x86_64}
  1150. case target_info.system of
  1151. system_x86_64_win64:
  1152. FormatName:='win64';
  1153. system_x86_64_darwin:
  1154. FormatName:='macho64';
  1155. system_x86_64_linux:
  1156. FormatName:='elf64';
  1157. else
  1158. FormatName:='elf64';
  1159. end;
  1160. {$endif x86_64}
  1161. Replace(result,'$FORMAT',FormatName);
  1162. end;
  1163. {*****************************************************************************
  1164. Initialize
  1165. *****************************************************************************}
  1166. {$ifdef i8086}
  1167. const
  1168. as_i8086_nasm_info : tasminfo =
  1169. (
  1170. id : as_i8086_nasm;
  1171. idtxt : 'NASM';
  1172. asmbin : 'nasm';
  1173. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1174. supported_targets : [system_i8086_msdos,system_i8086_win16];
  1175. flags : [af_needar,af_no_debug];
  1176. labelprefix : '..@';
  1177. comment : '; ';
  1178. dollarsign: '$';
  1179. );
  1180. as_i8086_nasmobj_info : tasminfo =
  1181. (
  1182. id : as_i8086_nasmobj;
  1183. idtxt : 'NASMOBJ';
  1184. asmbin : 'nasm';
  1185. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1186. supported_targets : [system_i8086_msdos,system_i8086_win16];
  1187. flags : [af_needar,af_no_debug];
  1188. labelprefix : '..@';
  1189. comment : '; ';
  1190. dollarsign: '$';
  1191. );
  1192. {$endif i8086}
  1193. {$ifdef i386}
  1194. const
  1195. as_i386_nasmcoff_info : tasminfo =
  1196. (
  1197. id : as_i386_nasmcoff;
  1198. idtxt : 'NASMCOFF';
  1199. asmbin : 'nasm';
  1200. asmcmd : '-f coff -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1201. supported_targets : [system_i386_go32v2];
  1202. flags : [af_needar,af_no_debug];
  1203. labelprefix : '..@';
  1204. comment : '; ';
  1205. dollarsign: '$';
  1206. );
  1207. as_i386_nasmwin32_info : tasminfo =
  1208. (
  1209. id : as_i386_nasmwin32;
  1210. idtxt : 'NASMWIN32';
  1211. asmbin : 'nasm';
  1212. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1213. supported_targets : [system_i386_win32];
  1214. flags : [af_needar,af_no_debug,af_smartlink_sections];
  1215. labelprefix : '..@';
  1216. comment : '; ';
  1217. dollarsign: '$';
  1218. );
  1219. as_i386_nasmobj_info : tasminfo =
  1220. (
  1221. id : as_i386_nasmobj;
  1222. idtxt : 'NASMOBJ';
  1223. asmbin : 'nasm';
  1224. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1225. supported_targets : [system_i386_embedded, system_i8086_msdos];
  1226. flags : [af_needar,af_no_debug];
  1227. labelprefix : '..@';
  1228. comment : '; ';
  1229. dollarsign: '$';
  1230. );
  1231. as_i386_nasmwdosx_info : tasminfo =
  1232. (
  1233. id : as_i386_nasmwdosx;
  1234. idtxt : 'NASMWDOSX';
  1235. asmbin : 'nasm';
  1236. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1237. supported_targets : [system_i386_wdosx];
  1238. flags : [af_needar,af_no_debug];
  1239. labelprefix : '..@';
  1240. comment : '; ';
  1241. dollarsign: '$';
  1242. );
  1243. as_i386_nasmelf_info : tasminfo =
  1244. (
  1245. id : as_i386_nasmelf;
  1246. idtxt : 'NASMELF';
  1247. asmbin : 'nasm';
  1248. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1249. supported_targets : [system_i386_linux];
  1250. flags : [af_needar,af_no_debug];
  1251. labelprefix : '..@';
  1252. comment : '; ';
  1253. dollarsign: '$';
  1254. );
  1255. {
  1256. as_i386_nasmdarwin_info : tasminfo =
  1257. (
  1258. id : as_i386_nasmdarwin;
  1259. idtxt : 'NASMDARWIN';
  1260. asmbin : 'nasm';
  1261. asmcmd : '-f macho32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1262. supported_targets : [system_i386_darwin];
  1263. flags : [af_needar,af_no_debug];
  1264. labelprefix : '..@';
  1265. comment : '; ';
  1266. dollarsign: '$';
  1267. );
  1268. }
  1269. as_i386_nasmbeos_info : tasminfo =
  1270. (
  1271. id : as_i386_nasmbeos;
  1272. idtxt : 'NASMELF';
  1273. asmbin : 'nasm';
  1274. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1275. supported_targets : [system_i386_beos];
  1276. flags : [af_needar,af_no_debug];
  1277. labelprefix : '..@';
  1278. comment : '; ';
  1279. dollarsign: '$';
  1280. );
  1281. as_i386_nasmhaiku_info : tasminfo =
  1282. (
  1283. id : as_i386_nasmhaiku;
  1284. idtxt : 'NASMELF';
  1285. asmbin : 'nasm';
  1286. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1287. supported_targets : [system_i386_haiku];
  1288. flags : [af_needar,af_no_debug];
  1289. labelprefix : '..@';
  1290. comment : '; ';
  1291. dollarsign: '$';
  1292. );
  1293. as_i386_nasm_info : tasminfo =
  1294. (
  1295. id : as_i386_nasm;
  1296. idtxt : 'NASM';
  1297. asmbin : 'nasm';
  1298. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1299. supported_targets : [system_any];
  1300. flags : [af_needar,af_no_debug];
  1301. labelprefix : '..@';
  1302. comment : '; ';
  1303. dollarsign: '$';
  1304. );
  1305. {$endif i386}
  1306. {$ifdef x86_64}
  1307. const
  1308. as_x86_64_nasm_info : tasminfo =
  1309. (
  1310. id : as_x86_64_nasm;
  1311. idtxt : 'NASM';
  1312. asmbin : 'nasm';
  1313. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1314. supported_targets : [system_any];
  1315. flags : [af_needar{,af_no_debug}];
  1316. labelprefix : '..@';
  1317. comment : '; ';
  1318. dollarsign: '$';
  1319. );
  1320. as_x86_64_nasmwin64_info : tasminfo =
  1321. (
  1322. id : as_x86_64_nasmwin64;
  1323. idtxt : 'NASMWIN64';
  1324. asmbin : 'nasm';
  1325. asmcmd : '-f win64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1326. supported_targets : [system_x86_64_win64];
  1327. flags : [af_needar,af_no_debug];
  1328. labelprefix : '..@';
  1329. comment : '; ';
  1330. dollarsign: '$';
  1331. );
  1332. as_x86_64_nasmelf_info : tasminfo =
  1333. (
  1334. id : as_x86_64_nasmelf;
  1335. idtxt : 'NASMELF';
  1336. asmbin : 'nasm';
  1337. asmcmd : '-f elf64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1338. supported_targets : [system_x86_64_linux];
  1339. flags : [af_needar,af_no_debug];
  1340. labelprefix : '..@';
  1341. comment : '; ';
  1342. dollarsign: '$';
  1343. );
  1344. as_x86_64_nasmdarwin_info : tasminfo =
  1345. (
  1346. id : as_x86_64_nasmdarwin;
  1347. idtxt : 'NASMDARWIN';
  1348. asmbin : 'nasm';
  1349. asmcmd : '-f macho64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1350. supported_targets : [system_x86_64_darwin];
  1351. flags : [af_needar,af_no_debug];
  1352. labelprefix : '..@';
  1353. comment : '; ';
  1354. dollarsign: '$';
  1355. );
  1356. {$endif x86_64}
  1357. initialization
  1358. {$ifdef i8086}
  1359. RegisterAssembler(as_i8086_nasm_info,TX86NasmAssembler);
  1360. RegisterAssembler(as_i8086_nasmobj_info,TX86NasmAssembler);
  1361. {$endif i8086}
  1362. {$ifdef i386}
  1363. RegisterAssembler(as_i386_nasmcoff_info,TX86NasmAssembler);
  1364. RegisterAssembler(as_i386_nasmwin32_info,TX86NasmAssembler);
  1365. RegisterAssembler(as_i386_nasmwdosx_info,TX86NasmAssembler);
  1366. RegisterAssembler(as_i386_nasmobj_info,TX86NasmAssembler);
  1367. RegisterAssembler(as_i386_nasmbeos_info,TX86NasmAssembler);
  1368. RegisterAssembler(as_i386_nasmhaiku_info,TX86NasmAssembler);
  1369. RegisterAssembler(as_i386_nasmelf_info,TX86NasmAssembler);
  1370. RegisterAssembler(as_i386_nasm_info,TX86NasmAssembler);
  1371. {$endif i386}
  1372. {$ifdef x86_64}
  1373. RegisterAssembler(as_x86_64_nasm_info,TX86NasmAssembler);
  1374. RegisterAssembler(as_x86_64_nasmwin64_info,TX86NasmAssembler);
  1375. RegisterAssembler(as_x86_64_nasmelf_info,TX86NasmAssembler);
  1376. RegisterAssembler(as_x86_64_nasmdarwin_info,TX86NasmAssembler);
  1377. {$endif x86_64}
  1378. end.