agx86nsm.pas 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements an asmoutput class for the Nasm assembler with
  4. Intel syntax for the i386+
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit agx86nsm;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,cpubase,globtype,
  23. aasmbase,aasmtai,aasmdata,aasmcpu,assemble,cgutils;
  24. type
  25. { TX86NasmAssembler }
  26. TX86NasmAssembler = class(texternalassembler)
  27. private
  28. FSectionsUsed: TFPHashList;
  29. FSectionsInDGROUP: TFPHashList;
  30. using_relative : boolean;
  31. function CodeSectionName(const aname:string): string;
  32. procedure WriteReference(var ref : treference);
  33. procedure WriteOper(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean);
  34. procedure WriteOper_jmp(const o:toper; ai : taicpu);
  35. procedure WriteSection(atype:TAsmSectiontype;const aname:string;alignment : byte);
  36. procedure ResetSectionsList;
  37. procedure WriteGroups;
  38. protected
  39. function single2str(d: single): string; override;
  40. function double2str(d: double): string; override;
  41. function extended2str(e: extended): string; override;
  42. public
  43. destructor Destroy;override;
  44. procedure WriteTree(p:TAsmList);override;
  45. procedure WriteAsmList;override;
  46. procedure WriteExternals;
  47. procedure WriteSmartExternals;
  48. procedure WriteHeader;
  49. function MakeCmdLine: TCmdStr;override;
  50. end;
  51. implementation
  52. uses
  53. cutils,globals,systems,
  54. fmodule,finput,verbose,cpuinfo,cgbase,omfbase
  55. ;
  56. const
  57. line_length = 64;
  58. nasm_regname_table : array[tregisterindex] of string[7] = (
  59. {r386nasm.inc contains the Nasm name of each register.}
  60. {$if defined(x86_64)}
  61. {$i r8664nasm.inc}
  62. {$elseif defined(i386)}
  63. {$i r386nasm.inc}
  64. {$elseif defined(i8086)}
  65. {$i r8086nasm.inc}
  66. {$endif}
  67. );
  68. 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_64bit,
  681. aitconst_64bit_unaligned:
  682. begin
  683. if assigned(tai_const(hp).sym) then
  684. internalerror(200404292);
  685. writer.AsmWrite(ait_const2str[aitconst_32bit]);
  686. writer.AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  687. writer.AsmWrite(',');
  688. writer.AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  689. writer.AsmLn;
  690. end;
  691. aitconst_uleb128bit,
  692. aitconst_sleb128bit,
  693. aitconst_128bit:
  694. begin
  695. writer.AsmWriteLn(asminfo^.comment+'Unsupported const type '+
  696. ait_const2str[consttype]);
  697. end;
  698. {$ifdef i8086}
  699. aitconst_farptr:
  700. begin
  701. writer.AsmWrite(ait_const2str[aitconst_16bit]);
  702. if assigned(tai_const(hp).sym) then
  703. begin
  704. if SmartAsm then
  705. AddSymbol(tai_const(hp).sym.name,false);
  706. writer.AsmWrite(tai_const(hp).sym.name);
  707. if tai_const(hp).value<>0 then
  708. writer.AsmWrite(tostr_with_plus(tai_const(hp).value));
  709. writer.AsmLn;
  710. writer.AsmWrite(ait_const2str[aitconst_16bit]);
  711. writer.AsmWrite('SEG ');
  712. writer.AsmWrite(tai_const(hp).sym.name);
  713. end
  714. else
  715. writer.AsmWrite(tostr(lo(longint(tai_const(hp).value)))+','+
  716. tostr(hi(longint(tai_const(hp).value))));
  717. writer.AsmLn;
  718. end;
  719. aitconst_seg:
  720. begin
  721. writer.AsmWrite(ait_const2str[aitconst_16bit]);
  722. if assigned(tai_const(hp).sym) then
  723. begin
  724. if SmartAsm then
  725. AddSymbol(tai_const(hp).sym.name,false);
  726. writer.AsmWrite('SEG ');
  727. writer.AsmWrite(tai_const(hp).sym.name);
  728. end
  729. else
  730. internalerror(2015110501);
  731. writer.AsmLn;
  732. end;
  733. aitconst_dgroup:
  734. writer.AsmWriteLn(#9'DW'#9'DGROUP');
  735. aitconst_fardataseg:
  736. writer.AsmWriteLn(#9'DW'#9+current_module.modulename^+'_DATA');
  737. {$endif i8086}
  738. aitconst_32bit,
  739. aitconst_16bit,
  740. aitconst_8bit,
  741. aitconst_rva_symbol,
  742. aitconst_secrel32_symbol,
  743. aitconst_16bit_unaligned,
  744. aitconst_32bit_unaligned:
  745. begin
  746. writer.AsmWrite(ait_const2str[tai_const(hp).consttype]);
  747. l:=0;
  748. repeat
  749. if assigned(tai_const(hp).sym) then
  750. begin
  751. if SmartAsm then
  752. begin
  753. AddSymbol(tai_const(hp).sym.name,false);
  754. if assigned(tai_const(hp).endsym) then
  755. AddSymbol(tai_const(hp).endsym.name,false);
  756. end;
  757. if assigned(tai_const(hp).endsym) then
  758. s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
  759. else
  760. s:=tai_const(hp).sym.name;
  761. if tai_const(hp).value<>0 then
  762. s:=s+tostr_with_plus(tai_const(hp).value);
  763. end
  764. else
  765. s:=tostr(tai_const(hp).value);
  766. writer.AsmWrite(s);
  767. inc(l,length(s));
  768. if (l>line_length) or
  769. (hp.next=nil) or
  770. (tai(hp.next).typ<>ait_const) or
  771. (tai_const(hp.next).consttype<>consttype) then
  772. break;
  773. hp:=tai(hp.next);
  774. writer.AsmWrite(',');
  775. until false;
  776. writer.AsmLn;
  777. end;
  778. else
  779. internalerror(200704252);
  780. end;
  781. end;
  782. ait_realconst:
  783. begin
  784. WriteRealConstAsBytes(tai_realconst(hp),#9#9'DB'#9,do_line);
  785. end;
  786. ait_string :
  787. begin
  788. counter := 0;
  789. lines := tai_string(hp).len div line_length;
  790. { separate lines in different parts }
  791. if tai_string(hp).len > 0 then
  792. Begin
  793. for j := 0 to lines-1 do
  794. begin
  795. writer.AsmWrite(#9#9'DB'#9);
  796. quoted:=false;
  797. for i:=counter to counter+line_length-1 do
  798. begin
  799. { it is an ascii character. }
  800. if (ord(tai_string(hp).str[i])>31) and
  801. (ord(tai_string(hp).str[i])<128) and
  802. (tai_string(hp).str[i]<>'"') then
  803. begin
  804. if not(quoted) then
  805. begin
  806. if i>counter then
  807. writer.AsmWrite(',');
  808. writer.AsmWrite('"');
  809. end;
  810. writer.AsmWrite(tai_string(hp).str[i]);
  811. quoted:=true;
  812. end { if > 31 and < 128 and ord('"') }
  813. else
  814. begin
  815. if quoted then
  816. writer.AsmWrite('"');
  817. if i>counter then
  818. writer.AsmWrite(',');
  819. quoted:=false;
  820. writer.AsmWrite(tostr(ord(tai_string(hp).str[i])));
  821. end;
  822. end; { end for i:=0 to... }
  823. if quoted then writer.AsmWrite('"');
  824. writer.AsmWrite(target_info.newline);
  825. inc(counter,line_length);
  826. end; { end for j:=0 ... }
  827. { do last line of lines }
  828. if counter<tai_string(hp).len then
  829. writer.AsmWrite(#9#9'DB'#9);
  830. quoted:=false;
  831. for i:=counter to tai_string(hp).len-1 do
  832. begin
  833. { it is an ascii character. }
  834. if (ord(tai_string(hp).str[i])>31) and
  835. (ord(tai_string(hp).str[i])<128) and
  836. (tai_string(hp).str[i]<>'"') then
  837. begin
  838. if not(quoted) then
  839. begin
  840. if i>counter then
  841. writer.AsmWrite(',');
  842. writer.AsmWrite('"');
  843. end;
  844. writer.AsmWrite(tai_string(hp).str[i]);
  845. quoted:=true;
  846. end { if > 31 and < 128 and " }
  847. else
  848. begin
  849. if quoted then
  850. writer.AsmWrite('"');
  851. if i>counter then
  852. writer.AsmWrite(',');
  853. quoted:=false;
  854. writer.AsmWrite(tostr(ord(tai_string(hp).str[i])));
  855. end;
  856. end; { end for i:=0 to... }
  857. if quoted then
  858. writer.AsmWrite('"');
  859. end;
  860. writer.AsmLn;
  861. end;
  862. ait_label :
  863. begin
  864. if tai_label(hp).labsym.is_used then
  865. begin
  866. if SmartAsm and (tai_label(hp).labsym.bind=AB_GLOBAL) then
  867. begin
  868. writer.AsmWrite(#9'GLOBAL ');
  869. writer.AsmWriteLn(tai_label(hp).labsym.name);
  870. end;
  871. writer.AsmWriteLn(tai_label(hp).labsym.name+':');
  872. end;
  873. if SmartAsm then
  874. AddSymbol(tai_label(hp).labsym.name,true);
  875. end;
  876. ait_symbol :
  877. begin
  878. if tai_symbol(hp).has_value then
  879. internalerror(2009090803);
  880. if tai_symbol(hp).is_global or SmartAsm then
  881. begin
  882. writer.AsmWrite(#9'GLOBAL ');
  883. writer.AsmWriteLn(tai_symbol(hp).sym.name);
  884. end;
  885. writer.AsmWrite(tai_symbol(hp).sym.name);
  886. if SmartAsm then
  887. AddSymbol(tai_symbol(hp).sym.name,true);
  888. if (not assigned(hp.next)) or (assigned(hp.next) and not(tai(hp.next).typ in
  889. [ait_const,ait_realconst,ait_string])) then
  890. writer.AsmWriteLn(':')
  891. end;
  892. ait_symbol_end : ;
  893. ait_instruction :
  894. begin
  895. fixed_opcode:=taicpu(hp).FixNonCommutativeOpcodes;
  896. { We need intel order, no At&t }
  897. taicpu(hp).SetOperandOrder(op_intel);
  898. { LOCK must be on same line as opcode }
  899. if (taicpu(hp).ops = 0) and
  900. (fixed_opcode = A_LOCK) then
  901. SkipNewLine:=true
  902. else
  903. SkipNewLine:=false;
  904. s:='';
  905. if ((fixed_opcode=A_FADDP) or
  906. (fixed_opcode=A_FMULP))
  907. and (taicpu(hp).ops=0) then
  908. begin
  909. taicpu(hp).allocate_oper(2);
  910. taicpu(hp).oper[0]^.typ:=top_reg;
  911. taicpu(hp).oper[0]^.reg:=NR_ST1;
  912. taicpu(hp).oper[1]^.typ:=top_reg;
  913. taicpu(hp).oper[1]^.reg:=NR_ST;
  914. end;
  915. { NASM only accepts move for loading of
  916. simple symbol address }
  917. if ((taicpu(hp).opcode=A_LEA) and
  918. (taicpu(hp).ops=2) and
  919. (taicpu(hp).oper[0]^.typ=top_reg) and
  920. (reg2opsize(taicpu(hp).oper[0]^.reg) in [S_NO,S_Q]) and
  921. (taicpu(hp).oper[1]^.typ=top_ref) and
  922. (taicpu(hp).oper[1]^.ref^.refaddr<>addr_no) and
  923. assigned(taicpu(hp).oper[1]^.ref^.symbol) and
  924. (taicpu(hp).oper[1]^.ref^.base=NR_NO)) then
  925. begin
  926. writer.AsmWrite(asminfo^.comment);
  927. writer.AsmWriteln('Converting LEA to MOV instruction');
  928. taicpu(hp).opcode:=A_MOV;
  929. end;
  930. if fixed_opcode=A_FWAIT then
  931. writer.AsmWriteln(#9#9'DB'#9'09bh')
  932. else
  933. begin
  934. prefix:='';
  935. {$ifndef i8086}
  936. { We need to explicitely set
  937. word prefix to get selectors
  938. to be pushed in 2 bytes PM }
  939. if (taicpu(hp).opsize=S_W) and
  940. ((fixed_opcode=A_PUSH) or
  941. (fixed_opcode=A_POP)) and
  942. (taicpu(hp).oper[0]^.typ=top_reg) and
  943. (is_segment_reg(taicpu(hp).oper[0]^.reg)) then
  944. writer.AsmWriteln(#9#9'DB'#9'066h');
  945. {$endif not i8086}
  946. writer.AsmWrite(#9#9+prefix+std_op2str[fixed_opcode]+cond2str[taicpu(hp).condition]);
  947. if taicpu(hp).ops<>0 then
  948. begin
  949. if is_calljmp(fixed_opcode) then
  950. begin
  951. writer.AsmWrite(#9);
  952. WriteOper_jmp(taicpu(hp).oper[0]^,taicpu(hp));
  953. end
  954. else
  955. begin
  956. for i:=0 to taicpu(hp).ops-1 do
  957. begin
  958. if i=0 then
  959. writer.AsmWrite(#9)
  960. else
  961. writer.AsmWrite(',');
  962. WriteOper(taicpu(hp).oper[i]^,taicpu(hp).opsize,fixed_opcode,taicpu(hp).ops,(i=2));
  963. end;
  964. end;
  965. end;
  966. if not SkipNewLine then
  967. writer.AsmLn;
  968. end;
  969. end;
  970. ait_stab,
  971. ait_force_line,
  972. ait_function_name : ;
  973. ait_cutobject :
  974. begin
  975. if SmartAsm then
  976. begin
  977. { only reset buffer if nothing has changed }
  978. if not writer.ClearIfEmpty then
  979. begin
  980. if SmartAsm then
  981. begin
  982. WriteSmartExternals;
  983. FreeExternChainList;
  984. end;
  985. WriteGroups;
  986. writer.AsmClose;
  987. DoAssemble;
  988. writer.AsmCreate(tai_cutobject(hp).place);
  989. ResetSectionsList;
  990. WriteHeader;
  991. end;
  992. { avoid empty files }
  993. LastSecType:=sec_none;
  994. LastSecName:='';
  995. LastAlign:=4;
  996. while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
  997. begin
  998. if tai(hp.next).typ=ait_section then
  999. begin
  1000. LastSecType:=tai_section(hp.next).sectype;
  1001. LastSecName:=tai_section(hp.next).name^;
  1002. LastAlign:=tai_section(hp.next).secalign;
  1003. end;
  1004. hp:=tai(hp.next);
  1005. end;
  1006. if LastSecType<>sec_none then
  1007. WriteSection(LastSecType,LastSecName,LastAlign);
  1008. writer.MarkEmpty;
  1009. NewObject:=true;
  1010. end;
  1011. end;
  1012. ait_marker :
  1013. if tai_marker(hp).kind=mark_NoLineInfoStart then
  1014. inc(InlineLevel)
  1015. else if tai_marker(hp).kind=mark_NoLineInfoEnd then
  1016. dec(InlineLevel);
  1017. ait_directive :
  1018. begin
  1019. case tai_directive(hp).directive of
  1020. asd_nasm_import,
  1021. asd_extern :
  1022. begin
  1023. case tai_directive(hp).directive of
  1024. asd_nasm_import :
  1025. writer.AsmWrite('import ');
  1026. asd_extern :
  1027. writer.AsmWrite('EXTERN ');
  1028. else
  1029. internalerror(200509191);
  1030. end;
  1031. if tai_directive(hp).name<>'' then
  1032. begin
  1033. if SmartAsm then
  1034. AddSymbol(tai_directive(hp).name,false);
  1035. writer.AsmWrite(tai_directive(hp).name);
  1036. end;
  1037. end;
  1038. asd_cpu :
  1039. begin
  1040. writer.AsmWrite('CPU ');
  1041. for cpu:=low(tcputype) to high(tcputype) do
  1042. begin
  1043. if tai_directive(hp).name=CPUTypeStr[CPU] then
  1044. begin
  1045. writer.AsmWriteLn(nasm_cpu_name[cpu]);
  1046. break;
  1047. end;
  1048. end;
  1049. end;
  1050. else
  1051. internalerror(200509191);
  1052. end;
  1053. writer.AsmLn;
  1054. end;
  1055. ait_seh_directive :
  1056. { Ignore for now };
  1057. ait_varloc:
  1058. begin
  1059. if tai_varloc(hp).newlocationhi<>NR_NO then
  1060. writer.AsmWriteLn(asminfo^.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1061. std_regname(tai_varloc(hp).newlocationhi)+':'+std_regname(tai_varloc(hp).newlocation))
  1062. else
  1063. writer.AsmWriteLn(asminfo^.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1064. std_regname(tai_varloc(hp).newlocation));
  1065. end;
  1066. else
  1067. internalerror(10000);
  1068. end;
  1069. hp:=tai(hp.next);
  1070. end;
  1071. end;
  1072. procedure TX86NasmAssembler.WriteExternals;
  1073. var
  1074. sym : TAsmSymbol;
  1075. i : longint;
  1076. begin
  1077. for i:=0 to current_asmdata.AsmSymbolDict.Count-1 do
  1078. begin
  1079. sym:=TAsmSymbol(current_asmdata.AsmSymbolDict[i]);
  1080. if sym.bind=AB_EXTERNAL then
  1081. writer.AsmWriteln('EXTERN'#9+sym.name);
  1082. end;
  1083. end;
  1084. procedure TX86NasmAssembler.WriteSmartExternals;
  1085. var
  1086. EC : PExternChain;
  1087. begin
  1088. EC:=FEC;
  1089. while assigned(EC) do
  1090. begin
  1091. if not EC^.is_defined then
  1092. writer.AsmWriteln('EXTERN'#9+EC^.psym^);
  1093. EC:=EC^.next;
  1094. end;
  1095. end;
  1096. procedure TX86NasmAssembler.WriteHeader;
  1097. begin
  1098. {$if defined(i8086)}
  1099. writer.AsmWriteLn('BITS 16');
  1100. {$elseif defined(i386)}
  1101. writer.AsmWriteLn('BITS 32');
  1102. using_relative:=false;
  1103. {$elseif defined(x86_64)}
  1104. writer.AsmWriteLn('BITS 64');
  1105. writer.AsmWriteLn('default rel');
  1106. using_relative:=true;
  1107. {$endif}
  1108. writer.AsmWriteLn('CPU '+nasm_cpu_name[current_settings.cputype]);
  1109. end;
  1110. procedure TX86NasmAssembler.WriteAsmList;
  1111. var
  1112. hal : tasmlisttype;
  1113. begin
  1114. {$ifdef EXTDEBUG}
  1115. if current_module.mainsource<>'' then
  1116. comment(v_info,'Start writing nasm-styled assembler output for '+current_module.mainsource);
  1117. {$endif}
  1118. ResetSectionsList;
  1119. WriteHeader;
  1120. writer.AsmLn;
  1121. WriteExternals;
  1122. for hal:=low(TasmlistType) to high(TasmlistType) do
  1123. begin
  1124. if not (current_asmdata.asmlists[hal].empty) then
  1125. begin
  1126. writer.AsmWriteLn(asminfo^.comment+'Begin asmlist '+AsmListTypeStr[hal]);
  1127. writetree(current_asmdata.asmlists[hal]);
  1128. writer.AsmWriteLn(asminfo^.comment+'End asmlist '+AsmListTypeStr[hal]);
  1129. end;
  1130. end;
  1131. writer.AsmLn;
  1132. if SmartAsm then
  1133. begin
  1134. WriteSmartExternals;
  1135. FreeExternChainList;
  1136. end;
  1137. WriteGroups;
  1138. {$ifdef EXTDEBUG}
  1139. if current_module.mainsource<>'' then
  1140. comment(v_info,'Done writing nasm-styled assembler output for '+current_module.mainsource);
  1141. {$endif EXTDEBUG}
  1142. end;
  1143. function TX86NasmAssembler.MakeCmdLine: TCmdStr;
  1144. var
  1145. FormatName : string;
  1146. begin
  1147. result:=Inherited MakeCmdLine;
  1148. {$ifdef i8086}
  1149. case target_info.system of
  1150. system_i8086_msdos,
  1151. system_i8086_win16,
  1152. system_i8086_embedded:
  1153. begin
  1154. FormatName:='obj';
  1155. if (cs_debuginfo in current_settings.moduleswitches) or
  1156. (cs_asm_source in current_settings.globalswitches) then
  1157. Replace(result,'$DEBUG','-g')
  1158. else
  1159. Replace(result,'$DEBUG','');
  1160. end
  1161. else
  1162. internalerror(2014082060);
  1163. end;
  1164. {$endif i8086}
  1165. {$ifdef i386}
  1166. case target_info.system of
  1167. system_i386_go32v2:
  1168. FormatName:='coff';
  1169. system_i386_wdosx,
  1170. system_i386_win32:
  1171. FormatName:='win32';
  1172. system_i386_embedded:
  1173. FormatName:='obj';
  1174. system_i386_linux,
  1175. system_i386_beos:
  1176. FormatName:='elf';
  1177. system_i386_darwin:
  1178. FormatName:='macho32';
  1179. else
  1180. FormatName:='elf';
  1181. end;
  1182. {$endif i386}
  1183. {$ifdef x86_64}
  1184. case target_info.system of
  1185. system_x86_64_win64:
  1186. FormatName:='win64';
  1187. system_x86_64_darwin:
  1188. FormatName:='macho64';
  1189. system_x86_64_embedded:
  1190. FormatName:='obj';
  1191. system_x86_64_linux:
  1192. FormatName:='elf64';
  1193. else
  1194. FormatName:='elf64';
  1195. end;
  1196. {$endif x86_64}
  1197. Replace(result,'$FORMAT',FormatName);
  1198. end;
  1199. {*****************************************************************************
  1200. Initialize
  1201. *****************************************************************************}
  1202. {$ifdef i8086}
  1203. const
  1204. as_i8086_nasm_info : tasminfo =
  1205. (
  1206. id : as_i8086_nasm;
  1207. idtxt : 'NASM';
  1208. asmbin : 'nasm';
  1209. asmcmd : '-f $FORMAT $DEBUG -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1210. supported_targets : [system_i8086_msdos,system_i8086_win16,system_i8086_embedded];
  1211. flags : [af_needar,af_no_debug];
  1212. labelprefix : '..@';
  1213. comment : '; ';
  1214. dollarsign: '$';
  1215. );
  1216. as_i8086_nasmobj_info : tasminfo =
  1217. (
  1218. id : as_i8086_nasmobj;
  1219. idtxt : 'NASMOBJ';
  1220. asmbin : 'nasm';
  1221. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1222. supported_targets : [system_i8086_msdos,system_i8086_win16,system_i8086_embedded];
  1223. flags : [af_needar,af_no_debug];
  1224. labelprefix : '..@';
  1225. comment : '; ';
  1226. dollarsign: '$';
  1227. );
  1228. {$endif i8086}
  1229. {$ifdef i386}
  1230. const
  1231. as_i386_nasmcoff_info : tasminfo =
  1232. (
  1233. id : as_i386_nasmcoff;
  1234. idtxt : 'NASMCOFF';
  1235. asmbin : 'nasm';
  1236. asmcmd : '-f coff -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1237. supported_targets : [system_i386_go32v2];
  1238. flags : [af_needar,af_no_debug];
  1239. labelprefix : '..@';
  1240. comment : '; ';
  1241. dollarsign: '$';
  1242. );
  1243. as_i386_nasmwin32_info : tasminfo =
  1244. (
  1245. id : as_i386_nasmwin32;
  1246. idtxt : 'NASMWIN32';
  1247. asmbin : 'nasm';
  1248. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1249. supported_targets : [system_i386_win32];
  1250. flags : [af_needar,af_no_debug,af_smartlink_sections];
  1251. labelprefix : '..@';
  1252. comment : '; ';
  1253. dollarsign: '$';
  1254. );
  1255. as_i386_nasmobj_info : tasminfo =
  1256. (
  1257. id : as_i386_nasmobj;
  1258. idtxt : 'NASMOBJ';
  1259. asmbin : 'nasm';
  1260. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1261. supported_targets : [system_i386_embedded, system_i8086_msdos];
  1262. flags : [af_needar,af_no_debug];
  1263. labelprefix : '..@';
  1264. comment : '; ';
  1265. dollarsign: '$';
  1266. );
  1267. as_i386_nasmwdosx_info : tasminfo =
  1268. (
  1269. id : as_i386_nasmwdosx;
  1270. idtxt : 'NASMWDOSX';
  1271. asmbin : 'nasm';
  1272. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1273. supported_targets : [system_i386_wdosx];
  1274. flags : [af_needar,af_no_debug];
  1275. labelprefix : '..@';
  1276. comment : '; ';
  1277. dollarsign: '$';
  1278. );
  1279. as_i386_nasmelf_info : tasminfo =
  1280. (
  1281. id : as_i386_nasmelf;
  1282. idtxt : 'NASMELF';
  1283. asmbin : 'nasm';
  1284. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1285. supported_targets : [system_i386_linux];
  1286. flags : [af_needar,af_no_debug];
  1287. labelprefix : '..@';
  1288. comment : '; ';
  1289. dollarsign: '$';
  1290. );
  1291. {
  1292. as_i386_nasmdarwin_info : tasminfo =
  1293. (
  1294. id : as_i386_nasmdarwin;
  1295. idtxt : 'NASMDARWIN';
  1296. asmbin : 'nasm';
  1297. asmcmd : '-f macho32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1298. supported_targets : [system_i386_darwin];
  1299. flags : [af_needar,af_no_debug];
  1300. labelprefix : '..@';
  1301. comment : '; ';
  1302. dollarsign: '$';
  1303. );
  1304. }
  1305. as_i386_nasmbeos_info : tasminfo =
  1306. (
  1307. id : as_i386_nasmbeos;
  1308. idtxt : 'NASMELF';
  1309. asmbin : 'nasm';
  1310. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1311. supported_targets : [system_i386_beos];
  1312. flags : [af_needar,af_no_debug];
  1313. labelprefix : '..@';
  1314. comment : '; ';
  1315. dollarsign: '$';
  1316. );
  1317. as_i386_nasmhaiku_info : tasminfo =
  1318. (
  1319. id : as_i386_nasmhaiku;
  1320. idtxt : 'NASMELF';
  1321. asmbin : 'nasm';
  1322. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1323. supported_targets : [system_i386_haiku];
  1324. flags : [af_needar,af_no_debug];
  1325. labelprefix : '..@';
  1326. comment : '; ';
  1327. dollarsign: '$';
  1328. );
  1329. as_i386_nasm_info : tasminfo =
  1330. (
  1331. id : as_i386_nasm;
  1332. idtxt : 'NASM';
  1333. asmbin : 'nasm';
  1334. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1335. supported_targets : [system_any];
  1336. flags : [af_needar,af_no_debug];
  1337. labelprefix : '..@';
  1338. comment : '; ';
  1339. dollarsign: '$';
  1340. );
  1341. {$endif i386}
  1342. {$ifdef x86_64}
  1343. const
  1344. as_x86_64_nasm_info : tasminfo =
  1345. (
  1346. id : as_x86_64_nasm;
  1347. idtxt : 'NASM';
  1348. asmbin : 'nasm';
  1349. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1350. supported_targets : [system_any];
  1351. flags : [af_needar{,af_no_debug}];
  1352. labelprefix : '..@';
  1353. comment : '; ';
  1354. dollarsign: '$';
  1355. );
  1356. as_x86_64_nasmwin64_info : tasminfo =
  1357. (
  1358. id : as_x86_64_nasmwin64;
  1359. idtxt : 'NASMWIN64';
  1360. asmbin : 'nasm';
  1361. asmcmd : '-f win64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1362. supported_targets : [system_x86_64_win64];
  1363. flags : [af_needar,af_no_debug];
  1364. labelprefix : '..@';
  1365. comment : '; ';
  1366. dollarsign: '$';
  1367. );
  1368. as_x86_64_nasmelf_info : tasminfo =
  1369. (
  1370. id : as_x86_64_nasmelf;
  1371. idtxt : 'NASMELF';
  1372. asmbin : 'nasm';
  1373. asmcmd : '-f elf64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1374. supported_targets : [system_x86_64_linux];
  1375. flags : [af_needar,af_no_debug];
  1376. labelprefix : '..@';
  1377. comment : '; ';
  1378. dollarsign: '$';
  1379. );
  1380. as_x86_64_nasmdarwin_info : tasminfo =
  1381. (
  1382. id : as_x86_64_nasmdarwin;
  1383. idtxt : 'NASMDARWIN';
  1384. asmbin : 'nasm';
  1385. asmcmd : '-f macho64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1386. supported_targets : [system_x86_64_darwin];
  1387. flags : [af_needar,af_no_debug];
  1388. labelprefix : '..@';
  1389. comment : '; ';
  1390. dollarsign: '$';
  1391. );
  1392. {$endif x86_64}
  1393. initialization
  1394. {$ifdef i8086}
  1395. RegisterAssembler(as_i8086_nasm_info,TX86NasmAssembler);
  1396. RegisterAssembler(as_i8086_nasmobj_info,TX86NasmAssembler);
  1397. {$endif i8086}
  1398. {$ifdef i386}
  1399. RegisterAssembler(as_i386_nasmcoff_info,TX86NasmAssembler);
  1400. RegisterAssembler(as_i386_nasmwin32_info,TX86NasmAssembler);
  1401. RegisterAssembler(as_i386_nasmwdosx_info,TX86NasmAssembler);
  1402. RegisterAssembler(as_i386_nasmobj_info,TX86NasmAssembler);
  1403. RegisterAssembler(as_i386_nasmbeos_info,TX86NasmAssembler);
  1404. RegisterAssembler(as_i386_nasmhaiku_info,TX86NasmAssembler);
  1405. RegisterAssembler(as_i386_nasmelf_info,TX86NasmAssembler);
  1406. RegisterAssembler(as_i386_nasm_info,TX86NasmAssembler);
  1407. {$endif i386}
  1408. {$ifdef x86_64}
  1409. RegisterAssembler(as_x86_64_nasm_info,TX86NasmAssembler);
  1410. RegisterAssembler(as_x86_64_nasmwin64_info,TX86NasmAssembler);
  1411. RegisterAssembler(as_x86_64_nasmelf_info,TX86NasmAssembler);
  1412. RegisterAssembler(as_x86_64_nasmdarwin_info,TX86NasmAssembler);
  1413. {$endif x86_64}
  1414. end.