cpupara.pas 14 KB

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