cpupara.pas 9.4 KB

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