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