agx86nsm.pas 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  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. aitconst_dgroup:
  721. writer.AsmWriteLn(#9'DW'#9'DGROUP');
  722. aitconst_fardataseg:
  723. writer.AsmWriteLn(#9'DW'#9+current_module.modulename^+'_DATA');
  724. {$endif i8086}
  725. aitconst_32bit,
  726. aitconst_16bit,
  727. aitconst_8bit,
  728. aitconst_rva_symbol,
  729. aitconst_secrel32_symbol,
  730. aitconst_16bit_unaligned,
  731. aitconst_32bit_unaligned:
  732. begin
  733. writer.AsmWrite(ait_const2str[tai_const(hp).consttype]);
  734. l:=0;
  735. repeat
  736. if assigned(tai_const(hp).sym) then
  737. begin
  738. if SmartAsm then
  739. begin
  740. AddSymbol(tai_const(hp).sym.name,false);
  741. if assigned(tai_const(hp).endsym) then
  742. AddSymbol(tai_const(hp).endsym.name,false);
  743. end;
  744. if assigned(tai_const(hp).endsym) then
  745. s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
  746. else
  747. s:=tai_const(hp).sym.name;
  748. if tai_const(hp).value<>0 then
  749. s:=s+tostr_with_plus(tai_const(hp).value);
  750. end
  751. else
  752. s:=tostr(tai_const(hp).value);
  753. writer.AsmWrite(s);
  754. inc(l,length(s));
  755. if (l>line_length) or
  756. (hp.next=nil) or
  757. (tai(hp.next).typ<>ait_const) or
  758. (tai_const(hp.next).consttype<>consttype) then
  759. break;
  760. hp:=tai(hp.next);
  761. writer.AsmWrite(',');
  762. until false;
  763. writer.AsmLn;
  764. end;
  765. else
  766. internalerror(200704252);
  767. end;
  768. end;
  769. ait_realconst:
  770. begin
  771. WriteRealConstAsBytes(tai_realconst(hp),#9#9'DB'#9,do_line);
  772. end;
  773. ait_string :
  774. begin
  775. counter := 0;
  776. lines := tai_string(hp).len div line_length;
  777. { separate lines in different parts }
  778. if tai_string(hp).len > 0 then
  779. Begin
  780. for j := 0 to lines-1 do
  781. begin
  782. writer.AsmWrite(#9#9'DB'#9);
  783. quoted:=false;
  784. for i:=counter to counter+line_length-1 do
  785. begin
  786. { it is an ascii character. }
  787. if (ord(tai_string(hp).str[i])>31) and
  788. (ord(tai_string(hp).str[i])<128) and
  789. (tai_string(hp).str[i]<>'"') then
  790. begin
  791. if not(quoted) then
  792. begin
  793. if i>counter then
  794. writer.AsmWrite(',');
  795. writer.AsmWrite('"');
  796. end;
  797. writer.AsmWrite(tai_string(hp).str[i]);
  798. quoted:=true;
  799. end { if > 31 and < 128 and ord('"') }
  800. else
  801. begin
  802. if quoted then
  803. writer.AsmWrite('"');
  804. if i>counter then
  805. writer.AsmWrite(',');
  806. quoted:=false;
  807. writer.AsmWrite(tostr(ord(tai_string(hp).str[i])));
  808. end;
  809. end; { end for i:=0 to... }
  810. if quoted then writer.AsmWrite('"');
  811. writer.AsmWrite(target_info.newline);
  812. inc(counter,line_length);
  813. end; { end for j:=0 ... }
  814. { do last line of lines }
  815. if counter<tai_string(hp).len then
  816. writer.AsmWrite(#9#9'DB'#9);
  817. quoted:=false;
  818. for i:=counter to tai_string(hp).len-1 do
  819. begin
  820. { it is an ascii character. }
  821. if (ord(tai_string(hp).str[i])>31) and
  822. (ord(tai_string(hp).str[i])<128) and
  823. (tai_string(hp).str[i]<>'"') then
  824. begin
  825. if not(quoted) then
  826. begin
  827. if i>counter then
  828. writer.AsmWrite(',');
  829. writer.AsmWrite('"');
  830. end;
  831. writer.AsmWrite(tai_string(hp).str[i]);
  832. quoted:=true;
  833. end { if > 31 and < 128 and " }
  834. else
  835. begin
  836. if quoted then
  837. writer.AsmWrite('"');
  838. if i>counter then
  839. writer.AsmWrite(',');
  840. quoted:=false;
  841. writer.AsmWrite(tostr(ord(tai_string(hp).str[i])));
  842. end;
  843. end; { end for i:=0 to... }
  844. if quoted then
  845. writer.AsmWrite('"');
  846. end;
  847. writer.AsmLn;
  848. end;
  849. ait_label :
  850. begin
  851. if tai_label(hp).labsym.is_used then
  852. begin
  853. if SmartAsm and (tai_label(hp).labsym.bind=AB_GLOBAL) then
  854. begin
  855. writer.AsmWrite(#9'GLOBAL ');
  856. writer.AsmWriteLn(tai_label(hp).labsym.name);
  857. end;
  858. writer.AsmWriteLn(tai_label(hp).labsym.name+':');
  859. end;
  860. if SmartAsm then
  861. AddSymbol(tai_label(hp).labsym.name,true);
  862. end;
  863. ait_symbol :
  864. begin
  865. if tai_symbol(hp).has_value then
  866. internalerror(2009090803);
  867. if tai_symbol(hp).is_global or SmartAsm then
  868. begin
  869. writer.AsmWrite(#9'GLOBAL ');
  870. writer.AsmWriteLn(tai_symbol(hp).sym.name);
  871. end;
  872. writer.AsmWrite(tai_symbol(hp).sym.name);
  873. if SmartAsm then
  874. AddSymbol(tai_symbol(hp).sym.name,true);
  875. if assigned(hp.next) and not(tai(hp.next).typ in
  876. [ait_const,ait_realconst,ait_string]) then
  877. writer.AsmWriteLn(':')
  878. end;
  879. ait_symbol_end : ;
  880. ait_instruction :
  881. begin
  882. fixed_opcode:=taicpu(hp).FixNonCommutativeOpcodes;
  883. { We need intel order, no At&t }
  884. taicpu(hp).SetOperandOrder(op_intel);
  885. { LOCK must be on same line as opcode }
  886. if (taicpu(hp).ops = 0) and
  887. (fixed_opcode = A_LOCK) then
  888. SkipNewLine:=true
  889. else
  890. SkipNewLine:=false;
  891. s:='';
  892. if ((fixed_opcode=A_FADDP) or
  893. (fixed_opcode=A_FMULP))
  894. and (taicpu(hp).ops=0) then
  895. begin
  896. taicpu(hp).allocate_oper(2);
  897. taicpu(hp).oper[0]^.typ:=top_reg;
  898. taicpu(hp).oper[0]^.reg:=NR_ST1;
  899. taicpu(hp).oper[1]^.typ:=top_reg;
  900. taicpu(hp).oper[1]^.reg:=NR_ST;
  901. end;
  902. { NASM only accepts move for loading of
  903. simple symbol address }
  904. if ((taicpu(hp).opcode=A_LEA) and
  905. (taicpu(hp).ops=2) and
  906. (taicpu(hp).oper[0]^.typ=top_reg) and
  907. (reg2opsize(taicpu(hp).oper[0]^.reg) in [S_NO,S_Q]) and
  908. (taicpu(hp).oper[1]^.typ=top_ref) and
  909. (taicpu(hp).oper[1]^.ref^.refaddr<>addr_no) and
  910. assigned(taicpu(hp).oper[1]^.ref^.symbol) and
  911. (taicpu(hp).oper[1]^.ref^.base=NR_NO)) then
  912. begin
  913. writer.AsmWrite(asminfo^.comment);
  914. writer.AsmWriteln('Converting LEA to MOV instruction');
  915. taicpu(hp).opcode:=A_MOV;
  916. end;
  917. if fixed_opcode=A_FWAIT then
  918. writer.AsmWriteln(#9#9'DB'#9'09bh')
  919. else
  920. begin
  921. prefix:='';
  922. {$ifndef i8086}
  923. { We need to explicitely set
  924. word prefix to get selectors
  925. to be pushed in 2 bytes PM }
  926. if (taicpu(hp).opsize=S_W) and
  927. ((fixed_opcode=A_PUSH) or
  928. (fixed_opcode=A_POP)) and
  929. (taicpu(hp).oper[0]^.typ=top_reg) and
  930. (is_segment_reg(taicpu(hp).oper[0]^.reg)) then
  931. writer.AsmWriteln(#9#9'DB'#9'066h');
  932. {$endif not i8086}
  933. writer.AsmWrite(#9#9+prefix+std_op2str[fixed_opcode]+cond2str[taicpu(hp).condition]);
  934. if taicpu(hp).ops<>0 then
  935. begin
  936. if is_calljmp(fixed_opcode) then
  937. begin
  938. writer.AsmWrite(#9);
  939. WriteOper_jmp(taicpu(hp).oper[0]^,taicpu(hp));
  940. end
  941. else
  942. begin
  943. for i:=0 to taicpu(hp).ops-1 do
  944. begin
  945. if i=0 then
  946. writer.AsmWrite(#9)
  947. else
  948. writer.AsmWrite(',');
  949. WriteOper(taicpu(hp).oper[i]^,taicpu(hp).opsize,fixed_opcode,taicpu(hp).ops,(i=2));
  950. end;
  951. end;
  952. end;
  953. if not SkipNewLine then
  954. writer.AsmLn;
  955. end;
  956. end;
  957. ait_stab,
  958. ait_force_line,
  959. ait_function_name : ;
  960. ait_cutobject :
  961. begin
  962. if SmartAsm then
  963. begin
  964. { only reset buffer if nothing has changed }
  965. if not writer.ClearIfEmpty then
  966. begin
  967. if SmartAsm then
  968. begin
  969. WriteSmartExternals;
  970. FreeExternChainList;
  971. end;
  972. WriteGroups;
  973. writer.AsmClose;
  974. DoAssemble;
  975. writer.AsmCreate(tai_cutobject(hp).place);
  976. ResetSectionsList;
  977. WriteHeader;
  978. end;
  979. { avoid empty files }
  980. LastSecType:=sec_none;
  981. LastSecName:='';
  982. LastAlign:=4;
  983. while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
  984. begin
  985. if tai(hp.next).typ=ait_section then
  986. begin
  987. LastSecType:=tai_section(hp.next).sectype;
  988. LastSecName:=tai_section(hp.next).name^;
  989. LastAlign:=tai_section(hp.next).secalign;
  990. end;
  991. hp:=tai(hp.next);
  992. end;
  993. if LastSecType<>sec_none then
  994. WriteSection(LastSecType,LastSecName,LastAlign);
  995. writer.MarkEmpty;
  996. end;
  997. end;
  998. ait_marker :
  999. if tai_marker(hp).kind=mark_NoLineInfoStart then
  1000. inc(InlineLevel)
  1001. else if tai_marker(hp).kind=mark_NoLineInfoEnd then
  1002. dec(InlineLevel);
  1003. ait_directive :
  1004. begin
  1005. case tai_directive(hp).directive of
  1006. asd_nasm_import :
  1007. writer.AsmWrite('import ');
  1008. asd_extern :
  1009. writer.AsmWrite('EXTERN ');
  1010. else
  1011. internalerror(200509191);
  1012. end;
  1013. if tai_directive(hp).name<>'' then
  1014. begin
  1015. if SmartAsm then
  1016. AddSymbol(tai_directive(hp).name,false);
  1017. writer.AsmWrite(tai_directive(hp).name);
  1018. end;
  1019. writer.AsmLn;
  1020. end;
  1021. ait_seh_directive :
  1022. { Ignore for now };
  1023. ait_varloc:
  1024. begin
  1025. if tai_varloc(hp).newlocationhi<>NR_NO then
  1026. writer.AsmWriteLn(asminfo^.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1027. std_regname(tai_varloc(hp).newlocationhi)+':'+std_regname(tai_varloc(hp).newlocation))
  1028. else
  1029. writer.AsmWriteLn(asminfo^.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1030. std_regname(tai_varloc(hp).newlocation));
  1031. end;
  1032. else
  1033. internalerror(10000);
  1034. end;
  1035. hp:=tai(hp.next);
  1036. end;
  1037. end;
  1038. procedure TX86NasmAssembler.WriteExternals;
  1039. var
  1040. sym : TAsmSymbol;
  1041. i : longint;
  1042. begin
  1043. for i:=0 to current_asmdata.AsmSymbolDict.Count-1 do
  1044. begin
  1045. sym:=TAsmSymbol(current_asmdata.AsmSymbolDict[i]);
  1046. if sym.bind=AB_EXTERNAL then
  1047. writer.AsmWriteln('EXTERN'#9+sym.name);
  1048. end;
  1049. end;
  1050. procedure TX86NasmAssembler.WriteSmartExternals;
  1051. var
  1052. EC : PExternChain;
  1053. begin
  1054. EC:=FEC;
  1055. while assigned(EC) do
  1056. begin
  1057. if not EC^.is_defined then
  1058. writer.AsmWriteln('EXTERN'#9+EC^.psym^);
  1059. EC:=EC^.next;
  1060. end;
  1061. end;
  1062. procedure TX86NasmAssembler.WriteHeader;
  1063. begin
  1064. {$if defined(i8086)}
  1065. writer.AsmWriteLn('BITS 16');
  1066. case current_settings.cputype of
  1067. cpu_8086: writer.AsmWriteLn('CPU 8086');
  1068. cpu_186: writer.AsmWriteLn('CPU 186');
  1069. cpu_286: writer.AsmWriteLn('CPU 286');
  1070. cpu_386: writer.AsmWriteLn('CPU 386');
  1071. cpu_Pentium: writer.AsmWriteLn('CPU PENTIUM');
  1072. cpu_Pentium2: writer.AsmWriteLn('CPU P2');
  1073. cpu_Pentium3: writer.AsmWriteLn('CPU P3');
  1074. cpu_Pentium4: writer.AsmWriteLn('CPU P4');
  1075. cpu_PentiumM: writer.AsmWriteLn('CPU P4');
  1076. else
  1077. internalerror(2013050101);
  1078. end;
  1079. {$elseif defined(i386)}
  1080. writer.AsmWriteLn('BITS 32');
  1081. using_relative:=false;
  1082. {$elseif defined(x86_64)}
  1083. writer.AsmWriteLn('BITS 64');
  1084. writer.AsmWriteLn('default rel');
  1085. using_relative:=true;
  1086. {$endif}
  1087. end;
  1088. procedure TX86NasmAssembler.WriteAsmList;
  1089. var
  1090. hal : tasmlisttype;
  1091. begin
  1092. {$ifdef EXTDEBUG}
  1093. if current_module.mainsource<>'' then
  1094. comment(v_info,'Start writing nasm-styled assembler output for '+current_module.mainsource);
  1095. {$endif}
  1096. ResetSectionsList;
  1097. WriteHeader;
  1098. writer.AsmLn;
  1099. WriteExternals;
  1100. for hal:=low(TasmlistType) to high(TasmlistType) do
  1101. begin
  1102. if not (current_asmdata.asmlists[hal].empty) then
  1103. begin
  1104. writer.AsmWriteLn(asminfo^.comment+'Begin asmlist '+AsmListTypeStr[hal]);
  1105. writetree(current_asmdata.asmlists[hal]);
  1106. writer.AsmWriteLn(asminfo^.comment+'End asmlist '+AsmListTypeStr[hal]);
  1107. end;
  1108. end;
  1109. writer.AsmLn;
  1110. if SmartAsm then
  1111. begin
  1112. WriteSmartExternals;
  1113. FreeExternChainList;
  1114. end;
  1115. WriteGroups;
  1116. {$ifdef EXTDEBUG}
  1117. if current_module.mainsource<>'' then
  1118. comment(v_info,'Done writing nasm-styled assembler output for '+current_module.mainsource);
  1119. {$endif EXTDEBUG}
  1120. end;
  1121. function TX86NasmAssembler.MakeCmdLine: TCmdStr;
  1122. var
  1123. FormatName : string;
  1124. begin
  1125. result:=Inherited MakeCmdLine;
  1126. {$ifdef i8086}
  1127. case target_info.system of
  1128. system_i8086_msdos,
  1129. system_i8086_win16:
  1130. FormatName:='obj';
  1131. else
  1132. internalerror(2014082060);
  1133. end;
  1134. {$endif i8086}
  1135. {$ifdef i386}
  1136. case target_info.system of
  1137. system_i386_go32v2:
  1138. FormatName:='coff';
  1139. system_i386_wdosx,
  1140. system_i386_win32:
  1141. FormatName:='win32';
  1142. system_i386_embedded:
  1143. FormatName:='obj';
  1144. system_i386_linux,
  1145. system_i386_beos:
  1146. FormatName:='elf';
  1147. system_i386_darwin:
  1148. FormatName:='macho32';
  1149. else
  1150. FormatName:='elf';
  1151. end;
  1152. {$endif i386}
  1153. {$ifdef x86_64}
  1154. case target_info.system of
  1155. system_x86_64_win64:
  1156. FormatName:='win64';
  1157. system_x86_64_darwin:
  1158. FormatName:='macho64';
  1159. system_x86_64_embedded:
  1160. FormatName:='obj';
  1161. system_x86_64_linux:
  1162. FormatName:='elf64';
  1163. else
  1164. FormatName:='elf64';
  1165. end;
  1166. {$endif x86_64}
  1167. Replace(result,'$FORMAT',FormatName);
  1168. end;
  1169. {*****************************************************************************
  1170. Initialize
  1171. *****************************************************************************}
  1172. {$ifdef i8086}
  1173. const
  1174. as_i8086_nasm_info : tasminfo =
  1175. (
  1176. id : as_i8086_nasm;
  1177. idtxt : 'NASM';
  1178. asmbin : 'nasm';
  1179. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1180. supported_targets : [system_i8086_msdos,system_i8086_win16];
  1181. flags : [af_needar,af_no_debug];
  1182. labelprefix : '..@';
  1183. comment : '; ';
  1184. dollarsign: '$';
  1185. );
  1186. as_i8086_nasmobj_info : tasminfo =
  1187. (
  1188. id : as_i8086_nasmobj;
  1189. idtxt : 'NASMOBJ';
  1190. asmbin : 'nasm';
  1191. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1192. supported_targets : [system_i8086_msdos,system_i8086_win16];
  1193. flags : [af_needar,af_no_debug];
  1194. labelprefix : '..@';
  1195. comment : '; ';
  1196. dollarsign: '$';
  1197. );
  1198. {$endif i8086}
  1199. {$ifdef i386}
  1200. const
  1201. as_i386_nasmcoff_info : tasminfo =
  1202. (
  1203. id : as_i386_nasmcoff;
  1204. idtxt : 'NASMCOFF';
  1205. asmbin : 'nasm';
  1206. asmcmd : '-f coff -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1207. supported_targets : [system_i386_go32v2];
  1208. flags : [af_needar,af_no_debug];
  1209. labelprefix : '..@';
  1210. comment : '; ';
  1211. dollarsign: '$';
  1212. );
  1213. as_i386_nasmwin32_info : tasminfo =
  1214. (
  1215. id : as_i386_nasmwin32;
  1216. idtxt : 'NASMWIN32';
  1217. asmbin : 'nasm';
  1218. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1219. supported_targets : [system_i386_win32];
  1220. flags : [af_needar,af_no_debug,af_smartlink_sections];
  1221. labelprefix : '..@';
  1222. comment : '; ';
  1223. dollarsign: '$';
  1224. );
  1225. as_i386_nasmobj_info : tasminfo =
  1226. (
  1227. id : as_i386_nasmobj;
  1228. idtxt : 'NASMOBJ';
  1229. asmbin : 'nasm';
  1230. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1231. supported_targets : [system_i386_embedded, system_i8086_msdos];
  1232. flags : [af_needar,af_no_debug];
  1233. labelprefix : '..@';
  1234. comment : '; ';
  1235. dollarsign: '$';
  1236. );
  1237. as_i386_nasmwdosx_info : tasminfo =
  1238. (
  1239. id : as_i386_nasmwdosx;
  1240. idtxt : 'NASMWDOSX';
  1241. asmbin : 'nasm';
  1242. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1243. supported_targets : [system_i386_wdosx];
  1244. flags : [af_needar,af_no_debug];
  1245. labelprefix : '..@';
  1246. comment : '; ';
  1247. dollarsign: '$';
  1248. );
  1249. as_i386_nasmelf_info : tasminfo =
  1250. (
  1251. id : as_i386_nasmelf;
  1252. idtxt : 'NASMELF';
  1253. asmbin : 'nasm';
  1254. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1255. supported_targets : [system_i386_linux];
  1256. flags : [af_needar,af_no_debug];
  1257. labelprefix : '..@';
  1258. comment : '; ';
  1259. dollarsign: '$';
  1260. );
  1261. {
  1262. as_i386_nasmdarwin_info : tasminfo =
  1263. (
  1264. id : as_i386_nasmdarwin;
  1265. idtxt : 'NASMDARWIN';
  1266. asmbin : 'nasm';
  1267. asmcmd : '-f macho32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1268. supported_targets : [system_i386_darwin];
  1269. flags : [af_needar,af_no_debug];
  1270. labelprefix : '..@';
  1271. comment : '; ';
  1272. dollarsign: '$';
  1273. );
  1274. }
  1275. as_i386_nasmbeos_info : tasminfo =
  1276. (
  1277. id : as_i386_nasmbeos;
  1278. idtxt : 'NASMELF';
  1279. asmbin : 'nasm';
  1280. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1281. supported_targets : [system_i386_beos];
  1282. flags : [af_needar,af_no_debug];
  1283. labelprefix : '..@';
  1284. comment : '; ';
  1285. dollarsign: '$';
  1286. );
  1287. as_i386_nasmhaiku_info : tasminfo =
  1288. (
  1289. id : as_i386_nasmhaiku;
  1290. idtxt : 'NASMELF';
  1291. asmbin : 'nasm';
  1292. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1293. supported_targets : [system_i386_haiku];
  1294. flags : [af_needar,af_no_debug];
  1295. labelprefix : '..@';
  1296. comment : '; ';
  1297. dollarsign: '$';
  1298. );
  1299. as_i386_nasm_info : tasminfo =
  1300. (
  1301. id : as_i386_nasm;
  1302. idtxt : 'NASM';
  1303. asmbin : 'nasm';
  1304. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1305. supported_targets : [system_any];
  1306. flags : [af_needar,af_no_debug];
  1307. labelprefix : '..@';
  1308. comment : '; ';
  1309. dollarsign: '$';
  1310. );
  1311. {$endif i386}
  1312. {$ifdef x86_64}
  1313. const
  1314. as_x86_64_nasm_info : tasminfo =
  1315. (
  1316. id : as_x86_64_nasm;
  1317. idtxt : 'NASM';
  1318. asmbin : 'nasm';
  1319. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1320. supported_targets : [system_any];
  1321. flags : [af_needar{,af_no_debug}];
  1322. labelprefix : '..@';
  1323. comment : '; ';
  1324. dollarsign: '$';
  1325. );
  1326. as_x86_64_nasmwin64_info : tasminfo =
  1327. (
  1328. id : as_x86_64_nasmwin64;
  1329. idtxt : 'NASMWIN64';
  1330. asmbin : 'nasm';
  1331. asmcmd : '-f win64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1332. supported_targets : [system_x86_64_win64];
  1333. flags : [af_needar,af_no_debug];
  1334. labelprefix : '..@';
  1335. comment : '; ';
  1336. dollarsign: '$';
  1337. );
  1338. as_x86_64_nasmelf_info : tasminfo =
  1339. (
  1340. id : as_x86_64_nasmelf;
  1341. idtxt : 'NASMELF';
  1342. asmbin : 'nasm';
  1343. asmcmd : '-f elf64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1344. supported_targets : [system_x86_64_linux];
  1345. flags : [af_needar,af_no_debug];
  1346. labelprefix : '..@';
  1347. comment : '; ';
  1348. dollarsign: '$';
  1349. );
  1350. as_x86_64_nasmdarwin_info : tasminfo =
  1351. (
  1352. id : as_x86_64_nasmdarwin;
  1353. idtxt : 'NASMDARWIN';
  1354. asmbin : 'nasm';
  1355. asmcmd : '-f macho64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1356. supported_targets : [system_x86_64_darwin];
  1357. flags : [af_needar,af_no_debug];
  1358. labelprefix : '..@';
  1359. comment : '; ';
  1360. dollarsign: '$';
  1361. );
  1362. {$endif x86_64}
  1363. initialization
  1364. {$ifdef i8086}
  1365. RegisterAssembler(as_i8086_nasm_info,TX86NasmAssembler);
  1366. RegisterAssembler(as_i8086_nasmobj_info,TX86NasmAssembler);
  1367. {$endif i8086}
  1368. {$ifdef i386}
  1369. RegisterAssembler(as_i386_nasmcoff_info,TX86NasmAssembler);
  1370. RegisterAssembler(as_i386_nasmwin32_info,TX86NasmAssembler);
  1371. RegisterAssembler(as_i386_nasmwdosx_info,TX86NasmAssembler);
  1372. RegisterAssembler(as_i386_nasmobj_info,TX86NasmAssembler);
  1373. RegisterAssembler(as_i386_nasmbeos_info,TX86NasmAssembler);
  1374. RegisterAssembler(as_i386_nasmhaiku_info,TX86NasmAssembler);
  1375. RegisterAssembler(as_i386_nasmelf_info,TX86NasmAssembler);
  1376. RegisterAssembler(as_i386_nasm_info,TX86NasmAssembler);
  1377. {$endif i386}
  1378. {$ifdef x86_64}
  1379. RegisterAssembler(as_x86_64_nasm_info,TX86NasmAssembler);
  1380. RegisterAssembler(as_x86_64_nasmwin64_info,TX86NasmAssembler);
  1381. RegisterAssembler(as_x86_64_nasmelf_info,TX86NasmAssembler);
  1382. RegisterAssembler(as_x86_64_nasmdarwin_info,TX86NasmAssembler);
  1383. {$endif x86_64}
  1384. end.