cpupara.pas 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 getfuncretloc(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. if push_addr_param(hp.paratype.def) or (hp.paratyp in [vs_var,vs_out]) then
  171. begin
  172. if nextintreg<=R_8 then
  173. begin
  174. hp.paraloc.loc:=LOC_REGISTER;
  175. hp.paraloc.register:=nextintreg;
  176. inc(nextintreg);
  177. end
  178. else
  179. begin
  180. {!!!!!!!}
  181. internalerror(2002071005);
  182. end;
  183. end
  184. else
  185. begin
  186. hp.paraloc.loc:=LOC_REFERENCE;
  187. hp.paraloc.reference.index:=stack_pointer_reg;
  188. hp.paraloc.reference.offset:=stack_offset;
  189. inc(stack_offset,hp.paratype.def.size);
  190. end;
  191. end;
  192. else
  193. internalerror(2002071002);
  194. end;
  195. hp:=tparaitem(hp.previous);
  196. end;
  197. end;
  198. function tppcparamanager.getfuncretloc(p : tabstractprocdef) : tparalocation;
  199. begin
  200. getfuncretloc.loc:=LOC_REGISTER;
  201. getfuncretloc.register:=R_3;
  202. end;
  203. begin
  204. paramanager:=tppcparamanager.create;
  205. end.
  206. {
  207. $Log$
  208. Revision 1.6 2002-08-13 21:40:58 florian
  209. * more fixes for ppc calling conventions
  210. Revision 1.5 2002/07/30 20:50:44 florian
  211. * the code generator knows now if parameters are in registers
  212. Revision 1.4 2002/07/28 20:45:22 florian
  213. + added direct assembler reader for PowerPC
  214. Revision 1.3 2002/07/26 22:22:10 florian
  215. * several PowerPC related fixes to get forward with system unit compilation
  216. Revision 1.2 2002/07/11 14:41:34 florian
  217. * start of the new generic parameter handling
  218. Revision 1.1 2002/07/07 09:44:32 florian
  219. * powerpc target fixed, very simple units can be compiled
  220. }