cpupara.pas 9.3 KB

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