cpupi.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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,aasmdata,
  23. procinfo, cpuinfo, psub;
  24. type
  25. tcpuprocinfo = class(tcgprocinfo)
  26. needstackframe: boolean;
  27. { offset where the frame pointer from the outer procedure is stored. }
  28. parent_framepointer_offset: longint;
  29. needs_frame_pointer : boolean;
  30. constructor create(aparent: tprocinfo); override;
  31. procedure set_first_temp_offset; override;
  32. function calc_stackframe_size: longint; override;
  33. function calc_stackframe_size(numgpr, numfpr : longint): longint;
  34. procedure allocate_got_register(list: TAsmList); override;
  35. procedure postprocess_code;override;
  36. end;
  37. implementation
  38. uses
  39. globtype, globals, systems,
  40. cpubase, cgbase,
  41. aasmtai,
  42. tgobj,cgobj,
  43. symconst, symsym, paramgr, symutil, symtable,
  44. verbose,
  45. aasmcpu;
  46. constructor tcpuprocinfo.create(aparent: tprocinfo);
  47. begin
  48. inherited create(aparent);
  49. maxpushedparasize := 0;
  50. needs_frame_pointer := false;
  51. end;
  52. procedure tcpuprocinfo.set_first_temp_offset;
  53. var
  54. ofs,
  55. lasize,
  56. minstacksize: aword;
  57. begin
  58. if target_info.abi<>abi_powerpc_elfv2 then
  59. lasize:=LinkageAreaSizeELF
  60. else
  61. lasize:=LinkageAreaSizeELFv2;
  62. if not (po_assembler in procdef.procoptions) then begin
  63. { align the stack properly }
  64. if target_info.abi<>abi_powerpc_elfv2 then
  65. begin
  66. { same for AIX/Darwin }
  67. minstacksize:=MINIMUM_STACKFRAME_SIZE;
  68. end
  69. else
  70. begin
  71. minstacksize:=MINIMUM_STACKFRAME_SIZE_ELFV2;
  72. end;
  73. ofs := align(maxpushedparasize + lasize, ELF_STACK_ALIGN);
  74. { the ABI specification says that it is required to always allocate space for 8 * 8 bytes
  75. for registers R3-R10 and stack header if there's a stack frame, but GCC doesn't do that,
  76. so we don't that too. Uncomment the next three lines if this is required }
  77. if (cs_profile in init_settings.moduleswitches) and (ofs < minstacksize) then begin
  78. ofs := minstacksize;
  79. end;
  80. tg.setfirsttemp(ofs);
  81. end else begin
  82. if (current_procinfo.procdef.localst.symtabletype=localsymtable) and
  83. (tabstractlocalsymtable(current_procinfo.procdef.localst).count_locals <> 0) then
  84. { at 0(r1), the previous value of r1 will be stored; also make sure
  85. there's room to store lr etc by potential callees}
  86. tg.setfirsttemp(lasize);
  87. end;
  88. end;
  89. function tcpuprocinfo.calc_stackframe_size: longint;
  90. begin
  91. result := calc_stackframe_size(18, 18);
  92. end;
  93. function tcpuprocinfo.calc_stackframe_size(numgpr, numfpr : longint) : longint;
  94. begin
  95. { more or less copied from cgcpu.pas/g_stackframe_entry }
  96. if not (po_assembler in procdef.procoptions) then begin
  97. // no VMX support
  98. result := align(numgpr * sizeof(pint) +
  99. numfpr * tcgsize2size[OS_FLOAT], ELF_STACK_ALIGN);
  100. if (pi_do_call in flags) or (tg.lasttemp <> tg.firsttemp) or
  101. (result > RED_ZONE_SIZE) {or (cs_profile in init_settings.moduleswitches)} then begin
  102. result := align(result + tg.lasttemp, ELF_STACK_ALIGN);
  103. needstackframe:=true;
  104. end else
  105. needstackframe:=false;
  106. end else begin
  107. result := align(tg.lasttemp, ELF_STACK_ALIGN);
  108. needstackframe:=result<>0;
  109. end;
  110. end;
  111. procedure tcpuprocinfo.allocate_got_register(list: TAsmList);
  112. begin
  113. if (target_info.system = system_powerpc64_darwin) and
  114. (cs_create_pic in current_settings.moduleswitches) then
  115. begin
  116. got := cg.getaddressregister(list);
  117. end;
  118. end;
  119. procedure tcpuprocinfo.postprocess_code;
  120. begin
  121. fixup_jmps(aktproccode);
  122. end;
  123. begin
  124. cprocinfo := tcpuprocinfo;
  125. end.