cpugas.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. var
  51. s:string;
  52. begin
  53. s:='';
  54. with ref do
  55. begin
  56. inc(offset,offsetfixup);
  57. if assigned(symbol)
  58. then
  59. s:=s+symbol.name;
  60. if base<>R_NONE
  61. then
  62. s:=s+gas_reg2str[base]+'+';
  63. if index<>R_NONE
  64. then
  65. begin
  66. if ScaleFactor<>0
  67. then
  68. s:=s+ToStr(ScaleFactor)+'*';
  69. s:=s+gas_reg2str[index]+'+';
  70. end;
  71. if Offset=0
  72. then
  73. SetLength(s,Length(s)-1)
  74. else if offset<0
  75. then
  76. begin
  77. SetLength(s,Length(s)-1);
  78. s:=s+tostr(offset);
  79. end
  80. else if offset>0
  81. then
  82. if assigned(symbol)
  83. then
  84. s:=s+'+'+tostr(offset)
  85. else
  86. s:=s+tostr(offset);
  87. end;
  88. getreferencestring:=s;
  89. end;
  90. function getopstr(const Oper:TOper):string;
  91. var
  92. hs:string;
  93. begin
  94. with Oper do
  95. case typ of
  96. top_reg:
  97. getopstr:=gas_reg2str[reg];
  98. top_ref:
  99. getopstr:='['+getreferencestring(ref^)+']';
  100. top_const:
  101. getopstr:={'$'+}tostr(longint(val));
  102. top_symbol:
  103. begin
  104. if assigned(sym) then
  105. hs:={'$'+}sym.name
  106. else
  107. hs:='$';
  108. if symofs>0 then
  109. hs:=hs+'+'+tostr(symofs)
  110. else
  111. if symofs<0 then
  112. hs:=hs+tostr(symofs)
  113. else
  114. if not(assigned(sym)) then
  115. hs:=hs+'0';
  116. getopstr:=hs;
  117. end;
  118. top_raddr:
  119. getopstr:=std_reg2str[reg1]+'+'+std_reg2str[reg2];
  120. top_caddr:
  121. getopstr:=std_reg2str[regb]+'+'+ToStr(const13);
  122. else
  123. internalerror(10001);
  124. end;
  125. end;
  126. (*
  127. function getopstr_jmp(const Oper:TOper):string;
  128. var
  129. hs:string;
  130. begin
  131. with Oper do
  132. case typ of
  133. top_reg:
  134. getopstr_jmp:=gas_reg2str[reg]+'+';
  135. top_ref:
  136. getopstr_jmp:=GetReferenceString(ref^);
  137. top_const:
  138. getopstr_jmp:=tostr(longint(val));
  139. top_symbol:
  140. begin
  141. hs:=sym.name;
  142. if symofs>0 then
  143. hs:=hs+'+'+tostr(symofs)
  144. else
  145. if symofs<0 then
  146. hs:=hs+tostr(symofs);
  147. getopstr_jmp:=hs;
  148. end;
  149. else
  150. internalerror(10001);
  151. end;
  152. end;*)
  153. {****************************************************************************
  154. TSPARCATTASMOUTPUT
  155. ****************************************************************************}
  156. procedure TGasSPARC.WriteInstruction(hp:Tai);
  157. var
  158. Op:TAsmOp;
  159. s:String;
  160. i:Integer;
  161. begin
  162. if hp.typ<>ait_instruction
  163. then
  164. Exit;
  165. taicpu(hp).SetOperandOrder(op_att);
  166. op:=taicpu(hp).opcode;
  167. {call maybe not translated to call}
  168. s:=#9+std_op2str[op]+cond2str[taicpu(hp).condition];
  169. {process operands}
  170. s:=#9+std_op2str[op];
  171. if taicpu(hp).ops>0
  172. then
  173. begin
  174. s+=#9+getopstr(taicpu(hp).oper[0]);
  175. for i:=1 to taicpu(hp).ops-1 do
  176. s+=','+getopstr(taicpu(hp).oper[i]);
  177. end;
  178. AsmWriteLn(s);
  179. end;
  180. {*****************************************************************************
  181. Initialize
  182. *****************************************************************************}
  183. const
  184. as_SPARC_as_info:TAsmInfo=(
  185. id:as_gas;
  186. idtxt:'AS';
  187. asmbin:'as';
  188. asmcmd:'-o $OBJ $ASM';
  189. supported_target:system_any;
  190. outputbinary:false;
  191. allowdirect:true;
  192. needar:true;
  193. labelprefix_only_inside_procedure:false;
  194. labelprefix:'.L';
  195. comment:'; ';
  196. secnames:({sec_none}'', {no section}
  197. {sec_code}'.text', {executable code}
  198. {sec_data}'.data', {initialized R/W data}
  199. {sec_bss}'.bss', {uninitialized R/W data}
  200. {sec_idata2}'.comment', {comments}
  201. {sec_idata4}'.debug', {debugging information}
  202. {sec_idata5}'.rodata', {RO data}
  203. {sec_idata6}'.line', {line numbers info for symbolic debug}
  204. {sec_idata7}'.init', {runtime intialization code}
  205. {sec_edata}'.fini', {runtime finalization code}
  206. {sec_stab}'.stab',
  207. {sec_stabstr} '.stabstr',
  208. {sec_common}'.note') {note info}
  209. );
  210. initialization
  211. RegisterAssembler(as_SPARC_as_info,TGasSPARC);
  212. end.
  213. {
  214. $Log$
  215. Revision 1.7 2002-10-20 19:01:38 mazen
  216. + op_raddr_reg and op_caddr_reg added to fix functions prologue
  217. Revision 1.6 2002/10/15 09:00:28 mazen
  218. * sone coding style modified
  219. }