cpupi.pas 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. tg.setfirsttemp(maxpushedparasize);
  78. if po_nostackframe in procdef.procoptions then
  79. exit;
  80. { estimate stack frame size }
  81. if pi_estimatestacksize in flags then
  82. begin
  83. stackframesize:=maxpushedparasize;
  84. localsize:=0;
  85. for i:=0 to procdef.localst.SymList.Count-1 do
  86. if tsym(procdef.localst.SymList[i]).typ=localvarsym then
  87. inc(localsize,tabstractnormalvarsym(procdef.localst.SymList[i]).getsize);
  88. inc(stackframesize,localsize);
  89. localsize:=0;
  90. for i:=0 to procdef.parast.SymList.Count-1 do
  91. if tsym(procdef.parast.SymList[i]).typ=paravarsym then
  92. begin
  93. if tabstractnormalvarsym(procdef.parast.SymList[i]).varspez in [vs_var,vs_out,vs_constref] then
  94. inc(localsize,4)
  95. else if is_open_string(tabstractnormalvarsym(procdef.parast.SymList[i]).vardef) then
  96. inc(localsize,256)
  97. else
  98. inc(localsize,tabstractnormalvarsym(procdef.parast.SymList[i]).getsize);
  99. end;
  100. inc(stackframesize,localsize);
  101. if pi_needs_implicit_finally in flags then
  102. inc(stackframesize,40);
  103. if pi_uses_exceptions in flags then
  104. inc(stackframesize,40);
  105. if procdef.proctypeoption in [potype_constructor] then
  106. inc(stackframesize,40*2);
  107. inc(stackframesize,estimatedtempsize);
  108. stackframesize:=Align(stackframesize,target_info.alignment.localalignmax);
  109. end;
  110. end;
  111. function txtensaprocinfo.calc_stackframe_size:longint;
  112. var
  113. r : byte;
  114. regs: tcpuregisterset;
  115. begin
  116. if pi_estimatestacksize in flags then
  117. result:=stackframesize
  118. else
  119. begin
  120. maxpushedparasize:=align(maxpushedparasize,max(current_settings.alignment.localalignmin,4));
  121. result:=Align(tg.direction*tg.lasttemp,max(current_settings.alignment.localalignmin,4))+maxpushedparasize;
  122. end;
  123. end;
  124. procedure txtensaprocinfo.init_framepointer;
  125. begin
  126. if target_info.abi=abi_xtensa_call0 then
  127. begin
  128. RS_FRAME_POINTER_REG:=RS_A15;
  129. NR_FRAME_POINTER_REG:=NR_A15;
  130. end
  131. else
  132. begin
  133. RS_FRAME_POINTER_REG:=RS_A7;
  134. NR_FRAME_POINTER_REG:=NR_A7;
  135. end;
  136. end;
  137. begin
  138. cprocinfo:=txtensaprocinfo;
  139. end.