agx86nsm.pas 49 KB

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