cpupara.pas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. PowerPC specific calling conventions
  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. { PowerPC specific calling conventions are handled by this unit
  19. }
  20. unit cpupara;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. cpubase,
  25. symconst,symbase,symdef,paramgr;
  26. type
  27. tppcparamanager = class(tparamanager)
  28. function getintparaloc(nr : longint) : tparalocation;override;
  29. procedure create_param_loc_info(p : tabstractprocdef);override;
  30. function getfuncretparaloc(p : tabstractprocdef) : tparalocation;override;
  31. end;
  32. implementation
  33. uses
  34. verbose,
  35. globtype,
  36. cpuinfo,cginfo,
  37. symtype,defbase;
  38. function tppcparamanager.getintparaloc(nr : longint) : tparalocation;
  39. begin
  40. fillchar(result,sizeof(tparalocation),0);
  41. if nr<1 then
  42. internalerror(2002070801)
  43. else if nr<=8 then
  44. begin
  45. result.loc:=LOC_REGISTER;
  46. result.register:=tregister(longint(R_2)+nr);
  47. end
  48. else
  49. begin
  50. result.loc:=LOC_REFERENCE;
  51. result.reference.index:=stack_pointer_reg;
  52. result.reference.offset:=(nr-8)*4;
  53. end;
  54. end;
  55. function getparaloc(p : tdef) : tloc;
  56. begin
  57. { Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER
  58. if push_addr_param for the def is true
  59. }
  60. case p.deftype of
  61. orddef:
  62. getparaloc:=LOC_REGISTER;
  63. floatdef:
  64. getparaloc:=LOC_FPUREGISTER;
  65. enumdef:
  66. getparaloc:=LOC_REGISTER;
  67. pointerdef:
  68. getparaloc:=LOC_REGISTER;
  69. formaldef:
  70. getparaloc:=LOC_REGISTER;
  71. classrefdef:
  72. getparaloc:=LOC_REGISTER;
  73. recorddef:
  74. getparaloc:=LOC_REFERENCE;
  75. objectdef:
  76. if is_object(p) then
  77. getparaloc:=LOC_REFERENCE
  78. else
  79. getparaloc:=LOC_REGISTER;
  80. stringdef:
  81. if is_shortstring(p) or is_longstring(p) then
  82. getparaloc:=LOC_REFERENCE
  83. else
  84. getparaloc:=LOC_REGISTER;
  85. procvardef:
  86. if (po_methodpointer in tprocvardef(p).procoptions) then
  87. getparaloc:=LOC_REFERENCE
  88. else
  89. getparaloc:=LOC_REGISTER;
  90. filedef:
  91. getparaloc:=LOC_REGISTER;
  92. arraydef:
  93. getparaloc:=LOC_REFERENCE;
  94. { avoid problems with errornous definitions }
  95. errordef:
  96. getparaloc:=LOC_REGISTER;
  97. else
  98. internalerror(2002071001);
  99. end;
  100. end;
  101. procedure tppcparamanager.create_param_loc_info(p : tabstractprocdef);
  102. var
  103. nextintreg,nextfloatreg,nextmmreg : tregister;
  104. stack_offset : aword;
  105. hp : tparaitem;
  106. loc : tloc;
  107. begin
  108. nextintreg:=R_3;
  109. nextfloatreg:=R_F1;
  110. nextmmreg:=R_M1;
  111. stack_offset:=0;
  112. { pointer for structured results ? }
  113. { !!!nextintreg:=R_4; }
  114. { frame pointer for nested procedures? }
  115. { inc(nextintreg); }
  116. { constructor? }
  117. { destructor? }
  118. hp:=tparaitem(p.para.last);
  119. while assigned(hp) do
  120. begin
  121. loc:=getparaloc(hp.paratype.def);
  122. case loc of
  123. LOC_REGISTER:
  124. begin
  125. hp.paraloc.size:=OS_32;
  126. if nextintreg<=R_8 then
  127. begin
  128. hp.paraloc.loc:=LOC_REGISTER;
  129. hp.paraloc.register:=nextintreg;
  130. inc(nextintreg);
  131. end
  132. else
  133. begin
  134. hp.paraloc.loc:=LOC_REFERENCE;
  135. hp.paraloc.reference.index:=stack_pointer_reg;
  136. hp.paraloc.reference.offset:=stack_offset;
  137. inc(stack_offset,4);
  138. end;
  139. end;
  140. LOC_FPUREGISTER:
  141. begin
  142. hp.paraloc.size:=OS_F32;
  143. if hp.paratyp in [vs_var,vs_out] then
  144. begin
  145. if nextintreg<=R_8 then
  146. begin
  147. hp.paraloc.loc:=LOC_REGISTER;
  148. hp.paraloc.register:=nextintreg;
  149. inc(nextintreg);
  150. end
  151. else
  152. begin
  153. {!!!!!!!}
  154. internalerror(2002071006);
  155. end;
  156. end
  157. else if nextfloatreg<=R_F8 then
  158. begin
  159. hp.paraloc.loc:=LOC_FPUREGISTER;
  160. hp.paraloc.register:=nextfloatreg;
  161. inc(nextfloatreg);
  162. end
  163. else
  164. begin
  165. {!!!!!!!}
  166. internalerror(2002071004);
  167. end;
  168. end;
  169. LOC_REFERENCE:
  170. begin
  171. hp.paraloc.size:=OS_32;
  172. if push_addr_param(hp.paratype.def,p.proccalloption in [pocall_cdecl,pocall_cppdecl]) or (hp.paratyp in [vs_var,vs_out]) then
  173. begin
  174. if nextintreg<=R_8 then
  175. begin
  176. hp.paraloc.loc:=LOC_REGISTER;
  177. hp.paraloc.register:=nextintreg;
  178. inc(nextintreg);
  179. end
  180. else
  181. begin
  182. {!!!!!!!}
  183. internalerror(2002071005);
  184. end;
  185. end
  186. else
  187. begin
  188. hp.paraloc.loc:=LOC_REFERENCE;
  189. hp.paraloc.reference.index:=stack_pointer_reg;
  190. hp.paraloc.reference.offset:=stack_offset;
  191. inc(stack_offset,hp.paratype.def.size);
  192. end;
  193. end;
  194. else
  195. internalerror(2002071002);
  196. end;
  197. hp:=tparaitem(hp.previous);
  198. end;
  199. end;
  200. function tppcparamanager.getfuncretparaloc(p : tabstractprocdef) : tparalocation;
  201. begin
  202. getfuncretparaloc.loc:=LOC_REGISTER;
  203. getfuncretparaloc.register:=R_3;
  204. end;
  205. begin
  206. paramanager:=tppcparamanager.create;
  207. end.
  208. {
  209. $Log$
  210. Revision 1.9 2002-08-31 12:43:31 florian
  211. * ppc compilation fixed
  212. Revision 1.8 2002/08/18 10:42:38 florian
  213. * remaining assembler writer bugs fixed, the errors in the
  214. system unit are inline assembler problems
  215. Revision 1.7 2002/08/17 22:09:47 florian
  216. * result type handling in tcgcal.pass_2 overhauled
  217. * better tnode.dowrite
  218. * some ppc stuff fixed
  219. Revision 1.6 2002/08/13 21:40:58 florian
  220. * more fixes for ppc calling conventions
  221. Revision 1.5 2002/07/30 20:50:44 florian
  222. * the code generator knows now if parameters are in registers
  223. Revision 1.4 2002/07/28 20:45:22 florian
  224. + added direct assembler reader for PowerPC
  225. Revision 1.3 2002/07/26 22:22:10 florian
  226. * several PowerPC related fixes to get forward with system unit compilation
  227. Revision 1.2 2002/07/11 14:41:34 florian
  228. * start of the new generic parameter handling
  229. Revision 1.1 2002/07/07 09:44:32 florian
  230. * powerpc target fixed, very simple units can be compiled
  231. }