cpugas.pas 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. {
  2. Copyright (c) 1999-2003 by Florian Klaempfl
  3. This unit implements an asmoutput class for SPARC AT&T syntax
  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. unit cpugas;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cpubase,
  22. aasmtai,aasmcpu,assemble,aggas;
  23. type
  24. TGasSPARC=class(TGnuAssembler)
  25. procedure WriteInstruction(hp:Tai);override;
  26. end;
  27. implementation
  28. uses
  29. cutils,systems,
  30. verbose,itcpugas,cgbase,cgutils;
  31. function GetReferenceString(var ref:TReference):string;
  32. begin
  33. GetReferenceString:='';
  34. with ref do
  35. begin
  36. if (base=NR_NO) and (index=NR_NO) then
  37. begin
  38. if assigned(symbol) then
  39. GetReferenceString:=symbol.name;
  40. if offset>0 then
  41. GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
  42. else if offset<0 then
  43. GetReferenceString:=GetReferenceString+ToStr(offset);
  44. case refaddr of
  45. addr_hi:
  46. GetReferenceString:='%hi('+GetReferenceString+')';
  47. addr_lo:
  48. GetReferenceString:='%lo('+GetReferenceString+')';
  49. end;
  50. end
  51. else
  52. begin
  53. {$ifdef extdebug}
  54. if assigned(symbol) and
  55. not(refaddr in [addr_pic,addr_lo]) then
  56. internalerror(2003052601);
  57. {$endif extdebug}
  58. if base<>NR_NO then
  59. GetReferenceString:=GetReferenceString+gas_regname(base);
  60. if index=NR_NO then
  61. begin
  62. { if (Offset<simm13lo) or (Offset>simm13hi) then
  63. internalerror(2003053008); }
  64. if offset>0 then
  65. GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
  66. else if offset<0 then
  67. GetReferenceString:=GetReferenceString+ToStr(offset);
  68. {
  69. else if (offset=0) and not(assigned(symbol)) then
  70. GetReferenceString:=GetReferenceString+ToStr(offset);
  71. }
  72. if assigned(symbol) then
  73. begin
  74. if refaddr=addr_lo then
  75. GetReferenceString:='%lo('+symbol.name+')+'+GetReferenceString
  76. else
  77. GetReferenceString:=symbol.name+'+'+GetReferenceString;
  78. end;
  79. end
  80. else
  81. begin
  82. {$ifdef extdebug}
  83. if (Offset<>0) or assigned(symbol) then
  84. internalerror(2003052603);
  85. {$endif extdebug}
  86. GetReferenceString:=GetReferenceString+'+'+gas_regname(index);
  87. end;
  88. end;
  89. end;
  90. end;
  91. function getopstr(const Oper:TOper):string;
  92. begin
  93. with Oper do
  94. case typ of
  95. top_reg:
  96. getopstr:=gas_regname(reg);
  97. top_const:
  98. getopstr:=tostr(longint(val));
  99. top_ref:
  100. if (oper.ref^.refaddr in [addr_no,addr_pic]) or ((oper.ref^.refaddr=addr_lo) and ((oper.ref^.base<>NR_NO) or
  101. (oper.ref^.index<>NR_NO))) then
  102. getopstr:='['+getreferencestring(ref^)+']'
  103. else
  104. getopstr:=getreferencestring(ref^);
  105. else
  106. internalerror(10001);
  107. end;
  108. end;
  109. procedure TGasSPARC.WriteInstruction(hp:Tai);
  110. var
  111. Op:TAsmOp;
  112. s:String;
  113. i:Integer;
  114. begin
  115. if hp.typ<>ait_instruction then
  116. exit;
  117. op:=taicpu(hp).opcode;
  118. { translate pseudoops, this should be move to a separate pass later, so it's done before
  119. peephole optimization }
  120. case op of
  121. A_FABSd:
  122. begin
  123. if (taicpu(hp).ops<>2) or
  124. (taicpu(hp).oper[0]^.typ<>top_reg) or
  125. (taicpu(hp).oper[1]^.typ<>top_reg) then
  126. internalerror(200401045);
  127. { FABSs %f<even>,%f<even> }
  128. s:=#9+std_op2str[A_FABSs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  129. AsmWriteLn(s);
  130. { FMOVs %f<odd>,%f<odd> }
  131. inc(taicpu(hp).oper[0]^.reg);
  132. inc(taicpu(hp).oper[1]^.reg);
  133. s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  134. dec(taicpu(hp).oper[0]^.reg);
  135. dec(taicpu(hp).oper[1]^.reg);
  136. AsmWriteLn(s);
  137. end;
  138. A_FMOVd:
  139. begin
  140. if (taicpu(hp).ops<>2) or
  141. (taicpu(hp).oper[0]^.typ<>top_reg) or
  142. (taicpu(hp).oper[1]^.typ<>top_reg) then
  143. internalerror(200401045);
  144. { FMOVs %f<even>,%f<even> }
  145. s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  146. AsmWriteLn(s);
  147. { FMOVs %f<odd>,%f<odd> }
  148. inc(taicpu(hp).oper[0]^.reg);
  149. inc(taicpu(hp).oper[1]^.reg);
  150. s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  151. dec(taicpu(hp).oper[0]^.reg);
  152. dec(taicpu(hp).oper[1]^.reg);
  153. AsmWriteLn(s);
  154. end
  155. else
  156. begin
  157. { call maybe not translated to call }
  158. s:=#9+std_op2str[op]+cond2str[taicpu(hp).condition];
  159. if taicpu(hp).delayslot_annulled then
  160. s:=s+',a';
  161. if taicpu(hp).ops>0 then
  162. begin
  163. s:=s+#9+getopstr(taicpu(hp).oper[0]^);
  164. for i:=1 to taicpu(hp).ops-1 do
  165. s:=s+','+getopstr(taicpu(hp).oper[i]^);
  166. end;
  167. AsmWriteLn(s);
  168. end;
  169. end;
  170. end;
  171. const
  172. as_sparc_as_info : tasminfo =
  173. (
  174. id : as_gas;
  175. idtxt : 'AS';
  176. asmbin : 'gas';
  177. asmcmd : '-o $OBJ $ASM';
  178. supported_target : system_any;
  179. flags : [af_allowdirect,af_needar,af_smartlink_sections];
  180. labelprefix : '.L';
  181. comment : '# ';
  182. );
  183. begin
  184. RegisterAssembler(as_SPARC_as_info,TGasSPARC);
  185. end.