cpupara.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. stack_offset : longint;
  104. hp : tparaitem;
  105. is_64bit : boolean;
  106. paraloc : tparalocation;
  107. begin
  108. nextintreg:=RS_O0;
  109. { Nested procedures have the parent framepoint in o0 }
  110. if p.parast.symtablelevel>normal_function_level then
  111. inc(NextIntReg);
  112. stack_offset:=92;
  113. hp:=TParaItem(p.para.First);
  114. while assigned(hp) do
  115. begin
  116. fillchar(paraloc,sizeof(tparalocation),0);
  117. if push_addr_param(hp.paratype.def,p.proccalloption) or (hp.paratyp in [vs_var,vs_out]) then
  118. paraloc.size:=OS_ADDR
  119. else
  120. begin
  121. paraloc.size:=def_cgSize(hp.paratype.def);
  122. if paraloc.size=OS_NO then
  123. paraloc.size:=OS_ADDR;
  124. end;
  125. is_64bit:=(paraloc.size in [OS_64,OS_S64,OS_F64]);
  126. if NextIntReg<=RS_O5-ord(is_64bit) then
  127. begin
  128. paraloc.loc:=LOC_REGISTER;
  129. { big endian }
  130. if is_64bit then
  131. begin
  132. paraloc.registerhigh.enum:=R_INTREGISTER;
  133. paraloc.registerhigh.number:=nextintreg shl 8;
  134. inc(nextintreg);
  135. end;
  136. paraloc.registerlow.enum:=R_INTREGISTER;
  137. paraloc.registerlow.number:=NextIntReg shl 8;
  138. inc(NextIntReg);
  139. end
  140. else
  141. begin
  142. paraloc.loc:=LOC_REFERENCE;
  143. { Low part need to be in O5 if still available }
  144. if NextIntReg<=RS_O5 then
  145. begin
  146. paraloc.low_in_reg:=true;
  147. paraloc.lowreg.enum:=R_INTREGISTER;
  148. paraloc.lowreg.number:=nextintreg shl 8;
  149. end;
  150. nextintreg:=RS_O6;
  151. paraloc.reference.index.enum:=R_INTREGISTER;
  152. paraloc.reference.index.number:=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. if side = callerside then
  161. hp.callerparaloc:=paraloc
  162. else
  163. begin
  164. { update callee paraloc and use Ix registers instead
  165. of Ox registers }
  166. hp.calleeparaloc:=paraloc;
  167. if hp.calleeparaloc.loc=LOC_REGISTER then
  168. begin
  169. { big endian }
  170. if is_64bit then
  171. inc(hp.calleeparaloc.registerhigh.number,(RS_I0-RS_O0) shl 8);
  172. inc(hp.calleeparaloc.registerlow.number,(RS_I0-RS_O0) shl 8);
  173. end
  174. else
  175. begin
  176. if hp.calleeparaloc.low_in_reg then
  177. inc(hp.calleeparaloc.lowreg.number,(RS_I0-RS_O0) shl 8);
  178. inc(hp.calleeparaloc.reference.index.number,(RS_I0-RS_O0) shl 8);
  179. end;
  180. end;
  181. hp:=TParaItem(hp.Next);
  182. end;
  183. end;
  184. function tSparcParaManager.GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;
  185. begin
  186. with GetFuncRetParaLoc do
  187. begin
  188. case p.rettype.def.deftype of
  189. orddef,enumdef:
  190. begin
  191. loc:=LOC_REGISTER;
  192. register.enum:=R_INTREGISTER;
  193. register.number:=NR_FUNCTION_RETURN_REG;
  194. size:=def_cgsize(p.rettype.def);
  195. if size in [OS_S64,OS_64] then
  196. internalerror(200305309);
  197. end;
  198. floatdef:
  199. begin
  200. loc:=LOC_FPUREGISTER;
  201. register.enum:=R_F1;
  202. size:=def_cgsize(p.rettype.def);
  203. end;
  204. setdef,
  205. variantdef,
  206. pointerdef,
  207. formaldef,
  208. classrefdef,
  209. recorddef,
  210. objectdef,
  211. stringdef,
  212. procvardef,
  213. filedef,
  214. arraydef,
  215. errordef:
  216. begin
  217. loc:=LOC_REFERENCE;
  218. reference.index.enum:=R_INTREGISTER;
  219. reference.index.number:=NR_FRAME_POINTER_REG;
  220. reference.offset:=64;
  221. size:=OS_ADDR;
  222. end;
  223. else
  224. internalerror(2002090903);
  225. end;
  226. end;
  227. end;
  228. procedure tsparcparamanager.splitparaloc64(const locpara:tparalocation;var loclopara,lochipara:tparalocation);
  229. begin
  230. { Word 0 is in register, word 1 is in reference }
  231. if (locpara.loc=LOC_REFERENCE) and locpara.low_in_reg then
  232. begin
  233. { high }
  234. lochipara:=locpara;
  235. if locpara.size=OS_S64 then
  236. lochipara.size:=OS_S32
  237. else
  238. lochipara.size:=OS_32;
  239. lochipara.low_in_reg:=false;
  240. { low }
  241. loclopara:=locpara;
  242. loclopara.size:=OS_32;
  243. loclopara.loc:=LOC_REGISTER;
  244. loclopara.register:=locpara.lowreg;
  245. end
  246. else
  247. inherited splitparaloc64(locpara,loclopara,lochipara);
  248. end;
  249. begin
  250. ParaManager:=TSparcParaManager.create;
  251. end.
  252. {
  253. $Log$
  254. Revision 1.25 2003-07-06 22:10:56 peter
  255. * big endian first allocates high
  256. Revision 1.24 2003/07/06 17:58:22 peter
  257. * framepointer fixes for sparc
  258. * parent framepointer code more generic
  259. Revision 1.23 2003/07/05 20:11:41 jonas
  260. * create_paraloc_info() is now called separately for the caller and
  261. callee info
  262. * fixed ppc cycle
  263. Revision 1.22 2003/07/02 22:18:04 peter
  264. * paraloc splitted in callerparaloc,calleeparaloc
  265. * sparc calling convention updates
  266. Revision 1.21 2003/06/17 16:36:59 peter
  267. * freeintparaloc
  268. Revision 1.20 2003/06/09 21:44:14 mazen
  269. * fix compile problem related to modification
  270. of the declareation of GetIntParaLoc in the
  271. ancestor's declaration
  272. Revision 1.19 2003/06/01 21:38:06 peter
  273. * getregisterfpu size parameter added
  274. * op_const_reg size parameter added
  275. * sparc updates
  276. Revision 1.18 2003/05/31 01:00:51 peter
  277. * register fixes
  278. Revision 1.17 2003/05/30 23:57:08 peter
  279. * more sparc cleanup
  280. * accumulator removed, splitted in function_return_reg (called) and
  281. function_result_reg (caller)
  282. Revision 1.16 2003/04/23 13:35:39 peter
  283. * fix sparc compile
  284. Revision 1.15 2003/04/23 12:35:35 florian
  285. * fixed several issues with powerpc
  286. + applied a patch from Jonas for nested function calls (PowerPC only)
  287. * ...
  288. Revision 1.14 2003/01/08 18:43:58 daniel
  289. * Tregister changed into a record
  290. Revision 1.13 2003/01/05 21:32:35 mazen
  291. * fixing several bugs compiling the RTL
  292. Revision 1.12 2002/11/25 19:21:49 mazen
  293. * fixed support of nSparcInline
  294. Revision 1.11 2002/11/25 17:43:28 peter
  295. * splitted defbase in defutil,symutil,defcmp
  296. * merged isconvertable and is_equal into compare_defs(_ext)
  297. * made operator search faster by walking the list only once
  298. Revision 1.10 2002/11/18 17:32:01 peter
  299. * pass proccalloption to ret_in_xxx and push_xxx functions
  300. Revision 1.9 2002/11/03 20:22:40 mazen
  301. * parameter handling updated
  302. Revision 1.8 2002/10/13 21:46:07 mazen
  303. * assembler output format fixed
  304. Revision 1.7 2002/10/10 19:57:51 mazen
  305. * Just to update repsitory
  306. Revision 1.6 2002/10/10 15:10:39 mazen
  307. * Internal error fixed, but usually i386 parameter model used
  308. Revision 1.5 2002/10/09 13:52:19 mazen
  309. just incase some one wolud help me debugging that\!
  310. Revision 1.4 2002/10/08 21:02:22 mazen
  311. * debugging register allocation
  312. Revision 1.3 2002/10/07 20:33:05 mazen
  313. word alignement modified in g_stack_frame
  314. Revision 1.2 2002/10/04 21:57:42 mazen
  315. * 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
  316. Revision 1.1 2002/08/21 13:30:07 mazen
  317. *** empty log message ***
  318. Revision 1.2 2002/07/11 14:41:34 florian
  319. * start of the new generic parameter handling
  320. Revision 1.1 2002/07/07 09:44:32 florian
  321. * powerpc target fixed, very simple units can be compiled
  322. }