cpupi.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. cpubase,
  24. cgbase,aasmdata,
  25. procinfo,cpuinfo,psub;
  26. type
  27. txtensaprocinfo = class(tcgprocinfo)
  28. callins,callxins : TAsmOp;
  29. stackframesize,
  30. stackpaddingreg: TSuperRegister;
  31. needs_frame_pointer: boolean;
  32. { highest N used in a call instruction }
  33. maxcall : Byte;
  34. // procedure handle_body_start;override;
  35. // procedure after_pass1;override;
  36. constructor create(aparent: tprocinfo); override;
  37. procedure set_first_temp_offset;override;
  38. function calc_stackframe_size:longint;override;
  39. procedure init_framepointer;override;
  40. end;
  41. implementation
  42. uses
  43. globals,systems,
  44. tgobj,
  45. symconst,symtype,symsym,symcpu,paramgr,
  46. cgutils,
  47. cgobj,
  48. defutil,
  49. aasmcpu;
  50. constructor txtensaprocinfo.create(aparent: tprocinfo);
  51. begin
  52. inherited create(aparent);
  53. maxpushedparasize := 0;
  54. if target_info.abi=abi_xtensa_windowed then
  55. begin
  56. callins:=A_CALL8;
  57. callxins:=A_CALLX8;
  58. { set properly }
  59. maxcall:=8;
  60. { we do not use a frame pointer for the windowed abi }
  61. include(flags,pi_estimatestacksize);
  62. framepointer:=NR_STACK_POINTER_REG;
  63. end
  64. else
  65. begin
  66. callins:=A_CALL0;
  67. callxins:=A_CALLX0;
  68. maxcall:=0;
  69. framepointer:=NR_FRAME_POINTER_REG;
  70. end;
  71. end;
  72. procedure txtensaprocinfo.set_first_temp_offset;
  73. var
  74. localsize : aint;
  75. i : longint;
  76. begin
  77. if (po_nostackframe in procdef.procoptions) then
  78. begin
  79. { maxpushedparasize sghould be zero,
  80. if not we will get an error later. }
  81. tg.setfirsttemp(maxpushedparasize);
  82. exit;
  83. end;
  84. if tg.direction = -1 then
  85. tg.setfirsttemp(-(1+12)*4)
  86. else
  87. tg.setfirsttemp(maxpushedparasize);
  88. { estimate stack frame size }
  89. if pi_estimatestacksize in flags then
  90. begin
  91. stackframesize:=maxpushedparasize+32;
  92. localsize:=0;
  93. for i:=0 to procdef.localst.SymList.Count-1 do
  94. if tsym(procdef.localst.SymList[i]).typ=localvarsym then
  95. inc(localsize,tabstractnormalvarsym(procdef.localst.SymList[i]).getsize);
  96. inc(stackframesize,localsize);
  97. localsize:=0;
  98. for i:=0 to procdef.parast.SymList.Count-1 do
  99. if tsym(procdef.parast.SymList[i]).typ=paravarsym then
  100. begin
  101. if tabstractnormalvarsym(procdef.parast.SymList[i]).varspez in [vs_var,vs_out,vs_constref] then
  102. inc(localsize,4)
  103. else if is_open_string(tabstractnormalvarsym(procdef.parast.SymList[i]).vardef) then
  104. inc(localsize,256)
  105. else
  106. inc(localsize,tabstractnormalvarsym(procdef.parast.SymList[i]).getsize);
  107. end;
  108. inc(stackframesize,localsize);
  109. if pi_needs_implicit_finally in flags then
  110. inc(stackframesize,40);
  111. if pi_uses_exceptions in flags then
  112. inc(stackframesize,40);
  113. if procdef.proctypeoption in [potype_constructor] then
  114. inc(stackframesize,40*2);
  115. inc(stackframesize,estimatedtempsize);
  116. stackframesize:=Align(stackframesize,target_info.alignment.localalignmax);
  117. end;
  118. end;
  119. function txtensaprocinfo.calc_stackframe_size:longint;
  120. var
  121. r : byte;
  122. regs: tcpuregisterset;
  123. begin
  124. if pi_estimatestacksize in flags then
  125. result:=stackframesize
  126. else
  127. begin
  128. maxpushedparasize:=align(maxpushedparasize,max(current_settings.alignment.localalignmin,4));
  129. result:=Align(tg.direction*tg.lasttemp,max(current_settings.alignment.localalignmin,4))+maxpushedparasize;
  130. end;
  131. end;
  132. procedure txtensaprocinfo.init_framepointer;
  133. begin
  134. if target_info.abi=abi_xtensa_call0 then
  135. begin
  136. RS_FRAME_POINTER_REG:=RS_A15;
  137. NR_FRAME_POINTER_REG:=NR_A15;
  138. end
  139. else
  140. begin
  141. RS_FRAME_POINTER_REG:=RS_A7;
  142. NR_FRAME_POINTER_REG:=NR_A7;
  143. end;
  144. end;
  145. begin
  146. cprocinfo:=txtensaprocinfo;
  147. end.