cpupara.pas 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. hp.paraloc.sp_fixup:=0;
  123. case loc of
  124. LOC_REGISTER:
  125. begin
  126. hp.paraloc.size:=OS_32;
  127. if nextintreg<=R_8 then
  128. begin
  129. hp.paraloc.loc:=LOC_REGISTER;
  130. hp.paraloc.register:=nextintreg;
  131. inc(nextintreg);
  132. end
  133. else
  134. begin
  135. hp.paraloc.loc:=LOC_REFERENCE;
  136. hp.paraloc.reference.index:=stack_pointer_reg;
  137. hp.paraloc.reference.offset:=stack_offset;
  138. inc(stack_offset,4);
  139. end;
  140. end;
  141. LOC_FPUREGISTER:
  142. begin
  143. hp.paraloc.size:=OS_F32;
  144. if hp.paratyp in [vs_var,vs_out] then
  145. begin
  146. if nextintreg<=R_8 then
  147. begin
  148. hp.paraloc.loc:=LOC_REGISTER;
  149. hp.paraloc.register:=nextintreg;
  150. inc(nextintreg);
  151. end
  152. else
  153. begin
  154. {!!!!!!!}
  155. internalerror(2002071006);
  156. end;
  157. end
  158. else if nextfloatreg<=R_F8 then
  159. begin
  160. hp.paraloc.loc:=LOC_FPUREGISTER;
  161. hp.paraloc.register:=nextfloatreg;
  162. inc(nextfloatreg);
  163. end
  164. else
  165. begin
  166. {!!!!!!!}
  167. internalerror(2002071004);
  168. end;
  169. end;
  170. LOC_REFERENCE:
  171. begin
  172. hp.paraloc.size:=OS_32;
  173. if push_addr_param(hp.paratype.def,p.proccalloption in [pocall_cdecl,pocall_cppdecl]) or (hp.paratyp in [vs_var,vs_out]) then
  174. begin
  175. if nextintreg<=R_8 then
  176. begin
  177. hp.paraloc.loc:=LOC_REGISTER;
  178. hp.paraloc.register:=nextintreg;
  179. inc(nextintreg);
  180. end
  181. else
  182. begin
  183. hp.paraloc.loc:=LOC_REFERENCE;
  184. hp.paraloc.reference.index:=stack_pointer_reg;
  185. hp.paraloc.reference.offset:=stack_offset;
  186. inc(stack_offset,4);
  187. end;
  188. end
  189. else
  190. begin
  191. hp.paraloc.loc:=LOC_REFERENCE;
  192. hp.paraloc.reference.index:=stack_pointer_reg;
  193. hp.paraloc.reference.offset:=stack_offset;
  194. inc(stack_offset,hp.paratype.def.size);
  195. end;
  196. end;
  197. else
  198. internalerror(2002071002);
  199. end;
  200. hp:=tparaitem(hp.previous);
  201. end;
  202. end;
  203. function tppcparamanager.getfuncretparaloc(p : tabstractprocdef) : tparalocation;
  204. begin
  205. getfuncretparaloc.loc:=LOC_REGISTER;
  206. getfuncretparaloc.register:=R_3;
  207. end;
  208. begin
  209. paramanager:=tppcparamanager.create;
  210. end.
  211. {
  212. $Log$
  213. Revision 1.10 2002-09-01 21:04:49 florian
  214. * several powerpc related stuff fixed
  215. Revision 1.9 2002/08/31 12:43:31 florian
  216. * ppc compilation fixed
  217. Revision 1.8 2002/08/18 10:42:38 florian
  218. * remaining assembler writer bugs fixed, the errors in the
  219. system unit are inline assembler problems
  220. Revision 1.7 2002/08/17 22:09:47 florian
  221. * result type handling in tcgcal.pass_2 overhauled
  222. * better tnode.dowrite
  223. * some ppc stuff fixed
  224. Revision 1.6 2002/08/13 21:40:58 florian
  225. * more fixes for ppc calling conventions
  226. Revision 1.5 2002/07/30 20:50:44 florian
  227. * the code generator knows now if parameters are in registers
  228. Revision 1.4 2002/07/28 20:45:22 florian
  229. + added direct assembler reader for PowerPC
  230. Revision 1.3 2002/07/26 22:22:10 florian
  231. * several PowerPC related fixes to get forward with system unit compilation
  232. Revision 1.2 2002/07/11 14:41:34 florian
  233. * start of the new generic parameter handling
  234. Revision 1.1 2002/07/07 09:44:32 florian
  235. * powerpc target fixed, very simple units can be compiled
  236. }