cpupara.pas 13 KB

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