cpupi.pas 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. cgbase,cpuinfo,psub;
  25. type
  26. tppcprocinfo = class(tcgprocinfo)
  27. { overall size of allocated stack space, currently this is used for the PowerPC only }
  28. localsize : aword;
  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 after_pass1;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;
  43. constructor tppcprocinfo.create(aparent:tprocinfo);
  44. begin
  45. inherited create(aparent);
  46. maxpushedparasize:=0;
  47. localsize:=0;
  48. end;
  49. procedure tppcprocinfo.after_pass1;
  50. var
  51. ofs : aword;
  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. inc(procdef.parast.address_fixup,ofs);
  62. // inc(selfpointer_offset,ofs);
  63. // inc(vmtpointer_offset,ofs);
  64. if cs_asm_source in aktglobalswitches then
  65. aktproccode.insert(Tai_comment.Create(strpnew('Parameter copies start at: r1+'+tostr(procdef.parast.address_fixup))));
  66. procdef.localst.address_fixup:=procdef.parast.address_fixup+procdef.parast.datasize;
  67. if cs_asm_source in aktglobalswitches then
  68. aktproccode.insert(Tai_comment.Create(strpnew('Locals start at: r1+'+tostr(procdef.localst.address_fixup))));
  69. firsttemp_offset:=align(procdef.localst.address_fixup+procdef.localst.datasize,16);
  70. if cs_asm_source in aktglobalswitches then
  71. aktproccode.insert(Tai_comment.Create(strpnew('Temp. space start: r1+'+tostr(firsttemp_offset))));
  72. //!!!! tg.setfirsttemp(firsttemp_offset);
  73. tg.firsttemp:=firsttemp_offset;
  74. tg.lasttemp:=firsttemp_offset;
  75. inherited after_pass1;
  76. end;
  77. end;
  78. procedure tppcprocinfo.allocate_push_parasize(size:longint);
  79. begin
  80. if size>maxpushedparasize then
  81. maxpushedparasize:=size;
  82. end;
  83. function tppcprocinfo.calc_stackframe_size:longint;
  84. var
  85. savearea : longint;
  86. begin
  87. { more or less copied from cgcpu.pas/g_stackframe_entry }
  88. result := align(align((31-13+1)*4+(31-14+1)*8,16)+tg.lasttemp,16);
  89. end;
  90. begin
  91. cprocinfo:=tppcprocinfo;
  92. end.
  93. {
  94. $Log$
  95. Revision 1.25 2003-08-08 15:52:50 olle
  96. * merged macos entry/exit code generation into the general one.
  97. Revision 1.24 2003/07/06 20:25:03 jonas
  98. * fixed ppc compiler
  99. Revision 1.23 2003/06/13 21:19:32 peter
  100. * current_procdef removed, use current_procinfo.procdef instead
  101. Revision 1.22 2003/06/02 21:42:05 jonas
  102. * function results can now also be regvars
  103. - removed tprocinfo.return_offset, never use it again since it's invalid
  104. if the result is a regvar
  105. Revision 1.21 2003/05/24 11:47:27 jonas
  106. * fixed framepointer storage: it's now always stored at r1+12, which is
  107. a place in the link area reserved for compiler use.
  108. Revision 1.20 2003/05/23 18:51:26 jonas
  109. * fixed support for nested procedures and more parameters than those
  110. which fit in registers (untested/probably not working: calling a
  111. nested procedure from a deeper nested procedure)
  112. Revision 1.19 2003/05/22 21:34:11 peter
  113. * inherite from tcgprocinfo
  114. Revision 1.18 2003/05/17 14:05:30 jonas
  115. * fixed para/localst calculations (note to self: don't commit at
  116. extremely late/early hours :)
  117. Revision 1.17 2003/05/16 23:15:51 jonas
  118. * workaround for nested procedures until Peter fixes it properly :)
  119. Revision 1.16 2003/05/16 20:00:39 jonas
  120. * powerpc nested procedure fixes, should work completely now if all
  121. local variables of the parent procedure are declared before the
  122. nested procedures are declared
  123. Revision 1.15 2003/05/15 19:39:09 florian
  124. * fixed ppc compiler which was broken by Peter's changes
  125. Revision 1.14 2003/05/10 23:57:23 florian
  126. * vmtpointer_offset must be adjusted in after_pass1 as well
  127. Revision 1.13 2003/05/09 19:00:30 jonas
  128. * call inherited after_header as well
  129. Revision 1.12 2003/04/27 11:21:36 peter
  130. * aktprocdef renamed to current_procinfo.procdef
  131. * procinfo renamed to current_procinfo
  132. * procinfo will now be stored in current_module so it can be
  133. cleaned up properly
  134. * gen_main_procsym changed to create_main_proc and release_main_proc
  135. to also generate a tprocinfo structure
  136. * fixed unit implicit initfinal
  137. Revision 1.11 2003/04/27 07:48:05 peter
  138. * updated for removed lexlevel
  139. Revision 1.10 2003/04/26 11:31:00 florian
  140. * fixed the powerpc to work with the new function result handling
  141. Revision 1.9 2003/04/24 11:24:00 florian
  142. * fixed several issues with nested procedures
  143. Revision 1.8 2003/04/06 16:39:11 jonas
  144. * don't generate entry/exit code for assembler procedures
  145. Revision 1.7 2003/04/05 21:09:32 jonas
  146. * several ppc/generic result offset related fixes. The "normal" result
  147. offset seems now to be calculated correctly and a lot of duplicate
  148. calculations have been removed. Nested functions accessing the parent's
  149. function result don't work at all though :(
  150. Revision 1.6 2002/12/15 19:22:01 florian
  151. * fixed some crashes and a rte 201
  152. Revision 1.5 2002/11/18 17:32:01 peter
  153. * pass proccalloption to ret_in_xxx and push_xxx functions
  154. Revision 1.4 2002/09/10 20:30:42 florian
  155. * fixed offset calculation for symtables etc.
  156. Revision 1.3 2002/09/07 17:54:59 florian
  157. * first part of PowerPC fixes
  158. Revision 1.2 2002/08/18 20:06:30 peter
  159. * inlining is now also allowed in interface
  160. * renamed write/load to ppuwrite/ppuload
  161. * tnode storing in ppu
  162. * nld,ncon,nbas are already updated for storing in ppu
  163. Revision 1.1 2002/08/17 09:23:49 florian
  164. * first part of procinfo rewrite
  165. }