cpupara.pas 8.5 KB

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