agx86nsm.pas 49 KB

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