agx86nsm.pas 51 KB

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