cpupara.pas 11 KB

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