cpupi.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 tabstractlocalsymtable(current_procinfo.procdef.localst).count_locals <> 0 then
  74. begin
  75. { at 0(r1), the previous value of r1 will be stored }
  76. tg.setfirsttemp(4);
  77. end
  78. end;
  79. end;
  80. (*
  81. procedure tppcprocinfo.after_pass1;
  82. begin
  83. if not(po_assembler in procdef.procoptions) then
  84. begin
  85. if cs_asm_source in current_settings.globalswitches then
  86. aktproccode.insert(Tai_comment.Create(strpnew('Parameter copies start at: r1+'+tostr(procdef.parast.address_fixup))));
  87. if cs_asm_source in current_settings.globalswitches then
  88. aktproccode.insert(Tai_comment.Create(strpnew('Locals start at: r1+'+tostr(procdef.localst.address_fixup))));
  89. firsttemp_offset:=align(procdef.localst.address_fixup+procdef.localst.datasize,16);
  90. if cs_asm_source in current_settings.globalswitches then
  91. aktproccode.insert(Tai_comment.Create(strpnew('Temp. space start: r1+'+tostr(firsttemp_offset))));
  92. //!!!! tg.setfirsttemp(firsttemp_offset);
  93. tg.firsttemp:=firsttemp_offset;
  94. tg.lasttemp:=firsttemp_offset;
  95. inherited after_pass1;
  96. end;
  97. end;
  98. *)
  99. function tppcprocinfo.uses_stack_temps: boolean;
  100. begin
  101. result := tg.firsttemp <> tg.lasttemp;
  102. end;
  103. function tppcprocinfo.calc_stackframe_size:longint;
  104. var
  105. low_nonvol_fpu_reg, regcounter: tsuperregister;
  106. begin
  107. if not (po_assembler in procdef.procoptions) then
  108. begin
  109. first_save_fpu_reg := 32;
  110. first_save_int_reg := 32;
  111. { FIXME: has to be R_F14 instead of R_F8 for SYSV-64bit }
  112. case target_info.abi of
  113. abi_powerpc_aix:
  114. low_nonvol_fpu_reg := RS_F14;
  115. abi_powerpc_sysv:
  116. low_nonvol_fpu_reg := RS_F14;
  117. else
  118. internalerror(2003122903);
  119. end;
  120. for regcounter := low_nonvol_fpu_reg to RS_F31 do
  121. begin
  122. if regcounter in cg.rg[R_FPUREGISTER].used_in_proc then
  123. begin
  124. first_save_fpu_reg := ord(regcounter) - ord(RS_F0);
  125. break;
  126. end;
  127. end;
  128. for regcounter := RS_R13 to RS_R31 do
  129. begin
  130. if regcounter in cg.rg[R_INTREGISTER].used_in_proc then
  131. begin
  132. first_save_int_reg := ord(regcounter) - ord(RS_R0);
  133. break;
  134. end;
  135. end;
  136. if not(pi_do_call in flags) and
  137. (not uses_stack_temps) and
  138. (((target_info.abi = abi_powerpc_aix) and
  139. ((32-first_save_int_reg)*4+(32-first_save_fpu_reg)*8 <= 220)) or
  140. ((target_info.abi = abi_powerpc_sysv) and
  141. (first_save_int_reg + first_save_fpu_reg = 64))) then
  142. { don't allocate a stack frame }
  143. result := (32-first_save_int_reg)*4+(32-first_save_fpu_reg)*8
  144. else
  145. result := (32-first_save_int_reg)*4+(32-first_save_fpu_reg)*8+tg.lasttemp;
  146. result := align(result,16);
  147. end
  148. else
  149. result := align(tg.lasttemp,16);
  150. end;
  151. begin
  152. cprocinfo:=tppcprocinfo;
  153. end.