cpupi.pas 8.9 KB

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