agx86nsm.pas 48 KB

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