agx86nsm.pas 48 KB

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