agx86nsm.pas 49 KB

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