cpupi.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. This unit contains the CPU specific part of tprocinfo
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. { This unit contains the CPU specific part of tprocinfo. }
  18. unit cpupi;
  19. {$I fpcdefs.inc}
  20. interface
  21. uses
  22. cutils,
  23. procinfo, cpuinfo, psub;
  24. type
  25. tppcprocinfo = class(tcgprocinfo)
  26. { offset where the frame pointer from the outer procedure is stored. }
  27. parent_framepointer_offset: longint;
  28. constructor create(aparent: tprocinfo); override;
  29. procedure set_first_temp_offset; override;
  30. procedure allocate_push_parasize(size: longint); override;
  31. function calc_stackframe_size: longint; override;
  32. function calc_stackframe_size(numgpr, numfpr : longint): longint;
  33. end;
  34. implementation
  35. uses
  36. globtype, globals, systems,
  37. cpubase, cgbase,
  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 begin
  53. { align the stack properly }
  54. ofs := align(maxpushedparasize + LinkageAreaSizeELF, 8);
  55. { the ABI specification says that it is required to always allocate space for 8 * 8 bytes
  56. for registers R3-R10 and stack header if there's a stack frame, but GCC doesn't do that,
  57. so we don't that too. Uncomment the next three lines if this is required }
  58. // if (ofs < 112) then begin
  59. // ofs := 112;
  60. // end;
  61. tg.setfirsttemp(ofs);
  62. end else begin
  63. locals := 0;
  64. current_procinfo.procdef.localst.foreach_static(@count_locals, @locals);
  65. if locals <> 0 then
  66. { at 0(r1), the previous value of r1 will be stored }
  67. tg.setfirsttemp(8);
  68. end;
  69. end;
  70. procedure tppcprocinfo.allocate_push_parasize(size: longint);
  71. begin
  72. if size > maxpushedparasize then
  73. maxpushedparasize := size;
  74. end;
  75. function tppcprocinfo.calc_stackframe_size: longint;
  76. begin
  77. result := calc_stackframe_size(18, 18);
  78. end;
  79. function tppcprocinfo.calc_stackframe_size(numgpr, numfpr : longint) : longint;
  80. begin
  81. { more or less copied from cgcpu.pas/g_stackframe_entry }
  82. if not (po_assembler in procdef.procoptions) then begin
  83. // no VMX support
  84. result := align(align(numgpr * tcgsize2size[OS_INT] +
  85. numfpr * tcgsize2size[OS_FLOAT], ELF_STACK_ALIGN) + tg.lasttemp, ELF_STACK_ALIGN);
  86. end else
  87. result := align(tg.lasttemp, ELF_STACK_ALIGN);
  88. end;
  89. begin
  90. cprocinfo := tppcprocinfo;
  91. end.