cpugas.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. unit CpuGas;
  17. {This unit implements an asmoutput class for SPARC AT&T syntax}
  18. {$MACRO ON}{$INCLUDE fpcdefs.inc}
  19. interface
  20. uses
  21. cpubase,
  22. aasmtai,aasmcpu,assemble,aggas;
  23. type
  24. TGasSPARC=class(TGnuAssembler)
  25. procedure WriteInstruction(hp:Tai);override;
  26. end;
  27. implementation
  28. uses
  29. cutils,systems,
  30. verbose;
  31. {$DEFINE gas_reg2str:=std_reg2str}
  32. function GetReferenceString(var ref:TReference):string;
  33. begin
  34. GetReferenceString:='+';
  35. with ref do
  36. if assigned(symbol)
  37. then
  38. GetReferenceString:=symbol.name
  39. else
  40. begin
  41. inc(offset,offsetfixup);
  42. if base.enum<>R_NONE
  43. then
  44. GetReferenceString:=gas_reg2str[base.enum]+'+';
  45. if index.enum<>R_NONE
  46. then
  47. begin
  48. if ScaleFactor<>0
  49. then
  50. GetReferenceString:=GetReferenceString+ToStr(ScaleFactor)+'*';
  51. GetReferenceString:=GetReferenceString+gas_reg2str[index.enum]+'+';
  52. end;
  53. if Offset=0
  54. then
  55. SetLength(GetReferenceString,Length(GetReferenceString)-1)
  56. else if offset<0
  57. then
  58. begin
  59. SetLength(GetReferenceString,Length(GetReferenceString)-1);
  60. GetReferenceString:=GetReferenceString+tostr(offset);
  61. end
  62. else if offset>0
  63. then
  64. GetReferenceString:=GetReferenceString+tostr(offset);
  65. end;
  66. end;
  67. function getopstr(const Oper:TOper):string;
  68. var
  69. hs:string;
  70. begin
  71. with Oper do
  72. case typ of
  73. top_reg:
  74. getopstr:=gas_reg2str[reg.enum];
  75. top_ref:
  76. getopstr:='['+getreferencestring(ref^)+']';
  77. top_const:
  78. getopstr:={'$'+}tostr(longint(val));
  79. top_symbol:
  80. begin
  81. if assigned(sym) then
  82. hs:={'$'+}sym.name
  83. else
  84. hs:='$';
  85. if symofs>0 then
  86. hs:=hs+'+'+tostr(symofs)
  87. else
  88. if symofs<0 then
  89. hs:=hs+tostr(symofs)
  90. else
  91. if not(assigned(sym)) then
  92. hs:=hs+'0';
  93. getopstr:=hs;
  94. end;
  95. top_raddr:
  96. getopstr:=std_reg2str[reg1.enum]+'+'+std_reg2str[reg2.enum];
  97. top_caddr:
  98. getopstr:=std_reg2str[regb.enum]+'+'+ToStr(const13);
  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. {****************************************************************************
  131. TSPARCATTASMOUTPUT
  132. ****************************************************************************}
  133. procedure TGasSPARC.WriteInstruction(hp:Tai);
  134. var
  135. Op:TAsmOp;
  136. s:String;
  137. i:Integer;
  138. begin
  139. if hp.typ<>ait_instruction
  140. then
  141. Exit;
  142. op:=taicpu(hp).opcode;
  143. {call maybe not translated to call}
  144. s:=#9+std_op2str[op]+cond2str[taicpu(hp).condition];
  145. {process operands}
  146. s:=#9+std_op2str[op];
  147. if taicpu(hp).ops>0
  148. then
  149. begin
  150. s:=s+#9+getopstr(taicpu(hp).oper[0]);
  151. for i:=1 to taicpu(hp).ops-1 do
  152. s:=s+','+getopstr(taicpu(hp).oper[i]);
  153. end;
  154. AsmWriteLn(s);
  155. end;
  156. {*****************************************************************************
  157. Initialize
  158. *****************************************************************************}
  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. initialization
  187. RegisterAssembler(as_SPARC_as_info,TGasSPARC);
  188. end.
  189. {
  190. $Log$
  191. Revision 1.14 2003-05-07 11:55:34 mazen
  192. - unused units removed from uses clause
  193. - unused variables removed from implemntation declarations
  194. Revision 1.13 2003/05/06 14:55:27 mazen
  195. * comment changed to ;# instead of ##
  196. * .bss section changed to .section ".bss"
  197. Revision 1.12 2003/03/15 22:51:58 mazen
  198. * remaking sparc rtl compile
  199. Revision 1.11 2003/01/08 18:43:58 daniel
  200. * Tregister changed into a record
  201. Revision 1.10 2002/11/16 15:29:16 florian
  202. * fixed Cish syntax
  203. Revision 1.9 2002/11/10 19:07:46 mazen
  204. * SPARC calling mechanism almost OK (as in GCC./mppcsparc )
  205. Revision 1.8 2002/10/25 19:37:53 mazen
  206. * bug of references name missing last character fixed
  207. Revision 1.7 2002/10/20 19:01:38 mazen
  208. + op_raddr_reg and op_caddr_reg added to fix functions prologue
  209. Revision 1.6 2002/10/15 09:00:28 mazen
  210. * sone coding style modified
  211. }