cpupara.pas 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. {*****************************************************************************}
  2. { File : cpupara.pas }
  3. { Author : Mazen NEIFER }
  4. { Project : Free Pascal Compiler (FPC) }
  5. { Creation date : 2002\07\13 }
  6. { Last modification date : 2002\08\20 }
  7. { Licence : GPL }
  8. { Bug report : [email protected] }
  9. {*****************************************************************************}
  10. {
  11. $Id$
  12. Copyright (c) 2002 by Florian Klaempfl
  13. PowerPC specific calling conventions
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation; either version 2 of the License, or
  17. (at your option) any later version.
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. GNU General Public License for more details.
  22. You should have received a copy of the GNU General Public License
  23. along with this program; if not, write to the Free Software
  24. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. ****************************************************************************}
  26. unit cpupara;
  27. {SPARC specific calling conventions are handled by this unit}
  28. {$INCLUDE fpcdefs.inc}
  29. interface
  30. uses
  31. cpubase,
  32. symconst,symbase,symtype,symdef,paramgr;
  33. type
  34. TSparcParaManager=class(TParaManager)
  35. function GetIntParaLoc(nr:longint):TParaLocation;override;
  36. procedure create_param_loc_info(p:TAbstractProcDef);override;
  37. function GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;override;
  38. end;
  39. implementation
  40. uses
  41. verbose,
  42. globtype,
  43. cpuinfo,cginfo,cgbase,
  44. defbase;
  45. function TSparcParaManager.GetIntParaLoc(nr:longint):TParaLocation;
  46. begin
  47. if nr<1
  48. then
  49. InternalError(2002100806);
  50. FillChar(Result,SizeOf(TParaLocation),0);
  51. Dec(nr);
  52. with Result do
  53. if nr<6
  54. then{The six first parameters are passed into registers}
  55. begin
  56. loc:=LOC_REGISTER;
  57. register:=TRegister(LongInt(R_O0)+nr);
  58. WriteLn('-------------------------------------------');
  59. end
  60. else{The other parameters are passed into the frame}
  61. begin
  62. loc:=LOC_REFERENCE;
  63. reference.index:=frame_pointer_reg;
  64. reference.offset:=-92-(nr-6)*4;
  65. WriteLn('+++++++++++++++++++++++++++++++++++++++++++');
  66. end;
  67. end;
  68. function GetParaLoc(p:TDef):TLoc;
  69. begin
  70. {Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER if
  71. push_addr_param for the def is true}
  72. case p.DefType of
  73. OrdDef:
  74. GetParaLoc:=LOC_REGISTER;
  75. FloatDef:
  76. GetParaLoc:=LOC_FPUREGISTER;
  77. enumdef:
  78. getparaloc:=LOC_REGISTER;
  79. pointerdef:
  80. getparaloc:=LOC_REGISTER;
  81. formaldef:
  82. getparaloc:=LOC_REGISTER;
  83. classrefdef:
  84. getparaloc:=LOC_REGISTER;
  85. recorddef:
  86. getparaloc:=LOC_REFERENCE;
  87. objectdef:
  88. if is_object(p) then
  89. getparaloc:=LOC_REFERENCE
  90. else
  91. getparaloc:=LOC_REGISTER;
  92. stringdef:
  93. if is_shortstring(p) or is_longstring(p) then
  94. getparaloc:=LOC_REFERENCE
  95. else
  96. getparaloc:=LOC_REGISTER;
  97. procvardef:
  98. if (po_methodpointer in tprocvardef(p).procoptions) then
  99. getparaloc:=LOC_REFERENCE
  100. else
  101. getparaloc:=LOC_REGISTER;
  102. filedef:
  103. getparaloc:=LOC_REGISTER;
  104. arraydef:
  105. getparaloc:=LOC_REFERENCE;
  106. setdef:
  107. if is_smallset(p) then
  108. getparaloc:=LOC_REGISTER
  109. else
  110. getparaloc:=LOC_REFERENCE;
  111. variantdef:
  112. getparaloc:=LOC_REFERENCE;
  113. { avoid problems with errornous definitions }
  114. errordef:
  115. getparaloc:=LOC_REGISTER;
  116. else
  117. internalerror(2002071001);
  118. end;
  119. end;
  120. procedure TSparcParaManager.create_param_loc_info(p:tabstractprocdef);
  121. var
  122. nextintreg,nextfloatreg,nextmmreg : tregister;
  123. stack_offset : aword;
  124. hp : tparaitem;
  125. loc : tloc;
  126. is_64bit: boolean;
  127. begin
  128. nextintreg:=R_O0;
  129. nextfloatreg:=R_F0;
  130. nextmmreg:=R_NONE;
  131. stack_offset:=92;
  132. {pointer for structured results ?}
  133. if not is_void(p.RetType.def)
  134. then
  135. if not(ret_in_reg(p.rettype.def))
  136. then
  137. inc(nextintreg);
  138. {frame pointer for nested procedures?}
  139. { inc(nextintreg); }
  140. { constructor? }
  141. { destructor? }
  142. WriteLn('***********************************************');
  143. hp:=TParaItem(p.para.last);
  144. while assigned(hp) do
  145. begin
  146. loc:=GetParaLoc(hp.paratype.def);
  147. hp.paraloc.sp_fixup:=0;
  148. case loc of
  149. LOC_REGISTER:
  150. begin
  151. hp.paraloc.size:=def_cgSize(hp.paratype.def);
  152. if hp.paraloc.size=OS_NO
  153. then
  154. hp.paraloc.size:=OS_ADDR;
  155. is_64bit:=hp.paraloc.size in [OS_64,OS_S64];
  156. if NextIntReg<=TRegister(ord(R_O5)-ord(is_64bit))
  157. then
  158. begin
  159. WriteLn('Allocating ',std_reg2str[NextIntReg]);
  160. hp.paraloc.loc:=LOC_REGISTER;
  161. hp.paraloc.registerlow:=NextIntReg;
  162. inc(NextIntReg);
  163. if is_64bit
  164. then
  165. begin
  166. hp.paraloc.registerhigh:=nextintreg;
  167. inc(nextintreg);
  168. end;
  169. end
  170. else
  171. begin
  172. nextintreg:=R_O6;
  173. hp.paraloc.loc:=LOC_REFERENCE;
  174. hp.paraloc.reference.index:=stack_pointer_reg;
  175. hp.paraloc.reference.offset:=stack_offset;
  176. if not is_64bit
  177. then
  178. inc(stack_offset,4)
  179. else
  180. inc(stack_offset,8);
  181. end;
  182. end;
  183. LOC_FPUREGISTER:
  184. begin
  185. if hp.paratyp in [vs_var,vs_out] then
  186. begin
  187. if nextintreg<=R_O5 then
  188. begin
  189. hp.paraloc.size:=OS_ADDR;
  190. hp.paraloc.loc:=LOC_REGISTER;
  191. hp.paraloc.register:=nextintreg;
  192. inc(nextintreg);
  193. end
  194. else
  195. begin
  196. {!!!!!!!}
  197. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  198. internalerror(2002071006);
  199. end;
  200. end
  201. else if nextfloatreg<=R_F10 then
  202. begin
  203. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  204. hp.paraloc.loc:=LOC_FPUREGISTER;
  205. hp.paraloc.register:=nextfloatreg;
  206. inc(nextfloatreg);
  207. end
  208. else
  209. begin
  210. {!!!!!!!}
  211. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  212. internalerror(2002071004);
  213. end;
  214. end;
  215. LOC_REFERENCE:
  216. begin
  217. hp.paraloc.size:=OS_ADDR;
  218. if push_addr_param(hp.paratype.def,p.proccalloption in [pocall_cdecl,pocall_cppdecl]) or (hp.paratyp in [vs_var,vs_out]) then
  219. begin
  220. if nextintreg<=R_O5 then
  221. begin
  222. hp.paraloc.loc:=LOC_REGISTER;
  223. hp.paraloc.register:=nextintreg;
  224. inc(nextintreg);
  225. end
  226. else
  227. begin
  228. hp.paraloc.loc:=LOC_REFERENCE;
  229. hp.paraloc.reference.index:=stack_pointer_reg;
  230. hp.paraloc.reference.offset:=stack_offset;
  231. inc(stack_offset,4);
  232. end;
  233. end
  234. else
  235. begin
  236. hp.paraloc.loc:=LOC_REFERENCE;
  237. hp.paraloc.reference.index:=stack_pointer_reg;
  238. hp.paraloc.reference.offset:=stack_offset;
  239. inc(stack_offset,hp.paratype.def.size);
  240. end;
  241. end;
  242. else
  243. internalerror(2002071002);
  244. end;
  245. hp:=TParaItem(hp.previous);
  246. end;
  247. end;
  248. function tSparcParaManager.GetFuncRetParaLoc(p:TAbstractProcDef):TParaLocation;
  249. begin
  250. case p.rettype.def.deftype of
  251. orddef,enumdef:
  252. begin
  253. WriteLn('Allocating i0 as return register');
  254. GetFuncRetParaLoc.loc:=LOC_REGISTER;
  255. GetFuncRetParaLoc.register:=R_i0;
  256. GetFuncRetParaLoc.size:=def_cgsize(p.rettype.def);
  257. if GetFuncRetParaLoc.size in [OS_S64,OS_64]
  258. then
  259. GetFuncRetParaLoc.RegisterHigh:=R_O1;
  260. end;
  261. floatdef:
  262. begin
  263. GetFuncRetParaLoc.loc:=LOC_FPUREGISTER;
  264. GetFuncRetParaLoc.register:=R_F1;
  265. GetFuncRetParaLoc.size:=def_cgsize(p.rettype.def);
  266. end;
  267. { smallsets are OS_INT in R3, others are OS_ADDR in R3 -> the same }
  268. { ugly, I know :) (JM) }
  269. setdef,
  270. variantdef,
  271. pointerdef,
  272. formaldef,
  273. classrefdef,
  274. recorddef,
  275. objectdef,
  276. stringdef,
  277. procvardef,
  278. filedef,
  279. arraydef,
  280. errordef:
  281. begin
  282. GetFuncRetParaLoc.loc:=LOC_REGISTER;
  283. GetFuncRetParaLoc.register:=R_O0;
  284. GetFuncRetParaLoc.size:=OS_ADDR;
  285. end;
  286. else
  287. internalerror(2002090903);
  288. end;
  289. end;
  290. begin
  291. ParaManager:=TSparcParaManager.create;
  292. end.
  293. {
  294. $Log$
  295. Revision 1.5 2002-10-09 13:52:19 mazen
  296. just incase some one wolud help me debugging that\!
  297. Revision 1.4 2002/10/08 21:02:22 mazen
  298. * debugging register allocation
  299. Revision 1.3 2002/10/07 20:33:05 mazen
  300. word alignement modified in g_stack_frame
  301. Revision 1.2 2002/10/04 21:57:42 mazen
  302. * 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
  303. Revision 1.1 2002/08/21 13:30:07 mazen
  304. *** empty log message ***
  305. Revision 1.2 2002/07/11 14:41:34 florian
  306. * start of the new generic parameter handling
  307. Revision 1.1 2002/07/07 09:44:32 florian
  308. * powerpc target fixed, very simple units can be compiled
  309. }