cpupara.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. symconst,symbase,symtype,symdef,paramgr;
  23. type
  24. TSparcParaManager=class(TParaManager)
  25. {Returns a structure giving the information on the storage of the parameter
  26. (which must be an integer parameter)
  27. @param(nr Parameter number of routine, starting from 1)}
  28. function GetIntParaLoc(nr:longint):TParaLocation;override;
  29. {Creates location information related to the parameter of the function}
  30. procedure create_param_loc_info(p:TAbstractProcDef);override;
  31. {Returns the location where the invisible parameter for structured function
  32. results will be passed.}
  33. function GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;override;
  34. end;
  35. implementation
  36. uses
  37. verbose,
  38. cpuinfo,cginfo,cgbase,
  39. defutil;
  40. function TSparcParaManager.GetIntParaLoc(nr:longint):TParaLocation;
  41. begin
  42. if nr<1 then
  43. InternalError(2002100806);
  44. FillChar(GetIntParaLoc,SizeOf(TParaLocation),0);
  45. Dec(nr);
  46. with GetIntParaLoc do
  47. begin
  48. { The six first parameters are passed into registers }
  49. if nr<6 then
  50. begin
  51. loc:=LOC_REGISTER;
  52. register.enum:=R_INTREGISTER;
  53. register.number:=(RS_I0+nr) shl 8;
  54. end
  55. else
  56. { The other parameters are passed into the frame }
  57. begin
  58. loc:=LOC_REFERENCE;
  59. reference.index.enum:=R_INTREGISTER;
  60. reference.index.number:=NR_FRAME_POINTER_REG;
  61. reference.offset:=-68-nr*4;
  62. end;
  63. size:=OS_INT;
  64. end;
  65. end;
  66. function GetParaLoc(p:TDef):TCGLoc;
  67. begin
  68. { Later, the LOC_REFERENCE is in most cases changed into
  69. LOC_REGISTER if push_addr_param for the def is true}
  70. case p.DefType of
  71. OrdDef:
  72. GetParaLoc:=LOC_REGISTER;
  73. FloatDef:
  74. GetParaLoc:=LOC_FPUREGISTER;
  75. enumdef:
  76. getparaloc:=LOC_REGISTER;
  77. pointerdef:
  78. getparaloc:=LOC_REGISTER;
  79. formaldef:
  80. getparaloc:=LOC_REGISTER;
  81. classrefdef:
  82. getparaloc:=LOC_REGISTER;
  83. recorddef:
  84. getparaloc:=LOC_REFERENCE;
  85. objectdef:
  86. if is_object(p) then
  87. getparaloc:=LOC_REFERENCE
  88. else
  89. getparaloc:=LOC_REGISTER;
  90. stringdef:
  91. if is_shortstring(p) or is_longstring(p) then
  92. getparaloc:=LOC_REFERENCE
  93. else
  94. getparaloc:=LOC_REGISTER;
  95. procvardef:
  96. if (po_methodpointer in tprocvardef(p).procoptions) then
  97. getparaloc:=LOC_REFERENCE
  98. else
  99. getparaloc:=LOC_REGISTER;
  100. filedef:
  101. getparaloc:=LOC_REGISTER;
  102. arraydef:
  103. getparaloc:=LOC_REFERENCE;
  104. setdef:
  105. if is_smallset(p) then
  106. getparaloc:=LOC_REGISTER
  107. else
  108. getparaloc:=LOC_REFERENCE;
  109. variantdef:
  110. getparaloc:=LOC_REFERENCE;
  111. { avoid problems with errornous definitions }
  112. errordef:
  113. getparaloc:=LOC_REGISTER;
  114. else
  115. internalerror(2002071001);
  116. end;
  117. end;
  118. procedure TSparcParaManager.create_param_loc_info(p:TAbstractProcDef);
  119. var
  120. nextintreg : tsuperregister;
  121. nextfloatreg : toldregister;
  122. stack_offset : longint;
  123. hp : tparaitem;
  124. loc : tcgloc;
  125. is_64bit : boolean;
  126. begin
  127. nextintreg:=RS_O0;
  128. nextfloatreg:=R_F0;
  129. stack_offset:=92;
  130. hp:=TParaItem(p.para.First);
  131. while assigned(hp) do
  132. begin
  133. loc:=GetParaLoc(hp.paratype.def);
  134. case loc of
  135. LOC_REGISTER:
  136. begin
  137. hp.paraloc.size:=def_cgSize(hp.paratype.def);
  138. if hp.paraloc.size=OS_NO then
  139. hp.paraloc.size:=OS_ADDR;
  140. is_64bit:=(hp.paraloc.size in [OS_64,OS_S64]);
  141. if NextIntReg<=RS_I5-ord(is_64bit) then
  142. begin
  143. hp.paraloc.loc:=LOC_REGISTER;
  144. hp.paraloc.registerlow.enum:=R_INTREGISTER;
  145. hp.paraloc.registerlow.number:=NextIntReg shl 8;
  146. inc(NextIntReg);
  147. if is_64bit then
  148. begin
  149. hp.paraloc.registerhigh.enum:=R_INTREGISTER;
  150. hp.paraloc.registerhigh.number:=nextintreg shl 8;
  151. inc(nextintreg);
  152. end;
  153. end
  154. else
  155. begin
  156. nextintreg:=RS_I6;
  157. hp.paraloc.loc:=LOC_REFERENCE;
  158. hp.paraloc.reference.index.enum:=R_INTREGISTER;
  159. hp.paraloc.reference.index.number:=NR_STACK_POINTER_REG;
  160. hp.paraloc.reference.offset:=stack_offset;
  161. if not is_64bit then
  162. inc(stack_offset,4)
  163. else
  164. inc(stack_offset,8);
  165. end;
  166. end;
  167. LOC_FPUREGISTER:
  168. begin
  169. if hp.paratyp in [vs_var,vs_out] then
  170. begin
  171. if NextIntReg<=RS_O5 then
  172. begin
  173. hp.paraloc.size:=OS_ADDR;
  174. hp.paraloc.loc:=LOC_REGISTER;
  175. hp.paraloc.register.enum:=R_INTREGISTER;
  176. hp.paraloc.register.number:=nextintreg shl 8;
  177. inc(nextintreg);
  178. end
  179. else
  180. begin
  181. {!!!!!!!}
  182. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  183. internalerror(2002071006);
  184. end;
  185. end
  186. else if nextfloatreg<=R_F10 then
  187. begin
  188. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  189. hp.paraloc.loc:=LOC_FPUREGISTER;
  190. { Doubles use 2 FPU regs, align on even register }
  191. if (hp.paraloc.size<>OS_F32) and
  192. odd(ord(nextfloatreg)-ord(R_F0)) then
  193. inc(nextfloatreg);
  194. hp.paraloc.register.enum:=nextfloatreg;
  195. inc(nextfloatreg);
  196. { Doubles use 2 FPU regs }
  197. if hp.paraloc.size<>OS_F32 then
  198. inc(nextfloatreg);
  199. end
  200. else
  201. begin
  202. {!!!!!!!}
  203. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  204. internalerror(2002071004);
  205. end;
  206. end;
  207. LOC_REFERENCE:
  208. begin
  209. hp.paraloc.size:=OS_ADDR;
  210. if push_addr_param(hp.paratype.def,p.proccalloption) or (hp.paratyp in [vs_var,vs_out]) then
  211. begin
  212. if nextintreg<=RS_O5 then
  213. begin
  214. hp.paraloc.loc:=LOC_REGISTER;
  215. hp.paraloc.register.enum:=R_INTREGISTER;
  216. hp.paraloc.register.number:=nextintreg shl 8;
  217. inc(nextintreg);
  218. end
  219. else
  220. begin
  221. hp.paraloc.loc:=LOC_REFERENCE;
  222. hp.paraloc.reference.index.enum:=R_INTREGISTER;
  223. hp.paraloc.reference.index.number:=NR_STACK_POINTER_REG;
  224. hp.paraloc.reference.offset:=stack_offset;
  225. inc(stack_offset,4);
  226. end;
  227. end
  228. else
  229. begin
  230. hp.paraloc.loc:=LOC_REFERENCE;
  231. hp.paraloc.reference.index.enum:=R_INTREGISTER;
  232. hp.paraloc.reference.index.number:=NR_STACK_POINTER_REG;
  233. hp.paraloc.reference.offset:=stack_offset;
  234. inc(stack_offset,hp.paratype.def.size);
  235. end;
  236. end;
  237. else
  238. internalerror(2002071002);
  239. end;
  240. hp:=TParaItem(hp.Next);
  241. end;
  242. end;
  243. function tSparcParaManager.GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;
  244. begin
  245. with GetFuncRetParaLoc do
  246. begin
  247. case p.rettype.def.deftype of
  248. orddef,enumdef:
  249. begin
  250. loc:=LOC_REGISTER;
  251. register.enum:=R_INTREGISTER;
  252. register.number:=NR_FUNCTION_RETURN_REG;
  253. size:=def_cgsize(p.rettype.def);
  254. if size in [OS_S64,OS_64] then
  255. internalerror(200305309);
  256. end;
  257. floatdef:
  258. begin
  259. loc:=LOC_FPUREGISTER;
  260. register.enum:=R_F1;
  261. size:=def_cgsize(p.rettype.def);
  262. end;
  263. setdef,
  264. variantdef,
  265. pointerdef,
  266. formaldef,
  267. classrefdef,
  268. recorddef,
  269. objectdef,
  270. stringdef,
  271. procvardef,
  272. filedef,
  273. arraydef,
  274. errordef:
  275. begin
  276. loc:=LOC_REFERENCE;
  277. reference.index.enum:=R_INTREGISTER;
  278. reference.index.number:=NR_FRAME_POINTER_REG;
  279. reference.offset:=64;
  280. size:=OS_ADDR;
  281. end;
  282. else
  283. internalerror(2002090903);
  284. end;
  285. end;
  286. end;
  287. begin
  288. ParaManager:=TSparcParaManager.create;
  289. end.
  290. {
  291. $Log$
  292. Revision 1.19 2003-06-01 21:38:06 peter
  293. * getregisterfpu size parameter added
  294. * op_const_reg size parameter added
  295. * sparc updates
  296. Revision 1.18 2003/05/31 01:00:51 peter
  297. * register fixes
  298. Revision 1.17 2003/05/30 23:57:08 peter
  299. * more sparc cleanup
  300. * accumulator removed, splitted in function_return_reg (called) and
  301. function_result_reg (caller)
  302. Revision 1.16 2003/04/23 13:35:39 peter
  303. * fix sparc compile
  304. Revision 1.15 2003/04/23 12:35:35 florian
  305. * fixed several issues with powerpc
  306. + applied a patch from Jonas for nested function calls (PowerPC only)
  307. * ...
  308. Revision 1.14 2003/01/08 18:43:58 daniel
  309. * Tregister changed into a record
  310. Revision 1.13 2003/01/05 21:32:35 mazen
  311. * fixing several bugs compiling the RTL
  312. Revision 1.12 2002/11/25 19:21:49 mazen
  313. * fixed support of nSparcInline
  314. Revision 1.11 2002/11/25 17:43:28 peter
  315. * splitted defbase in defutil,symutil,defcmp
  316. * merged isconvertable and is_equal into compare_defs(_ext)
  317. * made operator search faster by walking the list only once
  318. Revision 1.10 2002/11/18 17:32:01 peter
  319. * pass proccalloption to ret_in_xxx and push_xxx functions
  320. Revision 1.9 2002/11/03 20:22:40 mazen
  321. * parameter handling updated
  322. Revision 1.8 2002/10/13 21:46:07 mazen
  323. * assembler output format fixed
  324. Revision 1.7 2002/10/10 19:57:51 mazen
  325. * Just to update repsitory
  326. Revision 1.6 2002/10/10 15:10:39 mazen
  327. * Internal error fixed, but usually i386 parameter model used
  328. Revision 1.5 2002/10/09 13:52:19 mazen
  329. just incase some one wolud help me debugging that\!
  330. Revision 1.4 2002/10/08 21:02:22 mazen
  331. * debugging register allocation
  332. Revision 1.3 2002/10/07 20:33:05 mazen
  333. word alignement modified in g_stack_frame
  334. Revision 1.2 2002/10/04 21:57:42 mazen
  335. * 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
  336. Revision 1.1 2002/08/21 13:30:07 mazen
  337. *** empty log message ***
  338. Revision 1.2 2002/07/11 14:41:34 florian
  339. * start of the new generic parameter handling
  340. Revision 1.1 2002/07/07 09:44:32 florian
  341. * powerpc target fixed, very simple units can be compiled
  342. }