cpupara.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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);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);
  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. hp.callerparaloc:=paraloc;
  159. { update callee paraloc and use Ix registers instead
  160. of Ox registers }
  161. hp.calleeparaloc:=paraloc;
  162. if hp.calleeparaloc.loc=LOC_REGISTER then
  163. begin
  164. inc(hp.calleeparaloc.registerlow.number,(RS_I0-RS_O0) shl 8);
  165. if is_64bit then
  166. inc(hp.calleeparaloc.registerhigh.number,(RS_I0-RS_O0) shl 8);
  167. end
  168. else
  169. begin
  170. if hp.calleeparaloc.low_in_reg then
  171. inc(hp.calleeparaloc.lowreg.number,(RS_I0-RS_O0) shl 8);
  172. inc(hp.calleeparaloc.reference.index.number,(RS_I0-RS_O0) shl 8);
  173. end;
  174. hp:=TParaItem(hp.Next);
  175. end;
  176. end;
  177. function tSparcParaManager.GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;
  178. begin
  179. with GetFuncRetParaLoc do
  180. begin
  181. case p.rettype.def.deftype of
  182. orddef,enumdef:
  183. begin
  184. loc:=LOC_REGISTER;
  185. register.enum:=R_INTREGISTER;
  186. register.number:=NR_FUNCTION_RETURN_REG;
  187. size:=def_cgsize(p.rettype.def);
  188. if size in [OS_S64,OS_64] then
  189. internalerror(200305309);
  190. end;
  191. floatdef:
  192. begin
  193. loc:=LOC_FPUREGISTER;
  194. register.enum:=R_F1;
  195. size:=def_cgsize(p.rettype.def);
  196. end;
  197. setdef,
  198. variantdef,
  199. pointerdef,
  200. formaldef,
  201. classrefdef,
  202. recorddef,
  203. objectdef,
  204. stringdef,
  205. procvardef,
  206. filedef,
  207. arraydef,
  208. errordef:
  209. begin
  210. loc:=LOC_REFERENCE;
  211. reference.index.enum:=R_INTREGISTER;
  212. reference.index.number:=NR_FRAME_POINTER_REG;
  213. reference.offset:=64;
  214. size:=OS_ADDR;
  215. end;
  216. else
  217. internalerror(2002090903);
  218. end;
  219. end;
  220. end;
  221. procedure tsparcparamanager.splitparaloc64(const locpara:tparalocation;var loclopara,lochipara:tparalocation);
  222. begin
  223. { Word 0 is in register, word 1 is in reference }
  224. if (locpara.loc=LOC_REFERENCE) and locpara.low_in_reg then
  225. begin
  226. { high }
  227. lochipara:=locpara;
  228. if locpara.size=OS_S64 then
  229. lochipara.size:=OS_S32
  230. else
  231. lochipara.size:=OS_32;
  232. lochipara.low_in_reg:=false;
  233. { low }
  234. loclopara:=locpara;
  235. loclopara.size:=OS_32;
  236. loclopara.loc:=LOC_REGISTER;
  237. loclopara.register:=locpara.lowreg;
  238. end
  239. else
  240. inherited splitparaloc64(locpara,loclopara,lochipara);
  241. end;
  242. begin
  243. ParaManager:=TSparcParaManager.create;
  244. end.
  245. {
  246. $Log$
  247. Revision 1.22 2003-07-02 22:18:04 peter
  248. * paraloc splitted in callerparaloc,calleeparaloc
  249. * sparc calling convention updates
  250. Revision 1.21 2003/06/17 16:36:59 peter
  251. * freeintparaloc
  252. Revision 1.20 2003/06/09 21:44:14 mazen
  253. * fix compile problem related to modification
  254. of the declareation of GetIntParaLoc in the
  255. ancestor's declaration
  256. Revision 1.19 2003/06/01 21:38:06 peter
  257. * getregisterfpu size parameter added
  258. * op_const_reg size parameter added
  259. * sparc updates
  260. Revision 1.18 2003/05/31 01:00:51 peter
  261. * register fixes
  262. Revision 1.17 2003/05/30 23:57:08 peter
  263. * more sparc cleanup
  264. * accumulator removed, splitted in function_return_reg (called) and
  265. function_result_reg (caller)
  266. Revision 1.16 2003/04/23 13:35:39 peter
  267. * fix sparc compile
  268. Revision 1.15 2003/04/23 12:35:35 florian
  269. * fixed several issues with powerpc
  270. + applied a patch from Jonas for nested function calls (PowerPC only)
  271. * ...
  272. Revision 1.14 2003/01/08 18:43:58 daniel
  273. * Tregister changed into a record
  274. Revision 1.13 2003/01/05 21:32:35 mazen
  275. * fixing several bugs compiling the RTL
  276. Revision 1.12 2002/11/25 19:21:49 mazen
  277. * fixed support of nSparcInline
  278. Revision 1.11 2002/11/25 17:43:28 peter
  279. * splitted defbase in defutil,symutil,defcmp
  280. * merged isconvertable and is_equal into compare_defs(_ext)
  281. * made operator search faster by walking the list only once
  282. Revision 1.10 2002/11/18 17:32:01 peter
  283. * pass proccalloption to ret_in_xxx and push_xxx functions
  284. Revision 1.9 2002/11/03 20:22:40 mazen
  285. * parameter handling updated
  286. Revision 1.8 2002/10/13 21:46:07 mazen
  287. * assembler output format fixed
  288. Revision 1.7 2002/10/10 19:57:51 mazen
  289. * Just to update repsitory
  290. Revision 1.6 2002/10/10 15:10:39 mazen
  291. * Internal error fixed, but usually i386 parameter model used
  292. Revision 1.5 2002/10/09 13:52:19 mazen
  293. just incase some one wolud help me debugging that\!
  294. Revision 1.4 2002/10/08 21:02:22 mazen
  295. * debugging register allocation
  296. Revision 1.3 2002/10/07 20:33:05 mazen
  297. word alignement modified in g_stack_frame
  298. Revision 1.2 2002/10/04 21:57:42 mazen
  299. * 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
  300. Revision 1.1 2002/08/21 13:30:07 mazen
  301. *** empty log message ***
  302. Revision 1.2 2002/07/11 14:41:34 florian
  303. * start of the new generic parameter handling
  304. Revision 1.1 2002/07/07 09:44:32 florian
  305. * powerpc target fixed, very simple units can be compiled
  306. }