cpupi.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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,globtype,
  23. cgbase,
  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. constructor create(aparent:tprocinfo);override;
  30. procedure set_first_temp_offset;override;
  31. function calc_stackframe_size:longint;override;
  32. function uses_stack_temps: boolean;
  33. private
  34. first_save_int_reg, first_save_fpu_reg: tsuperregister;
  35. public
  36. property get_first_save_int_reg: tsuperregister read first_save_int_reg;
  37. property get_first_save_fpu_reg: tsuperregister read first_save_fpu_reg;
  38. needs_frame_pointer: boolean;
  39. end;
  40. implementation
  41. uses
  42. globals,systems,
  43. cpubase,
  44. aasmtai,aasmdata,
  45. tgobj,cgobj,
  46. symconst,symsym,paramgr,symutil,symtable,
  47. verbose;
  48. constructor tppcprocinfo.create(aparent:tprocinfo);
  49. begin
  50. inherited create(aparent);
  51. first_save_int_reg:=32;
  52. first_save_fpu_reg:=32;
  53. needs_frame_pointer:=false;
  54. end;
  55. procedure tppcprocinfo.set_first_temp_offset;
  56. var
  57. ofs : aword;
  58. begin
  59. if not(po_assembler in procdef.procoptions) then
  60. begin
  61. case target_info.abi of
  62. abi_powerpc_aix:
  63. ofs:=maxpushedparasize+LinkageAreaSizeAIX;
  64. abi_powerpc_sysv:
  65. ofs:=maxpushedparasize+LinkageAreaSizeSYSV;
  66. else
  67. internalerror(200402191);
  68. end;
  69. tg.setfirsttemp(ofs);
  70. end
  71. else
  72. begin
  73. if (current_procinfo.procdef.localst.symtabletype=localsymtable) and
  74. (tabstractlocalsymtable(current_procinfo.procdef.localst).count_locals <> 0) then
  75. begin
  76. { at 0(r1), the previous value of r1 will be stored }
  77. tg.setfirsttemp(4);
  78. end
  79. end;
  80. end;
  81. (*
  82. procedure tppcprocinfo.after_pass1;
  83. begin
  84. if not(po_assembler in procdef.procoptions) then
  85. begin
  86. if cs_asm_source in current_settings.globalswitches then
  87. aktproccode.insert(Tai_comment.Create(strpnew('Parameter copies start at: r1+'+tostr(procdef.parast.address_fixup))));
  88. if cs_asm_source in current_settings.globalswitches then
  89. aktproccode.insert(Tai_comment.Create(strpnew('Locals start at: r1+'+tostr(procdef.localst.address_fixup))));
  90. firsttemp_offset:=align(procdef.localst.address_fixup+procdef.localst.datasize,16);
  91. if cs_asm_source in current_settings.globalswitches then
  92. aktproccode.insert(Tai_comment.Create(strpnew('Temp. space start: r1+'+tostr(firsttemp_offset))));
  93. //!!!! tg.setfirsttemp(firsttemp_offset);
  94. tg.firsttemp:=firsttemp_offset;
  95. tg.lasttemp:=firsttemp_offset;
  96. inherited after_pass1;
  97. end;
  98. end;
  99. *)
  100. function tppcprocinfo.uses_stack_temps: boolean;
  101. begin
  102. result := tg.firsttemp <> tg.lasttemp;
  103. end;
  104. function tppcprocinfo.calc_stackframe_size:longint;
  105. var
  106. low_nonvol_fpu_reg, regcounter: tsuperregister;
  107. begin
  108. if not (po_assembler in procdef.procoptions) then
  109. begin
  110. first_save_fpu_reg := 32;
  111. first_save_int_reg := 32;
  112. { FIXME: has to be R_F14 instead of R_F8 for SYSV-64bit }
  113. case target_info.abi of
  114. abi_powerpc_aix:
  115. low_nonvol_fpu_reg := RS_F14;
  116. abi_powerpc_sysv:
  117. low_nonvol_fpu_reg := RS_F14;
  118. else
  119. internalerror(2003122903);
  120. end;
  121. for regcounter := low_nonvol_fpu_reg to RS_F31 do
  122. begin
  123. if regcounter in cg.rg[R_FPUREGISTER].used_in_proc then
  124. begin
  125. first_save_fpu_reg := ord(regcounter) - ord(RS_F0);
  126. break;
  127. end;
  128. end;
  129. for regcounter := RS_R13 to RS_R31 do
  130. begin
  131. if regcounter in cg.rg[R_INTREGISTER].used_in_proc then
  132. begin
  133. first_save_int_reg := ord(regcounter) - ord(RS_R0);
  134. break;
  135. end;
  136. end;
  137. if not(pi_do_call in flags) and
  138. (not uses_stack_temps) and
  139. (((target_info.abi = abi_powerpc_aix) and
  140. ((32-first_save_int_reg)*4+(32-first_save_fpu_reg)*8 <= 220)) or
  141. ((target_info.abi = abi_powerpc_sysv) and
  142. (first_save_int_reg + first_save_fpu_reg = 64))) then
  143. { don't allocate a stack frame }
  144. result := (32-first_save_int_reg)*4+(32-first_save_fpu_reg)*8
  145. else
  146. result := (32-first_save_int_reg)*4+(32-first_save_fpu_reg)*8+tg.lasttemp;
  147. result := align(result,16);
  148. end
  149. else
  150. begin
  151. result := align(tg.lasttemp,16);
  152. needstackframe:=result<>0;
  153. end;
  154. end;
  155. begin
  156. cprocinfo:=tppcprocinfo;
  157. end.