cpupi.pas 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. tcpuprocinfo = 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 tcpuprocinfo.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 tcpuprocinfo.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. abi_powerpc_darwin:
  68. ofs:=maxpushedparasize+LinkageAreaSizeAIX;
  69. abi_powerpc_sysv:
  70. ofs:=maxpushedparasize+LinkageAreaSizeSYSV;
  71. else
  72. internalerror(200402191);
  73. end;
  74. tg.setfirsttemp(ofs);
  75. end
  76. else
  77. begin
  78. if (current_procinfo.procdef.localst.symtabletype=localsymtable) and
  79. (tabstractlocalsymtable(current_procinfo.procdef.localst).count_locals <> 0) then
  80. begin
  81. { at 0(r1), the previous value of r1 will be stored }
  82. tg.setfirsttemp(4);
  83. end
  84. end;
  85. end;
  86. (*
  87. procedure tcpuprocinfo.after_pass1;
  88. begin
  89. if not(po_assembler in procdef.procoptions) then
  90. begin
  91. if cs_asm_source in current_settings.globalswitches then
  92. aktproccode.insert(Tai_comment.Create(strpnew('Parameter copies start at: r1+'+tostr(procdef.parast.address_fixup))));
  93. if cs_asm_source in current_settings.globalswitches then
  94. aktproccode.insert(Tai_comment.Create(strpnew('Locals start at: r1+'+tostr(procdef.localst.address_fixup))));
  95. firsttemp_offset:=align(procdef.localst.address_fixup+procdef.localst.datasize,16);
  96. if cs_asm_source in current_settings.globalswitches then
  97. aktproccode.insert(Tai_comment.Create(strpnew('Temp. space start: r1+'+tostr(firsttemp_offset))));
  98. //!!!! tg.setfirsttemp(firsttemp_offset);
  99. tg.firsttemp:=firsttemp_offset;
  100. tg.lasttemp:=firsttemp_offset;
  101. inherited after_pass1;
  102. end;
  103. end;
  104. *)
  105. function tcpuprocinfo.uses_stack_temps: boolean;
  106. begin
  107. result := tg.firsttemp <> tg.lasttemp;
  108. end;
  109. function tcpuprocinfo.calc_stackframe_size:longint;
  110. var
  111. low_nonvol_fpu_reg, regcounter: tsuperregister;
  112. begin
  113. if not (po_assembler in procdef.procoptions) then
  114. begin
  115. first_save_fpu_reg := 32;
  116. first_save_int_reg := 32;
  117. { FIXME: has to be R_F14 instead of R_F8 for SYSV-64bit }
  118. case target_info.abi of
  119. abi_powerpc_aix,
  120. abi_powerpc_darwin:
  121. low_nonvol_fpu_reg := RS_F14;
  122. abi_powerpc_sysv:
  123. low_nonvol_fpu_reg := RS_F14;
  124. else
  125. internalerror(2003122903);
  126. end;
  127. for regcounter := low_nonvol_fpu_reg to RS_F31 do
  128. begin
  129. if regcounter in cg.rg[R_FPUREGISTER].used_in_proc then
  130. begin
  131. first_save_fpu_reg := ord(regcounter) - ord(RS_F0);
  132. break;
  133. end;
  134. end;
  135. for regcounter := RS_R13 to RS_R31 do
  136. begin
  137. if regcounter in cg.rg[R_INTREGISTER].used_in_proc then
  138. begin
  139. first_save_int_reg := ord(regcounter) - ord(RS_R0);
  140. break;
  141. end;
  142. end;
  143. if not(pi_do_call in flags) and
  144. (not uses_stack_temps) and
  145. (((target_info.abi in [abi_powerpc_aix,abi_powerpc_darwin]) and
  146. ((32-first_save_int_reg)*4+(32-first_save_fpu_reg)*8 <= 220)) or
  147. ((target_info.abi = abi_powerpc_sysv) and
  148. (first_save_int_reg + first_save_fpu_reg = 64))) then
  149. begin
  150. { don't allocate a stack frame }
  151. result := (32-first_save_int_reg)*4+(32-first_save_fpu_reg)*8;
  152. needstackframe := false;
  153. end
  154. else
  155. begin
  156. result := (32-first_save_int_reg)*4+(32-first_save_fpu_reg)*8+tg.lasttemp;
  157. result := align(result,16);
  158. needstackframe := result<>0;
  159. end;
  160. end
  161. else
  162. begin
  163. result := align(tg.lasttemp,16);
  164. needstackframe := result<>0;
  165. end;
  166. end;
  167. procedure tcpuprocinfo.allocate_got_register(list: TAsmList);
  168. begin
  169. if (target_info.system = system_powerpc_darwin) and
  170. (cs_create_pic in current_settings.moduleswitches) then
  171. begin
  172. got := cg.getaddressregister(list);
  173. end;
  174. end;
  175. procedure tcpuprocinfo.postprocess_code;
  176. begin
  177. fixup_jmps(aktproccode);
  178. end;
  179. begin
  180. cprocinfo:=tcpuprocinfo;
  181. end.