agppcgas.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit the GAS asm writers for PowerPC/PowerPC64
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. {****************************************************************************}
  18. { Helper routines for Instruction Writer }
  19. {****************************************************************************}
  20. unit agppcgas;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. systems,aasmbase,
  25. aasmtai,aasmdata,
  26. assemble,aggas,
  27. cpubase,cgutils,
  28. globtype;
  29. type
  30. TPPCInstrWriter=class(TCPUInstrWriter)
  31. procedure WriteInstruction(hp : tai);override;
  32. end;
  33. TPPCGNUAssembler=class(TGNUassembler)
  34. constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
  35. function MakeCmdLine: TCmdStr; override;
  36. procedure WriteExtraHeader; override;
  37. end;
  38. TPPCAppleGNUAssembler=class(TAppleGNUassembler)
  39. constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
  40. function MakeCmdLine: TCmdStr; override;
  41. end;
  42. TPPCAIXAssembler=class(TPPCGNUAssembler)
  43. max_alignment : array[TAsmSectionType] of longint;
  44. constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
  45. protected
  46. function sectionname(atype: TAsmSectiontype; const aname: string; aorder: TAsmSectionOrder): string; override;
  47. procedure WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder;secalign:longint;secflags:TSectionFlags=[];secprogbits:TSectionProgbits=SPB_None); override;
  48. procedure WriteAsmList; override;
  49. procedure WriteExtraHeader; override;
  50. procedure WriteExtraFooter; override;
  51. procedure WriteDirectiveName(dir: TAsmDirective); override;
  52. end;
  53. TPPCMacOSAssembler=class(TPPCGNUAssembler)
  54. function sectionname(atype: TAsmSectiontype; const aname: string; aorder: TAsmSectionOrder): string; override;
  55. end;
  56. topstr = string[4];
  57. function branchmode(o: tasmop): topstr;
  58. function cond2str(op: tasmop; c: tasmcond): string;
  59. implementation
  60. uses
  61. cutils,globals,verbose,
  62. cgbase,
  63. itcpugas,cpuinfo,
  64. aasmcpu;
  65. {$ifdef cpu64bitaddr}
  66. const
  67. refaddr2str: array[trefaddr] of string[9] = ('', '', '', '', '@l', '@h', '@higher', '@highest', '@ha', '@highera', '@highesta');
  68. verbose_refaddrs = [addr_low, addr_high, addr_higher, addr_highest, addr_higha, addr_highera, addr_highesta];
  69. refaddr2str_darwin: array[trefaddr] of string[4] = ('','','','','lo16', 'hi16', '@err', '@err', 'ha16', '@err', '@err');
  70. {$else cpu64bitaddr}
  71. const
  72. refaddr2str: array[trefaddr] of string[3] = ('','','','','@l','@h','@ha');
  73. refaddr2str_darwin: array[trefaddr] of string[4] = ('','','','','lo16','hi16','ha16');
  74. verbose_refaddrs = [addr_low,addr_high,addr_higha];
  75. {$endif cpu64bitaddr}
  76. function getreferencestring(asminfo: pasminfo; var ref : treference) : string;
  77. var
  78. s : string;
  79. begin
  80. with ref do
  81. begin
  82. case refaddr of
  83. addr_no:
  84. begin
  85. if (offset < -32768) or (offset > 32767) { or assigned(symbol) } then
  86. internalerror(2006052501);
  87. s:='';
  88. end;
  89. addr_pic_no_got:
  90. begin
  91. { used for TOC-based loads }
  92. if (base<>NR_RTOC) or
  93. (index<>NR_NO) or
  94. (offset<>0) or
  95. not assigned(symbol) then
  96. internalerror(2011122702);
  97. if asminfo^.dollarsign<>'$' then
  98. getreferencestring:=ApplyAsmSymbolRestrictions(symbol.name)+'('+gas_regname(NR_RTOC)+')'
  99. else
  100. getreferencestring:=symbol.name+'('+gas_regname(NR_RTOC)+')';
  101. exit;
  102. end
  103. else
  104. begin
  105. if target_info.system in [system_powerpc_darwin,system_powerpc64_darwin] then
  106. s := refaddr2str_darwin[refaddr]
  107. else
  108. s :='';
  109. s := s+'(';
  110. if assigned(symbol) then
  111. begin
  112. if asminfo^.dollarsign<>'$' then
  113. begin
  114. s:=s+ApplyAsmSymbolRestrictions(symbol.name);
  115. if assigned(relsymbol) then
  116. s:=s+'-'+ApplyAsmSymbolRestrictions(relsymbol.name)
  117. end
  118. else
  119. begin
  120. s:=s+symbol.name;
  121. if assigned(relsymbol) then
  122. s:=s+'-'+relsymbol.name;
  123. end;
  124. end;
  125. end;
  126. end;
  127. if offset<0 then
  128. s:=s+tostr(offset)
  129. else
  130. if (offset>0) then
  131. begin
  132. if assigned(symbol) then
  133. s:=s+'+'+tostr(offset)
  134. else
  135. s:=s+tostr(offset);
  136. end;
  137. if not(refaddr in [addr_no,addr_pic_no_got]) then
  138. begin
  139. s := s+')';
  140. if (refaddr in verbose_refaddrs) and
  141. not(target_info.system in [system_powerpc_darwin,system_powerpc64_darwin]) then
  142. s := s+refaddr2str[refaddr];
  143. end;
  144. {$ifdef cpu64bitaddr}
  145. if (refaddr=addr_pic) and
  146. (target_info.system=system_powerpc64_linux) then
  147. s := s + '@got';
  148. {$endif cpu64bitaddr}
  149. if (index=NR_NO) then
  150. begin
  151. if offset=0 then
  152. begin
  153. if not (assigned(symbol)) then
  154. s:=s+'0';
  155. end;
  156. if (base<>NR_NO) then
  157. s:=s+'('+gas_regname(base)+')'
  158. else if not assigned(symbol) and
  159. not(refaddr in verbose_refaddrs) then
  160. s:=s+'(0)';
  161. end
  162. else if (index<>NR_NO) and (base<>NR_NO) then
  163. begin
  164. if (offset=0) then
  165. s:=s+gas_regname(base)+','+gas_regname(index)
  166. else
  167. internalerror(2006052502);
  168. end;
  169. end;
  170. getreferencestring:=s;
  171. end;
  172. function getopstr_jmp(asminfo: pasminfo; const o:toper) : string;
  173. var
  174. hs : string;
  175. begin
  176. case o.typ of
  177. top_reg :
  178. getopstr_jmp:=gas_regname(o.reg);
  179. { no top_ref jumping for powerpc }
  180. top_const :
  181. getopstr_jmp:=tostr(o.val);
  182. top_ref :
  183. begin
  184. if o.ref^.refaddr<>addr_full then
  185. internalerror(200402267);
  186. hs:=o.ref^.symbol.name;
  187. if asminfo^.dollarsign<>'$' then
  188. hs:=ApplyAsmSymbolRestrictions(hs);
  189. if o.ref^.offset>0 then
  190. hs:=hs+'+'+tostr(o.ref^.offset)
  191. else
  192. if o.ref^.offset<0 then
  193. hs:=hs+tostr(o.ref^.offset);
  194. getopstr_jmp:=hs;
  195. end;
  196. top_none:
  197. getopstr_jmp:='';
  198. else
  199. internalerror(2002070605);
  200. end;
  201. end;
  202. function getopstr(asminfo: pasminfo; const o:toper) : string;
  203. var
  204. hs : string;
  205. begin
  206. case o.typ of
  207. top_reg:
  208. getopstr:=gas_regname(o.reg);
  209. top_const:
  210. getopstr:=tostr(longint(o.val));
  211. top_ref:
  212. if o.ref^.refaddr=addr_full then
  213. begin
  214. hs:=o.ref^.symbol.name;
  215. if asminfo^.dollarsign<>'$' then
  216. hs:=ApplyAsmSymbolRestrictions(hs);
  217. if o.ref^.offset>0 then
  218. hs:=hs+'+'+tostr(o.ref^.offset)
  219. else
  220. if o.ref^.offset<0 then
  221. hs:=hs+tostr(o.ref^.offset);
  222. getopstr:=hs;
  223. end
  224. else
  225. getopstr:=getreferencestring(asminfo,o.ref^);
  226. else
  227. internalerror(2002070604);
  228. end;
  229. end;
  230. function branchmode(o: tasmop): topstr;
  231. var tempstr: topstr;
  232. begin
  233. tempstr := '';
  234. case o of
  235. A_BCCTR,A_BCCTRL: tempstr := 'ctr';
  236. A_BCLR,A_BCLRL: tempstr := 'lr';
  237. else
  238. ;
  239. end;
  240. case o of
  241. A_BL,A_BLA,A_BCL,A_BCLA,A_BCCTRL,A_BCLRL: tempstr := tempstr+'l';
  242. else
  243. ;
  244. end;
  245. case o of
  246. A_BA,A_BLA,A_BCA,A_BCLA: tempstr:=tempstr+'a';
  247. else
  248. ;
  249. end;
  250. branchmode := tempstr;
  251. end;
  252. function cond2str(op: tasmop; c: tasmcond): string;
  253. { note: no checking is performed whether the given combination of }
  254. { conditions is valid }
  255. var
  256. tempstr: string;
  257. begin
  258. tempstr:=#9;
  259. case c.simple of
  260. false:
  261. begin
  262. cond2str := tempstr+gas_op2str[op];
  263. case c.dirhint of
  264. DH_None:;
  265. DH_Minus:
  266. cond2str:=cond2str+'-';
  267. DH_Plus:
  268. cond2str:=cond2str+'+';
  269. end;
  270. cond2str:=cond2str+#9+tostr(c.bo)+','+tostr(c.bi);
  271. end;
  272. true:
  273. if (op >= A_B) and (op <= A_BCLRL) then
  274. case c.cond of
  275. { unconditional branch }
  276. C_NONE:
  277. cond2str := tempstr+gas_op2str[op];
  278. { bdnzt etc }
  279. else
  280. begin
  281. tempstr := tempstr+'b'+asmcondflag2str[c.cond]+
  282. branchmode(op);
  283. case c.dirhint of
  284. DH_None:
  285. tempstr:=tempstr+#9;
  286. DH_Minus:
  287. tempstr:=tempstr+('-'+#9);
  288. DH_Plus:
  289. tempstr:=tempstr+('+'+#9);
  290. end;
  291. case c.cond of
  292. C_LT..C_NU:
  293. begin
  294. if byte(c.cr)=0 then
  295. Comment(V_error,'Wrong use of whole CR register for '+tempstr);
  296. cond2str := tempstr+gas_regname(newreg(R_SPECIALREGISTER,c.cr,R_SUBWHOLE));
  297. end;
  298. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  299. cond2str := tempstr+tostr(c.crbit);
  300. else
  301. cond2str := tempstr;
  302. end;
  303. end;
  304. end
  305. { we have a trap instruction }
  306. else
  307. begin
  308. internalerror(2002070602);
  309. { not yet implemented !!!!!!!!!!!!!!!!!!!!! }
  310. { case tempstr := 'tw';}
  311. end;
  312. end;
  313. end;
  314. {****************************************************************************}
  315. { PowerPC Instruction Writer }
  316. {****************************************************************************}
  317. Procedure TPPCInstrWriter.WriteInstruction(hp : tai);
  318. var op: TAsmOp;
  319. s: string;
  320. i: byte;
  321. sep: string[3];
  322. begin
  323. op:=taicpu(hp).opcode;
  324. if is_calljmp(op) then
  325. begin
  326. { direct BO/BI in op[0] and op[1] not supported, put them in condition! }
  327. case op of
  328. A_B,A_BA,A_BL,A_BLA:
  329. s:=#9+gas_op2str[op]+#9;
  330. A_BCTR,A_BCTRL,A_BLR,A_BLRL:
  331. s:=#9+gas_op2str[op]
  332. else
  333. begin
  334. s:=cond2str(op,taicpu(hp).condition);
  335. if (s[length(s)] <> #9) and
  336. (taicpu(hp).ops>0) then
  337. s := s + ',';
  338. end;
  339. end;
  340. if (taicpu(hp).ops>0) and (taicpu(hp).oper[0]^.typ<>top_none) then
  341. begin
  342. { first write the current contents of s, because the symbol }
  343. { may be 255 characters }
  344. owner.writer.AsmWrite(s);
  345. s:=getopstr_jmp(owner.asminfo,taicpu(hp).oper[0]^);
  346. end;
  347. end
  348. else
  349. { process operands }
  350. begin
  351. s:=#9+gas_op2str[op];
  352. if taicpu(hp).ops<>0 then
  353. begin
  354. {
  355. if not is_calljmp(op) then
  356. sep:=','
  357. else
  358. }
  359. sep:=#9;
  360. for i:=0 to taicpu(hp).ops-1 do
  361. begin
  362. // debug code
  363. // writeln(s);
  364. // writeln(taicpu(hp).fileinfo.line);
  365. s:=s+sep+getopstr(owner.asminfo,taicpu(hp).oper[i]^);
  366. sep:=',';
  367. end;
  368. end;
  369. end;
  370. owner.writer.AsmWriteLn(s);
  371. end;
  372. {****************************************************************************}
  373. { GNU PPC Assembler writer }
  374. {****************************************************************************}
  375. constructor TPPCGNUAssembler.CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean);
  376. begin
  377. inherited;
  378. InstrWriter := TPPCInstrWriter.create(self);
  379. end;
  380. function TPPCGNUAssembler.MakeCmdLine: TCmdStr;
  381. begin
  382. result := inherited MakeCmdLine;
  383. {$ifdef cpu64bitaddr}
  384. Replace(result,'$ARCH','-a64')
  385. {$else cpu64bitaddr}
  386. { MorphOS has an old 2.9.1 GNU AS, with a bunch of patches
  387. to support the system, and it doesn't know the -a32 argument }
  388. if target_info.system = system_powerpc_morphos then
  389. Replace(result,'$ARCH','')
  390. else
  391. Replace(result,'$ARCH','-a32');
  392. {$endif cpu64bitaddr}
  393. end;
  394. procedure TPPCGNUAssembler.WriteExtraHeader;
  395. var
  396. i : longint;
  397. begin
  398. if target_info.abi = abi_powerpc_elfv2 then
  399. writer.AsmWriteln(#9'.abiversion 2');
  400. for i:=0 to 31 do
  401. writer.AsmWriteln(#9'.set'#9'r'+tostr(i)+','+tostr(i));
  402. for i:=0 to 31 do
  403. writer.AsmWriteln(#9'.set'#9'f'+tostr(i)+','+tostr(i));
  404. end;
  405. {****************************************************************************}
  406. { GNU/Apple PPC Assembler writer }
  407. {****************************************************************************}
  408. constructor TPPCAppleGNUAssembler.CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean);
  409. begin
  410. inherited;
  411. InstrWriter := TPPCInstrWriter.create(self);
  412. end;
  413. function TPPCAppleGNUAssembler.MakeCmdLine: TCmdStr;
  414. begin
  415. result := inherited MakeCmdLine;
  416. {$ifdef cpu64bitaddr}
  417. Replace(result,'$ARCH','ppc64')
  418. {$else cpu64bitaddr}
  419. case current_settings.cputype of
  420. cpu_PPC7400:
  421. Replace(result,'$ARCH','ppc7400');
  422. cpu_PPC970:
  423. Replace(result,'$ARCH','ppc970');
  424. else
  425. Replace(result,'$ARCH','ppc')
  426. end;
  427. {$endif cpu64bitaddr}
  428. end;
  429. {****************************************************************************}
  430. { AIX PPC Assembler writer }
  431. {****************************************************************************}
  432. constructor TPPCAIXAssembler.CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean);
  433. var
  434. cur_sectype : TAsmSectionType;
  435. begin
  436. inherited;
  437. InstrWriter := TPPCInstrWriter.create(self);
  438. { Use 8-byte alignment as default for all sections }
  439. for cur_sectype:=low(TAsmSectionType) to high(TAsmSectionType) do
  440. max_alignment[cur_sectype]:=8;
  441. end;
  442. procedure TPPCAIXAssembler.WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder;secalign:longint;
  443. secflags:TSectionFlags=[];secprogbits:TSectionProgbits=SPB_None);
  444. begin
  445. secalign:=max_alignment[atype];
  446. Inherited WriteSection(atype,aname,aorder,secalign,secflags,secprogbits);
  447. end;
  448. procedure TPPCAIXAssembler.WriteAsmList;
  449. var
  450. cur_sectype : TAsmSectionType;
  451. hal : tasmlisttype;
  452. hp : tai;
  453. max_al : longint;
  454. begin
  455. { Parse all asmlists to get maximum alignement used for all types }
  456. for hal:=low(TasmlistType) to high(TasmlistType) do
  457. begin
  458. if not (current_asmdata.asmlists[hal].empty) then
  459. begin
  460. cur_sectype:=sec_none;
  461. hp:=tai(current_asmdata.asmlists[hal].First);
  462. while assigned(hp) do
  463. begin
  464. case hp.typ of
  465. ait_align :
  466. begin
  467. if tai_align_abstract(hp).aligntype > max_alignment[cur_sectype] then
  468. begin
  469. max_alignment[cur_sectype]:=tai_align_abstract(hp).aligntype;
  470. current_asmdata.asmlists[hal].InsertAfter(tai_comment.Create(strpnew('Alignment put to '+tostr(tai_align_abstract(hp).aligntype))),hp);
  471. end;
  472. end;
  473. ait_section :
  474. begin
  475. cur_sectype:=tai_section(hp).sectype;
  476. if tai_section(hp).secalign > max_alignment[cur_sectype] then
  477. begin
  478. max_alignment[cur_sectype]:=tai_section(hp).secalign;
  479. current_asmdata.asmlists[hal].InsertAfter(tai_comment.Create(strpnew('Section '
  480. +sectionname(tai_section(hp).sectype,'',secorder_default)+' alignment put to '+tostr(tai_section(hp).secalign))),hp);
  481. end;
  482. end;
  483. else
  484. ;
  485. end;
  486. hp:=tai(hp.next);
  487. end;
  488. end;
  489. end;
  490. { sec_data, sec_rodata and sec_bss all are converted into .data[RW],
  491. in WriteSection below,
  492. so we take the maximum alignment of the three }
  493. max_al:=max_alignment[sec_data];
  494. max_al:=max(max_al,max_alignment[sec_rodata]);
  495. max_al:=max(max_al,max_alignment[sec_bss]);
  496. max_alignment[sec_data]:=max_al;
  497. max_alignment[sec_rodata]:=max_al;
  498. max_alignment[sec_bss]:=max_al;
  499. Inherited WriteAsmList;
  500. end;
  501. procedure TPPCAIXAssembler.WriteExtraHeader;
  502. var
  503. i: longint;
  504. begin
  505. inherited WriteExtraHeader;
  506. { map cr registers to plain numbers }
  507. for i:=0 to 7 do
  508. writer.AsmWriteln(#9'.set'#9'cr'+tostr(i)+','+tostr(i));
  509. { Ensure .data and .rodata sections are aligned to 8-byte boundary,
  510. required for correct RTTI alignment.
  511. AIX assembler seems to only care for the first
  512. alignment value given }
  513. writer.AsmWriteln(#9'.csect .data[RW],'+sectionalignment_aix(sec_data,max_alignment[sec_data]));
  514. writer.AsmWriteln(#9'.csect _data.bss_[BS],'+sectionalignment_aix(sec_data,max_alignment[sec_data]));
  515. { .rodata is translated into .text[RO]
  516. see sectionname in aggas unit. }
  517. writer.AsmWriteln(#9'.csect .text[RO],'+sectionalignment_aix(sec_rodata_norel,max_alignment[sec_rodata_norel]));
  518. { make sure we always have a code and toc section,
  519. the linker expects that }
  520. writer.AsmWriteln(#9'.csect .text[PR],'+sectionalignment_aix(sec_code,max_alignment[sec_code]));
  521. { set _text_s, to be used by footer below }
  522. writer.AsmWriteln(#9'_text_s:');
  523. writer.AsmWriteln(#9'.toc');
  524. end;
  525. procedure TPPCAIXAssembler.WriteExtraFooter;
  526. begin
  527. inherited WriteExtraFooter;
  528. { link between data and text section }
  529. writer.AsmWriteln(#9'.csect .data[RW],3');
  530. {$ifdef cpu64bitaddr}
  531. writer.AsmWriteln('text_pos:'#9'.llong _text_s')
  532. {$else cpu64bitaddr}
  533. writer.AsmWriteln('text_pos:'#9'.long _text_s')
  534. {$endif cpu64bitaddr}
  535. end;
  536. procedure TPPCAIXAssembler.WriteDirectiveName(dir: TAsmDirective);
  537. begin
  538. case dir of
  539. asd_reference:
  540. writer.AsmWrite('.ref ');
  541. asd_weak_reference,
  542. asd_weak_definition:
  543. writer.AsmWrite('.weak ');
  544. else
  545. inherited WriteDirectiveName(dir);
  546. end;
  547. end;
  548. function TPPCAIXAssembler.sectionname(atype: TAsmSectiontype; const aname: string; aorder: TAsmSectionOrder): string;
  549. begin
  550. case atype of
  551. sec_code:
  552. result:='.csect .text[PR]';
  553. sec_data,
  554. sec_rodata,
  555. { don't use .bss[BS], causes relocation problems }
  556. sec_bss:
  557. result:='.csect .data[RW]';
  558. sec_rodata_norel:
  559. result:='.csect .text[RO]';
  560. sec_fpc:
  561. result:='.csect .fpc[RO]';
  562. sec_toc:
  563. result:='.toc';
  564. { automatically placed in the right section }
  565. sec_stab,
  566. sec_stabstr:
  567. result:='';
  568. else
  569. internalerror(2011122601);
  570. end;
  571. end;
  572. function TPPCMacOSAssembler.sectionname(atype: TAsmSectiontype; const aname: string; aorder: TAsmSectionOrder): string;
  573. begin
  574. case atype of
  575. sec_code:
  576. result:='.text[PR]';
  577. sec_data,
  578. sec_rodata,
  579. { don't use .bss[BS], causes relocation problems }
  580. sec_bss:
  581. result:='.data[RW]';
  582. sec_rodata_norel:
  583. result:='.text[RO]';
  584. sec_fpc:
  585. result:='.fpc[RO]';
  586. sec_toc:
  587. result:='.toc';
  588. { automatically placed in the right section }
  589. sec_stab,
  590. sec_stabstr:
  591. result:='';
  592. else
  593. internalerror(2025010201);
  594. end;
  595. end;
  596. {*****************************************************************************
  597. Initialize
  598. *****************************************************************************}
  599. const
  600. as_ppc_gas_info : tasminfo =
  601. (
  602. id : as_gas;
  603. idtxt : 'AS';
  604. asmbin : 'as';
  605. {$ifdef cpu64bitaddr}
  606. asmcmd : '-a64 $ENDIAN -o $OBJ $EXTRAOPT $ASM';
  607. {$else cpu64bitaddr}
  608. asmcmd: '$ENDIAN -o $OBJ $EXTRAOPT $ARCH $ASM';
  609. {$endif cpu64bitaddr}
  610. supported_targets : [system_powerpc_linux,system_powerpc_netbsd,system_powerpc_openbsd,
  611. system_powerpc_MorphOS,system_powerpc_Amiga,system_powerpc_wii,
  612. system_powerpc64_linux,system_powerpc_embedded,system_powerpc64_embedded];
  613. flags : [af_needar,af_smartlink_sections];
  614. labelprefix : '.L';
  615. labelmaxlen : -1;
  616. comment : '# ';
  617. dollarsign: '$';
  618. );
  619. as_ppc_gas_macosclassic_info : tasminfo =
  620. (
  621. id : as_powerpc_gas_macosclassic;
  622. idtxt : 'AS-MACOS';
  623. asmbin : 'as';
  624. asmcmd: '-o $OBJ $EXTRAOPT $ARCH $ASM';
  625. supported_targets : [system_powerpc_macosclassic];
  626. flags : [af_needar,af_smartlink_sections];
  627. labelprefix : '.L';
  628. labelmaxlen : -1;
  629. comment : '# ';
  630. dollarsign: '$';
  631. );
  632. as_ppc_gas_legacy_info : tasminfo =
  633. (
  634. id : as_powerpc_gas_legacy;
  635. idtxt : 'AS-LEGACY';
  636. asmbin : 'as';
  637. {$ifdef cpu64bitaddr}
  638. asmcmd : '-a64 $ENDIAN -o $OBJ $EXTRAOPT $ASM';
  639. {$else cpu64bitaddr}
  640. asmcmd: '$ENDIAN -o $OBJ $EXTRAOPT $ARCH $ASM';
  641. {$endif cpu64bitaddr}
  642. supported_targets : [system_powerpc_morphos];
  643. flags : [af_needar];
  644. labelprefix : '.L';
  645. labelmaxlen : -1;
  646. comment : '# ';
  647. dollarsign: '$';
  648. );
  649. as_ppc_gas_darwin_powerpc_info : tasminfo =
  650. (
  651. id : as_darwin;
  652. idtxt : 'AS-DARWIN';
  653. asmbin : 'as';
  654. asmcmd : '-o $OBJ $EXTRAOPT $ASM -arch $ARCH';
  655. supported_targets : [system_powerpc_darwin,system_powerpc64_darwin];
  656. flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_stabs_use_function_absolute_addresses];
  657. labelprefix : 'L';
  658. labelmaxlen : -1;
  659. comment : '# ';
  660. dollarsign : '$';
  661. );
  662. as_ppc_aix_powerpc_info : tasminfo =
  663. (
  664. id : as_powerpc_xcoff;
  665. idtxt : 'AS-AIX';
  666. asmbin : 'as';
  667. { -u: allow using symbols before they are defined (when using native
  668. AIX assembler, ignore by GNU assembler)
  669. -mpwr5: we actually support Power3 and higher, but the AIX assembler
  670. has no parameter to select that one (only -mpwr3 and -mpwr5) }
  671. {$ifdef cpu64bitaddr}
  672. asmcmd : '-a64 -u -o $OBJ $EXTRAOPT $ASM -mpwr5';
  673. {$else cpu64bitaddr}
  674. asmcmd : '-u -o $OBJ $EXTRAOPT $ASM -mpwr5';
  675. {$endif cpu64bitaddr}
  676. supported_targets : [system_powerpc_aix,system_powerpc64_aix];
  677. flags : [af_needar,af_smartlink_sections,af_stabs_use_function_absolute_addresses];
  678. labelprefix : 'L';
  679. labelmaxlen : -1;
  680. comment : '# ';
  681. dollarsign : '.'
  682. );
  683. as_ppc_gas_aix_powerpc_info : tasminfo =
  684. (
  685. id : as_gas_powerpc_xcoff;
  686. idtxt : 'GAS';
  687. asmbin : 'gas';
  688. { -u: allow using symbols before they are defined (when using native
  689. AIX assembler, ignore by GNU assembler)
  690. -mpwr5: we actually support Power3 and higher, but the AIX assembler
  691. has no parameter to select that one (only -mpwr3 and -mpwr5) }
  692. {$ifdef cpu64bitaddr}
  693. asmcmd : '-a64 -u -o $OBJ $EXTRAOPT $ASM -mpwr5';
  694. {$else cpu64bitaddr}
  695. asmcmd : '-a32 -u -o $OBJ $EXTRAOPT $ASM -mpwr5';
  696. {$endif cpu64bitaddr}
  697. supported_targets : [system_powerpc_aix,system_powerpc64_aix];
  698. flags : [af_needar,af_smartlink_sections,af_stabs_use_function_absolute_addresses];
  699. labelprefix : 'L';
  700. labelmaxlen : -1;
  701. comment : '# ';
  702. dollarsign : '.'
  703. );
  704. as_ppc_clang_darwin_info : tasminfo =
  705. (
  706. id : as_clang_asdarwin;
  707. idtxt : 'CLANG';
  708. asmbin : 'clang';
  709. asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
  710. supported_targets : [system_powerpc_macosclassic, system_powerpc_darwin, system_powerpc64_darwin];
  711. flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_llvm];
  712. labelprefix : 'L';
  713. labelmaxlen : -1;
  714. comment : '# ';
  715. dollarsign: '$';
  716. );
  717. begin
  718. RegisterAssembler(as_ppc_gas_info,TPPCGNUAssembler);
  719. RegisterAssembler(as_ppc_gas_macosclassic_info,TPPCMACOsAssembler);
  720. RegisterAssembler(as_ppc_gas_legacy_info,TPPCGNUAssembler);
  721. RegisterAssembler(as_ppc_gas_darwin_powerpc_info,TPPCAppleGNUAssembler);
  722. RegisterAssembler(as_ppc_clang_darwin_info,TPPCAppleGNUAssembler);
  723. RegisterAssembler(as_ppc_aix_powerpc_info,TPPCAIXAssembler);
  724. RegisterAssembler(as_ppc_gas_aix_powerpc_info,TPPCAIXAssembler);
  725. end.