agarmgas.pas 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. {
  2. $Id$
  3. Copyright (c) 2003 by Florian Klaempfl
  4. This unit implements an asm for the ARM
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. { This unit implements the GNU Assembler writer for the ARM
  19. }
  20. unit agarmgas;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. aasmtai,
  25. aggas,
  26. cpubase,
  27. cginfo;
  28. type
  29. PARMGNUAssembler=^TARMGNUAssembler;
  30. TARMGNUAssembler=class(TGNUassembler)
  31. procedure WriteInstruction(hp : tai);override;
  32. end;
  33. const
  34. gas_shiftmode2str : array[tshiftmode] of string[3] = (
  35. '','lsl','lsr','asr','ror','rrx');
  36. implementation
  37. uses
  38. cutils,globals,verbose,
  39. systems,
  40. assemble,
  41. aasmcpu,
  42. itarmgas;
  43. const
  44. as_arm_gas_info : tasminfo =
  45. (
  46. id : as_gas;
  47. idtxt : 'AS';
  48. asmbin : 'as';
  49. asmcmd : '-o $OBJ $ASM';
  50. supported_target : system_any;
  51. outputbinary: false;
  52. allowdirect : true;
  53. needar : true;
  54. labelprefix_only_inside_procedure : false;
  55. labelprefix : '.L';
  56. comment : '# ';
  57. secnames : ('',
  58. '.text','.data','.text',
  59. '','','','','','',
  60. '.stab','.stabstr','COMMON')
  61. );
  62. function getreferencestring(var ref : treference) : string;
  63. var
  64. s : string;
  65. begin
  66. with ref do
  67. begin
  68. inc(offset,offsetfixup);
  69. {$ifdef extdebug}
  70. // if base=NR_NO then
  71. // internalerror(200308292);
  72. // if ((index<>NR_NO) or (shiftmode<>SM_None)) and ((offset<>0) or (symbol<>nil)) then
  73. // internalerror(200308293);
  74. {$endif extdebug}
  75. if assigned(symbol) then
  76. begin
  77. if (base<>NR_NO) and not(is_pc(base)) then
  78. internalerror(200309011);
  79. s:=symbol.name;
  80. if offset<0 then
  81. s:=s+tostr(offset)
  82. else if offset>0 then
  83. s:=s+'+'+tostr(offset);
  84. end
  85. else
  86. begin
  87. s:='['+gas_regname(base);
  88. if addressmode=AM_POSTINDEXED then
  89. s:=s+']';
  90. if index<>NR_NO then
  91. begin
  92. if signindex<0 then
  93. s:=s+', -'
  94. else
  95. s:=s+', ';
  96. s:=s+gas_regname(index);
  97. if shiftmode<>SM_None then
  98. s:=s+' ,'+gas_shiftmode2str[shiftmode]+' #'+tostr(shiftimm);
  99. end
  100. else if offset<>0 then
  101. s:=s+', #'+tostr(offset);
  102. case addressmode of
  103. AM_OFFSET:
  104. s:=s+']';
  105. AM_PREINDEXED:
  106. s:=s+']!';
  107. end;
  108. end;
  109. end;
  110. getreferencestring:=s;
  111. end;
  112. const
  113. shiftmode2str: array[tshiftmode] of string[3] = ('','lsl','lsr','asr','ror','rrx');
  114. function getopstr(const o:toper) : string;
  115. var
  116. hs : string;
  117. first : boolean;
  118. r : tregister;
  119. begin
  120. case o.typ of
  121. top_reg:
  122. getopstr:=gas_regname(o.reg);
  123. top_shifterop:
  124. begin
  125. if (o.shifterop^.rs<>NR_NO) and (o.shifterop^.shiftimm=0) then
  126. getopstr:=shiftmode2str[o.shifterop^.shiftmode]+' '+gas_regname(o.shifterop^.rs)
  127. else if (o.shifterop^.rs=NR_NO) then
  128. getopstr:=shiftmode2str[o.shifterop^.shiftmode]+' #'+tostr(o.shifterop^.shiftimm)
  129. else internalerror(200308282);
  130. end;
  131. top_const:
  132. getopstr:='#'+tostr(longint(o.val));
  133. top_regset:
  134. begin
  135. getopstr:='{';
  136. first:=true;
  137. for r:=RS_R0 to RS_R15 do
  138. if r in o.regset then
  139. begin
  140. if not(first) then
  141. getopstr:=getopstr+',';
  142. getopstr:=getopstr+gas_regname(newreg(R_INTREGISTER,r,R_SUBWHOLE));
  143. first:=false;
  144. end;
  145. getopstr:=getopstr+'}';
  146. end;
  147. top_ref:
  148. getopstr:=getreferencestring(o.ref^);
  149. top_symbol:
  150. begin
  151. hs:=o.sym.name;
  152. if o.symofs>0 then
  153. hs:=hs+'+'+tostr(o.symofs)
  154. else
  155. if o.symofs<0 then
  156. hs:=hs+tostr(o.symofs);
  157. getopstr:=hs;
  158. end;
  159. else
  160. internalerror(2002070604);
  161. end;
  162. end;
  163. Procedure TARMGNUAssembler.WriteInstruction(hp : tai);
  164. var op: TAsmOp;
  165. s: string;
  166. i: byte;
  167. sep: string[3];
  168. begin
  169. op:=taicpu(hp).opcode;
  170. s:=#9+gas_op2str[op]+cond2str[taicpu(hp).condition]+oppostfix2str[taicpu(hp).oppostfix];
  171. if taicpu(hp).ops<>0 then
  172. begin
  173. sep:=#9;
  174. for i:=0 to taicpu(hp).ops-1 do
  175. begin
  176. // debug code
  177. // writeln(s);
  178. // writeln(taicpu(hp).fileinfo.line);
  179. s:=s+sep+getopstr(taicpu(hp).oper[i]);
  180. sep:=',';
  181. end;
  182. end;
  183. AsmWriteLn(s);
  184. end;
  185. begin
  186. RegisterAssembler(as_arm_gas_info,TARMGNUAssembler);
  187. end.
  188. {
  189. $Log$
  190. Revision 1.10 2003-09-05 23:57:01 florian
  191. * arm is working again as before the new register naming scheme was implemented
  192. Revision 1.9 2003/09/04 00:15:29 florian
  193. * first bunch of adaptions of arm compiler for new register type
  194. Revision 1.8 2003/09/03 19:10:30 florian
  195. * initial revision of new register naming
  196. Revision 1.7 2003/09/01 15:11:16 florian
  197. * fixed reference handling
  198. * fixed operand postfix for floating point instructions
  199. * fixed wrong shifter constant handling
  200. Revision 1.6 2003/08/29 21:36:28 florian
  201. * fixed procedure entry/exit code
  202. * started to fix reference handling
  203. Revision 1.5 2003/08/28 13:26:10 florian
  204. * another couple of arm fixes
  205. Revision 1.4 2003/08/28 00:05:29 florian
  206. * today's arm patches
  207. Revision 1.3 2003/08/24 12:27:26 florian
  208. * continued to work on the arm port
  209. Revision 1.2 2003/08/20 15:50:12 florian
  210. * more arm stuff
  211. Revision 1.1 2003/08/16 13:23:01 florian
  212. * several arm related stuff fixed
  213. }