cpupi.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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;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;
  43. begin
  44. inherited create;
  45. maxpushedparasize:=0;
  46. localsize:=0;
  47. end;
  48. procedure tppcprocinfo.after_header;
  49. begin
  50. procdef.parast.address_fixup:=0;
  51. if assigned(procdef.localst) and (procdef.localst.symtablelevel>1) then
  52. begin
  53. procinfo.framepointer_offset:=procdef.parast.address_fixup;
  54. inc(procdef.parast.address_fixup,4);
  55. end;
  56. if paramanager.ret_in_param(procdef.rettype.def,procdef.proccalloption) then
  57. begin
  58. procinfo.return_offset:=procdef.parast.address_fixup;
  59. inc(procdef.parast.address_fixup,4);
  60. end;
  61. if assigned(_class) then
  62. begin
  63. procinfo.selfpointer_offset:=procdef.parast.address_fixup;
  64. inc(procdef.parast.address_fixup,4);
  65. end;
  66. { this value is necessary for nested procedures }
  67. if assigned(procdef.localst) then
  68. procdef.localst.address_fixup:=align(procdef.parast.address_fixup+procdef.parast.datasize,16);
  69. {
  70. procdef.funcretsym isn't set here yet and besides,
  71. symtable.insertvardata() already sets procinfo.return_offset! (JM)
  72. if assigned(procdef.funcretsym) and
  73. not(paramanager.ret_in_param(procdef.rettype.def,procdef.proccalloption)) then
  74. procinfo.return_offset:=tg.direction*tfuncretsym(procdef.funcretsym).address+procdef.localst.address_fixup;
  75. }
  76. end;
  77. procedure tppcprocinfo.after_pass1;
  78. var
  79. ofs : aword;
  80. begin
  81. if not(po_assembler in procdef.procoptions) then
  82. begin
  83. ofs:=align(maxpushedparasize+LinkageAreaSize,16);
  84. inc(procdef.parast.address_fixup,ofs);
  85. inc(procinfo.return_offset,ofs);
  86. inc(procinfo.framepointer_offset,ofs);
  87. inc(procinfo.selfpointer_offset,ofs);
  88. if cs_asm_source in aktglobalswitches then
  89. aktproccode.insert(Tai_comment.Create(strpnew('Parameter copies start at: r1+'+tostr(procdef.parast.address_fixup))));
  90. // Already done with an "inc" above now, not sure if it's correct (JM)
  91. procdef.localst.address_fixup:=procdef.parast.address_fixup+procdef.parast.datasize;
  92. {
  93. Already done with an "inc" above, should be correct (JM)
  94. if assigned(procdef.funcretsym) and
  95. not(paramanager.ret_in_param(procdef.rettype.def,procdef.proccalloption)) then
  96. procinfo.return_offset:=tg.direction*tfuncretsym(procdef.funcretsym).address+procdef.localst.address_fixup;
  97. }
  98. if cs_asm_source in aktglobalswitches then
  99. aktproccode.insert(Tai_comment.Create(strpnew('Locals start at: r1+'+tostr(procdef.localst.address_fixup))));
  100. procinfo.firsttemp_offset:=align(procdef.localst.address_fixup+procdef.localst.datasize,16);
  101. if cs_asm_source in aktglobalswitches then
  102. aktproccode.insert(Tai_comment.Create(strpnew('Temp. space start: r1+'+tostr(procinfo.firsttemp_offset))));
  103. //!!!! tg.setfirsttemp(procinfo.firsttemp_offset);
  104. tg.firsttemp:=procinfo.firsttemp_offset;
  105. tg.lasttemp:=procinfo.firsttemp_offset;
  106. end;
  107. end;
  108. begin
  109. cprocinfo:=tppcprocinfo;
  110. end.
  111. {
  112. $Log$
  113. Revision 1.8 2003-04-06 16:39:11 jonas
  114. * don't generate entry/exit code for assembler procedures
  115. Revision 1.7 2003/04/05 21:09:32 jonas
  116. * several ppc/generic result offset related fixes. The "normal" result
  117. offset seems now to be calculated correctly and a lot of duplicate
  118. calculations have been removed. Nested functions accessing the parent's
  119. function result don't work at all though :(
  120. Revision 1.6 2002/12/15 19:22:01 florian
  121. * fixed some crashes and a rte 201
  122. Revision 1.5 2002/11/18 17:32:01 peter
  123. * pass proccalloption to ret_in_xxx and push_xxx functions
  124. Revision 1.4 2002/09/10 20:30:42 florian
  125. * fixed offset calculation for symtables etc.
  126. Revision 1.3 2002/09/07 17:54:59 florian
  127. * first part of PowerPC fixes
  128. Revision 1.2 2002/08/18 20:06:30 peter
  129. * inlining is now also allowed in interface
  130. * renamed write/load to ppuwrite/ppuload
  131. * tnode storing in ppu
  132. * nld,ncon,nbas are already updated for storing in ppu
  133. Revision 1.1 2002/08/17 09:23:49 florian
  134. * first part of procinfo rewrite
  135. }