2
0

cpugas.pas 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 assigned(symbol) then
  41. begin
  42. if (base.number<>NR_NO) or (index.number<>NR_NO) then
  43. internalerror(2003052601);
  44. GetReferenceString:=symbol.name;
  45. if offset>0 then
  46. GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
  47. else if offset<0 then
  48. GetReferenceString:=GetReferenceString+ToStr(offset);
  49. case symaddr of
  50. refs_hi :
  51. GetReferenceString:='%hi('+GetReferenceString+')';
  52. refs_lo :
  53. GetReferenceString:='%lo('+GetReferenceString+')';
  54. end;
  55. end
  56. else
  57. begin
  58. GetReferenceString:='[';
  59. if base.number<>NR_NO then
  60. GetReferenceString:=GetReferenceString+std_reg2str[base.enum];
  61. if index.number=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+'+'+std_reg2str[index.enum];
  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:=std_reg2str[reg.enum];
  88. top_ref:
  89. getopstr:=getreferencestring(ref^);
  90. top_const:
  91. getopstr:=tostr(longint(val));
  92. top_symbol:
  93. begin
  94. if assigned(sym) then
  95. hs:={'$'+}sym.name
  96. else
  97. hs:='$';
  98. if symofs>0 then
  99. hs:=hs+'+'+tostr(symofs)
  100. else
  101. if symofs<0 then
  102. hs:=hs+tostr(symofs)
  103. else
  104. if not(assigned(sym)) then
  105. hs:=hs+'0';
  106. getopstr:=hs;
  107. end;
  108. else
  109. internalerror(10001);
  110. end;
  111. end;
  112. (*
  113. function getopstr_jmp(const Oper:TOper):string;
  114. var
  115. hs:string;
  116. begin
  117. with Oper do
  118. case typ of
  119. top_reg:
  120. getopstr_jmp:=gas_reg2str[reg]+'+';
  121. top_ref:
  122. getopstr_jmp:=GetReferenceString(ref^);
  123. top_const:
  124. getopstr_jmp:=tostr(longint(val));
  125. top_symbol:
  126. begin
  127. hs:=sym.name;
  128. if symofs>0 then
  129. hs:=hs+'+'+tostr(symofs)
  130. else
  131. if symofs<0 then
  132. hs:=hs+tostr(symofs);
  133. getopstr_jmp:=hs;
  134. end;
  135. else
  136. internalerror(10001);
  137. end;
  138. end;*)
  139. procedure TGasSPARC.WriteInstruction(hp:Tai);
  140. var
  141. Op:TAsmOp;
  142. s:String;
  143. i:Integer;
  144. begin
  145. if hp.typ<>ait_instruction then
  146. exit;
  147. op:=taicpu(hp).opcode;
  148. { call maybe not translated to call }
  149. s:=#9+std_op2str[op]+cond2str[taicpu(hp).condition];
  150. { process operands }
  151. s:=#9+std_op2str[op];
  152. if taicpu(hp).ops>0
  153. then
  154. begin
  155. s:=s+#9+getopstr(taicpu(hp).oper[0]);
  156. for i:=1 to taicpu(hp).ops-1 do
  157. s:=s+','+getopstr(taicpu(hp).oper[i]);
  158. end;
  159. AsmWriteLn(s);
  160. end;
  161. const
  162. as_SPARC_as_info:TAsmInfo=(
  163. id:as_gas;
  164. idtxt:'AS';
  165. asmbin:'as';
  166. asmcmd:'-o $OBJ $ASM';
  167. supported_target:system_any;
  168. outputbinary:false;
  169. allowdirect:true;
  170. needar:true;
  171. labelprefix_only_inside_procedure:false;
  172. labelprefix:'.L';
  173. comment:';#';
  174. secnames:({sec_none}'', {no section}
  175. {sec_code}'.text', {executable code}
  176. {sec_data}'.data', {initialized R/W data}
  177. {sec_bss}'.section ".bss"', {uninitialized R/W data}
  178. {sec_idata2}'.comment', {comments}
  179. {sec_idata4}'.debug', {debugging information}
  180. {sec_idata5}'.rodata', {RO data}
  181. {sec_idata6}'.line', {line numbers info for symbolic debug}
  182. {sec_idata7}'.init', {runtime intialization code}
  183. {sec_edata}'.fini', {runtime finalization code}
  184. {sec_stab}'.stab',
  185. {sec_stabstr} '.stabstr',
  186. {sec_common}'.note') {note info}
  187. );
  188. begin
  189. RegisterAssembler(as_SPARC_as_info,TGasSPARC);
  190. end.
  191. {
  192. $Log$
  193. Revision 1.19 2003-06-01 21:38:06 peter
  194. * getregisterfpu size parameter added
  195. * op_const_reg size parameter added
  196. * sparc updates
  197. Revision 1.18 2003/06/01 01:04:35 peter
  198. * reference fixes
  199. Revision 1.17 2003/05/31 01:00:51 peter
  200. * register fixes
  201. Revision 1.16 2003/05/30 23:57:08 peter
  202. * more sparc cleanup
  203. * accumulator removed, splitted in function_return_reg (called) and
  204. function_result_reg (caller)
  205. Revision 1.15 2003/05/28 23:18:31 florian
  206. * started to fix and clean up the sparc port
  207. Revision 1.14 2003/05/07 11:55:34 mazen
  208. - unused units removed from uses clause
  209. - unused variables removed from implemntation declarations
  210. Revision 1.13 2003/05/06 14:55:27 mazen
  211. * comment changed to ;# instead of ##
  212. * .bss section changed to .section ".bss"
  213. Revision 1.12 2003/03/15 22:51:58 mazen
  214. * remaking sparc rtl compile
  215. Revision 1.11 2003/01/08 18:43:58 daniel
  216. * Tregister changed into a record
  217. Revision 1.10 2002/11/16 15:29:16 florian
  218. * fixed Cish syntax
  219. Revision 1.9 2002/11/10 19:07:46 mazen
  220. * SPARC calling mechanism almost OK (as in GCC./mppcsparc )
  221. Revision 1.8 2002/10/25 19:37:53 mazen
  222. * bug of references name missing last character fixed
  223. Revision 1.7 2002/10/20 19:01:38 mazen
  224. + op_raddr_reg and op_caddr_reg added to fix functions prologue
  225. Revision 1.6 2002/10/15 09:00:28 mazen
  226. * sone coding style modified
  227. }