2
0

cpupi.pas 6.7 KB

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