cpugas.pas 7.1 KB

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