cpupara.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. {******************************************************************************
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. PowerPC specific calling conventions
  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. {SPARC specific calling conventions are handled by this unit}
  19. {$INCLUDE fpcdefs.inc}
  20. interface
  21. uses
  22. cpubase,
  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(nr:longint):TParaLocation;override;
  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. globtype,
  39. cpuinfo,cginfo,cgbase,
  40. defbase;
  41. function TSparcParaManager.GetIntParaLoc(nr:longint):TParaLocation;
  42. begin
  43. if nr<1
  44. then
  45. InternalError(2002100806);
  46. FillChar(GetIntParaLoc,SizeOf(TParaLocation),0);
  47. Dec(nr);
  48. with GetIntParaLoc do
  49. if nr<6
  50. then{The six first parameters are passed into registers}
  51. begin
  52. loc:=LOC_REGISTER;
  53. register:=TRegister(LongInt(R_i0)+nr);
  54. end
  55. else{The other parameters are passed into the frame}
  56. begin
  57. loc:=LOC_REFERENCE;
  58. reference.index:=frame_pointer_reg;
  59. reference.offset:=-68-nr*4;
  60. end;
  61. end;
  62. function GetParaLoc(p:TDef):TLoc;
  63. begin
  64. {Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER if
  65. push_addr_param for the def is true}
  66. case p.DefType of
  67. OrdDef:
  68. GetParaLoc:=LOC_REGISTER;
  69. FloatDef:
  70. GetParaLoc:=LOC_FPUREGISTER;
  71. enumdef:
  72. getparaloc:=LOC_REGISTER;
  73. pointerdef:
  74. getparaloc:=LOC_REGISTER;
  75. formaldef:
  76. getparaloc:=LOC_REGISTER;
  77. classrefdef:
  78. getparaloc:=LOC_REGISTER;
  79. recorddef:
  80. getparaloc:=LOC_REFERENCE;
  81. objectdef:
  82. if is_object(p)
  83. then
  84. getparaloc:=LOC_REFERENCE
  85. else
  86. getparaloc:=LOC_REGISTER;
  87. stringdef:
  88. if is_shortstring(p) or is_longstring(p)
  89. then
  90. getparaloc:=LOC_REFERENCE
  91. else
  92. getparaloc:=LOC_REGISTER;
  93. procvardef:
  94. if (po_methodpointer in tprocvardef(p).procoptions)
  95. then
  96. getparaloc:=LOC_REFERENCE
  97. else
  98. getparaloc:=LOC_REGISTER;
  99. filedef:
  100. getparaloc:=LOC_REGISTER;
  101. arraydef:
  102. getparaloc:=LOC_REFERENCE;
  103. setdef:
  104. if is_smallset(p)
  105. 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,nextfloatreg:tregister;
  121. stack_offset : aword;
  122. hp : tparaitem;
  123. loc : tloc;
  124. is_64bit: boolean;
  125. begin
  126. nextintreg:=R_i0;
  127. nextfloatreg:=R_F0;
  128. stack_offset:=92;
  129. WriteLn('***********************************************');
  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
  139. then
  140. hp.paraloc.size:=OS_ADDR;
  141. is_64bit:=hp.paraloc.size in [OS_64,OS_S64];
  142. if NextIntReg<=TRegister(ord(R_i5)-ord(is_64bit))
  143. then
  144. begin
  145. WriteLn('Allocating ',std_reg2str[NextIntReg]);
  146. hp.paraloc.loc:=LOC_REGISTER;
  147. hp.paraloc.registerlow:=NextIntReg;
  148. inc(NextIntReg);
  149. if is_64bit
  150. then
  151. begin
  152. hp.paraloc.registerhigh:=nextintreg;
  153. inc(nextintreg);
  154. end;
  155. end
  156. else
  157. begin
  158. nextintreg:=R_i6;
  159. hp.paraloc.loc:=LOC_REFERENCE;
  160. hp.paraloc.reference.index:=stack_pointer_reg;
  161. hp.paraloc.reference.offset:=stack_offset;
  162. if not is_64bit
  163. then
  164. inc(stack_offset,4)
  165. else
  166. inc(stack_offset,8);
  167. end;
  168. end;
  169. LOC_FPUREGISTER:
  170. begin
  171. if hp.paratyp in [vs_var,vs_out] then
  172. begin
  173. if nextintreg<=R_O5 then
  174. begin
  175. hp.paraloc.size:=OS_ADDR;
  176. hp.paraloc.loc:=LOC_REGISTER;
  177. hp.paraloc.register:=nextintreg;
  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. hp.paraloc.register:=nextfloatreg;
  192. inc(nextfloatreg);
  193. end
  194. else
  195. begin
  196. {!!!!!!!}
  197. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  198. internalerror(2002071004);
  199. end;
  200. end;
  201. LOC_REFERENCE:
  202. begin
  203. hp.paraloc.size:=OS_ADDR;
  204. if push_addr_param(hp.paratype.def,p.proccalloption in [pocall_cdecl,pocall_cppdecl]) or (hp.paratyp in [vs_var,vs_out]) then
  205. begin
  206. if nextintreg<=R_O5 then
  207. begin
  208. hp.paraloc.loc:=LOC_REGISTER;
  209. hp.paraloc.register:=nextintreg;
  210. inc(nextintreg);
  211. end
  212. else
  213. begin
  214. hp.paraloc.loc:=LOC_REFERENCE;
  215. hp.paraloc.reference.index:=stack_pointer_reg;
  216. hp.paraloc.reference.offset:=stack_offset;
  217. inc(stack_offset,4);
  218. end;
  219. end
  220. else
  221. begin
  222. hp.paraloc.loc:=LOC_REFERENCE;
  223. hp.paraloc.reference.index:=stack_pointer_reg;
  224. hp.paraloc.reference.offset:=stack_offset;
  225. inc(stack_offset,hp.paratype.def.size);
  226. end;
  227. end;
  228. else
  229. internalerror(2002071002);
  230. end;
  231. hp:=TParaItem(hp.Next);
  232. end;
  233. end;
  234. function tSparcParaManager.GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;
  235. begin
  236. with GetFuncRetParaLoc do
  237. case p.rettype.def.deftype of
  238. orddef,enumdef:
  239. begin
  240. WriteLn('Allocating i0 as return register');
  241. loc:=LOC_REGISTER;
  242. register:=R_I0;
  243. size:=def_cgsize(p.rettype.def);
  244. if size in [OS_S64,OS_64]
  245. then
  246. RegisterHigh:=R_I1;
  247. end;
  248. floatdef:
  249. begin
  250. loc:=LOC_FPUREGISTER;
  251. register:=R_F1;
  252. size:=def_cgsize(p.rettype.def);
  253. end;
  254. setdef,
  255. variantdef,
  256. pointerdef,
  257. formaldef,
  258. classrefdef,
  259. recorddef,
  260. objectdef,
  261. stringdef,
  262. procvardef,
  263. filedef,
  264. arraydef,
  265. errordef:
  266. begin
  267. loc:=LOC_REFERENCE;
  268. reference.index:=frame_pointer_reg;
  269. reference.offset:=64;
  270. size:=OS_ADDR;
  271. end;
  272. else
  273. internalerror(2002090903);
  274. end;
  275. end;
  276. begin
  277. ParaManager:=TSparcParaManager.create;
  278. end.
  279. {
  280. $Log$
  281. Revision 1.8 2002-10-13 21:46:07 mazen
  282. * assembler output format fixed
  283. Revision 1.7 2002/10/10 19:57:51 mazen
  284. * Just to update repsitory
  285. Revision 1.6 2002/10/10 15:10:39 mazen
  286. * Internal error fixed, but usually i386 parameter model used
  287. Revision 1.5 2002/10/09 13:52:19 mazen
  288. just incase some one wolud help me debugging that\!
  289. Revision 1.4 2002/10/08 21:02:22 mazen
  290. * debugging register allocation
  291. Revision 1.3 2002/10/07 20:33:05 mazen
  292. word alignement modified in g_stack_frame
  293. Revision 1.2 2002/10/04 21:57:42 mazen
  294. * 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
  295. Revision 1.1 2002/08/21 13:30:07 mazen
  296. *** empty log message ***
  297. Revision 1.2 2002/07/11 14:41:34 florian
  298. * start of the new generic parameter handling
  299. Revision 1.1 2002/07/07 09:44:32 florian
  300. * powerpc target fixed, very simple units can be compiled
  301. }