agx86nsm.pas 51 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(const aname:string): string;
  30. procedure WriteReference(var ref : treference);
  31. procedure WriteOper(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean);
  32. procedure WriteOper_jmp(const o:toper; ai : taicpu);
  33. procedure WriteSection(atype:TAsmSectiontype;const aname:string);
  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(const aname:string): string;
  271. begin
  272. {$ifdef i8086}
  273. if current_settings.x86memorymodel in x86_far_code_models then
  274. begin
  275. if cs_huge_code in current_settings.moduleswitches then
  276. result:=aname + '_TEXT use16 class=code'
  277. else
  278. result:=current_module.modulename^ + '_TEXT';
  279. end
  280. else
  281. {$endif}
  282. result:='.text';
  283. end;
  284. procedure TX86NasmAssembler.WriteReference(var ref : treference);
  285. var
  286. first : boolean;
  287. base_done : boolean;
  288. begin
  289. with ref do
  290. begin
  291. AsmWrite('[');
  292. first:=true;
  293. base_done:=false;
  294. if (segment<>NR_NO) then
  295. AsmWrite(nasm_regname(segment)+':');
  296. {$ifdef x86_64}
  297. if (base=NR_RIP) then
  298. begin
  299. { nasm RIP is implicit for pic }
  300. if not (ref.refaddr in [addr_pic,addr_pic_no_got]) and not using_relative then
  301. AsmWrite('$ + ');
  302. base_done:=true;
  303. end;
  304. {$endif x86_64}
  305. if assigned(symbol) then
  306. begin
  307. AsmWrite(symbol.name);
  308. if SmartAsm then
  309. AddSymbol(symbol.name,false);
  310. first:=false;
  311. end;
  312. if (base<>NR_NO) and not base_done then
  313. begin
  314. if not(first) then
  315. AsmWrite('+')
  316. else
  317. first:=false;
  318. AsmWrite(nasm_regname(base))
  319. end;
  320. if (index<>NR_NO) then
  321. begin
  322. if not(first) then
  323. AsmWrite('+')
  324. else
  325. first:=false;
  326. AsmWrite(nasm_regname(index));
  327. if scalefactor<>0 then
  328. AsmWrite('*'+tostr(scalefactor));
  329. end;
  330. if offset<0 then
  331. begin
  332. AsmWrite(tostr(offset));
  333. first:=false;
  334. end
  335. else if (offset>0) then
  336. begin
  337. AsmWrite('+'+tostr(offset));
  338. first:=false;
  339. end;
  340. if first then
  341. AsmWrite('0');
  342. AsmWrite(']');
  343. end;
  344. end;
  345. procedure TX86NasmAssembler.WriteOper(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean);
  346. begin
  347. case o.typ of
  348. top_reg :
  349. AsmWrite(nasm_regname(o.reg));
  350. top_const :
  351. begin
  352. if (ops=1) and (opcode<>A_RET) then
  353. AsmWrite(sizestr(s,dest));
  354. AsmWrite(tostr(longint(o.val)));
  355. end;
  356. top_ref :
  357. begin
  358. if o.ref^.refaddr in [addr_no,addr_pic,addr_pic_no_got] then
  359. begin
  360. if not ((opcode = A_LEA) or (opcode = A_LGS) or
  361. (opcode = A_LSS) or (opcode = A_LFS) or
  362. {$ifndef x86_64}
  363. (opcode = A_LES) or (opcode = A_LDS) or
  364. {$endif x86_64}
  365. // (opcode = A_SHR) or (opcode = A_SHL) or
  366. // (opcode = A_SAR) or (opcode = A_SAL) or
  367. (opcode = A_OUT) or (opcode = A_IN)) then
  368. AsmWrite(sizestr(s,dest));
  369. WriteReference(o.ref^);
  370. end
  371. {$ifdef i8086}
  372. else if o.ref^.refaddr=addr_dgroup then
  373. begin
  374. AsmWrite('dgroup');
  375. end
  376. {$endif i8086}
  377. else
  378. begin
  379. {$ifdef x86_64}
  380. if s=S_L then
  381. asmwrite('dword ')
  382. else
  383. asmwrite('qword ');
  384. {$endif}
  385. {$ifdef i386}
  386. asmwrite('dword ');
  387. {$endif i386}
  388. {$ifdef i8086}
  389. if o.ref^.refaddr=addr_seg then
  390. asmwrite('SEG ')
  391. else
  392. asmwrite('word ');
  393. {$endif i8086}
  394. if assigned(o.ref^.symbol) then
  395. begin
  396. if SmartAsm then
  397. AddSymbol(o.ref^.symbol.name,false);
  398. asmwrite(o.ref^.symbol.name);
  399. if o.ref^.offset=0 then
  400. exit;
  401. end;
  402. if o.ref^.offset>0 then
  403. asmwrite('+');
  404. asmwrite(tostr(o.ref^.offset));
  405. end;
  406. end;
  407. else
  408. internalerror(10001);
  409. end;
  410. end;
  411. procedure TX86NasmAssembler.WriteOper_jmp(const o:toper; ai : taicpu);
  412. begin
  413. case o.typ of
  414. top_reg :
  415. AsmWrite(nasm_regname(o.reg));
  416. top_ref :
  417. if o.ref^.refaddr=addr_no then
  418. begin
  419. if ai.opsize=S_FAR then
  420. AsmWrite('far ');
  421. WriteReference(o.ref^);
  422. end
  423. else
  424. begin
  425. if ai.opsize=S_FAR then
  426. AsmWrite('far ');
  427. { else
  428. AsmWrite('near ') just disables short branches, increasing code size.
  429. Omitting it does not cause any bad effects, tested with nasm 2.11. }
  430. AsmWrite(o.ref^.symbol.name);
  431. if SmartAsm then
  432. AddSymbol(o.ref^.symbol.name,false);
  433. if o.ref^.offset>0 then
  434. AsmWrite('+'+tostr(o.ref^.offset))
  435. else
  436. if o.ref^.offset<0 then
  437. AsmWrite(tostr(o.ref^.offset));
  438. end;
  439. top_const :
  440. AsmWrite(tostr(aint(o.val)));
  441. else
  442. internalerror(10001);
  443. end;
  444. end;
  445. const
  446. ait_const2str : array[aitconst_128bit..aitconst_64bit_unaligned] of string[30]=(
  447. #9'FIXME_128BIT'#9,#9'DQ'#9,#9'DD'#9,#9'DW'#9,#9'DB'#9,
  448. #9'FIXME_SLEB128BIT'#9,#9'FIXME_ULEB128BIT'#9,
  449. #9'RVA'#9,#9'SECREL32'#9,#9'FIXME_darwin_dwarf_delta64'#9,
  450. #9'FIXME_darwin_dwarf_delta32'#9,#9'FIXME_half16bit'#9,
  451. #9'DW'#9,#9'DD'#9,#9'FIXME_64BIT_UNALIGNED'#9
  452. );
  453. procedure TX86NasmAssembler.WriteSection(atype:TAsmSectiontype;const aname:string);
  454. const
  455. secnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
  456. '.text',
  457. '.data',
  458. '.data',
  459. '.rodata',
  460. '.bss',
  461. '.tbss',
  462. '.pdata',
  463. '.text','.data','.data','.data','.data',
  464. '.stab',
  465. '.stabstr',
  466. '.idata2','.idata4','.idata5','.idata6','.idata7','.edata',
  467. '.eh_frame',
  468. '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
  469. '.fpc',
  470. '',
  471. '.init',
  472. '.fini',
  473. '.objc_class',
  474. '.objc_meta_class',
  475. '.objc_cat_cls_meth',
  476. '.objc_cat_inst_meth',
  477. '.objc_protocol',
  478. '.objc_string_object',
  479. '.objc_cls_meth',
  480. '.objc_inst_meth',
  481. '.objc_cls_refs',
  482. '.objc_message_refs',
  483. '.objc_symbols',
  484. '.objc_category',
  485. '.objc_class_vars',
  486. '.objc_instance_vars',
  487. '.objc_module_info',
  488. '.objc_class_names',
  489. '.objc_meth_var_types',
  490. '.objc_meth_var_names',
  491. '.objc_selector_strs',
  492. '.objc_protocol_ext',
  493. '.objc_class_ext',
  494. '.objc_property',
  495. '.objc_image_info',
  496. '.objc_cstring_object',
  497. '.objc_sel_fixup',
  498. '__DATA,__objc_data',
  499. '__DATA,__objc_const',
  500. '.objc_superrefs',
  501. '__DATA, __datacoal_nt,coalesced',
  502. '.objc_classlist',
  503. '.objc_nlclasslist',
  504. '.objc_catlist',
  505. '.obcj_nlcatlist',
  506. '.objc_protolist',
  507. '.stack'
  508. );
  509. begin
  510. AsmLn;
  511. AsmWrite('SECTION ');
  512. { go32v2 stub only loads .text and .data sections, and allocates space for .bss.
  513. Thus, data which normally goes into .rodata and .rodata_norel sections must
  514. end up in .data section }
  515. if (atype in [sec_rodata,sec_rodata_norel]) and
  516. (target_info.system=system_i386_go32v2) then
  517. AsmWrite('.data')
  518. else if (atype=sec_user) then
  519. AsmWrite(aname)
  520. else if (atype=sec_threadvar) and
  521. (target_info.system in (systems_windows+systems_wince)) then
  522. AsmWrite('.tls'#9'bss')
  523. else if secnames[atype]='.text' then
  524. AsmWrite(CodeSectionName(aname))
  525. else
  526. AsmWrite(secnames[atype]);
  527. if create_smartlink_sections and
  528. (atype<>sec_bss) and
  529. (aname<>'') then
  530. begin
  531. AsmWrite('.');
  532. AsmWrite(aname);
  533. end;
  534. AsmLn;
  535. LastSecType:=atype;
  536. end;
  537. procedure TX86NasmAssembler.WriteTree(p:TAsmList);
  538. {$ifdef cpuextended}
  539. type
  540. t80bitarray = array[0..9] of byte;
  541. {$endif cpuextended}
  542. var
  543. s : string;
  544. hp : tai;
  545. counter,
  546. lines,
  547. i,j,l : longint;
  548. InlineLevel : longint;
  549. consttype : taiconst_type;
  550. do_line, SkipNewLine,
  551. quoted : boolean;
  552. co : comp;
  553. sin : single;
  554. d : double;
  555. {$ifdef cpuextended}
  556. e : extended;
  557. {$endif cpuextended}
  558. fixed_opcode: TAsmOp;
  559. prefix, LastSecName : string;
  560. begin
  561. if not assigned(p) then
  562. exit;
  563. InlineLevel:=0;
  564. { lineinfo is only needed for al_procedures (PFV) }
  565. do_line:=(cs_asm_source in current_settings.globalswitches) or
  566. ((cs_lineinfo in current_settings.moduleswitches)
  567. and (p=current_asmdata.asmlists[al_procedures]));
  568. hp:=tai(p.first);
  569. while assigned(hp) do
  570. begin
  571. prefetch(pointer(hp.next)^);
  572. if not(hp.typ in SkipLineInfo) then
  573. begin
  574. current_filepos:=tailineinfo(hp).fileinfo;
  575. { no line info for inlined code }
  576. if do_line and (inlinelevel=0) then
  577. WriteSourceLine(hp as tailineinfo);
  578. end;
  579. case hp.typ of
  580. ait_comment :
  581. Begin
  582. AsmWrite(target_asm.comment);
  583. AsmWritePChar(tai_comment(hp).str);
  584. AsmLn;
  585. End;
  586. ait_regalloc :
  587. begin
  588. if (cs_asm_regalloc in current_settings.globalswitches) then
  589. AsmWriteLn(#9#9+target_asm.comment+'Register '+nasm_regname(tai_regalloc(hp).reg)+' '+
  590. regallocstr[tai_regalloc(hp).ratype]);
  591. end;
  592. ait_tempalloc :
  593. begin
  594. if (cs_asm_tempalloc in current_settings.globalswitches) then
  595. WriteTempalloc(tai_tempalloc(hp));
  596. end;
  597. ait_section :
  598. begin
  599. if tai_section(hp).sectype<>sec_none then
  600. WriteSection(tai_section(hp).sectype,tai_section(hp).name^);
  601. LastSecType:=tai_section(hp).sectype;
  602. end;
  603. ait_align :
  604. begin
  605. if (tai_align(hp).aligntype>1) then
  606. begin
  607. if (LastSecType=sec_bss) or (
  608. (LastSecType=sec_threadvar) and
  609. (target_info.system in (systems_windows+systems_wince))
  610. ) then
  611. AsmWriteLn(#9'ALIGNB '+tostr(tai_align(hp).aligntype))
  612. else
  613. AsmWriteLn(#9'ALIGN '+tostr(tai_align(hp).aligntype));
  614. end;
  615. end;
  616. ait_datablock :
  617. begin
  618. if tai_datablock(hp).is_global or SmartAsm then
  619. begin
  620. AsmWrite(#9'GLOBAL ');
  621. AsmWriteLn(tai_datablock(hp).sym.name);
  622. end;
  623. AsmWrite(PadTabs(tai_datablock(hp).sym.name,':'));
  624. if SmartAsm then
  625. AddSymbol(tai_datablock(hp).sym.name,true);
  626. AsmWriteLn('RESB'#9+tostr(tai_datablock(hp).size));
  627. end;
  628. ait_const:
  629. begin
  630. consttype:=tai_const(hp).consttype;
  631. case consttype of
  632. aitconst_64bit,
  633. aitconst_64bit_unaligned:
  634. begin
  635. if assigned(tai_const(hp).sym) then
  636. internalerror(200404292);
  637. AsmWrite(ait_const2str[aitconst_32bit]);
  638. AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  639. AsmWrite(',');
  640. AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  641. AsmLn;
  642. end;
  643. aitconst_uleb128bit,
  644. aitconst_sleb128bit,
  645. aitconst_128bit:
  646. begin
  647. AsmWriteLn(target_asm.comment+'Unsupported const type '+
  648. ait_const2str[consttype]);
  649. end;
  650. {$ifdef i8086}
  651. aitconst_farptr:
  652. begin
  653. AsmWrite(ait_const2str[aitconst_16bit]);
  654. if assigned(tai_const(hp).sym) then
  655. begin
  656. if SmartAsm then
  657. AddSymbol(tai_const(hp).sym.name,false);
  658. AsmWrite(tai_const(hp).sym.name);
  659. if tai_const(hp).value<>0 then
  660. AsmWrite(tostr_with_plus(tai_const(hp).value));
  661. AsmLn;
  662. AsmWrite(ait_const2str[aitconst_16bit]);
  663. AsmWrite('SEG ');
  664. AsmWrite(tai_const(hp).sym.name);
  665. end
  666. else
  667. AsmWrite(tostr(lo(longint(tai_const(hp).value)))+','+
  668. tostr(hi(longint(tai_const(hp).value))));
  669. AsmLn;
  670. end;
  671. {$endif i8086}
  672. aitconst_32bit,
  673. aitconst_16bit,
  674. aitconst_8bit,
  675. aitconst_rva_symbol,
  676. aitconst_secrel32_symbol,
  677. aitconst_16bit_unaligned,
  678. aitconst_32bit_unaligned:
  679. begin
  680. AsmWrite(ait_const2str[tai_const(hp).consttype]);
  681. l:=0;
  682. repeat
  683. if assigned(tai_const(hp).sym) then
  684. begin
  685. if SmartAsm then
  686. begin
  687. AddSymbol(tai_const(hp).sym.name,false);
  688. if assigned(tai_const(hp).endsym) then
  689. AddSymbol(tai_const(hp).endsym.name,false);
  690. end;
  691. if assigned(tai_const(hp).endsym) then
  692. s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
  693. else
  694. s:=tai_const(hp).sym.name;
  695. if tai_const(hp).value<>0 then
  696. s:=s+tostr_with_plus(tai_const(hp).value);
  697. end
  698. else
  699. s:=tostr(tai_const(hp).value);
  700. AsmWrite(s);
  701. inc(l,length(s));
  702. if (l>line_length) or
  703. (hp.next=nil) or
  704. (tai(hp.next).typ<>ait_const) or
  705. (tai_const(hp.next).consttype<>consttype) then
  706. break;
  707. hp:=tai(hp.next);
  708. AsmWrite(',');
  709. until false;
  710. AsmLn;
  711. end;
  712. else
  713. internalerror(200704252);
  714. end;
  715. end;
  716. {$if defined(cpuextended) and defined(FPC_HAS_TYPE_EXTENDED)}
  717. ait_real_80bit :
  718. begin
  719. if do_line then
  720. AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_real_80bit(hp).value));
  721. { Make sure e is a extended type, bestreal could be
  722. a different type (bestreal) !! (PFV) }
  723. e:=tai_real_80bit(hp).value;
  724. AsmWrite(#9#9'DB'#9);
  725. for i:=0 to 9 do
  726. begin
  727. if i<>0 then
  728. AsmWrite(',');
  729. AsmWrite(tostr(t80bitarray(e)[i]));
  730. end;
  731. for i:=11 to tai_real_80bit(hp).savesize do
  732. AsmWrite(',0');
  733. AsmLn;
  734. end;
  735. {$else cpuextended}
  736. ait_real_80bit :
  737. AsmWriteLn(#9#9'DT'#9+extended2str(tai_real_80bit(hp).value));
  738. {$endif cpuextended}
  739. // ait_real_64bit :
  740. // AsmWriteLn(#9#9'DQ'#9+double2str(tai_real_64bit(hp).value));
  741. ait_real_64bit :
  742. begin
  743. if do_line then
  744. AsmWriteLn(target_asm.comment+'value: '+double2str(tai_real_64bit(hp).value));
  745. d:=tai_real_64bit(hp).value;
  746. { swap the values to correct endian if required }
  747. if source_info.endian <> target_info.endian then
  748. swap64bitarray(t64bitarray(d));
  749. AsmWrite(#9#9'DB'#9);
  750. {$ifdef arm}
  751. if tai_real_64bit(hp).formatoptions=fo_hiloswapped then
  752. begin
  753. for i:=4 to 7 do
  754. begin
  755. if i<>4 then
  756. AsmWrite(',');
  757. AsmWrite(tostr(t64bitarray(d)[i]));
  758. end;
  759. for i:=0 to 3 do
  760. begin
  761. AsmWrite(',');
  762. AsmWrite(tostr(t64bitarray(d)[i]));
  763. end;
  764. end
  765. else
  766. {$endif arm}
  767. begin
  768. for i:=0 to 7 do
  769. begin
  770. if i<>0 then
  771. AsmWrite(',');
  772. AsmWrite(tostr(t64bitarray(d)[i]));
  773. end;
  774. end;
  775. AsmLn;
  776. end;
  777. // ait_real_32bit :
  778. // AsmWriteLn(#9#9'DD'#9+single2str(tai_real_32bit(hp).value));
  779. ait_real_32bit :
  780. begin
  781. if do_line then
  782. AsmWriteLn(target_asm.comment+'value: '+single2str(tai_real_32bit(hp).value));
  783. sin:=tai_real_32bit(hp).value;
  784. { swap the values to correct endian if required }
  785. if source_info.endian <> target_info.endian then
  786. swap32bitarray(t32bitarray(sin));
  787. AsmWrite(#9#9'DB'#9);
  788. for i:=0 to 3 do
  789. begin
  790. if i<>0 then
  791. AsmWrite(',');
  792. AsmWrite(tostr(t32bitarray(sin)[i]));
  793. end;
  794. AsmLn;
  795. end;
  796. // ait_comp_64bit :
  797. // AsmWriteLn(#9#9'DQ'#9+comp2str(tai_real_80bit(hp).value));
  798. ait_comp_64bit :
  799. begin
  800. if do_line then
  801. AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_comp_64bit(hp).value));
  802. AsmWrite(#9#9'DB'#9);
  803. co:=comp(tai_comp_64bit(hp).value);
  804. { swap the values to correct endian if required }
  805. if source_info.endian <> target_info.endian then
  806. swap64bitarray(t64bitarray(co));
  807. for i:=0 to 7 do
  808. begin
  809. if i<>0 then
  810. AsmWrite(',');
  811. AsmWrite(tostr(t64bitarray(co)[i]));
  812. end;
  813. AsmLn;
  814. end;
  815. ait_string :
  816. begin
  817. counter := 0;
  818. lines := tai_string(hp).len div line_length;
  819. { separate lines in different parts }
  820. if tai_string(hp).len > 0 then
  821. Begin
  822. for j := 0 to lines-1 do
  823. begin
  824. AsmWrite(#9#9'DB'#9);
  825. quoted:=false;
  826. for i:=counter to counter+line_length-1 do
  827. begin
  828. { it is an ascii character. }
  829. if (ord(tai_string(hp).str[i])>31) and
  830. (ord(tai_string(hp).str[i])<128) and
  831. (tai_string(hp).str[i]<>'"') then
  832. begin
  833. if not(quoted) then
  834. begin
  835. if i>counter then
  836. AsmWrite(',');
  837. AsmWrite('"');
  838. end;
  839. AsmWrite(tai_string(hp).str[i]);
  840. quoted:=true;
  841. end { if > 31 and < 128 and ord('"') }
  842. else
  843. begin
  844. if quoted then
  845. AsmWrite('"');
  846. if i>counter then
  847. AsmWrite(',');
  848. quoted:=false;
  849. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  850. end;
  851. end; { end for i:=0 to... }
  852. if quoted then AsmWrite('"');
  853. AsmWrite(target_info.newline);
  854. inc(counter,line_length);
  855. end; { end for j:=0 ... }
  856. { do last line of lines }
  857. if counter<tai_string(hp).len then
  858. AsmWrite(#9#9'DB'#9);
  859. quoted:=false;
  860. for i:=counter to tai_string(hp).len-1 do
  861. begin
  862. { it is an ascii character. }
  863. if (ord(tai_string(hp).str[i])>31) and
  864. (ord(tai_string(hp).str[i])<128) and
  865. (tai_string(hp).str[i]<>'"') then
  866. begin
  867. if not(quoted) then
  868. begin
  869. if i>counter then
  870. AsmWrite(',');
  871. AsmWrite('"');
  872. end;
  873. AsmWrite(tai_string(hp).str[i]);
  874. quoted:=true;
  875. end { if > 31 and < 128 and " }
  876. else
  877. begin
  878. if quoted then
  879. AsmWrite('"');
  880. if i>counter then
  881. AsmWrite(',');
  882. quoted:=false;
  883. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  884. end;
  885. end; { end for i:=0 to... }
  886. if quoted then
  887. AsmWrite('"');
  888. end;
  889. AsmLn;
  890. end;
  891. ait_label :
  892. begin
  893. if tai_label(hp).labsym.is_used then
  894. begin
  895. if SmartAsm and (tai_label(hp).labsym.bind=AB_GLOBAL) then
  896. begin
  897. AsmWrite(#9'GLOBAL ');
  898. AsmWriteLn(tai_label(hp).labsym.name);
  899. end;
  900. AsmWriteLn(tai_label(hp).labsym.name+':');
  901. end;
  902. if SmartAsm then
  903. AddSymbol(tai_label(hp).labsym.name,true);
  904. end;
  905. ait_symbol :
  906. begin
  907. if tai_symbol(hp).has_value then
  908. internalerror(2009090803);
  909. if tai_symbol(hp).is_global or SmartAsm then
  910. begin
  911. AsmWrite(#9'GLOBAL ');
  912. AsmWriteLn(tai_symbol(hp).sym.name);
  913. end;
  914. AsmWrite(tai_symbol(hp).sym.name);
  915. if SmartAsm then
  916. AddSymbol(tai_symbol(hp).sym.name,true);
  917. if assigned(hp.next) and not(tai(hp.next).typ in
  918. [ait_const,
  919. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
  920. AsmWriteLn(':')
  921. end;
  922. ait_symbol_end : ;
  923. ait_instruction :
  924. begin
  925. fixed_opcode:=taicpu(hp).FixNonCommutativeOpcodes;
  926. { We need intel order, no At&t }
  927. taicpu(hp).SetOperandOrder(op_intel);
  928. { LOCK must be on same line as opcode }
  929. if (taicpu(hp).ops = 0) and
  930. (fixed_opcode = A_LOCK) then
  931. SkipNewLine:=true
  932. else
  933. SkipNewLine:=false;
  934. s:='';
  935. if ((fixed_opcode=A_FADDP) or
  936. (fixed_opcode=A_FMULP))
  937. and (taicpu(hp).ops=0) then
  938. begin
  939. taicpu(hp).allocate_oper(2);
  940. taicpu(hp).oper[0]^.typ:=top_reg;
  941. taicpu(hp).oper[0]^.reg:=NR_ST1;
  942. taicpu(hp).oper[1]^.typ:=top_reg;
  943. taicpu(hp).oper[1]^.reg:=NR_ST;
  944. end;
  945. { NASM only accepts move for loading of
  946. simple symbol address }
  947. if ((taicpu(hp).opcode=A_LEA) and
  948. (taicpu(hp).ops=2) and
  949. (taicpu(hp).oper[0]^.typ=top_reg) and
  950. (reg2opsize(taicpu(hp).oper[0]^.reg) in [S_NO,S_Q]) and
  951. (taicpu(hp).oper[1]^.typ=top_ref) and
  952. (taicpu(hp).oper[1]^.ref^.refaddr<>addr_no) and
  953. assigned(taicpu(hp).oper[1]^.ref^.symbol) and
  954. (taicpu(hp).oper[1]^.ref^.base=NR_NO)) then
  955. begin
  956. AsmWrite(target_asm.comment);
  957. AsmWriteln('Converting LEA to MOV instruction');
  958. taicpu(hp).opcode:=A_MOV;
  959. end;
  960. if fixed_opcode=A_FWAIT then
  961. AsmWriteln(#9#9'DB'#9'09bh')
  962. else
  963. begin
  964. prefix:='';
  965. {$ifdef i8086}
  966. { nickysn note: I don't know if the 187 requires FWAIT before
  967. every instruction like the 8087, so I'm including it just in case }
  968. if (current_settings.cputype<=cpu_186) and
  969. requires_fwait_on_8087(fixed_opcode) then
  970. prefix:='wait '+prefix;
  971. {$endif i8086}
  972. {$ifndef i8086}
  973. { We need to explicitely set
  974. word prefix to get selectors
  975. to be pushed in 2 bytes PM }
  976. if (taicpu(hp).opsize=S_W) and
  977. ((fixed_opcode=A_PUSH) or
  978. (fixed_opcode=A_POP)) and
  979. (taicpu(hp).oper[0]^.typ=top_reg) and
  980. (is_segment_reg(taicpu(hp).oper[0]^.reg)) then
  981. AsmWriteln(#9#9'DB'#9'066h');
  982. {$endif not i8086}
  983. AsmWrite(#9#9+prefix+std_op2str[fixed_opcode]+cond2str[taicpu(hp).condition]);
  984. if taicpu(hp).ops<>0 then
  985. begin
  986. if is_calljmp(fixed_opcode) then
  987. begin
  988. AsmWrite(#9);
  989. WriteOper_jmp(taicpu(hp).oper[0]^,taicpu(hp));
  990. end
  991. else
  992. begin
  993. for i:=0 to taicpu(hp).ops-1 do
  994. begin
  995. if i=0 then
  996. AsmWrite(#9)
  997. else
  998. AsmWrite(',');
  999. WriteOper(taicpu(hp).oper[i]^,taicpu(hp).opsize,fixed_opcode,taicpu(hp).ops,(i=2));
  1000. end;
  1001. end;
  1002. end;
  1003. if not SkipNewLine then
  1004. AsmLn;
  1005. end;
  1006. end;
  1007. ait_stab,
  1008. ait_force_line,
  1009. ait_function_name : ;
  1010. ait_cutobject :
  1011. begin
  1012. if SmartAsm then
  1013. begin
  1014. { only reset buffer if nothing has changed }
  1015. if AsmSize=AsmStartSize then
  1016. AsmClear
  1017. else
  1018. begin
  1019. if SmartAsm then
  1020. begin
  1021. WriteSmartExternals;
  1022. FreeExternChainList;
  1023. end;
  1024. AsmClose;
  1025. DoAssemble;
  1026. AsmCreate(tai_cutobject(hp).place);
  1027. WriteHeader;
  1028. end;
  1029. { avoid empty files }
  1030. LastSecType:=sec_none;
  1031. LastSecName:='';
  1032. while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
  1033. begin
  1034. if tai(hp.next).typ=ait_section then
  1035. begin
  1036. LastSecType:=tai_section(hp.next).sectype;
  1037. LastSecName:=tai_section(hp.next).name^;
  1038. end;
  1039. hp:=tai(hp.next);
  1040. end;
  1041. if LastSecType<>sec_none then
  1042. WriteSection(LastSecType,LastSecName);
  1043. AsmStartSize:=AsmSize;
  1044. end;
  1045. end;
  1046. ait_marker :
  1047. if tai_marker(hp).kind=mark_NoLineInfoStart then
  1048. inc(InlineLevel)
  1049. else if tai_marker(hp).kind=mark_NoLineInfoEnd then
  1050. dec(InlineLevel);
  1051. ait_directive :
  1052. begin
  1053. case tai_directive(hp).directive of
  1054. asd_nasm_import :
  1055. AsmWrite('import ');
  1056. asd_extern :
  1057. AsmWrite('EXTERN ');
  1058. else
  1059. internalerror(200509191);
  1060. end;
  1061. if tai_directive(hp).name<>'' then
  1062. begin
  1063. if SmartAsm then
  1064. AddSymbol(tai_directive(hp).name,false);
  1065. AsmWrite(tai_directive(hp).name);
  1066. end;
  1067. AsmLn;
  1068. end;
  1069. ait_seh_directive :
  1070. { Ignore for now };
  1071. ait_varloc:
  1072. begin
  1073. if tai_varloc(hp).newlocationhi<>NR_NO then
  1074. AsmWriteLn(target_asm.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1075. std_regname(tai_varloc(hp).newlocationhi)+':'+std_regname(tai_varloc(hp).newlocation))
  1076. else
  1077. AsmWriteLn(target_asm.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1078. std_regname(tai_varloc(hp).newlocation));
  1079. end;
  1080. else
  1081. internalerror(10000);
  1082. end;
  1083. hp:=tai(hp.next);
  1084. end;
  1085. end;
  1086. procedure TX86NasmAssembler.WriteExternals;
  1087. var
  1088. sym : TAsmSymbol;
  1089. i : longint;
  1090. begin
  1091. for i:=0 to current_asmdata.AsmSymbolDict.Count-1 do
  1092. begin
  1093. sym:=TAsmSymbol(current_asmdata.AsmSymbolDict[i]);
  1094. if sym.bind=AB_EXTERNAL then
  1095. AsmWriteln('EXTERN'#9+sym.name);
  1096. end;
  1097. end;
  1098. procedure TX86NasmAssembler.WriteSmartExternals;
  1099. var
  1100. EC : PExternChain;
  1101. begin
  1102. EC:=FEC;
  1103. while assigned(EC) do
  1104. begin
  1105. if not EC^.is_defined then
  1106. AsmWriteln('EXTERN'#9+EC^.psym^);
  1107. EC:=EC^.next;
  1108. end;
  1109. end;
  1110. procedure TX86NasmAssembler.WriteHeader;
  1111. begin
  1112. {$ifdef i8086}
  1113. AsmWriteLn('BITS 16');
  1114. case current_settings.cputype of
  1115. cpu_8086: AsmWriteLn('CPU 8086');
  1116. cpu_186: AsmWriteLn('CPU 186');
  1117. cpu_286: AsmWriteLn('CPU 286');
  1118. cpu_386: AsmWriteLn('CPU 386');
  1119. cpu_Pentium: AsmWriteLn('CPU PENTIUM');
  1120. cpu_Pentium2: AsmWriteLn('CPU P2');
  1121. cpu_Pentium3: AsmWriteLn('CPU P3');
  1122. cpu_Pentium4: AsmWriteLn('CPU P4');
  1123. cpu_PentiumM: AsmWriteLn('CPU P4');
  1124. else
  1125. internalerror(2013050101);
  1126. end;
  1127. if not (cs_huge_code in current_settings.moduleswitches) then
  1128. AsmWriteLn('SECTION ' + CodeSectionName(current_module.modulename^) + ' use16 class=code');
  1129. { NASM complains if you put a missing section in the GROUP directive, so }
  1130. { we add empty declarations to make sure they exist, even if empty }
  1131. AsmWriteLn('SECTION .rodata class=data');
  1132. AsmWriteLn('SECTION .data class=data');
  1133. AsmWriteLn('SECTION .fpc class=data');
  1134. { WLINK requires class=bss in order to leave the BSS section out of the executable }
  1135. AsmWriteLn('SECTION .bss class=bss');
  1136. if current_settings.x86memorymodel<>mm_tiny then
  1137. AsmWriteLn('SECTION stack stack class=stack align=16');
  1138. { group these sections in the same segment }
  1139. if current_settings.x86memorymodel=mm_tiny then
  1140. AsmWriteLn('GROUP dgroup text rodata data fpc bss')
  1141. else
  1142. AsmWriteLn('GROUP dgroup rodata data fpc bss stack');
  1143. if paratargetdbg in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4] then
  1144. begin
  1145. AsmWriteLn('SECTION .debug_frame use32 class=DWARF');
  1146. AsmWriteLn('SECTION .debug_info use32 class=DWARF');
  1147. AsmWriteLn('SECTION .debug_line use32 class=DWARF');
  1148. AsmWriteLn('SECTION .debug_abbrev use32 class=DWARF');
  1149. end;
  1150. if not (cs_huge_code in current_settings.moduleswitches) then
  1151. AsmWriteLn('SECTION ' + CodeSectionName(current_module.modulename^));
  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.