cpupi.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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;
  25. type
  26. tppcprocinfo = class(tprocinfo)
  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_header;override;
  33. procedure after_pass1;override;
  34. end;
  35. implementation
  36. uses
  37. globtype,globals,
  38. cpubase,
  39. aasmtai,
  40. tgobj,
  41. symconst, symsym,paramgr;
  42. constructor tppcprocinfo.create(aparent:tprocinfo);
  43. begin
  44. inherited create(aparent);
  45. maxpushedparasize:=0;
  46. localsize:=0;
  47. end;
  48. procedure tppcprocinfo.after_header;
  49. begin
  50. { this value is necessary for nested procedures }
  51. procdef.parast.address_fixup:=0;
  52. inherited after_header;
  53. if assigned(procdef.localst) then
  54. procdef.localst.address_fixup:=0;
  55. procdef.parast.address_fixup:= -procdef.parast.datasize;
  56. end;
  57. procedure tppcprocinfo.after_pass1;
  58. var
  59. ofs : aword;
  60. begin
  61. if not(po_assembler in procdef.procoptions) then
  62. begin
  63. procdef.parast.address_fixup := 0;
  64. allocate_implicit_parameter;
  65. procdef.localst.address_fixup := procdef.parast.address_fixup + procdef.parast.datasize;
  66. ofs:=align(maxpushedparasize+LinkageAreaSize,16);
  67. inc(procdef.parast.address_fixup,ofs);
  68. inc(framepointer_offset,ofs);
  69. // inc(selfpointer_offset,ofs);
  70. // inc(vmtpointer_offset,ofs);
  71. if cs_asm_source in aktglobalswitches then
  72. aktproccode.insert(Tai_comment.Create(strpnew('Parameter copies start at: r1+'+tostr(procdef.parast.address_fixup))));
  73. // Already done with an "inc" above now, not sure if it's correct (JM)
  74. procdef.localst.address_fixup:=procdef.parast.address_fixup+procdef.parast.datasize;
  75. if assigned(procdef.funcretsym) then
  76. return_offset:=tvarsym(procdef.funcretsym).address+tvarsym(procdef.funcretsym).owner.address_fixup;
  77. {
  78. Already done with an "inc" above, should be correct (JM)
  79. if assigned(procdef.funcretsym) and
  80. not(paramanager.ret_in_param(procdef.rettype.def,procdef.proccalloption)) then
  81. return_offset:=tg.direction*tfuncretsym(procdef.funcretsym).address+procdef.localst.address_fixup;
  82. }
  83. if cs_asm_source in aktglobalswitches then
  84. aktproccode.insert(Tai_comment.Create(strpnew('Locals start at: r1+'+tostr(procdef.localst.address_fixup))));
  85. firsttemp_offset:=align(procdef.localst.address_fixup+procdef.localst.datasize,16);
  86. if cs_asm_source in aktglobalswitches then
  87. aktproccode.insert(Tai_comment.Create(strpnew('Temp. space start: r1+'+tostr(firsttemp_offset))));
  88. //!!!! tg.setfirsttemp(firsttemp_offset);
  89. tg.firsttemp:=firsttemp_offset;
  90. tg.lasttemp:=firsttemp_offset;
  91. inherited after_pass1;
  92. end;
  93. end;
  94. begin
  95. cprocinfo:=tppcprocinfo;
  96. end.
  97. {
  98. $Log$
  99. Revision 1.18 2003-05-17 14:05:30 jonas
  100. * fixed para/localst calculations (note to self: don't commit at
  101. extremely late/early hours :)
  102. Revision 1.17 2003/05/16 23:15:51 jonas
  103. * workaround for nested procedures until Peter fixes it properly :)
  104. Revision 1.16 2003/05/16 20:00:39 jonas
  105. * powerpc nested procedure fixes, should work completely now if all
  106. local variables of the parent procedure are declared before the
  107. nested procedures are declared
  108. Revision 1.15 2003/05/15 19:39:09 florian
  109. * fixed ppc compiler which was broken by Peter's changes
  110. Revision 1.14 2003/05/10 23:57:23 florian
  111. * vmtpointer_offset must be adjusted in after_pass1 as well
  112. Revision 1.13 2003/05/09 19:00:30 jonas
  113. * call inherited after_header as well
  114. Revision 1.12 2003/04/27 11:21:36 peter
  115. * aktprocdef renamed to current_procdef
  116. * procinfo renamed to current_procinfo
  117. * procinfo will now be stored in current_module so it can be
  118. cleaned up properly
  119. * gen_main_procsym changed to create_main_proc and release_main_proc
  120. to also generate a tprocinfo structure
  121. * fixed unit implicit initfinal
  122. Revision 1.11 2003/04/27 07:48:05 peter
  123. * updated for removed lexlevel
  124. Revision 1.10 2003/04/26 11:31:00 florian
  125. * fixed the powerpc to work with the new function result handling
  126. Revision 1.9 2003/04/24 11:24:00 florian
  127. * fixed several issues with nested procedures
  128. Revision 1.8 2003/04/06 16:39:11 jonas
  129. * don't generate entry/exit code for assembler procedures
  130. Revision 1.7 2003/04/05 21:09:32 jonas
  131. * several ppc/generic result offset related fixes. The "normal" result
  132. offset seems now to be calculated correctly and a lot of duplicate
  133. calculations have been removed. Nested functions accessing the parent's
  134. function result don't work at all though :(
  135. Revision 1.6 2002/12/15 19:22:01 florian
  136. * fixed some crashes and a rte 201
  137. Revision 1.5 2002/11/18 17:32:01 peter
  138. * pass proccalloption to ret_in_xxx and push_xxx functions
  139. Revision 1.4 2002/09/10 20:30:42 florian
  140. * fixed offset calculation for symtables etc.
  141. Revision 1.3 2002/09/07 17:54:59 florian
  142. * first part of PowerPC fixes
  143. Revision 1.2 2002/08/18 20:06:30 peter
  144. * inlining is now also allowed in interface
  145. * renamed write/load to ppuwrite/ppuload
  146. * tnode storing in ppu
  147. * nld,ncon,nbas are already updated for storing in ppu
  148. Revision 1.1 2002/08/17 09:23:49 florian
  149. * first part of procinfo rewrite
  150. }