cpugas.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. cclasses,cpubase,
  22. globals,
  23. aasmbase,aasmtai,aasmcpu,assemble,aggas;
  24. type
  25. TGasSPARC=class(TGnuAssembler)
  26. procedure WriteInstruction(hp:Tai);override;
  27. end;
  28. implementation
  29. uses
  30. finput,
  31. cutils,systems,
  32. verbose;
  33. {$DEFINE gas_reg2str:=std_reg2str}
  34. const
  35. line_length = 70;
  36. var
  37. {$ifdef GDB}
  38. n_line:byte; { different types of source lines }
  39. linecount,
  40. includecount:longint;
  41. funcname:pchar;
  42. stabslastfileinfo:tfileposinfo;
  43. {$endif}
  44. lastsec:tsection; { last section type written }
  45. lastfileinfo:tfileposinfo;
  46. infile,
  47. lastinfile:tinputfile;
  48. symendcount:longint;
  49. function GetReferenceString(var ref:TReference):string;
  50. begin
  51. GetReferenceString:='+';
  52. with ref do
  53. if assigned(symbol)
  54. then
  55. GetReferenceString:=symbol.name
  56. else
  57. begin
  58. inc(offset,offsetfixup);
  59. if base<>R_NONE
  60. then
  61. GetReferenceString:=gas_reg2str[base]+'+';
  62. if index<>R_NONE
  63. then
  64. begin
  65. if ScaleFactor<>0
  66. then
  67. GetReferenceString:=GetReferenceString+ToStr(ScaleFactor)+'*';
  68. GetReferenceString:=GetReferenceString+gas_reg2str[index]+'+';
  69. end;
  70. if Offset=0
  71. then
  72. SetLength(GetReferenceString,Length(GetReferenceString)-1)
  73. else if offset<0
  74. then
  75. begin
  76. SetLength(GetReferenceString,Length(GetReferenceString)-1);
  77. GetReferenceString:=GetReferenceString+tostr(offset);
  78. end
  79. else if offset>0
  80. then
  81. GetReferenceString:=GetReferenceString+tostr(offset);
  82. end;
  83. end;
  84. function getopstr(const Oper:TOper):string;
  85. var
  86. hs:string;
  87. begin
  88. with Oper do
  89. case typ of
  90. top_reg:
  91. getopstr:=gas_reg2str[reg];
  92. top_ref:
  93. getopstr:='['+getreferencestring(ref^)+']';
  94. top_const:
  95. getopstr:={'$'+}tostr(longint(val));
  96. top_symbol:
  97. begin
  98. if assigned(sym) then
  99. hs:={'$'+}sym.name
  100. else
  101. hs:='$';
  102. if symofs>0 then
  103. hs:=hs+'+'+tostr(symofs)
  104. else
  105. if symofs<0 then
  106. hs:=hs+tostr(symofs)
  107. else
  108. if not(assigned(sym)) then
  109. hs:=hs+'0';
  110. getopstr:=hs;
  111. end;
  112. top_raddr:
  113. getopstr:=std_reg2str[reg1]+'+'+std_reg2str[reg2];
  114. top_caddr:
  115. getopstr:=std_reg2str[regb]+'+'+ToStr(const13);
  116. else
  117. internalerror(10001);
  118. end;
  119. end;
  120. (*
  121. function getopstr_jmp(const Oper:TOper):string;
  122. var
  123. hs:string;
  124. begin
  125. with Oper do
  126. case typ of
  127. top_reg:
  128. getopstr_jmp:=gas_reg2str[reg]+'+';
  129. top_ref:
  130. getopstr_jmp:=GetReferenceString(ref^);
  131. top_const:
  132. getopstr_jmp:=tostr(longint(val));
  133. top_symbol:
  134. begin
  135. hs:=sym.name;
  136. if symofs>0 then
  137. hs:=hs+'+'+tostr(symofs)
  138. else
  139. if symofs<0 then
  140. hs:=hs+tostr(symofs);
  141. getopstr_jmp:=hs;
  142. end;
  143. else
  144. internalerror(10001);
  145. end;
  146. end;*)
  147. {****************************************************************************
  148. TSPARCATTASMOUTPUT
  149. ****************************************************************************}
  150. procedure TGasSPARC.WriteInstruction(hp:Tai);
  151. var
  152. Op:TAsmOp;
  153. s:String;
  154. i:Integer;
  155. begin
  156. if hp.typ<>ait_instruction
  157. then
  158. Exit;
  159. op:=taicpu(hp).opcode;
  160. {call maybe not translated to call}
  161. s:=#9+std_op2str[op]+cond2str[taicpu(hp).condition];
  162. {process operands}
  163. s:=#9+std_op2str[op];
  164. if taicpu(hp).ops>0
  165. then
  166. begin
  167. s:=s+#9+getopstr(taicpu(hp).oper[0]);
  168. for i:=1 to taicpu(hp).ops-1 do
  169. s:=s+','+getopstr(taicpu(hp).oper[i]);
  170. end;
  171. AsmWriteLn(s);
  172. end;
  173. {*****************************************************************************
  174. Initialize
  175. *****************************************************************************}
  176. const
  177. as_SPARC_as_info:TAsmInfo=(
  178. id:as_gas;
  179. idtxt:'AS';
  180. asmbin:'as';
  181. asmcmd:'-o $OBJ $ASM';
  182. supported_target:system_any;
  183. outputbinary:false;
  184. allowdirect:true;
  185. needar:true;
  186. labelprefix_only_inside_procedure:false;
  187. labelprefix:'.L';
  188. comment:'; ';
  189. secnames:({sec_none}'', {no section}
  190. {sec_code}'.text', {executable code}
  191. {sec_data}'.data', {initialized R/W data}
  192. {sec_bss}'.bss', {uninitialized R/W data}
  193. {sec_idata2}'.comment', {comments}
  194. {sec_idata4}'.debug', {debugging information}
  195. {sec_idata5}'.rodata', {RO data}
  196. {sec_idata6}'.line', {line numbers info for symbolic debug}
  197. {sec_idata7}'.init', {runtime intialization code}
  198. {sec_edata}'.fini', {runtime finalization code}
  199. {sec_stab}'.stab',
  200. {sec_stabstr} '.stabstr',
  201. {sec_common}'.note') {note info}
  202. );
  203. initialization
  204. RegisterAssembler(as_SPARC_as_info,TGasSPARC);
  205. end.
  206. {
  207. $Log$
  208. Revision 1.10 2002-11-16 15:29:16 florian
  209. * fixed Cish syntax
  210. Revision 1.9 2002/11/10 19:07:46 mazen
  211. * SPARC calling mechanism almost OK (as in GCC./mppcsparc )
  212. Revision 1.8 2002/10/25 19:37:53 mazen
  213. * bug of references name missing last character fixed
  214. Revision 1.7 2002/10/20 19:01:38 mazen
  215. + op_raddr_reg and op_caddr_reg added to fix functions prologue
  216. Revision 1.6 2002/10/15 09:00:28 mazen
  217. * sone coding style modified
  218. }