cpupara.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Calling conventions for the SPARC
  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. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cpubase,
  22. aasmtai,
  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(list: taasmoutput; nr : longint) : tparalocation;override;
  30. procedure freeintparaloc(list: taasmoutput; nr : longint); override;
  31. {Creates location information related to the parameter of the function}
  32. procedure allocparaloc(list: taasmoutput; const loc: tparalocation);override;
  33. procedure freeparaloc(list: taasmoutput; const loc: tparalocation);override;
  34. procedure create_paraloc_info(p:TAbstractProcDef; side: tcallercallee);override;
  35. {Returns the location where the invisible parameter for structured function
  36. results will be passed.}
  37. function GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;override;
  38. procedure splitparaloc64(const locpara:tparalocation;var loclopara,lochipara:tparalocation);override;
  39. end;
  40. implementation
  41. uses
  42. verbose,
  43. cpuinfo,cginfo,cgbase,
  44. defutil,rgobj;
  45. function TSparcParaManager.GetIntParaLoc(List:TAasmOutput;nr:longint):TParaLocation;
  46. begin
  47. if nr<1 then
  48. InternalError(2002100806);
  49. FillChar(GetIntParaLoc,SizeOf(TParaLocation),0);
  50. Dec(nr);
  51. with GetIntParaLoc do
  52. begin
  53. { The six first parameters are passed into registers }
  54. if nr<6 then
  55. begin
  56. loc:=LOC_REGISTER;
  57. register.enum:=R_INTREGISTER;
  58. register.number:=(RS_O0+nr) shl 8;
  59. rg.getexplicitregisterint(list,register.number);
  60. end
  61. else
  62. { The other parameters are passed on the stack }
  63. begin
  64. loc:=LOC_REFERENCE;
  65. reference.index.enum:=R_INTREGISTER;
  66. reference.index.number:=NR_STACK_POINTER_REG;
  67. reference.offset:=92+(nr-6)*4;
  68. end;
  69. size:=OS_INT;
  70. end;
  71. end;
  72. procedure tsparcparamanager.freeintparaloc(list: taasmoutput; nr : longint);
  73. var
  74. r: tregister;
  75. begin
  76. if nr<1 then
  77. internalerror(2003060401);
  78. Dec(nr);
  79. if nr<6 then
  80. begin
  81. r.enum:=R_INTREGISTER;
  82. r.number:=(RS_O0+nr) shl 8;
  83. rg.ungetregisterint(list,r);
  84. end;
  85. end;
  86. procedure tsparcparamanager.allocparaloc(list: taasmoutput; const loc: tparalocation);
  87. begin
  88. if (loc.loc=LOC_REFERENCE) and
  89. (loc.low_in_reg) then
  90. rg.getexplicitregisterint(list,loc.lowreg.number);
  91. inherited allocparaloc(list,loc);
  92. end;
  93. procedure tsparcparamanager.freeparaloc(list: taasmoutput; const loc: tparalocation);
  94. begin
  95. if (loc.loc=LOC_REFERENCE) and
  96. (loc.low_in_reg) then
  97. rg.ungetregisterint(list,loc.lowreg);
  98. inherited freeparaloc(list,loc);
  99. end;
  100. procedure TSparcParaManager.create_paraloc_info(p:TAbstractProcDef; side: tcallercallee);
  101. var
  102. nextintreg : tsuperregister;
  103. nextfloatreg : toldregister;
  104. stack_offset : longint;
  105. hp : tparaitem;
  106. is_64bit : boolean;
  107. paraloc : tparalocation;
  108. begin
  109. nextintreg:=RS_O0;
  110. nextfloatreg:=R_F0;
  111. stack_offset:=92;
  112. hp:=TParaItem(p.para.First);
  113. while assigned(hp) do
  114. begin
  115. fillchar(paraloc,sizeof(tparalocation),0);
  116. if push_addr_param(hp.paratype.def,p.proccalloption) or (hp.paratyp in [vs_var,vs_out]) then
  117. paraloc.size:=OS_ADDR
  118. else
  119. begin
  120. paraloc.size:=def_cgSize(hp.paratype.def);
  121. if paraloc.size=OS_NO then
  122. paraloc.size:=OS_ADDR;
  123. end;
  124. is_64bit:=(paraloc.size in [OS_64,OS_S64,OS_F64]);
  125. if NextIntReg<=RS_O5-ord(is_64bit) then
  126. begin
  127. paraloc.loc:=LOC_REGISTER;
  128. paraloc.registerlow.enum:=R_INTREGISTER;
  129. paraloc.registerlow.number:=NextIntReg shl 8;
  130. inc(NextIntReg);
  131. if is_64bit then
  132. begin
  133. paraloc.registerhigh.enum:=R_INTREGISTER;
  134. paraloc.registerhigh.number:=nextintreg shl 8;
  135. inc(nextintreg);
  136. end;
  137. end
  138. else
  139. begin
  140. paraloc.loc:=LOC_REFERENCE;
  141. { Low part need to be in O5 if still available }
  142. if NextIntReg<=RS_O5 then
  143. begin
  144. paraloc.low_in_reg:=true;
  145. paraloc.lowreg.enum:=R_INTREGISTER;
  146. paraloc.lowreg.number:=nextintreg shl 8;
  147. end;
  148. nextintreg:=RS_O6;
  149. paraloc.reference.index.enum:=R_INTREGISTER;
  150. paraloc.reference.index.number:=NR_STACK_POINTER_REG;
  151. paraloc.reference.offset:=stack_offset;
  152. if is_64bit and
  153. (not paraloc.low_in_reg) then
  154. inc(stack_offset,8)
  155. else
  156. inc(stack_offset,4);
  157. end;
  158. if side = callerside then
  159. hp.callerparaloc:=paraloc
  160. else
  161. begin
  162. { update callee paraloc and use Ix registers instead
  163. of Ox registers }
  164. hp.calleeparaloc:=paraloc;
  165. if hp.calleeparaloc.loc=LOC_REGISTER then
  166. begin
  167. inc(hp.calleeparaloc.registerlow.number,(RS_I0-RS_O0) shl 8);
  168. if is_64bit then
  169. inc(hp.calleeparaloc.registerhigh.number,(RS_I0-RS_O0) shl 8);
  170. end
  171. else
  172. begin
  173. if hp.calleeparaloc.low_in_reg then
  174. inc(hp.calleeparaloc.lowreg.number,(RS_I0-RS_O0) shl 8);
  175. inc(hp.calleeparaloc.reference.index.number,(RS_I0-RS_O0) shl 8);
  176. end;
  177. end;
  178. hp:=TParaItem(hp.Next);
  179. end;
  180. end;
  181. function tSparcParaManager.GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;
  182. begin
  183. with GetFuncRetParaLoc do
  184. begin
  185. case p.rettype.def.deftype of
  186. orddef,enumdef:
  187. begin
  188. loc:=LOC_REGISTER;
  189. register.enum:=R_INTREGISTER;
  190. register.number:=NR_FUNCTION_RETURN_REG;
  191. size:=def_cgsize(p.rettype.def);
  192. if size in [OS_S64,OS_64] then
  193. internalerror(200305309);
  194. end;
  195. floatdef:
  196. begin
  197. loc:=LOC_FPUREGISTER;
  198. register.enum:=R_F1;
  199. size:=def_cgsize(p.rettype.def);
  200. end;
  201. setdef,
  202. variantdef,
  203. pointerdef,
  204. formaldef,
  205. classrefdef,
  206. recorddef,
  207. objectdef,
  208. stringdef,
  209. procvardef,
  210. filedef,
  211. arraydef,
  212. errordef:
  213. begin
  214. loc:=LOC_REFERENCE;
  215. reference.index.enum:=R_INTREGISTER;
  216. reference.index.number:=NR_FRAME_POINTER_REG;
  217. reference.offset:=64;
  218. size:=OS_ADDR;
  219. end;
  220. else
  221. internalerror(2002090903);
  222. end;
  223. end;
  224. end;
  225. procedure tsparcparamanager.splitparaloc64(const locpara:tparalocation;var loclopara,lochipara:tparalocation);
  226. begin
  227. { Word 0 is in register, word 1 is in reference }
  228. if (locpara.loc=LOC_REFERENCE) and locpara.low_in_reg then
  229. begin
  230. { high }
  231. lochipara:=locpara;
  232. if locpara.size=OS_S64 then
  233. lochipara.size:=OS_S32
  234. else
  235. lochipara.size:=OS_32;
  236. lochipara.low_in_reg:=false;
  237. { low }
  238. loclopara:=locpara;
  239. loclopara.size:=OS_32;
  240. loclopara.loc:=LOC_REGISTER;
  241. loclopara.register:=locpara.lowreg;
  242. end
  243. else
  244. inherited splitparaloc64(locpara,loclopara,lochipara);
  245. end;
  246. begin
  247. ParaManager:=TSparcParaManager.create;
  248. end.
  249. {
  250. $Log$
  251. Revision 1.23 2003-07-05 20:11:41 jonas
  252. * create_paraloc_info() is now called separately for the caller and
  253. callee info
  254. * fixed ppc cycle
  255. Revision 1.22 2003/07/02 22:18:04 peter
  256. * paraloc splitted in callerparaloc,calleeparaloc
  257. * sparc calling convention updates
  258. Revision 1.21 2003/06/17 16:36:59 peter
  259. * freeintparaloc
  260. Revision 1.20 2003/06/09 21:44:14 mazen
  261. * fix compile problem related to modification
  262. of the declareation of GetIntParaLoc in the
  263. ancestor's declaration
  264. Revision 1.19 2003/06/01 21:38:06 peter
  265. * getregisterfpu size parameter added
  266. * op_const_reg size parameter added
  267. * sparc updates
  268. Revision 1.18 2003/05/31 01:00:51 peter
  269. * register fixes
  270. Revision 1.17 2003/05/30 23:57:08 peter
  271. * more sparc cleanup
  272. * accumulator removed, splitted in function_return_reg (called) and
  273. function_result_reg (caller)
  274. Revision 1.16 2003/04/23 13:35:39 peter
  275. * fix sparc compile
  276. Revision 1.15 2003/04/23 12:35:35 florian
  277. * fixed several issues with powerpc
  278. + applied a patch from Jonas for nested function calls (PowerPC only)
  279. * ...
  280. Revision 1.14 2003/01/08 18:43:58 daniel
  281. * Tregister changed into a record
  282. Revision 1.13 2003/01/05 21:32:35 mazen
  283. * fixing several bugs compiling the RTL
  284. Revision 1.12 2002/11/25 19:21:49 mazen
  285. * fixed support of nSparcInline
  286. Revision 1.11 2002/11/25 17:43:28 peter
  287. * splitted defbase in defutil,symutil,defcmp
  288. * merged isconvertable and is_equal into compare_defs(_ext)
  289. * made operator search faster by walking the list only once
  290. Revision 1.10 2002/11/18 17:32:01 peter
  291. * pass proccalloption to ret_in_xxx and push_xxx functions
  292. Revision 1.9 2002/11/03 20:22:40 mazen
  293. * parameter handling updated
  294. Revision 1.8 2002/10/13 21:46:07 mazen
  295. * assembler output format fixed
  296. Revision 1.7 2002/10/10 19:57:51 mazen
  297. * Just to update repsitory
  298. Revision 1.6 2002/10/10 15:10:39 mazen
  299. * Internal error fixed, but usually i386 parameter model used
  300. Revision 1.5 2002/10/09 13:52:19 mazen
  301. just incase some one wolud help me debugging that\!
  302. Revision 1.4 2002/10/08 21:02:22 mazen
  303. * debugging register allocation
  304. Revision 1.3 2002/10/07 20:33:05 mazen
  305. word alignement modified in g_stack_frame
  306. Revision 1.2 2002/10/04 21:57:42 mazen
  307. * 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
  308. Revision 1.1 2002/08/21 13:30:07 mazen
  309. *** empty log message ***
  310. Revision 1.2 2002/07/11 14:41:34 florian
  311. * start of the new generic parameter handling
  312. Revision 1.1 2002/07/07 09:44:32 florian
  313. * powerpc target fixed, very simple units can be compiled
  314. }