cpugas.pas 6.7 KB

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