cpugas.pas 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. {******************************************************************************
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  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. This unit implements an asmoutput class for SPARC AT&T syntax
  18. }
  19. unit cpugas;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. cpubase,
  24. aasmtai,aasmcpu,assemble,aggas;
  25. type
  26. TGasSPARC=class(TGnuAssembler)
  27. procedure WriteInstruction(hp:Tai);override;
  28. end;
  29. implementation
  30. uses
  31. cutils,systems,
  32. verbose;
  33. function GetReferenceString(var ref:TReference):string;
  34. begin
  35. GetReferenceString:='';
  36. with ref do
  37. begin
  38. inc(offset,offsetfixup);
  39. offsetfixup:=0;
  40. if (base=NR_NO) and (index=NR_NO) then
  41. begin
  42. if assigned(symbol) then
  43. GetReferenceString:=symbol.name;
  44. if offset>0 then
  45. GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
  46. else if offset<0 then
  47. GetReferenceString:=GetReferenceString+ToStr(offset);
  48. case symaddr of
  49. refs_hi :
  50. GetReferenceString:='%hi('+GetReferenceString+')';
  51. refs_lo :
  52. GetReferenceString:='%lo('+GetReferenceString+')';
  53. end;
  54. end
  55. else
  56. begin
  57. if assigned(symbol) then
  58. internalerror(2003052601);
  59. GetReferenceString:='[';
  60. if base<>NR_NO then
  61. GetReferenceString:=GetReferenceString+gas_regname(base);
  62. if index=NR_NO then
  63. begin
  64. if (Offset<simm13lo) or (Offset>simm13hi) then
  65. internalerror(2003053008);
  66. if offset>0 then
  67. GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
  68. else if offset<0 then
  69. GetReferenceString:=GetReferenceString+ToStr(offset);
  70. end
  71. else
  72. begin
  73. if Offset<>0 then
  74. internalerror(2003052603);
  75. GetReferenceString:=GetReferenceString+'+'+gas_regname(index);
  76. end;
  77. GetReferenceString:=GetReferenceString+']';
  78. end;
  79. end;
  80. end;
  81. function getopstr(const Oper:TOper):string;
  82. var
  83. hs : string;
  84. begin
  85. with Oper do
  86. case typ of
  87. top_reg:
  88. getopstr:=gas_regname(reg);
  89. top_ref:
  90. getopstr:=getreferencestring(ref^);
  91. top_const:
  92. getopstr:=tostr(longint(val));
  93. top_symbol:
  94. begin
  95. if assigned(sym) then
  96. hs:={'$'+}sym.name
  97. else
  98. hs:='$';
  99. if symofs>0 then
  100. hs:=hs+'+'+tostr(symofs)
  101. else
  102. if symofs<0 then
  103. hs:=hs+tostr(symofs)
  104. else
  105. if not(assigned(sym)) then
  106. hs:=hs+'0';
  107. getopstr:=hs;
  108. end;
  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. { call maybe not translated to call }
  150. s:=#9+std_op2str[op]+cond2str[taicpu(hp).condition];
  151. if taicpu(hp).ops>0 then
  152. begin
  153. s:=s+#9+getopstr(taicpu(hp).oper[0]^);
  154. for i:=1 to taicpu(hp).ops-1 do
  155. s:=s+','+getopstr(taicpu(hp).oper[i]^);
  156. end;
  157. AsmWriteLn(s);
  158. end;
  159. const
  160. as_SPARC_as_info:TAsmInfo=(
  161. id:as_gas;
  162. idtxt:'AS';
  163. asmbin:'as';
  164. asmcmd:'-o $OBJ $ASM';
  165. supported_target:system_any;
  166. outputbinary:false;
  167. allowdirect:true;
  168. needar:true;
  169. labelprefix_only_inside_procedure:false;
  170. labelprefix:'.L';
  171. comment:';#';
  172. secnames:({sec_none}'', {no section}
  173. {sec_code}'.text', {executable code}
  174. {sec_data}'.data', {initialized R/W data}
  175. {sec_bss}'.section ".bss"', {uninitialized R/W data}
  176. {sec_idata2}'.comment', {comments}
  177. {sec_idata4}'.debug', {debugging information}
  178. {sec_idata5}'.rodata', {RO data}
  179. {sec_idata6}'.line', {line numbers info for symbolic debug}
  180. {sec_idata7}'.init', {runtime intialization code}
  181. {sec_edata}'.fini', {runtime finalization code}
  182. {sec_stab}'.stab',
  183. {sec_stabstr} '.stabstr',
  184. {sec_common}'.note') {note info}
  185. );
  186. begin
  187. RegisterAssembler(as_SPARC_as_info,TGasSPARC);
  188. end.
  189. {
  190. $Log$
  191. Revision 1.23 2003-10-24 11:22:50 mazen
  192. *fix related to toper==>poper
  193. Revision 1.22 2003/09/03 15:55:01 peter
  194. * NEWRA branch merged
  195. Revision 1.21.2.1 2003/09/01 21:02:55 peter
  196. * sparc updates for new tregister
  197. Revision 1.21 2003/07/08 21:25:00 peter
  198. * sparc fixes
  199. Revision 1.20 2003/07/02 22:18:04 peter
  200. * paraloc splitted in callerparaloc,calleeparaloc
  201. * sparc calling convention updates
  202. Revision 1.19 2003/06/01 21:38:06 peter
  203. * getregisterfpu size parameter added
  204. * op_const_reg size parameter added
  205. * sparc updates
  206. Revision 1.18 2003/06/01 01:04:35 peter
  207. * reference fixes
  208. Revision 1.17 2003/05/31 01:00:51 peter
  209. * register fixes
  210. Revision 1.16 2003/05/30 23:57:08 peter
  211. * more sparc cleanup
  212. * accumulator removed, splitted in function_return_reg (called) and
  213. function_result_reg (caller)
  214. Revision 1.15 2003/05/28 23:18:31 florian
  215. * started to fix and clean up the sparc port
  216. Revision 1.14 2003/05/07 11:55:34 mazen
  217. - unused units removed from uses clause
  218. - unused variables removed from implemntation declarations
  219. Revision 1.13 2003/05/06 14:55:27 mazen
  220. * comment changed to ;# instead of ##
  221. * .bss section changed to .section ".bss"
  222. Revision 1.12 2003/03/15 22:51:58 mazen
  223. * remaking sparc rtl compile
  224. Revision 1.11 2003/01/08 18:43:58 daniel
  225. * Tregister changed into a record
  226. Revision 1.10 2002/11/16 15:29:16 florian
  227. * fixed Cish syntax
  228. Revision 1.9 2002/11/10 19:07:46 mazen
  229. * SPARC calling mechanism almost OK (as in GCC./mppcsparc )
  230. Revision 1.8 2002/10/25 19:37:53 mazen
  231. * bug of references name missing last character fixed
  232. Revision 1.7 2002/10/20 19:01:38 mazen
  233. + op_raddr_reg and op_caddr_reg added to fix functions prologue
  234. Revision 1.6 2002/10/15 09:00:28 mazen
  235. * sone coding style modified
  236. }