agx86nsm.pas 50 KB

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