cpupara.pas 14 KB

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