cpupara.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. {Returns a structure giving the information on the storage of the parameter
  27. (which must be an integer parameter)
  28. @param(nr Parameter number of routine, starting from 1)}
  29. function GetIntParaLoc(nr:longint):TParaLocation;override;
  30. {Creates location information related to the parameter of the function}
  31. procedure create_param_loc_info(p:TAbstractProcDef);override;
  32. {Returns the location where the invisible parameter for structured function
  33. results will be passed.}
  34. function GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;override;
  35. end;
  36. implementation
  37. uses
  38. verbose,
  39. globtype,
  40. cpuinfo,cginfo,cgbase,
  41. defutil;
  42. function TSparcParaManager.GetIntParaLoc(nr:longint):TParaLocation;
  43. begin
  44. if nr<1
  45. then
  46. InternalError(2002100806);
  47. FillChar(GetIntParaLoc,SizeOf(TParaLocation),0);
  48. Dec(nr);
  49. with GetIntParaLoc do
  50. if nr<6
  51. then{The six first parameters are passed into registers}
  52. begin
  53. loc:=LOC_REGISTER;
  54. register:=TRegister(LongInt(R_i0)+nr);
  55. end
  56. else{The other parameters are passed into the frame}
  57. begin
  58. loc:=LOC_REFERENCE;
  59. reference.index:=frame_pointer_reg;
  60. reference.offset:=-68-nr*4;
  61. end;
  62. end;
  63. function GetParaLoc(p:TDef):TLoc;
  64. begin
  65. {Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER if
  66. push_addr_param for the def is true}
  67. case p.DefType of
  68. OrdDef:
  69. GetParaLoc:=LOC_REGISTER;
  70. FloatDef:
  71. GetParaLoc:=LOC_FPUREGISTER;
  72. enumdef:
  73. getparaloc:=LOC_REGISTER;
  74. pointerdef:
  75. getparaloc:=LOC_REGISTER;
  76. formaldef:
  77. getparaloc:=LOC_REGISTER;
  78. classrefdef:
  79. getparaloc:=LOC_REGISTER;
  80. recorddef:
  81. getparaloc:=LOC_REFERENCE;
  82. objectdef:
  83. if is_object(p)
  84. then
  85. getparaloc:=LOC_REFERENCE
  86. else
  87. getparaloc:=LOC_REGISTER;
  88. stringdef:
  89. if is_shortstring(p) or is_longstring(p)
  90. then
  91. getparaloc:=LOC_REFERENCE
  92. else
  93. getparaloc:=LOC_REGISTER;
  94. procvardef:
  95. if (po_methodpointer in tprocvardef(p).procoptions)
  96. then
  97. getparaloc:=LOC_REFERENCE
  98. else
  99. getparaloc:=LOC_REGISTER;
  100. filedef:
  101. getparaloc:=LOC_REGISTER;
  102. arraydef:
  103. getparaloc:=LOC_REFERENCE;
  104. setdef:
  105. if is_smallset(p)
  106. then
  107. getparaloc:=LOC_REGISTER
  108. else
  109. getparaloc:=LOC_REFERENCE;
  110. variantdef:
  111. getparaloc:=LOC_REFERENCE;
  112. { avoid problems with errornous definitions }
  113. errordef:
  114. getparaloc:=LOC_REGISTER;
  115. else
  116. internalerror(2002071001);
  117. end;
  118. end;
  119. procedure TSparcParaManager.create_param_loc_info(p:tabstractprocdef);
  120. var
  121. nextintreg,nextfloatreg:tregister;
  122. stack_offset : aword;
  123. hp : tparaitem;
  124. loc : tloc;
  125. is_64bit: boolean;
  126. begin
  127. nextintreg:=R_i0;
  128. nextfloatreg:=R_F0;
  129. stack_offset:=92;
  130. WriteLn('***********************************************');
  131. hp:=TParaItem(p.para.First);
  132. while assigned(hp) do
  133. begin
  134. loc:=GetParaLoc(hp.paratype.def);
  135. case loc of
  136. LOC_REGISTER:
  137. begin
  138. hp.paraloc.size:=def_cgSize(hp.paratype.def);
  139. if hp.paraloc.size=OS_NO
  140. then
  141. hp.paraloc.size:=OS_ADDR;
  142. is_64bit:=hp.paraloc.size in [OS_64,OS_S64];
  143. if NextIntReg<=TRegister(ord(R_i5)-ord(is_64bit))
  144. then
  145. begin
  146. WriteLn('Allocating ',std_reg2str[NextIntReg]);
  147. hp.paraloc.loc:=LOC_REGISTER;
  148. hp.paraloc.registerlow:=NextIntReg;
  149. inc(NextIntReg);
  150. if is_64bit
  151. then
  152. begin
  153. hp.paraloc.registerhigh:=nextintreg;
  154. inc(nextintreg);
  155. end;
  156. end
  157. else
  158. begin
  159. nextintreg:=R_i6;
  160. hp.paraloc.loc:=LOC_REFERENCE;
  161. hp.paraloc.reference.index:=stack_pointer_reg;
  162. hp.paraloc.reference.offset:=stack_offset;
  163. if not is_64bit
  164. then
  165. inc(stack_offset,4)
  166. else
  167. inc(stack_offset,8);
  168. end;
  169. end;
  170. LOC_FPUREGISTER:
  171. begin
  172. if hp.paratyp in [vs_var,vs_out] then
  173. begin
  174. if nextintreg<=R_O5 then
  175. begin
  176. hp.paraloc.size:=OS_ADDR;
  177. hp.paraloc.loc:=LOC_REGISTER;
  178. hp.paraloc.register:=nextintreg;
  179. inc(nextintreg);
  180. end
  181. else
  182. begin
  183. {!!!!!!!}
  184. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  185. internalerror(2002071006);
  186. end;
  187. end
  188. else if nextfloatreg<=R_F10 then
  189. begin
  190. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  191. hp.paraloc.loc:=LOC_FPUREGISTER;
  192. hp.paraloc.register:=nextfloatreg;
  193. inc(nextfloatreg);
  194. end
  195. else
  196. begin
  197. {!!!!!!!}
  198. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  199. internalerror(2002071004);
  200. end;
  201. end;
  202. LOC_REFERENCE:
  203. begin
  204. hp.paraloc.size:=OS_ADDR;
  205. if push_addr_param(hp.paratype.def,p.proccalloption) or (hp.paratyp in [vs_var,vs_out]) then
  206. begin
  207. if nextintreg<=R_O5 then
  208. begin
  209. hp.paraloc.loc:=LOC_REGISTER;
  210. hp.paraloc.register:=nextintreg;
  211. inc(nextintreg);
  212. end
  213. else
  214. begin
  215. hp.paraloc.loc:=LOC_REFERENCE;
  216. hp.paraloc.reference.index:=stack_pointer_reg;
  217. hp.paraloc.reference.offset:=stack_offset;
  218. inc(stack_offset,4);
  219. end;
  220. end
  221. else
  222. begin
  223. hp.paraloc.loc:=LOC_REFERENCE;
  224. hp.paraloc.reference.index:=stack_pointer_reg;
  225. hp.paraloc.reference.offset:=stack_offset;
  226. inc(stack_offset,hp.paratype.def.size);
  227. end;
  228. end;
  229. else
  230. internalerror(2002071002);
  231. end;
  232. hp:=TParaItem(hp.Next);
  233. end;
  234. end;
  235. function tSparcParaManager.GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;
  236. begin
  237. with GetFuncRetParaLoc do
  238. case p.rettype.def.deftype of
  239. orddef,enumdef:
  240. begin
  241. WriteLn('Allocating i0 as return register');
  242. loc:=LOC_REGISTER;
  243. register:=R_I0;
  244. size:=def_cgsize(p.rettype.def);
  245. if size in [OS_S64,OS_64]
  246. then
  247. RegisterHigh:=R_I1;
  248. end;
  249. floatdef:
  250. begin
  251. loc:=LOC_FPUREGISTER;
  252. register:=R_F1;
  253. size:=def_cgsize(p.rettype.def);
  254. end;
  255. setdef,
  256. variantdef,
  257. pointerdef,
  258. formaldef,
  259. classrefdef,
  260. recorddef,
  261. objectdef,
  262. stringdef,
  263. procvardef,
  264. filedef,
  265. arraydef,
  266. errordef:
  267. begin
  268. loc:=LOC_REFERENCE;
  269. reference.index:=frame_pointer_reg;
  270. reference.offset:=64;
  271. size:=OS_ADDR;
  272. end;
  273. else
  274. internalerror(2002090903);
  275. end;
  276. end;
  277. begin
  278. ParaManager:=TSparcParaManager.create;
  279. end.
  280. {
  281. $Log$
  282. Revision 1.11 2002-11-25 17:43:28 peter
  283. * splitted defbase in defutil,symutil,defcmp
  284. * merged isconvertable and is_equal into compare_defs(_ext)
  285. * made operator search faster by walking the list only once
  286. Revision 1.10 2002/11/18 17:32:01 peter
  287. * pass proccalloption to ret_in_xxx and push_xxx functions
  288. Revision 1.9 2002/11/03 20:22:40 mazen
  289. * parameter handling updated
  290. Revision 1.8 2002/10/13 21:46:07 mazen
  291. * assembler output format fixed
  292. Revision 1.7 2002/10/10 19:57:51 mazen
  293. * Just to update repsitory
  294. Revision 1.6 2002/10/10 15:10:39 mazen
  295. * Internal error fixed, but usually i386 parameter model used
  296. Revision 1.5 2002/10/09 13:52:19 mazen
  297. just incase some one wolud help me debugging that\!
  298. Revision 1.4 2002/10/08 21:02:22 mazen
  299. * debugging register allocation
  300. Revision 1.3 2002/10/07 20:33:05 mazen
  301. word alignement modified in g_stack_frame
  302. Revision 1.2 2002/10/04 21:57:42 mazen
  303. * 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
  304. Revision 1.1 2002/08/21 13:30:07 mazen
  305. *** empty log message ***
  306. Revision 1.2 2002/07/11 14:41:34 florian
  307. * start of the new generic parameter handling
  308. Revision 1.1 2002/07/07 09:44:32 florian
  309. * powerpc target fixed, very simple units can be compiled
  310. }