cpupara.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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.enum:=frame_pointer_reg;
  59. reference.offset:=-68-nr*4;
  60. end;
  61. end;
  62. function GetParaLoc(p:TDef):TCGLoc;
  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:tcgloc;
  124. is_64bit:boolean;
  125. begin
  126. nextintreg.enum:=R_O0;
  127. nextfloatreg.enum:=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.enum<=ToldRegister(ord(R_i5)-ord(is_64bit))
  142. then
  143. begin
  144. hp.paraloc.loc:=LOC_REGISTER;
  145. hp.paraloc.registerlow:=NextIntReg;
  146. inc(NextIntReg.enum);
  147. if is_64bit
  148. then
  149. begin
  150. hp.paraloc.registerhigh:=nextintreg;
  151. inc(nextintreg.enum);
  152. end;
  153. end
  154. else
  155. begin
  156. nextintreg.enum:=R_i6;
  157. hp.paraloc.loc:=LOC_REFERENCE;
  158. hp.paraloc.reference.index.enum:=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.enum<=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.enum);
  179. end
  180. else
  181. begin
  182. {!!!!!!!}
  183. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  184. internalerror(2002071006);
  185. end;
  186. end
  187. else if nextfloatreg.enum<=R_F10 then
  188. begin
  189. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  190. hp.paraloc.loc:=LOC_FPUREGISTER;
  191. hp.paraloc.register:=nextfloatreg;
  192. inc(nextfloatreg.enum);
  193. end
  194. else
  195. begin
  196. {!!!!!!!}
  197. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  198. internalerror(2002071004);
  199. end;
  200. end;
  201. LOC_REFERENCE:
  202. begin
  203. hp.paraloc.size:=OS_ADDR;
  204. if push_addr_param(hp.paratype.def,p.proccalloption) or (hp.paratyp in [vs_var,vs_out]) then
  205. begin
  206. if nextintreg.enum<=R_O5 then
  207. begin
  208. hp.paraloc.loc:=LOC_REGISTER;
  209. hp.paraloc.register:=nextintreg;
  210. inc(nextintreg.enum);
  211. end
  212. else
  213. begin
  214. hp.paraloc.loc:=LOC_REFERENCE;
  215. hp.paraloc.reference.index.enum:=stack_pointer_reg;
  216. hp.paraloc.reference.offset:=stack_offset;
  217. inc(stack_offset,4);
  218. end;
  219. end
  220. else
  221. begin
  222. hp.paraloc.loc:=LOC_REFERENCE;
  223. hp.paraloc.reference.index.enum:=stack_pointer_reg;
  224. hp.paraloc.reference.offset:=stack_offset;
  225. inc(stack_offset,hp.paratype.def.size);
  226. end;
  227. end;
  228. else
  229. internalerror(2002071002);
  230. end;
  231. hp:=TParaItem(hp.Next);
  232. end;
  233. end;
  234. function tSparcParaManager.GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;
  235. begin
  236. with GetFuncRetParaLoc do
  237. case p.rettype.def.deftype of
  238. orddef,enumdef:
  239. begin
  240. loc:=LOC_REGISTER;
  241. register.enum:=return_result_reg;
  242. size:=def_cgsize(p.rettype.def);
  243. if size in [OS_S64,OS_64]
  244. then
  245. RegisterHigh.enum:=R_I1;
  246. end;
  247. floatdef:
  248. begin
  249. loc:=LOC_FPUREGISTER;
  250. register.enum:=R_F1;
  251. size:=def_cgsize(p.rettype.def);
  252. end;
  253. setdef,
  254. variantdef,
  255. pointerdef,
  256. formaldef,
  257. classrefdef,
  258. recorddef,
  259. objectdef,
  260. stringdef,
  261. procvardef,
  262. filedef,
  263. arraydef,
  264. errordef:
  265. begin
  266. loc:=LOC_REFERENCE;
  267. reference.index.enum:=frame_pointer_reg;
  268. reference.offset:=64;
  269. size:=OS_ADDR;
  270. end;
  271. else
  272. internalerror(2002090903);
  273. end;
  274. end;
  275. begin
  276. ParaManager:=TSparcParaManager.create;
  277. end.
  278. {
  279. $Log$
  280. Revision 1.15 2003-04-23 12:35:35 florian
  281. * fixed several issues with powerpc
  282. + applied a patch from Jonas for nested function calls (PowerPC only)
  283. * ...
  284. Revision 1.14 2003/01/08 18:43:58 daniel
  285. * Tregister changed into a record
  286. Revision 1.13 2003/01/05 21:32:35 mazen
  287. * fixing several bugs compiling the RTL
  288. Revision 1.12 2002/11/25 19:21:49 mazen
  289. * fixed support of nSparcInline
  290. Revision 1.11 2002/11/25 17:43:28 peter
  291. * splitted defbase in defutil,symutil,defcmp
  292. * merged isconvertable and is_equal into compare_defs(_ext)
  293. * made operator search faster by walking the list only once
  294. Revision 1.10 2002/11/18 17:32:01 peter
  295. * pass proccalloption to ret_in_xxx and push_xxx functions
  296. Revision 1.9 2002/11/03 20:22:40 mazen
  297. * parameter handling updated
  298. Revision 1.8 2002/10/13 21:46:07 mazen
  299. * assembler output format fixed
  300. Revision 1.7 2002/10/10 19:57:51 mazen
  301. * Just to update repsitory
  302. Revision 1.6 2002/10/10 15:10:39 mazen
  303. * Internal error fixed, but usually i386 parameter model used
  304. Revision 1.5 2002/10/09 13:52:19 mazen
  305. just incase some one wolud help me debugging that\!
  306. Revision 1.4 2002/10/08 21:02:22 mazen
  307. * debugging register allocation
  308. Revision 1.3 2002/10/07 20:33:05 mazen
  309. word alignement modified in g_stack_frame
  310. Revision 1.2 2002/10/04 21:57:42 mazen
  311. * 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
  312. Revision 1.1 2002/08/21 13:30:07 mazen
  313. *** empty log message ***
  314. Revision 1.2 2002/07/11 14:41:34 florian
  315. * start of the new generic parameter handling
  316. Revision 1.1 2002/07/07 09:44:32 florian
  317. * powerpc target fixed, very simple units can be compiled
  318. }