cpupara.pas 13 KB

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