agx86nsm.pas 50 KB

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