cpupara.pas 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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,
  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. else
  94. internalerror(2002071001);
  95. end;
  96. end;
  97. procedure tppcparamanager.create_param_loc_info(p : tabstractprocdef);
  98. var
  99. nextintreg,nextfloatreg,nextmmreg : tregister;
  100. stack_offset : aword;
  101. hp : tparaitem;
  102. loc : tloc;
  103. begin
  104. nextintreg:=R_3;
  105. nextfloatreg:=R_F1;
  106. nextmmreg:=R_M1;
  107. stack_offset:=0;
  108. { pointer for structured results ? }
  109. { !!!nextintreg:=R_4; }
  110. { frame pointer for nested procedures? }
  111. { inc(nextintreg); }
  112. { constructor? }
  113. { destructor? }
  114. hp:=tparaitem(p.para.last);
  115. while assigned(hp) do
  116. begin
  117. loc:=getparaloc(hp.paratype.def);
  118. case loc of
  119. LOC_REGISTER:
  120. begin
  121. if nextintreg<=R_8 then
  122. begin
  123. hp.paraloc.loc:=LOC_REGISTER;
  124. hp.paraloc.register:=nextintreg;
  125. inc(nextintreg);
  126. end
  127. else
  128. begin
  129. hp.paraloc.loc:=LOC_REFERENCE;
  130. hp.paraloc.reference.index:=stack_pointer_reg;
  131. hp.paraloc.reference.offset:=stack_offset;
  132. inc(stack_offset,4);
  133. end;
  134. end;
  135. LOC_FPUREGISTER:
  136. begin
  137. if nextfloatreg<=R_F8 then
  138. begin
  139. hp.paraloc.loc:=LOC_FPUREGISTER;
  140. hp.paraloc.register:=nextfloatreg;
  141. inc(nextfloatreg);
  142. end
  143. else
  144. begin
  145. {!!!!!!!}
  146. internalerror(2002071004);
  147. end;
  148. end;
  149. LOC_REFERENCE:
  150. begin
  151. if push_addr_param(hp.paratype.def) then
  152. begin
  153. if nextintreg<=R_8 then
  154. begin
  155. hp.paraloc.loc:=LOC_REGISTER;
  156. hp.paraloc.register:=nextintreg;
  157. inc(nextintreg);
  158. end
  159. else
  160. begin
  161. {!!!!!!!}
  162. internalerror(2002071005);
  163. end;
  164. end
  165. else
  166. begin
  167. hp.paraloc.loc:=LOC_REFERENCE;
  168. hp.paraloc.reference.index:=stack_pointer_reg;
  169. hp.paraloc.reference.offset:=stack_offset;
  170. inc(stack_offset,hp.paratype.def.size);
  171. end;
  172. end;
  173. else
  174. internalerror(2002071002);
  175. end;
  176. hp:=tparaitem(hp.previous);
  177. end;
  178. end;
  179. function tppcparamanager.getfuncretloc(p : tabstractprocdef) : tparalocation;
  180. begin
  181. getfuncretloc.loc:=LOC_REGISTER;
  182. getfuncretloc.register:=R_3;
  183. end;
  184. begin
  185. paramanager:=tppcparamanager.create;
  186. end.
  187. {
  188. $Log$
  189. Revision 1.3 2002-07-26 22:22:10 florian
  190. * several PowerPC related fixes to get forward with system unit compilation
  191. Revision 1.2 2002/07/11 14:41:34 florian
  192. * start of the new generic parameter handling
  193. Revision 1.1 2002/07/07 09:44:32 florian
  194. * powerpc target fixed, very simple units can be compiled
  195. }