agx86nsm.pas 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562
  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. (opcode = A_LES) or (opcode = A_LDS) or
  363. // (opcode = A_SHR) or (opcode = A_SHL) or
  364. // (opcode = A_SAR) or (opcode = A_SAL) or
  365. (opcode = A_OUT) or (opcode = A_IN)) then
  366. AsmWrite(sizestr(s,dest));
  367. WriteReference(o.ref^);
  368. end
  369. {$ifdef i8086}
  370. else if o.ref^.refaddr=addr_dgroup then
  371. begin
  372. AsmWrite('dgroup');
  373. end
  374. {$endif i8086}
  375. else
  376. begin
  377. {$ifdef x86_64}
  378. if s=S_L then
  379. asmwrite('dword ')
  380. else
  381. asmwrite('qword ');
  382. {$endif}
  383. {$ifdef i386}
  384. asmwrite('dword ');
  385. {$endif i386}
  386. {$ifdef i8086}
  387. if o.ref^.refaddr=addr_seg then
  388. asmwrite('SEG ')
  389. else
  390. asmwrite('word ');
  391. {$endif i8086}
  392. if assigned(o.ref^.symbol) then
  393. begin
  394. if SmartAsm then
  395. AddSymbol(o.ref^.symbol.name,false);
  396. asmwrite(o.ref^.symbol.name);
  397. if o.ref^.offset=0 then
  398. exit;
  399. end;
  400. if o.ref^.offset>0 then
  401. asmwrite('+');
  402. asmwrite(tostr(o.ref^.offset));
  403. end;
  404. end;
  405. else
  406. internalerror(10001);
  407. end;
  408. end;
  409. procedure TX86NasmAssembler.WriteOper_jmp(const o:toper; ai : taicpu);
  410. begin
  411. case o.typ of
  412. top_reg :
  413. AsmWrite(nasm_regname(o.reg));
  414. top_ref :
  415. if o.ref^.refaddr=addr_no then
  416. begin
  417. if ai.opsize=S_FAR then
  418. AsmWrite('far ');
  419. WriteReference(o.ref^);
  420. end
  421. else
  422. begin
  423. if ai.opsize=S_FAR then
  424. AsmWrite('far ')
  425. else
  426. begin
  427. { NEAR forces NASM to emit near jumps, which are 386+ }
  428. {$ifndef i8086}
  429. if not(
  430. (ai.opcode=A_JCXZ) or (ai.opcode=A_JECXZ) or
  431. {$ifdef x86_64}
  432. (ai.opcode=A_JRCXZ) or
  433. {$endif x86_64}
  434. (ai.opcode=A_LOOP) or (ai.opcode=A_LOOPE) or
  435. (ai.opcode=A_LOOPNE) or (ai.opcode=A_LOOPNZ) or
  436. (ai.opcode=A_LOOPZ)
  437. ) then
  438. AsmWrite('NEAR ');
  439. {$endif i8086}
  440. end;
  441. AsmWrite(o.ref^.symbol.name);
  442. if SmartAsm then
  443. AddSymbol(o.ref^.symbol.name,false);
  444. if o.ref^.offset>0 then
  445. AsmWrite('+'+tostr(o.ref^.offset))
  446. else
  447. if o.ref^.offset<0 then
  448. AsmWrite(tostr(o.ref^.offset));
  449. end;
  450. top_const :
  451. AsmWrite(tostr(aint(o.val)));
  452. else
  453. internalerror(10001);
  454. end;
  455. end;
  456. const
  457. ait_const2str : array[aitconst_128bit..aitconst_64bit_unaligned] of string[30]=(
  458. #9'FIXME_128BIT'#9,#9'DQ'#9,#9'DD'#9,#9'DW'#9,#9'DB'#9,
  459. #9'FIXME_SLEB128BIT'#9,#9'FIXME_ULEB128BIT'#9,
  460. #9'RVA'#9,#9'SECREL32'#9,#9'FIXME_darwin_dwarf_delta64'#9,
  461. #9'FIXME_darwin_dwarf_delta32'#9,#9'FIXME_half16bit'#9,
  462. #9'DW'#9,#9'DD'#9,#9'FIXME_64BIT_UNALIGNED'#9
  463. );
  464. procedure TX86NasmAssembler.WriteSection(atype:TAsmSectiontype;const aname:string);
  465. const
  466. secnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
  467. '.text',
  468. '.data',
  469. '.data',
  470. '.rodata',
  471. '.bss',
  472. '.tbss',
  473. '.pdata',
  474. '.text','.data','.data','.data','.data',
  475. '.stab',
  476. '.stabstr',
  477. '.idata2','.idata4','.idata5','.idata6','.idata7','.edata',
  478. '.eh_frame',
  479. '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
  480. '.fpc',
  481. '',
  482. '.init',
  483. '.fini',
  484. '.objc_class',
  485. '.objc_meta_class',
  486. '.objc_cat_cls_meth',
  487. '.objc_cat_inst_meth',
  488. '.objc_protocol',
  489. '.objc_string_object',
  490. '.objc_cls_meth',
  491. '.objc_inst_meth',
  492. '.objc_cls_refs',
  493. '.objc_message_refs',
  494. '.objc_symbols',
  495. '.objc_category',
  496. '.objc_class_vars',
  497. '.objc_instance_vars',
  498. '.objc_module_info',
  499. '.objc_class_names',
  500. '.objc_meth_var_types',
  501. '.objc_meth_var_names',
  502. '.objc_selector_strs',
  503. '.objc_protocol_ext',
  504. '.objc_class_ext',
  505. '.objc_property',
  506. '.objc_image_info',
  507. '.objc_cstring_object',
  508. '.objc_sel_fixup',
  509. '__DATA,__objc_data',
  510. '__DATA,__objc_const',
  511. '.objc_superrefs',
  512. '__DATA, __datacoal_nt,coalesced',
  513. '.objc_classlist',
  514. '.objc_nlclasslist',
  515. '.objc_catlist',
  516. '.obcj_nlcatlist',
  517. '.objc_protolist'
  518. );
  519. begin
  520. AsmLn;
  521. AsmWrite('SECTION ');
  522. { go32v2 stub only loads .text and .data sections, and allocates space for .bss.
  523. Thus, data which normally goes into .rodata and .rodata_norel sections must
  524. end up in .data section }
  525. if (atype in [sec_rodata,sec_rodata_norel]) and
  526. (target_info.system=system_i386_go32v2) then
  527. AsmWrite('.data')
  528. else if (atype=sec_user) then
  529. AsmWrite(aname)
  530. else if (atype=sec_threadvar) and
  531. (target_info.system in (systems_windows+systems_wince)) then
  532. AsmWrite('.tls'#9'bss')
  533. else if secnames[atype]='.text' then
  534. AsmWrite(CodeSectionName(aname))
  535. else
  536. AsmWrite(secnames[atype]);
  537. if create_smartlink_sections and
  538. (atype<>sec_bss) and
  539. (aname<>'') then
  540. begin
  541. AsmWrite('.');
  542. AsmWrite(aname);
  543. end;
  544. AsmLn;
  545. LastSecType:=atype;
  546. end;
  547. procedure TX86NasmAssembler.WriteTree(p:TAsmList);
  548. {$ifdef cpuextended}
  549. type
  550. t80bitarray = array[0..9] of byte;
  551. {$endif cpuextended}
  552. var
  553. s : string;
  554. hp : tai;
  555. counter,
  556. lines,
  557. i,j,l : longint;
  558. InlineLevel : longint;
  559. consttype : taiconst_type;
  560. do_line, SkipNewLine,
  561. quoted : boolean;
  562. co : comp;
  563. sin : single;
  564. d : double;
  565. {$ifdef cpuextended}
  566. e : extended;
  567. {$endif cpuextended}
  568. fixed_opcode: TAsmOp;
  569. prefix, LastSecName : string;
  570. begin
  571. if not assigned(p) then
  572. exit;
  573. InlineLevel:=0;
  574. { lineinfo is only needed for al_procedures (PFV) }
  575. do_line:=(cs_asm_source in current_settings.globalswitches) or
  576. ((cs_lineinfo in current_settings.moduleswitches)
  577. and (p=current_asmdata.asmlists[al_procedures]));
  578. hp:=tai(p.first);
  579. while assigned(hp) do
  580. begin
  581. prefetch(pointer(hp.next)^);
  582. if not(hp.typ in SkipLineInfo) then
  583. begin
  584. current_filepos:=tailineinfo(hp).fileinfo;
  585. { no line info for inlined code }
  586. if do_line and (inlinelevel=0) then
  587. WriteSourceLine(hp as tailineinfo);
  588. end;
  589. case hp.typ of
  590. ait_comment :
  591. Begin
  592. AsmWrite(target_asm.comment);
  593. AsmWritePChar(tai_comment(hp).str);
  594. AsmLn;
  595. End;
  596. ait_regalloc :
  597. begin
  598. if (cs_asm_regalloc in current_settings.globalswitches) then
  599. AsmWriteLn(#9#9+target_asm.comment+'Register '+nasm_regname(tai_regalloc(hp).reg)+' '+
  600. regallocstr[tai_regalloc(hp).ratype]);
  601. end;
  602. ait_tempalloc :
  603. begin
  604. if (cs_asm_tempalloc in current_settings.globalswitches) then
  605. WriteTempalloc(tai_tempalloc(hp));
  606. end;
  607. ait_section :
  608. begin
  609. if tai_section(hp).sectype<>sec_none then
  610. WriteSection(tai_section(hp).sectype,tai_section(hp).name^);
  611. LastSecType:=tai_section(hp).sectype;
  612. end;
  613. ait_align :
  614. begin
  615. if (tai_align(hp).aligntype>1) then
  616. begin
  617. if (LastSecType=sec_bss) or (
  618. (LastSecType=sec_threadvar) and
  619. (target_info.system in (systems_windows+systems_wince))
  620. ) then
  621. AsmWriteLn(#9'ALIGNB '+tostr(tai_align(hp).aligntype))
  622. else
  623. AsmWriteLn(#9'ALIGN '+tostr(tai_align(hp).aligntype));
  624. end;
  625. end;
  626. ait_datablock :
  627. begin
  628. if tai_datablock(hp).is_global or SmartAsm then
  629. begin
  630. AsmWrite(#9'GLOBAL ');
  631. AsmWriteLn(tai_datablock(hp).sym.name);
  632. end;
  633. AsmWrite(PadTabs(tai_datablock(hp).sym.name,':'));
  634. if SmartAsm then
  635. AddSymbol(tai_datablock(hp).sym.name,true);
  636. AsmWriteLn('RESB'#9+tostr(tai_datablock(hp).size));
  637. end;
  638. ait_const:
  639. begin
  640. consttype:=tai_const(hp).consttype;
  641. case consttype of
  642. aitconst_64bit,
  643. aitconst_64bit_unaligned:
  644. begin
  645. if assigned(tai_const(hp).sym) then
  646. internalerror(200404292);
  647. AsmWrite(ait_const2str[aitconst_32bit]);
  648. AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  649. AsmWrite(',');
  650. AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  651. AsmLn;
  652. end;
  653. aitconst_uleb128bit,
  654. aitconst_sleb128bit,
  655. aitconst_128bit:
  656. begin
  657. AsmWriteLn(target_asm.comment+'Unsupported const type '+
  658. ait_const2str[consttype]);
  659. end;
  660. {$ifdef i8086}
  661. aitconst_farptr:
  662. begin
  663. AsmWrite(ait_const2str[aitconst_16bit]);
  664. if assigned(tai_const(hp).sym) then
  665. begin
  666. if SmartAsm then
  667. AddSymbol(tai_const(hp).sym.name,false);
  668. AsmWrite(tai_const(hp).sym.name);
  669. if tai_const(hp).value<>0 then
  670. AsmWrite(tostr_with_plus(tai_const(hp).value));
  671. AsmLn;
  672. AsmWrite(ait_const2str[aitconst_16bit]);
  673. AsmWrite('SEG ');
  674. AsmWrite(tai_const(hp).sym.name);
  675. end
  676. else
  677. AsmWrite(tostr(lo(longint(tai_const(hp).value)))+','+
  678. tostr(hi(longint(tai_const(hp).value))));
  679. AsmLn;
  680. end;
  681. {$endif i8086}
  682. aitconst_32bit,
  683. aitconst_16bit,
  684. aitconst_8bit,
  685. aitconst_rva_symbol,
  686. aitconst_secrel32_symbol,
  687. aitconst_16bit_unaligned,
  688. aitconst_32bit_unaligned:
  689. begin
  690. AsmWrite(ait_const2str[tai_const(hp).consttype]);
  691. l:=0;
  692. repeat
  693. if assigned(tai_const(hp).sym) then
  694. begin
  695. if SmartAsm then
  696. begin
  697. AddSymbol(tai_const(hp).sym.name,false);
  698. if assigned(tai_const(hp).endsym) then
  699. AddSymbol(tai_const(hp).endsym.name,false);
  700. end;
  701. if assigned(tai_const(hp).endsym) then
  702. s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
  703. else
  704. s:=tai_const(hp).sym.name;
  705. if tai_const(hp).value<>0 then
  706. s:=s+tostr_with_plus(tai_const(hp).value);
  707. end
  708. else
  709. s:=tostr(tai_const(hp).value);
  710. AsmWrite(s);
  711. inc(l,length(s));
  712. if (l>line_length) or
  713. (hp.next=nil) or
  714. (tai(hp.next).typ<>ait_const) or
  715. (tai_const(hp.next).consttype<>consttype) then
  716. break;
  717. hp:=tai(hp.next);
  718. AsmWrite(',');
  719. until false;
  720. AsmLn;
  721. end;
  722. else
  723. internalerror(200704252);
  724. end;
  725. end;
  726. {$if defined(cpuextended) and defined(FPC_HAS_TYPE_EXTENDED)}
  727. ait_real_80bit :
  728. begin
  729. if do_line then
  730. AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_real_80bit(hp).value));
  731. { Make sure e is a extended type, bestreal could be
  732. a different type (bestreal) !! (PFV) }
  733. e:=tai_real_80bit(hp).value;
  734. AsmWrite(#9#9'DB'#9);
  735. for i:=0 to 9 do
  736. begin
  737. if i<>0 then
  738. AsmWrite(',');
  739. AsmWrite(tostr(t80bitarray(e)[i]));
  740. end;
  741. for i:=11 to tai_real_80bit(hp).savesize do
  742. AsmWrite(',0');
  743. AsmLn;
  744. end;
  745. {$else cpuextended}
  746. ait_real_80bit :
  747. AsmWriteLn(#9#9'DT'#9+extended2str(tai_real_80bit(hp).value));
  748. {$endif cpuextended}
  749. // ait_real_64bit :
  750. // AsmWriteLn(#9#9'DQ'#9+double2str(tai_real_64bit(hp).value));
  751. ait_real_64bit :
  752. begin
  753. if do_line then
  754. AsmWriteLn(target_asm.comment+'value: '+double2str(tai_real_64bit(hp).value));
  755. d:=tai_real_64bit(hp).value;
  756. { swap the values to correct endian if required }
  757. if source_info.endian <> target_info.endian then
  758. swap64bitarray(t64bitarray(d));
  759. AsmWrite(#9#9'DB'#9);
  760. {$ifdef arm}
  761. if tai_real_64bit(hp).formatoptions=fo_hiloswapped then
  762. begin
  763. for i:=4 to 7 do
  764. begin
  765. if i<>4 then
  766. AsmWrite(',');
  767. AsmWrite(tostr(t64bitarray(d)[i]));
  768. end;
  769. for i:=0 to 3 do
  770. begin
  771. AsmWrite(',');
  772. AsmWrite(tostr(t64bitarray(d)[i]));
  773. end;
  774. end
  775. else
  776. {$endif arm}
  777. begin
  778. for i:=0 to 7 do
  779. begin
  780. if i<>0 then
  781. AsmWrite(',');
  782. AsmWrite(tostr(t64bitarray(d)[i]));
  783. end;
  784. end;
  785. AsmLn;
  786. end;
  787. // ait_real_32bit :
  788. // AsmWriteLn(#9#9'DD'#9+single2str(tai_real_32bit(hp).value));
  789. ait_real_32bit :
  790. begin
  791. if do_line then
  792. AsmWriteLn(target_asm.comment+'value: '+single2str(tai_real_32bit(hp).value));
  793. sin:=tai_real_32bit(hp).value;
  794. { swap the values to correct endian if required }
  795. if source_info.endian <> target_info.endian then
  796. swap32bitarray(t32bitarray(sin));
  797. AsmWrite(#9#9'DB'#9);
  798. for i:=0 to 3 do
  799. begin
  800. if i<>0 then
  801. AsmWrite(',');
  802. AsmWrite(tostr(t32bitarray(sin)[i]));
  803. end;
  804. AsmLn;
  805. end;
  806. // ait_comp_64bit :
  807. // AsmWriteLn(#9#9'DQ'#9+comp2str(tai_real_80bit(hp).value));
  808. ait_comp_64bit :
  809. begin
  810. if do_line then
  811. AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_comp_64bit(hp).value));
  812. AsmWrite(#9#9'DB'#9);
  813. co:=comp(tai_comp_64bit(hp).value);
  814. { swap the values to correct endian if required }
  815. if source_info.endian <> target_info.endian then
  816. swap64bitarray(t64bitarray(co));
  817. for i:=0 to 7 do
  818. begin
  819. if i<>0 then
  820. AsmWrite(',');
  821. AsmWrite(tostr(t64bitarray(co)[i]));
  822. end;
  823. AsmLn;
  824. end;
  825. ait_string :
  826. begin
  827. counter := 0;
  828. lines := tai_string(hp).len div line_length;
  829. { separate lines in different parts }
  830. if tai_string(hp).len > 0 then
  831. Begin
  832. for j := 0 to lines-1 do
  833. begin
  834. AsmWrite(#9#9'DB'#9);
  835. quoted:=false;
  836. for i:=counter to counter+line_length-1 do
  837. begin
  838. { it is an ascii character. }
  839. if (ord(tai_string(hp).str[i])>31) and
  840. (ord(tai_string(hp).str[i])<128) and
  841. (tai_string(hp).str[i]<>'"') then
  842. begin
  843. if not(quoted) then
  844. begin
  845. if i>counter then
  846. AsmWrite(',');
  847. AsmWrite('"');
  848. end;
  849. AsmWrite(tai_string(hp).str[i]);
  850. quoted:=true;
  851. end { if > 31 and < 128 and ord('"') }
  852. else
  853. begin
  854. if quoted then
  855. AsmWrite('"');
  856. if i>counter then
  857. AsmWrite(',');
  858. quoted:=false;
  859. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  860. end;
  861. end; { end for i:=0 to... }
  862. if quoted then AsmWrite('"');
  863. AsmWrite(target_info.newline);
  864. inc(counter,line_length);
  865. end; { end for j:=0 ... }
  866. { do last line of lines }
  867. if counter<tai_string(hp).len then
  868. AsmWrite(#9#9'DB'#9);
  869. quoted:=false;
  870. for i:=counter to tai_string(hp).len-1 do
  871. begin
  872. { it is an ascii character. }
  873. if (ord(tai_string(hp).str[i])>31) and
  874. (ord(tai_string(hp).str[i])<128) and
  875. (tai_string(hp).str[i]<>'"') then
  876. begin
  877. if not(quoted) then
  878. begin
  879. if i>counter then
  880. AsmWrite(',');
  881. AsmWrite('"');
  882. end;
  883. AsmWrite(tai_string(hp).str[i]);
  884. quoted:=true;
  885. end { if > 31 and < 128 and " }
  886. else
  887. begin
  888. if quoted then
  889. AsmWrite('"');
  890. if i>counter then
  891. AsmWrite(',');
  892. quoted:=false;
  893. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  894. end;
  895. end; { end for i:=0 to... }
  896. if quoted then
  897. AsmWrite('"');
  898. end;
  899. AsmLn;
  900. end;
  901. ait_label :
  902. begin
  903. if tai_label(hp).labsym.is_used then
  904. begin
  905. if SmartAsm and (tai_label(hp).labsym.bind=AB_GLOBAL) then
  906. begin
  907. AsmWrite(#9'GLOBAL ');
  908. AsmWriteLn(tai_label(hp).labsym.name);
  909. end;
  910. AsmWriteLn(tai_label(hp).labsym.name+':');
  911. end;
  912. if SmartAsm then
  913. AddSymbol(tai_label(hp).labsym.name,true);
  914. end;
  915. ait_symbol :
  916. begin
  917. if tai_symbol(hp).has_value then
  918. internalerror(2009090803);
  919. if tai_symbol(hp).is_global or SmartAsm then
  920. begin
  921. AsmWrite(#9'GLOBAL ');
  922. AsmWriteLn(tai_symbol(hp).sym.name);
  923. end;
  924. AsmWrite(tai_symbol(hp).sym.name);
  925. if SmartAsm then
  926. AddSymbol(tai_symbol(hp).sym.name,true);
  927. if assigned(hp.next) and not(tai(hp.next).typ in
  928. [ait_const,
  929. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
  930. AsmWriteLn(':')
  931. end;
  932. ait_symbol_end : ;
  933. ait_instruction :
  934. begin
  935. fixed_opcode:=taicpu(hp).FixNonCommutativeOpcodes;
  936. { We need intel order, no At&t }
  937. taicpu(hp).SetOperandOrder(op_intel);
  938. { LOCK must be on same line as opcode }
  939. if (taicpu(hp).ops = 0) and
  940. (fixed_opcode = A_LOCK) then
  941. SkipNewLine:=true
  942. else
  943. SkipNewLine:=false;
  944. s:='';
  945. if ((fixed_opcode=A_FADDP) or
  946. (fixed_opcode=A_FMULP))
  947. and (taicpu(hp).ops=0) then
  948. begin
  949. taicpu(hp).allocate_oper(2);
  950. taicpu(hp).oper[0]^.typ:=top_reg;
  951. taicpu(hp).oper[0]^.reg:=NR_ST1;
  952. taicpu(hp).oper[1]^.typ:=top_reg;
  953. taicpu(hp).oper[1]^.reg:=NR_ST;
  954. end;
  955. { NASM only accepts move for loading of
  956. simple symbol address }
  957. if ((taicpu(hp).opcode=A_LEA) and
  958. (taicpu(hp).ops=2) and
  959. (taicpu(hp).oper[0]^.typ=top_reg) and
  960. (reg2opsize(taicpu(hp).oper[0]^.reg) in [S_NO,S_Q]) and
  961. (taicpu(hp).oper[1]^.typ=top_ref) and
  962. (taicpu(hp).oper[1]^.ref^.refaddr<>addr_no) and
  963. assigned(taicpu(hp).oper[1]^.ref^.symbol) and
  964. (taicpu(hp).oper[1]^.ref^.base=NR_NO)) then
  965. begin
  966. AsmWrite(target_asm.comment);
  967. AsmWriteln('Converting LEA to MOV instruction');
  968. taicpu(hp).opcode:=A_MOV;
  969. end;
  970. if fixed_opcode=A_FWAIT then
  971. AsmWriteln(#9#9'DB'#9'09bh')
  972. else
  973. begin
  974. prefix:='';
  975. {$ifdef i8086}
  976. { nickysn note: I don't know if the 187 requires FWAIT before
  977. every instruction like the 8087, so I'm including it just in case }
  978. if (current_settings.cputype<=cpu_186) and
  979. requires_fwait_on_8087(fixed_opcode) then
  980. prefix:='wait '+prefix;
  981. {$endif i8086}
  982. {$ifndef i8086}
  983. { We need to explicitely set
  984. word prefix to get selectors
  985. to be pushed in 2 bytes PM }
  986. if (taicpu(hp).opsize=S_W) and
  987. ((fixed_opcode=A_PUSH) or
  988. (fixed_opcode=A_POP)) and
  989. (taicpu(hp).oper[0]^.typ=top_reg) and
  990. (is_segment_reg(taicpu(hp).oper[0]^.reg)) then
  991. AsmWriteln(#9#9'DB'#9'066h');
  992. {$endif not i8086}
  993. AsmWrite(#9#9+prefix+std_op2str[fixed_opcode]+cond2str[taicpu(hp).condition]);
  994. if taicpu(hp).ops<>0 then
  995. begin
  996. if is_calljmp(fixed_opcode) then
  997. begin
  998. AsmWrite(#9);
  999. WriteOper_jmp(taicpu(hp).oper[0]^,taicpu(hp));
  1000. end
  1001. else
  1002. begin
  1003. for i:=0 to taicpu(hp).ops-1 do
  1004. begin
  1005. if i=0 then
  1006. AsmWrite(#9)
  1007. else
  1008. AsmWrite(',');
  1009. WriteOper(taicpu(hp).oper[i]^,taicpu(hp).opsize,fixed_opcode,taicpu(hp).ops,(i=2));
  1010. end;
  1011. end;
  1012. end;
  1013. if not SkipNewLine then
  1014. AsmLn;
  1015. end;
  1016. end;
  1017. ait_stab,
  1018. ait_force_line,
  1019. ait_function_name : ;
  1020. ait_cutobject :
  1021. begin
  1022. if SmartAsm then
  1023. begin
  1024. { only reset buffer if nothing has changed }
  1025. if AsmSize=AsmStartSize then
  1026. AsmClear
  1027. else
  1028. begin
  1029. if SmartAsm then
  1030. begin
  1031. WriteSmartExternals;
  1032. FreeExternChainList;
  1033. end;
  1034. AsmClose;
  1035. DoAssemble;
  1036. AsmCreate(tai_cutobject(hp).place);
  1037. WriteHeader;
  1038. end;
  1039. { avoid empty files }
  1040. LastSecType:=sec_none;
  1041. LastSecName:='';
  1042. while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
  1043. begin
  1044. if tai(hp.next).typ=ait_section then
  1045. begin
  1046. LastSecType:=tai_section(hp.next).sectype;
  1047. LastSecName:=tai_section(hp.next).name^;
  1048. end;
  1049. hp:=tai(hp.next);
  1050. end;
  1051. if LastSecType<>sec_none then
  1052. WriteSection(LastSecType,LastSecName);
  1053. AsmStartSize:=AsmSize;
  1054. end;
  1055. end;
  1056. ait_marker :
  1057. if tai_marker(hp).kind=mark_NoLineInfoStart then
  1058. inc(InlineLevel)
  1059. else if tai_marker(hp).kind=mark_NoLineInfoEnd then
  1060. dec(InlineLevel);
  1061. ait_directive :
  1062. begin
  1063. case tai_directive(hp).directive of
  1064. asd_nasm_import :
  1065. AsmWrite('import ');
  1066. asd_extern :
  1067. AsmWrite('EXTERN ');
  1068. else
  1069. internalerror(200509191);
  1070. end;
  1071. if tai_directive(hp).name<>'' then
  1072. begin
  1073. if SmartAsm then
  1074. AddSymbol(tai_directive(hp).name,false);
  1075. AsmWrite(tai_directive(hp).name);
  1076. end;
  1077. AsmLn;
  1078. end;
  1079. ait_seh_directive :
  1080. { Ignore for now };
  1081. ait_varloc:
  1082. begin
  1083. if tai_varloc(hp).newlocationhi<>NR_NO then
  1084. AsmWriteLn(target_asm.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1085. std_regname(tai_varloc(hp).newlocationhi)+':'+std_regname(tai_varloc(hp).newlocation))
  1086. else
  1087. AsmWriteLn(target_asm.comment+'Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1088. std_regname(tai_varloc(hp).newlocation));
  1089. end;
  1090. else
  1091. internalerror(10000);
  1092. end;
  1093. hp:=tai(hp.next);
  1094. end;
  1095. end;
  1096. procedure TX86NasmAssembler.WriteExternals;
  1097. var
  1098. sym : TAsmSymbol;
  1099. i : longint;
  1100. begin
  1101. for i:=0 to current_asmdata.AsmSymbolDict.Count-1 do
  1102. begin
  1103. sym:=TAsmSymbol(current_asmdata.AsmSymbolDict[i]);
  1104. if sym.bind=AB_EXTERNAL then
  1105. AsmWriteln('EXTERN'#9+sym.name);
  1106. end;
  1107. end;
  1108. procedure TX86NasmAssembler.WriteSmartExternals;
  1109. var
  1110. EC : PExternChain;
  1111. begin
  1112. EC:=FEC;
  1113. while assigned(EC) do
  1114. begin
  1115. if not EC^.is_defined then
  1116. AsmWriteln('EXTERN'#9+EC^.psym^);
  1117. EC:=EC^.next;
  1118. end;
  1119. end;
  1120. procedure TX86NasmAssembler.WriteHeader;
  1121. begin
  1122. {$ifdef i8086}
  1123. AsmWriteLn('BITS 16');
  1124. case current_settings.cputype of
  1125. cpu_8086: AsmWriteLn('CPU 8086');
  1126. cpu_186: AsmWriteLn('CPU 186');
  1127. cpu_286: AsmWriteLn('CPU 286');
  1128. cpu_386: AsmWriteLn('CPU 386');
  1129. cpu_Pentium: AsmWriteLn('CPU PENTIUM');
  1130. cpu_Pentium2: AsmWriteLn('CPU P2');
  1131. cpu_Pentium3: AsmWriteLn('CPU P3');
  1132. cpu_Pentium4: AsmWriteLn('CPU P4');
  1133. cpu_PentiumM: AsmWriteLn('CPU P4');
  1134. else
  1135. internalerror(2013050101);
  1136. end;
  1137. AsmWriteLn('SECTION ' + CodeSectionName(current_module.modulename^) + ' use16 class=code');
  1138. { NASM complains if you put a missing section in the GROUP directive, so }
  1139. { we add empty declarations to make sure they exist, even if empty }
  1140. AsmWriteLn('SECTION .rodata');
  1141. AsmWriteLn('SECTION .data');
  1142. AsmWriteLn('SECTION .fpc');
  1143. { WLINK requires class=bss in order to leave the BSS section out of the executable }
  1144. AsmWriteLn('SECTION .bss class=bss');
  1145. { group these sections in the same segment }
  1146. if current_settings.x86memorymodel=mm_tiny then
  1147. AsmWriteLn('GROUP dgroup text rodata data fpc bss')
  1148. else
  1149. AsmWriteLn('GROUP dgroup rodata data fpc bss');
  1150. if paratargetdbg in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4] then
  1151. begin
  1152. AsmWriteLn('SECTION .debug_frame use32 class=DWARF');
  1153. AsmWriteLn('SECTION .debug_info use32 class=DWARF');
  1154. AsmWriteLn('SECTION .debug_line use32 class=DWARF');
  1155. AsmWriteLn('SECTION .debug_abbrev use32 class=DWARF');
  1156. end;
  1157. AsmWriteLn('SECTION ' + CodeSectionName(current_module.modulename^));
  1158. {$else i8086}
  1159. {$ifdef i386}
  1160. AsmWriteLn('BITS 32');
  1161. using_relative:=false;
  1162. {$else not i386}
  1163. AsmWriteLn('BITS 64');
  1164. AsmWriteLn('default rel');
  1165. using_relative:=true;
  1166. {$endif not i386}
  1167. {$endif i8086}
  1168. end;
  1169. procedure TX86NasmAssembler.WriteAsmList;
  1170. var
  1171. hal : tasmlisttype;
  1172. begin
  1173. {$ifdef EXTDEBUG}
  1174. if current_module.mainsource<>'' then
  1175. comment(v_info,'Start writing nasm-styled assembler output for '+current_module.mainsource);
  1176. {$endif}
  1177. WriteHeader;
  1178. AsmLn;
  1179. WriteExternals;
  1180. for hal:=low(TasmlistType) to high(TasmlistType) do
  1181. begin
  1182. if not (current_asmdata.asmlists[hal].empty) then
  1183. begin
  1184. AsmWriteLn(target_asm.comment+'Begin asmlist '+AsmListTypeStr[hal]);
  1185. writetree(current_asmdata.asmlists[hal]);
  1186. AsmWriteLn(target_asm.comment+'End asmlist '+AsmListTypeStr[hal]);
  1187. end;
  1188. end;
  1189. AsmLn;
  1190. if SmartAsm then
  1191. begin
  1192. WriteSmartExternals;
  1193. FreeExternChainList;
  1194. end;
  1195. {$ifdef EXTDEBUG}
  1196. if current_module.mainsource<>'' then
  1197. comment(v_info,'Done writing nasm-styled assembler output for '+current_module.mainsource);
  1198. {$endif EXTDEBUG}
  1199. end;
  1200. function TX86NasmAssembler.MakeCmdLine: TCmdStr;
  1201. var
  1202. FormatName : string;
  1203. begin
  1204. result:=Inherited MakeCmdLine;
  1205. {$ifdef i8086}
  1206. case target_info.system of
  1207. system_i8086_msdos:
  1208. FormatName:='obj';
  1209. end;
  1210. {$endif i8086}
  1211. {$ifdef i386}
  1212. case target_info.system of
  1213. system_i386_go32v2:
  1214. FormatName:='coff';
  1215. system_i386_wdosx,
  1216. system_i386_win32:
  1217. FormatName:='win32';
  1218. system_i386_embedded:
  1219. FormatName:='obj';
  1220. system_i386_linux,
  1221. system_i386_beos:
  1222. FormatName:='elf';
  1223. system_i386_darwin:
  1224. FormatName:='macho32';
  1225. else
  1226. FormatName:='elf';
  1227. end;
  1228. {$endif i386}
  1229. {$ifdef x86_64}
  1230. case target_info.system of
  1231. system_x86_64_win64:
  1232. FormatName:='win64';
  1233. system_x86_64_darwin:
  1234. FormatName:='macho64';
  1235. system_x86_64_linux:
  1236. FormatName:='elf64';
  1237. else
  1238. FormatName:='elf64';
  1239. end;
  1240. {$endif x86_64}
  1241. Replace(result,'$FORMAT',FormatName);
  1242. end;
  1243. {*****************************************************************************
  1244. Initialize
  1245. *****************************************************************************}
  1246. {$ifdef i8086}
  1247. const
  1248. as_i8086_nasm_info : tasminfo =
  1249. (
  1250. id : as_i8086_nasm;
  1251. idtxt : 'NASM';
  1252. asmbin : 'nasm';
  1253. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1254. supported_targets : [system_i8086_msdos];
  1255. flags : [af_needar,af_no_debug];
  1256. labelprefix : '..@';
  1257. comment : '; ';
  1258. dollarsign: '$';
  1259. );
  1260. as_i8086_nasmobj_info : tasminfo =
  1261. (
  1262. id : as_i8086_nasmobj;
  1263. idtxt : 'NASMOBJ';
  1264. asmbin : 'nasm';
  1265. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1266. supported_targets : [system_i8086_msdos];
  1267. flags : [af_needar,af_no_debug];
  1268. labelprefix : '..@';
  1269. comment : '; ';
  1270. dollarsign: '$';
  1271. );
  1272. {$endif i8086}
  1273. {$ifdef i386}
  1274. const
  1275. as_i386_nasmcoff_info : tasminfo =
  1276. (
  1277. id : as_i386_nasmcoff;
  1278. idtxt : 'NASMCOFF';
  1279. asmbin : 'nasm';
  1280. asmcmd : '-f coff -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1281. supported_targets : [system_i386_go32v2];
  1282. flags : [af_needar,af_no_debug];
  1283. labelprefix : '..@';
  1284. comment : '; ';
  1285. dollarsign: '$';
  1286. );
  1287. as_i386_nasmwin32_info : tasminfo =
  1288. (
  1289. id : as_i386_nasmwin32;
  1290. idtxt : 'NASMWIN32';
  1291. asmbin : 'nasm';
  1292. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1293. supported_targets : [system_i386_win32];
  1294. flags : [af_needar,af_no_debug];
  1295. labelprefix : '..@';
  1296. comment : '; ';
  1297. dollarsign: '$';
  1298. );
  1299. as_i386_nasmobj_info : tasminfo =
  1300. (
  1301. id : as_i386_nasmobj;
  1302. idtxt : 'NASMOBJ';
  1303. asmbin : 'nasm';
  1304. asmcmd : '-f obj -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1305. supported_targets : [system_i386_embedded, system_i8086_msdos];
  1306. flags : [af_needar,af_no_debug];
  1307. labelprefix : '..@';
  1308. comment : '; ';
  1309. dollarsign: '$';
  1310. );
  1311. as_i386_nasmwdosx_info : tasminfo =
  1312. (
  1313. id : as_i386_nasmwdosx;
  1314. idtxt : 'NASMWDOSX';
  1315. asmbin : 'nasm';
  1316. asmcmd : '-f win32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1317. supported_targets : [system_i386_wdosx];
  1318. flags : [af_needar,af_no_debug];
  1319. labelprefix : '..@';
  1320. comment : '; ';
  1321. dollarsign: '$';
  1322. );
  1323. as_i386_nasmelf_info : tasminfo =
  1324. (
  1325. id : as_i386_nasmelf;
  1326. idtxt : 'NASMELF';
  1327. asmbin : 'nasm';
  1328. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1329. supported_targets : [system_i386_linux];
  1330. flags : [af_needar,af_no_debug];
  1331. labelprefix : '..@';
  1332. comment : '; ';
  1333. dollarsign: '$';
  1334. );
  1335. as_i386_nasmdarwin_info : tasminfo =
  1336. (
  1337. id : as_i386_nasmdarwin;
  1338. idtxt : 'NASMDARWIN';
  1339. asmbin : 'nasm';
  1340. asmcmd : '-f macho32 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1341. supported_targets : [system_i386_darwin];
  1342. flags : [af_needar,af_no_debug];
  1343. labelprefix : '..@';
  1344. comment : '; ';
  1345. dollarsign: '$';
  1346. );
  1347. as_i386_nasmbeos_info : tasminfo =
  1348. (
  1349. id : as_i386_nasmbeos;
  1350. idtxt : 'NASMELF';
  1351. asmbin : 'nasm';
  1352. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1353. supported_targets : [system_i386_beos];
  1354. flags : [af_needar,af_no_debug];
  1355. labelprefix : '..@';
  1356. comment : '; ';
  1357. dollarsign: '$';
  1358. );
  1359. as_i386_nasmhaiku_info : tasminfo =
  1360. (
  1361. id : as_i386_nasmhaiku;
  1362. idtxt : 'NASMELF';
  1363. asmbin : 'nasm';
  1364. asmcmd : '-f elf -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1365. supported_targets : [system_i386_haiku];
  1366. flags : [af_needar,af_no_debug];
  1367. labelprefix : '..@';
  1368. comment : '; ';
  1369. dollarsign: '$';
  1370. );
  1371. as_i386_nasm_info : tasminfo =
  1372. (
  1373. id : as_i386_nasm;
  1374. idtxt : 'NASM';
  1375. asmbin : 'nasm';
  1376. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1377. supported_targets : [system_any];
  1378. flags : [af_needar,af_no_debug];
  1379. labelprefix : '..@';
  1380. comment : '; ';
  1381. dollarsign: '$';
  1382. );
  1383. {$endif i386}
  1384. {$ifdef x86_64}
  1385. const
  1386. as_x86_64_nasm_info : tasminfo =
  1387. (
  1388. id : as_x86_64_nasm;
  1389. idtxt : 'NASM';
  1390. asmbin : 'nasm';
  1391. asmcmd : '-f $FORMAT -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1392. supported_targets : [system_any];
  1393. flags : [af_needar{,af_no_debug}];
  1394. labelprefix : '..@';
  1395. comment : '; ';
  1396. dollarsign: '$';
  1397. );
  1398. as_x86_64_nasmwin64_info : tasminfo =
  1399. (
  1400. id : as_x86_64_nasmwin64;
  1401. idtxt : 'NASMWIN64';
  1402. asmbin : 'nasm';
  1403. asmcmd : '-f win64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1404. supported_targets : [system_x86_64_win64];
  1405. flags : [af_needar,af_no_debug];
  1406. labelprefix : '..@';
  1407. comment : '; ';
  1408. dollarsign: '$';
  1409. );
  1410. as_x86_64_nasmelf_info : tasminfo =
  1411. (
  1412. id : as_x86_64_nasmelf;
  1413. idtxt : 'NASMELF';
  1414. asmbin : 'nasm';
  1415. asmcmd : '-f elf64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1416. supported_targets : [system_x86_64_linux];
  1417. flags : [af_needar,af_no_debug];
  1418. labelprefix : '..@';
  1419. comment : '; ';
  1420. dollarsign: '$';
  1421. );
  1422. as_x86_64_nasmdarwin_info : tasminfo =
  1423. (
  1424. id : as_x86_64_nasmdarwin;
  1425. idtxt : 'NASMDARWIN';
  1426. asmbin : 'nasm';
  1427. asmcmd : '-f macho64 -o $OBJ -w-orphan-labels $EXTRAOPT $ASM';
  1428. supported_targets : [system_x86_64_darwin];
  1429. flags : [af_needar,af_no_debug];
  1430. labelprefix : '..@';
  1431. comment : '; ';
  1432. dollarsign: '$';
  1433. );
  1434. {$endif x86_64}
  1435. initialization
  1436. {$ifdef i8086}
  1437. RegisterAssembler(as_i8086_nasm_info,TX86NasmAssembler);
  1438. RegisterAssembler(as_i8086_nasmobj_info,TX86NasmAssembler);
  1439. {$endif i8086}
  1440. {$ifdef i386}
  1441. RegisterAssembler(as_i386_nasmcoff_info,TX86NasmAssembler);
  1442. RegisterAssembler(as_i386_nasmwin32_info,TX86NasmAssembler);
  1443. RegisterAssembler(as_i386_nasmwdosx_info,TX86NasmAssembler);
  1444. RegisterAssembler(as_i386_nasmobj_info,TX86NasmAssembler);
  1445. RegisterAssembler(as_i386_nasmbeos_info,TX86NasmAssembler);
  1446. RegisterAssembler(as_i386_nasmhaiku_info,TX86NasmAssembler);
  1447. RegisterAssembler(as_i386_nasmelf_info,TX86NasmAssembler);
  1448. RegisterAssembler(as_i386_nasm_info,TX86NasmAssembler);
  1449. {$endif i386}
  1450. {$ifdef x86_64}
  1451. RegisterAssembler(as_x86_64_nasm_info,TX86NasmAssembler);
  1452. RegisterAssembler(as_x86_64_nasmwin64_info,TX86NasmAssembler);
  1453. RegisterAssembler(as_x86_64_nasmelf_info,TX86NasmAssembler);
  1454. RegisterAssembler(as_x86_64_nasmdarwin_info,TX86NasmAssembler);
  1455. {$endif x86_64}
  1456. end.