cpupi.pas 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. This unit contains the CPU specific part of tprocinfo
  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. { This unit contains the CPU specific part of tprocinfo. }
  19. unit cpupi;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. cutils,
  24. procinfo,cpuinfo,psub;
  25. type
  26. tppcprocinfo = class(tcgprocinfo)
  27. { offset where the frame pointer from the outer procedure is stored. }
  28. parent_framepointer_offset : longint;
  29. constructor create(aparent:tprocinfo);override;
  30. procedure set_first_temp_offset;override;
  31. procedure allocate_push_parasize(size: longint);override;
  32. function calc_stackframe_size:longint;override;
  33. end;
  34. implementation
  35. uses
  36. globtype,globals,systems,
  37. cpubase,
  38. aasmtai,
  39. tgobj,
  40. symconst,symsym,paramgr,symutil,
  41. verbose;
  42. constructor tppcprocinfo.create(aparent:tprocinfo);
  43. begin
  44. inherited create(aparent);
  45. maxpushedparasize:=0;
  46. end;
  47. procedure tppcprocinfo.set_first_temp_offset;
  48. var
  49. ofs : aword;
  50. locals: longint;
  51. begin
  52. if not(po_assembler in procdef.procoptions) then
  53. begin
  54. case target_info.abi of
  55. abi_powerpc_aix:
  56. ofs:=align(maxpushedparasize+LinkageAreaSizeAIX,16);
  57. abi_powerpc_sysv:
  58. ofs:=align(maxpushedparasize+LinkageAreaSizeSYSV,16);
  59. else
  60. internalerror(200402191);
  61. end;
  62. tg.setfirsttemp(ofs);
  63. end
  64. else
  65. begin
  66. locals := 0;
  67. current_procinfo.procdef.localst.foreach_static({$ifdef FPCPROCVAR}@{$endif}count_locals,@locals);
  68. if locals <> 0 then
  69. { at 0(r1), the previous value of r1 will be stored }
  70. tg.setfirsttemp(4);
  71. end;
  72. end;
  73. (*
  74. procedure tppcprocinfo.after_pass1;
  75. begin
  76. if not(po_assembler in procdef.procoptions) then
  77. begin
  78. if cs_asm_source in aktglobalswitches then
  79. aktproccode.insert(Tai_comment.Create(strpnew('Parameter copies start at: r1+'+tostr(procdef.parast.address_fixup))));
  80. if cs_asm_source in aktglobalswitches then
  81. aktproccode.insert(Tai_comment.Create(strpnew('Locals start at: r1+'+tostr(procdef.localst.address_fixup))));
  82. firsttemp_offset:=align(procdef.localst.address_fixup+procdef.localst.datasize,16);
  83. if cs_asm_source in aktglobalswitches then
  84. aktproccode.insert(Tai_comment.Create(strpnew('Temp. space start: r1+'+tostr(firsttemp_offset))));
  85. //!!!! tg.setfirsttemp(firsttemp_offset);
  86. tg.firsttemp:=firsttemp_offset;
  87. tg.lasttemp:=firsttemp_offset;
  88. inherited after_pass1;
  89. end;
  90. end;
  91. *)
  92. procedure tppcprocinfo.allocate_push_parasize(size:longint);
  93. begin
  94. if size>maxpushedparasize then
  95. maxpushedparasize:=size;
  96. end;
  97. function tppcprocinfo.calc_stackframe_size:longint;
  98. var
  99. first_save_fpu_register: longint;
  100. begin
  101. { more or less copied from cgcpu.pas/g_stackframe_entry }
  102. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  103. case target_info.abi of
  104. abi_powerpc_aix:
  105. first_save_fpu_register := 14;
  106. abi_powerpc_sysv:
  107. first_save_fpu_register := 9;
  108. else
  109. internalerror(2003122903);
  110. end;
  111. if not (po_assembler in procdef.procoptions) then
  112. result := align(align((31-13+1)*4+(31-first_save_fpu_register+1)*8,16)+tg.lasttemp,16)
  113. else
  114. result := align(tg.lasttemp,16);
  115. end;
  116. begin
  117. cprocinfo:=tppcprocinfo;
  118. end.
  119. {
  120. $Log$
  121. Revision 1.34 2004-02-19 17:07:42 florian
  122. * fixed arg. area calculation
  123. Revision 1.33 2003/12/29 14:17:50 jonas
  124. * fixed saving/restoring of volatile fpu registers under sysv
  125. + better provisions for abi differences regarding fpu registers that have
  126. to be saved
  127. Revision 1.32 2003/12/07 16:40:45 jonas
  128. * moved count_locals from pstatmnt to symutils
  129. * use count_locals in powerpc/cpupi to check whether we should set the
  130. first temp offset (and as such generate a stackframe)
  131. Revision 1.31 2003/11/29 22:54:32 jonas
  132. * more ppc fixes, hello world works again under linuxppc
  133. Revision 1.30 2003/11/29 16:27:19 jonas
  134. * fixed several ppc assembler reader related problems
  135. * local vars in assembler procedures now start at offset 4
  136. * fixed second_int_to_bool (apparently an integer can be in LOC_JUMP??)
  137. Revision 1.29 2003/10/01 20:34:49 peter
  138. * procinfo unit contains tprocinfo
  139. * cginfo renamed to cgbase
  140. * moved cgmessage to verbose
  141. * fixed ppc and sparc compiles
  142. Revision 1.28 2003/09/28 17:55:04 peter
  143. * parent framepointer changed to hidden parameter
  144. * tloadparentfpnode added
  145. Revision 1.27 2003/08/18 11:51:19 olle
  146. + cleaning up in proc entry and exit, now calc_stack_frame always is used.
  147. Revision 1.26 2003/08/16 14:26:44 jonas
  148. * set correct localsymtable fixup already in handle_body_start instead
  149. of in after_pass1, as it's necessary to get the correct offsets for
  150. the calleeside paralocs (and those are now setup in the generic
  151. handle_body_start)
  152. Revision 1.25 2003/08/08 15:52:50 olle
  153. * merged macos entry/exit code generation into the general one.
  154. Revision 1.24 2003/07/06 20:25:03 jonas
  155. * fixed ppc compiler
  156. Revision 1.23 2003/06/13 21:19:32 peter
  157. * current_procdef removed, use current_procinfo.procdef instead
  158. Revision 1.22 2003/06/02 21:42:05 jonas
  159. * function results can now also be regvars
  160. - removed tprocinfo.return_offset, never use it again since it's invalid
  161. if the result is a regvar
  162. Revision 1.21 2003/05/24 11:47:27 jonas
  163. * fixed framepointer storage: it's now always stored at r1+12, which is
  164. a place in the link area reserved for compiler use.
  165. Revision 1.20 2003/05/23 18:51:26 jonas
  166. * fixed support for nested procedures and more parameters than those
  167. which fit in registers (untested/probably not working: calling a
  168. nested procedure from a deeper nested procedure)
  169. Revision 1.19 2003/05/22 21:34:11 peter
  170. * inherite from tcgprocinfo
  171. Revision 1.18 2003/05/17 14:05:30 jonas
  172. * fixed para/localst calculations (note to self: don't commit at
  173. extremely late/early hours :)
  174. Revision 1.17 2003/05/16 23:15:51 jonas
  175. * workaround for nested procedures until Peter fixes it properly :)
  176. Revision 1.16 2003/05/16 20:00:39 jonas
  177. * powerpc nested procedure fixes, should work completely now if all
  178. local variables of the parent procedure are declared before the
  179. nested procedures are declared
  180. Revision 1.15 2003/05/15 19:39:09 florian
  181. * fixed ppc compiler which was broken by Peter's changes
  182. Revision 1.14 2003/05/10 23:57:23 florian
  183. * vmtpointer_offset must be adjusted in after_pass1 as well
  184. Revision 1.13 2003/05/09 19:00:30 jonas
  185. * call inherited after_header as well
  186. Revision 1.12 2003/04/27 11:21:36 peter
  187. * aktprocdef renamed to current_procinfo.procdef
  188. * procinfo renamed to current_procinfo
  189. * procinfo will now be stored in current_module so it can be
  190. cleaned up properly
  191. * gen_main_procsym changed to create_main_proc and release_main_proc
  192. to also generate a tprocinfo structure
  193. * fixed unit implicit initfinal
  194. Revision 1.11 2003/04/27 07:48:05 peter
  195. * updated for removed lexlevel
  196. Revision 1.10 2003/04/26 11:31:00 florian
  197. * fixed the powerpc to work with the new function result handling
  198. Revision 1.9 2003/04/24 11:24:00 florian
  199. * fixed several issues with nested procedures
  200. Revision 1.8 2003/04/06 16:39:11 jonas
  201. * don't generate entry/exit code for assembler procedures
  202. Revision 1.7 2003/04/05 21:09:32 jonas
  203. * several ppc/generic result offset related fixes. The "normal" result
  204. offset seems now to be calculated correctly and a lot of duplicate
  205. calculations have been removed. Nested functions accessing the parent's
  206. function result don't work at all though :(
  207. Revision 1.6 2002/12/15 19:22:01 florian
  208. * fixed some crashes and a rte 201
  209. Revision 1.5 2002/11/18 17:32:01 peter
  210. * pass proccalloption to ret_in_xxx and push_xxx functions
  211. Revision 1.4 2002/09/10 20:30:42 florian
  212. * fixed offset calculation for symtables etc.
  213. Revision 1.3 2002/09/07 17:54:59 florian
  214. * first part of PowerPC fixes
  215. Revision 1.2 2002/08/18 20:06:30 peter
  216. * inlining is now also allowed in interface
  217. * renamed write/load to ppuwrite/ppuload
  218. * tnode storing in ppu
  219. * nld,ncon,nbas are already updated for storing in ppu
  220. Revision 1.1 2002/08/17 09:23:49 florian
  221. * first part of procinfo rewrite
  222. }