cpupi.pas 6.9 KB

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