cpupara.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. unit cpupara;
  18. {SPARC specific calling conventions are handled by this unit}
  19. {$INCLUDE fpcdefs.inc}
  20. interface
  21. uses
  22. cpubase,
  23. symconst,symbase,symtype,symdef,paramgr;
  24. type
  25. TSparcParaManager=class(TParaManager)
  26. function GetIntParaLoc(nr:longint):TParaLocation;override;
  27. procedure create_param_loc_info(p:TAbstractProcDef);override;
  28. function GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;override;
  29. end;
  30. implementation
  31. uses
  32. verbose,
  33. globtype,
  34. cpuinfo,cginfo,cgbase,
  35. defbase;
  36. function TSparcParaManager.GetIntParaLoc(nr:longint):TParaLocation;
  37. begin
  38. if nr<1
  39. then
  40. InternalError(2002100806);
  41. FillChar(GetIntParaLoc,SizeOf(TParaLocation),0);
  42. Dec(nr);
  43. with GetIntParaLoc do
  44. if nr<6
  45. then{The six first parameters are passed into registers}
  46. begin
  47. loc:=LOC_REGISTER;
  48. register:=TRegister(LongInt(R_i0)+nr);
  49. end
  50. else{The other parameters are passed into the frame}
  51. begin
  52. loc:=LOC_REFERENCE;
  53. reference.index:=frame_pointer_reg;
  54. reference.offset:=-68-nr*4;
  55. end;
  56. end;
  57. function GetParaLoc(p:TDef):TLoc;
  58. begin
  59. {Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER if
  60. push_addr_param for the def is true}
  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)
  78. then
  79. getparaloc:=LOC_REFERENCE
  80. else
  81. getparaloc:=LOC_REGISTER;
  82. stringdef:
  83. if is_shortstring(p) or is_longstring(p)
  84. then
  85. getparaloc:=LOC_REFERENCE
  86. else
  87. getparaloc:=LOC_REGISTER;
  88. procvardef:
  89. if (po_methodpointer in tprocvardef(p).procoptions)
  90. then
  91. getparaloc:=LOC_REFERENCE
  92. else
  93. getparaloc:=LOC_REGISTER;
  94. filedef:
  95. getparaloc:=LOC_REGISTER;
  96. arraydef:
  97. getparaloc:=LOC_REFERENCE;
  98. setdef:
  99. if is_smallset(p)
  100. then
  101. getparaloc:=LOC_REGISTER
  102. else
  103. getparaloc:=LOC_REFERENCE;
  104. variantdef:
  105. getparaloc:=LOC_REFERENCE;
  106. { avoid problems with errornous definitions }
  107. errordef:
  108. getparaloc:=LOC_REGISTER;
  109. else
  110. internalerror(2002071001);
  111. end;
  112. end;
  113. procedure TSparcParaManager.create_param_loc_info(p:tabstractprocdef);
  114. var
  115. nextintreg,nextfloatreg:tregister;
  116. stack_offset : aword;
  117. hp : tparaitem;
  118. loc : tloc;
  119. is_64bit: boolean;
  120. begin
  121. nextintreg:=R_i0;
  122. nextfloatreg:=R_F0;
  123. stack_offset:=92;
  124. WriteLn('***********************************************');
  125. hp:=TParaItem(p.para.First);
  126. while assigned(hp) do
  127. begin
  128. loc:=GetParaLoc(hp.paratype.def);
  129. case loc of
  130. LOC_REGISTER:
  131. begin
  132. hp.paraloc.size:=def_cgSize(hp.paratype.def);
  133. if hp.paraloc.size=OS_NO
  134. then
  135. hp.paraloc.size:=OS_ADDR;
  136. is_64bit:=hp.paraloc.size in [OS_64,OS_S64];
  137. if NextIntReg<=TRegister(ord(R_i5)-ord(is_64bit))
  138. then
  139. begin
  140. WriteLn('Allocating ',std_reg2str[NextIntReg]);
  141. hp.paraloc.loc:=LOC_REGISTER;
  142. hp.paraloc.registerlow:=NextIntReg;
  143. inc(NextIntReg);
  144. if is_64bit
  145. then
  146. begin
  147. hp.paraloc.registerhigh:=nextintreg;
  148. inc(nextintreg);
  149. end;
  150. end
  151. else
  152. begin
  153. nextintreg:=R_i6;
  154. hp.paraloc.loc:=LOC_REFERENCE;
  155. hp.paraloc.reference.index:=stack_pointer_reg;
  156. hp.paraloc.reference.offset:=stack_offset;
  157. if not is_64bit
  158. then
  159. inc(stack_offset,4)
  160. else
  161. inc(stack_offset,8);
  162. end;
  163. end;
  164. LOC_FPUREGISTER:
  165. begin
  166. if hp.paratyp in [vs_var,vs_out] then
  167. begin
  168. if nextintreg<=R_O5 then
  169. begin
  170. hp.paraloc.size:=OS_ADDR;
  171. hp.paraloc.loc:=LOC_REGISTER;
  172. hp.paraloc.register:=nextintreg;
  173. inc(nextintreg);
  174. end
  175. else
  176. begin
  177. {!!!!!!!}
  178. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  179. internalerror(2002071006);
  180. end;
  181. end
  182. else if nextfloatreg<=R_F10 then
  183. begin
  184. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  185. hp.paraloc.loc:=LOC_FPUREGISTER;
  186. hp.paraloc.register:=nextfloatreg;
  187. inc(nextfloatreg);
  188. end
  189. else
  190. begin
  191. {!!!!!!!}
  192. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  193. internalerror(2002071004);
  194. end;
  195. end;
  196. LOC_REFERENCE:
  197. begin
  198. hp.paraloc.size:=OS_ADDR;
  199. if push_addr_param(hp.paratype.def,p.proccalloption in [pocall_cdecl,pocall_cppdecl]) or (hp.paratyp in [vs_var,vs_out]) then
  200. begin
  201. if nextintreg<=R_O5 then
  202. begin
  203. hp.paraloc.loc:=LOC_REGISTER;
  204. hp.paraloc.register:=nextintreg;
  205. inc(nextintreg);
  206. end
  207. else
  208. begin
  209. hp.paraloc.loc:=LOC_REFERENCE;
  210. hp.paraloc.reference.index:=stack_pointer_reg;
  211. hp.paraloc.reference.offset:=stack_offset;
  212. inc(stack_offset,4);
  213. end;
  214. end
  215. else
  216. begin
  217. hp.paraloc.loc:=LOC_REFERENCE;
  218. hp.paraloc.reference.index:=stack_pointer_reg;
  219. hp.paraloc.reference.offset:=stack_offset;
  220. inc(stack_offset,hp.paratype.def.size);
  221. end;
  222. end;
  223. else
  224. internalerror(2002071002);
  225. end;
  226. hp:=TParaItem(hp.Next);
  227. end;
  228. end;
  229. function tSparcParaManager.GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;
  230. begin
  231. case p.rettype.def.deftype of
  232. orddef,enumdef:
  233. begin
  234. WriteLn('Allocating i0 as return register');
  235. GetFuncRetParaLoc.loc:=LOC_REGISTER;
  236. GetFuncRetParaLoc.register:=R_I0;
  237. GetFuncRetParaLoc.size:=def_cgsize(p.rettype.def);
  238. if GetFuncRetParaLoc.size in [OS_S64,OS_64]
  239. then
  240. GetFuncRetParaLoc.RegisterHigh:=R_I1;
  241. end;
  242. floatdef:
  243. begin
  244. GetFuncRetParaLoc.loc:=LOC_FPUREGISTER;
  245. GetFuncRetParaLoc.register:=R_F1;
  246. GetFuncRetParaLoc.size:=def_cgsize(p.rettype.def);
  247. end;
  248. setdef,
  249. variantdef,
  250. pointerdef,
  251. formaldef,
  252. classrefdef,
  253. recorddef,
  254. objectdef,
  255. stringdef,
  256. procvardef,
  257. filedef,
  258. arraydef,
  259. errordef:
  260. begin
  261. GetFuncRetParaLoc.loc:=LOC_REGISTER;
  262. GetFuncRetParaLoc.register:=R_I0;
  263. GetFuncRetParaLoc.size:=OS_ADDR;
  264. end;
  265. else
  266. internalerror(2002090903);
  267. end;
  268. end;
  269. begin
  270. ParaManager:=TSparcParaManager.create;
  271. end.
  272. {
  273. $Log$
  274. Revision 1.7 2002-10-10 19:57:51 mazen
  275. * Just to update repsitory
  276. Revision 1.6 2002/10/10 15:10:39 mazen
  277. * Internal error fixed, but usually i386 parameter model used
  278. Revision 1.5 2002/10/09 13:52:19 mazen
  279. just incase some one wolud help me debugging that\!
  280. Revision 1.4 2002/10/08 21:02:22 mazen
  281. * debugging register allocation
  282. Revision 1.3 2002/10/07 20:33:05 mazen
  283. word alignement modified in g_stack_frame
  284. Revision 1.2 2002/10/04 21:57:42 mazen
  285. * register allocation for parameters now done in cpupara, but InternalError(200109223) in cgcpu.pas:1053 is still not fixed du to location_force problem in ncgutils.pas:419
  286. Revision 1.1 2002/08/21 13:30:07 mazen
  287. *** empty log message ***
  288. Revision 1.2 2002/07/11 14:41:34 florian
  289. * start of the new generic parameter handling
  290. Revision 1.1 2002/07/07 09:44:32 florian
  291. * powerpc target fixed, very simple units can be compiled
  292. }