cpupi.pas 6.3 KB

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