cpupara.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. Alpha 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. }
  18. { Alpha specific calling conventions are handled by this unit
  19. }
  20. unit cpupara;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. cpubase,
  25. symconst,symbase,symtype,symdef,paramgr;
  26. type
  27. talphaparamanager = class(tparamanager)
  28. function getintparaloc(nr : longint) : tparalocation;override;
  29. procedure create_param_loc_info(p : tabstractprocdef);override;
  30. function getfuncretparaloc(p : tabstractprocdef) : tparalocation;override;
  31. end;
  32. implementation
  33. uses
  34. verbose,
  35. globtype,
  36. cpuinfo,cginfo,cgbase,
  37. defbase;
  38. function talphaparamanager.getintparaloc(nr : longint) : tparalocation;
  39. begin
  40. fillchar(result,sizeof(tparalocation),0);
  41. if nr<1 then
  42. internalerror(2002070801)
  43. else if nr<=8 then
  44. begin
  45. result.loc:=LOC_REGISTER;
  46. result.register:=tregister(longint(R_2)+nr);
  47. end
  48. else
  49. begin
  50. result.loc:=LOC_REFERENCE;
  51. result.reference.index:=stack_pointer_reg;
  52. result.reference.offset:=(nr-8)*4;
  53. end;
  54. end;
  55. function getparaloc(p : tdef) : tloc;
  56. begin
  57. { Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER
  58. if push_addr_param for the def is true
  59. }
  60. case p.deftype of
  61. orddef:
  62. getparaloc:=LOC_REGISTER;
  63. floatdef:
  64. getparaloc:=LOC_FPUREGISTER;
  65. enumdef:
  66. getparaloc:=LOC_REGISTER;
  67. pointerdef:
  68. getparaloc:=LOC_REGISTER;
  69. formaldef:
  70. getparaloc:=LOC_REGISTER;
  71. classrefdef:
  72. getparaloc:=LOC_REGISTER;
  73. recorddef:
  74. getparaloc:=LOC_REFERENCE;
  75. objectdef:
  76. if is_object(p) then
  77. getparaloc:=LOC_REFERENCE
  78. else
  79. getparaloc:=LOC_REGISTER;
  80. stringdef:
  81. if is_shortstring(p) or is_longstring(p) then
  82. getparaloc:=LOC_REFERENCE
  83. else
  84. getparaloc:=LOC_REGISTER;
  85. procvardef:
  86. if (po_methodpointer in tprocvardef(p).procoptions) then
  87. getparaloc:=LOC_REFERENCE
  88. else
  89. getparaloc:=LOC_REGISTER;
  90. filedef:
  91. getparaloc:=LOC_REGISTER;
  92. arraydef:
  93. getparaloc:=LOC_REFERENCE;
  94. setdef:
  95. if is_smallset(p) then
  96. getparaloc:=LOC_REGISTER
  97. else
  98. getparaloc:=LOC_REFERENCE;
  99. variantdef:
  100. getparaloc:=LOC_REFERENCE;
  101. { avoid problems with errornous definitions }
  102. errordef:
  103. getparaloc:=LOC_REGISTER;
  104. else
  105. internalerror(2002071001);
  106. end;
  107. end;
  108. procedure talphaparamanager.create_param_loc_info(p : tabstractprocdef);
  109. var
  110. nextintreg,nextfloatreg,nextmmreg : tregister;
  111. stack_offset : aword;
  112. hp : tparaitem;
  113. loc : tloc;
  114. is_64bit: boolean;
  115. begin
  116. nextintreg:=R_3;
  117. nextfloatreg:=R_F1;
  118. // nextmmreg:=R_M1;
  119. stack_offset:=0;
  120. { pointer for structured results ? }
  121. if not is_void(p.rettype.def) then
  122. begin
  123. if not(ret_in_reg(p.rettype.def)) then
  124. inc(nextintreg);
  125. end;
  126. { frame pointer for nested procedures? }
  127. { inc(nextintreg); }
  128. { constructor? }
  129. { destructor? }
  130. hp:=tparaitem(p.para.last);
  131. while assigned(hp) do
  132. begin
  133. loc:=getparaloc(hp.paratype.def);
  134. hp.paraloc.sp_fixup:=0;
  135. case loc of
  136. LOC_REGISTER:
  137. begin
  138. hp.paraloc.size := def_cgsize(hp.paratype.def);
  139. { for things like formaldef }
  140. if hp.paraloc.size = OS_NO then
  141. hp.paraloc.size := OS_ADDR;
  142. is_64bit := hp.paraloc.size in [OS_64,OS_S64];
  143. if nextintreg<=tregister(ord(R_10)-ord(is_64bit)) then
  144. begin
  145. hp.paraloc.loc:=LOC_REGISTER;
  146. hp.paraloc.registerlow:=nextintreg;
  147. inc(nextintreg);
  148. if is_64bit then
  149. begin
  150. hp.paraloc.registerhigh:=nextintreg;
  151. inc(nextintreg);
  152. end;
  153. end
  154. else
  155. begin
  156. nextintreg := R_11;
  157. hp.paraloc.loc:=LOC_REFERENCE;
  158. hp.paraloc.reference.index:=stack_pointer_reg;
  159. hp.paraloc.reference.offset:=stack_offset;
  160. if not is_64bit then
  161. inc(stack_offset,4)
  162. else
  163. inc(stack_offset,8);
  164. end;
  165. end;
  166. LOC_FPUREGISTER:
  167. begin
  168. if hp.paratyp in [vs_var,vs_out] then
  169. begin
  170. if nextintreg<=R_10 then
  171. begin
  172. hp.paraloc.size:=OS_ADDR;
  173. hp.paraloc.loc:=LOC_REGISTER;
  174. hp.paraloc.register:=nextintreg;
  175. inc(nextintreg);
  176. end
  177. else
  178. begin
  179. {!!!!!!!}
  180. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  181. internalerror(2002071006);
  182. end;
  183. end
  184. else if nextfloatreg<=R_F10 then
  185. begin
  186. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  187. hp.paraloc.loc:=LOC_FPUREGISTER;
  188. hp.paraloc.register:=nextfloatreg;
  189. inc(nextfloatreg);
  190. end
  191. else
  192. begin
  193. {!!!!!!!}
  194. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  195. internalerror(2002071004);
  196. end;
  197. end;
  198. LOC_REFERENCE:
  199. begin
  200. hp.paraloc.size:=OS_ADDR;
  201. if push_addr_param(hp.paratype.def,p.proccalloption in [pocall_cdecl,pocall_cppdecl]) or (hp.paratyp in [vs_var,vs_out]) then
  202. begin
  203. if nextintreg<=R_10 then
  204. begin
  205. hp.paraloc.loc:=LOC_REGISTER;
  206. hp.paraloc.register:=nextintreg;
  207. inc(nextintreg);
  208. end
  209. else
  210. begin
  211. hp.paraloc.loc:=LOC_REFERENCE;
  212. hp.paraloc.reference.index:=stack_pointer_reg;
  213. hp.paraloc.reference.offset:=stack_offset;
  214. inc(stack_offset,4);
  215. end;
  216. end
  217. else
  218. begin
  219. hp.paraloc.loc:=LOC_REFERENCE;
  220. hp.paraloc.reference.index:=stack_pointer_reg;
  221. hp.paraloc.reference.offset:=stack_offset;
  222. inc(stack_offset,hp.paratype.def.size);
  223. end;
  224. end;
  225. else
  226. internalerror(2002071002);
  227. end;
  228. hp:=tparaitem(hp.previous);
  229. end;
  230. end;
  231. function talphaparamanager.getfuncretparaloc(p : tabstractprocdef) : tparalocation;
  232. begin
  233. case p.rettype.def.deftype of
  234. orddef,
  235. enumdef:
  236. begin
  237. getfuncretparaloc.loc:=LOC_REGISTER;
  238. getfuncretparaloc.register:=R_3;
  239. getfuncretparaloc.size:=def_cgsize(p.rettype.def);
  240. if getfuncretparaloc.size in [OS_S64,OS_64] then
  241. getfuncretparaloc.registerhigh:=R_4;
  242. end;
  243. floatdef:
  244. begin
  245. getfuncretparaloc.loc:=LOC_FPUREGISTER;
  246. getfuncretparaloc.register:=R_F1;
  247. getfuncretparaloc.size:=def_cgsize(p.rettype.def);
  248. end;
  249. pointerdef,
  250. formaldef,
  251. classrefdef,
  252. recorddef,
  253. objectdef,
  254. stringdef,
  255. procvardef,
  256. filedef,
  257. arraydef,
  258. errordef:
  259. begin
  260. getfuncretparaloc.loc:=LOC_REGISTER;
  261. getfuncretparaloc.register:=R_3;
  262. getfuncretparaloc.size:=OS_ADDR;
  263. end;
  264. else
  265. internalerror(2002090903);
  266. end;
  267. end;
  268. begin
  269. paramanager:=talphaparamanager.create;
  270. end.
  271. {
  272. $Log$
  273. Revision 1.1 2002-09-29 23:54:12 florian
  274. * alpha compiles again, changes to common code not yet commited
  275. Revision 1.14 2002/09/28 21:27:16 florian
  276. + getparaloc supports now sets and variants
  277. Revision 1.13 2002/09/10 21:28:05 jonas
  278. * int64 paras are now handled correctly (until the registers are used up
  279. anyway :)
  280. * the return location is now initialized correctly
  281. * fixed bug where ret_in_reg() was called for the procdefinition instead
  282. of for the result of the procedure
  283. Revision 1.12 2002/09/09 09:11:37 florian
  284. - removed passes_parameters_in_reg
  285. Revision 1.11 2002/09/07 17:54:59 florian
  286. * first part of PowerPC fixes
  287. Revision 1.10 2002/09/01 21:04:49 florian
  288. * several powerpc related stuff fixed
  289. Revision 1.9 2002/08/31 12:43:31 florian
  290. * ppc compilation fixed
  291. Revision 1.8 2002/08/18 10:42:38 florian
  292. * remaining assembler writer bugs fixed, the errors in the
  293. system unit are inline assembler problems
  294. Revision 1.7 2002/08/17 22:09:47 florian
  295. * result type handling in tcgcal.pass_2 overhauled
  296. * better tnode.dowrite
  297. * some ppc stuff fixed
  298. Revision 1.6 2002/08/13 21:40:58 florian
  299. * more fixes for ppc calling conventions
  300. Revision 1.5 2002/07/30 20:50:44 florian
  301. * the code generator knows now if parameters are in registers
  302. Revision 1.4 2002/07/28 20:45:22 florian
  303. + added direct assembler reader for PowerPC
  304. Revision 1.3 2002/07/26 22:22:10 florian
  305. * several PowerPC related fixes to get forward with system unit compilation
  306. Revision 1.2 2002/07/11 14:41:34 florian
  307. * start of the new generic parameter handling
  308. Revision 1.1 2002/07/07 09:44:32 florian
  309. * powerpc target fixed, very simple units can be compiled
  310. }