cpugas.pas 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. inc(offset,offsetfixup);
  38. offsetfixup:=0;
  39. if (base=NR_NO) and (index=NR_NO) then
  40. begin
  41. if assigned(symbol) then
  42. GetReferenceString:=symbol.name;
  43. if offset>0 then
  44. GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
  45. else if offset<0 then
  46. GetReferenceString:=GetReferenceString+ToStr(offset);
  47. case refaddr of
  48. addr_hi :
  49. GetReferenceString:='%hi('+GetReferenceString+')';
  50. addr_lo :
  51. GetReferenceString:='%lo('+GetReferenceString+')';
  52. end;
  53. end
  54. else
  55. begin
  56. if assigned(symbol) then
  57. internalerror(2003052601);
  58. GetReferenceString:='[';
  59. if base<>NR_NO then
  60. GetReferenceString:=GetReferenceString+gas_regname(base);
  61. if index=NR_NO then
  62. begin
  63. if (Offset<simm13lo) or (Offset>simm13hi) then
  64. internalerror(2003053008);
  65. if offset>0 then
  66. GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
  67. else if offset<0 then
  68. GetReferenceString:=GetReferenceString+ToStr(offset);
  69. end
  70. else
  71. begin
  72. if Offset<>0 then
  73. internalerror(2003052603);
  74. GetReferenceString:=GetReferenceString+'+'+gas_regname(index);
  75. end;
  76. GetReferenceString:=GetReferenceString+']';
  77. end;
  78. end;
  79. end;
  80. function getopstr(const Oper:TOper):string;
  81. var
  82. hs : string;
  83. begin
  84. with Oper do
  85. case typ of
  86. top_reg:
  87. getopstr:=gas_regname(reg);
  88. top_const:
  89. getopstr:=tostr(longint(val));
  90. top_ref:
  91. if Oper.ref^.refaddr=addr_full then
  92. begin
  93. if assigned(ref) then
  94. hs:={'$'+}ref^.symbol.name
  95. else
  96. hs:='$';
  97. if ref^.offset>0 then
  98. hs:=hs+'+'+tostr(ref^.offset)
  99. else
  100. if ref^.offset<0 then
  101. hs:=hs+tostr(ref^.offset)
  102. else
  103. if not(assigned(ref)) then
  104. hs:=hs+'0';
  105. getopstr:=hs;
  106. end
  107. else
  108. getopstr:=getreferencestring(ref^);
  109. else
  110. internalerror(10001);
  111. end;
  112. end;
  113. (*
  114. function getopstr_jmp(const Oper:TOper):string;
  115. var
  116. hs:string;
  117. begin
  118. with Oper do
  119. case typ of
  120. top_reg:
  121. getopstr_jmp:=gas_reg2str[reg]+'+';
  122. top_ref:
  123. getopstr_jmp:=GetReferenceString(ref^);
  124. top_const:
  125. getopstr_jmp:=tostr(longint(val));
  126. top_symbol:
  127. begin
  128. hs:=sym.name;
  129. if symofs>0 then
  130. hs:=hs+'+'+tostr(symofs)
  131. else
  132. if symofs<0 then
  133. hs:=hs+tostr(symofs);
  134. getopstr_jmp:=hs;
  135. end;
  136. else
  137. internalerror(10001);
  138. end;
  139. end;*)
  140. procedure TGasSPARC.WriteInstruction(hp:Tai);
  141. var
  142. Op:TAsmOp;
  143. s:String;
  144. i:Integer;
  145. begin
  146. if hp.typ<>ait_instruction then
  147. exit;
  148. op:=taicpu(hp).opcode;
  149. { FMOVd does not exist, rewrite it using 2 FMOVs }
  150. if op=A_FMOVD then
  151. begin
  152. if (taicpu(hp).ops<>2) or
  153. (taicpu(hp).oper[0]^.typ<>top_reg) or
  154. (taicpu(hp).oper[1]^.typ<>top_reg) then
  155. internalerror(200401045);
  156. { FMOVs %f<even>,%f<even> }
  157. s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  158. AsmWriteLn(s);
  159. { FMOVs %f<odd>,%f<odd> }
  160. inc(taicpu(hp).oper[0]^.reg);
  161. inc(taicpu(hp).oper[1]^.reg);
  162. s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  163. dec(taicpu(hp).oper[0]^.reg);
  164. dec(taicpu(hp).oper[1]^.reg);
  165. AsmWriteLn(s);
  166. end
  167. else
  168. begin
  169. { call maybe not translated to call }
  170. s:=#9+std_op2str[op]+cond2str[taicpu(hp).condition];
  171. if taicpu(hp).ops>0 then
  172. begin
  173. s:=s+#9+getopstr(taicpu(hp).oper[0]^);
  174. for i:=1 to taicpu(hp).ops-1 do
  175. s:=s+','+getopstr(taicpu(hp).oper[i]^);
  176. end;
  177. AsmWriteLn(s);
  178. end;
  179. end;
  180. const
  181. as_SPARC_as_info:TAsmInfo=(
  182. id:as_gas;
  183. idtxt:'AS';
  184. asmbin:'as';
  185. asmcmd:'-o $OBJ $ASM';
  186. supported_target:system_any;
  187. outputbinary:false;
  188. allowdirect:true;
  189. needar:true;
  190. labelprefix_only_inside_procedure:false;
  191. labelprefix:'.L';
  192. comment:';# ';
  193. secnames:({sec_none}'', {no section}
  194. {sec_code}'.text', {executable code}
  195. {sec_data}'.data', {initialized R/W data}
  196. {sec_bss}'.section ".bss"', {uninitialized R/W data}
  197. {sec_idata2}'.comment', {comments}
  198. {sec_idata4}'.debug', {debugging information}
  199. {sec_idata5}'.rodata', {RO data}
  200. {sec_idata6}'.line', {line numbers info for symbolic debug}
  201. {sec_idata7}'.init', {runtime intialization code}
  202. {sec_edata}'.fini', {runtime finalization code}
  203. {sec_stab}'.stab',
  204. {sec_stabstr} '.stabstr',
  205. {sec_common}'.note') {note info}
  206. );
  207. begin
  208. RegisterAssembler(as_SPARC_as_info,TGasSPARC);
  209. end.
  210. {
  211. $Log$
  212. Revision 1.25 2004-02-27 15:15:33 mazen
  213. * symaddr ==> refaddr to follow the rest of compiler changes
  214. Revision 1.24 2004/01/12 16:39:41 peter
  215. * sparc updates, mostly float related
  216. Revision 1.23 2003/10/24 11:22:50 mazen
  217. *fix related to toper==>poper
  218. Revision 1.22 2003/09/03 15:55:01 peter
  219. * NEWRA branch merged
  220. Revision 1.21.2.1 2003/09/01 21:02:55 peter
  221. * sparc updates for new tregister
  222. Revision 1.21 2003/07/08 21:25:00 peter
  223. * sparc fixes
  224. Revision 1.20 2003/07/02 22:18:04 peter
  225. * paraloc splitted in callerparaloc,calleeparaloc
  226. * sparc calling convention updates
  227. Revision 1.19 2003/06/01 21:38:06 peter
  228. * getregisterfpu size parameter added
  229. * op_const_reg size parameter added
  230. * sparc updates
  231. Revision 1.18 2003/06/01 01:04:35 peter
  232. * reference fixes
  233. Revision 1.17 2003/05/31 01:00:51 peter
  234. * register fixes
  235. Revision 1.16 2003/05/30 23:57:08 peter
  236. * more sparc cleanup
  237. * accumulator removed, splitted in function_return_reg (called) and
  238. function_result_reg (caller)
  239. Revision 1.15 2003/05/28 23:18:31 florian
  240. * started to fix and clean up the sparc port
  241. Revision 1.14 2003/05/07 11:55:34 mazen
  242. - unused units removed from uses clause
  243. - unused variables removed from implemntation declarations
  244. Revision 1.13 2003/05/06 14:55:27 mazen
  245. * comment changed to ;# instead of ##
  246. * .bss section changed to .section ".bss"
  247. Revision 1.12 2003/03/15 22:51:58 mazen
  248. * remaking sparc rtl compile
  249. Revision 1.11 2003/01/08 18:43:58 daniel
  250. * Tregister changed into a record
  251. Revision 1.10 2002/11/16 15:29:16 florian
  252. * fixed Cish syntax
  253. Revision 1.9 2002/11/10 19:07:46 mazen
  254. * SPARC calling mechanism almost OK (as in GCC./mppcsparc )
  255. Revision 1.8 2002/10/25 19:37:53 mazen
  256. * bug of references name missing last character fixed
  257. Revision 1.7 2002/10/20 19:01:38 mazen
  258. + op_raddr_reg and op_caddr_reg added to fix functions prologue
  259. Revision 1.6 2002/10/15 09:00:28 mazen
  260. * sone coding style modified
  261. }