cpupara.pas 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. { 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. if nextintreg<=R_8 then
  125. begin
  126. hp.paraloc.loc:=LOC_REGISTER;
  127. hp.paraloc.register:=nextintreg;
  128. inc(nextintreg);
  129. end
  130. else
  131. begin
  132. hp.paraloc.loc:=LOC_REFERENCE;
  133. hp.paraloc.reference.index:=stack_pointer_reg;
  134. hp.paraloc.reference.offset:=stack_offset;
  135. inc(stack_offset,4);
  136. end;
  137. end;
  138. LOC_FPUREGISTER:
  139. begin
  140. if hp.paratyp in [vs_var,vs_out] then
  141. begin
  142. if nextintreg<=R_8 then
  143. begin
  144. hp.paraloc.loc:=LOC_REGISTER;
  145. hp.paraloc.register:=nextintreg;
  146. inc(nextintreg);
  147. end
  148. else
  149. begin
  150. {!!!!!!!}
  151. internalerror(2002071006);
  152. end;
  153. end
  154. else if nextfloatreg<=R_F8 then
  155. begin
  156. hp.paraloc.loc:=LOC_FPUREGISTER;
  157. hp.paraloc.register:=nextfloatreg;
  158. inc(nextfloatreg);
  159. end
  160. else
  161. begin
  162. {!!!!!!!}
  163. internalerror(2002071004);
  164. end;
  165. end;
  166. LOC_REFERENCE:
  167. begin
  168. if push_addr_param(hp.paratype.def) or (hp.paratyp in [vs_var,vs_out]) then
  169. begin
  170. if nextintreg<=R_8 then
  171. begin
  172. hp.paraloc.loc:=LOC_REGISTER;
  173. hp.paraloc.register:=nextintreg;
  174. inc(nextintreg);
  175. end
  176. else
  177. begin
  178. {!!!!!!!}
  179. internalerror(2002071005);
  180. end;
  181. end
  182. else
  183. begin
  184. hp.paraloc.loc:=LOC_REFERENCE;
  185. hp.paraloc.reference.index:=stack_pointer_reg;
  186. hp.paraloc.reference.offset:=stack_offset;
  187. inc(stack_offset,hp.paratype.def.size);
  188. end;
  189. end;
  190. else
  191. internalerror(2002071002);
  192. end;
  193. hp:=tparaitem(hp.previous);
  194. end;
  195. end;
  196. function tppcparamanager.getfuncretloc(p : tabstractprocdef) : tparalocation;
  197. begin
  198. getfuncretloc.loc:=LOC_REGISTER;
  199. getfuncretloc.register:=R_3;
  200. end;
  201. begin
  202. paramanager:=tppcparamanager.create;
  203. end.
  204. {
  205. $Log$
  206. Revision 1.5 2002-07-30 20:50:44 florian
  207. * the code generator knows now if parameters are in registers
  208. Revision 1.4 2002/07/28 20:45:22 florian
  209. + added direct assembler reader for PowerPC
  210. Revision 1.3 2002/07/26 22:22:10 florian
  211. * several PowerPC related fixes to get forward with system unit compilation
  212. Revision 1.2 2002/07/11 14:41:34 florian
  213. * start of the new generic parameter handling
  214. Revision 1.1 2002/07/07 09:44:32 florian
  215. * powerpc target fixed, very simple units can be compiled
  216. }