cpugas.pas 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. {
  2. $Id$
  3. Copyright (c) 1999-2003 by Florian Klaempfl
  4. This unit implements an asmoutput class for SPARC AT&T syntax
  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 cpugas;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cpubase,
  23. aasmtai,aasmcpu,assemble,aggas;
  24. type
  25. TGasSPARC=class(TGnuAssembler)
  26. procedure WriteInstruction(hp:Tai);override;
  27. end;
  28. implementation
  29. uses
  30. cutils,systems,
  31. verbose,itcpugas,cgbase;
  32. function GetReferenceString(var ref:TReference):string;
  33. begin
  34. GetReferenceString:='';
  35. with ref do
  36. begin
  37. if (base=NR_NO) and (index=NR_NO) then
  38. begin
  39. if assigned(symbol) then
  40. GetReferenceString:=symbol.name;
  41. if offset>0 then
  42. GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
  43. else if offset<0 then
  44. GetReferenceString:=GetReferenceString+ToStr(offset);
  45. case refaddr of
  46. addr_hi :
  47. GetReferenceString:='%hi('+GetReferenceString+')';
  48. addr_lo :
  49. GetReferenceString:='%lo('+GetReferenceString+')';
  50. end;
  51. end
  52. else
  53. begin
  54. if assigned(symbol) then
  55. internalerror(2003052601);
  56. if base<>NR_NO then
  57. GetReferenceString:=GetReferenceString+gas_regname(base);
  58. if index=NR_NO then
  59. begin
  60. { if (Offset<simm13lo) or (Offset>simm13hi) then
  61. internalerror(2003053008); }
  62. if offset>0 then
  63. GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
  64. else if offset<0 then
  65. GetReferenceString:=GetReferenceString+ToStr(offset);
  66. end
  67. else
  68. begin
  69. if Offset<>0 then
  70. internalerror(2003052603);
  71. GetReferenceString:=GetReferenceString+'+'+gas_regname(index);
  72. end;
  73. end;
  74. end;
  75. end;
  76. function getopstr(const Oper:TOper):string;
  77. begin
  78. with Oper do
  79. case typ of
  80. top_reg:
  81. getopstr:=gas_regname(reg);
  82. top_const:
  83. getopstr:=tostr(longint(val));
  84. top_ref:
  85. if Oper.ref^.refaddr=addr_no then
  86. getopstr:='['+getreferencestring(ref^)+']'
  87. else
  88. getopstr:=getreferencestring(ref^);
  89. else
  90. internalerror(10001);
  91. end;
  92. end;
  93. procedure TGasSPARC.WriteInstruction(hp:Tai);
  94. var
  95. Op:TAsmOp;
  96. s:String;
  97. i:Integer;
  98. begin
  99. if hp.typ<>ait_instruction then
  100. exit;
  101. op:=taicpu(hp).opcode;
  102. { FMOVd does not exist, rewrite it using 2 FMOVs }
  103. if op=A_FMOVD then
  104. begin
  105. if (taicpu(hp).ops<>2) or
  106. (taicpu(hp).oper[0]^.typ<>top_reg) or
  107. (taicpu(hp).oper[1]^.typ<>top_reg) then
  108. internalerror(200401045);
  109. { FMOVs %f<even>,%f<even> }
  110. s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  111. AsmWriteLn(s);
  112. { FMOVs %f<odd>,%f<odd> }
  113. inc(taicpu(hp).oper[0]^.reg);
  114. inc(taicpu(hp).oper[1]^.reg);
  115. s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  116. dec(taicpu(hp).oper[0]^.reg);
  117. dec(taicpu(hp).oper[1]^.reg);
  118. AsmWriteLn(s);
  119. end
  120. else
  121. begin
  122. { call maybe not translated to call }
  123. s:=#9+std_op2str[op]+cond2str[taicpu(hp).condition];
  124. if taicpu(hp).delayslot_annulled then
  125. s:=s+',a';
  126. if taicpu(hp).ops>0 then
  127. begin
  128. s:=s+#9+getopstr(taicpu(hp).oper[0]^);
  129. for i:=1 to taicpu(hp).ops-1 do
  130. s:=s+','+getopstr(taicpu(hp).oper[i]^);
  131. end;
  132. AsmWriteLn(s);
  133. end;
  134. end;
  135. const
  136. as_sparc_as_info : tasminfo =
  137. (
  138. id : as_gas;
  139. idtxt : 'AS';
  140. asmbin : 'as';
  141. asmcmd : '-o $OBJ $ASM';
  142. supported_target : system_any;
  143. flags : [af_allowdirect,af_needar,af_smartlink_sections];
  144. labelprefix : '.L';
  145. comment : '# ';
  146. );
  147. begin
  148. RegisterAssembler(as_SPARC_as_info,TGasSPARC);
  149. end.
  150. {
  151. $Log$
  152. Revision 1.27 2004-06-20 07:11:32 florian
  153. - offsetfixup removed
  154. Revision 1.26 2004/06/16 20:07:10 florian
  155. * dwarf branch merged
  156. Revision 1.25.2.3 2004/05/30 17:54:14 florian
  157. + implemented cmp64bit
  158. * started to fix spilling
  159. * fixed int64 sub partially
  160. Revision 1.25.2.2 2004/05/25 21:38:53 peter
  161. * assembler reader/writer updates
  162. Revision 1.25.2.1 2004/05/11 21:06:51 peter
  163. * sparc compiler fixed
  164. Revision 1.25 2004/02/27 15:15:33 mazen
  165. * symaddr ==> refaddr to follow the rest of compiler changes
  166. Revision 1.24 2004/01/12 16:39:41 peter
  167. * sparc updates, mostly float related
  168. Revision 1.23 2003/10/24 11:22:50 mazen
  169. *fix related to toper==>poper
  170. Revision 1.22 2003/09/03 15:55:01 peter
  171. * NEWRA branch merged
  172. Revision 1.21.2.1 2003/09/01 21:02:55 peter
  173. * sparc updates for new tregister
  174. Revision 1.21 2003/07/08 21:25:00 peter
  175. * sparc fixes
  176. Revision 1.20 2003/07/02 22:18:04 peter
  177. * paraloc splitted in callerparaloc,calleeparaloc
  178. * sparc calling convention updates
  179. Revision 1.19 2003/06/01 21:38:06 peter
  180. * getregisterfpu size parameter added
  181. * op_const_reg size parameter added
  182. * sparc updates
  183. Revision 1.18 2003/06/01 01:04:35 peter
  184. * reference fixes
  185. Revision 1.17 2003/05/31 01:00:51 peter
  186. * register fixes
  187. Revision 1.16 2003/05/30 23:57:08 peter
  188. * more sparc cleanup
  189. * accumulator removed, splitted in function_return_reg (called) and
  190. function_result_reg (caller)
  191. Revision 1.15 2003/05/28 23:18:31 florian
  192. * started to fix and clean up the sparc port
  193. Revision 1.14 2003/05/07 11:55:34 mazen
  194. - unused units removed from uses clause
  195. - unused variables removed from implemntation declarations
  196. Revision 1.13 2003/05/06 14:55:27 mazen
  197. * comment changed to ;# instead of ##
  198. * .bss section changed to .section ".bss"
  199. Revision 1.12 2003/03/15 22:51:58 mazen
  200. * remaking sparc rtl compile
  201. Revision 1.11 2003/01/08 18:43:58 daniel
  202. * Tregister changed into a record
  203. Revision 1.10 2002/11/16 15:29:16 florian
  204. * fixed Cish syntax
  205. Revision 1.9 2002/11/10 19:07:46 mazen
  206. * SPARC calling mechanism almost OK (as in GCC./mppcsparc )
  207. Revision 1.8 2002/10/25 19:37:53 mazen
  208. * bug of references name missing last character fixed
  209. Revision 1.7 2002/10/20 19:01:38 mazen
  210. + op_raddr_reg and op_caddr_reg added to fix functions prologue
  211. Revision 1.6 2002/10/15 09:00:28 mazen
  212. * sone coding style modified
  213. }