cpupara.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. Alpha specific calling conventions
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. { Alpha specific calling conventions are handled by this unit
  18. }
  19. unit cpupara;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. cpubase,
  24. symconst,symbase,symtype,symdef,paramgr;
  25. type
  26. talphaparamanager = class(tparamanager)
  27. function getintparaloc(nr : longint) : tparalocation;override;
  28. procedure create_param_loc_info(p : tabstractprocdef);override;
  29. function getfuncretparaloc(p : tabstractprocdef) : tparalocation;override;
  30. end;
  31. implementation
  32. uses
  33. verbose,
  34. globtype,
  35. cpuinfo,cginfo,cgbase,
  36. defbase;
  37. function talphaparamanager.getintparaloc(nr : longint) : tparalocation;
  38. begin
  39. fillchar(result,sizeof(tparalocation),0);
  40. if nr<1 then
  41. internalerror(2002070801)
  42. else if nr<=8 then
  43. begin
  44. result.loc:=LOC_REGISTER;
  45. result.register:=tregister(longint(R_2)+nr);
  46. end
  47. else
  48. begin
  49. result.loc:=LOC_REFERENCE;
  50. result.reference.index:=stack_pointer_reg;
  51. result.reference.offset:=(nr-8)*4;
  52. end;
  53. end;
  54. function getparaloc(p : tdef) : tloc;
  55. begin
  56. { Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER
  57. if push_addr_param for the def is true
  58. }
  59. case p.typ of
  60. orddef:
  61. getparaloc:=LOC_REGISTER;
  62. floatdef:
  63. getparaloc:=LOC_FPUREGISTER;
  64. enumdef:
  65. getparaloc:=LOC_REGISTER;
  66. pointerdef:
  67. getparaloc:=LOC_REGISTER;
  68. formaldef:
  69. getparaloc:=LOC_REGISTER;
  70. classrefdef:
  71. getparaloc:=LOC_REGISTER;
  72. recorddef:
  73. getparaloc:=LOC_REFERENCE;
  74. objectdef:
  75. if is_object(p) then
  76. getparaloc:=LOC_REFERENCE
  77. else
  78. getparaloc:=LOC_REGISTER;
  79. stringdef:
  80. if is_shortstring(p) or is_longstring(p) then
  81. getparaloc:=LOC_REFERENCE
  82. else
  83. getparaloc:=LOC_REGISTER;
  84. procvardef:
  85. if (po_methodpointer in tprocvardef(p).procoptions) then
  86. getparaloc:=LOC_REFERENCE
  87. else
  88. getparaloc:=LOC_REGISTER;
  89. filedef:
  90. getparaloc:=LOC_REGISTER;
  91. arraydef:
  92. getparaloc:=LOC_REFERENCE;
  93. setdef:
  94. if is_smallset(p) then
  95. getparaloc:=LOC_REGISTER
  96. else
  97. getparaloc:=LOC_REFERENCE;
  98. variantdef:
  99. getparaloc:=LOC_REFERENCE;
  100. { avoid problems with errornous definitions }
  101. errordef:
  102. getparaloc:=LOC_REGISTER;
  103. else
  104. internalerror(2002071001);
  105. end;
  106. end;
  107. procedure talphaparamanager.create_param_loc_info(p : tabstractprocdef);
  108. var
  109. nextintreg,nextfloatreg,nextmmreg : tregister;
  110. stack_offset : aword;
  111. hp : tparaitem;
  112. loc : tloc;
  113. is_64bit: boolean;
  114. begin
  115. nextintreg:=R_3;
  116. nextfloatreg:=R_F1;
  117. // nextmmreg:=R_M1;
  118. stack_offset:=0;
  119. { pointer for structured results ? }
  120. if not is_void(p.returndef) then
  121. begin
  122. if not(ret_in_reg(p.returndef)) then
  123. inc(nextintreg);
  124. end;
  125. { frame pointer for nested procedures? }
  126. { inc(nextintreg); }
  127. { constructor? }
  128. { destructor? }
  129. hp:=tparaitem(p.para.last);
  130. while assigned(hp) do
  131. begin
  132. loc:=getparaloc(hp.paratype.def);
  133. hp.paraloc.sp_fixup:=0;
  134. case loc of
  135. LOC_REGISTER:
  136. begin
  137. hp.paraloc.size := def_cgsize(hp.paratype.def);
  138. { for things like formaldef }
  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<=tregister(ord(R_10)-ord(is_64bit)) then
  143. begin
  144. hp.paraloc.loc:=LOC_REGISTER;
  145. hp.paraloc.register64.reglo:=nextintreg;
  146. inc(nextintreg);
  147. if is_64bit then
  148. begin
  149. hp.paraloc.register64.reghi:=nextintreg;
  150. inc(nextintreg);
  151. end;
  152. end
  153. else
  154. begin
  155. nextintreg := R_11;
  156. hp.paraloc.loc:=LOC_REFERENCE;
  157. hp.paraloc.reference.index:=stack_pointer_reg;
  158. hp.paraloc.reference.offset:=stack_offset;
  159. if not is_64bit then
  160. inc(stack_offset,4)
  161. else
  162. inc(stack_offset,8);
  163. end;
  164. end;
  165. LOC_FPUREGISTER:
  166. begin
  167. if hp.paratyp in [vs_var,vs_out] then
  168. begin
  169. if nextintreg<=R_10 then
  170. begin
  171. hp.paraloc.size:=OS_ADDR;
  172. hp.paraloc.loc:=LOC_REGISTER;
  173. hp.paraloc.register:=nextintreg;
  174. inc(nextintreg);
  175. end
  176. else
  177. begin
  178. {!!!!!!!}
  179. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  180. internalerror(2002071006);
  181. end;
  182. end
  183. else if nextfloatreg<=R_F10 then
  184. begin
  185. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  186. hp.paraloc.loc:=LOC_FPUREGISTER;
  187. hp.paraloc.register:=nextfloatreg;
  188. inc(nextfloatreg);
  189. end
  190. else
  191. begin
  192. {!!!!!!!}
  193. hp.paraloc.size:=def_cgsize(hp.paratype.def);
  194. internalerror(2002071004);
  195. end;
  196. end;
  197. LOC_REFERENCE:
  198. begin
  199. hp.paraloc.size:=OS_ADDR;
  200. if push_addr_param(hp.paratype.def,p.proccalloption in [pocall_cdecl,pocall_cppdecl]) or (hp.paratyp in [vs_var,vs_out]) then
  201. begin
  202. if nextintreg<=R_10 then
  203. begin
  204. hp.paraloc.loc:=LOC_REGISTER;
  205. hp.paraloc.register:=nextintreg;
  206. inc(nextintreg);
  207. end
  208. else
  209. begin
  210. hp.paraloc.loc:=LOC_REFERENCE;
  211. hp.paraloc.reference.index:=stack_pointer_reg;
  212. hp.paraloc.reference.offset:=stack_offset;
  213. inc(stack_offset,4);
  214. end;
  215. end
  216. else
  217. begin
  218. hp.paraloc.loc:=LOC_REFERENCE;
  219. hp.paraloc.reference.index:=stack_pointer_reg;
  220. hp.paraloc.reference.offset:=stack_offset;
  221. inc(stack_offset,hp.paratype.def.size);
  222. end;
  223. end;
  224. else
  225. internalerror(2002071002);
  226. end;
  227. hp:=tparaitem(hp.previous);
  228. end;
  229. end;
  230. function talphaparamanager.getfuncretparaloc(p : tabstractprocdef) : tparalocation;
  231. begin
  232. case p.returndef.typ of
  233. orddef,
  234. enumdef:
  235. begin
  236. getfuncretparaloc.loc:=LOC_REGISTER;
  237. getfuncretparaloc.register:=R_3;
  238. getfuncretparaloc.size:=def_cgsize(p.returndef);
  239. if getfuncretparaloc.size in [OS_S64,OS_64] then
  240. getfuncretparaloc.register64.reghi:=R_4;
  241. end;
  242. floatdef:
  243. begin
  244. getfuncretparaloc.loc:=LOC_FPUREGISTER;
  245. getfuncretparaloc.register:=R_F1;
  246. getfuncretparaloc.size:=def_cgsize(p.returndef);
  247. end;
  248. pointerdef,
  249. formaldef,
  250. classrefdef,
  251. recorddef,
  252. objectdef,
  253. stringdef,
  254. procvardef,
  255. filedef,
  256. arraydef,
  257. errordef:
  258. begin
  259. getfuncretparaloc.loc:=LOC_REGISTER;
  260. getfuncretparaloc.register:=R_3;
  261. getfuncretparaloc.size:=OS_ADDR;
  262. end;
  263. else
  264. internalerror(2002090903);
  265. end;
  266. end;
  267. begin
  268. paramanager:=talphaparamanager.create;
  269. end.